glre 0.29.0 → 0.30.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,50 +1,50 @@
1
- import{durable as Z,event as nt}from"reev";import{createFrame as st,createQueue as it}from"refr";import{nested as K}from"reev";var g={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)},Be=(e,t)=>e.forEach(t),pt=(e,...t)=>{Be(e,r=>r(...t))},ft=(e="",t="_",r="/")=>e.split(t).join(r),lt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",mt=(e=0)=>`${e}`.split(".")[1]?.length??0,dt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),xt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var bt=["x","y","z","w","r","g","b","a","s","t","p","q"],L=["bool","uint","int","float","bvec2","bvec3","bvec4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","vec2","vec3","vec4","color","mat2","mat3","mat4"],J=["toFloat","toInt","toUint","toBool","toVec2","toVec3","toVec4","toIvec2","toIvec3","toIvec4","toUvec2","toUvec3","toUvec4","toBvec2","toBvec3","toBvec4","toMat2","toMat3","toMat4","toColor"],$={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},ee=Object.keys($),B=["dot","distance","length","lengthSq","determinant","luminance"],M=["all","any"],V=["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"],D=["cross"],z=["reflect","refract"],W=["min","max","mix","clamp","step","smoothstep"],q=["texture","textureLod","textureSize","cubeTexture"],Me=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],te=[...B,...M,...V,...D,...z,...W,...q,...Me],re={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",ivec2:"vec2i",ivec3:"vec3i",ivec4:"vec4i",uvec2:"vec2u",uvec3:"vec3u",uvec4:"vec4u",bvec2:"vec2<bool>",bvec3:"vec3<bool>",bvec4:"vec4<bool>"},k={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},oe={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"},ne=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],se=["and","or"],ie={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"};var Y=e=>g.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ae=e=>ee.includes(e),ue=e=>te.includes(e),ce=e=>J.includes(e),S=e=>!e||typeof e!="object"?!1:e.isProxy,Ve=0,pe=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,n=(e&255)/255;return[t,r,n]},I=()=>`i${Ve++}`,U=(e,t)=>e.filter(r=>!g.und(r)&&!g.nul(r)).map(r=>p(r,t)).join(", "),C=(e,t)=>g.str(e)?t?.isWebGL?e:re[e]:"",fe=e=>$[e]||e,le=e=>Array.from(e.headers).map(([,t])=>t).join(`
2
- `),me=(e,t)=>{let{id:r,children:n=[]}=e,[o,s,...u]=n,a=s?_(s,t):"void",m=u.map((h,T)=>[`p${T}`,_(h,t)]),y=[p(o,t)];if(s&&y.push(`return ${p(s,t)};`),t?.isWebGL){let h=m.map(([T,E])=>`${E} ${T}`);return`${a} ${r}(${h}) {
3
- ${y.join(`
4
- `)}
5
- }`}let f=C(a,t),d=m.map(([h,T])=>`${h}: ${C(T,t)}`);return`fn ${r}(${d}) -> ${f} {
6
- ${y.join(`
7
- `)}
8
- }`},de=(e,t,r=!0)=>r?`
1
+ import{durable as H,event as at}from"reev";import{createFrame as ut,createQueue as ct}from"refr";import{nested as Y}from"reev";var g={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)},$e=(e,t)=>e.forEach(t),mt=(e,...t)=>{$e(e,r=>r(...t))},dt=(e="",t="_",r="/")=>e.split(t).join(r),xt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",gt=(e=0)=>`${e}`.split(".")[1]?.length??0,bt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),vt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var S=["bool","uint","int","float","bvec2","ivec2","uvec2","vec2","bvec3","ivec3","uvec3","vec3","bvec4","ivec4","uvec4","vec4","color","mat2","mat3","mat4"],U=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],A={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},Z=Object.keys(A),$=["dot","distance","length","lengthSq","determinant","luminance"],B=["all","any"],D=["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"],M=["cross"],V=["reflect","refract"],z=["min","max","mix","clamp","step","smoothstep"],W=["texture","textureLod","textureSize","cubeTexture"],Be=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],Q=[...$,...B,...D,...M,...V,...z,...W,...Be],J={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",ivec2:"vec2i",ivec3:"vec3i",ivec4:"vec4i",uvec2:"vec2u",uvec3:"vec3u",uvec4:"vec4u",bvec2:"vec2<bool>",bvec3:"vec3<bool>",bvec4:"vec4<bool>"},q={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},ee={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"},te=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],re=["and","or"],oe={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 k=e=>g.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ne=e=>Z.includes(e),se=e=>Q.includes(e),ie=e=>U.includes(e),P=e=>!e||typeof e!="object"?!1:e.isProxy;var De=0,ae=()=>`i${De++}`,L=(e,t)=>e.filter(r=>!g.und(r)&&!g.nul(r)).map(r=>u(r,t)).join(", "),R=(e,t)=>g.str(e)?t?.isWebGL?e:J[e]:"",ue=e=>A[e]||e,ce=e=>oe[e],pe=e=>{let t=U.indexOf(e);return t!==-1?S[t]:"float"},fe=e=>Array.from(e.headers).map(([,t])=>t).join(`
2
+ `),le=(e,t)=>{let{id:r,children:n=[],layout:o}=e,[s,a,...i]=n,m=o?.type&&o?.type!=="auto"?o?.type:a?y(a,t):"void",b=[],c=[];if(o?.inputs)for(let d of o.inputs)b.push([d.name,d.type]);else for(let d=0;d<i.length;d++)b.push([`p${d}`,y(i[d],t)]);let p="";if(t?.isWebGL){for(let[d,_]of b)c.push(`${_} ${d}`);p+=`${m} ${r}(${c}) {
3
+ `}else{for(let[d,_]of b)c.push(`${d}: ${R(_,t)}`);p+=`fn ${r}(${c}) -> ${R(m,t)} {
4
+ `}let T=u(s,t);return T&&(p+=T+`
5
+ `),a&&(p+=`return ${u(a,t)};`),p+=`
6
+ }`,p},Me=`
9
7
  #version 300 es
10
8
  precision mediump float;
11
9
  out vec4 fragColor;
12
- ${t}
13
- void main() {
14
- fragColor = ${e};
15
- }`.trim():`
16
- ${t}
10
+ `.trim(),Ve=`
17
11
  @fragment
18
12
  fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
19
- return ${e};
20
- }`.trim(),G=(e,t={})=>{let r=p(e,t),n=le(t),o=de(r,n,t.isWebGL);return console.log(`// \u2193\u2193\u2193 generated \u2193\u2193\u2193
13
+ `.trim(),ze=(e,t,r=!0)=>{let n="";return r&&(n+=Me),t&&(n+=`
14
+ `+t+`
15
+ `),r?n+=`void main() {
16
+ fragColor = ${e};`:(n+=Ve+`
17
+ `,n+=` return ${e};`),n+=`
18
+ }`,n},We=(e,t,r=!0)=>"",w=(e,t={})=>{let r=u(e,t),n=fe(t),o=ze(r,n,t.isWebGL);return console.log(`// \u2193\u2193\u2193 generated \u2193\u2193\u2193
21
19
 
