glre 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,40 +1,38 @@
1
- import{durable as ye,event as It}from"reev";import{createFrame as Ut,createQueue as Ft}from"refr";import{nested as be}from"reev";var l={arr:Array.isArray,bol:e=>typeof e=="boolean",str:e=>typeof e=="string",num:e=>typeof e=="number",int:e=>Number.isInteger(e),fun:e=>typeof e=="function",und:e=>typeof e>"u",nul:e=>e===null,set:e=>e instanceof Set,map:e=>e instanceof Map,obj:e=>!!e&&e.constructor.name==="Object",nan:e=>typeof e=="number"&&Number.isNaN(e)},Xt=(e,t)=>e.forEach(t),Vt=(e,...t)=>{Xt(e,r=>r(...t))},zt=(e="",t="_",r="/")=>e.split(t).join(r),kt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",qt=(e=0)=>`${e}`.split(".")[1]?.length??0,Yt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Ht=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var Z={bool:"bool",uint:"u32",int:"i32",float:"f32",bvec2:"vec2<bool>",ivec2:"vec2i",uvec2:"vec2u",vec2:"vec2f",bvec3:"vec3<bool>",ivec3:"vec3i",uvec3:"vec3u",vec3:"vec3f",bvec4:"vec4<bool>",ivec4:"vec4i",uvec4:"vec4u",vec4:"vec4f",color:"color",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",texture:"texture_2d<f32>",sampler2D:"sampler",struct:"struct"},O=Object.keys(Z),Q=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],J={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},Xe=Object.keys(J),ee=["dot","distance","length","lengthSq","determinant","luminance"],te=["all","any"],re=["abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth"],oe=["cross"],ne=["reflect","refract"],se=["min","max","mix","clamp","step","smoothstep"],ie=["texture","textureLod","textureSize","cubeTexture"],Tt=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],Te=[...ee,...te,...re,...oe,...ne,...se,...ie,...Tt],ae={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},_e={position:"vec4",vertex_index:"uint",instance_index:"uint",front_facing:"bool",frag_depth:"float",sample_index:"uint",sample_mask:"uint",point_coord:"vec2",positionLocal:"vec3",positionWorld:"vec3",positionView:"vec3",normalLocal:"vec3",normalWorld:"vec3",normalView:"vec3",screenCoordinate:"vec2",screenUV:"vec2",gl_FragCoord:"vec4",gl_VertexID:"uint",gl_InstanceID:"uint",gl_FrontFacing:"bool",gl_FragDepth:"float",gl_SampleID:"uint",gl_SampleMask:"uint",gl_PointCoord:"vec2",normal:"vec3",uv:"vec2",color:"vec4"},Ee=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],Ne=["and","or"],Ce={position:"gl_FragCoord",vertex_index:"gl_VertexID",instance_index:"gl_InstanceID",front_facing:"gl_FrontFacing",frag_depth:"gl_FragDepth",sample_index:"gl_SampleID",sample_mask:"gl_SampleMask",point_coord:"gl_PointCoord",uv:"gl_FragCoord.xy"};var Pe=e=>l.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),Se=e=>Xe.includes(e),Le=e=>Te.includes(e),we=e=>Q.includes(e),V=e=>!e||typeof e!="object"?!1:e.isProxy,ue=e=>l.str(e)?O.includes(e):!1,$e=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,n=(e&255)/255;return[t,r,n]},_t=0,L=()=>`i${_t++}`,w=(e,t)=>l.str(e)?t?.isWebGL?e:Z[e]||e:"",Ge=e=>J[e]||e,Re=e=>Ce[e],Oe=e=>{let t=Q.indexOf(e);return t!==-1?O[t]:"float"},pe=(e,t,r=!1,n=!1)=>e.isWebGL?r?o=>e.gl?.attribute?.(t,o):n?o=>e.gl?.texture?.(t,o):o=>e.gl?.uniform?.(t,o):r?o=>e.gl?._attribute?.(t,o):n?o=>e.gl?._texture?.(t,o):o=>e.gl?._uniform?.(t,o),ce=(e,t)=>{if(!e)return;if(!V(e))return t(e);if(e.type!=="conversion")return;let r=e.props.children?.slice(1).filter(Boolean);r?.length&&t(r)},Ie=e=>(e.code||(e.code={headers:new Map,fragInputs:new Map,vertInputs:new Map,vertOutputs:new Map,vertVaryings:new Map,dependencies:new Map},e.isWebGL||(e.code.fragInputs.set("position","@builtin(position) position: vec4f"),e.code.vertOutputs.set("position","@builtin(position) position: vec4f"))),e),z=(e,t="",r)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),ue(r)||e.code.dependencies.get(t).add(r)},Ue=(e,t)=>{let r=[],n=new Set,o=new Set,s=i=>{if(o.has(i)||n.has(i))return;o.add(i);let c=t.get(i)||new Set;for(let a of c)e.has(a)&&s(a);o.delete(i),n.add(i),e.has(i)&&r.push([i,e.get(i)])};for(let[i]of e)s(i);return r};var Et=(e,t)=>e.reduce((r,n)=>{let o=y(n,t),s=O.indexOf(r);return O.indexOf(o)>s?o:r},"float"),Nt=e=>_e[e],Ct=(e,t,r)=>{let n=t.length>0?y(t[0],r):"float";return ne.includes(e)?n:ee.includes(e)?"float":te.includes(e)?"bool":re.includes(e)?n:oe.includes(e)?"vec3":ie.includes(e)?"vec4":se.includes(e)?Et(t,r):n},Fe=(e,t,r)=>{if(Ee.includes(r)||Ne.includes(r))return"bool";if(e===t||e.includes("vec")&&!t.includes("vec"))return e;if(t.includes("vec")&&!e.includes("vec"))return t;let n=O.indexOf(e),o=O.indexOf(t);return n>=o?e:t},Pt=e=>l.bol(e)?"bool":l.str(e)?"texture":l.num(e)?Number.isInteger(e)?"int":"float":l.arr(e)&&ae[e.length]||"float",fe=e=>ae[e],St=(e,t)=>{if(e.length===0)return"void";let[r]=e;if(l.str(r))return r;let n=y(r,t);for(let o of e.slice(1))if(n!==y(o,t))throw new Error("glre node system error: defined scope return mismatch");return n},Lt=(e,t)=>{let{type:r,props:n}=e,{id:o,children:s=[],layout:i,inferFrom:c}=n,[a,p,g]=s;if(r==="conversion")return a;if(r==="operator")return Fe(y(p,t),y(g,t),a);if(r==="function")return Ct(a,s.slice(1),t);if(r==="ternary")return Fe(y(p,t),y(g,t),"add");if(r==="builtin")return Nt(o);if(r==="define"&&ue(i?.type))return i?.type;if(r==="attribute"&&l.arr(a)&&t.gl?.count)return fe(a.length/t.gl.count);if(r==="member"){if(Pe(a))return fe(a.length);if(V(p)&&l.str(a)){let C=p.props.fields?.[a];if(C)return y(C,t)}return"float"}return c?St(c,t):y(a,t)},y=(e,t)=>{if(t||(t={}),!V(e))return Pt(e);if(l.arr(e))return fe(e.length);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=Lt(e,t);return t.infers.set(e,r),r};var R=(e,t)=>e.filter(r=>!l.und(r)&&!l.nul(r)).map(r=>f(r,t)).join(", "),Ae=(e,t,r,n)=>{if(e.isWebGL)return`texture(${R(n?[t,r,n]:[t,r],e)})`;let o=f(t,e),s=[o,o+"Sampler",f(r,e)];return n?(s.push(f(n,e)),`textureSampleLevel(${s})`):`textureSample(${s})`},Be=(e,t,r,n)=>{let o=`if (${f(t,e)}) {
2
- ${f(r,e)}
3
- }`;for(let s=2;s<n.length;s+=2){let i=s>=n.length-1;o+=i?` else {
4
- ${f(n[s],e)}
5
- }`:` else if (${f(n[s],e)}) {
6
- ${f(n[s+1],e)}
7
- }`}return o},De=(e,t,r)=>{let n=`switch (${f(t,e)}) {
8
- `;for(let o=1;o<r.length;o+=2)o>=r.length-1&&r.length%2===0?n+=`default:
9
- ${f(r[o],e)}
1
+ import{durable as fe,event as Pt}from"reev";import{createFrame as $t,createQueue as wt}from"refr";import{nested as pe}from"reev";var d={arr:Array.isArray,bol:e=>typeof e=="boolean",str:e=>typeof e=="string",num:e=>typeof e=="number",int:e=>Number.isInteger(e),fun:e=>typeof e=="function",und:e=>typeof e>"u",nul:e=>e===null,set:e=>e instanceof Set,map:e=>e instanceof Map,obj:e=>!!e&&e.constructor.name==="Object",nan:e=>typeof e=="number"&&Number.isNaN(e)},xt=(e,t)=>e.forEach(t),Ot=(e,...t)=>{xt(e,r=>r(...t))},It=(e="",t="_",r="/")=>e.split(t).join(r),Ft=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Ut=(e=0)=>`${e}`.split(".")[1]?.length??0,At=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Bt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var j={bool:"bool",uint:"u32",int:"i32",float:"f32",bvec2:"vec2<bool>",ivec2:"vec2i",uvec2:"vec2u",vec2:"vec2f",bvec3:"vec3<bool>",ivec3:"vec3i",uvec3:"vec3u",vec3:"vec3f",bvec4:"vec4<bool>",ivec4:"vec4i",uvec4:"vec4u",vec4:"vec4f",color:"color",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",texture:"texture_2d<f32>",sampler2D:"sampler",struct:"struct"},K=Object.keys(j),Z=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],Q={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},le=Object.keys(Q),xe=["dot","distance","length","lengthSq","determinant","luminance","all","any","abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","sinh","cosh","tanh","asinh","acosh","atanh","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth","degrees","radians","cross","reflect","refract","min","max","mix","clamp","step","smoothstep","pow","atan2","texture","textureLod","textureSize","cubeTexture","faceforward","bitcast","cbrt","difference","equals","pow2","pow3","pow4","transformDirection"],J={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},me={texture:"vec4",cubeTexture:"vec4",textureSize:"vec4",length:"float",lengthSq:"float",distance:"float",dot:"float",all:"bool",any:"bool",cross:"vec3"},Te={position:"vec4",vertex_index:"uint",instance_index:"uint",front_facing:"bool",frag_depth:"float",sample_index:"uint",sample_mask:"uint",point_coord:"vec2",positionLocal:"vec3",positionWorld:"vec3",positionView:"vec3",normalLocal:"vec3",normalWorld:"vec3",normalView:"vec3",screenCoordinate:"vec2",screenUV:"vec2",gl_FragCoord:"vec4",gl_VertexID:"uint",gl_InstanceID:"uint",gl_FrontFacing:"bool",gl_FragDepth:"float",gl_SampleID:"uint",gl_SampleMask:"uint",gl_PointCoord:"vec2",normal:"vec3",uv:"vec2",color:"vec4"},ge=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],be=["and","or"],ve={position:"gl_FragCoord",vertex_index:"gl_VertexID",instance_index:"gl_InstanceID",front_facing:"gl_FrontFacing",frag_depth:"gl_FragDepth",sample_index:"gl_SampleID",sample_mask:"gl_SampleMask",point_coord:"gl_PointCoord",uv:"gl_FragCoord.xy"};var he=e=>d.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ye=e=>le.includes(e),Ce=e=>xe.includes(e),Xe=e=>Z.includes(e),M=e=>!e||typeof e!="object"?!1:e.isProxy,ee=e=>d.str(e)?K.includes(e):!1,_e=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,o=(e&255)/255;return[t,r,o]},mt=0,P=()=>`x${mt++}`,G=(e,t)=>d.str(e)?t?.isWebGL?e:j[e]||e:"",Ee=e=>Q[e]||e,Pe=e=>ve[e],$e=e=>{let t=Z.indexOf(e);return t!==-1?K[t]:"float"},te=(e,t,r=!1,o=!1)=>e.isWebGL?r?n=>e.gl?.attribute?.(t,n):o?n=>e.gl?.texture?.(t,n):n=>e.gl?.uniform?.(t,n):r?n=>e.gl?._attribute?.(t,n):o?n=>e.gl?._texture?.(t,n):n=>e.gl?._uniform?.(t,n),re=(e,t)=>{if(d.und(e))return;if(!M(e))return t(e);if(e.type!=="conversion")return;let r=e.props.children?.slice(1).filter(Boolean);r?.length&&t(r)},we=e=>(e.code||(e.code={headers:new Map,fragInputs:new Map,vertInputs:new Map,vertOutputs:new Map,vertVaryings:new Map,dependencies:new Map},e.isWebGL||(e.code.fragInputs.set("position","@builtin(position) position: vec4f"),e.code.vertOutputs.set("position","@builtin(position) position: vec4f"))),e),W=(e,t="",r)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),ee(r)||e.code.dependencies.get(t).add(r)},Ne=(e,t)=>{let r=[],o=new Set,n=new Set,s=a=>{if(n.has(a)||o.has(a))return;n.add(a);let c=t.get(a)||new Set;for(let i of c)e.has(i)&&s(i);n.delete(a),o.add(a),e.has(a)&&r.push([a,e.get(a)])};for(let[a]of e)s(a);return r};var Tt=e=>Te[e],Ge=(e,t,r)=>ge.includes(r)||be.includes(r)?"bool":e===t?e:e==="float"||e==="int"?t:t==="float"||t==="int"?e:e==="mat4"&&t==="vec4"||e==="mat3"&&t==="vec3"||e==="mat2"&&t==="vec2"?t:e,gt=e=>d.bol(e)?"bool":d.str(e)?"texture":d.num(e)?"float":d.arr(e)?J[e.length]:"float",ne=e=>J[e],bt=(e,t)=>{if(e.length===0)return"void";let[r]=e;if(d.str(r))return r;let o=h(r,t);for(let n of e.slice(1))if(o!==h(n,t))throw new Error("glre node system error: defined scope return mismatch");return o},vt=e=>me[e],ht=(e,t)=>{let{type:r,props:o}=e,{id:n,children:s=[],inferFrom:a,layout:c}=o,[i,f,l]=s;if(r==="conversion")return i;if(r==="operator")return Ge(h(f,t),h(l,t),i);if(r==="ternary")return Ge(h(f,t),h(l,t),"add");if(r==="builtin")return Tt(n);if(r==="function")return vt(i)||h(f,t);if(r==="define"&&ee(c?.type))return c?.type;if(r==="attribute"&&d.arr(i)&&t.gl?.count)return ne(i.length/t.gl.count);if(r==="member"){if(he(i))return ne(i.length);if(M(f)&&d.str(i)){let _=f.props.fields?.[i];if(_)return h(_,t)}return"float"}return a?bt(a,t):h(i,t)},h=(e,t)=>{if(t||(t={}),!M(e))return gt(e);if(d.arr(e))return ne(e.length);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=ht(e,t);return t.infers.set(e,r),r};var R=(e,t)=>e.filter(r=>!d.und(r)&&!d.nul(r)).map(r=>p(r,t)).join(", "),Le=(e,t,r,o)=>{if(e.isWebGL)return`texture(${R(o?[t,r,o]:[t,r],e)})`;let n=p(t,e),s=[n,n+"Sampler",p(r,e)];return o?(s.push(p(o,e)),`textureSampleLevel(${s})`):`textureSample(${s})`},Se=(e,t,r,o)=>{let n=`if (${p(t,e)}) {
2
+ ${p(r,e)}
3
+ }`;for(let s=2;s<o.length;s+=2){let a=s>=o.length-1;n+=a?` else {
4
+ ${p(o[s],e)}
5
+ }`:` else if (${p(o[s],e)}) {
6
+ ${p(o[s+1],e)}
7
+ }`}return n},Re=(e,t,r)=>{let o=`switch (${p(t,e)}) {
8
+ `;for(let n=1;n<r.length;n+=2)n>=r.length-1&&r.length%2===0?o+=`default:
9
+ ${p(r[n],e)}
10
10
  break;
11
- `:o+1<r.length&&(n+=`case ${f(r[o],e)}:
12
- ${f(r[o+1],e)}
11
+ `:n+1<r.length&&(o+=`case ${p(r[n],e)}:
12
+ ${p(r[n+1],e)}
13
13
  break;
14
- `);return n+="}",n},Me=(e,t,r)=>{let n=y(t,e),o=r?.props?.id;if(e.isWebGL)return`${n} ${o} = ${f(t,e)};`;let s=w(n);return`var ${o}: ${s} = ${f(t,e)};`},We=(e,t,r)=>{let{id:n,children:o=[],layout:s}=t,[i,...c]=o,a=[],p=[];if(s?.inputs)for(let v of s.inputs)a.push([v.name,v.type]);else for(let v=0;v<c.length;v++)a.push([`p${v}`,y(c[v],e)]);let g=[];if(e?.isWebGL){for(let[v,m]of a)z(e,n,m),p.push(`${m} ${v}`);z(e,n,r),g.push(`${r} ${n}(${p}) {`)}else{for(let[v,m]of a)p.push(`${v}: ${w(m,e)}`);g.push(`fn ${n}(${p}) -> ${w(r,e)} {`)}let C=f(i,e);return C&&g.push(C),g.push("}"),g.join(`
15
- `)},Ve=(e,t,r={})=>{let n=[];for(let s in r){let i=r[s],c=y(i,e);e.isWebGL&&z(e,t,c),n.push(e.isWebGL?`${c} ${s};`:`${s}: ${w(c,e)},`)}let o=n.join(`
14
+ `);return o+="}",o},Oe=(e,t,r)=>{let o=h(t,e),n=r?.props?.id;if(e.isWebGL)return`${o} ${n} = ${p(t,e)};`;let s=G(o);return`var ${n}: ${s} = ${p(t,e)};`},Ie=(e,t,r={})=>{let o=[];for(let s in r){let a=r[s],c=h(a,e);e.isWebGL&&W(e,t,c),o.push(e.isWebGL?`${c} ${s};`:`${s}: ${G(c,e)},`)}let n=o.join(`
16
15
  `);return`struct ${t} {
17
- ${o}
18
- };`},ze=(e,t,r="",n,o)=>{if(e.isWebGL)if(o){let s=[];for(let i in n)s.push(o[i]);return`${t} ${r} = ${t}(${R(s,e)});`}else return`${t} ${r};`;else if(o){let s=[];for(let i in n)s.push(o[i]);return`var ${r}: ${t} = ${t}(${R(s,e)});`}else return`var ${r}: ${t};`},ke=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${w(r,e)}`,qe=(e,t,r)=>{let n=r==="sampler2D"||r==="texture";if(e.isWebGL)return n?`uniform sampler2D ${t};`:`uniform ${r} ${t};`;if(n){let{group:c=1,binding:a=0}=e.gl?.webgpu?.textures.map.get(t)||{};return`@group(${c}) @binding(${a}) var ${t}Sampler: sampler;
19
- @group(${c}) @binding(${a+1}) var ${t}: texture_2d<f32>;`}let{group:o=0,binding:s=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},i=w(r,e);return`@group(${o}) @binding(${s}) var<uniform> ${t}: ${i};`},Ye=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:n=0}=e.gl?.webgpu?.attribs.map.get(t)||{},o=w(r,e);return`@location(${n}) ${t}: ${o}`},He=(e,t,r,n)=>e.isWebGL?`const ${r} ${t} = ${n};`:`const ${t}: ${w(r,e)} = ${n};`;var f=(e,t)=>{if(t||(t={}),Ie(t),l.arr(e))return R(e,t);if(l.str(e))return e;if(l.num(e)){let m=`${e}`;return m.includes(".")?m:m+".0"}if(l.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[],fields:i,initialValues:c}=n,[a,p,g,C]=s;if(r==="variable")return o;if(r==="member")return`${f(p,t)}.${f(a,t)}`;if(r==="ternary")return t.isWebGL?`(${f(a,t)} ? ${f(p,t)} : ${f(g,t)})`:`select(${f(g,t)}, ${f(p,t)}, ${f(a,t)})`;if(r==="conversion")return`${w(a,t)}(${R(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${f(p,t)}`:`(${f(p,t)} ${Ge(a)} ${f(g,t)})`;if(r==="function")return a==="negate"?`(-${R(s.slice(1),t)})`:a==="texture"?Ae(t,p,g,C):`${a}(${R(s.slice(1),t)})`;if(r==="scope")return s.map(m=>f(m,t)).join(`
20
- `);if(r==="assign")return`${f(a,t)} = ${f(p,t)};`;if(r==="return")return`return ${f(a,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${a}; i += 1) {
21
- ${f(p,t)}
22
- }`:`for (var i: i32 = 0; i < ${a}; i++) {
23
- ${f(p,t)}
24
- }`;if(r==="if")return Be(t,a,p,s);if(r==="switch")return De(t,a,s);if(r==="declare")return Me(t,a,p);if(r==="define")return t.code?.headers.has(o)||t.code?.headers.set(o,We(t,n,y(e,t))),`${o}(${R(s.slice(1),t)})`;if(r==="struct")return t.code?.headers.has(o)||t.code?.headers.set(o,Ve(t,o,i)),ze(t,o,a.props.id,i,c);if(r==="varying"){if(t.code?.vertOutputs.has(o))return t.isWebGL?`${o}`:`out.${o}`;let m=ke(t,o,y(e,t));return t.code?.fragInputs.set(o,m),t.code?.vertOutputs.set(o,m),t.code?.vertVaryings.set(o,f(a,t)),t.isWebGL?`${o}`:`out.${o}`}if(r==="builtin"){if(t.isWebGL)return Re(o);if(o==="position")return"out.position";let m=`@builtin(${o}) ${o}: ${w(y(e,t),t)}`;return t.isFrag?t.code?.fragInputs.set(o,m):t.code?.vertInputs.set(o,m),`in.${o}`}if(r==="attribute"){let m=pe(t,o,!0);return ce(a,m),e.listeners.add(m),t.code?.vertInputs.set(o,Ye(t,o,y(e,t))),t.isWebGL?`${o}`:`in.${o}`}if(t.code?.headers.has(o))return o;let v="";if(r==="uniform"){let m=y(e,t),D=pe(t,o,!1,m==="texture");ce(a,D),e.listeners.add(D),v=qe(t,o,m)}return r==="constant"&&(v=He(t,o,y(e,t),f(a,t))),v?(t.code?.headers.set(o,v),o):f(a,t)};var I=null,B=null,F=e=>{if(!I||(I.props.children||(I.props.children=[]),I.props.children.push(e),e.type!=="return"||!B))return;let{props:t}=B;t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e)},je=(e,t)=>{t||(t=L());let r=d("variable",{id:t,inferFrom:[e]}),n=d("declare",null,e,r);return F(n),r},Ke=(e,t)=>{let r=d("assign",null,e,t);return F(r),e},wt=e=>{let t=d("return",{inferFrom:[e]},e);return F(t),t},vr=(e,t=L())=>(r={},n=L())=>{let o=d("variable",{id:n,inferFrom:[t]}),s=d("struct",{id:t,fields:e,initialValues:r},o);return F(s),o},U=(e,t,r=B)=>{let n=I,o=B;I=e,B=r,n&&(e.props.parent=n);let s=t();s&&wt(s),I=n,B=o},yr=(e,t)=>{let r=d("scope");U(r,t);let n=d("if",null,e,r);F(n);let o=()=>({ElseIf:(s,i)=>{let c=d("scope");return U(c,i),n.props.children.push(s,c),o()},Else:s=>{let i=d("scope");U(i,s),n.props.children.push(i)}});return o()},hr=(e,t)=>{let r=d("scope");U(r,()=>t({i:d("variable",{id:"i",inferFrom:[A(0)]})}));let n=d("loop",null,e,r);return F(n),n},Xr=e=>{let t=d("switch",null,e);F(t);let r=()=>({Case:(...n)=>o=>{let s=d("scope");U(s,o);for(let i of n)t.props.children.push(i,s);return r()},Default:n=>{let o=d("scope");U(o,n),t.props.children.push(o)}});return r()},Tr=e=>{let t,r=(...n)=>{let o=t?.name||L(),s=d("scope"),i=[],c=[];if(t?.inputs)for(let p of t.inputs)c.push({id:p.name,inferFrom:[x(p.type)]});else for(let p=0;p<n.length;p++)c.push({id:`p${p}`,inferFrom:[n[p]]});for(let p of c)i.push(d("variable",p));let a=d("define",{id:o,layout:t},s,...n);return U(s,()=>e(i),a),a};return r.setLayout=n=>void(t=n),r};var $t=(e,t)=>{if(t==="string")return f(e)},d=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let n=new Set,o=(c,a)=>{if(a==="type")return e;if(a==="props")return t;if(a==="toVar")return je.bind(null,i);if(a==="assign")return Ke.bind(null,i);if(a==="isProxy")return!0;if(a==="toString")return f.bind(null,i);if(a===Symbol.toPrimitive)return $t.bind(null,i);if(a==="listeners")return n;if(Se(a))return(...p)=>Gt(a,i,...p);if(Le(a))return(...p)=>u(a,i,...p);if(we(a))return()=>x(Oe(a),i);if(l.str(a))return Ze(a,i)},s=(c,a,p)=>(a==="value"&&n.forEach(g=>g(p)),l.str(a)&&Ze(a,i).assign(p),!0),i=new Proxy({},{get:o,set:s});return i},Sr=(e,t=L())=>d("attribute",{id:t},e),Lr=(e,t=L())=>d("constant",{id:t},e),k=(e,t=L())=>d("uniform",{id:t},e),wr=(e=L())=>d("variable",{id:e}),T=(e=L())=>d("builtin",{id:e}),$r=(e,t=L())=>d("varying",{id:t,inferFrom:[e]},e),Gt=(e,...t)=>d("operator",null,e,...t),u=(e,...t)=>d("function",null,e,...t),x=(e,...t)=>d("conversion",null,e,...t),Ze=(e,t)=>d("member",null,e,t),Gr=(e,t,r)=>d("ternary",null,e,t,r);var Rt=`
16
+ ${n}
17
+ };`},Fe=(e,t,r="",o,n)=>{if(e.isWebGL)if(n){let s=[];for(let a in o)s.push(n[a]);return`${t} ${r} = ${t}(${R(s,e)});`}else return`${t} ${r};`;else if(n){let s=[];for(let a in o)s.push(n[a]);return`var ${r}: ${t} = ${t}(${R(s,e)});`}else return`var ${r}: ${t};`},Ue=(e,t,r)=>{let{id:o,children:n=[],layout:s}=t,[a,...c]=n,i=[],f=[];if(s?.inputs)for(let v of s.inputs)i.push([v.name,v.type]);else for(let v=0;v<c.length;v++)i.push([`p${v}`,h(c[v],e)]);let l=[];if(e?.isWebGL){for(let[v,g]of i)W(e,o,g),f.push(`${g} ${v}`);W(e,o,r),l.push(`${r} ${o}(${f}) {`)}else{for(let[v,g]of i)f.push(`${v}: ${G(g,e)}`);l.push(`fn ${o}(${f}) -> ${G(r,e)} {`)}let _=p(a,e);return _&&l.push(_),l.push("}"),l.join(`
18
+ `)},Ae=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${G(r,e)}`,Be=(e,t,r)=>{let o=r==="sampler2D"||r==="texture";if(e.isWebGL)return o?`uniform sampler2D ${t};`:`uniform ${r} ${t};`;if(o){let{group:c=1,binding:i=0}=e.gl?.webgpu?.textures.map.get(t)||{};return`@group(${c}) @binding(${i}) var ${t}Sampler: sampler;
19
+ @group(${c}) @binding(${i+1}) var ${t}: texture_2d<f32>;`}let{group:n=0,binding:s=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},a=G(r,e);return`@group(${n}) @binding(${s}) var<uniform> ${t}: ${a};`},De=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:o=0}=e.gl?.webgpu?.attribs.map.get(t)||{},n=G(r,e);return`@location(${o}) ${t}: ${n}`},Me=(e,t,r,o)=>e.isWebGL?`const ${r} ${t} = ${o};`:`const ${t}: ${G(r,e)} = ${o};`;var p=(e,t)=>{if(t||(t={}),we(t),d.arr(e))return R(e,t);if(d.str(e))return e;if(d.num(e)){let g=`${e}`;return g.includes(".")?g:g+".0"}if(d.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:o}=e,{id:n="i",children:s=[],fields:a,initialValues:c}=o,[i,f,l,_]=s;if(r==="variable")return n;if(r==="member")return`${p(f,t)}.${p(i,t)}`;if(r==="ternary")return t.isWebGL?`(${p(l,t)} ? ${p(i,t)} : ${p(f,t)})`:`select(${p(i,t)}, ${p(f,t)}, ${p(l,t)})`;if(r==="conversion")return`${G(i,t)}(${R(s.slice(1),t)})`;if(r==="operator")return i==="not"||i==="bitNot"?`!${p(f,t)}`:`(${p(f,t)} ${Ee(i)} ${p(l,t)})`;if(r==="function")return i==="negate"?`(-${p(f,t)})`:i==="oneMinus"?`(1.0-${p(f,t)})`:i==="texture"?Le(t,f,l,_):i==="atan2"&&t.isWebGL?`atan(${p(f,t)}, ${p(l,t)})`:`${i}(${R(s.slice(1),t)})`;if(r==="scope")return s.map(g=>p(g,t)).join(`
20
+ `);if(r==="assign")return`${p(i,t)} = ${p(f,t)};`;if(r==="return")return`return ${p(i,t)};`;if(r==="loop")return t.isWebGL?`for (int ${n} = 0; ${n} < ${p(i,t)}; ${n} += 1) {
21
+ ${p(f,t)}
22
+ }`:`for (var ${n}: i32 = 0; ${n} < ${p(i,t)}; ${n}++) {
23
+ ${p(f,t)}
24
+ }`;if(r==="if")return Se(t,i,f,s);if(r==="switch")return Re(t,i,s);if(r==="declare")return Oe(t,i,f);if(r==="define")return t.code?.headers.has(n)||t.code?.headers.set(n,Ue(t,o,h(e,t))),`${n}(${R(s.slice(1),t)})`;if(r==="struct")return t.code?.headers.has(n)||t.code?.headers.set(n,Ie(t,n,a)),Fe(t,n,i.props.id,a,c);if(r==="varying"){if(t.code?.vertOutputs.has(n))return t.isWebGL?`${n}`:`out.${n}`;let g=Ae(t,n,h(e,t));return t.code?.fragInputs.set(n,g),t.code?.vertOutputs.set(n,g),t.code?.vertVaryings.set(n,p(i,t)),t.isWebGL?`${n}`:`out.${n}`}if(r==="builtin"){if(t.isWebGL)return Pe(n);if(n==="position")return"out.position";let g=`@builtin(${n}) ${n}: ${G(h(e,t),t)}`;return t.isFrag?t.code?.fragInputs.set(n,g):t.code?.vertInputs.set(n,g),`in.${n}`}if(r==="attribute"){let g=te(t,n,!0);return re(i,g),e.listeners.add(g),t.code?.vertInputs.set(n,De(t,n,h(e,t))),t.isWebGL?`${n}`:`in.${n}`}if(t.code?.headers.has(n))return n;let v="";if(r==="uniform"){let g=h(e,t),A=te(t,n,!1,g==="texture");re(i,A),e.listeners.add(A),v=Be(t,n,g)}return r==="constant"&&(v=Me(t,n,h(e,t),p(i,t))),v?(t.code?.headers.set(n,v),n):p(i,t)};var O=null,U=null,F=e=>{if(!O||(O.props.children||(O.props.children=[]),O.props.children.push(e),e.type!=="return"||!U))return;let{props:t}=U;t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e)},We=(e,t)=>{t||(t=P());let r=x("variable",{id:t,inferFrom:[e]}),o=x("declare",null,e,r);return F(o),r},Ve=(e,t)=>{let r=x("assign",null,e,t);return F(r),e},yt=e=>{let t=x("return",{inferFrom:[e]},e);return F(t),t},ar=(e,t=P())=>(r={},o=P())=>{let n=x("variable",{id:o,inferFrom:[t]}),s=x("struct",{id:t,fields:e,initialValues:r},n);return F(s),n},I=(e,t,r=U)=>{let o=O,n=U;O=e,U=r,o&&(e.props.parent=o);let s=t();s&&yt(s),O=o,U=n},ur=(e,t)=>{let r=x("scope");I(r,t);let o=x("if",null,e,r);F(o);let n=()=>({ElseIf:(s,a)=>{let c=x("scope");return I(c,a),o.props.children.push(s,c),n()},Else:s=>{let a=x("scope");I(a,s),o.props.children.push(a)}});return n()},pr=(e,t)=>{let r=x("scope"),o=P();I(r,()=>t({i:x("variable",{id:o,inferFrom:[T("int",0)]})}));let n=x("loop",{id:o},e,r);return F(n),n},cr=e=>{let t=x("switch",null,e);F(t);let r=()=>({Case:(...o)=>n=>{let s=x("scope");I(s,n);for(let a of o)t.props.children.push(a,s);return r()},Default:o=>{let n=x("scope");I(n,o),t.props.children.push(n)}});return r()},fr=(e,t=P())=>{let r,o=(...n)=>{let s=r?.name||t,a=x("scope"),c=[],i=[];if(r?.inputs)for(let l of r.inputs)i.push({id:l.name,inferFrom:[T(l.type)]});else for(let l=0;l<n.length;l++)i.push({id:`p${l}`,inferFrom:[n[l]]});for(let l of i)c.push(x("variable",l));let f=x("define",{id:s,layout:r},a,...n);return I(a,()=>e(c),f),f};return o.setLayout=n=>(r=n,o),o};var Ct=(e,t)=>{if(t==="string")return p(e)},x=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=new Set,n=(c,i)=>{if(i==="type")return e;if(i==="props")return t;if(i==="toVar")return We.bind(null,a);if(i==="assign")return Ve.bind(null,a);if(i==="isProxy")return!0;if(i==="toString")return p.bind(null,a);if(i===Symbol.toPrimitive)return Ct.bind(null,a);if(i==="listeners")return o;if(ye(i))return(...f)=>Xt(i,a,...f);if(Ce(i))return(...f)=>u(i,a,...f);if(Xe(i))return()=>T($e(i),a);if(d.str(i))return ze(i,a)},s=(c,i,f)=>(i==="value"&&o.forEach(l=>l(f)),d.str(i)&&ze(i,a).assign(f),!0),a=new Proxy({},{get:n,set:s});return a},gr=(e,t=P())=>x("attribute",{id:t},e),br=(e,t=P())=>x("constant",{id:t},e),V=(e,t=P())=>x("uniform",{id:t},e),vr=(e=P())=>x("variable",{id:e}),C=(e=P())=>x("builtin",{id:e}),hr=(e,t=P())=>x("varying",{id:t,inferFrom:[e]},e),ze=(e,t)=>x("member",null,e,t),yr=(e,t,r)=>x("ternary",null,e,t,r),Xt=(e,...t)=>x("operator",null,e,...t),u=(e,...t)=>x("function",null,e,...t),T=(e,...t)=>x("conversion",null,e,...t);var _t=`
25
25
  #version 300 es
