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