22
20
  ${o}
23
21
 
24
- `),o},F=(e,t)=>{let r=p(e,t),n=le(t);return de(r,n,t.isWebGL)};var ge=e=>g.bol(e)?"bool":g.num(e)?"float":g.arr(e)&&k[e.length]||"float",xe=(e,t,r)=>{if(ne.includes(r)||se.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=L.indexOf(e),o=L.indexOf(t);return n>=o?e:t},De=(e,t)=>e.reduce((r,n)=>{let o=_(n,t),s=L.indexOf(r);return L.indexOf(o)>s?o:r},"float"),ze=e=>k[e],We=e=>oe[e],qe=(e,t,r)=>{let n=t.length>0?_(t[0],r):"float";return z.includes(e)?n:B.includes(e)?"float":M.includes(e)?"bool":V.includes(e)?n:D.includes(e)?"vec3":q.includes(e)?"vec4":W.includes(e)?De(t,r):n},ke=(e,t)=>{let{type:r,props:n}=e,{id:o,children:s=[],value:u}=n,[a,m,y]=s;return r==="uniform"||r==="variable"||r==="constant"||r==="attribute"||r==="varying"?ge(u):r==="conversion"?a:r==="operator"?xe(_(m,t),_(y,t),a):r==="function"?qe(a,s.slice(1),t):r==="swizzle"?ze(a.length):r==="ternary"?xe(_(m,t),_(y,t),"add"):r==="define"?m?_(m,t):"void":r==="builtin"?We(o):"float"},_=(e,t)=>{if(t||(t={}),!S(e))return ge(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=ke(e,t);return t.infers.set(e,r),r};var p=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),g.str(e))return e;if(g.num(e))return e.toFixed(1);if(g.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[]}=n,[u,a,m]=s,y="";if(r==="uniform"){if(t.headers.has(o))return o;t.binding||(t.binding=0);let f=_(e,t);y=t.isWebGL?`uniform ${f} ${o};`:`@group(0) @binding(${t.binding++}) var<uniform> ${o}: ${C(f,t)};`}if(r==="attribute"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(r==="constant"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(r==="varying"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(y)return t.headers.set(o,y),t.onMount?.(o,n.value),o;if(r==="variable")return o;if(r==="swizzle")return`${p(a,t)}.${p(u,t)}`;if(r==="operator")return u==="not"||u==="bitNot"?`!${p(a,t)}`:`(${p(a,t)} ${fe(u)} ${p(m,t)})`;if(r==="function")return u==="negate"?`(-${U(s.slice(1),t)})`:`${u}(${U(s.slice(1),t)})`;if(r==="conversion")return`${C(u,t)}(${U(s.slice(1),t)})`;if(r==="scope")return s.map(f=>p(f,t)).join(`
25
- `);if(r==="assign")return`${p(u,t)} = ${p(a,t)};`;if(r==="define"){let f=s.slice(2),d=`${o}(${f.map(h=>p(h,t))})`;return t.headers.has(o)||t.headers.set(o,me(n,t)),d}if(r==="loop")return`for (int i = 0; i < ${u}; i++) {
26
- ${p(a,t)}
27
- }`;if(r==="if"){let f=`if (${p(u,t)}) {
28
- ${p(a,t)}
29
- }`;for(let d=2;d<s.length;d+=2){let h=d>=s.length-1;f+=h?` else {
30
- ${p(s[d],t)}
31
- }`:` else if (${p(s[d],t)}) {
32
- ${p(s[d+1],t)}
33
- }`}return f}if(r==="switch"){let f=`switch (${p(u,t)}) {
34
- `;for(let d=1;d<s.length;d+=2)d>=s.length-1&&s.length%2===0?f+=`default:
35
- ${p(s[d],t)}
22
+ `),o},O=(e,t)=>{let r=u(e,t),n=fe(t);return We(r,n,t.isWebGL)};var qe=(e,t)=>e.reduce((r,n)=>{let o=y(n,t),s=S.indexOf(r);return S.indexOf(o)>s?o:r},"float"),ke=e=>ee[e],Ye=(e,t,r)=>{let n=t.length>0?y(t[0],r):"float";return V.includes(e)?n:$.includes(e)?"float":B.includes(e)?"bool":D.includes(e)?n:M.includes(e)?"vec3":W.includes(e)?"vec4":z.includes(e)?qe(t,r):n},me=(e,t,r)=>{if(te.includes(r)||re.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=S.indexOf(e),o=S.indexOf(t);return n>=o?e:t},je=e=>g.bol(e)?"bool":g.num(e)?"float":g.arr(e)&&q[e.length]||"float",He=e=>q[e],Ke=(e,t)=>{let{type:r,props:n}=e,{id:o,children:s=[],inferFrom:a}=n,[i,m,b]=s;return a?y(a,t):r==="conversion"?i:r==="operator"?me(y(m,t),y(b,t),i):r==="function"?Ye(i,s.slice(1),t):r==="swizzle"?He(i.length):r==="ternary"?me(y(m,t),y(b,t),"add"):r==="builtin"?ke(o):r==="define"?n.layout?.type&&n.layout?.type!=="auto"?n.layout.type:m?y(m,t):"void":y(i,t)},y=(e,t)=>{if(t||(t={}),!P(e))return je(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=Ke(e,t);return t.infers.set(e,r),r};var u=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),g.str(e))return e;if(g.num(e)){let c=`${e}`;return c.includes(".")?c:c+".0"}if(g.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[]}=n,[a,i,m]=s,b="";if(r==="attribute"){if(t.headers.has(o))return o;b=`${y(e,t)} ${o}`}if(r==="uniform"){if(t.headers.has(o))return o;t.binding||(t.binding=0);let c=y(e,t);b=t.isWebGL?`uniform ${c} ${o};`:`@group(0) @binding(${t.binding++}) var<uniform> ${o}: ${R(c,t)};`}if(r==="constant"){if(t.headers.has(o))return o;let c=y(e,t),p=u(a,t);b=t.isWebGL?`const ${c} ${o} = ${p};`:`const ${o}: ${R(c,t)} = ${p};`}if(r==="varying"){if(t.headers.has(o))return o;b=`${y(e,t)} ${o}`}if(b)return t.headers.set(o,b),t.onMount?.(o),o;if(r==="variable")return o;if(r==="swizzle")return`${u(i,t)}.${u(a,t)}`;if(r==="ternary")return`(${u(a,t)} ? ${u(i,t)} : ${u(m,t)})`;if(r==="builtin")return t?.isWebGL?ce(o):o;if(r==="conversion")return`${R(a,t)}(${L(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${u(i,t)}`:`(${u(i,t)} ${ue(a)} ${u(m,t)})`;if(r==="function")return a==="negate"?`(-${L(s.slice(1),t)})`:`${a}(${L(s.slice(1),t)})`;if(r==="scope")return s.map(c=>u(c,t)).join(`
23
+ `);if(r==="assign")return`${u(a,t)} = ${u(i,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${a}; i += 1) {
24
+ ${u(i,t)}
25
+ }`:`for (var i: i32 = 0; i < ${a}; i++) {
26
+ ${u(i,t)}
27
+ }`;if(r==="define"){let c=s.slice(2),p=`${o}(${c.map(T=>u(T,t))})`;return t.headers.has(o)||t.headers.set(o,le(n,t)),p}if(r==="if"){let c=`if (${u(a,t)}) {
28
+ ${u(i,t)}
29
+ }`;for(let p=2;p<s.length;p+=2){let T=p>=s.length-1;c+=T?` else {
30
+ ${u(s[p],t)}
31
+ }`:` else if (${u(s[p],t)}) {
32
+ ${u(s[p+1],t)}
33
+ }`}return c}if(r==="switch"){let c=`switch (${u(a,t)}) {
34
+ `;for(let p=1;p<s.length;p+=2)p>=s.length-1&&s.length%2===0?c+=`default:
35
+ ${u(s[p],t)}
36
36
  break;
37
- `:d+1<s.length&&(f+=`case ${p(s[d],t)}:
38
- ${p(s[d+1],t)}
37
+ `:p+1<s.length&&(c+=`case ${u(s[p],t)}:
38
+ ${u(s[p+1],t)}
39
39
  break;
40
- `);return f+="}",f}if(r==="ternary")return`(${p(u,t)} ? ${p(a,t)} : ${p(m,t)})`;if(r==="declare"){let f=_(a,t),d=u?.props?.id;if(t.isWebGL)return`${f} ${d} = ${p(a,t)};`;let h=C(f);return`var ${d}: ${h} = ${p(a,t)};`}if(r==="builtin"){if(t?.isWebGL){let f=ie[o];if(f)return f;if(o==="uv")return"gl_FragCoord.xy"}return o}return p(u,t)};var R=null,w=(e,t=()=>{})=>{let r=R;R=e,t(),R=r},O=e=>{R&&(R.props.children||(R.props.children=[]),R.props.children.push(e))},be=(e,t)=>{t||(t=I());let r=c("variable",{id:t}),n=c("declare",null,r,e);return O(n),r},ve=(e,t)=>{let r=c("assign",null,e,t);return O(r),e},Gt=(e,t)=>{let r=c("scope");w(r,t);let n=c("if",null,e,r);O(n);let o=()=>({ElseIf:(s,u)=>{let a=c("scope");return w(a,u),n.props.children.push(s,a),o()},Else:s=>{let u=c("scope");w(u,s),n.props.children.push(u)}});return o()},Ft=(e,t)=>{let r=c("scope");w(r,()=>t({i:c("variable",{id:"i"})}));let n=c("loop",null,e,r);return O(n),n},At=e=>{let t=c("switch",null,e);O(t);let r=()=>({Case:(...n)=>o=>{let s=c("scope");w(s,o);for(let u of n)t.props.children.push(u,s);return r()},Default:n=>{let o=c("scope");w(o,n),t.props.children.push(o)}});return r()},$t=e=>{let t=I();return(...r)=>{let n=c("scope"),o,s=[];for(let u=0;u<r.length;u++){let a=`p${u}`,m=c("variable",{id:a});s.push(m)}return w(n,()=>o=e(s)),c("define",{id:t},n,o,...r)}};var Ye=(e,t)=>{if(t==="string")return p(e)},c=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let n=(u,a)=>{if(a==="type")return e;if(a==="props")return t;if(a==="toVar")return be.bind(null,s);if(a==="assign")return ve.bind(null,s);if(a==="isProxy")return!0;if(a==="toString")return p.bind(null,s);if(a===Symbol.toPrimitive)return Ye.bind(null,s);if(Y(a))return ye(a,s);if(ae(a))return(...m)=>je(a,s,...m);if(ue(a))return(...m)=>i(a,s,...m);if(ce(a))return b(a,s)},o=(u,a,m)=>Y(a)?(ye(a,s).assign(m),!0):!1,s=new Proxy({},{get:n,set:o});return s};var ye=(e,t)=>c("swizzle",null,e,t),je=(e,...t)=>c("operator",null,e,...t),i=(e,...t)=>c("function",null,e,...t),b=(e,...t)=>c("conversion",null,e,...t);var Yt=(e,t,r)=>c("ternary",null,e,t,r),j=(e,t)=>c("uniform",{id:t,value:e}),jt=(e,t)=>c("varying",{id:t,value:e}),Kt=(e,t)=>c("varying",{id:t,value:e}),Ht=e=>c("variable",{id:e}),Zt=e=>c("builtin",{id:e}),Qt=j([1280,800],"iResolution"),Jt=j([0,0],"iMouse"),er=j(0,"iTime"),Ke=c("builtin",{id:"position"}),He=c("builtin",{id:"vertex_index"}),tr=c("builtin",{id:"instance_index"}),rr=c("builtin",{id:"front_facing"}),or=c("builtin",{id:"frag_depth"}),nr=c("builtin",{id:"sample_index"}),sr=c("builtin",{id:"sample_mask"}),ir=c("builtin",{id:"point_coord"}),ar=c("builtin",{id:"position"}),ur=c("builtin",{id:"positionWorld"}),cr=c("builtin",{id:"positionView"}),pr=c("builtin",{id:"normalLocal"}),fr=c("builtin",{id:"normalWorld"}),lr=c("builtin",{id:"normalView"}),mr=c("builtin",{id:"screenCoordinate"}),dr=c("builtin",{id:"screenUV"}),xr=Ke,gr=He,br=e=>b("float",e),vr=e=>b("int",e),yr=e=>b("uint",e),Xr=e=>b("bool",e),Tr=(e,t)=>b("vec2",e,t),Xe=(e,t,r)=>b("vec3",e,t,r),_r=(e,t,r,n)=>b("vec4",e,t,r,n),hr=(...e)=>b("mat2",...e),Er=(...e)=>b("mat3",...e),Pr=(...e)=>b("mat4",...e),Nr=(e,t)=>b("ivec2",e,t),Sr=(e,t,r)=>b("ivec3",e,t,r),Rr=(e,t,r,n)=>b("ivec4",e,t,r,n),wr=(e,t)=>b("uvec2",e,t),Cr=(e,t,r)=>b("uvec3",e,t,r),Lr=(e,t,r,n)=>b("uvec4",e,t,r,n),Or=(e,t)=>b("bvec2",e,t),Ir=(e,t,r)=>b("bvec3",e,t,r),Ur=(e,t,r,n)=>b("bvec4",e,t,r,n),Gr=(e,t,r)=>g.num(e)&&g.und(t)&&g.und(r)?Xe(...pe(e)):Xe(e,t,r),Fr=(e,t,r)=>i("texture",e,t,r),Ar=(e,t,r)=>i("cubeTexture",e,t,r),$r=(e,t)=>i("textureSize",e,t),Br=e=>i("abs",e),Mr=e=>i("acos",e),Vr=e=>i("all",e),Dr=e=>i("any",e),zr=e=>i("asin",e),Wr=(e,t)=>t!==void 0?i("atan",e,t):i("atan",e),qr=(e,t)=>i("atan",e,t),kr=(e,t)=>i("bitcast",e,t),Yr=e=>i("cbrt",e),jr=e=>i("ceil",e),Kr=(e,t,r)=>i("clamp",e,t,r),Hr=e=>i("cos",e),Zr=(e,t)=>i("cross",e,t),Qr=e=>i("dFdx",e),Jr=e=>i("dFdy",e),eo=e=>i("degrees",e),to=(e,t)=>i("difference",e,t),ro=(e,t)=>i("distance",e,t),oo=(e,t)=>i("dot",e,t),no=(e,t)=>i("equals",e,t),so=e=>i("exp",e),io=e=>i("exp2",e),ao=(e,t,r)=>i("faceforward",e,t,r),uo=e=>i("floor",e),co=e=>i("fract",e),po=e=>i("fwidth",e),fo=e=>i("inverseSqrt",e),lo=e=>i("length",e),mo=e=>i("lengthSq",e),xo=e=>i("log",e),go=e=>i("log2",e),bo=(e,t)=>i("max",e,t),vo=(e,t)=>i("min",e,t),yo=(e,t,r)=>i("mix",e,t,r),Xo=e=>i("negate",e),To=e=>i("normalize",e),_o=e=>i("oneMinus",e),ho=(e,t)=>i("pow",e,t),Eo=e=>i("pow2",e),Po=e=>i("pow3",e),No=e=>i("pow4",e),So=e=>i("radians",e),Ro=e=>i("reciprocal",e),wo=(e,t)=>i("reflect",e,t),Co=(e,t,r)=>i("refract",e,t,r),Lo=e=>i("round",e),Oo=e=>i("saturate",e),Io=e=>i("sign",e),Uo=e=>i("sin",e),Go=(e,t,r)=>i("smoothstep",e,t,r),Fo=e=>i("sqrt",e),Ao=(e,t)=>i("step",e,t),$o=e=>i("tan",e),Bo=(e,t)=>i("transformDirection",e,t),Mo=e=>i("trunc",e);var Ze=`
40
+ `);return c+="}",c}if(r==="declare"){let c=y(a,t),p=i?.props?.id;if(t.isWebGL)return`${c} ${p} = ${u(a,t)};`;let T=R(c);return`var ${p}: ${T} = ${u(a,t)};`}return u(a,t)};var G=null;var de=e=>{G&&(G.props.children||(G.props.children=[]),G.props.children.push(e))},xe=(e,t)=>{t||(t=ae());let r=N("variable",{id:t,inferFrom:e}),n=N("declare",null,e,r);return de(n),r},ge=(e,t)=>{let r=N("assign",null,e,t);return de(r),e};var Ze=(e,t)=>{if(t==="string")return u(e)},N=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let n=(a,i)=>{if(i==="type")return e;if(i==="props")return t;if(i==="toVar")return xe.bind(null,s);if(i==="assign")return ge.bind(null,s);if(i==="isProxy")return!0;if(i==="toString")return u.bind(null,s);if(i===Symbol.toPrimitive)return Ze.bind(null,s);if(k(i))return be(i,s);if(ne(i))return(...m)=>Qe(i,s,...m);if(se(i))return(...m)=>ve(i,s,...m);if(ie(i))return()=>C(pe(i),s)},o=(a,i,m)=>k(i)?(be(i,s).assign(m),!0):!1,s=new Proxy({},{get:n,set:o});return s};var I=(e,t)=>N("uniform",{id:t},e);var X=e=>N("builtin",{id:e}),be=(e,t)=>N("swizzle",null,e,t),Qe=(e,...t)=>N("operator",null,e,...t),ve=(e,...t)=>N("function",null,e,...t),C=(e,...t)=>N("conversion",null,e,...t);var Yt=X("position"),jt=X("vertex_index"),Ht=X("instance_index"),Kt=X("front_facing"),Zt=X("frag_depth"),Qt=X("sample_index"),Jt=X("sample_mask"),er=X("point_coord"),tr=X("normalLocal"),rr=X("normalWorld"),or=X("normalView"),nr=X("position"),sr=X("positionWorld"),ir=X("positionView"),ar=X("screenCoordinate"),ur=X("screenUV"),Je=e=>C("float",e);var ye=(e,t)=>C("vec2",e,t);var cr=I(ye(1280,800),"iResolution"),pr=I(ye(0,0),"iMouse"),fr=I(Je(0),"iTime");var et=`
41
41
  #version 300 es
42
42
  void main() {
43
43
  float x = float(gl_VertexID % 2) * 4.0 - 1.0;
44
44
  float y = float(gl_VertexID / 2) * 4.0 - 1.0;
45
45
  gl_Position = vec4(x, y, 0.0, 1.0);
46
46
  }
47
- `,Qe=`
47
+ `,tt=`
48
48
  #version 300 es
49
49
  precision mediump float;
50
50
  uniform vec2 iResolution;
@@ -52,19 +52,19 @@ out vec4 fragColor;
52
52
  void main() {
53
53
  fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
54
54
  }
55
- `,Te=(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}`)},_e=(e,t=Ze,r=Qe,n=()=>{})=>{S(r)&&(r=G(r,{isWebGL:!0})),S(t)&&(t=F(r,{isWebGL:!0}));let o=e.createProgram(),s=Te(e,t,e.VERTEX_SHADER),u=Te(e,r,e.FRAGMENT_SHADER);if(!s||!u)return n();if(e.attachShader(o,s),e.attachShader(o,u),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let a=e.getProgramInfoLog(o);e.deleteProgram(o),n(),console.warn(`Could not link pg: ${a}`)},he=(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},Ee=(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},Pe=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Ne=(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)},Se=(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 Re=async e=>{let t=e.el.getContext("webgl2"),r=_e(t,e.vs,e.fs,()=>void(e.isLoop=!1));t.useProgram(r);let n=0,o=K(T=>t.getUniformLocation(r,T)),s=K(T=>t.getAttribLocation(r,T)),u=K(()=>n++);return{webgl:{context:t,program:r},render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(T="",E,P)=>{let N=s(T,!0),X=he(t,E),l=Ee(t,P),x=Pe(e.count,E,P);Ne(t,x,N,X,l)},_uniform:(T,E)=>{let P=o(T);if(g.num(E))return t.uniform1f(P,E);let N=E.length;if(N<=4)return t[`uniform${N}fv`](P,E);N=Math.sqrt(N)<<0,t[`uniformMatrix${N}fv`](P,!1,E)},_texture:(T,E)=>{let P=new Image;Object.assign(P,{src:E,crossOrigin:"anonymous"}),P.decode().then(()=>{let N=o(T),X=u(T);Se(t,P,N,X)})}}};import{nested as H}from"reev";var Je=`
55
+ `,Xe=(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}`)},_e=(e,t=et,r=tt,n=()=>{})=>{P(r)&&(r=w(r,{isWebGL:!0})),P(t)&&(t=O(r,{isWebGL:!0}));let o=e.createProgram(),s=Xe(e,t,e.VERTEX_SHADER),a=Xe(e,r,e.FRAGMENT_SHADER);if(!s||!a)return n();if(e.attachShader(o,s),e.attachShader(o,a),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let i=e.getProgramInfoLog(o);e.deleteProgram(o),n(),console.warn(`Could not link pg: ${i}`)},Te=(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},he=(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},Ee=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Ne=(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)},Pe=(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 Se=async e=>{let t=e.el.getContext("webgl2"),r=_e(t,e.vs,e.fs,()=>void(e.isLoop=!1));t.useProgram(r);let n=0,o=Y(d=>t.getUniformLocation(r,d)),s=Y(d=>t.getAttribLocation(r,d)),a=Y(()=>n++);return{webgl:{context:t,program:r},render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(d="",_,h)=>{let E=s(d,!0),v=Te(t,_),f=he(t,h),l=Ee(e.count,_,h);Ne(t,l,E,v,f)},_uniform:(d,_)=>{let h=o(d);if(g.num(_))return t.uniform1f(h,_);let E=_.length;if(E<=4)return t[`uniform${E}fv`](h,_);E=Math.sqrt(E)<<0,t[`uniformMatrix${E}fv`](h,!1,_)},_texture:(d,_)=>{let h=new Image;Object.assign(h,{src:_,crossOrigin:"anonymous"}),h.decode().then(()=>{let E=o(d),v=a(d);Pe(t,h,E,v)})}}};import{nested as j}from"reev";var rt=`
56
56
  @vertex
57
57
  fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
58
58
  let x = f32(vertex_index % 2u) * 4.0 - 1.0;
59
59
  let y = f32(vertex_index / 2u) * 4.0 - 1.0;
60
60
  return vec4f(x, y, 0.0, 1.0);
61
61
  }
62
- `,et=`
62
+ `,ot=`
63
63
  @group(0) @binding(0) var<uniform> iResolution: vec2f;
64
64
 
65
65
  @fragment
66
66
  fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
67
67
  return vec4f(position.xy / iResolution, 0.0, 1.0);
68
68
  }
69
- `,we=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}},Ce=(e,t,r,n,o=Je,s=et)=>{S(o)&&(o=F(o,{isWebGL:!1})),S(s)&&(s=G(s,{isWebGL:!1}));let u=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:o.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:u,primitive:{topology:"triangle-list"}})},Le=(e,t)=>{let r=[],n=[];t.forEach((u,a)=>{if(!u)return;let m="buffer"in u,y=u instanceof GPUTextureView,f=u instanceof GPUSampler;if(m)r.push({binding:a,visibility:3,buffer:{type:"uniform"}});else if(y)r.push({binding:a,visibility:2,texture:{}});else if(f)r.push({binding:a,visibility:2,sampler:{}});else return;n.push({binding:a,resource:u})});let o=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:o,entries:n});return{layout:o,bindGroup:s}},Oe=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),tt=e=>Math.ceil(e/256)*256,Ie=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},Ue=(e,t)=>{let r=new Float32Array(t),n=tt(r.byteLength),o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},Ge=(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}},rt=(e,t)=>e/t,ot=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Fe=(e,t,r=6)=>{let n=rt(t,r);return{arrayStride:n*4,attributes:[{shaderLocation:e,offset:0,format:ot(n)}]}};var Ae=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await we(t),o={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],u=[],a=[],m=H((X,l)=>{let{array:x,buffer:v}=Ie(r,l);return u.push(v),a.push(Fe(a.length,x.length,e.count)),o.needsUpdate=!0,{array:x,buffer:v}}),y=H((X,l)=>{let{array:x,buffer:v}=Ue(r,l);return o.resources[0].push({buffer:v}),o.needsUpdate=!0,{array:x,buffer:v}}),f=H((X,{width:l,height:x})=>{let{texture:v,sampler:A}=Ge(r,l,x);return o.resources[1].push(A,v.createView()),o.needsUpdate=!0,{texture:v,width:l,height:x}}),d=()=>{let X=[];s.length=0,o.resources.forEach(l=>{if(!l.length)return;let{layout:x,bindGroup:v}=Le(r,l);X.push(x),s.push(v)}),o.pipeline=Ce(r,n,a,X,e.vs,e.fs)};return{webgpu:o,render:()=>{if(o.loadingImg)return;o.needsUpdate&&d(),o.needsUpdate=!1;let X=r.createCommandEncoder(),l=X.beginRenderPass(Oe(t));l.setPipeline(o.pipeline),s.forEach((x,v)=>l.setBindGroup(v,x)),u.forEach((x,v)=>l.setVertexBuffer(v,x)),l.draw(e.count,1,0,0),l.end(),r.queue.submit([X.finish()])},clean:()=>{},_attribute:(X="",l)=>{let{array:x,buffer:v}=m(X,l);r.queue.writeBuffer(v,0,x)},_uniform:(X,l)=>{g.num(l)&&(l=[l]);let{array:x,buffer:v}=y(X,l);x.set(l),r.queue.writeBuffer(v,0,x)},_texture:(X,l)=>{o.loadingImg++;let x=Object.assign(new Image,{src:l,crossOrigin:"anonymous"});x.decode().then(()=>{let{texture:v,width:A,height:$e}=f(X,x);r.queue.copyExternalImageToTexture({source:x},{texture:v},{width:A,height:$e}),o.loadingImg--})}}};var mn=e=>g.obj(e)?"isGL"in e:!1,at=()=>typeof window>"u",ut=()=>at()?!1:"gpu"in navigator,Q=performance.now(),ct=e=>{let t=nt({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=it(),t.frame=st(),t.attribute=Z((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=Z((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=Z((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:Q}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,ut()||(t.isWebGL=!0),t.isWebGL?t(await Re(t)):t(await Ae(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,u]=t.size,{top:a,left:m}=t.el.getBoundingClientRect();t.mouse[0]=(n-a-s/2)/(s/2),t.mouse[1]=-(o-m-u/2)/(u/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{Q=performance.now()/1e3,t.uniform("iTime",Q)}),t(e)},dn=ct;export{Me as ADDITIONAL_FUNCTIONS,M as BOOL_RETURN_FUNCTIONS,oe as BUILTIN_TYPES,ne as COMPARISON_OPERATORS,k as COMPONENT_COUNT_TO_TYPE,L as CONSTANTS,J as CONVERSIONS,z as FIRST_ARG_TYPE_FUNCTIONS,te as FUNCTIONS,$t as Fn,W as HIGHEST_TYPE_FUNCTIONS,Gt as If,se as LOGICAL_OPERATORS,Ft as Loop,$ as OPERATORS,ee as OPERATOR_KEYS,V as PRESERVE_TYPE_FUNCTIONS,B as SCALAR_RETURN_FUNCTIONS,bt as SWIZZLES,At as Switch,re as TYPE_MAPPING,D as VEC3_RETURN_FUNCTIONS,q as VEC4_RETURN_FUNCTIONS,ie as WGSL_TO_GLSL_BUILTIN,Br as abs,Mr as acos,tt as alignTo256,Vr as all,Dr as any,zr as asin,ve as assign,Wr as atan,qr as atan2,Kt as attribute,kr as bitcast,Xr as bool,Zt as builtin,Or as bvec2,Ir as bvec3,Ur as bvec4,Yr as cbrt,jr as ceil,Kr as clamp,p as code,Gr as color,b as conversion,Hr as cos,Ne as createAttrib,Le as createBindGroup,Fe as createBufferLayout,Oe as createDescriptor,we as createDevice,ct as createGL,Ee as createIbo,Ce as createPipeline,_e as createProgram,Se as createTexture,Ge as createTextureSampler,Ue as createUniformBuffer,he as createVbo,Ie as createVertexBuffer,Zr as cross,Ar as cubeTexture,Qr as dFdx,Jr as dFdy,dn as default,Qe as defaultFragmentGLSL,Ze as defaultVertexGLSL,eo as degrees,to as difference,dt as dig,ro as distance,oo as dot,Be as each,no as equals,so as exp,io as exp2,lt as ext,ao as faceforward,mt as fig,br as float,uo as floor,pt as flush,C as formatConversions,co as fract,xr as fragCoord,or as fragDepth,G as fragment,rr as frontFacing,i as function_,po as fwidth,me as generateDefine,I as getId,fe as getOperator,Pe as getStride,pe as hex2rgb,Jt as iMouse,Qt as iResolution,er as iTime,_ as infer,ke as inferImpl,tr as instanceIndex,vr as int,fo as inverseSqrt,g as is,ce as isConversion,ue as isFunction,mn as isGL,S as isNodeProxy,ae as isOperator,at as isServer,Y as isSwizzle,ut as isWebGPUSupported,Nr as ivec2,Sr as ivec3,Rr as ivec4,U as joins,lo as length,mo as lengthSq,xo as log,go as log2,hr as mat2,Er as mat3,Pr as mat4,bo as max,vo as min,yo as mix,Xo as negate,c as node,pr as normalLocal,lr as normalView,fr as normalWorld,To as normalize,_o as oneMinus,je as operator,ir as pointCoord,Ke as position,ar as positionLocal,cr as positionView,ur as positionWorld,ho as pow,Eo as pow2,Po as pow3,No as pow4,So as radians,Ro as reciprocal,wo as reflect,Co as refract,ft as replace,Lo as round,nr as sampleIndex,sr as sampleMask,Oo as saturate,mr as screenCoordinate,dr as screenUV,Yt as select,xt as sig,Io as sign,Uo as sin,Go as smoothstep,Fo as sqrt,Ao as step,ye as swizzle,$o as tan,Fr as texture,$r as textureSize,be as toVar,Bo as transformDirection,Mo as trunc,yr as uint,j as uniform,wr as uvec2,Cr as uvec3,Lr as uvec4,Ht as variable,jt as varying,Tr as vec2,Xe as vec3,_r as vec4,F as vertex,gr as vertexId,He as vertexIndex,Re as webgl,Ae as webgpu};
69
+ `,Re=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}},Ce=(e,t,r,n,o=rt,s=ot)=>{P(o)&&(o=O(o,{isWebGL:!1})),P(s)&&(s=w(s,{isWebGL:!1}));let a=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:o.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:a,primitive:{topology:"triangle-list"}})},Le=(e,t)=>{let r=[],n=[];t.forEach((a,i)=>{if(!a)return;let m="buffer"in a,b=a instanceof GPUTextureView,c=a instanceof GPUSampler;if(m)r.push({binding:i,visibility:3,buffer:{type:"uniform"}});else if(b)r.push({binding:i,visibility:2,texture:{}});else if(c)r.push({binding:i,visibility:2,sampler:{}});else return;n.push({binding:i,resource:a})});let o=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:o,entries:n});return{layout:o,bindGroup:s}},we=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),nt=e=>Math.ceil(e/256)*256,Oe=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},Ge=(e,t)=>{let r=new Float32Array(t),n=nt(r.byteLength),o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},Ie=(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}},st=(e,t)=>e/t,it=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Fe=(e,t,r=6)=>{let n=st(t,r);return{arrayStride:n*4,attributes:[{shaderLocation:e,offset:0,format:it(n)}]}};var Ue=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await Re(t),o={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],a=[],i=[],m=j((v,f)=>{let{array:l,buffer:x}=Oe(r,f);return a.push(x),i.push(Fe(i.length,l.length,e.count)),o.needsUpdate=!0,{array:l,buffer:x}}),b=j((v,f)=>{let{array:l,buffer:x}=Ge(r,f);return o.resources[0].push({buffer:x}),o.needsUpdate=!0,{array:l,buffer:x}}),c=j((v,{width:f,height:l})=>{let{texture:x,sampler:F}=Ie(r,f,l);return o.resources[1].push(F,x.createView()),o.needsUpdate=!0,{texture:x,width:f,height:l}}),p=()=>{let v=[];s.length=0,o.resources.forEach(f=>{if(!f.length)return;let{layout:l,bindGroup:x}=Le(r,f);v.push(l),s.push(x)}),o.pipeline=Ce(r,n,i,v,e.vs,e.fs)};return{webgpu:o,render:()=>{if(o.loadingImg)return;o.needsUpdate&&p(),o.needsUpdate=!1;let v=r.createCommandEncoder(),f=v.beginRenderPass(we(t));f.setPipeline(o.pipeline),s.forEach((l,x)=>f.setBindGroup(x,l)),a.forEach((l,x)=>f.setVertexBuffer(x,l)),f.draw(e.count,1,0,0),f.end(),r.queue.submit([v.finish()])},clean:()=>{},_attribute:(v="",f)=>{let{array:l,buffer:x}=m(v,f);r.queue.writeBuffer(x,0,l)},_uniform:(v,f)=>{g.num(f)&&(f=[f]);let{array:l,buffer:x}=b(v,f);l.set(f),r.queue.writeBuffer(x,0,l)},_texture:(v,f)=>{o.loadingImg++;let l=Object.assign(new Image,{src:f,crossOrigin:"anonymous"});l.decode().then(()=>{let{texture:x,width:F,height:Ae}=c(v,l);r.queue.copyExternalImageToTexture({source:l},{texture:x},{width:F,height:Ae}),o.loadingImg--})}}};var Ar=e=>g.obj(e)?"isGL"in e:!1,pt=()=>typeof window>"u",ft=()=>pt()?!1:"gpu"in navigator,K=performance.now(),lt=e=>{let t=at({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=ct(),t.frame=ut(),t.attribute=H((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=H((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=H((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:K}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,ft()||(t.isWebGL=!0),t.isWebGL?t(await Se(t)):t(await Ue(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,a]=t.size,{top:i,left:m}=t.el.getBoundingClientRect();t.mouse[0]=(n-i-s/2)/(s/2),t.mouse[1]=-(o-m-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{K=performance.now()/1e3,t.uniform("iTime",K)}),t(e)},$r=lt;export{nt as alignTo256,Ne as createAttrib,Le as createBindGroup,Fe as createBufferLayout,we as createDescriptor,Re as createDevice,lt as createGL,he as createIbo,Ce as createPipeline,_e as createProgram,Pe as createTexture,Ie as createTextureSampler,Ge as createUniformBuffer,Te as createVbo,Oe as createVertexBuffer,$r as default,tt as defaultFragmentGLSL,et as defaultVertexGLSL,bt as dig,$e as each,xt as ext,gt as fig,mt as flush,Ee as getStride,g as is,Ar as isGL,pt as isServer,ft as isWebGPUSupported,dt as replace,vt as sig,Se as webgl,Ue as webgpu};
70
70
  //# sourceMappingURL=index.js.map