@cosmos.gl/graph 3.0.0-beta.6 → 3.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,16 +1,16 @@
1
- (function(te,Ue){typeof exports=="object"&&typeof module<"u"?Ue(exports):typeof define=="function"&&define.amd?define(["exports"],Ue):(te=typeof globalThis<"u"?globalThis:te||self,Ue(te.Cosmos={}))})(this,function(te){"use strict";var rb=Object.defineProperty;var sb=(te,Ue,Ot)=>Ue in te?rb(te,Ue,{enumerable:!0,configurable:!0,writable:!0,value:Ot}):te[Ue]=Ot;var m=(te,Ue,Ot)=>sb(te,typeof Ue!="symbol"?Ue+"":Ue,Ot);var Ue="http://www.w3.org/1999/xhtml";const Ot={svg:"http://www.w3.org/2000/svg",xhtml:Ue,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function li(n){var e=n+="",t=e.indexOf(":");return t>=0&&(e=n.slice(0,t))!=="xmlns"&&(n=n.slice(t+1)),Ot.hasOwnProperty(e)?{space:Ot[e],local:n}:n}function Gu(n){return function(){var e=this.ownerDocument,t=this.namespaceURI;return t===Ue&&e.documentElement.namespaceURI===Ue?e.createElement(n):e.createElementNS(t,n)}}function ef(n){return function(){return this.ownerDocument.createElementNS(n.space,n.local)}}function Vo(n){var e=li(n);return(e.local?ef:Gu)(e)}function tf(){}function $r(n){return n==null?tf:function(){return this.querySelector(n)}}function nf(n){typeof n!="function"&&(n=$r(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=new Array(o),l,c,u=0;u<o;++u)(l=s[u])&&(c=n.call(l,l.__data__,u,s))&&("__data__"in l&&(c.__data__=l.__data__),a[u]=c);return new qe(i,this._parents)}function rf(n){return n==null?[]:Array.isArray(n)?n:Array.from(n)}function sf(){return[]}function Ho(n){return n==null?sf:function(){return this.querySelectorAll(n)}}function of(n){return function(){return rf(n.apply(this,arguments))}}function af(n){typeof n=="function"?n=of(n):n=Ho(n);for(var e=this._groups,t=e.length,i=[],r=[],s=0;s<t;++s)for(var o=e[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&(i.push(n.call(l,l.__data__,c,o)),r.push(l));return new qe(i,r)}function Wo(n){return function(){return this.matches(n)}}function $o(n){return function(e){return e.matches(n)}}var lf=Array.prototype.find;function cf(n){return function(){return lf.call(this.children,n)}}function uf(){return this.firstElementChild}function ff(n){return this.select(n==null?uf:cf(typeof n=="function"?n:$o(n)))}var hf=Array.prototype.filter;function df(){return Array.from(this.children)}function pf(n){return function(){return hf.call(this.children,n)}}function mf(n){return this.selectAll(n==null?df:pf(typeof n=="function"?n:$o(n)))}function gf(n){typeof n!="function"&&(n=Wo(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=[],l,c=0;c<o;++c)(l=s[c])&&n.call(l,l.__data__,c,s)&&a.push(l);return new qe(i,this._parents)}function Xo(n){return new Array(n.length)}function _f(){return new qe(this._enter||this._groups.map(Xo),this._parents)}function ci(n,e){this.ownerDocument=n.ownerDocument,this.namespaceURI=n.namespaceURI,this._next=null,this._parent=n,this.__data__=e}ci.prototype={constructor:ci,appendChild:function(n){return this._parent.insertBefore(n,this._next)},insertBefore:function(n,e){return this._parent.insertBefore(n,e)},querySelector:function(n){return this._parent.querySelector(n)},querySelectorAll:function(n){return this._parent.querySelectorAll(n)}};function xf(n){return function(){return n}}function yf(n,e,t,i,r,s){for(var o=0,a,l=e.length,c=s.length;o<c;++o)(a=e[o])?(a.__data__=s[o],i[o]=a):t[o]=new ci(n,s[o]);for(;o<l;++o)(a=e[o])&&(r[o]=a)}function vf(n,e,t,i,r,s,o){var a,l,c=new Map,u=e.length,f=s.length,h=new Array(u),d;for(a=0;a<u;++a)(l=e[a])&&(h[a]=d=o.call(l,l.__data__,a,e)+"",c.has(d)?r[a]=l:c.set(d,l));for(a=0;a<f;++a)d=o.call(n,s[a],a,s)+"",(l=c.get(d))?(i[a]=l,l.__data__=s[a],c.delete(d)):t[a]=new ci(n,s[a]);for(a=0;a<u;++a)(l=e[a])&&c.get(h[a])===l&&(r[a]=l)}function bf(n){return n.__data__}function Sf(n,e){if(!arguments.length)return Array.from(this,bf);var t=e?vf:yf,i=this._parents,r=this._groups;typeof n!="function"&&(n=xf(n));for(var s=r.length,o=new Array(s),a=new Array(s),l=new Array(s),c=0;c<s;++c){var u=i[c],f=r[c],h=f.length,d=Tf(n.call(u,u&&u.__data__,c,i)),_=d.length,I=a[c]=new Array(_),P=o[c]=new Array(_),A=l[c]=new Array(h);t(u,f,I,P,A,d,e);for(var O=0,E=0,x,R;O<_;++O)if(x=I[O]){for(O>=E&&(E=O+1);!(R=P[E])&&++E<_;);x._next=R||null}}return o=new qe(o,i),o._enter=a,o._exit=l,o}function Tf(n){return typeof n=="object"&&"length"in n?n:Array.from(n)}function wf(){return new qe(this._exit||this._groups.map(Xo),this._parents)}function Af(n,e,t){var i=this.enter(),r=this,s=this.exit();return typeof n=="function"?(i=n(i),i&&(i=i.selection())):i=i.append(n+""),e!=null&&(r=e(r),r&&(r=r.selection())),t==null?s.remove():t(s),i&&r?i.merge(r).order():r}function Cf(n){for(var e=n.selection?n.selection():n,t=this._groups,i=e._groups,r=t.length,s=i.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var c=t[l],u=i[l],f=c.length,h=a[l]=new Array(f),d,_=0;_<f;++_)(d=c[_]||u[_])&&(h[_]=d);for(;l<r;++l)a[l]=t[l];return new qe(a,this._parents)}function If(){for(var n=this._groups,e=-1,t=n.length;++e<t;)for(var i=n[e],r=i.length-1,s=i[r],o;--r>=0;)(o=i[r])&&(s&&o.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(o,s),s=o);return this}function Pf(n){n||(n=Ef);function e(f,h){return f&&h?n(f.__data__,h.__data__):!f-!h}for(var t=this._groups,i=t.length,r=new Array(i),s=0;s<i;++s){for(var o=t[s],a=o.length,l=r[s]=new Array(a),c,u=0;u<a;++u)(c=o[u])&&(l[u]=c);l.sort(e)}return new qe(r,this._parents).order()}function Ef(n,e){return n<e?-1:n>e?1:n>=e?0:NaN}function Rf(){var n=arguments[0];return arguments[0]=this,n.apply(null,arguments),this}function kf(){return Array.from(this)}function Df(){for(var n=this._groups,e=0,t=n.length;e<t;++e)for(var i=n[e],r=0,s=i.length;r<s;++r){var o=i[r];if(o)return o}return null}function Mf(){let n=0;for(const e of this)++n;return n}function Ff(){return!this.node()}function Nf(n){for(var e=this._groups,t=0,i=e.length;t<i;++t)for(var r=e[t],s=0,o=r.length,a;s<o;++s)(a=r[s])&&n.call(a,a.__data__,s,r);return this}function Of(n){return function(){this.removeAttribute(n)}}function Bf(n){return function(){this.removeAttributeNS(n.space,n.local)}}function Uf(n,e){return function(){this.setAttribute(n,e)}}function zf(n,e){return function(){this.setAttributeNS(n.space,n.local,e)}}function Lf(n,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttribute(n):this.setAttribute(n,t)}}function Vf(n,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttributeNS(n.space,n.local):this.setAttributeNS(n.space,n.local,t)}}function Hf(n,e){var t=li(n);if(arguments.length<2){var i=this.node();return t.local?i.getAttributeNS(t.space,t.local):i.getAttribute(t)}return this.each((e==null?t.local?Bf:Of:typeof e=="function"?t.local?Vf:Lf:t.local?zf:Uf)(t,e))}function Yo(n){return n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView}function Wf(n){return function(){this.style.removeProperty(n)}}function $f(n,e,t){return function(){this.style.setProperty(n,e,t)}}function Xf(n,e,t){return function(){var i=e.apply(this,arguments);i==null?this.style.removeProperty(n):this.style.setProperty(n,i,t)}}function Yf(n,e,t){return arguments.length>1?this.each((e==null?Wf:typeof e=="function"?Xf:$f)(n,e,t??"")):tn(this.node(),n)}function tn(n,e){return n.style.getPropertyValue(e)||Yo(n).getComputedStyle(n,null).getPropertyValue(e)}function qf(n){return function(){delete this[n]}}function jf(n,e){return function(){this[n]=e}}function Kf(n,e){return function(){var t=e.apply(this,arguments);t==null?delete this[n]:this[n]=t}}function Zf(n,e){return arguments.length>1?this.each((e==null?qf:typeof e=="function"?Kf:jf)(n,e)):this.node()[n]}function qo(n){return n.trim().split(/^|\s+/)}function Xr(n){return n.classList||new jo(n)}function jo(n){this._node=n,this._names=qo(n.getAttribute("class")||"")}jo.prototype={add:function(n){var e=this._names.indexOf(n);e<0&&(this._names.push(n),this._node.setAttribute("class",this._names.join(" ")))},remove:function(n){var e=this._names.indexOf(n);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(n){return this._names.indexOf(n)>=0}};function Ko(n,e){for(var t=Xr(n),i=-1,r=e.length;++i<r;)t.add(e[i])}function Zo(n,e){for(var t=Xr(n),i=-1,r=e.length;++i<r;)t.remove(e[i])}function Qf(n){return function(){Ko(this,n)}}function Jf(n){return function(){Zo(this,n)}}function Gf(n,e){return function(){(e.apply(this,arguments)?Ko:Zo)(this,n)}}function eh(n,e){var t=qo(n+"");if(arguments.length<2){for(var i=Xr(this.node()),r=-1,s=t.length;++r<s;)if(!i.contains(t[r]))return!1;return!0}return this.each((typeof e=="function"?Gf:e?Qf:Jf)(t,e))}function th(){this.textContent=""}function nh(n){return function(){this.textContent=n}}function ih(n){return function(){var e=n.apply(this,arguments);this.textContent=e??""}}function rh(n){return arguments.length?this.each(n==null?th:(typeof n=="function"?ih:nh)(n)):this.node().textContent}function sh(){this.innerHTML=""}function oh(n){return function(){this.innerHTML=n}}function ah(n){return function(){var e=n.apply(this,arguments);this.innerHTML=e??""}}function lh(n){return arguments.length?this.each(n==null?sh:(typeof n=="function"?ah:oh)(n)):this.node().innerHTML}function ch(){this.nextSibling&&this.parentNode.appendChild(this)}function uh(){return this.each(ch)}function fh(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function hh(){return this.each(fh)}function dh(n){var e=typeof n=="function"?n:Vo(n);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function ph(){return null}function mh(n,e){var t=typeof n=="function"?n:Vo(n),i=e==null?ph:typeof e=="function"?e:$r(e);return this.select(function(){return this.insertBefore(t.apply(this,arguments),i.apply(this,arguments)||null)})}function gh(){var n=this.parentNode;n&&n.removeChild(this)}function _h(){return this.each(gh)}function xh(){var n=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(n,this.nextSibling):n}function yh(){var n=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(n,this.nextSibling):n}function vh(n){return this.select(n?yh:xh)}function bh(n){return arguments.length?this.property("__data__",n):this.node().__data__}function Sh(n){return function(e){n.call(this,e,this.__data__)}}function Th(n){return n.trim().split(/^|\s+/).map(function(e){var t="",i=e.indexOf(".");return i>=0&&(t=e.slice(i+1),e=e.slice(0,i)),{type:e,name:t}})}function wh(n){return function(){var e=this.__on;if(e){for(var t=0,i=-1,r=e.length,s;t<r;++t)s=e[t],(!n.type||s.type===n.type)&&s.name===n.name?this.removeEventListener(s.type,s.listener,s.options):e[++i]=s;++i?e.length=i:delete this.__on}}}function Ah(n,e,t){return function(){var i=this.__on,r,s=Sh(e);if(i){for(var o=0,a=i.length;o<a;++o)if((r=i[o]).type===n.type&&r.name===n.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=s,r.options=t),r.value=e;return}}this.addEventListener(n.type,s,t),r={type:n.type,name:n.name,value:e,listener:s,options:t},i?i.push(r):this.__on=[r]}}function Ch(n,e,t){var i=Th(n+""),r,s=i.length,o;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,c=a.length,u;l<c;++l)for(r=0,u=a[l];r<s;++r)if((o=i[r]).type===u.type&&o.name===u.name)return u.value}return}for(a=e?Ah:wh,r=0;r<s;++r)this.each(a(i[r],e,t));return this}function Qo(n,e,t){var i=Yo(n),r=i.CustomEvent;typeof r=="function"?r=new r(e,t):(r=i.document.createEvent("Event"),t?(r.initEvent(e,t.bubbles,t.cancelable),r.detail=t.detail):r.initEvent(e,!1,!1)),n.dispatchEvent(r)}function Ih(n,e){return function(){return Qo(this,n,e)}}function Ph(n,e){return function(){return Qo(this,n,e.apply(this,arguments))}}function Eh(n,e){return this.each((typeof e=="function"?Ph:Ih)(n,e))}function*Rh(){for(var n=this._groups,e=0,t=n.length;e<t;++e)for(var i=n[e],r=0,s=i.length,o;r<s;++r)(o=i[r])&&(yield o)}var Jo=[null];function qe(n,e){this._groups=n,this._parents=e}function In(){return new qe([[document.documentElement]],Jo)}function kh(){return this}qe.prototype=In.prototype={constructor:qe,select:nf,selectAll:af,selectChild:ff,selectChildren:mf,filter:gf,data:Sf,enter:_f,exit:wf,join:Af,merge:Cf,selection:kh,order:If,sort:Pf,call:Rf,nodes:kf,node:Df,size:Mf,empty:Ff,each:Nf,attr:Hf,style:Yf,property:Zf,classed:eh,text:rh,html:lh,raise:uh,lower:hh,append:dh,insert:mh,remove:_h,clone:vh,datum:bh,on:Ch,dispatch:Eh,[Symbol.iterator]:Rh};function we(n){return typeof n=="string"?new qe([[document.querySelector(n)]],[document.documentElement]):new qe([[n]],Jo)}function Dh(n){let e;for(;e=n.sourceEvent;)n=e;return n}function yt(n,e){if(n=Dh(n),e===void 0&&(e=n.currentTarget),e){var t=e.ownerSVGElement||e;if(t.createSVGPoint){var i=t.createSVGPoint();return i.x=n.clientX,i.y=n.clientY,i=i.matrixTransform(e.getScreenCTM().inverse()),[i.x,i.y]}if(e.getBoundingClientRect){var r=e.getBoundingClientRect();return[n.clientX-r.left-e.clientLeft,n.clientY-r.top-e.clientTop]}}return[n.pageX,n.pageY]}var Mh={value:()=>{}};function ui(){for(var n=0,e=arguments.length,t={},i;n<e;++n){if(!(i=arguments[n]+"")||i in t||/[\s.]/.test(i))throw new Error("illegal type: "+i);t[i]=[]}return new fi(t)}function fi(n){this._=n}function Fh(n,e){return n.trim().split(/^|\s+/).map(function(t){var i="",r=t.indexOf(".");if(r>=0&&(i=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:i}})}fi.prototype=ui.prototype={constructor:fi,on:function(n,e){var t=this._,i=Fh(n+"",t),r,s=-1,o=i.length;if(arguments.length<2){for(;++s<o;)if((r=(n=i[s]).type)&&(r=Nh(t[r],n.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++s<o;)if(r=(n=i[s]).type)t[r]=Go(t[r],n.name,e);else if(e==null)for(r in t)t[r]=Go(t[r],n.name,null);return this},copy:function(){var n={},e=this._;for(var t in e)n[t]=e[t].slice();return new fi(n)},call:function(n,e){if((r=arguments.length-2)>0)for(var t=new Array(r),i=0,r,s;i<r;++i)t[i]=arguments[i+2];if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(s=this._[n],i=0,r=s.length;i<r;++i)s[i].value.apply(e,t)},apply:function(n,e,t){if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(var i=this._[n],r=0,s=i.length;r<s;++r)i[r].value.apply(e,t)}};function Nh(n,e){for(var t=0,i=n.length,r;t<i;++t)if((r=n[t]).name===e)return r.value}function Go(n,e,t){for(var i=0,r=n.length;i<r;++i)if(n[i].name===e){n[i]=Mh,n=n.slice(0,i).concat(n.slice(i+1));break}return t!=null&&n.push({name:e,value:t}),n}var nn=0,Pn=0,En=0,ea=1e3,hi,Rn,di=0,Bt=0,pi=0,kn=typeof performance=="object"&&performance.now?performance:Date,ta=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(n){setTimeout(n,17)};function Yr(){return Bt||(ta(Oh),Bt=kn.now()+pi)}function Oh(){Bt=0}function mi(){this._call=this._time=this._next=null}mi.prototype=na.prototype={constructor:mi,restart:function(n,e,t){if(typeof n!="function")throw new TypeError("callback is not a function");t=(t==null?Yr():+t)+(e==null?0:+e),!this._next&&Rn!==this&&(Rn?Rn._next=this:hi=this,Rn=this),this._call=n,this._time=t,qr()},stop:function(){this._call&&(this._call=null,this._time=1/0,qr())}};function na(n,e,t){var i=new mi;return i.restart(n,e,t),i}function Bh(){Yr(),++nn;for(var n=hi,e;n;)(e=Bt-n._time)>=0&&n._call.call(null,e),n=n._next;--nn}function ia(){Bt=(di=kn.now())+pi,nn=Pn=0;try{Bh()}finally{nn=0,zh(),Bt=0}}function Uh(){var n=kn.now(),e=n-di;e>ea&&(pi-=e,di=n)}function zh(){for(var n,e=hi,t,i=1/0;e;)e._call?(i>e._time&&(i=e._time),n=e,e=e._next):(t=e._next,e._next=null,e=n?n._next=t:hi=t);Rn=n,qr(i)}function qr(n){if(!nn){Pn&&(Pn=clearTimeout(Pn));var e=n-Bt;e>24?(n<1/0&&(Pn=setTimeout(ia,n-kn.now()-pi)),En&&(En=clearInterval(En))):(En||(di=kn.now(),En=setInterval(Uh,ea)),nn=1,ta(ia))}}function ra(n,e,t){var i=new mi;return e=e==null?0:+e,i.restart(r=>{i.stop(),n(r+e)},e,t),i}var Lh=ui("start","end","cancel","interrupt"),Vh=[],sa=0,oa=1,jr=2,gi=3,aa=4,Kr=5,_i=6;function xi(n,e,t,i,r,s){var o=n.__transition;if(!o)n.__transition={};else if(t in o)return;Hh(n,t,{name:e,index:i,group:r,on:Lh,tween:Vh,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:sa})}function Zr(n,e){var t=it(n,e);if(t.state>sa)throw new Error("too late; already scheduled");return t}function ft(n,e){var t=it(n,e);if(t.state>gi)throw new Error("too late; already running");return t}function it(n,e){var t=n.__transition;if(!t||!(t=t[e]))throw new Error("transition not found");return t}function Hh(n,e,t){var i=n.__transition,r;i[e]=t,t.timer=na(s,0,t.time);function s(c){t.state=oa,t.timer.restart(o,t.delay,t.time),t.delay<=c&&o(c-t.delay)}function o(c){var u,f,h,d;if(t.state!==oa)return l();for(u in i)if(d=i[u],d.name===t.name){if(d.state===gi)return ra(o);d.state===aa?(d.state=_i,d.timer.stop(),d.on.call("interrupt",n,n.__data__,d.index,d.group),delete i[u]):+u<e&&(d.state=_i,d.timer.stop(),d.on.call("cancel",n,n.__data__,d.index,d.group),delete i[u])}if(ra(function(){t.state===gi&&(t.state=aa,t.timer.restart(a,t.delay,t.time),a(c))}),t.state=jr,t.on.call("start",n,n.__data__,t.index,t.group),t.state===jr){for(t.state=gi,r=new Array(h=t.tween.length),u=0,f=-1;u<h;++u)(d=t.tween[u].value.call(n,n.__data__,t.index,t.group))&&(r[++f]=d);r.length=f+1}}function a(c){for(var u=c<t.duration?t.ease.call(null,c/t.duration):(t.timer.restart(l),t.state=Kr,1),f=-1,h=r.length;++f<h;)r[f].call(n,u);t.state===Kr&&(t.on.call("end",n,n.__data__,t.index,t.group),l())}function l(){t.state=_i,t.timer.stop(),delete i[e];for(var c in i)return;delete n.__transition}}function yi(n,e){var t=n.__transition,i,r,s=!0,o;if(t){e=e==null?null:e+"";for(o in t){if((i=t[o]).name!==e){s=!1;continue}r=i.state>jr&&i.state<Kr,i.state=_i,i.timer.stop(),i.on.call(r?"interrupt":"cancel",n,n.__data__,i.index,i.group),delete t[o]}s&&delete n.__transition}}function Wh(n){return this.each(function(){yi(this,n)})}function Qr(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function la(n,e){var t=Object.create(n.prototype);for(var i in e)t[i]=e[i];return t}function Dn(){}var Mn=.7,vi=1/Mn,rn="\\s*([+-]?\\d+)\\s*",Fn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ht="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",$h=/^#([0-9a-f]{3,8})$/,Xh=new RegExp(`^rgb\\(${rn},${rn},${rn}\\)$`),Yh=new RegExp(`^rgb\\(${ht},${ht},${ht}\\)$`),qh=new RegExp(`^rgba\\(${rn},${rn},${rn},${Fn}\\)$`),jh=new RegExp(`^rgba\\(${ht},${ht},${ht},${Fn}\\)$`),Kh=new RegExp(`^hsl\\(${Fn},${ht},${ht}\\)$`),Zh=new RegExp(`^hsla\\(${Fn},${ht},${ht},${Fn}\\)$`),ca={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Qr(Dn,kt,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:ua,formatHex:ua,formatHex8:Qh,formatHsl:Jh,formatRgb:fa,toString:fa});function ua(){return this.rgb().formatHex()}function Qh(){return this.rgb().formatHex8()}function Jh(){return ga(this).formatHsl()}function fa(){return this.rgb().formatRgb()}function kt(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=$h.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?ha(e):t===3?new Xe(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?bi(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?bi(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=Xh.exec(n))?new Xe(e[1],e[2],e[3],1):(e=Yh.exec(n))?new Xe(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=qh.exec(n))?bi(e[1],e[2],e[3],e[4]):(e=jh.exec(n))?bi(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Kh.exec(n))?ma(e[1],e[2]/100,e[3]/100,1):(e=Zh.exec(n))?ma(e[1],e[2]/100,e[3]/100,e[4]):ca.hasOwnProperty(n)?ha(ca[n]):n==="transparent"?new Xe(NaN,NaN,NaN,0):null}function ha(n){return new Xe(n>>16&255,n>>8&255,n&255,1)}function bi(n,e,t,i){return i<=0&&(n=e=t=NaN),new Xe(n,e,t,i)}function Gh(n){return n instanceof Dn||(n=kt(n)),n?(n=n.rgb(),new Xe(n.r,n.g,n.b,n.opacity)):new Xe}function Jr(n,e,t,i){return arguments.length===1?Gh(n):new Xe(n,e,t,i??1)}function Xe(n,e,t,i){this.r=+n,this.g=+e,this.b=+t,this.opacity=+i}Qr(Xe,Jr,la(Dn,{brighter(n){return n=n==null?vi:Math.pow(vi,n),new Xe(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?Mn:Math.pow(Mn,n),new Xe(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new Xe(Ut(this.r),Ut(this.g),Ut(this.b),Si(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:da,formatHex:da,formatHex8:ed,formatRgb:pa,toString:pa}));function da(){return`#${zt(this.r)}${zt(this.g)}${zt(this.b)}`}function ed(){return`#${zt(this.r)}${zt(this.g)}${zt(this.b)}${zt((isNaN(this.opacity)?1:this.opacity)*255)}`}function pa(){const n=Si(this.opacity);return`${n===1?"rgb(":"rgba("}${Ut(this.r)}, ${Ut(this.g)}, ${Ut(this.b)}${n===1?")":`, ${n})`}`}function Si(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function Ut(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function zt(n){return n=Ut(n),(n<16?"0":"")+n.toString(16)}function ma(n,e,t,i){return i<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new rt(n,e,t,i)}function ga(n){if(n instanceof rt)return new rt(n.h,n.s,n.l,n.opacity);if(n instanceof Dn||(n=kt(n)),!n)return new rt;if(n instanceof rt)return n;n=n.rgb();var e=n.r/255,t=n.g/255,i=n.b/255,r=Math.min(e,t,i),s=Math.max(e,t,i),o=NaN,a=s-r,l=(s+r)/2;return a?(e===s?o=(t-i)/a+(t<i)*6:t===s?o=(i-e)/a+2:o=(e-t)/a+4,a/=l<.5?s+r:2-s-r,o*=60):a=l>0&&l<1?0:o,new rt(o,a,l,n.opacity)}function td(n,e,t,i){return arguments.length===1?ga(n):new rt(n,e,t,i??1)}function rt(n,e,t,i){this.h=+n,this.s=+e,this.l=+t,this.opacity=+i}Qr(rt,td,la(Dn,{brighter(n){return n=n==null?vi:Math.pow(vi,n),new rt(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?Mn:Math.pow(Mn,n),new rt(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,i=t+(t<.5?t:1-t)*e,r=2*t-i;return new Xe(Gr(n>=240?n-240:n+120,r,i),Gr(n,r,i),Gr(n<120?n+240:n-120,r,i),this.opacity)},clamp(){return new rt(_a(this.h),Ti(this.s),Ti(this.l),Si(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=Si(this.opacity);return`${n===1?"hsl(":"hsla("}${_a(this.h)}, ${Ti(this.s)*100}%, ${Ti(this.l)*100}%${n===1?")":`, ${n})`}`}}));function _a(n){return n=(n||0)%360,n<0?n+360:n}function Ti(n){return Math.max(0,Math.min(1,n||0))}function Gr(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const es=n=>()=>n;function nd(n,e){return function(t){return n+t*e}}function id(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(i){return Math.pow(n+i*e,t)}}function rd(n){return(n=+n)==1?xa:function(e,t){return t-e?id(e,t,n):es(isNaN(e)?t:e)}}function xa(n,e){var t=e-n;return t?nd(n,t):es(isNaN(n)?e:n)}const wi=function n(e){var t=rd(e);function i(r,s){var o=t((r=Jr(r)).r,(s=Jr(s)).r),a=t(r.g,s.g),l=t(r.b,s.b),c=xa(r.opacity,s.opacity);return function(u){return r.r=o(u),r.g=a(u),r.b=l(u),r.opacity=c(u),r+""}}return i.gamma=n,i}(1);function sd(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,i=e.slice(),r;return function(s){for(r=0;r<t;++r)i[r]=n[r]*(1-s)+e[r]*s;return i}}function od(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function ad(n,e){var t=e?e.length:0,i=n?Math.min(t,n.length):0,r=new Array(i),s=new Array(t),o;for(o=0;o<i;++o)r[o]=is(n[o],e[o]);for(;o<t;++o)s[o]=e[o];return function(a){for(o=0;o<i;++o)s[o]=r[o](a);return s}}function ld(n,e){var t=new Date;return n=+n,e=+e,function(i){return t.setTime(n*(1-i)+e*i),t}}function st(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function cd(n,e){var t={},i={},r;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in n?t[r]=is(n[r],e[r]):i[r]=e[r];return function(s){for(r in t)i[r]=t[r](s);return i}}var ts=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ns=new RegExp(ts.source,"g");function ud(n){return function(){return n}}function fd(n){return function(e){return n(e)+""}}function ya(n,e){var t=ts.lastIndex=ns.lastIndex=0,i,r,s,o=-1,a=[],l=[];for(n=n+"",e=e+"";(i=ts.exec(n))&&(r=ns.exec(e));)(s=r.index)>t&&(s=e.slice(t,s),a[o]?a[o]+=s:a[++o]=s),(i=i[0])===(r=r[0])?a[o]?a[o]+=r:a[++o]=r:(a[++o]=null,l.push({i:o,x:st(i,r)})),t=ns.lastIndex;return t<e.length&&(s=e.slice(t),a[o]?a[o]+=s:a[++o]=s),a.length<2?l[0]?fd(l[0].x):ud(e):(e=l.length,function(c){for(var u=0,f;u<e;++u)a[(f=l[u]).i]=f.x(c);return a.join("")})}function is(n,e){var t=typeof e,i;return e==null||t==="boolean"?es(e):(t==="number"?st:t==="string"?(i=kt(e))?(e=i,wi):ya:e instanceof kt?wi:e instanceof Date?ld:od(e)?sd:Array.isArray(e)?ad:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?cd:st)(n,e)}function hd(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}var va=180/Math.PI,rs={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ba(n,e,t,i,r,s){var o,a,l;return(o=Math.sqrt(n*n+e*e))&&(n/=o,e/=o),(l=n*t+e*i)&&(t-=n*l,i-=e*l),(a=Math.sqrt(t*t+i*i))&&(t/=a,i/=a,l/=a),n*i<e*t&&(n=-n,e=-e,l=-l,o=-o),{translateX:r,translateY:s,rotate:Math.atan2(e,n)*va,skewX:Math.atan(l)*va,scaleX:o,scaleY:a}}var Ai;function dd(n){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(n+"");return e.isIdentity?rs:ba(e.a,e.b,e.c,e.d,e.e,e.f)}function pd(n){return n==null||(Ai||(Ai=document.createElementNS("http://www.w3.org/2000/svg","g")),Ai.setAttribute("transform",n),!(n=Ai.transform.baseVal.consolidate()))?rs:(n=n.matrix,ba(n.a,n.b,n.c,n.d,n.e,n.f))}function Sa(n,e,t,i){function r(c){return c.length?c.pop()+" ":""}function s(c,u,f,h,d,_){if(c!==f||u!==h){var I=d.push("translate(",null,e,null,t);_.push({i:I-4,x:st(c,f)},{i:I-2,x:st(u,h)})}else(f||h)&&d.push("translate("+f+e+h+t)}function o(c,u,f,h){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),h.push({i:f.push(r(f)+"rotate(",null,i)-2,x:st(c,u)})):u&&f.push(r(f)+"rotate("+u+i)}function a(c,u,f,h){c!==u?h.push({i:f.push(r(f)+"skewX(",null,i)-2,x:st(c,u)}):u&&f.push(r(f)+"skewX("+u+i)}function l(c,u,f,h,d,_){if(c!==f||u!==h){var I=d.push(r(d)+"scale(",null,",",null,")");_.push({i:I-4,x:st(c,f)},{i:I-2,x:st(u,h)})}else(f!==1||h!==1)&&d.push(r(d)+"scale("+f+","+h+")")}return function(c,u){var f=[],h=[];return c=n(c),u=n(u),s(c.translateX,c.translateY,u.translateX,u.translateY,f,h),o(c.rotate,u.rotate,f,h),a(c.skewX,u.skewX,f,h),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,f,h),c=u=null,function(d){for(var _=-1,I=h.length,P;++_<I;)f[(P=h[_]).i]=P.x(d);return f.join("")}}}var md=Sa(dd,"px, ","px)","deg)"),gd=Sa(pd,", ",")",")"),_d=1e-12;function Ta(n){return((n=Math.exp(n))+1/n)/2}function xd(n){return((n=Math.exp(n))-1/n)/2}function yd(n){return((n=Math.exp(2*n))-1)/(n+1)}const vd=function n(e,t,i){function r(s,o){var a=s[0],l=s[1],c=s[2],u=o[0],f=o[1],h=o[2],d=u-a,_=f-l,I=d*d+_*_,P,A;if(I<_d)A=Math.log(h/c)/e,P=function(U){return[a+U*d,l+U*_,c*Math.exp(e*U*A)]};else{var O=Math.sqrt(I),E=(h*h-c*c+i*I)/(2*c*t*O),x=(h*h-c*c-i*I)/(2*h*t*O),R=Math.log(Math.sqrt(E*E+1)-E),N=Math.log(Math.sqrt(x*x+1)-x);A=(N-R)/e,P=function(U){var W=U*A,q=Ta(R),G=c/(t*O)*(q*yd(e*W+R)-xd(R));return[a+G*d,l+G*_,c*q/Ta(e*W+R)]}}return P.duration=A*1e3*e/Math.SQRT2,P}return r.rho=function(s){var o=Math.max(.001,+s),a=o*o,l=a*a;return n(o,a,l)},r}(Math.SQRT2,2,4);function bd(n,e){var t,i;return function(){var r=ft(this,n),s=r.tween;if(s!==t){i=t=s;for(var o=0,a=i.length;o<a;++o)if(i[o].name===e){i=i.slice(),i.splice(o,1);break}}r.tween=i}}function Sd(n,e,t){var i,r;if(typeof t!="function")throw new Error;return function(){var s=ft(this,n),o=s.tween;if(o!==i){r=(i=o).slice();for(var a={name:e,value:t},l=0,c=r.length;l<c;++l)if(r[l].name===e){r[l]=a;break}l===c&&r.push(a)}s.tween=r}}function Td(n,e){var t=this._id;if(n+="",arguments.length<2){for(var i=it(this.node(),t).tween,r=0,s=i.length,o;r<s;++r)if((o=i[r]).name===n)return o.value;return null}return this.each((e==null?bd:Sd)(t,n,e))}function ss(n,e,t){var i=n._id;return n.each(function(){var r=ft(this,i);(r.value||(r.value={}))[e]=t.apply(this,arguments)}),function(r){return it(r,i).value[e]}}function wa(n,e){var t;return(typeof e=="number"?st:e instanceof kt?wi:(t=kt(e))?(e=t,wi):ya)(n,e)}function wd(n){return function(){this.removeAttribute(n)}}function Ad(n){return function(){this.removeAttributeNS(n.space,n.local)}}function Cd(n,e,t){var i,r=t+"",s;return function(){var o=this.getAttribute(n);return o===r?null:o===i?s:s=e(i=o,t)}}function Id(n,e,t){var i,r=t+"",s;return function(){var o=this.getAttributeNS(n.space,n.local);return o===r?null:o===i?s:s=e(i=o,t)}}function Pd(n,e,t){var i,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttribute(n):(o=this.getAttribute(n),l=a+"",o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a)))}}function Ed(n,e,t){var i,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttributeNS(n.space,n.local):(o=this.getAttributeNS(n.space,n.local),l=a+"",o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a)))}}function Rd(n,e){var t=li(n),i=t==="transform"?gd:wa;return this.attrTween(n,typeof e=="function"?(t.local?Ed:Pd)(t,i,ss(this,"attr."+n,e)):e==null?(t.local?Ad:wd)(t):(t.local?Id:Cd)(t,i,e))}function kd(n,e){return function(t){this.setAttribute(n,e.call(this,t))}}function Dd(n,e){return function(t){this.setAttributeNS(n.space,n.local,e.call(this,t))}}function Md(n,e){var t,i;function r(){var s=e.apply(this,arguments);return s!==i&&(t=(i=s)&&Dd(n,s)),t}return r._value=e,r}function Fd(n,e){var t,i;function r(){var s=e.apply(this,arguments);return s!==i&&(t=(i=s)&&kd(n,s)),t}return r._value=e,r}function Nd(n,e){var t="attr."+n;if(arguments.length<2)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;var i=li(n);return this.tween(t,(i.local?Md:Fd)(i,e))}function Od(n,e){return function(){Zr(this,n).delay=+e.apply(this,arguments)}}function Bd(n,e){return e=+e,function(){Zr(this,n).delay=e}}function Ud(n){var e=this._id;return arguments.length?this.each((typeof n=="function"?Od:Bd)(e,n)):it(this.node(),e).delay}function zd(n,e){return function(){ft(this,n).duration=+e.apply(this,arguments)}}function Ld(n,e){return e=+e,function(){ft(this,n).duration=e}}function Vd(n){var e=this._id;return arguments.length?this.each((typeof n=="function"?zd:Ld)(e,n)):it(this.node(),e).duration}function Hd(n,e){if(typeof e!="function")throw new Error;return function(){ft(this,n).ease=e}}function Wd(n){var e=this._id;return arguments.length?this.each(Hd(e,n)):it(this.node(),e).ease}function $d(n,e){return function(){var t=e.apply(this,arguments);if(typeof t!="function")throw new Error;ft(this,n).ease=t}}function Xd(n){if(typeof n!="function")throw new Error;return this.each($d(this._id,n))}function Yd(n){typeof n!="function"&&(n=Wo(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=[],l,c=0;c<o;++c)(l=s[c])&&n.call(l,l.__data__,c,s)&&a.push(l);return new vt(i,this._parents,this._name,this._id)}function qd(n){if(n._id!==this._id)throw new Error;for(var e=this._groups,t=n._groups,i=e.length,r=t.length,s=Math.min(i,r),o=new Array(i),a=0;a<s;++a)for(var l=e[a],c=t[a],u=l.length,f=o[a]=new Array(u),h,d=0;d<u;++d)(h=l[d]||c[d])&&(f[d]=h);for(;a<i;++a)o[a]=e[a];return new vt(o,this._parents,this._name,this._id)}function jd(n){return(n+"").trim().split(/^|\s+/).every(function(e){var t=e.indexOf(".");return t>=0&&(e=e.slice(0,t)),!e||e==="start"})}function Kd(n,e,t){var i,r,s=jd(e)?Zr:ft;return function(){var o=s(this,n),a=o.on;a!==i&&(r=(i=a).copy()).on(e,t),o.on=r}}function Zd(n,e){var t=this._id;return arguments.length<2?it(this.node(),t).on.on(n):this.each(Kd(t,n,e))}function Qd(n){return function(){var e=this.parentNode;for(var t in this.__transition)if(+t!==n)return;e&&e.removeChild(this)}}function Jd(){return this.on("end.remove",Qd(this._id))}function Gd(n){var e=this._name,t=this._id;typeof n!="function"&&(n=$r(n));for(var i=this._groups,r=i.length,s=new Array(r),o=0;o<r;++o)for(var a=i[o],l=a.length,c=s[o]=new Array(l),u,f,h=0;h<l;++h)(u=a[h])&&(f=n.call(u,u.__data__,h,a))&&("__data__"in u&&(f.__data__=u.__data__),c[h]=f,xi(c[h],e,t,h,c,it(u,t)));return new vt(s,this._parents,e,t)}function ep(n){var e=this._name,t=this._id;typeof n!="function"&&(n=Ho(n));for(var i=this._groups,r=i.length,s=[],o=[],a=0;a<r;++a)for(var l=i[a],c=l.length,u,f=0;f<c;++f)if(u=l[f]){for(var h=n.call(u,u.__data__,f,l),d,_=it(u,t),I=0,P=h.length;I<P;++I)(d=h[I])&&xi(d,e,t,I,h,_);s.push(h),o.push(u)}return new vt(s,o,e,t)}var tp=In.prototype.constructor;function np(){return new tp(this._groups,this._parents)}function ip(n,e){var t,i,r;return function(){var s=tn(this,n),o=(this.style.removeProperty(n),tn(this,n));return s===o?null:s===t&&o===i?r:r=e(t=s,i=o)}}function Aa(n){return function(){this.style.removeProperty(n)}}function rp(n,e,t){var i,r=t+"",s;return function(){var o=tn(this,n);return o===r?null:o===i?s:s=e(i=o,t)}}function sp(n,e,t){var i,r,s;return function(){var o=tn(this,n),a=t(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(n),tn(this,n))),o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a))}}function op(n,e){var t,i,r,s="style."+e,o="end."+s,a;return function(){var l=ft(this,n),c=l.on,u=l.value[s]==null?a||(a=Aa(e)):void 0;(c!==t||r!==u)&&(i=(t=c).copy()).on(o,r=u),l.on=i}}function ap(n,e,t){var i=(n+="")=="transform"?md:wa;return e==null?this.styleTween(n,ip(n,i)).on("end.style."+n,Aa(n)):typeof e=="function"?this.styleTween(n,sp(n,i,ss(this,"style."+n,e))).each(op(this._id,n)):this.styleTween(n,rp(n,i,e),t).on("end.style."+n,null)}function lp(n,e,t){return function(i){this.style.setProperty(n,e.call(this,i),t)}}function cp(n,e,t){var i,r;function s(){var o=e.apply(this,arguments);return o!==r&&(i=(r=o)&&lp(n,o,t)),i}return s._value=e,s}function up(n,e,t){var i="style."+(n+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(e==null)return this.tween(i,null);if(typeof e!="function")throw new Error;return this.tween(i,cp(n,e,t??""))}function fp(n){return function(){this.textContent=n}}function hp(n){return function(){var e=n(this);this.textContent=e??""}}function dp(n){return this.tween("text",typeof n=="function"?hp(ss(this,"text",n)):fp(n==null?"":n+""))}function pp(n){return function(e){this.textContent=n.call(this,e)}}function mp(n){var e,t;function i(){var r=n.apply(this,arguments);return r!==t&&(e=(t=r)&&pp(r)),e}return i._value=n,i}function gp(n){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(n==null)return this.tween(e,null);if(typeof n!="function")throw new Error;return this.tween(e,mp(n))}function _p(){for(var n=this._name,e=this._id,t=Ca(),i=this._groups,r=i.length,s=0;s<r;++s)for(var o=i[s],a=o.length,l,c=0;c<a;++c)if(l=o[c]){var u=it(l,e);xi(l,n,t,c,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new vt(i,this._parents,n,t)}function xp(){var n,e,t=this,i=t._id,r=t.size();return new Promise(function(s,o){var a={value:o},l={value:function(){--r===0&&s()}};t.each(function(){var c=ft(this,i),u=c.on;u!==n&&(e=(n=u).copy(),e._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),c.on=e}),r===0&&s()})}var yp=0;function vt(n,e,t,i){this._groups=n,this._parents=e,this._name=t,this._id=i}function Ca(){return++yp}var bt=In.prototype;vt.prototype={constructor:vt,select:Gd,selectAll:ep,selectChild:bt.selectChild,selectChildren:bt.selectChildren,filter:Yd,merge:qd,selection:np,transition:_p,call:bt.call,nodes:bt.nodes,node:bt.node,size:bt.size,empty:bt.empty,each:bt.each,on:Zd,attr:Rd,attrTween:Nd,style:ap,styleTween:up,text:dp,textTween:gp,remove:Jd,tween:Td,delay:Ud,duration:Vd,ease:Wd,easeVarying:Xd,end:xp,[Symbol.iterator]:bt[Symbol.iterator]};function vp(n){return n*n}function bp(n){return n*(2-n)}function Sp(n){return((n*=2)<=1?n*n:--n*(2-n)+1)/2}function Tp(n){return((n*=2)<=1?n*n*n:(n-=2)*n*n+2)/2}var wp={time:null,delay:0,duration:250,ease:Tp};function Ap(n,e){for(var t;!(t=n.__transition)||!(t=t[e]);)if(!(n=n.parentNode))throw new Error(`transition ${e} not found`);return t}function Cp(n){var e,t;n instanceof vt?(e=n._id,n=n._name):(e=Ca(),(t=wp).time=Yr(),n=n==null?null:n+"");for(var i=this._groups,r=i.length,s=0;s<r;++s)for(var o=i[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&xi(l,n,e,c,o,t||Ap(l,e));return new vt(i,this._parents,n,e)}In.prototype.interrupt=Wh,In.prototype.transition=Cp;function Ia(){let n;if(typeof window<"u"&&window.performance)n=window.performance.now();else if(typeof process<"u"&&process.hrtime){const e=process.hrtime();n=e[0]*1e3+e[1]/1e6}else n=Date.now();return n}class Pa{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Ia(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Ia()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}}class Ip{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(const e of Object.values(this.stats))e.reset();return this}forEach(e){for(const t of Object.values(this.stats))e(t)}getTable(){const e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){const{name:t,type:i}=e;let r=this.stats[t];return r||(e instanceof Pa?r=e:r=new Pa(t,i),this.stats[t]=r),r}}class Pp{constructor(){m(this,"stats",new Map)}getStats(e){return this.get(e)}get(e){return this.stats.has(e)||this.stats.set(e,new Ip({id:e})),this.stats.get(e)}}const Ea=new Pp,Ci=globalThis,sn=globalThis.process||{},Ep=globalThis.navigator||{};function Ra(n){var i,r;if(typeof window<"u"&&((i=window.process)==null?void 0:i.type)==="renderer"||typeof process<"u"&&((r=process.versions)!=null&&r.electron))return!0;const t=typeof navigator<"u"&&navigator.userAgent;return!!(t&&t.indexOf("Electron")>=0)}function Lt(){return!(typeof process=="object"&&String(process)==="[object process]"&&!(process!=null&&process.browser))||Ra()}function Rp(n){return Lt()?Ra()?"Electron":(Ep.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown":"Node"}const ka="4.1.0";function kp(n){try{const e=window[n],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}class Dp{constructor(e,t,i="sessionStorage"){this.storage=kp(i),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){const t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}}_loadConfiguration(){let e={};if(this.storage){const t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}function Mp(n){let e;return n<10?e=`${n.toFixed(2)}ms`:n<100?e=`${n.toFixed(1)}ms`:n<1e3?e=`${n.toFixed(0)}ms`:e=`${(n/1e3).toFixed(2)}s`,e}function Fp(n,e=8){const t=Math.max(e-n.length,0);return`${" ".repeat(t)}${n}`}var Ii;(function(n){n[n.BLACK=30]="BLACK",n[n.RED=31]="RED",n[n.GREEN=32]="GREEN",n[n.YELLOW=33]="YELLOW",n[n.BLUE=34]="BLUE",n[n.MAGENTA=35]="MAGENTA",n[n.CYAN=36]="CYAN",n[n.WHITE=37]="WHITE",n[n.BRIGHT_BLACK=90]="BRIGHT_BLACK",n[n.BRIGHT_RED=91]="BRIGHT_RED",n[n.BRIGHT_GREEN=92]="BRIGHT_GREEN",n[n.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",n[n.BRIGHT_BLUE=94]="BRIGHT_BLUE",n[n.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",n[n.BRIGHT_CYAN=96]="BRIGHT_CYAN",n[n.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(Ii||(Ii={}));const Np=10;function Da(n){return typeof n!="string"?n:(n=n.toUpperCase(),Ii[n]||Ii.WHITE)}function Op(n,e,t){return!Lt&&typeof n=="string"&&(e&&(n=`\x1B[${Da(e)}m${n}\x1B[39m`),t&&(n=`\x1B[${Da(t)+Np}m${n}\x1B[49m`)),n}function Bp(n,e=["constructor"]){const t=Object.getPrototypeOf(n),i=Object.getOwnPropertyNames(t),r=n;for(const s of i){const o=r[s];typeof o=="function"&&(e.find(a=>s===a)||(r[s]=o.bind(n)))}}function os(n,e){if(!n)throw new Error("Assertion failed")}function on(){var e,t,i;let n;if(Lt()&&Ci.performance)n=(t=(e=Ci==null?void 0:Ci.performance)==null?void 0:e.now)==null?void 0:t.call(e);else if("hrtime"in sn){const r=(i=sn==null?void 0:sn.hrtime)==null?void 0:i.call(sn);n=r[0]*1e3+r[1]/1e6}else n=Date.now();return n}const an={debug:Lt()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},Up={enabled:!0,level:0};function ln(){}const Ma={},Fa={once:!0};class Na{constructor({id:e}={id:""}){this.VERSION=ka,this._startTs=on(),this._deltaTs=on(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new Dp(`__probe-${this.id}__`,Up),this.timeStamp(`${this.id} started`),Bp(this),Object.seal(this)}set level(e){this.setLevel(e)}get level(){return this.getLevel()}isEnabled(){return this._storage.config.enabled}getLevel(){return this._storage.config.level}getTotal(){return Number((on()-this._startTs).toPrecision(10))}getDelta(){return Number((on()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._storage.setConfiguration({enabled:e}),this}setLevel(e){return this._storage.setConfiguration({level:e}),this}get(e){return this._storage.config[e]}set(e,t){this._storage.setConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e){return this._getLogFunction(0,e,an.warn,arguments,Fa)}error(e){return this._getLogFunction(0,e,an.error,arguments)}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t){return this._getLogFunction(e,t,an.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,an.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,an.debug||an.info,arguments,Fa)}table(e,t,i){return t?this._getLogFunction(e,t,console.table||ln,i&&[i],{tag:Lp(t)}):ln}time(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}timeEnd(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}timeStamp(e,t){return this._getLogFunction(e,t,console.timeStamp||ln)}group(e,t,i={collapsed:!1}){const r=Ba({logLevel:e,message:t,opts:i}),{collapsed:s}=i;return r.method=(s?console.groupCollapsed:console.group)||console.info,this._getLogFunction(r)}groupCollapsed(e,t,i={}){return this.group(e,t,Object.assign({},i,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||ln)}withGroup(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=Oa(e)}_getLogFunction(e,t,i,r,s){if(this._shouldLog(e)){s=Ba({logLevel:e,message:t,args:r,opts:s}),i=i||s.method,os(i),s.total=this.getTotal(),s.delta=this.getDelta(),this._deltaTs=on();const o=s.tag||s.message;if(s.once&&o)if(!Ma[o])Ma[o]=on();else return ln;return t=zp(this.id,s.message,s),i.bind(console,t,...s.args)}return ln}}Na.VERSION=ka;function Oa(n){if(!n)return 0;let e;switch(typeof n){case"number":e=n;break;case"object":e=n.logLevel||n.priority||0;break;default:return 0}return os(Number.isFinite(e)&&e>=0),e}function Ba(n){const{logLevel:e,message:t}=n;n.logLevel=Oa(e);const i=n.args?Array.from(n.args):[];for(;i.length&&i.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&i.unshift(t),n.message=e;break;case"object":Object.assign(n,e);break}typeof n.message=="function"&&(n.message=n.message());const r=typeof n.message;return os(r==="string"||r==="object"),Object.assign(n,{args:i},n.opts)}function zp(n,e,t){if(typeof e=="string"){const i=t.time?Fp(Mp(t.total)):"";e=t.time?`${n}: ${i} ${e}`:`${n}: ${e}`,e=Op(e,t.color,t.background)}return e}function Lp(n){for(const e in n)for(const t in n[e])return t||"untitled";return"empty"}const D=new Na({id:"luma.gl"}),as={};function Pi(n="id"){as[n]=as[n]||1;const e=as[n]++;return`${n}-${e}`}class ce{constructor(e,t,i){m(this,"id");m(this,"props");m(this,"userData",{});m(this,"_device");m(this,"destroyed",!1);m(this,"allocatedBytes",0);m(this,"_attachedResources",new Set);if(!e)throw new Error("no device");this._device=e,this.props=Vp(t,i);const r=this.props.id!=="undefined"?this.props.id:Pi(this[Symbol.toStringTag]);this.props.id=r,this.id=r,this.userData=this.props.userData||{},this.addStats()}toString(){return`${this[Symbol.toStringTag]||this.constructor.name}:"${this.id}"`}destroy(){this.destroyResource()}delete(){return this.destroy(),this}getProps(){return this.props}attachResource(e){this._attachedResources.add(e)}detachResource(e){this._attachedResources.delete(e)}destroyAttachedResource(e){this._attachedResources.delete(e)&&e.destroy()}destroyAttachedResources(){for(const e of Object.values(this._attachedResources))e.destroy();this._attachedResources=new Set}destroyResource(){this.destroyAttachedResources(),this.removeStats(),this.destroyed=!0}removeStats(){const e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get(`${t}s Active`).decrementCount()}trackAllocatedMemory(e,t=this[Symbol.toStringTag]){const i=this._device.statsManager.getStats("Resource Counts");i.get("GPU Memory").addCount(e),i.get(`${t} Memory`).addCount(e),this.allocatedBytes=e}trackDeallocatedMemory(e=this[Symbol.toStringTag]){const t=this._device.statsManager.getStats("Resource Counts");t.get("GPU Memory").subtractCount(this.allocatedBytes),t.get(`${e} Memory`).subtractCount(this.allocatedBytes),this.allocatedBytes=0}addStats(){const e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get("Resources Created").incrementCount(),e.get(`${t}s Created`).incrementCount(),e.get(`${t}s Active`).incrementCount()}}m(ce,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function Vp(n,e){const t={...e};for(const i in n)n[i]!==void 0&&(t[i]=n[i]);return t}const ke=class ke extends ce{constructor(t,i){const r={...i};(i.usage||0)&ke.INDEX&&!i.indexType&&(i.data instanceof Uint32Array?r.indexType="uint32":i.data instanceof Uint16Array?r.indexType="uint16":i.data instanceof Uint8Array&&(r.indexType="uint8")),delete r.data;super(t,r,ke.defaultProps);m(this,"usage");m(this,"indexType");m(this,"updateTimestamp");m(this,"debugData",new ArrayBuffer(0));this.usage=r.usage||0,this.indexType=r.indexType,this.updateTimestamp=t.incrementTimestamp()}get[Symbol.toStringTag](){return"Buffer"}clone(t){return this.device.createBuffer({...this.props,...t})}_setDebugData(t,i,r){const s=ArrayBuffer.isView(t)?t.buffer:t,o=Math.min(t?t.byteLength:r,ke.DEBUG_DATA_MAX_LENGTH);s===null?this.debugData=new ArrayBuffer(o):i===0&&r===s.byteLength?this.debugData=s.slice(0,o):this.debugData=s.slice(i,i+o)}};m(ke,"INDEX",16),m(ke,"VERTEX",32),m(ke,"UNIFORM",64),m(ke,"STORAGE",128),m(ke,"INDIRECT",256),m(ke,"QUERY_RESOLVE",512),m(ke,"MAP_READ",1),m(ke,"MAP_WRITE",2),m(ke,"COPY_SRC",4),m(ke,"COPY_DST",8),m(ke,"DEBUG_DATA_MAX_LENGTH",32),m(ke,"defaultProps",{...ce.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",onMapped:void 0});let L=ke;function Ua(n){const[e,t,i]=ls[n],r=n.includes("norm"),s=!r&&!n.startsWith("float"),o=n.startsWith("s");return{signedType:e,primitiveType:t,byteLength:i,normalized:r,integer:s,signed:o}}function Hp(n){const e=n;switch(e){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return e}}function Wp(n,e){switch(e){case 1:return n;case 2:return n+n%2;default:return n+(4-n%4)%4}}function za(n){const e=ArrayBuffer.isView(n)?n.constructor:n;if(e===Uint8ClampedArray)return"uint8";const t=Object.values(ls).find(i=>e===i[4]);if(!t)throw new Error(e.name);return t[0]}function La(n){const[,,,,e]=ls[n];return e}const ls={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};function cs(n){let e;n.endsWith("-webgl")&&(n.replace("-webgl",""),e=!0);const[t,i]=n.split("x"),r=t,s=i?parseInt(i):1,o=Ua(r),a={type:r,components:s,byteLength:o.byteLength*s,integer:o.integer,signed:o.signed,normalized:o.normalized};return e&&(a.webglOnly=!0),a}function $p(n,e,t){const i=t?Hp(n):n;switch(i){case"unorm8":return e===1?"unorm8":e===3?"unorm8x3-webgl":`${i}x${e}`;case"snorm8":case"uint8":case"sint8":case"uint16":case"sint16":case"unorm16":case"snorm16":case"float16":if(e===1||e===3)throw new Error(`size: ${e}`);return`${i}x${e}`;default:return e===1?i:`${i}x${e}`}}function Xp(n,e,t){if(!e||e>4)throw new Error(`size ${e}`);const i=e,r=za(n);return $p(r,i,t)}function Yp(n){let e;switch(n.primitiveType){case"f32":e="float32";break;case"i32":e="sint32";break;case"u32":e="uint32";break;case"f16":return n.components<=2?"float16x2":"float16x4"}return n.components===1?e:`${e}x${n.components}`}const De="texture-compression-bc",ue="texture-compression-astc",dt="texture-compression-etc2",qp="texture-compression-etc1-webgl",Ei="texture-compression-pvrtc-webgl",us="texture-compression-atc-webgl",Ri="float32-renderable-webgl",fs="float16-renderable-webgl",jp="rgb9e5ufloat-renderable-webgl",hs="snorm8-renderable-webgl",Nn="norm16-renderable-webgl",ds="snorm16-renderable-webgl",ki="float32-filterable",Va="float16-filterable-webgl";function Ha(n){const e=Kp[n];if(!e)throw new Error(`Unsupported texture format ${n}`);return e}const Kp={...{r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:hs},rg8snorm:{render:hs},"rgb8snorm-webgl":{},rgba8snorm:{render:hs},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:Nn},rg16unorm:{render:Nn},"rgb16unorm-webgl":{f:Nn},rgba16unorm:{render:Nn},r16snorm:{f:ds},rg16snorm:{render:ds},"rgb16snorm-webgl":{f:Nn},rgba16snorm:{render:ds},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:fs,filter:"float16-filterable-webgl"},rg16float:{render:fs,filter:Va},rgba16float:{render:fs,filter:Va},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Ri,filter:ki},rg32float:{render:!1,filter:ki},"rgb32float-webgl":{render:Ri,filter:ki},rgba32float:{render:Ri,filter:ki},"rgba4unorm-webgl":{channels:"rgba",bitsPerChannel:[4,4,4,4],packed:!0},"rgb565unorm-webgl":{channels:"rgb",bitsPerChannel:[5,6,5,0],packed:!0},"rgb5a1unorm-webgl":{channels:"rgba",bitsPerChannel:[5,5,5,1],packed:!0},rgb9e5ufloat:{channels:"rgb",packed:!0,render:jp},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Ri},rgb10a2unorm:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},rgb10a2uint:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},stencil8:{attachment:"stencil",bitsPerChannel:[8,0,0,0],dataType:"uint8"},depth16unorm:{attachment:"depth",bitsPerChannel:[16,0,0,0],dataType:"uint16"},depth24plus:{attachment:"depth",bitsPerChannel:[24,0,0,0],dataType:"uint32"},depth32float:{attachment:"depth",bitsPerChannel:[32,0,0,0],dataType:"float32"},"depth24plus-stencil8":{attachment:"depth-stencil",bitsPerChannel:[24,8,0,0],packed:!0},"depth32float-stencil8":{attachment:"depth-stencil",bitsPerChannel:[32,8,0,0],packed:!0}},...{"bc1-rgb-unorm-webgl":{f:De},"bc1-rgb-unorm-srgb-webgl":{f:De},"bc1-rgba-unorm":{f:De},"bc1-rgba-unorm-srgb":{f:De},"bc2-rgba-unorm":{f:De},"bc2-rgba-unorm-srgb":{f:De},"bc3-rgba-unorm":{f:De},"bc3-rgba-unorm-srgb":{f:De},"bc4-r-unorm":{f:De},"bc4-r-snorm":{f:De},"bc5-rg-unorm":{f:De},"bc5-rg-snorm":{f:De},"bc6h-rgb-ufloat":{f:De},"bc6h-rgb-float":{f:De},"bc7-rgba-unorm":{f:De},"bc7-rgba-unorm-srgb":{f:De},"etc2-rgb8unorm":{f:dt},"etc2-rgb8unorm-srgb":{f:dt},"etc2-rgb8a1unorm":{f:dt},"etc2-rgb8a1unorm-srgb":{f:dt},"etc2-rgba8unorm":{f:dt},"etc2-rgba8unorm-srgb":{f:dt},"eac-r11unorm":{f:dt},"eac-r11snorm":{f:dt},"eac-rg11unorm":{f:dt},"eac-rg11snorm":{f:dt},"astc-4x4-unorm":{f:ue},"astc-4x4-unorm-srgb":{f:ue},"astc-5x4-unorm":{f:ue},"astc-5x4-unorm-srgb":{f:ue},"astc-5x5-unorm":{f:ue},"astc-5x5-unorm-srgb":{f:ue},"astc-6x5-unorm":{f:ue},"astc-6x5-unorm-srgb":{f:ue},"astc-6x6-unorm":{f:ue},"astc-6x6-unorm-srgb":{f:ue},"astc-8x5-unorm":{f:ue},"astc-8x5-unorm-srgb":{f:ue},"astc-8x6-unorm":{f:ue},"astc-8x6-unorm-srgb":{f:ue},"astc-8x8-unorm":{f:ue},"astc-8x8-unorm-srgb":{f:ue},"astc-10x5-unorm":{f:ue},"astc-10x5-unorm-srgb":{f:ue},"astc-10x6-unorm":{f:ue},"astc-10x6-unorm-srgb":{f:ue},"astc-10x8-unorm":{f:ue},"astc-10x8-unorm-srgb":{f:ue},"astc-10x10-unorm":{f:ue},"astc-10x10-unorm-srgb":{f:ue},"astc-12x10-unorm":{f:ue},"astc-12x10-unorm-srgb":{f:ue},"astc-12x12-unorm":{f:ue},"astc-12x12-unorm-srgb":{f:ue},"pvrtc-rgb4unorm-webgl":{f:Ei},"pvrtc-rgba4unorm-webgl":{f:Ei},"pvrtc-rbg2unorm-webgl":{f:Ei},"pvrtc-rgba2unorm-webgl":{f:Ei},"etc1-rbg-unorm-webgl":{f:qp},"atc-rgb-unorm-webgl":{f:us},"atc-rgba-unorm-webgl":{f:us},"atc-rgbai-unorm-webgl":{f:us}}},Zp=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],Qp=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;class Jp{getInfo(e){return Wa(e)}isColor(e){return e.startsWith("rgba")||e.startsWith("bgra")||e.startsWith("rgb")}isDepthStencil(e){return e.startsWith("depth")||e.startsWith("stencil")}isCompressed(e){return Zp.some(t=>e.startsWith(t))}getCapabilities(e){const t=Ha(e),i={format:e,create:t.f??!0,render:t.render??!0,filter:t.filter??!0,blend:t.blend??!0,store:t.store??!0},r=Wa(e),s=e.startsWith("depth")||e.startsWith("stencil"),o=r==null?void 0:r.signed,a=r==null?void 0:r.integer,l=r==null?void 0:r.webgl;return i.render&&(i.render=!o),i.filter&&(i.filter=!s&&!o&&!a&&!l),i}}const Vt=new Jp;function Wa(n){let e=Gp(n);if(Vt.isCompressed(n)){e.channels="rgb",e.components=3,e.bytesPerPixel=1,e.srgb=!1,e.compressed=!0;const i=em(n);i&&(e.blockWidth=i.blockWidth,e.blockHeight=i.blockHeight)}const t=Qp.exec(n);if(t){const[,i,r,s,o,a]=t,l=`${s}${r}`,c=Ua(l),u=c.byteLength*8,f=i.length,h=[u,f>=2?u:0,f>=3?u:0,f>=4?u:0];e={format:n,attachment:e.attachment,dataType:c.signedType,components:f,channels:i,integer:c.integer,signed:c.signed,normalized:c.normalized,bitsPerChannel:h,bytesPerPixel:c.byteLength*i.length,packed:e.packed,srgb:e.srgb},a==="-webgl"&&(e.webgl=!0),o==="-srgb"&&(e.srgb=!0)}return n.endsWith("-webgl")&&(e.webgl=!0),n.endsWith("-srgb")&&(e.srgb=!0),e}function Gp(n){var s;const e=Ha(n),t=e.bytesPerPixel||1,i=e.bitsPerChannel||[8,8,8,8];return delete e.bitsPerChannel,delete e.bytesPerPixel,delete e.f,delete e.render,delete e.filter,delete e.blend,delete e.store,{...e,format:n,attachment:e.attachment||"color",channels:e.channels||"r",components:e.components||((s=e.channels)==null?void 0:s.length)||1,bytesPerPixel:t,bitsPerChannel:i,dataType:e.dataType||"uint8",srgb:e.srgb??!1,packed:e.packed??!1,webgl:e.webgl??!1,integer:e.integer??!1,signed:e.signed??!1,normalized:e.normalized??!1,compressed:e.compressed??!1}}function em(n){const t=/.*-(\d+)x(\d+)-.*/.exec(n);if(t){const[,i,r]=t;return{blockWidth:Number(i),blockHeight:Number(r)}}return null}function tm(n){return typeof ImageData<"u"&&n instanceof ImageData||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement||typeof VideoFrame<"u"&&n instanceof VideoFrame||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas}function nm(n){if(typeof ImageData<"u"&&n instanceof ImageData||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas)return{width:n.width,height:n.height};if(typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement)return{width:n.naturalWidth,height:n.naturalHeight};if(typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement)return{width:n.videoWidth,height:n.videoHeight};if(typeof VideoFrame<"u"&&n instanceof VideoFrame)return{width:n.displayWidth,height:n.displayHeight};throw new Error("Unknown image type")}class im{}class rm{constructor(e=[],t){m(this,"features");m(this,"disabledFeatures");this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){var t;return!((t=this.disabledFeatures)!=null&&t[e])&&this.features.has(e)}}const Sr=class Sr{constructor(e){m(this,"id");m(this,"props");m(this,"userData",{});m(this,"statsManager",Ea);m(this,"timestamp",0);m(this,"_reused",!1);m(this,"_lumaData",{});m(this,"_textureCaps",{});this.props={...Sr.defaultProps,...e},this.id=this.props.id||Pi(this[Symbol.toStringTag].toLowerCase())}get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}getVertexFormatInfo(e){return cs(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return Vt.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){const i=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(i),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,i=1){const r=Math.max(e,t,i);return 1+Math.floor(Math.log2(r))}isExternalImage(e){return tm(e)}getExternalImageSize(e){return nm(e)}isTextureFormatSupported(e){return this.getTextureFormatCapabilities(e).create}isTextureFormatFilterable(e){return this.getTextureFormatCapabilities(e).filter}isTextureFormatRenderable(e){return this.getTextureFormatCapabilities(e).render}isTextureFormatCompressed(e){return Vt.isCompressed(e)}pushDebugGroup(e){this.commandEncoder.pushDebugGroup(e)}popDebugGroup(){var e;(e=this.commandEncoder)==null||e.popDebugGroup()}insertDebugMarker(e){var t;(t=this.commandEncoder)==null||t.insertDebugMarker(e)}loseDevice(){return!1}incrementTimestamp(){return this.timestamp++}reportError(e,t,...i){return this.props.onError(e,t)?()=>{}:D.error(e.message,t,...i)}debug(){if(this.props.debug)debugger;else D.once(0,`'Type luma.log.set({debug: true}) in console to enable debug breakpoints',
2
- or create a device with the 'debug: true' prop.`)()}getDefaultCanvasContext(){if(!this.canvasContext)throw new Error("Device has no default CanvasContext. See props.createCanvasContext");return this.canvasContext}beginRenderPass(e){return this.commandEncoder.beginRenderPass(e)}beginComputePass(e){return this.commandEncoder.beginComputePass(e)}getCanvasContext(){return this.getDefaultCanvasContext()}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}resetWebGL(){throw new Error("not implemented")}static _getCanvasContextProps(e){return e.createCanvasContext===!0?{}:e.createCanvasContext}_getDeviceTextureFormatCapabilities(e){const t=Vt.getCapabilities(e),i=s=>(typeof s=="string"?this.features.has(s):s)??!0,r=i(t.create);return{format:e,create:r,render:r&&i(t.render),filter:r&&i(t.filter),blend:r&&i(t.blend),store:r&&i(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});const t={...e};if((e.usage||0)&L.INDEX&&(e.indexType||(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array?t.indexType="uint16":e.data instanceof Uint8Array&&(t.data=new Uint16Array(e.data),t.indexType="uint16")),!t.indexType))throw new Error("indices buffer content must be of type uint16 or uint32");return t}};m(Sr,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{const[i,r]=e.getDevicePixelSize();D.log(1,`${e} resized => ${i}x${r}px`)()},onPositionChange:(e,t)=>{const[i,r]=e.getPosition();D.log(1,`${e} repositioned => ${i},${r}`)()},onVisibilityChange:e=>D.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>D.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:D.get("debug")||void 0,debugShaders:D.get("debug-shaders")||void 0,debugFramebuffers:!!D.get("debug-framebuffers"),debugFactories:!!D.get("debug-factories"),debugWebGL:!!D.get("debug-webgl"),debugSpectorJS:void 0,debugSpectorJSUrl:void 0,_reuseDevices:!1,_requestMaxLimits:!0,_cacheShaders:!1,_cachePipelines:!1,_cacheDestroyPolicy:"unused",_initializeFeatures:!0,_disabledFeatures:{"compilation-status-async-webgl":!0},_handle:void 0});let Ht=Sr;const sm="set luma.log.level=1 (or higher) to trace rendering",$a="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",ii=class ii{constructor(){m(this,"stats",Ea);m(this,"log",D);m(this,"VERSION","9.2.6");m(this,"spector");m(this,"preregisteredAdapters",new Map);if(globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw D.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),D.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");D.error("This version of luma.gl has already been initialized")()}D.log(1,`${this.VERSION} - ${sm}`)(),globalThis.luma=this}async createDevice(e={}){const t={...ii.defaultProps,...e},i=this.selectAdapter(t.type,t.adapters);if(!i)throw new Error($a);return t.waitForPageLoad&&await i.pageLoaded,await i.create(t)}async attachDevice(e,t){var s;const i=this._getTypeFromHandle(e,t.adapters),r=i&&this.selectAdapter(i,t.adapters);if(!r)throw new Error($a);return await((s=r==null?void 0:r.attach)==null?void 0:s.call(r,e,t))}registerAdapters(e){for(const t of e)this.preregisteredAdapters.set(t.type,t)}getSupportedAdapters(e=[]){const t=this._getAdapterMap(e);return Array.from(t).map(([,i])=>i).filter(i=>{var r;return(r=i.isSupported)==null?void 0:r.call(i)}).map(i=>i.type)}getBestAvailableAdapterType(e=[]){var r,s;const t=["webgpu","webgl","null"],i=this._getAdapterMap(e);for(const o of t)if((s=(r=i.get(o))==null?void 0:r.isSupported)!=null&&s.call(r))return o;return null}selectAdapter(e,t=[]){let i=e;e==="best-available"&&(i=this.getBestAvailableAdapterType(t));const r=this._getAdapterMap(t);return i&&r.get(i)||null}enforceWebGL2(e=!0,t=[]){var s;const r=this._getAdapterMap(t).get("webgl");r||D.warn("enforceWebGL2: webgl adapter not found")(),(s=r==null?void 0:r.enforceWebGL2)==null||s.call(r,e)}setDefaultDeviceProps(e){Object.assign(ii.defaultProps,e)}_getAdapterMap(e=[]){const t=new Map(this.preregisteredAdapters);for(const i of e)t.set(i.type,i);return t}_getTypeFromHandle(e,t=[]){return e instanceof WebGL2RenderingContext?"webgl":typeof GPUDevice<"u"&&e instanceof GPUDevice||e!=null&&e.queue?"webgpu":e===null?"null":(e instanceof WebGLRenderingContext?D.warn("WebGL1 is not supported",e)():D.warn("Unknown handle type",e)(),null)}};m(ii,"defaultProps",{...Ht.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});let ps=ii;const om=new ps;class am{get pageLoaded(){return um()}}const lm=Lt()&&typeof document<"u",cm=()=>lm&&document.readyState==="complete";let Di=null;function um(){return Di||(cm()||typeof window>"u"?Di=Promise.resolve():Di=new Promise(n=>window.addEventListener("load",()=>n()))),Di}function fm(){let n,e;return{promise:new Promise((i,r)=>{n=i,e=r}),resolve:n,reject:e}}const Qt=class Qt{constructor(e){m(this,"id");m(this,"props");m(this,"canvas");m(this,"htmlCanvas");m(this,"offscreenCanvas");m(this,"type");m(this,"initialized");m(this,"isInitialized",!1);m(this,"isVisible",!0);m(this,"cssWidth");m(this,"cssHeight");m(this,"devicePixelRatio");m(this,"devicePixelWidth");m(this,"devicePixelHeight");m(this,"drawingBufferWidth");m(this,"drawingBufferHeight");m(this,"_initializedResolvers",fm());m(this,"_resizeObserver");m(this,"_intersectionObserver");m(this,"_position");m(this,"destroyed",!1);var t,i;if(this.props={...Qt.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,Lt()?e.canvas?typeof e.canvas=="string"?this.canvas=dm(e.canvas):this.canvas=e.canvas:this.canvas=pm(e):this.canvas={width:e.width||1,height:e.height||1},Qt.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):Qt.isOffscreenCanvas(this.canvas)?(this.id=e.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=e.id||"node-canvas-context",this.type="node"),this.cssWidth=((t=this.htmlCanvas)==null?void 0:t.clientWidth)||this.canvas.width,this.cssHeight=((i=this.htmlCanvas)==null?void 0:i.clientHeight)||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],Qt.isHTMLCanvas(this.canvas)){this._intersectionObserver=new IntersectionObserver(r=>this._handleIntersection(r)),this._intersectionObserver.observe(this.canvas),this._resizeObserver=new ResizeObserver(r=>this._handleResize(r));try{this._resizeObserver.observe(this.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.canvas,{box:"content-box"})}setTimeout(()=>this._observeDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}static isHTMLCanvas(e){return typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}destroy(){this.destroyed=!0}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){const e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){this.canvas.width=e,this.canvas.height=t,this.drawingBufferWidth=e,this.drawingBufferHeight=t}getDevicePixelRatio(){return typeof window<"u"&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){const i=this.cssToDeviceRatio(),[r,s]=this.getDrawingBufferSize();return mm(e,i,r,s,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){const[e,t]=this.getDevicePixelSize();return e/t}cssToDeviceRatio(){try{const[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){var t;((t=this.htmlCanvas)==null?void 0:t.id)==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}_handleIntersection(e){const t=e.find(r=>r.target===this.canvas);if(!t)return;const i=t.isIntersecting;this.isVisible!==i&&(this.isVisible=i,this.device.props.onVisibilityChange(this))}_handleResize(e){var l,c;const t=e.find(u=>u.target===this.canvas);if(!t)return;this.cssWidth=t.contentBoxSize[0].inlineSize,this.cssHeight=t.contentBoxSize[0].blockSize;const i=this.getDevicePixelSize(),r=((l=t.devicePixelContentBoxSize)==null?void 0:l[0].inlineSize)||t.contentBoxSize[0].inlineSize*devicePixelRatio,s=((c=t.devicePixelContentBoxSize)==null?void 0:c[0].blockSize)||t.contentBoxSize[0].blockSize*devicePixelRatio,[o,a]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(r,o)),this.devicePixelHeight=Math.max(1,Math.min(s,a)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:i})}_updateDrawingBufferSize(){if(this.props.autoResize){if(typeof this.props.useDevicePixels=="number"){const e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._updateDevice()}this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_observeDevicePixelRatio(){const e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange(this,{oldRatio:e}),matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change",()=>this._observeDevicePixelRatio(),{once:!0})}_trackPosition(e=100){const t=setInterval(()=>{this.destroyed?clearInterval(t):this.updatePosition()},e)}updatePosition(){var t,i,r;const e=(t=this.htmlCanvas)==null?void 0:t.getBoundingClientRect();if(e){const s=[e.left,e.top];if(this._position??(this._position=s),s[0]!==this._position[0]||s[1]!==this._position[1]){const a=this._position;this._position=s,(r=(i=this.device.props).onPositionChange)==null||r.call(i,this,{oldPosition:a})}}}};m(Qt,"defaultProps",{id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1});let Mi=Qt;function hm(n){if(typeof n=="string"){const e=document.getElementById(n);if(!e)throw new Error(`${n} is not an HTML element`);return e}return n||document.body}function dm(n){const e=document.getElementById(n);if(!Mi.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function pm(n){const{width:e,height:t}=n,i=document.createElement("canvas");i.id=Pi("lumagl-auto-created-canvas"),i.width=e||1,i.height=t||1,i.style.width=Number.isFinite(e)?`${e}px`:"100%",i.style.height=Number.isFinite(t)?`${t}px`:"100%",n!=null&&n.visible||(i.style.visibility="hidden");const r=hm((n==null?void 0:n.container)||null);return r.insertBefore(i,r.firstChild),i}function mm(n,e,t,i,r){const s=n,o=Xa(s[0],e,t);let a=Ya(s[1],e,i,r),l=Xa(s[0]+1,e,t);const c=l===t-1?l:l-1;l=Ya(s[1]+1,e,i,r);let u;return r?(l=l===0?l:l+1,u=a,a=l):u=l===i-1?l:l-1,{x:o,y:a,width:Math.max(c-o+1,1),height:Math.max(u-a+1,1)}}function Xa(n,e,t){return Math.min(Math.round(n*e),t-1)}function Ya(n,e,t,i){return i?Math.max(0,t-1-Math.round(n*e)):Math.min(Math.round(n*e),t-1)}const ri=class ri extends ce{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){t=ri.normalizeProps(e,t),super(e,t,ri.defaultProps)}static normalizeProps(e,t){return t}};m(ri,"defaultProps",{...ce.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"none",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});let cn=ri;const gm={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},Ce=class Ce extends ce{constructor(t,i){i=Ce.normalizeProps(t,i);super(t,i,Ce.defaultProps);m(this,"dimension");m(this,"baseDimension");m(this,"format");m(this,"width");m(this,"height");m(this,"depth");m(this,"mipLevels");m(this,"updateTimestamp");if(this.dimension=this.props.dimension,this.baseDimension=gm[this.dimension],this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.mipLevels=this.props.mipLevels,this.props.width===void 0||this.props.height===void 0)if(t.isExternalImage(i.data)){const r=t.getExternalImageSize(i.data);this.width=(r==null?void 0:r.width)||1,this.height=(r==null?void 0:r.height)||1}else this.width=1,this.height=1,(this.props.width===void 0||this.props.height===void 0)&&D.warn(`${this} created with undefined width or height. This is deprecated. Use AsyncTexture instead.`)();this.updateTimestamp=t.incrementTimestamp()}get[Symbol.toStringTag](){return"Texture"}toString(){return`Texture(${this.id},${this.format},${this.width}x${this.height})`}setSampler(t){this.sampler=t instanceof cn?t:this.device.createSampler(t)}clone(t){return this.device.createTexture({...this.props,...t})}static normalizeProps(t,i){const r={...i},{width:s,height:o}=r;return typeof s=="number"&&(r.width=Math.max(1,Math.ceil(s))),typeof o=="number"&&(r.height=Math.max(1,Math.ceil(o))),r}_initializeData(t){this.device.isExternalImage(t)?this.copyExternalImage({image:t,width:this.width,height:this.height,depth:this.depth,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}):t&&this.copyImageData({data:t,mipLevel:0,x:0,y:0,z:0,aspect:"all"})}_normalizeCopyImageDataOptions(t){const{width:i,height:r,depth:s}=this,o={...Ce.defaultCopyDataOptions,width:i,height:r,depth:s,...t},a=this.device.getTextureFormatInfo(this.format);if(!t.bytesPerRow&&!a.bytesPerPixel)throw new Error(`bytesPerRow must be provided for texture format ${this.format}`);return o.bytesPerRow=t.bytesPerRow||i*(a.bytesPerPixel||4),o.rowsPerImage=t.rowsPerImage||r,o}_normalizeCopyExternalImageOptions(t){const i=this.device.getExternalImageSize(t.image),r={...Ce.defaultCopyExternalImageOptions,...i,...t};return r.width=Math.min(r.width,this.width-r.x),r.height=Math.min(r.height,this.height-r.y),r}};m(Ce,"SAMPLE",4),m(Ce,"STORAGE",8),m(Ce,"RENDER",16),m(Ce,"COPY_SRC",1),m(Ce,"COPY_DST",2),m(Ce,"TEXTURE",4),m(Ce,"RENDER_ATTACHMENT",16),m(Ce,"defaultProps",{...ce.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:Ce.TEXTURE|Ce.RENDER_ATTACHMENT|Ce.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),m(Ce,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),m(Ce,"defaultCopyExternalImageOptions",{image:void 0,sourceX:0,sourceY:0,width:void 0,height:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1});let Q=Ce;const Tr=class Tr extends ce{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,Tr.defaultProps)}};m(Tr,"defaultProps",{...ce.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});let Fi=Tr;function _m(n,e,t){let i="";const r=e.split(/\r?\n/),s=n.slice().sort((o,a)=>o.lineNum-a.lineNum);switch((t==null?void 0:t.showSourceCode)||"no"){case"all":let o=0;for(let a=1;a<=r.length;a++)for(i+=qa(r[a-1],a,t);s.length>o&&s[o].lineNum===a;){const l=s[o++];i+=ms(l,r,l.lineNum,{...t,inlineSource:!1})}for(;s.length>o;){const a=s[o++];i+=ms(a,[],0,{...t,inlineSource:!1})}return i;case"issues":case"no":for(const a of n)i+=ms(a,r,a.lineNum,{inlineSource:(t==null?void 0:t.showSourceCode)!=="no"});return i}}function ms(n,e,t,i){if(i!=null&&i.inlineSource){const s=xm(e,t),o=n.linePos>0?`${" ".repeat(n.linePos+5)}^^^
1
+ (function(le,ze){typeof exports=="object"&&typeof module<"u"?ze(exports):typeof define=="function"&&define.amd?define(["exports"],ze):(le=typeof globalThis<"u"?globalThis:le||self,ze(le.Cosmos={}))})(this,function(le){"use strict";var Qv=Object.defineProperty;var Jv=(le,ze,Bt)=>ze in le?Qv(le,ze,{enumerable:!0,configurable:!0,writable:!0,value:Bt}):le[ze]=Bt;var m=(le,ze,Bt)=>Jv(le,typeof ze!="symbol"?ze+"":ze,Bt);var ze="http://www.w3.org/1999/xhtml";const Bt={svg:"http://www.w3.org/2000/svg",xhtml:ze,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function li(n){var e=n+="",t=e.indexOf(":");return t>=0&&(e=n.slice(0,t))!=="xmlns"&&(n=n.slice(t+1)),Bt.hasOwnProperty(e)?{space:Bt[e],local:n}:n}function Xu(n){return function(){var e=this.ownerDocument,t=this.namespaceURI;return t===ze&&e.documentElement.namespaceURI===ze?e.createElement(n):e.createElementNS(t,n)}}function Yu(n){return function(){return this.ownerDocument.createElementNS(n.space,n.local)}}function Xo(n){var e=li(n);return(e.local?Yu:Xu)(e)}function qu(){}function $r(n){return n==null?qu:function(){return this.querySelector(n)}}function ju(n){typeof n!="function"&&(n=$r(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=new Array(o),l,c,u=0;u<o;++u)(l=s[u])&&(c=n.call(l,l.__data__,u,s))&&("__data__"in l&&(c.__data__=l.__data__),a[u]=c);return new qe(i,this._parents)}function Ku(n){return n==null?[]:Array.isArray(n)?n:Array.from(n)}function Zu(){return[]}function Yo(n){return n==null?Zu:function(){return this.querySelectorAll(n)}}function Qu(n){return function(){return Ku(n.apply(this,arguments))}}function Ju(n){typeof n=="function"?n=Qu(n):n=Yo(n);for(var e=this._groups,t=e.length,i=[],r=[],s=0;s<t;++s)for(var o=e[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&(i.push(n.call(l,l.__data__,c,o)),r.push(l));return new qe(i,r)}function qo(n){return function(){return this.matches(n)}}function jo(n){return function(e){return e.matches(n)}}var Gu=Array.prototype.find;function ef(n){return function(){return Gu.call(this.children,n)}}function tf(){return this.firstElementChild}function nf(n){return this.select(n==null?tf:ef(typeof n=="function"?n:jo(n)))}var rf=Array.prototype.filter;function sf(){return Array.from(this.children)}function of(n){return function(){return rf.call(this.children,n)}}function af(n){return this.selectAll(n==null?sf:of(typeof n=="function"?n:jo(n)))}function lf(n){typeof n!="function"&&(n=qo(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=[],l,c=0;c<o;++c)(l=s[c])&&n.call(l,l.__data__,c,s)&&a.push(l);return new qe(i,this._parents)}function Ko(n){return new Array(n.length)}function cf(){return new qe(this._enter||this._groups.map(Ko),this._parents)}function ci(n,e){this.ownerDocument=n.ownerDocument,this.namespaceURI=n.namespaceURI,this._next=null,this._parent=n,this.__data__=e}ci.prototype={constructor:ci,appendChild:function(n){return this._parent.insertBefore(n,this._next)},insertBefore:function(n,e){return this._parent.insertBefore(n,e)},querySelector:function(n){return this._parent.querySelector(n)},querySelectorAll:function(n){return this._parent.querySelectorAll(n)}};function uf(n){return function(){return n}}function ff(n,e,t,i,r,s){for(var o=0,a,l=e.length,c=s.length;o<c;++o)(a=e[o])?(a.__data__=s[o],i[o]=a):t[o]=new ci(n,s[o]);for(;o<l;++o)(a=e[o])&&(r[o]=a)}function hf(n,e,t,i,r,s,o){var a,l,c=new Map,u=e.length,f=s.length,h=new Array(u),d;for(a=0;a<u;++a)(l=e[a])&&(h[a]=d=o.call(l,l.__data__,a,e)+"",c.has(d)?r[a]=l:c.set(d,l));for(a=0;a<f;++a)d=o.call(n,s[a],a,s)+"",(l=c.get(d))?(i[a]=l,l.__data__=s[a],c.delete(d)):t[a]=new ci(n,s[a]);for(a=0;a<u;++a)(l=e[a])&&c.get(h[a])===l&&(r[a]=l)}function df(n){return n.__data__}function pf(n,e){if(!arguments.length)return Array.from(this,df);var t=e?hf:ff,i=this._parents,r=this._groups;typeof n!="function"&&(n=uf(n));for(var s=r.length,o=new Array(s),a=new Array(s),l=new Array(s),c=0;c<s;++c){var u=i[c],f=r[c],h=f.length,d=mf(n.call(u,u&&u.__data__,c,i)),_=d.length,I=a[c]=new Array(_),P=o[c]=new Array(_),A=l[c]=new Array(h);t(u,f,I,P,A,d,e);for(var O=0,E=0,y,R;O<_;++O)if(y=I[O]){for(O>=E&&(E=O+1);!(R=P[E])&&++E<_;);y._next=R||null}}return o=new qe(o,i),o._enter=a,o._exit=l,o}function mf(n){return typeof n=="object"&&"length"in n?n:Array.from(n)}function gf(){return new qe(this._exit||this._groups.map(Ko),this._parents)}function _f(n,e,t){var i=this.enter(),r=this,s=this.exit();return typeof n=="function"?(i=n(i),i&&(i=i.selection())):i=i.append(n+""),e!=null&&(r=e(r),r&&(r=r.selection())),t==null?s.remove():t(s),i&&r?i.merge(r).order():r}function xf(n){for(var e=n.selection?n.selection():n,t=this._groups,i=e._groups,r=t.length,s=i.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var c=t[l],u=i[l],f=c.length,h=a[l]=new Array(f),d,_=0;_<f;++_)(d=c[_]||u[_])&&(h[_]=d);for(;l<r;++l)a[l]=t[l];return new qe(a,this._parents)}function yf(){for(var n=this._groups,e=-1,t=n.length;++e<t;)for(var i=n[e],r=i.length-1,s=i[r],o;--r>=0;)(o=i[r])&&(s&&o.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(o,s),s=o);return this}function vf(n){n||(n=bf);function e(f,h){return f&&h?n(f.__data__,h.__data__):!f-!h}for(var t=this._groups,i=t.length,r=new Array(i),s=0;s<i;++s){for(var o=t[s],a=o.length,l=r[s]=new Array(a),c,u=0;u<a;++u)(c=o[u])&&(l[u]=c);l.sort(e)}return new qe(r,this._parents).order()}function bf(n,e){return n<e?-1:n>e?1:n>=e?0:NaN}function Sf(){var n=arguments[0];return arguments[0]=this,n.apply(null,arguments),this}function Tf(){return Array.from(this)}function wf(){for(var n=this._groups,e=0,t=n.length;e<t;++e)for(var i=n[e],r=0,s=i.length;r<s;++r){var o=i[r];if(o)return o}return null}function Af(){let n=0;for(const e of this)++n;return n}function Cf(){return!this.node()}function If(n){for(var e=this._groups,t=0,i=e.length;t<i;++t)for(var r=e[t],s=0,o=r.length,a;s<o;++s)(a=r[s])&&n.call(a,a.__data__,s,r);return this}function Pf(n){return function(){this.removeAttribute(n)}}function Ef(n){return function(){this.removeAttributeNS(n.space,n.local)}}function Rf(n,e){return function(){this.setAttribute(n,e)}}function kf(n,e){return function(){this.setAttributeNS(n.space,n.local,e)}}function Df(n,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttribute(n):this.setAttribute(n,t)}}function Ff(n,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttributeNS(n.space,n.local):this.setAttributeNS(n.space,n.local,t)}}function Mf(n,e){var t=li(n);if(arguments.length<2){var i=this.node();return t.local?i.getAttributeNS(t.space,t.local):i.getAttribute(t)}return this.each((e==null?t.local?Ef:Pf:typeof e=="function"?t.local?Ff:Df:t.local?kf:Rf)(t,e))}function Zo(n){return n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView}function Nf(n){return function(){this.style.removeProperty(n)}}function Of(n,e,t){return function(){this.style.setProperty(n,e,t)}}function Bf(n,e,t){return function(){var i=e.apply(this,arguments);i==null?this.style.removeProperty(n):this.style.setProperty(n,i,t)}}function Uf(n,e,t){return arguments.length>1?this.each((e==null?Nf:typeof e=="function"?Bf:Of)(n,e,t??"")):nn(this.node(),n)}function nn(n,e){return n.style.getPropertyValue(e)||Zo(n).getComputedStyle(n,null).getPropertyValue(e)}function zf(n){return function(){delete this[n]}}function Lf(n,e){return function(){this[n]=e}}function Vf(n,e){return function(){var t=e.apply(this,arguments);t==null?delete this[n]:this[n]=t}}function Hf(n,e){return arguments.length>1?this.each((e==null?zf:typeof e=="function"?Vf:Lf)(n,e)):this.node()[n]}function Qo(n){return n.trim().split(/^|\s+/)}function Xr(n){return n.classList||new Jo(n)}function Jo(n){this._node=n,this._names=Qo(n.getAttribute("class")||"")}Jo.prototype={add:function(n){var e=this._names.indexOf(n);e<0&&(this._names.push(n),this._node.setAttribute("class",this._names.join(" ")))},remove:function(n){var e=this._names.indexOf(n);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(n){return this._names.indexOf(n)>=0}};function Go(n,e){for(var t=Xr(n),i=-1,r=e.length;++i<r;)t.add(e[i])}function ea(n,e){for(var t=Xr(n),i=-1,r=e.length;++i<r;)t.remove(e[i])}function Wf(n){return function(){Go(this,n)}}function $f(n){return function(){ea(this,n)}}function Xf(n,e){return function(){(e.apply(this,arguments)?Go:ea)(this,n)}}function Yf(n,e){var t=Qo(n+"");if(arguments.length<2){for(var i=Xr(this.node()),r=-1,s=t.length;++r<s;)if(!i.contains(t[r]))return!1;return!0}return this.each((typeof e=="function"?Xf:e?Wf:$f)(t,e))}function qf(){this.textContent=""}function jf(n){return function(){this.textContent=n}}function Kf(n){return function(){var e=n.apply(this,arguments);this.textContent=e??""}}function Zf(n){return arguments.length?this.each(n==null?qf:(typeof n=="function"?Kf:jf)(n)):this.node().textContent}function Qf(){this.innerHTML=""}function Jf(n){return function(){this.innerHTML=n}}function Gf(n){return function(){var e=n.apply(this,arguments);this.innerHTML=e??""}}function eh(n){return arguments.length?this.each(n==null?Qf:(typeof n=="function"?Gf:Jf)(n)):this.node().innerHTML}function th(){this.nextSibling&&this.parentNode.appendChild(this)}function nh(){return this.each(th)}function ih(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function rh(){return this.each(ih)}function sh(n){var e=typeof n=="function"?n:Xo(n);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function oh(){return null}function ah(n,e){var t=typeof n=="function"?n:Xo(n),i=e==null?oh:typeof e=="function"?e:$r(e);return this.select(function(){return this.insertBefore(t.apply(this,arguments),i.apply(this,arguments)||null)})}function lh(){var n=this.parentNode;n&&n.removeChild(this)}function ch(){return this.each(lh)}function uh(){var n=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(n,this.nextSibling):n}function fh(){var n=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(n,this.nextSibling):n}function hh(n){return this.select(n?fh:uh)}function dh(n){return arguments.length?this.property("__data__",n):this.node().__data__}function ph(n){return function(e){n.call(this,e,this.__data__)}}function mh(n){return n.trim().split(/^|\s+/).map(function(e){var t="",i=e.indexOf(".");return i>=0&&(t=e.slice(i+1),e=e.slice(0,i)),{type:e,name:t}})}function gh(n){return function(){var e=this.__on;if(e){for(var t=0,i=-1,r=e.length,s;t<r;++t)s=e[t],(!n.type||s.type===n.type)&&s.name===n.name?this.removeEventListener(s.type,s.listener,s.options):e[++i]=s;++i?e.length=i:delete this.__on}}}function _h(n,e,t){return function(){var i=this.__on,r,s=ph(e);if(i){for(var o=0,a=i.length;o<a;++o)if((r=i[o]).type===n.type&&r.name===n.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=s,r.options=t),r.value=e;return}}this.addEventListener(n.type,s,t),r={type:n.type,name:n.name,value:e,listener:s,options:t},i?i.push(r):this.__on=[r]}}function xh(n,e,t){var i=mh(n+""),r,s=i.length,o;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,c=a.length,u;l<c;++l)for(r=0,u=a[l];r<s;++r)if((o=i[r]).type===u.type&&o.name===u.name)return u.value}return}for(a=e?_h:gh,r=0;r<s;++r)this.each(a(i[r],e,t));return this}function ta(n,e,t){var i=Zo(n),r=i.CustomEvent;typeof r=="function"?r=new r(e,t):(r=i.document.createEvent("Event"),t?(r.initEvent(e,t.bubbles,t.cancelable),r.detail=t.detail):r.initEvent(e,!1,!1)),n.dispatchEvent(r)}function yh(n,e){return function(){return ta(this,n,e)}}function vh(n,e){return function(){return ta(this,n,e.apply(this,arguments))}}function bh(n,e){return this.each((typeof e=="function"?vh:yh)(n,e))}function*Sh(){for(var n=this._groups,e=0,t=n.length;e<t;++e)for(var i=n[e],r=0,s=i.length,o;r<s;++r)(o=i[r])&&(yield o)}var na=[null];function qe(n,e){this._groups=n,this._parents=e}function Pn(){return new qe([[document.documentElement]],na)}function Th(){return this}qe.prototype=Pn.prototype={constructor:qe,select:ju,selectAll:Ju,selectChild:nf,selectChildren:af,filter:lf,data:pf,enter:cf,exit:gf,join:_f,merge:xf,selection:Th,order:yf,sort:vf,call:Sf,nodes:Tf,node:wf,size:Af,empty:Cf,each:If,attr:Mf,style:Uf,property:Hf,classed:Yf,text:Zf,html:eh,raise:nh,lower:rh,append:sh,insert:ah,remove:ch,clone:hh,datum:dh,on:xh,dispatch:bh,[Symbol.iterator]:Sh};function we(n){return typeof n=="string"?new qe([[document.querySelector(n)]],[document.documentElement]):new qe([[n]],na)}function wh(n){let e;for(;e=n.sourceEvent;)n=e;return n}function vt(n,e){if(n=wh(n),e===void 0&&(e=n.currentTarget),e){var t=e.ownerSVGElement||e;if(t.createSVGPoint){var i=t.createSVGPoint();return i.x=n.clientX,i.y=n.clientY,i=i.matrixTransform(e.getScreenCTM().inverse()),[i.x,i.y]}if(e.getBoundingClientRect){var r=e.getBoundingClientRect();return[n.clientX-r.left-e.clientLeft,n.clientY-r.top-e.clientTop]}}return[n.pageX,n.pageY]}var Ah={value:()=>{}};function ui(){for(var n=0,e=arguments.length,t={},i;n<e;++n){if(!(i=arguments[n]+"")||i in t||/[\s.]/.test(i))throw new Error("illegal type: "+i);t[i]=[]}return new fi(t)}function fi(n){this._=n}function Ch(n,e){return n.trim().split(/^|\s+/).map(function(t){var i="",r=t.indexOf(".");if(r>=0&&(i=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:i}})}fi.prototype=ui.prototype={constructor:fi,on:function(n,e){var t=this._,i=Ch(n+"",t),r,s=-1,o=i.length;if(arguments.length<2){for(;++s<o;)if((r=(n=i[s]).type)&&(r=Ih(t[r],n.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++s<o;)if(r=(n=i[s]).type)t[r]=ia(t[r],n.name,e);else if(e==null)for(r in t)t[r]=ia(t[r],n.name,null);return this},copy:function(){var n={},e=this._;for(var t in e)n[t]=e[t].slice();return new fi(n)},call:function(n,e){if((r=arguments.length-2)>0)for(var t=new Array(r),i=0,r,s;i<r;++i)t[i]=arguments[i+2];if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(s=this._[n],i=0,r=s.length;i<r;++i)s[i].value.apply(e,t)},apply:function(n,e,t){if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(var i=this._[n],r=0,s=i.length;r<s;++r)i[r].value.apply(e,t)}};function Ih(n,e){for(var t=0,i=n.length,r;t<i;++t)if((r=n[t]).name===e)return r.value}function ia(n,e,t){for(var i=0,r=n.length;i<r;++i)if(n[i].name===e){n[i]=Ah,n=n.slice(0,i).concat(n.slice(i+1));break}return t!=null&&n.push({name:e,value:t}),n}var rn=0,En=0,Rn=0,ra=1e3,hi,kn,di=0,Ut=0,pi=0,Dn=typeof performance=="object"&&performance.now?performance:Date,sa=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(n){setTimeout(n,17)};function Yr(){return Ut||(sa(Ph),Ut=Dn.now()+pi)}function Ph(){Ut=0}function mi(){this._call=this._time=this._next=null}mi.prototype=oa.prototype={constructor:mi,restart:function(n,e,t){if(typeof n!="function")throw new TypeError("callback is not a function");t=(t==null?Yr():+t)+(e==null?0:+e),!this._next&&kn!==this&&(kn?kn._next=this:hi=this,kn=this),this._call=n,this._time=t,qr()},stop:function(){this._call&&(this._call=null,this._time=1/0,qr())}};function oa(n,e,t){var i=new mi;return i.restart(n,e,t),i}function Eh(){Yr(),++rn;for(var n=hi,e;n;)(e=Ut-n._time)>=0&&n._call.call(null,e),n=n._next;--rn}function aa(){Ut=(di=Dn.now())+pi,rn=En=0;try{Eh()}finally{rn=0,kh(),Ut=0}}function Rh(){var n=Dn.now(),e=n-di;e>ra&&(pi-=e,di=n)}function kh(){for(var n,e=hi,t,i=1/0;e;)e._call?(i>e._time&&(i=e._time),n=e,e=e._next):(t=e._next,e._next=null,e=n?n._next=t:hi=t);kn=n,qr(i)}function qr(n){if(!rn){En&&(En=clearTimeout(En));var e=n-Ut;e>24?(n<1/0&&(En=setTimeout(aa,n-Dn.now()-pi)),Rn&&(Rn=clearInterval(Rn))):(Rn||(di=Dn.now(),Rn=setInterval(Rh,ra)),rn=1,sa(aa))}}function la(n,e,t){var i=new mi;return e=e==null?0:+e,i.restart(r=>{i.stop(),n(r+e)},e,t),i}var Dh=ui("start","end","cancel","interrupt"),Fh=[],ca=0,ua=1,jr=2,gi=3,fa=4,Kr=5,_i=6;function xi(n,e,t,i,r,s){var o=n.__transition;if(!o)n.__transition={};else if(t in o)return;Mh(n,t,{name:e,index:i,group:r,on:Dh,tween:Fh,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:ca})}function Zr(n,e){var t=it(n,e);if(t.state>ca)throw new Error("too late; already scheduled");return t}function ut(n,e){var t=it(n,e);if(t.state>gi)throw new Error("too late; already running");return t}function it(n,e){var t=n.__transition;if(!t||!(t=t[e]))throw new Error("transition not found");return t}function Mh(n,e,t){var i=n.__transition,r;i[e]=t,t.timer=oa(s,0,t.time);function s(c){t.state=ua,t.timer.restart(o,t.delay,t.time),t.delay<=c&&o(c-t.delay)}function o(c){var u,f,h,d;if(t.state!==ua)return l();for(u in i)if(d=i[u],d.name===t.name){if(d.state===gi)return la(o);d.state===fa?(d.state=_i,d.timer.stop(),d.on.call("interrupt",n,n.__data__,d.index,d.group),delete i[u]):+u<e&&(d.state=_i,d.timer.stop(),d.on.call("cancel",n,n.__data__,d.index,d.group),delete i[u])}if(la(function(){t.state===gi&&(t.state=fa,t.timer.restart(a,t.delay,t.time),a(c))}),t.state=jr,t.on.call("start",n,n.__data__,t.index,t.group),t.state===jr){for(t.state=gi,r=new Array(h=t.tween.length),u=0,f=-1;u<h;++u)(d=t.tween[u].value.call(n,n.__data__,t.index,t.group))&&(r[++f]=d);r.length=f+1}}function a(c){for(var u=c<t.duration?t.ease.call(null,c/t.duration):(t.timer.restart(l),t.state=Kr,1),f=-1,h=r.length;++f<h;)r[f].call(n,u);t.state===Kr&&(t.on.call("end",n,n.__data__,t.index,t.group),l())}function l(){t.state=_i,t.timer.stop(),delete i[e];for(var c in i)return;delete n.__transition}}function yi(n,e){var t=n.__transition,i,r,s=!0,o;if(t){e=e==null?null:e+"";for(o in t){if((i=t[o]).name!==e){s=!1;continue}r=i.state>jr&&i.state<Kr,i.state=_i,i.timer.stop(),i.on.call(r?"interrupt":"cancel",n,n.__data__,i.index,i.group),delete t[o]}s&&delete n.__transition}}function Nh(n){return this.each(function(){yi(this,n)})}function Qr(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function ha(n,e){var t=Object.create(n.prototype);for(var i in e)t[i]=e[i];return t}function Fn(){}var Mn=.7,vi=1/Mn,sn="\\s*([+-]?\\d+)\\s*",Nn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ft="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Oh=/^#([0-9a-f]{3,8})$/,Bh=new RegExp(`^rgb\\(${sn},${sn},${sn}\\)$`),Uh=new RegExp(`^rgb\\(${ft},${ft},${ft}\\)$`),zh=new RegExp(`^rgba\\(${sn},${sn},${sn},${Nn}\\)$`),Lh=new RegExp(`^rgba\\(${ft},${ft},${ft},${Nn}\\)$`),Vh=new RegExp(`^hsl\\(${Nn},${ft},${ft}\\)$`),Hh=new RegExp(`^hsla\\(${Nn},${ft},${ft},${Nn}\\)$`),da={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Qr(Fn,Dt,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:pa,formatHex:pa,formatHex8:Wh,formatHsl:$h,formatRgb:ma,toString:ma});function pa(){return this.rgb().formatHex()}function Wh(){return this.rgb().formatHex8()}function $h(){return va(this).formatHsl()}function ma(){return this.rgb().formatRgb()}function Dt(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=Oh.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?ga(e):t===3?new Xe(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?bi(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?bi(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=Bh.exec(n))?new Xe(e[1],e[2],e[3],1):(e=Uh.exec(n))?new Xe(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=zh.exec(n))?bi(e[1],e[2],e[3],e[4]):(e=Lh.exec(n))?bi(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Vh.exec(n))?ya(e[1],e[2]/100,e[3]/100,1):(e=Hh.exec(n))?ya(e[1],e[2]/100,e[3]/100,e[4]):da.hasOwnProperty(n)?ga(da[n]):n==="transparent"?new Xe(NaN,NaN,NaN,0):null}function ga(n){return new Xe(n>>16&255,n>>8&255,n&255,1)}function bi(n,e,t,i){return i<=0&&(n=e=t=NaN),new Xe(n,e,t,i)}function Xh(n){return n instanceof Fn||(n=Dt(n)),n?(n=n.rgb(),new Xe(n.r,n.g,n.b,n.opacity)):new Xe}function Jr(n,e,t,i){return arguments.length===1?Xh(n):new Xe(n,e,t,i??1)}function Xe(n,e,t,i){this.r=+n,this.g=+e,this.b=+t,this.opacity=+i}Qr(Xe,Jr,ha(Fn,{brighter(n){return n=n==null?vi:Math.pow(vi,n),new Xe(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?Mn:Math.pow(Mn,n),new Xe(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new Xe(zt(this.r),zt(this.g),zt(this.b),Si(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:_a,formatHex:_a,formatHex8:Yh,formatRgb:xa,toString:xa}));function _a(){return`#${Lt(this.r)}${Lt(this.g)}${Lt(this.b)}`}function Yh(){return`#${Lt(this.r)}${Lt(this.g)}${Lt(this.b)}${Lt((isNaN(this.opacity)?1:this.opacity)*255)}`}function xa(){const n=Si(this.opacity);return`${n===1?"rgb(":"rgba("}${zt(this.r)}, ${zt(this.g)}, ${zt(this.b)}${n===1?")":`, ${n})`}`}function Si(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function zt(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function Lt(n){return n=zt(n),(n<16?"0":"")+n.toString(16)}function ya(n,e,t,i){return i<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new rt(n,e,t,i)}function va(n){if(n instanceof rt)return new rt(n.h,n.s,n.l,n.opacity);if(n instanceof Fn||(n=Dt(n)),!n)return new rt;if(n instanceof rt)return n;n=n.rgb();var e=n.r/255,t=n.g/255,i=n.b/255,r=Math.min(e,t,i),s=Math.max(e,t,i),o=NaN,a=s-r,l=(s+r)/2;return a?(e===s?o=(t-i)/a+(t<i)*6:t===s?o=(i-e)/a+2:o=(e-t)/a+4,a/=l<.5?s+r:2-s-r,o*=60):a=l>0&&l<1?0:o,new rt(o,a,l,n.opacity)}function qh(n,e,t,i){return arguments.length===1?va(n):new rt(n,e,t,i??1)}function rt(n,e,t,i){this.h=+n,this.s=+e,this.l=+t,this.opacity=+i}Qr(rt,qh,ha(Fn,{brighter(n){return n=n==null?vi:Math.pow(vi,n),new rt(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?Mn:Math.pow(Mn,n),new rt(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,i=t+(t<.5?t:1-t)*e,r=2*t-i;return new Xe(Gr(n>=240?n-240:n+120,r,i),Gr(n,r,i),Gr(n<120?n+240:n-120,r,i),this.opacity)},clamp(){return new rt(ba(this.h),Ti(this.s),Ti(this.l),Si(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=Si(this.opacity);return`${n===1?"hsl(":"hsla("}${ba(this.h)}, ${Ti(this.s)*100}%, ${Ti(this.l)*100}%${n===1?")":`, ${n})`}`}}));function ba(n){return n=(n||0)%360,n<0?n+360:n}function Ti(n){return Math.max(0,Math.min(1,n||0))}function Gr(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const es=n=>()=>n;function jh(n,e){return function(t){return n+t*e}}function Kh(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(i){return Math.pow(n+i*e,t)}}function Zh(n){return(n=+n)==1?Sa:function(e,t){return t-e?Kh(e,t,n):es(isNaN(e)?t:e)}}function Sa(n,e){var t=e-n;return t?jh(n,t):es(isNaN(n)?e:n)}const wi=function n(e){var t=Zh(e);function i(r,s){var o=t((r=Jr(r)).r,(s=Jr(s)).r),a=t(r.g,s.g),l=t(r.b,s.b),c=Sa(r.opacity,s.opacity);return function(u){return r.r=o(u),r.g=a(u),r.b=l(u),r.opacity=c(u),r+""}}return i.gamma=n,i}(1);function Qh(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,i=e.slice(),r;return function(s){for(r=0;r<t;++r)i[r]=n[r]*(1-s)+e[r]*s;return i}}function Jh(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Gh(n,e){var t=e?e.length:0,i=n?Math.min(t,n.length):0,r=new Array(i),s=new Array(t),o;for(o=0;o<i;++o)r[o]=is(n[o],e[o]);for(;o<t;++o)s[o]=e[o];return function(a){for(o=0;o<i;++o)s[o]=r[o](a);return s}}function ed(n,e){var t=new Date;return n=+n,e=+e,function(i){return t.setTime(n*(1-i)+e*i),t}}function st(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function td(n,e){var t={},i={},r;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in n?t[r]=is(n[r],e[r]):i[r]=e[r];return function(s){for(r in t)i[r]=t[r](s);return i}}var ts=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ns=new RegExp(ts.source,"g");function nd(n){return function(){return n}}function id(n){return function(e){return n(e)+""}}function Ta(n,e){var t=ts.lastIndex=ns.lastIndex=0,i,r,s,o=-1,a=[],l=[];for(n=n+"",e=e+"";(i=ts.exec(n))&&(r=ns.exec(e));)(s=r.index)>t&&(s=e.slice(t,s),a[o]?a[o]+=s:a[++o]=s),(i=i[0])===(r=r[0])?a[o]?a[o]+=r:a[++o]=r:(a[++o]=null,l.push({i:o,x:st(i,r)})),t=ns.lastIndex;return t<e.length&&(s=e.slice(t),a[o]?a[o]+=s:a[++o]=s),a.length<2?l[0]?id(l[0].x):nd(e):(e=l.length,function(c){for(var u=0,f;u<e;++u)a[(f=l[u]).i]=f.x(c);return a.join("")})}function is(n,e){var t=typeof e,i;return e==null||t==="boolean"?es(e):(t==="number"?st:t==="string"?(i=Dt(e))?(e=i,wi):Ta:e instanceof Dt?wi:e instanceof Date?ed:Jh(e)?Qh:Array.isArray(e)?Gh:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?td:st)(n,e)}function rd(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}var wa=180/Math.PI,rs={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Aa(n,e,t,i,r,s){var o,a,l;return(o=Math.sqrt(n*n+e*e))&&(n/=o,e/=o),(l=n*t+e*i)&&(t-=n*l,i-=e*l),(a=Math.sqrt(t*t+i*i))&&(t/=a,i/=a,l/=a),n*i<e*t&&(n=-n,e=-e,l=-l,o=-o),{translateX:r,translateY:s,rotate:Math.atan2(e,n)*wa,skewX:Math.atan(l)*wa,scaleX:o,scaleY:a}}var Ai;function sd(n){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(n+"");return e.isIdentity?rs:Aa(e.a,e.b,e.c,e.d,e.e,e.f)}function od(n){return n==null||(Ai||(Ai=document.createElementNS("http://www.w3.org/2000/svg","g")),Ai.setAttribute("transform",n),!(n=Ai.transform.baseVal.consolidate()))?rs:(n=n.matrix,Aa(n.a,n.b,n.c,n.d,n.e,n.f))}function Ca(n,e,t,i){function r(c){return c.length?c.pop()+" ":""}function s(c,u,f,h,d,_){if(c!==f||u!==h){var I=d.push("translate(",null,e,null,t);_.push({i:I-4,x:st(c,f)},{i:I-2,x:st(u,h)})}else(f||h)&&d.push("translate("+f+e+h+t)}function o(c,u,f,h){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),h.push({i:f.push(r(f)+"rotate(",null,i)-2,x:st(c,u)})):u&&f.push(r(f)+"rotate("+u+i)}function a(c,u,f,h){c!==u?h.push({i:f.push(r(f)+"skewX(",null,i)-2,x:st(c,u)}):u&&f.push(r(f)+"skewX("+u+i)}function l(c,u,f,h,d,_){if(c!==f||u!==h){var I=d.push(r(d)+"scale(",null,",",null,")");_.push({i:I-4,x:st(c,f)},{i:I-2,x:st(u,h)})}else(f!==1||h!==1)&&d.push(r(d)+"scale("+f+","+h+")")}return function(c,u){var f=[],h=[];return c=n(c),u=n(u),s(c.translateX,c.translateY,u.translateX,u.translateY,f,h),o(c.rotate,u.rotate,f,h),a(c.skewX,u.skewX,f,h),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,f,h),c=u=null,function(d){for(var _=-1,I=h.length,P;++_<I;)f[(P=h[_]).i]=P.x(d);return f.join("")}}}var ad=Ca(sd,"px, ","px)","deg)"),ld=Ca(od,", ",")",")"),cd=1e-12;function Ia(n){return((n=Math.exp(n))+1/n)/2}function ud(n){return((n=Math.exp(n))-1/n)/2}function fd(n){return((n=Math.exp(2*n))-1)/(n+1)}const hd=function n(e,t,i){function r(s,o){var a=s[0],l=s[1],c=s[2],u=o[0],f=o[1],h=o[2],d=u-a,_=f-l,I=d*d+_*_,P,A;if(I<cd)A=Math.log(h/c)/e,P=function(U){return[a+U*d,l+U*_,c*Math.exp(e*U*A)]};else{var O=Math.sqrt(I),E=(h*h-c*c+i*I)/(2*c*t*O),y=(h*h-c*c-i*I)/(2*h*t*O),R=Math.log(Math.sqrt(E*E+1)-E),N=Math.log(Math.sqrt(y*y+1)-y);A=(N-R)/e,P=function(U){var H=U*A,Y=Ia(R),Z=c/(t*O)*(Y*fd(e*H+R)-ud(R));return[a+Z*d,l+Z*_,c*Y/Ia(e*H+R)]}}return P.duration=A*1e3*e/Math.SQRT2,P}return r.rho=function(s){var o=Math.max(.001,+s),a=o*o,l=a*a;return n(o,a,l)},r}(Math.SQRT2,2,4);function dd(n,e){var t,i;return function(){var r=ut(this,n),s=r.tween;if(s!==t){i=t=s;for(var o=0,a=i.length;o<a;++o)if(i[o].name===e){i=i.slice(),i.splice(o,1);break}}r.tween=i}}function pd(n,e,t){var i,r;if(typeof t!="function")throw new Error;return function(){var s=ut(this,n),o=s.tween;if(o!==i){r=(i=o).slice();for(var a={name:e,value:t},l=0,c=r.length;l<c;++l)if(r[l].name===e){r[l]=a;break}l===c&&r.push(a)}s.tween=r}}function md(n,e){var t=this._id;if(n+="",arguments.length<2){for(var i=it(this.node(),t).tween,r=0,s=i.length,o;r<s;++r)if((o=i[r]).name===n)return o.value;return null}return this.each((e==null?dd:pd)(t,n,e))}function ss(n,e,t){var i=n._id;return n.each(function(){var r=ut(this,i);(r.value||(r.value={}))[e]=t.apply(this,arguments)}),function(r){return it(r,i).value[e]}}function Pa(n,e){var t;return(typeof e=="number"?st:e instanceof Dt?wi:(t=Dt(e))?(e=t,wi):Ta)(n,e)}function gd(n){return function(){this.removeAttribute(n)}}function _d(n){return function(){this.removeAttributeNS(n.space,n.local)}}function xd(n,e,t){var i,r=t+"",s;return function(){var o=this.getAttribute(n);return o===r?null:o===i?s:s=e(i=o,t)}}function yd(n,e,t){var i,r=t+"",s;return function(){var o=this.getAttributeNS(n.space,n.local);return o===r?null:o===i?s:s=e(i=o,t)}}function vd(n,e,t){var i,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttribute(n):(o=this.getAttribute(n),l=a+"",o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a)))}}function bd(n,e,t){var i,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttributeNS(n.space,n.local):(o=this.getAttributeNS(n.space,n.local),l=a+"",o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a)))}}function Sd(n,e){var t=li(n),i=t==="transform"?ld:Pa;return this.attrTween(n,typeof e=="function"?(t.local?bd:vd)(t,i,ss(this,"attr."+n,e)):e==null?(t.local?_d:gd)(t):(t.local?yd:xd)(t,i,e))}function Td(n,e){return function(t){this.setAttribute(n,e.call(this,t))}}function wd(n,e){return function(t){this.setAttributeNS(n.space,n.local,e.call(this,t))}}function Ad(n,e){var t,i;function r(){var s=e.apply(this,arguments);return s!==i&&(t=(i=s)&&wd(n,s)),t}return r._value=e,r}function Cd(n,e){var t,i;function r(){var s=e.apply(this,arguments);return s!==i&&(t=(i=s)&&Td(n,s)),t}return r._value=e,r}function Id(n,e){var t="attr."+n;if(arguments.length<2)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;var i=li(n);return this.tween(t,(i.local?Ad:Cd)(i,e))}function Pd(n,e){return function(){Zr(this,n).delay=+e.apply(this,arguments)}}function Ed(n,e){return e=+e,function(){Zr(this,n).delay=e}}function Rd(n){var e=this._id;return arguments.length?this.each((typeof n=="function"?Pd:Ed)(e,n)):it(this.node(),e).delay}function kd(n,e){return function(){ut(this,n).duration=+e.apply(this,arguments)}}function Dd(n,e){return e=+e,function(){ut(this,n).duration=e}}function Fd(n){var e=this._id;return arguments.length?this.each((typeof n=="function"?kd:Dd)(e,n)):it(this.node(),e).duration}function Md(n,e){if(typeof e!="function")throw new Error;return function(){ut(this,n).ease=e}}function Nd(n){var e=this._id;return arguments.length?this.each(Md(e,n)):it(this.node(),e).ease}function Od(n,e){return function(){var t=e.apply(this,arguments);if(typeof t!="function")throw new Error;ut(this,n).ease=t}}function Bd(n){if(typeof n!="function")throw new Error;return this.each(Od(this._id,n))}function Ud(n){typeof n!="function"&&(n=qo(n));for(var e=this._groups,t=e.length,i=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=i[r]=[],l,c=0;c<o;++c)(l=s[c])&&n.call(l,l.__data__,c,s)&&a.push(l);return new bt(i,this._parents,this._name,this._id)}function zd(n){if(n._id!==this._id)throw new Error;for(var e=this._groups,t=n._groups,i=e.length,r=t.length,s=Math.min(i,r),o=new Array(i),a=0;a<s;++a)for(var l=e[a],c=t[a],u=l.length,f=o[a]=new Array(u),h,d=0;d<u;++d)(h=l[d]||c[d])&&(f[d]=h);for(;a<i;++a)o[a]=e[a];return new bt(o,this._parents,this._name,this._id)}function Ld(n){return(n+"").trim().split(/^|\s+/).every(function(e){var t=e.indexOf(".");return t>=0&&(e=e.slice(0,t)),!e||e==="start"})}function Vd(n,e,t){var i,r,s=Ld(e)?Zr:ut;return function(){var o=s(this,n),a=o.on;a!==i&&(r=(i=a).copy()).on(e,t),o.on=r}}function Hd(n,e){var t=this._id;return arguments.length<2?it(this.node(),t).on.on(n):this.each(Vd(t,n,e))}function Wd(n){return function(){var e=this.parentNode;for(var t in this.__transition)if(+t!==n)return;e&&e.removeChild(this)}}function $d(){return this.on("end.remove",Wd(this._id))}function Xd(n){var e=this._name,t=this._id;typeof n!="function"&&(n=$r(n));for(var i=this._groups,r=i.length,s=new Array(r),o=0;o<r;++o)for(var a=i[o],l=a.length,c=s[o]=new Array(l),u,f,h=0;h<l;++h)(u=a[h])&&(f=n.call(u,u.__data__,h,a))&&("__data__"in u&&(f.__data__=u.__data__),c[h]=f,xi(c[h],e,t,h,c,it(u,t)));return new bt(s,this._parents,e,t)}function Yd(n){var e=this._name,t=this._id;typeof n!="function"&&(n=Yo(n));for(var i=this._groups,r=i.length,s=[],o=[],a=0;a<r;++a)for(var l=i[a],c=l.length,u,f=0;f<c;++f)if(u=l[f]){for(var h=n.call(u,u.__data__,f,l),d,_=it(u,t),I=0,P=h.length;I<P;++I)(d=h[I])&&xi(d,e,t,I,h,_);s.push(h),o.push(u)}return new bt(s,o,e,t)}var qd=Pn.prototype.constructor;function jd(){return new qd(this._groups,this._parents)}function Kd(n,e){var t,i,r;return function(){var s=nn(this,n),o=(this.style.removeProperty(n),nn(this,n));return s===o?null:s===t&&o===i?r:r=e(t=s,i=o)}}function Ea(n){return function(){this.style.removeProperty(n)}}function Zd(n,e,t){var i,r=t+"",s;return function(){var o=nn(this,n);return o===r?null:o===i?s:s=e(i=o,t)}}function Qd(n,e,t){var i,r,s;return function(){var o=nn(this,n),a=t(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(n),nn(this,n))),o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a))}}function Jd(n,e){var t,i,r,s="style."+e,o="end."+s,a;return function(){var l=ut(this,n),c=l.on,u=l.value[s]==null?a||(a=Ea(e)):void 0;(c!==t||r!==u)&&(i=(t=c).copy()).on(o,r=u),l.on=i}}function Gd(n,e,t){var i=(n+="")=="transform"?ad:Pa;return e==null?this.styleTween(n,Kd(n,i)).on("end.style."+n,Ea(n)):typeof e=="function"?this.styleTween(n,Qd(n,i,ss(this,"style."+n,e))).each(Jd(this._id,n)):this.styleTween(n,Zd(n,i,e),t).on("end.style."+n,null)}function ep(n,e,t){return function(i){this.style.setProperty(n,e.call(this,i),t)}}function tp(n,e,t){var i,r;function s(){var o=e.apply(this,arguments);return o!==r&&(i=(r=o)&&ep(n,o,t)),i}return s._value=e,s}function np(n,e,t){var i="style."+(n+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(e==null)return this.tween(i,null);if(typeof e!="function")throw new Error;return this.tween(i,tp(n,e,t??""))}function ip(n){return function(){this.textContent=n}}function rp(n){return function(){var e=n(this);this.textContent=e??""}}function sp(n){return this.tween("text",typeof n=="function"?rp(ss(this,"text",n)):ip(n==null?"":n+""))}function op(n){return function(e){this.textContent=n.call(this,e)}}function ap(n){var e,t;function i(){var r=n.apply(this,arguments);return r!==t&&(e=(t=r)&&op(r)),e}return i._value=n,i}function lp(n){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(n==null)return this.tween(e,null);if(typeof n!="function")throw new Error;return this.tween(e,ap(n))}function cp(){for(var n=this._name,e=this._id,t=Ra(),i=this._groups,r=i.length,s=0;s<r;++s)for(var o=i[s],a=o.length,l,c=0;c<a;++c)if(l=o[c]){var u=it(l,e);xi(l,n,t,c,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new bt(i,this._parents,n,t)}function up(){var n,e,t=this,i=t._id,r=t.size();return new Promise(function(s,o){var a={value:o},l={value:function(){--r===0&&s()}};t.each(function(){var c=ut(this,i),u=c.on;u!==n&&(e=(n=u).copy(),e._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),c.on=e}),r===0&&s()})}var fp=0;function bt(n,e,t,i){this._groups=n,this._parents=e,this._name=t,this._id=i}function Ra(){return++fp}var St=Pn.prototype;bt.prototype={constructor:bt,select:Xd,selectAll:Yd,selectChild:St.selectChild,selectChildren:St.selectChildren,filter:Ud,merge:zd,selection:jd,transition:cp,call:St.call,nodes:St.nodes,node:St.node,size:St.size,empty:St.empty,each:St.each,on:Hd,attr:Sd,attrTween:Id,style:Gd,styleTween:np,text:sp,textTween:lp,remove:$d,tween:md,delay:Rd,duration:Fd,ease:Nd,easeVarying:Bd,end:up,[Symbol.iterator]:St[Symbol.iterator]};function hp(n){return n*n}function dp(n){return n*(2-n)}function pp(n){return((n*=2)<=1?n*n:--n*(2-n)+1)/2}function mp(n){return((n*=2)<=1?n*n*n:(n-=2)*n*n+2)/2}var gp={time:null,delay:0,duration:250,ease:mp};function _p(n,e){for(var t;!(t=n.__transition)||!(t=t[e]);)if(!(n=n.parentNode))throw new Error(`transition ${e} not found`);return t}function xp(n){var e,t;n instanceof bt?(e=n._id,n=n._name):(e=Ra(),(t=gp).time=Yr(),n=n==null?null:n+"");for(var i=this._groups,r=i.length,s=0;s<r;++s)for(var o=i[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&xi(l,n,e,c,o,t||_p(l,e));return new bt(i,this._parents,n,e)}Pn.prototype.interrupt=Nh,Pn.prototype.transition=xp;function ka(){let n;if(typeof window<"u"&&window.performance)n=window.performance.now();else if(typeof process<"u"&&process.hrtime){const e=process.hrtime();n=e[0]*1e3+e[1]/1e6}else n=Date.now();return n}class Da{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=ka(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(ka()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}}class yp{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(const e of Object.values(this.stats))e.reset();return this}forEach(e){for(const t of Object.values(this.stats))e(t)}getTable(){const e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){const{name:t,type:i}=e;let r=this.stats[t];return r||(e instanceof Da?r=e:r=new Da(t,i),this.stats[t]=r),r}}class vp{constructor(){m(this,"stats",new Map)}getStats(e){return this.get(e)}get(e){return this.stats.has(e)||this.stats.set(e,new yp({id:e})),this.stats.get(e)}}const Fa=new vp,Ci=globalThis,on=globalThis.process||{},bp=globalThis.navigator||{};function Ma(n){var i,r;if(typeof window<"u"&&((i=window.process)==null?void 0:i.type)==="renderer"||typeof process<"u"&&((r=process.versions)!=null&&r.electron))return!0;const t=typeof navigator<"u"&&navigator.userAgent;return!!(t&&t.indexOf("Electron")>=0)}function Vt(){return!(typeof process=="object"&&String(process)==="[object process]"&&!(process!=null&&process.browser))||Ma()}function Sp(n){return Vt()?Ma()?"Electron":(bp.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown":"Node"}const Na="4.1.0";function Tp(n){try{const e=window[n],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}class wp{constructor(e,t,i="sessionStorage"){this.storage=Tp(i),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){const t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}}_loadConfiguration(){let e={};if(this.storage){const t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}function Ap(n){let e;return n<10?e=`${n.toFixed(2)}ms`:n<100?e=`${n.toFixed(1)}ms`:n<1e3?e=`${n.toFixed(0)}ms`:e=`${(n/1e3).toFixed(2)}s`,e}function Cp(n,e=8){const t=Math.max(e-n.length,0);return`${" ".repeat(t)}${n}`}var Ii;(function(n){n[n.BLACK=30]="BLACK",n[n.RED=31]="RED",n[n.GREEN=32]="GREEN",n[n.YELLOW=33]="YELLOW",n[n.BLUE=34]="BLUE",n[n.MAGENTA=35]="MAGENTA",n[n.CYAN=36]="CYAN",n[n.WHITE=37]="WHITE",n[n.BRIGHT_BLACK=90]="BRIGHT_BLACK",n[n.BRIGHT_RED=91]="BRIGHT_RED",n[n.BRIGHT_GREEN=92]="BRIGHT_GREEN",n[n.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",n[n.BRIGHT_BLUE=94]="BRIGHT_BLUE",n[n.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",n[n.BRIGHT_CYAN=96]="BRIGHT_CYAN",n[n.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(Ii||(Ii={}));const Ip=10;function Oa(n){return typeof n!="string"?n:(n=n.toUpperCase(),Ii[n]||Ii.WHITE)}function Pp(n,e,t){return!Vt&&typeof n=="string"&&(e&&(n=`\x1B[${Oa(e)}m${n}\x1B[39m`),t&&(n=`\x1B[${Oa(t)+Ip}m${n}\x1B[49m`)),n}function Ep(n,e=["constructor"]){const t=Object.getPrototypeOf(n),i=Object.getOwnPropertyNames(t),r=n;for(const s of i){const o=r[s];typeof o=="function"&&(e.find(a=>s===a)||(r[s]=o.bind(n)))}}function os(n,e){if(!n)throw new Error("Assertion failed")}function an(){var e,t,i;let n;if(Vt()&&Ci.performance)n=(t=(e=Ci==null?void 0:Ci.performance)==null?void 0:e.now)==null?void 0:t.call(e);else if("hrtime"in on){const r=(i=on==null?void 0:on.hrtime)==null?void 0:i.call(on);n=r[0]*1e3+r[1]/1e6}else n=Date.now();return n}const ln={debug:Vt()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},Rp={enabled:!0,level:0};function cn(){}const Ba={},Ua={once:!0};class za{constructor({id:e}={id:""}){this.VERSION=Na,this._startTs=an(),this._deltaTs=an(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new wp(`__probe-${this.id}__`,Rp),this.timeStamp(`${this.id} started`),Ep(this),Object.seal(this)}set level(e){this.setLevel(e)}get level(){return this.getLevel()}isEnabled(){return this._storage.config.enabled}getLevel(){return this._storage.config.level}getTotal(){return Number((an()-this._startTs).toPrecision(10))}getDelta(){return Number((an()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._storage.setConfiguration({enabled:e}),this}setLevel(e){return this._storage.setConfiguration({level:e}),this}get(e){return this._storage.config[e]}set(e,t){this._storage.setConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e){return this._getLogFunction(0,e,ln.warn,arguments,Ua)}error(e){return this._getLogFunction(0,e,ln.error,arguments)}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t){return this._getLogFunction(e,t,ln.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,ln.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,ln.debug||ln.info,arguments,Ua)}table(e,t,i){return t?this._getLogFunction(e,t,console.table||cn,i&&[i],{tag:Dp(t)}):cn}time(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}timeEnd(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}timeStamp(e,t){return this._getLogFunction(e,t,console.timeStamp||cn)}group(e,t,i={collapsed:!1}){const r=Va({logLevel:e,message:t,opts:i}),{collapsed:s}=i;return r.method=(s?console.groupCollapsed:console.group)||console.info,this._getLogFunction(r)}groupCollapsed(e,t,i={}){return this.group(e,t,Object.assign({},i,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||cn)}withGroup(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=La(e)}_getLogFunction(e,t,i,r,s){if(this._shouldLog(e)){s=Va({logLevel:e,message:t,args:r,opts:s}),i=i||s.method,os(i),s.total=this.getTotal(),s.delta=this.getDelta(),this._deltaTs=an();const o=s.tag||s.message;if(s.once&&o)if(!Ba[o])Ba[o]=an();else return cn;return t=kp(this.id,s.message,s),i.bind(console,t,...s.args)}return cn}}za.VERSION=Na;function La(n){if(!n)return 0;let e;switch(typeof n){case"number":e=n;break;case"object":e=n.logLevel||n.priority||0;break;default:return 0}return os(Number.isFinite(e)&&e>=0),e}function Va(n){const{logLevel:e,message:t}=n;n.logLevel=La(e);const i=n.args?Array.from(n.args):[];for(;i.length&&i.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&i.unshift(t),n.message=e;break;case"object":Object.assign(n,e);break}typeof n.message=="function"&&(n.message=n.message());const r=typeof n.message;return os(r==="string"||r==="object"),Object.assign(n,{args:i},n.opts)}function kp(n,e,t){if(typeof e=="string"){const i=t.time?Cp(Ap(t.total)):"";e=t.time?`${n}: ${i} ${e}`:`${n}: ${e}`,e=Pp(e,t.color,t.background)}return e}function Dp(n){for(const e in n)for(const t in n[e])return t||"untitled";return"empty"}const D=new za({id:"luma.gl"}),as={};function Pi(n="id"){as[n]=as[n]||1;const e=as[n]++;return`${n}-${e}`}class ae{constructor(e,t,i){m(this,"id");m(this,"props");m(this,"userData",{});m(this,"_device");m(this,"destroyed",!1);m(this,"allocatedBytes",0);m(this,"_attachedResources",new Set);if(!e)throw new Error("no device");this._device=e,this.props=Fp(t,i);const r=this.props.id!=="undefined"?this.props.id:Pi(this[Symbol.toStringTag]);this.props.id=r,this.id=r,this.userData=this.props.userData||{},this.addStats()}toString(){return`${this[Symbol.toStringTag]||this.constructor.name}:"${this.id}"`}destroy(){this.destroyResource()}delete(){return this.destroy(),this}getProps(){return this.props}attachResource(e){this._attachedResources.add(e)}detachResource(e){this._attachedResources.delete(e)}destroyAttachedResource(e){this._attachedResources.delete(e)&&e.destroy()}destroyAttachedResources(){for(const e of Object.values(this._attachedResources))e.destroy();this._attachedResources=new Set}destroyResource(){this.destroyAttachedResources(),this.removeStats(),this.destroyed=!0}removeStats(){const e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get(`${t}s Active`).decrementCount()}trackAllocatedMemory(e,t=this[Symbol.toStringTag]){const i=this._device.statsManager.getStats("Resource Counts");i.get("GPU Memory").addCount(e),i.get(`${t} Memory`).addCount(e),this.allocatedBytes=e}trackDeallocatedMemory(e=this[Symbol.toStringTag]){const t=this._device.statsManager.getStats("Resource Counts");t.get("GPU Memory").subtractCount(this.allocatedBytes),t.get(`${e} Memory`).subtractCount(this.allocatedBytes),this.allocatedBytes=0}addStats(){const e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get("Resources Created").incrementCount(),e.get(`${t}s Created`).incrementCount(),e.get(`${t}s Active`).incrementCount()}}m(ae,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function Fp(n,e){const t={...e};for(const i in n)n[i]!==void 0&&(t[i]=n[i]);return t}const ke=class ke extends ae{constructor(t,i){const r={...i};(i.usage||0)&ke.INDEX&&!i.indexType&&(i.data instanceof Uint32Array?r.indexType="uint32":i.data instanceof Uint16Array?r.indexType="uint16":i.data instanceof Uint8Array&&(r.indexType="uint8")),delete r.data;super(t,r,ke.defaultProps);m(this,"usage");m(this,"indexType");m(this,"updateTimestamp");m(this,"debugData",new ArrayBuffer(0));this.usage=r.usage||0,this.indexType=r.indexType,this.updateTimestamp=t.incrementTimestamp()}get[Symbol.toStringTag](){return"Buffer"}clone(t){return this.device.createBuffer({...this.props,...t})}_setDebugData(t,i,r){const s=ArrayBuffer.isView(t)?t.buffer:t,o=Math.min(t?t.byteLength:r,ke.DEBUG_DATA_MAX_LENGTH);s===null?this.debugData=new ArrayBuffer(o):i===0&&r===s.byteLength?this.debugData=s.slice(0,o):this.debugData=s.slice(i,i+o)}};m(ke,"INDEX",16),m(ke,"VERTEX",32),m(ke,"UNIFORM",64),m(ke,"STORAGE",128),m(ke,"INDIRECT",256),m(ke,"QUERY_RESOLVE",512),m(ke,"MAP_READ",1),m(ke,"MAP_WRITE",2),m(ke,"COPY_SRC",4),m(ke,"COPY_DST",8),m(ke,"DEBUG_DATA_MAX_LENGTH",32),m(ke,"defaultProps",{...ae.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",onMapped:void 0});let L=ke;function Ha(n){const[e,t,i]=ls[n],r=n.includes("norm"),s=!r&&!n.startsWith("float"),o=n.startsWith("s");return{signedType:e,primitiveType:t,byteLength:i,normalized:r,integer:s,signed:o}}function Mp(n){const e=n;switch(e){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return e}}function Np(n,e){switch(e){case 1:return n;case 2:return n+n%2;default:return n+(4-n%4)%4}}function Wa(n){const e=ArrayBuffer.isView(n)?n.constructor:n;if(e===Uint8ClampedArray)return"uint8";const t=Object.values(ls).find(i=>e===i[4]);if(!t)throw new Error(e.name);return t[0]}function $a(n){const[,,,,e]=ls[n];return e}const ls={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};function cs(n){let e;n.endsWith("-webgl")&&(n.replace("-webgl",""),e=!0);const[t,i]=n.split("x"),r=t,s=i?parseInt(i):1,o=Ha(r),a={type:r,components:s,byteLength:o.byteLength*s,integer:o.integer,signed:o.signed,normalized:o.normalized};return e&&(a.webglOnly=!0),a}function Op(n,e,t){const i=t?Mp(n):n;switch(i){case"unorm8":return e===1?"unorm8":e===3?"unorm8x3-webgl":`${i}x${e}`;case"snorm8":case"uint8":case"sint8":case"uint16":case"sint16":case"unorm16":case"snorm16":case"float16":if(e===1||e===3)throw new Error(`size: ${e}`);return`${i}x${e}`;default:return e===1?i:`${i}x${e}`}}function Bp(n,e,t){if(!e||e>4)throw new Error(`size ${e}`);const i=e,r=Wa(n);return Op(r,i,t)}function Up(n){let e;switch(n.primitiveType){case"f32":e="float32";break;case"i32":e="sint32";break;case"u32":e="uint32";break;case"f16":return n.components<=2?"float16x2":"float16x4"}return n.components===1?e:`${e}x${n.components}`}const Fe="texture-compression-bc",ce="texture-compression-astc",ht="texture-compression-etc2",zp="texture-compression-etc1-webgl",Ei="texture-compression-pvrtc-webgl",us="texture-compression-atc-webgl",Ri="float32-renderable-webgl",fs="float16-renderable-webgl",Lp="rgb9e5ufloat-renderable-webgl",hs="snorm8-renderable-webgl",On="norm16-renderable-webgl",ds="snorm16-renderable-webgl",ki="float32-filterable",Xa="float16-filterable-webgl";function Ya(n){const e=Vp[n];if(!e)throw new Error(`Unsupported texture format ${n}`);return e}const Vp={...{r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:hs},rg8snorm:{render:hs},"rgb8snorm-webgl":{},rgba8snorm:{render:hs},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:On},rg16unorm:{render:On},"rgb16unorm-webgl":{f:On},rgba16unorm:{render:On},r16snorm:{f:ds},rg16snorm:{render:ds},"rgb16snorm-webgl":{f:On},rgba16snorm:{render:ds},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:fs,filter:"float16-filterable-webgl"},rg16float:{render:fs,filter:Xa},rgba16float:{render:fs,filter:Xa},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Ri,filter:ki},rg32float:{render:!1,filter:ki},"rgb32float-webgl":{render:Ri,filter:ki},rgba32float:{render:Ri,filter:ki},"rgba4unorm-webgl":{channels:"rgba",bitsPerChannel:[4,4,4,4],packed:!0},"rgb565unorm-webgl":{channels:"rgb",bitsPerChannel:[5,6,5,0],packed:!0},"rgb5a1unorm-webgl":{channels:"rgba",bitsPerChannel:[5,5,5,1],packed:!0},rgb9e5ufloat:{channels:"rgb",packed:!0,render:Lp},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Ri},rgb10a2unorm:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},rgb10a2uint:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},stencil8:{attachment:"stencil",bitsPerChannel:[8,0,0,0],dataType:"uint8"},depth16unorm:{attachment:"depth",bitsPerChannel:[16,0,0,0],dataType:"uint16"},depth24plus:{attachment:"depth",bitsPerChannel:[24,0,0,0],dataType:"uint32"},depth32float:{attachment:"depth",bitsPerChannel:[32,0,0,0],dataType:"float32"},"depth24plus-stencil8":{attachment:"depth-stencil",bitsPerChannel:[24,8,0,0],packed:!0},"depth32float-stencil8":{attachment:"depth-stencil",bitsPerChannel:[32,8,0,0],packed:!0}},...{"bc1-rgb-unorm-webgl":{f:Fe},"bc1-rgb-unorm-srgb-webgl":{f:Fe},"bc1-rgba-unorm":{f:Fe},"bc1-rgba-unorm-srgb":{f:Fe},"bc2-rgba-unorm":{f:Fe},"bc2-rgba-unorm-srgb":{f:Fe},"bc3-rgba-unorm":{f:Fe},"bc3-rgba-unorm-srgb":{f:Fe},"bc4-r-unorm":{f:Fe},"bc4-r-snorm":{f:Fe},"bc5-rg-unorm":{f:Fe},"bc5-rg-snorm":{f:Fe},"bc6h-rgb-ufloat":{f:Fe},"bc6h-rgb-float":{f:Fe},"bc7-rgba-unorm":{f:Fe},"bc7-rgba-unorm-srgb":{f:Fe},"etc2-rgb8unorm":{f:ht},"etc2-rgb8unorm-srgb":{f:ht},"etc2-rgb8a1unorm":{f:ht},"etc2-rgb8a1unorm-srgb":{f:ht},"etc2-rgba8unorm":{f:ht},"etc2-rgba8unorm-srgb":{f:ht},"eac-r11unorm":{f:ht},"eac-r11snorm":{f:ht},"eac-rg11unorm":{f:ht},"eac-rg11snorm":{f:ht},"astc-4x4-unorm":{f:ce},"astc-4x4-unorm-srgb":{f:ce},"astc-5x4-unorm":{f:ce},"astc-5x4-unorm-srgb":{f:ce},"astc-5x5-unorm":{f:ce},"astc-5x5-unorm-srgb":{f:ce},"astc-6x5-unorm":{f:ce},"astc-6x5-unorm-srgb":{f:ce},"astc-6x6-unorm":{f:ce},"astc-6x6-unorm-srgb":{f:ce},"astc-8x5-unorm":{f:ce},"astc-8x5-unorm-srgb":{f:ce},"astc-8x6-unorm":{f:ce},"astc-8x6-unorm-srgb":{f:ce},"astc-8x8-unorm":{f:ce},"astc-8x8-unorm-srgb":{f:ce},"astc-10x5-unorm":{f:ce},"astc-10x5-unorm-srgb":{f:ce},"astc-10x6-unorm":{f:ce},"astc-10x6-unorm-srgb":{f:ce},"astc-10x8-unorm":{f:ce},"astc-10x8-unorm-srgb":{f:ce},"astc-10x10-unorm":{f:ce},"astc-10x10-unorm-srgb":{f:ce},"astc-12x10-unorm":{f:ce},"astc-12x10-unorm-srgb":{f:ce},"astc-12x12-unorm":{f:ce},"astc-12x12-unorm-srgb":{f:ce},"pvrtc-rgb4unorm-webgl":{f:Ei},"pvrtc-rgba4unorm-webgl":{f:Ei},"pvrtc-rbg2unorm-webgl":{f:Ei},"pvrtc-rgba2unorm-webgl":{f:Ei},"etc1-rbg-unorm-webgl":{f:zp},"atc-rgb-unorm-webgl":{f:us},"atc-rgba-unorm-webgl":{f:us},"atc-rgbai-unorm-webgl":{f:us}}},Hp=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],Wp=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;class $p{getInfo(e){return qa(e)}isColor(e){return e.startsWith("rgba")||e.startsWith("bgra")||e.startsWith("rgb")}isDepthStencil(e){return e.startsWith("depth")||e.startsWith("stencil")}isCompressed(e){return Hp.some(t=>e.startsWith(t))}getCapabilities(e){const t=Ya(e),i={format:e,create:t.f??!0,render:t.render??!0,filter:t.filter??!0,blend:t.blend??!0,store:t.store??!0},r=qa(e),s=e.startsWith("depth")||e.startsWith("stencil"),o=r==null?void 0:r.signed,a=r==null?void 0:r.integer,l=r==null?void 0:r.webgl;return i.render&&(i.render=!o),i.filter&&(i.filter=!s&&!o&&!a&&!l),i}}const Ht=new $p;function qa(n){let e=Xp(n);if(Ht.isCompressed(n)){e.channels="rgb",e.components=3,e.bytesPerPixel=1,e.srgb=!1,e.compressed=!0;const i=Yp(n);i&&(e.blockWidth=i.blockWidth,e.blockHeight=i.blockHeight)}const t=Wp.exec(n);if(t){const[,i,r,s,o,a]=t,l=`${s}${r}`,c=Ha(l),u=c.byteLength*8,f=i.length,h=[u,f>=2?u:0,f>=3?u:0,f>=4?u:0];e={format:n,attachment:e.attachment,dataType:c.signedType,components:f,channels:i,integer:c.integer,signed:c.signed,normalized:c.normalized,bitsPerChannel:h,bytesPerPixel:c.byteLength*i.length,packed:e.packed,srgb:e.srgb},a==="-webgl"&&(e.webgl=!0),o==="-srgb"&&(e.srgb=!0)}return n.endsWith("-webgl")&&(e.webgl=!0),n.endsWith("-srgb")&&(e.srgb=!0),e}function Xp(n){var s;const e=Ya(n),t=e.bytesPerPixel||1,i=e.bitsPerChannel||[8,8,8,8];return delete e.bitsPerChannel,delete e.bytesPerPixel,delete e.f,delete e.render,delete e.filter,delete e.blend,delete e.store,{...e,format:n,attachment:e.attachment||"color",channels:e.channels||"r",components:e.components||((s=e.channels)==null?void 0:s.length)||1,bytesPerPixel:t,bitsPerChannel:i,dataType:e.dataType||"uint8",srgb:e.srgb??!1,packed:e.packed??!1,webgl:e.webgl??!1,integer:e.integer??!1,signed:e.signed??!1,normalized:e.normalized??!1,compressed:e.compressed??!1}}function Yp(n){const t=/.*-(\d+)x(\d+)-.*/.exec(n);if(t){const[,i,r]=t;return{blockWidth:Number(i),blockHeight:Number(r)}}return null}function qp(n){return typeof ImageData<"u"&&n instanceof ImageData||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement||typeof VideoFrame<"u"&&n instanceof VideoFrame||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas}function jp(n){if(typeof ImageData<"u"&&n instanceof ImageData||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas)return{width:n.width,height:n.height};if(typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement)return{width:n.naturalWidth,height:n.naturalHeight};if(typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement)return{width:n.videoWidth,height:n.videoHeight};if(typeof VideoFrame<"u"&&n instanceof VideoFrame)return{width:n.displayWidth,height:n.displayHeight};throw new Error("Unknown image type")}class Kp{}class Zp{constructor(e=[],t){m(this,"features");m(this,"disabledFeatures");this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){var t;return!((t=this.disabledFeatures)!=null&&t[e])&&this.features.has(e)}}const Sr=class Sr{constructor(e){m(this,"id");m(this,"props");m(this,"userData",{});m(this,"statsManager",Fa);m(this,"timestamp",0);m(this,"_reused",!1);m(this,"_lumaData",{});m(this,"_textureCaps",{});this.props={...Sr.defaultProps,...e},this.id=this.props.id||Pi(this[Symbol.toStringTag].toLowerCase())}get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}getVertexFormatInfo(e){return cs(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return Ht.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){const i=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(i),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,i=1){const r=Math.max(e,t,i);return 1+Math.floor(Math.log2(r))}isExternalImage(e){return qp(e)}getExternalImageSize(e){return jp(e)}isTextureFormatSupported(e){return this.getTextureFormatCapabilities(e).create}isTextureFormatFilterable(e){return this.getTextureFormatCapabilities(e).filter}isTextureFormatRenderable(e){return this.getTextureFormatCapabilities(e).render}isTextureFormatCompressed(e){return Ht.isCompressed(e)}pushDebugGroup(e){this.commandEncoder.pushDebugGroup(e)}popDebugGroup(){var e;(e=this.commandEncoder)==null||e.popDebugGroup()}insertDebugMarker(e){var t;(t=this.commandEncoder)==null||t.insertDebugMarker(e)}loseDevice(){return!1}incrementTimestamp(){return this.timestamp++}reportError(e,t,...i){return this.props.onError(e,t)?()=>{}:D.error(e.message,t,...i)}debug(){if(this.props.debug)debugger;else D.once(0,`'Type luma.log.set({debug: true}) in console to enable debug breakpoints',
2
+ or create a device with the 'debug: true' prop.`)()}getDefaultCanvasContext(){if(!this.canvasContext)throw new Error("Device has no default CanvasContext. See props.createCanvasContext");return this.canvasContext}beginRenderPass(e){return this.commandEncoder.beginRenderPass(e)}beginComputePass(e){return this.commandEncoder.beginComputePass(e)}getCanvasContext(){return this.getDefaultCanvasContext()}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}resetWebGL(){throw new Error("not implemented")}static _getCanvasContextProps(e){return e.createCanvasContext===!0?{}:e.createCanvasContext}_getDeviceTextureFormatCapabilities(e){const t=Ht.getCapabilities(e),i=s=>(typeof s=="string"?this.features.has(s):s)??!0,r=i(t.create);return{format:e,create:r,render:r&&i(t.render),filter:r&&i(t.filter),blend:r&&i(t.blend),store:r&&i(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});const t={...e};if((e.usage||0)&L.INDEX&&(e.indexType||(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array?t.indexType="uint16":e.data instanceof Uint8Array&&(t.data=new Uint16Array(e.data),t.indexType="uint16")),!t.indexType))throw new Error("indices buffer content must be of type uint16 or uint32");return t}};m(Sr,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{const[i,r]=e.getDevicePixelSize();D.log(1,`${e} resized => ${i}x${r}px`)()},onPositionChange:(e,t)=>{const[i,r]=e.getPosition();D.log(1,`${e} repositioned => ${i},${r}`)()},onVisibilityChange:e=>D.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>D.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:D.get("debug")||void 0,debugShaders:D.get("debug-shaders")||void 0,debugFramebuffers:!!D.get("debug-framebuffers"),debugFactories:!!D.get("debug-factories"),debugWebGL:!!D.get("debug-webgl"),debugSpectorJS:void 0,debugSpectorJSUrl:void 0,_reuseDevices:!1,_requestMaxLimits:!0,_cacheShaders:!1,_cachePipelines:!1,_cacheDestroyPolicy:"unused",_initializeFeatures:!0,_disabledFeatures:{"compilation-status-async-webgl":!0},_handle:void 0});let Wt=Sr;const Qp="set luma.log.level=1 (or higher) to trace rendering",ja="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",ri=class ri{constructor(){m(this,"stats",Fa);m(this,"log",D);m(this,"VERSION","9.2.6");m(this,"spector");m(this,"preregisteredAdapters",new Map);if(globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw D.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),D.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");D.error("This version of luma.gl has already been initialized")()}D.log(1,`${this.VERSION} - ${Qp}`)(),globalThis.luma=this}async createDevice(e={}){const t={...ri.defaultProps,...e},i=this.selectAdapter(t.type,t.adapters);if(!i)throw new Error(ja);return t.waitForPageLoad&&await i.pageLoaded,await i.create(t)}async attachDevice(e,t){var s;const i=this._getTypeFromHandle(e,t.adapters),r=i&&this.selectAdapter(i,t.adapters);if(!r)throw new Error(ja);return await((s=r==null?void 0:r.attach)==null?void 0:s.call(r,e,t))}registerAdapters(e){for(const t of e)this.preregisteredAdapters.set(t.type,t)}getSupportedAdapters(e=[]){const t=this._getAdapterMap(e);return Array.from(t).map(([,i])=>i).filter(i=>{var r;return(r=i.isSupported)==null?void 0:r.call(i)}).map(i=>i.type)}getBestAvailableAdapterType(e=[]){var r,s;const t=["webgpu","webgl","null"],i=this._getAdapterMap(e);for(const o of t)if((s=(r=i.get(o))==null?void 0:r.isSupported)!=null&&s.call(r))return o;return null}selectAdapter(e,t=[]){let i=e;e==="best-available"&&(i=this.getBestAvailableAdapterType(t));const r=this._getAdapterMap(t);return i&&r.get(i)||null}enforceWebGL2(e=!0,t=[]){var s;const r=this._getAdapterMap(t).get("webgl");r||D.warn("enforceWebGL2: webgl adapter not found")(),(s=r==null?void 0:r.enforceWebGL2)==null||s.call(r,e)}setDefaultDeviceProps(e){Object.assign(ri.defaultProps,e)}_getAdapterMap(e=[]){const t=new Map(this.preregisteredAdapters);for(const i of e)t.set(i.type,i);return t}_getTypeFromHandle(e,t=[]){return e instanceof WebGL2RenderingContext?"webgl":typeof GPUDevice<"u"&&e instanceof GPUDevice||e!=null&&e.queue?"webgpu":e===null?"null":(e instanceof WebGLRenderingContext?D.warn("WebGL1 is not supported",e)():D.warn("Unknown handle type",e)(),null)}};m(ri,"defaultProps",{...Wt.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});let ps=ri;const Jp=new ps;class Gp{get pageLoaded(){return nm()}}const em=Vt()&&typeof document<"u",tm=()=>em&&document.readyState==="complete";let Di=null;function nm(){return Di||(tm()||typeof window>"u"?Di=Promise.resolve():Di=new Promise(n=>window.addEventListener("load",()=>n()))),Di}function im(){let n,e;return{promise:new Promise((i,r)=>{n=i,e=r}),resolve:n,reject:e}}const Jt=class Jt{constructor(e){m(this,"id");m(this,"props");m(this,"canvas");m(this,"htmlCanvas");m(this,"offscreenCanvas");m(this,"type");m(this,"initialized");m(this,"isInitialized",!1);m(this,"isVisible",!0);m(this,"cssWidth");m(this,"cssHeight");m(this,"devicePixelRatio");m(this,"devicePixelWidth");m(this,"devicePixelHeight");m(this,"drawingBufferWidth");m(this,"drawingBufferHeight");m(this,"_initializedResolvers",im());m(this,"_resizeObserver");m(this,"_intersectionObserver");m(this,"_position");m(this,"destroyed",!1);var t,i;if(this.props={...Jt.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,Vt()?e.canvas?typeof e.canvas=="string"?this.canvas=sm(e.canvas):this.canvas=e.canvas:this.canvas=om(e):this.canvas={width:e.width||1,height:e.height||1},Jt.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):Jt.isOffscreenCanvas(this.canvas)?(this.id=e.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=e.id||"node-canvas-context",this.type="node"),this.cssWidth=((t=this.htmlCanvas)==null?void 0:t.clientWidth)||this.canvas.width,this.cssHeight=((i=this.htmlCanvas)==null?void 0:i.clientHeight)||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],Jt.isHTMLCanvas(this.canvas)){this._intersectionObserver=new IntersectionObserver(r=>this._handleIntersection(r)),this._intersectionObserver.observe(this.canvas),this._resizeObserver=new ResizeObserver(r=>this._handleResize(r));try{this._resizeObserver.observe(this.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.canvas,{box:"content-box"})}setTimeout(()=>this._observeDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}static isHTMLCanvas(e){return typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}destroy(){this.destroyed=!0}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){const e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){this.canvas.width=e,this.canvas.height=t,this.drawingBufferWidth=e,this.drawingBufferHeight=t}getDevicePixelRatio(){return typeof window<"u"&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){const i=this.cssToDeviceRatio(),[r,s]=this.getDrawingBufferSize();return am(e,i,r,s,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){const[e,t]=this.getDevicePixelSize();return e/t}cssToDeviceRatio(){try{const[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){var t;((t=this.htmlCanvas)==null?void 0:t.id)==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}_handleIntersection(e){const t=e.find(r=>r.target===this.canvas);if(!t)return;const i=t.isIntersecting;this.isVisible!==i&&(this.isVisible=i,this.device.props.onVisibilityChange(this))}_handleResize(e){var l,c;const t=e.find(u=>u.target===this.canvas);if(!t)return;this.cssWidth=t.contentBoxSize[0].inlineSize,this.cssHeight=t.contentBoxSize[0].blockSize;const i=this.getDevicePixelSize(),r=((l=t.devicePixelContentBoxSize)==null?void 0:l[0].inlineSize)||t.contentBoxSize[0].inlineSize*devicePixelRatio,s=((c=t.devicePixelContentBoxSize)==null?void 0:c[0].blockSize)||t.contentBoxSize[0].blockSize*devicePixelRatio,[o,a]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(r,o)),this.devicePixelHeight=Math.max(1,Math.min(s,a)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:i})}_updateDrawingBufferSize(){if(this.props.autoResize){if(typeof this.props.useDevicePixels=="number"){const e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._updateDevice()}this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_observeDevicePixelRatio(){const e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange(this,{oldRatio:e}),matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change",()=>this._observeDevicePixelRatio(),{once:!0})}_trackPosition(e=100){const t=setInterval(()=>{this.destroyed?clearInterval(t):this.updatePosition()},e)}updatePosition(){var t,i,r;const e=(t=this.htmlCanvas)==null?void 0:t.getBoundingClientRect();if(e){const s=[e.left,e.top];if(this._position??(this._position=s),s[0]!==this._position[0]||s[1]!==this._position[1]){const a=this._position;this._position=s,(r=(i=this.device.props).onPositionChange)==null||r.call(i,this,{oldPosition:a})}}}};m(Jt,"defaultProps",{id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1});let Fi=Jt;function rm(n){if(typeof n=="string"){const e=document.getElementById(n);if(!e)throw new Error(`${n} is not an HTML element`);return e}return n||document.body}function sm(n){const e=document.getElementById(n);if(!Fi.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function om(n){const{width:e,height:t}=n,i=document.createElement("canvas");i.id=Pi("lumagl-auto-created-canvas"),i.width=e||1,i.height=t||1,i.style.width=Number.isFinite(e)?`${e}px`:"100%",i.style.height=Number.isFinite(t)?`${t}px`:"100%",n!=null&&n.visible||(i.style.visibility="hidden");const r=rm((n==null?void 0:n.container)||null);return r.insertBefore(i,r.firstChild),i}function am(n,e,t,i,r){const s=n,o=Ka(s[0],e,t);let a=Za(s[1],e,i,r),l=Ka(s[0]+1,e,t);const c=l===t-1?l:l-1;l=Za(s[1]+1,e,i,r);let u;return r?(l=l===0?l:l+1,u=a,a=l):u=l===i-1?l:l-1,{x:o,y:a,width:Math.max(c-o+1,1),height:Math.max(u-a+1,1)}}function Ka(n,e,t){return Math.min(Math.round(n*e),t-1)}function Za(n,e,t,i){return i?Math.max(0,t-1-Math.round(n*e)):Math.min(Math.round(n*e),t-1)}const si=class si extends ae{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){t=si.normalizeProps(e,t),super(e,t,si.defaultProps)}static normalizeProps(e,t){return t}};m(si,"defaultProps",{...ae.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"none",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});let un=si;const lm={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},Ce=class Ce extends ae{constructor(t,i){i=Ce.normalizeProps(t,i);super(t,i,Ce.defaultProps);m(this,"dimension");m(this,"baseDimension");m(this,"format");m(this,"width");m(this,"height");m(this,"depth");m(this,"mipLevels");m(this,"updateTimestamp");if(this.dimension=this.props.dimension,this.baseDimension=lm[this.dimension],this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.mipLevels=this.props.mipLevels,this.props.width===void 0||this.props.height===void 0)if(t.isExternalImage(i.data)){const r=t.getExternalImageSize(i.data);this.width=(r==null?void 0:r.width)||1,this.height=(r==null?void 0:r.height)||1}else this.width=1,this.height=1,(this.props.width===void 0||this.props.height===void 0)&&D.warn(`${this} created with undefined width or height. This is deprecated. Use AsyncTexture instead.`)();this.updateTimestamp=t.incrementTimestamp()}get[Symbol.toStringTag](){return"Texture"}toString(){return`Texture(${this.id},${this.format},${this.width}x${this.height})`}setSampler(t){this.sampler=t instanceof un?t:this.device.createSampler(t)}clone(t){return this.device.createTexture({...this.props,...t})}static normalizeProps(t,i){const r={...i},{width:s,height:o}=r;return typeof s=="number"&&(r.width=Math.max(1,Math.ceil(s))),typeof o=="number"&&(r.height=Math.max(1,Math.ceil(o))),r}_initializeData(t){this.device.isExternalImage(t)?this.copyExternalImage({image:t,width:this.width,height:this.height,depth:this.depth,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}):t&&this.copyImageData({data:t,mipLevel:0,x:0,y:0,z:0,aspect:"all"})}_normalizeCopyImageDataOptions(t){const{width:i,height:r,depth:s}=this,o={...Ce.defaultCopyDataOptions,width:i,height:r,depth:s,...t},a=this.device.getTextureFormatInfo(this.format);if(!t.bytesPerRow&&!a.bytesPerPixel)throw new Error(`bytesPerRow must be provided for texture format ${this.format}`);return o.bytesPerRow=t.bytesPerRow||i*(a.bytesPerPixel||4),o.rowsPerImage=t.rowsPerImage||r,o}_normalizeCopyExternalImageOptions(t){const i=this.device.getExternalImageSize(t.image),r={...Ce.defaultCopyExternalImageOptions,...i,...t};return r.width=Math.min(r.width,this.width-r.x),r.height=Math.min(r.height,this.height-r.y),r}};m(Ce,"SAMPLE",4),m(Ce,"STORAGE",8),m(Ce,"RENDER",16),m(Ce,"COPY_SRC",1),m(Ce,"COPY_DST",2),m(Ce,"TEXTURE",4),m(Ce,"RENDER_ATTACHMENT",16),m(Ce,"defaultProps",{...ae.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:Ce.TEXTURE|Ce.RENDER_ATTACHMENT|Ce.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),m(Ce,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),m(Ce,"defaultCopyExternalImageOptions",{image:void 0,sourceX:0,sourceY:0,width:void 0,height:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1});let Q=Ce;const Tr=class Tr extends ae{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,Tr.defaultProps)}};m(Tr,"defaultProps",{...ae.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});let Mi=Tr;function cm(n,e,t){let i="";const r=e.split(/\r?\n/),s=n.slice().sort((o,a)=>o.lineNum-a.lineNum);switch((t==null?void 0:t.showSourceCode)||"no"){case"all":let o=0;for(let a=1;a<=r.length;a++)for(i+=Qa(r[a-1],a,t);s.length>o&&s[o].lineNum===a;){const l=s[o++];i+=ms(l,r,l.lineNum,{...t,inlineSource:!1})}for(;s.length>o;){const a=s[o++];i+=ms(a,[],0,{...t,inlineSource:!1})}return i;case"issues":case"no":for(const a of n)i+=ms(a,r,a.lineNum,{inlineSource:(t==null?void 0:t.showSourceCode)!=="no"});return i}}function ms(n,e,t,i){if(i!=null&&i.inlineSource){const s=um(e,t),o=n.linePos>0?`${" ".repeat(n.linePos+5)}^^^
3
3
  `:"";return`
4
4
  ${s}${o}${n.type.toUpperCase()}: ${n.message}
5
5
 
6
- `}const r=n.type==="error"?"red":"#8B4000";return i!=null&&i.html?`<div class='luma-compiler-log-error' style="color:${r};"><b> ${n.type.toUpperCase()}: ${n.message}</b></div>`:`${n.type.toUpperCase()}: ${n.message}`}function xm(n,e,t){let i="";for(let r=e-2;r<=e;r++){const s=n[r-1];s!==void 0&&(i+=qa(s,e,t))}return i}function qa(n,e,t){const i=t!=null&&t.html?vm(n):n;return`${ym(String(e),4)}: ${i}${t!=null&&t.html?"<br/>":`
7
- `}`}function ym(n,e){let t="";for(let i=n.length;i<e;++i)t+=" ";return t+n}function vm(n){return n.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}const wr=class wr extends ce{constructor(t,i){i={...i,debugShaders:i.debugShaders||t.props.debugShaders||"errors"};super(t,{id:bm(i),...i},wr.defaultProps);m(this,"stage");m(this,"source");m(this,"compilationStatus","pending");this.stage=this.props.stage,this.source=this.props.source}get[Symbol.toStringTag](){return"Shader"}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(){const t=this.props.debugShaders;switch(t){case"never":return;case"errors":if(this.compilationStatus==="success")return;break}const i=await this.getCompilationInfo();t==="warnings"&&(i==null?void 0:i.length)===0||this._displayShaderLog(i,this.id)}_displayShaderLog(t,i){var u;if(typeof document>"u"||!(document!=null&&document.createElement))return;const r=i,s=`${this.stage} shader "${r}"`;let o=_m(t,this.source,{showSourceCode:"all",html:!0});const a=this.getTranslatedSource();a&&(o+=`<br /><br /><h1>Translated Source</h1><br /><br /><code style="user-select:text;"><pre>${a}</pre></code>`);const l=document.createElement("Button");l.innerHTML=`
6
+ `}const r=n.type==="error"?"red":"#8B4000";return i!=null&&i.html?`<div class='luma-compiler-log-error' style="color:${r};"><b> ${n.type.toUpperCase()}: ${n.message}</b></div>`:`${n.type.toUpperCase()}: ${n.message}`}function um(n,e,t){let i="";for(let r=e-2;r<=e;r++){const s=n[r-1];s!==void 0&&(i+=Qa(s,e,t))}return i}function Qa(n,e,t){const i=t!=null&&t.html?hm(n):n;return`${fm(String(e),4)}: ${i}${t!=null&&t.html?"<br/>":`
7
+ `}`}function fm(n,e){let t="";for(let i=n.length;i<e;++i)t+=" ";return t+n}function hm(n){return n.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}const wr=class wr extends ae{constructor(t,i){i={...i,debugShaders:i.debugShaders||t.props.debugShaders||"errors"};super(t,{id:dm(i),...i},wr.defaultProps);m(this,"stage");m(this,"source");m(this,"compilationStatus","pending");this.stage=this.props.stage,this.source=this.props.source}get[Symbol.toStringTag](){return"Shader"}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(){const t=this.props.debugShaders;switch(t){case"never":return;case"errors":if(this.compilationStatus==="success")return;break}const i=await this.getCompilationInfo();t==="warnings"&&(i==null?void 0:i.length)===0||this._displayShaderLog(i,this.id)}_displayShaderLog(t,i){var u;if(typeof document>"u"||!(document!=null&&document.createElement))return;const r=i,s=`${this.stage} shader "${r}"`;let o=cm(t,this.source,{showSourceCode:"all",html:!0});const a=this.getTranslatedSource();a&&(o+=`<br /><br /><h1>Translated Source</h1><br /><br /><code style="user-select:text;"><pre>${a}</pre></code>`);const l=document.createElement("Button");l.innerHTML=`
8
8
  <h1>Compilation error in ${s}</h1><br /><br />
9
9
  <code style="user-select:text;"><pre>
10
10
  ${o}
11
- </pre></code>`,l.style.top="10px",l.style.left="10px",l.style.position="absolute",l.style.zIndex="9999",l.style.width="100%",l.style.textAlign="left",document.body.appendChild(l),(u=document.getElementsByClassName("luma-compiler-log-error")[0])==null||u.scrollIntoView(),l.onclick=()=>{const f=`data:text/plain,${encodeURIComponent(this.source)}`;navigator.clipboard.writeText(f)}}};m(wr,"defaultProps",{...ce.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});let Ni=wr;function bm(n){return Sm(n.source)||n.id||Pi(`unnamed ${n.stage}-shader`)}function Sm(n,e="unnamed"){const i=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(n);return i?i[1]:e}const Ar=class Ar extends ce{constructor(t,i={}){super(t,i,Ar.defaultProps);m(this,"width");m(this,"height");this.width=this.props.width,this.height=this.props.height}get[Symbol.toStringTag](){return"Framebuffer"}clone(t){const i=this.colorAttachments.map(s=>s.texture.clone(t)),r=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(t);return this.device.createFramebuffer({...this.props,colorAttachments:i,depthStencilAttachment:r})}resize(t){let i=!t;if(t){const[r,s]=Array.isArray(t)?t:[t.width,t.height];i=i||s!==this.height||r!==this.width,this.width=r,this.height=s}i&&(D.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((i,r)=>{if(typeof i=="string"){const s=this.createColorTexture(i,r);return this.attachResource(s),s.view}return i instanceof Q?i.view:i});const t=this.props.depthStencilAttachment;if(t)if(typeof t=="string"){const i=this.createDepthStencilTexture(t);this.attachResource(i),this.depthStencilAttachment=i.view}else t instanceof Q?this.depthStencilAttachment=t.view:this.depthStencilAttachment=t}createColorTexture(t,i){return this.device.createTexture({id:`${this.id}-color-attachment-${i}`,usage:Q.RENDER_ATTACHMENT,format:t,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(t){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:Q.RENDER_ATTACHMENT,format:t,width:this.width,height:this.height})}resizeAttachments(t,i){for(let r=0;r<this.colorAttachments.length;++r)if(this.colorAttachments[r]){const s=this.colorAttachments[r].texture.clone({width:t,height:i});this.destroyAttachedResource(this.colorAttachments[r]),this.colorAttachments[r]=s.view,this.attachResource(s.view)}if(this.depthStencilAttachment){const r=this.depthStencilAttachment.texture.clone({width:t,height:i});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=r.view,this.attachResource(r)}this.updateAttachments()}};m(Ar,"defaultProps",{...ce.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});let Oi=Ar;const Cr=class Cr extends ce{constructor(t,i){super(t,i,Cr.defaultProps);m(this,"shaderLayout");m(this,"bufferLayout");m(this,"linkStatus","pending");m(this,"hash","");this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[]}get[Symbol.toStringTag](){return"RenderPipeline"}};m(Cr,"defaultProps",{...ce.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",colorAttachmentFormats:void 0,depthStencilAttachmentFormat:void 0,parameters:{},bindings:{},uniforms:{}});let Wt=Cr;const ut=class ut extends ce{get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){t=ut.normalizeProps(e,t),super(e,t,ut.defaultProps)}static normalizeProps(e,t){return t}};m(ut,"defaultClearColor",[0,0,0,1]),m(ut,"defaultClearDepth",1),m(ut,"defaultClearStencil",0),m(ut,"defaultProps",{...ce.defaultProps,framebuffer:null,parameters:void 0,clearColor:ut.defaultClearColor,clearColors:void 0,clearDepth:ut.defaultClearDepth,clearStencil:ut.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});let gs=ut;const Ir=class Ir extends ce{constructor(t,i){super(t,i,Ir.defaultProps);m(this,"hash","");m(this,"shaderLayout");this.shaderLayout=i.shaderLayout}get[Symbol.toStringTag](){return"ComputePipeline"}};m(Ir,"defaultProps",{...ce.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});let Bi=Ir;const Pr=class Pr extends ce{get[Symbol.toStringTag](){return"CommandEncoder"}constructor(e,t){super(e,t,Pr.defaultProps)}};m(Pr,"defaultProps",{...ce.defaultProps,measureExecutionTime:void 0});let _s=Pr;const Er=class Er extends ce{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Er.defaultProps)}};m(Er,"defaultProps",{...ce.defaultProps});let xs=Er;function ja(n){return Cm[n]}function Tm(n){const[e,t]=Am[n],i=e==="i32"||e==="u32",r=e!=="u32",s=wm[e]*t;return{primitiveType:e,components:t,byteLength:s,integer:i,signed:r}}const wm={f32:4,f16:2,i32:4,u32:4},Am={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},Cm={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}};function Ka(n,e){const t={};for(const i of n.attributes){const r=Pm(n,e,i.name);r&&(t[i.name]=r)}return t}function Im(n,e,t=16){const i=Ka(n,e),r=new Array(t).fill(null);for(const s of Object.values(i))r[s.location]=s;return r}function Pm(n,e,t){const i=Em(n,t),r=Rm(e,t);if(!i)return null;const s=Tm(i.type),o=Yp(s),a=(r==null?void 0:r.vertexFormat)||o,l=cs(a);return{attributeName:(r==null?void 0:r.attributeName)||i.name,bufferName:(r==null?void 0:r.bufferName)||i.name,location:i.location,shaderType:i.type,primitiveType:s.primitiveType,shaderComponents:s.components,vertexFormat:a,bufferDataType:l.type,bufferComponents:l.components,normalized:l.normalized,integer:s.integer,stepMode:(r==null?void 0:r.stepMode)||i.stepMode||"vertex",byteOffset:(r==null?void 0:r.byteOffset)||0,byteStride:(r==null?void 0:r.byteStride)||0}}function Em(n,e){const t=n.attributes.find(i=>i.name===e);return t||D.warn(`shader layout attribute "${e}" not present in shader`),t||null}function Rm(n,e){km(n);let t=Dm(n,e);return t||(t=Mm(n,e),t)?t:(D.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function km(n){for(const e of n)(e.attributes&&e.format||!e.attributes&&!e.format)&&D.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function Dm(n,e){for(const t of n)if(t.format&&t.name===e)return{attributeName:t.name,bufferName:e,stepMode:t.stepMode,vertexFormat:t.format,byteOffset:0,byteStride:t.byteStride||0};return null}function Mm(n,e){var t;for(const i of n){let r=i.byteStride;if(typeof i.byteStride!="number")for(const o of i.attributes||[]){const a=cs(o.format);r+=a.byteLength}const s=(t=i.attributes)==null?void 0:t.find(o=>o.attribute===e);if(s)return{attributeName:s.attribute,bufferName:i.name,stepMode:i.stepMode,vertexFormat:s.format,byteOffset:s.byteOffset,byteStride:r}}return null}const Rr=class Rr extends ce{constructor(t,i){super(t,i,Rr.defaultProps);m(this,"maxVertexAttributes");m(this,"attributeInfos");m(this,"indexBuffer",null);m(this,"attributes");this.maxVertexAttributes=t.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=Im(i.shaderLayout,i.bufferLayout,this.maxVertexAttributes)}get[Symbol.toStringTag](){return"VertexArray"}setConstantWebGL(t,i){this.device.reportError(new Error("constant attributes not supported"),this)()}};m(Rr,"defaultProps",{...ce.defaultProps,shaderLayout:void 0,bufferLayout:[]});let ys=Rr;const kr=class kr extends ce{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,kr.defaultProps)}};m(kr,"defaultProps",{...ce.defaultProps,layout:void 0,buffers:{}});let vs=kr;const Dr=class Dr extends ce{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,Dr.defaultProps)}};m(Dr,"defaultProps",{...ce.defaultProps,type:void 0,count:void 0});let bs=Dr,Ui;function Za(n){return(!Ui||Ui.byteLength<n)&&(Ui=new ArrayBuffer(n)),Ui}function Fm(n,e){const t=Za(n.BYTES_PER_ELEMENT*e);return new n(t,0,e)}function Nm(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function zi(n){return Array.isArray(n)?n.length===0||typeof n[0]=="number":Nm(n)}const Om=1024;class Bm{constructor(e,t={}){m(this,"layout",{});m(this,"byteLength");let i=0;for(const[s,o]of Object.entries(e)){const a=ja(o),{type:l,components:c}=a,u=c*((t==null?void 0:t[s])??1);i=Wp(i,u);const f=i;i+=u,this.layout[s]={type:l,size:u,offset:f}}i+=(4-i%4)%4;const r=i*4;this.byteLength=Math.max(r,Om)}getData(e){const t=Za(this.byteLength),i={i32:new Int32Array(t),u32:new Uint32Array(t),f32:new Float32Array(t),f16:new Uint16Array(t)};for(const[r,s]of Object.entries(e)){const o=this.layout[r];if(!o){D.warn(`Supplied uniform value ${r} not present in uniform block layout`)();continue}const{type:a,size:l,offset:c}=o,u=i[a];if(l===1){if(typeof s!="number"&&typeof s!="boolean"){D.warn(`Supplied value for single component uniform ${r} is not a number: ${s}`)();continue}u[c]=Number(s)}else{if(!zi(s)){D.warn(`Supplied value for multi component / array uniform ${r} is not a numeric array: ${s}`)();continue}u.set(s,c)}}return new Uint8Array(t,0,this.byteLength)}has(e){return!!this.layout[e]}get(e){return this.layout[e]}}function Um(n,e,t=16){if(n!==e)return!1;const i=n,r=e;if(!zi(i))return!1;if(zi(r)&&i.length===r.length){for(let s=0;s<i.length;++s)if(r[s]!==i[s])return!1}return!0}function zm(n){return zi(n)?n.slice():n}class Lm{constructor(e){m(this,"name");m(this,"uniforms",{});m(this,"modifiedUniforms",{});m(this,"modified",!0);m(this,"bindingLayout",{});m(this,"needsRedraw","initialized");var t;if(this.name=(e==null?void 0:e.name)||"unnamed",e!=null&&e.name&&(e!=null&&e.shaderLayout)){const i=(t=e==null?void 0:e.shaderLayout.bindings)==null?void 0:t.find(s=>s.type==="uniform"&&s.name===(e==null?void 0:e.name));if(!i)throw new Error(e==null?void 0:e.name);const r=i;for(const s of r.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(const[t,i]of Object.entries(e))this._setUniform(t,i),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${i}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){Um(this.uniforms[e],t)||(this.uniforms[e]=zm(t),this.modifiedUniforms[e]=!0,this.modified=!0)}}class xe{constructor(e){m(this,"uniformBlocks",new Map);m(this,"uniformBufferLayouts",new Map);m(this,"uniformBuffers",new Map);for(const[t,i]of Object.entries(e)){const r=t,s=new Bm(i.uniformTypes??{},i.uniformSizes??{});this.uniformBufferLayouts.set(r,s);const o=new Lm({name:t});o.setUniforms(i.defaultUniforms||{}),this.uniformBlocks.set(r,o)}}destroy(){for(const e of this.uniformBuffers.values())e.destroy()}setUniforms(e){var t;for(const[i,r]of Object.entries(e))(t=this.uniformBlocks.get(i))==null||t.setUniforms(r);this.updateUniformBuffers()}getUniformBufferByteLength(e){var t;return((t=this.uniformBufferLayouts.get(e))==null?void 0:t.byteLength)||0}getUniformBufferData(e){var i,r;const t=((i=this.uniformBlocks.get(e))==null?void 0:i.getAllUniforms())||{};return(r=this.uniformBufferLayouts.get(e))==null?void 0:r.getData(t)}createUniformBuffer(e,t,i){i&&this.setUniforms(i);const r=this.getUniformBufferByteLength(t),s=e.createBuffer({usage:L.UNIFORM|L.COPY_DST,byteLength:r}),o=this.getUniformBufferData(t);return s.write(o),s}getManagedUniformBuffer(e,t){if(!this.uniformBuffers.get(t)){const i=this.getUniformBufferByteLength(t),r=e.createBuffer({usage:L.UNIFORM|L.COPY_DST,byteLength:i});this.uniformBuffers.set(t,r)}return this.uniformBuffers.get(t)}updateUniformBuffers(){let e=!1;for(const t of this.uniformBlocks.keys()){const i=this.updateUniformBuffer(t);e||(e=i)}return e&&D.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){var s;const t=this.uniformBlocks.get(e);let i=this.uniformBuffers.get(e),r=!1;if(i&&(t!=null&&t.needsRedraw)){r||(r=t.needsRedraw);const o=this.getUniformBufferData(e);i=this.uniformBuffers.get(e),i==null||i.write(o);const a=(s=this.uniformBlocks.get(e))==null?void 0:s.getAllUniforms();D.log(4,`Writing to uniform buffer ${String(e)}`,o,a)()}return r}}var $t;(function(n){n[n.DEPTH_BUFFER_BIT=256]="DEPTH_BUFFER_BIT",n[n.STENCIL_BUFFER_BIT=1024]="STENCIL_BUFFER_BIT",n[n.COLOR_BUFFER_BIT=16384]="COLOR_BUFFER_BIT",n[n.POINTS=0]="POINTS",n[n.LINES=1]="LINES",n[n.LINE_LOOP=2]="LINE_LOOP",n[n.LINE_STRIP=3]="LINE_STRIP",n[n.TRIANGLES=4]="TRIANGLES",n[n.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",n[n.TRIANGLE_FAN=6]="TRIANGLE_FAN",n[n.ZERO=0]="ZERO",n[n.ONE=1]="ONE",n[n.SRC_COLOR=768]="SRC_COLOR",n[n.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",n[n.SRC_ALPHA=770]="SRC_ALPHA",n[n.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",n[n.DST_ALPHA=772]="DST_ALPHA",n[n.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",n[n.DST_COLOR=774]="DST_COLOR",n[n.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",n[n.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE",n[n.CONSTANT_COLOR=32769]="CONSTANT_COLOR",n[n.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",n[n.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",n[n.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",n[n.FUNC_ADD=32774]="FUNC_ADD",n[n.FUNC_SUBTRACT=32778]="FUNC_SUBTRACT",n[n.FUNC_REVERSE_SUBTRACT=32779]="FUNC_REVERSE_SUBTRACT",n[n.BLEND_EQUATION=32777]="BLEND_EQUATION",n[n.BLEND_EQUATION_RGB=32777]="BLEND_EQUATION_RGB",n[n.BLEND_EQUATION_ALPHA=34877]="BLEND_EQUATION_ALPHA",n[n.BLEND_DST_RGB=32968]="BLEND_DST_RGB",n[n.BLEND_SRC_RGB=32969]="BLEND_SRC_RGB",n[n.BLEND_DST_ALPHA=32970]="BLEND_DST_ALPHA",n[n.BLEND_SRC_ALPHA=32971]="BLEND_SRC_ALPHA",n[n.BLEND_COLOR=32773]="BLEND_COLOR",n[n.ARRAY_BUFFER_BINDING=34964]="ARRAY_BUFFER_BINDING",n[n.ELEMENT_ARRAY_BUFFER_BINDING=34965]="ELEMENT_ARRAY_BUFFER_BINDING",n[n.LINE_WIDTH=2849]="LINE_WIDTH",n[n.ALIASED_POINT_SIZE_RANGE=33901]="ALIASED_POINT_SIZE_RANGE",n[n.ALIASED_LINE_WIDTH_RANGE=33902]="ALIASED_LINE_WIDTH_RANGE",n[n.CULL_FACE_MODE=2885]="CULL_FACE_MODE",n[n.FRONT_FACE=2886]="FRONT_FACE",n[n.DEPTH_RANGE=2928]="DEPTH_RANGE",n[n.DEPTH_WRITEMASK=2930]="DEPTH_WRITEMASK",n[n.DEPTH_CLEAR_VALUE=2931]="DEPTH_CLEAR_VALUE",n[n.DEPTH_FUNC=2932]="DEPTH_FUNC",n[n.STENCIL_CLEAR_VALUE=2961]="STENCIL_CLEAR_VALUE",n[n.STENCIL_FUNC=2962]="STENCIL_FUNC",n[n.STENCIL_FAIL=2964]="STENCIL_FAIL",n[n.STENCIL_PASS_DEPTH_FAIL=2965]="STENCIL_PASS_DEPTH_FAIL",n[n.STENCIL_PASS_DEPTH_PASS=2966]="STENCIL_PASS_DEPTH_PASS",n[n.STENCIL_REF=2967]="STENCIL_REF",n[n.STENCIL_VALUE_MASK=2963]="STENCIL_VALUE_MASK",n[n.STENCIL_WRITEMASK=2968]="STENCIL_WRITEMASK",n[n.STENCIL_BACK_FUNC=34816]="STENCIL_BACK_FUNC",n[n.STENCIL_BACK_FAIL=34817]="STENCIL_BACK_FAIL",n[n.STENCIL_BACK_PASS_DEPTH_FAIL=34818]="STENCIL_BACK_PASS_DEPTH_FAIL",n[n.STENCIL_BACK_PASS_DEPTH_PASS=34819]="STENCIL_BACK_PASS_DEPTH_PASS",n[n.STENCIL_BACK_REF=36003]="STENCIL_BACK_REF",n[n.STENCIL_BACK_VALUE_MASK=36004]="STENCIL_BACK_VALUE_MASK",n[n.STENCIL_BACK_WRITEMASK=36005]="STENCIL_BACK_WRITEMASK",n[n.VIEWPORT=2978]="VIEWPORT",n[n.SCISSOR_BOX=3088]="SCISSOR_BOX",n[n.COLOR_CLEAR_VALUE=3106]="COLOR_CLEAR_VALUE",n[n.COLOR_WRITEMASK=3107]="COLOR_WRITEMASK",n[n.UNPACK_ALIGNMENT=3317]="UNPACK_ALIGNMENT",n[n.PACK_ALIGNMENT=3333]="PACK_ALIGNMENT",n[n.MAX_TEXTURE_SIZE=3379]="MAX_TEXTURE_SIZE",n[n.MAX_VIEWPORT_DIMS=3386]="MAX_VIEWPORT_DIMS",n[n.SUBPIXEL_BITS=3408]="SUBPIXEL_BITS",n[n.RED_BITS=3410]="RED_BITS",n[n.GREEN_BITS=3411]="GREEN_BITS",n[n.BLUE_BITS=3412]="BLUE_BITS",n[n.ALPHA_BITS=3413]="ALPHA_BITS",n[n.DEPTH_BITS=3414]="DEPTH_BITS",n[n.STENCIL_BITS=3415]="STENCIL_BITS",n[n.POLYGON_OFFSET_UNITS=10752]="POLYGON_OFFSET_UNITS",n[n.POLYGON_OFFSET_FACTOR=32824]="POLYGON_OFFSET_FACTOR",n[n.TEXTURE_BINDING_2D=32873]="TEXTURE_BINDING_2D",n[n.SAMPLE_BUFFERS=32936]="SAMPLE_BUFFERS",n[n.SAMPLES=32937]="SAMPLES",n[n.SAMPLE_COVERAGE_VALUE=32938]="SAMPLE_COVERAGE_VALUE",n[n.SAMPLE_COVERAGE_INVERT=32939]="SAMPLE_COVERAGE_INVERT",n[n.COMPRESSED_TEXTURE_FORMATS=34467]="COMPRESSED_TEXTURE_FORMATS",n[n.VENDOR=7936]="VENDOR",n[n.RENDERER=7937]="RENDERER",n[n.VERSION=7938]="VERSION",n[n.IMPLEMENTATION_COLOR_READ_TYPE=35738]="IMPLEMENTATION_COLOR_READ_TYPE",n[n.IMPLEMENTATION_COLOR_READ_FORMAT=35739]="IMPLEMENTATION_COLOR_READ_FORMAT",n[n.BROWSER_DEFAULT_WEBGL=37444]="BROWSER_DEFAULT_WEBGL",n[n.STATIC_DRAW=35044]="STATIC_DRAW",n[n.STREAM_DRAW=35040]="STREAM_DRAW",n[n.DYNAMIC_DRAW=35048]="DYNAMIC_DRAW",n[n.ARRAY_BUFFER=34962]="ARRAY_BUFFER",n[n.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",n[n.BUFFER_SIZE=34660]="BUFFER_SIZE",n[n.BUFFER_USAGE=34661]="BUFFER_USAGE",n[n.CURRENT_VERTEX_ATTRIB=34342]="CURRENT_VERTEX_ATTRIB",n[n.VERTEX_ATTRIB_ARRAY_ENABLED=34338]="VERTEX_ATTRIB_ARRAY_ENABLED",n[n.VERTEX_ATTRIB_ARRAY_SIZE=34339]="VERTEX_ATTRIB_ARRAY_SIZE",n[n.VERTEX_ATTRIB_ARRAY_STRIDE=34340]="VERTEX_ATTRIB_ARRAY_STRIDE",n[n.VERTEX_ATTRIB_ARRAY_TYPE=34341]="VERTEX_ATTRIB_ARRAY_TYPE",n[n.VERTEX_ATTRIB_ARRAY_NORMALIZED=34922]="VERTEX_ATTRIB_ARRAY_NORMALIZED",n[n.VERTEX_ATTRIB_ARRAY_POINTER=34373]="VERTEX_ATTRIB_ARRAY_POINTER",n[n.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING=34975]="VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",n[n.CULL_FACE=2884]="CULL_FACE",n[n.FRONT=1028]="FRONT",n[n.BACK=1029]="BACK",n[n.FRONT_AND_BACK=1032]="FRONT_AND_BACK",n[n.BLEND=3042]="BLEND",n[n.DEPTH_TEST=2929]="DEPTH_TEST",n[n.DITHER=3024]="DITHER",n[n.POLYGON_OFFSET_FILL=32823]="POLYGON_OFFSET_FILL",n[n.SAMPLE_ALPHA_TO_COVERAGE=32926]="SAMPLE_ALPHA_TO_COVERAGE",n[n.SAMPLE_COVERAGE=32928]="SAMPLE_COVERAGE",n[n.SCISSOR_TEST=3089]="SCISSOR_TEST",n[n.STENCIL_TEST=2960]="STENCIL_TEST",n[n.NO_ERROR=0]="NO_ERROR",n[n.INVALID_ENUM=1280]="INVALID_ENUM",n[n.INVALID_VALUE=1281]="INVALID_VALUE",n[n.INVALID_OPERATION=1282]="INVALID_OPERATION",n[n.OUT_OF_MEMORY=1285]="OUT_OF_MEMORY",n[n.CONTEXT_LOST_WEBGL=37442]="CONTEXT_LOST_WEBGL",n[n.CW=2304]="CW",n[n.CCW=2305]="CCW",n[n.DONT_CARE=4352]="DONT_CARE",n[n.FASTEST=4353]="FASTEST",n[n.NICEST=4354]="NICEST",n[n.GENERATE_MIPMAP_HINT=33170]="GENERATE_MIPMAP_HINT",n[n.BYTE=5120]="BYTE",n[n.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",n[n.SHORT=5122]="SHORT",n[n.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",n[n.INT=5124]="INT",n[n.UNSIGNED_INT=5125]="UNSIGNED_INT",n[n.FLOAT=5126]="FLOAT",n[n.DOUBLE=5130]="DOUBLE",n[n.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",n[n.ALPHA=6406]="ALPHA",n[n.RGB=6407]="RGB",n[n.RGBA=6408]="RGBA",n[n.LUMINANCE=6409]="LUMINANCE",n[n.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",n[n.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",n[n.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",n[n.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",n[n.FRAGMENT_SHADER=35632]="FRAGMENT_SHADER",n[n.VERTEX_SHADER=35633]="VERTEX_SHADER",n[n.COMPILE_STATUS=35713]="COMPILE_STATUS",n[n.DELETE_STATUS=35712]="DELETE_STATUS",n[n.LINK_STATUS=35714]="LINK_STATUS",n[n.VALIDATE_STATUS=35715]="VALIDATE_STATUS",n[n.ATTACHED_SHADERS=35717]="ATTACHED_SHADERS",n[n.ACTIVE_ATTRIBUTES=35721]="ACTIVE_ATTRIBUTES",n[n.ACTIVE_UNIFORMS=35718]="ACTIVE_UNIFORMS",n[n.MAX_VERTEX_ATTRIBS=34921]="MAX_VERTEX_ATTRIBS",n[n.MAX_VERTEX_UNIFORM_VECTORS=36347]="MAX_VERTEX_UNIFORM_VECTORS",n[n.MAX_VARYING_VECTORS=36348]="MAX_VARYING_VECTORS",n[n.MAX_COMBINED_TEXTURE_IMAGE_UNITS=35661]="MAX_COMBINED_TEXTURE_IMAGE_UNITS",n[n.MAX_VERTEX_TEXTURE_IMAGE_UNITS=35660]="MAX_VERTEX_TEXTURE_IMAGE_UNITS",n[n.MAX_TEXTURE_IMAGE_UNITS=34930]="MAX_TEXTURE_IMAGE_UNITS",n[n.MAX_FRAGMENT_UNIFORM_VECTORS=36349]="MAX_FRAGMENT_UNIFORM_VECTORS",n[n.SHADER_TYPE=35663]="SHADER_TYPE",n[n.SHADING_LANGUAGE_VERSION=35724]="SHADING_LANGUAGE_VERSION",n[n.CURRENT_PROGRAM=35725]="CURRENT_PROGRAM",n[n.NEVER=512]="NEVER",n[n.LESS=513]="LESS",n[n.EQUAL=514]="EQUAL",n[n.LEQUAL=515]="LEQUAL",n[n.GREATER=516]="GREATER",n[n.NOTEQUAL=517]="NOTEQUAL",n[n.GEQUAL=518]="GEQUAL",n[n.ALWAYS=519]="ALWAYS",n[n.KEEP=7680]="KEEP",n[n.REPLACE=7681]="REPLACE",n[n.INCR=7682]="INCR",n[n.DECR=7683]="DECR",n[n.INVERT=5386]="INVERT",n[n.INCR_WRAP=34055]="INCR_WRAP",n[n.DECR_WRAP=34056]="DECR_WRAP",n[n.NEAREST=9728]="NEAREST",n[n.LINEAR=9729]="LINEAR",n[n.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",n[n.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",n[n.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",n[n.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",n[n.TEXTURE_MAG_FILTER=10240]="TEXTURE_MAG_FILTER",n[n.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",n[n.TEXTURE_WRAP_S=10242]="TEXTURE_WRAP_S",n[n.TEXTURE_WRAP_T=10243]="TEXTURE_WRAP_T",n[n.TEXTURE_2D=3553]="TEXTURE_2D",n[n.TEXTURE=5890]="TEXTURE",n[n.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",n[n.TEXTURE_BINDING_CUBE_MAP=34068]="TEXTURE_BINDING_CUBE_MAP",n[n.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",n[n.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",n[n.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",n[n.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",n[n.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",n[n.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",n[n.MAX_CUBE_MAP_TEXTURE_SIZE=34076]="MAX_CUBE_MAP_TEXTURE_SIZE",n[n.TEXTURE0=33984]="TEXTURE0",n[n.ACTIVE_TEXTURE=34016]="ACTIVE_TEXTURE",n[n.REPEAT=10497]="REPEAT",n[n.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",n[n.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",n[n.TEXTURE_WIDTH=4096]="TEXTURE_WIDTH",n[n.TEXTURE_HEIGHT=4097]="TEXTURE_HEIGHT",n[n.FLOAT_VEC2=35664]="FLOAT_VEC2",n[n.FLOAT_VEC3=35665]="FLOAT_VEC3",n[n.FLOAT_VEC4=35666]="FLOAT_VEC4",n[n.INT_VEC2=35667]="INT_VEC2",n[n.INT_VEC3=35668]="INT_VEC3",n[n.INT_VEC4=35669]="INT_VEC4",n[n.BOOL=35670]="BOOL",n[n.BOOL_VEC2=35671]="BOOL_VEC2",n[n.BOOL_VEC3=35672]="BOOL_VEC3",n[n.BOOL_VEC4=35673]="BOOL_VEC4",n[n.FLOAT_MAT2=35674]="FLOAT_MAT2",n[n.FLOAT_MAT3=35675]="FLOAT_MAT3",n[n.FLOAT_MAT4=35676]="FLOAT_MAT4",n[n.SAMPLER_2D=35678]="SAMPLER_2D",n[n.SAMPLER_CUBE=35680]="SAMPLER_CUBE",n[n.LOW_FLOAT=36336]="LOW_FLOAT",n[n.MEDIUM_FLOAT=36337]="MEDIUM_FLOAT",n[n.HIGH_FLOAT=36338]="HIGH_FLOAT",n[n.LOW_INT=36339]="LOW_INT",n[n.MEDIUM_INT=36340]="MEDIUM_INT",n[n.HIGH_INT=36341]="HIGH_INT",n[n.FRAMEBUFFER=36160]="FRAMEBUFFER",n[n.RENDERBUFFER=36161]="RENDERBUFFER",n[n.RGBA4=32854]="RGBA4",n[n.RGB5_A1=32855]="RGB5_A1",n[n.RGB565=36194]="RGB565",n[n.DEPTH_COMPONENT16=33189]="DEPTH_COMPONENT16",n[n.STENCIL_INDEX=6401]="STENCIL_INDEX",n[n.STENCIL_INDEX8=36168]="STENCIL_INDEX8",n[n.DEPTH_STENCIL=34041]="DEPTH_STENCIL",n[n.RENDERBUFFER_WIDTH=36162]="RENDERBUFFER_WIDTH",n[n.RENDERBUFFER_HEIGHT=36163]="RENDERBUFFER_HEIGHT",n[n.RENDERBUFFER_INTERNAL_FORMAT=36164]="RENDERBUFFER_INTERNAL_FORMAT",n[n.RENDERBUFFER_RED_SIZE=36176]="RENDERBUFFER_RED_SIZE",n[n.RENDERBUFFER_GREEN_SIZE=36177]="RENDERBUFFER_GREEN_SIZE",n[n.RENDERBUFFER_BLUE_SIZE=36178]="RENDERBUFFER_BLUE_SIZE",n[n.RENDERBUFFER_ALPHA_SIZE=36179]="RENDERBUFFER_ALPHA_SIZE",n[n.RENDERBUFFER_DEPTH_SIZE=36180]="RENDERBUFFER_DEPTH_SIZE",n[n.RENDERBUFFER_STENCIL_SIZE=36181]="RENDERBUFFER_STENCIL_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE=36048]="FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",n[n.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME=36049]="FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL=36050]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE=36051]="FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE",n[n.COLOR_ATTACHMENT0=36064]="COLOR_ATTACHMENT0",n[n.DEPTH_ATTACHMENT=36096]="DEPTH_ATTACHMENT",n[n.STENCIL_ATTACHMENT=36128]="STENCIL_ATTACHMENT",n[n.DEPTH_STENCIL_ATTACHMENT=33306]="DEPTH_STENCIL_ATTACHMENT",n[n.NONE=0]="NONE",n[n.FRAMEBUFFER_COMPLETE=36053]="FRAMEBUFFER_COMPLETE",n[n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT=36054]="FRAMEBUFFER_INCOMPLETE_ATTACHMENT",n[n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT=36055]="FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",n[n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS=36057]="FRAMEBUFFER_INCOMPLETE_DIMENSIONS",n[n.FRAMEBUFFER_UNSUPPORTED=36061]="FRAMEBUFFER_UNSUPPORTED",n[n.FRAMEBUFFER_BINDING=36006]="FRAMEBUFFER_BINDING",n[n.RENDERBUFFER_BINDING=36007]="RENDERBUFFER_BINDING",n[n.READ_FRAMEBUFFER=36008]="READ_FRAMEBUFFER",n[n.DRAW_FRAMEBUFFER=36009]="DRAW_FRAMEBUFFER",n[n.MAX_RENDERBUFFER_SIZE=34024]="MAX_RENDERBUFFER_SIZE",n[n.INVALID_FRAMEBUFFER_OPERATION=1286]="INVALID_FRAMEBUFFER_OPERATION",n[n.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL",n[n.UNPACK_PREMULTIPLY_ALPHA_WEBGL=37441]="UNPACK_PREMULTIPLY_ALPHA_WEBGL",n[n.UNPACK_COLORSPACE_CONVERSION_WEBGL=37443]="UNPACK_COLORSPACE_CONVERSION_WEBGL",n[n.READ_BUFFER=3074]="READ_BUFFER",n[n.UNPACK_ROW_LENGTH=3314]="UNPACK_ROW_LENGTH",n[n.UNPACK_SKIP_ROWS=3315]="UNPACK_SKIP_ROWS",n[n.UNPACK_SKIP_PIXELS=3316]="UNPACK_SKIP_PIXELS",n[n.PACK_ROW_LENGTH=3330]="PACK_ROW_LENGTH",n[n.PACK_SKIP_ROWS=3331]="PACK_SKIP_ROWS",n[n.PACK_SKIP_PIXELS=3332]="PACK_SKIP_PIXELS",n[n.TEXTURE_BINDING_3D=32874]="TEXTURE_BINDING_3D",n[n.UNPACK_SKIP_IMAGES=32877]="UNPACK_SKIP_IMAGES",n[n.UNPACK_IMAGE_HEIGHT=32878]="UNPACK_IMAGE_HEIGHT",n[n.MAX_3D_TEXTURE_SIZE=32883]="MAX_3D_TEXTURE_SIZE",n[n.MAX_ELEMENTS_VERTICES=33e3]="MAX_ELEMENTS_VERTICES",n[n.MAX_ELEMENTS_INDICES=33001]="MAX_ELEMENTS_INDICES",n[n.MAX_TEXTURE_LOD_BIAS=34045]="MAX_TEXTURE_LOD_BIAS",n[n.MAX_FRAGMENT_UNIFORM_COMPONENTS=35657]="MAX_FRAGMENT_UNIFORM_COMPONENTS",n[n.MAX_VERTEX_UNIFORM_COMPONENTS=35658]="MAX_VERTEX_UNIFORM_COMPONENTS",n[n.MAX_ARRAY_TEXTURE_LAYERS=35071]="MAX_ARRAY_TEXTURE_LAYERS",n[n.MIN_PROGRAM_TEXEL_OFFSET=35076]="MIN_PROGRAM_TEXEL_OFFSET",n[n.MAX_PROGRAM_TEXEL_OFFSET=35077]="MAX_PROGRAM_TEXEL_OFFSET",n[n.MAX_VARYING_COMPONENTS=35659]="MAX_VARYING_COMPONENTS",n[n.FRAGMENT_SHADER_DERIVATIVE_HINT=35723]="FRAGMENT_SHADER_DERIVATIVE_HINT",n[n.RASTERIZER_DISCARD=35977]="RASTERIZER_DISCARD",n[n.VERTEX_ARRAY_BINDING=34229]="VERTEX_ARRAY_BINDING",n[n.MAX_VERTEX_OUTPUT_COMPONENTS=37154]="MAX_VERTEX_OUTPUT_COMPONENTS",n[n.MAX_FRAGMENT_INPUT_COMPONENTS=37157]="MAX_FRAGMENT_INPUT_COMPONENTS",n[n.MAX_SERVER_WAIT_TIMEOUT=37137]="MAX_SERVER_WAIT_TIMEOUT",n[n.MAX_ELEMENT_INDEX=36203]="MAX_ELEMENT_INDEX",n[n.RED=6403]="RED",n[n.RGB8=32849]="RGB8",n[n.RGBA8=32856]="RGBA8",n[n.RGB10_A2=32857]="RGB10_A2",n[n.TEXTURE_3D=32879]="TEXTURE_3D",n[n.TEXTURE_WRAP_R=32882]="TEXTURE_WRAP_R",n[n.TEXTURE_MIN_LOD=33082]="TEXTURE_MIN_LOD",n[n.TEXTURE_MAX_LOD=33083]="TEXTURE_MAX_LOD",n[n.TEXTURE_BASE_LEVEL=33084]="TEXTURE_BASE_LEVEL",n[n.TEXTURE_MAX_LEVEL=33085]="TEXTURE_MAX_LEVEL",n[n.TEXTURE_COMPARE_MODE=34892]="TEXTURE_COMPARE_MODE",n[n.TEXTURE_COMPARE_FUNC=34893]="TEXTURE_COMPARE_FUNC",n[n.SRGB=35904]="SRGB",n[n.SRGB8=35905]="SRGB8",n[n.SRGB8_ALPHA8=35907]="SRGB8_ALPHA8",n[n.COMPARE_REF_TO_TEXTURE=34894]="COMPARE_REF_TO_TEXTURE",n[n.RGBA32F=34836]="RGBA32F",n[n.RGB32F=34837]="RGB32F",n[n.RGBA16F=34842]="RGBA16F",n[n.RGB16F=34843]="RGB16F",n[n.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",n[n.TEXTURE_BINDING_2D_ARRAY=35869]="TEXTURE_BINDING_2D_ARRAY",n[n.R11F_G11F_B10F=35898]="R11F_G11F_B10F",n[n.RGB9_E5=35901]="RGB9_E5",n[n.RGBA32UI=36208]="RGBA32UI",n[n.RGB32UI=36209]="RGB32UI",n[n.RGBA16UI=36214]="RGBA16UI",n[n.RGB16UI=36215]="RGB16UI",n[n.RGBA8UI=36220]="RGBA8UI",n[n.RGB8UI=36221]="RGB8UI",n[n.RGBA32I=36226]="RGBA32I",n[n.RGB32I=36227]="RGB32I",n[n.RGBA16I=36232]="RGBA16I",n[n.RGB16I=36233]="RGB16I",n[n.RGBA8I=36238]="RGBA8I",n[n.RGB8I=36239]="RGB8I",n[n.RED_INTEGER=36244]="RED_INTEGER",n[n.RGB_INTEGER=36248]="RGB_INTEGER",n[n.RGBA_INTEGER=36249]="RGBA_INTEGER",n[n.R8=33321]="R8",n[n.RG8=33323]="RG8",n[n.R16F=33325]="R16F",n[n.R32F=33326]="R32F",n[n.RG16F=33327]="RG16F",n[n.RG32F=33328]="RG32F",n[n.R8I=33329]="R8I",n[n.R8UI=33330]="R8UI",n[n.R16I=33331]="R16I",n[n.R16UI=33332]="R16UI",n[n.R32I=33333]="R32I",n[n.R32UI=33334]="R32UI",n[n.RG8I=33335]="RG8I",n[n.RG8UI=33336]="RG8UI",n[n.RG16I=33337]="RG16I",n[n.RG16UI=33338]="RG16UI",n[n.RG32I=33339]="RG32I",n[n.RG32UI=33340]="RG32UI",n[n.R8_SNORM=36756]="R8_SNORM",n[n.RG8_SNORM=36757]="RG8_SNORM",n[n.RGB8_SNORM=36758]="RGB8_SNORM",n[n.RGBA8_SNORM=36759]="RGBA8_SNORM",n[n.RGB10_A2UI=36975]="RGB10_A2UI",n[n.TEXTURE_IMMUTABLE_FORMAT=37167]="TEXTURE_IMMUTABLE_FORMAT",n[n.TEXTURE_IMMUTABLE_LEVELS=33503]="TEXTURE_IMMUTABLE_LEVELS",n[n.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",n[n.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",n[n.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",n[n.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",n[n.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",n[n.HALF_FLOAT=5131]="HALF_FLOAT",n[n.RG=33319]="RG",n[n.RG_INTEGER=33320]="RG_INTEGER",n[n.INT_2_10_10_10_REV=36255]="INT_2_10_10_10_REV",n[n.CURRENT_QUERY=34917]="CURRENT_QUERY",n[n.QUERY_RESULT=34918]="QUERY_RESULT",n[n.QUERY_RESULT_AVAILABLE=34919]="QUERY_RESULT_AVAILABLE",n[n.ANY_SAMPLES_PASSED=35887]="ANY_SAMPLES_PASSED",n[n.ANY_SAMPLES_PASSED_CONSERVATIVE=36202]="ANY_SAMPLES_PASSED_CONSERVATIVE",n[n.MAX_DRAW_BUFFERS=34852]="MAX_DRAW_BUFFERS",n[n.DRAW_BUFFER0=34853]="DRAW_BUFFER0",n[n.DRAW_BUFFER1=34854]="DRAW_BUFFER1",n[n.DRAW_BUFFER2=34855]="DRAW_BUFFER2",n[n.DRAW_BUFFER3=34856]="DRAW_BUFFER3",n[n.DRAW_BUFFER4=34857]="DRAW_BUFFER4",n[n.DRAW_BUFFER5=34858]="DRAW_BUFFER5",n[n.DRAW_BUFFER6=34859]="DRAW_BUFFER6",n[n.DRAW_BUFFER7=34860]="DRAW_BUFFER7",n[n.DRAW_BUFFER8=34861]="DRAW_BUFFER8",n[n.DRAW_BUFFER9=34862]="DRAW_BUFFER9",n[n.DRAW_BUFFER10=34863]="DRAW_BUFFER10",n[n.DRAW_BUFFER11=34864]="DRAW_BUFFER11",n[n.DRAW_BUFFER12=34865]="DRAW_BUFFER12",n[n.DRAW_BUFFER13=34866]="DRAW_BUFFER13",n[n.DRAW_BUFFER14=34867]="DRAW_BUFFER14",n[n.DRAW_BUFFER15=34868]="DRAW_BUFFER15",n[n.MAX_COLOR_ATTACHMENTS=36063]="MAX_COLOR_ATTACHMENTS",n[n.COLOR_ATTACHMENT1=36065]="COLOR_ATTACHMENT1",n[n.COLOR_ATTACHMENT2=36066]="COLOR_ATTACHMENT2",n[n.COLOR_ATTACHMENT3=36067]="COLOR_ATTACHMENT3",n[n.COLOR_ATTACHMENT4=36068]="COLOR_ATTACHMENT4",n[n.COLOR_ATTACHMENT5=36069]="COLOR_ATTACHMENT5",n[n.COLOR_ATTACHMENT6=36070]="COLOR_ATTACHMENT6",n[n.COLOR_ATTACHMENT7=36071]="COLOR_ATTACHMENT7",n[n.COLOR_ATTACHMENT8=36072]="COLOR_ATTACHMENT8",n[n.COLOR_ATTACHMENT9=36073]="COLOR_ATTACHMENT9",n[n.COLOR_ATTACHMENT10=36074]="COLOR_ATTACHMENT10",n[n.COLOR_ATTACHMENT11=36075]="COLOR_ATTACHMENT11",n[n.COLOR_ATTACHMENT12=36076]="COLOR_ATTACHMENT12",n[n.COLOR_ATTACHMENT13=36077]="COLOR_ATTACHMENT13",n[n.COLOR_ATTACHMENT14=36078]="COLOR_ATTACHMENT14",n[n.COLOR_ATTACHMENT15=36079]="COLOR_ATTACHMENT15",n[n.SAMPLER_3D=35679]="SAMPLER_3D",n[n.SAMPLER_2D_SHADOW=35682]="SAMPLER_2D_SHADOW",n[n.SAMPLER_2D_ARRAY=36289]="SAMPLER_2D_ARRAY",n[n.SAMPLER_2D_ARRAY_SHADOW=36292]="SAMPLER_2D_ARRAY_SHADOW",n[n.SAMPLER_CUBE_SHADOW=36293]="SAMPLER_CUBE_SHADOW",n[n.INT_SAMPLER_2D=36298]="INT_SAMPLER_2D",n[n.INT_SAMPLER_3D=36299]="INT_SAMPLER_3D",n[n.INT_SAMPLER_CUBE=36300]="INT_SAMPLER_CUBE",n[n.INT_SAMPLER_2D_ARRAY=36303]="INT_SAMPLER_2D_ARRAY",n[n.UNSIGNED_INT_SAMPLER_2D=36306]="UNSIGNED_INT_SAMPLER_2D",n[n.UNSIGNED_INT_SAMPLER_3D=36307]="UNSIGNED_INT_SAMPLER_3D",n[n.UNSIGNED_INT_SAMPLER_CUBE=36308]="UNSIGNED_INT_SAMPLER_CUBE",n[n.UNSIGNED_INT_SAMPLER_2D_ARRAY=36311]="UNSIGNED_INT_SAMPLER_2D_ARRAY",n[n.MAX_SAMPLES=36183]="MAX_SAMPLES",n[n.SAMPLER_BINDING=35097]="SAMPLER_BINDING",n[n.PIXEL_PACK_BUFFER=35051]="PIXEL_PACK_BUFFER",n[n.PIXEL_UNPACK_BUFFER=35052]="PIXEL_UNPACK_BUFFER",n[n.PIXEL_PACK_BUFFER_BINDING=35053]="PIXEL_PACK_BUFFER_BINDING",n[n.PIXEL_UNPACK_BUFFER_BINDING=35055]="PIXEL_UNPACK_BUFFER_BINDING",n[n.COPY_READ_BUFFER=36662]="COPY_READ_BUFFER",n[n.COPY_WRITE_BUFFER=36663]="COPY_WRITE_BUFFER",n[n.COPY_READ_BUFFER_BINDING=36662]="COPY_READ_BUFFER_BINDING",n[n.COPY_WRITE_BUFFER_BINDING=36663]="COPY_WRITE_BUFFER_BINDING",n[n.FLOAT_MAT2x3=35685]="FLOAT_MAT2x3",n[n.FLOAT_MAT2x4=35686]="FLOAT_MAT2x4",n[n.FLOAT_MAT3x2=35687]="FLOAT_MAT3x2",n[n.FLOAT_MAT3x4=35688]="FLOAT_MAT3x4",n[n.FLOAT_MAT4x2=35689]="FLOAT_MAT4x2",n[n.FLOAT_MAT4x3=35690]="FLOAT_MAT4x3",n[n.UNSIGNED_INT_VEC2=36294]="UNSIGNED_INT_VEC2",n[n.UNSIGNED_INT_VEC3=36295]="UNSIGNED_INT_VEC3",n[n.UNSIGNED_INT_VEC4=36296]="UNSIGNED_INT_VEC4",n[n.UNSIGNED_NORMALIZED=35863]="UNSIGNED_NORMALIZED",n[n.SIGNED_NORMALIZED=36764]="SIGNED_NORMALIZED",n[n.VERTEX_ATTRIB_ARRAY_INTEGER=35069]="VERTEX_ATTRIB_ARRAY_INTEGER",n[n.VERTEX_ATTRIB_ARRAY_DIVISOR=35070]="VERTEX_ATTRIB_ARRAY_DIVISOR",n[n.TRANSFORM_FEEDBACK_BUFFER_MODE=35967]="TRANSFORM_FEEDBACK_BUFFER_MODE",n[n.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS=35968]="MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS",n[n.TRANSFORM_FEEDBACK_VARYINGS=35971]="TRANSFORM_FEEDBACK_VARYINGS",n[n.TRANSFORM_FEEDBACK_BUFFER_START=35972]="TRANSFORM_FEEDBACK_BUFFER_START",n[n.TRANSFORM_FEEDBACK_BUFFER_SIZE=35973]="TRANSFORM_FEEDBACK_BUFFER_SIZE",n[n.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN=35976]="TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN",n[n.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS=35978]="MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS",n[n.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS=35979]="MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS",n[n.INTERLEAVED_ATTRIBS=35980]="INTERLEAVED_ATTRIBS",n[n.SEPARATE_ATTRIBS=35981]="SEPARATE_ATTRIBS",n[n.TRANSFORM_FEEDBACK_BUFFER=35982]="TRANSFORM_FEEDBACK_BUFFER",n[n.TRANSFORM_FEEDBACK_BUFFER_BINDING=35983]="TRANSFORM_FEEDBACK_BUFFER_BINDING",n[n.TRANSFORM_FEEDBACK=36386]="TRANSFORM_FEEDBACK",n[n.TRANSFORM_FEEDBACK_PAUSED=36387]="TRANSFORM_FEEDBACK_PAUSED",n[n.TRANSFORM_FEEDBACK_ACTIVE=36388]="TRANSFORM_FEEDBACK_ACTIVE",n[n.TRANSFORM_FEEDBACK_BINDING=36389]="TRANSFORM_FEEDBACK_BINDING",n[n.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING=33296]="FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING",n[n.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE=33297]="FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE",n[n.FRAMEBUFFER_ATTACHMENT_RED_SIZE=33298]="FRAMEBUFFER_ATTACHMENT_RED_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_GREEN_SIZE=33299]="FRAMEBUFFER_ATTACHMENT_GREEN_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_BLUE_SIZE=33300]="FRAMEBUFFER_ATTACHMENT_BLUE_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE=33301]="FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE=33302]="FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE=33303]="FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE",n[n.FRAMEBUFFER_DEFAULT=33304]="FRAMEBUFFER_DEFAULT",n[n.DEPTH24_STENCIL8=35056]="DEPTH24_STENCIL8",n[n.DRAW_FRAMEBUFFER_BINDING=36006]="DRAW_FRAMEBUFFER_BINDING",n[n.READ_FRAMEBUFFER_BINDING=36010]="READ_FRAMEBUFFER_BINDING",n[n.RENDERBUFFER_SAMPLES=36011]="RENDERBUFFER_SAMPLES",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER=36052]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER",n[n.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE=36182]="FRAMEBUFFER_INCOMPLETE_MULTISAMPLE",n[n.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",n[n.UNIFORM_BUFFER_BINDING=35368]="UNIFORM_BUFFER_BINDING",n[n.UNIFORM_BUFFER_START=35369]="UNIFORM_BUFFER_START",n[n.UNIFORM_BUFFER_SIZE=35370]="UNIFORM_BUFFER_SIZE",n[n.MAX_VERTEX_UNIFORM_BLOCKS=35371]="MAX_VERTEX_UNIFORM_BLOCKS",n[n.MAX_FRAGMENT_UNIFORM_BLOCKS=35373]="MAX_FRAGMENT_UNIFORM_BLOCKS",n[n.MAX_COMBINED_UNIFORM_BLOCKS=35374]="MAX_COMBINED_UNIFORM_BLOCKS",n[n.MAX_UNIFORM_BUFFER_BINDINGS=35375]="MAX_UNIFORM_BUFFER_BINDINGS",n[n.MAX_UNIFORM_BLOCK_SIZE=35376]="MAX_UNIFORM_BLOCK_SIZE",n[n.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS=35377]="MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS",n[n.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS=35379]="MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS",n[n.UNIFORM_BUFFER_OFFSET_ALIGNMENT=35380]="UNIFORM_BUFFER_OFFSET_ALIGNMENT",n[n.ACTIVE_UNIFORM_BLOCKS=35382]="ACTIVE_UNIFORM_BLOCKS",n[n.UNIFORM_TYPE=35383]="UNIFORM_TYPE",n[n.UNIFORM_SIZE=35384]="UNIFORM_SIZE",n[n.UNIFORM_BLOCK_INDEX=35386]="UNIFORM_BLOCK_INDEX",n[n.UNIFORM_OFFSET=35387]="UNIFORM_OFFSET",n[n.UNIFORM_ARRAY_STRIDE=35388]="UNIFORM_ARRAY_STRIDE",n[n.UNIFORM_MATRIX_STRIDE=35389]="UNIFORM_MATRIX_STRIDE",n[n.UNIFORM_IS_ROW_MAJOR=35390]="UNIFORM_IS_ROW_MAJOR",n[n.UNIFORM_BLOCK_BINDING=35391]="UNIFORM_BLOCK_BINDING",n[n.UNIFORM_BLOCK_DATA_SIZE=35392]="UNIFORM_BLOCK_DATA_SIZE",n[n.UNIFORM_BLOCK_ACTIVE_UNIFORMS=35394]="UNIFORM_BLOCK_ACTIVE_UNIFORMS",n[n.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES=35395]="UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES",n[n.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER=35396]="UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER",n[n.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER=35398]="UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER",n[n.OBJECT_TYPE=37138]="OBJECT_TYPE",n[n.SYNC_CONDITION=37139]="SYNC_CONDITION",n[n.SYNC_STATUS=37140]="SYNC_STATUS",n[n.SYNC_FLAGS=37141]="SYNC_FLAGS",n[n.SYNC_FENCE=37142]="SYNC_FENCE",n[n.SYNC_GPU_COMMANDS_COMPLETE=37143]="SYNC_GPU_COMMANDS_COMPLETE",n[n.UNSIGNALED=37144]="UNSIGNALED",n[n.SIGNALED=37145]="SIGNALED",n[n.ALREADY_SIGNALED=37146]="ALREADY_SIGNALED",n[n.TIMEOUT_EXPIRED=37147]="TIMEOUT_EXPIRED",n[n.CONDITION_SATISFIED=37148]="CONDITION_SATISFIED",n[n.WAIT_FAILED=37149]="WAIT_FAILED",n[n.SYNC_FLUSH_COMMANDS_BIT=1]="SYNC_FLUSH_COMMANDS_BIT",n[n.COLOR=6144]="COLOR",n[n.DEPTH=6145]="DEPTH",n[n.STENCIL=6146]="STENCIL",n[n.MIN=32775]="MIN",n[n.MAX=32776]="MAX",n[n.DEPTH_COMPONENT24=33190]="DEPTH_COMPONENT24",n[n.STREAM_READ=35041]="STREAM_READ",n[n.STREAM_COPY=35042]="STREAM_COPY",n[n.STATIC_READ=35045]="STATIC_READ",n[n.STATIC_COPY=35046]="STATIC_COPY",n[n.DYNAMIC_READ=35049]="DYNAMIC_READ",n[n.DYNAMIC_COPY=35050]="DYNAMIC_COPY",n[n.DEPTH_COMPONENT32F=36012]="DEPTH_COMPONENT32F",n[n.DEPTH32F_STENCIL8=36013]="DEPTH32F_STENCIL8",n[n.INVALID_INDEX=4294967295]="INVALID_INDEX",n[n.TIMEOUT_IGNORED=-1]="TIMEOUT_IGNORED",n[n.MAX_CLIENT_WAIT_TIMEOUT_WEBGL=37447]="MAX_CLIENT_WAIT_TIMEOUT_WEBGL",n[n.UNMASKED_VENDOR_WEBGL=37445]="UNMASKED_VENDOR_WEBGL",n[n.UNMASKED_RENDERER_WEBGL=37446]="UNMASKED_RENDERER_WEBGL",n[n.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047]="MAX_TEXTURE_MAX_ANISOTROPY_EXT",n[n.TEXTURE_MAX_ANISOTROPY_EXT=34046]="TEXTURE_MAX_ANISOTROPY_EXT",n[n.R16_EXT=33322]="R16_EXT",n[n.RG16_EXT=33324]="RG16_EXT",n[n.RGB16_EXT=32852]="RGB16_EXT",n[n.RGBA16_EXT=32859]="RGBA16_EXT",n[n.R16_SNORM_EXT=36760]="R16_SNORM_EXT",n[n.RG16_SNORM_EXT=36761]="RG16_SNORM_EXT",n[n.RGB16_SNORM_EXT=36762]="RGB16_SNORM_EXT",n[n.RGBA16_SNORM_EXT=36763]="RGBA16_SNORM_EXT",n[n.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",n[n.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",n[n.COMPRESSED_RED_RGTC1_EXT=36283]="COMPRESSED_RED_RGTC1_EXT",n[n.COMPRESSED_SIGNED_RED_RGTC1_EXT=36284]="COMPRESSED_SIGNED_RED_RGTC1_EXT",n[n.COMPRESSED_RED_GREEN_RGTC2_EXT=36285]="COMPRESSED_RED_GREEN_RGTC2_EXT",n[n.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT=36286]="COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT",n[n.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",n[n.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",n[n.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",n[n.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",n[n.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",n[n.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",n[n.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",n[n.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",n[n.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",n[n.COMPRESSED_RGBA8_ETC2_EAC=37493]="COMPRESSED_RGBA8_ETC2_EAC",n[n.COMPRESSED_SRGB8_ETC2=37494]="COMPRESSED_SRGB8_ETC2",n[n.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37495]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",n[n.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37496]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",n[n.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37497]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",n[n.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",n[n.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",n[n.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",n[n.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",n[n.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",n[n.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",n[n.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35986]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",n[n.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",n[n.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",n[n.COMPRESSED_RGBA_ASTC_5x4_KHR=37809]="COMPRESSED_RGBA_ASTC_5x4_KHR",n[n.COMPRESSED_RGBA_ASTC_5x5_KHR=37810]="COMPRESSED_RGBA_ASTC_5x5_KHR",n[n.COMPRESSED_RGBA_ASTC_6x5_KHR=37811]="COMPRESSED_RGBA_ASTC_6x5_KHR",n[n.COMPRESSED_RGBA_ASTC_6x6_KHR=37812]="COMPRESSED_RGBA_ASTC_6x6_KHR",n[n.COMPRESSED_RGBA_ASTC_8x5_KHR=37813]="COMPRESSED_RGBA_ASTC_8x5_KHR",n[n.COMPRESSED_RGBA_ASTC_8x6_KHR=37814]="COMPRESSED_RGBA_ASTC_8x6_KHR",n[n.COMPRESSED_RGBA_ASTC_8x8_KHR=37815]="COMPRESSED_RGBA_ASTC_8x8_KHR",n[n.COMPRESSED_RGBA_ASTC_10x5_KHR=37816]="COMPRESSED_RGBA_ASTC_10x5_KHR",n[n.COMPRESSED_RGBA_ASTC_10x6_KHR=37817]="COMPRESSED_RGBA_ASTC_10x6_KHR",n[n.COMPRESSED_RGBA_ASTC_10x8_KHR=37818]="COMPRESSED_RGBA_ASTC_10x8_KHR",n[n.COMPRESSED_RGBA_ASTC_10x10_KHR=37819]="COMPRESSED_RGBA_ASTC_10x10_KHR",n[n.COMPRESSED_RGBA_ASTC_12x10_KHR=37820]="COMPRESSED_RGBA_ASTC_12x10_KHR",n[n.COMPRESSED_RGBA_ASTC_12x12_KHR=37821]="COMPRESSED_RGBA_ASTC_12x12_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR=37840]="COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR=37841]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR=37842]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR=37843]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR=37844]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR=37845]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR=37846]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR=37847]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR=37848]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR=37849]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR=37850]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR=37851]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR=37852]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR=37853]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR",n[n.QUERY_COUNTER_BITS_EXT=34916]="QUERY_COUNTER_BITS_EXT",n[n.CURRENT_QUERY_EXT=34917]="CURRENT_QUERY_EXT",n[n.QUERY_RESULT_EXT=34918]="QUERY_RESULT_EXT",n[n.QUERY_RESULT_AVAILABLE_EXT=34919]="QUERY_RESULT_AVAILABLE_EXT",n[n.TIME_ELAPSED_EXT=35007]="TIME_ELAPSED_EXT",n[n.TIMESTAMP_EXT=36392]="TIMESTAMP_EXT",n[n.GPU_DISJOINT_EXT=36795]="GPU_DISJOINT_EXT",n[n.COMPLETION_STATUS_KHR=37297]="COMPLETION_STATUS_KHR",n[n.DEPTH_CLAMP_EXT=34383]="DEPTH_CLAMP_EXT",n[n.FIRST_VERTEX_CONVENTION_WEBGL=36429]="FIRST_VERTEX_CONVENTION_WEBGL",n[n.LAST_VERTEX_CONVENTION_WEBGL=36430]="LAST_VERTEX_CONVENTION_WEBGL",n[n.PROVOKING_VERTEX_WEBL=36431]="PROVOKING_VERTEX_WEBL",n[n.POLYGON_MODE_WEBGL=2880]="POLYGON_MODE_WEBGL",n[n.POLYGON_OFFSET_LINE_WEBGL=10754]="POLYGON_OFFSET_LINE_WEBGL",n[n.LINE_WEBGL=6913]="LINE_WEBGL",n[n.FILL_WEBGL=6914]="FILL_WEBGL",n[n.MAX_CLIP_DISTANCES_WEBGL=3378]="MAX_CLIP_DISTANCES_WEBGL",n[n.MAX_CULL_DISTANCES_WEBGL=33529]="MAX_CULL_DISTANCES_WEBGL",n[n.MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL=33530]="MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL",n[n.CLIP_DISTANCE0_WEBGL=12288]="CLIP_DISTANCE0_WEBGL",n[n.CLIP_DISTANCE1_WEBGL=12289]="CLIP_DISTANCE1_WEBGL",n[n.CLIP_DISTANCE2_WEBGL=12290]="CLIP_DISTANCE2_WEBGL",n[n.CLIP_DISTANCE3_WEBGL=12291]="CLIP_DISTANCE3_WEBGL",n[n.CLIP_DISTANCE4_WEBGL=12292]="CLIP_DISTANCE4_WEBGL",n[n.CLIP_DISTANCE5_WEBGL=12293]="CLIP_DISTANCE5_WEBGL",n[n.CLIP_DISTANCE6_WEBGL=12294]="CLIP_DISTANCE6_WEBGL",n[n.CLIP_DISTANCE7_WEBGL=12295]="CLIP_DISTANCE7_WEBGL",n[n.POLYGON_OFFSET_CLAMP_EXT=36379]="POLYGON_OFFSET_CLAMP_EXT",n[n.LOWER_LEFT_EXT=36001]="LOWER_LEFT_EXT",n[n.UPPER_LEFT_EXT=36002]="UPPER_LEFT_EXT",n[n.NEGATIVE_ONE_TO_ONE_EXT=37726]="NEGATIVE_ONE_TO_ONE_EXT",n[n.ZERO_TO_ONE_EXT=37727]="ZERO_TO_ONE_EXT",n[n.CLIP_ORIGIN_EXT=37724]="CLIP_ORIGIN_EXT",n[n.CLIP_DEPTH_MODE_EXT=37725]="CLIP_DEPTH_MODE_EXT",n[n.SRC1_COLOR_WEBGL=35065]="SRC1_COLOR_WEBGL",n[n.SRC1_ALPHA_WEBGL=34185]="SRC1_ALPHA_WEBGL",n[n.ONE_MINUS_SRC1_COLOR_WEBGL=35066]="ONE_MINUS_SRC1_COLOR_WEBGL",n[n.ONE_MINUS_SRC1_ALPHA_WEBGL=35067]="ONE_MINUS_SRC1_ALPHA_WEBGL",n[n.MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL=35068]="MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL",n[n.MIRROR_CLAMP_TO_EDGE_EXT=34627]="MIRROR_CLAMP_TO_EDGE_EXT"})($t||($t={}));const Vm={WEBGL_depth_texture:{UNSIGNED_INT_24_8_WEBGL:34042},OES_element_index_uint:{},OES_texture_float:{},OES_texture_half_float:{HALF_FLOAT_OES:5131},EXT_color_buffer_float:{},OES_standard_derivatives:{FRAGMENT_SHADER_DERIVATIVE_HINT_OES:35723},EXT_frag_depth:{},EXT_blend_minmax:{MIN_EXT:32775,MAX_EXT:32776},EXT_shader_texture_lod:{}},Hm=n=>({drawBuffersWEBGL(e){return n.drawBuffers(e)},COLOR_ATTACHMENT0_WEBGL:36064,COLOR_ATTACHMENT1_WEBGL:36065,COLOR_ATTACHMENT2_WEBGL:36066,COLOR_ATTACHMENT3_WEBGL:36067}),Wm=n=>({VERTEX_ARRAY_BINDING_OES:34229,createVertexArrayOES(){return n.createVertexArray()},deleteVertexArrayOES(e){return n.deleteVertexArray(e)},isVertexArrayOES(e){return n.isVertexArray(e)},bindVertexArrayOES(e){return n.bindVertexArray(e)}}),$m=n=>({VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE:35070,drawArraysInstancedANGLE(...e){return n.drawArraysInstanced(...e)},drawElementsInstancedANGLE(...e){return n.drawElementsInstanced(...e)},vertexAttribDivisorANGLE(...e){return n.vertexAttribDivisor(...e)}});function Xm(n=!0){const e=HTMLCanvasElement.prototype;if(!n&&e.originalGetContext){e.getContext=e.originalGetContext,e.originalGetContext=void 0;return}e.originalGetContext=e.getContext,e.getContext=function(t,i){if(t==="webgl"||t==="experimental-webgl"){const r=this.originalGetContext("webgl2",i);return r instanceof HTMLElement&&Ym(r),r}return this.originalGetContext(t,i)}}function Ym(n){n.getExtension("EXT_color_buffer_float");const e={...Vm,WEBGL_disjoint_timer_query:n.getExtension("EXT_disjoint_timer_query_webgl2"),WEBGL_draw_buffers:Hm(n),OES_vertex_array_object:Wm(n),ANGLE_instanced_arrays:$m(n)},t=n.getExtension;n.getExtension=function(r){const s=t.call(n,r);return s||(r in e?e[r]:null)};const i=n.getSupportedExtensions;n.getSupportedExtensions=function(){const r=i.apply(n)||[];return r==null?void 0:r.concat(Object.keys(e))}}async function Qa(n,e){const t=document.getElementsByTagName("head")[0];if(!t)throw new Error("loadScript");const i=document.createElement("script");return i.setAttribute("type","text/javascript"),i.setAttribute("src",n),new Promise((r,s)=>{i.onload=r,i.onerror=o=>s(new Error(`Unable to load script '${n}': ${o}`)),t.appendChild(i)})}const qm=1;let he=null,Ja=!1;const Ss={debugSpectorJS:D.get("debug-spectorjs"),debugSpectorJSUrl:"https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",gl:void 0};async function jm(n){if(!globalThis.SPECTOR)try{await Qa(n.debugSpectorJSUrl||Ss.debugSpectorJSUrl)}catch(e){D.warn(String(e))}}function Km(n){var e;if(n={...Ss,...n},!n.debugSpectorJS)return null;if(!he&&globalThis.SPECTOR&&!((e=globalThis.luma)!=null&&e.spector)){D.probe(qm,"SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();const{Spector:t}=globalThis.SPECTOR;he=new t,globalThis.luma&&(globalThis.luma.spector=he)}if(!he)return null;if(Ja||(Ja=!0,he.spyCanvases(),he==null||he.onCaptureStarted.add(t=>D.info("Spector capture started:",t)()),he==null||he.onCapture.add(t=>{D.info("Spector capture complete:",t)(),he==null||he.getResultUI(),he==null||he.resultView.display(),he==null||he.resultView.addCapture(t)})),n.gl){const t=n.gl,i=t.device;he==null||he.startCapture(n.gl,500),t.device=i,new Promise(r=>setTimeout(r,2e3)).then(r=>{D.info("Spector capture stopped after 2 seconds")(),he==null||he.stopCapture()})}return he}const Zm="https://unpkg.com/webgl-debug@2.0.1/index.js";function Ga(n){return n.luma=n.luma||{},n.luma}async function Qm(){Lt()&&!globalThis.WebGLDebugUtils&&(globalThis.global=globalThis.global||globalThis,globalThis.global.module={},await Qa(Zm))}function Jm(n,e={}){return e.debugWebGL||e.traceWebGL?eg(n,e):Gm(n)}function Gm(n){const e=Ga(n);return e.realContext?e.realContext:n}function eg(n,e){if(!globalThis.WebGLDebugUtils)return D.warn("webgl-debug not loaded")(),n;const t=Ga(n);if(t.debugContext)return t.debugContext;globalThis.WebGLDebugUtils.init({...$t,...n});const i=globalThis.WebGLDebugUtils.makeDebugContext(n,tg.bind(null,e),ng.bind(null,e));for(const o in $t)!(o in i)&&typeof $t[o]=="number"&&(i[o]=$t[o]);class r{}Object.setPrototypeOf(i,Object.getPrototypeOf(n)),Object.setPrototypeOf(r,i);const s=Object.create(r);return t.realContext=n,t.debugContext=s,s.debug=!0,s}function el(n,e){e=Array.from(e).map(i=>i===void 0?"undefined":i);let t=globalThis.WebGLDebugUtils.glFunctionArgsToString(n,e);return t=`${t.slice(0,100)}${t.length>100?"...":""}`,`gl.${n}(${t})`}function tg(n,e,t,i){i=Array.from(i).map(a=>a===void 0?"undefined":a);const r=globalThis.WebGLDebugUtils.glEnumToString(e),s=globalThis.WebGLDebugUtils.glFunctionArgsToString(t,i),o=`${r} in gl.${t}(${s})`;D.error(o)();debugger}function ng(n,e,t){let i="";D.level>=1&&(i=el(e,t),n.traceWebGL&&D.log(1,i)());for(const r of t)if(r===void 0){i=i||el(e,t);debugger}}const Li=1;class ig extends am{constructor(){super();m(this,"type","webgl");Ht.defaultProps={...Ht.defaultProps,...Ss}}enforceWebGL2(t){Xm(t)}isSupported(){return typeof WebGL2RenderingContext<"u"}isDeviceHandle(t){return typeof WebGL2RenderingContext<"u"&&t instanceof WebGL2RenderingContext?!0:(typeof WebGLRenderingContext<"u"&&t instanceof WebGLRenderingContext&&D.warn("WebGL1 is not supported",t)(),!1)}async attach(t,i={}){const{WebGLDevice:r}=await Promise.resolve().then(()=>Al);if(t instanceof r)return t;if((t==null?void 0:t.device)instanceof r)return t.device;if(!rg(t))throw new Error("Invalid WebGL2RenderingContext");const s=i.createCanvasContext===!0?{}:i.createCanvasContext;return new r({...i,_handle:t,createCanvasContext:{canvas:t.canvas,autoResize:!1,...s}})}async create(t={}){const{WebGLDevice:i}=await Promise.resolve().then(()=>Al);D.groupCollapsed(Li,"WebGLDevice created")();try{const r=[];(t.debugWebGL||t.debug)&&r.push(Qm()),t.debugSpectorJS&&r.push(jm(t));const s=await Promise.allSettled(r);for(const l of s)l.status==="rejected"&&D.error(`Failed to initialize debug libraries ${l.reason}`)();const o=new i(t),a=`${o._reused?"Reusing":"Created"} device with WebGL2 ${o.props.debug?"debug ":""}context: ${o.info.vendor}, ${o.info.renderer} for canvas: ${o.canvasContext.id}`;return D.probe(Li,a)(),D.table(Li,o.info)(),o}finally{D.groupEnd(Li)()}}}function rg(n){return typeof WebGL2RenderingContext<"u"&&n instanceof WebGL2RenderingContext?!0:!!(n&&Number.isFinite(n._version))}const sg=new ig,Ts={3042:!1,32773:new Float32Array([0,0,0,0]),32777:32774,34877:32774,32969:1,32968:0,32971:1,32970:0,3106:new Float32Array([0,0,0,0]),3107:[!0,!0,!0,!0],2884:!1,2885:1029,2929:!1,2931:1,2932:513,2928:new Float32Array([0,1]),2930:!0,3024:!0,35725:null,36006:null,36007:null,34229:null,34964:null,2886:2305,33170:4352,2849:1,32823:!1,32824:0,10752:0,32926:!1,32928:!1,32938:1,32939:!1,3089:!1,3088:new Int32Array([0,0,1024,1024]),2960:!1,2961:0,2968:4294967295,36005:4294967295,2962:519,2967:0,2963:4294967295,34816:519,36003:0,36004:4294967295,2964:7680,2965:7680,2966:7680,34817:7680,34818:7680,34819:7680,2978:[0,0,1024,1024],36389:null,36662:null,36663:null,35053:null,35055:null,35723:4352,36010:null,35977:!1,3333:4,3317:4,37440:!1,37441:!1,37443:37444,3330:0,3332:0,3331:0,3314:0,32878:0,3316:0,3315:0,32877:0},be=(n,e,t)=>e?n.enable(t):n.disable(t),tl=(n,e,t)=>n.hint(t,e),je=(n,e,t)=>n.pixelStorei(t,e),nl=(n,e,t)=>{const i=t===36006?36009:36008;return n.bindFramebuffer(i,e)},On=(n,e,t)=>{const r={34964:34962,36662:36662,36663:36663,35053:35051,35055:35052}[t];n.bindBuffer(r,e)};function ws(n){return Array.isArray(n)||ArrayBuffer.isView(n)&&!(n instanceof DataView)}const og={3042:be,32773:(n,e)=>n.blendColor(...e),32777:"blendEquation",34877:"blendEquation",32969:"blendFunc",32968:"blendFunc",32971:"blendFunc",32970:"blendFunc",3106:(n,e)=>n.clearColor(...e),3107:(n,e)=>n.colorMask(...e),2884:be,2885:(n,e)=>n.cullFace(e),2929:be,2931:(n,e)=>n.clearDepth(e),2932:(n,e)=>n.depthFunc(e),2928:(n,e)=>n.depthRange(...e),2930:(n,e)=>n.depthMask(e),3024:be,35723:tl,35725:(n,e)=>n.useProgram(e),36007:(n,e)=>n.bindRenderbuffer(36161,e),36389:(n,e)=>{var t;return(t=n.bindTransformFeedback)==null?void 0:t.call(n,36386,e)},34229:(n,e)=>n.bindVertexArray(e),36006:nl,36010:nl,34964:On,36662:On,36663:On,35053:On,35055:On,2886:(n,e)=>n.frontFace(e),33170:tl,2849:(n,e)=>n.lineWidth(e),32823:be,32824:"polygonOffset",10752:"polygonOffset",35977:be,32926:be,32928:be,32938:"sampleCoverage",32939:"sampleCoverage",3089:be,3088:(n,e)=>n.scissor(...e),2960:be,2961:(n,e)=>n.clearStencil(e),2968:(n,e)=>n.stencilMaskSeparate(1028,e),36005:(n,e)=>n.stencilMaskSeparate(1029,e),2962:"stencilFuncFront",2967:"stencilFuncFront",2963:"stencilFuncFront",34816:"stencilFuncBack",36003:"stencilFuncBack",36004:"stencilFuncBack",2964:"stencilOpFront",2965:"stencilOpFront",2966:"stencilOpFront",34817:"stencilOpBack",34818:"stencilOpBack",34819:"stencilOpBack",2978:(n,e)=>n.viewport(...e),34383:be,10754:be,12288:be,12289:be,12290:be,12291:be,12292:be,12293:be,12294:be,12295:be,3333:je,3317:je,37440:je,37441:je,37443:je,3330:je,3332:je,3331:je,3314:je,32878:je,3316:je,3315:je,32877:je,framebuffer:(n,e)=>{const t=e&&"handle"in e?e.handle:e;return n.bindFramebuffer(36160,t)},blend:(n,e)=>e?n.enable(3042):n.disable(3042),blendColor:(n,e)=>n.blendColor(...e),blendEquation:(n,e)=>{const t=typeof e=="number"?[e,e]:e;n.blendEquationSeparate(...t)},blendFunc:(n,e)=>{const t=(e==null?void 0:e.length)===2?[...e,...e]:e;n.blendFuncSeparate(...t)},clearColor:(n,e)=>n.clearColor(...e),clearDepth:(n,e)=>n.clearDepth(e),clearStencil:(n,e)=>n.clearStencil(e),colorMask:(n,e)=>n.colorMask(...e),cull:(n,e)=>e?n.enable(2884):n.disable(2884),cullFace:(n,e)=>n.cullFace(e),depthTest:(n,e)=>e?n.enable(2929):n.disable(2929),depthFunc:(n,e)=>n.depthFunc(e),depthMask:(n,e)=>n.depthMask(e),depthRange:(n,e)=>n.depthRange(...e),dither:(n,e)=>e?n.enable(3024):n.disable(3024),derivativeHint:(n,e)=>{n.hint(35723,e)},frontFace:(n,e)=>n.frontFace(e),mipmapHint:(n,e)=>n.hint(33170,e),lineWidth:(n,e)=>n.lineWidth(e),polygonOffsetFill:(n,e)=>e?n.enable(32823):n.disable(32823),polygonOffset:(n,e)=>n.polygonOffset(...e),sampleCoverage:(n,e)=>n.sampleCoverage(e[0],e[1]||!1),scissorTest:(n,e)=>e?n.enable(3089):n.disable(3089),scissor:(n,e)=>n.scissor(...e),stencilTest:(n,e)=>e?n.enable(2960):n.disable(2960),stencilMask:(n,e)=>{e=ws(e)?e:[e,e];const[t,i]=e;n.stencilMaskSeparate(1028,t),n.stencilMaskSeparate(1029,i)},stencilFunc:(n,e)=>{e=ws(e)&&e.length===3?[...e,...e]:e;const[t,i,r,s,o,a]=e;n.stencilFuncSeparate(1028,t,i,r),n.stencilFuncSeparate(1029,s,o,a)},stencilOp:(n,e)=>{e=ws(e)&&e.length===3?[...e,...e]:e;const[t,i,r,s,o,a]=e;n.stencilOpSeparate(1028,t,i,r),n.stencilOpSeparate(1029,s,o,a)},viewport:(n,e)=>n.viewport(...e)};function ye(n,e,t){return e[n]!==void 0?e[n]:t[n]}const ag={blendEquation:(n,e,t)=>n.blendEquationSeparate(ye(32777,e,t),ye(34877,e,t)),blendFunc:(n,e,t)=>n.blendFuncSeparate(ye(32969,e,t),ye(32968,e,t),ye(32971,e,t),ye(32970,e,t)),polygonOffset:(n,e,t)=>n.polygonOffset(ye(32824,e,t),ye(10752,e,t)),sampleCoverage:(n,e,t)=>n.sampleCoverage(ye(32938,e,t),ye(32939,e,t)),stencilFuncFront:(n,e,t)=>n.stencilFuncSeparate(1028,ye(2962,e,t),ye(2967,e,t),ye(2963,e,t)),stencilFuncBack:(n,e,t)=>n.stencilFuncSeparate(1029,ye(34816,e,t),ye(36003,e,t),ye(36004,e,t)),stencilOpFront:(n,e,t)=>n.stencilOpSeparate(1028,ye(2964,e,t),ye(2965,e,t),ye(2966,e,t)),stencilOpBack:(n,e,t)=>n.stencilOpSeparate(1029,ye(34817,e,t),ye(34818,e,t),ye(34819,e,t))},il={enable:(n,e)=>n({[e]:!0}),disable:(n,e)=>n({[e]:!1}),pixelStorei:(n,e,t)=>n({[e]:t}),hint:(n,e,t)=>n({[e]:t}),useProgram:(n,e)=>n({35725:e}),bindRenderbuffer:(n,e,t)=>n({36007:t}),bindTransformFeedback:(n,e,t)=>n({36389:t}),bindVertexArray:(n,e)=>n({34229:e}),bindFramebuffer:(n,e,t)=>{switch(e){case 36160:return n({36006:t,36010:t});case 36009:return n({36006:t});case 36008:return n({36010:t});default:return null}},bindBuffer:(n,e,t)=>{const i={34962:[34964],36662:[36662],36663:[36663],35051:[35053],35052:[35055]}[e];return i?n({[i]:t}):{valueChanged:!0}},blendColor:(n,e,t,i,r)=>n({32773:new Float32Array([e,t,i,r])}),blendEquation:(n,e)=>n({32777:e,34877:e}),blendEquationSeparate:(n,e,t)=>n({32777:e,34877:t}),blendFunc:(n,e,t)=>n({32969:e,32968:t,32971:e,32970:t}),blendFuncSeparate:(n,e,t,i,r)=>n({32969:e,32968:t,32971:i,32970:r}),clearColor:(n,e,t,i,r)=>n({3106:new Float32Array([e,t,i,r])}),clearDepth:(n,e)=>n({2931:e}),clearStencil:(n,e)=>n({2961:e}),colorMask:(n,e,t,i,r)=>n({3107:[e,t,i,r]}),cullFace:(n,e)=>n({2885:e}),depthFunc:(n,e)=>n({2932:e}),depthRange:(n,e,t)=>n({2928:new Float32Array([e,t])}),depthMask:(n,e)=>n({2930:e}),frontFace:(n,e)=>n({2886:e}),lineWidth:(n,e)=>n({2849:e}),polygonOffset:(n,e,t)=>n({32824:e,10752:t}),sampleCoverage:(n,e,t)=>n({32938:e,32939:t}),scissor:(n,e,t,i,r)=>n({3088:new Int32Array([e,t,i,r])}),stencilMask:(n,e)=>n({2968:e,36005:e}),stencilMaskSeparate:(n,e,t)=>n({[e===1028?2968:36005]:t}),stencilFunc:(n,e,t,i)=>n({2962:e,2967:t,2963:i,34816:e,36003:t,36004:i}),stencilFuncSeparate:(n,e,t,i,r)=>n({[e===1028?2962:34816]:t,[e===1028?2967:36003]:i,[e===1028?2963:36004]:r}),stencilOp:(n,e,t,i)=>n({2964:e,2965:t,2966:i,34817:e,34818:t,34819:i}),stencilOpSeparate:(n,e,t,i,r)=>n({[e===1028?2964:34817]:t,[e===1028?2965:34818]:i,[e===1028?2966:34819]:r}),viewport:(n,e,t,i,r)=>n({2978:[e,t,i,r]})},pt=(n,e)=>n.isEnabled(e),rl={3042:pt,2884:pt,2929:pt,3024:pt,32823:pt,32926:pt,32928:pt,3089:pt,2960:pt,35977:pt},lg=new Set([34016,36388,36387,35983,35368,34965,35739,35738,3074,34853,34854,34855,34856,34857,34858,34859,34860,34861,34862,34863,34864,34865,34866,34867,34868,35097,32873,35869,32874,34068]);function un(n,e){if(ug(e))return;const t={};for(const r in e){const s=Number(r),o=og[r];o&&(typeof o=="string"?t[o]=!0:o(n,e[r],s))}const i=n.state&&n.state.cache;if(i)for(const r in t){const s=ag[r];s(n,e,i)}}function sl(n,e=Ts){if(typeof e=="number"){const r=e,s=rl[r];return s?s(n,r):n.getParameter(r)}const t=Array.isArray(e)?e:Object.keys(e),i={};for(const r of t){const s=rl[r];i[r]=s?s(n,Number(r)):n.getParameter(Number(r))}return i}function cg(n){un(n,Ts)}function ug(n){for(const e in n)return!1;return!0}function fg(n,e){if(n===e)return!0;if(ol(n)&&ol(e)&&n.length===e.length){for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}return!1}function ol(n){return Array.isArray(n)||ArrayBuffer.isView(n)}class Xt{constructor(e,t){m(this,"gl");m(this,"program",null);m(this,"stateStack",[]);m(this,"enable",!0);m(this,"cache",null);m(this,"log");m(this,"initialized",!1);this.gl=e,this.log=(t==null?void 0:t.log)||(()=>{}),this._updateCache=this._updateCache.bind(this),Object.seal(this)}static get(e){return e.state}push(e={}){this.stateStack.push({})}pop(){const e=this.stateStack[this.stateStack.length-1];un(this.gl,e),this.stateStack.pop()}trackState(e,t){if(this.cache=t!=null&&t.copyState?sl(e):Object.assign({},Ts),this.initialized)throw new Error("WebGLStateTracker");this.initialized=!0,this.gl.state=this,dg(e);for(const i in il){const r=il[i];hg(e,i,r)}al(e,"getParameter"),al(e,"isEnabled")}_updateCache(e){let t=!1,i;const r=this.stateStack.length>0?this.stateStack[this.stateStack.length-1]:null;for(const s in e){const o=e[s],a=this.cache[s];fg(o,a)||(t=!0,i=a,r&&!(s in r)&&(r[s]=a),this.cache[s]=o)}return{valueChanged:t,oldValue:i}}}function al(n,e){const t=n[e].bind(n);n[e]=function(r){if(r===void 0||lg.has(r))return t(r);const s=Xt.get(n);return r in s.cache||(s.cache[r]=t(r)),s.enable?s.cache[r]:t(r)},Object.defineProperty(n[e],"name",{value:`${e}-from-cache`,configurable:!1})}function hg(n,e,t){if(!n[e])return;const i=n[e].bind(n);n[e]=function(...s){const o=Xt.get(n),{valueChanged:a,oldValue:l}=t(o._updateCache,...s);return a&&i(...s),l},Object.defineProperty(n[e],"name",{value:`${e}-to-cache`,configurable:!1})}function dg(n){const e=n.useProgram.bind(n);n.useProgram=function(i){const r=Xt.get(n);r.program!==i&&(e(i),r.program=i)}}function pg(n,e,t){let i="";const r={preserveDrawingBuffer:!0,...t};let s=null;if(s||(s=n.getContext("webgl2",r)),r.failIfMajorPerformanceCaveat&&(i||(i="Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.")),!s&&!t.failIfMajorPerformanceCaveat&&(r.failIfMajorPerformanceCaveat=!1,s=n.getContext("webgl2",r),s.luma||(s.luma={}),s.luma.softwareRenderer=!0),s||(s=n.getContext("webgl",{}),s&&(s=null,i||(i="Your browser only supports WebGL1"))),!s)throw i||(i="Your browser does not support WebGL"),new Error(`Failed to create WebGL context: ${i}`);const{onContextLost:o,onContextRestored:a}=e;return n.addEventListener("webglcontextlost",l=>o(l),!1),n.addEventListener("webglcontextrestored",l=>a(l),!1),s.luma||(s.luma={}),s}function fn(n,e,t){return t[e]===void 0&&(t[e]=n.getExtension(e)||null),t[e]}function mg(n,e){const t=n.getParameter(7936),i=n.getParameter(7937);fn(n,"WEBGL_debug_renderer_info",e);const r=e.WEBGL_debug_renderer_info,s=n.getParameter(r?r.UNMASKED_VENDOR_WEBGL:7936),o=n.getParameter(r?r.UNMASKED_RENDERER_WEBGL:7937),a=s||t,l=o||i,c=n.getParameter(7938),u=ll(a,l),f=gg(a,l),h=_g(a,l);return{type:"webgl",gpu:u,gpuType:h,gpuBackend:f,vendor:a,renderer:l,version:c,shadingLanguage:"glsl",shadingLanguageVersion:300}}function ll(n,e){return/NVIDIA/i.exec(n)||/NVIDIA/i.exec(e)?"nvidia":/INTEL/i.exec(n)||/INTEL/i.exec(e)?"intel":/Apple/i.exec(n)||/Apple/i.exec(e)?"apple":/AMD/i.exec(n)||/AMD/i.exec(e)||/ATI/i.exec(n)||/ATI/i.exec(e)?"amd":/SwiftShader/i.exec(n)||/SwiftShader/i.exec(e)?"software":"unknown"}function gg(n,e){return/Metal/i.exec(n)||/Metal/i.exec(e)?"metal":/ANGLE/i.exec(n)||/ANGLE/i.exec(e)?"opengl":"unknown"}function _g(n,e){if(/SwiftShader/i.exec(n)||/SwiftShader/i.exec(e))return"cpu";switch(ll(n,e)){case"intel":return"integrated";case"software":return"cpu";case"unknown":return"unknown";default:return"discrete"}}function cl(n){switch(n){case"uint8":return 5121;case"sint8":return 5120;case"unorm8":return 5121;case"snorm8":return 5120;case"uint16":return 5123;case"sint16":return 5122;case"unorm16":return 5123;case"snorm16":return 5122;case"uint32":return 5125;case"sint32":return 5124;case"float16":return 5131;case"float32":return 5126}throw new Error(String(n))}const Bn="WEBGL_compressed_texture_s3tc",Un="WEBGL_compressed_texture_s3tc_srgb",hn="EXT_texture_compression_rgtc",dn="EXT_texture_compression_bptc",xg="WEBGL_compressed_texture_etc",yg="WEBGL_compressed_texture_astc",vg="WEBGL_compressed_texture_etc1",bg="WEBGL_compressed_texture_pvrtc",Sg="WEBGL_compressed_texture_atc",ul="EXT_texture_norm16",fl="EXT_render_snorm",Tg="EXT_color_buffer_float",As={"float32-renderable-webgl":["EXT_color_buffer_float"],"float16-renderable-webgl":["EXT_color_buffer_half_float"],"rgb9e5ufloat-renderable-webgl":["WEBGL_render_shared_exponent"],"snorm8-renderable-webgl":[fl],"norm16-renderable-webgl":[ul],"snorm16-renderable-webgl":[ul,fl],"float32-filterable":["OES_texture_float_linear"],"float16-filterable-webgl":["OES_texture_half_float_linear"],"texture-filterable-anisotropic-webgl":["EXT_texture_filter_anisotropic"],"texture-blend-float-webgl":["EXT_float_blend"],"texture-compression-bc":[Bn,Un,hn,dn],"texture-compression-bc5-webgl":[hn],"texture-compression-bc7-webgl":[dn],"texture-compression-etc2":[xg],"texture-compression-astc":[yg],"texture-compression-etc1-webgl":[vg],"texture-compression-pvrtc-webgl":[bg],"texture-compression-atc-webgl":[Sg]};function wg(n){return n in As}function Ag(n,e,t){return(As[e]||[]).every(r=>fn(n,r,t))}const Cs={r8unorm:{gl:33321,rb:!0},r8snorm:{gl:36756},r8uint:{gl:33330,rb:!0},r8sint:{gl:33329,rb:!0},rg8unorm:{gl:33323,rb:!0},rg8snorm:{gl:36757},rg8uint:{gl:33336,rb:!0},rg8sint:{gl:33335,rb:!0},r16uint:{gl:33332,rb:!0},r16sint:{gl:33331,rb:!0},r16float:{gl:33325,rb:!0},r16unorm:{gl:33322,rb:!0},r16snorm:{gl:36760},"rgba4unorm-webgl":{gl:32854,rb:!0},"rgb565unorm-webgl":{gl:36194,rb:!0},"rgb5a1unorm-webgl":{gl:32855,rb:!0},"rgb8unorm-webgl":{gl:32849},"rgb8snorm-webgl":{gl:36758},rgba8unorm:{gl:32856},"rgba8unorm-srgb":{gl:35907},rgba8snorm:{gl:36759},rgba8uint:{gl:36220},rgba8sint:{gl:36238},bgra8unorm:{},"bgra8unorm-srgb":{},rg16uint:{gl:33338},rg16sint:{gl:33337},rg16float:{gl:33327,rb:!0},rg16unorm:{gl:33324},rg16snorm:{gl:36761},r32uint:{gl:33334,rb:!0},r32sint:{gl:33333,rb:!0},r32float:{gl:33326},rgb9e5ufloat:{gl:35901},rg11b10ufloat:{gl:35898,rb:!0},rgb10a2unorm:{gl:32857,rb:!0},rgb10a2uint:{gl:36975,rb:!0},"rgb16unorm-webgl":{gl:32852},"rgb16snorm-webgl":{gl:36762},rg32uint:{gl:33340,rb:!0},rg32sint:{gl:33339,rb:!0},rg32float:{gl:33328,rb:!0},rgba16uint:{gl:36214,rb:!0},rgba16sint:{gl:36232,rb:!0},rgba16float:{gl:34842},rgba16unorm:{gl:32859,rb:!0},rgba16snorm:{gl:36763},"rgb32float-webgl":{gl:34837,x:Tg,dataFormat:6407,types:[5126]},rgba32uint:{gl:36208,rb:!0},rgba32sint:{gl:36226,rb:!0},rgba32float:{gl:34836,rb:!0},stencil8:{gl:36168,rb:!0},depth16unorm:{gl:33189,dataFormat:6402,types:[5123],rb:!0},depth24plus:{gl:33190,dataFormat:6402,types:[5125]},depth32float:{gl:36012,dataFormat:6402,types:[5126],rb:!0},"depth24plus-stencil8":{gl:35056,rb:!0,depthTexture:!0,dataFormat:34041,types:[34042]},"depth32float-stencil8":{gl:36013,dataFormat:34041,types:[36269],rb:!0},"bc1-rgb-unorm-webgl":{gl:33776,x:Bn},"bc1-rgb-unorm-srgb-webgl":{gl:35916,x:Un},"bc1-rgba-unorm":{gl:33777,x:Bn},"bc1-rgba-unorm-srgb":{gl:35916,x:Un},"bc2-rgba-unorm":{gl:33778,x:Bn},"bc2-rgba-unorm-srgb":{gl:35918,x:Un},"bc3-rgba-unorm":{gl:33779,x:Bn},"bc3-rgba-unorm-srgb":{gl:35919,x:Un},"bc4-r-unorm":{gl:36283,x:hn},"bc4-r-snorm":{gl:36284,x:hn},"bc5-rg-unorm":{gl:36285,x:hn},"bc5-rg-snorm":{gl:36286,x:hn},"bc6h-rgb-ufloat":{gl:36495,x:dn},"bc6h-rgb-float":{gl:36494,x:dn},"bc7-rgba-unorm":{gl:36492,x:dn},"bc7-rgba-unorm-srgb":{gl:36493,x:dn},"etc2-rgb8unorm":{gl:37492},"etc2-rgb8unorm-srgb":{gl:37494},"etc2-rgb8a1unorm":{gl:37496},"etc2-rgb8a1unorm-srgb":{gl:37497},"etc2-rgba8unorm":{gl:37493},"etc2-rgba8unorm-srgb":{gl:37495},"eac-r11unorm":{gl:37488},"eac-r11snorm":{gl:37489},"eac-rg11unorm":{gl:37490},"eac-rg11snorm":{gl:37491},"astc-4x4-unorm":{gl:37808},"astc-4x4-unorm-srgb":{gl:37840},"astc-5x4-unorm":{gl:37809},"astc-5x4-unorm-srgb":{gl:37841},"astc-5x5-unorm":{gl:37810},"astc-5x5-unorm-srgb":{gl:37842},"astc-6x5-unorm":{gl:37811},"astc-6x5-unorm-srgb":{gl:37843},"astc-6x6-unorm":{gl:37812},"astc-6x6-unorm-srgb":{gl:37844},"astc-8x5-unorm":{gl:37813},"astc-8x5-unorm-srgb":{gl:37845},"astc-8x6-unorm":{gl:37814},"astc-8x6-unorm-srgb":{gl:37846},"astc-8x8-unorm":{gl:37815},"astc-8x8-unorm-srgb":{gl:37847},"astc-10x5-unorm":{gl:37819},"astc-10x5-unorm-srgb":{gl:37851},"astc-10x6-unorm":{gl:37817},"astc-10x6-unorm-srgb":{gl:37849},"astc-10x8-unorm":{gl:37818},"astc-10x8-unorm-srgb":{gl:37850},"astc-10x10-unorm":{gl:37819},"astc-10x10-unorm-srgb":{gl:37851},"astc-12x10-unorm":{gl:37820},"astc-12x10-unorm-srgb":{gl:37852},"astc-12x12-unorm":{gl:37821},"astc-12x12-unorm-srgb":{gl:37853},"pvrtc-rgb4unorm-webgl":{gl:35840},"pvrtc-rgba4unorm-webgl":{gl:35842},"pvrtc-rbg2unorm-webgl":{gl:35841},"pvrtc-rgba2unorm-webgl":{gl:35843},"etc1-rbg-unorm-webgl":{gl:36196},"atc-rgb-unorm-webgl":{gl:35986},"atc-rgba-unorm-webgl":{gl:35986},"atc-rgbai-unorm-webgl":{gl:34798}};function Cg(n,e,t){let i=e.create;const r=Cs[e.format];return(r==null?void 0:r.gl)===void 0&&(i=!1),r!=null&&r.x&&(i=i&&!!fn(n,r.x,t)),{format:e.format,create:i&&e.create,render:i&&e.render,filter:i&&e.filter,blend:i&&e.blend,store:i&&e.store}}function hl(n){var r;const e=Cs[n],t=Eg(n),i=Vt.getInfo(n);return i.compressed&&(e.dataFormat=t),{internalFormat:t,format:(e==null?void 0:e.dataFormat)||Pg(i.channels,i.integer,i.normalized,t),type:i.dataType?cl(i.dataType):((r=e==null?void 0:e.types)==null?void 0:r[0])||5121,compressed:i.compressed||!1}}function Ig(n){switch(Vt.getInfo(n).attachment){case"depth":return 36096;case"stencil":return 36128;case"depth-stencil":return 33306;default:throw new Error(`Not a depth stencil format: ${n}`)}}function Pg(n,e,t,i){if(i===6408||i===6407)return i;switch(n){case"r":return e&&!t?36244:6403;case"rg":return e&&!t?33320:33319;case"rgb":return e&&!t?36248:6407;case"rgba":return e&&!t?36249:6408;case"bgra":throw new Error("bgra pixels not supported by WebGL");default:return 6408}}function Eg(n){const e=Cs[n],t=e==null?void 0:e.gl;if(t===void 0)throw new Error(`Unsupported texture format ${n}`);return t}const dl={"depth-clip-control":"EXT_depth_clamp","timer-query-webgl":"EXT_disjoint_timer_query_webgl2","compilation-status-async-webgl":"KHR_parallel_shader_compile","polygon-mode-webgl":"WEBGL_polygon_mode","provoking-vertex-webgl":"WEBGL_provoking_vertex","shader-clip-cull-distance-webgl":"WEBGL_clip_cull_distance","shader-noperspective-interpolation-webgl":"NV_shader_noperspective_interpolation","shader-conservative-depth-webgl":"EXT_conservative_depth"};class Rg extends rm{constructor(t,i,r){super([],r);m(this,"gl");m(this,"extensions");m(this,"testedFeatures",new Set);this.gl=t,this.extensions=i,fn(t,"EXT_color_buffer_float",i)}*[Symbol.iterator](){const t=this.getFeatures();for(const i of t)this.has(i)&&(yield i);return[]}has(t){var i;return(i=this.disabledFeatures)!=null&&i[t]?!1:(this.testedFeatures.has(t)||(this.testedFeatures.add(t),wg(t)&&Ag(this.gl,t,this.extensions)&&this.features.add(t),this.getWebGLFeature(t)&&this.features.add(t)),this.features.has(t))}initializeFeatures(){const t=this.getFeatures().filter(i=>i!=="polygon-mode-webgl");for(const i of t)this.has(i)}getFeatures(){return[...Object.keys(dl),...Object.keys(As)]}getWebGLFeature(t){const i=dl[t];return typeof i=="string"?!!fn(this.gl,i,this.extensions):!!i}}class kg extends im{constructor(t){super();m(this,"gl");m(this,"limits",{});this.gl=t}get maxTextureDimension1D(){return 0}get maxTextureDimension2D(){return this.getParameter(3379)}get maxTextureDimension3D(){return this.getParameter(32883)}get maxTextureArrayLayers(){return this.getParameter(35071)}get maxBindGroups(){return 0}get maxDynamicUniformBuffersPerPipelineLayout(){return 0}get maxDynamicStorageBuffersPerPipelineLayout(){return 0}get maxSampledTexturesPerShaderStage(){return this.getParameter(35660)}get maxSamplersPerShaderStage(){return this.getParameter(35661)}get maxStorageBuffersPerShaderStage(){return 0}get maxStorageTexturesPerShaderStage(){return 0}get maxUniformBuffersPerShaderStage(){return this.getParameter(35375)}get maxUniformBufferBindingSize(){return this.getParameter(35376)}get maxStorageBufferBindingSize(){return 0}get minUniformBufferOffsetAlignment(){return this.getParameter(35380)}get minStorageBufferOffsetAlignment(){return 0}get maxVertexBuffers(){return 16}get maxVertexAttributes(){return this.getParameter(34921)}get maxVertexBufferArrayStride(){return 2048}get maxInterStageShaderVariables(){return this.getParameter(35659)}get maxComputeWorkgroupStorageSize(){return 0}get maxComputeInvocationsPerWorkgroup(){return 0}get maxComputeWorkgroupSizeX(){return 0}get maxComputeWorkgroupSizeY(){return 0}get maxComputeWorkgroupSizeZ(){return 0}get maxComputeWorkgroupsPerDimension(){return 0}getParameter(t){return this.limits[t]===void 0&&(this.limits[t]=this.gl.getParameter(t)),this.limits[t]||0}}class zn extends Oi{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"colorAttachments",[]);m(this,"depthStencilAttachment",null);const r=i.handle===null;this.device=t,this.gl=t.gl,this.handle=this.props.handle||r?this.props.handle:this.gl.createFramebuffer(),r||(t._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.autoCreateAttachmentTextures(),this.updateAttachments())}destroy(){super.destroy(),!this.destroyed&&this.handle!==null&&this.gl.deleteFramebuffer(this.handle)}updateAttachments(){const t=this.gl.bindFramebuffer(36160,this.handle);for(let i=0;i<this.colorAttachments.length;++i){const r=this.colorAttachments[i];if(r){const s=36064+i;this._attachTextureView(s,r)}}if(this.depthStencilAttachment){const i=Ig(this.depthStencilAttachment.props.format);this._attachTextureView(i,this.depthStencilAttachment)}if(this.device.props.debug){const i=this.gl.checkFramebufferStatus(36160);if(i!==36053)throw new Error(`Framebuffer ${Mg(i)}`)}this.gl.bindFramebuffer(36160,t)}_attachTextureView(t,i){const{gl:r}=this.device,{texture:s}=i,o=i.props.baseMipLevel,a=i.props.baseArrayLayer;switch(r.bindTexture(s.glTarget,s.handle),s.glTarget){case 35866:case 32879:r.framebufferTextureLayer(36160,t,s.handle,o,a);break;case 34067:const l=Dg(a);r.framebufferTexture2D(36160,t,l,s.handle,o);break;case 3553:r.framebufferTexture2D(36160,t,3553,s.handle,o);break;default:throw new Error("Illegal texture type")}r.bindTexture(s.glTarget,null)}}function Dg(n){return n<34069?n+34069:n}function Mg(n){switch(n){case 36053:return"success";case 36054:return"Mismatched attachments";case 36055:return"No attachments";case 36057:return"Height/width mismatch";case 36061:return"Unsupported or split attachments";case 36182:return"Samples mismatch";default:return`${n}`}}class Fg extends Mi{constructor(t,i){super(i);m(this,"device");m(this,"handle",null);m(this,"_framebuffer",null);this.device=t,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._updateDevice()}get[Symbol.toStringTag](){return"WebGLCanvasContext"}getCurrentFramebuffer(){return this._framebuffer=this._framebuffer||new zn(this.device,{handle:null}),this._framebuffer}_updateDevice(){}}const Is={};function Ng(n="id"){Is[n]=Is[n]||1;const e=Is[n]++;return`${n}-${e}`}class Ln extends L{constructor(t,i={}){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"glTarget");m(this,"glUsage");m(this,"glIndexType",5123);m(this,"byteLength",0);m(this,"bytesUsed",0);this.device=t,this.gl=this.device.gl;const r=typeof i=="object"?i.handle:void 0;this.handle=r||this.gl.createBuffer(),t._setWebGLDebugMetadata(this.handle,this,{spector:{...this.props,data:typeof this.props.data}}),this.glTarget=Og(this.props.usage),this.glUsage=Bg(this.props.usage),this.glIndexType=this.props.indexType==="uint32"?5125:5123,i.data?this._initWithData(i.data,i.byteOffset,i.byteLength):this._initWithByteLength(i.byteLength||0)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.trackDeallocatedMemory(),this.gl.deleteBuffer(this.handle),this.destroyed=!0,this.handle=null)}_initWithData(t,i=0,r=t.byteLength+i){const s=this.glTarget;this.gl.bindBuffer(s,this.handle),this.gl.bufferData(s,r,this.glUsage),this.gl.bufferSubData(s,i,t),this.gl.bindBuffer(s,null),this.bytesUsed=r,this.byteLength=r,this._setDebugData(t,i,r),this.trackAllocatedMemory(r)}_initWithByteLength(t){let i=t;t===0&&(i=new Float32Array(0));const r=this.glTarget;return this.gl.bindBuffer(r,this.handle),this.gl.bufferData(r,i,this.glUsage),this.gl.bindBuffer(r,null),this.bytesUsed=t,this.byteLength=t,this._setDebugData(null,0,t),this.trackAllocatedMemory(t),this}write(t,i=0){const r=ArrayBuffer.isView(t)?t:new Uint8Array(t),s=36663;this.gl.bindBuffer(s,this.handle),this.gl.bufferSubData(s,i,r),this.gl.bindBuffer(s,null),this._setDebugData(t,i,t.byteLength)}async mapAndWriteAsync(t,i=0,r=this.byteLength-i){const s=new ArrayBuffer(r);await t(s,"copied"),this.write(s,i)}async readAsync(t=0,i){return this.readSyncWebGL(t,i)}async mapAndReadAsync(t,i=0,r){const s=await this.readAsync(i,r);return await t(s.buffer,"copied")}readSyncWebGL(t=0,i){i=i??this.byteLength-t;const r=new Uint8Array(i),s=0;return this.gl.bindBuffer(36662,this.handle),this.gl.getBufferSubData(36662,t,r,s,i),this.gl.bindBuffer(36662,null),this._setDebugData(r,t,i),r}}function Og(n){return n&L.INDEX?34963:n&L.VERTEX?34962:n&L.UNIFORM?35345:34962}function Bg(n){return n&L.INDEX||n&L.VERTEX?35044:n&L.UNIFORM?35048:35044}function Ug(n){const e=n.split(/\r?\n/),t=[];for(const i of e){if(i.length<=1)continue;const r=i.split(":");if(r.length===2){const[f,h]=r;t.push({message:h.trim(),type:pl(f),lineNum:0,linePos:0});continue}const[s,o,a,...l]=r;let c=parseInt(a,10);isNaN(c)&&(c=0);let u=parseInt(o,10);isNaN(u)&&(u=0),t.push({message:l.join(":").trim(),type:pl(s),lineNum:c,linePos:u})}return t}function pl(n){const e=["warning","error","info"],t=n.toLowerCase();return e.includes(t)?t:"info"}class zg extends Ni{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");switch(this.device=t,this.props.stage){case"vertex":this.handle=this.props.handle||this.device.gl.createShader(35633);break;case"fragment":this.handle=this.props.handle||this.device.gl.createShader(35632);break;default:throw new Error(this.props.stage)}t._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this._compile(this.source)}destroy(){this.handle&&(this.removeStats(),this.device.gl.deleteShader(this.handle),this.destroyed=!0,this.handle.destroyed=!0)}get asyncCompilationStatus(){return this._waitForCompilationComplete().then(()=>(this._getCompilationStatus(),this.compilationStatus))}async getCompilationInfo(){return await this._waitForCompilationComplete(),this.getCompilationInfoSync()}getCompilationInfoSync(){const t=this.device.gl.getShaderInfoLog(this.handle);return t?Ug(t):[]}getTranslatedSource(){const i=this.device.getExtension("WEBGL_debug_shaders").WEBGL_debug_shaders;return(i==null?void 0:i.getTranslatedShaderSource(this.handle))||null}async _compile(t){t=t.startsWith("#version ")?t:`#version 300 es
12
- ${t}`;const{gl:i}=this.device;if(i.shaderSource(this.handle,t),i.compileShader(this.handle),!this.device.props.debug){this.compilationStatus="pending";return}if(!this.device.features.has("compilation-status-async-webgl")){if(this._getCompilationStatus(),this.debugShader(),this.compilationStatus==="error")throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);return}D.once(1,"Shader compilation is asynchronous")(),await this._waitForCompilationComplete(),D.info(2,`Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)(),this._getCompilationStatus(),this.debugShader()}async _waitForCompilationComplete(){const t=async s=>await new Promise(o=>setTimeout(o,s));if(!this.device.features.has("compilation-status-async-webgl")){await t(10);return}const{gl:r}=this.device;for(;;){if(r.getShaderParameter(this.handle,37297))return;await t(10)}}_getCompilationStatus(){this.compilationStatus=this.device.gl.getShaderParameter(this.handle,35713)?"success":"error"}}function Lg(n,e,t,i){if($g(e))return i(n);const r=n;r.pushState();try{return Vg(n,e),un(r.gl,t),i(n)}finally{r.popState()}}function Vg(n,e){const t=n,{gl:i}=t;if(e.cullMode)switch(e.cullMode){case"none":i.disable(2884);break;case"front":i.enable(2884),i.cullFace(1028);break;case"back":i.enable(2884),i.cullFace(1029);break}if(e.frontFace&&i.frontFace(Yt("frontFace",e.frontFace,{ccw:2305,cw:2304})),e.unclippedDepth&&n.features.has("depth-clip-control")&&i.enable(34383),e.depthBias!==void 0&&(i.enable(32823),i.polygonOffset(e.depthBias,e.depthBiasSlopeScale||0)),e.provokingVertex&&n.features.has("provoking-vertex-webgl")){const s=t.getExtension("WEBGL_provoking_vertex").WEBGL_provoking_vertex,o=Yt("provokingVertex",e.provokingVertex,{first:36429,last:36430});s==null||s.provokingVertexWEBGL(o)}if((e.polygonMode||e.polygonOffsetLine)&&n.features.has("polygon-mode-webgl")){if(e.polygonMode){const s=t.getExtension("WEBGL_polygon_mode").WEBGL_polygon_mode,o=Yt("polygonMode",e.polygonMode,{fill:6914,line:6913});s==null||s.polygonModeWEBGL(1028,o),s==null||s.polygonModeWEBGL(1029,o)}e.polygonOffsetLine&&i.enable(10754)}if(n.features.has("shader-clip-cull-distance-webgl")&&(e.clipDistance0&&i.enable(12288),e.clipDistance1&&i.enable(12289),e.clipDistance2&&i.enable(12290),e.clipDistance3&&i.enable(12291),e.clipDistance4&&i.enable(12292),e.clipDistance5&&i.enable(12293),e.clipDistance6&&i.enable(12294),e.clipDistance7&&i.enable(12295)),e.depthWriteEnabled!==void 0&&i.depthMask(Wg("depthWriteEnabled",e.depthWriteEnabled)),e.depthCompare&&(e.depthCompare!=="always"?i.enable(2929):i.disable(2929),i.depthFunc(Ps("depthCompare",e.depthCompare))),e.stencilWriteMask){const r=e.stencilWriteMask;i.stencilMaskSeparate(1028,r),i.stencilMaskSeparate(1029,r)}if(e.stencilReadMask&&D.warn("stencilReadMask not supported under WebGL"),e.stencilCompare){const r=e.stencilReadMask||4294967295,s=Ps("depthCompare",e.stencilCompare);e.stencilCompare!=="always"?i.enable(2960):i.disable(2960),i.stencilFuncSeparate(1028,s,0,r),i.stencilFuncSeparate(1029,s,0,r)}if(e.stencilPassOperation&&e.stencilFailOperation&&e.stencilDepthFailOperation){const r=Es("stencilPassOperation",e.stencilPassOperation),s=Es("stencilFailOperation",e.stencilFailOperation),o=Es("stencilDepthFailOperation",e.stencilDepthFailOperation);i.stencilOpSeparate(1028,s,o,r),i.stencilOpSeparate(1029,s,o,r)}switch(e.blend){case!0:i.enable(3042);break;case!1:i.disable(3042);break}if(e.blendColorOperation||e.blendAlphaOperation){const r=ml("blendColorOperation",e.blendColorOperation||"add"),s=ml("blendAlphaOperation",e.blendAlphaOperation||"add");i.blendEquationSeparate(r,s);const o=Vi("blendColorSrcFactor",e.blendColorSrcFactor||"one"),a=Vi("blendColorDstFactor",e.blendColorDstFactor||"zero"),l=Vi("blendAlphaSrcFactor",e.blendAlphaSrcFactor||"one"),c=Vi("blendAlphaDstFactor",e.blendAlphaDstFactor||"zero");i.blendFuncSeparate(o,a,l,c)}}function Ps(n,e){return Yt(n,e,{never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519})}function Es(n,e){return Yt(n,e,{keep:7680,zero:0,replace:7681,invert:5386,"increment-clamp":7682,"decrement-clamp":7683,"increment-wrap":34055,"decrement-wrap":34056})}function ml(n,e){return Yt(n,e,{add:32774,subtract:32778,"reverse-subtract":32779,min:32775,max:32776})}function Vi(n,e,t="color"){return Yt(n,e,{one:1,zero:0,src:768,"one-minus-src":769,dst:774,"one-minus-dst":775,"src-alpha":770,"one-minus-src-alpha":771,"dst-alpha":772,"one-minus-dst-alpha":773,"src-alpha-saturated":776,constant:t==="color"?32769:32771,"one-minus-constant":t==="color"?32770:32772,src1:768,"one-minus-src1":769,"src1-alpha":770,"one-minus-src1-alpha":771})}function Hg(n,e){return`Illegal parameter ${e} for ${n}`}function Yt(n,e,t){if(!(e in t))throw new Error(Hg(n,e));return t[e]}function Wg(n,e){return e}function $g(n){let e=!0;for(const t in n){e=!1;break}return e}function gl(n){const e={};return n.addressModeU&&(e[10242]=Rs(n.addressModeU)),n.addressModeV&&(e[10243]=Rs(n.addressModeV)),n.addressModeW&&(e[32882]=Rs(n.addressModeW)),n.magFilter&&(e[10240]=ks(n.magFilter)),(n.minFilter||n.mipmapFilter)&&(e[10241]=Xg(n.minFilter||"linear",n.mipmapFilter)),n.lodMinClamp!==void 0&&(e[33082]=n.lodMinClamp),n.lodMaxClamp!==void 0&&(e[33083]=n.lodMaxClamp),n.type==="comparison-sampler"&&(e[34892]=34894),n.compare&&(e[34893]=Ps("compare",n.compare)),n.maxAnisotropy&&(e[34046]=n.maxAnisotropy),e}function Rs(n){switch(n){case"clamp-to-edge":return 33071;case"repeat":return 10497;case"mirror-repeat":return 33648}}function ks(n){switch(n){case"nearest":return 9728;case"linear":return 9729}}function Xg(n,e="none"){if(!e)return ks(n);switch(e){case"none":return ks(n);case"nearest":switch(n){case"nearest":return 9984;case"linear":return 9985}break;case"linear":switch(n){case"nearest":return 9986;case"linear":return 9987}}}class Yg extends cn{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"parameters");this.device=t,this.parameters=gl(i),this.handle=i.handle||this.device.gl.createSampler(),this._setSamplerParameters(this.parameters)}destroy(){this.handle&&(this.device.gl.deleteSampler(this.handle),this.handle=void 0)}toString(){return`Sampler(${this.id},${JSON.stringify(this.props)})`}_setSamplerParameters(t){for(const[i,r]of Object.entries(t)){const s=Number(i);switch(s){case 33082:case 33083:this.device.gl.samplerParameterf(this.handle,s,r);break;default:this.device.gl.samplerParameteri(this.handle,s,r);break}}}}function Vn(n,e,t){if(qg(e))return t(n);const{nocatch:i=!0}=e,r=Xt.get(n);r.push(),un(n,e);let s;if(i)s=t(n),r.pop();else try{s=t(n)}finally{r.pop()}return s}function qg(n){for(const e in n)return!1;return!0}class pn extends Fi{constructor(t,i){super(t,{...Q.defaultProps,...i});m(this,"device");m(this,"gl");m(this,"handle");m(this,"texture");this.device=t,this.gl=this.device.gl,this.handle=null,this.texture=i.texture}}class Hn extends Q{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"sampler");m(this,"view");m(this,"glTarget");m(this,"glFormat");m(this,"glType");m(this,"glInternalFormat");m(this,"compressed");m(this,"_textureUnit",0);this.device=t,this.gl=this.device.gl;const r=hl(this.props.format);this.glTarget=jg(this.props.dimension),this.glInternalFormat=r.internalFormat,this.glFormat=r.format,this.glType=r.type,this.compressed=r.compressed,this.handle=this.props.handle||this.gl.createTexture(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.gl.bindTexture(this.glTarget,this.handle);const{dimension:s,width:o,height:a,depth:l,mipLevels:c,glTarget:u,glInternalFormat:f}=this;switch(s){case"2d":case"cube":this.gl.texStorage2D(u,c,f,o,a);break;case"2d-array":case"3d":this.gl.texStorage3D(u,c,f,o,a,l);break;default:throw new Error(s)}this.gl.bindTexture(this.glTarget,null),this._initializeData(i.data),this.setSampler(this.props.sampler),this.view=new pn(this.device,{...this.props,texture:this}),Object.seal(this)}destroy(){this.handle&&(this.gl.deleteTexture(this.handle),this.removeStats(),this.trackDeallocatedMemory("Texture"),this.destroyed=!0)}createView(t){return new pn(this.device,{...t,texture:this})}setSampler(t={}){super.setSampler(t);const i=gl(this.sampler.props);this._setSamplerParameters(i)}copyImageData(t){const i=this._normalizeCopyImageDataOptions(t),r=i.data,{width:s,height:o,depth:a}=this,{mipLevel:l=0,byteOffset:c=0,x:u=0,y:f=0,z:h=0}=i,{glFormat:d,glType:_,compressed:I}=this,P=_l(this.glTarget,this.dimension,h);let A;if(!this.compressed){const{bytesPerPixel:E}=this.device.getTextureFormatInfo(this.format);if(E){if(i.bytesPerRow%E!==0)throw new Error(`bytesPerRow (${i.bytesPerRow}) must be a multiple of bytesPerPixel (${E}) for ${this.format}`);A=i.bytesPerRow/E}}const O=this.compressed?{}:{...A!==void 0?{3314:A}:{},32878:i.rowsPerImage};this.gl.bindTexture(P,this.handle),Vn(this.gl,O,()=>{switch(this.dimension){case"2d":case"cube":I?this.gl.compressedTexSubImage2D(P,l,u,f,s,o,d,r,c):this.gl.texSubImage2D(P,l,u,f,s,o,d,_,r,c);break;case"2d-array":case"3d":I?this.gl.compressedTexSubImage3D(P,l,u,f,h,s,o,a,d,r,c):this.gl.texSubImage3D(P,l,u,f,h,s,o,a,d,_,r,c);break;default:}}),this.gl.bindTexture(P,null)}copyExternalImage(t){const i=this._normalizeCopyExternalImageOptions(t);if(i.sourceX||i.sourceY)throw new Error("WebGL does not support sourceX/sourceY)");const{glFormat:r,glType:s}=this,{image:o,depth:a,mipLevel:l,x:c,y:u,z:f,width:h,height:d}=i,_=_l(this.glTarget,this.dimension,a),I=i.flipY?{37440:!0}:{};return this.gl.bindTexture(this.glTarget,this.handle),Vn(this.gl,I,()=>{switch(this.dimension){case"2d":case"cube":this.gl.texSubImage2D(_,l,c,u,h,d,r,s,o);break;case"2d-array":case"3d":this.gl.texSubImage3D(_,l,c,u,f,h,d,a,r,s,o);break;default:}}),this.gl.bindTexture(this.glTarget,null),{width:i.width,height:i.height}}generateMipmapsWebGL(t){if(!(!(this.device.isTextureFormatRenderable(this.props.format)&&this.device.isTextureFormatFilterable(this.props.format))&&(D.warn(`${this} is not renderable or filterable, may not be able to generate mipmaps`)(),!(t!=null&&t.force))))try{this.gl.bindTexture(this.glTarget,this.handle),this.gl.generateMipmap(this.glTarget)}catch(r){D.warn(`Error generating mipmap for ${this}: ${r.message}`)()}finally{this.gl.bindTexture(this.glTarget,null)}}_setSamplerParameters(t){D.log(2,`${this.id} sampler parameters`,this.device.getGLKeys(t))(),this.gl.bindTexture(this.glTarget,this.handle);for(const[i,r]of Object.entries(t)){const s=Number(i),o=r;switch(s){case 33082:case 33083:this.gl.texParameterf(this.glTarget,s,o);break;case 10240:case 10241:this.gl.texParameteri(this.glTarget,s,o);break;case 10242:case 10243:case 32882:this.gl.texParameteri(this.glTarget,s,o);break;case 34046:this.device.features.has("texture-filterable-anisotropic-webgl")&&this.gl.texParameteri(this.glTarget,s,o);break;case 34892:case 34893:this.gl.texParameteri(this.glTarget,s,o);break}}this.gl.bindTexture(this.glTarget,null)}_getActiveUnit(){return this.gl.getParameter(34016)-33984}_bind(t){const{gl:i}=this;return t!==void 0&&(this._textureUnit=t,i.activeTexture(33984+t)),i.bindTexture(this.glTarget,this.handle),t}_unbind(t){const{gl:i}=this;return t!==void 0&&(this._textureUnit=t,i.activeTexture(33984+t)),i.bindTexture(this.glTarget,null),t}}function jg(n){switch(n){case"1d":break;case"2d":return 3553;case"3d":return 32879;case"cube":return 34067;case"2d-array":return 35866}throw new Error(n)}function _l(n,e,t){return e==="cube"?34069+t:n}function Kg(n){return Gg[n]}function Ds(n){return Jg[n]}function Zg(n){return!!xl[n]}function Qg(n){return xl[n]}const Jg={5126:"f32",35664:"vec2<f32>",35665:"vec3<f32>",35666:"vec4<f32>",5124:"i32",35667:"vec2<i32>",35668:"vec3<i32>",35669:"vec4<i32>",5125:"u32",36294:"vec2<u32>",36295:"vec3<u32>",36296:"vec4<u32>",35670:"f32",35671:"vec2<f32>",35672:"vec3<f32>",35673:"vec4<f32>",35674:"mat2x2<f32>",35685:"mat2x3<f32>",35686:"mat2x4<f32>",35687:"mat3x2<f32>",35675:"mat3x3<f32>",35688:"mat3x4<f32>",35689:"mat4x2<f32>",35690:"mat4x3<f32>",35676:"mat4x4<f32>"},xl={35678:{viewDimension:"2d",sampleType:"float"},35680:{viewDimension:"cube",sampleType:"float"},35679:{viewDimension:"3d",sampleType:"float"},35682:{viewDimension:"3d",sampleType:"depth"},36289:{viewDimension:"2d-array",sampleType:"float"},36292:{viewDimension:"2d-array",sampleType:"depth"},36293:{viewDimension:"cube",sampleType:"float"},36298:{viewDimension:"2d",sampleType:"sint"},36299:{viewDimension:"3d",sampleType:"sint"},36300:{viewDimension:"cube",sampleType:"sint"},36303:{viewDimension:"2d-array",sampleType:"uint"},36306:{viewDimension:"2d",sampleType:"uint"},36307:{viewDimension:"3d",sampleType:"uint"},36308:{viewDimension:"cube",sampleType:"uint"},36311:{viewDimension:"2d-array",sampleType:"uint"}},Gg={uint8:5121,sint8:5120,unorm8:5121,snorm8:5120,uint16:5123,sint16:5122,unorm16:5123,snorm16:5122,uint32:5125,sint32:5124,float16:5131,float32:5126};function e_(n,e){const t={attributes:[],bindings:[]};t.attributes=t_(n,e);const i=r_(n,e);for(const a of i){const l=a.uniforms.map(c=>({name:c.name,format:c.format,byteOffset:c.byteOffset,byteStride:c.byteStride,arrayLength:c.arrayLength}));t.bindings.push({type:"uniform",name:a.name,group:0,location:a.location,visibility:(a.vertex?1:0)&(a.fragment?2:0),minBindingSize:a.byteLength,uniforms:l})}const r=i_(n,e);let s=0;for(const a of r)if(Zg(a.type)){const{viewDimension:l,sampleType:c}=Qg(a.type);t.bindings.push({type:"texture",name:a.name,group:0,location:s,viewDimension:l,sampleType:c}),a.textureUnit=s,s+=1}r.length&&(t.uniforms=r);const o=n_(n,e);return o!=null&&o.length&&(t.varyings=o),t}function t_(n,e){const t=[],i=n.getProgramParameter(e,35721);for(let r=0;r<i;r++){const s=n.getActiveAttrib(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a}=s,l=n.getAttribLocation(e,o);if(l>=0){const c=Ds(a),u=/instance/i.test(o)?"instance":"vertex";t.push({name:o,location:l,stepMode:u,type:c})}}return t.sort((r,s)=>r.location-s.location),t}function n_(n,e){const t=[],i=n.getProgramParameter(e,35971);for(let r=0;r<i;r++){const s=n.getTransformFeedbackVarying(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a,size:l}=s,c=Ds(a),{type:u,components:f}=ja(c);t.push({location:r,name:o,type:u,size:l*f})}return t.sort((r,s)=>r.location-s.location),t}function i_(n,e){const t=[],i=n.getProgramParameter(e,35718);for(let r=0;r<i;r++){const s=n.getActiveUniform(e,r);if(!s)throw new Error("activeInfo");const{name:o,size:a,type:l}=s,{name:c,isArray:u}=s_(o);let f=n.getUniformLocation(e,c);const h={location:f,name:c,size:a,type:l,isArray:u};if(t.push(h),h.size>1)for(let d=0;d<h.size;d++){const _=`${c}[${d}]`;f=n.getUniformLocation(e,_);const I={...h,name:_,location:f};t.push(I)}}return t}function r_(n,e){const t=(s,o)=>n.getActiveUniformBlockParameter(e,s,o),i=[],r=n.getProgramParameter(e,35382);for(let s=0;s<r;s++){const o={name:n.getActiveUniformBlockName(e,s)||"",location:t(s,35391),byteLength:t(s,35392),vertex:t(s,35396),fragment:t(s,35398),uniformCount:t(s,35394),uniforms:[]},a=t(s,35395)||[],l=n.getActiveUniforms(e,a,35383),c=n.getActiveUniforms(e,a,35384),u=n.getActiveUniforms(e,a,35387),f=n.getActiveUniforms(e,a,35388);for(let h=0;h<o.uniformCount;++h){const d=n.getActiveUniform(e,a[h]);if(!d)throw new Error("activeInfo");const _=Ds(l[h]);o.uniforms.push({name:d.name,format:_,type:l[h],arrayLength:c[h],byteOffset:u[h],byteStride:f[h]})}i.push(o)}return i.sort((s,o)=>s.location-o.location),i}function s_(n){if(n[n.length-1]!=="]")return{name:n,length:1,isArray:!1};const t=/([^[]*)(\[[0-9]+\])?/.exec(n);if(!t||t.length<2)throw new Error(`Failed to parse GLSL uniform name ${n}`);return{name:t[1],length:t[2]?1:0,isArray:!!t[2]}}function o_(n,e,t,i){const r=n;let s=i;s===!0&&(s=1),s===!1&&(s=0);const o=typeof s=="number"?[s]:s;switch(t){case 35678:case 35680:case 35679:case 35682:case 36289:case 36292:case 36293:case 36298:case 36299:case 36300:case 36303:case 36306:case 36307:case 36308:case 36311:if(typeof i!="number")throw new Error("samplers must be set to integers");return n.uniform1i(e,i);case 5126:return n.uniform1fv(e,o);case 35664:return n.uniform2fv(e,o);case 35665:return n.uniform3fv(e,o);case 35666:return n.uniform4fv(e,o);case 5124:return n.uniform1iv(e,o);case 35667:return n.uniform2iv(e,o);case 35668:return n.uniform3iv(e,o);case 35669:return n.uniform4iv(e,o);case 35670:return n.uniform1iv(e,o);case 35671:return n.uniform2iv(e,o);case 35672:return n.uniform3iv(e,o);case 35673:return n.uniform4iv(e,o);case 5125:return r.uniform1uiv(e,o,1);case 36294:return r.uniform2uiv(e,o,2);case 36295:return r.uniform3uiv(e,o,3);case 36296:return r.uniform4uiv(e,o,4);case 35674:return n.uniformMatrix2fv(e,!1,o);case 35675:return n.uniformMatrix3fv(e,!1,o);case 35676:return n.uniformMatrix4fv(e,!1,o);case 35685:return r.uniformMatrix2x3fv(e,!1,o);case 35686:return r.uniformMatrix2x4fv(e,!1,o);case 35687:return r.uniformMatrix3x2fv(e,!1,o);case 35688:return r.uniformMatrix3x4fv(e,!1,o);case 35689:return r.uniformMatrix4x2fv(e,!1,o);case 35690:return r.uniformMatrix4x3fv(e,!1,o)}throw new Error("Illegal uniform")}function a_(n){switch(n){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 3;case"triangle-list":return 4;case"triangle-strip":return 5;default:throw new Error(n)}}function l_(n){switch(n){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 1;case"triangle-list":return 4;case"triangle-strip":return 4;default:throw new Error(n)}}const yl=4;class c_ extends Wt{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"vs");m(this,"fs");m(this,"introspectedLayout");m(this,"uniforms",{});m(this,"bindings",{});m(this,"varyings",null);m(this,"_uniformCount",0);m(this,"_uniformSetters",{});this.device=t,this.handle=this.props.handle||this.device.gl.createProgram(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:{id:this.props.id}}),this.vs=i.vs,this.fs=i.fs;const{varyings:r,bufferMode:s=35981}=i;r&&r.length>0&&(this.varyings=r,this.device.gl.transformFeedbackVaryings(this.handle,r,s)),this._linkShaders(),D.time(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.introspectedLayout=e_(this.device.gl,this.handle),D.timeEnd(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.shaderLayout=i.shaderLayout?u_(this.introspectedLayout,i.shaderLayout):this.introspectedLayout}get[Symbol.toStringTag](){return"WEBGLRenderPipeline"}destroy(){this.handle&&(this.device.gl.useProgram(null),this.device.gl.deleteProgram(this.handle),this.destroyed=!0,this.handle.destroyed=!0,this.handle=null)}setBindings(t,i){for(const[r,s]of Object.entries(t)){const o=this.shaderLayout.bindings.find(a=>a.name===r)||this.shaderLayout.bindings.find(a=>a.name===`${r}Uniforms`);if(!o){const a=this.shaderLayout.bindings.map(l=>`"${l.name}"`).join(", ");i!=null&&i.disableWarnings||D.warn(`No binding "${r}" in render pipeline "${this.id}", expected one of ${a}`,s)();continue}switch(s||D.warn(`Unsetting binding "${r}" in render pipeline "${this.id}"`)(),o.type){case"uniform":if(!(s instanceof Ln)&&!(s.buffer instanceof Ln))throw new Error("buffer value");break;case"texture":if(!(s instanceof pn||s instanceof Hn||s instanceof zn))throw new Error(`${this} Bad texture binding for ${r}`);break;case"sampler":D.warn(`Ignoring sampler ${r}`)();break;default:throw new Error(o.type)}this.bindings[r]=s}}draw(t){var P;const{renderPass:i,parameters:r=this.props.parameters,topology:s=this.props.topology,vertexArray:o,vertexCount:a,instanceCount:l,isInstanced:c=!1,firstVertex:u=0,transformFeedback:f}=t,h=a_(s),d=!!o.indexBuffer,_=(P=o.indexBuffer)==null?void 0:P.glIndexType;if(this.linkStatus!=="success")return D.info(2,`RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)(),!1;if(!this._areTexturesRenderable())return D.info(2,`RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)(),!1;this.device.gl.useProgram(this.handle),o.bindBeforeRender(i),f&&f.begin(this.props.topology),this._applyBindings(),this._applyUniforms();const I=i;return Lg(this.device,r,I.glParameters,()=>{d&&c?this.device.gl.drawElementsInstanced(h,a||0,_,u,l||0):d?this.device.gl.drawElements(h,a||0,_,u):c?this.device.gl.drawArraysInstanced(h,u,a||0,l||0):this.device.gl.drawArrays(h,u,a||0),f&&f.end()}),o.unbindAfterRender(i),!0}async _linkShaders(){const{gl:t}=this.device;if(t.attachShader(this.handle,this.vs.handle),t.attachShader(this.handle,this.fs.handle),D.time(yl,`linkProgram for ${this.id}`)(),t.linkProgram(this.handle),D.timeEnd(yl,`linkProgram for ${this.id}`)(),D.level,!this.device.features.has("compilation-status-async-webgl")){const r=this._getLinkStatus();this._reportLinkStatus(r);return}D.once(1,"RenderPipeline linking is asynchronous")(),await this._waitForLinkComplete(),D.info(2,`RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();const i=this._getLinkStatus();this._reportLinkStatus(i)}async _reportLinkStatus(t){var i;switch(t){case"success":return;default:const r=t==="link-error"?"Link error":"Validation error";switch(this.vs.compilationStatus){case"error":throw this.vs.debugShader(),new Error(`${this} ${r} during compilation of ${this.vs}`);case"pending":await this.vs.asyncCompilationStatus,this.vs.debugShader();break}switch((i=this.fs)==null?void 0:i.compilationStatus){case"error":throw this.fs.debugShader(),new Error(`${this} ${r} during compilation of ${this.fs}`);case"pending":await this.fs.asyncCompilationStatus,this.fs.debugShader();break}const s=this.device.gl.getProgramInfoLog(this.handle);this.device.reportError(new Error(`${r} during ${t}: ${s}`),this)(),this.device.debug()}}_getLinkStatus(){const{gl:t}=this.device;return t.getProgramParameter(this.handle,35714)?(t.validateProgram(this.handle),t.getProgramParameter(this.handle,35715)?(this.linkStatus="success","success"):(this.linkStatus="error","validation-error")):(this.linkStatus="error","link-error")}async _waitForLinkComplete(){const t=async s=>await new Promise(o=>setTimeout(o,s));if(!this.device.features.has("compilation-status-async-webgl")){await t(10);return}const{gl:r}=this.device;for(;;){if(r.getProgramParameter(this.handle,37297))return;await t(10)}}_areTexturesRenderable(){let t=!0;for(const i of this.shaderLayout.bindings)!this.bindings[i.name]&&!this.bindings[i.name.replace(/Uniforms$/,"")]&&(D.warn(`Binding ${i.name} not found in ${this.id}`)(),t=!1);return t}_applyBindings(){if(this.linkStatus!=="success")return;const{gl:t}=this.device;t.useProgram(this.handle);let i=0,r=0;for(const s of this.shaderLayout.bindings){const o=this.bindings[s.name]||this.bindings[s.name.replace(/Uniforms$/,"")];if(!o)throw new Error(`No value for binding ${s.name} in ${this.id}`);switch(s.type){case"uniform":const{name:a}=s,l=t.getUniformBlockIndex(this.handle,a);if(l===4294967295)throw new Error(`Invalid uniform block name ${a}`);t.uniformBlockBinding(this.handle,r,l),o instanceof Ln?t.bindBufferBase(35345,r,o.handle):t.bindBufferRange(35345,r,o.buffer.handle,o.offset||0,o.size||o.buffer.byteLength-o.offset),r+=1;break;case"texture":if(!(o instanceof pn||o instanceof Hn||o instanceof zn))throw new Error("texture");let c;if(o instanceof pn)c=o.texture;else if(o instanceof Hn)c=o;else if(o instanceof zn&&o.colorAttachments[0]instanceof pn)D.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")(),c=o.colorAttachments[0].texture;else throw new Error("No texture");t.activeTexture(33984+i),t.bindTexture(c.glTarget,c.handle),i+=1;break;case"sampler":break;case"storage":case"read-only-storage":throw new Error(`binding type '${s.type}' not supported in WebGL`)}}}_applyUniforms(){for(const t of this.shaderLayout.uniforms||[]){const{name:i,location:r,type:s,textureUnit:o}=t,a=this.uniforms[i]??o;a!==void 0&&o_(this.device.gl,r,s,a)}}}function u_(n,e){const t={...n,attributes:n.attributes.map(i=>({...i}))};for(const i of(e==null?void 0:e.attributes)||[]){const r=t.attributes.find(s=>s.name===i.name);r?(r.type=i.type||r.type,r.stepMode=i.stepMode||r.stepMode):D.warn(`shader layout attribute ${i.name} not present in shader`)}return t}class f_ extends xs{constructor(t){super(t,{});m(this,"device");m(this,"handle",null);m(this,"commands",[]);this.device=t}_executeCommands(t=this.commands){for(const i of t)switch(i.name){case"copy-buffer-to-buffer":h_(this.device,i.options);break;case"copy-buffer-to-texture":d_(this.device,i.options);break;case"copy-texture-to-buffer":p_(this.device,i.options);break;case"copy-texture-to-texture":m_(this.device,i.options);break;default:throw new Error(i.name)}}}function h_(n,e){const t=e.sourceBuffer,i=e.destinationBuffer;n.gl.bindBuffer(36662,t.handle),n.gl.bindBuffer(36663,i.handle),n.gl.copyBufferSubData(36662,36663,e.sourceOffset??0,e.destinationOffset??0,e.size),n.gl.bindBuffer(36662,null),n.gl.bindBuffer(36663,null)}function d_(n,e){throw new Error("Not implemented")}function p_(n,e){const{sourceTexture:t,mipLevel:i=0,aspect:r="all",width:s=e.sourceTexture.width,height:o=e.sourceTexture.height,depthOrArrayLayers:a=0,origin:l=[0,0],destinationBuffer:c,byteOffset:u=0,bytesPerRow:f,rowsPerImage:h}=e;if(r!=="all")throw new Error("aspect not supported in WebGL");if(i!==0||a!==0||f||h)throw new Error("not implemented");const{framebuffer:d,destroyFramebuffer:_}=vl(t);let I;try{const P=c,A=s||d.width,O=o||d.height,E=hl(d.colorAttachments[0].texture.props.format),x=E.format,R=E.type;n.gl.bindBuffer(35051,P.handle),I=n.gl.bindFramebuffer(36160,d.handle),n.gl.readPixels(l[0],l[1],A,O,x,R,u)}finally{n.gl.bindBuffer(35051,null),I!==void 0&&n.gl.bindFramebuffer(36160,I),_&&d.destroy()}}function m_(n,e){const{sourceTexture:t,destinationMipLevel:i=0,origin:r=[0,0],destinationOrigin:s=[0,0],destinationTexture:o}=e;let{width:a=e.destinationTexture.width,height:l=e.destinationTexture.height}=e;const{framebuffer:c,destroyFramebuffer:u}=vl(t),[f,h]=r,[d,_,I]=s,P=n.gl.bindFramebuffer(36160,c.handle);let A,O;if(o instanceof Hn)A=o,a=Number.isFinite(a)?a:A.width,l=Number.isFinite(l)?l:A.height,A._bind(0),O=A.glTarget;else throw new Error("invalid destination");switch(O){case 3553:case 34067:n.gl.copyTexSubImage2D(O,i,d,_,f,h,a,l);break;case 35866:case 32879:n.gl.copyTexSubImage3D(O,i,d,_,I,f,h,a,l);break}A&&A._unbind(),n.gl.bindFramebuffer(36160,P),u&&c.destroy()}function vl(n){if(n instanceof Q){const{width:e,height:t,id:i}=n;return{framebuffer:n.device.createFramebuffer({id:`framebuffer-for-${i}`,width:e,height:t,colorAttachments:[n]}),destroyFramebuffer:!0}}return{framebuffer:n,destroyFramebuffer:!1}}const g_=[1,2,4,8];class __ extends gs{constructor(t,i){var o;super(t,i);m(this,"device");m(this,"handle",null);m(this,"glParameters",{});this.device=t;let r;if(!((o=i==null?void 0:i.parameters)!=null&&o.viewport))if(i!=null&&i.framebuffer){const{width:a,height:l}=i.framebuffer;r=[0,0,a,l]}else{const[a,l]=t.getDefaultCanvasContext().getDrawingBufferSize();r=[0,0,a,l]}this.device.pushState(),this.setParameters({viewport:r,...this.props.parameters});const s=this.props.framebuffer;if(this.props.framebuffer&&(s!=null&&s.handle)){const a=this.props.framebuffer.colorAttachments.map((l,c)=>36064+c);this.device.gl.drawBuffers(a)}else this.device.gl.drawBuffers([1029]);this.clear()}end(){this.device.popState()}pushDebugGroup(t){}popDebugGroup(){}insertDebugMarker(t){}setParameters(t={}){const i={...this.glParameters};i.framebuffer=this.props.framebuffer||null,this.props.depthReadOnly&&(i.depthMask=!this.props.depthReadOnly),i.stencilMask=this.props.stencilReadOnly?0:1,i[35977]=this.props.discard,t.viewport&&(t.viewport.length>=6?(i.viewport=t.viewport.slice(0,4),i.depthRange=[t.viewport[4],t.viewport[5]]):i.viewport=t.viewport),t.scissorRect&&(i.scissorTest=!0,i.scissor=t.scissorRect),t.blendConstant&&(i.blendColor=t.blendConstant),t.stencilReference&&(console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL"),i[2967]=t.stencilReference),"colorMask"in t&&(i.colorMask=g_.map(r=>!!(r&t.colorMask))),this.glParameters=i,un(this.device.gl,i)}beginOcclusionQuery(t){const i=this.props.occlusionQuerySet;i==null||i.beginOcclusionQuery()}endOcclusionQuery(){const t=this.props.occlusionQuerySet;t==null||t.endOcclusionQuery()}clear(){const t={...this.glParameters};let i=0;this.props.clearColors&&this.props.clearColors.forEach((r,s)=>{r&&this.clearColorBuffer(s,r)}),this.props.clearColor!==!1&&this.props.clearColors===void 0&&(i|=16384,t.clearColor=this.props.clearColor),this.props.clearDepth!==!1&&(i|=256,t.clearDepth=this.props.clearDepth),this.props.clearStencil!==!1&&(i|=1024,t.clearStencil=this.props.clearStencil),i!==0&&Vn(this.device.gl,t,()=>{this.device.gl.clear(i)})}clearColorBuffer(t=0,i=[0,0,0,0]){Vn(this.device.gl,{framebuffer:this.props.framebuffer},()=>{switch(i.constructor){case Int8Array:case Int16Array:case Int32Array:this.device.gl.clearBufferiv(6144,t,i);break;case Uint8Array:case Uint8ClampedArray:case Uint16Array:case Uint32Array:this.device.gl.clearBufferuiv(6144,t,i);break;case Float32Array:this.device.gl.clearBufferfv(6144,t,i);break;default:throw new Error("clearColorBuffer: color must be typed array")}})}}class bl extends _s{constructor(t,i){super(t,i);m(this,"device");m(this,"handle",null);m(this,"commandBuffer");this.device=t,this.commandBuffer=new f_(t)}destroy(){}finish(){return this.commandBuffer}beginRenderPass(t){return new __(this.device,t)}beginComputePass(t){throw new Error("ComputePass not supported in WebGL")}copyBufferToBuffer(t){this.commandBuffer.commands.push({name:"copy-buffer-to-buffer",options:t})}copyBufferToTexture(t){this.commandBuffer.commands.push({name:"copy-buffer-to-texture",options:t})}copyTextureToBuffer(t){this.commandBuffer.commands.push({name:"copy-texture-to-buffer",options:t})}copyTextureToTexture(t){this.commandBuffer.commands.push({name:"copy-texture-to-texture",options:t})}pushDebugGroup(t){}popDebugGroup(){}insertDebugMarker(t){}resolveQuerySet(t,i,r){}}function x_(n){const{target:e,source:t,start:i=0,count:r=1}=n,s=t.length,o=r*s;let a=0;for(let l=i;a<s;a++)e[l++]=t[a];for(;a<o;)a<o-a?(e.copyWithin(i+a,i,i+a),a*=2):(e.copyWithin(i+a,i,i+o-a),a=o);return n.target}class Ms extends ys{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"buffer",null);m(this,"bufferValue",null);this.device=t,this.handle=this.device.gl.createVertexArray()}get[Symbol.toStringTag](){return"VertexArray"}static isConstantAttributeZeroSupported(t){return Rp()==="Chrome"}destroy(){var t;super.destroy(),this.buffer&&((t=this.buffer)==null||t.destroy()),this.handle&&(this.device.gl.deleteVertexArray(this.handle),this.handle=void 0)}setIndexBuffer(t){const i=t;if(i&&i.glTarget!==34963)throw new Error("Use .setBuffer()");this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34963,i?i.handle:null),this.indexBuffer=i,this.device.gl.bindVertexArray(null)}setBuffer(t,i){const r=i;if(r.glTarget===34963)throw new Error("Use .setIndexBuffer()");const{size:s,type:o,stride:a,offset:l,normalized:c,integer:u,divisor:f}=this._getAccessor(t);this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34962,r.handle),u?this.device.gl.vertexAttribIPointer(t,s,o,a,l):this.device.gl.vertexAttribPointer(t,s,o,c,a,l),this.device.gl.bindBuffer(34962,null),this.device.gl.enableVertexAttribArray(t),this.device.gl.vertexAttribDivisor(t,f||0),this.attributes[t]=r,this.device.gl.bindVertexArray(null)}setConstantWebGL(t,i){this._enable(t,!1),this.attributes[t]=i}bindBeforeRender(){this.device.gl.bindVertexArray(this.handle),this._applyConstantAttributes()}unbindAfterRender(){this.device.gl.bindVertexArray(null)}_applyConstantAttributes(){for(let t=0;t<this.maxVertexAttributes;++t){const i=this.attributes[t];ArrayBuffer.isView(i)&&this.device.setConstantAttributeWebGL(t,i)}}_getAccessor(t){const i=this.attributeInfos[t];if(!i)throw new Error(`Unknown attribute location ${t}`);const r=cl(i.bufferDataType);return{size:i.bufferComponents,type:r,stride:i.byteStride,offset:i.byteOffset,normalized:i.normalized,integer:i.integer,divisor:i.stepMode==="instance"?1:0}}_enable(t,i=!0){const s=Ms.isConstantAttributeZeroSupported(this.device)||t!==0;(i||s)&&(t=Number(t),this.device.gl.bindVertexArray(this.handle),i?this.device.gl.enableVertexAttribArray(t):this.device.gl.disableVertexAttribArray(t),this.device.gl.bindVertexArray(null))}getConstantBuffer(t,i){const r=y_(i),s=r.byteLength*t,o=r.length*t;if(this.buffer&&s!==this.buffer.byteLength)throw new Error(`Buffer size is immutable, byte length ${s} !== ${this.buffer.byteLength}.`);let a=!this.buffer;if(this.buffer=this.buffer||this.device.createBuffer({byteLength:s}),a||(a=!v_(r,this.bufferValue)),a){const l=Fm(i.constructor,o);x_({target:l,source:r,start:0,count:o}),this.buffer.write(l),this.bufferValue=i}return this.buffer}}function y_(n){return Array.isArray(n)?new Float32Array(n):n}function v_(n,e){if(!n||!e||n.length!==e.length||n.constructor!==e.constructor)return!1;for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}class b_ extends vs{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"layout");m(this,"buffers",{});m(this,"unusedBuffers",{});m(this,"bindOnUse",!0);m(this,"_bound",!1);this.device=t,this.gl=t.gl,this.handle=this.props.handle||this.gl.createTransformFeedback(),this.layout=this.props.layout,i.buffers&&this.setBuffers(i.buffers),Object.seal(this)}destroy(){this.gl.deleteTransformFeedback(this.handle),super.destroy()}begin(t="point-list"){this.gl.bindTransformFeedback(36386,this.handle),this.bindOnUse&&this._bindBuffers(),this.gl.beginTransformFeedback(l_(t))}end(){this.gl.endTransformFeedback(),this.bindOnUse&&this._unbindBuffers(),this.gl.bindTransformFeedback(36386,null)}setBuffers(t){this.buffers={},this.unusedBuffers={},this.bind(()=>{for(const i in t)this.setBuffer(i,t[i])})}setBuffer(t,i){const r=this._getVaryingIndex(t),{buffer:s,byteLength:o,byteOffset:a}=this._getBufferRange(i);if(r<0){this.unusedBuffers[t]=s,D.warn(`${this.id} unusedBuffers varying buffer ${t}`)();return}this.buffers[r]={buffer:s,byteLength:o,byteOffset:a},this.bindOnUse||this._bindBuffer(r,s,a,o)}getBuffer(t){if(Sl(t))return this.buffers[t]||null;const i=this._getVaryingIndex(t);return i>=0?this.buffers[i]:null}bind(t=this.handle){if(typeof t!="function")return this.gl.bindTransformFeedback(36386,t),this;let i;return this._bound?i=t():(this.gl.bindTransformFeedback(36386,this.handle),this._bound=!0,i=t(),this._bound=!1,this.gl.bindTransformFeedback(36386,null)),i}unbind(){this.bind(null)}_getBufferRange(t){if(t instanceof Ln)return{buffer:t,byteOffset:0,byteLength:t.byteLength};const{buffer:i,byteOffset:r=0,byteLength:s=t.buffer.byteLength}=t;return{buffer:i,byteOffset:r,byteLength:s}}_getVaryingIndex(t){if(Sl(t))return Number(t);for(const i of this.layout.varyings||[])if(t===i.name)return i.location;return-1}_bindBuffers(){for(const t in this.buffers){const{buffer:i,byteLength:r,byteOffset:s}=this._getBufferRange(this.buffers[t]);this._bindBuffer(Number(t),i,s,r)}}_unbindBuffers(){for(const t in this.buffers)this.gl.bindBufferBase(35982,Number(t),null)}_bindBuffer(t,i,r=0,s){const o=i&&i.handle;!o||s===void 0?this.gl.bindBufferBase(35982,t,o):this.gl.bindBufferRange(35982,t,o,r,s)}}function Sl(n){return typeof n=="number"?Number.isInteger(n):/^\d+$/.test(n)}class S_ extends bs{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"target",null);m(this,"_queryPending",!1);m(this,"_pollingPromise",null);if(this.device=t,i.count>1)throw new Error("WebGL QuerySet can only have one value");const r=this.device.gl.createQuery();if(!r)throw new Error("WebGL query not supported");this.handle=r,Object.seal(this)}get[Symbol.toStringTag](){return"Query"}destroy(){this.device.gl.deleteQuery(this.handle)}beginTimestampQuery(){return this._begin(35007)}endTimestampQuery(){this._end()}beginOcclusionQuery(t){return this._begin(t!=null&&t.conservative?36202:35887)}endOcclusionQuery(){this._end()}beginTransformFeedbackQuery(){return this._begin(35976)}endTransformFeedbackQuery(){this._end()}async resolveQuery(){return[await this.pollQuery()]}_begin(t){this._queryPending||(this.target=t,this.device.gl.beginQuery(this.target,this.handle))}_end(){this._queryPending||this.target&&(this.device.gl.endQuery(this.target),this.target=null,this._queryPending=!0)}isResultAvailable(){if(!this._queryPending)return!1;const t=this.device.gl.getQueryParameter(this.handle,34919);return t&&(this._queryPending=!1),t}isTimerDisjoint(){return this.device.gl.getParameter(36795)}getResult(){return this.device.gl.getQueryParameter(this.handle,34918)}getTimerMilliseconds(){return this.getResult()/1e6}pollQuery(t=Number.POSITIVE_INFINITY){if(this._pollingPromise)return this._pollingPromise;let i=0;return this._pollingPromise=new Promise((r,s)=>{const o=()=>{this.isResultAvailable()?(r(this.getResult()),this._pollingPromise=null):i++>t?(s("Timed out"),this._pollingPromise=null):requestAnimationFrame(o)};requestAnimationFrame(o)}),this._pollingPromise}}function Tl(n){switch(n){case 6406:case 33326:case 6403:case 36244:return 1;case 33339:case 33340:case 33328:case 33320:case 33319:return 2;case 6407:case 36248:case 34837:return 3;case 6408:case 36249:case 34836:return 4;default:return 0}}function T_(n){switch(n){case 5121:return 1;case 33635:case 32819:case 32820:return 2;case 5126:return 4;default:return 0}}function w_(n){return A_[n]}const A_={5124:"sint32",5125:"uint32",5122:"sint16",5123:"uint16",5120:"sint8",5121:"uint8",5126:"float32",5131:"float16",33635:"uint16",32819:"uint16",32820:"uint16",33640:"uint32",35899:"uint32",35902:"uint32",34042:"uint32",36269:"uint32"};function C_(n,e){var O;const{sourceX:t=0,sourceY:i=0,sourceAttachment:r=0}=e||{};let{target:s=null,sourceWidth:o,sourceHeight:a,sourceDepth:l,sourceFormat:c,sourceType:u}=e||{};const{framebuffer:f,deleteFramebuffer:h}=wl(n),{gl:d,handle:_}=f;o||(o=f.width),a||(a=f.height);const I=(O=f.colorAttachments[r])==null?void 0:O.texture;if(!I)throw new Error(`Invalid framebuffer attachment ${r}`);l=(I==null?void 0:I.depth)||1,c||(c=(I==null?void 0:I.glFormat)||6408),u||(u=(I==null?void 0:I.glType)||5121),s=E_(s,u,c,o,a);const P=za(s);u=u||Kg(P);const A=d.bindFramebuffer(36160,_);return d.readBuffer(36064+r),d.readPixels(t,i,o,a,c,u,s),d.readBuffer(36064),d.bindFramebuffer(36160,A||null),h&&f.destroy(),s}function I_(n,e){const{target:t,sourceX:i=0,sourceY:r=0,sourceFormat:s=6408,targetByteOffset:o=0}=e||{};let{sourceWidth:a,sourceHeight:l,sourceType:c}=e||{};const{framebuffer:u,deleteFramebuffer:f}=wl(n);a=a||u.width,l=l||u.height;const h=u;c=c||5121;let d=t;if(!d){const I=Tl(s),P=T_(c),A=o+a*l*I*P;d=h.device.createBuffer({byteLength:A})}const _=n.device.createCommandEncoder();return _.copyTextureToBuffer({sourceTexture:n,width:a,height:l,origin:[i,r],destinationBuffer:d,byteOffset:o}),_.destroy(),f&&u.destroy(),d}function wl(n){return n instanceof Oi?{framebuffer:n,deleteFramebuffer:!1}:{framebuffer:P_(n),deleteFramebuffer:!0}}function P_(n,e){const{device:t,width:i,height:r,id:s}=n;return t.createFramebuffer({...e,id:`framebuffer-for-${s}`,width:i,height:r,colorAttachments:[n]})}function E_(n,e,t,i,r,s){if(n)return n;e||(e=5121);const o=w_(e),a=La(o),l=Tl(t);return new a(i*r*l)}class R_ extends Ht{constructor(t){var f,h;super({...t,id:t.id||Ng("webgl-device")});m(this,"type","webgl");m(this,"handle");m(this,"features");m(this,"limits");m(this,"info");m(this,"canvasContext");m(this,"preferredColorFormat","rgba8unorm");m(this,"preferredDepthFormat","depth24plus");m(this,"commandEncoder");m(this,"lost");m(this,"_resolveContextLost");m(this,"gl");m(this,"_constants");m(this,"_extensions",{});m(this,"_polyfilled",!1);m(this,"spectorJS");const i=Ht._getCanvasContextProps(t);if(!i)throw new Error("WebGLDevice requires props.createCanvasContext to be set");let r=(h=(f=i.canvas)==null?void 0:f.gl)==null?void 0:h.device;if(r)throw new Error(`WebGL context already attached to device ${r.id}`);this.canvasContext=new Fg(this,i),this.lost=new Promise(d=>{this._resolveContextLost=d});const s={...t.webgl};i.alphaMode==="premultiplied"&&(s.premultipliedAlpha=!0),t.powerPreference!==void 0&&(s.powerPreference=t.powerPreference);const a=this.props._handle||pg(this.canvasContext.canvas,{onContextLost:d=>{var _;return(_=this._resolveContextLost)==null?void 0:_.call(this,{reason:"destroyed",message:"Entered sleep mode, or too many apps or browser tabs are using the GPU."})},onContextRestored:d=>console.log("WebGL context restored")},s);if(!a)throw new Error("WebGL context creation failed");if(r=a.device,r){if(t._reuseDevices)return D.log(1,`Not creating a new Device, instead returning a reference to Device ${r.id} already attached to WebGL context`,r)(),r._reused=!0,r;throw new Error(`WebGL context already attached to device ${r.id}`)}this.handle=a,this.gl=a,this.spectorJS=Km({...this.props,gl:this.handle}),this.gl.device=this,this.gl._version=2,this.info=mg(this.gl,this._extensions),this.limits=new kg(this.gl),this.features=new Rg(this.gl,this._extensions,this.props._disabledFeatures),this.props._initializeFeatures&&this.features.initializeFeatures(),new Xt(this.gl,{log:(...d)=>D.log(1,...d)()}).trackState(this.gl,{copyState:!1});const c=t.debugWebGL||t.debug,u=t.debugWebGL;c&&(this.gl=Jm(this.gl,{debugWebGL:c,traceWebGL:u}),D.warn("WebGL debug mode activated. Performance reduced.")(),t.debugWebGL&&(D.level=Math.max(D.level,1))),this.commandEncoder=new bl(this,{id:`${this}-command-encoder`})}get[Symbol.toStringTag](){return"WebGLDevice"}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}isVertexFormatSupported(t){switch(t){case"unorm8x4-bgra":return!1;default:return!0}}destroy(){!this.props._reuseDevices&&!this._reused&&delete this.gl.device}get isLost(){return this.gl.isContextLost()}getTextureByteAlignment(){return 4}createCanvasContext(t){throw new Error("WebGL only supports a single canvas")}createBuffer(t){const i=this._normalizeBufferProps(t);return new Ln(this,i)}createTexture(t){return new Hn(this,t)}createExternalTexture(t){throw new Error("createExternalTexture() not implemented")}createSampler(t){return new Yg(this,t)}createShader(t){return new zg(this,t)}createFramebuffer(t){return new zn(this,t)}createVertexArray(t){return new Ms(this,t)}createTransformFeedback(t){return new b_(this,t)}createQuerySet(t){return new S_(this,t)}createRenderPipeline(t){return new c_(this,t)}createComputePipeline(t){throw new Error("ComputePipeline not supported in WebGL")}createCommandEncoder(t={}){return new bl(this,t)}submit(t){t||(t=this.commandEncoder.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:`${this.id}-default-encoder`})),t._executeCommands()}readPixelsToArrayWebGL(t,i){return C_(t,i)}readPixelsToBufferWebGL(t,i){return I_(t,i)}setParametersWebGL(t){un(this.gl,t)}getParametersWebGL(t){return sl(this.gl,t)}withParametersWebGL(t,i){return Vn(this.gl,t,i)}resetWebGL(){D.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")(),cg(this.gl)}_getDeviceSpecificTextureFormatCapabilities(t){return Cg(this.gl,t,this._extensions)}loseDevice(){var s;let t=!1;const r=this.getExtension("WEBGL_lose_context").WEBGL_lose_context;return r&&(t=!0,r.loseContext()),(s=this._resolveContextLost)==null||s.call(this,{reason:"destroyed",message:"Application triggered context loss"}),t}pushState(){Xt.get(this.gl).push()}popState(){Xt.get(this.gl).pop()}getGLKey(t,i){const r=Number(t);for(const s in this.gl)if(this.gl[s]===r)return`GL.${s}`;return i!=null&&i.emptyIfUnknown?"":String(t)}getGLKeys(t){const i={emptyIfUnknown:!0};return Object.entries(t).reduce((r,[s,o])=>(r[`${s}:${this.getGLKey(s,i)}`]=`${o}:${this.getGLKey(o,i)}`,r),{})}setConstantAttributeWebGL(t,i){const r=this.limits.maxVertexAttributes;this._constants=this._constants||new Array(r).fill(null);const s=this._constants[t];switch(s&&F_(s,i)&&D.info(1,`setConstantAttributeWebGL(${t}) could have been skipped, value unchanged`)(),this._constants[t]=i,i.constructor){case Float32Array:k_(this,t,i);break;case Int32Array:D_(this,t,i);break;case Uint32Array:M_(this,t,i);break;default:throw new Error("constant")}}getExtension(t){return fn(this.gl,t,this._extensions),this._extensions}_setWebGLDebugMetadata(t,i,r){t.luma=i;const s={props:r.spector,id:r.spector.id};t.__SPECTOR_Metadata=s}}function k_(n,e,t){switch(t.length){case 1:n.gl.vertexAttrib1fv(e,t);break;case 2:n.gl.vertexAttrib2fv(e,t);break;case 3:n.gl.vertexAttrib3fv(e,t);break;case 4:n.gl.vertexAttrib4fv(e,t);break}}function D_(n,e,t){n.gl.vertexAttribI4iv(e,t)}function M_(n,e,t){n.gl.vertexAttribI4uiv(e,t)}function F_(n,e){if(!n||!e||n.length!==e.length||n.constructor!==e.constructor)return!1;for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}const Al=Object.freeze(Object.defineProperty({__proto__:null,WebGLDevice:R_},Symbol.toStringTag,{value:"Module"})),Cl="#b3b3b3",Il=void 0,Hi=void 0,Pl=1,El=4,Rl="#666666",kl=.1,Dl=1,Ml=1,Fs="#222222",V={enableSimulation:!0,spaceSize:4096,pointSizeScale:1,linkWidthScale:1,linkArrowsSizeScale:1,renderLinks:!0,curvedLinks:!1,curvedLinkSegments:19,curvedLinkWeight:.8,curvedLinkControlPointDistance:.5,linkArrows:!1,linkVisibilityDistanceRange:[50,150],linkVisibilityMinTransparency:.25,hoveredPointCursor:"auto",hoveredLinkCursor:"auto",renderHoveredPointRing:!1,hoveredPointRingColor:"white",hoveredLinkColor:void 0,hoveredLinkWidthIncrease:5,focusedPointRingColor:"white",focusedPointIndex:void 0,simulation:{decay:5e3,gravity:.25,center:0,repulsion:1,repulsionTheta:1.15,linkSpring:1,linkDistance:10,linkDistRandomVariationRange:[1,1.2],repulsionFromMouse:2,friction:.85,cluster:.1},showFPSMonitor:!1,pixelRatio:typeof window<"u"&&window.devicePixelRatio||2,scalePointsOnZoom:!1,scaleLinksOnZoom:!1,enableZoom:!0,enableSimulationDuringZoom:!1,enableDrag:!1,fitViewOnInit:!0,fitViewDelay:250,fitViewPadding:.1,fitViewDuration:250,pointSamplingDistance:100,linkSamplingDistance:100,attribution:"",rescalePositions:void 0,enableRightClickRepulsion:!1},Fl=.7,Nl=.95,Ol=3;/*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE */const{entries:Bl,setPrototypeOf:Ul,isFrozen:N_,getPrototypeOf:O_,getOwnPropertyDescriptor:B_}=Object;let{freeze:ze,seal:Qe,create:zl}=Object,{apply:Ns,construct:Os}=typeof Reflect<"u"&&Reflect;ze||(ze=function(e){return e}),Qe||(Qe=function(e){return e}),Ns||(Ns=function(e,t,i){return e.apply(t,i)}),Os||(Os=function(e,t){return new e(...t)});const Wi=Ve(Array.prototype.forEach),U_=Ve(Array.prototype.lastIndexOf),Ll=Ve(Array.prototype.pop),Wn=Ve(Array.prototype.push),z_=Ve(Array.prototype.splice),$i=Ve(String.prototype.toLowerCase),Bs=Ve(String.prototype.toString),Vl=Ve(String.prototype.match),$n=Ve(String.prototype.replace),L_=Ve(String.prototype.indexOf),V_=Ve(String.prototype.trim),ot=Ve(Object.prototype.hasOwnProperty),Le=Ve(RegExp.prototype.test),Xn=H_(TypeError);function Ve(n){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var t=arguments.length,i=new Array(t>1?t-1:0),r=1;r<t;r++)i[r-1]=arguments[r];return Ns(n,e,i)}}function H_(n){return function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return Os(n,t)}}function ne(n,e){let t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:$i;Ul&&Ul(n,null);let i=e.length;for(;i--;){let r=e[i];if(typeof r=="string"){const s=t(r);s!==r&&(N_(e)||(e[i]=s),r=s)}n[r]=!0}return n}function W_(n){for(let e=0;e<n.length;e++)ot(n,e)||(n[e]=null);return n}function St(n){const e=zl(null);for(const[t,i]of Bl(n))ot(n,t)&&(Array.isArray(i)?e[t]=W_(i):i&&typeof i=="object"&&i.constructor===Object?e[t]=St(i):e[t]=i);return e}function Yn(n,e){for(;n!==null;){const i=B_(n,e);if(i){if(i.get)return Ve(i.get);if(typeof i.value=="function")return Ve(i.value)}n=O_(n)}function t(){return null}return t}const Hl=ze(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Us=ze(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),zs=ze(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),$_=ze(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Ls=ze(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),X_=ze(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Wl=ze(["#text"]),$l=ze(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),Vs=ze(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Xl=ze(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Xi=ze(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Y_=Qe(/\{\{[\w\W]*|[\w\W]*\}\}/gm),q_=Qe(/<%[\w\W]*|[\w\W]*%>/gm),j_=Qe(/\$\{[\w\W]*/gm),K_=Qe(/^data-[\-\w.\u00B7-\uFFFF]+$/),Z_=Qe(/^aria-[\-\w]+$/),Yl=Qe(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Q_=Qe(/^(?:\w+script|data):/i),J_=Qe(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),ql=Qe(/^html$/i),G_=Qe(/^[a-z][.\w]*(-[.\w]+)+$/i);var jl=Object.freeze({__proto__:null,ARIA_ATTR:Z_,ATTR_WHITESPACE:J_,CUSTOM_ELEMENT:G_,DATA_ATTR:K_,DOCTYPE_NAME:ql,ERB_EXPR:q_,IS_ALLOWED_URI:Yl,IS_SCRIPT_OR_DATA:Q_,MUSTACHE_EXPR:Y_,TMPLIT_EXPR:j_});const qn={element:1,text:3,progressingInstruction:7,comment:8,document:9},ex=function(){return typeof window>"u"?null:window},tx=function(e,t){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let i=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(i=t.getAttribute(r));const s="dompurify"+(i?"#"+i:"");try{return e.createPolicy(s,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return console.warn("TrustedTypes policy "+s+" could not be created."),null}},Kl=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Zl(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ex();const e=Y=>Zl(Y);if(e.version="3.2.6",e.removed=[],!n||!n.document||n.document.nodeType!==qn.document||!n.Element)return e.isSupported=!1,e;let{document:t}=n;const i=t,r=i.currentScript,{DocumentFragment:s,HTMLTemplateElement:o,Node:a,Element:l,NodeFilter:c,NamedNodeMap:u=n.NamedNodeMap||n.MozNamedAttrMap,HTMLFormElement:f,DOMParser:h,trustedTypes:d}=n,_=l.prototype,I=Yn(_,"cloneNode"),P=Yn(_,"remove"),A=Yn(_,"nextSibling"),O=Yn(_,"childNodes"),E=Yn(_,"parentNode");if(typeof o=="function"){const Y=t.createElement("template");Y.content&&Y.content.ownerDocument&&(t=Y.content.ownerDocument)}let x,R="";const{implementation:N,createNodeIterator:U,createDocumentFragment:W,getElementsByTagName:q}=t,{importNode:G}=i;let B=Kl();e.isSupported=typeof Bl=="function"&&typeof E=="function"&&N&&N.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:de,ERB_EXPR:se,TMPLIT_EXPR:C,DATA_ATTR:H,ARIA_ATTR:M,IS_SCRIPT_OR_DATA:$,ATTR_WHITESPACE:Z,CUSTOM_ELEMENT:j}=jl;let{IS_ALLOWED_URI:ee}=jl,J=null;const ge=ne({},[...Hl,...Us,...zs,...Ls,...Wl]);let fe=null;const Te=ne({},[...$l,...Vs,...Xl,...Xi]);let oe=Object.seal(zl(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),We=null,$e=null,nt=!0,Gt=!0,Mu=!1,Fu=!0,vn=!1,Br=!0,en=!1,Do=!1,Mo=!1,bn=!1,Ur=!1,zr=!1,Nu=!0,Ou=!1;const Zv="user-content-";let Fo=!0,si=!1,Sn={},Tn=null;const Bu=ne({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Uu=null;const zu=ne({},["audio","video","img","source","image","track"]);let No=null;const Lu=ne({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Lr="http://www.w3.org/1998/Math/MathML",Vr="http://www.w3.org/2000/svg",Pt="http://www.w3.org/1999/xhtml";let wn=Pt,Oo=!1,Bo=null;const Qv=ne({},[Lr,Vr,Pt],Bs);let Hr=ne({},["mi","mo","mn","ms","mtext"]),Wr=ne({},["annotation-xml"]);const Jv=ne({},["title","style","font","a","script"]);let oi=null;const Gv=["application/xhtml+xml","text/html"],eb="text/html";let Ee=null,An=null;const tb=t.createElement("form"),Vu=function(y){return y instanceof RegExp||y instanceof Function},Uo=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(An&&An===y)){if((!y||typeof y!="object")&&(y={}),y=St(y),oi=Gv.indexOf(y.PARSER_MEDIA_TYPE)===-1?eb:y.PARSER_MEDIA_TYPE,Ee=oi==="application/xhtml+xml"?Bs:$i,J=ot(y,"ALLOWED_TAGS")?ne({},y.ALLOWED_TAGS,Ee):ge,fe=ot(y,"ALLOWED_ATTR")?ne({},y.ALLOWED_ATTR,Ee):Te,Bo=ot(y,"ALLOWED_NAMESPACES")?ne({},y.ALLOWED_NAMESPACES,Bs):Qv,No=ot(y,"ADD_URI_SAFE_ATTR")?ne(St(Lu),y.ADD_URI_SAFE_ATTR,Ee):Lu,Uu=ot(y,"ADD_DATA_URI_TAGS")?ne(St(zu),y.ADD_DATA_URI_TAGS,Ee):zu,Tn=ot(y,"FORBID_CONTENTS")?ne({},y.FORBID_CONTENTS,Ee):Bu,We=ot(y,"FORBID_TAGS")?ne({},y.FORBID_TAGS,Ee):St({}),$e=ot(y,"FORBID_ATTR")?ne({},y.FORBID_ATTR,Ee):St({}),Sn=ot(y,"USE_PROFILES")?y.USE_PROFILES:!1,nt=y.ALLOW_ARIA_ATTR!==!1,Gt=y.ALLOW_DATA_ATTR!==!1,Mu=y.ALLOW_UNKNOWN_PROTOCOLS||!1,Fu=y.ALLOW_SELF_CLOSE_IN_ATTR!==!1,vn=y.SAFE_FOR_TEMPLATES||!1,Br=y.SAFE_FOR_XML!==!1,en=y.WHOLE_DOCUMENT||!1,bn=y.RETURN_DOM||!1,Ur=y.RETURN_DOM_FRAGMENT||!1,zr=y.RETURN_TRUSTED_TYPE||!1,Mo=y.FORCE_BODY||!1,Nu=y.SANITIZE_DOM!==!1,Ou=y.SANITIZE_NAMED_PROPS||!1,Fo=y.KEEP_CONTENT!==!1,si=y.IN_PLACE||!1,ee=y.ALLOWED_URI_REGEXP||Yl,wn=y.NAMESPACE||Pt,Hr=y.MATHML_TEXT_INTEGRATION_POINTS||Hr,Wr=y.HTML_INTEGRATION_POINTS||Wr,oe=y.CUSTOM_ELEMENT_HANDLING||{},y.CUSTOM_ELEMENT_HANDLING&&Vu(y.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(oe.tagNameCheck=y.CUSTOM_ELEMENT_HANDLING.tagNameCheck),y.CUSTOM_ELEMENT_HANDLING&&Vu(y.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(oe.attributeNameCheck=y.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),y.CUSTOM_ELEMENT_HANDLING&&typeof y.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(oe.allowCustomizedBuiltInElements=y.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),vn&&(Gt=!1),Ur&&(bn=!0),Sn&&(J=ne({},Wl),fe=[],Sn.html===!0&&(ne(J,Hl),ne(fe,$l)),Sn.svg===!0&&(ne(J,Us),ne(fe,Vs),ne(fe,Xi)),Sn.svgFilters===!0&&(ne(J,zs),ne(fe,Vs),ne(fe,Xi)),Sn.mathMl===!0&&(ne(J,Ls),ne(fe,Xl),ne(fe,Xi))),y.ADD_TAGS&&(J===ge&&(J=St(J)),ne(J,y.ADD_TAGS,Ee)),y.ADD_ATTR&&(fe===Te&&(fe=St(fe)),ne(fe,y.ADD_ATTR,Ee)),y.ADD_URI_SAFE_ATTR&&ne(No,y.ADD_URI_SAFE_ATTR,Ee),y.FORBID_CONTENTS&&(Tn===Bu&&(Tn=St(Tn)),ne(Tn,y.FORBID_CONTENTS,Ee)),Fo&&(J["#text"]=!0),en&&ne(J,["html","head","body"]),J.table&&(ne(J,["tbody"]),delete We.tbody),y.TRUSTED_TYPES_POLICY){if(typeof y.TRUSTED_TYPES_POLICY.createHTML!="function")throw Xn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof y.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Xn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');x=y.TRUSTED_TYPES_POLICY,R=x.createHTML("")}else x===void 0&&(x=tx(d,r)),x!==null&&typeof R=="string"&&(R=x.createHTML(""));ze&&ze(y),An=y}},Hu=ne({},[...Us,...zs,...$_]),Wu=ne({},[...Ls,...X_]),nb=function(y){let F=E(y);(!F||!F.tagName)&&(F={namespaceURI:wn,tagName:"template"});const X=$i(y.tagName),_e=$i(F.tagName);return Bo[y.namespaceURI]?y.namespaceURI===Vr?F.namespaceURI===Pt?X==="svg":F.namespaceURI===Lr?X==="svg"&&(_e==="annotation-xml"||Hr[_e]):!!Hu[X]:y.namespaceURI===Lr?F.namespaceURI===Pt?X==="math":F.namespaceURI===Vr?X==="math"&&Wr[_e]:!!Wu[X]:y.namespaceURI===Pt?F.namespaceURI===Vr&&!Wr[_e]||F.namespaceURI===Lr&&!Hr[_e]?!1:!Wu[X]&&(Jv[X]||!Hu[X]):!!(oi==="application/xhtml+xml"&&Bo[y.namespaceURI]):!1},xt=function(y){Wn(e.removed,{element:y});try{E(y).removeChild(y)}catch{P(y)}},Cn=function(y,F){try{Wn(e.removed,{attribute:F.getAttributeNode(y),from:F})}catch{Wn(e.removed,{attribute:null,from:F})}if(F.removeAttribute(y),y==="is")if(bn||Ur)try{xt(F)}catch{}else try{F.setAttribute(y,"")}catch{}},$u=function(y){let F=null,X=null;if(Mo)y="<remove></remove>"+y;else{const Ie=Vl(y,/^[\r\n\t ]+/);X=Ie&&Ie[0]}oi==="application/xhtml+xml"&&wn===Pt&&(y='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+y+"</body></html>");const _e=x?x.createHTML(y):y;if(wn===Pt)try{F=new h().parseFromString(_e,oi)}catch{}if(!F||!F.documentElement){F=N.createDocument(wn,"template",null);try{F.documentElement.innerHTML=Oo?R:_e}catch{}}const Oe=F.body||F.documentElement;return y&&X&&Oe.insertBefore(t.createTextNode(X),Oe.childNodes[0]||null),wn===Pt?q.call(F,en?"html":"body")[0]:en?F.documentElement:Oe},Xu=function(y){return U.call(y.ownerDocument||y,y,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},zo=function(y){return y instanceof f&&(typeof y.nodeName!="string"||typeof y.textContent!="string"||typeof y.removeChild!="function"||!(y.attributes instanceof u)||typeof y.removeAttribute!="function"||typeof y.setAttribute!="function"||typeof y.namespaceURI!="string"||typeof y.insertBefore!="function"||typeof y.hasChildNodes!="function")},Yu=function(y){return typeof a=="function"&&y instanceof a};function Et(Y,y,F){Wi(Y,X=>{X.call(e,y,F,An)})}const qu=function(y){let F=null;if(Et(B.beforeSanitizeElements,y,null),zo(y))return xt(y),!0;const X=Ee(y.nodeName);if(Et(B.uponSanitizeElement,y,{tagName:X,allowedTags:J}),Br&&y.hasChildNodes()&&!Yu(y.firstElementChild)&&Le(/<[/\w!]/g,y.innerHTML)&&Le(/<[/\w!]/g,y.textContent)||y.nodeType===qn.progressingInstruction||Br&&y.nodeType===qn.comment&&Le(/<[/\w]/g,y.data))return xt(y),!0;if(!J[X]||We[X]){if(!We[X]&&Ku(X)&&(oe.tagNameCheck instanceof RegExp&&Le(oe.tagNameCheck,X)||oe.tagNameCheck instanceof Function&&oe.tagNameCheck(X)))return!1;if(Fo&&!Tn[X]){const _e=E(y)||y.parentNode,Oe=O(y)||y.childNodes;if(Oe&&_e){const Ie=Oe.length;for(let Ye=Ie-1;Ye>=0;--Ye){const Rt=I(Oe[Ye],!0);Rt.__removalCount=(y.__removalCount||0)+1,_e.insertBefore(Rt,A(y))}}}return xt(y),!0}return y instanceof l&&!nb(y)||(X==="noscript"||X==="noembed"||X==="noframes")&&Le(/<\/no(script|embed|frames)/i,y.innerHTML)?(xt(y),!0):(vn&&y.nodeType===qn.text&&(F=y.textContent,Wi([de,se,C],_e=>{F=$n(F,_e," ")}),y.textContent!==F&&(Wn(e.removed,{element:y.cloneNode()}),y.textContent=F)),Et(B.afterSanitizeElements,y,null),!1)},ju=function(y,F,X){if(Nu&&(F==="id"||F==="name")&&(X in t||X in tb))return!1;if(!(Gt&&!$e[F]&&Le(H,F))){if(!(nt&&Le(M,F))){if(!fe[F]||$e[F]){if(!(Ku(y)&&(oe.tagNameCheck instanceof RegExp&&Le(oe.tagNameCheck,y)||oe.tagNameCheck instanceof Function&&oe.tagNameCheck(y))&&(oe.attributeNameCheck instanceof RegExp&&Le(oe.attributeNameCheck,F)||oe.attributeNameCheck instanceof Function&&oe.attributeNameCheck(F))||F==="is"&&oe.allowCustomizedBuiltInElements&&(oe.tagNameCheck instanceof RegExp&&Le(oe.tagNameCheck,X)||oe.tagNameCheck instanceof Function&&oe.tagNameCheck(X))))return!1}else if(!No[F]){if(!Le(ee,$n(X,Z,""))){if(!((F==="src"||F==="xlink:href"||F==="href")&&y!=="script"&&L_(X,"data:")===0&&Uu[y])){if(!(Mu&&!Le($,$n(X,Z,"")))){if(X)return!1}}}}}}return!0},Ku=function(y){return y!=="annotation-xml"&&Vl(y,j)},Zu=function(y){Et(B.beforeSanitizeAttributes,y,null);const{attributes:F}=y;if(!F||zo(y))return;const X={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:fe,forceKeepAttr:void 0};let _e=F.length;for(;_e--;){const Oe=F[_e],{name:Ie,namespaceURI:Ye,value:Rt}=Oe,ai=Ee(Ie),Lo=Rt;let Be=Ie==="value"?Lo:V_(Lo);if(X.attrName=ai,X.attrValue=Be,X.keepAttr=!0,X.forceKeepAttr=void 0,Et(B.uponSanitizeAttribute,y,X),Be=X.attrValue,Ou&&(ai==="id"||ai==="name")&&(Cn(Ie,y),Be=Zv+Be),Br&&Le(/((--!?|])>)|<\/(style|title)/i,Be)){Cn(Ie,y);continue}if(X.forceKeepAttr)continue;if(!X.keepAttr){Cn(Ie,y);continue}if(!Fu&&Le(/\/>/i,Be)){Cn(Ie,y);continue}vn&&Wi([de,se,C],Ju=>{Be=$n(Be,Ju," ")});const Qu=Ee(y.nodeName);if(!ju(Qu,ai,Be)){Cn(Ie,y);continue}if(x&&typeof d=="object"&&typeof d.getAttributeType=="function"&&!Ye)switch(d.getAttributeType(Qu,ai)){case"TrustedHTML":{Be=x.createHTML(Be);break}case"TrustedScriptURL":{Be=x.createScriptURL(Be);break}}if(Be!==Lo)try{Ye?y.setAttributeNS(Ye,Ie,Be):y.setAttribute(Ie,Be),zo(y)?xt(y):Ll(e.removed)}catch{Cn(Ie,y)}}Et(B.afterSanitizeAttributes,y,null)},ib=function Y(y){let F=null;const X=Xu(y);for(Et(B.beforeSanitizeShadowDOM,y,null);F=X.nextNode();)Et(B.uponSanitizeShadowNode,F,null),qu(F),Zu(F),F.content instanceof s&&Y(F.content);Et(B.afterSanitizeShadowDOM,y,null)};return e.sanitize=function(Y){let y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},F=null,X=null,_e=null,Oe=null;if(Oo=!Y,Oo&&(Y="<!-->"),typeof Y!="string"&&!Yu(Y))if(typeof Y.toString=="function"){if(Y=Y.toString(),typeof Y!="string")throw Xn("dirty is not a string, aborting")}else throw Xn("toString is not a function");if(!e.isSupported)return Y;if(Do||Uo(y),e.removed=[],typeof Y=="string"&&(si=!1),si){if(Y.nodeName){const Rt=Ee(Y.nodeName);if(!J[Rt]||We[Rt])throw Xn("root node is forbidden and cannot be sanitized in-place")}}else if(Y instanceof a)F=$u("<!---->"),X=F.ownerDocument.importNode(Y,!0),X.nodeType===qn.element&&X.nodeName==="BODY"||X.nodeName==="HTML"?F=X:F.appendChild(X);else{if(!bn&&!vn&&!en&&Y.indexOf("<")===-1)return x&&zr?x.createHTML(Y):Y;if(F=$u(Y),!F)return bn?null:zr?R:""}F&&Mo&&xt(F.firstChild);const Ie=Xu(si?Y:F);for(;_e=Ie.nextNode();)qu(_e),Zu(_e),_e.content instanceof s&&ib(_e.content);if(si)return Y;if(bn){if(Ur)for(Oe=W.call(F.ownerDocument);F.firstChild;)Oe.appendChild(F.firstChild);else Oe=F;return(fe.shadowroot||fe.shadowrootmode)&&(Oe=G.call(i,Oe,!0)),Oe}let Ye=en?F.outerHTML:F.innerHTML;return en&&J["!doctype"]&&F.ownerDocument&&F.ownerDocument.doctype&&F.ownerDocument.doctype.name&&Le(ql,F.ownerDocument.doctype.name)&&(Ye="<!DOCTYPE "+F.ownerDocument.doctype.name+`>
13
- `+Ye),vn&&Wi([de,se,C],Rt=>{Ye=$n(Ye,Rt," ")}),x&&zr?x.createHTML(Ye):Ye},e.setConfig=function(){let Y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Uo(Y),Do=!0},e.clearConfig=function(){An=null,Do=!1},e.isValidAttribute=function(Y,y,F){An||Uo({});const X=Ee(Y),_e=Ee(y);return ju(X,_e,F)},e.addHook=function(Y,y){typeof y=="function"&&Wn(B[Y],y)},e.removeHook=function(Y,y){if(y!==void 0){const F=U_(B[Y],y);return F===-1?void 0:z_(B[Y],F,1)[0]}return Ll(B[Y])},e.removeHooks=function(Y){B[Y]=[]},e.removeAllHooks=function(){B=Kl()},e}var nx=Zl();function Yi(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function ix(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function Ql(n){let e,t,i;n.length!==2?(e=Yi,t=(a,l)=>Yi(n(a),l),i=(a,l)=>n(a)-l):(e=n===Yi||n===ix?n:rx,t=n,i=n);function r(a,l,c=0,u=a.length){if(c<u){if(e(l,l)!==0)return u;do{const f=c+u>>>1;t(a[f],l)<0?c=f+1:u=f}while(c<u)}return c}function s(a,l,c=0,u=a.length){if(c<u){if(e(l,l)!==0)return u;do{const f=c+u>>>1;t(a[f],l)<=0?c=f+1:u=f}while(c<u)}return c}function o(a,l,c=0,u=a.length){const f=r(a,l,c,u-1);return f>c&&i(a[f-1],l)>-i(a[f],l)?f-1:f}return{left:r,center:o,right:s}}function rx(){return 0}function sx(n){return n===null?NaN:+n}const ox=Ql(Yi).right;Ql(sx).center;var Hs=Math.sqrt(50),Ws=Math.sqrt(10),$s=Math.sqrt(2);function ax(n,e,t){var i,r=-1,s,o,a;if(e=+e,n=+n,t=+t,n===e&&t>0)return[n];if((i=e<n)&&(s=n,n=e,e=s),(a=Jl(n,e,t))===0||!isFinite(a))return[];if(a>0){let l=Math.round(n/a),c=Math.round(e/a);for(l*a<n&&++l,c*a>e&&--c,o=new Array(s=c-l+1);++r<s;)o[r]=(l+r)*a}else{a=-a;let l=Math.round(n*a),c=Math.round(e*a);for(l/a<n&&++l,c/a>e&&--c,o=new Array(s=c-l+1);++r<s;)o[r]=(l+r)/a}return i&&o.reverse(),o}function Jl(n,e,t){var i=(e-n)/Math.max(0,t),r=Math.floor(Math.log(i)/Math.LN10),s=i/Math.pow(10,r);return r>=0?(s>=Hs?10:s>=Ws?5:s>=$s?2:1)*Math.pow(10,r):-Math.pow(10,-r)/(s>=Hs?10:s>=Ws?5:s>=$s?2:1)}function lx(n,e,t){var i=Math.abs(e-n)/Math.max(0,t),r=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),s=i/r;return s>=Hs?r*=10:s>=Ws?r*=5:s>=$s&&(r*=2),e<n?-r:r}function cx(n,e,t){n=+n,e=+e,t=(r=arguments.length)<2?(e=n,n=0,1):r<3?1:+t;for(var i=-1,r=Math.max(0,Math.ceil((e-n)/t))|0,s=new Array(r);++i<r;)s[i]=n+i*t;return s}function Gl(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function ux(n){return function(){return n}}function fx(n){return+n}var ec=[0,1];function mt(n){return n}function Xs(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:ux(isNaN(e)?NaN:.5)}function hx(n,e){var t;return n>e&&(t=n,n=e,e=t),function(i){return Math.max(n,Math.min(e,i))}}function dx(n,e,t){var i=n[0],r=n[1],s=e[0],o=e[1];return r<i?(i=Xs(r,i),s=t(o,s)):(i=Xs(i,r),s=t(s,o)),function(a){return s(i(a))}}function px(n,e,t){var i=Math.min(n.length,e.length)-1,r=new Array(i),s=new Array(i),o=-1;for(n[i]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++o<i;)r[o]=Xs(n[o],n[o+1]),s[o]=t(e[o],e[o+1]);return function(a){var l=ox(n,a,1,i)-1;return s[l](r[l](a))}}function tc(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function nc(){var n=ec,e=ec,t=is,i,r,s,o=mt,a,l,c;function u(){var h=Math.min(n.length,e.length);return o!==mt&&(o=hx(n[0],n[h-1])),a=h>2?px:dx,l=c=null,f}function f(h){return h==null||isNaN(h=+h)?s:(l||(l=a(n.map(i),e,t)))(i(o(h)))}return f.invert=function(h){return o(r((c||(c=a(e,n.map(i),st)))(h)))},f.domain=function(h){return arguments.length?(n=Array.from(h,fx),u()):n.slice()},f.range=function(h){return arguments.length?(e=Array.from(h),u()):e.slice()},f.rangeRound=function(h){return e=Array.from(h),t=hd,u()},f.clamp=function(h){return arguments.length?(o=h?!0:mt,u()):o!==mt},f.interpolate=function(h){return arguments.length?(t=h,u()):t},f.unknown=function(h){return arguments.length?(s=h,f):s},function(h,d){return i=h,r=d,u()}}function mx(){return nc()(mt,mt)}function gx(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function qi(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,i=n.slice(0,t);return[i.length>1?i[0]+i.slice(2):i,+n.slice(t+1)]}function mn(n){return n=qi(Math.abs(n)),n?n[1]:NaN}function _x(n,e){return function(t,i){for(var r=t.length,s=[],o=0,a=n[0],l=0;r>0&&a>0&&(l+a+1>i&&(a=Math.max(1,i-l)),s.push(t.substring(r-=a,r+a)),!((l+=a+1)>i));)a=n[o=(o+1)%n.length];return s.reverse().join(e)}}function xx(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var yx=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function ji(n){if(!(e=yx.exec(n)))throw new Error("invalid format: "+n);var e;return new Ys({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}ji.prototype=Ys.prototype;function Ys(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}Ys.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function vx(n){e:for(var e=n.length,t=1,i=-1,r;t<e;++t)switch(n[t]){case".":i=r=t;break;case"0":i===0&&(i=t),r=t;break;default:if(!+n[t])break e;i>0&&(i=0);break}return i>0?n.slice(0,i)+n.slice(r+1):n}var ic;function bx(n,e){var t=qi(n,e);if(!t)return n+"";var i=t[0],r=t[1],s=r-(ic=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,o=i.length;return s===o?i:s>o?i+new Array(s-o+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+qi(n,Math.max(0,e+s-1))[0]}function rc(n,e){var t=qi(n,e);if(!t)return n+"";var i=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}const sc={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:gx,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>rc(n*100,e),r:rc,s:bx,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function oc(n){return n}var ac=Array.prototype.map,lc=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Sx(n){var e=n.grouping===void 0||n.thousands===void 0?oc:_x(ac.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",i=n.currency===void 0?"":n.currency[1]+"",r=n.decimal===void 0?".":n.decimal+"",s=n.numerals===void 0?oc:xx(ac.call(n.numerals,String)),o=n.percent===void 0?"%":n.percent+"",a=n.minus===void 0?"−":n.minus+"",l=n.nan===void 0?"NaN":n.nan+"";function c(f){f=ji(f);var h=f.fill,d=f.align,_=f.sign,I=f.symbol,P=f.zero,A=f.width,O=f.comma,E=f.precision,x=f.trim,R=f.type;R==="n"?(O=!0,R="g"):sc[R]||(E===void 0&&(E=12),x=!0,R="g"),(P||h==="0"&&d==="=")&&(P=!0,h="0",d="=");var N=I==="$"?t:I==="#"&&/[boxX]/.test(R)?"0"+R.toLowerCase():"",U=I==="$"?i:/[%p]/.test(R)?o:"",W=sc[R],q=/[defgprs%]/.test(R);E=E===void 0?6:/[gprs]/.test(R)?Math.max(1,Math.min(21,E)):Math.max(0,Math.min(20,E));function G(B){var de=N,se=U,C,H,M;if(R==="c")se=W(B)+se,B="";else{B=+B;var $=B<0||1/B<0;if(B=isNaN(B)?l:W(Math.abs(B),E),x&&(B=vx(B)),$&&+B==0&&_!=="+"&&($=!1),de=($?_==="("?_:a:_==="-"||_==="("?"":_)+de,se=(R==="s"?lc[8+ic/3]:"")+se+($&&_==="("?")":""),q){for(C=-1,H=B.length;++C<H;)if(M=B.charCodeAt(C),48>M||M>57){se=(M===46?r+B.slice(C+1):B.slice(C))+se,B=B.slice(0,C);break}}}O&&!P&&(B=e(B,1/0));var Z=de.length+B.length+se.length,j=Z<A?new Array(A-Z+1).join(h):"";switch(O&&P&&(B=e(j+B,j.length?A-se.length:1/0),j=""),d){case"<":B=de+B+se+j;break;case"=":B=de+j+B+se;break;case"^":B=j.slice(0,Z=j.length>>1)+de+B+se+j.slice(Z);break;default:B=j+de+B+se;break}return s(B)}return G.toString=function(){return f+""},G}function u(f,h){var d=c((f=ji(f),f.type="f",f)),_=Math.max(-8,Math.min(8,Math.floor(mn(h)/3)))*3,I=Math.pow(10,-_),P=lc[8+_/3];return function(A){return d(I*A)+P}}return{format:c,formatPrefix:u}}var Ki,cc,uc;Tx({thousands:",",grouping:[3],currency:["$",""]});function Tx(n){return Ki=Sx(n),cc=Ki.format,uc=Ki.formatPrefix,Ki}function wx(n){return Math.max(0,-mn(Math.abs(n)))}function Ax(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(mn(e)/3)))*3-mn(Math.abs(n)))}function Cx(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,mn(e)-mn(n))+1}function Ix(n,e,t,i){var r=lx(n,e,t),s;switch(i=ji(i??",f"),i.type){case"s":{var o=Math.max(Math.abs(n),Math.abs(e));return i.precision==null&&!isNaN(s=Ax(r,o))&&(i.precision=s),uc(i,o)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(s=Cx(r,Math.max(Math.abs(n),Math.abs(e))))&&(i.precision=s-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(s=wx(r))&&(i.precision=s-(i.type==="%")*2);break}}return cc(i)}function fc(n){var e=n.domain;return n.ticks=function(t){var i=e();return ax(i[0],i[i.length-1],t??10)},n.tickFormat=function(t,i){var r=e();return Ix(r[0],r[r.length-1],t??10,i)},n.nice=function(t){t==null&&(t=10);var i=e(),r=0,s=i.length-1,o=i[r],a=i[s],l,c,u=10;for(a<o&&(c=o,o=a,a=c,c=r,r=s,s=c);u-- >0;){if(c=Jl(o,a,t),c===l)return i[r]=o,i[s]=a,e(i);if(c>0)o=Math.floor(o/c)*c,a=Math.ceil(a/c)*c;else if(c<0)o=Math.ceil(o*c)/c,a=Math.floor(a*c)/c;else break;l=c}return n},n}function qs(){var n=mx();return n.copy=function(){return tc(n,qs())},Gl.apply(n,arguments),fc(n)}function hc(n){return function(e){return e<0?-Math.pow(-e,n):Math.pow(e,n)}}function Px(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)}function Ex(n){return n<0?-n*n:n*n}function Rx(n){var e=n(mt,mt),t=1;function i(){return t===1?n(mt,mt):t===.5?n(Px,Ex):n(hc(t),hc(1/t))}return e.exponent=function(r){return arguments.length?(t=+r,i()):t},fc(e)}function dc(){var n=Rx(nc());return n.copy=function(){return tc(n,dc()).exponent(n.exponent())},Gl.apply(n,arguments),n}var pc=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var n=0,e=arguments.length;e--;)n+=arguments[e]*arguments[e];return Math.sqrt(n)});function kx(){var n=new pc(9);return pc!=Float32Array&&(n[1]=0,n[2]=0,n[3]=0,n[5]=0,n[6]=0,n[7]=0),n[0]=1,n[4]=1,n[8]=1,n}function mc(n,e,t){var i=e[0],r=e[1],s=e[2],o=e[3],a=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=t[0],d=t[1];return n[0]=i,n[1]=r,n[2]=s,n[3]=o,n[4]=a,n[5]=l,n[6]=h*i+d*o+c,n[7]=h*r+d*a+u,n[8]=h*s+d*l+f,n}function js(n,e,t){var i=t[0],r=t[1];return n[0]=i*e[0],n[1]=i*e[1],n[2]=i*e[2],n[3]=r*e[3],n[4]=r*e[4],n[5]=r*e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n}function Dx(n,e,t){return n[0]=2/e,n[1]=0,n[2]=0,n[3]=0,n[4]=-2/t,n[5]=0,n[6]=-1,n[7]=1,n[8]=1,n}function Mx(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function Fx(n){if(Object.prototype.hasOwnProperty.call(n,"__esModule"))return n;var e=n.default;if(typeof e=="function"){var t=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(i){var r=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return n[i]}})}),t}var Zi={exports:{}},Nx=Zi.exports,gc;function Ox(){return gc||(gc=1,function(n){(function(e,t,i){function r(l){var c=this,u=a();c.next=function(){var f=2091639*c.s0+c.c*23283064365386963e-26;return c.s0=c.s1,c.s1=c.s2,c.s2=f-(c.c=f|0)},c.c=1,c.s0=u(" "),c.s1=u(" "),c.s2=u(" "),c.s0-=u(l),c.s0<0&&(c.s0+=1),c.s1-=u(l),c.s1<0&&(c.s1+=1),c.s2-=u(l),c.s2<0&&(c.s2+=1),u=null}function s(l,c){return c.c=l.c,c.s0=l.s0,c.s1=l.s1,c.s2=l.s2,c}function o(l,c){var u=new r(l),f=c&&c.state,h=u.next;return h.int32=function(){return u.next()*4294967296|0},h.double=function(){return h()+(h()*2097152|0)*11102230246251565e-32},h.quick=h,f&&(typeof f=="object"&&s(f,u),h.state=function(){return s(u,{})}),h}function a(){var l=4022871197,c=function(u){u=String(u);for(var f=0;f<u.length;f++){l+=u.charCodeAt(f);var h=.02519603282416938*l;l=h>>>0,h-=l,h*=l,l=h>>>0,h-=l,l+=h*4294967296}return(l>>>0)*23283064365386963e-26};return c}t&&t.exports?t.exports=o:this.alea=o})(Nx,n)}(Zi)),Zi.exports}var Qi={exports:{}},Bx=Qi.exports,_c;function Ux(){return _c||(_c=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.x=0,l.y=0,l.z=0,l.w=0,l.next=function(){var f=l.x^l.x<<11;return l.x=l.y,l.y=l.z,l.z=l.w,l.w^=l.w>>>19^f^f>>>8},a===(a|0)?l.x=a:c+=a;for(var u=0;u<c.length+64;u++)l.x^=c.charCodeAt(u)|0,l.next()}function s(a,l){return l.x=a.x,l.y=a.y,l.z=a.z,l.w=a.w,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xor128=o})(Bx,n)}(Qi)),Qi.exports}var Ji={exports:{}},zx=Ji.exports,xc;function Lx(){return xc||(xc=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.next=function(){var f=l.x^l.x>>>2;return l.x=l.y,l.y=l.z,l.z=l.w,l.w=l.v,(l.d=l.d+362437|0)+(l.v=l.v^l.v<<4^(f^f<<1))|0},l.x=0,l.y=0,l.z=0,l.w=0,l.v=0,a===(a|0)?l.x=a:c+=a;for(var u=0;u<c.length+64;u++)l.x^=c.charCodeAt(u)|0,u==c.length&&(l.d=l.x<<10^l.x>>>4),l.next()}function s(a,l){return l.x=a.x,l.y=a.y,l.z=a.z,l.w=a.w,l.v=a.v,l.d=a.d,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xorwow=o})(zx,n)}(Ji)),Ji.exports}var Gi={exports:{}},Vx=Gi.exports,yc;function Hx(){return yc||(yc=1,function(n){(function(e,t,i){function r(a){var l=this;l.next=function(){var u=l.x,f=l.i,h,d;return h=u[f],h^=h>>>7,d=h^h<<24,h=u[f+1&7],d^=h^h>>>10,h=u[f+3&7],d^=h^h>>>3,h=u[f+4&7],d^=h^h<<7,h=u[f+7&7],h=h^h<<13,d^=h^h<<9,u[f]=d,l.i=f+1&7,d};function c(u,f){var h,d=[];if(f===(f|0))d[0]=f;else for(f=""+f,h=0;h<f.length;++h)d[h&7]=d[h&7]<<15^f.charCodeAt(h)+d[h+1&7]<<13;for(;d.length<8;)d.push(0);for(h=0;h<8&&d[h]===0;++h);for(h==8?d[7]=-1:d[h],u.x=d,u.i=0,h=256;h>0;--h)u.next()}c(l,a)}function s(a,l){return l.x=a.x.slice(),l.i=a.i,l}function o(a,l){a==null&&(a=+new Date);var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(u.x&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xorshift7=o})(Vx,n)}(Gi)),Gi.exports}var er={exports:{}},Wx=er.exports,vc;function $x(){return vc||(vc=1,function(n){(function(e,t,i){function r(a){var l=this;l.next=function(){var u=l.w,f=l.X,h=l.i,d,_;return l.w=u=u+1640531527|0,_=f[h+34&127],d=f[h=h+1&127],_^=_<<13,d^=d<<17,_^=_>>>15,d^=d>>>12,_=f[h]=_^d,l.i=h,_+(u^u>>>16)|0};function c(u,f){var h,d,_,I,P,A=[],O=128;for(f===(f|0)?(d=f,f=null):(f=f+"\0",d=0,O=Math.max(O,f.length)),_=0,I=-32;I<O;++I)f&&(d^=f.charCodeAt((I+32)%f.length)),I===0&&(P=d),d^=d<<10,d^=d>>>15,d^=d<<4,d^=d>>>13,I>=0&&(P=P+1640531527|0,h=A[I&127]^=d+P,_=h==0?_+1:0);for(_>=128&&(A[(f&&f.length||0)&127]=-1),_=127,I=4*128;I>0;--I)d=A[_+34&127],h=A[_=_+1&127],d^=d<<13,h^=h<<17,d^=d>>>15,h^=h>>>12,A[_]=d^h;u.w=P,u.X=A,u.i=_}c(l,a)}function s(a,l){return l.i=a.i,l.w=a.w,l.X=a.X.slice(),l}function o(a,l){a==null&&(a=+new Date);var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(u.X&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xor4096=o})(Wx,n)}(er)),er.exports}var tr={exports:{}},Xx=tr.exports,bc;function Yx(){return bc||(bc=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.next=function(){var f=l.b,h=l.c,d=l.d,_=l.a;return f=f<<25^f>>>7^h,h=h-d|0,d=d<<24^d>>>8^_,_=_-f|0,l.b=f=f<<20^f>>>12^h,l.c=h=h-d|0,l.d=d<<16^h>>>16^_,l.a=_-f|0},l.a=0,l.b=0,l.c=-1640531527,l.d=1367130551,a===Math.floor(a)?(l.a=a/4294967296|0,l.b=a|0):c+=a;for(var u=0;u<c.length+20;u++)l.b^=c.charCodeAt(u)|0,l.next()}function s(a,l){return l.a=a.a,l.b=a.b,l.c=a.c,l.d=a.d,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.tychei=o})(Xx,n)}(tr)),tr.exports}var nr={exports:{}};const qx=Fx(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var jx=nr.exports,Sc;function Kx(){return Sc||(Sc=1,function(n){(function(e,t,i){var r=256,s=6,o=52,a="random",l=i.pow(r,s),c=i.pow(2,o),u=c*2,f=r-1,h;function d(x,R,N){var U=[];R=R==!0?{entropy:!0}:R||{};var W=A(P(R.entropy?[x,E(t)]:x??O(),3),U),q=new _(U),G=function(){for(var B=q.g(s),de=l,se=0;B<c;)B=(B+se)*r,de*=r,se=q.g(1);for(;B>=u;)B/=2,de/=2,se>>>=1;return(B+se)/de};return G.int32=function(){return q.g(4)|0},G.quick=function(){return q.g(4)/4294967296},G.double=G,A(E(q.S),t),(R.pass||N||function(B,de,se,C){return C&&(C.S&&I(C,q),B.state=function(){return I(q,{})}),se?(i[a]=B,de):B})(G,W,"global"in R?R.global:this==i,R.state)}function _(x){var R,N=x.length,U=this,W=0,q=U.i=U.j=0,G=U.S=[];for(N||(x=[N++]);W<r;)G[W]=W++;for(W=0;W<r;W++)G[W]=G[q=f&q+x[W%N]+(R=G[W])],G[q]=R;(U.g=function(B){for(var de,se=0,C=U.i,H=U.j,M=U.S;B--;)de=M[C=f&C+1],se=se*r+M[f&(M[C]=M[H=f&H+de])+(M[H]=de)];return U.i=C,U.j=H,se})(r)}function I(x,R){return R.i=x.i,R.j=x.j,R.S=x.S.slice(),R}function P(x,R){var N=[],U=typeof x,W;if(R&&U=="object")for(W in x)try{N.push(P(x[W],R-1))}catch{}return N.length?N:U=="string"?x:x+"\0"}function A(x,R){for(var N=x+"",U,W=0;W<N.length;)R[f&W]=f&(U^=R[f&W]*19)+N.charCodeAt(W++);return E(R)}function O(){try{var x;return h&&(x=h.randomBytes)?x=x(r):(x=new Uint8Array(r),(e.crypto||e.msCrypto).getRandomValues(x)),E(x)}catch{var R=e.navigator,N=R&&R.plugins;return[+new Date,e,N,e.screen,E(t)]}}function E(x){return String.fromCharCode.apply(0,x)}if(A(i.random(),t),n.exports){n.exports=d;try{h=qx}catch{}}else i["seed"+a]=d})(typeof self<"u"?self:jx,[],Math)}(nr)),nr.exports}var Ks,Tc;function Zx(){if(Tc)return Ks;Tc=1;var n=Ox(),e=Ux(),t=Lx(),i=Hx(),r=$x(),s=Yx(),o=Kx();return o.alea=n,o.xor128=e,o.xorwow=t,o.xorshift7=i,o.xor4096=r,o.tychei=s,Ks=o,Ks}var Qx=Zx();const Jx=Mx(Qx);function Gx(n,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,ty(i.key),i)}}function Zs(n,e,t){return e&&Gx(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),n}function wc(n,e){n.prototype=Object.create(e.prototype),n.prototype.constructor=n,Qs(n,e)}function Qs(n,e){return Qs=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,r){return i.__proto__=r,i},Qs(n,e)}function ey(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var i=t.call(n,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}function ty(n){var e=ey(n,"string");return typeof e=="symbol"?e:String(e)}var ir=function(){function n(){}var e=n.prototype;return e._seed=function(i,r){if(i===(i||0))return i;for(var s=""+i,o=0,a=0;a<s.length;++a)o^=s.charCodeAt(a)|0;return o},n}(),Ac=function(n){wc(e,n);function e(i,r){var s;return s=n.call(this)||this,s._rng=void 0,s.seed(i,r),s}var t=e.prototype;return t.next=function(){return this._rng()},t.seed=function(r,s){this._rng=r},t.clone=function(r,s){return new e(this._rng,s)},Zs(e,[{key:"name",get:function(){return"function"}}]),e}(ir),Cc=function(){var n=[].slice.call(arguments),e=n,t=e[0],i=t===void 0?"default":t;switch(typeof i){case"object":if(i instanceof ir)return i;break;case"function":return new Ac(i);case"number":case"string":default:return new Ac(Jx.apply(void 0,n))}throw new Error('invalid RNG "'+i+'"')},ny=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){return n.next()*(t-e)+e}};function at(n){return new iy(n)}var iy=function(e){var t=this;this.n=void 0,this.isInt=function(){if(Number.isInteger(t.n))return t;throw new Error("Expected number to be an integer, got "+t.n)},this.isPositive=function(){if(t.n>0)return t;throw new Error("Expected number to be positive, got "+t.n)},this.lessThan=function(i){if(t.n<i)return t;throw new Error("Expected number to be less than "+i+", got "+t.n)},this.greaterThanOrEqual=function(i){if(t.n>=i)return t;throw new Error("Expected number to be greater than or equal to "+i+", got "+t.n)},this.greaterThan=function(i){if(t.n>i)return t;throw new Error("Expected number to be greater than "+i+", got "+t.n)},this.n=e},ry=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),t===void 0&&(t=e===void 0?1:e,e=0),at(e).isInt(),at(t).isInt(),function(){return Math.floor(n.next()*(t-e+1)+e)}},sy=function(n){return function(){return n.next()>=.5}},oy=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){var i,r,s;do i=n.next()*2-1,r=n.next()*2-1,s=i*i+r*r;while(!s||s>1);return e+t*r*Math.sqrt(-2*Math.log(s)/s)}},ay=function(n,e,t){e===void 0&&(e=0),t===void 0&&(t=1);var i=n.normal(e,t);return function(){return Math.exp(i())}},ly=function(n,e){return e===void 0&&(e=.5),at(e).greaterThanOrEqual(0).lessThan(1),function(){return Math.floor(n.next()+e)}},cy=function(n,e,t){return e===void 0&&(e=1),t===void 0&&(t=.5),at(e).isInt().isPositive(),at(t).greaterThanOrEqual(0).lessThan(1),function(){for(var i=0,r=0;i++<e;)n.next()<t&&r++;return r}},uy=function(n,e){e===void 0&&(e=.5),at(e).greaterThan(0).lessThan(1);var t=1/Math.log(1-e);return function(){return Math.floor(1+Math.log(n.next())*t)}},fy=[0,0,.6931471805599453,1.791759469228055,3.1780538303479458,4.787491742782046,6.579251212010101,8.525161361065415,10.60460290274525,12.801827480081469],hy=function(e){return fy[e]},dy=.9189385332046727,py=function(n,e){if(e===void 0&&(e=1),at(e).isPositive(),e<10){var t=Math.exp(-e);return function(){for(var l=t,c=0,u=n.next();u>l;)u=u-l,l=e*l/++c;return c}}else{var i=Math.sqrt(e),r=.931+2.53*i,s=-.059+.02483*r,o=1.1239+1.1328/(r-3.4),a=.9277-3.6224/(r-2);return function(){for(;;){var l=void 0,c=n.next();if(c<=.86*a)return l=c/a-.43,Math.floor((2*s/(.5-Math.abs(l))+r)*l+e+.445);c>=a?l=n.next()-.5:(l=c/a-.93,l=(l<0?-.5:.5)-l,c=n.next()*a);var u=.5-Math.abs(l);if(!(u<.013&&c>u)){var f=Math.floor((2*s/u+r)*l+e+.445);if(c=c*o/(s/(u*u)+r),f>=10){var h=(f+.5)*Math.log(e/f)-e-dy+f-(.08333333333333333-(.002777777777777778-1/(1260*f*f))/(f*f))/f;if(Math.log(c*i)<=h)return f}else if(f>=0){var d,_=(d=hy(f))!=null?d:0;if(Math.log(c)<=f*Math.log(e)-e-_)return f}}}}}},my=function(n,e){return e===void 0&&(e=1),at(e).isPositive(),function(){return-Math.log(1-n.next())/e}},gy=function(n,e){return e===void 0&&(e=1),at(e).isInt().greaterThanOrEqual(0),function(){for(var t=0,i=0;i<e;++i)t+=n.next();return t}},_y=function(n,e){e===void 0&&(e=1),at(e).isInt().isPositive();var t=n.irwinHall(e);return function(){return t()/e}},xy=function(n,e){e===void 0&&(e=1),at(e).greaterThanOrEqual(0);var t=1/e;return function(){return 1/Math.pow(1-n.next(),t)}},yy=function(n){wc(e,n);function e(){return n.apply(this,arguments)||this}var t=e.prototype;return t.next=function(){return Math.random()},t.seed=function(r,s){},t.clone=function(){return new e},Zs(e,[{key:"name",get:function(){return"default"}}]),e}(ir),Ic=function(){function n(t){var i=this;this._rng=void 0,this._patch=void 0,this._cache={},this.next=function(){return i._rng.next()},this.float=function(r,s){return i.uniform(r,s)()},this.int=function(r,s){return i.uniformInt(r,s)()},this.integer=function(r,s){return i.uniformInt(r,s)()},this.bool=function(){return i.uniformBoolean()()},this.boolean=function(){return i.uniformBoolean()()},this.uniform=function(r,s){return i._memoize("uniform",ny,r,s)},this.uniformInt=function(r,s){return i._memoize("uniformInt",ry,r,s)},this.uniformBoolean=function(){return i._memoize("uniformBoolean",sy)},this.normal=function(r,s){return oy(i,r,s)},this.logNormal=function(r,s){return ay(i,r,s)},this.bernoulli=function(r){return ly(i,r)},this.binomial=function(r,s){return cy(i,r,s)},this.geometric=function(r){return uy(i,r)},this.poisson=function(r){return py(i,r)},this.exponential=function(r){return my(i,r)},this.irwinHall=function(r){return gy(i,r)},this.bates=function(r){return _y(i,r)},this.pareto=function(r){return xy(i,r)},t&&t instanceof ir?this.use(t):this.use(new yy),this._cache={}}var e=n.prototype;return e.clone=function(){var i=[].slice.call(arguments);return i.length?new n(Cc.apply(void 0,i)):new n(this.rng.clone())},e.use=function(){this._rng=Cc.apply(void 0,[].slice.call(arguments))},e.patch=function(){if(this._patch)throw new Error("Math.random already patched");this._patch=Math.random,Math.random=this.uniform()},e.unpatch=function(){this._patch&&(Math.random=this._patch,delete this._patch)},e.choice=function(i){if(!Array.isArray(i))throw new Error("Random.choice expected input to be an array, got "+typeof i);var r=i==null?void 0:i.length;if(r>0){var s=this.uniformInt(0,r-1)();return i[s]}else return},e._memoize=function(i,r){var s=[].slice.call(arguments,2),o=""+s.join(";"),a=this._cache[i];return(a===void 0||a.key!==o)&&(a={key:o,distribution:r.apply(void 0,[this].concat(s))},this._cache[i]=a),a.distribution},Zs(n,[{key:"rng",get:function(){return this._rng}}]),n}();new Ic;const Js=.001,rr=64,vy=4,Pc=2;class by{constructor(){this.pointsTextureSize=0,this.linksTextureSize=0,this.alpha=1,this.transform=kx(),this.screenSize=[0,0],this.mousePosition=[0,0],this.screenMousePosition=[0,0],this.selectedArea=[[0,0],[0,0]],this.isSimulationRunning=!1,this.simulationProgress=0,this.selectedIndices=null,this.maxPointSize=rr,this.hoveredPoint=void 0,this.focusedPoint=void 0,this.draggingPointIndex=void 0,this.hoveredLinkIndex=void 0,this.adjustedSpaceSize=V.spaceSize,this.isSpaceKeyPressed=!1,this.webglMaxTextureSize=16384,this.hoveredPointRingColor=[1,1,1,Fl],this.focusedPointRingColor=[1,1,1,Nl],this.hoveredLinkColor=[-1,-1,-1,-1],this.greyoutPointColor=[-1,-1,-1,-1],this.isDarkenGreyout=!1,this.isLinkHoveringEnabled=!1,this.alphaTarget=0,this.scalePointX=qs(),this.scalePointY=qs(),this.random=new Ic,this._backgroundColor=[0,0,0,0],this.alphaDecay=e=>1-Math.pow(Js,1/e)}get backgroundColor(){return this._backgroundColor}get transformationMatrix4x4(){const e=this.transform;if(e.length!==9)throw new Error(`Transform must be a 9-element array (3x3 matrix), got ${e.length} elements`);return[e[0],e[1],e[2],0,e[3],e[4],e[5],0,e[6],e[7],e[8],0,0,0,0,1]}set backgroundColor(e){this._backgroundColor=e;const t=Dc(e[0],e[1],e[2]);document.documentElement.style.setProperty("--cosmosgl-attribution-color",t>.65?"black":"white"),document.documentElement.style.setProperty("--cosmosgl-error-message-color",t>.65?"black":"white"),this.div&&(this.div.style.backgroundColor=`rgba(${e[0]*255}, ${e[1]*255}, ${e[2]*255}, ${e[3]})`),this.isDarkenGreyout=t<.65}addRandomSeed(e){this.random=this.random.clone(e)}getRandomFloat(e,t){return this.random.float(e,t)}adjustSpaceSize(e,t){(e<=0||!isFinite(e))&&(console.error(`Invalid spaceSize value: ${e}. Using default value of ${V.spaceSize}`),e=V.spaceSize);const i=2;if(e<i&&(console.warn(`spaceSize (${e}) is too small. Using minimum value of ${i}`),e=i),!Number.isFinite(t)||t<=0||t<i){console.warn(`Invalid webglMaxTextureSize: ${t}. Using configSpaceSize without WebGL limit adjustment.`),this.adjustedSpaceSize=e;return}e>=t?(this.adjustedSpaceSize=Math.max(t/2,i),console.warn(`The \`spaceSize\` has been reduced to ${this.adjustedSpaceSize} due to WebGL limits`)):this.adjustedSpaceSize=e}setWebGLMaxTextureSize(e){this.webglMaxTextureSize=e}updateScreenSize(e,t){const{adjustedSpaceSize:i}=this;this.screenSize=[e,t],this.scalePointX.domain([0,i]).range([(e-i)/2,(e+i)/2]),this.scalePointY.domain([i,0]).range([(t-i)/2,(t+i)/2])}scaleX(e){return this.scalePointX(e)}scaleY(e){return this.scalePointY(e)}setHoveredPointRingColor(e){const t=Tt(e);this.hoveredPointRingColor[0]=t[0],this.hoveredPointRingColor[1]=t[1],this.hoveredPointRingColor[2]=t[2]}setFocusedPointRingColor(e){const t=Tt(e);this.focusedPointRingColor[0]=t[0],this.focusedPointRingColor[1]=t[1],this.focusedPointRingColor[2]=t[2]}setGreyoutPointColor(e){if(e===void 0){this.greyoutPointColor=[-1,-1,-1,-1];return}const t=Tt(e);this.greyoutPointColor[0]=t[0],this.greyoutPointColor[1]=t[1],this.greyoutPointColor[2]=t[2],this.greyoutPointColor[3]=t[3]}updateLinkHoveringEnabled(e){this.isLinkHoveringEnabled=!!(e.onLinkClick||e.onLinkContextMenu||e.onLinkMouseOver||e.onLinkMouseOut),this.isLinkHoveringEnabled||(this.hoveredLinkIndex=void 0)}setHoveredLinkColor(e){if(e===void 0){this.hoveredLinkColor=[-1,-1,-1,-1];return}const t=Tt(e);this.hoveredLinkColor[0]=t[0],this.hoveredLinkColor[1]=t[1],this.hoveredLinkColor[2]=t[2],this.hoveredLinkColor[3]=t[3]}setFocusedPoint(e){e!==void 0?this.focusedPoint={index:e}:this.focusedPoint=void 0}addAlpha(e){return(this.alphaTarget-this.alpha)*this.alphaDecay(e)}}const Ec=n=>typeof n=="function",Gs=n=>Array.isArray(n),Rc=n=>n instanceof Object,kc=n=>n instanceof Object?n.constructor.name!=="Function"&&n.constructor.name!=="Object":!1,eo=n=>Rc(n)&&!Gs(n)&&!Ec(n)&&!kc(n);function Tt(n){let e;if(Gs(n))e=n;else{const t=kt(n),i=t==null?void 0:t.rgb();e=[(i==null?void 0:i.r)||0,(i==null?void 0:i.g)||0,(i==null?void 0:i.b)||0,(t==null?void 0:t.opacity)??1]}return[e[0]/255,e[1]/255,e[2]/255,e[3]]}function Dc(n,e,t){return .2126*n+.7152*e+.0722*t}function Me(n,e,t=0,i=0,r,s){return n.readPixelsToArrayWebGL(e,{sourceX:t,sourceY:i,sourceWidth:r,sourceHeight:s})}function to(n,e){switch(n.info.type){case"webgl":{const t=n.gl.getParameter($t.ALIASED_POINT_SIZE_RANGE);return((t==null?void 0:t[1])??rr)/e}case"webgpu":return rr/e;default:return rr/e}}function Mc(n,e,t){return Math.min(Math.max(n,e),t)}function Ke(n){return n!=null&&!Number.isNaN(n)}function Fc(n,e){return nx.sanitize(n,{ALLOWED_TAGS:["a","b","i","em","strong","span","div","p","br"],ALLOWED_ATTR:["href","target","class","id","style"],ALLOW_DATA_ATTR:!1,...e})}class Sy{constructor(){this.enableSimulation=V.enableSimulation,this.backgroundColor=Fs,this.spaceSize=V.spaceSize,this.pointDefaultColor=Cl,this.pointGreyoutOpacity=Il,this.pointGreyoutColor=Hi,this.pointDefaultSize=El,this.pointOpacity=Pl,this.pointSizeScale=V.pointSizeScale,this.hoveredPointCursor=V.hoveredPointCursor,this.hoveredLinkCursor=V.hoveredLinkCursor,this.renderHoveredPointRing=V.renderHoveredPointRing,this.hoveredPointRingColor=V.hoveredPointRingColor,this.focusedPointRingColor=V.focusedPointRingColor,this.focusedPointIndex=V.focusedPointIndex,this.linkDefaultColor=Rl,this.linkOpacity=Dl,this.linkGreyoutOpacity=kl,this.linkDefaultWidth=Ml,this.linkWidthScale=V.linkWidthScale,this.hoveredLinkColor=V.hoveredLinkColor,this.hoveredLinkWidthIncrease=V.hoveredLinkWidthIncrease,this.renderLinks=V.renderLinks,this.curvedLinks=V.curvedLinks,this.curvedLinkSegments=V.curvedLinkSegments,this.curvedLinkWeight=V.curvedLinkWeight,this.curvedLinkControlPointDistance=V.curvedLinkControlPointDistance,this.linkDefaultArrows=V.linkArrows,this.linkArrowsSizeScale=V.linkArrowsSizeScale,this.scaleLinksOnZoom=V.scaleLinksOnZoom,this.linkVisibilityDistanceRange=V.linkVisibilityDistanceRange,this.linkVisibilityMinTransparency=V.linkVisibilityMinTransparency,this.simulationDecay=V.simulation.decay,this.simulationGravity=V.simulation.gravity,this.simulationCenter=V.simulation.center,this.simulationRepulsion=V.simulation.repulsion,this.simulationRepulsionTheta=V.simulation.repulsionTheta,this.simulationLinkSpring=V.simulation.linkSpring,this.simulationLinkDistance=V.simulation.linkDistance,this.simulationLinkDistRandomVariationRange=V.simulation.linkDistRandomVariationRange,this.simulationRepulsionFromMouse=V.simulation.repulsionFromMouse,this.enableRightClickRepulsion=V.enableRightClickRepulsion,this.simulationFriction=V.simulation.friction,this.simulationCluster=V.simulation.cluster,this.onSimulationStart=void 0,this.onSimulationTick=void 0,this.onSimulationEnd=void 0,this.onSimulationPause=void 0,this.onSimulationUnpause=void 0,this.onClick=void 0,this.onPointClick=void 0,this.onLinkClick=void 0,this.onBackgroundClick=void 0,this.onContextMenu=void 0,this.onPointContextMenu=void 0,this.onLinkContextMenu=void 0,this.onBackgroundContextMenu=void 0,this.onMouseMove=void 0,this.onPointMouseOver=void 0,this.onPointMouseOut=void 0,this.onLinkMouseOver=void 0,this.onLinkMouseOut=void 0,this.onZoomStart=void 0,this.onZoom=void 0,this.onZoomEnd=void 0,this.onDragStart=void 0,this.onDrag=void 0,this.onDragEnd=void 0,this.showFPSMonitor=V.showFPSMonitor,this.pixelRatio=V.pixelRatio,this.scalePointsOnZoom=V.scalePointsOnZoom,this.initialZoomLevel=void 0,this.enableZoom=V.enableZoom,this.enableSimulationDuringZoom=V.enableSimulationDuringZoom,this.enableDrag=V.enableDrag,this.fitViewOnInit=V.fitViewOnInit,this.fitViewDelay=V.fitViewDelay,this.fitViewPadding=V.fitViewPadding,this.fitViewDuration=V.fitViewDuration,this.fitViewByPointsInRect=void 0,this.fitViewByPointIndices=void 0,this.randomSeed=void 0,this.pointSamplingDistance=V.pointSamplingDistance,this.linkSamplingDistance=V.linkSamplingDistance,this.attribution=V.attribution,this.rescalePositions=V.rescalePositions}init(e){Object.keys(e).forEach(t=>{this.deepMergeConfig(this.getConfig(),e,t)})}deepMergeConfig(e,t,i){eo(e[i])&&eo(t[i])?Object.keys(t[i]).forEach(r=>{this.deepMergeConfig(e[i],t[i],r)}):e[i]=t[i]}getConfig(){return this}}function no(n,e){if(!n)throw new Error(e||"shadertools: assertion failed.")}const io={number:{type:"number",validate(n,e){return Number.isFinite(n)&&typeof e=="object"&&(e.max===void 0||n<=e.max)&&(e.min===void 0||n>=e.min)}},array:{type:"array",validate(n,e){return Array.isArray(n)||ArrayBuffer.isView(n)}}};function Ty(n){const e={};for(const[t,i]of Object.entries(n))e[t]=wy(i);return e}function wy(n){let e=Nc(n);if(e!=="object")return{value:n,...io[e],type:e};if(typeof n=="object")return n?n.type!==void 0?{...n,...io[n.type],type:n.type}:n.value===void 0?{type:"object",value:n}:(e=Nc(n.value),{...n,...io[e],type:e}):{type:"object",value:null};throw new Error("props")}function Nc(n){return Array.isArray(n)||ArrayBuffer.isView(n)?"array":typeof n}const Ay={vertex:`#ifdef MODULE_LOGDEPTH
11
+ </pre></code>`,l.style.top="10px",l.style.left="10px",l.style.position="absolute",l.style.zIndex="9999",l.style.width="100%",l.style.textAlign="left",document.body.appendChild(l),(u=document.getElementsByClassName("luma-compiler-log-error")[0])==null||u.scrollIntoView(),l.onclick=()=>{const f=`data:text/plain,${encodeURIComponent(this.source)}`;navigator.clipboard.writeText(f)}}};m(wr,"defaultProps",{...ae.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});let Ni=wr;function dm(n){return pm(n.source)||n.id||Pi(`unnamed ${n.stage}-shader`)}function pm(n,e="unnamed"){const i=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(n);return i?i[1]:e}const Ar=class Ar extends ae{constructor(t,i={}){super(t,i,Ar.defaultProps);m(this,"width");m(this,"height");this.width=this.props.width,this.height=this.props.height}get[Symbol.toStringTag](){return"Framebuffer"}clone(t){const i=this.colorAttachments.map(s=>s.texture.clone(t)),r=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(t);return this.device.createFramebuffer({...this.props,colorAttachments:i,depthStencilAttachment:r})}resize(t){let i=!t;if(t){const[r,s]=Array.isArray(t)?t:[t.width,t.height];i=i||s!==this.height||r!==this.width,this.width=r,this.height=s}i&&(D.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((i,r)=>{if(typeof i=="string"){const s=this.createColorTexture(i,r);return this.attachResource(s),s.view}return i instanceof Q?i.view:i});const t=this.props.depthStencilAttachment;if(t)if(typeof t=="string"){const i=this.createDepthStencilTexture(t);this.attachResource(i),this.depthStencilAttachment=i.view}else t instanceof Q?this.depthStencilAttachment=t.view:this.depthStencilAttachment=t}createColorTexture(t,i){return this.device.createTexture({id:`${this.id}-color-attachment-${i}`,usage:Q.RENDER_ATTACHMENT,format:t,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(t){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:Q.RENDER_ATTACHMENT,format:t,width:this.width,height:this.height})}resizeAttachments(t,i){for(let r=0;r<this.colorAttachments.length;++r)if(this.colorAttachments[r]){const s=this.colorAttachments[r].texture.clone({width:t,height:i});this.destroyAttachedResource(this.colorAttachments[r]),this.colorAttachments[r]=s.view,this.attachResource(s.view)}if(this.depthStencilAttachment){const r=this.depthStencilAttachment.texture.clone({width:t,height:i});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=r.view,this.attachResource(r)}this.updateAttachments()}};m(Ar,"defaultProps",{...ae.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});let Oi=Ar;const Cr=class Cr extends ae{constructor(t,i){super(t,i,Cr.defaultProps);m(this,"shaderLayout");m(this,"bufferLayout");m(this,"linkStatus","pending");m(this,"hash","");this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[]}get[Symbol.toStringTag](){return"RenderPipeline"}};m(Cr,"defaultProps",{...ae.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",colorAttachmentFormats:void 0,depthStencilAttachmentFormat:void 0,parameters:{},bindings:{},uniforms:{}});let $t=Cr;const ct=class ct extends ae{get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){t=ct.normalizeProps(e,t),super(e,t,ct.defaultProps)}static normalizeProps(e,t){return t}};m(ct,"defaultClearColor",[0,0,0,1]),m(ct,"defaultClearDepth",1),m(ct,"defaultClearStencil",0),m(ct,"defaultProps",{...ae.defaultProps,framebuffer:null,parameters:void 0,clearColor:ct.defaultClearColor,clearColors:void 0,clearDepth:ct.defaultClearDepth,clearStencil:ct.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});let gs=ct;const Ir=class Ir extends ae{constructor(t,i){super(t,i,Ir.defaultProps);m(this,"hash","");m(this,"shaderLayout");this.shaderLayout=i.shaderLayout}get[Symbol.toStringTag](){return"ComputePipeline"}};m(Ir,"defaultProps",{...ae.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});let Bi=Ir;const Pr=class Pr extends ae{get[Symbol.toStringTag](){return"CommandEncoder"}constructor(e,t){super(e,t,Pr.defaultProps)}};m(Pr,"defaultProps",{...ae.defaultProps,measureExecutionTime:void 0});let _s=Pr;const Er=class Er extends ae{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Er.defaultProps)}};m(Er,"defaultProps",{...ae.defaultProps});let xs=Er;function Ja(n){return xm[n]}function mm(n){const[e,t]=_m[n],i=e==="i32"||e==="u32",r=e!=="u32",s=gm[e]*t;return{primitiveType:e,components:t,byteLength:s,integer:i,signed:r}}const gm={f32:4,f16:2,i32:4,u32:4},_m={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},xm={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}};function Ga(n,e){const t={};for(const i of n.attributes){const r=vm(n,e,i.name);r&&(t[i.name]=r)}return t}function ym(n,e,t=16){const i=Ga(n,e),r=new Array(t).fill(null);for(const s of Object.values(i))r[s.location]=s;return r}function vm(n,e,t){const i=bm(n,t),r=Sm(e,t);if(!i)return null;const s=mm(i.type),o=Up(s),a=(r==null?void 0:r.vertexFormat)||o,l=cs(a);return{attributeName:(r==null?void 0:r.attributeName)||i.name,bufferName:(r==null?void 0:r.bufferName)||i.name,location:i.location,shaderType:i.type,primitiveType:s.primitiveType,shaderComponents:s.components,vertexFormat:a,bufferDataType:l.type,bufferComponents:l.components,normalized:l.normalized,integer:s.integer,stepMode:(r==null?void 0:r.stepMode)||i.stepMode||"vertex",byteOffset:(r==null?void 0:r.byteOffset)||0,byteStride:(r==null?void 0:r.byteStride)||0}}function bm(n,e){const t=n.attributes.find(i=>i.name===e);return t||D.warn(`shader layout attribute "${e}" not present in shader`),t||null}function Sm(n,e){Tm(n);let t=wm(n,e);return t||(t=Am(n,e),t)?t:(D.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function Tm(n){for(const e of n)(e.attributes&&e.format||!e.attributes&&!e.format)&&D.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function wm(n,e){for(const t of n)if(t.format&&t.name===e)return{attributeName:t.name,bufferName:e,stepMode:t.stepMode,vertexFormat:t.format,byteOffset:0,byteStride:t.byteStride||0};return null}function Am(n,e){var t;for(const i of n){let r=i.byteStride;if(typeof i.byteStride!="number")for(const o of i.attributes||[]){const a=cs(o.format);r+=a.byteLength}const s=(t=i.attributes)==null?void 0:t.find(o=>o.attribute===e);if(s)return{attributeName:s.attribute,bufferName:i.name,stepMode:i.stepMode,vertexFormat:s.format,byteOffset:s.byteOffset,byteStride:r}}return null}const Rr=class Rr extends ae{constructor(t,i){super(t,i,Rr.defaultProps);m(this,"maxVertexAttributes");m(this,"attributeInfos");m(this,"indexBuffer",null);m(this,"attributes");this.maxVertexAttributes=t.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=ym(i.shaderLayout,i.bufferLayout,this.maxVertexAttributes)}get[Symbol.toStringTag](){return"VertexArray"}setConstantWebGL(t,i){this.device.reportError(new Error("constant attributes not supported"),this)()}};m(Rr,"defaultProps",{...ae.defaultProps,shaderLayout:void 0,bufferLayout:[]});let ys=Rr;const kr=class kr extends ae{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,kr.defaultProps)}};m(kr,"defaultProps",{...ae.defaultProps,layout:void 0,buffers:{}});let vs=kr;const Dr=class Dr extends ae{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,Dr.defaultProps)}};m(Dr,"defaultProps",{...ae.defaultProps,type:void 0,count:void 0});let bs=Dr,Ui;function el(n){return(!Ui||Ui.byteLength<n)&&(Ui=new ArrayBuffer(n)),Ui}function Cm(n,e){const t=el(n.BYTES_PER_ELEMENT*e);return new n(t,0,e)}function Im(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function zi(n){return Array.isArray(n)?n.length===0||typeof n[0]=="number":Im(n)}const Pm=1024;class Em{constructor(e,t={}){m(this,"layout",{});m(this,"byteLength");let i=0;for(const[s,o]of Object.entries(e)){const a=Ja(o),{type:l,components:c}=a,u=c*((t==null?void 0:t[s])??1);i=Np(i,u);const f=i;i+=u,this.layout[s]={type:l,size:u,offset:f}}i+=(4-i%4)%4;const r=i*4;this.byteLength=Math.max(r,Pm)}getData(e){const t=el(this.byteLength),i={i32:new Int32Array(t),u32:new Uint32Array(t),f32:new Float32Array(t),f16:new Uint16Array(t)};for(const[r,s]of Object.entries(e)){const o=this.layout[r];if(!o){D.warn(`Supplied uniform value ${r} not present in uniform block layout`)();continue}const{type:a,size:l,offset:c}=o,u=i[a];if(l===1){if(typeof s!="number"&&typeof s!="boolean"){D.warn(`Supplied value for single component uniform ${r} is not a number: ${s}`)();continue}u[c]=Number(s)}else{if(!zi(s)){D.warn(`Supplied value for multi component / array uniform ${r} is not a numeric array: ${s}`)();continue}u.set(s,c)}}return new Uint8Array(t,0,this.byteLength)}has(e){return!!this.layout[e]}get(e){return this.layout[e]}}function Rm(n,e,t=16){if(n!==e)return!1;const i=n,r=e;if(!zi(i))return!1;if(zi(r)&&i.length===r.length){for(let s=0;s<i.length;++s)if(r[s]!==i[s])return!1}return!0}function km(n){return zi(n)?n.slice():n}class Dm{constructor(e){m(this,"name");m(this,"uniforms",{});m(this,"modifiedUniforms",{});m(this,"modified",!0);m(this,"bindingLayout",{});m(this,"needsRedraw","initialized");var t;if(this.name=(e==null?void 0:e.name)||"unnamed",e!=null&&e.name&&(e!=null&&e.shaderLayout)){const i=(t=e==null?void 0:e.shaderLayout.bindings)==null?void 0:t.find(s=>s.type==="uniform"&&s.name===(e==null?void 0:e.name));if(!i)throw new Error(e==null?void 0:e.name);const r=i;for(const s of r.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(const[t,i]of Object.entries(e))this._setUniform(t,i),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${i}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){Rm(this.uniforms[e],t)||(this.uniforms[e]=km(t),this.modifiedUniforms[e]=!0,this.modified=!0)}}class _e{constructor(e){m(this,"uniformBlocks",new Map);m(this,"uniformBufferLayouts",new Map);m(this,"uniformBuffers",new Map);for(const[t,i]of Object.entries(e)){const r=t,s=new Em(i.uniformTypes??{},i.uniformSizes??{});this.uniformBufferLayouts.set(r,s);const o=new Dm({name:t});o.setUniforms(i.defaultUniforms||{}),this.uniformBlocks.set(r,o)}}destroy(){for(const e of this.uniformBuffers.values())e.destroy()}setUniforms(e){var t;for(const[i,r]of Object.entries(e))(t=this.uniformBlocks.get(i))==null||t.setUniforms(r);this.updateUniformBuffers()}getUniformBufferByteLength(e){var t;return((t=this.uniformBufferLayouts.get(e))==null?void 0:t.byteLength)||0}getUniformBufferData(e){var i,r;const t=((i=this.uniformBlocks.get(e))==null?void 0:i.getAllUniforms())||{};return(r=this.uniformBufferLayouts.get(e))==null?void 0:r.getData(t)}createUniformBuffer(e,t,i){i&&this.setUniforms(i);const r=this.getUniformBufferByteLength(t),s=e.createBuffer({usage:L.UNIFORM|L.COPY_DST,byteLength:r}),o=this.getUniformBufferData(t);return s.write(o),s}getManagedUniformBuffer(e,t){if(!this.uniformBuffers.get(t)){const i=this.getUniformBufferByteLength(t),r=e.createBuffer({usage:L.UNIFORM|L.COPY_DST,byteLength:i});this.uniformBuffers.set(t,r)}return this.uniformBuffers.get(t)}updateUniformBuffers(){let e=!1;for(const t of this.uniformBlocks.keys()){const i=this.updateUniformBuffer(t);e||(e=i)}return e&&D.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){var s;const t=this.uniformBlocks.get(e);let i=this.uniformBuffers.get(e),r=!1;if(i&&(t!=null&&t.needsRedraw)){r||(r=t.needsRedraw);const o=this.getUniformBufferData(e);i=this.uniformBuffers.get(e),i==null||i.write(o);const a=(s=this.uniformBlocks.get(e))==null?void 0:s.getAllUniforms();D.log(4,`Writing to uniform buffer ${String(e)}`,o,a)()}return r}}var Xt;(function(n){n[n.DEPTH_BUFFER_BIT=256]="DEPTH_BUFFER_BIT",n[n.STENCIL_BUFFER_BIT=1024]="STENCIL_BUFFER_BIT",n[n.COLOR_BUFFER_BIT=16384]="COLOR_BUFFER_BIT",n[n.POINTS=0]="POINTS",n[n.LINES=1]="LINES",n[n.LINE_LOOP=2]="LINE_LOOP",n[n.LINE_STRIP=3]="LINE_STRIP",n[n.TRIANGLES=4]="TRIANGLES",n[n.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",n[n.TRIANGLE_FAN=6]="TRIANGLE_FAN",n[n.ZERO=0]="ZERO",n[n.ONE=1]="ONE",n[n.SRC_COLOR=768]="SRC_COLOR",n[n.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",n[n.SRC_ALPHA=770]="SRC_ALPHA",n[n.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",n[n.DST_ALPHA=772]="DST_ALPHA",n[n.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",n[n.DST_COLOR=774]="DST_COLOR",n[n.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",n[n.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE",n[n.CONSTANT_COLOR=32769]="CONSTANT_COLOR",n[n.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",n[n.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",n[n.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",n[n.FUNC_ADD=32774]="FUNC_ADD",n[n.FUNC_SUBTRACT=32778]="FUNC_SUBTRACT",n[n.FUNC_REVERSE_SUBTRACT=32779]="FUNC_REVERSE_SUBTRACT",n[n.BLEND_EQUATION=32777]="BLEND_EQUATION",n[n.BLEND_EQUATION_RGB=32777]="BLEND_EQUATION_RGB",n[n.BLEND_EQUATION_ALPHA=34877]="BLEND_EQUATION_ALPHA",n[n.BLEND_DST_RGB=32968]="BLEND_DST_RGB",n[n.BLEND_SRC_RGB=32969]="BLEND_SRC_RGB",n[n.BLEND_DST_ALPHA=32970]="BLEND_DST_ALPHA",n[n.BLEND_SRC_ALPHA=32971]="BLEND_SRC_ALPHA",n[n.BLEND_COLOR=32773]="BLEND_COLOR",n[n.ARRAY_BUFFER_BINDING=34964]="ARRAY_BUFFER_BINDING",n[n.ELEMENT_ARRAY_BUFFER_BINDING=34965]="ELEMENT_ARRAY_BUFFER_BINDING",n[n.LINE_WIDTH=2849]="LINE_WIDTH",n[n.ALIASED_POINT_SIZE_RANGE=33901]="ALIASED_POINT_SIZE_RANGE",n[n.ALIASED_LINE_WIDTH_RANGE=33902]="ALIASED_LINE_WIDTH_RANGE",n[n.CULL_FACE_MODE=2885]="CULL_FACE_MODE",n[n.FRONT_FACE=2886]="FRONT_FACE",n[n.DEPTH_RANGE=2928]="DEPTH_RANGE",n[n.DEPTH_WRITEMASK=2930]="DEPTH_WRITEMASK",n[n.DEPTH_CLEAR_VALUE=2931]="DEPTH_CLEAR_VALUE",n[n.DEPTH_FUNC=2932]="DEPTH_FUNC",n[n.STENCIL_CLEAR_VALUE=2961]="STENCIL_CLEAR_VALUE",n[n.STENCIL_FUNC=2962]="STENCIL_FUNC",n[n.STENCIL_FAIL=2964]="STENCIL_FAIL",n[n.STENCIL_PASS_DEPTH_FAIL=2965]="STENCIL_PASS_DEPTH_FAIL",n[n.STENCIL_PASS_DEPTH_PASS=2966]="STENCIL_PASS_DEPTH_PASS",n[n.STENCIL_REF=2967]="STENCIL_REF",n[n.STENCIL_VALUE_MASK=2963]="STENCIL_VALUE_MASK",n[n.STENCIL_WRITEMASK=2968]="STENCIL_WRITEMASK",n[n.STENCIL_BACK_FUNC=34816]="STENCIL_BACK_FUNC",n[n.STENCIL_BACK_FAIL=34817]="STENCIL_BACK_FAIL",n[n.STENCIL_BACK_PASS_DEPTH_FAIL=34818]="STENCIL_BACK_PASS_DEPTH_FAIL",n[n.STENCIL_BACK_PASS_DEPTH_PASS=34819]="STENCIL_BACK_PASS_DEPTH_PASS",n[n.STENCIL_BACK_REF=36003]="STENCIL_BACK_REF",n[n.STENCIL_BACK_VALUE_MASK=36004]="STENCIL_BACK_VALUE_MASK",n[n.STENCIL_BACK_WRITEMASK=36005]="STENCIL_BACK_WRITEMASK",n[n.VIEWPORT=2978]="VIEWPORT",n[n.SCISSOR_BOX=3088]="SCISSOR_BOX",n[n.COLOR_CLEAR_VALUE=3106]="COLOR_CLEAR_VALUE",n[n.COLOR_WRITEMASK=3107]="COLOR_WRITEMASK",n[n.UNPACK_ALIGNMENT=3317]="UNPACK_ALIGNMENT",n[n.PACK_ALIGNMENT=3333]="PACK_ALIGNMENT",n[n.MAX_TEXTURE_SIZE=3379]="MAX_TEXTURE_SIZE",n[n.MAX_VIEWPORT_DIMS=3386]="MAX_VIEWPORT_DIMS",n[n.SUBPIXEL_BITS=3408]="SUBPIXEL_BITS",n[n.RED_BITS=3410]="RED_BITS",n[n.GREEN_BITS=3411]="GREEN_BITS",n[n.BLUE_BITS=3412]="BLUE_BITS",n[n.ALPHA_BITS=3413]="ALPHA_BITS",n[n.DEPTH_BITS=3414]="DEPTH_BITS",n[n.STENCIL_BITS=3415]="STENCIL_BITS",n[n.POLYGON_OFFSET_UNITS=10752]="POLYGON_OFFSET_UNITS",n[n.POLYGON_OFFSET_FACTOR=32824]="POLYGON_OFFSET_FACTOR",n[n.TEXTURE_BINDING_2D=32873]="TEXTURE_BINDING_2D",n[n.SAMPLE_BUFFERS=32936]="SAMPLE_BUFFERS",n[n.SAMPLES=32937]="SAMPLES",n[n.SAMPLE_COVERAGE_VALUE=32938]="SAMPLE_COVERAGE_VALUE",n[n.SAMPLE_COVERAGE_INVERT=32939]="SAMPLE_COVERAGE_INVERT",n[n.COMPRESSED_TEXTURE_FORMATS=34467]="COMPRESSED_TEXTURE_FORMATS",n[n.VENDOR=7936]="VENDOR",n[n.RENDERER=7937]="RENDERER",n[n.VERSION=7938]="VERSION",n[n.IMPLEMENTATION_COLOR_READ_TYPE=35738]="IMPLEMENTATION_COLOR_READ_TYPE",n[n.IMPLEMENTATION_COLOR_READ_FORMAT=35739]="IMPLEMENTATION_COLOR_READ_FORMAT",n[n.BROWSER_DEFAULT_WEBGL=37444]="BROWSER_DEFAULT_WEBGL",n[n.STATIC_DRAW=35044]="STATIC_DRAW",n[n.STREAM_DRAW=35040]="STREAM_DRAW",n[n.DYNAMIC_DRAW=35048]="DYNAMIC_DRAW",n[n.ARRAY_BUFFER=34962]="ARRAY_BUFFER",n[n.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",n[n.BUFFER_SIZE=34660]="BUFFER_SIZE",n[n.BUFFER_USAGE=34661]="BUFFER_USAGE",n[n.CURRENT_VERTEX_ATTRIB=34342]="CURRENT_VERTEX_ATTRIB",n[n.VERTEX_ATTRIB_ARRAY_ENABLED=34338]="VERTEX_ATTRIB_ARRAY_ENABLED",n[n.VERTEX_ATTRIB_ARRAY_SIZE=34339]="VERTEX_ATTRIB_ARRAY_SIZE",n[n.VERTEX_ATTRIB_ARRAY_STRIDE=34340]="VERTEX_ATTRIB_ARRAY_STRIDE",n[n.VERTEX_ATTRIB_ARRAY_TYPE=34341]="VERTEX_ATTRIB_ARRAY_TYPE",n[n.VERTEX_ATTRIB_ARRAY_NORMALIZED=34922]="VERTEX_ATTRIB_ARRAY_NORMALIZED",n[n.VERTEX_ATTRIB_ARRAY_POINTER=34373]="VERTEX_ATTRIB_ARRAY_POINTER",n[n.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING=34975]="VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",n[n.CULL_FACE=2884]="CULL_FACE",n[n.FRONT=1028]="FRONT",n[n.BACK=1029]="BACK",n[n.FRONT_AND_BACK=1032]="FRONT_AND_BACK",n[n.BLEND=3042]="BLEND",n[n.DEPTH_TEST=2929]="DEPTH_TEST",n[n.DITHER=3024]="DITHER",n[n.POLYGON_OFFSET_FILL=32823]="POLYGON_OFFSET_FILL",n[n.SAMPLE_ALPHA_TO_COVERAGE=32926]="SAMPLE_ALPHA_TO_COVERAGE",n[n.SAMPLE_COVERAGE=32928]="SAMPLE_COVERAGE",n[n.SCISSOR_TEST=3089]="SCISSOR_TEST",n[n.STENCIL_TEST=2960]="STENCIL_TEST",n[n.NO_ERROR=0]="NO_ERROR",n[n.INVALID_ENUM=1280]="INVALID_ENUM",n[n.INVALID_VALUE=1281]="INVALID_VALUE",n[n.INVALID_OPERATION=1282]="INVALID_OPERATION",n[n.OUT_OF_MEMORY=1285]="OUT_OF_MEMORY",n[n.CONTEXT_LOST_WEBGL=37442]="CONTEXT_LOST_WEBGL",n[n.CW=2304]="CW",n[n.CCW=2305]="CCW",n[n.DONT_CARE=4352]="DONT_CARE",n[n.FASTEST=4353]="FASTEST",n[n.NICEST=4354]="NICEST",n[n.GENERATE_MIPMAP_HINT=33170]="GENERATE_MIPMAP_HINT",n[n.BYTE=5120]="BYTE",n[n.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",n[n.SHORT=5122]="SHORT",n[n.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",n[n.INT=5124]="INT",n[n.UNSIGNED_INT=5125]="UNSIGNED_INT",n[n.FLOAT=5126]="FLOAT",n[n.DOUBLE=5130]="DOUBLE",n[n.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",n[n.ALPHA=6406]="ALPHA",n[n.RGB=6407]="RGB",n[n.RGBA=6408]="RGBA",n[n.LUMINANCE=6409]="LUMINANCE",n[n.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",n[n.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",n[n.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",n[n.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",n[n.FRAGMENT_SHADER=35632]="FRAGMENT_SHADER",n[n.VERTEX_SHADER=35633]="VERTEX_SHADER",n[n.COMPILE_STATUS=35713]="COMPILE_STATUS",n[n.DELETE_STATUS=35712]="DELETE_STATUS",n[n.LINK_STATUS=35714]="LINK_STATUS",n[n.VALIDATE_STATUS=35715]="VALIDATE_STATUS",n[n.ATTACHED_SHADERS=35717]="ATTACHED_SHADERS",n[n.ACTIVE_ATTRIBUTES=35721]="ACTIVE_ATTRIBUTES",n[n.ACTIVE_UNIFORMS=35718]="ACTIVE_UNIFORMS",n[n.MAX_VERTEX_ATTRIBS=34921]="MAX_VERTEX_ATTRIBS",n[n.MAX_VERTEX_UNIFORM_VECTORS=36347]="MAX_VERTEX_UNIFORM_VECTORS",n[n.MAX_VARYING_VECTORS=36348]="MAX_VARYING_VECTORS",n[n.MAX_COMBINED_TEXTURE_IMAGE_UNITS=35661]="MAX_COMBINED_TEXTURE_IMAGE_UNITS",n[n.MAX_VERTEX_TEXTURE_IMAGE_UNITS=35660]="MAX_VERTEX_TEXTURE_IMAGE_UNITS",n[n.MAX_TEXTURE_IMAGE_UNITS=34930]="MAX_TEXTURE_IMAGE_UNITS",n[n.MAX_FRAGMENT_UNIFORM_VECTORS=36349]="MAX_FRAGMENT_UNIFORM_VECTORS",n[n.SHADER_TYPE=35663]="SHADER_TYPE",n[n.SHADING_LANGUAGE_VERSION=35724]="SHADING_LANGUAGE_VERSION",n[n.CURRENT_PROGRAM=35725]="CURRENT_PROGRAM",n[n.NEVER=512]="NEVER",n[n.LESS=513]="LESS",n[n.EQUAL=514]="EQUAL",n[n.LEQUAL=515]="LEQUAL",n[n.GREATER=516]="GREATER",n[n.NOTEQUAL=517]="NOTEQUAL",n[n.GEQUAL=518]="GEQUAL",n[n.ALWAYS=519]="ALWAYS",n[n.KEEP=7680]="KEEP",n[n.REPLACE=7681]="REPLACE",n[n.INCR=7682]="INCR",n[n.DECR=7683]="DECR",n[n.INVERT=5386]="INVERT",n[n.INCR_WRAP=34055]="INCR_WRAP",n[n.DECR_WRAP=34056]="DECR_WRAP",n[n.NEAREST=9728]="NEAREST",n[n.LINEAR=9729]="LINEAR",n[n.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",n[n.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",n[n.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",n[n.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",n[n.TEXTURE_MAG_FILTER=10240]="TEXTURE_MAG_FILTER",n[n.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",n[n.TEXTURE_WRAP_S=10242]="TEXTURE_WRAP_S",n[n.TEXTURE_WRAP_T=10243]="TEXTURE_WRAP_T",n[n.TEXTURE_2D=3553]="TEXTURE_2D",n[n.TEXTURE=5890]="TEXTURE",n[n.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",n[n.TEXTURE_BINDING_CUBE_MAP=34068]="TEXTURE_BINDING_CUBE_MAP",n[n.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",n[n.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",n[n.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",n[n.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",n[n.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",n[n.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",n[n.MAX_CUBE_MAP_TEXTURE_SIZE=34076]="MAX_CUBE_MAP_TEXTURE_SIZE",n[n.TEXTURE0=33984]="TEXTURE0",n[n.ACTIVE_TEXTURE=34016]="ACTIVE_TEXTURE",n[n.REPEAT=10497]="REPEAT",n[n.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",n[n.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",n[n.TEXTURE_WIDTH=4096]="TEXTURE_WIDTH",n[n.TEXTURE_HEIGHT=4097]="TEXTURE_HEIGHT",n[n.FLOAT_VEC2=35664]="FLOAT_VEC2",n[n.FLOAT_VEC3=35665]="FLOAT_VEC3",n[n.FLOAT_VEC4=35666]="FLOAT_VEC4",n[n.INT_VEC2=35667]="INT_VEC2",n[n.INT_VEC3=35668]="INT_VEC3",n[n.INT_VEC4=35669]="INT_VEC4",n[n.BOOL=35670]="BOOL",n[n.BOOL_VEC2=35671]="BOOL_VEC2",n[n.BOOL_VEC3=35672]="BOOL_VEC3",n[n.BOOL_VEC4=35673]="BOOL_VEC4",n[n.FLOAT_MAT2=35674]="FLOAT_MAT2",n[n.FLOAT_MAT3=35675]="FLOAT_MAT3",n[n.FLOAT_MAT4=35676]="FLOAT_MAT4",n[n.SAMPLER_2D=35678]="SAMPLER_2D",n[n.SAMPLER_CUBE=35680]="SAMPLER_CUBE",n[n.LOW_FLOAT=36336]="LOW_FLOAT",n[n.MEDIUM_FLOAT=36337]="MEDIUM_FLOAT",n[n.HIGH_FLOAT=36338]="HIGH_FLOAT",n[n.LOW_INT=36339]="LOW_INT",n[n.MEDIUM_INT=36340]="MEDIUM_INT",n[n.HIGH_INT=36341]="HIGH_INT",n[n.FRAMEBUFFER=36160]="FRAMEBUFFER",n[n.RENDERBUFFER=36161]="RENDERBUFFER",n[n.RGBA4=32854]="RGBA4",n[n.RGB5_A1=32855]="RGB5_A1",n[n.RGB565=36194]="RGB565",n[n.DEPTH_COMPONENT16=33189]="DEPTH_COMPONENT16",n[n.STENCIL_INDEX=6401]="STENCIL_INDEX",n[n.STENCIL_INDEX8=36168]="STENCIL_INDEX8",n[n.DEPTH_STENCIL=34041]="DEPTH_STENCIL",n[n.RENDERBUFFER_WIDTH=36162]="RENDERBUFFER_WIDTH",n[n.RENDERBUFFER_HEIGHT=36163]="RENDERBUFFER_HEIGHT",n[n.RENDERBUFFER_INTERNAL_FORMAT=36164]="RENDERBUFFER_INTERNAL_FORMAT",n[n.RENDERBUFFER_RED_SIZE=36176]="RENDERBUFFER_RED_SIZE",n[n.RENDERBUFFER_GREEN_SIZE=36177]="RENDERBUFFER_GREEN_SIZE",n[n.RENDERBUFFER_BLUE_SIZE=36178]="RENDERBUFFER_BLUE_SIZE",n[n.RENDERBUFFER_ALPHA_SIZE=36179]="RENDERBUFFER_ALPHA_SIZE",n[n.RENDERBUFFER_DEPTH_SIZE=36180]="RENDERBUFFER_DEPTH_SIZE",n[n.RENDERBUFFER_STENCIL_SIZE=36181]="RENDERBUFFER_STENCIL_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE=36048]="FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",n[n.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME=36049]="FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL=36050]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE=36051]="FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE",n[n.COLOR_ATTACHMENT0=36064]="COLOR_ATTACHMENT0",n[n.DEPTH_ATTACHMENT=36096]="DEPTH_ATTACHMENT",n[n.STENCIL_ATTACHMENT=36128]="STENCIL_ATTACHMENT",n[n.DEPTH_STENCIL_ATTACHMENT=33306]="DEPTH_STENCIL_ATTACHMENT",n[n.NONE=0]="NONE",n[n.FRAMEBUFFER_COMPLETE=36053]="FRAMEBUFFER_COMPLETE",n[n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT=36054]="FRAMEBUFFER_INCOMPLETE_ATTACHMENT",n[n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT=36055]="FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",n[n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS=36057]="FRAMEBUFFER_INCOMPLETE_DIMENSIONS",n[n.FRAMEBUFFER_UNSUPPORTED=36061]="FRAMEBUFFER_UNSUPPORTED",n[n.FRAMEBUFFER_BINDING=36006]="FRAMEBUFFER_BINDING",n[n.RENDERBUFFER_BINDING=36007]="RENDERBUFFER_BINDING",n[n.READ_FRAMEBUFFER=36008]="READ_FRAMEBUFFER",n[n.DRAW_FRAMEBUFFER=36009]="DRAW_FRAMEBUFFER",n[n.MAX_RENDERBUFFER_SIZE=34024]="MAX_RENDERBUFFER_SIZE",n[n.INVALID_FRAMEBUFFER_OPERATION=1286]="INVALID_FRAMEBUFFER_OPERATION",n[n.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL",n[n.UNPACK_PREMULTIPLY_ALPHA_WEBGL=37441]="UNPACK_PREMULTIPLY_ALPHA_WEBGL",n[n.UNPACK_COLORSPACE_CONVERSION_WEBGL=37443]="UNPACK_COLORSPACE_CONVERSION_WEBGL",n[n.READ_BUFFER=3074]="READ_BUFFER",n[n.UNPACK_ROW_LENGTH=3314]="UNPACK_ROW_LENGTH",n[n.UNPACK_SKIP_ROWS=3315]="UNPACK_SKIP_ROWS",n[n.UNPACK_SKIP_PIXELS=3316]="UNPACK_SKIP_PIXELS",n[n.PACK_ROW_LENGTH=3330]="PACK_ROW_LENGTH",n[n.PACK_SKIP_ROWS=3331]="PACK_SKIP_ROWS",n[n.PACK_SKIP_PIXELS=3332]="PACK_SKIP_PIXELS",n[n.TEXTURE_BINDING_3D=32874]="TEXTURE_BINDING_3D",n[n.UNPACK_SKIP_IMAGES=32877]="UNPACK_SKIP_IMAGES",n[n.UNPACK_IMAGE_HEIGHT=32878]="UNPACK_IMAGE_HEIGHT",n[n.MAX_3D_TEXTURE_SIZE=32883]="MAX_3D_TEXTURE_SIZE",n[n.MAX_ELEMENTS_VERTICES=33e3]="MAX_ELEMENTS_VERTICES",n[n.MAX_ELEMENTS_INDICES=33001]="MAX_ELEMENTS_INDICES",n[n.MAX_TEXTURE_LOD_BIAS=34045]="MAX_TEXTURE_LOD_BIAS",n[n.MAX_FRAGMENT_UNIFORM_COMPONENTS=35657]="MAX_FRAGMENT_UNIFORM_COMPONENTS",n[n.MAX_VERTEX_UNIFORM_COMPONENTS=35658]="MAX_VERTEX_UNIFORM_COMPONENTS",n[n.MAX_ARRAY_TEXTURE_LAYERS=35071]="MAX_ARRAY_TEXTURE_LAYERS",n[n.MIN_PROGRAM_TEXEL_OFFSET=35076]="MIN_PROGRAM_TEXEL_OFFSET",n[n.MAX_PROGRAM_TEXEL_OFFSET=35077]="MAX_PROGRAM_TEXEL_OFFSET",n[n.MAX_VARYING_COMPONENTS=35659]="MAX_VARYING_COMPONENTS",n[n.FRAGMENT_SHADER_DERIVATIVE_HINT=35723]="FRAGMENT_SHADER_DERIVATIVE_HINT",n[n.RASTERIZER_DISCARD=35977]="RASTERIZER_DISCARD",n[n.VERTEX_ARRAY_BINDING=34229]="VERTEX_ARRAY_BINDING",n[n.MAX_VERTEX_OUTPUT_COMPONENTS=37154]="MAX_VERTEX_OUTPUT_COMPONENTS",n[n.MAX_FRAGMENT_INPUT_COMPONENTS=37157]="MAX_FRAGMENT_INPUT_COMPONENTS",n[n.MAX_SERVER_WAIT_TIMEOUT=37137]="MAX_SERVER_WAIT_TIMEOUT",n[n.MAX_ELEMENT_INDEX=36203]="MAX_ELEMENT_INDEX",n[n.RED=6403]="RED",n[n.RGB8=32849]="RGB8",n[n.RGBA8=32856]="RGBA8",n[n.RGB10_A2=32857]="RGB10_A2",n[n.TEXTURE_3D=32879]="TEXTURE_3D",n[n.TEXTURE_WRAP_R=32882]="TEXTURE_WRAP_R",n[n.TEXTURE_MIN_LOD=33082]="TEXTURE_MIN_LOD",n[n.TEXTURE_MAX_LOD=33083]="TEXTURE_MAX_LOD",n[n.TEXTURE_BASE_LEVEL=33084]="TEXTURE_BASE_LEVEL",n[n.TEXTURE_MAX_LEVEL=33085]="TEXTURE_MAX_LEVEL",n[n.TEXTURE_COMPARE_MODE=34892]="TEXTURE_COMPARE_MODE",n[n.TEXTURE_COMPARE_FUNC=34893]="TEXTURE_COMPARE_FUNC",n[n.SRGB=35904]="SRGB",n[n.SRGB8=35905]="SRGB8",n[n.SRGB8_ALPHA8=35907]="SRGB8_ALPHA8",n[n.COMPARE_REF_TO_TEXTURE=34894]="COMPARE_REF_TO_TEXTURE",n[n.RGBA32F=34836]="RGBA32F",n[n.RGB32F=34837]="RGB32F",n[n.RGBA16F=34842]="RGBA16F",n[n.RGB16F=34843]="RGB16F",n[n.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",n[n.TEXTURE_BINDING_2D_ARRAY=35869]="TEXTURE_BINDING_2D_ARRAY",n[n.R11F_G11F_B10F=35898]="R11F_G11F_B10F",n[n.RGB9_E5=35901]="RGB9_E5",n[n.RGBA32UI=36208]="RGBA32UI",n[n.RGB32UI=36209]="RGB32UI",n[n.RGBA16UI=36214]="RGBA16UI",n[n.RGB16UI=36215]="RGB16UI",n[n.RGBA8UI=36220]="RGBA8UI",n[n.RGB8UI=36221]="RGB8UI",n[n.RGBA32I=36226]="RGBA32I",n[n.RGB32I=36227]="RGB32I",n[n.RGBA16I=36232]="RGBA16I",n[n.RGB16I=36233]="RGB16I",n[n.RGBA8I=36238]="RGBA8I",n[n.RGB8I=36239]="RGB8I",n[n.RED_INTEGER=36244]="RED_INTEGER",n[n.RGB_INTEGER=36248]="RGB_INTEGER",n[n.RGBA_INTEGER=36249]="RGBA_INTEGER",n[n.R8=33321]="R8",n[n.RG8=33323]="RG8",n[n.R16F=33325]="R16F",n[n.R32F=33326]="R32F",n[n.RG16F=33327]="RG16F",n[n.RG32F=33328]="RG32F",n[n.R8I=33329]="R8I",n[n.R8UI=33330]="R8UI",n[n.R16I=33331]="R16I",n[n.R16UI=33332]="R16UI",n[n.R32I=33333]="R32I",n[n.R32UI=33334]="R32UI",n[n.RG8I=33335]="RG8I",n[n.RG8UI=33336]="RG8UI",n[n.RG16I=33337]="RG16I",n[n.RG16UI=33338]="RG16UI",n[n.RG32I=33339]="RG32I",n[n.RG32UI=33340]="RG32UI",n[n.R8_SNORM=36756]="R8_SNORM",n[n.RG8_SNORM=36757]="RG8_SNORM",n[n.RGB8_SNORM=36758]="RGB8_SNORM",n[n.RGBA8_SNORM=36759]="RGBA8_SNORM",n[n.RGB10_A2UI=36975]="RGB10_A2UI",n[n.TEXTURE_IMMUTABLE_FORMAT=37167]="TEXTURE_IMMUTABLE_FORMAT",n[n.TEXTURE_IMMUTABLE_LEVELS=33503]="TEXTURE_IMMUTABLE_LEVELS",n[n.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",n[n.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",n[n.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",n[n.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",n[n.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",n[n.HALF_FLOAT=5131]="HALF_FLOAT",n[n.RG=33319]="RG",n[n.RG_INTEGER=33320]="RG_INTEGER",n[n.INT_2_10_10_10_REV=36255]="INT_2_10_10_10_REV",n[n.CURRENT_QUERY=34917]="CURRENT_QUERY",n[n.QUERY_RESULT=34918]="QUERY_RESULT",n[n.QUERY_RESULT_AVAILABLE=34919]="QUERY_RESULT_AVAILABLE",n[n.ANY_SAMPLES_PASSED=35887]="ANY_SAMPLES_PASSED",n[n.ANY_SAMPLES_PASSED_CONSERVATIVE=36202]="ANY_SAMPLES_PASSED_CONSERVATIVE",n[n.MAX_DRAW_BUFFERS=34852]="MAX_DRAW_BUFFERS",n[n.DRAW_BUFFER0=34853]="DRAW_BUFFER0",n[n.DRAW_BUFFER1=34854]="DRAW_BUFFER1",n[n.DRAW_BUFFER2=34855]="DRAW_BUFFER2",n[n.DRAW_BUFFER3=34856]="DRAW_BUFFER3",n[n.DRAW_BUFFER4=34857]="DRAW_BUFFER4",n[n.DRAW_BUFFER5=34858]="DRAW_BUFFER5",n[n.DRAW_BUFFER6=34859]="DRAW_BUFFER6",n[n.DRAW_BUFFER7=34860]="DRAW_BUFFER7",n[n.DRAW_BUFFER8=34861]="DRAW_BUFFER8",n[n.DRAW_BUFFER9=34862]="DRAW_BUFFER9",n[n.DRAW_BUFFER10=34863]="DRAW_BUFFER10",n[n.DRAW_BUFFER11=34864]="DRAW_BUFFER11",n[n.DRAW_BUFFER12=34865]="DRAW_BUFFER12",n[n.DRAW_BUFFER13=34866]="DRAW_BUFFER13",n[n.DRAW_BUFFER14=34867]="DRAW_BUFFER14",n[n.DRAW_BUFFER15=34868]="DRAW_BUFFER15",n[n.MAX_COLOR_ATTACHMENTS=36063]="MAX_COLOR_ATTACHMENTS",n[n.COLOR_ATTACHMENT1=36065]="COLOR_ATTACHMENT1",n[n.COLOR_ATTACHMENT2=36066]="COLOR_ATTACHMENT2",n[n.COLOR_ATTACHMENT3=36067]="COLOR_ATTACHMENT3",n[n.COLOR_ATTACHMENT4=36068]="COLOR_ATTACHMENT4",n[n.COLOR_ATTACHMENT5=36069]="COLOR_ATTACHMENT5",n[n.COLOR_ATTACHMENT6=36070]="COLOR_ATTACHMENT6",n[n.COLOR_ATTACHMENT7=36071]="COLOR_ATTACHMENT7",n[n.COLOR_ATTACHMENT8=36072]="COLOR_ATTACHMENT8",n[n.COLOR_ATTACHMENT9=36073]="COLOR_ATTACHMENT9",n[n.COLOR_ATTACHMENT10=36074]="COLOR_ATTACHMENT10",n[n.COLOR_ATTACHMENT11=36075]="COLOR_ATTACHMENT11",n[n.COLOR_ATTACHMENT12=36076]="COLOR_ATTACHMENT12",n[n.COLOR_ATTACHMENT13=36077]="COLOR_ATTACHMENT13",n[n.COLOR_ATTACHMENT14=36078]="COLOR_ATTACHMENT14",n[n.COLOR_ATTACHMENT15=36079]="COLOR_ATTACHMENT15",n[n.SAMPLER_3D=35679]="SAMPLER_3D",n[n.SAMPLER_2D_SHADOW=35682]="SAMPLER_2D_SHADOW",n[n.SAMPLER_2D_ARRAY=36289]="SAMPLER_2D_ARRAY",n[n.SAMPLER_2D_ARRAY_SHADOW=36292]="SAMPLER_2D_ARRAY_SHADOW",n[n.SAMPLER_CUBE_SHADOW=36293]="SAMPLER_CUBE_SHADOW",n[n.INT_SAMPLER_2D=36298]="INT_SAMPLER_2D",n[n.INT_SAMPLER_3D=36299]="INT_SAMPLER_3D",n[n.INT_SAMPLER_CUBE=36300]="INT_SAMPLER_CUBE",n[n.INT_SAMPLER_2D_ARRAY=36303]="INT_SAMPLER_2D_ARRAY",n[n.UNSIGNED_INT_SAMPLER_2D=36306]="UNSIGNED_INT_SAMPLER_2D",n[n.UNSIGNED_INT_SAMPLER_3D=36307]="UNSIGNED_INT_SAMPLER_3D",n[n.UNSIGNED_INT_SAMPLER_CUBE=36308]="UNSIGNED_INT_SAMPLER_CUBE",n[n.UNSIGNED_INT_SAMPLER_2D_ARRAY=36311]="UNSIGNED_INT_SAMPLER_2D_ARRAY",n[n.MAX_SAMPLES=36183]="MAX_SAMPLES",n[n.SAMPLER_BINDING=35097]="SAMPLER_BINDING",n[n.PIXEL_PACK_BUFFER=35051]="PIXEL_PACK_BUFFER",n[n.PIXEL_UNPACK_BUFFER=35052]="PIXEL_UNPACK_BUFFER",n[n.PIXEL_PACK_BUFFER_BINDING=35053]="PIXEL_PACK_BUFFER_BINDING",n[n.PIXEL_UNPACK_BUFFER_BINDING=35055]="PIXEL_UNPACK_BUFFER_BINDING",n[n.COPY_READ_BUFFER=36662]="COPY_READ_BUFFER",n[n.COPY_WRITE_BUFFER=36663]="COPY_WRITE_BUFFER",n[n.COPY_READ_BUFFER_BINDING=36662]="COPY_READ_BUFFER_BINDING",n[n.COPY_WRITE_BUFFER_BINDING=36663]="COPY_WRITE_BUFFER_BINDING",n[n.FLOAT_MAT2x3=35685]="FLOAT_MAT2x3",n[n.FLOAT_MAT2x4=35686]="FLOAT_MAT2x4",n[n.FLOAT_MAT3x2=35687]="FLOAT_MAT3x2",n[n.FLOAT_MAT3x4=35688]="FLOAT_MAT3x4",n[n.FLOAT_MAT4x2=35689]="FLOAT_MAT4x2",n[n.FLOAT_MAT4x3=35690]="FLOAT_MAT4x3",n[n.UNSIGNED_INT_VEC2=36294]="UNSIGNED_INT_VEC2",n[n.UNSIGNED_INT_VEC3=36295]="UNSIGNED_INT_VEC3",n[n.UNSIGNED_INT_VEC4=36296]="UNSIGNED_INT_VEC4",n[n.UNSIGNED_NORMALIZED=35863]="UNSIGNED_NORMALIZED",n[n.SIGNED_NORMALIZED=36764]="SIGNED_NORMALIZED",n[n.VERTEX_ATTRIB_ARRAY_INTEGER=35069]="VERTEX_ATTRIB_ARRAY_INTEGER",n[n.VERTEX_ATTRIB_ARRAY_DIVISOR=35070]="VERTEX_ATTRIB_ARRAY_DIVISOR",n[n.TRANSFORM_FEEDBACK_BUFFER_MODE=35967]="TRANSFORM_FEEDBACK_BUFFER_MODE",n[n.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS=35968]="MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS",n[n.TRANSFORM_FEEDBACK_VARYINGS=35971]="TRANSFORM_FEEDBACK_VARYINGS",n[n.TRANSFORM_FEEDBACK_BUFFER_START=35972]="TRANSFORM_FEEDBACK_BUFFER_START",n[n.TRANSFORM_FEEDBACK_BUFFER_SIZE=35973]="TRANSFORM_FEEDBACK_BUFFER_SIZE",n[n.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN=35976]="TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN",n[n.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS=35978]="MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS",n[n.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS=35979]="MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS",n[n.INTERLEAVED_ATTRIBS=35980]="INTERLEAVED_ATTRIBS",n[n.SEPARATE_ATTRIBS=35981]="SEPARATE_ATTRIBS",n[n.TRANSFORM_FEEDBACK_BUFFER=35982]="TRANSFORM_FEEDBACK_BUFFER",n[n.TRANSFORM_FEEDBACK_BUFFER_BINDING=35983]="TRANSFORM_FEEDBACK_BUFFER_BINDING",n[n.TRANSFORM_FEEDBACK=36386]="TRANSFORM_FEEDBACK",n[n.TRANSFORM_FEEDBACK_PAUSED=36387]="TRANSFORM_FEEDBACK_PAUSED",n[n.TRANSFORM_FEEDBACK_ACTIVE=36388]="TRANSFORM_FEEDBACK_ACTIVE",n[n.TRANSFORM_FEEDBACK_BINDING=36389]="TRANSFORM_FEEDBACK_BINDING",n[n.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING=33296]="FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING",n[n.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE=33297]="FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE",n[n.FRAMEBUFFER_ATTACHMENT_RED_SIZE=33298]="FRAMEBUFFER_ATTACHMENT_RED_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_GREEN_SIZE=33299]="FRAMEBUFFER_ATTACHMENT_GREEN_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_BLUE_SIZE=33300]="FRAMEBUFFER_ATTACHMENT_BLUE_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE=33301]="FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE=33302]="FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE",n[n.FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE=33303]="FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE",n[n.FRAMEBUFFER_DEFAULT=33304]="FRAMEBUFFER_DEFAULT",n[n.DEPTH24_STENCIL8=35056]="DEPTH24_STENCIL8",n[n.DRAW_FRAMEBUFFER_BINDING=36006]="DRAW_FRAMEBUFFER_BINDING",n[n.READ_FRAMEBUFFER_BINDING=36010]="READ_FRAMEBUFFER_BINDING",n[n.RENDERBUFFER_SAMPLES=36011]="RENDERBUFFER_SAMPLES",n[n.FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER=36052]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER",n[n.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE=36182]="FRAMEBUFFER_INCOMPLETE_MULTISAMPLE",n[n.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",n[n.UNIFORM_BUFFER_BINDING=35368]="UNIFORM_BUFFER_BINDING",n[n.UNIFORM_BUFFER_START=35369]="UNIFORM_BUFFER_START",n[n.UNIFORM_BUFFER_SIZE=35370]="UNIFORM_BUFFER_SIZE",n[n.MAX_VERTEX_UNIFORM_BLOCKS=35371]="MAX_VERTEX_UNIFORM_BLOCKS",n[n.MAX_FRAGMENT_UNIFORM_BLOCKS=35373]="MAX_FRAGMENT_UNIFORM_BLOCKS",n[n.MAX_COMBINED_UNIFORM_BLOCKS=35374]="MAX_COMBINED_UNIFORM_BLOCKS",n[n.MAX_UNIFORM_BUFFER_BINDINGS=35375]="MAX_UNIFORM_BUFFER_BINDINGS",n[n.MAX_UNIFORM_BLOCK_SIZE=35376]="MAX_UNIFORM_BLOCK_SIZE",n[n.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS=35377]="MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS",n[n.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS=35379]="MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS",n[n.UNIFORM_BUFFER_OFFSET_ALIGNMENT=35380]="UNIFORM_BUFFER_OFFSET_ALIGNMENT",n[n.ACTIVE_UNIFORM_BLOCKS=35382]="ACTIVE_UNIFORM_BLOCKS",n[n.UNIFORM_TYPE=35383]="UNIFORM_TYPE",n[n.UNIFORM_SIZE=35384]="UNIFORM_SIZE",n[n.UNIFORM_BLOCK_INDEX=35386]="UNIFORM_BLOCK_INDEX",n[n.UNIFORM_OFFSET=35387]="UNIFORM_OFFSET",n[n.UNIFORM_ARRAY_STRIDE=35388]="UNIFORM_ARRAY_STRIDE",n[n.UNIFORM_MATRIX_STRIDE=35389]="UNIFORM_MATRIX_STRIDE",n[n.UNIFORM_IS_ROW_MAJOR=35390]="UNIFORM_IS_ROW_MAJOR",n[n.UNIFORM_BLOCK_BINDING=35391]="UNIFORM_BLOCK_BINDING",n[n.UNIFORM_BLOCK_DATA_SIZE=35392]="UNIFORM_BLOCK_DATA_SIZE",n[n.UNIFORM_BLOCK_ACTIVE_UNIFORMS=35394]="UNIFORM_BLOCK_ACTIVE_UNIFORMS",n[n.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES=35395]="UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES",n[n.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER=35396]="UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER",n[n.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER=35398]="UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER",n[n.OBJECT_TYPE=37138]="OBJECT_TYPE",n[n.SYNC_CONDITION=37139]="SYNC_CONDITION",n[n.SYNC_STATUS=37140]="SYNC_STATUS",n[n.SYNC_FLAGS=37141]="SYNC_FLAGS",n[n.SYNC_FENCE=37142]="SYNC_FENCE",n[n.SYNC_GPU_COMMANDS_COMPLETE=37143]="SYNC_GPU_COMMANDS_COMPLETE",n[n.UNSIGNALED=37144]="UNSIGNALED",n[n.SIGNALED=37145]="SIGNALED",n[n.ALREADY_SIGNALED=37146]="ALREADY_SIGNALED",n[n.TIMEOUT_EXPIRED=37147]="TIMEOUT_EXPIRED",n[n.CONDITION_SATISFIED=37148]="CONDITION_SATISFIED",n[n.WAIT_FAILED=37149]="WAIT_FAILED",n[n.SYNC_FLUSH_COMMANDS_BIT=1]="SYNC_FLUSH_COMMANDS_BIT",n[n.COLOR=6144]="COLOR",n[n.DEPTH=6145]="DEPTH",n[n.STENCIL=6146]="STENCIL",n[n.MIN=32775]="MIN",n[n.MAX=32776]="MAX",n[n.DEPTH_COMPONENT24=33190]="DEPTH_COMPONENT24",n[n.STREAM_READ=35041]="STREAM_READ",n[n.STREAM_COPY=35042]="STREAM_COPY",n[n.STATIC_READ=35045]="STATIC_READ",n[n.STATIC_COPY=35046]="STATIC_COPY",n[n.DYNAMIC_READ=35049]="DYNAMIC_READ",n[n.DYNAMIC_COPY=35050]="DYNAMIC_COPY",n[n.DEPTH_COMPONENT32F=36012]="DEPTH_COMPONENT32F",n[n.DEPTH32F_STENCIL8=36013]="DEPTH32F_STENCIL8",n[n.INVALID_INDEX=4294967295]="INVALID_INDEX",n[n.TIMEOUT_IGNORED=-1]="TIMEOUT_IGNORED",n[n.MAX_CLIENT_WAIT_TIMEOUT_WEBGL=37447]="MAX_CLIENT_WAIT_TIMEOUT_WEBGL",n[n.UNMASKED_VENDOR_WEBGL=37445]="UNMASKED_VENDOR_WEBGL",n[n.UNMASKED_RENDERER_WEBGL=37446]="UNMASKED_RENDERER_WEBGL",n[n.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047]="MAX_TEXTURE_MAX_ANISOTROPY_EXT",n[n.TEXTURE_MAX_ANISOTROPY_EXT=34046]="TEXTURE_MAX_ANISOTROPY_EXT",n[n.R16_EXT=33322]="R16_EXT",n[n.RG16_EXT=33324]="RG16_EXT",n[n.RGB16_EXT=32852]="RGB16_EXT",n[n.RGBA16_EXT=32859]="RGBA16_EXT",n[n.R16_SNORM_EXT=36760]="R16_SNORM_EXT",n[n.RG16_SNORM_EXT=36761]="RG16_SNORM_EXT",n[n.RGB16_SNORM_EXT=36762]="RGB16_SNORM_EXT",n[n.RGBA16_SNORM_EXT=36763]="RGBA16_SNORM_EXT",n[n.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",n[n.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",n[n.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",n[n.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",n[n.COMPRESSED_RED_RGTC1_EXT=36283]="COMPRESSED_RED_RGTC1_EXT",n[n.COMPRESSED_SIGNED_RED_RGTC1_EXT=36284]="COMPRESSED_SIGNED_RED_RGTC1_EXT",n[n.COMPRESSED_RED_GREEN_RGTC2_EXT=36285]="COMPRESSED_RED_GREEN_RGTC2_EXT",n[n.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT=36286]="COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT",n[n.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",n[n.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",n[n.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",n[n.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",n[n.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",n[n.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",n[n.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",n[n.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",n[n.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",n[n.COMPRESSED_RGBA8_ETC2_EAC=37493]="COMPRESSED_RGBA8_ETC2_EAC",n[n.COMPRESSED_SRGB8_ETC2=37494]="COMPRESSED_SRGB8_ETC2",n[n.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37495]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",n[n.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37496]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",n[n.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37497]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",n[n.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",n[n.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",n[n.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",n[n.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",n[n.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",n[n.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",n[n.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35986]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",n[n.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",n[n.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",n[n.COMPRESSED_RGBA_ASTC_5x4_KHR=37809]="COMPRESSED_RGBA_ASTC_5x4_KHR",n[n.COMPRESSED_RGBA_ASTC_5x5_KHR=37810]="COMPRESSED_RGBA_ASTC_5x5_KHR",n[n.COMPRESSED_RGBA_ASTC_6x5_KHR=37811]="COMPRESSED_RGBA_ASTC_6x5_KHR",n[n.COMPRESSED_RGBA_ASTC_6x6_KHR=37812]="COMPRESSED_RGBA_ASTC_6x6_KHR",n[n.COMPRESSED_RGBA_ASTC_8x5_KHR=37813]="COMPRESSED_RGBA_ASTC_8x5_KHR",n[n.COMPRESSED_RGBA_ASTC_8x6_KHR=37814]="COMPRESSED_RGBA_ASTC_8x6_KHR",n[n.COMPRESSED_RGBA_ASTC_8x8_KHR=37815]="COMPRESSED_RGBA_ASTC_8x8_KHR",n[n.COMPRESSED_RGBA_ASTC_10x5_KHR=37816]="COMPRESSED_RGBA_ASTC_10x5_KHR",n[n.COMPRESSED_RGBA_ASTC_10x6_KHR=37817]="COMPRESSED_RGBA_ASTC_10x6_KHR",n[n.COMPRESSED_RGBA_ASTC_10x8_KHR=37818]="COMPRESSED_RGBA_ASTC_10x8_KHR",n[n.COMPRESSED_RGBA_ASTC_10x10_KHR=37819]="COMPRESSED_RGBA_ASTC_10x10_KHR",n[n.COMPRESSED_RGBA_ASTC_12x10_KHR=37820]="COMPRESSED_RGBA_ASTC_12x10_KHR",n[n.COMPRESSED_RGBA_ASTC_12x12_KHR=37821]="COMPRESSED_RGBA_ASTC_12x12_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR=37840]="COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR=37841]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR=37842]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR=37843]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR=37844]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR=37845]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR=37846]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR=37847]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR=37848]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR=37849]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR=37850]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR=37851]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR=37852]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR",n[n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR=37853]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR",n[n.QUERY_COUNTER_BITS_EXT=34916]="QUERY_COUNTER_BITS_EXT",n[n.CURRENT_QUERY_EXT=34917]="CURRENT_QUERY_EXT",n[n.QUERY_RESULT_EXT=34918]="QUERY_RESULT_EXT",n[n.QUERY_RESULT_AVAILABLE_EXT=34919]="QUERY_RESULT_AVAILABLE_EXT",n[n.TIME_ELAPSED_EXT=35007]="TIME_ELAPSED_EXT",n[n.TIMESTAMP_EXT=36392]="TIMESTAMP_EXT",n[n.GPU_DISJOINT_EXT=36795]="GPU_DISJOINT_EXT",n[n.COMPLETION_STATUS_KHR=37297]="COMPLETION_STATUS_KHR",n[n.DEPTH_CLAMP_EXT=34383]="DEPTH_CLAMP_EXT",n[n.FIRST_VERTEX_CONVENTION_WEBGL=36429]="FIRST_VERTEX_CONVENTION_WEBGL",n[n.LAST_VERTEX_CONVENTION_WEBGL=36430]="LAST_VERTEX_CONVENTION_WEBGL",n[n.PROVOKING_VERTEX_WEBL=36431]="PROVOKING_VERTEX_WEBL",n[n.POLYGON_MODE_WEBGL=2880]="POLYGON_MODE_WEBGL",n[n.POLYGON_OFFSET_LINE_WEBGL=10754]="POLYGON_OFFSET_LINE_WEBGL",n[n.LINE_WEBGL=6913]="LINE_WEBGL",n[n.FILL_WEBGL=6914]="FILL_WEBGL",n[n.MAX_CLIP_DISTANCES_WEBGL=3378]="MAX_CLIP_DISTANCES_WEBGL",n[n.MAX_CULL_DISTANCES_WEBGL=33529]="MAX_CULL_DISTANCES_WEBGL",n[n.MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL=33530]="MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL",n[n.CLIP_DISTANCE0_WEBGL=12288]="CLIP_DISTANCE0_WEBGL",n[n.CLIP_DISTANCE1_WEBGL=12289]="CLIP_DISTANCE1_WEBGL",n[n.CLIP_DISTANCE2_WEBGL=12290]="CLIP_DISTANCE2_WEBGL",n[n.CLIP_DISTANCE3_WEBGL=12291]="CLIP_DISTANCE3_WEBGL",n[n.CLIP_DISTANCE4_WEBGL=12292]="CLIP_DISTANCE4_WEBGL",n[n.CLIP_DISTANCE5_WEBGL=12293]="CLIP_DISTANCE5_WEBGL",n[n.CLIP_DISTANCE6_WEBGL=12294]="CLIP_DISTANCE6_WEBGL",n[n.CLIP_DISTANCE7_WEBGL=12295]="CLIP_DISTANCE7_WEBGL",n[n.POLYGON_OFFSET_CLAMP_EXT=36379]="POLYGON_OFFSET_CLAMP_EXT",n[n.LOWER_LEFT_EXT=36001]="LOWER_LEFT_EXT",n[n.UPPER_LEFT_EXT=36002]="UPPER_LEFT_EXT",n[n.NEGATIVE_ONE_TO_ONE_EXT=37726]="NEGATIVE_ONE_TO_ONE_EXT",n[n.ZERO_TO_ONE_EXT=37727]="ZERO_TO_ONE_EXT",n[n.CLIP_ORIGIN_EXT=37724]="CLIP_ORIGIN_EXT",n[n.CLIP_DEPTH_MODE_EXT=37725]="CLIP_DEPTH_MODE_EXT",n[n.SRC1_COLOR_WEBGL=35065]="SRC1_COLOR_WEBGL",n[n.SRC1_ALPHA_WEBGL=34185]="SRC1_ALPHA_WEBGL",n[n.ONE_MINUS_SRC1_COLOR_WEBGL=35066]="ONE_MINUS_SRC1_COLOR_WEBGL",n[n.ONE_MINUS_SRC1_ALPHA_WEBGL=35067]="ONE_MINUS_SRC1_ALPHA_WEBGL",n[n.MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL=35068]="MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL",n[n.MIRROR_CLAMP_TO_EDGE_EXT=34627]="MIRROR_CLAMP_TO_EDGE_EXT"})(Xt||(Xt={}));const Fm={WEBGL_depth_texture:{UNSIGNED_INT_24_8_WEBGL:34042},OES_element_index_uint:{},OES_texture_float:{},OES_texture_half_float:{HALF_FLOAT_OES:5131},EXT_color_buffer_float:{},OES_standard_derivatives:{FRAGMENT_SHADER_DERIVATIVE_HINT_OES:35723},EXT_frag_depth:{},EXT_blend_minmax:{MIN_EXT:32775,MAX_EXT:32776},EXT_shader_texture_lod:{}},Mm=n=>({drawBuffersWEBGL(e){return n.drawBuffers(e)},COLOR_ATTACHMENT0_WEBGL:36064,COLOR_ATTACHMENT1_WEBGL:36065,COLOR_ATTACHMENT2_WEBGL:36066,COLOR_ATTACHMENT3_WEBGL:36067}),Nm=n=>({VERTEX_ARRAY_BINDING_OES:34229,createVertexArrayOES(){return n.createVertexArray()},deleteVertexArrayOES(e){return n.deleteVertexArray(e)},isVertexArrayOES(e){return n.isVertexArray(e)},bindVertexArrayOES(e){return n.bindVertexArray(e)}}),Om=n=>({VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE:35070,drawArraysInstancedANGLE(...e){return n.drawArraysInstanced(...e)},drawElementsInstancedANGLE(...e){return n.drawElementsInstanced(...e)},vertexAttribDivisorANGLE(...e){return n.vertexAttribDivisor(...e)}});function Bm(n=!0){const e=HTMLCanvasElement.prototype;if(!n&&e.originalGetContext){e.getContext=e.originalGetContext,e.originalGetContext=void 0;return}e.originalGetContext=e.getContext,e.getContext=function(t,i){if(t==="webgl"||t==="experimental-webgl"){const r=this.originalGetContext("webgl2",i);return r instanceof HTMLElement&&Um(r),r}return this.originalGetContext(t,i)}}function Um(n){n.getExtension("EXT_color_buffer_float");const e={...Fm,WEBGL_disjoint_timer_query:n.getExtension("EXT_disjoint_timer_query_webgl2"),WEBGL_draw_buffers:Mm(n),OES_vertex_array_object:Nm(n),ANGLE_instanced_arrays:Om(n)},t=n.getExtension;n.getExtension=function(r){const s=t.call(n,r);return s||(r in e?e[r]:null)};const i=n.getSupportedExtensions;n.getSupportedExtensions=function(){const r=i.apply(n)||[];return r==null?void 0:r.concat(Object.keys(e))}}async function tl(n,e){const t=document.getElementsByTagName("head")[0];if(!t)throw new Error("loadScript");const i=document.createElement("script");return i.setAttribute("type","text/javascript"),i.setAttribute("src",n),new Promise((r,s)=>{i.onload=r,i.onerror=o=>s(new Error(`Unable to load script '${n}': ${o}`)),t.appendChild(i)})}const zm=1;let fe=null,nl=!1;const Ss={debugSpectorJS:D.get("debug-spectorjs"),debugSpectorJSUrl:"https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",gl:void 0};async function Lm(n){if(!globalThis.SPECTOR)try{await tl(n.debugSpectorJSUrl||Ss.debugSpectorJSUrl)}catch(e){D.warn(String(e))}}function Vm(n){var e;if(n={...Ss,...n},!n.debugSpectorJS)return null;if(!fe&&globalThis.SPECTOR&&!((e=globalThis.luma)!=null&&e.spector)){D.probe(zm,"SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();const{Spector:t}=globalThis.SPECTOR;fe=new t,globalThis.luma&&(globalThis.luma.spector=fe)}if(!fe)return null;if(nl||(nl=!0,fe.spyCanvases(),fe==null||fe.onCaptureStarted.add(t=>D.info("Spector capture started:",t)()),fe==null||fe.onCapture.add(t=>{D.info("Spector capture complete:",t)(),fe==null||fe.getResultUI(),fe==null||fe.resultView.display(),fe==null||fe.resultView.addCapture(t)})),n.gl){const t=n.gl,i=t.device;fe==null||fe.startCapture(n.gl,500),t.device=i,new Promise(r=>setTimeout(r,2e3)).then(r=>{D.info("Spector capture stopped after 2 seconds")(),fe==null||fe.stopCapture()})}return fe}const Hm="https://unpkg.com/webgl-debug@2.0.1/index.js";function il(n){return n.luma=n.luma||{},n.luma}async function Wm(){Vt()&&!globalThis.WebGLDebugUtils&&(globalThis.global=globalThis.global||globalThis,globalThis.global.module={},await tl(Hm))}function $m(n,e={}){return e.debugWebGL||e.traceWebGL?Ym(n,e):Xm(n)}function Xm(n){const e=il(n);return e.realContext?e.realContext:n}function Ym(n,e){if(!globalThis.WebGLDebugUtils)return D.warn("webgl-debug not loaded")(),n;const t=il(n);if(t.debugContext)return t.debugContext;globalThis.WebGLDebugUtils.init({...Xt,...n});const i=globalThis.WebGLDebugUtils.makeDebugContext(n,qm.bind(null,e),jm.bind(null,e));for(const o in Xt)!(o in i)&&typeof Xt[o]=="number"&&(i[o]=Xt[o]);class r{}Object.setPrototypeOf(i,Object.getPrototypeOf(n)),Object.setPrototypeOf(r,i);const s=Object.create(r);return t.realContext=n,t.debugContext=s,s.debug=!0,s}function rl(n,e){e=Array.from(e).map(i=>i===void 0?"undefined":i);let t=globalThis.WebGLDebugUtils.glFunctionArgsToString(n,e);return t=`${t.slice(0,100)}${t.length>100?"...":""}`,`gl.${n}(${t})`}function qm(n,e,t,i){i=Array.from(i).map(a=>a===void 0?"undefined":a);const r=globalThis.WebGLDebugUtils.glEnumToString(e),s=globalThis.WebGLDebugUtils.glFunctionArgsToString(t,i),o=`${r} in gl.${t}(${s})`;D.error(o)();debugger}function jm(n,e,t){let i="";D.level>=1&&(i=rl(e,t),n.traceWebGL&&D.log(1,i)());for(const r of t)if(r===void 0){i=i||rl(e,t);debugger}}const Li=1;class Km extends Gp{constructor(){super();m(this,"type","webgl");Wt.defaultProps={...Wt.defaultProps,...Ss}}enforceWebGL2(t){Bm(t)}isSupported(){return typeof WebGL2RenderingContext<"u"}isDeviceHandle(t){return typeof WebGL2RenderingContext<"u"&&t instanceof WebGL2RenderingContext?!0:(typeof WebGLRenderingContext<"u"&&t instanceof WebGLRenderingContext&&D.warn("WebGL1 is not supported",t)(),!1)}async attach(t,i={}){const{WebGLDevice:r}=await Promise.resolve().then(()=>El);if(t instanceof r)return t;if((t==null?void 0:t.device)instanceof r)return t.device;if(!Zm(t))throw new Error("Invalid WebGL2RenderingContext");const s=i.createCanvasContext===!0?{}:i.createCanvasContext;return new r({...i,_handle:t,createCanvasContext:{canvas:t.canvas,autoResize:!1,...s}})}async create(t={}){const{WebGLDevice:i}=await Promise.resolve().then(()=>El);D.groupCollapsed(Li,"WebGLDevice created")();try{const r=[];(t.debugWebGL||t.debug)&&r.push(Wm()),t.debugSpectorJS&&r.push(Lm(t));const s=await Promise.allSettled(r);for(const l of s)l.status==="rejected"&&D.error(`Failed to initialize debug libraries ${l.reason}`)();const o=new i(t),a=`${o._reused?"Reusing":"Created"} device with WebGL2 ${o.props.debug?"debug ":""}context: ${o.info.vendor}, ${o.info.renderer} for canvas: ${o.canvasContext.id}`;return D.probe(Li,a)(),D.table(Li,o.info)(),o}finally{D.groupEnd(Li)()}}}function Zm(n){return typeof WebGL2RenderingContext<"u"&&n instanceof WebGL2RenderingContext?!0:!!(n&&Number.isFinite(n._version))}const Qm=new Km,Ts={3042:!1,32773:new Float32Array([0,0,0,0]),32777:32774,34877:32774,32969:1,32968:0,32971:1,32970:0,3106:new Float32Array([0,0,0,0]),3107:[!0,!0,!0,!0],2884:!1,2885:1029,2929:!1,2931:1,2932:513,2928:new Float32Array([0,1]),2930:!0,3024:!0,35725:null,36006:null,36007:null,34229:null,34964:null,2886:2305,33170:4352,2849:1,32823:!1,32824:0,10752:0,32926:!1,32928:!1,32938:1,32939:!1,3089:!1,3088:new Int32Array([0,0,1024,1024]),2960:!1,2961:0,2968:4294967295,36005:4294967295,2962:519,2967:0,2963:4294967295,34816:519,36003:0,36004:4294967295,2964:7680,2965:7680,2966:7680,34817:7680,34818:7680,34819:7680,2978:[0,0,1024,1024],36389:null,36662:null,36663:null,35053:null,35055:null,35723:4352,36010:null,35977:!1,3333:4,3317:4,37440:!1,37441:!1,37443:37444,3330:0,3332:0,3331:0,3314:0,32878:0,3316:0,3315:0,32877:0},ve=(n,e,t)=>e?n.enable(t):n.disable(t),sl=(n,e,t)=>n.hint(t,e),je=(n,e,t)=>n.pixelStorei(t,e),ol=(n,e,t)=>{const i=t===36006?36009:36008;return n.bindFramebuffer(i,e)},Bn=(n,e,t)=>{const r={34964:34962,36662:36662,36663:36663,35053:35051,35055:35052}[t];n.bindBuffer(r,e)};function ws(n){return Array.isArray(n)||ArrayBuffer.isView(n)&&!(n instanceof DataView)}const Jm={3042:ve,32773:(n,e)=>n.blendColor(...e),32777:"blendEquation",34877:"blendEquation",32969:"blendFunc",32968:"blendFunc",32971:"blendFunc",32970:"blendFunc",3106:(n,e)=>n.clearColor(...e),3107:(n,e)=>n.colorMask(...e),2884:ve,2885:(n,e)=>n.cullFace(e),2929:ve,2931:(n,e)=>n.clearDepth(e),2932:(n,e)=>n.depthFunc(e),2928:(n,e)=>n.depthRange(...e),2930:(n,e)=>n.depthMask(e),3024:ve,35723:sl,35725:(n,e)=>n.useProgram(e),36007:(n,e)=>n.bindRenderbuffer(36161,e),36389:(n,e)=>{var t;return(t=n.bindTransformFeedback)==null?void 0:t.call(n,36386,e)},34229:(n,e)=>n.bindVertexArray(e),36006:ol,36010:ol,34964:Bn,36662:Bn,36663:Bn,35053:Bn,35055:Bn,2886:(n,e)=>n.frontFace(e),33170:sl,2849:(n,e)=>n.lineWidth(e),32823:ve,32824:"polygonOffset",10752:"polygonOffset",35977:ve,32926:ve,32928:ve,32938:"sampleCoverage",32939:"sampleCoverage",3089:ve,3088:(n,e)=>n.scissor(...e),2960:ve,2961:(n,e)=>n.clearStencil(e),2968:(n,e)=>n.stencilMaskSeparate(1028,e),36005:(n,e)=>n.stencilMaskSeparate(1029,e),2962:"stencilFuncFront",2967:"stencilFuncFront",2963:"stencilFuncFront",34816:"stencilFuncBack",36003:"stencilFuncBack",36004:"stencilFuncBack",2964:"stencilOpFront",2965:"stencilOpFront",2966:"stencilOpFront",34817:"stencilOpBack",34818:"stencilOpBack",34819:"stencilOpBack",2978:(n,e)=>n.viewport(...e),34383:ve,10754:ve,12288:ve,12289:ve,12290:ve,12291:ve,12292:ve,12293:ve,12294:ve,12295:ve,3333:je,3317:je,37440:je,37441:je,37443:je,3330:je,3332:je,3331:je,3314:je,32878:je,3316:je,3315:je,32877:je,framebuffer:(n,e)=>{const t=e&&"handle"in e?e.handle:e;return n.bindFramebuffer(36160,t)},blend:(n,e)=>e?n.enable(3042):n.disable(3042),blendColor:(n,e)=>n.blendColor(...e),blendEquation:(n,e)=>{const t=typeof e=="number"?[e,e]:e;n.blendEquationSeparate(...t)},blendFunc:(n,e)=>{const t=(e==null?void 0:e.length)===2?[...e,...e]:e;n.blendFuncSeparate(...t)},clearColor:(n,e)=>n.clearColor(...e),clearDepth:(n,e)=>n.clearDepth(e),clearStencil:(n,e)=>n.clearStencil(e),colorMask:(n,e)=>n.colorMask(...e),cull:(n,e)=>e?n.enable(2884):n.disable(2884),cullFace:(n,e)=>n.cullFace(e),depthTest:(n,e)=>e?n.enable(2929):n.disable(2929),depthFunc:(n,e)=>n.depthFunc(e),depthMask:(n,e)=>n.depthMask(e),depthRange:(n,e)=>n.depthRange(...e),dither:(n,e)=>e?n.enable(3024):n.disable(3024),derivativeHint:(n,e)=>{n.hint(35723,e)},frontFace:(n,e)=>n.frontFace(e),mipmapHint:(n,e)=>n.hint(33170,e),lineWidth:(n,e)=>n.lineWidth(e),polygonOffsetFill:(n,e)=>e?n.enable(32823):n.disable(32823),polygonOffset:(n,e)=>n.polygonOffset(...e),sampleCoverage:(n,e)=>n.sampleCoverage(e[0],e[1]||!1),scissorTest:(n,e)=>e?n.enable(3089):n.disable(3089),scissor:(n,e)=>n.scissor(...e),stencilTest:(n,e)=>e?n.enable(2960):n.disable(2960),stencilMask:(n,e)=>{e=ws(e)?e:[e,e];const[t,i]=e;n.stencilMaskSeparate(1028,t),n.stencilMaskSeparate(1029,i)},stencilFunc:(n,e)=>{e=ws(e)&&e.length===3?[...e,...e]:e;const[t,i,r,s,o,a]=e;n.stencilFuncSeparate(1028,t,i,r),n.stencilFuncSeparate(1029,s,o,a)},stencilOp:(n,e)=>{e=ws(e)&&e.length===3?[...e,...e]:e;const[t,i,r,s,o,a]=e;n.stencilOpSeparate(1028,t,i,r),n.stencilOpSeparate(1029,s,o,a)},viewport:(n,e)=>n.viewport(...e)};function xe(n,e,t){return e[n]!==void 0?e[n]:t[n]}const Gm={blendEquation:(n,e,t)=>n.blendEquationSeparate(xe(32777,e,t),xe(34877,e,t)),blendFunc:(n,e,t)=>n.blendFuncSeparate(xe(32969,e,t),xe(32968,e,t),xe(32971,e,t),xe(32970,e,t)),polygonOffset:(n,e,t)=>n.polygonOffset(xe(32824,e,t),xe(10752,e,t)),sampleCoverage:(n,e,t)=>n.sampleCoverage(xe(32938,e,t),xe(32939,e,t)),stencilFuncFront:(n,e,t)=>n.stencilFuncSeparate(1028,xe(2962,e,t),xe(2967,e,t),xe(2963,e,t)),stencilFuncBack:(n,e,t)=>n.stencilFuncSeparate(1029,xe(34816,e,t),xe(36003,e,t),xe(36004,e,t)),stencilOpFront:(n,e,t)=>n.stencilOpSeparate(1028,xe(2964,e,t),xe(2965,e,t),xe(2966,e,t)),stencilOpBack:(n,e,t)=>n.stencilOpSeparate(1029,xe(34817,e,t),xe(34818,e,t),xe(34819,e,t))},al={enable:(n,e)=>n({[e]:!0}),disable:(n,e)=>n({[e]:!1}),pixelStorei:(n,e,t)=>n({[e]:t}),hint:(n,e,t)=>n({[e]:t}),useProgram:(n,e)=>n({35725:e}),bindRenderbuffer:(n,e,t)=>n({36007:t}),bindTransformFeedback:(n,e,t)=>n({36389:t}),bindVertexArray:(n,e)=>n({34229:e}),bindFramebuffer:(n,e,t)=>{switch(e){case 36160:return n({36006:t,36010:t});case 36009:return n({36006:t});case 36008:return n({36010:t});default:return null}},bindBuffer:(n,e,t)=>{const i={34962:[34964],36662:[36662],36663:[36663],35051:[35053],35052:[35055]}[e];return i?n({[i]:t}):{valueChanged:!0}},blendColor:(n,e,t,i,r)=>n({32773:new Float32Array([e,t,i,r])}),blendEquation:(n,e)=>n({32777:e,34877:e}),blendEquationSeparate:(n,e,t)=>n({32777:e,34877:t}),blendFunc:(n,e,t)=>n({32969:e,32968:t,32971:e,32970:t}),blendFuncSeparate:(n,e,t,i,r)=>n({32969:e,32968:t,32971:i,32970:r}),clearColor:(n,e,t,i,r)=>n({3106:new Float32Array([e,t,i,r])}),clearDepth:(n,e)=>n({2931:e}),clearStencil:(n,e)=>n({2961:e}),colorMask:(n,e,t,i,r)=>n({3107:[e,t,i,r]}),cullFace:(n,e)=>n({2885:e}),depthFunc:(n,e)=>n({2932:e}),depthRange:(n,e,t)=>n({2928:new Float32Array([e,t])}),depthMask:(n,e)=>n({2930:e}),frontFace:(n,e)=>n({2886:e}),lineWidth:(n,e)=>n({2849:e}),polygonOffset:(n,e,t)=>n({32824:e,10752:t}),sampleCoverage:(n,e,t)=>n({32938:e,32939:t}),scissor:(n,e,t,i,r)=>n({3088:new Int32Array([e,t,i,r])}),stencilMask:(n,e)=>n({2968:e,36005:e}),stencilMaskSeparate:(n,e,t)=>n({[e===1028?2968:36005]:t}),stencilFunc:(n,e,t,i)=>n({2962:e,2967:t,2963:i,34816:e,36003:t,36004:i}),stencilFuncSeparate:(n,e,t,i,r)=>n({[e===1028?2962:34816]:t,[e===1028?2967:36003]:i,[e===1028?2963:36004]:r}),stencilOp:(n,e,t,i)=>n({2964:e,2965:t,2966:i,34817:e,34818:t,34819:i}),stencilOpSeparate:(n,e,t,i,r)=>n({[e===1028?2964:34817]:t,[e===1028?2965:34818]:i,[e===1028?2966:34819]:r}),viewport:(n,e,t,i,r)=>n({2978:[e,t,i,r]})},dt=(n,e)=>n.isEnabled(e),ll={3042:dt,2884:dt,2929:dt,3024:dt,32823:dt,32926:dt,32928:dt,3089:dt,2960:dt,35977:dt},eg=new Set([34016,36388,36387,35983,35368,34965,35739,35738,3074,34853,34854,34855,34856,34857,34858,34859,34860,34861,34862,34863,34864,34865,34866,34867,34868,35097,32873,35869,32874,34068]);function fn(n,e){if(ng(e))return;const t={};for(const r in e){const s=Number(r),o=Jm[r];o&&(typeof o=="string"?t[o]=!0:o(n,e[r],s))}const i=n.state&&n.state.cache;if(i)for(const r in t){const s=Gm[r];s(n,e,i)}}function cl(n,e=Ts){if(typeof e=="number"){const r=e,s=ll[r];return s?s(n,r):n.getParameter(r)}const t=Array.isArray(e)?e:Object.keys(e),i={};for(const r of t){const s=ll[r];i[r]=s?s(n,Number(r)):n.getParameter(Number(r))}return i}function tg(n){fn(n,Ts)}function ng(n){for(const e in n)return!1;return!0}function ig(n,e){if(n===e)return!0;if(ul(n)&&ul(e)&&n.length===e.length){for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}return!1}function ul(n){return Array.isArray(n)||ArrayBuffer.isView(n)}class Yt{constructor(e,t){m(this,"gl");m(this,"program",null);m(this,"stateStack",[]);m(this,"enable",!0);m(this,"cache",null);m(this,"log");m(this,"initialized",!1);this.gl=e,this.log=(t==null?void 0:t.log)||(()=>{}),this._updateCache=this._updateCache.bind(this),Object.seal(this)}static get(e){return e.state}push(e={}){this.stateStack.push({})}pop(){const e=this.stateStack[this.stateStack.length-1];fn(this.gl,e),this.stateStack.pop()}trackState(e,t){if(this.cache=t!=null&&t.copyState?cl(e):Object.assign({},Ts),this.initialized)throw new Error("WebGLStateTracker");this.initialized=!0,this.gl.state=this,sg(e);for(const i in al){const r=al[i];rg(e,i,r)}fl(e,"getParameter"),fl(e,"isEnabled")}_updateCache(e){let t=!1,i;const r=this.stateStack.length>0?this.stateStack[this.stateStack.length-1]:null;for(const s in e){const o=e[s],a=this.cache[s];ig(o,a)||(t=!0,i=a,r&&!(s in r)&&(r[s]=a),this.cache[s]=o)}return{valueChanged:t,oldValue:i}}}function fl(n,e){const t=n[e].bind(n);n[e]=function(r){if(r===void 0||eg.has(r))return t(r);const s=Yt.get(n);return r in s.cache||(s.cache[r]=t(r)),s.enable?s.cache[r]:t(r)},Object.defineProperty(n[e],"name",{value:`${e}-from-cache`,configurable:!1})}function rg(n,e,t){if(!n[e])return;const i=n[e].bind(n);n[e]=function(...s){const o=Yt.get(n),{valueChanged:a,oldValue:l}=t(o._updateCache,...s);return a&&i(...s),l},Object.defineProperty(n[e],"name",{value:`${e}-to-cache`,configurable:!1})}function sg(n){const e=n.useProgram.bind(n);n.useProgram=function(i){const r=Yt.get(n);r.program!==i&&(e(i),r.program=i)}}function og(n,e,t){let i="";const r={preserveDrawingBuffer:!0,...t};let s=null;if(s||(s=n.getContext("webgl2",r)),r.failIfMajorPerformanceCaveat&&(i||(i="Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.")),!s&&!t.failIfMajorPerformanceCaveat&&(r.failIfMajorPerformanceCaveat=!1,s=n.getContext("webgl2",r),s.luma||(s.luma={}),s.luma.softwareRenderer=!0),s||(s=n.getContext("webgl",{}),s&&(s=null,i||(i="Your browser only supports WebGL1"))),!s)throw i||(i="Your browser does not support WebGL"),new Error(`Failed to create WebGL context: ${i}`);const{onContextLost:o,onContextRestored:a}=e;return n.addEventListener("webglcontextlost",l=>o(l),!1),n.addEventListener("webglcontextrestored",l=>a(l),!1),s.luma||(s.luma={}),s}function hn(n,e,t){return t[e]===void 0&&(t[e]=n.getExtension(e)||null),t[e]}function ag(n,e){const t=n.getParameter(7936),i=n.getParameter(7937);hn(n,"WEBGL_debug_renderer_info",e);const r=e.WEBGL_debug_renderer_info,s=n.getParameter(r?r.UNMASKED_VENDOR_WEBGL:7936),o=n.getParameter(r?r.UNMASKED_RENDERER_WEBGL:7937),a=s||t,l=o||i,c=n.getParameter(7938),u=hl(a,l),f=lg(a,l),h=cg(a,l);return{type:"webgl",gpu:u,gpuType:h,gpuBackend:f,vendor:a,renderer:l,version:c,shadingLanguage:"glsl",shadingLanguageVersion:300}}function hl(n,e){return/NVIDIA/i.exec(n)||/NVIDIA/i.exec(e)?"nvidia":/INTEL/i.exec(n)||/INTEL/i.exec(e)?"intel":/Apple/i.exec(n)||/Apple/i.exec(e)?"apple":/AMD/i.exec(n)||/AMD/i.exec(e)||/ATI/i.exec(n)||/ATI/i.exec(e)?"amd":/SwiftShader/i.exec(n)||/SwiftShader/i.exec(e)?"software":"unknown"}function lg(n,e){return/Metal/i.exec(n)||/Metal/i.exec(e)?"metal":/ANGLE/i.exec(n)||/ANGLE/i.exec(e)?"opengl":"unknown"}function cg(n,e){if(/SwiftShader/i.exec(n)||/SwiftShader/i.exec(e))return"cpu";switch(hl(n,e)){case"intel":return"integrated";case"software":return"cpu";case"unknown":return"unknown";default:return"discrete"}}function dl(n){switch(n){case"uint8":return 5121;case"sint8":return 5120;case"unorm8":return 5121;case"snorm8":return 5120;case"uint16":return 5123;case"sint16":return 5122;case"unorm16":return 5123;case"snorm16":return 5122;case"uint32":return 5125;case"sint32":return 5124;case"float16":return 5131;case"float32":return 5126}throw new Error(String(n))}const Un="WEBGL_compressed_texture_s3tc",zn="WEBGL_compressed_texture_s3tc_srgb",dn="EXT_texture_compression_rgtc",pn="EXT_texture_compression_bptc",ug="WEBGL_compressed_texture_etc",fg="WEBGL_compressed_texture_astc",hg="WEBGL_compressed_texture_etc1",dg="WEBGL_compressed_texture_pvrtc",pg="WEBGL_compressed_texture_atc",pl="EXT_texture_norm16",ml="EXT_render_snorm",mg="EXT_color_buffer_float",As={"float32-renderable-webgl":["EXT_color_buffer_float"],"float16-renderable-webgl":["EXT_color_buffer_half_float"],"rgb9e5ufloat-renderable-webgl":["WEBGL_render_shared_exponent"],"snorm8-renderable-webgl":[ml],"norm16-renderable-webgl":[pl],"snorm16-renderable-webgl":[pl,ml],"float32-filterable":["OES_texture_float_linear"],"float16-filterable-webgl":["OES_texture_half_float_linear"],"texture-filterable-anisotropic-webgl":["EXT_texture_filter_anisotropic"],"texture-blend-float-webgl":["EXT_float_blend"],"texture-compression-bc":[Un,zn,dn,pn],"texture-compression-bc5-webgl":[dn],"texture-compression-bc7-webgl":[pn],"texture-compression-etc2":[ug],"texture-compression-astc":[fg],"texture-compression-etc1-webgl":[hg],"texture-compression-pvrtc-webgl":[dg],"texture-compression-atc-webgl":[pg]};function gg(n){return n in As}function _g(n,e,t){return(As[e]||[]).every(r=>hn(n,r,t))}const Cs={r8unorm:{gl:33321,rb:!0},r8snorm:{gl:36756},r8uint:{gl:33330,rb:!0},r8sint:{gl:33329,rb:!0},rg8unorm:{gl:33323,rb:!0},rg8snorm:{gl:36757},rg8uint:{gl:33336,rb:!0},rg8sint:{gl:33335,rb:!0},r16uint:{gl:33332,rb:!0},r16sint:{gl:33331,rb:!0},r16float:{gl:33325,rb:!0},r16unorm:{gl:33322,rb:!0},r16snorm:{gl:36760},"rgba4unorm-webgl":{gl:32854,rb:!0},"rgb565unorm-webgl":{gl:36194,rb:!0},"rgb5a1unorm-webgl":{gl:32855,rb:!0},"rgb8unorm-webgl":{gl:32849},"rgb8snorm-webgl":{gl:36758},rgba8unorm:{gl:32856},"rgba8unorm-srgb":{gl:35907},rgba8snorm:{gl:36759},rgba8uint:{gl:36220},rgba8sint:{gl:36238},bgra8unorm:{},"bgra8unorm-srgb":{},rg16uint:{gl:33338},rg16sint:{gl:33337},rg16float:{gl:33327,rb:!0},rg16unorm:{gl:33324},rg16snorm:{gl:36761},r32uint:{gl:33334,rb:!0},r32sint:{gl:33333,rb:!0},r32float:{gl:33326},rgb9e5ufloat:{gl:35901},rg11b10ufloat:{gl:35898,rb:!0},rgb10a2unorm:{gl:32857,rb:!0},rgb10a2uint:{gl:36975,rb:!0},"rgb16unorm-webgl":{gl:32852},"rgb16snorm-webgl":{gl:36762},rg32uint:{gl:33340,rb:!0},rg32sint:{gl:33339,rb:!0},rg32float:{gl:33328,rb:!0},rgba16uint:{gl:36214,rb:!0},rgba16sint:{gl:36232,rb:!0},rgba16float:{gl:34842},rgba16unorm:{gl:32859,rb:!0},rgba16snorm:{gl:36763},"rgb32float-webgl":{gl:34837,x:mg,dataFormat:6407,types:[5126]},rgba32uint:{gl:36208,rb:!0},rgba32sint:{gl:36226,rb:!0},rgba32float:{gl:34836,rb:!0},stencil8:{gl:36168,rb:!0},depth16unorm:{gl:33189,dataFormat:6402,types:[5123],rb:!0},depth24plus:{gl:33190,dataFormat:6402,types:[5125]},depth32float:{gl:36012,dataFormat:6402,types:[5126],rb:!0},"depth24plus-stencil8":{gl:35056,rb:!0,depthTexture:!0,dataFormat:34041,types:[34042]},"depth32float-stencil8":{gl:36013,dataFormat:34041,types:[36269],rb:!0},"bc1-rgb-unorm-webgl":{gl:33776,x:Un},"bc1-rgb-unorm-srgb-webgl":{gl:35916,x:zn},"bc1-rgba-unorm":{gl:33777,x:Un},"bc1-rgba-unorm-srgb":{gl:35916,x:zn},"bc2-rgba-unorm":{gl:33778,x:Un},"bc2-rgba-unorm-srgb":{gl:35918,x:zn},"bc3-rgba-unorm":{gl:33779,x:Un},"bc3-rgba-unorm-srgb":{gl:35919,x:zn},"bc4-r-unorm":{gl:36283,x:dn},"bc4-r-snorm":{gl:36284,x:dn},"bc5-rg-unorm":{gl:36285,x:dn},"bc5-rg-snorm":{gl:36286,x:dn},"bc6h-rgb-ufloat":{gl:36495,x:pn},"bc6h-rgb-float":{gl:36494,x:pn},"bc7-rgba-unorm":{gl:36492,x:pn},"bc7-rgba-unorm-srgb":{gl:36493,x:pn},"etc2-rgb8unorm":{gl:37492},"etc2-rgb8unorm-srgb":{gl:37494},"etc2-rgb8a1unorm":{gl:37496},"etc2-rgb8a1unorm-srgb":{gl:37497},"etc2-rgba8unorm":{gl:37493},"etc2-rgba8unorm-srgb":{gl:37495},"eac-r11unorm":{gl:37488},"eac-r11snorm":{gl:37489},"eac-rg11unorm":{gl:37490},"eac-rg11snorm":{gl:37491},"astc-4x4-unorm":{gl:37808},"astc-4x4-unorm-srgb":{gl:37840},"astc-5x4-unorm":{gl:37809},"astc-5x4-unorm-srgb":{gl:37841},"astc-5x5-unorm":{gl:37810},"astc-5x5-unorm-srgb":{gl:37842},"astc-6x5-unorm":{gl:37811},"astc-6x5-unorm-srgb":{gl:37843},"astc-6x6-unorm":{gl:37812},"astc-6x6-unorm-srgb":{gl:37844},"astc-8x5-unorm":{gl:37813},"astc-8x5-unorm-srgb":{gl:37845},"astc-8x6-unorm":{gl:37814},"astc-8x6-unorm-srgb":{gl:37846},"astc-8x8-unorm":{gl:37815},"astc-8x8-unorm-srgb":{gl:37847},"astc-10x5-unorm":{gl:37819},"astc-10x5-unorm-srgb":{gl:37851},"astc-10x6-unorm":{gl:37817},"astc-10x6-unorm-srgb":{gl:37849},"astc-10x8-unorm":{gl:37818},"astc-10x8-unorm-srgb":{gl:37850},"astc-10x10-unorm":{gl:37819},"astc-10x10-unorm-srgb":{gl:37851},"astc-12x10-unorm":{gl:37820},"astc-12x10-unorm-srgb":{gl:37852},"astc-12x12-unorm":{gl:37821},"astc-12x12-unorm-srgb":{gl:37853},"pvrtc-rgb4unorm-webgl":{gl:35840},"pvrtc-rgba4unorm-webgl":{gl:35842},"pvrtc-rbg2unorm-webgl":{gl:35841},"pvrtc-rgba2unorm-webgl":{gl:35843},"etc1-rbg-unorm-webgl":{gl:36196},"atc-rgb-unorm-webgl":{gl:35986},"atc-rgba-unorm-webgl":{gl:35986},"atc-rgbai-unorm-webgl":{gl:34798}};function xg(n,e,t){let i=e.create;const r=Cs[e.format];return(r==null?void 0:r.gl)===void 0&&(i=!1),r!=null&&r.x&&(i=i&&!!hn(n,r.x,t)),{format:e.format,create:i&&e.create,render:i&&e.render,filter:i&&e.filter,blend:i&&e.blend,store:i&&e.store}}function gl(n){var r;const e=Cs[n],t=bg(n),i=Ht.getInfo(n);return i.compressed&&(e.dataFormat=t),{internalFormat:t,format:(e==null?void 0:e.dataFormat)||vg(i.channels,i.integer,i.normalized,t),type:i.dataType?dl(i.dataType):((r=e==null?void 0:e.types)==null?void 0:r[0])||5121,compressed:i.compressed||!1}}function yg(n){switch(Ht.getInfo(n).attachment){case"depth":return 36096;case"stencil":return 36128;case"depth-stencil":return 33306;default:throw new Error(`Not a depth stencil format: ${n}`)}}function vg(n,e,t,i){if(i===6408||i===6407)return i;switch(n){case"r":return e&&!t?36244:6403;case"rg":return e&&!t?33320:33319;case"rgb":return e&&!t?36248:6407;case"rgba":return e&&!t?36249:6408;case"bgra":throw new Error("bgra pixels not supported by WebGL");default:return 6408}}function bg(n){const e=Cs[n],t=e==null?void 0:e.gl;if(t===void 0)throw new Error(`Unsupported texture format ${n}`);return t}const _l={"depth-clip-control":"EXT_depth_clamp","timer-query-webgl":"EXT_disjoint_timer_query_webgl2","compilation-status-async-webgl":"KHR_parallel_shader_compile","polygon-mode-webgl":"WEBGL_polygon_mode","provoking-vertex-webgl":"WEBGL_provoking_vertex","shader-clip-cull-distance-webgl":"WEBGL_clip_cull_distance","shader-noperspective-interpolation-webgl":"NV_shader_noperspective_interpolation","shader-conservative-depth-webgl":"EXT_conservative_depth"};class Sg extends Zp{constructor(t,i,r){super([],r);m(this,"gl");m(this,"extensions");m(this,"testedFeatures",new Set);this.gl=t,this.extensions=i,hn(t,"EXT_color_buffer_float",i)}*[Symbol.iterator](){const t=this.getFeatures();for(const i of t)this.has(i)&&(yield i);return[]}has(t){var i;return(i=this.disabledFeatures)!=null&&i[t]?!1:(this.testedFeatures.has(t)||(this.testedFeatures.add(t),gg(t)&&_g(this.gl,t,this.extensions)&&this.features.add(t),this.getWebGLFeature(t)&&this.features.add(t)),this.features.has(t))}initializeFeatures(){const t=this.getFeatures().filter(i=>i!=="polygon-mode-webgl");for(const i of t)this.has(i)}getFeatures(){return[...Object.keys(_l),...Object.keys(As)]}getWebGLFeature(t){const i=_l[t];return typeof i=="string"?!!hn(this.gl,i,this.extensions):!!i}}class Tg extends Kp{constructor(t){super();m(this,"gl");m(this,"limits",{});this.gl=t}get maxTextureDimension1D(){return 0}get maxTextureDimension2D(){return this.getParameter(3379)}get maxTextureDimension3D(){return this.getParameter(32883)}get maxTextureArrayLayers(){return this.getParameter(35071)}get maxBindGroups(){return 0}get maxDynamicUniformBuffersPerPipelineLayout(){return 0}get maxDynamicStorageBuffersPerPipelineLayout(){return 0}get maxSampledTexturesPerShaderStage(){return this.getParameter(35660)}get maxSamplersPerShaderStage(){return this.getParameter(35661)}get maxStorageBuffersPerShaderStage(){return 0}get maxStorageTexturesPerShaderStage(){return 0}get maxUniformBuffersPerShaderStage(){return this.getParameter(35375)}get maxUniformBufferBindingSize(){return this.getParameter(35376)}get maxStorageBufferBindingSize(){return 0}get minUniformBufferOffsetAlignment(){return this.getParameter(35380)}get minStorageBufferOffsetAlignment(){return 0}get maxVertexBuffers(){return 16}get maxVertexAttributes(){return this.getParameter(34921)}get maxVertexBufferArrayStride(){return 2048}get maxInterStageShaderVariables(){return this.getParameter(35659)}get maxComputeWorkgroupStorageSize(){return 0}get maxComputeInvocationsPerWorkgroup(){return 0}get maxComputeWorkgroupSizeX(){return 0}get maxComputeWorkgroupSizeY(){return 0}get maxComputeWorkgroupSizeZ(){return 0}get maxComputeWorkgroupsPerDimension(){return 0}getParameter(t){return this.limits[t]===void 0&&(this.limits[t]=this.gl.getParameter(t)),this.limits[t]||0}}class Ln extends Oi{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"colorAttachments",[]);m(this,"depthStencilAttachment",null);const r=i.handle===null;this.device=t,this.gl=t.gl,this.handle=this.props.handle||r?this.props.handle:this.gl.createFramebuffer(),r||(t._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.autoCreateAttachmentTextures(),this.updateAttachments())}destroy(){super.destroy(),!this.destroyed&&this.handle!==null&&this.gl.deleteFramebuffer(this.handle)}updateAttachments(){const t=this.gl.bindFramebuffer(36160,this.handle);for(let i=0;i<this.colorAttachments.length;++i){const r=this.colorAttachments[i];if(r){const s=36064+i;this._attachTextureView(s,r)}}if(this.depthStencilAttachment){const i=yg(this.depthStencilAttachment.props.format);this._attachTextureView(i,this.depthStencilAttachment)}if(this.device.props.debug){const i=this.gl.checkFramebufferStatus(36160);if(i!==36053)throw new Error(`Framebuffer ${Ag(i)}`)}this.gl.bindFramebuffer(36160,t)}_attachTextureView(t,i){const{gl:r}=this.device,{texture:s}=i,o=i.props.baseMipLevel,a=i.props.baseArrayLayer;switch(r.bindTexture(s.glTarget,s.handle),s.glTarget){case 35866:case 32879:r.framebufferTextureLayer(36160,t,s.handle,o,a);break;case 34067:const l=wg(a);r.framebufferTexture2D(36160,t,l,s.handle,o);break;case 3553:r.framebufferTexture2D(36160,t,3553,s.handle,o);break;default:throw new Error("Illegal texture type")}r.bindTexture(s.glTarget,null)}}function wg(n){return n<34069?n+34069:n}function Ag(n){switch(n){case 36053:return"success";case 36054:return"Mismatched attachments";case 36055:return"No attachments";case 36057:return"Height/width mismatch";case 36061:return"Unsupported or split attachments";case 36182:return"Samples mismatch";default:return`${n}`}}class Cg extends Fi{constructor(t,i){super(i);m(this,"device");m(this,"handle",null);m(this,"_framebuffer",null);this.device=t,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._updateDevice()}get[Symbol.toStringTag](){return"WebGLCanvasContext"}getCurrentFramebuffer(){return this._framebuffer=this._framebuffer||new Ln(this.device,{handle:null}),this._framebuffer}_updateDevice(){}}const Is={};function Ig(n="id"){Is[n]=Is[n]||1;const e=Is[n]++;return`${n}-${e}`}class Vn extends L{constructor(t,i={}){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"glTarget");m(this,"glUsage");m(this,"glIndexType",5123);m(this,"byteLength",0);m(this,"bytesUsed",0);this.device=t,this.gl=this.device.gl;const r=typeof i=="object"?i.handle:void 0;this.handle=r||this.gl.createBuffer(),t._setWebGLDebugMetadata(this.handle,this,{spector:{...this.props,data:typeof this.props.data}}),this.glTarget=Pg(this.props.usage),this.glUsage=Eg(this.props.usage),this.glIndexType=this.props.indexType==="uint32"?5125:5123,i.data?this._initWithData(i.data,i.byteOffset,i.byteLength):this._initWithByteLength(i.byteLength||0)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.trackDeallocatedMemory(),this.gl.deleteBuffer(this.handle),this.destroyed=!0,this.handle=null)}_initWithData(t,i=0,r=t.byteLength+i){const s=this.glTarget;this.gl.bindBuffer(s,this.handle),this.gl.bufferData(s,r,this.glUsage),this.gl.bufferSubData(s,i,t),this.gl.bindBuffer(s,null),this.bytesUsed=r,this.byteLength=r,this._setDebugData(t,i,r),this.trackAllocatedMemory(r)}_initWithByteLength(t){let i=t;t===0&&(i=new Float32Array(0));const r=this.glTarget;return this.gl.bindBuffer(r,this.handle),this.gl.bufferData(r,i,this.glUsage),this.gl.bindBuffer(r,null),this.bytesUsed=t,this.byteLength=t,this._setDebugData(null,0,t),this.trackAllocatedMemory(t),this}write(t,i=0){const r=ArrayBuffer.isView(t)?t:new Uint8Array(t),s=36663;this.gl.bindBuffer(s,this.handle),this.gl.bufferSubData(s,i,r),this.gl.bindBuffer(s,null),this._setDebugData(t,i,t.byteLength)}async mapAndWriteAsync(t,i=0,r=this.byteLength-i){const s=new ArrayBuffer(r);await t(s,"copied"),this.write(s,i)}async readAsync(t=0,i){return this.readSyncWebGL(t,i)}async mapAndReadAsync(t,i=0,r){const s=await this.readAsync(i,r);return await t(s.buffer,"copied")}readSyncWebGL(t=0,i){i=i??this.byteLength-t;const r=new Uint8Array(i),s=0;return this.gl.bindBuffer(36662,this.handle),this.gl.getBufferSubData(36662,t,r,s,i),this.gl.bindBuffer(36662,null),this._setDebugData(r,t,i),r}}function Pg(n){return n&L.INDEX?34963:n&L.VERTEX?34962:n&L.UNIFORM?35345:34962}function Eg(n){return n&L.INDEX||n&L.VERTEX?35044:n&L.UNIFORM?35048:35044}function Rg(n){const e=n.split(/\r?\n/),t=[];for(const i of e){if(i.length<=1)continue;const r=i.split(":");if(r.length===2){const[f,h]=r;t.push({message:h.trim(),type:xl(f),lineNum:0,linePos:0});continue}const[s,o,a,...l]=r;let c=parseInt(a,10);isNaN(c)&&(c=0);let u=parseInt(o,10);isNaN(u)&&(u=0),t.push({message:l.join(":").trim(),type:xl(s),lineNum:c,linePos:u})}return t}function xl(n){const e=["warning","error","info"],t=n.toLowerCase();return e.includes(t)?t:"info"}class kg extends Ni{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");switch(this.device=t,this.props.stage){case"vertex":this.handle=this.props.handle||this.device.gl.createShader(35633);break;case"fragment":this.handle=this.props.handle||this.device.gl.createShader(35632);break;default:throw new Error(this.props.stage)}t._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this._compile(this.source)}destroy(){this.handle&&(this.removeStats(),this.device.gl.deleteShader(this.handle),this.destroyed=!0,this.handle.destroyed=!0)}get asyncCompilationStatus(){return this._waitForCompilationComplete().then(()=>(this._getCompilationStatus(),this.compilationStatus))}async getCompilationInfo(){return await this._waitForCompilationComplete(),this.getCompilationInfoSync()}getCompilationInfoSync(){const t=this.device.gl.getShaderInfoLog(this.handle);return t?Rg(t):[]}getTranslatedSource(){const i=this.device.getExtension("WEBGL_debug_shaders").WEBGL_debug_shaders;return(i==null?void 0:i.getTranslatedShaderSource(this.handle))||null}async _compile(t){t=t.startsWith("#version ")?t:`#version 300 es
12
+ ${t}`;const{gl:i}=this.device;if(i.shaderSource(this.handle,t),i.compileShader(this.handle),!this.device.props.debug){this.compilationStatus="pending";return}if(!this.device.features.has("compilation-status-async-webgl")){if(this._getCompilationStatus(),this.debugShader(),this.compilationStatus==="error")throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);return}D.once(1,"Shader compilation is asynchronous")(),await this._waitForCompilationComplete(),D.info(2,`Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)(),this._getCompilationStatus(),this.debugShader()}async _waitForCompilationComplete(){const t=async s=>await new Promise(o=>setTimeout(o,s));if(!this.device.features.has("compilation-status-async-webgl")){await t(10);return}const{gl:r}=this.device;for(;;){if(r.getShaderParameter(this.handle,37297))return;await t(10)}}_getCompilationStatus(){this.compilationStatus=this.device.gl.getShaderParameter(this.handle,35713)?"success":"error"}}function Dg(n,e,t,i){if(Og(e))return i(n);const r=n;r.pushState();try{return Fg(n,e),fn(r.gl,t),i(n)}finally{r.popState()}}function Fg(n,e){const t=n,{gl:i}=t;if(e.cullMode)switch(e.cullMode){case"none":i.disable(2884);break;case"front":i.enable(2884),i.cullFace(1028);break;case"back":i.enable(2884),i.cullFace(1029);break}if(e.frontFace&&i.frontFace(qt("frontFace",e.frontFace,{ccw:2305,cw:2304})),e.unclippedDepth&&n.features.has("depth-clip-control")&&i.enable(34383),e.depthBias!==void 0&&(i.enable(32823),i.polygonOffset(e.depthBias,e.depthBiasSlopeScale||0)),e.provokingVertex&&n.features.has("provoking-vertex-webgl")){const s=t.getExtension("WEBGL_provoking_vertex").WEBGL_provoking_vertex,o=qt("provokingVertex",e.provokingVertex,{first:36429,last:36430});s==null||s.provokingVertexWEBGL(o)}if((e.polygonMode||e.polygonOffsetLine)&&n.features.has("polygon-mode-webgl")){if(e.polygonMode){const s=t.getExtension("WEBGL_polygon_mode").WEBGL_polygon_mode,o=qt("polygonMode",e.polygonMode,{fill:6914,line:6913});s==null||s.polygonModeWEBGL(1028,o),s==null||s.polygonModeWEBGL(1029,o)}e.polygonOffsetLine&&i.enable(10754)}if(n.features.has("shader-clip-cull-distance-webgl")&&(e.clipDistance0&&i.enable(12288),e.clipDistance1&&i.enable(12289),e.clipDistance2&&i.enable(12290),e.clipDistance3&&i.enable(12291),e.clipDistance4&&i.enable(12292),e.clipDistance5&&i.enable(12293),e.clipDistance6&&i.enable(12294),e.clipDistance7&&i.enable(12295)),e.depthWriteEnabled!==void 0&&i.depthMask(Ng("depthWriteEnabled",e.depthWriteEnabled)),e.depthCompare&&(e.depthCompare!=="always"?i.enable(2929):i.disable(2929),i.depthFunc(Ps("depthCompare",e.depthCompare))),e.stencilWriteMask){const r=e.stencilWriteMask;i.stencilMaskSeparate(1028,r),i.stencilMaskSeparate(1029,r)}if(e.stencilReadMask&&D.warn("stencilReadMask not supported under WebGL"),e.stencilCompare){const r=e.stencilReadMask||4294967295,s=Ps("depthCompare",e.stencilCompare);e.stencilCompare!=="always"?i.enable(2960):i.disable(2960),i.stencilFuncSeparate(1028,s,0,r),i.stencilFuncSeparate(1029,s,0,r)}if(e.stencilPassOperation&&e.stencilFailOperation&&e.stencilDepthFailOperation){const r=Es("stencilPassOperation",e.stencilPassOperation),s=Es("stencilFailOperation",e.stencilFailOperation),o=Es("stencilDepthFailOperation",e.stencilDepthFailOperation);i.stencilOpSeparate(1028,s,o,r),i.stencilOpSeparate(1029,s,o,r)}switch(e.blend){case!0:i.enable(3042);break;case!1:i.disable(3042);break}if(e.blendColorOperation||e.blendAlphaOperation){const r=yl("blendColorOperation",e.blendColorOperation||"add"),s=yl("blendAlphaOperation",e.blendAlphaOperation||"add");i.blendEquationSeparate(r,s);const o=Vi("blendColorSrcFactor",e.blendColorSrcFactor||"one"),a=Vi("blendColorDstFactor",e.blendColorDstFactor||"zero"),l=Vi("blendAlphaSrcFactor",e.blendAlphaSrcFactor||"one"),c=Vi("blendAlphaDstFactor",e.blendAlphaDstFactor||"zero");i.blendFuncSeparate(o,a,l,c)}}function Ps(n,e){return qt(n,e,{never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519})}function Es(n,e){return qt(n,e,{keep:7680,zero:0,replace:7681,invert:5386,"increment-clamp":7682,"decrement-clamp":7683,"increment-wrap":34055,"decrement-wrap":34056})}function yl(n,e){return qt(n,e,{add:32774,subtract:32778,"reverse-subtract":32779,min:32775,max:32776})}function Vi(n,e,t="color"){return qt(n,e,{one:1,zero:0,src:768,"one-minus-src":769,dst:774,"one-minus-dst":775,"src-alpha":770,"one-minus-src-alpha":771,"dst-alpha":772,"one-minus-dst-alpha":773,"src-alpha-saturated":776,constant:t==="color"?32769:32771,"one-minus-constant":t==="color"?32770:32772,src1:768,"one-minus-src1":769,"src1-alpha":770,"one-minus-src1-alpha":771})}function Mg(n,e){return`Illegal parameter ${e} for ${n}`}function qt(n,e,t){if(!(e in t))throw new Error(Mg(n,e));return t[e]}function Ng(n,e){return e}function Og(n){let e=!0;for(const t in n){e=!1;break}return e}function vl(n){const e={};return n.addressModeU&&(e[10242]=Rs(n.addressModeU)),n.addressModeV&&(e[10243]=Rs(n.addressModeV)),n.addressModeW&&(e[32882]=Rs(n.addressModeW)),n.magFilter&&(e[10240]=ks(n.magFilter)),(n.minFilter||n.mipmapFilter)&&(e[10241]=Bg(n.minFilter||"linear",n.mipmapFilter)),n.lodMinClamp!==void 0&&(e[33082]=n.lodMinClamp),n.lodMaxClamp!==void 0&&(e[33083]=n.lodMaxClamp),n.type==="comparison-sampler"&&(e[34892]=34894),n.compare&&(e[34893]=Ps("compare",n.compare)),n.maxAnisotropy&&(e[34046]=n.maxAnisotropy),e}function Rs(n){switch(n){case"clamp-to-edge":return 33071;case"repeat":return 10497;case"mirror-repeat":return 33648}}function ks(n){switch(n){case"nearest":return 9728;case"linear":return 9729}}function Bg(n,e="none"){if(!e)return ks(n);switch(e){case"none":return ks(n);case"nearest":switch(n){case"nearest":return 9984;case"linear":return 9985}break;case"linear":switch(n){case"nearest":return 9986;case"linear":return 9987}}}class Ug extends un{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"parameters");this.device=t,this.parameters=vl(i),this.handle=i.handle||this.device.gl.createSampler(),this._setSamplerParameters(this.parameters)}destroy(){this.handle&&(this.device.gl.deleteSampler(this.handle),this.handle=void 0)}toString(){return`Sampler(${this.id},${JSON.stringify(this.props)})`}_setSamplerParameters(t){for(const[i,r]of Object.entries(t)){const s=Number(i);switch(s){case 33082:case 33083:this.device.gl.samplerParameterf(this.handle,s,r);break;default:this.device.gl.samplerParameteri(this.handle,s,r);break}}}}function Hn(n,e,t){if(zg(e))return t(n);const{nocatch:i=!0}=e,r=Yt.get(n);r.push(),fn(n,e);let s;if(i)s=t(n),r.pop();else try{s=t(n)}finally{r.pop()}return s}function zg(n){for(const e in n)return!1;return!0}class mn extends Mi{constructor(t,i){super(t,{...Q.defaultProps,...i});m(this,"device");m(this,"gl");m(this,"handle");m(this,"texture");this.device=t,this.gl=this.device.gl,this.handle=null,this.texture=i.texture}}class Wn extends Q{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"sampler");m(this,"view");m(this,"glTarget");m(this,"glFormat");m(this,"glType");m(this,"glInternalFormat");m(this,"compressed");m(this,"_textureUnit",0);this.device=t,this.gl=this.device.gl;const r=gl(this.props.format);this.glTarget=Lg(this.props.dimension),this.glInternalFormat=r.internalFormat,this.glFormat=r.format,this.glType=r.type,this.compressed=r.compressed,this.handle=this.props.handle||this.gl.createTexture(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.gl.bindTexture(this.glTarget,this.handle);const{dimension:s,width:o,height:a,depth:l,mipLevels:c,glTarget:u,glInternalFormat:f}=this;switch(s){case"2d":case"cube":this.gl.texStorage2D(u,c,f,o,a);break;case"2d-array":case"3d":this.gl.texStorage3D(u,c,f,o,a,l);break;default:throw new Error(s)}this.gl.bindTexture(this.glTarget,null),this._initializeData(i.data),this.setSampler(this.props.sampler),this.view=new mn(this.device,{...this.props,texture:this}),Object.seal(this)}destroy(){this.handle&&(this.gl.deleteTexture(this.handle),this.removeStats(),this.trackDeallocatedMemory("Texture"),this.destroyed=!0)}createView(t){return new mn(this.device,{...t,texture:this})}setSampler(t={}){super.setSampler(t);const i=vl(this.sampler.props);this._setSamplerParameters(i)}copyImageData(t){const i=this._normalizeCopyImageDataOptions(t),r=i.data,{width:s,height:o,depth:a}=this,{mipLevel:l=0,byteOffset:c=0,x:u=0,y:f=0,z:h=0}=i,{glFormat:d,glType:_,compressed:I}=this,P=bl(this.glTarget,this.dimension,h);let A;if(!this.compressed){const{bytesPerPixel:E}=this.device.getTextureFormatInfo(this.format);if(E){if(i.bytesPerRow%E!==0)throw new Error(`bytesPerRow (${i.bytesPerRow}) must be a multiple of bytesPerPixel (${E}) for ${this.format}`);A=i.bytesPerRow/E}}const O=this.compressed?{}:{...A!==void 0?{3314:A}:{},32878:i.rowsPerImage};this.gl.bindTexture(P,this.handle),Hn(this.gl,O,()=>{switch(this.dimension){case"2d":case"cube":I?this.gl.compressedTexSubImage2D(P,l,u,f,s,o,d,r,c):this.gl.texSubImage2D(P,l,u,f,s,o,d,_,r,c);break;case"2d-array":case"3d":I?this.gl.compressedTexSubImage3D(P,l,u,f,h,s,o,a,d,r,c):this.gl.texSubImage3D(P,l,u,f,h,s,o,a,d,_,r,c);break;default:}}),this.gl.bindTexture(P,null)}copyExternalImage(t){const i=this._normalizeCopyExternalImageOptions(t);if(i.sourceX||i.sourceY)throw new Error("WebGL does not support sourceX/sourceY)");const{glFormat:r,glType:s}=this,{image:o,depth:a,mipLevel:l,x:c,y:u,z:f,width:h,height:d}=i,_=bl(this.glTarget,this.dimension,a),I=i.flipY?{37440:!0}:{};return this.gl.bindTexture(this.glTarget,this.handle),Hn(this.gl,I,()=>{switch(this.dimension){case"2d":case"cube":this.gl.texSubImage2D(_,l,c,u,h,d,r,s,o);break;case"2d-array":case"3d":this.gl.texSubImage3D(_,l,c,u,f,h,d,a,r,s,o);break;default:}}),this.gl.bindTexture(this.glTarget,null),{width:i.width,height:i.height}}generateMipmapsWebGL(t){if(!(!(this.device.isTextureFormatRenderable(this.props.format)&&this.device.isTextureFormatFilterable(this.props.format))&&(D.warn(`${this} is not renderable or filterable, may not be able to generate mipmaps`)(),!(t!=null&&t.force))))try{this.gl.bindTexture(this.glTarget,this.handle),this.gl.generateMipmap(this.glTarget)}catch(r){D.warn(`Error generating mipmap for ${this}: ${r.message}`)()}finally{this.gl.bindTexture(this.glTarget,null)}}_setSamplerParameters(t){D.log(2,`${this.id} sampler parameters`,this.device.getGLKeys(t))(),this.gl.bindTexture(this.glTarget,this.handle);for(const[i,r]of Object.entries(t)){const s=Number(i),o=r;switch(s){case 33082:case 33083:this.gl.texParameterf(this.glTarget,s,o);break;case 10240:case 10241:this.gl.texParameteri(this.glTarget,s,o);break;case 10242:case 10243:case 32882:this.gl.texParameteri(this.glTarget,s,o);break;case 34046:this.device.features.has("texture-filterable-anisotropic-webgl")&&this.gl.texParameteri(this.glTarget,s,o);break;case 34892:case 34893:this.gl.texParameteri(this.glTarget,s,o);break}}this.gl.bindTexture(this.glTarget,null)}_getActiveUnit(){return this.gl.getParameter(34016)-33984}_bind(t){const{gl:i}=this;return t!==void 0&&(this._textureUnit=t,i.activeTexture(33984+t)),i.bindTexture(this.glTarget,this.handle),t}_unbind(t){const{gl:i}=this;return t!==void 0&&(this._textureUnit=t,i.activeTexture(33984+t)),i.bindTexture(this.glTarget,null),t}}function Lg(n){switch(n){case"1d":break;case"2d":return 3553;case"3d":return 32879;case"cube":return 34067;case"2d-array":return 35866}throw new Error(n)}function bl(n,e,t){return e==="cube"?34069+t:n}function Vg(n){return Xg[n]}function Ds(n){return $g[n]}function Hg(n){return!!Sl[n]}function Wg(n){return Sl[n]}const $g={5126:"f32",35664:"vec2<f32>",35665:"vec3<f32>",35666:"vec4<f32>",5124:"i32",35667:"vec2<i32>",35668:"vec3<i32>",35669:"vec4<i32>",5125:"u32",36294:"vec2<u32>",36295:"vec3<u32>",36296:"vec4<u32>",35670:"f32",35671:"vec2<f32>",35672:"vec3<f32>",35673:"vec4<f32>",35674:"mat2x2<f32>",35685:"mat2x3<f32>",35686:"mat2x4<f32>",35687:"mat3x2<f32>",35675:"mat3x3<f32>",35688:"mat3x4<f32>",35689:"mat4x2<f32>",35690:"mat4x3<f32>",35676:"mat4x4<f32>"},Sl={35678:{viewDimension:"2d",sampleType:"float"},35680:{viewDimension:"cube",sampleType:"float"},35679:{viewDimension:"3d",sampleType:"float"},35682:{viewDimension:"3d",sampleType:"depth"},36289:{viewDimension:"2d-array",sampleType:"float"},36292:{viewDimension:"2d-array",sampleType:"depth"},36293:{viewDimension:"cube",sampleType:"float"},36298:{viewDimension:"2d",sampleType:"sint"},36299:{viewDimension:"3d",sampleType:"sint"},36300:{viewDimension:"cube",sampleType:"sint"},36303:{viewDimension:"2d-array",sampleType:"uint"},36306:{viewDimension:"2d",sampleType:"uint"},36307:{viewDimension:"3d",sampleType:"uint"},36308:{viewDimension:"cube",sampleType:"uint"},36311:{viewDimension:"2d-array",sampleType:"uint"}},Xg={uint8:5121,sint8:5120,unorm8:5121,snorm8:5120,uint16:5123,sint16:5122,unorm16:5123,snorm16:5122,uint32:5125,sint32:5124,float16:5131,float32:5126};function Yg(n,e){const t={attributes:[],bindings:[]};t.attributes=qg(n,e);const i=Zg(n,e);for(const a of i){const l=a.uniforms.map(c=>({name:c.name,format:c.format,byteOffset:c.byteOffset,byteStride:c.byteStride,arrayLength:c.arrayLength}));t.bindings.push({type:"uniform",name:a.name,group:0,location:a.location,visibility:(a.vertex?1:0)&(a.fragment?2:0),minBindingSize:a.byteLength,uniforms:l})}const r=Kg(n,e);let s=0;for(const a of r)if(Hg(a.type)){const{viewDimension:l,sampleType:c}=Wg(a.type);t.bindings.push({type:"texture",name:a.name,group:0,location:s,viewDimension:l,sampleType:c}),a.textureUnit=s,s+=1}r.length&&(t.uniforms=r);const o=jg(n,e);return o!=null&&o.length&&(t.varyings=o),t}function qg(n,e){const t=[],i=n.getProgramParameter(e,35721);for(let r=0;r<i;r++){const s=n.getActiveAttrib(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a}=s,l=n.getAttribLocation(e,o);if(l>=0){const c=Ds(a),u=/instance/i.test(o)?"instance":"vertex";t.push({name:o,location:l,stepMode:u,type:c})}}return t.sort((r,s)=>r.location-s.location),t}function jg(n,e){const t=[],i=n.getProgramParameter(e,35971);for(let r=0;r<i;r++){const s=n.getTransformFeedbackVarying(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a,size:l}=s,c=Ds(a),{type:u,components:f}=Ja(c);t.push({location:r,name:o,type:u,size:l*f})}return t.sort((r,s)=>r.location-s.location),t}function Kg(n,e){const t=[],i=n.getProgramParameter(e,35718);for(let r=0;r<i;r++){const s=n.getActiveUniform(e,r);if(!s)throw new Error("activeInfo");const{name:o,size:a,type:l}=s,{name:c,isArray:u}=Qg(o);let f=n.getUniformLocation(e,c);const h={location:f,name:c,size:a,type:l,isArray:u};if(t.push(h),h.size>1)for(let d=0;d<h.size;d++){const _=`${c}[${d}]`;f=n.getUniformLocation(e,_);const I={...h,name:_,location:f};t.push(I)}}return t}function Zg(n,e){const t=(s,o)=>n.getActiveUniformBlockParameter(e,s,o),i=[],r=n.getProgramParameter(e,35382);for(let s=0;s<r;s++){const o={name:n.getActiveUniformBlockName(e,s)||"",location:t(s,35391),byteLength:t(s,35392),vertex:t(s,35396),fragment:t(s,35398),uniformCount:t(s,35394),uniforms:[]},a=t(s,35395)||[],l=n.getActiveUniforms(e,a,35383),c=n.getActiveUniforms(e,a,35384),u=n.getActiveUniforms(e,a,35387),f=n.getActiveUniforms(e,a,35388);for(let h=0;h<o.uniformCount;++h){const d=n.getActiveUniform(e,a[h]);if(!d)throw new Error("activeInfo");const _=Ds(l[h]);o.uniforms.push({name:d.name,format:_,type:l[h],arrayLength:c[h],byteOffset:u[h],byteStride:f[h]})}i.push(o)}return i.sort((s,o)=>s.location-o.location),i}function Qg(n){if(n[n.length-1]!=="]")return{name:n,length:1,isArray:!1};const t=/([^[]*)(\[[0-9]+\])?/.exec(n);if(!t||t.length<2)throw new Error(`Failed to parse GLSL uniform name ${n}`);return{name:t[1],length:t[2]?1:0,isArray:!!t[2]}}function Jg(n,e,t,i){const r=n;let s=i;s===!0&&(s=1),s===!1&&(s=0);const o=typeof s=="number"?[s]:s;switch(t){case 35678:case 35680:case 35679:case 35682:case 36289:case 36292:case 36293:case 36298:case 36299:case 36300:case 36303:case 36306:case 36307:case 36308:case 36311:if(typeof i!="number")throw new Error("samplers must be set to integers");return n.uniform1i(e,i);case 5126:return n.uniform1fv(e,o);case 35664:return n.uniform2fv(e,o);case 35665:return n.uniform3fv(e,o);case 35666:return n.uniform4fv(e,o);case 5124:return n.uniform1iv(e,o);case 35667:return n.uniform2iv(e,o);case 35668:return n.uniform3iv(e,o);case 35669:return n.uniform4iv(e,o);case 35670:return n.uniform1iv(e,o);case 35671:return n.uniform2iv(e,o);case 35672:return n.uniform3iv(e,o);case 35673:return n.uniform4iv(e,o);case 5125:return r.uniform1uiv(e,o,1);case 36294:return r.uniform2uiv(e,o,2);case 36295:return r.uniform3uiv(e,o,3);case 36296:return r.uniform4uiv(e,o,4);case 35674:return n.uniformMatrix2fv(e,!1,o);case 35675:return n.uniformMatrix3fv(e,!1,o);case 35676:return n.uniformMatrix4fv(e,!1,o);case 35685:return r.uniformMatrix2x3fv(e,!1,o);case 35686:return r.uniformMatrix2x4fv(e,!1,o);case 35687:return r.uniformMatrix3x2fv(e,!1,o);case 35688:return r.uniformMatrix3x4fv(e,!1,o);case 35689:return r.uniformMatrix4x2fv(e,!1,o);case 35690:return r.uniformMatrix4x3fv(e,!1,o)}throw new Error("Illegal uniform")}function Gg(n){switch(n){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 3;case"triangle-list":return 4;case"triangle-strip":return 5;default:throw new Error(n)}}function e_(n){switch(n){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 1;case"triangle-list":return 4;case"triangle-strip":return 4;default:throw new Error(n)}}const Tl=4;class t_ extends $t{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"vs");m(this,"fs");m(this,"introspectedLayout");m(this,"uniforms",{});m(this,"bindings",{});m(this,"varyings",null);m(this,"_uniformCount",0);m(this,"_uniformSetters",{});this.device=t,this.handle=this.props.handle||this.device.gl.createProgram(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:{id:this.props.id}}),this.vs=i.vs,this.fs=i.fs;const{varyings:r,bufferMode:s=35981}=i;r&&r.length>0&&(this.varyings=r,this.device.gl.transformFeedbackVaryings(this.handle,r,s)),this._linkShaders(),D.time(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.introspectedLayout=Yg(this.device.gl,this.handle),D.timeEnd(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.shaderLayout=i.shaderLayout?n_(this.introspectedLayout,i.shaderLayout):this.introspectedLayout}get[Symbol.toStringTag](){return"WEBGLRenderPipeline"}destroy(){this.handle&&(this.device.gl.useProgram(null),this.device.gl.deleteProgram(this.handle),this.destroyed=!0,this.handle.destroyed=!0,this.handle=null)}setBindings(t,i){for(const[r,s]of Object.entries(t)){const o=this.shaderLayout.bindings.find(a=>a.name===r)||this.shaderLayout.bindings.find(a=>a.name===`${r}Uniforms`);if(!o){const a=this.shaderLayout.bindings.map(l=>`"${l.name}"`).join(", ");i!=null&&i.disableWarnings||D.warn(`No binding "${r}" in render pipeline "${this.id}", expected one of ${a}`,s)();continue}switch(s||D.warn(`Unsetting binding "${r}" in render pipeline "${this.id}"`)(),o.type){case"uniform":if(!(s instanceof Vn)&&!(s.buffer instanceof Vn))throw new Error("buffer value");break;case"texture":if(!(s instanceof mn||s instanceof Wn||s instanceof Ln))throw new Error(`${this} Bad texture binding for ${r}`);break;case"sampler":D.warn(`Ignoring sampler ${r}`)();break;default:throw new Error(o.type)}this.bindings[r]=s}}draw(t){var P;const{renderPass:i,parameters:r=this.props.parameters,topology:s=this.props.topology,vertexArray:o,vertexCount:a,instanceCount:l,isInstanced:c=!1,firstVertex:u=0,transformFeedback:f}=t,h=Gg(s),d=!!o.indexBuffer,_=(P=o.indexBuffer)==null?void 0:P.glIndexType;if(this.linkStatus!=="success")return D.info(2,`RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)(),!1;if(!this._areTexturesRenderable())return D.info(2,`RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)(),!1;this.device.gl.useProgram(this.handle),o.bindBeforeRender(i),f&&f.begin(this.props.topology),this._applyBindings(),this._applyUniforms();const I=i;return Dg(this.device,r,I.glParameters,()=>{d&&c?this.device.gl.drawElementsInstanced(h,a||0,_,u,l||0):d?this.device.gl.drawElements(h,a||0,_,u):c?this.device.gl.drawArraysInstanced(h,u,a||0,l||0):this.device.gl.drawArrays(h,u,a||0),f&&f.end()}),o.unbindAfterRender(i),!0}async _linkShaders(){const{gl:t}=this.device;if(t.attachShader(this.handle,this.vs.handle),t.attachShader(this.handle,this.fs.handle),D.time(Tl,`linkProgram for ${this.id}`)(),t.linkProgram(this.handle),D.timeEnd(Tl,`linkProgram for ${this.id}`)(),D.level,!this.device.features.has("compilation-status-async-webgl")){const r=this._getLinkStatus();this._reportLinkStatus(r);return}D.once(1,"RenderPipeline linking is asynchronous")(),await this._waitForLinkComplete(),D.info(2,`RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();const i=this._getLinkStatus();this._reportLinkStatus(i)}async _reportLinkStatus(t){var i;switch(t){case"success":return;default:const r=t==="link-error"?"Link error":"Validation error";switch(this.vs.compilationStatus){case"error":throw this.vs.debugShader(),new Error(`${this} ${r} during compilation of ${this.vs}`);case"pending":await this.vs.asyncCompilationStatus,this.vs.debugShader();break}switch((i=this.fs)==null?void 0:i.compilationStatus){case"error":throw this.fs.debugShader(),new Error(`${this} ${r} during compilation of ${this.fs}`);case"pending":await this.fs.asyncCompilationStatus,this.fs.debugShader();break}const s=this.device.gl.getProgramInfoLog(this.handle);this.device.reportError(new Error(`${r} during ${t}: ${s}`),this)(),this.device.debug()}}_getLinkStatus(){const{gl:t}=this.device;return t.getProgramParameter(this.handle,35714)?(t.validateProgram(this.handle),t.getProgramParameter(this.handle,35715)?(this.linkStatus="success","success"):(this.linkStatus="error","validation-error")):(this.linkStatus="error","link-error")}async _waitForLinkComplete(){const t=async s=>await new Promise(o=>setTimeout(o,s));if(!this.device.features.has("compilation-status-async-webgl")){await t(10);return}const{gl:r}=this.device;for(;;){if(r.getProgramParameter(this.handle,37297))return;await t(10)}}_areTexturesRenderable(){let t=!0;for(const i of this.shaderLayout.bindings)!this.bindings[i.name]&&!this.bindings[i.name.replace(/Uniforms$/,"")]&&(D.warn(`Binding ${i.name} not found in ${this.id}`)(),t=!1);return t}_applyBindings(){if(this.linkStatus!=="success")return;const{gl:t}=this.device;t.useProgram(this.handle);let i=0,r=0;for(const s of this.shaderLayout.bindings){const o=this.bindings[s.name]||this.bindings[s.name.replace(/Uniforms$/,"")];if(!o)throw new Error(`No value for binding ${s.name} in ${this.id}`);switch(s.type){case"uniform":const{name:a}=s,l=t.getUniformBlockIndex(this.handle,a);if(l===4294967295)throw new Error(`Invalid uniform block name ${a}`);t.uniformBlockBinding(this.handle,r,l),o instanceof Vn?t.bindBufferBase(35345,r,o.handle):t.bindBufferRange(35345,r,o.buffer.handle,o.offset||0,o.size||o.buffer.byteLength-o.offset),r+=1;break;case"texture":if(!(o instanceof mn||o instanceof Wn||o instanceof Ln))throw new Error("texture");let c;if(o instanceof mn)c=o.texture;else if(o instanceof Wn)c=o;else if(o instanceof Ln&&o.colorAttachments[0]instanceof mn)D.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")(),c=o.colorAttachments[0].texture;else throw new Error("No texture");t.activeTexture(33984+i),t.bindTexture(c.glTarget,c.handle),i+=1;break;case"sampler":break;case"storage":case"read-only-storage":throw new Error(`binding type '${s.type}' not supported in WebGL`)}}}_applyUniforms(){for(const t of this.shaderLayout.uniforms||[]){const{name:i,location:r,type:s,textureUnit:o}=t,a=this.uniforms[i]??o;a!==void 0&&Jg(this.device.gl,r,s,a)}}}function n_(n,e){const t={...n,attributes:n.attributes.map(i=>({...i}))};for(const i of(e==null?void 0:e.attributes)||[]){const r=t.attributes.find(s=>s.name===i.name);r?(r.type=i.type||r.type,r.stepMode=i.stepMode||r.stepMode):D.warn(`shader layout attribute ${i.name} not present in shader`)}return t}class i_ extends xs{constructor(t){super(t,{});m(this,"device");m(this,"handle",null);m(this,"commands",[]);this.device=t}_executeCommands(t=this.commands){for(const i of t)switch(i.name){case"copy-buffer-to-buffer":r_(this.device,i.options);break;case"copy-buffer-to-texture":s_(this.device,i.options);break;case"copy-texture-to-buffer":o_(this.device,i.options);break;case"copy-texture-to-texture":a_(this.device,i.options);break;default:throw new Error(i.name)}}}function r_(n,e){const t=e.sourceBuffer,i=e.destinationBuffer;n.gl.bindBuffer(36662,t.handle),n.gl.bindBuffer(36663,i.handle),n.gl.copyBufferSubData(36662,36663,e.sourceOffset??0,e.destinationOffset??0,e.size),n.gl.bindBuffer(36662,null),n.gl.bindBuffer(36663,null)}function s_(n,e){throw new Error("Not implemented")}function o_(n,e){const{sourceTexture:t,mipLevel:i=0,aspect:r="all",width:s=e.sourceTexture.width,height:o=e.sourceTexture.height,depthOrArrayLayers:a=0,origin:l=[0,0],destinationBuffer:c,byteOffset:u=0,bytesPerRow:f,rowsPerImage:h}=e;if(r!=="all")throw new Error("aspect not supported in WebGL");if(i!==0||a!==0||f||h)throw new Error("not implemented");const{framebuffer:d,destroyFramebuffer:_}=wl(t);let I;try{const P=c,A=s||d.width,O=o||d.height,E=gl(d.colorAttachments[0].texture.props.format),y=E.format,R=E.type;n.gl.bindBuffer(35051,P.handle),I=n.gl.bindFramebuffer(36160,d.handle),n.gl.readPixels(l[0],l[1],A,O,y,R,u)}finally{n.gl.bindBuffer(35051,null),I!==void 0&&n.gl.bindFramebuffer(36160,I),_&&d.destroy()}}function a_(n,e){const{sourceTexture:t,destinationMipLevel:i=0,origin:r=[0,0],destinationOrigin:s=[0,0],destinationTexture:o}=e;let{width:a=e.destinationTexture.width,height:l=e.destinationTexture.height}=e;const{framebuffer:c,destroyFramebuffer:u}=wl(t),[f,h]=r,[d,_,I]=s,P=n.gl.bindFramebuffer(36160,c.handle);let A,O;if(o instanceof Wn)A=o,a=Number.isFinite(a)?a:A.width,l=Number.isFinite(l)?l:A.height,A._bind(0),O=A.glTarget;else throw new Error("invalid destination");switch(O){case 3553:case 34067:n.gl.copyTexSubImage2D(O,i,d,_,f,h,a,l);break;case 35866:case 32879:n.gl.copyTexSubImage3D(O,i,d,_,I,f,h,a,l);break}A&&A._unbind(),n.gl.bindFramebuffer(36160,P),u&&c.destroy()}function wl(n){if(n instanceof Q){const{width:e,height:t,id:i}=n;return{framebuffer:n.device.createFramebuffer({id:`framebuffer-for-${i}`,width:e,height:t,colorAttachments:[n]}),destroyFramebuffer:!0}}return{framebuffer:n,destroyFramebuffer:!1}}const l_=[1,2,4,8];class c_ extends gs{constructor(t,i){var o;super(t,i);m(this,"device");m(this,"handle",null);m(this,"glParameters",{});this.device=t;let r;if(!((o=i==null?void 0:i.parameters)!=null&&o.viewport))if(i!=null&&i.framebuffer){const{width:a,height:l}=i.framebuffer;r=[0,0,a,l]}else{const[a,l]=t.getDefaultCanvasContext().getDrawingBufferSize();r=[0,0,a,l]}this.device.pushState(),this.setParameters({viewport:r,...this.props.parameters});const s=this.props.framebuffer;if(this.props.framebuffer&&(s!=null&&s.handle)){const a=this.props.framebuffer.colorAttachments.map((l,c)=>36064+c);this.device.gl.drawBuffers(a)}else this.device.gl.drawBuffers([1029]);this.clear()}end(){this.device.popState()}pushDebugGroup(t){}popDebugGroup(){}insertDebugMarker(t){}setParameters(t={}){const i={...this.glParameters};i.framebuffer=this.props.framebuffer||null,this.props.depthReadOnly&&(i.depthMask=!this.props.depthReadOnly),i.stencilMask=this.props.stencilReadOnly?0:1,i[35977]=this.props.discard,t.viewport&&(t.viewport.length>=6?(i.viewport=t.viewport.slice(0,4),i.depthRange=[t.viewport[4],t.viewport[5]]):i.viewport=t.viewport),t.scissorRect&&(i.scissorTest=!0,i.scissor=t.scissorRect),t.blendConstant&&(i.blendColor=t.blendConstant),t.stencilReference&&(console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL"),i[2967]=t.stencilReference),"colorMask"in t&&(i.colorMask=l_.map(r=>!!(r&t.colorMask))),this.glParameters=i,fn(this.device.gl,i)}beginOcclusionQuery(t){const i=this.props.occlusionQuerySet;i==null||i.beginOcclusionQuery()}endOcclusionQuery(){const t=this.props.occlusionQuerySet;t==null||t.endOcclusionQuery()}clear(){const t={...this.glParameters};let i=0;this.props.clearColors&&this.props.clearColors.forEach((r,s)=>{r&&this.clearColorBuffer(s,r)}),this.props.clearColor!==!1&&this.props.clearColors===void 0&&(i|=16384,t.clearColor=this.props.clearColor),this.props.clearDepth!==!1&&(i|=256,t.clearDepth=this.props.clearDepth),this.props.clearStencil!==!1&&(i|=1024,t.clearStencil=this.props.clearStencil),i!==0&&Hn(this.device.gl,t,()=>{this.device.gl.clear(i)})}clearColorBuffer(t=0,i=[0,0,0,0]){Hn(this.device.gl,{framebuffer:this.props.framebuffer},()=>{switch(i.constructor){case Int8Array:case Int16Array:case Int32Array:this.device.gl.clearBufferiv(6144,t,i);break;case Uint8Array:case Uint8ClampedArray:case Uint16Array:case Uint32Array:this.device.gl.clearBufferuiv(6144,t,i);break;case Float32Array:this.device.gl.clearBufferfv(6144,t,i);break;default:throw new Error("clearColorBuffer: color must be typed array")}})}}class Al extends _s{constructor(t,i){super(t,i);m(this,"device");m(this,"handle",null);m(this,"commandBuffer");this.device=t,this.commandBuffer=new i_(t)}destroy(){}finish(){return this.commandBuffer}beginRenderPass(t){return new c_(this.device,t)}beginComputePass(t){throw new Error("ComputePass not supported in WebGL")}copyBufferToBuffer(t){this.commandBuffer.commands.push({name:"copy-buffer-to-buffer",options:t})}copyBufferToTexture(t){this.commandBuffer.commands.push({name:"copy-buffer-to-texture",options:t})}copyTextureToBuffer(t){this.commandBuffer.commands.push({name:"copy-texture-to-buffer",options:t})}copyTextureToTexture(t){this.commandBuffer.commands.push({name:"copy-texture-to-texture",options:t})}pushDebugGroup(t){}popDebugGroup(){}insertDebugMarker(t){}resolveQuerySet(t,i,r){}}function u_(n){const{target:e,source:t,start:i=0,count:r=1}=n,s=t.length,o=r*s;let a=0;for(let l=i;a<s;a++)e[l++]=t[a];for(;a<o;)a<o-a?(e.copyWithin(i+a,i,i+a),a*=2):(e.copyWithin(i+a,i,i+o-a),a=o);return n.target}class Fs extends ys{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"buffer",null);m(this,"bufferValue",null);this.device=t,this.handle=this.device.gl.createVertexArray()}get[Symbol.toStringTag](){return"VertexArray"}static isConstantAttributeZeroSupported(t){return Sp()==="Chrome"}destroy(){var t;super.destroy(),this.buffer&&((t=this.buffer)==null||t.destroy()),this.handle&&(this.device.gl.deleteVertexArray(this.handle),this.handle=void 0)}setIndexBuffer(t){const i=t;if(i&&i.glTarget!==34963)throw new Error("Use .setBuffer()");this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34963,i?i.handle:null),this.indexBuffer=i,this.device.gl.bindVertexArray(null)}setBuffer(t,i){const r=i;if(r.glTarget===34963)throw new Error("Use .setIndexBuffer()");const{size:s,type:o,stride:a,offset:l,normalized:c,integer:u,divisor:f}=this._getAccessor(t);this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34962,r.handle),u?this.device.gl.vertexAttribIPointer(t,s,o,a,l):this.device.gl.vertexAttribPointer(t,s,o,c,a,l),this.device.gl.bindBuffer(34962,null),this.device.gl.enableVertexAttribArray(t),this.device.gl.vertexAttribDivisor(t,f||0),this.attributes[t]=r,this.device.gl.bindVertexArray(null)}setConstantWebGL(t,i){this._enable(t,!1),this.attributes[t]=i}bindBeforeRender(){this.device.gl.bindVertexArray(this.handle),this._applyConstantAttributes()}unbindAfterRender(){this.device.gl.bindVertexArray(null)}_applyConstantAttributes(){for(let t=0;t<this.maxVertexAttributes;++t){const i=this.attributes[t];ArrayBuffer.isView(i)&&this.device.setConstantAttributeWebGL(t,i)}}_getAccessor(t){const i=this.attributeInfos[t];if(!i)throw new Error(`Unknown attribute location ${t}`);const r=dl(i.bufferDataType);return{size:i.bufferComponents,type:r,stride:i.byteStride,offset:i.byteOffset,normalized:i.normalized,integer:i.integer,divisor:i.stepMode==="instance"?1:0}}_enable(t,i=!0){const s=Fs.isConstantAttributeZeroSupported(this.device)||t!==0;(i||s)&&(t=Number(t),this.device.gl.bindVertexArray(this.handle),i?this.device.gl.enableVertexAttribArray(t):this.device.gl.disableVertexAttribArray(t),this.device.gl.bindVertexArray(null))}getConstantBuffer(t,i){const r=f_(i),s=r.byteLength*t,o=r.length*t;if(this.buffer&&s!==this.buffer.byteLength)throw new Error(`Buffer size is immutable, byte length ${s} !== ${this.buffer.byteLength}.`);let a=!this.buffer;if(this.buffer=this.buffer||this.device.createBuffer({byteLength:s}),a||(a=!h_(r,this.bufferValue)),a){const l=Cm(i.constructor,o);u_({target:l,source:r,start:0,count:o}),this.buffer.write(l),this.bufferValue=i}return this.buffer}}function f_(n){return Array.isArray(n)?new Float32Array(n):n}function h_(n,e){if(!n||!e||n.length!==e.length||n.constructor!==e.constructor)return!1;for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}class d_ extends vs{constructor(t,i){super(t,i);m(this,"device");m(this,"gl");m(this,"handle");m(this,"layout");m(this,"buffers",{});m(this,"unusedBuffers",{});m(this,"bindOnUse",!0);m(this,"_bound",!1);this.device=t,this.gl=t.gl,this.handle=this.props.handle||this.gl.createTransformFeedback(),this.layout=this.props.layout,i.buffers&&this.setBuffers(i.buffers),Object.seal(this)}destroy(){this.gl.deleteTransformFeedback(this.handle),super.destroy()}begin(t="point-list"){this.gl.bindTransformFeedback(36386,this.handle),this.bindOnUse&&this._bindBuffers(),this.gl.beginTransformFeedback(e_(t))}end(){this.gl.endTransformFeedback(),this.bindOnUse&&this._unbindBuffers(),this.gl.bindTransformFeedback(36386,null)}setBuffers(t){this.buffers={},this.unusedBuffers={},this.bind(()=>{for(const i in t)this.setBuffer(i,t[i])})}setBuffer(t,i){const r=this._getVaryingIndex(t),{buffer:s,byteLength:o,byteOffset:a}=this._getBufferRange(i);if(r<0){this.unusedBuffers[t]=s,D.warn(`${this.id} unusedBuffers varying buffer ${t}`)();return}this.buffers[r]={buffer:s,byteLength:o,byteOffset:a},this.bindOnUse||this._bindBuffer(r,s,a,o)}getBuffer(t){if(Cl(t))return this.buffers[t]||null;const i=this._getVaryingIndex(t);return i>=0?this.buffers[i]:null}bind(t=this.handle){if(typeof t!="function")return this.gl.bindTransformFeedback(36386,t),this;let i;return this._bound?i=t():(this.gl.bindTransformFeedback(36386,this.handle),this._bound=!0,i=t(),this._bound=!1,this.gl.bindTransformFeedback(36386,null)),i}unbind(){this.bind(null)}_getBufferRange(t){if(t instanceof Vn)return{buffer:t,byteOffset:0,byteLength:t.byteLength};const{buffer:i,byteOffset:r=0,byteLength:s=t.buffer.byteLength}=t;return{buffer:i,byteOffset:r,byteLength:s}}_getVaryingIndex(t){if(Cl(t))return Number(t);for(const i of this.layout.varyings||[])if(t===i.name)return i.location;return-1}_bindBuffers(){for(const t in this.buffers){const{buffer:i,byteLength:r,byteOffset:s}=this._getBufferRange(this.buffers[t]);this._bindBuffer(Number(t),i,s,r)}}_unbindBuffers(){for(const t in this.buffers)this.gl.bindBufferBase(35982,Number(t),null)}_bindBuffer(t,i,r=0,s){const o=i&&i.handle;!o||s===void 0?this.gl.bindBufferBase(35982,t,o):this.gl.bindBufferRange(35982,t,o,r,s)}}function Cl(n){return typeof n=="number"?Number.isInteger(n):/^\d+$/.test(n)}class p_ extends bs{constructor(t,i){super(t,i);m(this,"device");m(this,"handle");m(this,"target",null);m(this,"_queryPending",!1);m(this,"_pollingPromise",null);if(this.device=t,i.count>1)throw new Error("WebGL QuerySet can only have one value");const r=this.device.gl.createQuery();if(!r)throw new Error("WebGL query not supported");this.handle=r,Object.seal(this)}get[Symbol.toStringTag](){return"Query"}destroy(){this.device.gl.deleteQuery(this.handle)}beginTimestampQuery(){return this._begin(35007)}endTimestampQuery(){this._end()}beginOcclusionQuery(t){return this._begin(t!=null&&t.conservative?36202:35887)}endOcclusionQuery(){this._end()}beginTransformFeedbackQuery(){return this._begin(35976)}endTransformFeedbackQuery(){this._end()}async resolveQuery(){return[await this.pollQuery()]}_begin(t){this._queryPending||(this.target=t,this.device.gl.beginQuery(this.target,this.handle))}_end(){this._queryPending||this.target&&(this.device.gl.endQuery(this.target),this.target=null,this._queryPending=!0)}isResultAvailable(){if(!this._queryPending)return!1;const t=this.device.gl.getQueryParameter(this.handle,34919);return t&&(this._queryPending=!1),t}isTimerDisjoint(){return this.device.gl.getParameter(36795)}getResult(){return this.device.gl.getQueryParameter(this.handle,34918)}getTimerMilliseconds(){return this.getResult()/1e6}pollQuery(t=Number.POSITIVE_INFINITY){if(this._pollingPromise)return this._pollingPromise;let i=0;return this._pollingPromise=new Promise((r,s)=>{const o=()=>{this.isResultAvailable()?(r(this.getResult()),this._pollingPromise=null):i++>t?(s("Timed out"),this._pollingPromise=null):requestAnimationFrame(o)};requestAnimationFrame(o)}),this._pollingPromise}}function Il(n){switch(n){case 6406:case 33326:case 6403:case 36244:return 1;case 33339:case 33340:case 33328:case 33320:case 33319:return 2;case 6407:case 36248:case 34837:return 3;case 6408:case 36249:case 34836:return 4;default:return 0}}function m_(n){switch(n){case 5121:return 1;case 33635:case 32819:case 32820:return 2;case 5126:return 4;default:return 0}}function g_(n){return __[n]}const __={5124:"sint32",5125:"uint32",5122:"sint16",5123:"uint16",5120:"sint8",5121:"uint8",5126:"float32",5131:"float16",33635:"uint16",32819:"uint16",32820:"uint16",33640:"uint32",35899:"uint32",35902:"uint32",34042:"uint32",36269:"uint32"};function x_(n,e){var O;const{sourceX:t=0,sourceY:i=0,sourceAttachment:r=0}=e||{};let{target:s=null,sourceWidth:o,sourceHeight:a,sourceDepth:l,sourceFormat:c,sourceType:u}=e||{};const{framebuffer:f,deleteFramebuffer:h}=Pl(n),{gl:d,handle:_}=f;o||(o=f.width),a||(a=f.height);const I=(O=f.colorAttachments[r])==null?void 0:O.texture;if(!I)throw new Error(`Invalid framebuffer attachment ${r}`);l=(I==null?void 0:I.depth)||1,c||(c=(I==null?void 0:I.glFormat)||6408),u||(u=(I==null?void 0:I.glType)||5121),s=b_(s,u,c,o,a);const P=Wa(s);u=u||Vg(P);const A=d.bindFramebuffer(36160,_);return d.readBuffer(36064+r),d.readPixels(t,i,o,a,c,u,s),d.readBuffer(36064),d.bindFramebuffer(36160,A||null),h&&f.destroy(),s}function y_(n,e){const{target:t,sourceX:i=0,sourceY:r=0,sourceFormat:s=6408,targetByteOffset:o=0}=e||{};let{sourceWidth:a,sourceHeight:l,sourceType:c}=e||{};const{framebuffer:u,deleteFramebuffer:f}=Pl(n);a=a||u.width,l=l||u.height;const h=u;c=c||5121;let d=t;if(!d){const I=Il(s),P=m_(c),A=o+a*l*I*P;d=h.device.createBuffer({byteLength:A})}const _=n.device.createCommandEncoder();return _.copyTextureToBuffer({sourceTexture:n,width:a,height:l,origin:[i,r],destinationBuffer:d,byteOffset:o}),_.destroy(),f&&u.destroy(),d}function Pl(n){return n instanceof Oi?{framebuffer:n,deleteFramebuffer:!1}:{framebuffer:v_(n),deleteFramebuffer:!0}}function v_(n,e){const{device:t,width:i,height:r,id:s}=n;return t.createFramebuffer({...e,id:`framebuffer-for-${s}`,width:i,height:r,colorAttachments:[n]})}function b_(n,e,t,i,r,s){if(n)return n;e||(e=5121);const o=g_(e),a=$a(o),l=Il(t);return new a(i*r*l)}class S_ extends Wt{constructor(t){var f,h;super({...t,id:t.id||Ig("webgl-device")});m(this,"type","webgl");m(this,"handle");m(this,"features");m(this,"limits");m(this,"info");m(this,"canvasContext");m(this,"preferredColorFormat","rgba8unorm");m(this,"preferredDepthFormat","depth24plus");m(this,"commandEncoder");m(this,"lost");m(this,"_resolveContextLost");m(this,"gl");m(this,"_constants");m(this,"_extensions",{});m(this,"_polyfilled",!1);m(this,"spectorJS");const i=Wt._getCanvasContextProps(t);if(!i)throw new Error("WebGLDevice requires props.createCanvasContext to be set");let r=(h=(f=i.canvas)==null?void 0:f.gl)==null?void 0:h.device;if(r)throw new Error(`WebGL context already attached to device ${r.id}`);this.canvasContext=new Cg(this,i),this.lost=new Promise(d=>{this._resolveContextLost=d});const s={...t.webgl};i.alphaMode==="premultiplied"&&(s.premultipliedAlpha=!0),t.powerPreference!==void 0&&(s.powerPreference=t.powerPreference);const a=this.props._handle||og(this.canvasContext.canvas,{onContextLost:d=>{var _;return(_=this._resolveContextLost)==null?void 0:_.call(this,{reason:"destroyed",message:"Entered sleep mode, or too many apps or browser tabs are using the GPU."})},onContextRestored:d=>console.log("WebGL context restored")},s);if(!a)throw new Error("WebGL context creation failed");if(r=a.device,r){if(t._reuseDevices)return D.log(1,`Not creating a new Device, instead returning a reference to Device ${r.id} already attached to WebGL context`,r)(),r._reused=!0,r;throw new Error(`WebGL context already attached to device ${r.id}`)}this.handle=a,this.gl=a,this.spectorJS=Vm({...this.props,gl:this.handle}),this.gl.device=this,this.gl._version=2,this.info=ag(this.gl,this._extensions),this.limits=new Tg(this.gl),this.features=new Sg(this.gl,this._extensions,this.props._disabledFeatures),this.props._initializeFeatures&&this.features.initializeFeatures(),new Yt(this.gl,{log:(...d)=>D.log(1,...d)()}).trackState(this.gl,{copyState:!1});const c=t.debugWebGL||t.debug,u=t.debugWebGL;c&&(this.gl=$m(this.gl,{debugWebGL:c,traceWebGL:u}),D.warn("WebGL debug mode activated. Performance reduced.")(),t.debugWebGL&&(D.level=Math.max(D.level,1))),this.commandEncoder=new Al(this,{id:`${this}-command-encoder`})}get[Symbol.toStringTag](){return"WebGLDevice"}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}isVertexFormatSupported(t){switch(t){case"unorm8x4-bgra":return!1;default:return!0}}destroy(){!this.props._reuseDevices&&!this._reused&&delete this.gl.device}get isLost(){return this.gl.isContextLost()}getTextureByteAlignment(){return 4}createCanvasContext(t){throw new Error("WebGL only supports a single canvas")}createBuffer(t){const i=this._normalizeBufferProps(t);return new Vn(this,i)}createTexture(t){return new Wn(this,t)}createExternalTexture(t){throw new Error("createExternalTexture() not implemented")}createSampler(t){return new Ug(this,t)}createShader(t){return new kg(this,t)}createFramebuffer(t){return new Ln(this,t)}createVertexArray(t){return new Fs(this,t)}createTransformFeedback(t){return new d_(this,t)}createQuerySet(t){return new p_(this,t)}createRenderPipeline(t){return new t_(this,t)}createComputePipeline(t){throw new Error("ComputePipeline not supported in WebGL")}createCommandEncoder(t={}){return new Al(this,t)}submit(t){t||(t=this.commandEncoder.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:`${this.id}-default-encoder`})),t._executeCommands()}readPixelsToArrayWebGL(t,i){return x_(t,i)}readPixelsToBufferWebGL(t,i){return y_(t,i)}setParametersWebGL(t){fn(this.gl,t)}getParametersWebGL(t){return cl(this.gl,t)}withParametersWebGL(t,i){return Hn(this.gl,t,i)}resetWebGL(){D.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")(),tg(this.gl)}_getDeviceSpecificTextureFormatCapabilities(t){return xg(this.gl,t,this._extensions)}loseDevice(){var s;let t=!1;const r=this.getExtension("WEBGL_lose_context").WEBGL_lose_context;return r&&(t=!0,r.loseContext()),(s=this._resolveContextLost)==null||s.call(this,{reason:"destroyed",message:"Application triggered context loss"}),t}pushState(){Yt.get(this.gl).push()}popState(){Yt.get(this.gl).pop()}getGLKey(t,i){const r=Number(t);for(const s in this.gl)if(this.gl[s]===r)return`GL.${s}`;return i!=null&&i.emptyIfUnknown?"":String(t)}getGLKeys(t){const i={emptyIfUnknown:!0};return Object.entries(t).reduce((r,[s,o])=>(r[`${s}:${this.getGLKey(s,i)}`]=`${o}:${this.getGLKey(o,i)}`,r),{})}setConstantAttributeWebGL(t,i){const r=this.limits.maxVertexAttributes;this._constants=this._constants||new Array(r).fill(null);const s=this._constants[t];switch(s&&C_(s,i)&&D.info(1,`setConstantAttributeWebGL(${t}) could have been skipped, value unchanged`)(),this._constants[t]=i,i.constructor){case Float32Array:T_(this,t,i);break;case Int32Array:w_(this,t,i);break;case Uint32Array:A_(this,t,i);break;default:throw new Error("constant")}}getExtension(t){return hn(this.gl,t,this._extensions),this._extensions}_setWebGLDebugMetadata(t,i,r){t.luma=i;const s={props:r.spector,id:r.spector.id};t.__SPECTOR_Metadata=s}}function T_(n,e,t){switch(t.length){case 1:n.gl.vertexAttrib1fv(e,t);break;case 2:n.gl.vertexAttrib2fv(e,t);break;case 3:n.gl.vertexAttrib3fv(e,t);break;case 4:n.gl.vertexAttrib4fv(e,t);break}}function w_(n,e,t){n.gl.vertexAttribI4iv(e,t)}function A_(n,e,t){n.gl.vertexAttribI4uiv(e,t)}function C_(n,e){if(!n||!e||n.length!==e.length||n.constructor!==e.constructor)return!1;for(let t=0;t<n.length;++t)if(n[t]!==e[t])return!1;return!0}const El=Object.freeze(Object.defineProperty({__proto__:null,WebGLDevice:S_},Symbol.toStringTag,{value:"Module"}));/*! @license DOMPurify 3.3.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.3/LICENSE */const{entries:Rl,setPrototypeOf:kl,isFrozen:I_,getPrototypeOf:P_,getOwnPropertyDescriptor:E_}=Object;let{freeze:Le,seal:Je,create:Hi}=Object,{apply:Ms,construct:Ns}=typeof Reflect<"u"&&Reflect;Le||(Le=function(e){return e}),Je||(Je=function(e){return e}),Ms||(Ms=function(e,t){for(var i=arguments.length,r=new Array(i>2?i-2:0),s=2;s<i;s++)r[s-2]=arguments[s];return e.apply(t,r)}),Ns||(Ns=function(e){for(var t=arguments.length,i=new Array(t>1?t-1:0),r=1;r<t;r++)i[r-1]=arguments[r];return new e(...i)});const Wi=He(Array.prototype.forEach),R_=He(Array.prototype.lastIndexOf),Dl=He(Array.prototype.pop),$n=He(Array.prototype.push),k_=He(Array.prototype.splice),$i=He(String.prototype.toLowerCase),Os=He(String.prototype.toString),Bs=He(String.prototype.match),Xn=He(String.prototype.replace),D_=He(String.prototype.indexOf),F_=He(String.prototype.trim),Ke=He(Object.prototype.hasOwnProperty),Ve=He(RegExp.prototype.test),Yn=M_(TypeError);function He(n){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var t=arguments.length,i=new Array(t>1?t-1:0),r=1;r<t;r++)i[r-1]=arguments[r];return Ms(n,e,i)}}function M_(n){return function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return Ns(n,t)}}function ee(n,e){let t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:$i;kl&&kl(n,null);let i=e.length;for(;i--;){let r=e[i];if(typeof r=="string"){const s=t(r);s!==r&&(I_(e)||(e[i]=s),r=s)}n[r]=!0}return n}function N_(n){for(let e=0;e<n.length;e++)Ke(n,e)||(n[e]=null);return n}function pt(n){const e=Hi(null);for(const[t,i]of Rl(n))Ke(n,t)&&(Array.isArray(i)?e[t]=N_(i):i&&typeof i=="object"&&i.constructor===Object?e[t]=pt(i):e[t]=i);return e}function qn(n,e){for(;n!==null;){const i=E_(n,e);if(i){if(i.get)return He(i.get);if(typeof i.value=="function")return He(i.value)}n=P_(n)}function t(){return null}return t}const Fl=Le(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Us=Le(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),zs=Le(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),O_=Le(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Ls=Le(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),B_=Le(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Ml=Le(["#text"]),Nl=Le(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),Vs=Le(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Ol=Le(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Xi=Le(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),U_=Je(/\{\{[\w\W]*|[\w\W]*\}\}/gm),z_=Je(/<%[\w\W]*|[\w\W]*%>/gm),L_=Je(/\$\{[\w\W]*/gm),V_=Je(/^data-[\-\w.\u00B7-\uFFFF]+$/),H_=Je(/^aria-[\-\w]+$/),Bl=Je(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),W_=Je(/^(?:\w+script|data):/i),$_=Je(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ul=Je(/^html$/i),X_=Je(/^[a-z][.\w]*(-[.\w]+)+$/i);var zl=Object.freeze({__proto__:null,ARIA_ATTR:H_,ATTR_WHITESPACE:$_,CUSTOM_ELEMENT:X_,DATA_ATTR:V_,DOCTYPE_NAME:Ul,ERB_EXPR:z_,IS_ALLOWED_URI:Bl,IS_SCRIPT_OR_DATA:W_,MUSTACHE_EXPR:U_,TMPLIT_EXPR:L_});const jn={element:1,text:3,progressingInstruction:7,comment:8,document:9},Y_=function(){return typeof window>"u"?null:window},q_=function(e,t){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let i=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(i=t.getAttribute(r));const s="dompurify"+(i?"#"+i:"");try{return e.createPolicy(s,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return console.warn("TrustedTypes policy "+s+" could not be created."),null}},Ll=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Vl(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Y_();const e=X=>Vl(X);if(e.version="3.3.3",e.removed=[],!n||!n.document||n.document.nodeType!==jn.document||!n.Element)return e.isSupported=!1,e;let{document:t}=n;const i=t,r=i.currentScript,{DocumentFragment:s,HTMLTemplateElement:o,Node:a,Element:l,NodeFilter:c,NamedNodeMap:u=n.NamedNodeMap||n.MozNamedAttrMap,HTMLFormElement:f,DOMParser:h,trustedTypes:d}=n,_=l.prototype,I=qn(_,"cloneNode"),P=qn(_,"remove"),A=qn(_,"nextSibling"),O=qn(_,"childNodes"),E=qn(_,"parentNode");if(typeof o=="function"){const X=t.createElement("template");X.content&&X.content.ownerDocument&&(t=X.content.ownerDocument)}let y,R="";const{implementation:N,createNodeIterator:U,createDocumentFragment:H,getElementsByTagName:Y}=t,{importNode:Z}=i;let B=Ll();e.isSupported=typeof Rl=="function"&&typeof E=="function"&&N&&N.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:he,ERB_EXPR:ie,TMPLIT_EXPR:C,DATA_ATTR:V,ARIA_ATTR:F,IS_SCRIPT_OR_DATA:W,ATTR_WHITESPACE:K,CUSTOM_ELEMENT:q}=zl;let{IS_ALLOWED_URI:G}=zl,J=null;const me=ee({},[...Fl,...Us,...zs,...Ls,...Ml]);let ue=null;const Se=ee({},[...Nl,...Vs,...Ol,...Xi]);let re=Object.seal(Hi(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),$e=null,Be=null;const Ee=Object.seal(Hi(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let bn=!0,Mo=!0,Cu=!1,Iu=!0,Sn=!1,Br=!0,en=!1,No=!1,Oo=!1,Tn=!1,Ur=!1,zr=!1,Pu=!0,Eu=!1;const Wv="user-content-";let Bo=!0,oi=!1,wn={},xt=null;const Uo=ee({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Ru=null;const ku=ee({},["audio","video","img","source","image","track"]);let zo=null;const Du=ee({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Lr="http://www.w3.org/1998/Math/MathML",Vr="http://www.w3.org/2000/svg",Et="http://www.w3.org/1999/xhtml";let An=Et,Lo=!1,Vo=null;const $v=ee({},[Lr,Vr,Et],Os);let Hr=ee({},["mi","mo","mn","ms","mtext"]),Wr=ee({},["annotation-xml"]);const Xv=ee({},["title","style","font","a","script"]);let ai=null;const Yv=["application/xhtml+xml","text/html"],qv="text/html";let Ie=null,Cn=null;const jv=t.createElement("form"),Fu=function(x){return x instanceof RegExp||x instanceof Function},Ho=function(){let x=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Cn&&Cn===x)){if((!x||typeof x!="object")&&(x={}),x=pt(x),ai=Yv.indexOf(x.PARSER_MEDIA_TYPE)===-1?qv:x.PARSER_MEDIA_TYPE,Ie=ai==="application/xhtml+xml"?Os:$i,J=Ke(x,"ALLOWED_TAGS")?ee({},x.ALLOWED_TAGS,Ie):me,ue=Ke(x,"ALLOWED_ATTR")?ee({},x.ALLOWED_ATTR,Ie):Se,Vo=Ke(x,"ALLOWED_NAMESPACES")?ee({},x.ALLOWED_NAMESPACES,Os):$v,zo=Ke(x,"ADD_URI_SAFE_ATTR")?ee(pt(Du),x.ADD_URI_SAFE_ATTR,Ie):Du,Ru=Ke(x,"ADD_DATA_URI_TAGS")?ee(pt(ku),x.ADD_DATA_URI_TAGS,Ie):ku,xt=Ke(x,"FORBID_CONTENTS")?ee({},x.FORBID_CONTENTS,Ie):Uo,$e=Ke(x,"FORBID_TAGS")?ee({},x.FORBID_TAGS,Ie):pt({}),Be=Ke(x,"FORBID_ATTR")?ee({},x.FORBID_ATTR,Ie):pt({}),wn=Ke(x,"USE_PROFILES")?x.USE_PROFILES:!1,bn=x.ALLOW_ARIA_ATTR!==!1,Mo=x.ALLOW_DATA_ATTR!==!1,Cu=x.ALLOW_UNKNOWN_PROTOCOLS||!1,Iu=x.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Sn=x.SAFE_FOR_TEMPLATES||!1,Br=x.SAFE_FOR_XML!==!1,en=x.WHOLE_DOCUMENT||!1,Tn=x.RETURN_DOM||!1,Ur=x.RETURN_DOM_FRAGMENT||!1,zr=x.RETURN_TRUSTED_TYPE||!1,Oo=x.FORCE_BODY||!1,Pu=x.SANITIZE_DOM!==!1,Eu=x.SANITIZE_NAMED_PROPS||!1,Bo=x.KEEP_CONTENT!==!1,oi=x.IN_PLACE||!1,G=x.ALLOWED_URI_REGEXP||Bl,An=x.NAMESPACE||Et,Hr=x.MATHML_TEXT_INTEGRATION_POINTS||Hr,Wr=x.HTML_INTEGRATION_POINTS||Wr,re=x.CUSTOM_ELEMENT_HANDLING||{},x.CUSTOM_ELEMENT_HANDLING&&Fu(x.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(re.tagNameCheck=x.CUSTOM_ELEMENT_HANDLING.tagNameCheck),x.CUSTOM_ELEMENT_HANDLING&&Fu(x.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(re.attributeNameCheck=x.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),x.CUSTOM_ELEMENT_HANDLING&&typeof x.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(re.allowCustomizedBuiltInElements=x.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Sn&&(Mo=!1),Ur&&(Tn=!0),wn&&(J=ee({},Ml),ue=Hi(null),wn.html===!0&&(ee(J,Fl),ee(ue,Nl)),wn.svg===!0&&(ee(J,Us),ee(ue,Vs),ee(ue,Xi)),wn.svgFilters===!0&&(ee(J,zs),ee(ue,Vs),ee(ue,Xi)),wn.mathMl===!0&&(ee(J,Ls),ee(ue,Ol),ee(ue,Xi))),Ke(x,"ADD_TAGS")||(Ee.tagCheck=null),Ke(x,"ADD_ATTR")||(Ee.attributeCheck=null),x.ADD_TAGS&&(typeof x.ADD_TAGS=="function"?Ee.tagCheck=x.ADD_TAGS:(J===me&&(J=pt(J)),ee(J,x.ADD_TAGS,Ie))),x.ADD_ATTR&&(typeof x.ADD_ATTR=="function"?Ee.attributeCheck=x.ADD_ATTR:(ue===Se&&(ue=pt(ue)),ee(ue,x.ADD_ATTR,Ie))),x.ADD_URI_SAFE_ATTR&&ee(zo,x.ADD_URI_SAFE_ATTR,Ie),x.FORBID_CONTENTS&&(xt===Uo&&(xt=pt(xt)),ee(xt,x.FORBID_CONTENTS,Ie)),x.ADD_FORBID_CONTENTS&&(xt===Uo&&(xt=pt(xt)),ee(xt,x.ADD_FORBID_CONTENTS,Ie)),Bo&&(J["#text"]=!0),en&&ee(J,["html","head","body"]),J.table&&(ee(J,["tbody"]),delete $e.tbody),x.TRUSTED_TYPES_POLICY){if(typeof x.TRUSTED_TYPES_POLICY.createHTML!="function")throw Yn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof x.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Yn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');y=x.TRUSTED_TYPES_POLICY,R=y.createHTML("")}else y===void 0&&(y=q_(d,r)),y!==null&&typeof R=="string"&&(R=y.createHTML(""));Le&&Le(x),Cn=x}},Mu=ee({},[...Us,...zs,...O_]),Nu=ee({},[...Ls,...B_]),Kv=function(x){let M=E(x);(!M||!M.tagName)&&(M={namespaceURI:An,tagName:"template"});const $=$i(x.tagName),ge=$i(M.tagName);return Vo[x.namespaceURI]?x.namespaceURI===Vr?M.namespaceURI===Et?$==="svg":M.namespaceURI===Lr?$==="svg"&&(ge==="annotation-xml"||Hr[ge]):!!Mu[$]:x.namespaceURI===Lr?M.namespaceURI===Et?$==="math":M.namespaceURI===Vr?$==="math"&&Wr[ge]:!!Nu[$]:x.namespaceURI===Et?M.namespaceURI===Vr&&!Wr[ge]||M.namespaceURI===Lr&&!Hr[ge]?!1:!Nu[$]&&(Xv[$]||!Mu[$]):!!(ai==="application/xhtml+xml"&&Vo[x.namespaceURI]):!1},yt=function(x){$n(e.removed,{element:x});try{E(x).removeChild(x)}catch{P(x)}},tn=function(x,M){try{$n(e.removed,{attribute:M.getAttributeNode(x),from:M})}catch{$n(e.removed,{attribute:null,from:M})}if(M.removeAttribute(x),x==="is")if(Tn||Ur)try{yt(M)}catch{}else try{M.setAttribute(x,"")}catch{}},Ou=function(x){let M=null,$=null;if(Oo)x="<remove></remove>"+x;else{const Te=Bs(x,/^[\r\n\t ]+/);$=Te&&Te[0]}ai==="application/xhtml+xml"&&An===Et&&(x='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+x+"</body></html>");const ge=y?y.createHTML(x):x;if(An===Et)try{M=new h().parseFromString(ge,ai)}catch{}if(!M||!M.documentElement){M=N.createDocument(An,"template",null);try{M.documentElement.innerHTML=Lo?R:ge}catch{}}const Ue=M.body||M.documentElement;return x&&$&&Ue.insertBefore(t.createTextNode($),Ue.childNodes[0]||null),An===Et?Y.call(M,en?"html":"body")[0]:en?M.documentElement:Ue},Bu=function(x){return U.call(x.ownerDocument||x,x,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Wo=function(x){return x instanceof f&&(typeof x.nodeName!="string"||typeof x.textContent!="string"||typeof x.removeChild!="function"||!(x.attributes instanceof u)||typeof x.removeAttribute!="function"||typeof x.setAttribute!="function"||typeof x.namespaceURI!="string"||typeof x.insertBefore!="function"||typeof x.hasChildNodes!="function")},Uu=function(x){return typeof a=="function"&&x instanceof a};function Rt(X,x,M){Wi(X,$=>{$.call(e,x,M,Cn)})}const zu=function(x){let M=null;if(Rt(B.beforeSanitizeElements,x,null),Wo(x))return yt(x),!0;const $=Ie(x.nodeName);if(Rt(B.uponSanitizeElement,x,{tagName:$,allowedTags:J}),Br&&x.hasChildNodes()&&!Uu(x.firstElementChild)&&Ve(/<[/\w!]/g,x.innerHTML)&&Ve(/<[/\w!]/g,x.textContent)||x.nodeType===jn.progressingInstruction||Br&&x.nodeType===jn.comment&&Ve(/<[/\w]/g,x.data))return yt(x),!0;if(!(Ee.tagCheck instanceof Function&&Ee.tagCheck($))&&(!J[$]||$e[$])){if(!$e[$]&&Vu($)&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,$)||re.tagNameCheck instanceof Function&&re.tagNameCheck($)))return!1;if(Bo&&!xt[$]){const ge=E(x)||x.parentNode,Ue=O(x)||x.childNodes;if(Ue&&ge){const Te=Ue.length;for(let Ye=Te-1;Ye>=0;--Ye){const kt=I(Ue[Ye],!0);kt.__removalCount=(x.__removalCount||0)+1,ge.insertBefore(kt,A(x))}}}return yt(x),!0}return x instanceof l&&!Kv(x)||($==="noscript"||$==="noembed"||$==="noframes")&&Ve(/<\/no(script|embed|frames)/i,x.innerHTML)?(yt(x),!0):(Sn&&x.nodeType===jn.text&&(M=x.textContent,Wi([he,ie,C],ge=>{M=Xn(M,ge," ")}),x.textContent!==M&&($n(e.removed,{element:x.cloneNode()}),x.textContent=M)),Rt(B.afterSanitizeElements,x,null),!1)},Lu=function(x,M,$){if(Be[M]||Pu&&(M==="id"||M==="name")&&($ in t||$ in jv))return!1;if(!(Mo&&!Be[M]&&Ve(V,M))){if(!(bn&&Ve(F,M))){if(!(Ee.attributeCheck instanceof Function&&Ee.attributeCheck(M,x))){if(!ue[M]||Be[M]){if(!(Vu(x)&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,x)||re.tagNameCheck instanceof Function&&re.tagNameCheck(x))&&(re.attributeNameCheck instanceof RegExp&&Ve(re.attributeNameCheck,M)||re.attributeNameCheck instanceof Function&&re.attributeNameCheck(M,x))||M==="is"&&re.allowCustomizedBuiltInElements&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,$)||re.tagNameCheck instanceof Function&&re.tagNameCheck($))))return!1}else if(!zo[M]){if(!Ve(G,Xn($,K,""))){if(!((M==="src"||M==="xlink:href"||M==="href")&&x!=="script"&&D_($,"data:")===0&&Ru[x])){if(!(Cu&&!Ve(W,Xn($,K,"")))){if($)return!1}}}}}}}return!0},Vu=function(x){return x!=="annotation-xml"&&Bs(x,q)},Hu=function(x){Rt(B.beforeSanitizeAttributes,x,null);const{attributes:M}=x;if(!M||Wo(x))return;const $={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ue,forceKeepAttr:void 0};let ge=M.length;for(;ge--;){const Ue=M[ge],{name:Te,namespaceURI:Ye,value:kt}=Ue,In=Ie(Te),$o=kt;let De=Te==="value"?$o:F_($o);if($.attrName=In,$.attrValue=De,$.keepAttr=!0,$.forceKeepAttr=void 0,Rt(B.uponSanitizeAttribute,x,$),De=$.attrValue,Eu&&(In==="id"||In==="name")&&(tn(Te,x),De=Wv+De),Br&&Ve(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,De)){tn(Te,x);continue}if(In==="attributename"&&Bs(De,"href")){tn(Te,x);continue}if($.forceKeepAttr)continue;if(!$.keepAttr){tn(Te,x);continue}if(!Iu&&Ve(/\/>/i,De)){tn(Te,x);continue}Sn&&Wi([he,ie,C],$u=>{De=Xn(De,$u," ")});const Wu=Ie(x.nodeName);if(!Lu(Wu,In,De)){tn(Te,x);continue}if(y&&typeof d=="object"&&typeof d.getAttributeType=="function"&&!Ye)switch(d.getAttributeType(Wu,In)){case"TrustedHTML":{De=y.createHTML(De);break}case"TrustedScriptURL":{De=y.createScriptURL(De);break}}if(De!==$o)try{Ye?x.setAttributeNS(Ye,Te,De):x.setAttribute(Te,De),Wo(x)?yt(x):Dl(e.removed)}catch{tn(Te,x)}}Rt(B.afterSanitizeAttributes,x,null)},Zv=function X(x){let M=null;const $=Bu(x);for(Rt(B.beforeSanitizeShadowDOM,x,null);M=$.nextNode();)Rt(B.uponSanitizeShadowNode,M,null),zu(M),Hu(M),M.content instanceof s&&X(M.content);Rt(B.afterSanitizeShadowDOM,x,null)};return e.sanitize=function(X){let x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},M=null,$=null,ge=null,Ue=null;if(Lo=!X,Lo&&(X="<!-->"),typeof X!="string"&&!Uu(X))if(typeof X.toString=="function"){if(X=X.toString(),typeof X!="string")throw Yn("dirty is not a string, aborting")}else throw Yn("toString is not a function");if(!e.isSupported)return X;if(No||Ho(x),e.removed=[],typeof X=="string"&&(oi=!1),oi){if(X.nodeName){const kt=Ie(X.nodeName);if(!J[kt]||$e[kt])throw Yn("root node is forbidden and cannot be sanitized in-place")}}else if(X instanceof a)M=Ou("<!---->"),$=M.ownerDocument.importNode(X,!0),$.nodeType===jn.element&&$.nodeName==="BODY"||$.nodeName==="HTML"?M=$:M.appendChild($);else{if(!Tn&&!Sn&&!en&&X.indexOf("<")===-1)return y&&zr?y.createHTML(X):X;if(M=Ou(X),!M)return Tn?null:zr?R:""}M&&Oo&&yt(M.firstChild);const Te=Bu(oi?X:M);for(;ge=Te.nextNode();)zu(ge),Hu(ge),ge.content instanceof s&&Zv(ge.content);if(oi)return X;if(Tn){if(Ur)for(Ue=H.call(M.ownerDocument);M.firstChild;)Ue.appendChild(M.firstChild);else Ue=M;return(ue.shadowroot||ue.shadowrootmode)&&(Ue=Z.call(i,Ue,!0)),Ue}let Ye=en?M.outerHTML:M.innerHTML;return en&&J["!doctype"]&&M.ownerDocument&&M.ownerDocument.doctype&&M.ownerDocument.doctype.name&&Ve(Ul,M.ownerDocument.doctype.name)&&(Ye="<!DOCTYPE "+M.ownerDocument.doctype.name+`>
13
+ `+Ye),Sn&&Wi([he,ie,C],kt=>{Ye=Xn(Ye,kt," ")}),y&&zr?y.createHTML(Ye):Ye},e.setConfig=function(){let X=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ho(X),No=!0},e.clearConfig=function(){Cn=null,No=!1},e.isValidAttribute=function(X,x,M){Cn||Ho({});const $=Ie(X),ge=Ie(x);return Lu($,ge,M)},e.addHook=function(X,x){typeof x=="function"&&$n(B[X],x)},e.removeHook=function(X,x){if(x!==void 0){const M=R_(B[X],x);return M===-1?void 0:k_(B[X],M,1)[0]}return Dl(B[X])},e.removeHooks=function(X){B[X]=[]},e.removeAllHooks=function(){B=Ll()},e}var j_=Vl();function Yi(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function K_(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function Hl(n){let e,t,i;n.length!==2?(e=Yi,t=(a,l)=>Yi(n(a),l),i=(a,l)=>n(a)-l):(e=n===Yi||n===K_?n:Z_,t=n,i=n);function r(a,l,c=0,u=a.length){if(c<u){if(e(l,l)!==0)return u;do{const f=c+u>>>1;t(a[f],l)<0?c=f+1:u=f}while(c<u)}return c}function s(a,l,c=0,u=a.length){if(c<u){if(e(l,l)!==0)return u;do{const f=c+u>>>1;t(a[f],l)<=0?c=f+1:u=f}while(c<u)}return c}function o(a,l,c=0,u=a.length){const f=r(a,l,c,u-1);return f>c&&i(a[f-1],l)>-i(a[f],l)?f-1:f}return{left:r,center:o,right:s}}function Z_(){return 0}function Q_(n){return n===null?NaN:+n}const J_=Hl(Yi).right;Hl(Q_).center;var Hs=Math.sqrt(50),Ws=Math.sqrt(10),$s=Math.sqrt(2);function G_(n,e,t){var i,r=-1,s,o,a;if(e=+e,n=+n,t=+t,n===e&&t>0)return[n];if((i=e<n)&&(s=n,n=e,e=s),(a=Wl(n,e,t))===0||!isFinite(a))return[];if(a>0){let l=Math.round(n/a),c=Math.round(e/a);for(l*a<n&&++l,c*a>e&&--c,o=new Array(s=c-l+1);++r<s;)o[r]=(l+r)*a}else{a=-a;let l=Math.round(n*a),c=Math.round(e*a);for(l/a<n&&++l,c/a>e&&--c,o=new Array(s=c-l+1);++r<s;)o[r]=(l+r)/a}return i&&o.reverse(),o}function Wl(n,e,t){var i=(e-n)/Math.max(0,t),r=Math.floor(Math.log(i)/Math.LN10),s=i/Math.pow(10,r);return r>=0?(s>=Hs?10:s>=Ws?5:s>=$s?2:1)*Math.pow(10,r):-Math.pow(10,-r)/(s>=Hs?10:s>=Ws?5:s>=$s?2:1)}function ex(n,e,t){var i=Math.abs(e-n)/Math.max(0,t),r=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),s=i/r;return s>=Hs?r*=10:s>=Ws?r*=5:s>=$s&&(r*=2),e<n?-r:r}function tx(n,e,t){n=+n,e=+e,t=(r=arguments.length)<2?(e=n,n=0,1):r<3?1:+t;for(var i=-1,r=Math.max(0,Math.ceil((e-n)/t))|0,s=new Array(r);++i<r;)s[i]=n+i*t;return s}function $l(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function nx(n){return function(){return n}}function ix(n){return+n}var Xl=[0,1];function mt(n){return n}function Xs(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:nx(isNaN(e)?NaN:.5)}function rx(n,e){var t;return n>e&&(t=n,n=e,e=t),function(i){return Math.max(n,Math.min(e,i))}}function sx(n,e,t){var i=n[0],r=n[1],s=e[0],o=e[1];return r<i?(i=Xs(r,i),s=t(o,s)):(i=Xs(i,r),s=t(s,o)),function(a){return s(i(a))}}function ox(n,e,t){var i=Math.min(n.length,e.length)-1,r=new Array(i),s=new Array(i),o=-1;for(n[i]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++o<i;)r[o]=Xs(n[o],n[o+1]),s[o]=t(e[o],e[o+1]);return function(a){var l=J_(n,a,1,i)-1;return s[l](r[l](a))}}function Yl(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function ql(){var n=Xl,e=Xl,t=is,i,r,s,o=mt,a,l,c;function u(){var h=Math.min(n.length,e.length);return o!==mt&&(o=rx(n[0],n[h-1])),a=h>2?ox:sx,l=c=null,f}function f(h){return h==null||isNaN(h=+h)?s:(l||(l=a(n.map(i),e,t)))(i(o(h)))}return f.invert=function(h){return o(r((c||(c=a(e,n.map(i),st)))(h)))},f.domain=function(h){return arguments.length?(n=Array.from(h,ix),u()):n.slice()},f.range=function(h){return arguments.length?(e=Array.from(h),u()):e.slice()},f.rangeRound=function(h){return e=Array.from(h),t=rd,u()},f.clamp=function(h){return arguments.length?(o=h?!0:mt,u()):o!==mt},f.interpolate=function(h){return arguments.length?(t=h,u()):t},f.unknown=function(h){return arguments.length?(s=h,f):s},function(h,d){return i=h,r=d,u()}}function ax(){return ql()(mt,mt)}function lx(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function qi(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,i=n.slice(0,t);return[i.length>1?i[0]+i.slice(2):i,+n.slice(t+1)]}function gn(n){return n=qi(Math.abs(n)),n?n[1]:NaN}function cx(n,e){return function(t,i){for(var r=t.length,s=[],o=0,a=n[0],l=0;r>0&&a>0&&(l+a+1>i&&(a=Math.max(1,i-l)),s.push(t.substring(r-=a,r+a)),!((l+=a+1)>i));)a=n[o=(o+1)%n.length];return s.reverse().join(e)}}function ux(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var fx=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function ji(n){if(!(e=fx.exec(n)))throw new Error("invalid format: "+n);var e;return new Ys({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}ji.prototype=Ys.prototype;function Ys(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}Ys.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function hx(n){e:for(var e=n.length,t=1,i=-1,r;t<e;++t)switch(n[t]){case".":i=r=t;break;case"0":i===0&&(i=t),r=t;break;default:if(!+n[t])break e;i>0&&(i=0);break}return i>0?n.slice(0,i)+n.slice(r+1):n}var jl;function dx(n,e){var t=qi(n,e);if(!t)return n+"";var i=t[0],r=t[1],s=r-(jl=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,o=i.length;return s===o?i:s>o?i+new Array(s-o+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+qi(n,Math.max(0,e+s-1))[0]}function Kl(n,e){var t=qi(n,e);if(!t)return n+"";var i=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}const Zl={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:lx,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>Kl(n*100,e),r:Kl,s:dx,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Ql(n){return n}var Jl=Array.prototype.map,Gl=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function px(n){var e=n.grouping===void 0||n.thousands===void 0?Ql:cx(Jl.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",i=n.currency===void 0?"":n.currency[1]+"",r=n.decimal===void 0?".":n.decimal+"",s=n.numerals===void 0?Ql:ux(Jl.call(n.numerals,String)),o=n.percent===void 0?"%":n.percent+"",a=n.minus===void 0?"−":n.minus+"",l=n.nan===void 0?"NaN":n.nan+"";function c(f){f=ji(f);var h=f.fill,d=f.align,_=f.sign,I=f.symbol,P=f.zero,A=f.width,O=f.comma,E=f.precision,y=f.trim,R=f.type;R==="n"?(O=!0,R="g"):Zl[R]||(E===void 0&&(E=12),y=!0,R="g"),(P||h==="0"&&d==="=")&&(P=!0,h="0",d="=");var N=I==="$"?t:I==="#"&&/[boxX]/.test(R)?"0"+R.toLowerCase():"",U=I==="$"?i:/[%p]/.test(R)?o:"",H=Zl[R],Y=/[defgprs%]/.test(R);E=E===void 0?6:/[gprs]/.test(R)?Math.max(1,Math.min(21,E)):Math.max(0,Math.min(20,E));function Z(B){var he=N,ie=U,C,V,F;if(R==="c")ie=H(B)+ie,B="";else{B=+B;var W=B<0||1/B<0;if(B=isNaN(B)?l:H(Math.abs(B),E),y&&(B=hx(B)),W&&+B==0&&_!=="+"&&(W=!1),he=(W?_==="("?_:a:_==="-"||_==="("?"":_)+he,ie=(R==="s"?Gl[8+jl/3]:"")+ie+(W&&_==="("?")":""),Y){for(C=-1,V=B.length;++C<V;)if(F=B.charCodeAt(C),48>F||F>57){ie=(F===46?r+B.slice(C+1):B.slice(C))+ie,B=B.slice(0,C);break}}}O&&!P&&(B=e(B,1/0));var K=he.length+B.length+ie.length,q=K<A?new Array(A-K+1).join(h):"";switch(O&&P&&(B=e(q+B,q.length?A-ie.length:1/0),q=""),d){case"<":B=he+B+ie+q;break;case"=":B=he+q+B+ie;break;case"^":B=q.slice(0,K=q.length>>1)+he+B+ie+q.slice(K);break;default:B=q+he+B+ie;break}return s(B)}return Z.toString=function(){return f+""},Z}function u(f,h){var d=c((f=ji(f),f.type="f",f)),_=Math.max(-8,Math.min(8,Math.floor(gn(h)/3)))*3,I=Math.pow(10,-_),P=Gl[8+_/3];return function(A){return d(I*A)+P}}return{format:c,formatPrefix:u}}var Ki,ec,tc;mx({thousands:",",grouping:[3],currency:["$",""]});function mx(n){return Ki=px(n),ec=Ki.format,tc=Ki.formatPrefix,Ki}function gx(n){return Math.max(0,-gn(Math.abs(n)))}function _x(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(gn(e)/3)))*3-gn(Math.abs(n)))}function xx(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,gn(e)-gn(n))+1}function yx(n,e,t,i){var r=ex(n,e,t),s;switch(i=ji(i??",f"),i.type){case"s":{var o=Math.max(Math.abs(n),Math.abs(e));return i.precision==null&&!isNaN(s=_x(r,o))&&(i.precision=s),tc(i,o)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(s=xx(r,Math.max(Math.abs(n),Math.abs(e))))&&(i.precision=s-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(s=gx(r))&&(i.precision=s-(i.type==="%")*2);break}}return ec(i)}function nc(n){var e=n.domain;return n.ticks=function(t){var i=e();return G_(i[0],i[i.length-1],t??10)},n.tickFormat=function(t,i){var r=e();return yx(r[0],r[r.length-1],t??10,i)},n.nice=function(t){t==null&&(t=10);var i=e(),r=0,s=i.length-1,o=i[r],a=i[s],l,c,u=10;for(a<o&&(c=o,o=a,a=c,c=r,r=s,s=c);u-- >0;){if(c=Wl(o,a,t),c===l)return i[r]=o,i[s]=a,e(i);if(c>0)o=Math.floor(o/c)*c,a=Math.ceil(a/c)*c;else if(c<0)o=Math.ceil(o*c)/c,a=Math.floor(a*c)/c;else break;l=c}return n},n}function qs(){var n=ax();return n.copy=function(){return Yl(n,qs())},$l.apply(n,arguments),nc(n)}function ic(n){return function(e){return e<0?-Math.pow(-e,n):Math.pow(e,n)}}function vx(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)}function bx(n){return n<0?-n*n:n*n}function Sx(n){var e=n(mt,mt),t=1;function i(){return t===1?n(mt,mt):t===.5?n(vx,bx):n(ic(t),ic(1/t))}return e.exponent=function(r){return arguments.length?(t=+r,i()):t},nc(e)}function rc(){var n=Sx(ql());return n.copy=function(){return Yl(n,rc()).exponent(n.exponent())},$l.apply(n,arguments),n}var sc=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var n=0,e=arguments.length;e--;)n+=arguments[e]*arguments[e];return Math.sqrt(n)});function Tx(){var n=new sc(9);return sc!=Float32Array&&(n[1]=0,n[2]=0,n[3]=0,n[5]=0,n[6]=0,n[7]=0),n[0]=1,n[4]=1,n[8]=1,n}function oc(n,e,t){var i=e[0],r=e[1],s=e[2],o=e[3],a=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=t[0],d=t[1];return n[0]=i,n[1]=r,n[2]=s,n[3]=o,n[4]=a,n[5]=l,n[6]=h*i+d*o+c,n[7]=h*r+d*a+u,n[8]=h*s+d*l+f,n}function js(n,e,t){var i=t[0],r=t[1];return n[0]=i*e[0],n[1]=i*e[1],n[2]=i*e[2],n[3]=r*e[3],n[4]=r*e[4],n[5]=r*e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n}function wx(n,e,t){return n[0]=2/e,n[1]=0,n[2]=0,n[3]=0,n[4]=-2/t,n[5]=0,n[6]=-1,n[7]=1,n[8]=1,n}function Ax(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function Cx(n){if(Object.prototype.hasOwnProperty.call(n,"__esModule"))return n;var e=n.default;if(typeof e=="function"){var t=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(i){var r=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return n[i]}})}),t}var Zi={exports:{}},Ix=Zi.exports,ac;function Px(){return ac||(ac=1,function(n){(function(e,t,i){function r(l){var c=this,u=a();c.next=function(){var f=2091639*c.s0+c.c*23283064365386963e-26;return c.s0=c.s1,c.s1=c.s2,c.s2=f-(c.c=f|0)},c.c=1,c.s0=u(" "),c.s1=u(" "),c.s2=u(" "),c.s0-=u(l),c.s0<0&&(c.s0+=1),c.s1-=u(l),c.s1<0&&(c.s1+=1),c.s2-=u(l),c.s2<0&&(c.s2+=1),u=null}function s(l,c){return c.c=l.c,c.s0=l.s0,c.s1=l.s1,c.s2=l.s2,c}function o(l,c){var u=new r(l),f=c&&c.state,h=u.next;return h.int32=function(){return u.next()*4294967296|0},h.double=function(){return h()+(h()*2097152|0)*11102230246251565e-32},h.quick=h,f&&(typeof f=="object"&&s(f,u),h.state=function(){return s(u,{})}),h}function a(){var l=4022871197,c=function(u){u=String(u);for(var f=0;f<u.length;f++){l+=u.charCodeAt(f);var h=.02519603282416938*l;l=h>>>0,h-=l,h*=l,l=h>>>0,h-=l,l+=h*4294967296}return(l>>>0)*23283064365386963e-26};return c}t&&t.exports?t.exports=o:this.alea=o})(Ix,n)}(Zi)),Zi.exports}var Qi={exports:{}},Ex=Qi.exports,lc;function Rx(){return lc||(lc=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.x=0,l.y=0,l.z=0,l.w=0,l.next=function(){var f=l.x^l.x<<11;return l.x=l.y,l.y=l.z,l.z=l.w,l.w^=l.w>>>19^f^f>>>8},a===(a|0)?l.x=a:c+=a;for(var u=0;u<c.length+64;u++)l.x^=c.charCodeAt(u)|0,l.next()}function s(a,l){return l.x=a.x,l.y=a.y,l.z=a.z,l.w=a.w,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xor128=o})(Ex,n)}(Qi)),Qi.exports}var Ji={exports:{}},kx=Ji.exports,cc;function Dx(){return cc||(cc=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.next=function(){var f=l.x^l.x>>>2;return l.x=l.y,l.y=l.z,l.z=l.w,l.w=l.v,(l.d=l.d+362437|0)+(l.v=l.v^l.v<<4^(f^f<<1))|0},l.x=0,l.y=0,l.z=0,l.w=0,l.v=0,a===(a|0)?l.x=a:c+=a;for(var u=0;u<c.length+64;u++)l.x^=c.charCodeAt(u)|0,u==c.length&&(l.d=l.x<<10^l.x>>>4),l.next()}function s(a,l){return l.x=a.x,l.y=a.y,l.z=a.z,l.w=a.w,l.v=a.v,l.d=a.d,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xorwow=o})(kx,n)}(Ji)),Ji.exports}var Gi={exports:{}},Fx=Gi.exports,uc;function Mx(){return uc||(uc=1,function(n){(function(e,t,i){function r(a){var l=this;l.next=function(){var u=l.x,f=l.i,h,d;return h=u[f],h^=h>>>7,d=h^h<<24,h=u[f+1&7],d^=h^h>>>10,h=u[f+3&7],d^=h^h>>>3,h=u[f+4&7],d^=h^h<<7,h=u[f+7&7],h=h^h<<13,d^=h^h<<9,u[f]=d,l.i=f+1&7,d};function c(u,f){var h,d=[];if(f===(f|0))d[0]=f;else for(f=""+f,h=0;h<f.length;++h)d[h&7]=d[h&7]<<15^f.charCodeAt(h)+d[h+1&7]<<13;for(;d.length<8;)d.push(0);for(h=0;h<8&&d[h]===0;++h);for(h==8?d[7]=-1:d[h],u.x=d,u.i=0,h=256;h>0;--h)u.next()}c(l,a)}function s(a,l){return l.x=a.x.slice(),l.i=a.i,l}function o(a,l){a==null&&(a=+new Date);var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(u.x&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xorshift7=o})(Fx,n)}(Gi)),Gi.exports}var er={exports:{}},Nx=er.exports,fc;function Ox(){return fc||(fc=1,function(n){(function(e,t,i){function r(a){var l=this;l.next=function(){var u=l.w,f=l.X,h=l.i,d,_;return l.w=u=u+1640531527|0,_=f[h+34&127],d=f[h=h+1&127],_^=_<<13,d^=d<<17,_^=_>>>15,d^=d>>>12,_=f[h]=_^d,l.i=h,_+(u^u>>>16)|0};function c(u,f){var h,d,_,I,P,A=[],O=128;for(f===(f|0)?(d=f,f=null):(f=f+"\0",d=0,O=Math.max(O,f.length)),_=0,I=-32;I<O;++I)f&&(d^=f.charCodeAt((I+32)%f.length)),I===0&&(P=d),d^=d<<10,d^=d>>>15,d^=d<<4,d^=d>>>13,I>=0&&(P=P+1640531527|0,h=A[I&127]^=d+P,_=h==0?_+1:0);for(_>=128&&(A[(f&&f.length||0)&127]=-1),_=127,I=4*128;I>0;--I)d=A[_+34&127],h=A[_=_+1&127],d^=d<<13,h^=h<<17,d^=d>>>15,h^=h>>>12,A[_]=d^h;u.w=P,u.X=A,u.i=_}c(l,a)}function s(a,l){return l.i=a.i,l.w=a.w,l.X=a.X.slice(),l}function o(a,l){a==null&&(a=+new Date);var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(u.X&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.xor4096=o})(Nx,n)}(er)),er.exports}var tr={exports:{}},Bx=tr.exports,hc;function Ux(){return hc||(hc=1,function(n){(function(e,t,i){function r(a){var l=this,c="";l.next=function(){var f=l.b,h=l.c,d=l.d,_=l.a;return f=f<<25^f>>>7^h,h=h-d|0,d=d<<24^d>>>8^_,_=_-f|0,l.b=f=f<<20^f>>>12^h,l.c=h=h-d|0,l.d=d<<16^h>>>16^_,l.a=_-f|0},l.a=0,l.b=0,l.c=-1640531527,l.d=1367130551,a===Math.floor(a)?(l.a=a/4294967296|0,l.b=a|0):c+=a;for(var u=0;u<c.length+20;u++)l.b^=c.charCodeAt(u)|0,l.next()}function s(a,l){return l.a=a.a,l.b=a.b,l.c=a.c,l.d=a.d,l}function o(a,l){var c=new r(a),u=l&&l.state,f=function(){return(c.next()>>>0)/4294967296};return f.double=function(){do var h=c.next()>>>11,d=(c.next()>>>0)/4294967296,_=(h+d)/(1<<21);while(_===0);return _},f.int32=c.next,f.quick=f,u&&(typeof u=="object"&&s(u,c),f.state=function(){return s(c,{})}),f}t&&t.exports?t.exports=o:this.tychei=o})(Bx,n)}(tr)),tr.exports}var nr={exports:{}};const zx=Cx(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Lx=nr.exports,dc;function Vx(){return dc||(dc=1,function(n){(function(e,t,i){var r=256,s=6,o=52,a="random",l=i.pow(r,s),c=i.pow(2,o),u=c*2,f=r-1,h;function d(y,R,N){var U=[];R=R==!0?{entropy:!0}:R||{};var H=A(P(R.entropy?[y,E(t)]:y??O(),3),U),Y=new _(U),Z=function(){for(var B=Y.g(s),he=l,ie=0;B<c;)B=(B+ie)*r,he*=r,ie=Y.g(1);for(;B>=u;)B/=2,he/=2,ie>>>=1;return(B+ie)/he};return Z.int32=function(){return Y.g(4)|0},Z.quick=function(){return Y.g(4)/4294967296},Z.double=Z,A(E(Y.S),t),(R.pass||N||function(B,he,ie,C){return C&&(C.S&&I(C,Y),B.state=function(){return I(Y,{})}),ie?(i[a]=B,he):B})(Z,H,"global"in R?R.global:this==i,R.state)}function _(y){var R,N=y.length,U=this,H=0,Y=U.i=U.j=0,Z=U.S=[];for(N||(y=[N++]);H<r;)Z[H]=H++;for(H=0;H<r;H++)Z[H]=Z[Y=f&Y+y[H%N]+(R=Z[H])],Z[Y]=R;(U.g=function(B){for(var he,ie=0,C=U.i,V=U.j,F=U.S;B--;)he=F[C=f&C+1],ie=ie*r+F[f&(F[C]=F[V=f&V+he])+(F[V]=he)];return U.i=C,U.j=V,ie})(r)}function I(y,R){return R.i=y.i,R.j=y.j,R.S=y.S.slice(),R}function P(y,R){var N=[],U=typeof y,H;if(R&&U=="object")for(H in y)try{N.push(P(y[H],R-1))}catch{}return N.length?N:U=="string"?y:y+"\0"}function A(y,R){for(var N=y+"",U,H=0;H<N.length;)R[f&H]=f&(U^=R[f&H]*19)+N.charCodeAt(H++);return E(R)}function O(){try{var y;return h&&(y=h.randomBytes)?y=y(r):(y=new Uint8Array(r),(e.crypto||e.msCrypto).getRandomValues(y)),E(y)}catch{var R=e.navigator,N=R&&R.plugins;return[+new Date,e,N,e.screen,E(t)]}}function E(y){return String.fromCharCode.apply(0,y)}if(A(i.random(),t),n.exports){n.exports=d;try{h=zx}catch{}}else i["seed"+a]=d})(typeof self<"u"?self:Lx,[],Math)}(nr)),nr.exports}var Ks,pc;function Hx(){if(pc)return Ks;pc=1;var n=Px(),e=Rx(),t=Dx(),i=Mx(),r=Ox(),s=Ux(),o=Vx();return o.alea=n,o.xor128=e,o.xorwow=t,o.xorshift7=i,o.xor4096=r,o.tychei=s,Ks=o,Ks}var Wx=Hx();const $x=Ax(Wx);function Xx(n,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,qx(i.key),i)}}function Zs(n,e,t){return e&&Xx(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),n}function mc(n,e){n.prototype=Object.create(e.prototype),n.prototype.constructor=n,Qs(n,e)}function Qs(n,e){return Qs=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,r){return i.__proto__=r,i},Qs(n,e)}function Yx(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var i=t.call(n,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}function qx(n){var e=Yx(n,"string");return typeof e=="symbol"?e:String(e)}var ir=function(){function n(){}var e=n.prototype;return e._seed=function(i,r){if(i===(i||0))return i;for(var s=""+i,o=0,a=0;a<s.length;++a)o^=s.charCodeAt(a)|0;return o},n}(),gc=function(n){mc(e,n);function e(i,r){var s;return s=n.call(this)||this,s._rng=void 0,s.seed(i,r),s}var t=e.prototype;return t.next=function(){return this._rng()},t.seed=function(r,s){this._rng=r},t.clone=function(r,s){return new e(this._rng,s)},Zs(e,[{key:"name",get:function(){return"function"}}]),e}(ir),_c=function(){var n=[].slice.call(arguments),e=n,t=e[0],i=t===void 0?"default":t;switch(typeof i){case"object":if(i instanceof ir)return i;break;case"function":return new gc(i);case"number":case"string":default:return new gc($x.apply(void 0,n))}throw new Error('invalid RNG "'+i+'"')},jx=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){return n.next()*(t-e)+e}};function ot(n){return new Kx(n)}var Kx=function(e){var t=this;this.n=void 0,this.isInt=function(){if(Number.isInteger(t.n))return t;throw new Error("Expected number to be an integer, got "+t.n)},this.isPositive=function(){if(t.n>0)return t;throw new Error("Expected number to be positive, got "+t.n)},this.lessThan=function(i){if(t.n<i)return t;throw new Error("Expected number to be less than "+i+", got "+t.n)},this.greaterThanOrEqual=function(i){if(t.n>=i)return t;throw new Error("Expected number to be greater than or equal to "+i+", got "+t.n)},this.greaterThan=function(i){if(t.n>i)return t;throw new Error("Expected number to be greater than "+i+", got "+t.n)},this.n=e},Zx=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),t===void 0&&(t=e===void 0?1:e,e=0),ot(e).isInt(),ot(t).isInt(),function(){return Math.floor(n.next()*(t-e+1)+e)}},Qx=function(n){return function(){return n.next()>=.5}},Jx=function(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){var i,r,s;do i=n.next()*2-1,r=n.next()*2-1,s=i*i+r*r;while(!s||s>1);return e+t*r*Math.sqrt(-2*Math.log(s)/s)}},Gx=function(n,e,t){e===void 0&&(e=0),t===void 0&&(t=1);var i=n.normal(e,t);return function(){return Math.exp(i())}},ey=function(n,e){return e===void 0&&(e=.5),ot(e).greaterThanOrEqual(0).lessThan(1),function(){return Math.floor(n.next()+e)}},ty=function(n,e,t){return e===void 0&&(e=1),t===void 0&&(t=.5),ot(e).isInt().isPositive(),ot(t).greaterThanOrEqual(0).lessThan(1),function(){for(var i=0,r=0;i++<e;)n.next()<t&&r++;return r}},ny=function(n,e){e===void 0&&(e=.5),ot(e).greaterThan(0).lessThan(1);var t=1/Math.log(1-e);return function(){return Math.floor(1+Math.log(n.next())*t)}},iy=[0,0,.6931471805599453,1.791759469228055,3.1780538303479458,4.787491742782046,6.579251212010101,8.525161361065415,10.60460290274525,12.801827480081469],ry=function(e){return iy[e]},sy=.9189385332046727,oy=function(n,e){if(e===void 0&&(e=1),ot(e).isPositive(),e<10){var t=Math.exp(-e);return function(){for(var l=t,c=0,u=n.next();u>l;)u=u-l,l=e*l/++c;return c}}else{var i=Math.sqrt(e),r=.931+2.53*i,s=-.059+.02483*r,o=1.1239+1.1328/(r-3.4),a=.9277-3.6224/(r-2);return function(){for(;;){var l=void 0,c=n.next();if(c<=.86*a)return l=c/a-.43,Math.floor((2*s/(.5-Math.abs(l))+r)*l+e+.445);c>=a?l=n.next()-.5:(l=c/a-.93,l=(l<0?-.5:.5)-l,c=n.next()*a);var u=.5-Math.abs(l);if(!(u<.013&&c>u)){var f=Math.floor((2*s/u+r)*l+e+.445);if(c=c*o/(s/(u*u)+r),f>=10){var h=(f+.5)*Math.log(e/f)-e-sy+f-(.08333333333333333-(.002777777777777778-1/(1260*f*f))/(f*f))/f;if(Math.log(c*i)<=h)return f}else if(f>=0){var d,_=(d=ry(f))!=null?d:0;if(Math.log(c)<=f*Math.log(e)-e-_)return f}}}}}},ay=function(n,e){return e===void 0&&(e=1),ot(e).isPositive(),function(){return-Math.log(1-n.next())/e}},ly=function(n,e){return e===void 0&&(e=1),ot(e).isInt().greaterThanOrEqual(0),function(){for(var t=0,i=0;i<e;++i)t+=n.next();return t}},cy=function(n,e){e===void 0&&(e=1),ot(e).isInt().isPositive();var t=n.irwinHall(e);return function(){return t()/e}},uy=function(n,e){e===void 0&&(e=1),ot(e).greaterThanOrEqual(0);var t=1/e;return function(){return 1/Math.pow(1-n.next(),t)}},fy=function(n){mc(e,n);function e(){return n.apply(this,arguments)||this}var t=e.prototype;return t.next=function(){return Math.random()},t.seed=function(r,s){},t.clone=function(){return new e},Zs(e,[{key:"name",get:function(){return"default"}}]),e}(ir),xc=function(){function n(t){var i=this;this._rng=void 0,this._patch=void 0,this._cache={},this.next=function(){return i._rng.next()},this.float=function(r,s){return i.uniform(r,s)()},this.int=function(r,s){return i.uniformInt(r,s)()},this.integer=function(r,s){return i.uniformInt(r,s)()},this.bool=function(){return i.uniformBoolean()()},this.boolean=function(){return i.uniformBoolean()()},this.uniform=function(r,s){return i._memoize("uniform",jx,r,s)},this.uniformInt=function(r,s){return i._memoize("uniformInt",Zx,r,s)},this.uniformBoolean=function(){return i._memoize("uniformBoolean",Qx)},this.normal=function(r,s){return Jx(i,r,s)},this.logNormal=function(r,s){return Gx(i,r,s)},this.bernoulli=function(r){return ey(i,r)},this.binomial=function(r,s){return ty(i,r,s)},this.geometric=function(r){return ny(i,r)},this.poisson=function(r){return oy(i,r)},this.exponential=function(r){return ay(i,r)},this.irwinHall=function(r){return ly(i,r)},this.bates=function(r){return cy(i,r)},this.pareto=function(r){return uy(i,r)},t&&t instanceof ir?this.use(t):this.use(new fy),this._cache={}}var e=n.prototype;return e.clone=function(){var i=[].slice.call(arguments);return i.length?new n(_c.apply(void 0,i)):new n(this.rng.clone())},e.use=function(){this._rng=_c.apply(void 0,[].slice.call(arguments))},e.patch=function(){if(this._patch)throw new Error("Math.random already patched");this._patch=Math.random,Math.random=this.uniform()},e.unpatch=function(){this._patch&&(Math.random=this._patch,delete this._patch)},e.choice=function(i){if(!Array.isArray(i))throw new Error("Random.choice expected input to be an array, got "+typeof i);var r=i==null?void 0:i.length;if(r>0){var s=this.uniformInt(0,r-1)();return i[s]}else return},e._memoize=function(i,r){var s=[].slice.call(arguments,2),o=""+s.join(";"),a=this._cache[i];return(a===void 0||a.key!==o)&&(a={key:o,distribution:r.apply(void 0,[this].concat(s))},this._cache[i]=a),a.distribution},Zs(n,[{key:"rng",get:function(){return this._rng}}]),n}();new xc;const Js=.001,rr=64,hy=4,yc=2;class dy{constructor(){this.pointsTextureSize=0,this.linksTextureSize=0,this.alpha=1,this.transform=Tx(),this.screenSize=[0,0],this.mousePosition=[0,0],this.screenMousePosition=[0,0],this.selectedArea=[[0,0],[0,0]],this.isSimulationRunning=!1,this.simulationProgress=0,this.selectedIndices=null,this.maxPointSize=rr,this.hoveredPoint=void 0,this.focusedPoint=void 0,this.draggingPointIndex=void 0,this.hoveredLinkIndex=void 0,this.adjustedSpaceSize=wt.spaceSize,this.isSpaceKeyPressed=!1,this.webglMaxTextureSize=16384,this.hoveredPointRingColor=[1,1,1,Cc],this.focusedPointRingColor=[1,1,1,Ic],this.hoveredLinkColor=[-1,-1,-1,-1],this.greyoutPointColor=[-1,-1,-1,-1],this.isDarkenGreyout=!1,this.isLinkHoveringEnabled=!1,this.alphaTarget=0,this.scalePointX=qs(),this.scalePointY=qs(),this.random=new xc,this._backgroundColor=[0,0,0,0],this.alphaDecay=e=>1-Math.pow(Js,1/e)}get backgroundColor(){return this._backgroundColor}get transformationMatrix4x4(){const e=this.transform;if(e.length!==9)throw new Error(`Transform must be a 9-element array (3x3 matrix), got ${e.length} elements`);return[e[0],e[1],e[2],0,e[3],e[4],e[5],0,e[6],e[7],e[8],0,0,0,0,1]}set backgroundColor(e){this._backgroundColor=e;const t=Tc(e[0],e[1],e[2]);document.documentElement.style.setProperty("--cosmosgl-attribution-color",t>.65?"black":"white"),document.documentElement.style.setProperty("--cosmosgl-error-message-color",t>.65?"black":"white"),this.div&&(this.div.style.backgroundColor=`rgba(${e[0]*255}, ${e[1]*255}, ${e[2]*255}, ${e[3]})`),this.isDarkenGreyout=t<.65}addRandomSeed(e){this.random=this.random.clone(e)}getRandomFloat(e,t){return this.random.float(e,t)}adjustSpaceSize(e,t){(e<=0||!isFinite(e))&&(console.error(`Invalid spaceSize value: ${e}. Using default value of ${wt.spaceSize}`),e=wt.spaceSize);const i=2;if(e<i&&(console.warn(`spaceSize (${e}) is too small. Using minimum value of ${i}`),e=i),!Number.isFinite(t)||t<=0||t<i){console.warn(`Invalid webglMaxTextureSize: ${t}. Using configSpaceSize without WebGL limit adjustment.`),this.adjustedSpaceSize=e;return}e>=t?(this.adjustedSpaceSize=Math.max(t/2,i),console.warn(`The \`spaceSize\` has been reduced to ${this.adjustedSpaceSize} due to WebGL limits`)):this.adjustedSpaceSize=e}setWebGLMaxTextureSize(e){this.webglMaxTextureSize=e}updateScreenSize(e,t){const{adjustedSpaceSize:i}=this;this.screenSize=[e,t],this.scalePointX.domain([0,i]).range([(e-i)/2,(e+i)/2]),this.scalePointY.domain([i,0]).range([(t-i)/2,(t+i)/2])}scaleX(e){return this.scalePointX(e)}scaleY(e){return this.scalePointY(e)}setHoveredPointRingColor(e){const t=Tt(e);this.hoveredPointRingColor[0]=t[0],this.hoveredPointRingColor[1]=t[1],this.hoveredPointRingColor[2]=t[2]}setFocusedPointRingColor(e){const t=Tt(e);this.focusedPointRingColor[0]=t[0],this.focusedPointRingColor[1]=t[1],this.focusedPointRingColor[2]=t[2]}setGreyoutPointColor(e){if(e===void 0){this.greyoutPointColor=[-1,-1,-1,-1];return}const t=Tt(e);this.greyoutPointColor[0]=t[0],this.greyoutPointColor[1]=t[1],this.greyoutPointColor[2]=t[2],this.greyoutPointColor[3]=t[3]}updateLinkHoveringEnabled(e){this.isLinkHoveringEnabled=!!(e.onLinkClick||e.onLinkContextMenu||e.onLinkMouseOver||e.onLinkMouseOut),this.isLinkHoveringEnabled||(this.hoveredLinkIndex=void 0)}setHoveredLinkColor(e){if(e===void 0){this.hoveredLinkColor=[-1,-1,-1,-1];return}const t=Tt(e);this.hoveredLinkColor[0]=t[0],this.hoveredLinkColor[1]=t[1],this.hoveredLinkColor[2]=t[2],this.hoveredLinkColor[3]=t[3]}setFocusedPoint(e){e!==void 0?this.focusedPoint={index:e}:this.focusedPoint=void 0}addAlpha(e){return(this.alphaTarget-this.alpha)*this.alphaDecay(e)}}const vc=n=>typeof n=="function",Gs=n=>Array.isArray(n),bc=n=>n instanceof Object,Sc=n=>n instanceof Object?n.constructor.name!=="Function"&&n.constructor.name!=="Object":!1,py=n=>bc(n)&&!Gs(n)&&!vc(n)&&!Sc(n);function Tt(n){let e;if(Gs(n))e=n;else{const t=Dt(n),i=t==null?void 0:t.rgb();e=[((i==null?void 0:i.r)??0)/255,((i==null?void 0:i.g)??0)/255,((i==null?void 0:i.b)??0)/255,(t==null?void 0:t.opacity)??1]}return e}function Tc(n,e,t){return .2126*n+.7152*e+.0722*t}function Me(n,e,t=0,i=0,r,s){return n.readPixelsToArrayWebGL(e,{sourceX:t,sourceY:i,sourceWidth:r,sourceHeight:s})}function eo(n,e){switch(n.info.type){case"webgl":{const t=n.gl.getParameter(Xt.ALIASED_POINT_SIZE_RANGE);return((t==null?void 0:t[1])??rr)/e}case"webgpu":return rr/e;default:return rr/e}}function wc(n,e,t){return Math.min(Math.max(n,e),t)}function Ze(n){return n!=null&&!Number.isNaN(n)}function Ac(n,e){return j_.sanitize(n,{ALLOWED_TAGS:["a","b","i","em","strong","span","div","p","br"],ALLOWED_ATTR:["href","target","class","id","style"],ALLOW_DATA_ATTR:!1,...e})}var to=(n=>(n[n.Circle=0]="Circle",n[n.Square=1]="Square",n[n.Triangle=2]="Triangle",n[n.Diamond=3]="Diamond",n[n.Pentagon=4]="Pentagon",n[n.Hexagon=5]="Hexagon",n[n.Star=6]="Star",n[n.Cross=7]="Cross",n[n.None=8]="None",n))(to||{});class my{constructor(e){this._config=e}get pointsNumber(){return this.pointPositions&&this.pointPositions.length/2}get linksNumber(){return this.links&&this.links.length/2}updatePoints(){this.pointPositions=this.inputPointPositions}updatePointColor(){if(this.pointsNumber===void 0){this.pointColors=void 0;return}const e=Tt(this._config.pointDefaultColor);if(this.inputPointColors===void 0||this.inputPointColors.length/4!==this.pointsNumber){this.pointColors=new Float32Array(this.pointsNumber*4);for(let t=0;t<this.pointColors.length/4;t++)this.pointColors[t*4]=e[0],this.pointColors[t*4+1]=e[1],this.pointColors[t*4+2]=e[2],this.pointColors[t*4+3]=e[3]}else{this.pointColors=this.inputPointColors;for(let t=0;t<this.pointColors.length/4;t++)Ze(this.pointColors[t*4])||(this.pointColors[t*4]=e[0]),Ze(this.pointColors[t*4+1])||(this.pointColors[t*4+1]=e[1]),Ze(this.pointColors[t*4+2])||(this.pointColors[t*4+2]=e[2]),Ze(this.pointColors[t*4+3])||(this.pointColors[t*4+3]=e[3])}}updatePointSize(){if(this.pointsNumber===void 0){this.pointSizes=void 0;return}const e=this._config.pointDefaultSize;if(this.inputPointSizes===void 0||this.inputPointSizes.length!==this.pointsNumber)this.pointSizes=new Float32Array(this.pointsNumber).fill(e);else{this.pointSizes=this.inputPointSizes;for(let t=0;t<this.pointSizes.length;t++)Ze(this.pointSizes[t])||(this.pointSizes[t]=e)}}updatePointShape(){if(this.pointsNumber===void 0){this.pointShapes=void 0;return}const{pointDefaultShape:e}=this._config,t=typeof e=="string"?Number(e):e,i=t>=0&&t<=8?t:wt.pointDefaultShape;if(this.inputPointShapes===void 0||this.inputPointShapes.length!==this.pointsNumber)this.pointShapes=new Float32Array(this.pointsNumber).fill(i);else{this.pointShapes=new Float32Array(this.inputPointShapes);const r=this.pointShapes;for(let s=0;s<r.length;s++){const o=r[s];(o==null||!Ze(o)||o<0||o>8)&&(r[s]=i)}}}updatePointImageIndices(){if(this.pointsNumber===void 0){this.pointImageIndices=void 0;return}if(this.inputPointImageIndices===void 0||this.inputPointImageIndices.length!==this.pointsNumber)this.pointImageIndices=new Float32Array(this.pointsNumber).fill(-1);else{const e=new Float32Array(this.inputPointImageIndices);for(let t=0;t<e.length;t++){const i=e[t],r=i===void 0?NaN:i;!Number.isFinite(r)||r<0?e[t]=-1:e[t]=Math.trunc(r)}this.pointImageIndices=e}}updatePointImageSizes(){var t;if(this.pointsNumber===void 0){this.pointImageSizes=void 0;return}const e=this._config.pointDefaultSize;if(this.inputPointImageSizes===void 0||this.inputPointImageSizes.length!==this.pointsNumber)this.pointImageSizes=this.pointSizes?new Float32Array(this.pointSizes):new Float32Array(this.pointsNumber).fill(e);else{this.pointImageSizes=new Float32Array(this.inputPointImageSizes);for(let i=0;i<this.pointImageSizes.length;i++)Ze(this.pointImageSizes[i])||(this.pointImageSizes[i]=((t=this.pointSizes)==null?void 0:t[i])??e)}}updateLinks(){this.links=this.inputLinks}updateLinkColor(){if(this.linksNumber===void 0){this.linkColors=void 0;return}const e=Tt(this._config.linkDefaultColor);if(this.inputLinkColors===void 0||this.inputLinkColors.length/4!==this.linksNumber){this.linkColors=new Float32Array(this.linksNumber*4);for(let t=0;t<this.linkColors.length/4;t++)this.linkColors[t*4]=e[0],this.linkColors[t*4+1]=e[1],this.linkColors[t*4+2]=e[2],this.linkColors[t*4+3]=e[3]}else{this.linkColors=this.inputLinkColors;for(let t=0;t<this.linkColors.length/4;t++)Ze(this.linkColors[t*4])||(this.linkColors[t*4]=e[0]),Ze(this.linkColors[t*4+1])||(this.linkColors[t*4+1]=e[1]),Ze(this.linkColors[t*4+2])||(this.linkColors[t*4+2]=e[2]),Ze(this.linkColors[t*4+3])||(this.linkColors[t*4+3]=e[3])}}updateLinkWidth(){if(this.linksNumber===void 0){this.linkWidths=void 0;return}const e=this._config.linkDefaultWidth;if(this.inputLinkWidths===void 0||this.inputLinkWidths.length!==this.linksNumber)this.linkWidths=new Float32Array(this.linksNumber).fill(e);else{this.linkWidths=this.inputLinkWidths;for(let t=0;t<this.linkWidths.length;t++)Ze(this.linkWidths[t])||(this.linkWidths[t]=e)}}updateArrows(){if(this.linksNumber===void 0){this.linkArrows=void 0;return}const e=this._config.linkDefaultArrows;this.linkArrowsBoolean===void 0||this.linkArrowsBoolean.length!==this.linksNumber?this.linkArrows=new Array(this.linksNumber).fill(+e):this.linkArrows=this.linkArrowsBoolean.map(t=>+t)}updateLinkStrength(){this.linksNumber===void 0&&(this.linkStrength=void 0),this.inputLinkStrength===void 0||this.inputLinkStrength.length!==this.linksNumber?this.linkStrength=void 0:this.linkStrength=this.inputLinkStrength}updateClusters(){if(this.pointsNumber===void 0){this.pointClusters=void 0,this.clusterPositions=void 0;return}this.inputPointClusters===void 0||this.inputPointClusters.length!==this.pointsNumber?this.pointClusters=void 0:this.pointClusters=this.inputPointClusters,this.inputClusterPositions===void 0?this.clusterPositions=void 0:this.clusterPositions=this.inputClusterPositions,this.inputClusterStrength===void 0||this.inputClusterStrength.length!==this.pointsNumber?this.clusterStrength=void 0:this.clusterStrength=this.inputClusterStrength}update(){this.updatePoints(),this.updatePointColor(),this.updatePointSize(),this.updatePointShape(),this.updatePointImageIndices(),this.updatePointImageSizes(),this.updateLinks(),this.updateLinkColor(),this.updateLinkWidth(),this.updateArrows(),this.updateLinkStrength(),this.updateClusters(),this._createAdjacencyLists(),this._calculateDegrees()}getAdjacentIndices(e){var t,i,r,s;return[...((i=(t=this.sourceIndexToTargetIndices)==null?void 0:t[e])==null?void 0:i.map(o=>o[0]))||[],...((s=(r=this.targetIndexToSourceIndices)==null?void 0:r[e])==null?void 0:s.map(o=>o[0]))||[]]}_createAdjacencyLists(){var e,t;if(this.linksNumber===void 0||this.links===void 0){this.sourceIndexToTargetIndices=void 0,this.targetIndexToSourceIndices=void 0;return}this.sourceIndexToTargetIndices=new Array(this.pointsNumber).fill(void 0),this.targetIndexToSourceIndices=new Array(this.pointsNumber).fill(void 0);for(let i=0;i<this.linksNumber;i++){const r=this.links[i*2],s=this.links[i*2+1];r!==void 0&&s!==void 0&&(this.sourceIndexToTargetIndices[r]===void 0&&(this.sourceIndexToTargetIndices[r]=[]),(e=this.sourceIndexToTargetIndices[r])==null||e.push([s,i]),this.targetIndexToSourceIndices[s]===void 0&&(this.targetIndexToSourceIndices[s]=[]),(t=this.targetIndexToSourceIndices[s])==null||t.push([r,i]))}}_calculateDegrees(){var e,t,i,r;if(this.pointsNumber===void 0){this.degree=void 0,this.inDegree=void 0,this.outDegree=void 0;return}this.degree=new Array(this.pointsNumber).fill(0),this.inDegree=new Array(this.pointsNumber).fill(0),this.outDegree=new Array(this.pointsNumber).fill(0);for(let s=0;s<this.pointsNumber;s++)this.inDegree[s]=((t=(e=this.targetIndexToSourceIndices)==null?void 0:e[s])==null?void 0:t.length)??0,this.outDegree[s]=((r=(i=this.sourceIndexToTargetIndices)==null?void 0:i[s])==null?void 0:r.length)??0,this.degree[s]=(this.inDegree[s]??0)+(this.outDegree[s]??0)}}const wt={enableSimulation:!0,backgroundColor:"#222222",spaceSize:4096,pointDefaultColor:"#b3b3b3",pointDefaultSize:4,pointDefaultShape:to.Circle,pointOpacity:1,pointGreyoutOpacity:void 0,pointGreyoutColor:void 0,pointSizeScale:1,scalePointsOnZoom:!1,hoveredPointCursor:"auto",renderHoveredPointRing:!1,hoveredPointRingColor:"white",focusedPointRingColor:"white",focusedPointIndex:void 0,renderLinks:!0,linkDefaultColor:"#666666",linkDefaultWidth:1,linkOpacity:1,linkGreyoutOpacity:.1,linkWidthScale:1,scaleLinksOnZoom:!1,curvedLinks:!1,curvedLinkSegments:19,curvedLinkWeight:.8,curvedLinkControlPointDistance:.5,linkDefaultArrows:!1,linkArrowsSizeScale:1,linkVisibilityDistanceRange:[50,150],linkVisibilityMinTransparency:.25,hoveredLinkCursor:"auto",hoveredLinkColor:void 0,hoveredLinkWidthIncrease:5,simulationDecay:5e3,simulationGravity:.25,simulationCenter:0,simulationRepulsion:1,simulationRepulsionTheta:1.15,simulationLinkSpring:1,simulationLinkDistance:10,simulationLinkDistRandomVariationRange:[1,1.2],simulationRepulsionFromMouse:2,simulationFriction:.85,simulationCluster:.1,enableRightClickRepulsion:!1,onSimulationStart:void 0,onSimulationTick:void 0,onSimulationEnd:void 0,onSimulationPause:void 0,onSimulationUnpause:void 0,onClick:void 0,onPointClick:void 0,onLinkClick:void 0,onBackgroundClick:void 0,onContextMenu:void 0,onPointContextMenu:void 0,onLinkContextMenu:void 0,onBackgroundContextMenu:void 0,onMouseMove:void 0,onPointMouseOver:void 0,onPointMouseOut:void 0,onLinkMouseOver:void 0,onLinkMouseOut:void 0,onZoomStart:void 0,onZoom:void 0,onZoomEnd:void 0,onDragStart:void 0,onDrag:void 0,onDragEnd:void 0,showFPSMonitor:!1,pixelRatio:typeof window<"u"&&window.devicePixelRatio||2,enableZoom:!0,enableSimulationDuringZoom:!1,initialZoomLevel:void 0,enableDrag:!1,fitViewOnInit:!0,fitViewDelay:250,fitViewPadding:.1,fitViewDuration:250,fitViewByPointsInRect:void 0,fitViewByPointIndices:void 0,pointSamplingDistance:100,linkSamplingDistance:100,randomSeed:void 0,rescalePositions:void 0,attribution:""},Cc=.7,Ic=.95,no=n=>Array.isArray(n)?[...n]:n;function Pc(){const n={};for(const[e,t]of Object.entries(wt))n[e]=no(t);return n}function gy(n){Object.assign(n,Pc())}function io(n,e,t=!1){const i={};for(const[r,s]of Object.entries(e))s!==void 0?i[r]=no(s):t&&(i[r]=no(wt[r]));Object.assign(n,i)}function ro(n,e){if(!n)throw new Error(e||"shadertools: assertion failed.")}const so={number:{type:"number",validate(n,e){return Number.isFinite(n)&&typeof e=="object"&&(e.max===void 0||n<=e.max)&&(e.min===void 0||n>=e.min)}},array:{type:"array",validate(n,e){return Array.isArray(n)||ArrayBuffer.isView(n)}}};function _y(n){const e={};for(const[t,i]of Object.entries(n))e[t]=xy(i);return e}function xy(n){let e=Ec(n);if(e!=="object")return{value:n,...so[e],type:e};if(typeof n=="object")return n?n.type!==void 0?{...n,...so[n.type],type:n.type}:n.value===void 0?{type:"object",value:n}:(e=Ec(n.value),{...n,...so[e],type:e}):{type:"object",value:null};throw new Error("props")}function Ec(n){return Array.isArray(n)||ArrayBuffer.isView(n)?"array":typeof n}const yy={vertex:`#ifdef MODULE_LOGDEPTH
14
14
  logdepth_adjustPosition(gl_Position);
15
15
  #endif
16
16
  `,fragment:`#ifdef MODULE_MATERIAL
@@ -33,9 +33,9 @@ ${t}`;const{gl:i}=this.device;if(i.shaderSource(this.handle,t),i.compileShader(t
33
33
  #ifdef MODULE_LOGDEPTH
34
34
  logdepth_setFragDepth();
35
35
  #endif
36
- `},Oc=/void\s+main\s*\([^)]*\)\s*\{\n?/,Bc=/}\n?[^{}]*$/,ro=[],sr="__LUMA_INJECT_DECLARATIONS__";function Cy(n){const e={vertex:{},fragment:{}};for(const t in n){let i=n[t];const r=Iy(t);typeof i=="string"&&(i={order:0,injection:i}),e[r][t]=i}return e}function Iy(n){const e=n.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function or(n,e,t,i=!1){const r=e==="vertex";for(const s in t){const o=t[s];o.sort((l,c)=>l.order-c.order),ro.length=o.length;for(let l=0,c=o.length;l<c;++l)ro[l]=o[l].injection;const a=`${ro.join(`
36
+ `},Rc=/void\s+main\s*\([^)]*\)\s*\{\n?/,kc=/}\n?[^{}]*$/,oo=[],sr="__LUMA_INJECT_DECLARATIONS__";function vy(n){const e={vertex:{},fragment:{}};for(const t in n){let i=n[t];const r=by(t);typeof i=="string"&&(i={order:0,injection:i}),e[r][t]=i}return e}function by(n){const e=n.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function or(n,e,t,i=!1){const r=e==="vertex";for(const s in t){const o=t[s];o.sort((l,c)=>l.order-c.order),oo.length=o.length;for(let l=0,c=o.length;l<c;++l)oo[l]=o[l].injection;const a=`${oo.join(`
37
37
  `)}
38
- `;switch(s){case"vs:#decl":r&&(n=n.replace(sr,a));break;case"vs:#main-start":r&&(n=n.replace(Oc,l=>l+a));break;case"vs:#main-end":r&&(n=n.replace(Bc,l=>a+l));break;case"fs:#decl":r||(n=n.replace(sr,a));break;case"fs:#main-start":r||(n=n.replace(Oc,l=>l+a));break;case"fs:#main-end":r||(n=n.replace(Bc,l=>a+l));break;default:n=n.replace(s,l=>l+a)}}return n=n.replace(sr,""),i&&(n=n.replace(/\}\s*$/,s=>s+Ay[e])),n}function ar(n){n.map(e=>Py(e))}function Py(n){if(n.instance)return;ar(n.dependencies||[]);const{propTypes:e={},deprecations:t=[],inject:i={}}=n,r={normalizedInjections:Cy(i),parsedDeprecations:Ey(t)};e&&(r.propValidators=Ty(e)),n.instance=r;let s={};e&&(s=Object.entries(e).reduce((o,[a,l])=>{const c=l==null?void 0:l.value;return c&&(o[a]=c),o},{})),n.defaultUniforms={...n.defaultUniforms,...s}}function Uc(n,e,t){var i;(i=n.deprecations)==null||i.forEach(r=>{var s;(s=r.regex)!=null&&s.test(e)&&(r.deprecated?t.deprecated(r.old,r.new)():t.removed(r.old,r.new)())})}function Ey(n){return n.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),n}function so(n){ar(n);const e={},t={};zc({modules:n,level:0,moduleMap:e,moduleDepth:t});const i=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return ar(i),i}function zc(n){const{modules:e,level:t,moduleMap:i,moduleDepth:r}=n;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(const s of e)i[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(const s of e)s.dependencies&&zc({modules:s.dependencies,level:t+1,moduleMap:i,moduleDepth:r})}function Ry(n){switch(n==null?void 0:n.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
38
+ `;switch(s){case"vs:#decl":r&&(n=n.replace(sr,a));break;case"vs:#main-start":r&&(n=n.replace(Rc,l=>l+a));break;case"vs:#main-end":r&&(n=n.replace(kc,l=>a+l));break;case"fs:#decl":r||(n=n.replace(sr,a));break;case"fs:#main-start":r||(n=n.replace(Rc,l=>l+a));break;case"fs:#main-end":r||(n=n.replace(kc,l=>a+l));break;default:n=n.replace(s,l=>l+a)}}return n=n.replace(sr,""),i&&(n=n.replace(/\}\s*$/,s=>s+yy[e])),n}function ar(n){n.map(e=>Sy(e))}function Sy(n){if(n.instance)return;ar(n.dependencies||[]);const{propTypes:e={},deprecations:t=[],inject:i={}}=n,r={normalizedInjections:vy(i),parsedDeprecations:Ty(t)};e&&(r.propValidators=_y(e)),n.instance=r;let s={};e&&(s=Object.entries(e).reduce((o,[a,l])=>{const c=l==null?void 0:l.value;return c&&(o[a]=c),o},{})),n.defaultUniforms={...n.defaultUniforms,...s}}function Dc(n,e,t){var i;(i=n.deprecations)==null||i.forEach(r=>{var s;(s=r.regex)!=null&&s.test(e)&&(r.deprecated?t.deprecated(r.old,r.new)():t.removed(r.old,r.new)())})}function Ty(n){return n.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),n}function ao(n){ar(n);const e={},t={};Fc({modules:n,level:0,moduleMap:e,moduleDepth:t});const i=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return ar(i),i}function Fc(n){const{modules:e,level:t,moduleMap:i,moduleDepth:r}=n;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(const s of e)i[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(const s of e)s.dependencies&&Fc({modules:s.dependencies,level:t+1,moduleMap:i,moduleDepth:r})}function wy(n){switch(n==null?void 0:n.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
39
39
  // Apple optimizes away the calculation necessary for emulated fp64
40
40
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
41
41
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
@@ -59,41 +59,41 @@ ${t}`;const{gl:i}=this.device;if(i.shaderSource(this.handle,t),i.compileShader(t
59
59
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
60
60
  // If the GPU doesn't have full 32 bits precision, will causes overflow
61
61
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
62
- `}}function ky(n,e){var i;if(Number(((i=n.match(/^#version[ \t]+(\d+)/m))==null?void 0:i[1])||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return n=Vc(n,Dy),n;case"fragment":return n=Vc(n,My),n;default:throw new Error(e)}}const Lc=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
63
- `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Dy=[...Lc,[oo("attribute"),"in $1"],[oo("varying"),"out $1"]],My=[...Lc,[oo("varying"),"in $1"]];function Vc(n,e){for(const[t,i]of e)n=n.replace(t,i);return n}function oo(n){return new RegExp(`\\b${n}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Hc(n,e){let t="";for(const i in n){const r=n[i];if(t+=`void ${r.signature} {
62
+ `}}function Ay(n,e){var i;if(Number(((i=n.match(/^#version[ \t]+(\d+)/m))==null?void 0:i[1])||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return n=Nc(n,Cy),n;case"fragment":return n=Nc(n,Iy),n;default:throw new Error(e)}}const Mc=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
63
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Cy=[...Mc,[lo("attribute"),"in $1"],[lo("varying"),"out $1"]],Iy=[...Mc,[lo("varying"),"in $1"]];function Nc(n,e){for(const[t,i]of e)n=n.replace(t,i);return n}function lo(n){return new RegExp(`\\b${n}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Oc(n,e){let t="";for(const i in n){const r=n[i];if(t+=`void ${r.signature} {
64
64
  `,r.header&&(t+=` ${r.header}`),e[i]){const s=e[i];s.sort((o,a)=>o.order-a.order);for(const o of s)t+=` ${o.injection}
65
65
  `}r.footer&&(t+=` ${r.footer}`),t+=`}
66
- `}return t}function Wc(n){const e={vertex:{},fragment:{}};for(const t of n){let i,r;typeof t!="string"?(i=t,r=i.hook):(i={},r=t),r=r.trim();const[s,o]=r.split(":"),a=r.replace(/\(.+/,""),l=Object.assign(i,{signature:o});switch(s){case"vs":e.vertex[a]=l;break;case"fs":e.fragment[a]=l;break;default:throw new Error(s)}}return e}function Fy(n,e){return{name:Ny(n,e),language:"glsl",version:Oy(n)}}function Ny(n,e="unnamed"){const i=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(n);return i?i[1]:e}function Oy(n){let e=100;const t=n.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){const i=parseInt(t[1],10);Number.isFinite(i)&&(e=i)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}const $c=`
66
+ `}return t}function Bc(n){const e={vertex:{},fragment:{}};for(const t of n){let i,r;typeof t!="string"?(i=t,r=i.hook):(i={},r=t),r=r.trim();const[s,o]=r.split(":"),a=r.replace(/\(.+/,""),l=Object.assign(i,{signature:o});switch(s){case"vs":e.vertex[a]=l;break;case"fs":e.fragment[a]=l;break;default:throw new Error(s)}}return e}function Py(n,e){return{name:Ey(n,e),language:"glsl",version:Ry(n)}}function Ey(n,e="unnamed"){const i=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(n);return i?i[1]:e}function Ry(n){let e=100;const t=n.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){const i=parseInt(t[1],10);Number.isFinite(i)&&(e=i)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}const Uc=`
67
67
 
68
68
  ${sr}
69
- `,By=`precision highp float;
70
- `;function Uy(n){const e=so(n.modules||[]);return{source:Ly(n.platformInfo,{...n,source:n.source,stage:"vertex",modules:e}),getUniforms:Yc(e)}}function zy(n){const{vs:e,fs:t}=n,i=so(n.modules||[]);return{vs:Xc(n.platformInfo,{...n,source:e,stage:"vertex",modules:i}),fs:Xc(n.platformInfo,{...n,source:t,stage:"fragment",modules:i}),getUniforms:Yc(i)}}function Ly(n,e){var I;const{source:t,stage:i,modules:r,hookFunctions:s=[],inject:o={},log:a}=e;no(typeof t=="string","shader source must be a string");const l=t;let c="";const u=Wc(s),f={},h={},d={};for(const P in o){const A=typeof o[P]=="string"?{injection:o[P],order:0}:o[P],O=/^(v|f)s:(#)?([\w-]+)$/.exec(P);if(O){const E=O[2],x=O[3];E?x==="decl"?h[P]=[A]:d[P]=[A]:f[P]=[A]}else d[P]=[A]}const _=r;for(const P of _){a&&Uc(P,l,a);const A=qc(P,"wgsl");c+=A;const O=((I=P.injections)==null?void 0:I[i])||{};for(const E in O){const x=/^(v|f)s:#([\w-]+)$/.exec(E);if(x){const N=x[2]==="decl"?h:d;N[E]=N[E]||[],N[E].push(O[E])}else f[E]=f[E]||[],f[E].push(O[E])}}return c+=$c,c=or(c,i,h),c+=Hc(u[i],f),c+=l,c=or(c,i,d),c}function Xc(n,e){var N;const{source:t,stage:i,language:r="glsl",modules:s,defines:o={},hookFunctions:a=[],inject:l={},prologue:c=!0,log:u}=e;no(typeof t=="string","shader source must be a string");const f=r==="glsl"?Fy(t).version:-1,h=n.shaderLanguageVersion,d=f===100?"#version 100":"#version 300 es",I=t.split(`
69
+ `,ky=`precision highp float;
70
+ `;function Dy(n){const e=ao(n.modules||[]);return{source:My(n.platformInfo,{...n,source:n.source,stage:"vertex",modules:e}),getUniforms:Lc(e)}}function Fy(n){const{vs:e,fs:t}=n,i=ao(n.modules||[]);return{vs:zc(n.platformInfo,{...n,source:e,stage:"vertex",modules:i}),fs:zc(n.platformInfo,{...n,source:t,stage:"fragment",modules:i}),getUniforms:Lc(i)}}function My(n,e){var I;const{source:t,stage:i,modules:r,hookFunctions:s=[],inject:o={},log:a}=e;ro(typeof t=="string","shader source must be a string");const l=t;let c="";const u=Bc(s),f={},h={},d={};for(const P in o){const A=typeof o[P]=="string"?{injection:o[P],order:0}:o[P],O=/^(v|f)s:(#)?([\w-]+)$/.exec(P);if(O){const E=O[2],y=O[3];E?y==="decl"?h[P]=[A]:d[P]=[A]:f[P]=[A]}else d[P]=[A]}const _=r;for(const P of _){a&&Dc(P,l,a);const A=Vc(P,"wgsl");c+=A;const O=((I=P.injections)==null?void 0:I[i])||{};for(const E in O){const y=/^(v|f)s:#([\w-]+)$/.exec(E);if(y){const N=y[2]==="decl"?h:d;N[E]=N[E]||[],N[E].push(O[E])}else f[E]=f[E]||[],f[E].push(O[E])}}return c+=Uc,c=or(c,i,h),c+=Oc(u[i],f),c+=l,c=or(c,i,d),c}function zc(n,e){var N;const{source:t,stage:i,language:r="glsl",modules:s,defines:o={},hookFunctions:a=[],inject:l={},prologue:c=!0,log:u}=e;ro(typeof t=="string","shader source must be a string");const f=r==="glsl"?Py(t).version:-1,h=n.shaderLanguageVersion,d=f===100?"#version 100":"#version 300 es",I=t.split(`
71
71
  `).slice(1).join(`
72
72
  `),P={};s.forEach(U=>{Object.assign(P,U.defines)}),Object.assign(P,o);let A="";switch(r){case"wgsl":break;case"glsl":A=c?`${d}
73
73
 
74
74
  // ----- PROLOGUE -------------------------
75
75
  ${`#define SHADER_TYPE_${i.toUpperCase()}`}
76
76
 
77
- ${Ry(n)}
78
- ${i==="fragment"?By:""}
77
+ ${wy(n)}
78
+ ${i==="fragment"?ky:""}
79
79
 
80
80
  // ----- APPLICATION DEFINES -------------------------
81
81
 
82
- ${Vy(P)}
82
+ ${Ny(P)}
83
83
 
84
84
  `:`${d}
85
- `;break}const O=Wc(a),E={},x={},R={};for(const U in l){const W=typeof l[U]=="string"?{injection:l[U],order:0}:l[U],q=/^(v|f)s:(#)?([\w-]+)$/.exec(U);if(q){const G=q[2],B=q[3];G?B==="decl"?x[U]=[W]:R[U]=[W]:E[U]=[W]}else R[U]=[W]}for(const U of s){u&&Uc(U,I,u);const W=qc(U,i);A+=W;const q=((N=U.instance)==null?void 0:N.normalizedInjections[i])||{};for(const G in q){const B=/^(v|f)s:#([\w-]+)$/.exec(G);if(B){const se=B[2]==="decl"?x:R;se[G]=se[G]||[],se[G].push(q[G])}else E[G]=E[G]||[],E[G].push(q[G])}}return A+="// ----- MAIN SHADER SOURCE -------------------------",A+=$c,A=or(A,i,x),A+=Hc(O[i],E),A+=I,A=or(A,i,R),r==="glsl"&&f!==h&&(A=ky(A,i)),A.trim()}function Yc(n){return function(t){var r;const i={};for(const s of n){const o=(r=s.getUniforms)==null?void 0:r.call(s,t,i);Object.assign(i,o)}return i}}function Vy(n={}){let e="";for(const t in n){const i=n[t];(i||Number.isFinite(i))&&(e+=`#define ${t.toUpperCase()} ${n[t]}
86
- `)}return e}function qc(n,e){let t;switch(e){case"vertex":t=n.vs||"";break;case"fragment":t=n.fs||"";break;case"wgsl":t=n.source||"";break;default:no(!1)}if(!n.name)throw new Error("Shader module must have a name");const i=n.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");let r=`// ----- MODULE ${n.name} ---------------
85
+ `;break}const O=Bc(a),E={},y={},R={};for(const U in l){const H=typeof l[U]=="string"?{injection:l[U],order:0}:l[U],Y=/^(v|f)s:(#)?([\w-]+)$/.exec(U);if(Y){const Z=Y[2],B=Y[3];Z?B==="decl"?y[U]=[H]:R[U]=[H]:E[U]=[H]}else R[U]=[H]}for(const U of s){u&&Dc(U,I,u);const H=Vc(U,i);A+=H;const Y=((N=U.instance)==null?void 0:N.normalizedInjections[i])||{};for(const Z in Y){const B=/^(v|f)s:#([\w-]+)$/.exec(Z);if(B){const ie=B[2]==="decl"?y:R;ie[Z]=ie[Z]||[],ie[Z].push(Y[Z])}else E[Z]=E[Z]||[],E[Z].push(Y[Z])}}return A+="// ----- MAIN SHADER SOURCE -------------------------",A+=Uc,A=or(A,i,y),A+=Oc(O[i],E),A+=I,A=or(A,i,R),r==="glsl"&&f!==h&&(A=Ay(A,i)),A.trim()}function Lc(n){return function(t){var r;const i={};for(const s of n){const o=(r=s.getUniforms)==null?void 0:r.call(s,t,i);Object.assign(i,o)}return i}}function Ny(n={}){let e="";for(const t in n){const i=n[t];(i||Number.isFinite(i))&&(e+=`#define ${t.toUpperCase()} ${n[t]}
86
+ `)}return e}function Vc(n,e){let t;switch(e){case"vertex":t=n.vs||"";break;case"fragment":t=n.fs||"";break;case"wgsl":t=n.source||"";break;default:ro(!1)}if(!n.name)throw new Error("Shader module must have a name");const i=n.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");let r=`// ----- MODULE ${n.name} ---------------
87
87
 
88
88
  `;return e!=="wgsl"&&(r+=`#define MODULE_${i}
89
89
  `),r+=`${t}
90
- `,r}const Hy=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Wy=/^\s*\#\s*endif\s*$/;function $y(n,e){var o;const t=n.split(`
91
- `),i=[];let r=!0,s=null;for(const a of t){const l=a.match(Hy),c=a.match(Wy);l?(s=l[1],r=!!((o=e==null?void 0:e.defines)!=null&&o[s])):c?r=!0:r&&i.push(a)}return i.join(`
92
- `)}const Jt=class Jt{constructor(){m(this,"_hookFunctions",[]);m(this,"_defaultModules",[])}static getDefaultShaderAssembler(){return Jt.defaultShaderAssembler=Jt.defaultShaderAssembler||new Jt,Jt.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){const t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){const t=this._getModuleList(e.modules),i=this._hookFunctions,{source:r,getUniforms:s}=Uy({...e,source:e.source,modules:t,hookFunctions:i});return{source:e.platformInfo.shaderLanguage==="wgsl"?$y(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){const t=this._getModuleList(e.modules),i=this._hookFunctions;return{...zy({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:i}),modules:t}}_getModuleList(e=[]){const t=new Array(this._defaultModules.length+e.length),i={};let r=0;for(let s=0,o=this._defaultModules.length;s<o;++s){const a=this._defaultModules[s],l=a.name;t[r++]=a,i[l]=!0}for(let s=0,o=e.length;s<o;++s){const a=e[s],l=a.name;i[l]||(t[r++]=a,i[l]=!0)}return t.length=r,ar(t),t}};m(Jt,"defaultShaderAssembler");let ao=Jt;class Je{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}get isPointer(){return!1}getTypeName(){return this.name}}class jc{constructor(e,t,i){this.name=e,this.type=t,this.attributes=i,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class Dt extends Je{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}}class Mt extends Je{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}}class lo extends Je{constructor(e,t,i){super(e,i),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class qt extends Je{constructor(e,t,i,r){super(e,i),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}}var Ft;(n=>{n[n.Uniform=0]="Uniform",n[n.Storage=1]="Storage",n[n.Texture=2]="Texture",n[n.Sampler=3]="Sampler",n[n.StorageTexture=4]="StorageTexture"})(Ft||(Ft={}));class lr{constructor(e,t,i,r,s,o,a){this.name=e,this.type=t,this.group=i,this.binding=r,this.attributes=s,this.resourceType=o,this.access=a}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class Xy{constructor(e,t){this.name=e,this.type=t}}class Yy{constructor(e,t,i,r){this.name=e,this.type=t,this.locationType=i,this.location=r,this.interpolation=null}}class Kc{constructor(e,t,i,r){this.name=e,this.type=t,this.locationType=i,this.location=r}}class qy{constructor(e,t,i,r){this.name=e,this.type=t,this.attributes=i,this.id=r}}class jy{constructor(e,t,i){this.name=e,this.type=t,this.attributes=i}}class Ky{constructor(e,t=null,i){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=i}}class Zy{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function Qy(n){var e=(32768&n)>>15,t=(31744&n)>>10,i=1023&n;return t==0?(e?-1:1)*Math.pow(2,-14)*(i/Math.pow(2,10)):t==31?i?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,t-15)*(1+i/Math.pow(2,10))}const Zc=new Float32Array(1),Jy=new Int32Array(Zc.buffer),Fe=new Uint16Array(1);function Gy(n){Zc[0]=n;const e=Jy[0],t=e>>31&1;let i=e>>23&255,r=8388607&e;if(i===255)return Fe[0]=t<<15|31744|(r!==0?512:0),Fe[0];if(i===0){if(r===0)return Fe[0]=t<<15,Fe[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return i=127-s,r&=8388607,i>0?(r=(r>>126-i)+(r>>127-i&1),Fe[0]=t<<15|i<<10|r>>13,Fe[0]):(Fe[0]=t<<15,Fe[0])}return i=i-127+15,i>=31?(Fe[0]=t<<15|31744,Fe[0]):i<=0?i<-10?(Fe[0]=t<<15,Fe[0]):(r=(8388608|r)>>1-i,Fe[0]=t<<15|r>>13,Fe[0]):(r>>=13,Fe[0]=t<<15|i<<10|r,Fe[0])}const co=new Uint32Array(1),Qc=new Float32Array(co.buffer,0,1);function Jc(n){const e=112+(n>>6&31)<<23|(63&n)<<17;return co[0]=e,Qc[0]}function e0(n,e,t,i,r,s,o,a,l){const c=i*(o>>=r)*(s>>=r)+t*o+e*a;switch(l){case"r8unorm":return[ae(n,c,"8unorm",1)[0]];case"r8snorm":return[ae(n,c,"8snorm",1)[0]];case"r8uint":return[ae(n,c,"8uint",1)[0]];case"r8sint":return[ae(n,c,"8sint",1)[0]];case"rg8unorm":{const u=ae(n,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{const u=ae(n,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{const u=ae(n,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{const u=ae(n,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const u=ae(n,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{const u=ae(n,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{const u=ae(n,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{const u=ae(n,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const u=ae(n,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[ae(n,c,"16uint",1)[0]];case"r16sint":return[ae(n,c,"16sint",1)[0]];case"r16float":return[ae(n,c,"16float",1)[0]];case"rg16uint":{const u=ae(n,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{const u=ae(n,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{const u=ae(n,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{const u=ae(n,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{const u=ae(n,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{const u=ae(n,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[ae(n,c,"32uint",1)[0]];case"r32sint":return[ae(n,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[ae(n,c,"32float",1)[0]];case"rg32uint":{const u=ae(n,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{const u=ae(n,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{const u=ae(n,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{const u=ae(n,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{const u=ae(n,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{const u=ae(n,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{const u=new Uint32Array(n.buffer,c,1)[0],f=(4192256&u)>>11,h=(4290772992&u)>>22;return[Jc(2047&u),Jc(f),function(d){const _=112+(d>>5&31)<<23|(31&d)<<18;return co[0]=_,Qc[0]}(h),1]}}return null}function ae(n,e,t,i){const r=[0,0,0,0];for(let s=0;s<i;++s)switch(t){case"8unorm":r[s]=n[e]/255,e++;break;case"8snorm":r[s]=n[e]/255*2-1,e++;break;case"8uint":r[s]=n[e],e++;break;case"8sint":r[s]=n[e]-127,e++;break;case"16uint":r[s]=n[e]|n[e+1]<<8,e+=2;break;case"16sint":r[s]=(n[e]|n[e+1]<<8)-32768,e+=2;break;case"16float":r[s]=Qy(n[e]|n[e+1]<<8),e+=2;break;case"32uint":case"32sint":r[s]=n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24,e+=4;break;case"32float":r[s]=new Float32Array(n.buffer,e,1)[0],e+=4}return r}function le(n,e,t,i,r){for(let s=0;s<i;++s)switch(t){case"8unorm":n[e]=255*r[s],e++;break;case"8snorm":n[e]=.5*(r[s]+1)*255,e++;break;case"8uint":n[e]=r[s],e++;break;case"8sint":n[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(n.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(n.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{const o=Gy(r[s]);new Uint16Array(n.buffer,e,1)[0]=o,e+=2;break}case"32uint":new Uint32Array(n.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(n.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(n.buffer,e,1)[0]=r[s],e+=4}return r}const uo={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class Ge{constructor(){this.id=Ge._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(cr.instance);for(const i of e)i instanceof Array?this.searchBlock(i,t):i.search(t);t(ur.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}}Ge._id=0;class cr extends Ge{}cr.instance=new cr;class ur extends Ge{}ur.instance=new ur;const Gc=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]);class pe extends Ge{constructor(){super()}}class jn extends pe{constructor(e,t,i,r,s,o){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=i,this.body=r,this.startLine=s,this.endLine=o}get astNodeType(){return"function"}search(e){if(this.attributes)for(const t of this.attributes)e(t);e(this);for(const t of this.args)e(t);this.searchBlock(this.body,e)}}class t0 extends pe{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}}class eu extends pe{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}}class fo extends pe{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}}class tu extends pe{constructor(e,t,i,r){super(),this.init=e,this.condition=t,this.increment=i,this.body=r}get astNodeType(){return"for"}search(e){var t,i,r;(t=this.init)===null||t===void 0||t.search(e),(i=this.condition)===null||i===void 0||i.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}}class wt extends pe{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class ho extends pe{constructor(e,t,i){super(),this.attributes=null,this.name=e,this.type=t,this.value=i}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}}class Kn extends pe{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class fr extends pe{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}var gn,Zn,w,b;(n=>{n.increment="++",n.decrement="--"})(gn||(gn={})),(n=>{n.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return n[t]}})(gn||(gn={}));class nu extends pe{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}}(n=>{n.assign="=",n.addAssign="+=",n.subtractAssin="-=",n.multiplyAssign="*=",n.divideAssign="/=",n.moduloAssign="%=",n.andAssign="&=",n.orAssign="|=",n.xorAssign="^=",n.shiftLeftAssign="<<=",n.shiftRightAssign=">>="})(Zn||(Zn={})),(n=>{n.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(Zn||(Zn={}));class iu extends pe{constructor(e,t,i){super(),this.operator=e,this.variable=t,this.value=i}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}}class po extends pe{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Gc.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class ru extends pe{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}search(e){var t;this.searchBlock(this.body,e),(t=this.continuing)===null||t===void 0||t.search(e)}}class su extends pe{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}search(e){e(this);for(const t of this.cases)t.search(e)}}class ou extends pe{constructor(e,t,i,r){super(),this.condition=e,this.body=t,this.elseif=i,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}}class au extends pe{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}}class n0 extends pe{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class i0 extends pe{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class lu extends pe{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class mo extends pe{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class r0 extends pe{constructor(){super()}get astNodeType(){return"discard"}}class cu extends pe{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class uu extends pe{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class k extends pe{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let i=1;i<e.length;++i){const r=k._priority.get(t.name);k._priority.get(e[i].name)<r&&(t=e[i])}return t.name==="x32"?k.i32:t}getTypeName(){return this.name}}k.x32=new k("x32"),k.f32=new k("f32"),k.i32=new k("i32"),k.u32=new k("u32"),k.f16=new k("f16"),k.bool=new k("bool"),k.void=new k("void"),k._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class fu extends k{constructor(e){super(e)}}class At extends k{constructor(e,t,i,r){super(e),this.members=t,this.startLine=i,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(const t of this.members)e(t)}}class T extends k{constructor(e,t,i){super(e),this.format=t,this.access=i}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}}T.vec2f=new T("vec2",k.f32,null),T.vec3f=new T("vec3",k.f32,null),T.vec4f=new T("vec4",k.f32,null),T.vec2i=new T("vec2",k.i32,null),T.vec3i=new T("vec3",k.i32,null),T.vec4i=new T("vec4",k.i32,null),T.vec2u=new T("vec2",k.u32,null),T.vec3u=new T("vec3",k.u32,null),T.vec4u=new T("vec4",k.u32,null),T.vec2h=new T("vec2",k.f16,null),T.vec3h=new T("vec3",k.f16,null),T.vec4h=new T("vec4",k.f16,null),T.vec2b=new T("vec2",k.bool,null),T.vec3b=new T("vec3",k.bool,null),T.vec4b=new T("vec4",k.bool,null),T.mat2x2f=new T("mat2x2",k.f32,null),T.mat2x3f=new T("mat2x3",k.f32,null),T.mat2x4f=new T("mat2x4",k.f32,null),T.mat3x2f=new T("mat3x2",k.f32,null),T.mat3x3f=new T("mat3x3",k.f32,null),T.mat3x4f=new T("mat3x4",k.f32,null),T.mat4x2f=new T("mat4x2",k.f32,null),T.mat4x3f=new T("mat4x3",k.f32,null),T.mat4x4f=new T("mat4x4",k.f32,null),T.mat2x2h=new T("mat2x2",k.f16,null),T.mat2x3h=new T("mat2x3",k.f16,null),T.mat2x4h=new T("mat2x4",k.f16,null),T.mat3x2h=new T("mat3x2",k.f16,null),T.mat3x3h=new T("mat3x3",k.f16,null),T.mat3x4h=new T("mat3x4",k.f16,null),T.mat4x2h=new T("mat4x2",k.f16,null),T.mat4x3h=new T("mat4x3",k.f16,null),T.mat4x4h=new T("mat4x4",k.f16,null),T.mat2x2i=new T("mat2x2",k.i32,null),T.mat2x3i=new T("mat2x3",k.i32,null),T.mat2x4i=new T("mat2x4",k.i32,null),T.mat3x2i=new T("mat3x2",k.i32,null),T.mat3x3i=new T("mat3x3",k.i32,null),T.mat3x4i=new T("mat3x4",k.i32,null),T.mat4x2i=new T("mat4x2",k.i32,null),T.mat4x3i=new T("mat4x3",k.i32,null),T.mat4x4i=new T("mat4x4",k.i32,null),T.mat2x2u=new T("mat2x2",k.u32,null),T.mat2x3u=new T("mat2x3",k.u32,null),T.mat2x4u=new T("mat2x4",k.u32,null),T.mat3x2u=new T("mat3x2",k.u32,null),T.mat3x3u=new T("mat3x3",k.u32,null),T.mat3x4u=new T("mat3x4",k.u32,null),T.mat4x2u=new T("mat4x2",k.u32,null),T.mat4x3u=new T("mat4x3",k.u32,null),T.mat4x4u=new T("mat4x4",k.u32,null);class hr extends k{constructor(e,t,i,r){super(e),this.storage=t,this.type=i,this.access=r}get astNodeType(){return"pointer"}}class Qn extends k{constructor(e,t,i,r){super(e),this.attributes=t,this.format=i,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}}class Jn extends k{constructor(e,t,i){super(e),this.format=t,this.access=i}get astNodeType(){return"sampler"}}class lt extends Ge{constructor(){super(),this.postfix=null}}class jt extends lt{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class gt extends lt{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(const t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}}class go extends lt{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return Gc.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(const t of this.args)t.search(e);e(this)}}class Ze extends lt{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,t){return e.evalExpression(this,e.context)}}class hu extends lt{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){const i=e.evalExpression(this.initializer,e.context);return i!==null&&this.postfix?i.getSubData(e,this.postfix,e.context):i}return null}search(e){this.initializer.search(e)}}class Ae extends lt{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof v}get isVector(){return this.value instanceof g||this.value instanceof K}get scalarValue(){return this.value instanceof v?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof g||this.value instanceof K?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}}class du extends lt{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class _n extends lt{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class pu extends lt{constructor(){super()}}class Se extends pu{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}}class ct extends pu{constructor(e,t,i){super(),this.operator=e,this.left=t,this.right=i}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?k.f32:e.name==="u32"||t.name==="u32"?k.u32:k.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class mu extends Ge{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class dr extends lt{constructor(){super()}get astNodeType(){return"default"}}class gu extends mu{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class _u extends mu{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class xu extends Ge{constructor(e,t,i){super(),this.name=e,this.type=t,this.attributes=i}get astNodeType(){return"argument"}}class s0 extends Ge{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}}class yu extends Ge{constructor(e,t,i){super(),this.name=e,this.type=t,this.attributes=i}get astNodeType(){return"member"}}class vu extends Ge{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class et{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=et._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,i,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,i){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}}et._id=0;class _o extends et{constructor(){super(new Je("void",null),null)}toString(){return"void"}}_o.void=new _o;class xn extends et{constructor(e){super(new lo("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,t,i,r){this.reference.setDataValue(e,t,i,r)}getSubData(e,t,i){return t?this.reference.getSubData(e,t,i):this}toString(){return`&${this.reference.toString()}`}}class v extends et{constructor(e,t,i=null){super(t,i),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new v(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new v(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new v(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,i,r){if(i)return void console.error("SetDataValue: Scalar data does not support postfix",i);if(!(t instanceof v))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,i){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}}function o0(n,e,t){const i=e.length;return i===2?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec2i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec2u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):i===3?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec3i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec3u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):i===4?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec4i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec4u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}class g extends et{constructor(e,t,i=null){if(super(t,i),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{const r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new g(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new g(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new g(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,i,r){i instanceof jt?console.error("TODO: Set vector postfix"):t instanceof g?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,i){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof qt)r=this.typeInfo.format||r;else{const o=this.typeInfo.name;o==="vec2f"||o==="vec3f"||o==="vec4f"?r=e.getTypeInfo("f32"):o==="vec2i"||o==="vec3i"||o==="vec4i"?r=e.getTypeInfo("i32"):o==="vec2b"||o==="vec3b"||o==="vec4b"?r=e.getTypeInfo("bool"):o==="vec2u"||o==="vec3u"||o==="vec4u"?r=e.getTypeInfo("u32"):o==="vec2h"||o==="vec3h"||o==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${o}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof _n){const o=t.index;let a=-1;if(o instanceof Ae){if(!(o.value instanceof v))return console.error(`GetSubData: Invalid array index ${o.value}`),null;a=o.value.value}else{const l=e.evalExpression(o,i);if(!(l instanceof v))return console.error("GetSubData: Unknown index type",o),null;a=l.value}if(a<0||a>=s.data.length)return console.error("GetSubData: Index out of range",a),null;if(s.data instanceof Float32Array){const l=new Float32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}if(s.data instanceof Int32Array){const l=new Int32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}if(s.data instanceof Uint32Array){const l=new Uint32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof jt))return console.error("GetSubData: Unknown postfix",t),null;{const o=t.value.toLowerCase();if(o.length===1){let l=0;if(o==="x"||o==="r")l=0;else if(o==="y"||o==="g")l=1;else if(o==="z"||o==="b")l=2;else{if(o!=="w"&&o!=="a")return console.error(`GetSubData: Unknown member ${o}`),null;l=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}}const a=[];for(const l of o)l==="x"||l==="r"?a.push(this.data[0]):l==="y"||l==="g"?a.push(this.data[1]):l==="z"||l==="b"?a.push(this.data[2]):l==="w"||l==="a"?a.push(this.data[3]):console.error(`GetDataValue: Unknown member ${l}`);s=o0(e,a,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class K extends et{constructor(e,t,i=null){super(t,i),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new K(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,i,r){i instanceof jt?console.error("TODO: Set matrix postfix"):t instanceof K?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,i){if(t===null)return this;const r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof qt)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof _n){const s=t.index;let o=-1;if(s instanceof Ae){if(!(s.value instanceof v))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;o=s.value.value}else{const c=e.evalExpression(s,i);if(!(c instanceof v))return console.error("GetDataValue: Unknown index type",s),null;o=c.value}if(o<0||o>=this.data.length)return console.error("GetDataValue: Index out of range",o),null;const a=r.endsWith("h")?"h":"f";let l;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+2*o*4,2),e.getTypeInfo(`vec2${a}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+3*o*4,3),e.getTypeInfo(`vec3${a}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+4*o*4,4),e.getTypeInfo(`vec4${a}`))}return t.postfix?l.getSubData(e,t.postfix,i):l}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class ve extends et{constructor(e,t,i=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=i}clone(){const e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new ve(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,i,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,o=this.typeInfo;for(;i;){if(i instanceof _n)if(o instanceof Mt){const a=i.index;if(a instanceof Ae){if(!(a.value instanceof v))return void console.error(`SetDataValue: Invalid index type ${a.value}`);s+=a.value.value*o.stride}else{const l=e.evalExpression(a,r);if(!(l instanceof v))return void console.error("SetDataValue: Unknown index type",a);s+=l.value*o.stride}o=o.format}else console.error(`SetDataValue: Type ${o.getTypeName()} is not an array`);else{if(!(i instanceof jt))return void console.error("SetDataValue: Unknown postfix type",i);{const a=i.value;if(o instanceof Dt){let l=!1;for(const c of o.members)if(c.name===a){s+=c.offset,o=c.type,l=!0;break}if(!l)return void console.error(`SetDataValue: Member ${a} not found`)}else if(o instanceof Je){const l=o.getTypeName();let c=0;if(a==="x"||a==="r")c=0;else if(a==="y"||a==="g")c=1;else if(a==="z"||a==="b")c=2;else{if(a!=="w"&&a!=="a")return void console.error(`SetDataValue: Unknown member ${a}`);c=3}if(!(t instanceof v))return void console.error("SetDataValue: Invalid value",t);const u=t.value;return l==="vec2f"?void(new Float32Array(this.buffer,s,2)[c]=u):l==="vec3f"?void(new Float32Array(this.buffer,s,3)[c]=u):l==="vec4f"?void(new Float32Array(this.buffer,s,4)[c]=u):l==="vec2i"?void(new Int32Array(this.buffer,s,2)[c]=u):l==="vec3i"?void(new Int32Array(this.buffer,s,3)[c]=u):l==="vec4i"?void(new Int32Array(this.buffer,s,4)[c]=u):l==="vec2u"?void(new Uint32Array(this.buffer,s,2)[c]=u):l==="vec3u"?void(new Uint32Array(this.buffer,s,3)[c]=u):l==="vec4u"?void(new Uint32Array(this.buffer,s,4)[c]=u):void console.error(`SetDataValue: Type ${l} is not a struct`)}}}i=i.postfix}this.setData(e,t,o,s,r)}setData(e,t,i,r,s){const o=i.getTypeName();if(o!=="f32"&&o!=="f16")if(o!=="i32"&&o!=="atomic<i32>"&&o!=="x32")if(o!=="u32"&&o!=="atomic<u32>")if(o!=="bool"){if(o==="vec2f"||o==="vec2h"){const a=new Float32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3f"||o==="vec3h"){const a=new Float32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4f"||o==="vec4h"){const a=new Float32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2i"){const a=new Int32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3i"){const a=new Int32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4i"){const a=new Int32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2u"){const a=new Uint32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3u"){const a=new Uint32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4u"){const a=new Uint32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2b"){const a=new Uint32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3b"){const a=new Uint32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4b"){const a=new Uint32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="mat2x2f"||o==="mat2x2h"){const a=new Float32Array(this.buffer,r,4);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="mat2x3f"||o==="mat2x3h"){const a=new Float32Array(this.buffer,r,6);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5]))}if(o==="mat2x4f"||o==="mat2x4h"){const a=new Float32Array(this.buffer,r,8);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7]))}if(o==="mat3x2f"||o==="mat3x2h"){const a=new Float32Array(this.buffer,r,6);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5]))}if(o==="mat3x3f"||o==="mat3x3h"){const a=new Float32Array(this.buffer,r,9);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8]))}if(o==="mat3x4f"||o==="mat3x4h"){const a=new Float32Array(this.buffer,r,12);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11]))}if(o==="mat4x2f"||o==="mat4x2h"){const a=new Float32Array(this.buffer,r,8);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7]))}if(o==="mat4x3f"||o==="mat4x3h"){const a=new Float32Array(this.buffer,r,12);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11]))}if(o==="mat4x4f"||o==="mat4x4h"){const a=new Float32Array(this.buffer,r,16);return void(t instanceof K?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11],a[12]=t.data[12],a[13]=t.data[13],a[14]=t.data[14],a[15]=t.data[15]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11],a[12]=t[12],a[13]=t[13],a[14]=t[14],a[15]=t[15]))}if(t instanceof ve){if(i===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",o,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${o}`)}else t instanceof v&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,i){var r,s,o;if(t===null)return this;let a=this.offset,l=this.typeInfo;for(;t;){if(t instanceof _n){const u=t.index,f=u instanceof lt?e.evalExpression(u,i):u;let h=0;if(f instanceof v?h=f.value:typeof f=="number"?h=f:console.error("GetDataValue: Invalid index type",u),l instanceof Mt)a+=h*l.stride,l=l.format;else{const d=l.getTypeName();d==="mat4x4"||d==="mat4x4f"||d==="mat4x4h"?(a+=16*h,l=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${l.getTypeName()} is not an array`)}}else{if(!(t instanceof jt))return console.error("GetDataValue: Unknown postfix type",t),null;{const u=t.value;if(l instanceof Dt){let f=!1;for(const h of l.members)if(h.name===u){a+=h.offset,l=h.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${u} not found`),null}else if(l instanceof Je){const f=l.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(u.length>0&&u.length<5){let h="f";const d=[];for(let _=0;_<u.length;++_){const I=u[_].toLowerCase();let P=0;if(I==="x"||I==="r")P=0;else if(I==="y"||I==="g")P=1;else if(I==="z"||I==="b")P=2;else{if(I!=="w"&&I!=="a")return console.error(`Unknown member ${u}`),null;P=3}if(u.length===1){if(f.endsWith("f"))return this.buffer.byteLength<a+4*P+4?(console.log("Insufficient buffer data"),null):new v(new Float32Array(this.buffer,a+4*P,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new v(new Float32Array(this.buffer,a+4*P,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new v(new Int32Array(this.buffer,a+4*P,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new v(new Int32Array(this.buffer,a+4*P,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new v(new Uint32Array(this.buffer,a+4*P,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")d.push(new Float32Array(this.buffer,a,2)[P]);else if(f==="vec3f"){if(a+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;const A=new Float32Array(this.buffer,a,3);d.push(A[P])}else if(f==="vec4f")d.push(new Float32Array(this.buffer,a,4)[P]);else if(f==="vec2i")h="i",d.push(new Int32Array(this.buffer,a,2)[P]);else if(f==="vec3i")h="i",d.push(new Int32Array(this.buffer,a,3)[P]);else if(f==="vec4i")h="i",d.push(new Int32Array(this.buffer,a,4)[P]);else if(f==="vec2u"){h="u";const A=new Uint32Array(this.buffer,a,2);d.push(A[P])}else f==="vec3u"?(h="u",d.push(new Uint32Array(this.buffer,a,3)[P])):f==="vec4u"&&(h="u",d.push(new Uint32Array(this.buffer,a,4)[P]))}return d.length===2?l=e.getTypeInfo(`vec2${h}`):d.length===3?l=e.getTypeInfo(`vec3${h}`):d.length===4?l=e.getTypeInfo(`vec4${h}`):console.error(`GetDataValue: Invalid vector length ${d.length}`),new g(d,l,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}const c=l.getTypeName();return c==="f32"?new v(new Float32Array(this.buffer,a,1),l,this):c==="i32"?new v(new Int32Array(this.buffer,a,1),l,this):c==="u32"?new v(new Uint32Array(this.buffer,a,1),l,this):c==="vec2f"?new g(new Float32Array(this.buffer,a,2),l,this):c==="vec3f"?new g(new Float32Array(this.buffer,a,3),l,this):c==="vec4f"?new g(new Float32Array(this.buffer,a,4),l,this):c==="vec2i"?new g(new Int32Array(this.buffer,a,2),l,this):c==="vec3i"?new g(new Int32Array(this.buffer,a,3),l,this):c==="vec4i"?new g(new Int32Array(this.buffer,a,4),l,this):c==="vec2u"?new g(new Uint32Array(this.buffer,a,2),l,this):c==="vec3u"?new g(new Uint32Array(this.buffer,a,3),l,this):c==="vec4u"?new g(new Uint32Array(this.buffer,a,4),l,this):l instanceof qt&&l.name==="atomic"?((r=l.format)===null||r===void 0?void 0:r.name)==="u32"?new v(new Uint32Array(this.buffer,a,1)[0],l.format,this):((s=l.format)===null||s===void 0?void 0:s.name)==="i32"?new v(new Int32Array(this.buffer,a,1)[0],l.format,this):(console.error(`GetDataValue: Invalid atomic format ${(o=l.format)===null||o===void 0?void 0:o.name}`),null):new ve(this.buffer,l,a,this)}toString(){let e="";if(this.typeInfo instanceof Mt)if(this.typeInfo.format.name==="f32"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="i32"){const t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="u32"){const t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="vec2f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let i=1;i<t.length/2;++i)e+=`, [${t[2*i]}, ${t[2*i+1]}]`}else if(this.typeInfo.format.name==="vec3f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let i=4;i<t.length;i+=4)e+=`, [${t[i]}, ${t[i+1]}, ${t[i+2]}]`}else if(this.typeInfo.format.name==="vec4f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let i=4;i<t.length;i+=4)e+=`, [${t[i]}, ${t[i+1]}, ${t[i+2]}, ${t[i+3]}]`}else e="[...]";else this.typeInfo instanceof Dt?e+="{...}":e="[...]";return e}}class Ct extends et{constructor(e,t,i,r){super(t,null),this.data=e,this.descriptor=i,this.view=r}clone(){return new Ct(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>0?(e=i[0])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.width)!==null&&t!==void 0?t:0}get height(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>1?(e=i[1])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>2?(e=i[2])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];const t=[this.width,this.height,this.depthOrArrayLayers];for(let i=0;i<t.length;++i)t[i]=Math.max(1,t[i]>>e);return t}get texelByteSize(){const e=this.format,t=uo[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=uo[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=uo[e],i=this.width;if(!e||i<=0||!t)return-1;const r=this.height,s=this.depthOrArrayLayers,o=this.dimension;return i/t.blockWidth*(o==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,i=0,r=0){const s=this.texelByteSize,o=this.bytesPerRow,a=this.height,l=this.data[r];return e0(new Uint8Array(l),e,t,i,r,a,o,s,this.format)}setPixel(e,t,i,r,s){const o=this.texelByteSize,a=this.bytesPerRow,l=this.height,c=this.data[r];(function(u,f,h,d,_,I,P,A,O,E){const x=d*(P>>=_)*(I>>=_)+h*P+f*A;switch(O){case"r8unorm":return void le(u,x,"8unorm",1,E);case"r8snorm":return void le(u,x,"8snorm",1,E);case"r8uint":return void le(u,x,"8uint",1,E);case"r8sint":return void le(u,x,"8sint",1,E);case"rg8unorm":return void le(u,x,"8unorm",2,E);case"rg8snorm":return void le(u,x,"8snorm",2,E);case"rg8uint":return void le(u,x,"8uint",2,E);case"rg8sint":return void le(u,x,"8sint",2,E);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void le(u,x,"8unorm",4,E);case"rgba8snorm":return void le(u,x,"8snorm",4,E);case"rgba8uint":return void le(u,x,"8uint",4,E);case"rgba8sint":return void le(u,x,"8sint",4,E);case"r16uint":return void le(u,x,"16uint",1,E);case"r16sint":return void le(u,x,"16sint",1,E);case"r16float":return void le(u,x,"16float",1,E);case"rg16uint":return void le(u,x,"16uint",2,E);case"rg16sint":return void le(u,x,"16sint",2,E);case"rg16float":return void le(u,x,"16float",2,E);case"rgba16uint":return void le(u,x,"16uint",4,E);case"rgba16sint":return void le(u,x,"16sint",4,E);case"rgba16float":return void le(u,x,"16float",4,E);case"r32uint":return void le(u,x,"32uint",1,E);case"r32sint":return void le(u,x,"32sint",1,E);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void le(u,x,"32float",1,E);case"rg32uint":return void le(u,x,"32uint",2,E);case"rg32sint":return void le(u,x,"32sint",2,E);case"rg32float":return void le(u,x,"32float",2,E);case"rgba32uint":return void le(u,x,"32uint",4,E);case"rgba32sint":return void le(u,x,"32sint",4,E);case"rgba32float":return void le(u,x,"32float",4,E);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,i,r,l,a,o,this.format,s)}}(n=>{n[n.token=0]="token",n[n.keyword=1]="keyword",n[n.reserved=2]="reserved"})(b||(b={}));class S{constructor(e,t,i){this.name=e,this.type=t,this.rule=i}toString(){return this.name}}class p{}w=p,p.none=new S("",b.reserved,""),p.eof=new S("EOF",b.token,""),p.reserved={asm:new S("asm",b.reserved,"asm"),bf16:new S("bf16",b.reserved,"bf16"),do:new S("do",b.reserved,"do"),enum:new S("enum",b.reserved,"enum"),f16:new S("f16",b.reserved,"f16"),f64:new S("f64",b.reserved,"f64"),handle:new S("handle",b.reserved,"handle"),i8:new S("i8",b.reserved,"i8"),i16:new S("i16",b.reserved,"i16"),i64:new S("i64",b.reserved,"i64"),mat:new S("mat",b.reserved,"mat"),premerge:new S("premerge",b.reserved,"premerge"),regardless:new S("regardless",b.reserved,"regardless"),typedef:new S("typedef",b.reserved,"typedef"),u8:new S("u8",b.reserved,"u8"),u16:new S("u16",b.reserved,"u16"),u64:new S("u64",b.reserved,"u64"),unless:new S("unless",b.reserved,"unless"),using:new S("using",b.reserved,"using"),vec:new S("vec",b.reserved,"vec"),void:new S("void",b.reserved,"void")},p.keywords={array:new S("array",b.keyword,"array"),atomic:new S("atomic",b.keyword,"atomic"),bool:new S("bool",b.keyword,"bool"),f32:new S("f32",b.keyword,"f32"),i32:new S("i32",b.keyword,"i32"),mat2x2:new S("mat2x2",b.keyword,"mat2x2"),mat2x3:new S("mat2x3",b.keyword,"mat2x3"),mat2x4:new S("mat2x4",b.keyword,"mat2x4"),mat3x2:new S("mat3x2",b.keyword,"mat3x2"),mat3x3:new S("mat3x3",b.keyword,"mat3x3"),mat3x4:new S("mat3x4",b.keyword,"mat3x4"),mat4x2:new S("mat4x2",b.keyword,"mat4x2"),mat4x3:new S("mat4x3",b.keyword,"mat4x3"),mat4x4:new S("mat4x4",b.keyword,"mat4x4"),ptr:new S("ptr",b.keyword,"ptr"),sampler:new S("sampler",b.keyword,"sampler"),sampler_comparison:new S("sampler_comparison",b.keyword,"sampler_comparison"),struct:new S("struct",b.keyword,"struct"),texture_1d:new S("texture_1d",b.keyword,"texture_1d"),texture_2d:new S("texture_2d",b.keyword,"texture_2d"),texture_2d_array:new S("texture_2d_array",b.keyword,"texture_2d_array"),texture_3d:new S("texture_3d",b.keyword,"texture_3d"),texture_cube:new S("texture_cube",b.keyword,"texture_cube"),texture_cube_array:new S("texture_cube_array",b.keyword,"texture_cube_array"),texture_multisampled_2d:new S("texture_multisampled_2d",b.keyword,"texture_multisampled_2d"),texture_storage_1d:new S("texture_storage_1d",b.keyword,"texture_storage_1d"),texture_storage_2d:new S("texture_storage_2d",b.keyword,"texture_storage_2d"),texture_storage_2d_array:new S("texture_storage_2d_array",b.keyword,"texture_storage_2d_array"),texture_storage_3d:new S("texture_storage_3d",b.keyword,"texture_storage_3d"),texture_depth_2d:new S("texture_depth_2d",b.keyword,"texture_depth_2d"),texture_depth_2d_array:new S("texture_depth_2d_array",b.keyword,"texture_depth_2d_array"),texture_depth_cube:new S("texture_depth_cube",b.keyword,"texture_depth_cube"),texture_depth_cube_array:new S("texture_depth_cube_array",b.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new S("texture_depth_multisampled_2d",b.keyword,"texture_depth_multisampled_2d"),texture_external:new S("texture_external",b.keyword,"texture_external"),u32:new S("u32",b.keyword,"u32"),vec2:new S("vec2",b.keyword,"vec2"),vec3:new S("vec3",b.keyword,"vec3"),vec4:new S("vec4",b.keyword,"vec4"),bitcast:new S("bitcast",b.keyword,"bitcast"),block:new S("block",b.keyword,"block"),break:new S("break",b.keyword,"break"),case:new S("case",b.keyword,"case"),continue:new S("continue",b.keyword,"continue"),continuing:new S("continuing",b.keyword,"continuing"),default:new S("default",b.keyword,"default"),diagnostic:new S("diagnostic",b.keyword,"diagnostic"),discard:new S("discard",b.keyword,"discard"),else:new S("else",b.keyword,"else"),enable:new S("enable",b.keyword,"enable"),fallthrough:new S("fallthrough",b.keyword,"fallthrough"),false:new S("false",b.keyword,"false"),fn:new S("fn",b.keyword,"fn"),for:new S("for",b.keyword,"for"),function:new S("function",b.keyword,"function"),if:new S("if",b.keyword,"if"),let:new S("let",b.keyword,"let"),const:new S("const",b.keyword,"const"),loop:new S("loop",b.keyword,"loop"),while:new S("while",b.keyword,"while"),private:new S("private",b.keyword,"private"),read:new S("read",b.keyword,"read"),read_write:new S("read_write",b.keyword,"read_write"),return:new S("return",b.keyword,"return"),requires:new S("requires",b.keyword,"requires"),storage:new S("storage",b.keyword,"storage"),switch:new S("switch",b.keyword,"switch"),true:new S("true",b.keyword,"true"),alias:new S("alias",b.keyword,"alias"),type:new S("type",b.keyword,"type"),uniform:new S("uniform",b.keyword,"uniform"),var:new S("var",b.keyword,"var"),override:new S("override",b.keyword,"override"),workgroup:new S("workgroup",b.keyword,"workgroup"),write:new S("write",b.keyword,"write"),r8unorm:new S("r8unorm",b.keyword,"r8unorm"),r8snorm:new S("r8snorm",b.keyword,"r8snorm"),r8uint:new S("r8uint",b.keyword,"r8uint"),r8sint:new S("r8sint",b.keyword,"r8sint"),r16uint:new S("r16uint",b.keyword,"r16uint"),r16sint:new S("r16sint",b.keyword,"r16sint"),r16float:new S("r16float",b.keyword,"r16float"),rg8unorm:new S("rg8unorm",b.keyword,"rg8unorm"),rg8snorm:new S("rg8snorm",b.keyword,"rg8snorm"),rg8uint:new S("rg8uint",b.keyword,"rg8uint"),rg8sint:new S("rg8sint",b.keyword,"rg8sint"),r32uint:new S("r32uint",b.keyword,"r32uint"),r32sint:new S("r32sint",b.keyword,"r32sint"),r32float:new S("r32float",b.keyword,"r32float"),rg16uint:new S("rg16uint",b.keyword,"rg16uint"),rg16sint:new S("rg16sint",b.keyword,"rg16sint"),rg16float:new S("rg16float",b.keyword,"rg16float"),rgba8unorm:new S("rgba8unorm",b.keyword,"rgba8unorm"),rgba8unorm_srgb:new S("rgba8unorm_srgb",b.keyword,"rgba8unorm_srgb"),rgba8snorm:new S("rgba8snorm",b.keyword,"rgba8snorm"),rgba8uint:new S("rgba8uint",b.keyword,"rgba8uint"),rgba8sint:new S("rgba8sint",b.keyword,"rgba8sint"),bgra8unorm:new S("bgra8unorm",b.keyword,"bgra8unorm"),bgra8unorm_srgb:new S("bgra8unorm_srgb",b.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new S("rgb10a2unorm",b.keyword,"rgb10a2unorm"),rg11b10float:new S("rg11b10float",b.keyword,"rg11b10float"),rg32uint:new S("rg32uint",b.keyword,"rg32uint"),rg32sint:new S("rg32sint",b.keyword,"rg32sint"),rg32float:new S("rg32float",b.keyword,"rg32float"),rgba16uint:new S("rgba16uint",b.keyword,"rgba16uint"),rgba16sint:new S("rgba16sint",b.keyword,"rgba16sint"),rgba16float:new S("rgba16float",b.keyword,"rgba16float"),rgba32uint:new S("rgba32uint",b.keyword,"rgba32uint"),rgba32sint:new S("rgba32sint",b.keyword,"rgba32sint"),rgba32float:new S("rgba32float",b.keyword,"rgba32float"),static_assert:new S("static_assert",b.keyword,"static_assert")},p.tokens={decimal_float_literal:new S("decimal_float_literal",b.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new S("hex_float_literal",b.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new S("int_literal",b.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new S("uint_literal",b.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new S("name",b.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new S("ident",b.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new S("and",b.token,"&"),and_and:new S("and_and",b.token,"&&"),arrow:new S("arrow ",b.token,"->"),attr:new S("attr",b.token,"@"),forward_slash:new S("forward_slash",b.token,"/"),bang:new S("bang",b.token,"!"),bracket_left:new S("bracket_left",b.token,"["),bracket_right:new S("bracket_right",b.token,"]"),brace_left:new S("brace_left",b.token,"{"),brace_right:new S("brace_right",b.token,"}"),colon:new S("colon",b.token,":"),comma:new S("comma",b.token,","),equal:new S("equal",b.token,"="),equal_equal:new S("equal_equal",b.token,"=="),not_equal:new S("not_equal",b.token,"!="),greater_than:new S("greater_than",b.token,">"),greater_than_equal:new S("greater_than_equal",b.token,">="),shift_right:new S("shift_right",b.token,">>"),less_than:new S("less_than",b.token,"<"),less_than_equal:new S("less_than_equal",b.token,"<="),shift_left:new S("shift_left",b.token,"<<"),modulo:new S("modulo",b.token,"%"),minus:new S("minus",b.token,"-"),minus_minus:new S("minus_minus",b.token,"--"),period:new S("period",b.token,"."),plus:new S("plus",b.token,"+"),plus_plus:new S("plus_plus",b.token,"++"),or:new S("or",b.token,"|"),or_or:new S("or_or",b.token,"||"),paren_left:new S("paren_left",b.token,"("),paren_right:new S("paren_right",b.token,")"),semicolon:new S("semicolon",b.token,";"),star:new S("star",b.token,"*"),tilde:new S("tilde",b.token,"~"),underscore:new S("underscore",b.token,"_"),xor:new S("xor",b.token,"^"),plus_equal:new S("plus_equal",b.token,"+="),minus_equal:new S("minus_equal",b.token,"-="),times_equal:new S("times_equal",b.token,"*="),division_equal:new S("division_equal",b.token,"/="),modulo_equal:new S("modulo_equal",b.token,"%="),and_equal:new S("and_equal",b.token,"&="),or_equal:new S("or_equal",b.token,"|="),xor_equal:new S("xor_equal",b.token,"^="),shift_right_equal:new S("shift_right_equal",b.token,">>="),shift_left_equal:new S("shift_left_equal",b.token,"<<=")},p.simpleTokens={"@":w.tokens.attr,"{":w.tokens.brace_left,"}":w.tokens.brace_right,":":w.tokens.colon,",":w.tokens.comma,"(":w.tokens.paren_left,")":w.tokens.paren_right,";":w.tokens.semicolon},p.literalTokens={"&":w.tokens.and,"&&":w.tokens.and_and,"->":w.tokens.arrow,"/":w.tokens.forward_slash,"!":w.tokens.bang,"[":w.tokens.bracket_left,"]":w.tokens.bracket_right,"=":w.tokens.equal,"==":w.tokens.equal_equal,"!=":w.tokens.not_equal,">":w.tokens.greater_than,">=":w.tokens.greater_than_equal,">>":w.tokens.shift_right,"<":w.tokens.less_than,"<=":w.tokens.less_than_equal,"<<":w.tokens.shift_left,"%":w.tokens.modulo,"-":w.tokens.minus,"--":w.tokens.minus_minus,".":w.tokens.period,"+":w.tokens.plus,"++":w.tokens.plus_plus,"|":w.tokens.or,"||":w.tokens.or_or,"*":w.tokens.star,"~":w.tokens.tilde,_:w.tokens.underscore,"^":w.tokens.xor,"+=":w.tokens.plus_equal,"-=":w.tokens.minus_equal,"*=":w.tokens.times_equal,"/=":w.tokens.division_equal,"%=":w.tokens.modulo_equal,"&=":w.tokens.and_equal,"|=":w.tokens.or_equal,"^=":w.tokens.xor_equal,">>=":w.tokens.shift_right_equal,"<<=":w.tokens.shift_left_equal},p.regexTokens={decimal_float_literal:w.tokens.decimal_float_literal,hex_float_literal:w.tokens.hex_float_literal,int_literal:w.tokens.int_literal,uint_literal:w.tokens.uint_literal,ident:w.tokens.ident},p.storage_class=[w.keywords.function,w.keywords.private,w.keywords.workgroup,w.keywords.uniform,w.keywords.storage],p.access_mode=[w.keywords.read,w.keywords.write,w.keywords.read_write],p.sampler_type=[w.keywords.sampler,w.keywords.sampler_comparison],p.sampled_texture_type=[w.keywords.texture_1d,w.keywords.texture_2d,w.keywords.texture_2d_array,w.keywords.texture_3d,w.keywords.texture_cube,w.keywords.texture_cube_array],p.multisampled_texture_type=[w.keywords.texture_multisampled_2d],p.storage_texture_type=[w.keywords.texture_storage_1d,w.keywords.texture_storage_2d,w.keywords.texture_storage_2d_array,w.keywords.texture_storage_3d],p.depth_texture_type=[w.keywords.texture_depth_2d,w.keywords.texture_depth_2d_array,w.keywords.texture_depth_cube,w.keywords.texture_depth_cube_array,w.keywords.texture_depth_multisampled_2d],p.texture_external_type=[w.keywords.texture_external],p.any_texture_type=[...w.sampled_texture_type,...w.multisampled_texture_type,...w.storage_texture_type,...w.depth_texture_type,...w.texture_external_type],p.texel_format=[w.keywords.r8unorm,w.keywords.r8snorm,w.keywords.r8uint,w.keywords.r8sint,w.keywords.r16uint,w.keywords.r16sint,w.keywords.r16float,w.keywords.rg8unorm,w.keywords.rg8snorm,w.keywords.rg8uint,w.keywords.rg8sint,w.keywords.r32uint,w.keywords.r32sint,w.keywords.r32float,w.keywords.rg16uint,w.keywords.rg16sint,w.keywords.rg16float,w.keywords.rgba8unorm,w.keywords.rgba8unorm_srgb,w.keywords.rgba8snorm,w.keywords.rgba8uint,w.keywords.rgba8sint,w.keywords.bgra8unorm,w.keywords.bgra8unorm_srgb,w.keywords.rgb10a2unorm,w.keywords.rg11b10float,w.keywords.rg32uint,w.keywords.rg32sint,w.keywords.rg32float,w.keywords.rgba16uint,w.keywords.rgba16sint,w.keywords.rgba16float,w.keywords.rgba32uint,w.keywords.rgba32sint,w.keywords.rgba32float],p.const_literal=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.keywords.true,w.keywords.false],p.literal_or_ident=[w.tokens.ident,w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.tokens.name],p.element_count_expression=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.ident],p.template_types=[w.keywords.vec2,w.keywords.vec3,w.keywords.vec4,w.keywords.mat2x2,w.keywords.mat2x3,w.keywords.mat2x4,w.keywords.mat3x2,w.keywords.mat3x3,w.keywords.mat3x4,w.keywords.mat4x2,w.keywords.mat4x3,w.keywords.mat4x4,w.keywords.atomic,w.keywords.bitcast,...w.any_texture_type],p.attribute_name=[w.tokens.ident,w.keywords.block,w.keywords.diagnostic],p.assignment_operators=[w.tokens.equal,w.tokens.plus_equal,w.tokens.minus_equal,w.tokens.times_equal,w.tokens.division_equal,w.tokens.modulo_equal,w.tokens.and_equal,w.tokens.or_equal,w.tokens.xor_equal,w.tokens.shift_right_equal,w.tokens.shift_left_equal],p.increment_operators=[w.tokens.plus_plus,w.tokens.minus_minus];class bu{constructor(e,t,i,r,s){this.type=e,this.lexeme=t,this.line=i,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return p.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==p.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class a0{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new bu(p.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
90
+ `,r}const Oy=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,By=/^\s*\#\s*endif\s*$/;function Uy(n,e){var o;const t=n.split(`
91
+ `),i=[];let r=!0,s=null;for(const a of t){const l=a.match(Oy),c=a.match(By);l?(s=l[1],r=!!((o=e==null?void 0:e.defines)!=null&&o[s])):c?r=!0:r&&i.push(a)}return i.join(`
92
+ `)}const Gt=class Gt{constructor(){m(this,"_hookFunctions",[]);m(this,"_defaultModules",[])}static getDefaultShaderAssembler(){return Gt.defaultShaderAssembler=Gt.defaultShaderAssembler||new Gt,Gt.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){const t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){const t=this._getModuleList(e.modules),i=this._hookFunctions,{source:r,getUniforms:s}=Dy({...e,source:e.source,modules:t,hookFunctions:i});return{source:e.platformInfo.shaderLanguage==="wgsl"?Uy(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){const t=this._getModuleList(e.modules),i=this._hookFunctions;return{...Fy({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:i}),modules:t}}_getModuleList(e=[]){const t=new Array(this._defaultModules.length+e.length),i={};let r=0;for(let s=0,o=this._defaultModules.length;s<o;++s){const a=this._defaultModules[s],l=a.name;t[r++]=a,i[l]=!0}for(let s=0,o=e.length;s<o;++s){const a=e[s],l=a.name;i[l]||(t[r++]=a,i[l]=!0)}return t.length=r,ar(t),t}};m(Gt,"defaultShaderAssembler");let co=Gt;class Ge{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}get isPointer(){return!1}getTypeName(){return this.name}}class Hc{constructor(e,t,i){this.name=e,this.type=t,this.attributes=i,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class Ft extends Ge{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}}class Mt extends Ge{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}}class uo extends Ge{constructor(e,t,i){super(e,i),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class jt extends Ge{constructor(e,t,i,r){super(e,i),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}}var Nt;(n=>{n[n.Uniform=0]="Uniform",n[n.Storage=1]="Storage",n[n.Texture=2]="Texture",n[n.Sampler=3]="Sampler",n[n.StorageTexture=4]="StorageTexture"})(Nt||(Nt={}));class lr{constructor(e,t,i,r,s,o,a){this.name=e,this.type=t,this.group=i,this.binding=r,this.attributes=s,this.resourceType=o,this.access=a}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class zy{constructor(e,t){this.name=e,this.type=t}}class Ly{constructor(e,t,i,r){this.name=e,this.type=t,this.locationType=i,this.location=r,this.interpolation=null}}class Wc{constructor(e,t,i,r){this.name=e,this.type=t,this.locationType=i,this.location=r}}class Vy{constructor(e,t,i,r){this.name=e,this.type=t,this.attributes=i,this.id=r}}class Hy{constructor(e,t,i){this.name=e,this.type=t,this.attributes=i}}class Wy{constructor(e,t=null,i){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=i}}class $y{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function Xy(n){var e=(32768&n)>>15,t=(31744&n)>>10,i=1023&n;return t==0?(e?-1:1)*Math.pow(2,-14)*(i/Math.pow(2,10)):t==31?i?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,t-15)*(1+i/Math.pow(2,10))}const $c=new Float32Array(1),Yy=new Int32Array($c.buffer),Ne=new Uint16Array(1);function qy(n){$c[0]=n;const e=Yy[0],t=e>>31&1;let i=e>>23&255,r=8388607&e;if(i===255)return Ne[0]=t<<15|31744|(r!==0?512:0),Ne[0];if(i===0){if(r===0)return Ne[0]=t<<15,Ne[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return i=127-s,r&=8388607,i>0?(r=(r>>126-i)+(r>>127-i&1),Ne[0]=t<<15|i<<10|r>>13,Ne[0]):(Ne[0]=t<<15,Ne[0])}return i=i-127+15,i>=31?(Ne[0]=t<<15|31744,Ne[0]):i<=0?i<-10?(Ne[0]=t<<15,Ne[0]):(r=(8388608|r)>>1-i,Ne[0]=t<<15|r>>13,Ne[0]):(r>>=13,Ne[0]=t<<15|i<<10|r,Ne[0])}const fo=new Uint32Array(1),Xc=new Float32Array(fo.buffer,0,1);function Yc(n){const e=112+(n>>6&31)<<23|(63&n)<<17;return fo[0]=e,Xc[0]}function jy(n,e,t,i,r,s,o,a,l){const c=i*(o>>=r)*(s>>=r)+t*o+e*a;switch(l){case"r8unorm":return[se(n,c,"8unorm",1)[0]];case"r8snorm":return[se(n,c,"8snorm",1)[0]];case"r8uint":return[se(n,c,"8uint",1)[0]];case"r8sint":return[se(n,c,"8sint",1)[0]];case"rg8unorm":{const u=se(n,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{const u=se(n,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{const u=se(n,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{const u=se(n,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const u=se(n,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{const u=se(n,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{const u=se(n,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{const u=se(n,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const u=se(n,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[se(n,c,"16uint",1)[0]];case"r16sint":return[se(n,c,"16sint",1)[0]];case"r16float":return[se(n,c,"16float",1)[0]];case"rg16uint":{const u=se(n,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{const u=se(n,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{const u=se(n,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{const u=se(n,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{const u=se(n,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{const u=se(n,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[se(n,c,"32uint",1)[0]];case"r32sint":return[se(n,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[se(n,c,"32float",1)[0]];case"rg32uint":{const u=se(n,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{const u=se(n,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{const u=se(n,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{const u=se(n,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{const u=se(n,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{const u=se(n,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{const u=new Uint32Array(n.buffer,c,1)[0],f=(4192256&u)>>11,h=(4290772992&u)>>22;return[Yc(2047&u),Yc(f),function(d){const _=112+(d>>5&31)<<23|(31&d)<<18;return fo[0]=_,Xc[0]}(h),1]}}return null}function se(n,e,t,i){const r=[0,0,0,0];for(let s=0;s<i;++s)switch(t){case"8unorm":r[s]=n[e]/255,e++;break;case"8snorm":r[s]=n[e]/255*2-1,e++;break;case"8uint":r[s]=n[e],e++;break;case"8sint":r[s]=n[e]-127,e++;break;case"16uint":r[s]=n[e]|n[e+1]<<8,e+=2;break;case"16sint":r[s]=(n[e]|n[e+1]<<8)-32768,e+=2;break;case"16float":r[s]=Xy(n[e]|n[e+1]<<8),e+=2;break;case"32uint":case"32sint":r[s]=n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24,e+=4;break;case"32float":r[s]=new Float32Array(n.buffer,e,1)[0],e+=4}return r}function oe(n,e,t,i,r){for(let s=0;s<i;++s)switch(t){case"8unorm":n[e]=255*r[s],e++;break;case"8snorm":n[e]=.5*(r[s]+1)*255,e++;break;case"8uint":n[e]=r[s],e++;break;case"8sint":n[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(n.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(n.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{const o=qy(r[s]);new Uint16Array(n.buffer,e,1)[0]=o,e+=2;break}case"32uint":new Uint32Array(n.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(n.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(n.buffer,e,1)[0]=r[s],e+=4}return r}const ho={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class et{constructor(){this.id=et._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(cr.instance);for(const i of e)i instanceof Array?this.searchBlock(i,t):i.search(t);t(ur.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}}et._id=0;class cr extends et{}cr.instance=new cr;class ur extends et{}ur.instance=new ur;const qc=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]);class de extends et{constructor(){super()}}class Kn extends de{constructor(e,t,i,r,s,o){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=i,this.body=r,this.startLine=s,this.endLine=o}get astNodeType(){return"function"}search(e){if(this.attributes)for(const t of this.attributes)e(t);e(this);for(const t of this.args)e(t);this.searchBlock(this.body,e)}}class Ky extends de{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}}class jc extends de{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}}class po extends de{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}}class Kc extends de{constructor(e,t,i,r){super(),this.init=e,this.condition=t,this.increment=i,this.body=r}get astNodeType(){return"for"}search(e){var t,i,r;(t=this.init)===null||t===void 0||t.search(e),(i=this.condition)===null||i===void 0||i.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}}class At extends de{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class mo extends de{constructor(e,t,i){super(),this.attributes=null,this.name=e,this.type=t,this.value=i}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}}class Zn extends de{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class fr extends de{constructor(e,t,i,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=i,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}var _n,Qn,w,b;(n=>{n.increment="++",n.decrement="--"})(_n||(_n={})),(n=>{n.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return n[t]}})(_n||(_n={}));class Zc extends de{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}}(n=>{n.assign="=",n.addAssign="+=",n.subtractAssin="-=",n.multiplyAssign="*=",n.divideAssign="/=",n.moduloAssign="%=",n.andAssign="&=",n.orAssign="|=",n.xorAssign="^=",n.shiftLeftAssign="<<=",n.shiftRightAssign=">>="})(Qn||(Qn={})),(n=>{n.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(Qn||(Qn={}));class Qc extends de{constructor(e,t,i){super(),this.operator=e,this.variable=t,this.value=i}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}}class go extends de{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return qc.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class Jc extends de{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}search(e){var t;this.searchBlock(this.body,e),(t=this.continuing)===null||t===void 0||t.search(e)}}class Gc extends de{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}search(e){e(this);for(const t of this.cases)t.search(e)}}class eu extends de{constructor(e,t,i,r){super(),this.condition=e,this.body=t,this.elseif=i,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}}class tu extends de{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}}class Zy extends de{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class Qy extends de{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class nu extends de{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class _o extends de{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class Jy extends de{constructor(){super()}get astNodeType(){return"discard"}}class iu extends de{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class ru extends de{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class k extends de{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let i=1;i<e.length;++i){const r=k._priority.get(t.name);k._priority.get(e[i].name)<r&&(t=e[i])}return t.name==="x32"?k.i32:t}getTypeName(){return this.name}}k.x32=new k("x32"),k.f32=new k("f32"),k.i32=new k("i32"),k.u32=new k("u32"),k.f16=new k("f16"),k.bool=new k("bool"),k.void=new k("void"),k._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class su extends k{constructor(e){super(e)}}class Ct extends k{constructor(e,t,i,r){super(e),this.members=t,this.startLine=i,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(const t of this.members)e(t)}}class T extends k{constructor(e,t,i){super(e),this.format=t,this.access=i}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}}T.vec2f=new T("vec2",k.f32,null),T.vec3f=new T("vec3",k.f32,null),T.vec4f=new T("vec4",k.f32,null),T.vec2i=new T("vec2",k.i32,null),T.vec3i=new T("vec3",k.i32,null),T.vec4i=new T("vec4",k.i32,null),T.vec2u=new T("vec2",k.u32,null),T.vec3u=new T("vec3",k.u32,null),T.vec4u=new T("vec4",k.u32,null),T.vec2h=new T("vec2",k.f16,null),T.vec3h=new T("vec3",k.f16,null),T.vec4h=new T("vec4",k.f16,null),T.vec2b=new T("vec2",k.bool,null),T.vec3b=new T("vec3",k.bool,null),T.vec4b=new T("vec4",k.bool,null),T.mat2x2f=new T("mat2x2",k.f32,null),T.mat2x3f=new T("mat2x3",k.f32,null),T.mat2x4f=new T("mat2x4",k.f32,null),T.mat3x2f=new T("mat3x2",k.f32,null),T.mat3x3f=new T("mat3x3",k.f32,null),T.mat3x4f=new T("mat3x4",k.f32,null),T.mat4x2f=new T("mat4x2",k.f32,null),T.mat4x3f=new T("mat4x3",k.f32,null),T.mat4x4f=new T("mat4x4",k.f32,null),T.mat2x2h=new T("mat2x2",k.f16,null),T.mat2x3h=new T("mat2x3",k.f16,null),T.mat2x4h=new T("mat2x4",k.f16,null),T.mat3x2h=new T("mat3x2",k.f16,null),T.mat3x3h=new T("mat3x3",k.f16,null),T.mat3x4h=new T("mat3x4",k.f16,null),T.mat4x2h=new T("mat4x2",k.f16,null),T.mat4x3h=new T("mat4x3",k.f16,null),T.mat4x4h=new T("mat4x4",k.f16,null),T.mat2x2i=new T("mat2x2",k.i32,null),T.mat2x3i=new T("mat2x3",k.i32,null),T.mat2x4i=new T("mat2x4",k.i32,null),T.mat3x2i=new T("mat3x2",k.i32,null),T.mat3x3i=new T("mat3x3",k.i32,null),T.mat3x4i=new T("mat3x4",k.i32,null),T.mat4x2i=new T("mat4x2",k.i32,null),T.mat4x3i=new T("mat4x3",k.i32,null),T.mat4x4i=new T("mat4x4",k.i32,null),T.mat2x2u=new T("mat2x2",k.u32,null),T.mat2x3u=new T("mat2x3",k.u32,null),T.mat2x4u=new T("mat2x4",k.u32,null),T.mat3x2u=new T("mat3x2",k.u32,null),T.mat3x3u=new T("mat3x3",k.u32,null),T.mat3x4u=new T("mat3x4",k.u32,null),T.mat4x2u=new T("mat4x2",k.u32,null),T.mat4x3u=new T("mat4x3",k.u32,null),T.mat4x4u=new T("mat4x4",k.u32,null);class hr extends k{constructor(e,t,i,r){super(e),this.storage=t,this.type=i,this.access=r}get astNodeType(){return"pointer"}}class Jn extends k{constructor(e,t,i,r){super(e),this.attributes=t,this.format=i,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}}class Gn extends k{constructor(e,t,i){super(e),this.format=t,this.access=i}get astNodeType(){return"sampler"}}class at extends et{constructor(){super(),this.postfix=null}}class Kt extends at{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class gt extends at{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(const t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}}class xo extends at{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return qc.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(const t of this.args)t.search(e);e(this)}}class Qe extends at{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,t){return e.evalExpression(this,e.context)}}class ou extends at{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){const i=e.evalExpression(this.initializer,e.context);return i!==null&&this.postfix?i.getSubData(e,this.postfix,e.context):i}return null}search(e){this.initializer.search(e)}}class Ae extends at{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof v}get isVector(){return this.value instanceof g||this.value instanceof j}get scalarValue(){return this.value instanceof v?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof g||this.value instanceof j?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}}class au extends at{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class xn extends at{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class lu extends at{constructor(){super()}}class be extends lu{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}}class lt extends lu{constructor(e,t,i){super(),this.operator=e,this.left=t,this.right=i}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?k.f32:e.name==="u32"||t.name==="u32"?k.u32:k.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class cu extends et{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class dr extends at{constructor(){super()}get astNodeType(){return"default"}}class uu extends cu{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class fu extends cu{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class hu extends et{constructor(e,t,i){super(),this.name=e,this.type=t,this.attributes=i}get astNodeType(){return"argument"}}class Gy extends et{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}}class du extends et{constructor(e,t,i){super(),this.name=e,this.type=t,this.attributes=i}get astNodeType(){return"member"}}class pu extends et{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class tt{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=tt._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,i,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,i){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}}tt._id=0;class yo extends tt{constructor(){super(new Ge("void",null),null)}toString(){return"void"}}yo.void=new yo;class yn extends tt{constructor(e){super(new uo("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,t,i,r){this.reference.setDataValue(e,t,i,r)}getSubData(e,t,i){return t?this.reference.getSubData(e,t,i):this}toString(){return`&${this.reference.toString()}`}}class v extends tt{constructor(e,t,i=null){super(t,i),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new v(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new v(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new v(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,i,r){if(i)return void console.error("SetDataValue: Scalar data does not support postfix",i);if(!(t instanceof v))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,i){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}}function e0(n,e,t){const i=e.length;return i===2?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec2i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec2u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):i===3?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec3i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec3u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):i===4?t==="f32"?new g(new Float32Array(e),n.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new g(new Int32Array(e),n.getTypeInfo("vec4i")):t==="u32"?new g(new Uint32Array(e),n.getTypeInfo("vec4u")):t==="f16"?new g(new Float32Array(e),n.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}class g extends tt{constructor(e,t,i=null){if(super(t,i),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{const r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new g(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new g(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new g(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,i,r){i instanceof Kt?console.error("TODO: Set vector postfix"):t instanceof g?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,i){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof jt)r=this.typeInfo.format||r;else{const o=this.typeInfo.name;o==="vec2f"||o==="vec3f"||o==="vec4f"?r=e.getTypeInfo("f32"):o==="vec2i"||o==="vec3i"||o==="vec4i"?r=e.getTypeInfo("i32"):o==="vec2b"||o==="vec3b"||o==="vec4b"?r=e.getTypeInfo("bool"):o==="vec2u"||o==="vec3u"||o==="vec4u"?r=e.getTypeInfo("u32"):o==="vec2h"||o==="vec3h"||o==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${o}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof xn){const o=t.index;let a=-1;if(o instanceof Ae){if(!(o.value instanceof v))return console.error(`GetSubData: Invalid array index ${o.value}`),null;a=o.value.value}else{const l=e.evalExpression(o,i);if(!(l instanceof v))return console.error("GetSubData: Unknown index type",o),null;a=l.value}if(a<0||a>=s.data.length)return console.error("GetSubData: Index out of range",a),null;if(s.data instanceof Float32Array){const l=new Float32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}if(s.data instanceof Int32Array){const l=new Int32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}if(s.data instanceof Uint32Array){const l=new Uint32Array(s.data.buffer,s.data.byteOffset+4*a,1);return new v(l,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof Kt))return console.error("GetSubData: Unknown postfix",t),null;{const o=t.value.toLowerCase();if(o.length===1){let l=0;if(o==="x"||o==="r")l=0;else if(o==="y"||o==="g")l=1;else if(o==="z"||o==="b")l=2;else{if(o!=="w"&&o!=="a")return console.error(`GetSubData: Unknown member ${o}`),null;l=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new v(c,r,this)}}const a=[];for(const l of o)l==="x"||l==="r"?a.push(this.data[0]):l==="y"||l==="g"?a.push(this.data[1]):l==="z"||l==="b"?a.push(this.data[2]):l==="w"||l==="a"?a.push(this.data[3]):console.error(`GetDataValue: Unknown member ${l}`);s=e0(e,a,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class j extends tt{constructor(e,t,i=null){super(t,i),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new j(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,i,r){i instanceof Kt?console.error("TODO: Set matrix postfix"):t instanceof j?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,i){if(t===null)return this;const r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof jt)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof xn){const s=t.index;let o=-1;if(s instanceof Ae){if(!(s.value instanceof v))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;o=s.value.value}else{const c=e.evalExpression(s,i);if(!(c instanceof v))return console.error("GetDataValue: Unknown index type",s),null;o=c.value}if(o<0||o>=this.data.length)return console.error("GetDataValue: Index out of range",o),null;const a=r.endsWith("h")?"h":"f";let l;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+2*o*4,2),e.getTypeInfo(`vec2${a}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+3*o*4,3),e.getTypeInfo(`vec3${a}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;l=new g(new Float32Array(this.data.buffer,this.data.byteOffset+4*o*4,4),e.getTypeInfo(`vec4${a}`))}return t.postfix?l.getSubData(e,t.postfix,i):l}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class ye extends tt{constructor(e,t,i=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=i}clone(){const e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new ye(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,i,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,o=this.typeInfo;for(;i;){if(i instanceof xn)if(o instanceof Mt){const a=i.index;if(a instanceof Ae){if(!(a.value instanceof v))return void console.error(`SetDataValue: Invalid index type ${a.value}`);s+=a.value.value*o.stride}else{const l=e.evalExpression(a,r);if(!(l instanceof v))return void console.error("SetDataValue: Unknown index type",a);s+=l.value*o.stride}o=o.format}else console.error(`SetDataValue: Type ${o.getTypeName()} is not an array`);else{if(!(i instanceof Kt))return void console.error("SetDataValue: Unknown postfix type",i);{const a=i.value;if(o instanceof Ft){let l=!1;for(const c of o.members)if(c.name===a){s+=c.offset,o=c.type,l=!0;break}if(!l)return void console.error(`SetDataValue: Member ${a} not found`)}else if(o instanceof Ge){const l=o.getTypeName();let c=0;if(a==="x"||a==="r")c=0;else if(a==="y"||a==="g")c=1;else if(a==="z"||a==="b")c=2;else{if(a!=="w"&&a!=="a")return void console.error(`SetDataValue: Unknown member ${a}`);c=3}if(!(t instanceof v))return void console.error("SetDataValue: Invalid value",t);const u=t.value;return l==="vec2f"?void(new Float32Array(this.buffer,s,2)[c]=u):l==="vec3f"?void(new Float32Array(this.buffer,s,3)[c]=u):l==="vec4f"?void(new Float32Array(this.buffer,s,4)[c]=u):l==="vec2i"?void(new Int32Array(this.buffer,s,2)[c]=u):l==="vec3i"?void(new Int32Array(this.buffer,s,3)[c]=u):l==="vec4i"?void(new Int32Array(this.buffer,s,4)[c]=u):l==="vec2u"?void(new Uint32Array(this.buffer,s,2)[c]=u):l==="vec3u"?void(new Uint32Array(this.buffer,s,3)[c]=u):l==="vec4u"?void(new Uint32Array(this.buffer,s,4)[c]=u):void console.error(`SetDataValue: Type ${l} is not a struct`)}}}i=i.postfix}this.setData(e,t,o,s,r)}setData(e,t,i,r,s){const o=i.getTypeName();if(o!=="f32"&&o!=="f16")if(o!=="i32"&&o!=="atomic<i32>"&&o!=="x32")if(o!=="u32"&&o!=="atomic<u32>")if(o!=="bool"){if(o==="vec2f"||o==="vec2h"){const a=new Float32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3f"||o==="vec3h"){const a=new Float32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4f"||o==="vec4h"){const a=new Float32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2i"){const a=new Int32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3i"){const a=new Int32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4i"){const a=new Int32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2u"){const a=new Uint32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3u"){const a=new Uint32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4u"){const a=new Uint32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="vec2b"){const a=new Uint32Array(this.buffer,r,2);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1]):(a[0]=t[0],a[1]=t[1]))}if(o==="vec3b"){const a=new Uint32Array(this.buffer,r,3);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2]):(a[0]=t[0],a[1]=t[1],a[2]=t[2]))}if(o==="vec4b"){const a=new Uint32Array(this.buffer,r,4);return void(t instanceof g?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="mat2x2f"||o==="mat2x2h"){const a=new Float32Array(this.buffer,r,4);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3]))}if(o==="mat2x3f"||o==="mat2x3h"){const a=new Float32Array(this.buffer,r,6);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5]))}if(o==="mat2x4f"||o==="mat2x4h"){const a=new Float32Array(this.buffer,r,8);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7]))}if(o==="mat3x2f"||o==="mat3x2h"){const a=new Float32Array(this.buffer,r,6);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5]))}if(o==="mat3x3f"||o==="mat3x3h"){const a=new Float32Array(this.buffer,r,9);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8]))}if(o==="mat3x4f"||o==="mat3x4h"){const a=new Float32Array(this.buffer,r,12);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11]))}if(o==="mat4x2f"||o==="mat4x2h"){const a=new Float32Array(this.buffer,r,8);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7]))}if(o==="mat4x3f"||o==="mat4x3h"){const a=new Float32Array(this.buffer,r,12);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11]))}if(o==="mat4x4f"||o==="mat4x4h"){const a=new Float32Array(this.buffer,r,16);return void(t instanceof j?(a[0]=t.data[0],a[1]=t.data[1],a[2]=t.data[2],a[3]=t.data[3],a[4]=t.data[4],a[5]=t.data[5],a[6]=t.data[6],a[7]=t.data[7],a[8]=t.data[8],a[9]=t.data[9],a[10]=t.data[10],a[11]=t.data[11],a[12]=t.data[12],a[13]=t.data[13],a[14]=t.data[14],a[15]=t.data[15]):(a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11],a[12]=t[12],a[13]=t[13],a[14]=t[14],a[15]=t[15]))}if(t instanceof ye){if(i===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",o,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${o}`)}else t instanceof v&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof v&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,i){var r,s,o;if(t===null)return this;let a=this.offset,l=this.typeInfo;for(;t;){if(t instanceof xn){const u=t.index,f=u instanceof at?e.evalExpression(u,i):u;let h=0;if(f instanceof v?h=f.value:typeof f=="number"?h=f:console.error("GetDataValue: Invalid index type",u),l instanceof Mt)a+=h*l.stride,l=l.format;else{const d=l.getTypeName();d==="mat4x4"||d==="mat4x4f"||d==="mat4x4h"?(a+=16*h,l=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${l.getTypeName()} is not an array`)}}else{if(!(t instanceof Kt))return console.error("GetDataValue: Unknown postfix type",t),null;{const u=t.value;if(l instanceof Ft){let f=!1;for(const h of l.members)if(h.name===u){a+=h.offset,l=h.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${u} not found`),null}else if(l instanceof Ge){const f=l.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(u.length>0&&u.length<5){let h="f";const d=[];for(let _=0;_<u.length;++_){const I=u[_].toLowerCase();let P=0;if(I==="x"||I==="r")P=0;else if(I==="y"||I==="g")P=1;else if(I==="z"||I==="b")P=2;else{if(I!=="w"&&I!=="a")return console.error(`Unknown member ${u}`),null;P=3}if(u.length===1){if(f.endsWith("f"))return this.buffer.byteLength<a+4*P+4?(console.log("Insufficient buffer data"),null):new v(new Float32Array(this.buffer,a+4*P,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new v(new Float32Array(this.buffer,a+4*P,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new v(new Int32Array(this.buffer,a+4*P,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new v(new Int32Array(this.buffer,a+4*P,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new v(new Uint32Array(this.buffer,a+4*P,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")d.push(new Float32Array(this.buffer,a,2)[P]);else if(f==="vec3f"){if(a+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;const A=new Float32Array(this.buffer,a,3);d.push(A[P])}else if(f==="vec4f")d.push(new Float32Array(this.buffer,a,4)[P]);else if(f==="vec2i")h="i",d.push(new Int32Array(this.buffer,a,2)[P]);else if(f==="vec3i")h="i",d.push(new Int32Array(this.buffer,a,3)[P]);else if(f==="vec4i")h="i",d.push(new Int32Array(this.buffer,a,4)[P]);else if(f==="vec2u"){h="u";const A=new Uint32Array(this.buffer,a,2);d.push(A[P])}else f==="vec3u"?(h="u",d.push(new Uint32Array(this.buffer,a,3)[P])):f==="vec4u"&&(h="u",d.push(new Uint32Array(this.buffer,a,4)[P]))}return d.length===2?l=e.getTypeInfo(`vec2${h}`):d.length===3?l=e.getTypeInfo(`vec3${h}`):d.length===4?l=e.getTypeInfo(`vec4${h}`):console.error(`GetDataValue: Invalid vector length ${d.length}`),new g(d,l,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}const c=l.getTypeName();return c==="f32"?new v(new Float32Array(this.buffer,a,1),l,this):c==="i32"?new v(new Int32Array(this.buffer,a,1),l,this):c==="u32"?new v(new Uint32Array(this.buffer,a,1),l,this):c==="vec2f"?new g(new Float32Array(this.buffer,a,2),l,this):c==="vec3f"?new g(new Float32Array(this.buffer,a,3),l,this):c==="vec4f"?new g(new Float32Array(this.buffer,a,4),l,this):c==="vec2i"?new g(new Int32Array(this.buffer,a,2),l,this):c==="vec3i"?new g(new Int32Array(this.buffer,a,3),l,this):c==="vec4i"?new g(new Int32Array(this.buffer,a,4),l,this):c==="vec2u"?new g(new Uint32Array(this.buffer,a,2),l,this):c==="vec3u"?new g(new Uint32Array(this.buffer,a,3),l,this):c==="vec4u"?new g(new Uint32Array(this.buffer,a,4),l,this):l instanceof jt&&l.name==="atomic"?((r=l.format)===null||r===void 0?void 0:r.name)==="u32"?new v(new Uint32Array(this.buffer,a,1)[0],l.format,this):((s=l.format)===null||s===void 0?void 0:s.name)==="i32"?new v(new Int32Array(this.buffer,a,1)[0],l.format,this):(console.error(`GetDataValue: Invalid atomic format ${(o=l.format)===null||o===void 0?void 0:o.name}`),null):new ye(this.buffer,l,a,this)}toString(){let e="";if(this.typeInfo instanceof Mt)if(this.typeInfo.format.name==="f32"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="i32"){const t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="u32"){const t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let i=1;i<t.length;++i)e+=`, ${t[i]}`}else if(this.typeInfo.format.name==="vec2f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let i=1;i<t.length/2;++i)e+=`, [${t[2*i]}, ${t[2*i+1]}]`}else if(this.typeInfo.format.name==="vec3f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let i=4;i<t.length;i+=4)e+=`, [${t[i]}, ${t[i+1]}, ${t[i+2]}]`}else if(this.typeInfo.format.name==="vec4f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let i=4;i<t.length;i+=4)e+=`, [${t[i]}, ${t[i+1]}, ${t[i+2]}, ${t[i+3]}]`}else e="[...]";else this.typeInfo instanceof Ft?e+="{...}":e="[...]";return e}}class It extends tt{constructor(e,t,i,r){super(t,null),this.data=e,this.descriptor=i,this.view=r}clone(){return new It(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>0?(e=i[0])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.width)!==null&&t!==void 0?t:0}get height(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>1?(e=i[1])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;const i=this.descriptor.size;return i instanceof Array&&i.length>2?(e=i[2])!==null&&e!==void 0?e:0:i instanceof Object&&(t=i.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];const t=[this.width,this.height,this.depthOrArrayLayers];for(let i=0;i<t.length;++i)t[i]=Math.max(1,t[i]>>e);return t}get texelByteSize(){const e=this.format,t=ho[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=ho[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=ho[e],i=this.width;if(!e||i<=0||!t)return-1;const r=this.height,s=this.depthOrArrayLayers,o=this.dimension;return i/t.blockWidth*(o==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,i=0,r=0){const s=this.texelByteSize,o=this.bytesPerRow,a=this.height,l=this.data[r];return jy(new Uint8Array(l),e,t,i,r,a,o,s,this.format)}setPixel(e,t,i,r,s){const o=this.texelByteSize,a=this.bytesPerRow,l=this.height,c=this.data[r];(function(u,f,h,d,_,I,P,A,O,E){const y=d*(P>>=_)*(I>>=_)+h*P+f*A;switch(O){case"r8unorm":return void oe(u,y,"8unorm",1,E);case"r8snorm":return void oe(u,y,"8snorm",1,E);case"r8uint":return void oe(u,y,"8uint",1,E);case"r8sint":return void oe(u,y,"8sint",1,E);case"rg8unorm":return void oe(u,y,"8unorm",2,E);case"rg8snorm":return void oe(u,y,"8snorm",2,E);case"rg8uint":return void oe(u,y,"8uint",2,E);case"rg8sint":return void oe(u,y,"8sint",2,E);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void oe(u,y,"8unorm",4,E);case"rgba8snorm":return void oe(u,y,"8snorm",4,E);case"rgba8uint":return void oe(u,y,"8uint",4,E);case"rgba8sint":return void oe(u,y,"8sint",4,E);case"r16uint":return void oe(u,y,"16uint",1,E);case"r16sint":return void oe(u,y,"16sint",1,E);case"r16float":return void oe(u,y,"16float",1,E);case"rg16uint":return void oe(u,y,"16uint",2,E);case"rg16sint":return void oe(u,y,"16sint",2,E);case"rg16float":return void oe(u,y,"16float",2,E);case"rgba16uint":return void oe(u,y,"16uint",4,E);case"rgba16sint":return void oe(u,y,"16sint",4,E);case"rgba16float":return void oe(u,y,"16float",4,E);case"r32uint":return void oe(u,y,"32uint",1,E);case"r32sint":return void oe(u,y,"32sint",1,E);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void oe(u,y,"32float",1,E);case"rg32uint":return void oe(u,y,"32uint",2,E);case"rg32sint":return void oe(u,y,"32sint",2,E);case"rg32float":return void oe(u,y,"32float",2,E);case"rgba32uint":return void oe(u,y,"32uint",4,E);case"rgba32sint":return void oe(u,y,"32sint",4,E);case"rgba32float":return void oe(u,y,"32float",4,E);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,i,r,l,a,o,this.format,s)}}(n=>{n[n.token=0]="token",n[n.keyword=1]="keyword",n[n.reserved=2]="reserved"})(b||(b={}));class S{constructor(e,t,i){this.name=e,this.type=t,this.rule=i}toString(){return this.name}}class p{}w=p,p.none=new S("",b.reserved,""),p.eof=new S("EOF",b.token,""),p.reserved={asm:new S("asm",b.reserved,"asm"),bf16:new S("bf16",b.reserved,"bf16"),do:new S("do",b.reserved,"do"),enum:new S("enum",b.reserved,"enum"),f16:new S("f16",b.reserved,"f16"),f64:new S("f64",b.reserved,"f64"),handle:new S("handle",b.reserved,"handle"),i8:new S("i8",b.reserved,"i8"),i16:new S("i16",b.reserved,"i16"),i64:new S("i64",b.reserved,"i64"),mat:new S("mat",b.reserved,"mat"),premerge:new S("premerge",b.reserved,"premerge"),regardless:new S("regardless",b.reserved,"regardless"),typedef:new S("typedef",b.reserved,"typedef"),u8:new S("u8",b.reserved,"u8"),u16:new S("u16",b.reserved,"u16"),u64:new S("u64",b.reserved,"u64"),unless:new S("unless",b.reserved,"unless"),using:new S("using",b.reserved,"using"),vec:new S("vec",b.reserved,"vec"),void:new S("void",b.reserved,"void")},p.keywords={array:new S("array",b.keyword,"array"),atomic:new S("atomic",b.keyword,"atomic"),bool:new S("bool",b.keyword,"bool"),f32:new S("f32",b.keyword,"f32"),i32:new S("i32",b.keyword,"i32"),mat2x2:new S("mat2x2",b.keyword,"mat2x2"),mat2x3:new S("mat2x3",b.keyword,"mat2x3"),mat2x4:new S("mat2x4",b.keyword,"mat2x4"),mat3x2:new S("mat3x2",b.keyword,"mat3x2"),mat3x3:new S("mat3x3",b.keyword,"mat3x3"),mat3x4:new S("mat3x4",b.keyword,"mat3x4"),mat4x2:new S("mat4x2",b.keyword,"mat4x2"),mat4x3:new S("mat4x3",b.keyword,"mat4x3"),mat4x4:new S("mat4x4",b.keyword,"mat4x4"),ptr:new S("ptr",b.keyword,"ptr"),sampler:new S("sampler",b.keyword,"sampler"),sampler_comparison:new S("sampler_comparison",b.keyword,"sampler_comparison"),struct:new S("struct",b.keyword,"struct"),texture_1d:new S("texture_1d",b.keyword,"texture_1d"),texture_2d:new S("texture_2d",b.keyword,"texture_2d"),texture_2d_array:new S("texture_2d_array",b.keyword,"texture_2d_array"),texture_3d:new S("texture_3d",b.keyword,"texture_3d"),texture_cube:new S("texture_cube",b.keyword,"texture_cube"),texture_cube_array:new S("texture_cube_array",b.keyword,"texture_cube_array"),texture_multisampled_2d:new S("texture_multisampled_2d",b.keyword,"texture_multisampled_2d"),texture_storage_1d:new S("texture_storage_1d",b.keyword,"texture_storage_1d"),texture_storage_2d:new S("texture_storage_2d",b.keyword,"texture_storage_2d"),texture_storage_2d_array:new S("texture_storage_2d_array",b.keyword,"texture_storage_2d_array"),texture_storage_3d:new S("texture_storage_3d",b.keyword,"texture_storage_3d"),texture_depth_2d:new S("texture_depth_2d",b.keyword,"texture_depth_2d"),texture_depth_2d_array:new S("texture_depth_2d_array",b.keyword,"texture_depth_2d_array"),texture_depth_cube:new S("texture_depth_cube",b.keyword,"texture_depth_cube"),texture_depth_cube_array:new S("texture_depth_cube_array",b.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new S("texture_depth_multisampled_2d",b.keyword,"texture_depth_multisampled_2d"),texture_external:new S("texture_external",b.keyword,"texture_external"),u32:new S("u32",b.keyword,"u32"),vec2:new S("vec2",b.keyword,"vec2"),vec3:new S("vec3",b.keyword,"vec3"),vec4:new S("vec4",b.keyword,"vec4"),bitcast:new S("bitcast",b.keyword,"bitcast"),block:new S("block",b.keyword,"block"),break:new S("break",b.keyword,"break"),case:new S("case",b.keyword,"case"),continue:new S("continue",b.keyword,"continue"),continuing:new S("continuing",b.keyword,"continuing"),default:new S("default",b.keyword,"default"),diagnostic:new S("diagnostic",b.keyword,"diagnostic"),discard:new S("discard",b.keyword,"discard"),else:new S("else",b.keyword,"else"),enable:new S("enable",b.keyword,"enable"),fallthrough:new S("fallthrough",b.keyword,"fallthrough"),false:new S("false",b.keyword,"false"),fn:new S("fn",b.keyword,"fn"),for:new S("for",b.keyword,"for"),function:new S("function",b.keyword,"function"),if:new S("if",b.keyword,"if"),let:new S("let",b.keyword,"let"),const:new S("const",b.keyword,"const"),loop:new S("loop",b.keyword,"loop"),while:new S("while",b.keyword,"while"),private:new S("private",b.keyword,"private"),read:new S("read",b.keyword,"read"),read_write:new S("read_write",b.keyword,"read_write"),return:new S("return",b.keyword,"return"),requires:new S("requires",b.keyword,"requires"),storage:new S("storage",b.keyword,"storage"),switch:new S("switch",b.keyword,"switch"),true:new S("true",b.keyword,"true"),alias:new S("alias",b.keyword,"alias"),type:new S("type",b.keyword,"type"),uniform:new S("uniform",b.keyword,"uniform"),var:new S("var",b.keyword,"var"),override:new S("override",b.keyword,"override"),workgroup:new S("workgroup",b.keyword,"workgroup"),write:new S("write",b.keyword,"write"),r8unorm:new S("r8unorm",b.keyword,"r8unorm"),r8snorm:new S("r8snorm",b.keyword,"r8snorm"),r8uint:new S("r8uint",b.keyword,"r8uint"),r8sint:new S("r8sint",b.keyword,"r8sint"),r16uint:new S("r16uint",b.keyword,"r16uint"),r16sint:new S("r16sint",b.keyword,"r16sint"),r16float:new S("r16float",b.keyword,"r16float"),rg8unorm:new S("rg8unorm",b.keyword,"rg8unorm"),rg8snorm:new S("rg8snorm",b.keyword,"rg8snorm"),rg8uint:new S("rg8uint",b.keyword,"rg8uint"),rg8sint:new S("rg8sint",b.keyword,"rg8sint"),r32uint:new S("r32uint",b.keyword,"r32uint"),r32sint:new S("r32sint",b.keyword,"r32sint"),r32float:new S("r32float",b.keyword,"r32float"),rg16uint:new S("rg16uint",b.keyword,"rg16uint"),rg16sint:new S("rg16sint",b.keyword,"rg16sint"),rg16float:new S("rg16float",b.keyword,"rg16float"),rgba8unorm:new S("rgba8unorm",b.keyword,"rgba8unorm"),rgba8unorm_srgb:new S("rgba8unorm_srgb",b.keyword,"rgba8unorm_srgb"),rgba8snorm:new S("rgba8snorm",b.keyword,"rgba8snorm"),rgba8uint:new S("rgba8uint",b.keyword,"rgba8uint"),rgba8sint:new S("rgba8sint",b.keyword,"rgba8sint"),bgra8unorm:new S("bgra8unorm",b.keyword,"bgra8unorm"),bgra8unorm_srgb:new S("bgra8unorm_srgb",b.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new S("rgb10a2unorm",b.keyword,"rgb10a2unorm"),rg11b10float:new S("rg11b10float",b.keyword,"rg11b10float"),rg32uint:new S("rg32uint",b.keyword,"rg32uint"),rg32sint:new S("rg32sint",b.keyword,"rg32sint"),rg32float:new S("rg32float",b.keyword,"rg32float"),rgba16uint:new S("rgba16uint",b.keyword,"rgba16uint"),rgba16sint:new S("rgba16sint",b.keyword,"rgba16sint"),rgba16float:new S("rgba16float",b.keyword,"rgba16float"),rgba32uint:new S("rgba32uint",b.keyword,"rgba32uint"),rgba32sint:new S("rgba32sint",b.keyword,"rgba32sint"),rgba32float:new S("rgba32float",b.keyword,"rgba32float"),static_assert:new S("static_assert",b.keyword,"static_assert")},p.tokens={decimal_float_literal:new S("decimal_float_literal",b.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new S("hex_float_literal",b.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new S("int_literal",b.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new S("uint_literal",b.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new S("name",b.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new S("ident",b.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new S("and",b.token,"&"),and_and:new S("and_and",b.token,"&&"),arrow:new S("arrow ",b.token,"->"),attr:new S("attr",b.token,"@"),forward_slash:new S("forward_slash",b.token,"/"),bang:new S("bang",b.token,"!"),bracket_left:new S("bracket_left",b.token,"["),bracket_right:new S("bracket_right",b.token,"]"),brace_left:new S("brace_left",b.token,"{"),brace_right:new S("brace_right",b.token,"}"),colon:new S("colon",b.token,":"),comma:new S("comma",b.token,","),equal:new S("equal",b.token,"="),equal_equal:new S("equal_equal",b.token,"=="),not_equal:new S("not_equal",b.token,"!="),greater_than:new S("greater_than",b.token,">"),greater_than_equal:new S("greater_than_equal",b.token,">="),shift_right:new S("shift_right",b.token,">>"),less_than:new S("less_than",b.token,"<"),less_than_equal:new S("less_than_equal",b.token,"<="),shift_left:new S("shift_left",b.token,"<<"),modulo:new S("modulo",b.token,"%"),minus:new S("minus",b.token,"-"),minus_minus:new S("minus_minus",b.token,"--"),period:new S("period",b.token,"."),plus:new S("plus",b.token,"+"),plus_plus:new S("plus_plus",b.token,"++"),or:new S("or",b.token,"|"),or_or:new S("or_or",b.token,"||"),paren_left:new S("paren_left",b.token,"("),paren_right:new S("paren_right",b.token,")"),semicolon:new S("semicolon",b.token,";"),star:new S("star",b.token,"*"),tilde:new S("tilde",b.token,"~"),underscore:new S("underscore",b.token,"_"),xor:new S("xor",b.token,"^"),plus_equal:new S("plus_equal",b.token,"+="),minus_equal:new S("minus_equal",b.token,"-="),times_equal:new S("times_equal",b.token,"*="),division_equal:new S("division_equal",b.token,"/="),modulo_equal:new S("modulo_equal",b.token,"%="),and_equal:new S("and_equal",b.token,"&="),or_equal:new S("or_equal",b.token,"|="),xor_equal:new S("xor_equal",b.token,"^="),shift_right_equal:new S("shift_right_equal",b.token,">>="),shift_left_equal:new S("shift_left_equal",b.token,"<<=")},p.simpleTokens={"@":w.tokens.attr,"{":w.tokens.brace_left,"}":w.tokens.brace_right,":":w.tokens.colon,",":w.tokens.comma,"(":w.tokens.paren_left,")":w.tokens.paren_right,";":w.tokens.semicolon},p.literalTokens={"&":w.tokens.and,"&&":w.tokens.and_and,"->":w.tokens.arrow,"/":w.tokens.forward_slash,"!":w.tokens.bang,"[":w.tokens.bracket_left,"]":w.tokens.bracket_right,"=":w.tokens.equal,"==":w.tokens.equal_equal,"!=":w.tokens.not_equal,">":w.tokens.greater_than,">=":w.tokens.greater_than_equal,">>":w.tokens.shift_right,"<":w.tokens.less_than,"<=":w.tokens.less_than_equal,"<<":w.tokens.shift_left,"%":w.tokens.modulo,"-":w.tokens.minus,"--":w.tokens.minus_minus,".":w.tokens.period,"+":w.tokens.plus,"++":w.tokens.plus_plus,"|":w.tokens.or,"||":w.tokens.or_or,"*":w.tokens.star,"~":w.tokens.tilde,_:w.tokens.underscore,"^":w.tokens.xor,"+=":w.tokens.plus_equal,"-=":w.tokens.minus_equal,"*=":w.tokens.times_equal,"/=":w.tokens.division_equal,"%=":w.tokens.modulo_equal,"&=":w.tokens.and_equal,"|=":w.tokens.or_equal,"^=":w.tokens.xor_equal,">>=":w.tokens.shift_right_equal,"<<=":w.tokens.shift_left_equal},p.regexTokens={decimal_float_literal:w.tokens.decimal_float_literal,hex_float_literal:w.tokens.hex_float_literal,int_literal:w.tokens.int_literal,uint_literal:w.tokens.uint_literal,ident:w.tokens.ident},p.storage_class=[w.keywords.function,w.keywords.private,w.keywords.workgroup,w.keywords.uniform,w.keywords.storage],p.access_mode=[w.keywords.read,w.keywords.write,w.keywords.read_write],p.sampler_type=[w.keywords.sampler,w.keywords.sampler_comparison],p.sampled_texture_type=[w.keywords.texture_1d,w.keywords.texture_2d,w.keywords.texture_2d_array,w.keywords.texture_3d,w.keywords.texture_cube,w.keywords.texture_cube_array],p.multisampled_texture_type=[w.keywords.texture_multisampled_2d],p.storage_texture_type=[w.keywords.texture_storage_1d,w.keywords.texture_storage_2d,w.keywords.texture_storage_2d_array,w.keywords.texture_storage_3d],p.depth_texture_type=[w.keywords.texture_depth_2d,w.keywords.texture_depth_2d_array,w.keywords.texture_depth_cube,w.keywords.texture_depth_cube_array,w.keywords.texture_depth_multisampled_2d],p.texture_external_type=[w.keywords.texture_external],p.any_texture_type=[...w.sampled_texture_type,...w.multisampled_texture_type,...w.storage_texture_type,...w.depth_texture_type,...w.texture_external_type],p.texel_format=[w.keywords.r8unorm,w.keywords.r8snorm,w.keywords.r8uint,w.keywords.r8sint,w.keywords.r16uint,w.keywords.r16sint,w.keywords.r16float,w.keywords.rg8unorm,w.keywords.rg8snorm,w.keywords.rg8uint,w.keywords.rg8sint,w.keywords.r32uint,w.keywords.r32sint,w.keywords.r32float,w.keywords.rg16uint,w.keywords.rg16sint,w.keywords.rg16float,w.keywords.rgba8unorm,w.keywords.rgba8unorm_srgb,w.keywords.rgba8snorm,w.keywords.rgba8uint,w.keywords.rgba8sint,w.keywords.bgra8unorm,w.keywords.bgra8unorm_srgb,w.keywords.rgb10a2unorm,w.keywords.rg11b10float,w.keywords.rg32uint,w.keywords.rg32sint,w.keywords.rg32float,w.keywords.rgba16uint,w.keywords.rgba16sint,w.keywords.rgba16float,w.keywords.rgba32uint,w.keywords.rgba32sint,w.keywords.rgba32float],p.const_literal=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.keywords.true,w.keywords.false],p.literal_or_ident=[w.tokens.ident,w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.tokens.name],p.element_count_expression=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.ident],p.template_types=[w.keywords.vec2,w.keywords.vec3,w.keywords.vec4,w.keywords.mat2x2,w.keywords.mat2x3,w.keywords.mat2x4,w.keywords.mat3x2,w.keywords.mat3x3,w.keywords.mat3x4,w.keywords.mat4x2,w.keywords.mat4x3,w.keywords.mat4x4,w.keywords.atomic,w.keywords.bitcast,...w.any_texture_type],p.attribute_name=[w.tokens.ident,w.keywords.block,w.keywords.diagnostic],p.assignment_operators=[w.tokens.equal,w.tokens.plus_equal,w.tokens.minus_equal,w.tokens.times_equal,w.tokens.division_equal,w.tokens.modulo_equal,w.tokens.and_equal,w.tokens.or_equal,w.tokens.xor_equal,w.tokens.shift_right_equal,w.tokens.shift_left_equal],p.increment_operators=[w.tokens.plus_plus,w.tokens.minus_minus];class mu{constructor(e,t,i,r,s){this.type=e,this.lexeme=t,this.line=i,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return p.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==p.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class t0{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new mu(p.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
93
93
  `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
94
94
  `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let o=1;for(;o>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
95
95
  `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),o--,o==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),o++)}return!0}}const t=p.simpleTokens[e];if(t)return this._addToken(t),!0;let i=p.none;const r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let o=this._peekAhead();for(;this._isAlphaNumeric(o);)e+=this._advance(),o=this._peekAhead()}if(r){const o=p.keywords[e];if(o)return this._addToken(o),!0}if(r||s)return this._addToken(p.tokens.ident),!0;for(;;){let o=this._findType(e);const a=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(a=="=")return this._current++,e+=a,this._addToken(p.tokens.minus_equal),!0;if(a=="-")return this._current++,e+=a,this._addToken(p.tokens.minus_minus),!0;const l=this._tokens.length-1;if((p.literal_or_ident.indexOf(this._tokens[l].type)!=-1||this._tokens[l].type==p.tokens.paren_right)&&a!=">")return this._addToken(o),!0}if(e==">"&&(a==">"||a=="=")){let l=!1,c=this._tokens.length-1;for(let u=0;u<5&&c>=0&&p.assignment_operators.indexOf(this._tokens[c].type)===-1;++u,--c)if(this._tokens[c].type===p.tokens.less_than){c>0&&this._tokens[c-1].isArrayOrTemplateType()&&(l=!0);break}if(l)return this._addToken(o),!0}if(o===p.none){let l=e,c=0;const u=2;for(let f=0;f<u;++f)if(l+=this._peekAhead(f),o=this._findType(l),o!==p.none){c=f;break}if(o===p.none)return i!==p.none&&(this._current--,this._addToken(i),!0);e=l,this._current+=c+1}if(i=o,this._isAtEnd())break;e+=this._advance()}return i!==p.none&&(this._addToken(i),!0)}_findType(e){for(const i in p.regexTokens){const r=p.regexTokens[i];if(this._match(e,r.rule))return r}return p.literalTokens[e]||p.none}_match(e,t){const i=t.exec(e);return i&&i.index==0&&i[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
96
- `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){const t=this._source.substring(this._start,this._current);this._tokens.push(new bu(e,t,this._line,this._start,this._current))}}function z(n){return Array.isArray(n)||(n==null?void 0:n.buffer)instanceof ArrayBuffer}const pr=new Float32Array(1),l0=new Uint32Array(pr.buffer),c0=new Uint32Array(pr.buffer),mr=new Int32Array(1),u0=new Float32Array(mr.buffer),f0=new Uint32Array(mr.buffer),gr=new Uint32Array(1),h0=new Float32Array(gr.buffer),d0=new Int32Array(gr.buffer);function Su(n,e,t){if(e===t)return n;if(e==="f32"){if(t==="i32"||t==="x32")return pr[0]=n,l0[0];if(t==="u32")return pr[0]=n,c0[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return mr[0]=n,u0[0];if(t==="u32")return mr[0]=n,f0[0]}else if(e==="u32"){if(t==="f32")return gr[0]=n,h0[0];if(t==="i32"||t==="x32")return gr[0]=n,d0[0]}return console.error(`Unsupported cast from ${e} to ${t}`),n}class p0{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class _r{constructor(e,t){this.align=e,this.size=t}}class _t{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Zy,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(const t of e)t instanceof jn&&this._functions.set(t.name,new p0(t));for(const t of e)if(t instanceof At){const i=this.getTypeInfo(t,null);i instanceof Dt&&this.structs.push(i)}for(const t of e)if(t instanceof mo)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof ho){const i=t,r=this._getAttributeNum(i.attributes,"id",0),s=i.type!=null?this.getTypeInfo(i.type,i.attributes):null;this.overrides.push(new qy(i.name,s,i.attributes,r));continue}if(this._isUniformVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=new lr(i.name,o,r,s,i.attributes,Ft.Uniform,i.access);a.access||(a.access="read"),this.uniforms.push(a);continue}if(this._isStorageVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=this._isStorageTexture(o),l=new lr(i.name,o,r,s,i.attributes,a?Ft.StorageTexture:Ft.Storage,i.access);l.access||(l.access="read"),this.storage.push(l);continue}if(this._isTextureVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=this._isStorageTexture(o),l=new lr(i.name,o,r,s,i.attributes,a?Ft.StorageTexture:Ft.Texture,i.access);l.access||(l.access="read"),a?this.storage.push(l):this.textures.push(l);continue}if(this._isSamplerVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=new lr(i.name,o,r,s,i.attributes,Ft.Sampler,i.access);this.samplers.push(a);continue}}for(const t of e)if(t instanceof jn){const i=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),o=i||r||s,a=new Ky(t.name,o==null?void 0:o.name,t.attributes);a.attributes=t.attributes,a.startLine=t.startLine,a.endLine=t.endLine,this.functions.push(a),this._functions.get(t.name).info=a,o&&(this._functions.get(t.name).inUse=!0,a.inUse=!0,a.resources=this._findResources(t,!!o),a.inputs=this._getInputs(t.args),a.outputs=this._getOutputs(t.returnType),this.entry[o.name].push(a)),a.arguments=t.args.map(l=>new jy(l.name,this.getTypeInfo(l.type,l.attributes),l.attributes)),a.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}for(const t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(const t of this._functions.values())t.node.search(i=>{var r,s,o;if(i instanceof vu){if(i.value)if(z(i.value))for(const a of i.value)for(const l of this.overrides)a===l.name&&((r=t.info)===null||r===void 0||r.overrides.push(l));else for(const a of this.overrides)i.value===a.name&&((s=t.info)===null||s===void 0||s.overrides.push(a))}else if(i instanceof Ze)for(const a of this.overrides)i.name===a.name&&((o=t.info)===null||o===void 0||o.overrides.push(a))});for(const t of this.uniforms)this._markStructsInUse(t.type);for(const t of this.storage)this._markStructsInUse(t.type)}getFunctionInfo(e){for(const t of this.functions)if(t.name==e)return t;return null}getStructInfo(e){for(const t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(const t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(const t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{const t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var i;for(const r of e.calls){const s=(i=this._functions.get(r.name))===null||i===void 0?void 0:i.info;s&&t.add(s)}}findResource(e,t,i){if(i){for(const r of this.entry.compute)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}for(const r of this.entry.vertex)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}for(const r of this.entry.fragment)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}}for(const r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(const r of this.storage)if(r.group==e&&r.binding==t)return r;for(const r of this.textures)if(r.group==e&&r.binding==t)return r;for(const r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(const t of this.uniforms)if(t.name==e)return t;for(const t of this.storage)if(t.name==e)return t;for(const t of this.textures)if(t.name==e)return t;for(const t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){const t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){const i=[],r=this,s=[];return e.search(o=>{if(o instanceof cr)s.push({});else if(o instanceof ur)s.pop();else if(o instanceof wt){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type),s.length>0&&(s[s.length-1][a.name]=a)}else if(o instanceof gt){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type)}else if(o instanceof Kn){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type),s.length>0&&(s[s.length-1][a.name]=a)}else if(o instanceof Ze){const a=o;if(s.length>0&&s[s.length-1][a.name])return;const l=r._findResource(a.name);l&&i.push(l)}else if(o instanceof go){const a=o,l=r._functions.get(a.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),i.push(...l.resources))}else if(o instanceof po){const a=o,l=r._functions.get(a.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),i.push(...l.resources))}}),[...new Map(i.map(o=>[o.name,o])).values()]}getBindGroups(){const e=[];function t(i,r){i>=e.length&&(e.length=i+1),e[i]===void 0&&(e[i]=[]),r>=e[i].length&&(e[i].length=r+1)}for(const i of this.uniforms)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.storage)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.textures)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.samplers)t(i.group,i.binding),e[i.group][i.binding]=i;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof At)this._getStructOutputs(e,t);else{const i=this._getOutputInfo(e);i!==null&&t.push(i)}return t}_getStructOutputs(e,t){for(const i of e.members)if(i.type instanceof At)this._getStructOutputs(i.type,t);else{const r=this._getAttribute(i,"location")||this._getAttribute(i,"builtin");if(r!==null){const s=this.getTypeInfo(i.type,i.type.attributes),o=this._parseInt(r.value),a=new Kc(i.name,s,r.name,o);t.push(a)}}}_getOutputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const i=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new Kc("",i,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(const i of e)if(i.type instanceof At)this._getStructInputs(i.type,t);else{const r=this._getInputInfo(i);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(const i of e.members)if(i.type instanceof At)this._getStructInputs(i.type,t);else{const r=this._getInputInfo(i);r!==null&&t.push(r)}}_getInputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const i=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),o=new Yy(e.name,r,t.name,s);return i!==null&&(o.interpolation=this._parseString(i.value)),o}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);const t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(const t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new Xy(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(const t of this.structs)if(t.name==e)return t;for(const t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof hr){const r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new lo(e.name,r,t);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Qn){const r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,o=new Mt(r.name,t);return o.format=s,o.count=r.count,this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof At){const r=e,s=new Dt(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(const o of r.members){const a=this.getTypeInfo(o.type,o.attributes);s.members.push(new jc(o.name,a,o.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Jn){const r=e,s=r.format instanceof k,o=r.format?s?this.getTypeInfo(r.format,null):new Je(r.format,null):null,a=new qt(r.name,o,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof T){const r=e,s=r.format?this.getTypeInfo(r.format,null):null,o=new qt(r.name,s,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}const i=new Je(e.name,t);return this._types.set(e,i),this._updateTypeInfo(i),i}_updateTypeInfo(e){var t,i,r;const s=this._getTypeSize(e);if(e.size=(t=s==null?void 0:s.size)!==null&&t!==void 0?t:0,e instanceof Mt&&e.format){const o=this._getTypeSize(e.format);e.stride=Math.max((i=o==null?void 0:o.size)!==null&&i!==void 0?i:0,(r=o==null?void 0:o.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof lo&&this._updateTypeInfo(e.format),e instanceof Dt&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let i=0,r=0,s=0,o=0;for(let a=0,l=e.members.length;a<l;++a){const c=e.members[a],u=this._getTypeSize(c);if(!u)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;const f=u.align,h=u.size;i=this._roundUp(f,i+r),r=h,s=i,o=Math.max(o,f),c.offset=i,c.size=h,this._updateTypeInfo(c.type)}e.size=this._roundUp(o,s+r),e.align=o}_getTypeSize(e){var t,i;if(e==null)return null;const r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof jc&&(e=e.type),e instanceof Je){const o=this._getAlias(e.name);o!==null&&(e=o)}{const o=_t._typeInfo[e.name];if(o!==void 0){const a=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new _r(Math.max(s,o.align/a),Math.max(r,o.size/a))}}{const o=_t._typeInfo[e.name.substring(0,e.name.length-1)];if(o){const a=e.name[e.name.length-1]==="h"?2:1;return new _r(Math.max(s,o.align/a),Math.max(r,o.size/a))}}if(e instanceof Mt){let o=e,a=8,l=8;const c=this._getTypeSize(o.format);return c!==null&&(l=c.size,a=c.align),l=o.count*this._getAttributeNum((i=e==null?void 0:e.attributes)!==null&&i!==void 0?i:null,"stride",this._roundUp(a,l)),r&&(l=r),new _r(Math.max(s,a),Math.max(r,l))}if(e instanceof Dt){let o=0,a=0,l=0,c=0,u=0;for(const f of e.members){const h=this._getTypeSize(f.type);h!==null&&(o=Math.max(h.align,o),l=this._roundUp(h.align,l+c),c=h.size,u=l)}return a=this._roundUp(o,u+c),new _r(Math.max(s,o),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof wt&&e.storage=="uniform"}_isStorageVar(e){return e instanceof wt&&e.storage=="storage"}_isTextureVar(e){return e instanceof wt&&e.type!==null&&_t._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof wt&&e.type!==null&&_t._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){const i=e;if(!i||!i.attributes)return null;const r=i.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,i){if(e===null)return i;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:i;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):i}return i}_roundUp(e,t){return Math.ceil(t/e)*e}}_t._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},_t._textureTypes=p.any_texture_type.map(n=>n.name),_t._samplerTypes=p.sampler_type.map(n=>n.name);let xo=0;class yo{constructor(e,t,i){this.id=xo++,this.name=e,this.value=t,this.node=i}clone(){return new yo(this.name,this.value,this.node)}}class vo{constructor(e){this.id=xo++,this.name=e.name,this.node=e}clone(){return new vo(this.node)}}class bo{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=xo++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?(t=this.variables.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?(t=this.functions.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,i){this.variables.set(e,new yo(e,t,i??null))}setVariable(e,t,i){const r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,i)}getVariableValue(e){var t;const i=this.getVariable(e);return(t=i==null?void 0:i.value)!==null&&t!==void 0?t:null}clone(){return new bo(this)}}class m0{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class g0{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const i=this.exec.evalExpression(e.args[0],t);let r=!0;if(i instanceof g)return i.data.forEach(s=>{s||(r=!1)}),new v(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){const r=i.data.some(s=>s);return new v(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){const i=this.exec.evalExpression(e.args[2],t);if(!(i instanceof v))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return i.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.evalExpression(i,t);if(r instanceof ve&&r.typeInfo.size===0){const s=r.typeInfo,o=r.buffer.byteLength/s.stride;return new v(o,this.getTypeInfo("u32"))}return new v(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.abs(s)),i.typeInfo);const r=i;return new v(Math.abs(r.value),r.typeInfo)}Acos(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.acos(s)),i.typeInfo);const r=i;return new v(Math.acos(r.value),i.typeInfo)}Acosh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.acosh(s)),i.typeInfo);const r=i;return new v(Math.acosh(r.value),i.typeInfo)}Asin(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.asin(s)),i.typeInfo);const r=i;return new v(Math.asin(r.value),i.typeInfo)}Asinh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.asinh(s)),i.typeInfo);const r=i;return new v(Math.asinh(r.value),i.typeInfo)}Atan(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.atan(s)),i.typeInfo);const r=i;return new v(Math.atan(r.value),i.typeInfo)}Atanh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.atanh(s)),i.typeInfo);const r=i;return new v(Math.atanh(r.value),i.typeInfo)}Atan2(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.atan2(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.atan2(s.value,o.value),i.typeInfo)}Ceil(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.ceil(s)),i.typeInfo);const r=i;return new v(Math.ceil(r.value),i.typeInfo)}_clamp(e,t,i){return Math.min(Math.max(e,t),i)}Clamp(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return new g(i.data.map((c,u)=>this._clamp(c,r.data[u],s.data[u])),i.typeInfo);const o=i,a=r,l=s;return new v(this._clamp(o.value,a.value,l.value),i.typeInfo)}Cos(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.cos(s)),i.typeInfo);const r=i;return new v(Math.cos(r.value),i.typeInfo)}Cosh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.cosh(s)),i.typeInfo);const r=i;return new v(Math.cos(r.value),i.typeInfo)}CountLeadingZeros(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.clz32(s)),i.typeInfo);const r=i;return new v(Math.clz32(r.value),i.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._countOneBits(s)),i.typeInfo);const r=i;return new v(this._countOneBits(r.value),i.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._countTrailingZeros(s)),i.typeInfo);const r=i;return new v(this._countTrailingZeros(r.value),i.typeInfo)}Cross(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){if(i.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;const s=i.data,o=r.data;return new g([s[1]*o[2]-o[1]*s[2],s[2]*o[0]-o[2]*s[0],s[0]*o[1]-o[0]*s[1]],i.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){const i=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return i instanceof g?new g(i.data.map(s=>s*r),i.typeInfo):new v(i.value*r,this.getTypeInfo("f32"))}Determinant(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof K){const r=i.data,s=i.typeInfo.getTypeName(),o=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new v(r[0]*r[3]-r[1]*r[2],o);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new v(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),o);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new v(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),o);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){let a=0;for(let l=0;l<i.data.length;++l)a+=(i.data[l]-r.data[l])*(i.data[l]-r.data[l]);return new v(Math.sqrt(a),this.getTypeInfo("f32"))}const s=i,o=r;return new v(Math.abs(s.value-o.value),i.typeInfo)}_dot(e,t){let i=0;for(let r=0;r<e.length;++r)i+=t[r]*e[r];return i}Dot(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return i instanceof g&&r instanceof g?new v(this._dot(i.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.exp(s)),i.typeInfo);const r=i;return new v(Math.exp(r.value),i.typeInfo)}Exp2(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.pow(2,s)),i.typeInfo);const r=i;return new v(Math.pow(2,r.value),i.typeInfo)}ExtractBits(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;const o=r.value,a=s.value;if(i instanceof g)return new g(i.data.map(c=>c>>o&(1<<a)-1),i.typeInfo);if(i.typeInfo.name!=="i32"&&i.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;const l=i.value;return new v(l>>o&(1<<a)-1,this.getTypeInfo("i32"))}FaceForward(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g){const o=this._dot(r.data,s.data);return new g(o<0?Array.from(i.data):i.data.map(a=>-a),i.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._firstLeadingBit(s)),i.typeInfo);const r=i;return new v(this._firstLeadingBit(r.value),i.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._firstTrailingBit(s)),i.typeInfo);const r=i;return new v(this._firstTrailingBit(r.value),i.typeInfo)}Floor(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.floor(s)),i.typeInfo);const r=i;return new v(Math.floor(r.value),i.typeInfo)}Fma(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return i.data.length!==r.data.length||i.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new g(i.data.map((c,u)=>c*r.data[u]+s.data[u]),i.typeInfo);const o=i,a=r,l=s;return new v(o.value*a.value+l.value,o.typeInfo)}Fract(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>s-Math.floor(s)),i.typeInfo);const r=i;return new v(r.value-Math.floor(r.value),i.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),o=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;const a=s.value,l=(1<<o.value)-1<<a,c=~l;if(i instanceof g&&r instanceof g)return new g(i.data.map((h,d)=>h&c|r.data[d]<<a&l),i.typeInfo);const u=i.value,f=r.value;return new v(u&c|f<<a&l,i.typeInfo)}InverseSqrt(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>1/Math.sqrt(s)),i.typeInfo);const r=i;return new v(1/Math.sqrt(r.value),i.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){let s=0;return i.data.forEach(o=>{s+=o*o}),new v(Math.sqrt(s),this.getTypeInfo("f32"))}const r=i;return new v(Math.abs(r.value),i.typeInfo)}Log(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.log(s)),i.typeInfo);const r=i;return new v(Math.log(r.value),i.typeInfo)}Log2(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.log2(s)),i.typeInfo);const r=i;return new v(Math.log2(r.value),i.typeInfo)}Max(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.max(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.max(s.value,o.value),i.typeInfo)}Min(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.min(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.min(s.value,o.value),i.typeInfo)}Mix(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return new g(i.data.map((l,c)=>i.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),i.typeInfo);const o=r,a=s;return new v(i.value*(1-a.value)+o.value*a.value,i.typeInfo)}Modf(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((o,a)=>o%r.data[a]),i.typeInfo);const s=r;return new v(i.value%s.value,i.typeInfo)}Normalize(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){const r=this.Length(e,t).value;return new g(i.data.map(s=>s/r),i.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.pow(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.pow(s.value,o.value),i.typeInfo)}QuantizeToF16(e,t){const i=this.exec.evalExpression(e.args[0],t);return i instanceof g?new g(i.data.map(r=>r),i.typeInfo):new v(i.value,i.typeInfo)}Radians(e,t){const i=this.exec.evalExpression(e.args[0],t);return i instanceof g?new g(i.data.map(r=>r*Math.PI/180),i.typeInfo):new v(i.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){const s=this._dot(i.data,r.data);return new g(i.data.map((o,a)=>o-2*s*r.data[a]),i.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof v){const o=this._dot(r.data,i.data);return new g(i.data.map((a,l)=>{const c=1-s.value*s.value*(1-o*o);if(c<0)return 0;const u=Math.sqrt(c);return s.value*a-(s.value*o+u)*r.data[l]}),i.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.round(s)),i.typeInfo);const r=i;return new v(Math.round(r.value),i.typeInfo)}Saturate(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.min(Math.max(s,0),1)),i.typeInfo);const r=i;return new v(Math.min(Math.max(r.value,0),1),i.typeInfo)}Sign(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sign(s)),i.typeInfo);const r=i;return new v(Math.sign(r.value),i.typeInfo)}Sin(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sin(s)),i.typeInfo);const r=i;return new v(Math.sin(r.value),i.typeInfo)}Sinh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sinh(s)),i.typeInfo);const r=i;return new v(Math.sinh(r.value),i.typeInfo)}_smoothstep(e,t,i){const r=Math.min(Math.max((i-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof g&&i instanceof g&&r instanceof g)return new g(s.data.map((c,u)=>this._smoothstep(i.data[u],r.data[u],c)),s.typeInfo);const o=i,a=r,l=s;return new v(this._smoothstep(o.value,a.value,l.value),s.typeInfo)}Sqrt(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sqrt(s)),i.typeInfo);const r=i;return new v(Math.sqrt(r.value),i.typeInfo)}Step(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof g&&i instanceof g)return new g(r.data.map((o,a)=>o<i.data[a]?0:1),r.typeInfo);const s=i;return new v(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.tan(s)),i.typeInfo);const r=i;return new v(Math.tan(r.value),i.typeInfo)}Tanh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.tanh(s)),i.typeInfo);const r=i;return new v(Math.tanh(r.value),i.typeInfo)}_getTransposeType(e){const t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){const i=this.exec.evalExpression(e.args[0],t);if(!(i instanceof K))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;const r=this._getTransposeType(i.typeInfo);if(i.typeInfo.name==="mat2x2"||i.typeInfo.name==="mat2x2f"||i.typeInfo.name==="mat2x2h"){const s=i.data;return new K([s[0],s[2],s[1],s[3]],r)}if(i.typeInfo.name==="mat2x3"||i.typeInfo.name==="mat2x3f"||i.typeInfo.name==="mat2x3h"){const s=i.data;return new K([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(i.typeInfo.name==="mat2x4"||i.typeInfo.name==="mat2x4f"||i.typeInfo.name==="mat2x4h"){const s=i.data;return new K([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(i.typeInfo.name==="mat3x2"||i.typeInfo.name==="mat3x2f"||i.typeInfo.name==="mat3x2h"){const s=i.data;return new K([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(i.typeInfo.name==="mat3x3"||i.typeInfo.name==="mat3x3f"||i.typeInfo.name==="mat3x3h"){const s=i.data;return new K([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(i.typeInfo.name==="mat3x4"||i.typeInfo.name==="mat3x4f"||i.typeInfo.name==="mat3x4h"){const s=i.data;return new K([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(i.typeInfo.name==="mat4x2"||i.typeInfo.name==="mat4x2f"||i.typeInfo.name==="mat4x2h"){const s=i.data;return new K([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(i.typeInfo.name==="mat4x3"||i.typeInfo.name==="mat4x3f"||i.typeInfo.name==="mat4x3h"){const s=i.data;return new K([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(i.typeInfo.name==="mat4x4"||i.typeInfo.name==="mat4x4f"||i.typeInfo.name==="mat4x4h"){const s=i.data;return new K([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${i.typeInfo.name}`),null}Trunc(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.trunc(s)),i.typeInfo);const r=i;return new v(Math.trunc(r.value),i.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){const i=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(i instanceof Ze){const s=i.name,o=t.getVariableValue(s);if(o instanceof Ct){if(r<0||r>=o.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;const a=o.getMipLevelSize(r),l=o.dimension;return l==="1d"?new v(a[0],this.getTypeInfo("u32")):l==="3d"?new g(a,this.getTypeInfo("vec3u")):l==="2d"?new g(a.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${l} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){const i=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof g)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(i instanceof Ze){const o=i.name,a=t.getVariableValue(o);if(a instanceof Ct){const l=Math.floor(r.data[0]),c=Math.floor(r.data[1]);if(l<0||l>=a.width||c<0||c>=a.height)return console.error(`Texture ${o} out of bounds. Line ${e.line}`),null;const u=a.getPixel(l,c,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new g(u,this.getTypeInfo("vec4f"))}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){const i=e.args[0];if(i instanceof Ze){const r=i.name,s=t.getVariableValue(r);return s instanceof Ct?new v(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){const i=e.args[0];if(i instanceof Ze){const r=i.name,s=t.getVariableValue(r);return s instanceof Ct?new v(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){const i=e.args[0];if(i instanceof Ze){const r=i.name,s=t.getVariableValue(r);return s instanceof Ct?new v(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){const i=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,o=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(o.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof g)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(i instanceof Ze){const a=i.name,l=t.getVariableValue(a);if(l instanceof Ct){const c=l.getMipLevelSize(0),u=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return u<0||u>=c[0]||f<0||f>=c[1]?(console.error(`Texture ${a} out of bounds. Line ${e.line}`),null):(l.setPixel(u,f,0,s,Array.from(o)),null)}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t);return t.getVariable(r).value.getSubData(this.exec,i.postfix,t)}AtomicStore(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t);return l instanceof v&&a instanceof v&&(l.value=a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),null}AtomicAdd(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value+=a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicSub(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value-=a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicMax(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=Math.max(l.value,a.value)),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicMin(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=Math.min(l.value,a.value)),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicAnd(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value&a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicOr(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value|a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicXor(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value^a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicExchange(e,t){let i=e.args[0];i instanceof Se&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=a.value),s.value instanceof ve&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}}const So={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},He={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]};class Ne extends m0{constructor(e,t){var i;super(),this.ast=e??[],this.reflection=new _t,this.reflection.updateAST(this.ast),this.context=(i=t==null?void 0:t.clone())!==null&&i!==void 0?i:new bo,this.builtins=new g0(this),this.typeInfo={bool:this.getTypeInfo(k.bool),i32:this.getTypeInfo(k.i32),u32:this.getTypeInfo(k.u32),f32:this.getTypeInfo(k.f32),f16:this.getTypeInfo(k.f16),vec2f:this.getTypeInfo(T.vec2f),vec2u:this.getTypeInfo(T.vec2u),vec2i:this.getTypeInfo(T.vec2i),vec2h:this.getTypeInfo(T.vec2h),vec3f:this.getTypeInfo(T.vec3f),vec3u:this.getTypeInfo(T.vec3u),vec3i:this.getTypeInfo(T.vec3i),vec3h:this.getTypeInfo(T.vec3h),vec4f:this.getTypeInfo(T.vec4f),vec4u:this.getTypeInfo(T.vec4u),vec4i:this.getTypeInfo(T.vec4i),vec4h:this.getTypeInfo(T.vec4h),mat2x2f:this.getTypeInfo(T.mat2x2f),mat2x3f:this.getTypeInfo(T.mat2x3f),mat2x4f:this.getTypeInfo(T.mat2x4f),mat3x2f:this.getTypeInfo(T.mat3x2f),mat3x3f:this.getTypeInfo(T.mat3x3f),mat3x4f:this.getTypeInfo(T.mat3x4f),mat4x2f:this.getTypeInfo(T.mat4x2f),mat4x3f:this.getTypeInfo(T.mat4x3f),mat4x4f:this.getTypeInfo(T.mat4x4f)}}getVariableValue(e){var t,i;const r=(i=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&i!==void 0?i:null;if(r===null)return null;if(r instanceof v)return r.value;if(r instanceof g||r instanceof K)return Array.from(r.data);if(r instanceof ve&&r.typeInfo instanceof Mt){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,i,r){const s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);const o=s.getFunction(e);if(!o)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}const a=t[0],l=t[1],c=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new g(t,u));const f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(const h in i)for(const d in i[h]){const _=i[h][d];s.variables.forEach(I=>{var P;const A=I.node;if(A!=null&&A.attributes){let O=null,E=null;for(const x of A.attributes)x.name==="binding"?O=x.value:x.name==="group"&&(E=x.value);if(d==O&&h==E){let x=!1;for(const R of f.resources)if(R.name===I.name&&R.group===parseInt(h)&&R.binding===parseInt(d)){x=!0;break}if(x)if(_.texture!==void 0&&_.descriptor!==void 0){const R=new Ct(_.texture,this.getTypeInfo(A.type),_.descriptor,(P=_.texture.view)!==null&&P!==void 0?P:null);I.value=R}else _.uniform!==void 0?I.value=new ve(_.uniform,this.getTypeInfo(A.type)):I.value=new ve(_,this.getTypeInfo(A.type))}}})}for(let h=0;h<c;++h)for(let d=0;d<l;++d)for(let _=0;_<a;++_)s.setVariable("@workgroup_id",new g([_,d,h],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(o,[_,d,h],s)}execStatement(e,t){if(e instanceof au)return this.evalExpression(e.value,t);if(e instanceof cu){if(e.condition){const i=this.evalExpression(e.condition,t);if(!(i instanceof v))throw new Error("Invalid break-if condition");if(!i.value)return null}return Ne._breakObj}if(e instanceof uu)return Ne._continueObj;if(e instanceof Kn)this._let(e,t);else if(e instanceof wt)this._var(e,t);else if(e instanceof fr)this._const(e,t);else if(e instanceof jn)this._function(e,t);else{if(e instanceof ou)return this._if(e,t);if(e instanceof su)return this._switch(e,t);if(e instanceof tu)return this._for(e,t);if(e instanceof eu)return this._while(e,t);if(e instanceof ru)return this._loop(e,t);if(e instanceof fo){const i=t.clone();return i.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,i)}if(e instanceof iu)this._assign(e,t);else if(e instanceof nu)this._increment(e,t);else{if(e instanceof At)return null;if(e instanceof ho){const i=e.name;t.getVariable(i)===null&&t.setVariable(i,new v(0,this.getTypeInfo("u32")))}else if(e instanceof po)this._call(e,t);else{if(e instanceof lu||e instanceof mo)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof ct?this._evalBinaryOp(e,t):e instanceof Ae?this._evalLiteral(e,t):e instanceof Ze?this._evalVariable(e,t):e instanceof go?this._evalCall(e,t):e instanceof gt?this._evalCreate(e,t):e instanceof hu?this._evalConst(e,t):e instanceof du?this._evalBitcast(e,t):e instanceof Se?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof k){const r=this.reflection.getTypeInfo(e);if(r!==null)return r}let i=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return i!==null||(i=this.reflection.getTypeInfoByName(e)),i}_setOverrides(e,t){for(const i in e){const r=e[i],s=this.reflection.getOverrideInfo(i);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(i,new v(r,s.type)):s.type.name==="bool"?t.setVariable(i,new v(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(i,new g(r,s.type)):console.error(`Invalid constant type for ${i}`)):console.error(`Override ${i} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,i){const r=[1,1,1];for(const u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){const f=i.getVariableValue(u.value[0]);r[0]=f instanceof v?f.value:parseInt(u.value[0])}if(u.value.length>1){const f=i.getVariableValue(u.value[1]);r[1]=f instanceof v?f.value:parseInt(u.value[1])}if(u.value.length>2){const f=i.getVariableValue(u.value[2]);r[2]=f instanceof v?f.value:parseInt(u.value[2])}}const s=this.getTypeInfo("vec3u"),o=this.getTypeInfo("u32");i.setVariable("@workgroup_size",new g(r,s));const a=r[0],l=r[1],c=r[2];for(let u=0,f=0;u<c;++u)for(let h=0;h<l;++h)for(let d=0;d<a;++d,++f){const _=[d,h,u],I=[d+t[0]*r[0],h+t[1]*r[1],u+t[2]*r[2]];i.setVariable("@local_invocation_id",new g(_,s)),i.setVariable("@global_invocation_id",new g(I,s)),i.setVariable("@local_invocation_index",new v(f,o)),this._dispatchExec(e,i)}}_dispatchExec(e,t){for(const i of e.node.args)for(const r of i.attributes)if(r.name==="builtin"){const s=`@${r.value}`,o=t.getVariable(s);o!==void 0&&t.variables.set(i.name,o)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof Se;)e=e.right;return e instanceof Ze?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(const i of e){if(i instanceof Array){const s=t.clone(),o=this._execStatements(i,s);if(o)return o;continue}const r=this.execStatement(i,t);if(r)return r}return null}_call(e,t){const i=t.clone();i.currentFunctionName=e.name;const r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){const o=r.node.args[s],a=this.evalExpression(e.args[s],i);i.setVariable(o.name,a,o)}this._execStatements(r.node.body,i)}else e.isBuiltin?this._callBuiltinFunction(e,i):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){const i=this.getVariableName(e.variable,t),r=t.getVariable(i);r?e.operator==="++"?r.value instanceof v?r.value.value++:console.error(`Variable ${i} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof v?r.value.value--:console.error(`Variable ${i} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${i} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof Ze){const i=this.getVariableName(e,t),r=t.getVariable(i);return r===null?(console.error(`Variable ${i} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof Se){if(e.operator==="*"){const i=this._getVariableData(e.right,t);return i instanceof xn?i.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){const i=this._getVariableData(e.right,t);return new xn(i)}}return null}_assign(e,t){let i=null,r="<var>",s=null;if(e.variable instanceof Se){const l=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(l instanceof v||l instanceof g||l instanceof K){if(c instanceof v||c instanceof g||c instanceof K&&l.data.length===c.data.length)return void l.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(l instanceof ve&&c instanceof ve&&l.buffer.byteLength-l.offset>=c.buffer.byteLength-c.offset)return void(l.buffer.byteLength%4==0?new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(l.buffer,l.offset,l.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return l instanceof v||l instanceof g||l instanceof K?c instanceof v||c instanceof g||c instanceof K?void l.data.set(c.data.map((f,h)=>l.data[h]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(l instanceof v||l instanceof g||l instanceof K)&&(c instanceof v||c instanceof g||c instanceof K)?void l.data.set(c.data.map((f,h)=>l.data[h]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof Se){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);const l=t.getVariable(r);if(!(l&&l.value instanceof xn))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);i=l.value.reference;let c=e.variable.postfix;if(!c){let u=e.variable.right;for(;u instanceof Se;){if(u.postfix){c=u.postfix;break}u=u.right}}c&&(i=i.getSubData(this,c,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);const l=t.getVariable(r);if(l===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);i=l.value}if(i instanceof xn&&(i=i.reference),i===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);const o=this.evalExpression(e.value,t),a=e.operator;if(a!=="="){const l=i.getSubData(this,s,t);if(l instanceof g&&o instanceof v){const c=l.data,u=o.value;if(a==="+=")for(let f=0;f<c.length;++f)c[f]+=u;else if(a==="-=")for(let f=0;f<c.length;++f)c[f]-=u;else if(a==="*=")for(let f=0;f<c.length;++f)c[f]*=u;else if(a==="/=")for(let f=0;f<c.length;++f)c[f]/=u;else if(a==="%=")for(let f=0;f<c.length;++f)c[f]%=u;else if(a==="&=")for(let f=0;f<c.length;++f)c[f]&=u;else if(a==="|=")for(let f=0;f<c.length;++f)c[f]|=u;else if(a==="^=")for(let f=0;f<c.length;++f)c[f]^=u;else if(a==="<<=")for(let f=0;f<c.length;++f)c[f]<<=u;else if(a===">>=")for(let f=0;f<c.length;++f)c[f]>>=u;else console.error(`Invalid operator ${a}. Line ${e.line}`)}else if(l instanceof g&&o instanceof g){const c=l.data,u=o.data;if(c.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(a==="+=")for(let f=0;f<c.length;++f)c[f]+=u[f];else if(a==="-=")for(let f=0;f<c.length;++f)c[f]-=u[f];else if(a==="*=")for(let f=0;f<c.length;++f)c[f]*=u[f];else if(a==="/=")for(let f=0;f<c.length;++f)c[f]/=u[f];else if(a==="%=")for(let f=0;f<c.length;++f)c[f]%=u[f];else if(a==="&=")for(let f=0;f<c.length;++f)c[f]&=u[f];else if(a==="|=")for(let f=0;f<c.length;++f)c[f]|=u[f];else if(a==="^=")for(let f=0;f<c.length;++f)c[f]^=u[f];else if(a==="<<=")for(let f=0;f<c.length;++f)c[f]<<=u[f];else if(a===">>=")for(let f=0;f<c.length;++f)c[f]>>=u[f];else console.error(`Invalid operator ${a}. Line ${e.line}`)}else{if(!(l instanceof v&&o instanceof v))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);a==="+="?l.value+=o.value:a==="-="?l.value-=o.value:a==="*="?l.value*=o.value:a==="/="?l.value/=o.value:a==="%="?l.value%=o.value:a==="&="?l.value&=o.value:a==="|="?l.value|=o.value:a==="^="?l.value^=o.value:a==="<<="?l.value<<=o.value:a===">>="?l.value>>=o.value:console.error(`Invalid operator ${a}. Line ${e.line}`)}return void(i instanceof ve&&i.setDataValue(this,l,s,t))}if(i instanceof ve)i.setDataValue(this,o,s,t);else if(s){if(!(i instanceof g||i instanceof K))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof _n){const l=this.evalExpression(s.index,t).value;if(i instanceof g){if(!(o instanceof v))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[l]=o.value}else{if(!(i instanceof K))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{const c=this.evalExpression(s.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(o instanceof g))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{const u=i.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(c<2&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(c<2&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(c<2&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(c<3&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(c<3&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(c<3&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(c<4&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(c<4&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(c<4&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}}}}}else if(s instanceof jt){const l=s.value;if(!(i instanceof g))return void console.error(`Invalid assignment to ${l}. Variable ${r} is not a vector. Line ${e.line}`);if(o instanceof v){if(l.length>1)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);if(l==="x")i.data[0]=o.value;else if(l==="y"){if(i.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[1]=o.value}else if(l==="z"){if(i.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[2]=o.value}else if(l==="w"){if(i.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[3]=o.value}}else{if(!(o instanceof g))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(l.length!==o.data.length)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);for(let c=0;c<l.length;++c){const u=l[c];if(u==="x"||u==="r")i.data[0]=o.data[c];else if(u==="y"||u==="g"){if(o.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[1]=o.data[c]}else if(u==="z"||u==="b"){if(o.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[2]=o.data[c]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(o.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[3]=o.data[c]}}}}}else i instanceof v&&o instanceof v?i.value=o.value:i instanceof g&&o instanceof g||i instanceof K&&o instanceof K?i.data.set(o.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`)}_function(e,t){const i=new vo(e);t.functions.set(e.name,i)}_const(e,t){let i=null;e.value!==null&&(i=this.evalExpression(e.value,t)),t.createVariable(e.name,i,e)}_let(e,t){let i=null;if(e.value!==null){if(i=this.evalExpression(e.value,t),i===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Se||(i=i.clone())}else{const r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){const s=new gt(e.type,[]);i=this._evalCreate(s,t)}}t.createVariable(e.name,i,e)}_var(e,t){let i=null;if(e.value!==null){if(i=this.evalExpression(e.value,t),i===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Se||(i=i.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);const r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof Qn||e.type instanceof At||e.type instanceof T){const s=new gt(e.type,[]);i=this._evalCreate(s,t)}}t.createVariable(e.name,i,e)}_switch(e,t){t=t.clone();const i=this.evalExpression(e.condition,t);if(!(i instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(const s of e.cases)if(s instanceof gu)for(const o of s.selectors){if(o instanceof dr){r=s;continue}const a=this.evalExpression(o,t);if(!(a instanceof v))return console.error(`Invalid case selector. Line ${e.line}`),null;if(a.value===i.value)return this._execStatements(s.body,t)}else s instanceof _u&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();const i=this.evalExpression(e.condition,t);if(!(i instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(i.value)return this._execStatements(e.body,t);for(const r of e.elseif){const s=this.evalExpression(r.condition,t);if(!(s instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof v?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){const i=this._execStatements(e.body,t);if(i===Ne._breakObj)break;if(i!==null&&i!==Ne._continueObj)return i;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){const i=this._execStatements(e.body,t);if(i===Ne._breakObj)break;if(i===Ne._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===Ne._breakObj)break}else if(i!==null)return i}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){const i=this._execStatements(e.body,t);if(i===Ne._breakObj)break;if(i!==Ne._continueObj&&i!==null)return i}return null}_evalBitcast(e,t){const i=this.evalExpression(e.value,t),r=e.type;if(i instanceof v){const s=Su(i.value,i.typeInfo.name,r.name);return new v(s,this.getTypeInfo(r))}if(i instanceof g){const s=i.typeInfo.getTypeName();let o="";if(s.endsWith("f"))o="f32";else if(s.endsWith("i"))o="i32";else if(s.endsWith("u"))o="u32";else if(s.endsWith("b"))o="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;o="f16"}const a=r.getTypeName();let l="";if(a.endsWith("f"))l="f32";else if(a.endsWith("i"))l="i32";else if(a.endsWith("u"))l="u32";else if(a.endsWith("b"))l="bool";else{if(!a.endsWith("h"))return console.error(`Unknown vector type ${l}. Line ${e.line}`),null;l="f16"}const c=function(u,f,h){if(f===h)return u;const d=new Array(u.length);for(let _=0;_<u.length;_++)d[_]=Su(u[_],f,h);return d}(Array.from(i.data),o,l);return new g(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${i.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var i;if(e instanceof gt){if(e.type===null)return _o.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}const r=e instanceof gt?e.type.name:e.name,s=e instanceof gt?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;const o=new ve(new ArrayBuffer(s.size),s,0);if(s instanceof Dt){if(e.args)for(let a=0;a<e.args.length;++a){const l=s.members[a],c=e.args[a],u=this.evalExpression(c,t);o.setData(this,u,l.type,l.offset,t)}}else if(s instanceof Mt){let a=0;if(e.args)for(let l=0;l<e.args.length;++l){const c=e.args[l],u=this.evalExpression(c,t);s.format===null&&(((i=u.typeInfo)===null||i===void 0?void 0:i.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),o.setData(this,u,s.format,a,t),a+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof gt?o.getSubData(this,e.postfix,t):o}_evalLiteral(e,t){const i=this.getTypeInfo(e.type),r=i.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new v(e.scalarValue,i):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){const i=t.getVariableValue(e.name);return i===null?i:i.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let i=1;i<e.length;++i){const r=Ne._priority.get(t.name);Ne._priority.get(e[i].name)<r&&(t=e[i])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){const i=this.evalExpression(e.right,t);if(e.operator==="&")return new xn(i);if(e.operator==="*")return i instanceof xn?i.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);const r=i instanceof v?i.value:i instanceof g?Array.from(i.data):null;switch(e.operator){case"+":{if(z(r)){const a=r.map((l,c)=>+l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(+s,o)}case"-":{if(z(r)){const a=r.map((l,c)=>-l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(-s,o)}case"!":{if(z(r)){const a=r.map((l,c)=>l?0:1);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(s?0:1,o)}case"~":{if(z(r)){const a=r.map((l,c)=>~l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(~s,o)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){const i=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=i instanceof v?i.value:i instanceof g||i instanceof K?Array.from(i.data):null,o=r instanceof v?r.value:r instanceof g||r instanceof K?Array.from(r.data):null;switch(e.operator){case"+":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d+f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h+u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u+h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a+l,c)}case"-":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d-f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h-u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u-h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a-l,c)}case"*":{if(z(s)&&z(o)){const u=s,f=o;if(i instanceof K&&r instanceof K){const h=function(P,A,O,E){if(He[A.name]===void 0||He[E.name]===void 0)return null;const x=He[A.name][0],R=He[A.name][1],N=He[E.name][0];if(x!==He[E.name][1])return null;const U=new Array(N*R);for(let W=0;W<R;W++)for(let q=0;q<N;q++){let G=0;for(let B=0;B<x;B++)G+=P[B*R+W]*O[q*x+B];U[W*N+q]=G}return U}(u,i.typeInfo,f,r.typeInfo);if(h===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;const d=He[r.typeInfo.name][0],_=He[i.typeInfo.name][1],I=this.getTypeInfo(`mat${d}x${_}f`);return new K(h,I)}if(i instanceof K&&r instanceof g){const h=function(d,_,I,P){if(He[_.name]===void 0||So[P.name]===void 0)return null;const A=He[_.name][0],O=He[_.name][1];if(A!==I.length)return null;const E=new Array(O);for(let x=0;x<O;x++){let R=0;for(let N=0;N<A;N++)R+=d[N*O+x]*I[N];E[x]=R}return E}(u,i.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(h,r.typeInfo)}if(i instanceof g&&r instanceof K){const h=function(d,_,I,P){if(So[_.name]===void 0||He[P.name]===void 0)return null;const A=He[P.name][0],O=He[P.name][1];if(O!==d.length)return null;const E=[];for(let x=0;x<A;x++){let R=0;for(let N=0;N<O;N++)R+=d[N]*I[N*A+x];E[x]=R}return E}(u,i.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(h,i.typeInfo)}{if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d*f[_]);return new g(h,i.typeInfo)}}if(z(s)){const u=o,f=s.map((h,d)=>h*u);return i instanceof K?new K(f,i.typeInfo):new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u*h);return r instanceof K?new K(f,r.typeInfo):new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a*l,c)}case"%":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d%f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h%u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u%h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a%l,c)}case"/":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d/f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h/u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u/h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a/l,c)}case"&":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d&f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h&u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u&h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a&l,c)}case"|":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d|f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h|u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u|h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a|l,c)}case"^":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d^f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h^u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u^h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a^l,c)}case"<<":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d<<f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h<<u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u<<h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a<<l,c)}case">>":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d>>f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h>>u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u>>h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a>>l,c)}case">":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u>l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>c?1:0);return new g(l,r.typeInfo)}return new v(s>o?1:0,this.getTypeInfo("bool"));case"<":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u<l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<c?1:0);return new g(l,r.typeInfo)}return new v(s<o?1:0,this.getTypeInfo("bool"));case"==":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u===l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c==a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a==c?1:0);return new g(l,r.typeInfo)}return new v(s===o?1:0,this.getTypeInfo("bool"));case"!=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u!==l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c!==a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a!==c?1:0);return new g(l,r.typeInfo)}return new v(s!==o?1:0,this.getTypeInfo("bool"));case">=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u>=l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>=a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>=c?1:0);return new g(l,r.typeInfo)}return new v(s>=o?1:0,this.getTypeInfo("bool"));case"<=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u<=l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<=a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<=c?1:0);return new g(l,r.typeInfo)}return new v(s<=o?1:0,this.getTypeInfo("bool"));case"&&":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u&&l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c&&a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a&&c?1:0);return new g(l,r.typeInfo)}return new v(s&&o?1:0,this.getTypeInfo("bool"));case"||":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u||l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c||a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a||c?1:0);return new g(l,r.typeInfo)}return new v(s||o?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;const i=t.clone();i.currentFunctionName=e.name;const r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,i):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){const o=r.node.args[s],a=this.evalExpression(e.args[s],i);i.createVariable(o.name,a,o)}return this._execStatements(r.node.body,i)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothstep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}const i=t.getFunction(e.name);if(i){const r=t.clone();for(let s=0;s<i.node.args.length;++s){const o=i.node.args[s],a=this.evalExpression(e.args[s],r);r.setVariable(o.name,a,o)}return this._execStatements(i.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new v(0,this.getTypeInfo(e.type));const i=this.evalExpression(e.args[0],t);return i.typeInfo=this.getTypeInfo(e.type),i.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){const i=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=So[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ae)if(e.isVector){const a=e.vectorValue;for(const l of a)o.push(l)}else o.push(e.scalarValue);else if(e.args)for(const a of e.args){const l=this.evalExpression(a,t);if(l instanceof g){const c=l.data;for(let u=0;u<c.length;++u){let f=c[u];o.push(f)}}else if(l instanceof v){let c=l.value;o.push(c)}}if(e.type instanceof T&&e.type.format===null&&(e.type.format=T.f32),o.length===0){const a=new Array(s).fill(0);return new g(a,i).getSubData(this,e.postfix,t)}if(o.length===1)for(;o.length<s;)o.push(o[0]);return o.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new g(o.length>s?o.slice(0,s):o,i).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const i=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=He[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ae)if(e.isVector){const a=e.vectorValue;for(const l of a)o.push(l)}else o.push(e.scalarValue);else if(e.args)for(const a of e.args){const l=this.evalExpression(a,t);l instanceof g?o.push(...l.data):l instanceof v?o.push(l.value):l instanceof K&&o.push(...l.data)}if(i instanceof qt&&i.format===null&&(i.format=this.getTypeInfo("f32")),o.length===0){const a=new Array(s[2]).fill(0);return new K(a,i).getSubData(this,e.postfix,t)}return o.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new K(o,i).getSubData(this,e.postfix,t)}}Ne._breakObj=new et(new Je("BREAK",null),null),Ne._continueObj=new et(new Je("CONTINUE",null),null),Ne._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class _0{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class x0{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new _0,this._exec=new Ne,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const i=this._global_decl_or_directive();if(!i)break;t.push(i)}if(this._deferArrayCountEval.length>0){for(const i of this._deferArrayCountEval){const r=i.arrayType,s=i.countNode;if(s instanceof Ze){const o=s.name,a=this._context.constants.get(o);if(a)try{const l=a.constEvaluate(this._exec);r.count=l}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(const i of t)i.search(r=>{r instanceof yu||r instanceof hr?r.type=this._forwardType(r.type):r instanceof Qn?r.format=this._forwardType(r.format):r instanceof wt||r instanceof Kn||r instanceof fr?r.type=this._forwardType(r.type):r instanceof jn?r.returnType=this._forwardType(r.returnType):r instanceof xu&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof fu){const t=this._getType(e.name);if(t)return t}else e instanceof hr?e.type=this._forwardType(e.type):e instanceof Qn&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){const t=new a0(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==p.eof}_match(e){if(e instanceof S)return!!this._check(e)&&(this._advance(),!0);for(let t=0,i=e.length;t<i;++t){const r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;const t=this._peek();if(e instanceof Array){const i=t.type;let r=!1;for(const s of e){if(i===s)return!0;s===p.tokens.name&&(r=!0)}if(r){const s=p.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===p.tokens.name){const i=p.tokens.name.rule.exec(t.lexeme);return i&&i.index==0&&i[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(p.tokens.semicolon)&&!this._isAtEnd(););if(this._match(p.keywords.alias)){const t=this._type_alias();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.diagnostic)){const t=this._diagnostic();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.requires)){const t=this._requires_directive();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.enable)){const t=this._enable_directive();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}const e=this._attribute();if(this._check(p.keywords.var)){const t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.override)){const t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.let)){const t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.const)){const t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.struct)){const t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.fn)){const t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(p.keywords.fn))return null;const e=this._currentLine,t=this._consume(p.tokens.ident,"Expected function name.").toString();this._consume(p.tokens.paren_left,"Expected '(' for function arguments.");const i=[];if(!this._check(p.tokens.paren_right))do{if(this._check(p.tokens.paren_right))break;const a=this._attribute(),l=this._consume(p.tokens.name,"Expected argument name.").toString();this._consume(p.tokens.colon,"Expected ':' for argument type.");const c=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=c,i.push(this._updateNode(new xu(l,u,a))))}while(this._match(p.tokens.comma));this._consume(p.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(p.tokens.arrow)){const a=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=a)}const s=this._compound_statement(),o=this._currentLine;return this._updateNode(new jn(t,i,r,s,e,o),e)}_compound_statement(){const e=[];for(this._consume(p.tokens.brace_left,"Expected '{' for block.");!this._check(p.tokens.brace_right);){const t=this._statement();t!==null&&e.push(t)}return this._consume(p.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(p.tokens.semicolon)&&!this._isAtEnd(););if(this._check(p.tokens.attr)&&this._attribute(),this._check(p.keywords.if))return this._if_statement();if(this._check(p.keywords.switch))return this._switch_statement();if(this._check(p.keywords.loop))return this._loop_statement();if(this._check(p.keywords.for))return this._for_statement();if(this._check(p.keywords.while))return this._while_statement();if(this._check(p.keywords.continuing))return this._continuing_statement();if(this._check(p.keywords.static_assert))return this._static_assert_statement();if(this._check(p.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(p.keywords.return))e=this._return_statement();else if(this._check([p.keywords.var,p.keywords.let,p.keywords.const]))e=this._variable_statement();else if(this._match(p.keywords.discard))e=this._updateNode(new r0);else if(this._match(p.keywords.break)){const t=this._updateNode(new cu);if(this._currentLoop.length>0){const i=this._currentLoop[this._currentLoop.length-1];t.loopId=i.id}e=t,this._check(p.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(p.keywords.continue)){const t=this._updateNode(new uu);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const i=this._currentLoop[this._currentLoop.length-1];t.loopId=i.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(p.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(p.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new t0(t),e)}_while_statement(){if(!this._match(p.keywords.while))return null;const e=this._updateNode(new eu(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(p.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){const e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(p.keywords.continuing))return null;const t=this._currentLine,i=this._compound_statement();return this._updateNode(new fo(i,e),t)}_for_statement(){if(!this._match(p.keywords.for))return null;this._consume(p.tokens.paren_left,"Expected '('.");const e=this._updateNode(new tu(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(p.tokens.semicolon)?null:this._for_init(),this._consume(p.tokens.semicolon,"Expected ';'."),e.condition=this._check(p.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(p.tokens.semicolon,"Expected ';'."),e.increment=this._check(p.tokens.paren_right)?null:this._for_increment(),this._consume(p.tokens.paren_right,"Expected ')'."),this._check(p.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(p.keywords.var)){const e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(p.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new wt(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(p.keywords.let)){const e=this._currentLine,t=this._consume(p.tokens.name,"Expected name for let.").toString();let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for let.");const r=this._short_circuit_or_expression();return this._updateNode(new Kn(t,i,null,null,r),e)}if(this._match(p.keywords.const)){const e=this._currentLine,t=this._consume(p.tokens.name,"Expected name for const.").toString();let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for const.");const r=this._short_circuit_or_expression();return i===null&&r instanceof Ae&&(i=r.type),this._updateNode(new fr(t,i,null,null,r),e)}return null}_increment_decrement_statement(){const e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(p.increment_operators))return this._current=e,null;const i=this._consume(p.increment_operators,"Expected increment operator");return this._updateNode(new nu(i.type===p.tokens.plus_plus?gn.increment:gn.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(p.tokens.brace_right))return null;let i=this._match(p.tokens.underscore);if(i||(e=this._unary_expression()),!i&&e==null)return null;const r=this._consume(p.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new iu(Zn.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(p.tokens.ident))return null;const e=this._currentLine,t=this._current,i=this._consume(p.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new po(i.lexeme,r),e)}_loop_statement(){if(!this._match(p.keywords.loop))return null;this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Expected '{' for loop.");const e=this._updateNode(new ru([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let i of t)e.body.push(i);else e.body.push(t);if(t instanceof fo){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(p.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(p.keywords.switch))return null;const e=this._updateNode(new su(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(p.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([p.keywords.default,p.keywords.case]);){if(this._match(p.keywords.case)){const i=this._case_selectors();for(const s of i)if(s instanceof dr){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(p.tokens.colon),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Exected '{' for switch case.");const r=this._case_body();this._consume(p.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new gu(i,r)))}if(this._match(p.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(p.tokens.colon),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Exected '{' for switch default.");const i=this._case_body();this._consume(p.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new _u(i)))}}return e}_case_selectors(){const e=[];for(this._match(p.keywords.default)?e.push(this._updateNode(new dr)):e.push(this._shift_expression());this._match(p.tokens.comma);)this._match(p.keywords.default)?e.push(this._updateNode(new dr)):e.push(this._shift_expression());return e}_case_body(){if(this._match(p.keywords.fallthrough))return this._consume(p.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);const t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(p.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(p.tokens.attr)&&this._attribute();const i=this._compound_statement();let r=[];this._match_elseif()&&(this._check(p.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(p.keywords.else)&&(this._check(p.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new ou(t,i,r,s),e)}_match_elseif(){return this._tokens[this._current].type===p.keywords.else&&this._tokens[this._current+1].type===p.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){const t=this._optional_paren_expression(),i=this._compound_statement();return e.push(this._updateNode(new s0(t,i))),this._match_elseif()&&(this._check(p.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(p.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new au(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(p.tokens.or_or);)e=this._updateNode(new ct(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(p.tokens.and_and);)e=this._updateNode(new ct(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(p.tokens.or);)e=this._updateNode(new ct(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(p.tokens.xor);)e=this._updateNode(new ct(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(p.tokens.and);)e=this._updateNode(new ct(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([p.tokens.equal_equal,p.tokens.not_equal])?this._updateNode(new ct(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([p.tokens.less_than,p.tokens.greater_than,p.tokens.less_than_equal,p.tokens.greater_than_equal]);)e=this._updateNode(new ct(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([p.tokens.shift_left,p.tokens.shift_right]);)e=this._updateNode(new ct(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([p.tokens.plus,p.tokens.minus]);)e=this._updateNode(new ct(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([p.tokens.star,p.tokens.forward_slash,p.tokens.modulo]);)e=this._updateNode(new ct(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([p.tokens.minus,p.tokens.bang,p.tokens.tilde,p.tokens.star,p.tokens.and])?this._updateNode(new Se(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){const e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(p.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(p.tokens.bracket_right,"Expected ']'.");const t=this._updateNode(new _n(e)),i=this._postfix_expression();return i&&(t.postfix=i),t}if(this._match(p.tokens.period)){const e=this._consume(p.tokens.name,"Expected member name."),t=this._postfix_expression(),i=this._updateNode(new jt(e.lexeme));return t&&(i.postfix=t),i}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){const t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return k.void;case"bool":return k.bool;case"i32":return k.i32;case"u32":return k.u32;case"f32":return k.f32;case"f16":return k.f16;case"vec2f":return T.vec2f;case"vec3f":return T.vec3f;case"vec4f":return T.vec4f;case"vec2i":return T.vec2i;case"vec3i":return T.vec3i;case"vec4i":return T.vec4i;case"vec2u":return T.vec2u;case"vec3u":return T.vec3u;case"vec4u":return T.vec4u;case"vec2h":return T.vec2h;case"vec3h":return T.vec3h;case"vec4h":return T.vec4h;case"mat2x2f":return T.mat2x2f;case"mat2x3f":return T.mat2x3f;case"mat2x4f":return T.mat2x4f;case"mat3x2f":return T.mat3x2f;case"mat3x3f":return T.mat3x3f;case"mat3x4f":return T.mat3x4f;case"mat4x2f":return T.mat4x2f;case"mat4x3f":return T.mat4x3f;case"mat4x4f":return T.mat4x4f;case"mat2x2h":return T.mat2x2h;case"mat2x3h":return T.mat2x3h;case"mat2x4h":return T.mat2x4h;case"mat3x2h":return T.mat3x2h;case"mat3x3h":return T.mat3x3h;case"mat3x4h":return T.mat3x4h;case"mat4x2h":return T.mat4x2h;case"mat4x3h":return T.mat4x3h;case"mat4x4h":return T.mat4x4h;case"mat2x2i":return T.mat2x2i;case"mat2x3i":return T.mat2x3i;case"mat2x4i":return T.mat2x4i;case"mat3x2i":return T.mat3x2i;case"mat3x3i":return T.mat3x3i;case"mat3x4i":return T.mat3x4i;case"mat4x2i":return T.mat4x2i;case"mat4x3i":return T.mat4x3i;case"mat4x4i":return T.mat4x4i;case"mat2x2u":return T.mat2x2u;case"mat2x3u":return T.mat2x3u;case"mat2x4u":return T.mat2x4u;case"mat3x2u":return T.mat3x2u;case"mat3x3u":return T.mat3x3u;case"mat3x4u":return T.mat3x4u;case"mat4x2u":return T.mat4x2u;case"mat4x3u":return T.mat4x3u;case"mat4x4u":return T.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(p.tokens.ident)){const i=this._previous().toString();if(this._check(p.tokens.paren_left)){const r=this._argument_expression_list(),s=this._getType(i);return s!==null?this._updateNode(new gt(s,r)):this._updateNode(new go(i,r))}if(this._context.constants.has(i)){const r=this._context.constants.get(i);return this._updateNode(new hu(i,r.value))}return this._updateNode(new Ze(i))}if(this._match(p.tokens.int_literal)){const i=this._previous().toString();let r=i.endsWith("i")||i.endsWith("i")?k.i32:i.endsWith("u")||i.endsWith("U")?k.u32:k.x32;const s=parseInt(i);return this._validateTypeRange(s,r),this._updateNode(new Ae(new v(s,this._exec.getTypeInfo(r)),r))}if(this._match(p.tokens.uint_literal)){const i=parseInt(this._previous().toString());return this._validateTypeRange(i,k.u32),this._updateNode(new Ae(new v(i,this._exec.getTypeInfo(k.u32)),k.u32))}if(this._match([p.tokens.decimal_float_literal,p.tokens.hex_float_literal])){let i=this._previous().toString(),r=i.endsWith("h");r&&(i=i.substring(0,i.length-1));const s=parseFloat(i);this._validateTypeRange(s,r?k.f16:k.f32);const o=r?k.f16:k.f32;return this._updateNode(new Ae(new v(s,this._exec.getTypeInfo(o)),o))}if(this._match([p.keywords.true,p.keywords.false])){let i=this._previous().toString()===p.keywords.true.rule;return this._updateNode(new Ae(new v(i?1:0,this._exec.getTypeInfo(k.bool)),k.bool))}if(this._check(p.tokens.paren_left))return this._paren_expression();if(this._match(p.keywords.bitcast)){this._consume(p.tokens.less_than,"Expected '<'.");const i=this._type_decl();this._consume(p.tokens.greater_than,"Expected '>'.");const r=this._paren_expression();return this._updateNode(new du(i,r))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new gt(e,t))}_argument_expression_list(){if(!this._match(p.tokens.paren_left))return null;const e=[];do{if(this._check(p.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t)}while(this._match(p.tokens.comma));return this._consume(p.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(p.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(p.tokens.paren_right),e}_paren_expression(){this._consume(p.tokens.paren_left,"Expected '('.");const e=this._short_circuit_or_expression();return this._consume(p.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(p.keywords.struct))return null;const e=this._currentLine,t=this._consume(p.tokens.ident,"Expected name for struct.").toString();this._consume(p.tokens.brace_left,"Expected '{' for struct body.");const i=[];for(;!this._check(p.tokens.brace_right);){const o=this._attribute(),a=this._consume(p.tokens.name,"Expected variable name.").toString();this._consume(p.tokens.colon,"Expected ':' for struct member type.");const l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l),this._check(p.tokens.brace_right)?this._match(p.tokens.comma):this._consume(p.tokens.comma,"Expected ',' for struct member."),i.push(this._updateNode(new yu(a,c,o)))}this._consume(p.tokens.brace_right,"Expected '}' after struct body.");const r=this._currentLine,s=this._updateNode(new At(t,i,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){const e=this._variable_decl();if(!e)return null;if(this._match(p.tokens.equal)){const t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof Ae){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof Ae&&(e.type=e.value.type.name==="x32"?k.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){const e=this._override_decl();return e&&this._match(p.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(p.keywords.const))return null;const t=this._consume(p.tokens.name,"Expected variable name"),i=this._currentLine;let r=null;if(this._match(p.tokens.colon)){const l=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=l)}let s=null;this._consume(p.tokens.equal,"const declarations require an assignment");const o=this._short_circuit_or_expression();try{let l=[k.f32],c=o.constEvaluate(this._exec,l);c instanceof v&&this._validateTypeRange(c.value,l[0]),l[0]instanceof T&&l[0].format===null&&c.typeInfo instanceof qt&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?l[0].format=k.f16:c.typeInfo.format.name==="f32"?l[0].format=k.f32:c.typeInfo.format.name==="i32"?l[0].format=k.i32:c.typeInfo.format.name==="u32"?l[0].format=k.u32:c.typeInfo.format.name==="bool"?l[0].format=k.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new Ae(c,l[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=o}if(r!==null&&s instanceof Ae){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof Ae&&(r=(e=s==null?void 0:s.type)!==null&&e!==void 0?e:k.f32,r===k.x32&&(r=k.i32));const a=this._updateNode(new fr(t.toString(),r,"","",s),i);return this._context.constants.set(a.name,a),a}_global_let_decl(){if(!this._match(p.keywords.let))return null;const e=this._currentLine,t=this._consume(p.tokens.name,"Expected variable name");let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}let r=null;if(this._match(p.tokens.equal)&&(r=this._const_expression()),i!==null&&r instanceof Ae){if(r.type.name!=="x32"&&i.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${i.name}. Line:${this._currentLine}`);r.type=i}else i===null&&r instanceof Ae&&(i=r.type.name==="x32"?k.i32:r.type);return r instanceof Ae&&r.isScalar&&this._validateTypeRange(r.scalarValue,i),this._updateNode(new Kn(t.toString(),i,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(p.keywords.var))return null;const e=this._currentLine;let t="",i="";this._match(p.tokens.less_than)&&(t=this._consume(p.storage_class,"Expected storage_class.").toString(),this._match(p.tokens.comma)&&(i=this._consume(p.access_mode,"Expected access_mode.").toString()),this._consume(p.tokens.greater_than,"Expected '>'."));const r=this._consume(p.tokens.name,"Expected variable name");let s=null;if(this._match(p.tokens.colon)){const o=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=o)}return this._updateNode(new wt(r.toString(),s,t,i,null),e)}_override_decl(){if(!this._match(p.keywords.override))return null;const e=this._consume(p.tokens.name,"Expected variable name");let t=null;if(this._match(p.tokens.colon)){const i=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=i)}return this._updateNode(new ho(e.toString(),t,null))}_diagnostic(){this._consume(p.tokens.paren_left,"Expected '('");const e=this._consume(p.tokens.ident,"Expected severity control name.");this._consume(p.tokens.comma,"Expected ','");let t=this._consume(p.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(p.tokens.period)&&(t+=`.${this._consume(p.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(p.tokens.paren_right,"Expected ')'"),this._updateNode(new lu(e.toString(),t))}_enable_directive(){const e=this._consume(p.tokens.ident,"identity expected.");return this._updateNode(new n0(e.toString()))}_requires_directive(){const e=[this._consume(p.tokens.ident,"identity expected.").toString()];for(;this._match(p.tokens.comma);){const t=this._consume(p.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new i0(e))}_type_alias(){const e=this._consume(p.tokens.ident,"identity expected.");this._consume(p.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);const i=this._updateNode(new mo(e.toString(),t));return this._context.aliases.set(i.name,i),i}_type_decl(){if(this._check([p.tokens.ident,...p.texel_format,p.keywords.bool,p.keywords.f32,p.keywords.i32,p.keywords.u32])){const i=this._advance().toString();if(this._context.structs.has(i))return this._context.structs.get(i);if(this._context.aliases.has(i))return this._context.aliases.get(i).type;if(!this._getType(i)){const r=this._updateNode(new fu(i));return this._forwardTypeCount++,r}return this._updateNode(new k(i))}let e=this._texture_sampler_types();if(e)return e;if(this._check(p.template_types)){let i=this._advance().toString(),r=null,s=null;return this._match(p.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(p.tokens.comma)&&(s=this._consume(p.access_mode,"Expected access_mode for pointer").toString()),this._consume(p.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new T(i,r,s))}if(this._match(p.keywords.ptr)){let i=this._previous().toString();this._consume(p.tokens.less_than,"Expected '<' for pointer.");const r=this._consume(p.storage_class,"Expected storage_class for pointer");this._consume(p.tokens.comma,"Expected ',' for pointer.");const s=this._type_decl();let o=null;return this._match(p.tokens.comma)&&(o=this._consume(p.access_mode,"Expected access_mode for pointer").toString()),this._consume(p.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new hr(i,r.toString(),s,o))}const t=this._attribute();if(this._match(p.keywords.array)){let i=null,r=-1;const s=this._previous();let o=null;if(this._match(p.tokens.less_than)){i=this._type_decl(),this._context.aliases.has(i.name)&&(i=this._context.aliases.get(i.name).type);let l="";if(this._match(p.tokens.comma)){o=this._shift_expression();try{l=o.constEvaluate(this._exec).toString(),o=null}catch{l="1"}}this._consume(p.tokens.greater_than,"Expected '>' for array."),r=l?parseInt(l):0}const a=this._updateNode(new Qn(s.toString(),t,i,r));return o&&this._deferArrayCountEval.push({arrayType:a,countNode:o}),a}return null}_texture_sampler_types(){if(this._match(p.sampler_type))return this._updateNode(new Jn(this._previous().toString(),null,null));if(this._match(p.depth_texture_type))return this._updateNode(new Jn(this._previous().toString(),null,null));if(this._match(p.sampled_texture_type)||this._match(p.multisampled_texture_type)){const e=this._previous();this._consume(p.tokens.less_than,"Expected '<' for sampler type.");const t=this._type_decl();return this._consume(p.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Jn(e.toString(),t,null))}if(this._match(p.storage_texture_type)){const e=this._previous();this._consume(p.tokens.less_than,"Expected '<' for sampler type.");const t=this._consume(p.texel_format,"Invalid texel format.").toString();this._consume(p.tokens.comma,"Expected ',' after texel format.");const i=this._consume(p.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(p.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Jn(e.toString(),t,i))}return null}_attribute(){let e=[];for(;this._match(p.tokens.attr);){const t=this._consume(p.attribute_name,"Expected attribute name"),i=this._updateNode(new vu(t.toString(),null));if(this._match(p.tokens.paren_left)){if(i.value=this._consume(p.literal_or_ident,"Expected attribute value").toString(),this._check(p.tokens.comma)){this._advance();do{const r=this._consume(p.literal_or_ident,"Expected attribute value").toString();i.value instanceof Array||(i.value=[i.value]),i.value.push(r)}while(this._match(p.tokens.comma))}this._consume(p.tokens.paren_right,"Expected ')'")}e.push(i)}return e.length==0?null:e}}class y0 extends _t{constructor(e){super(),e&&this.update(e)}update(e){const t=new x0().parse(e);this.updateAST(t)}}function v0(n){var s;const e={attributes:[],bindings:[]};let t;try{t=b0(n)}catch(o){return D.error(o.message)(),e}for(const o of t.uniforms){const a=[];for(const l of((s=o.type)==null?void 0:s.members)||[])a.push({name:l.name,type:Tu(l.type)});e.bindings.push({type:"uniform",name:o.name,group:o.group,location:o.binding,members:a})}for(const o of t.textures)e.bindings.push({type:"texture",name:o.name,group:o.group,location:o.binding});for(const o of t.samplers)e.bindings.push({type:"sampler",name:o.name,group:o.group,location:o.binding});const i=t.entry.vertex[0],r=(i==null?void 0:i.inputs.length)||0;for(let o=0;o<r;o++){const a=i.inputs[o];if(a.locationType==="location"){const l=Tu(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:l})}}return e}function Tu(n){return n!=null&&n.format?`${n.name}<${n.format.name}>`:n.name}function b0(n){try{return new y0(n)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&(e!=null&&e.message)&&(t+=`: ${e.message} `),typeof e=="object"&&(e!=null&&e.token)&&(t+=e.token.line||""),new Error(t,{cause:e})}}const To={};function xr(n="id"){To[n]=To[n]||1;const e=To[n]++;return`${n}-${e}`}class wu{constructor(e){m(this,"id");m(this,"userData",{});m(this,"topology");m(this,"bufferLayout",[]);m(this,"vertexCount");m(this,"indices");m(this,"attributes");if(this.id=e.id||xr("geometry"),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&L.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){var e;(e=this.indices)==null||e.destroy();for(const t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}}function S0(n,e){if(e instanceof wu)return e;const t=T0(n,e),{attributes:i,bufferLayout:r}=w0(n,e);return new wu({topology:e.topology||"triangle-list",bufferLayout:r,vertexCount:e.vertexCount,indices:t,attributes:i})}function T0(n,e){if(!e.indices)return;const t=e.indices.value;return n.createBuffer({usage:L.INDEX,data:t})}function w0(n,e){const t=[],i={};for(const[s,o]of Object.entries(e.attributes)){let a=s;switch(s){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){i[a]=n.createBuffer({data:o.value,id:`${s}-buffer`});const{value:l,size:c,normalized:u}=o;t.push({name:a,format:Xp(l,c,u)})}}const r=e._calculateVertexCount(e.attributes,e.indices);return{attributes:i,bufferLayout:t,vertexCount:r}}const Mr=class Mr{constructor(e){m(this,"device");m(this,"cachingEnabled");m(this,"destroyPolicy");m(this,"debug");m(this,"_hashCounter",0);m(this,"_hashes",{});m(this,"_renderPipelineCache",{});m(this,"_computePipelineCache",{});this.device=e,this.cachingEnabled=e.props._cachePipelines,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=e.props.debugFactories}static getDefaultPipelineFactory(e){return e._lumaData.defaultPipelineFactory=e._lumaData.defaultPipelineFactory||new Mr(e),e._lumaData.defaultPipelineFactory}get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}createRenderPipeline(e){var o;if(!this.cachingEnabled)return this.device.createRenderPipeline(e);const t={...Wt.defaultProps,...e},i=this._renderPipelineCache,r=this._hashRenderPipeline(t);let s=(o=i[r])==null?void 0:o.pipeline;return s?(i[r].useCount++,this.debug&&D.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${e.id})`)()):(s=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:xr("unnamed-cached")}),s.hash=r,i[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${i[r].useCount}`)()),s}createComputePipeline(e){var o;if(!this.cachingEnabled)return this.device.createComputePipeline(e);const t={...Bi.defaultProps,...e},i=this._computePipelineCache,r=this._hashComputePipeline(t);let s=(o=i[r])==null?void 0:o.pipeline;return s?(i[r].useCount++,this.debug&&D.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${e.id})`)()):(s=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),s.hash=r,i[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${i[r].useCount}`)()),s}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._getCache(e),i=e.hash;t[i].useCount--,t[i].useCount===0?(this._destroyPipeline(e),this.debug&&D.log(3,`${this}: ${e} released and destroyed`)()):t[i].useCount<0?(D.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[i].useCount=0):this.debug&&D.log(3,`${this}: ${e} released, count=${t[i].useCount}`)()}_destroyPipeline(e){const t=this._getCache(e);switch(this.destroyPolicy){case"never":return!1;case"unused":return delete t[e.hash],e.destroy(),!0}}_getCache(e){let t;if(e instanceof Bi&&(t=this._computePipelineCache),e instanceof Wt&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){const{type:t}=this.device,i=this._getHash(e.shader.source);return`${t}/C/${i}`}_hashRenderPipeline(e){const t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,r="-",s=this._getHash(JSON.stringify(e.bufferLayout)),{type:o}=this.device;switch(o){case"webgl":return`${o}/R/${t}/${i}V${r}BL${s}`;case"webgpu":default:const a=this._getHash(JSON.stringify(e.parameters));return`${o}/R/${t}/${i}V${r}T${e.topology}P${a}BL${s}`}}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}};m(Mr,"defaultProps",{...Wt.defaultProps});let wo=Mr;const Fr=class Fr{constructor(e){m(this,"device");m(this,"cachingEnabled");m(this,"destroyPolicy");m(this,"debug");m(this,"_cache",{});this.device=e,this.cachingEnabled=e.props._cacheShaders,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=!0}static getDefaultShaderFactory(e){var t;return(t=e._lumaData).defaultShaderFactory||(t.defaultShaderFactory=new Fr(e)),e._lumaData.defaultShaderFactory}get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}createShader(e){if(!this.cachingEnabled)return this.device.createShader(e);const t=this._hashShader(e);let i=this._cache[t];if(i)i.useCount++,this.debug&&D.log(3,`${this}: Reusing shader ${i.shader.id} count=${i.useCount}`)();else{const r=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=i={shader:r,useCount:1},this.debug&&D.log(3,`${this}: Created new shader ${r.id}`)()}return i.shader}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._hashShader(e),i=this._cache[t];if(i)if(i.useCount--,i.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[t],i.shader.destroy(),this.debug&&D.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.debug&&D.log(3,`${this}: Releasing shader ${e.id} count=${i.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}};m(Fr,"defaultProps",{...Ni.defaultProps});let Ao=Fr;function A0(n,e){var r;const t={},i="Values";if(n.attributes.length===0&&!((r=n.varyings)!=null&&r.length))return{"No attributes or varyings":{[i]:"N/A"}};for(const s of n.attributes)if(s){const o=`${s.location} ${s.name}: ${s.type}`;t[`in ${o}`]={[i]:s.stepMode||"vertex"}}for(const s of n.varyings||[]){const o=`${s.location} ${s.name}`;t[`out ${o}`]={[i]:JSON.stringify(s)}}return t}let Pe=null,Kt=null;function C0(n,{id:e,minimap:t,opaque:i,top:r="0",left:s="0",rgbaScale:o=1}){Pe||(Pe=document.createElement("canvas"),Pe.id=e,Pe.title=e,Pe.style.zIndex="100",Pe.style.position="absolute",Pe.style.top=r,Pe.style.left=s,Pe.style.border="blue 5px solid",Pe.style.transform="scaleY(-1)",document.body.appendChild(Pe),Kt=Pe.getContext("2d")),(Pe.width!==n.width||Pe.height!==n.height)&&(Pe.width=n.width/2,Pe.height=n.height/2,Pe.style.width="400px",Pe.style.height="400px");const a=n.device.readPixelsToArrayWebGL(n),l=Kt==null?void 0:Kt.createImageData(n.width,n.height);if(l){for(let u=0;u<a.length;u+=4)l.data[0+u+0]=a[u+0]*o,l.data[0+u+1]=a[u+1]*o,l.data[0+u+2]=a[u+2]*o,l.data[0+u+3]=i?255:a[u+3]*o;Kt==null||Kt.putImageData(l,0,0)}}function Co(n,e,t){if(n===e)return!0;if(!t||!n||!e)return!1;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let i=0;i<n.length;i++)if(!Co(n[i],e[i],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof n=="object"&&typeof e=="object"){const i=Object.keys(n),r=Object.keys(e);if(i.length!==r.length)return!1;for(const s of i)if(!e.hasOwnProperty(s)||!Co(n[s],e[s],t-1))return!1;return!0}return!1}class Io{constructor(e){m(this,"bufferLayouts");this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(t=>t.name===e)||null}getAttributeNamesForBuffer(e){var t;return e.attributes?(t=e.attributes)==null?void 0:t.map(i=>i.attribute):[e.name]}mergeBufferLayouts(e,t){const i=[...e];for(const r of t){const s=i.findIndex(o=>o.name===r.name);s<0?i.push(r):i[s]=r}return i}getBufferIndex(e){const t=this.bufferLayouts.findIndex(i=>i.name===e);return t===-1&&D.warn(`BufferLayout: Missing buffer for "${e}".`)(),t}}function I0(n,e){const t=Object.fromEntries(n.attributes.map(r=>[r.name,r.location])),i=e.slice();return i.sort((r,s)=>{const o=r.attributes?r.attributes.map(u=>u.attribute):[r.name],a=s.attributes?s.attributes.map(u=>u.attribute):[s.name],l=Math.min(...o.map(u=>t[u])),c=Math.min(...a.map(u=>t[u]));return l-c}),i}function P0(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function E0(n){return Array.isArray(n)?n.length===0||typeof n[0]=="number":!1}function R0(n){return P0(n)||E0(n)}function k0(n){return R0(n)||typeof n=="number"||typeof n=="boolean"}function D0(n){const e={bindings:{},uniforms:{}};return Object.keys(n).forEach(t=>{const i=n[t];k0(i)?e.uniforms[t]=i:e.bindings[t]=i}),e}class M0{constructor(e,t){m(this,"options",{disableWarnings:!1});m(this,"modules");m(this,"moduleUniforms");m(this,"moduleBindings");Object.assign(this.options,t);const i=so(Object.values(e).filter(r=>r.dependencies));for(const r of i)e[r.name]=r;D.log(1,"Creating ShaderInputs with modules",Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(const[r,s]of Object.entries(e))this._addModule(s),s.name&&r!==s.name&&!this.options.disableWarnings&&D.warn(`Module name: ${r} vs ${s.name}`)()}destroy(){}setProps(e){var t;for(const i of Object.keys(e)){const r=i,s=e[r]||{},o=this.modules[r];if(!o){this.options.disableWarnings||D.warn(`Module ${i} not found`)();continue}const a=this.moduleUniforms[r],l=this.moduleBindings[r],c=((t=o.getUniforms)==null?void 0:t.call(o,s,a))||s,{uniforms:u,bindings:f}=D0(c);this.moduleUniforms[r]={...a,...u},this.moduleBindings[r]={...l,...f}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){const e={};for(const t of Object.values(this.moduleBindings))Object.assign(e,t);return e}getDebugTable(){var t;const e={};for(const[i,r]of Object.entries(this.moduleUniforms))for(const[s,o]of Object.entries(r))e[`${i}.${s}`]={type:(t=this.modules[i].uniformTypes)==null?void 0:t[s],value:String(o)};return e}_addModule(e){const t=e.name;this.moduleUniforms[t]=e.defaultUniforms||{},this.moduleBindings[t]={}}}let F0="";async function N0(n,e){const t=new Image;return t.crossOrigin="anonymous",t.src=n.startsWith("http")?n:F0+n,await t.decode(),e?await createImageBitmap(t,e):await createImageBitmap(t)}const O0=["+X","-X","+Y","-Y","+Z","-Z"],B0=["+X","-X","+Y","-Y","+Z","-Z"],Nr=class Nr{constructor(e,t){m(this,"device");m(this,"id");m(this,"props");m(this,"texture");m(this,"sampler");m(this,"view");m(this,"ready");m(this,"isReady",!1);m(this,"destroyed",!1);m(this,"resolveReady",()=>{});m(this,"rejectReady",()=>{});this.device=e;const i=xr("async-texture");this.props={...Nr.defaultProps,id:i,...t},this.id=this.props.id,t={...t},typeof(t==null?void 0:t.data)=="string"&&t.dimension==="2d"&&(t.data=N0(t.data)),t.mipmaps&&(t.mipLevels="auto"),this.ready=new Promise((r,s)=>{this.resolveReady=()=>{this.isReady=!0,r()},this.rejectReady=s}),this.initAsync(t)}get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}async initAsync(e){const t=e.data,i=await Au(t).then(void 0,this.rejectReady);if(this.destroyed)return;const r=this.props.width&&this.props.height?{width:this.props.width,height:this.props.height}:this.getTextureDataSize(i);if(!r)throw new Error("Texture size could not be determined");const s={...r,...e,data:void 0,mipLevels:1},o=this.device.getMipLevelCount(s.width,s.height);if(s.mipLevels=this.props.mipLevels==="auto"?o:Math.min(o,this.props.mipLevels),this.texture=this.device.createTexture(s),this.sampler=this.texture.sampler,this.view=this.texture.view,e.data)switch(this.props.dimension){case"1d":this._setTexture1DData(this.texture,i);break;case"2d":this._setTexture2DData(i);break;case"3d":this._setTexture3DData(this.texture,i);break;case"2d-array":this._setTextureArrayData(this.texture,i);break;case"cube":this._setTextureCubeData(this.texture,i);break;case"cube-array":this._setTextureCubeArrayData(this.texture,i);break}this.props.mipmaps&&this.generateMipmaps(),D.info(1,`${this} loaded`),this.resolveReady()}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}generateMipmaps(){this.texture.generateMipmapsWebGL()}setSampler(e={}){this.texture.setSampler(e instanceof cn?e:this.device.createSampler(e))}resize(e){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(e.width===this.texture.width&&e.height===this.texture.height)return!1;if(this.texture){const t=this.texture;this.texture=t.clone(e),t.destroy()}return!0}isTextureLevelData(e){const t=e==null?void 0:e.data;return ArrayBuffer.isView(t)}getTextureDataSize(e){if(!e||ArrayBuffer.isView(e))return null;if(Array.isArray(e))return this.getTextureDataSize(e[0]);if(this.device.isExternalImage(e))return this.device.getExternalImageSize(e);if(e&&typeof e=="object"&&e.constructor===Object){const i=Object.values(e)[0];return{width:i.width,height:i.height}}throw new Error("texture size deduction failed")}getCubeFaceDepth(e){switch(e){case"+X":return 0;case"-X":return 1;case"+Y":return 2;case"-Y":return 3;case"+Z":return 4;case"-Z":return 5;default:throw new Error(e)}}setTextureData(e){}_setTexture1DData(e,t){throw new Error("setTexture1DData not supported in WebGL.")}_setTexture2DData(e,t=0){if(!this.texture)throw new Error("Texture not initialized");const i=this._normalizeTextureData(e);i.length>1&&this.props.mipmaps!==!1&&D.warn(`Texture ${this.id} mipmap and multiple LODs.`)();for(let r=0;r<i.length;r++){const s=i[r];this.device.isExternalImage(s)?this.texture.copyExternalImage({image:s,depth:t,mipLevel:r,flipY:!0}):this.texture.copyImageData({data:s.data,mipLevel:r})}}_setTexture3DData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="3d")throw new Error(this.id);for(let r=0;r<t.length;r++)this._setTexture2DData(t[r],r)}_setTextureCubeData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="cube")throw new Error(this.id);for(const[r,s]of Object.entries(t)){const o=B0.indexOf(r);this._setTexture2DData(s,o)}}_setTextureArrayData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="2d-array")throw new Error(this.id);for(let r=0;r<t.length;r++)this._setTexture2DData(t[r],r)}_setTextureCubeArrayData(e,t){throw new Error("setTextureCubeArrayData not supported in WebGL2.")}_setTextureCubeFaceData(e,t,i,r=0){Array.isArray(t)&&t.length>1&&this.props.mipmaps!==!1&&D.warn(`${this.id} has mipmap and multiple LODs.`)();const s=O0.indexOf(i);this._setTexture2DData(t,s)}_normalizeTextureData(e){const t=this.texture;let i;return ArrayBuffer.isView(e)?i=[{data:e,width:t.width,height:t.height}]:Array.isArray(e)?i=e:i=[e],i}};m(Nr,"defaultProps",{...Q.defaultProps,data:null,mipmaps:!1});let Gn=Nr;async function Au(n){if(n=await n,Array.isArray(n))return await Promise.all(n.map(Au));if(n&&typeof n=="object"&&n.constructor===Object){const e=n,t=await Promise.all(Object.values(e)),i=Object.keys(e),r={};for(let s=0;s<i.length;s++)r[i[s]]=t[s];return r}return n}const Zt=2,U0=1e4,Or=class Or{constructor(e,t){m(this,"device");m(this,"id");m(this,"source");m(this,"vs");m(this,"fs");m(this,"pipelineFactory");m(this,"shaderFactory");m(this,"userData",{});m(this,"parameters");m(this,"topology");m(this,"bufferLayout");m(this,"isInstanced");m(this,"instanceCount",0);m(this,"vertexCount");m(this,"indexBuffer",null);m(this,"bufferAttributes",{});m(this,"constantAttributes",{});m(this,"bindings",{});m(this,"vertexArray");m(this,"transformFeedback",null);m(this,"pipeline");m(this,"shaderInputs");m(this,"_uniformStore");m(this,"_attributeInfos",{});m(this,"_gpuGeometry",null);m(this,"props");m(this,"_pipelineNeedsUpdate","newly created");m(this,"_needsRedraw","initializing");m(this,"_destroyed",!1);m(this,"_lastDrawTimestamp",-1);m(this,"_lastLogTime",0);m(this,"_logOpen",!1);m(this,"_drawCount",0);var l,c,u,f;this.props={...Or.defaultProps,...t},t=this.props,this.id=t.id||xr("model"),this.device=e,Object.assign(this.userData,t.userData);const i=Object.fromEntries(((l=this.props.modules)==null?void 0:l.map(h=>[h.name,h]))||[]),r=t.shaderInputs||new M0(i,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);const s=L0(e),o=(((c=this.props.modules)==null?void 0:c.length)>0?this.props.modules:(u=this.shaderInputs)==null?void 0:u.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){const{source:h,getUniforms:d}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:s,...this.props,modules:o});this.source=h,this._getModuleUniforms=d,(f=this.props).shaderLayout||(f.shaderLayout=v0(this.source))}else{const{vs:h,fs:d,getUniforms:_}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:s,...this.props,modules:o});this.vs=h,this.fs=d,this._getModuleUniforms=_}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,t.geometry&&this.setGeometry(t.geometry),this.pipelineFactory=t.pipelineFactory||wo.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||Ao.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in t&&(this.isInstanced=t.isInstanced),t.instanceCount&&this.setInstanceCount(t.instanceCount),t.vertexCount&&this.setVertexCount(t.vertexCount),t.indexBuffer&&this.setIndexBuffer(t.indexBuffer),t.attributes&&this.setAttributes(t.attributes),t.constantAttributes&&this.setConstantAttributes(t.constantAttributes),t.bindings&&this.setBindings(t.bindings),t.transformFeedback&&(this.transformFeedback=t.transformFeedback),Object.seal(this)}get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}destroy(){var e;this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),(e=this._gpuGeometry)==null||e.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");const e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||(this._needsRedraw=e)}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(e){const t=this._areBindingsLoading();if(t)return D.info(Zt,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;try{e.pushDebugGroup(`${this}.predraw(${e})`),this.predraw()}finally{e.popDebugGroup()}let i;try{e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();const r=this._getBindings();this.pipeline.setBindings(r,{disableWarnings:this.props.disableWarnings});const{indexBuffer:s}=this.vertexArray,o=s?s.byteLength/(s.indexType==="uint32"?4:2):void 0;i=this.pipeline.draw({renderPass:e,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),i?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",i}setGeometry(e){var i;(i=this._gpuGeometry)==null||i.destroy();const t=e&&S0(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");const r=new Io(this.bufferLayout);this.bufferLayout=r.mergeBufferLayouts(t.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(t)}this._gpuGeometry=t}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(e){const t=new Io(this.bufferLayout);this.bufferLayout=this._gpuGeometry?t.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(e){Co(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw("vertexCount")}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new xe(this.shaderInputs.modules);for(const[t,i]of Object.entries(this.shaderInputs.modules))if(z0(i)){const r=this._uniformStore.getManagedUniformBuffer(this.device,t);this.bindings[`${t}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw("bindings")}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(e){this.vertexArray.setIndexBuffer(e),this.setNeedsRedraw("indexBuffer")}setAttributes(e,t){const i=(t==null?void 0:t.disableWarnings)??this.props.disableWarnings;e.indices&&D.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=I0(this.pipeline.shaderLayout,this.bufferLayout);const r=new Io(this.bufferLayout);for(const[s,o]of Object.entries(e)){const a=r.getBufferLayout(s);if(!a){i||D.warn(`Model(${this.id}): Missing layout for buffer "${s}".`)();continue}const l=r.getAttributeNamesForBuffer(a);let c=!1;for(const u of l){const f=this._attributeInfos[u];if(f){const h=this.device.type==="webgpu"?r.getBufferIndex(f.bufferName):f.location;this.vertexArray.setBuffer(h,o),c=!0}}!c&&!i&&D.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${s}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(const[i,r]of Object.entries(e)){const s=this._attributeInfos[i];s?this.vertexArray.setConstantWebGL(s.location,r):((t==null?void 0:t.disableWarnings)??this.props.disableWarnings)||D.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${i}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(const e of Object.values(this.bindings))if(e instanceof Gn&&!e.isReady)return e.id;return!1}_getBindings(){const e={};for(const[t,i]of Object.entries(this.bindings))i instanceof Gn?i.isReady&&(e[t]=i.texture):e[t]=i;return e}_getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof Fi?e=Math.max(e,t.texture.updateTimestamp):t instanceof L||t instanceof Q?e=Math.max(e,t.updateTimestamp):t instanceof Gn?e=t.texture?Math.max(e,t.texture.updateTimestamp):1/0:t instanceof cn||(e=Math.max(e,t.buffer.updateTimestamp));return e}_setGeometryAttributes(e){const t={...e.attributes};for(const[i]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(r=>r.name===i)&&i!=="positions"&&delete t[i];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(t,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||(this._pipelineNeedsUpdate=e),this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,t=null;this.pipeline&&(D.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,t=this.pipeline.fs),this._pipelineNeedsUpdate=!1;const i=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders});let r=null;this.source?r=i:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:i,fs:r}),this._attributeInfos=Ka(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),t&&this.shaderFactory.release(t)}return this.pipeline}_logDrawCallStart(){const e=D.level>3?0:U0;D.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,D.group(Zt,`>>> DRAWING MODEL ${this.id}`,{collapsed:D.level<=2})())}_logDrawCallEnd(){if(this._logOpen){const e=A0(this.pipeline.shaderLayout,this.id);D.table(Zt,e)();const t=this.shaderInputs.getDebugTable();D.table(Zt,t)();const i=this._getAttributeDebugTable();D.table(Zt,this._attributeInfos)(),D.table(Zt,i)(),D.groupEnd(Zt)(),this._logOpen=!1}}_logFramebuffer(e){const t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;const i=e.props.framebuffer;i&&C0(i,{id:i.id,minimap:!0})}_getAttributeDebugTable(){const e={};for(const[t,i]of Object.entries(this._attributeInfos)){const r=this.vertexArray.attributes[i.location];e[i.location]={name:t,type:i.shaderType,values:r?this._getBufferOrConstantValues(r,i.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){const{indexBuffer:t}=this.vertexArray,i=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:i.toString()}}return e}_getBufferOrConstantValues(e,t){const i=La(t);return(e instanceof L?new i(e.debugData):e).toString()}};m(Or,"defaultProps",{...Wt.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:ao.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});let me=Or;function z0(n){return!!(n.uniformTypes&&!V0(n.uniformTypes))}function L0(n){return{type:n.type,shaderLanguage:n.info.shadingLanguage,shaderLanguageVersion:n.info.shadingLanguageVersion,gpu:n.info.gpu,features:n.features}}function V0(n){for(const e in n)return!1;return!0}class Nt{constructor(e,t,i,r,s){this._debugRandomNumber=Math.floor(Math.random()*1e3),this.device=e,this.config=t,this.store=i,this.data=r,s&&(this.points=s)}}const H0=`#version 300 es
96
+ `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){const t=this._source.substring(this._start,this._current);this._tokens.push(new mu(e,t,this._line,this._start,this._current))}}function z(n){return Array.isArray(n)||(n==null?void 0:n.buffer)instanceof ArrayBuffer}const pr=new Float32Array(1),n0=new Uint32Array(pr.buffer),i0=new Uint32Array(pr.buffer),mr=new Int32Array(1),r0=new Float32Array(mr.buffer),s0=new Uint32Array(mr.buffer),gr=new Uint32Array(1),o0=new Float32Array(gr.buffer),a0=new Int32Array(gr.buffer);function gu(n,e,t){if(e===t)return n;if(e==="f32"){if(t==="i32"||t==="x32")return pr[0]=n,n0[0];if(t==="u32")return pr[0]=n,i0[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return mr[0]=n,r0[0];if(t==="u32")return mr[0]=n,s0[0]}else if(e==="u32"){if(t==="f32")return gr[0]=n,o0[0];if(t==="i32"||t==="x32")return gr[0]=n,a0[0]}return console.error(`Unsupported cast from ${e} to ${t}`),n}class l0{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class _r{constructor(e,t){this.align=e,this.size=t}}class _t{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new $y,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(const t of e)t instanceof Kn&&this._functions.set(t.name,new l0(t));for(const t of e)if(t instanceof Ct){const i=this.getTypeInfo(t,null);i instanceof Ft&&this.structs.push(i)}for(const t of e)if(t instanceof _o)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof mo){const i=t,r=this._getAttributeNum(i.attributes,"id",0),s=i.type!=null?this.getTypeInfo(i.type,i.attributes):null;this.overrides.push(new Vy(i.name,s,i.attributes,r));continue}if(this._isUniformVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=new lr(i.name,o,r,s,i.attributes,Nt.Uniform,i.access);a.access||(a.access="read"),this.uniforms.push(a);continue}if(this._isStorageVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=this._isStorageTexture(o),l=new lr(i.name,o,r,s,i.attributes,a?Nt.StorageTexture:Nt.Storage,i.access);l.access||(l.access="read"),this.storage.push(l);continue}if(this._isTextureVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=this._isStorageTexture(o),l=new lr(i.name,o,r,s,i.attributes,a?Nt.StorageTexture:Nt.Texture,i.access);l.access||(l.access="read"),a?this.storage.push(l):this.textures.push(l);continue}if(this._isSamplerVar(t)){const i=t,r=this._getAttributeNum(i.attributes,"group",0),s=this._getAttributeNum(i.attributes,"binding",0),o=this.getTypeInfo(i.type,i.attributes),a=new lr(i.name,o,r,s,i.attributes,Nt.Sampler,i.access);this.samplers.push(a);continue}}for(const t of e)if(t instanceof Kn){const i=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),o=i||r||s,a=new Wy(t.name,o==null?void 0:o.name,t.attributes);a.attributes=t.attributes,a.startLine=t.startLine,a.endLine=t.endLine,this.functions.push(a),this._functions.get(t.name).info=a,o&&(this._functions.get(t.name).inUse=!0,a.inUse=!0,a.resources=this._findResources(t,!!o),a.inputs=this._getInputs(t.args),a.outputs=this._getOutputs(t.returnType),this.entry[o.name].push(a)),a.arguments=t.args.map(l=>new Hy(l.name,this.getTypeInfo(l.type,l.attributes),l.attributes)),a.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}for(const t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(const t of this._functions.values())t.node.search(i=>{var r,s,o;if(i instanceof pu){if(i.value)if(z(i.value))for(const a of i.value)for(const l of this.overrides)a===l.name&&((r=t.info)===null||r===void 0||r.overrides.push(l));else for(const a of this.overrides)i.value===a.name&&((s=t.info)===null||s===void 0||s.overrides.push(a))}else if(i instanceof Qe)for(const a of this.overrides)i.name===a.name&&((o=t.info)===null||o===void 0||o.overrides.push(a))});for(const t of this.uniforms)this._markStructsInUse(t.type);for(const t of this.storage)this._markStructsInUse(t.type)}getFunctionInfo(e){for(const t of this.functions)if(t.name==e)return t;return null}getStructInfo(e){for(const t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(const t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(const t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{const t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var i;for(const r of e.calls){const s=(i=this._functions.get(r.name))===null||i===void 0?void 0:i.info;s&&t.add(s)}}findResource(e,t,i){if(i){for(const r of this.entry.compute)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}for(const r of this.entry.vertex)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}for(const r of this.entry.fragment)if(r.name===i){for(const s of r.resources)if(s.group==e&&s.binding==t)return s}}for(const r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(const r of this.storage)if(r.group==e&&r.binding==t)return r;for(const r of this.textures)if(r.group==e&&r.binding==t)return r;for(const r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(const t of this.uniforms)if(t.name==e)return t;for(const t of this.storage)if(t.name==e)return t;for(const t of this.textures)if(t.name==e)return t;for(const t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){const t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){const i=[],r=this,s=[];return e.search(o=>{if(o instanceof cr)s.push({});else if(o instanceof ur)s.pop();else if(o instanceof At){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type),s.length>0&&(s[s.length-1][a.name]=a)}else if(o instanceof gt){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type)}else if(o instanceof Zn){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type),s.length>0&&(s[s.length-1][a.name]=a)}else if(o instanceof Qe){const a=o;if(s.length>0&&s[s.length-1][a.name])return;const l=r._findResource(a.name);l&&i.push(l)}else if(o instanceof xo){const a=o,l=r._functions.get(a.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),i.push(...l.resources))}else if(o instanceof go){const a=o,l=r._functions.get(a.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),i.push(...l.resources))}}),[...new Map(i.map(o=>[o.name,o])).values()]}getBindGroups(){const e=[];function t(i,r){i>=e.length&&(e.length=i+1),e[i]===void 0&&(e[i]=[]),r>=e[i].length&&(e[i].length=r+1)}for(const i of this.uniforms)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.storage)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.textures)t(i.group,i.binding),e[i.group][i.binding]=i;for(const i of this.samplers)t(i.group,i.binding),e[i.group][i.binding]=i;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof Ct)this._getStructOutputs(e,t);else{const i=this._getOutputInfo(e);i!==null&&t.push(i)}return t}_getStructOutputs(e,t){for(const i of e.members)if(i.type instanceof Ct)this._getStructOutputs(i.type,t);else{const r=this._getAttribute(i,"location")||this._getAttribute(i,"builtin");if(r!==null){const s=this.getTypeInfo(i.type,i.type.attributes),o=this._parseInt(r.value),a=new Wc(i.name,s,r.name,o);t.push(a)}}}_getOutputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const i=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new Wc("",i,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(const i of e)if(i.type instanceof Ct)this._getStructInputs(i.type,t);else{const r=this._getInputInfo(i);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(const i of e.members)if(i.type instanceof Ct)this._getStructInputs(i.type,t);else{const r=this._getInputInfo(i);r!==null&&t.push(r)}}_getInputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const i=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),o=new Ly(e.name,r,t.name,s);return i!==null&&(o.interpolation=this._parseString(i.value)),o}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);const t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(const t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new zy(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(const t of this.structs)if(t.name==e)return t;for(const t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof hr){const r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new uo(e.name,r,t);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Jn){const r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,o=new Mt(r.name,t);return o.format=s,o.count=r.count,this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Ct){const r=e,s=new Ft(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(const o of r.members){const a=this.getTypeInfo(o.type,o.attributes);s.members.push(new Hc(o.name,a,o.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Gn){const r=e,s=r.format instanceof k,o=r.format?s?this.getTypeInfo(r.format,null):new Ge(r.format,null):null,a=new jt(r.name,o,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof T){const r=e,s=r.format?this.getTypeInfo(r.format,null):null,o=new jt(r.name,s,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}const i=new Ge(e.name,t);return this._types.set(e,i),this._updateTypeInfo(i),i}_updateTypeInfo(e){var t,i,r;const s=this._getTypeSize(e);if(e.size=(t=s==null?void 0:s.size)!==null&&t!==void 0?t:0,e instanceof Mt&&e.format){const o=this._getTypeSize(e.format);e.stride=Math.max((i=o==null?void 0:o.size)!==null&&i!==void 0?i:0,(r=o==null?void 0:o.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof uo&&this._updateTypeInfo(e.format),e instanceof Ft&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let i=0,r=0,s=0,o=0;for(let a=0,l=e.members.length;a<l;++a){const c=e.members[a],u=this._getTypeSize(c);if(!u)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;const f=u.align,h=u.size;i=this._roundUp(f,i+r),r=h,s=i,o=Math.max(o,f),c.offset=i,c.size=h,this._updateTypeInfo(c.type)}e.size=this._roundUp(o,s+r),e.align=o}_getTypeSize(e){var t,i;if(e==null)return null;const r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof Hc&&(e=e.type),e instanceof Ge){const o=this._getAlias(e.name);o!==null&&(e=o)}{const o=_t._typeInfo[e.name];if(o!==void 0){const a=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new _r(Math.max(s,o.align/a),Math.max(r,o.size/a))}}{const o=_t._typeInfo[e.name.substring(0,e.name.length-1)];if(o){const a=e.name[e.name.length-1]==="h"?2:1;return new _r(Math.max(s,o.align/a),Math.max(r,o.size/a))}}if(e instanceof Mt){let o=e,a=8,l=8;const c=this._getTypeSize(o.format);return c!==null&&(l=c.size,a=c.align),l=o.count*this._getAttributeNum((i=e==null?void 0:e.attributes)!==null&&i!==void 0?i:null,"stride",this._roundUp(a,l)),r&&(l=r),new _r(Math.max(s,a),Math.max(r,l))}if(e instanceof Ft){let o=0,a=0,l=0,c=0,u=0;for(const f of e.members){const h=this._getTypeSize(f.type);h!==null&&(o=Math.max(h.align,o),l=this._roundUp(h.align,l+c),c=h.size,u=l)}return a=this._roundUp(o,u+c),new _r(Math.max(s,o),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof At&&e.storage=="uniform"}_isStorageVar(e){return e instanceof At&&e.storage=="storage"}_isTextureVar(e){return e instanceof At&&e.type!==null&&_t._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof At&&e.type!==null&&_t._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){const i=e;if(!i||!i.attributes)return null;const r=i.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,i){if(e===null)return i;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:i;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):i}return i}_roundUp(e,t){return Math.ceil(t/e)*e}}_t._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},_t._textureTypes=p.any_texture_type.map(n=>n.name),_t._samplerTypes=p.sampler_type.map(n=>n.name);let vo=0;class bo{constructor(e,t,i){this.id=vo++,this.name=e,this.value=t,this.node=i}clone(){return new bo(this.name,this.value,this.node)}}class So{constructor(e){this.id=vo++,this.name=e.name,this.node=e}clone(){return new So(this.node)}}class To{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=vo++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?(t=this.variables.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?(t=this.functions.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,i){this.variables.set(e,new bo(e,t,i??null))}setVariable(e,t,i){const r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,i)}getVariableValue(e){var t;const i=this.getVariable(e);return(t=i==null?void 0:i.value)!==null&&t!==void 0?t:null}clone(){return new To(this)}}class c0{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class u0{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const i=this.exec.evalExpression(e.args[0],t);let r=!0;if(i instanceof g)return i.data.forEach(s=>{s||(r=!1)}),new v(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){const r=i.data.some(s=>s);return new v(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){const i=this.exec.evalExpression(e.args[2],t);if(!(i instanceof v))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return i.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.evalExpression(i,t);if(r instanceof ye&&r.typeInfo.size===0){const s=r.typeInfo,o=r.buffer.byteLength/s.stride;return new v(o,this.getTypeInfo("u32"))}return new v(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.abs(s)),i.typeInfo);const r=i;return new v(Math.abs(r.value),r.typeInfo)}Acos(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.acos(s)),i.typeInfo);const r=i;return new v(Math.acos(r.value),i.typeInfo)}Acosh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.acosh(s)),i.typeInfo);const r=i;return new v(Math.acosh(r.value),i.typeInfo)}Asin(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.asin(s)),i.typeInfo);const r=i;return new v(Math.asin(r.value),i.typeInfo)}Asinh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.asinh(s)),i.typeInfo);const r=i;return new v(Math.asinh(r.value),i.typeInfo)}Atan(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.atan(s)),i.typeInfo);const r=i;return new v(Math.atan(r.value),i.typeInfo)}Atanh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.atanh(s)),i.typeInfo);const r=i;return new v(Math.atanh(r.value),i.typeInfo)}Atan2(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.atan2(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.atan2(s.value,o.value),i.typeInfo)}Ceil(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.ceil(s)),i.typeInfo);const r=i;return new v(Math.ceil(r.value),i.typeInfo)}_clamp(e,t,i){return Math.min(Math.max(e,t),i)}Clamp(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return new g(i.data.map((c,u)=>this._clamp(c,r.data[u],s.data[u])),i.typeInfo);const o=i,a=r,l=s;return new v(this._clamp(o.value,a.value,l.value),i.typeInfo)}Cos(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.cos(s)),i.typeInfo);const r=i;return new v(Math.cos(r.value),i.typeInfo)}Cosh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.cosh(s)),i.typeInfo);const r=i;return new v(Math.cos(r.value),i.typeInfo)}CountLeadingZeros(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.clz32(s)),i.typeInfo);const r=i;return new v(Math.clz32(r.value),i.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._countOneBits(s)),i.typeInfo);const r=i;return new v(this._countOneBits(r.value),i.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._countTrailingZeros(s)),i.typeInfo);const r=i;return new v(this._countTrailingZeros(r.value),i.typeInfo)}Cross(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){if(i.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;const s=i.data,o=r.data;return new g([s[1]*o[2]-o[1]*s[2],s[2]*o[0]-o[2]*s[0],s[0]*o[1]-o[0]*s[1]],i.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){const i=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return i instanceof g?new g(i.data.map(s=>s*r),i.typeInfo):new v(i.value*r,this.getTypeInfo("f32"))}Determinant(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof j){const r=i.data,s=i.typeInfo.getTypeName(),o=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new v(r[0]*r[3]-r[1]*r[2],o);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new v(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),o);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new v(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),o);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){let a=0;for(let l=0;l<i.data.length;++l)a+=(i.data[l]-r.data[l])*(i.data[l]-r.data[l]);return new v(Math.sqrt(a),this.getTypeInfo("f32"))}const s=i,o=r;return new v(Math.abs(s.value-o.value),i.typeInfo)}_dot(e,t){let i=0;for(let r=0;r<e.length;++r)i+=t[r]*e[r];return i}Dot(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return i instanceof g&&r instanceof g?new v(this._dot(i.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.exp(s)),i.typeInfo);const r=i;return new v(Math.exp(r.value),i.typeInfo)}Exp2(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.pow(2,s)),i.typeInfo);const r=i;return new v(Math.pow(2,r.value),i.typeInfo)}ExtractBits(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;const o=r.value,a=s.value;if(i instanceof g)return new g(i.data.map(c=>c>>o&(1<<a)-1),i.typeInfo);if(i.typeInfo.name!=="i32"&&i.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;const l=i.value;return new v(l>>o&(1<<a)-1,this.getTypeInfo("i32"))}FaceForward(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g){const o=this._dot(r.data,s.data);return new g(o<0?Array.from(i.data):i.data.map(a=>-a),i.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._firstLeadingBit(s)),i.typeInfo);const r=i;return new v(this._firstLeadingBit(r.value),i.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>this._firstTrailingBit(s)),i.typeInfo);const r=i;return new v(this._firstTrailingBit(r.value),i.typeInfo)}Floor(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.floor(s)),i.typeInfo);const r=i;return new v(Math.floor(r.value),i.typeInfo)}Fma(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return i.data.length!==r.data.length||i.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new g(i.data.map((c,u)=>c*r.data[u]+s.data[u]),i.typeInfo);const o=i,a=r,l=s;return new v(o.value*a.value+l.value,o.typeInfo)}Fract(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>s-Math.floor(s)),i.typeInfo);const r=i;return new v(r.value-Math.floor(r.value),i.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),o=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;const a=s.value,l=(1<<o.value)-1<<a,c=~l;if(i instanceof g&&r instanceof g)return new g(i.data.map((h,d)=>h&c|r.data[d]<<a&l),i.typeInfo);const u=i.value,f=r.value;return new v(u&c|f<<a&l,i.typeInfo)}InverseSqrt(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>1/Math.sqrt(s)),i.typeInfo);const r=i;return new v(1/Math.sqrt(r.value),i.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){let s=0;return i.data.forEach(o=>{s+=o*o}),new v(Math.sqrt(s),this.getTypeInfo("f32"))}const r=i;return new v(Math.abs(r.value),i.typeInfo)}Log(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.log(s)),i.typeInfo);const r=i;return new v(Math.log(r.value),i.typeInfo)}Log2(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.log2(s)),i.typeInfo);const r=i;return new v(Math.log2(r.value),i.typeInfo)}Max(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.max(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.max(s.value,o.value),i.typeInfo)}Min(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.min(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.min(s.value,o.value),i.typeInfo)}Mix(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof g)return new g(i.data.map((l,c)=>i.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),i.typeInfo);const o=r,a=s;return new v(i.value*(1-a.value)+o.value*a.value,i.typeInfo)}Modf(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((o,a)=>o%r.data[a]),i.typeInfo);const s=r;return new v(i.value%s.value,i.typeInfo)}Normalize(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g){const r=this.Length(e,t).value;return new g(i.data.map(s=>s/r),i.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g)return new g(i.data.map((a,l)=>Math.pow(a,r.data[l])),i.typeInfo);const s=i,o=r;return new v(Math.pow(s.value,o.value),i.typeInfo)}QuantizeToF16(e,t){const i=this.exec.evalExpression(e.args[0],t);return i instanceof g?new g(i.data.map(r=>r),i.typeInfo):new v(i.value,i.typeInfo)}Radians(e,t){const i=this.exec.evalExpression(e.args[0],t);return i instanceof g?new g(i.data.map(r=>r*Math.PI/180),i.typeInfo):new v(i.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(i instanceof g&&r instanceof g){const s=this._dot(i.data,r.data);return new g(i.data.map((o,a)=>o-2*s*r.data[a]),i.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(i instanceof g&&r instanceof g&&s instanceof v){const o=this._dot(r.data,i.data);return new g(i.data.map((a,l)=>{const c=1-s.value*s.value*(1-o*o);if(c<0)return 0;const u=Math.sqrt(c);return s.value*a-(s.value*o+u)*r.data[l]}),i.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.round(s)),i.typeInfo);const r=i;return new v(Math.round(r.value),i.typeInfo)}Saturate(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.min(Math.max(s,0),1)),i.typeInfo);const r=i;return new v(Math.min(Math.max(r.value,0),1),i.typeInfo)}Sign(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sign(s)),i.typeInfo);const r=i;return new v(Math.sign(r.value),i.typeInfo)}Sin(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sin(s)),i.typeInfo);const r=i;return new v(Math.sin(r.value),i.typeInfo)}Sinh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sinh(s)),i.typeInfo);const r=i;return new v(Math.sinh(r.value),i.typeInfo)}_smoothstep(e,t,i){const r=Math.min(Math.max((i-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof g&&i instanceof g&&r instanceof g)return new g(s.data.map((c,u)=>this._smoothstep(i.data[u],r.data[u],c)),s.typeInfo);const o=i,a=r,l=s;return new v(this._smoothstep(o.value,a.value,l.value),s.typeInfo)}Sqrt(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.sqrt(s)),i.typeInfo);const r=i;return new v(Math.sqrt(r.value),i.typeInfo)}Step(e,t){const i=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof g&&i instanceof g)return new g(r.data.map((o,a)=>o<i.data[a]?0:1),r.typeInfo);const s=i;return new v(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.tan(s)),i.typeInfo);const r=i;return new v(Math.tan(r.value),i.typeInfo)}Tanh(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.tanh(s)),i.typeInfo);const r=i;return new v(Math.tanh(r.value),i.typeInfo)}_getTransposeType(e){const t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){const i=this.exec.evalExpression(e.args[0],t);if(!(i instanceof j))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;const r=this._getTransposeType(i.typeInfo);if(i.typeInfo.name==="mat2x2"||i.typeInfo.name==="mat2x2f"||i.typeInfo.name==="mat2x2h"){const s=i.data;return new j([s[0],s[2],s[1],s[3]],r)}if(i.typeInfo.name==="mat2x3"||i.typeInfo.name==="mat2x3f"||i.typeInfo.name==="mat2x3h"){const s=i.data;return new j([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(i.typeInfo.name==="mat2x4"||i.typeInfo.name==="mat2x4f"||i.typeInfo.name==="mat2x4h"){const s=i.data;return new j([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(i.typeInfo.name==="mat3x2"||i.typeInfo.name==="mat3x2f"||i.typeInfo.name==="mat3x2h"){const s=i.data;return new j([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(i.typeInfo.name==="mat3x3"||i.typeInfo.name==="mat3x3f"||i.typeInfo.name==="mat3x3h"){const s=i.data;return new j([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(i.typeInfo.name==="mat3x4"||i.typeInfo.name==="mat3x4f"||i.typeInfo.name==="mat3x4h"){const s=i.data;return new j([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(i.typeInfo.name==="mat4x2"||i.typeInfo.name==="mat4x2f"||i.typeInfo.name==="mat4x2h"){const s=i.data;return new j([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(i.typeInfo.name==="mat4x3"||i.typeInfo.name==="mat4x3f"||i.typeInfo.name==="mat4x3h"){const s=i.data;return new j([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(i.typeInfo.name==="mat4x4"||i.typeInfo.name==="mat4x4f"||i.typeInfo.name==="mat4x4h"){const s=i.data;return new j([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${i.typeInfo.name}`),null}Trunc(e,t){const i=this.exec.evalExpression(e.args[0],t);if(i instanceof g)return new g(i.data.map(s=>Math.trunc(s)),i.typeInfo);const r=i;return new v(Math.trunc(r.value),i.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){const i=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(i instanceof Qe){const s=i.name,o=t.getVariableValue(s);if(o instanceof It){if(r<0||r>=o.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;const a=o.getMipLevelSize(r),l=o.dimension;return l==="1d"?new v(a[0],this.getTypeInfo("u32")):l==="3d"?new g(a,this.getTypeInfo("vec3u")):l==="2d"?new g(a.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${l} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){const i=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof g)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(i instanceof Qe){const o=i.name,a=t.getVariableValue(o);if(a instanceof It){const l=Math.floor(r.data[0]),c=Math.floor(r.data[1]);if(l<0||l>=a.width||c<0||c>=a.height)return console.error(`Texture ${o} out of bounds. Line ${e.line}`),null;const u=a.getPixel(l,c,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new g(u,this.getTypeInfo("vec4f"))}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){const i=e.args[0];if(i instanceof Qe){const r=i.name,s=t.getVariableValue(r);return s instanceof It?new v(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){const i=e.args[0];if(i instanceof Qe){const r=i.name,s=t.getVariableValue(r);return s instanceof It?new v(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){const i=e.args[0];if(i instanceof Qe){const r=i.name,s=t.getVariableValue(r);return s instanceof It?new v(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){const i=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,o=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(o.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof g)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(i instanceof Qe){const a=i.name,l=t.getVariableValue(a);if(l instanceof It){const c=l.getMipLevelSize(0),u=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return u<0||u>=c[0]||f<0||f>=c[1]?(console.error(`Texture ${a} out of bounds. Line ${e.line}`),null):(l.setPixel(u,f,0,s,Array.from(o)),null)}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t);return t.getVariable(r).value.getSubData(this.exec,i.postfix,t)}AtomicStore(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t);return l instanceof v&&a instanceof v&&(l.value=a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),null}AtomicAdd(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value+=a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicSub(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value-=a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicMax(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=Math.max(l.value,a.value)),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicMin(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=Math.min(l.value,a.value)),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicAnd(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value&a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicOr(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value|a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicXor(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=l.value^a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicExchange(e,t){let i=e.args[0];i instanceof be&&(i=i.right);const r=this.exec.getVariableName(i,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,i.postfix,t),c=new v(l.value,l.typeInfo);return l instanceof v&&a instanceof v&&(l.value=a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,i.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}}const wo={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},We={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]};class Oe extends c0{constructor(e,t){var i;super(),this.ast=e??[],this.reflection=new _t,this.reflection.updateAST(this.ast),this.context=(i=t==null?void 0:t.clone())!==null&&i!==void 0?i:new To,this.builtins=new u0(this),this.typeInfo={bool:this.getTypeInfo(k.bool),i32:this.getTypeInfo(k.i32),u32:this.getTypeInfo(k.u32),f32:this.getTypeInfo(k.f32),f16:this.getTypeInfo(k.f16),vec2f:this.getTypeInfo(T.vec2f),vec2u:this.getTypeInfo(T.vec2u),vec2i:this.getTypeInfo(T.vec2i),vec2h:this.getTypeInfo(T.vec2h),vec3f:this.getTypeInfo(T.vec3f),vec3u:this.getTypeInfo(T.vec3u),vec3i:this.getTypeInfo(T.vec3i),vec3h:this.getTypeInfo(T.vec3h),vec4f:this.getTypeInfo(T.vec4f),vec4u:this.getTypeInfo(T.vec4u),vec4i:this.getTypeInfo(T.vec4i),vec4h:this.getTypeInfo(T.vec4h),mat2x2f:this.getTypeInfo(T.mat2x2f),mat2x3f:this.getTypeInfo(T.mat2x3f),mat2x4f:this.getTypeInfo(T.mat2x4f),mat3x2f:this.getTypeInfo(T.mat3x2f),mat3x3f:this.getTypeInfo(T.mat3x3f),mat3x4f:this.getTypeInfo(T.mat3x4f),mat4x2f:this.getTypeInfo(T.mat4x2f),mat4x3f:this.getTypeInfo(T.mat4x3f),mat4x4f:this.getTypeInfo(T.mat4x4f)}}getVariableValue(e){var t,i;const r=(i=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&i!==void 0?i:null;if(r===null)return null;if(r instanceof v)return r.value;if(r instanceof g||r instanceof j)return Array.from(r.data);if(r instanceof ye&&r.typeInfo instanceof Mt){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,i,r){const s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);const o=s.getFunction(e);if(!o)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}const a=t[0],l=t[1],c=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new g(t,u));const f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(const h in i)for(const d in i[h]){const _=i[h][d];s.variables.forEach(I=>{var P;const A=I.node;if(A!=null&&A.attributes){let O=null,E=null;for(const y of A.attributes)y.name==="binding"?O=y.value:y.name==="group"&&(E=y.value);if(d==O&&h==E){let y=!1;for(const R of f.resources)if(R.name===I.name&&R.group===parseInt(h)&&R.binding===parseInt(d)){y=!0;break}if(y)if(_.texture!==void 0&&_.descriptor!==void 0){const R=new It(_.texture,this.getTypeInfo(A.type),_.descriptor,(P=_.texture.view)!==null&&P!==void 0?P:null);I.value=R}else _.uniform!==void 0?I.value=new ye(_.uniform,this.getTypeInfo(A.type)):I.value=new ye(_,this.getTypeInfo(A.type))}}})}for(let h=0;h<c;++h)for(let d=0;d<l;++d)for(let _=0;_<a;++_)s.setVariable("@workgroup_id",new g([_,d,h],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(o,[_,d,h],s)}execStatement(e,t){if(e instanceof tu)return this.evalExpression(e.value,t);if(e instanceof iu){if(e.condition){const i=this.evalExpression(e.condition,t);if(!(i instanceof v))throw new Error("Invalid break-if condition");if(!i.value)return null}return Oe._breakObj}if(e instanceof ru)return Oe._continueObj;if(e instanceof Zn)this._let(e,t);else if(e instanceof At)this._var(e,t);else if(e instanceof fr)this._const(e,t);else if(e instanceof Kn)this._function(e,t);else{if(e instanceof eu)return this._if(e,t);if(e instanceof Gc)return this._switch(e,t);if(e instanceof Kc)return this._for(e,t);if(e instanceof jc)return this._while(e,t);if(e instanceof Jc)return this._loop(e,t);if(e instanceof po){const i=t.clone();return i.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,i)}if(e instanceof Qc)this._assign(e,t);else if(e instanceof Zc)this._increment(e,t);else{if(e instanceof Ct)return null;if(e instanceof mo){const i=e.name;t.getVariable(i)===null&&t.setVariable(i,new v(0,this.getTypeInfo("u32")))}else if(e instanceof go)this._call(e,t);else{if(e instanceof nu||e instanceof _o)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof lt?this._evalBinaryOp(e,t):e instanceof Ae?this._evalLiteral(e,t):e instanceof Qe?this._evalVariable(e,t):e instanceof xo?this._evalCall(e,t):e instanceof gt?this._evalCreate(e,t):e instanceof ou?this._evalConst(e,t):e instanceof au?this._evalBitcast(e,t):e instanceof be?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof k){const r=this.reflection.getTypeInfo(e);if(r!==null)return r}let i=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return i!==null||(i=this.reflection.getTypeInfoByName(e)),i}_setOverrides(e,t){for(const i in e){const r=e[i],s=this.reflection.getOverrideInfo(i);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(i,new v(r,s.type)):s.type.name==="bool"?t.setVariable(i,new v(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(i,new g(r,s.type)):console.error(`Invalid constant type for ${i}`)):console.error(`Override ${i} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,i){const r=[1,1,1];for(const u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){const f=i.getVariableValue(u.value[0]);r[0]=f instanceof v?f.value:parseInt(u.value[0])}if(u.value.length>1){const f=i.getVariableValue(u.value[1]);r[1]=f instanceof v?f.value:parseInt(u.value[1])}if(u.value.length>2){const f=i.getVariableValue(u.value[2]);r[2]=f instanceof v?f.value:parseInt(u.value[2])}}const s=this.getTypeInfo("vec3u"),o=this.getTypeInfo("u32");i.setVariable("@workgroup_size",new g(r,s));const a=r[0],l=r[1],c=r[2];for(let u=0,f=0;u<c;++u)for(let h=0;h<l;++h)for(let d=0;d<a;++d,++f){const _=[d,h,u],I=[d+t[0]*r[0],h+t[1]*r[1],u+t[2]*r[2]];i.setVariable("@local_invocation_id",new g(_,s)),i.setVariable("@global_invocation_id",new g(I,s)),i.setVariable("@local_invocation_index",new v(f,o)),this._dispatchExec(e,i)}}_dispatchExec(e,t){for(const i of e.node.args)for(const r of i.attributes)if(r.name==="builtin"){const s=`@${r.value}`,o=t.getVariable(s);o!==void 0&&t.variables.set(i.name,o)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof be;)e=e.right;return e instanceof Qe?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(const i of e){if(i instanceof Array){const s=t.clone(),o=this._execStatements(i,s);if(o)return o;continue}const r=this.execStatement(i,t);if(r)return r}return null}_call(e,t){const i=t.clone();i.currentFunctionName=e.name;const r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){const o=r.node.args[s],a=this.evalExpression(e.args[s],i);i.setVariable(o.name,a,o)}this._execStatements(r.node.body,i)}else e.isBuiltin?this._callBuiltinFunction(e,i):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){const i=this.getVariableName(e.variable,t),r=t.getVariable(i);r?e.operator==="++"?r.value instanceof v?r.value.value++:console.error(`Variable ${i} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof v?r.value.value--:console.error(`Variable ${i} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${i} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof Qe){const i=this.getVariableName(e,t),r=t.getVariable(i);return r===null?(console.error(`Variable ${i} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof be){if(e.operator==="*"){const i=this._getVariableData(e.right,t);return i instanceof yn?i.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){const i=this._getVariableData(e.right,t);return new yn(i)}}return null}_assign(e,t){let i=null,r="<var>",s=null;if(e.variable instanceof be){const l=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(l instanceof v||l instanceof g||l instanceof j){if(c instanceof v||c instanceof g||c instanceof j&&l.data.length===c.data.length)return void l.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(l instanceof ye&&c instanceof ye&&l.buffer.byteLength-l.offset>=c.buffer.byteLength-c.offset)return void(l.buffer.byteLength%4==0?new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(l.buffer,l.offset,l.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return l instanceof v||l instanceof g||l instanceof j?c instanceof v||c instanceof g||c instanceof j?void l.data.set(c.data.map((f,h)=>l.data[h]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(l instanceof v||l instanceof g||l instanceof j)&&(c instanceof v||c instanceof g||c instanceof j)?void l.data.set(c.data.map((f,h)=>l.data[h]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof be){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);const l=t.getVariable(r);if(!(l&&l.value instanceof yn))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);i=l.value.reference;let c=e.variable.postfix;if(!c){let u=e.variable.right;for(;u instanceof be;){if(u.postfix){c=u.postfix;break}u=u.right}}c&&(i=i.getSubData(this,c,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);const l=t.getVariable(r);if(l===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);i=l.value}if(i instanceof yn&&(i=i.reference),i===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);const o=this.evalExpression(e.value,t),a=e.operator;if(a!=="="){const l=i.getSubData(this,s,t);if(l instanceof g&&o instanceof v){const c=l.data,u=o.value;if(a==="+=")for(let f=0;f<c.length;++f)c[f]+=u;else if(a==="-=")for(let f=0;f<c.length;++f)c[f]-=u;else if(a==="*=")for(let f=0;f<c.length;++f)c[f]*=u;else if(a==="/=")for(let f=0;f<c.length;++f)c[f]/=u;else if(a==="%=")for(let f=0;f<c.length;++f)c[f]%=u;else if(a==="&=")for(let f=0;f<c.length;++f)c[f]&=u;else if(a==="|=")for(let f=0;f<c.length;++f)c[f]|=u;else if(a==="^=")for(let f=0;f<c.length;++f)c[f]^=u;else if(a==="<<=")for(let f=0;f<c.length;++f)c[f]<<=u;else if(a===">>=")for(let f=0;f<c.length;++f)c[f]>>=u;else console.error(`Invalid operator ${a}. Line ${e.line}`)}else if(l instanceof g&&o instanceof g){const c=l.data,u=o.data;if(c.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(a==="+=")for(let f=0;f<c.length;++f)c[f]+=u[f];else if(a==="-=")for(let f=0;f<c.length;++f)c[f]-=u[f];else if(a==="*=")for(let f=0;f<c.length;++f)c[f]*=u[f];else if(a==="/=")for(let f=0;f<c.length;++f)c[f]/=u[f];else if(a==="%=")for(let f=0;f<c.length;++f)c[f]%=u[f];else if(a==="&=")for(let f=0;f<c.length;++f)c[f]&=u[f];else if(a==="|=")for(let f=0;f<c.length;++f)c[f]|=u[f];else if(a==="^=")for(let f=0;f<c.length;++f)c[f]^=u[f];else if(a==="<<=")for(let f=0;f<c.length;++f)c[f]<<=u[f];else if(a===">>=")for(let f=0;f<c.length;++f)c[f]>>=u[f];else console.error(`Invalid operator ${a}. Line ${e.line}`)}else{if(!(l instanceof v&&o instanceof v))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);a==="+="?l.value+=o.value:a==="-="?l.value-=o.value:a==="*="?l.value*=o.value:a==="/="?l.value/=o.value:a==="%="?l.value%=o.value:a==="&="?l.value&=o.value:a==="|="?l.value|=o.value:a==="^="?l.value^=o.value:a==="<<="?l.value<<=o.value:a===">>="?l.value>>=o.value:console.error(`Invalid operator ${a}. Line ${e.line}`)}return void(i instanceof ye&&i.setDataValue(this,l,s,t))}if(i instanceof ye)i.setDataValue(this,o,s,t);else if(s){if(!(i instanceof g||i instanceof j))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof xn){const l=this.evalExpression(s.index,t).value;if(i instanceof g){if(!(o instanceof v))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[l]=o.value}else{if(!(i instanceof j))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{const c=this.evalExpression(s.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(o instanceof g))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{const u=i.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(c<2&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(c<2&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(c<2&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(c<3&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(c<3&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(c<3&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(c<4&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[2*c]=o.data[0],i.data[2*c+1]=o.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(c<4&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[3*c]=o.data[0],i.data[3*c+1]=o.data[1],i.data[3*c+2]=o.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(c<4&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);i.data[4*c]=o.data[0],i.data[4*c+1]=o.data[1],i.data[4*c+2]=o.data[2],i.data[4*c+3]=o.data[3]}}}}}else if(s instanceof Kt){const l=s.value;if(!(i instanceof g))return void console.error(`Invalid assignment to ${l}. Variable ${r} is not a vector. Line ${e.line}`);if(o instanceof v){if(l.length>1)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);if(l==="x")i.data[0]=o.value;else if(l==="y"){if(i.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[1]=o.value}else if(l==="z"){if(i.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[2]=o.value}else if(l==="w"){if(i.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);i.data[3]=o.value}}else{if(!(o instanceof g))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(l.length!==o.data.length)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);for(let c=0;c<l.length;++c){const u=l[c];if(u==="x"||u==="r")i.data[0]=o.data[c];else if(u==="y"||u==="g"){if(o.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[1]=o.data[c]}else if(u==="z"||u==="b"){if(o.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[2]=o.data[c]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(o.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);i.data[3]=o.data[c]}}}}}else i instanceof v&&o instanceof v?i.value=o.value:i instanceof g&&o instanceof g||i instanceof j&&o instanceof j?i.data.set(o.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`)}_function(e,t){const i=new So(e);t.functions.set(e.name,i)}_const(e,t){let i=null;e.value!==null&&(i=this.evalExpression(e.value,t)),t.createVariable(e.name,i,e)}_let(e,t){let i=null;if(e.value!==null){if(i=this.evalExpression(e.value,t),i===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof be||(i=i.clone())}else{const r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){const s=new gt(e.type,[]);i=this._evalCreate(s,t)}}t.createVariable(e.name,i,e)}_var(e,t){let i=null;if(e.value!==null){if(i=this.evalExpression(e.value,t),i===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof be||(i=i.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);const r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof Jn||e.type instanceof Ct||e.type instanceof T){const s=new gt(e.type,[]);i=this._evalCreate(s,t)}}t.createVariable(e.name,i,e)}_switch(e,t){t=t.clone();const i=this.evalExpression(e.condition,t);if(!(i instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(const s of e.cases)if(s instanceof uu)for(const o of s.selectors){if(o instanceof dr){r=s;continue}const a=this.evalExpression(o,t);if(!(a instanceof v))return console.error(`Invalid case selector. Line ${e.line}`),null;if(a.value===i.value)return this._execStatements(s.body,t)}else s instanceof fu&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();const i=this.evalExpression(e.condition,t);if(!(i instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(i.value)return this._execStatements(e.body,t);for(const r of e.elseif){const s=this.evalExpression(r.condition,t);if(!(s instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof v?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){const i=this._execStatements(e.body,t);if(i===Oe._breakObj)break;if(i!==null&&i!==Oe._continueObj)return i;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){const i=this._execStatements(e.body,t);if(i===Oe._breakObj)break;if(i===Oe._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===Oe._breakObj)break}else if(i!==null)return i}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){const i=this._execStatements(e.body,t);if(i===Oe._breakObj)break;if(i!==Oe._continueObj&&i!==null)return i}return null}_evalBitcast(e,t){const i=this.evalExpression(e.value,t),r=e.type;if(i instanceof v){const s=gu(i.value,i.typeInfo.name,r.name);return new v(s,this.getTypeInfo(r))}if(i instanceof g){const s=i.typeInfo.getTypeName();let o="";if(s.endsWith("f"))o="f32";else if(s.endsWith("i"))o="i32";else if(s.endsWith("u"))o="u32";else if(s.endsWith("b"))o="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;o="f16"}const a=r.getTypeName();let l="";if(a.endsWith("f"))l="f32";else if(a.endsWith("i"))l="i32";else if(a.endsWith("u"))l="u32";else if(a.endsWith("b"))l="bool";else{if(!a.endsWith("h"))return console.error(`Unknown vector type ${l}. Line ${e.line}`),null;l="f16"}const c=function(u,f,h){if(f===h)return u;const d=new Array(u.length);for(let _=0;_<u.length;_++)d[_]=gu(u[_],f,h);return d}(Array.from(i.data),o,l);return new g(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${i.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var i;if(e instanceof gt){if(e.type===null)return yo.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}const r=e instanceof gt?e.type.name:e.name,s=e instanceof gt?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;const o=new ye(new ArrayBuffer(s.size),s,0);if(s instanceof Ft){if(e.args)for(let a=0;a<e.args.length;++a){const l=s.members[a],c=e.args[a],u=this.evalExpression(c,t);o.setData(this,u,l.type,l.offset,t)}}else if(s instanceof Mt){let a=0;if(e.args)for(let l=0;l<e.args.length;++l){const c=e.args[l],u=this.evalExpression(c,t);s.format===null&&(((i=u.typeInfo)===null||i===void 0?void 0:i.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),o.setData(this,u,s.format,a,t),a+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof gt?o.getSubData(this,e.postfix,t):o}_evalLiteral(e,t){const i=this.getTypeInfo(e.type),r=i.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new v(e.scalarValue,i):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){const i=t.getVariableValue(e.name);return i===null?i:i.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let i=1;i<e.length;++i){const r=Oe._priority.get(t.name);Oe._priority.get(e[i].name)<r&&(t=e[i])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){const i=this.evalExpression(e.right,t);if(e.operator==="&")return new yn(i);if(e.operator==="*")return i instanceof yn?i.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);const r=i instanceof v?i.value:i instanceof g?Array.from(i.data):null;switch(e.operator){case"+":{if(z(r)){const a=r.map((l,c)=>+l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(+s,o)}case"-":{if(z(r)){const a=r.map((l,c)=>-l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(-s,o)}case"!":{if(z(r)){const a=r.map((l,c)=>l?0:1);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(s?0:1,o)}case"~":{if(z(r)){const a=r.map((l,c)=>~l);return new g(a,i.typeInfo)}const s=r,o=this._maxFormatTypeInfo([i.typeInfo,i.typeInfo]);return new v(~s,o)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){const i=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=i instanceof v?i.value:i instanceof g||i instanceof j?Array.from(i.data):null,o=r instanceof v?r.value:r instanceof g||r instanceof j?Array.from(r.data):null;switch(e.operator){case"+":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d+f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h+u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u+h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a+l,c)}case"-":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d-f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h-u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u-h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a-l,c)}case"*":{if(z(s)&&z(o)){const u=s,f=o;if(i instanceof j&&r instanceof j){const h=function(P,A,O,E){if(We[A.name]===void 0||We[E.name]===void 0)return null;const y=We[A.name][0],R=We[A.name][1],N=We[E.name][0];if(y!==We[E.name][1])return null;const U=new Array(N*R);for(let H=0;H<R;H++)for(let Y=0;Y<N;Y++){let Z=0;for(let B=0;B<y;B++)Z+=P[B*R+H]*O[Y*y+B];U[H*N+Y]=Z}return U}(u,i.typeInfo,f,r.typeInfo);if(h===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;const d=We[r.typeInfo.name][0],_=We[i.typeInfo.name][1],I=this.getTypeInfo(`mat${d}x${_}f`);return new j(h,I)}if(i instanceof j&&r instanceof g){const h=function(d,_,I,P){if(We[_.name]===void 0||wo[P.name]===void 0)return null;const A=We[_.name][0],O=We[_.name][1];if(A!==I.length)return null;const E=new Array(O);for(let y=0;y<O;y++){let R=0;for(let N=0;N<A;N++)R+=d[N*O+y]*I[N];E[y]=R}return E}(u,i.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(h,r.typeInfo)}if(i instanceof g&&r instanceof j){const h=function(d,_,I,P){if(wo[_.name]===void 0||We[P.name]===void 0)return null;const A=We[P.name][0],O=We[P.name][1];if(O!==d.length)return null;const E=[];for(let y=0;y<A;y++){let R=0;for(let N=0;N<O;N++)R+=d[N]*I[N*A+y];E[y]=R}return E}(u,i.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(h,i.typeInfo)}{if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d*f[_]);return new g(h,i.typeInfo)}}if(z(s)){const u=o,f=s.map((h,d)=>h*u);return i instanceof j?new j(f,i.typeInfo):new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u*h);return r instanceof j?new j(f,r.typeInfo):new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a*l,c)}case"%":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d%f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h%u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u%h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a%l,c)}case"/":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d/f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h/u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u/h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a/l,c)}case"&":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d&f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h&u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u&h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a&l,c)}case"|":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d|f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h|u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u|h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a|l,c)}case"^":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d^f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h^u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u^h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a^l,c)}case"<<":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d<<f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h<<u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u<<h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a<<l,c)}case">>":{if(z(s)&&z(o)){const u=s,f=o;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const h=u.map((d,_)=>d>>f[_]);return new g(h,i.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h>>u);return new g(f,i.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u>>h);return new g(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([i.typeInfo,r.typeInfo]);return new v(a>>l,c)}case">":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u>l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>c?1:0);return new g(l,r.typeInfo)}return new v(s>o?1:0,this.getTypeInfo("bool"));case"<":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u<l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<c?1:0);return new g(l,r.typeInfo)}return new v(s<o?1:0,this.getTypeInfo("bool"));case"==":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u===l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c==a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a==c?1:0);return new g(l,r.typeInfo)}return new v(s===o?1:0,this.getTypeInfo("bool"));case"!=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u!==l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c!==a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a!==c?1:0);return new g(l,r.typeInfo)}return new v(s!==o?1:0,this.getTypeInfo("bool"));case">=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u>=l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>=a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>=c?1:0);return new g(l,r.typeInfo)}return new v(s>=o?1:0,this.getTypeInfo("bool"));case"<=":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u<=l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<=a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<=c?1:0);return new g(l,r.typeInfo)}return new v(s<=o?1:0,this.getTypeInfo("bool"));case"&&":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u&&l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c&&a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a&&c?1:0);return new g(l,r.typeInfo)}return new v(s&&o?1:0,this.getTypeInfo("bool"));case"||":if(z(s)&&z(o)){const a=s,l=o;if(a.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=a.map((u,f)=>u||l[f]?1:0);return new g(c,i.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c||a?1:0);return new g(l,i.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a||c?1:0);return new g(l,r.typeInfo)}return new v(s||o?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;const i=t.clone();i.currentFunctionName=e.name;const r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,i):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){const o=r.node.args[s],a=this.evalExpression(e.args[s],i);i.createVariable(o.name,a,o)}return this._execStatements(r.node.body,i)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothstep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}const i=t.getFunction(e.name);if(i){const r=t.clone();for(let s=0;s<i.node.args.length;++s){const o=i.node.args[s],a=this.evalExpression(e.args[s],r);r.setVariable(o.name,a,o)}return this._execStatements(i.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new v(0,this.getTypeInfo(e.type));const i=this.evalExpression(e.args[0],t);return i.typeInfo=this.getTypeInfo(e.type),i.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){const i=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=wo[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ae)if(e.isVector){const a=e.vectorValue;for(const l of a)o.push(l)}else o.push(e.scalarValue);else if(e.args)for(const a of e.args){const l=this.evalExpression(a,t);if(l instanceof g){const c=l.data;for(let u=0;u<c.length;++u){let f=c[u];o.push(f)}}else if(l instanceof v){let c=l.value;o.push(c)}}if(e.type instanceof T&&e.type.format===null&&(e.type.format=T.f32),o.length===0){const a=new Array(s).fill(0);return new g(a,i).getSubData(this,e.postfix,t)}if(o.length===1)for(;o.length<s;)o.push(o[0]);return o.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new g(o.length>s?o.slice(0,s):o,i).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const i=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=We[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ae)if(e.isVector){const a=e.vectorValue;for(const l of a)o.push(l)}else o.push(e.scalarValue);else if(e.args)for(const a of e.args){const l=this.evalExpression(a,t);l instanceof g?o.push(...l.data):l instanceof v?o.push(l.value):l instanceof j&&o.push(...l.data)}if(i instanceof jt&&i.format===null&&(i.format=this.getTypeInfo("f32")),o.length===0){const a=new Array(s[2]).fill(0);return new j(a,i).getSubData(this,e.postfix,t)}return o.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new j(o,i).getSubData(this,e.postfix,t)}}Oe._breakObj=new tt(new Ge("BREAK",null),null),Oe._continueObj=new tt(new Ge("CONTINUE",null),null),Oe._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class f0{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class h0{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new f0,this._exec=new Oe,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const i=this._global_decl_or_directive();if(!i)break;t.push(i)}if(this._deferArrayCountEval.length>0){for(const i of this._deferArrayCountEval){const r=i.arrayType,s=i.countNode;if(s instanceof Qe){const o=s.name,a=this._context.constants.get(o);if(a)try{const l=a.constEvaluate(this._exec);r.count=l}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(const i of t)i.search(r=>{r instanceof du||r instanceof hr?r.type=this._forwardType(r.type):r instanceof Jn?r.format=this._forwardType(r.format):r instanceof At||r instanceof Zn||r instanceof fr?r.type=this._forwardType(r.type):r instanceof Kn?r.returnType=this._forwardType(r.returnType):r instanceof hu&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof su){const t=this._getType(e.name);if(t)return t}else e instanceof hr?e.type=this._forwardType(e.type):e instanceof Jn&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){const t=new t0(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==p.eof}_match(e){if(e instanceof S)return!!this._check(e)&&(this._advance(),!0);for(let t=0,i=e.length;t<i;++t){const r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;const t=this._peek();if(e instanceof Array){const i=t.type;let r=!1;for(const s of e){if(i===s)return!0;s===p.tokens.name&&(r=!0)}if(r){const s=p.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===p.tokens.name){const i=p.tokens.name.rule.exec(t.lexeme);return i&&i.index==0&&i[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(p.tokens.semicolon)&&!this._isAtEnd(););if(this._match(p.keywords.alias)){const t=this._type_alias();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.diagnostic)){const t=this._diagnostic();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.requires)){const t=this._requires_directive();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(p.keywords.enable)){const t=this._enable_directive();return this._consume(p.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}const e=this._attribute();if(this._check(p.keywords.var)){const t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.override)){const t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.let)){const t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.const)){const t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(p.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.struct)){const t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(p.keywords.fn)){const t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(p.keywords.fn))return null;const e=this._currentLine,t=this._consume(p.tokens.ident,"Expected function name.").toString();this._consume(p.tokens.paren_left,"Expected '(' for function arguments.");const i=[];if(!this._check(p.tokens.paren_right))do{if(this._check(p.tokens.paren_right))break;const a=this._attribute(),l=this._consume(p.tokens.name,"Expected argument name.").toString();this._consume(p.tokens.colon,"Expected ':' for argument type.");const c=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=c,i.push(this._updateNode(new hu(l,u,a))))}while(this._match(p.tokens.comma));this._consume(p.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(p.tokens.arrow)){const a=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=a)}const s=this._compound_statement(),o=this._currentLine;return this._updateNode(new Kn(t,i,r,s,e,o),e)}_compound_statement(){const e=[];for(this._consume(p.tokens.brace_left,"Expected '{' for block.");!this._check(p.tokens.brace_right);){const t=this._statement();t!==null&&e.push(t)}return this._consume(p.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(p.tokens.semicolon)&&!this._isAtEnd(););if(this._check(p.tokens.attr)&&this._attribute(),this._check(p.keywords.if))return this._if_statement();if(this._check(p.keywords.switch))return this._switch_statement();if(this._check(p.keywords.loop))return this._loop_statement();if(this._check(p.keywords.for))return this._for_statement();if(this._check(p.keywords.while))return this._while_statement();if(this._check(p.keywords.continuing))return this._continuing_statement();if(this._check(p.keywords.static_assert))return this._static_assert_statement();if(this._check(p.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(p.keywords.return))e=this._return_statement();else if(this._check([p.keywords.var,p.keywords.let,p.keywords.const]))e=this._variable_statement();else if(this._match(p.keywords.discard))e=this._updateNode(new Jy);else if(this._match(p.keywords.break)){const t=this._updateNode(new iu);if(this._currentLoop.length>0){const i=this._currentLoop[this._currentLoop.length-1];t.loopId=i.id}e=t,this._check(p.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(p.keywords.continue)){const t=this._updateNode(new ru);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const i=this._currentLoop[this._currentLoop.length-1];t.loopId=i.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(p.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(p.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new Ky(t),e)}_while_statement(){if(!this._match(p.keywords.while))return null;const e=this._updateNode(new jc(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(p.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){const e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(p.keywords.continuing))return null;const t=this._currentLine,i=this._compound_statement();return this._updateNode(new po(i,e),t)}_for_statement(){if(!this._match(p.keywords.for))return null;this._consume(p.tokens.paren_left,"Expected '('.");const e=this._updateNode(new Kc(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(p.tokens.semicolon)?null:this._for_init(),this._consume(p.tokens.semicolon,"Expected ';'."),e.condition=this._check(p.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(p.tokens.semicolon,"Expected ';'."),e.increment=this._check(p.tokens.paren_right)?null:this._for_increment(),this._consume(p.tokens.paren_right,"Expected ')'."),this._check(p.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(p.keywords.var)){const e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(p.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new At(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(p.keywords.let)){const e=this._currentLine,t=this._consume(p.tokens.name,"Expected name for let.").toString();let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for let.");const r=this._short_circuit_or_expression();return this._updateNode(new Zn(t,i,null,null,r),e)}if(this._match(p.keywords.const)){const e=this._currentLine,t=this._consume(p.tokens.name,"Expected name for const.").toString();let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for const.");const r=this._short_circuit_or_expression();return i===null&&r instanceof Ae&&(i=r.type),this._updateNode(new fr(t,i,null,null,r),e)}return null}_increment_decrement_statement(){const e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(p.increment_operators))return this._current=e,null;const i=this._consume(p.increment_operators,"Expected increment operator");return this._updateNode(new Zc(i.type===p.tokens.plus_plus?_n.increment:_n.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(p.tokens.brace_right))return null;let i=this._match(p.tokens.underscore);if(i||(e=this._unary_expression()),!i&&e==null)return null;const r=this._consume(p.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new Qc(Qn.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(p.tokens.ident))return null;const e=this._currentLine,t=this._current,i=this._consume(p.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new go(i.lexeme,r),e)}_loop_statement(){if(!this._match(p.keywords.loop))return null;this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Expected '{' for loop.");const e=this._updateNode(new Jc([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let i of t)e.body.push(i);else e.body.push(t);if(t instanceof po){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(p.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(p.keywords.switch))return null;const e=this._updateNode(new Gc(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(p.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([p.keywords.default,p.keywords.case]);){if(this._match(p.keywords.case)){const i=this._case_selectors();for(const s of i)if(s instanceof dr){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(p.tokens.colon),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Exected '{' for switch case.");const r=this._case_body();this._consume(p.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new uu(i,r)))}if(this._match(p.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(p.tokens.colon),this._check(p.tokens.attr)&&this._attribute(),this._consume(p.tokens.brace_left,"Exected '{' for switch default.");const i=this._case_body();this._consume(p.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new fu(i)))}}return e}_case_selectors(){const e=[];for(this._match(p.keywords.default)?e.push(this._updateNode(new dr)):e.push(this._shift_expression());this._match(p.tokens.comma);)this._match(p.keywords.default)?e.push(this._updateNode(new dr)):e.push(this._shift_expression());return e}_case_body(){if(this._match(p.keywords.fallthrough))return this._consume(p.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);const t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(p.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(p.tokens.attr)&&this._attribute();const i=this._compound_statement();let r=[];this._match_elseif()&&(this._check(p.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(p.keywords.else)&&(this._check(p.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new eu(t,i,r,s),e)}_match_elseif(){return this._tokens[this._current].type===p.keywords.else&&this._tokens[this._current+1].type===p.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){const t=this._optional_paren_expression(),i=this._compound_statement();return e.push(this._updateNode(new Gy(t,i))),this._match_elseif()&&(this._check(p.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(p.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new tu(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(p.tokens.or_or);)e=this._updateNode(new lt(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(p.tokens.and_and);)e=this._updateNode(new lt(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(p.tokens.or);)e=this._updateNode(new lt(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(p.tokens.xor);)e=this._updateNode(new lt(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(p.tokens.and);)e=this._updateNode(new lt(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([p.tokens.equal_equal,p.tokens.not_equal])?this._updateNode(new lt(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([p.tokens.less_than,p.tokens.greater_than,p.tokens.less_than_equal,p.tokens.greater_than_equal]);)e=this._updateNode(new lt(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([p.tokens.shift_left,p.tokens.shift_right]);)e=this._updateNode(new lt(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([p.tokens.plus,p.tokens.minus]);)e=this._updateNode(new lt(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([p.tokens.star,p.tokens.forward_slash,p.tokens.modulo]);)e=this._updateNode(new lt(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([p.tokens.minus,p.tokens.bang,p.tokens.tilde,p.tokens.star,p.tokens.and])?this._updateNode(new be(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){const e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(p.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(p.tokens.bracket_right,"Expected ']'.");const t=this._updateNode(new xn(e)),i=this._postfix_expression();return i&&(t.postfix=i),t}if(this._match(p.tokens.period)){const e=this._consume(p.tokens.name,"Expected member name."),t=this._postfix_expression(),i=this._updateNode(new Kt(e.lexeme));return t&&(i.postfix=t),i}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){const t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return k.void;case"bool":return k.bool;case"i32":return k.i32;case"u32":return k.u32;case"f32":return k.f32;case"f16":return k.f16;case"vec2f":return T.vec2f;case"vec3f":return T.vec3f;case"vec4f":return T.vec4f;case"vec2i":return T.vec2i;case"vec3i":return T.vec3i;case"vec4i":return T.vec4i;case"vec2u":return T.vec2u;case"vec3u":return T.vec3u;case"vec4u":return T.vec4u;case"vec2h":return T.vec2h;case"vec3h":return T.vec3h;case"vec4h":return T.vec4h;case"mat2x2f":return T.mat2x2f;case"mat2x3f":return T.mat2x3f;case"mat2x4f":return T.mat2x4f;case"mat3x2f":return T.mat3x2f;case"mat3x3f":return T.mat3x3f;case"mat3x4f":return T.mat3x4f;case"mat4x2f":return T.mat4x2f;case"mat4x3f":return T.mat4x3f;case"mat4x4f":return T.mat4x4f;case"mat2x2h":return T.mat2x2h;case"mat2x3h":return T.mat2x3h;case"mat2x4h":return T.mat2x4h;case"mat3x2h":return T.mat3x2h;case"mat3x3h":return T.mat3x3h;case"mat3x4h":return T.mat3x4h;case"mat4x2h":return T.mat4x2h;case"mat4x3h":return T.mat4x3h;case"mat4x4h":return T.mat4x4h;case"mat2x2i":return T.mat2x2i;case"mat2x3i":return T.mat2x3i;case"mat2x4i":return T.mat2x4i;case"mat3x2i":return T.mat3x2i;case"mat3x3i":return T.mat3x3i;case"mat3x4i":return T.mat3x4i;case"mat4x2i":return T.mat4x2i;case"mat4x3i":return T.mat4x3i;case"mat4x4i":return T.mat4x4i;case"mat2x2u":return T.mat2x2u;case"mat2x3u":return T.mat2x3u;case"mat2x4u":return T.mat2x4u;case"mat3x2u":return T.mat3x2u;case"mat3x3u":return T.mat3x3u;case"mat3x4u":return T.mat3x4u;case"mat4x2u":return T.mat4x2u;case"mat4x3u":return T.mat4x3u;case"mat4x4u":return T.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(p.tokens.ident)){const i=this._previous().toString();if(this._check(p.tokens.paren_left)){const r=this._argument_expression_list(),s=this._getType(i);return s!==null?this._updateNode(new gt(s,r)):this._updateNode(new xo(i,r))}if(this._context.constants.has(i)){const r=this._context.constants.get(i);return this._updateNode(new ou(i,r.value))}return this._updateNode(new Qe(i))}if(this._match(p.tokens.int_literal)){const i=this._previous().toString();let r=i.endsWith("i")||i.endsWith("i")?k.i32:i.endsWith("u")||i.endsWith("U")?k.u32:k.x32;const s=parseInt(i);return this._validateTypeRange(s,r),this._updateNode(new Ae(new v(s,this._exec.getTypeInfo(r)),r))}if(this._match(p.tokens.uint_literal)){const i=parseInt(this._previous().toString());return this._validateTypeRange(i,k.u32),this._updateNode(new Ae(new v(i,this._exec.getTypeInfo(k.u32)),k.u32))}if(this._match([p.tokens.decimal_float_literal,p.tokens.hex_float_literal])){let i=this._previous().toString(),r=i.endsWith("h");r&&(i=i.substring(0,i.length-1));const s=parseFloat(i);this._validateTypeRange(s,r?k.f16:k.f32);const o=r?k.f16:k.f32;return this._updateNode(new Ae(new v(s,this._exec.getTypeInfo(o)),o))}if(this._match([p.keywords.true,p.keywords.false])){let i=this._previous().toString()===p.keywords.true.rule;return this._updateNode(new Ae(new v(i?1:0,this._exec.getTypeInfo(k.bool)),k.bool))}if(this._check(p.tokens.paren_left))return this._paren_expression();if(this._match(p.keywords.bitcast)){this._consume(p.tokens.less_than,"Expected '<'.");const i=this._type_decl();this._consume(p.tokens.greater_than,"Expected '>'.");const r=this._paren_expression();return this._updateNode(new au(i,r))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new gt(e,t))}_argument_expression_list(){if(!this._match(p.tokens.paren_left))return null;const e=[];do{if(this._check(p.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t)}while(this._match(p.tokens.comma));return this._consume(p.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(p.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(p.tokens.paren_right),e}_paren_expression(){this._consume(p.tokens.paren_left,"Expected '('.");const e=this._short_circuit_or_expression();return this._consume(p.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(p.keywords.struct))return null;const e=this._currentLine,t=this._consume(p.tokens.ident,"Expected name for struct.").toString();this._consume(p.tokens.brace_left,"Expected '{' for struct body.");const i=[];for(;!this._check(p.tokens.brace_right);){const o=this._attribute(),a=this._consume(p.tokens.name,"Expected variable name.").toString();this._consume(p.tokens.colon,"Expected ':' for struct member type.");const l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l),this._check(p.tokens.brace_right)?this._match(p.tokens.comma):this._consume(p.tokens.comma,"Expected ',' for struct member."),i.push(this._updateNode(new du(a,c,o)))}this._consume(p.tokens.brace_right,"Expected '}' after struct body.");const r=this._currentLine,s=this._updateNode(new Ct(t,i,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){const e=this._variable_decl();if(!e)return null;if(this._match(p.tokens.equal)){const t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof Ae){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof Ae&&(e.type=e.value.type.name==="x32"?k.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){const e=this._override_decl();return e&&this._match(p.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(p.keywords.const))return null;const t=this._consume(p.tokens.name,"Expected variable name"),i=this._currentLine;let r=null;if(this._match(p.tokens.colon)){const l=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=l)}let s=null;this._consume(p.tokens.equal,"const declarations require an assignment");const o=this._short_circuit_or_expression();try{let l=[k.f32],c=o.constEvaluate(this._exec,l);c instanceof v&&this._validateTypeRange(c.value,l[0]),l[0]instanceof T&&l[0].format===null&&c.typeInfo instanceof jt&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?l[0].format=k.f16:c.typeInfo.format.name==="f32"?l[0].format=k.f32:c.typeInfo.format.name==="i32"?l[0].format=k.i32:c.typeInfo.format.name==="u32"?l[0].format=k.u32:c.typeInfo.format.name==="bool"?l[0].format=k.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new Ae(c,l[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=o}if(r!==null&&s instanceof Ae){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof Ae&&(r=(e=s==null?void 0:s.type)!==null&&e!==void 0?e:k.f32,r===k.x32&&(r=k.i32));const a=this._updateNode(new fr(t.toString(),r,"","",s),i);return this._context.constants.set(a.name,a),a}_global_let_decl(){if(!this._match(p.keywords.let))return null;const e=this._currentLine,t=this._consume(p.tokens.name,"Expected variable name");let i=null;if(this._match(p.tokens.colon)){const s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}let r=null;if(this._match(p.tokens.equal)&&(r=this._const_expression()),i!==null&&r instanceof Ae){if(r.type.name!=="x32"&&i.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${i.name}. Line:${this._currentLine}`);r.type=i}else i===null&&r instanceof Ae&&(i=r.type.name==="x32"?k.i32:r.type);return r instanceof Ae&&r.isScalar&&this._validateTypeRange(r.scalarValue,i),this._updateNode(new Zn(t.toString(),i,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(p.keywords.var))return null;const e=this._currentLine;let t="",i="";this._match(p.tokens.less_than)&&(t=this._consume(p.storage_class,"Expected storage_class.").toString(),this._match(p.tokens.comma)&&(i=this._consume(p.access_mode,"Expected access_mode.").toString()),this._consume(p.tokens.greater_than,"Expected '>'."));const r=this._consume(p.tokens.name,"Expected variable name");let s=null;if(this._match(p.tokens.colon)){const o=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=o)}return this._updateNode(new At(r.toString(),s,t,i,null),e)}_override_decl(){if(!this._match(p.keywords.override))return null;const e=this._consume(p.tokens.name,"Expected variable name");let t=null;if(this._match(p.tokens.colon)){const i=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=i)}return this._updateNode(new mo(e.toString(),t,null))}_diagnostic(){this._consume(p.tokens.paren_left,"Expected '('");const e=this._consume(p.tokens.ident,"Expected severity control name.");this._consume(p.tokens.comma,"Expected ','");let t=this._consume(p.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(p.tokens.period)&&(t+=`.${this._consume(p.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(p.tokens.paren_right,"Expected ')'"),this._updateNode(new nu(e.toString(),t))}_enable_directive(){const e=this._consume(p.tokens.ident,"identity expected.");return this._updateNode(new Zy(e.toString()))}_requires_directive(){const e=[this._consume(p.tokens.ident,"identity expected.").toString()];for(;this._match(p.tokens.comma);){const t=this._consume(p.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new Qy(e))}_type_alias(){const e=this._consume(p.tokens.ident,"identity expected.");this._consume(p.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);const i=this._updateNode(new _o(e.toString(),t));return this._context.aliases.set(i.name,i),i}_type_decl(){if(this._check([p.tokens.ident,...p.texel_format,p.keywords.bool,p.keywords.f32,p.keywords.i32,p.keywords.u32])){const i=this._advance().toString();if(this._context.structs.has(i))return this._context.structs.get(i);if(this._context.aliases.has(i))return this._context.aliases.get(i).type;if(!this._getType(i)){const r=this._updateNode(new su(i));return this._forwardTypeCount++,r}return this._updateNode(new k(i))}let e=this._texture_sampler_types();if(e)return e;if(this._check(p.template_types)){let i=this._advance().toString(),r=null,s=null;return this._match(p.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(p.tokens.comma)&&(s=this._consume(p.access_mode,"Expected access_mode for pointer").toString()),this._consume(p.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new T(i,r,s))}if(this._match(p.keywords.ptr)){let i=this._previous().toString();this._consume(p.tokens.less_than,"Expected '<' for pointer.");const r=this._consume(p.storage_class,"Expected storage_class for pointer");this._consume(p.tokens.comma,"Expected ',' for pointer.");const s=this._type_decl();let o=null;return this._match(p.tokens.comma)&&(o=this._consume(p.access_mode,"Expected access_mode for pointer").toString()),this._consume(p.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new hr(i,r.toString(),s,o))}const t=this._attribute();if(this._match(p.keywords.array)){let i=null,r=-1;const s=this._previous();let o=null;if(this._match(p.tokens.less_than)){i=this._type_decl(),this._context.aliases.has(i.name)&&(i=this._context.aliases.get(i.name).type);let l="";if(this._match(p.tokens.comma)){o=this._shift_expression();try{l=o.constEvaluate(this._exec).toString(),o=null}catch{l="1"}}this._consume(p.tokens.greater_than,"Expected '>' for array."),r=l?parseInt(l):0}const a=this._updateNode(new Jn(s.toString(),t,i,r));return o&&this._deferArrayCountEval.push({arrayType:a,countNode:o}),a}return null}_texture_sampler_types(){if(this._match(p.sampler_type))return this._updateNode(new Gn(this._previous().toString(),null,null));if(this._match(p.depth_texture_type))return this._updateNode(new Gn(this._previous().toString(),null,null));if(this._match(p.sampled_texture_type)||this._match(p.multisampled_texture_type)){const e=this._previous();this._consume(p.tokens.less_than,"Expected '<' for sampler type.");const t=this._type_decl();return this._consume(p.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Gn(e.toString(),t,null))}if(this._match(p.storage_texture_type)){const e=this._previous();this._consume(p.tokens.less_than,"Expected '<' for sampler type.");const t=this._consume(p.texel_format,"Invalid texel format.").toString();this._consume(p.tokens.comma,"Expected ',' after texel format.");const i=this._consume(p.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(p.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Gn(e.toString(),t,i))}return null}_attribute(){let e=[];for(;this._match(p.tokens.attr);){const t=this._consume(p.attribute_name,"Expected attribute name"),i=this._updateNode(new pu(t.toString(),null));if(this._match(p.tokens.paren_left)){if(i.value=this._consume(p.literal_or_ident,"Expected attribute value").toString(),this._check(p.tokens.comma)){this._advance();do{const r=this._consume(p.literal_or_ident,"Expected attribute value").toString();i.value instanceof Array||(i.value=[i.value]),i.value.push(r)}while(this._match(p.tokens.comma))}this._consume(p.tokens.paren_right,"Expected ')'")}e.push(i)}return e.length==0?null:e}}class d0 extends _t{constructor(e){super(),e&&this.update(e)}update(e){const t=new h0().parse(e);this.updateAST(t)}}function p0(n){var s;const e={attributes:[],bindings:[]};let t;try{t=m0(n)}catch(o){return D.error(o.message)(),e}for(const o of t.uniforms){const a=[];for(const l of((s=o.type)==null?void 0:s.members)||[])a.push({name:l.name,type:_u(l.type)});e.bindings.push({type:"uniform",name:o.name,group:o.group,location:o.binding,members:a})}for(const o of t.textures)e.bindings.push({type:"texture",name:o.name,group:o.group,location:o.binding});for(const o of t.samplers)e.bindings.push({type:"sampler",name:o.name,group:o.group,location:o.binding});const i=t.entry.vertex[0],r=(i==null?void 0:i.inputs.length)||0;for(let o=0;o<r;o++){const a=i.inputs[o];if(a.locationType==="location"){const l=_u(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:l})}}return e}function _u(n){return n!=null&&n.format?`${n.name}<${n.format.name}>`:n.name}function m0(n){try{return new d0(n)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&(e!=null&&e.message)&&(t+=`: ${e.message} `),typeof e=="object"&&(e!=null&&e.token)&&(t+=e.token.line||""),new Error(t,{cause:e})}}const Ao={};function xr(n="id"){Ao[n]=Ao[n]||1;const e=Ao[n]++;return`${n}-${e}`}class xu{constructor(e){m(this,"id");m(this,"userData",{});m(this,"topology");m(this,"bufferLayout",[]);m(this,"vertexCount");m(this,"indices");m(this,"attributes");if(this.id=e.id||xr("geometry"),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&L.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){var e;(e=this.indices)==null||e.destroy();for(const t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}}function g0(n,e){if(e instanceof xu)return e;const t=_0(n,e),{attributes:i,bufferLayout:r}=x0(n,e);return new xu({topology:e.topology||"triangle-list",bufferLayout:r,vertexCount:e.vertexCount,indices:t,attributes:i})}function _0(n,e){if(!e.indices)return;const t=e.indices.value;return n.createBuffer({usage:L.INDEX,data:t})}function x0(n,e){const t=[],i={};for(const[s,o]of Object.entries(e.attributes)){let a=s;switch(s){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){i[a]=n.createBuffer({data:o.value,id:`${s}-buffer`});const{value:l,size:c,normalized:u}=o;t.push({name:a,format:Bp(l,c,u)})}}const r=e._calculateVertexCount(e.attributes,e.indices);return{attributes:i,bufferLayout:t,vertexCount:r}}const Fr=class Fr{constructor(e){m(this,"device");m(this,"cachingEnabled");m(this,"destroyPolicy");m(this,"debug");m(this,"_hashCounter",0);m(this,"_hashes",{});m(this,"_renderPipelineCache",{});m(this,"_computePipelineCache",{});this.device=e,this.cachingEnabled=e.props._cachePipelines,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=e.props.debugFactories}static getDefaultPipelineFactory(e){return e._lumaData.defaultPipelineFactory=e._lumaData.defaultPipelineFactory||new Fr(e),e._lumaData.defaultPipelineFactory}get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}createRenderPipeline(e){var o;if(!this.cachingEnabled)return this.device.createRenderPipeline(e);const t={...$t.defaultProps,...e},i=this._renderPipelineCache,r=this._hashRenderPipeline(t);let s=(o=i[r])==null?void 0:o.pipeline;return s?(i[r].useCount++,this.debug&&D.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${e.id})`)()):(s=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:xr("unnamed-cached")}),s.hash=r,i[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${i[r].useCount}`)()),s}createComputePipeline(e){var o;if(!this.cachingEnabled)return this.device.createComputePipeline(e);const t={...Bi.defaultProps,...e},i=this._computePipelineCache,r=this._hashComputePipeline(t);let s=(o=i[r])==null?void 0:o.pipeline;return s?(i[r].useCount++,this.debug&&D.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${e.id})`)()):(s=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),s.hash=r,i[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${i[r].useCount}`)()),s}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._getCache(e),i=e.hash;t[i].useCount--,t[i].useCount===0?(this._destroyPipeline(e),this.debug&&D.log(3,`${this}: ${e} released and destroyed`)()):t[i].useCount<0?(D.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[i].useCount=0):this.debug&&D.log(3,`${this}: ${e} released, count=${t[i].useCount}`)()}_destroyPipeline(e){const t=this._getCache(e);switch(this.destroyPolicy){case"never":return!1;case"unused":return delete t[e.hash],e.destroy(),!0}}_getCache(e){let t;if(e instanceof Bi&&(t=this._computePipelineCache),e instanceof $t&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){const{type:t}=this.device,i=this._getHash(e.shader.source);return`${t}/C/${i}`}_hashRenderPipeline(e){const t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,r="-",s=this._getHash(JSON.stringify(e.bufferLayout)),{type:o}=this.device;switch(o){case"webgl":return`${o}/R/${t}/${i}V${r}BL${s}`;case"webgpu":default:const a=this._getHash(JSON.stringify(e.parameters));return`${o}/R/${t}/${i}V${r}T${e.topology}P${a}BL${s}`}}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}};m(Fr,"defaultProps",{...$t.defaultProps});let Co=Fr;const Mr=class Mr{constructor(e){m(this,"device");m(this,"cachingEnabled");m(this,"destroyPolicy");m(this,"debug");m(this,"_cache",{});this.device=e,this.cachingEnabled=e.props._cacheShaders,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=!0}static getDefaultShaderFactory(e){var t;return(t=e._lumaData).defaultShaderFactory||(t.defaultShaderFactory=new Mr(e)),e._lumaData.defaultShaderFactory}get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}createShader(e){if(!this.cachingEnabled)return this.device.createShader(e);const t=this._hashShader(e);let i=this._cache[t];if(i)i.useCount++,this.debug&&D.log(3,`${this}: Reusing shader ${i.shader.id} count=${i.useCount}`)();else{const r=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=i={shader:r,useCount:1},this.debug&&D.log(3,`${this}: Created new shader ${r.id}`)()}return i.shader}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._hashShader(e),i=this._cache[t];if(i)if(i.useCount--,i.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[t],i.shader.destroy(),this.debug&&D.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.debug&&D.log(3,`${this}: Releasing shader ${e.id} count=${i.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}};m(Mr,"defaultProps",{...Ni.defaultProps});let Io=Mr;function y0(n,e){var r;const t={},i="Values";if(n.attributes.length===0&&!((r=n.varyings)!=null&&r.length))return{"No attributes or varyings":{[i]:"N/A"}};for(const s of n.attributes)if(s){const o=`${s.location} ${s.name}: ${s.type}`;t[`in ${o}`]={[i]:s.stepMode||"vertex"}}for(const s of n.varyings||[]){const o=`${s.location} ${s.name}`;t[`out ${o}`]={[i]:JSON.stringify(s)}}return t}let Pe=null,Zt=null;function v0(n,{id:e,minimap:t,opaque:i,top:r="0",left:s="0",rgbaScale:o=1}){Pe||(Pe=document.createElement("canvas"),Pe.id=e,Pe.title=e,Pe.style.zIndex="100",Pe.style.position="absolute",Pe.style.top=r,Pe.style.left=s,Pe.style.border="blue 5px solid",Pe.style.transform="scaleY(-1)",document.body.appendChild(Pe),Zt=Pe.getContext("2d")),(Pe.width!==n.width||Pe.height!==n.height)&&(Pe.width=n.width/2,Pe.height=n.height/2,Pe.style.width="400px",Pe.style.height="400px");const a=n.device.readPixelsToArrayWebGL(n),l=Zt==null?void 0:Zt.createImageData(n.width,n.height);if(l){for(let u=0;u<a.length;u+=4)l.data[0+u+0]=a[u+0]*o,l.data[0+u+1]=a[u+1]*o,l.data[0+u+2]=a[u+2]*o,l.data[0+u+3]=i?255:a[u+3]*o;Zt==null||Zt.putImageData(l,0,0)}}function Po(n,e,t){if(n===e)return!0;if(!t||!n||!e)return!1;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let i=0;i<n.length;i++)if(!Po(n[i],e[i],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof n=="object"&&typeof e=="object"){const i=Object.keys(n),r=Object.keys(e);if(i.length!==r.length)return!1;for(const s of i)if(!e.hasOwnProperty(s)||!Po(n[s],e[s],t-1))return!1;return!0}return!1}class Eo{constructor(e){m(this,"bufferLayouts");this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(t=>t.name===e)||null}getAttributeNamesForBuffer(e){var t;return e.attributes?(t=e.attributes)==null?void 0:t.map(i=>i.attribute):[e.name]}mergeBufferLayouts(e,t){const i=[...e];for(const r of t){const s=i.findIndex(o=>o.name===r.name);s<0?i.push(r):i[s]=r}return i}getBufferIndex(e){const t=this.bufferLayouts.findIndex(i=>i.name===e);return t===-1&&D.warn(`BufferLayout: Missing buffer for "${e}".`)(),t}}function b0(n,e){const t=Object.fromEntries(n.attributes.map(r=>[r.name,r.location])),i=e.slice();return i.sort((r,s)=>{const o=r.attributes?r.attributes.map(u=>u.attribute):[r.name],a=s.attributes?s.attributes.map(u=>u.attribute):[s.name],l=Math.min(...o.map(u=>t[u])),c=Math.min(...a.map(u=>t[u]));return l-c}),i}function S0(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function T0(n){return Array.isArray(n)?n.length===0||typeof n[0]=="number":!1}function w0(n){return S0(n)||T0(n)}function A0(n){return w0(n)||typeof n=="number"||typeof n=="boolean"}function C0(n){const e={bindings:{},uniforms:{}};return Object.keys(n).forEach(t=>{const i=n[t];A0(i)?e.uniforms[t]=i:e.bindings[t]=i}),e}class I0{constructor(e,t){m(this,"options",{disableWarnings:!1});m(this,"modules");m(this,"moduleUniforms");m(this,"moduleBindings");Object.assign(this.options,t);const i=ao(Object.values(e).filter(r=>r.dependencies));for(const r of i)e[r.name]=r;D.log(1,"Creating ShaderInputs with modules",Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(const[r,s]of Object.entries(e))this._addModule(s),s.name&&r!==s.name&&!this.options.disableWarnings&&D.warn(`Module name: ${r} vs ${s.name}`)()}destroy(){}setProps(e){var t;for(const i of Object.keys(e)){const r=i,s=e[r]||{},o=this.modules[r];if(!o){this.options.disableWarnings||D.warn(`Module ${i} not found`)();continue}const a=this.moduleUniforms[r],l=this.moduleBindings[r],c=((t=o.getUniforms)==null?void 0:t.call(o,s,a))||s,{uniforms:u,bindings:f}=C0(c);this.moduleUniforms[r]={...a,...u},this.moduleBindings[r]={...l,...f}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){const e={};for(const t of Object.values(this.moduleBindings))Object.assign(e,t);return e}getDebugTable(){var t;const e={};for(const[i,r]of Object.entries(this.moduleUniforms))for(const[s,o]of Object.entries(r))e[`${i}.${s}`]={type:(t=this.modules[i].uniformTypes)==null?void 0:t[s],value:String(o)};return e}_addModule(e){const t=e.name;this.moduleUniforms[t]=e.defaultUniforms||{},this.moduleBindings[t]={}}}let P0="";async function E0(n,e){const t=new Image;return t.crossOrigin="anonymous",t.src=n.startsWith("http")?n:P0+n,await t.decode(),e?await createImageBitmap(t,e):await createImageBitmap(t)}const R0=["+X","-X","+Y","-Y","+Z","-Z"],k0=["+X","-X","+Y","-Y","+Z","-Z"],Nr=class Nr{constructor(e,t){m(this,"device");m(this,"id");m(this,"props");m(this,"texture");m(this,"sampler");m(this,"view");m(this,"ready");m(this,"isReady",!1);m(this,"destroyed",!1);m(this,"resolveReady",()=>{});m(this,"rejectReady",()=>{});this.device=e;const i=xr("async-texture");this.props={...Nr.defaultProps,id:i,...t},this.id=this.props.id,t={...t},typeof(t==null?void 0:t.data)=="string"&&t.dimension==="2d"&&(t.data=E0(t.data)),t.mipmaps&&(t.mipLevels="auto"),this.ready=new Promise((r,s)=>{this.resolveReady=()=>{this.isReady=!0,r()},this.rejectReady=s}),this.initAsync(t)}get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}async initAsync(e){const t=e.data,i=await yu(t).then(void 0,this.rejectReady);if(this.destroyed)return;const r=this.props.width&&this.props.height?{width:this.props.width,height:this.props.height}:this.getTextureDataSize(i);if(!r)throw new Error("Texture size could not be determined");const s={...r,...e,data:void 0,mipLevels:1},o=this.device.getMipLevelCount(s.width,s.height);if(s.mipLevels=this.props.mipLevels==="auto"?o:Math.min(o,this.props.mipLevels),this.texture=this.device.createTexture(s),this.sampler=this.texture.sampler,this.view=this.texture.view,e.data)switch(this.props.dimension){case"1d":this._setTexture1DData(this.texture,i);break;case"2d":this._setTexture2DData(i);break;case"3d":this._setTexture3DData(this.texture,i);break;case"2d-array":this._setTextureArrayData(this.texture,i);break;case"cube":this._setTextureCubeData(this.texture,i);break;case"cube-array":this._setTextureCubeArrayData(this.texture,i);break}this.props.mipmaps&&this.generateMipmaps(),D.info(1,`${this} loaded`),this.resolveReady()}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}generateMipmaps(){this.texture.generateMipmapsWebGL()}setSampler(e={}){this.texture.setSampler(e instanceof un?e:this.device.createSampler(e))}resize(e){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(e.width===this.texture.width&&e.height===this.texture.height)return!1;if(this.texture){const t=this.texture;this.texture=t.clone(e),t.destroy()}return!0}isTextureLevelData(e){const t=e==null?void 0:e.data;return ArrayBuffer.isView(t)}getTextureDataSize(e){if(!e||ArrayBuffer.isView(e))return null;if(Array.isArray(e))return this.getTextureDataSize(e[0]);if(this.device.isExternalImage(e))return this.device.getExternalImageSize(e);if(e&&typeof e=="object"&&e.constructor===Object){const i=Object.values(e)[0];return{width:i.width,height:i.height}}throw new Error("texture size deduction failed")}getCubeFaceDepth(e){switch(e){case"+X":return 0;case"-X":return 1;case"+Y":return 2;case"-Y":return 3;case"+Z":return 4;case"-Z":return 5;default:throw new Error(e)}}setTextureData(e){}_setTexture1DData(e,t){throw new Error("setTexture1DData not supported in WebGL.")}_setTexture2DData(e,t=0){if(!this.texture)throw new Error("Texture not initialized");const i=this._normalizeTextureData(e);i.length>1&&this.props.mipmaps!==!1&&D.warn(`Texture ${this.id} mipmap and multiple LODs.`)();for(let r=0;r<i.length;r++){const s=i[r];this.device.isExternalImage(s)?this.texture.copyExternalImage({image:s,depth:t,mipLevel:r,flipY:!0}):this.texture.copyImageData({data:s.data,mipLevel:r})}}_setTexture3DData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="3d")throw new Error(this.id);for(let r=0;r<t.length;r++)this._setTexture2DData(t[r],r)}_setTextureCubeData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="cube")throw new Error(this.id);for(const[r,s]of Object.entries(t)){const o=k0.indexOf(r);this._setTexture2DData(s,o)}}_setTextureArrayData(e,t){var i;if(((i=this.texture)==null?void 0:i.props.dimension)!=="2d-array")throw new Error(this.id);for(let r=0;r<t.length;r++)this._setTexture2DData(t[r],r)}_setTextureCubeArrayData(e,t){throw new Error("setTextureCubeArrayData not supported in WebGL2.")}_setTextureCubeFaceData(e,t,i,r=0){Array.isArray(t)&&t.length>1&&this.props.mipmaps!==!1&&D.warn(`${this.id} has mipmap and multiple LODs.`)();const s=R0.indexOf(i);this._setTexture2DData(t,s)}_normalizeTextureData(e){const t=this.texture;let i;return ArrayBuffer.isView(e)?i=[{data:e,width:t.width,height:t.height}]:Array.isArray(e)?i=e:i=[e],i}};m(Nr,"defaultProps",{...Q.defaultProps,data:null,mipmaps:!1});let ei=Nr;async function yu(n){if(n=await n,Array.isArray(n))return await Promise.all(n.map(yu));if(n&&typeof n=="object"&&n.constructor===Object){const e=n,t=await Promise.all(Object.values(e)),i=Object.keys(e),r={};for(let s=0;s<i.length;s++)r[i[s]]=t[s];return r}return n}const Qt=2,D0=1e4,Or=class Or{constructor(e,t){m(this,"device");m(this,"id");m(this,"source");m(this,"vs");m(this,"fs");m(this,"pipelineFactory");m(this,"shaderFactory");m(this,"userData",{});m(this,"parameters");m(this,"topology");m(this,"bufferLayout");m(this,"isInstanced");m(this,"instanceCount",0);m(this,"vertexCount");m(this,"indexBuffer",null);m(this,"bufferAttributes",{});m(this,"constantAttributes",{});m(this,"bindings",{});m(this,"vertexArray");m(this,"transformFeedback",null);m(this,"pipeline");m(this,"shaderInputs");m(this,"_uniformStore");m(this,"_attributeInfos",{});m(this,"_gpuGeometry",null);m(this,"props");m(this,"_pipelineNeedsUpdate","newly created");m(this,"_needsRedraw","initializing");m(this,"_destroyed",!1);m(this,"_lastDrawTimestamp",-1);m(this,"_lastLogTime",0);m(this,"_logOpen",!1);m(this,"_drawCount",0);var l,c,u,f;this.props={...Or.defaultProps,...t},t=this.props,this.id=t.id||xr("model"),this.device=e,Object.assign(this.userData,t.userData);const i=Object.fromEntries(((l=this.props.modules)==null?void 0:l.map(h=>[h.name,h]))||[]),r=t.shaderInputs||new I0(i,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);const s=M0(e),o=(((c=this.props.modules)==null?void 0:c.length)>0?this.props.modules:(u=this.shaderInputs)==null?void 0:u.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){const{source:h,getUniforms:d}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:s,...this.props,modules:o});this.source=h,this._getModuleUniforms=d,(f=this.props).shaderLayout||(f.shaderLayout=p0(this.source))}else{const{vs:h,fs:d,getUniforms:_}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:s,...this.props,modules:o});this.vs=h,this.fs=d,this._getModuleUniforms=_}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,t.geometry&&this.setGeometry(t.geometry),this.pipelineFactory=t.pipelineFactory||Co.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||Io.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in t&&(this.isInstanced=t.isInstanced),t.instanceCount&&this.setInstanceCount(t.instanceCount),t.vertexCount&&this.setVertexCount(t.vertexCount),t.indexBuffer&&this.setIndexBuffer(t.indexBuffer),t.attributes&&this.setAttributes(t.attributes),t.constantAttributes&&this.setConstantAttributes(t.constantAttributes),t.bindings&&this.setBindings(t.bindings),t.transformFeedback&&(this.transformFeedback=t.transformFeedback),Object.seal(this)}get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}destroy(){var e;this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),(e=this._gpuGeometry)==null||e.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");const e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||(this._needsRedraw=e)}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(e){const t=this._areBindingsLoading();if(t)return D.info(Qt,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;try{e.pushDebugGroup(`${this}.predraw(${e})`),this.predraw()}finally{e.popDebugGroup()}let i;try{e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();const r=this._getBindings();this.pipeline.setBindings(r,{disableWarnings:this.props.disableWarnings});const{indexBuffer:s}=this.vertexArray,o=s?s.byteLength/(s.indexType==="uint32"?4:2):void 0;i=this.pipeline.draw({renderPass:e,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),i?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",i}setGeometry(e){var i;(i=this._gpuGeometry)==null||i.destroy();const t=e&&g0(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");const r=new Eo(this.bufferLayout);this.bufferLayout=r.mergeBufferLayouts(t.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(t)}this._gpuGeometry=t}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(e){const t=new Eo(this.bufferLayout);this.bufferLayout=this._gpuGeometry?t.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(e){Po(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw("vertexCount")}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new _e(this.shaderInputs.modules);for(const[t,i]of Object.entries(this.shaderInputs.modules))if(F0(i)){const r=this._uniformStore.getManagedUniformBuffer(this.device,t);this.bindings[`${t}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw("bindings")}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(e){this.vertexArray.setIndexBuffer(e),this.setNeedsRedraw("indexBuffer")}setAttributes(e,t){const i=(t==null?void 0:t.disableWarnings)??this.props.disableWarnings;e.indices&&D.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=b0(this.pipeline.shaderLayout,this.bufferLayout);const r=new Eo(this.bufferLayout);for(const[s,o]of Object.entries(e)){const a=r.getBufferLayout(s);if(!a){i||D.warn(`Model(${this.id}): Missing layout for buffer "${s}".`)();continue}const l=r.getAttributeNamesForBuffer(a);let c=!1;for(const u of l){const f=this._attributeInfos[u];if(f){const h=this.device.type==="webgpu"?r.getBufferIndex(f.bufferName):f.location;this.vertexArray.setBuffer(h,o),c=!0}}!c&&!i&&D.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${s}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(const[i,r]of Object.entries(e)){const s=this._attributeInfos[i];s?this.vertexArray.setConstantWebGL(s.location,r):((t==null?void 0:t.disableWarnings)??this.props.disableWarnings)||D.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${i}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(const e of Object.values(this.bindings))if(e instanceof ei&&!e.isReady)return e.id;return!1}_getBindings(){const e={};for(const[t,i]of Object.entries(this.bindings))i instanceof ei?i.isReady&&(e[t]=i.texture):e[t]=i;return e}_getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof Mi?e=Math.max(e,t.texture.updateTimestamp):t instanceof L||t instanceof Q?e=Math.max(e,t.updateTimestamp):t instanceof ei?e=t.texture?Math.max(e,t.texture.updateTimestamp):1/0:t instanceof un||(e=Math.max(e,t.buffer.updateTimestamp));return e}_setGeometryAttributes(e){const t={...e.attributes};for(const[i]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(r=>r.name===i)&&i!=="positions"&&delete t[i];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(t,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||(this._pipelineNeedsUpdate=e),this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,t=null;this.pipeline&&(D.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,t=this.pipeline.fs),this._pipelineNeedsUpdate=!1;const i=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders});let r=null;this.source?r=i:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:i,fs:r}),this._attributeInfos=Ga(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),t&&this.shaderFactory.release(t)}return this.pipeline}_logDrawCallStart(){const e=D.level>3?0:D0;D.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,D.group(Qt,`>>> DRAWING MODEL ${this.id}`,{collapsed:D.level<=2})())}_logDrawCallEnd(){if(this._logOpen){const e=y0(this.pipeline.shaderLayout,this.id);D.table(Qt,e)();const t=this.shaderInputs.getDebugTable();D.table(Qt,t)();const i=this._getAttributeDebugTable();D.table(Qt,this._attributeInfos)(),D.table(Qt,i)(),D.groupEnd(Qt)(),this._logOpen=!1}}_logFramebuffer(e){const t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;const i=e.props.framebuffer;i&&v0(i,{id:i.id,minimap:!0})}_getAttributeDebugTable(){const e={};for(const[t,i]of Object.entries(this._attributeInfos)){const r=this.vertexArray.attributes[i.location];e[i.location]={name:t,type:i.shaderType,values:r?this._getBufferOrConstantValues(r,i.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){const{indexBuffer:t}=this.vertexArray,i=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:i.toString()}}return e}_getBufferOrConstantValues(e,t){const i=$a(t);return(e instanceof L?new i(e.debugData):e).toString()}};m(Or,"defaultProps",{...$t.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:co.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});let pe=Or;function F0(n){return!!(n.uniformTypes&&!N0(n.uniformTypes))}function M0(n){return{type:n.type,shaderLanguage:n.info.shadingLanguage,shaderLanguageVersion:n.info.shadingLanguageVersion,gpu:n.info.gpu,features:n.features}}function N0(n){for(const e in n)return!1;return!0}class Ot{constructor(e,t,i,r,s){this._debugRandomNumber=Math.floor(Math.random()*1e3),this.device=e,this.config=t,this.store=i,this.data=r,s&&(this.points=s)}}const O0=`#version 300 es
97
97
  precision highp float;
98
98
 
99
99
  in vec4 rgba;
@@ -101,7 +101,7 @@ out vec4 fragColor;
101
101
 
102
102
  void main() {
103
103
  fragColor = rgba;
104
- }`,W0=`#version 300 es
104
+ }`,B0=`#version 300 es
105
105
  precision highp float;
106
106
 
107
107
  uniform sampler2D positionsTexture;
@@ -127,7 +127,7 @@ void main() {
127
127
  gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
128
128
  gl_PointSize = 1.0;
129
129
  }
130
- `,$0=`#version 300 es
130
+ `,U0=`#version 300 es
131
131
  precision highp float;
132
132
 
133
133
  uniform sampler2D positionsTexture;
@@ -163,7 +163,7 @@ void main() {
163
163
  }
164
164
 
165
165
  fragColor = velocity;
166
- }`;function yr(n){const e=new Float32Array(n*n*2);for(let t=0;t<n;t++)for(let i=0;i<n;i++){const r=t*n*2+i*2;e[r+0]=i,e[r+1]=t}return e}function ie(n,e){const t=Vt.getInfo(n);return e*(t.bytesPerPixel??0)}const tt=`#version 300 es
166
+ }`;function yr(n){const e=new Float32Array(n*n*2);for(let t=0;t<n;t++)for(let i=0;i<n;i++){const r=t*n*2+i*2;e[r+0]=i,e[r+1]=t}return e}function te(n,e){const t=Ht.getInfo(n);return e*(t.bytesPerPixel??0)}const nt=`#version 300 es
167
167
  #ifdef GL_ES
168
168
  precision highp float;
169
169
  #endif
@@ -176,7 +176,7 @@ void main() {
176
176
  textureCoords = (vertexCoord + 1.0) / 2.0;
177
177
  gl_Position = vec4(vertexCoord, 0, 1);
178
178
  }
179
- `;class X0 extends Nt{create(){var r;const{device:e,store:t}=this,{pointsTextureSize:i}=t;if(i){if(this.centermassTexture||(this.centermassTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST})),this.centermassTexture.copyImageData({data:new Float32Array(4).fill(0),bytesPerRow:ie("rgba32float",1),mipLevel:0,x:0,y:0}),this.centermassFbo||(this.centermassFbo=e.createFramebuffer({width:1,height:1,colorAttachments:[this.centermassTexture]})),!this.pointIndices||this.previousPointsTextureSize!==t.pointsTextureSize){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const s=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:s,usage:L.VERTEX|L.COPY_DST}),(r=this.calculateCentermassCommand)==null||r.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=i}}initPrograms(){const{device:e,store:t,points:i}=this;!i||!t.pointsTextureSize||!this.centermassFbo||this.centermassFbo.destroyed||!this.centermassTexture||this.centermassTexture.destroyed||(this.forceVertexCoordBuffer||(this.forceVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.calculateUniformStore||(this.calculateUniformStore=new xe({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32"}}})),this.forceUniformStore||(this.forceUniformStore=new xe({forceCenterUniforms:{uniformTypes:{centerForce:"f32",alpha:"f32"}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new me(e,{fs:H0,vs:W0,topology:"point-list",attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateCentermassUniforms:this.calculateUniformStore.getManagedUniformBuffer(e,"calculateCentermassUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.calculateCentermassCommand.setVertexCount(this.data.pointsNumber??0),this.runCommand||(this.runCommand=new me(e,{fs:$0,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceCenterUniforms:this.forceUniformStore.getManagedUniformBuffer(e,"forceCenterUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,store:t,points:i}=this;if(!i||!this.calculateCentermassCommand||!this.calculateUniformStore||!this.runCommand||!this.forceUniformStore||!this.centermassFbo||!this.centermassTexture||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!i.velocityFbo||i.velocityFbo.destroyed||t.pointsTextureSize!==this.previousPointsTextureSize||!this.pointIndices)return;const r=e.beginRenderPass({framebuffer:this.centermassFbo,clearColor:[0,0,0,0]});this.calculateUniformStore.setUniforms({calculateCentermassUniforms:{pointsTextureSize:t.pointsTextureSize??0}}),this.calculateCentermassCommand.setBindings({positionsTexture:i.previousPositionTexture}),this.calculateCentermassCommand.draw(r),r.end(),this.forceUniformStore.setUniforms({forceCenterUniforms:{centerForce:this.config.simulationCenter??0,alpha:t.alpha}}),this.runCommand.setBindings({positionsTexture:i.previousPositionTexture,centermassTexture:this.centermassTexture});const s=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(s),s.end()}destroy(){var e,t,i,r;(e=this.calculateCentermassCommand)==null||e.destroy(),this.calculateCentermassCommand=void 0,(t=this.runCommand)==null||t.destroy(),this.runCommand=void 0,this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassFbo=void 0,this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=void 0,(i=this.calculateUniformStore)==null||i.destroy(),this.calculateUniformStore=void 0,(r=this.forceUniformStore)==null||r.destroy(),this.forceUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.forceVertexCoordBuffer&&!this.forceVertexCoordBuffer.destroyed&&this.forceVertexCoordBuffer.destroy(),this.forceVertexCoordBuffer=void 0,this.previousPointsTextureSize=void 0}}const Y0=`#version 300 es
179
+ `;class z0 extends Ot{create(){var r;const{device:e,store:t}=this,{pointsTextureSize:i}=t;if(i){if(this.centermassTexture||(this.centermassTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST})),this.centermassTexture.copyImageData({data:new Float32Array(4).fill(0),bytesPerRow:te("rgba32float",1),mipLevel:0,x:0,y:0}),this.centermassFbo||(this.centermassFbo=e.createFramebuffer({width:1,height:1,colorAttachments:[this.centermassTexture]})),!this.pointIndices||this.previousPointsTextureSize!==t.pointsTextureSize){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const s=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:s,usage:L.VERTEX|L.COPY_DST}),(r=this.calculateCentermassCommand)==null||r.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=i}}initPrograms(){const{device:e,store:t,points:i}=this;!i||!t.pointsTextureSize||!this.centermassFbo||this.centermassFbo.destroyed||!this.centermassTexture||this.centermassTexture.destroyed||(this.forceVertexCoordBuffer||(this.forceVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.calculateUniformStore||(this.calculateUniformStore=new _e({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32"}}})),this.forceUniformStore||(this.forceUniformStore=new _e({forceCenterUniforms:{uniformTypes:{centerForce:"f32",alpha:"f32"}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new pe(e,{fs:O0,vs:B0,topology:"point-list",attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateCentermassUniforms:this.calculateUniformStore.getManagedUniformBuffer(e,"calculateCentermassUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.calculateCentermassCommand.setVertexCount(this.data.pointsNumber??0),this.runCommand||(this.runCommand=new pe(e,{fs:U0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceCenterUniforms:this.forceUniformStore.getManagedUniformBuffer(e,"forceCenterUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,store:t,points:i}=this;if(!i||!this.calculateCentermassCommand||!this.calculateUniformStore||!this.runCommand||!this.forceUniformStore||!this.centermassFbo||!this.centermassTexture||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!i.velocityFbo||i.velocityFbo.destroyed||t.pointsTextureSize!==this.previousPointsTextureSize||!this.pointIndices)return;const r=e.beginRenderPass({framebuffer:this.centermassFbo,clearColor:[0,0,0,0]});this.calculateUniformStore.setUniforms({calculateCentermassUniforms:{pointsTextureSize:t.pointsTextureSize??0}}),this.calculateCentermassCommand.setBindings({positionsTexture:i.previousPositionTexture}),this.calculateCentermassCommand.draw(r),r.end(),this.forceUniformStore.setUniforms({forceCenterUniforms:{centerForce:this.config.simulationCenter,alpha:t.alpha}}),this.runCommand.setBindings({positionsTexture:i.previousPositionTexture,centermassTexture:this.centermassTexture});const s=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(s),s.end()}destroy(){var e,t,i,r;(e=this.calculateCentermassCommand)==null||e.destroy(),this.calculateCentermassCommand=void 0,(t=this.runCommand)==null||t.destroy(),this.runCommand=void 0,this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassFbo=void 0,this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=void 0,(i=this.calculateUniformStore)==null||i.destroy(),this.calculateUniformStore=void 0,(r=this.forceUniformStore)==null||r.destroy(),this.forceUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.forceVertexCoordBuffer&&!this.forceVertexCoordBuffer.destroyed&&this.forceVertexCoordBuffer.destroy(),this.forceVertexCoordBuffer=void 0,this.previousPointsTextureSize=void 0}}const L0=`#version 300 es
180
180
  precision highp float;
181
181
 
182
182
  uniform sampler2D positionsTexture;
@@ -215,7 +215,7 @@ void main() {
215
215
  }
216
216
 
217
217
  fragColor = velocity;
218
- }`;class q0 extends Nt{initPrograms(){const{device:e,points:t,store:i}=this;!t||!i.pointsTextureSize||(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new xe({forceGravityUniforms:{uniformTypes:{gravity:"f32",spaceSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new me(e,{fs:Y0,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceGravityUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceGravityUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,points:t,store:i}=this;if(!t||!this.runCommand||!this.uniformStore||!t.previousPositionTexture||t.previousPositionTexture.destroyed||!t.velocityFbo||t.velocityFbo.destroyed)return;this.uniformStore.setUniforms({forceGravityUniforms:{gravity:this.config.simulationGravity??0,spaceSize:i.adjustedSpaceSize??0,alpha:i.alpha}}),this.runCommand.setBindings({positionsTexture:t.previousPositionTexture});const r=e.beginRenderPass({framebuffer:t.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}function j0(n){return`#version 300 es
218
+ }`;class V0 extends Ot{initPrograms(){const{device:e,points:t,store:i}=this;!t||!i.pointsTextureSize||(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new _e({forceGravityUniforms:{uniformTypes:{gravity:"f32",spaceSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new pe(e,{fs:L0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceGravityUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceGravityUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,points:t,store:i}=this;if(!t||!this.runCommand||!this.uniformStore||!t.previousPositionTexture||t.previousPositionTexture.destroyed||!t.velocityFbo||t.velocityFbo.destroyed)return;this.uniformStore.setUniforms({forceGravityUniforms:{gravity:this.config.simulationGravity,spaceSize:i.adjustedSpaceSize,alpha:i.alpha}}),this.runCommand.setBindings({positionsTexture:t.previousPositionTexture});const r=e.beginRenderPass({framebuffer:t.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}function H0(n){return`#version 300 es
219
219
  precision highp float;
220
220
 
221
221
  uniform sampler2D positionsTexture;
@@ -301,7 +301,7 @@ void main() {
301
301
 
302
302
  fragColor = vec4(velocity.rg, 0.0, 0.0);
303
303
  }
304
- `}function re(n,e){return!n||n.length!==2?e:[n[0],n[1]]}function Re(n,e){return!n||n.length!==4?e:[n[0],n[1],n[2],n[3]]}var Po=(n=>(n.OUTGOING="outgoing",n.INCOMING="incoming",n))(Po||{});class Cu extends Nt{constructor(){super(...arguments),this.linkFirstIndicesAndAmount=new Float32Array,this.indices=new Float32Array,this.maxPointDegree=0}create(e){var h;const{device:t,store:{pointsTextureSize:i,linksTextureSize:r},data:s}=this;if(!i||!r)return;this.linkFirstIndicesAndAmount=new Float32Array(i*i*4),this.indices=new Float32Array(r*r*4);const o=new Float32Array(r*r*4),a=new Float32Array(r*r*4),l=e==="incoming"?s.sourceIndexToTargetIndices:s.targetIndexToSourceIndices;this.maxPointDegree=0;let c=0;l==null||l.forEach((d,_)=>{d&&(this.linkFirstIndicesAndAmount[_*4+0]=c%r,this.linkFirstIndicesAndAmount[_*4+1]=Math.floor(c/r),this.linkFirstIndicesAndAmount[_*4+2]=d.length??0,d.forEach(([I,P])=>{var U,W,q;this.indices[c*4+0]=I%i,this.indices[c*4+1]=Math.floor(I/i);const A=((U=s.degree)==null?void 0:U[I])??0,O=((W=s.degree)==null?void 0:W[_])??0,E=A+O,x=E!==0?A/E:.5,R=Math.min(A,O);let N=((q=s.linkStrength)==null?void 0:q[P])??1/Math.max(R,1);N=Math.sqrt(N),o[c*4+0]=x,o[c*4+1]=N,a[c*4]=this.store.getRandomFloat(0,1),c+=1}),this.maxPointDegree=Math.max(this.maxPointDegree,d.length??0))});const u=!this.linkFirstIndicesAndAmountTexture||this.linkFirstIndicesAndAmountTexture.width!==i||this.linkFirstIndicesAndAmountTexture.height!==i,f=!this.indicesTexture||this.indicesTexture.width!==r||this.indicesTexture.height!==r;u&&(this.linkFirstIndicesAndAmountTexture&&!this.linkFirstIndicesAndAmountTexture.destroyed&&this.linkFirstIndicesAndAmountTexture.destroy(),this.linkFirstIndicesAndAmountTexture=t.createTexture({width:i,height:i,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.linkFirstIndicesAndAmountTexture.copyImageData({data:this.linkFirstIndicesAndAmount,bytesPerRow:ie("rgba32float",i),mipLevel:0,x:0,y:0}),f&&(this.indicesTexture&&!this.indicesTexture.destroyed&&this.indicesTexture.destroy(),this.biasAndStrengthTexture&&!this.biasAndStrengthTexture.destroyed&&this.biasAndStrengthTexture.destroy(),this.randomDistanceTexture&&!this.randomDistanceTexture.destroyed&&this.randomDistanceTexture.destroy(),this.indicesTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST}),this.biasAndStrengthTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST}),this.randomDistanceTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.indicesTexture.copyImageData({data:this.indices,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),this.biasAndStrengthTexture.copyImageData({data:o,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),this.randomDistanceTexture.copyImageData({data:a,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),this.previousMaxPointDegree!==void 0&&this.previousMaxPointDegree!==this.maxPointDegree&&((h=this.runCommand)==null||h.destroy(),this.runCommand=void 0),this.previousMaxPointDegree=this.maxPointDegree,this.previousPointsTextureSize=i,this.previousLinksTextureSize=r}initPrograms(){const{device:e,store:t,points:i}=this;!i||!t.pointsTextureSize||!t.linksTextureSize||!this.linkFirstIndicesAndAmountTexture||!this.indicesTexture||!this.biasAndStrengthTexture||!this.randomDistanceTexture||(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new xe({forceLinkUniforms:{uniformTypes:{linkSpring:"f32",linkDistance:"f32",linkDistRandomVariationRange:"vec2<f32>",pointsTextureSize:"f32",linksTextureSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new me(e,{fs:j0(this.maxPointDegree),vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceLinkUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceLinkUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,store:t,points:i}=this;if(!i||!this.runCommand||!this.uniformStore||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!this.linkFirstIndicesAndAmountTexture||!this.indicesTexture||!this.biasAndStrengthTexture||!this.randomDistanceTexture||!i.velocityFbo||i.velocityFbo.destroyed||t.pointsTextureSize!==this.previousPointsTextureSize||t.linksTextureSize!==this.previousLinksTextureSize)return;this.uniformStore.setUniforms({forceLinkUniforms:{linkSpring:this.config.simulationLinkSpring??0,linkDistance:this.config.simulationLinkDistance??0,linkDistRandomVariationRange:re(this.config.simulationLinkDistRandomVariationRange,[0,0]),pointsTextureSize:t.pointsTextureSize,linksTextureSize:t.linksTextureSize,alpha:t.alpha}}),this.runCommand.setBindings({positionsTexture:i.previousPositionTexture,linkInfoTexture:this.linkFirstIndicesAndAmountTexture,linkIndicesTexture:this.indicesTexture,linkPropertiesTexture:this.biasAndStrengthTexture,linkRandomDistanceTexture:this.randomDistanceTexture});const r=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,this.linkFirstIndicesAndAmountTexture&&!this.linkFirstIndicesAndAmountTexture.destroyed&&this.linkFirstIndicesAndAmountTexture.destroy(),this.linkFirstIndicesAndAmountTexture=void 0,this.indicesTexture&&!this.indicesTexture.destroyed&&this.indicesTexture.destroy(),this.indicesTexture=void 0,this.biasAndStrengthTexture&&!this.biasAndStrengthTexture.destroyed&&this.biasAndStrengthTexture.destroy(),this.biasAndStrengthTexture=void 0,this.randomDistanceTexture&&!this.randomDistanceTexture.destroyed&&this.randomDistanceTexture.destroy(),this.randomDistanceTexture=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}const K0=`#version 300 es
304
+ `}function ne(n,e){return!n||n.length!==2?e:[n[0],n[1]]}function Re(n,e){return!n||n.length!==4?e:[n[0],n[1],n[2],n[3]]}var Ro=(n=>(n.OUTGOING="outgoing",n.INCOMING="incoming",n))(Ro||{});class vu extends Ot{constructor(){super(...arguments),this.linkFirstIndicesAndAmount=new Float32Array,this.indices=new Float32Array,this.maxPointDegree=0}create(e){var h;const{device:t,store:{pointsTextureSize:i,linksTextureSize:r},data:s}=this;if(!i||!r)return;this.linkFirstIndicesAndAmount=new Float32Array(i*i*4),this.indices=new Float32Array(r*r*4);const o=new Float32Array(r*r*4),a=new Float32Array(r*r*4),l=e==="incoming"?s.sourceIndexToTargetIndices:s.targetIndexToSourceIndices;this.maxPointDegree=0;let c=0;l==null||l.forEach((d,_)=>{d&&(this.linkFirstIndicesAndAmount[_*4+0]=c%r,this.linkFirstIndicesAndAmount[_*4+1]=Math.floor(c/r),this.linkFirstIndicesAndAmount[_*4+2]=d.length??0,d.forEach(([I,P])=>{var U,H,Y;this.indices[c*4+0]=I%i,this.indices[c*4+1]=Math.floor(I/i);const A=((U=s.degree)==null?void 0:U[I])??0,O=((H=s.degree)==null?void 0:H[_])??0,E=A+O,y=E!==0?A/E:.5,R=Math.min(A,O);let N=((Y=s.linkStrength)==null?void 0:Y[P])??1/Math.max(R,1);N=Math.sqrt(N),o[c*4+0]=y,o[c*4+1]=N,a[c*4]=this.store.getRandomFloat(0,1),c+=1}),this.maxPointDegree=Math.max(this.maxPointDegree,d.length??0))});const u=!this.linkFirstIndicesAndAmountTexture||this.linkFirstIndicesAndAmountTexture.width!==i||this.linkFirstIndicesAndAmountTexture.height!==i,f=!this.indicesTexture||this.indicesTexture.width!==r||this.indicesTexture.height!==r;u&&(this.linkFirstIndicesAndAmountTexture&&!this.linkFirstIndicesAndAmountTexture.destroyed&&this.linkFirstIndicesAndAmountTexture.destroy(),this.linkFirstIndicesAndAmountTexture=t.createTexture({width:i,height:i,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.linkFirstIndicesAndAmountTexture.copyImageData({data:this.linkFirstIndicesAndAmount,bytesPerRow:te("rgba32float",i),mipLevel:0,x:0,y:0}),f&&(this.indicesTexture&&!this.indicesTexture.destroyed&&this.indicesTexture.destroy(),this.biasAndStrengthTexture&&!this.biasAndStrengthTexture.destroyed&&this.biasAndStrengthTexture.destroy(),this.randomDistanceTexture&&!this.randomDistanceTexture.destroyed&&this.randomDistanceTexture.destroy(),this.indicesTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST}),this.biasAndStrengthTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST}),this.randomDistanceTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.indicesTexture.copyImageData({data:this.indices,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),this.biasAndStrengthTexture.copyImageData({data:o,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),this.randomDistanceTexture.copyImageData({data:a,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),this.previousMaxPointDegree!==void 0&&this.previousMaxPointDegree!==this.maxPointDegree&&((h=this.runCommand)==null||h.destroy(),this.runCommand=void 0),this.previousMaxPointDegree=this.maxPointDegree,this.previousPointsTextureSize=i,this.previousLinksTextureSize=r}initPrograms(){const{device:e,store:t,points:i}=this;!i||!t.pointsTextureSize||!t.linksTextureSize||!this.linkFirstIndicesAndAmountTexture||!this.indicesTexture||!this.biasAndStrengthTexture||!this.randomDistanceTexture||(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new _e({forceLinkUniforms:{uniformTypes:{linkSpring:"f32",linkDistance:"f32",linkDistRandomVariationRange:"vec2<f32>",pointsTextureSize:"f32",linksTextureSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new pe(e,{fs:H0(this.maxPointDegree),vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceLinkUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceLinkUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,store:t,points:i}=this;if(!i||!this.runCommand||!this.uniformStore||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!this.linkFirstIndicesAndAmountTexture||!this.indicesTexture||!this.biasAndStrengthTexture||!this.randomDistanceTexture||!i.velocityFbo||i.velocityFbo.destroyed||t.pointsTextureSize!==this.previousPointsTextureSize||t.linksTextureSize!==this.previousLinksTextureSize)return;this.uniformStore.setUniforms({forceLinkUniforms:{linkSpring:this.config.simulationLinkSpring,linkDistance:this.config.simulationLinkDistance,linkDistRandomVariationRange:ne(this.config.simulationLinkDistRandomVariationRange,[0,0]),pointsTextureSize:t.pointsTextureSize,linksTextureSize:t.linksTextureSize,alpha:t.alpha}}),this.runCommand.setBindings({positionsTexture:i.previousPositionTexture,linkInfoTexture:this.linkFirstIndicesAndAmountTexture,linkIndicesTexture:this.indicesTexture,linkPropertiesTexture:this.biasAndStrengthTexture,linkRandomDistanceTexture:this.randomDistanceTexture});const r=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,this.linkFirstIndicesAndAmountTexture&&!this.linkFirstIndicesAndAmountTexture.destroyed&&this.linkFirstIndicesAndAmountTexture.destroy(),this.linkFirstIndicesAndAmountTexture=void 0,this.indicesTexture&&!this.indicesTexture.destroyed&&this.indicesTexture.destroy(),this.indicesTexture=void 0,this.biasAndStrengthTexture&&!this.biasAndStrengthTexture.destroyed&&this.biasAndStrengthTexture.destroy(),this.biasAndStrengthTexture=void 0,this.randomDistanceTexture&&!this.randomDistanceTexture.destroyed&&this.randomDistanceTexture.destroy(),this.randomDistanceTexture=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}const W0=`#version 300 es
305
305
  precision highp float;
306
306
 
307
307
  in vec4 vColor;
@@ -309,7 +309,7 @@ out vec4 fragColor;
309
309
 
310
310
  void main() {
311
311
  fragColor = vColor;
312
- }`,Z0=`#version 300 es
312
+ }`,$0=`#version 300 es
313
313
  precision highp float;
314
314
 
315
315
  uniform sampler2D positionsTexture;
@@ -345,7 +345,7 @@ void main() {
345
345
 
346
346
  gl_Position = vec4(levelPosition, 0.0, 1.0);
347
347
  gl_PointSize = 1.0;
348
- }`,Q0=`#version 300 es
348
+ }`,X0=`#version 300 es
349
349
  precision highp float;
350
350
 
351
351
  uniform sampler2D positionsTexture;
@@ -482,7 +482,7 @@ void main() {
482
482
  }
483
483
 
484
484
  fragColor = velocity;
485
- }`,J0=`#version 300 es
485
+ }`,Y0=`#version 300 es
486
486
  precision highp float;
487
487
 
488
488
  uniform sampler2D positionsTexture;
@@ -542,7 +542,7 @@ void main() {
542
542
  velocity.xy += velocity.xy * random.rg;
543
543
 
544
544
  fragColor = velocity;
545
- }`;class G0 extends Nt{constructor(){super(...arguments),this.levels=0,this.levelTargets=new Map}create(){var o;const{device:e,store:t}=this;if(!t.pointsTextureSize)return;this.levels=Math.log2(t.adjustedSpaceSize);for(let a=0;a<this.levels;a+=1){const l=Math.pow(2,a+1),c=this.levelTargets.get(a);if(c&&c.texture.width===l&&c.texture.height===l){c.texture.copyImageData({data:new Float32Array(l*l*4).fill(0),bytesPerRow:ie("rgba32float",l),mipLevel:0,x:0,y:0});continue}c&&(c.fbo.destroyed||c.fbo.destroy(),c.texture.destroyed||c.texture.destroy());const u=e.createTexture({width:l,height:l,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST});u.copyImageData({data:new Float32Array(l*l*4).fill(0),bytesPerRow:ie("rgba32float",l),mipLevel:0,x:0,y:0});const f=e.createFramebuffer({width:l,height:l,colorAttachments:[u]});this.levelTargets.set(a,{texture:u,fbo:f})}for(const[a,l]of Array.from(this.levelTargets.entries()))a>=this.levels&&(l.fbo.destroyed||l.fbo.destroy(),l.texture.destroyed||l.texture.destroy(),this.levelTargets.delete(a));const i=t.pointsTextureSize*t.pointsTextureSize,r=new Float32Array(i*4);for(let a=0;a<i;++a)r[a*4]=t.getRandomFloat(-1,1)*1e-5,r[a*4+1]=t.getRandomFloat(-1,1)*1e-5;if((!this.randomValuesTexture||this.randomValuesTexture.destroyed||this.randomValuesTexture.width!==t.pointsTextureSize||this.randomValuesTexture.height!==t.pointsTextureSize)&&(this.randomValuesTexture&&!this.randomValuesTexture.destroyed&&this.randomValuesTexture.destroy(),this.randomValuesTexture=e.createTexture({width:t.pointsTextureSize,height:t.pointsTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.randomValuesTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",t.pointsTextureSize),mipLevel:0,x:0,y:0}),!this.pointIndices||this.previousPointsTextureSize!==t.pointsTextureSize){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const a=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:a,usage:L.VERTEX|L.COPY_DST}),(o=this.calculateLevelsCommand)==null||o.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=t.pointsTextureSize,this.previousSpaceSize=t.adjustedSpaceSize}initPrograms(){const{device:e,store:t,data:i,points:r}=this;!i.pointsNumber||!r||!t.pointsTextureSize||(this.calculateLevelsUniformStore||(this.calculateLevelsUniformStore=new xe({calculateLevelsUniforms:{uniformTypes:{pointsTextureSize:"f32",levelTextureSize:"f32",cellSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,levelTextureSize:0,cellSize:0}}})),this.calculateLevelsCommand||(this.calculateLevelsCommand=new me(e,{fs:K0,vs:Z0,topology:"point-list",vertexCount:i.pointsNumber,attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateLevelsUniforms:this.calculateLevelsUniformStore.getManagedUniformBuffer(e,"calculateLevelsUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.forceUniformStore||(this.forceUniformStore=new xe({forceUniforms:{uniformTypes:{level:"f32",levels:"f32",levelTextureSize:"f32",alpha:"f32",repulsion:"f32",spaceSize:"f32",theta:"f32"},defaultUniforms:{level:0,levels:this.levels,levelTextureSize:0,alpha:t.alpha,repulsion:this.config.simulationRepulsion??0,spaceSize:t.adjustedSpaceSize??0,theta:this.config.simulationRepulsionTheta??0}}})),this.forceVertexCoordBuffer||(this.forceVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.forceCommand||(this.forceCommand=new me(e,{fs:Q0,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceUniforms:this.forceUniformStore.getManagedUniformBuffer(e,"forceUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.forceCenterUniformStore||(this.forceCenterUniformStore=new xe({forceCenterUniforms:{uniformTypes:{levelTextureSize:"f32",alpha:"f32",repulsion:"f32"},defaultUniforms:{levelTextureSize:0,alpha:t.alpha,repulsion:this.config.simulationRepulsion??0}}})),this.forceFromItsOwnCentermassCommand||(this.forceFromItsOwnCentermassCommand=new me(e,{fs:J0,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceCenterUniforms:this.forceCenterUniformStore.getManagedUniformBuffer(e,"forceCenterUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})))}run(){this.store.pointsTextureSize!==this.previousPointsTextureSize||this.store.adjustedSpaceSize!==this.previousSpaceSize||(this.drawLevels(),this.drawForces())}destroy(){var e,t,i,r,s,o;(e=this.calculateLevelsCommand)==null||e.destroy(),this.calculateLevelsCommand=void 0,(t=this.forceCommand)==null||t.destroy(),this.forceCommand=void 0,(i=this.forceFromItsOwnCentermassCommand)==null||i.destroy(),this.forceFromItsOwnCentermassCommand=void 0;for(const a of this.levelTargets.values())a.fbo&&!a.fbo.destroyed&&a.fbo.destroy();this.randomValuesTexture&&!this.randomValuesTexture.destroyed&&this.randomValuesTexture.destroy(),this.randomValuesTexture=void 0;for(const a of this.levelTargets.values())a.texture&&!a.texture.destroyed&&a.texture.destroy();this.levelTargets.clear(),(r=this.calculateLevelsUniformStore)==null||r.destroy(),this.calculateLevelsUniformStore=void 0,(s=this.forceUniformStore)==null||s.destroy(),this.forceUniformStore=void 0,(o=this.forceCenterUniformStore)==null||o.destroy(),this.forceCenterUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.forceVertexCoordBuffer&&!this.forceVertexCoordBuffer.destroyed&&this.forceVertexCoordBuffer.destroy(),this.forceVertexCoordBuffer=void 0}drawLevels(){const{device:e,store:t,data:i,points:r}=this;if(r&&!(!this.calculateLevelsCommand||!this.calculateLevelsUniformStore)&&!(!r.previousPositionTexture||r.previousPositionTexture.destroyed)&&i.pointsNumber&&this.pointIndices)for(let s=0;s<this.levels;s+=1){const o=this.levelTargets.get(s);if(!o||o.fbo.destroyed||o.texture.destroyed)continue;const a=Math.pow(2,s+1),l=(t.adjustedSpaceSize??0)/a;this.calculateLevelsUniformStore.setUniforms({calculateLevelsUniforms:{pointsTextureSize:t.pointsTextureSize??0,levelTextureSize:a,cellSize:l}}),this.calculateLevelsCommand.setVertexCount(i.pointsNumber),this.calculateLevelsCommand.setBindings({positionsTexture:r.previousPositionTexture});const c=e.beginRenderPass({framebuffer:o.fbo,clearColor:[0,0,0,0]});this.calculateLevelsCommand.draw(c),c.end()}}drawForces(){const{device:e,store:t,points:i}=this;if(!i||!this.forceCommand||!this.forceUniformStore||!this.forceFromItsOwnCentermassCommand||!this.forceCenterUniformStore||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!this.randomValuesTexture||this.randomValuesTexture.destroyed||!i.velocityFbo||i.velocityFbo.destroyed)return;const r=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});for(let s=0;s<this.levels;s+=1){const o=this.levelTargets.get(s);if(!o||o.texture.destroyed)continue;const a=Math.pow(2,s+1);this.forceUniformStore.setUniforms({forceUniforms:{level:s,levels:this.levels,levelTextureSize:a,alpha:t.alpha,repulsion:this.config.simulationRepulsion??0,spaceSize:t.adjustedSpaceSize??0,theta:this.config.simulationRepulsionTheta??0}}),this.forceCommand.setBindings({positionsTexture:i.previousPositionTexture,levelFbo:o.texture}),this.forceCommand.draw(r),s===this.levels-1&&(this.forceCenterUniformStore.setUniforms({forceCenterUniforms:{levelTextureSize:a,alpha:t.alpha,repulsion:this.config.simulationRepulsion??0}}),this.forceFromItsOwnCentermassCommand.setBindings({positionsTexture:i.previousPositionTexture,randomValues:this.randomValuesTexture,levelFbo:o.texture}),this.forceFromItsOwnCentermassCommand.draw(r))}r.end()}}const ev=`#version 300 es
545
+ }`;class q0 extends Ot{constructor(){super(...arguments),this.levels=0,this.levelTargets=new Map}create(){var o;const{device:e,store:t}=this;if(!t.pointsTextureSize)return;this.levels=Math.log2(t.adjustedSpaceSize);for(let a=0;a<this.levels;a+=1){const l=Math.pow(2,a+1),c=this.levelTargets.get(a);if(c&&c.texture.width===l&&c.texture.height===l){c.texture.copyImageData({data:new Float32Array(l*l*4).fill(0),bytesPerRow:te("rgba32float",l),mipLevel:0,x:0,y:0});continue}c&&(c.fbo.destroyed||c.fbo.destroy(),c.texture.destroyed||c.texture.destroy());const u=e.createTexture({width:l,height:l,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST});u.copyImageData({data:new Float32Array(l*l*4).fill(0),bytesPerRow:te("rgba32float",l),mipLevel:0,x:0,y:0});const f=e.createFramebuffer({width:l,height:l,colorAttachments:[u]});this.levelTargets.set(a,{texture:u,fbo:f})}for(const[a,l]of Array.from(this.levelTargets.entries()))a>=this.levels&&(l.fbo.destroyed||l.fbo.destroy(),l.texture.destroyed||l.texture.destroy(),this.levelTargets.delete(a));const i=t.pointsTextureSize*t.pointsTextureSize,r=new Float32Array(i*4);for(let a=0;a<i;++a)r[a*4]=t.getRandomFloat(-1,1)*1e-5,r[a*4+1]=t.getRandomFloat(-1,1)*1e-5;if((!this.randomValuesTexture||this.randomValuesTexture.destroyed||this.randomValuesTexture.width!==t.pointsTextureSize||this.randomValuesTexture.height!==t.pointsTextureSize)&&(this.randomValuesTexture&&!this.randomValuesTexture.destroyed&&this.randomValuesTexture.destroy(),this.randomValuesTexture=e.createTexture({width:t.pointsTextureSize,height:t.pointsTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.COPY_DST})),this.randomValuesTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",t.pointsTextureSize),mipLevel:0,x:0,y:0}),!this.pointIndices||this.previousPointsTextureSize!==t.pointsTextureSize){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const a=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:a,usage:L.VERTEX|L.COPY_DST}),(o=this.calculateLevelsCommand)==null||o.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=t.pointsTextureSize,this.previousSpaceSize=t.adjustedSpaceSize}initPrograms(){const{device:e,store:t,data:i,points:r}=this;!i.pointsNumber||!r||!t.pointsTextureSize||(this.calculateLevelsUniformStore||(this.calculateLevelsUniformStore=new _e({calculateLevelsUniforms:{uniformTypes:{pointsTextureSize:"f32",levelTextureSize:"f32",cellSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,levelTextureSize:0,cellSize:0}}})),this.calculateLevelsCommand||(this.calculateLevelsCommand=new pe(e,{fs:W0,vs:$0,topology:"point-list",vertexCount:i.pointsNumber,attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateLevelsUniforms:this.calculateLevelsUniformStore.getManagedUniformBuffer(e,"calculateLevelsUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.forceUniformStore||(this.forceUniformStore=new _e({forceUniforms:{uniformTypes:{level:"f32",levels:"f32",levelTextureSize:"f32",alpha:"f32",repulsion:"f32",spaceSize:"f32",theta:"f32"},defaultUniforms:{level:0,levels:this.levels,levelTextureSize:0,alpha:t.alpha,repulsion:this.config.simulationRepulsion,spaceSize:t.adjustedSpaceSize,theta:this.config.simulationRepulsionTheta}}})),this.forceVertexCoordBuffer||(this.forceVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.forceCommand||(this.forceCommand=new pe(e,{fs:X0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceUniforms:this.forceUniformStore.getManagedUniformBuffer(e,"forceUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.forceCenterUniformStore||(this.forceCenterUniformStore=new _e({forceCenterUniforms:{uniformTypes:{levelTextureSize:"f32",alpha:"f32",repulsion:"f32"},defaultUniforms:{levelTextureSize:0,alpha:t.alpha,repulsion:this.config.simulationRepulsion}}})),this.forceFromItsOwnCentermassCommand||(this.forceFromItsOwnCentermassCommand=new pe(e,{fs:Y0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.forceVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceCenterUniforms:this.forceCenterUniformStore.getManagedUniformBuffer(e,"forceCenterUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})))}run(){this.store.pointsTextureSize!==this.previousPointsTextureSize||this.store.adjustedSpaceSize!==this.previousSpaceSize||(this.drawLevels(),this.drawForces())}destroy(){var e,t,i,r,s,o;(e=this.calculateLevelsCommand)==null||e.destroy(),this.calculateLevelsCommand=void 0,(t=this.forceCommand)==null||t.destroy(),this.forceCommand=void 0,(i=this.forceFromItsOwnCentermassCommand)==null||i.destroy(),this.forceFromItsOwnCentermassCommand=void 0;for(const a of this.levelTargets.values())a.fbo&&!a.fbo.destroyed&&a.fbo.destroy();this.randomValuesTexture&&!this.randomValuesTexture.destroyed&&this.randomValuesTexture.destroy(),this.randomValuesTexture=void 0;for(const a of this.levelTargets.values())a.texture&&!a.texture.destroyed&&a.texture.destroy();this.levelTargets.clear(),(r=this.calculateLevelsUniformStore)==null||r.destroy(),this.calculateLevelsUniformStore=void 0,(s=this.forceUniformStore)==null||s.destroy(),this.forceUniformStore=void 0,(o=this.forceCenterUniformStore)==null||o.destroy(),this.forceCenterUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.forceVertexCoordBuffer&&!this.forceVertexCoordBuffer.destroyed&&this.forceVertexCoordBuffer.destroy(),this.forceVertexCoordBuffer=void 0}drawLevels(){const{device:e,store:t,data:i,points:r}=this;if(r&&!(!this.calculateLevelsCommand||!this.calculateLevelsUniformStore)&&!(!r.previousPositionTexture||r.previousPositionTexture.destroyed)&&i.pointsNumber&&this.pointIndices)for(let s=0;s<this.levels;s+=1){const o=this.levelTargets.get(s);if(!o||o.fbo.destroyed||o.texture.destroyed)continue;const a=Math.pow(2,s+1),l=t.adjustedSpaceSize/a;this.calculateLevelsUniformStore.setUniforms({calculateLevelsUniforms:{pointsTextureSize:t.pointsTextureSize??0,levelTextureSize:a,cellSize:l}}),this.calculateLevelsCommand.setVertexCount(i.pointsNumber),this.calculateLevelsCommand.setBindings({positionsTexture:r.previousPositionTexture});const c=e.beginRenderPass({framebuffer:o.fbo,clearColor:[0,0,0,0]});this.calculateLevelsCommand.draw(c),c.end()}}drawForces(){const{device:e,store:t,points:i}=this;if(!i||!this.forceCommand||!this.forceUniformStore||!this.forceFromItsOwnCentermassCommand||!this.forceCenterUniformStore||!i.previousPositionTexture||i.previousPositionTexture.destroyed||!this.randomValuesTexture||this.randomValuesTexture.destroyed||!i.velocityFbo||i.velocityFbo.destroyed)return;const r=e.beginRenderPass({framebuffer:i.velocityFbo,clearColor:[0,0,0,0]});for(let s=0;s<this.levels;s+=1){const o=this.levelTargets.get(s);if(!o||o.texture.destroyed)continue;const a=Math.pow(2,s+1);this.forceUniformStore.setUniforms({forceUniforms:{level:s,levels:this.levels,levelTextureSize:a,alpha:t.alpha,repulsion:this.config.simulationRepulsion,spaceSize:t.adjustedSpaceSize,theta:this.config.simulationRepulsionTheta}}),this.forceCommand.setBindings({positionsTexture:i.previousPositionTexture,levelFbo:o.texture}),this.forceCommand.draw(r),s===this.levels-1&&(this.forceCenterUniformStore.setUniforms({forceCenterUniforms:{levelTextureSize:a,alpha:t.alpha,repulsion:this.config.simulationRepulsion}}),this.forceFromItsOwnCentermassCommand.setBindings({positionsTexture:i.previousPositionTexture,randomValues:this.randomValuesTexture,levelFbo:o.texture}),this.forceFromItsOwnCentermassCommand.draw(r))}r.end()}}const j0=`#version 300 es
546
546
  precision highp float;
547
547
 
548
548
  uniform sampler2D positionsTexture;
@@ -576,7 +576,7 @@ void main() {
576
576
  velocity.rg -= addV * vec2(cos(angle), sin(angle));
577
577
 
578
578
  fragColor = velocity;
579
- }`;class tv extends Nt{initPrograms(){const{device:e,points:t}=this;t&&(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new xe({forceMouseUniforms:{uniformTypes:{repulsion:"f32",mousePos:"vec2<f32>"}}})),this.runCommand||(this.runCommand=new me(e,{fs:ev,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceMouseUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceMouseUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,points:t,store:i}=this;if(!t||!this.runCommand||!this.uniformStore||!t.previousPositionTexture||t.previousPositionTexture.destroyed||!t.velocityFbo||t.velocityFbo.destroyed)return;this.uniformStore.setUniforms({forceMouseUniforms:{repulsion:this.config.simulationRepulsionFromMouse??0,mousePos:re(i.mousePosition,[0,0])}}),this.runCommand.setBindings({positionsTexture:t.previousPositionTexture});const r=e.beginRenderPass({framebuffer:t.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}const nv=`#version 300 es
579
+ }`;class K0 extends Ot{initPrograms(){const{device:e,points:t}=this;t&&(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new _e({forceMouseUniforms:{uniformTypes:{repulsion:"f32",mousePos:"vec2<f32>"}}})),this.runCommand||(this.runCommand=new pe(e,{fs:j0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.vertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{forceMouseUniforms:this.uniformStore.getManagedUniformBuffer(e,"forceMouseUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})))}run(){const{device:e,points:t,store:i}=this;if(!t||!this.runCommand||!this.uniformStore||!t.previousPositionTexture||t.previousPositionTexture.destroyed||!t.velocityFbo||t.velocityFbo.destroyed)return;this.uniformStore.setUniforms({forceMouseUniforms:{repulsion:this.config.simulationRepulsionFromMouse,mousePos:ne(i.mousePosition,[0,0])}}),this.runCommand.setBindings({positionsTexture:t.previousPositionTexture});const r=e.beginRenderPass({framebuffer:t.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(r),r.end()}destroy(){var e,t;(e=this.runCommand)==null||e.destroy(),this.runCommand=void 0,(t=this.uniformStore)==null||t.destroy(),this.uniformStore=void 0,this.vertexCoordBuffer&&!this.vertexCoordBuffer.destroyed&&this.vertexCoordBuffer.destroy(),this.vertexCoordBuffer=void 0}}const Z0=`#version 300 es
580
580
  #ifdef GL_ES
581
581
  precision highp float;
582
582
  #endif
@@ -587,7 +587,7 @@ out vec4 fragColor;
587
587
 
588
588
  void main() {
589
589
  fragColor = rgba;
590
- }`,iv=`#version 300 es
590
+ }`,Q0=`#version 300 es
591
591
  #ifdef GL_ES
592
592
  precision highp float;
593
593
  #endif
@@ -625,7 +625,7 @@ void main() {
625
625
  gl_Position = vec4(xy, 0.0, 1.0);
626
626
  gl_PointSize = 1.0;
627
627
  }
628
- `,rv=`#version 300 es
628
+ `,J0=`#version 300 es
629
629
  #ifdef GL_ES
630
630
  precision highp float;
631
631
  #endif
@@ -679,7 +679,7 @@ void main() {
679
679
  }
680
680
 
681
681
  fragColor = velocity;
682
- }`;class sv extends Nt{create(){var f,h;const{device:e,store:t,data:i}=this,{pointsTextureSize:r}=t;if(i.pointsNumber===void 0||!i.pointClusters&&!i.clusterPositions)return;this.clusterCount=(i.pointClusters??[]).reduce((d,_)=>_===void 0||_<0?d:Math.max(d,_),0)+1,this.clustersTextureSize=Math.ceil(Math.sqrt(this.clusterCount));const s=this.previousPointsTextureSize!==r||this.previousClustersTextureSize!==this.clustersTextureSize||this.previousClusterCount!==this.clusterCount,o=r*r*4,a=this.clustersTextureSize*this.clustersTextureSize*4,l=new Float32Array(o),c=new Float32Array(a).fill(-1),u=new Float32Array(o).fill(1);if(i.clusterPositions)for(let d=0;d<this.clusterCount;++d)c[d*4+0]=i.clusterPositions[d*2+0]??-1,c[d*4+1]=i.clusterPositions[d*2+1]??-1;for(let d=0;d<i.pointsNumber;++d){const _=(f=i.pointClusters)==null?void 0:f[d];_===void 0?(l[d*4+0]=-1,l[d*4+1]=-1):(l[d*4+0]=_%this.clustersTextureSize,l[d*4+1]=Math.floor(_/this.clustersTextureSize)),i.clusterStrength&&(u[d*4+0]=i.clusterStrength[d]??1)}if(!this.clusterTexture||s?(this.clusterTexture&&!this.clusterTexture.destroyed&&this.clusterTexture.destroy(),this.clusterTexture=e.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0})):this.clusterTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),!this.clusterPositionsTexture||s?(this.clusterPositionsTexture&&!this.clusterPositionsTexture.destroyed&&this.clusterPositionsTexture.destroy(),this.clusterPositionsTexture=e.createTexture({width:this.clustersTextureSize,height:this.clustersTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterPositionsTexture.copyImageData({data:c,bytesPerRow:ie("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0})):this.clusterPositionsTexture.copyImageData({data:c,bytesPerRow:ie("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),!this.clusterForceCoefficientTexture||s?(this.clusterForceCoefficientTexture&&!this.clusterForceCoefficientTexture.destroyed&&this.clusterForceCoefficientTexture.destroy(),this.clusterForceCoefficientTexture=e.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterForceCoefficientTexture.copyImageData({data:u,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0})):this.clusterForceCoefficientTexture.copyImageData({data:u,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),!this.centermassTexture||this.previousClustersTextureSize!==this.clustersTextureSize?(this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=e.createTexture({width:this.clustersTextureSize,height:this.clustersTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.centermassTexture.copyImageData({data:new Float32Array(a).fill(0),bytesPerRow:ie("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),this.centermassFbo=e.createFramebuffer({width:this.clustersTextureSize,height:this.clustersTextureSize,colorAttachments:[this.centermassTexture]})):this.centermassTexture.copyImageData({data:new Float32Array(a).fill(0),bytesPerRow:ie("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),!this.pointIndices||this.previousPointsTextureSize!==r){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const d=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:d,usage:L.VERTEX|L.COPY_DST}),(h=this.calculateCentermassCommand)==null||h.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=r,this.previousClustersTextureSize=this.clustersTextureSize,this.previousClusterCount=this.clusterCount}initPrograms(){const{device:e,store:t,data:i}=this;i.pointsNumber===void 0||!i.pointClusters&&!i.clusterPositions||(this.calculateCentermassUniformStore||(this.calculateCentermassUniformStore=new xe({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32",clustersTextureSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,clustersTextureSize:this.clustersTextureSize??0}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new me(e,{fs:nv,vs:iv,topology:"point-list",vertexCount:i.pointsNumber??0,attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateCentermassUniforms:this.calculateCentermassUniformStore.getManagedUniformBuffer(e,"calculateCentermassUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.applyForcesUniformStore||(this.applyForcesUniformStore=new xe({applyForcesUniforms:{uniformTypes:{alpha:"f32",clustersTextureSize:"f32",clusterCoefficient:"f32"},defaultUniforms:{alpha:t.alpha,clustersTextureSize:this.clustersTextureSize??0,clusterCoefficient:this.config.simulationCluster??0}}})),this.applyForcesVertexCoordBuffer||(this.applyForcesVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.applyForcesCommand||(this.applyForcesCommand=new me(e,{fs:rv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.applyForcesVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{applyForcesUniforms:this.applyForcesUniformStore.getManagedUniformBuffer(e,"applyForcesUniforms")}})))}calculateCentermass(){const{device:e,points:t}=this;if(!t||!this.calculateCentermassCommand||!this.calculateCentermassUniformStore||!this.pointIndices||!this.centermassFbo||this.centermassFbo.destroyed||!this.clusterTexture||this.clusterTexture.destroyed||!t.previousPositionTexture||t.previousPositionTexture.destroyed)return;this.calculateCentermassCommand.setVertexCount(this.data.pointsNumber??0),this.calculateCentermassUniformStore.setUniforms({calculateCentermassUniforms:{pointsTextureSize:this.store.pointsTextureSize,clustersTextureSize:this.clustersTextureSize??0}}),this.calculateCentermassCommand.setBindings({clusterTexture:this.clusterTexture,positionsTexture:t.previousPositionTexture});const i=e.beginRenderPass({framebuffer:this.centermassFbo,clearColor:[0,0,0,0]});this.calculateCentermassCommand.draw(i),i.end()}run(){var t;if(!this.data.pointClusters&&!this.data.clusterPositions||(this.calculateCentermass(),!this.applyForcesCommand||!this.applyForcesUniformStore)||!this.clusterTexture||this.clusterTexture.destroyed||!this.centermassTexture||this.centermassTexture.destroyed||!this.clusterPositionsTexture||this.clusterPositionsTexture.destroyed||!this.clusterForceCoefficientTexture||this.clusterForceCoefficientTexture.destroyed||!((t=this.points)!=null&&t.previousPositionTexture)||this.points.previousPositionTexture.destroyed||!this.points.velocityFbo||this.points.velocityFbo.destroyed)return;this.applyForcesUniformStore.setUniforms({applyForcesUniforms:{alpha:this.store.alpha,clustersTextureSize:this.clustersTextureSize??0,clusterCoefficient:this.config.simulationCluster??0}}),this.applyForcesCommand.setBindings({clusterTexture:this.clusterTexture,centermassTexture:this.centermassTexture,clusterPositionsTexture:this.clusterPositionsTexture,clusterForceCoefficient:this.clusterForceCoefficientTexture,positionsTexture:this.points.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.points.velocityFbo,clearColor:[0,0,0,0]});this.applyForcesCommand.draw(e),e.end()}destroy(){var e,t,i,r;(e=this.calculateCentermassCommand)==null||e.destroy(),this.calculateCentermassCommand=void 0,(t=this.applyForcesCommand)==null||t.destroy(),this.applyForcesCommand=void 0,this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassFbo=void 0,this.clusterTexture&&!this.clusterTexture.destroyed&&this.clusterTexture.destroy(),this.clusterTexture=void 0,this.clusterPositionsTexture&&!this.clusterPositionsTexture.destroyed&&this.clusterPositionsTexture.destroy(),this.clusterPositionsTexture=void 0,this.clusterForceCoefficientTexture&&!this.clusterForceCoefficientTexture.destroyed&&this.clusterForceCoefficientTexture.destroy(),this.clusterForceCoefficientTexture=void 0,this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=void 0,(i=this.calculateCentermassUniformStore)==null||i.destroy(),this.calculateCentermassUniformStore=void 0,(r=this.applyForcesUniformStore)==null||r.destroy(),this.applyForcesUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.applyForcesVertexCoordBuffer&&!this.applyForcesVertexCoordBuffer.destroyed&&this.applyForcesVertexCoordBuffer.destroy(),this.applyForcesVertexCoordBuffer=void 0}}var ov=`<div class="gl-box">
682
+ }`;class G0 extends Ot{constructor(){super(...arguments),this.cachedCentroidPositions=null}create(){var f,h;this.cachedCentroidPositions=null;const{device:e,store:t,data:i}=this,{pointsTextureSize:r}=t;if(i.pointsNumber===void 0||!i.pointClusters&&!i.clusterPositions)return;this.clusterCount=(i.pointClusters??[]).reduce((d,_)=>_===void 0||_<0?d:Math.max(d,_),0)+1,this.clustersTextureSize=Math.ceil(Math.sqrt(this.clusterCount));const s=this.previousPointsTextureSize!==r||this.previousClustersTextureSize!==this.clustersTextureSize||this.previousClusterCount!==this.clusterCount,o=r*r*4,a=this.clustersTextureSize*this.clustersTextureSize*4,l=new Float32Array(o),c=new Float32Array(a).fill(-1),u=new Float32Array(o).fill(1);if(i.clusterPositions)for(let d=0;d<this.clusterCount;++d)c[d*4+0]=i.clusterPositions[d*2+0]??-1,c[d*4+1]=i.clusterPositions[d*2+1]??-1;for(let d=0;d<i.pointsNumber;++d){const _=(f=i.pointClusters)==null?void 0:f[d];_===void 0?(l[d*4+0]=-1,l[d*4+1]=-1):(l[d*4+0]=_%this.clustersTextureSize,l[d*4+1]=Math.floor(_/this.clustersTextureSize)),i.clusterStrength&&(u[d*4+0]=i.clusterStrength[d]??1)}if(!this.clusterTexture||s?(this.clusterTexture&&!this.clusterTexture.destroyed&&this.clusterTexture.destroy(),this.clusterTexture=e.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0})):this.clusterTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),!this.clusterPositionsTexture||s?(this.clusterPositionsTexture&&!this.clusterPositionsTexture.destroyed&&this.clusterPositionsTexture.destroy(),this.clusterPositionsTexture=e.createTexture({width:this.clustersTextureSize,height:this.clustersTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterPositionsTexture.copyImageData({data:c,bytesPerRow:te("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0})):this.clusterPositionsTexture.copyImageData({data:c,bytesPerRow:te("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),!this.clusterForceCoefficientTexture||s?(this.clusterForceCoefficientTexture&&!this.clusterForceCoefficientTexture.destroyed&&this.clusterForceCoefficientTexture.destroy(),this.clusterForceCoefficientTexture=e.createTexture({width:r,height:r,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.clusterForceCoefficientTexture.copyImageData({data:u,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0})):this.clusterForceCoefficientTexture.copyImageData({data:u,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),!this.centermassTexture||this.previousClustersTextureSize!==this.clustersTextureSize?(this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=e.createTexture({width:this.clustersTextureSize,height:this.clustersTextureSize,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.centermassTexture.copyImageData({data:new Float32Array(a).fill(0),bytesPerRow:te("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),this.centermassFbo=e.createFramebuffer({width:this.clustersTextureSize,height:this.clustersTextureSize,colorAttachments:[this.centermassTexture]})):this.centermassTexture.copyImageData({data:new Float32Array(a).fill(0),bytesPerRow:te("rgba32float",this.clustersTextureSize),mipLevel:0,x:0,y:0}),!this.pointIndices||this.previousPointsTextureSize!==r){this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy();const d=yr(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:d,usage:L.VERTEX|L.COPY_DST}),(h=this.calculateCentermassCommand)==null||h.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=r,this.previousClustersTextureSize=this.clustersTextureSize,this.previousClusterCount=this.clusterCount}initPrograms(){const{device:e,store:t,data:i}=this;i.pointsNumber===void 0||!i.pointClusters&&!i.clusterPositions||(this.calculateCentermassUniformStore||(this.calculateCentermassUniformStore=new _e({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32",clustersTextureSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,clustersTextureSize:this.clustersTextureSize??0}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new pe(e,{fs:Z0,vs:Q0,topology:"point-list",vertexCount:i.pointsNumber??0,attributes:{...this.pointIndices&&{pointIndices:this.pointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{calculateCentermassUniforms:this.calculateCentermassUniformStore.getManagedUniformBuffer(e,"calculateCentermassUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one",depthWriteEnabled:!1,depthCompare:"always"}})),this.applyForcesUniformStore||(this.applyForcesUniformStore=new _e({applyForcesUniforms:{uniformTypes:{alpha:"f32",clustersTextureSize:"f32",clusterCoefficient:"f32"},defaultUniforms:{alpha:t.alpha,clustersTextureSize:this.clustersTextureSize??0,clusterCoefficient:this.config.simulationCluster}}})),this.applyForcesVertexCoordBuffer||(this.applyForcesVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.applyForcesCommand||(this.applyForcesCommand=new pe(e,{fs:J0,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.applyForcesVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{applyForcesUniforms:this.applyForcesUniformStore.getManagedUniformBuffer(e,"applyForcesUniforms")}})))}calculateCentermass(){const{device:e,points:t}=this;if(!t||!this.calculateCentermassCommand||!this.calculateCentermassUniformStore||!this.pointIndices||!this.centermassFbo||this.centermassFbo.destroyed||!this.clusterTexture||this.clusterTexture.destroyed||!t.previousPositionTexture||t.previousPositionTexture.destroyed)return;this.calculateCentermassCommand.setVertexCount(this.data.pointsNumber??0),this.calculateCentermassUniformStore.setUniforms({calculateCentermassUniforms:{pointsTextureSize:this.store.pointsTextureSize,clustersTextureSize:this.clustersTextureSize??0}}),this.calculateCentermassCommand.setBindings({clusterTexture:this.clusterTexture,positionsTexture:t.previousPositionTexture});const i=e.beginRenderPass({framebuffer:this.centermassFbo,clearColor:[0,0,0,0]});this.calculateCentermassCommand.draw(i),i.end()}getCentroidPositions(){var o;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this,i=!e||!t;if(i&&((o=this.points)!=null&&o.areClusterCentroidsUpToDate)&&this.cachedCentroidPositions)return this.cachedCentroidPositions;if(this.calculateCentermass(),!this.centermassFbo||this.centermassFbo.destroyed||this.clusterCount===void 0)return[];const r=Me(this.device,this.centermassFbo),s=[];s.length=this.clusterCount*2;for(let a=0;a<s.length/2;a+=1){const l=r[a*4+0],c=r[a*4+1],u=r[a*4+2];l!==void 0&&c!==void 0&&u!==void 0&&(s[a*2]=l/u,s[a*2+1]=c/u)}return i&&this.points&&(this.cachedCentroidPositions=s,this.points.areClusterCentroidsUpToDate=!0),s}run(){var t;if(!this.data.pointClusters&&!this.data.clusterPositions||(this.calculateCentermass(),!this.applyForcesCommand||!this.applyForcesUniformStore)||!this.clusterTexture||this.clusterTexture.destroyed||!this.centermassTexture||this.centermassTexture.destroyed||!this.clusterPositionsTexture||this.clusterPositionsTexture.destroyed||!this.clusterForceCoefficientTexture||this.clusterForceCoefficientTexture.destroyed||!((t=this.points)!=null&&t.previousPositionTexture)||this.points.previousPositionTexture.destroyed||!this.points.velocityFbo||this.points.velocityFbo.destroyed)return;this.applyForcesUniformStore.setUniforms({applyForcesUniforms:{alpha:this.store.alpha,clustersTextureSize:this.clustersTextureSize??0,clusterCoefficient:this.config.simulationCluster}}),this.applyForcesCommand.setBindings({clusterTexture:this.clusterTexture,centermassTexture:this.centermassTexture,clusterPositionsTexture:this.clusterPositionsTexture,clusterForceCoefficient:this.clusterForceCoefficientTexture,positionsTexture:this.points.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.points.velocityFbo,clearColor:[0,0,0,0]});this.applyForcesCommand.draw(e),e.end()}destroy(){var e,t,i,r;this.cachedCentroidPositions=null,(e=this.calculateCentermassCommand)==null||e.destroy(),this.calculateCentermassCommand=void 0,(t=this.applyForcesCommand)==null||t.destroy(),this.applyForcesCommand=void 0,this.centermassFbo&&!this.centermassFbo.destroyed&&this.centermassFbo.destroy(),this.centermassFbo=void 0,this.clusterTexture&&!this.clusterTexture.destroyed&&this.clusterTexture.destroy(),this.clusterTexture=void 0,this.clusterPositionsTexture&&!this.clusterPositionsTexture.destroyed&&this.clusterPositionsTexture.destroy(),this.clusterPositionsTexture=void 0,this.clusterForceCoefficientTexture&&!this.clusterForceCoefficientTexture.destroyed&&this.clusterForceCoefficientTexture.destroy(),this.clusterForceCoefficientTexture=void 0,this.centermassTexture&&!this.centermassTexture.destroyed&&this.centermassTexture.destroy(),this.centermassTexture=void 0,(i=this.calculateCentermassUniformStore)==null||i.destroy(),this.calculateCentermassUniformStore=void 0,(r=this.applyForcesUniformStore)==null||r.destroy(),this.applyForcesUniformStore=void 0,this.pointIndices&&!this.pointIndices.destroyed&&this.pointIndices.destroy(),this.pointIndices=void 0,this.applyForcesVertexCoordBuffer&&!this.applyForcesVertexCoordBuffer.destroyed&&this.applyForcesVertexCoordBuffer.destroy(),this.applyForcesVertexCoordBuffer=void 0}}var ev=`<div class="gl-box">
683
683
  <svg viewBox="0 0 55 60">
684
684
  <text x="27" y="56" class="gl-fps">00 FPS</text>
685
685
  <text x="28" y="8" class="gl-mem"></text>
@@ -696,7 +696,7 @@ void main() {
696
696
  <line x1="7" y1="38" x2="7" y2="11" class="gl-gpu" stroke-dasharray="0 27"/>
697
697
  <path d="M1.94775 43.3772a.736.736 0 10-.00416 1.472c.58535.00231.56465.1288.6348.3197.07015.18975.04933.43585.04933.43585l-.00653.05405v8.671a.736.736 0 101.472 0v-1.4145c.253.09522.52785.1495.81765.1495h5.267c1.2535 0 2.254-.9752 2.254-2.185v-3.105c0-1.2075-1.00625-2.185-2.254-2.185h-5.267c-.28865 0-.5635.05405-.8165.1495.01806-.16445.04209-.598-.1357-1.0787-.22425-.6072-.9499-1.2765-2.0125-1.2765zm2.9095 3.6455c.42435 0 .7659.36225.7659.8119v2.9785c0 .44965-.34155.8119-.7659.8119s-.7659-.36225-.7659-.8119v-2.9785c0-.44965.34155-.8119.7659-.8119zm4.117 0a2.3 2.3 0 012.3 2.3 2.3 2.3 0 01-2.3 2.3 2.3 2.3 0 01-2.3-2.3 2.3 2.3 0 012.3-2.3z"/>
698
698
  </svg>
699
- </div>`,av=`#gl-bench {
699
+ </div>`,tv=`#gl-bench {
700
700
  position:absolute;
701
701
  left:0;
702
702
  top:0;
@@ -755,7 +755,7 @@ void main() {
755
755
  #gl-bench .opacity {
756
756
  stroke: #448844;
757
757
  }
758
- `;class lv{constructor(e,t={}){this.css=av,this.svg=ov,this.paramLogger=()=>{},this.chartLogger=()=>{},this.chartLen=20,this.chartHz=20,this.names=[],this.cpuAccums=[],this.gpuAccums=[],this.activeAccums=[],this.chart=new Array(this.chartLen),this.now=()=>performance&&performance.now?performance.now():Date.now(),this.updateUI=()=>{[].forEach.call(this.nodes["gl-gpu-svg"],a=>{a.style.display=this.trackGPU?"inline":"none"})},Object.assign(this,t),this.detected=0,this.finished=[],this.isFramebuffer=0,this.frameId=0;let i,r=0,s,o=a=>{++r<20?i=requestAnimationFrame(o):(this.detected=Math.ceil(1e3*r/(a-s)/70),cancelAnimationFrame(i)),s||(s=a)};if(requestAnimationFrame(o),e){const a=async(c,u)=>Promise.resolve(setTimeout(()=>{e.getError();const f=this.now()-c;u.forEach((h,d)=>{h&&(this.gpuAccums[d]+=f)})},0)),l=(c,u,f)=>function(){const h=u.now();c.apply(f,arguments),u.trackGPU&&u.finished.push(a(h,u.activeAccums.slice(0)))};["drawArrays","drawElements","drawArraysInstanced","drawBuffers","drawElementsInstanced","drawRangeElements"].forEach(c=>{e[c]&&(e[c]=l(e[c],this,e))}),e.getExtension=((c,u)=>function(){let f=c.apply(e,arguments);return f&&["drawElementsInstancedANGLE","drawBuffersWEBGL"].forEach(h=>{f[h]&&(f[h]=l(f[h],u,f))}),f})(e.getExtension,this)}if(!this.withoutUI){this.dom||(this.dom=document.body);let a=document.createElement("div");a.id="gl-bench",this.dom.appendChild(a),this.dom.insertAdjacentHTML("afterbegin",'<style id="gl-bench-style">'+this.css+"</style>"),this.dom=a,this.dom.addEventListener("click",()=>{this.trackGPU=!this.trackGPU,this.updateUI()}),this.paramLogger=((l,c,u)=>{const f=["gl-cpu","gl-gpu","gl-mem","gl-fps","gl-gpu-svg","gl-chart"],h=Object.assign({},f);return f.forEach(d=>h[d]=c.getElementsByClassName(d)),this.nodes=h,(d,_,I,P,A,O,E)=>{h["gl-cpu"][d].style.strokeDasharray=(_*.27).toFixed(0)+" 100",h["gl-gpu"][d].style.strokeDasharray=(I*.27).toFixed(0)+" 100",h["gl-mem"][d].innerHTML=u[d]?u[d]:P?"mem: "+P.toFixed(0)+"mb":"",h["gl-fps"][d].innerHTML=A.toFixed(0)+" FPS",l(u[d],_,I,P,A,O,E)}})(this.paramLogger,this.dom,this.names),this.chartLogger=((l,c)=>{let u={"gl-chart":c.getElementsByClassName("gl-chart")};return(f,h,d)=>{let _="",I=h.length;for(let P=0;P<I;P++){let A=(d+P+1)%I;h[A]!=null&&(_=_+" "+(55*P/(I-1)).toFixed(1)+","+(45-h[A]*22/60/this.detected).toFixed(1))}u["gl-chart"][f].setAttribute("points",_),l(this.names[f],h,d)}})(this.chartLogger,this.dom)}}addUI(e){this.names.indexOf(e)==-1&&(this.names.push(e),this.dom&&(this.dom.insertAdjacentHTML("beforeend",this.svg),this.updateUI()),this.cpuAccums.push(0),this.gpuAccums.push(0),this.activeAccums.push(!1))}nextFrame(e){this.frameId++;const t=e||this.now();if(this.frameId<=1)this.paramFrame=this.frameId,this.paramTime=t;else{let i=t-this.paramTime;if(i>=1e3){const r=this.frameId-this.paramFrame,s=r/i*1e3;for(let o=0;o<this.names.length;o++){const a=this.cpuAccums[o]/i*100,l=this.gpuAccums[o]/i*100,c=performance&&performance.memory?performance.memory.usedJSHeapSize/(1<<20):0;this.paramLogger(o,a,l,c,s,i,r),this.cpuAccums[o]=0,Promise.all(this.finished).then(()=>{this.gpuAccums[o]=0,this.finished=[]})}this.paramFrame=this.frameId,this.paramTime=t}}if(!this.detected||!this.chartFrame)this.chartFrame=this.frameId,this.chartTime=t,this.circularId=0;else{let i=t-this.chartTime,r=this.chartHz*i/1e3;for(;--r>0&&this.detected;){const o=(this.frameId-this.chartFrame)/i*1e3;this.chart[this.circularId%this.chartLen]=o;for(let a=0;a<this.names.length;a++)this.chartLogger(a,this.chart,this.circularId);this.circularId++,this.chartFrame=this.frameId,this.chartTime=t}}}begin(e){this.updateAccums(e)}end(e){this.updateAccums(e)}updateAccums(e){let t=this.names.indexOf(e);t==-1&&(t=this.names.length,this.addUI(e));const i=this.now(),r=i-this.t0;for(let s=0;s<t+1;s++)this.activeAccums[s]&&(this.cpuAccums[s]+=r);this.activeAccums[t]=!this.activeAccums[t],this.t0=i}}const cv=`
758
+ `;class nv{constructor(e,t={}){this.css=tv,this.svg=ev,this.paramLogger=()=>{},this.chartLogger=()=>{},this.chartLen=20,this.chartHz=20,this.names=[],this.cpuAccums=[],this.gpuAccums=[],this.activeAccums=[],this.chart=new Array(this.chartLen),this.now=()=>performance&&performance.now?performance.now():Date.now(),this.updateUI=()=>{[].forEach.call(this.nodes["gl-gpu-svg"],a=>{a.style.display=this.trackGPU?"inline":"none"})},Object.assign(this,t),this.detected=0,this.finished=[],this.isFramebuffer=0,this.frameId=0;let i,r=0,s,o=a=>{++r<20?i=requestAnimationFrame(o):(this.detected=Math.ceil(1e3*r/(a-s)/70),cancelAnimationFrame(i)),s||(s=a)};if(requestAnimationFrame(o),e){const a=async(c,u)=>Promise.resolve(setTimeout(()=>{e.getError();const f=this.now()-c;u.forEach((h,d)=>{h&&(this.gpuAccums[d]+=f)})},0)),l=(c,u,f)=>function(){const h=u.now();c.apply(f,arguments),u.trackGPU&&u.finished.push(a(h,u.activeAccums.slice(0)))};["drawArrays","drawElements","drawArraysInstanced","drawBuffers","drawElementsInstanced","drawRangeElements"].forEach(c=>{e[c]&&(e[c]=l(e[c],this,e))}),e.getExtension=((c,u)=>function(){let f=c.apply(e,arguments);return f&&["drawElementsInstancedANGLE","drawBuffersWEBGL"].forEach(h=>{f[h]&&(f[h]=l(f[h],u,f))}),f})(e.getExtension,this)}if(!this.withoutUI){this.dom||(this.dom=document.body);let a=document.createElement("div");a.id="gl-bench",this.dom.appendChild(a),this.dom.insertAdjacentHTML("afterbegin",'<style id="gl-bench-style">'+this.css+"</style>"),this.dom=a,this.dom.addEventListener("click",()=>{this.trackGPU=!this.trackGPU,this.updateUI()}),this.paramLogger=((l,c,u)=>{const f=["gl-cpu","gl-gpu","gl-mem","gl-fps","gl-gpu-svg","gl-chart"],h=Object.assign({},f);return f.forEach(d=>h[d]=c.getElementsByClassName(d)),this.nodes=h,(d,_,I,P,A,O,E)=>{h["gl-cpu"][d].style.strokeDasharray=(_*.27).toFixed(0)+" 100",h["gl-gpu"][d].style.strokeDasharray=(I*.27).toFixed(0)+" 100",h["gl-mem"][d].innerHTML=u[d]?u[d]:P?"mem: "+P.toFixed(0)+"mb":"",h["gl-fps"][d].innerHTML=A.toFixed(0)+" FPS",l(u[d],_,I,P,A,O,E)}})(this.paramLogger,this.dom,this.names),this.chartLogger=((l,c)=>{let u={"gl-chart":c.getElementsByClassName("gl-chart")};return(f,h,d)=>{let _="",I=h.length;for(let P=0;P<I;P++){let A=(d+P+1)%I;h[A]!=null&&(_=_+" "+(55*P/(I-1)).toFixed(1)+","+(45-h[A]*22/60/this.detected).toFixed(1))}u["gl-chart"][f].setAttribute("points",_),l(this.names[f],h,d)}})(this.chartLogger,this.dom)}}addUI(e){this.names.indexOf(e)==-1&&(this.names.push(e),this.dom&&(this.dom.insertAdjacentHTML("beforeend",this.svg),this.updateUI()),this.cpuAccums.push(0),this.gpuAccums.push(0),this.activeAccums.push(!1))}nextFrame(e){this.frameId++;const t=e||this.now();if(this.frameId<=1)this.paramFrame=this.frameId,this.paramTime=t;else{let i=t-this.paramTime;if(i>=1e3){const r=this.frameId-this.paramFrame,s=r/i*1e3;for(let o=0;o<this.names.length;o++){const a=this.cpuAccums[o]/i*100,l=this.gpuAccums[o]/i*100,c=performance&&performance.memory?performance.memory.usedJSHeapSize/(1<<20):0;this.paramLogger(o,a,l,c,s,i,r),this.cpuAccums[o]=0,Promise.all(this.finished).then(()=>{this.gpuAccums[o]=0,this.finished=[]})}this.paramFrame=this.frameId,this.paramTime=t}}if(!this.detected||!this.chartFrame)this.chartFrame=this.frameId,this.chartTime=t,this.circularId=0;else{let i=t-this.chartTime,r=this.chartHz*i/1e3;for(;--r>0&&this.detected;){const o=(this.frameId-this.chartFrame)/i*1e3;this.chart[this.circularId%this.chartLen]=o;for(let a=0;a<this.names.length;a++)this.chartLogger(a,this.chart,this.circularId);this.circularId++,this.chartFrame=this.frameId,this.chartTime=t}}}begin(e){this.updateAccums(e)}end(e){this.updateAccums(e)}updateAccums(e){let t=this.names.indexOf(e);t==-1&&(t=this.names.length,this.addUI(e));const i=this.now(),r=i-this.t0;for(let s=0;s<t+1;s++)this.activeAccums[s]&&(this.cpuAccums[s]+=r);this.activeAccums[t]=!this.activeAccums[t],this.t0=i}}const iv=`
759
759
  #gl-bench {
760
760
  position:absolute;
761
761
  right:0;
@@ -807,13 +807,13 @@ void main() {
807
807
  #gl-bench .opacity {
808
808
  stroke: #8288e4;
809
809
  }
810
- `;class Iu{constructor(e){this.destroy();const t=e.getContext("webgl")||e.getContext("experimental-webgl");this.bench=new lv(t,{css:cv})}begin(){var e;(e=this.bench)==null||e.begin("frame")}end(e){var t,i;(t=this.bench)==null||t.end("frame"),(i=this.bench)==null||i.nextFrame(e)}destroy(){this.bench=void 0,we("#gl-bench").remove()}}var Pu=(n=>(n[n.Circle=0]="Circle",n[n.Square=1]="Square",n[n.Triangle=2]="Triangle",n[n.Diamond=3]="Diamond",n[n.Pentagon=4]="Pentagon",n[n.Hexagon=5]="Hexagon",n[n.Star=6]="Star",n[n.Cross=7]="Cross",n[n.None=8]="None",n))(Pu||{});class uv{constructor(e){this._config=e}get pointsNumber(){return this.pointPositions&&this.pointPositions.length/2}get linksNumber(){return this.links&&this.links.length/2}updatePoints(){this.pointPositions=this.inputPointPositions}updatePointColor(){if(this.pointsNumber===void 0){this.pointColors=void 0;return}const e=Tt(this._config.pointDefaultColor);if(this.inputPointColors===void 0||this.inputPointColors.length/4!==this.pointsNumber){this.pointColors=new Float32Array(this.pointsNumber*4);for(let t=0;t<this.pointColors.length/4;t++)this.pointColors[t*4]=e[0],this.pointColors[t*4+1]=e[1],this.pointColors[t*4+2]=e[2],this.pointColors[t*4+3]=e[3]}else{this.pointColors=this.inputPointColors;for(let t=0;t<this.pointColors.length/4;t++)Ke(this.pointColors[t*4])||(this.pointColors[t*4]=e[0]),Ke(this.pointColors[t*4+1])||(this.pointColors[t*4+1]=e[1]),Ke(this.pointColors[t*4+2])||(this.pointColors[t*4+2]=e[2]),Ke(this.pointColors[t*4+3])||(this.pointColors[t*4+3]=e[3])}}updatePointSize(){if(this.pointsNumber===void 0){this.pointSizes=void 0;return}const e=this._config.pointDefaultSize;if(this.inputPointSizes===void 0||this.inputPointSizes.length!==this.pointsNumber)this.pointSizes=new Float32Array(this.pointsNumber).fill(e);else{this.pointSizes=this.inputPointSizes;for(let t=0;t<this.pointSizes.length;t++)Ke(this.pointSizes[t])||(this.pointSizes[t]=e)}}updatePointShape(){if(this.pointsNumber===void 0){this.pointShapes=void 0;return}const e=0;if(this.inputPointShapes===void 0||this.inputPointShapes.length!==this.pointsNumber)this.pointShapes=new Float32Array(this.pointsNumber).fill(e);else{this.pointShapes=new Float32Array(this.inputPointShapes);const t=this.pointShapes;for(let i=0;i<t.length;i++){const r=t[i];(r==null||!Ke(r)||r<0||r>8)&&(t[i]=e)}}}updatePointImageIndices(){if(this.pointsNumber===void 0){this.pointImageIndices=void 0;return}if(this.inputPointImageIndices===void 0||this.inputPointImageIndices.length!==this.pointsNumber)this.pointImageIndices=new Float32Array(this.pointsNumber).fill(-1);else{const e=new Float32Array(this.inputPointImageIndices);for(let t=0;t<e.length;t++){const i=e[t],r=i===void 0?NaN:i;!Number.isFinite(r)||r<0?e[t]=-1:e[t]=Math.trunc(r)}this.pointImageIndices=e}}updatePointImageSizes(){var t;if(this.pointsNumber===void 0){this.pointImageSizes=void 0;return}const e=this._config.pointDefaultSize;if(this.inputPointImageSizes===void 0||this.inputPointImageSizes.length!==this.pointsNumber)this.pointImageSizes=this.pointSizes?new Float32Array(this.pointSizes):new Float32Array(this.pointsNumber).fill(e);else{this.pointImageSizes=new Float32Array(this.inputPointImageSizes);for(let i=0;i<this.pointImageSizes.length;i++)Ke(this.pointImageSizes[i])||(this.pointImageSizes[i]=((t=this.pointSizes)==null?void 0:t[i])??e)}}updateLinks(){this.links=this.inputLinks}updateLinkColor(){if(this.linksNumber===void 0){this.linkColors=void 0;return}const e=Tt(this._config.linkDefaultColor);if(this.inputLinkColors===void 0||this.inputLinkColors.length/4!==this.linksNumber){this.linkColors=new Float32Array(this.linksNumber*4);for(let t=0;t<this.linkColors.length/4;t++)this.linkColors[t*4]=e[0],this.linkColors[t*4+1]=e[1],this.linkColors[t*4+2]=e[2],this.linkColors[t*4+3]=e[3]}else{this.linkColors=this.inputLinkColors;for(let t=0;t<this.linkColors.length/4;t++)Ke(this.linkColors[t*4])||(this.linkColors[t*4]=e[0]),Ke(this.linkColors[t*4+1])||(this.linkColors[t*4+1]=e[1]),Ke(this.linkColors[t*4+2])||(this.linkColors[t*4+2]=e[2]),Ke(this.linkColors[t*4+3])||(this.linkColors[t*4+3]=e[3])}}updateLinkWidth(){if(this.linksNumber===void 0){this.linkWidths=void 0;return}const e=this._config.linkDefaultWidth;if(this.inputLinkWidths===void 0||this.inputLinkWidths.length!==this.linksNumber)this.linkWidths=new Float32Array(this.linksNumber).fill(e);else{this.linkWidths=this.inputLinkWidths;for(let t=0;t<this.linkWidths.length;t++)Ke(this.linkWidths[t])||(this.linkWidths[t]=e)}}updateArrows(){if(this.linksNumber===void 0){this.linkArrows=void 0;return}const e=this._config.linkDefaultArrows;this.linkArrowsBoolean===void 0||this.linkArrowsBoolean.length!==this.linksNumber?this.linkArrows=new Array(this.linksNumber).fill(+e):this.linkArrows=this.linkArrowsBoolean.map(t=>+t)}updateLinkStrength(){this.linksNumber===void 0&&(this.linkStrength=void 0),this.inputLinkStrength===void 0||this.inputLinkStrength.length!==this.linksNumber?this.linkStrength=void 0:this.linkStrength=this.inputLinkStrength}updateClusters(){if(this.pointsNumber===void 0){this.pointClusters=void 0,this.clusterPositions=void 0;return}this.inputPointClusters===void 0||this.inputPointClusters.length!==this.pointsNumber?this.pointClusters=void 0:this.pointClusters=this.inputPointClusters,this.inputClusterPositions===void 0?this.clusterPositions=void 0:this.clusterPositions=this.inputClusterPositions,this.inputClusterStrength===void 0||this.inputClusterStrength.length!==this.pointsNumber?this.clusterStrength=void 0:this.clusterStrength=this.inputClusterStrength}update(){this.updatePoints(),this.updatePointColor(),this.updatePointSize(),this.updatePointShape(),this.updatePointImageIndices(),this.updatePointImageSizes(),this.updateLinks(),this.updateLinkColor(),this.updateLinkWidth(),this.updateArrows(),this.updateLinkStrength(),this.updateClusters(),this._createAdjacencyLists(),this._calculateDegrees()}getAdjacentIndices(e){var t,i,r,s;return[...((i=(t=this.sourceIndexToTargetIndices)==null?void 0:t[e])==null?void 0:i.map(o=>o[0]))||[],...((s=(r=this.targetIndexToSourceIndices)==null?void 0:r[e])==null?void 0:s.map(o=>o[0]))||[]]}_createAdjacencyLists(){var e,t;if(this.linksNumber===void 0||this.links===void 0){this.sourceIndexToTargetIndices=void 0,this.targetIndexToSourceIndices=void 0;return}this.sourceIndexToTargetIndices=new Array(this.pointsNumber).fill(void 0),this.targetIndexToSourceIndices=new Array(this.pointsNumber).fill(void 0);for(let i=0;i<this.linksNumber;i++){const r=this.links[i*2],s=this.links[i*2+1];r!==void 0&&s!==void 0&&(this.sourceIndexToTargetIndices[r]===void 0&&(this.sourceIndexToTargetIndices[r]=[]),(e=this.sourceIndexToTargetIndices[r])==null||e.push([s,i]),this.targetIndexToSourceIndices[s]===void 0&&(this.targetIndexToSourceIndices[s]=[]),(t=this.targetIndexToSourceIndices[s])==null||t.push([r,i]))}}_calculateDegrees(){var e,t,i,r;if(this.pointsNumber===void 0){this.degree=void 0,this.inDegree=void 0,this.outDegree=void 0;return}this.degree=new Array(this.pointsNumber).fill(0),this.inDegree=new Array(this.pointsNumber).fill(0),this.outDegree=new Array(this.pointsNumber).fill(0);for(let s=0;s<this.pointsNumber;s++)this.inDegree[s]=((t=(e=this.targetIndexToSourceIndices)==null?void 0:e[s])==null?void 0:t.length)??0,this.outDegree[s]=((r=(i=this.sourceIndexToTargetIndices)==null?void 0:i[s])==null?void 0:r.length)??0,this.degree[s]=(this.inDegree[s]??0)+(this.outDegree[s]??0)}}const Eu={name:"conicParametricCurve",vs:`
810
+ `;class bu{constructor(e){this.destroy();const t=e.getContext("webgl")||e.getContext("experimental-webgl");this.bench=new nv(t,{css:iv})}begin(){var e;(e=this.bench)==null||e.begin("frame")}end(e){var t,i;(t=this.bench)==null||t.end("frame"),(i=this.bench)==null||i.nextFrame(e)}destroy(){this.bench=void 0,we("#gl-bench").remove()}}const Su={name:"conicParametricCurve",vs:`
811
811
  vec2 conicParametricCurve(vec2 A, vec2 B, vec2 ControlPoint, float t, float w) {
812
812
  vec2 divident = (1.0 - t) * (1.0 - t) * A + 2.0 * (1.0 - t) * t * w * ControlPoint + t * t * B;
813
813
  float divisor = (1.0 - t) * (1.0 - t) + 2.0 * (1.0 - t) * t * w + t * t;
814
814
  return divident / divisor;
815
815
  }
816
- `},fv=`#version 300 es
816
+ `},rv=`#version 300 es
817
817
  #ifdef GL_ES
818
818
  precision highp float;
819
819
  #endif
@@ -871,7 +871,7 @@ void main() {
871
871
  }
872
872
  } else fragColor = vec4(color, opacity);
873
873
 
874
- }`,hv=`#version 300 es
874
+ }`,sv=`#version 300 es
875
875
  #ifdef GL_ES
876
876
  precision highp float;
877
877
  #endif
@@ -1112,7 +1112,7 @@ void main() {
1112
1112
  #endif
1113
1113
 
1114
1114
  gl_Position = vec4(final.rg, 0, 1);
1115
- }`,dv=`#version 300 es
1115
+ }`,ov=`#version 300 es
1116
1116
  #ifdef GL_ES
1117
1117
  precision highp float;
1118
1118
  #endif
@@ -1124,7 +1124,7 @@ out vec4 fragColor;
1124
1124
  void main() {
1125
1125
  fragColor = rgba;
1126
1126
  }
1127
- `,pv=`#version 300 es
1127
+ `,av=`#version 300 es
1128
1128
  #ifdef GL_ES
1129
1129
  precision highp float;
1130
1130
  #endif
@@ -1205,7 +1205,7 @@ void main() {
1205
1205
 
1206
1206
  gl_PointSize = 1.0;
1207
1207
  }
1208
- `,mv=`#version 300 es
1208
+ `,lv=`#version 300 es
1209
1209
  #ifdef GL_ES
1210
1210
  precision highp float;
1211
1211
  #endif
@@ -1245,7 +1245,7 @@ void main() {
1245
1245
  // No link at this position, output -1 to indicate no hover
1246
1246
  fragColor = vec4(-1.0, 0.0, 0.0, 0.0);
1247
1247
  }
1248
- } `,gv=`#version 300 es
1248
+ } `,cv=`#version 300 es
1249
1249
  #ifdef GL_ES
1250
1250
  precision highp float;
1251
1251
  #endif
@@ -1254,7 +1254,7 @@ in vec2 vertexCoord;
1254
1254
 
1255
1255
  void main() {
1256
1256
  gl_Position = vec4(vertexCoord, 0.0, 1.0);
1257
- } `,_v=n=>{const e=dc().exponent(2).range([0,1]).domain([-1,1]),t=cx(0,n).map(r=>-.5+r/n);t.push(.5);const i=new Array(t.length*2);return t.forEach((r,s)=>{i[s*2]=[e(r*2),.5],i[s*2+1]=[e(r*2),-.5]}),i};class xv extends Nt{initPrograms(){var o;const{device:e,config:t,store:i,data:r}=this;this.updateLinkIndexFbo(),this.hoveredLineIndexTexture||(this.hoveredLineIndexTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST,data:new Float32Array(4).fill(0)})),this.hoveredLineIndexFbo||(this.hoveredLineIndexFbo=e.createFramebuffer({width:1,height:1,colorAttachments:[this.hoveredLineIndexTexture]})),this.curveLineGeometry||this.updateCurveLineGeometry();const s=this.data.linksNumber??0;this.pointABuffer||(this.pointABuffer=e.createBuffer({data:new Float32Array(s*2),usage:L.VERTEX|L.COPY_DST})),this.pointBBuffer||(this.pointBBuffer=e.createBuffer({data:new Float32Array(s*2),usage:L.VERTEX|L.COPY_DST})),this.colorBuffer||(this.colorBuffer=e.createBuffer({data:new Float32Array(s*4),usage:L.VERTEX|L.COPY_DST})),this.widthBuffer||(this.widthBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.arrowBuffer||(this.arrowBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.linkIndexBuffer||(this.linkIndexBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.drawLineUniformStore||(this.drawLineUniformStore=new xe({drawLineUniforms:{uniformTypes:{transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",widthScale:"f32",linkArrowsSizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",linkVisibilityDistanceRange:"vec2<f32>",linkVisibilityMinTransparency:"f32",linkOpacity:"f32",greyoutOpacity:"f32",curvedWeight:"f32",curvedLinkControlPointDistance:"f32",curvedLinkSegments:"f32",scaleLinksOnZoom:"f32",maxPointSize:"f32",renderMode:"f32",hoveredLinkIndex:"f32",hoveredLinkColor:"vec4<f32>",hoveredLinkWidthIncrease:"f32"},defaultUniforms:{transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize,widthScale:t.linkWidthScale??1,linkArrowsSizeScale:t.linkArrowsSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),linkVisibilityDistanceRange:re(t.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:t.linkVisibilityMinTransparency??0,linkOpacity:t.linkOpacity??1,greyoutOpacity:t.linkGreyoutOpacity??1,curvedWeight:t.curvedLinkWeight??0,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance??0,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments??V.curvedLinkSegments:1,scaleLinksOnZoom:t.scaleLinksOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,renderMode:0,hoveredLinkIndex:i.hoveredLinkIndex??-1,hoveredLinkColor:Re(i.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease??0}},drawLineFragmentUniforms:{uniformTypes:{renderMode:"f32"},defaultUniforms:{renderMode:0}}})),this.drawCurveCommand||(this.drawCurveCommand=new me(e,{vs:hv,fs:fv,modules:[Eu],topology:"triangle-strip",vertexCount:((o=this.curveLineGeometry)==null?void 0:o.length)??0,attributes:{...this.curveLineBuffer&&{position:this.curveLineBuffer},...this.pointABuffer&&{pointA:this.pointABuffer},...this.pointBBuffer&&{pointB:this.pointBBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.widthBuffer&&{width:this.widthBuffer},...this.arrowBuffer&&{arrow:this.arrowBuffer},...this.linkIndexBuffer&&{linkIndices:this.linkIndexBuffer}},bufferLayout:[{name:"position",format:"float32x2"},{name:"pointA",format:"float32x2",stepMode:"instance"},{name:"pointB",format:"float32x2",stepMode:"instance"},{name:"color",format:"float32x4",stepMode:"instance"},{name:"width",format:"float32",stepMode:"instance"},{name:"arrow",format:"float32",stepMode:"instance"},{name:"linkIndices",format:"float32",stepMode:"instance"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawLineUniforms:this.drawLineUniformStore.getManagedUniformBuffer(e,"drawLineUniforms"),drawLineFragmentUniforms:this.drawLineUniformStore.getManagedUniformBuffer(e,"drawLineFragmentUniforms")},parameters:{cullMode:"back",blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.quadBuffer||(this.quadBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1]),usage:L.VERTEX|L.COPY_DST})),this.hoveredLineIndexUniformStore||(this.hoveredLineIndexUniformStore=new xe({hoveredLineIndexUniforms:{uniformTypes:{mousePosition:"vec2<f32>",screenSize:"vec2<f32>"},defaultUniforms:{mousePosition:re(i.screenMousePosition,[0,0]),screenSize:re(i.screenSize,[0,0])}}})),this.hoveredLineIndexCommand||(this.hoveredLineIndexCommand=new me(e,{vs:gv,fs:mv,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.quadBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{hoveredLineIndexUniforms:this.hoveredLineIndexUniformStore.getManagedUniformBuffer(e,"hoveredLineIndexUniforms")}})),this.fillSampledLinksUniformStore||(this.fillSampledLinksUniformStore=new xe({fillSampledLinksUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>",curvedWeight:"f32",curvedLinkControlPointDistance:"f32",curvedLinkSegments:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),curvedWeight:t.curvedLinkWeight??0,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance??0,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments??V.curvedLinkSegments:1}}})),this.fillSampledLinksFboCommand||(this.fillSampledLinksFboCommand=new me(e,{fs:dv,vs:pv,modules:[Eu],topology:"point-list",vertexCount:r.linksNumber??0,attributes:{...this.pointABuffer&&{pointA:this.pointABuffer},...this.pointBBuffer&&{pointB:this.pointBBuffer},...this.linkIndexBuffer&&{linkIndices:this.linkIndexBuffer}},bufferLayout:[{name:"pointA",format:"float32x2"},{name:"pointB",format:"float32x2"},{name:"linkIndices",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledLinksUniforms:this.fillSampledLinksUniformStore.getManagedUniformBuffer(e,"fillSampledLinksUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.updateSampledLinksGrid()}draw(e){const{config:t,points:i,store:r}=this;i&&(!i.currentPositionTexture||i.currentPositionTexture.destroyed||!i.greyoutStatusTexture||i.greyoutStatusTexture.destroyed||((!this.pointABuffer||!this.pointBBuffer)&&this.updatePointsBuffer(),this.colorBuffer||this.updateColor(),this.widthBuffer||this.updateWidth(),this.arrowBuffer||this.updateArrow(),this.curveLineGeometry||this.updateCurveLineGeometry(),!(!this.drawCurveCommand||!this.drawLineUniformStore)&&(this.drawLineUniformStore.setUniforms({drawLineUniforms:{transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize,widthScale:t.linkWidthScale??1,linkArrowsSizeScale:t.linkArrowsSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),linkVisibilityDistanceRange:re(t.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:t.linkVisibilityMinTransparency??0,linkOpacity:t.linkOpacity??1,greyoutOpacity:t.linkGreyoutOpacity??1,curvedWeight:t.curvedLinkWeight??0,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance??0,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments??V.curvedLinkSegments:1,scaleLinksOnZoom:t.scaleLinksOnZoom??!0?1:0,maxPointSize:r.maxPointSize??100,renderMode:0,hoveredLinkIndex:r.hoveredLinkIndex??-1,hoveredLinkColor:Re(r.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease??0},drawLineFragmentUniforms:{renderMode:0}}),this.drawCurveCommand.setBindings({positionsTexture:i.currentPositionTexture,pointGreyoutStatus:i.greyoutStatusTexture}),this.drawCurveCommand.setInstanceCount(this.data.linksNumber??0),this.drawCurveCommand.draw(e))))}updateLinkIndexFbo(){var a,l;const{device:e,store:t}=this;if(!this.store.isLinkHoveringEnabled)return;const i=t.screenSize??[0,0],r=i[0],s=i[1];if(!r||!s)return;const o=((a=this.previousScreenSize)==null?void 0:a[0])!==r||((l=this.previousScreenSize)==null?void 0:l[1])!==s;(!this.linkIndexTexture||o)&&(this.linkIndexFbo&&!this.linkIndexFbo.destroyed&&this.linkIndexFbo.destroy(),this.linkIndexTexture&&!this.linkIndexTexture.destroyed&&this.linkIndexTexture.destroy(),this.linkIndexTexture=e.createTexture({width:r,height:s,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.linkIndexTexture.copyImageData({data:new Float32Array(r*s*4).fill(0),bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),this.linkIndexFbo=e.createFramebuffer({width:r,height:s,colorAttachments:[this.linkIndexTexture]}),this.previousScreenSize=[r,s])}updateSampledLinksGrid(){const{store:{screenSize:e},config:{linkSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=V.linkSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);s===0||o===0||(!this.sampledLinksFbo||this.sampledLinksFbo.width!==s||this.sampledLinksFbo.height!==o)&&(this.sampledLinksFbo&&!this.sampledLinksFbo.destroyed&&this.sampledLinksFbo.destroy(),this.sampledLinksFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}updatePointsBuffer(){var l;const{device:e,data:t,store:i}=this;if(t.linksNumber===void 0||t.links===void 0||!i.pointsTextureSize)return;const r=new Float32Array(t.linksNumber*2),s=new Float32Array(t.linksNumber*2);for(let c=0;c<t.linksNumber;c++){const u=t.links[c*2],f=t.links[c*2+1],h=u%i.pointsTextureSize,d=Math.floor(u/i.pointsTextureSize),_=f%i.pointsTextureSize,I=Math.floor(f/i.pointsTextureSize);r[c*2]=h,r[c*2+1]=d,s[c*2]=_,s[c*2+1]=I}const o=(((l=this.pointABuffer)==null?void 0:l.byteLength)??0)/(Float32Array.BYTES_PER_ELEMENT*2);!this.pointABuffer||o!==t.linksNumber?(this.pointABuffer&&!this.pointABuffer.destroyed&&this.pointABuffer.destroy(),this.pointABuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.pointABuffer.write(r),!this.pointBBuffer||o!==t.linksNumber?(this.pointBBuffer&&!this.pointBBuffer.destroyed&&this.pointBBuffer.destroy(),this.pointBBuffer=e.createBuffer({data:s,usage:L.VERTEX|L.COPY_DST})):this.pointBBuffer.write(s);const a=new Float32Array(t.linksNumber);for(let c=0;c<t.linksNumber;c++)a[c]=c;!this.linkIndexBuffer||o!==t.linksNumber?(this.linkIndexBuffer&&!this.linkIndexBuffer.destroyed&&this.linkIndexBuffer.destroy(),this.linkIndexBuffer=e.createBuffer({data:a,usage:L.VERTEX|L.COPY_DST})):this.linkIndexBuffer.write(a),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({pointA:this.pointABuffer,pointB:this.pointBBuffer,linkIndices:this.linkIndexBuffer}),this.fillSampledLinksFboCommand&&this.fillSampledLinksFboCommand.setAttributes({pointA:this.pointABuffer,pointB:this.pointBBuffer,linkIndices:this.linkIndexBuffer}),this.updateSampledLinksGrid()}updateColor(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkColors??new Float32Array(i*4).fill(0);this.colorBuffer?(this.colorBuffer.byteLength??0)/(Float32Array.BYTES_PER_ELEMENT*4)!==i?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r):this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({color:this.colorBuffer})}updateWidth(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkWidths??new Float32Array(i).fill(0);this.widthBuffer?(this.widthBuffer.byteLength??0)/Float32Array.BYTES_PER_ELEMENT!==i?(this.widthBuffer&&!this.widthBuffer.destroyed&&this.widthBuffer.destroy(),this.widthBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.widthBuffer.write(r):this.widthBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({width:this.widthBuffer})}updateArrow(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkArrows?new Float32Array(t.linkArrows):new Float32Array(i).fill(0);this.arrowBuffer?(this.arrowBuffer.byteLength??0)/Float32Array.BYTES_PER_ELEMENT!==i?(this.arrowBuffer&&!this.arrowBuffer.destroyed&&this.arrowBuffer.destroy(),this.arrowBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.arrowBuffer.write(r):this.arrowBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({arrow:this.arrowBuffer})}updateCurveLineGeometry(){const{device:e,config:{curvedLinks:t,curvedLinkSegments:i}}=this;this.curveLineGeometry=_v(t?i??V.curvedLinkSegments:1);const r=new Float32Array(this.curveLineGeometry.length*2);for(let s=0;s<this.curveLineGeometry.length;s++)r[s*2]=this.curveLineGeometry[s][0],r[s*2+1]=this.curveLineGeometry[s][1];!this.curveLineBuffer||this.curveLineBuffer.byteLength!==r.byteLength?(this.curveLineBuffer&&!this.curveLineBuffer.destroyed&&this.curveLineBuffer.destroy(),this.curveLineBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.curveLineBuffer.write(r),this.drawCurveCommand&&(this.drawCurveCommand.setAttributes({position:this.curveLineBuffer}),this.drawCurveCommand.setVertexCount(this.curveLineGeometry.length))}getSampledLinkPositionsMap(){const e=new Map;if(!this.sampledLinksFbo||this.sampledLinksFbo.destroyed)return e;const t=this.points;if(!(t!=null&&t.currentPositionTexture)||t.currentPositionTexture.destroyed)return e;if(this.fillSampledLinksFboCommand&&this.fillSampledLinksUniformStore&&this.sampledLinksFbo){this.fillSampledLinksFboCommand.setVertexCount(this.data.linksNumber??0),this.fillSampledLinksUniformStore.setUniforms({fillSampledLinksUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),curvedWeight:this.config.curvedLinkWeight??0,curvedLinkControlPointDistance:this.config.curvedLinkControlPointDistance??0,curvedLinkSegments:this.config.curvedLinks?this.config.curvedLinkSegments??V.curvedLinkSegments:1}}),this.fillSampledLinksFboCommand.setBindings({positionsTexture:t.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledLinksFbo,clearColor:[-1,-1,-1,-1]});this.fillSampledLinksFboCommand.draw(r),r.end()}const i=Me(this.device,this.sampledLinksFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=i[r*4+1],a=i[r*4+2],l=i[r*4+3];s!==void 0&&s>=0&&o!==void 0&&a!==void 0&&l!==void 0&&e.set(Math.round(s),[o,a,l])}return e}getSampledLinks(){const e=[],t=[],i=[];if(!this.sampledLinksFbo||this.sampledLinksFbo.destroyed)return{indices:e,positions:t,angles:i};const r=this.points;if(!(r!=null&&r.currentPositionTexture)||r.currentPositionTexture.destroyed)return{indices:e,positions:t,angles:i};if(this.fillSampledLinksFboCommand&&this.fillSampledLinksUniformStore&&this.sampledLinksFbo){this.fillSampledLinksFboCommand.setVertexCount(this.data.linksNumber??0),this.fillSampledLinksUniformStore.setUniforms({fillSampledLinksUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),curvedWeight:this.config.curvedLinkWeight??0,curvedLinkControlPointDistance:this.config.curvedLinkControlPointDistance??0,curvedLinkSegments:this.config.curvedLinks?this.config.curvedLinkSegments??V.curvedLinkSegments:1}}),this.fillSampledLinksFboCommand.setBindings({positionsTexture:r.currentPositionTexture});const o=this.device.beginRenderPass({framebuffer:this.sampledLinksFbo,clearColor:[-1,-1,-1,-1]});this.fillSampledLinksFboCommand.draw(o),o.end()}const s=Me(this.device,this.sampledLinksFbo);for(let o=0;o<s.length/4;o++){const a=s[o*4],l=s[o*4+1],c=s[o*4+2],u=s[o*4+3];a!==void 0&&a>=0&&l!==void 0&&c!==void 0&&u!==void 0&&(e.push(Math.round(a)),t.push(l,c),i.push(u))}return{indices:e,positions:t,angles:i}}findHoveredLine(){const{config:e,points:t,store:i}=this;if(!t||!t.currentPositionTexture||t.currentPositionTexture.destroyed||!t.greyoutStatusTexture||t.greyoutStatusTexture.destroyed||!this.data.linksNumber||!this.store.isLinkHoveringEnabled||!this.linkIndexFbo||!this.drawCurveCommand||!this.drawLineUniformStore||!this.linkIndexTexture||this.linkIndexTexture.destroyed)return;this.drawLineUniformStore.setUniforms({drawLineUniforms:{transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize,widthScale:e.linkWidthScale??1,linkArrowsSizeScale:e.linkArrowsSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),linkVisibilityDistanceRange:re(e.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:e.linkVisibilityMinTransparency??0,linkOpacity:e.linkOpacity??1,greyoutOpacity:e.linkGreyoutOpacity??1,curvedWeight:e.curvedLinkWeight??0,curvedLinkControlPointDistance:e.curvedLinkControlPointDistance??0,curvedLinkSegments:e.curvedLinks?e.curvedLinkSegments??V.curvedLinkSegments:1,scaleLinksOnZoom:e.scaleLinksOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,renderMode:1,hoveredLinkIndex:i.hoveredLinkIndex??-1,hoveredLinkColor:Re(i.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:e.hoveredLinkWidthIncrease??0},drawLineFragmentUniforms:{renderMode:1}}),this.drawCurveCommand.setBindings({positionsTexture:t.currentPositionTexture,pointGreyoutStatus:t.greyoutStatusTexture}),this.drawCurveCommand.setInstanceCount(this.data.linksNumber??0);const r=this.device.beginRenderPass({framebuffer:this.linkIndexFbo,clearColor:[0,0,0,0]});if(this.drawCurveCommand.draw(r),r.end(),this.hoveredLineIndexCommand&&this.hoveredLineIndexFbo&&this.hoveredLineIndexUniformStore){this.hoveredLineIndexUniformStore.setUniforms({hoveredLineIndexUniforms:{mousePosition:re(i.screenMousePosition,[0,0]),screenSize:re(i.screenSize,[0,0])}}),this.hoveredLineIndexCommand.setBindings({linkIndexTexture:this.linkIndexTexture});const s=this.device.beginRenderPass({framebuffer:this.hoveredLineIndexFbo});this.hoveredLineIndexCommand.draw(s),s.end()}}destroy(){var e,t,i,r,s,o;(e=this.drawCurveCommand)==null||e.destroy(),this.drawCurveCommand=void 0,(t=this.hoveredLineIndexCommand)==null||t.destroy(),this.hoveredLineIndexCommand=void 0,(i=this.fillSampledLinksFboCommand)==null||i.destroy(),this.fillSampledLinksFboCommand=void 0,this.linkIndexFbo&&!this.linkIndexFbo.destroyed&&this.linkIndexFbo.destroy(),this.linkIndexFbo=void 0,this.sampledLinksFbo&&!this.sampledLinksFbo.destroyed&&this.sampledLinksFbo.destroy(),this.sampledLinksFbo=void 0,this.hoveredLineIndexFbo&&!this.hoveredLineIndexFbo.destroyed&&this.hoveredLineIndexFbo.destroy(),this.hoveredLineIndexFbo=void 0,this.linkIndexTexture&&!this.linkIndexTexture.destroyed&&this.linkIndexTexture.destroy(),this.linkIndexTexture=void 0,this.hoveredLineIndexTexture&&!this.hoveredLineIndexTexture.destroyed&&this.hoveredLineIndexTexture.destroy(),this.hoveredLineIndexTexture=void 0,(r=this.drawLineUniformStore)==null||r.destroy(),this.drawLineUniformStore=void 0,(s=this.hoveredLineIndexUniformStore)==null||s.destroy(),this.hoveredLineIndexUniformStore=void 0,(o=this.fillSampledLinksUniformStore)==null||o.destroy(),this.fillSampledLinksUniformStore=void 0,this.pointABuffer&&!this.pointABuffer.destroyed&&this.pointABuffer.destroy(),this.pointABuffer=void 0,this.pointBBuffer&&!this.pointBBuffer.destroyed&&this.pointBBuffer.destroy(),this.pointBBuffer=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.widthBuffer&&!this.widthBuffer.destroyed&&this.widthBuffer.destroy(),this.widthBuffer=void 0,this.arrowBuffer&&!this.arrowBuffer.destroyed&&this.arrowBuffer.destroy(),this.arrowBuffer=void 0,this.curveLineBuffer&&!this.curveLineBuffer.destroyed&&this.curveLineBuffer.destroy(),this.curveLineBuffer=void 0,this.linkIndexBuffer&&!this.linkIndexBuffer.destroyed&&this.linkIndexBuffer.destroy(),this.linkIndexBuffer=void 0,this.quadBuffer&&!this.quadBuffer.destroyed&&this.quadBuffer.destroy(),this.quadBuffer=void 0}}const yv=`#version 300 es
1257
+ } `,uv=n=>{const e=rc().exponent(2).range([0,1]).domain([-1,1]),t=tx(0,n).map(r=>-.5+r/n);t.push(.5);const i=new Array(t.length*2);return t.forEach((r,s)=>{i[s*2]=[e(r*2),.5],i[s*2+1]=[e(r*2),-.5]}),i};class fv extends Ot{initPrograms(){var o;const{device:e,config:t,store:i,data:r}=this;this.updateLinkIndexFbo(),this.hoveredLineIndexTexture||(this.hoveredLineIndexTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST,data:new Float32Array(4).fill(0)})),this.hoveredLineIndexFbo||(this.hoveredLineIndexFbo=e.createFramebuffer({width:1,height:1,colorAttachments:[this.hoveredLineIndexTexture]})),this.curveLineGeometry||this.updateCurveLineGeometry();const s=this.data.linksNumber??0;this.pointABuffer||(this.pointABuffer=e.createBuffer({data:new Float32Array(s*2),usage:L.VERTEX|L.COPY_DST})),this.pointBBuffer||(this.pointBBuffer=e.createBuffer({data:new Float32Array(s*2),usage:L.VERTEX|L.COPY_DST})),this.colorBuffer||(this.colorBuffer=e.createBuffer({data:new Float32Array(s*4),usage:L.VERTEX|L.COPY_DST})),this.widthBuffer||(this.widthBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.arrowBuffer||(this.arrowBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.linkIndexBuffer||(this.linkIndexBuffer=e.createBuffer({data:new Float32Array(s),usage:L.VERTEX|L.COPY_DST})),this.drawLineUniformStore||(this.drawLineUniformStore=new _e({drawLineUniforms:{uniformTypes:{transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",widthScale:"f32",linkArrowsSizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",linkVisibilityDistanceRange:"vec2<f32>",linkVisibilityMinTransparency:"f32",linkOpacity:"f32",greyoutOpacity:"f32",curvedWeight:"f32",curvedLinkControlPointDistance:"f32",curvedLinkSegments:"f32",scaleLinksOnZoom:"f32",maxPointSize:"f32",renderMode:"f32",hoveredLinkIndex:"f32",hoveredLinkColor:"vec4<f32>",hoveredLinkWidthIncrease:"f32"},defaultUniforms:{transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize,widthScale:t.linkWidthScale,linkArrowsSizeScale:t.linkArrowsSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),linkVisibilityDistanceRange:ne(t.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:t.linkVisibilityMinTransparency,linkOpacity:t.linkOpacity,greyoutOpacity:t.linkGreyoutOpacity,curvedWeight:t.curvedLinkWeight,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments:1,scaleLinksOnZoom:t.scaleLinksOnZoom?1:0,maxPointSize:i.maxPointSize,renderMode:0,hoveredLinkIndex:i.hoveredLinkIndex??-1,hoveredLinkColor:Re(i.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease}},drawLineFragmentUniforms:{uniformTypes:{renderMode:"f32"},defaultUniforms:{renderMode:0}}})),this.drawCurveCommand||(this.drawCurveCommand=new pe(e,{vs:sv,fs:rv,modules:[Su],topology:"triangle-strip",vertexCount:((o=this.curveLineGeometry)==null?void 0:o.length)??0,attributes:{...this.curveLineBuffer&&{position:this.curveLineBuffer},...this.pointABuffer&&{pointA:this.pointABuffer},...this.pointBBuffer&&{pointB:this.pointBBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.widthBuffer&&{width:this.widthBuffer},...this.arrowBuffer&&{arrow:this.arrowBuffer},...this.linkIndexBuffer&&{linkIndices:this.linkIndexBuffer}},bufferLayout:[{name:"position",format:"float32x2"},{name:"pointA",format:"float32x2",stepMode:"instance"},{name:"pointB",format:"float32x2",stepMode:"instance"},{name:"color",format:"float32x4",stepMode:"instance"},{name:"width",format:"float32",stepMode:"instance"},{name:"arrow",format:"float32",stepMode:"instance"},{name:"linkIndices",format:"float32",stepMode:"instance"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawLineUniforms:this.drawLineUniformStore.getManagedUniformBuffer(e,"drawLineUniforms"),drawLineFragmentUniforms:this.drawLineUniformStore.getManagedUniformBuffer(e,"drawLineFragmentUniforms")},parameters:{cullMode:"back",blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.quadBuffer||(this.quadBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1]),usage:L.VERTEX|L.COPY_DST})),this.hoveredLineIndexUniformStore||(this.hoveredLineIndexUniformStore=new _e({hoveredLineIndexUniforms:{uniformTypes:{mousePosition:"vec2<f32>",screenSize:"vec2<f32>"},defaultUniforms:{mousePosition:ne(i.screenMousePosition,[0,0]),screenSize:ne(i.screenSize,[0,0])}}})),this.hoveredLineIndexCommand||(this.hoveredLineIndexCommand=new pe(e,{vs:cv,fs:lv,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.quadBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{hoveredLineIndexUniforms:this.hoveredLineIndexUniformStore.getManagedUniformBuffer(e,"hoveredLineIndexUniforms")}})),this.fillSampledLinksUniformStore||(this.fillSampledLinksUniformStore=new _e({fillSampledLinksUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>",curvedWeight:"f32",curvedLinkControlPointDistance:"f32",curvedLinkSegments:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),curvedWeight:t.curvedLinkWeight,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments:1}}})),this.fillSampledLinksFboCommand||(this.fillSampledLinksFboCommand=new pe(e,{fs:ov,vs:av,modules:[Su],topology:"point-list",vertexCount:r.linksNumber??0,attributes:{...this.pointABuffer&&{pointA:this.pointABuffer},...this.pointBBuffer&&{pointB:this.pointBBuffer},...this.linkIndexBuffer&&{linkIndices:this.linkIndexBuffer}},bufferLayout:[{name:"pointA",format:"float32x2"},{name:"pointB",format:"float32x2"},{name:"linkIndices",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledLinksUniforms:this.fillSampledLinksUniformStore.getManagedUniformBuffer(e,"fillSampledLinksUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.updateSampledLinksGrid()}draw(e){const{config:t,points:i,store:r}=this;i&&(!i.currentPositionTexture||i.currentPositionTexture.destroyed||!i.greyoutStatusTexture||i.greyoutStatusTexture.destroyed||((!this.pointABuffer||!this.pointBBuffer)&&this.updatePointsBuffer(),this.colorBuffer||this.updateColor(),this.widthBuffer||this.updateWidth(),this.arrowBuffer||this.updateArrow(),this.curveLineGeometry||this.updateCurveLineGeometry(),!(!this.drawCurveCommand||!this.drawLineUniformStore)&&(this.drawLineUniformStore.setUniforms({drawLineUniforms:{transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize,widthScale:t.linkWidthScale,linkArrowsSizeScale:t.linkArrowsSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),linkVisibilityDistanceRange:ne(t.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:t.linkVisibilityMinTransparency,linkOpacity:t.linkOpacity,greyoutOpacity:t.linkGreyoutOpacity,curvedWeight:t.curvedLinkWeight,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments:1,scaleLinksOnZoom:t.scaleLinksOnZoom?1:0,maxPointSize:r.maxPointSize,renderMode:0,hoveredLinkIndex:r.hoveredLinkIndex??-1,hoveredLinkColor:Re(r.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease},drawLineFragmentUniforms:{renderMode:0}}),this.drawCurveCommand.setBindings({positionsTexture:i.currentPositionTexture,pointGreyoutStatus:i.greyoutStatusTexture}),this.drawCurveCommand.setInstanceCount(this.data.linksNumber??0),this.drawCurveCommand.draw(e))))}updateLinkIndexFbo(){var a,l;const{device:e,store:t}=this;if(!this.store.isLinkHoveringEnabled)return;const i=t.screenSize??[0,0],r=i[0],s=i[1];if(!r||!s)return;const o=((a=this.previousScreenSize)==null?void 0:a[0])!==r||((l=this.previousScreenSize)==null?void 0:l[1])!==s;(!this.linkIndexTexture||o)&&(this.linkIndexFbo&&!this.linkIndexFbo.destroyed&&this.linkIndexFbo.destroy(),this.linkIndexTexture&&!this.linkIndexTexture.destroyed&&this.linkIndexTexture.destroy(),this.linkIndexTexture=e.createTexture({width:r,height:s,format:"rgba32float",usage:Q.SAMPLE|Q.RENDER|Q.COPY_DST}),this.linkIndexTexture.copyImageData({data:new Float32Array(r*s*4).fill(0),bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),this.linkIndexFbo=e.createFramebuffer({width:r,height:s,colorAttachments:[this.linkIndexTexture]}),this.previousScreenSize=[r,s])}updateSampledLinksGrid(){const{store:{screenSize:e},config:{linkSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=wt.linkSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);s===0||o===0||(!this.sampledLinksFbo||this.sampledLinksFbo.width!==s||this.sampledLinksFbo.height!==o)&&(this.sampledLinksFbo&&!this.sampledLinksFbo.destroyed&&this.sampledLinksFbo.destroy(),this.sampledLinksFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}updatePointsBuffer(){var l;const{device:e,data:t,store:i}=this;if(t.linksNumber===void 0||t.links===void 0||!i.pointsTextureSize)return;const r=new Float32Array(t.linksNumber*2),s=new Float32Array(t.linksNumber*2);for(let c=0;c<t.linksNumber;c++){const u=t.links[c*2],f=t.links[c*2+1],h=u%i.pointsTextureSize,d=Math.floor(u/i.pointsTextureSize),_=f%i.pointsTextureSize,I=Math.floor(f/i.pointsTextureSize);r[c*2]=h,r[c*2+1]=d,s[c*2]=_,s[c*2+1]=I}const o=(((l=this.pointABuffer)==null?void 0:l.byteLength)??0)/(Float32Array.BYTES_PER_ELEMENT*2);!this.pointABuffer||o!==t.linksNumber?(this.pointABuffer&&!this.pointABuffer.destroyed&&this.pointABuffer.destroy(),this.pointABuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.pointABuffer.write(r),!this.pointBBuffer||o!==t.linksNumber?(this.pointBBuffer&&!this.pointBBuffer.destroyed&&this.pointBBuffer.destroy(),this.pointBBuffer=e.createBuffer({data:s,usage:L.VERTEX|L.COPY_DST})):this.pointBBuffer.write(s);const a=new Float32Array(t.linksNumber);for(let c=0;c<t.linksNumber;c++)a[c]=c;!this.linkIndexBuffer||o!==t.linksNumber?(this.linkIndexBuffer&&!this.linkIndexBuffer.destroyed&&this.linkIndexBuffer.destroy(),this.linkIndexBuffer=e.createBuffer({data:a,usage:L.VERTEX|L.COPY_DST})):this.linkIndexBuffer.write(a),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({pointA:this.pointABuffer,pointB:this.pointBBuffer,linkIndices:this.linkIndexBuffer}),this.fillSampledLinksFboCommand&&this.fillSampledLinksFboCommand.setAttributes({pointA:this.pointABuffer,pointB:this.pointBBuffer,linkIndices:this.linkIndexBuffer}),this.updateSampledLinksGrid()}updateColor(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkColors??new Float32Array(i*4).fill(0);this.colorBuffer?(this.colorBuffer.byteLength??0)/(Float32Array.BYTES_PER_ELEMENT*4)!==i?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r):this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({color:this.colorBuffer})}updateWidth(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkWidths??new Float32Array(i).fill(0);this.widthBuffer?(this.widthBuffer.byteLength??0)/Float32Array.BYTES_PER_ELEMENT!==i?(this.widthBuffer&&!this.widthBuffer.destroyed&&this.widthBuffer.destroy(),this.widthBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.widthBuffer.write(r):this.widthBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({width:this.widthBuffer})}updateArrow(){const{device:e,data:t}=this,i=t.linksNumber??0,r=t.linkArrows?new Float32Array(t.linkArrows):new Float32Array(i).fill(0);this.arrowBuffer?(this.arrowBuffer.byteLength??0)/Float32Array.BYTES_PER_ELEMENT!==i?(this.arrowBuffer&&!this.arrowBuffer.destroyed&&this.arrowBuffer.destroy(),this.arrowBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.arrowBuffer.write(r):this.arrowBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({arrow:this.arrowBuffer})}updateCurveLineGeometry(){const{device:e,config:{curvedLinks:t,curvedLinkSegments:i}}=this;this.curveLineGeometry=uv(t?i:1);const r=new Float32Array(this.curveLineGeometry.length*2);for(let s=0;s<this.curveLineGeometry.length;s++)r[s*2]=this.curveLineGeometry[s][0],r[s*2+1]=this.curveLineGeometry[s][1];!this.curveLineBuffer||this.curveLineBuffer.byteLength!==r.byteLength?(this.curveLineBuffer&&!this.curveLineBuffer.destroyed&&this.curveLineBuffer.destroy(),this.curveLineBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.curveLineBuffer.write(r),this.drawCurveCommand&&(this.drawCurveCommand.setAttributes({position:this.curveLineBuffer}),this.drawCurveCommand.setVertexCount(this.curveLineGeometry.length))}getSampledLinkPositionsMap(){const e=new Map;if(!this.sampledLinksFbo||this.sampledLinksFbo.destroyed)return e;const t=this.points;if(!(t!=null&&t.currentPositionTexture)||t.currentPositionTexture.destroyed)return e;if(this.fillSampledLinksFboCommand&&this.fillSampledLinksUniformStore&&this.sampledLinksFbo){this.fillSampledLinksFboCommand.setVertexCount(this.data.linksNumber??0),this.fillSampledLinksUniformStore.setUniforms({fillSampledLinksUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),curvedWeight:this.config.curvedLinkWeight,curvedLinkControlPointDistance:this.config.curvedLinkControlPointDistance,curvedLinkSegments:this.config.curvedLinks?this.config.curvedLinkSegments:1}}),this.fillSampledLinksFboCommand.setBindings({positionsTexture:t.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledLinksFbo,clearColor:[-1,-1,-1,-1]});this.fillSampledLinksFboCommand.draw(r),r.end()}const i=Me(this.device,this.sampledLinksFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=i[r*4+1],a=i[r*4+2],l=i[r*4+3];s!==void 0&&s>=0&&o!==void 0&&a!==void 0&&l!==void 0&&e.set(Math.round(s),[o,a,l])}return e}getSampledLinks(){const e=[],t=[],i=[];if(!this.sampledLinksFbo||this.sampledLinksFbo.destroyed)return{indices:e,positions:t,angles:i};const r=this.points;if(!(r!=null&&r.currentPositionTexture)||r.currentPositionTexture.destroyed)return{indices:e,positions:t,angles:i};if(this.fillSampledLinksFboCommand&&this.fillSampledLinksUniformStore&&this.sampledLinksFbo){this.fillSampledLinksFboCommand.setVertexCount(this.data.linksNumber??0),this.fillSampledLinksUniformStore.setUniforms({fillSampledLinksUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),curvedWeight:this.config.curvedLinkWeight,curvedLinkControlPointDistance:this.config.curvedLinkControlPointDistance,curvedLinkSegments:this.config.curvedLinks?this.config.curvedLinkSegments:1}}),this.fillSampledLinksFboCommand.setBindings({positionsTexture:r.currentPositionTexture});const o=this.device.beginRenderPass({framebuffer:this.sampledLinksFbo,clearColor:[-1,-1,-1,-1]});this.fillSampledLinksFboCommand.draw(o),o.end()}const s=Me(this.device,this.sampledLinksFbo);for(let o=0;o<s.length/4;o++){const a=s[o*4],l=s[o*4+1],c=s[o*4+2],u=s[o*4+3];a!==void 0&&a>=0&&l!==void 0&&c!==void 0&&u!==void 0&&(e.push(Math.round(a)),t.push(l,c),i.push(u))}return{indices:e,positions:t,angles:i}}findHoveredLine(){const{config:e,points:t,store:i}=this;if(!t||!t.currentPositionTexture||t.currentPositionTexture.destroyed||!t.greyoutStatusTexture||t.greyoutStatusTexture.destroyed||!this.data.linksNumber||!this.store.isLinkHoveringEnabled||!this.linkIndexFbo||!this.drawCurveCommand||!this.drawLineUniformStore||!this.linkIndexTexture||this.linkIndexTexture.destroyed)return;this.drawLineUniformStore.setUniforms({drawLineUniforms:{transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize,widthScale:e.linkWidthScale,linkArrowsSizeScale:e.linkArrowsSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),linkVisibilityDistanceRange:ne(e.linkVisibilityDistanceRange,[0,0]),linkVisibilityMinTransparency:e.linkVisibilityMinTransparency,linkOpacity:e.linkOpacity,greyoutOpacity:e.linkGreyoutOpacity,curvedWeight:e.curvedLinkWeight,curvedLinkControlPointDistance:e.curvedLinkControlPointDistance,curvedLinkSegments:e.curvedLinks?e.curvedLinkSegments:1,scaleLinksOnZoom:e.scaleLinksOnZoom?1:0,maxPointSize:i.maxPointSize,renderMode:1,hoveredLinkIndex:i.hoveredLinkIndex??-1,hoveredLinkColor:Re(i.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:e.hoveredLinkWidthIncrease},drawLineFragmentUniforms:{renderMode:1}}),this.drawCurveCommand.setBindings({positionsTexture:t.currentPositionTexture,pointGreyoutStatus:t.greyoutStatusTexture}),this.drawCurveCommand.setInstanceCount(this.data.linksNumber??0);const r=this.device.beginRenderPass({framebuffer:this.linkIndexFbo,clearColor:[0,0,0,0]});if(this.drawCurveCommand.draw(r),r.end(),this.hoveredLineIndexCommand&&this.hoveredLineIndexFbo&&this.hoveredLineIndexUniformStore){this.hoveredLineIndexUniformStore.setUniforms({hoveredLineIndexUniforms:{mousePosition:ne(i.screenMousePosition,[0,0]),screenSize:ne(i.screenSize,[0,0])}}),this.hoveredLineIndexCommand.setBindings({linkIndexTexture:this.linkIndexTexture});const s=this.device.beginRenderPass({framebuffer:this.hoveredLineIndexFbo});this.hoveredLineIndexCommand.draw(s),s.end()}}destroy(){var e,t,i,r,s,o;(e=this.drawCurveCommand)==null||e.destroy(),this.drawCurveCommand=void 0,(t=this.hoveredLineIndexCommand)==null||t.destroy(),this.hoveredLineIndexCommand=void 0,(i=this.fillSampledLinksFboCommand)==null||i.destroy(),this.fillSampledLinksFboCommand=void 0,this.linkIndexFbo&&!this.linkIndexFbo.destroyed&&this.linkIndexFbo.destroy(),this.linkIndexFbo=void 0,this.sampledLinksFbo&&!this.sampledLinksFbo.destroyed&&this.sampledLinksFbo.destroy(),this.sampledLinksFbo=void 0,this.hoveredLineIndexFbo&&!this.hoveredLineIndexFbo.destroyed&&this.hoveredLineIndexFbo.destroy(),this.hoveredLineIndexFbo=void 0,this.linkIndexTexture&&!this.linkIndexTexture.destroyed&&this.linkIndexTexture.destroy(),this.linkIndexTexture=void 0,this.hoveredLineIndexTexture&&!this.hoveredLineIndexTexture.destroyed&&this.hoveredLineIndexTexture.destroy(),this.hoveredLineIndexTexture=void 0,(r=this.drawLineUniformStore)==null||r.destroy(),this.drawLineUniformStore=void 0,(s=this.hoveredLineIndexUniformStore)==null||s.destroy(),this.hoveredLineIndexUniformStore=void 0,(o=this.fillSampledLinksUniformStore)==null||o.destroy(),this.fillSampledLinksUniformStore=void 0,this.pointABuffer&&!this.pointABuffer.destroyed&&this.pointABuffer.destroy(),this.pointABuffer=void 0,this.pointBBuffer&&!this.pointBBuffer.destroyed&&this.pointBBuffer.destroy(),this.pointBBuffer=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.widthBuffer&&!this.widthBuffer.destroyed&&this.widthBuffer.destroy(),this.widthBuffer=void 0,this.arrowBuffer&&!this.arrowBuffer.destroyed&&this.arrowBuffer.destroy(),this.arrowBuffer=void 0,this.curveLineBuffer&&!this.curveLineBuffer.destroyed&&this.curveLineBuffer.destroy(),this.curveLineBuffer=void 0,this.linkIndexBuffer&&!this.linkIndexBuffer.destroyed&&this.linkIndexBuffer.destroy(),this.linkIndexBuffer=void 0,this.quadBuffer&&!this.quadBuffer.destroyed&&this.quadBuffer.destroy(),this.quadBuffer=void 0}}const hv=`#version 300 es
1258
1258
  #ifdef GL_ES
1259
1259
  precision highp float;
1260
1260
  #endif
@@ -1513,7 +1513,7 @@ void main() {
1513
1513
  finalPointAlpha
1514
1514
  );
1515
1515
  }
1516
- `,vv=`#version 300 es
1516
+ `,dv=`#version 300 es
1517
1517
  #ifdef GL_ES
1518
1518
  precision highp float;
1519
1519
  #endif
@@ -1715,7 +1715,7 @@ void main() {
1715
1715
  imageAtlasUV = atlasCoords;
1716
1716
  }
1717
1717
  #endif
1718
- } `,bv=`#version 300 es
1718
+ } `,pv=`#version 300 es
1719
1719
  #ifdef GL_ES
1720
1720
  precision highp float;
1721
1721
  #endif
@@ -1803,7 +1803,7 @@ void main() {
1803
1803
  }
1804
1804
  }
1805
1805
 
1806
- `,Sv=`#version 300 es
1806
+ `,mv=`#version 300 es
1807
1807
  #ifdef GL_ES
1808
1808
  precision highp float;
1809
1809
  #endif
@@ -1891,7 +1891,7 @@ void main() {
1891
1891
  if (pointInPolygon(screenPos, polygonPathTexture, polygonPathLength)) {
1892
1892
  fragColor.r = 1.0;
1893
1893
  }
1894
- } `,Tv=`#version 300 es
1894
+ } `,gv=`#version 300 es
1895
1895
  #ifdef GL_ES
1896
1896
  precision highp float;
1897
1897
  #endif
@@ -1934,7 +1934,7 @@ void main () {
1934
1934
  float opacity = smoothstep(r, r * smoothing, 1.0);
1935
1935
  float stroke = smoothstep(width, width * smoothing, r);
1936
1936
  fragColor = vec4(rgbColor, opacity * stroke * pointOpacity);
1937
- }`,wv=`#version 300 es
1937
+ }`,_v=`#version 300 es
1938
1938
  #ifdef GL_ES
1939
1939
  precision highp float;
1940
1940
  #endif
@@ -2078,7 +2078,7 @@ void main () {
2078
2078
  #endif
2079
2079
 
2080
2080
  gl_Position = vec4(final.rg, 0, 1);
2081
- }`,Av=`#version 300 es
2081
+ }`,xv=`#version 300 es
2082
2082
  #ifdef GL_ES
2083
2083
  precision highp float;
2084
2084
  #endif
@@ -2092,13 +2092,14 @@ void main() {
2092
2092
  discard;
2093
2093
  }
2094
2094
  fragColor = rgba;
2095
- }`,Cv=`#version 300 es
2095
+ }`,yv=`#version 300 es
2096
2096
  #ifdef GL_ES
2097
2097
  precision highp float;
2098
2098
  #endif
2099
2099
 
2100
2100
  in vec2 pointIndices;
2101
2101
  in float size;
2102
+ in float imageSize;
2102
2103
 
2103
2104
  uniform sampler2D positionsTexture;
2104
2105
  uniform sampler2D pointGreyoutStatus;
@@ -2191,7 +2192,9 @@ void main() {
2191
2192
  vec3 finalPosition = transformationMatrix * vec3(normalizedPosition, 1);
2192
2193
  #endif
2193
2194
 
2194
- float pointRadius = 0.5 * calculatePointSize(size * sizeScale);
2195
+ float shapeSizeValue = calculatePointSize(size * sizeScale);
2196
+ float imageSizeValue = calculatePointSize(imageSize * sizeScale);
2197
+ float pointRadius = 0.5 * max(shapeSizeValue, imageSizeValue);
2195
2198
  vec2 pointScreenPosition = (finalPosition.xy + 1.0) * screenSize / 2.0;
2196
2199
 
2197
2200
  rgba = vec4(0.0);
@@ -2199,12 +2202,12 @@ void main() {
2199
2202
 
2200
2203
  if (euclideanDistance(pointScreenPosition.x, mousePosition.x, pointScreenPosition.y, mousePosition.y) < pointRadius / ratio) {
2201
2204
  float index = pointIndices.g * pointsTextureSize + pointIndices.r;
2202
- rgba = vec4(index, size, pointPosition.xy);
2205
+ rgba = vec4(index, max(size, imageSize), pointPosition.xy);
2203
2206
  gl_Position = vec4(-0.5, -0.5, 0.0, 1.0);
2204
2207
  }
2205
2208
 
2206
2209
  gl_PointSize = 1.0;
2207
- }`,Iv=`#version 300 es
2210
+ }`,vv=`#version 300 es
2208
2211
  #ifdef GL_ES
2209
2212
  precision highp float;
2210
2213
  #endif
@@ -2215,7 +2218,7 @@ out vec4 fragColor;
2215
2218
 
2216
2219
  void main() {
2217
2220
  fragColor = rgba;
2218
- }`,Pv=`#version 300 es
2221
+ }`,bv=`#version 300 es
2219
2222
  #ifdef GL_ES
2220
2223
  precision highp float;
2221
2224
  #endif
@@ -2265,7 +2268,7 @@ void main() {
2265
2268
  gl_Position = vec4(2.0 * vec2(i, j) - 1.0, 0.0, 1.0);
2266
2269
 
2267
2270
  gl_PointSize = 1.0;
2268
- }`,Ev=`#version 300 es
2271
+ }`,Sv=`#version 300 es
2269
2272
  #ifdef GL_ES
2270
2273
  precision highp float;
2271
2274
  #endif
@@ -2315,7 +2318,7 @@ void main() {
2315
2318
  pointPosition.g = clamp(pointPosition.g, 0.0, spaceSize);
2316
2319
 
2317
2320
  fragColor = pointPosition;
2318
- }`,Rv=`#version 300 es
2321
+ }`,Tv=`#version 300 es
2319
2322
  #ifdef GL_ES
2320
2323
  precision highp float;
2321
2324
  #endif
@@ -2345,7 +2348,7 @@ void main() {
2345
2348
  fragColor = vec4(pointPosition.rg, 1.0, 1.0);
2346
2349
  }
2347
2350
 
2348
- `,kv=`#version 300 es
2351
+ `,wv=`#version 300 es
2349
2352
  #ifdef GL_ES
2350
2353
  precision highp float;
2351
2354
  #endif
@@ -2378,7 +2381,7 @@ void main() {
2378
2381
  }
2379
2382
 
2380
2383
  fragColor = pointPosition;
2381
- }`;function Dv(n,e=16384){if(!(n!=null&&n.length))return null;let t=0;for(const c of n){const u=Math.max(c.width,c.height);u>t&&(t=u)}if(t===0)return console.warn("Invalid image dimensions: all images have zero width or height"),null;const i=t,r=Math.ceil(Math.sqrt(n.length));let s=r*t,o=1;s>e&&(o=e/s,t=Math.max(1,Math.floor(t*o)),s=Math.max(1,Math.floor(s*o)),console.warn(`🖼️ Atlas scaling required: Original size ${(i*r).toLocaleString()}px exceeds WebGL limit ${e.toLocaleString()}px. Scaling down to ${s.toLocaleString()}px (${Math.round(o*100)}% of original quality)`));const a=new Uint8Array(s*s*4).fill(0),l=new Float32Array(r*r*4).fill(-1);for(const[c,u]of n.entries()){const f=u.width,h=u.height;if(f===0||h===0)continue;const d=Math.min(1,t/Math.max(f,h)),_=Math.floor(f*d),I=Math.floor(h*d),P=Math.floor(c/r),O=c%r*t,E=P*t;l[c*4]=O/s,l[c*4+1]=E/s,l[c*4+2]=(O+_)/s,l[c*4+3]=(E+I)/s;for(let x=0;x<I;x++)for(let R=0;R<_;R++){const N=Math.floor(R*(f/_)),W=(Math.floor(x*(h/I))*f+N)*4,q=((E+x)*s+(O+R))*4;a[q]=u.data[W]??0,a[q+1]=u.data[W+1]??0,a[q+2]=u.data[W+2]??0,a[q+3]=u.data[W+3]??255}}return{atlasData:a,atlasSize:s,atlasCoords:l,atlasCoordsSize:r}}class Mv extends Nt{constructor(){super(...arguments),this.imageCount=0,this.isPositionsUpToDate=!1,this.polygonPathLength=0}updatePositions(){const{device:e,store:t,data:i,config:{rescalePositions:r,enableSimulation:s}}=this,{pointsTextureSize:o}=t;if(!o||!i.pointPositions||i.pointsNumber===void 0)return;const a=o*o*4,l=new Float32Array(a),c=o*o*4*4,u=l.byteLength;u!==c&&console.error("Texture data size mismatch:",{pointsTextureSize:o,expectedBytes:c,actualBytes:u,textureDataSize:a,dataLength:l.length});let f=r;r===void 0&&!s&&(f=!0),this.shouldSkipRescale&&(f=!1),f?this.rescaleInitialNodePositions():this.shouldSkipRescale||(this.scaleX=void 0,this.scaleY=void 0),this.shouldSkipRescale=void 0;for(let _=0;_<i.pointsNumber;++_)l[_*4+0]=i.pointPositions[_*2+0],l[_*4+1]=i.pointPositions[_*2+1],l[_*4+2]=_;if(!this.currentPositionTexture||this.currentPositionTexture.width!==o||this.currentPositionTexture.height!==o?(this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.currentPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.currentPositionTexture]})):this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),!this.previousPositionTexture||this.previousPositionTexture.width!==o||this.previousPositionTexture.height!==o?(this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.previousPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.previousPositionTexture]})):this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.config.enableSimulation){const _=new Float32Array(o*o*4).fill(0);!this.velocityTexture||this.velocityTexture.width!==o||this.velocityTexture.height!==o?(this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.velocityTexture.copyImageData({data:_,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.velocityFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.velocityTexture]})):this.velocityTexture.copyImageData({data:_,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0})}!this.selectedTexture||this.selectedTexture.width!==o||this.selectedTexture.height!==o?(this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.selectedTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.selectedFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.selectedTexture]})):this.selectedTexture.copyImageData({data:l,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.hoveredFbo||(this.hoveredFbo=e.createFramebuffer({width:2,height:2,colorAttachments:["rgba32float"]}));const h=yr(t.pointsTextureSize),d=h.byteLength;!this.drawPointIndices||this.drawPointIndices.byteLength!==d?(this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.drawPointIndices.write(h),this.drawCommand&&this.drawCommand.setAttributes({pointIndices:this.drawPointIndices}),!this.hoveredPointIndices||this.hoveredPointIndices.byteLength!==d?(this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.hoveredPointIndices.write(h),!this.sampledPointIndices||this.sampledPointIndices.byteLength!==d?(this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.sampledPointIndices.write(h),this.fillSampledPointsFboCommand&&this.fillSampledPointsFboCommand.setAttributes({pointIndices:this.sampledPointIndices}),this.updateGreyoutStatus(),this.updatePinnedStatus(),this.updateSampledPointsGrid(),this.trackPointsByIndices()}initPrograms(){var s,o,a;const{device:e,config:t,store:i,data:r}=this;(!this.imageAtlasCoordsTexture||!this.imageAtlasTexture)&&this.createAtlas(),this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),this.greyoutStatusTexture||this.updateGreyoutStatus(),t.enableSimulation&&(this.updatePositionVertexCoordBuffer||(this.updatePositionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.updatePositionUniformStore||(this.updatePositionUniformStore=new xe({updatePositionUniforms:{uniformTypes:{friction:"f32",spaceSize:"f32"},defaultUniforms:{friction:t.simulationFriction??0,spaceSize:i.adjustedSpaceSize??0}}})),this.updatePositionCommand||(this.updatePositionCommand=new me(e,{fs:Ev,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.updatePositionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{updatePositionUniforms:this.updatePositionUniformStore.getManagedUniformBuffer(e,"updatePositionUniforms")}}))),this.dragPointVertexCoordBuffer||(this.dragPointVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.dragPointUniformStore||(this.dragPointUniformStore=new xe({dragPointUniforms:{uniformTypes:{mousePos:"vec2<f32>",index:"f32"},defaultUniforms:{mousePos:re(i.mousePosition,[0,0]),index:((s=i.hoveredPoint)==null?void 0:s.index)??-1}}})),this.dragPointCommand||(this.dragPointCommand=new me(e,{fs:kv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.dragPointVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{dragPointUniforms:this.dragPointUniformStore.getManagedUniformBuffer(e,"dragPointUniforms")}})),this.drawUniformStore||(this.drawUniformStore=new xe({drawVertexUniforms:{uniformTypes:{ratio:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",greyoutColor:"vec4<f32>",backgroundColor:"vec4<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",isDarkenGreyout:"f32",skipSelected:"f32",skipUnselected:"f32",hasImages:"f32",imageCount:"f32",imageAtlasCoordsTextureSize:"f32"},defaultUniforms:{ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:(()=>{const l=i.transform??[1,0,0,0,1,0,0,0,1];return[l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]})(),pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),backgroundColor:Re(i.backgroundColor,[0,0,0,1]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,skipSelected:0,skipUnselected:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0}},drawFragmentUniforms:{uniformTypes:{greyoutOpacity:"f32",pointOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>"},defaultUniforms:{greyoutOpacity:t.pointGreyoutOpacity??-1,pointOpacity:t.pointOpacity??1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1])}}})),this.drawCommand||(this.drawCommand=new me(e,{fs:yv,vs:vv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.drawPointIndices&&{pointIndices:this.drawPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.shapeBuffer&&{shape:this.shapeBuffer},...this.imageIndicesBuffer&&{imageIndex:this.imageIndicesBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"},{name:"color",format:"float32x4"},{name:"shape",format:"float32"},{name:"imageIndex",format:"float32"},{name:"imageSize",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawVertexUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawVertexUniforms"),drawFragmentUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawFragmentUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.findPointsOnAreaSelectionVertexCoordBuffer||(this.findPointsOnAreaSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnAreaSelectionUniformStore||(this.findPointsOnAreaSelectionUniformStore=new xe({findPointsOnAreaSelectionUniforms:{uniformTypes:{sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",selection0:"vec2<f32>",selection1:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32"},defaultUniforms:{sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,selection0:re((o=i.selectedArea)==null?void 0:o[0],[0,0]),selection1:re((a=i.selectedArea)==null?void 0:a[1],[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100}}})),this.findPointsOnAreaSelectionCommand||(this.findPointsOnAreaSelectionCommand=new me(e,{fs:bv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnAreaSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnAreaSelectionUniforms:this.findPointsOnAreaSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnAreaSelectionUniforms")}})),this.findPointsOnPolygonSelectionVertexCoordBuffer||(this.findPointsOnPolygonSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnPolygonSelectionUniformStore||(this.findPointsOnPolygonSelectionUniformStore=new xe({findPointsOnPolygonSelectionUniforms:{uniformTypes:{spaceSize:"f32",screenSize:"vec2<f32>",transformationMatrix:"mat4x4<f32>",polygonPathLength:"f32"},defaultUniforms:{spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),transformationMatrix:i.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}})),this.findPointsOnPolygonSelectionCommand||(this.findPointsOnPolygonSelectionCommand=new me(e,{fs:Sv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnPolygonSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnPolygonSelectionUniforms:this.findPointsOnPolygonSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnPolygonSelectionUniforms")}})),this.findHoveredPointUniformStore||(this.findHoveredPointUniformStore=new xe({findHoveredPointUniforms:{uniformTypes:{pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",mousePosition:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",skipSelected:"f32",skipUnselected:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,mousePosition:re(i.screenMousePosition,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,skipSelected:0,skipUnselected:0}}})),this.findHoveredPointCommand||(this.findHoveredPointCommand=new me(e,{fs:Av,vs:Cv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findHoveredPointUniforms:this.findHoveredPointUniformStore.getManagedUniformBuffer(e,"findHoveredPointUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.fillSampledPointsUniformStore||(this.fillSampledPointsUniformStore=new xe({fillSampledPointsUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0])}}})),this.fillSampledPointsFboCommand||(this.fillSampledPointsFboCommand=new me(e,{fs:Iv,vs:Pv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.sampledPointIndices&&{pointIndices:this.sampledPointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledPointsUniforms:this.fillSampledPointsUniformStore.getManagedUniformBuffer(e,"fillSampledPointsUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})),this.drawHighlightedVertexCoordBuffer||(this.drawHighlightedVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.drawHighlightedUniformStore||(this.drawHighlightedUniformStore=new xe({drawHighlightedUniforms:{uniformTypes:{size:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",scalePointsOnZoom:"f32",pointIndex:"f32",maxPointSize:"f32",color:"vec4<f32>",universalPointOpacity:"f32",greyoutOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>",greyoutColor:"vec4<f32>",width:"f32"},defaultUniforms:{size:1,transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,pointIndex:-1,maxPointSize:i.maxPointSize??100,color:[0,0,0,1],universalPointOpacity:t.pointOpacity??1,greyoutOpacity:t.pointGreyoutOpacity??-1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),width:.85}}})),this.drawHighlightedCommand||(this.drawHighlightedCommand=new me(e,{fs:Tv,vs:wv,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.drawHighlightedVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawHighlightedUniforms:this.drawHighlightedUniformStore.getManagedUniformBuffer(e,"drawHighlightedUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.trackPointsVertexCoordBuffer||(this.trackPointsVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.trackPointsUniformStore||(this.trackPointsUniformStore=new xe({trackPointsUniforms:{uniformTypes:{pointsTextureSize:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0}}})),this.trackPointsCommand||(this.trackPointsCommand=new me(e,{fs:Rv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.trackPointsVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{trackPointsUniforms:this.trackPointsUniformStore.getManagedUniformBuffer(e,"trackPointsUniforms")}}))}updateColor(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=i.pointColors,s=r.byteLength;!this.colorBuffer||this.colorBuffer.byteLength!==s?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({color:this.colorBuffer})}updateGreyoutStatus(){const{device:e,store:{selectedIndices:t,pointsTextureSize:i}}=this;if(!i)return;const r=new Float32Array(i*i*4).fill(t?1:0);if(t)for(const s of t)r[s*4]=0;!this.greyoutStatusTexture||this.greyoutStatusTexture.width!==i||this.greyoutStatusTexture.height!==i?(this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=e.createTexture({width:i,height:i,format:"rgba32float"}),this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",i),mipLevel:0,x:0,y:0})):this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",i),mipLevel:0,x:0,y:0})}updatePinnedStatus(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=new Float32Array(t*t*4).fill(0);if(i.inputPinnedPoints&&i.pointsNumber!==void 0)for(const s of i.inputPinnedPoints)s>=0&&s<i.pointsNumber&&(r[s*4]=1);!this.pinnedStatusTexture||this.pinnedStatusTexture.width!==t||this.pinnedStatusTexture.height!==t?(this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0})):this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0})}updateSize(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t||i.pointsNumber===void 0||i.pointSizes===void 0)return;const r=i.pointSizes,s=r.byteLength;!this.sizeBuffer||this.sizeBuffer.byteLength!==s?(this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.sizeBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({size:this.sizeBuffer});const o=new Float32Array(t*t*4);for(let a=0;a<i.pointsNumber;a++)o[a*4]=i.pointSizes[a];!this.sizeTexture||this.sizeTexture.width!==t||this.sizeTexture.height!==t?(this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.sizeTexture.copyImageData({data:o,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0})):this.sizeTexture.copyImageData({data:o,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0})}updateShape(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointShapes===void 0)return;const i=t.pointShapes,r=i.byteLength;!this.shapeBuffer||this.shapeBuffer.byteLength!==r?(this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.shapeBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({shape:this.shapeBuffer})}updateImageIndices(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageIndices===void 0)return;const i=t.pointImageIndices,r=i.byteLength;!this.imageIndicesBuffer||this.imageIndicesBuffer.byteLength!==r?(this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageIndicesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageIndex:this.imageIndicesBuffer})}updateImageSizes(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageSizes===void 0)return;const i=t.pointImageSizes,r=i.byteLength;!this.imageSizesBuffer||this.imageSizesBuffer.byteLength!==r?(this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageSizesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageSize:this.imageSizesBuffer})}createAtlas(){var c;const{device:e,data:t,store:i}=this;if(!((c=t.inputImageData)!=null&&c.length)){this.imageCount=0,this.imageAtlasCoordsTextureSize=0,this.imageAtlasCoordsTexture||(this.imageAtlasCoordsTexture=e.createTexture({data:new Float32Array(4).fill(0),width:1,height:1,format:"rgba32float"})),this.imageAtlasTexture||(this.imageAtlasTexture=e.createTexture({data:new Uint8Array(4).fill(0),width:1,height:1,format:"rgba8unorm"}));return}const r=Dv(t.inputImageData,i.webglMaxTextureSize);if(!r){console.warn("Failed to create atlas from image data");return}this.imageCount=t.inputImageData.length;const{atlasData:s,atlasSize:o,atlasCoords:a,atlasCoordsSize:l}=r;this.imageAtlasCoordsTextureSize=l,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=e.createTexture({width:o,height:o,format:"rgba8unorm"}),this.imageAtlasTexture.copyImageData({data:s,bytesPerRow:ie("rgba8unorm",o),rowsPerImage:o,mipLevel:0,x:0,y:0}),this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=e.createTexture({width:l,height:l,format:"rgba32float"}),this.imageAtlasCoordsTexture.copyImageData({data:a,bytesPerRow:ie("rgba32float",l),rowsPerImage:l,mipLevel:0,x:0,y:0})}updateSampledPointsGrid(){const{store:{screenSize:e},config:{pointSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=V.pointSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);s===0||o===0||(!this.sampledPointsFbo||this.sampledPointsFbo.width!==s||this.sampledPointsFbo.height!==o)&&(this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}trackPoints(){var t;if(!((t=this.trackedIndices)!=null&&t.length)||!this.trackPointsCommand||!this.trackPointsUniformStore||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.trackedIndicesTexture||this.trackedIndicesTexture.destroyed)return;this.trackPointsUniformStore.setUniforms({trackPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0}}),this.trackPointsCommand.setBindings({positionsTexture:this.currentPositionTexture,trackedIndices:this.trackedIndicesTexture});const e=this.device.beginRenderPass({framebuffer:this.trackedPositionsFbo});this.trackPointsCommand.draw(e),e.end()}draw(e){var a,l;const{data:t,config:i,store:r}=this;if(this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),!this.drawCommand||!this.drawUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed||(!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)&&(this.createAtlas(),!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)||this.imageAtlasTexture.destroyed||this.imageAtlasCoordsTexture.destroyed||!t.pointsNumber||t.pointsNumber===0||!r.screenSize||r.screenSize[0]===0||r.screenSize[1]===0)return;this.drawCommand.setVertexCount(t.pointsNumber);const s={ratio:i.pixelRatio??V.pixelRatio,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),greyoutColor:Re(r.greyoutPointColor,[-1,-1,-1,-1]),backgroundColor:Re(r.backgroundColor,[0,0,0,1]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,maxPointSize:r.maxPointSize??100,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0},o={greyoutOpacity:i.pointGreyoutOpacity??-1,pointOpacity:i.pointOpacity??1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1])};if(r.selectedIndices&&r.selectedIndices.length>0?(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:1,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e),this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:1},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)):(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)),i.renderHoveredPointRing&&r.hoveredPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((a=t.pointSizes)==null?void 0:a[r.hoveredPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.hoveredPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.hoveredPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}if(r.focusedPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((l=t.pointSizes)==null?void 0:l[r.focusedPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.focusedPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.focusedPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}}updatePosition(){if(!this.updatePositionCommand||!this.updatePositionUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.velocityTexture||this.velocityTexture.destroyed||!this.pinnedStatusTexture||this.pinnedStatusTexture.destroyed)return;this.updatePositionUniformStore.setUniforms({updatePositionUniforms:{friction:this.config.simulationFriction??0,spaceSize:this.store.adjustedSpaceSize??0}}),this.updatePositionCommand.setBindings({positionsTexture:this.previousPositionTexture,velocity:this.velocityTexture,pinnedStatusTexture:this.pinnedStatusTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.updatePositionCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}drag(){var t;if(!this.dragPointCommand||!this.dragPointUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed)return;this.dragPointUniformStore.setUniforms({dragPointUniforms:{mousePos:re(this.store.mousePosition,[0,0]),index:((t=this.store.hoveredPoint)==null?void 0:t.index)??-1}}),this.dragPointCommand.setBindings({positionsTexture:this.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.dragPointCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}findPointsOnAreaSelection(){var t,i;if(!this.findPointsOnAreaSelectionCommand||!this.findPointsOnAreaSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.sizeTexture||this.sizeTexture.destroyed)return;this.findPointsOnAreaSelectionUniformStore.setUniforms({findPointsOnAreaSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),sizeScale:this.config.pointSizeScale??1,transformationMatrix:this.store.transformationMatrix4x4,ratio:this.config.pixelRatio??V.pixelRatio,selection0:re((t=this.store.selectedArea)==null?void 0:t[0],[0,0]),selection1:re((i=this.store.selectedArea)==null?void 0:i[1],[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,maxPointSize:this.store.maxPointSize??100}}),this.findPointsOnAreaSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,pointSize:this.sizeTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnAreaSelectionCommand.draw(e),e.end()}findPointsOnPolygonSelection(){if(!this.findPointsOnPolygonSelectionCommand||!this.findPointsOnPolygonSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.polygonPathTexture||this.polygonPathTexture.destroyed)return;this.findPointsOnPolygonSelectionUniformStore.setUniforms({findPointsOnPolygonSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),transformationMatrix:this.store.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}),this.findPointsOnPolygonSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,polygonPathTexture:this.polygonPathTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnPolygonSelectionCommand.draw(e),e.end()}updatePolygonPath(e){const{device:t}=this;if(this.polygonPathLength=e.length,e.length===0){this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0;return}const i=Math.ceil(Math.sqrt(e.length)),r=new Float32Array(i*i*4);for(const[s,o]of e.entries()){const[a,l]=o;r[s*4]=a,r[s*4+1]=l,r[s*4+2]=0,r[s*4+3]=0}!this.polygonPathTexture||this.polygonPathTexture.width!==i||this.polygonPathTexture.height!==i?(this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=t.createTexture({width:i,height:i,format:"rgba32float"}),this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",i),mipLevel:0,x:0,y:0})):this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",i),mipLevel:0,x:0,y:0})}findHoveredPoint(){if(!this.hoveredFbo||this.hoveredFbo.destroyed||!this.findHoveredPointCommand||!this.findHoveredPointUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||(this.greyoutStatusTexture||this.updateGreyoutStatus(),!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed))return;this.findHoveredPointCommand.setVertexCount(this.data.pointsNumber??0),this.findHoveredPointCommand.setAttributes({...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}});const e={ratio:this.config.pixelRatio??V.pixelRatio,sizeScale:this.config.pointSizeScale??1,pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,mousePosition:re(this.store.screenMousePosition,[0,0]),maxPointSize:this.store.maxPointSize??100},t={positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture},i=this.device.beginRenderPass({framebuffer:this.hoveredFbo,clearColor:[0,0,0,0]});this.store.selectedIndices&&this.store.selectedIndices.length>0?(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:1,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i),this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:1}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)):(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)),i.end()}trackPointsByIndices(e){const{store:{pointsTextureSize:t},device:i}=this;if(this.trackedIndices=e,this.trackedPositions=void 0,this.isPositionsUpToDate=!1,!(e!=null&&e.length)||!t)return;const r=Math.ceil(Math.sqrt(e.length)),s=new Float32Array(r*r*4).fill(-1);for(const[o,a]of e.entries())a!==void 0&&(s[o*4]=a%t,s[o*4+1]=Math.floor(a/t),s[o*4+2]=0,s[o*4+3]=0);!this.trackedIndicesTexture||this.trackedIndicesTexture.width!==r||this.trackedIndicesTexture.height!==r?(this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=i.createTexture({width:r,height:r,format:"rgba32float"}),this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0})):this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0}),(!this.trackedPositionsFbo||this.trackedPositionsFbo.width!==r||this.trackedPositionsFbo.height!==r)&&(this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=i.createFramebuffer({width:r,height:r,colorAttachments:["rgba32float"]})),this.trackPoints()}getTrackedPositionsMap(){if(!this.trackedIndices)return new Map;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this;if((!e||!t)&&this.isPositionsUpToDate&&this.trackedPositions)return this.trackedPositions;if(!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return new Map;const i=Me(this.device,this.trackedPositionsFbo),r=new Map;for(let s=0;s<i.length/4;s+=1){const o=i[s*4],a=i[s*4+1],l=this.trackedIndices[s];o!==void 0&&a!==void 0&&l!==void 0&&r.set(l,[o,a])}return(!e||!t)&&(this.trackedPositions=r,this.isPositionsUpToDate=!0),r}getSampledPointPositionsMap(){const e=new Map;if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return e;if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return e;this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const i=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(i),i.end()}const t=Me(this.device,this.sampledPointsFbo);for(let i=0;i<t.length/4;i++){const r=t[i*4],s=!!t[i*4+1],o=t[i*4+2],a=t[i*4+3];s&&r!==void 0&&o!==void 0&&a!==void 0&&e.set(r,[o,a])}return e}getSampledPoints(){const e=[],t=[];if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return{indices:e,positions:t};if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return{indices:e,positions:t};this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(r),r.end()}const i=Me(this.device,this.sampledPointsFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=!!i[r*4+1],a=i[r*4+2],l=i[r*4+3];o&&s!==void 0&&a!==void 0&&l!==void 0&&(e.push(s),t.push(a,l))}return{indices:e,positions:t}}getTrackedPositionsArray(){const e=[];if(!this.trackedIndices||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return e;e.length=this.trackedIndices.length*2;const t=Me(this.device,this.trackedPositionsFbo);for(let i=0;i<t.length/4;i+=1){const r=t[i*4],s=t[i*4+1],o=this.trackedIndices[i];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d,_,I,P,A,O;(e=this.drawCommand)==null||e.destroy(),this.drawCommand=void 0,(t=this.drawHighlightedCommand)==null||t.destroy(),this.drawHighlightedCommand=void 0,(i=this.updatePositionCommand)==null||i.destroy(),this.updatePositionCommand=void 0,(r=this.dragPointCommand)==null||r.destroy(),this.dragPointCommand=void 0,(s=this.findPointsOnAreaSelectionCommand)==null||s.destroy(),this.findPointsOnAreaSelectionCommand=void 0,(o=this.findPointsOnPolygonSelectionCommand)==null||o.destroy(),this.findPointsOnPolygonSelectionCommand=void 0,(a=this.findHoveredPointCommand)==null||a.destroy(),this.findHoveredPointCommand=void 0,(l=this.fillSampledPointsFboCommand)==null||l.destroy(),this.fillSampledPointsFboCommand=void 0,(c=this.trackPointsCommand)==null||c.destroy(),this.trackPointsCommand=void 0,this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionFbo=void 0,this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionFbo=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedFbo=void 0,this.hoveredFbo&&!this.hoveredFbo.destroyed&&this.hoveredFbo.destroy(),this.hoveredFbo=void 0,this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=void 0,this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=void 0,this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionTexture=void 0,this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionTexture=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=void 0,this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedTexture=void 0,this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=void 0,this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=void 0,this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=void 0,this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=void 0,this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=void 0,this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=void 0,(u=this.updatePositionUniformStore)==null||u.destroy(),this.updatePositionUniformStore=void 0,(f=this.dragPointUniformStore)==null||f.destroy(),this.dragPointUniformStore=void 0,(h=this.drawUniformStore)==null||h.destroy(),this.drawUniformStore=void 0,(d=this.findPointsOnAreaSelectionUniformStore)==null||d.destroy(),this.findPointsOnAreaSelectionUniformStore=void 0,(_=this.findPointsOnPolygonSelectionUniformStore)==null||_.destroy(),this.findPointsOnPolygonSelectionUniformStore=void 0,(I=this.findHoveredPointUniformStore)==null||I.destroy(),this.findHoveredPointUniformStore=void 0,(P=this.fillSampledPointsUniformStore)==null||P.destroy(),this.fillSampledPointsUniformStore=void 0,(A=this.drawHighlightedUniformStore)==null||A.destroy(),this.drawHighlightedUniformStore=void 0,(O=this.trackPointsUniformStore)==null||O.destroy(),this.trackPointsUniformStore=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=void 0,this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=void 0,this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=void 0,this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=void 0,this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=void 0,this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=void 0,this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=void 0,this.updatePositionVertexCoordBuffer&&!this.updatePositionVertexCoordBuffer.destroyed&&this.updatePositionVertexCoordBuffer.destroy(),this.updatePositionVertexCoordBuffer=void 0,this.dragPointVertexCoordBuffer&&!this.dragPointVertexCoordBuffer.destroyed&&this.dragPointVertexCoordBuffer.destroy(),this.dragPointVertexCoordBuffer=void 0,this.findPointsOnAreaSelectionVertexCoordBuffer&&!this.findPointsOnAreaSelectionVertexCoordBuffer.destroyed&&this.findPointsOnAreaSelectionVertexCoordBuffer.destroy(),this.findPointsOnAreaSelectionVertexCoordBuffer=void 0,this.findPointsOnPolygonSelectionVertexCoordBuffer&&!this.findPointsOnPolygonSelectionVertexCoordBuffer.destroyed&&this.findPointsOnPolygonSelectionVertexCoordBuffer.destroy(),this.findPointsOnPolygonSelectionVertexCoordBuffer=void 0,this.drawHighlightedVertexCoordBuffer&&!this.drawHighlightedVertexCoordBuffer.destroyed&&this.drawHighlightedVertexCoordBuffer.destroy(),this.drawHighlightedVertexCoordBuffer=void 0,this.trackPointsVertexCoordBuffer&&!this.trackPointsVertexCoordBuffer.destroyed&&this.trackPointsVertexCoordBuffer.destroy(),this.trackPointsVertexCoordBuffer=void 0}swapFbo(){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionFbo||this.previousPositionFbo.destroyed)return;const e=this.previousPositionTexture,t=this.previousPositionFbo;this.previousPositionTexture=this.currentPositionTexture,this.previousPositionFbo=this.currentPositionFbo,this.currentPositionTexture=e,this.currentPositionFbo=t}rescaleInitialNodePositions(){const{config:{spaceSize:e}}=this;if(!this.data.pointPositions||!e)return;const t=this.data.pointPositions,i=t.length/2;let r=1/0,s=-1/0,o=1/0,a=-1/0;for(let A=0;A<t.length;A+=2){const O=t[A],E=t[A+1];r=Math.min(r,O),s=Math.max(s,O),o=Math.min(o,E),a=Math.max(a,E)}const l=s-r,c=a-o,u=Math.max(l,c);if(u>e){this.scaleX=void 0,this.scaleY=void 0;return}const f=e*e*.001,h=i>f?e*Math.max(1.2,Math.sqrt(i)/e):e*.1,d=h/u,_=(e-h)/2,I=(u-l)/2*d+_,P=(u-c)/2*d+_;this.scaleX=A=>(A-r)*d+I,this.scaleY=A=>(A-o)*d+P;for(let A=0;A<i;A++)this.data.pointPositions[A*2]=this.scaleX(t[A*2]),this.data.pointPositions[A*2+1]=this.scaleY(t[A*2+1])}}const Fv={passive:!1},ei={capture:!0,passive:!1};function Eo(n){n.stopImmediatePropagation()}function yn(n){n.preventDefault(),n.stopImmediatePropagation()}function Ru(n){var e=n.document.documentElement,t=we(n).on("dragstart.drag",yn,ei);"onselectstart"in e?t.on("selectstart.drag",yn,ei):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function ku(n,e){var t=n.document.documentElement,i=we(n).on("dragstart.drag",null);e&&(i.on("click.drag",yn,ei),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in t?i.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}const vr=n=>()=>n;function Ro(n,{sourceEvent:e,subject:t,target:i,identifier:r,active:s,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:t,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}Ro.prototype.on=function(){var n=this._.on.apply(this._,arguments);return n===this._?this:n};function Nv(n){return!n.ctrlKey&&!n.button}function Ov(){return this.parentNode}function Bv(n,e){return e??{x:n.x,y:n.y}}function Uv(){return navigator.maxTouchPoints||"ontouchstart"in this}function zv(){var n=Nv,e=Ov,t=Bv,i=Uv,r={},s=ui("start","drag","end"),o=0,a,l,c,u,f=0;function h(x){x.on("mousedown.drag",d).filter(i).on("touchstart.drag",P).on("touchmove.drag",A,Fv).on("touchend.drag touchcancel.drag",O).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(x,R){if(!(u||!n.call(this,x,R))){var N=E(this,e.call(this,x,R),x,R,"mouse");N&&(we(x.view).on("mousemove.drag",_,ei).on("mouseup.drag",I,ei),Ru(x.view),Eo(x),c=!1,a=x.clientX,l=x.clientY,N("start",x))}}function _(x){if(yn(x),!c){var R=x.clientX-a,N=x.clientY-l;c=R*R+N*N>f}r.mouse("drag",x)}function I(x){we(x.view).on("mousemove.drag mouseup.drag",null),ku(x.view,c),yn(x),r.mouse("end",x)}function P(x,R){if(n.call(this,x,R)){var N=x.changedTouches,U=e.call(this,x,R),W=N.length,q,G;for(q=0;q<W;++q)(G=E(this,U,x,R,N[q].identifier,N[q]))&&(Eo(x),G("start",x,N[q]))}}function A(x){var R=x.changedTouches,N=R.length,U,W;for(U=0;U<N;++U)(W=r[R[U].identifier])&&(yn(x),W("drag",x,R[U]))}function O(x){var R=x.changedTouches,N=R.length,U,W;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),U=0;U<N;++U)(W=r[R[U].identifier])&&(Eo(x),W("end",x,R[U]))}function E(x,R,N,U,W,q){var G=s.copy(),B=yt(q||N,R),de,se,C;if((C=t.call(x,new Ro("beforestart",{sourceEvent:N,target:h,identifier:W,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:G}),U))!=null)return de=C.x-B[0]||0,se=C.y-B[1]||0,function H(M,$,Z){var j=B,ee;switch(M){case"start":r[W]=H,ee=o++;break;case"end":delete r[W],--o;case"drag":B=yt(Z||$,R),ee=o;break}G.call(M,x,new Ro(M,{sourceEvent:$,subject:C,target:h,identifier:W,active:ee,x:B[0]+de,y:B[1]+se,dx:B[0]-j[0],dy:B[1]-j[1],dispatch:G}),U)}}return h.filter=function(x){return arguments.length?(n=typeof x=="function"?x:vr(!!x),h):n},h.container=function(x){return arguments.length?(e=typeof x=="function"?x:vr(x),h):e},h.subject=function(x){return arguments.length?(t=typeof x=="function"?x:vr(x),h):t},h.touchable=function(x){return arguments.length?(i=typeof x=="function"?x:vr(!!x),h):i},h.on=function(){var x=s.on.apply(s,arguments);return x===s?h:x},h.clickDistance=function(x){return arguments.length?(f=(x=+x)*x,h):Math.sqrt(f)},h}const br=n=>()=>n;function Lv(n,{sourceEvent:e,target:t,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function It(n,e,t){this.k=n,this.x=e,this.y=t}It.prototype={constructor:It,scale:function(n){return n===1?this:new It(this.k*n,this.x,this.y)},translate:function(n,e){return n===0&e===0?this:new It(this.k,this.x+this.k*n,this.y+this.k*e)},apply:function(n){return[n[0]*this.k+this.x,n[1]*this.k+this.y]},applyX:function(n){return n*this.k+this.x},applyY:function(n){return n*this.k+this.y},invert:function(n){return[(n[0]-this.x)/this.k,(n[1]-this.y)/this.k]},invertX:function(n){return(n-this.x)/this.k},invertY:function(n){return(n-this.y)/this.k},rescaleX:function(n){return n.copy().domain(n.range().map(this.invertX,this).map(n.invert,n))},rescaleY:function(n){return n.copy().domain(n.range().map(this.invertY,this).map(n.invert,n))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ti=new It(1,0,0);It.prototype;function ko(n){n.stopImmediatePropagation()}function ni(n){n.preventDefault(),n.stopImmediatePropagation()}function Vv(n){return(!n.ctrlKey||n.type==="wheel")&&!n.button}function Hv(){var n=this;return n instanceof SVGElement?(n=n.ownerSVGElement||n,n.hasAttribute("viewBox")?(n=n.viewBox.baseVal,[[n.x,n.y],[n.x+n.width,n.y+n.height]]):[[0,0],[n.width.baseVal.value,n.height.baseVal.value]]):[[0,0],[n.clientWidth,n.clientHeight]]}function Du(){return this.__zoom||ti}function Wv(n){return-n.deltaY*(n.deltaMode===1?.05:n.deltaMode?1:.002)*(n.ctrlKey?10:1)}function $v(){return navigator.maxTouchPoints||"ontouchstart"in this}function Xv(n,e,t){var i=n.invertX(e[0][0])-t[0][0],r=n.invertX(e[1][0])-t[1][0],s=n.invertY(e[0][1])-t[0][1],o=n.invertY(e[1][1])-t[1][1];return n.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function Yv(){var n=Vv,e=Hv,t=Xv,i=Wv,r=$v,s=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=vd,c=ui("start","zoom","end"),u,f,h,d=500,_=150,I=0,P=10;function A(C){C.property("__zoom",Du).on("wheel.zoom",W,{passive:!1}).on("mousedown.zoom",q).on("dblclick.zoom",G).filter(r).on("touchstart.zoom",B).on("touchmove.zoom",de).on("touchend.zoom touchcancel.zoom",se).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.transform=function(C,H,M,$){var Z=C.selection?C.selection():C;Z.property("__zoom",Du),C!==Z?R(C,H,M,$):Z.interrupt().each(function(){N(this,arguments).event($).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},A.scaleBy=function(C,H,M,$){A.scaleTo(C,function(){var Z=this.__zoom.k,j=typeof H=="function"?H.apply(this,arguments):H;return Z*j},M,$)},A.scaleTo=function(C,H,M,$){A.transform(C,function(){var Z=e.apply(this,arguments),j=this.__zoom,ee=M==null?x(Z):typeof M=="function"?M.apply(this,arguments):M,J=j.invert(ee),ge=typeof H=="function"?H.apply(this,arguments):H;return t(E(O(j,ge),ee,J),Z,o)},M,$)},A.translateBy=function(C,H,M,$){A.transform(C,function(){return t(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof M=="function"?M.apply(this,arguments):M),e.apply(this,arguments),o)},null,$)},A.translateTo=function(C,H,M,$,Z){A.transform(C,function(){var j=e.apply(this,arguments),ee=this.__zoom,J=$==null?x(j):typeof $=="function"?$.apply(this,arguments):$;return t(ti.translate(J[0],J[1]).scale(ee.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof M=="function"?-M.apply(this,arguments):-M),j,o)},$,Z)};function O(C,H){return H=Math.max(s[0],Math.min(s[1],H)),H===C.k?C:new It(H,C.x,C.y)}function E(C,H,M){var $=H[0]-M[0]*C.k,Z=H[1]-M[1]*C.k;return $===C.x&&Z===C.y?C:new It(C.k,$,Z)}function x(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function R(C,H,M,$){C.on("start.zoom",function(){N(this,arguments).event($).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event($).end()}).tween("zoom",function(){var Z=this,j=arguments,ee=N(Z,j).event($),J=e.apply(Z,j),ge=M==null?x(J):typeof M=="function"?M.apply(Z,j):M,fe=Math.max(J[1][0]-J[0][0],J[1][1]-J[0][1]),Te=Z.__zoom,oe=typeof H=="function"?H.apply(Z,j):H,We=l(Te.invert(ge).concat(fe/Te.k),oe.invert(ge).concat(fe/oe.k));return function($e){if($e===1)$e=oe;else{var nt=We($e),Gt=fe/nt[2];$e=new It(Gt,ge[0]-nt[0]*Gt,ge[1]-nt[1]*Gt)}ee.zoom(null,$e)}})}function N(C,H,M){return!M&&C.__zooming||new U(C,H)}function U(C,H){this.that=C,this.args=H,this.active=0,this.sourceEvent=null,this.extent=e.apply(C,H),this.taps=0}U.prototype={event:function(C){return C&&(this.sourceEvent=C),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(C,H){return this.mouse&&C!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var H=we(this.that).datum();c.call(C,this.that,new Lv(C,{sourceEvent:this.sourceEvent,target:A,transform:this.that.__zoom,dispatch:c}),H)}};function W(C,...H){if(!n.apply(this,arguments))return;var M=N(this,H).event(C),$=this.__zoom,Z=Math.max(s[0],Math.min(s[1],$.k*Math.pow(2,i.apply(this,arguments)))),j=yt(C);if(M.wheel)(M.mouse[0][0]!==j[0]||M.mouse[0][1]!==j[1])&&(M.mouse[1]=$.invert(M.mouse[0]=j)),clearTimeout(M.wheel);else{if($.k===Z)return;M.mouse=[j,$.invert(j)],yi(this),M.start()}ni(C),M.wheel=setTimeout(ee,_),M.zoom("mouse",t(E(O($,Z),M.mouse[0],M.mouse[1]),M.extent,o));function ee(){M.wheel=null,M.end()}}function q(C,...H){if(h||!n.apply(this,arguments))return;var M=C.currentTarget,$=N(this,H,!0).event(C),Z=we(C.view).on("mousemove.zoom",ge,!0).on("mouseup.zoom",fe,!0),j=yt(C,M),ee=C.clientX,J=C.clientY;Ru(C.view),ko(C),$.mouse=[j,this.__zoom.invert(j)],yi(this),$.start();function ge(Te){if(ni(Te),!$.moved){var oe=Te.clientX-ee,We=Te.clientY-J;$.moved=oe*oe+We*We>I}$.event(Te).zoom("mouse",t(E($.that.__zoom,$.mouse[0]=yt(Te,M),$.mouse[1]),$.extent,o))}function fe(Te){Z.on("mousemove.zoom mouseup.zoom",null),ku(Te.view,$.moved),ni(Te),$.event(Te).end()}}function G(C,...H){if(n.apply(this,arguments)){var M=this.__zoom,$=yt(C.changedTouches?C.changedTouches[0]:C,this),Z=M.invert($),j=M.k*(C.shiftKey?.5:2),ee=t(E(O(M,j),$,Z),e.apply(this,H),o);ni(C),a>0?we(this).transition().duration(a).call(R,ee,$,C):we(this).call(A.transform,ee,$,C)}}function B(C,...H){if(n.apply(this,arguments)){var M=C.touches,$=M.length,Z=N(this,H,C.changedTouches.length===$).event(C),j,ee,J,ge;for(ko(C),ee=0;ee<$;++ee)J=M[ee],ge=yt(J,this),ge=[ge,this.__zoom.invert(ge),J.identifier],Z.touch0?!Z.touch1&&Z.touch0[2]!==ge[2]&&(Z.touch1=ge,Z.taps=0):(Z.touch0=ge,j=!0,Z.taps=1+!!u);u&&(u=clearTimeout(u)),j&&(Z.taps<2&&(f=ge[0],u=setTimeout(function(){u=null},d)),yi(this),Z.start())}}function de(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee,J,ge;for(ni(C),j=0;j<Z;++j)ee=$[j],J=yt(ee,this),M.touch0&&M.touch0[2]===ee.identifier?M.touch0[0]=J:M.touch1&&M.touch1[2]===ee.identifier&&(M.touch1[0]=J);if(ee=M.that.__zoom,M.touch1){var fe=M.touch0[0],Te=M.touch0[1],oe=M.touch1[0],We=M.touch1[1],$e=($e=oe[0]-fe[0])*$e+($e=oe[1]-fe[1])*$e,nt=(nt=We[0]-Te[0])*nt+(nt=We[1]-Te[1])*nt;ee=O(ee,Math.sqrt($e/nt)),J=[(fe[0]+oe[0])/2,(fe[1]+oe[1])/2],ge=[(Te[0]+We[0])/2,(Te[1]+We[1])/2]}else if(M.touch0)J=M.touch0[0],ge=M.touch0[1];else return;M.zoom("touch",t(E(ee,J,ge),M.extent,o))}}function se(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee;for(ko(C),h&&clearTimeout(h),h=setTimeout(function(){h=null},d),j=0;j<Z;++j)ee=$[j],M.touch0&&M.touch0[2]===ee.identifier?delete M.touch0:M.touch1&&M.touch1[2]===ee.identifier&&delete M.touch1;if(M.touch1&&!M.touch0&&(M.touch0=M.touch1,delete M.touch1),M.touch0)M.touch0[1]=this.__zoom.invert(M.touch0[0]);else if(M.end(),M.taps===2&&(ee=yt(ee,this),Math.hypot(f[0]-ee[0],f[1]-ee[1])<P)){var J=we(this).on("dblclick.zoom");J&&J.apply(this,arguments)}}}return A.wheelDelta=function(C){return arguments.length?(i=typeof C=="function"?C:br(+C),A):i},A.filter=function(C){return arguments.length?(n=typeof C=="function"?C:br(!!C),A):n},A.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:br(!!C),A):r},A.extent=function(C){return arguments.length?(e=typeof C=="function"?C:br([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),A):e},A.scaleExtent=function(C){return arguments.length?(s[0]=+C[0],s[1]=+C[1],A):[s[0],s[1]]},A.translateExtent=function(C){return arguments.length?(o[0][0]=+C[0][0],o[1][0]=+C[1][0],o[0][1]=+C[0][1],o[1][1]=+C[1][1],A):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},A.constrain=function(C){return arguments.length?(t=C,A):t},A.duration=function(C){return arguments.length?(a=+C,A):a},A.interpolate=function(C){return arguments.length?(l=C,A):l},A.on=function(){var C=c.on.apply(c,arguments);return C===c?A:C},A.clickDistance=function(C){return arguments.length?(I=(C=+C)*C,A):Math.sqrt(I)},A.tapDistance=function(C){return arguments.length?(P=+C,A):P},A}class qv{constructor(e,t){this.eventTransform=ti,this.behavior=Yv().scaleExtent([.001,1/0]).on("start",i=>{var s,o;this.isRunning=!0;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomStart)==null||o.call(s,i,r)}).on("zoom",i=>{var h,d;this.eventTransform=i.transform;const{eventTransform:{x:r,y:s,k:o},store:{transform:a,screenSize:l}}=this,c=l[0],u=l[1];if(!c||!u)return;Dx(a,c,u),mc(a,a,[r,s]),js(a,a,[o,o]),mc(a,a,[c/2,u/2]),js(a,a,[c/2,u/2]),js(a,a,[1,-1]);const f=!!i.sourceEvent;(d=(h=this.config)==null?void 0:h.onZoom)==null||d.call(h,i,f)}).on("end",i=>{var s,o;this.isRunning=!1;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomEnd)==null||o.call(s,i,r)}),this.isRunning=!1,this.store=e,this.config=t}getTransform(e,t,i=.1){if(e.length===0)return this.eventTransform;const{store:{screenSize:r}}=this,s=r[0],o=r[1];let a=1/0,l=-1/0,c=1/0,u=-1/0;for(let R=0;R<e.length;R+=2){const N=e[R],U=e[R+1];N<a&&(a=N),N>l&&(l=N),U<c&&(c=U),U>u&&(u=U)}const f=[this.store.scaleX(a),this.store.scaleX(l)],h=[this.store.scaleY(c),this.store.scaleY(u)];f[0]===f[1]&&(f[0]-=.5,f[1]+=.5),h[0]===h[1]&&(h[0]+=.5,h[1]-=.5);const d=s*(1-i*2)/(f[1]-f[0]),_=o*(1-i*2)/(h[0]-h[1]),I=Mc(t??Math.min(d,_),...this.behavior.scaleExtent()),P=(f[1]+f[0])/2,A=(h[1]+h[0])/2,O=s/2-P*I,E=o/2-A*I;return ti.translate(O,E).scale(I)}getDistanceToPoint(e){const{x:t,y:i,k:r}=this.eventTransform,s=this.getTransform(e,r),o=t-s.x,a=i-s.y;return Math.sqrt(o*o+a*a)}getMiddlePointTransform(e){const{store:{screenSize:t},eventTransform:{x:i,y:r,k:s}}=this,o=t[0],a=t[1],l=(o/2-i)/s,c=(a/2-r)/s,u=this.store.scaleX(e[0]),f=this.store.scaleY(e[1]),h=(l+u)/2,d=(c+f)/2,_=1,I=o/2-h*_,P=a/2-d*_;return ti.translate(I,P).scale(_)}convertScreenToSpacePosition(e){const{eventTransform:{x:t,y:i,k:r},store:{screenSize:s}}=this,o=s[0],a=s[1],l=(e[0]-t)/r,c=(e[1]-i)/r,u=[l,a-c];return u[0]-=(o-this.store.adjustedSpaceSize)/2,u[1]-=(a-this.store.adjustedSpaceSize)/2,u}convertSpaceToScreenPosition(e){const t=this.eventTransform.applyX(this.store.scaleX(e[0])),i=this.eventTransform.applyY(this.store.scaleY(e[1]));return[t,i]}convertSpaceToScreenRadius(e){const{config:{scalePointsOnZoom:t},store:{maxPointSize:i},eventTransform:{k:r}}=this;let s=e*2;return t?s*=r:s*=Math.min(5,Math.max(1,r*.01)),Math.min(s,i)/2}}class jv{constructor(e,t){this.isActive=!1,this.behavior=zv().subject(i=>this.store.hoveredPoint&&!this.store.isSpaceKeyPressed?{x:i.x,y:i.y}:void 0).on("start",i=>{var r,s;this.store.hoveredPoint&&(this.store.draggingPointIndex=this.store.hoveredPoint.index,this.isActive=!0,(s=(r=this.config)==null?void 0:r.onDragStart)==null||s.call(r,i))}).on("drag",i=>{var r,s;(s=(r=this.config)==null?void 0:r.onDrag)==null||s.call(r,i)}).on("end",i=>{var r,s;this.isActive=!1,this.store.draggingPointIndex=void 0,(s=(r=this.config)==null?void 0:r.onDragEnd)==null||s.call(r,i)}),this.store=e,this.config=t}}class Kv{constructor(e,t,i){if(this.config=new Sy,this.graph=new uv(this.config),this.isReady=!1,this.requestAnimationFrameId=0,this.isRightClickMouse=!1,this.store=new by,this.zoomInstance=new qv(this.store,this.config),this.dragInstance=new jv(this.store,this.config),this._findHoveredItemExecutionCount=0,this._isMouseOnCanvas=!1,this._lastMouseX=0,this._lastMouseY=0,this._lastCheckedMouseX=0,this._lastCheckedMouseY=0,this._shouldForceHoverDetection=!1,this._isFirstRenderAfterInit=!0,this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this._isDestroyed=!1,t&&this.config.init(t),i)this.deviceInitPromise=i,this.shouldDestroyDevice=!1;else{const s=document.createElement("canvas");this.deviceInitPromise=this.createDevice(s),this.shouldDestroyDevice=!0}const r=this.deviceInitPromise.then(s=>{if(this._isDestroyed)return this.shouldDestroyDevice&&s.destroy(),s;this.device=s,this.isReady=!0;const o=this.validateDevice(s);i&&o.setProps({useDevicePixels:this.config.pixelRatio}),this.store.div=e;const a=o.canvas;a.parentNode!==this.store.div&&(a.parentNode&&a.parentNode.removeChild(a),this.store.div.appendChild(a)),this.addAttribution(),a.style.width="100%",a.style.height="100%",this.canvas=a;const l=this.canvas.clientWidth,c=this.canvas.clientHeight;return this.store.adjustSpaceSize(this.config.spaceSize,this.device.limits.maxTextureDimension2D),this.store.setWebGLMaxTextureSize(this.device.limits.maxTextureDimension2D),this.store.updateScreenSize(l,c),this.canvasD3Selection=we(this.canvas),this.canvasD3Selection.on("mouseenter.cosmos",u=>{this._isMouseOnCanvas=!0,this._lastMouseX=u.clientX,this._lastMouseY=u.clientY}).on("mousemove.cosmos",u=>{this._isMouseOnCanvas=!0,this._lastMouseX=u.clientX,this._lastMouseY=u.clientY}).on("mouseleave.cosmos",u=>{this._isMouseOnCanvas=!1,this.currentEvent=u,this.store.hoveredPoint!==void 0&&this.config.onPointMouseOut&&this.config.onPointMouseOut(u),this.store.hoveredLinkIndex!==void 0&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(u),this.isRightClickMouse=!1,this.store.hoveredPoint=void 0,this.store.hoveredLinkIndex=void 0,this.updateCanvasCursor()}),we(document).on("keydown.cosmos",u=>{u.code==="Space"&&(this.store.isSpaceKeyPressed=!0)}).on("keyup.cosmos",u=>{u.code==="Space"&&(this.store.isSpaceKeyPressed=!1)}),this.zoomInstance.behavior.on("start.detect",u=>{this.currentEvent=u}).on("zoom.detect",u=>{!!u.sourceEvent&&this.updateMousePosition(u.sourceEvent),this.currentEvent=u}).on("end.detect",u=>{this.currentEvent=u,this._shouldForceHoverDetection=!0}),this.dragInstance.behavior.on("start.detect",u=>{this.currentEvent=u,this.updateCanvasCursor()}).on("drag.detect",u=>{this.dragInstance.isActive&&this.updateMousePosition(u),this.currentEvent=u}).on("end.detect",u=>{this.currentEvent=u,this.updateCanvasCursor()}),this.canvasD3Selection.call(this.dragInstance.behavior).call(this.zoomInstance.behavior).on("click",this.onClick.bind(this)).on("mousemove",this.onMouseMove.bind(this)).on("contextmenu",this.onContextMenu.bind(this)),(!this.config.enableZoom||!this.config.enableDrag)&&this.updateZoomDragBehaviors(),this.setZoomLevel(this.config.initialZoomLevel??1),this.store.maxPointSize=to(s,this.config.pixelRatio),this.store.isSimulationRunning=this.config.enableSimulation,this.points=new Mv(s,this.config,this.store,this.graph),this.lines=new xv(s,this.config,this.store,this.graph,this.points),this.config.enableSimulation&&(this.forceGravity=new q0(s,this.config,this.store,this.graph,this.points),this.forceCenter=new X0(s,this.config,this.store,this.graph,this.points),this.forceManyBody=new G0(s,this.config,this.store,this.graph,this.points),this.forceLinkIncoming=new Cu(s,this.config,this.store,this.graph,this.points),this.forceLinkOutgoing=new Cu(s,this.config,this.store,this.graph,this.points),this.forceMouse=new tv(s,this.config,this.store,this.graph,this.points)),this.clusters=new sv(s,this.config,this.store,this.graph,this.points),this.store.backgroundColor=Tt(this.config.backgroundColor),this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),this.config.focusedPointIndex!==void 0&&this.store.setFocusedPoint(this.config.focusedPointIndex),this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Hi),this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),this.store.updateLinkHoveringEnabled(this.config),this.config.showFPSMonitor&&(this.fpsMonitor=new Iu(this.canvas)),this.config.randomSeed!==void 0&&this.store.addRandomSeed(this.config.randomSeed),s}).catch(s=>{throw this.device=void 0,this.isReady=!1,console.error("Device initialization failed:",s),s});this.ready=r.then(()=>{})}get progress(){return this._isDestroyed?0:this.store.simulationProgress}get isSimulationRunning(){return this._isDestroyed?!1:this.store.isSimulationRunning}get maxPointSize(){return this._isDestroyed?0:this.store.maxPointSize}setConfig(e){var i,r,s,o,a,l,c,u,f;if(this._isDestroyed||this.ensureDevice(()=>this.setConfig(e)))return;const t={...this.config};this.config.init(e),t.pointDefaultColor!==this.config.pointDefaultColor&&(this.graph.updatePointColor(),(i=this.points)==null||i.updateColor()),t.pointDefaultSize!==this.config.pointDefaultSize&&(this.graph.updatePointSize(),(r=this.points)==null||r.updateSize()),t.linkDefaultColor!==this.config.linkDefaultColor&&(this.graph.updateLinkColor(),(s=this.lines)==null||s.updateColor()),t.linkDefaultWidth!==this.config.linkDefaultWidth&&(this.graph.updateLinkWidth(),(o=this.lines)==null||o.updateWidth()),t.linkDefaultArrows!==this.config.linkDefaultArrows&&(this.graph.updateArrows(),(a=this.lines)==null||a.updateArrow()),(t.curvedLinkSegments!==this.config.curvedLinkSegments||t.curvedLinks!==this.config.curvedLinks)&&((l=this.lines)==null||l.updateCurveLineGeometry()),t.backgroundColor!==this.config.backgroundColor&&(this.store.backgroundColor=Tt(this.config.backgroundColor??Fs)),t.hoveredPointRingColor!==this.config.hoveredPointRingColor&&this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),t.focusedPointRingColor!==this.config.focusedPointRingColor&&this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),t.pointGreyoutColor!==this.config.pointGreyoutColor&&this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Hi),t.hoveredLinkColor!==this.config.hoveredLinkColor&&this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),t.focusedPointIndex!==this.config.focusedPointIndex&&this.store.setFocusedPoint(this.config.focusedPointIndex),t.pixelRatio!==this.config.pixelRatio&&(c=this.device)!=null&&c.canvasContext&&(this.device.canvasContext.setProps({useDevicePixels:this.config.pixelRatio}),this.store.maxPointSize=to(this.device,this.config.pixelRatio)),t.spaceSize!==this.config.spaceSize&&(this.store.adjustSpaceSize(this.config.spaceSize,((u=this.device)==null?void 0:u.limits.maxTextureDimension2D)??4096),this.resizeCanvas(!0),this.update(this.store.isSimulationRunning?this.store.alpha:0)),t.showFPSMonitor!==this.config.showFPSMonitor&&(this.config.showFPSMonitor?this.fpsMonitor=new Iu(this.canvas):((f=this.fpsMonitor)==null||f.destroy(),this.fpsMonitor=void 0)),(t.enableZoom!==this.config.enableZoom||t.enableDrag!==this.config.enableDrag)&&this.updateZoomDragBehaviors(),(t.onLinkClick!==this.config.onLinkClick||t.onLinkContextMenu!==this.config.onLinkContextMenu||t.onLinkMouseOver!==this.config.onLinkMouseOver||t.onLinkMouseOut!==this.config.onLinkMouseOut)&&this.store.updateLinkHoveringEnabled(this.config)}setPointPositions(e,t){this._isDestroyed||this.ensureDevice(()=>this.setPointPositions(e,t))||(this.graph.inputPointPositions=e,this.points.shouldSkipRescale=t,this.isPointPositionsUpdateNeeded=!0,this.isLinksUpdateNeeded=!0,this.isPointColorUpdateNeeded=!0,this.isPointSizeUpdateNeeded=!0,this.isPointShapeUpdateNeeded=!0,this.isPointImageIndicesUpdateNeeded=!0,this.isPointImageSizesUpdateNeeded=!0,this.isPointClusterUpdateNeeded=!0,this.isForceManyBodyUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0,this.isForceCenterUpdateNeeded=!0)}setPointColors(e){this._isDestroyed||this.ensureDevice(()=>this.setPointColors(e))||(this.graph.inputPointColors=e,this.isPointColorUpdateNeeded=!0)}getPointColors(){return this._isDestroyed?new Float32Array:this.graph.pointColors??new Float32Array}setPointSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointSizes(e))||(this.graph.inputPointSizes=e,this.isPointSizeUpdateNeeded=!0)}setPointShapes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointShapes(e))||(this.graph.inputPointShapes=e,this.isPointShapeUpdateNeeded=!0)}setImageData(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setImageData(e))||(this.graph.inputImageData=e,(t=this.points)==null||t.createAtlas())}setPointImageIndices(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageIndices(e))||(this.graph.inputPointImageIndices=e,this.isPointImageIndicesUpdateNeeded=!0)}setPointImageSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageSizes(e))||(this.graph.inputPointImageSizes=e,this.isPointImageSizesUpdateNeeded=!0)}getPointSizes(){return this._isDestroyed?new Float32Array:this.graph.pointSizes??new Float32Array}setLinks(e){this._isDestroyed||this.ensureDevice(()=>this.setLinks(e))||(this.graph.inputLinks=e,this.isLinksUpdateNeeded=!0,this.isLinkColorUpdateNeeded=!0,this.isLinkWidthUpdateNeeded=!0,this.isLinkArrowUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0)}setLinkColors(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkColors(e))||(this.graph.inputLinkColors=e,this.isLinkColorUpdateNeeded=!0)}getLinkColors(){return this._isDestroyed?new Float32Array:this.graph.linkColors??new Float32Array}setLinkWidths(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkWidths(e))||(this.graph.inputLinkWidths=e,this.isLinkWidthUpdateNeeded=!0)}getLinkWidths(){return this._isDestroyed?new Float32Array:this.graph.linkWidths??new Float32Array}setLinkArrows(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkArrows(e))||(this.graph.linkArrowsBoolean=e,this.isLinkArrowUpdateNeeded=!0)}setLinkStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkStrength(e))||(this.graph.inputLinkStrength=e,this.isForceLinkUpdateNeeded=!0)}setPointClusters(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusters(e))||(this.graph.inputPointClusters=e,this.isPointClusterUpdateNeeded=!0)}setClusterPositions(e){this._isDestroyed||this.ensureDevice(()=>this.setClusterPositions(e))||(this.graph.inputClusterPositions=e,this.isPointClusterUpdateNeeded=!0)}setPointClusterStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusterStrength(e))||(this.graph.inputClusterStrength=e,this.isPointClusterUpdateNeeded=!0)}setPinnedPoints(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setPinnedPoints(e))||(this.graph.inputPinnedPoints=e&&e.length>0?e:void 0,(t=this.points)==null||t.updatePinnedStatus())}render(e){if(this._isDestroyed||this.ensureDevice(()=>this.render(e)))return;this.graph.update();const{fitViewOnInit:t,fitViewDelay:i,fitViewPadding:r,fitViewDuration:s,fitViewByPointsInRect:o,fitViewByPointIndices:a,initialZoomLevel:l}=this.config;if(!this.graph.pointsNumber&&!this.graph.linksNumber){this.stopFrames(),we(this.canvas).style("cursor",null),this.device&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit());return}this._isFirstRenderAfterInit&&t&&l===void 0&&(this._fitViewOnInitTimeoutID=window.setTimeout(()=>{a?this.fitViewByPointIndices(a,s,r):o?this.setZoomTransformByPointPositions(new Float32Array(this.flatten(o)),s,void 0,r):this.fitView(s,r)},i)),this.update(e),this.startFrames(),this._isFirstRenderAfterInit=!1}zoomToPointByIndex(e,t=700,i=Ol,r=!0){if(this._isDestroyed||this.ensureDevice(()=>this.zoomToPointByIndex(e,t,i,r))||!this.device||!this.points||!this.canvasD3Selection)return;const{store:{screenSize:s}}=this,o=Me(this.device,this.points.currentPositionFbo);if(e===void 0)return;const a=o[e*4+0],l=o[e*4+1];if(a===void 0||l===void 0)return;const c=this.zoomInstance.getDistanceToPoint([a,l]),u=r?i:Math.max(this.getZoomLevel(),i);if(c<Math.min(s[0],s[1]))this.setZoomTransformByPointPositions(new Float32Array([a,l]),t,u);else{const f=this.zoomInstance.getTransform([a,l],u),h=this.zoomInstance.getMiddlePointTransform([a,l]);this.canvasD3Selection.transition().ease(vp).duration(t/2).call(this.zoomInstance.behavior.transform,h).transition().ease(bp).duration(t/2).call(this.zoomInstance.behavior.transform,f)}}zoom(e,t=0){this._isDestroyed||this.setZoomLevel(e,t)}setZoomLevel(e,t=0){this._isDestroyed||this.ensureDevice(()=>this.setZoomLevel(e,t))||this.canvasD3Selection&&(t===0?this.canvasD3Selection.call(this.zoomInstance.behavior.scaleTo,e):this.canvasD3Selection.transition().duration(t).call(this.zoomInstance.behavior.scaleTo,e))}getZoomLevel(){return this._isDestroyed?0:this.zoomInstance.eventTransform.k}getPointPositions(){if(this._isDestroyed||!this.device||!this.points)return[];if(this.graph.pointsNumber===void 0)return[];const e=[],t=Me(this.device,this.points.currentPositionFbo);e.length=this.graph.pointsNumber*2;for(let i=0;i<this.graph.pointsNumber;i+=1){const r=t[i*4+0],s=t[i*4+1];r!==void 0&&s!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}getClusterPositions(){if(this._isDestroyed||!this.device||!this.clusters)return[];if(this.graph.pointClusters===void 0||this.clusters.clusterCount===void 0)return[];this.clusters.calculateCentermass();const e=[],t=Me(this.device,this.clusters.centermassFbo);e.length=this.clusters.clusterCount*2;for(let i=0;i<e.length/2;i+=1){const r=t[i*4+0],s=t[i*4+1],o=t[i*4+2];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r/o,e[i*2+1]=s/o)}return e}fitView(e=250,t=.1){this._isDestroyed||this.ensureDevice(()=>this.fitView(e,t))||this.setZoomTransformByPointPositions(new Float32Array(this.getPointPositions()),e,void 0,t)}fitViewByPointIndices(e,t=250,i=.1){if(this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointIndices(e,t,i)))return;const r=this.getPointPositions(),s=new Float32Array(e.length*2);for(const[o,a]of e.entries())s[o*2]=r[a*2],s[o*2+1]=r[a*2+1];this.setZoomTransformByPointPositions(s,t,void 0,i)}fitViewByPointPositions(e,t=250,i=.1){this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointPositions(e,t,i))||this.setZoomTransformByPointPositions(new Float32Array(e),t,void 0,i)}setZoomTransformByPointPositions(e,t=250,i,r=.1){var o;if(this._isDestroyed||this.ensureDevice(()=>this.setZoomTransformByPointPositions(e,t,i,r)))return;this.resizeCanvas();const s=this.zoomInstance.getTransform(e,i,r);(o=this.canvasD3Selection)==null||o.transition().ease(Sp).duration(t).call(this.zoomInstance.behavior.transform,s)}getPointsInRect(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;const t=this.store.screenSize[1];return this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection(),Me(this.device,this.points.selectedFbo).map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}getPointsInPolygon(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;if(e.length<3)return new Float32Array;const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);return this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection(),Me(this.device,this.points.selectedFbo).map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}selectPointsInRect(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInRect(e))&&!(!this.device||!this.points)){if(e){const t=this.store.screenSize[1];this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection();const i=Me(this.device,this.points.selectedFbo);this.store.selectedIndices=i.map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointsInPolygon(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInPolygon(e))&&!(!this.device||!this.points)){if(e){if(e.length<3){console.warn("Polygon path requires at least 3 points to form a polygon.");return}const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection();const r=Me(this.device,this.points.selectedFbo);this.store.selectedIndices=r.map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointByIndex(e,t=!1){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointByIndex(e,t)))if(t){const i=this.graph.getAdjacentIndices(e)??[];this.selectPointsByIndices([e,...i])}else this.selectPointsByIndices([e])}selectPointsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.selectPointsByIndices(e))||this.points&&(e?e.length===0?this.store.selectedIndices=new Float32Array:this.store.selectedIndices=new Float32Array(e.filter(t=>t!==void 0)):this.store.selectedIndices=null,this.points.updateGreyoutStatus())}unselectPoints(){this._isDestroyed||this.ensureDevice(()=>this.unselectPoints())||this.points&&(this.store.selectedIndices=null,this.points.updateGreyoutStatus())}getSelectedIndices(){if(this._isDestroyed)return null;const{selectedIndices:e}=this.store;return e?Array.from(e):null}getAdjacentIndices(e){if(!this._isDestroyed)return this.graph.getAdjacentIndices(e)}spaceToScreenPosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertSpaceToScreenPosition(e)}screenToSpacePosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertScreenToSpacePosition(e)}spaceToScreenRadius(e){return this._isDestroyed?0:this.zoomInstance.convertSpaceToScreenRadius(e)}getPointRadiusByIndex(e){var t;if(!this._isDestroyed)return(t=this.graph.pointSizes)==null?void 0:t[e]}trackPointPositionsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.trackPointPositionsByIndices(e))||this.points&&this.points.trackPointsByIndices(e)}getTrackedPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getTrackedPositionsMap()}getTrackedPointPositionsArray(){return this._isDestroyed||!this.points?[]:this.points.getTrackedPositionsArray()}getSampledPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getSampledPointPositionsMap()}getSampledPoints(){return this._isDestroyed||!this.points?{indices:[],positions:[]}:this.points.getSampledPoints()}getSampledLinkPositionsMap(){return this._isDestroyed||!this.lines?new Map:this.lines.getSampledLinkPositionsMap()}getSampledLinks(){return this._isDestroyed||!this.lines?{indices:[],positions:[],angles:[]}:this.lines.getSampledLinks()}getScaleX(){if(!(this._isDestroyed||!this.points))return this.points.scaleX}getScaleY(){if(!(this._isDestroyed||!this.points))return this.points.scaleY}start(e=1){var t,i;this._isDestroyed||this.ensureDevice(()=>this.start(e))||this.graph.pointsNumber&&(this.store.isSimulationRunning=!0,this.store.simulationProgress=0,this.store.alpha=e,(i=(t=this.config).onSimulationStart)==null||i.call(t))}stop(){var e,t;this._isDestroyed||(this.store.isSimulationRunning=!1,this.store.simulationProgress=0,this.store.alpha=0,(t=(e=this.config).onSimulationEnd)==null||t.call(e))}pause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.pause())||(this.store.isSimulationRunning=!1,(t=(e=this.config).onSimulationPause)==null||t.call(e))}unpause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.unpause())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationUnpause)==null||t.call(e))}step(){this._isDestroyed||this.ensureDevice(()=>this.step())||this.config.enableSimulation&&this.store.pointsTextureSize&&this.runSimulationStep(!0)}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d;this._isDestroyed||(this._isDestroyed=!0,this.isReady=!1,window.clearTimeout(this._fitViewOnInitTimeoutID),this.stopFrames(),this.canvasD3Selection&&this.canvasD3Selection.on("mouseenter.cosmos",null).on("mousemove.cosmos",null).on("mouseleave.cosmos",null).on("click",null).on("mousemove",null).on("contextmenu",null).on(".drag",null).on(".zoom",null),we(document).on("keydown.cosmos",null).on("keyup.cosmos",null),(e=this.zoomInstance)!=null&&e.behavior&&this.zoomInstance.behavior.on("start.detect",null).on("zoom.detect",null).on("end.detect",null),(t=this.dragInstance)!=null&&t.behavior&&this.dragInstance.behavior.on("start.detect",null).on("drag.detect",null).on("end.detect",null),(i=this.fpsMonitor)==null||i.destroy(),(r=this.points)==null||r.destroy(),(s=this.lines)==null||s.destroy(),(o=this.clusters)==null||o.destroy(),(a=this.forceGravity)==null||a.destroy(),(l=this.forceCenter)==null||l.destroy(),(c=this.forceManyBody)==null||c.destroy(),(u=this.forceLinkIncoming)==null||u.destroy(),(f=this.forceLinkOutgoing)==null||f.destroy(),(h=this.forceMouse)==null||h.destroy(),this.device&&this.shouldDestroyDevice&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit(),this.device.destroy()),this.shouldDestroyDevice&&this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.attributionDivElement&&this.attributionDivElement.parentNode&&this.attributionDivElement.parentNode.removeChild(this.attributionDivElement),(d=document.getElementById("gl-bench-style"))==null||d.remove(),this.canvasD3Selection=void 0,this.attributionDivElement=void 0)}create(){var e,t,i,r,s;this._isDestroyed||this.ensureDevice(()=>this.create())||this.points&&this.lines&&(this.isPointPositionsUpdateNeeded&&this.points.updatePositions(),this.isPointColorUpdateNeeded&&this.points.updateColor(),this.isPointSizeUpdateNeeded&&this.points.updateSize(),this.isPointShapeUpdateNeeded&&this.points.updateShape(),this.isPointImageIndicesUpdateNeeded&&this.points.updateImageIndices(),this.isPointImageSizesUpdateNeeded&&this.points.updateImageSizes(),this.isLinksUpdateNeeded&&this.lines.updatePointsBuffer(),this.isLinkColorUpdateNeeded&&this.lines.updateColor(),this.isLinkWidthUpdateNeeded&&this.lines.updateWidth(),this.isLinkArrowUpdateNeeded&&this.lines.updateArrow(),this.isForceManyBodyUpdateNeeded&&((e=this.forceManyBody)==null||e.create()),this.isForceLinkUpdateNeeded&&((t=this.forceLinkIncoming)==null||t.create(Po.INCOMING),(i=this.forceLinkOutgoing)==null||i.create(Po.OUTGOING)),this.isForceCenterUpdateNeeded&&((r=this.forceCenter)==null||r.create()),this.isPointClusterUpdateNeeded&&((s=this.clusters)==null||s.create()),this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1)}flatten(e){return e.flat()}pair(e){const t=new Array(e.length/2);for(let i=0;i<e.length/2;i++)t[i]=[e[i*2],e[i*2+1]];return t}ensureDevice(e){return this.isReady?!1:(this.ready.then(()=>{this._isDestroyed||e()}).catch(t=>{console.error("Device initialization failed",t)}),!0)}validateDevice(e){const t=e.canvasContext;if(t===null||t.type==="offscreen-canvas")throw new Error("Device must have an HTMLCanvasElement canvas context. OffscreenCanvas and compute-only devices are not supported.");return t}async createDevice(e){return await om.createDevice({type:"webgl",adapters:[sg],createCanvasContext:{canvas:e,useDevicePixels:this.config.pixelRatio,autoResize:!0,width:void 0,height:void 0}})}update(e=this.store.alpha){const{graph:t}=this;this.store.pointsTextureSize=Math.ceil(Math.sqrt(t.pointsNumber??0)),this.store.linksTextureSize=Math.ceil(Math.sqrt((t.linksNumber??0)*2)),this.create(),this.initPrograms(),this.store.hoveredPoint=void 0,this.store.alpha=e}runSimulationStep(e=!1){var a,l,c,u,f,h,d,_,I,P,A,O,E,x,R,N,U,W,q;const{config:{simulationGravity:t,simulationCenter:i,enableSimulation:r},store:{isSimulationRunning:s}}=this;if(!r)return;this.isRightClickMouse&&this.config.enableRightClickRepulsion&&((a=this.forceMouse)==null||a.run(),(l=this.points)==null||l.updatePosition()),(e||s&&!(this.zoomInstance.isRunning&&!this.config.enableSimulationDuringZoom))&&(t&&((c=this.forceGravity)==null||c.run(),(u=this.points)==null||u.updatePosition()),i&&((f=this.forceCenter)==null||f.run(),(h=this.points)==null||h.updatePosition()),(d=this.forceManyBody)==null||d.run(),(_=this.points)==null||_.updatePosition(),this.store.linksTextureSize&&((I=this.forceLinkIncoming)==null||I.run(),(P=this.points)==null||P.updatePosition(),(A=this.forceLinkOutgoing)==null||A.run(),(O=this.points)==null||O.updatePosition()),(this.graph.pointClusters||this.graph.clusterPositions)&&((E=this.clusters)==null||E.run(),(x=this.points)==null||x.updatePosition()),this.store.alpha+=this.store.addAlpha(this.config.simulationDecay??V.simulation.decay),this.isRightClickMouse&&this.config.enableRightClickRepulsion&&(this.store.alpha=Math.max(this.store.alpha,.1)),this.store.simulationProgress=Math.sqrt(Math.min(1,Js/this.store.alpha)),(W=(U=this.config).onSimulationTick)==null||W.call(U,this.store.alpha,(R=this.store.hoveredPoint)==null?void 0:R.index,(N=this.store.hoveredPoint)==null?void 0:N.position)),(q=this.points)==null||q.trackPoints()}initPrograms(){var e,t,i,r,s,o;this._isDestroyed||!this.points||!this.lines||!this.clusters||(this.points.initPrograms(),this.lines.initPrograms(),(e=this.forceGravity)==null||e.initPrograms(),(t=this.forceManyBody)==null||t.initPrograms(),(i=this.forceCenter)==null||i.initPrograms(),(r=this.forceLinkIncoming)==null||r.initPrograms(),(s=this.forceLinkOutgoing)==null||s.initPrograms(),(o=this.forceMouse)==null||o.initPrograms(),this.clusters.initPrograms())}frame(){if(this._isDestroyed)return;const{store:{alpha:e,isSimulationRunning:t}}=this;e<Js&&t&&this.end(),this.requestAnimationFrameId=window.requestAnimationFrame(i=>{this.renderFrame(i),this._isDestroyed||this.frame()})}renderFrame(e){var t,i,r,s,o,a,l;if(!this._isDestroyed&&this.store.pointsTextureSize){if((t=this.fpsMonitor)==null||t.begin(),this.resizeCanvas(),this.dragInstance.isActive||this.findHoveredItem(),this.runSimulationStep(!1),this.device){const c=this.store.backgroundColor??[0,0,0,1],u=this.device.beginRenderPass({clearColor:c,clearDepth:1,clearStencil:0}),{config:{renderLinks:f}}=this;f!==!1&&!!this.store.linksTextureSize&&!!this.graph.linksNumber&&this.graph.linksNumber>0&&((i=this.lines)==null||i.draw(u)),(r=this.points)==null||r.draw(u),this.dragInstance.isActive&&((s=this.points)==null||s.drag(),(o=this.points)==null||o.drag(),(a=this.points)==null||a.trackPoints()),u.end(),this.device.submit()}(l=this.fpsMonitor)==null||l.end(e??performance.now()),this.currentEvent=void 0}}stopFrames(){this.requestAnimationFrameId&&(window.cancelAnimationFrame(this.requestAnimationFrameId),this.requestAnimationFrameId=0)}startFrames(){this._isDestroyed||(this.stopFrames(),this.frame())}end(){var e,t;this.store.isSimulationRunning=!1,this.store.simulationProgress=1,(t=(e=this.config).onSimulationEnd)==null||t.call(e),this._shouldForceHoverDetection=!0}onClick(e){var t,i,r,s,o,a,l,c,u,f;(s=(r=this.config).onClick)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointClick)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkClick)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundClick)==null||f.call(u,e)}updateMousePosition(e){if(!e)return;const t=e.offsetX??e.x,i=e.offsetY??e.y;t===void 0||i===void 0||(this.store.mousePosition=this.zoomInstance.convertScreenToSpacePosition([t,i]),this.store.screenMousePosition=[t,this.store.screenSize[1]-i])}onMouseMove(e){var t,i,r,s;this.currentEvent=e,this.updateMousePosition(e),this.isRightClickMouse=e.which===3,(s=(r=this.config).onMouseMove)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,this.currentEvent)}onContextMenu(e){var t,i,r,s,o,a,l,c,u,f;e.preventDefault(),(s=(r=this.config).onContextMenu)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointContextMenu)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkContextMenu)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundContextMenu)==null||f.call(u,e)}resizeCanvas(e=!1){var o,a,l,c;if(this._isDestroyed)return;const t=this.canvas.clientWidth,i=this.canvas.clientHeight,[r,s]=this.store.screenSize;if(e||r!==t||s!==i){const{k:u}=this.zoomInstance.eventTransform,f=this.zoomInstance.convertScreenToSpacePosition([r/2,s/2]);this.store.updateScreenSize(t,i),(o=this.canvasD3Selection)==null||o.call(this.zoomInstance.behavior.transform,this.zoomInstance.getTransform(f,u)),(a=this.points)==null||a.updateSampledPointsGrid(),(l=this.lines)==null||l.updateSampledLinksGrid(),this.store.isLinkHoveringEnabled&&((c=this.lines)==null||c.updateLinkIndexFbo())}}updateZoomDragBehaviors(){var e,t,i,r;this.config.enableDrag?(e=this.canvasD3Selection)==null||e.call(this.dragInstance.behavior):(t=this.canvasD3Selection)==null||t.call(this.dragInstance.behavior).on(".drag",null),this.config.enableZoom?(i=this.canvasD3Selection)==null||i.call(this.zoomInstance.behavior):(r=this.canvasD3Selection)==null||r.call(this.zoomInstance.behavior).on("wheel.zoom",null)}findHoveredItem(){if(this._isDestroyed||!this._isMouseOnCanvas)return;if(this._findHoveredItemExecutionCount<vy){this._findHoveredItemExecutionCount+=1;return}const e=Math.abs(this._lastMouseX-this._lastCheckedMouseX),t=Math.abs(this._lastMouseY-this._lastCheckedMouseY);if(!(!(e>Pc||t>Pc)&&!this._shouldForceHoverDetection)){if(this._lastCheckedMouseX=this._lastMouseX,this._lastCheckedMouseY=this._lastMouseY,this._shouldForceHoverDetection=!1,this._findHoveredItemExecutionCount=0,this.findHoveredPoint(),this.graph.linksNumber&&this.store.isLinkHoveringEnabled)this.findHoveredLine();else if(this.store.hoveredLinkIndex!==void 0){const r=this.store.hoveredLinkIndex!==void 0;this.store.hoveredLinkIndex=void 0,r&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(this.currentEvent)}this.updateCanvasCursor()}}findHoveredPoint(){var l,c,u,f,h;if(this._isDestroyed||!this.device||!this.points)return;this.points.findHoveredPoint();let e=!1,t=!1;const i=Me(this.device,this.points.hoveredFbo,0,0,2,2),r=i[0],s=i[1],o=i[2],a=i[3];s>0?((this.store.hoveredPoint===void 0||this.store.hoveredPoint.index!==r)&&(e=!0),this.store.hoveredPoint={index:r,position:[o,a]}):(this.store.hoveredPoint&&(t=!0),this.store.hoveredPoint=void 0),e&&this.store.hoveredPoint&&((u=(c=this.config).onPointMouseOver)==null||u.call(c,this.store.hoveredPoint.index,this.store.hoveredPoint.position,this.currentEvent,((l=this.store.selectedIndices)==null?void 0:l.includes(this.store.hoveredPoint.index))??!1)),t&&((h=(f=this.config).onPointMouseOut)==null||h.call(f,this.currentEvent))}findHoveredLine(){var s,o,a,l,c,u;if(this._isDestroyed||!this.lines)return;if(this.store.hoveredPoint){this.store.hoveredLinkIndex!==void 0&&(this.store.hoveredLinkIndex=void 0,(o=(s=this.config).onLinkMouseOut)==null||o.call(s,this.currentEvent));return}this.lines.findHoveredLine();let e=!1,t=!1;if(!this.device)return;const r=Me(this.device,this.lines.hoveredLineIndexFbo)[0];r>=0?(this.store.hoveredLinkIndex!==r&&(e=!0),this.store.hoveredLinkIndex=r):(this.store.hoveredLinkIndex!==void 0&&(t=!0),this.store.hoveredLinkIndex=void 0),e&&this.store.hoveredLinkIndex!==void 0&&((l=(a=this.config).onLinkMouseOver)==null||l.call(a,this.store.hoveredLinkIndex)),t&&((u=(c=this.config).onLinkMouseOut)==null||u.call(c,this.currentEvent))}updateCanvasCursor(){const{hoveredPointCursor:e,hoveredLinkCursor:t}=this.config;this.dragInstance.isActive?we(this.canvas).style("cursor","grabbing"):this.store.hoveredPoint?!this.config.enableDrag||this.store.isSpaceKeyPressed?we(this.canvas).style("cursor",e):we(this.canvas).style("cursor","grab"):this.store.isLinkHoveringEnabled&&this.store.hoveredLinkIndex!==void 0?we(this.canvas).style("cursor",t):we(this.canvas).style("cursor",null)}addAttribution(){var e;this.config.attribution&&(this.attributionDivElement=document.createElement("div"),this.attributionDivElement.style.cssText=`
2384
+ }`;function Av(n,e=16384){if(!(n!=null&&n.length))return null;let t=0;for(const c of n){const u=Math.max(c.width,c.height);u>t&&(t=u)}if(t===0)return console.warn("Invalid image dimensions: all images have zero width or height"),null;const i=t,r=Math.ceil(Math.sqrt(n.length));let s=r*t,o=1;s>e&&(o=e/s,t=Math.max(1,Math.floor(t*o)),s=Math.max(1,Math.floor(s*o)),console.warn(`🖼️ Atlas scaling required: Original size ${(i*r).toLocaleString()}px exceeds WebGL limit ${e.toLocaleString()}px. Scaling down to ${s.toLocaleString()}px (${Math.round(o*100)}% of original quality)`));const a=new Uint8Array(s*s*4).fill(0),l=new Float32Array(r*r*4).fill(-1);for(const[c,u]of n.entries()){const f=u.width,h=u.height;if(f===0||h===0)continue;const d=Math.min(1,t/Math.max(f,h)),_=Math.floor(f*d),I=Math.floor(h*d),P=Math.floor(c/r),O=c%r*t,E=P*t;l[c*4]=O/s,l[c*4+1]=E/s,l[c*4+2]=(O+_)/s,l[c*4+3]=(E+I)/s;for(let y=0;y<I;y++)for(let R=0;R<_;R++){const N=Math.floor(R*(f/_)),H=(Math.floor(y*(h/I))*f+N)*4,Y=((E+y)*s+(O+R))*4;a[Y]=u.data[H]??0,a[Y+1]=u.data[H+1]??0,a[Y+2]=u.data[H+2]??0,a[Y+3]=u.data[H+3]??255}}return{atlasData:a,atlasSize:s,atlasCoords:l,atlasCoordsSize:r}}class Cv extends Ot{constructor(){super(...arguments),this.imageCount=0,this.areClusterCentroidsUpToDate=!1,this.isPositionsUpToDate=!1,this.polygonPathLength=0}updatePositions(){const{device:e,store:t,data:i,config:{rescalePositions:r,enableSimulation:s}}=this,{pointsTextureSize:o}=t;if(!o||!i.pointPositions||i.pointsNumber===void 0)return;const a=o*o*4,l=new Float32Array(a),c=o*o*4*4,u=l.byteLength;u!==c&&console.error("Texture data size mismatch:",{pointsTextureSize:o,expectedBytes:c,actualBytes:u,textureDataSize:a,dataLength:l.length});let f=r;r===void 0&&!s&&(f=!0),this.shouldSkipRescale&&(f=!1),f?this.rescaleInitialNodePositions():this.shouldSkipRescale||(this.scaleX=void 0,this.scaleY=void 0),this.shouldSkipRescale=void 0;for(let _=0;_<i.pointsNumber;++_)l[_*4+0]=i.pointPositions[_*2+0],l[_*4+1]=i.pointPositions[_*2+1],l[_*4+2]=_;if(!this.currentPositionTexture||this.currentPositionTexture.width!==o||this.currentPositionTexture.height!==o?(this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.currentPositionTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.currentPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.currentPositionTexture]})):this.currentPositionTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),!this.previousPositionTexture||this.previousPositionTexture.width!==o||this.previousPositionTexture.height!==o?(this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.previousPositionTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.previousPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.previousPositionTexture]})):this.previousPositionTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.config.enableSimulation){const _=new Float32Array(o*o*4).fill(0);!this.velocityTexture||this.velocityTexture.width!==o||this.velocityTexture.height!==o?(this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.velocityTexture.copyImageData({data:_,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.velocityFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.velocityTexture]})):this.velocityTexture.copyImageData({data:_,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0})}!this.selectedTexture||this.selectedTexture.width!==o||this.selectedTexture.height!==o?(this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.selectedTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.selectedFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.selectedTexture]})):this.selectedTexture.copyImageData({data:l,bytesPerRow:te("rgba32float",o),mipLevel:0,x:0,y:0}),this.hoveredFbo||(this.hoveredFbo=e.createFramebuffer({width:2,height:2,colorAttachments:["rgba32float"]}));const h=yr(t.pointsTextureSize),d=h.byteLength;!this.drawPointIndices||this.drawPointIndices.byteLength!==d?(this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.drawPointIndices.write(h),this.drawCommand&&this.drawCommand.setAttributes({pointIndices:this.drawPointIndices}),!this.hoveredPointIndices||this.hoveredPointIndices.byteLength!==d?(this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.hoveredPointIndices.write(h),!this.sampledPointIndices||this.sampledPointIndices.byteLength!==d?(this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.sampledPointIndices.write(h),this.fillSampledPointsFboCommand&&this.fillSampledPointsFboCommand.setAttributes({pointIndices:this.sampledPointIndices}),this.updateGreyoutStatus(),this.updatePinnedStatus(),this.updateSampledPointsGrid(),this.trackPointsByIndices()}initPrograms(){var s,o,a;const{device:e,config:t,store:i,data:r}=this;(!this.imageAtlasCoordsTexture||!this.imageAtlasTexture)&&this.createAtlas(),this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),this.greyoutStatusTexture||this.updateGreyoutStatus(),t.enableSimulation&&(this.updatePositionVertexCoordBuffer||(this.updatePositionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.updatePositionUniformStore||(this.updatePositionUniformStore=new _e({updatePositionUniforms:{uniformTypes:{friction:"f32",spaceSize:"f32"},defaultUniforms:{friction:t.simulationFriction,spaceSize:i.adjustedSpaceSize}}})),this.updatePositionCommand||(this.updatePositionCommand=new pe(e,{fs:Sv,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.updatePositionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{updatePositionUniforms:this.updatePositionUniformStore.getManagedUniformBuffer(e,"updatePositionUniforms")}}))),this.dragPointVertexCoordBuffer||(this.dragPointVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.dragPointUniformStore||(this.dragPointUniformStore=new _e({dragPointUniforms:{uniformTypes:{mousePos:"vec2<f32>",index:"f32"},defaultUniforms:{mousePos:ne(i.mousePosition,[0,0]),index:((s=i.hoveredPoint)==null?void 0:s.index)??-1}}})),this.dragPointCommand||(this.dragPointCommand=new pe(e,{fs:wv,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.dragPointVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{dragPointUniforms:this.dragPointUniformStore.getManagedUniformBuffer(e,"dragPointUniforms")}})),this.drawUniformStore||(this.drawUniformStore=new _e({drawVertexUniforms:{uniformTypes:{ratio:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",greyoutColor:"vec4<f32>",backgroundColor:"vec4<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",isDarkenGreyout:"f32",skipSelected:"f32",skipUnselected:"f32",hasImages:"f32",imageCount:"f32",imageAtlasCoordsTextureSize:"f32"},defaultUniforms:{ratio:t.pixelRatio,transformationMatrix:(()=>{const l=i.transform??[1,0,0,0,1,0,0,0,1];return[l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]})(),pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),backgroundColor:Re(i.backgroundColor,[0,0,0,1]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:i.maxPointSize,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,skipSelected:0,skipUnselected:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0}},drawFragmentUniforms:{uniformTypes:{greyoutOpacity:"f32",pointOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>"},defaultUniforms:{greyoutOpacity:t.pointGreyoutOpacity??-1,pointOpacity:t.pointOpacity,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1])}}})),this.drawCommand||(this.drawCommand=new pe(e,{fs:hv,vs:dv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.drawPointIndices&&{pointIndices:this.drawPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.shapeBuffer&&{shape:this.shapeBuffer},...this.imageIndicesBuffer&&{imageIndex:this.imageIndicesBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"},{name:"color",format:"float32x4"},{name:"shape",format:"float32"},{name:"imageIndex",format:"float32"},{name:"imageSize",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawVertexUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawVertexUniforms"),drawFragmentUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawFragmentUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.findPointsOnAreaSelectionVertexCoordBuffer||(this.findPointsOnAreaSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnAreaSelectionUniformStore||(this.findPointsOnAreaSelectionUniformStore=new _e({findPointsOnAreaSelectionUniforms:{uniformTypes:{sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",selection0:"vec2<f32>",selection1:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32"},defaultUniforms:{sizeScale:t.pointSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),ratio:t.pixelRatio,transformationMatrix:i.transformationMatrix4x4,selection0:ne((o=i.selectedArea)==null?void 0:o[0],[0,0]),selection1:ne((a=i.selectedArea)==null?void 0:a[1],[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:i.maxPointSize}}})),this.findPointsOnAreaSelectionCommand||(this.findPointsOnAreaSelectionCommand=new pe(e,{fs:pv,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnAreaSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnAreaSelectionUniforms:this.findPointsOnAreaSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnAreaSelectionUniforms")}})),this.findPointsOnPolygonSelectionVertexCoordBuffer||(this.findPointsOnPolygonSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnPolygonSelectionUniformStore||(this.findPointsOnPolygonSelectionUniformStore=new _e({findPointsOnPolygonSelectionUniforms:{uniformTypes:{spaceSize:"f32",screenSize:"vec2<f32>",transformationMatrix:"mat4x4<f32>",polygonPathLength:"f32"},defaultUniforms:{spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),transformationMatrix:i.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}})),this.findPointsOnPolygonSelectionCommand||(this.findPointsOnPolygonSelectionCommand=new pe(e,{fs:mv,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnPolygonSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnPolygonSelectionUniforms:this.findPointsOnPolygonSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnPolygonSelectionUniforms")}})),this.findHoveredPointUniformStore||(this.findHoveredPointUniformStore=new _e({findHoveredPointUniforms:{uniformTypes:{pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",mousePosition:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",skipSelected:"f32",skipUnselected:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),ratio:t.pixelRatio,transformationMatrix:i.transformationMatrix4x4,mousePosition:ne(i.screenMousePosition,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:i.maxPointSize,skipSelected:0,skipUnselected:0}}})),this.findHoveredPointCommand||(this.findHoveredPointCommand=new pe(e,{fs:xv,vs:yv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"},{name:"imageSize",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findHoveredPointUniforms:this.findHoveredPointUniformStore.getManagedUniformBuffer(e,"findHoveredPointUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.fillSampledPointsUniformStore||(this.fillSampledPointsUniformStore=new _e({fillSampledPointsUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0])}}})),this.fillSampledPointsFboCommand||(this.fillSampledPointsFboCommand=new pe(e,{fs:vv,vs:bv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.sampledPointIndices&&{pointIndices:this.sampledPointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledPointsUniforms:this.fillSampledPointsUniformStore.getManagedUniformBuffer(e,"fillSampledPointsUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})),this.drawHighlightedVertexCoordBuffer||(this.drawHighlightedVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.drawHighlightedUniformStore||(this.drawHighlightedUniformStore=new _e({drawHighlightedUniforms:{uniformTypes:{size:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",scalePointsOnZoom:"f32",pointIndex:"f32",maxPointSize:"f32",color:"vec4<f32>",universalPointOpacity:"f32",greyoutOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>",greyoutColor:"vec4<f32>",width:"f32"},defaultUniforms:{size:1,transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:i.adjustedSpaceSize,screenSize:ne(i.screenSize,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,pointIndex:-1,maxPointSize:i.maxPointSize,color:[0,0,0,1],universalPointOpacity:t.pointOpacity,greyoutOpacity:t.pointGreyoutOpacity??-1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),width:.85}}})),this.drawHighlightedCommand||(this.drawHighlightedCommand=new pe(e,{fs:gv,vs:_v,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.drawHighlightedVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawHighlightedUniforms:this.drawHighlightedUniformStore.getManagedUniformBuffer(e,"drawHighlightedUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.trackPointsVertexCoordBuffer||(this.trackPointsVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.trackPointsUniformStore||(this.trackPointsUniformStore=new _e({trackPointsUniforms:{uniformTypes:{pointsTextureSize:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0}}})),this.trackPointsCommand||(this.trackPointsCommand=new pe(e,{fs:Tv,vs:nt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.trackPointsVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{trackPointsUniforms:this.trackPointsUniformStore.getManagedUniformBuffer(e,"trackPointsUniforms")}}))}updateColor(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=i.pointColors,s=r.byteLength;!this.colorBuffer||this.colorBuffer.byteLength!==s?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({color:this.colorBuffer})}updateGreyoutStatus(){const{device:e,store:{selectedIndices:t,pointsTextureSize:i}}=this;if(!i)return;const r=new Float32Array(i*i*4).fill(t?1:0);if(t)for(const s of t)r[s*4]=0;!this.greyoutStatusTexture||this.greyoutStatusTexture.width!==i||this.greyoutStatusTexture.height!==i?(this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=e.createTexture({width:i,height:i,format:"rgba32float"}),this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",i),mipLevel:0,x:0,y:0})):this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",i),mipLevel:0,x:0,y:0})}updatePinnedStatus(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=new Float32Array(t*t*4).fill(0);if(i.inputPinnedPoints&&i.pointsNumber!==void 0)for(const s of i.inputPinnedPoints)s>=0&&s<i.pointsNumber&&(r[s*4]=1);!this.pinnedStatusTexture||this.pinnedStatusTexture.width!==t||this.pinnedStatusTexture.height!==t?(this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",t),mipLevel:0,x:0,y:0})):this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",t),mipLevel:0,x:0,y:0})}updateSize(){var a;const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t||i.pointsNumber===void 0||i.pointSizes===void 0)return;const r=i.pointSizes,s=r.byteLength;!this.sizeBuffer||this.sizeBuffer.byteLength!==s?(this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.sizeBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({size:this.sizeBuffer});const o=new Float32Array(t*t*4);for(let l=0;l<i.pointsNumber;l++){const c=i.pointSizes[l],u=((a=i.pointImageSizes)==null?void 0:a[l])??c;o[l*4]=Math.max(c,u)}!this.sizeTexture||this.sizeTexture.width!==t||this.sizeTexture.height!==t?(this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.sizeTexture.copyImageData({data:o,bytesPerRow:te("rgba32float",t),mipLevel:0,x:0,y:0})):this.sizeTexture.copyImageData({data:o,bytesPerRow:te("rgba32float",t),mipLevel:0,x:0,y:0})}updateShape(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointShapes===void 0)return;const i=t.pointShapes,r=i.byteLength;!this.shapeBuffer||this.shapeBuffer.byteLength!==r?(this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.shapeBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({shape:this.shapeBuffer})}updateImageIndices(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageIndices===void 0)return;const i=t.pointImageIndices,r=i.byteLength;!this.imageIndicesBuffer||this.imageIndicesBuffer.byteLength!==r?(this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageIndicesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageIndex:this.imageIndicesBuffer})}updateImageSizes(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageSizes===void 0)return;const i=t.pointImageSizes,r=i.byteLength;!this.imageSizesBuffer||this.imageSizesBuffer.byteLength!==r?(this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageSizesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageSize:this.imageSizesBuffer}),this.findHoveredPointCommand&&this.findHoveredPointCommand.setAttributes({imageSize:this.imageSizesBuffer})}createAtlas(){var c;const{device:e,data:t,store:i}=this;if(!((c=t.inputImageData)!=null&&c.length)){this.imageCount=0,this.imageAtlasCoordsTextureSize=0,this.imageAtlasCoordsTexture||(this.imageAtlasCoordsTexture=e.createTexture({data:new Float32Array(4).fill(0),width:1,height:1,format:"rgba32float"})),this.imageAtlasTexture||(this.imageAtlasTexture=e.createTexture({data:new Uint8Array(4).fill(0),width:1,height:1,format:"rgba8unorm"}));return}const r=Av(t.inputImageData,i.webglMaxTextureSize);if(!r){console.warn("Failed to create atlas from image data");return}this.imageCount=t.inputImageData.length;const{atlasData:s,atlasSize:o,atlasCoords:a,atlasCoordsSize:l}=r;this.imageAtlasCoordsTextureSize=l,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=e.createTexture({width:o,height:o,format:"rgba8unorm"}),this.imageAtlasTexture.copyImageData({data:s,bytesPerRow:te("rgba8unorm",o),rowsPerImage:o,mipLevel:0,x:0,y:0}),this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=e.createTexture({width:l,height:l,format:"rgba32float"}),this.imageAtlasCoordsTexture.copyImageData({data:a,bytesPerRow:te("rgba32float",l),rowsPerImage:l,mipLevel:0,x:0,y:0})}updateSampledPointsGrid(){const{store:{screenSize:e},config:{pointSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=wt.pointSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);s===0||o===0||(!this.sampledPointsFbo||this.sampledPointsFbo.width!==s||this.sampledPointsFbo.height!==o)&&(this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}trackPoints(){var t;if(!((t=this.trackedIndices)!=null&&t.length)||!this.trackPointsCommand||!this.trackPointsUniformStore||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.trackedIndicesTexture||this.trackedIndicesTexture.destroyed)return;this.trackPointsUniformStore.setUniforms({trackPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0}}),this.trackPointsCommand.setBindings({positionsTexture:this.currentPositionTexture,trackedIndices:this.trackedIndicesTexture});const e=this.device.beginRenderPass({framebuffer:this.trackedPositionsFbo});this.trackPointsCommand.draw(e),e.end()}draw(e){var a,l,c,u;const{data:t,config:i,store:r}=this;if(this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),!this.drawCommand||!this.drawUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed||(!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)&&(this.createAtlas(),!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)||this.imageAtlasTexture.destroyed||this.imageAtlasCoordsTexture.destroyed||!t.pointsNumber||t.pointsNumber===0||!r.screenSize||r.screenSize[0]===0||r.screenSize[1]===0)return;this.drawCommand.setVertexCount(t.pointsNumber);const s={ratio:i.pixelRatio,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),greyoutColor:Re(r.greyoutPointColor,[-1,-1,-1,-1]),backgroundColor:Re(r.backgroundColor,[0,0,0,1]),scalePointsOnZoom:i.scalePointsOnZoom?1:0,maxPointSize:r.maxPointSize,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0},o={greyoutOpacity:i.pointGreyoutOpacity??-1,pointOpacity:i.pointOpacity,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1])};if(r.selectedIndices&&r.selectedIndices.length>0?(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:1,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e),this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:1},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)):(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)),i.renderHoveredPointRing&&r.hoveredPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const f=((a=t.pointSizes)==null?void 0:a[r.hoveredPoint.index])??1,h=((l=t.pointImageSizes)==null?void 0:l[r.hoveredPoint.index])??f;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:Math.max(f,h),transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom?1:0,pointIndex:r.hoveredPoint.index,maxPointSize:r.maxPointSize,color:Re(r.hoveredPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}if(r.focusedPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const f=((c=t.pointSizes)==null?void 0:c[r.focusedPoint.index])??1,h=((u=t.pointImageSizes)==null?void 0:u[r.focusedPoint.index])??f;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:Math.max(f,h),transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom?1:0,pointIndex:r.focusedPoint.index,maxPointSize:r.maxPointSize,color:Re(r.focusedPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}}updatePosition(){if(!this.updatePositionCommand||!this.updatePositionUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.velocityTexture||this.velocityTexture.destroyed||!this.pinnedStatusTexture||this.pinnedStatusTexture.destroyed)return;this.updatePositionUniformStore.setUniforms({updatePositionUniforms:{friction:this.config.simulationFriction,spaceSize:this.store.adjustedSpaceSize}}),this.updatePositionCommand.setBindings({positionsTexture:this.previousPositionTexture,velocity:this.velocityTexture,pinnedStatusTexture:this.pinnedStatusTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.updatePositionCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}drag(){var t;if(!this.dragPointCommand||!this.dragPointUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed)return;this.dragPointUniformStore.setUniforms({dragPointUniforms:{mousePos:ne(this.store.mousePosition,[0,0]),index:((t=this.store.hoveredPoint)==null?void 0:t.index)??-1}}),this.dragPointCommand.setBindings({positionsTexture:this.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.dragPointCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}findPointsOnAreaSelection(){var t,i;if(!this.findPointsOnAreaSelectionCommand||!this.findPointsOnAreaSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.sizeTexture||this.sizeTexture.destroyed)return;this.findPointsOnAreaSelectionUniformStore.setUniforms({findPointsOnAreaSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),sizeScale:this.config.pointSizeScale,transformationMatrix:this.store.transformationMatrix4x4,ratio:this.config.pixelRatio,selection0:ne((t=this.store.selectedArea)==null?void 0:t[0],[0,0]),selection1:ne((i=this.store.selectedArea)==null?void 0:i[1],[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom?1:0,maxPointSize:this.store.maxPointSize}}),this.findPointsOnAreaSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,pointSize:this.sizeTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnAreaSelectionCommand.draw(e),e.end()}findPointsOnPolygonSelection(){if(!this.findPointsOnPolygonSelectionCommand||!this.findPointsOnPolygonSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.polygonPathTexture||this.polygonPathTexture.destroyed)return;this.findPointsOnPolygonSelectionUniformStore.setUniforms({findPointsOnPolygonSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),transformationMatrix:this.store.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}),this.findPointsOnPolygonSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,polygonPathTexture:this.polygonPathTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnPolygonSelectionCommand.draw(e),e.end()}updatePolygonPath(e){const{device:t}=this;if(this.polygonPathLength=e.length,e.length===0){this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0;return}const i=Math.ceil(Math.sqrt(e.length)),r=new Float32Array(i*i*4);for(const[s,o]of e.entries()){const[a,l]=o;r[s*4]=a,r[s*4+1]=l,r[s*4+2]=0,r[s*4+3]=0}!this.polygonPathTexture||this.polygonPathTexture.width!==i||this.polygonPathTexture.height!==i?(this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=t.createTexture({width:i,height:i,format:"rgba32float"}),this.polygonPathTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",i),mipLevel:0,x:0,y:0})):this.polygonPathTexture.copyImageData({data:r,bytesPerRow:te("rgba32float",i),mipLevel:0,x:0,y:0})}findHoveredPoint(){if(!this.hoveredFbo||this.hoveredFbo.destroyed||!this.findHoveredPointCommand||!this.findHoveredPointUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||(this.greyoutStatusTexture||this.updateGreyoutStatus(),!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed))return;this.findHoveredPointCommand.setVertexCount(this.data.pointsNumber??0),this.findHoveredPointCommand.setAttributes({...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}});const e={ratio:this.config.pixelRatio,sizeScale:this.config.pointSizeScale,pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom?1:0,mousePosition:ne(this.store.screenMousePosition,[0,0]),maxPointSize:this.store.maxPointSize},t={positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture},i=this.device.beginRenderPass({framebuffer:this.hoveredFbo,clearColor:[0,0,0,0]});this.store.selectedIndices&&this.store.selectedIndices.length>0?(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:1,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i),this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:1}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)):(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)),i.end()}trackPointsByIndices(e){const{store:{pointsTextureSize:t},device:i}=this;if(this.trackedIndices=e,this.trackedPositions=void 0,this.isPositionsUpToDate=!1,!(e!=null&&e.length)||!t)return;const r=Math.ceil(Math.sqrt(e.length)),s=new Float32Array(r*r*4).fill(-1);for(const[o,a]of e.entries())a!==void 0&&(s[o*4]=a%t,s[o*4+1]=Math.floor(a/t),s[o*4+2]=0,s[o*4+3]=0);!this.trackedIndicesTexture||this.trackedIndicesTexture.width!==r||this.trackedIndicesTexture.height!==r?(this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=i.createTexture({width:r,height:r,format:"rgba32float"}),this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0})):this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:te("rgba32float",r),mipLevel:0,x:0,y:0}),(!this.trackedPositionsFbo||this.trackedPositionsFbo.width!==r||this.trackedPositionsFbo.height!==r)&&(this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=i.createFramebuffer({width:r,height:r,colorAttachments:["rgba32float"]})),this.trackPoints()}getTrackedPositionsMap(){if(!this.trackedIndices)return new Map;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this;if((!e||!t)&&this.isPositionsUpToDate&&this.trackedPositions)return this.trackedPositions;if(!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return new Map;const i=Me(this.device,this.trackedPositionsFbo),r=new Map;for(let s=0;s<i.length/4;s+=1){const o=i[s*4],a=i[s*4+1],l=this.trackedIndices[s];o!==void 0&&a!==void 0&&l!==void 0&&r.set(l,[o,a])}return(!e||!t)&&(this.trackedPositions=r,this.isPositionsUpToDate=!0),r}getSampledPointPositionsMap(){const e=new Map;if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return e;if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return e;this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const i=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(i),i.end()}const t=Me(this.device,this.sampledPointsFbo);for(let i=0;i<t.length/4;i++){const r=t[i*4],s=!!t[i*4+1],o=t[i*4+2],a=t[i*4+3];s&&r!==void 0&&o!==void 0&&a!==void 0&&e.set(r,[o,a])}return e}getSampledPoints(){const e=[],t=[];if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return{indices:e,positions:t};if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return{indices:e,positions:t};this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(r),r.end()}const i=Me(this.device,this.sampledPointsFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=!!i[r*4+1],a=i[r*4+2],l=i[r*4+3];o&&s!==void 0&&a!==void 0&&l!==void 0&&(e.push(s),t.push(a,l))}return{indices:e,positions:t}}getTrackedPositionsArray(){const e=[];if(!this.trackedIndices||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return e;e.length=this.trackedIndices.length*2;const t=Me(this.device,this.trackedPositionsFbo);for(let i=0;i<t.length/4;i+=1){const r=t[i*4],s=t[i*4+1],o=this.trackedIndices[i];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d,_,I,P,A,O;(e=this.drawCommand)==null||e.destroy(),this.drawCommand=void 0,(t=this.drawHighlightedCommand)==null||t.destroy(),this.drawHighlightedCommand=void 0,(i=this.updatePositionCommand)==null||i.destroy(),this.updatePositionCommand=void 0,(r=this.dragPointCommand)==null||r.destroy(),this.dragPointCommand=void 0,(s=this.findPointsOnAreaSelectionCommand)==null||s.destroy(),this.findPointsOnAreaSelectionCommand=void 0,(o=this.findPointsOnPolygonSelectionCommand)==null||o.destroy(),this.findPointsOnPolygonSelectionCommand=void 0,(a=this.findHoveredPointCommand)==null||a.destroy(),this.findHoveredPointCommand=void 0,(l=this.fillSampledPointsFboCommand)==null||l.destroy(),this.fillSampledPointsFboCommand=void 0,(c=this.trackPointsCommand)==null||c.destroy(),this.trackPointsCommand=void 0,this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionFbo=void 0,this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionFbo=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedFbo=void 0,this.hoveredFbo&&!this.hoveredFbo.destroyed&&this.hoveredFbo.destroy(),this.hoveredFbo=void 0,this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=void 0,this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=void 0,this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionTexture=void 0,this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionTexture=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=void 0,this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedTexture=void 0,this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=void 0,this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=void 0,this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=void 0,this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=void 0,this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=void 0,this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=void 0,(u=this.updatePositionUniformStore)==null||u.destroy(),this.updatePositionUniformStore=void 0,(f=this.dragPointUniformStore)==null||f.destroy(),this.dragPointUniformStore=void 0,(h=this.drawUniformStore)==null||h.destroy(),this.drawUniformStore=void 0,(d=this.findPointsOnAreaSelectionUniformStore)==null||d.destroy(),this.findPointsOnAreaSelectionUniformStore=void 0,(_=this.findPointsOnPolygonSelectionUniformStore)==null||_.destroy(),this.findPointsOnPolygonSelectionUniformStore=void 0,(I=this.findHoveredPointUniformStore)==null||I.destroy(),this.findHoveredPointUniformStore=void 0,(P=this.fillSampledPointsUniformStore)==null||P.destroy(),this.fillSampledPointsUniformStore=void 0,(A=this.drawHighlightedUniformStore)==null||A.destroy(),this.drawHighlightedUniformStore=void 0,(O=this.trackPointsUniformStore)==null||O.destroy(),this.trackPointsUniformStore=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=void 0,this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=void 0,this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=void 0,this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=void 0,this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=void 0,this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=void 0,this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=void 0,this.updatePositionVertexCoordBuffer&&!this.updatePositionVertexCoordBuffer.destroyed&&this.updatePositionVertexCoordBuffer.destroy(),this.updatePositionVertexCoordBuffer=void 0,this.dragPointVertexCoordBuffer&&!this.dragPointVertexCoordBuffer.destroyed&&this.dragPointVertexCoordBuffer.destroy(),this.dragPointVertexCoordBuffer=void 0,this.findPointsOnAreaSelectionVertexCoordBuffer&&!this.findPointsOnAreaSelectionVertexCoordBuffer.destroyed&&this.findPointsOnAreaSelectionVertexCoordBuffer.destroy(),this.findPointsOnAreaSelectionVertexCoordBuffer=void 0,this.findPointsOnPolygonSelectionVertexCoordBuffer&&!this.findPointsOnPolygonSelectionVertexCoordBuffer.destroyed&&this.findPointsOnPolygonSelectionVertexCoordBuffer.destroy(),this.findPointsOnPolygonSelectionVertexCoordBuffer=void 0,this.drawHighlightedVertexCoordBuffer&&!this.drawHighlightedVertexCoordBuffer.destroyed&&this.drawHighlightedVertexCoordBuffer.destroy(),this.drawHighlightedVertexCoordBuffer=void 0,this.trackPointsVertexCoordBuffer&&!this.trackPointsVertexCoordBuffer.destroyed&&this.trackPointsVertexCoordBuffer.destroy(),this.trackPointsVertexCoordBuffer=void 0}swapFbo(){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionFbo||this.previousPositionFbo.destroyed)return;const e=this.previousPositionTexture,t=this.previousPositionFbo;this.previousPositionTexture=this.currentPositionTexture,this.previousPositionFbo=this.currentPositionFbo,this.currentPositionTexture=e,this.currentPositionFbo=t,this.areClusterCentroidsUpToDate=!1}rescaleInitialNodePositions(){const{config:{spaceSize:e}}=this;if(!this.data.pointPositions||!e)return;const t=this.data.pointPositions,i=t.length/2;let r=1/0,s=-1/0,o=1/0,a=-1/0;for(let A=0;A<t.length;A+=2){const O=t[A],E=t[A+1];r=Math.min(r,O),s=Math.max(s,O),o=Math.min(o,E),a=Math.max(a,E)}const l=s-r,c=a-o,u=Math.max(l,c);if(u>e){this.scaleX=void 0,this.scaleY=void 0;return}const f=e*e*.001,h=i>f?e*Math.max(1.2,Math.sqrt(i)/e):e*.1,d=h/u,_=(e-h)/2,I=(u-l)/2*d+_,P=(u-c)/2*d+_;this.scaleX=A=>(A-r)*d+I,this.scaleY=A=>(A-o)*d+P;for(let A=0;A<i;A++)this.data.pointPositions[A*2]=this.scaleX(t[A*2]),this.data.pointPositions[A*2+1]=this.scaleY(t[A*2+1])}}const Iv={passive:!1},ti={capture:!0,passive:!1};function ko(n){n.stopImmediatePropagation()}function vn(n){n.preventDefault(),n.stopImmediatePropagation()}function Tu(n){var e=n.document.documentElement,t=we(n).on("dragstart.drag",vn,ti);"onselectstart"in e?t.on("selectstart.drag",vn,ti):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function wu(n,e){var t=n.document.documentElement,i=we(n).on("dragstart.drag",null);e&&(i.on("click.drag",vn,ti),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in t?i.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}const vr=n=>()=>n;function Do(n,{sourceEvent:e,subject:t,target:i,identifier:r,active:s,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:t,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}Do.prototype.on=function(){var n=this._.on.apply(this._,arguments);return n===this._?this:n};function Pv(n){return!n.ctrlKey&&!n.button}function Ev(){return this.parentNode}function Rv(n,e){return e??{x:n.x,y:n.y}}function kv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Dv(){var n=Pv,e=Ev,t=Rv,i=kv,r={},s=ui("start","drag","end"),o=0,a,l,c,u,f=0;function h(y){y.on("mousedown.drag",d).filter(i).on("touchstart.drag",P).on("touchmove.drag",A,Iv).on("touchend.drag touchcancel.drag",O).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(y,R){if(!(u||!n.call(this,y,R))){var N=E(this,e.call(this,y,R),y,R,"mouse");N&&(we(y.view).on("mousemove.drag",_,ti).on("mouseup.drag",I,ti),Tu(y.view),ko(y),c=!1,a=y.clientX,l=y.clientY,N("start",y))}}function _(y){if(vn(y),!c){var R=y.clientX-a,N=y.clientY-l;c=R*R+N*N>f}r.mouse("drag",y)}function I(y){we(y.view).on("mousemove.drag mouseup.drag",null),wu(y.view,c),vn(y),r.mouse("end",y)}function P(y,R){if(n.call(this,y,R)){var N=y.changedTouches,U=e.call(this,y,R),H=N.length,Y,Z;for(Y=0;Y<H;++Y)(Z=E(this,U,y,R,N[Y].identifier,N[Y]))&&(ko(y),Z("start",y,N[Y]))}}function A(y){var R=y.changedTouches,N=R.length,U,H;for(U=0;U<N;++U)(H=r[R[U].identifier])&&(vn(y),H("drag",y,R[U]))}function O(y){var R=y.changedTouches,N=R.length,U,H;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),U=0;U<N;++U)(H=r[R[U].identifier])&&(ko(y),H("end",y,R[U]))}function E(y,R,N,U,H,Y){var Z=s.copy(),B=vt(Y||N,R),he,ie,C;if((C=t.call(y,new Do("beforestart",{sourceEvent:N,target:h,identifier:H,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:Z}),U))!=null)return he=C.x-B[0]||0,ie=C.y-B[1]||0,function V(F,W,K){var q=B,G;switch(F){case"start":r[H]=V,G=o++;break;case"end":delete r[H],--o;case"drag":B=vt(K||W,R),G=o;break}Z.call(F,y,new Do(F,{sourceEvent:W,subject:C,target:h,identifier:H,active:G,x:B[0]+he,y:B[1]+ie,dx:B[0]-q[0],dy:B[1]-q[1],dispatch:Z}),U)}}return h.filter=function(y){return arguments.length?(n=typeof y=="function"?y:vr(!!y),h):n},h.container=function(y){return arguments.length?(e=typeof y=="function"?y:vr(y),h):e},h.subject=function(y){return arguments.length?(t=typeof y=="function"?y:vr(y),h):t},h.touchable=function(y){return arguments.length?(i=typeof y=="function"?y:vr(!!y),h):i},h.on=function(){var y=s.on.apply(s,arguments);return y===s?h:y},h.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,h):Math.sqrt(f)},h}const br=n=>()=>n;function Fv(n,{sourceEvent:e,target:t,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function Pt(n,e,t){this.k=n,this.x=e,this.y=t}Pt.prototype={constructor:Pt,scale:function(n){return n===1?this:new Pt(this.k*n,this.x,this.y)},translate:function(n,e){return n===0&e===0?this:new Pt(this.k,this.x+this.k*n,this.y+this.k*e)},apply:function(n){return[n[0]*this.k+this.x,n[1]*this.k+this.y]},applyX:function(n){return n*this.k+this.x},applyY:function(n){return n*this.k+this.y},invert:function(n){return[(n[0]-this.x)/this.k,(n[1]-this.y)/this.k]},invertX:function(n){return(n-this.x)/this.k},invertY:function(n){return(n-this.y)/this.k},rescaleX:function(n){return n.copy().domain(n.range().map(this.invertX,this).map(n.invert,n))},rescaleY:function(n){return n.copy().domain(n.range().map(this.invertY,this).map(n.invert,n))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ni=new Pt(1,0,0);Pt.prototype;function Fo(n){n.stopImmediatePropagation()}function ii(n){n.preventDefault(),n.stopImmediatePropagation()}function Mv(n){return(!n.ctrlKey||n.type==="wheel")&&!n.button}function Nv(){var n=this;return n instanceof SVGElement?(n=n.ownerSVGElement||n,n.hasAttribute("viewBox")?(n=n.viewBox.baseVal,[[n.x,n.y],[n.x+n.width,n.y+n.height]]):[[0,0],[n.width.baseVal.value,n.height.baseVal.value]]):[[0,0],[n.clientWidth,n.clientHeight]]}function Au(){return this.__zoom||ni}function Ov(n){return-n.deltaY*(n.deltaMode===1?.05:n.deltaMode?1:.002)*(n.ctrlKey?10:1)}function Bv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Uv(n,e,t){var i=n.invertX(e[0][0])-t[0][0],r=n.invertX(e[1][0])-t[1][0],s=n.invertY(e[0][1])-t[0][1],o=n.invertY(e[1][1])-t[1][1];return n.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function zv(){var n=Mv,e=Nv,t=Uv,i=Ov,r=Bv,s=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=hd,c=ui("start","zoom","end"),u,f,h,d=500,_=150,I=0,P=10;function A(C){C.property("__zoom",Au).on("wheel.zoom",H,{passive:!1}).on("mousedown.zoom",Y).on("dblclick.zoom",Z).filter(r).on("touchstart.zoom",B).on("touchmove.zoom",he).on("touchend.zoom touchcancel.zoom",ie).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.transform=function(C,V,F,W){var K=C.selection?C.selection():C;K.property("__zoom",Au),C!==K?R(C,V,F,W):K.interrupt().each(function(){N(this,arguments).event(W).start().zoom(null,typeof V=="function"?V.apply(this,arguments):V).end()})},A.scaleBy=function(C,V,F,W){A.scaleTo(C,function(){var K=this.__zoom.k,q=typeof V=="function"?V.apply(this,arguments):V;return K*q},F,W)},A.scaleTo=function(C,V,F,W){A.transform(C,function(){var K=e.apply(this,arguments),q=this.__zoom,G=F==null?y(K):typeof F=="function"?F.apply(this,arguments):F,J=q.invert(G),me=typeof V=="function"?V.apply(this,arguments):V;return t(E(O(q,me),G,J),K,o)},F,W)},A.translateBy=function(C,V,F,W){A.transform(C,function(){return t(this.__zoom.translate(typeof V=="function"?V.apply(this,arguments):V,typeof F=="function"?F.apply(this,arguments):F),e.apply(this,arguments),o)},null,W)},A.translateTo=function(C,V,F,W,K){A.transform(C,function(){var q=e.apply(this,arguments),G=this.__zoom,J=W==null?y(q):typeof W=="function"?W.apply(this,arguments):W;return t(ni.translate(J[0],J[1]).scale(G.k).translate(typeof V=="function"?-V.apply(this,arguments):-V,typeof F=="function"?-F.apply(this,arguments):-F),q,o)},W,K)};function O(C,V){return V=Math.max(s[0],Math.min(s[1],V)),V===C.k?C:new Pt(V,C.x,C.y)}function E(C,V,F){var W=V[0]-F[0]*C.k,K=V[1]-F[1]*C.k;return W===C.x&&K===C.y?C:new Pt(C.k,W,K)}function y(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function R(C,V,F,W){C.on("start.zoom",function(){N(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(W).end()}).tween("zoom",function(){var K=this,q=arguments,G=N(K,q).event(W),J=e.apply(K,q),me=F==null?y(J):typeof F=="function"?F.apply(K,q):F,ue=Math.max(J[1][0]-J[0][0],J[1][1]-J[0][1]),Se=K.__zoom,re=typeof V=="function"?V.apply(K,q):V,$e=l(Se.invert(me).concat(ue/Se.k),re.invert(me).concat(ue/re.k));return function(Be){if(Be===1)Be=re;else{var Ee=$e(Be),bn=ue/Ee[2];Be=new Pt(bn,me[0]-Ee[0]*bn,me[1]-Ee[1]*bn)}G.zoom(null,Be)}})}function N(C,V,F){return!F&&C.__zooming||new U(C,V)}function U(C,V){this.that=C,this.args=V,this.active=0,this.sourceEvent=null,this.extent=e.apply(C,V),this.taps=0}U.prototype={event:function(C){return C&&(this.sourceEvent=C),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(C,V){return this.mouse&&C!=="mouse"&&(this.mouse[1]=V.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=V.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=V.invert(this.touch1[0])),this.that.__zoom=V,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var V=we(this.that).datum();c.call(C,this.that,new Fv(C,{sourceEvent:this.sourceEvent,target:A,transform:this.that.__zoom,dispatch:c}),V)}};function H(C,...V){if(!n.apply(this,arguments))return;var F=N(this,V).event(C),W=this.__zoom,K=Math.max(s[0],Math.min(s[1],W.k*Math.pow(2,i.apply(this,arguments)))),q=vt(C);if(F.wheel)(F.mouse[0][0]!==q[0]||F.mouse[0][1]!==q[1])&&(F.mouse[1]=W.invert(F.mouse[0]=q)),clearTimeout(F.wheel);else{if(W.k===K)return;F.mouse=[q,W.invert(q)],yi(this),F.start()}ii(C),F.wheel=setTimeout(G,_),F.zoom("mouse",t(E(O(W,K),F.mouse[0],F.mouse[1]),F.extent,o));function G(){F.wheel=null,F.end()}}function Y(C,...V){if(h||!n.apply(this,arguments))return;var F=C.currentTarget,W=N(this,V,!0).event(C),K=we(C.view).on("mousemove.zoom",me,!0).on("mouseup.zoom",ue,!0),q=vt(C,F),G=C.clientX,J=C.clientY;Tu(C.view),Fo(C),W.mouse=[q,this.__zoom.invert(q)],yi(this),W.start();function me(Se){if(ii(Se),!W.moved){var re=Se.clientX-G,$e=Se.clientY-J;W.moved=re*re+$e*$e>I}W.event(Se).zoom("mouse",t(E(W.that.__zoom,W.mouse[0]=vt(Se,F),W.mouse[1]),W.extent,o))}function ue(Se){K.on("mousemove.zoom mouseup.zoom",null),wu(Se.view,W.moved),ii(Se),W.event(Se).end()}}function Z(C,...V){if(n.apply(this,arguments)){var F=this.__zoom,W=vt(C.changedTouches?C.changedTouches[0]:C,this),K=F.invert(W),q=F.k*(C.shiftKey?.5:2),G=t(E(O(F,q),W,K),e.apply(this,V),o);ii(C),a>0?we(this).transition().duration(a).call(R,G,W,C):we(this).call(A.transform,G,W,C)}}function B(C,...V){if(n.apply(this,arguments)){var F=C.touches,W=F.length,K=N(this,V,C.changedTouches.length===W).event(C),q,G,J,me;for(Fo(C),G=0;G<W;++G)J=F[G],me=vt(J,this),me=[me,this.__zoom.invert(me),J.identifier],K.touch0?!K.touch1&&K.touch0[2]!==me[2]&&(K.touch1=me,K.taps=0):(K.touch0=me,q=!0,K.taps=1+!!u);u&&(u=clearTimeout(u)),q&&(K.taps<2&&(f=me[0],u=setTimeout(function(){u=null},d)),yi(this),K.start())}}function he(C,...V){if(this.__zooming){var F=N(this,V).event(C),W=C.changedTouches,K=W.length,q,G,J,me;for(ii(C),q=0;q<K;++q)G=W[q],J=vt(G,this),F.touch0&&F.touch0[2]===G.identifier?F.touch0[0]=J:F.touch1&&F.touch1[2]===G.identifier&&(F.touch1[0]=J);if(G=F.that.__zoom,F.touch1){var ue=F.touch0[0],Se=F.touch0[1],re=F.touch1[0],$e=F.touch1[1],Be=(Be=re[0]-ue[0])*Be+(Be=re[1]-ue[1])*Be,Ee=(Ee=$e[0]-Se[0])*Ee+(Ee=$e[1]-Se[1])*Ee;G=O(G,Math.sqrt(Be/Ee)),J=[(ue[0]+re[0])/2,(ue[1]+re[1])/2],me=[(Se[0]+$e[0])/2,(Se[1]+$e[1])/2]}else if(F.touch0)J=F.touch0[0],me=F.touch0[1];else return;F.zoom("touch",t(E(G,J,me),F.extent,o))}}function ie(C,...V){if(this.__zooming){var F=N(this,V).event(C),W=C.changedTouches,K=W.length,q,G;for(Fo(C),h&&clearTimeout(h),h=setTimeout(function(){h=null},d),q=0;q<K;++q)G=W[q],F.touch0&&F.touch0[2]===G.identifier?delete F.touch0:F.touch1&&F.touch1[2]===G.identifier&&delete F.touch1;if(F.touch1&&!F.touch0&&(F.touch0=F.touch1,delete F.touch1),F.touch0)F.touch0[1]=this.__zoom.invert(F.touch0[0]);else if(F.end(),F.taps===2&&(G=vt(G,this),Math.hypot(f[0]-G[0],f[1]-G[1])<P)){var J=we(this).on("dblclick.zoom");J&&J.apply(this,arguments)}}}return A.wheelDelta=function(C){return arguments.length?(i=typeof C=="function"?C:br(+C),A):i},A.filter=function(C){return arguments.length?(n=typeof C=="function"?C:br(!!C),A):n},A.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:br(!!C),A):r},A.extent=function(C){return arguments.length?(e=typeof C=="function"?C:br([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),A):e},A.scaleExtent=function(C){return arguments.length?(s[0]=+C[0],s[1]=+C[1],A):[s[0],s[1]]},A.translateExtent=function(C){return arguments.length?(o[0][0]=+C[0][0],o[1][0]=+C[1][0],o[0][1]=+C[0][1],o[1][1]=+C[1][1],A):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},A.constrain=function(C){return arguments.length?(t=C,A):t},A.duration=function(C){return arguments.length?(a=+C,A):a},A.interpolate=function(C){return arguments.length?(l=C,A):l},A.on=function(){var C=c.on.apply(c,arguments);return C===c?A:C},A.clickDistance=function(C){return arguments.length?(I=(C=+C)*C,A):Math.sqrt(I)},A.tapDistance=function(C){return arguments.length?(P=+C,A):P},A}class Lv{constructor(e,t){this.eventTransform=ni,this.behavior=zv().scaleExtent([.001,1/0]).on("start",i=>{var s,o;this.isRunning=!0;const r=!!i.sourceEvent;r&&(this.shouldEnableSimulationDuringZoomOverride=void 0),(o=(s=this.config).onZoomStart)==null||o.call(s,i,r)}).on("zoom",i=>{var h,d;this.eventTransform=i.transform;const{eventTransform:{x:r,y:s,k:o},store:{transform:a,screenSize:l}}=this,c=l[0],u=l[1];if(!c||!u)return;wx(a,c,u),oc(a,a,[r,s]),js(a,a,[o,o]),oc(a,a,[c/2,u/2]),js(a,a,[c/2,u/2]),js(a,a,[1,-1]);const f=!!i.sourceEvent;(d=(h=this.config).onZoom)==null||d.call(h,i,f)}).on("end",i=>{var s,o;this.isRunning=!1;const r=!!i.sourceEvent;(o=(s=this.config).onZoomEnd)==null||o.call(s,i,r)}),this.isRunning=!1,this.shouldEnableSimulationDuringZoomOverride=void 0,this.store=e,this.config=t}getTransform(e,t,i=.1){if(e.length===0)return this.eventTransform;const{store:{screenSize:r}}=this,s=r[0],o=r[1];let a=1/0,l=-1/0,c=1/0,u=-1/0;for(let R=0;R<e.length;R+=2){const N=e[R],U=e[R+1];N<a&&(a=N),N>l&&(l=N),U<c&&(c=U),U>u&&(u=U)}const f=[this.store.scaleX(a),this.store.scaleX(l)],h=[this.store.scaleY(c),this.store.scaleY(u)];f[0]===f[1]&&(f[0]-=.5,f[1]+=.5),h[0]===h[1]&&(h[0]+=.5,h[1]-=.5);const d=s*(1-i*2)/(f[1]-f[0]),_=o*(1-i*2)/(h[0]-h[1]),I=wc(t??Math.min(d,_),...this.behavior.scaleExtent()),P=(f[1]+f[0])/2,A=(h[1]+h[0])/2,O=s/2-P*I,E=o/2-A*I;return ni.translate(O,E).scale(I)}getDistanceToPoint(e){const{x:t,y:i,k:r}=this.eventTransform,s=this.getTransform(e,r),o=t-s.x,a=i-s.y;return Math.sqrt(o*o+a*a)}getMiddlePointTransform(e){const{store:{screenSize:t},eventTransform:{x:i,y:r,k:s}}=this,o=t[0],a=t[1],l=(o/2-i)/s,c=(a/2-r)/s,u=this.store.scaleX(e[0]),f=this.store.scaleY(e[1]),h=(l+u)/2,d=(c+f)/2,_=1,I=o/2-h*_,P=a/2-d*_;return ni.translate(I,P).scale(_)}convertScreenToSpacePosition(e){const{eventTransform:{x:t,y:i,k:r},store:{screenSize:s}}=this,o=s[0],a=s[1],l=(e[0]-t)/r,c=(e[1]-i)/r,u=[l,a-c];return u[0]-=(o-this.store.adjustedSpaceSize)/2,u[1]-=(a-this.store.adjustedSpaceSize)/2,u}convertSpaceToScreenPosition(e){const t=this.eventTransform.applyX(this.store.scaleX(e[0])),i=this.eventTransform.applyY(this.store.scaleY(e[1]));return[t,i]}convertSpaceToScreenRadius(e){const{config:{scalePointsOnZoom:t},store:{maxPointSize:i},eventTransform:{k:r}}=this;let s=e*2;return t?s*=r:s*=Math.min(5,Math.max(1,r*.01)),Math.min(s,i)/2}}class Vv{constructor(e,t){this.isActive=!1,this.behavior=Dv().subject(i=>this.store.hoveredPoint&&!this.store.isSpaceKeyPressed?{x:i.x,y:i.y}:void 0).on("start",i=>{var r,s;this.store.hoveredPoint&&(this.store.draggingPointIndex=this.store.hoveredPoint.index,this.isActive=!0,(s=(r=this.config).onDragStart)==null||s.call(r,i))}).on("drag",i=>{var r,s;(s=(r=this.config).onDrag)==null||s.call(r,i)}).on("end",i=>{var r,s;this.isActive=!1,this.store.draggingPointIndex=void 0,(s=(r=this.config).onDragEnd)==null||s.call(r,i)}),this.store=e,this.config=t}}class Hv{constructor(e,t,i){if(this.config=Pc(),this.graph=new my(this.config),this.isReady=!1,this.requestAnimationFrameId=0,this.isRightClickMouse=!1,this.store=new dy,this.zoomInstance=new Lv(this.store,this.config),this.dragInstance=new Vv(this.store,this.config),this._findHoveredItemExecutionCount=0,this._isMouseOnCanvas=!1,this._lastMouseX=0,this._lastMouseY=0,this._lastCheckedMouseX=0,this._lastCheckedMouseY=0,this._shouldForceHoverDetection=!1,this._isFirstRenderAfterInit=!0,this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this._isDestroyed=!1,t&&io(this.config,t),i)this.deviceInitPromise=i,this.shouldDestroyDevice=!1;else{const s=document.createElement("canvas");this.deviceInitPromise=this.createDevice(s),this.shouldDestroyDevice=!0}const r=this.deviceInitPromise.then(s=>{if(this._isDestroyed)return this.shouldDestroyDevice&&s.destroy(),s;this.device=s,this.isReady=!0;const o=this.validateDevice(s);i&&o.setProps({useDevicePixels:this.config.pixelRatio}),this.store.div=e;const a=o.canvas;a.parentNode!==this.store.div&&(a.parentNode&&a.parentNode.removeChild(a),this.store.div.appendChild(a)),this.addAttribution(),a.style.width="100%",a.style.height="100%",this.canvas=a;const l=this.canvas.clientWidth,c=this.canvas.clientHeight;return this.store.adjustSpaceSize(this.config.spaceSize,this.device.limits.maxTextureDimension2D),this.store.setWebGLMaxTextureSize(this.device.limits.maxTextureDimension2D),this.store.updateScreenSize(l,c),this.canvasD3Selection=we(this.canvas),this.canvasD3Selection.on("mouseenter.cosmos",u=>{this._isMouseOnCanvas=!0,this._lastMouseX=u.clientX,this._lastMouseY=u.clientY}).on("mousemove.cosmos",u=>{this._isMouseOnCanvas=!0,this._lastMouseX=u.clientX,this._lastMouseY=u.clientY}).on("mouseleave.cosmos",u=>{this._isMouseOnCanvas=!1,this.currentEvent=u,this.store.hoveredPoint!==void 0&&this.config.onPointMouseOut&&this.config.onPointMouseOut(u),this.store.hoveredLinkIndex!==void 0&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(u),this.isRightClickMouse=!1,this.store.hoveredPoint=void 0,this.store.hoveredLinkIndex=void 0,this.updateCanvasCursor()}),we(document).on("keydown.cosmos",u=>{u.code==="Space"&&(this.store.isSpaceKeyPressed=!0)}).on("keyup.cosmos",u=>{u.code==="Space"&&(this.store.isSpaceKeyPressed=!1)}),this.zoomInstance.behavior.on("start.detect",u=>{this.currentEvent=u}).on("zoom.detect",u=>{!!u.sourceEvent&&this.updateMousePosition(u.sourceEvent),this.currentEvent=u}).on("end.detect",u=>{this.currentEvent=u,this._shouldForceHoverDetection=!0}),this.dragInstance.behavior.on("start.detect",u=>{this.currentEvent=u,this.updateCanvasCursor()}).on("drag.detect",u=>{this.dragInstance.isActive&&this.updateMousePosition(u),this.currentEvent=u}).on("end.detect",u=>{this.currentEvent=u,this.updateCanvasCursor()}),this.canvasD3Selection.call(this.dragInstance.behavior).call(this.zoomInstance.behavior).on("click",this.onClick.bind(this)).on("mousemove",this.onMouseMove.bind(this)).on("contextmenu",this.onContextMenu.bind(this)),(!this.config.enableZoom||!this.config.enableDrag)&&this.updateZoomDragBehaviors(),this.setZoomLevel(this.config.initialZoomLevel??1),this.store.maxPointSize=eo(s,this.config.pixelRatio),this.store.isSimulationRunning=this.config.enableSimulation,this.points=new Cv(s,this.config,this.store,this.graph),this.lines=new fv(s,this.config,this.store,this.graph,this.points),this.config.enableSimulation&&(this.forceGravity=new V0(s,this.config,this.store,this.graph,this.points),this.forceCenter=new z0(s,this.config,this.store,this.graph,this.points),this.forceManyBody=new q0(s,this.config,this.store,this.graph,this.points),this.forceLinkIncoming=new vu(s,this.config,this.store,this.graph,this.points),this.forceLinkOutgoing=new vu(s,this.config,this.store,this.graph,this.points),this.forceMouse=new K0(s,this.config,this.store,this.graph,this.points)),this.clusters=new G0(s,this.config,this.store,this.graph,this.points),this.store.backgroundColor=Tt(this.config.backgroundColor),this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor),this.store.setFocusedPointRingColor(this.config.focusedPointRingColor),this.config.focusedPointIndex!==void 0&&this.store.setFocusedPoint(this.config.focusedPointIndex),this.store.setGreyoutPointColor(this.config.pointGreyoutColor),this.store.setHoveredLinkColor(this.config.hoveredLinkColor),this.store.updateLinkHoveringEnabled(this.config),this.config.showFPSMonitor&&(this.fpsMonitor=new bu(this.canvas)),this.config.randomSeed!==void 0&&this.store.addRandomSeed(this.config.randomSeed),s}).catch(s=>{throw this.device=void 0,this.isReady=!1,console.error("Device initialization failed:",s),s});this.ready=r.then(()=>{})}get progress(){return this._isDestroyed?0:this.store.simulationProgress}get isSimulationRunning(){return this._isDestroyed?!1:this.store.isSimulationRunning}get maxPointSize(){return this._isDestroyed?0:this.store.maxPointSize}setConfig(e){if(this._isDestroyed||this.ensureDevice(()=>this.setConfig(e)))return;const t={...this.config};gy(this.config),io(this.config,e),this.preserveInitOnlyFields(t),this.updateStateFromConfig(t)}setConfigPartial(e){if(this._isDestroyed||this.ensureDevice(()=>this.setConfigPartial(e)))return;const t={...this.config};io(this.config,e,!0),this.preserveInitOnlyFields(t),this.updateStateFromConfig(t)}setPointPositions(e,t){this._isDestroyed||this.ensureDevice(()=>this.setPointPositions(e,t))||(this.graph.inputPointPositions=e,this.points.shouldSkipRescale=t,this.isPointPositionsUpdateNeeded=!0,this.isLinksUpdateNeeded=!0,this.isPointColorUpdateNeeded=!0,this.isPointSizeUpdateNeeded=!0,this.isPointShapeUpdateNeeded=!0,this.isPointImageIndicesUpdateNeeded=!0,this.isPointImageSizesUpdateNeeded=!0,this.isPointClusterUpdateNeeded=!0,this.isForceManyBodyUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0,this.isForceCenterUpdateNeeded=!0)}setPointColors(e){this._isDestroyed||this.ensureDevice(()=>this.setPointColors(e))||(this.graph.inputPointColors=e,this.isPointColorUpdateNeeded=!0)}getPointColors(){return this._isDestroyed?new Float32Array:this.graph.pointColors??new Float32Array}setPointSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointSizes(e))||(this.graph.inputPointSizes=e,this.isPointSizeUpdateNeeded=!0)}setPointShapes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointShapes(e))||(this.graph.inputPointShapes=e,this.isPointShapeUpdateNeeded=!0)}setImageData(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setImageData(e))||(this.graph.inputImageData=e,(t=this.points)==null||t.createAtlas())}setPointImageIndices(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageIndices(e))||(this.graph.inputPointImageIndices=e,this.isPointImageIndicesUpdateNeeded=!0)}setPointImageSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageSizes(e))||(this.graph.inputPointImageSizes=e,this.isPointImageSizesUpdateNeeded=!0)}getPointSizes(){return this._isDestroyed?new Float32Array:this.graph.pointSizes??new Float32Array}setLinks(e){this._isDestroyed||this.ensureDevice(()=>this.setLinks(e))||(this.graph.inputLinks=e,this.isLinksUpdateNeeded=!0,this.isLinkColorUpdateNeeded=!0,this.isLinkWidthUpdateNeeded=!0,this.isLinkArrowUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0)}setLinkColors(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkColors(e))||(this.graph.inputLinkColors=e,this.isLinkColorUpdateNeeded=!0)}getLinkColors(){return this._isDestroyed?new Float32Array:this.graph.linkColors??new Float32Array}setLinkWidths(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkWidths(e))||(this.graph.inputLinkWidths=e,this.isLinkWidthUpdateNeeded=!0)}getLinkWidths(){return this._isDestroyed?new Float32Array:this.graph.linkWidths??new Float32Array}setLinkArrows(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkArrows(e))||(this.graph.linkArrowsBoolean=e,this.isLinkArrowUpdateNeeded=!0)}setLinkStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkStrength(e))||(this.graph.inputLinkStrength=e,this.isForceLinkUpdateNeeded=!0)}setPointClusters(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusters(e))||(this.graph.inputPointClusters=e,this.isPointClusterUpdateNeeded=!0)}setClusterPositions(e){this._isDestroyed||this.ensureDevice(()=>this.setClusterPositions(e))||(this.graph.inputClusterPositions=e,this.isPointClusterUpdateNeeded=!0)}setPointClusterStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusterStrength(e))||(this.graph.inputClusterStrength=e,this.isPointClusterUpdateNeeded=!0)}setPinnedPoints(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setPinnedPoints(e))||(this.graph.inputPinnedPoints=e&&e.length>0?e:void 0,(t=this.points)==null||t.updatePinnedStatus())}render(e){if(this._isDestroyed||this.ensureDevice(()=>this.render(e)))return;this.graph.update();const{fitViewOnInit:t,fitViewDelay:i,fitViewPadding:r,fitViewDuration:s,fitViewByPointsInRect:o,fitViewByPointIndices:a,initialZoomLevel:l}=this.config;if(!this.graph.pointsNumber&&!this.graph.linksNumber){this.stopFrames(),we(this.canvas).style("cursor",null),this.device&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit());return}this._isFirstRenderAfterInit&&t&&l===void 0&&(this._fitViewOnInitTimeoutID=window.setTimeout(()=>{a?this.fitViewByPointIndices(a,s,r):o?this.setZoomTransformByPointPositions(new Float32Array(this.flatten(o)),s,void 0,r):this.fitView(s,r)},i)),this.update(e),this._shouldForceHoverDetection=!0,this.startFrames(),this._isFirstRenderAfterInit=!1}zoomToPointByIndex(e,t=700,i=3,r=!0,s=!0){if(this._isDestroyed||this.ensureDevice(()=>this.zoomToPointByIndex(e,t,i,r,s))||!this.device||!this.points||!this.canvasD3Selection)return;const{store:{screenSize:o}}=this,a=Me(this.device,this.points.currentPositionFbo);if(e===void 0)return;const l=a[e*4+0],c=a[e*4+1];if(l===void 0||c===void 0)return;const u=this.zoomInstance.getDistanceToPoint([l,c]),f=r?i:Math.max(this.getZoomLevel(),i);if(u<Math.min(o[0],o[1]))this.setZoomTransformByPointPositions(new Float32Array([l,c]),t,f,void 0,s);else{this.zoomInstance.shouldEnableSimulationDuringZoomOverride=s;const h=this.zoomInstance.getTransform([l,c],f),d=this.zoomInstance.getMiddlePointTransform([l,c]);this.canvasD3Selection.transition().ease(hp).duration(t/2).call(this.zoomInstance.behavior.transform,d).transition().ease(dp).duration(t/2).call(this.zoomInstance.behavior.transform,h)}}zoom(e,t=0,i=!0){this._isDestroyed||this.setZoomLevel(e,t,i)}setZoomLevel(e,t=0,i=!0){this._isDestroyed||this.ensureDevice(()=>this.setZoomLevel(e,t,i))||this.canvasD3Selection&&(this.zoomInstance.shouldEnableSimulationDuringZoomOverride=i,t===0?this.canvasD3Selection.call(this.zoomInstance.behavior.scaleTo,e):this.canvasD3Selection.transition().duration(t).call(this.zoomInstance.behavior.scaleTo,e))}getZoomLevel(){return this._isDestroyed?0:this.zoomInstance.eventTransform.k}getPointPositions(){if(this._isDestroyed||!this.device||!this.points)return[];if(this.graph.pointsNumber===void 0)return[];const e=[],t=Me(this.device,this.points.currentPositionFbo);e.length=this.graph.pointsNumber*2;for(let i=0;i<this.graph.pointsNumber;i+=1){const r=t[i*4+0],s=t[i*4+1];r!==void 0&&s!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}getClusterPositions(){return this._isDestroyed||!this.device||!this.clusters?[]:this.graph.pointClusters===void 0||this.clusters.clusterCount===void 0?[]:this.clusters.getCentroidPositions()}fitView(e=250,t=.1,i=!0){this._isDestroyed||this.ensureDevice(()=>this.fitView(e,t,i))||this.setZoomTransformByPointPositions(new Float32Array(this.getPointPositions()),e,void 0,t,i)}fitViewByPointIndices(e,t=250,i=.1,r=!0){if(this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointIndices(e,t,i,r)))return;const s=this.getPointPositions(),o=new Float32Array(e.length*2);for(const[a,l]of e.entries())o[a*2]=s[l*2],o[a*2+1]=s[l*2+1];this.setZoomTransformByPointPositions(o,t,void 0,i,r)}fitViewByPointPositions(e,t=250,i=.1,r=!0){this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointPositions(e,t,i,r))||this.setZoomTransformByPointPositions(new Float32Array(e),t,void 0,i,r)}setZoomTransformByPointPositions(e,t=250,i,r=.1,s=!0){var a;if(this._isDestroyed||this.ensureDevice(()=>this.setZoomTransformByPointPositions(e,t,i,r,s)))return;this.zoomInstance.shouldEnableSimulationDuringZoomOverride=s,this.resizeCanvas();const o=this.zoomInstance.getTransform(e,i,r);(a=this.canvasD3Selection)==null||a.transition().ease(pp).duration(t).call(this.zoomInstance.behavior.transform,o)}getPointsInRect(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;const t=this.store.screenSize[1];return this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection(),Me(this.device,this.points.selectedFbo).map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}getPointsInPolygon(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;if(e.length<3)return new Float32Array;const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);return this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection(),Me(this.device,this.points.selectedFbo).map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}selectPointsInRect(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInRect(e))&&!(!this.device||!this.points)){if(e){const t=this.store.screenSize[1];this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection();const i=Me(this.device,this.points.selectedFbo);this.store.selectedIndices=i.map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointsInPolygon(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInPolygon(e))&&!(!this.device||!this.points)){if(e){if(e.length<3){console.warn("Polygon path requires at least 3 points to form a polygon.");return}const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection();const r=Me(this.device,this.points.selectedFbo);this.store.selectedIndices=r.map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointByIndex(e,t=!1){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointByIndex(e,t)))if(t){const i=this.graph.getAdjacentIndices(e)??[];this.selectPointsByIndices([e,...i])}else this.selectPointsByIndices([e])}selectPointsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.selectPointsByIndices(e))||this.points&&(e?e.length===0?this.store.selectedIndices=new Float32Array:this.store.selectedIndices=new Float32Array(e.filter(t=>t!==void 0)):this.store.selectedIndices=null,this.points.updateGreyoutStatus())}unselectPoints(){this._isDestroyed||this.ensureDevice(()=>this.unselectPoints())||this.points&&(this.store.selectedIndices=null,this.points.updateGreyoutStatus())}getSelectedIndices(){if(this._isDestroyed)return null;const{selectedIndices:e}=this.store;return e?Array.from(e):null}getAdjacentIndices(e){if(!this._isDestroyed)return this.graph.getAdjacentIndices(e)}spaceToScreenPosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertSpaceToScreenPosition(e)}screenToSpacePosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertScreenToSpacePosition(e)}spaceToScreenRadius(e){return this._isDestroyed?0:this.zoomInstance.convertSpaceToScreenRadius(e)}getPointRadiusByIndex(e){var r,s;if(this._isDestroyed)return;const t=(r=this.graph.pointSizes)==null?void 0:r[e],i=(s=this.graph.pointImageSizes)==null?void 0:s[e];if(!(t===void 0&&i===void 0))return Math.max(t??0,i??0)}trackPointPositionsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.trackPointPositionsByIndices(e))||this.points&&this.points.trackPointsByIndices(e)}getTrackedPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getTrackedPositionsMap()}getTrackedPointPositionsArray(){return this._isDestroyed||!this.points?[]:this.points.getTrackedPositionsArray()}getSampledPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getSampledPointPositionsMap()}getSampledPoints(){return this._isDestroyed||!this.points?{indices:[],positions:[]}:this.points.getSampledPoints()}getSampledLinkPositionsMap(){return this._isDestroyed||!this.lines?new Map:this.lines.getSampledLinkPositionsMap()}getSampledLinks(){return this._isDestroyed||!this.lines?{indices:[],positions:[],angles:[]}:this.lines.getSampledLinks()}getScaleX(){if(!(this._isDestroyed||!this.points))return this.points.scaleX}getScaleY(){if(!(this._isDestroyed||!this.points))return this.points.scaleY}start(e=1){var t,i;this._isDestroyed||this.ensureDevice(()=>this.start(e))||this.graph.pointsNumber&&(this.store.isSimulationRunning=!0,this.store.simulationProgress=0,this.store.alpha=e,(i=(t=this.config).onSimulationStart)==null||i.call(t))}stop(){var e,t;this._isDestroyed||(this.store.isSimulationRunning=!1,this.store.simulationProgress=0,this.store.alpha=0,(t=(e=this.config).onSimulationEnd)==null||t.call(e))}pause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.pause())||(this.store.isSimulationRunning=!1,(t=(e=this.config).onSimulationPause)==null||t.call(e))}unpause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.unpause())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationUnpause)==null||t.call(e))}step(){this._isDestroyed||this.ensureDevice(()=>this.step())||this.config.enableSimulation&&this.store.pointsTextureSize&&this.runSimulationStep(!0)}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d;this._isDestroyed||(this._isDestroyed=!0,this.isReady=!1,window.clearTimeout(this._fitViewOnInitTimeoutID),this.stopFrames(),this.canvasD3Selection&&this.canvasD3Selection.on("mouseenter.cosmos",null).on("mousemove.cosmos",null).on("mouseleave.cosmos",null).on("click",null).on("mousemove",null).on("contextmenu",null).on(".drag",null).on(".zoom",null),we(document).on("keydown.cosmos",null).on("keyup.cosmos",null),(e=this.zoomInstance)!=null&&e.behavior&&this.zoomInstance.behavior.on("start.detect",null).on("zoom.detect",null).on("end.detect",null),(t=this.dragInstance)!=null&&t.behavior&&this.dragInstance.behavior.on("start.detect",null).on("drag.detect",null).on("end.detect",null),(i=this.fpsMonitor)==null||i.destroy(),(r=this.points)==null||r.destroy(),(s=this.lines)==null||s.destroy(),(o=this.clusters)==null||o.destroy(),(a=this.forceGravity)==null||a.destroy(),(l=this.forceCenter)==null||l.destroy(),(c=this.forceManyBody)==null||c.destroy(),(u=this.forceLinkIncoming)==null||u.destroy(),(f=this.forceLinkOutgoing)==null||f.destroy(),(h=this.forceMouse)==null||h.destroy(),this.device&&this.shouldDestroyDevice&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit(),this.device.destroy()),this.shouldDestroyDevice&&this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.attributionDivElement&&this.attributionDivElement.parentNode&&this.attributionDivElement.parentNode.removeChild(this.attributionDivElement),(d=document.getElementById("gl-bench-style"))==null||d.remove(),this.canvasD3Selection=void 0,this.attributionDivElement=void 0)}create(){var e,t,i,r,s;this._isDestroyed||this.ensureDevice(()=>this.create())||this.points&&this.lines&&(this.isPointPositionsUpdateNeeded&&this.points.updatePositions(),this.isPointColorUpdateNeeded&&this.points.updateColor(),this.isPointSizeUpdateNeeded&&this.points.updateSize(),this.isPointShapeUpdateNeeded&&this.points.updateShape(),this.isPointImageIndicesUpdateNeeded&&this.points.updateImageIndices(),this.isPointImageSizesUpdateNeeded&&this.points.updateImageSizes(),this.isLinksUpdateNeeded&&this.lines.updatePointsBuffer(),this.isLinkColorUpdateNeeded&&this.lines.updateColor(),this.isLinkWidthUpdateNeeded&&this.lines.updateWidth(),this.isLinkArrowUpdateNeeded&&this.lines.updateArrow(),this.isForceManyBodyUpdateNeeded&&((e=this.forceManyBody)==null||e.create()),this.isForceLinkUpdateNeeded&&((t=this.forceLinkIncoming)==null||t.create(Ro.INCOMING),(i=this.forceLinkOutgoing)==null||i.create(Ro.OUTGOING)),this.isForceCenterUpdateNeeded&&((r=this.forceCenter)==null||r.create()),this.isPointClusterUpdateNeeded&&((s=this.clusters)==null||s.create()),this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1)}flatten(e){return e.flat()}pair(e){const t=new Array(e.length/2);for(let i=0;i<e.length/2;i++)t[i]=[e[i*2],e[i*2+1]];return t}preserveInitOnlyFields(e){this.config.enableSimulation=e.enableSimulation,this.config.initialZoomLevel=e.initialZoomLevel,this.config.randomSeed=e.randomSeed,this.config.attribution=e.attribution}updateStateFromConfig(e){var t,i,r,s,o,a,l,c,u,f;e.pointDefaultColor!==this.config.pointDefaultColor&&(this.graph.updatePointColor(),(t=this.points)==null||t.updateColor()),e.pointDefaultSize!==this.config.pointDefaultSize&&(this.graph.updatePointSize(),(i=this.points)==null||i.updateSize()),e.pointDefaultShape!==this.config.pointDefaultShape&&(this.graph.updatePointShape(),(r=this.points)==null||r.updateShape()),e.linkDefaultColor!==this.config.linkDefaultColor&&(this.graph.updateLinkColor(),(s=this.lines)==null||s.updateColor()),e.linkDefaultWidth!==this.config.linkDefaultWidth&&(this.graph.updateLinkWidth(),(o=this.lines)==null||o.updateWidth()),e.linkDefaultArrows!==this.config.linkDefaultArrows&&(this.graph.updateArrows(),(a=this.lines)==null||a.updateArrow()),(e.curvedLinkSegments!==this.config.curvedLinkSegments||e.curvedLinks!==this.config.curvedLinks)&&((l=this.lines)==null||l.updateCurveLineGeometry()),e.backgroundColor!==this.config.backgroundColor&&(this.store.backgroundColor=Tt(this.config.backgroundColor)),e.hoveredPointRingColor!==this.config.hoveredPointRingColor&&this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor),e.focusedPointRingColor!==this.config.focusedPointRingColor&&this.store.setFocusedPointRingColor(this.config.focusedPointRingColor),e.pointGreyoutColor!==this.config.pointGreyoutColor&&this.store.setGreyoutPointColor(this.config.pointGreyoutColor),e.hoveredLinkColor!==this.config.hoveredLinkColor&&this.store.setHoveredLinkColor(this.config.hoveredLinkColor),e.focusedPointIndex!==this.config.focusedPointIndex&&this.store.setFocusedPoint(this.config.focusedPointIndex),e.pixelRatio!==this.config.pixelRatio&&(c=this.device)!=null&&c.canvasContext&&(this.device.canvasContext.setProps({useDevicePixels:this.config.pixelRatio}),this.store.maxPointSize=eo(this.device,this.config.pixelRatio)),e.spaceSize!==this.config.spaceSize&&(this.store.adjustSpaceSize(this.config.spaceSize,((u=this.device)==null?void 0:u.limits.maxTextureDimension2D)??4096),this.resizeCanvas(!0),this.update(this.store.isSimulationRunning?this.store.alpha:0)),e.showFPSMonitor!==this.config.showFPSMonitor&&(this.config.showFPSMonitor?this.fpsMonitor=new bu(this.canvas):((f=this.fpsMonitor)==null||f.destroy(),this.fpsMonitor=void 0)),(e.enableZoom!==this.config.enableZoom||e.enableDrag!==this.config.enableDrag)&&this.updateZoomDragBehaviors(),(e.onLinkClick!==this.config.onLinkClick||e.onLinkContextMenu!==this.config.onLinkContextMenu||e.onLinkMouseOver!==this.config.onLinkMouseOver||e.onLinkMouseOut!==this.config.onLinkMouseOut)&&this.store.updateLinkHoveringEnabled(this.config)}ensureDevice(e){return this.isReady?!1:(this.ready.then(()=>{this._isDestroyed||e()}).catch(t=>{console.error("Device initialization failed",t)}),!0)}validateDevice(e){const t=e.canvasContext;if(t===null||t.type==="offscreen-canvas")throw new Error("Device must have an HTMLCanvasElement canvas context. OffscreenCanvas and compute-only devices are not supported.");return t}async createDevice(e){return await Jp.createDevice({type:"webgl",adapters:[Qm],createCanvasContext:{canvas:e,useDevicePixels:this.config.pixelRatio,autoResize:!0,width:void 0,height:void 0}})}update(e=this.store.alpha){const{graph:t}=this;this.store.pointsTextureSize=Math.ceil(Math.sqrt(t.pointsNumber??0)),this.store.linksTextureSize=Math.ceil(Math.sqrt((t.linksNumber??0)*2)),this.create(),this.initPrograms(),this.store.alpha=e}runSimulationStep(e=!1){var l,c,u,f,h,d,_,I,P,A,O,E,y,R,N,U,H,Y,Z;const{config:{simulationGravity:t,simulationCenter:i,enableSimulation:r},store:{isSimulationRunning:s}}=this;if(!r)return;this.isRightClickMouse&&this.config.enableRightClickRepulsion&&((l=this.forceMouse)==null||l.run(),(c=this.points)==null||c.updatePosition());const o=this.zoomInstance.shouldEnableSimulationDuringZoomOverride??this.config.enableSimulationDuringZoom;(e||s&&!(this.zoomInstance.isRunning&&!o))&&(t&&((u=this.forceGravity)==null||u.run(),(f=this.points)==null||f.updatePosition()),i&&((h=this.forceCenter)==null||h.run(),(d=this.points)==null||d.updatePosition()),(_=this.forceManyBody)==null||_.run(),(I=this.points)==null||I.updatePosition(),this.store.linksTextureSize&&((P=this.forceLinkIncoming)==null||P.run(),(A=this.points)==null||A.updatePosition(),(O=this.forceLinkOutgoing)==null||O.run(),(E=this.points)==null||E.updatePosition()),(this.graph.pointClusters||this.graph.clusterPositions)&&((y=this.clusters)==null||y.run(),(R=this.points)==null||R.updatePosition()),this.store.alpha+=this.store.addAlpha(this.config.simulationDecay),this.isRightClickMouse&&this.config.enableRightClickRepulsion&&(this.store.alpha=Math.max(this.store.alpha,.1)),this.store.simulationProgress=Math.sqrt(Math.min(1,Js/this.store.alpha)),(Y=(H=this.config).onSimulationTick)==null||Y.call(H,this.store.alpha,(N=this.store.hoveredPoint)==null?void 0:N.index,(U=this.store.hoveredPoint)==null?void 0:U.position)),(Z=this.points)==null||Z.trackPoints()}initPrograms(){var e,t,i,r,s,o;this._isDestroyed||!this.points||!this.lines||!this.clusters||(this.points.initPrograms(),this.lines.initPrograms(),(e=this.forceGravity)==null||e.initPrograms(),(t=this.forceManyBody)==null||t.initPrograms(),(i=this.forceCenter)==null||i.initPrograms(),(r=this.forceLinkIncoming)==null||r.initPrograms(),(s=this.forceLinkOutgoing)==null||s.initPrograms(),(o=this.forceMouse)==null||o.initPrograms(),this.clusters.initPrograms())}frame(){if(this._isDestroyed)return;const{store:{alpha:e,isSimulationRunning:t}}=this;e<Js&&t&&this.end(),this.requestAnimationFrameId=window.requestAnimationFrame(i=>{this.renderFrame(i),this._isDestroyed||this.frame()})}renderFrame(e){var t,i,r,s,o,a,l;if(!this._isDestroyed&&this.store.pointsTextureSize){if((t=this.fpsMonitor)==null||t.begin(),this.resizeCanvas(),this.dragInstance.isActive||this.findHoveredItem(),this.runSimulationStep(!1),this.device){const c=this.store.backgroundColor??[0,0,0,1],u=this.device.beginRenderPass({clearColor:c,clearDepth:1,clearStencil:0}),{config:{renderLinks:f}}=this;f!==!1&&!!this.store.linksTextureSize&&!!this.graph.linksNumber&&this.graph.linksNumber>0&&((i=this.lines)==null||i.draw(u)),(r=this.points)==null||r.draw(u),this.dragInstance.isActive&&((s=this.points)==null||s.drag(),(o=this.points)==null||o.drag(),(a=this.points)==null||a.trackPoints()),u.end(),this.device.submit()}(l=this.fpsMonitor)==null||l.end(e??performance.now()),this.currentEvent=void 0}}stopFrames(){this.requestAnimationFrameId&&(window.cancelAnimationFrame(this.requestAnimationFrameId),this.requestAnimationFrameId=0)}startFrames(){this._isDestroyed||(this.stopFrames(),this.frame())}end(){var e,t;this.store.isSimulationRunning=!1,this.store.simulationProgress=1,(t=(e=this.config).onSimulationEnd)==null||t.call(e),this._shouldForceHoverDetection=!0}onClick(e){var t,i,r,s,o,a,l,c,u,f;(s=(r=this.config).onClick)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointClick)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkClick)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundClick)==null||f.call(u,e)}updateMousePosition(e){if(!e)return;const t=e.offsetX??e.x,i=e.offsetY??e.y;t===void 0||i===void 0||(this.store.mousePosition=this.zoomInstance.convertScreenToSpacePosition([t,i]),this.store.screenMousePosition=[t,this.store.screenSize[1]-i])}onMouseMove(e){var t,i,r,s;this.currentEvent=e,this.updateMousePosition(e),this.isRightClickMouse=e.which===3,(s=(r=this.config).onMouseMove)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,this.currentEvent)}onContextMenu(e){var t,i,r,s,o,a,l,c,u,f;e.preventDefault(),(s=(r=this.config).onContextMenu)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointContextMenu)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkContextMenu)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundContextMenu)==null||f.call(u,e)}resizeCanvas(e=!1){var o,a,l,c;if(this._isDestroyed)return;const t=this.canvas.clientWidth,i=this.canvas.clientHeight,[r,s]=this.store.screenSize;if(e||r!==t||s!==i){const{k:u}=this.zoomInstance.eventTransform,f=this.zoomInstance.convertScreenToSpacePosition([r/2,s/2]);this.store.updateScreenSize(t,i),(o=this.canvasD3Selection)==null||o.call(this.zoomInstance.behavior.transform,this.zoomInstance.getTransform(f,u)),(a=this.points)==null||a.updateSampledPointsGrid(),(l=this.lines)==null||l.updateSampledLinksGrid(),this.store.isLinkHoveringEnabled&&((c=this.lines)==null||c.updateLinkIndexFbo())}}updateZoomDragBehaviors(){var e,t,i,r;this.config.enableDrag?(e=this.canvasD3Selection)==null||e.call(this.dragInstance.behavior):(t=this.canvasD3Selection)==null||t.call(this.dragInstance.behavior).on(".drag",null),this.config.enableZoom?(i=this.canvasD3Selection)==null||i.call(this.zoomInstance.behavior):(r=this.canvasD3Selection)==null||r.call(this.zoomInstance.behavior).on("wheel.zoom",null)}findHoveredItem(){if(this._isDestroyed||!this._isMouseOnCanvas)return;if(this._findHoveredItemExecutionCount<hy){this._findHoveredItemExecutionCount+=1;return}const e=Math.abs(this._lastMouseX-this._lastCheckedMouseX),t=Math.abs(this._lastMouseY-this._lastCheckedMouseY);if(!(!(e>yc||t>yc)&&!this._shouldForceHoverDetection)){if(this._lastCheckedMouseX=this._lastMouseX,this._lastCheckedMouseY=this._lastMouseY,this._shouldForceHoverDetection=!1,this._findHoveredItemExecutionCount=0,this.findHoveredPoint(),this.graph.linksNumber&&this.store.isLinkHoveringEnabled)this.findHoveredLine();else if(this.store.hoveredLinkIndex!==void 0){const r=this.store.hoveredLinkIndex!==void 0;this.store.hoveredLinkIndex=void 0,r&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(this.currentEvent)}this.updateCanvasCursor()}}findHoveredPoint(){var l,c,u,f,h;if(this._isDestroyed||!this.device||!this.points)return;this.points.findHoveredPoint();let e=!1,t=!1;const i=Me(this.device,this.points.hoveredFbo,0,0,2,2),r=i[0],s=i[1],o=i[2],a=i[3];s>0?((this.store.hoveredPoint===void 0||this.store.hoveredPoint.index!==r)&&(e=!0),this.store.hoveredPoint={index:r,position:[o,a]}):(this.store.hoveredPoint&&(t=!0),this.store.hoveredPoint=void 0),e&&this.store.hoveredPoint&&((u=(c=this.config).onPointMouseOver)==null||u.call(c,this.store.hoveredPoint.index,this.store.hoveredPoint.position,this.currentEvent,((l=this.store.selectedIndices)==null?void 0:l.includes(this.store.hoveredPoint.index))??!1)),t&&((h=(f=this.config).onPointMouseOut)==null||h.call(f,this.currentEvent))}findHoveredLine(){var s,o,a,l,c,u;if(this._isDestroyed||!this.lines)return;if(this.store.hoveredPoint){this.store.hoveredLinkIndex!==void 0&&(this.store.hoveredLinkIndex=void 0,(o=(s=this.config).onLinkMouseOut)==null||o.call(s,this.currentEvent));return}this.lines.findHoveredLine();let e=!1,t=!1;if(!this.device)return;const r=Me(this.device,this.lines.hoveredLineIndexFbo)[0];r>=0?(this.store.hoveredLinkIndex!==r&&(e=!0),this.store.hoveredLinkIndex=r):(this.store.hoveredLinkIndex!==void 0&&(t=!0),this.store.hoveredLinkIndex=void 0),e&&this.store.hoveredLinkIndex!==void 0&&((l=(a=this.config).onLinkMouseOver)==null||l.call(a,this.store.hoveredLinkIndex)),t&&((u=(c=this.config).onLinkMouseOut)==null||u.call(c,this.currentEvent))}updateCanvasCursor(){const{hoveredPointCursor:e,hoveredLinkCursor:t}=this.config;this.dragInstance.isActive?we(this.canvas).style("cursor","grabbing"):this.store.hoveredPoint?!this.config.enableDrag||this.store.isSpaceKeyPressed?we(this.canvas).style("cursor",e):we(this.canvas).style("cursor","grab"):this.store.isLinkHoveringEnabled&&this.store.hoveredLinkIndex!==void 0?we(this.canvas).style("cursor",t):we(this.canvas).style("cursor",null)}addAttribution(){var e;this.config.attribution&&(this.attributionDivElement=document.createElement("div"),this.attributionDivElement.style.cssText=`
2382
2385
  user-select: none;
2383
2386
  position: absolute;
2384
2387
  bottom: 0;
@@ -2387,5 +2390,5 @@ void main() {
2387
2390
  margin: 0 0.6rem 0.6rem 0;
2388
2391
  font-size: 0.7rem;
2389
2392
  font-family: inherit;
2390
- `,this.attributionDivElement.innerHTML=Fc(this.config.attribution,{ALLOWED_TAGS:["a","b","i","em","strong","span","div","p","br","img"],ALLOWED_ATTR:["href","target","class","id","style","src","alt","title"]}),(e=this.store.div)==null||e.appendChild(this.attributionDivElement))}}te.Graph=Kv,te.PointShape=Pu,te.clamp=Mc,te.defaultBackgroundColor=Fs,te.defaultConfigValues=V,te.defaultGreyoutLinkOpacity=kl,te.defaultGreyoutPointColor=Hi,te.defaultGreyoutPointOpacity=Il,te.defaultLinkColor=Rl,te.defaultLinkOpacity=Dl,te.defaultLinkWidth=Ml,te.defaultPointColor=Cl,te.defaultPointOpacity=Pl,te.defaultPointSize=El,te.defaultScaleToZoom=Ol,te.focusedPointRingOpacity=Nl,te.getMaxPointSize=to,te.getRgbaColor=Tt,te.hoveredPointRingOpacity=Fl,te.isAClassInstance=kc,te.isArray=Gs,te.isFunction=Ec,te.isNumber=Ke,te.isObject=Rc,te.isPlainObject=eo,te.readPixels=Me,te.rgbToBrightness=Dc,te.sanitizeHtml=Fc,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})});
2393
+ `,this.attributionDivElement.innerHTML=Ac(this.config.attribution,{ALLOWED_TAGS:["a","b","i","em","strong","span","div","p","br","img"],ALLOWED_ATTR:["href","target","class","id","style","src","alt","title"]}),(e=this.store.div)==null||e.appendChild(this.attributionDivElement))}}le.Graph=Hv,le.PointShape=to,le.clamp=wc,le.defaultConfigValues=wt,le.focusedPointRingOpacity=Ic,le.getMaxPointSize=eo,le.getRgbaColor=Tt,le.hoveredPointRingOpacity=Cc,le.isAClassInstance=Sc,le.isArray=Gs,le.isFunction=vc,le.isNumber=Ze,le.isObject=bc,le.isPlainObject=py,le.readPixels=Me,le.rgbToBrightness=Tc,le.sanitizeHtml=Ac,Object.defineProperty(le,Symbol.toStringTag,{value:"Module"})});
2391
2394
  //# sourceMappingURL=index.min.js.map