glre 0.31.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.
@@ -0,0 +1,54 @@
1
+ import * as reev from 'reev';
2
+ import * as refr_dist_types_687121c7 from 'refr/dist/types-687121c7';
3
+ import { GL, NodeProxy, WebGPUState, WebGLState, Uniform, Attribute } from './index.js';
4
+ export { AttribData, Attributes, BaseNodeProxy, Constants, Conversions, DynamicProperties, Fn, FnLayout, Functions, GLClearMode, GLDrawMode, GLDrawType, If, Loop, NodeContext, NodeProps, NodeTypes, Operators, PrecisionMode, Return, Switch, Swizzles, TextureData, UniformData, Uniforms, X, 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, default as 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 } from './index.js';
5
+ export { Frame, Fun, Queue } from 'refr';
6
+
7
+ declare const useGL: (props?: Partial<GL>) => reev.EventState<{
8
+ isNative: boolean;
9
+ isWebGL: boolean;
10
+ isLoop: boolean;
11
+ isGL: true;
12
+ width: number;
13
+ height: number;
14
+ size: [number, number];
15
+ mouse: [number, number];
16
+ count: number;
17
+ el: HTMLCanvasElement;
18
+ vs: string | NodeProxy;
19
+ fs: string | NodeProxy;
20
+ vert: string | NodeProxy;
21
+ frag: string | NodeProxy;
22
+ vertex: string | NodeProxy;
23
+ fragment: string | NodeProxy;
24
+ webgpu: WebGPUState;
25
+ webgl: WebGLState;
26
+ queue: refr_dist_types_687121c7.Q;
27
+ frame: refr_dist_types_687121c7.a;
28
+ ref?: any;
29
+ init(): void;
30
+ loop(): void;
31
+ mount(): void;
32
+ clean(): void;
33
+ render(): void;
34
+ resize(e?: Event): void;
35
+ mousemove(e: Event): void;
36
+ _uniform?(key: string, value: Uniform, isMatrix?: boolean): GL;
37
+ uniform(key: string, value: Uniform, isMatrix?: boolean): GL;
38
+ uniform(node: NodeProxy): GL;
39
+ uniform(target: {
40
+ [key: string]: Uniform;
41
+ }): GL;
42
+ _texture?(key: string, value: string): GL;
43
+ texture(key: string, value: string): GL;
44
+ texture(target: {
45
+ [key: string]: string;
46
+ }): GL;
47
+ _attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
48
+ attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
49
+ attribute(target: {
50
+ [key: string]: Attribute;
51
+ }): GL;
52
+ }, any[] | unknown[]>;
53
+
54
+ export { Attribute, GL, NodeProxy, Uniform, WebGLState, WebGPUState, useGL };
package/dist/native.js CHANGED
@@ -1,70 +1,36 @@
1
- import{useState as yt}from"react";import{durable as J,event as mt}from"reev";import{createFrame as dt,createQueue as xt}from"refr";import{nested as Z}from"reev";var y={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)},We=(e,t)=>e.forEach(t),vt=(e,...t)=>{We(e,r=>r(...t))},Xt=(e="",t="_",r="/")=>e.split(t).join(r),_t=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Tt=(e=0)=>`${e}`.split(".")[1]?.length??0,ht=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Et=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var Pt=["x","y","z","w","r","g","b","a","s","t","p","q"],R=["bool","uint","int","float","bvec2","ivec2","uvec2","vec2","bvec3","ivec3","uvec3","vec3","bvec4","ivec4","uvec4","vec4","color","mat2","mat3","mat4"],B=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],D={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},te=Object.keys(D),M=["dot","distance","length","lengthSq","determinant","luminance"],z=["all","any"],V=["abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth"],W=["cross"],q=["reflect","refract"],k=["min","max","mix","clamp","step","smoothstep"],Y=["texture","textureLod","textureSize","cubeTexture"],qe=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],re=[...M,...z,...V,...W,...q,...k,...Y,...qe],oe={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",ivec2:"vec2i",ivec3:"vec3i",ivec4:"vec4i",uvec2:"vec2u",uvec3:"vec3u",uvec4:"vec4u",bvec2:"vec2<bool>",bvec3:"vec3<bool>",bvec4:"vec4<bool>"},j={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},ne={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"},se=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],ie=["and","or"],ae={position:"gl_FragCoord",vertex_index:"gl_VertexID",instance_index:"gl_InstanceID",front_facing:"gl_FrontFacing",frag_depth:"gl_FragDepth",sample_index:"gl_SampleID",sample_mask:"gl_SampleMask",point_coord:"gl_PointCoord",uv:"gl_FragCoord.xy"};var H=e=>y.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ue=e=>te.includes(e),ce=e=>re.includes(e),fe=e=>B.includes(e),L=e=>!e||typeof e!="object"?!1:e.isProxy,pe=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,o=(e&255)/255;return[t,r,o]},ke=0,K=()=>`i${ke++}`,F=(e,t)=>e.filter(r=>!y.und(r)&&!y.nul(r)).map(r=>c(r,t)).join(", "),w=(e,t)=>y.str(e)?t?.isWebGL?e:oe[e]:"",le=e=>D[e]||e,me=e=>ae[e],de=e=>{let t=B.indexOf(e);return t!==-1?R[t]:"float"},xe=e=>Array.from(e.headers).map(([,t])=>t).join(`
2
- `),ge=(e,t)=>{let{id:r,children:o=[],layout:n}=e,[s,a,...u]=o,d=n?.type&&n?.type!=="auto"?n?.type:a?T(a,t):"void",l=[],f=[];if(n?.inputs)for(let b of n.inputs)l.push([b.name,b.type]);else for(let b=0;b<u.length;b++)l.push([`p${b}`,T(u[b],t)]);let p="";if(t?.isWebGL){for(let[b,E]of l)f.push(`${E} ${b}`);p+=`${d} ${r}(${f}) {
3
- `}else{for(let[b,E]of l)f.push(`${b}: ${w(E,t)}`);p+=`fn ${r}(${f}) -> ${w(d,t)} {
4
- `}let N=c(s,t);return N&&(p+=N+`
5
- `),a&&(p+=`return ${c(a,t)};`),p+=`
6
- }`,p},Ye=`
7
- #version 300 es
8
- precision mediump float;
9
- out vec4 fragColor;
10
- `.trim(),je=`
11
- @fragment
12
- fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
13
- `.trim(),He=(e,t,r=!0)=>{let o="";return r&&(o+=Ye),t&&(o+=`
14
- `+t+`
15
- `),r?o+=`void main() {
16
- fragColor = ${e};`:(o+=je+`
17
- `,o+=` return ${e};`),o+=`
18
- }`,o},Ke=(e,t,r=!0)=>"",I=(e,t={})=>{let r=c(e,t),o=xe(t),n=He(r,o,t.isWebGL);return console.log(`// \u2193\u2193\u2193 generated \u2193\u2193\u2193
19
-
20
- ${n}
21
-
22
- `),n},U=(e,t)=>{let r=c(e,t),o=xe(t);return Ke(r,o,t.isWebGL)};var Ze=(e,t)=>e.reduce((r,o)=>{let n=T(o,t),s=R.indexOf(r);return R.indexOf(n)>s?n:r},"float"),Qe=e=>ne[e],Je=(e,t,r)=>{let o=t.length>0?T(t[0],r):"float";return q.includes(e)?o:M.includes(e)?"float":z.includes(e)?"bool":V.includes(e)?o:W.includes(e)?"vec3":Y.includes(e)?"vec4":k.includes(e)?Ze(t,r):o},be=(e,t,r)=>{if(se.includes(r)||ie.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 o=R.indexOf(e),n=R.indexOf(t);return o>=n?e:t},et=e=>y.bol(e)?"bool":y.num(e)?"float":y.arr(e)&&j[e.length]||"float",tt=e=>j[e],rt=(e,t)=>{let{type:r,props:o}=e,{id:n,children:s=[],inferFrom:a}=o,[u,d,l]=s;return a?T(a,t):r==="conversion"?u:r==="operator"?be(T(d,t),T(l,t),u):r==="function"?Je(u,s.slice(1),t):r==="swizzle"?tt(u.length):r==="ternary"?be(T(d,t),T(l,t),"add"):r==="builtin"?Qe(n):r==="define"?o.layout?.type&&o.layout?.type!=="auto"?o.layout.type:d?T(d,t):"void":T(u,t)},T=(e,t)=>{if(t||(t={}),!L(e))return et(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=rt(e,t);return t.infers.set(e,r),r};var c=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),y.str(e))return e;if(y.num(e)){let f=`${e}`;return f.includes(".")?f:f+".0"}if(y.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:o}=e,{id:n="",children:s=[]}=o,[a,u,d]=s,l="";if(r==="attribute"){if(t.headers.has(n))return n;l=`${T(e,t)} ${n}`}if(r==="uniform"){if(t.headers.has(n))return n;t.binding||(t.binding=0);let f=T(e,t);l=t.isWebGL?`uniform ${f} ${n};`:`@group(0) @binding(${t.binding++}) var<uniform> ${n}: ${w(f,t)};`}if(r==="constant"){if(t.headers.has(n))return n;let f=T(e,t),p=c(a,t);l=t.isWebGL?`const ${f} ${n} = ${p};`:`const ${n}: ${w(f,t)} = ${p};`}if(r==="varying"){if(t.headers.has(n))return n;l=`${T(e,t)} ${n}`}if(l)return t.headers.set(n,l),t.onMount?.(n),n;if(r==="variable")return n;if(r==="swizzle")return`${c(u,t)}.${c(a,t)}`;if(r==="ternary")return`(${c(a,t)} ? ${c(u,t)} : ${c(d,t)})`;if(r==="builtin")return t?.isWebGL?me(n):n;if(r==="conversion")return`${w(a,t)}(${F(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${c(u,t)}`:`(${c(u,t)} ${le(a)} ${c(d,t)})`;if(r==="function")return a==="negate"?`(-${F(s.slice(1),t)})`:`${a}(${F(s.slice(1),t)})`;if(r==="scope")return s.map(f=>c(f,t)).join(`
23
- `);if(r==="assign")return`${c(a,t)} = ${c(u,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${a}; i += 1) {
24
- ${c(u,t)}
25
- }`:`for (var i: i32 = 0; i < ${a}; i++) {
26
- ${c(u,t)}
27
- }`;if(r==="define"){let f=s.slice(2),p=`${n}(${f.map(N=>c(N,t))})`;return t.headers.has(n)||t.headers.set(n,ge(o,t)),p}if(r==="if"){let f=`if (${c(a,t)}) {
28
- ${c(u,t)}
29
- }`;for(let p=2;p<s.length;p+=2){let N=p>=s.length-1;f+=N?` else {
30
- ${c(s[p],t)}
31
- }`:` else if (${c(s[p],t)}) {
32
- ${c(s[p+1],t)}
33
- }`}return f}if(r==="switch"){let f=`switch (${c(a,t)}) {
34
- `;for(let p=1;p<s.length;p+=2)p>=s.length-1&&s.length%2===0?f+=`default:
35
- ${c(s[p],t)}
1
+ import{useState as Ut}from"react";import{durable as fe,event as wt}from"reev";import{createFrame as St,createQueue as Gt}from"refr";import{nested as pe}from"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)},dt=(e,t)=>e.forEach(t),Ft=(e,...t)=>{dt(e,r=>r(...t))},At=(e="",t="_",r="/")=>e.split(t).join(r),Bt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Dt=(e=0)=>`${e}`.split(".")[1]?.length??0,Mt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),zt=(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"],Y=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],H={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},de=Object.keys(H),j=["dot","distance","length","lengthSq","determinant","luminance"],K=["all","any"],Z=["abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth"],Q=["cross"],J=["reflect","refract"],ee=["min","max","mix","clamp","step","smoothstep"],te=["texture","textureLod","textureSize","cubeTexture"],xt=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],xe=[...j,...K,...Z,...Q,...J,...ee,...te,...xt],ge={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>"},re={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},be={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"},ve=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],he=["and","or"],Xe={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 oe=e=>l.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ye=e=>de.includes(e),Te=e=>xe.includes(e),_e=e=>Y.includes(e),Ee=e=>!e||typeof e!="object"?!1:e.isProxy,Pe=e=>!(!e||e==="auto"),Ce=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++}`,R=(e,t)=>e.filter(r=>!l.und(r)&&!l.nul(r)).map(r=>c(r,t)).join(", "),L=(e,t)=>l.str(e)?t?.isWebGL?e:ge[e]:"",Ne=e=>H[e]||e,Le=e=>Xe[e],we=e=>{let t=Y.indexOf(e);return t!==-1?G[t]:"float"};var bt=(e,t)=>e.reduce((r,n)=>{let o=X(n,t),i=G.indexOf(r);return G.indexOf(o)>i?o:r},"float"),vt=e=>be[e],ht=(e,t,r)=>{let n=t.length>0?X(t[0],r):"float";return J.includes(e)?n:j.includes(e)?"float":K.includes(e)?"bool":Z.includes(e)?n:Q.includes(e)?"vec3":te.includes(e)?"vec4":ee.includes(e)?bt(t,r):n},Se=(e,t,r)=>{if(ve.includes(r)||he.includes(r))return"bool";if(e===t||e.includes("vec")&&!t.includes("vec"))return e;if(t.includes("vec")&&!e.includes("vec"))return t;let n=G.indexOf(e),o=G.indexOf(t);return n>=o?e:t},Xt=e=>l.bol(e)?"bool":l.num(e)?"float":l.arr(e)&&re[e.length]||"float",yt=e=>re[e],Tt=(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},_t=(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"?Se(X(f,t),X(b,t),p):r==="function"?ht(p,i.slice(1),t):r==="swizzle"?yt(p.length):r==="ternary"?Se(X(f,t),X(b,t),"add"):r==="builtin"?vt(o):r==="define"&&Pe(s?.type)?s?.type:a?Tt(a,t):X(p,t)},X=(e,t)=>{if(t||(t={}),!Ee(e))return Xt(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=_t(e,t);return t.infers.set(e,r),r};var Ge=(e,t,r,n)=>{if(e.isWebGL)return`texture(${R(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})`},Re=(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},Oe=(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&&(f+=`case ${c(s[p],t)}:
38
- ${c(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 f+="}",f}if(r==="declare"){let f=T(a,t),p=u?.props?.id;if(t.isWebGL)return`${f} ${p} = ${c(a,t)};`;let N=w(f);return`var ${p}: ${N} = ${c(a,t)};`}return c(a,t)};var C=null,O=(e,t=()=>{})=>{let r=C;C=e,t(),C=r},G=e=>{C&&(C.props.children||(C.props.children=[]),C.props.children.push(e))},ye=(e,t)=>{t||(t=K());let r=m("variable",{id:t,inferFrom:e}),o=m("declare",null,e,r);return G(o),r},ve=(e,t)=>{let r=m("assign",null,e,t);return G(r),e},Wt=(e,t)=>{let r=m("scope");O(r,t);let o=m("if",null,e,r);G(o);let n=()=>({ElseIf:(s,a)=>{let u=m("scope");return O(u,a),o.props.children.push(s,u),n()},Else:s=>{let a=m("scope");O(a,s),o.props.children.push(a)}});return n()},qt=(e,t)=>{let r=m("scope");O(r,()=>t({i:m("variable",{id:"i",inferFrom:Xe(0)})}));let o=m("loop",null,e,r);return G(o),o},kt=e=>{let t=m("switch",null,e);G(t);let r=()=>({Case:(...o)=>n=>{let s=m("scope");O(s,n);for(let a of o)t.props.children.push(a,s);return r()},Default:o=>{let n=m("scope");O(n,o),t.props.children.push(n)}});return r()},Yt=e=>{let t,r=(...o)=>{let n=t?.name||K(),s=m("scope"),a,u=[],d=[];if(t?.inputs)for(let l of t.inputs)d.push({id:l.name,inferFrom:v(l.type)});else for(let l=0;l<o.length;l++)d.push({id:`p${l}`,inferFrom:o[l]});for(let l of d)u.push(m("variable",l));return O(s,()=>a=e(u)),m("define",{id:n,layout:t},s,a,...o)};return r.setLayout=o=>(t=o,r),r};var ot=(e,t)=>{if(t==="string")return c(e)},m=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=(a,u)=>{if(u==="type")return e;if(u==="props")return t;if(u==="toVar")return ye.bind(null,s);if(u==="assign")return ve.bind(null,s);if(u==="isProxy")return!0;if(u==="toString")return c.bind(null,s);if(u===Symbol.toPrimitive)return ot.bind(null,s);if(H(u))return _e(u,s);if(ue(u))return(...d)=>nt(u,s,...d);if(ce(u))return(...d)=>i(u,s,...d);if(fe(u))return()=>v(de(u),s)},n=(a,u,d)=>H(u)?(_e(u,s).assign(d),!0):!1,s=new Proxy({},{get:o,set:n});return s},Qt=(e,t)=>m("varying",{id:t},e),A=(e,t)=>m("uniform",{id:t},e),Jt=(e,t)=>m("varying",{id:t},e),er=(e,t)=>m("constant",{id:t},e),tr=e=>m("variable",{id:e}),h=e=>m("builtin",{id:e}),_e=(e,t)=>m("swizzle",null,e,t),nt=(e,...t)=>m("operator",null,e,...t),i=(e,...t)=>m("function",null,e,...t),v=(e,...t)=>m("conversion",null,e,...t),rr=(e,t,r)=>m("ternary",null,e,t,r);var ar=h("position"),ur=h("vertex_index"),cr=h("instance_index"),fr=h("front_facing"),pr=h("frag_depth"),lr=h("sample_index"),mr=h("sample_mask"),dr=h("point_coord"),xr=h("normalLocal"),gr=h("normalWorld"),br=h("normalView"),yr=h("position"),vr=h("positionWorld"),Xr=h("positionView"),_r=h("screenCoordinate"),Tr=h("screenUV"),st=e=>v("float",e),Xe=e=>v("int",e),hr=e=>v("uint",e),Er=e=>v("bool",e),he=(e,t)=>v("vec2",e,t),Te=(e,t,r)=>v("vec3",e,t,r),Nr=(e,t,r,o)=>v("vec4",e,t,r,o),Pr=(...e)=>v("mat2",...e),Sr=(...e)=>v("mat3",...e),Lr=(...e)=>v("mat4",...e),Rr=(e,t)=>v("ivec2",e,t),wr=(e,t,r)=>v("ivec3",e,t,r),Cr=(e,t,r,o)=>v("ivec4",e,t,r,o),Or=(e,t)=>v("uvec2",e,t),Gr=(e,t,r)=>v("uvec3",e,t,r),Fr=(e,t,r,o)=>v("uvec4",e,t,r,o),Ir=(e,t)=>v("bvec2",e,t),Ur=(e,t,r)=>v("bvec3",e,t,r),Ar=(e,t,r,o)=>v("bvec4",e,t,r,o),$r=(e,t,r)=>y.num(e)&&y.und(t)&&y.und(r)?Te(...pe(e)):Te(e,t,r),Br=A(he(1280,800),"iResolution"),Dr=A(he(0,0),"iMouse"),Mr=A(st(0),"iTime"),zr=(e,t,r)=>i("texture",e,t,r),Vr=(e,t,r)=>i("cubeTexture",e,t,r),Wr=(e,t)=>i("textureSize",e,t),qr=e=>i("abs",e),kr=e=>i("acos",e),Yr=e=>i("all",e),jr=e=>i("any",e),Hr=e=>i("asin",e),Kr=(e,t)=>t!==void 0?i("atan",e,t):i("atan",e),Zr=(e,t)=>i("atan",e,t),Qr=(e,t)=>i("bitcast",e,t),Jr=e=>i("cbrt",e),eo=e=>i("ceil",e),to=(e,t,r)=>i("clamp",e,t,r),ro=e=>i("cos",e),oo=(e,t)=>i("cross",e,t),no=e=>i("dFdx",e),so=e=>i("dFdy",e),io=e=>i("degrees",e),ao=(e,t)=>i("difference",e,t),uo=(e,t)=>i("distance",e,t),co=(e,t)=>i("dot",e,t),fo=(e,t)=>i("equals",e,t),po=e=>i("exp",e),lo=e=>i("exp2",e),mo=(e,t,r)=>i("faceforward",e,t,r),xo=e=>i("floor",e),go=e=>i("fract",e),bo=e=>i("fwidth",e),yo=e=>i("inverseSqrt",e),vo=e=>i("length",e),Xo=e=>i("lengthSq",e),_o=e=>i("log",e),To=e=>i("log2",e),ho=(e,t)=>i("max",e,t),Eo=(e,t)=>i("min",e,t),No=(e,t,r)=>i("mix",e,t,r),Po=e=>i("negate",e),So=e=>i("normalize",e),Lo=e=>i("oneMinus",e),Ro=(e,t)=>i("pow",e,t),wo=e=>i("pow2",e),Co=e=>i("pow3",e),Oo=e=>i("pow4",e),Go=e=>i("radians",e),Fo=e=>i("reciprocal",e),Io=(e,t)=>i("reflect",e,t),Uo=(e,t,r)=>i("refract",e,t,r),Ao=e=>i("round",e),$o=e=>i("saturate",e),Bo=e=>i("sign",e),Do=e=>i("sin",e),Mo=(e,t,r)=>i("smoothstep",e,t,r),zo=e=>i("sqrt",e),Vo=(e,t)=>i("step",e,t),Wo=e=>i("tan",e),qo=(e,t)=>i("transformDirection",e,t),ko=e=>i("trunc",e);var it=`
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
- `,at=`
14
+ `);return n+="}",n},$e=(e,t,r)=>{let n=X(t,e),o=r?.props?.id;if(e.isWebGL)return`${n} ${o} = ${c(t,e)};`;let i=L(n);return`var ${o}: ${i} = ${c(t,e)};`},Ie=(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}: ${L(_,e)}`);b.push(`fn ${n}(${f}) -> ${L(r,e)} {`)}let d=c(s,e);return d&&b.push(d),b.push("}"),b.join(`
15
+ `)},Ue=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.vertVaryings.size}) ${t}: ${L(r,e)}`,Fe=(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=L(r,e);return`@group(${o}) @binding(${i}) var<uniform> ${t}: ${s};`},Ae=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:n=0}=e.webgpu?.attribs.map.get(t)||{},o=L(r,e);return`@location(${n}) ${t}: ${o}`},Be=(e,t,r,n)=>e.isWebGL?`const ${r} ${t} = ${n};`:`const ${t}: ${L(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`${L(s,t)}(${R(i.slice(1),t)})`;if(r==="operator")return s==="not"||s==="bitNot"?`!${c(a,t)}`:`(${c(a,t)} ${Ne(s)} ${c(p,t)})`;if(r==="function")return s==="negate"?`(-${R(i.slice(1),t)})`:s==="texture"?Ge(t,a,p,f):`${s}(${R(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 Re(t,s,a,i);if(r==="switch")return Oe(t,s,i);if(r==="declare")return $e(t,s,a);if(r==="define"){let d=`${o}(${R(i.slice(1),t)})`;return t.headers.has(o)||t.headers.set(o,Ie(t,n,X(e,t))),d}if(r==="varying"){if(t.vertOutputs.has(o))return t.isWebGL?`${o}`:`out.${o}`;let d=Ue(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 Le(o);if(o==="position")return"out.position";let d=`@builtin(${o}) ${o}: ${L(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,Ae(t,o,X(e,t))),t.isWebGL?`${o}`:`in.${o}`;if(t.headers.has(o))return o;let b="";return r==="uniform"&&(b=Fe(t,o,X(e,t))),r==="constant"&&(b=Be(t,o,X(e,t),c(s,t))),b?(t.headers.set(o,b),o):c(s,t)};var O=null,U=null,F=e=>{if(!O||(O.props.children||(O.props.children=[]),O.props.children.push(e),e.type!=="return"||!U))return;let{props:t}=U;t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e)},De=(e,t)=>{t||(t=w());let r=m("variable",{id:t,inferFrom:[e]}),n=m("declare",null,e,r);return F(n),r},Me=(e,t)=>{let r=m("assign",null,e,t);return F(r),e},Et=e=>{let t=m("return",{inferFrom:[e]},e);return F(t),t},$=(e,t,r=U)=>{let n=O,o=U;O=e,U=r,n&&(e.props.parent=n);let i=t();i&&Et(i),O=n,U=o},fr=(e,t)=>{let r=m("scope");$(r,t);let n=m("if",null,e,r);F(n);let o=()=>({ElseIf:(i,s)=>{let a=m("scope");return $(a,s),n.props.children.push(i,a),o()},Else:i=>{let s=m("scope");$(s,i),n.props.children.push(s)}});return o()},lr=(e,t)=>{let r=m("scope");$(r,()=>t({i:m("variable",{id:"i",inferFrom:[I(0)]})}));let n=m("loop",null,e,r);return F(n),n},mr=e=>{let t=m("switch",null,e);F(t);let r=()=>({Case:(...n)=>o=>{let i=m("scope");$(i,o);for(let s of n)t.props.children.push(s,i);return r()},Default:n=>{let o=m("scope");$(o,n),t.props.children.push(o)}});return r()},dr=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,()=>e(s),p),p};return r.setLayout=n=>(t=n,r),r};var Pt=(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 De.bind(null,i);if(a==="assign")return Me.bind(null,i);if(a==="isProxy")return!0;if(a==="toString")return c.bind(null,i);if(a===Symbol.toPrimitive)return Pt.bind(null,i);if(oe(a))return ze(a,i);if(ye(a))return(...p)=>Ct(a,i,...p);if(Te(a))return(...p)=>u(a,i,...p);if(_e(a))return()=>x(we(a),i)},o=(s,a,p)=>oe(a)?(ze(a,i).assign(p),!0):!1,i=new Proxy({},{get:n,set:o});return i},Xr=(e,t=w())=>m("attribute",{id:t},e),yr=(e,t=w())=>m("constant",{id:t},e),D=(e,t=w())=>m("uniform",{id:t},e),Tr=(e=w())=>m("variable",{id:e}),T=(e=w())=>m("builtin",{id:e}),_r=(e,t=w())=>m("varying",{id:t,inferFrom:[e]},e),ze=(e,t)=>m("swizzle",null,e,t),Ct=(e,...t)=>m("operator",null,e,...t),u=(e,...t)=>m("function",null,e,...t),x=(e,...t)=>m("conversion",null,e,...t),Er=(e,t,r)=>m("ternary",null,e,t,r);var Nt=`
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
- `,Ee=(e,t,r)=>{let o=e.createShader(r);if(!o)throw new Error("Failed to create shader");if(e.shaderSource(o,t.trim()),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS))return o;let n=e.getShaderInfoLog(o);e.deleteShader(o),console.warn(`Could not compile shader: ${n}`)},Ne=(e,t=it,r=at,o=()=>{})=>{L(r)&&(r=I(r,{isWebGL:!0})),L(t)&&(t=U(r,{isWebGL:!0}));let n=e.createProgram(),s=Ee(e,t,e.VERTEX_SHADER),a=Ee(e,r,e.FRAGMENT_SHADER);if(!s||!a)return o();if(e.attachShader(n,s),e.attachShader(n,a),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let u=e.getProgramInfoLog(n);e.deleteProgram(n),o(),console.warn(`Could not link pg: ${u}`)},Pe=(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},Se=(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},Le=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},Re=(e,t,r,o,n)=>{e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,t,e.FLOAT,!1,0,0),n&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n)},we=(e,t,r,o)=>{let n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),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,o),e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,n)};var Ce=async e=>{let t=e.el.getContext("webgl2"),r=Ne(t,e.vs,e.fs,()=>void(e.isLoop=!1));t.useProgram(r);let o=0,n=Z(b=>t.getUniformLocation(r,b)),s=Z(b=>t.getAttribLocation(r,b)),a=Z(()=>o++);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:(b="",E,P)=>{let S=s(b,!0),_=Pe(t,E),x=Se(t,P),g=Le(e.count,E,P);Re(t,g,S,_,x)},_uniform:(b,E)=>{let P=n(b);if(y.num(E))return t.uniform1f(P,E);let S=E.length;if(S<=4)return t[`uniform${S}fv`](P,E);S=Math.sqrt(S)<<0,t[`uniformMatrix${S}fv`](P,!1,E)},_texture:(b,E)=>{let P=new Image;Object.assign(P,{src:E,crossOrigin:"anonymous"}),P.decode().then(()=>{let S=n(b),_=a(b);we(t,P,S,_)})}}};import{nested as Q}from"reev";var ut=`
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
- `,ct=`
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
- `,Oe=async e=>{let t=navigator.gpu,r=t.getPreferredCanvasFormat(),n=await(await t.requestAdapter()).requestDevice();return e.configure({device:n,format:r,alphaMode:"opaque"}),{device:n,format:r}},Ge=(e,t,r,o,n=ut,s=ct)=>{L(n)&&(n=U(n,{isWebGL:!1})),L(s)&&(s=I(s,{isWebGL:!1}));let a=e.createPipelineLayout({bindGroupLayouts:o});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:n.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:a,primitive:{topology:"triangle-list"}})},Fe=(e,t)=>{let r=[],o=[];t.forEach((a,u)=>{if(!a)return;let d="buffer"in a,l=a instanceof GPUTextureView,f=a instanceof GPUSampler;if(d)r.push({binding:u,visibility:3,buffer:{type:"uniform"}});else if(l)r.push({binding:u,visibility:2,texture:{}});else if(f)r.push({binding:u,visibility:2,sampler:{}});else return;o.push({binding:u,resource:a})});let n=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:n,entries:o});return{layout:n,bindGroup:s}},Ie=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),ft=e=>Math.ceil(e/256)*256,Ue=(e,t)=>{let r=new Float32Array(t),o=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:o}},Ae=(e,t)=>{let r=new Float32Array(t),o=ft(r.byteLength),n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},$e=(e,t=1280,r=800)=>{let o=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),n=e.createSampler({magFilter:"linear",minFilter:"linear"});return{texture:o,sampler:n}},pt=(e,t)=>e/t,lt=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Be=(e,t,r=6)=>{let o=pt(t,r);return{arrayStride:o*4,attributes:[{shaderLocation:e,offset:0,format:lt(o)}]}};var De=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await Oe(t),n={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],a=[],u=[],d=Q((_,x)=>{let{array:g,buffer:X}=Ue(r,x);return a.push(X),u.push(Be(u.length,g.length,e.count)),n.needsUpdate=!0,{array:g,buffer:X}}),l=Q((_,x)=>{let{array:g,buffer:X}=Ae(r,x);return n.resources[0].push({buffer:X}),n.needsUpdate=!0,{array:g,buffer:X}}),f=Q((_,{width:x,height:g})=>{let{texture:X,sampler:$}=$e(r,x,g);return n.resources[1].push($,X.createView()),n.needsUpdate=!0,{texture:X,width:x,height:g}}),p=()=>{let _=[];s.length=0,n.resources.forEach(x=>{if(!x.length)return;let{layout:g,bindGroup:X}=Fe(r,x);_.push(g),s.push(X)}),n.pipeline=Ge(r,o,u,_,e.vs,e.fs)};return{webgpu:n,render:()=>{if(n.loadingImg)return;n.needsUpdate&&p(),n.needsUpdate=!1;let _=r.createCommandEncoder(),x=_.beginRenderPass(Ie(t));x.setPipeline(n.pipeline),s.forEach((g,X)=>x.setBindGroup(X,g)),a.forEach((g,X)=>x.setVertexBuffer(X,g)),x.draw(e.count,1,0,0),x.end(),r.queue.submit([_.finish()])},clean:()=>{},_attribute:(_="",x)=>{let{array:g,buffer:X}=d(_,x);r.queue.writeBuffer(X,0,g)},_uniform:(_,x)=>{y.num(x)&&(x=[x]);let{array:g,buffer:X}=l(_,x);g.set(x),r.queue.writeBuffer(X,0,g)},_texture:(_,x)=>{n.loadingImg++;let g=Object.assign(new Image,{src:x,crossOrigin:"anonymous"});g.decode().then(()=>{let{texture:X,width:$,height:Ve}=f(_,g);r.queue.copyExternalImageToTexture({source:g},{texture:X},{width:$,height:Ve}),n.loadingImg--})}}};var Me=e=>y.obj(e)?"isGL"in e:!1,gt=()=>typeof window>"u",bt=()=>gt()?!1:"gpu"in navigator,ee=performance.now(),ze=e=>{let t=mt({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=xt(),t.frame=dt(),t.attribute=J((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n))),t.texture=J((r,o)=>t.queue(()=>t._texture?.(r,o))),t.uniform=J((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:ee}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,bt()||(t.isWebGL=!0),t.isWebGL?t(await Ce(t)):t(await De(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,o=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=o,t.uniform("iResolution",t.size)}),t("mousemove",(r,o=r.clientX,n=r.clientY)=>{let[s,a]=t.size,{top:u,left:d}=t.el.getBoundingClientRect();t.mouse[0]=(o-u-s/2)/(s/2),t.mouse[1]=-(n-d-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{ee=performance.now()/1e3,t.uniform("iTime",ee)}),t(e)};var Rn=(e={})=>yt(()=>{let t=Me(e)?e:ze(e);return t.ref=r=>{t.el={},t({render(){r.flush(),r.endFrameEXP()}}),t.mount(),(()=>{t.width=r.drawingBufferWidth,t.height=r.drawingBufferHeight,t.resize()})()},t({isNative:!0})})[0];export{qe as ADDITIONAL_FUNCTIONS,z as BOOL_RETURN_FUNCTIONS,ne as BUILTIN_TYPES,se as COMPARISON_OPERATORS,j as COMPONENT_COUNT_TO_TYPE,R as CONSTANTS,B as CONVERSIONS,q as FIRST_ARG_TYPE_FUNCTIONS,re as FUNCTIONS,Yt as Fn,k as HIGHEST_TYPE_FUNCTIONS,Wt as If,ie as LOGICAL_OPERATORS,qt as Loop,D as OPERATORS,te as OPERATOR_KEYS,V as PRESERVE_TYPE_FUNCTIONS,M as SCALAR_RETURN_FUNCTIONS,Pt as SWIZZLES,kt as Switch,oe as TYPE_MAPPING,W as VEC3_RETURN_FUNCTIONS,Y as VEC4_RETURN_FUNCTIONS,ae as WGSL_TO_GLSL_BUILTIN,qr as abs,kr as acos,ft as alignTo256,Yr as all,jr as any,Hr as asin,ve as assign,Kr as atan,Zr as atan2,Qt as attribute,Qr as bitcast,Er as bool,h as builtin,Ir as bvec2,Ur as bvec3,Ar as bvec4,Jr as cbrt,eo as ceil,to as clamp,c as code,$r as color,er as constant,v as conversion,de as conversionToConstant,ro as cos,Re as createAttrib,Fe as createBindGroup,Be as createBufferLayout,Ie as createDescriptor,Oe as createDevice,ze as createGL,Se as createIbo,Ge as createPipeline,Ne as createProgram,we as createTexture,$e as createTextureSampler,Ae as createUniformBuffer,Pe as createVbo,Ue as createVertexBuffer,oo as cross,Vr as cubeTexture,no as dFdx,so as dFdy,at as defaultFragmentGLSL,it as defaultVertexGLSL,io as degrees,ao as difference,ht as dig,uo as distance,co as dot,We as each,fo as equals,po as exp,lo as exp2,_t as ext,mo as faceforward,Tt as fig,st as float,xo as floor,vt as flush,w as formatConversions,go as fract,pr as fragDepth,I as fragment,fr as frontFacing,i as function_,bo as fwidth,ge as generateDefine,me as getBluiltin,K as getId,le as getOperator,Le as getStride,pe as hex2rgb,Dr as iMouse,Br as iResolution,Mr as iTime,T as infer,rt as inferImpl,cr as instanceIndex,Xe as int,yo as inverseSqrt,y as is,fe as isConversion,ce as isFunction,Me as isGL,L as isNodeProxy,ue as isOperator,gt as isServer,H as isSwizzle,bt as isWebGPUSupported,Rr as ivec2,wr as ivec3,Cr as ivec4,F as joins,vo as length,Xo as lengthSq,_o as log,To as log2,Pr as mat2,Sr as mat3,Lr as mat4,ho as max,Eo as min,No as mix,Po as negate,m as node,xr as normalLocal,br as normalView,gr as normalWorld,So as normalize,Lo as oneMinus,nt as operator,dr as pointCoord,ar as position,yr as positionLocal,Xr as positionView,vr as positionWorld,Ro as pow,wo as pow2,Co as pow3,Oo as pow4,Go as radians,Fo as reciprocal,Io as reflect,Uo as refract,Xt as replace,Ao as round,lr as sampleIndex,mr as sampleMask,$o as saturate,_r as screenCoordinate,Tr as screenUV,rr as select,Et as sig,Bo as sign,Do as sin,Mo as smoothstep,zo as sqrt,Vo as step,_e as swizzle,Wo as tan,zr as texture,Wr as textureSize,ye as toVar,qo as transformDirection,ko as trunc,hr as uint,A as uniform,Rn as useGL,Or as uvec2,Gr as uvec3,Fr as uvec4,tr as variable,Jt as varying,he as vec2,Te as vec3,Nr as vec4,U as vertex,ur as vertexIndex,Ce as webgl,De as webgpu};
25
+ `.trim(),We=(e,t)=>{let r=c(e,t);return[Array.from(t.headers.values()).join(`
26
+ `),r]},ne=(e,t)=>`struct ${e} {
27
+ ${Array.from(t.values()).join(`,
28
+ `)}
29
+ }`,M=(e,t)=>{t.headers?.clear(),t.isFrag=!1;let[r,n]=We(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(ne("In",t.vertInputs)),t.vertOutputs?.size&&o.push(ne("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]=We(e,t),o=[];if(t.isWebGL){o.push(Nt);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(ne("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},se=T("position"),ie=T("vertex_index"),Sr=T("instance_index"),Gr=T("front_facing"),Rr=T("frag_depth"),Or=T("sample_index"),$r=T("sample_mask"),Ir=T("point_coord"),Ur=T("normalLocal"),Fr=T("normalWorld"),Ar=T("normalView"),Br=T("position"),Dr=T("positionWorld"),Mr=T("positionView"),zr=T("screenCoordinate"),Vr=T("screenUV"),V=e=>x("float",e),I=e=>x("int",e),Wr=e=>x("uint",e),qr=e=>x("bool",e),qe=(e,t)=>x("vec2",e,t),Ve=(e,t,r)=>x("vec3",e,t,r),ae=(e,t,r,n)=>x("vec4",e,t,r,n),kr=(...e)=>x("mat2",...e),Yr=(...e)=>x("mat3",...e),Hr=(...e)=>x("mat4",...e),jr=(e,t)=>x("ivec2",e,t),Kr=(e,t,r)=>x("ivec3",e,t,r),Zr=(e,t,r,n)=>x("ivec4",e,t,r,n),Qr=(e,t)=>x("uvec2",e,t),Jr=(e,t,r)=>x("uvec3",e,t,r),eo=(e,t,r,n)=>x("uvec4",e,t,r,n),to=(e,t)=>x("bvec2",e,t),ro=(e,t,r)=>x("bvec3",e,t,r),oo=(e,t,r,n)=>x("bvec4",e,t,r,n),no=()=>x("texture"),so=()=>x("sampler2D"),io=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Ve(...Ce(e)):Ve(e,t,r),ue=D(qe(1280,800),"iResolution"),ao=D(qe(0,0),"iMouse"),uo=D(V(0),"iTime"),po=()=>se.xy.div(ue),co=(e,t,r)=>u("texture",e,t,r),fo=(e,t,r)=>u("cubeTexture",e,t,r),lo=(e,t)=>u("textureSize",e,t),mo=e=>u("abs",e),xo=e=>u("acos",e),go=e=>u("all",e),bo=e=>u("any",e),vo=e=>u("asin",e),ho=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),Xo=(e,t)=>u("atan",e,t),yo=(e,t)=>u("bitcast",e,t),To=e=>u("cbrt",e),_o=e=>u("ceil",e),Eo=(e,t,r)=>u("clamp",e,t,r),Po=e=>u("cos",e),Co=(e,t)=>u("cross",e,t),No=e=>u("dFdx",e),Lo=e=>u("dFdy",e),wo=e=>u("degrees",e),So=(e,t)=>u("difference",e,t),Go=(e,t)=>u("distance",e,t),Ro=(e,t)=>u("dot",e,t),Oo=(e,t)=>u("equals",e,t),$o=e=>u("exp",e),Io=e=>u("exp2",e),Uo=(e,t,r)=>u("faceforward",e,t,r),Fo=e=>u("floor",e),ke=e=>u("fract",e),Ao=e=>u("fwidth",e),Bo=e=>u("inverseSqrt",e),Do=e=>u("length",e),Mo=e=>u("lengthSq",e),zo=e=>u("log",e),Vo=e=>u("log2",e),Wo=(e,t)=>u("max",e,t),qo=(e,t)=>u("min",e,t),ko=(e,t,r)=>u("mix",e,t,r),Yo=e=>u("negate",e),Ho=e=>u("normalize",e),jo=e=>u("oneMinus",e),Ko=(e,t)=>u("pow",e,t),Zo=e=>u("pow2",e),Qo=e=>u("pow3",e),Jo=e=>u("pow4",e),en=e=>u("radians",e),tn=e=>u("reciprocal",e),rn=(e,t)=>u("reflect",e,t),on=(e,t,r)=>u("refract",e,t,r),nn=e=>u("round",e),sn=e=>u("saturate",e),an=e=>u("sign",e),un=e=>u("sin",e),pn=(e,t,r)=>u("smoothstep",e,t,r),cn=e=>u("sqrt",e),fn=(e,t)=>u("step",e,t),ln=e=>u("tan",e),mn=(e,t)=>u("transformDirection",e,t),dn=e=>u("trunc",e);var Ye=(e,t,r)=>{let n=e.createShader(r);if(!n)throw new Error("Failed to create shader");if(e.shaderSource(n,t.trim()),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;let o=e.getShaderInfoLog(n);e.deleteShader(n),console.warn(`Could not compile shader: ${o}`)},He=(e,t,r,n=()=>{},o)=>{let i={isWebGL:!0,gl:o};l.str(r)||(r=z(r,i)),l.str(t)||(t=M(t,i));let s=e.createProgram(),a=Ye(e,t,e.VERTEX_SHADER),p=Ye(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}`)},je=(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},Ke=(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},Ze=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Qe=(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)},Je=(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 et=async e=>{let t=e.el.getContext("webgl2"),r=He(t,e.vs,e.fs,()=>void(e.isLoop=!1),e);t.useProgram(r);let n=0,o=pe(g=>t.getUniformLocation(r,g)),i=pe(g=>t.getAttribLocation(r,g)),s=pe(()=>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 C=i(g,!0),A=je(t,_),W=Ke(t,E),q=Ze(e.count,_,E);Qe(t,q,C,A,W)},_uniform:(g,_)=>{let E=o(g);if(l.num(_))return t.uniform1f(E,_);let C=_.length;if(C<=4)return t[`uniform${C}fv`](E,_);C=Math.sqrt(C)<<0,t[`uniformMatrix${C}fv`](E,!1,_)},_texture:(g,_)=>{let E=new Image;Object.assign(E,{src:_,crossOrigin:"anonymous"}),E.decode().then(()=>{let C=o(g),A=s(g);Je(t,E,C,A)})},webgl:{context:t,program:r}}};import{nested as ce}from"reev";var tt=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}},rt=()=>{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}}}},ot=(e,t,r,n,o,i,s)=>{let a={isWebGL:!1,webgpu:o};l.str(s)||(s=z(s,a)),l.str(i)||(i=M(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"}})},nt=(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}},st=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},it=(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},at=(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"}}),ut=(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}},pt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT}),Lt=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",ct=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:Lt(i)}]};return{vertexBuffers:t,bufferLayouts:r}};var ft=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await tt(t),o=rt(),i=0,s=!0,a,p=y=>{},f=ce((y,v)=>{s=!0;let{group:h,binding:P}=o.uniform(),{array:S,buffer:N}=nt(r,v);return{array:S,buffer:N,binding:P,group:h}}),b=ce((y,{width:v,height:h})=>{s=!0;let{group:P,binding:S}=o.texture(),{texture:N,sampler:B}=ut(r,v,h);return{texture:N,sampler:B,binding:S,group:P}}),d=ce((y,v)=>{s=!0;let h=v.length/e.count,{location:P}=o.attrib(),{array:S,buffer:N}=st(r,v);return{array:S,buffer:N,location:P,stride:h}}),g=()=>{let{vertexBuffers:y,bufferLayouts:v}=ct(d.map),{bindGroups:h,bindGroupLayouts:P}=it(r,f.map,b.map),S=ot(r,n,v,P,me,e.vs,e.fs);p=N=>{N.setPipeline(S),h.forEach((B,k)=>N.setBindGroup(k,B)),y.forEach((B,k)=>N.setVertexBuffer(k,B)),N.draw(e.count,1,0,0),N.end()}},_=()=>{if(i)return;s&&g(),s=!1;let y=r.createCommandEncoder();p(y.beginRenderPass(at(t,a))),r.queue.submit([y.finish()])},E=()=>{let y=e.el;a?.destroy(),a=pt(r,y.width,y.height)},C=()=>{a?.destroy()},A=(y="",v)=>{let{array:h,buffer:P}=d(y,v);h.set(v),r.queue.writeBuffer(P,0,h)},W=(y,v)=>{l.num(v)&&(v=[v]);let{array:h,buffer:P}=f(y,v);h.set(v),r.queue.writeBuffer(P,0,h)},q=(y,v)=>{i++;let h=Object.assign(new Image,{src:v,crossOrigin:"anonymous"});h.decode().then(()=>{let P=b(y,h);r.queue.copyExternalImageToTexture({source:h},{texture:P.texture},{width:h.width,height:h.height}),i--})};E();let me={device:r,uniforms:f,textures:b,attribs:d};return{webgpu:me,render:_,resize:E,clean:C,_attribute:A,_uniform:W,_texture:q}};var lt=e=>l.obj(e)?"isGL"in e:!1,Rt=()=>typeof window>"u",Ot=()=>Rt()?!1:"gpu"in navigator,le=performance.now(),$t=()=>ae(ke(se.xy.div(ue)),0,1),It=()=>ae(V(I(ie).mod(I(2))).mul(4).sub(1),V(I(ie).div(I(2))).mul(4).sub(1),0,1),mt=e=>{let t=wt({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Gt(),t.frame=St(),t.attribute=fe((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o)),t),t.uniform=fe((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o)),t),t.texture=fe((r,n)=>t.queue(()=>t._texture?.(r,n)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:le}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||It(),t.fs=t.fs||t.frag||t.fragment||$t(),Ot()||(t.isWebGL=!0),t.isWebGL?t(await et(t)):t(await ft(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",()=>{le=performance.now()/1e3,t.uniform("iTime",le)}),t(e)};var Qn=(e={})=>Ut(()=>{let t=lt(e)?e:mt(e);return t.ref=r=>{t.el={},t({render(){r.flush(),r.endFrameEXP()}}),t.mount(),(()=>{t.width=r.drawingBufferWidth,t.height=r.drawingBufferHeight,t.resize()})()},t({isNative:!0})})[0];export{dr as Fn,fr as If,lr as Loop,Et as Return,mr as Switch,mo as abs,xo as acos,go as all,bo as any,vo as asin,Me as assign,ho as atan,Xo as atan2,Xr as attribute,yo as bitcast,qr as bool,T as builtin,to as bvec2,ro as bvec3,oo as bvec4,To as cbrt,_o as ceil,Eo as clamp,c as code,io as color,yr as constant,x as conversion,we as conversionToConstant,Po as cos,Qe as createAttrib,st as createAttribBuffer,it as createBindGroup,rt as createBindings,pt as createDepthTexture,at as createDescriptor,tt as createDevice,mt as createGL,Ke as createIbo,ot as createPipeline,He as createProgram,Je as createTexture,ut as createTextureSampler,nt as createUniformBuffer,je as createVbo,ct as createVertexBuffers,Co as cross,fo as cubeTexture,No as dFdx,Lo as dFdy,wo as degrees,So as difference,Mt as dig,Go as distance,Ro as dot,dt as each,Oo as equals,$o as exp,Io as exp2,Bt as ext,Uo as faceforward,Dt as fig,V as float,Fo as floor,Ft as flush,L as formatConversions,ke as fract,Rr as fragDepth,z as fragment,Gr as frontFacing,u as function_,Ao as fwidth,Le as getBluiltin,w as getId,Ne as getOperator,Ze as getStride,Ce as hex2rgb,ao as iMouse,ue as iResolution,uo as iTime,Sr as instanceIndex,I as int,Bo as inverseSqrt,l as is,Pe as isConstantsType,_e as isConversion,Te as isFunction,lt as isGL,Ee as isNodeProxy,ye as isOperator,Rt as isServer,oe as isSwizzle,Ot as isWebGPUSupported,jr as ivec2,Kr as ivec3,Zr as ivec4,R as joins,Do as length,Mo as lengthSq,zo as log,Vo as log2,kr as mat2,Yr as mat3,Hr as mat4,Wo as max,qo as min,ko as mix,Yo as negate,m as node,Ur as normalLocal,Ar as normalView,Fr as normalWorld,Ho as normalize,jo as oneMinus,Ct as operator,Ir as pointCoord,se as position,Br as positionLocal,Mr as positionView,Dr as positionWorld,Ko as pow,Zo as pow2,Qo as pow3,Jo as pow4,en as radians,tn as reciprocal,rn as reflect,on as refract,At as replace,nn as round,Or as sampleIndex,$r as sampleMask,so as sampler2D,sn as saturate,zr as screenCoordinate,Vr as screenUV,Er as select,zt as sig,an as sign,un as sin,pn as smoothstep,cn as sqrt,fn as step,ze as swizzle,ln as tan,co as texture,no as texture2D,lo as textureSize,De as toVar,mn as transformDirection,dn as trunc,Wr as uint,D as uniform,Qn as useGL,po as uv,Qr as uvec2,Jr as uvec3,eo as uvec4,Tr as variable,qe as vec2,Ve as vec3,ae as vec4,M as vertex,ie as vertexIndex,_r as vertexStage,et as webgl,ft as webgpu};
70
36
  //# sourceMappingURL=native.js.map