26
26
  precision mediump float;
27
27
  out vec4 fragColor;
28
- `.trim(),Je=(e,t)=>{let r=f(e,t),n="";return t.isWebGL&&t.code?.dependencies?n=Ue(t.code.headers,t.code.dependencies).map(([,s])=>s).join(`
29
- `):n=Array.from(t.code?.headers?.values()||[]).join(`
30
- `),[n,r]},le=(e,t)=>`struct ${e} {
28
+ `.trim(),qe=(e,t)=>{let r=p(e,t),o="";return t.isWebGL&&t.code?.dependencies?o=Ne(t.code.headers,t.code.dependencies).map(([,s])=>s).join(`
29
+ `):o=Array.from(t.code?.headers?.values()||[]).join(`
30
+ `),[o,r]},oe=(e,t)=>`struct ${e} {
31
31
  ${Array.from(t.values()).join(`,
32
32
  `)}
33
- }`,q=(e,t)=>{if(l.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!1;let[r,n]=Je(e,t),o=[];if(t.isWebGL){o.push("#version 300 es");for(let i of t.code?.vertInputs?.values()||[])o.push(`in ${i}`);for(let i of t.code?.vertOutputs?.values()||[])o.push(`out ${i}`);o.push(r),o.push("void main() {"),o.push(` gl_Position = ${n};`);for(let[i,c]of t.code?.vertVaryings?.entries()||[])o.push(` ${i} = ${c};`)}else{t.code?.vertInputs?.size&&o.push(le("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&o.push(le("Out",t.code.vertOutputs)),o.push(r),o.push("@vertex"),o.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),o.push(" var out: Out;"),o.push(` out.position = ${n};`);for(let[i,c]of t.code?.vertVaryings?.entries()||[])o.push(` out.${i} = ${c};`);o.push(" return out;")}o.push("}");let s=o.filter(Boolean).join(`
34
- `).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
35
- ${s}`),s},Y=(e,t)=>{if(l.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!0;let[r,n]=Je(e,t),o=[];if(t.isWebGL){o.push(Rt);for(let i of t.code?.fragInputs?.values()||[])o.push(`in ${i}`);o.push(r),o.push(`void main() {
36
- fragColor = ${n};`)}else t.code?.fragInputs?.size&&o.push(le("Out",t.code.fragInputs)),o.push(r),o.push(`@fragment
37
- fn main(out: Out) -> @location(0) vec4f {`),o.push(` return ${n};`);o.push("}");let s=o.filter(Boolean).join(`
38
- `).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
39
- ${s}`),s},de=T("position"),me=T("vertex_index"),Ar=T("instance_index"),Br=T("front_facing"),Dr=T("frag_depth"),Mr=T("sample_index"),Wr=T("sample_mask"),Vr=T("point_coord"),zr=T("normalLocal"),kr=T("normalWorld"),qr=T("normalView"),Yr=T("position"),Hr=T("positionWorld"),jr=T("positionView"),Kr=T("screenCoordinate"),Zr=T("screenUV"),H=e=>x("float",e),A=e=>x("int",e),Qr=e=>x("uint",e),Jr=e=>x("bool",e),et=(e,t)=>x("vec2",e,t),Qe=(e,t,r)=>x("vec3",e,t,r),xe=(e,t,r,n)=>x("vec4",e,t,r,n),eo=(...e)=>x("mat2",...e),to=(...e)=>x("mat3",...e),ro=(...e)=>x("mat4",...e),oo=(e,t)=>x("ivec2",e,t),no=(e,t,r)=>x("ivec3",e,t,r),so=(e,t,r,n)=>x("ivec4",e,t,r,n),io=(e,t)=>x("uvec2",e,t),ao=(e,t,r)=>x("uvec3",e,t,r),uo=(e,t,r,n)=>x("uvec4",e,t,r,n),po=(e,t)=>x("bvec2",e,t),co=(e,t,r)=>x("bvec3",e,t,r),fo=(e,t,r,n)=>x("bvec4",e,t,r,n),lo=e=>x("texture",e),mo=()=>x("sampler2D"),xo=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Qe(...$e(e)):Qe(e,t,r),ge=k(et(),"iResolution"),go=k(et(),"iMouse"),bo=k(H(),"iTime"),vo=()=>de.xy.div(ge),yo=(e,t,r)=>u("texture",e,t,r),ho=(e,t,r)=>u("cubeTexture",e,t,r),Xo=(e,t)=>u("textureSize",e,t),To=e=>u("abs",e),_o=e=>u("acos",e),Eo=e=>u("all",e),No=e=>u("any",e),Co=e=>u("asin",e),Po=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),So=(e,t)=>u("atan",e,t),Lo=(e,t)=>u("bitcast",e,t),wo=e=>u("cbrt",e),$o=e=>u("ceil",e),Go=(e,t,r)=>u("clamp",e,t,r),Ro=e=>u("cos",e),Oo=(e,t)=>u("cross",e,t),Io=e=>u("dFdx",e),Uo=e=>u("dFdy",e),Fo=e=>u("degrees",e),Ao=(e,t)=>u("difference",e,t),Bo=(e,t)=>u("distance",e,t),Do=(e,t)=>u("dot",e,t),Mo=(e,t)=>u("equals",e,t),Wo=e=>u("exp",e),Vo=e=>u("exp2",e),zo=(e,t,r)=>u("faceforward",e,t,r),ko=e=>u("floor",e),tt=e=>u("fract",e),qo=e=>u("fwidth",e),Yo=e=>u("inverseSqrt",e),Ho=e=>u("length",e),jo=e=>u("lengthSq",e),Ko=e=>u("log",e),Zo=e=>u("log2",e),Qo=(e,t)=>u("max",e,t),Jo=(e,t)=>u("min",e,t),en=(e,t,r)=>u("mix",e,t,r),tn=e=>u("negate",e),rn=e=>u("normalize",e),on=e=>u("oneMinus",e),nn=(e,t)=>u("pow",e,t),sn=e=>u("pow2",e),an=e=>u("pow3",e),un=e=>u("pow4",e),pn=e=>u("radians",e),cn=e=>u("reciprocal",e),fn=(e,t)=>u("reflect",e,t),ln=(e,t,r)=>u("refract",e,t,r),dn=e=>u("round",e),mn=e=>u("saturate",e),xn=e=>u("sign",e),gn=e=>u("sin",e),bn=(e,t,r)=>u("smoothstep",e,t,r),vn=e=>u("sqrt",e),yn=(e,t)=>u("step",e,t),hn=e=>u("tan",e),Xn=(e,t)=>u("transformDirection",e,t),Tn=e=>u("trunc",e);var rt=(e,t,r)=>{let n=e.createShader(r);if(!n)throw new Error("Failed to create shader");if(e.shaderSource(n,t.trim()),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;let o=e.getShaderInfoLog(n);e.deleteShader(n),console.warn(`Could not compile shader: ${o}`)},ot=(e,t,r,n=()=>{})=>{let o=e.createProgram(),s=rt(e,r,e.FRAGMENT_SHADER),i=rt(e,t,e.VERTEX_SHADER);if(!s||!i)return n();if(e.attachShader(o,i),e.attachShader(o,s),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let c=e.getProgramInfoLog(o);e.deleteProgram(o),n(),console.warn(`Could not link program: ${c}`)},nt=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array(t),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),r},st=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(t),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r},it=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},at=(e,t,r,n,o)=>{e.bindBuffer(e.ARRAY_BUFFER,n),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,t,e.FLOAT,!1,0,0),o&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,o)},ut=(e,t,r,n)=>{let o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),e.uniform1i(r,n),e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_2D,o)};var pt=async e=>{let t=e.el.getContext("webgl2"),r={isWebGL:!0,gl:e},n=Y(e.fs,r),o=q(e.vs,r),s=ot(t,o,n,()=>void(e.isLoop=!1));t.useProgram(s);let i=0,c=be(P=>t.getUniformLocation(s,P)),a=be(P=>t.getAttribLocation(s,P)),p=be(()=>i++);return{render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(s),_attribute:(P="",E,S)=>{let $=a(P,!0),M=nt(t,E),j=st(t,S),h=it(e.count,E,S);at(t,h,$,M,j)},_uniform:(P,E)=>{let S=c(P);if(l.num(E))return t.uniform1f(S,E);let $=E.length;if($<=4)return t[`uniform${$}fv`](S,E);$=Math.sqrt($)<<0,t[`uniformMatrix${$}fv`](S,!1,E)},_texture:(P,E)=>{let S=new Image;Object.assign(S,{src:E,crossOrigin:"anonymous"}),S.decode().then(()=>{let $=c(P),M=p(P);ut(t,S,$,M)})},webgl:{context:t,program:s}}};import{nested as ve}from"reev";var ct=async e=>{let t=navigator.gpu,r=t.getPreferredCanvasFormat(),o=await(await t.requestAdapter()).requestDevice();return e.configure({device:o,format:r,alphaMode:"opaque"}),{device:o,format:r}},ft=()=>{let e=0,t=0,r=0;return{uniform:()=>{let n=Math.floor(e/12),o=e%12;return e++,{group:n,binding:o}},texture:()=>{let o=Math.floor(e/12)+1+Math.floor(t/6),s=t%6*2;return t++,{group:o,binding:s}},attrib:()=>{let n=r;return r++,{location:n}}}},Ot=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",lt=e=>{let t=[],r=[];for(let{buffer:n,location:o,stride:s}of e)t[o]=n,r[o]={arrayStride:s*4,attributes:[{shaderLocation:o,offset:0,format:Ot(s)}]};return{vertexBuffers:t,bufferLayouts:r}},dt=(e,t,r)=>{let n=new Map,o={bindGroups:[],bindGroupLayouts:[]},s=(i,c,a)=>{n.has(i)||n.set(i,{layouts:[],bindings:[]});let{layouts:p,bindings:g}=n.get(i);p.push(c),g.push(a)};for(let{binding:i,buffer:c,group:a}of t)s(a,{binding:i,visibility:3,buffer:{type:"uniform"}},{binding:i,resource:{buffer:c}});for(let{binding:i,group:c,sampler:a,view:p}of r)s(c,{binding:i,visibility:2,sampler:{}},{binding:i,resource:a}),s(c,{binding:i+1,visibility:2,texture:{}},{binding:i+1,resource:p});for(let[i,{layouts:c,bindings:a}]of n)o.bindGroupLayouts[i]=e.createBindGroupLayout({entries:c}),o.bindGroups[i]=e.createBindGroup({layout:o.bindGroupLayouts[i],entries:a});return o},mt=(e,t,r,n,o,s)=>e.createRenderPipeline({vertex:{module:e.createShaderModule({label:"vert",code:o}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({label:"frag",code:s}),entryPoint:"main",targets:[{format:t}]},layout:e.createPipelineLayout({bindGroupLayouts:n}),primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}}),xt=(e,t)=>{let r=new Float32Array(t),n=Math.ceil(r.byteLength/256)*256,o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},gt=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},bt=(e,t)=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:t.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}}),vt=(e,t=1280,r=800)=>{let n=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),o=e.createSampler({magFilter:"linear",minFilter:"linear"});return{texture:n,sampler:o}},yt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT});var ht=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await ct(t),o=ft(),s,i,c=h=>{},a=0,p=!0,g,C=ve((h,b)=>{p=!0;let{array:X,buffer:_}=xt(r,b),{binding:G,group:N}=o.uniform();return{binding:G,group:N,array:X,buffer:_}}),v=ve((h,b=0,X=0)=>{p=!0;let{texture:_,sampler:G}=vt(r,b,X),{binding:N,group:W}=o.texture();return{binding:N,group:W,texture:_,sampler:G,view:_.createView()}}),m=ve((h,b)=>{p=!0;let X=b.length/e.count,{location:_}=o.attrib(),{array:G,buffer:N}=gt(r,b);return{array:G,buffer:N,location:_,stride:X}}),D=()=>{let{vertexBuffers:h,bufferLayouts:b}=lt(m.map.values()),{bindGroups:X,bindGroupLayouts:_}=dt(r,C.map.values(),v.map.values()),G=mt(r,n,b,_,i,s);c=N=>{N.setPipeline(G),X.forEach((W,K)=>N.setBindGroup(K,W)),h.forEach((W,K)=>N.setVertexBuffer(K,W)),N.draw(e.count,1,0,0),N.end()}},P=()=>{if(!s||!i){let b={isWebGL:!1,gl:e};s=Y(e.fs,b),i=q(e.vs,b)}if(a)return;p&&D(),p=!1;let h=r.createCommandEncoder();c(h.beginRenderPass(bt(t,g))),r.queue.submit([h.finish()])},E=()=>{let h=e.el;g?.destroy(),g=yt(r,h.width,h.height)},S=()=>{g?.destroy()},$=(h="",b)=>{let{array:X,buffer:_}=m(h,b);X.set(b),r.queue.writeBuffer(_,0,X)},M=(h,b)=>{l.num(b)&&(b=[b]);let{array:X,buffer:_}=C(h,b);X.set(b),r.queue.writeBuffer(_,0,X)},j=(h,b)=>{a++;let X=Object.assign(new Image,{src:b,crossOrigin:"anonymous"});X.decode().then(()=>{let{width:_,height:G}=X,{texture:N}=v(h,_,G);r.queue.copyExternalImageToTexture({source:X},{texture:N},{width:_,height:G}),a--})};return E(),{webgpu:{device:r,uniforms:C,textures:v,attribs:m},render:P,resize:E,clean:S,_attribute:$,_uniform:M,_texture:j}};var Yn=e=>l.obj(e)?"isGL"in e:!1,At=()=>typeof window>"u",Bt=()=>At()?!1:"gpu"in navigator,he=performance.now(),Dt=()=>xe(tt(de.xy.div(ge)),0,1),Mt=()=>xe(H(A(me).mod(A(2))).mul(4).sub(1),H(A(me).div(A(2))).mul(4).sub(1),0,1),Wt=e=>{let t=It({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Ft(),t.frame=Ut(),t.attribute=ye((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o)),t),t.uniform=ye((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o)),t),t.texture=ye((r,n)=>t.queue(()=>t._texture?.(r,n)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:he}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||Mt(),t.fs=t.fs||t.frag||t.fragment||Dt(),Bt()||(t.isWebGL=!0),t.isWebGL?t(await pt(t)):t(await ht(t)),t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.render(),t.isLoop)),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove))}),t("clean",()=>{t.frame.stop(),t.frame.clean(t.render),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,n=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=n,t.uniform("iResolution",t.size)}),t("mousemove",(r,n=r.clientX,o=r.clientY)=>{let[s,i]=t.size,{top:c,left:a}=t.el.getBoundingClientRect();t.mouse[0]=(n-c-s/2)/(s/2),t.mouse[1]=-(o-a-i/2)/(i/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{he=performance.now()/1e3,t.uniform("iTime",he)}),t(e)},Hn=Wt;export{Tr as Fn,yr as If,hr as Loop,wt as Return,Xr as Switch,To as abs,_o as acos,z as addDependency,Eo as all,No as any,Co as asin,Ke as assign,Po as atan,So as atan2,Sr as attribute,Lo as bitcast,Jr as bool,T as builtin,po as bvec2,co as bvec3,fo as bvec4,wo as cbrt,$o as ceil,Go as clamp,f as code,xo as color,Lr as constant,x as conversion,Oe as conversionToConstant,Ro as cos,at as createAttrib,gt as createAttribBuffer,dt as createBindGroup,ft as createBindings,yt as createDepthTexture,bt as createDescriptor,ct as createDevice,Wt as createGL,st as createIbo,mt as createPipeline,ot as createProgram,ut as createTexture,vt as createTextureSampler,xt as createUniformBuffer,nt as createVbo,lt as createVertexBuffers,Oo as cross,ho as cubeTexture,Io as dFdx,Uo as dFdy,Hn as default,Fo as degrees,Ao as difference,Yt as dig,Bo as distance,Do as dot,Xt as each,Mo as equals,Wo as exp,Vo as exp2,kt as ext,zo as faceforward,qt as fig,H as float,ko as floor,Vt as flush,w as formatConversions,tt as fract,Dr as fragDepth,Y as fragment,Br as frontFacing,u as function_,qo as fwidth,Re as getBluiltin,pe as getEventFun,L as getId,Ge as getOperator,it as getStride,$e as hex2rgb,go as iMouse,ge as iResolution,bo as iTime,Ie as initNodeContext,Ar as instanceIndex,A as int,Yo as inverseSqrt,l as is,ue as isConstants,we as isConversion,Le as isFunction,Yn as isGL,V as isNodeProxy,Se as isOperator,At as isServer,Pe as isSwizzle,Bt as isWebGPUSupported,oo as ivec2,no as ivec3,so as ivec4,Ho as length,jo as lengthSq,Ko as log,Zo as log2,eo as mat2,to as mat3,ro as mat4,Qo as max,Ze as member,Jo as min,en as mix,tn as negate,d as node,zr as normalLocal,qr as normalView,kr as normalWorld,rn as normalize,on as oneMinus,Gt as operator,Vr as pointCoord,de as position,Yr as positionLocal,jr as positionView,Hr as positionWorld,nn as pow,sn as pow2,an as pow3,un as pow4,pn as radians,cn as reciprocal,fn as reflect,ln as refract,zt as replace,dn as round,ce as safeEventCall,Mr as sampleIndex,Wr as sampleMask,mo as sampler2D,mn as saturate,Kr as screenCoordinate,Zr as screenUV,Gr as select,Ht as sig,xn as sign,gn as sin,bn as smoothstep,Ue as sortHeadersByDependencies,vn as sqrt,yn as step,vr as struct,hn as tan,yo as texture,lo as texture2D,Xo as textureSize,je as toVar,Xn as transformDirection,Tn as trunc,Qr as uint,k as uniform,vo as uv,io as uvec2,ao as uvec3,uo as uvec4,wr as variable,et as vec2,Qe as vec3,xe as vec4,q as vertex,me as vertexIndex,$r as vertexStage,pt as webgl,ht as webgpu};
33
+ }`,z=(e,t)=>{if(d.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!1;let[r,o]=qe(e,t),n=[];if(t.isWebGL){n.push("#version 300 es");for(let a of t.code?.vertInputs?.values()||[])n.push(`in ${a}`);for(let a of t.code?.vertOutputs?.values()||[])n.push(`out ${a}`);n.push(r),n.push("void main() {"),n.push(` gl_Position = ${o};`);for(let[a,c]of t.code?.vertVaryings?.entries()||[])n.push(` ${a} = ${c};`)}else{t.code?.vertInputs?.size&&n.push(oe("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&n.push(oe("Out",t.code.vertOutputs)),n.push(r),n.push("@vertex"),n.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),n.push(" var out: Out;"),n.push(` out.position = ${o};`);for(let[a,c]of t.code?.vertVaryings?.entries()||[])n.push(` out.${a} = ${c};`);n.push(" return out;")}return n.push("}"),n.filter(Boolean).join(`
34
+ `).trim()},k=(e,t)=>{if(d.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!0;let[r,o]=qe(e,t),n=[];if(t.isWebGL){n.push(_t);for(let a of t.code?.fragInputs?.values()||[])n.push(`in ${a}`);n.push(r),n.push(`void main() {
35
+ fragColor = ${o};`)}else t.code?.fragInputs?.size&&n.push(oe("Out",t.code.fragInputs)),n.push(r),n.push(`@fragment
36
+ fn main(out: Out) -> @location(0) vec4f {`),n.push(` return ${o};`);return n.push("}"),n.filter(Boolean).join(`
37
+ `).trim()},se=C("position"),ie=C("vertex_index"),$r=C("instance_index"),wr=C("front_facing"),Nr=C("frag_depth"),Gr=C("sample_index"),Lr=C("sample_mask"),Sr=C("point_coord"),Rr=C("position"),Or=C("positionWorld"),Ir=C("positionView"),Fr=C("normalLocal"),Ur=C("normalWorld"),Ar=C("normalView"),Br=C("screenCoordinate"),Dr=C("screenUV"),q=e=>T("float",e),D=e=>T("int",e),Mr=e=>T("uint",e),Wr=e=>T("bool",e),Ye=(e,t)=>T("vec2",e,t),ke=(e,t,r)=>T("vec3",e,t,r),ae=(e,t,r,o)=>T("vec4",e,t,r,o),Vr=(...e)=>T("mat2",...e),zr=(...e)=>T("mat3",...e),kr=(...e)=>T("mat4",...e),qr=(e,t)=>T("ivec2",e,t),Yr=(e,t,r)=>T("ivec3",e,t,r),Hr=(e,t,r,o)=>T("ivec4",e,t,r,o),jr=(e,t)=>T("uvec2",e,t),Kr=(e,t,r)=>T("uvec3",e,t,r),Zr=(e,t,r,o)=>T("uvec4",e,t,r,o),Qr=(e,t)=>T("bvec2",e,t),Jr=(e,t,r)=>T("bvec3",e,t,r),en=(e,t,r,o)=>T("bvec4",e,t,r,o),tn=e=>T("texture",e),rn=()=>T("sampler2D"),nn=(e,t,r)=>d.num(e)&&d.und(t)&&d.und(r)?ke(..._e(e)):ke(e,t,r),ue=V(Ye(),"iResolution"),on=V(Ye(),"iMouse"),sn=V(q(),"iTime"),an=se.xy.div(ue),un=(e,t,r)=>u("texture",e,t,r),pn=(e,t,r)=>u("cubeTexture",e,t,r),cn=(e,t)=>u("textureSize",e,t),fn=e=>u("length",e),dn=e=>u("lengthSq",e),ln=(e,t)=>u("distance",e,t),xn=(e,t)=>u("dot",e,t),mn=e=>u("all",e),Tn=e=>u("any",e),gn=(e,t)=>u("cross",e,t),bn=e=>u("abs",e),vn=e=>u("sign",e),hn=e=>u("floor",e),yn=e=>u("ceil",e),Cn=e=>u("round",e),He=e=>u("fract",e),Xn=e=>u("trunc",e),_n=e=>u("sin",e),En=e=>u("cos",e),Pn=e=>u("tan",e),$n=e=>u("asin",e),wn=e=>u("acos",e),Nn=e=>u("atan",e),Gn=e=>u("sinh",e),Ln=e=>u("cosh",e),Sn=e=>u("tanh",e),Rn=e=>u("asinh",e),On=e=>u("acosh",e),In=e=>u("atanh",e),Fn=e=>u("exp",e),Un=e=>u("exp2",e),An=e=>u("log",e),Bn=e=>u("log2",e),Dn=e=>u("sqrt",e),Mn=e=>u("inverseSqrt",e),Wn=e=>u("normalize",e),Vn=e=>u("oneMinus",e),zn=e=>u("saturate",e),kn=e=>u("negate",e),qn=e=>u("reciprocal",e),Yn=e=>u("dFdx",e),Hn=e=>u("dFdy",e),jn=e=>u("fwidth",e),Kn=e=>u("degrees",e),Zn=e=>u("radians",e),Qn=(e,t)=>u("reflect",e,t),Jn=(e,t,r)=>u("refract",e,t,r),eo=(e,t)=>u("min",e,t),to=(e,t)=>u("max",e,t),ro=(e,t,r)=>u("mix",e,t,r),no=(e,t,r)=>u("clamp",e,t,r),oo=(e,t)=>u("step",e,t),so=(e,t,r)=>u("smoothstep",e,t,r),io=(e,t)=>u("atan2",e,t),ao=(e,t)=>u("pow",e,t),uo=e=>u("pow2",e),po=e=>u("pow3",e),co=e=>u("pow4",e),fo=(e,t)=>u("bitcast",e,t),lo=e=>u("cbrt",e),xo=(e,t)=>u("difference",e,t),mo=(e,t)=>u("equals",e,t),To=(e,t,r)=>u("faceforward",e,t,r),go=(e,t)=>u("transformDirection",e,t),bo=(e,t)=>e.sub(e.div(t).floor().mul(t));var je=(e,t,r,o=console.warn)=>{let n=e.createShader(r);if(!n)return o("Failed to create shader");if(e.shaderSource(n,t.trim()),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;let s=e.getShaderInfoLog(n);e.deleteShader(n),o(`Could not compile shader: ${s}`)},Ke=(e,t,r,o=console.warn)=>{let n=e.createProgram(),s=je(e,r,e.FRAGMENT_SHADER,o),a=je(e,t,e.VERTEX_SHADER,o);if(!s||!a)return;if(e.attachShader(n,a),e.attachShader(n,s),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let c=e.getProgramInfoLog(n);e.deleteProgram(n),o(`Could not link program: ${c}`)},Ze=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array(t),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),r},Qe=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(t),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r},Je=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},et=(e,t,r,o,n)=>{e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,t,e.FLOAT,!1,0,0),n&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n)},tt=(e,t,r,o)=>{let n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),e.uniform1i(r,o),e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,n)};var rt=async e=>{let t=e.el.getContext("webgl2"),r={isWebGL:!0,gl:e},o=k(e.fs,r),n=z(e.vs,r),s=Ke(t,n,o,e.error);t.useProgram(s);let a=0,c=pe($=>t.getUniformLocation(s,$)),i=pe($=>t.getAttribLocation(s,$)),f=pe(()=>a++);return{webgl:{context:t,program:s},render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>{t.deleteProgram(s),t.getExtension("WEBGL_lose_context")?.loseContext(),e.el.width=1,e.el.height=1},_attribute:($="",w,N)=>{let L=i($,!0),m=Ze(t,w),b=Qe(t,N),y=Je(e.count,w,N);et(t,y,L,m,b)},_uniform:($,w)=>{let N=c($);if(d.num(w))return t.uniform1f(N,w);let L=w.length;if(L<=4)return t[`uniform${L}fv`](N,w);L=Math.sqrt(L)<<0,t[`uniformMatrix${L}fv`](N,!1,w)},_texture:($,w)=>{e.loading++;let N=new Image;Object.assign(N,{src:w,crossOrigin:"anonymous"}),N.decode().then(()=>{let L=c($),m=f($);tt(t,N,L,m),e.loading--})}}};import{nested as ce}from"reev";var nt=async e=>{let t=navigator.gpu,r=t.getPreferredCanvasFormat(),n=await(await t.requestAdapter()).requestDevice();return e.configure({device:n,format:r,alphaMode:"opaque"}),{device:n,format:r}},ot=()=>{let e=0,t=0,r=0;return{uniform:()=>{let o=Math.floor(e/12),n=e%12;return e++,{group:o,binding:n}},texture:()=>{let n=Math.floor(e/12)+1+Math.floor(t/6),s=t%6*2;return t++,{group:n,binding:s}},attrib:()=>{let o=r;return r++,{location:o}}}},Et=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",st=e=>{let t=[],r=[];for(let{buffer:o,location:n,stride:s}of e)t[n]=o,r[n]={arrayStride:s*4,attributes:[{shaderLocation:n,offset:0,format:Et(s)}]};return{vertexBuffers:t,bufferLayouts:r}},it=(e,t,r)=>{let o=new Map,n={bindGroups:[],bindGroupLayouts:[]},s=(a,c,i)=>{o.has(a)||o.set(a,{layouts:[],bindings:[]});let{layouts:f,bindings:l}=o.get(a);f.push(c),l.push(i)};for(let{binding:a,buffer:c,group:i}of t)s(i,{binding:a,visibility:3,buffer:{type:"uniform"}},{binding:a,resource:{buffer:c}});for(let{binding:a,group:c,sampler:i,view:f}of r)s(c,{binding:a,visibility:2,sampler:{}},{binding:a,resource:i}),s(c,{binding:a+1,visibility:2,texture:{}},{binding:a+1,resource:f});for(let[a,{layouts:c,bindings:i}]of o)n.bindGroupLayouts[a]=e.createBindGroupLayout({entries:c}),n.bindGroups[a]=e.createBindGroup({layout:n.bindGroupLayouts[a],entries:i});return n},at=(e,t,r,o,n,s)=>e.createRenderPipeline({vertex:{module:e.createShaderModule({label:"vert",code:n}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({label:"frag",code:s}),entryPoint:"main",targets:[{format:t}]},layout:e.createPipelineLayout({bindGroupLayouts:o}),primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}}),ut=(e,t)=>{let r=new Float32Array(t),o=Math.ceil(r.byteLength/256)*256,n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},pt=(e,t)=>{let r=new Float32Array(t),o=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:o}},ct=(e,t)=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:t.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}}),ft=(e,t=1280,r=800)=>{let o=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),n=e.createSampler({magFilter:"linear",minFilter:"linear"});return{texture:o,sampler:n}},dt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT});var lt=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await nt(t);r.onuncapturederror=m=>e.error(m.error.message);let n=ot(),s,a,c=m=>{},i=!0,f,l=ce((m,b)=>{i=!0;let{array:y,buffer:X}=ut(r,b),{binding:S,group:E}=n.uniform();return{binding:S,group:E,array:y,buffer:X}}),_=ce((m,b=0,y=0)=>{i=!0;let{texture:X,sampler:S}=ft(r,b,y),{binding:E,group:B}=n.texture();return{binding:E,group:B,texture:X,sampler:S,view:X.createView()}}),v=ce((m,b)=>{i=!0;let y=b.length/e.count,{location:X}=n.attrib(),{array:S,buffer:E}=pt(r,b);return{array:S,buffer:E,location:X,stride:y}}),g=()=>{let{vertexBuffers:m,bufferLayouts:b}=st(v.map.values()),{bindGroups:y,bindGroupLayouts:X}=it(r,l.map.values(),_.map.values()),S=at(r,o,b,X,a,s);c=E=>{E.setPipeline(S),y.forEach((B,H)=>E.setBindGroup(H,B)),m.forEach((B,H)=>E.setVertexBuffer(H,B)),E.draw(e.count,1,0,0),E.end()}},A=()=>{if(!s||!a){let b={isWebGL:!1,gl:e};s=k(e.fs,b),a=z(e.vs,b)}if(e.loading)return;i&&g(),i=!1;let m=r.createCommandEncoder();c(m.beginRenderPass(ct(t,f))),r.queue.submit([m.finish()])},Y=()=>{let m=e.el;f?.destroy(),f=dt(r,m.width,m.height)},$=()=>{r.destroy(),f?.destroy();for(let{texture:m}of _.map.values())m.destroy();for(let{buffer:m}of l.map.values())m.destroy();for(let{buffer:m}of v.map.values())m.destroy()},w=(m="",b)=>{let{array:y,buffer:X}=v(m,b);y.set(b),r.queue.writeBuffer(X,0,y)},N=(m,b)=>{d.num(b)&&(b=[b]);let{array:y,buffer:X}=l(m,b);y.set(b),r.queue.writeBuffer(X,0,y)},L=(m,b)=>{e.loading++;let y=Object.assign(new Image,{src:b,crossOrigin:"anonymous"});y.decode().then(()=>{let{width:X,height:S}=y,{texture:E}=_(m,X,S);r.queue.copyExternalImageToTexture({source:y},{texture:E},{width:X,height:S}),e.loading--})};return Y(),{webgpu:{device:r,uniforms:l,textures:_,attribs:v},render:A,resize:Y,clean:$,_attribute:w,_uniform:N,_texture:L}};var Vo=e=>d.obj(e)?"isGL"in e:!1,Nt=()=>typeof window>"u",Gt=()=>Nt()?!1:"gpu"in navigator,de=performance.now(),Lt=()=>ae(He(se.xy.div(ue)),0,1),St=()=>ae(q(D(ie).mod(D(2))).mul(4).sub(1),q(D(ie).div(D(2))).mul(4).sub(1),0,1),Rt=e=>{let t=Pt({isNative:!1,isWebGL:!0,isError:!1,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{},loading:0,error(){t.isError=!0,t.isLoop=!1,t.clean()}});return t.queue=wt(),t.frame=$t(),t.attribute=fe((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n)),t),t.uniform=fe((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n)),t),t.texture=fe((r,o)=>t.queue(()=>t._texture?.(r,o)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:de}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||St(),t.fs=t.fs||t.frag||t.fragment||Lt(),Gt()||(t.isWebGL=!0),t.isWebGL?t(await rt(t)):t(await lt(t)),!t.isError&&(t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.loading?!0:(t.render(),t.isLoop))),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove)))}),t("clean",()=>{t.frame.stop(),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,o=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=o,t.uniform("iResolution",t.size)}),t("mousemove",(r,o=r.clientX,n=r.clientY)=>{let[s,a]=t.size,{top:c,left:i}=t.el.getBoundingClientRect();t.mouse[0]=(o-c-s/2)/(s/2),t.mouse[1]=-(n-i-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{de=performance.now()/1e3,t.uniform("iTime",de)}),t(e)},zo=Rt;export{fr as Fn,ur as If,pr as Loop,yt as Return,cr as Switch,bn as abs,wn as acos,On as acosh,W as addDependency,mn as all,Tn as any,$n as asin,Rn as asinh,Ve as assign,Nn as atan,io as atan2,In as atanh,gr as attribute,fo as bitcast,Wr as bool,C as builtin,Qr as bvec2,Jr as bvec3,en as bvec4,lo as cbrt,yn as ceil,no as clamp,p as code,nn as color,br as constant,T as conversion,$e as conversionToConstant,En as cos,Ln as cosh,et as createAttrib,pt as createAttribBuffer,it as createBindGroup,ot as createBindings,dt as createDepthTexture,ct as createDescriptor,nt as createDevice,Rt as createGL,Qe as createIbo,at as createPipeline,Ke as createProgram,tt as createTexture,ft as createTextureSampler,ut as createUniformBuffer,Ze as createVbo,st as createVertexBuffers,gn as cross,pn as cubeTexture,Yn as dFdx,Hn as dFdy,zo as default,Kn as degrees,xo as difference,At as dig,ln as distance,xn as dot,xt as each,mo as equals,Fn as exp,Un as exp2,Ft as ext,To as faceforward,Ut as fig,q as float,hn as floor,Ot as flush,G as formatConversions,He as fract,Nr as fragDepth,k as fragment,wr as frontFacing,u as function_,jn as fwidth,Pe as getBluiltin,te as getEventFun,P as getId,Ee as getOperator,Je as getStride,_e as hex2rgb,on as iMouse,ue as iResolution,sn as iTime,we as initNodeContext,$r as instanceIndex,D as int,Mn as inverseSqrt,d as is,ee as isConstants,Xe as isConversion,Ce as isFunction,Vo as isGL,M as isNodeProxy,ye as isOperator,Nt as isServer,he as isSwizzle,Gt as isWebGPUSupported,qr as ivec2,Yr as ivec3,Hr as ivec4,fn as length,dn as lengthSq,An as log,Bn as log2,Vr as mat2,zr as mat3,kr as mat4,to as max,ze as member,eo as min,ro as mix,bo as mod,kn as negate,x as node,Fr as normalLocal,Ar as normalView,Ur as normalWorld,Wn as normalize,Vn as oneMinus,Xt as operator,Sr as pointCoord,se as position,Rr as positionLocal,Ir as positionView,Or as positionWorld,ao as pow,uo as pow2,po as pow3,co as pow4,Zn as radians,qn as reciprocal,Qn as reflect,Jn as refract,It as replace,Cn as round,re as safeEventCall,Gr as sampleIndex,Lr as sampleMask,rn as sampler2D,zn as saturate,Br as screenCoordinate,Dr as screenUV,yr as select,Bt as sig,vn as sign,_n as sin,Gn as sinh,so as smoothstep,Ne as sortHeadersByDependencies,Dn as sqrt,oo as step,ar as struct,Pn as tan,Sn as tanh,un as texture,tn as texture2D,cn as textureSize,We as toVar,go as transformDirection,Xn as trunc,Mr as uint,V as uniform,an as uv,jr as uvec2,Kr as uvec3,Zr as uvec4,vr as variable,Ye as vec2,ke as vec3,ae as vec4,z as vertex,ie as vertexIndex,hr as vertexStage,rt as webgl,lt as webgpu};
40
38
  //# sourceMappingURL=index.js.map