glre 0.40.0 → 0.41.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/addons.cjs +1 -1
- package/dist/addons.cjs.map +1 -1
- package/dist/addons.d.ts +4 -3
- package/dist/addons.js +1 -1
- package/dist/addons.js.map +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +12 -11
- package/dist/node.cjs +16 -16
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +5 -4
- package/dist/node.js +15 -15
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +9 -8
- package/dist/solid.d.ts +9 -8
- package/package.json +1 -1
- package/src/node/scope.ts +3 -2
- package/src/node/types.ts +1 -1
- package/src/node/utils/index.ts +2 -1
- package/src/node/utils/infer.ts +2 -1
- package/src/node/utils/utils.ts +6 -11
- package/src/types.ts +4 -3
- package/src/utils/helpers.ts +25 -8
- package/src/utils/program.ts +11 -4
- package/src/utils/webgl.ts +7 -3
- package/src/utils/webgpu.ts +12 -4
package/dist/node.d.ts
CHANGED
|
@@ -123,10 +123,10 @@ type GL = EventState<{
|
|
|
123
123
|
uniform(target: {
|
|
124
124
|
[key: string]: Uniform;
|
|
125
125
|
}): GL;
|
|
126
|
-
_texture?(key: string, value:
|
|
127
|
-
texture(key: string, value:
|
|
126
|
+
_texture?(key: string, value: Texture$1): GL;
|
|
127
|
+
texture(key: string, value: Texture$1): GL;
|
|
128
128
|
texture(target: {
|
|
129
|
-
[key: string]:
|
|
129
|
+
[key: string]: Texture$1;
|
|
130
130
|
}): GL;
|
|
131
131
|
_attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
132
132
|
attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
@@ -145,6 +145,7 @@ type GL = EventState<{
|
|
|
145
145
|
}): GL;
|
|
146
146
|
}>;
|
|
147
147
|
type Uniform = number | number[] | Float32Array;
|
|
148
|
+
type Texture$1 = string | HTMLImageElement | HTMLVideoElement;
|
|
148
149
|
type Attribute = number[] | Float32Array;
|
|
149
150
|
type Storage = number[] | Float32Array;
|
|
150
151
|
/**
|
|
@@ -329,7 +330,7 @@ type XImpl<T extends C> = _X<T> & {
|
|
|
329
330
|
};
|
|
330
331
|
type C = Constants;
|
|
331
332
|
type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>;
|
|
332
|
-
type Y<T extends C = C> = number | number[] | string | boolean | undefined | X<T>;
|
|
333
|
+
type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>;
|
|
333
334
|
type Methods = Functions | Operators | Conversions | Swizzles | '__nodeType' | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString' | 'element' | 'select';
|
|
334
335
|
interface _X<T extends C> {
|
|
335
336
|
readonly __nodeType?: T;
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var w=["toBool","toUInt","toInt","toFloat","toBVec2","toIVec2","toUVec2","toVec2","toBVec3","toIVec3","toUVec3","toVec3","toBVec4","toIVec4","toUVec4","toVec4","toColor","toMat2","toMat3","toMat4"],G={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"},P=Object.keys(G),D={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:">>="},j=Object.keys(D),M={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},K={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"},Z=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],J=["and","or"],Q=[["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"]],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"},W={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"},te=[...Object.keys(W),"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"],O=(e,t)=>e===t,Me=(e,t)=>Q.some(([n,r,s])=>n===e&&r===t||n===t&&r===e),ne=(e,t,n)=>Z.includes(n)||J.includes(n)?O(e,t):O(e,t)?!0:Me(e,t),re=(e,t,n)=>{if(Z.includes(n)||J.includes(n))return"bool";if(O(e,t))return e;let r=Q.find(([s,o,a])=>s===e&&o===t||s===t&&o===e);return r?r[2]:e};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)};var We=e=>[1,2,3,4,9,16].includes(e),Ve=(e,t=3)=>e%t===0?Math.floor(e/t):-1,V=(e,t=1,n=console.warn)=>{let r=Ve(e,t);return We(r)||n(`glre attribute error: Invalid attribute length ${e}. Must divide by vertex count (${t}) with valid stride (1,2,3,4,9,16)`),r};var dt=`
|
|
2
2
|
struct In { @builtin(vertex_index) vertex_index: u32 }
|
|
3
3
|
struct Out { @builtin(position) position: vec4f }
|
|
4
4
|
@vertex
|
|
@@ -9,7 +9,7 @@ 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 L=(e=1024)=>{if(l.num(e)){let s=Math.sqrt(e),o=Math.ceil(s);return Number.isInteger(s)||console.warn(`GLRE Storage Warning: particleCount (${e}) is not a square. Using ${o}x${o} texture may waste GPU memory. Consider using [width, height] format for optimal storage.`),{x:o,y:o}}let[t,n,r]=e;if(r!==void 0){let s=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} = ${s}.`),{x:t,y:s}}return{x:t,y:n}};var oe=e=>l.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),se=e=>j.includes(e),ie=e=>te.includes(e),F=e=>l.obj(e)?!1:e instanceof Element,ae=e=>w.includes(e),A=e=>!e||typeof e!="object"?!1:e.isProxy,B=e=>l.str(e)?P.includes(e):!1,ue=e=>{let t=(e>>16&255)/255,n=(e>>8&255)/255,r=(e&255)/255;return[t,n,r]},Be=0,v=()=>`x${Be++}`,pe=(e,t)=>{if(t==="global_invocation_id")return`uvec3(uint(gl_FragCoord.y) * uint(${L(e.gl?.particleCount).x}) + uint(gl_FragCoord.x), 0u, 0u)`;let n=ee[t];if(!n)throw new Error(`Error: unknown builtin variable ${t}`);return n},h=(e,t)=>l.str(e)?t?.isWebGL?e:G[e]||e:"",z=e=>D[e]||e,ce=e=>{let t=w.indexOf(e);return t!==-1?P[t]:"float"},fe=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),le=e=>l.num(e)||l.str(e)&&/^\d+$/.test(e),U=(e,t="",n)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),B(n)||e.code.dependencies.get(t).add(n)},ze=(e,t,n)=>e.isWebGL?n==="attribute"?r=>e.gl?.attribute?.(t,r):n==="instance"?r=>e.gl?.instance?.(t,r):n==="texture"?r=>e.gl?.texture?.(t,r):r=>e.gl?.uniform?.(t,r):n==="attribute"?r=>e.gl?._attribute?.(t,r):n==="instance"?r=>e.gl?._instance?.(t,r):n==="texture"?r=>e.gl?._texture?.(t,r):r=>e.gl?._uniform?.(t,r),ke=(e,t)=>{if(l.und(e))return;if(!A(e))return t(e);if(e.type!=="conversion")return;let n=e.props.children?.slice(1);l.und(n?.[0])||t(n.map(r=>r??n[0]))},k=(e,t,n,r,s)=>{let o=ze(e,t,n);return ke(s,o),r.listeners.add(o),o};var He=e=>K[e],qe=(e,t,n)=>(ne(e,t,n)||console.warn(`GLRE Type Warning: Invalid operator '${n}' between types '${e}' and '${t}'`),re(e,t,n)),je=e=>l.bol(e)?"bool":l.str(e)?"texture":l.num(e)?"float":l.arr(e)?M[e.length]:F(e)?"texture":"void",N=e=>{let t=M[e];if(!t)throw`glre node system error: Cannot infer type from array length ${e}. Check your data size. Supported: 1(float), 2(vec2), 3(vec3), 4(vec4), 9(mat3), 16(mat4)`;return t},de=(e,t)=>{if(e.length===0)return"void";let[n]=e;return l.str(n)?n:g(n,t)},Ke=e=>W[e],Ze=(e,t)=>{let{type:n,props:r}=e,{id:s,children:o=[],inferFrom:a,layout:f}=r,[i,u,m]=o;if(n==="conversion")return i;if(n==="operator")return qe(g(u,t),g(m,t),i);if(n==="builtin")return He(s);if(n==="function")return Ke(i)||g(u,t);if(n==="define")return B(f?.type)?f?.type:!a||a.length===0?"void":de(a,t);if(n==="attribute"&&l.arr(i)){let $=V(i.length,t.gl?.count,t.gl?.error);return N($)}if(n==="instance"&&l.arr(i)){let $=V(i.length,t.gl?.instanceCount,t.gl?.error);return N($)}if(n==="member"){if(oe(u))return N(u.length);if(A(i)){let $=g(i,t),C=t.code?.structStructFields?.get($);if(C&&C[u])return g(C[u],t)}return"float"}return a?de(a,t):i?g(i,t):"void"},g=(e,t)=>{if(t||(t={}),!A(e))return je(e);if(l.arr(e))return N(e.length);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let n=Ze(e,t);return t.infers.set(e,n),n};var y=(e,t)=>e.filter(n=>!l.und(n)&&!l.nul(n)).map(n=>p(n,t)).join(", "),xe=(e,t,n,r)=>{let s=()=>{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}`)},o=p(n,e),a=L(e.gl?.particleCount),f=`int(${o}) % ${a.x}`,i=`int(${o}) / ${a.x}`;return`texelFetch(${p(t,e)}, ivec2(${f}, ${i}), 0)${s()}`},Te=(e,t,n)=>{let r=p(t,e),s=p(n,e),o=g(n,e);if(o==="float")return`_${r} = vec4(${s}, 0.0, 0.0, 1.0);`;if(o==="vec2")return`_${r} = vec4(${s}, 0.0, 1.0);`;if(o==="vec3")return`_${r} = vec4(${s}, 1.0);`;if(o==="vec4")return`_${r} = ${s};`;throw new Error(`Unsupported storage scatter type: ${o}`)},me=(e,t,n,r)=>{if(e.isWebGL)return`texture(${y(r?[t,n,r]:[t,n],e)})`;let s=p(t,e),o=[s,s+"Sampler",p(n,e)];return r?(o.push(p(r,e)),`textureSampleLevel(${o})`):`textureSample(${o})`},ge=(e,t,n,r)=>{let s=`if (${p(t,e)}) {
|
|
13
13
|
${p(n,e)}
|
|
14
14
|
}`;for(let o=2;o<r.length;o+=2){let a=o>=r.length-1;s+=a?` else {
|
|
15
15
|
${p(r[o],e)}
|
|
@@ -22,13 +22,13 @@ break;
|
|
|
22
22
|
`:s+1<n.length&&(r+=`case ${p(n[s],e)}:
|
|
23
23
|
${p(n[s+1],e)}
|
|
24
24
|
break;
|
|
25
|
-
`);return r+="}",r},
|
|
25
|
+
`);return r+="}",r},be=(e,t,n)=>{let r=g(t,e),s=n?.props?.id;if(e.isWebGL)return`${r} ${s} = ${p(t,e)};`;let o=h(r);return`var ${s}: ${o} = ${p(t,e)};`},$e=(e,t,n={})=>{e.code?.structStructFields?.set(t,n);let r=[];for(let o in n){let a=n[o],f=g(a,e);e.isWebGL&&U(e,t,f),r.push(e.isWebGL?`${f} ${o};`:`${o}: ${h(f,e)},`)}let s=r.join(`
|
|
26
26
|
`);return`struct ${t} {
|
|
27
27
|
${s}
|
|
28
|
-
};`}
|
|
29
|
-
`)},
|
|
30
|
-
@group(${f}) @binding(${i+1}) var ${t}: texture_2d<f32>;`}let{group:s=0,binding:o=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},a=
|
|
31
|
-
layout(location = ${f}) out vec4 _${t};`}let{group:r=0,binding:s=0}=e.gl?.webgpu?.storages.map.get(t)||{},o=
|
|
28
|
+
};`},Ce=(e,t,n="",r)=>{let s=e.code?.structStructFields?.get(t)||{};if(e.isWebGL)if(r){let o=[];for(let a in s)o.push(r[a]);return`${t} ${n} = ${t}(${y(o,e)});`}else return`${t} ${n};`;else if(r){let o=[];for(let a in s)o.push(r[a]);return`var ${n}: ${t} = ${t}(${y(o,e)});`}else return`var ${n}: ${t};`},he=(e,t,n)=>{let{id:r,children:s=[],layout:o}=t,[a,...f]=s,i=[],u=[];for(let x=0;x<f.length;x++){let E=o?.inputs?.[x];E?i.push([E.name,E.type==="auto"?g(f[x],e):E.type]):i.push([`p${x}`,g(f[x],e)])}let m=p(a,e),$=g(n,e),C=[];if(e?.isWebGL){for(let[x,E]of i)U(e,r,E),u.push(`${E} ${x}`);U(e,r,$),C.push(`${$} ${r}(${u}) {`)}else{for(let[E,De]of i)u.push(`${E}: ${h(De,e)}`);$==="void"?C.push(`fn ${r}(${u}) {`):C.push(`fn ${r}(${u}) -> ${h($,e)} {`)}return m&&C.push(m),C.push("}"),C.join(`
|
|
29
|
+
`)},Ee=(e,t,n)=>e.isWebGL?`${n} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${h(n,e)}`,_e=(e,t,n)=>{if(e.isWebGL)return`${n} ${t};`;let{location:r=0}=e.gl?.webgpu?.attribs.map.get(t)||{},s=h(n,e);return`@location(${r}) ${t}: ${s}`},ye=(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?.webgpu?.textures.map.get(t)||{};return`@group(${f}) @binding(${i}) var ${t}Sampler: sampler;
|
|
30
|
+
@group(${f}) @binding(${i+1}) var ${t}: texture_2d<f32>;`}let{group:s=0,binding:o=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},a=h(n,e);return`@group(${s}) @binding(${o}) var<uniform> ${t}: ${a};`},Xe=(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:s=0}=e.gl?.webgpu?.storages.map.get(t)||{},o=h(n,e);return`@group(${r}) @binding(${s}) var<storage, read_write> ${t}: array<${o}>;`},Se=(e,t,n,r)=>{let s=g(t,e),o=p(n,e),a=p(t,e);return e.isWebGL?s==="int"?`for (int ${r} = 0; ${r} < ${a}; ${r} += 1) {
|
|
32
32
|
${o}
|
|
33
33
|
}`:s==="float"?`for (float ${r} = 0.0; ${r} < ${a}; ${r} += 1.0) {
|
|
34
34
|
${o}
|
|
@@ -48,22 +48,22 @@ ${o}
|
|
|
48
48
|
${o}
|
|
49
49
|
}`:`for (var ${r}: i32 = 0; ${r} < ${a}; ${r}++) {
|
|
50
50
|
${o}
|
|
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
|
+
}`},Re=(e,t,n,r)=>e.isWebGL?`const ${n} ${t} = ${r};`:`const ${t}: ${h(n,e)} = ${r};`;var p=(e,t)=>{if(t||(t={}),fe(t),l.arr(e))return y(e,t);if(l.str(e))return e;if(l.num(e)){let x=`${e}`;return x.includes(".")?x:x+".0"}if(l.bol(e))return e?"true":"false";if(F(e))throw"";if(!e)return"";let{type:n,props:r={}}=e,{id:s="i",children:o=[],fields:a,initialValues:f}=r,[i,u,m,$]=o;if(n==="variable")return s;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?xe(t,i,u,e):`${p(i,t)}[${p(u,t)}]`;if(n==="scatter"){let[x,E]=i.props.children??[];return t.isWebGL?Te(t,x,u):`${p(x,t)}[${p(E,t)}] = ${p(u,t)};`}if(n==="ternary")return t.isWebGL?`(${p(m,t)} ? ${p(i,t)} : ${p(u,t)})`:`select(${p(i,t)}, ${p(u,t)}, ${p(m,t)})`;if(n==="conversion")return`${h(i,t)}(${y(o.slice(1),t)})`;if(n==="operator")return i==="not"||i==="bitNot"?`!${p(u,t)}`:i==="mod"?p(Ye(u,m),t):i.endsWith("Assign")?`${p(u,t)} ${z(i)} ${p(m,t)};`:`(${p(u,t)} ${z(i)} ${p(m,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 me(t,u,m,$);if(i==="atan2"&&t.isWebGL)return`atan(${p(u,t)}, ${p(m,t)})`;if(!t.isWebGL){if(i==="dFdx")return`dpdx(${p(u,t)})`;if(i==="dFdy")return`dpdy(${p(u,t)})`}return`${i}(${y(o.slice(1),t)})`}if(n==="scope")return o.map(x=>p(x,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 Se(t,i,u,s);if(n==="if")return ge(t,i,u,o);if(n==="switch")return ve(t,i,o);if(n==="declare")return be(t,i,u);if(n==="define")return t.code?.headers.has(s)||t.code?.headers.set(s,he(t,r,e)),`${s}(${y(o.slice(1),t)})`;if(n==="struct")return t.code?.headers.has(s)||t.code?.headers.set(s,$e(t,s,a)),Ce(t,s,i.props.id,f);if(n==="varying"){if(t.code?.vertOutputs.has(s))return t.isWebGL?`${s}`:`out.${s}`;let x=Ee(t,s,g(e,t));return t.code?.fragInputs.set(s,x),t.code?.vertOutputs.set(s,x),t.code?.vertVaryings.set(s,p(i,t)),t.isWebGL?`${s}`:`out.${s}`}if(n==="builtin"){if(t.isWebGL)return pe(t,s);if(s==="position")return"out.position";let x=`@builtin(${s}) ${s}: ${h(g(e,t),t)}`;return t.label==="compute"?t.code?.computeInputs.set(s,x):t.label==="frag"?t.code?.fragInputs.set(s,x):t.label==="vert"&&t.code?.vertInputs.set(s,x),`in.${s}`}if(n==="attribute"||n==="instance")return k(t,s,n,e,i),t.code?.vertInputs.set(s,_e(t,s,g(e,t))),t.isWebGL?`${s}`:`in.${s}`;if(t.code?.headers.has(s))return s;let C="";if(n==="uniform"){let x=g(e,t);k(t,s,x,e,i),C=ye(t,s,x)}return n==="storage"&&(C=Xe(t,s,g(e,t))),n==="constant"&&(C=Re(t,s,g(e,t),p(i,t))),C?(t.code?.headers.set(s,C),s):p(i,t)};var Je=`
|
|
53
53
|
#version 300 es
|
|
54
54
|
precision mediump float;
|
|
55
55
|
out vec4 fragColor;
|
|
56
|
-
`.trim(),
|
|
56
|
+
`.trim(),Qe=(e,t)=>{let n=[],r=new Set,s=new Set,o=a=>{if(s.has(a)||r.has(a))return;s.add(a);let f=t.get(a)||new Set;for(let i of f)e.has(i)&&o(i);s.delete(a),r.add(a),e.has(a)&&n.push([a,e.get(a)])};for(let[a]of e)o(a);return n},H=(e,t)=>{let n=p(e,t),r="";t.isWebGL&&t.code?.dependencies?r=Qe(t.code.headers,t.code.dependencies).map(([,f])=>f).join(`
|
|
57
57
|
`):r=Array.from(t.code?.headers?.values()||[]).join(`
|
|
58
|
-
`);let[s,o]=n.split("return ");return o?o=o.replace(";",""):[s,o]=["",n],[r,s.trim(),o]},
|
|
58
|
+
`);let[s,o]=n.split("return ");return o?o=o.replace(";",""):[s,o]=["",n],[r,s.trim(),o]},I=(e,t)=>`struct ${e} {
|
|
59
59
|
${Array.from(t.values()).join(`,
|
|
60
60
|
`)}
|
|
61
|
-
}`,
|
|
61
|
+
}`,Le=(e,t={})=>{t.code?.headers?.clear(),t.label="frag";let[n,r,s]=H(e,t),o=[];if(t.isWebGL){o.push(Je);for(let f of t.code?.fragInputs?.values()||[])o.push(`in ${f}`);o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` fragColor = ${s};`)}else t.code?.fragInputs?.size&&o.push(I("Out",t.code.fragInputs)),o.push(n),o.push(`@fragment
|
|
62
62
|
fn main(out: Out) -> @location(0) vec4f {`),o.push(` ${r}`),o.push(` return ${s};`);o.push("}");let a=o.filter(Boolean).join(`
|
|
63
63
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
64
|
-
${a}`),a},Fe=(e,t={})=>{t.code?.headers?.clear(),t.label="vert";let[n,r,s]=
|
|
64
|
+
${a}`),a},Fe=(e,t={})=>{t.code?.headers?.clear(),t.label="vert";let[n,r,s]=H(e,t),o=[];if(t.isWebGL){o.push("#version 300 es");for(let f of t.code?.vertInputs?.values()||[])o.push(`in ${f}`);for(let f of t.code?.vertOutputs?.values()||[])o.push(`out ${f}`);o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` gl_Position = ${s};`);for(let[f,i]of t.code?.vertVaryings?.entries()||[])o.push(` ${f} = ${i};`)}else{t.code?.vertInputs?.size&&o.push(I("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&o.push(I("Out",t.code.vertOutputs)),o.push(n),o.push("@vertex"),o.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),o.push(" var out: Out;"),o.push(` ${r}`),o.push(` out.position = ${s};`);for(let[f,i]of t.code?.vertVaryings?.entries()||[])o.push(` out.${f} = ${i};`);o.push(" return out;")}o.push("}");let a=o.filter(Boolean).join(`
|
|
65
65
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
66
|
-
${a}`),a},Ae=(e,t={})=>{t.code?.headers?.clear(),t.label="compute";let[n,r,s]=
|
|
66
|
+
${a}`),a},Ae=(e,t={})=>{t.code?.headers?.clear(),t.label="compute";let[n,r,s]=H(e,t),o=[];t.isWebGL?(o.push("#version 300 es"),o.push("precision mediump float;"),o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` ${s};`),o.push("}")):(t.code?.computeInputs?.size&&o.push(I("In",t.code.computeInputs)),o.push(n),o.push("@compute @workgroup_size(32)"),o.push(`fn main(${t.code?.computeInputs?.size?"in: In":""}) {`),o.push(` ${r}`),o.push(` ${s};`),o.push("}"));let a=o.filter(Boolean).join(`
|
|
67
67
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
68
|
-
${a}`),a};var X=null,S=null,
|
|
68
|
+
${a}`),a};var X=null,S=null,_=e=>{if(!X)return;if(X.props.children||(X.props.children=[]),X.props.children.push(e),e.type!=="return"||!S)return e;let{props:t}=S;return t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e),e};function Ue(e,t){t||(t=v());let n=d("variable",{id:t,inferFrom:[e]}),r=d("declare",null,e,n);return _(r),n}var Ne=(e,t=!1,n)=>{let r=d(t?"scatter":"assign",null,e,n);return _(r),e},et=e=>_(d("return",{inferFrom:[e]},e)),Wt=()=>_(d("break")),Vt=()=>_(d("continue")),Bt=(e,t=v())=>(n={},r=v())=>{let s=d("variable",{id:r,inferFrom:[t]}),o=d("struct",{id:t,fields:e,initialValues:n},s);return _(o),s},Ie=(e,t,n=S)=>{let[r,s]=[X,S];[X,S]=[e,n];let o=t();o&&et(o),[X,S]=[r,s]},R=e=>{let t=d("scope");return Ie(t,e),t},zt=(e,t)=>{let n=R(t),r=d("if",null,e,n);_(r);let s=()=>({ElseIf:(o,a)=>{let f=R(a);return r.props.children.push(o,f),s()},Else:o=>{let a=R(o);r.props.children.push(a)}});return s()},kt=(e,t)=>{let n=v(),r=R(()=>t({i:d("variable",{id:n,inferFrom:[T("int",0)]})})),s=d("loop",{id:n},e,r);return _(s)},Ht=e=>{let t=d("switch",null,e);_(t);let n=()=>({Case:(...r)=>s=>{let o=R(s);for(let a of r)t.props.children.push(a,o);return n()},Default:r=>{let s=R(r);t.props.children.push(s)}});return n()};function qt(e,t){let n=v(),r=(...s)=>{let o=t?.name||n,a=[],f=[];for(let m=0;m<s.length;m++){let $=t?.inputs?.[m];$?f.push({id:$.name,inferFrom:$.type==="auto"?[s[m]]:[T($.type,s[m])]}):f.push({id:`p${m}`,inferFrom:[s[m]]})}for(let m of f)a.push(d("variable",m));let i=d("scope"),u=d("define",{id:o,layout:t},i,...s);return Ie(i,()=>e(a),u),u};return r.getLayout=()=>t,r.setLayout=s=>(t=s,r),r}var tt=(e,t)=>{if(t==="string")return p(e,null)},d=(e,t,...n)=>{t||(t={}),n.length&&(t.children=n);let r=new Set,s=(f,i)=>{if(i==="type")return e;if(i==="props")return t;if(i!=="__nodeType"){if(i==="toVar")return Ue.bind(null,a);if(i==="isProxy")return!0;if(i==="toString")return p.bind(null,a);if(i==="fragment")return Le.bind(null,a);if(i==="compute")return Ae.bind(null,a);if(i==="vertex")return Fe.bind(null,a);if(i===Symbol.toPrimitive)return tt.bind(null,a);if(i==="listeners")return r;if(i==="attribute")return(u=v())=>nt(a,u);if(i==="instance")return(u=v())=>rt(a,u);if(i==="constant")return(u=v())=>ot(a,u);if(i==="uniform")return(u=v())=>Y(a,u);if(i==="variable")return(u=v())=>st(u);if(i==="builtin")return(u=v())=>b(u);if(i==="vertexStage")return(u=v())=>it(a,u);if(i==="element")return u=>e==="storage"?at(a,u):Oe(a,u);if(i==="member")return u=>q(a,u);if(i==="assign")return Ne.bind(null,a,a.type==="gather");if(i==="select")return ut.bind(null,a);if(se(i))return i.endsWith("Assign")?(...u)=>_(we(i,a,...u)):(...u)=>we(i,a,...u);if(ie(i))return(...u)=>c(i,a,...u);if(ae(i))return()=>T(ce(i),a);if(l.str(i))return le(i)?Oe(a,i):q(a,i)}},o=(f,i,u)=>(i==="value"&&r.forEach(m=>m(u)),l.str(i)&&q(a,i).assign(u),!0),a=new Proxy({},{get:s,set:o});return a},nt=(e,t=v())=>d("attribute",{id:t},e),rt=(e,t=v())=>d("instance",{id:t},e),ot=(e,t=v())=>d("constant",{id:t},e),Y=(e,t=v())=>d("uniform",{id:t},e),en=(e,t=v())=>d("storage",{id:t},e),st=(e=v())=>d("variable",{id:e}),b=(e=v())=>d("builtin",{id:e}),it=(e,t=v())=>d("varying",{id:t,inferFrom:[e]},e),q=(e,t)=>d("member",null,e,t),Oe=(e,t)=>d("element",null,e,t),at=(e,t)=>d("gather",null,e,t),tn=(e,t)=>d("scatter",null,e,t),ut=(e,t,n)=>d("ternary",null,e,t,n),we=(e,...t)=>d("operator",null,e,...t),c=(e,...t)=>d("function",null,e,...t),T=(e,...t)=>d("conversion",null,e,...t);var pt=b("position"),an=b("vertex_index"),un=b("instance_index"),pn=b("front_facing"),cn=b("frag_depth"),fn=b("sample_index"),ln=b("sample_mask"),dn=b("point_coord"),xn=b("global_invocation_id"),Tn=b("position"),mn=b("positionWorld"),gn=b("positionView"),vn=b("normalLocal"),bn=b("normalWorld"),$n=b("normalView"),Cn=b("screenCoordinate"),hn=b("screenUV"),ct=e=>T("float",e),En=e=>T("int",e),_n=e=>T("uint",e),yn=e=>T("bool",e),Pe=(e,t)=>T("vec2",e,t),Ge=(e,t,n)=>T("vec3",e,t,n),Xn=(e,t,n,r)=>T("vec4",e,t,n,r),Sn=(...e)=>T("mat2",...e),Rn=(...e)=>T("mat3",...e),Yn=(...e)=>T("mat4",...e),Ln=(e,t)=>T("ivec2",e,t),Fn=(e,t,n)=>T("ivec3",e,t,n),An=(e,t,n,r)=>T("ivec4",e,t,n,r),Un=(e,t)=>T("uvec2",e,t),Nn=(e,t,n)=>T("uvec3",e,t,n),In=(e,t,n,r)=>T("uvec4",e,t,n,r),On=(e,t)=>T("bvec2",e,t),wn=(e,t,n)=>T("bvec3",e,t,n),Gn=(e,t,n,r)=>T("bvec4",e,t,n,r),Pn=e=>T("texture",e),Dn=()=>T("sampler2D"),Mn=(e,t,n)=>l.num(e)&&l.und(t)&&l.und(n)?Ge(...ue(e)):Ge(e,t,n),ft=Y(Pe(),"iResolution"),Wn=Y(Pe(),"iMouse"),Vn=Y(ct(),"iTime"),Bn=pt.xy.div(ft),zn=e=>c("all",e),kn=e=>c("any",e),Hn=e=>c("determinant",e),qn=(e,t)=>c("distance",e,t),jn=(e,t)=>c("dot",e,t),Kn=e=>c("length",e),Zn=e=>c("lengthSq",e),Jn=e=>c("luminance",e),Qn=(e,t)=>c("cross",e,t),er=(e,t,n)=>c("cubeTexture",e,t,n),tr=(e,t,n)=>c("texture",e,t,n),nr=(e,t,n)=>c("texelFetch",e,t,n),rr=(e,t,n)=>c("textureLod",e,t,n),or=e=>c("abs",e),sr=e=>c("acos",e),ir=e=>c("acosh",e),ar=e=>c("asin",e),ur=e=>c("asinh",e),pr=e=>c("atan",e),cr=e=>c("atanh",e),fr=e=>c("ceil",e),lr=e=>c("cos",e),dr=e=>c("cosh",e),xr=e=>c("dFdx",e),Tr=e=>c("dFdy",e),mr=e=>c("degrees",e),gr=e=>c("exp",e),vr=e=>c("exp2",e),br=e=>c("floor",e),$r=e=>c("fract",e),Cr=e=>c("fwidth",e),hr=e=>c("inverseSqrt",e),Er=e=>c("log",e),_r=e=>c("log2",e),yr=e=>c("negate",e),Xr=e=>c("normalize",e),Sr=e=>c("oneMinus",e),Rr=e=>c("radians",e),Yr=e=>c("reciprocal",e),Lr=e=>c("round",e),Fr=e=>c("sign",e),Ar=e=>c("sin",e),Ur=e=>c("sinh",e),Nr=e=>c("sqrt",e),Ir=e=>c("tan",e),Or=e=>c("tanh",e),wr=e=>c("trunc",e),Gr=(e,t)=>c("atan2",e,t),Pr=(e,t,n)=>c("clamp",e,t,n),Dr=(e,t)=>c("max",e,t),Mr=(e,t)=>c("min",e,t),Wr=(e,t,n)=>c("mix",e,t,n),Vr=(e,t)=>c("pow",e,t),Br=(e,t)=>c("reflect",e,t),zr=(e,t,n)=>c("refract",e,t,n),kr=(e,t,n)=>c("smoothstep",e,t,n),Hr=(e,t)=>c("step",e,t),Ye=(e,t)=>e.sub(e.div(t).floor().mul(t));export{Wt as Break,Vt as Continue,qt as Fn,zt as If,kt as Loop,et as Return,R as Scope,Ht as Switch,or as abs,sr as acos,ir as acosh,_ as addToScope,zn as all,kn as any,ar as asin,ur as asinh,Ne as assign,pr as atan,Gr as atan2,cr as atanh,nt as attribute,yn as bool,b as builtin,On as bvec2,wn as bvec3,Gn as bvec4,fr as ceil,Pr as clamp,Mn as color,Ae as compute,ot as constant,T as conversion,lr as cos,dr as cosh,d as create,Qn as cross,er as cubeTexture,xr as dFdx,Tr as dFdy,mr as degrees,Hn as determinant,qn as distance,jn as dot,Oe as element,gr as exp,vr as exp2,ct as float,br as floor,$r as fract,cn as fragDepth,Le as fragment,pn as frontFacing,c as function_,Cr as fwidth,at as gather,Wn as iMouse,ft as iResolution,Vn as iTime,xn as id,rt as instance,un as instanceIndex,En as int,hr as inverseSqrt,Ln as ivec2,Fn as ivec3,An as ivec4,Kn as length,Zn as lengthSq,Er as log,_r as log2,Jn as luminance,Sn as mat2,Rn as mat3,Yn as mat4,Dr as max,q as member,Mr as min,Wr as mix,Ye as mod,yr as negate,vn as normalLocal,$n as normalView,bn as normalWorld,Xr as normalize,Sr as oneMinus,we as operator,dn as pointCoord,pt as position,Tn as positionLocal,gn as positionView,mn as positionWorld,Vr as pow,Rr as radians,Yr as reciprocal,Br as reflect,zr as refract,Lr as round,fn as sampleIndex,ln as sampleMask,Dn as sampler2D,tn as scatter,Ie as scoped,Cn as screenCoordinate,hn as screenUV,ut as select,Fr as sign,Ar as sin,Ur as sinh,kr as smoothstep,Nr as sqrt,Hr as step,en as storage,Bt as struct,Ir as tan,Or as tanh,nr as texelFetch,tr as texture,Pn as texture2D,rr as textureLod,Ue as toVar,wr as trunc,_n as uint,Y as uniform,Bn as uv,Un as uvec2,Nn as uvec3,In as uvec4,st as variable,Pe as vec2,Ge as vec3,Xn as vec4,Fe as vertex,an as vertexIndex,it as vertexStage};
|
|
69
69
|
//# sourceMappingURL=node.js.map
|