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/index.cjs CHANGED
@@ -1,70 +1,36 @@
1
- "use strict";var D=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Ke=(e,t)=>{for(var r in t)D(e,r,{get:t[r],enumerable:!0})},Ze=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of je(t))!He.call(e,o)&&o!==r&&D(e,o,{get:()=>t[o],enumerable:!(n=Ye(t,o))||n.enumerable});return e};var Qe=e=>Ze(D({},"__esModule",{value:!0}),e);var Pt={};Ke(Pt,{alignTo256:()=>Ve,createAttrib:()=>re,createBindGroup:()=>ae,createBufferLayout:()=>le,createDescriptor:()=>ue,createDevice:()=>se,createGL:()=>qe,createIbo:()=>ee,createPipeline:()=>ie,createProgram:()=>Q,createTexture:()=>oe,createTextureSampler:()=>fe,createUniformBuffer:()=>pe,createVbo:()=>J,createVertexBuffer:()=>ce,default:()=>Nt,defaultFragmentGLSL:()=>Me,defaultVertexGLSL:()=>De,dig:()=>ot,each:()=>xe,ext:()=>tt,fig:()=>rt,flush:()=>Je,getStride:()=>te,is:()=>x,isGL:()=>Et,isServer:()=>ze,isWebGPUSupported:()=>We,replace:()=>et,sig:()=>nt,webgl:()=>ne,webgpu:()=>me});module.exports=Qe(Pt);var C=require("reev"),$=require("refr");var U=require("reev");var x={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)},xe=(e,t)=>e.forEach(t),Je=(e,...t)=>{xe(e,r=>r(...t))},et=(e="",t="_",r="/")=>e.split(t).join(r),tt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",rt=(e=0)=>`${e}`.split(".")[1]?.length??0,ot=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),nt=(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"],M=["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:">>"},ge=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"],st=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],be=[...z,...W,...q,...k,...Y,...j,...H,...st],ve={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"},ye={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"},Xe=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],_e=["and","or"],Te={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=>x.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),he=e=>ge.includes(e),Ee=e=>be.includes(e),Ne=e=>M.includes(e),P=e=>!e||typeof e!="object"?!1:e.isProxy;var it=0,Pe=()=>`i${it++}`,w=(e,t)=>e.filter(r=>!x.und(r)&&!x.nul(r)).map(r=>u(r,t)).join(", "),R=(e,t)=>x.str(e)?t?.isWebGL?e:ve[e]:"",Se=e=>V[e]||e,Re=e=>Te[e],Ce=e=>{let t=M.indexOf(e);return t!==-1?S[t]:"float"},Le=e=>Array.from(e.headers).map(([,t])=>t).join(`
2
- `),we=(e,t)=>{let{id:r,children:n=[],layout:o}=e,[s,a,...i]=n,m=o?.type&&o?.type!=="auto"?o?.type:a?y(a,t):"void",b=[],c=[];if(o?.inputs)for(let d of o.inputs)b.push([d.name,d.type]);else for(let d=0;d<i.length;d++)b.push([`p${d}`,y(i[d],t)]);let p="";if(t?.isWebGL){for(let[d,_]of b)c.push(`${_} ${d}`);p+=`${m} ${r}(${c}) {
3
- `}else{for(let[d,_]of b)c.push(`${d}: ${R(_,t)}`);p+=`fn ${r}(${c}) -> ${R(m,t)} {
4
- `}let T=u(s,t);return T&&(p+=T+`
5
- `),a&&(p+=`return ${u(a,t)};`),p+=`
6
- }`,p},at=`
7
- #version 300 es
8
- precision mediump float;
9
- out vec4 fragColor;
10
- `.trim(),ut=`
11
- @fragment
12
- fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
13
- `.trim(),ct=(e,t,r=!0)=>{let n="";return r&&(n+=at),t&&(n+=`
14
- `+t+`
15
- `),r?n+=`void main() {
16
- fragColor = ${e};`:(n+=ut+`
17
- `,n+=` return ${e};`),n+=`
18
- }`,n},pt=(e,t,r=!0)=>"",O=(e,t={})=>{let r=u(e,t),n=Le(t),o=ct(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=Le(t);return pt(r,n,t.isWebGL)};var ft=(e,t)=>e.reduce((r,n)=>{let o=y(n,t),s=S.indexOf(r);return S.indexOf(o)>s?o:r},"float"),lt=e=>ye[e],mt=(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)?ft(t,r):n},Oe=(e,t,r)=>{if(Xe.includes(r)||_e.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},dt=e=>x.bol(e)?"bool":x.num(e)?"float":x.arr(e)&&K[e.length]||"float",xt=e=>K[e],gt=(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"?Oe(y(m,t),y(b,t),i):r==="function"?mt(i,s.slice(1),t):r==="swizzle"?xt(i.length):r==="ternary"?Oe(y(m,t),y(b,t),"add"):r==="builtin"?lt(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 dt(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=gt(e,t);return t.infers.set(e,r),r};var u=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),x.str(e))return e;if(x.num(e)){let c=`${e}`;return c.includes(".")?c:c+".0"}if(x.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[]}=n,[a,i,m]=s,b="";if(r==="attribute"){if(t.headers.has(o))return o;b=`${y(e,t)} ${o}`}if(r==="uniform"){if(t.headers.has(o))return o;t.binding||(t.binding=0);let c=y(e,t);b=t.isWebGL?`uniform ${c} ${o};`:`@group(0) @binding(${t.binding++}) var<uniform> ${o}: ${R(c,t)};`}if(r==="constant"){if(t.headers.has(o))return o;let c=y(e,t),p=u(a,t);b=t.isWebGL?`const ${c} ${o} = ${p};`:`const ${o}: ${R(c,t)} = ${p};`}if(r==="varying"){if(t.headers.has(o))return o;b=`${y(e,t)} ${o}`}if(b)return t.headers.set(o,b),t.onMount?.(o),o;if(r==="variable")return o;if(r==="swizzle")return`${u(i,t)}.${u(a,t)}`;if(r==="ternary")return`(${u(a,t)} ? ${u(i,t)} : ${u(m,t)})`;if(r==="builtin")return t?.isWebGL?Re(o):o;if(r==="conversion")return`${R(a,t)}(${w(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${u(i,t)}`:`(${u(i,t)} ${Se(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,we(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 Xt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var _t=(e,t)=>{for(var r in t)re(e,r,{get:t[r],enumerable:!0})},Et=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yt(t))!Tt.call(e,o)&&o!==r&&re(e,o,{get:()=>t[o],enumerable:!(n=Xt(t,o))||n.enumerable});return e};var Ct=e=>Et(re({},"__esModule",{value:!0}),e);var Mo={};_t(Mo,{Fn:()=>Wt,If:()=>Mt,Loop:()=>Vt,Return:()=>mt,Switch:()=>zt,abs:()=>Ir,acos:()=>Ur,all:()=>Fr,any:()=>Ar,asin:()=>Dr,assign:()=>_e,atan:()=>Br,atan2:()=>Mr,attribute:()=>kt,bitcast:()=>Vr,bool:()=>mr,builtin:()=>y,bvec2:()=>_r,bvec3:()=>Er,bvec4:()=>Cr,cbrt:()=>zr,ceil:()=>Wr,clamp:()=>qr,code:()=>c,color:()=>Sr,constant:()=>Yt,conversion:()=>x,conversionToConstant:()=>ye,cos:()=>kr,createAttrib:()=>Ge,createAttribBuffer:()=>Be,createBindGroup:()=>Me,createBindings:()=>Fe,createDepthTexture:()=>We,createDescriptor:()=>Ve,createDevice:()=>Ue,createGL:()=>ht,createIbo:()=>Re,createPipeline:()=>Ae,createProgram:()=>we,createTexture:()=>$e,createTextureSampler:()=>ze,createUniformBuffer:()=>De,createVbo:()=>Le,createVertexBuffers:()=>qe,cross:()=>Yr,cubeTexture:()=>Gr,dFdx:()=>Hr,dFdy:()=>jr,default:()=>Bo,degrees:()=>Kr,difference:()=>Zr,dig:()=>Lt,distance:()=>Qr,dot:()=>Jr,each:()=>je,equals:()=>eo,exp:()=>to,exp2:()=>ro,ext:()=>St,faceforward:()=>oo,fig:()=>wt,float:()=>W,floor:()=>no,flush:()=>Nt,formatConversions:()=>N,fract:()=>Se,fragDepth:()=>er,fragment:()=>z,frontFacing:()=>Jt,function_:()=>u,fwidth:()=>so,getBluiltin:()=>Xe,getId:()=>w,getOperator:()=>he,getStride:()=>Oe,hex2rgb:()=>ve,iMouse:()=>wr,iResolution:()=>j,iTime:()=>Lr,instanceIndex:()=>Qt,int:()=>R,inverseSqrt:()=>io,is:()=>l,isConstantsType:()=>be,isConversion:()=>de,isFunction:()=>xe,isGL:()=>Fo,isNodeProxy:()=>ge,isOperator:()=>me,isServer:()=>bt,isSwizzle:()=>q,isWebGPUSupported:()=>vt,ivec2:()=>br,ivec3:()=>vr,ivec4:()=>hr,joins:()=>L,length:()=>ao,lengthSq:()=>uo,log:()=>po,log2:()=>co,mat2:()=>xr,mat3:()=>dr,mat4:()=>gr,max:()=>fo,min:()=>lo,mix:()=>mo,negate:()=>xo,node:()=>m,normalLocal:()=>nr,normalView:()=>ir,normalWorld:()=>sr,normalize:()=>go,oneMinus:()=>bo,operator:()=>xt,pointCoord:()=>or,position:()=>k,positionLocal:()=>ar,positionView:()=>pr,positionWorld:()=>ur,pow:()=>vo,pow2:()=>ho,pow3:()=>Xo,pow4:()=>yo,radians:()=>To,reciprocal:()=>_o,reflect:()=>Eo,refract:()=>Co,replace:()=>Pt,round:()=>No,sampleIndex:()=>tr,sampleMask:()=>rr,sampler2D:()=>Pr,saturate:()=>Po,screenCoordinate:()=>cr,screenUV:()=>fr,select:()=>Kt,sig:()=>Rt,sign:()=>So,sin:()=>wo,smoothstep:()=>Lo,sqrt:()=>Ro,step:()=>Oo,swizzle:()=>Ee,tan:()=>Go,texture:()=>Or,texture2D:()=>Nr,textureSize:()=>$r,toVar:()=>Te,transformDirection:()=>$o,trunc:()=>Io,uint:()=>lr,uniform:()=>M,uv:()=>Rr,uvec2:()=>Xr,uvec3:()=>yr,uvec4:()=>Tr,variable:()=>Ht,vec2:()=>Pe,vec3:()=>Ne,vec4:()=>H,vertex:()=>V,vertexIndex:()=>Y,vertexStage:()=>jt,webgl:()=>Ie,webgpu:()=>ke});module.exports=Ct(Mo);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)},je=(e,t)=>e.forEach(t),Nt=(e,...t)=>{je(e,r=>r(...t))},Pt=(e="",t="_",r="/")=>e.split(t).join(r),St=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",wt=(e=0)=>`${e}`.split(".")[1]?.length??0,Lt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Rt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var G=["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:">>"},Ke=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"],Ot=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],Ze=[...se,...ie,...ae,...ue,...pe,...ce,...fe,...Ot],Qe={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"},Je={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"},et=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],tt=["and","or"],rt={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=>Ke.includes(e),xe=e=>Ze.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]},Gt=0,w=()=>`i${Gt++}`,L=(e,t)=>e.filter(r=>!l.und(r)&&!l.nul(r)).map(r=>c(r,t)).join(", "),N=(e,t)=>l.str(e)?t?.isWebGL?e:Qe[e]:"",he=e=>ne[e]||e,Xe=e=>rt[e],ye=e=>{let t=oe.indexOf(e);return t!==-1?G[t]:"float"};var $t=(e,t)=>e.reduce((r,n)=>{let o=X(n,t),i=G.indexOf(r);return G.indexOf(o)>i?o:r},"float"),It=e=>Je[e],Ut=(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)?$t(t,r):n},ot=(e,t,r)=>{if(et.includes(r)||tt.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=G.indexOf(e),o=G.indexOf(t);return n>=o?e:t},Ft=e=>l.bol(e)?"bool":l.num(e)?"float":l.arr(e)&&le[e.length]||"float",At=e=>le[e],Dt=(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},Bt=(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"?ot(X(f,t),X(b,t),p):r==="function"?Ut(p,i.slice(1),t):r==="swizzle"?At(p.length):r==="ternary"?ot(X(f,t),X(b,t),"add"):r==="builtin"?It(o):r==="define"&&be(s?.type)?s?.type:a?Dt(a,t):X(p,t)},X=(e,t)=>{if(t||(t={}),!ge(e))return Ft(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=Bt(e,t);return t.infers.set(e,r),r};var nt=(e,t,r,n)=>{if(e.isWebGL)return`texture(${L(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})`},st=(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},it=(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=R(c);return`var ${p}: ${T} = ${u(a,t)};`}return u(a,t)};var I=null;var Ge=e=>{I&&(I.props.children||(I.props.children=[]),I.props.children.push(e))},Ie=(e,t)=>{t||(t=Pe());let r=N("variable",{id:t,inferFrom:e}),n=N("declare",null,e,r);return Ge(n),r},Fe=(e,t)=>{let r=N("assign",null,e,t);return Ge(r),e};var bt=(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 Ie.bind(null,s);if(i==="assign")return Fe.bind(null,s);if(i==="isProxy")return!0;if(i==="toString")return u.bind(null,s);if(i===Symbol.toPrimitive)return bt.bind(null,s);if(Z(i))return Ue(i,s);if(he(i))return(...m)=>vt(i,s,...m);if(Ee(i))return(...m)=>Ae(i,s,...m);if(Ne(i))return()=>L(Ce(i),s)},o=(a,i,m)=>Z(i)?(Ue(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}),Ue=(e,t)=>N("swizzle",null,e,t),vt=(e,...t)=>N("operator",null,e,...t),Ae=(e,...t)=>N("function",null,e,...t),L=(e,...t)=>N("conversion",null,e,...t);var rr=X("position"),or=X("vertex_index"),nr=X("instance_index"),sr=X("front_facing"),ir=X("frag_depth"),ar=X("sample_index"),ur=X("sample_mask"),cr=X("point_coord"),pr=X("normalLocal"),fr=X("normalWorld"),lr=X("normalView"),mr=X("position"),dr=X("positionWorld"),xr=X("positionView"),gr=X("screenCoordinate"),br=X("screenUV"),yt=e=>L("float",e);var $e=(e,t)=>L("vec2",e,t);var vr=F($e(1280,800),"iResolution"),yr=F($e(0,0),"iMouse"),Xr=F(yt(0),"iTime");var De=`
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
- `,Me=`
14
+ `);return n+="}",n},at=(e,t,r)=>{let n=X(t,e),o=r?.props?.id;if(e.isWebGL)return`${n} ${o} = ${c(t,e)};`;let i=N(n);return`var ${o}: ${i} = ${c(t,e)};`},ut=(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}: ${N(_,e)}`);b.push(`fn ${n}(${f}) -> ${N(r,e)} {`)}let d=c(s,e);return d&&b.push(d),b.push("}"),b.join(`
15
+ `)},pt=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.vertVaryings.size}) ${t}: ${N(r,e)}`,ct=(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=N(r,e);return`@group(${o}) @binding(${i}) var<uniform> ${t}: ${s};`},ft=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:n=0}=e.webgpu?.attribs.map.get(t)||{},o=N(r,e);return`@location(${n}) ${t}: ${o}`},lt=(e,t,r,n)=>e.isWebGL?`const ${r} ${t} = ${n};`:`const ${t}: ${N(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`${N(s,t)}(${L(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"?`(-${L(i.slice(1),t)})`:s==="texture"?nt(t,a,p,f):`${s}(${L(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 st(t,s,a,i);if(r==="switch")return it(t,s,i);if(r==="declare")return at(t,s,a);if(r==="define"){let d=`${o}(${L(i.slice(1),t)})`;return t.headers.has(o)||t.headers.set(o,ut(t,n,X(e,t))),d}if(r==="varying"){if(t.vertOutputs.has(o))return t.isWebGL?`${o}`:`out.${o}`;let d=pt(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}: ${N(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,ft(t,o,X(e,t))),t.isWebGL?`${o}`:`in.${o}`;if(t.headers.has(o))return o;let b="";return r==="uniform"&&(b=ct(t,o,X(e,t))),r==="constant"&&(b=lt(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=w());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},mt=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&&mt(i),$=n,U=o},Mt=(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()},Vt=(e,t)=>{let r=m("scope");I(r,()=>t({i:m("variable",{id:"i",inferFrom:[R(0)]})}));let n=m("loop",null,e,r);return F(n),n},zt=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()},Wt=e=>{let t,r=(...n)=>{let o=t?.name||w(),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 qt=(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 qt.bind(null,i);if(q(a))return Ee(a,i);if(me(a))return(...p)=>xt(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},kt=(e,t=w())=>m("attribute",{id:t},e),Yt=(e,t=w())=>m("constant",{id:t},e),M=(e,t=w())=>m("uniform",{id:t},e),Ht=(e=w())=>m("variable",{id:e}),y=(e=w())=>m("builtin",{id:e}),jt=(e,t=w())=>m("varying",{id:t,inferFrom:[e]},e),Ee=(e,t)=>m("swizzle",null,e,t),xt=(e,...t)=>m("operator",null,e,...t),u=(e,...t)=>m("function",null,e,...t),x=(e,...t)=>m("conversion",null,e,...t),Kt=(e,t,r)=>m("ternary",null,e,t,r);var Zt=`
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
- `,Be=(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=De,r=Me,n=()=>{})=>{P(r)&&(r=O(r,{isWebGL:!0})),P(t)&&(t=G(r,{isWebGL:!0}));let o=e.createProgram(),s=Be(e,t,e.VERTEX_SHADER),a=Be(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)(d=>t.getUniformLocation(r,d)),s=(0,U.nested)(d=>t.getAttribLocation(r,d)),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:(d="",_,h)=>{let E=s(d,!0),v=J(t,_),f=ee(t,h),l=te(e.count,_,h);re(t,l,E,v,f)},_uniform:(d,_)=>{let h=o(d);if(x.num(_))return t.uniform1f(h,_);let E=_.length;if(E<=4)return t[`uniform${E}fv`](h,_);E=Math.sqrt(E)<<0,t[`uniformMatrix${E}fv`](h,!1,_)},_texture:(d,_)=>{let h=new Image;Object.assign(h,{src:_,crossOrigin:"anonymous"}),h.decode().then(()=>{let E=o(d),v=a(d);oe(t,h,E,v)})}}};var A=require("reev");var Xt=`
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
- `,_t=`
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=Xt,s=_t)=>{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"}]}),Ve=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=Ve(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}},Tt=(e,t)=>e/t,ht=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",le=(e,t,r=6)=>{let n=Tt(t,r);return{arrayStride:n*4,attributes:[{shaderLocation:e,offset:0,format:ht(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)=>{x.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:ke}=c(v,l);r.queue.copyExternalImageToTexture({source:l},{texture:g},{width:B,height:ke}),o.loadingImg--})}}};var Et=e=>x.obj(e)?"isGL"in e:!1,ze=()=>typeof window>"u",We=()=>ze()?!1:"gpu"in navigator,de=performance.now(),qe=e=>{let t=(0,C.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,C.durable)((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=(0,C.durable)((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=(0,C.durable)((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:de}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,We()||(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",()=>{de=performance.now()/1e3,t.uniform("iTime",de)}),t(e)},Nt=qe;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,webgl,webgpu});
25
+ `.trim(),dt=(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]=dt(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]=dt(e,t),o=[];if(t.isWebGL){o.push(Zt);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"),Qt=y("instance_index"),Jt=y("front_facing"),er=y("frag_depth"),tr=y("sample_index"),rr=y("sample_mask"),or=y("point_coord"),nr=y("normalLocal"),sr=y("normalWorld"),ir=y("normalView"),ar=y("position"),ur=y("positionWorld"),pr=y("positionView"),cr=y("screenCoordinate"),fr=y("screenUV"),W=e=>x("float",e),R=e=>x("int",e),lr=e=>x("uint",e),mr=e=>x("bool",e),Pe=(e,t)=>x("vec2",e,t),Ne=(e,t,r)=>x("vec3",e,t,r),H=(e,t,r,n)=>x("vec4",e,t,r,n),xr=(...e)=>x("mat2",...e),dr=(...e)=>x("mat3",...e),gr=(...e)=>x("mat4",...e),br=(e,t)=>x("ivec2",e,t),vr=(e,t,r)=>x("ivec3",e,t,r),hr=(e,t,r,n)=>x("ivec4",e,t,r,n),Xr=(e,t)=>x("uvec2",e,t),yr=(e,t,r)=>x("uvec3",e,t,r),Tr=(e,t,r,n)=>x("uvec4",e,t,r,n),_r=(e,t)=>x("bvec2",e,t),Er=(e,t,r)=>x("bvec3",e,t,r),Cr=(e,t,r,n)=>x("bvec4",e,t,r,n),Nr=()=>x("texture"),Pr=()=>x("sampler2D"),Sr=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Ne(...ve(e)):Ne(e,t,r),j=M(Pe(1280,800),"iResolution"),wr=M(Pe(0,0),"iMouse"),Lr=M(W(0),"iTime"),Rr=()=>k.xy.div(j),Or=(e,t,r)=>u("texture",e,t,r),Gr=(e,t,r)=>u("cubeTexture",e,t,r),$r=(e,t)=>u("textureSize",e,t),Ir=e=>u("abs",e),Ur=e=>u("acos",e),Fr=e=>u("all",e),Ar=e=>u("any",e),Dr=e=>u("asin",e),Br=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),Mr=(e,t)=>u("atan",e,t),Vr=(e,t)=>u("bitcast",e,t),zr=e=>u("cbrt",e),Wr=e=>u("ceil",e),qr=(e,t,r)=>u("clamp",e,t,r),kr=e=>u("cos",e),Yr=(e,t)=>u("cross",e,t),Hr=e=>u("dFdx",e),jr=e=>u("dFdy",e),Kr=e=>u("degrees",e),Zr=(e,t)=>u("difference",e,t),Qr=(e,t)=>u("distance",e,t),Jr=(e,t)=>u("dot",e,t),eo=(e,t)=>u("equals",e,t),to=e=>u("exp",e),ro=e=>u("exp2",e),oo=(e,t,r)=>u("faceforward",e,t,r),no=e=>u("floor",e),Se=e=>u("fract",e),so=e=>u("fwidth",e),io=e=>u("inverseSqrt",e),ao=e=>u("length",e),uo=e=>u("lengthSq",e),po=e=>u("log",e),co=e=>u("log2",e),fo=(e,t)=>u("max",e,t),lo=(e,t)=>u("min",e,t),mo=(e,t,r)=>u("mix",e,t,r),xo=e=>u("negate",e),go=e=>u("normalize",e),bo=e=>u("oneMinus",e),vo=(e,t)=>u("pow",e,t),ho=e=>u("pow2",e),Xo=e=>u("pow3",e),yo=e=>u("pow4",e),To=e=>u("radians",e),_o=e=>u("reciprocal",e),Eo=(e,t)=>u("reflect",e,t),Co=(e,t,r)=>u("refract",e,t,r),No=e=>u("round",e),Po=e=>u("saturate",e),So=e=>u("sign",e),wo=e=>u("sin",e),Lo=(e,t,r)=>u("smoothstep",e,t,r),Ro=e=>u("sqrt",e),Oo=(e,t)=>u("step",e,t),Go=e=>u("tan",e),$o=(e,t)=>u("transformDirection",e,t),Io=e=>u("trunc",e);var gt=(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}`)},we=(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=gt(e,t,e.VERTEX_SHADER),p=gt(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}`)},Le=(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},Re=(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},Oe=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Ge=(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=we(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 P=i(g,!0),D=Le(t,_),J=Re(t,E),ee=Oe(e.count,_,E);Ge(t,ee,P,D,J)},_uniform:(g,_)=>{let E=o(g);if(l.num(_))return t.uniform1f(E,_);let P=_.length;if(P<=4)return t[`uniform${P}fv`](E,_);P=Math.sqrt(P)<<0,t[`uniformMatrix${P}fv`](E,!1,_)},_texture:(g,_)=>{let E=new Image;Object.assign(E,{src:_,crossOrigin:"anonymous"}),E.decode().then(()=>{let P=o(g),D=s(g);$e(t,E,P,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}),Uo=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:Uo(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:O,buffer:S}=De(r,v);return{array:O,buffer:S,binding:C,group:h}}),b=(0,Z.nested)((T,{width:v,height:h})=>{s=!0;let{group:C,binding:O}=o.texture(),{texture:S,sampler:B}=ze(r,v,h);return{texture:S,sampler:B,binding:O,group:C}}),d=(0,Z.nested)((T,v)=>{s=!0;let h=v.length/e.count,{location:C}=o.attrib(),{array:O,buffer:S}=Be(r,v);return{array:O,buffer:S,location:C,stride:h}}),g=()=>{let{vertexBuffers:T,bufferLayouts:v}=qe(d.map),{bindGroups:h,bindGroupLayouts:C}=Me(r,f.map,b.map),O=Ae(r,n,v,C,He,e.vs,e.fs);p=S=>{S.setPipeline(O),h.forEach((B,te)=>S.setBindGroup(te,B)),T.forEach((B,te)=>S.setVertexBuffer(te,B)),S.draw(e.count,1,0,0),S.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)},P=()=>{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 He={device:r,uniforms:f,textures:b,attribs:d};return{webgpu:He,render:_,resize:E,clean:P,_attribute:D,_uniform:J,_texture:ee}};var Fo=e=>l.obj(e)?"isGL"in e:!1,bt=()=>typeof window>"u",vt=()=>bt()?!1:"gpu"in navigator,Ye=performance.now(),Ao=()=>H(Se(k.xy.div(j)),0,1),Do=()=>H(W(R(Y).mod(R(2))).mul(4).sub(1),W(R(Y).div(R(2))).mul(4).sub(1),0,1),ht=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||Do(),t.fs=t.fs||t.frag||t.fragment||Ao(),vt()||(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)},Bo=ht;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,uv,uvec2,uvec3,uvec4,variable,vec2,vec3,vec4,vertex,vertexIndex,vertexStage,webgl,webgpu});
70
36
  //# sourceMappingURL=index.cjs.map