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