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

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(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)}^^^
1
+ (function(oe,ze){typeof exports=="object"&&typeof module<"u"?ze(exports):typeof define=="function"&&define.amd?define(["exports"],ze):(oe=typeof globalThis<"u"?globalThis:oe||self,ze(oe.Cosmos={}))})(this,function(oe){"use strict";var vb=Object.defineProperty;var bb=(oe,ze,Ut)=>ze in oe?vb(oe,ze,{enumerable:!0,configurable:!0,writable:!0,value:Ut}):oe[ze]=Ut;var g=(oe,ze,Ut)=>bb(oe,typeof ze!="symbol"?ze+"":ze,Ut);var ze="http://www.w3.org/1999/xhtml";const Ut={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 cn(i){var e=i+="",t=e.indexOf(":");return t>=0&&(e=i.slice(0,t))!=="xmlns"&&(i=i.slice(t+1)),Ut.hasOwnProperty(e)?{space:Ut[e],local:i}:i}function af(i){return function(){var e=this.ownerDocument,t=this.namespaceURI;return t===ze&&e.documentElement.namespaceURI===ze?e.createElement(i):e.createElementNS(t,i)}}function lf(i){return function(){return this.ownerDocument.createElementNS(i.space,i.local)}}function Zo(i){var e=cn(i);return(e.local?lf:af)(e)}function cf(){}function jr(i){return i==null?cf:function(){return this.querySelector(i)}}function uf(i){typeof i!="function"&&(i=jr(i));for(var e=this._groups,t=e.length,n=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=n[r]=new Array(o),l,c,u=0;u<o;++u)(l=s[u])&&(c=i.call(l,l.__data__,u,s))&&("__data__"in l&&(c.__data__=l.__data__),a[u]=c);return new je(n,this._parents)}function ff(i){return i==null?[]:Array.isArray(i)?i:Array.from(i)}function hf(){return[]}function Qo(i){return i==null?hf:function(){return this.querySelectorAll(i)}}function df(i){return function(){return ff(i.apply(this,arguments))}}function pf(i){typeof i=="function"?i=df(i):i=Qo(i);for(var e=this._groups,t=e.length,n=[],r=[],s=0;s<t;++s)for(var o=e[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&(n.push(i.call(l,l.__data__,c,o)),r.push(l));return new je(n,r)}function Jo(i){return function(){return this.matches(i)}}function Go(i){return function(e){return e.matches(i)}}var gf=Array.prototype.find;function mf(i){return function(){return gf.call(this.children,i)}}function _f(){return this.firstElementChild}function xf(i){return this.select(i==null?_f:mf(typeof i=="function"?i:Go(i)))}var yf=Array.prototype.filter;function vf(){return Array.from(this.children)}function bf(i){return function(){return yf.call(this.children,i)}}function Sf(i){return this.selectAll(i==null?vf:bf(typeof i=="function"?i:Go(i)))}function Tf(i){typeof i!="function"&&(i=Jo(i));for(var e=this._groups,t=e.length,n=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=n[r]=[],l,c=0;c<o;++c)(l=s[c])&&i.call(l,l.__data__,c,s)&&a.push(l);return new je(n,this._parents)}function ea(i){return new Array(i.length)}function wf(){return new je(this._enter||this._groups.map(ea),this._parents)}function un(i,e){this.ownerDocument=i.ownerDocument,this.namespaceURI=i.namespaceURI,this._next=null,this._parent=i,this.__data__=e}un.prototype={constructor:un,appendChild:function(i){return this._parent.insertBefore(i,this._next)},insertBefore:function(i,e){return this._parent.insertBefore(i,e)},querySelector:function(i){return this._parent.querySelector(i)},querySelectorAll:function(i){return this._parent.querySelectorAll(i)}};function Af(i){return function(){return i}}function Cf(i,e,t,n,r,s){for(var o=0,a,l=e.length,c=s.length;o<c;++o)(a=e[o])?(a.__data__=s[o],n[o]=a):t[o]=new un(i,s[o]);for(;o<l;++o)(a=e[o])&&(r[o]=a)}function Pf(i,e,t,n,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(i,s[a],a,s)+"",(l=c.get(d))?(n[a]=l,l.__data__=s[a],c.delete(d)):t[a]=new un(i,s[a]);for(a=0;a<u;++a)(l=e[a])&&c.get(h[a])===l&&(r[a]=l)}function If(i){return i.__data__}function kf(i,e){if(!arguments.length)return Array.from(this,If);var t=e?Pf:Cf,n=this._parents,r=this._groups;typeof i!="function"&&(i=Af(i));for(var s=r.length,o=new Array(s),a=new Array(s),l=new Array(s),c=0;c<s;++c){var u=n[c],f=r[c],h=f.length,d=Rf(i.call(u,u&&u.__data__,c,n)),_=d.length,P=a[c]=new Array(_),I=o[c]=new Array(_),w=l[c]=new Array(h);t(u,f,P,I,w,d,e);for(var M=0,k=0,y,R;M<_;++M)if(y=P[M]){for(M>=k&&(k=M+1);!(R=I[k])&&++k<_;);y._next=R||null}}return o=new je(o,n),o._enter=a,o._exit=l,o}function Rf(i){return typeof i=="object"&&"length"in i?i:Array.from(i)}function Ef(){return new je(this._exit||this._groups.map(ea),this._parents)}function Df(i,e,t){var n=this.enter(),r=this,s=this.exit();return typeof i=="function"?(n=i(n),n&&(n=n.selection())):n=n.append(i+""),e!=null&&(r=e(r),r&&(r=r.selection())),t==null?s.remove():t(s),n&&r?n.merge(r).order():r}function Ff(i){for(var e=i.selection?i.selection():i,t=this._groups,n=e._groups,r=t.length,s=n.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var c=t[l],u=n[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 je(a,this._parents)}function Mf(){for(var i=this._groups,e=-1,t=i.length;++e<t;)for(var n=i[e],r=n.length-1,s=n[r],o;--r>=0;)(o=n[r])&&(s&&o.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(o,s),s=o);return this}function Nf(i){i||(i=Of);function e(f,h){return f&&h?i(f.__data__,h.__data__):!f-!h}for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++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 je(r,this._parents).order()}function Of(i,e){return i<e?-1:i>e?1:i>=e?0:NaN}function Bf(){var i=arguments[0];return arguments[0]=this,i.apply(null,arguments),this}function Uf(){return Array.from(this)}function zf(){for(var i=this._groups,e=0,t=i.length;e<t;++e)for(var n=i[e],r=0,s=n.length;r<s;++r){var o=n[r];if(o)return o}return null}function Lf(){let i=0;for(const e of this)++i;return i}function Vf(){return!this.node()}function Wf(i){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,o=r.length,a;s<o;++s)(a=r[s])&&i.call(a,a.__data__,s,r);return this}function Hf(i){return function(){this.removeAttribute(i)}}function $f(i){return function(){this.removeAttributeNS(i.space,i.local)}}function Xf(i,e){return function(){this.setAttribute(i,e)}}function Yf(i,e){return function(){this.setAttributeNS(i.space,i.local,e)}}function qf(i,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttribute(i):this.setAttribute(i,t)}}function jf(i,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttributeNS(i.space,i.local):this.setAttributeNS(i.space,i.local,t)}}function Kf(i,e){var t=cn(i);if(arguments.length<2){var n=this.node();return t.local?n.getAttributeNS(t.space,t.local):n.getAttribute(t)}return this.each((e==null?t.local?$f:Hf:typeof e=="function"?t.local?jf:qf:t.local?Yf:Xf)(t,e))}function ta(i){return i.ownerDocument&&i.ownerDocument.defaultView||i.document&&i||i.defaultView}function Zf(i){return function(){this.style.removeProperty(i)}}function Qf(i,e,t){return function(){this.style.setProperty(i,e,t)}}function Jf(i,e,t){return function(){var n=e.apply(this,arguments);n==null?this.style.removeProperty(i):this.style.setProperty(i,n,t)}}function Gf(i,e,t){return arguments.length>1?this.each((e==null?Zf:typeof e=="function"?Jf:Qf)(i,e,t??"")):ni(this.node(),i)}function ni(i,e){return i.style.getPropertyValue(e)||ta(i).getComputedStyle(i,null).getPropertyValue(e)}function eh(i){return function(){delete this[i]}}function th(i,e){return function(){this[i]=e}}function ih(i,e){return function(){var t=e.apply(this,arguments);t==null?delete this[i]:this[i]=t}}function nh(i,e){return arguments.length>1?this.each((e==null?eh:typeof e=="function"?ih:th)(i,e)):this.node()[i]}function ia(i){return i.trim().split(/^|\s+/)}function Kr(i){return i.classList||new na(i)}function na(i){this._node=i,this._names=ia(i.getAttribute("class")||"")}na.prototype={add:function(i){var e=this._names.indexOf(i);e<0&&(this._names.push(i),this._node.setAttribute("class",this._names.join(" ")))},remove:function(i){var e=this._names.indexOf(i);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(i){return this._names.indexOf(i)>=0}};function ra(i,e){for(var t=Kr(i),n=-1,r=e.length;++n<r;)t.add(e[n])}function sa(i,e){for(var t=Kr(i),n=-1,r=e.length;++n<r;)t.remove(e[n])}function rh(i){return function(){ra(this,i)}}function sh(i){return function(){sa(this,i)}}function oh(i,e){return function(){(e.apply(this,arguments)?ra:sa)(this,i)}}function ah(i,e){var t=ia(i+"");if(arguments.length<2){for(var n=Kr(this.node()),r=-1,s=t.length;++r<s;)if(!n.contains(t[r]))return!1;return!0}return this.each((typeof e=="function"?oh:e?rh:sh)(t,e))}function lh(){this.textContent=""}function ch(i){return function(){this.textContent=i}}function uh(i){return function(){var e=i.apply(this,arguments);this.textContent=e??""}}function fh(i){return arguments.length?this.each(i==null?lh:(typeof i=="function"?uh:ch)(i)):this.node().textContent}function hh(){this.innerHTML=""}function dh(i){return function(){this.innerHTML=i}}function ph(i){return function(){var e=i.apply(this,arguments);this.innerHTML=e??""}}function gh(i){return arguments.length?this.each(i==null?hh:(typeof i=="function"?ph:dh)(i)):this.node().innerHTML}function mh(){this.nextSibling&&this.parentNode.appendChild(this)}function _h(){return this.each(mh)}function xh(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function yh(){return this.each(xh)}function vh(i){var e=typeof i=="function"?i:Zo(i);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function bh(){return null}function Sh(i,e){var t=typeof i=="function"?i:Zo(i),n=e==null?bh:typeof e=="function"?e:jr(e);return this.select(function(){return this.insertBefore(t.apply(this,arguments),n.apply(this,arguments)||null)})}function Th(){var i=this.parentNode;i&&i.removeChild(this)}function wh(){return this.each(Th)}function Ah(){var i=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(i,this.nextSibling):i}function Ch(){var i=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(i,this.nextSibling):i}function Ph(i){return this.select(i?Ch:Ah)}function Ih(i){return arguments.length?this.property("__data__",i):this.node().__data__}function kh(i){return function(e){i.call(this,e,this.__data__)}}function Rh(i){return i.trim().split(/^|\s+/).map(function(e){var t="",n=e.indexOf(".");return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function Eh(i){return function(){var e=this.__on;if(e){for(var t=0,n=-1,r=e.length,s;t<r;++t)s=e[t],(!i.type||s.type===i.type)&&s.name===i.name?this.removeEventListener(s.type,s.listener,s.options):e[++n]=s;++n?e.length=n:delete this.__on}}}function Dh(i,e,t){return function(){var n=this.__on,r,s=kh(e);if(n){for(var o=0,a=n.length;o<a;++o)if((r=n[o]).type===i.type&&r.name===i.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(i.type,s,t),r={type:i.type,name:i.name,value:e,listener:s,options:t},n?n.push(r):this.__on=[r]}}function Fh(i,e,t){var n=Rh(i+""),r,s=n.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=n[r]).type===u.type&&o.name===u.name)return u.value}return}for(a=e?Dh:Eh,r=0;r<s;++r)this.each(a(n[r],e,t));return this}function oa(i,e,t){var n=ta(i),r=n.CustomEvent;typeof r=="function"?r=new r(e,t):(r=n.document.createEvent("Event"),t?(r.initEvent(e,t.bubbles,t.cancelable),r.detail=t.detail):r.initEvent(e,!1,!1)),i.dispatchEvent(r)}function Mh(i,e){return function(){return oa(this,i,e)}}function Nh(i,e){return function(){return oa(this,i,e.apply(this,arguments))}}function Oh(i,e){return this.each((typeof e=="function"?Nh:Mh)(i,e))}function*Bh(){for(var i=this._groups,e=0,t=i.length;e<t;++e)for(var n=i[e],r=0,s=n.length,o;r<s;++r)(o=n[r])&&(yield o)}var aa=[null];function je(i,e){this._groups=i,this._parents=e}function Ii(){return new je([[document.documentElement]],aa)}function Uh(){return this}je.prototype=Ii.prototype={constructor:je,select:uf,selectAll:pf,selectChild:xf,selectChildren:Sf,filter:Tf,data:kf,enter:wf,exit:Ef,join:Df,merge:Ff,selection:Uh,order:Mf,sort:Nf,call:Bf,nodes:Uf,node:zf,size:Lf,empty:Vf,each:Wf,attr:Kf,style:Gf,property:nh,classed:ah,text:fh,html:gh,raise:_h,lower:yh,append:vh,insert:Sh,remove:wh,clone:Ph,datum:Ih,on:Fh,dispatch:Oh,[Symbol.iterator]:Bh};function Ae(i){return typeof i=="string"?new je([[document.querySelector(i)]],[document.documentElement]):new je([[i]],aa)}function zh(i){let e;for(;e=i.sourceEvent;)i=e;return i}function St(i,e){if(i=zh(i),e===void 0&&(e=i.currentTarget),e){var t=e.ownerSVGElement||e;if(t.createSVGPoint){var n=t.createSVGPoint();return n.x=i.clientX,n.y=i.clientY,n=n.matrixTransform(e.getScreenCTM().inverse()),[n.x,n.y]}if(e.getBoundingClientRect){var r=e.getBoundingClientRect();return[i.clientX-r.left-e.clientLeft,i.clientY-r.top-e.clientTop]}}return[i.pageX,i.pageY]}var Lh={value:()=>{}};function fn(){for(var i=0,e=arguments.length,t={},n;i<e;++i){if(!(n=arguments[i]+"")||n in t||/[\s.]/.test(n))throw new Error("illegal type: "+n);t[n]=[]}return new hn(t)}function hn(i){this._=i}function Vh(i,e){return i.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})}hn.prototype=fn.prototype={constructor:hn,on:function(i,e){var t=this._,n=Vh(i+"",t),r,s=-1,o=n.length;if(arguments.length<2){for(;++s<o;)if((r=(i=n[s]).type)&&(r=Wh(t[r],i.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++s<o;)if(r=(i=n[s]).type)t[r]=la(t[r],i.name,e);else if(e==null)for(r in t)t[r]=la(t[r],i.name,null);return this},copy:function(){var i={},e=this._;for(var t in e)i[t]=e[t].slice();return new hn(i)},call:function(i,e){if((r=arguments.length-2)>0)for(var t=new Array(r),n=0,r,s;n<r;++n)t[n]=arguments[n+2];if(!this._.hasOwnProperty(i))throw new Error("unknown type: "+i);for(s=this._[i],n=0,r=s.length;n<r;++n)s[n].value.apply(e,t)},apply:function(i,e,t){if(!this._.hasOwnProperty(i))throw new Error("unknown type: "+i);for(var n=this._[i],r=0,s=n.length;r<s;++r)n[r].value.apply(e,t)}};function Wh(i,e){for(var t=0,n=i.length,r;t<n;++t)if((r=i[t]).name===e)return r.value}function la(i,e,t){for(var n=0,r=i.length;n<r;++n)if(i[n].name===e){i[n]=Lh,i=i.slice(0,n).concat(i.slice(n+1));break}return t!=null&&i.push({name:e,value:t}),i}var ri=0,ki=0,Ri=0,ca=1e3,dn,Ei,pn=0,zt=0,gn=0,Di=typeof performance=="object"&&performance.now?performance:Date,ua=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(i){setTimeout(i,17)};function Zr(){return zt||(ua(Hh),zt=Di.now()+gn)}function Hh(){zt=0}function mn(){this._call=this._time=this._next=null}mn.prototype=fa.prototype={constructor:mn,restart:function(i,e,t){if(typeof i!="function")throw new TypeError("callback is not a function");t=(t==null?Zr():+t)+(e==null?0:+e),!this._next&&Ei!==this&&(Ei?Ei._next=this:dn=this,Ei=this),this._call=i,this._time=t,Qr()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qr())}};function fa(i,e,t){var n=new mn;return n.restart(i,e,t),n}function $h(){Zr(),++ri;for(var i=dn,e;i;)(e=zt-i._time)>=0&&i._call.call(null,e),i=i._next;--ri}function ha(){zt=(pn=Di.now())+gn,ri=ki=0;try{$h()}finally{ri=0,Yh(),zt=0}}function Xh(){var i=Di.now(),e=i-pn;e>ca&&(gn-=e,pn=i)}function Yh(){for(var i,e=dn,t,n=1/0;e;)e._call?(n>e._time&&(n=e._time),i=e,e=e._next):(t=e._next,e._next=null,e=i?i._next=t:dn=t);Ei=i,Qr(n)}function Qr(i){if(!ri){ki&&(ki=clearTimeout(ki));var e=i-zt;e>24?(i<1/0&&(ki=setTimeout(ha,i-Di.now()-gn)),Ri&&(Ri=clearInterval(Ri))):(Ri||(pn=Di.now(),Ri=setInterval(Xh,ca)),ri=1,ua(ha))}}function da(i,e,t){var n=new mn;return e=e==null?0:+e,n.restart(r=>{n.stop(),i(r+e)},e,t),n}var qh=fn("start","end","cancel","interrupt"),jh=[],pa=0,ga=1,Jr=2,_n=3,ma=4,Gr=5,xn=6;function yn(i,e,t,n,r,s){var o=i.__transition;if(!o)i.__transition={};else if(t in o)return;Kh(i,t,{name:e,index:n,group:r,on:qh,tween:jh,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:pa})}function es(i,e){var t=rt(i,e);if(t.state>pa)throw new Error("too late; already scheduled");return t}function ft(i,e){var t=rt(i,e);if(t.state>_n)throw new Error("too late; already running");return t}function rt(i,e){var t=i.__transition;if(!t||!(t=t[e]))throw new Error("transition not found");return t}function Kh(i,e,t){var n=i.__transition,r;n[e]=t,t.timer=fa(s,0,t.time);function s(c){t.state=ga,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!==ga)return l();for(u in n)if(d=n[u],d.name===t.name){if(d.state===_n)return da(o);d.state===ma?(d.state=xn,d.timer.stop(),d.on.call("interrupt",i,i.__data__,d.index,d.group),delete n[u]):+u<e&&(d.state=xn,d.timer.stop(),d.on.call("cancel",i,i.__data__,d.index,d.group),delete n[u])}if(da(function(){t.state===_n&&(t.state=ma,t.timer.restart(a,t.delay,t.time),a(c))}),t.state=Jr,t.on.call("start",i,i.__data__,t.index,t.group),t.state===Jr){for(t.state=_n,r=new Array(h=t.tween.length),u=0,f=-1;u<h;++u)(d=t.tween[u].value.call(i,i.__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=Gr,1),f=-1,h=r.length;++f<h;)r[f].call(i,u);t.state===Gr&&(t.on.call("end",i,i.__data__,t.index,t.group),l())}function l(){t.state=xn,t.timer.stop(),delete n[e];for(var c in n)return;delete i.__transition}}function vn(i,e){var t=i.__transition,n,r,s=!0,o;if(t){e=e==null?null:e+"";for(o in t){if((n=t[o]).name!==e){s=!1;continue}r=n.state>Jr&&n.state<Gr,n.state=xn,n.timer.stop(),n.on.call(r?"interrupt":"cancel",i,i.__data__,n.index,n.group),delete t[o]}s&&delete i.__transition}}function Zh(i){return this.each(function(){vn(this,i)})}function ts(i,e,t){i.prototype=e.prototype=t,t.constructor=i}function _a(i,e){var t=Object.create(i.prototype);for(var n in e)t[n]=e[n];return t}function Fi(){}var Mi=.7,bn=1/Mi,si="\\s*([+-]?\\d+)\\s*",Ni="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ht="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Qh=/^#([0-9a-f]{3,8})$/,Jh=new RegExp(`^rgb\\(${si},${si},${si}\\)$`),Gh=new RegExp(`^rgb\\(${ht},${ht},${ht}\\)$`),ed=new RegExp(`^rgba\\(${si},${si},${si},${Ni}\\)$`),td=new RegExp(`^rgba\\(${ht},${ht},${ht},${Ni}\\)$`),id=new RegExp(`^hsl\\(${Ni},${ht},${ht}\\)$`),nd=new RegExp(`^hsla\\(${Ni},${ht},${ht},${Ni}\\)$`),xa={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};ts(Fi,Ft,{copy(i){return Object.assign(new this.constructor,this,i)},displayable(){return this.rgb().displayable()},hex:ya,formatHex:ya,formatHex8:rd,formatHsl:sd,formatRgb:va,toString:va});function ya(){return this.rgb().formatHex()}function rd(){return this.rgb().formatHex8()}function sd(){return Aa(this).formatHsl()}function va(){return this.rgb().formatRgb()}function Ft(i){var e,t;return i=(i+"").trim().toLowerCase(),(e=Qh.exec(i))?(t=e[1].length,e=parseInt(e[1],16),t===6?ba(e):t===3?new Ye(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?Sn(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?Sn(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=Jh.exec(i))?new Ye(e[1],e[2],e[3],1):(e=Gh.exec(i))?new Ye(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=ed.exec(i))?Sn(e[1],e[2],e[3],e[4]):(e=td.exec(i))?Sn(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=id.exec(i))?wa(e[1],e[2]/100,e[3]/100,1):(e=nd.exec(i))?wa(e[1],e[2]/100,e[3]/100,e[4]):xa.hasOwnProperty(i)?ba(xa[i]):i==="transparent"?new Ye(NaN,NaN,NaN,0):null}function ba(i){return new Ye(i>>16&255,i>>8&255,i&255,1)}function Sn(i,e,t,n){return n<=0&&(i=e=t=NaN),new Ye(i,e,t,n)}function od(i){return i instanceof Fi||(i=Ft(i)),i?(i=i.rgb(),new Ye(i.r,i.g,i.b,i.opacity)):new Ye}function is(i,e,t,n){return arguments.length===1?od(i):new Ye(i,e,t,n??1)}function Ye(i,e,t,n){this.r=+i,this.g=+e,this.b=+t,this.opacity=+n}ts(Ye,is,_a(Fi,{brighter(i){return i=i==null?bn:Math.pow(bn,i),new Ye(this.r*i,this.g*i,this.b*i,this.opacity)},darker(i){return i=i==null?Mi:Math.pow(Mi,i),new Ye(this.r*i,this.g*i,this.b*i,this.opacity)},rgb(){return this},clamp(){return new Ye(Lt(this.r),Lt(this.g),Lt(this.b),Tn(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:Sa,formatHex:Sa,formatHex8:ad,formatRgb:Ta,toString:Ta}));function Sa(){return`#${Vt(this.r)}${Vt(this.g)}${Vt(this.b)}`}function ad(){return`#${Vt(this.r)}${Vt(this.g)}${Vt(this.b)}${Vt((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ta(){const i=Tn(this.opacity);return`${i===1?"rgb(":"rgba("}${Lt(this.r)}, ${Lt(this.g)}, ${Lt(this.b)}${i===1?")":`, ${i})`}`}function Tn(i){return isNaN(i)?1:Math.max(0,Math.min(1,i))}function Lt(i){return Math.max(0,Math.min(255,Math.round(i)||0))}function Vt(i){return i=Lt(i),(i<16?"0":"")+i.toString(16)}function wa(i,e,t,n){return n<=0?i=e=t=NaN:t<=0||t>=1?i=e=NaN:e<=0&&(i=NaN),new st(i,e,t,n)}function Aa(i){if(i instanceof st)return new st(i.h,i.s,i.l,i.opacity);if(i instanceof Fi||(i=Ft(i)),!i)return new st;if(i instanceof st)return i;i=i.rgb();var e=i.r/255,t=i.g/255,n=i.b/255,r=Math.min(e,t,n),s=Math.max(e,t,n),o=NaN,a=s-r,l=(s+r)/2;return a?(e===s?o=(t-n)/a+(t<n)*6:t===s?o=(n-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 st(o,a,l,i.opacity)}function ld(i,e,t,n){return arguments.length===1?Aa(i):new st(i,e,t,n??1)}function st(i,e,t,n){this.h=+i,this.s=+e,this.l=+t,this.opacity=+n}ts(st,ld,_a(Fi,{brighter(i){return i=i==null?bn:Math.pow(bn,i),new st(this.h,this.s,this.l*i,this.opacity)},darker(i){return i=i==null?Mi:Math.pow(Mi,i),new st(this.h,this.s,this.l*i,this.opacity)},rgb(){var i=this.h%360+(this.h<0)*360,e=isNaN(i)||isNaN(this.s)?0:this.s,t=this.l,n=t+(t<.5?t:1-t)*e,r=2*t-n;return new Ye(ns(i>=240?i-240:i+120,r,n),ns(i,r,n),ns(i<120?i+240:i-120,r,n),this.opacity)},clamp(){return new st(Ca(this.h),wn(this.s),wn(this.l),Tn(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 i=Tn(this.opacity);return`${i===1?"hsl(":"hsla("}${Ca(this.h)}, ${wn(this.s)*100}%, ${wn(this.l)*100}%${i===1?")":`, ${i})`}`}}));function Ca(i){return i=(i||0)%360,i<0?i+360:i}function wn(i){return Math.max(0,Math.min(1,i||0))}function ns(i,e,t){return(i<60?e+(t-e)*i/60:i<180?t:i<240?e+(t-e)*(240-i)/60:e)*255}const rs=i=>()=>i;function cd(i,e){return function(t){return i+t*e}}function ud(i,e,t){return i=Math.pow(i,t),e=Math.pow(e,t)-i,t=1/t,function(n){return Math.pow(i+n*e,t)}}function fd(i){return(i=+i)==1?Pa:function(e,t){return t-e?ud(e,t,i):rs(isNaN(e)?t:e)}}function Pa(i,e){var t=e-i;return t?cd(i,t):rs(isNaN(i)?e:i)}const An=function i(e){var t=fd(e);function n(r,s){var o=t((r=is(r)).r,(s=is(s)).r),a=t(r.g,s.g),l=t(r.b,s.b),c=Pa(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 n.gamma=i,n}(1);function hd(i,e){e||(e=[]);var t=i?Math.min(e.length,i.length):0,n=e.slice(),r;return function(s){for(r=0;r<t;++r)n[r]=i[r]*(1-s)+e[r]*s;return n}}function dd(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function pd(i,e){var t=e?e.length:0,n=i?Math.min(t,i.length):0,r=new Array(n),s=new Array(t),o;for(o=0;o<n;++o)r[o]=as(i[o],e[o]);for(;o<t;++o)s[o]=e[o];return function(a){for(o=0;o<n;++o)s[o]=r[o](a);return s}}function gd(i,e){var t=new Date;return i=+i,e=+e,function(n){return t.setTime(i*(1-n)+e*n),t}}function ot(i,e){return i=+i,e=+e,function(t){return i*(1-t)+e*t}}function md(i,e){var t={},n={},r;(i===null||typeof i!="object")&&(i={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in i?t[r]=as(i[r],e[r]):n[r]=e[r];return function(s){for(r in t)n[r]=t[r](s);return n}}var ss=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,os=new RegExp(ss.source,"g");function _d(i){return function(){return i}}function xd(i){return function(e){return i(e)+""}}function Ia(i,e){var t=ss.lastIndex=os.lastIndex=0,n,r,s,o=-1,a=[],l=[];for(i=i+"",e=e+"";(n=ss.exec(i))&&(r=os.exec(e));)(s=r.index)>t&&(s=e.slice(t,s),a[o]?a[o]+=s:a[++o]=s),(n=n[0])===(r=r[0])?a[o]?a[o]+=r:a[++o]=r:(a[++o]=null,l.push({i:o,x:ot(n,r)})),t=os.lastIndex;return t<e.length&&(s=e.slice(t),a[o]?a[o]+=s:a[++o]=s),a.length<2?l[0]?xd(l[0].x):_d(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 as(i,e){var t=typeof e,n;return e==null||t==="boolean"?rs(e):(t==="number"?ot:t==="string"?(n=Ft(e))?(e=n,An):Ia:e instanceof Ft?An:e instanceof Date?gd:dd(e)?hd:Array.isArray(e)?pd:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?md:ot)(i,e)}function yd(i,e){return i=+i,e=+e,function(t){return Math.round(i*(1-t)+e*t)}}var ka=180/Math.PI,ls={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ra(i,e,t,n,r,s){var o,a,l;return(o=Math.sqrt(i*i+e*e))&&(i/=o,e/=o),(l=i*t+e*n)&&(t-=i*l,n-=e*l),(a=Math.sqrt(t*t+n*n))&&(t/=a,n/=a,l/=a),i*n<e*t&&(i=-i,e=-e,l=-l,o=-o),{translateX:r,translateY:s,rotate:Math.atan2(e,i)*ka,skewX:Math.atan(l)*ka,scaleX:o,scaleY:a}}var Cn;function vd(i){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(i+"");return e.isIdentity?ls:Ra(e.a,e.b,e.c,e.d,e.e,e.f)}function bd(i){return i==null||(Cn||(Cn=document.createElementNS("http://www.w3.org/2000/svg","g")),Cn.setAttribute("transform",i),!(i=Cn.transform.baseVal.consolidate()))?ls:(i=i.matrix,Ra(i.a,i.b,i.c,i.d,i.e,i.f))}function Ea(i,e,t,n){function r(c){return c.length?c.pop()+" ":""}function s(c,u,f,h,d,_){if(c!==f||u!==h){var P=d.push("translate(",null,e,null,t);_.push({i:P-4,x:ot(c,f)},{i:P-2,x:ot(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,n)-2,x:ot(c,u)})):u&&f.push(r(f)+"rotate("+u+n)}function a(c,u,f,h){c!==u?h.push({i:f.push(r(f)+"skewX(",null,n)-2,x:ot(c,u)}):u&&f.push(r(f)+"skewX("+u+n)}function l(c,u,f,h,d,_){if(c!==f||u!==h){var P=d.push(r(d)+"scale(",null,",",null,")");_.push({i:P-4,x:ot(c,f)},{i:P-2,x:ot(u,h)})}else(f!==1||h!==1)&&d.push(r(d)+"scale("+f+","+h+")")}return function(c,u){var f=[],h=[];return c=i(c),u=i(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,P=h.length,I;++_<P;)f[(I=h[_]).i]=I.x(d);return f.join("")}}}var Sd=Ea(vd,"px, ","px)","deg)"),Td=Ea(bd,", ",")",")"),wd=1e-12;function Da(i){return((i=Math.exp(i))+1/i)/2}function Ad(i){return((i=Math.exp(i))-1/i)/2}function Cd(i){return((i=Math.exp(2*i))-1)/(i+1)}const Pd=function i(e,t,n){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,P=d*d+_*_,I,w;if(P<wd)w=Math.log(h/c)/e,I=function(U){return[a+U*d,l+U*_,c*Math.exp(e*U*w)]};else{var M=Math.sqrt(P),k=(h*h-c*c+n*P)/(2*c*t*M),y=(h*h-c*c-n*P)/(2*h*t*M),R=Math.log(Math.sqrt(k*k+1)-k),B=Math.log(Math.sqrt(y*y+1)-y);w=(B-R)/e,I=function(U){var W=U*w,q=Da(R),Q=c/(t*M)*(q*Cd(e*W+R)-Ad(R));return[a+Q*d,l+Q*_,c*q/Da(e*W+R)]}}return I.duration=w*1e3*e/Math.SQRT2,I}return r.rho=function(s){var o=Math.max(.001,+s),a=o*o,l=a*a;return i(o,a,l)},r}(Math.SQRT2,2,4);function Id(i,e){var t,n;return function(){var r=ft(this,i),s=r.tween;if(s!==t){n=t=s;for(var o=0,a=n.length;o<a;++o)if(n[o].name===e){n=n.slice(),n.splice(o,1);break}}r.tween=n}}function kd(i,e,t){var n,r;if(typeof t!="function")throw new Error;return function(){var s=ft(this,i),o=s.tween;if(o!==n){r=(n=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 Rd(i,e){var t=this._id;if(i+="",arguments.length<2){for(var n=rt(this.node(),t).tween,r=0,s=n.length,o;r<s;++r)if((o=n[r]).name===i)return o.value;return null}return this.each((e==null?Id:kd)(t,i,e))}function cs(i,e,t){var n=i._id;return i.each(function(){var r=ft(this,n);(r.value||(r.value={}))[e]=t.apply(this,arguments)}),function(r){return rt(r,n).value[e]}}function Fa(i,e){var t;return(typeof e=="number"?ot:e instanceof Ft?An:(t=Ft(e))?(e=t,An):Ia)(i,e)}function Ed(i){return function(){this.removeAttribute(i)}}function Dd(i){return function(){this.removeAttributeNS(i.space,i.local)}}function Fd(i,e,t){var n,r=t+"",s;return function(){var o=this.getAttribute(i);return o===r?null:o===n?s:s=e(n=o,t)}}function Md(i,e,t){var n,r=t+"",s;return function(){var o=this.getAttributeNS(i.space,i.local);return o===r?null:o===n?s:s=e(n=o,t)}}function Nd(i,e,t){var n,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttribute(i):(o=this.getAttribute(i),l=a+"",o===l?null:o===n&&l===r?s:(r=l,s=e(n=o,a)))}}function Od(i,e,t){var n,r,s;return function(){var o,a=t(this),l;return a==null?void this.removeAttributeNS(i.space,i.local):(o=this.getAttributeNS(i.space,i.local),l=a+"",o===l?null:o===n&&l===r?s:(r=l,s=e(n=o,a)))}}function Bd(i,e){var t=cn(i),n=t==="transform"?Td:Fa;return this.attrTween(i,typeof e=="function"?(t.local?Od:Nd)(t,n,cs(this,"attr."+i,e)):e==null?(t.local?Dd:Ed)(t):(t.local?Md:Fd)(t,n,e))}function Ud(i,e){return function(t){this.setAttribute(i,e.call(this,t))}}function zd(i,e){return function(t){this.setAttributeNS(i.space,i.local,e.call(this,t))}}function Ld(i,e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&zd(i,s)),t}return r._value=e,r}function Vd(i,e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&Ud(i,s)),t}return r._value=e,r}function Wd(i,e){var t="attr."+i;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 n=cn(i);return this.tween(t,(n.local?Ld:Vd)(n,e))}function Hd(i,e){return function(){es(this,i).delay=+e.apply(this,arguments)}}function $d(i,e){return e=+e,function(){es(this,i).delay=e}}function Xd(i){var e=this._id;return arguments.length?this.each((typeof i=="function"?Hd:$d)(e,i)):rt(this.node(),e).delay}function Yd(i,e){return function(){ft(this,i).duration=+e.apply(this,arguments)}}function qd(i,e){return e=+e,function(){ft(this,i).duration=e}}function jd(i){var e=this._id;return arguments.length?this.each((typeof i=="function"?Yd:qd)(e,i)):rt(this.node(),e).duration}function Kd(i,e){if(typeof e!="function")throw new Error;return function(){ft(this,i).ease=e}}function Zd(i){var e=this._id;return arguments.length?this.each(Kd(e,i)):rt(this.node(),e).ease}function Qd(i,e){return function(){var t=e.apply(this,arguments);if(typeof t!="function")throw new Error;ft(this,i).ease=t}}function Jd(i){if(typeof i!="function")throw new Error;return this.each(Qd(this._id,i))}function Gd(i){typeof i!="function"&&(i=Jo(i));for(var e=this._groups,t=e.length,n=new Array(t),r=0;r<t;++r)for(var s=e[r],o=s.length,a=n[r]=[],l,c=0;c<o;++c)(l=s[c])&&i.call(l,l.__data__,c,s)&&a.push(l);return new Tt(n,this._parents,this._name,this._id)}function ep(i){if(i._id!==this._id)throw new Error;for(var e=this._groups,t=i._groups,n=e.length,r=t.length,s=Math.min(n,r),o=new Array(n),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<n;++a)o[a]=e[a];return new Tt(o,this._parents,this._name,this._id)}function tp(i){return(i+"").trim().split(/^|\s+/).every(function(e){var t=e.indexOf(".");return t>=0&&(e=e.slice(0,t)),!e||e==="start"})}function ip(i,e,t){var n,r,s=tp(e)?es:ft;return function(){var o=s(this,i),a=o.on;a!==n&&(r=(n=a).copy()).on(e,t),o.on=r}}function np(i,e){var t=this._id;return arguments.length<2?rt(this.node(),t).on.on(i):this.each(ip(t,i,e))}function rp(i){return function(){var e=this.parentNode;for(var t in this.__transition)if(+t!==i)return;e&&e.removeChild(this)}}function sp(){return this.on("end.remove",rp(this._id))}function op(i){var e=this._name,t=this._id;typeof i!="function"&&(i=jr(i));for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o)for(var a=n[o],l=a.length,c=s[o]=new Array(l),u,f,h=0;h<l;++h)(u=a[h])&&(f=i.call(u,u.__data__,h,a))&&("__data__"in u&&(f.__data__=u.__data__),c[h]=f,yn(c[h],e,t,h,c,rt(u,t)));return new Tt(s,this._parents,e,t)}function ap(i){var e=this._name,t=this._id;typeof i!="function"&&(i=Qo(i));for(var n=this._groups,r=n.length,s=[],o=[],a=0;a<r;++a)for(var l=n[a],c=l.length,u,f=0;f<c;++f)if(u=l[f]){for(var h=i.call(u,u.__data__,f,l),d,_=rt(u,t),P=0,I=h.length;P<I;++P)(d=h[P])&&yn(d,e,t,P,h,_);s.push(h),o.push(u)}return new Tt(s,o,e,t)}var lp=Ii.prototype.constructor;function cp(){return new lp(this._groups,this._parents)}function up(i,e){var t,n,r;return function(){var s=ni(this,i),o=(this.style.removeProperty(i),ni(this,i));return s===o?null:s===t&&o===n?r:r=e(t=s,n=o)}}function Ma(i){return function(){this.style.removeProperty(i)}}function fp(i,e,t){var n,r=t+"",s;return function(){var o=ni(this,i);return o===r?null:o===n?s:s=e(n=o,t)}}function hp(i,e,t){var n,r,s;return function(){var o=ni(this,i),a=t(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(i),ni(this,i))),o===l?null:o===n&&l===r?s:(r=l,s=e(n=o,a))}}function dp(i,e){var t,n,r,s="style."+e,o="end."+s,a;return function(){var l=ft(this,i),c=l.on,u=l.value[s]==null?a||(a=Ma(e)):void 0;(c!==t||r!==u)&&(n=(t=c).copy()).on(o,r=u),l.on=n}}function pp(i,e,t){var n=(i+="")=="transform"?Sd:Fa;return e==null?this.styleTween(i,up(i,n)).on("end.style."+i,Ma(i)):typeof e=="function"?this.styleTween(i,hp(i,n,cs(this,"style."+i,e))).each(dp(this._id,i)):this.styleTween(i,fp(i,n,e),t).on("end.style."+i,null)}function gp(i,e,t){return function(n){this.style.setProperty(i,e.call(this,n),t)}}function mp(i,e,t){var n,r;function s(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&gp(i,o,t)),n}return s._value=e,s}function _p(i,e,t){var n="style."+(i+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,mp(i,e,t??""))}function xp(i){return function(){this.textContent=i}}function yp(i){return function(){var e=i(this);this.textContent=e??""}}function vp(i){return this.tween("text",typeof i=="function"?yp(cs(this,"text",i)):xp(i==null?"":i+""))}function bp(i){return function(e){this.textContent=i.call(this,e)}}function Sp(i){var e,t;function n(){var r=i.apply(this,arguments);return r!==t&&(e=(t=r)&&bp(r)),e}return n._value=i,n}function Tp(i){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(i==null)return this.tween(e,null);if(typeof i!="function")throw new Error;return this.tween(e,Sp(i))}function wp(){for(var i=this._name,e=this._id,t=Na(),n=this._groups,r=n.length,s=0;s<r;++s)for(var o=n[s],a=o.length,l,c=0;c<a;++c)if(l=o[c]){var u=rt(l,e);yn(l,i,t,c,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Tt(n,this._parents,i,t)}function Ap(){var i,e,t=this,n=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,n),u=c.on;u!==i&&(e=(i=u).copy(),e._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),c.on=e}),r===0&&s()})}var Cp=0;function Tt(i,e,t,n){this._groups=i,this._parents=e,this._name=t,this._id=n}function Na(){return++Cp}var wt=Ii.prototype;Tt.prototype={constructor:Tt,select:op,selectAll:ap,selectChild:wt.selectChild,selectChildren:wt.selectChildren,filter:Gd,merge:ep,selection:cp,transition:wp,call:wt.call,nodes:wt.nodes,node:wt.node,size:wt.size,empty:wt.empty,each:wt.each,on:np,attr:Bd,attrTween:Wd,style:pp,styleTween:_p,text:vp,textTween:Tp,remove:sp,tween:Rd,delay:Xd,duration:jd,ease:Zd,easeVarying:Jd,end:Ap,[Symbol.iterator]:wt[Symbol.iterator]};const Oa=i=>+i;function Ba(i){return i*i}function Ua(i){return i*(2-i)}function za(i){return((i*=2)<=1?i*i:--i*(2-i)+1)/2}function Pp(i){return i*i*i}function Ip(i){return--i*i*i+1}function La(i){return((i*=2)<=1?i*i*i:(i-=2)*i*i+2)/2}var Va=Math.PI,Wa=Va/2;function kp(i){return+i==1?1:1-Math.cos(i*Wa)}function Rp(i){return Math.sin(i*Wa)}function Ep(i){return(1-Math.cos(Va*i))/2}function Pn(i){return(Math.pow(2,-10*i)-.0009765625)*1.0009775171065494}function Dp(i){return Pn(1-+i)}function Fp(i){return 1-Pn(i)}function Mp(i){return((i*=2)<=1?Pn(1-i):2-Pn(i-1))/2}function Np(i){return 1-Math.sqrt(1-i*i)}function Op(i){return Math.sqrt(1- --i*i)}function Bp(i){return((i*=2)<=1?1-Math.sqrt(1-i*i):Math.sqrt(1-(i-=2)*i)+1)/2}var Up={time:null,delay:0,duration:250,ease:La};function zp(i,e){for(var t;!(t=i.__transition)||!(t=t[e]);)if(!(i=i.parentNode))throw new Error(`transition ${e} not found`);return t}function Lp(i){var e,t;i instanceof Tt?(e=i._id,i=i._name):(e=Na(),(t=Up).time=Zr(),i=i==null?null:i+"");for(var n=this._groups,r=n.length,s=0;s<r;++s)for(var o=n[s],a=o.length,l,c=0;c<a;++c)(l=o[c])&&yn(l,i,e,c,o,t||zp(l,e));return new Tt(n,this._parents,i,e)}Ii.prototype.interrupt=Zh,Ii.prototype.transition=Lp;function Ha(){let i;if(typeof window<"u"&&window.performance)i=window.performance.now();else if(typeof process<"u"&&process.hrtime){const e=process.hrtime();i=e[0]*1e3+e[1]/1e6}else i=Date.now();return i}class $a{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=Ha(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Ha()-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 Vp{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:n}=e;let r=this.stats[t];return r||(e instanceof $a?r=e:r=new $a(t,n),this.stats[t]=r),r}}class Wp{constructor(){g(this,"stats",new Map)}getStats(e){return this.get(e)}get(e){return this.stats.has(e)||this.stats.set(e,new Vp({id:e})),this.stats.get(e)}}const Xa=new Wp,In=globalThis,oi=globalThis.process||{},Hp=globalThis.navigator||{};function Ya(i){var n,r;if(typeof window<"u"&&((n=window.process)==null?void 0:n.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 Wt(){return!(typeof process=="object"&&String(process)==="[object process]"&&!(process!=null&&process.browser))||Ya()}function $p(i){return Wt()?Ya()?"Electron":(Hp.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown":"Node"}const qa="4.1.0";function Xp(i){try{const e=window[i],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}class Yp{constructor(e,t,n="sessionStorage"){this.storage=Xp(n),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 qp(i){let e;return i<10?e=`${i.toFixed(2)}ms`:i<100?e=`${i.toFixed(1)}ms`:i<1e3?e=`${i.toFixed(0)}ms`:e=`${(i/1e3).toFixed(2)}s`,e}function jp(i,e=8){const t=Math.max(e-i.length,0);return`${" ".repeat(t)}${i}`}var kn;(function(i){i[i.BLACK=30]="BLACK",i[i.RED=31]="RED",i[i.GREEN=32]="GREEN",i[i.YELLOW=33]="YELLOW",i[i.BLUE=34]="BLUE",i[i.MAGENTA=35]="MAGENTA",i[i.CYAN=36]="CYAN",i[i.WHITE=37]="WHITE",i[i.BRIGHT_BLACK=90]="BRIGHT_BLACK",i[i.BRIGHT_RED=91]="BRIGHT_RED",i[i.BRIGHT_GREEN=92]="BRIGHT_GREEN",i[i.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",i[i.BRIGHT_BLUE=94]="BRIGHT_BLUE",i[i.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",i[i.BRIGHT_CYAN=96]="BRIGHT_CYAN",i[i.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(kn||(kn={}));const Kp=10;function ja(i){return typeof i!="string"?i:(i=i.toUpperCase(),kn[i]||kn.WHITE)}function Zp(i,e,t){return!Wt&&typeof i=="string"&&(e&&(i=`\x1B[${ja(e)}m${i}\x1B[39m`),t&&(i=`\x1B[${ja(t)+Kp}m${i}\x1B[49m`)),i}function Qp(i,e=["constructor"]){const t=Object.getPrototypeOf(i),n=Object.getOwnPropertyNames(t),r=i;for(const s of n){const o=r[s];typeof o=="function"&&(e.find(a=>s===a)||(r[s]=o.bind(i)))}}function us(i,e){if(!i)throw new Error("Assertion failed")}function ai(){var e,t,n;let i;if(Wt()&&In.performance)i=(t=(e=In==null?void 0:In.performance)==null?void 0:e.now)==null?void 0:t.call(e);else if("hrtime"in oi){const r=(n=oi==null?void 0:oi.hrtime)==null?void 0:n.call(oi);i=r[0]*1e3+r[1]/1e6}else i=Date.now();return i}const li={debug:Wt()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},Jp={enabled:!0,level:0};function ci(){}const Ka={},Za={once:!0};class Qa{constructor({id:e}={id:""}){this.VERSION=qa,this._startTs=ai(),this._deltaTs=ai(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new Yp(`__probe-${this.id}__`,Jp),this.timeStamp(`${this.id} started`),Qp(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((ai()-this._startTs).toPrecision(10))}getDelta(){return Number((ai()-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,li.warn,arguments,Za)}error(e){return this._getLogFunction(0,e,li.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,li.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,li.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,li.debug||li.info,arguments,Za)}table(e,t,n){return t?this._getLogFunction(e,t,console.table||ci,n&&[n],{tag:eg(t)}):ci}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||ci)}group(e,t,n={collapsed:!1}){const r=Ga({logLevel:e,message:t,opts:n}),{collapsed:s}=n;return r.method=(s?console.groupCollapsed:console.group)||console.info,this._getLogFunction(r)}groupCollapsed(e,t,n={}){return this.group(e,t,Object.assign({},n,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||ci)}withGroup(e,t,n){this.group(e,t)();try{n()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=Ja(e)}_getLogFunction(e,t,n,r,s){if(this._shouldLog(e)){s=Ga({logLevel:e,message:t,args:r,opts:s}),n=n||s.method,us(n),s.total=this.getTotal(),s.delta=this.getDelta(),this._deltaTs=ai();const o=s.tag||s.message;if(s.once&&o)if(!Ka[o])Ka[o]=ai();else return ci;return t=Gp(this.id,s.message,s),n.bind(console,t,...s.args)}return ci}}Qa.VERSION=qa;function Ja(i){if(!i)return 0;let e;switch(typeof i){case"number":e=i;break;case"object":e=i.logLevel||i.priority||0;break;default:return 0}return us(Number.isFinite(e)&&e>=0),e}function Ga(i){const{logLevel:e,message:t}=i;i.logLevel=Ja(e);const n=i.args?Array.from(i.args):[];for(;n.length&&n.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&n.unshift(t),i.message=e;break;case"object":Object.assign(i,e);break}typeof i.message=="function"&&(i.message=i.message());const r=typeof i.message;return us(r==="string"||r==="object"),Object.assign(i,{args:n},i.opts)}function Gp(i,e,t){if(typeof e=="string"){const n=t.time?jp(qp(t.total)):"";e=t.time?`${i}: ${n} ${e}`:`${i}: ${e}`,e=Zp(e,t.color,t.background)}return e}function eg(i){for(const e in i)for(const t in i[e])return t||"untitled";return"empty"}const D=new Qa({id:"luma.gl"}),fs={};function Rn(i="id"){fs[i]=fs[i]||1;const e=fs[i]++;return`${i}-${e}`}class ce{constructor(e,t,n){g(this,"id");g(this,"props");g(this,"userData",{});g(this,"_device");g(this,"destroyed",!1);g(this,"allocatedBytes",0);g(this,"_attachedResources",new Set);if(!e)throw new Error("no device");this._device=e,this.props=tg(t,n);const r=this.props.id!=="undefined"?this.props.id:Rn(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 n=this._device.statsManager.getStats("Resource Counts");n.get("GPU Memory").addCount(e),n.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()}}g(ce,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function tg(i,e){const t={...e};for(const n in i)i[n]!==void 0&&(t[n]=i[n]);return t}const De=class De extends ce{constructor(t,n){const r={...n};(n.usage||0)&De.INDEX&&!n.indexType&&(n.data instanceof Uint32Array?r.indexType="uint32":n.data instanceof Uint16Array?r.indexType="uint16":n.data instanceof Uint8Array&&(r.indexType="uint8")),delete r.data;super(t,r,De.defaultProps);g(this,"usage");g(this,"indexType");g(this,"updateTimestamp");g(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,n,r){const s=ArrayBuffer.isView(t)?t.buffer:t,o=Math.min(t?t.byteLength:r,De.DEBUG_DATA_MAX_LENGTH);s===null?this.debugData=new ArrayBuffer(o):n===0&&r===s.byteLength?this.debugData=s.slice(0,o):this.debugData=s.slice(n,n+o)}};g(De,"INDEX",16),g(De,"VERTEX",32),g(De,"UNIFORM",64),g(De,"STORAGE",128),g(De,"INDIRECT",256),g(De,"QUERY_RESOLVE",512),g(De,"MAP_READ",1),g(De,"MAP_WRITE",2),g(De,"COPY_SRC",4),g(De,"COPY_DST",8),g(De,"DEBUG_DATA_MAX_LENGTH",32),g(De,"defaultProps",{...ce.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",onMapped:void 0});let H=De;function el(i){const[e,t,n]=hs[i],r=i.includes("norm"),s=!r&&!i.startsWith("float"),o=i.startsWith("s");return{signedType:e,primitiveType:t,byteLength:n,normalized:r,integer:s,signed:o}}function ig(i){const e=i;switch(e){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return e}}function ng(i,e){switch(e){case 1:return i;case 2:return i+i%2;default:return i+(4-i%4)%4}}function tl(i){const e=ArrayBuffer.isView(i)?i.constructor:i;if(e===Uint8ClampedArray)return"uint8";const t=Object.values(hs).find(n=>e===n[4]);if(!t)throw new Error(e.name);return t[0]}function il(i){const[,,,,e]=hs[i];return e}const hs={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 ds(i){let e;i.endsWith("-webgl")&&(i.replace("-webgl",""),e=!0);const[t,n]=i.split("x"),r=t,s=n?parseInt(n):1,o=el(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 rg(i,e,t){const n=t?ig(i):i;switch(n){case"unorm8":return e===1?"unorm8":e===3?"unorm8x3-webgl":`${n}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`${n}x${e}`;default:return e===1?n:`${n}x${e}`}}function sg(i,e,t){if(!e||e>4)throw new Error(`size ${e}`);const n=e,r=tl(i);return rg(r,n,t)}function og(i){let e;switch(i.primitiveType){case"f32":e="float32";break;case"i32":e="sint32";break;case"u32":e="uint32";break;case"f16":return i.components<=2?"float16x2":"float16x4"}return i.components===1?e:`${e}x${i.components}`}const Me="texture-compression-bc",ue="texture-compression-astc",dt="texture-compression-etc2",ag="texture-compression-etc1-webgl",En="texture-compression-pvrtc-webgl",ps="texture-compression-atc-webgl",Dn="float32-renderable-webgl",gs="float16-renderable-webgl",lg="rgb9e5ufloat-renderable-webgl",ms="snorm8-renderable-webgl",Oi="norm16-renderable-webgl",_s="snorm16-renderable-webgl",Fn="float32-filterable",nl="float16-filterable-webgl";function rl(i){const e=cg[i];if(!e)throw new Error(`Unsupported texture format ${i}`);return e}const cg={...{r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:ms},rg8snorm:{render:ms},"rgb8snorm-webgl":{},rgba8snorm:{render:ms},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:Oi},rg16unorm:{render:Oi},"rgb16unorm-webgl":{f:Oi},rgba16unorm:{render:Oi},r16snorm:{f:_s},rg16snorm:{render:_s},"rgb16snorm-webgl":{f:Oi},rgba16snorm:{render:_s},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:gs,filter:"float16-filterable-webgl"},rg16float:{render:gs,filter:nl},rgba16float:{render:gs,filter:nl},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Dn,filter:Fn},rg32float:{render:!1,filter:Fn},"rgb32float-webgl":{render:Dn,filter:Fn},rgba32float:{render:Dn,filter:Fn},"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:lg},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Dn},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:Me},"bc1-rgb-unorm-srgb-webgl":{f:Me},"bc1-rgba-unorm":{f:Me},"bc1-rgba-unorm-srgb":{f:Me},"bc2-rgba-unorm":{f:Me},"bc2-rgba-unorm-srgb":{f:Me},"bc3-rgba-unorm":{f:Me},"bc3-rgba-unorm-srgb":{f:Me},"bc4-r-unorm":{f:Me},"bc4-r-snorm":{f:Me},"bc5-rg-unorm":{f:Me},"bc5-rg-snorm":{f:Me},"bc6h-rgb-ufloat":{f:Me},"bc6h-rgb-float":{f:Me},"bc7-rgba-unorm":{f:Me},"bc7-rgba-unorm-srgb":{f:Me},"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:En},"pvrtc-rgba4unorm-webgl":{f:En},"pvrtc-rbg2unorm-webgl":{f:En},"pvrtc-rgba2unorm-webgl":{f:En},"etc1-rbg-unorm-webgl":{f:ag},"atc-rgb-unorm-webgl":{f:ps},"atc-rgba-unorm-webgl":{f:ps},"atc-rgbai-unorm-webgl":{f:ps}}},ug=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],fg=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;class hg{getInfo(e){return sl(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 ug.some(t=>e.startsWith(t))}getCapabilities(e){const t=rl(e),n={format:e,create:t.f??!0,render:t.render??!0,filter:t.filter??!0,blend:t.blend??!0,store:t.store??!0},r=sl(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 n.render&&(n.render=!o),n.filter&&(n.filter=!s&&!o&&!a&&!l),n}}const Ht=new hg;function sl(i){let e=dg(i);if(Ht.isCompressed(i)){e.channels="rgb",e.components=3,e.bytesPerPixel=1,e.srgb=!1,e.compressed=!0;const n=pg(i);n&&(e.blockWidth=n.blockWidth,e.blockHeight=n.blockHeight)}const t=fg.exec(i);if(t){const[,n,r,s,o,a]=t,l=`${s}${r}`,c=el(l),u=c.byteLength*8,f=n.length,h=[u,f>=2?u:0,f>=3?u:0,f>=4?u:0];e={format:i,attachment:e.attachment,dataType:c.signedType,components:f,channels:n,integer:c.integer,signed:c.signed,normalized:c.normalized,bitsPerChannel:h,bytesPerPixel:c.byteLength*n.length,packed:e.packed,srgb:e.srgb},a==="-webgl"&&(e.webgl=!0),o==="-srgb"&&(e.srgb=!0)}return i.endsWith("-webgl")&&(e.webgl=!0),i.endsWith("-srgb")&&(e.srgb=!0),e}function dg(i){var s;const e=rl(i),t=e.bytesPerPixel||1,n=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:i,attachment:e.attachment||"color",channels:e.channels||"r",components:e.components||((s=e.channels)==null?void 0:s.length)||1,bytesPerPixel:t,bitsPerChannel:n,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 pg(i){const t=/.*-(\d+)x(\d+)-.*/.exec(i);if(t){const[,n,r]=t;return{blockWidth:Number(n),blockHeight:Number(r)}}return null}function gg(i){return typeof ImageData<"u"&&i instanceof ImageData||typeof ImageBitmap<"u"&&i instanceof ImageBitmap||typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement||typeof HTMLVideoElement<"u"&&i instanceof HTMLVideoElement||typeof VideoFrame<"u"&&i instanceof VideoFrame||typeof HTMLCanvasElement<"u"&&i instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas}function mg(i){if(typeof ImageData<"u"&&i instanceof ImageData||typeof ImageBitmap<"u"&&i instanceof ImageBitmap||typeof HTMLCanvasElement<"u"&&i instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas)return{width:i.width,height:i.height};if(typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement)return{width:i.naturalWidth,height:i.naturalHeight};if(typeof HTMLVideoElement<"u"&&i instanceof HTMLVideoElement)return{width:i.videoWidth,height:i.videoHeight};if(typeof VideoFrame<"u"&&i instanceof VideoFrame)return{width:i.displayWidth,height:i.displayHeight};throw new Error("Unknown image type")}class _g{}class xg{constructor(e=[],t){g(this,"features");g(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 Cr=class Cr{constructor(e){g(this,"id");g(this,"props");g(this,"userData",{});g(this,"statsManager",Xa);g(this,"timestamp",0);g(this,"_reused",!1);g(this,"_lumaData",{});g(this,"_textureCaps",{});this.props={...Cr.defaultProps,...e},this.id=this.props.id||Rn(this[Symbol.toStringTag].toLowerCase())}get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}getVertexFormatInfo(e){return ds(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return Ht.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){const n=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(n),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,n=1){const r=Math.max(e,t,n);return 1+Math.floor(Math.log2(r))}isExternalImage(e){return gg(e)}getExternalImageSize(e){return mg(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,...n){return this.props.onError(e,t)?()=>{}:D.error(e.message,t,...n)}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),n=s=>(typeof s=="string"?this.features.has(s):s)??!0,r=n(t.create);return{format:e,create:r,render:r&&n(t.render),filter:r&&n(t.filter),blend:r&&n(t.blend),store:r&&n(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});const t={...e};if((e.usage||0)&H.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}};g(Cr,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{const[n,r]=e.getDevicePixelSize();D.log(1,`${e} resized => ${n}x${r}px`)()},onPositionChange:(e,t)=>{const[n,r]=e.getPosition();D.log(1,`${e} repositioned => ${n},${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 $t=Cr;const yg="set luma.log.level=1 (or higher) to trace rendering",ol="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",sn=class sn{constructor(){g(this,"stats",Xa);g(this,"log",D);g(this,"VERSION","9.2.6");g(this,"spector");g(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} - ${yg}`)(),globalThis.luma=this}async createDevice(e={}){const t={...sn.defaultProps,...e},n=this.selectAdapter(t.type,t.adapters);if(!n)throw new Error(ol);return t.waitForPageLoad&&await n.pageLoaded,await n.create(t)}async attachDevice(e,t){var s;const n=this._getTypeFromHandle(e,t.adapters),r=n&&this.selectAdapter(n,t.adapters);if(!r)throw new Error(ol);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(([,n])=>n).filter(n=>{var r;return(r=n.isSupported)==null?void 0:r.call(n)}).map(n=>n.type)}getBestAvailableAdapterType(e=[]){var r,s;const t=["webgpu","webgl","null"],n=this._getAdapterMap(e);for(const o of t)if((s=(r=n.get(o))==null?void 0:r.isSupported)!=null&&s.call(r))return o;return null}selectAdapter(e,t=[]){let n=e;e==="best-available"&&(n=this.getBestAvailableAdapterType(t));const r=this._getAdapterMap(t);return n&&r.get(n)||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(sn.defaultProps,e)}_getAdapterMap(e=[]){const t=new Map(this.preregisteredAdapters);for(const n of e)t.set(n.type,n);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)}};g(sn,"defaultProps",{...$t.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});let xs=sn;const vg=new xs;class bg{get pageLoaded(){return wg()}}const Sg=Wt()&&typeof document<"u",Tg=()=>Sg&&document.readyState==="complete";let Mn=null;function wg(){return Mn||(Tg()||typeof window>"u"?Mn=Promise.resolve():Mn=new Promise(i=>window.addEventListener("load",()=>i()))),Mn}function Ag(){let i,e;return{promise:new Promise((n,r)=>{i=n,e=r}),resolve:i,reject:e}}const Gt=class Gt{constructor(e){g(this,"id");g(this,"props");g(this,"canvas");g(this,"htmlCanvas");g(this,"offscreenCanvas");g(this,"type");g(this,"initialized");g(this,"isInitialized",!1);g(this,"isVisible",!0);g(this,"cssWidth");g(this,"cssHeight");g(this,"devicePixelRatio");g(this,"devicePixelWidth");g(this,"devicePixelHeight");g(this,"drawingBufferWidth");g(this,"drawingBufferHeight");g(this,"_initializedResolvers",Ag());g(this,"_resizeObserver");g(this,"_intersectionObserver");g(this,"_position");g(this,"destroyed",!1);var t,n;if(this.props={...Gt.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,Wt()?e.canvas?typeof e.canvas=="string"?this.canvas=Pg(e.canvas):this.canvas=e.canvas:this.canvas=Ig(e):this.canvas={width:e.width||1,height:e.height||1},Gt.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):Gt.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=((n=this.htmlCanvas)==null?void 0:n.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],Gt.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 n=this.cssToDeviceRatio(),[r,s]=this.getDrawingBufferSize();return kg(e,n,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 n=t.isIntersecting;this.isVisible!==n&&(this.isVisible=n,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 n=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:n})}_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,n,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=(n=this.device.props).onPositionChange)==null||r.call(n,this,{oldPosition:a})}}}};g(Gt,"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 Nn=Gt;function Cg(i){if(typeof i=="string"){const e=document.getElementById(i);if(!e)throw new Error(`${i} is not an HTML element`);return e}return i||document.body}function Pg(i){const e=document.getElementById(i);if(!Nn.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function Ig(i){const{width:e,height:t}=i,n=document.createElement("canvas");n.id=Rn("lumagl-auto-created-canvas"),n.width=e||1,n.height=t||1,n.style.width=Number.isFinite(e)?`${e}px`:"100%",n.style.height=Number.isFinite(t)?`${t}px`:"100%",i!=null&&i.visible||(n.style.visibility="hidden");const r=Cg((i==null?void 0:i.container)||null);return r.insertBefore(n,r.firstChild),n}function kg(i,e,t,n,r){const s=i,o=al(s[0],e,t);let a=ll(s[1],e,n,r),l=al(s[0]+1,e,t);const c=l===t-1?l:l-1;l=ll(s[1]+1,e,n,r);let u;return r?(l=l===0?l:l+1,u=a,a=l):u=l===n-1?l:l-1,{x:o,y:a,width:Math.max(c-o+1,1),height:Math.max(u-a+1,1)}}function al(i,e,t){return Math.min(Math.round(i*e),t-1)}function ll(i,e,t,n){return n?Math.max(0,t-1-Math.round(i*e)):Math.min(Math.round(i*e),t-1)}const on=class on extends ce{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){t=on.normalizeProps(e,t),super(e,t,on.defaultProps)}static normalizeProps(e,t){return t}};g(on,"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 ui=on;const Rg={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},Ie=class Ie extends ce{constructor(t,n){n=Ie.normalizeProps(t,n);super(t,n,Ie.defaultProps);g(this,"dimension");g(this,"baseDimension");g(this,"format");g(this,"width");g(this,"height");g(this,"depth");g(this,"mipLevels");g(this,"updateTimestamp");if(this.dimension=this.props.dimension,this.baseDimension=Rg[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(n.data)){const r=t.getExternalImageSize(n.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 ui?t:this.device.createSampler(t)}clone(t){return this.device.createTexture({...this.props,...t})}static normalizeProps(t,n){const r={...n},{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:n,height:r,depth:s}=this,o={...Ie.defaultCopyDataOptions,width:n,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||n*(a.bytesPerPixel||4),o.rowsPerImage=t.rowsPerImage||r,o}_normalizeCopyExternalImageOptions(t){const n=this.device.getExternalImageSize(t.image),r={...Ie.defaultCopyExternalImageOptions,...n,...t};return r.width=Math.min(r.width,this.width-r.x),r.height=Math.min(r.height,this.height-r.y),r}};g(Ie,"SAMPLE",4),g(Ie,"STORAGE",8),g(Ie,"RENDER",16),g(Ie,"COPY_SRC",1),g(Ie,"COPY_DST",2),g(Ie,"TEXTURE",4),g(Ie,"RENDER_ATTACHMENT",16),g(Ie,"defaultProps",{...ce.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:Ie.TEXTURE|Ie.RENDER_ATTACHMENT|Ie.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),g(Ie,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),g(Ie,"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 X=Ie;const Pr=class Pr extends ce{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,Pr.defaultProps)}};g(Pr,"defaultProps",{...ce.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});let On=Pr;function Eg(i,e,t){let n="";const r=e.split(/\r?\n/),s=i.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(n+=cl(r[a-1],a,t);s.length>o&&s[o].lineNum===a;){const l=s[o++];n+=ys(l,r,l.lineNum,{...t,inlineSource:!1})}for(;s.length>o;){const a=s[o++];n+=ys(a,[],0,{...t,inlineSource:!1})}return n;case"issues":case"no":for(const a of i)n+=ys(a,r,a.lineNum,{inlineSource:(t==null?void 0:t.showSourceCode)!=="no"});return n}}function ys(i,e,t,n){if(n!=null&&n.inlineSource){const s=Dg(e,t),o=i.linePos>0?`${" ".repeat(i.linePos+5)}^^^
3
3
  `:"";return`
4
- ${s}${o}${n.type.toUpperCase()}: ${n.message}
4
+ ${s}${o}${i.type.toUpperCase()}: ${i.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 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=`
6
+ `}const r=i.type==="error"?"red":"#8B4000";return n!=null&&n.html?`<div class='luma-compiler-log-error' style="color:${r};"><b> ${i.type.toUpperCase()}: ${i.message}</b></div>`:`${i.type.toUpperCase()}: ${i.message}`}function Dg(i,e,t){let n="";for(let r=e-2;r<=e;r++){const s=i[r-1];s!==void 0&&(n+=cl(s,e,t))}return n}function cl(i,e,t){const n=t!=null&&t.html?Mg(i):i;return`${Fg(String(e),4)}: ${n}${t!=null&&t.html?"<br/>":`
7
+ `}`}function Fg(i,e){let t="";for(let n=i.length;n<e;++n)t+=" ";return t+i}function Mg(i){return i.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}const Ir=class Ir extends ce{constructor(t,n){n={...n,debugShaders:n.debugShaders||t.props.debugShaders||"errors"};super(t,{id:Ng(n),...n},Ir.defaultProps);g(this,"stage");g(this,"source");g(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 n=await this.getCompilationInfo();t==="warnings"&&(n==null?void 0:n.length)===0||this._displayShaderLog(n,this.id)}_displayShaderLog(t,n){var u;if(typeof document>"u"||!(document!=null&&document.createElement))return;const r=n,s=`${this.stage} shader "${r}"`;let o=Eg(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",{...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
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)}}};g(Ir,"defaultProps",{...ce.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});let Bn=Ir;function Ng(i){return Og(i.source)||i.id||Rn(`unnamed ${i.stage}-shader`)}function Og(i,e="unnamed"){const n=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(i);return n?n[1]:e}const kr=class kr extends ce{constructor(t,n={}){super(t,n,kr.defaultProps);g(this,"width");g(this,"height");this.width=this.props.width,this.height=this.props.height}get[Symbol.toStringTag](){return"Framebuffer"}clone(t){const n=this.colorAttachments.map(s=>s.texture.clone(t)),r=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(t);return this.device.createFramebuffer({...this.props,colorAttachments:n,depthStencilAttachment:r})}resize(t){let n=!t;if(t){const[r,s]=Array.isArray(t)?t:[t.width,t.height];n=n||s!==this.height||r!==this.width,this.width=r,this.height=s}n&&(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((n,r)=>{if(typeof n=="string"){const s=this.createColorTexture(n,r);return this.attachResource(s),s.view}return n instanceof X?n.view:n});const t=this.props.depthStencilAttachment;if(t)if(typeof t=="string"){const n=this.createDepthStencilTexture(t);this.attachResource(n),this.depthStencilAttachment=n.view}else t instanceof X?this.depthStencilAttachment=t.view:this.depthStencilAttachment=t}createColorTexture(t,n){return this.device.createTexture({id:`${this.id}-color-attachment-${n}`,usage:X.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:X.RENDER_ATTACHMENT,format:t,width:this.width,height:this.height})}resizeAttachments(t,n){for(let r=0;r<this.colorAttachments.length;++r)if(this.colorAttachments[r]){const s=this.colorAttachments[r].texture.clone({width:t,height:n});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:n});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=r.view,this.attachResource(r)}this.updateAttachments()}};g(kr,"defaultProps",{...ce.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});let Un=kr;const Rr=class Rr extends ce{constructor(t,n){super(t,n,Rr.defaultProps);g(this,"shaderLayout");g(this,"bufferLayout");g(this,"linkStatus","pending");g(this,"hash","");this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[]}get[Symbol.toStringTag](){return"RenderPipeline"}};g(Rr,"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 Xt=Rr;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}};g(ut,"defaultClearColor",[0,0,0,1]),g(ut,"defaultClearDepth",1),g(ut,"defaultClearStencil",0),g(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 vs=ut;const Er=class Er extends ce{constructor(t,n){super(t,n,Er.defaultProps);g(this,"hash","");g(this,"shaderLayout");this.shaderLayout=n.shaderLayout}get[Symbol.toStringTag](){return"ComputePipeline"}};g(Er,"defaultProps",{...ce.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});let zn=Er;const Dr=class Dr extends ce{get[Symbol.toStringTag](){return"CommandEncoder"}constructor(e,t){super(e,t,Dr.defaultProps)}};g(Dr,"defaultProps",{...ce.defaultProps,measureExecutionTime:void 0});let bs=Dr;const Fr=class Fr extends ce{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Fr.defaultProps)}};g(Fr,"defaultProps",{...ce.defaultProps});let Ss=Fr;function ul(i){return Lg[i]}function Bg(i){const[e,t]=zg[i],n=e==="i32"||e==="u32",r=e!=="u32",s=Ug[e]*t;return{primitiveType:e,components:t,byteLength:s,integer:n,signed:r}}const Ug={f32:4,f16:2,i32:4,u32:4},zg={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]},Lg={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 fl(i,e){const t={};for(const n of i.attributes){const r=Wg(i,e,n.name);r&&(t[n.name]=r)}return t}function Vg(i,e,t=16){const n=fl(i,e),r=new Array(t).fill(null);for(const s of Object.values(n))r[s.location]=s;return r}function Wg(i,e,t){const n=Hg(i,t),r=$g(e,t);if(!n)return null;const s=Bg(n.type),o=og(s),a=(r==null?void 0:r.vertexFormat)||o,l=ds(a);return{attributeName:(r==null?void 0:r.attributeName)||n.name,bufferName:(r==null?void 0:r.bufferName)||n.name,location:n.location,shaderType:n.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)||n.stepMode||"vertex",byteOffset:(r==null?void 0:r.byteOffset)||0,byteStride:(r==null?void 0:r.byteStride)||0}}function Hg(i,e){const t=i.attributes.find(n=>n.name===e);return t||D.warn(`shader layout attribute "${e}" not present in shader`),t||null}function $g(i,e){Xg(i);let t=Yg(i,e);return t||(t=qg(i,e),t)?t:(D.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function Xg(i){for(const e of i)(e.attributes&&e.format||!e.attributes&&!e.format)&&D.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function Yg(i,e){for(const t of i)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 qg(i,e){var t;for(const n of i){let r=n.byteStride;if(typeof n.byteStride!="number")for(const o of n.attributes||[]){const a=ds(o.format);r+=a.byteLength}const s=(t=n.attributes)==null?void 0:t.find(o=>o.attribute===e);if(s)return{attributeName:s.attribute,bufferName:n.name,stepMode:n.stepMode,vertexFormat:s.format,byteOffset:s.byteOffset,byteStride:r}}return null}const Mr=class Mr extends ce{constructor(t,n){super(t,n,Mr.defaultProps);g(this,"maxVertexAttributes");g(this,"attributeInfos");g(this,"indexBuffer",null);g(this,"attributes");this.maxVertexAttributes=t.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=Vg(n.shaderLayout,n.bufferLayout,this.maxVertexAttributes)}get[Symbol.toStringTag](){return"VertexArray"}setConstantWebGL(t,n){this.device.reportError(new Error("constant attributes not supported"),this)()}};g(Mr,"defaultProps",{...ce.defaultProps,shaderLayout:void 0,bufferLayout:[]});let Ts=Mr;const Nr=class Nr extends ce{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,Nr.defaultProps)}};g(Nr,"defaultProps",{...ce.defaultProps,layout:void 0,buffers:{}});let ws=Nr;const Or=class Or extends ce{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,Or.defaultProps)}};g(Or,"defaultProps",{...ce.defaultProps,type:void 0,count:void 0});let As=Or,Ln;function hl(i){return(!Ln||Ln.byteLength<i)&&(Ln=new ArrayBuffer(i)),Ln}function jg(i,e){const t=hl(i.BYTES_PER_ELEMENT*e);return new i(t,0,e)}function Kg(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Vn(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":Kg(i)}const Zg=1024;class Qg{constructor(e,t={}){g(this,"layout",{});g(this,"byteLength");let n=0;for(const[s,o]of Object.entries(e)){const a=ul(o),{type:l,components:c}=a,u=c*((t==null?void 0:t[s])??1);n=ng(n,u);const f=n;n+=u,this.layout[s]={type:l,size:u,offset:f}}n+=(4-n%4)%4;const r=n*4;this.byteLength=Math.max(r,Zg)}getData(e){const t=hl(this.byteLength),n={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=n[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(!Vn(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 Jg(i,e,t=16){if(i!==e)return!1;const n=i,r=e;if(!Vn(n))return!1;if(Vn(r)&&n.length===r.length){for(let s=0;s<n.length;++s)if(r[s]!==n[s])return!1}return!0}function Gg(i){return Vn(i)?i.slice():i}class em{constructor(e){g(this,"name");g(this,"uniforms",{});g(this,"modifiedUniforms",{});g(this,"modified",!0);g(this,"bindingLayout",{});g(this,"needsRedraw","initialized");var t;if(this.name=(e==null?void 0:e.name)||"unnamed",e!=null&&e.name&&(e!=null&&e.shaderLayout)){const n=(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(!n)throw new Error(e==null?void 0:e.name);const r=n;for(const s of r.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(const[t,n]of Object.entries(e))this._setUniform(t,n),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${n}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){Jg(this.uniforms[e],t)||(this.uniforms[e]=Gg(t),this.modifiedUniforms[e]=!0,this.modified=!0)}}class pe{constructor(e){g(this,"uniformBlocks",new Map);g(this,"uniformBufferLayouts",new Map);g(this,"uniformBuffers",new Map);for(const[t,n]of Object.entries(e)){const r=t,s=new Qg(n.uniformTypes??{},n.uniformSizes??{});this.uniformBufferLayouts.set(r,s);const o=new em({name:t});o.setUniforms(n.defaultUniforms||{}),this.uniformBlocks.set(r,o)}}destroy(){for(const e of this.uniformBuffers.values())e.destroy()}setUniforms(e){var t;for(const[n,r]of Object.entries(e))(t=this.uniformBlocks.get(n))==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 n,r;const t=((n=this.uniformBlocks.get(e))==null?void 0:n.getAllUniforms())||{};return(r=this.uniformBufferLayouts.get(e))==null?void 0:r.getData(t)}createUniformBuffer(e,t,n){n&&this.setUniforms(n);const r=this.getUniformBufferByteLength(t),s=e.createBuffer({usage:H.UNIFORM|H.COPY_DST,byteLength:r}),o=this.getUniformBufferData(t);return s.write(o),s}getManagedUniformBuffer(e,t){if(!this.uniformBuffers.get(t)){const n=this.getUniformBufferByteLength(t),r=e.createBuffer({usage:H.UNIFORM|H.COPY_DST,byteLength:n});this.uniformBuffers.set(t,r)}return this.uniformBuffers.get(t)}updateUniformBuffers(){let e=!1;for(const t of this.uniformBlocks.keys()){const n=this.updateUniformBuffer(t);e||(e=n)}return e&&D.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){var s;const t=this.uniformBlocks.get(e);let n=this.uniformBuffers.get(e),r=!1;if(n&&(t!=null&&t.needsRedraw)){r||(r=t.needsRedraw);const o=this.getUniformBufferData(e);n=this.uniformBuffers.get(e),n==null||n.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 Yt;(function(i){i[i.DEPTH_BUFFER_BIT=256]="DEPTH_BUFFER_BIT",i[i.STENCIL_BUFFER_BIT=1024]="STENCIL_BUFFER_BIT",i[i.COLOR_BUFFER_BIT=16384]="COLOR_BUFFER_BIT",i[i.POINTS=0]="POINTS",i[i.LINES=1]="LINES",i[i.LINE_LOOP=2]="LINE_LOOP",i[i.LINE_STRIP=3]="LINE_STRIP",i[i.TRIANGLES=4]="TRIANGLES",i[i.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",i[i.TRIANGLE_FAN=6]="TRIANGLE_FAN",i[i.ZERO=0]="ZERO",i[i.ONE=1]="ONE",i[i.SRC_COLOR=768]="SRC_COLOR",i[i.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",i[i.SRC_ALPHA=770]="SRC_ALPHA",i[i.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",i[i.DST_ALPHA=772]="DST_ALPHA",i[i.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",i[i.DST_COLOR=774]="DST_COLOR",i[i.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",i[i.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE",i[i.CONSTANT_COLOR=32769]="CONSTANT_COLOR",i[i.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",i[i.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",i[i.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",i[i.FUNC_ADD=32774]="FUNC_ADD",i[i.FUNC_SUBTRACT=32778]="FUNC_SUBTRACT",i[i.FUNC_REVERSE_SUBTRACT=32779]="FUNC_REVERSE_SUBTRACT",i[i.BLEND_EQUATION=32777]="BLEND_EQUATION",i[i.BLEND_EQUATION_RGB=32777]="BLEND_EQUATION_RGB",i[i.BLEND_EQUATION_ALPHA=34877]="BLEND_EQUATION_ALPHA",i[i.BLEND_DST_RGB=32968]="BLEND_DST_RGB",i[i.BLEND_SRC_RGB=32969]="BLEND_SRC_RGB",i[i.BLEND_DST_ALPHA=32970]="BLEND_DST_ALPHA",i[i.BLEND_SRC_ALPHA=32971]="BLEND_SRC_ALPHA",i[i.BLEND_COLOR=32773]="BLEND_COLOR",i[i.ARRAY_BUFFER_BINDING=34964]="ARRAY_BUFFER_BINDING",i[i.ELEMENT_ARRAY_BUFFER_BINDING=34965]="ELEMENT_ARRAY_BUFFER_BINDING",i[i.LINE_WIDTH=2849]="LINE_WIDTH",i[i.ALIASED_POINT_SIZE_RANGE=33901]="ALIASED_POINT_SIZE_RANGE",i[i.ALIASED_LINE_WIDTH_RANGE=33902]="ALIASED_LINE_WIDTH_RANGE",i[i.CULL_FACE_MODE=2885]="CULL_FACE_MODE",i[i.FRONT_FACE=2886]="FRONT_FACE",i[i.DEPTH_RANGE=2928]="DEPTH_RANGE",i[i.DEPTH_WRITEMASK=2930]="DEPTH_WRITEMASK",i[i.DEPTH_CLEAR_VALUE=2931]="DEPTH_CLEAR_VALUE",i[i.DEPTH_FUNC=2932]="DEPTH_FUNC",i[i.STENCIL_CLEAR_VALUE=2961]="STENCIL_CLEAR_VALUE",i[i.STENCIL_FUNC=2962]="STENCIL_FUNC",i[i.STENCIL_FAIL=2964]="STENCIL_FAIL",i[i.STENCIL_PASS_DEPTH_FAIL=2965]="STENCIL_PASS_DEPTH_FAIL",i[i.STENCIL_PASS_DEPTH_PASS=2966]="STENCIL_PASS_DEPTH_PASS",i[i.STENCIL_REF=2967]="STENCIL_REF",i[i.STENCIL_VALUE_MASK=2963]="STENCIL_VALUE_MASK",i[i.STENCIL_WRITEMASK=2968]="STENCIL_WRITEMASK",i[i.STENCIL_BACK_FUNC=34816]="STENCIL_BACK_FUNC",i[i.STENCIL_BACK_FAIL=34817]="STENCIL_BACK_FAIL",i[i.STENCIL_BACK_PASS_DEPTH_FAIL=34818]="STENCIL_BACK_PASS_DEPTH_FAIL",i[i.STENCIL_BACK_PASS_DEPTH_PASS=34819]="STENCIL_BACK_PASS_DEPTH_PASS",i[i.STENCIL_BACK_REF=36003]="STENCIL_BACK_REF",i[i.STENCIL_BACK_VALUE_MASK=36004]="STENCIL_BACK_VALUE_MASK",i[i.STENCIL_BACK_WRITEMASK=36005]="STENCIL_BACK_WRITEMASK",i[i.VIEWPORT=2978]="VIEWPORT",i[i.SCISSOR_BOX=3088]="SCISSOR_BOX",i[i.COLOR_CLEAR_VALUE=3106]="COLOR_CLEAR_VALUE",i[i.COLOR_WRITEMASK=3107]="COLOR_WRITEMASK",i[i.UNPACK_ALIGNMENT=3317]="UNPACK_ALIGNMENT",i[i.PACK_ALIGNMENT=3333]="PACK_ALIGNMENT",i[i.MAX_TEXTURE_SIZE=3379]="MAX_TEXTURE_SIZE",i[i.MAX_VIEWPORT_DIMS=3386]="MAX_VIEWPORT_DIMS",i[i.SUBPIXEL_BITS=3408]="SUBPIXEL_BITS",i[i.RED_BITS=3410]="RED_BITS",i[i.GREEN_BITS=3411]="GREEN_BITS",i[i.BLUE_BITS=3412]="BLUE_BITS",i[i.ALPHA_BITS=3413]="ALPHA_BITS",i[i.DEPTH_BITS=3414]="DEPTH_BITS",i[i.STENCIL_BITS=3415]="STENCIL_BITS",i[i.POLYGON_OFFSET_UNITS=10752]="POLYGON_OFFSET_UNITS",i[i.POLYGON_OFFSET_FACTOR=32824]="POLYGON_OFFSET_FACTOR",i[i.TEXTURE_BINDING_2D=32873]="TEXTURE_BINDING_2D",i[i.SAMPLE_BUFFERS=32936]="SAMPLE_BUFFERS",i[i.SAMPLES=32937]="SAMPLES",i[i.SAMPLE_COVERAGE_VALUE=32938]="SAMPLE_COVERAGE_VALUE",i[i.SAMPLE_COVERAGE_INVERT=32939]="SAMPLE_COVERAGE_INVERT",i[i.COMPRESSED_TEXTURE_FORMATS=34467]="COMPRESSED_TEXTURE_FORMATS",i[i.VENDOR=7936]="VENDOR",i[i.RENDERER=7937]="RENDERER",i[i.VERSION=7938]="VERSION",i[i.IMPLEMENTATION_COLOR_READ_TYPE=35738]="IMPLEMENTATION_COLOR_READ_TYPE",i[i.IMPLEMENTATION_COLOR_READ_FORMAT=35739]="IMPLEMENTATION_COLOR_READ_FORMAT",i[i.BROWSER_DEFAULT_WEBGL=37444]="BROWSER_DEFAULT_WEBGL",i[i.STATIC_DRAW=35044]="STATIC_DRAW",i[i.STREAM_DRAW=35040]="STREAM_DRAW",i[i.DYNAMIC_DRAW=35048]="DYNAMIC_DRAW",i[i.ARRAY_BUFFER=34962]="ARRAY_BUFFER",i[i.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",i[i.BUFFER_SIZE=34660]="BUFFER_SIZE",i[i.BUFFER_USAGE=34661]="BUFFER_USAGE",i[i.CURRENT_VERTEX_ATTRIB=34342]="CURRENT_VERTEX_ATTRIB",i[i.VERTEX_ATTRIB_ARRAY_ENABLED=34338]="VERTEX_ATTRIB_ARRAY_ENABLED",i[i.VERTEX_ATTRIB_ARRAY_SIZE=34339]="VERTEX_ATTRIB_ARRAY_SIZE",i[i.VERTEX_ATTRIB_ARRAY_STRIDE=34340]="VERTEX_ATTRIB_ARRAY_STRIDE",i[i.VERTEX_ATTRIB_ARRAY_TYPE=34341]="VERTEX_ATTRIB_ARRAY_TYPE",i[i.VERTEX_ATTRIB_ARRAY_NORMALIZED=34922]="VERTEX_ATTRIB_ARRAY_NORMALIZED",i[i.VERTEX_ATTRIB_ARRAY_POINTER=34373]="VERTEX_ATTRIB_ARRAY_POINTER",i[i.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING=34975]="VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",i[i.CULL_FACE=2884]="CULL_FACE",i[i.FRONT=1028]="FRONT",i[i.BACK=1029]="BACK",i[i.FRONT_AND_BACK=1032]="FRONT_AND_BACK",i[i.BLEND=3042]="BLEND",i[i.DEPTH_TEST=2929]="DEPTH_TEST",i[i.DITHER=3024]="DITHER",i[i.POLYGON_OFFSET_FILL=32823]="POLYGON_OFFSET_FILL",i[i.SAMPLE_ALPHA_TO_COVERAGE=32926]="SAMPLE_ALPHA_TO_COVERAGE",i[i.SAMPLE_COVERAGE=32928]="SAMPLE_COVERAGE",i[i.SCISSOR_TEST=3089]="SCISSOR_TEST",i[i.STENCIL_TEST=2960]="STENCIL_TEST",i[i.NO_ERROR=0]="NO_ERROR",i[i.INVALID_ENUM=1280]="INVALID_ENUM",i[i.INVALID_VALUE=1281]="INVALID_VALUE",i[i.INVALID_OPERATION=1282]="INVALID_OPERATION",i[i.OUT_OF_MEMORY=1285]="OUT_OF_MEMORY",i[i.CONTEXT_LOST_WEBGL=37442]="CONTEXT_LOST_WEBGL",i[i.CW=2304]="CW",i[i.CCW=2305]="CCW",i[i.DONT_CARE=4352]="DONT_CARE",i[i.FASTEST=4353]="FASTEST",i[i.NICEST=4354]="NICEST",i[i.GENERATE_MIPMAP_HINT=33170]="GENERATE_MIPMAP_HINT",i[i.BYTE=5120]="BYTE",i[i.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",i[i.SHORT=5122]="SHORT",i[i.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",i[i.INT=5124]="INT",i[i.UNSIGNED_INT=5125]="UNSIGNED_INT",i[i.FLOAT=5126]="FLOAT",i[i.DOUBLE=5130]="DOUBLE",i[i.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",i[i.ALPHA=6406]="ALPHA",i[i.RGB=6407]="RGB",i[i.RGBA=6408]="RGBA",i[i.LUMINANCE=6409]="LUMINANCE",i[i.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",i[i.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",i[i.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",i[i.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",i[i.FRAGMENT_SHADER=35632]="FRAGMENT_SHADER",i[i.VERTEX_SHADER=35633]="VERTEX_SHADER",i[i.COMPILE_STATUS=35713]="COMPILE_STATUS",i[i.DELETE_STATUS=35712]="DELETE_STATUS",i[i.LINK_STATUS=35714]="LINK_STATUS",i[i.VALIDATE_STATUS=35715]="VALIDATE_STATUS",i[i.ATTACHED_SHADERS=35717]="ATTACHED_SHADERS",i[i.ACTIVE_ATTRIBUTES=35721]="ACTIVE_ATTRIBUTES",i[i.ACTIVE_UNIFORMS=35718]="ACTIVE_UNIFORMS",i[i.MAX_VERTEX_ATTRIBS=34921]="MAX_VERTEX_ATTRIBS",i[i.MAX_VERTEX_UNIFORM_VECTORS=36347]="MAX_VERTEX_UNIFORM_VECTORS",i[i.MAX_VARYING_VECTORS=36348]="MAX_VARYING_VECTORS",i[i.MAX_COMBINED_TEXTURE_IMAGE_UNITS=35661]="MAX_COMBINED_TEXTURE_IMAGE_UNITS",i[i.MAX_VERTEX_TEXTURE_IMAGE_UNITS=35660]="MAX_VERTEX_TEXTURE_IMAGE_UNITS",i[i.MAX_TEXTURE_IMAGE_UNITS=34930]="MAX_TEXTURE_IMAGE_UNITS",i[i.MAX_FRAGMENT_UNIFORM_VECTORS=36349]="MAX_FRAGMENT_UNIFORM_VECTORS",i[i.SHADER_TYPE=35663]="SHADER_TYPE",i[i.SHADING_LANGUAGE_VERSION=35724]="SHADING_LANGUAGE_VERSION",i[i.CURRENT_PROGRAM=35725]="CURRENT_PROGRAM",i[i.NEVER=512]="NEVER",i[i.LESS=513]="LESS",i[i.EQUAL=514]="EQUAL",i[i.LEQUAL=515]="LEQUAL",i[i.GREATER=516]="GREATER",i[i.NOTEQUAL=517]="NOTEQUAL",i[i.GEQUAL=518]="GEQUAL",i[i.ALWAYS=519]="ALWAYS",i[i.KEEP=7680]="KEEP",i[i.REPLACE=7681]="REPLACE",i[i.INCR=7682]="INCR",i[i.DECR=7683]="DECR",i[i.INVERT=5386]="INVERT",i[i.INCR_WRAP=34055]="INCR_WRAP",i[i.DECR_WRAP=34056]="DECR_WRAP",i[i.NEAREST=9728]="NEAREST",i[i.LINEAR=9729]="LINEAR",i[i.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",i[i.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",i[i.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",i[i.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",i[i.TEXTURE_MAG_FILTER=10240]="TEXTURE_MAG_FILTER",i[i.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",i[i.TEXTURE_WRAP_S=10242]="TEXTURE_WRAP_S",i[i.TEXTURE_WRAP_T=10243]="TEXTURE_WRAP_T",i[i.TEXTURE_2D=3553]="TEXTURE_2D",i[i.TEXTURE=5890]="TEXTURE",i[i.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",i[i.TEXTURE_BINDING_CUBE_MAP=34068]="TEXTURE_BINDING_CUBE_MAP",i[i.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",i[i.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",i[i.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",i[i.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",i[i.MAX_CUBE_MAP_TEXTURE_SIZE=34076]="MAX_CUBE_MAP_TEXTURE_SIZE",i[i.TEXTURE0=33984]="TEXTURE0",i[i.ACTIVE_TEXTURE=34016]="ACTIVE_TEXTURE",i[i.REPEAT=10497]="REPEAT",i[i.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",i[i.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",i[i.TEXTURE_WIDTH=4096]="TEXTURE_WIDTH",i[i.TEXTURE_HEIGHT=4097]="TEXTURE_HEIGHT",i[i.FLOAT_VEC2=35664]="FLOAT_VEC2",i[i.FLOAT_VEC3=35665]="FLOAT_VEC3",i[i.FLOAT_VEC4=35666]="FLOAT_VEC4",i[i.INT_VEC2=35667]="INT_VEC2",i[i.INT_VEC3=35668]="INT_VEC3",i[i.INT_VEC4=35669]="INT_VEC4",i[i.BOOL=35670]="BOOL",i[i.BOOL_VEC2=35671]="BOOL_VEC2",i[i.BOOL_VEC3=35672]="BOOL_VEC3",i[i.BOOL_VEC4=35673]="BOOL_VEC4",i[i.FLOAT_MAT2=35674]="FLOAT_MAT2",i[i.FLOAT_MAT3=35675]="FLOAT_MAT3",i[i.FLOAT_MAT4=35676]="FLOAT_MAT4",i[i.SAMPLER_2D=35678]="SAMPLER_2D",i[i.SAMPLER_CUBE=35680]="SAMPLER_CUBE",i[i.LOW_FLOAT=36336]="LOW_FLOAT",i[i.MEDIUM_FLOAT=36337]="MEDIUM_FLOAT",i[i.HIGH_FLOAT=36338]="HIGH_FLOAT",i[i.LOW_INT=36339]="LOW_INT",i[i.MEDIUM_INT=36340]="MEDIUM_INT",i[i.HIGH_INT=36341]="HIGH_INT",i[i.FRAMEBUFFER=36160]="FRAMEBUFFER",i[i.RENDERBUFFER=36161]="RENDERBUFFER",i[i.RGBA4=32854]="RGBA4",i[i.RGB5_A1=32855]="RGB5_A1",i[i.RGB565=36194]="RGB565",i[i.DEPTH_COMPONENT16=33189]="DEPTH_COMPONENT16",i[i.STENCIL_INDEX=6401]="STENCIL_INDEX",i[i.STENCIL_INDEX8=36168]="STENCIL_INDEX8",i[i.DEPTH_STENCIL=34041]="DEPTH_STENCIL",i[i.RENDERBUFFER_WIDTH=36162]="RENDERBUFFER_WIDTH",i[i.RENDERBUFFER_HEIGHT=36163]="RENDERBUFFER_HEIGHT",i[i.RENDERBUFFER_INTERNAL_FORMAT=36164]="RENDERBUFFER_INTERNAL_FORMAT",i[i.RENDERBUFFER_RED_SIZE=36176]="RENDERBUFFER_RED_SIZE",i[i.RENDERBUFFER_GREEN_SIZE=36177]="RENDERBUFFER_GREEN_SIZE",i[i.RENDERBUFFER_BLUE_SIZE=36178]="RENDERBUFFER_BLUE_SIZE",i[i.RENDERBUFFER_ALPHA_SIZE=36179]="RENDERBUFFER_ALPHA_SIZE",i[i.RENDERBUFFER_DEPTH_SIZE=36180]="RENDERBUFFER_DEPTH_SIZE",i[i.RENDERBUFFER_STENCIL_SIZE=36181]="RENDERBUFFER_STENCIL_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE=36048]="FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",i[i.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME=36049]="FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",i[i.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL=36050]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",i[i.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE=36051]="FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE",i[i.COLOR_ATTACHMENT0=36064]="COLOR_ATTACHMENT0",i[i.DEPTH_ATTACHMENT=36096]="DEPTH_ATTACHMENT",i[i.STENCIL_ATTACHMENT=36128]="STENCIL_ATTACHMENT",i[i.DEPTH_STENCIL_ATTACHMENT=33306]="DEPTH_STENCIL_ATTACHMENT",i[i.NONE=0]="NONE",i[i.FRAMEBUFFER_COMPLETE=36053]="FRAMEBUFFER_COMPLETE",i[i.FRAMEBUFFER_INCOMPLETE_ATTACHMENT=36054]="FRAMEBUFFER_INCOMPLETE_ATTACHMENT",i[i.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT=36055]="FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",i[i.FRAMEBUFFER_INCOMPLETE_DIMENSIONS=36057]="FRAMEBUFFER_INCOMPLETE_DIMENSIONS",i[i.FRAMEBUFFER_UNSUPPORTED=36061]="FRAMEBUFFER_UNSUPPORTED",i[i.FRAMEBUFFER_BINDING=36006]="FRAMEBUFFER_BINDING",i[i.RENDERBUFFER_BINDING=36007]="RENDERBUFFER_BINDING",i[i.READ_FRAMEBUFFER=36008]="READ_FRAMEBUFFER",i[i.DRAW_FRAMEBUFFER=36009]="DRAW_FRAMEBUFFER",i[i.MAX_RENDERBUFFER_SIZE=34024]="MAX_RENDERBUFFER_SIZE",i[i.INVALID_FRAMEBUFFER_OPERATION=1286]="INVALID_FRAMEBUFFER_OPERATION",i[i.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL",i[i.UNPACK_PREMULTIPLY_ALPHA_WEBGL=37441]="UNPACK_PREMULTIPLY_ALPHA_WEBGL",i[i.UNPACK_COLORSPACE_CONVERSION_WEBGL=37443]="UNPACK_COLORSPACE_CONVERSION_WEBGL",i[i.READ_BUFFER=3074]="READ_BUFFER",i[i.UNPACK_ROW_LENGTH=3314]="UNPACK_ROW_LENGTH",i[i.UNPACK_SKIP_ROWS=3315]="UNPACK_SKIP_ROWS",i[i.UNPACK_SKIP_PIXELS=3316]="UNPACK_SKIP_PIXELS",i[i.PACK_ROW_LENGTH=3330]="PACK_ROW_LENGTH",i[i.PACK_SKIP_ROWS=3331]="PACK_SKIP_ROWS",i[i.PACK_SKIP_PIXELS=3332]="PACK_SKIP_PIXELS",i[i.TEXTURE_BINDING_3D=32874]="TEXTURE_BINDING_3D",i[i.UNPACK_SKIP_IMAGES=32877]="UNPACK_SKIP_IMAGES",i[i.UNPACK_IMAGE_HEIGHT=32878]="UNPACK_IMAGE_HEIGHT",i[i.MAX_3D_TEXTURE_SIZE=32883]="MAX_3D_TEXTURE_SIZE",i[i.MAX_ELEMENTS_VERTICES=33e3]="MAX_ELEMENTS_VERTICES",i[i.MAX_ELEMENTS_INDICES=33001]="MAX_ELEMENTS_INDICES",i[i.MAX_TEXTURE_LOD_BIAS=34045]="MAX_TEXTURE_LOD_BIAS",i[i.MAX_FRAGMENT_UNIFORM_COMPONENTS=35657]="MAX_FRAGMENT_UNIFORM_COMPONENTS",i[i.MAX_VERTEX_UNIFORM_COMPONENTS=35658]="MAX_VERTEX_UNIFORM_COMPONENTS",i[i.MAX_ARRAY_TEXTURE_LAYERS=35071]="MAX_ARRAY_TEXTURE_LAYERS",i[i.MIN_PROGRAM_TEXEL_OFFSET=35076]="MIN_PROGRAM_TEXEL_OFFSET",i[i.MAX_PROGRAM_TEXEL_OFFSET=35077]="MAX_PROGRAM_TEXEL_OFFSET",i[i.MAX_VARYING_COMPONENTS=35659]="MAX_VARYING_COMPONENTS",i[i.FRAGMENT_SHADER_DERIVATIVE_HINT=35723]="FRAGMENT_SHADER_DERIVATIVE_HINT",i[i.RASTERIZER_DISCARD=35977]="RASTERIZER_DISCARD",i[i.VERTEX_ARRAY_BINDING=34229]="VERTEX_ARRAY_BINDING",i[i.MAX_VERTEX_OUTPUT_COMPONENTS=37154]="MAX_VERTEX_OUTPUT_COMPONENTS",i[i.MAX_FRAGMENT_INPUT_COMPONENTS=37157]="MAX_FRAGMENT_INPUT_COMPONENTS",i[i.MAX_SERVER_WAIT_TIMEOUT=37137]="MAX_SERVER_WAIT_TIMEOUT",i[i.MAX_ELEMENT_INDEX=36203]="MAX_ELEMENT_INDEX",i[i.RED=6403]="RED",i[i.RGB8=32849]="RGB8",i[i.RGBA8=32856]="RGBA8",i[i.RGB10_A2=32857]="RGB10_A2",i[i.TEXTURE_3D=32879]="TEXTURE_3D",i[i.TEXTURE_WRAP_R=32882]="TEXTURE_WRAP_R",i[i.TEXTURE_MIN_LOD=33082]="TEXTURE_MIN_LOD",i[i.TEXTURE_MAX_LOD=33083]="TEXTURE_MAX_LOD",i[i.TEXTURE_BASE_LEVEL=33084]="TEXTURE_BASE_LEVEL",i[i.TEXTURE_MAX_LEVEL=33085]="TEXTURE_MAX_LEVEL",i[i.TEXTURE_COMPARE_MODE=34892]="TEXTURE_COMPARE_MODE",i[i.TEXTURE_COMPARE_FUNC=34893]="TEXTURE_COMPARE_FUNC",i[i.SRGB=35904]="SRGB",i[i.SRGB8=35905]="SRGB8",i[i.SRGB8_ALPHA8=35907]="SRGB8_ALPHA8",i[i.COMPARE_REF_TO_TEXTURE=34894]="COMPARE_REF_TO_TEXTURE",i[i.RGBA32F=34836]="RGBA32F",i[i.RGB32F=34837]="RGB32F",i[i.RGBA16F=34842]="RGBA16F",i[i.RGB16F=34843]="RGB16F",i[i.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",i[i.TEXTURE_BINDING_2D_ARRAY=35869]="TEXTURE_BINDING_2D_ARRAY",i[i.R11F_G11F_B10F=35898]="R11F_G11F_B10F",i[i.RGB9_E5=35901]="RGB9_E5",i[i.RGBA32UI=36208]="RGBA32UI",i[i.RGB32UI=36209]="RGB32UI",i[i.RGBA16UI=36214]="RGBA16UI",i[i.RGB16UI=36215]="RGB16UI",i[i.RGBA8UI=36220]="RGBA8UI",i[i.RGB8UI=36221]="RGB8UI",i[i.RGBA32I=36226]="RGBA32I",i[i.RGB32I=36227]="RGB32I",i[i.RGBA16I=36232]="RGBA16I",i[i.RGB16I=36233]="RGB16I",i[i.RGBA8I=36238]="RGBA8I",i[i.RGB8I=36239]="RGB8I",i[i.RED_INTEGER=36244]="RED_INTEGER",i[i.RGB_INTEGER=36248]="RGB_INTEGER",i[i.RGBA_INTEGER=36249]="RGBA_INTEGER",i[i.R8=33321]="R8",i[i.RG8=33323]="RG8",i[i.R16F=33325]="R16F",i[i.R32F=33326]="R32F",i[i.RG16F=33327]="RG16F",i[i.RG32F=33328]="RG32F",i[i.R8I=33329]="R8I",i[i.R8UI=33330]="R8UI",i[i.R16I=33331]="R16I",i[i.R16UI=33332]="R16UI",i[i.R32I=33333]="R32I",i[i.R32UI=33334]="R32UI",i[i.RG8I=33335]="RG8I",i[i.RG8UI=33336]="RG8UI",i[i.RG16I=33337]="RG16I",i[i.RG16UI=33338]="RG16UI",i[i.RG32I=33339]="RG32I",i[i.RG32UI=33340]="RG32UI",i[i.R8_SNORM=36756]="R8_SNORM",i[i.RG8_SNORM=36757]="RG8_SNORM",i[i.RGB8_SNORM=36758]="RGB8_SNORM",i[i.RGBA8_SNORM=36759]="RGBA8_SNORM",i[i.RGB10_A2UI=36975]="RGB10_A2UI",i[i.TEXTURE_IMMUTABLE_FORMAT=37167]="TEXTURE_IMMUTABLE_FORMAT",i[i.TEXTURE_IMMUTABLE_LEVELS=33503]="TEXTURE_IMMUTABLE_LEVELS",i[i.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",i[i.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",i[i.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",i[i.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",i[i.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",i[i.HALF_FLOAT=5131]="HALF_FLOAT",i[i.RG=33319]="RG",i[i.RG_INTEGER=33320]="RG_INTEGER",i[i.INT_2_10_10_10_REV=36255]="INT_2_10_10_10_REV",i[i.CURRENT_QUERY=34917]="CURRENT_QUERY",i[i.QUERY_RESULT=34918]="QUERY_RESULT",i[i.QUERY_RESULT_AVAILABLE=34919]="QUERY_RESULT_AVAILABLE",i[i.ANY_SAMPLES_PASSED=35887]="ANY_SAMPLES_PASSED",i[i.ANY_SAMPLES_PASSED_CONSERVATIVE=36202]="ANY_SAMPLES_PASSED_CONSERVATIVE",i[i.MAX_DRAW_BUFFERS=34852]="MAX_DRAW_BUFFERS",i[i.DRAW_BUFFER0=34853]="DRAW_BUFFER0",i[i.DRAW_BUFFER1=34854]="DRAW_BUFFER1",i[i.DRAW_BUFFER2=34855]="DRAW_BUFFER2",i[i.DRAW_BUFFER3=34856]="DRAW_BUFFER3",i[i.DRAW_BUFFER4=34857]="DRAW_BUFFER4",i[i.DRAW_BUFFER5=34858]="DRAW_BUFFER5",i[i.DRAW_BUFFER6=34859]="DRAW_BUFFER6",i[i.DRAW_BUFFER7=34860]="DRAW_BUFFER7",i[i.DRAW_BUFFER8=34861]="DRAW_BUFFER8",i[i.DRAW_BUFFER9=34862]="DRAW_BUFFER9",i[i.DRAW_BUFFER10=34863]="DRAW_BUFFER10",i[i.DRAW_BUFFER11=34864]="DRAW_BUFFER11",i[i.DRAW_BUFFER12=34865]="DRAW_BUFFER12",i[i.DRAW_BUFFER13=34866]="DRAW_BUFFER13",i[i.DRAW_BUFFER14=34867]="DRAW_BUFFER14",i[i.DRAW_BUFFER15=34868]="DRAW_BUFFER15",i[i.MAX_COLOR_ATTACHMENTS=36063]="MAX_COLOR_ATTACHMENTS",i[i.COLOR_ATTACHMENT1=36065]="COLOR_ATTACHMENT1",i[i.COLOR_ATTACHMENT2=36066]="COLOR_ATTACHMENT2",i[i.COLOR_ATTACHMENT3=36067]="COLOR_ATTACHMENT3",i[i.COLOR_ATTACHMENT4=36068]="COLOR_ATTACHMENT4",i[i.COLOR_ATTACHMENT5=36069]="COLOR_ATTACHMENT5",i[i.COLOR_ATTACHMENT6=36070]="COLOR_ATTACHMENT6",i[i.COLOR_ATTACHMENT7=36071]="COLOR_ATTACHMENT7",i[i.COLOR_ATTACHMENT8=36072]="COLOR_ATTACHMENT8",i[i.COLOR_ATTACHMENT9=36073]="COLOR_ATTACHMENT9",i[i.COLOR_ATTACHMENT10=36074]="COLOR_ATTACHMENT10",i[i.COLOR_ATTACHMENT11=36075]="COLOR_ATTACHMENT11",i[i.COLOR_ATTACHMENT12=36076]="COLOR_ATTACHMENT12",i[i.COLOR_ATTACHMENT13=36077]="COLOR_ATTACHMENT13",i[i.COLOR_ATTACHMENT14=36078]="COLOR_ATTACHMENT14",i[i.COLOR_ATTACHMENT15=36079]="COLOR_ATTACHMENT15",i[i.SAMPLER_3D=35679]="SAMPLER_3D",i[i.SAMPLER_2D_SHADOW=35682]="SAMPLER_2D_SHADOW",i[i.SAMPLER_2D_ARRAY=36289]="SAMPLER_2D_ARRAY",i[i.SAMPLER_2D_ARRAY_SHADOW=36292]="SAMPLER_2D_ARRAY_SHADOW",i[i.SAMPLER_CUBE_SHADOW=36293]="SAMPLER_CUBE_SHADOW",i[i.INT_SAMPLER_2D=36298]="INT_SAMPLER_2D",i[i.INT_SAMPLER_3D=36299]="INT_SAMPLER_3D",i[i.INT_SAMPLER_CUBE=36300]="INT_SAMPLER_CUBE",i[i.INT_SAMPLER_2D_ARRAY=36303]="INT_SAMPLER_2D_ARRAY",i[i.UNSIGNED_INT_SAMPLER_2D=36306]="UNSIGNED_INT_SAMPLER_2D",i[i.UNSIGNED_INT_SAMPLER_3D=36307]="UNSIGNED_INT_SAMPLER_3D",i[i.UNSIGNED_INT_SAMPLER_CUBE=36308]="UNSIGNED_INT_SAMPLER_CUBE",i[i.UNSIGNED_INT_SAMPLER_2D_ARRAY=36311]="UNSIGNED_INT_SAMPLER_2D_ARRAY",i[i.MAX_SAMPLES=36183]="MAX_SAMPLES",i[i.SAMPLER_BINDING=35097]="SAMPLER_BINDING",i[i.PIXEL_PACK_BUFFER=35051]="PIXEL_PACK_BUFFER",i[i.PIXEL_UNPACK_BUFFER=35052]="PIXEL_UNPACK_BUFFER",i[i.PIXEL_PACK_BUFFER_BINDING=35053]="PIXEL_PACK_BUFFER_BINDING",i[i.PIXEL_UNPACK_BUFFER_BINDING=35055]="PIXEL_UNPACK_BUFFER_BINDING",i[i.COPY_READ_BUFFER=36662]="COPY_READ_BUFFER",i[i.COPY_WRITE_BUFFER=36663]="COPY_WRITE_BUFFER",i[i.COPY_READ_BUFFER_BINDING=36662]="COPY_READ_BUFFER_BINDING",i[i.COPY_WRITE_BUFFER_BINDING=36663]="COPY_WRITE_BUFFER_BINDING",i[i.FLOAT_MAT2x3=35685]="FLOAT_MAT2x3",i[i.FLOAT_MAT2x4=35686]="FLOAT_MAT2x4",i[i.FLOAT_MAT3x2=35687]="FLOAT_MAT3x2",i[i.FLOAT_MAT3x4=35688]="FLOAT_MAT3x4",i[i.FLOAT_MAT4x2=35689]="FLOAT_MAT4x2",i[i.FLOAT_MAT4x3=35690]="FLOAT_MAT4x3",i[i.UNSIGNED_INT_VEC2=36294]="UNSIGNED_INT_VEC2",i[i.UNSIGNED_INT_VEC3=36295]="UNSIGNED_INT_VEC3",i[i.UNSIGNED_INT_VEC4=36296]="UNSIGNED_INT_VEC4",i[i.UNSIGNED_NORMALIZED=35863]="UNSIGNED_NORMALIZED",i[i.SIGNED_NORMALIZED=36764]="SIGNED_NORMALIZED",i[i.VERTEX_ATTRIB_ARRAY_INTEGER=35069]="VERTEX_ATTRIB_ARRAY_INTEGER",i[i.VERTEX_ATTRIB_ARRAY_DIVISOR=35070]="VERTEX_ATTRIB_ARRAY_DIVISOR",i[i.TRANSFORM_FEEDBACK_BUFFER_MODE=35967]="TRANSFORM_FEEDBACK_BUFFER_MODE",i[i.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS=35968]="MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS",i[i.TRANSFORM_FEEDBACK_VARYINGS=35971]="TRANSFORM_FEEDBACK_VARYINGS",i[i.TRANSFORM_FEEDBACK_BUFFER_START=35972]="TRANSFORM_FEEDBACK_BUFFER_START",i[i.TRANSFORM_FEEDBACK_BUFFER_SIZE=35973]="TRANSFORM_FEEDBACK_BUFFER_SIZE",i[i.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN=35976]="TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN",i[i.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS=35978]="MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS",i[i.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS=35979]="MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS",i[i.INTERLEAVED_ATTRIBS=35980]="INTERLEAVED_ATTRIBS",i[i.SEPARATE_ATTRIBS=35981]="SEPARATE_ATTRIBS",i[i.TRANSFORM_FEEDBACK_BUFFER=35982]="TRANSFORM_FEEDBACK_BUFFER",i[i.TRANSFORM_FEEDBACK_BUFFER_BINDING=35983]="TRANSFORM_FEEDBACK_BUFFER_BINDING",i[i.TRANSFORM_FEEDBACK=36386]="TRANSFORM_FEEDBACK",i[i.TRANSFORM_FEEDBACK_PAUSED=36387]="TRANSFORM_FEEDBACK_PAUSED",i[i.TRANSFORM_FEEDBACK_ACTIVE=36388]="TRANSFORM_FEEDBACK_ACTIVE",i[i.TRANSFORM_FEEDBACK_BINDING=36389]="TRANSFORM_FEEDBACK_BINDING",i[i.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING=33296]="FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING",i[i.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE=33297]="FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE",i[i.FRAMEBUFFER_ATTACHMENT_RED_SIZE=33298]="FRAMEBUFFER_ATTACHMENT_RED_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_GREEN_SIZE=33299]="FRAMEBUFFER_ATTACHMENT_GREEN_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_BLUE_SIZE=33300]="FRAMEBUFFER_ATTACHMENT_BLUE_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE=33301]="FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE=33302]="FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE",i[i.FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE=33303]="FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE",i[i.FRAMEBUFFER_DEFAULT=33304]="FRAMEBUFFER_DEFAULT",i[i.DEPTH24_STENCIL8=35056]="DEPTH24_STENCIL8",i[i.DRAW_FRAMEBUFFER_BINDING=36006]="DRAW_FRAMEBUFFER_BINDING",i[i.READ_FRAMEBUFFER_BINDING=36010]="READ_FRAMEBUFFER_BINDING",i[i.RENDERBUFFER_SAMPLES=36011]="RENDERBUFFER_SAMPLES",i[i.FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER=36052]="FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER",i[i.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE=36182]="FRAMEBUFFER_INCOMPLETE_MULTISAMPLE",i[i.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",i[i.UNIFORM_BUFFER_BINDING=35368]="UNIFORM_BUFFER_BINDING",i[i.UNIFORM_BUFFER_START=35369]="UNIFORM_BUFFER_START",i[i.UNIFORM_BUFFER_SIZE=35370]="UNIFORM_BUFFER_SIZE",i[i.MAX_VERTEX_UNIFORM_BLOCKS=35371]="MAX_VERTEX_UNIFORM_BLOCKS",i[i.MAX_FRAGMENT_UNIFORM_BLOCKS=35373]="MAX_FRAGMENT_UNIFORM_BLOCKS",i[i.MAX_COMBINED_UNIFORM_BLOCKS=35374]="MAX_COMBINED_UNIFORM_BLOCKS",i[i.MAX_UNIFORM_BUFFER_BINDINGS=35375]="MAX_UNIFORM_BUFFER_BINDINGS",i[i.MAX_UNIFORM_BLOCK_SIZE=35376]="MAX_UNIFORM_BLOCK_SIZE",i[i.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS=35377]="MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS",i[i.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS=35379]="MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS",i[i.UNIFORM_BUFFER_OFFSET_ALIGNMENT=35380]="UNIFORM_BUFFER_OFFSET_ALIGNMENT",i[i.ACTIVE_UNIFORM_BLOCKS=35382]="ACTIVE_UNIFORM_BLOCKS",i[i.UNIFORM_TYPE=35383]="UNIFORM_TYPE",i[i.UNIFORM_SIZE=35384]="UNIFORM_SIZE",i[i.UNIFORM_BLOCK_INDEX=35386]="UNIFORM_BLOCK_INDEX",i[i.UNIFORM_OFFSET=35387]="UNIFORM_OFFSET",i[i.UNIFORM_ARRAY_STRIDE=35388]="UNIFORM_ARRAY_STRIDE",i[i.UNIFORM_MATRIX_STRIDE=35389]="UNIFORM_MATRIX_STRIDE",i[i.UNIFORM_IS_ROW_MAJOR=35390]="UNIFORM_IS_ROW_MAJOR",i[i.UNIFORM_BLOCK_BINDING=35391]="UNIFORM_BLOCK_BINDING",i[i.UNIFORM_BLOCK_DATA_SIZE=35392]="UNIFORM_BLOCK_DATA_SIZE",i[i.UNIFORM_BLOCK_ACTIVE_UNIFORMS=35394]="UNIFORM_BLOCK_ACTIVE_UNIFORMS",i[i.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES=35395]="UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES",i[i.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER=35396]="UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER",i[i.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER=35398]="UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER",i[i.OBJECT_TYPE=37138]="OBJECT_TYPE",i[i.SYNC_CONDITION=37139]="SYNC_CONDITION",i[i.SYNC_STATUS=37140]="SYNC_STATUS",i[i.SYNC_FLAGS=37141]="SYNC_FLAGS",i[i.SYNC_FENCE=37142]="SYNC_FENCE",i[i.SYNC_GPU_COMMANDS_COMPLETE=37143]="SYNC_GPU_COMMANDS_COMPLETE",i[i.UNSIGNALED=37144]="UNSIGNALED",i[i.SIGNALED=37145]="SIGNALED",i[i.ALREADY_SIGNALED=37146]="ALREADY_SIGNALED",i[i.TIMEOUT_EXPIRED=37147]="TIMEOUT_EXPIRED",i[i.CONDITION_SATISFIED=37148]="CONDITION_SATISFIED",i[i.WAIT_FAILED=37149]="WAIT_FAILED",i[i.SYNC_FLUSH_COMMANDS_BIT=1]="SYNC_FLUSH_COMMANDS_BIT",i[i.COLOR=6144]="COLOR",i[i.DEPTH=6145]="DEPTH",i[i.STENCIL=6146]="STENCIL",i[i.MIN=32775]="MIN",i[i.MAX=32776]="MAX",i[i.DEPTH_COMPONENT24=33190]="DEPTH_COMPONENT24",i[i.STREAM_READ=35041]="STREAM_READ",i[i.STREAM_COPY=35042]="STREAM_COPY",i[i.STATIC_READ=35045]="STATIC_READ",i[i.STATIC_COPY=35046]="STATIC_COPY",i[i.DYNAMIC_READ=35049]="DYNAMIC_READ",i[i.DYNAMIC_COPY=35050]="DYNAMIC_COPY",i[i.DEPTH_COMPONENT32F=36012]="DEPTH_COMPONENT32F",i[i.DEPTH32F_STENCIL8=36013]="DEPTH32F_STENCIL8",i[i.INVALID_INDEX=4294967295]="INVALID_INDEX",i[i.TIMEOUT_IGNORED=-1]="TIMEOUT_IGNORED",i[i.MAX_CLIENT_WAIT_TIMEOUT_WEBGL=37447]="MAX_CLIENT_WAIT_TIMEOUT_WEBGL",i[i.UNMASKED_VENDOR_WEBGL=37445]="UNMASKED_VENDOR_WEBGL",i[i.UNMASKED_RENDERER_WEBGL=37446]="UNMASKED_RENDERER_WEBGL",i[i.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047]="MAX_TEXTURE_MAX_ANISOTROPY_EXT",i[i.TEXTURE_MAX_ANISOTROPY_EXT=34046]="TEXTURE_MAX_ANISOTROPY_EXT",i[i.R16_EXT=33322]="R16_EXT",i[i.RG16_EXT=33324]="RG16_EXT",i[i.RGB16_EXT=32852]="RGB16_EXT",i[i.RGBA16_EXT=32859]="RGBA16_EXT",i[i.R16_SNORM_EXT=36760]="R16_SNORM_EXT",i[i.RG16_SNORM_EXT=36761]="RG16_SNORM_EXT",i[i.RGB16_SNORM_EXT=36762]="RGB16_SNORM_EXT",i[i.RGBA16_SNORM_EXT=36763]="RGBA16_SNORM_EXT",i[i.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",i[i.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",i[i.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",i[i.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",i[i.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",i[i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",i[i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",i[i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",i[i.COMPRESSED_RED_RGTC1_EXT=36283]="COMPRESSED_RED_RGTC1_EXT",i[i.COMPRESSED_SIGNED_RED_RGTC1_EXT=36284]="COMPRESSED_SIGNED_RED_RGTC1_EXT",i[i.COMPRESSED_RED_GREEN_RGTC2_EXT=36285]="COMPRESSED_RED_GREEN_RGTC2_EXT",i[i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT=36286]="COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT",i[i.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",i[i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",i[i.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",i[i.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",i[i.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",i[i.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",i[i.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",i[i.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",i[i.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",i[i.COMPRESSED_RGBA8_ETC2_EAC=37493]="COMPRESSED_RGBA8_ETC2_EAC",i[i.COMPRESSED_SRGB8_ETC2=37494]="COMPRESSED_SRGB8_ETC2",i[i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37495]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",i[i.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37496]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",i[i.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37497]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",i[i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",i[i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",i[i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",i[i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",i[i.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",i[i.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",i[i.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35986]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",i[i.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",i[i.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",i[i.COMPRESSED_RGBA_ASTC_5x4_KHR=37809]="COMPRESSED_RGBA_ASTC_5x4_KHR",i[i.COMPRESSED_RGBA_ASTC_5x5_KHR=37810]="COMPRESSED_RGBA_ASTC_5x5_KHR",i[i.COMPRESSED_RGBA_ASTC_6x5_KHR=37811]="COMPRESSED_RGBA_ASTC_6x5_KHR",i[i.COMPRESSED_RGBA_ASTC_6x6_KHR=37812]="COMPRESSED_RGBA_ASTC_6x6_KHR",i[i.COMPRESSED_RGBA_ASTC_8x5_KHR=37813]="COMPRESSED_RGBA_ASTC_8x5_KHR",i[i.COMPRESSED_RGBA_ASTC_8x6_KHR=37814]="COMPRESSED_RGBA_ASTC_8x6_KHR",i[i.COMPRESSED_RGBA_ASTC_8x8_KHR=37815]="COMPRESSED_RGBA_ASTC_8x8_KHR",i[i.COMPRESSED_RGBA_ASTC_10x5_KHR=37816]="COMPRESSED_RGBA_ASTC_10x5_KHR",i[i.COMPRESSED_RGBA_ASTC_10x6_KHR=37817]="COMPRESSED_RGBA_ASTC_10x6_KHR",i[i.COMPRESSED_RGBA_ASTC_10x8_KHR=37818]="COMPRESSED_RGBA_ASTC_10x8_KHR",i[i.COMPRESSED_RGBA_ASTC_10x10_KHR=37819]="COMPRESSED_RGBA_ASTC_10x10_KHR",i[i.COMPRESSED_RGBA_ASTC_12x10_KHR=37820]="COMPRESSED_RGBA_ASTC_12x10_KHR",i[i.COMPRESSED_RGBA_ASTC_12x12_KHR=37821]="COMPRESSED_RGBA_ASTC_12x12_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR=37840]="COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR=37841]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR=37842]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR=37843]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR=37844]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR=37845]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR=37846]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR=37847]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR=37848]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR=37849]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR=37850]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR=37851]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR=37852]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR",i[i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR=37853]="COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR",i[i.QUERY_COUNTER_BITS_EXT=34916]="QUERY_COUNTER_BITS_EXT",i[i.CURRENT_QUERY_EXT=34917]="CURRENT_QUERY_EXT",i[i.QUERY_RESULT_EXT=34918]="QUERY_RESULT_EXT",i[i.QUERY_RESULT_AVAILABLE_EXT=34919]="QUERY_RESULT_AVAILABLE_EXT",i[i.TIME_ELAPSED_EXT=35007]="TIME_ELAPSED_EXT",i[i.TIMESTAMP_EXT=36392]="TIMESTAMP_EXT",i[i.GPU_DISJOINT_EXT=36795]="GPU_DISJOINT_EXT",i[i.COMPLETION_STATUS_KHR=37297]="COMPLETION_STATUS_KHR",i[i.DEPTH_CLAMP_EXT=34383]="DEPTH_CLAMP_EXT",i[i.FIRST_VERTEX_CONVENTION_WEBGL=36429]="FIRST_VERTEX_CONVENTION_WEBGL",i[i.LAST_VERTEX_CONVENTION_WEBGL=36430]="LAST_VERTEX_CONVENTION_WEBGL",i[i.PROVOKING_VERTEX_WEBL=36431]="PROVOKING_VERTEX_WEBL",i[i.POLYGON_MODE_WEBGL=2880]="POLYGON_MODE_WEBGL",i[i.POLYGON_OFFSET_LINE_WEBGL=10754]="POLYGON_OFFSET_LINE_WEBGL",i[i.LINE_WEBGL=6913]="LINE_WEBGL",i[i.FILL_WEBGL=6914]="FILL_WEBGL",i[i.MAX_CLIP_DISTANCES_WEBGL=3378]="MAX_CLIP_DISTANCES_WEBGL",i[i.MAX_CULL_DISTANCES_WEBGL=33529]="MAX_CULL_DISTANCES_WEBGL",i[i.MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL=33530]="MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL",i[i.CLIP_DISTANCE0_WEBGL=12288]="CLIP_DISTANCE0_WEBGL",i[i.CLIP_DISTANCE1_WEBGL=12289]="CLIP_DISTANCE1_WEBGL",i[i.CLIP_DISTANCE2_WEBGL=12290]="CLIP_DISTANCE2_WEBGL",i[i.CLIP_DISTANCE3_WEBGL=12291]="CLIP_DISTANCE3_WEBGL",i[i.CLIP_DISTANCE4_WEBGL=12292]="CLIP_DISTANCE4_WEBGL",i[i.CLIP_DISTANCE5_WEBGL=12293]="CLIP_DISTANCE5_WEBGL",i[i.CLIP_DISTANCE6_WEBGL=12294]="CLIP_DISTANCE6_WEBGL",i[i.CLIP_DISTANCE7_WEBGL=12295]="CLIP_DISTANCE7_WEBGL",i[i.POLYGON_OFFSET_CLAMP_EXT=36379]="POLYGON_OFFSET_CLAMP_EXT",i[i.LOWER_LEFT_EXT=36001]="LOWER_LEFT_EXT",i[i.UPPER_LEFT_EXT=36002]="UPPER_LEFT_EXT",i[i.NEGATIVE_ONE_TO_ONE_EXT=37726]="NEGATIVE_ONE_TO_ONE_EXT",i[i.ZERO_TO_ONE_EXT=37727]="ZERO_TO_ONE_EXT",i[i.CLIP_ORIGIN_EXT=37724]="CLIP_ORIGIN_EXT",i[i.CLIP_DEPTH_MODE_EXT=37725]="CLIP_DEPTH_MODE_EXT",i[i.SRC1_COLOR_WEBGL=35065]="SRC1_COLOR_WEBGL",i[i.SRC1_ALPHA_WEBGL=34185]="SRC1_ALPHA_WEBGL",i[i.ONE_MINUS_SRC1_COLOR_WEBGL=35066]="ONE_MINUS_SRC1_COLOR_WEBGL",i[i.ONE_MINUS_SRC1_ALPHA_WEBGL=35067]="ONE_MINUS_SRC1_ALPHA_WEBGL",i[i.MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL=35068]="MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL",i[i.MIRROR_CLAMP_TO_EDGE_EXT=34627]="MIRROR_CLAMP_TO_EDGE_EXT"})(Yt||(Yt={}));const tm={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:{}},im=i=>({drawBuffersWEBGL(e){return i.drawBuffers(e)},COLOR_ATTACHMENT0_WEBGL:36064,COLOR_ATTACHMENT1_WEBGL:36065,COLOR_ATTACHMENT2_WEBGL:36066,COLOR_ATTACHMENT3_WEBGL:36067}),nm=i=>({VERTEX_ARRAY_BINDING_OES:34229,createVertexArrayOES(){return i.createVertexArray()},deleteVertexArrayOES(e){return i.deleteVertexArray(e)},isVertexArrayOES(e){return i.isVertexArray(e)},bindVertexArrayOES(e){return i.bindVertexArray(e)}}),rm=i=>({VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE:35070,drawArraysInstancedANGLE(...e){return i.drawArraysInstanced(...e)},drawElementsInstancedANGLE(...e){return i.drawElementsInstanced(...e)},vertexAttribDivisorANGLE(...e){return i.vertexAttribDivisor(...e)}});function sm(i=!0){const e=HTMLCanvasElement.prototype;if(!i&&e.originalGetContext){e.getContext=e.originalGetContext,e.originalGetContext=void 0;return}e.originalGetContext=e.getContext,e.getContext=function(t,n){if(t==="webgl"||t==="experimental-webgl"){const r=this.originalGetContext("webgl2",n);return r instanceof HTMLElement&&om(r),r}return this.originalGetContext(t,n)}}function om(i){i.getExtension("EXT_color_buffer_float");const e={...tm,WEBGL_disjoint_timer_query:i.getExtension("EXT_disjoint_timer_query_webgl2"),WEBGL_draw_buffers:im(i),OES_vertex_array_object:nm(i),ANGLE_instanced_arrays:rm(i)},t=i.getExtension;i.getExtension=function(r){const s=t.call(i,r);return s||(r in e?e[r]:null)};const n=i.getSupportedExtensions;i.getSupportedExtensions=function(){const r=n.apply(i)||[];return r==null?void 0:r.concat(Object.keys(e))}}async function dl(i,e){const t=document.getElementsByTagName("head")[0];if(!t)throw new Error("loadScript");const n=document.createElement("script");return n.setAttribute("type","text/javascript"),n.setAttribute("src",i),new Promise((r,s)=>{n.onload=r,n.onerror=o=>s(new Error(`Unable to load script '${i}': ${o}`)),t.appendChild(n)})}const am=1;let he=null,pl=!1;const Cs={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(i){if(!globalThis.SPECTOR)try{await dl(i.debugSpectorJSUrl||Cs.debugSpectorJSUrl)}catch(e){D.warn(String(e))}}function cm(i){var e;if(i={...Cs,...i},!i.debugSpectorJS)return null;if(!he&&globalThis.SPECTOR&&!((e=globalThis.luma)!=null&&e.spector)){D.probe(am,"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(pl||(pl=!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)})),i.gl){const t=i.gl,n=t.device;he==null||he.startCapture(i.gl,500),t.device=n,new Promise(r=>setTimeout(r,2e3)).then(r=>{D.info("Spector capture stopped after 2 seconds")(),he==null||he.stopCapture()})}return he}const um="https://unpkg.com/webgl-debug@2.0.1/index.js";function gl(i){return i.luma=i.luma||{},i.luma}async function fm(){Wt()&&!globalThis.WebGLDebugUtils&&(globalThis.global=globalThis.global||globalThis,globalThis.global.module={},await dl(um))}function hm(i,e={}){return e.debugWebGL||e.traceWebGL?pm(i,e):dm(i)}function dm(i){const e=gl(i);return e.realContext?e.realContext:i}function pm(i,e){if(!globalThis.WebGLDebugUtils)return D.warn("webgl-debug not loaded")(),i;const t=gl(i);if(t.debugContext)return t.debugContext;globalThis.WebGLDebugUtils.init({...Yt,...i});const n=globalThis.WebGLDebugUtils.makeDebugContext(i,gm.bind(null,e),mm.bind(null,e));for(const o in Yt)!(o in n)&&typeof Yt[o]=="number"&&(n[o]=Yt[o]);class r{}Object.setPrototypeOf(n,Object.getPrototypeOf(i)),Object.setPrototypeOf(r,n);const s=Object.create(r);return t.realContext=i,t.debugContext=s,s.debug=!0,s}function ml(i,e){e=Array.from(e).map(n=>n===void 0?"undefined":n);let t=globalThis.WebGLDebugUtils.glFunctionArgsToString(i,e);return t=`${t.slice(0,100)}${t.length>100?"...":""}`,`gl.${i}(${t})`}function gm(i,e,t,n){n=Array.from(n).map(a=>a===void 0?"undefined":a);const r=globalThis.WebGLDebugUtils.glEnumToString(e),s=globalThis.WebGLDebugUtils.glFunctionArgsToString(t,n),o=`${r} in gl.${t}(${s})`;D.error(o)();debugger}function mm(i,e,t){let n="";D.level>=1&&(n=ml(e,t),i.traceWebGL&&D.log(1,n)());for(const r of t)if(r===void 0){n=n||ml(e,t);debugger}}const Wn=1;class _m extends bg{constructor(){super();g(this,"type","webgl");$t.defaultProps={...$t.defaultProps,...Cs}}enforceWebGL2(t){sm(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,n={}){const{WebGLDevice:r}=await Promise.resolve().then(()=>Vl);if(t instanceof r)return t;if((t==null?void 0:t.device)instanceof r)return t.device;if(!xm(t))throw new Error("Invalid WebGL2RenderingContext");const s=n.createCanvasContext===!0?{}:n.createCanvasContext;return new r({...n,_handle:t,createCanvasContext:{canvas:t.canvas,autoResize:!1,...s}})}async create(t={}){const{WebGLDevice:n}=await Promise.resolve().then(()=>Vl);D.groupCollapsed(Wn,"WebGLDevice created")();try{const r=[];(t.debugWebGL||t.debug)&&r.push(fm()),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 n(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(Wn,a)(),D.table(Wn,o.info)(),o}finally{D.groupEnd(Wn)()}}}function xm(i){return typeof WebGL2RenderingContext<"u"&&i instanceof WebGL2RenderingContext?!0:!!(i&&Number.isFinite(i._version))}const ym=new _m,Ps={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=(i,e,t)=>e?i.enable(t):i.disable(t),_l=(i,e,t)=>i.hint(t,e),Ke=(i,e,t)=>i.pixelStorei(t,e),xl=(i,e,t)=>{const n=t===36006?36009:36008;return i.bindFramebuffer(n,e)},Bi=(i,e,t)=>{const r={34964:34962,36662:36662,36663:36663,35053:35051,35055:35052}[t];i.bindBuffer(r,e)};function Is(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}const vm={3042:ve,32773:(i,e)=>i.blendColor(...e),32777:"blendEquation",34877:"blendEquation",32969:"blendFunc",32968:"blendFunc",32971:"blendFunc",32970:"blendFunc",3106:(i,e)=>i.clearColor(...e),3107:(i,e)=>i.colorMask(...e),2884:ve,2885:(i,e)=>i.cullFace(e),2929:ve,2931:(i,e)=>i.clearDepth(e),2932:(i,e)=>i.depthFunc(e),2928:(i,e)=>i.depthRange(...e),2930:(i,e)=>i.depthMask(e),3024:ve,35723:_l,35725:(i,e)=>i.useProgram(e),36007:(i,e)=>i.bindRenderbuffer(36161,e),36389:(i,e)=>{var t;return(t=i.bindTransformFeedback)==null?void 0:t.call(i,36386,e)},34229:(i,e)=>i.bindVertexArray(e),36006:xl,36010:xl,34964:Bi,36662:Bi,36663:Bi,35053:Bi,35055:Bi,2886:(i,e)=>i.frontFace(e),33170:_l,2849:(i,e)=>i.lineWidth(e),32823:ve,32824:"polygonOffset",10752:"polygonOffset",35977:ve,32926:ve,32928:ve,32938:"sampleCoverage",32939:"sampleCoverage",3089:ve,3088:(i,e)=>i.scissor(...e),2960:ve,2961:(i,e)=>i.clearStencil(e),2968:(i,e)=>i.stencilMaskSeparate(1028,e),36005:(i,e)=>i.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:(i,e)=>i.viewport(...e),34383:ve,10754:ve,12288:ve,12289:ve,12290:ve,12291:ve,12292:ve,12293:ve,12294:ve,12295:ve,3333:Ke,3317:Ke,37440:Ke,37441:Ke,37443:Ke,3330:Ke,3332:Ke,3331:Ke,3314:Ke,32878:Ke,3316:Ke,3315:Ke,32877:Ke,framebuffer:(i,e)=>{const t=e&&"handle"in e?e.handle:e;return i.bindFramebuffer(36160,t)},blend:(i,e)=>e?i.enable(3042):i.disable(3042),blendColor:(i,e)=>i.blendColor(...e),blendEquation:(i,e)=>{const t=typeof e=="number"?[e,e]:e;i.blendEquationSeparate(...t)},blendFunc:(i,e)=>{const t=(e==null?void 0:e.length)===2?[...e,...e]:e;i.blendFuncSeparate(...t)},clearColor:(i,e)=>i.clearColor(...e),clearDepth:(i,e)=>i.clearDepth(e),clearStencil:(i,e)=>i.clearStencil(e),colorMask:(i,e)=>i.colorMask(...e),cull:(i,e)=>e?i.enable(2884):i.disable(2884),cullFace:(i,e)=>i.cullFace(e),depthTest:(i,e)=>e?i.enable(2929):i.disable(2929),depthFunc:(i,e)=>i.depthFunc(e),depthMask:(i,e)=>i.depthMask(e),depthRange:(i,e)=>i.depthRange(...e),dither:(i,e)=>e?i.enable(3024):i.disable(3024),derivativeHint:(i,e)=>{i.hint(35723,e)},frontFace:(i,e)=>i.frontFace(e),mipmapHint:(i,e)=>i.hint(33170,e),lineWidth:(i,e)=>i.lineWidth(e),polygonOffsetFill:(i,e)=>e?i.enable(32823):i.disable(32823),polygonOffset:(i,e)=>i.polygonOffset(...e),sampleCoverage:(i,e)=>i.sampleCoverage(e[0],e[1]||!1),scissorTest:(i,e)=>e?i.enable(3089):i.disable(3089),scissor:(i,e)=>i.scissor(...e),stencilTest:(i,e)=>e?i.enable(2960):i.disable(2960),stencilMask:(i,e)=>{e=Is(e)?e:[e,e];const[t,n]=e;i.stencilMaskSeparate(1028,t),i.stencilMaskSeparate(1029,n)},stencilFunc:(i,e)=>{e=Is(e)&&e.length===3?[...e,...e]:e;const[t,n,r,s,o,a]=e;i.stencilFuncSeparate(1028,t,n,r),i.stencilFuncSeparate(1029,s,o,a)},stencilOp:(i,e)=>{e=Is(e)&&e.length===3?[...e,...e]:e;const[t,n,r,s,o,a]=e;i.stencilOpSeparate(1028,t,n,r),i.stencilOpSeparate(1029,s,o,a)},viewport:(i,e)=>i.viewport(...e)};function xe(i,e,t){return e[i]!==void 0?e[i]:t[i]}const bm={blendEquation:(i,e,t)=>i.blendEquationSeparate(xe(32777,e,t),xe(34877,e,t)),blendFunc:(i,e,t)=>i.blendFuncSeparate(xe(32969,e,t),xe(32968,e,t),xe(32971,e,t),xe(32970,e,t)),polygonOffset:(i,e,t)=>i.polygonOffset(xe(32824,e,t),xe(10752,e,t)),sampleCoverage:(i,e,t)=>i.sampleCoverage(xe(32938,e,t),xe(32939,e,t)),stencilFuncFront:(i,e,t)=>i.stencilFuncSeparate(1028,xe(2962,e,t),xe(2967,e,t),xe(2963,e,t)),stencilFuncBack:(i,e,t)=>i.stencilFuncSeparate(1029,xe(34816,e,t),xe(36003,e,t),xe(36004,e,t)),stencilOpFront:(i,e,t)=>i.stencilOpSeparate(1028,xe(2964,e,t),xe(2965,e,t),xe(2966,e,t)),stencilOpBack:(i,e,t)=>i.stencilOpSeparate(1029,xe(34817,e,t),xe(34818,e,t),xe(34819,e,t))},yl={enable:(i,e)=>i({[e]:!0}),disable:(i,e)=>i({[e]:!1}),pixelStorei:(i,e,t)=>i({[e]:t}),hint:(i,e,t)=>i({[e]:t}),useProgram:(i,e)=>i({35725:e}),bindRenderbuffer:(i,e,t)=>i({36007:t}),bindTransformFeedback:(i,e,t)=>i({36389:t}),bindVertexArray:(i,e)=>i({34229:e}),bindFramebuffer:(i,e,t)=>{switch(e){case 36160:return i({36006:t,36010:t});case 36009:return i({36006:t});case 36008:return i({36010:t});default:return null}},bindBuffer:(i,e,t)=>{const n={34962:[34964],36662:[36662],36663:[36663],35051:[35053],35052:[35055]}[e];return n?i({[n]:t}):{valueChanged:!0}},blendColor:(i,e,t,n,r)=>i({32773:new Float32Array([e,t,n,r])}),blendEquation:(i,e)=>i({32777:e,34877:e}),blendEquationSeparate:(i,e,t)=>i({32777:e,34877:t}),blendFunc:(i,e,t)=>i({32969:e,32968:t,32971:e,32970:t}),blendFuncSeparate:(i,e,t,n,r)=>i({32969:e,32968:t,32971:n,32970:r}),clearColor:(i,e,t,n,r)=>i({3106:new Float32Array([e,t,n,r])}),clearDepth:(i,e)=>i({2931:e}),clearStencil:(i,e)=>i({2961:e}),colorMask:(i,e,t,n,r)=>i({3107:[e,t,n,r]}),cullFace:(i,e)=>i({2885:e}),depthFunc:(i,e)=>i({2932:e}),depthRange:(i,e,t)=>i({2928:new Float32Array([e,t])}),depthMask:(i,e)=>i({2930:e}),frontFace:(i,e)=>i({2886:e}),lineWidth:(i,e)=>i({2849:e}),polygonOffset:(i,e,t)=>i({32824:e,10752:t}),sampleCoverage:(i,e,t)=>i({32938:e,32939:t}),scissor:(i,e,t,n,r)=>i({3088:new Int32Array([e,t,n,r])}),stencilMask:(i,e)=>i({2968:e,36005:e}),stencilMaskSeparate:(i,e,t)=>i({[e===1028?2968:36005]:t}),stencilFunc:(i,e,t,n)=>i({2962:e,2967:t,2963:n,34816:e,36003:t,36004:n}),stencilFuncSeparate:(i,e,t,n,r)=>i({[e===1028?2962:34816]:t,[e===1028?2967:36003]:n,[e===1028?2963:36004]:r}),stencilOp:(i,e,t,n)=>i({2964:e,2965:t,2966:n,34817:e,34818:t,34819:n}),stencilOpSeparate:(i,e,t,n,r)=>i({[e===1028?2964:34817]:t,[e===1028?2965:34818]:n,[e===1028?2966:34819]:r}),viewport:(i,e,t,n,r)=>i({2978:[e,t,n,r]})},pt=(i,e)=>i.isEnabled(e),vl={3042:pt,2884:pt,2929:pt,3024:pt,32823:pt,32926:pt,32928:pt,3089:pt,2960:pt,35977:pt},Sm=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 fi(i,e){if(wm(e))return;const t={};for(const r in e){const s=Number(r),o=vm[r];o&&(typeof o=="string"?t[o]=!0:o(i,e[r],s))}const n=i.state&&i.state.cache;if(n)for(const r in t){const s=bm[r];s(i,e,n)}}function bl(i,e=Ps){if(typeof e=="number"){const r=e,s=vl[r];return s?s(i,r):i.getParameter(r)}const t=Array.isArray(e)?e:Object.keys(e),n={};for(const r of t){const s=vl[r];n[r]=s?s(i,Number(r)):i.getParameter(Number(r))}return n}function Tm(i){fi(i,Ps)}function wm(i){for(const e in i)return!1;return!0}function Am(i,e){if(i===e)return!0;if(Sl(i)&&Sl(e)&&i.length===e.length){for(let t=0;t<i.length;++t)if(i[t]!==e[t])return!1;return!0}return!1}function Sl(i){return Array.isArray(i)||ArrayBuffer.isView(i)}class qt{constructor(e,t){g(this,"gl");g(this,"program",null);g(this,"stateStack",[]);g(this,"enable",!0);g(this,"cache",null);g(this,"log");g(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];fi(this.gl,e),this.stateStack.pop()}trackState(e,t){if(this.cache=t!=null&&t.copyState?bl(e):Object.assign({},Ps),this.initialized)throw new Error("WebGLStateTracker");this.initialized=!0,this.gl.state=this,Pm(e);for(const n in yl){const r=yl[n];Cm(e,n,r)}Tl(e,"getParameter"),Tl(e,"isEnabled")}_updateCache(e){let t=!1,n;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];Am(o,a)||(t=!0,n=a,r&&!(s in r)&&(r[s]=a),this.cache[s]=o)}return{valueChanged:t,oldValue:n}}}function Tl(i,e){const t=i[e].bind(i);i[e]=function(r){if(r===void 0||Sm.has(r))return t(r);const s=qt.get(i);return r in s.cache||(s.cache[r]=t(r)),s.enable?s.cache[r]:t(r)},Object.defineProperty(i[e],"name",{value:`${e}-from-cache`,configurable:!1})}function Cm(i,e,t){if(!i[e])return;const n=i[e].bind(i);i[e]=function(...s){const o=qt.get(i),{valueChanged:a,oldValue:l}=t(o._updateCache,...s);return a&&n(...s),l},Object.defineProperty(i[e],"name",{value:`${e}-to-cache`,configurable:!1})}function Pm(i){const e=i.useProgram.bind(i);i.useProgram=function(n){const r=qt.get(i);r.program!==n&&(e(n),r.program=n)}}function Im(i,e,t){let n="";const r={preserveDrawingBuffer:!0,...t};let s=null;if(s||(s=i.getContext("webgl2",r)),r.failIfMajorPerformanceCaveat&&(n||(n="Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.")),!s&&!t.failIfMajorPerformanceCaveat&&(r.failIfMajorPerformanceCaveat=!1,s=i.getContext("webgl2",r),s.luma||(s.luma={}),s.luma.softwareRenderer=!0),s||(s=i.getContext("webgl",{}),s&&(s=null,n||(n="Your browser only supports WebGL1"))),!s)throw n||(n="Your browser does not support WebGL"),new Error(`Failed to create WebGL context: ${n}`);const{onContextLost:o,onContextRestored:a}=e;return i.addEventListener("webglcontextlost",l=>o(l),!1),i.addEventListener("webglcontextrestored",l=>a(l),!1),s.luma||(s.luma={}),s}function hi(i,e,t){return t[e]===void 0&&(t[e]=i.getExtension(e)||null),t[e]}function km(i,e){const t=i.getParameter(7936),n=i.getParameter(7937);hi(i,"WEBGL_debug_renderer_info",e);const r=e.WEBGL_debug_renderer_info,s=i.getParameter(r?r.UNMASKED_VENDOR_WEBGL:7936),o=i.getParameter(r?r.UNMASKED_RENDERER_WEBGL:7937),a=s||t,l=o||n,c=i.getParameter(7938),u=wl(a,l),f=Rm(a,l),h=Em(a,l);return{type:"webgl",gpu:u,gpuType:h,gpuBackend:f,vendor:a,renderer:l,version:c,shadingLanguage:"glsl",shadingLanguageVersion:300}}function wl(i,e){return/NVIDIA/i.exec(i)||/NVIDIA/i.exec(e)?"nvidia":/INTEL/i.exec(i)||/INTEL/i.exec(e)?"intel":/Apple/i.exec(i)||/Apple/i.exec(e)?"apple":/AMD/i.exec(i)||/AMD/i.exec(e)||/ATI/i.exec(i)||/ATI/i.exec(e)?"amd":/SwiftShader/i.exec(i)||/SwiftShader/i.exec(e)?"software":"unknown"}function Rm(i,e){return/Metal/i.exec(i)||/Metal/i.exec(e)?"metal":/ANGLE/i.exec(i)||/ANGLE/i.exec(e)?"opengl":"unknown"}function Em(i,e){if(/SwiftShader/i.exec(i)||/SwiftShader/i.exec(e))return"cpu";switch(wl(i,e)){case"intel":return"integrated";case"software":return"cpu";case"unknown":return"unknown";default:return"discrete"}}function Al(i){switch(i){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(i))}const Ui="WEBGL_compressed_texture_s3tc",zi="WEBGL_compressed_texture_s3tc_srgb",di="EXT_texture_compression_rgtc",pi="EXT_texture_compression_bptc",Dm="WEBGL_compressed_texture_etc",Fm="WEBGL_compressed_texture_astc",Mm="WEBGL_compressed_texture_etc1",Nm="WEBGL_compressed_texture_pvrtc",Om="WEBGL_compressed_texture_atc",Cl="EXT_texture_norm16",Pl="EXT_render_snorm",Bm="EXT_color_buffer_float",ks={"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":[Pl],"norm16-renderable-webgl":[Cl],"snorm16-renderable-webgl":[Cl,Pl],"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":[Ui,zi,di,pi],"texture-compression-bc5-webgl":[di],"texture-compression-bc7-webgl":[pi],"texture-compression-etc2":[Dm],"texture-compression-astc":[Fm],"texture-compression-etc1-webgl":[Mm],"texture-compression-pvrtc-webgl":[Nm],"texture-compression-atc-webgl":[Om]};function Um(i){return i in ks}function zm(i,e,t){return(ks[e]||[]).every(r=>hi(i,r,t))}const Rs={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:Bm,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:Ui},"bc1-rgb-unorm-srgb-webgl":{gl:35916,x:zi},"bc1-rgba-unorm":{gl:33777,x:Ui},"bc1-rgba-unorm-srgb":{gl:35916,x:zi},"bc2-rgba-unorm":{gl:33778,x:Ui},"bc2-rgba-unorm-srgb":{gl:35918,x:zi},"bc3-rgba-unorm":{gl:33779,x:Ui},"bc3-rgba-unorm-srgb":{gl:35919,x:zi},"bc4-r-unorm":{gl:36283,x:di},"bc4-r-snorm":{gl:36284,x:di},"bc5-rg-unorm":{gl:36285,x:di},"bc5-rg-snorm":{gl:36286,x:di},"bc6h-rgb-ufloat":{gl:36495,x:pi},"bc6h-rgb-float":{gl:36494,x:pi},"bc7-rgba-unorm":{gl:36492,x:pi},"bc7-rgba-unorm-srgb":{gl:36493,x:pi},"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 Lm(i,e,t){let n=e.create;const r=Rs[e.format];return(r==null?void 0:r.gl)===void 0&&(n=!1),r!=null&&r.x&&(n=n&&!!hi(i,r.x,t)),{format:e.format,create:n&&e.create,render:n&&e.render,filter:n&&e.filter,blend:n&&e.blend,store:n&&e.store}}function Il(i){var r;const e=Rs[i],t=Hm(i),n=Ht.getInfo(i);return n.compressed&&(e.dataFormat=t),{internalFormat:t,format:(e==null?void 0:e.dataFormat)||Wm(n.channels,n.integer,n.normalized,t),type:n.dataType?Al(n.dataType):((r=e==null?void 0:e.types)==null?void 0:r[0])||5121,compressed:n.compressed||!1}}function Vm(i){switch(Ht.getInfo(i).attachment){case"depth":return 36096;case"stencil":return 36128;case"depth-stencil":return 33306;default:throw new Error(`Not a depth stencil format: ${i}`)}}function Wm(i,e,t,n){if(n===6408||n===6407)return n;switch(i){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 Hm(i){const e=Rs[i],t=e==null?void 0:e.gl;if(t===void 0)throw new Error(`Unsupported texture format ${i}`);return t}const kl={"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 $m extends xg{constructor(t,n,r){super([],r);g(this,"gl");g(this,"extensions");g(this,"testedFeatures",new Set);this.gl=t,this.extensions=n,hi(t,"EXT_color_buffer_float",n)}*[Symbol.iterator](){const t=this.getFeatures();for(const n of t)this.has(n)&&(yield n);return[]}has(t){var n;return(n=this.disabledFeatures)!=null&&n[t]?!1:(this.testedFeatures.has(t)||(this.testedFeatures.add(t),Um(t)&&zm(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(n=>n!=="polygon-mode-webgl");for(const n of t)this.has(n)}getFeatures(){return[...Object.keys(kl),...Object.keys(ks)]}getWebGLFeature(t){const n=kl[t];return typeof n=="string"?!!hi(this.gl,n,this.extensions):!!n}}class Xm extends _g{constructor(t){super();g(this,"gl");g(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 Li extends Un{constructor(t,n){super(t,n);g(this,"device");g(this,"gl");g(this,"handle");g(this,"colorAttachments",[]);g(this,"depthStencilAttachment",null);const r=n.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 n=0;n<this.colorAttachments.length;++n){const r=this.colorAttachments[n];if(r){const s=36064+n;this._attachTextureView(s,r)}}if(this.depthStencilAttachment){const n=Vm(this.depthStencilAttachment.props.format);this._attachTextureView(n,this.depthStencilAttachment)}if(this.device.props.debug){const n=this.gl.checkFramebufferStatus(36160);if(n!==36053)throw new Error(`Framebuffer ${qm(n)}`)}this.gl.bindFramebuffer(36160,t)}_attachTextureView(t,n){const{gl:r}=this.device,{texture:s}=n,o=n.props.baseMipLevel,a=n.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=Ym(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 Ym(i){return i<34069?i+34069:i}function qm(i){switch(i){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`${i}`}}class jm extends Nn{constructor(t,n){super(n);g(this,"device");g(this,"handle",null);g(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 Li(this.device,{handle:null}),this._framebuffer}_updateDevice(){}}const Es={};function Km(i="id"){Es[i]=Es[i]||1;const e=Es[i]++;return`${i}-${e}`}class Vi extends H{constructor(t,n={}){super(t,n);g(this,"device");g(this,"gl");g(this,"handle");g(this,"glTarget");g(this,"glUsage");g(this,"glIndexType",5123);g(this,"byteLength",0);g(this,"bytesUsed",0);this.device=t,this.gl=this.device.gl;const r=typeof n=="object"?n.handle:void 0;this.handle=r||this.gl.createBuffer(),t._setWebGLDebugMetadata(this.handle,this,{spector:{...this.props,data:typeof this.props.data}}),this.glTarget=Zm(this.props.usage),this.glUsage=Qm(this.props.usage),this.glIndexType=this.props.indexType==="uint32"?5125:5123,n.data?this._initWithData(n.data,n.byteOffset,n.byteLength):this._initWithByteLength(n.byteLength||0)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.trackDeallocatedMemory(),this.gl.deleteBuffer(this.handle),this.destroyed=!0,this.handle=null)}_initWithData(t,n=0,r=t.byteLength+n){const s=this.glTarget;this.gl.bindBuffer(s,this.handle),this.gl.bufferData(s,r,this.glUsage),this.gl.bufferSubData(s,n,t),this.gl.bindBuffer(s,null),this.bytesUsed=r,this.byteLength=r,this._setDebugData(t,n,r),this.trackAllocatedMemory(r)}_initWithByteLength(t){let n=t;t===0&&(n=new Float32Array(0));const r=this.glTarget;return this.gl.bindBuffer(r,this.handle),this.gl.bufferData(r,n,this.glUsage),this.gl.bindBuffer(r,null),this.bytesUsed=t,this.byteLength=t,this._setDebugData(null,0,t),this.trackAllocatedMemory(t),this}write(t,n=0){const r=ArrayBuffer.isView(t)?t:new Uint8Array(t),s=36663;this.gl.bindBuffer(s,this.handle),this.gl.bufferSubData(s,n,r),this.gl.bindBuffer(s,null),this._setDebugData(t,n,t.byteLength)}async mapAndWriteAsync(t,n=0,r=this.byteLength-n){const s=new ArrayBuffer(r);await t(s,"copied"),this.write(s,n)}async readAsync(t=0,n){return this.readSyncWebGL(t,n)}async mapAndReadAsync(t,n=0,r){const s=await this.readAsync(n,r);return await t(s.buffer,"copied")}readSyncWebGL(t=0,n){n=n??this.byteLength-t;const r=new Uint8Array(n),s=0;return this.gl.bindBuffer(36662,this.handle),this.gl.getBufferSubData(36662,t,r,s,n),this.gl.bindBuffer(36662,null),this._setDebugData(r,t,n),r}}function Zm(i){return i&H.INDEX?34963:i&H.VERTEX?34962:i&H.UNIFORM?35345:34962}function Qm(i){return i&H.INDEX||i&H.VERTEX?35044:i&H.UNIFORM?35048:35044}function Jm(i){const e=i.split(/\r?\n/),t=[];for(const n of e){if(n.length<=1)continue;const r=n.split(":");if(r.length===2){const[f,h]=r;t.push({message:h.trim(),type:Rl(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:Rl(s),lineNum:c,linePos:u})}return t}function Rl(i){const e=["warning","error","info"],t=i.toLowerCase();return e.includes(t)?t:"info"}class Gm extends Bn{constructor(t,n){super(t,n);g(this,"device");g(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?Jm(t):[]}getTranslatedSource(){const n=this.device.getExtension("WEBGL_debug_shaders").WEBGL_debug_shaders;return(n==null?void 0:n.getTranslatedShaderSource(this.handle))||null}async _compile(t){t=t.startsWith("#version ")?t:`#version 300 es
12
+ ${t}`;const{gl:n}=this.device;if(n.shaderSource(this.handle,t),n.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 e_(i,e,t,n){if(r_(e))return n(i);const r=i;r.pushState();try{return t_(i,e),fi(r.gl,t),n(i)}finally{r.popState()}}function t_(i,e){const t=i,{gl:n}=t;if(e.cullMode)switch(e.cullMode){case"none":n.disable(2884);break;case"front":n.enable(2884),n.cullFace(1028);break;case"back":n.enable(2884),n.cullFace(1029);break}if(e.frontFace&&n.frontFace(jt("frontFace",e.frontFace,{ccw:2305,cw:2304})),e.unclippedDepth&&i.features.has("depth-clip-control")&&n.enable(34383),e.depthBias!==void 0&&(n.enable(32823),n.polygonOffset(e.depthBias,e.depthBiasSlopeScale||0)),e.provokingVertex&&i.features.has("provoking-vertex-webgl")){const s=t.getExtension("WEBGL_provoking_vertex").WEBGL_provoking_vertex,o=jt("provokingVertex",e.provokingVertex,{first:36429,last:36430});s==null||s.provokingVertexWEBGL(o)}if((e.polygonMode||e.polygonOffsetLine)&&i.features.has("polygon-mode-webgl")){if(e.polygonMode){const s=t.getExtension("WEBGL_polygon_mode").WEBGL_polygon_mode,o=jt("polygonMode",e.polygonMode,{fill:6914,line:6913});s==null||s.polygonModeWEBGL(1028,o),s==null||s.polygonModeWEBGL(1029,o)}e.polygonOffsetLine&&n.enable(10754)}if(i.features.has("shader-clip-cull-distance-webgl")&&(e.clipDistance0&&n.enable(12288),e.clipDistance1&&n.enable(12289),e.clipDistance2&&n.enable(12290),e.clipDistance3&&n.enable(12291),e.clipDistance4&&n.enable(12292),e.clipDistance5&&n.enable(12293),e.clipDistance6&&n.enable(12294),e.clipDistance7&&n.enable(12295)),e.depthWriteEnabled!==void 0&&n.depthMask(n_("depthWriteEnabled",e.depthWriteEnabled)),e.depthCompare&&(e.depthCompare!=="always"?n.enable(2929):n.disable(2929),n.depthFunc(Ds("depthCompare",e.depthCompare))),e.stencilWriteMask){const r=e.stencilWriteMask;n.stencilMaskSeparate(1028,r),n.stencilMaskSeparate(1029,r)}if(e.stencilReadMask&&D.warn("stencilReadMask not supported under WebGL"),e.stencilCompare){const r=e.stencilReadMask||4294967295,s=Ds("depthCompare",e.stencilCompare);e.stencilCompare!=="always"?n.enable(2960):n.disable(2960),n.stencilFuncSeparate(1028,s,0,r),n.stencilFuncSeparate(1029,s,0,r)}if(e.stencilPassOperation&&e.stencilFailOperation&&e.stencilDepthFailOperation){const r=Fs("stencilPassOperation",e.stencilPassOperation),s=Fs("stencilFailOperation",e.stencilFailOperation),o=Fs("stencilDepthFailOperation",e.stencilDepthFailOperation);n.stencilOpSeparate(1028,s,o,r),n.stencilOpSeparate(1029,s,o,r)}switch(e.blend){case!0:n.enable(3042);break;case!1:n.disable(3042);break}if(e.blendColorOperation||e.blendAlphaOperation){const r=El("blendColorOperation",e.blendColorOperation||"add"),s=El("blendAlphaOperation",e.blendAlphaOperation||"add");n.blendEquationSeparate(r,s);const o=Hn("blendColorSrcFactor",e.blendColorSrcFactor||"one"),a=Hn("blendColorDstFactor",e.blendColorDstFactor||"zero"),l=Hn("blendAlphaSrcFactor",e.blendAlphaSrcFactor||"one"),c=Hn("blendAlphaDstFactor",e.blendAlphaDstFactor||"zero");n.blendFuncSeparate(o,a,l,c)}}function Ds(i,e){return jt(i,e,{never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519})}function Fs(i,e){return jt(i,e,{keep:7680,zero:0,replace:7681,invert:5386,"increment-clamp":7682,"decrement-clamp":7683,"increment-wrap":34055,"decrement-wrap":34056})}function El(i,e){return jt(i,e,{add:32774,subtract:32778,"reverse-subtract":32779,min:32775,max:32776})}function Hn(i,e,t="color"){return jt(i,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 i_(i,e){return`Illegal parameter ${e} for ${i}`}function jt(i,e,t){if(!(e in t))throw new Error(i_(i,e));return t[e]}function n_(i,e){return e}function r_(i){let e=!0;for(const t in i){e=!1;break}return e}function Dl(i){const e={};return i.addressModeU&&(e[10242]=Ms(i.addressModeU)),i.addressModeV&&(e[10243]=Ms(i.addressModeV)),i.addressModeW&&(e[32882]=Ms(i.addressModeW)),i.magFilter&&(e[10240]=Ns(i.magFilter)),(i.minFilter||i.mipmapFilter)&&(e[10241]=s_(i.minFilter||"linear",i.mipmapFilter)),i.lodMinClamp!==void 0&&(e[33082]=i.lodMinClamp),i.lodMaxClamp!==void 0&&(e[33083]=i.lodMaxClamp),i.type==="comparison-sampler"&&(e[34892]=34894),i.compare&&(e[34893]=Ds("compare",i.compare)),i.maxAnisotropy&&(e[34046]=i.maxAnisotropy),e}function Ms(i){switch(i){case"clamp-to-edge":return 33071;case"repeat":return 10497;case"mirror-repeat":return 33648}}function Ns(i){switch(i){case"nearest":return 9728;case"linear":return 9729}}function s_(i,e="none"){if(!e)return Ns(i);switch(e){case"none":return Ns(i);case"nearest":switch(i){case"nearest":return 9984;case"linear":return 9985}break;case"linear":switch(i){case"nearest":return 9986;case"linear":return 9987}}}class o_ extends ui{constructor(t,n){super(t,n);g(this,"device");g(this,"handle");g(this,"parameters");this.device=t,this.parameters=Dl(n),this.handle=n.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[n,r]of Object.entries(t)){const s=Number(n);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 Wi(i,e,t){if(a_(e))return t(i);const{nocatch:n=!0}=e,r=qt.get(i);r.push(),fi(i,e);let s;if(n)s=t(i),r.pop();else try{s=t(i)}finally{r.pop()}return s}function a_(i){for(const e in i)return!1;return!0}class gi extends On{constructor(t,n){super(t,{...X.defaultProps,...n});g(this,"device");g(this,"gl");g(this,"handle");g(this,"texture");this.device=t,this.gl=this.device.gl,this.handle=null,this.texture=n.texture}}class Hi extends X{constructor(t,n){super(t,n);g(this,"device");g(this,"gl");g(this,"handle");g(this,"sampler");g(this,"view");g(this,"glTarget");g(this,"glFormat");g(this,"glType");g(this,"glInternalFormat");g(this,"compressed");g(this,"_textureUnit",0);this.device=t,this.gl=this.device.gl;const r=Il(this.props.format);this.glTarget=l_(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(n.data),this.setSampler(this.props.sampler),this.view=new gi(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 gi(this.device,{...t,texture:this})}setSampler(t={}){super.setSampler(t);const n=Dl(this.sampler.props);this._setSamplerParameters(n)}copyImageData(t){const n=this._normalizeCopyImageDataOptions(t),r=n.data,{width:s,height:o,depth:a}=this,{mipLevel:l=0,byteOffset:c=0,x:u=0,y:f=0,z:h=0}=n,{glFormat:d,glType:_,compressed:P}=this,I=Fl(this.glTarget,this.dimension,h);let w;if(!this.compressed){const{bytesPerPixel:k}=this.device.getTextureFormatInfo(this.format);if(k){if(n.bytesPerRow%k!==0)throw new Error(`bytesPerRow (${n.bytesPerRow}) must be a multiple of bytesPerPixel (${k}) for ${this.format}`);w=n.bytesPerRow/k}}const M=this.compressed?{}:{...w!==void 0?{3314:w}:{},32878:n.rowsPerImage};this.gl.bindTexture(I,this.handle),Wi(this.gl,M,()=>{switch(this.dimension){case"2d":case"cube":P?this.gl.compressedTexSubImage2D(I,l,u,f,s,o,d,r,c):this.gl.texSubImage2D(I,l,u,f,s,o,d,_,r,c);break;case"2d-array":case"3d":P?this.gl.compressedTexSubImage3D(I,l,u,f,h,s,o,a,d,r,c):this.gl.texSubImage3D(I,l,u,f,h,s,o,a,d,_,r,c);break;default:}}),this.gl.bindTexture(I,null)}copyExternalImage(t){const n=this._normalizeCopyExternalImageOptions(t);if(n.sourceX||n.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}=n,_=Fl(this.glTarget,this.dimension,a),P=n.flipY?{37440:!0}:{};return this.gl.bindTexture(this.glTarget,this.handle),Wi(this.gl,P,()=>{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:n.width,height:n.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[n,r]of Object.entries(t)){const s=Number(n),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:n}=this;return t!==void 0&&(this._textureUnit=t,n.activeTexture(33984+t)),n.bindTexture(this.glTarget,this.handle),t}_unbind(t){const{gl:n}=this;return t!==void 0&&(this._textureUnit=t,n.activeTexture(33984+t)),n.bindTexture(this.glTarget,null),t}}function l_(i){switch(i){case"1d":break;case"2d":return 3553;case"3d":return 32879;case"cube":return 34067;case"2d-array":return 35866}throw new Error(i)}function Fl(i,e,t){return e==="cube"?34069+t:i}function c_(i){return d_[i]}function Os(i){return h_[i]}function u_(i){return!!Ml[i]}function f_(i){return Ml[i]}const h_={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>"},Ml={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"}},d_={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 p_(i,e){const t={attributes:[],bindings:[]};t.attributes=g_(i,e);const n=x_(i,e);for(const a of n){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,e);let s=0;for(const a of r)if(u_(a.type)){const{viewDimension:l,sampleType:c}=f_(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=m_(i,e);return o!=null&&o.length&&(t.varyings=o),t}function g_(i,e){const t=[],n=i.getProgramParameter(e,35721);for(let r=0;r<n;r++){const s=i.getActiveAttrib(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a}=s,l=i.getAttribLocation(e,o);if(l>=0){const c=Os(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 m_(i,e){const t=[],n=i.getProgramParameter(e,35971);for(let r=0;r<n;r++){const s=i.getTransformFeedbackVarying(e,r);if(!s)throw new Error("activeInfo");const{name:o,type:a,size:l}=s,c=Os(a),{type:u,components:f}=ul(c);t.push({location:r,name:o,type:u,size:l*f})}return t.sort((r,s)=>r.location-s.location),t}function __(i,e){const t=[],n=i.getProgramParameter(e,35718);for(let r=0;r<n;r++){const s=i.getActiveUniform(e,r);if(!s)throw new Error("activeInfo");const{name:o,size:a,type:l}=s,{name:c,isArray:u}=y_(o);let f=i.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=i.getUniformLocation(e,_);const P={...h,name:_,location:f};t.push(P)}}return t}function x_(i,e){const t=(s,o)=>i.getActiveUniformBlockParameter(e,s,o),n=[],r=i.getProgramParameter(e,35382);for(let s=0;s<r;s++){const o={name:i.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=i.getActiveUniforms(e,a,35383),c=i.getActiveUniforms(e,a,35384),u=i.getActiveUniforms(e,a,35387),f=i.getActiveUniforms(e,a,35388);for(let h=0;h<o.uniformCount;++h){const d=i.getActiveUniform(e,a[h]);if(!d)throw new Error("activeInfo");const _=Os(l[h]);o.uniforms.push({name:d.name,format:_,type:l[h],arrayLength:c[h],byteOffset:u[h],byteStride:f[h]})}n.push(o)}return n.sort((s,o)=>s.location-o.location),n}function y_(i){if(i[i.length-1]!=="]")return{name:i,length:1,isArray:!1};const t=/([^[]*)(\[[0-9]+\])?/.exec(i);if(!t||t.length<2)throw new Error(`Failed to parse GLSL uniform name ${i}`);return{name:t[1],length:t[2]?1:0,isArray:!!t[2]}}function v_(i,e,t,n){const r=i;let s=n;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 n!="number")throw new Error("samplers must be set to integers");return i.uniform1i(e,n);case 5126:return i.uniform1fv(e,o);case 35664:return i.uniform2fv(e,o);case 35665:return i.uniform3fv(e,o);case 35666:return i.uniform4fv(e,o);case 5124:return i.uniform1iv(e,o);case 35667:return i.uniform2iv(e,o);case 35668:return i.uniform3iv(e,o);case 35669:return i.uniform4iv(e,o);case 35670:return i.uniform1iv(e,o);case 35671:return i.uniform2iv(e,o);case 35672:return i.uniform3iv(e,o);case 35673:return i.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 i.uniformMatrix2fv(e,!1,o);case 35675:return i.uniformMatrix3fv(e,!1,o);case 35676:return i.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 b_(i){switch(i){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(i)}}function S_(i){switch(i){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(i)}}const Nl=4;class T_ extends Xt{constructor(t,n){super(t,n);g(this,"device");g(this,"handle");g(this,"vs");g(this,"fs");g(this,"introspectedLayout");g(this,"uniforms",{});g(this,"bindings",{});g(this,"varyings",null);g(this,"_uniformCount",0);g(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=n.vs,this.fs=n.fs;const{varyings:r,bufferMode:s=35981}=n;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=p_(this.device.gl,this.handle),D.timeEnd(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.shaderLayout=n.shaderLayout?w_(this.introspectedLayout,n.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,n){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(", ");n!=null&&n.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 Vi)&&!(s.buffer instanceof Vi))throw new Error("buffer value");break;case"texture":if(!(s instanceof gi||s instanceof Hi||s instanceof Li))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 I;const{renderPass:n,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=b_(s),d=!!o.indexBuffer,_=(I=o.indexBuffer)==null?void 0:I.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(n),f&&f.begin(this.props.topology),this._applyBindings(),this._applyUniforms();const P=n;return e_(this.device,r,P.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(n),!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(Nl,`linkProgram for ${this.id}`)(),t.linkProgram(this.handle),D.timeEnd(Nl,`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 n=this._getLinkStatus();this._reportLinkStatus(n)}async _reportLinkStatus(t){var n;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((n=this.fs)==null?void 0:n.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 n of this.shaderLayout.bindings)!this.bindings[n.name]&&!this.bindings[n.name.replace(/Uniforms$/,"")]&&(D.warn(`Binding ${n.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 n=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 Vi?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 gi||o instanceof Hi||o instanceof Li))throw new Error("texture");let c;if(o instanceof gi)c=o.texture;else if(o instanceof Hi)c=o;else if(o instanceof Li&&o.colorAttachments[0]instanceof gi)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+n),t.bindTexture(c.glTarget,c.handle),n+=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:n,location:r,type:s,textureUnit:o}=t,a=this.uniforms[n]??o;a!==void 0&&v_(this.device.gl,r,s,a)}}}function w_(i,e){const t={...i,attributes:i.attributes.map(n=>({...n}))};for(const n of(e==null?void 0:e.attributes)||[]){const r=t.attributes.find(s=>s.name===n.name);r?(r.type=n.type||r.type,r.stepMode=n.stepMode||r.stepMode):D.warn(`shader layout attribute ${n.name} not present in shader`)}return t}class A_ extends Ss{constructor(t){super(t,{});g(this,"device");g(this,"handle",null);g(this,"commands",[]);this.device=t}_executeCommands(t=this.commands){for(const n of t)switch(n.name){case"copy-buffer-to-buffer":C_(this.device,n.options);break;case"copy-buffer-to-texture":P_(this.device,n.options);break;case"copy-texture-to-buffer":I_(this.device,n.options);break;case"copy-texture-to-texture":k_(this.device,n.options);break;default:throw new Error(n.name)}}}function C_(i,e){const t=e.sourceBuffer,n=e.destinationBuffer;i.gl.bindBuffer(36662,t.handle),i.gl.bindBuffer(36663,n.handle),i.gl.copyBufferSubData(36662,36663,e.sourceOffset??0,e.destinationOffset??0,e.size),i.gl.bindBuffer(36662,null),i.gl.bindBuffer(36663,null)}function P_(i,e){throw new Error("Not implemented")}function I_(i,e){const{sourceTexture:t,mipLevel:n=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(n!==0||a!==0||f||h)throw new Error("not implemented");const{framebuffer:d,destroyFramebuffer:_}=Ol(t);let P;try{const I=c,w=s||d.width,M=o||d.height,k=Il(d.colorAttachments[0].texture.props.format),y=k.format,R=k.type;i.gl.bindBuffer(35051,I.handle),P=i.gl.bindFramebuffer(36160,d.handle),i.gl.readPixels(l[0],l[1],w,M,y,R,u)}finally{i.gl.bindBuffer(35051,null),P!==void 0&&i.gl.bindFramebuffer(36160,P),_&&d.destroy()}}function k_(i,e){const{sourceTexture:t,destinationMipLevel:n=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}=Ol(t),[f,h]=r,[d,_,P]=s,I=i.gl.bindFramebuffer(36160,c.handle);let w,M;if(o instanceof Hi)w=o,a=Number.isFinite(a)?a:w.width,l=Number.isFinite(l)?l:w.height,w._bind(0),M=w.glTarget;else throw new Error("invalid destination");switch(M){case 3553:case 34067:i.gl.copyTexSubImage2D(M,n,d,_,f,h,a,l);break;case 35866:case 32879:i.gl.copyTexSubImage3D(M,n,d,_,P,f,h,a,l);break}w&&w._unbind(),i.gl.bindFramebuffer(36160,I),u&&c.destroy()}function Ol(i){if(i instanceof X){const{width:e,height:t,id:n}=i;return{framebuffer:i.device.createFramebuffer({id:`framebuffer-for-${n}`,width:e,height:t,colorAttachments:[i]}),destroyFramebuffer:!0}}return{framebuffer:i,destroyFramebuffer:!1}}const R_=[1,2,4,8];class E_ extends vs{constructor(t,n){var o;super(t,n);g(this,"device");g(this,"handle",null);g(this,"glParameters",{});this.device=t;let r;if(!((o=n==null?void 0:n.parameters)!=null&&o.viewport))if(n!=null&&n.framebuffer){const{width:a,height:l}=n.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 n={...this.glParameters};n.framebuffer=this.props.framebuffer||null,this.props.depthReadOnly&&(n.depthMask=!this.props.depthReadOnly),n.stencilMask=this.props.stencilReadOnly?0:1,n[35977]=this.props.discard,t.viewport&&(t.viewport.length>=6?(n.viewport=t.viewport.slice(0,4),n.depthRange=[t.viewport[4],t.viewport[5]]):n.viewport=t.viewport),t.scissorRect&&(n.scissorTest=!0,n.scissor=t.scissorRect),t.blendConstant&&(n.blendColor=t.blendConstant),t.stencilReference&&(console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL"),n[2967]=t.stencilReference),"colorMask"in t&&(n.colorMask=R_.map(r=>!!(r&t.colorMask))),this.glParameters=n,fi(this.device.gl,n)}beginOcclusionQuery(t){const n=this.props.occlusionQuerySet;n==null||n.beginOcclusionQuery()}endOcclusionQuery(){const t=this.props.occlusionQuerySet;t==null||t.endOcclusionQuery()}clear(){const t={...this.glParameters};let n=0;this.props.clearColors&&this.props.clearColors.forEach((r,s)=>{r&&this.clearColorBuffer(s,r)}),this.props.clearColor!==!1&&this.props.clearColors===void 0&&(n|=16384,t.clearColor=this.props.clearColor),this.props.clearDepth!==!1&&(n|=256,t.clearDepth=this.props.clearDepth),this.props.clearStencil!==!1&&(n|=1024,t.clearStencil=this.props.clearStencil),n!==0&&Wi(this.device.gl,t,()=>{this.device.gl.clear(n)})}clearColorBuffer(t=0,n=[0,0,0,0]){Wi(this.device.gl,{framebuffer:this.props.framebuffer},()=>{switch(n.constructor){case Int8Array:case Int16Array:case Int32Array:this.device.gl.clearBufferiv(6144,t,n);break;case Uint8Array:case Uint8ClampedArray:case Uint16Array:case Uint32Array:this.device.gl.clearBufferuiv(6144,t,n);break;case Float32Array:this.device.gl.clearBufferfv(6144,t,n);break;default:throw new Error("clearColorBuffer: color must be typed array")}})}}class Bl extends bs{constructor(t,n){super(t,n);g(this,"device");g(this,"handle",null);g(this,"commandBuffer");this.device=t,this.commandBuffer=new A_(t)}destroy(){}finish(){return this.commandBuffer}beginRenderPass(t){return new E_(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,n,r){}}function D_(i){const{target:e,source:t,start:n=0,count:r=1}=i,s=t.length,o=r*s;let a=0;for(let l=n;a<s;a++)e[l++]=t[a];for(;a<o;)a<o-a?(e.copyWithin(n+a,n,n+a),a*=2):(e.copyWithin(n+a,n,n+o-a),a=o);return i.target}class Bs extends Ts{constructor(t,n){super(t,n);g(this,"device");g(this,"handle");g(this,"buffer",null);g(this,"bufferValue",null);this.device=t,this.handle=this.device.gl.createVertexArray()}get[Symbol.toStringTag](){return"VertexArray"}static isConstantAttributeZeroSupported(t){return $p()==="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 n=t;if(n&&n.glTarget!==34963)throw new Error("Use .setBuffer()");this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34963,n?n.handle:null),this.indexBuffer=n,this.device.gl.bindVertexArray(null)}setBuffer(t,n){const r=n;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,n){this._enable(t,!1),this.attributes[t]=n}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 n=this.attributes[t];ArrayBuffer.isView(n)&&this.device.setConstantAttributeWebGL(t,n)}}_getAccessor(t){const n=this.attributeInfos[t];if(!n)throw new Error(`Unknown attribute location ${t}`);const r=Al(n.bufferDataType);return{size:n.bufferComponents,type:r,stride:n.byteStride,offset:n.byteOffset,normalized:n.normalized,integer:n.integer,divisor:n.stepMode==="instance"?1:0}}_enable(t,n=!0){const s=Bs.isConstantAttributeZeroSupported(this.device)||t!==0;(n||s)&&(t=Number(t),this.device.gl.bindVertexArray(this.handle),n?this.device.gl.enableVertexAttribArray(t):this.device.gl.disableVertexAttribArray(t),this.device.gl.bindVertexArray(null))}getConstantBuffer(t,n){const r=F_(n),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=!M_(r,this.bufferValue)),a){const l=jg(n.constructor,o);D_({target:l,source:r,start:0,count:o}),this.buffer.write(l),this.bufferValue=n}return this.buffer}}function F_(i){return Array.isArray(i)?new Float32Array(i):i}function M_(i,e){if(!i||!e||i.length!==e.length||i.constructor!==e.constructor)return!1;for(let t=0;t<i.length;++t)if(i[t]!==e[t])return!1;return!0}class N_ extends ws{constructor(t,n){super(t,n);g(this,"device");g(this,"gl");g(this,"handle");g(this,"layout");g(this,"buffers",{});g(this,"unusedBuffers",{});g(this,"bindOnUse",!0);g(this,"_bound",!1);this.device=t,this.gl=t.gl,this.handle=this.props.handle||this.gl.createTransformFeedback(),this.layout=this.props.layout,n.buffers&&this.setBuffers(n.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(S_(t))}end(){this.gl.endTransformFeedback(),this.bindOnUse&&this._unbindBuffers(),this.gl.bindTransformFeedback(36386,null)}setBuffers(t){this.buffers={},this.unusedBuffers={},this.bind(()=>{for(const n in t)this.setBuffer(n,t[n])})}setBuffer(t,n){const r=this._getVaryingIndex(t),{buffer:s,byteLength:o,byteOffset:a}=this._getBufferRange(n);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(Ul(t))return this.buffers[t]||null;const n=this._getVaryingIndex(t);return n>=0?this.buffers[n]:null}bind(t=this.handle){if(typeof t!="function")return this.gl.bindTransformFeedback(36386,t),this;let n;return this._bound?n=t():(this.gl.bindTransformFeedback(36386,this.handle),this._bound=!0,n=t(),this._bound=!1,this.gl.bindTransformFeedback(36386,null)),n}unbind(){this.bind(null)}_getBufferRange(t){if(t instanceof Vi)return{buffer:t,byteOffset:0,byteLength:t.byteLength};const{buffer:n,byteOffset:r=0,byteLength:s=t.buffer.byteLength}=t;return{buffer:n,byteOffset:r,byteLength:s}}_getVaryingIndex(t){if(Ul(t))return Number(t);for(const n of this.layout.varyings||[])if(t===n.name)return n.location;return-1}_bindBuffers(){for(const t in this.buffers){const{buffer:n,byteLength:r,byteOffset:s}=this._getBufferRange(this.buffers[t]);this._bindBuffer(Number(t),n,s,r)}}_unbindBuffers(){for(const t in this.buffers)this.gl.bindBufferBase(35982,Number(t),null)}_bindBuffer(t,n,r=0,s){const o=n&&n.handle;!o||s===void 0?this.gl.bindBufferBase(35982,t,o):this.gl.bindBufferRange(35982,t,o,r,s)}}function Ul(i){return typeof i=="number"?Number.isInteger(i):/^\d+$/.test(i)}class O_ extends As{constructor(t,n){super(t,n);g(this,"device");g(this,"handle");g(this,"target",null);g(this,"_queryPending",!1);g(this,"_pollingPromise",null);if(this.device=t,n.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 n=0;return this._pollingPromise=new Promise((r,s)=>{const o=()=>{this.isResultAvailable()?(r(this.getResult()),this._pollingPromise=null):n++>t?(s("Timed out"),this._pollingPromise=null):requestAnimationFrame(o)};requestAnimationFrame(o)}),this._pollingPromise}}function zl(i){switch(i){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 B_(i){switch(i){case 5121:return 1;case 33635:case 32819:case 32820:return 2;case 5126:return 4;default:return 0}}function U_(i){return z_[i]}const z_={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 L_(i,e){var M;const{sourceX:t=0,sourceY:n=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}=Ll(i),{gl:d,handle:_}=f;o||(o=f.width),a||(a=f.height);const P=(M=f.colorAttachments[r])==null?void 0:M.texture;if(!P)throw new Error(`Invalid framebuffer attachment ${r}`);l=(P==null?void 0:P.depth)||1,c||(c=(P==null?void 0:P.glFormat)||6408),u||(u=(P==null?void 0:P.glType)||5121),s=H_(s,u,c,o,a);const I=tl(s);u=u||c_(I);const w=d.bindFramebuffer(36160,_);return d.readBuffer(36064+r),d.readPixels(t,n,o,a,c,u,s),d.readBuffer(36064),d.bindFramebuffer(36160,w||null),h&&f.destroy(),s}function V_(i,e){const{target:t,sourceX:n=0,sourceY:r=0,sourceFormat:s=6408,targetByteOffset:o=0}=e||{};let{sourceWidth:a,sourceHeight:l,sourceType:c}=e||{};const{framebuffer:u,deleteFramebuffer:f}=Ll(i);a=a||u.width,l=l||u.height;const h=u;c=c||5121;let d=t;if(!d){const P=zl(s),I=B_(c),w=o+a*l*P*I;d=h.device.createBuffer({byteLength:w})}const _=i.device.createCommandEncoder();return _.copyTextureToBuffer({sourceTexture:i,width:a,height:l,origin:[n,r],destinationBuffer:d,byteOffset:o}),_.destroy(),f&&u.destroy(),d}function Ll(i){return i instanceof Un?{framebuffer:i,deleteFramebuffer:!1}:{framebuffer:W_(i),deleteFramebuffer:!0}}function W_(i,e){const{device:t,width:n,height:r,id:s}=i;return t.createFramebuffer({...e,id:`framebuffer-for-${s}`,width:n,height:r,colorAttachments:[i]})}function H_(i,e,t,n,r,s){if(i)return i;e||(e=5121);const o=U_(e),a=il(o),l=zl(t);return new a(n*r*l)}class $_ extends $t{constructor(t){var f,h;super({...t,id:t.id||Km("webgl-device")});g(this,"type","webgl");g(this,"handle");g(this,"features");g(this,"limits");g(this,"info");g(this,"canvasContext");g(this,"preferredColorFormat","rgba8unorm");g(this,"preferredDepthFormat","depth24plus");g(this,"commandEncoder");g(this,"lost");g(this,"_resolveContextLost");g(this,"gl");g(this,"_constants");g(this,"_extensions",{});g(this,"_polyfilled",!1);g(this,"spectorJS");const n=$t._getCanvasContextProps(t);if(!n)throw new Error("WebGLDevice requires props.createCanvasContext to be set");let r=(h=(f=n.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 jm(this,n),this.lost=new Promise(d=>{this._resolveContextLost=d});const s={...t.webgl};n.alphaMode==="premultiplied"&&(s.premultipliedAlpha=!0),t.powerPreference!==void 0&&(s.powerPreference=t.powerPreference);const a=this.props._handle||Im(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=cm({...this.props,gl:this.handle}),this.gl.device=this,this.gl._version=2,this.info=km(this.gl,this._extensions),this.limits=new Xm(this.gl),this.features=new $m(this.gl,this._extensions,this.props._disabledFeatures),this.props._initializeFeatures&&this.features.initializeFeatures(),new qt(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=hm(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 n=this._normalizeBufferProps(t);return new Vi(this,n)}createTexture(t){return new Hi(this,t)}createExternalTexture(t){throw new Error("createExternalTexture() not implemented")}createSampler(t){return new o_(this,t)}createShader(t){return new Gm(this,t)}createFramebuffer(t){return new Li(this,t)}createVertexArray(t){return new Bs(this,t)}createTransformFeedback(t){return new N_(this,t)}createQuerySet(t){return new O_(this,t)}createRenderPipeline(t){return new T_(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,n){return L_(t,n)}readPixelsToBufferWebGL(t,n){return V_(t,n)}setParametersWebGL(t){fi(this.gl,t)}getParametersWebGL(t){return bl(this.gl,t)}withParametersWebGL(t,n){return Wi(this.gl,t,n)}resetWebGL(){D.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")(),Tm(this.gl)}_getDeviceSpecificTextureFormatCapabilities(t){return Lm(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(){qt.get(this.gl).push()}popState(){qt.get(this.gl).pop()}getGLKey(t,n){const r=Number(t);for(const s in this.gl)if(this.gl[s]===r)return`GL.${s}`;return n!=null&&n.emptyIfUnknown?"":String(t)}getGLKeys(t){const n={emptyIfUnknown:!0};return Object.entries(t).reduce((r,[s,o])=>(r[`${s}:${this.getGLKey(s,n)}`]=`${o}:${this.getGLKey(o,n)}`,r),{})}setConstantAttributeWebGL(t,n){const r=this.limits.maxVertexAttributes;this._constants=this._constants||new Array(r).fill(null);const s=this._constants[t];switch(s&&j_(s,n)&&D.info(1,`setConstantAttributeWebGL(${t}) could have been skipped, value unchanged`)(),this._constants[t]=n,n.constructor){case Float32Array:X_(this,t,n);break;case Int32Array:Y_(this,t,n);break;case Uint32Array:q_(this,t,n);break;default:throw new Error("constant")}}getExtension(t){return hi(this.gl,t,this._extensions),this._extensions}_setWebGLDebugMetadata(t,n,r){t.luma=n;const s={props:r.spector,id:r.spector.id};t.__SPECTOR_Metadata=s}}function X_(i,e,t){switch(t.length){case 1:i.gl.vertexAttrib1fv(e,t);break;case 2:i.gl.vertexAttrib2fv(e,t);break;case 3:i.gl.vertexAttrib3fv(e,t);break;case 4:i.gl.vertexAttrib4fv(e,t);break}}function Y_(i,e,t){i.gl.vertexAttribI4iv(e,t)}function q_(i,e,t){i.gl.vertexAttribI4uiv(e,t)}function j_(i,e){if(!i||!e||i.length!==e.length||i.constructor!==e.constructor)return!1;for(let t=0;t<i.length;++t)if(i[t]!==e[t])return!1;return!0}const Vl=Object.freeze(Object.defineProperty({__proto__:null,WebGLDevice:$_},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:Wl,setPrototypeOf:Hl,isFrozen:K_,getPrototypeOf:Z_,getOwnPropertyDescriptor:Q_}=Object;let{freeze:Le,seal:et,create:$n}=Object,{apply:Us,construct:zs}=typeof Reflect<"u"&&Reflect;Le||(Le=function(e){return e}),et||(et=function(e){return e}),Us||(Us=function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),s=2;s<n;s++)r[s-2]=arguments[s];return e.apply(t,r)}),zs||(zs=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return new e(...n)});const Xn=We(Array.prototype.forEach),J_=We(Array.prototype.lastIndexOf),$l=We(Array.prototype.pop),$i=We(Array.prototype.push),G_=We(Array.prototype.splice),Yn=We(String.prototype.toLowerCase),Ls=We(String.prototype.toString),Vs=We(String.prototype.match),Xi=We(String.prototype.replace),ex=We(String.prototype.indexOf),tx=We(String.prototype.trim),Ze=We(Object.prototype.hasOwnProperty),Ve=We(RegExp.prototype.test),Yi=ix(TypeError);function We(i){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return Us(i,e,n)}}function ix(i){return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return zs(i,t)}}function te(i,e){let t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Yn;Hl&&Hl(i,null);let n=e.length;for(;n--;){let r=e[n];if(typeof r=="string"){const s=t(r);s!==r&&(K_(e)||(e[n]=s),r=s)}i[r]=!0}return i}function nx(i){for(let e=0;e<i.length;e++)Ze(i,e)||(i[e]=null);return i}function gt(i){const e=$n(null);for(const[t,n]of Wl(i))Ze(i,t)&&(Array.isArray(n)?e[t]=nx(n):n&&typeof n=="object"&&n.constructor===Object?e[t]=gt(n):e[t]=n);return e}function qi(i,e){for(;i!==null;){const n=Q_(i,e);if(n){if(n.get)return We(n.get);if(typeof n.value=="function")return We(n.value)}i=Z_(i)}function t(){return null}return t}const Xl=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"]),Ws=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"]),Hs=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"]),rx=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"]),$s=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"]),sx=Le(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Yl=Le(["#text"]),ql=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"]),Xs=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"]),jl=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"]),qn=Le(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),ox=et(/\{\{[\w\W]*|[\w\W]*\}\}/gm),ax=et(/<%[\w\W]*|[\w\W]*%>/gm),lx=et(/\$\{[\w\W]*/gm),cx=et(/^data-[\-\w.\u00B7-\uFFFF]+$/),ux=et(/^aria-[\-\w]+$/),Kl=et(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),fx=et(/^(?:\w+script|data):/i),hx=et(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Zl=et(/^html$/i),dx=et(/^[a-z][.\w]*(-[.\w]+)+$/i);var Ql=Object.freeze({__proto__:null,ARIA_ATTR:ux,ATTR_WHITESPACE:hx,CUSTOM_ELEMENT:dx,DATA_ATTR:cx,DOCTYPE_NAME:Zl,ERB_EXPR:ax,IS_ALLOWED_URI:Kl,IS_SCRIPT_OR_DATA:fx,MUSTACHE_EXPR:ox,TMPLIT_EXPR:lx});const ji={element:1,text:3,progressingInstruction:7,comment:8,document:9},px=function(){return typeof window>"u"?null:window},gx=function(e,t){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let n=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(n=t.getAttribute(r));const s="dompurify"+(n?"#"+n:"");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}},Jl=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Gl(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:px();const e=Y=>Gl(Y);if(e.version="3.3.3",e.removed=[],!i||!i.document||i.document.nodeType!==ji.document||!i.Element)return e.isSupported=!1,e;let{document:t}=i;const n=t,r=n.currentScript,{DocumentFragment:s,HTMLTemplateElement:o,Node:a,Element:l,NodeFilter:c,NamedNodeMap:u=i.NamedNodeMap||i.MozNamedAttrMap,HTMLFormElement:f,DOMParser:h,trustedTypes:d}=i,_=l.prototype,P=qi(_,"cloneNode"),I=qi(_,"remove"),w=qi(_,"nextSibling"),M=qi(_,"childNodes"),k=qi(_,"parentNode");if(typeof o=="function"){const Y=t.createElement("template");Y.content&&Y.content.ownerDocument&&(t=Y.content.ownerDocument)}let y,R="";const{implementation:B,createNodeIterator:U,createDocumentFragment:W,getElementsByTagName:q}=t,{importNode:Q}=n;let O=Jl();e.isSupported=typeof Wl=="function"&&typeof k=="function"&&B&&B.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:le,ERB_EXPR:ee,TMPLIT_EXPR:C,DATA_ATTR:L,ARIA_ATTR:F,IS_SCRIPT_OR_DATA:V,ATTR_WHITESPACE:Z,CUSTOM_ELEMENT:j}=Ql;let{IS_ALLOWED_URI:G}=Ql,J=null;const me=te({},[...Xl,...Ws,...Hs,...$s,...Yl]);let fe=null;const Te=te({},[...ql,...Xs,...jl,...qn]);let re=Object.seal($n(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}})),Xe=null,Be=null;const Ee=Object.seal($n(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let bi=!0,zo=!0,Vu=!1,Wu=!0,Si=!1,Vr=!0,ti=!1,Lo=!1,Vo=!1,Ti=!1,Wr=!1,Hr=!1,Hu=!0,$u=!1;const hb="user-content-";let Wo=!0,an=!1,wi={},vt=null;const Ho=te({},["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 Xu=null;const Yu=te({},["audio","video","img","source","image","track"]);let $o=null;const qu=te({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),$r="http://www.w3.org/1998/Math/MathML",Xr="http://www.w3.org/2000/svg",Rt="http://www.w3.org/1999/xhtml";let Ai=Rt,Xo=!1,Yo=null;const db=te({},[$r,Xr,Rt],Ls);let Yr=te({},["mi","mo","mn","ms","mtext"]),qr=te({},["annotation-xml"]);const pb=te({},["title","style","font","a","script"]);let ln=null;const gb=["application/xhtml+xml","text/html"],mb="text/html";let ke=null,Ci=null;const _b=t.createElement("form"),ju=function(x){return x instanceof RegExp||x instanceof Function},qo=function(){let x=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Ci&&Ci===x)){if((!x||typeof x!="object")&&(x={}),x=gt(x),ln=gb.indexOf(x.PARSER_MEDIA_TYPE)===-1?mb:x.PARSER_MEDIA_TYPE,ke=ln==="application/xhtml+xml"?Ls:Yn,J=Ze(x,"ALLOWED_TAGS")?te({},x.ALLOWED_TAGS,ke):me,fe=Ze(x,"ALLOWED_ATTR")?te({},x.ALLOWED_ATTR,ke):Te,Yo=Ze(x,"ALLOWED_NAMESPACES")?te({},x.ALLOWED_NAMESPACES,Ls):db,$o=Ze(x,"ADD_URI_SAFE_ATTR")?te(gt(qu),x.ADD_URI_SAFE_ATTR,ke):qu,Xu=Ze(x,"ADD_DATA_URI_TAGS")?te(gt(Yu),x.ADD_DATA_URI_TAGS,ke):Yu,vt=Ze(x,"FORBID_CONTENTS")?te({},x.FORBID_CONTENTS,ke):Ho,Xe=Ze(x,"FORBID_TAGS")?te({},x.FORBID_TAGS,ke):gt({}),Be=Ze(x,"FORBID_ATTR")?te({},x.FORBID_ATTR,ke):gt({}),wi=Ze(x,"USE_PROFILES")?x.USE_PROFILES:!1,bi=x.ALLOW_ARIA_ATTR!==!1,zo=x.ALLOW_DATA_ATTR!==!1,Vu=x.ALLOW_UNKNOWN_PROTOCOLS||!1,Wu=x.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Si=x.SAFE_FOR_TEMPLATES||!1,Vr=x.SAFE_FOR_XML!==!1,ti=x.WHOLE_DOCUMENT||!1,Ti=x.RETURN_DOM||!1,Wr=x.RETURN_DOM_FRAGMENT||!1,Hr=x.RETURN_TRUSTED_TYPE||!1,Vo=x.FORCE_BODY||!1,Hu=x.SANITIZE_DOM!==!1,$u=x.SANITIZE_NAMED_PROPS||!1,Wo=x.KEEP_CONTENT!==!1,an=x.IN_PLACE||!1,G=x.ALLOWED_URI_REGEXP||Kl,Ai=x.NAMESPACE||Rt,Yr=x.MATHML_TEXT_INTEGRATION_POINTS||Yr,qr=x.HTML_INTEGRATION_POINTS||qr,re=x.CUSTOM_ELEMENT_HANDLING||{},x.CUSTOM_ELEMENT_HANDLING&&ju(x.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(re.tagNameCheck=x.CUSTOM_ELEMENT_HANDLING.tagNameCheck),x.CUSTOM_ELEMENT_HANDLING&&ju(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),Si&&(zo=!1),Wr&&(Ti=!0),wi&&(J=te({},Yl),fe=$n(null),wi.html===!0&&(te(J,Xl),te(fe,ql)),wi.svg===!0&&(te(J,Ws),te(fe,Xs),te(fe,qn)),wi.svgFilters===!0&&(te(J,Hs),te(fe,Xs),te(fe,qn)),wi.mathMl===!0&&(te(J,$s),te(fe,jl),te(fe,qn))),Ze(x,"ADD_TAGS")||(Ee.tagCheck=null),Ze(x,"ADD_ATTR")||(Ee.attributeCheck=null),x.ADD_TAGS&&(typeof x.ADD_TAGS=="function"?Ee.tagCheck=x.ADD_TAGS:(J===me&&(J=gt(J)),te(J,x.ADD_TAGS,ke))),x.ADD_ATTR&&(typeof x.ADD_ATTR=="function"?Ee.attributeCheck=x.ADD_ATTR:(fe===Te&&(fe=gt(fe)),te(fe,x.ADD_ATTR,ke))),x.ADD_URI_SAFE_ATTR&&te($o,x.ADD_URI_SAFE_ATTR,ke),x.FORBID_CONTENTS&&(vt===Ho&&(vt=gt(vt)),te(vt,x.FORBID_CONTENTS,ke)),x.ADD_FORBID_CONTENTS&&(vt===Ho&&(vt=gt(vt)),te(vt,x.ADD_FORBID_CONTENTS,ke)),Wo&&(J["#text"]=!0),ti&&te(J,["html","head","body"]),J.table&&(te(J,["tbody"]),delete Xe.tbody),x.TRUSTED_TYPES_POLICY){if(typeof x.TRUSTED_TYPES_POLICY.createHTML!="function")throw Yi('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof x.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Yi('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');y=x.TRUSTED_TYPES_POLICY,R=y.createHTML("")}else y===void 0&&(y=gx(d,r)),y!==null&&typeof R=="string"&&(R=y.createHTML(""));Le&&Le(x),Ci=x}},Ku=te({},[...Ws,...Hs,...rx]),Zu=te({},[...$s,...sx]),xb=function(x){let N=k(x);(!N||!N.tagName)&&(N={namespaceURI:Ai,tagName:"template"});const $=Yn(x.tagName),_e=Yn(N.tagName);return Yo[x.namespaceURI]?x.namespaceURI===Xr?N.namespaceURI===Rt?$==="svg":N.namespaceURI===$r?$==="svg"&&(_e==="annotation-xml"||Yr[_e]):!!Ku[$]:x.namespaceURI===$r?N.namespaceURI===Rt?$==="math":N.namespaceURI===Xr?$==="math"&&qr[_e]:!!Zu[$]:x.namespaceURI===Rt?N.namespaceURI===Xr&&!qr[_e]||N.namespaceURI===$r&&!Yr[_e]?!1:!Zu[$]&&(pb[$]||!Ku[$]):!!(ln==="application/xhtml+xml"&&Yo[x.namespaceURI]):!1},bt=function(x){$i(e.removed,{element:x});try{k(x).removeChild(x)}catch{I(x)}},ii=function(x,N){try{$i(e.removed,{attribute:N.getAttributeNode(x),from:N})}catch{$i(e.removed,{attribute:null,from:N})}if(N.removeAttribute(x),x==="is")if(Ti||Wr)try{bt(N)}catch{}else try{N.setAttribute(x,"")}catch{}},Qu=function(x){let N=null,$=null;if(Vo)x="<remove></remove>"+x;else{const we=Vs(x,/^[\r\n\t ]+/);$=we&&we[0]}ln==="application/xhtml+xml"&&Ai===Rt&&(x='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+x+"</body></html>");const _e=y?y.createHTML(x):x;if(Ai===Rt)try{N=new h().parseFromString(_e,ln)}catch{}if(!N||!N.documentElement){N=B.createDocument(Ai,"template",null);try{N.documentElement.innerHTML=Xo?R:_e}catch{}}const Ue=N.body||N.documentElement;return x&&$&&Ue.insertBefore(t.createTextNode($),Ue.childNodes[0]||null),Ai===Rt?q.call(N,ti?"html":"body")[0]:ti?N.documentElement:Ue},Ju=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)},jo=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")},Gu=function(x){return typeof a=="function"&&x instanceof a};function Et(Y,x,N){Xn(Y,$=>{$.call(e,x,N,Ci)})}const ef=function(x){let N=null;if(Et(O.beforeSanitizeElements,x,null),jo(x))return bt(x),!0;const $=ke(x.nodeName);if(Et(O.uponSanitizeElement,x,{tagName:$,allowedTags:J}),Vr&&x.hasChildNodes()&&!Gu(x.firstElementChild)&&Ve(/<[/\w!]/g,x.innerHTML)&&Ve(/<[/\w!]/g,x.textContent)||x.nodeType===ji.progressingInstruction||Vr&&x.nodeType===ji.comment&&Ve(/<[/\w]/g,x.data))return bt(x),!0;if(!(Ee.tagCheck instanceof Function&&Ee.tagCheck($))&&(!J[$]||Xe[$])){if(!Xe[$]&&nf($)&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,$)||re.tagNameCheck instanceof Function&&re.tagNameCheck($)))return!1;if(Wo&&!vt[$]){const _e=k(x)||x.parentNode,Ue=M(x)||x.childNodes;if(Ue&&_e){const we=Ue.length;for(let qe=we-1;qe>=0;--qe){const Dt=P(Ue[qe],!0);Dt.__removalCount=(x.__removalCount||0)+1,_e.insertBefore(Dt,w(x))}}}return bt(x),!0}return x instanceof l&&!xb(x)||($==="noscript"||$==="noembed"||$==="noframes")&&Ve(/<\/no(script|embed|frames)/i,x.innerHTML)?(bt(x),!0):(Si&&x.nodeType===ji.text&&(N=x.textContent,Xn([le,ee,C],_e=>{N=Xi(N,_e," ")}),x.textContent!==N&&($i(e.removed,{element:x.cloneNode()}),x.textContent=N)),Et(O.afterSanitizeElements,x,null),!1)},tf=function(x,N,$){if(Be[N]||Hu&&(N==="id"||N==="name")&&($ in t||$ in _b))return!1;if(!(zo&&!Be[N]&&Ve(L,N))){if(!(bi&&Ve(F,N))){if(!(Ee.attributeCheck instanceof Function&&Ee.attributeCheck(N,x))){if(!fe[N]||Be[N]){if(!(nf(x)&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,x)||re.tagNameCheck instanceof Function&&re.tagNameCheck(x))&&(re.attributeNameCheck instanceof RegExp&&Ve(re.attributeNameCheck,N)||re.attributeNameCheck instanceof Function&&re.attributeNameCheck(N,x))||N==="is"&&re.allowCustomizedBuiltInElements&&(re.tagNameCheck instanceof RegExp&&Ve(re.tagNameCheck,$)||re.tagNameCheck instanceof Function&&re.tagNameCheck($))))return!1}else if(!$o[N]){if(!Ve(G,Xi($,Z,""))){if(!((N==="src"||N==="xlink:href"||N==="href")&&x!=="script"&&ex($,"data:")===0&&Xu[x])){if(!(Vu&&!Ve(V,Xi($,Z,"")))){if($)return!1}}}}}}}return!0},nf=function(x){return x!=="annotation-xml"&&Vs(x,j)},rf=function(x){Et(O.beforeSanitizeAttributes,x,null);const{attributes:N}=x;if(!N||jo(x))return;const $={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:fe,forceKeepAttr:void 0};let _e=N.length;for(;_e--;){const Ue=N[_e],{name:we,namespaceURI:qe,value:Dt}=Ue,Pi=ke(we),Ko=Dt;let Fe=we==="value"?Ko:tx(Ko);if($.attrName=Pi,$.attrValue=Fe,$.keepAttr=!0,$.forceKeepAttr=void 0,Et(O.uponSanitizeAttribute,x,$),Fe=$.attrValue,$u&&(Pi==="id"||Pi==="name")&&(ii(we,x),Fe=hb+Fe),Vr&&Ve(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Fe)){ii(we,x);continue}if(Pi==="attributename"&&Vs(Fe,"href")){ii(we,x);continue}if($.forceKeepAttr)continue;if(!$.keepAttr){ii(we,x);continue}if(!Wu&&Ve(/\/>/i,Fe)){ii(we,x);continue}Si&&Xn([le,ee,C],of=>{Fe=Xi(Fe,of," ")});const sf=ke(x.nodeName);if(!tf(sf,Pi,Fe)){ii(we,x);continue}if(y&&typeof d=="object"&&typeof d.getAttributeType=="function"&&!qe)switch(d.getAttributeType(sf,Pi)){case"TrustedHTML":{Fe=y.createHTML(Fe);break}case"TrustedScriptURL":{Fe=y.createScriptURL(Fe);break}}if(Fe!==Ko)try{qe?x.setAttributeNS(qe,we,Fe):x.setAttribute(we,Fe),jo(x)?bt(x):$l(e.removed)}catch{ii(we,x)}}Et(O.afterSanitizeAttributes,x,null)},yb=function Y(x){let N=null;const $=Ju(x);for(Et(O.beforeSanitizeShadowDOM,x,null);N=$.nextNode();)Et(O.uponSanitizeShadowNode,N,null),ef(N),rf(N),N.content instanceof s&&Y(N.content);Et(O.afterSanitizeShadowDOM,x,null)};return e.sanitize=function(Y){let x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},N=null,$=null,_e=null,Ue=null;if(Xo=!Y,Xo&&(Y="<!-->"),typeof Y!="string"&&!Gu(Y))if(typeof Y.toString=="function"){if(Y=Y.toString(),typeof Y!="string")throw Yi("dirty is not a string, aborting")}else throw Yi("toString is not a function");if(!e.isSupported)return Y;if(Lo||qo(x),e.removed=[],typeof Y=="string"&&(an=!1),an){if(Y.nodeName){const Dt=ke(Y.nodeName);if(!J[Dt]||Xe[Dt])throw Yi("root node is forbidden and cannot be sanitized in-place")}}else if(Y instanceof a)N=Qu("<!---->"),$=N.ownerDocument.importNode(Y,!0),$.nodeType===ji.element&&$.nodeName==="BODY"||$.nodeName==="HTML"?N=$:N.appendChild($);else{if(!Ti&&!Si&&!ti&&Y.indexOf("<")===-1)return y&&Hr?y.createHTML(Y):Y;if(N=Qu(Y),!N)return Ti?null:Hr?R:""}N&&Vo&&bt(N.firstChild);const we=Ju(an?Y:N);for(;_e=we.nextNode();)ef(_e),rf(_e),_e.content instanceof s&&yb(_e.content);if(an)return Y;if(Ti){if(Wr)for(Ue=W.call(N.ownerDocument);N.firstChild;)Ue.appendChild(N.firstChild);else Ue=N;return(fe.shadowroot||fe.shadowrootmode)&&(Ue=Q.call(n,Ue,!0)),Ue}let qe=ti?N.outerHTML:N.innerHTML;return ti&&J["!doctype"]&&N.ownerDocument&&N.ownerDocument.doctype&&N.ownerDocument.doctype.name&&Ve(Zl,N.ownerDocument.doctype.name)&&(qe="<!DOCTYPE "+N.ownerDocument.doctype.name+`>
13
+ `+qe),Si&&Xn([le,ee,C],Dt=>{qe=Xi(qe,Dt," ")}),y&&Hr?y.createHTML(qe):qe},e.setConfig=function(){let Y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};qo(Y),Lo=!0},e.clearConfig=function(){Ci=null,Lo=!1},e.isValidAttribute=function(Y,x,N){Ci||qo({});const $=ke(Y),_e=ke(x);return tf($,_e,N)},e.addHook=function(Y,x){typeof x=="function"&&$i(O[Y],x)},e.removeHook=function(Y,x){if(x!==void 0){const N=J_(O[Y],x);return N===-1?void 0:G_(O[Y],N,1)[0]}return $l(O[Y])},e.removeHooks=function(Y){O[Y]=[]},e.removeAllHooks=function(){O=Jl()},e}var mx=Gl();function jn(i,e){return i==null||e==null?NaN:i<e?-1:i>e?1:i>=e?0:NaN}function _x(i,e){return i==null||e==null?NaN:e<i?-1:e>i?1:e>=i?0:NaN}function ec(i){let e,t,n;i.length!==2?(e=jn,t=(a,l)=>jn(i(a),l),n=(a,l)=>i(a)-l):(e=i===jn||i===_x?i:xx,t=i,n=i);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&&n(a[f-1],l)>-n(a[f],l)?f-1:f}return{left:r,center:o,right:s}}function xx(){return 0}function yx(i){return i===null?NaN:+i}const vx=ec(jn).right;ec(yx).center;var Ys=Math.sqrt(50),qs=Math.sqrt(10),js=Math.sqrt(2);function bx(i,e,t){var n,r=-1,s,o,a;if(e=+e,i=+i,t=+t,i===e&&t>0)return[i];if((n=e<i)&&(s=i,i=e,e=s),(a=tc(i,e,t))===0||!isFinite(a))return[];if(a>0){let l=Math.round(i/a),c=Math.round(e/a);for(l*a<i&&++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(i*a),c=Math.round(e*a);for(l/a<i&&++l,c/a>e&&--c,o=new Array(s=c-l+1);++r<s;)o[r]=(l+r)/a}return n&&o.reverse(),o}function tc(i,e,t){var n=(e-i)/Math.max(0,t),r=Math.floor(Math.log(n)/Math.LN10),s=n/Math.pow(10,r);return r>=0?(s>=Ys?10:s>=qs?5:s>=js?2:1)*Math.pow(10,r):-Math.pow(10,-r)/(s>=Ys?10:s>=qs?5:s>=js?2:1)}function Sx(i,e,t){var n=Math.abs(e-i)/Math.max(0,t),r=Math.pow(10,Math.floor(Math.log(n)/Math.LN10)),s=n/r;return s>=Ys?r*=10:s>=qs?r*=5:s>=js&&(r*=2),e<i?-r:r}function Tx(i,e,t){i=+i,e=+e,t=(r=arguments.length)<2?(e=i,i=0,1):r<3?1:+t;for(var n=-1,r=Math.max(0,Math.ceil((e-i)/t))|0,s=new Array(r);++n<r;)s[n]=i+n*t;return s}function ic(i,e){switch(arguments.length){case 0:break;case 1:this.range(i);break;default:this.range(e).domain(i);break}return this}function wx(i){return function(){return i}}function Ax(i){return+i}var nc=[0,1];function mt(i){return i}function Ks(i,e){return(e-=i=+i)?function(t){return(t-i)/e}:wx(isNaN(e)?NaN:.5)}function Cx(i,e){var t;return i>e&&(t=i,i=e,e=t),function(n){return Math.max(i,Math.min(e,n))}}function Px(i,e,t){var n=i[0],r=i[1],s=e[0],o=e[1];return r<n?(n=Ks(r,n),s=t(o,s)):(n=Ks(n,r),s=t(s,o)),function(a){return s(n(a))}}function Ix(i,e,t){var n=Math.min(i.length,e.length)-1,r=new Array(n),s=new Array(n),o=-1;for(i[n]<i[0]&&(i=i.slice().reverse(),e=e.slice().reverse());++o<n;)r[o]=Ks(i[o],i[o+1]),s[o]=t(e[o],e[o+1]);return function(a){var l=vx(i,a,1,n)-1;return s[l](r[l](a))}}function rc(i,e){return e.domain(i.domain()).range(i.range()).interpolate(i.interpolate()).clamp(i.clamp()).unknown(i.unknown())}function sc(){var i=nc,e=nc,t=as,n,r,s,o=mt,a,l,c;function u(){var h=Math.min(i.length,e.length);return o!==mt&&(o=Cx(i[0],i[h-1])),a=h>2?Ix:Px,l=c=null,f}function f(h){return h==null||isNaN(h=+h)?s:(l||(l=a(i.map(n),e,t)))(n(o(h)))}return f.invert=function(h){return o(r((c||(c=a(e,i.map(n),ot)))(h)))},f.domain=function(h){return arguments.length?(i=Array.from(h,Ax),u()):i.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=yd,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 n=h,r=d,u()}}function kx(){return sc()(mt,mt)}function Rx(i){return Math.abs(i=Math.round(i))>=1e21?i.toLocaleString("en").replace(/,/g,""):i.toString(10)}function Kn(i,e){if((t=(i=e?i.toExponential(e-1):i.toExponential()).indexOf("e"))<0)return null;var t,n=i.slice(0,t);return[n.length>1?n[0]+n.slice(2):n,+i.slice(t+1)]}function mi(i){return i=Kn(Math.abs(i)),i?i[1]:NaN}function Ex(i,e){return function(t,n){for(var r=t.length,s=[],o=0,a=i[0],l=0;r>0&&a>0&&(l+a+1>n&&(a=Math.max(1,n-l)),s.push(t.substring(r-=a,r+a)),!((l+=a+1)>n));)a=i[o=(o+1)%i.length];return s.reverse().join(e)}}function Dx(i){return function(e){return e.replace(/[0-9]/g,function(t){return i[+t]})}}var Fx=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Zn(i){if(!(e=Fx.exec(i)))throw new Error("invalid format: "+i);var e;return new Zs({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]})}Zn.prototype=Zs.prototype;function Zs(i){this.fill=i.fill===void 0?" ":i.fill+"",this.align=i.align===void 0?">":i.align+"",this.sign=i.sign===void 0?"-":i.sign+"",this.symbol=i.symbol===void 0?"":i.symbol+"",this.zero=!!i.zero,this.width=i.width===void 0?void 0:+i.width,this.comma=!!i.comma,this.precision=i.precision===void 0?void 0:+i.precision,this.trim=!!i.trim,this.type=i.type===void 0?"":i.type+""}Zs.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 Mx(i){e:for(var e=i.length,t=1,n=-1,r;t<e;++t)switch(i[t]){case".":n=r=t;break;case"0":n===0&&(n=t),r=t;break;default:if(!+i[t])break e;n>0&&(n=0);break}return n>0?i.slice(0,n)+i.slice(r+1):i}var oc;function Nx(i,e){var t=Kn(i,e);if(!t)return i+"";var n=t[0],r=t[1],s=r-(oc=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,o=n.length;return s===o?n:s>o?n+new Array(s-o+1).join("0"):s>0?n.slice(0,s)+"."+n.slice(s):"0."+new Array(1-s).join("0")+Kn(i,Math.max(0,e+s-1))[0]}function ac(i,e){var t=Kn(i,e);if(!t)return i+"";var n=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+n:n.length>r+1?n.slice(0,r+1)+"."+n.slice(r+1):n+new Array(r-n.length+2).join("0")}const lc={"%":(i,e)=>(i*100).toFixed(e),b:i=>Math.round(i).toString(2),c:i=>i+"",d:Rx,e:(i,e)=>i.toExponential(e),f:(i,e)=>i.toFixed(e),g:(i,e)=>i.toPrecision(e),o:i=>Math.round(i).toString(8),p:(i,e)=>ac(i*100,e),r:ac,s:Nx,X:i=>Math.round(i).toString(16).toUpperCase(),x:i=>Math.round(i).toString(16)};function cc(i){return i}var uc=Array.prototype.map,fc=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Ox(i){var e=i.grouping===void 0||i.thousands===void 0?cc:Ex(uc.call(i.grouping,Number),i.thousands+""),t=i.currency===void 0?"":i.currency[0]+"",n=i.currency===void 0?"":i.currency[1]+"",r=i.decimal===void 0?".":i.decimal+"",s=i.numerals===void 0?cc:Dx(uc.call(i.numerals,String)),o=i.percent===void 0?"%":i.percent+"",a=i.minus===void 0?"−":i.minus+"",l=i.nan===void 0?"NaN":i.nan+"";function c(f){f=Zn(f);var h=f.fill,d=f.align,_=f.sign,P=f.symbol,I=f.zero,w=f.width,M=f.comma,k=f.precision,y=f.trim,R=f.type;R==="n"?(M=!0,R="g"):lc[R]||(k===void 0&&(k=12),y=!0,R="g"),(I||h==="0"&&d==="=")&&(I=!0,h="0",d="=");var B=P==="$"?t:P==="#"&&/[boxX]/.test(R)?"0"+R.toLowerCase():"",U=P==="$"?n:/[%p]/.test(R)?o:"",W=lc[R],q=/[defgprs%]/.test(R);k=k===void 0?6:/[gprs]/.test(R)?Math.max(1,Math.min(21,k)):Math.max(0,Math.min(20,k));function Q(O){var le=B,ee=U,C,L,F;if(R==="c")ee=W(O)+ee,O="";else{O=+O;var V=O<0||1/O<0;if(O=isNaN(O)?l:W(Math.abs(O),k),y&&(O=Mx(O)),V&&+O==0&&_!=="+"&&(V=!1),le=(V?_==="("?_:a:_==="-"||_==="("?"":_)+le,ee=(R==="s"?fc[8+oc/3]:"")+ee+(V&&_==="("?")":""),q){for(C=-1,L=O.length;++C<L;)if(F=O.charCodeAt(C),48>F||F>57){ee=(F===46?r+O.slice(C+1):O.slice(C))+ee,O=O.slice(0,C);break}}}M&&!I&&(O=e(O,1/0));var Z=le.length+O.length+ee.length,j=Z<w?new Array(w-Z+1).join(h):"";switch(M&&I&&(O=e(j+O,j.length?w-ee.length:1/0),j=""),d){case"<":O=le+O+ee+j;break;case"=":O=le+j+O+ee;break;case"^":O=j.slice(0,Z=j.length>>1)+le+O+ee+j.slice(Z);break;default:O=j+le+O+ee;break}return s(O)}return Q.toString=function(){return f+""},Q}function u(f,h){var d=c((f=Zn(f),f.type="f",f)),_=Math.max(-8,Math.min(8,Math.floor(mi(h)/3)))*3,P=Math.pow(10,-_),I=fc[8+_/3];return function(w){return d(P*w)+I}}return{format:c,formatPrefix:u}}var Qn,hc,dc;Bx({thousands:",",grouping:[3],currency:["$",""]});function Bx(i){return Qn=Ox(i),hc=Qn.format,dc=Qn.formatPrefix,Qn}function Ux(i){return Math.max(0,-mi(Math.abs(i)))}function zx(i,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(mi(e)/3)))*3-mi(Math.abs(i)))}function Lx(i,e){return i=Math.abs(i),e=Math.abs(e)-i,Math.max(0,mi(e)-mi(i))+1}function Vx(i,e,t,n){var r=Sx(i,e,t),s;switch(n=Zn(n??",f"),n.type){case"s":{var o=Math.max(Math.abs(i),Math.abs(e));return n.precision==null&&!isNaN(s=zx(r,o))&&(n.precision=s),dc(n,o)}case"":case"e":case"g":case"p":case"r":{n.precision==null&&!isNaN(s=Lx(r,Math.max(Math.abs(i),Math.abs(e))))&&(n.precision=s-(n.type==="e"));break}case"f":case"%":{n.precision==null&&!isNaN(s=Ux(r))&&(n.precision=s-(n.type==="%")*2);break}}return hc(n)}function pc(i){var e=i.domain;return i.ticks=function(t){var n=e();return bx(n[0],n[n.length-1],t??10)},i.tickFormat=function(t,n){var r=e();return Vx(r[0],r[r.length-1],t??10,n)},i.nice=function(t){t==null&&(t=10);var n=e(),r=0,s=n.length-1,o=n[r],a=n[s],l,c,u=10;for(a<o&&(c=o,o=a,a=c,c=r,r=s,s=c);u-- >0;){if(c=tc(o,a,t),c===l)return n[r]=o,n[s]=a,e(n);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 i},i}function Qs(){var i=kx();return i.copy=function(){return rc(i,Qs())},ic.apply(i,arguments),pc(i)}function gc(i){return function(e){return e<0?-Math.pow(-e,i):Math.pow(e,i)}}function Wx(i){return i<0?-Math.sqrt(-i):Math.sqrt(i)}function Hx(i){return i<0?-i*i:i*i}function $x(i){var e=i(mt,mt),t=1;function n(){return t===1?i(mt,mt):t===.5?i(Wx,Hx):i(gc(t),gc(1/t))}return e.exponent=function(r){return arguments.length?(t=+r,n()):t},pc(e)}function mc(){var i=$x(sc());return i.copy=function(){return rc(i,mc()).exponent(i.exponent())},ic.apply(i,arguments),i}var _c=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var i=0,e=arguments.length;e--;)i+=arguments[e]*arguments[e];return Math.sqrt(i)});function Xx(){var i=new _c(9);return _c!=Float32Array&&(i[1]=0,i[2]=0,i[3]=0,i[5]=0,i[6]=0,i[7]=0),i[0]=1,i[4]=1,i[8]=1,i}function xc(i,e,t){var n=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 i[0]=n,i[1]=r,i[2]=s,i[3]=o,i[4]=a,i[5]=l,i[6]=h*n+d*o+c,i[7]=h*r+d*a+u,i[8]=h*s+d*l+f,i}function Js(i,e,t){var n=t[0],r=t[1];return i[0]=n*e[0],i[1]=n*e[1],i[2]=n*e[2],i[3]=r*e[3],i[4]=r*e[4],i[5]=r*e[5],i[6]=e[6],i[7]=e[7],i[8]=e[8],i}function Yx(i,e,t){return i[0]=2/e,i[1]=0,i[2]=0,i[3]=0,i[4]=-2/t,i[5]=0,i[6]=-1,i[7]=1,i[8]=1,i}function qx(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}function jx(i){if(Object.prototype.hasOwnProperty.call(i,"__esModule"))return i;var e=i.default;if(typeof e=="function"){var t=function n(){return this instanceof n?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(i).forEach(function(n){var r=Object.getOwnPropertyDescriptor(i,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return i[n]}})}),t}var Jn={exports:{}},Kx=Jn.exports,yc;function Zx(){return yc||(yc=1,function(i){(function(e,t,n){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})(Kx,i)}(Jn)),Jn.exports}var Gn={exports:{}},Qx=Gn.exports,vc;function Jx(){return vc||(vc=1,function(i){(function(e,t,n){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})(Qx,i)}(Gn)),Gn.exports}var er={exports:{}},Gx=er.exports,bc;function ey(){return bc||(bc=1,function(i){(function(e,t,n){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})(Gx,i)}(er)),er.exports}var tr={exports:{}},ty=tr.exports,Sc;function iy(){return Sc||(Sc=1,function(i){(function(e,t,n){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})(ty,i)}(tr)),tr.exports}var ir={exports:{}},ny=ir.exports,Tc;function ry(){return Tc||(Tc=1,function(i){(function(e,t,n){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,_,P,I,w=[],M=128;for(f===(f|0)?(d=f,f=null):(f=f+"\0",d=0,M=Math.max(M,f.length)),_=0,P=-32;P<M;++P)f&&(d^=f.charCodeAt((P+32)%f.length)),P===0&&(I=d),d^=d<<10,d^=d>>>15,d^=d<<4,d^=d>>>13,P>=0&&(I=I+1640531527|0,h=w[P&127]^=d+I,_=h==0?_+1:0);for(_>=128&&(w[(f&&f.length||0)&127]=-1),_=127,P=4*128;P>0;--P)d=w[_+34&127],h=w[_=_+1&127],d^=d<<13,h^=h<<17,d^=d>>>15,h^=h>>>12,w[_]=d^h;u.w=I,u.X=w,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})(ny,i)}(ir)),ir.exports}var nr={exports:{}},sy=nr.exports,wc;function oy(){return wc||(wc=1,function(i){(function(e,t,n){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})(sy,i)}(nr)),nr.exports}var rr={exports:{}};const ay=jx(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var ly=rr.exports,Ac;function cy(){return Ac||(Ac=1,function(i){(function(e,t,n){var r=256,s=6,o=52,a="random",l=n.pow(r,s),c=n.pow(2,o),u=c*2,f=r-1,h;function d(y,R,B){var U=[];R=R==!0?{entropy:!0}:R||{};var W=w(I(R.entropy?[y,k(t)]:y??M(),3),U),q=new _(U),Q=function(){for(var O=q.g(s),le=l,ee=0;O<c;)O=(O+ee)*r,le*=r,ee=q.g(1);for(;O>=u;)O/=2,le/=2,ee>>>=1;return(O+ee)/le};return Q.int32=function(){return q.g(4)|0},Q.quick=function(){return q.g(4)/4294967296},Q.double=Q,w(k(q.S),t),(R.pass||B||function(O,le,ee,C){return C&&(C.S&&P(C,q),O.state=function(){return P(q,{})}),ee?(n[a]=O,le):O})(Q,W,"global"in R?R.global:this==n,R.state)}function _(y){var R,B=y.length,U=this,W=0,q=U.i=U.j=0,Q=U.S=[];for(B||(y=[B++]);W<r;)Q[W]=W++;for(W=0;W<r;W++)Q[W]=Q[q=f&q+y[W%B]+(R=Q[W])],Q[q]=R;(U.g=function(O){for(var le,ee=0,C=U.i,L=U.j,F=U.S;O--;)le=F[C=f&C+1],ee=ee*r+F[f&(F[C]=F[L=f&L+le])+(F[L]=le)];return U.i=C,U.j=L,ee})(r)}function P(y,R){return R.i=y.i,R.j=y.j,R.S=y.S.slice(),R}function I(y,R){var B=[],U=typeof y,W;if(R&&U=="object")for(W in y)try{B.push(I(y[W],R-1))}catch{}return B.length?B:U=="string"?y:y+"\0"}function w(y,R){for(var B=y+"",U,W=0;W<B.length;)R[f&W]=f&(U^=R[f&W]*19)+B.charCodeAt(W++);return k(R)}function M(){try{var y;return h&&(y=h.randomBytes)?y=y(r):(y=new Uint8Array(r),(e.crypto||e.msCrypto).getRandomValues(y)),k(y)}catch{var R=e.navigator,B=R&&R.plugins;return[+new Date,e,B,e.screen,k(t)]}}function k(y){return String.fromCharCode.apply(0,y)}if(w(n.random(),t),i.exports){i.exports=d;try{h=ay}catch{}}else n["seed"+a]=d})(typeof self<"u"?self:ly,[],Math)}(rr)),rr.exports}var Gs,Cc;function uy(){if(Cc)return Gs;Cc=1;var i=Zx(),e=Jx(),t=ey(),n=iy(),r=ry(),s=oy(),o=cy();return o.alea=i,o.xor128=e,o.xorwow=t,o.xorshift7=n,o.xor4096=r,o.tychei=s,Gs=o,Gs}var fy=uy();const hy=qx(fy);function dy(i,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(i,gy(n.key),n)}}function eo(i,e,t){return e&&dy(i.prototype,e),Object.defineProperty(i,"prototype",{writable:!1}),i}function Pc(i,e){i.prototype=Object.create(e.prototype),i.prototype.constructor=i,to(i,e)}function to(i,e){return to=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},to(i,e)}function py(i,e){if(typeof i!="object"||i===null)return i;var t=i[Symbol.toPrimitive];if(t!==void 0){var n=t.call(i,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(i)}function gy(i){var e=py(i,"string");return typeof e=="symbol"?e:String(e)}var sr=function(){function i(){}var e=i.prototype;return e._seed=function(n,r){if(n===(n||0))return n;for(var s=""+n,o=0,a=0;a<s.length;++a)o^=s.charCodeAt(a)|0;return o},i}(),Ic=function(i){Pc(e,i);function e(n,r){var s;return s=i.call(this)||this,s._rng=void 0,s.seed(n,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)},eo(e,[{key:"name",get:function(){return"function"}}]),e}(sr),kc=function(){var i=[].slice.call(arguments),e=i,t=e[0],n=t===void 0?"default":t;switch(typeof n){case"object":if(n instanceof sr)return n;break;case"function":return new Ic(n);case"number":case"string":default:return new Ic(hy.apply(void 0,i))}throw new Error('invalid RNG "'+n+'"')},my=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){return i.next()*(t-e)+e}};function at(i){return new _y(i)}var _y=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(n){if(t.n<n)return t;throw new Error("Expected number to be less than "+n+", got "+t.n)},this.greaterThanOrEqual=function(n){if(t.n>=n)return t;throw new Error("Expected number to be greater than or equal to "+n+", got "+t.n)},this.greaterThan=function(n){if(t.n>n)return t;throw new Error("Expected number to be greater than "+n+", got "+t.n)},this.n=e},xy=function(i,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(i.next()*(t-e+1)+e)}},yy=function(i){return function(){return i.next()>=.5}},vy=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),function(){var n,r,s;do n=i.next()*2-1,r=i.next()*2-1,s=n*n+r*r;while(!s||s>1);return e+t*r*Math.sqrt(-2*Math.log(s)/s)}},by=function(i,e,t){e===void 0&&(e=0),t===void 0&&(t=1);var n=i.normal(e,t);return function(){return Math.exp(n())}},Sy=function(i,e){return e===void 0&&(e=.5),at(e).greaterThanOrEqual(0).lessThan(1),function(){return Math.floor(i.next()+e)}},Ty=function(i,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 n=0,r=0;n++<e;)i.next()<t&&r++;return r}},wy=function(i,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(i.next())*t)}},Ay=[0,0,.6931471805599453,1.791759469228055,3.1780538303479458,4.787491742782046,6.579251212010101,8.525161361065415,10.60460290274525,12.801827480081469],Cy=function(e){return Ay[e]},Py=.9189385332046727,Iy=function(i,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=i.next();u>l;)u=u-l,l=e*l/++c;return c}}else{var n=Math.sqrt(e),r=.931+2.53*n,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=i.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=i.next()-.5:(l=c/a-.93,l=(l<0?-.5:.5)-l,c=i.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-Py+f-(.08333333333333333-(.002777777777777778-1/(1260*f*f))/(f*f))/f;if(Math.log(c*n)<=h)return f}else if(f>=0){var d,_=(d=Cy(f))!=null?d:0;if(Math.log(c)<=f*Math.log(e)-e-_)return f}}}}}},ky=function(i,e){return e===void 0&&(e=1),at(e).isPositive(),function(){return-Math.log(1-i.next())/e}},Ry=function(i,e){return e===void 0&&(e=1),at(e).isInt().greaterThanOrEqual(0),function(){for(var t=0,n=0;n<e;++n)t+=i.next();return t}},Ey=function(i,e){e===void 0&&(e=1),at(e).isInt().isPositive();var t=i.irwinHall(e);return function(){return t()/e}},Dy=function(i,e){e===void 0&&(e=1),at(e).greaterThanOrEqual(0);var t=1/e;return function(){return 1/Math.pow(1-i.next(),t)}},Fy=function(i){Pc(e,i);function e(){return i.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},eo(e,[{key:"name",get:function(){return"default"}}]),e}(sr),Rc=function(){function i(t){var n=this;this._rng=void 0,this._patch=void 0,this._cache={},this.next=function(){return n._rng.next()},this.float=function(r,s){return n.uniform(r,s)()},this.int=function(r,s){return n.uniformInt(r,s)()},this.integer=function(r,s){return n.uniformInt(r,s)()},this.bool=function(){return n.uniformBoolean()()},this.boolean=function(){return n.uniformBoolean()()},this.uniform=function(r,s){return n._memoize("uniform",my,r,s)},this.uniformInt=function(r,s){return n._memoize("uniformInt",xy,r,s)},this.uniformBoolean=function(){return n._memoize("uniformBoolean",yy)},this.normal=function(r,s){return vy(n,r,s)},this.logNormal=function(r,s){return by(n,r,s)},this.bernoulli=function(r){return Sy(n,r)},this.binomial=function(r,s){return Ty(n,r,s)},this.geometric=function(r){return wy(n,r)},this.poisson=function(r){return Iy(n,r)},this.exponential=function(r){return ky(n,r)},this.irwinHall=function(r){return Ry(n,r)},this.bates=function(r){return Ey(n,r)},this.pareto=function(r){return Dy(n,r)},t&&t instanceof sr?this.use(t):this.use(new Fy),this._cache={}}var e=i.prototype;return e.clone=function(){var n=[].slice.call(arguments);return n.length?new i(kc.apply(void 0,n)):new i(this.rng.clone())},e.use=function(){this._rng=kc.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(n){if(!Array.isArray(n))throw new Error("Random.choice expected input to be an array, got "+typeof n);var r=n==null?void 0:n.length;if(r>0){var s=this.uniformInt(0,r-1)();return n[s]}else return},e._memoize=function(n,r){var s=[].slice.call(arguments,2),o=""+s.join(";"),a=this._cache[n];return(a===void 0||a.key!==o)&&(a={key:o,distribution:r.apply(void 0,[this].concat(s))},this._cache[n]=a),a.distribution},eo(i,[{key:"rng",get:function(){return this._rng}}]),i}();new Rc;const io=.001,or=64,My=4,Ec=2;class Ny{constructor(){this.pointsTextureSize=0,this.linksTextureSize=0,this.alpha=1,this.transform=Xx(),this.screenSize=[0,0],this.mousePosition=[0,0],this.screenMousePosition=[0,0],this.searchArea=[[0,0],[0,0]],this.isSimulationRunning=!1,this.simulationProgress=0,this.maxPointSize=or,this.hoveredPoint=void 0,this.focusedPoint=void 0,this.draggingPointIndex=void 0,this.hoveredLinkIndex=void 0,this.adjustedSpaceSize=At.spaceSize,this.isSpaceKeyPressed=!1,this.webglMaxTextureSize=16384,this.hoveredPointRingColor=[1,1,1,Uc],this.focusedPointRingColor=[1,1,1,zc],this.outlinedPointRingColor=[1,1,1,1],this.highlightedPointSet=void 0,this.outlinedPointSet=void 0,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 Rc,this._backgroundColor=[0,0,0,0],this.alphaDecay=e=>1-Math.pow(io,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=Nc(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 ${At.spaceSize}`),e=At.spaceSize);const n=2;if(e<n&&(console.warn(`spaceSize (${e}) is too small. Using minimum value of ${n}`),e=n),!Number.isFinite(t)||t<=0||t<n){console.warn(`Invalid webglMaxTextureSize: ${t}. Using configSpaceSize without WebGL limit adjustment.`),this.adjustedSpaceSize=e;return}e>=t?(this.adjustedSpaceSize=Math.max(t/2,n),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:n}=this;this.screenSize=[e,t],this.scalePointX.domain([0,n]).range([(e-n)/2,(e+n)/2]),this.scalePointY.domain([n,0]).range([(t-n)/2,(t+n)/2])}scaleX(e){return this.scalePointX(e)}scaleY(e){return this.scalePointY(e)}setHoveredPointRingColor(e){const t=_t(e);this.hoveredPointRingColor[0]=t[0],this.hoveredPointRingColor[1]=t[1],this.hoveredPointRingColor[2]=t[2]}setFocusedPointRingColor(e){const t=_t(e);this.focusedPointRingColor[0]=t[0],this.focusedPointRingColor[1]=t[1],this.focusedPointRingColor[2]=t[2]}setOutlinedPointRingColor(e){const t=_t(e);this.outlinedPointRingColor[0]=t[0],this.outlinedPointRingColor[1]=t[1],this.outlinedPointRingColor[2]=t[2],this.outlinedPointRingColor[3]=t[3]}setHighlightedPointSet(e){this.highlightedPointSet=e?new Set(e):void 0}setOutlinedPointSet(e){this.outlinedPointSet=e?new Set(e):void 0}setGreyoutPointColor(e){if(e===void 0){this.greyoutPointColor=[-1,-1,-1,-1];return}const t=_t(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=_t(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 Dc=i=>typeof i=="function",no=i=>Array.isArray(i),Fc=i=>i instanceof Object,Mc=i=>i instanceof Object?i.constructor.name!=="Function"&&i.constructor.name!=="Object":!1,Oy=i=>Fc(i)&&!no(i)&&!Dc(i)&&!Mc(i);function _t(i){let e;if(no(i))e=i;else{const t=Ft(i),n=t==null?void 0:t.rgb();e=[((n==null?void 0:n.r)??0)/255,((n==null?void 0:n.g)??0)/255,((n==null?void 0:n.b)??0)/255,(t==null?void 0:t.opacity)??1]}return e}function Nc(i,e,t){return .2126*i+.7152*e+.0722*t}function He(i,e,t=0,n=0,r,s){return i.readPixelsToArrayWebGL(e,{sourceX:t,sourceY:n,sourceWidth:r,sourceHeight:s})}function ro(i){const e=[];for(let t=0;t<i.length;t+=4)i[t]!==0&&e.push(t/4);return e}function so(i,e){switch(i.info.type){case"webgl":{const t=i.gl.getParameter(Yt.ALIASED_POINT_SIZE_RANGE);return((t==null?void 0:t[1])??or)/e}case"webgpu":return or/e;default:return or/e}}function Oc(i,e,t){return Math.min(Math.max(i,e),t)}function Qe(i){return i!=null&&!Number.isNaN(i)}function Bc(i,e){return mx.sanitize(i,{ALLOWED_TAGS:["a","b","i","em","strong","span","div","p","br"],ALLOWED_ATTR:["href","target","class","id","style"],ALLOW_DATA_ATTR:!1,...e})}var oo=(i=>(i[i.Circle=0]="Circle",i[i.Square=1]="Square",i[i.Triangle=2]="Triangle",i[i.Diamond=3]="Diamond",i[i.Pentagon=4]="Pentagon",i[i.Hexagon=5]="Hexagon",i[i.Star=6]="Star",i[i.Cross=7]="Cross",i[i.None=8]="None",i))(oo||{});class By{constructor(e){this.sourcePointsNumber=0,this.targetPointsNumber=0,this._config=e}get pointsNumber(){return this.pointPositions&&this.pointPositions.length/2}get linksNumber(){return this.links&&this.links.length/2}updatePoints(){this.sourcePointsNumber=this.pointPositions?this.pointPositions.length/2:0,this.pointPositions=this.inputPointPositions,this.targetPointsNumber=this.pointPositions?this.pointPositions.length/2:0}updatePointColor(){if(this.pointsNumber===void 0){this.pointColors=void 0;return}const e=_t(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++)Qe(this.pointColors[t*4])||(this.pointColors[t*4]=e[0]),Qe(this.pointColors[t*4+1])||(this.pointColors[t*4+1]=e[1]),Qe(this.pointColors[t*4+2])||(this.pointColors[t*4+2]=e[2]),Qe(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++)Qe(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,n=t>=0&&t<=8?t:At.pointDefaultShape;if(this.inputPointShapes===void 0||this.inputPointShapes.length!==this.pointsNumber)this.pointShapes=new Float32Array(this.pointsNumber).fill(n);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||!Qe(o)||o<0||o>8)&&(r[s]=n)}}}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 n=e[t],r=n===void 0?NaN:n;!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 n=0;n<this.pointImageSizes.length;n++)Qe(this.pointImageSizes[n])||(this.pointImageSizes[n]=((t=this.pointSizes)==null?void 0:t[n])??e)}}updateLinks(){this.links=this.inputLinks}updateLinkColor(){if(this.linksNumber===void 0){this.linkColors=void 0;return}const e=_t(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++)Qe(this.linkColors[t*4])||(this.linkColors[t*4]=e[0]),Qe(this.linkColors[t*4+1])||(this.linkColors[t*4+1]=e[1]),Qe(this.linkColors[t*4+2])||(this.linkColors[t*4+2]=e[2]),Qe(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++)Qe(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()}getNeighboringPointIndices(e){var s,o;const t=Array.isArray(e)?e:[e],n=this.pointsNumber??0,r=new Set;for(const a of t)if(!(a<0||a>=n)){for(const[l]of((s=this.sourceIndexToTargetIndices)==null?void 0:s[a])??[])r.add(l);for(const[l]of((o=this.targetIndexToSourceIndices)==null?void 0:o[a])??[])r.add(l)}return[...r]}getConnectedLinkIndices(e){var o;const t=Array.isArray(e)?e:[e],n=this.pointsNumber??0,r=new Set(t),s=new Set;for(const a of r)if(!(a<0||a>=n))for(const[l,c]of((o=this.sourceIndexToTargetIndices)==null?void 0:o[a])??[])r.has(l)&&s.add(c);return[...s]}getConnectedPointIndices(e){const t=Array.isArray(e)?e:[e],n=new Set;if(this.links===void 0)return[];const r=this.linksNumber??0;for(const s of t){if(s<0||s>=r)continue;const o=this.links[s*2],a=this.links[s*2+1];o!==void 0&&n.add(o),a!==void 0&&n.add(a)}return[...n]}_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 n=0;n<this.linksNumber;n++){const r=this.links[n*2],s=this.links[n*2+1];r!==void 0&&s!==void 0&&(this.sourceIndexToTargetIndices[r]===void 0&&(this.sourceIndexToTargetIndices[r]=[]),(e=this.sourceIndexToTargetIndices[r])==null||e.push([s,n]),this.targetIndexToSourceIndices[s]===void 0&&(this.targetIndexToSourceIndices[s]=[]),(t=this.targetIndexToSourceIndices[s])==null||t.push([r,n]))}}_calculateDegrees(){var e,t,n,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=(n=this.sourceIndexToTargetIndices)==null?void 0:n[s])==null?void 0:r.length)??0,this.degree[s]=(this.inDegree[s]??0)+(this.outDegree[s]??0)}}var be=(i=>(i.Positions="positions",i.PointColors="pointColors",i.PointSizes="pointSizes",i.LinkColors="linkColors",i.LinkWidths="linkWidths",i))(be||{}),ao=(i=>(i.Linear="linear",i.QuadIn="quad-in",i.QuadOut="quad-out",i.QuadInOut="quad-in-out",i.CubicIn="cubic-in",i.CubicOut="cubic-out",i.CubicInOut="cubic-in-out",i.SinIn="sin-in",i.SinOut="sin-out",i.SinInOut="sin-in-out",i.ExpIn="exp-in",i.ExpOut="exp-out",i.ExpInOut="exp-in-out",i.CircleIn="circle-in",i.CircleOut="circle-out",i.CircleInOut="circle-in-out",i))(ao||{});const Uy={linear:Oa,"quad-in":Ba,"quad-out":Ua,"quad-in-out":za,"cubic-in":Pp,"cubic-out":Ip,"cubic-in-out":La,"sin-in":kp,"sin-out":Rp,"sin-in-out":Ep,"exp-in":Dp,"exp-out":Fp,"exp-in-out":Mp,"circle-in":Np,"circle-out":Op,"circle-in-out":Bp};class zy{constructor(e){this.progress=1,this.startTime=0,this.pendingProperties=new Set,this.activeProperties=new Set,this.config=e}get isPending(){return this.pendingProperties.size>0}get isActive(){return this.activeProperties.size>0}isPendingFor(e){return this.pendingProperties.has(e)}isActiveFor(e){return this.activeProperties.has(e)}queue(e){this.pendingProperties.add(e)}dequeue(e){this.pendingProperties.delete(e)}start(){var t,n,r,s;if(!this.isPending)return;const{transitionDuration:e}=this.config;if(e<=0){const o=this.isActive;this.pendingProperties.clear(),this.clearActiveCycle(),o&&((n=(t=this.config).onTransitionEnd)==null||n.call(t,!0));return}this.isActive&&this.end(!0),this.startTime=performance.now(),this.progress=0,this.activeProperties=new Set(this.pendingProperties),this.pendingProperties.clear(),(s=(r=this.config).onTransitionStart)==null||s.call(r)}step(){var r,s;if(!this.isActive)return;const{transitionDuration:e}=this.config;if(e<=0){this.end(!0);return}const t=Math.min((performance.now()-this.startTime)/e,1),n=this.applyEasing(t);this.progress=n,(s=(r=this.config).onTransition)==null||s.call(r,n),t>=1&&this.end(!1)}end(e){var t,n;this.isActive&&(this.clearActiveCycle(),(n=(t=this.config).onTransitionEnd)==null||n.call(t,e))}abort(){this.pendingProperties.clear(),this.clearActiveCycle()}applyEasing(e){return(Uy[this.config.transitionEasing]??Oa)(e)}clearActiveCycle(){this.startTime=0,this.progress=1,this.activeProperties.clear()}}const At={enableSimulation:!0,transitionDuration:800,transitionEasing:ao.CubicInOut,backgroundColor:"#222222",spaceSize:4096,pointDefaultColor:"#b3b3b3",pointDefaultSize:4,pointDefaultShape:oo.Circle,pointOpacity:1,pointGreyoutOpacity:void 0,pointGreyoutColor:void 0,pointSizeScale:1,scalePointsOnZoom:!1,hoveredPointCursor:"auto",renderHoveredPointRing:!1,hoveredPointRingColor:"white",focusedPointRingColor:"white",focusedPointIndex:void 0,highlightedPointIndices:void 0,outlinedPointIndices:void 0,outlinedPointRingColor:"white",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,highlightedLinkIndices:void 0,focusedLinkIndex:void 0,focusedLinkWidthIncrease: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,onTransitionStart:void 0,onTransition:void 0,onTransitionEnd: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:""},Uc=.7,zc=.95;function Lc(){const i={};for(const[e,t]of Object.entries(At))i[e]=Array.isArray(t)?[...t]:t;return i}function Ly(i){Object.assign(i,Lc())}function lo(i,e,t=!1){const n={};for(const[r,s]of Object.entries(e))if(s!==void 0)n[r]=s;else if(t){const o=At[r];n[r]=Array.isArray(o)?[...o]:o}Object.assign(i,n)}function co(i,e){if(!i)throw new Error(e||"shadertools: assertion failed.")}const uo={number:{type:"number",validate(i,e){return Number.isFinite(i)&&typeof e=="object"&&(e.max===void 0||i<=e.max)&&(e.min===void 0||i>=e.min)}},array:{type:"array",validate(i,e){return Array.isArray(i)||ArrayBuffer.isView(i)}}};function Vy(i){const e={};for(const[t,n]of Object.entries(i))e[t]=Wy(n);return e}function Wy(i){let e=Vc(i);if(e!=="object")return{value:i,...uo[e],type:e};if(typeof i=="object")return i?i.type!==void 0?{...i,...uo[i.type],type:i.type}:i.value===void 0?{type:"object",value:i}:(e=Vc(i.value),{...i,...uo[e],type:e}):{type:"object",value:null};throw new Error("props")}function Vc(i){return Array.isArray(i)||ArrayBuffer.isView(i)?"array":typeof i}const Hy={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
- `},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(`
36
+ `},Wc=/void\s+main\s*\([^)]*\)\s*\{\n?/,Hc=/}\n?[^{}]*$/,fo=[],ar="__LUMA_INJECT_DECLARATIONS__";function $y(i){const e={vertex:{},fragment:{}};for(const t in i){let n=i[t];const r=Xy(t);typeof n=="string"&&(n={order:0,injection:n}),e[r][t]=n}return e}function Xy(i){const e=i.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function lr(i,e,t,n=!1){const r=e==="vertex";for(const s in t){const o=t[s];o.sort((l,c)=>l.order-c.order),fo.length=o.length;for(let l=0,c=o.length;l<c;++l)fo[l]=o[l].injection;const a=`${fo.join(`
37
37
  `)}
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
38
+ `;switch(s){case"vs:#decl":r&&(i=i.replace(ar,a));break;case"vs:#main-start":r&&(i=i.replace(Wc,l=>l+a));break;case"vs:#main-end":r&&(i=i.replace(Hc,l=>a+l));break;case"fs:#decl":r||(i=i.replace(ar,a));break;case"fs:#main-start":r||(i=i.replace(Wc,l=>l+a));break;case"fs:#main-end":r||(i=i.replace(Hc,l=>a+l));break;default:i=i.replace(s,l=>l+a)}}return i=i.replace(ar,""),n&&(i=i.replace(/\}\s*$/,s=>s+Hy[e])),i}function cr(i){i.map(e=>Yy(e))}function Yy(i){if(i.instance)return;cr(i.dependencies||[]);const{propTypes:e={},deprecations:t=[],inject:n={}}=i,r={normalizedInjections:$y(n),parsedDeprecations:qy(t)};e&&(r.propValidators=Vy(e)),i.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},{})),i.defaultUniforms={...i.defaultUniforms,...s}}function $c(i,e,t){var n;(n=i.deprecations)==null||n.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 qy(i){return i.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),i}function ho(i){cr(i);const e={},t={};Xc({modules:i,level:0,moduleMap:e,moduleDepth:t});const n=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return cr(n),n}function Xc(i){const{modules:e,level:t,moduleMap:n,moduleDepth:r}=i;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(const s of e)n[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(const s of e)s.dependencies&&Xc({modules:s.dependencies,level:t+1,moduleMap:n,moduleDepth:r})}function jy(i){switch(i==null?void 0:i.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 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
- `,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}
62
+ `}}function Ky(i,e){var n;if(Number(((n=i.match(/^#version[ \t]+(\d+)/m))==null?void 0:n[1])||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return i=qc(i,Zy),i;case"fragment":return i=qc(i,Qy),i;default:throw new Error(e)}}const Yc=[[/^(#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("]],Zy=[...Yc,[po("attribute"),"in $1"],[po("varying"),"out $1"]],Qy=[...Yc,[po("varying"),"in $1"]];function qc(i,e){for(const[t,n]of e)i=i.replace(t,n);return i}function po(i){return new RegExp(`\\b${i}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function jc(i,e){let t="";for(const n in i){const r=i[n];if(t+=`void ${r.signature} {
64
+ `,r.header&&(t+=` ${r.header}`),e[n]){const s=e[n];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 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=`
66
+ `}return t}function Kc(i){const e={vertex:{},fragment:{}};for(const t of i){let n,r;typeof t!="string"?(n=t,r=n.hook):(n={},r=t),r=r.trim();const[s,o]=r.split(":"),a=r.replace(/\(.+/,""),l=Object.assign(n,{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 Jy(i,e){return{name:Gy(i,e),language:"glsl",version:e0(i)}}function Gy(i,e="unnamed"){const n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(i);return n?n[1]:e}function e0(i){let e=100;const t=i.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){const n=parseInt(t[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}const Zc=`
67
67
 
68
- ${sr}
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(`
68
+ ${ar}
69
+ `,t0=`precision highp float;
70
+ `;function i0(i){const e=ho(i.modules||[]);return{source:r0(i.platformInfo,{...i,source:i.source,stage:"vertex",modules:e}),getUniforms:Jc(e)}}function n0(i){const{vs:e,fs:t}=i,n=ho(i.modules||[]);return{vs:Qc(i.platformInfo,{...i,source:e,stage:"vertex",modules:n}),fs:Qc(i.platformInfo,{...i,source:t,stage:"fragment",modules:n}),getUniforms:Jc(n)}}function r0(i,e){var P;const{source:t,stage:n,modules:r,hookFunctions:s=[],inject:o={},log:a}=e;co(typeof t=="string","shader source must be a string");const l=t;let c="";const u=Kc(s),f={},h={},d={};for(const I in o){const w=typeof o[I]=="string"?{injection:o[I],order:0}:o[I],M=/^(v|f)s:(#)?([\w-]+)$/.exec(I);if(M){const k=M[2],y=M[3];k?y==="decl"?h[I]=[w]:d[I]=[w]:f[I]=[w]}else d[I]=[w]}const _=r;for(const I of _){a&&$c(I,l,a);const w=Gc(I,"wgsl");c+=w;const M=((P=I.injections)==null?void 0:P[n])||{};for(const k in M){const y=/^(v|f)s:#([\w-]+)$/.exec(k);if(y){const B=y[2]==="decl"?h:d;B[k]=B[k]||[],B[k].push(M[k])}else f[k]=f[k]||[],f[k].push(M[k])}}return c+=Zc,c=lr(c,n,h),c+=jc(u[n],f),c+=l,c=lr(c,n,d),c}function Qc(i,e){var B;const{source:t,stage:n,language:r="glsl",modules:s,defines:o={},hookFunctions:a=[],inject:l={},prologue:c=!0,log:u}=e;co(typeof t=="string","shader source must be a string");const f=r==="glsl"?Jy(t).version:-1,h=i.shaderLanguageVersion,d=f===100?"#version 100":"#version 300 es",P=t.split(`
71
71
  `).slice(1).join(`
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}
72
+ `),I={};s.forEach(U=>{Object.assign(I,U.defines)}),Object.assign(I,o);let w="";switch(r){case"wgsl":break;case"glsl":w=c?`${d}
73
73
 
74
74
  // ----- PROLOGUE -------------------------
75
- ${`#define SHADER_TYPE_${i.toUpperCase()}`}
75
+ ${`#define SHADER_TYPE_${n.toUpperCase()}`}
76
76
 
77
- ${wy(n)}
78
- ${i==="fragment"?ky:""}
77
+ ${jy(i)}
78
+ ${n==="fragment"?t0:""}
79
79
 
80
80
  // ----- APPLICATION DEFINES -------------------------
81
81
 
82
- ${Ny(P)}
82
+ ${s0(I)}
83
83
 
84
84
  `:`${d}
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} ---------------
85
+ `;break}const M=Kc(a),k={},y={},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 Q=q[2],O=q[3];Q?O==="decl"?y[U]=[W]:R[U]=[W]:k[U]=[W]}else R[U]=[W]}for(const U of s){u&&$c(U,P,u);const W=Gc(U,n);w+=W;const q=((B=U.instance)==null?void 0:B.normalizedInjections[n])||{};for(const Q in q){const O=/^(v|f)s:#([\w-]+)$/.exec(Q);if(O){const ee=O[2]==="decl"?y:R;ee[Q]=ee[Q]||[],ee[Q].push(q[Q])}else k[Q]=k[Q]||[],k[Q].push(q[Q])}}return w+="// ----- MAIN SHADER SOURCE -------------------------",w+=Zc,w=lr(w,n,y),w+=jc(M[n],k),w+=P,w=lr(w,n,R),r==="glsl"&&f!==h&&(w=Ky(w,n)),w.trim()}function Jc(i){return function(t){var r;const n={};for(const s of i){const o=(r=s.getUniforms)==null?void 0:r.call(s,t,n);Object.assign(n,o)}return n}}function s0(i={}){let e="";for(const t in i){const n=i[t];(n||Number.isFinite(n))&&(e+=`#define ${t.toUpperCase()} ${i[t]}
86
+ `)}return e}function Gc(i,e){let t;switch(e){case"vertex":t=i.vs||"";break;case"fragment":t=i.fs||"";break;case"wgsl":t=i.source||"";break;default:co(!1)}if(!i.name)throw new Error("Shader module must have a name");const n=i.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");let r=`// ----- MODULE ${i.name} ---------------
87
87
 
88
- `;return e!=="wgsl"&&(r+=`#define MODULE_${i}
88
+ `;return e!=="wgsl"&&(r+=`#define MODULE_${n}
89
89
  `),r+=`${t}
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==`
90
+ `,r}const o0=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,a0=/^\s*\#\s*endif\s*$/;function l0(i,e){var o;const t=i.split(`
91
+ `),n=[];let r=!0,s=null;for(const a of t){const l=a.match(o0),c=a.match(a0);l?(s=l[1],r=!!((o=e==null?void 0:e.defines)!=null&&o[s])):c?r=!0:r&&n.push(a)}return n.join(`
92
+ `)}const ei=class ei{constructor(){g(this,"_hookFunctions",[]);g(this,"_defaultModules",[])}static getDefaultShaderAssembler(){return ei.defaultShaderAssembler=ei.defaultShaderAssembler||new ei,ei.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(n=>n.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){const t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:s}=i0({...e,source:e.source,modules:t,hookFunctions:n});return{source:e.platformInfo.shaderLanguage==="wgsl"?l0(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){const t=this._getModuleList(e.modules),n=this._hookFunctions;return{...n0({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n}),modules:t}}_getModuleList(e=[]){const t=new Array(this._defaultModules.length+e.length),n={};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,n[l]=!0}for(let s=0,o=e.length;s<o;++s){const a=e[s],l=a.name;n[l]||(t[r++]=a,n[l]=!0)}return t.length=r,cr(t),t}};g(ei,"defaultShaderAssembler");let go=ei;class tt{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 eu{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,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 Mt extends tt{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 Nt extends tt{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 mo extends tt{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class Kt extends tt{constructor(e,t,n,r){super(e,n),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 Ot;(i=>{i[i.Uniform=0]="Uniform",i[i.Storage=1]="Storage",i[i.Texture=2]="Texture",i[i.Sampler=3]="Sampler",i[i.StorageTexture=4]="StorageTexture"})(Ot||(Ot={}));class ur{constructor(e,t,n,r,s,o,a){this.name=e,this.type=t,this.group=n,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 c0{constructor(e,t){this.name=e,this.type=t}}class u0{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}}class tu{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}}class f0{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}}class h0{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}}class d0{constructor(e,t=null,n){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=n}}class p0{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function g0(i){var e=(32768&i)>>15,t=(31744&i)>>10,n=1023&i;return t==0?(e?-1:1)*Math.pow(2,-14)*(n/Math.pow(2,10)):t==31?n?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,t-15)*(1+n/Math.pow(2,10))}const iu=new Float32Array(1),m0=new Int32Array(iu.buffer),Ne=new Uint16Array(1);function _0(i){iu[0]=i;const e=m0[0],t=e>>31&1;let n=e>>23&255,r=8388607&e;if(n===255)return Ne[0]=t<<15|31744|(r!==0?512:0),Ne[0];if(n===0){if(r===0)return Ne[0]=t<<15,Ne[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),Ne[0]=t<<15|n<<10|r>>13,Ne[0]):(Ne[0]=t<<15,Ne[0])}return n=n-127+15,n>=31?(Ne[0]=t<<15|31744,Ne[0]):n<=0?n<-10?(Ne[0]=t<<15,Ne[0]):(r=(8388608|r)>>1-n,Ne[0]=t<<15|r>>13,Ne[0]):(r>>=13,Ne[0]=t<<15|n<<10|r,Ne[0])}const _o=new Uint32Array(1),nu=new Float32Array(_o.buffer,0,1);function ru(i){const e=112+(i>>6&31)<<23|(63&i)<<17;return _o[0]=e,nu[0]}function x0(i,e,t,n,r,s,o,a,l){const c=n*(o>>=r)*(s>>=r)+t*o+e*a;switch(l){case"r8unorm":return[se(i,c,"8unorm",1)[0]];case"r8snorm":return[se(i,c,"8snorm",1)[0]];case"r8uint":return[se(i,c,"8uint",1)[0]];case"r8sint":return[se(i,c,"8sint",1)[0]];case"rg8unorm":{const u=se(i,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{const u=se(i,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{const u=se(i,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{const u=se(i,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const u=se(i,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{const u=se(i,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{const u=se(i,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{const u=se(i,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const u=se(i,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[se(i,c,"16uint",1)[0]];case"r16sint":return[se(i,c,"16sint",1)[0]];case"r16float":return[se(i,c,"16float",1)[0]];case"rg16uint":{const u=se(i,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{const u=se(i,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{const u=se(i,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{const u=se(i,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{const u=se(i,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{const u=se(i,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[se(i,c,"32uint",1)[0]];case"r32sint":return[se(i,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[se(i,c,"32float",1)[0]];case"rg32uint":{const u=se(i,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{const u=se(i,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{const u=se(i,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{const u=se(i,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{const u=se(i,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{const u=se(i,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{const u=new Uint32Array(i.buffer,c,1)[0],f=(4192256&u)>>11,h=(4290772992&u)>>22;return[ru(2047&u),ru(f),function(d){const _=112+(d>>5&31)<<23|(31&d)<<18;return _o[0]=_,nu[0]}(h),1]}}return null}function se(i,e,t,n){const r=[0,0,0,0];for(let s=0;s<n;++s)switch(t){case"8unorm":r[s]=i[e]/255,e++;break;case"8snorm":r[s]=i[e]/255*2-1,e++;break;case"8uint":r[s]=i[e],e++;break;case"8sint":r[s]=i[e]-127,e++;break;case"16uint":r[s]=i[e]|i[e+1]<<8,e+=2;break;case"16sint":r[s]=(i[e]|i[e+1]<<8)-32768,e+=2;break;case"16float":r[s]=g0(i[e]|i[e+1]<<8),e+=2;break;case"32uint":case"32sint":r[s]=i[e]|i[e+1]<<8|i[e+2]<<16|i[e+3]<<24,e+=4;break;case"32float":r[s]=new Float32Array(i.buffer,e,1)[0],e+=4}return r}function ae(i,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":i[e]=255*r[s],e++;break;case"8snorm":i[e]=.5*(r[s]+1)*255,e++;break;case"8uint":i[e]=r[s],e++;break;case"8sint":i[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{const o=_0(r[s]);new Uint16Array(i.buffer,e,1)[0]=o,e+=2;break}case"32uint":new Uint32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(i.buffer,e,1)[0]=r[s],e+=4}return r}const xo={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 it{constructor(){this.id=it._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(fr.instance);for(const n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(hr.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}}it._id=0;class fr extends it{}fr.instance=new fr;class hr extends it{}hr.instance=new hr;const su=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 ge extends it{constructor(){super()}}class Ki extends ge{constructor(e,t,n,r,s,o){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,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 y0 extends ge{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}}class ou extends ge{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 yo extends ge{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}}class au extends ge{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}}class Ct extends ge{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,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 vo extends ge{constructor(e,t,n){super(),this.attributes=null,this.name=e,this.type=t,this.value=n}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}}class Zi extends ge{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,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 dr extends ge{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,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 _i,Qi,A,b;(i=>{i.increment="++",i.decrement="--"})(_i||(_i={})),(i=>{i.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return i[t]}})(_i||(_i={}));class lu extends ge{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}}(i=>{i.assign="=",i.addAssign="+=",i.subtractAssin="-=",i.multiplyAssign="*=",i.divideAssign="/=",i.moduloAssign="%=",i.andAssign="&=",i.orAssign="|=",i.xorAssign="^=",i.shiftLeftAssign="<<=",i.shiftRightAssign=">>="})(Qi||(Qi={})),(i=>{i.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(Qi||(Qi={}));class cu extends ge{constructor(e,t,n){super(),this.operator=e,this.variable=t,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}}class bo extends ge{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return su.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class uu extends ge{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 fu extends ge{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 hu extends ge{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,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 du extends ge{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 v0 extends ge{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class b0 extends ge{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class pu extends ge{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class So extends ge{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class S0 extends ge{constructor(){super()}get astNodeType(){return"discard"}}class gu extends ge{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class mu extends ge{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class E extends ge{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 n=1;n<e.length;++n){const r=E._priority.get(t.name);E._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?E.i32:t}getTypeName(){return this.name}}E.x32=new E("x32"),E.f32=new E("f32"),E.i32=new E("i32"),E.u32=new E("u32"),E.f16=new E("f16"),E.bool=new E("bool"),E.void=new E("void"),E._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class _u extends E{constructor(e){super(e)}}class Pt extends E{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,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 E{constructor(e,t,n){super(e),this.format=t,this.access=n}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",E.f32,null),T.vec3f=new T("vec3",E.f32,null),T.vec4f=new T("vec4",E.f32,null),T.vec2i=new T("vec2",E.i32,null),T.vec3i=new T("vec3",E.i32,null),T.vec4i=new T("vec4",E.i32,null),T.vec2u=new T("vec2",E.u32,null),T.vec3u=new T("vec3",E.u32,null),T.vec4u=new T("vec4",E.u32,null),T.vec2h=new T("vec2",E.f16,null),T.vec3h=new T("vec3",E.f16,null),T.vec4h=new T("vec4",E.f16,null),T.vec2b=new T("vec2",E.bool,null),T.vec3b=new T("vec3",E.bool,null),T.vec4b=new T("vec4",E.bool,null),T.mat2x2f=new T("mat2x2",E.f32,null),T.mat2x3f=new T("mat2x3",E.f32,null),T.mat2x4f=new T("mat2x4",E.f32,null),T.mat3x2f=new T("mat3x2",E.f32,null),T.mat3x3f=new T("mat3x3",E.f32,null),T.mat3x4f=new T("mat3x4",E.f32,null),T.mat4x2f=new T("mat4x2",E.f32,null),T.mat4x3f=new T("mat4x3",E.f32,null),T.mat4x4f=new T("mat4x4",E.f32,null),T.mat2x2h=new T("mat2x2",E.f16,null),T.mat2x3h=new T("mat2x3",E.f16,null),T.mat2x4h=new T("mat2x4",E.f16,null),T.mat3x2h=new T("mat3x2",E.f16,null),T.mat3x3h=new T("mat3x3",E.f16,null),T.mat3x4h=new T("mat3x4",E.f16,null),T.mat4x2h=new T("mat4x2",E.f16,null),T.mat4x3h=new T("mat4x3",E.f16,null),T.mat4x4h=new T("mat4x4",E.f16,null),T.mat2x2i=new T("mat2x2",E.i32,null),T.mat2x3i=new T("mat2x3",E.i32,null),T.mat2x4i=new T("mat2x4",E.i32,null),T.mat3x2i=new T("mat3x2",E.i32,null),T.mat3x3i=new T("mat3x3",E.i32,null),T.mat3x4i=new T("mat3x4",E.i32,null),T.mat4x2i=new T("mat4x2",E.i32,null),T.mat4x3i=new T("mat4x3",E.i32,null),T.mat4x4i=new T("mat4x4",E.i32,null),T.mat2x2u=new T("mat2x2",E.u32,null),T.mat2x3u=new T("mat2x3",E.u32,null),T.mat2x4u=new T("mat2x4",E.u32,null),T.mat3x2u=new T("mat3x2",E.u32,null),T.mat3x3u=new T("mat3x3",E.u32,null),T.mat3x4u=new T("mat3x4",E.u32,null),T.mat4x2u=new T("mat4x2",E.u32,null),T.mat4x3u=new T("mat4x3",E.u32,null),T.mat4x4u=new T("mat4x4",E.u32,null);class pr extends E{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}}class Ji extends E{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}}class Gi extends E{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}}class lt extends it{constructor(){super(),this.postfix=null}}class Zt extends lt{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class xt 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 To 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 su.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 Je 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 xu extends lt{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){const n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}}class Ce 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 m||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 m||this.value instanceof K?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}}class yu extends lt{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class xi extends lt{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class vu extends lt{constructor(){super()}}class Se extends vu{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 vu{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?E.f32:e.name==="u32"||t.name==="u32"?E.u32:E.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class bu extends it{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class gr extends lt{constructor(){super()}get astNodeType(){return"default"}}class Su extends bu{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class Tu extends bu{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class wu extends it{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}}class T0 extends it{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 Au extends it{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}}class Cu extends it{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class nt{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=nt._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}}nt._id=0;class wo extends nt{constructor(){super(new tt("void",null),null)}toString(){return"void"}}wo.void=new wo;class yi extends nt{constructor(e){super(new mo("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}toString(){return`&${this.reference.toString()}`}}class v extends nt{constructor(e,t,n=null){super(t,n),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,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);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,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}}function w0(i,e,t){const n=e.length;return n===2?t==="f32"?new m(new Float32Array(e),i.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new m(new Int32Array(e),i.getTypeInfo("vec2i")):t==="u32"?new m(new Uint32Array(e),i.getTypeInfo("vec2u")):t==="f16"?new m(new Float32Array(e),i.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new m(new Float32Array(e),i.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new m(new Int32Array(e),i.getTypeInfo("vec3i")):t==="u32"?new m(new Uint32Array(e),i.getTypeInfo("vec3u")):t==="f16"?new m(new Float32Array(e),i.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new m(new Float32Array(e),i.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new m(new Int32Array(e),i.getTypeInfo("vec4i")):t==="u32"?new m(new Uint32Array(e),i.getTypeInfo("vec4u")):t==="f16"?new m(new Float32Array(e),i.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}class m extends nt{constructor(e,t,n=null){if(super(t,n),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 m(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new m(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new m(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof Zt?console.error("TODO: Set vector postfix"):t instanceof m?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof Kt)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 xi){const o=t.index;let a=-1;if(o instanceof Ce){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,n);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 Zt))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=w0(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 nt{constructor(e,t,n=null){super(t,n),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,n,r){n instanceof Zt?console.error("TODO: Set matrix postfix"):t instanceof K?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;const r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof Kt)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 xi){const s=t.index;let o=-1;if(s instanceof Ce){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,n);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 m(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 m(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 m(new Float32Array(this.data.buffer,this.data.byteOffset+4*o*4,4),e.getTypeInfo(`vec4${a}`))}return t.postfix?l.getSubData(e,t.postfix,n):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 nt{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}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,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,o=this.typeInfo;for(;n;){if(n instanceof xi)if(o instanceof Nt){const a=n.index;if(a instanceof Ce){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(!(n instanceof Zt))return void console.error("SetDataValue: Unknown postfix type",n);{const a=n.value;if(o instanceof Mt){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 tt){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`)}}}n=n.postfix}this.setData(e,t,o,s,r)}setData(e,t,n,r,s){const o=n.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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 m?(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 ye){if(n===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,n){var r,s,o;if(t===null)return this;let a=this.offset,l=this.typeInfo;for(;t;){if(t instanceof xi){const u=t.index,f=u instanceof lt?e.evalExpression(u,n):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 Nt)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 Zt))return console.error("GetDataValue: Unknown postfix type",t),null;{const u=t.value;if(l instanceof Mt){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 tt){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 P=u[_].toLowerCase();let I=0;if(P==="x"||P==="r")I=0;else if(P==="y"||P==="g")I=1;else if(P==="z"||P==="b")I=2;else{if(P!=="w"&&P!=="a")return console.error(`Unknown member ${u}`),null;I=3}if(u.length===1){if(f.endsWith("f"))return this.buffer.byteLength<a+4*I+4?(console.log("Insufficient buffer data"),null):new v(new Float32Array(this.buffer,a+4*I,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new v(new Float32Array(this.buffer,a+4*I,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new v(new Int32Array(this.buffer,a+4*I,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new v(new Int32Array(this.buffer,a+4*I,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new v(new Uint32Array(this.buffer,a+4*I,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")d.push(new Float32Array(this.buffer,a,2)[I]);else if(f==="vec3f"){if(a+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;const w=new Float32Array(this.buffer,a,3);d.push(w[I])}else if(f==="vec4f")d.push(new Float32Array(this.buffer,a,4)[I]);else if(f==="vec2i")h="i",d.push(new Int32Array(this.buffer,a,2)[I]);else if(f==="vec3i")h="i",d.push(new Int32Array(this.buffer,a,3)[I]);else if(f==="vec4i")h="i",d.push(new Int32Array(this.buffer,a,4)[I]);else if(f==="vec2u"){h="u";const w=new Uint32Array(this.buffer,a,2);d.push(w[I])}else f==="vec3u"?(h="u",d.push(new Uint32Array(this.buffer,a,3)[I])):f==="vec4u"&&(h="u",d.push(new Uint32Array(this.buffer,a,4)[I]))}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 m(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 m(new Float32Array(this.buffer,a,2),l,this):c==="vec3f"?new m(new Float32Array(this.buffer,a,3),l,this):c==="vec4f"?new m(new Float32Array(this.buffer,a,4),l,this):c==="vec2i"?new m(new Int32Array(this.buffer,a,2),l,this):c==="vec3i"?new m(new Int32Array(this.buffer,a,3),l,this):c==="vec4i"?new m(new Int32Array(this.buffer,a,4),l,this):c==="vec2u"?new m(new Uint32Array(this.buffer,a,2),l,this):c==="vec3u"?new m(new Uint32Array(this.buffer,a,3),l,this):c==="vec4u"?new m(new Uint32Array(this.buffer,a,4),l,this):l instanceof Kt&&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 Nt)if(this.typeInfo.format.name==="f32"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){const t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){const t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+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 n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+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 n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof Mt?e+="{...}":e="[...]";return e}}class It extends nt{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new It(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.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 n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){const e=this.format,t=xo[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=xo[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=xo[e],n=this.width;if(!e||n<=0||!t)return-1;const r=this.height,s=this.depthOrArrayLayers,o=this.dimension;return n/t.blockWidth*(o==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){const s=this.texelByteSize,o=this.bytesPerRow,a=this.height,l=this.data[r];return x0(new Uint8Array(l),e,t,n,r,a,o,s,this.format)}setPixel(e,t,n,r,s){const o=this.texelByteSize,a=this.bytesPerRow,l=this.height,c=this.data[r];(function(u,f,h,d,_,P,I,w,M,k){const y=d*(I>>=_)*(P>>=_)+h*I+f*w;switch(M){case"r8unorm":return void ae(u,y,"8unorm",1,k);case"r8snorm":return void ae(u,y,"8snorm",1,k);case"r8uint":return void ae(u,y,"8uint",1,k);case"r8sint":return void ae(u,y,"8sint",1,k);case"rg8unorm":return void ae(u,y,"8unorm",2,k);case"rg8snorm":return void ae(u,y,"8snorm",2,k);case"rg8uint":return void ae(u,y,"8uint",2,k);case"rg8sint":return void ae(u,y,"8sint",2,k);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void ae(u,y,"8unorm",4,k);case"rgba8snorm":return void ae(u,y,"8snorm",4,k);case"rgba8uint":return void ae(u,y,"8uint",4,k);case"rgba8sint":return void ae(u,y,"8sint",4,k);case"r16uint":return void ae(u,y,"16uint",1,k);case"r16sint":return void ae(u,y,"16sint",1,k);case"r16float":return void ae(u,y,"16float",1,k);case"rg16uint":return void ae(u,y,"16uint",2,k);case"rg16sint":return void ae(u,y,"16sint",2,k);case"rg16float":return void ae(u,y,"16float",2,k);case"rgba16uint":return void ae(u,y,"16uint",4,k);case"rgba16sint":return void ae(u,y,"16sint",4,k);case"rgba16float":return void ae(u,y,"16float",4,k);case"r32uint":return void ae(u,y,"32uint",1,k);case"r32sint":return void ae(u,y,"32sint",1,k);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void ae(u,y,"32float",1,k);case"rg32uint":return void ae(u,y,"32uint",2,k);case"rg32sint":return void ae(u,y,"32sint",2,k);case"rg32float":return void ae(u,y,"32float",2,k);case"rgba32uint":return void ae(u,y,"32uint",4,k);case"rgba32sint":return void ae(u,y,"32sint",4,k);case"rgba32float":return void ae(u,y,"32float",4,k);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,n,r,l,a,o,this.format,s)}}(i=>{i[i.token=0]="token",i[i.keyword=1]="keyword",i[i.reserved=2]="reserved"})(b||(b={}));class S{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}}class p{}A=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={"@":A.tokens.attr,"{":A.tokens.brace_left,"}":A.tokens.brace_right,":":A.tokens.colon,",":A.tokens.comma,"(":A.tokens.paren_left,")":A.tokens.paren_right,";":A.tokens.semicolon},p.literalTokens={"&":A.tokens.and,"&&":A.tokens.and_and,"->":A.tokens.arrow,"/":A.tokens.forward_slash,"!":A.tokens.bang,"[":A.tokens.bracket_left,"]":A.tokens.bracket_right,"=":A.tokens.equal,"==":A.tokens.equal_equal,"!=":A.tokens.not_equal,">":A.tokens.greater_than,">=":A.tokens.greater_than_equal,">>":A.tokens.shift_right,"<":A.tokens.less_than,"<=":A.tokens.less_than_equal,"<<":A.tokens.shift_left,"%":A.tokens.modulo,"-":A.tokens.minus,"--":A.tokens.minus_minus,".":A.tokens.period,"+":A.tokens.plus,"++":A.tokens.plus_plus,"|":A.tokens.or,"||":A.tokens.or_or,"*":A.tokens.star,"~":A.tokens.tilde,_:A.tokens.underscore,"^":A.tokens.xor,"+=":A.tokens.plus_equal,"-=":A.tokens.minus_equal,"*=":A.tokens.times_equal,"/=":A.tokens.division_equal,"%=":A.tokens.modulo_equal,"&=":A.tokens.and_equal,"|=":A.tokens.or_equal,"^=":A.tokens.xor_equal,">>=":A.tokens.shift_right_equal,"<<=":A.tokens.shift_left_equal},p.regexTokens={decimal_float_literal:A.tokens.decimal_float_literal,hex_float_literal:A.tokens.hex_float_literal,int_literal:A.tokens.int_literal,uint_literal:A.tokens.uint_literal,ident:A.tokens.ident},p.storage_class=[A.keywords.function,A.keywords.private,A.keywords.workgroup,A.keywords.uniform,A.keywords.storage],p.access_mode=[A.keywords.read,A.keywords.write,A.keywords.read_write],p.sampler_type=[A.keywords.sampler,A.keywords.sampler_comparison],p.sampled_texture_type=[A.keywords.texture_1d,A.keywords.texture_2d,A.keywords.texture_2d_array,A.keywords.texture_3d,A.keywords.texture_cube,A.keywords.texture_cube_array],p.multisampled_texture_type=[A.keywords.texture_multisampled_2d],p.storage_texture_type=[A.keywords.texture_storage_1d,A.keywords.texture_storage_2d,A.keywords.texture_storage_2d_array,A.keywords.texture_storage_3d],p.depth_texture_type=[A.keywords.texture_depth_2d,A.keywords.texture_depth_2d_array,A.keywords.texture_depth_cube,A.keywords.texture_depth_cube_array,A.keywords.texture_depth_multisampled_2d],p.texture_external_type=[A.keywords.texture_external],p.any_texture_type=[...A.sampled_texture_type,...A.multisampled_texture_type,...A.storage_texture_type,...A.depth_texture_type,...A.texture_external_type],p.texel_format=[A.keywords.r8unorm,A.keywords.r8snorm,A.keywords.r8uint,A.keywords.r8sint,A.keywords.r16uint,A.keywords.r16sint,A.keywords.r16float,A.keywords.rg8unorm,A.keywords.rg8snorm,A.keywords.rg8uint,A.keywords.rg8sint,A.keywords.r32uint,A.keywords.r32sint,A.keywords.r32float,A.keywords.rg16uint,A.keywords.rg16sint,A.keywords.rg16float,A.keywords.rgba8unorm,A.keywords.rgba8unorm_srgb,A.keywords.rgba8snorm,A.keywords.rgba8uint,A.keywords.rgba8sint,A.keywords.bgra8unorm,A.keywords.bgra8unorm_srgb,A.keywords.rgb10a2unorm,A.keywords.rg11b10float,A.keywords.rg32uint,A.keywords.rg32sint,A.keywords.rg32float,A.keywords.rgba16uint,A.keywords.rgba16sint,A.keywords.rgba16float,A.keywords.rgba32uint,A.keywords.rgba32sint,A.keywords.rgba32float],p.const_literal=[A.tokens.int_literal,A.tokens.uint_literal,A.tokens.decimal_float_literal,A.tokens.hex_float_literal,A.keywords.true,A.keywords.false],p.literal_or_ident=[A.tokens.ident,A.tokens.int_literal,A.tokens.uint_literal,A.tokens.decimal_float_literal,A.tokens.hex_float_literal,A.tokens.name],p.element_count_expression=[A.tokens.int_literal,A.tokens.uint_literal,A.tokens.ident],p.template_types=[A.keywords.vec2,A.keywords.vec3,A.keywords.vec4,A.keywords.mat2x2,A.keywords.mat2x3,A.keywords.mat2x4,A.keywords.mat3x2,A.keywords.mat3x3,A.keywords.mat3x4,A.keywords.mat4x2,A.keywords.mat4x3,A.keywords.mat4x4,A.keywords.atomic,A.keywords.bitcast,...A.any_texture_type],p.attribute_name=[A.tokens.ident,A.keywords.block,A.keywords.diagnostic],p.assignment_operators=[A.tokens.equal,A.tokens.plus_equal,A.tokens.minus_equal,A.tokens.times_equal,A.tokens.division_equal,A.tokens.modulo_equal,A.tokens.and_equal,A.tokens.or_equal,A.tokens.xor_equal,A.tokens.shift_right_equal,A.tokens.shift_left_equal],p.increment_operators=[A.tokens.plus_plus,A.tokens.minus_minus];class Pu{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,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 Pu(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
- `)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 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
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 n=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 n!==p.none&&(this._current--,this._addToken(n),!0);e=l,this._current+=c+1}if(n=o,this._isAtEnd())break;e+=this._advance()}return n!==p.none&&(this._addToken(n),!0)}_findType(e){for(const n in p.regexTokens){const r=p.regexTokens[n];if(this._match(e,r.rule))return r}return p.literalTokens[e]||p.none}_match(e,t){const n=t.exec(e);return n&&n.index==0&&n[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 Pu(e,t,this._line,this._start,this._current))}}function z(i){return Array.isArray(i)||(i==null?void 0:i.buffer)instanceof ArrayBuffer}const mr=new Float32Array(1),C0=new Uint32Array(mr.buffer),P0=new Uint32Array(mr.buffer),_r=new Int32Array(1),I0=new Float32Array(_r.buffer),k0=new Uint32Array(_r.buffer),xr=new Uint32Array(1),R0=new Float32Array(xr.buffer),E0=new Int32Array(xr.buffer);function Iu(i,e,t){if(e===t)return i;if(e==="f32"){if(t==="i32"||t==="x32")return mr[0]=i,C0[0];if(t==="u32")return mr[0]=i,P0[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return _r[0]=i,I0[0];if(t==="u32")return _r[0]=i,k0[0]}else if(e==="u32"){if(t==="f32")return xr[0]=i,R0[0];if(t==="i32"||t==="x32")return xr[0]=i,E0[0]}return console.error(`Unsupported cast from ${e} to ${t}`),i}class D0{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class yr{constructor(e,t){this.align=e,this.size=t}}class yt{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new p0,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 Ki&&this._functions.set(t.name,new D0(t));for(const t of e)if(t instanceof Pt){const n=this.getTypeInfo(t,null);n instanceof Mt&&this.structs.push(n)}for(const t of e)if(t instanceof So)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof vo){const n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new f0(n.name,s,n.attributes,r));continue}if(this._isUniformVar(t)){const n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),a=new ur(n.name,o,r,s,n.attributes,Ot.Uniform,n.access);a.access||(a.access="read"),this.uniforms.push(a);continue}if(this._isStorageVar(t)){const n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),a=this._isStorageTexture(o),l=new ur(n.name,o,r,s,n.attributes,a?Ot.StorageTexture:Ot.Storage,n.access);l.access||(l.access="read"),this.storage.push(l);continue}if(this._isTextureVar(t)){const n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),a=this._isStorageTexture(o),l=new ur(n.name,o,r,s,n.attributes,a?Ot.StorageTexture:Ot.Texture,n.access);l.access||(l.access="read"),a?this.storage.push(l):this.textures.push(l);continue}if(this._isSamplerVar(t)){const n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),a=new ur(n.name,o,r,s,n.attributes,Ot.Sampler,n.access);this.samplers.push(a);continue}}for(const t of e)if(t instanceof Ki){const n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),o=n||r||s,a=new d0(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 h0(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(n=>{var r,s,o;if(n instanceof Cu){if(n.value)if(z(n.value))for(const a of n.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)n.value===a.name&&((s=t.info)===null||s===void 0||s.overrides.push(a))}else if(n instanceof Je)for(const a of this.overrides)n.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 n;for(const r of e.calls){const s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(const r of this.entry.compute)if(r.name===n){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===n){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===n){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 n=[],r=this,s=[];return e.search(o=>{if(o instanceof fr)s.push({});else if(o instanceof hr)s.pop();else if(o instanceof Ct){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 xt){const a=o;t&&a.type!==null&&this._markStructsFromAST(a.type)}else if(o instanceof Zi){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 Je){const a=o;if(s.length>0&&s[s.length-1][a.name])return;const l=r._findResource(a.name);l&&n.push(l)}else if(o instanceof To){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)),n.push(...l.resources))}else if(o instanceof bo){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)),n.push(...l.resources))}}),[...new Map(n.map(o=>[o.name,o])).values()]}getBindGroups(){const e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(const n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof Pt)this._getStructOutputs(e,t);else{const n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(const n of e.members)if(n.type instanceof Pt)this._getStructOutputs(n.type,t);else{const r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){const s=this.getTypeInfo(n.type,n.type.attributes),o=this._parseInt(r.value),a=new tu(n.name,s,r.name,o);t.push(a)}}}_getOutputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new tu("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(const n of e)if(n.type instanceof Pt)this._getStructInputs(n.type,t);else{const r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(const n of e.members)if(n.type instanceof Pt)this._getStructInputs(n.type,t);else{const r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),o=new u0(e.name,r,t.name,s);return n!==null&&(o.interpolation=this._parseString(n.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 c0(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 pr){const r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new mo(e.name,r,t);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Ji){const r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,o=new Nt(r.name,t);return o.format=s,o.count=r.count,this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Pt){const r=e,s=new Mt(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 eu(o.name,a,o.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Gi){const r=e,s=r.format instanceof E,o=r.format?s?this.getTypeInfo(r.format,null):new tt(r.format,null):null,a=new Kt(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 Kt(r.name,s,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}const n=new tt(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;const s=this._getTypeSize(e);if(e.size=(t=s==null?void 0:s.size)!==null&&t!==void 0?t:0,e instanceof Nt&&e.format){const o=this._getTypeSize(e.format);e.stride=Math.max((n=o==null?void 0:o.size)!==null&&n!==void 0?n:0,(r=o==null?void 0:o.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof mo&&this._updateTypeInfo(e.format),e instanceof Mt&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=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;n=this._roundUp(f,n+r),r=h,s=n,o=Math.max(o,f),c.offset=n,c.size=h,this._updateTypeInfo(c.type)}e.size=this._roundUp(o,s+r),e.align=o}_getTypeSize(e){var t,n;if(e==null)return null;const r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof eu&&(e=e.type),e instanceof tt){const o=this._getAlias(e.name);o!==null&&(e=o)}{const o=yt._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 yr(Math.max(s,o.align/a),Math.max(r,o.size/a))}}{const o=yt._typeInfo[e.name.substring(0,e.name.length-1)];if(o){const a=e.name[e.name.length-1]==="h"?2:1;return new yr(Math.max(s,o.align/a),Math.max(r,o.size/a))}}if(e instanceof Nt){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((n=e==null?void 0:e.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(a,l)),r&&(l=r),new yr(Math.max(s,a),Math.max(r,l))}if(e instanceof Mt){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 yr(Math.max(s,o),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof Ct&&e.storage=="uniform"}_isStorageVar(e){return e instanceof Ct&&e.storage=="storage"}_isTextureVar(e){return e instanceof Ct&&e.type!==null&&yt._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof Ct&&e.type!==null&&yt._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){const n=e;if(!n||!n.attributes)return null;const r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}}yt._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}},yt._textureTypes=p.any_texture_type.map(i=>i.name),yt._samplerTypes=p.sampler_type.map(i=>i.name);let Ao=0;class Co{constructor(e,t,n){this.id=Ao++,this.name=e,this.value=t,this.node=n}clone(){return new Co(this.name,this.value,this.node)}}class Po{constructor(e){this.id=Ao++,this.name=e.name,this.node=e}clone(){return new Po(this.node)}}class Io{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=Ao++,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,n){this.variables.set(e,new Co(e,t,n??null))}setVariable(e,t,n){const r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;const n=this.getVariable(e);return(t=n==null?void 0:n.value)!==null&&t!==void 0?t:null}clone(){return new Io(this)}}class F0{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class M0{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const n=this.exec.evalExpression(e.args[0],t);let r=!0;if(n instanceof m)return n.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 n=this.exec.evalExpression(e.args[0],t);if(n instanceof m){const r=n.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 n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof v))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.evalExpression(n,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 n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.abs(s)),n.typeInfo);const r=n;return new v(Math.abs(r.value),r.typeInfo)}Acos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.acos(s)),n.typeInfo);const r=n;return new v(Math.acos(r.value),n.typeInfo)}Acosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.acosh(s)),n.typeInfo);const r=n;return new v(Math.acosh(r.value),n.typeInfo)}Asin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.asin(s)),n.typeInfo);const r=n;return new v(Math.asin(r.value),n.typeInfo)}Asinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.asinh(s)),n.typeInfo);const r=n;return new v(Math.asinh(r.value),n.typeInfo)}Atan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.atan(s)),n.typeInfo);const r=n;return new v(Math.atan(r.value),n.typeInfo)}Atanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.atanh(s)),n.typeInfo);const r=n;return new v(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m)return new m(n.data.map((a,l)=>Math.atan2(a,r.data[l])),n.typeInfo);const s=n,o=r;return new v(Math.atan2(s.value,o.value),n.typeInfo)}Ceil(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.ceil(s)),n.typeInfo);const r=n;return new v(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof m&&r instanceof m&&s instanceof m)return new m(n.data.map((c,u)=>this._clamp(c,r.data[u],s.data[u])),n.typeInfo);const o=n,a=r,l=s;return new v(this._clamp(o.value,a.value,l.value),n.typeInfo)}Cos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.cos(s)),n.typeInfo);const r=n;return new v(Math.cos(r.value),n.typeInfo)}Cosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.cosh(s)),n.typeInfo);const r=n;return new v(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.clz32(s)),n.typeInfo);const r=n;return new v(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>this._countOneBits(s)),n.typeInfo);const r=n;return new v(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);const r=n;return new v(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;const s=n.data,o=r.data;return new m([s[1]*o[2]-o[1]*s[2],s[2]*o[0]-o[2]*s[0],s[0]*o[1]-o[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){const n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof m?new m(n.data.map(s=>s*r),n.typeInfo):new v(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof K){const r=n.data,s=n.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 n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m){let a=0;for(let l=0;l<n.data.length;++l)a+=(n.data[l]-r.data[l])*(n.data[l]-r.data[l]);return new v(Math.sqrt(a),this.getTypeInfo("f32"))}const s=n,o=r;return new v(Math.abs(s.value-o.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof m&&r instanceof m?new v(this._dot(n.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 n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.exp(s)),n.typeInfo);const r=n;return new v(Math.exp(r.value),n.typeInfo)}Exp2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.pow(2,s)),n.typeInfo);const r=n;return new v(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){const n=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(n instanceof m)return new m(n.data.map(c=>c>>o&(1<<a)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;const l=n.value;return new v(l>>o&(1<<a)-1,this.getTypeInfo("i32"))}FaceForward(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof m&&r instanceof m&&s instanceof m){const o=this._dot(r.data,s.data);return new m(o<0?Array.from(n.data):n.data.map(a=>-a),n.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 n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);const r=n;return new v(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);const r=n;return new v(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.floor(s)),n.typeInfo);const r=n;return new v(Math.floor(r.value),n.typeInfo)}Fma(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof m&&r instanceof m&&s instanceof m)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new m(n.data.map((c,u)=>c*r.data[u]+s.data[u]),n.typeInfo);const o=n,a=r,l=s;return new v(o.value*a.value+l.value,o.typeInfo)}Fract(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>s-Math.floor(s)),n.typeInfo);const r=n;return new v(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){const n=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(n instanceof m&&r instanceof m)return new m(n.data.map((h,d)=>h&c|r.data[d]<<a&l),n.typeInfo);const u=n.value,f=r.value;return new v(u&c|f<<a&l,n.typeInfo)}InverseSqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);const r=n;return new v(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m){let s=0;return n.data.forEach(o=>{s+=o*o}),new v(Math.sqrt(s),this.getTypeInfo("f32"))}const r=n;return new v(Math.abs(r.value),n.typeInfo)}Log(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.log(s)),n.typeInfo);const r=n;return new v(Math.log(r.value),n.typeInfo)}Log2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.log2(s)),n.typeInfo);const r=n;return new v(Math.log2(r.value),n.typeInfo)}Max(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m)return new m(n.data.map((a,l)=>Math.max(a,r.data[l])),n.typeInfo);const s=n,o=r;return new v(Math.max(s.value,o.value),n.typeInfo)}Min(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m)return new m(n.data.map((a,l)=>Math.min(a,r.data[l])),n.typeInfo);const s=n,o=r;return new v(Math.min(s.value,o.value),n.typeInfo)}Mix(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof m&&r instanceof m&&s instanceof m)return new m(n.data.map((l,c)=>n.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),n.typeInfo);const o=r,a=s;return new v(n.value*(1-a.value)+o.value*a.value,n.typeInfo)}Modf(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m)return new m(n.data.map((o,a)=>o%r.data[a]),n.typeInfo);const s=r;return new v(n.value%s.value,n.typeInfo)}Normalize(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m){const r=this.Length(e,t).value;return new m(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m)return new m(n.data.map((a,l)=>Math.pow(a,r.data[l])),n.typeInfo);const s=n,o=r;return new v(Math.pow(s.value,o.value),n.typeInfo)}QuantizeToF16(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof m?new m(n.data.map(r=>r),n.typeInfo):new v(n.value,n.typeInfo)}Radians(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof m?new m(n.data.map(r=>r*Math.PI/180),n.typeInfo):new v(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof m&&r instanceof m){const s=this._dot(n.data,r.data);return new m(n.data.map((o,a)=>o-2*s*r.data[a]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof m&&r instanceof m&&s instanceof v){const o=this._dot(r.data,n.data);return new m(n.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]}),n.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 n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.round(s)),n.typeInfo);const r=n;return new v(Math.round(r.value),n.typeInfo)}Saturate(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);const r=n;return new v(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.sign(s)),n.typeInfo);const r=n;return new v(Math.sign(r.value),n.typeInfo)}Sin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.sin(s)),n.typeInfo);const r=n;return new v(Math.sin(r.value),n.typeInfo)}Sinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.sinh(s)),n.typeInfo);const r=n;return new v(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){const r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){const n=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 m&&n instanceof m&&r instanceof m)return new m(s.data.map((c,u)=>this._smoothstep(n.data[u],r.data[u],c)),s.typeInfo);const o=n,a=r,l=s;return new v(this._smoothstep(o.value,a.value,l.value),s.typeInfo)}Sqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.sqrt(s)),n.typeInfo);const r=n;return new v(Math.sqrt(r.value),n.typeInfo)}Step(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof m&&n instanceof m)return new m(r.data.map((o,a)=>o<n.data[a]?0:1),r.typeInfo);const s=n;return new v(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.tan(s)),n.typeInfo);const r=n;return new v(Math.tan(r.value),n.typeInfo)}Tanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.tanh(s)),n.typeInfo);const r=n;return new v(Math.tanh(r.value),n.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 n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof K))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;const r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){const s=n.data;return new K([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){const s=n.data;return new K([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){const s=n.data;return new K([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){const s=n.data;return new K([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){const s=n.data;return new K([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){const s=n.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(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){const s=n.data;return new K([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){const s=n.data;return new K([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){const s=n.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 ${n.typeInfo.name}`),null}Trunc(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof m)return new m(n.data.map(s=>Math.trunc(s)),n.typeInfo);const r=n;return new v(Math.trunc(r.value),n.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 n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof Je){const s=n.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 m(a,this.getTypeInfo("vec3u")):l==="2d"?new m(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 n=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 m)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof Je){const o=n.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 m(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 n=e.args[0];if(n instanceof Je){const r=n.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 n=e.args[0];if(n instanceof Je){const r=n.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 n=e.args[0];if(n instanceof Je){const r=n.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 n=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 m)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof Je){const a=n.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 n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.postfix,t);return l instanceof v&&a instanceof v&&(l.value=a.value),s.value instanceof ye&&s.value.setDataValue(this.exec,l,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof Se&&(n=n.right);const r=this.exec.getVariableName(n,t),s=t.getVariable(r);let o=e.args[1];const a=this.exec.evalExpression(o,t),l=s.value.getSubData(this.exec,n.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,n.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 ko={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},$e={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 F0{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new yt,this.reflection.updateAST(this.ast),this.context=(n=t==null?void 0:t.clone())!==null&&n!==void 0?n:new Io,this.builtins=new M0(this),this.typeInfo={bool:this.getTypeInfo(E.bool),i32:this.getTypeInfo(E.i32),u32:this.getTypeInfo(E.u32),f32:this.getTypeInfo(E.f32),f16:this.getTypeInfo(E.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,n;const r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof v)return r.value;if(r instanceof m||r instanceof K)return Array.from(r.data);if(r instanceof ye&&r.typeInfo instanceof Nt){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,n,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 m(t,u));const f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(const h in n)for(const d in n[h]){const _=n[h][d];s.variables.forEach(P=>{var I;const w=P.node;if(w!=null&&w.attributes){let M=null,k=null;for(const y of w.attributes)y.name==="binding"?M=y.value:y.name==="group"&&(k=y.value);if(d==M&&h==k){let y=!1;for(const R of f.resources)if(R.name===P.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(w.type),_.descriptor,(I=_.texture.view)!==null&&I!==void 0?I:null);P.value=R}else _.uniform!==void 0?P.value=new ye(_.uniform,this.getTypeInfo(w.type)):P.value=new ye(_,this.getTypeInfo(w.type))}}})}for(let h=0;h<c;++h)for(let d=0;d<l;++d)for(let _=0;_<a;++_)s.setVariable("@workgroup_id",new m([_,d,h],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(o,[_,d,h],s)}execStatement(e,t){if(e instanceof du)return this.evalExpression(e.value,t);if(e instanceof gu){if(e.condition){const n=this.evalExpression(e.condition,t);if(!(n instanceof v))throw new Error("Invalid break-if condition");if(!n.value)return null}return Oe._breakObj}if(e instanceof mu)return Oe._continueObj;if(e instanceof Zi)this._let(e,t);else if(e instanceof Ct)this._var(e,t);else if(e instanceof dr)this._const(e,t);else if(e instanceof Ki)this._function(e,t);else{if(e instanceof hu)return this._if(e,t);if(e instanceof fu)return this._switch(e,t);if(e instanceof au)return this._for(e,t);if(e instanceof ou)return this._while(e,t);if(e instanceof uu)return this._loop(e,t);if(e instanceof yo){const n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof cu)this._assign(e,t);else if(e instanceof lu)this._increment(e,t);else{if(e instanceof Pt)return null;if(e instanceof vo){const n=e.name;t.getVariable(n)===null&&t.setVariable(n,new v(0,this.getTypeInfo("u32")))}else if(e instanceof bo)this._call(e,t);else{if(e instanceof pu||e instanceof So)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 Ce?this._evalLiteral(e,t):e instanceof Je?this._evalVariable(e,t):e instanceof To?this._evalCall(e,t):e instanceof xt?this._evalCreate(e,t):e instanceof xu?this._evalConst(e,t):e instanceof yu?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 E){const r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(const n in e){const r=e[n],s=this.reflection.getOverrideInfo(n);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(n,new v(r,s.type)):s.type.name==="bool"?t.setVariable(n,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(n,new m(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){const r=[1,1,1];for(const u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){const f=n.getVariableValue(u.value[0]);r[0]=f instanceof v?f.value:parseInt(u.value[0])}if(u.value.length>1){const f=n.getVariableValue(u.value[1]);r[1]=f instanceof v?f.value:parseInt(u.value[1])}if(u.value.length>2){const f=n.getVariableValue(u.value[2]);r[2]=f instanceof v?f.value:parseInt(u.value[2])}}const s=this.getTypeInfo("vec3u"),o=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new m(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],P=[d+t[0]*r[0],h+t[1]*r[1],u+t[2]*r[2]];n.setVariable("@local_invocation_id",new m(_,s)),n.setVariable("@global_invocation_id",new m(P,s)),n.setVariable("@local_invocation_index",new v(f,o)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(const n of e.node.args)for(const r of n.attributes)if(r.name==="builtin"){const s=`@${r.value}`,o=t.getVariable(s);o!==void 0&&t.variables.set(n.name,o)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof Se;)e=e.right;return e instanceof Je?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(const n of e){if(n instanceof Array){const s=t.clone(),o=this._execStatements(n,s);if(o)return o;continue}const r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){const n=t.clone();n.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],n);n.setVariable(o.name,a,o)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){const n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof v?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof v?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof Je){const n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof Se){if(e.operator==="*"){const n=this._getVariableData(e.right,t);return n instanceof yi?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){const n=this._getVariableData(e.right,t);return new yi(n)}}return null}_assign(e,t){let n=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 m||l instanceof K){if(c instanceof v||c instanceof m||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 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 m||l instanceof K?c instanceof v||c instanceof m||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 m||l instanceof K)&&(c instanceof v||c instanceof m||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 yi))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=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&&(n=n.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}`);n=l.value}if(n instanceof yi&&(n=n.reference),n===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=n.getSubData(this,s,t);if(l instanceof m&&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 m&&o instanceof m){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(n instanceof ye&&n.setDataValue(this,l,s,t))}if(n instanceof ye)n.setDataValue(this,o,s,t);else if(s){if(!(n instanceof m||n instanceof K))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof xi){const l=this.evalExpression(s.index,t).value;if(n instanceof m){if(!(o instanceof v))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[l]=o.value}else{if(!(n 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 m))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{const u=n.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}`);n.data[2*c]=o.data[0],n.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}`);n.data[3*c]=o.data[0],n.data[3*c+1]=o.data[1],n.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}`);n.data[4*c]=o.data[0],n.data[4*c+1]=o.data[1],n.data[4*c+2]=o.data[2],n.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}`);n.data[2*c]=o.data[0],n.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}`);n.data[3*c]=o.data[0],n.data[3*c+1]=o.data[1],n.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}`);n.data[4*c]=o.data[0],n.data[4*c+1]=o.data[1],n.data[4*c+2]=o.data[2],n.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}`);n.data[2*c]=o.data[0],n.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}`);n.data[3*c]=o.data[0],n.data[3*c+1]=o.data[1],n.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}`);n.data[4*c]=o.data[0],n.data[4*c+1]=o.data[1],n.data[4*c+2]=o.data[2],n.data[4*c+3]=o.data[3]}}}}}else if(s instanceof Zt){const l=s.value;if(!(n instanceof m))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")n.data[0]=o.value;else if(l==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[1]=o.value}else if(l==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[2]=o.value}else if(l==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[3]=o.value}}else{if(!(o instanceof m))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")n.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}`);n.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}`);n.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}`);n.data[3]=o.data[c]}}}}}else n instanceof v&&o instanceof v?n.value=o.value:n instanceof m&&o instanceof m||n instanceof K&&o instanceof K?n.data.set(o.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`)}_function(e,t){const n=new Po(e);t.functions.set(e.name,n)}_const(e,t){let n=null;e.value!==null&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e)}_let(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Se||(n=n.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 xt(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Se||(n=n.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 Ji||e.type instanceof Pt||e.type instanceof T){const s=new xt(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();const n=this.evalExpression(e.condition,t);if(!(n instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(const s of e.cases)if(s instanceof Su)for(const o of s.selectors){if(o instanceof gr){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===n.value)return this._execStatements(s.body,t)}else s instanceof Tu&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();const n=this.evalExpression(e.condition,t);if(!(n instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.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 n=this._execStatements(e.body,t);if(n===Oe._breakObj)break;if(n!==null&&n!==Oe._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){const n=this._execStatements(e.body,t);if(n===Oe._breakObj)break;if(n===Oe._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===Oe._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){const n=this._execStatements(e.body,t);if(n===Oe._breakObj)break;if(n!==Oe._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){const n=this.evalExpression(e.value,t),r=e.type;if(n instanceof v){const s=Iu(n.value,n.typeInfo.name,r.name);return new v(s,this.getTypeInfo(r))}if(n instanceof m){const s=n.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[_]=Iu(u[_],f,h);return d}(Array.from(n.data),o,l);return new m(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof xt){if(e.type===null)return wo.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 xt?e.type.name:e.name,s=e instanceof xt?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 Mt){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 Nt){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&&(((n=u.typeInfo)===null||n===void 0?void 0:n.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 xt?o.getSubData(this,e.postfix,t):o}_evalLiteral(e,t){const n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new v(e.scalarValue,n):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 n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){const r=Oe._priority.get(t.name);Oe._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){const n=this.evalExpression(e.right,t);if(e.operator==="&")return new yi(n);if(e.operator==="*")return n instanceof yi?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);const r=n instanceof v?n.value:n instanceof m?Array.from(n.data):null;switch(e.operator){case"+":{if(z(r)){const a=r.map((l,c)=>+l);return new m(a,n.typeInfo)}const s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(+s,o)}case"-":{if(z(r)){const a=r.map((l,c)=>-l);return new m(a,n.typeInfo)}const s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(-s,o)}case"!":{if(z(r)){const a=r.map((l,c)=>l?0:1);return new m(a,n.typeInfo)}const s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(s?0:1,o)}case"~":{if(z(r)){const a=r.map((l,c)=>~l);return new m(a,n.typeInfo)}const s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(~s,o)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){const n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof v?n.value:n instanceof m||n instanceof K?Array.from(n.data):null,o=r instanceof v?r.value:r instanceof m||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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h+u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u+h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h-u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u-h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new v(a-l,c)}case"*":{if(z(s)&&z(o)){const u=s,f=o;if(n instanceof K&&r instanceof K){const h=function(I,w,M,k){if($e[w.name]===void 0||$e[k.name]===void 0)return null;const y=$e[w.name][0],R=$e[w.name][1],B=$e[k.name][0];if(y!==$e[k.name][1])return null;const U=new Array(B*R);for(let W=0;W<R;W++)for(let q=0;q<B;q++){let Q=0;for(let O=0;O<y;O++)Q+=I[O*R+W]*M[q*y+O];U[W*B+q]=Q}return U}(u,n.typeInfo,f,r.typeInfo);if(h===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;const d=$e[r.typeInfo.name][0],_=$e[n.typeInfo.name][1],P=this.getTypeInfo(`mat${d}x${_}f`);return new K(h,P)}if(n instanceof K&&r instanceof m){const h=function(d,_,P,I){if($e[_.name]===void 0||ko[I.name]===void 0)return null;const w=$e[_.name][0],M=$e[_.name][1];if(w!==P.length)return null;const k=new Array(M);for(let y=0;y<M;y++){let R=0;for(let B=0;B<w;B++)R+=d[B*M+y]*P[B];k[y]=R}return k}(u,n.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new m(h,r.typeInfo)}if(n instanceof m&&r instanceof K){const h=function(d,_,P,I){if(ko[_.name]===void 0||$e[I.name]===void 0)return null;const w=$e[I.name][0],M=$e[I.name][1];if(M!==d.length)return null;const k=[];for(let y=0;y<w;y++){let R=0;for(let B=0;B<M;B++)R+=d[B]*P[B*w+y];k[y]=R}return k}(u,n.typeInfo,f,r.typeInfo);return h===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new m(h,n.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 m(h,n.typeInfo)}}if(z(s)){const u=o,f=s.map((h,d)=>h*u);return n instanceof K?new K(f,n.typeInfo):new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u*h);return r instanceof K?new K(f,r.typeInfo):new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h%u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u%h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h/u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u/h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h&u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u&h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h|u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u|h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h^u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u^h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h<<u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u<<h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(h,n.typeInfo)}if(z(s)){const u=o,f=s.map((h,d)=>h>>u);return new m(f,n.typeInfo)}if(z(o)){const u=s,f=o.map((h,d)=>u>>h);return new m(f,r.typeInfo)}const a=s,l=o,c=this._maxFormatTypeInfo([n.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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c==a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a==c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c!==a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a!==c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c>=a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a>=c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c<=a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a<=c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c&&a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a&&c?1:0);return new m(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 m(c,n.typeInfo)}if(z(s)){const a=o,l=s.map((c,u)=>c||a?1:0);return new m(l,n.typeInfo)}if(z(o)){const a=s,l=o.map((c,u)=>a||c?1:0);return new m(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 n=t.clone();n.currentFunctionName=e.name;const r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):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],n);n.createVariable(o.name,a,o)}return this._execStatements(r.node.body,n)}_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 n=t.getFunction(e.name);if(n){const r=t.clone();for(let s=0;s<n.node.args.length;++s){const o=n.node.args[s],a=this.evalExpression(e.args[s],r);r.setVariable(o.name,a,o)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new v(0,this.getTypeInfo(e.type));const n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){const n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=ko[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ce)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 m){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 m(a,n).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 m(o.length>s?o.slice(0,s):o,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=$e[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;const o=[];if(e instanceof Ce)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 m?o.push(...l.data):l instanceof v?o.push(l.value):l instanceof K&&o.push(...l.data)}if(n instanceof Kt&&n.format===null&&(n.format=this.getTypeInfo("f32")),o.length===0){const a=new Array(s[2]).fill(0);return new K(a,n).getSubData(this,e.postfix,t)}return o.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new K(o,n).getSubData(this,e.postfix,t)}}Oe._breakObj=new nt(new tt("BREAK",null),null),Oe._continueObj=new nt(new tt("CONTINUE",null),null),Oe._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class N0{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class O0{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new N0,this._exec=new Oe,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(const n of this._deferArrayCountEval){const r=n.arrayType,s=n.countNode;if(s instanceof Je){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 n of t)n.search(r=>{r instanceof Au||r instanceof pr?r.type=this._forwardType(r.type):r instanceof Ji?r.format=this._forwardType(r.format):r instanceof Ct||r instanceof Zi||r instanceof dr?r.type=this._forwardType(r.type):r instanceof Ki?r.returnType=this._forwardType(r.returnType):r instanceof wu&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof _u){const t=this._getType(e.name);if(t)return t}else e instanceof pr?e.type=this._forwardType(e.type):e instanceof Ji&&(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,n=e.length;t<n;++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 n=t.type;let r=!1;for(const s of e){if(n===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 n=p.tokens.name.rule.exec(t.lexeme);return n&&n.index==0&&n[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 n=[];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,n.push(this._updateNode(new wu(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 Ki(t,n,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 S0);else if(this._match(p.keywords.break)){const t=this._updateNode(new gu);if(this._currentLoop.length>0){const n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.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 mu);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.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 y0(t),e)}_while_statement(){if(!this._match(p.keywords.while))return null;const e=this._updateNode(new ou(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,n=this._compound_statement();return this._updateNode(new yo(n,e),t)}_for_statement(){if(!this._match(p.keywords.for))return null;this._consume(p.tokens.paren_left,"Expected '('.");const e=this._updateNode(new au(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 Ct(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 n=null;if(this._match(p.tokens.colon)){const s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for let.");const r=this._short_circuit_or_expression();return this._updateNode(new Zi(t,n,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 n=null;if(this._match(p.tokens.colon)){const s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(p.tokens.equal,"Expected '=' for const.");const r=this._short_circuit_or_expression();return n===null&&r instanceof Ce&&(n=r.type),this._updateNode(new dr(t,n,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 n=this._consume(p.increment_operators,"Expected increment operator");return this._updateNode(new lu(n.type===p.tokens.plus_plus?_i.increment:_i.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(p.tokens.brace_right))return null;let n=this._match(p.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;const r=this._consume(p.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new cu(Qi.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(p.tokens.ident))return null;const e=this._currentLine,t=this._current,n=this._consume(p.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new bo(n.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 uu([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof yo){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 fu(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 n=this._case_selectors();for(const s of n)if(s instanceof gr){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 Su(n,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 n=this._case_body();this._consume(p.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Tu(n)))}}return e}_case_selectors(){const e=[];for(this._match(p.keywords.default)?e.push(this._updateNode(new gr)):e.push(this._shift_expression());this._match(p.tokens.comma);)this._match(p.keywords.default)?e.push(this._updateNode(new gr)):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 n=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 hu(t,n,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(),n=this._compound_statement();return e.push(this._updateNode(new T0(t,n))),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 du(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 xi(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(p.tokens.period)){const e=this._consume(p.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new Zt(e.lexeme));return t&&(n.postfix=t),n}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 E.void;case"bool":return E.bool;case"i32":return E.i32;case"u32":return E.u32;case"f32":return E.f32;case"f16":return E.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 n=this._previous().toString();if(this._check(p.tokens.paren_left)){const r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new xt(s,r)):this._updateNode(new To(n,r))}if(this._context.constants.has(n)){const r=this._context.constants.get(n);return this._updateNode(new xu(n,r.value))}return this._updateNode(new Je(n))}if(this._match(p.tokens.int_literal)){const n=this._previous().toString();let r=n.endsWith("i")||n.endsWith("i")?E.i32:n.endsWith("u")||n.endsWith("U")?E.u32:E.x32;const s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new Ce(new v(s,this._exec.getTypeInfo(r)),r))}if(this._match(p.tokens.uint_literal)){const n=parseInt(this._previous().toString());return this._validateTypeRange(n,E.u32),this._updateNode(new Ce(new v(n,this._exec.getTypeInfo(E.u32)),E.u32))}if(this._match([p.tokens.decimal_float_literal,p.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));const s=parseFloat(n);this._validateTypeRange(s,r?E.f16:E.f32);const o=r?E.f16:E.f32;return this._updateNode(new Ce(new v(s,this._exec.getTypeInfo(o)),o))}if(this._match([p.keywords.true,p.keywords.false])){let n=this._previous().toString()===p.keywords.true.rule;return this._updateNode(new Ce(new v(n?1:0,this._exec.getTypeInfo(E.bool)),E.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 n=this._type_decl();this._consume(p.tokens.greater_than,"Expected '>'.");const r=this._paren_expression();return this._updateNode(new yu(n,r))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new xt(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 n=[];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."),n.push(this._updateNode(new Au(a,c,o)))}this._consume(p.tokens.brace_right,"Expected '}' after struct body.");const r=this._currentLine,s=this._updateNode(new Pt(t,n,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 Ce){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 Ce&&(e.type=e.value.type.name==="x32"?E.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"),n=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=[E.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 Kt&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?l[0].format=E.f16:c.typeInfo.format.name==="f32"?l[0].format=E.f32:c.typeInfo.format.name==="i32"?l[0].format=E.i32:c.typeInfo.format.name==="u32"?l[0].format=E.u32:c.typeInfo.format.name==="bool"?l[0].format=E.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new Ce(c,l[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=o}if(r!==null&&s instanceof Ce){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 Ce&&(r=(e=s==null?void 0:s.type)!==null&&e!==void 0?e:E.f32,r===E.x32&&(r=E.i32));const a=this._updateNode(new dr(t.toString(),r,"","",s),n);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 n=null;if(this._match(p.tokens.colon)){const s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(p.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof Ce){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof Ce&&(n=r.type.name==="x32"?E.i32:r.type);return r instanceof Ce&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new Zi(t.toString(),n,"","",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="",n="";this._match(p.tokens.less_than)&&(t=this._consume(p.storage_class,"Expected storage_class.").toString(),this._match(p.tokens.comma)&&(n=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 Ct(r.toString(),s,t,n,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 n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new vo(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 pu(e.toString(),t))}_enable_directive(){const e=this._consume(p.tokens.ident,"identity expected.");return this._updateNode(new v0(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 b0(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 n=this._updateNode(new So(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([p.tokens.ident,...p.texel_format,p.keywords.bool,p.keywords.f32,p.keywords.i32,p.keywords.u32])){const n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){const r=this._updateNode(new _u(n));return this._forwardTypeCount++,r}return this._updateNode(new E(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(p.template_types)){let n=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(n,r,s))}if(this._match(p.keywords.ptr)){let n=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 pr(n,r.toString(),s,o))}const t=this._attribute();if(this._match(p.keywords.array)){let n=null,r=-1;const s=this._previous();let o=null;if(this._match(p.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.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 Ji(s.toString(),t,n,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 Gi(this._previous().toString(),null,null));if(this._match(p.depth_texture_type))return this._updateNode(new Gi(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 Gi(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 n=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 Gi(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(p.tokens.attr);){const t=this._consume(p.attribute_name,"Expected attribute name"),n=this._updateNode(new Cu(t.toString(),null));if(this._match(p.tokens.paren_left)){if(n.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();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(p.tokens.comma))}this._consume(p.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}}class B0 extends yt{constructor(e){super(),e&&this.update(e)}update(e){const t=new O0().parse(e);this.updateAST(t)}}function U0(i){var s;const e={attributes:[],bindings:[]};let t;try{t=z0(i)}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:ku(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 n=t.entry.vertex[0],r=(n==null?void 0:n.inputs.length)||0;for(let o=0;o<r;o++){const a=n.inputs[o];if(a.locationType==="location"){const l=ku(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:l})}}return e}function ku(i){return i!=null&&i.format?`${i.name}<${i.format.name}>`:i.name}function z0(i){try{return new B0(i)}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 Ro={};function vr(i="id"){Ro[i]=Ro[i]||1;const e=Ro[i]++;return`${i}-${e}`}class Ru{constructor(e){g(this,"id");g(this,"userData",{});g(this,"topology");g(this,"bufferLayout",[]);g(this,"vertexCount");g(this,"indices");g(this,"attributes");if(this.id=e.id||vr("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&H.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 L0(i,e){if(e instanceof Ru)return e;const t=V0(i,e),{attributes:n,bufferLayout:r}=W0(i,e);return new Ru({topology:e.topology||"triangle-list",bufferLayout:r,vertexCount:e.vertexCount,indices:t,attributes:n})}function V0(i,e){if(!e.indices)return;const t=e.indices.value;return i.createBuffer({usage:H.INDEX,data:t})}function W0(i,e){const t=[],n={};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){n[a]=i.createBuffer({data:o.value,id:`${s}-buffer`});const{value:l,size:c,normalized:u}=o;t.push({name:a,format:sg(l,c,u)})}}const r=e._calculateVertexCount(e.attributes,e.indices);return{attributes:n,bufferLayout:t,vertexCount:r}}const Br=class Br{constructor(e){g(this,"device");g(this,"cachingEnabled");g(this,"destroyPolicy");g(this,"debug");g(this,"_hashCounter",0);g(this,"_hashes",{});g(this,"_renderPipelineCache",{});g(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 Br(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={...Xt.defaultProps,...e},n=this._renderPipelineCache,r=this._hashRenderPipeline(t);let s=(o=n[r])==null?void 0:o.pipeline;return s?(n[r].useCount++,this.debug&&D.log(3,`${this}: ${n[r].pipeline} reused, count=${n[r].useCount}, (id=${e.id})`)()):(s=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:vr("unnamed-cached")}),s.hash=r,n[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${n[r].useCount}`)()),s}createComputePipeline(e){var o;if(!this.cachingEnabled)return this.device.createComputePipeline(e);const t={...zn.defaultProps,...e},n=this._computePipelineCache,r=this._hashComputePipeline(t);let s=(o=n[r])==null?void 0:o.pipeline;return s?(n[r].useCount++,this.debug&&D.log(3,`${this}: ${n[r].pipeline} reused, count=${n[r].useCount}, (id=${e.id})`)()):(s=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),s.hash=r,n[r]={pipeline:s,useCount:1},this.debug&&D.log(3,`${this}: ${s} created, count=${n[r].useCount}`)()),s}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._getCache(e),n=e.hash;t[n].useCount--,t[n].useCount===0?(this._destroyPipeline(e),this.debug&&D.log(3,`${this}: ${e} released and destroyed`)()):t[n].useCount<0?(D.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[n].useCount=0):this.debug&&D.log(3,`${this}: ${e} released, count=${t[n].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 zn&&(t=this._computePipelineCache),e instanceof Xt&&(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,n=this._getHash(e.shader.source);return`${t}/C/${n}`}_hashRenderPipeline(e){const t=e.vs?this._getHash(e.vs.source):0,n=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}/${n}V${r}BL${s}`;case"webgpu":default:const a=this._getHash(JSON.stringify(e.parameters));return`${o}/R/${t}/${n}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]}};g(Br,"defaultProps",{...Xt.defaultProps});let Eo=Br;const Ur=class Ur{constructor(e){g(this,"device");g(this,"cachingEnabled");g(this,"destroyPolicy");g(this,"debug");g(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 Ur(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 n=this._cache[t];if(n)n.useCount++,this.debug&&D.log(3,`${this}: Reusing shader ${n.shader.id} count=${n.useCount}`)();else{const r=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=n={shader:r,useCount:1},this.debug&&D.log(3,`${this}: Created new shader ${r.id}`)()}return n.shader}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._hashShader(e),n=this._cache[t];if(n)if(n.useCount--,n.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[t],n.shader.destroy(),this.debug&&D.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(n.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.debug&&D.log(3,`${this}: Releasing shader ${e.id} count=${n.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}};g(Ur,"defaultProps",{...Bn.defaultProps});let Do=Ur;function H0(i,e){var r;const t={},n="Values";if(i.attributes.length===0&&!((r=i.varyings)!=null&&r.length))return{"No attributes or varyings":{[n]:"N/A"}};for(const s of i.attributes)if(s){const o=`${s.location} ${s.name}: ${s.type}`;t[`in ${o}`]={[n]:s.stepMode||"vertex"}}for(const s of i.varyings||[]){const o=`${s.location} ${s.name}`;t[`out ${o}`]={[n]:JSON.stringify(s)}}return t}let Re=null,Qt=null;function $0(i,{id:e,minimap:t,opaque:n,top:r="0",left:s="0",rgbaScale:o=1}){Re||(Re=document.createElement("canvas"),Re.id=e,Re.title=e,Re.style.zIndex="100",Re.style.position="absolute",Re.style.top=r,Re.style.left=s,Re.style.border="blue 5px solid",Re.style.transform="scaleY(-1)",document.body.appendChild(Re),Qt=Re.getContext("2d")),(Re.width!==i.width||Re.height!==i.height)&&(Re.width=i.width/2,Re.height=i.height/2,Re.style.width="400px",Re.style.height="400px");const a=i.device.readPixelsToArrayWebGL(i),l=Qt==null?void 0:Qt.createImageData(i.width,i.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]=n?255:a[u+3]*o;Qt==null||Qt.putImageData(l,0,0)}}function Fo(i,e,t){if(i===e)return!0;if(!t||!i||!e)return!1;if(Array.isArray(i)){if(!Array.isArray(e)||i.length!==e.length)return!1;for(let n=0;n<i.length;n++)if(!Fo(i[n],e[n],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof i=="object"&&typeof e=="object"){const n=Object.keys(i),r=Object.keys(e);if(n.length!==r.length)return!1;for(const s of n)if(!e.hasOwnProperty(s)||!Fo(i[s],e[s],t-1))return!1;return!0}return!1}class Mo{constructor(e){g(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(n=>n.attribute):[e.name]}mergeBufferLayouts(e,t){const n=[...e];for(const r of t){const s=n.findIndex(o=>o.name===r.name);s<0?n.push(r):n[s]=r}return n}getBufferIndex(e){const t=this.bufferLayouts.findIndex(n=>n.name===e);return t===-1&&D.warn(`BufferLayout: Missing buffer for "${e}".`)(),t}}function X0(i,e){const t=Object.fromEntries(i.attributes.map(r=>[r.name,r.location])),n=e.slice();return n.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}),n}function Y0(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function q0(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function j0(i){return Y0(i)||q0(i)}function K0(i){return j0(i)||typeof i=="number"||typeof i=="boolean"}function Z0(i){const e={bindings:{},uniforms:{}};return Object.keys(i).forEach(t=>{const n=i[t];K0(n)?e.uniforms[t]=n:e.bindings[t]=n}),e}class Q0{constructor(e,t){g(this,"options",{disableWarnings:!1});g(this,"modules");g(this,"moduleUniforms");g(this,"moduleBindings");Object.assign(this.options,t);const n=ho(Object.values(e).filter(r=>r.dependencies));for(const r of n)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 n of Object.keys(e)){const r=n,s=e[r]||{},o=this.modules[r];if(!o){this.options.disableWarnings||D.warn(`Module ${n} 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}=Z0(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[n,r]of Object.entries(this.moduleUniforms))for(const[s,o]of Object.entries(r))e[`${n}.${s}`]={type:(t=this.modules[n].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 J0="";async function G0(i,e){const t=new Image;return t.crossOrigin="anonymous",t.src=i.startsWith("http")?i:J0+i,await t.decode(),e?await createImageBitmap(t,e):await createImageBitmap(t)}const ev=["+X","-X","+Y","-Y","+Z","-Z"],tv=["+X","-X","+Y","-Y","+Z","-Z"],zr=class zr{constructor(e,t){g(this,"device");g(this,"id");g(this,"props");g(this,"texture");g(this,"sampler");g(this,"view");g(this,"ready");g(this,"isReady",!1);g(this,"destroyed",!1);g(this,"resolveReady",()=>{});g(this,"rejectReady",()=>{});this.device=e;const n=vr("async-texture");this.props={...zr.defaultProps,id:n,...t},this.id=this.props.id,t={...t},typeof(t==null?void 0:t.data)=="string"&&t.dimension==="2d"&&(t.data=G0(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,n=await Eu(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(n);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,n);break;case"2d":this._setTexture2DData(n);break;case"3d":this._setTexture3DData(this.texture,n);break;case"2d-array":this._setTextureArrayData(this.texture,n);break;case"cube":this._setTextureCubeData(this.texture,n);break;case"cube-array":this._setTextureCubeArrayData(this.texture,n);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 ui?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 n=Object.values(e)[0];return{width:n.width,height:n.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 n=this._normalizeTextureData(e);n.length>1&&this.props.mipmaps!==!1&&D.warn(`Texture ${this.id} mipmap and multiple LODs.`)();for(let r=0;r<n.length;r++){const s=n[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 n;if(((n=this.texture)==null?void 0:n.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 n;if(((n=this.texture)==null?void 0:n.props.dimension)!=="cube")throw new Error(this.id);for(const[r,s]of Object.entries(t)){const o=tv.indexOf(r);this._setTexture2DData(s,o)}}_setTextureArrayData(e,t){var n;if(((n=this.texture)==null?void 0:n.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,n,r=0){Array.isArray(t)&&t.length>1&&this.props.mipmaps!==!1&&D.warn(`${this.id} has mipmap and multiple LODs.`)();const s=ev.indexOf(n);this._setTexture2DData(t,s)}_normalizeTextureData(e){const t=this.texture;let n;return ArrayBuffer.isView(e)?n=[{data:e,width:t.width,height:t.height}]:Array.isArray(e)?n=e:n=[e],n}};g(zr,"defaultProps",{...X.defaultProps,data:null,mipmaps:!1});let en=zr;async function Eu(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(Eu));if(i&&typeof i=="object"&&i.constructor===Object){const e=i,t=await Promise.all(Object.values(e)),n=Object.keys(e),r={};for(let s=0;s<n.length;s++)r[n[s]]=t[s];return r}return i}const Jt=2,iv=1e4,Lr=class Lr{constructor(e,t){g(this,"device");g(this,"id");g(this,"source");g(this,"vs");g(this,"fs");g(this,"pipelineFactory");g(this,"shaderFactory");g(this,"userData",{});g(this,"parameters");g(this,"topology");g(this,"bufferLayout");g(this,"isInstanced");g(this,"instanceCount",0);g(this,"vertexCount");g(this,"indexBuffer",null);g(this,"bufferAttributes",{});g(this,"constantAttributes",{});g(this,"bindings",{});g(this,"vertexArray");g(this,"transformFeedback",null);g(this,"pipeline");g(this,"shaderInputs");g(this,"_uniformStore");g(this,"_attributeInfos",{});g(this,"_gpuGeometry",null);g(this,"props");g(this,"_pipelineNeedsUpdate","newly created");g(this,"_needsRedraw","initializing");g(this,"_destroyed",!1);g(this,"_lastDrawTimestamp",-1);g(this,"_lastLogTime",0);g(this,"_logOpen",!1);g(this,"_drawCount",0);var l,c,u,f;this.props={...Lr.defaultProps,...t},t=this.props,this.id=t.id||vr("model"),this.device=e,Object.assign(this.userData,t.userData);const n=Object.fromEntries(((l=this.props.modules)==null?void 0:l.map(h=>[h.name,h]))||[]),r=t.shaderInputs||new Q0(n,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);const s=rv(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=U0(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||Eo.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||Do.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(Jt,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;try{e.pushDebugGroup(`${this}.predraw(${e})`),this.predraw()}finally{e.popDebugGroup()}let n;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;n=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),n?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",n}setGeometry(e){var n;(n=this._gpuGeometry)==null||n.destroy();const t=e&&L0(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");const r=new Mo(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 Mo(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){Fo(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 pe(this.shaderInputs.modules);for(const[t,n]of Object.entries(this.shaderInputs.modules))if(nv(n)){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 n=(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=X0(this.pipeline.shaderLayout,this.bufferLayout);const r=new Mo(this.bufferLayout);for(const[s,o]of Object.entries(e)){const a=r.getBufferLayout(s);if(!a){n||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&&!n&&D.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${s}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(const[n,r]of Object.entries(e)){const s=this._attributeInfos[n];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 "${n}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(const e of Object.values(this.bindings))if(e instanceof en&&!e.isReady)return e.id;return!1}_getBindings(){const e={};for(const[t,n]of Object.entries(this.bindings))n instanceof en?n.isReady&&(e[t]=n.texture):e[t]=n;return e}_getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof On?e=Math.max(e,t.texture.updateTimestamp):t instanceof H||t instanceof X?e=Math.max(e,t.updateTimestamp):t instanceof en?e=t.texture?Math.max(e,t.texture.updateTimestamp):1/0:t instanceof ui||(e=Math.max(e,t.buffer.updateTimestamp));return e}_setGeometryAttributes(e){const t={...e.attributes};for(const[n]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(r=>r.name===n)&&n!=="positions"&&delete t[n];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 n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders});let r=null;this.source?r=n: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:n,fs:r}),this._attributeInfos=fl(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:iv;D.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,D.group(Jt,`>>> DRAWING MODEL ${this.id}`,{collapsed:D.level<=2})())}_logDrawCallEnd(){if(this._logOpen){const e=H0(this.pipeline.shaderLayout,this.id);D.table(Jt,e)();const t=this.shaderInputs.getDebugTable();D.table(Jt,t)();const n=this._getAttributeDebugTable();D.table(Jt,this._attributeInfos)(),D.table(Jt,n)(),D.groupEnd(Jt)(),this._logOpen=!1}}_logFramebuffer(e){const t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;const n=e.props.framebuffer;n&&$0(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){const e={};for(const[t,n]of Object.entries(this._attributeInfos)){const r=this.vertexArray.attributes[n.location];e[n.location]={name:t,type:n.shaderType,values:r?this._getBufferOrConstantValues(r,n.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){const{indexBuffer:t}=this.vertexArray,n=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:n.toString()}}return e}_getBufferOrConstantValues(e,t){const n=il(t);return(e instanceof H?new n(e.debugData):e).toString()}};g(Lr,"defaultProps",{...Xt.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:go.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});let de=Lr;function nv(i){return!!(i.uniformTypes&&!sv(i.uniformTypes))}function rv(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}function sv(i){for(const e in i)return!1;return!0}class Bt{constructor(e,t,n,r,s){this._debugRandomNumber=Math.floor(Math.random()*1e3),this.device=e,this.config=t,this.store=n,this.data=r,s&&(this.points=s)}}const ov=`#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
- }`,B0=`#version 300 es
104
+ }`,av=`#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
- `,U0=`#version 300 es
130
+ `,lv=`#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 te(n,e){const t=Ht.getInfo(n);return e*(t.bytesPerPixel??0)}const nt=`#version 300 es
166
+ }`;function br(i){const e=new Float32Array(i*i*2);for(let t=0;t<i;t++)for(let n=0;n<i;n++){const r=t*i*2+n*2;e[r+0]=n,e[r+1]=t}return e}function Sr(i,e,t,n,r,s){const o=r?r.length/s:0,a=e.length/s;if(o===a&&t&&!t.destroyed&&n&&!n.destroyed){const f=n,h=t;return h.write(e),{source:f,target:h,previous:new Float32Array(e)}}const c=new Float32Array(e.length),u=Math.min(o,a);for(let f=0;f<u*s;f+=1)c[f]=(r==null?void 0:r[f])??e[f]??0;for(let f=u*s;f<e.length;f+=1)c[f]=e[f]??0;return t&&!t.destroyed&&t.destroy(),n&&!n.destroyed&&n.destroy(),{source:i.createBuffer({data:c,usage:H.VERTEX|H.COPY_DST}),target:i.createBuffer({data:e,usage:H.VERTEX|H.COPY_DST}),previous:new Float32Array(e)}}function ie(i,e){const t=Ht.getInfo(i);return e*(t.bytesPerPixel??0)}const Ge=`#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 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
179
+ `;class Du extends Bt{create(){var r;const{device:e,store:t}=this,{pointsTextureSize:n}=t;if(n){if(this.centermassTexture||(this.centermassTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:X.SAMPLE|X.RENDER|X.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=br(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:s,usage:H.VERTEX|H.COPY_DST}),(r=this.calculateCentermassCommand)==null||r.setAttributes({pointIndices:this.pointIndices})}this.previousPointsTextureSize=n}}initPrograms(){const{device:e,store:t,points:n}=this;!n||!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 pe({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32"}}})),this.forceUniformStore||(this.forceUniformStore=new pe({forceCenterUniforms:{uniformTypes:{centerForce:"f32",alpha:"f32"}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new de(e,{fs:ov,vs:av,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 de(e,{fs:lv,vs:Ge,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:n}=this;if(!n||!this.calculateCentermassCommand||!this.calculateUniformStore||!this.runCommand||!this.forceUniformStore||!this.centermassFbo||!this.centermassTexture||!n.previousPositionTexture||n.previousPositionTexture.destroyed||!n.velocityFbo||n.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:n.previousPositionTexture}),this.calculateCentermassCommand.draw(r),r.end(),this.forceUniformStore.setUniforms({forceCenterUniforms:{centerForce:this.config.simulationCenter,alpha:t.alpha}}),this.runCommand.setBindings({positionsTexture:n.previousPositionTexture,centermassTexture:this.centermassTexture});const s=e.beginRenderPass({framebuffer:n.velocityFbo,clearColor:[0,0,0,0]});this.runCommand.draw(s),s.end()}destroy(){var e,t,n,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,(n=this.calculateUniformStore)==null||n.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 cv=`#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 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
218
+ }`;class Fu extends Bt{initPrograms(){const{device:e,points:t,store:n}=this;!t||!n.pointsTextureSize||(this.vertexCoordBuffer||(this.vertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.uniformStore||(this.uniformStore=new pe({forceGravityUniforms:{uniformTypes:{gravity:"f32",spaceSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new de(e,{fs:cv,vs:Ge,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:n}=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:n.adjustedSpaceSize,alpha:n.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 uv(i){return`#version 300 es
219
219
  precision highp float;
220
220
 
221
221
  uniform sampler2D positionsTexture;
@@ -252,7 +252,7 @@ uniform float alpha;
252
252
  in vec2 textureCoords;
253
253
  out vec4 fragColor;
254
254
 
255
- const float MAX_LINKS = ${n}.0;
255
+ const float MAX_LINKS = ${i}.0;
256
256
 
257
257
  void main() {
258
258
  vec4 pointPosition = texture(positionsTexture, textureCoords);
@@ -301,7 +301,7 @@ void main() {
301
301
 
302
302
  fragColor = vec4(velocity.rg, 0.0, 0.0);
303
303
  }
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
304
+ `}function ne(i,e){return!i||i.length!==2?e:[i[0],i[1]]}function Pe(i,e){return!i||i.length!==4?e:[i[0],i[1],i[2],i[3]]}var No=(i=>(i.OUTGOING="outgoing",i.INCOMING="incoming",i))(No||{});class Tr extends Bt{constructor(){super(...arguments),this.linkFirstIndicesAndAmount=new Float32Array,this.indices=new Float32Array,this.maxPointDegree=0}create(e){var h;const{device:t,store:{pointsTextureSize:n,linksTextureSize:r},data:s}=this;if(!n||!r)return;this.linkFirstIndicesAndAmount=new Float32Array(n*n*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(([P,I])=>{var U,W,q;this.indices[c*4+0]=P%n,this.indices[c*4+1]=Math.floor(P/n);const w=((U=s.degree)==null?void 0:U[P])??0,M=((W=s.degree)==null?void 0:W[_])??0,k=w+M,y=k!==0?w/k:.5,R=Math.min(w,M);let B=((q=s.linkStrength)==null?void 0:q[I])??1/Math.max(R,1);B=Math.sqrt(B),o[c*4+0]=y,o[c*4+1]=B,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!==n||this.linkFirstIndicesAndAmountTexture.height!==n,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:n,height:n,format:"rgba32float",usage:X.SAMPLE|X.COPY_DST})),this.linkFirstIndicesAndAmountTexture.copyImageData({data:this.linkFirstIndicesAndAmount,bytesPerRow:ie("rgba32float",n),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:X.SAMPLE|X.COPY_DST}),this.biasAndStrengthTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:X.SAMPLE|X.COPY_DST}),this.randomDistanceTexture=t.createTexture({width:r,height:r,format:"rgba32float",usage:X.SAMPLE|X.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=n,this.previousLinksTextureSize=r}initPrograms(){const{device:e,store:t,points:n}=this;!n||!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 pe({forceLinkUniforms:{uniformTypes:{linkSpring:"f32",linkDistance:"f32",linkDistRandomVariationRange:"vec2<f32>",pointsTextureSize:"f32",linksTextureSize:"f32",alpha:"f32"}}})),this.runCommand||(this.runCommand=new de(e,{fs:uv(this.maxPointDegree),vs:Ge,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:n}=this;if(!n||!this.runCommand||!this.uniformStore||!n.previousPositionTexture||n.previousPositionTexture.destroyed||!this.linkFirstIndicesAndAmountTexture||!this.indicesTexture||!this.biasAndStrengthTexture||!this.randomDistanceTexture||!n.velocityFbo||n.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:n.previousPositionTexture,linkInfoTexture:this.linkFirstIndicesAndAmountTexture,linkIndicesTexture:this.indicesTexture,linkPropertiesTexture:this.biasAndStrengthTexture,linkRandomDistanceTexture:this.randomDistanceTexture});const r=e.beginRenderPass({framebuffer:n.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 fv=`#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
- }`,$0=`#version 300 es
312
+ }`,hv=`#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
- }`,X0=`#version 300 es
348
+ }`,dv=`#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
- }`,Y0=`#version 300 es
485
+ }`,pv=`#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 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
545
+ }`;class Mu extends Bt{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:X.SAMPLE|X.RENDER|X.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 n=t.pointsTextureSize*t.pointsTextureSize,r=new Float32Array(n*4);for(let a=0;a<n;++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:X.SAMPLE|X.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=br(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:a,usage:H.VERTEX|H.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:n,points:r}=this;!n.pointsNumber||!r||!t.pointsTextureSize||(this.calculateLevelsUniformStore||(this.calculateLevelsUniformStore=new pe({calculateLevelsUniforms:{uniformTypes:{pointsTextureSize:"f32",levelTextureSize:"f32",cellSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,levelTextureSize:0,cellSize:0}}})),this.calculateLevelsCommand||(this.calculateLevelsCommand=new de(e,{fs:fv,vs:hv,topology:"point-list",vertexCount:n.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 pe({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 de(e,{fs:dv,vs:Ge,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 pe({forceCenterUniforms:{uniformTypes:{levelTextureSize:"f32",alpha:"f32",repulsion:"f32"},defaultUniforms:{levelTextureSize:0,alpha:t.alpha,repulsion:this.config.simulationRepulsion}}})),this.forceFromItsOwnCentermassCommand||(this.forceFromItsOwnCentermassCommand=new de(e,{fs:pv,vs:Ge,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,n,r,s,o;(e=this.calculateLevelsCommand)==null||e.destroy(),this.calculateLevelsCommand=void 0,(t=this.forceCommand)==null||t.destroy(),this.forceCommand=void 0,(n=this.forceFromItsOwnCentermassCommand)==null||n.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:n,points:r}=this;if(r&&!(!this.calculateLevelsCommand||!this.calculateLevelsUniformStore)&&!(!r.previousPositionTexture||r.previousPositionTexture.destroyed)&&n.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(n.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:n}=this;if(!n||!this.forceCommand||!this.forceUniformStore||!this.forceFromItsOwnCentermassCommand||!this.forceCenterUniformStore||!n.previousPositionTexture||n.previousPositionTexture.destroyed||!this.randomValuesTexture||this.randomValuesTexture.destroyed||!n.velocityFbo||n.velocityFbo.destroyed)return;const r=e.beginRenderPass({framebuffer:n.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:n.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:n.previousPositionTexture,randomValues:this.randomValuesTexture,levelFbo:o.texture}),this.forceFromItsOwnCentermassCommand.draw(r))}r.end()}}const gv=`#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 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
579
+ }`;class Nu extends Bt{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 pe({forceMouseUniforms:{uniformTypes:{repulsion:"f32",mousePos:"vec2<f32>"}}})),this.runCommand||(this.runCommand=new de(e,{fs:gv,vs:Ge,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:n}=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(n.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 mv=`#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
- }`,Q0=`#version 300 es
590
+ }`,_v=`#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
- `,J0=`#version 300 es
628
+ `,xv=`#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 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">
682
+ }`;class yv extends Bt{constructor(){super(...arguments),this.cachedCentroidPositions=null}create(){var f,h;this.cachedCentroidPositions=null;const{device:e,store:t,data:n}=this,{pointsTextureSize:r}=t;if(n.pointsNumber===void 0||!n.pointClusters&&!n.clusterPositions)return;this.clusterCount=(n.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(n.clusterPositions)for(let d=0;d<this.clusterCount;++d)c[d*4+0]=n.clusterPositions[d*2+0]??-1,c[d*4+1]=n.clusterPositions[d*2+1]??-1;for(let d=0;d<n.pointsNumber;++d){const _=(f=n.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)),n.clusterStrength&&(u[d*4+0]=n.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:X.SAMPLE|X.RENDER|X.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:X.SAMPLE|X.RENDER|X.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:X.SAMPLE|X.RENDER|X.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:X.SAMPLE|X.RENDER|X.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=br(t.pointsTextureSize);this.pointIndices=e.createBuffer({data:d,usage:H.VERTEX|H.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:n}=this;n.pointsNumber===void 0||!n.pointClusters&&!n.clusterPositions||(this.calculateCentermassUniformStore||(this.calculateCentermassUniformStore=new pe({calculateCentermassUniforms:{uniformTypes:{pointsTextureSize:"f32",clustersTextureSize:"f32"},defaultUniforms:{pointsTextureSize:t.pointsTextureSize,clustersTextureSize:this.clustersTextureSize??0}}})),this.calculateCentermassCommand||(this.calculateCentermassCommand=new de(e,{fs:mv,vs:_v,topology:"point-list",vertexCount:n.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 pe({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 de(e,{fs:xv,vs:Ge,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 n=e.beginRenderPass({framebuffer:this.centermassFbo,clearColor:[0,0,0,0]});this.calculateCentermassCommand.draw(n),n.end()}getCentroidPositions(){var o;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this,n=!e||!t;if(n&&((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=He(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 n&&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,n,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,(n=this.calculateCentermassUniformStore)==null||n.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 vv=`<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>`,tv=`#gl-bench {
699
+ </div>`,bv=`#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 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=`
758
+ `;class Sv{constructor(e,t={}){this.css=bv,this.svg=vv,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 n,r=0,s,o=a=>{++r<20?n=requestAnimationFrame(o):(this.detected=Math.ceil(1e3*r/(a-s)/70),cancelAnimationFrame(n)),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,_,P,I,w,M,k)=>{h["gl-cpu"][d].style.strokeDasharray=(_*.27).toFixed(0)+" 100",h["gl-gpu"][d].style.strokeDasharray=(P*.27).toFixed(0)+" 100",h["gl-mem"][d].innerHTML=u[d]?u[d]:I?"mem: "+I.toFixed(0)+"mb":"",h["gl-fps"][d].innerHTML=w.toFixed(0)+" FPS",l(u[d],_,P,I,w,M,k)}})(this.paramLogger,this.dom,this.names),this.chartLogger=((l,c)=>{let u={"gl-chart":c.getElementsByClassName("gl-chart")};return(f,h,d)=>{let _="",P=h.length;for(let I=0;I<P;I++){let w=(d+I+1)%P;h[w]!=null&&(_=_+" "+(55*I/(P-1)).toFixed(1)+","+(45-h[w]*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 n=t-this.paramTime;if(n>=1e3){const r=this.frameId-this.paramFrame,s=r/n*1e3;for(let o=0;o<this.names.length;o++){const a=this.cpuAccums[o]/n*100,l=this.gpuAccums[o]/n*100,c=performance&&performance.memory?performance.memory.usedJSHeapSize/(1<<20):0;this.paramLogger(o,a,l,c,s,n,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 n=t-this.chartTime,r=this.chartHz*n/1e3;for(;--r>0&&this.detected;){const o=(this.frameId-this.chartFrame)/n*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 n=this.now(),r=n-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=n}}const Tv=`
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 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:`
810
+ `;class Ou{constructor(e){this.destroy();const t=e.getContext("webgl")||e.getContext("experimental-webgl");this.bench=new Sv(t,{css:Tv})}begin(){var e;(e=this.bench)==null||e.begin("frame")}end(e){var t,n;(t=this.bench)==null||t.end("frame"),(n=this.bench)==null||n.nextFrame(e)}destroy(){this.bench=void 0,Ae("#gl-bench").remove()}}const Bu={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
- `},rv=`#version 300 es
816
+ `},wv=`#version 300 es
817
817
  #ifdef GL_ES
818
818
  precision highp float;
819
819
  #endif
@@ -871,19 +871,21 @@ void main() {
871
871
  }
872
872
  } else fragColor = vec4(color, opacity);
873
873
 
874
- }`,sv=`#version 300 es
874
+ }`,Av=`#version 300 es
875
875
  #ifdef GL_ES
876
876
  precision highp float;
877
877
  #endif
878
878
 
879
879
  in vec2 position, pointA, pointB;
880
- in vec4 color;
881
- in float width;
880
+ in vec4 sourceColor;
881
+ in vec4 targetColor;
882
+ in float sourceWidth;
883
+ in float targetWidth;
882
884
  in float arrow;
883
885
  in float linkIndices;
884
886
 
885
887
  uniform sampler2D positionsTexture;
886
- uniform sampler2D pointGreyoutStatus;
888
+ uniform sampler2D linkStatus;
887
889
 
888
890
  #ifdef USE_UNIFORM_BUFFERS
889
891
  layout(std140) uniform drawLineUniforms {
@@ -906,6 +908,13 @@ layout(std140) uniform drawLineUniforms {
906
908
  float hoveredLinkIndex;
907
909
  vec4 hoveredLinkColor;
908
910
  float hoveredLinkWidthIncrease;
911
+ float isLinkHighlightingActive;
912
+ float linkStatusTextureSize;
913
+ float focusedLinkIndex;
914
+ float focusedLinkWidthIncrease;
915
+ float transitionProgress;
916
+ float animateColors;
917
+ float animateWidths;
909
918
  } drawLine;
910
919
 
911
920
  #define transformationMatrix drawLine.transformationMatrix
@@ -927,6 +936,13 @@ layout(std140) uniform drawLineUniforms {
927
936
  #define hoveredLinkIndex drawLine.hoveredLinkIndex
928
937
  #define hoveredLinkColor drawLine.hoveredLinkColor
929
938
  #define hoveredLinkWidthIncrease drawLine.hoveredLinkWidthIncrease
939
+ #define isLinkHighlightingActive drawLine.isLinkHighlightingActive
940
+ #define linkStatusTextureSize drawLine.linkStatusTextureSize
941
+ #define focusedLinkIndex drawLine.focusedLinkIndex
942
+ #define focusedLinkWidthIncrease drawLine.focusedLinkWidthIncrease
943
+ #define transitionProgress drawLine.transitionProgress
944
+ #define animateColors drawLine.animateColors
945
+ #define animateWidths drawLine.animateWidths
930
946
  #else
931
947
  uniform mat3 transformationMatrix;
932
948
  uniform float pointsTextureSize;
@@ -948,6 +964,13 @@ uniform float renderMode;
948
964
  uniform float hoveredLinkIndex;
949
965
  uniform vec4 hoveredLinkColor;
950
966
  uniform float hoveredLinkWidthIncrease;
967
+ uniform float isLinkHighlightingActive;
968
+ uniform float linkStatusTextureSize;
969
+ uniform float focusedLinkIndex;
970
+ uniform float focusedLinkWidthIncrease;
971
+ uniform float transitionProgress;
972
+ uniform float animateColors;
973
+ uniform float animateWidths;
951
974
  #endif
952
975
 
953
976
  out vec4 rgbaColor;
@@ -999,10 +1022,7 @@ void main() {
999
1022
 
1000
1023
  vec2 pointTexturePosA = (pointA + 0.5) / pointsTextureSize;
1001
1024
  vec2 pointTexturePosB = (pointB + 0.5) / pointsTextureSize;
1002
-
1003
- vec4 greyoutStatusA = texture(pointGreyoutStatus, pointTexturePosA);
1004
- vec4 greyoutStatusB = texture(pointGreyoutStatus, pointTexturePosB);
1005
-
1025
+
1006
1026
  vec4 pointPositionA = texture(positionsTexture, pointTexturePosA);
1007
1027
  vec4 pointPositionB = texture(positionsTexture, pointTexturePosB);
1008
1028
  vec2 a = pointPositionA.xy;
@@ -1019,9 +1039,16 @@ void main() {
1019
1039
 
1020
1040
  // Convert link distance to screen pixels
1021
1041
  float linkDistPx = linkDist * transformationMatrix[0][0];
1042
+
1043
+ float lineWidthBase = animateWidths > 0.0
1044
+ ? mix(sourceWidth, targetWidth, transitionProgress)
1045
+ : targetWidth;
1046
+ vec4 lineColor = animateColors > 0.0
1047
+ ? mix(sourceColor, targetColor, transitionProgress)
1048
+ : targetColor;
1022
1049
 
1023
1050
  // Calculate line width using the width scale
1024
- float linkWidth = width * widthScale;
1051
+ float linkWidth = lineWidthBase * widthScale;
1025
1052
  float k = 2.0;
1026
1053
  // Arrow width is proportionally larger than the line width
1027
1054
  float arrowWidth = linkWidth * k;
@@ -1051,11 +1078,22 @@ void main() {
1051
1078
  if (renderMode > 0.0) {
1052
1079
  // Add 5 pixels padding for better hover detection
1053
1080
  linkWidthPx += 5.0 / transformationMatrix[0][0];
1081
+ // Match the visible-pass width increases so the pickable area covers the full rendered link
1082
+ if (hoveredLinkIndex == linkIndex) {
1083
+ linkWidthPx += hoveredLinkWidthIncrease / transformationMatrix[0][0];
1084
+ }
1085
+ if (focusedLinkIndex == linkIndex) {
1086
+ linkWidthPx += focusedLinkWidthIncrease / transformationMatrix[0][0];
1087
+ }
1054
1088
  } else {
1055
- // Add pixel increase if this is the hovered link
1089
+ // Add pixel increase if this is the hovered link
1056
1090
  if (hoveredLinkIndex == linkIndex) {
1057
1091
  linkWidthPx += hoveredLinkWidthIncrease / transformationMatrix[0][0];
1058
1092
  }
1093
+ // Add pixel increase if this is the focused link
1094
+ if (focusedLinkIndex == linkIndex) {
1095
+ linkWidthPx += focusedLinkWidthIncrease / transformationMatrix[0][0];
1096
+ }
1059
1097
  }
1060
1098
  float smoothingPx = 0.5 / transformationMatrix[0][0];
1061
1099
  smoothing = smoothingPx / linkWidthPx;
@@ -1064,13 +1102,19 @@ void main() {
1064
1102
 
1065
1103
 
1066
1104
  // Calculate final color with opacity based on link distance
1067
- vec3 rgbColor = color.rgb;
1105
+ vec3 rgbColor = lineColor.rgb;
1068
1106
  // Adjust opacity based on link distance
1069
- float opacity = color.a * linkOpacity * max(linkVisibilityMinTransparency, map(linkDistPx, linkVisibilityDistanceRange.g, linkVisibilityDistanceRange.r, 0.0, 1.0));
1070
-
1071
- // Apply greyed out opacity if either endpoint is greyed out
1072
- if (greyoutStatusA.r > 0.0 || greyoutStatusB.r > 0.0) {
1073
- opacity *= greyoutOpacity;
1107
+ float opacity = lineColor.a * linkOpacity * max(linkVisibilityMinTransparency, map(linkDistPx, linkVisibilityDistanceRange.g, linkVisibilityDistanceRange.r, 0.0, 1.0));
1108
+
1109
+ // Apply greyed-out opacity from link status texture
1110
+ if (isLinkHighlightingActive > 0.0 && linkStatusTextureSize > 0.0) {
1111
+ float texX = mod(linkIndices, linkStatusTextureSize);
1112
+ float texY = floor(linkIndices / linkStatusTextureSize);
1113
+ vec2 linkStatusCoord = (vec2(texX, texY) + 0.5) / linkStatusTextureSize;
1114
+ vec4 linkStatusValue = texture(linkStatus, linkStatusCoord);
1115
+ if (linkStatusValue.r > 0.0) {
1116
+ opacity *= greyoutOpacity;
1117
+ }
1074
1118
  }
1075
1119
 
1076
1120
  // Pass final color to fragment shader
@@ -1112,7 +1156,7 @@ void main() {
1112
1156
  #endif
1113
1157
 
1114
1158
  gl_Position = vec4(final.rg, 0, 1);
1115
- }`,ov=`#version 300 es
1159
+ }`,Cv=`#version 300 es
1116
1160
  #ifdef GL_ES
1117
1161
  precision highp float;
1118
1162
  #endif
@@ -1124,7 +1168,7 @@ out vec4 fragColor;
1124
1168
  void main() {
1125
1169
  fragColor = rgba;
1126
1170
  }
1127
- `,av=`#version 300 es
1171
+ `,Pv=`#version 300 es
1128
1172
  #ifdef GL_ES
1129
1173
  precision highp float;
1130
1174
  #endif
@@ -1205,7 +1249,7 @@ void main() {
1205
1249
 
1206
1250
  gl_PointSize = 1.0;
1207
1251
  }
1208
- `,lv=`#version 300 es
1252
+ `,Iv=`#version 300 es
1209
1253
  #ifdef GL_ES
1210
1254
  precision highp float;
1211
1255
  #endif
@@ -1245,7 +1289,7 @@ void main() {
1245
1289
  // No link at this position, output -1 to indicate no hover
1246
1290
  fragColor = vec4(-1.0, 0.0, 0.0, 0.0);
1247
1291
  }
1248
- } `,cv=`#version 300 es
1292
+ } `,kv=`#version 300 es
1249
1293
  #ifdef GL_ES
1250
1294
  precision highp float;
1251
1295
  #endif
@@ -1254,7 +1298,7 @@ in vec2 vertexCoord;
1254
1298
 
1255
1299
  void main() {
1256
1300
  gl_Position = vec4(vertexCoord, 0.0, 1.0);
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
1301
+ } `,Rv=i=>{const e=mc().exponent(2).range([0,1]).domain([-1,1]),t=Tx(0,i).map(r=>-.5+r/i);t.push(.5);const n=new Array(t.length*2);return t.forEach((r,s)=>{n[s*2]=[e(r*2),.5],n[s*2+1]=[e(r*2),-.5]}),n};class Ev extends Bt{constructor(){super(...arguments),this.linkStatusTextureSize=0,this.transitionProgress=1,this.shouldAnimateLinkColors=!1,this.shouldAnimateLinkWidths=!1}initPrograms(){var o;const{device:e,config:t,store:n,data:r}=this;this.updateLinkIndexFbo(),this.hoveredLineIndexTexture||(this.hoveredLineIndexTexture=e.createTexture({width:1,height:1,format:"rgba32float",usage:X.SAMPLE|X.RENDER|X.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:H.VERTEX|H.COPY_DST})),this.pointBBuffer||(this.pointBBuffer=e.createBuffer({data:new Float32Array(s*2),usage:H.VERTEX|H.COPY_DST})),this.arrowBuffer||(this.arrowBuffer=e.createBuffer({data:new Float32Array(s),usage:H.VERTEX|H.COPY_DST})),this.linkIndexBuffer||(this.linkIndexBuffer=e.createBuffer({data:new Float32Array(s),usage:H.VERTEX|H.COPY_DST})),this.drawLineUniformStore||(this.drawLineUniformStore=new pe({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",isLinkHighlightingActive:"f32",linkStatusTextureSize:"f32",focusedLinkIndex:"f32",focusedLinkWidthIncrease:"f32",transitionProgress:"f32",animateColors:"f32",animateWidths:"f32"},defaultUniforms:{transformationMatrix:n.transformationMatrix4x4,pointsTextureSize:n.pointsTextureSize,widthScale:t.linkWidthScale,linkArrowsSizeScale:t.linkArrowsSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.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:n.maxPointSize,renderMode:0,hoveredLinkIndex:n.hoveredLinkIndex??-1,hoveredLinkColor:Pe(n.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease,isLinkHighlightingActive:0,linkStatusTextureSize:0,focusedLinkIndex:t.focusedLinkIndex??-1,focusedLinkWidthIncrease:t.focusedLinkWidthIncrease,transitionProgress:1,animateColors:0,animateWidths:0}},drawLineFragmentUniforms:{uniformTypes:{renderMode:"f32"},defaultUniforms:{renderMode:0}}})),this.drawCurveCommand||(this.drawCurveCommand=new de(e,{vs:Av,fs:wv,modules:[Bu],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.sourceColorBuffer&&{sourceColor:this.sourceColorBuffer},...this.targetColorBuffer&&{targetColor:this.targetColorBuffer},...this.sourceWidthBuffer&&{sourceWidth:this.sourceWidthBuffer},...this.targetWidthBuffer&&{targetWidth:this.targetWidthBuffer},...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:"sourceColor",format:"float32x4",stepMode:"instance"},{name:"targetColor",format:"float32x4",stepMode:"instance"},{name:"sourceWidth",format:"float32",stepMode:"instance"},{name:"targetWidth",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:H.VERTEX|H.COPY_DST})),this.hoveredLineIndexUniformStore||(this.hoveredLineIndexUniformStore=new pe({hoveredLineIndexUniforms:{uniformTypes:{mousePosition:"vec2<f32>",screenSize:"vec2<f32>"},defaultUniforms:{mousePosition:ne(n.screenMousePosition,[0,0]),screenSize:ne(n.screenSize,[0,0])}}})),this.hoveredLineIndexCommand||(this.hoveredLineIndexCommand=new de(e,{vs:kv,fs:Iv,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 pe({fillSampledLinksUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>",curvedWeight:"f32",curvedLinkControlPointDistance:"f32",curvedLinkSegments:"f32"},defaultUniforms:{pointsTextureSize:n.pointsTextureSize??0,transformationMatrix:n.transformationMatrix4x4,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),curvedWeight:t.curvedLinkWeight,curvedLinkControlPointDistance:t.curvedLinkControlPointDistance,curvedLinkSegments:t.curvedLinks?t.curvedLinkSegments:1}}})),this.fillSampledLinksFboCommand||(this.fillSampledLinksFboCommand=new de(e,{fs:Cv,vs:Pv,modules:[Bu],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(),this.updateLinkStatus()}draw(e){const{config:t,points:n,store:r}=this;if(!n||!n.currentPositionTexture||n.currentPositionTexture.destroyed||((!this.pointABuffer||!this.pointBBuffer)&&this.updatePointsBuffer(),this.targetColorBuffer||this.updateColor(),this.targetWidthBuffer||this.updateWidth(),this.arrowBuffer||this.updateArrow(),this.curveLineGeometry||this.updateCurveLineGeometry(),!this.drawCurveCommand||!this.drawLineUniformStore||!this.linkStatusTexture))return;const s=t.highlightedLinkIndices!==void 0;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:Pe(r.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:t.hoveredLinkWidthIncrease,isLinkHighlightingActive:s?1:0,linkStatusTextureSize:this.linkStatusTextureSize,focusedLinkIndex:t.focusedLinkIndex??-1,focusedLinkWidthIncrease:t.focusedLinkWidthIncrease,transitionProgress:this.transitionProgress,animateColors:this.shouldAnimateLinkColors?1:0,animateWidths:this.shouldAnimateLinkWidths?1:0},drawLineFragmentUniforms:{renderMode:0}}),this.drawCurveCommand.setBindings({positionsTexture:n.currentPositionTexture,linkStatus:this.linkStatusTexture}),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 n=t.screenSize??[0,0],r=n[0],s=n[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:X.SAMPLE|X.RENDER|X.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:n}=this;let r=t??Math.min(...e)/2;r===0&&(r=At.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=n.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}updatePointsBuffer(){var l;const{device:e,data:t,store:n}=this;if(t.linksNumber===void 0||t.links===void 0||!n.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%n.pointsTextureSize,d=Math.floor(u/n.pointsTextureSize),_=f%n.pointsTextureSize,P=Math.floor(f/n.pointsTextureSize);r[c*2]=h,r[c*2+1]=d,s[c*2]=_,s[c*2+1]=P}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:H.VERTEX|H.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:H.VERTEX|H.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:H.VERTEX|H.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(),this.config.highlightedLinkIndices!==void 0&&this.updateLinkStatus()}updateColor(){const{data:e}=this,t=e.linksNumber??0,n=e.linkColors??new Float32Array(t*4).fill(0),{source:r,target:s,previous:o}=Sr(this.device,n,this.sourceColorBuffer,this.targetColorBuffer,this.previousColorData,4);this.sourceColorBuffer=r,this.targetColorBuffer=s,this.previousColorData=o,this.drawCurveCommand&&this.drawCurveCommand.setAttributes({...this.sourceColorBuffer&&{sourceColor:this.sourceColorBuffer},...this.targetColorBuffer&&{targetColor:this.targetColorBuffer}})}updateWidth(){const{data:e}=this,t=e.linksNumber??0,n=e.linkWidths??new Float32Array(t).fill(0),{source:r,target:s,previous:o}=Sr(this.device,n,this.sourceWidthBuffer,this.targetWidthBuffer,this.previousWidthData,1);this.sourceWidthBuffer=r,this.targetWidthBuffer=s,this.previousWidthData=o,this.drawCurveCommand&&this.drawCurveCommand.setAttributes({...this.sourceWidthBuffer&&{sourceWidth:this.sourceWidthBuffer},...this.targetWidthBuffer&&{targetWidth:this.targetWidthBuffer}})}updateArrow(){const{device:e,data:t}=this,n=t.linksNumber??0,r=t.linkArrows?new Float32Array(t.linkArrows):new Float32Array(n).fill(0);this.arrowBuffer?(this.arrowBuffer.byteLength??0)/Float32Array.BYTES_PER_ELEMENT!==n?(this.arrowBuffer&&!this.arrowBuffer.destroyed&&this.arrowBuffer.destroy(),this.arrowBuffer=e.createBuffer({data:r,usage:H.VERTEX|H.COPY_DST})):this.arrowBuffer.write(r):this.arrowBuffer=e.createBuffer({data:r,usage:H.VERTEX|H.COPY_DST}),this.drawCurveCommand&&this.drawCurveCommand.setAttributes({arrow:this.arrowBuffer})}updateLinkStatus(){const{device:e,config:t,data:n}=this,r=n.linksNumber??0;if(!r){this.linkStatusTexture||this.ensureLinkStatusPlaceholder();return}const{highlightedLinkIndices:s}=t;if(s===void 0){this.linkStatusTexture||this.ensureLinkStatusPlaceholder(),this.linkStatusTextureSize=0;return}const o=Math.ceil(Math.sqrt(r));this.linkStatusTextureSize=o;const a=new Float32Array(o*o*4);for(let c=0;c<r;c++)a[c*4]=1;for(const c of s)c>=0&&c<r&&(a[c*4]=0);const l={data:a,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0};!this.linkStatusTexture||this.linkStatusTexture.width!==o||this.linkStatusTexture.height!==o?(this.linkStatusTexture&&!this.linkStatusTexture.destroyed&&this.linkStatusTexture.destroy(),this.linkStatusTexture=e.createTexture({width:o,height:o,format:"rgba32float",usage:X.SAMPLE|X.RENDER|X.COPY_DST}),this.linkStatusTexture.copyImageData(l)):this.linkStatusTexture.copyImageData(l)}updateCurveLineGeometry(){const{device:e,config:{curvedLinks:t,curvedLinkSegments:n}}=this;this.curveLineGeometry=Rv(t?n: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:H.VERTEX|H.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 n=He(this.device,this.sampledLinksFbo);for(let r=0;r<n.length/4;r++){const s=n[r*4],o=n[r*4+1],a=n[r*4+2],l=n[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=[],n=[];if(!this.sampledLinksFbo||this.sampledLinksFbo.destroyed)return{indices:e,positions:t,angles:n};const r=this.points;if(!(r!=null&&r.currentPositionTexture)||r.currentPositionTexture.destroyed)return{indices:e,positions:t,angles:n};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=He(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),n.push(u))}return{indices:e,positions:t,angles:n}}findHoveredLine(){const{config:e,points:t,store:n}=this;if(!t||!t.currentPositionTexture||t.currentPositionTexture.destroyed||!this.data.linksNumber||!this.store.isLinkHoveringEnabled||!this.linkIndexFbo||!this.drawCurveCommand||!this.drawLineUniformStore||!this.linkStatusTexture||!this.linkIndexTexture||this.linkIndexTexture.destroyed)return;const r=e.highlightedLinkIndices!==void 0;this.drawLineUniformStore.setUniforms({drawLineUniforms:{transformationMatrix:n.transformationMatrix4x4,pointsTextureSize:n.pointsTextureSize,widthScale:e.linkWidthScale,linkArrowsSizeScale:e.linkArrowsSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.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:n.maxPointSize,renderMode:1,hoveredLinkIndex:n.hoveredLinkIndex??-1,hoveredLinkColor:Pe(n.hoveredLinkColor,[-1,-1,-1,-1]),hoveredLinkWidthIncrease:e.hoveredLinkWidthIncrease,isLinkHighlightingActive:r?1:0,linkStatusTextureSize:this.linkStatusTextureSize,focusedLinkIndex:e.focusedLinkIndex??-1,focusedLinkWidthIncrease:e.focusedLinkWidthIncrease,transitionProgress:this.transitionProgress,animateColors:this.shouldAnimateLinkColors?1:0,animateWidths:this.shouldAnimateLinkWidths?1:0},drawLineFragmentUniforms:{renderMode:1}}),this.drawCurveCommand.setBindings({positionsTexture:t.currentPositionTexture,linkStatus:this.linkStatusTexture}),this.drawCurveCommand.setInstanceCount(this.data.linksNumber??0);const s=this.device.beginRenderPass({framebuffer:this.linkIndexFbo,clearColor:[0,0,0,0]});if(this.drawCurveCommand.draw(s),s.end(),this.hoveredLineIndexCommand&&this.hoveredLineIndexFbo&&this.hoveredLineIndexUniformStore){this.hoveredLineIndexUniformStore.setUniforms({hoveredLineIndexUniforms:{mousePosition:ne(n.screenMousePosition,[0,0]),screenSize:ne(n.screenSize,[0,0])}}),this.hoveredLineIndexCommand.setBindings({linkIndexTexture:this.linkIndexTexture});const o=this.device.beginRenderPass({framebuffer:this.hoveredLineIndexFbo});this.hoveredLineIndexCommand.draw(o),o.end()}}setTransitionProgress(e,t=!1,n=!1){this.transitionProgress=e,this.shouldAnimateLinkColors=t,this.shouldAnimateLinkWidths=n}destroy(){var e,t,n,r,s,o;(e=this.drawCurveCommand)==null||e.destroy(),this.drawCurveCommand=void 0,(t=this.hoveredLineIndexCommand)==null||t.destroy(),this.hoveredLineIndexCommand=void 0,(n=this.fillSampledLinksFboCommand)==null||n.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,this.linkStatusTexture&&!this.linkStatusTexture.destroyed&&this.linkStatusTexture.destroy(),this.linkStatusTexture=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.sourceColorBuffer&&!this.sourceColorBuffer.destroyed&&this.sourceColorBuffer.destroy(),this.sourceColorBuffer=void 0,this.targetColorBuffer&&!this.targetColorBuffer.destroyed&&this.targetColorBuffer.destroy(),this.targetColorBuffer=void 0,this.previousColorData=void 0,this.sourceWidthBuffer&&!this.sourceWidthBuffer.destroyed&&this.sourceWidthBuffer.destroy(),this.sourceWidthBuffer=void 0,this.targetWidthBuffer&&!this.targetWidthBuffer.destroyed&&this.targetWidthBuffer.destroy(),this.targetWidthBuffer=void 0,this.previousWidthData=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}ensureLinkStatusPlaceholder(){this.linkStatusTexture&&!this.linkStatusTexture.destroyed||(this.linkStatusTexture=this.device.createTexture({width:1,height:1,format:"rgba32float",usage:X.SAMPLE|X.RENDER|X.COPY_DST,data:new Float32Array(4).fill(0)}),this.linkStatusTextureSize=0)}}const Dv=`#version 300 es
1258
1302
  #ifdef GL_ES
1259
1303
  precision highp float;
1260
1304
  #endif
@@ -1267,22 +1311,29 @@ layout(std140) uniform drawFragmentUniforms {
1267
1311
  float pointOpacity;
1268
1312
  float isDarkenGreyout;
1269
1313
  vec4 backgroundColor;
1314
+ vec4 outlineColor;
1315
+ float outlineWidth;
1270
1316
  } drawFragment;
1271
1317
 
1272
1318
  #define greyoutOpacity drawFragment.greyoutOpacity
1273
1319
  #define pointOpacity drawFragment.pointOpacity
1274
1320
  #define isDarkenGreyout drawFragment.isDarkenGreyout
1275
1321
  #define backgroundColor drawFragment.backgroundColor
1322
+ #define outlineColor drawFragment.outlineColor
1323
+ #define outlineWidth drawFragment.outlineWidth
1276
1324
  #else
1277
1325
  uniform float greyoutOpacity;
1278
1326
  uniform float pointOpacity;
1279
1327
  uniform float isDarkenGreyout;
1280
1328
  uniform vec4 backgroundColor;
1329
+ uniform vec4 outlineColor;
1330
+ uniform float outlineWidth;
1281
1331
  #endif
1282
1332
 
1283
1333
 
1284
1334
  in float pointShape;
1285
1335
  in float isGreyedOut;
1336
+ in float isOutlined;
1286
1337
  in vec4 shapeColor;
1287
1338
  in vec4 imageAtlasUV;
1288
1339
  in float shapeSize;
@@ -1512,21 +1563,52 @@ void main() {
1512
1563
  mix(finalShapeColor.rgb, finalImageColor.rgb, finalImageColor.a),
1513
1564
  finalPointAlpha
1514
1565
  );
1566
+
1567
+ // Render outline ring around the point
1568
+ if (isOutlined > 0.0) {
1569
+ float r = length(pointCoord);
1570
+ const float ringSmoothing = 1.025;
1571
+ float rSafe = max(r, 1e-6);
1572
+ float wSafe = max(outlineWidth, 1e-6);
1573
+ float outerEdge = smoothstep(rSafe, rSafe * ringSmoothing, 1.0);
1574
+ float innerEdge = smoothstep(wSafe, wSafe * ringSmoothing, r);
1575
+ float ringAlpha = outerEdge * innerEdge;
1576
+
1577
+ // Grey out the ring color when the point is greyed
1578
+ vec3 ringColor = outlineColor.rgb;
1579
+ if (isGreyedOut > 0.0) {
1580
+ float blendFactor = 0.65;
1581
+ if (isDarkenGreyout > 0.0) {
1582
+ ringColor = mix(ringColor, vec3(0.2), blendFactor);
1583
+ } else {
1584
+ ringColor = mix(ringColor, max(backgroundColor.rgb, vec3(0.8)), blendFactor);
1585
+ }
1586
+ }
1587
+
1588
+ float ringOpacity = ringAlpha * outlineColor.a;
1589
+ // Composite ring on top of existing fragment
1590
+ fragColor = vec4(
1591
+ mix(fragColor.rgb, ringColor, ringOpacity),
1592
+ max(fragColor.a, ringOpacity)
1593
+ );
1594
+ }
1515
1595
  }
1516
- `,dv=`#version 300 es
1596
+ `,Fv=`#version 300 es
1517
1597
  #ifdef GL_ES
1518
1598
  precision highp float;
1519
1599
  #endif
1520
1600
 
1521
1601
  in vec2 pointIndices;
1522
- in float size;
1523
- in vec4 color;
1602
+ in float sourceSize;
1603
+ in float targetSize;
1604
+ in vec4 sourceColor;
1605
+ in vec4 targetColor;
1524
1606
  in float shape;
1525
1607
  in float imageIndex;
1526
1608
  in float imageSize;
1527
1609
 
1528
1610
  uniform sampler2D positionsTexture;
1529
- uniform sampler2D pointGreyoutStatus;
1611
+ uniform sampler2D pointStatus;
1530
1612
  uniform sampler2D imageAtlasCoords;
1531
1613
 
1532
1614
  #ifdef USE_UNIFORM_BUFFERS
@@ -1542,11 +1624,14 @@ layout(std140) uniform drawVertexUniforms {
1542
1624
  float scalePointsOnZoom;
1543
1625
  float maxPointSize;
1544
1626
  float isDarkenGreyout;
1545
- float skipSelected;
1546
- float skipUnselected;
1627
+ float skipHighlighted;
1628
+ float skipGreyed;
1547
1629
  float hasImages;
1548
1630
  float imageCount;
1549
1631
  float imageAtlasCoordsTextureSize;
1632
+ float transitionProgress;
1633
+ float animateColors;
1634
+ float animateSizes;
1550
1635
  } drawVertex;
1551
1636
 
1552
1637
  #define ratio drawVertex.ratio
@@ -1560,11 +1645,14 @@ layout(std140) uniform drawVertexUniforms {
1560
1645
  #define scalePointsOnZoom drawVertex.scalePointsOnZoom
1561
1646
  #define maxPointSize drawVertex.maxPointSize
1562
1647
  #define isDarkenGreyout drawVertex.isDarkenGreyout
1563
- #define skipSelected drawVertex.skipSelected
1564
- #define skipUnselected drawVertex.skipUnselected
1648
+ #define skipHighlighted drawVertex.skipHighlighted
1649
+ #define skipGreyed drawVertex.skipGreyed
1565
1650
  #define hasImages drawVertex.hasImages
1566
1651
  #define imageCount drawVertex.imageCount
1567
1652
  #define imageAtlasCoordsTextureSize drawVertex.imageAtlasCoordsTextureSize
1653
+ #define transitionProgress drawVertex.transitionProgress
1654
+ #define animateColors drawVertex.animateColors
1655
+ #define animateSizes drawVertex.animateSizes
1568
1656
  #else
1569
1657
  uniform float ratio;
1570
1658
  uniform mat3 transformationMatrix;
@@ -1577,15 +1665,19 @@ uniform vec4 backgroundColor;
1577
1665
  uniform float scalePointsOnZoom;
1578
1666
  uniform float maxPointSize;
1579
1667
  uniform float isDarkenGreyout;
1580
- uniform float skipSelected;
1581
- uniform float skipUnselected;
1668
+ uniform float skipHighlighted;
1669
+ uniform float skipGreyed;
1582
1670
  uniform float hasImages;
1583
1671
  uniform float imageCount;
1584
1672
  uniform float imageAtlasCoordsTextureSize;
1673
+ uniform float transitionProgress;
1674
+ uniform float animateColors;
1675
+ uniform float animateSizes;
1585
1676
  #endif
1586
1677
 
1587
1678
  out float pointShape;
1588
1679
  out float isGreyedOut;
1680
+ out float isOutlined;
1589
1681
  out vec4 shapeColor;
1590
1682
  out vec4 imageAtlasUV;
1591
1683
  out float shapeSize;
@@ -1595,7 +1687,7 @@ out float overallSize;
1595
1687
  float calculatePointSize(float size) {
1596
1688
  float pSize;
1597
1689
 
1598
- if (scalePointsOnZoom > 0.0) {
1690
+ if (scalePointsOnZoom > 0.0) {
1599
1691
  pSize = size * ratio * transformationMatrix[0][0];
1600
1692
  } else {
1601
1693
  pSize = size * ratio * min(5.0, max(1.0, transformationMatrix[0][0] * 0.01));
@@ -1604,24 +1696,27 @@ float calculatePointSize(float size) {
1604
1696
  return min(pSize, maxPointSize * ratio);
1605
1697
  }
1606
1698
 
1607
- void main() {
1608
- // Check greyout status for selective rendering
1609
- vec4 greyoutStatus = texture(pointGreyoutStatus, (pointIndices + 0.5) / pointsTextureSize);
1610
- isGreyedOut = greyoutStatus.r;
1611
- float isSelected = (greyoutStatus.r == 0.0) ? 1.0 : 0.0;
1612
-
1699
+ const float outlineRingScale = 1.3;
1700
+
1701
+ void main() {
1702
+ // Read point status texture: R = greyout, G = outlined
1703
+ vec4 status = texture(pointStatus, (pointIndices + 0.5) / pointsTextureSize);
1704
+ isGreyedOut = status.r;
1705
+ isOutlined = status.g;
1706
+ float isHighlighted = (status.r == 0.0) ? 1.0 : 0.0;
1707
+
1613
1708
  // Discard point based on rendering mode
1614
- if (skipSelected > 0.0 && isSelected > 0.0) {
1615
- gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Move off-screen
1709
+ if (skipHighlighted > 0.0 && isHighlighted > 0.0) {
1710
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
1616
1711
  gl_PointSize = 0.0;
1617
1712
  return;
1618
1713
  }
1619
- if (skipUnselected > 0.0 && isSelected <= 0.0) {
1620
- gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Move off-screen
1714
+ if (skipGreyed > 0.0 && isHighlighted <= 0.0) {
1715
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
1621
1716
  gl_PointSize = 0.0;
1622
1717
  return;
1623
1718
  }
1624
-
1719
+
1625
1720
  // Position
1626
1721
  vec4 pointPosition = texture(positionsTexture, (pointIndices + 0.5) / pointsTextureSize);
1627
1722
  vec2 point = pointPosition.rg;
@@ -1629,11 +1724,11 @@ void main() {
1629
1724
  // Transform point position to normalized device coordinates
1630
1725
  // Convert from space coordinates [0, spaceSize] to normalized [-1, 1]
1631
1726
  vec2 normalizedPosition = 2.0 * point / spaceSize - 1.0;
1632
-
1727
+
1633
1728
  // Apply aspect ratio correction - this is needed to map the square space to the rectangular screen
1634
1729
  // The transformation matrix handles zoom/pan, but we need this to handle aspect ratio
1635
1730
  normalizedPosition *= spaceSize / screenSize;
1636
-
1731
+
1637
1732
  #ifdef USE_UNIFORM_BUFFERS
1638
1733
  mat3 transformMat3 = mat3(transformationMatrix);
1639
1734
  vec3 finalPosition = transformMat3 * vec3(normalizedPosition, 1);
@@ -1642,12 +1737,27 @@ void main() {
1642
1737
  #endif
1643
1738
  gl_Position = vec4(finalPosition.rg, 0, 1);
1644
1739
 
1740
+ float pointSize = animateSizes > 0.0
1741
+ ? mix(sourceSize, targetSize, transitionProgress)
1742
+ : targetSize;
1743
+ vec4 pointColor = animateColors > 0.0
1744
+ ? mix(sourceColor, targetColor, transitionProgress)
1745
+ : targetColor;
1746
+
1645
1747
  // Calculate sizes for shape and image
1646
- float shapeSizeValue = calculatePointSize(size * sizeScale);
1748
+ float shapeSizeValue = calculatePointSize(pointSize * sizeScale);
1647
1749
  float imageSizeValue = calculatePointSize(imageSize * sizeScale);
1648
-
1750
+
1649
1751
  // Use the larger of the two sizes for the overall point size
1650
1752
  float overallSizeValue = max(shapeSizeValue, imageSizeValue);
1753
+
1754
+ // Scale up point sprite to fit outline ring; clamp to hardware gl_PointSize limit so the
1755
+ // sprite never gets silently clipped — the point body is unaffected, only the ring narrows.
1756
+ if (isOutlined > 0.0) {
1757
+ overallSizeValue *= outlineRingScale;
1758
+ overallSizeValue = min(overallSizeValue, maxPointSize * ratio);
1759
+ }
1760
+
1651
1761
  gl_PointSize = overallSizeValue;
1652
1762
 
1653
1763
  // Pass size information to fragment shader
@@ -1655,31 +1765,27 @@ void main() {
1655
1765
  imageSizeVarying = imageSizeValue;
1656
1766
  overallSize = overallSizeValue;
1657
1767
 
1658
- shapeColor = color;
1768
+ shapeColor = pointColor;
1659
1769
  pointShape = shape;
1660
1770
 
1661
- // Adjust alpha of selected points
1771
+ // Adjust color of greyed-out points
1662
1772
  if (isGreyedOut > 0.0) {
1663
1773
  if (greyoutColor[0] != -1.0) {
1664
1774
  shapeColor = greyoutColor;
1665
1775
  } else {
1666
1776
  // If greyoutColor is not set, make color lighter or darker based on isDarkenGreyout
1667
- float blendFactor = 0.65; // Controls how much to modify (0.0 = original, 1.0 = target color)
1668
-
1777
+ float blendFactor = 0.65;
1778
+
1669
1779
  #ifdef USE_UNIFORM_BUFFERS
1670
1780
  if (isDarkenGreyout > 0.0) {
1671
- // Darken the color
1672
1781
  shapeColor.rgb = mix(shapeColor.rgb, vec3(0.2), blendFactor);
1673
1782
  } else {
1674
- // Lighten the color
1675
1783
  shapeColor.rgb = mix(shapeColor.rgb, max(backgroundColor.rgb, vec3(0.8)), blendFactor);
1676
1784
  }
1677
1785
  #else
1678
1786
  if (isDarkenGreyout > 0.0) {
1679
- // Darken the color
1680
1787
  shapeColor.rgb = mix(shapeColor.rgb, vec3(0.2), blendFactor);
1681
1788
  } else {
1682
- // Lighten the color
1683
1789
  shapeColor.rgb = mix(shapeColor.rgb, max(backgroundColor.rgb, vec3(0.8)), blendFactor);
1684
1790
  }
1685
1791
  #endif
@@ -1690,12 +1796,9 @@ void main() {
1690
1796
  if (hasImages <= 0.0 || imageIndex < 0.0 || imageIndex >= imageCount) {
1691
1797
  imageAtlasUV = vec4(-1.0);
1692
1798
  } else {
1693
- // Calculate image atlas UV coordinates based on imageIndex
1694
1799
  float atlasCoordIndex = imageIndex;
1695
- // Calculate the position in the texture grid
1696
1800
  float texX = mod(atlasCoordIndex, imageAtlasCoordsTextureSize);
1697
1801
  float texY = floor(atlasCoordIndex / imageAtlasCoordsTextureSize);
1698
- // Convert to texture coordinates (0.0 to 1.0)
1699
1802
  vec2 atlasCoordTexCoord = (vec2(texX, texY) + 0.5) / imageAtlasCoordsTextureSize;
1700
1803
  vec4 atlasCoords = texture(imageAtlasCoords, atlasCoordTexCoord);
1701
1804
  imageAtlasUV = atlasCoords;
@@ -1704,18 +1807,16 @@ void main() {
1704
1807
  if (hasImages <= 0.0 || imageIndex < 0.0 || imageIndex >= imageCount) {
1705
1808
  imageAtlasUV = vec4(-1.0);
1706
1809
  } else {
1707
- // Calculate image atlas UV coordinates based on imageIndex
1708
1810
  float atlasCoordIndex = imageIndex;
1709
- // Calculate the position in the texture grid
1710
1811
  float texX = mod(atlasCoordIndex, imageAtlasCoordsTextureSize);
1711
1812
  float texY = floor(atlasCoordIndex / imageAtlasCoordsTextureSize);
1712
- // Convert to texture coordinates (0.0 to 1.0)
1713
1813
  vec2 atlasCoordTexCoord = (vec2(texX, texY) + 0.5) / imageAtlasCoordsTextureSize;
1714
1814
  vec4 atlasCoords = texture(imageAtlasCoords, atlasCoordTexCoord);
1715
1815
  imageAtlasUV = atlasCoords;
1716
1816
  }
1717
1817
  #endif
1718
- } `,pv=`#version 300 es
1818
+ }
1819
+ `,Mv=`#version 300 es
1719
1820
  #ifdef GL_ES
1720
1821
  precision highp float;
1721
1822
  #endif
@@ -1724,35 +1825,35 @@ uniform sampler2D positionsTexture;
1724
1825
  uniform sampler2D pointSize;
1725
1826
 
1726
1827
  #ifdef USE_UNIFORM_BUFFERS
1727
- layout(std140) uniform findPointsOnAreaSelectionUniforms {
1828
+ layout(std140) uniform findPointsInRectUniforms {
1728
1829
  float sizeScale;
1729
1830
  float spaceSize;
1730
1831
  vec2 screenSize;
1731
1832
  float ratio;
1732
1833
  mat4 transformationMatrix;
1733
- vec2 selection0;
1734
- vec2 selection1;
1834
+ vec2 rect0;
1835
+ vec2 rect1;
1735
1836
  float scalePointsOnZoom;
1736
1837
  float maxPointSize;
1737
- } findPointsOnAreaSelection;
1738
-
1739
- #define sizeScale findPointsOnAreaSelection.sizeScale
1740
- #define spaceSize findPointsOnAreaSelection.spaceSize
1741
- #define screenSize findPointsOnAreaSelection.screenSize
1742
- #define ratio findPointsOnAreaSelection.ratio
1743
- #define transformationMatrix findPointsOnAreaSelection.transformationMatrix
1744
- #define selection0 findPointsOnAreaSelection.selection0
1745
- #define selection1 findPointsOnAreaSelection.selection1
1746
- #define scalePointsOnZoom findPointsOnAreaSelection.scalePointsOnZoom
1747
- #define maxPointSize findPointsOnAreaSelection.maxPointSize
1838
+ } findPointsInRect;
1839
+
1840
+ #define sizeScale findPointsInRect.sizeScale
1841
+ #define spaceSize findPointsInRect.spaceSize
1842
+ #define screenSize findPointsInRect.screenSize
1843
+ #define ratio findPointsInRect.ratio
1844
+ #define transformationMatrix findPointsInRect.transformationMatrix
1845
+ #define rect0 findPointsInRect.rect0
1846
+ #define rect1 findPointsInRect.rect1
1847
+ #define scalePointsOnZoom findPointsInRect.scalePointsOnZoom
1848
+ #define maxPointSize findPointsInRect.maxPointSize
1748
1849
  #else
1749
1850
  uniform float sizeScale;
1750
1851
  uniform float spaceSize;
1751
1852
  uniform vec2 screenSize;
1752
1853
  uniform float ratio;
1753
1854
  uniform mat3 transformationMatrix;
1754
- uniform vec2 selection0;
1755
- uniform vec2 selection1;
1855
+ uniform vec2 rect0;
1856
+ uniform vec2 rect1;
1756
1857
  uniform float scalePointsOnZoom;
1757
1858
  uniform float maxPointSize;
1758
1859
  #endif
@@ -1792,10 +1893,10 @@ void main() {
1792
1893
  vec4 pSize = texture(pointSize, textureCoords);
1793
1894
  float size = pSize.r * sizeScale;
1794
1895
 
1795
- float left = 2.0 * (selection0.x - 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
1796
- float right = 2.0 * (selection1.x + 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
1797
- float top = 2.0 * (selection0.y - 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
1798
- float bottom = 2.0 * (selection1.y + 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
1896
+ float left = 2.0 * (rect0.x - 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
1897
+ float right = 2.0 * (rect1.x + 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
1898
+ float top = 2.0 * (rect0.y - 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
1899
+ float bottom = 2.0 * (rect1.y + 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
1799
1900
 
1800
1901
  fragColor = vec4(0.0, 0.0, pointPosition.r, pointPosition.g);
1801
1902
  if (final.x >= left && final.x <= right && final.y >= top && final.y <= bottom) {
@@ -1803,7 +1904,7 @@ void main() {
1803
1904
  }
1804
1905
  }
1805
1906
 
1806
- `,mv=`#version 300 es
1907
+ `,Nv=`#version 300 es
1807
1908
  #ifdef GL_ES
1808
1909
  precision highp float;
1809
1910
  #endif
@@ -1812,17 +1913,17 @@ uniform sampler2D positionsTexture;
1812
1913
  uniform sampler2D polygonPathTexture; // Texture containing polygon path points
1813
1914
 
1814
1915
  #ifdef USE_UNIFORM_BUFFERS
1815
- layout(std140) uniform findPointsOnPolygonSelectionUniforms {
1916
+ layout(std140) uniform findPointsInPolygonUniforms {
1816
1917
  float spaceSize;
1817
1918
  vec2 screenSize;
1818
1919
  mat4 transformationMatrix;
1819
1920
  float polygonPathLength;
1820
- } findPointsOnPolygonSelection;
1921
+ } findPointsInPolygon;
1821
1922
 
1822
- #define spaceSize findPointsOnPolygonSelection.spaceSize
1823
- #define screenSize findPointsOnPolygonSelection.screenSize
1824
- #define transformationMatrix findPointsOnPolygonSelection.transformationMatrix
1825
- #define polygonPathLength int(findPointsOnPolygonSelection.polygonPathLength)
1923
+ #define spaceSize findPointsInPolygon.spaceSize
1924
+ #define screenSize findPointsInPolygon.screenSize
1925
+ #define transformationMatrix findPointsInPolygon.transformationMatrix
1926
+ #define polygonPathLength int(findPointsInPolygon.polygonPathLength)
1826
1927
  #else
1827
1928
  uniform int polygonPathLength;
1828
1929
  uniform float spaceSize;
@@ -1891,7 +1992,7 @@ void main() {
1891
1992
  if (pointInPolygon(screenPos, polygonPathTexture, polygonPathLength)) {
1892
1993
  fragColor.r = 1.0;
1893
1994
  }
1894
- } `,gv=`#version 300 es
1995
+ } `,Ov=`#version 300 es
1895
1996
  #ifdef GL_ES
1896
1997
  precision highp float;
1897
1998
  #endif
@@ -1934,7 +2035,7 @@ void main () {
1934
2035
  float opacity = smoothstep(r, r * smoothing, 1.0);
1935
2036
  float stroke = smoothstep(width, width * smoothing, r);
1936
2037
  fragColor = vec4(rgbColor, opacity * stroke * pointOpacity);
1937
- }`,_v=`#version 300 es
2038
+ }`,Bv=`#version 300 es
1938
2039
  #ifdef GL_ES
1939
2040
  precision highp float;
1940
2041
  #endif
@@ -1942,7 +2043,7 @@ precision highp float;
1942
2043
  in vec2 vertexCoord;
1943
2044
 
1944
2045
  uniform sampler2D positionsTexture;
1945
- uniform sampler2D pointGreyoutStatusTexture;
2046
+ uniform sampler2D pointStatus;
1946
2047
 
1947
2048
  #ifdef USE_UNIFORM_BUFFERS
1948
2049
  layout(std140) uniform drawHighlightedUniforms {
@@ -2023,7 +2124,7 @@ void main () {
2023
2124
 
2024
2125
  rgbColor = color.rgb;
2025
2126
  pointOpacity = color.a * universalPointOpacity;
2026
- vec4 greyoutStatus = texture(pointGreyoutStatusTexture, textureCoordinates / pointsTextureSize);
2127
+ vec4 greyoutStatus = texture(pointStatus, textureCoordinates / pointsTextureSize);
2027
2128
  if (greyoutStatus.r > 0.0) {
2028
2129
  if (greyoutColor[0] != -1.0) {
2029
2130
  rgbColor = greyoutColor.rgb;
@@ -2078,7 +2179,7 @@ void main () {
2078
2179
  #endif
2079
2180
 
2080
2181
  gl_Position = vec4(final.rg, 0, 1);
2081
- }`,xv=`#version 300 es
2182
+ }`,Uv=`#version 300 es
2082
2183
  #ifdef GL_ES
2083
2184
  precision highp float;
2084
2185
  #endif
@@ -2092,7 +2193,7 @@ void main() {
2092
2193
  discard;
2093
2194
  }
2094
2195
  fragColor = rgba;
2095
- }`,yv=`#version 300 es
2196
+ }`,zv=`#version 300 es
2096
2197
  #ifdef GL_ES
2097
2198
  precision highp float;
2098
2199
  #endif
@@ -2102,7 +2203,7 @@ in float size;
2102
2203
  in float imageSize;
2103
2204
 
2104
2205
  uniform sampler2D positionsTexture;
2105
- uniform sampler2D pointGreyoutStatus;
2206
+ uniform sampler2D pointStatus;
2106
2207
 
2107
2208
  #ifdef USE_UNIFORM_BUFFERS
2108
2209
  layout(std140) uniform findHoveredPointUniforms {
@@ -2115,8 +2216,8 @@ layout(std140) uniform findHoveredPointUniforms {
2115
2216
  vec2 mousePosition;
2116
2217
  float scalePointsOnZoom;
2117
2218
  float maxPointSize;
2118
- float skipSelected;
2119
- float skipUnselected;
2219
+ float skipHighlighted;
2220
+ float skipGreyed;
2120
2221
  } findHoveredPoint;
2121
2222
 
2122
2223
  #define pointsTextureSize findHoveredPoint.pointsTextureSize
@@ -2128,8 +2229,8 @@ layout(std140) uniform findHoveredPointUniforms {
2128
2229
  #define mousePosition findHoveredPoint.mousePosition
2129
2230
  #define scalePointsOnZoom findHoveredPoint.scalePointsOnZoom
2130
2231
  #define maxPointSize findHoveredPoint.maxPointSize
2131
- #define skipSelected findHoveredPoint.skipSelected
2132
- #define skipUnselected findHoveredPoint.skipUnselected
2232
+ #define skipHighlighted findHoveredPoint.skipHighlighted
2233
+ #define skipGreyed findHoveredPoint.skipGreyed
2133
2234
  #else
2134
2235
  uniform float pointsTextureSize;
2135
2236
  uniform float sizeScale;
@@ -2140,8 +2241,8 @@ uniform mat3 transformationMatrix;
2140
2241
  uniform vec2 mousePosition;
2141
2242
  uniform float scalePointsOnZoom;
2142
2243
  uniform float maxPointSize;
2143
- uniform float skipSelected;
2144
- uniform float skipUnselected;
2244
+ uniform float skipHighlighted;
2245
+ uniform float skipGreyed;
2145
2246
  #endif
2146
2247
 
2147
2248
  out vec4 rgba;
@@ -2163,16 +2264,16 @@ float euclideanDistance (float x1, float x2, float y1, float y2) {
2163
2264
  }
2164
2265
 
2165
2266
  void main() {
2166
- vec4 greyoutStatus = texture(pointGreyoutStatus, (pointIndices + 0.5) / pointsTextureSize);
2167
- float isSelected = (greyoutStatus.r == 0.0) ? 1.0 : 0.0;
2267
+ vec4 greyoutStatus = texture(pointStatus, (pointIndices + 0.5) / pointsTextureSize);
2268
+ float isHighlighted = (greyoutStatus.r == 0.0) ? 1.0 : 0.0;
2168
2269
 
2169
- if (skipSelected > 0.0 && isSelected > 0.0) {
2270
+ if (skipHighlighted > 0.0 && isHighlighted > 0.0) {
2170
2271
  rgba = vec4(0.0);
2171
2272
  gl_Position = vec4(0.5, 0.5, 0.0, 1.0);
2172
2273
  gl_PointSize = 1.0;
2173
2274
  return;
2174
2275
  }
2175
- if (skipUnselected > 0.0 && isSelected <= 0.0) {
2276
+ if (skipGreyed > 0.0 && isHighlighted <= 0.0) {
2176
2277
  rgba = vec4(0.0);
2177
2278
  gl_Position = vec4(0.5, 0.5, 0.0, 1.0);
2178
2279
  gl_PointSize = 1.0;
@@ -2207,7 +2308,7 @@ void main() {
2207
2308
  }
2208
2309
 
2209
2310
  gl_PointSize = 1.0;
2210
- }`,vv=`#version 300 es
2311
+ }`,Lv=`#version 300 es
2211
2312
  #ifdef GL_ES
2212
2313
  precision highp float;
2213
2314
  #endif
@@ -2218,7 +2319,7 @@ out vec4 fragColor;
2218
2319
 
2219
2320
  void main() {
2220
2321
  fragColor = rgba;
2221
- }`,bv=`#version 300 es
2322
+ }`,Vv=`#version 300 es
2222
2323
  #ifdef GL_ES
2223
2324
  precision highp float;
2224
2325
  #endif
@@ -2268,7 +2369,7 @@ void main() {
2268
2369
  gl_Position = vec4(2.0 * vec2(i, j) - 1.0, 0.0, 1.0);
2269
2370
 
2270
2371
  gl_PointSize = 1.0;
2271
- }`,Sv=`#version 300 es
2372
+ }`,Wv=`#version 300 es
2272
2373
  #ifdef GL_ES
2273
2374
  precision highp float;
2274
2375
  #endif
@@ -2318,7 +2419,35 @@ void main() {
2318
2419
  pointPosition.g = clamp(pointPosition.g, 0.0, spaceSize);
2319
2420
 
2320
2421
  fragColor = pointPosition;
2321
- }`,Tv=`#version 300 es
2422
+ }`,Hv=`#version 300 es
2423
+ #ifdef GL_ES
2424
+ precision highp float;
2425
+ #endif
2426
+
2427
+ uniform sampler2D sourceTexture;
2428
+ uniform sampler2D targetTexture;
2429
+
2430
+ #ifdef USE_UNIFORM_BUFFERS
2431
+ layout(std140) uniform interpolatePositionUniforms {
2432
+ float progress;
2433
+ } interpolatePosition;
2434
+
2435
+ #define progress interpolatePosition.progress
2436
+ #else
2437
+ uniform float progress;
2438
+ #endif
2439
+
2440
+ in vec2 textureCoords;
2441
+
2442
+ out vec4 fragColor;
2443
+
2444
+ void main() {
2445
+ vec4 source = texture(sourceTexture, textureCoords);
2446
+ vec4 target = texture(targetTexture, textureCoords);
2447
+ vec2 position = mix(source.rg, target.rg, progress);
2448
+ fragColor = vec4(position, source.b, 1.0);
2449
+ }
2450
+ `,$v=`#version 300 es
2322
2451
  #ifdef GL_ES
2323
2452
  precision highp float;
2324
2453
  #endif
@@ -2348,7 +2477,7 @@ void main() {
2348
2477
  fragColor = vec4(pointPosition.rg, 1.0, 1.0);
2349
2478
  }
2350
2479
 
2351
- `,wv=`#version 300 es
2480
+ `,Xv=`#version 300 es
2352
2481
  #ifdef GL_ES
2353
2482
  precision highp float;
2354
2483
  #endif
@@ -2381,7 +2510,7 @@ void main() {
2381
2510
  }
2382
2511
 
2383
2512
  fragColor = pointPosition;
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=`
2513
+ }`;function Yv(i,e=16384){if(!(i!=null&&i.length))return null;let t=0;for(const c of i){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 n=t,r=Math.ceil(Math.sqrt(i.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 ${(n*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 i.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),P=Math.floor(h*d),I=Math.floor(c/r),M=c%r*t,k=I*t;l[c*4]=M/s,l[c*4+1]=k/s,l[c*4+2]=(M+_)/s,l[c*4+3]=(k+P)/s;for(let y=0;y<P;y++)for(let R=0;R<_;R++){const B=Math.floor(R*(f/_)),W=(Math.floor(y*(h/P))*f+B)*4,q=((k+y)*s+(M+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}}function qv(i,e,t){const n=new Float32Array(e*e*4);if(!i)return n;for(let r=0;r<t;++r)n[r*4+0]=i[r*2+0],n[r*4+1]=i[r*2+1],n[r*4+2]=r;return n}function jv(i,e,t,n,r){const s=new Float32Array(r*r*4);for(let o=0;o<t;o+=1)s[o*4+0]=i[o*4+0],s[o*4+1]=i[o*4+1],s[o*4+2]=o;for(let o=t;o<n;o+=1)s[o*4+0]=e[o*4+0],s[o*4+1]=e[o*4+1],s[o*4+2]=o;return s}class Kv extends Bt{constructor(){super(...arguments),this.imageCount=0,this.areClusterCentroidsUpToDate=!1,this.isPositionsUpToDate=!1,this.polygonPathLength=0,this.transitionProgress=1,this.shouldAnimatePointColors=!1,this.shouldAnimatePointSizes=!1}updatePositions(){var I;const{device:e,store:t,data:n,config:{rescalePositions:r,enableSimulation:s}}=this,{pointsTextureSize:o}=t;if(!o||!n.pointPositions||n.pointsNumber===void 0)return!1;let a=r;r===void 0&&!s&&(a=!0),this.shouldSkipRescale&&(a=!1),a?this.rescaleInitialNodePositions():this.shouldSkipRescale||(this.scaleX=void 0,this.scaleY=void 0),this.shouldSkipRescale=void 0;const l=n.sourcePointsNumber,c=n.targetPointsNumber,u=l===c,f=((I=this.transition)==null?void 0:I.isPendingFor(be.Positions))===!0&&this.config.transitionDuration>0&&!!this.currentPositionTexture,h=qv(n.pointPositions,o,c),d=(w,M)=>{w.copyImageData({data:M,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0})};if(f&&(this.createTransitionResources(),this.sourcePositionTexture&&this.targetPositionTexture)){if(u){const w=this.currentPositionTexture;if(w&&!w.destroyed){const M=this.device.createCommandEncoder();M.copyTextureToTexture({sourceTexture:w,destinationTexture:this.sourcePositionTexture,width:o,height:o}),this.device.submit(M.finish())}}else if(this.currentPositionFbo){const w=He(e,this.currentPositionFbo),M=jv(w,h,Math.min(l,c),c,o);d(this.sourcePositionTexture,M)}else d(this.sourcePositionTexture,h);d(this.targetPositionTexture,h)}this.createOrUpdatePositionTextures(h,o),this.config.enableSimulation&&this.ensureSimulationResources(),!this.searchTexture||this.searchTexture.width!==o||this.searchTexture.height!==o?(this.searchTexture&&!this.searchTexture.destroyed&&this.searchTexture.destroy(),this.searchFbo&&!this.searchFbo.destroyed&&this.searchFbo.destroy(),this.searchTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.searchTexture.copyImageData({data:h,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.searchFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.searchTexture]})):this.searchTexture.copyImageData({data:h,bytesPerRow:ie("rgba32float",o),mipLevel:0,x:0,y:0}),this.hoveredFbo||(this.hoveredFbo=e.createFramebuffer({width:2,height:2,colorAttachments:["rgba32float"]}));const _=br(t.pointsTextureSize),P=_.byteLength;return!this.drawPointIndices||this.drawPointIndices.byteLength!==P?(this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=e.createBuffer({data:_,usage:H.VERTEX|H.COPY_DST})):this.drawPointIndices.write(_),this.drawCommand&&this.drawCommand.setAttributes({pointIndices:this.drawPointIndices}),!this.hoveredPointIndices||this.hoveredPointIndices.byteLength!==P?(this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=e.createBuffer({data:_,usage:H.VERTEX|H.COPY_DST})):this.hoveredPointIndices.write(_),!this.sampledPointIndices||this.sampledPointIndices.byteLength!==P?(this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=e.createBuffer({data:_,usage:H.VERTEX|H.COPY_DST})):this.sampledPointIndices.write(_),this.fillSampledPointsFboCommand&&this.fillSampledPointsFboCommand.setAttributes({pointIndices:this.sampledPointIndices}),this.updatePointStatus(),this.updatePinnedStatus(),this.updateSampledPointsGrid(),this.trackPointsByIndices(),f}initPrograms(){var s,o,a;const{device:e,config:t,store:n,data:r}=this;(!this.imageAtlasCoordsTexture||!this.imageAtlasTexture)&&this.createAtlas(),this.targetColorBuffer||this.updateColor(),this.targetSizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),this.pointStatusTexture||this.updatePointStatus(),t.enableSimulation&&this.ensureUpdatePositionProgram(),this.dragPointVertexCoordBuffer||(this.dragPointVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.dragPointUniformStore||(this.dragPointUniformStore=new pe({dragPointUniforms:{uniformTypes:{mousePos:"vec2<f32>",index:"f32"},defaultUniforms:{mousePos:ne(n.mousePosition,[0,0]),index:((s=n.hoveredPoint)==null?void 0:s.index)??-1}}})),this.dragPointCommand||(this.dragPointCommand=new de(e,{fs:Xv,vs:Ge,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 pe({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",skipHighlighted:"f32",skipGreyed:"f32",hasImages:"f32",imageCount:"f32",imageAtlasCoordsTextureSize:"f32",transitionProgress:"f32",animateColors:"f32",animateSizes:"f32"},defaultUniforms:{ratio:t.pixelRatio,transformationMatrix:(()=>{const l=n.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:n.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),greyoutColor:Pe(n.greyoutPointColor,[0,0,0,1]),backgroundColor:Pe(n.backgroundColor,[0,0,0,1]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:n.maxPointSize,isDarkenGreyout:n.isDarkenGreyout??!1?1:0,skipHighlighted:0,skipGreyed:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0,transitionProgress:1,animateColors:0,animateSizes:0}},drawFragmentUniforms:{uniformTypes:{greyoutOpacity:"f32",pointOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>",outlineColor:"vec4<f32>",outlineWidth:"f32"},defaultUniforms:{greyoutOpacity:t.pointGreyoutOpacity??-1,pointOpacity:t.pointOpacity,isDarkenGreyout:n.isDarkenGreyout??!1?1:0,backgroundColor:Pe(n.backgroundColor,[0,0,0,1]),outlineColor:Pe(n.outlinedPointRingColor,[1,1,1,1]),outlineWidth:.9}}})),this.drawCommand||(this.drawCommand=new de(e,{fs:Dv,vs:Fv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.drawPointIndices&&{pointIndices:this.drawPointIndices},...this.sourceSizeBuffer&&{sourceSize:this.sourceSizeBuffer},...this.targetSizeBuffer&&{targetSize:this.targetSizeBuffer},...this.sourceColorBuffer&&{sourceColor:this.sourceColorBuffer},...this.targetColorBuffer&&{targetColor:this.targetColorBuffer},...this.shapeBuffer&&{shape:this.shapeBuffer},...this.imageIndicesBuffer&&{imageIndex:this.imageIndicesBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"sourceSize",format:"float32"},{name:"targetSize",format:"float32"},{name:"sourceColor",format:"float32x4"},{name:"targetColor",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.findPointsInRectVertexCoordBuffer||(this.findPointsInRectVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsInRectUniformStore||(this.findPointsInRectUniformStore=new pe({findPointsInRectUniforms:{uniformTypes:{sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",rect0:"vec2<f32>",rect1:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32"},defaultUniforms:{sizeScale:t.pointSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),ratio:t.pixelRatio,transformationMatrix:n.transformationMatrix4x4,rect0:ne((o=n.searchArea)==null?void 0:o[0],[0,0]),rect1:ne((a=n.searchArea)==null?void 0:a[1],[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:n.maxPointSize}}})),this.findPointsInRectCommand||(this.findPointsInRectCommand=new de(e,{fs:Mv,vs:Ge,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsInRectVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsInRectUniforms:this.findPointsInRectUniformStore.getManagedUniformBuffer(e,"findPointsInRectUniforms")}})),this.findPointsInPolygonVertexCoordBuffer||(this.findPointsInPolygonVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsInPolygonUniformStore||(this.findPointsInPolygonUniformStore=new pe({findPointsInPolygonUniforms:{uniformTypes:{spaceSize:"f32",screenSize:"vec2<f32>",transformationMatrix:"mat4x4<f32>",polygonPathLength:"f32"},defaultUniforms:{spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),transformationMatrix:n.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}})),this.findPointsInPolygonCommand||(this.findPointsInPolygonCommand=new de(e,{fs:Nv,vs:Ge,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsInPolygonVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsInPolygonUniforms:this.findPointsInPolygonUniformStore.getManagedUniformBuffer(e,"findPointsInPolygonUniforms")}})),this.findHoveredPointUniformStore||(this.findHoveredPointUniformStore=new pe({findHoveredPointUniforms:{uniformTypes:{pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",mousePosition:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",skipHighlighted:"f32",skipGreyed:"f32"},defaultUniforms:{pointsTextureSize:n.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),ratio:t.pixelRatio,transformationMatrix:n.transformationMatrix4x4,mousePosition:ne(n.screenMousePosition,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,maxPointSize:n.maxPointSize,skipHighlighted:0,skipGreyed:0}}})),this.findHoveredPointCommand||(this.findHoveredPointCommand=new de(e,{fs:Uv,vs:zv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.targetSizeBuffer&&{size:this.targetSizeBuffer},...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 pe({fillSampledPointsUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>"},defaultUniforms:{pointsTextureSize:n.pointsTextureSize??0,transformationMatrix:n.transformationMatrix4x4,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0])}}})),this.fillSampledPointsFboCommand||(this.fillSampledPointsFboCommand=new de(e,{fs:Lv,vs:Vv,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 pe({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:n.transformationMatrix4x4,pointsTextureSize:n.pointsTextureSize??0,sizeScale:t.pointSizeScale,spaceSize:n.adjustedSpaceSize,screenSize:ne(n.screenSize,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom?1:0,pointIndex:-1,maxPointSize:n.maxPointSize,color:[0,0,0,1],universalPointOpacity:t.pointOpacity,greyoutOpacity:t.pointGreyoutOpacity??-1,isDarkenGreyout:n.isDarkenGreyout??!1?1:0,backgroundColor:Pe(n.backgroundColor,[0,0,0,1]),greyoutColor:Pe(n.greyoutPointColor,[0,0,0,1]),width:.85}}})),this.drawHighlightedCommand||(this.drawHighlightedCommand=new de(e,{fs:Ov,vs:Bv,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 pe({trackPointsUniforms:{uniformTypes:{pointsTextureSize:"f32"},defaultUniforms:{pointsTextureSize:n.pointsTextureSize??0}}})),this.trackPointsCommand||(this.trackPointsCommand=new de(e,{fs:$v,vs:Ge,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{store:{pointsTextureSize:e},data:t}=this;if(!e)return;const n=t.pointColors,{source:r,target:s,previous:o}=Sr(this.device,n,this.sourceColorBuffer,this.targetColorBuffer,this.previousColorData,4);this.sourceColorBuffer=r,this.targetColorBuffer=s,this.previousColorData=o,this.drawCommand&&this.drawCommand.setAttributes({...this.sourceColorBuffer&&{sourceColor:this.sourceColorBuffer},...this.targetColorBuffer&&{targetColor:this.targetColorBuffer}})}updatePointStatus(){const{device:e,config:t,data:n,store:{pointsTextureSize:r}}=this;if(!r||n.pointsNumber===void 0)return;const{highlightedPointIndices:s,outlinedPointIndices:o}=t,a=s!==void 0,l=o!==void 0,c=new Float32Array(r*r*4);if(a){for(let f=0;f<c.length;f+=4)c[f]=1;for(const f of s)f>=0&&f<n.pointsNumber&&(c[f*4]=0)}if(l)for(const f of o)f>=0&&f<n.pointsNumber&&(c[f*4+1]=1);const u={data:c,bytesPerRow:ie("rgba32float",r),mipLevel:0,x:0,y:0};!this.pointStatusTexture||this.pointStatusTexture.width!==r||this.pointStatusTexture.height!==r?(this.pointStatusTexture&&!this.pointStatusTexture.destroyed&&this.pointStatusTexture.destroy(),this.pointStatusTexture=e.createTexture({width:r,height:r,format:"rgba32float"}),this.pointStatusTexture.copyImageData(u)):this.pointStatusTexture.copyImageData(u)}updatePinnedStatus(){const{device:e,store:{pointsTextureSize:t},data:n}=this;if(!t)return;const r=new Float32Array(t*t*4).fill(0);if(n.inputPinnedPoints&&n.pointsNumber!==void 0)for(const s of n.inputPinnedPoints)s>=0&&s<n.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(){var c;const{device:e,store:{pointsTextureSize:t},data:n}=this;if(!t||n.pointsNumber===void 0)return;const r=n.pointSizes,{source:s,target:o,previous:a}=Sr(this.device,r,this.sourceSizeBuffer,this.targetSizeBuffer,this.previousSizeData,1);this.sourceSizeBuffer=s,this.targetSizeBuffer=o,this.previousSizeData=a,this.drawCommand&&this.drawCommand.setAttributes({...this.sourceSizeBuffer&&{sourceSize:this.sourceSizeBuffer},...this.targetSizeBuffer&&{targetSize:this.targetSizeBuffer}});const l=new Float32Array(t*t*4);for(let u=0;u<n.pointsNumber;u++){const f=r[u],h=((c=n.pointImageSizes)==null?void 0:c[u])??f;l[u*4]=Math.max(f,h)}if(!this.sizeTexture||this.sizeTexture.width!==t||this.sizeTexture.height!==t){this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy();const u=e.createTexture({width:t,height:t,format:"rgba32float"});this.sizeTexture=u,u.copyImageData({data:l,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0})}else this.sizeTexture.copyImageData({data:l,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 n=t.pointShapes,r=n.byteLength;!this.shapeBuffer||this.shapeBuffer.byteLength!==r?(this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=e.createBuffer({data:n,usage:H.VERTEX|H.COPY_DST})):this.shapeBuffer.write(n),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 n=t.pointImageIndices,r=n.byteLength;!this.imageIndicesBuffer||this.imageIndicesBuffer.byteLength!==r?(this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=e.createBuffer({data:n,usage:H.VERTEX|H.COPY_DST})):this.imageIndicesBuffer.write(n),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 n=t.pointImageSizes,r=n.byteLength;!this.imageSizesBuffer||this.imageSizesBuffer.byteLength!==r?(this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=e.createBuffer({data:n,usage:H.VERTEX|H.COPY_DST})):this.imageSizesBuffer.write(n),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:n}=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=Yv(t.inputImageData,n.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:n}=this;let r=t??Math.min(...e)/2;r===0&&(r=At.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=n.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()}setTransitionProgress(e,t=!1,n=!1){this.transitionProgress=e,this.shouldAnimatePointColors=t,this.shouldAnimatePointSizes=n}draw(e){var l,c,u,f;const{data:t,config:n,store:r}=this;if(this.targetColorBuffer||this.updateColor(),this.targetSizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),!this.drawCommand||!this.drawUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.pointStatusTexture||this.pointStatusTexture.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:n.pixelRatio,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:n.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),greyoutColor:Pe(r.greyoutPointColor,[-1,-1,-1,-1]),backgroundColor:Pe(r.backgroundColor,[0,0,0,1]),scalePointsOnZoom:n.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,transitionProgress:this.transitionProgress,animateColors:this.shouldAnimatePointColors?1:0,animateSizes:this.shouldAnimatePointSizes?1:0},o={greyoutOpacity:n.pointGreyoutOpacity??-1,pointOpacity:n.pointOpacity,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Pe(r.backgroundColor,[0,0,0,1]),outlineColor:Pe(r.outlinedPointRingColor,[1,1,1,1]),outlineWidth:.9};if(n.highlightedPointIndices!==void 0?(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipHighlighted:1,skipGreyed:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointStatus:this.pointStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e),this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipHighlighted:0,skipGreyed:1},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointStatus:this.pointStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)):(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipHighlighted:0,skipGreyed:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointStatus:this.pointStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)),n.renderHoveredPointRing&&r.hoveredPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.pointStatusTexture||this.pointStatusTexture.destroyed)return;const h=((l=t.pointSizes)==null?void 0:l[r.hoveredPoint.index])??1,d=((c=t.pointImageSizes)==null?void 0:c[r.hoveredPoint.index])??h;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:Math.max(h,d),transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:n.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),scalePointsOnZoom:n.scalePointsOnZoom?1:0,pointIndex:r.hoveredPoint.index,maxPointSize:r.maxPointSize,color:Pe(r.hoveredPointRingColor,[0,0,0,1]),universalPointOpacity:n.pointOpacity,greyoutOpacity:n.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Pe(r.backgroundColor,[0,0,0,1]),greyoutColor:Pe(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointStatus:this.pointStatusTexture}),this.drawHighlightedCommand.draw(e)}if(r.focusedPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.pointStatusTexture||this.pointStatusTexture.destroyed)return;const h=((u=t.pointSizes)==null?void 0:u[r.focusedPoint.index])??1,d=((f=t.pointImageSizes)==null?void 0:f[r.focusedPoint.index])??h;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:Math.max(h,d),transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:n.pointSizeScale,spaceSize:r.adjustedSpaceSize,screenSize:ne(r.screenSize,[0,0]),scalePointsOnZoom:n.scalePointsOnZoom?1:0,pointIndex:r.focusedPoint.index,maxPointSize:r.maxPointSize,color:Pe(r.focusedPointRingColor,[0,0,0,1]),universalPointOpacity:n.pointOpacity,greyoutOpacity:n.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Pe(r.backgroundColor,[0,0,0,1]),greyoutColor:Pe(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointStatus:this.pointStatusTexture}),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.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.isPositionsUpToDate=!1}findPointsInRect(){var t,n;if(!this.findPointsInRectCommand||!this.findPointsInRectUniformStore||!this.searchFbo||this.searchFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.sizeTexture||this.sizeTexture.destroyed)return!1;this.findPointsInRectUniformStore.setUniforms({findPointsInRectUniforms:{spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),sizeScale:this.config.pointSizeScale,transformationMatrix:this.store.transformationMatrix4x4,ratio:this.config.pixelRatio,rect0:ne((t=this.store.searchArea)==null?void 0:t[0],[0,0]),rect1:ne((n=this.store.searchArea)==null?void 0:n[1],[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom?1:0,maxPointSize:this.store.maxPointSize}}),this.findPointsInRectCommand.setBindings({positionsTexture:this.currentPositionTexture,pointSize:this.sizeTexture});const e=this.device.beginRenderPass({framebuffer:this.searchFbo});return this.findPointsInRectCommand.draw(e),e.end(),!0}findPointsInPolygon(){if(!this.findPointsInPolygonCommand||!this.findPointsInPolygonUniformStore||!this.searchFbo||this.searchFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.polygonPathTexture||this.polygonPathTexture.destroyed)return!1;this.findPointsInPolygonUniformStore.setUniforms({findPointsInPolygonUniforms:{spaceSize:this.store.adjustedSpaceSize,screenSize:ne(this.store.screenSize,[0,0]),transformationMatrix:this.store.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}),this.findPointsInPolygonCommand.setBindings({positionsTexture:this.currentPositionTexture,polygonPathTexture:this.polygonPathTexture});const e=this.device.beginRenderPass({framebuffer:this.searchFbo});return this.findPointsInPolygonCommand.draw(e),e.end(),!0}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 n=Math.ceil(Math.sqrt(e.length)),r=new Float32Array(n*n*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!==n||this.polygonPathTexture.height!==n?(this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=t.createTexture({width:n,height:n,format:"rgba32float"}),this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",n),mipLevel:0,x:0,y:0})):this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ie("rgba32float",n),mipLevel:0,x:0,y:0})}findHoveredPoint(){if(!this.hoveredFbo||this.hoveredFbo.destroyed||!this.findHoveredPointCommand||!this.findHoveredPointUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||(this.pointStatusTexture||this.updatePointStatus(),!this.pointStatusTexture||this.pointStatusTexture.destroyed))return;this.findHoveredPointCommand.setVertexCount(this.data.pointsNumber??0),this.findHoveredPointCommand.setAttributes({...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.targetSizeBuffer&&{size:this.targetSizeBuffer},...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,pointStatus:this.pointStatusTexture},n=this.device.beginRenderPass({framebuffer:this.hoveredFbo,clearColor:[0,0,0,0]});this.config.highlightedPointIndices!==void 0?(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipHighlighted:1,skipGreyed:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(n),this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipHighlighted:0,skipGreyed:1}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(n)):(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipHighlighted:0,skipGreyed:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(n)),n.end()}trackPointsByIndices(e){const{store:{pointsTextureSize:t},device:n}=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=n.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=n.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 n=He(this.device,this.trackedPositionsFbo),r=new Map;for(let s=0;s<n.length/4;s+=1){const o=n[s*4],a=n[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 n=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(n),n.end()}const t=He(this.device,this.sampledPointsFbo);for(let n=0;n<t.length/4;n++){const r=t[n*4],s=!!t[n*4+1],o=t[n*4+2],a=t[n*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 n=He(this.device,this.sampledPointsFbo);for(let r=0;r<n.length/4;r++){const s=n[r*4],o=!!n[r*4+1],a=n[r*4+2],l=n[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=He(this.device,this.trackedPositionsFbo);for(let n=0;n<t.length/4;n+=1){const r=t[n*4],s=t[n*4+1],o=this.trackedIndices[n];r!==void 0&&s!==void 0&&o!==void 0&&(e[n*2]=r,e[n*2+1]=s)}return e}destroy(){var e,t,n,r,s,o,a,l,c,u,f,h,d,_,P,I,w,M,k,y;(e=this.drawCommand)==null||e.destroy(),this.drawCommand=void 0,(t=this.drawHighlightedCommand)==null||t.destroy(),this.drawHighlightedCommand=void 0,(n=this.interpolatePositionCommand)==null||n.destroy(),this.interpolatePositionCommand=void 0,(r=this.updatePositionCommand)==null||r.destroy(),this.updatePositionCommand=void 0,(s=this.dragPointCommand)==null||s.destroy(),this.dragPointCommand=void 0,(o=this.findPointsInRectCommand)==null||o.destroy(),this.findPointsInRectCommand=void 0,(a=this.findPointsInPolygonCommand)==null||a.destroy(),this.findPointsInPolygonCommand=void 0,(l=this.findHoveredPointCommand)==null||l.destroy(),this.findHoveredPointCommand=void 0,(c=this.fillSampledPointsFboCommand)==null||c.destroy(),this.fillSampledPointsFboCommand=void 0,(u=this.trackPointsCommand)==null||u.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.sourcePositionFbo&&!this.sourcePositionFbo.destroyed&&this.sourcePositionFbo.destroy(),this.sourcePositionFbo=void 0,this.targetPositionFbo&&!this.targetPositionFbo.destroyed&&this.targetPositionFbo.destroy(),this.targetPositionFbo=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.searchFbo&&!this.searchFbo.destroyed&&this.searchFbo.destroy(),this.searchFbo=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.sourcePositionTexture&&!this.sourcePositionTexture.destroyed&&this.sourcePositionTexture.destroy(),this.sourcePositionTexture=void 0,this.targetPositionTexture&&!this.targetPositionTexture.destroyed&&this.targetPositionTexture.destroy(),this.targetPositionTexture=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=void 0,this.searchTexture&&!this.searchTexture.destroyed&&this.searchTexture.destroy(),this.searchTexture=void 0,this.pointStatusTexture&&!this.pointStatusTexture.destroyed&&this.pointStatusTexture.destroy(),this.pointStatusTexture=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,(f=this.interpolatePositionUniformStore)==null||f.destroy(),this.interpolatePositionUniformStore=void 0,(h=this.updatePositionUniformStore)==null||h.destroy(),this.updatePositionUniformStore=void 0,(d=this.dragPointUniformStore)==null||d.destroy(),this.dragPointUniformStore=void 0,(_=this.drawUniformStore)==null||_.destroy(),this.drawUniformStore=void 0,(P=this.findPointsInRectUniformStore)==null||P.destroy(),this.findPointsInRectUniformStore=void 0,(I=this.findPointsInPolygonUniformStore)==null||I.destroy(),this.findPointsInPolygonUniformStore=void 0,(w=this.findHoveredPointUniformStore)==null||w.destroy(),this.findHoveredPointUniformStore=void 0,(M=this.fillSampledPointsUniformStore)==null||M.destroy(),this.fillSampledPointsUniformStore=void 0,(k=this.drawHighlightedUniformStore)==null||k.destroy(),this.drawHighlightedUniformStore=void 0,(y=this.trackPointsUniformStore)==null||y.destroy(),this.trackPointsUniformStore=void 0,this.sourceColorBuffer&&!this.sourceColorBuffer.destroyed&&this.sourceColorBuffer.destroy(),this.sourceColorBuffer=void 0,this.targetColorBuffer&&!this.targetColorBuffer.destroyed&&this.targetColorBuffer.destroy(),this.targetColorBuffer=void 0,this.previousColorData=void 0,this.sourceSizeBuffer&&!this.sourceSizeBuffer.destroyed&&this.sourceSizeBuffer.destroy(),this.sourceSizeBuffer=void 0,this.targetSizeBuffer&&!this.targetSizeBuffer.destroyed&&this.targetSizeBuffer.destroy(),this.targetSizeBuffer=void 0,this.previousSizeData=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.interpolatePositionVertexCoordBuffer&&!this.interpolatePositionVertexCoordBuffer.destroyed&&this.interpolatePositionVertexCoordBuffer.destroy(),this.interpolatePositionVertexCoordBuffer=void 0,this.dragPointVertexCoordBuffer&&!this.dragPointVertexCoordBuffer.destroyed&&this.dragPointVertexCoordBuffer.destroy(),this.dragPointVertexCoordBuffer=void 0,this.findPointsInRectVertexCoordBuffer&&!this.findPointsInRectVertexCoordBuffer.destroyed&&this.findPointsInRectVertexCoordBuffer.destroy(),this.findPointsInRectVertexCoordBuffer=void 0,this.findPointsInPolygonVertexCoordBuffer&&!this.findPointsInPolygonVertexCoordBuffer.destroyed&&this.findPointsInPolygonVertexCoordBuffer.destroy(),this.findPointsInPolygonVertexCoordBuffer=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}ensureSimulationResources(){const{store:{pointsTextureSize:e},device:t}=this;if(!e)return;this.ensureUpdatePositionProgram();const n=new Float32Array(e*e*4).fill(0);!this.velocityTexture||this.velocityTexture.width!==e||this.velocityTexture.height!==e?(this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=t.createTexture({width:e,height:e,format:"rgba32float"}),this.velocityTexture.copyImageData({data:n,bytesPerRow:ie("rgba32float",e),mipLevel:0,x:0,y:0}),this.velocityFbo=t.createFramebuffer({width:e,height:e,colorAttachments:[this.velocityTexture]})):this.velocityTexture.copyImageData({data:n,bytesPerRow:ie("rgba32float",e),mipLevel:0,x:0,y:0})}createTransitionResources(){const{store:{pointsTextureSize:e},device:t}=this;if(!e)return;const n=new Float32Array(e*e*4).fill(0),r=X.SAMPLE|X.RENDER|X.COPY_SRC|X.COPY_DST;(!this.sourcePositionTexture||this.sourcePositionTexture.width!==e||this.sourcePositionTexture.height!==e)&&(this.sourcePositionFbo&&!this.sourcePositionFbo.destroyed&&this.sourcePositionFbo.destroy(),this.sourcePositionTexture&&!this.sourcePositionTexture.destroyed&&this.sourcePositionTexture.destroy(),this.sourcePositionTexture=t.createTexture({width:e,height:e,format:"rgba32float",usage:r}),this.sourcePositionFbo=t.createFramebuffer({width:e,height:e,colorAttachments:[this.sourcePositionTexture]})),this.sourcePositionTexture.copyImageData({data:n,bytesPerRow:ie("rgba32float",e),mipLevel:0,x:0,y:0}),(!this.targetPositionTexture||this.targetPositionTexture.width!==e||this.targetPositionTexture.height!==e)&&(this.targetPositionFbo&&!this.targetPositionFbo.destroyed&&this.targetPositionFbo.destroy(),this.targetPositionTexture&&!this.targetPositionTexture.destroyed&&this.targetPositionTexture.destroy(),this.targetPositionTexture=t.createTexture({width:e,height:e,format:"rgba32float",usage:r}),this.targetPositionFbo=t.createFramebuffer({width:e,height:e,colorAttachments:[this.targetPositionTexture]})),this.targetPositionTexture.copyImageData({data:n,bytesPerRow:ie("rgba32float",e),mipLevel:0,x:0,y:0}),this.interpolatePositionVertexCoordBuffer||(this.interpolatePositionVertexCoordBuffer=t.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.interpolatePositionUniformStore||(this.interpolatePositionUniformStore=new pe({interpolatePositionUniforms:{uniformTypes:{progress:"f32"},defaultUniforms:{progress:0}}})),this.interpolatePositionCommand||(this.interpolatePositionCommand=new de(t,{fs:Hv,vs:Ge,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.interpolatePositionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{interpolatePositionUniforms:this.interpolatePositionUniformStore.getManagedUniformBuffer(t,"interpolatePositionUniforms")}}))}destroyTransitionResources(){var e,t;(e=this.interpolatePositionCommand)==null||e.destroy(),this.interpolatePositionCommand=void 0,(t=this.interpolatePositionUniformStore)==null||t.destroy(),this.interpolatePositionUniformStore=void 0,this.interpolatePositionVertexCoordBuffer&&!this.interpolatePositionVertexCoordBuffer.destroyed&&this.interpolatePositionVertexCoordBuffer.destroy(),this.interpolatePositionVertexCoordBuffer=void 0,this.sourcePositionFbo&&!this.sourcePositionFbo.destroyed&&this.sourcePositionFbo.destroy(),this.sourcePositionFbo=void 0,this.sourcePositionTexture&&!this.sourcePositionTexture.destroyed&&this.sourcePositionTexture.destroy(),this.sourcePositionTexture=void 0,this.targetPositionFbo&&!this.targetPositionFbo.destroyed&&this.targetPositionFbo.destroy(),this.targetPositionFbo=void 0,this.targetPositionTexture&&!this.targetPositionTexture.destroyed&&this.targetPositionTexture.destroy(),this.targetPositionTexture=void 0}interpolatePosition(e){if(!this.interpolatePositionCommand||!this.interpolatePositionUniformStore||!this.sourcePositionTexture||this.sourcePositionTexture.destroyed||!this.targetPositionTexture||this.targetPositionTexture.destroyed||!this.currentPositionFbo||this.currentPositionFbo.destroyed)return;this.interpolatePositionUniformStore.setUniforms({interpolatePositionUniforms:{progress:e}}),this.interpolatePositionCommand.setBindings({sourceTexture:this.sourcePositionTexture,targetTexture:this.targetPositionTexture});const t=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.interpolatePositionCommand.draw(t),t.end(),this.isPositionsUpToDate=!1,this.areClusterCentroidsUpToDate=!1}destroySimulationResources(){var e,t;(e=this.updatePositionCommand)==null||e.destroy(),this.updatePositionCommand=void 0,(t=this.updatePositionUniformStore)==null||t.destroy(),this.updatePositionUniformStore=void 0,this.updatePositionVertexCoordBuffer&&!this.updatePositionVertexCoordBuffer.destroyed&&this.updatePositionVertexCoordBuffer.destroy(),this.updatePositionVertexCoordBuffer=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=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}createOrUpdatePositionTextures(e,t){(!this.currentPositionTexture||this.currentPositionTexture.width!==t||this.currentPositionTexture.height!==t)&&(this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionTexture=this.device.createTexture({width:t,height:t,format:"rgba32float"}),this.currentPositionFbo=this.device.createFramebuffer({width:t,height:t,colorAttachments:[this.currentPositionTexture]})),this.currentPositionTexture.copyImageData({data:e,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0}),(!this.previousPositionTexture||this.previousPositionTexture.width!==t||this.previousPositionTexture.height!==t)&&(this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionTexture=this.device.createTexture({width:t,height:t,format:"rgba32float"}),this.previousPositionFbo=this.device.createFramebuffer({width:t,height:t,colorAttachments:[this.previousPositionTexture]})),this.previousPositionTexture.copyImageData({data:e,bytesPerRow:ie("rgba32float",t),mipLevel:0,x:0,y:0}),this.areClusterCentroidsUpToDate=!1,this.isPositionsUpToDate=!1}ensureUpdatePositionProgram(){const{device:e,config:t,store:n}=this;this.updatePositionVertexCoordBuffer||(this.updatePositionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.updatePositionUniformStore||(this.updatePositionUniformStore=new pe({updatePositionUniforms:{uniformTypes:{friction:"f32",spaceSize:"f32"},defaultUniforms:{friction:t.simulationFriction,spaceSize:n.adjustedSpaceSize}}})),this.updatePositionCommand||(this.updatePositionCommand=new de(e,{fs:Wv,vs:Ge,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")}}))}rescaleInitialNodePositions(){const{config:{spaceSize:e}}=this;if(!this.data.pointPositions||!e)return;const t=this.data.pointPositions,n=t.length/2;let r=1/0,s=-1/0,o=1/0,a=-1/0;for(let w=0;w<t.length;w+=2){const M=t[w],k=t[w+1];r=Math.min(r,M),s=Math.max(s,M),o=Math.min(o,k),a=Math.max(a,k)}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=n>f?e*Math.max(1.2,Math.sqrt(n)/e):e*.1,d=h/u,_=(e-h)/2,P=(u-l)/2*d+_,I=(u-c)/2*d+_;this.scaleX=w=>(w-r)*d+P,this.scaleY=w=>(w-o)*d+I;for(let w=0;w<n;w++)this.data.pointPositions[w*2]=this.scaleX(t[w*2]),this.data.pointPositions[w*2+1]=this.scaleY(t[w*2+1])}}const Zv={passive:!1},tn={capture:!0,passive:!1};function Oo(i){i.stopImmediatePropagation()}function vi(i){i.preventDefault(),i.stopImmediatePropagation()}function Uu(i){var e=i.document.documentElement,t=Ae(i).on("dragstart.drag",vi,tn);"onselectstart"in e?t.on("selectstart.drag",vi,tn):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function zu(i,e){var t=i.document.documentElement,n=Ae(i).on("dragstart.drag",null);e&&(n.on("click.drag",vi,tn),setTimeout(function(){n.on("click.drag",null)},0)),"onselectstart"in t?n.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}const wr=i=>()=>i;function Bo(i,{sourceEvent:e,subject:t,target:n,identifier:r,active:s,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:i,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:t,enumerable:!0,configurable:!0},target:{value:n,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}})}Bo.prototype.on=function(){var i=this._.on.apply(this._,arguments);return i===this._?this:i};function Qv(i){return!i.ctrlKey&&!i.button}function Jv(){return this.parentNode}function Gv(i,e){return e??{x:i.x,y:i.y}}function eb(){return navigator.maxTouchPoints||"ontouchstart"in this}function tb(){var i=Qv,e=Jv,t=Gv,n=eb,r={},s=fn("start","drag","end"),o=0,a,l,c,u,f=0;function h(y){y.on("mousedown.drag",d).filter(n).on("touchstart.drag",I).on("touchmove.drag",w,Zv).on("touchend.drag touchcancel.drag",M).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(y,R){if(!(u||!i.call(this,y,R))){var B=k(this,e.call(this,y,R),y,R,"mouse");B&&(Ae(y.view).on("mousemove.drag",_,tn).on("mouseup.drag",P,tn),Uu(y.view),Oo(y),c=!1,a=y.clientX,l=y.clientY,B("start",y))}}function _(y){if(vi(y),!c){var R=y.clientX-a,B=y.clientY-l;c=R*R+B*B>f}r.mouse("drag",y)}function P(y){Ae(y.view).on("mousemove.drag mouseup.drag",null),zu(y.view,c),vi(y),r.mouse("end",y)}function I(y,R){if(i.call(this,y,R)){var B=y.changedTouches,U=e.call(this,y,R),W=B.length,q,Q;for(q=0;q<W;++q)(Q=k(this,U,y,R,B[q].identifier,B[q]))&&(Oo(y),Q("start",y,B[q]))}}function w(y){var R=y.changedTouches,B=R.length,U,W;for(U=0;U<B;++U)(W=r[R[U].identifier])&&(vi(y),W("drag",y,R[U]))}function M(y){var R=y.changedTouches,B=R.length,U,W;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),U=0;U<B;++U)(W=r[R[U].identifier])&&(Oo(y),W("end",y,R[U]))}function k(y,R,B,U,W,q){var Q=s.copy(),O=St(q||B,R),le,ee,C;if((C=t.call(y,new Bo("beforestart",{sourceEvent:B,target:h,identifier:W,active:o,x:O[0],y:O[1],dx:0,dy:0,dispatch:Q}),U))!=null)return le=C.x-O[0]||0,ee=C.y-O[1]||0,function L(F,V,Z){var j=O,G;switch(F){case"start":r[W]=L,G=o++;break;case"end":delete r[W],--o;case"drag":O=St(Z||V,R),G=o;break}Q.call(F,y,new Bo(F,{sourceEvent:V,subject:C,target:h,identifier:W,active:G,x:O[0]+le,y:O[1]+ee,dx:O[0]-j[0],dy:O[1]-j[1],dispatch:Q}),U)}}return h.filter=function(y){return arguments.length?(i=typeof y=="function"?y:wr(!!y),h):i},h.container=function(y){return arguments.length?(e=typeof y=="function"?y:wr(y),h):e},h.subject=function(y){return arguments.length?(t=typeof y=="function"?y:wr(y),h):t},h.touchable=function(y){return arguments.length?(n=typeof y=="function"?y:wr(!!y),h):n},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 Ar=i=>()=>i;function ib(i,{sourceEvent:e,target:t,transform:n,dispatch:r}){Object.defineProperties(this,{type:{value:i,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:r}})}function kt(i,e,t){this.k=i,this.x=e,this.y=t}kt.prototype={constructor:kt,scale:function(i){return i===1?this:new kt(this.k*i,this.x,this.y)},translate:function(i,e){return i===0&e===0?this:new kt(this.k,this.x+this.k*i,this.y+this.k*e)},apply:function(i){return[i[0]*this.k+this.x,i[1]*this.k+this.y]},applyX:function(i){return i*this.k+this.x},applyY:function(i){return i*this.k+this.y},invert:function(i){return[(i[0]-this.x)/this.k,(i[1]-this.y)/this.k]},invertX:function(i){return(i-this.x)/this.k},invertY:function(i){return(i-this.y)/this.k},rescaleX:function(i){return i.copy().domain(i.range().map(this.invertX,this).map(i.invert,i))},rescaleY:function(i){return i.copy().domain(i.range().map(this.invertY,this).map(i.invert,i))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var nn=new kt(1,0,0);kt.prototype;function Uo(i){i.stopImmediatePropagation()}function rn(i){i.preventDefault(),i.stopImmediatePropagation()}function nb(i){return(!i.ctrlKey||i.type==="wheel")&&!i.button}function rb(){var i=this;return i instanceof SVGElement?(i=i.ownerSVGElement||i,i.hasAttribute("viewBox")?(i=i.viewBox.baseVal,[[i.x,i.y],[i.x+i.width,i.y+i.height]]):[[0,0],[i.width.baseVal.value,i.height.baseVal.value]]):[[0,0],[i.clientWidth,i.clientHeight]]}function Lu(){return this.__zoom||nn}function sb(i){return-i.deltaY*(i.deltaMode===1?.05:i.deltaMode?1:.002)*(i.ctrlKey?10:1)}function ob(){return navigator.maxTouchPoints||"ontouchstart"in this}function ab(i,e,t){var n=i.invertX(e[0][0])-t[0][0],r=i.invertX(e[1][0])-t[1][0],s=i.invertY(e[0][1])-t[0][1],o=i.invertY(e[1][1])-t[1][1];return i.translate(r>n?(n+r)/2:Math.min(0,n)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function lb(){var i=nb,e=rb,t=ab,n=sb,r=ob,s=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=Pd,c=fn("start","zoom","end"),u,f,h,d=500,_=150,P=0,I=10;function w(C){C.property("__zoom",Lu).on("wheel.zoom",W,{passive:!1}).on("mousedown.zoom",q).on("dblclick.zoom",Q).filter(r).on("touchstart.zoom",O).on("touchmove.zoom",le).on("touchend.zoom touchcancel.zoom",ee).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}w.transform=function(C,L,F,V){var Z=C.selection?C.selection():C;Z.property("__zoom",Lu),C!==Z?R(C,L,F,V):Z.interrupt().each(function(){B(this,arguments).event(V).start().zoom(null,typeof L=="function"?L.apply(this,arguments):L).end()})},w.scaleBy=function(C,L,F,V){w.scaleTo(C,function(){var Z=this.__zoom.k,j=typeof L=="function"?L.apply(this,arguments):L;return Z*j},F,V)},w.scaleTo=function(C,L,F,V){w.transform(C,function(){var Z=e.apply(this,arguments),j=this.__zoom,G=F==null?y(Z):typeof F=="function"?F.apply(this,arguments):F,J=j.invert(G),me=typeof L=="function"?L.apply(this,arguments):L;return t(k(M(j,me),G,J),Z,o)},F,V)},w.translateBy=function(C,L,F,V){w.transform(C,function(){return t(this.__zoom.translate(typeof L=="function"?L.apply(this,arguments):L,typeof F=="function"?F.apply(this,arguments):F),e.apply(this,arguments),o)},null,V)},w.translateTo=function(C,L,F,V,Z){w.transform(C,function(){var j=e.apply(this,arguments),G=this.__zoom,J=V==null?y(j):typeof V=="function"?V.apply(this,arguments):V;return t(nn.translate(J[0],J[1]).scale(G.k).translate(typeof L=="function"?-L.apply(this,arguments):-L,typeof F=="function"?-F.apply(this,arguments):-F),j,o)},V,Z)};function M(C,L){return L=Math.max(s[0],Math.min(s[1],L)),L===C.k?C:new kt(L,C.x,C.y)}function k(C,L,F){var V=L[0]-F[0]*C.k,Z=L[1]-F[1]*C.k;return V===C.x&&Z===C.y?C:new kt(C.k,V,Z)}function y(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function R(C,L,F,V){C.on("start.zoom",function(){B(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){B(this,arguments).event(V).end()}).tween("zoom",function(){var Z=this,j=arguments,G=B(Z,j).event(V),J=e.apply(Z,j),me=F==null?y(J):typeof F=="function"?F.apply(Z,j):F,fe=Math.max(J[1][0]-J[0][0],J[1][1]-J[0][1]),Te=Z.__zoom,re=typeof L=="function"?L.apply(Z,j):L,Xe=l(Te.invert(me).concat(fe/Te.k),re.invert(me).concat(fe/re.k));return function(Be){if(Be===1)Be=re;else{var Ee=Xe(Be),bi=fe/Ee[2];Be=new kt(bi,me[0]-Ee[0]*bi,me[1]-Ee[1]*bi)}G.zoom(null,Be)}})}function B(C,L,F){return!F&&C.__zooming||new U(C,L)}function U(C,L){this.that=C,this.args=L,this.active=0,this.sourceEvent=null,this.extent=e.apply(C,L),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,L){return this.mouse&&C!=="mouse"&&(this.mouse[1]=L.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=L.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=L.invert(this.touch1[0])),this.that.__zoom=L,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var L=Ae(this.that).datum();c.call(C,this.that,new ib(C,{sourceEvent:this.sourceEvent,target:w,transform:this.that.__zoom,dispatch:c}),L)}};function W(C,...L){if(!i.apply(this,arguments))return;var F=B(this,L).event(C),V=this.__zoom,Z=Math.max(s[0],Math.min(s[1],V.k*Math.pow(2,n.apply(this,arguments)))),j=St(C);if(F.wheel)(F.mouse[0][0]!==j[0]||F.mouse[0][1]!==j[1])&&(F.mouse[1]=V.invert(F.mouse[0]=j)),clearTimeout(F.wheel);else{if(V.k===Z)return;F.mouse=[j,V.invert(j)],vn(this),F.start()}rn(C),F.wheel=setTimeout(G,_),F.zoom("mouse",t(k(M(V,Z),F.mouse[0],F.mouse[1]),F.extent,o));function G(){F.wheel=null,F.end()}}function q(C,...L){if(h||!i.apply(this,arguments))return;var F=C.currentTarget,V=B(this,L,!0).event(C),Z=Ae(C.view).on("mousemove.zoom",me,!0).on("mouseup.zoom",fe,!0),j=St(C,F),G=C.clientX,J=C.clientY;Uu(C.view),Uo(C),V.mouse=[j,this.__zoom.invert(j)],vn(this),V.start();function me(Te){if(rn(Te),!V.moved){var re=Te.clientX-G,Xe=Te.clientY-J;V.moved=re*re+Xe*Xe>P}V.event(Te).zoom("mouse",t(k(V.that.__zoom,V.mouse[0]=St(Te,F),V.mouse[1]),V.extent,o))}function fe(Te){Z.on("mousemove.zoom mouseup.zoom",null),zu(Te.view,V.moved),rn(Te),V.event(Te).end()}}function Q(C,...L){if(i.apply(this,arguments)){var F=this.__zoom,V=St(C.changedTouches?C.changedTouches[0]:C,this),Z=F.invert(V),j=F.k*(C.shiftKey?.5:2),G=t(k(M(F,j),V,Z),e.apply(this,L),o);rn(C),a>0?Ae(this).transition().duration(a).call(R,G,V,C):Ae(this).call(w.transform,G,V,C)}}function O(C,...L){if(i.apply(this,arguments)){var F=C.touches,V=F.length,Z=B(this,L,C.changedTouches.length===V).event(C),j,G,J,me;for(Uo(C),G=0;G<V;++G)J=F[G],me=St(J,this),me=[me,this.__zoom.invert(me),J.identifier],Z.touch0?!Z.touch1&&Z.touch0[2]!==me[2]&&(Z.touch1=me,Z.taps=0):(Z.touch0=me,j=!0,Z.taps=1+!!u);u&&(u=clearTimeout(u)),j&&(Z.taps<2&&(f=me[0],u=setTimeout(function(){u=null},d)),vn(this),Z.start())}}function le(C,...L){if(this.__zooming){var F=B(this,L).event(C),V=C.changedTouches,Z=V.length,j,G,J,me;for(rn(C),j=0;j<Z;++j)G=V[j],J=St(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 fe=F.touch0[0],Te=F.touch0[1],re=F.touch1[0],Xe=F.touch1[1],Be=(Be=re[0]-fe[0])*Be+(Be=re[1]-fe[1])*Be,Ee=(Ee=Xe[0]-Te[0])*Ee+(Ee=Xe[1]-Te[1])*Ee;G=M(G,Math.sqrt(Be/Ee)),J=[(fe[0]+re[0])/2,(fe[1]+re[1])/2],me=[(Te[0]+Xe[0])/2,(Te[1]+Xe[1])/2]}else if(F.touch0)J=F.touch0[0],me=F.touch0[1];else return;F.zoom("touch",t(k(G,J,me),F.extent,o))}}function ee(C,...L){if(this.__zooming){var F=B(this,L).event(C),V=C.changedTouches,Z=V.length,j,G;for(Uo(C),h&&clearTimeout(h),h=setTimeout(function(){h=null},d),j=0;j<Z;++j)G=V[j],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=St(G,this),Math.hypot(f[0]-G[0],f[1]-G[1])<I)){var J=Ae(this).on("dblclick.zoom");J&&J.apply(this,arguments)}}}return w.wheelDelta=function(C){return arguments.length?(n=typeof C=="function"?C:Ar(+C),w):n},w.filter=function(C){return arguments.length?(i=typeof C=="function"?C:Ar(!!C),w):i},w.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:Ar(!!C),w):r},w.extent=function(C){return arguments.length?(e=typeof C=="function"?C:Ar([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),w):e},w.scaleExtent=function(C){return arguments.length?(s[0]=+C[0],s[1]=+C[1],w):[s[0],s[1]]},w.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],w):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},w.constrain=function(C){return arguments.length?(t=C,w):t},w.duration=function(C){return arguments.length?(a=+C,w):a},w.interpolate=function(C){return arguments.length?(l=C,w):l},w.on=function(){var C=c.on.apply(c,arguments);return C===c?w:C},w.clickDistance=function(C){return arguments.length?(P=(C=+C)*C,w):Math.sqrt(P)},w.tapDistance=function(C){return arguments.length?(I=+C,w):I},w}class cb{constructor(e,t){this.eventTransform=nn,this.behavior=lb().scaleExtent([.001,1/0]).on("start",n=>{var s,o;this.isRunning=!0;const r=!!n.sourceEvent;r&&(this.shouldEnableSimulationDuringZoomOverride=void 0),(o=(s=this.config).onZoomStart)==null||o.call(s,n,r)}).on("zoom",n=>{var h,d;this.eventTransform=n.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;Yx(a,c,u),xc(a,a,[r,s]),Js(a,a,[o,o]),xc(a,a,[c/2,u/2]),Js(a,a,[c/2,u/2]),Js(a,a,[1,-1]);const f=!!n.sourceEvent;(d=(h=this.config).onZoom)==null||d.call(h,n,f)}).on("end",n=>{var s,o;this.isRunning=!1;const r=!!n.sourceEvent;(o=(s=this.config).onZoomEnd)==null||o.call(s,n,r)}),this.isRunning=!1,this.shouldEnableSimulationDuringZoomOverride=void 0,this.store=e,this.config=t}getTransform(e,t,n=.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 B=e[R],U=e[R+1];B<a&&(a=B),B>l&&(l=B),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-n*2)/(f[1]-f[0]),_=o*(1-n*2)/(h[0]-h[1]),P=Oc(t??Math.min(d,_),...this.behavior.scaleExtent()),I=(f[1]+f[0])/2,w=(h[1]+h[0])/2,M=s/2-I*P,k=o/2-w*P;return nn.translate(M,k).scale(P)}getDistanceToPoint(e){const{x:t,y:n,k:r}=this.eventTransform,s=this.getTransform(e,r),o=t-s.x,a=n-s.y;return Math.sqrt(o*o+a*a)}getMiddlePointTransform(e){const{store:{screenSize:t},eventTransform:{x:n,y:r,k:s}}=this,o=t[0],a=t[1],l=(o/2-n)/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,P=o/2-h*_,I=a/2-d*_;return nn.translate(P,I).scale(_)}convertScreenToSpacePosition(e){const{eventTransform:{x:t,y:n,k:r},store:{screenSize:s}}=this,o=s[0],a=s[1],l=(e[0]-t)/r,c=(e[1]-n)/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])),n=this.eventTransform.applyY(this.store.scaleY(e[1]));return[t,n]}convertSpaceToScreenRadius(e){const{config:{scalePointsOnZoom:t},store:{maxPointSize:n},eventTransform:{k:r}}=this;let s=e*2;return t?s*=r:s*=Math.min(5,Math.max(1,r*.01)),Math.min(s,n)/2}}class ub{constructor(e,t,n){this.isActive=!1,this.behavior=tb().subject(r=>{if(!(this.transition.isActiveFor(be.Positions)||this.transition.isActiveFor(be.PointSizes)))return this.store.hoveredPoint&&!this.store.isSpaceKeyPressed?{x:r.x,y:r.y}:void 0}).on("start",r=>{var s,o;this.store.hoveredPoint&&(this.store.draggingPointIndex=this.store.hoveredPoint.index,this.isActive=!0,(o=(s=this.config).onDragStart)==null||o.call(s,r))}).on("drag",r=>{var s,o;(o=(s=this.config).onDrag)==null||o.call(s,r)}).on("end",r=>{var s,o;this.isActive=!1,this.store.draggingPointIndex=void 0,(o=(s=this.config).onDragEnd)==null||o.call(s,r)}),this.store=e,this.config=t,this.transition=n}}class fb{constructor(e,t,n){if(this.config=Lc(),this.graph=new By(this.config),this.isReady=!1,this.requestAnimationFrameId=0,this.isRightClickMouse=!1,this.store=new Ny,this.zoomInstance=new cb(this.store,this.config),this.transition=new zy(this.config),this.dragInstance=new ub(this.store,this.config,this.transition),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&&lo(this.config,t),n)this.deviceInitPromise=n,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);n&&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=Ae(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()}),Ae(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=so(s,this.config.pixelRatio),this.store.isSimulationRunning=this.config.enableSimulation,this.points=new Kv(s,this.config,this.store,this.graph),this.points.transition=this.transition,this.lines=new Ev(s,this.config,this.store,this.graph,this.points),this.config.enableSimulation&&(this.forceGravity=new Fu(s,this.config,this.store,this.graph,this.points),this.forceCenter=new Du(s,this.config,this.store,this.graph,this.points),this.forceManyBody=new Mu(s,this.config,this.store,this.graph,this.points),this.forceLinkIncoming=new Tr(s,this.config,this.store,this.graph,this.points),this.forceLinkOutgoing=new Tr(s,this.config,this.store,this.graph,this.points),this.forceMouse=new Nu(s,this.config,this.store,this.graph,this.points)),this.clusters=new yv(s,this.config,this.store,this.graph,this.points),this.store.backgroundColor=_t(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.setOutlinedPointRingColor(this.config.outlinedPointRingColor),this.store.setHighlightedPointSet(this.config.highlightedPointIndices),this.store.setOutlinedPointSet(this.config.outlinedPointIndices),this.store.setHoveredLinkColor(this.config.hoveredLinkColor),this.store.updateLinkHoveringEnabled(this.config),this.config.showFPSMonitor&&(this.fpsMonitor=new Ou(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};Ly(this.config),lo(this.config,e),this.preserveInitOnlyFields(t),this.updateStateFromConfig(t)}setConfigPartial(e){if(this._isDestroyed||this.ensureDevice(()=>this.setConfigPartial(e)))return;const t={...this.config};lo(this.config,e,!0),this.preserveInitOnlyFields(t),this.updateStateFromConfig(t)}setPointPositions(e,t){var r;if(this._isDestroyed||this.ensureDevice(()=>this.setPointPositions(e,t)))return;this.graph.inputPointPositions=e,this.points.shouldSkipRescale=t,this.isPointPositionsUpdateNeeded=!0;const n=(r=this.points)==null?void 0:r.currentPositionTexture;n&&!n.destroyed&&this.transition.queue(be.Positions),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,this.transition.queue(be.PointColors))}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,this.transition.queue(be.PointSizes))}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,this.transition.queue(be.LinkColors))}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,this.transition.queue(be.LinkWidths))}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){var u,f,h;if(this._isDestroyed||this.ensureDevice(()=>this.render(e)))return;this.graph.update();const{fitViewOnInit:t,fitViewDelay:n,fitViewPadding:r,fitViewDuration:s,fitViewByPointsInRect:o,fitViewByPointIndices:a,initialZoomLevel:l}=this.config;if(!this.graph.pointsNumber&&!this.graph.linksNumber){this.stopFrames(),Ae(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)},n)),this.update(e),this.transition.isPendingFor(be.Positions)&&this.store.isSimulationRunning&&this.config.transitionDuration>0&&!this._isFirstRenderAfterInit&&(this.store.isSimulationRunning=!1,(f=(u=this.config).onSimulationPause)==null||f.call(u));const c=(h=this.points)==null?void 0:h.currentPositionTexture;this.transition.isPending&&(!c||c.destroyed)&&this.transition.abort(),this.transition.start(),this._shouldForceHoverDetection=!0,this.startFrames(),this._isFirstRenderAfterInit=!1}zoomToPointByIndex(e,t=700,n=3,r=!0,s=!0){if(this._isDestroyed||this.ensureDevice(()=>this.zoomToPointByIndex(e,t,n,r,s))||!this.device||!this.points||!this.canvasD3Selection)return;const{store:{screenSize:o}}=this,a=He(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?n:Math.max(this.getZoomLevel(),n);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(Ba).duration(t/2).call(this.zoomInstance.behavior.transform,d).transition().ease(Ua).duration(t/2).call(this.zoomInstance.behavior.transform,h)}}zoom(e,t=0,n=!0){this._isDestroyed||this.setZoomLevel(e,t,n)}setZoomLevel(e,t=0,n=!0){this._isDestroyed||this.ensureDevice(()=>this.setZoomLevel(e,t,n))||this.canvasD3Selection&&(this.zoomInstance.shouldEnableSimulationDuringZoomOverride=n,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=He(this.device,this.points.currentPositionFbo);e.length=this.graph.pointsNumber*2;for(let n=0;n<this.graph.pointsNumber;n+=1){const r=t[n*4+0],s=t[n*4+1];r!==void 0&&s!==void 0&&(e[n*2]=r,e[n*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,n=!0){this._isDestroyed||this.ensureDevice(()=>this.fitView(e,t,n))||this.setZoomTransformByPointPositions(this.getFitViewPositions(),e,void 0,t,n)}fitViewByPointIndices(e,t=250,n=.1,r=!0){if(this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointIndices(e,t,n,r)))return;const s=this.getFitViewPositions(),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,n,r)}fitViewByPointPositions(e,t=250,n=.1,r=!0){this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointPositions(e,t,n,r))||this.setZoomTransformByPointPositions(new Float32Array(e),t,void 0,n,r)}setZoomTransformByPointPositions(e,t=250,n,r=.1,s=!0){var a;if(this._isDestroyed||this.ensureDevice(()=>this.setZoomTransformByPointPositions(e,t,n,r,s)))return;this.zoomInstance.shouldEnableSimulationDuringZoomOverride=s,this.resizeCanvas();const o=this.zoomInstance.getTransform(e,n,r);(a=this.canvasD3Selection)==null||a.transition().ease(za).duration(t).call(this.zoomInstance.behavior.transform,o)}findPointsInRect(e){if(this._isDestroyed)return[];if(!this.isReady||!this.device||!this.points)return[];const t=this.store.screenSize[1];return this.store.searchArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsInRect()?ro(He(this.device,this.points.searchFbo)):[]}findPointsInPolygon(e){if(this._isDestroyed)return[];if(!this.isReady||!this.device||!this.points)return[];if(e.length<3)return console.warn("Polygon path requires at least 3 points to form a polygon."),[];const t=this.store.screenSize[1],n=e.map(([r,s])=>[r,t-s]);return this.points.updatePolygonPath(n),this.points.findPointsInPolygon()?ro(He(this.device,this.points.searchFbo)):[]}getNeighboringPointIndices(e){return this._isDestroyed?[]:this.graph.getNeighboringPointIndices(e)}getConnectedLinkIndices(e){return this._isDestroyed?[]:this.graph.getConnectedLinkIndices(e)}getConnectedPointIndices(e){return this._isDestroyed?[]:this.graph.getConnectedPointIndices(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],n=(s=this.graph.pointImageSizes)==null?void 0:s[e];if(!(t===void 0&&n===void 0))return Math.max(t??0,n??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 n,r;if(this._isDestroyed||this.ensureDevice(()=>this.start(e))||!this.config.enableSimulation||!this.graph.pointsNumber)return;this.transition.isActiveFor(be.Positions)&&this.transition.end(!0);const t=this.store.isSimulationRunning;this.store.isSimulationRunning=!0,this.store.simulationProgress=0,this.store.alpha=e,t||(r=(n=this.config).onSimulationStart)==null||r.call(n)}stop(){var t,n;if(this._isDestroyed)return;const e=this.store.isSimulationRunning||this.store.alpha>0||this.store.simulationProgress>0;this.store.isSimulationRunning=!1,this.store.simulationProgress=0,this.store.alpha=0,e&&((n=(t=this.config).onSimulationEnd)==null||n.call(t))}pause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.pause())||this.store.isSimulationRunning&&(this.store.isSimulationRunning=!1,(t=(e=this.config).onSimulationPause)==null||t.call(e))}unpause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.unpause())||this.config.enableSimulation&&(this.store.isSimulationRunning||(this.transition.isActiveFor(be.Positions)&&this.transition.end(!0),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,n,r,s,o,a,l,c,u,f,h,d;this._isDestroyed||(this._isDestroyed=!0,this.isReady=!1,this.transition.abort(),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),Ae(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),(n=this.fpsMonitor)==null||n.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,n,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(No.INCOMING),(n=this.forceLinkOutgoing)==null||n.create(No.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 n=0;n<e.length/2;n++)t[n]=[e[n*2],e[n*2+1]];return t}preserveInitOnlyFields(e){this.config.initialZoomLevel=e.initialZoomLevel,this.config.randomSeed=e.randomSeed,this.config.attribution=e.attribution}getFitViewPositions(){return this.transition.isActive&&this.transition.isActiveFor(be.Positions)&&!!this.graph.pointPositions&&this.graph.pointPositions?new Float32Array(this.graph.pointPositions):new Float32Array(this.getPointPositions())}updateStateFromConfig(e){var t,n,r,s,o,a,l,c,u,f,h,d;this.applyEnableSimulationConfigChange(e),e.pointDefaultColor!==this.config.pointDefaultColor&&(this.graph.updatePointColor(),(t=this.points)==null||t.updateColor()),e.pointDefaultSize!==this.config.pointDefaultSize&&(this.graph.updatePointSize(),(n=this.points)==null||n.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=_t(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.outlinedPointRingColor!==this.config.outlinedPointRingColor&&this.store.setOutlinedPointRingColor(this.config.outlinedPointRingColor),e.highlightedPointIndices!==this.config.highlightedPointIndices&&this.store.setHighlightedPointSet(this.config.highlightedPointIndices),e.outlinedPointIndices!==this.config.outlinedPointIndices&&this.store.setOutlinedPointSet(this.config.outlinedPointIndices),(e.highlightedPointIndices!==this.config.highlightedPointIndices||e.outlinedPointIndices!==this.config.outlinedPointIndices)&&((c=this.points)==null||c.updatePointStatus()),e.highlightedLinkIndices!==this.config.highlightedLinkIndices&&((u=this.lines)==null||u.updateLinkStatus()),e.pixelRatio!==this.config.pixelRatio&&(f=this.device)!=null&&f.canvasContext&&(this.device.canvasContext.setProps({useDevicePixels:this.config.pixelRatio}),this.store.maxPointSize=so(this.device,this.config.pixelRatio)),e.spaceSize!==this.config.spaceSize&&(this.store.adjustSpaceSize(this.config.spaceSize,((h=this.device)==null?void 0:h.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 Ou(this.canvas):((d=this.fpsMonitor)==null||d.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)}applyEnableSimulationConfigChange(e){var n,r,s,o,a;if(e.enableSimulation===this.config.enableSimulation)return;if(this.config.enableSimulation){this.transition.end(!0),this.transition.dequeue(be.Positions),this.ensureSimulationModules(),(n=this.points)==null||n.ensureSimulationResources(),this.isForceManyBodyUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0,this.isForceCenterUpdateNeeded=!0,this.create(),this.initPrograms(),this.store.simulationProgress=0,this.store.alpha=1,this.store.isSimulationRunning=!0,this._shouldForceHoverDetection=!0,(s=(r=this.config).onSimulationStart)==null||s.call(r);return}const t=this.store.isSimulationRunning||this.store.alpha>0||this.store.simulationProgress>0;this.store.isSimulationRunning=!1,this.store.alpha=0,this.store.simulationProgress=0,this._shouldForceHoverDetection=!0,t&&((a=(o=this.config).onSimulationEnd)==null||a.call(o)),this.destroySimulationModules()}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 vg.createDevice({type:"webgl",adapters:[ym],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,_,P,I,w,M,k,y,R,B,U,W,q,Q,O,le,ee,C,L,F,V;const{config:{simulationGravity:t,simulationCenter:n,enableSimulation:r},store:{isSimulationRunning:s}}=this;if(!r)return;this.isRightClickMouse&&this.config.enableRightClickRepulsion&&((l=this.points)==null||l.swapFbo(),(c=this.forceMouse)==null||c.run(),(u=this.points)==null||u.updatePosition());const o=this.zoomInstance.shouldEnableSimulationDuringZoomOverride??this.config.enableSimulationDuringZoom;(e||s&&!(this.zoomInstance.isRunning&&!o))&&(t&&((f=this.points)==null||f.swapFbo(),(h=this.forceGravity)==null||h.run(),(d=this.points)==null||d.updatePosition()),n&&((_=this.points)==null||_.swapFbo(),(P=this.forceCenter)==null||P.run(),(I=this.points)==null||I.updatePosition()),(w=this.points)==null||w.swapFbo(),(M=this.forceManyBody)==null||M.run(),(k=this.points)==null||k.updatePosition(),this.store.linksTextureSize&&((y=this.points)==null||y.swapFbo(),(R=this.forceLinkIncoming)==null||R.run(),(B=this.points)==null||B.updatePosition(),(U=this.points)==null||U.swapFbo(),(W=this.forceLinkOutgoing)==null||W.run(),(q=this.points)==null||q.updatePosition()),(this.graph.pointClusters||this.graph.clusterPositions)&&((Q=this.points)==null||Q.swapFbo(),(O=this.clusters)==null||O.run(),(le=this.points)==null||le.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,io/this.store.alpha)),(F=(L=this.config).onSimulationTick)==null||F.call(L,this.store.alpha,(ee=this.store.hoveredPoint)==null?void 0:ee.index,(C=this.store.hoveredPoint)==null?void 0:C.position)),(V=this.points)==null||V.trackPoints()}initPrograms(){var e,t,n,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(),(n=this.forceCenter)==null||n.initPrograms(),(r=this.forceLinkIncoming)==null||r.initPrograms(),(s=this.forceLinkOutgoing)==null||s.initPrograms(),(o=this.forceMouse)==null||o.initPrograms(),this.clusters.initPrograms())}ensureSimulationModules(){!this.device||!this.points||(this.forceGravity||(this.forceGravity=new Fu(this.device,this.config,this.store,this.graph,this.points)),this.forceCenter||(this.forceCenter=new Du(this.device,this.config,this.store,this.graph,this.points)),this.forceManyBody||(this.forceManyBody=new Mu(this.device,this.config,this.store,this.graph,this.points)),this.forceLinkIncoming||(this.forceLinkIncoming=new Tr(this.device,this.config,this.store,this.graph,this.points)),this.forceLinkOutgoing||(this.forceLinkOutgoing=new Tr(this.device,this.config,this.store,this.graph,this.points)),this.forceMouse||(this.forceMouse=new Nu(this.device,this.config,this.store,this.graph,this.points)))}destroySimulationModules(){var e,t,n,r,s,o,a;(e=this.forceGravity)==null||e.destroy(),this.forceGravity=void 0,(t=this.forceCenter)==null||t.destroy(),this.forceCenter=void 0,(n=this.forceManyBody)==null||n.destroy(),this.forceManyBody=void 0,(r=this.forceLinkIncoming)==null||r.destroy(),this.forceLinkIncoming=void 0,(s=this.forceLinkOutgoing)==null||s.destroy(),this.forceLinkOutgoing=void 0,(o=this.forceMouse)==null||o.destroy(),this.forceMouse=void 0,(a=this.points)==null||a.destroySimulationResources()}frame(){if(this._isDestroyed)return;const{store:{alpha:e,isSimulationRunning:t}}=this;e<io&&t&&this.end(),this.requestAnimationFrameId=window.requestAnimationFrame(n=>{this.renderFrame(n),this._isDestroyed||this.frame()})}renderFrame(e){var l,c,u,f,h,d,_,P,I,w;if(this._isDestroyed||!this.store.pointsTextureSize)return;const t=e??performance.now();(l=this.fpsMonitor)==null||l.begin(),this.resizeCanvas();const n=this.transition.isActiveFor(be.Positions),r=this.transition.isActiveFor(be.PointColors),s=this.transition.isActiveFor(be.PointSizes),o=this.transition.isActiveFor(be.LinkColors),a=this.transition.isActiveFor(be.LinkWidths);if(this.transition.isActive&&(this.transition.step(),n&&((c=this.points)==null||c.interpolatePosition(this.transition.progress))),(u=this.points)==null||u.setTransitionProgress(this.transition.progress,r,s),(f=this.lines)==null||f.setTransitionProgress(this.transition.progress,o,a),this.dragInstance.isActive||this.findHoveredItem(),this.runSimulationStep(!1),this.device){const M=this.store.backgroundColor??[0,0,0,1],k=this.device.beginRenderPass({clearColor:M,clearDepth:1,clearStencil:0}),{config:{renderLinks:y}}=this;y!==!1&&!!this.store.linksTextureSize&&!!this.graph.linksNumber&&this.graph.linksNumber>0&&((h=this.lines)==null||h.draw(k)),(d=this.points)==null||d.draw(k),this.dragInstance.isActive&&((_=this.points)==null||_.swapFbo(),(P=this.points)==null||P.drag(),(I=this.points)==null||I.trackPoints()),k.end(),this.device.submit()}(w=this.fpsMonitor)==null||w.end(t),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,n,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,(n=this.store.hoveredPoint)==null?void 0:n.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,n=e.offsetY??e.y;t===void 0||n===void 0||(this.store.mousePosition=this.zoomInstance.convertScreenToSpacePosition([t,n]),this.store.screenMousePosition=[t,this.store.screenSize[1]-n])}onMouseMove(e){var t,n,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,(n=this.store.hoveredPoint)==null?void 0:n.position,this.currentEvent)}onContextMenu(e){var t,n,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,(n=this.store.hoveredPoint)==null?void 0:n.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,n=this.canvas.clientHeight,[r,s]=this.store.screenSize;if(e||r!==t||s!==n){const{k:u}=this.zoomInstance.eventTransform,f=this.zoomInstance.convertScreenToSpacePosition([r/2,s/2]);this.store.updateScreenSize(t,n),(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,n,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?(n=this.canvasD3Selection)==null||n.call(this.zoomInstance.behavior):(r=this.canvasD3Selection)==null||r.call(this.zoomInstance.behavior).on("wheel.zoom",null)}findHoveredItem(){var o,a,l,c,u,f,h,d,_,P;if(this._isDestroyed||!this._isMouseOnCanvas||this.transition.isActiveFor(be.PointSizes))return;if(this._findHoveredItemExecutionCount<My){this._findHoveredItemExecutionCount+=1;return}const e=Math.abs(this._lastMouseX-this._lastCheckedMouseX),t=Math.abs(this._lastMouseY-this._lastCheckedMouseY);if(!(e>Ec||t>Ec)&&!this._shouldForceHoverDetection)return;this._lastCheckedMouseX=this._lastMouseX,this._lastCheckedMouseY=this._lastMouseY,this._shouldForceHoverDetection=!1,this._findHoveredItemExecutionCount=0;const r=this.findHoveredPoint();let s={mouseover:!1,mouseout:!1};if(this.graph.linksNumber&&this.store.isLinkHoveringEnabled?s=this.findHoveredLine():this.store.hoveredLinkIndex!==void 0&&(s.mouseout=!0,this.store.hoveredLinkIndex=void 0),r.mouseout&&((a=(o=this.config).onPointMouseOut)==null||a.call(o,this.currentEvent)),s.mouseout&&((c=(l=this.config).onLinkMouseOut)==null||c.call(l,this.currentEvent)),r.mouseover&&this.store.hoveredPoint){const I=this.store.hoveredPoint.index;(d=(h=this.config).onPointMouseOver)==null||d.call(h,this.store.hoveredPoint.index,this.store.hoveredPoint.position,this.currentEvent,((u=this.store.highlightedPointSet)==null?void 0:u.has(I))??!1,((f=this.store.outlinedPointSet)==null?void 0:f.has(I))??!1)}s.mouseover&&this.store.hoveredLinkIndex!==void 0&&((P=(_=this.config).onLinkMouseOver)==null||P.call(_,this.store.hoveredLinkIndex)),this.updateCanvasCursor()}findHoveredPoint(){if(this._isDestroyed||!this.device||!this.points)return{mouseover:!1,mouseout:!1};this.points.findHoveredPoint();let e=!1,t=!1;const n=He(this.device,this.points.hoveredFbo,0,0,2,2),r=n[0],s=n[1],o=n[2],a=n[3];return 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),{mouseover:e,mouseout:t}}findHoveredLine(){if(this._isDestroyed||!this.lines)return{mouseover:!1,mouseout:!1};if(this.store.hoveredPoint){const s=this.store.hoveredLinkIndex!==void 0;return s&&(this.store.hoveredLinkIndex=void 0),{mouseover:!1,mouseout:s}}this.lines.findHoveredLine();let e=!1,t=!1;if(!this.device)return{mouseover:!1,mouseout:!1};const r=He(this.device,this.lines.hoveredLineIndexFbo)[0];return r>=0?(this.store.hoveredLinkIndex!==r&&(e=!0),this.store.hoveredLinkIndex=r):(this.store.hoveredLinkIndex!==void 0&&(t=!0),this.store.hoveredLinkIndex=void 0),{mouseover:e,mouseout:t}}updateCanvasCursor(){const{hoveredPointCursor:e,hoveredLinkCursor:t}=this.config;this.dragInstance.isActive?Ae(this.canvas).style("cursor","grabbing"):this.store.hoveredPoint?!this.config.enableDrag||this.store.isSpaceKeyPressed?Ae(this.canvas).style("cursor",e):Ae(this.canvas).style("cursor","grab"):this.store.isLinkHoveringEnabled&&this.store.hoveredLinkIndex!==void 0?Ae(this.canvas).style("cursor",t):Ae(this.canvas).style("cursor",null)}addAttribution(){var e;this.config.attribution&&(this.attributionDivElement=document.createElement("div"),this.attributionDivElement.style.cssText=`
2385
2514
  user-select: none;
2386
2515
  position: absolute;
2387
2516
  bottom: 0;
@@ -2390,5 +2519,5 @@ void main() {
2390
2519
  margin: 0 0.6rem 0.6rem 0;
2391
2520
  font-size: 0.7rem;
2392
2521
  font-family: inherit;
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"})});
2522
+ `,this.attributionDivElement.innerHTML=Bc(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))}}oe.Graph=fb,oe.PointShape=oo,oe.TransitionEasing=ao,oe.clamp=Oc,oe.defaultConfigValues=At,oe.extractIndicesFromPixels=ro,oe.focusedPointRingOpacity=zc,oe.getMaxPointSize=so,oe.getRgbaColor=_t,oe.hoveredPointRingOpacity=Uc,oe.isAClassInstance=Mc,oe.isArray=no,oe.isFunction=Dc,oe.isNumber=Qe,oe.isObject=Fc,oe.isPlainObject=Oy,oe.readPixels=He,oe.rgbToBrightness=Nc,oe.sanitizeHtml=Bc,Object.defineProperty(oe,Symbol.toStringTag,{value:"Module"})});
2394
2523
  //# sourceMappingURL=index.min.js.map