glre 0.27.0 → 0.28.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.
@@ -4,7 +4,8 @@ export { Frame, Fun, Queue } from 'refr';
4
4
  import { EventState } from 'reev';
5
5
 
6
6
  declare const SWIZZLES: readonly ["x", "y", "z", "w", "r", "g", "b", "a", "s", "t", "p", "q"];
7
- declare const NODE_TYPES: readonly ["float", "int", "uint", "bool", "color", "vec2", "vec3", "vec4", "mat2", "mat3", "mat4", "ivec2", "ivec3", "ivec4", "uvec2", "uvec3", "uvec4", "bvec2", "bvec3", "bvec4"];
7
+ declare const CONSTANTS: readonly ["bool", "uint", "int", "float", "bvec2", "bvec3", "bvec4", "ivec2", "ivec3", "ivec4", "uvec2", "uvec3", "uvec4", "vec2", "vec3", "vec4", "color", "mat2", "mat3", "mat4"];
8
+ declare const CONVERSIONS: readonly ["toFloat", "toInt", "toUint", "toBool", "toVec2", "toVec3", "toVec4", "toIvec2", "toIvec3", "toIvec4", "toUvec2", "toUvec3", "toUvec4", "toBvec2", "toBvec3", "toBvec4", "toMat2", "toMat3", "toMat4", "toColor"];
8
9
  declare const OPERATORS: {
9
10
  readonly add: "+";
10
11
  readonly sub: "-";
@@ -26,7 +27,15 @@ declare const OPERATORS: {
26
27
  readonly shiftRight: ">>";
27
28
  };
28
29
  declare const OPERATOR_KEYS: (keyof typeof OPERATORS)[];
29
- declare const FUNCTIONS: readonly ["abs", "acos", "asin", "atan", "atan2", "ceil", "clamp", "cos", "cross", "degrees", "distance", "dot", "exp", "exp2", "faceforward", "floor", "fract", "length", "all", "any", "bitcast", "cbrt", "dFdx", "dFdy", "difference", "equals", "fwidth", "inverseSqrt", "lengthSq", "log", "log2", "max", "min", "mix", "negate", "normalize", "oneMinus", "pow", "pow2", "pow3", "pow4", "radians", "reciprocal", "reflect", "refract", "round", "saturate", "sign", "sin", "smoothstep", "sqrt", "step", "tan", "transformDirection", "trunc"];
30
+ declare const SCALAR_RETURN_FUNCTIONS: readonly ["dot", "distance", "length", "lengthSq", "determinant", "luminance"];
31
+ declare const BOOL_RETURN_FUNCTIONS: readonly ["all", "any"];
32
+ declare const PRESERVE_TYPE_FUNCTIONS: readonly ["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"];
33
+ declare const VEC3_RETURN_FUNCTIONS: readonly ["cross"];
34
+ declare const FIRST_ARG_TYPE_FUNCTIONS: readonly ["reflect", "refract"];
35
+ declare const HIGHEST_TYPE_FUNCTIONS: readonly ["min", "max", "mix", "clamp", "step", "smoothstep"];
36
+ declare const VEC4_RETURN_FUNCTIONS: readonly ["texture", "textureLod", "textureSize", "cubeTexture"];
37
+ declare const ADDITIONAL_FUNCTIONS: readonly ["atan2", "degrees", "faceforward", "bitcast", "cbrt", "difference", "equals", "pow", "pow2", "pow3", "pow4", "radians", "transformDirection"];
38
+ declare const FUNCTIONS: readonly ["dot", "distance", "length", "lengthSq", "determinant", "luminance", "all", "any", "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", "cross", "reflect", "refract", "min", "max", "mix", "clamp", "step", "smoothstep", "texture", "textureLod", "textureSize", "cubeTexture", "atan2", "degrees", "faceforward", "bitcast", "cbrt", "difference", "equals", "pow", "pow2", "pow3", "pow4", "radians", "transformDirection"];
30
39
  declare const TYPE_MAPPING: {
31
40
  readonly float: "f32";
32
41
  readonly int: "i32";
@@ -48,24 +57,50 @@ declare const TYPE_MAPPING: {
48
57
  readonly bvec3: "vec3<bool>";
49
58
  readonly bvec4: "vec4<bool>";
50
59
  };
60
+ declare const COMPONENT_COUNT_TO_TYPE: {
61
+ readonly 1: "float";
62
+ readonly 2: "vec2";
63
+ readonly 3: "vec3";
64
+ readonly 4: "vec4";
65
+ readonly 9: "mat3";
66
+ readonly 16: "mat4";
67
+ };
68
+ declare const BUILTIN_TYPES: {
69
+ readonly gl_FragCoord: "vec4";
70
+ readonly position: "vec3";
71
+ readonly normal: "vec3";
72
+ readonly uv: "vec2";
73
+ readonly color: "vec4";
74
+ };
75
+ declare const COMPARISON_OPERATORS: readonly ["equal", "notEqual", "lessThan", "lessThanEqual", "greaterThan", "greaterThanEqual"];
76
+ declare const LOGICAL_OPERATORS: readonly ["and", "or"];
51
77
 
52
- type NodeType = (typeof NODE_TYPES)[number];
78
+ type Constants = (typeof CONSTANTS)[number] | 'void';
79
+ type Conversions = (typeof CONVERSIONS)[number];
53
80
  type Functions = (typeof FUNCTIONS)[number];
54
81
  type Operators = (typeof OPERATOR_KEYS)[number];
55
82
  interface NodeProps {
56
83
  id?: string;
84
+ args?: X[];
85
+ type?: string;
57
86
  children?: X[];
58
- defaultValue?: number | number[];
87
+ returnType?: Constants;
88
+ value?: number | number[] | boolean;
89
+ paramInfo?: Array<{
90
+ name: string;
91
+ type: string;
92
+ }>;
59
93
  }
60
94
  interface NodeConfig {
61
95
  isWebGL?: boolean;
62
96
  uniforms?: Set<string>;
97
+ functions?: Set<string>;
63
98
  onUniform?: (name: string, value: any) => void;
64
99
  }
65
100
  type _Swizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
66
101
  type Swizzles = _Swizzles<'x' | 'y' | 'z' | 'w'> | _Swizzles<'r' | 'g' | 'b' | 'a'> | _Swizzles<'p' | 'q'> | _Swizzles<'s' | 't'>;
67
- type NodeTypes = 'uniform' | 'variable' | 'swizzle' | 'operator' | 'node_type' | 'math_fun' | 'declare' | 'assign' | 'fn' | 'if' | 'loop' | 'scope';
68
- interface NodeProxy extends Record<Swizzles, NodeProxy> {
102
+ type NodeTypes = 'uniform' | 'variable' | 'swizzle' | 'operator' | 'conversions' | 'math_fun' | 'declare' | 'assign' | 'fn_def' | 'fn_run' | 'if' | 'loop' | 'scope' | 'switch' | 'case' | 'default' | 'ternary' | 'attribute' | 'varying' | 'builtin' | 'constant' | 'vertex_stage';
103
+ interface NodeProxy extends Record<Swizzles | Conversions, NodeProxy> {
69
104
  add(n: X): NodeProxy;
70
105
  sub(n: X): NodeProxy;
71
106
  mul(n: X): NodeProxy;
@@ -82,48 +117,118 @@ interface NodeProxy extends Record<Swizzles, NodeProxy> {
82
117
  not(): NodeProxy;
83
118
  assign(n: X): NodeProxy;
84
119
  toVar(name?: string): NodeProxy;
120
+ toConst(name?: string): NodeProxy;
121
+ abs(): NodeProxy;
122
+ sin(): NodeProxy;
123
+ cos(): NodeProxy;
124
+ tan(): NodeProxy;
125
+ asin(): NodeProxy;
126
+ acos(): NodeProxy;
127
+ atan(): NodeProxy;
128
+ atan2(x: X): NodeProxy;
129
+ pow(y: X): NodeProxy;
130
+ pow2(): NodeProxy;
131
+ pow3(): NodeProxy;
132
+ pow4(): NodeProxy;
133
+ sqrt(): NodeProxy;
134
+ inverseSqrt(): NodeProxy;
135
+ exp(): NodeProxy;
136
+ exp2(): NodeProxy;
137
+ log(): NodeProxy;
138
+ log2(): NodeProxy;
139
+ floor(): NodeProxy;
140
+ ceil(): NodeProxy;
141
+ round(): NodeProxy;
142
+ fract(): NodeProxy;
143
+ trunc(): NodeProxy;
144
+ min(y: X): NodeProxy;
145
+ max(y: X): NodeProxy;
146
+ clamp(min: X, max: X): NodeProxy;
147
+ saturate(): NodeProxy;
148
+ mix(y: X, a: X): NodeProxy;
149
+ step(edge: X): NodeProxy;
150
+ smoothstep(edge0: X, edge1: X): NodeProxy;
151
+ length(): NodeProxy;
152
+ distance(y: X): NodeProxy;
153
+ dot(y: X): NodeProxy;
154
+ cross(y: X): NodeProxy;
155
+ normalize(): NodeProxy;
156
+ reflect(N: X): NodeProxy;
157
+ refract(N: X, eta: X): NodeProxy;
158
+ sign(): NodeProxy;
159
+ oneMinus(): NodeProxy;
160
+ reciprocal(): NodeProxy;
161
+ negate(): NodeProxy;
162
+ dFdx(): NodeProxy;
163
+ dFdy(): NodeProxy;
164
+ fwidth(): NodeProxy;
85
165
  toString(c?: NodeConfig): string;
86
166
  type: NodeTypes;
87
167
  props: NodeProps;
88
168
  isProxy: true;
89
169
  }
90
- type X = NodeProxy | number | string | null | undefined;
170
+ type X = NodeProxy | number | string | boolean | null | undefined;
91
171
 
92
172
  declare const code: (target: X, c?: NodeConfig | null) => string;
93
173
 
174
+ declare const infer: (target: X, c?: NodeConfig) => Constants;
175
+ declare const inferParameterTypes: (args: X[], c?: NodeConfig) => Constants[];
176
+
94
177
  declare const node: (type: NodeTypes, props?: NodeProps | null, ...args: X[]) => NodeProxy;
95
178
  declare const v: (...args: X[]) => NodeProxy;
96
- declare const u: (key: string, defaultValue?: number | number[]) => NodeProxy;
97
179
  declare const s: (key: Swizzles, arg: X) => NodeProxy;
98
180
  declare const n: (key: string, ...args: X[]) => NodeProxy;
99
181
  declare const o: (key: Operators, ...args: X[]) => NodeProxy;
100
182
  declare const f: (key: Functions, ...args: X[]) => NodeProxy;
183
+ declare const u: (id: string, value?: number | number[] | boolean) => NodeProxy;
184
+ declare const select: (x: X, y: X, z: X) => NodeProxy;
101
185
 
102
- declare const If: (x: X, callback: () => void) => {
103
- ElseIf: (y: X, elseCallback: () => void) => void;
186
+ declare const If: (condition: X, callback: () => void) => {
187
+ ElseIf: (newCondition: X, elseIfCallback: () => void) => /*elided*/ any;
104
188
  Else: (elseCallback: () => void) => void;
105
189
  };
106
190
  declare const Loop: (x: X, callback?: (params: {
107
191
  i: NodeProxy;
108
192
  }) => void) => NodeProxy;
109
- declare const Fn: (callback: (args: X[]) => NodeProxy) => (...args: X[]) => NodeProxy;
110
- declare const toVar: (x: X) => (id: string) => NodeProxy;
193
+ declare const Switch: (value: X) => {
194
+ Case: (...values: X[]) => (callback: () => void) => /*elided*/ any;
195
+ Default: (callback: () => void) => void;
196
+ };
197
+ declare const Fn: (callback: (args: NodeProxy[]) => NodeProxy) => (...args: NodeProxy[]) => NodeProxy;
198
+ declare const toVar: (x: X) => (id?: string) => NodeProxy;
199
+ declare const toConst: (x: X) => (id?: string) => NodeProxy;
111
200
  declare const assign: (x: X) => (y: X) => X;
201
+ declare const varying: (value: X, name?: string) => NodeProxy;
112
202
 
113
203
  declare const isSwizzle: (key: unknown) => key is Swizzles;
114
204
  declare const isOperator: (key: unknown) => key is Operators;
115
- declare const isNodeType: (key: unknown) => key is NodeType;
116
205
  declare const isFunction: (key: unknown) => key is Functions;
206
+ declare const isConversion: (key: unknown) => key is Conversions;
207
+ declare const isNodeProxy: (x: unknown) => x is NodeProxy;
208
+ declare const hex2rgb: (hex: number) => number[];
117
209
  declare const getId: () => string;
118
210
  declare const joins: (children: X[], c: NodeConfig) => string;
119
- declare const inferType: (target: X, c: NodeConfig) => string;
211
+ declare const formatConversions: (x: X, c?: NodeConfig) => string;
212
+ declare const getOperator: (op: X) => "/" | "+" | "-" | "*" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "&" | "|" | "^" | "<<" | ">>";
120
213
  declare const fragment: (x: X, c: NodeConfig) => string;
121
214
  declare const vertex: (x: X, c: NodeConfig) => string;
122
215
 
123
216
  declare const iResolution: NodeProxy;
124
217
  declare const iMouse: NodeProxy;
125
218
  declare const iTime: NodeProxy;
126
- declare const fragCoord: NodeProxy;
219
+ declare const position: NodeProxy;
220
+ declare const uv: (index?: number) => NodeProxy;
221
+ declare const vertexColor: (index?: number) => NodeProxy;
222
+ declare const attribute: (id: string, type?: string) => NodeProxy;
223
+ declare const vertexStage: (value: X) => NodeProxy;
224
+ declare const positionLocal: NodeProxy;
225
+ declare const positionWorld: NodeProxy;
226
+ declare const positionView: NodeProxy;
227
+ declare const normalLocal: NodeProxy;
228
+ declare const normalWorld: NodeProxy;
229
+ declare const normalView: NodeProxy;
230
+ declare const screenCoordinate: NodeProxy;
231
+ declare const screenUV: NodeProxy;
127
232
  declare const float: (x: X) => NodeProxy;
128
233
  declare const int: (x: X) => NodeProxy;
129
234
  declare const uint: (x: X) => NodeProxy;
@@ -143,12 +248,17 @@ declare const uvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
143
248
  declare const bvec2: (x?: X, y?: X) => NodeProxy;
144
249
  declare const bvec3: (x?: X, y?: X, z?: X) => NodeProxy;
145
250
  declare const bvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
251
+ declare const color: (r?: X, g?: X, b?: X) => NodeProxy;
252
+ declare const texture: (x: X, y: X, z?: X) => NodeProxy;
253
+ declare const cubeTexture: (x: X, y: X, z?: X) => NodeProxy;
254
+ declare const textureSize: (x: X, y?: X) => NodeProxy;
146
255
  declare const abs: (x: X) => NodeProxy;
147
256
  declare const acos: (x: X) => NodeProxy;
148
257
  declare const all: (x: X) => NodeProxy;
149
258
  declare const any: (x: X) => NodeProxy;
150
259
  declare const asin: (x: X) => NodeProxy;
151
- declare const atan: (y: X, x: X) => NodeProxy;
260
+ declare const atan: (y: X, x?: X) => NodeProxy;
261
+ declare const atan2: (y: X, x: X) => NodeProxy;
152
262
  declare const bitcast: (x: X, y: X) => NodeProxy;
153
263
  declare const cbrt: (x: X) => NodeProxy;
154
264
  declare const ceil: (x: X) => NodeProxy;
@@ -360,7 +470,7 @@ declare const createBufferLayout: (shaderLocation: number, dataLength: number, c
360
470
 
361
471
  declare const defaultVertexGLSL = "\n#version 300 es\nvoid main() {\n float x = float(gl_VertexID % 2) * 4.0 - 1.0;\n float y = float(gl_VertexID / 2) * 4.0 - 1.0;\n gl_Position = vec4(x, y, 0.0, 1.0);\n}\n";
362
472
  declare const defaultFragmentGLSL = "\n#version 300 es\nprecision mediump float;\nuniform vec2 iResolution;\nout vec4 fragColor;\nvoid main() {\n fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n}\n";
363
- declare const createProgram: (c: WebGLRenderingContext, vs?: string | X, fs?: string | X) => WebGLProgram | undefined;
473
+ declare const createProgram: (c: WebGLRenderingContext, vs?: string | X, fs?: string | X, onError?: () => void) => void | WebGLProgram;
364
474
  declare const createVbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
365
475
  declare const createIbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
366
476
  declare const getStride: (count: number, value: number[], iboValue?: number[]) => number;
@@ -434,4 +544,4 @@ declare const createGL: (props?: Partial<GL>) => EventState<{
434
544
  }): GL;
435
545
  }, any[] | unknown[]>;
436
546
 
437
- export { type Attribute, type Attributes, FUNCTIONS, Fn, type Functions, type GL, type GLClearMode, type GLDrawMode, type GLDrawType, type GPUBindGroup, type GPUBuffer, type GPUContext, type GPUDevice, type GPUPipeline, If, Loop, NODE_TYPES, type NodeConfig, type NodeProps, type NodeProxy, type NodeType, type NodeTypes, OPERATORS, OPERATOR_KEYS, type Operators, type PrecisionMode, SWIZZLES, type Swizzles, TYPE_MAPPING, type Uniform, type Uniforms, type WebGLState, type WebGPUState, type X, abs, acos, alignTo256, all, any, asin, assign, atan, bitcast, bool, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, cos, createAttrib, createBindGroup, createBufferLayout, createDescriptor, createDevice, createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffer, cross, dFdx, dFdy, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, degrees, difference, dig, distance, dot, each, equals, exp, exp2, ext, f, faceforward, fig, float, floor, flush, fract, fragCoord, fragment, fwidth, getId, getStride, iMouse, iResolution, iTime, inferType, int, inverseSqrt, is, isFunction, isGL, isNodeType, isOperator, isServer, isSwizzle, isWebGPUSupported, ivec2, ivec3, ivec4, joins, length, lengthSq, log, log2, mat2, mat3, mat4, max, min, mix, n, negate, node, normalize, o, oneMinus, pow, pow2, pow3, pow4, radians, reciprocal, reflect, refract, replace, round, s, saturate, sig, sign, sin, smoothstep, sqrt, step, tan, toVar, transformDirection, trunc, u, uint, uvec2, uvec3, uvec4, v, vec2, vec3, vec4, vertex, webgl, webgpu };
547
+ export { ADDITIONAL_FUNCTIONS, type Attribute, type Attributes, BOOL_RETURN_FUNCTIONS, BUILTIN_TYPES, COMPARISON_OPERATORS, COMPONENT_COUNT_TO_TYPE, CONSTANTS, CONVERSIONS, type Constants, type Conversions, FIRST_ARG_TYPE_FUNCTIONS, FUNCTIONS, Fn, type Functions, type GL, type GLClearMode, type GLDrawMode, type GLDrawType, type GPUBindGroup, type GPUBuffer, type GPUContext, type GPUDevice, type GPUPipeline, HIGHEST_TYPE_FUNCTIONS, If, LOGICAL_OPERATORS, Loop, type NodeConfig, type NodeProps, type NodeProxy, type NodeTypes, OPERATORS, OPERATOR_KEYS, type Operators, PRESERVE_TYPE_FUNCTIONS, type PrecisionMode, SCALAR_RETURN_FUNCTIONS, SWIZZLES, Switch, type Swizzles, TYPE_MAPPING, type Uniform, type Uniforms, VEC3_RETURN_FUNCTIONS, VEC4_RETURN_FUNCTIONS, type WebGLState, type WebGPUState, type X, abs, acos, alignTo256, all, any, asin, assign, atan, atan2, attribute, bitcast, bool, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, cos, createAttrib, createBindGroup, createBufferLayout, createDescriptor, createDevice, createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffer, cross, cubeTexture, dFdx, dFdy, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, degrees, difference, dig, distance, dot, each, equals, exp, exp2, ext, f, faceforward, fig, float, floor, flush, formatConversions, fract, fragment, fwidth, getId, getOperator, getStride, hex2rgb, iMouse, iResolution, iTime, infer, inferParameterTypes, int, inverseSqrt, is, isConversion, isFunction, isGL, isNodeProxy, isOperator, isServer, isSwizzle, isWebGPUSupported, ivec2, ivec3, ivec4, joins, length, lengthSq, log, log2, mat2, mat3, mat4, max, min, mix, n, negate, node, normalLocal, normalView, normalWorld, normalize, o, oneMinus, position, positionLocal, positionView, positionWorld, pow, pow2, pow3, pow4, radians, reciprocal, reflect, refract, replace, round, s, saturate, screenCoordinate, screenUV, select, sig, sign, sin, smoothstep, sqrt, step, tan, texture, textureSize, toConst, toVar, transformDirection, trunc, u, uint, uv, uvec2, uvec3, uvec4, v, varying, vec2, vec3, vec4, vertex, vertexColor, vertexStage, webgl, webgpu };
package/dist/index.js CHANGED
@@ -1,41 +1,46 @@
1
- "use strict";var D=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Se=(e,t)=>{for(var r in t)D(e,r,{get:t[r],enumerable:!0})},Ae=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Pe(t))!Ge.call(e,n)&&n!==r&&D(e,n,{get:()=>t[n],enumerable:!(o=Le(t,n))||o.enumerable});return e};var Fe=e=>Ae(D({},"__esModule",{value:!0}),e);var Tr={};Se(Tr,{FUNCTIONS:()=>V,Fn:()=>qe,If:()=>De,Loop:()=>We,NODE_TYPES:()=>W,OPERATORS:()=>U,OPERATOR_KEYS:()=>q,SWIZZLES:()=>Ce,TYPE_MAPPING:()=>Y,abs:()=>gt,acos:()=>bt,alignTo256:()=>he,all:()=>Xt,any:()=>vt,asin:()=>yt,assign:()=>K,atan:()=>ht,bitcast:()=>Tt,bool:()=>et,bvec2:()=>lt,bvec3:()=>xt,bvec4:()=>dt,cbrt:()=>Et,ceil:()=>wt,clamp:()=>Rt,code:()=>c,cos:()=>_t,createAttrib:()=>te,createBindGroup:()=>ie,createBufferLayout:()=>pe,createDescriptor:()=>ae,createDevice:()=>ne,createGL:()=>we,createIbo:()=>J,createPipeline:()=>se,createProgram:()=>Z,createTexture:()=>re,createTextureSampler:()=>fe,createUniformBuffer:()=>ce,createVbo:()=>Q,createVertexBuffer:()=>ue,cross:()=>Lt,dFdx:()=>Pt,dFdy:()=>Gt,default:()=>hr,defaultFragmentGLSL:()=>ye,defaultVertexGLSL:()=>ve,degrees:()=>St,difference:()=>At,dig:()=>$e,distance:()=>Ft,dot:()=>Ut,each:()=>xe,equals:()=>Nt,exp:()=>zt,exp2:()=>Bt,ext:()=>ze,f:()=>s,faceforward:()=>$t,fig:()=>Be,float:()=>Ze,floor:()=>It,flush:()=>Ue,fract:()=>Ct,fragCoord:()=>He,fragment:()=>G,fwidth:()=>Mt,getId:()=>P,getStride:()=>ee,iMouse:()=>je,iResolution:()=>ke,iTime:()=>Ke,inferType:()=>_,int:()=>Qe,inverseSqrt:()=>Ot,is:()=>x,isFunction:()=>j,isGL:()=>yr,isNodeType:()=>Me,isOperator:()=>k,isServer:()=>Te,isSwizzle:()=>N,isWebGPUSupported:()=>Ee,ivec2:()=>at,ivec3:()=>ut,ivec4:()=>ct,joins:()=>z,length:()=>Dt,lengthSq:()=>Wt,log:()=>qt,log2:()=>Vt,mat2:()=>nt,mat3:()=>st,mat4:()=>it,max:()=>Yt,min:()=>kt,mix:()=>jt,n:()=>d,negate:()=>Kt,node:()=>l,normalize:()=>Ht,o:()=>be,oneMinus:()=>Zt,pow:()=>Qt,pow2:()=>Jt,pow3:()=>er,pow4:()=>tr,radians:()=>rr,reciprocal:()=>or,reflect:()=>nr,refract:()=>sr,replace:()=>Ne,round:()=>ir,s:()=>H,saturate:()=>ar,sig:()=>Ie,sign:()=>ur,sin:()=>cr,smoothstep:()=>fr,sqrt:()=>pr,step:()=>mr,tan:()=>lr,toVar:()=>$,transformDirection:()=>xr,trunc:()=>dr,u:()=>F,uint:()=>Je,uvec2:()=>ft,uvec3:()=>pt,uvec4:()=>mt,v:()=>Ye,vec2:()=>tt,vec3:()=>rt,vec4:()=>ot,vertex:()=>S,webgl:()=>oe,webgpu:()=>me});module.exports=Fe(Tr);var L=require("reev"),M=require("refr");var I=require("reev");var x={arr:Array.isArray,bol:e=>typeof e=="boolean",str:e=>typeof e=="string",num:e=>typeof e=="number",int:e=>Number.isInteger(e),fun:e=>typeof e=="function",und:e=>typeof e>"u",nul:e=>e===null,set:e=>e instanceof Set,map:e=>e instanceof Map,obj:e=>!!e&&e.constructor.name==="Object",nan:e=>typeof e=="number"&&Number.isNaN(e)},xe=(e,t)=>e.forEach(t),Ue=(e,...t)=>{xe(e,r=>r(...t))},Ne=(e="",t="_",r="/")=>e.split(t).join(r),ze=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Be=(e=0)=>`${e}`.split(".")[1]?.length??0,$e=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Ie=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var Ce=["x","y","z","w","r","g","b","a","s","t","p","q"],W=["float","int","uint","bool","color","vec2","vec3","vec4","mat2","mat3","mat4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","bvec2","bvec3","bvec4"],U={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},q=Object.keys(U),V=["abs","acos","asin","atan","atan2","ceil","clamp","cos","cross","degrees","distance","dot","exp","exp2","faceforward","floor","fract","length","all","any","bitcast","cbrt","dFdx","dFdy","difference","equals","fwidth","inverseSqrt","lengthSq","log","log2","max","min","mix","negate","normalize","oneMinus","pow","pow2","pow3","pow4","radians","reciprocal","reflect","refract","round","saturate","sign","sin","smoothstep","sqrt","step","tan","transformDirection","trunc"],Y={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>"};var N=e=>x.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),k=e=>q.includes(e),Me=e=>W.includes(e),j=e=>V.includes(e),Oe=0,P=()=>`i${Oe++}`,z=(e,t)=>e.filter(r=>!x.und(r)&&!x.nul(r)).map(r=>c(r,t)).join(", "),_=(e,t)=>{if(!e||typeof e!="object")return"float";let{type:r,props:o}=e,{children:n=[]}=o,[i,a,f]=n;if(r==="node_type")return i;if(r==="operator"){let v=_(a,t),m=_(f,t);return v===m||v.includes("vec")?v:m.includes("vec")?m:"float"}return r==="math_fun"?["normalize","cross","reflect"].includes(i)?_(n[1],t):(["dot","distance","length"].includes(i),"float"):"float"},de=e=>!e.uniforms||e.uniforms.size===0?"":Array.from(e.uniforms).map((r,o)=>e.isWebGL?`uniform vec2 ${r};`:`@group(0) @binding(${o}) var<uniform> ${r}: vec2f;`).join(`
2
- `)+`
3
- `,ge=(e,t,r=!0)=>r?`
4
- ${t}
1
+ import{durable as H,event as et}from"reev";import{createFrame as tt,createQueue as rt}from"refr";import{nested as j}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)},$e=(e,t)=>e.forEach(t),it=(e,...t)=>{$e(e,r=>r(...t))},at=(e="",t="_",r="/")=>e.split(t).join(r),ut=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",ct=(e=0)=>`${e}`.split(".")[1]?.length??0,ft=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),pt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var mt=["x","y","z","w","r","g","b","a","s","t","p","q"],L=["bool","uint","int","float","bvec2","bvec3","bvec4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","vec2","vec3","vec4","color","mat2","mat3","mat4"],Q=["toFloat","toInt","toUint","toBool","toVec2","toVec3","toVec4","toIvec2","toIvec3","toIvec4","toUvec2","toUvec3","toUvec4","toBvec2","toBvec3","toBvec4","toMat2","toMat3","toMat4","toColor"],F={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},J=Object.keys(F),$=["dot","distance","length","lengthSq","determinant","luminance"],B=["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"],V=["cross"],M=["reflect","refract"],W=["min","max","mix","clamp","step","smoothstep"],D=["texture","textureLod","textureSize","cubeTexture"],Be=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],ee=[...$,...B,...z,...V,...M,...W,...D,...Be],te={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>"},q={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},re={gl_FragCoord:"vec4",position:"vec3",normal:"vec3",uv:"vec2",color:"vec4"},oe=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],ne=["and","or"];var Y=e=>l.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),se=e=>J.includes(e),ie=e=>ee.includes(e),ae=e=>Q.includes(e),ue=e=>!e||!l.fun(e)?!1:e.isProxy,ze=0,ce=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,o=(e&255)/255;return[t,r,o]},R=()=>`i${ze++}`,k=(e,t)=>e.filter(r=>!l.und(r)&&!l.nul(r)).map(r=>c(r,t)).join(", "),O=(e,t)=>l.str(e)?t?.isWebGL?e:te[e]:"",fe=e=>F[e]||e,pe=e=>{let t=Array.from(e.uniforms).map((o,n)=>e.isWebGL?`uniform ${o};`:`@group(0) @binding(${n}) var<uniform> ${o};`).join(`
2
+ `),r=Array.from(e.functions).join(`
3
+ `);return`${t}
4
+ ${r}`},le=(e,t,r=!0)=>r?`
5
5
  #version 300 es
6
6
  precision mediump float;
7
- uniform vec2 iResolution;
8
- uniform vec2 iMouse;
9
- uniform float iTime;
10
7
  out vec4 fragColor;
8
+ ${t}
11
9
  void main() {
12
- ${e}
10
+ fragColor = ${e};
13
11
  }`.trim():`
14
- @group(0) @binding(0) var<uniform> iResolution: vec2f;
15
- @group(0) @binding(1) var<uniform> iMouse: vec2f;
16
- @group(0) @binding(2) var<uniform> iTime: f32;
17
12
  ${t}
18
13
  @fragment
19
14
  fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
20
- ${e}
21
- }`.trim(),G=(e,t)=>{let r=c(e,t),o=de(t);return ge(r,o,t.isWebGL)},S=(e,t)=>{let r=c(e,t),o=de(t);return ge(r,o,t.isWebGL)};var c=(e,t)=>{if(t||(t={}),t.uniforms||(t.uniforms=new Set),x.num(e))return e.toFixed(1);if(x.str(e))return e;if(!e)return"";let{type:r,props:o}=e,{id:n="",children:i=[]}=o,[a,f,v]=i;if(r==="uniform")return t.uniforms.add(n),t.onUniform?.(n,o.defaultValue),n;if(r==="variable")return n;if(r==="swizzle")return`${c(f,t)}.${c(a,t)}`;if(r==="node_type"){if(!x.str(a))return n;let m=!t.isWebGL&&a.startsWith("vec")?`${a}f`:a,X=z(i.slice(1),t);return`${m}(${X})`}if(r==="operator"){if(a==="not"||a==="bitNot")return`!${c(f,t)}`;let m=U[a];return`(${c(f,t)} ${m} ${c(v,t)})`}if(r==="math_fun")return`${a}(${z(i.slice(1),t)})`;if(r==="assign")return`${c(a,t)} = ${c(f,t)};`;if(r==="scope")return i.map(m=>c(m,t)).join(`
22
- `);if(r==="loop")return`for (int i = 0; i < ${a}; i++) {
15
+ return ${e};
16
+ }`.trim(),U=(e,t)=>{let r=c(e,t),o=pe(t);return le(r,o,t.isWebGL)},G=(e,t)=>{let r=c(e,t),o=pe(t);return le(r,o,t.isWebGL)};var me=e=>l.bol(e)?"bool":l.num(e)?Number.isInteger(e)?"int":"float":l.arr(e)&&q[e.length]||"float",xe=(e,t,r)=>{if(oe.includes(r)||ne.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=L.indexOf(e),n=L.indexOf(t);return o>=n?e:t},Ve=e=>e.reduce((t,r)=>{let o=_(r),n=L.indexOf(t);return L.indexOf(o)>n?o:t},"float"),Me=e=>q[e]||"vec4",We=e=>e?re[e]:"vec3",De=(e,t)=>{let r=t.length>0?_(t[0]):"float";return M.includes(e)?r:$.includes(e)?"float":B.includes(e)?"bool":z.includes(e)?r:V.includes(e)?"vec3":D.includes(e)?"vec4":W.includes(e)?Ve(t):r},_=(e,t)=>{if(!e)throw"";if(!ue(e))return me(e);let{type:r,props:o}=e,{id:n,children:s=[],value:a,returnType:f}=o,[X,p,m]=s;return r==="uniform"||r==="variable"||r==="constant"||r==="attribute"||r==="varying"?me(a):r==="conversions"?X:r==="operator"?xe(_(p,t),_(m,t),X):r==="math_fun"?De(X,s.slice(1)):r==="swizzle"?Me(X.length):r==="ternary"?xe(_(p,t),_(m,t),"add"):r==="fn_run"||r==="fn_def"?f:r==="builtin"?We(n):"float"},Et=(e,t)=>e.map(r=>_(r,t));var c=(e,t)=>{if(t||(t={}),t.uniforms||(t.uniforms=new Set),t.functions||(t.functions=new Set),l.num(e))return e.toFixed(1);if(l.str(e))return e;if(l.bol(e))return e.toString();if(!e)return"";let{type:r,props:o}=e,{id:n="",children:s=[]}=o,[a,f,X]=s;if(r==="uniform"){let p=_(e,t);return t.uniforms.add(`${p} ${n}`),t.onUniform?.(n,o.value),n}if(r==="variable"||r==="varying"||r==="constant"||r==="attribute")return n;if(r==="vertex_stage")return c(a,t);if(r==="swizzle")return`${c(f,t)}.${c(a,t)}`;if(r==="operator")return a==="not"||a==="bitNot"?`!${c(f,t)}`:`(${c(f,t)} ${fe(a)} ${c(X,t)})`;if(r==="math_fun")return`${a}(${k(s.slice(1),t)})`;if(r==="conversions")return`${O(a,t)}(${k(s.slice(1),t)})`;if(r==="scope")return s.map(p=>c(p,t)).join(`
17
+ `);if(r==="assign")return`${c(a,t)} = ${c(f,t)};`;if(r==="fn_run")return t.functions.add(c(a,t)),`${n}(${s.slice(1).map(p=>c(p,t)).join(", ")})`;if(r==="fn_def"){let{paramInfo:p=[],returnType:m}=o,y=c(a,t),C=f?`return ${c(f,t)};`:"";if(t?.isWebGL){let T=p.map(({name:E,type:h})=>`${h} ${E}`).join(", ");return`${m} ${n}(${T}) {
18
+ ${y}
19
+ ${C}
20
+ }`}else{let T=O(m,t),E=p.map(({name:h,type:P})=>{let g=O(P,t);return`${h}: ${g}`}).join(", ");return`fn ${n}(${E}) -> ${T} {
21
+ ${y}
22
+ ${C}
23
+ }`}}if(r==="loop")return`for (int i = 0; i < ${a}; i++) {
23
24
  ${c(f,t)}
24
- }`;if(r==="fn"){let m=c(a,t);return f&&(m+=`
25
- return ${c(f,t)};`),m}if(r==="if"){let m=`if (${c(a,t)}) {
25
+ }`;if(r==="if"){let p=`if (${c(a,t)}) {
26
26
  ${c(f,t)}
27
- }`;for(let X=2;X<i.length;X+=2){let R=X>=i.length-1;m+=R?` else {
28
- ${c(i[X],t)}
29
- }`:` else if (${c(i[X],t)}) {
30
- ${c(i[X+1],t)}
31
- }`}return m}if(r==="declare"){let m=_(f,t),X=a?.props?.id;if(t.isWebGL)return`${m} ${X} = ${c(f,t)};`;let R=Y[m];return`var ${X}: ${R} = ${c(f,t)};`}return c(a,t)};var w=null,A=(e,t=()=>{})=>{let r=w;w=e,t(),w=r},B=e=>{w&&(w.props.children||(w.props.children=[]),w.props.children.push(e))},De=(e,t)=>{let r=l("scope");A(r,t);let o=l("if",null,e,r);return B(o),{ElseIf:(n,i)=>{let a=l("scope");A(a,i),o.props.children.push(n,a)},Else:n=>{let i=l("scope");A(i,n),o.props.children.push(i)}}},We=(e,t)=>{let r=l("scope");A(r,()=>t?.({i:l("variable",{id:"i"})}));let o=l("loop",null,e,r);return B(o),o},qe=e=>(...t)=>{let r,o=l("scope");return A(o,()=>r=e(t)),l("fn",null,o,r)},$=e=>t=>{t||(t=P());let r=l("variable",{id:t}),o=l("declare",null,r,e);return B(o),r},K=e=>t=>{let r=l("assign",null,e,t);return B(r),e};var Ve=e=>t=>{if(t==="string")return c(e)},l=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=new Proxy(()=>{},{get(n,i){return i==="type"?e:i==="props"?t:i==="toVar"?$(o):i==="assign"?K(o):i==="isProxy"?!0:i==="toString"?c.bind(null,o):i===Symbol.toPrimitive?Ve(o):N(i)?H(i,o):k(i)?(...a)=>be(i,o,...a):j(i)?(...a)=>s(i,o,...a):$(o)("")},set(n,i,a){return N(i)?(H(i,o).assign(a),!0):!1}});return o},Ye=(...e)=>l("variable",{id:P()},...e),F=(e,t)=>l("uniform",{defaultValue:t},e),H=(e,t)=>l("swizzle",null,e,t),d=(e,...t)=>l("node_type",null,e,...t),be=(e,...t)=>l("operator",null,e,...t),s=(e,...t)=>l("math_fun",null,e,...t);var ke=F("iResolution",[1280,800]),je=F("iMouse",[0,0]),Ke=F("iTime",0),He=l("variable",{id:"fragCoord"}),Ze=e=>d("float",e),Qe=e=>d("int",e),Je=e=>d("uint",e),et=e=>d("bool",e),tt=(e,t)=>d("vec2",e,t),rt=(e,t,r)=>d("vec3",e,t,r),ot=(e,t,r,o)=>d("vec4",e,t,r,o),nt=(...e)=>d("mat2",...e),st=(...e)=>d("mat3",...e),it=(...e)=>d("mat4",...e),at=(e,t)=>d("ivec2",e,t),ut=(e,t,r)=>d("ivec3",e,t,r),ct=(e,t,r,o)=>d("ivec4",e,t,r,o),ft=(e,t)=>d("uvec2",e,t),pt=(e,t,r)=>d("uvec3",e,t,r),mt=(e,t,r,o)=>d("uvec4",e,t,r,o),lt=(e,t)=>d("bvec2",e,t),xt=(e,t,r)=>d("bvec3",e,t,r),dt=(e,t,r,o)=>d("bvec4",e,t,r,o),gt=e=>s("abs",e),bt=e=>s("acos",e),Xt=e=>s("all",e),vt=e=>s("any",e),yt=e=>s("asin",e),ht=(e,t)=>s("atan",e,t),Tt=(e,t)=>s("bitcast",e,t),Et=e=>s("cbrt",e),wt=e=>s("ceil",e),Rt=(e,t,r)=>s("clamp",e,t,r),_t=e=>s("cos",e),Lt=(e,t)=>s("cross",e,t),Pt=e=>s("dFdx",e),Gt=e=>s("dFdy",e),St=e=>s("degrees",e),At=(e,t)=>s("difference",e,t),Ft=(e,t)=>s("distance",e,t),Ut=(e,t)=>s("dot",e,t),Nt=(e,t)=>s("equals",e,t),zt=e=>s("exp",e),Bt=e=>s("exp2",e),$t=(e,t,r)=>s("faceforward",e,t,r),It=e=>s("floor",e),Ct=e=>s("fract",e),Mt=e=>s("fwidth",e),Ot=e=>s("inverseSqrt",e),Dt=e=>s("length",e),Wt=e=>s("lengthSq",e),qt=e=>s("log",e),Vt=e=>s("log2",e),Yt=(e,t)=>s("max",e,t),kt=(e,t)=>s("min",e,t),jt=(e,t,r)=>s("mix",e,t,r),Kt=e=>s("negate",e),Ht=e=>s("normalize",e),Zt=e=>s("oneMinus",e),Qt=(e,t)=>s("pow",e,t),Jt=e=>s("pow2",e),er=e=>s("pow3",e),tr=e=>s("pow4",e),rr=e=>s("radians",e),or=e=>s("reciprocal",e),nr=(e,t)=>s("reflect",e,t),sr=(e,t,r)=>s("refract",e,t,r),ir=e=>s("round",e),ar=e=>s("saturate",e),ur=e=>s("sign",e),cr=e=>s("sin",e),fr=(e,t,r)=>s("smoothstep",e,t,r),pr=e=>s("sqrt",e),mr=(e,t)=>s("step",e,t),lr=e=>s("tan",e),xr=(e,t)=>s("transformDirection",e,t),dr=e=>s("trunc",e);var ve=`
27
+ }`;for(let m=2;m<s.length;m+=2){let y=m>=s.length-1;p+=y?` else {
28
+ ${c(s[m],t)}
29
+ }`:` else if (${c(s[m],t)}) {
30
+ ${c(s[m+1],t)}
31
+ }`}return p}if(r==="switch"){let p=`switch (${c(a,t)}) {
32
+ `;for(let m of s.slice(1))p+=c(m,t)+`
33
+ `;return p+="}",p}if(r==="case"){let p=s.slice(0,-1),m=s[s.length-1],y="";for(let C of p)y+=`case ${c(C,t)}:
34
+ `;return y+=`${c(m,t)}
35
+ break;
36
+ `,y}if(r==="default"&&`${c(a,t)}`,r==="ternary")return`(${c(a,t)} ? ${c(f,t)} : ${c(X,t)})`;if(r==="declare"){let p=_(f,t),m=a?.props?.id;if(t.isWebGL)return`${p} ${m} = ${c(f,t)};`;let y=O(p);return`var ${m}: ${y} = ${c(f,t)};`}if(r==="builtin"){if(t?.isWebGL){if(n==="position")return"gl_FragCoord";if(n==="uv")return"gl_FragCoord.xy"}return n}return c(a,t)};var S=null,N=(e,t=()=>{})=>{let r=S;S=e,t(),S=r},w=e=>{S&&(S.props.children||(S.props.children=[]),S.props.children.push(e))},Lt=(e,t)=>{let r=u("scope");N(r,t);let o=u("if",null,e,r);w(o);let n=()=>({ElseIf:(s,a)=>{let f=u("scope");return N(f,a),o.props.children.push(s,f),n()},Else:s=>{let a=u("scope");N(a,s),o.props.children.push(a)}});return n()},Ot=(e,t)=>{let r=u("scope");N(r,()=>t?.({i:u("variable",{id:"i"})}));let o=u("loop",null,e,r);return w(o),o},Ut=e=>{let t=u("switch",null,e);w(t);let r=()=>({Case:(...o)=>n=>{let s=u("scope");N(s,n);let a=u("case",null,...o,s);return t.props.children.push(a),r()},Default:o=>{let n=u("scope");N(n,o);let s=u("default",null,n);t.props.children.push(s)}});return r()},Gt=e=>{let t=R();return(...r)=>{let o=u("scope"),n,s=[];for(let p=0;p<r.length;p++){let m=`p${p}`,y=u("variable",{id:m});s.push(y)}N(o,()=>n=e(s));let a=n?_(n):"void",f=r.map((p,m)=>({name:`p${m}`,type:_(p)})),X=u("fn_def",{id:t,returnType:a,paramInfo:f,args:r},o,n);return u("fn_run",{id:t,returnType:a},X,...s)}},de=e=>t=>{t||(t=R());let r=u("variable",{id:t}),o=u("declare",null,r,e);return w(o),r},be=e=>t=>{t||(t=R());let r=u("constant",{id:t}),o=u("declare",null,r,e);return w(o),r},ge=e=>t=>{let r=u("assign",null,e,t);return w(r),e},It=(e,t)=>{t||(t=R());let r=u("varying",{id:t}),o=u("declare",null,r,e);return w(o),r};var qe=e=>t=>{if(t==="string")return c(e)},u=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=new Proxy(()=>{},{get(n,s){if(s==="type")return e;if(s==="props")return t;if(s==="toVar")return de(o);if(s==="toConst")return be(o);if(s==="assign")return ge(o);if(s==="isProxy")return!0;if(s==="toString")return c.bind(null,o);if(s===Symbol.toPrimitive)return qe(o);if(Y(s))return ve(s,o);if(se(s))return(...a)=>Ye(s,o,...a);if(ie(s))return(...a)=>i(s,o,...a);if(ae(s))return b(s,o)},set(n,s,a){return Y(s)?(ve(s,o).assign(a),!0):!1}});return o},zt=(...e)=>u("variable",{id:R()},...e),ve=(e,t)=>u("swizzle",null,e,t),b=(e,...t)=>u("conversions",null,e,...t),Ye=(e,...t)=>u("operator",null,e,...t),i=(e,...t)=>u("math_fun",null,e,...t),I=(e,t)=>u("uniform",{id:e,value:t}),Vt=(e,t,r)=>u("ternary",null,e,t,r);var Yt=I("iResolution",[1280,800]),kt=I("iMouse",[0,0]),jt=I("iTime",0),Kt=u("variable",{id:"gl_FragCoord"}),Ht=(e=0)=>u("attribute",{id:`uv${e||""}`}),Zt=(e=0)=>u("attribute",{id:`color${e||""}`}),Qt=(e,t)=>u("attribute",{id:e,type:t}),Jt=e=>u("vertex_stage",null,e),er=u("builtin",{id:"positionLocal"}),tr=u("builtin",{id:"positionWorld"}),rr=u("builtin",{id:"positionView"}),or=u("builtin",{id:"normalLocal"}),nr=u("builtin",{id:"normalWorld"}),sr=u("builtin",{id:"normalView"}),ir=u("builtin",{id:"screenCoordinate"}),ar=u("builtin",{id:"screenUV"}),ur=e=>b("float",e),cr=e=>b("int",e),fr=e=>b("uint",e),pr=e=>b("bool",e),lr=(e,t)=>b("vec2",e,t),Xe=(e,t,r)=>b("vec3",e,t,r),mr=(e,t,r,o)=>b("vec4",e,t,r,o),xr=(...e)=>b("mat2",...e),dr=(...e)=>b("mat3",...e),br=(...e)=>b("mat4",...e),gr=(e,t)=>b("ivec2",e,t),vr=(e,t,r)=>b("ivec3",e,t,r),Xr=(e,t,r,o)=>b("ivec4",e,t,r,o),yr=(e,t)=>b("uvec2",e,t),Tr=(e,t,r)=>b("uvec3",e,t,r),Er=(e,t,r,o)=>b("uvec4",e,t,r,o),hr=(e,t)=>b("bvec2",e,t),_r=(e,t,r)=>b("bvec3",e,t,r),Pr=(e,t,r,o)=>b("bvec4",e,t,r,o),Rr=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Xe(...ce(e)):Xe(e,t,r),Sr=(e,t,r)=>i("texture",e,t,r),Nr=(e,t,r)=>i("cubeTexture",e,t,r),wr=(e,t)=>i("textureSize",e,t),Cr=e=>i("abs",e),Lr=e=>i("acos",e),Or=e=>i("all",e),Ur=e=>i("any",e),Gr=e=>i("asin",e),Ir=(e,t)=>t!==void 0?i("atan",e,t):i("atan",e),Ar=(e,t)=>i("atan",e,t),Fr=(e,t)=>i("bitcast",e,t),$r=e=>i("cbrt",e),Br=e=>i("ceil",e),zr=(e,t,r)=>i("clamp",e,t,r),Vr=e=>i("cos",e),Mr=(e,t)=>i("cross",e,t),Wr=e=>i("dFdx",e),Dr=e=>i("dFdy",e),qr=e=>i("degrees",e),Yr=(e,t)=>i("difference",e,t),kr=(e,t)=>i("distance",e,t),jr=(e,t)=>i("dot",e,t),Kr=(e,t)=>i("equals",e,t),Hr=e=>i("exp",e),Zr=e=>i("exp2",e),Qr=(e,t,r)=>i("faceforward",e,t,r),Jr=e=>i("floor",e),eo=e=>i("fract",e),to=e=>i("fwidth",e),ro=e=>i("inverseSqrt",e),oo=e=>i("length",e),no=e=>i("lengthSq",e),so=e=>i("log",e),io=e=>i("log2",e),ao=(e,t)=>i("max",e,t),uo=(e,t)=>i("min",e,t),co=(e,t,r)=>i("mix",e,t,r),fo=e=>i("negate",e),po=e=>i("normalize",e),lo=e=>i("oneMinus",e),mo=(e,t)=>i("pow",e,t),xo=e=>i("pow2",e),bo=e=>i("pow3",e),go=e=>i("pow4",e),vo=e=>i("radians",e),Xo=e=>i("reciprocal",e),yo=(e,t)=>i("reflect",e,t),To=(e,t,r)=>i("refract",e,t,r),Eo=e=>i("round",e),ho=e=>i("saturate",e),_o=e=>i("sign",e),Po=e=>i("sin",e),Ro=(e,t,r)=>i("smoothstep",e,t,r),So=e=>i("sqrt",e),No=(e,t)=>i("step",e,t),wo=e=>i("tan",e),Co=(e,t)=>i("transformDirection",e,t),Lo=e=>i("trunc",e);var ke=`
32
37
  #version 300 es
33
38
  void main() {
34
39
  float x = float(gl_VertexID % 2) * 4.0 - 1.0;
35
40
  float y = float(gl_VertexID / 2) * 4.0 - 1.0;
36
41
  gl_Position = vec4(x, y, 0.0, 1.0);
37
42
  }
38
- `,ye=`
43
+ `,je=`
39
44
  #version 300 es
40
45
  precision mediump float;
41
46
  uniform vec2 iResolution;
@@ -43,19 +48,19 @@ out vec4 fragColor;
43
48
  void main() {
44
49
  fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
45
50
  }
46
- `,Xe=(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}`)},Z=(e,t=ve,r=ye)=>{x.str(r)||(r=G(r,{isWebGL:!0})),x.str(t)||(t=S(r,{isWebGL:!0}));let o=e.createProgram(),n=Xe(e,t,e.VERTEX_SHADER),i=Xe(e,r,e.FRAGMENT_SHADER);if(!n||!i)return;if(e.attachShader(o,n),e.attachShader(o,i),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let a=e.getProgramInfoLog(o);e.deleteProgram(o),console.warn(`Could not link pg: ${a}`)},Q=(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},J=(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},ee=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},te=(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)},re=(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 oe=async e=>{let t=e.el.getContext("webgl2"),r=Z(t,e.vs,e.fs),o={context:t,program:r};t.useProgram(r);let n=0,i=(0,I.nested)(y=>t.getUniformLocation(r,y)),a=(0,I.nested)(y=>t.getAttribLocation(r,y)),f=(0,I.nested)(()=>n++);return{webgl:o,render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(y="",h,T)=>{let E=a(y,!0),b=Q(t,h),u=J(t,T),p=ee(e.count,h,T);te(t,p,E,b,u)},_uniform:(y,h)=>{let T=i(y);if(x.num(h))return t.uniform1f(T,h);let E=h.length;if(E<=4)return t[`uniform${E}fv`](T,h);E=Math.sqrt(E)<<0,t[`uniformMatrix${E}fv`](T,!1,h)},_texture:(y,h)=>{let T=new Image;Object.assign(T,{src:h,crossOrigin:"anonymous"}),T.decode().then(()=>{let E=i(y),b=f(y);re(t,T,E,b)})}}};var C=require("reev");var gr=`
51
+ `,ye=(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}`)},Te=(e,t=ke,r=je,o=()=>{})=>{l.str(r)||(r=U(r,{isWebGL:!0})),l.str(t)||(t=G(r,{isWebGL:!0}));let n=e.createProgram(),s=ye(e,t,e.VERTEX_SHADER),a=ye(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 f=e.getProgramInfoLog(n);e.deleteProgram(n),o(),console.warn(`Could not link pg: ${f}`)},Ee=(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},he=(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},_e=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},Pe=(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)},Re=(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 Se=async e=>{let t=e.el.getContext("webgl2"),r=Te(t,e.vs,e.fs,()=>void(e.isLoop=!1)),o={context:t,program:r};t.useProgram(r);let n=0,s=j(T=>t.getUniformLocation(r,T)),a=j(T=>t.getAttribLocation(r,T)),f=j(()=>n++);return{webgl:o,render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(T="",E,h)=>{let P=a(T,!0),g=Ee(t,E),x=he(t,h),d=_e(e.count,E,h);Pe(t,d,P,g,x)},_uniform:(T,E)=>{let h=s(T);if(l.num(E))return t.uniform1f(h,E);let P=E.length;if(P<=4)return t[`uniform${P}fv`](h,E);P=Math.sqrt(P)<<0,t[`uniformMatrix${P}fv`](h,!1,E)},_texture:(T,E)=>{let h=new Image;Object.assign(h,{src:E,crossOrigin:"anonymous"}),h.decode().then(()=>{let P=s(T),g=f(T);Re(t,h,P,g)})}}};import{nested as K}from"reev";var Ke=`
47
52
  @vertex
48
53
  fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
49
54
  let x = f32(vertex_index % 2u) * 4.0 - 1.0;
50
55
  let y = f32(vertex_index / 2u) * 4.0 - 1.0;
51
56
  return vec4f(x, y, 0.0, 1.0);
52
57
  }
53
- `,br=`
58
+ `,He=`
54
59
  @group(0) @binding(0) var<uniform> iResolution: vec2f;
55
60
 
56
61
  @fragment
57
62
  fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
58
63
  return vec4f(position.xy / iResolution, 0.0, 1.0);
59
64
  }
60
- `,ne=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}},se=(e,t,r,o,n=gr,i=br)=>{x.str(i)||(i=G(i,{isWebGL:!1})),x.str(n)||(n=S(n,{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:i.trim()}),entryPoint:"main",targets:[{format:t}]},layout:a,primitive:{topology:"triangle-list"}})},ie=(e,t)=>{let r=[],o=[];t.forEach((a,f)=>{if(!a)return;let v="buffer"in a,m=a instanceof GPUTextureView,X=a instanceof GPUSampler;if(v)r.push({binding:f,visibility:3,buffer:{type:"uniform"}});else if(m)r.push({binding:f,visibility:2,texture:{}});else if(X)r.push({binding:f,visibility:2,sampler:{}});else return;o.push({binding:f,resource:a})});let n=e.createBindGroupLayout({entries:r}),i=e.createBindGroup({layout:n,entries:o});return{layout:n,bindGroup:i}},ae=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),he=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}},ce=(e,t)=>{let r=new Float32Array(t),o=he(r.byteLength),n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},fe=(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}},Xr=(e,t)=>e/t,vr=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",pe=(e,t,r=6)=>{let o=Xr(t,r);return{arrayStride:o*4,attributes:[{shaderLocation:e,offset:0,format:vr(o)}]}};var me=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await ne(t),n={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},i=[],a=[],f=[],v=(0,C.nested)((b,u)=>{let{array:p,buffer:g}=ue(r,u);return a.push(g),f.push(pe(f.length,p.length,e.count)),n.needsUpdate=!0,{array:p,buffer:g}}),m=(0,C.nested)((b,u)=>{let{array:p,buffer:g}=ce(r,u);return n.resources[0].push({buffer:g}),n.needsUpdate=!0,{array:p,buffer:g}}),X=(0,C.nested)((b,{width:u,height:p})=>{let{texture:g,sampler:O}=fe(r,u,p);return n.resources[1].push(O,g.createView()),n.needsUpdate=!0,{texture:g,width:u,height:p}}),R=()=>{let b=[];i.length=0,n.resources.forEach(u=>{if(!u.length)return;let{layout:p,bindGroup:g}=ie(r,u);b.push(p),i.push(g)}),n.pipeline=se(r,o,f,b,e.vs,e.fs)};return{webgpu:n,render:()=>{if(n.loadingImg)return;n.needsUpdate&&R(),n.needsUpdate=!1;let b=r.createCommandEncoder(),u=b.beginRenderPass(ae(t));u.setPipeline(n.pipeline),i.forEach((p,g)=>u.setBindGroup(g,p)),a.forEach((p,g)=>u.setVertexBuffer(g,p)),u.draw(e.count,1,0,0),u.end(),r.queue.submit([b.finish()])},clean:()=>{},_attribute:(b="",u)=>{let{array:p,buffer:g}=v(b,u);r.queue.writeBuffer(g,0,p)},_uniform:(b,u)=>{x.num(u)&&(u=[u]);let{array:p,buffer:g}=m(b,u);p.set(u),r.queue.writeBuffer(g,0,p)},_texture:(b,u)=>{n.loadingImg++;let p=Object.assign(new Image,{src:u,crossOrigin:"anonymous"});p.decode().then(()=>{let{texture:g,width:O,height:_e}=X(b,p);r.queue.copyExternalImageToTexture({source:p},{texture:g},{width:O,height:_e}),n.loadingImg--})}}};var yr=e=>x.obj(e)?"isGL"in e:!1,Te=()=>typeof window>"u",Ee=()=>Te()?!1:"gpu"in navigator,le=performance.now(),we=e=>{let t=(0,L.event)({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=(0,M.createQueue)(),t.frame=(0,M.createFrame)(),t.attribute=(0,L.durable)((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n))),t.texture=(0,L.durable)((r,o)=>t.queue(()=>t._texture?.(r,o))),t.uniform=(0,L.durable)((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:le}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,Ee()||(t.isWebGL=!0),t.isWebGL?t(await oe(t)):t(await me(t)),t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.render(),t.isLoop)),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove))}),t("clean",()=>{t.frame.stop(),t.frame.clean(t.render),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,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[i,a]=t.size,{top:f,left:v}=t.el.getBoundingClientRect();t.mouse[0]=(o-f-i/2)/(i/2),t.mouse[1]=-(n-v-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{le=performance.now()/1e3,t.uniform("iTime",le)}),t(e)},hr=we;0&&(module.exports={FUNCTIONS,Fn,If,Loop,NODE_TYPES,OPERATORS,OPERATOR_KEYS,SWIZZLES,TYPE_MAPPING,abs,acos,alignTo256,all,any,asin,assign,atan,bitcast,bool,bvec2,bvec3,bvec4,cbrt,ceil,clamp,code,cos,createAttrib,createBindGroup,createBufferLayout,createDescriptor,createDevice,createGL,createIbo,createPipeline,createProgram,createTexture,createTextureSampler,createUniformBuffer,createVbo,createVertexBuffer,cross,dFdx,dFdy,defaultFragmentGLSL,defaultVertexGLSL,degrees,difference,dig,distance,dot,each,equals,exp,exp2,ext,f,faceforward,fig,float,floor,flush,fract,fragCoord,fragment,fwidth,getId,getStride,iMouse,iResolution,iTime,inferType,int,inverseSqrt,is,isFunction,isGL,isNodeType,isOperator,isServer,isSwizzle,isWebGPUSupported,ivec2,ivec3,ivec4,joins,length,lengthSq,log,log2,mat2,mat3,mat4,max,min,mix,n,negate,node,normalize,o,oneMinus,pow,pow2,pow3,pow4,radians,reciprocal,reflect,refract,replace,round,s,saturate,sig,sign,sin,smoothstep,sqrt,step,tan,toVar,transformDirection,trunc,u,uint,uvec2,uvec3,uvec4,v,vec2,vec3,vec4,vertex,webgl,webgpu});
65
+ `,Ne=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}},we=(e,t,r,o,n=Ke,s=He)=>{l.str(s)||(s=U(s,{isWebGL:!1})),l.str(n)||(n=G(n,{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"}})},Ce=(e,t)=>{let r=[],o=[];t.forEach((a,f)=>{if(!a)return;let X="buffer"in a,p=a instanceof GPUTextureView,m=a instanceof GPUSampler;if(X)r.push({binding:f,visibility:3,buffer:{type:"uniform"}});else if(p)r.push({binding:f,visibility:2,texture:{}});else if(m)r.push({binding:f,visibility:2,sampler:{}});else return;o.push({binding:f,resource:a})});let n=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:n,entries:o});return{layout:n,bindGroup:s}},Le=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),Ze=e=>Math.ceil(e/256)*256,Oe=(e,t)=>{let r=new Float32Array(t),o=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:o}},Ue=(e,t)=>{let r=new Float32Array(t),o=Ze(r.byteLength),n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},Ge=(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}},Qe=(e,t)=>e/t,Je=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Ie=(e,t,r=6)=>{let o=Qe(t,r);return{arrayStride:o*4,attributes:[{shaderLocation:e,offset:0,format:Je(o)}]}};var Ae=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await Ne(t),n={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],a=[],f=[],X=K((g,x)=>{let{array:d,buffer:v}=Oe(r,x);return a.push(v),f.push(Ie(f.length,d.length,e.count)),n.needsUpdate=!0,{array:d,buffer:v}}),p=K((g,x)=>{let{array:d,buffer:v}=Ue(r,x);return n.resources[0].push({buffer:v}),n.needsUpdate=!0,{array:d,buffer:v}}),m=K((g,{width:x,height:d})=>{let{texture:v,sampler:A}=Ge(r,x,d);return n.resources[1].push(A,v.createView()),n.needsUpdate=!0,{texture:v,width:x,height:d}}),y=()=>{let g=[];s.length=0,n.resources.forEach(x=>{if(!x.length)return;let{layout:d,bindGroup:v}=Ce(r,x);g.push(d),s.push(v)}),n.pipeline=we(r,o,f,g,e.vs,e.fs)};return{webgpu:n,render:()=>{if(n.loadingImg)return;n.needsUpdate&&y(),n.needsUpdate=!1;let g=r.createCommandEncoder(),x=g.beginRenderPass(Le(t));x.setPipeline(n.pipeline),s.forEach((d,v)=>x.setBindGroup(v,d)),a.forEach((d,v)=>x.setVertexBuffer(v,d)),x.draw(e.count,1,0,0),x.end(),r.queue.submit([g.finish()])},clean:()=>{},_attribute:(g="",x)=>{let{array:d,buffer:v}=X(g,x);r.queue.writeBuffer(v,0,d)},_uniform:(g,x)=>{l.num(x)&&(x=[x]);let{array:d,buffer:v}=p(g,x);d.set(x),r.queue.writeBuffer(v,0,d)},_texture:(g,x)=>{n.loadingImg++;let d=Object.assign(new Image,{src:x,crossOrigin:"anonymous"});d.decode().then(()=>{let{texture:v,width:A,height:Fe}=m(g,d);r.queue.copyExternalImageToTexture({source:d},{texture:v},{width:A,height:Fe}),n.loadingImg--})}}};var un=e=>l.obj(e)?"isGL"in e:!1,ot=()=>typeof window>"u",nt=()=>ot()?!1:"gpu"in navigator,Z=performance.now(),st=e=>{let t=et({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=rt(),t.frame=tt(),t.attribute=H((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n))),t.texture=H((r,o)=>t.queue(()=>t._texture?.(r,o))),t.uniform=H((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:Z}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,nt()||(t.isWebGL=!0),t.isWebGL?t(await Se(t)):t(await Ae(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:f,left:X}=t.el.getBoundingClientRect();t.mouse[0]=(o-f-s/2)/(s/2),t.mouse[1]=-(n-X-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{Z=performance.now()/1e3,t.uniform("iTime",Z)}),t(e)},cn=st;export{Be as ADDITIONAL_FUNCTIONS,B as BOOL_RETURN_FUNCTIONS,re as BUILTIN_TYPES,oe as COMPARISON_OPERATORS,q as COMPONENT_COUNT_TO_TYPE,L as CONSTANTS,Q as CONVERSIONS,M as FIRST_ARG_TYPE_FUNCTIONS,ee as FUNCTIONS,Gt as Fn,W as HIGHEST_TYPE_FUNCTIONS,Lt as If,ne as LOGICAL_OPERATORS,Ot as Loop,F as OPERATORS,J as OPERATOR_KEYS,z as PRESERVE_TYPE_FUNCTIONS,$ as SCALAR_RETURN_FUNCTIONS,mt as SWIZZLES,Ut as Switch,te as TYPE_MAPPING,V as VEC3_RETURN_FUNCTIONS,D as VEC4_RETURN_FUNCTIONS,Cr as abs,Lr as acos,Ze as alignTo256,Or as all,Ur as any,Gr as asin,ge as assign,Ir as atan,Ar as atan2,Qt as attribute,Fr as bitcast,pr as bool,hr as bvec2,_r as bvec3,Pr as bvec4,$r as cbrt,Br as ceil,zr as clamp,c as code,Rr as color,Vr as cos,Pe as createAttrib,Ce as createBindGroup,Ie as createBufferLayout,Le as createDescriptor,Ne as createDevice,st as createGL,he as createIbo,we as createPipeline,Te as createProgram,Re as createTexture,Ge as createTextureSampler,Ue as createUniformBuffer,Ee as createVbo,Oe as createVertexBuffer,Mr as cross,Nr as cubeTexture,Wr as dFdx,Dr as dFdy,cn as default,je as defaultFragmentGLSL,ke as defaultVertexGLSL,qr as degrees,Yr as difference,ft as dig,kr as distance,jr as dot,$e as each,Kr as equals,Hr as exp,Zr as exp2,ut as ext,i as f,Qr as faceforward,ct as fig,ur as float,Jr as floor,it as flush,O as formatConversions,eo as fract,U as fragment,to as fwidth,R as getId,fe as getOperator,_e as getStride,ce as hex2rgb,kt as iMouse,Yt as iResolution,jt as iTime,_ as infer,Et as inferParameterTypes,cr as int,ro as inverseSqrt,l as is,ae as isConversion,ie as isFunction,un as isGL,ue as isNodeProxy,se as isOperator,ot as isServer,Y as isSwizzle,nt as isWebGPUSupported,gr as ivec2,vr as ivec3,Xr as ivec4,k as joins,oo as length,no as lengthSq,so as log,io as log2,xr as mat2,dr as mat3,br as mat4,ao as max,uo as min,co as mix,b as n,fo as negate,u as node,or as normalLocal,sr as normalView,nr as normalWorld,po as normalize,Ye as o,lo as oneMinus,Kt as position,er as positionLocal,rr as positionView,tr as positionWorld,mo as pow,xo as pow2,bo as pow3,go as pow4,vo as radians,Xo as reciprocal,yo as reflect,To as refract,at as replace,Eo as round,ve as s,ho as saturate,ir as screenCoordinate,ar as screenUV,Vt as select,pt as sig,_o as sign,Po as sin,Ro as smoothstep,So as sqrt,No as step,wo as tan,Sr as texture,wr as textureSize,be as toConst,de as toVar,Co as transformDirection,Lo as trunc,I as u,fr as uint,Ht as uv,yr as uvec2,Tr as uvec3,Er as uvec4,zt as v,It as varying,lr as vec2,Xe as vec3,mr as vec4,G as vertex,Zt as vertexColor,Jt as vertexStage,Se as webgl,Ae as webgpu};
61
66
  //# sourceMappingURL=index.js.map