glre 0.48.0 → 0.49.1
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/README.md +18 -18
- package/dist/addons.d.ts +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +57 -53
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +57 -53
- package/dist/node.cjs +15 -15
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +60 -56
- package/dist/node.js +15 -15
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +57 -53
- package/dist/solid.d.ts +57 -53
- package/package.json +1 -1
- package/src/index.ts +4 -1
- package/src/node/create.ts +10 -9
- package/src/node/scope.ts +3 -15
- package/src/node/types.ts +20 -43
- package/src/node/utils/const.ts +27 -10
- package/src/node/utils/index.ts +15 -8
- package/src/node/utils/infer.ts +17 -10
package/dist/node.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var n in t)O(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ot(t))!st.call(e,o)&&o!==n&&O(e,o,{get:()=>t[o],enumerable:!(r=rt(t,o))||r.enumerable});return e};var ut=e=>at(O({},"__esModule",{value:!0}),e);var Cr={};it(Cr,{Break:()=>_t,Continue:()=>yt,Fn:()=>At,If:()=>St,Loop:()=>Rt,Return:()=>ze,Scope:()=>S,Switch:()=>Lt,abs:()=>Yn,acos:()=>In,acosh:()=>Un,addToScope:()=>E,all:()=>bn,any:()=>$n,asin:()=>Nn,asinh:()=>Gn,assign:()=>J,atan:()=>Dn,atan2:()=>cr,atanh:()=>wn,attribute:()=>He,bool:()=>Qt,builtin:()=>b,bvec2:()=>ln,bvec3:()=>fn,bvec4:()=>cn,ceil:()=>On,clamp:()=>dr,color:()=>Tn,compute:()=>Z,constant:()=>qe,conversion:()=>x,cos:()=>Pn,cosh:()=>Wn,create:()=>d,cross:()=>Sn,cubeTexture:()=>Rn,dFdx:()=>Mn,dFdy:()=>Vn,degrees:()=>Bn,determinant:()=>hn,distance:()=>Cn,dot:()=>En,element:()=>te,exp:()=>zn,exp2:()=>Hn,float:()=>et,floor:()=>kn,fract:()=>qn,fragDepth:()=>Dt,fragment:()=>j,frontFacing:()=>Gt,function_:()=>l,fwidth:()=>jn,gather:()=>Ze,iMouse:()=>mn,iResolution:()=>tt,iTime:()=>gn,id:()=>Wt,instance:()=>ke,instanceIndex:()=>Nt,int:()=>Kt,inverseSqrt:()=>Kn,ivec2:()=>rn,ivec3:()=>on,ivec4:()=>sn,length:()=>_n,lengthSq:()=>yn,log:()=>Zn,log2:()=>Qn,luminance:()=>Xn,mat2:()=>en,mat3:()=>tn,mat4:()=>nn,max:()=>xr,member:()=>w,min:()=>Tr,mix:()=>mr,mod:()=>k,negate:()=>Jn,normalLocal:()=>zt,normalView:()=>kt,normalWorld:()=>Ht,normalize:()=>er,oneMinus:()=>tr,operator:()=>ne,pointCoord:()=>Pt,position:()=>Je,positionLocal:()=>Mt,positionView:()=>Bt,positionWorld:()=>Vt,pow:()=>gr,radians:()=>nr,reciprocal:()=>rr,reflect:()=>vr,refract:()=>br,round:()=>or,sampleIndex:()=>wt,sampleMask:()=>Ot,sampler2D:()=>xn,scatter:()=>It,scoped:()=>ee,screenCoordinate:()=>qt,screenUV:()=>jt,select:()=>Qe,sign:()=>sr,sin:()=>ir,sinh:()=>ar,smoothstep:()=>$r,sqrt:()=>ur,step:()=>hr,storage:()=>Yt,struct:()=>Xt,tan:()=>pr,tanh:()=>lr,texelFetch:()=>An,texture:()=>Ln,texture2D:()=>dn,textureLod:()=>Fn,toVar:()=>Q,trunc:()=>fr,uint:()=>Zt,uniform:()=>L,uv:()=>vn,uvec2:()=>an,uvec3:()=>un,uvec4:()=>pn,variable:()=>je,vec2:()=>oe,vec3:()=>re,vec4:()=>Jt,vertex:()=>K,vertexIndex:()=>Ut,vertexStage:()=>Ke});module.exports=ut(Cr);var W=["toBool","toUInt","toInt","toFloat","toBVec2","toIVec2","toUVec2","toVec2","toBVec3","toIVec3","toUVec3","toVec3","toBVec4","toIVec4","toUVec4","toVec4","toColor","toMat2","toMat3","toMat4"],M={bool:"bool",uint:"u32",int:"i32",float:"f32",bvec2:"vec2<bool>",ivec2:"vec2i",uvec2:"vec2u",vec2:"vec2f",bvec3:"vec3<bool>",ivec3:"vec3i",uvec3:"vec3u",vec3:"vec3f",bvec4:"vec4<bool>",ivec4:"vec4i",uvec4:"vec4u",vec4:"vec4f",color:"color",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",texture:"texture_2d<f32>",sampler2D:"sampler",struct:"struct"},V=Object.keys(M),se={float:"float",vec2:"float",vec3:"float",vec4:"float",int:"int",ivec2:"int",ivec3:"int",ivec4:"int",uint:"uint",uvec2:"uint",uvec3:"uint",uvec4:"uint",bool:"bool",bvec2:"bool",bvec3:"bool",bvec4:"bool"},F={float:{1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},int:{1:"int",2:"ivec2",3:"ivec3",4:"ivec4"},uint:{1:"uint",2:"uvec2",3:"uvec3",4:"uvec4"},bool:{1:"bool",2:"bvec2",3:"bvec3",4:"bvec4"}},B={not:"!",add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>",addAssign:"+=",subAssign:"-=",mulAssign:"*=",divAssign:"/=",modAssign:"%=",bitAndAssign:"&=",bitOrAssign:"|=",bitXorAssign:"^=",shiftLeftAssign:"<<=",shiftRightAssign:">>="},ie=Object.keys(B),ae={position:"vec4",vertex_index:"uint",instance_index:"uint",front_facing:"bool",frag_depth:"float",sample_index:"uint",sample_mask:"uint",point_coord:"vec2",global_invocation_id:"uvec3",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"},ue=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],pe=["and","or"],le=[["float","vec2","vec2"],["float","vec3","vec3"],["float","vec4","vec4"],["int","ivec2","ivec2"],["int","ivec3","ivec3"],["int","ivec4","ivec4"],["uint","uvec2","uvec2"],["uint","uvec3","uvec3"],["uint","uvec4","uvec4"],["mat2","vec2","vec2"],["mat3","vec3","vec3"],["mat4","vec4","vec4"],["vec2","mat2","vec2"],["vec3","mat3","vec3"],["vec4","mat4","vec4"]],fe={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"},z={all:"bool",any:"bool",determinant:"float",distance:"float",dot:"float",length:"float",lengthSq:"float",luminance:"float",cross:"vec3",cubeTexture:"vec4",texture:"vec4",texelFetch:"vec4",textureLod:"vec4"},ce=[...Object.keys(z),"abs","acos","acosh","asin","asinh","atan","atanh","ceil","cos","cosh","dFdx","dFdy","degrees","exp","exp2","floor","fract","fwidth","inverse","inverseSqrt","log","log2","negate","normalize","oneMinus","radians","reciprocal","round","sign","sin","sinh","sqrt","tan","tanh","trunc","saturate","atan2","clamp","max","min","mix","pow","reflect","refract","smoothstep","step"],P=(e,t)=>e===t,pt=(e,t)=>le.some(([n,r,o])=>n===e&&r===t||n===t&&r===e),de=(e,t,n)=>ue.includes(n)||pe.includes(n)?P(e,t):P(e,t)?!0:pt(e,t),xe=(e,t,n)=>{if(ue.includes(n)||pe.includes(n))return"bool";if(P(e,t))return e;let r=le.find(([o,s,a])=>o===e&&s===t||o===t&&s===e);return r?r[2]:e};var c={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)};var Y=e=>e instanceof Float32Array;var lt=e=>[1,2,3,4,9,16].includes(e),ft=(e,t=3)=>e%t===0?Math.floor(e/t):-1,Te=(e,t=1,n=console.warn,r="")=>{let o=ft(e,t);return lt(o)||n(`glre attribute error: Invalid attribute length ${e}, ${r?`${r} `:" "}must divide by vertex count (${t}) with valid stride (1,2,3,4,9,16)`),o};var yr=`
|
|
2
2
|
struct In { @builtin(vertex_index) vertex_index: u32 }
|
|
3
3
|
struct Out { @builtin(position) position: vec4f }
|
|
4
4
|
@vertex
|
|
@@ -9,26 +9,26 @@ fn main(in: In) -> Out {
|
|
|
9
9
|
out.position = vec4f(x, y, 0.0, 1.0);
|
|
10
10
|
return out;
|
|
11
11
|
}
|
|
12
|
-
`.trim();var
|
|
12
|
+
`.trim();var I=(e=1024)=>{if(c.num(e)){let o=Math.sqrt(e),s=Math.ceil(o);return Number.isInteger(o)||console.warn(`GLRE Storage Warning: particleCount (${e}) is not a square. Using ${s}x${s} texture may waste GPU memory. Consider using [width, height] format for optimal storage.`),{x:s,y:s}}let[t,n,r]=e;if(r!==void 0){let o=n*r;return console.warn(`GLRE Storage Warning: 3D particleCount [${t}, ${n}, ${r}] specified but WebGL storage textures only support 2D. Flattening to 2D by multiplying height=${n} * depth=${r} = ${o}.`),{x:t,y:o}}return{x:t,y:n}};var me=e=>c.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ge=e=>ie.includes(e),ve=e=>ce.includes(e),be=e=>c.obj(e)?!1:e instanceof Element,$e=e=>W.includes(e),A=e=>!e||typeof e!="object"?!1:e.isProxy,U=e=>c.str(e)?V.includes(e):!1,he=e=>{let t=(e>>16&255)/255,n=(e>>8&255)/255,r=(e&255)/255;return[t,n,r]},ct=0,v=()=>`x${ct++}`,Ce=(e,t)=>{if(t==="global_invocation_id")return`uvec3(uint(gl_FragCoord.y) * uint(${I(e.gl?.particleCount).x}) + uint(gl_FragCoord.x), 0u, 0u)`;let n=fe[t];if(!n)throw new Error(`Error: unknown builtin variable ${t}`);return n},C=(e,t)=>c.str(e)?t?.isWebGL?e:M[e]||e:"",H=e=>B[e]||e,Ee=e=>{let t=W.indexOf(e);return t!==-1?V[t]:"float"},_e=e=>(e.code||(e.code={headers:new Map,fragInputs:new Map,vertInputs:new Map,vertOutputs:new Map,vertVaryings:new Map,computeInputs:new Map,dependencies:new Map,structStructFields:new Map},e.isWebGL)||(e.code.fragInputs.set("position","@builtin(position) position: vec4f"),e.code.vertOutputs.set("position","@builtin(position) position: vec4f")),e),ye=e=>c.num(e)||c.str(e)&&/^\d+$/.test(e),N=(e,t="",n)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),U(n)||e.code.dependencies.get(t).add(n)},dt=(e,t,n)=>e.isWebGL?n==="attribute"?e.gl?.attribute?.bind(null,t):n==="instance"?e.gl?.instance?.bind(null,t):n==="texture"?e.gl?.texture?.bind(null,t):n==="storage"?e.gl?.storage?.bind(null,t):r=>e.gl?.uniform?.(t,r):n==="attribute"?e.gl?._attribute?.bind(null,t):n==="instance"?e.gl?._instance?.bind(null,t):n==="texture"?e.gl?._texture?.bind(null,t):n==="storage"?e.gl?._storage?.bind(null,t):r=>e.gl?._uniform?.(t,r),xt=(e,t)=>{if(c.und(e))return;if(!A(e))return t(e);if(e.type!=="conversion")return;let n=e.props.children?.slice(1);if(!c.und(n?.[0])){if(c.arr(n[0])||Y(n[0]))return t(n[0]);t(n.map(r=>r??n[0]))}},G=(e,t,n,r,o)=>{let s=dt(e,t,n);if(s)return xt(o,s),r.listeners.add(s),s};var Tt=e=>ae[e],mt=(e,t)=>F[se[e]][t],gt=(e,t,n)=>n==="not"?"bool":(de(e,t,n)||console.warn(`GLRE Type Warning: Invalid operator '${n}' between types '${e}' and '${t}'`),xe(e,t,n)),vt=e=>c.bol(e)?"bool":c.str(e)?"texture":c.num(e)?"float":c.arr(e)||Y(e)?F.float[e.length]:be(e)?"texture":"void",Se=(e,t=console.warn,n="")=>{let r=F.float[e];return r||t(`glre node system error: Cannot infer ${n?`${n} `:""} type from array length ${e}. Check your data size. Supported: 1(float), 2(vec2), 3(vec3), 4(vec4), 9(mat3), 16(mat4)`),r},Xe=(e,t)=>{if(e.length===0)return"void";let[n]=e;return c.str(n)?n:g(n,t)},bt=e=>z[e],$t=(e,t)=>{let{type:n,props:r}=e,{id:o,children:s=[],inferFrom:a,layout:f}=r,[i,u,T]=s;if(n==="conversion")return i;if(n==="operator")return gt(g(u,t),g(T,t),i);if(n==="builtin")return Tt(o);if(n==="function")return bt(i)||g(u,t);if(n==="define")return U(f?.type)?f?.type:!a||a.length===0?"void":Xe(a,t);if((n==="attribute"||n==="instance")&&c.arr(i)){let h=n==="instance"?t.gl?.instanceCount:t.gl?.count,$=Te(i.length,h,t.gl?.error,o);return Se($,t.gl?.error,o)}if(n==="member"){let h=g(i,t);if(!U(h)){let $=t.code?.structStructFields?.get(h);if($&&$[u])return g($[u],t)}return me(u)?mt(h,u.length):"float"}return a?Xe(a,t):i?g(i,t):"void"},g=(e,t)=>{if(t||(t={}),!A(e))return vt(e);if(c.arr(e))return Se(e.length,t.gl?.error,e.props.id);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let n=$t(e,t);return t.infers.set(e,n),n};var y=(e,t)=>e.filter(n=>!c.und(n)&&!c.nul(n)).map(n=>p(n,t)).join(", "),Re=(e,t,n,r)=>{let o=()=>{let u=g(r,e);if(u==="float")return".x";if(u==="vec2")return".xy";if(u==="vec3")return".xyz";if(u==="vec4")return"";throw new Error(`Unsupported storage scatter type: ${u}`)},s=p(n,e),a=I(e.gl?.particleCount),f=`int(${s}) % ${a.x}`,i=`int(${s}) / ${a.x}`;return`texelFetch(${p(t,e)}, ivec2(${f}, ${i}), 0)${o()}`},Le=(e,t,n)=>{let r=p(t,e),o=p(n,e),s=g(n,e);if(s==="float")return`_${r} = vec4(${o}, 0.0, 0.0, 1.0);`;if(s==="vec2")return`_${r} = vec4(${o}, 0.0, 1.0);`;if(s==="vec3")return`_${r} = vec4(${o}, 1.0);`;if(s==="vec4")return`_${r} = ${o};`;throw new Error(`Unsupported storage scatter type: ${s}`)},Ae=(e,t,n,r)=>{if(e.isWebGL)return`texture(${y(r?[t,n,r]:[t,n],e)})`;let o=p(t,e),s=[o,o+"Sampler",p(n,e)];return r?(s.push(p(r,e)),`textureSampleLevel(${s})`):`textureSample(${s})`},Fe=(e,t,n,r)=>{let o=`if (${p(t,e)}) {
|
|
13
13
|
${p(n,e)}
|
|
14
14
|
}`;for(let s=2;s<r.length;s+=2){let a=s>=r.length-1;o+=a?` else {
|
|
15
15
|
${p(r[s],e)}
|
|
16
16
|
}`:` else if (${p(r[s],e)}) {
|
|
17
17
|
${p(r[s+1],e)}
|
|
18
|
-
}`}return o},
|
|
18
|
+
}`}return o},Ye=(e,t,n)=>{let r=`switch (${p(t,e)}) {
|
|
19
19
|
`;for(let o=1;o<n.length;o+=2)o>=n.length-1&&n.length%2===0?r+=`default:
|
|
20
20
|
${p(n[o],e)}
|
|
21
21
|
break;
|
|
22
22
|
`:o+1<n.length&&(r+=`case ${p(n[o],e)}:
|
|
23
23
|
${p(n[o+1],e)}
|
|
24
24
|
break;
|
|
25
|
-
`);return r+="}",r},
|
|
25
|
+
`);return r+="}",r},Ie=(e,t,n)=>{let r=g(t,e),o=n?.props?.id;if(e.isWebGL)return`${r} ${o} = ${p(t,e)};`;let s=C(r);return`var ${o}: ${s} = ${p(t,e)};`},Ue=(e,t,n={})=>{e.code?.structStructFields?.set(t,n);let r=[];for(let s in n){let a=n[s],f=g(a,e);e.isWebGL&&N(e,t,f),r.push(e.isWebGL?`${f} ${s};`:`${s}: ${C(f,e)},`)}let o=r.join(`
|
|
26
26
|
`);return`struct ${t} {
|
|
27
27
|
${o}
|
|
28
|
-
};`},Ne=(e,t,n="",r)=>{let o=e.code?.structStructFields?.get(t)||{};if(e.isWebGL)if(r){let s=[];for(let a in o)s.push(r[a]);return`${t} ${n} = ${t}(${y(s,e)});`}else return`${t} ${n};`;else if(r){let s=[];for(let a in o)s.push(r[a]);return`var ${n}: ${t} = ${t}(${y(s,e)});`}else return`var ${n}: ${t};`},
|
|
29
|
-
`)},
|
|
30
|
-
@group(${
|
|
31
|
-
layout(location = ${
|
|
28
|
+
};`},Ne=(e,t,n="",r)=>{let o=e.code?.structStructFields?.get(t)||{};if(e.isWebGL)if(r){let s=[];for(let a in o)s.push(r[a]);return`${t} ${n} = ${t}(${y(s,e)});`}else return`${t} ${n};`;else if(r){let s=[];for(let a in o)s.push(r[a]);return`var ${n}: ${t} = ${t}(${y(s,e)});`}else return`var ${n}: ${t};`},Ge=(e,t,n)=>{let{id:r,children:o=[],layout:s}=t,[a,...f]=o,i=[],u=[];for(let m=0;m<f.length;m++){let _=s?.inputs?.[m];_?i.push([_.name,_.type==="auto"?g(f[m],e):_.type]):i.push([`p${m}`,g(f[m],e)])}let T=p(a,e),h=g(n,e),$=[];if(e?.isWebGL){for(let[m,_]of i)N(e,r,_),u.push(`${_} ${m}`);N(e,r,h),$.push(`${h} ${r}(${u}) {`)}else{for(let[_,nt]of i)u.push(`${_}: ${C(nt,e)}`);h==="void"?$.push(`fn ${r}(${u}) {`):$.push(`fn ${r}(${u}) -> ${C(h,e)} {`)}return T&&$.push(T),$.push("}"),$.join(`
|
|
29
|
+
`)},De=(e,t,n)=>e.isWebGL?`${n} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${C(n,e)}`,we=(e,t,n)=>{if(e.isWebGL)return`${n} ${t};`;let{location:r=0}=e.gl?.binding?.attrib(t)||{},o=C(n,e);return`@location(${r}) ${t}: ${o}`},Oe=(e,t,n)=>{let r=n==="sampler2D"||n==="texture";if(e.isWebGL)return r?`uniform sampler2D ${t};`:`uniform ${n} ${t};`;if(r){let{group:f=1,binding:i=0}=e.gl?.binding?.texture(t)||{};return`@group(${f}) @binding(${i}) var ${t}Sampler: sampler;
|
|
30
|
+
@group(${f}) @binding(${i+1}) var ${t}: texture_2d<f32>;`}let{group:o=0,binding:s=0}=e.gl?.binding?.uniform(t)||{},a=C(n,e);return`@group(${o}) @binding(${s}) var<uniform> ${t}: ${a};`},Pe=(e,t,n)=>{if(e.isWebGL){let a=`uniform sampler2D ${t};`;if(e.label!=="compute")return a;let f=e.units?.(t);return`${a}
|
|
31
|
+
layout(location = ${f}) out vec4 _${t};`}let{group:r=0,binding:o=0}=e.gl?.binding?.storage(t)||{},s=C(n,e);return`@group(${r}) @binding(${o}) var<storage, read_write> ${t}: array<${s}>;`},We=(e,t,n,r)=>{let o=g(t,e),s=p(n,e),a=p(t,e);return e.isWebGL?o==="int"?`for (int ${r} = 0; ${r} < ${a}; ${r} += 1) {
|
|
32
32
|
${s}
|
|
33
33
|
}`:o==="float"?`for (float ${r} = 0.0; ${r} < ${a}; ${r} += 1.0) {
|
|
34
34
|
${s}
|
|
@@ -48,18 +48,18 @@ ${s}
|
|
|
48
48
|
${s}
|
|
49
49
|
}`:`for (var ${r}: i32 = 0; ${r} < ${a}; ${r}++) {
|
|
50
50
|
${s}
|
|
51
|
-
}`},
|
|
52
|
-
`);if(n==="assign")return`${p(i,t)} = ${p(u,t)};`;if(n==="return")return`return ${p(i,t)};`;if(n==="break")return"break;";if(n==="continue")return"continue;";if(n==="loop")return
|
|
51
|
+
}`},Me=(e,t,n,r)=>e.isWebGL?`const ${n} ${t} = ${r};`:`const ${t}: ${C(n,e)} = ${r};`;var Ve=(e=0)=>{let t=`${e}`;return t.includes(".")?t:t+".0"},p=(e,t)=>{if(t||(t={}),_e(t),c.arr(e))return y(e,t);if(c.str(e))return e;if(c.num(e))return Ve(e);if(c.bol(e))return e?"true":"false";if(!e||!A(e))return"";let{type:n,props:r={}}=e,{id:o="i",children:s=[],fields:a,initialValues:f}=r,[i,u,T,h]=s;if(n==="variable")return o;if(n==="member")return`${p(i,t)}.${p(u,t)}`;if(n==="element")return`${p(i,t)}[${p(u,t)}]`;if(n==="gather")return t.isWebGL?Re(t,i,u,e):`${p(i,t)}[${p(u,t)}]`;if(n==="scatter"){let[m,_]=i.props.children??[];return t.isWebGL?Le(t,m,u):`${p(m,t)}[${p(_,t)}] = ${p(u,t)};`}if(n==="ternary")return t.isWebGL?`(${p(T,t)} ? ${p(i,t)} : ${p(u,t)})`:`select(${p(i,t)}, ${p(u,t)}, ${p(T,t)})`;if(n==="conversion")return i==="float"&&c.num(u)?Ve(u):i==="bool"&&c.bol(u)?u?"true":"false":i==="int"&&c.num(u)?`${u<<0}`:`${C(i,t)}(${y(s.slice(1),t)})`;if(n==="operator")return i==="not"||i==="bitNot"?`!${p(u,t)}`:i==="mod"?p(k(u,T),t):i.endsWith("Assign")?`${p(u,t)} ${H(i)} ${p(T,t)};`:`(${p(u,t)} ${H(i)} ${p(T,t)})`;if(n==="function"){if(i==="negate")return`(-${p(u,t)})`;if(i==="reciprocal")return`(1.0 / ${p(u,t)})`;if(i==="oneMinus")return`(1.0-${p(u,t)})`;if(i==="saturate")return`clamp(${p(u,t)}, 0.0, 1.0)`;if(i==="texture")return Ae(t,u,T,h);if(i==="atan2"&&t.isWebGL)return`atan(${p(u,t)}, ${p(T,t)})`;if(!t.isWebGL){if(i==="dFdx")return`dpdx(${p(u,t)})`;if(i==="dFdy")return`dpdy(${p(u,t)})`}return`${i}(${y(s.slice(1),t)})`}if(n==="scope")return s.map(m=>p(m,t)).join(`
|
|
52
|
+
`);if(n==="assign")return`${p(i,t)} = ${p(u,t)};`;if(n==="return")return`return ${p(i,t)};`;if(n==="break")return"break;";if(n==="continue")return"continue;";if(n==="loop")return We(t,i,u,o);if(n==="if")return Fe(t,i,u,s);if(n==="switch")return Ye(t,i,s);if(n==="declare")return Ie(t,i,u);if(n==="define")return t.code?.headers.has(o)||t.code?.headers.set(o,Ge(t,r,e)),`${o}(${y(s.slice(1),t)})`;if(n==="struct")return t.code?.headers.has(o)||t.code?.headers.set(o,Ue(t,o,a)),Ne(t,o,i.props.id,f);if(n==="varying"){if(t.code?.vertOutputs.has(o))return t.isWebGL?`${o}`:`out.${o}`;let m=De(t,o,g(e,t));return t.code?.fragInputs.set(o,m),t.code?.vertOutputs.set(o,m),t.code?.vertVaryings.set(o,{node:i}),t.isWebGL?`${o}`:`out.${o}`}if(n==="builtin"){if(t.isWebGL)return Ce(t,o);if(o==="position")return"out.position";let m=`@builtin(${o}) ${o}: ${C(g(e,t),t)}`;return t.label==="compute"?t.code?.computeInputs.set(o,m):t.label==="frag"?t.code?.fragInputs.set(o,m):t.label==="vert"&&t.code?.vertInputs.set(o,m),`in.${o}`}if(n==="attribute"||n==="instance")return G(t,o,n,e,i),t.code?.vertInputs.set(o,we(t,o,g(e,t))),t.isWebGL?`${o}`:`in.${o}`;if(t.code?.headers.has(o))return o;let $="";if(n==="uniform"){let m=g(e,t);G(t,o,m,e,i),$=Oe(t,o,m)}return n==="storage"&&(G(t,o,n,e,i),$=Pe(t,o,g(e,t))),n==="constant"&&($=Me(t,o,g(e,t),p(i,t))),$?(t.code?.headers.set(o,$),o):p(i,t)};var ht=(e,t)=>{let n=[],r=new Set,o=new Set,s=a=>{if(o.has(a)||r.has(a))return;o.add(a);let f=t.get(a)||new Set;for(let i of f)e.has(i)&&s(i);o.delete(a),r.add(a),e.has(a)&&n.push([a,e.get(a)])};for(let[a]of e)s(a);return n},q=(e,t)=>{let n=p(e,t),r="";t.isWebGL&&t.code?.dependencies?r=ht(t.code.headers,t.code.dependencies).map(([,f])=>f).join(`
|
|
53
53
|
`):r=Array.from(t.code?.headers?.values()||[]).join(`
|
|
54
|
-
`);let[o,s]=n.split("return ");return s?s=s.replace(";",""):[o,s]=["",n],[r,o.trim(),s]},
|
|
54
|
+
`);let[o,s]=n.split("return ");return s?s=s.replace(";",""):[o,s]=["",n],[r,o.trim(),s]},D=(e,t)=>`struct ${e} {
|
|
55
55
|
${Array.from(t.values()).join(`,
|
|
56
56
|
`)}
|
|
57
|
-
}`,
|
|
57
|
+
}`,Ct=["float","int","sampler2D","samplerCube","sampler3D","sampler2DArray","sampler2DShadow","samplerCubeShadow","sampler2DArrayShadow","isampler2D","isampler3D","isamplerCube","isampler2DArray","usampler2D","usampler3D","usamplerCube","usampler2DArray"],Be=(e,t="highp")=>{for(let n of Ct)e.push(`precision ${t} ${n};`)},Et=(e,t="highp")=>{if(!e)return"highp";if(t==="highp"){let n=e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.HIGH_FLOAT),r=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT);if(n&&n.precision>0&&r&&r.precision>0)return"highp";t="mediump"}if(t==="mediump"){let n=e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT),r=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT);if(n&&n.precision>0&&r&&r.precision>0)return"mediump"}return"lowp"},j=(e,t={})=>{t.code?.headers?.clear(),t.label="frag";let[n,r,o]=q(e,t),s=[];if(t.isWebGL){s.push("#version 300 es"),Be(s,Et(t.gl?.gl,t.gl?.precision)),s.push("out vec4 fragColor;");for(let f of t.code?.fragInputs?.values()||[])s.push(`in ${f}`);s.push(n),s.push("void main() {"),s.push(` ${r}`),s.push(` fragColor = ${o};`)}else t.code?.fragInputs?.size&&s.push(D("Out",t.code.fragInputs)),s.push(n),s.push(`@fragment
|
|
58
58
|
fn main(out: Out) -> @location(0) vec4f {`),s.push(` ${r}`),s.push(` return ${o};`);s.push("}");let a=s.filter(Boolean).join(`
|
|
59
59
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
60
|
-
${a}`),a},
|
|
60
|
+
${a}`),a},K=(e,t={})=>{if(t.code?.headers?.clear(),t.label="vert",t.code)for(let[f,{node:i}]of t.code.vertVaryings.entries())t.code.vertVaryings.set(f,{node:i,code:p(i,t)});let[n,r,o]=q(e,t),s=[];if(t.isWebGL){s.push("#version 300 es");for(let f of t.code?.vertInputs?.values()||[])s.push(`in ${f}`);for(let f of t.code?.vertOutputs?.values()||[])s.push(`out ${f}`);if(s.push(n),s.push("void main() {"),s.push(` ${r}`),s.push(` gl_Position = ${o};`),t.code)for(let[f,i]of t.code.vertVaryings.entries())s.push(` ${f} = ${i.code};`)}else{if(t.code?.vertInputs?.size&&s.push(D("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&s.push(D("Out",t.code.vertOutputs)),s.push(n),s.push("@vertex"),s.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),s.push(" var out: Out;"),s.push(` ${r}`),s.push(` out.position = ${o};`),t.code)for(let[f,i]of t.code.vertVaryings.entries())s.push(` out.${f} = ${i.code};`);s.push(" return out;")}s.push("}");let a=s.filter(Boolean).join(`
|
|
61
61
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
62
|
-
${a}`),a},
|
|
62
|
+
${a}`),a},Z=(e,t={})=>{t.code?.headers?.clear(),t.label="compute";let[n,r,o]=q(e,t),s=[];t.isWebGL?(s.push("#version 300 es"),Be(s,"highp"),s.push(n),s.push("void main() {"),s.push(` ${r}`),s.push(` ${o};`),s.push("}")):(t.code?.computeInputs?.size&&s.push(D("In",t.code.computeInputs)),s.push(n),s.push("@compute @workgroup_size(32)"),s.push(`fn main(${t.code?.computeInputs?.size?"in: In":""}) {`),s.push(` ${r}`),s.push(` ${o};`),s.push("}"));let a=s.filter(Boolean).join(`
|
|
63
63
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
64
|
-
${a}`),a};var X=null,
|
|
64
|
+
${a}`),a};var X=null,R=null,E=e=>{if(!X||(X.props.children||(X.props.children=[]),X.props.children.push(e),e.type!=="return"||!R))return e;let{props:t}=R;return t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e),e};function Q(e,t){t||(t=v());let n=d("variable",{id:t,inferFrom:[e]}),r=d("declare",null,e,n);return E(r),n}var J=(e,t=!1,n)=>{let r=d(t?"scatter":"assign",null,e,n);return E(r),e},ze=e=>E(d("return",{inferFrom:[e]},e)),_t=()=>E(d("break")),yt=()=>E(d("continue")),Xt=(e,t=v())=>(n={},r=v())=>{let o=d("variable",{id:r,inferFrom:[t]}),s=d("struct",{id:t,fields:e,initialValues:n},o);return E(s),o},ee=(e,t,n=R)=>{let[r,o]=[X,R];[X,R]=[e,n];let s=t();s&&ze(s),[X,R]=[r,o]},S=e=>{let t=d("scope");return ee(t,e),t},St=(e,t)=>{let n=S(t),r=d("if",null,e,n);E(r);let o=()=>({ElseIf:(s,a)=>{let f=S(a);return r.props.children.push(s,f),o()},Else:s=>{let a=S(s);r.props.children.push(a)}});return o()},Rt=(e,t)=>{let n=v(),r=S(()=>t({i:d("variable",{id:n,inferFrom:[x("int",0)]})})),o=d("loop",{id:n},e,r);return E(o)},Lt=e=>{let t=d("switch",null,e);E(t);let n=()=>({Case:(...r)=>o=>{let s=S(o);for(let a of r)t.props.children.push(a,s);return n()},Default:r=>{let o=S(r);t.props.children.push(o)}});return n()};function At(e,t){let n=v(),r=(...o)=>{let s=t?.name||n,a=[],f=[];for(let T=0;T<o.length;T++){let h=t?.inputs?.[T];h?f.push({id:h.name,inferFrom:h.type==="auto"?[o[T]]:[x(h.type,o[T])]}):f.push({id:`p${T}`,inferFrom:[o[T]]})}for(let T of f)a.push(d("variable",T));let i=d("scope"),u=d("define",{id:s,layout:t},i,...o);return ee(i,()=>e(a),u),u};return r.getLayout=()=>t,r.setLayout=o=>(t=o,r),r}var Ft=(e,t)=>{if(t==="string")return p(e,null)},d=(e,t,...n)=>{t||(t={}),n.length&&(t.children=n);let r=new Set,o=(f,i)=>{if(i==="type")return e;if(i==="props")return t;if(i==="toVar")return Q.bind(null,a);if(i==="isProxy")return!0;if(i==="toString")return p.bind(null,a);if(i==="fragment")return j.bind(null,a);if(i==="compute")return Z.bind(null,a);if(i==="vertex")return K.bind(null,a);if(i===Symbol.toPrimitive)return Ft.bind(null,a);if(i==="listeners")return r;if(i==="attribute")return(u=v())=>He(a,u);if(i==="instance")return(u=v())=>ke(a,u);if(i==="constant")return(u=v())=>qe(a,u);if(i==="uniform")return(u=v())=>L(a,u);if(i==="variable")return(u=v())=>je(u);if(i==="builtin")return(u=v())=>b(u);if(i==="vertexStage")return(u=v())=>Ke(a,u);if(i==="element")return u=>e==="storage"?Ze(a,u):te(a,u);if(i==="member")return u=>w(a,u);if(i==="assign")return J.bind(null,a,a.type==="gather");if(i==="select")return Qe.bind(null,a);if(ge(i))return i.endsWith("Assign")?(...u)=>E(ne(i,a,...u)):(...u)=>ne(i,a,...u);if(ve(i))return(...u)=>l(i,a,...u);if($e(i))return()=>x(Ee(i),a);if(c.str(i))return ye(i)?te(a,i):w(a,i)},s=(f,i,u)=>(i==="value"&&r.forEach(T=>T(u)),c.str(i)&&w(a,i).assign(u),!0),a=new Proxy({},{get:o,set:s});return a},He=(e,t=v())=>d("attribute",{id:t},e),ke=(e,t=v())=>d("instance",{id:t},e),qe=(e,t=v())=>d("constant",{id:t},e),L=(e,t=v())=>d("uniform",{id:t},e),Yt=(e,t=v())=>d("storage",{id:t},e),je=(e=v())=>d("variable",{id:e}),b=(e=v())=>d("builtin",{id:e}),Ke=(e,t=v())=>d("varying",{id:t,inferFrom:[e]},e),w=(e,t)=>d("member",null,e,t),te=(e,t)=>d("element",null,e,t),Ze=(e,t)=>d("gather",null,e,t),It=(e,t)=>d("scatter",null,e,t),Qe=(e,t,n)=>d("ternary",null,e,t,n),ne=(e,...t)=>d("operator",null,e,...t),l=(e,...t)=>d("function",null,e,...t),x=(e,...t)=>d("conversion",null,e,...t);var Je=b("position"),Ut=b("vertex_index"),Nt=b("instance_index"),Gt=b("front_facing"),Dt=b("frag_depth"),wt=b("sample_index"),Ot=b("sample_mask"),Pt=b("point_coord"),Wt=b("global_invocation_id"),Mt=b("position"),Vt=b("positionWorld"),Bt=b("positionView"),zt=b("normalLocal"),Ht=b("normalWorld"),kt=b("normalView"),qt=b("screenCoordinate"),jt=b("screenUV"),et=e=>x("float",e),Kt=e=>x("int",e),Zt=e=>x("uint",e),Qt=e=>x("bool",e),oe=(e,t)=>x("vec2",e,t),re=(e,t,n)=>x("vec3",e,t,n),Jt=(e,t,n,r)=>x("vec4",e,t,n,r),en=(...e)=>x("mat2",...e),tn=(...e)=>x("mat3",...e),nn=(...e)=>x("mat4",...e),rn=(e,t)=>x("ivec2",e,t),on=(e,t,n)=>x("ivec3",e,t,n),sn=(e,t,n,r)=>x("ivec4",e,t,n,r),an=(e,t)=>x("uvec2",e,t),un=(e,t,n)=>x("uvec3",e,t,n),pn=(e,t,n,r)=>x("uvec4",e,t,n,r),ln=(e,t)=>x("bvec2",e,t),fn=(e,t,n)=>x("bvec3",e,t,n),cn=(e,t,n,r)=>x("bvec4",e,t,n,r),dn=e=>x("texture",e),xn=()=>x("sampler2D"),Tn=(e,t,n)=>c.num(e)&&c.und(t)&&c.und(n)?re(...he(e)):re(e,t,n),tt=L(oe(),"iResolution"),mn=L(oe(),"iMouse"),gn=L(et(),"iTime"),vn=Je.xy.div(tt),bn=e=>l("all",e),$n=e=>l("any",e),hn=e=>l("determinant",e),Cn=(e,t)=>l("distance",e,t),En=(e,t)=>l("dot",e,t),_n=e=>l("length",e),yn=e=>l("lengthSq",e),Xn=e=>l("luminance",e),Sn=(e,t)=>l("cross",e,t),Rn=(e,t,n)=>l("cubeTexture",e,t,n),Ln=(e,t,n)=>l("texture",e,t,n),An=(e,t,n)=>l("texelFetch",e,t,n),Fn=(e,t,n)=>l("textureLod",e,t,n),Yn=e=>l("abs",e),In=e=>l("acos",e),Un=e=>l("acosh",e),Nn=e=>l("asin",e),Gn=e=>l("asinh",e),Dn=e=>l("atan",e),wn=e=>l("atanh",e),On=e=>l("ceil",e),Pn=e=>l("cos",e),Wn=e=>l("cosh",e),Mn=e=>l("dFdx",e),Vn=e=>l("dFdy",e),Bn=e=>l("degrees",e),zn=e=>l("exp",e),Hn=e=>l("exp2",e),kn=e=>l("floor",e),qn=e=>l("fract",e),jn=e=>l("fwidth",e),Kn=e=>l("inverseSqrt",e),Zn=e=>l("log",e),Qn=e=>l("log2",e),Jn=e=>l("negate",e),er=e=>l("normalize",e),tr=e=>l("oneMinus",e),nr=e=>l("radians",e),rr=e=>l("reciprocal",e),or=e=>l("round",e),sr=e=>l("sign",e),ir=e=>l("sin",e),ar=e=>l("sinh",e),ur=e=>l("sqrt",e),pr=e=>l("tan",e),lr=e=>l("tanh",e),fr=e=>l("trunc",e),cr=(e,t)=>l("atan2",e,t),dr=(e,t,n)=>l("clamp",e,t,n),xr=(e,t)=>l("max",e,t),Tr=(e,t)=>l("min",e,t),mr=(e,t,n)=>l("mix",e,t,n),gr=(e,t)=>l("pow",e,t),vr=(e,t)=>l("reflect",e,t),br=(e,t,n)=>l("refract",e,t,n),$r=(e,t,n)=>l("smoothstep",e,t,n),hr=(e,t)=>l("step",e,t),k=(e,t)=>e.sub(e.div(t).floor().mul(t));0&&(module.exports={Break,Continue,Fn,If,Loop,Return,Scope,Switch,abs,acos,acosh,addToScope,all,any,asin,asinh,assign,atan,atan2,atanh,attribute,bool,builtin,bvec2,bvec3,bvec4,ceil,clamp,color,compute,constant,conversion,cos,cosh,create,cross,cubeTexture,dFdx,dFdy,degrees,determinant,distance,dot,element,exp,exp2,float,floor,fract,fragDepth,fragment,frontFacing,function_,fwidth,gather,iMouse,iResolution,iTime,id,instance,instanceIndex,int,inverseSqrt,ivec2,ivec3,ivec4,length,lengthSq,log,log2,luminance,mat2,mat3,mat4,max,member,min,mix,mod,negate,normalLocal,normalView,normalWorld,normalize,oneMinus,operator,pointCoord,position,positionLocal,positionView,positionWorld,pow,radians,reciprocal,reflect,refract,round,sampleIndex,sampleMask,sampler2D,scatter,scoped,screenCoordinate,screenUV,select,sign,sin,sinh,smoothstep,sqrt,step,storage,struct,tan,tanh,texelFetch,texture,texture2D,textureLod,toVar,trunc,uint,uniform,uv,uvec2,uvec3,uvec4,variable,vec2,vec3,vec4,vertex,vertexIndex,vertexStage});
|
|
65
65
|
//# sourceMappingURL=node.cjs.map
|