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