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