diff --git a/docs/assets/index-jgfTJMVF.js b/docs/assets/index-DoezzRr4.js similarity index 57% rename from docs/assets/index-jgfTJMVF.js rename to docs/assets/index-DoezzRr4.js index 708b369..7753733 100644 --- a/docs/assets/index-jgfTJMVF.js +++ b/docs/assets/index-DoezzRr4.js @@ -1,62 +1,45 @@ -(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const d of i)if(d.type==="childList")for(const m of d.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&r(m)}).observe(document,{childList:!0,subtree:!0});function n(i){const d={};return i.integrity&&(d.integrity=i.integrity),i.referrerPolicy&&(d.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?d.credentials="include":i.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function r(i){if(i.ep)return;i.ep=!0;const d=n(i);fetch(i.href,d)}})();const Qi=(t,e)=>t===e,Ee=Symbol("solid-proxy"),Jr=Symbol("solid-track"),_n={equals:Qi};let Ss=Os;const be=1,$n=2,Ms={owned:null,cleanups:null,context:null,owner:null},or={};var ht=null;let ar=null,Ji=null,pt=null,It=null,ge=null,Wn=0;function to(t,e){const n=pt,r=ht,i=t.length===0,d=e===void 0?r:e,m=i?Ms:{owned:null,cleanups:null,context:d?d.context:null,owner:d},g=i?t:()=>t(()=>de(()=>Ke(m)));ht=m,pt=null;try{return Se(g,!0)}finally{pt=n,ht=r}}function qt(t,e){e=e?Object.assign({},_n,e):_n;const n={value:t,observers:null,observerSlots:null,comparator:e.equals||void 0},r=i=>(typeof i=="function"&&(i=i(n.value)),Us(n,i));return[Ds.bind(n),r]}function eo(t,e,n){const r=Cn(t,e,!0,be);Re(r)}function Ae(t,e,n){const r=Cn(t,e,!1,be);Re(r)}function rn(t,e,n){Ss=co;const r=Cn(t,e,!1,be);r.user=!0,ge?ge.push(r):Re(r)}function ve(t,e,n){n=n?Object.assign({},_n,n):_n;const r=Cn(t,e,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,Re(r),Ds.bind(r)}function no(t){return t&&typeof t=="object"&&"then"in t}function ro(t,e,n){let r,i,d;arguments.length===2&&typeof e=="object"||arguments.length===1?(r=!0,i=t,d=e):(r=t,i=e,d={});let m=null,g=or,S=!1,A="initialValue"in d,I=typeof r=="function"&&ve(r);const k=new Set,[F,z]=(d.storage||qt)(d.initialValue),[B,N]=qt(void 0),[q,tt]=qt(void 0,{equals:!1}),[st,ut]=qt(A?"ready":"unresolved");function rt(nt,K,Y,it){return m===nt&&(m=null,it!==void 0&&(A=!0),(nt===g||K===g)&&d.onHydrated&&queueMicrotask(()=>d.onHydrated(it,{value:K})),g=or,xt(K,Y)),K}function xt(nt,K){Se(()=>{K===void 0&&z(()=>nt),ut(K!==void 0?"errored":A?"ready":"unresolved"),N(K);for(const Y of k.keys())Y.decrement();k.clear()},!1)}function lt(){const nt=oo,K=F(),Y=B();if(Y!==void 0&&!m)throw Y;return pt&&pt.user,K}function vt(nt=!0){if(nt!==!1&&S)return;S=!1;const K=I?I():r;if(K==null||K===!1){rt(m,de(F));return}const Y=g!==or?g:de(()=>i(K,{value:F(),refetching:nt}));return no(Y)?(m=Y,"value"in Y?(Y.status==="success"?rt(m,Y.value,void 0,K):rt(m,void 0,hr(Y.value),K),Y):(S=!0,queueMicrotask(()=>S=!1),Se(()=>{ut(A?"refreshing":"pending"),tt()},!1),Y.then(it=>rt(Y,it,void 0,K),it=>rt(Y,void 0,hr(it),K)))):(rt(m,Y,void 0,K),Y)}return Object.defineProperties(lt,{state:{get:()=>st()},error:{get:()=>B()},loading:{get(){const nt=st();return nt==="pending"||nt==="refreshing"}},latest:{get(){if(!A)return lt();const nt=B();if(nt&&!m)throw nt;return F()}}}),I?eo(()=>vt(!1)):vt(!1),[lt,{refetch:vt,mutate:z}]}function Ts(t){return Se(t,!1)}function de(t){if(pt===null)return t();const e=pt;pt=null;try{return t()}finally{pt=e}}function sn(t){return ht===null||(ht.cleanups===null?ht.cleanups=[t]:ht.cleanups.push(t)),t}function fr(){return pt}function Or(t,e){const n=Symbol("context");return{id:n,Provider:lo(n),defaultValue:t}}function so(t){let e;return ht&&ht.context&&(e=ht.context[t.id])!==void 0?e:t.defaultValue}function io(t){const e=ve(t),n=ve(()=>dr(e()));return n.toArray=()=>{const r=n();return Array.isArray(r)?r:r!=null?[r]:[]},n}let oo;function Ds(){if(this.sources&&this.state)if(this.state===be)Re(this);else{const t=It;It=null,Se(()=>Mn(this),!1),It=t}if(pt){const t=this.observers?this.observers.length:0;pt.sources?(pt.sources.push(this),pt.sourceSlots.push(t)):(pt.sources=[this],pt.sourceSlots=[t]),this.observers?(this.observers.push(pt),this.observerSlots.push(pt.sources.length-1)):(this.observers=[pt],this.observerSlots=[pt.sources.length-1])}return this.value}function Us(t,e,n){let r=t.value;return(!t.comparator||!t.comparator(r,e))&&(t.value=e,t.observers&&t.observers.length&&Se(()=>{for(let i=0;i1e6)throw It=[],new Error},!1)),e}function Re(t){if(!t.fn)return;Ke(t);const e=Wn;ao(t,t.value,e)}function ao(t,e,n){let r;const i=ht,d=pt;pt=ht=t;try{r=t.fn(e)}catch(m){return t.pure&&(t.state=be,t.owned&&t.owned.forEach(Ke),t.owned=null),t.updatedAt=n+1,As(m)}finally{pt=d,ht=i}(!t.updatedAt||t.updatedAt<=n)&&(t.updatedAt!=null&&"observers"in t?Us(t,r):t.value=r,t.updatedAt=n)}function Cn(t,e,n,r=be,i){const d={fn:t,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:e,owner:ht,context:ht?ht.context:null,pure:n};return ht===null||ht!==Ms&&(ht.owned?ht.owned.push(d):ht.owned=[d]),d}function Sn(t){if(t.state===0)return;if(t.state===$n)return Mn(t);if(t.suspense&&de(t.suspense.inFallback))return t.suspense.effects.push(t);const e=[t];for(;(t=t.owner)&&(!t.updatedAt||t.updatedAt=0;n--)if(t=e[n],t.state===be)Re(t);else if(t.state===$n){const r=It;It=null,Se(()=>Mn(t,e[0]),!1),It=r}}function Se(t,e){if(It)return t();let n=!1;e||(It=[]),ge?n=!0:ge=[],Wn++;try{const r=t();return uo(n),r}catch(r){n||(ge=null),It=null,As(r)}}function uo(t){if(It&&(Os(It),It=null),t)return;const e=ge;ge=null,e.length&&Se(()=>Ss(e),!1)}function Os(t){for(let e=0;e=0;e--)Ke(t.tOwned[e]);delete t.tOwned}if(t.owned){for(e=t.owned.length-1;e>=0;e--)Ke(t.owned[e]);t.owned=null}if(t.cleanups){for(e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}t.state=0}function hr(t){return t instanceof Error?t:new Error(typeof t=="string"?t:"Unknown error",{cause:t})}function As(t,e=ht){throw hr(t)}function dr(t){if(typeof t=="function"&&!t.length)return dr(t());if(Array.isArray(t)){const e=[];for(let n=0;ni=de(()=>(ht.context={...ht.context,[t]:r.value},io(()=>r.children))),void 0),i}}function Kt(t,e){return de(()=>t(e||{}))}const fo=t=>`Stale read from <${t}>.`;function Er(t){const e=t.keyed,n=ve(()=>t.when,void 0,{equals:(r,i)=>e?r===i:!r==!i});return ve(()=>{const r=n();if(r){const i=t.children;return typeof i=="function"&&i.length>0?de(()=>i(e?r:()=>{if(!de(n))throw fo("Show");return t.when})):i}return t.fallback},void 0,void 0)}function ho(t,e,n){let r=n.length,i=e.length,d=r,m=0,g=0,S=e[i-1].nextSibling,A=null;for(;mI-g){const B=e[m];for(;g{i=d,e===document?t():mn(e,t(),e.firstChild?null:void 0,n)},r.owner),()=>{i(),e.textContent=""}}function Ar(t,e,n){let r;const i=()=>{const m=document.createElement("template");return m.innerHTML=t,m.content.firstChild},d=()=>(r||(r=i())).cloneNode(!0);return d.cloneNode=d,d}function yn(t,e){e==null?t.removeAttribute("class"):t.className=e}function wo(t,e,n){return de(()=>t(e,n))}function mn(t,e,n,r){if(n!==void 0&&!r&&(r=[]),typeof e!="function")return Tn(t,e,r,n);Ae(i=>Tn(t,e(),i,n),r)}function Tn(t,e,n,r,i){for(;typeof n=="function";)n=n();if(e===n)return n;const d=typeof e,m=r!==void 0;if(t=m&&n[0]&&n[0].parentNode||t,d==="string"||d==="number"){if(d==="number"&&(e=e.toString(),e===n))return n;if(m){let g=n[0];g&&g.nodeType===3?g.data!==e&&(g.data=e):g=document.createTextNode(e),n=Pe(t,n,r,g)}else n!==""&&typeof n=="string"?n=t.firstChild.data=e:n=t.textContent=e}else if(e==null||d==="boolean")n=Pe(t,n,r);else{if(d==="function")return Ae(()=>{let g=e();for(;typeof g=="function";)g=g();n=Tn(t,g,n,r)}),()=>n;if(Array.isArray(e)){const g=[],S=n&&Array.isArray(n);if(pr(g,e,n,i))return Ae(()=>n=Tn(t,g,n,r,!0)),()=>n;if(g.length===0){if(n=Pe(t,n,r),m)return n}else S?n.length===0?ts(t,g,r):ho(t,n,g):(n&&Pe(t),ts(t,g));n=g}else if(e.nodeType){if(Array.isArray(n)){if(m)return n=Pe(t,n,r,e);Pe(t,n,null,e)}else n==null||n===""||!t.firstChild?t.appendChild(e):t.replaceChild(e,t.firstChild);n=e}}return n}function pr(t,e,n,r){let i=!1;for(let d=0,m=e.length;d=0;m--){const g=e[m];if(i!==g){const S=g.parentNode===t;!d&&!m?S?t.replaceChild(i,g):t.insertBefore(i,n):S&&g.remove()}else d=!0}}else t.insertBefore(i,n);return[i]}const yo="_page_13ypr_1",mo="_circle-counter_13ypr_6",go="_welcome-message_13ypr_26",xo="_fade-in_13ypr_1",vo="_canvas_13ypr_41",dn={page:yo,circleCounter:mo,welcomeMessage:go,fadeIn:xo,canvas:vo};function kr(t,e,n){const r=so(t);if(r===void 0)throw new Error(`Called '${e}' outside of ${n!==void 0?`<${n}>`:"its Provider"}.`);return r}const ks=Or(),bo=ks.Provider;function Ir(){return kr(ks,"useCamera","CameraContext")}var _o=Object.defineProperty,$o=Object.defineProperties,So=Object.getOwnPropertyDescriptors,es=Object.getOwnPropertySymbols,Mo=Object.prototype.hasOwnProperty,To=Object.prototype.propertyIsEnumerable,wr=(t,e,n)=>e in t?_o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e)=>{for(var n in e||(e={}))Mo.call(e,n)&&wr(t,n,e[n]);if(es)for(var n of es(e))To.call(e,n)&&wr(t,n,e[n]);return t},ye=(t,e)=>$o(t,So(e)),E=(t,e,n)=>(wr(t,typeof e!="symbol"?e+"":e,n),n),Do="Invariant failed";function Dn(t,e){if(!t)throw new Error(Do)}var pn=class yr extends Error{constructor(e,n){let r=n.map(i=>`- ${i}`);r.length>20&&(r=[...r.slice(0,11),"...",...r.slice(-10)]),super(`Resolution of the following tree failed: +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const d of i)if(d.type==="childList")for(const m of d.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&r(m)}).observe(document,{childList:!0,subtree:!0});function n(i){const d={};return i.integrity&&(d.integrity=i.integrity),i.referrerPolicy&&(d.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?d.credentials="include":i.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function r(i){if(i.ep)return;i.ep=!0;const d=n(i);fetch(i.href,d)}})();const Ji=(t,e)=>t===e,ke=Symbol("solid-proxy"),Jr=Symbol("solid-track"),Sn={equals:Ji};let Ss=Os;const be=1,Mn=2,Ms={owned:null,cleanups:null,context:null,owner:null},or={};var ht=null;let ar=null,to=null,pt=null,It=null,xe=null,Yn=0;function eo(t,e){const n=pt,r=ht,i=t.length===0,d=e===void 0?r:e,m=i?Ms:{owned:null,cleanups:null,context:d?d.context:null,owner:d},g=i?t:()=>t(()=>pe(()=>Je(m)));ht=m,pt=null;try{return Se(g,!0)}finally{pt=n,ht=r}}function qt(t,e){e=e?Object.assign({},Sn,e):Sn;const n={value:t,observers:null,observerSlots:null,comparator:e.equals||void 0},r=i=>(typeof i=="function"&&(i=i(n.value)),Us(n,i));return[Ds.bind(n),r]}function no(t,e,n){const r=Xn(t,e,!0,be);Ne(r)}function Ie(t,e,n){const r=Xn(t,e,!1,be);Ne(r)}function Ae(t,e,n){Ss=lo;const r=Xn(t,e,!1,be);r.user=!0,xe?xe.push(r):Ne(r)}function de(t,e,n){n=n?Object.assign({},Sn,n):Sn;const r=Xn(t,e,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,Ne(r),Ds.bind(r)}function ro(t){return t&&typeof t=="object"&&"then"in t}function so(t,e,n){let r,i,d;arguments.length===2&&typeof e=="object"||arguments.length===1?(r=!0,i=t,d=e):(r=t,i=e,d={});let m=null,g=or,S=!1,A="initialValue"in d,P=typeof r=="function"&&de(r);const k=new Set,[F,z]=(d.storage||qt)(d.initialValue),[B,V]=qt(void 0),[L,tt]=qt(void 0,{equals:!1}),[it,ut]=qt(A?"ready":"unresolved");function st(rt,K,Y,ot){return m===rt&&(m=null,ot!==void 0&&(A=!0),(rt===g||K===g)&&d.onHydrated&&queueMicrotask(()=>d.onHydrated(ot,{value:K})),g=or,xt(K,Y)),K}function xt(rt,K){Se(()=>{K===void 0&&z(()=>rt),ut(K!==void 0?"errored":A?"ready":"unresolved"),V(K);for(const Y of k.keys())Y.decrement();k.clear()},!1)}function lt(){const rt=ao,K=F(),Y=B();if(Y!==void 0&&!m)throw Y;return pt&&pt.user,K}function vt(rt=!0){if(rt!==!1&&S)return;S=!1;const K=P?P():r;if(K==null||K===!1){st(m,pe(F));return}const Y=g!==or?g:pe(()=>i(K,{value:F(),refetching:rt}));return ro(Y)?(m=Y,"value"in Y?(Y.status==="success"?st(m,Y.value,void 0,K):st(m,void 0,fr(Y.value),K),Y):(S=!0,queueMicrotask(()=>S=!1),Se(()=>{ut(A?"refreshing":"pending"),tt()},!1),Y.then(ot=>st(Y,ot,void 0,K),ot=>st(Y,void 0,fr(ot),K)))):(st(m,Y,void 0,K),Y)}return Object.defineProperties(lt,{state:{get:()=>it()},error:{get:()=>B()},loading:{get(){const rt=it();return rt==="pending"||rt==="refreshing"}},latest:{get(){if(!A)return lt();const rt=B();if(rt&&!m)throw rt;return F()}}}),P?no(()=>vt(!1)):vt(!1),[lt,{refetch:vt,mutate:z}]}function Ts(t){return Se(t,!1)}function pe(t){if(pt===null)return t();const e=pt;pt=null;try{return t()}finally{pt=e}}function on(t){return ht===null||(ht.cleanups===null?ht.cleanups=[t]:ht.cleanups.push(t)),t}function lr(){return pt}function Ur(t,e){const n=Symbol("context");return{id:n,Provider:fo(n),defaultValue:t}}function io(t){let e;return ht&&ht.context&&(e=ht.context[t.id])!==void 0?e:t.defaultValue}function oo(t){const e=de(t),n=de(()=>hr(e()));return n.toArray=()=>{const r=n();return Array.isArray(r)?r:r!=null?[r]:[]},n}let ao;function Ds(){if(this.sources&&this.state)if(this.state===be)Ne(this);else{const t=It;It=null,Se(()=>Dn(this),!1),It=t}if(pt){const t=this.observers?this.observers.length:0;pt.sources?(pt.sources.push(this),pt.sourceSlots.push(t)):(pt.sources=[this],pt.sourceSlots=[t]),this.observers?(this.observers.push(pt),this.observerSlots.push(pt.sources.length-1)):(this.observers=[pt],this.observerSlots=[pt.sources.length-1])}return this.value}function Us(t,e,n){let r=t.value;return(!t.comparator||!t.comparator(r,e))&&(t.value=e,t.observers&&t.observers.length&&Se(()=>{for(let i=0;i1e6)throw It=[],new Error},!1)),e}function Ne(t){if(!t.fn)return;Je(t);const e=Yn;uo(t,t.value,e)}function uo(t,e,n){let r;const i=ht,d=pt;pt=ht=t;try{r=t.fn(e)}catch(m){return t.pure&&(t.state=be,t.owned&&t.owned.forEach(Je),t.owned=null),t.updatedAt=n+1,As(m)}finally{pt=d,ht=i}(!t.updatedAt||t.updatedAt<=n)&&(t.updatedAt!=null&&"observers"in t?Us(t,r):t.value=r,t.updatedAt=n)}function Xn(t,e,n,r=be,i){const d={fn:t,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:e,owner:ht,context:ht?ht.context:null,pure:n};return ht===null||ht!==Ms&&(ht.owned?ht.owned.push(d):ht.owned=[d]),d}function Tn(t){if(t.state===0)return;if(t.state===Mn)return Dn(t);if(t.suspense&&pe(t.suspense.inFallback))return t.suspense.effects.push(t);const e=[t];for(;(t=t.owner)&&(!t.updatedAt||t.updatedAt=0;n--)if(t=e[n],t.state===be)Ne(t);else if(t.state===Mn){const r=It;It=null,Se(()=>Dn(t,e[0]),!1),It=r}}function Se(t,e){if(It)return t();let n=!1;e||(It=[]),xe?n=!0:xe=[],Yn++;try{const r=t();return co(n),r}catch(r){n||(xe=null),It=null,As(r)}}function co(t){if(It&&(Os(It),It=null),t)return;const e=xe;xe=null,e.length&&Se(()=>Ss(e),!1)}function Os(t){for(let e=0;e=0;e--)Je(t.tOwned[e]);delete t.tOwned}if(t.owned){for(e=t.owned.length-1;e>=0;e--)Je(t.owned[e]);t.owned=null}if(t.cleanups){for(e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}t.state=0}function fr(t){return t instanceof Error?t:new Error(typeof t=="string"?t:"Unknown error",{cause:t})}function As(t,e=ht){throw fr(t)}function hr(t){if(typeof t=="function"&&!t.length)return hr(t());if(Array.isArray(t)){const e=[];for(let n=0;ni=pe(()=>(ht.context={...ht.context,[t]:r.value},oo(()=>r.children))),void 0),i}}function Kt(t,e){return pe(()=>t(e||{}))}const ho=t=>`Stale read from <${t}>.`;function Or(t){const e=t.keyed,n=de(()=>t.when,void 0,{equals:(r,i)=>e?r===i:!r==!i});return de(()=>{const r=n();if(r){const i=t.children;return typeof i=="function"&&i.length>0?pe(()=>i(e?r:()=>{if(!pe(n))throw ho("Show");return t.when})):i}return t.fallback},void 0,void 0)}function po(t,e,n){let r=n.length,i=e.length,d=r,m=0,g=0,S=e[i-1].nextSibling,A=null;for(;mP-g){const B=e[m];for(;g{i=d,e===document?t():gn(e,t(),e.firstChild?null:void 0,n)},r.owner),()=>{i(),e.textContent=""}}function Er(t,e,n){let r;const i=()=>{const m=document.createElement("template");return m.innerHTML=t,m.content.firstChild},d=()=>(r||(r=i())).cloneNode(!0);return d.cloneNode=d,d}function mn(t,e){e==null?t.removeAttribute("class"):t.className=e}function yo(t,e,n){return pe(()=>t(e,n))}function gn(t,e,n,r){if(n!==void 0&&!r&&(r=[]),typeof e!="function")return Un(t,e,r,n);Ie(i=>Un(t,e(),i,n),r)}function Un(t,e,n,r,i){for(;typeof n=="function";)n=n();if(e===n)return n;const d=typeof e,m=r!==void 0;if(t=m&&n[0]&&n[0].parentNode||t,d==="string"||d==="number"){if(d==="number"&&(e=e.toString(),e===n))return n;if(m){let g=n[0];g&&g.nodeType===3?g.data!==e&&(g.data=e):g=document.createTextNode(e),n=Fe(t,n,r,g)}else n!==""&&typeof n=="string"?n=t.firstChild.data=e:n=t.textContent=e}else if(e==null||d==="boolean")n=Fe(t,n,r);else{if(d==="function")return Ie(()=>{let g=e();for(;typeof g=="function";)g=g();n=Un(t,g,n,r)}),()=>n;if(Array.isArray(e)){const g=[],S=n&&Array.isArray(n);if(dr(g,e,n,i))return Ie(()=>n=Un(t,g,n,r,!0)),()=>n;if(g.length===0){if(n=Fe(t,n,r),m)return n}else S?n.length===0?ts(t,g,r):po(t,n,g):(n&&Fe(t),ts(t,g));n=g}else if(e.nodeType){if(Array.isArray(n)){if(m)return n=Fe(t,n,r,e);Fe(t,n,null,e)}else n==null||n===""||!t.firstChild?t.appendChild(e):t.replaceChild(e,t.firstChild);n=e}}return n}function dr(t,e,n,r){let i=!1;for(let d=0,m=e.length;d=0;m--){const g=e[m];if(i!==g){const S=g.parentNode===t;!d&&!m?S?t.replaceChild(i,g):t.insertBefore(i,n):S&&g.remove()}else d=!0}}else t.insertBefore(i,n);return[i]}const mo="_page_13ypr_1",go="_circle-counter_13ypr_6",xo="_welcome-message_13ypr_26",vo="_fade-in_13ypr_1",bo="_canvas_13ypr_41",pn={page:mo,circleCounter:go,welcomeMessage:xo,fadeIn:vo,canvas:bo};function Ar(t,e,n){const r=io(t);if(r===void 0)throw new Error(`Called '${e}' outside of ${n!==void 0?`<${n}>`:"its Provider"}.`);return r}const ks=Ur(),_o=ks.Provider;function kr(){return Ar(ks,"useCamera","CameraContext")}var $o=Object.defineProperty,So=Object.defineProperties,Mo=Object.getOwnPropertyDescriptors,es=Object.getOwnPropertySymbols,To=Object.prototype.hasOwnProperty,Do=Object.prototype.propertyIsEnumerable,pr=(t,e,n)=>e in t?$o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e)=>{for(var n in e||(e={}))To.call(e,n)&&pr(t,n,e[n]);if(es)for(var n of es(e))Do.call(e,n)&&pr(t,n,e[n]);return t},me=(t,e)=>So(t,Mo(e)),E=(t,e,n)=>(pr(t,typeof e!="symbol"?e+"":e,n),n),Uo="Invariant failed";function On(t,e){if(!t)throw new Error(Uo)}var wn=class wr extends Error{constructor(e,n){let r=n.map(i=>`- ${i}`);r.length>20&&(r=[...r.slice(0,11),"...",...r.slice(-10)]),super(`Resolution of the following tree failed: ${r.join(` -`)}`),this.cause=e,this.trace=n,Object.setPrototypeOf(this,yr.prototype)}appendToTrace(e){let n=[e,...this.trace];return new yr(this.cause,n)}},Uo=class Is extends Error{constructor(e){super(`Missing value for '${e}'`),this.slot=e,Object.setPrototypeOf(this,Is.prototype)}},ns=class Ps extends Error{constructor(e){var n;super(`Buffer '${(n=e.label)!=null?n:""}' is not bindable as a uniform. Use .$usage('uniform') to allow it.`),Object.setPrototypeOf(this,Ps.prototype)}},Oo=class Fs extends Error{constructor(e,n){super(`The function '${e??""}' is missing links to the following external values: ${n}.`),Object.setPrototypeOf(this,Fs.prototype)}},zs=class Bs extends Error{constructor(e){super(`Bind group was not provided for '${e??""}' layout.`),Object.setPrototypeOf(this,Bs.prototype)}},Ye=null;function Eo(t,e){Dn(Ye===null),Ye=t;try{return e()}finally{Ye=null}}function Yn(){return Ye}var we=()=>Ye!==null;function ne(t){let e={"~repr":void 0,type:t.type};return Object.assign((...n)=>{var r;let i=n;if(we())return`${e.type}(${i.join(", ")})`;if(i.length<=1)return t.makeFromScalar((r=i[0])!=null?r:0);if(i.length===t.length)return t.make(...i);throw new Error(`'${t.type}' constructor called with invalid number of arguments.`)},e)}var Xn=class{constructor(t,e){this.x=t,this.y=e,E(this,"length",2)}*[Symbol.iterator](){yield this.x,yield this.y}get 0(){return this.x}get 1(){return this.y}set 0(t){this.x=t}set 1(t){this.y=t}"~resolve"(){return`${this.kind}(${this.x}, ${this.y})`}},Un=class js extends Xn{constructor(){super(...arguments),E(this,"kind","vec2f")}make2(e,n){return new js(e,n)}make3(e,n,r){return new kn(e,n,r)}make4(e,n,r,i){return new zn(e,n,r,i)}},On=class Rs extends Xn{constructor(){super(...arguments),E(this,"kind","vec2h")}make2(e,n){return new Rs(e,n)}make3(e,n,r){return new In(e,n,r)}make4(e,n,r,i){return new Bn(e,n,r,i)}},En=class Vs extends Xn{constructor(){super(...arguments),E(this,"kind","vec2i")}make2(e,n){return new Vs(e,n)}make3(e,n,r){return new Pn(e,n,r)}make4(e,n,r,i){return new jn(e,n,r,i)}},An=class Ns extends Xn{constructor(){super(...arguments),E(this,"kind","vec2u")}make2(e,n){return new Ns(e,n)}make3(e,n,r){return new Fn(e,n,r)}make4(e,n,r,i){return new Rn(e,n,r,i)}},Zn=class{constructor(e,n,r){this.x=e,this.y=n,this.z=r,E(this,"length",3)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}set 0(e){this.x=e}set 1(e){this.y=e}set 2(e){this.z=e}"~resolve"(){return`${this.kind}(${this.x}, ${this.y}, ${this.z})`}},kn=class Ls extends Zn{constructor(){super(...arguments),E(this,"kind","vec3f")}make2(e,n){return new Un(e,n)}make3(e,n,r){return new Ls(e,n,r)}make4(e,n,r,i){return new zn(e,n,r,i)}},In=class Gs extends Zn{constructor(){super(...arguments),E(this,"kind","vec3h")}make2(e,n){return new On(e,n)}make3(e,n,r){return new Gs(e,n,r)}make4(e,n,r,i){return new Bn(e,n,r,i)}},Pn=class qs extends Zn{constructor(){super(...arguments),E(this,"kind","vec3i")}make2(e,n){return new En(e,n)}make3(e,n,r){return new qs(e,n,r)}make4(e,n,r,i){return new jn(e,n,r,i)}},Fn=class Ws extends Zn{constructor(){super(...arguments),E(this,"kind","vec3u")}make2(e,n){return new An(e,n)}make3(e,n,r){return new Ws(e,n,r)}make4(e,n,r,i){return new Rn(e,n,r,i)}},Hn=class{constructor(e,n,r,i){this.x=e,this.y=n,this.z=r,this.w=i,E(this,"length",4)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}set 0(e){this.x=e}set 1(e){this.y=e}set 2(e){this.z=e}set 3(e){this.w=e}"~resolve"(){return`${this.kind}(${this.x}, ${this.y}, ${this.z}, ${this.w})`}},zn=class Cs extends Hn{constructor(){super(...arguments),E(this,"kind","vec4f")}make2(e,n){return new Un(e,n)}make3(e,n,r){return new kn(e,n,r)}make4(e,n,r,i){return new Cs(e,n,r,i)}},Bn=class Ys extends Hn{constructor(){super(...arguments),E(this,"kind","vec4h")}make2(e,n){return new On(e,n)}make3(e,n,r){return new In(e,n,r)}make4(e,n,r,i){return new Ys(e,n,r,i)}},jn=class Xs extends Hn{constructor(){super(...arguments),E(this,"kind","vec4i")}make2(e,n){return new En(e,n)}make3(e,n,r){return new Pn(e,n,r)}make4(e,n,r,i){return new Xs(e,n,r,i)}},Rn=class Zs extends Hn{constructor(){super(...arguments),E(this,"kind","vec4u")}make2(e,n){return new An(e,n)}make3(e,n,r){return new Fn(e,n,r)}make4(e,n,r,i){return new Zs(e,n,r,i)}},at={get:(t,e)=>{if(typeof e=="symbol"||!Number.isNaN(Number.parseInt(e)))return Reflect.get(t,e);let n=t,r=new Array(e.length),i=0;for(let d of e){switch(d){case"x":r[i]=n.x;break;case"y":r[i]=n.y;break;case"z":r[i]=n.z;break;case"w":r[i]=n.w;break;default:return Reflect.get(n,e)}i++}return e.length===4?new Proxy(n.make4(r[0],r[1],r[2],r[3]),at):e.length===3?new Proxy(n.make3(r[0],r[1],r[2]),at):e.length===2?new Proxy(n.make2(r[0],r[1]),at):Reflect.get(t,e)}},G=ne({type:"vec2f",length:2,make:(t,e)=>new Proxy(new Un(t,e),at),makeFromScalar:t=>new Proxy(new Un(t,t),at)}),Ao=ne({type:"vec2h",length:2,make:(t,e)=>new Proxy(new On(t,e),at),makeFromScalar:t=>new Proxy(new On(t,t),at)}),De=ne({type:"vec2i",length:2,make:(t,e)=>new Proxy(new En(t,e),at),makeFromScalar:t=>new Proxy(new En(t,t),at)}),Ue=ne({type:"vec2u",length:2,make:(t,e)=>new Proxy(new An(t,e),at),makeFromScalar:t=>new Proxy(new An(t,t),at)}),Qe=ne({type:"vec3f",length:3,make:(t,e,n)=>new Proxy(new kn(t,e,n),at),makeFromScalar:t=>new Proxy(new kn(t,t,t),at)}),ko=ne({type:"vec3h",length:3,make:(t,e,n)=>new Proxy(new In(t,e,n),at),makeFromScalar:t=>new Proxy(new In(t,t,t),at)}),mr=ne({type:"vec3i",length:3,make:(t,e,n)=>new Proxy(new Pn(t,e,n),at),makeFromScalar:t=>new Proxy(new Pn(t,t,t),at)}),Oe=ne({type:"vec3u",length:3,make:(t,e,n)=>new Proxy(new Fn(t,e,n),at),makeFromScalar:t=>new Proxy(new Fn(t,t,t),at)}),ot=ne({type:"vec4f",length:4,make:(t,e,n,r)=>new Proxy(new zn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new zn(t,t,t,t),at)}),Io=ne({type:"vec4h",length:4,make:(t,e,n,r)=>new Proxy(new Bn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new Bn(t,t,t,t),at)}),te=ne({type:"vec4i",length:4,make:(t,e,n,r)=>new Proxy(new jn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new jn(t,t,t,t),at)}),ee=ne({length:4,type:"vec4u",make:(t,e,n,r)=>new Proxy(new Rn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new Rn(t,t,t,t),at)}),Hs=Object.defineProperty,Po=(t,e,n)=>e in t?Hs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fo=(t,e)=>{for(var n in e)Hs(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n)=>Po(t,typeof e!="symbol"?e+"":e,n),Ks={};Fo(Ks,{BufferReader:()=>gn,BufferWriter:()=>xn,MaxValue:()=>mt,Measurer:()=>yt,UnresolvedReferenceError:()=>Te,ValidationError:()=>Kn,arrayOf:()=>Vo,bool:()=>Lo,byte:()=>Xo,chars:()=>ua,concat:()=>ha,dynamicArrayOf:()=>pa,f16:()=>sa,f32:()=>oa,f32Array:()=>Ea,f64Array:()=>Aa,generic:()=>la,genericEnum:()=>fa,i16:()=>Ho,i16Array:()=>Ua,i32:()=>ta,i32Array:()=>Oa,i8:()=>Co,i8Array:()=>Da,keyed:()=>ma,object:()=>ca,optional:()=>xa,string:()=>qo,tupleOf:()=>_a,u16:()=>Qo,u16Array:()=>Ma,u32:()=>na,u32Array:()=>Ta,u8:()=>ni,u8Array:()=>$a,u8ClampedArray:()=>Sa});var Te=class Qs extends Error{constructor(e){super(e),Object.setPrototypeOf(this,Qs.prototype)}},Kn=class Js extends Error{constructor(e){super(e),Object.setPrototypeOf(this,Js.prototype)}},zo=class{constructor(){Q(this,"size",Number.NaN),Q(this,"unbounded",this),Q(this,"isUnbounded",!0)}add(){return this}fork(){return this}},Bo=new zo,yt=class ti{constructor(){Q(this,"size",0),Q(this,"unbounded",Bo),Q(this,"isUnbounded",!1)}add(e){return this.size+=e,this}fork(){const e=new ti;return e.size=this.size,e}},mt=Symbol("The biggest (in amount of bytes needed) value a schema can represent"),Mt=class{constructor(){Q(this,"__unwrapped")}resolveReferences(t){}seekProperty(t,e){return null}},jo=class{constructor(t){this.key=t}},Xe={STRING:"string",ENUM:"enum"},Ro=class extends Mt{constructor(t,e){super(),this._unstableElementSchema=t,this.length=e,Q(this,"elementSchema"),this.elementSchema=t}resolveReferences(t){this.elementSchema=t.resolve(this._unstableElementSchema)}write(t,e){if(e.length!==this.length)throw new Kn(`Expected array of length ${this.length}, got ${e.length}`);for(const n of e)this.elementSchema.write(t,n)}read(t){const e=[];for(let n=0;n{const i=e.fork();for(const d of Object.values(r.properties))d.measure(mt,i);return[r,i.size]}).reduce((r,i)=>r[1]>i[1]?r:i)[0];for(const r of Object.values(n.properties))r.measure(mt,e)}else{const n=t.type,r=this.subTypeMap[n]||null;if(r===null)throw new Error(`Unknown sub-type '${n.toString()}', expected one of '${JSON.stringify(Object.keys(this.subTypeMap))}'`);for(const[i,d]of $e(r.properties))d.measure(t[i],e)}return e}};function la(t,e){return new si(Xe.STRING,t,e)}function fa(t,e){return new si(Xe.ENUM,t,e)}function ha(t){return new Pr(Object.fromEntries(t.flatMap(({properties:e})=>Object.entries(e))))}var da=class extends Mt{constructor(t){super(),this._unstableElementType=t,Q(this,"elementType"),this.elementType=t}resolveReferences(t){this.elementType=t.resolve(this._unstableElementType)}write(t,e){t.writeUint32(e.length);for(const n of e)this.elementType.write(t,n)}read(t){const e=[],n=t.readUint32();for(let r=0;r=t.length)return null;const r=new yt;for(let i=0;it.resolve(n))}var ba=class extends Mt{constructor(t){super(),this._unstableSchemas=t,Q(this,"schemas"),this.schemas=t}resolveReferences(t){this.schemas=va(t,this._unstableSchemas)}write(t,e){if(e.length!==this.schemas.length)throw new Kn(`Expected tuple of length ${this.schemas.length}, got ${e.length}`);for(let n=0;nnew _e(t,Uint8Array),Sa=t=>new _e(t,Uint8ClampedArray),Ma=t=>new _e(t,Uint16Array),Ta=t=>new _e(t,Uint32Array),Da=t=>new _e(t,Int8Array),Ua=t=>new _e(t,Int16Array),Oa=t=>new _e(t,Int32Array),Ea=t=>new _e(t,Float32Array),Aa=t=>new _e(t,Float64Array);function ka(){const t=new Uint8Array(4),e=new Uint32Array(t.buffer);return e[0]=1,t[0]===0}function Ia(){return ka()?"big":"little"}function Fr(t){let e=0,n=t;return n&&"buffer"in n&&"byteOffset"in n&&(e+=n.byteOffset,n=n.buffer),{buffer:n,byteOffset:e,byteLength:t.byteLength}}var oi=class{constructor(t,e){Q(this,"dataView"),Q(this,"littleEndian"),Q(this,"byteOffset",0),Q(this,"endianness");const{byteOffset:n=0,endianness:r="system"}=e??{};this.byteOffset=n;const i=Ia();this.endianness=r==="system"?i:r,this.littleEndian=this.endianness==="little";const d=Fr(t);this.byteOffset+=d.byteOffset,this.dataView=new DataView(d.buffer)}get currentByteOffset(){return this.byteOffset}seekTo(t){this.byteOffset=t}skipBytes(t){this.byteOffset+=t}};function Pa(t){if(t===0)return 0;if(Number.isNaN(t))return 32256;if(!Number.isFinite(t))return t>0?31744:64512;const e=t<0?1:0,n=Math.abs(t),r=Math.floor(Math.log2(n)),i=n/2**r-1,d=r+15,m=Math.floor(i*1024);return e<<15|d<<10|m}function Fa(t){const e=(t&32768)>>15,n=(t&31744)>>10,r=t&1023;return n===0?e===0?r/1024:-r/1024:n===31?r===0?e===0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:Number.NaN:(e===0?1:-1)*(1+r/1024)*2**(n-15)}var gn=class extends oi{constructor(){super(...arguments),Q(this,"_cachedTextDecoder")}get _textDecoder(){return this._cachedTextDecoder||(this._cachedTextDecoder=new TextDecoder(void 0,{fatal:!0})),this._cachedTextDecoder}readBool(){return this.dataView.getUint8(this.byteOffset++)!==0}readByte(){return this.dataView.getUint8(this.byteOffset++)}readInt8(){return this.dataView.getInt8(this.byteOffset++)}readUint8(){return this.dataView.getUint8(this.byteOffset++)}readInt16(){const t=this.dataView.getInt16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readUint16(){const t=this.dataView.getUint16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readInt32(){const t=this.dataView.getInt32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readUint32(){const t=this.dataView.getUint32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readFloat16(){const t=this.dataView.getUint16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,Fa(t)}readFloat32(){const t=this.dataView.getFloat32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readString(){let t=0;for(;this.byteOffset+twe()?`u32(${t})`:typeof t=="boolean"?t?1:0:Number.isInteger(t)?((t<0||t>4294967295)&&console.warn(`u32 value ${t} overflowed`),(t&4294967295)>>>0):Math.max(0,Math.min(4294967295,Math.floor(t))),gt=Object.assign(za,{type:"u32"}),Ba=t=>{if(we())return`i32(${t})`;if(typeof t=="boolean")return t?1:0;if(Number.isInteger(t))return(t<-2147483648||t>2147483647)&&console.warn(`i32 value ${t} overflowed`),(t|0)&4294967295;let e=t<0?Math.ceil(t):Math.floor(t);return Math.max(-2147483648,Math.min(2147483647,e))},Zt=Object.assign(Ba,{type:"i32"}),ja=t=>{if(we())return`f32(${t})`;if(typeof t=="boolean")return t?1:0;let e=new Float32Array(1);return e[0]=t,e[0]},P=Object.assign(ja,{type:"f32"}),Ra=t=>{if(we())return`f16(${t})`;if(typeof t=="boolean")return t?1:0;let e=new ArrayBuffer(2);return wn.f16.write(new wn.BufferWriter(e),t),wn.f16.read(new wn.BufferReader(e))};Object.assign(Ra,{type:"f16"});var Va=["bool","f32","f16","i32","u32","vec2f","vec2h","vec2i","vec2u","vec3f","vec3h","vec3i","vec3u","vec4f","vec4h","vec4i","vec4u","mat2x2f","mat3x3f","mat4x4f","struct","array","atomic","decorated"];function Ve(t){return Va.includes(t?.type)}function zr(t){return t?.type==="array"}function Ne(t){return t?.type==="struct"}function ai(t){return t?.type==="@align"}function ui(t){return t?.type==="@size"}function Na(t){return t?.type==="@location"}function La(t){return t?.type==="@builtin"}function Le(t){return t?.type==="decorated"}var Qn=t=>new Ga(t),Ga=class{constructor(t){this.propTypes=t,E(this,"_label"),E(this,"type","struct"),E(this,"~repr"),E(this,"~exotic")}get label(){return this._label}$name(t){return this._label=t,this}},xe=(t,e)=>{let n=e-1,r=~n;return t&n?(t&r)+e:t},ci=["uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","unorm8x4-bgra"],qa={f32:"float32",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",f16:"float16",vec2h:"float16x2",vec4h:"float16x4",u32:"uint32",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",i32:"sint32",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4"},Wa=["unstruct","disarray","loose-decorated",...ci];function li(t){return Wa.includes(t?.type)}function Br(t){return t?.type==="disarray"}function Jn(t){return t?.type==="unstruct"}function ke(t){return t?.type==="loose-decorated"}function Ze(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(ai))==null?void 0:n.value}function Ca(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(ui))==null?void 0:n.value}function gr(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(Na))==null?void 0:n.value}function tr(t){return Ve(t)||li(t)}var W=class{constructor(t){this.type=t,E(this,"~repr")}},Ya={uint8:gt,uint8x2:Ue,uint8x4:ee,sint8:Zt,sint8x2:De,sint8x4:te,unorm8:P,unorm8x2:G,unorm8x4:ot,snorm8:P,snorm8x2:G,snorm8x4:ot,uint16:gt,uint16x2:Ue,uint16x4:ee,sint16:Zt,sint16x2:De,sint16x4:te,unorm16:P,unorm16x2:G,unorm16x4:ot,snorm16:P,snorm16x2:G,snorm16x4:ot,float16:P,float16x2:G,float16x4:ot,float32:P,float32x2:G,float32x3:Qe,float32x4:ot,uint32:gt,uint32x2:Ue,uint32x3:Oe,uint32x4:ee,sint32:Zt,sint32x2:De,sint32x3:mr,sint32x4:te,"unorm10-10-10-2":ot,"unorm8x4-bgra":ot},Xa=Object.keys(Ya);new W("uint8");new W("uint8x2");new W("uint8x4");new W("sint8");new W("sint8x2");new W("sint8x4");new W("unorm8");new W("unorm8x2");new W("unorm8x4");new W("snorm8");new W("snorm8x2");new W("snorm8x4");new W("uint16");new W("uint16x2");new W("uint16x4");new W("sint16");new W("sint16x2");new W("sint16x4");new W("unorm16");new W("unorm16x2");new W("unorm16x4");new W("snorm16");new W("snorm16x2");new W("snorm16x4");new W("float16");new W("float16x2");new W("float16x4");new W("float32");new W("float32x2");new W("float32x3");new W("float32x4");new W("uint32");new W("uint32x2");new W("uint32x3");new W("uint32x4");new W("sint32");new W("sint32x2");new W("sint32x3");new W("sint32x4");new W("unorm10-10-10-2");new W("unorm8x4-bgra");var Za={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:16,vec3h:8,vec3i:16,vec3u:16,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:8,mat3x3f:16,mat4x4f:16};function Ha(t){var e,n,r;let i=t?.type,d=Za[i];if(d!==void 0)return d;if(Ne(t))return Object.values(t.propTypes).map(St).reduce((m,g)=>m>g?m:g);if(zr(t))return St(t.elementType);if(Jn(t)){let m=Object.values(t.propTypes)[0];return m&&(e=Ze(m))!=null?e:1}if(Br(t))return(n=Ze(t.elementType))!=null?n:1;if(Le(t)||ke(t))return(r=Ze(t))!=null?r:St(t.inner);if(Xa.includes(i))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(t)}`)}function Ka(t){var e,n;if(Jn(t)){let r=Object.values(t.propTypes)[0];return r?ue(r):1}return Br(t)?ue(t.elementType):ke(t)?(e=Ze(t))!=null?e:ue(t.inner):(n=Ze(t))!=null?n:1}var ss=new WeakMap,is=new WeakMap;function St(t){let e=ss.get(t);return e===void 0&&(e=Ha(t),ss.set(t,e)),e}function ue(t){let e=is.get(t);return e===void 0&&(e=Ka(t),is.set(t,e)),e}var Qa={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:12,vec3h:6,vec3i:12,vec3u:12,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:16,mat3x3f:48,mat4x4f:64,uint8:1,uint8x2:2,uint8x4:4,sint8:1,sint8x2:2,sint8x4:4,unorm8:1,unorm8x2:2,unorm8x4:4,snorm8:1,snorm8x2:2,snorm8x4:4,uint16:2,uint16x2:4,uint16x4:8,sint16:2,sint16x2:4,sint16x4:8,unorm16:2,unorm16x2:4,unorm16x4:8,snorm16:2,snorm16x2:4,snorm16x4:8,float16:2,float16x2:4,float16x4:8,float32:4,float32x2:8,float32x3:12,float32x4:16,uint32:4,uint32x2:8,uint32x3:12,uint32x4:16,sint32:4,sint32x2:8,sint32x3:12,sint32x4:16,"unorm10-10-10-2":4,"unorm8x4-bgra":4};function Ja(t){let e=0;for(let n of Object.values(t.propTypes)){if(Number.isNaN(e))throw new Error("Only the last property of a struct can be unbounded");if(e=xe(e,St(n)),e+=wt(n),Number.isNaN(e)&&n.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return xe(e,St(t))}function tu(t){let e=0;for(let n of Object.values(t.propTypes)){let r=ue(n);e=xe(e,r),e+=wt(n)}return e}function eu(t){var e;let n=Qa[t?.type];if(n!==void 0)return n;if(Ne(t))return Ja(t);if(Jn(t))return tu(t);if(zr(t)){if(t.elementCount===0)return Number.NaN;let r=St(t.elementType);return xe(wt(t.elementType),r)*t.elementCount}if(Br(t)){let r=ue(t.elementType);return xe(wt(t.elementType),r)*t.elementCount}if(Le(t)||ke(t))return(e=Ca(t))!=null?e:wt(t.inner);throw new Error(`Cannot determine size of data: ${t}`)}var os=new WeakMap;function wt(t){let e=os.get(t);return e===void 0&&(e=eu(t),os.set(t,e)),e}var jr=(t,e)=>new nu(t,e),nu=class{constructor(t,e){if(this.elementType=t,this.elementCount=e,E(this,"type","array"),E(this,"~repr"),E(this,"~exotic"),Number.isNaN(wt(t)))throw new Error("Cannot nest runtime sized arrays.")}};function Rr(t){let e={"~repr":void 0,type:t.type,label:t.type};return Object.assign((...n)=>{let r=[];for(let i of n)if(typeof i=="number")r.push(i);else for(let d=0;dthis[n]).join(", ")})`}},su=class extends ru{constructor(){super(...arguments),E(this,"kind","mat2x2f")}makeColumn(e,n){return G(e,n)}},iu=class{constructor(...e){E(this,"columns"),E(this,"length",12),this.columns=[this.makeColumn(e[0],e[1],e[2]),this.makeColumn(e[3],e[4],e[5]),this.makeColumn(e[6],e[7],e[8])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return 0}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return 0}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return 0}set 0(e){this.columns[0].x=e}set 1(e){this.columns[0].y=e}set 2(e){this.columns[0].z=e}set 3(e){}set 4(e){this.columns[1].x=e}set 5(e){this.columns[1].y=e}set 6(e){this.columns[1].z=e}set 7(e){}set 8(e){this.columns[2].x=e}set 9(e){this.columns[2].y=e}set 10(e){this.columns[2].z=e}set 11(e){}"~resolve"(){return`${this.kind}(${this[0]}, ${this[1]}, ${this[2]}, ${this[4]}, ${this[5]}, ${this[6]}, ${this[8]}, ${this[9]}, ${this[10]})`}},ou=class extends iu{constructor(){super(...arguments),E(this,"kind","mat3x3f")}makeColumn(e,n,r){return Qe(e,n,r)}},au=class{constructor(...e){E(this,"columns"),E(this,"length",16),this.columns=[this.makeColumn(e[0],e[1],e[2],e[3]),this.makeColumn(e[4],e[5],e[6],e[7]),this.makeColumn(e[8],e[9],e[10],e[11]),this.makeColumn(e[12],e[13],e[14],e[15])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return this.columns[0].w}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return this.columns[1].w}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return this.columns[2].w}get 12(){return this.columns[3].x}get 13(){return this.columns[3].y}get 14(){return this.columns[3].z}get 15(){return this.columns[3].w}set 0(e){this.columns[0].x=e}set 1(e){this.columns[0].y=e}set 2(e){this.columns[0].z=e}set 3(e){this.columns[0].w=e}set 4(e){this.columns[1].x=e}set 5(e){this.columns[1].y=e}set 6(e){this.columns[1].z=e}set 7(e){this.columns[1].w=e}set 8(e){this.columns[2].x=e}set 9(e){this.columns[2].y=e}set 10(e){this.columns[2].z=e}set 11(e){this.columns[2].w=e}set 12(e){this.columns[3].x=e}set 13(e){this.columns[3].y=e}set 14(e){this.columns[3].z=e}set 15(e){this.columns[3].w=e}"~resolve"(){return`${this.kind}(${Array.from({length:this.length}).map((e,n)=>this[n]).join(", ")})`}},uu=class extends au{constructor(){super(...arguments),E(this,"kind","mat4x4f")}makeColumn(e,n,r,i){return ot(e,n,r,i)}},cu=Rr({type:"mat2x2f",rows:2,columns:2,makeFromElements:(...t)=>new su(...t)}),Je=Rr({type:"mat3x3f",rows:3,columns:3,makeFromElements:(...t)=>new ou(...t)}),fi=Rr({type:"mat4x4f",rows:4,columns:4,makeFromElements:(...t)=>new uu(...t)});function Vt(t,e){return Le(t)?new as(t.inner,[e,...t.attribs]):ke(t)?new us(t.inner,[e,...t.attribs]):li(t)?new us(t,[e]):new as(t,[e])}function xr(t,e){return Vt(e,{type:"@location",value:t})}function hi(t){return(Le(t)||ke(t))&&t.attribs.find(La)!==void 0}function lu(t){return!Le(t)&&!ke(t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var di=class{constructor(e,n){this.inner=e,this.attribs=n,E(this,"~repr");var r,i;let d=(r=n.find(ai))==null?void 0:r.value,m=(i=n.find(ui))==null?void 0:i.value;if(d!==void 0){if(d<=0)throw new Error(`Custom data alignment must be a positive number, got: ${d}.`);if(Math.log2(d)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${d}.`);if(Ve(this.inner)&&d%St(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${d}, expected multiple of: ${St(this.inner)}.`)}if(m!==void 0){if(mt[Ee][e]),n}function mi(t){fr()&&tn(Nn(t,ze),wi)()}function du(t){return mi(t),Reflect.ownKeys(t)}const pu={get(t,e,n){if(e===Vn)return t;if(e===Ee)return n;if(e===Jr)return mi(t),n;const r=Nn(t,ze),i=r[e];let d=i?i():t[e];if(e===ze||e===me||e==="__proto__")return d;if(!i){const m=Object.getOwnPropertyDescriptor(t,e);fr()&&(typeof d!="function"||t.hasOwnProperty(e))&&!(m&&m.get)&&(d=tn(r,e,d)())}return Be(d)?yi(d):d},has(t,e){return e===Vn||e===Ee||e===Jr||e===ze||e===me||e==="__proto__"?!0:(fr()&&tn(Nn(t,me),e)(),e in t)},set(){return!0},deleteProperty(){return!0},ownKeys:du,getOwnPropertyDescriptor:hu};function je(t,e,n,r=!1){if(!r&&t[e]===n)return;const i=t[e],d=t.length;n===void 0?(delete t[e],t[me]&&t[me][e]&&i!==void 0&&t[me][e].$()):(t[e]=n,t[me]&&t[me][e]&&i===void 0&&t[me][e].$());let m=Nn(t,ze),g;if((g=tn(m,e,i))&&g.$(()=>n),Array.isArray(t)&&t.length!==d){for(let S=t.length;S1){r=e.shift();const m=typeof r,g=Array.isArray(t);if(Array.isArray(r)){for(let S=0;S1){We(t[r],e,[r].concat(n));return}i=t[r],n=[r].concat(n)}let d=e[0];typeof d=="function"&&(d=d(i,n),d===i)||r===void 0&&d==null||(d=pe(d),r===void 0||Be(i)&&Be(d)&&!Array.isArray(d)?gi(i,d):je(t,r,d))}function yu(...[t,e]){const n=pe(t||{}),r=Array.isArray(n),i=yi(n);function d(...m){Ts(()=>{r&&m.length===1?wu(n,m[0]):We(n,m)})}return[i,d]}const Ln=new WeakMap,xi={get(t,e){if(e===Vn)return t;const n=t[e];let r;return Be(n)?Ln.get(n)||(Ln.set(n,r=new Proxy(n,xi)),r):n},set(t,e,n){return je(t,e,pe(n)),!0},deleteProperty(t,e){return je(t,e,void 0,!0),!0}};function vi(t){return e=>{if(Be(e)){let n;(n=Ln.get(e))||Ln.set(e,n=new Proxy(e,xi)),t(n)}return e}}function mu(t,e){return class extends t{constructor(...n){super(...n),e(this)}}}const gu=mu(Array,t=>t.fill(0));let C=1e-6;function xu(t){function e(s=0,f=0){const o=new t(2);return s!==void 0&&(o[0]=s,f!==void 0&&(o[1]=f)),o}const n=e;function r(s,f,o){const u=o??new t(2);return u[0]=s,u[1]=f,u}function i(s,f){const o=f??new t(2);return o[0]=Math.ceil(s[0]),o[1]=Math.ceil(s[1]),o}function d(s,f){const o=f??new t(2);return o[0]=Math.floor(s[0]),o[1]=Math.floor(s[1]),o}function m(s,f){const o=f??new t(2);return o[0]=Math.round(s[0]),o[1]=Math.round(s[1]),o}function g(s,f=0,o=1,u){const p=u??new t(2);return p[0]=Math.min(o,Math.max(f,s[0])),p[1]=Math.min(o,Math.max(f,s[1])),p}function S(s,f,o){const u=o??new t(2);return u[0]=s[0]+f[0],u[1]=s[1]+f[1],u}function A(s,f,o,u){const p=u??new t(2);return p[0]=s[0]+f[0]*o,p[1]=s[1]+f[1]*o,p}function I(s,f){const o=s[0],u=s[1],p=f[0],_=f[1],D=Math.sqrt(o*o+u*u),h=Math.sqrt(p*p+_*_),w=D*h,b=w&&K(s,f)/w;return Math.acos(b)}function k(s,f,o){const u=o??new t(2);return u[0]=s[0]-f[0],u[1]=s[1]-f[1],u}const F=k;function z(s,f){return Math.abs(s[0]-f[0])1e-5?(o[0]=u/_,o[1]=p/_):(o[0]=0,o[1]=0),o}function ie(s,f){const o=f??new t(2);return o[0]=-s[0],o[1]=-s[1],o}function ft(s,f){const o=f??new t(2);return o[0]=s[0],o[1]=s[1],o}const oe=ft;function Lt(s,f,o){const u=o??new t(2);return u[0]=s[0]*f[0],u[1]=s[1]*f[1],u}const ae=Lt;function Gt(s,f,o){const u=o??new t(2);return u[0]=s[0]/f[0],u[1]=s[1]/f[1],u}const Qt=Gt;function Wt(s=1,f){const o=f??new t(2),u=Math.random()*2*Math.PI;return o[0]=Math.cos(u)*s,o[1]=Math.sin(u)*s,o}function c(s){const f=s??new t(2);return f[0]=0,f[1]=0,f}function x(s,f,o){const u=o??new t(2),p=s[0],_=s[1];return u[0]=p*f[0]+_*f[4]+f[12],u[1]=p*f[1]+_*f[5]+f[13],u}function a(s,f,o){const u=o??new t(2),p=s[0],_=s[1];return u[0]=f[0]*p+f[4]*_+f[8],u[1]=f[1]*p+f[5]*_+f[9],u}function l(s,f,o,u){const p=u??new t(2),_=s[0]-f[0],D=s[1]-f[1],h=Math.sin(o),w=Math.cos(o);return p[0]=_*w-D*h+f[0],p[1]=_*h+D*w+f[1],p}function y(s,f,o){const u=o??new t(2);return Ft(s,u),ut(u,f,u)}function v(s,f,o){const u=o??new t(2);return Y(s)>f?y(s,f,u):ft(s,u)}function T(s,f,o){const u=o??new t(2);return N(s,f,.5,u)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,angle:I,subtract:k,sub:F,equalsApproximately:z,equals:B,lerp:N,lerpV:q,max:tt,min:st,mulScalar:ut,scale:rt,divScalar:xt,inverse:lt,invert:vt,cross:nt,dot:K,length:Y,len:it,lengthSq:X,lenSq:et,distance:H,dist:re,distanceSq:Pt,distSq:se,normalize:Ft,negate:ie,copy:ft,clone:oe,multiply:Lt,mul:ae,divide:Gt,div:Qt,random:Wt,zero:c,transformMat4:x,transformMat3:a,rotate:l,setLength:y,truncate:v,midpoint:T}}const cs=new Map;function bi(t){let e=cs.get(t);return e||(e=xu(t),cs.set(t,e)),e}function vu(t){function e(h,w,b){const $=new t(3);return h!==void 0&&($[0]=h,w!==void 0&&($[1]=w,b!==void 0&&($[2]=b))),$}const n=e;function r(h,w,b,$){const M=$??new t(3);return M[0]=h,M[1]=w,M[2]=b,M}function i(h,w){const b=w??new t(3);return b[0]=Math.ceil(h[0]),b[1]=Math.ceil(h[1]),b[2]=Math.ceil(h[2]),b}function d(h,w){const b=w??new t(3);return b[0]=Math.floor(h[0]),b[1]=Math.floor(h[1]),b[2]=Math.floor(h[2]),b}function m(h,w){const b=w??new t(3);return b[0]=Math.round(h[0]),b[1]=Math.round(h[1]),b[2]=Math.round(h[2]),b}function g(h,w=0,b=1,$){const M=$??new t(3);return M[0]=Math.min(b,Math.max(w,h[0])),M[1]=Math.min(b,Math.max(w,h[1])),M[2]=Math.min(b,Math.max(w,h[2])),M}function S(h,w,b){const $=b??new t(3);return $[0]=h[0]+w[0],$[1]=h[1]+w[1],$[2]=h[2]+w[2],$}function A(h,w,b,$){const M=$??new t(3);return M[0]=h[0]+w[0]*b,M[1]=h[1]+w[1]*b,M[2]=h[2]+w[2]*b,M}function I(h,w){const b=h[0],$=h[1],M=h[2],U=w[0],O=w[1],R=w[2],L=Math.sqrt(b*b+$*$+M*M),j=Math.sqrt(U*U+O*O+R*R),V=L*j,Z=V&&K(h,w)/V;return Math.acos(Z)}function k(h,w,b){const $=b??new t(3);return $[0]=h[0]-w[0],$[1]=h[1]-w[1],$[2]=h[2]-w[2],$}const F=k;function z(h,w){return Math.abs(h[0]-w[0])1e-5?(b[0]=$/O,b[1]=M/O,b[2]=U/O):(b[0]=0,b[1]=0,b[2]=0),b}function ie(h,w){const b=w??new t(3);return b[0]=-h[0],b[1]=-h[1],b[2]=-h[2],b}function ft(h,w){const b=w??new t(3);return b[0]=h[0],b[1]=h[1],b[2]=h[2],b}const oe=ft;function Lt(h,w,b){const $=b??new t(3);return $[0]=h[0]*w[0],$[1]=h[1]*w[1],$[2]=h[2]*w[2],$}const ae=Lt;function Gt(h,w,b){const $=b??new t(3);return $[0]=h[0]/w[0],$[1]=h[1]/w[1],$[2]=h[2]/w[2],$}const Qt=Gt;function Wt(h=1,w){const b=w??new t(3),$=Math.random()*2*Math.PI,M=Math.random()*2-1,U=Math.sqrt(1-M*M)*h;return b[0]=Math.cos($)*U,b[1]=Math.sin($)*U,b[2]=M*h,b}function c(h){const w=h??new t(3);return w[0]=0,w[1]=0,w[2]=0,w}function x(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2],R=w[3]*M+w[7]*U+w[11]*O+w[15]||1;return $[0]=(w[0]*M+w[4]*U+w[8]*O+w[12])/R,$[1]=(w[1]*M+w[5]*U+w[9]*O+w[13])/R,$[2]=(w[2]*M+w[6]*U+w[10]*O+w[14])/R,$}function a(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2];return $[0]=M*w[0*4+0]+U*w[1*4+0]+O*w[2*4+0],$[1]=M*w[0*4+1]+U*w[1*4+1]+O*w[2*4+1],$[2]=M*w[0*4+2]+U*w[1*4+2]+O*w[2*4+2],$}function l(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2];return $[0]=M*w[0]+U*w[4]+O*w[8],$[1]=M*w[1]+U*w[5]+O*w[9],$[2]=M*w[2]+U*w[6]+O*w[10],$}function y(h,w,b){const $=b??new t(3),M=w[0],U=w[1],O=w[2],R=w[3]*2,L=h[0],j=h[1],V=h[2],Z=U*V-O*j,J=O*L-M*V,dt=M*j-U*L;return $[0]=L+Z*R+(U*dt-O*J)*2,$[1]=j+J*R+(O*Z-M*dt)*2,$[2]=V+dt*R+(M*J-U*Z)*2,$}function v(h,w){const b=w??new t(3);return b[0]=h[12],b[1]=h[13],b[2]=h[14],b}function T(h,w,b){const $=b??new t(3),M=w*4;return $[0]=h[M+0],$[1]=h[M+1],$[2]=h[M+2],$}function s(h,w){const b=w??new t(3),$=h[0],M=h[1],U=h[2],O=h[4],R=h[5],L=h[6],j=h[8],V=h[9],Z=h[10];return b[0]=Math.sqrt($*$+M*M+U*U),b[1]=Math.sqrt(O*O+R*R+L*L),b[2]=Math.sqrt(j*j+V*V+Z*Z),b}function f(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[0],O[1]=U[1]*Math.cos(b)-U[2]*Math.sin(b),O[2]=U[1]*Math.sin(b)+U[2]*Math.cos(b),M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function o(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[2]*Math.sin(b)+U[0]*Math.cos(b),O[1]=U[1],O[2]=U[2]*Math.cos(b)-U[0]*Math.sin(b),M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function u(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[0]*Math.cos(b)-U[1]*Math.sin(b),O[1]=U[0]*Math.sin(b)+U[1]*Math.cos(b),O[2]=U[2],M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function p(h,w,b){const $=b??new t(3);return Ft(h,$),ut($,w,$)}function _(h,w,b){const $=b??new t(3);return Y(h)>w?p(h,w,$):ft(h,$)}function D(h,w,b){const $=b??new t(3);return N(h,w,.5,$)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,angle:I,subtract:k,sub:F,equalsApproximately:z,equals:B,lerp:N,lerpV:q,max:tt,min:st,mulScalar:ut,scale:rt,divScalar:xt,inverse:lt,invert:vt,cross:nt,dot:K,length:Y,len:it,lengthSq:X,lenSq:et,distance:H,dist:re,distanceSq:Pt,distSq:se,normalize:Ft,negate:ie,copy:ft,clone:oe,multiply:Lt,mul:ae,divide:Gt,div:Qt,random:Wt,zero:c,transformMat4:x,transformMat4Upper3x3:a,transformMat3:l,transformQuat:y,getTranslation:v,getAxis:T,getScaling:s,rotateX:f,rotateY:o,rotateZ:u,setLength:p,truncate:_,midpoint:D}}const ls=new Map;function er(t){let e=ls.get(t);return e||(e=vu(t),ls.set(t,e)),e}function bu(t){const e=bi(t),n=er(t);function r(c,x,a,l,y,v,T,s,f){const o=new t(12);return o[3]=0,o[7]=0,o[11]=0,c!==void 0&&(o[0]=c,x!==void 0&&(o[1]=x,a!==void 0&&(o[2]=a,l!==void 0&&(o[4]=l,y!==void 0&&(o[5]=y,v!==void 0&&(o[6]=v,T!==void 0&&(o[8]=T,s!==void 0&&(o[9]=s,f!==void 0&&(o[10]=f))))))))),o}function i(c,x,a,l,y,v,T,s,f,o){const u=o??new t(12);return u[0]=c,u[1]=x,u[2]=a,u[3]=0,u[4]=l,u[5]=y,u[6]=v,u[7]=0,u[8]=T,u[9]=s,u[10]=f,u[11]=0,u}function d(c,x){const a=x??new t(12);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=0,a[4]=c[4],a[5]=c[5],a[6]=c[6],a[7]=0,a[8]=c[8],a[9]=c[9],a[10]=c[10],a[11]=0,a}function m(c,x){const a=x??new t(12),l=c[0],y=c[1],v=c[2],T=c[3],s=l+l,f=y+y,o=v+v,u=l*s,p=y*s,_=y*f,D=v*s,h=v*f,w=v*o,b=T*s,$=T*f,M=T*o;return a[0]=1-_-w,a[1]=p+M,a[2]=D-$,a[3]=0,a[4]=p-M,a[5]=1-u-w,a[6]=h+b,a[7]=0,a[8]=D+$,a[9]=h-b,a[10]=1-u-_,a[11]=0,a}function g(c,x){const a=x??new t(12);return a[0]=-c[0],a[1]=-c[1],a[2]=-c[2],a[4]=-c[4],a[5]=-c[5],a[6]=-c[6],a[8]=-c[8],a[9]=-c[9],a[10]=-c[10],a}function S(c,x){const a=x??new t(12);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[4]=c[4],a[5]=c[5],a[6]=c[6],a[8]=c[8],a[9]=c[9],a[10]=c[10],a}const A=S;function I(c,x){return Math.abs(c[0]-x[0])C?(a[0]=c[0]/y,a[1]=c[1]/y,a[2]=c[2]/y):(a[0]=1,a[1]=0,a[2]=0),{angle:l,axis:a}}function g(c,x){const a=Y(c,x);return Math.acos(2*a*a-1)}function S(c,x,a){const l=a??new t(4),y=c[0],v=c[1],T=c[2],s=c[3],f=x[0],o=x[1],u=x[2],p=x[3];return l[0]=y*p+s*f+v*u-T*o,l[1]=v*p+s*o+T*f-y*u,l[2]=T*p+s*u+y*o-v*f,l[3]=s*p-y*f-v*o-T*u,l}const A=S;function I(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u+f*o,l[1]=T*u+s*o,l[2]=s*u-T*o,l[3]=f*u-v*o,l}function k(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u-s*o,l[1]=T*u+f*o,l[2]=s*u+v*o,l[3]=f*u-T*o,l}function F(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u+T*o,l[1]=T*u-v*o,l[2]=s*u+f*o,l[3]=f*u-s*o,l}function z(c,x,a,l){const y=l??new t(4),v=c[0],T=c[1],s=c[2],f=c[3];let o=x[0],u=x[1],p=x[2],_=x[3],D=v*o+T*u+s*p+f*_;D<0&&(D=-D,o=-o,u=-u,p=-p,_=-_);let h,w;if(1-D>C){const b=Math.acos(D),$=Math.sin(b);h=Math.sin((1-a)*b)/$,w=Math.sin(a*b)/$}else h=1-a,w=a;return y[0]=h*v+w*o,y[1]=h*T+w*u,y[2]=h*s+w*p,y[3]=h*f+w*_,y}function B(c,x){const a=x??new t(4),l=c[0],y=c[1],v=c[2],T=c[3],s=l*l+y*y+v*v+T*T,f=s?1/s:0;return a[0]=-l*f,a[1]=-y*f,a[2]=-v*f,a[3]=T*f,a}function N(c,x){const a=x??new t(4);return a[0]=-c[0],a[1]=-c[1],a[2]=-c[2],a[3]=c[3],a}function q(c,x){const a=x??new t(4),l=c[0]+c[5]+c[10];if(l>0){const y=Math.sqrt(l+1);a[3]=.5*y;const v=.5/y;a[0]=(c[6]-c[9])*v,a[1]=(c[8]-c[2])*v,a[2]=(c[1]-c[4])*v}else{let y=0;c[5]>c[0]&&(y=1),c[10]>c[y*4+y]&&(y=2);const v=(y+1)%3,T=(y+2)%3,s=Math.sqrt(c[y*4+y]-c[v*4+v]-c[T*4+T]+1);a[y]=.5*s;const f=.5/s;a[3]=(c[v*4+T]-c[T*4+v])*f,a[v]=(c[v*4+y]+c[y*4+v])*f,a[T]=(c[T*4+y]+c[y*4+T])*f}return a}function tt(c,x,a,l,y){const v=y??new t(4),T=c*.5,s=x*.5,f=a*.5,o=Math.sin(T),u=Math.cos(T),p=Math.sin(s),_=Math.cos(s),D=Math.sin(f),h=Math.cos(f);switch(l){case"xyz":v[0]=o*_*h+u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h-o*p*D;break;case"xzy":v[0]=o*_*h-u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h+o*p*D;break;case"yxz":v[0]=o*_*h+u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h+o*p*D;break;case"yzx":v[0]=o*_*h+u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h-o*p*D;break;case"zxy":v[0]=o*_*h-u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h-o*p*D;break;case"zyx":v[0]=o*_*h-u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h+o*p*D;break;default:throw new Error(`Unknown rotation order: ${l}`)}return v}function st(c,x){const a=x??new t(4);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a}const ut=st;function rt(c,x,a){const l=a??new t(4);return l[0]=c[0]+x[0],l[1]=c[1]+x[1],l[2]=c[2]+x[2],l[3]=c[3]+x[3],l}function xt(c,x,a){const l=a??new t(4);return l[0]=c[0]-x[0],l[1]=c[1]-x[1],l[2]=c[2]-x[2],l[3]=c[3]-x[3],l}const lt=xt;function vt(c,x,a){const l=a??new t(4);return l[0]=c[0]*x,l[1]=c[1]*x,l[2]=c[2]*x,l[3]=c[3]*x,l}const nt=vt;function K(c,x,a){const l=a??new t(4);return l[0]=c[0]/x,l[1]=c[1]/x,l[2]=c[2]/x,l[3]=c[3]/x,l}function Y(c,x){return c[0]*x[0]+c[1]*x[1]+c[2]*x[2]+c[3]*x[3]}function it(c,x,a,l){const y=l??new t(4);return y[0]=c[0]+a*(x[0]-c[0]),y[1]=c[1]+a*(x[1]-c[1]),y[2]=c[2]+a*(x[2]-c[2]),y[3]=c[3]+a*(x[3]-c[3]),y}function X(c){const x=c[0],a=c[1],l=c[2],y=c[3];return Math.sqrt(x*x+a*a+l*l+y*y)}const et=X;function H(c){const x=c[0],a=c[1],l=c[2],y=c[3];return x*x+a*a+l*l+y*y}const re=H;function Pt(c,x){const a=x??new t(4),l=c[0],y=c[1],v=c[2],T=c[3],s=Math.sqrt(l*l+y*y+v*v+T*T);return s>1e-5?(a[0]=l/s,a[1]=y/s,a[2]=v/s,a[3]=T/s):(a[0]=0,a[1]=0,a[2]=0,a[3]=1),a}function se(c,x){return Math.abs(c[0]-x[0]).999999?(l[0]=0,l[1]=0,l[2]=0,l[3]=1,l):(e.cross(c,x,ft),l[0]=ft[0],l[1]=ft[1],l[2]=ft[2],l[3]=1+y,Pt(l,l))}const Gt=new t(4),Qt=new t(4);function Wt(c,x,a,l,y,v){const T=v??new t(4);return z(c,l,y,Gt),z(x,a,y,Qt),z(Gt,Qt,2*y*(1-y),T),T}return{create:n,fromValues:r,set:i,fromAxisAngle:d,toAxisAngle:m,angle:g,multiply:S,mul:A,rotateX:I,rotateY:k,rotateZ:F,slerp:z,inverse:B,conjugate:N,fromMat:q,fromEuler:tt,copy:st,clone:ut,add:rt,subtract:xt,sub:lt,mulScalar:vt,scale:nt,divScalar:K,dot:Y,lerp:it,length:X,len:et,lengthSq:H,lenSq:re,normalize:Pt,equalsApproximately:se,equals:Ft,identity:ie,rotationTo:ae,sqlerp:Wt}}const ds=new Map;function Tu(t){let e=ds.get(t);return e||(e=Mu(t),ds.set(t,e)),e}function Du(t){function e(a,l,y,v){const T=new t(4);return a!==void 0&&(T[0]=a,l!==void 0&&(T[1]=l,y!==void 0&&(T[2]=y,v!==void 0&&(T[3]=v)))),T}const n=e;function r(a,l,y,v,T){const s=T??new t(4);return s[0]=a,s[1]=l,s[2]=y,s[3]=v,s}function i(a,l){const y=l??new t(4);return y[0]=Math.ceil(a[0]),y[1]=Math.ceil(a[1]),y[2]=Math.ceil(a[2]),y[3]=Math.ceil(a[3]),y}function d(a,l){const y=l??new t(4);return y[0]=Math.floor(a[0]),y[1]=Math.floor(a[1]),y[2]=Math.floor(a[2]),y[3]=Math.floor(a[3]),y}function m(a,l){const y=l??new t(4);return y[0]=Math.round(a[0]),y[1]=Math.round(a[1]),y[2]=Math.round(a[2]),y[3]=Math.round(a[3]),y}function g(a,l=0,y=1,v){const T=v??new t(4);return T[0]=Math.min(y,Math.max(l,a[0])),T[1]=Math.min(y,Math.max(l,a[1])),T[2]=Math.min(y,Math.max(l,a[2])),T[3]=Math.min(y,Math.max(l,a[3])),T}function S(a,l,y){const v=y??new t(4);return v[0]=a[0]+l[0],v[1]=a[1]+l[1],v[2]=a[2]+l[2],v[3]=a[3]+l[3],v}function A(a,l,y,v){const T=v??new t(4);return T[0]=a[0]+l[0]*y,T[1]=a[1]+l[1]*y,T[2]=a[2]+l[2]*y,T[3]=a[3]+l[3]*y,T}function I(a,l,y){const v=y??new t(4);return v[0]=a[0]-l[0],v[1]=a[1]-l[1],v[2]=a[2]-l[2],v[3]=a[3]-l[3],v}const k=I;function F(a,l){return Math.abs(a[0]-l[0])1e-5?(y[0]=v/o,y[1]=T/o,y[2]=s/o,y[3]=f/o):(y[0]=0,y[1]=0,y[2]=0,y[3]=0),y}function se(a,l){const y=l??new t(4);return y[0]=-a[0],y[1]=-a[1],y[2]=-a[2],y[3]=-a[3],y}function Ft(a,l){const y=l??new t(4);return y[0]=a[0],y[1]=a[1],y[2]=a[2],y[3]=a[3],y}const ie=Ft;function ft(a,l,y){const v=y??new t(4);return v[0]=a[0]*l[0],v[1]=a[1]*l[1],v[2]=a[2]*l[2],v[3]=a[3]*l[3],v}const oe=ft;function Lt(a,l,y){const v=y??new t(4);return v[0]=a[0]/l[0],v[1]=a[1]/l[1],v[2]=a[2]/l[2],v[3]=a[3]/l[3],v}const ae=Lt;function Gt(a){const l=a??new t(4);return l[0]=0,l[1]=0,l[2]=0,l[3]=0,l}function Qt(a,l,y){const v=y??new t(4),T=a[0],s=a[1],f=a[2],o=a[3];return v[0]=l[0]*T+l[4]*s+l[8]*f+l[12]*o,v[1]=l[1]*T+l[5]*s+l[9]*f+l[13]*o,v[2]=l[2]*T+l[6]*s+l[10]*f+l[14]*o,v[3]=l[3]*T+l[7]*s+l[11]*f+l[15]*o,v}function Wt(a,l,y){const v=y??new t(4);return Pt(a,v),st(v,l,v)}function c(a,l,y){const v=y??new t(4);return nt(a)>l?Wt(a,l,v):Ft(a,v)}function x(a,l,y){const v=y??new t(4);return B(a,l,.5,v)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,subtract:I,sub:k,equalsApproximately:F,equals:z,lerp:B,lerpV:N,max:q,min:tt,mulScalar:st,scale:ut,divScalar:rt,inverse:xt,invert:lt,dot:vt,length:nt,len:K,lengthSq:Y,lenSq:it,distance:X,dist:et,distanceSq:H,distSq:re,normalize:Pt,negate:se,copy:Ft,clone:ie,multiply:ft,mul:oe,divide:Lt,div:ae,zero:Gt,transformMat4:Qt,setLength:Wt,truncate:c,midpoint:x}}const ps=new Map;function Uu(t){let e=ps.get(t);return e||(e=Du(t),ps.set(t,e)),e}function Vr(t,e,n,r,i,d){return{mat3:_u(t),mat4:Su(e),quat:Tu(n),vec2:bi(r),vec3:er(i),vec4:Uu(d)}}const{mat3:Ou,mat4:Eu,quat:rf,vec2:ct,vec3:Au,vec4:sf}=Vr(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array);Vr(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array);Vr(gu,Array,Array,Array,Array,Array);function _i(){return new Promise(t=>requestAnimationFrame(t))}function vr({x:t,y:e}){return G(-e,t)}function ku(t,e,n,r,i){return G(t.x+e.x*n+r.x*i,t.y+e.y*n+r.y*i)}const[ce,$i]=yu([]);qt(!1);const{sign:Si,sqrt:br,abs:ws,min:Iu,max:Pu}=Math;function Fu(t){const n=pe(ce).findIndex(r=>ct.distance(r.center,t){r.push({center:t,radius:0})})),ce.length-1):n}function zu(t){const e=pe(ce);let n=Number.POSITIVE_INFINITY,r;const{center:i}=e[t];for(let m=0;mi}}function Bu(t,e,n){const r=ct.sub(e.center,t.center,G()),i=e.radius-t.radius,d=ct.dot(r,r),m=ct.dot(n,r);return(d-i*i)/(2*(m+i*ct.length(n)))-t.radius}function ju(t,e){const n=pe(ce),r=n[t],i=n[e],d=ct.normalize(ct.sub(i.center,r.center,G()),G());let m=Number.POSITIVE_INFINITY,g;for(let A=0;A=-r.radius/2&&kct.addScaled(r.center,d,r.radius+A,G())}}function Ru(t,e,n,r){t.radiusws(ct.distance([it,-X],[z,B])-m-et)?Number.POSITIVE_INFINITY:et}function Vu(t,e,n,r){t.radius>e.radius&&([t,e]=[e,t]);const i=ct.sub(e.center,t.center,G()),d=ct.length(i),m=t.radius,g=e.radius,S=n,A=(m*m-g*g+2*(m-g)*S+d*d)/(2*d),I=(m+S)**2-A*A;if(I<0)return;const k=ct.scale(i,1/d,G()),F=vr(k),z=br(I),B=Si(ct.dot(vr(i),ct.sub(r.center,t.center,G())));return ku(t.center,k,A,F,z*B)}function Nu(t,e,n){const r=pe(ce),i=r[n],d=r[t],m=r[e];let g=Number.POSITIVE_INFINITY,S;for(let I=0;IVu(d,m,I,i)}}async function ur(t,e,n,r,i){const d=ce[t];for(;;){if(await Promise.race([_i(),i])instanceof PointerEvent)return;const g=Iu(e,d.radius*1.025+.004/r()),S=n(g);if(!S||($i(t,vi(A=>{A.radius=g,A.center=S})),g===e))return}}const Mi=Or(),Lu=Mi.Provider;function nr(){return kr(Mi,"useCanvas","CanvasContext")}function Gu(){let t,e;return{promise:new Promise((r,i)=>{t=r,e=i}),resolve:t,reject:e}}var Nr=class{constructor(){E(this,"lastUniqueId",0)}makeUnique(e){let n;return e?(n=e.replaceAll(/\s/g,"_"),n=n.replaceAll(/[^\w\d]/g,"")):n="item",`${n}_${this.lastUniqueId++}`}},Lr=class{constructor(){E(this,"_usedNames",new Set)}makeUnique(e){if(e===void 0)throw new Error("Unnamed item found when using a strict name registry");let n=0,r=e;for(;this._usedNames.has(r);)n++,r=`${e}_${n}`;return this._usedNames.add(r),r}};function _r(t){return t?.resourceType==="slot"}function $r(t){return t?.resourceType==="derived"}function Sr(t){return t?.["~providing"]!==void 0}function Gr(t){return t?.resourceType==="accessor"}function qu(t,e){let n="size"in t?t.size:t.currentByteOffset,r=e-1,i=n&r;"skipBytes"in t?t.skipBytes(e-i&r):t.add(e-i&r)}var $t=qu,le={bool(t,e,n){t.writeBool(n)},f32(t,e,n){t.writeFloat32(n)},f16(t,e,n){t.writeFloat16(n)},i32(t,e,n){t.writeInt32(n)},u32(t,e,n){t.writeUint32(n)},vec2f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y)},vec2h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y)},vec2i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y)},vec2u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y)},vec3f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y),t.writeFloat32(n.z)},vec3h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y),t.writeFloat16(n.z)},vec3i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)},vec3u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y),t.writeUint32(n.z)},vec4f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y),t.writeFloat32(n.z),t.writeFloat32(n.w)},vec4h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y),t.writeFloat16(n.z),t.writeFloat16(n.w)},vec4i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)},vec4u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y),t.writeUint32(n.z),t.writeUint32(n.w)},mat2x2f(t,e,n){for(let r=0;r{let n=t.readFloat32();return t.readFloat32(),n};return Je(t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e())},mat4x4f(t){return fi(t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},struct(t,e){let n=St(e);$t(t,n);let r={};for(let[i,d]of Object.entries(e.propTypes))$t(t,St(d)),r[i]=fe(t,d);return $t(t,n),r},array(t,e){if(e.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let n=St(e),r=[];for(let i=0;it.readUint8(),uint8x2:t=>Ue(t.readUint8(),t.readUint8()),uint8x4:t=>ee(t.readUint8(),t.readUint8(),t.readUint8(),t.readUint8()),sint8:t=>t.readInt8(),sint8x2:t=>De(t.readInt8(),t.readInt8()),sint8x4:t=>te(t.readInt8(),t.readInt8(),t.readInt8(),t.readInt8()),unorm8:t=>t.readUint8()/255,unorm8x2:t=>G(t.readUint8()/255,t.readUint8()/255),unorm8x4:t=>ot(t.readUint8()/255,t.readUint8()/255,t.readUint8()/255,t.readUint8()/255),snorm8:t=>(t.readUint8()-128)/127,snorm8x2:t=>G((t.readUint8()-128)/127,(t.readUint8()-128)/127),snorm8x4:t=>ot((t.readUint8()-128)/127,(t.readUint8()-128)/127,(t.readUint8()-128)/127,(t.readUint8()-128)/127),uint16:t=>t.readUint16(),uint16x2:t=>Ue(t.readUint16(),t.readUint16()),uint16x4:t=>ee(t.readUint16(),t.readUint16(),t.readUint16(),t.readUint16()),sint16:t=>t.readInt16(),sint16x2:t=>De(t.readInt16(),t.readInt16()),sint16x4:t=>te(t.readInt16(),t.readInt16(),t.readInt16(),t.readInt16()),unorm16:t=>t.readUint16()/65535,unorm16x2:t=>G(t.readUint16()/65535,t.readUint16()/65535),unorm16x4:t=>ot(t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535),snorm16:t=>(t.readUint16()-32768)/32767,snorm16x2:t=>G(Me.snorm16(t),Me.snorm16(t)),snorm16x4:t=>ot(Me.snorm16(t),Me.snorm16(t),Me.snorm16(t),Me.snorm16(t)),float16(t){return t.readFloat16()},float16x2:t=>G(t.readFloat16(),t.readFloat16()),float16x4:t=>ot(t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16()),float32:t=>t.readFloat32(),float32x2:t=>G(t.readFloat32(),t.readFloat32()),float32x3:t=>Qe(t.readFloat32(),t.readFloat32(),t.readFloat32()),float32x4:t=>ot(t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()),uint32:t=>t.readUint32(),uint32x2:t=>Ue(t.readUint32(),t.readUint32()),uint32x3:t=>Oe(t.readUint32(),t.readUint32(),t.readUint32()),uint32x4:t=>ee(t.readUint32(),t.readUint32(),t.readUint32(),t.readUint32()),sint32:t=>t.readInt32(),sint32x2:t=>De(t.readInt32(),t.readInt32()),sint32x3:t=>mr(t.readInt32(),t.readInt32(),t.readInt32()),sint32x4:t=>te(t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32()),"unorm10-10-10-2"(t){let e=t.readUint32(),n=(e>>22)/1023,r=(e>>12&1023)/1023,i=(e>>2&1023)/1023,d=(e&3)/3;return ot(n,r,i,d)},"unorm8x4-bgra"(t){let e=t.readByte()/255,n=t.readByte()/255,r=t.readByte()/255,i=t.readByte()/255;return ot(r,n,e,i)},unstruct(t,e){let n={};for(let[r,i]of Object.entries(e.propTypes))n[r]=fe(t,i);return n},disarray(t,e){let n=St(e),r=[];for(let i=0;i"}),this.initial)){let r=new xn(this._buffer.getMappedRange());He(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(e){return this._label=e,this._buffer&&(this._buffer.label=e),this}$usage(...e){var n;for(let r of e){if((n=this._disallowedUsages)!=null&&n.includes(r))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${r}`);this.flags|=r==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=r==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=r==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||r==="uniform",this.usableAsStorage=this.usableAsStorage||r==="storage",this.usableAsVertex=this.usableAsVertex||r==="vertex"}return this}$addFlags(e){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return e&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):e&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=e,this)}write(e){let n=this.buffer,r=this._group.device;if(n.mapState==="mapped"){let m=n.getMappedRange();He(new xn(m),this.dataType,e);return}let i=wt(this.dataType);this._group.flush();let d=new ArrayBuffer(i);He(new xn(d),this.dataType,e),r.queue.writeBuffer(n,0,d,0,i)}copyFrom(e){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let n=wt(this.dataType);this._group.commandEncoder.copyBufferToBuffer(e.buffer,0,this.buffer,0,n)}async read(){this._group.flush();let e=this.buffer,n=this._group.device;if(e.mapState==="mapped"){let m=e.getMappedRange();return fe(new gn(m),this.dataType)}if(e.usage&GPUBufferUsage.MAP_READ){await e.mapAsync(GPUMapMode.READ);let m=e.getMappedRange(),g=fe(new gn(m),this.dataType);return e.unmap(),g}let r=n.createBuffer({size:wt(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),i=n.createCommandEncoder();i.copyBufferToBuffer(e,0,r,0,wt(this.dataType)),n.queue.submit([i.finish()]),await n.queue.onSubmittedWorkDone(),await r.mapAsync(GPUMapMode.READ,0,wt(this.dataType));let d=fe(new gn(r.getMappedRange()),this.dataType);return r.unmap(),r.destroy(),d}destroy(){var e;this._destroyed||(this._destroyed=!0,this._ownBuffer&&((e=this._buffer)==null||e.destroy()))}toString(){var e;return`buffer:${(e=this._label)!=null?e:""}`}};function ms(t){return!!(t!=null&&t.usableAsStorage)}var Xu=class Di extends Error{constructor(e){var n;super(`Resource '${(n=e.label)!=null?n:""}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,Di.prototype)}};function Zu(t){return t?.resourceType==="buffer-usage"}var Hu={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},gs=class{constructor(e,n,r){this.usage=e,this.dataType=n,this._membership=r,E(this,"~repr"),E(this,"resourceType","buffer-usage")}get label(){return this._membership.key}"~resolve"(e){let n=e.names.makeUnique(this.label),r=e.allocateLayoutEntry(this._membership.layout),i=Hu[this.usage];return e.addDeclaration(`@group(${r}) @binding(${this._membership.idx}) var<${i}> ${n}: ${e.resolve(this.dataType)};`),n}toString(){var e;return`${this.usage}:${(e=this.label)!=null?e:""}`}get value(){if(!we())throw new Error("Cannot access buffer's value directly in JS.");return this}},Ku=class{constructor(t){this._membership=t,E(this,"resourceType","sampler")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: sampler;`),e}},Qu=class{constructor(t){this._membership=t,E(this,"resourceType","sampler-comparison")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: sampler_comparison;`),e}},Ju={r8unorm:P,r8snorm:P,r8uint:gt,r8sint:Zt,r16uint:gt,r16sint:Zt,r16float:P,rg8unorm:P,rg8snorm:P,rg8uint:gt,rg8sint:Zt,r32uint:gt,r32sint:Zt,r32float:P,rg16uint:gt,rg16sint:Zt,rg16float:P,rgba8unorm:P,"rgba8unorm-srgb":P,rgba8snorm:P,rgba8uint:gt,rgba8sint:Zt,bgra8unorm:P,"bgra8unorm-srgb":P,rgb9e5ufloat:P,rgb10a2uint:gt,rgb10a2unorm:P,rg11b10ufloat:P,rg32uint:gt,rg32sint:Zt,rg32float:P,rgba16uint:gt,rgba16sint:Zt,rgba16float:P,rgba32uint:gt,rgba32sint:Zt,rgba32float:P,stencil8:P,depth16unorm:P,depth24plus:P,"depth24plus-stencil8":P,depth32float:P,"depth32float-stencil8":P,"bc1-rgba-unorm":P,"bc1-rgba-unorm-srgb":P,"bc2-rgba-unorm":P,"bc2-rgba-unorm-srgb":P,"bc3-rgba-unorm":P,"bc3-rgba-unorm-srgb":P,"bc4-r-unorm":P,"bc4-r-snorm":P,"bc5-rg-unorm":P,"bc5-rg-snorm":P,"bc6h-rgb-ufloat":P,"bc6h-rgb-float":P,"bc7-rgba-unorm":P,"bc7-rgba-unorm-srgb":P,"etc2-rgb8unorm":P,"etc2-rgb8unorm-srgb":P,"etc2-rgb8a1unorm":P,"etc2-rgb8a1unorm-srgb":P,"etc2-rgba8unorm":P,"etc2-rgba8unorm-srgb":P,"eac-r11unorm":P,"eac-r11snorm":P,"eac-rg11unorm":P,"eac-rg11snorm":P,"astc-4x4-unorm":P,"astc-4x4-unorm-srgb":P,"astc-5x4-unorm":P,"astc-5x4-unorm-srgb":P,"astc-5x5-unorm":P,"astc-5x5-unorm-srgb":P,"astc-6x5-unorm":P,"astc-6x5-unorm-srgb":P,"astc-6x6-unorm":P,"astc-6x6-unorm-srgb":P,"astc-8x5-unorm":P,"astc-8x5-unorm-srgb":P,"astc-8x6-unorm":P,"astc-8x6-unorm-srgb":P,"astc-8x8-unorm":P,"astc-8x8-unorm-srgb":P,"astc-10x5-unorm":P,"astc-10x5-unorm-srgb":P,"astc-10x6-unorm":P,"astc-10x6-unorm-srgb":P,"astc-10x8-unorm":P,"astc-10x8-unorm-srgb":P,"astc-10x10-unorm":P,"astc-10x10-unorm-srgb":P,"astc-12x10-unorm":P,"astc-12x10-unorm-srgb":P,"astc-12x12-unorm":P,"astc-12x12-unorm-srgb":P},Gn={rgba8unorm:ot,rgba8snorm:ot,rgba8uint:ee,rgba8sint:te,rgba16uint:ee,rgba16sint:te,rgba16float:ot,r32uint:ee,r32sint:te,r32float:ot,rg32uint:ee,rg32sint:te,rg32float:ot,rgba32uint:ee,rgba32sint:te,rgba32float:ot,bgra8unorm:ot},tc={f32:"float",u32:"uint",i32:"sint"},ec={float:P,"unfilterable-float":P,uint:gt,sint:Zt,depth:P};function nc(t,e){return new ic(t,e)}function en(t){return t?.resourceType==="texture"}function rc(t){return t?.resourceType==="texture-storage-view"}function sc(t){return t?.resourceType==="texture-sampled-view"}var Ui={mutable:"read_write",readonly:"read",writeonly:"write"},ic=class{constructor(t,e){this.props=t,this._branch=e,E(this,"resourceType","texture"),E(this,"usableAsSampled",!1),E(this,"usableAsStorage",!1),E(this,"usableAsRender",!1),E(this,"_destroyed",!1),E(this,"_label"),E(this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC),E(this,"_texture",null)}get label(){return this._label}$name(t){return this._label=t,this}unwrap(){var t,e,n,r,i;if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:(t=this._label)!=null?t:"",format:this.props.format,size:this.props.size,usage:this._flags,dimension:(e=this.props.dimension)!=null?e:"2d",viewFormats:(n=this.props.viewFormats)!=null?n:[],mipLevelCount:(r=this.props.mipLevelCount)!=null?r:1,sampleCount:(i=this.props.sampleCount)!=null?i:1})),this._texture}$usage(...t){let e=t.includes("storage"),n=t.includes("sampled"),r=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=e?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=r?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||(this.usableAsStorage=e),this.usableAsSampled||(this.usableAsSampled=n),this.usableAsRender||(this.usableAsRender=r),this}createView(t,e){if(t==="sampled")return this._asSampled(e);let n=e;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,e){var n;if(!this.usableAsStorage)throw new Error("Unusable as storage");let r=(n=t?.format)!=null?n:this.props.format,i=Gn[r];return Dn(!!i),new oc(t??{},e,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){var e;if(!this.usableAsSampled)throw new Error("Unusable as sampled");let n=(e=t?.format)!=null?e:this.props.format;if(!Gn[n])throw new Error(`Unsupported storage texture format: ${n}`);return new uc(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},rr={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},oc=class{constructor(t,e,n){this.access=e,this._texture=n,E(this,"resourceType","texture-storage-view"),E(this,"texelDataType"),E(this,"dimension"),E(this,"_view"),E(this,"_format");var r,i,d;this.dimension=(i=(r=t?.dimension)!=null?r:n.props.dimension)!=null?i:"2d",this._format=(d=t?.format)!=null?d:n.props.format,this.texelDataType=Gn[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView({label:`${(t=this.label)!=null?t:""} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let e=t.names.makeUnique(this.label),{group:n,binding:r}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),i=`texture_storage_${rr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${r}) var ${e}: ${i}<${this._format}, ${Ui[this.access]}>;`),e}},ac=class{constructor(t,e,n,r){this._format=t,this.dimension=e,this.access=n,this._membership=r,E(this,"resourceType","texture-storage-view"),E(this,"texelDataType"),this.texelDataType=Gn[this._format]}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),r=`texture_storage_${rr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: ${r}<${this._format}, ${Ui[this.access]}>;`),e}},uc=class{constructor(e,n){this._props=e,this._texture=n,E(this,"resourceType","texture-sampled-view"),E(this,"channelDataType"),E(this,"dimension"),E(this,"_format"),E(this,"_view");var r,i,d;this.dimension=(i=(r=e?.dimension)!=null?r:n.props.dimension)!=null?i:"2d",this._format=(d=e?.format)!=null?d:n.props.format,this.channelDataType=Ju[this._format]}get label(){return this._texture.label}$name(e){return this._texture.$name(e),this}unwrap(){var e;return this._view||(this._view=this._texture.unwrap().createView(he({label:`${(e=this.label)!=null?e:""} - View`},this._props))),this._view}"~resolve"(e){var n;let r=e.names.makeUnique(this.label),i=((n=this._texture.props.sampleCount)!=null?n:1)>1,{group:d,binding:m}=e.allocateFixedEntry({texture:tc[this.channelDataType.type],viewDimension:this.dimension,multisampled:i},this),g=i?"texture_multisampled_2d":`texture_${rr[this.dimension]}`;return e.addDeclaration(`@group(${d}) @binding(${m}) var ${r}: ${g}<${e.resolve(this.channelDataType)}>;`),r}},cc=class{constructor(t,e,n,r){this.dimension=e,this._multisampled=n,this._membership=r,E(this,"resourceType","texture-sampled-view"),E(this,"channelDataType"),this.channelDataType=ec[t]}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),r=this._multisampled?"texture_multisampled_2d":`texture_${rr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: ${r}<${t.resolve(this.channelDataType)}>;`),e}};function lc(t){return!!(t!=null&&t.usableAsSampled)}var fc=class Oi extends Error{constructor(e){var n;super(`Resource '${(n=e.label)!=null?n:""}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,Oi.prototype)}},hc=class{constructor(t){this._membership=t,E(this,"resourceType","external-texture")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: texture_external;`),e}};function Ei(t){return new wc(t)}function Ai(t){return!!t&&t.resourceType==="bind-group-layout"}function dc(t){return!!t&&t.resourceType==="bind-group"}var pc=class ki extends Error{constructor(e,n){super(`Bind group '${e??""}' is missing a required binding '${n}'`),Object.setPrototypeOf(this,ki.prototype)}},xs=["compute"],Fe=["compute","vertex","fragment"],wc=class{constructor(t){this.entries=t,E(this,"_label"),E(this,"_index"),E(this,"resourceType","bind-group-layout"),E(this,"bound",{});var e,n,r,i,d;let m=0;for(let[g,S]of Object.entries(t)){if(S===null){m++;continue}let A={idx:m,key:g,layout:this};if("uniform"in S&&(this.bound[g]=new gs("uniform",S.uniform,A)),"storage"in S){let I="type"in S.storage?S.storage:S.storage(0);this.bound[g]=new gs((e=S.access)!=null?e:"readonly",I,A)}"texture"in S&&(this.bound[g]=new cc(S.texture,(n=S.viewDimension)!=null?n:"2d",(r=S.multisampled)!=null?r:!1,A)),"storageTexture"in S&&(this.bound[g]=new ac(S.storageTexture,(i=S.viewDimension)!=null?i:"2d",(d=S.access)!=null?d:"writeonly",A)),"externalTexture"in S&&(this.bound[g]=new hc(A)),"sampler"in S&&(S.sampler==="comparison"?this.bound[g]=new Qu(A):this.bound[g]=new Ku(A)),m++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var e;return t.device.createBindGroupLayout({label:(e=this.label)!=null?e:"",entries:Object.values(this.entries).map((n,r)=>{var i,d,m,g;if(n===null)return null;let S=n.visibility,A={binding:r,visibility:0};if("uniform"in n)S=S??Fe,A.buffer={type:"uniform"};else if("storage"in n)S=S??(n.access==="mutable"?xs:Fe),A.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)S=S??Fe,A.sampler={type:n.sampler};else if("texture"in n)S=S??Fe,A.texture={sampleType:n.texture,viewDimension:(i=n.viewDimension)!=null?i:"2d",multisampled:(d=n.multisampled)!=null?d:!1};else if("storageTexture"in n){let I=(m=n.access)!=null?m:"writeonly";S=S??(I==="readonly"?Fe:xs),A.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[I],viewDimension:(g=n.viewDimension)!=null?g:"2d"}}else"externalTexture"in n&&(S=S??Fe,A.externalTexture={});return S!=null&&S.includes("compute")&&(A.visibility|=GPUShaderStage.COMPUTE),S!=null&&S.includes("vertex")&&(A.visibility|=GPUShaderStage.VERTEX),S!=null&&S.includes("fragment")&&(A.visibility|=GPUShaderStage.FRAGMENT),A}).filter(n=>n!==null)})}populate(t){return new Ii(this,t)}},Ii=class{constructor(e,n){this.layout=e,this.entries=n,E(this,"resourceType","bind-group");for(let r of Object.keys(e.entries))if(e.entries[r]!==null&&!(r in n))throw new pc(e.label,r)}unwrap(e){var n;return e.device.createBindGroup({label:(n=this.layout.label)!=null?n:"",layout:e.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([r,i],d)=>{var m;if(i===null)return null;let g=this.entries[r];if(g===void 0)throw new Error(`'${r}' is a resource required to populate bind group layout '${(m=this.layout.label)!=null?m:""}'.`);if("uniform"in i){let S;if(Mr(g)){if(!Yu(g))throw new ns(g);S={buffer:e.unwrap(g)}}else S={buffer:g};return{binding:d,resource:S}}if("storage"in i){let S;if(Mr(g)){if(!ms(g))throw new ns(g);S={buffer:e.unwrap(g)}}else S={buffer:g};return{binding:d,resource:S}}if("texture"in i){let S;if(en(g)){if(!lc(g))throw new fc(g);S=e.unwrap(g.createView("sampled"))}else S=g;return{binding:d,resource:S}}if("storageTexture"in i){let S;if(en(g)){if(!ms(g))throw new Xu(g);i.access==="readonly"?S=e.unwrap(g.createView("readonly")):i.access==="mutable"?S=e.unwrap(g.createView("mutable")):S=e.unwrap(g.createView("writeonly"))}else S=g;return{binding:d,resource:S}}if("externalTexture"in i||"sampler"in i)return{binding:d,resource:g};throw new Error(`Malformed bind group entry: ${g} (${JSON.stringify(g)})`)}).filter(r=>r!==null)})}};function yc(t,e="vertex"){return new gc(t,e)}function mc(t){return t?.resourceType==="vertex-layout"}function vn(t,e,n){if(Le(e)||ke(e))return vn(t,e.inner,xe(n,ue(e)));if(Ne(e)){let r=n;return Object.fromEntries(Object.entries(e.propTypes).map(([i,d])=>{r=xe(r,St(d));let m=[i,vn(t,d,r)];return r+=wt(d),m}))}if(Jn(e)){let r=n;return Object.fromEntries(Object.entries(e.propTypes).map(([i,d])=>{r=xe(r,ue(d));let m=[i,vn(t,d,r)];return r+=wt(d),m}))}if("type"in e&&typeof e.type=="string"){if(ci.includes(e.type))return{_layout:t,format:e.type,offset:n};let r=qa[e.type];if(r)return{_layout:t,format:r,offset:n}}throw new Error(`Unsupported data used in vertex layout: ${String(e)}`)}var gc=class{constructor(t,e){this.schemaForCount=t,this.stepMode=e,E(this,"resourceType","vertex-layout"),E(this,"stride"),E(this,"attrib"),E(this,"_label");let n=t(0);this.stride=xe(wt(n.elementType),St(n)),this.attrib=vn(this,n.elementType,0)}get label(){return this._label}$name(t){return this._label=t,this}},vs=class{constructor(e){this._make=e,E(this,"_map",new WeakMap)}getOrMake(e,...n){if(this._map.has(e))return this._map.get(e);let r=this._make(e,...n);return this._map.set(e,r),r}};function xc(t,e){throw new Error(`Failed to handle ${t} at ${e}`)}var vc=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function bc(t){return vc.includes(t.type)}function _c(t,[e,n]){return` ${lu(n)}${e}: ${t.resolve(n)}, -`}function $c(t,e){let n=t.names.makeUnique(e.label);return t.addDeclaration(` +`)}`),this.cause=e,this.trace=n,Object.setPrototypeOf(this,wr.prototype)}appendToTrace(e){let n=[e,...this.trace];return new wr(this.cause,n)}},Oo=class Is extends Error{constructor(e){super(`Missing value for '${e}'`),this.slot=e,Object.setPrototypeOf(this,Is.prototype)}},ns=class Ps extends Error{constructor(e){var n;super(`Buffer '${(n=e.label)!=null?n:""}' is not bindable as a uniform. Use .$usage('uniform') to allow it.`),Object.setPrototypeOf(this,Ps.prototype)}},Eo=class Fs extends Error{constructor(e,n){super(`The function '${e??""}' is missing links to the following external values: ${n}.`),Object.setPrototypeOf(this,Fs.prototype)}},zs=class Bs extends Error{constructor(e){super(`Bind group was not provided for '${e??""}' layout.`),Object.setPrototypeOf(this,Bs.prototype)}},Xe=null;function Ao(t,e){On(Xe===null),Xe=t;try{return e()}finally{Xe=null}}function Zn(){return Xe}var ye=()=>Xe!==null;function ne(t){let e={"~repr":void 0,type:t.type};return Object.assign((...n)=>{var r;let i=n;if(ye())return`${e.type}(${i.join(", ")})`;if(i.length<=1)return t.makeFromScalar((r=i[0])!=null?r:0);if(i.length===t.length)return t.make(...i);throw new Error(`'${t.type}' constructor called with invalid number of arguments.`)},e)}var Hn=class{constructor(t,e){this.x=t,this.y=e,E(this,"length",2)}*[Symbol.iterator](){yield this.x,yield this.y}get 0(){return this.x}get 1(){return this.y}set 0(t){this.x=t}set 1(t){this.y=t}"~resolve"(){return`${this.kind}(${this.x}, ${this.y})`}},En=class js extends Hn{constructor(){super(...arguments),E(this,"kind","vec2f")}make2(e,n){return new js(e,n)}make3(e,n,r){return new Pn(e,n,r)}make4(e,n,r,i){return new jn(e,n,r,i)}},An=class Rs extends Hn{constructor(){super(...arguments),E(this,"kind","vec2h")}make2(e,n){return new Rs(e,n)}make3(e,n,r){return new Fn(e,n,r)}make4(e,n,r,i){return new Rn(e,n,r,i)}},kn=class Ns extends Hn{constructor(){super(...arguments),E(this,"kind","vec2i")}make2(e,n){return new Ns(e,n)}make3(e,n,r){return new zn(e,n,r)}make4(e,n,r,i){return new Nn(e,n,r,i)}},In=class Vs extends Hn{constructor(){super(...arguments),E(this,"kind","vec2u")}make2(e,n){return new Vs(e,n)}make3(e,n,r){return new Bn(e,n,r)}make4(e,n,r,i){return new Vn(e,n,r,i)}},Kn=class{constructor(e,n,r){this.x=e,this.y=n,this.z=r,E(this,"length",3)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}set 0(e){this.x=e}set 1(e){this.y=e}set 2(e){this.z=e}"~resolve"(){return`${this.kind}(${this.x}, ${this.y}, ${this.z})`}},Pn=class Ls extends Kn{constructor(){super(...arguments),E(this,"kind","vec3f")}make2(e,n){return new En(e,n)}make3(e,n,r){return new Ls(e,n,r)}make4(e,n,r,i){return new jn(e,n,r,i)}},Fn=class Gs extends Kn{constructor(){super(...arguments),E(this,"kind","vec3h")}make2(e,n){return new An(e,n)}make3(e,n,r){return new Gs(e,n,r)}make4(e,n,r,i){return new Rn(e,n,r,i)}},zn=class qs extends Kn{constructor(){super(...arguments),E(this,"kind","vec3i")}make2(e,n){return new kn(e,n)}make3(e,n,r){return new qs(e,n,r)}make4(e,n,r,i){return new Nn(e,n,r,i)}},Bn=class Ws extends Kn{constructor(){super(...arguments),E(this,"kind","vec3u")}make2(e,n){return new In(e,n)}make3(e,n,r){return new Ws(e,n,r)}make4(e,n,r,i){return new Vn(e,n,r,i)}},Qn=class{constructor(e,n,r,i){this.x=e,this.y=n,this.z=r,this.w=i,E(this,"length",4)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}set 0(e){this.x=e}set 1(e){this.y=e}set 2(e){this.z=e}set 3(e){this.w=e}"~resolve"(){return`${this.kind}(${this.x}, ${this.y}, ${this.z}, ${this.w})`}},jn=class Cs extends Qn{constructor(){super(...arguments),E(this,"kind","vec4f")}make2(e,n){return new En(e,n)}make3(e,n,r){return new Pn(e,n,r)}make4(e,n,r,i){return new Cs(e,n,r,i)}},Rn=class Ys extends Qn{constructor(){super(...arguments),E(this,"kind","vec4h")}make2(e,n){return new An(e,n)}make3(e,n,r){return new Fn(e,n,r)}make4(e,n,r,i){return new Ys(e,n,r,i)}},Nn=class Xs extends Qn{constructor(){super(...arguments),E(this,"kind","vec4i")}make2(e,n){return new kn(e,n)}make3(e,n,r){return new zn(e,n,r)}make4(e,n,r,i){return new Xs(e,n,r,i)}},Vn=class Zs extends Qn{constructor(){super(...arguments),E(this,"kind","vec4u")}make2(e,n){return new In(e,n)}make3(e,n,r){return new Bn(e,n,r)}make4(e,n,r,i){return new Zs(e,n,r,i)}},at={get:(t,e)=>{if(typeof e=="symbol"||!Number.isNaN(Number.parseInt(e)))return Reflect.get(t,e);let n=t,r=new Array(e.length),i=0;for(let d of e){switch(d){case"x":r[i]=n.x;break;case"y":r[i]=n.y;break;case"z":r[i]=n.z;break;case"w":r[i]=n.w;break;default:return Reflect.get(n,e)}i++}return e.length===4?new Proxy(n.make4(r[0],r[1],r[2],r[3]),at):e.length===3?new Proxy(n.make3(r[0],r[1],r[2]),at):e.length===2?new Proxy(n.make2(r[0],r[1]),at):Reflect.get(t,e)}},q=ne({type:"vec2f",length:2,make:(t,e)=>new Proxy(new En(t,e),at),makeFromScalar:t=>new Proxy(new En(t,t),at)}),ko=ne({type:"vec2h",length:2,make:(t,e)=>new Proxy(new An(t,e),at),makeFromScalar:t=>new Proxy(new An(t,t),at)}),Ue=ne({type:"vec2i",length:2,make:(t,e)=>new Proxy(new kn(t,e),at),makeFromScalar:t=>new Proxy(new kn(t,t),at)}),Oe=ne({type:"vec2u",length:2,make:(t,e)=>new Proxy(new In(t,e),at),makeFromScalar:t=>new Proxy(new In(t,t),at)}),tn=ne({type:"vec3f",length:3,make:(t,e,n)=>new Proxy(new Pn(t,e,n),at),makeFromScalar:t=>new Proxy(new Pn(t,t,t),at)}),Io=ne({type:"vec3h",length:3,make:(t,e,n)=>new Proxy(new Fn(t,e,n),at),makeFromScalar:t=>new Proxy(new Fn(t,t,t),at)}),yr=ne({type:"vec3i",length:3,make:(t,e,n)=>new Proxy(new zn(t,e,n),at),makeFromScalar:t=>new Proxy(new zn(t,t,t),at)}),Ee=ne({type:"vec3u",length:3,make:(t,e,n)=>new Proxy(new Bn(t,e,n),at),makeFromScalar:t=>new Proxy(new Bn(t,t,t),at)}),et=ne({type:"vec4f",length:4,make:(t,e,n,r)=>new Proxy(new jn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new jn(t,t,t,t),at)}),Po=ne({type:"vec4h",length:4,make:(t,e,n,r)=>new Proxy(new Rn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new Rn(t,t,t,t),at)}),te=ne({type:"vec4i",length:4,make:(t,e,n,r)=>new Proxy(new Nn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new Nn(t,t,t,t),at)}),ee=ne({length:4,type:"vec4u",make:(t,e,n,r)=>new Proxy(new Vn(t,e,n,r),at),makeFromScalar:t=>new Proxy(new Vn(t,t,t,t),at)}),Hs=Object.defineProperty,Fo=(t,e,n)=>e in t?Hs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zo=(t,e)=>{for(var n in e)Hs(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n)=>Fo(t,typeof e!="symbol"?e+"":e,n),Ks={};zo(Ks,{BufferReader:()=>xn,BufferWriter:()=>vn,MaxValue:()=>gt,Measurer:()=>yt,UnresolvedReferenceError:()=>De,ValidationError:()=>Jn,arrayOf:()=>Vo,bool:()=>Go,byte:()=>Zo,chars:()=>ca,concat:()=>da,dynamicArrayOf:()=>wa,f16:()=>ia,f32:()=>aa,f32Array:()=>Aa,f64Array:()=>ka,generic:()=>fa,genericEnum:()=>ha,i16:()=>Ko,i16Array:()=>Oa,i32:()=>ea,i32Array:()=>Ea,i8:()=>Yo,i8Array:()=>Ua,keyed:()=>ga,object:()=>la,optional:()=>va,string:()=>Wo,tupleOf:()=>$a,u16:()=>Jo,u16Array:()=>Ta,u32:()=>ra,u32Array:()=>Da,u8:()=>ni,u8Array:()=>Sa,u8ClampedArray:()=>Ma});var De=class Qs extends Error{constructor(e){super(e),Object.setPrototypeOf(this,Qs.prototype)}},Jn=class Js extends Error{constructor(e){super(e),Object.setPrototypeOf(this,Js.prototype)}},Bo=class{constructor(){Q(this,"size",Number.NaN),Q(this,"unbounded",this),Q(this,"isUnbounded",!0)}add(){return this}fork(){return this}},jo=new Bo,yt=class ti{constructor(){Q(this,"size",0),Q(this,"unbounded",jo),Q(this,"isUnbounded",!1)}add(e){return this.size+=e,this}fork(){const e=new ti;return e.size=this.size,e}},gt=Symbol("The biggest (in amount of bytes needed) value a schema can represent"),Mt=class{constructor(){Q(this,"__unwrapped")}resolveReferences(t){}seekProperty(t,e){return null}},Ro=class{constructor(t){this.key=t}},Ze={STRING:"string",ENUM:"enum"},No=class extends Mt{constructor(t,e){super(),this._unstableElementSchema=t,this.length=e,Q(this,"elementSchema"),this.elementSchema=t}resolveReferences(t){this.elementSchema=t.resolve(this._unstableElementSchema)}write(t,e){if(e.length!==this.length)throw new Jn(`Expected array of length ${this.length}, got ${e.length}`);for(const n of e)this.elementSchema.write(t,n)}read(t){const e=[];for(let n=0;n{const i=e.fork();for(const d of Object.values(r.properties))d.measure(gt,i);return[r,i.size]}).reduce((r,i)=>r[1]>i[1]?r:i)[0];for(const r of Object.values(n.properties))r.measure(gt,e)}else{const n=t.type,r=this.subTypeMap[n]||null;if(r===null)throw new Error(`Unknown sub-type '${n.toString()}', expected one of '${JSON.stringify(Object.keys(this.subTypeMap))}'`);for(const[i,d]of $e(r.properties))d.measure(t[i],e)}return e}};function fa(t,e){return new si(Ze.STRING,t,e)}function ha(t,e){return new si(Ze.ENUM,t,e)}function da(t){return new Ir(Object.fromEntries(t.flatMap(({properties:e})=>Object.entries(e))))}var pa=class extends Mt{constructor(t){super(),this._unstableElementType=t,Q(this,"elementType"),this.elementType=t}resolveReferences(t){this.elementType=t.resolve(this._unstableElementType)}write(t,e){t.writeUint32(e.length);for(const n of e)this.elementType.write(t,n)}read(t){const e=[],n=t.readUint32();for(let r=0;r=t.length)return null;const r=new yt;for(let i=0;it.resolve(n))}var _a=class extends Mt{constructor(t){super(),this._unstableSchemas=t,Q(this,"schemas"),this.schemas=t}resolveReferences(t){this.schemas=ba(t,this._unstableSchemas)}write(t,e){if(e.length!==this.schemas.length)throw new Jn(`Expected tuple of length ${this.schemas.length}, got ${e.length}`);for(let n=0;nnew _e(t,Uint8Array),Ma=t=>new _e(t,Uint8ClampedArray),Ta=t=>new _e(t,Uint16Array),Da=t=>new _e(t,Uint32Array),Ua=t=>new _e(t,Int8Array),Oa=t=>new _e(t,Int16Array),Ea=t=>new _e(t,Int32Array),Aa=t=>new _e(t,Float32Array),ka=t=>new _e(t,Float64Array);function Ia(){const t=new Uint8Array(4),e=new Uint32Array(t.buffer);return e[0]=1,t[0]===0}function Pa(){return Ia()?"big":"little"}function Pr(t){let e=0,n=t;return n&&"buffer"in n&&"byteOffset"in n&&(e+=n.byteOffset,n=n.buffer),{buffer:n,byteOffset:e,byteLength:t.byteLength}}var oi=class{constructor(t,e){Q(this,"dataView"),Q(this,"littleEndian"),Q(this,"byteOffset",0),Q(this,"endianness");const{byteOffset:n=0,endianness:r="system"}=e??{};this.byteOffset=n;const i=Pa();this.endianness=r==="system"?i:r,this.littleEndian=this.endianness==="little";const d=Pr(t);this.byteOffset+=d.byteOffset,this.dataView=new DataView(d.buffer)}get currentByteOffset(){return this.byteOffset}seekTo(t){this.byteOffset=t}skipBytes(t){this.byteOffset+=t}};function Fa(t){if(t===0)return 0;if(Number.isNaN(t))return 32256;if(!Number.isFinite(t))return t>0?31744:64512;const e=t<0?1:0,n=Math.abs(t),r=Math.floor(Math.log2(n)),i=n/2**r-1,d=r+15,m=Math.floor(i*1024);return e<<15|d<<10|m}function za(t){const e=(t&32768)>>15,n=(t&31744)>>10,r=t&1023;return n===0?e===0?r/1024:-r/1024:n===31?r===0?e===0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:Number.NaN:(e===0?1:-1)*(1+r/1024)*2**(n-15)}var xn=class extends oi{constructor(){super(...arguments),Q(this,"_cachedTextDecoder")}get _textDecoder(){return this._cachedTextDecoder||(this._cachedTextDecoder=new TextDecoder(void 0,{fatal:!0})),this._cachedTextDecoder}readBool(){return this.dataView.getUint8(this.byteOffset++)!==0}readByte(){return this.dataView.getUint8(this.byteOffset++)}readInt8(){return this.dataView.getInt8(this.byteOffset++)}readUint8(){return this.dataView.getUint8(this.byteOffset++)}readInt16(){const t=this.dataView.getInt16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readUint16(){const t=this.dataView.getUint16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readInt32(){const t=this.dataView.getInt32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readUint32(){const t=this.dataView.getUint32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readFloat16(){const t=this.dataView.getUint16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,za(t)}readFloat32(){const t=this.dataView.getFloat32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readString(){let t=0;for(;this.byteOffset+tye()?`u32(${t})`:typeof t=="boolean"?t?1:0:Number.isInteger(t)?((t<0||t>4294967295)&&console.warn(`u32 value ${t} overflowed`),(t&4294967295)>>>0):Math.max(0,Math.min(4294967295,Math.floor(t))),mt=Object.assign(Ba,{type:"u32"}),ja=t=>{if(ye())return`i32(${t})`;if(typeof t=="boolean")return t?1:0;if(Number.isInteger(t))return(t<-2147483648||t>2147483647)&&console.warn(`i32 value ${t} overflowed`),(t|0)&4294967295;let e=t<0?Math.ceil(t):Math.floor(t);return Math.max(-2147483648,Math.min(2147483647,e))},Zt=Object.assign(ja,{type:"i32"}),Ra=t=>{if(ye())return`f32(${t})`;if(typeof t=="boolean")return t?1:0;let e=new Float32Array(1);return e[0]=t,e[0]},I=Object.assign(Ra,{type:"f32"}),Na=t=>{if(ye())return`f16(${t})`;if(typeof t=="boolean")return t?1:0;let e=new ArrayBuffer(2);return yn.f16.write(new yn.BufferWriter(e),t),yn.f16.read(new yn.BufferReader(e))};Object.assign(Na,{type:"f16"});var Va=["bool","f32","f16","i32","u32","vec2f","vec2h","vec2i","vec2u","vec3f","vec3h","vec3i","vec3u","vec4f","vec4h","vec4i","vec4u","mat2x2f","mat3x3f","mat4x4f","struct","array","atomic","decorated"];function Ve(t){return Va.includes(t?.type)}function Fr(t){return t?.type==="array"}function Le(t){return t?.type==="struct"}function ai(t){return t?.type==="@align"}function ui(t){return t?.type==="@size"}function La(t){return t?.type==="@location"}function Ga(t){return t?.type==="@builtin"}function Ge(t){return t?.type==="decorated"}var qe=t=>new qa(t),qa=class{constructor(t){this.propTypes=t,E(this,"_label"),E(this,"type","struct"),E(this,"~repr"),E(this,"~exotic")}get label(){return this._label}$name(t){return this._label=t,this}},ve=(t,e)=>{let n=e-1,r=~n;return t&n?(t&r)+e:t},ci=["uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","unorm8x4-bgra"],Wa={f32:"float32",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",f16:"float16",vec2h:"float16x2",vec4h:"float16x4",u32:"uint32",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",i32:"sint32",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4"},Ca=["unstruct","disarray","loose-decorated",...ci];function li(t){return Ca.includes(t?.type)}function zr(t){return t?.type==="disarray"}function tr(t){return t?.type==="unstruct"}function Pe(t){return t?.type==="loose-decorated"}function He(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(ai))==null?void 0:n.value}function Ya(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(ui))==null?void 0:n.value}function mr(t){var e,n;return(n=(e=t.attribs)==null?void 0:e.find(La))==null?void 0:n.value}function er(t){return Ve(t)||li(t)}var W=class{constructor(t){this.type=t,E(this,"~repr")}},Xa={uint8:mt,uint8x2:Oe,uint8x4:ee,sint8:Zt,sint8x2:Ue,sint8x4:te,unorm8:I,unorm8x2:q,unorm8x4:et,snorm8:I,snorm8x2:q,snorm8x4:et,uint16:mt,uint16x2:Oe,uint16x4:ee,sint16:Zt,sint16x2:Ue,sint16x4:te,unorm16:I,unorm16x2:q,unorm16x4:et,snorm16:I,snorm16x2:q,snorm16x4:et,float16:I,float16x2:q,float16x4:et,float32:I,float32x2:q,float32x3:tn,float32x4:et,uint32:mt,uint32x2:Oe,uint32x3:Ee,uint32x4:ee,sint32:Zt,sint32x2:Ue,sint32x3:yr,sint32x4:te,"unorm10-10-10-2":et,"unorm8x4-bgra":et},Za=Object.keys(Xa);new W("uint8");new W("uint8x2");new W("uint8x4");new W("sint8");new W("sint8x2");new W("sint8x4");new W("unorm8");new W("unorm8x2");new W("unorm8x4");new W("snorm8");new W("snorm8x2");new W("snorm8x4");new W("uint16");new W("uint16x2");new W("uint16x4");new W("sint16");new W("sint16x2");new W("sint16x4");new W("unorm16");new W("unorm16x2");new W("unorm16x4");new W("snorm16");new W("snorm16x2");new W("snorm16x4");new W("float16");new W("float16x2");new W("float16x4");new W("float32");new W("float32x2");new W("float32x3");new W("float32x4");new W("uint32");new W("uint32x2");new W("uint32x3");new W("uint32x4");new W("sint32");new W("sint32x2");new W("sint32x3");new W("sint32x4");new W("unorm10-10-10-2");new W("unorm8x4-bgra");var Ha={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:16,vec3h:8,vec3i:16,vec3u:16,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:8,mat3x3f:16,mat4x4f:16};function Ka(t){var e,n,r;let i=t?.type,d=Ha[i];if(d!==void 0)return d;if(Le(t))return Object.values(t.propTypes).map(St).reduce((m,g)=>m>g?m:g);if(Fr(t))return St(t.elementType);if(tr(t)){let m=Object.values(t.propTypes)[0];return m&&(e=He(m))!=null?e:1}if(zr(t))return(n=He(t.elementType))!=null?n:1;if(Ge(t)||Pe(t))return(r=He(t))!=null?r:St(t.inner);if(Za.includes(i))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(t)}`)}function Qa(t){var e,n;if(tr(t)){let r=Object.values(t.propTypes)[0];return r?ue(r):1}return zr(t)?ue(t.elementType):Pe(t)?(e=He(t))!=null?e:ue(t.inner):(n=He(t))!=null?n:1}var ss=new WeakMap,is=new WeakMap;function St(t){let e=ss.get(t);return e===void 0&&(e=Ka(t),ss.set(t,e)),e}function ue(t){let e=is.get(t);return e===void 0&&(e=Qa(t),is.set(t,e)),e}var Ja={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:12,vec3h:6,vec3i:12,vec3u:12,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:16,mat3x3f:48,mat4x4f:64,uint8:1,uint8x2:2,uint8x4:4,sint8:1,sint8x2:2,sint8x4:4,unorm8:1,unorm8x2:2,unorm8x4:4,snorm8:1,snorm8x2:2,snorm8x4:4,uint16:2,uint16x2:4,uint16x4:8,sint16:2,sint16x2:4,sint16x4:8,unorm16:2,unorm16x2:4,unorm16x4:8,snorm16:2,snorm16x2:4,snorm16x4:8,float16:2,float16x2:4,float16x4:8,float32:4,float32x2:8,float32x3:12,float32x4:16,uint32:4,uint32x2:8,uint32x3:12,uint32x4:16,sint32:4,sint32x2:8,sint32x3:12,sint32x4:16,"unorm10-10-10-2":4,"unorm8x4-bgra":4};function tu(t){let e=0;for(let n of Object.values(t.propTypes)){if(Number.isNaN(e))throw new Error("Only the last property of a struct can be unbounded");if(e=ve(e,St(n)),e+=wt(n),Number.isNaN(e)&&n.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return ve(e,St(t))}function eu(t){let e=0;for(let n of Object.values(t.propTypes)){let r=ue(n);e=ve(e,r),e+=wt(n)}return e}function nu(t){var e;let n=Ja[t?.type];if(n!==void 0)return n;if(Le(t))return tu(t);if(tr(t))return eu(t);if(Fr(t)){if(t.elementCount===0)return Number.NaN;let r=St(t.elementType);return ve(wt(t.elementType),r)*t.elementCount}if(zr(t)){let r=ue(t.elementType);return ve(wt(t.elementType),r)*t.elementCount}if(Ge(t)||Pe(t))return(e=Ya(t))!=null?e:wt(t.inner);throw new Error(`Cannot determine size of data: ${t}`)}var os=new WeakMap;function wt(t){let e=os.get(t);return e===void 0&&(e=nu(t),os.set(t,e)),e}var Br=(t,e)=>new ru(t,e),ru=class{constructor(t,e){if(this.elementType=t,this.elementCount=e,E(this,"type","array"),E(this,"~repr"),E(this,"~exotic"),Number.isNaN(wt(t)))throw new Error("Cannot nest runtime sized arrays.")}};function jr(t){let e={"~repr":void 0,type:t.type,label:t.type};return Object.assign((...n)=>{let r=[];for(let i of n)if(typeof i=="number")r.push(i);else for(let d=0;dthis[n]).join(", ")})`}},iu=class extends su{constructor(){super(...arguments),E(this,"kind","mat2x2f")}makeColumn(e,n){return q(e,n)}},ou=class{constructor(...e){E(this,"columns"),E(this,"length",12),this.columns=[this.makeColumn(e[0],e[1],e[2]),this.makeColumn(e[3],e[4],e[5]),this.makeColumn(e[6],e[7],e[8])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return 0}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return 0}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return 0}set 0(e){this.columns[0].x=e}set 1(e){this.columns[0].y=e}set 2(e){this.columns[0].z=e}set 3(e){}set 4(e){this.columns[1].x=e}set 5(e){this.columns[1].y=e}set 6(e){this.columns[1].z=e}set 7(e){}set 8(e){this.columns[2].x=e}set 9(e){this.columns[2].y=e}set 10(e){this.columns[2].z=e}set 11(e){}"~resolve"(){return`${this.kind}(${this[0]}, ${this[1]}, ${this[2]}, ${this[4]}, ${this[5]}, ${this[6]}, ${this[8]}, ${this[9]}, ${this[10]})`}},au=class extends ou{constructor(){super(...arguments),E(this,"kind","mat3x3f")}makeColumn(e,n,r){return tn(e,n,r)}},uu=class{constructor(...e){E(this,"columns"),E(this,"length",16),this.columns=[this.makeColumn(e[0],e[1],e[2],e[3]),this.makeColumn(e[4],e[5],e[6],e[7]),this.makeColumn(e[8],e[9],e[10],e[11]),this.makeColumn(e[12],e[13],e[14],e[15])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return this.columns[0].w}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return this.columns[1].w}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return this.columns[2].w}get 12(){return this.columns[3].x}get 13(){return this.columns[3].y}get 14(){return this.columns[3].z}get 15(){return this.columns[3].w}set 0(e){this.columns[0].x=e}set 1(e){this.columns[0].y=e}set 2(e){this.columns[0].z=e}set 3(e){this.columns[0].w=e}set 4(e){this.columns[1].x=e}set 5(e){this.columns[1].y=e}set 6(e){this.columns[1].z=e}set 7(e){this.columns[1].w=e}set 8(e){this.columns[2].x=e}set 9(e){this.columns[2].y=e}set 10(e){this.columns[2].z=e}set 11(e){this.columns[2].w=e}set 12(e){this.columns[3].x=e}set 13(e){this.columns[3].y=e}set 14(e){this.columns[3].z=e}set 15(e){this.columns[3].w=e}"~resolve"(){return`${this.kind}(${Array.from({length:this.length}).map((e,n)=>this[n]).join(", ")})`}},cu=class extends uu{constructor(){super(...arguments),E(this,"kind","mat4x4f")}makeColumn(e,n,r,i){return et(e,n,r,i)}},lu=jr({type:"mat2x2f",rows:2,columns:2,makeFromElements:(...t)=>new iu(...t)}),en=jr({type:"mat3x3f",rows:3,columns:3,makeFromElements:(...t)=>new au(...t)}),fi=jr({type:"mat4x4f",rows:4,columns:4,makeFromElements:(...t)=>new cu(...t)});function Nt(t,e){return Ge(t)?new as(t.inner,[e,...t.attribs]):Pe(t)?new us(t.inner,[e,...t.attribs]):li(t)?new us(t,[e]):new as(t,[e])}function bn(t,e){return Nt(e,{type:"@location",value:t})}function hi(t){return(Ge(t)||Pe(t))&&t.attribs.find(Ga)!==void 0}function fu(t){return!Ge(t)&&!Pe(t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var di=class{constructor(e,n){this.inner=e,this.attribs=n,E(this,"~repr");var r,i;let d=(r=n.find(ai))==null?void 0:r.value,m=(i=n.find(ui))==null?void 0:i.value;if(d!==void 0){if(d<=0)throw new Error(`Custom data alignment must be a positive number, got: ${d}.`);if(Math.log2(d)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${d}.`);if(Ve(this.inner)&&d%St(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${d}, expected multiple of: ${St(this.inner)}.`)}if(m!==void 0){if(mt[ke][e]),n}function mi(t){lr()&&nn(Gn(t,Be),wi)()}function pu(t){return mi(t),Reflect.ownKeys(t)}const wu={get(t,e,n){if(e===Ln)return t;if(e===ke)return n;if(e===Jr)return mi(t),n;const r=Gn(t,Be),i=r[e];let d=i?i():t[e];if(e===Be||e===ge||e==="__proto__")return d;if(!i){const m=Object.getOwnPropertyDescriptor(t,e);lr()&&(typeof d!="function"||t.hasOwnProperty(e))&&!(m&&m.get)&&(d=nn(r,e,d)())}return je(d)?yi(d):d},has(t,e){return e===Ln||e===ke||e===Jr||e===Be||e===ge||e==="__proto__"?!0:(lr()&&nn(Gn(t,ge),e)(),e in t)},set(){return!0},deleteProperty(){return!0},ownKeys:pu,getOwnPropertyDescriptor:du};function Re(t,e,n,r=!1){if(!r&&t[e]===n)return;const i=t[e],d=t.length;n===void 0?(delete t[e],t[ge]&&t[ge][e]&&i!==void 0&&t[ge][e].$()):(t[e]=n,t[ge]&&t[ge][e]&&i===void 0&&t[ge][e].$());let m=Gn(t,Be),g;if((g=nn(m,e,i))&&g.$(()=>n),Array.isArray(t)&&t.length!==d){for(let S=t.length;S1){r=e.shift();const m=typeof r,g=Array.isArray(t);if(Array.isArray(r)){for(let S=0;S1){Ce(t[r],e,[r].concat(n));return}i=t[r],n=[r].concat(n)}let d=e[0];typeof d=="function"&&(d=d(i,n),d===i)||r===void 0&&d==null||(d=we(d),r===void 0||je(i)&&je(d)&&!Array.isArray(d)?gi(i,d):Re(t,r,d))}function mu(...[t,e]){const n=we(t||{}),r=Array.isArray(n),i=yi(n);function d(...m){Ts(()=>{r&&m.length===1?yu(n,m[0]):Ce(n,m)})}return[i,d]}const qn=new WeakMap,xi={get(t,e){if(e===Ln)return t;const n=t[e];let r;return je(n)?qn.get(n)||(qn.set(n,r=new Proxy(n,xi)),r):n},set(t,e,n){return Re(t,e,we(n)),!0},deleteProperty(t,e){return Re(t,e,void 0,!0),!0}};function vi(t){return e=>{if(je(e)){let n;(n=qn.get(e))||qn.set(e,n=new Proxy(e,xi)),t(n)}return e}}function gu(t,e){return class extends t{constructor(...n){super(...n),e(this)}}}const xu=gu(Array,t=>t.fill(0));let C=1e-6;function vu(t){function e(s=0,f=0){const o=new t(2);return s!==void 0&&(o[0]=s,f!==void 0&&(o[1]=f)),o}const n=e;function r(s,f,o){const u=o??new t(2);return u[0]=s,u[1]=f,u}function i(s,f){const o=f??new t(2);return o[0]=Math.ceil(s[0]),o[1]=Math.ceil(s[1]),o}function d(s,f){const o=f??new t(2);return o[0]=Math.floor(s[0]),o[1]=Math.floor(s[1]),o}function m(s,f){const o=f??new t(2);return o[0]=Math.round(s[0]),o[1]=Math.round(s[1]),o}function g(s,f=0,o=1,u){const p=u??new t(2);return p[0]=Math.min(o,Math.max(f,s[0])),p[1]=Math.min(o,Math.max(f,s[1])),p}function S(s,f,o){const u=o??new t(2);return u[0]=s[0]+f[0],u[1]=s[1]+f[1],u}function A(s,f,o,u){const p=u??new t(2);return p[0]=s[0]+f[0]*o,p[1]=s[1]+f[1]*o,p}function P(s,f){const o=s[0],u=s[1],p=f[0],_=f[1],D=Math.sqrt(o*o+u*u),h=Math.sqrt(p*p+_*_),w=D*h,b=w&&K(s,f)/w;return Math.acos(b)}function k(s,f,o){const u=o??new t(2);return u[0]=s[0]-f[0],u[1]=s[1]-f[1],u}const F=k;function z(s,f){return Math.abs(s[0]-f[0])1e-5?(o[0]=u/_,o[1]=p/_):(o[0]=0,o[1]=0),o}function ie(s,f){const o=f??new t(2);return o[0]=-s[0],o[1]=-s[1],o}function ft(s,f){const o=f??new t(2);return o[0]=s[0],o[1]=s[1],o}const oe=ft;function Lt(s,f,o){const u=o??new t(2);return u[0]=s[0]*f[0],u[1]=s[1]*f[1],u}const ae=Lt;function Gt(s,f,o){const u=o??new t(2);return u[0]=s[0]/f[0],u[1]=s[1]/f[1],u}const Qt=Gt;function Wt(s=1,f){const o=f??new t(2),u=Math.random()*2*Math.PI;return o[0]=Math.cos(u)*s,o[1]=Math.sin(u)*s,o}function c(s){const f=s??new t(2);return f[0]=0,f[1]=0,f}function x(s,f,o){const u=o??new t(2),p=s[0],_=s[1];return u[0]=p*f[0]+_*f[4]+f[12],u[1]=p*f[1]+_*f[5]+f[13],u}function a(s,f,o){const u=o??new t(2),p=s[0],_=s[1];return u[0]=f[0]*p+f[4]*_+f[8],u[1]=f[1]*p+f[5]*_+f[9],u}function l(s,f,o,u){const p=u??new t(2),_=s[0]-f[0],D=s[1]-f[1],h=Math.sin(o),w=Math.cos(o);return p[0]=_*w-D*h+f[0],p[1]=_*h+D*w+f[1],p}function y(s,f,o){const u=o??new t(2);return Ft(s,u),ut(u,f,u)}function v(s,f,o){const u=o??new t(2);return Y(s)>f?y(s,f,u):ft(s,u)}function T(s,f,o){const u=o??new t(2);return V(s,f,.5,u)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,angle:P,subtract:k,sub:F,equalsApproximately:z,equals:B,lerp:V,lerpV:L,max:tt,min:it,mulScalar:ut,scale:st,divScalar:xt,inverse:lt,invert:vt,cross:rt,dot:K,length:Y,len:ot,lengthSq:X,lenSq:nt,distance:H,dist:re,distanceSq:Pt,distSq:se,normalize:Ft,negate:ie,copy:ft,clone:oe,multiply:Lt,mul:ae,divide:Gt,div:Qt,random:Wt,zero:c,transformMat4:x,transformMat3:a,rotate:l,setLength:y,truncate:v,midpoint:T}}const cs=new Map;function bi(t){let e=cs.get(t);return e||(e=vu(t),cs.set(t,e)),e}function bu(t){function e(h,w,b){const $=new t(3);return h!==void 0&&($[0]=h,w!==void 0&&($[1]=w,b!==void 0&&($[2]=b))),$}const n=e;function r(h,w,b,$){const M=$??new t(3);return M[0]=h,M[1]=w,M[2]=b,M}function i(h,w){const b=w??new t(3);return b[0]=Math.ceil(h[0]),b[1]=Math.ceil(h[1]),b[2]=Math.ceil(h[2]),b}function d(h,w){const b=w??new t(3);return b[0]=Math.floor(h[0]),b[1]=Math.floor(h[1]),b[2]=Math.floor(h[2]),b}function m(h,w){const b=w??new t(3);return b[0]=Math.round(h[0]),b[1]=Math.round(h[1]),b[2]=Math.round(h[2]),b}function g(h,w=0,b=1,$){const M=$??new t(3);return M[0]=Math.min(b,Math.max(w,h[0])),M[1]=Math.min(b,Math.max(w,h[1])),M[2]=Math.min(b,Math.max(w,h[2])),M}function S(h,w,b){const $=b??new t(3);return $[0]=h[0]+w[0],$[1]=h[1]+w[1],$[2]=h[2]+w[2],$}function A(h,w,b,$){const M=$??new t(3);return M[0]=h[0]+w[0]*b,M[1]=h[1]+w[1]*b,M[2]=h[2]+w[2]*b,M}function P(h,w){const b=h[0],$=h[1],M=h[2],U=w[0],O=w[1],R=w[2],G=Math.sqrt(b*b+$*$+M*M),j=Math.sqrt(U*U+O*O+R*R),N=G*j,Z=N&&K(h,w)/N;return Math.acos(Z)}function k(h,w,b){const $=b??new t(3);return $[0]=h[0]-w[0],$[1]=h[1]-w[1],$[2]=h[2]-w[2],$}const F=k;function z(h,w){return Math.abs(h[0]-w[0])1e-5?(b[0]=$/O,b[1]=M/O,b[2]=U/O):(b[0]=0,b[1]=0,b[2]=0),b}function ie(h,w){const b=w??new t(3);return b[0]=-h[0],b[1]=-h[1],b[2]=-h[2],b}function ft(h,w){const b=w??new t(3);return b[0]=h[0],b[1]=h[1],b[2]=h[2],b}const oe=ft;function Lt(h,w,b){const $=b??new t(3);return $[0]=h[0]*w[0],$[1]=h[1]*w[1],$[2]=h[2]*w[2],$}const ae=Lt;function Gt(h,w,b){const $=b??new t(3);return $[0]=h[0]/w[0],$[1]=h[1]/w[1],$[2]=h[2]/w[2],$}const Qt=Gt;function Wt(h=1,w){const b=w??new t(3),$=Math.random()*2*Math.PI,M=Math.random()*2-1,U=Math.sqrt(1-M*M)*h;return b[0]=Math.cos($)*U,b[1]=Math.sin($)*U,b[2]=M*h,b}function c(h){const w=h??new t(3);return w[0]=0,w[1]=0,w[2]=0,w}function x(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2],R=w[3]*M+w[7]*U+w[11]*O+w[15]||1;return $[0]=(w[0]*M+w[4]*U+w[8]*O+w[12])/R,$[1]=(w[1]*M+w[5]*U+w[9]*O+w[13])/R,$[2]=(w[2]*M+w[6]*U+w[10]*O+w[14])/R,$}function a(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2];return $[0]=M*w[0*4+0]+U*w[1*4+0]+O*w[2*4+0],$[1]=M*w[0*4+1]+U*w[1*4+1]+O*w[2*4+1],$[2]=M*w[0*4+2]+U*w[1*4+2]+O*w[2*4+2],$}function l(h,w,b){const $=b??new t(3),M=h[0],U=h[1],O=h[2];return $[0]=M*w[0]+U*w[4]+O*w[8],$[1]=M*w[1]+U*w[5]+O*w[9],$[2]=M*w[2]+U*w[6]+O*w[10],$}function y(h,w,b){const $=b??new t(3),M=w[0],U=w[1],O=w[2],R=w[3]*2,G=h[0],j=h[1],N=h[2],Z=U*N-O*j,J=O*G-M*N,dt=M*j-U*G;return $[0]=G+Z*R+(U*dt-O*J)*2,$[1]=j+J*R+(O*Z-M*dt)*2,$[2]=N+dt*R+(M*J-U*Z)*2,$}function v(h,w){const b=w??new t(3);return b[0]=h[12],b[1]=h[13],b[2]=h[14],b}function T(h,w,b){const $=b??new t(3),M=w*4;return $[0]=h[M+0],$[1]=h[M+1],$[2]=h[M+2],$}function s(h,w){const b=w??new t(3),$=h[0],M=h[1],U=h[2],O=h[4],R=h[5],G=h[6],j=h[8],N=h[9],Z=h[10];return b[0]=Math.sqrt($*$+M*M+U*U),b[1]=Math.sqrt(O*O+R*R+G*G),b[2]=Math.sqrt(j*j+N*N+Z*Z),b}function f(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[0],O[1]=U[1]*Math.cos(b)-U[2]*Math.sin(b),O[2]=U[1]*Math.sin(b)+U[2]*Math.cos(b),M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function o(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[2]*Math.sin(b)+U[0]*Math.cos(b),O[1]=U[1],O[2]=U[2]*Math.cos(b)-U[0]*Math.sin(b),M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function u(h,w,b,$){const M=$??new t(3),U=[],O=[];return U[0]=h[0]-w[0],U[1]=h[1]-w[1],U[2]=h[2]-w[2],O[0]=U[0]*Math.cos(b)-U[1]*Math.sin(b),O[1]=U[0]*Math.sin(b)+U[1]*Math.cos(b),O[2]=U[2],M[0]=O[0]+w[0],M[1]=O[1]+w[1],M[2]=O[2]+w[2],M}function p(h,w,b){const $=b??new t(3);return Ft(h,$),ut($,w,$)}function _(h,w,b){const $=b??new t(3);return Y(h)>w?p(h,w,$):ft(h,$)}function D(h,w,b){const $=b??new t(3);return V(h,w,.5,$)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,angle:P,subtract:k,sub:F,equalsApproximately:z,equals:B,lerp:V,lerpV:L,max:tt,min:it,mulScalar:ut,scale:st,divScalar:xt,inverse:lt,invert:vt,cross:rt,dot:K,length:Y,len:ot,lengthSq:X,lenSq:nt,distance:H,dist:re,distanceSq:Pt,distSq:se,normalize:Ft,negate:ie,copy:ft,clone:oe,multiply:Lt,mul:ae,divide:Gt,div:Qt,random:Wt,zero:c,transformMat4:x,transformMat4Upper3x3:a,transformMat3:l,transformQuat:y,getTranslation:v,getAxis:T,getScaling:s,rotateX:f,rotateY:o,rotateZ:u,setLength:p,truncate:_,midpoint:D}}const ls=new Map;function nr(t){let e=ls.get(t);return e||(e=bu(t),ls.set(t,e)),e}function _u(t){const e=bi(t),n=nr(t);function r(c,x,a,l,y,v,T,s,f){const o=new t(12);return o[3]=0,o[7]=0,o[11]=0,c!==void 0&&(o[0]=c,x!==void 0&&(o[1]=x,a!==void 0&&(o[2]=a,l!==void 0&&(o[4]=l,y!==void 0&&(o[5]=y,v!==void 0&&(o[6]=v,T!==void 0&&(o[8]=T,s!==void 0&&(o[9]=s,f!==void 0&&(o[10]=f))))))))),o}function i(c,x,a,l,y,v,T,s,f,o){const u=o??new t(12);return u[0]=c,u[1]=x,u[2]=a,u[3]=0,u[4]=l,u[5]=y,u[6]=v,u[7]=0,u[8]=T,u[9]=s,u[10]=f,u[11]=0,u}function d(c,x){const a=x??new t(12);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=0,a[4]=c[4],a[5]=c[5],a[6]=c[6],a[7]=0,a[8]=c[8],a[9]=c[9],a[10]=c[10],a[11]=0,a}function m(c,x){const a=x??new t(12),l=c[0],y=c[1],v=c[2],T=c[3],s=l+l,f=y+y,o=v+v,u=l*s,p=y*s,_=y*f,D=v*s,h=v*f,w=v*o,b=T*s,$=T*f,M=T*o;return a[0]=1-_-w,a[1]=p+M,a[2]=D-$,a[3]=0,a[4]=p-M,a[5]=1-u-w,a[6]=h+b,a[7]=0,a[8]=D+$,a[9]=h-b,a[10]=1-u-_,a[11]=0,a}function g(c,x){const a=x??new t(12);return a[0]=-c[0],a[1]=-c[1],a[2]=-c[2],a[4]=-c[4],a[5]=-c[5],a[6]=-c[6],a[8]=-c[8],a[9]=-c[9],a[10]=-c[10],a}function S(c,x){const a=x??new t(12);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[4]=c[4],a[5]=c[5],a[6]=c[6],a[8]=c[8],a[9]=c[9],a[10]=c[10],a}const A=S;function P(c,x){return Math.abs(c[0]-x[0])C?(a[0]=c[0]/y,a[1]=c[1]/y,a[2]=c[2]/y):(a[0]=1,a[1]=0,a[2]=0),{angle:l,axis:a}}function g(c,x){const a=Y(c,x);return Math.acos(2*a*a-1)}function S(c,x,a){const l=a??new t(4),y=c[0],v=c[1],T=c[2],s=c[3],f=x[0],o=x[1],u=x[2],p=x[3];return l[0]=y*p+s*f+v*u-T*o,l[1]=v*p+s*o+T*f-y*u,l[2]=T*p+s*u+y*o-v*f,l[3]=s*p-y*f-v*o-T*u,l}const A=S;function P(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u+f*o,l[1]=T*u+s*o,l[2]=s*u-T*o,l[3]=f*u-v*o,l}function k(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u-s*o,l[1]=T*u+f*o,l[2]=s*u+v*o,l[3]=f*u-T*o,l}function F(c,x,a){const l=a??new t(4),y=x*.5,v=c[0],T=c[1],s=c[2],f=c[3],o=Math.sin(y),u=Math.cos(y);return l[0]=v*u+T*o,l[1]=T*u-v*o,l[2]=s*u+f*o,l[3]=f*u-s*o,l}function z(c,x,a,l){const y=l??new t(4),v=c[0],T=c[1],s=c[2],f=c[3];let o=x[0],u=x[1],p=x[2],_=x[3],D=v*o+T*u+s*p+f*_;D<0&&(D=-D,o=-o,u=-u,p=-p,_=-_);let h,w;if(1-D>C){const b=Math.acos(D),$=Math.sin(b);h=Math.sin((1-a)*b)/$,w=Math.sin(a*b)/$}else h=1-a,w=a;return y[0]=h*v+w*o,y[1]=h*T+w*u,y[2]=h*s+w*p,y[3]=h*f+w*_,y}function B(c,x){const a=x??new t(4),l=c[0],y=c[1],v=c[2],T=c[3],s=l*l+y*y+v*v+T*T,f=s?1/s:0;return a[0]=-l*f,a[1]=-y*f,a[2]=-v*f,a[3]=T*f,a}function V(c,x){const a=x??new t(4);return a[0]=-c[0],a[1]=-c[1],a[2]=-c[2],a[3]=c[3],a}function L(c,x){const a=x??new t(4),l=c[0]+c[5]+c[10];if(l>0){const y=Math.sqrt(l+1);a[3]=.5*y;const v=.5/y;a[0]=(c[6]-c[9])*v,a[1]=(c[8]-c[2])*v,a[2]=(c[1]-c[4])*v}else{let y=0;c[5]>c[0]&&(y=1),c[10]>c[y*4+y]&&(y=2);const v=(y+1)%3,T=(y+2)%3,s=Math.sqrt(c[y*4+y]-c[v*4+v]-c[T*4+T]+1);a[y]=.5*s;const f=.5/s;a[3]=(c[v*4+T]-c[T*4+v])*f,a[v]=(c[v*4+y]+c[y*4+v])*f,a[T]=(c[T*4+y]+c[y*4+T])*f}return a}function tt(c,x,a,l,y){const v=y??new t(4),T=c*.5,s=x*.5,f=a*.5,o=Math.sin(T),u=Math.cos(T),p=Math.sin(s),_=Math.cos(s),D=Math.sin(f),h=Math.cos(f);switch(l){case"xyz":v[0]=o*_*h+u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h-o*p*D;break;case"xzy":v[0]=o*_*h-u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h+o*p*D;break;case"yxz":v[0]=o*_*h+u*p*D,v[1]=u*p*h-o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h+o*p*D;break;case"yzx":v[0]=o*_*h+u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h-o*p*D;break;case"zxy":v[0]=o*_*h-u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D+o*p*h,v[3]=u*_*h-o*p*D;break;case"zyx":v[0]=o*_*h-u*p*D,v[1]=u*p*h+o*_*D,v[2]=u*_*D-o*p*h,v[3]=u*_*h+o*p*D;break;default:throw new Error(`Unknown rotation order: ${l}`)}return v}function it(c,x){const a=x??new t(4);return a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a}const ut=it;function st(c,x,a){const l=a??new t(4);return l[0]=c[0]+x[0],l[1]=c[1]+x[1],l[2]=c[2]+x[2],l[3]=c[3]+x[3],l}function xt(c,x,a){const l=a??new t(4);return l[0]=c[0]-x[0],l[1]=c[1]-x[1],l[2]=c[2]-x[2],l[3]=c[3]-x[3],l}const lt=xt;function vt(c,x,a){const l=a??new t(4);return l[0]=c[0]*x,l[1]=c[1]*x,l[2]=c[2]*x,l[3]=c[3]*x,l}const rt=vt;function K(c,x,a){const l=a??new t(4);return l[0]=c[0]/x,l[1]=c[1]/x,l[2]=c[2]/x,l[3]=c[3]/x,l}function Y(c,x){return c[0]*x[0]+c[1]*x[1]+c[2]*x[2]+c[3]*x[3]}function ot(c,x,a,l){const y=l??new t(4);return y[0]=c[0]+a*(x[0]-c[0]),y[1]=c[1]+a*(x[1]-c[1]),y[2]=c[2]+a*(x[2]-c[2]),y[3]=c[3]+a*(x[3]-c[3]),y}function X(c){const x=c[0],a=c[1],l=c[2],y=c[3];return Math.sqrt(x*x+a*a+l*l+y*y)}const nt=X;function H(c){const x=c[0],a=c[1],l=c[2],y=c[3];return x*x+a*a+l*l+y*y}const re=H;function Pt(c,x){const a=x??new t(4),l=c[0],y=c[1],v=c[2],T=c[3],s=Math.sqrt(l*l+y*y+v*v+T*T);return s>1e-5?(a[0]=l/s,a[1]=y/s,a[2]=v/s,a[3]=T/s):(a[0]=0,a[1]=0,a[2]=0,a[3]=1),a}function se(c,x){return Math.abs(c[0]-x[0]).999999?(l[0]=0,l[1]=0,l[2]=0,l[3]=1,l):(e.cross(c,x,ft),l[0]=ft[0],l[1]=ft[1],l[2]=ft[2],l[3]=1+y,Pt(l,l))}const Gt=new t(4),Qt=new t(4);function Wt(c,x,a,l,y,v){const T=v??new t(4);return z(c,l,y,Gt),z(x,a,y,Qt),z(Gt,Qt,2*y*(1-y),T),T}return{create:n,fromValues:r,set:i,fromAxisAngle:d,toAxisAngle:m,angle:g,multiply:S,mul:A,rotateX:P,rotateY:k,rotateZ:F,slerp:z,inverse:B,conjugate:V,fromMat:L,fromEuler:tt,copy:it,clone:ut,add:st,subtract:xt,sub:lt,mulScalar:vt,scale:rt,divScalar:K,dot:Y,lerp:ot,length:X,len:nt,lengthSq:H,lenSq:re,normalize:Pt,equalsApproximately:se,equals:Ft,identity:ie,rotationTo:ae,sqlerp:Wt}}const ds=new Map;function Du(t){let e=ds.get(t);return e||(e=Tu(t),ds.set(t,e)),e}function Uu(t){function e(a,l,y,v){const T=new t(4);return a!==void 0&&(T[0]=a,l!==void 0&&(T[1]=l,y!==void 0&&(T[2]=y,v!==void 0&&(T[3]=v)))),T}const n=e;function r(a,l,y,v,T){const s=T??new t(4);return s[0]=a,s[1]=l,s[2]=y,s[3]=v,s}function i(a,l){const y=l??new t(4);return y[0]=Math.ceil(a[0]),y[1]=Math.ceil(a[1]),y[2]=Math.ceil(a[2]),y[3]=Math.ceil(a[3]),y}function d(a,l){const y=l??new t(4);return y[0]=Math.floor(a[0]),y[1]=Math.floor(a[1]),y[2]=Math.floor(a[2]),y[3]=Math.floor(a[3]),y}function m(a,l){const y=l??new t(4);return y[0]=Math.round(a[0]),y[1]=Math.round(a[1]),y[2]=Math.round(a[2]),y[3]=Math.round(a[3]),y}function g(a,l=0,y=1,v){const T=v??new t(4);return T[0]=Math.min(y,Math.max(l,a[0])),T[1]=Math.min(y,Math.max(l,a[1])),T[2]=Math.min(y,Math.max(l,a[2])),T[3]=Math.min(y,Math.max(l,a[3])),T}function S(a,l,y){const v=y??new t(4);return v[0]=a[0]+l[0],v[1]=a[1]+l[1],v[2]=a[2]+l[2],v[3]=a[3]+l[3],v}function A(a,l,y,v){const T=v??new t(4);return T[0]=a[0]+l[0]*y,T[1]=a[1]+l[1]*y,T[2]=a[2]+l[2]*y,T[3]=a[3]+l[3]*y,T}function P(a,l,y){const v=y??new t(4);return v[0]=a[0]-l[0],v[1]=a[1]-l[1],v[2]=a[2]-l[2],v[3]=a[3]-l[3],v}const k=P;function F(a,l){return Math.abs(a[0]-l[0])1e-5?(y[0]=v/o,y[1]=T/o,y[2]=s/o,y[3]=f/o):(y[0]=0,y[1]=0,y[2]=0,y[3]=0),y}function se(a,l){const y=l??new t(4);return y[0]=-a[0],y[1]=-a[1],y[2]=-a[2],y[3]=-a[3],y}function Ft(a,l){const y=l??new t(4);return y[0]=a[0],y[1]=a[1],y[2]=a[2],y[3]=a[3],y}const ie=Ft;function ft(a,l,y){const v=y??new t(4);return v[0]=a[0]*l[0],v[1]=a[1]*l[1],v[2]=a[2]*l[2],v[3]=a[3]*l[3],v}const oe=ft;function Lt(a,l,y){const v=y??new t(4);return v[0]=a[0]/l[0],v[1]=a[1]/l[1],v[2]=a[2]/l[2],v[3]=a[3]/l[3],v}const ae=Lt;function Gt(a){const l=a??new t(4);return l[0]=0,l[1]=0,l[2]=0,l[3]=0,l}function Qt(a,l,y){const v=y??new t(4),T=a[0],s=a[1],f=a[2],o=a[3];return v[0]=l[0]*T+l[4]*s+l[8]*f+l[12]*o,v[1]=l[1]*T+l[5]*s+l[9]*f+l[13]*o,v[2]=l[2]*T+l[6]*s+l[10]*f+l[14]*o,v[3]=l[3]*T+l[7]*s+l[11]*f+l[15]*o,v}function Wt(a,l,y){const v=y??new t(4);return Pt(a,v),it(v,l,v)}function c(a,l,y){const v=y??new t(4);return rt(a)>l?Wt(a,l,v):Ft(a,v)}function x(a,l,y){const v=y??new t(4);return B(a,l,.5,v)}return{create:e,fromValues:n,set:r,ceil:i,floor:d,round:m,clamp:g,add:S,addScaled:A,subtract:P,sub:k,equalsApproximately:F,equals:z,lerp:B,lerpV:V,max:L,min:tt,mulScalar:it,scale:ut,divScalar:st,inverse:xt,invert:lt,dot:vt,length:rt,len:K,lengthSq:Y,lenSq:ot,distance:X,dist:nt,distanceSq:H,distSq:re,normalize:Pt,negate:se,copy:Ft,clone:ie,multiply:ft,mul:oe,divide:Lt,div:ae,zero:Gt,transformMat4:Qt,setLength:Wt,truncate:c,midpoint:x}}const ps=new Map;function Ou(t){let e=ps.get(t);return e||(e=Uu(t),ps.set(t,e)),e}function Rr(t,e,n,r,i,d){return{mat3:$u(t),mat4:Mu(e),quat:Du(n),vec2:bi(r),vec3:nr(i),vec4:Ou(d)}}const{mat3:Eu,mat4:Au,quat:ef,vec2:ct,vec3:ku,vec4:nf}=Rr(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array);Rr(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array);Rr(xu,Array,Array,Array,Array,Array);function _i(){return new Promise(t=>requestAnimationFrame(t))}function gr({x:t,y:e}){return q(-e,t)}function Iu(t,e,n,r,i){return q(t.x+e.x*n+r.x*i,t.y+e.y*n+r.y*i)}const[ce,$i]=mu([]);qt(!1);const{sign:Si,sqrt:xr,abs:ws,min:Pu,max:Fu}=Math;function zu(t){const n=we(ce).findIndex(r=>ct.distance(r.center,t){r.push({center:t,radius:0})})),ce.length-1):n}function Bu(t){const e=we(ce);let n=Number.POSITIVE_INFINITY,r;const{center:i}=e[t];for(let m=0;mi}}function ju(t,e,n){const r=ct.sub(e.center,t.center,q()),i=e.radius-t.radius,d=ct.dot(r,r),m=ct.dot(n,r);return(d-i*i)/(2*(m+i*ct.length(n)))-t.radius}function Ru(t,e){const n=we(ce),r=n[t],i=n[e],d=ct.normalize(ct.sub(i.center,r.center,q()),q());let m=Number.POSITIVE_INFINITY,g;for(let A=0;A=-r.radius/2&&kct.addScaled(r.center,d,r.radius+A,q())}}function Nu(t,e,n,r){t.radiusws(ct.distance([ot,-X],[z,B])-m-nt)?Number.POSITIVE_INFINITY:nt}function Vu(t,e,n,r){t.radius>e.radius&&([t,e]=[e,t]);const i=ct.sub(e.center,t.center,q()),d=ct.length(i),m=t.radius,g=e.radius,S=n,A=(m*m-g*g+2*(m-g)*S+d*d)/(2*d),P=(m+S)**2-A*A;if(P<0)return;const k=ct.scale(i,1/d,q()),F=gr(k),z=xr(P),B=Si(ct.dot(gr(i),ct.sub(r.center,t.center,q())));return Iu(t.center,k,A,F,z*B)}function Lu(t,e,n){const r=we(ce),i=r[n],d=r[t],m=r[e];let g=Number.POSITIVE_INFINITY,S;for(let P=0;PVu(d,m,P,i)}}async function ur(t,e,n,r,i){const d=ce[t];for(;;){if(await Promise.race([_i(),i])instanceof PointerEvent)return;const g=Pu(e,d.radius*1.025+.004/r()),S=n(g);if(!S||($i(t,vi(A=>{A.radius=g,A.center=S})),g===e))return}}const Mi=Ur(),Gu=Mi.Provider;function rr(){return Ar(Mi,"useCanvas","CanvasContext")}function qu(){let t,e;return{promise:new Promise((r,i)=>{t=r,e=i}),resolve:t,reject:e}}var Nr=class{constructor(){E(this,"lastUniqueId",0)}makeUnique(e){let n;return e?(n=e.replaceAll(/\s/g,"_"),n=n.replaceAll(/[^\w\d]/g,"")):n="item",`${n}_${this.lastUniqueId++}`}},Vr=class{constructor(){E(this,"_usedNames",new Set)}makeUnique(e){if(e===void 0)throw new Error("Unnamed item found when using a strict name registry");let n=0,r=e;for(;this._usedNames.has(r);)n++,r=`${e}_${n}`;return this._usedNames.add(r),r}};function vr(t){return t?.resourceType==="slot"}function br(t){return t?.resourceType==="derived"}function _r(t){return t?.["~providing"]!==void 0}function Lr(t){return t?.resourceType==="accessor"}function Wu(t,e){let n="size"in t?t.size:t.currentByteOffset,r=e-1,i=n&r;"skipBytes"in t?t.skipBytes(e-i&r):t.add(e-i&r)}var $t=Wu,le={bool(t,e,n){t.writeBool(n)},f32(t,e,n){t.writeFloat32(n)},f16(t,e,n){t.writeFloat16(n)},i32(t,e,n){t.writeInt32(n)},u32(t,e,n){t.writeUint32(n)},vec2f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y)},vec2h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y)},vec2i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y)},vec2u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y)},vec3f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y),t.writeFloat32(n.z)},vec3h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y),t.writeFloat16(n.z)},vec3i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)},vec3u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y),t.writeUint32(n.z)},vec4f(t,e,n){t.writeFloat32(n.x),t.writeFloat32(n.y),t.writeFloat32(n.z),t.writeFloat32(n.w)},vec4h(t,e,n){t.writeFloat16(n.x),t.writeFloat16(n.y),t.writeFloat16(n.z),t.writeFloat16(n.w)},vec4i(t,e,n){t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)},vec4u(t,e,n){t.writeUint32(n.x),t.writeUint32(n.y),t.writeUint32(n.z),t.writeUint32(n.w)},mat2x2f(t,e,n){for(let r=0;r{let n=t.readFloat32();return t.readFloat32(),n};return en(t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e())},mat4x4f(t){return fi(t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},struct(t,e){let n=St(e);$t(t,n);let r={};for(let[i,d]of Object.entries(e.propTypes))$t(t,St(d)),r[i]=fe(t,d);return $t(t,n),r},array(t,e){if(e.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let n=St(e),r=[];for(let i=0;it.readUint8(),uint8x2:t=>Oe(t.readUint8(),t.readUint8()),uint8x4:t=>ee(t.readUint8(),t.readUint8(),t.readUint8(),t.readUint8()),sint8:t=>t.readInt8(),sint8x2:t=>Ue(t.readInt8(),t.readInt8()),sint8x4:t=>te(t.readInt8(),t.readInt8(),t.readInt8(),t.readInt8()),unorm8:t=>t.readUint8()/255,unorm8x2:t=>q(t.readUint8()/255,t.readUint8()/255),unorm8x4:t=>et(t.readUint8()/255,t.readUint8()/255,t.readUint8()/255,t.readUint8()/255),snorm8:t=>(t.readUint8()-128)/127,snorm8x2:t=>q((t.readUint8()-128)/127,(t.readUint8()-128)/127),snorm8x4:t=>et((t.readUint8()-128)/127,(t.readUint8()-128)/127,(t.readUint8()-128)/127,(t.readUint8()-128)/127),uint16:t=>t.readUint16(),uint16x2:t=>Oe(t.readUint16(),t.readUint16()),uint16x4:t=>ee(t.readUint16(),t.readUint16(),t.readUint16(),t.readUint16()),sint16:t=>t.readInt16(),sint16x2:t=>Ue(t.readInt16(),t.readInt16()),sint16x4:t=>te(t.readInt16(),t.readInt16(),t.readInt16(),t.readInt16()),unorm16:t=>t.readUint16()/65535,unorm16x2:t=>q(t.readUint16()/65535,t.readUint16()/65535),unorm16x4:t=>et(t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535),snorm16:t=>(t.readUint16()-32768)/32767,snorm16x2:t=>q(Te.snorm16(t),Te.snorm16(t)),snorm16x4:t=>et(Te.snorm16(t),Te.snorm16(t),Te.snorm16(t),Te.snorm16(t)),float16(t){return t.readFloat16()},float16x2:t=>q(t.readFloat16(),t.readFloat16()),float16x4:t=>et(t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16()),float32:t=>t.readFloat32(),float32x2:t=>q(t.readFloat32(),t.readFloat32()),float32x3:t=>tn(t.readFloat32(),t.readFloat32(),t.readFloat32()),float32x4:t=>et(t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()),uint32:t=>t.readUint32(),uint32x2:t=>Oe(t.readUint32(),t.readUint32()),uint32x3:t=>Ee(t.readUint32(),t.readUint32(),t.readUint32()),uint32x4:t=>ee(t.readUint32(),t.readUint32(),t.readUint32(),t.readUint32()),sint32:t=>t.readInt32(),sint32x2:t=>Ue(t.readInt32(),t.readInt32()),sint32x3:t=>yr(t.readInt32(),t.readInt32(),t.readInt32()),sint32x4:t=>te(t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32()),"unorm10-10-10-2"(t){let e=t.readUint32(),n=(e>>22)/1023,r=(e>>12&1023)/1023,i=(e>>2&1023)/1023,d=(e&3)/3;return et(n,r,i,d)},"unorm8x4-bgra"(t){let e=t.readByte()/255,n=t.readByte()/255,r=t.readByte()/255,i=t.readByte()/255;return et(r,n,e,i)},unstruct(t,e){let n={};for(let[r,i]of Object.entries(e.propTypes))n[r]=fe(t,i);return n},disarray(t,e){let n=St(e),r=[];for(let i=0;i"}),this.initial)){let r=new vn(this._buffer.getMappedRange());Ke(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(e){return this._label=e,this._buffer&&(this._buffer.label=e),this}$usage(...e){var n;for(let r of e){if((n=this._disallowedUsages)!=null&&n.includes(r))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${r}`);this.flags|=r==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=r==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=r==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||r==="uniform",this.usableAsStorage=this.usableAsStorage||r==="storage",this.usableAsVertex=this.usableAsVertex||r==="vertex"}return this}$addFlags(e){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return e&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):e&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=e,this)}write(e){let n=this.buffer,r=this._group.device;if(n.mapState==="mapped"){let m=n.getMappedRange();Ke(new vn(m),this.dataType,e);return}let i=wt(this.dataType);this._group.flush();let d=new ArrayBuffer(i);Ke(new vn(d),this.dataType,e),r.queue.writeBuffer(n,0,d,0,i)}copyFrom(e){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let n=wt(this.dataType);this._group.commandEncoder.copyBufferToBuffer(e.buffer,0,this.buffer,0,n)}async read(){this._group.flush();let e=this.buffer,n=this._group.device;if(e.mapState==="mapped"){let m=e.getMappedRange();return fe(new xn(m),this.dataType)}if(e.usage&GPUBufferUsage.MAP_READ){await e.mapAsync(GPUMapMode.READ);let m=e.getMappedRange(),g=fe(new xn(m),this.dataType);return e.unmap(),g}let r=n.createBuffer({size:wt(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),i=n.createCommandEncoder();i.copyBufferToBuffer(e,0,r,0,wt(this.dataType)),n.queue.submit([i.finish()]),await n.queue.onSubmittedWorkDone(),await r.mapAsync(GPUMapMode.READ,0,wt(this.dataType));let d=fe(new xn(r.getMappedRange()),this.dataType);return r.unmap(),r.destroy(),d}destroy(){var e;this._destroyed||(this._destroyed=!0,this._ownBuffer&&((e=this._buffer)==null||e.destroy()))}toString(){var e;return`buffer:${(e=this._label)!=null?e:""}`}};function ms(t){return!!(t!=null&&t.usableAsStorage)}var Zu=class Di extends Error{constructor(e){var n;super(`Resource '${(n=e.label)!=null?n:""}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,Di.prototype)}};function Hu(t){return t?.resourceType==="buffer-usage"}var Ku={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},gs=class{constructor(e,n,r){this.usage=e,this.dataType=n,this._membership=r,E(this,"~repr"),E(this,"resourceType","buffer-usage")}get label(){return this._membership.key}"~resolve"(e){let n=e.names.makeUnique(this.label),r=e.allocateLayoutEntry(this._membership.layout),i=Ku[this.usage];return e.addDeclaration(`@group(${r}) @binding(${this._membership.idx}) var<${i}> ${n}: ${e.resolve(this.dataType)};`),n}toString(){var e;return`${this.usage}:${(e=this.label)!=null?e:""}`}get value(){if(!ye())throw new Error("Cannot access buffer's value directly in JS.");return this}},Qu=class{constructor(t){this._membership=t,E(this,"resourceType","sampler")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: sampler;`),e}},Ju=class{constructor(t){this._membership=t,E(this,"resourceType","sampler-comparison")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: sampler_comparison;`),e}},tc={r8unorm:I,r8snorm:I,r8uint:mt,r8sint:Zt,r16uint:mt,r16sint:Zt,r16float:I,rg8unorm:I,rg8snorm:I,rg8uint:mt,rg8sint:Zt,r32uint:mt,r32sint:Zt,r32float:I,rg16uint:mt,rg16sint:Zt,rg16float:I,rgba8unorm:I,"rgba8unorm-srgb":I,rgba8snorm:I,rgba8uint:mt,rgba8sint:Zt,bgra8unorm:I,"bgra8unorm-srgb":I,rgb9e5ufloat:I,rgb10a2uint:mt,rgb10a2unorm:I,rg11b10ufloat:I,rg32uint:mt,rg32sint:Zt,rg32float:I,rgba16uint:mt,rgba16sint:Zt,rgba16float:I,rgba32uint:mt,rgba32sint:Zt,rgba32float:I,stencil8:I,depth16unorm:I,depth24plus:I,"depth24plus-stencil8":I,depth32float:I,"depth32float-stencil8":I,"bc1-rgba-unorm":I,"bc1-rgba-unorm-srgb":I,"bc2-rgba-unorm":I,"bc2-rgba-unorm-srgb":I,"bc3-rgba-unorm":I,"bc3-rgba-unorm-srgb":I,"bc4-r-unorm":I,"bc4-r-snorm":I,"bc5-rg-unorm":I,"bc5-rg-snorm":I,"bc6h-rgb-ufloat":I,"bc6h-rgb-float":I,"bc7-rgba-unorm":I,"bc7-rgba-unorm-srgb":I,"etc2-rgb8unorm":I,"etc2-rgb8unorm-srgb":I,"etc2-rgb8a1unorm":I,"etc2-rgb8a1unorm-srgb":I,"etc2-rgba8unorm":I,"etc2-rgba8unorm-srgb":I,"eac-r11unorm":I,"eac-r11snorm":I,"eac-rg11unorm":I,"eac-rg11snorm":I,"astc-4x4-unorm":I,"astc-4x4-unorm-srgb":I,"astc-5x4-unorm":I,"astc-5x4-unorm-srgb":I,"astc-5x5-unorm":I,"astc-5x5-unorm-srgb":I,"astc-6x5-unorm":I,"astc-6x5-unorm-srgb":I,"astc-6x6-unorm":I,"astc-6x6-unorm-srgb":I,"astc-8x5-unorm":I,"astc-8x5-unorm-srgb":I,"astc-8x6-unorm":I,"astc-8x6-unorm-srgb":I,"astc-8x8-unorm":I,"astc-8x8-unorm-srgb":I,"astc-10x5-unorm":I,"astc-10x5-unorm-srgb":I,"astc-10x6-unorm":I,"astc-10x6-unorm-srgb":I,"astc-10x8-unorm":I,"astc-10x8-unorm-srgb":I,"astc-10x10-unorm":I,"astc-10x10-unorm-srgb":I,"astc-12x10-unorm":I,"astc-12x10-unorm-srgb":I,"astc-12x12-unorm":I,"astc-12x12-unorm-srgb":I},Wn={rgba8unorm:et,rgba8snorm:et,rgba8uint:ee,rgba8sint:te,rgba16uint:ee,rgba16sint:te,rgba16float:et,r32uint:ee,r32sint:te,r32float:et,rg32uint:ee,rg32sint:te,rg32float:et,rgba32uint:ee,rgba32sint:te,rgba32float:et,bgra8unorm:et},ec={f32:"float",u32:"uint",i32:"sint"},nc={float:I,"unfilterable-float":I,uint:mt,sint:Zt,depth:I};function rc(t,e){return new oc(t,e)}function rn(t){return t?.resourceType==="texture"}function sc(t){return t?.resourceType==="texture-storage-view"}function ic(t){return t?.resourceType==="texture-sampled-view"}var Ui={mutable:"read_write",readonly:"read",writeonly:"write"},oc=class{constructor(t,e){this.props=t,this._branch=e,E(this,"resourceType","texture"),E(this,"usableAsSampled",!1),E(this,"usableAsStorage",!1),E(this,"usableAsRender",!1),E(this,"_destroyed",!1),E(this,"_label"),E(this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC),E(this,"_texture",null)}get label(){return this._label}$name(t){return this._label=t,this}unwrap(){var t,e,n,r,i;if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:(t=this._label)!=null?t:"",format:this.props.format,size:this.props.size,usage:this._flags,dimension:(e=this.props.dimension)!=null?e:"2d",viewFormats:(n=this.props.viewFormats)!=null?n:[],mipLevelCount:(r=this.props.mipLevelCount)!=null?r:1,sampleCount:(i=this.props.sampleCount)!=null?i:1})),this._texture}$usage(...t){let e=t.includes("storage"),n=t.includes("sampled"),r=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=e?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=r?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||(this.usableAsStorage=e),this.usableAsSampled||(this.usableAsSampled=n),this.usableAsRender||(this.usableAsRender=r),this}createView(t,e){if(t==="sampled")return this._asSampled(e);let n=e;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,e){var n;if(!this.usableAsStorage)throw new Error("Unusable as storage");let r=(n=t?.format)!=null?n:this.props.format,i=Wn[r];return On(!!i),new ac(t??{},e,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){var e;if(!this.usableAsSampled)throw new Error("Unusable as sampled");let n=(e=t?.format)!=null?e:this.props.format;if(!Wn[n])throw new Error(`Unsupported storage texture format: ${n}`);return new cc(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},sr={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},ac=class{constructor(t,e,n){this.access=e,this._texture=n,E(this,"resourceType","texture-storage-view"),E(this,"texelDataType"),E(this,"dimension"),E(this,"_view"),E(this,"_format");var r,i,d;this.dimension=(i=(r=t?.dimension)!=null?r:n.props.dimension)!=null?i:"2d",this._format=(d=t?.format)!=null?d:n.props.format,this.texelDataType=Wn[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView({label:`${(t=this.label)!=null?t:""} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let e=t.names.makeUnique(this.label),{group:n,binding:r}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),i=`texture_storage_${sr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${r}) var ${e}: ${i}<${this._format}, ${Ui[this.access]}>;`),e}},uc=class{constructor(t,e,n,r){this._format=t,this.dimension=e,this.access=n,this._membership=r,E(this,"resourceType","texture-storage-view"),E(this,"texelDataType"),this.texelDataType=Wn[this._format]}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),r=`texture_storage_${sr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: ${r}<${this._format}, ${Ui[this.access]}>;`),e}},cc=class{constructor(e,n){this._props=e,this._texture=n,E(this,"resourceType","texture-sampled-view"),E(this,"channelDataType"),E(this,"dimension"),E(this,"_format"),E(this,"_view");var r,i,d;this.dimension=(i=(r=e?.dimension)!=null?r:n.props.dimension)!=null?i:"2d",this._format=(d=e?.format)!=null?d:n.props.format,this.channelDataType=tc[this._format]}get label(){return this._texture.label}$name(e){return this._texture.$name(e),this}unwrap(){var e;return this._view||(this._view=this._texture.unwrap().createView(he({label:`${(e=this.label)!=null?e:""} - View`},this._props))),this._view}"~resolve"(e){var n;let r=e.names.makeUnique(this.label),i=((n=this._texture.props.sampleCount)!=null?n:1)>1,{group:d,binding:m}=e.allocateFixedEntry({texture:ec[this.channelDataType.type],viewDimension:this.dimension,multisampled:i},this),g=i?"texture_multisampled_2d":`texture_${sr[this.dimension]}`;return e.addDeclaration(`@group(${d}) @binding(${m}) var ${r}: ${g}<${e.resolve(this.channelDataType)}>;`),r}},lc=class{constructor(t,e,n,r){this.dimension=e,this._multisampled=n,this._membership=r,E(this,"resourceType","texture-sampled-view"),E(this,"channelDataType"),this.channelDataType=nc[t]}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),r=this._multisampled?"texture_multisampled_2d":`texture_${sr[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: ${r}<${t.resolve(this.channelDataType)}>;`),e}};function fc(t){return!!(t!=null&&t.usableAsSampled)}var hc=class Oi extends Error{constructor(e){var n;super(`Resource '${(n=e.label)!=null?n:""}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,Oi.prototype)}},dc=class{constructor(t){this._membership=t,E(this,"resourceType","external-texture")}get label(){return this._membership.key}"~resolve"(t){let e=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${e}: texture_external;`),e}};function Ei(t){return new yc(t)}function Ai(t){return!!t&&t.resourceType==="bind-group-layout"}function pc(t){return!!t&&t.resourceType==="bind-group"}var wc=class ki extends Error{constructor(e,n){super(`Bind group '${e??""}' is missing a required binding '${n}'`),Object.setPrototypeOf(this,ki.prototype)}},xs=["compute"],ze=["compute","vertex","fragment"],yc=class{constructor(t){this.entries=t,E(this,"_label"),E(this,"_index"),E(this,"resourceType","bind-group-layout"),E(this,"bound",{});var e,n,r,i,d;let m=0;for(let[g,S]of Object.entries(t)){if(S===null){m++;continue}let A={idx:m,key:g,layout:this};if("uniform"in S&&(this.bound[g]=new gs("uniform",S.uniform,A)),"storage"in S){let P="type"in S.storage?S.storage:S.storage(0);this.bound[g]=new gs((e=S.access)!=null?e:"readonly",P,A)}"texture"in S&&(this.bound[g]=new lc(S.texture,(n=S.viewDimension)!=null?n:"2d",(r=S.multisampled)!=null?r:!1,A)),"storageTexture"in S&&(this.bound[g]=new uc(S.storageTexture,(i=S.viewDimension)!=null?i:"2d",(d=S.access)!=null?d:"writeonly",A)),"externalTexture"in S&&(this.bound[g]=new dc(A)),"sampler"in S&&(S.sampler==="comparison"?this.bound[g]=new Ju(A):this.bound[g]=new Qu(A)),m++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var e;return t.device.createBindGroupLayout({label:(e=this.label)!=null?e:"",entries:Object.values(this.entries).map((n,r)=>{var i,d,m,g;if(n===null)return null;let S=n.visibility,A={binding:r,visibility:0};if("uniform"in n)S=S??ze,A.buffer={type:"uniform"};else if("storage"in n)S=S??(n.access==="mutable"?xs:ze),A.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)S=S??ze,A.sampler={type:n.sampler};else if("texture"in n)S=S??ze,A.texture={sampleType:n.texture,viewDimension:(i=n.viewDimension)!=null?i:"2d",multisampled:(d=n.multisampled)!=null?d:!1};else if("storageTexture"in n){let P=(m=n.access)!=null?m:"writeonly";S=S??(P==="readonly"?ze:xs),A.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[P],viewDimension:(g=n.viewDimension)!=null?g:"2d"}}else"externalTexture"in n&&(S=S??ze,A.externalTexture={});return S!=null&&S.includes("compute")&&(A.visibility|=GPUShaderStage.COMPUTE),S!=null&&S.includes("vertex")&&(A.visibility|=GPUShaderStage.VERTEX),S!=null&&S.includes("fragment")&&(A.visibility|=GPUShaderStage.FRAGMENT),A}).filter(n=>n!==null)})}populate(t){return new Ii(this,t)}},Ii=class{constructor(e,n){this.layout=e,this.entries=n,E(this,"resourceType","bind-group");for(let r of Object.keys(e.entries))if(e.entries[r]!==null&&!(r in n))throw new wc(e.label,r)}unwrap(e){var n;return e.device.createBindGroup({label:(n=this.layout.label)!=null?n:"",layout:e.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([r,i],d)=>{var m;if(i===null)return null;let g=this.entries[r];if(g===void 0)throw new Error(`'${r}' is a resource required to populate bind group layout '${(m=this.layout.label)!=null?m:""}'.`);if("uniform"in i){let S;if($r(g)){if(!Xu(g))throw new ns(g);S={buffer:e.unwrap(g)}}else S={buffer:g};return{binding:d,resource:S}}if("storage"in i){let S;if($r(g)){if(!ms(g))throw new ns(g);S={buffer:e.unwrap(g)}}else S={buffer:g};return{binding:d,resource:S}}if("texture"in i){let S;if(rn(g)){if(!fc(g))throw new hc(g);S=e.unwrap(g.createView("sampled"))}else S=g;return{binding:d,resource:S}}if("storageTexture"in i){let S;if(rn(g)){if(!ms(g))throw new Zu(g);i.access==="readonly"?S=e.unwrap(g.createView("readonly")):i.access==="mutable"?S=e.unwrap(g.createView("mutable")):S=e.unwrap(g.createView("writeonly"))}else S=g;return{binding:d,resource:S}}if("externalTexture"in i||"sampler"in i)return{binding:d,resource:g};throw new Error(`Malformed bind group entry: ${g} (${JSON.stringify(g)})`)}).filter(r=>r!==null)})}};function mc(t,e="vertex"){return new xc(t,e)}function gc(t){return t?.resourceType==="vertex-layout"}function _n(t,e,n){if(Ge(e)||Pe(e))return _n(t,e.inner,ve(n,ue(e)));if(Le(e)){let r=n;return Object.fromEntries(Object.entries(e.propTypes).map(([i,d])=>{r=ve(r,St(d));let m=[i,_n(t,d,r)];return r+=wt(d),m}))}if(tr(e)){let r=n;return Object.fromEntries(Object.entries(e.propTypes).map(([i,d])=>{r=ve(r,ue(d));let m=[i,_n(t,d,r)];return r+=wt(d),m}))}if("type"in e&&typeof e.type=="string"){if(ci.includes(e.type))return{_layout:t,format:e.type,offset:n};let r=Wa[e.type];if(r)return{_layout:t,format:r,offset:n}}throw new Error(`Unsupported data used in vertex layout: ${String(e)}`)}var xc=class{constructor(t,e){this.schemaForCount=t,this.stepMode=e,E(this,"resourceType","vertex-layout"),E(this,"stride"),E(this,"attrib"),E(this,"_label");let n=t(0);this.stride=ve(wt(n.elementType),St(n)),this.attrib=_n(this,n.elementType,0)}get label(){return this._label}$name(t){return this._label=t,this}},vs=class{constructor(e){this._make=e,E(this,"_map",new WeakMap)}getOrMake(e,...n){if(this._map.has(e))return this._map.get(e);let r=this._make(e,...n);return this._map.set(e,r),r}};function vc(t,e){throw new Error(`Failed to handle ${t} at ${e}`)}var bc=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function _c(t){return bc.includes(t.type)}function $c(t,[e,n]){return` ${fu(n)}${e}: ${t.resolve(n)}, +`}function Sc(t,e){let n=t.names.makeUnique(e.label);return t.addDeclaration(` struct ${n} { -${Object.entries(e.propTypes).map(r=>_c(t,r)).join("")}} -`),n}function Sc(t,e){let n=t.resolve(e.elementType);return e.elementCount===0?`array<${n}>`:`array<${n}, ${e.elementCount}>`}function Pi(t,e){if(bc(e))return e.type;if(e.type==="struct")return $c(t,e);if(e.type==="array")return Sc(t,e);if(e.type==="atomic")return`atomic<${Pi(t,e.inner)}>`;if(e.type==="decorated")return t.resolve(e.inner);xc(e,"resolveData")}function*Mc(t){let e=0;for(;;)t.has(e)||(yield e),e++}var Tc=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function Nt(t,e){return qr(e.value)||Ve(e.value)?t.resolve(e.value):String(e.value)}function Dc(t){throw new Error(`'${JSON.stringify(t)}' was not handled by the WGSL generator.`)}function Fi(t,e){return e?{value:"true",dataType:rs}:{value:"false",dataType:rs}}function zi(t,e){return`${t.indent()}{ -${e.b.map(n=>Dr(t,n)).join(` +${Object.entries(e.propTypes).map(r=>$c(t,r)).join("")}} +`),n}function Mc(t,e){let n=t.resolve(e.elementType);return e.elementCount===0?`array<${n}>`:`array<${n}, ${e.elementCount}>`}function Pi(t,e){if(_c(e))return e.type;if(e.type==="struct")return Sc(t,e);if(e.type==="array")return Mc(t,e);if(e.type==="atomic")return`atomic<${Pi(t,e.inner)}>`;if(e.type==="decorated")return t.resolve(e.inner);vc(e,"resolveData")}function*Tc(t){let e=0;for(;;)t.has(e)||(yield e),e++}var Dc=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function Vt(t,e){return Gr(e.value)||Ve(e.value)?t.resolve(e.value):String(e.value)}function Uc(t){throw new Error(`'${JSON.stringify(t)}' was not handled by the WGSL generator.`)}function Fi(t,e){return e?{value:"true",dataType:rs}:{value:"false",dataType:rs}}function zi(t,e){return`${t.indent()}{ +${e.b.map(n=>Mr(t,n)).join(` `)} -${t.dedent()}}`}function Tr(t,e){return t.getById(e)}function Ht(t,e){if(typeof e=="string")return Tr(t,e);if(typeof e=="boolean")return Fi(t,e);if("x"in e){let[n,r,i]=e.x,d=Nt(t,Ht(t,n)),m=Nt(t,Ht(t,i));return{value:Tc.includes(r)?`(${d} ${r} ${m})`:`${d} ${r} ${m}`,dataType:Jt}}if("u"in e){let[n,r]=e.u,i=Nt(t,Ht(t,r));return{value:`${n}${i}`,dataType:Jt}}if("a"in e){let[n,r]=e.a,i=Ht(t,n),d=Nt(t,Ht(t,r));if(typeof i.value=="string")return{value:`${i.value}.${d}`,dataType:Jt};if(qr(i.value))return d==="value"?{value:Nt(t,i),dataType:Jt}:{value:i.value[d],dataType:Jt};if(typeof i.value=="object")return{value:i.value[d],dataType:Jt};throw new Error(`Cannot access member ${d} of ${i.value}`)}if("i"in e){let[n,r]=e.i,i=Nt(t,Ht(t,n)),d=Nt(t,Ht(t,r));return{value:`${i}[${d}]`,dataType:Jt}}if("n"in e)return{value:e.n,dataType:Jt};if("f"in e){let[n,r]=e.f,i=Ht(t,n).value,d=r.map(m=>Ht(t,m)).map(m=>Nt(t,m));return typeof i=="string"?{value:`${i}(${d.join(", ")})`,dataType:Jt}:{value:i(...d),dataType:Jt}}Dc(e)}function Dr(t,e){if(typeof e=="string")return`${t.pre}${Nt(t,Tr(t,e))};`;if(typeof e=="boolean")return`${t.pre}${Nt(t,Fi(t,e))};`;if("r"in e)return e.r===null?`${t.pre}return;`:`${t.pre}return ${Nt(t,Ht(t,e.r))};`;if("q"in e){let[n,r,i]=e.q,d=Nt(t,Ht(t,n));t.indent();let m=Dr(t,r);t.dedent(),t.indent();let g=i?Dr(t,i):void 0;return t.dedent(),g?`${t.pre}if (${d}) +${t.dedent()}}`}function Sr(t,e){return t.getById(e)}function Ht(t,e){if(typeof e=="string")return Sr(t,e);if(typeof e=="boolean")return Fi(t,e);if("x"in e){let[n,r,i]=e.x,d=Vt(t,Ht(t,n)),m=Vt(t,Ht(t,i));return{value:Dc.includes(r)?`(${d} ${r} ${m})`:`${d} ${r} ${m}`,dataType:Jt}}if("u"in e){let[n,r]=e.u,i=Vt(t,Ht(t,r));return{value:`${n}${i}`,dataType:Jt}}if("a"in e){let[n,r]=e.a,i=Ht(t,n),d=Vt(t,Ht(t,r));if(typeof i.value=="string")return{value:`${i.value}.${d}`,dataType:Jt};if(Gr(i.value))return d==="value"?{value:Vt(t,i),dataType:Jt}:{value:i.value[d],dataType:Jt};if(typeof i.value=="object")return{value:i.value[d],dataType:Jt};throw new Error(`Cannot access member ${d} of ${i.value}`)}if("i"in e){let[n,r]=e.i,i=Vt(t,Ht(t,n)),d=Vt(t,Ht(t,r));return{value:`${i}[${d}]`,dataType:Jt}}if("n"in e)return{value:e.n,dataType:Jt};if("f"in e){let[n,r]=e.f,i=Ht(t,n).value,d=r.map(m=>Ht(t,m)).map(m=>Vt(t,m));return typeof i=="string"?{value:`${i}(${d.join(", ")})`,dataType:Jt}:{value:i(...d),dataType:Jt}}Uc(e)}function Mr(t,e){if(typeof e=="string")return`${t.pre}${Vt(t,Sr(t,e))};`;if(typeof e=="boolean")return`${t.pre}${Vt(t,Fi(t,e))};`;if("r"in e)return e.r===null?`${t.pre}return;`:`${t.pre}return ${Vt(t,Ht(t,e.r))};`;if("q"in e){let[n,r,i]=e.q,d=Vt(t,Ht(t,n));t.indent();let m=Mr(t,r);t.dedent(),t.indent();let g=i?Mr(t,i):void 0;return t.dedent(),g?`${t.pre}if (${d}) ${m} ${t.pre}else ${g}`:`${t.pre}if (${d}) -${m}`}if("l"in e||"c"in e){let[n,r]="l"in e?e.l:e.c,i=Nt(t,Tr(t,n)),d=r?Ht(t,r):void 0;if(!d)throw new Error("Cannot create variable without an initial value.");return`${t.pre}var ${i} = ${Nt(t,d)};`}return"b"in e?zi(t,e):`${t.pre}${Nt(t,Ht(t,e))};`}function Uc(t,e){return zi(t,e)}var Bi="#CATCHALL#",Oc=class{constructor(){E(this,"_stack",[]),E(this,"_itemDepth",0)}get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}pushFunctionScope(t,e,n){this._stack.push({type:"functionScope",args:t,returnType:e,externalMap:n})}pop(){let t=this._stack.pop();t?.type==="item"&&this._itemDepth--}readSlot(t){for(let e=this._stack.length-1;e>=0;--e){let n=this._stack[e];if(n?.type==="item")n.usedSlots.add(t);else if(n?.type==="slotBinding"){let r=n.bindingMap.get(t);if(r!==void 0)return r}else if(!(n?.type==="functionScope"||n?.type==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let e=this._stack.length-1;e>=0;--e){let n=this._stack[e];if(n?.type==="functionScope"){let r=n.args.find(d=>d.value===t);if(r!==void 0)return r;let i=n.externalMap[t];return i!==void 0?{value:i,dataType:Jt}:void 0}if(n?.type==="blockScope"){let r=n.declarations.get(t);if(r!==void 0)return{value:t,dataType:r}}}}},bn=[""," "," "," "," "," "," "," "," "],cr=bn.length-1,Ec=class{constructor(){E(this,"identLevel",0)}get pre(){var t;return(t=bn[this.identLevel])!=null?t:bn[cr].repeat(this.identLevel/cr)+bn[this.identLevel%cr]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},Ac=class{constructor(t){E(this,"_memoizedResolves",new WeakMap),E(this,"_memoizedDerived",new WeakMap),E(this,"_indentController",new Ec),E(this,"_jitTranspiler"),E(this,"_itemStateStack",new Oc),E(this,"_declarations",[]),E(this,"bindGroupLayoutsToPlaceholderMap",new Map),E(this,"_nextFreeLayoutPlaceholderIdx",0),E(this,"fixedBindings",[]),E(this,"names"),this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){var e;return(e=this._itemStateStack.getResourceById(t))!=null?e:{value:t,dataType:Jt}}transpileFn(t){if(!this._jitTranspiler)throw new Error("Tried to execute a tgpu.fn function without providing a JIT transpiler, or transpiling at build time.");return this._jitTranspiler.transpileFn(t)}fnToWgsl(t){this._itemStateStack.pushFunctionScope(t.args,t.returnType,t.externalMap);let e=Uc(this,t.body);this._itemStateStack.pop();let n=t.args.map(r=>`${r.value}: ${this.resolve(r.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${this.resolve(t.returnType)}`:`(${n})`,body:e}}addDeclaration(t){this._declarations.push(t)}allocateLayoutEntry(t){let e=this.bindGroupLayoutsToPlaceholderMap,n=e.get(t);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,e.set(t,n)),n}allocateFixedEntry(t,e){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:t,resource:e}),{group:Bi,binding:n}}readSlot(t){let e=this._itemStateStack.readSlot(t);if(e===void 0)throw new Uo(t);return e}withSlots(t,e){this._itemStateStack.pushSlotBindings(t);try{return e()}finally{this._itemStateStack.pop()}}unwrap(t){if(Sr(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let e=t;for(;;)if(_r(e))e=this.readSlot(e);else if($r(e))e=this._getOrCompute(e);else break;return e}_getOrCompute(t){var e;let n=(e=this._memoizedDerived.get(t))!=null?e:[];this._itemStateStack.pushItem();try{for(let d of n)if([...d.slotToValueMap.entries()].every(([m,g])=>m.areEqual(this._itemStateStack.readSlot(m),g)))return d.result;let r=t["~compute"](),i=new Map;for(let d of this._itemStateStack.topItem.usedSlots)i.set(d,this._itemStateStack.readSlot(d));return n.push({slotToValueMap:i,result:r}),this._memoizedDerived.set(t,n),r}catch(r){throw r instanceof pn?r.appendToTrace(t):new pn(r,[t])}finally{this._itemStateStack.pop()}}_getOrInstantiate(t){var e;let n=(e=this._memoizedResolves.get(t))!=null?e:[];this._itemStateStack.pushItem();try{for(let d of n)if([...d.slotToValueMap.entries()].every(([m,g])=>m.areEqual(this._itemStateStack.readSlot(m),g)))return d.result;let r;Ve(t)?r=Pi(this,t):$r(t)||_r(t)?r=this.resolve(this.unwrap(t)):Ti(t)?r=t["~resolve"](this):r=this.resolveValue(t);let i=new Map;for(let d of this._itemStateStack.topItem.usedSlots)i.set(d,this._itemStateStack.readSlot(d));return n.push({slotToValueMap:i,result:r}),this._memoizedResolves.set(t,n),r}catch(r){throw r instanceof pn?r.appendToTrace(t):new pn(r,[t])}finally{this._itemStateStack.pop()}}resolve(t){if(Sr(t))return this.withSlots(t["~providing"].pairs,()=>this.resolve(t["~providing"].inner));if(t&&typeof t=="object"||typeof t=="function"){if(this._itemStateStack.itemDepth===0){let e=Eo(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(` +${m}`}if("l"in e||"c"in e){let[n,r]="l"in e?e.l:e.c,i=Vt(t,Sr(t,n)),d=r?Ht(t,r):void 0;if(!d)throw new Error("Cannot create variable without an initial value.");return`${t.pre}var ${i} = ${Vt(t,d)};`}return"b"in e?zi(t,e):`${t.pre}${Vt(t,Ht(t,e))};`}function Oc(t,e){return zi(t,e)}var Bi="#CATCHALL#",Ec=class{constructor(){E(this,"_stack",[]),E(this,"_itemDepth",0)}get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}pushFunctionScope(t,e,n){this._stack.push({type:"functionScope",args:t,returnType:e,externalMap:n})}pop(){let t=this._stack.pop();t?.type==="item"&&this._itemDepth--}readSlot(t){for(let e=this._stack.length-1;e>=0;--e){let n=this._stack[e];if(n?.type==="item")n.usedSlots.add(t);else if(n?.type==="slotBinding"){let r=n.bindingMap.get(t);if(r!==void 0)return r}else if(!(n?.type==="functionScope"||n?.type==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let e=this._stack.length-1;e>=0;--e){let n=this._stack[e];if(n?.type==="functionScope"){let r=n.args.find(d=>d.value===t);if(r!==void 0)return r;let i=n.externalMap[t];return i!==void 0?{value:i,dataType:Jt}:void 0}if(n?.type==="blockScope"){let r=n.declarations.get(t);if(r!==void 0)return{value:t,dataType:r}}}}},$n=[""," "," "," "," "," "," "," "," "],cr=$n.length-1,Ac=class{constructor(){E(this,"identLevel",0)}get pre(){var t;return(t=$n[this.identLevel])!=null?t:$n[cr].repeat(this.identLevel/cr)+$n[this.identLevel%cr]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},kc=class{constructor(t){E(this,"_memoizedResolves",new WeakMap),E(this,"_memoizedDerived",new WeakMap),E(this,"_indentController",new Ac),E(this,"_jitTranspiler"),E(this,"_itemStateStack",new Ec),E(this,"_declarations",[]),E(this,"bindGroupLayoutsToPlaceholderMap",new Map),E(this,"_nextFreeLayoutPlaceholderIdx",0),E(this,"fixedBindings",[]),E(this,"names"),this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){var e;return(e=this._itemStateStack.getResourceById(t))!=null?e:{value:t,dataType:Jt}}transpileFn(t){if(!this._jitTranspiler)throw new Error("Tried to execute a tgpu.fn function without providing a JIT transpiler, or transpiling at build time.");return this._jitTranspiler.transpileFn(t)}fnToWgsl(t){this._itemStateStack.pushFunctionScope(t.args,t.returnType,t.externalMap);let e=Oc(this,t.body);this._itemStateStack.pop();let n=t.args.map(r=>`${r.value}: ${this.resolve(r.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${this.resolve(t.returnType)}`:`(${n})`,body:e}}addDeclaration(t){this._declarations.push(t)}allocateLayoutEntry(t){let e=this.bindGroupLayoutsToPlaceholderMap,n=e.get(t);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,e.set(t,n)),n}allocateFixedEntry(t,e){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:t,resource:e}),{group:Bi,binding:n}}readSlot(t){let e=this._itemStateStack.readSlot(t);if(e===void 0)throw new Oo(t);return e}withSlots(t,e){this._itemStateStack.pushSlotBindings(t);try{return e()}finally{this._itemStateStack.pop()}}unwrap(t){if(_r(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let e=t;for(;;)if(vr(e))e=this.readSlot(e);else if(br(e))e=this._getOrCompute(e);else break;return e}_getOrCompute(t){var e;let n=(e=this._memoizedDerived.get(t))!=null?e:[];this._itemStateStack.pushItem();try{for(let d of n)if([...d.slotToValueMap.entries()].every(([m,g])=>m.areEqual(this._itemStateStack.readSlot(m),g)))return d.result;let r=t["~compute"](),i=new Map;for(let d of this._itemStateStack.topItem.usedSlots)i.set(d,this._itemStateStack.readSlot(d));return n.push({slotToValueMap:i,result:r}),this._memoizedDerived.set(t,n),r}catch(r){throw r instanceof wn?r.appendToTrace(t):new wn(r,[t])}finally{this._itemStateStack.pop()}}_getOrInstantiate(t){var e;let n=(e=this._memoizedResolves.get(t))!=null?e:[];this._itemStateStack.pushItem();try{for(let d of n)if([...d.slotToValueMap.entries()].every(([m,g])=>m.areEqual(this._itemStateStack.readSlot(m),g)))return d.result;let r;Ve(t)?r=Pi(this,t):br(t)||vr(t)?r=this.resolve(this.unwrap(t)):Ti(t)?r=t["~resolve"](this):r=this.resolveValue(t);let i=new Map;for(let d of this._itemStateStack.topItem.usedSlots)i.set(d,this._itemStateStack.readSlot(d));return n.push({slotToValueMap:i,result:r}),this._memoizedResolves.set(t,n),r}catch(r){throw r instanceof wn?r.appendToTrace(t):new wn(r,[t])}finally{this._itemStateStack.pop()}}resolve(t){if(_r(t))return this.withSlots(t["~providing"].pairs,()=>this.resolve(t["~providing"].inner));if(t&&typeof t=="object"||typeof t=="function"){if(this._itemStateStack.itemDepth===0){let e=Ao(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(` -`)}${e}`}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,e){if(qr(t))return this.resolve(t);if(e&&zr(e))return`array(${t.map(n=>this.resolveValue(n,e.elementType))})`;if(Array.isArray(t))return`array(${t.map(n=>this.resolveValue(n))})`;if(e&&Ne(e))return`${this.resolve(e)}(${Object.entries(e.propTypes).map(([n,r])=>this.resolveValue(t[n],r))})`;throw new Error(`Value ${t} (as json: ${JSON.stringify(t)}) of schema ${e} is not resolvable to WGSL`)}};function Wr(t,e){var n;let r=new Ac(e),i=r.resolve(t),d=r.bindGroupLayoutsToPlaceholderMap,m=[],g=new Set([...d.keys()].map(F=>F.index).filter(F=>F!==void 0)),S=Mc(g),A=r.fixedBindings.map((F,z)=>[String(z),F.layoutEntry]),I=()=>{let F=S.next().value,z=Ei(Object.fromEntries(A));return m[F]=z,i=i.replaceAll(Bi,String(F)),[F,z.populate(Object.fromEntries(r.fixedBindings.map((B,N)=>[String(N),B.resource])))]},k=A.length>0?I():null;for(let[F,z]of d.entries()){let B=(n=F.index)!=null?n:S.next().value;m[B]=F,i=i.replaceAll(z,String(B))}return{code:i,bindGroupLayouts:m,catchall:k}}function kc(t,e,n){return new Pc(new Fc(t,e,n),{})}function Ic(t){return t?.resourceType==="compute-pipeline"}var Pc=class ji{constructor(e,n){this._core=e,this._priors=n,E(this,"resourceType","compute-pipeline")}get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(e,n){var r;return new ji(this._core,{bindGroupLayoutMap:new Map([...(r=this._priors.bindGroupLayoutMap)!=null?r:[],[e,n]])})}dispatchWorkgroups(e,n,r){var i;let d=this._core.unwrap(),m=this._core.branch.commandEncoder.beginComputePass({label:(i=this._core.label)!=null?i:""});m.setPipeline(d.pipeline),d.bindGroupLayouts.forEach((g,S)=>{var A;if(d.catchall&&S===d.catchall[0])m.setBindGroup(S,this._core.branch.unwrap(d.catchall[1]));else{let I=(A=this._priors.bindGroupLayoutMap)==null?void 0:A.get(g);if(I===void 0)throw new zs(g.label);m.setBindGroup(S,this._core.branch.unwrap(I))}}),m.dispatchWorkgroups(e,n,r),m.end()}$name(e){return this._core.label=e,this}},Fc=class{constructor(t,e,n){this.branch=t,this._slotBindings=e,this._entryFn=n,E(this,"label"),E(this,"_memo")}unwrap(){var t,e,n,r,i;if(this._memo===void 0){let d=this.branch.device,{code:m,bindGroupLayouts:g,catchall:S}=Wr({"~resolve":A=>(A.withSlots(this._slotBindings,()=>{A.resolve(this._entryFn)}),"")},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});S!==null&&((e=g[S[0]])==null||e.$name(`${(t=this.label)!=null?t:""} - Automatic Bind Group & Layout`)),this._memo={pipeline:d.createComputePipeline({label:(n=this.label)!=null?n:"",layout:d.createPipelineLayout({label:`${(r=this.label)!=null?r:""} - Pipeline Layout`,bindGroupLayouts:g.map(A=>this.branch.unwrap(A))}),compute:{module:d.createShaderModule({label:`${(i=this.label)!=null?i:""} - Shader`,code:m})}}),bindGroupLayouts:g,catchall:S}}return this._memo}};function zc(t){return typeof t?.format=="string"}function Bc(t,e){var n,r;let i=[];if(tr(t)){if(!zc(e))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return i.push(e._layout),{usedVertexLayouts:i,bufferDefinitions:[{arrayStride:e._layout.stride,stepMode:e._layout.stepMode,attributes:[{format:e.format,offset:e.offset,shaderLocation:(n=gr(t))!=null?n:0}]}]}}let d=[],m=new WeakMap,g=0;for(let[S,A]of Object.entries(t)){if(hi(A))continue;let I=e[S];if(!I)throw new Error(`An attribute by the name of '${S}' was not provided to the shader.`);let k=I._layout,F=m.get(k);F||(i.push(k),F=[],d.push({arrayStride:k.stride,stepMode:k.stepMode,attributes:F}),m.set(k,F)),g=(r=gr(A))!=null?r:g,F.push({format:I.format,offset:I.offset,shaderLocation:g++})}return{usedVertexLayouts:i,bufferDefinitions:d}}function jc(t){return typeof t?.loadOp=="string"}function Rc(t,e){if(tr(t)){if(!jc(e))throw new Error("Expected a single color attachment, not a record.");return[e]}let n=[];for(let r of Object.keys(t)){let i=e[r];if(!i)throw new Error(`A color attachment by the name of '${r}' was not provided to the shader.`);n.push(i)}return n}function Vc(t){return typeof t?.format=="string"}function Nc(t,e){if(tr(t)){if(!Vc(e))throw new Error("Expected a single color target configuration, not a record.");return[e]}let n=[];for(let r of Object.keys(t)){let i=e[r];if(!i)throw new Error(`A color target by the name of '${r}' was not provided to the shader.`);n.push(i)}return n}function Lc(t){return new Gc(new qc(t),{})}var Gc=class Ce{constructor(e,n){this._core=e,this._priors=n,E(this,"resourceType","render-pipeline")}get label(){return this._core.label}$name(e){return this._core.label=e,this}with(e,n){var r,i;if(Ai(e))return new Ce(this._core,ye(he({},this._priors),{bindGroupLayoutMap:new Map([...(r=this._priors.bindGroupLayoutMap)!=null?r:[],[e,n]])}));if(mc(e))return new Ce(this._core,ye(he({},this._priors),{vertexLayoutMap:new Map([...(i=this._priors.vertexLayoutMap)!=null?i:[],[e,n]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(e){return new Ce(this._core,ye(he({},this._priors),{colorAttachment:e}))}withDepthStencilAttachment(e){return new Ce(this._core,ye(he({},this._priors),{depthStencilAttachment:e}))}draw(e,n,r,i){this.beginPass(d=>{d.draw(e,n,r,i)})}beginPass(e){var n;let r=this._core.unwrap(),{branch:i,fragmentFn:d}=this._core.options,m={colorAttachments:Rc(d.shell.returnType,(n=this._priors.colorAttachment)!=null?n:{}).map(k=>en(k.view)?ye(he({},k),{view:i.unwrap(k.view).createView()}):k)};if(this._core.label!==void 0&&(m.label=this._core.label),this._priors.depthStencilAttachment!==void 0){let k=this._priors.depthStencilAttachment;en(k.view)?m.depthStencilAttachment=ye(he({},k),{view:i.unwrap(k.view).createView()}):m.depthStencilAttachment=k}let g=i.commandEncoder.beginRenderPass(m);g.setPipeline(r.pipeline);let S=new Set(r.bindGroupLayouts);r.bindGroupLayouts.forEach((k,F)=>{var z;if(r.catchall&&F===r.catchall[0])g.setBindGroup(F,i.unwrap(r.catchall[1])),S.delete(k);else{let B=(z=this._priors.bindGroupLayoutMap)==null?void 0:z.get(k);B!==void 0&&(S.delete(k),g.setBindGroup(F,i.unwrap(B)))}});let A=new Set(this._core.usedVertexLayouts),I=this._core.usedVertexLayouts;I.forEach((k,F)=>{var z;let B=(z=this._priors.vertexLayoutMap)==null?void 0:z.get(k);B&&(A.delete(k),g.setVertexBuffer(F,i.unwrap(B)))}),e({setBindGroup(k,F){let z=r.bindGroupLayouts.indexOf(k);S.delete(k),g.setBindGroup(z,i.unwrap(F))},setVertexBuffer(k,F){let z=I.indexOf(k);A.delete(k),g.setVertexBuffer(z,i.unwrap(F))},draw(k,F,z,B){for(let N of S)throw new zs(N.label);if(A.size>0)throw new Error(`Missing vertex buffers for layouts: '${[...A.values()].map(N=>{var q;return(q=N.label)!=null?q:""}).join(", ")}'. Please provide it using pipeline.with(layout, buffer).(...)`);g.draw(k,F,z,B)},drawIndexed(k,F,z,B,N){g.drawIndexed(k,F,z,B,N)}}),g.end()}},qc=class{constructor(t){this.options=t,E(this,"label"),E(this,"usedVertexLayouts"),E(this,"_memo"),E(this,"_vertexBufferLayouts"),E(this,"_targets");let e=Bc(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=e.bufferDefinitions,this.usedVertexLayouts=e.usedVertexLayouts,this._targets=Nc(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,e,n,r;if(this._memo===void 0){let{branch:i,vertexFn:d,fragmentFn:m,slotBindings:g,primitiveState:S,depthStencilState:A}=this.options,{code:I,bindGroupLayouts:k,catchall:F}=Wr({"~resolve":q=>(q.withSlots(g,()=>{q.resolve(d),q.resolve(m)}),"")},{names:i.nameRegistry,jitTranspiler:i.jitTranspiler});F!==null&&((e=k[F[0]])==null||e.$name(`${(t=this.label)!=null?t:""} - Automatic Bind Group & Layout`));let z=i.device,B=z.createShaderModule({label:`${(n=this.label)!=null?n:""} - Shader`,code:I}),N={layout:z.createPipelineLayout({label:`${(r=this.label)!=null?r:""} - Pipeline Layout`,bindGroupLayouts:k.map(q=>i.unwrap(q))}),vertex:{module:B,buffers:this._vertexBufferLayouts},fragment:{module:B,targets:this._targets}};this.label!==void 0&&(N.label=this.label),S&&(N.primitive=S),A&&(N.depthStencil=A),this._memo={pipeline:z.createRenderPipeline(N),bindGroupLayouts:k,catchall:F}}return this._memo}},Wc=class Ri{constructor(e,n){this._getRoot=e,this._slotBindings=n}with(e,n){return new Ri(this._getRoot,[...this._slotBindings,[Gr(e)?e.slot:e,n]])}withCompute(e){return new Cc(this._getRoot(),this._slotBindings,e)}withVertex(e,n){return new Yc({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:e,vertexAttribs:n})}},Cc=class{constructor(t,e,n){this._root=t,this._slotBindings=e,this._entryFn=n}createPipeline(){return kc(this._root,this._slotBindings,this._entryFn)}},Yc=class{constructor(t){this._options=t}withFragment(t,e,n){return Dn(typeof t!="string"),Dn(typeof e!="string"),new Xc(ye(he({},this._options),{fragmentFn:t,targets:e}))}},Xc=class Ur{constructor(e){this._options=e}withPrimitive(e){return new Ur(ye(he({},this._options),{primitiveState:e}))}withDepthStencil(e){return new Ur(ye(he({},this._options),{depthStencilState:e}))}createPipeline(){return Lc(this._options)}},Vi=class extends Wc{constructor(t,e,n,r){super(()=>this,[]),this.device=t,this.nameRegistry=e,this.jitTranspiler=n,this._ownDevice=r,E(this,"_disposables",[]),E(this,"_unwrappedBindGroupLayouts",new vs(i=>i.unwrap(this))),E(this,"_unwrappedBindGroups",new vs(i=>i.unwrap(this))),E(this,"_commandEncoder",null)}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(t,e){let n=Cu(this,t,e);return this._disposables.push(n),n}createTexture(t){let e=nc(t,this);return this._disposables.push(e),e}createBindGroup(t,e){return new Ii(t,e)}destroy(){for(let t of this._disposables)t.destroy();this._ownDevice&&this.device.destroy()}unwrap(t){if(Ic(t))return t.rawPipeline;if(Ai(t))return this._unwrappedBindGroupLayouts.getOrMake(t);if(dc(t))return this._unwrappedBindGroups.getOrMake(t);if(Mr(t))return t.buffer;if(en(t)||rc(t)||sc(t))return t.unwrap();throw new Error(`Unknown resource type: ${t}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Zc(t){let{adapter:e,device:n,unstable_names:r="random",unstable_jitTranspiler:i}=t??{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let d=await navigator.gpu.requestAdapter(e);if(!d)throw new Error("Could not find a compatible GPU");return new Vi(await d.requestDevice(n),r==="random"?new Nr:new Lr,i,!0)}function Hc(t){let{device:e,unstable_names:n="random",unstable_jitTranspiler:r}=t??{};return new Vi(e,n==="random"?new Nr:new Lr,r,!1)}function Kc(t,e){return new Qc(t,e)}var Qc=class{constructor(t,e){this.dataType=t,this._value=e,E(this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let e=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${e} = ${n};`),e}get value(){return we()?this:this._value}};function Jc(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"$name"in t}function qn(t,e){for(let[n,r]of Object.entries(e))t[n]=r,Jc(r)&&(!("label"in r)||r.label===void 0)&&r.$name(n)}function Cr(t,e,n){return Object.entries(e).reduce((r,[i,d])=>r.replaceAll(new RegExp(`(?!(N in m)));qn(m,B)}let A=(d=S?.ast)!=null?d:r.transpileFn(String(e)),I=A.externalNames.filter(B=>!(B in m));if(I.length>0)throw new Oo(this.label,I);let k=A.argNames.map((B,N)=>({value:B,dataType:t.argTypes[N]})),{head:F,body:z}=r.fnToWgsl({args:k,returnType:t.returnType,body:A.body,externalMap:m});r.addDeclaration(`${i}fn ${g}${r.resolve(F)}${r.resolve(z)}`)}return g}}}function sl(t,e){var n,r,i;let{workgroupSize:d}=e;return{argTypes:[],returnType:void 0,workgroupSize:[(n=d[0])!=null?n:1,(r=d[1])!=null?r:1,(i=d[2])!=null?i:1],does(m){return il(this,d,m)}}}function il(t,e,n){let r=sr(t,n);return{shell:t,get label(){return r.label},$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,this},"~resolve"(i){return r.resolve(i,`@compute @workgroup_size(${e.join(", ")}) `)}}}function Li(t,e){return{argTypes:t,returnType:e,does(n){return ul(this,n)}}}function ol(t){return Li([]).does(t)}function al(t){return t?.resourceType==="function"}function ul(t,e){let n=sr(t,e),r=Object.assign((...i)=>{if(we())return new qi(r,i);if(typeof e=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return e(...i)},{shell:t,resourceType:"function",$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,this},with(i,d){return Gi(r,[[Gr(i)?i.slot:i,d]])},"~resolve"(i){return n.resolve(i)}});return Object.defineProperty(r,"label",{get:()=>n.label}),Object.defineProperty(r,"toString",{value:()=>{var i;return`fn:${(i=n.label)!=null?i:""}`}}),r}function Gi(t,e){let n={resourceType:"function",shell:t.shell,"~providing":{inner:t,pairs:e},$uses(i){return t.$uses(i),this},$name(i){return t.$name(i),this},with(i,d){return Gi(r,[...e,[Gr(i)?i.slot:i,d]])}},r=Object.assign((...i)=>we()?new qi(r,i):t(...i),n);return Object.defineProperty(r,"label",{get:()=>t.label}),Object.defineProperty(r,"toString",{value(){var i;let d=(i=t.label)!=null?i:"",m=([g,S])=>{var A;return`${(A=g.label)!=null?A:""}=${S}`};return`fn:${d}[${e.map(m).join(", ")}]`}}),r}var qi=class{constructor(t,e){this._fn=t,this._params=e}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(e=>t.resolve(e)).join(", ")})`)}};function cl(t){let e=0;return Object.fromEntries(Object.entries(t).map(([n,r])=>{if(hi(r))return[n,r];let i=gr(r);return i!==void 0?(e=i+1,[n,r]):[n,Vt(r,{type:"@location",value:e++})]}))}function Wi(t,e,n){var r,i,d;let m=tr(n)?xr(0,n):Qn(cl(n));if(typeof e=="string"){let g=(d=(i=(r=e.match(new RegExp("->(?.*?){","s")))==null?void 0:r.groups)==null?void 0:i.output)==null?void 0:d.trim();g&&!/\s/g.test(g)&&t.applyExternals({[g]:m})}return m}function ll(t,e){return{argTypes:[t],returnType:e,does(n){return fl(this,n)}}}function fl(t,e){let n=sr(t,e),r=Wi(n,e,t.returnType);return{shell:t,outputType:r,get label(){return n.label},$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,Ne(r)&&r.$name(`${i}_Output`),this},"~resolve"(i){return n.resolve(i,"@fragment ")}}}function hl(t,e){return{argTypes:[t],returnType:e,does(n){return dl(this,n)}}}function dl(t,e){let n=sr(t,e),r=Wi(n,e,t.returnType);return{shell:t,outputType:r,get label(){return n.label},$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,Ne(r)&&r.$name(`${i}_Output`),this},"~resolve"(i){return n.resolve(i,"@vertex ")}}}function pl(t){let{externals:e,template:n,names:r,jitTranspiler:i}=t,d={};qn(d,e??{});let m={"~resolve"(S){return Cr(S,d,n??"")}};Object.defineProperty(m,"toString",{value:()=>""});let{code:g}=Wr(m,{names:r==="strict"?new Lr:new Nr,jitTranspiler:i});return g}function Ci(t){return new wl(t)}var wl=class{constructor(t=void 0){this.defaultValue=t,E(this,"resourceType","slot"),E(this,"label")}$name(t){return this.label=t,this}areEqual(t,e){return Object.is(t,e)}toString(){var t;return`slot:${(t=this.label)!=null?t:""}`}get value(){let t=Yn();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return t.unwrap(this)}};function yl(t,e){return new ml(t,e)}var ml=class{constructor(t,e=void 0){this.schema=t,this.defaultValue=e,E(this,"resourceType","accessor"),E(this,"label"),E(this,"slot"),this.slot=Ci(e)}$name(t){return this.label=t,this.slot.$name(t),this}toString(){var t;return`accessor:${(t=this.label)!=null?t:""}`}get value(){if(!Yn())throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return this}"~resolve"(t){let e=t.unwrap(this.slot);return Zu(e)?t.resolve(e):al(e)?`${t.resolve(e)}()`:t.resolveValue(e,this.schema)}};function gl(t){return xl(t)}function xl(t){return{resourceType:"derived","~compute":t,get value(){let e=Yn();if(!e)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return e.unwrap(this)},with(e,n){return Yi(this,[[e,n]])},toString(){return"derived"}}}function Yi(t,e){return{resourceType:"derived","~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},"~providing":{inner:t,pairs:e},get value(){let n=Yn();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return n.unwrap(this)},with(n,r){return Yi(t,[...e,[n,r]])},toString(){let n=([r,i])=>{var d;return`${(d=r.label)!=null?d:""}=${i}`};return`derived[${e.map(n).join(", ")}]`}}}function vl(t,e){return new Xi("private",t,e)}function bl(t){return new Xi("workgroup",t)}var Xi=class{constructor(t,e,n){this.scope=t,this._dataType=e,this._initialValue=n,E(this,"_label")}$name(t){return this._label=t,this}"~resolve"(t){let e=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${e}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${e}: ${t.resolve(this._dataType)};`),e}get value(){if(!we())throw new Error("Cannot access tgpu.var's value directly in JS.");return this}},Yr={Uniform:"uniform",Storage:"storage",Vertex:"vertex",fn:Li,procedure:ol,fragmentFn:ll,vertexFn:hl,computeFn:sl,vertexLayout:yc,bindGroupLayout:Ei,derived:gl,slot:Ci,accessor:yl,privateVar:vl,workgroupVar:bl,const:Kc,declare:tl,init:Zc,initFromDevice:Hc,resolve:pl};Object.assign(Yr,{__assignAst:rl});var Ie=Yr;const Zi=Or(),_l=Zi.Provider;function Xr(){return kr(Zi,"useRootContext","RootContext")}function $l(t){const[e]=ro(()=>({adapterOptions:t.adapterOptions}),async({adapterOptions:n})=>{sn(()=>{d?.destroy(),i?.destroy()});const r=await navigator.gpu?.requestAdapter(n);if(!r)throw new Error("Failed to get GPUAdapter, make sure to use a browser with WebGPU support.");const i=await r?.requestDevice();if(!i)throw new Error("Failed to get GPUDevice, make sure to use a browser with WebGPU support.");const d=Yr.initFromDevice({device:i});return{adapter:r,device:i,root:d}});return Kt(Er,{get when(){return e()},keyed:!0,children:n=>Kt(_l,{value:n,get children(){return t.children}})})}function Sl(t,e){const[n,r]=qt();return rn(()=>{const i=t();if(!i)return;const d=new ResizeObserver(m=>{const g=m[0]?.devicePixelContentBoxSize[0];if(!i.isConnected||!g)return;const{width:S,height:A}=i.getBoundingClientRect(),I=g.inlineSize,k=g.blockSize,F={width:S,height:A,widthPX:I,heightPX:k};r(F),e?.(F)});d.observe(i),sn(()=>{d.disconnect()})}),n}var Ml=Ar("");const{min:bs,max:_s}=Math;function Tl(t){const{device:e}=Xr(),[n,r]=qt(),i=Sl(n,m=>{const g=n();g&&(g.width=_s(1,bs(m.widthPX,e.limits.maxTextureDimension2D)),g.height=_s(1,bs(m.heightPX,e.limits.maxTextureDimension2D)))});function d(m){const g=m.getContext("webgpu");if(!g)throw new Error("GPUCanvasContext failed to initialize.");return g.configure({device:e,format:navigator.gpu.getPreferredCanvasFormat()}),g}return[(()=>{var m=Ml();return wo(r,m),m.style.setProperty("width","100%"),m.style.setProperty("height","100%"),Ae(()=>yn(m,t.class)),m})(),Kt(Er,{get when(){return n()},keyed:!0,children:m=>Kt(Lu,{get value(){return{canvas:m,context:d(m),canvasSize:()=>({width:i()?.widthPX??0,height:i()?.heightPX??0})}},get children(){return t.children}})})]}const Hi=Qn({viewMatrix:Je,viewMatrixInverse:Je,resolution:G}),nn=Ie.bindGroupLayout({camera2DUniforms:{uniform:Hi}}),Dl=Ie.fn([G],G).does(`(world: vec2f) -> vec2f { +`)}${e}`}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,e){if(Gr(t))return this.resolve(t);if(e&&Fr(e))return`array(${t.map(n=>this.resolveValue(n,e.elementType))})`;if(Array.isArray(t))return`array(${t.map(n=>this.resolveValue(n))})`;if(e&&Le(e))return`${this.resolve(e)}(${Object.entries(e.propTypes).map(([n,r])=>this.resolveValue(t[n],r))})`;throw new Error(`Value ${t} (as json: ${JSON.stringify(t)}) of schema ${e} is not resolvable to WGSL`)}};function qr(t,e){var n;let r=new kc(e),i=r.resolve(t),d=r.bindGroupLayoutsToPlaceholderMap,m=[],g=new Set([...d.keys()].map(F=>F.index).filter(F=>F!==void 0)),S=Tc(g),A=r.fixedBindings.map((F,z)=>[String(z),F.layoutEntry]),P=()=>{let F=S.next().value,z=Ei(Object.fromEntries(A));return m[F]=z,i=i.replaceAll(Bi,String(F)),[F,z.populate(Object.fromEntries(r.fixedBindings.map((B,V)=>[String(V),B.resource])))]},k=A.length>0?P():null;for(let[F,z]of d.entries()){let B=(n=F.index)!=null?n:S.next().value;m[B]=F,i=i.replaceAll(z,String(B))}return{code:i,bindGroupLayouts:m,catchall:k}}function Ic(t,e,n){return new Fc(new zc(t,e,n),{})}function Pc(t){return t?.resourceType==="compute-pipeline"}var Fc=class ji{constructor(e,n){this._core=e,this._priors=n,E(this,"resourceType","compute-pipeline")}get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(e,n){var r;return new ji(this._core,{bindGroupLayoutMap:new Map([...(r=this._priors.bindGroupLayoutMap)!=null?r:[],[e,n]])})}dispatchWorkgroups(e,n,r){var i;let d=this._core.unwrap(),m=this._core.branch.commandEncoder.beginComputePass({label:(i=this._core.label)!=null?i:""});m.setPipeline(d.pipeline),d.bindGroupLayouts.forEach((g,S)=>{var A;if(d.catchall&&S===d.catchall[0])m.setBindGroup(S,this._core.branch.unwrap(d.catchall[1]));else{let P=(A=this._priors.bindGroupLayoutMap)==null?void 0:A.get(g);if(P===void 0)throw new zs(g.label);m.setBindGroup(S,this._core.branch.unwrap(P))}}),m.dispatchWorkgroups(e,n,r),m.end()}$name(e){return this._core.label=e,this}},zc=class{constructor(t,e,n){this.branch=t,this._slotBindings=e,this._entryFn=n,E(this,"label"),E(this,"_memo")}unwrap(){var t,e,n,r,i;if(this._memo===void 0){let d=this.branch.device,{code:m,bindGroupLayouts:g,catchall:S}=qr({"~resolve":A=>(A.withSlots(this._slotBindings,()=>{A.resolve(this._entryFn)}),"")},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});S!==null&&((e=g[S[0]])==null||e.$name(`${(t=this.label)!=null?t:""} - Automatic Bind Group & Layout`)),this._memo={pipeline:d.createComputePipeline({label:(n=this.label)!=null?n:"",layout:d.createPipelineLayout({label:`${(r=this.label)!=null?r:""} - Pipeline Layout`,bindGroupLayouts:g.map(A=>this.branch.unwrap(A))}),compute:{module:d.createShaderModule({label:`${(i=this.label)!=null?i:""} - Shader`,code:m})}}),bindGroupLayouts:g,catchall:S}}return this._memo}};function Bc(t){return typeof t?.format=="string"}function jc(t,e){var n,r;let i=[];if(er(t)){if(!Bc(e))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return i.push(e._layout),{usedVertexLayouts:i,bufferDefinitions:[{arrayStride:e._layout.stride,stepMode:e._layout.stepMode,attributes:[{format:e.format,offset:e.offset,shaderLocation:(n=mr(t))!=null?n:0}]}]}}let d=[],m=new WeakMap,g=0;for(let[S,A]of Object.entries(t)){if(hi(A))continue;let P=e[S];if(!P)throw new Error(`An attribute by the name of '${S}' was not provided to the shader.`);let k=P._layout,F=m.get(k);F||(i.push(k),F=[],d.push({arrayStride:k.stride,stepMode:k.stepMode,attributes:F}),m.set(k,F)),g=(r=mr(A))!=null?r:g,F.push({format:P.format,offset:P.offset,shaderLocation:g++})}return{usedVertexLayouts:i,bufferDefinitions:d}}function Rc(t){return typeof t?.loadOp=="string"}function Nc(t,e){if(er(t)){if(!Rc(e))throw new Error("Expected a single color attachment, not a record.");return[e]}let n=[];for(let r of Object.keys(t)){let i=e[r];if(!i)throw new Error(`A color attachment by the name of '${r}' was not provided to the shader.`);n.push(i)}return n}function Vc(t){return typeof t?.format=="string"}function Lc(t,e){if(er(t)){if(!Vc(e))throw new Error("Expected a single color target configuration, not a record.");return[e]}let n=[];for(let r of Object.keys(t)){let i=e[r];if(!i)throw new Error(`A color target by the name of '${r}' was not provided to the shader.`);n.push(i)}return n}function Gc(t){return new qc(new Wc(t),{})}var qc=class Ye{constructor(e,n){this._core=e,this._priors=n,E(this,"resourceType","render-pipeline")}get label(){return this._core.label}$name(e){return this._core.label=e,this}with(e,n){var r,i;if(Ai(e))return new Ye(this._core,me(he({},this._priors),{bindGroupLayoutMap:new Map([...(r=this._priors.bindGroupLayoutMap)!=null?r:[],[e,n]])}));if(gc(e))return new Ye(this._core,me(he({},this._priors),{vertexLayoutMap:new Map([...(i=this._priors.vertexLayoutMap)!=null?i:[],[e,n]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(e){return new Ye(this._core,me(he({},this._priors),{colorAttachment:e}))}withDepthStencilAttachment(e){return new Ye(this._core,me(he({},this._priors),{depthStencilAttachment:e}))}draw(e,n,r,i){this.beginPass(d=>{d.draw(e,n,r,i)})}beginPass(e){var n;let r=this._core.unwrap(),{branch:i,fragmentFn:d}=this._core.options,m={colorAttachments:Nc(d.shell.returnType,(n=this._priors.colorAttachment)!=null?n:{}).map(k=>rn(k.view)?me(he({},k),{view:i.unwrap(k.view).createView()}):k)};if(this._core.label!==void 0&&(m.label=this._core.label),this._priors.depthStencilAttachment!==void 0){let k=this._priors.depthStencilAttachment;rn(k.view)?m.depthStencilAttachment=me(he({},k),{view:i.unwrap(k.view).createView()}):m.depthStencilAttachment=k}let g=i.commandEncoder.beginRenderPass(m);g.setPipeline(r.pipeline);let S=new Set(r.bindGroupLayouts);r.bindGroupLayouts.forEach((k,F)=>{var z;if(r.catchall&&F===r.catchall[0])g.setBindGroup(F,i.unwrap(r.catchall[1])),S.delete(k);else{let B=(z=this._priors.bindGroupLayoutMap)==null?void 0:z.get(k);B!==void 0&&(S.delete(k),g.setBindGroup(F,i.unwrap(B)))}});let A=new Set(this._core.usedVertexLayouts),P=this._core.usedVertexLayouts;P.forEach((k,F)=>{var z;let B=(z=this._priors.vertexLayoutMap)==null?void 0:z.get(k);B&&(A.delete(k),g.setVertexBuffer(F,i.unwrap(B)))}),e({setBindGroup(k,F){let z=r.bindGroupLayouts.indexOf(k);S.delete(k),g.setBindGroup(z,i.unwrap(F))},setVertexBuffer(k,F){let z=P.indexOf(k);A.delete(k),g.setVertexBuffer(z,i.unwrap(F))},draw(k,F,z,B){for(let V of S)throw new zs(V.label);if(A.size>0)throw new Error(`Missing vertex buffers for layouts: '${[...A.values()].map(V=>{var L;return(L=V.label)!=null?L:""}).join(", ")}'. Please provide it using pipeline.with(layout, buffer).(...)`);g.draw(k,F,z,B)},drawIndexed(k,F,z,B,V){g.drawIndexed(k,F,z,B,V)}}),g.end()}},Wc=class{constructor(t){this.options=t,E(this,"label"),E(this,"usedVertexLayouts"),E(this,"_memo"),E(this,"_vertexBufferLayouts"),E(this,"_targets");let e=jc(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=e.bufferDefinitions,this.usedVertexLayouts=e.usedVertexLayouts,this._targets=Lc(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,e,n,r;if(this._memo===void 0){let{branch:i,vertexFn:d,fragmentFn:m,slotBindings:g,primitiveState:S,depthStencilState:A}=this.options,{code:P,bindGroupLayouts:k,catchall:F}=qr({"~resolve":L=>(L.withSlots(g,()=>{L.resolve(d),L.resolve(m)}),"")},{names:i.nameRegistry,jitTranspiler:i.jitTranspiler});F!==null&&((e=k[F[0]])==null||e.$name(`${(t=this.label)!=null?t:""} - Automatic Bind Group & Layout`));let z=i.device,B=z.createShaderModule({label:`${(n=this.label)!=null?n:""} - Shader`,code:P}),V={layout:z.createPipelineLayout({label:`${(r=this.label)!=null?r:""} - Pipeline Layout`,bindGroupLayouts:k.map(L=>i.unwrap(L))}),vertex:{module:B,buffers:this._vertexBufferLayouts},fragment:{module:B,targets:this._targets}};this.label!==void 0&&(V.label=this.label),S&&(V.primitive=S),A&&(V.depthStencil=A),this._memo={pipeline:z.createRenderPipeline(V),bindGroupLayouts:k,catchall:F}}return this._memo}},Cc=class Ri{constructor(e,n){this._getRoot=e,this._slotBindings=n}with(e,n){return new Ri(this._getRoot,[...this._slotBindings,[Lr(e)?e.slot:e,n]])}withCompute(e){return new Yc(this._getRoot(),this._slotBindings,e)}withVertex(e,n){return new Xc({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:e,vertexAttribs:n})}},Yc=class{constructor(t,e,n){this._root=t,this._slotBindings=e,this._entryFn=n}createPipeline(){return Ic(this._root,this._slotBindings,this._entryFn)}},Xc=class{constructor(t){this._options=t}withFragment(t,e,n){return On(typeof t!="string"),On(typeof e!="string"),new Zc(me(he({},this._options),{fragmentFn:t,targets:e}))}},Zc=class Tr{constructor(e){this._options=e}withPrimitive(e){return new Tr(me(he({},this._options),{primitiveState:e}))}withDepthStencil(e){return new Tr(me(he({},this._options),{depthStencilState:e}))}createPipeline(){return Gc(this._options)}},Ni=class extends Cc{constructor(t,e,n,r){super(()=>this,[]),this.device=t,this.nameRegistry=e,this.jitTranspiler=n,this._ownDevice=r,E(this,"_disposables",[]),E(this,"_unwrappedBindGroupLayouts",new vs(i=>i.unwrap(this))),E(this,"_unwrappedBindGroups",new vs(i=>i.unwrap(this))),E(this,"_commandEncoder",null)}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(t,e){let n=Yu(this,t,e);return this._disposables.push(n),n}createTexture(t){let e=rc(t,this);return this._disposables.push(e),e}createBindGroup(t,e){return new Ii(t,e)}destroy(){for(let t of this._disposables)t.destroy();this._ownDevice&&this.device.destroy()}unwrap(t){if(Pc(t))return t.rawPipeline;if(Ai(t))return this._unwrappedBindGroupLayouts.getOrMake(t);if(pc(t))return this._unwrappedBindGroups.getOrMake(t);if($r(t))return t.buffer;if(rn(t)||sc(t)||ic(t))return t.unwrap();throw new Error(`Unknown resource type: ${t}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Hc(t){let{adapter:e,device:n,unstable_names:r="random",unstable_jitTranspiler:i}=t??{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let d=await navigator.gpu.requestAdapter(e);if(!d)throw new Error("Could not find a compatible GPU");return new Ni(await d.requestDevice(n),r==="random"?new Nr:new Vr,i,!0)}function Kc(t){let{device:e,unstable_names:n="random",unstable_jitTranspiler:r}=t??{};return new Ni(e,n==="random"?new Nr:new Vr,r,!1)}function Qc(t,e){return new Jc(t,e)}var Jc=class{constructor(t,e){this.dataType=t,this._value=e,E(this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let e=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${e} = ${n};`),e}get value(){return ye()?this:this._value}};function tl(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"$name"in t}function Cn(t,e){for(let[n,r]of Object.entries(e))t[n]=r,tl(r)&&(!("label"in r)||r.label===void 0)&&r.$name(n)}function Wr(t,e,n){return Object.entries(e).reduce((r,[i,d])=>r.replaceAll(new RegExp(`(?!(V in m)));Cn(m,B)}let A=(d=S?.ast)!=null?d:r.transpileFn(String(e)),P=A.externalNames.filter(B=>!(B in m));if(P.length>0)throw new Eo(this.label,P);let k=A.argNames.map((B,V)=>({value:B,dataType:t.argTypes[V]})),{head:F,body:z}=r.fnToWgsl({args:k,returnType:t.returnType,body:A.body,externalMap:m});r.addDeclaration(`${i}fn ${g}${r.resolve(F)}${r.resolve(z)}`)}return g}}}function il(t,e){var n,r,i;let{workgroupSize:d}=e;return{argTypes:[],returnType:void 0,workgroupSize:[(n=d[0])!=null?n:1,(r=d[1])!=null?r:1,(i=d[2])!=null?i:1],does(m){return ol(this,d,m)}}}function ol(t,e,n){let r=ir(t,n);return{shell:t,get label(){return r.label},$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,this},"~resolve"(i){return r.resolve(i,`@compute @workgroup_size(${e.join(", ")}) `)}}}function Li(t,e){return{argTypes:t,returnType:e,does(n){return cl(this,n)}}}function al(t){return Li([]).does(t)}function ul(t){return t?.resourceType==="function"}function cl(t,e){let n=ir(t,e),r=Object.assign((...i)=>{if(ye())return new qi(r,i);if(typeof e=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return e(...i)},{shell:t,resourceType:"function",$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,this},with(i,d){return Gi(r,[[Lr(i)?i.slot:i,d]])},"~resolve"(i){return n.resolve(i)}});return Object.defineProperty(r,"label",{get:()=>n.label}),Object.defineProperty(r,"toString",{value:()=>{var i;return`fn:${(i=n.label)!=null?i:""}`}}),r}function Gi(t,e){let n={resourceType:"function",shell:t.shell,"~providing":{inner:t,pairs:e},$uses(i){return t.$uses(i),this},$name(i){return t.$name(i),this},with(i,d){return Gi(r,[...e,[Lr(i)?i.slot:i,d]])}},r=Object.assign((...i)=>ye()?new qi(r,i):t(...i),n);return Object.defineProperty(r,"label",{get:()=>t.label}),Object.defineProperty(r,"toString",{value(){var i;let d=(i=t.label)!=null?i:"",m=([g,S])=>{var A;return`${(A=g.label)!=null?A:""}=${S}`};return`fn:${d}[${e.map(m).join(", ")}]`}}),r}var qi=class{constructor(t,e){this._fn=t,this._params=e}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(e=>t.resolve(e)).join(", ")})`)}};function ll(t){let e=0;return Object.fromEntries(Object.entries(t).map(([n,r])=>{if(hi(r))return[n,r];let i=mr(r);return i!==void 0?(e=i+1,[n,r]):[n,Nt(r,{type:"@location",value:e++})]}))}function Wi(t,e,n){var r,i,d;let m=er(n)?bn(0,n):qe(ll(n));if(typeof e=="string"){let g=(d=(i=(r=e.match(new RegExp("->(?.*?){","s")))==null?void 0:r.groups)==null?void 0:i.output)==null?void 0:d.trim();g&&!/\s/g.test(g)&&t.applyExternals({[g]:m})}return m}function fl(t,e){return{argTypes:[t],returnType:e,does(n){return hl(this,n)}}}function hl(t,e){let n=ir(t,e),r=Wi(n,e,t.returnType);return{shell:t,outputType:r,get label(){return n.label},$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,Le(r)&&r.$name(`${i}_Output`),this},"~resolve"(i){return n.resolve(i,"@fragment ")}}}function dl(t,e){return{argTypes:[t],returnType:e,does(n){return pl(this,n)}}}function pl(t,e){let n=ir(t,e),r=Wi(n,e,t.returnType);return{shell:t,outputType:r,get label(){return n.label},$uses(i){return n.applyExternals(i),this},$name(i){return n.label=i,Le(r)&&r.$name(`${i}_Output`),this},"~resolve"(i){return n.resolve(i,"@vertex ")}}}function wl(t){let{externals:e,template:n,names:r,jitTranspiler:i}=t,d={};Cn(d,e??{});let m={"~resolve"(S){return Wr(S,d,n??"")}};Object.defineProperty(m,"toString",{value:()=>""});let{code:g}=qr(m,{names:r==="strict"?new Vr:new Nr,jitTranspiler:i});return g}function Ci(t){return new yl(t)}var yl=class{constructor(t=void 0){this.defaultValue=t,E(this,"resourceType","slot"),E(this,"label")}$name(t){return this.label=t,this}areEqual(t,e){return Object.is(t,e)}toString(){var t;return`slot:${(t=this.label)!=null?t:""}`}get value(){let t=Zn();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return t.unwrap(this)}};function ml(t,e){return new gl(t,e)}var gl=class{constructor(t,e=void 0){this.schema=t,this.defaultValue=e,E(this,"resourceType","accessor"),E(this,"label"),E(this,"slot"),this.slot=Ci(e)}$name(t){return this.label=t,this.slot.$name(t),this}toString(){var t;return`accessor:${(t=this.label)!=null?t:""}`}get value(){if(!Zn())throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return this}"~resolve"(t){let e=t.unwrap(this.slot);return Hu(e)?t.resolve(e):ul(e)?`${t.resolve(e)}()`:t.resolveValue(e,this.schema)}};function xl(t){return vl(t)}function vl(t){return{resourceType:"derived","~compute":t,get value(){let e=Zn();if(!e)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return e.unwrap(this)},with(e,n){return Yi(this,[[e,n]])},toString(){return"derived"}}}function Yi(t,e){return{resourceType:"derived","~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},"~providing":{inner:t,pairs:e},get value(){let n=Zn();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return n.unwrap(this)},with(n,r){return Yi(t,[...e,[n,r]])},toString(){let n=([r,i])=>{var d;return`${(d=r.label)!=null?d:""}=${i}`};return`derived[${e.map(n).join(", ")}]`}}}function bl(t,e){return new Xi("private",t,e)}function _l(t){return new Xi("workgroup",t)}var Xi=class{constructor(t,e,n){this.scope=t,this._dataType=e,this._initialValue=n,E(this,"_label")}$name(t){return this._label=t,this}"~resolve"(t){let e=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${e}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${e}: ${t.resolve(this._dataType)};`),e}get value(){if(!ye())throw new Error("Cannot access tgpu.var's value directly in JS.");return this}},Cr={Uniform:"uniform",Storage:"storage",Vertex:"vertex",fn:Li,procedure:al,fragmentFn:fl,vertexFn:dl,computeFn:il,vertexLayout:mc,bindGroupLayout:Ei,derived:xl,slot:Ci,accessor:ml,privateVar:bl,workgroupVar:_l,const:Qc,declare:el,init:Hc,initFromDevice:Kc,resolve:wl};Object.assign(Cr,{__assignAst:sl});var Me=Cr;const Zi=Ur(),$l=Zi.Provider;function Yr(){return Ar(Zi,"useRootContext","RootContext")}function Sl(t){const[e]=so(()=>({adapterOptions:t.adapterOptions}),async({adapterOptions:n})=>{on(()=>{d?.destroy(),i?.destroy()});const r=await navigator.gpu?.requestAdapter(n);if(!r)throw new Error("Failed to get GPUAdapter, make sure to use a browser with WebGPU support.");console.info(`Using ${r.info.vendor} adapter.`);const i=await r?.requestDevice();if(!i)throw new Error("Failed to get GPUDevice, make sure to use a browser with WebGPU support.");const d=Cr.initFromDevice({device:i});return{adapter:r,device:i,root:d}});return Kt(Or,{get when(){return e()},keyed:!0,children:n=>Kt($l,{value:n,get children(){return t.children}})})}function Ml(t,e){const[n,r]=qt();return Ae(()=>{const i=t();if(!i)return;const d=new ResizeObserver(m=>{const g=m[0]?.devicePixelContentBoxSize[0];if(!i.isConnected||!g)return;const{width:S,height:A}=i.getBoundingClientRect(),P=g.inlineSize,k=g.blockSize,F={width:S,height:A,widthPX:P,heightPX:k};r(F),e?.(F)});d.observe(i),on(()=>{d.disconnect()})}),n}var Tl=Er("");const{min:bs,max:_s}=Math;function Dl(t){const{device:e}=Yr(),[n,r]=qt(),i=Ml(n,m=>{const g=n();g&&(g.width=_s(1,bs(m.widthPX,e.limits.maxTextureDimension2D)),g.height=_s(1,bs(m.heightPX,e.limits.maxTextureDimension2D)))});function d(m){const g=m.getContext("webgpu");if(!g)throw new Error("GPUCanvasContext failed to initialize.");return g.configure({device:e,format:navigator.gpu.getPreferredCanvasFormat()}),g}return[(()=>{var m=Tl();return yo(r,m),m.style.setProperty("width","100%"),m.style.setProperty("height","100%"),Ie(()=>mn(m,t.class)),m})(),Kt(Or,{get when(){return n()},keyed:!0,children:m=>Kt(Gu,{get value(){return{canvas:m,context:d(m),canvasSize:()=>({width:i()?.widthPX??0,height:i()?.heightPX??0})}},get children(){return t.children}})})]}const Hi=qe({viewMatrix:en,viewMatrixInverse:en,resolution:q}),sn=Me.bindGroupLayout({camera2DUniforms:{uniform:Hi}}),Ul=Me.fn([q],q).does(`(world: vec2f) -> vec2f { let clip = camera2DUniforms.viewMatrix * vec3(world, 1); return clip.xy / clip.z; - }`).$uses({...nn.bound}).$name("camera2DWorldToClip"),Ul=Ie.fn([G],G).does(`(clip: vec2f) -> vec2f { + }`).$uses({...sn.bound}).$name("camera2DWorldToClip"),Ol=Me.fn([q],q).does(`(clip: vec2f) -> vec2f { let world = camera2DUniforms.viewMatrixInverse * vec3(clip, 1); return world.xy / world.z; - }`).$uses({...nn.bound}).$name("camera2DClipToWorld"),Ol=Ie.fn([G],G).does(`(clip: vec2f) -> vec2f { + }`).$uses({...sn.bound}).$name("camera2DClipToWorld"),El=Me.fn([q],q).does(`(clip: vec2f) -> vec2f { return 0.5 * clip * camera2DUniforms.resolution; - }`).$uses({...nn.bound}).$name("camera2DClipToPixels");function El(t){const{root:e}=Xr(),{canvasSize:n}=nr(),r=()=>1/t.fovy,i=e.createBuffer(Hi).$usage("uniform").$name("Camera2DUniforms"),d=nn.populate({camera2DUniforms:i}),m=ve(()=>{const{position:A,fovy:I}=t,{x:k,y:F}=A,{width:z,height:B}=n(),N=z/B,q=fi();Eu.ortho(k-N*I,k+N*I,F-I,F+I,0,0,q);const tt=Je(q.columns[0].xyw,q.columns[1].xyw,q.columns[3].xyw),st=Ou.inverse(tt,Je());return{viewMatrix:tt,viewMatrixInverse:st,resolution:G(z,B)}});function g({x:A,y:I}){return Au.transformMat3(Qe(A,I,1),m().viewMatrixInverse,G())}function S(){i.write(m())}return Kt(bo,{value:{update:S,bindGroup:d,BindGroupLayout:nn,wgsl:{worldToClip:Dl,clipToWorld:Ul,clipToPixels:Ol},js:{clipToWorld:g},zoom:r},get children(){return t.children}})}function Al(t){const{canvas:e}=nr(),[n,r]=qt(1),[i,d]=qt(G());let m;function g(S){S.preventDefault();const A=pi(S),I=m?.(A);if(!I)return;const k=n(),F=k*(1-S.deltaY*.001),z=k/F;Ts(()=>{d(({x:B,y:N})=>G(B+(I.x-B)*(1-z),N+(I.y-N)*(1-z))),r(F)})}return rn(()=>{e.addEventListener("wheel",g,{passive:!1}),sn(()=>{e.removeEventListener("wheel",g)})}),Kt(El,{get position(){return i()},get fovy(){return 1/n()},get children(){return[ve(()=>(()=>{let{js:S}=Ir();return m=S.clipToWorld,null})()),ve(()=>t.children)]}})}function kl(t){rn(()=>{let e=-1;function n(){de(t),e=requestAnimationFrame(n)}sn(()=>{cancelAnimationFrame(e)}),n()})}const Ge=Qn({position:fu.position,positionOriginal:xr(0,G),innerRatio:xr(1,P)}),ir=Ie.fn([Ge],ot),Il=ir.does(` - (in: VertexOutput) -> vec4f { - let position = in.positionOriginal; - let r = sin((position.x + position.y) * 10); - let g = sin(position.y * 10); - return vec4f(r / fwidth(r), g / fwidth(g), 1, 1); - } - `).$uses({VertexOutput:Ge}),Pl=ir.does(` - (in: VertexOutput) -> vec4f { - let checker = (floor(in.position.x / 16) + floor(in.position.y / 16)) % 2; - return vec4f(vec3f(checker), 1); - } - `).$uses({VertexOutput:Ge}),Fl=ir.does(` - (in: VertexOutput) -> vec4f { - let dist = length(in.positionOriginal); - let fade = smoothstep(0.05, 0.3, dist); - - let angle = atan2(in.positionOriginal.y, in.positionOriginal.x); - let wave = sin(angle * 17); - let waveflat = clamp(wave / fwidth(wave), 0, 1); - - let color = mix(vec3f(1, 1, 1), vec3f(1, 0, 0), waveflat); - return vec4f(color, fade); - } - `).$uses({VertexOutput:Ge}),zl=ir.does(` + }`).$uses({...sn.bound}).$name("camera2DClipToPixels");function Al(t){const{root:e}=Yr(),{canvasSize:n}=rr(),r=()=>1/t.fovy,i=e.createBuffer(Hi).$usage("uniform").$name("Camera2DUniforms"),d=sn.populate({camera2DUniforms:i}),m=de(()=>{const{position:A,fovy:P}=t,{x:k,y:F}=A,{width:z,height:B}=n(),V=z/B,L=fi();Au.ortho(k-V*P,k+V*P,F-P,F+P,0,0,L);const tt=en(L.columns[0].xyw,L.columns[1].xyw,L.columns[3].xyw),it=Eu.inverse(tt,en());return{viewMatrix:tt,viewMatrixInverse:it,resolution:q(z,B)}});function g({x:A,y:P}){return ku.transformMat3(tn(A,P,1),m().viewMatrixInverse,q())}function S(){i.write(m())}return Kt(_o,{value:{update:S,bindGroup:d,BindGroupLayout:sn,wgsl:{worldToClip:Ul,clipToWorld:Ol,clipToPixels:El},js:{clipToWorld:g},zoom:r},get children(){return t.children}})}function kl(t){const{canvas:e}=rr(),[n,r]=qt(1),[i,d]=qt(q());let m;function g(S){S.preventDefault();const A=pi(S),P=m?.(A);if(!P)return;const k=n(),F=k*(1-S.deltaY*.001),z=k/F;Ts(()=>{d(({x:B,y:V})=>q(B+(P.x-B)*(1-z),V+(P.y-V)*(1-z))),r(F)})}return Ae(()=>{e.addEventListener("wheel",g,{passive:!1}),on(()=>{e.removeEventListener("wheel",g)})}),Kt(Al,{get position(){return i()},get fovy(){return 1/n()},get children(){return[de(()=>(()=>{let{js:S}=kr();return m=S.clipToWorld,null})()),de(()=>t.children)]}})}function Il(t){Ae(()=>{let e=-1;function n(){pe(t),e=requestAnimationFrame(n)}on(()=>{cancelAnimationFrame(e)}),n()})}function Pl(t,...e){const n=[],r=[];for(let i=0;iBr(Ki,t)},color:{uniform:Xr},highlighted:{uniform:Qi}}),Bl=Me.fn([I,I,I],I).does(` + (edge0: f32, edge1: f32, x: f32) -> f32 { + return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); + }`),jl=Me.fn([Dr],et).does(` (in: VertexOutput) -> vec4f { const OUTER_RADIUS = 1.0; let dist = length(in.positionOriginal); let distWidth = fwidth(dist); // adding half a distWidth in order for circles to touch fully let disk = clamp((0.5*distWidth + OUTER_RADIUS - dist) / distWidth, 0, 1); - let fade = smoothstep(in.innerRatio, OUTER_RADIUS, dist); - return vec4f(vec3f(1-fade), disk * fade); + let fade = linearstep(in.innerRatio, OUTER_RADIUS, dist); + if in.vHighlighted != 0.0 { + return mix(highlighted.color_.fade, highlighted.color_.rim, fade * fade) * vec4f(1, 1, 1, disk * fade); + } else { + return mix(color.fade, color.rim, fade * fade) * vec4f(1, 1, 1, disk * fade); + }; } - `).$uses({VertexOutput:Ge}),Bl={frag1:Il,frag2:Pl,frag3:Fl,frag4:zl};function jl(t,...e){const n=[],r=[];for(let i=0;ijr(Ki,t)}});function Nl(t){const{wgsl:{worldToClip:e,clipToPixels:n},...r}=Ir(),{root:i,device:d}=Xr(),{context:m}=nr(),g=i.createBuffer(jr(Ki,Vl)).$usage("storage").$name("Circles");rn(()=>{g.write(t.circles)});const S=ve(()=>{const I=jl` - ${{VertexOutput:Ge,frag:t.frag,worldToClip:e,clipToPixels:n,...r.BindGroupLayout.bound,...lr.bound}} + `).$uses({VertexOutput:Dr,color:Qe.bound.color,highlighted:Qe.bound.highlighted,linearstep:Bl});function Rl(t){const{wgsl:{worldToClip:e,clipToPixels:n},...r}=kr(),{root:i,device:d}=Yr(),{context:m}=rr(),g=i.createBuffer(Br(Ki,zl)).$usage("storage").$name("circles");Ae(()=>{g.write(t.circles)});const S=i.createBuffer(Xr).$usage("uniform").$name("color");Ae(()=>{S.write(t.color??{rim:et(0,0,0,1),fade:et(0,0,0,1)})});const A=i.createBuffer(Qi).$usage("uniform").$name("highlighted");Ae(()=>{A.write(t.highlighted??{index:-1,color_:{rim:et(),fade:et()}})});const P=de(()=>{const F=Pl` + ${{VertexOutput:Dr,worldToClip:e,clipToPixels:n,frag:jl,...r.BindGroupLayout.bound,...Qe.bound}} const SUBDIVS = ${$s}; const WEDGE_ANGLE = radians(360.0) / SUBDIVS; @@ -82,6 +65,7 @@ ${m}`}if("l"in e||"c"in e){let[n,r]="l"in e?e.l:e.c,i=Nt(t,Tr(t,n)),d=r?Ht(t,r): out.position = vec4f(clip, 0, 1); out.positionOriginal = mix(vec2f(0,0), unitCircle, ratio); out.innerRatio = innerRatio; + out.vHighlighted = f32(instanceIndex == highlighted.index); return out; } @@ -89,4 +73,4 @@ ${m}`}if("l"in e||"c"in e){let[n,r]="l"in e?e.l:e.c,i=Nt(t,Tr(t,n)),d=r?Ht(t,r): let color = frag(in); return vec4f(color.rgb * color.a, color.a); } - `,k=d.createShaderModule({label:"our hardcoded red triangle shaders",code:I}),F=d.createRenderPipeline({label:"our hardcoded red triangle pipeline",primitive:{topology:"triangle-strip"},layout:d.createPipelineLayout({bindGroupLayouts:[i.unwrap(r.BindGroupLayout),i.unwrap(lr)]}),vertex:{entryPoint:"vs",module:k},fragment:{entryPoint:"fs",module:k,targets:[{format:navigator.gpu.getPreferredCanvasFormat(),blend:Rl}]}}),z=lr.populate({circles:g.buffer});return{pipeline:F,uniformBindGroup:z}});return kl(()=>{const{pipeline:I,uniformBindGroup:k}=S(),F=m.getCurrentTexture().createView();r.update();const z=d.createCommandEncoder(),B=z.beginRenderPass({label:"our basic canvas renderPass",colorAttachments:[{clearValue:t.clearColor??[1,1,1,1],loadOp:"clear",storeOp:"store",view:F}]});B.setPipeline(I),B.setBindGroup(0,i.unwrap(r.bindGroup)),B.setBindGroup(1,i.unwrap(k)),t.circles.length>0&&B.draw(($s+1)*2,t.circles.length),B.end();const N=z.finish();d.queue.submit([N])}),null}var Ll=Ar("

Apollonian Circles

Click to create, scroll to zoom."),Gl=Ar("
Number of Circles: ");function ql(){const{js:{clipToWorld:t},zoom:e}=Ir(),[n,r]=qt(),[i,d]=qt(),[m,g]=qt(),[S,A]=qt();async function I(z,B){for(;;){const N=pi(z),q=t(N),tt=Fu(q);r(tt),d(void 0),g(void 0),A(void 0);const st=zu(tt);if(await ur(tt,st.radius,st.curve,e,B),st.index===void 0)return;d(st.index);const ut=ju(st.index,tt);if(await ur(tt,ut.radius,ut.curve,e,B),ut.index===void 0)return;g(ut.index);const rt=Nu(st.index,ut.index,tt);if(await ur(tt,rt.radius,rt.curve,e,B),rt.index===void 0)return;A(rt.index);{const lt=ce[tt];if(ct.distance(lt.center,q){B.removeEventListener("pointerup",q)}),I(z,N)}return rn(()=>{k.addEventListener("pointerdown",F),sn(()=>{k.removeEventListener("pointerdown",F)})}),Kt(Nl,{circles:ce,get frag(){return Bl.frag4}})}function Wl(){return(()=>{var t=Gl(),e=t.firstChild;return e.firstChild,mn(e,()=>ce.length,null),mn(t,Kt(Er,{get when(){return ce.length===0},get children(){var n=Ll();return Ae(()=>yn(n,dn.welcomeMessage)),n}}),null),mn(t,Kt($l,{get children(){return Kt(Tl,{get class(){return dn.canvas},get children(){return Kt(Al,{get children(){return Kt(ql,{})}})}})}}),null),Ae(n=>{var r=dn.page,i=dn.circleCounter;return r!==n.e&&yn(t,n.e=r),i!==n.t&&yn(e,n.t=i),n},{e:void 0,t:void 0}),t})()}const Cl=document.getElementById("root");po(()=>Kt(Wl,{}),Cl); + `,z=d.createShaderModule({label:"our hardcoded red triangle shaders",code:F}),B=d.createRenderPipeline({label:"our hardcoded red triangle pipeline",primitive:{topology:"triangle-strip"},layout:d.createPipelineLayout({bindGroupLayouts:[i.unwrap(r.BindGroupLayout),i.unwrap(Qe)]}),vertex:{entryPoint:"vs",module:z},fragment:{entryPoint:"fs",module:z,targets:[{format:navigator.gpu.getPreferredCanvasFormat(),blend:Fl}]}}),V=Qe.populate({circles:g.buffer,color:S,highlighted:A});return{pipeline:B,uniformBindGroup:V}});return Il(()=>{const{pipeline:F,uniformBindGroup:z}=P(),B=m.getCurrentTexture().createView();r.update();const V=d.createCommandEncoder(),L=V.beginRenderPass({label:"our basic canvas renderPass",colorAttachments:[{clearValue:t.clearColor??[1,1,1,1],loadOp:"clear",storeOp:"store",view:B}]});L.setPipeline(F),L.setBindGroup(0,i.unwrap(r.bindGroup)),L.setBindGroup(1,i.unwrap(z)),t.circles.length>0&&L.draw(($s+1)*2,t.circles.length),L.end();const tt=V.finish();d.queue.submit([tt])}),null}var Nl=Er("

Apollonian Circles

Click to create, scroll to zoom."),Vl=Er("
Number of Circles: ");function Ll(){const{js:{clipToWorld:t},zoom:e}=kr(),[n,r]=qt(),[i,d]=qt(),[m,g]=qt(),[S,A]=qt();async function P(z,B){for(;;){const V=pi(z),L=t(V),tt=zu(L);r(tt),d(void 0),g(void 0),A(void 0);const it=Bu(tt);if(await ur(tt,it.radius,it.curve,e,B),it.index===void 0)return;d(it.index);const ut=Ru(it.index,tt);if(await ur(tt,ut.radius,ut.curve,e,B),ut.index===void 0)return;g(ut.index);const st=Lu(it.index,ut.index,tt);if(await ur(tt,st.radius,st.curve,e,B),st.index===void 0)return;A(st.index),r(void 0);{const lt=ce[tt];if(ct.distance(lt.center,L){B.removeEventListener("pointerup",L)}),P(z,V)}return Ae(()=>{k.addEventListener("pointerdown",F),on(()=>{k.removeEventListener("pointerdown",F)})}),Kt(Rl,{circles:ce,get highlighted(){return de(()=>!!n())()?{index:n(),color_:{rim:et(0,0,0,1),fade:et(.5,.8,1,1)}}:void 0}})}function Gl(){return(()=>{var t=Vl(),e=t.firstChild;return e.firstChild,gn(e,()=>ce.length,null),gn(t,Kt(Or,{get when(){return ce.length===0},get children(){var n=Nl();return Ie(()=>mn(n,pn.welcomeMessage)),n}}),null),gn(t,Kt(Sl,{get children(){return Kt(Dl,{get class(){return pn.canvas},get children(){return Kt(kl,{get children(){return Kt(Ll,{})}})}})}}),null),Ie(n=>{var r=pn.page,i=pn.circleCounter;return r!==n.e&&mn(t,n.e=r),i!==n.t&&mn(e,n.t=i),n},{e:void 0,t:void 0}),t})()}const ql=document.getElementById("root");wo(()=>Kt(Gl,{}),ql); diff --git a/docs/index.html b/docs/index.html index 1c43a5f..b16fb68 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,7 +6,7 @@ Solid App - + diff --git a/src/App.tsx b/src/App.tsx index fb11fb6..687cb1b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { createSignal, For } from 'solid-js' import ui from './App.module.css' -import { frags } from './frags' +import { frags } from './demo/frags' import { Root } from './lib/Root' import { AutoCanvas } from './lib/AutoCanvas' diff --git a/src/Test.tsx b/src/Test.tsx index da765c3..76a5417 100644 --- a/src/Test.tsx +++ b/src/Test.tsx @@ -1,6 +1,6 @@ import { createMemo } from 'solid-js' import { createAnimationFrame } from './utils/createAnimationFrame' -import { TestFrag, VertexOutput } from './frags' +import { TestFrag, VertexOutput } from './demo/frags' import { wgsl } from './utils/wgsl' import { struct, v2f, vec2f } from 'typegpu/data' import tgpu from 'typegpu/experimental' diff --git a/src/demo/App.tsx b/src/demo/App.tsx index 779b427..afe1cfe 100644 --- a/src/demo/App.tsx +++ b/src/demo/App.tsx @@ -8,10 +8,8 @@ import { closestFirstCircle, closestSecondCircle, closestThirdCircle, - debug, growUntilRadius, nextAnimationFrame, - setDebug, } from './state' import { useCanvas } from '@/lib/CanvasContext' import { createPromiseCallbacks } from '@/utils/createPromiseCallbacks' @@ -20,7 +18,7 @@ import { Root } from '@/lib/Root' import { AutoCanvas } from '@/lib/AutoCanvas' import { WheelZoomCamera2D } from './WheelZoomCamera2D' import { Circles } from '@/demo/Circles' -import { frags } from '@/frags' +import { vec4f } from 'typegpu/data' function Inside() { const { @@ -63,6 +61,7 @@ function Inside() { return } setThirdCircleIndex(third.index) + setSelectedCircleIndex(undefined) { const circle = circles[index]! @@ -100,7 +99,22 @@ function Inside() { }) }) - return + return ( + + ) } export function App() { diff --git a/src/demo/Circles.tsx b/src/demo/Circles.tsx index c853e99..46e5a11 100644 --- a/src/demo/Circles.tsx +++ b/src/demo/Circles.tsx @@ -1,30 +1,92 @@ import { createEffect, createMemo } from 'solid-js' import { createAnimationFrame } from '../utils/createAnimationFrame' -import { TestFrag, VertexOutput } from '../frags' import { wgsl } from '../utils/wgsl' -import { arrayOf, f32, struct, vec2f, Infer } from 'typegpu/data' +import { + arrayOf, + f32, + struct, + vec2f, + Infer, + vec4f, + u32, + builtin, + location, +} from 'typegpu/data' import tgpu from 'typegpu/experimental' import { useRootContext } from '../lib/RootContext' import { useCanvas } from '../lib/CanvasContext' import { premultipliedAlphaBlend } from '../utils/blendModes' import { useCamera } from '../lib/CameraContext' +const VertexOutput = struct({ + position: builtin.position, + positionOriginal: location(0, vec2f), + innerRatio: location(1, f32), + vHighlighted: location(2, f32), +}) + +type Circle = Infer const Circle = struct({ center: vec2f, radius: f32, }).$name('Circle') -type Circle = Infer + +type CircleColor = Infer +const CircleColor = struct({ + rim: vec4f, + fade: vec4f, +}) + +type HighlightedCircle = Infer +const HighlightedCircle = struct({ + index: u32, + color_: CircleColor, +}) const N = 10000 const SUBDIVS = 24 const uniformBindGroupLayout = tgpu.bindGroupLayout({ circles: { storage: (length) => arrayOf(Circle, length) }, + color: { uniform: CircleColor }, + highlighted: { uniform: HighlightedCircle }, }) +const linearstep = tgpu.fn([f32, f32, f32], f32).does(/* wgsl */ ` + (edge0: f32, edge1: f32, x: f32) -> f32 { + return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); + }`) + +const fadeFragmentShader = tgpu + .fn([VertexOutput], vec4f) + .does( + /* wgsl */ ` + (in: VertexOutput) -> vec4f { + const OUTER_RADIUS = 1.0; + let dist = length(in.positionOriginal); + let distWidth = fwidth(dist); + // adding half a distWidth in order for circles to touch fully + let disk = clamp((0.5*distWidth + OUTER_RADIUS - dist) / distWidth, 0, 1); + let fade = linearstep(in.innerRatio, OUTER_RADIUS, dist); + if in.vHighlighted != 0.0 { + return mix(highlighted.color_.fade, highlighted.color_.rim, fade * fade) * vec4f(1, 1, 1, disk * fade); + } else { + return mix(color.fade, color.rim, fade * fade) * vec4f(1, 1, 1, disk * fade); + }; + } + `, + ) + .$uses({ + VertexOutput, + color: uniformBindGroupLayout.bound.color, + highlighted: uniformBindGroupLayout.bound.highlighted, + linearstep, + }) + type CirclesProps = { - frag: TestFrag circles: Circle[] + highlighted?: HighlightedCircle + color?: CircleColor clearColor?: [number, number, number, number] } @@ -39,19 +101,47 @@ export function Circles(props: CirclesProps) { const circlesBuffer = root .createBuffer(arrayOf(Circle, N)) .$usage('storage') - .$name('Circles') + .$name('circles') createEffect(() => { circlesBuffer.write(props.circles) }) + const colorBuffer = root + .createBuffer(CircleColor) + .$usage('uniform') + .$name('color') + + createEffect(() => { + colorBuffer.write( + props.color ?? { + rim: vec4f(0, 0, 0, 1), + fade: vec4f(0, 0, 0, 1), + }, + ) + }) + + const highlightedBuffer = root + .createBuffer(HighlightedCircle) + .$usage('uniform') + .$name('highlighted') + + createEffect(() => { + highlightedBuffer.write( + props.highlighted ?? { + index: -1, + color_: { rim: vec4f(), fade: vec4f() }, + }, + ) + }) + const stuff = createMemo(() => { const shaderCode = wgsl/* wgsl */ ` ${{ VertexOutput, - frag: props.frag, worldToClip, clipToPixels, + frag: fadeFragmentShader, ...camera.BindGroupLayout.bound, ...uniformBindGroupLayout.bound, }} @@ -80,6 +170,7 @@ export function Circles(props: CirclesProps) { out.position = vec4f(clip, 0, 1); out.positionOriginal = mix(vec2f(0,0), unitCircle, ratio); out.innerRatio = innerRatio; + out.vHighlighted = f32(instanceIndex == highlighted.index); return out; } @@ -122,6 +213,8 @@ export function Circles(props: CirclesProps) { const uniformBindGroup = uniformBindGroupLayout.populate({ circles: circlesBuffer.buffer, + color: colorBuffer, + highlighted: highlightedBuffer, }) return { pipeline, uniformBindGroup } diff --git a/src/frags.ts b/src/demo/frags.ts similarity index 98% rename from src/frags.ts rename to src/demo/frags.ts index 568cc0c..0a973ce 100644 --- a/src/frags.ts +++ b/src/demo/frags.ts @@ -1,7 +1,7 @@ import tgpu from 'typegpu/experimental' import { struct, builtin, vec2f, vec4f, location, f32 } from 'typegpu/data' -export const VertexOutput = struct({ +const VertexOutput = struct({ position: builtin.position, positionOriginal: location(0, vec2f), innerRatio: location(1, f32), diff --git a/src/demo/state.ts b/src/demo/state.ts index f58d4f3..09c5c51 100644 --- a/src/demo/state.ts +++ b/src/demo/state.ts @@ -23,6 +23,11 @@ function vec2AddScaled2(a: v2f, b: v2f, bs: number, c: v2f, cs: number): v2f { return vec2f(a.x + b.x * bs + c.x * cs, a.y + b.y * bs + c.y * cs) } +// const { random } = Math +// const initialCircles: Circle[] = Array.from({ length: 5000 }).map(() => ({ +// center: vec2f(random() * 10 - 5, random() * 10 - 5), +// radius: random() * 0.05 + 0.05, +// })) export const [circles, setCircles] = createStore([]) export const [debug, setDebug] = createSignal(false) diff --git a/src/lib/Root.tsx b/src/lib/Root.tsx index 6a8f611..a46748f 100644 --- a/src/lib/Root.tsx +++ b/src/lib/Root.tsx @@ -20,6 +20,7 @@ export function Root(props: ParentProps) { `Failed to get GPUAdapter, make sure to use a browser with WebGPU support.`, ) } + console.info(`Using ${adapter.info.vendor} adapter.`) const device = await adapter?.requestDevice() if (!device) { throw new Error(