glre 0.27.0 → 0.29.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.
@@ -2,9 +2,11 @@ import * as refr from 'refr';
2
2
  import { Queue, Frame } from 'refr';
3
3
  export { Frame, Fun, Queue } from 'refr';
4
4
  import { EventState } from 'reev';
5
+ import { NodeProps as NodeProps$1 } from './../../../../node_modules/glre/src/node/types';
5
6
 
6
7
  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"];
8
+ declare const CONSTANTS: readonly ["bool", "uint", "int", "float", "bvec2", "bvec3", "bvec4", "ivec2", "ivec3", "ivec4", "uvec2", "uvec3", "uvec4", "vec2", "vec3", "vec4", "color", "mat2", "mat3", "mat4"];
9
+ 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
10
  declare const OPERATORS: {
9
11
  readonly add: "+";
10
12
  readonly sub: "-";
@@ -26,7 +28,15 @@ declare const OPERATORS: {
26
28
  readonly shiftRight: ">>";
27
29
  };
28
30
  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"];
31
+ declare const SCALAR_RETURN_FUNCTIONS: readonly ["dot", "distance", "length", "lengthSq", "determinant", "luminance"];
32
+ declare const BOOL_RETURN_FUNCTIONS: readonly ["all", "any"];
33
+ 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"];
34
+ declare const VEC3_RETURN_FUNCTIONS: readonly ["cross"];
35
+ declare const FIRST_ARG_TYPE_FUNCTIONS: readonly ["reflect", "refract"];
36
+ declare const HIGHEST_TYPE_FUNCTIONS: readonly ["min", "max", "mix", "clamp", "step", "smoothstep"];
37
+ declare const VEC4_RETURN_FUNCTIONS: readonly ["texture", "textureLod", "textureSize", "cubeTexture"];
38
+ declare const ADDITIONAL_FUNCTIONS: readonly ["atan2", "degrees", "faceforward", "bitcast", "cbrt", "difference", "equals", "pow", "pow2", "pow3", "pow4", "radians", "transformDirection"];
39
+ 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
40
  declare const TYPE_MAPPING: {
31
41
  readonly float: "f32";
32
42
  readonly int: "i32";
@@ -48,24 +58,78 @@ declare const TYPE_MAPPING: {
48
58
  readonly bvec3: "vec3<bool>";
49
59
  readonly bvec4: "vec4<bool>";
50
60
  };
61
+ declare const COMPONENT_COUNT_TO_TYPE: {
62
+ readonly 1: "float";
63
+ readonly 2: "vec2";
64
+ readonly 3: "vec3";
65
+ readonly 4: "vec4";
66
+ readonly 9: "mat3";
67
+ readonly 16: "mat4";
68
+ };
69
+ declare const BUILTIN_TYPES: {
70
+ readonly position: "vec4";
71
+ readonly vertex_index: "uint";
72
+ readonly instance_index: "uint";
73
+ readonly front_facing: "bool";
74
+ readonly frag_depth: "float";
75
+ readonly sample_index: "uint";
76
+ readonly sample_mask: "uint";
77
+ readonly point_coord: "vec2";
78
+ readonly positionLocal: "vec3";
79
+ readonly positionWorld: "vec3";
80
+ readonly positionView: "vec3";
81
+ readonly normalLocal: "vec3";
82
+ readonly normalWorld: "vec3";
83
+ readonly normalView: "vec3";
84
+ readonly screenCoordinate: "vec2";
85
+ readonly screenUV: "vec2";
86
+ readonly gl_FragCoord: "vec4";
87
+ readonly gl_VertexID: "uint";
88
+ readonly gl_InstanceID: "uint";
89
+ readonly gl_FrontFacing: "bool";
90
+ readonly gl_FragDepth: "float";
91
+ readonly gl_SampleID: "uint";
92
+ readonly gl_SampleMask: "uint";
93
+ readonly gl_PointCoord: "vec2";
94
+ readonly normal: "vec3";
95
+ readonly uv: "vec2";
96
+ readonly color: "vec4";
97
+ };
98
+ declare const COMPARISON_OPERATORS: readonly ["equal", "notEqual", "lessThan", "lessThanEqual", "greaterThan", "greaterThanEqual"];
99
+ declare const LOGICAL_OPERATORS: readonly ["and", "or"];
100
+ declare const WGSL_TO_GLSL_BUILTIN: {
101
+ readonly position: "gl_FragCoord";
102
+ readonly vertex_index: "gl_VertexID";
103
+ readonly instance_index: "gl_InstanceID";
104
+ readonly front_facing: "gl_FrontFacing";
105
+ readonly frag_depth: "gl_FragDepth";
106
+ readonly sample_index: "gl_SampleID";
107
+ readonly sample_mask: "gl_SampleMask";
108
+ readonly point_coord: "gl_PointCoord";
109
+ };
51
110
 
52
- type NodeType = (typeof NODE_TYPES)[number];
111
+ type Constants = (typeof CONSTANTS)[number] | 'void';
112
+ type Conversions = (typeof CONVERSIONS)[number];
53
113
  type Functions = (typeof FUNCTIONS)[number];
54
114
  type Operators = (typeof OPERATOR_KEYS)[number];
55
115
  interface NodeProps {
56
116
  id?: string;
117
+ args?: X[];
118
+ type?: string;
57
119
  children?: X[];
58
- defaultValue?: number | number[];
120
+ value?: number | number[] | boolean;
59
121
  }
60
122
  interface NodeConfig {
61
123
  isWebGL?: boolean;
62
- uniforms?: Set<string>;
63
- onUniform?: (name: string, value: any) => void;
124
+ binding?: number;
125
+ infers?: WeakMap<NodeProxy, Constants>;
126
+ headers?: Map<string, string>;
127
+ onMount?: (name: string, value: any) => void;
64
128
  }
65
129
  type _Swizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
66
130
  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> {
131
+ type NodeTypes = 'uniform' | 'variable' | 'swizzle' | 'operator' | 'conversion' | 'function' | 'declare' | 'assign' | 'define' | 'if' | 'loop' | 'scope' | 'switch' | 'ternary' | 'attribute' | 'varying' | 'builtin' | 'constant';
132
+ interface NodeProxy extends Record<Swizzles | Conversions, NodeProxy> {
69
133
  add(n: X): NodeProxy;
70
134
  sub(n: X): NodeProxy;
71
135
  mul(n: X): NodeProxy;
@@ -82,48 +146,125 @@ interface NodeProxy extends Record<Swizzles, NodeProxy> {
82
146
  not(): NodeProxy;
83
147
  assign(n: X): NodeProxy;
84
148
  toVar(name?: string): NodeProxy;
149
+ toConst(name?: string): NodeProxy;
150
+ abs(): NodeProxy;
151
+ sin(): NodeProxy;
152
+ cos(): NodeProxy;
153
+ tan(): NodeProxy;
154
+ asin(): NodeProxy;
155
+ acos(): NodeProxy;
156
+ atan(): NodeProxy;
157
+ atan2(x: X): NodeProxy;
158
+ pow(y: X): NodeProxy;
159
+ pow2(): NodeProxy;
160
+ pow3(): NodeProxy;
161
+ pow4(): NodeProxy;
162
+ sqrt(): NodeProxy;
163
+ inverseSqrt(): NodeProxy;
164
+ exp(): NodeProxy;
165
+ exp2(): NodeProxy;
166
+ log(): NodeProxy;
167
+ log2(): NodeProxy;
168
+ floor(): NodeProxy;
169
+ ceil(): NodeProxy;
170
+ round(): NodeProxy;
171
+ fract(): NodeProxy;
172
+ trunc(): NodeProxy;
173
+ min(y: X): NodeProxy;
174
+ max(y: X): NodeProxy;
175
+ clamp(min: X, max: X): NodeProxy;
176
+ saturate(): NodeProxy;
177
+ mix(y: X, a: X): NodeProxy;
178
+ step(edge: X): NodeProxy;
179
+ smoothstep(edge0: X, edge1: X): NodeProxy;
180
+ length(): NodeProxy;
181
+ distance(y: X): NodeProxy;
182
+ dot(y: X): NodeProxy;
183
+ cross(y: X): NodeProxy;
184
+ normalize(): NodeProxy;
185
+ reflect(N: X): NodeProxy;
186
+ refract(N: X, eta: X): NodeProxy;
187
+ sign(): NodeProxy;
188
+ oneMinus(): NodeProxy;
189
+ reciprocal(): NodeProxy;
190
+ negate(): NodeProxy;
191
+ dFdx(): NodeProxy;
192
+ dFdy(): NodeProxy;
193
+ fwidth(): NodeProxy;
85
194
  toString(c?: NodeConfig): string;
86
195
  type: NodeTypes;
87
196
  props: NodeProps;
88
197
  isProxy: true;
89
198
  }
90
- type X = NodeProxy | number | string | null | undefined;
199
+ type X = NodeProxy | number | string | boolean | undefined;
91
200
 
92
201
  declare const code: (target: X, c?: NodeConfig | null) => string;
93
202
 
203
+ declare const inferImpl: (target: NodeProxy, c: NodeConfig) => Constants;
204
+ declare const infer: (target: X, c: NodeConfig | null) => Constants;
205
+
94
206
  declare const node: (type: NodeTypes, props?: NodeProps | null, ...args: X[]) => NodeProxy;
95
- declare const v: (...args: X[]) => NodeProxy;
96
- declare const u: (key: string, defaultValue?: number | number[]) => NodeProxy;
97
- declare const s: (key: Swizzles, arg: X) => NodeProxy;
98
- declare const n: (key: string, ...args: X[]) => NodeProxy;
99
- declare const o: (key: Operators, ...args: X[]) => NodeProxy;
100
- declare const f: (key: Functions, ...args: X[]) => NodeProxy;
207
+ declare const swizzle: (key: Swizzles, arg: X) => NodeProxy;
208
+ declare const operator: (key: Operators, ...args: X[]) => NodeProxy;
209
+ declare const function_: (key: Functions, ...args: X[]) => NodeProxy;
210
+ declare const conversion: (key: string, ...args: X[]) => NodeProxy;
101
211
 
102
- declare const If: (x: X, callback: () => void) => {
103
- ElseIf: (y: X, elseCallback: () => void) => void;
104
- Else: (elseCallback: () => void) => void;
212
+ declare const toVar: (x: X, id?: string) => NodeProxy;
213
+ declare const assign: (x: X, y: X) => X;
214
+ declare const If: (condition: X, fun: () => void) => {
215
+ ElseIf: (x: X, _fun: () => void) => /*elided*/ any;
216
+ Else: (_fun: () => void) => void;
105
217
  };
106
- declare const Loop: (x: X, callback?: (params: {
107
- i: NodeProxy;
218
+ declare const Loop: (x: X, fun: (params: {
219
+ i?: NodeProxy;
108
220
  }) => void) => NodeProxy;
109
- declare const Fn: (callback: (args: X[]) => NodeProxy) => (...args: X[]) => NodeProxy;
110
- declare const toVar: (x: X) => (id: string) => NodeProxy;
111
- declare const assign: (x: X) => (y: X) => X;
221
+ declare const Switch: (value: X) => {
222
+ Case: (...values: X[]) => (fun: () => void) => /*elided*/ any;
223
+ Default: (fun: () => void) => void;
224
+ };
225
+ declare const Fn: (fun: (paramVars: NodeProxy[]) => NodeProxy) => (...args: X[]) => NodeProxy;
112
226
 
113
227
  declare const isSwizzle: (key: unknown) => key is Swizzles;
114
228
  declare const isOperator: (key: unknown) => key is Operators;
115
- declare const isNodeType: (key: unknown) => key is NodeType;
116
229
  declare const isFunction: (key: unknown) => key is Functions;
230
+ declare const isConversion: (key: unknown) => key is Conversions;
231
+ declare const isNodeProxy: (x: unknown) => x is NodeProxy;
232
+ declare const hex2rgb: (hex: number) => number[];
117
233
  declare const getId: () => string;
118
234
  declare const joins: (children: X[], c: NodeConfig) => string;
119
- declare const inferType: (target: X, c: NodeConfig) => string;
120
- declare const fragment: (x: X, c: NodeConfig) => string;
235
+ declare const formatConversions: (x: X, c?: NodeConfig) => string;
236
+ declare const getOperator: (op: X) => "/" | "+" | "-" | "*" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "&" | "|" | "^" | "<<" | ">>";
237
+ declare const generateDefine: (props: NodeProps$1, c: NodeConfig) => string;
238
+ declare const fragment: (x: X, c?: NodeConfig) => string;
121
239
  declare const vertex: (x: X, c: NodeConfig) => string;
122
240
 
241
+ declare const select: (x: X, y: X, z: X) => NodeProxy;
242
+ declare const uniform: (value: number | number[], id?: string) => NodeProxy;
243
+ declare const varying: (value: number | number[], id?: string) => NodeProxy;
244
+ declare const attribute: (value: number | number[], id?: string) => NodeProxy;
245
+ declare const variable: (id: string) => NodeProxy;
246
+ declare const builtin: (id: string) => NodeProxy;
123
247
  declare const iResolution: NodeProxy;
124
248
  declare const iMouse: NodeProxy;
125
249
  declare const iTime: NodeProxy;
250
+ declare const position: NodeProxy;
251
+ declare const vertexIndex: NodeProxy;
252
+ declare const instanceIndex: NodeProxy;
253
+ declare const frontFacing: NodeProxy;
254
+ declare const fragDepth: NodeProxy;
255
+ declare const sampleIndex: NodeProxy;
256
+ declare const sampleMask: NodeProxy;
257
+ declare const pointCoord: NodeProxy;
258
+ declare const positionLocal: NodeProxy;
259
+ declare const positionWorld: NodeProxy;
260
+ declare const positionView: NodeProxy;
261
+ declare const normalLocal: NodeProxy;
262
+ declare const normalWorld: NodeProxy;
263
+ declare const normalView: NodeProxy;
264
+ declare const screenCoordinate: NodeProxy;
265
+ declare const screenUV: NodeProxy;
126
266
  declare const fragCoord: NodeProxy;
267
+ declare const vertexId: NodeProxy;
127
268
  declare const float: (x: X) => NodeProxy;
128
269
  declare const int: (x: X) => NodeProxy;
129
270
  declare const uint: (x: X) => NodeProxy;
@@ -143,12 +284,17 @@ declare const uvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
143
284
  declare const bvec2: (x?: X, y?: X) => NodeProxy;
144
285
  declare const bvec3: (x?: X, y?: X, z?: X) => NodeProxy;
145
286
  declare const bvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
287
+ declare const color: (r?: X, g?: X, b?: X) => NodeProxy;
288
+ declare const texture: (x: X, y: X, z?: X) => NodeProxy;
289
+ declare const cubeTexture: (x: X, y: X, z?: X) => NodeProxy;
290
+ declare const textureSize: (x: X, y?: X) => NodeProxy;
146
291
  declare const abs: (x: X) => NodeProxy;
147
292
  declare const acos: (x: X) => NodeProxy;
148
293
  declare const all: (x: X) => NodeProxy;
149
294
  declare const any: (x: X) => NodeProxy;
150
295
  declare const asin: (x: X) => NodeProxy;
151
- declare const atan: (y: X, x: X) => NodeProxy;
296
+ declare const atan: (y: X, x?: X) => NodeProxy;
297
+ declare const atan2: (y: X, x: X) => NodeProxy;
152
298
  declare const bitcast: (x: X, y: X) => NodeProxy;
153
299
  declare const cbrt: (x: X) => NodeProxy;
154
300
  declare const ceil: (x: X) => NodeProxy;
@@ -238,12 +384,12 @@ type GL = EventState<{
238
384
  mouse: [number, number];
239
385
  count: number;
240
386
  el: HTMLCanvasElement;
241
- vs: string | X;
242
- fs: string | X;
243
- vert: string | X;
244
- frag: string | X;
245
- vertex: string | X;
246
- fragment: string | X;
387
+ vs: string | NodeProxy;
388
+ fs: string | NodeProxy;
389
+ vert: string | NodeProxy;
390
+ frag: string | NodeProxy;
391
+ vertex: string | NodeProxy;
392
+ fragment: string | NodeProxy;
247
393
  /**
248
394
  * core state
249
395
  */
@@ -318,7 +464,7 @@ declare const createDevice: (c: GPUContext) => Promise<{
318
464
  device: any;
319
465
  format: any;
320
466
  }>;
321
- declare const createPipeline: (device: GPUDevice, format: string, bufferLayouts: any[], bindGroupLayouts: any[], vs?: string | X, fs?: string | X) => GPUPipeline;
467
+ declare const createPipeline: (device: GPUDevice, format: string, bufferLayouts: any[], bindGroupLayouts: any[], vs?: string | NodeProxy, fs?: string | NodeProxy) => GPUPipeline;
322
468
  declare const createBindGroup: (device: GPUDevice, resources: any[]) => {
323
469
  layout: any;
324
470
  bindGroup: any;
@@ -360,7 +506,7 @@ declare const createBufferLayout: (shaderLocation: number, dataLength: number, c
360
506
 
361
507
  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
508
  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;
509
+ declare const createProgram: (c: WebGLRenderingContext, vs?: string | NodeProxy, fs?: string | NodeProxy, onError?: () => void) => void | WebGLProgram;
364
510
  declare const createVbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
365
511
  declare const createIbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
366
512
  declare const getStride: (count: number, value: number[], iboValue?: number[]) => number;
@@ -399,12 +545,12 @@ declare const createGL: (props?: Partial<GL>) => EventState<{
399
545
  mouse: [number, number];
400
546
  count: number;
401
547
  el: HTMLCanvasElement;
402
- vs: string | X;
403
- fs: string | X;
404
- vert: string | X;
405
- frag: string | X;
406
- vertex: string | X;
407
- fragment: string | X;
548
+ vs: string | NodeProxy;
549
+ fs: string | NodeProxy;
550
+ vert: string | NodeProxy;
551
+ frag: string | NodeProxy;
552
+ vertex: string | NodeProxy;
553
+ fragment: string | NodeProxy;
408
554
  webgpu: WebGPUState;
409
555
  webgl: WebGLState;
410
556
  queue: refr.Queue;
@@ -434,4 +580,4 @@ declare const createGL: (props?: Partial<GL>) => EventState<{
434
580
  }): GL;
435
581
  }, any[] | unknown[]>;
436
582
 
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 };
583
+ 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, WGSL_TO_GLSL_BUILTIN, type WebGLState, type WebGPUState, type X, abs, acos, alignTo256, all, any, asin, assign, atan, atan2, attribute, bitcast, bool, builtin, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, conversion, 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, faceforward, fig, float, floor, flush, formatConversions, fract, fragCoord, fragDepth, fragment, frontFacing, function_, fwidth, generateDefine, getId, getOperator, getStride, hex2rgb, iMouse, iResolution, iTime, infer, inferImpl, instanceIndex, 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, 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, saturate, screenCoordinate, screenUV, select, sig, sign, sin, smoothstep, sqrt, step, swizzle, tan, texture, textureSize, toVar, transformDirection, trunc, uint, uniform, uvec2, uvec3, uvec4, variable, varying, vec2, vec3, vec4, vertex, vertexId, vertexIndex, webgl, webgpu };
package/dist/index.js CHANGED
@@ -1,41 +1,50 @@
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 Z,event as nt}from"reev";import{createFrame as st,createQueue as it}from"refr";import{nested as K}from"reev";var g={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)},Be=(e,t)=>e.forEach(t),pt=(e,...t)=>{Be(e,r=>r(...t))},ft=(e="",t="_",r="/")=>e.split(t).join(r),lt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",mt=(e=0)=>`${e}`.split(".")[1]?.length??0,dt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),xt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var bt=["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"],J=["toFloat","toInt","toUint","toBool","toVec2","toVec3","toVec4","toIvec2","toIvec3","toIvec4","toUvec2","toUvec3","toUvec4","toBvec2","toBvec3","toBvec4","toMat2","toMat3","toMat4","toColor"],$={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},ee=Object.keys($),B=["dot","distance","length","lengthSq","determinant","luminance"],M=["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"],D=["cross"],z=["reflect","refract"],W=["min","max","mix","clamp","step","smoothstep"],q=["texture","textureLod","textureSize","cubeTexture"],Me=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],te=[...B,...M,...V,...D,...z,...W,...q,...Me],re={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",ivec2:"vec2i",ivec3:"vec3i",ivec4:"vec4i",uvec2:"vec2u",uvec3:"vec3u",uvec4:"vec4u",bvec2:"vec2<bool>",bvec3:"vec3<bool>",bvec4:"vec4<bool>"},k={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},oe={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"},ne=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],se=["and","or"],ie={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"};var Y=e=>g.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ae=e=>ee.includes(e),ue=e=>te.includes(e),ce=e=>J.includes(e),S=e=>!e||typeof e!="object"?!1:e.isProxy,Ve=0,pe=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,n=(e&255)/255;return[t,r,n]},I=()=>`i${Ve++}`,U=(e,t)=>e.filter(r=>!g.und(r)&&!g.nul(r)).map(r=>p(r,t)).join(", "),C=(e,t)=>g.str(e)?t?.isWebGL?e:re[e]:"",fe=e=>$[e]||e,le=e=>Array.from(e.headers).map(([,t])=>t).join(`
2
+ `),me=(e,t)=>{let{id:r,children:n=[]}=e,[o,s,...u]=n,a=s?_(s,t):"void",m=u.map((h,T)=>[`p${T}`,_(h,t)]),y=[p(o,t)];if(s&&y.push(`return ${p(s,t)};`),t?.isWebGL){let h=m.map(([T,E])=>`${E} ${T}`);return`${a} ${r}(${h}) {
3
+ ${y.join(`
4
+ `)}
5
+ }`}let f=C(a,t),d=m.map(([h,T])=>`${h}: ${C(T,t)}`);return`fn ${r}(${d}) -> ${f} {
6
+ ${y.join(`
7
+ `)}
8
+ }`},de=(e,t,r=!0)=>r?`
5
9
  #version 300 es
6
10
  precision mediump float;
7
- uniform vec2 iResolution;
8
- uniform vec2 iMouse;
9
- uniform float iTime;
10
11
  out vec4 fragColor;
12
+ ${t}
11
13
  void main() {
12
- ${e}
14
+ fragColor = ${e};
13
15
  }`.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
16
  ${t}
18
17
  @fragment
19
18
  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++) {
23
- ${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)}) {
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=`
19
+ return ${e};
20
+ }`.trim(),G=(e,t={})=>{let r=p(e,t),n=le(t),o=de(r,n,t.isWebGL);return console.log(`// \u2193\u2193\u2193 generated \u2193\u2193\u2193
21
+
22
+ ${o}
23
+
24
+ `),o},F=(e,t)=>{let r=p(e,t),n=le(t);return de(r,n,t.isWebGL)};var ge=e=>g.bol(e)?"bool":g.num(e)?"float":g.arr(e)&&k[e.length]||"float",xe=(e,t,r)=>{if(ne.includes(r)||se.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=L.indexOf(e),o=L.indexOf(t);return n>=o?e:t},De=(e,t)=>e.reduce((r,n)=>{let o=_(n,t),s=L.indexOf(r);return L.indexOf(o)>s?o:r},"float"),ze=e=>k[e],We=e=>oe[e],qe=(e,t,r)=>{let n=t.length>0?_(t[0],r):"float";return z.includes(e)?n:B.includes(e)?"float":M.includes(e)?"bool":V.includes(e)?n:D.includes(e)?"vec3":q.includes(e)?"vec4":W.includes(e)?De(t,r):n},ke=(e,t)=>{let{type:r,props:n}=e,{id:o,children:s=[],value:u}=n,[a,m,y]=s;return r==="uniform"||r==="variable"||r==="constant"||r==="attribute"||r==="varying"?ge(u):r==="conversion"?a:r==="operator"?xe(_(m,t),_(y,t),a):r==="function"?qe(a,s.slice(1),t):r==="swizzle"?ze(a.length):r==="ternary"?xe(_(m,t),_(y,t),"add"):r==="define"?m?_(m,t):"void":r==="builtin"?We(o):"float"},_=(e,t)=>{if(t||(t={}),!S(e))return ge(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=ke(e,t);return t.infers.set(e,r),r};var p=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),g.str(e))return e;if(g.num(e))return e.toFixed(1);if(g.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[]}=n,[u,a,m]=s,y="";if(r==="uniform"){if(t.headers.has(o))return o;t.binding||(t.binding=0);let f=_(e,t);y=t.isWebGL?`uniform ${f} ${o};`:`@group(0) @binding(${t.binding++}) var<uniform> ${o}: ${C(f,t)};`}if(r==="attribute"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(r==="constant"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(r==="varying"){if(t.headers.has(o))return o;y=`${_(e,t)} ${o}`}if(y)return t.headers.set(o,y),t.onMount?.(o,n.value),o;if(r==="variable")return o;if(r==="swizzle")return`${p(a,t)}.${p(u,t)}`;if(r==="operator")return u==="not"||u==="bitNot"?`!${p(a,t)}`:`(${p(a,t)} ${fe(u)} ${p(m,t)})`;if(r==="function")return u==="negate"?`(-${U(s.slice(1),t)})`:`${u}(${U(s.slice(1),t)})`;if(r==="conversion")return`${C(u,t)}(${U(s.slice(1),t)})`;if(r==="scope")return s.map(f=>p(f,t)).join(`
25
+ `);if(r==="assign")return`${p(u,t)} = ${p(a,t)};`;if(r==="define"){let f=s.slice(2),d=`${o}(${f.map(h=>p(h,t))})`;return t.headers.has(o)||t.headers.set(o,me(n,t)),d}if(r==="loop")return`for (int i = 0; i < ${u}; i++) {
26
+ ${p(a,t)}
27
+ }`;if(r==="if"){let f=`if (${p(u,t)}) {
28
+ ${p(a,t)}
29
+ }`;for(let d=2;d<s.length;d+=2){let h=d>=s.length-1;f+=h?` else {
30
+ ${p(s[d],t)}
31
+ }`:` else if (${p(s[d],t)}) {
32
+ ${p(s[d+1],t)}
33
+ }`}return f}if(r==="switch"){let f=`switch (${p(u,t)}) {
34
+ `;for(let d=1;d<s.length;d+=2)d>=s.length-1&&s.length%2===0?f+=`default:
35
+ ${p(s[d],t)}
36
+ break;
37
+ `:d+1<s.length&&(f+=`case ${p(s[d],t)}:
38
+ ${p(s[d+1],t)}
39
+ break;
40
+ `);return f+="}",f}if(r==="ternary")return`(${p(u,t)} ? ${p(a,t)} : ${p(m,t)})`;if(r==="declare"){let f=_(a,t),d=u?.props?.id;if(t.isWebGL)return`${f} ${d} = ${p(a,t)};`;let h=C(f);return`var ${d}: ${h} = ${p(a,t)};`}if(r==="builtin"){if(t?.isWebGL){let f=ie[o];if(f)return f;if(o==="uv")return"gl_FragCoord.xy"}return o}return p(u,t)};var R=null,w=(e,t=()=>{})=>{let r=R;R=e,t(),R=r},O=e=>{R&&(R.props.children||(R.props.children=[]),R.props.children.push(e))},be=(e,t)=>{t||(t=I());let r=c("variable",{id:t}),n=c("declare",null,r,e);return O(n),r},ve=(e,t)=>{let r=c("assign",null,e,t);return O(r),e},Gt=(e,t)=>{let r=c("scope");w(r,t);let n=c("if",null,e,r);O(n);let o=()=>({ElseIf:(s,u)=>{let a=c("scope");return w(a,u),n.props.children.push(s,a),o()},Else:s=>{let u=c("scope");w(u,s),n.props.children.push(u)}});return o()},Ft=(e,t)=>{let r=c("scope");w(r,()=>t({i:c("variable",{id:"i"})}));let n=c("loop",null,e,r);return O(n),n},At=e=>{let t=c("switch",null,e);O(t);let r=()=>({Case:(...n)=>o=>{let s=c("scope");w(s,o);for(let u of n)t.props.children.push(u,s);return r()},Default:n=>{let o=c("scope");w(o,n),t.props.children.push(o)}});return r()},$t=e=>{let t=I();return(...r)=>{let n=c("scope"),o,s=[];for(let u=0;u<r.length;u++){let a=`p${u}`,m=c("variable",{id:a});s.push(m)}return w(n,()=>o=e(s)),c("define",{id:t},n,o,...r)}};var Ye=(e,t)=>{if(t==="string")return p(e)},c=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let n=(u,a)=>{if(a==="type")return e;if(a==="props")return t;if(a==="toVar")return be.bind(null,s);if(a==="assign")return ve.bind(null,s);if(a==="isProxy")return!0;if(a==="toString")return p.bind(null,s);if(a===Symbol.toPrimitive)return Ye.bind(null,s);if(Y(a))return ye(a,s);if(ae(a))return(...m)=>je(a,s,...m);if(ue(a))return(...m)=>i(a,s,...m);if(ce(a))return b(a,s)},o=(u,a,m)=>Y(a)?(ye(a,s).assign(m),!0):!1,s=new Proxy({},{get:n,set:o});return s};var ye=(e,t)=>c("swizzle",null,e,t),je=(e,...t)=>c("operator",null,e,...t),i=(e,...t)=>c("function",null,e,...t),b=(e,...t)=>c("conversion",null,e,...t);var Yt=(e,t,r)=>c("ternary",null,e,t,r),j=(e,t)=>c("uniform",{id:t,value:e}),jt=(e,t)=>c("varying",{id:t,value:e}),Kt=(e,t)=>c("varying",{id:t,value:e}),Ht=e=>c("variable",{id:e}),Zt=e=>c("builtin",{id:e}),Qt=j([1280,800],"iResolution"),Jt=j([0,0],"iMouse"),er=j(0,"iTime"),Ke=c("builtin",{id:"position"}),He=c("builtin",{id:"vertex_index"}),tr=c("builtin",{id:"instance_index"}),rr=c("builtin",{id:"front_facing"}),or=c("builtin",{id:"frag_depth"}),nr=c("builtin",{id:"sample_index"}),sr=c("builtin",{id:"sample_mask"}),ir=c("builtin",{id:"point_coord"}),ar=c("builtin",{id:"position"}),ur=c("builtin",{id:"positionWorld"}),cr=c("builtin",{id:"positionView"}),pr=c("builtin",{id:"normalLocal"}),fr=c("builtin",{id:"normalWorld"}),lr=c("builtin",{id:"normalView"}),mr=c("builtin",{id:"screenCoordinate"}),dr=c("builtin",{id:"screenUV"}),xr=Ke,gr=He,br=e=>b("float",e),vr=e=>b("int",e),yr=e=>b("uint",e),Xr=e=>b("bool",e),Tr=(e,t)=>b("vec2",e,t),Xe=(e,t,r)=>b("vec3",e,t,r),_r=(e,t,r,n)=>b("vec4",e,t,r,n),hr=(...e)=>b("mat2",...e),Er=(...e)=>b("mat3",...e),Pr=(...e)=>b("mat4",...e),Nr=(e,t)=>b("ivec2",e,t),Sr=(e,t,r)=>b("ivec3",e,t,r),Rr=(e,t,r,n)=>b("ivec4",e,t,r,n),wr=(e,t)=>b("uvec2",e,t),Cr=(e,t,r)=>b("uvec3",e,t,r),Lr=(e,t,r,n)=>b("uvec4",e,t,r,n),Or=(e,t)=>b("bvec2",e,t),Ir=(e,t,r)=>b("bvec3",e,t,r),Ur=(e,t,r,n)=>b("bvec4",e,t,r,n),Gr=(e,t,r)=>g.num(e)&&g.und(t)&&g.und(r)?Xe(...pe(e)):Xe(e,t,r),Fr=(e,t,r)=>i("texture",e,t,r),Ar=(e,t,r)=>i("cubeTexture",e,t,r),$r=(e,t)=>i("textureSize",e,t),Br=e=>i("abs",e),Mr=e=>i("acos",e),Vr=e=>i("all",e),Dr=e=>i("any",e),zr=e=>i("asin",e),Wr=(e,t)=>t!==void 0?i("atan",e,t):i("atan",e),qr=(e,t)=>i("atan",e,t),kr=(e,t)=>i("bitcast",e,t),Yr=e=>i("cbrt",e),jr=e=>i("ceil",e),Kr=(e,t,r)=>i("clamp",e,t,r),Hr=e=>i("cos",e),Zr=(e,t)=>i("cross",e,t),Qr=e=>i("dFdx",e),Jr=e=>i("dFdy",e),eo=e=>i("degrees",e),to=(e,t)=>i("difference",e,t),ro=(e,t)=>i("distance",e,t),oo=(e,t)=>i("dot",e,t),no=(e,t)=>i("equals",e,t),so=e=>i("exp",e),io=e=>i("exp2",e),ao=(e,t,r)=>i("faceforward",e,t,r),uo=e=>i("floor",e),co=e=>i("fract",e),po=e=>i("fwidth",e),fo=e=>i("inverseSqrt",e),lo=e=>i("length",e),mo=e=>i("lengthSq",e),xo=e=>i("log",e),go=e=>i("log2",e),bo=(e,t)=>i("max",e,t),vo=(e,t)=>i("min",e,t),yo=(e,t,r)=>i("mix",e,t,r),Xo=e=>i("negate",e),To=e=>i("normalize",e),_o=e=>i("oneMinus",e),ho=(e,t)=>i("pow",e,t),Eo=e=>i("pow2",e),Po=e=>i("pow3",e),No=e=>i("pow4",e),So=e=>i("radians",e),Ro=e=>i("reciprocal",e),wo=(e,t)=>i("reflect",e,t),Co=(e,t,r)=>i("refract",e,t,r),Lo=e=>i("round",e),Oo=e=>i("saturate",e),Io=e=>i("sign",e),Uo=e=>i("sin",e),Go=(e,t,r)=>i("smoothstep",e,t,r),Fo=e=>i("sqrt",e),Ao=(e,t)=>i("step",e,t),$o=e=>i("tan",e),Bo=(e,t)=>i("transformDirection",e,t),Mo=e=>i("trunc",e);var Ze=`
32
41
  #version 300 es
33
42
  void main() {
34
43
  float x = float(gl_VertexID % 2) * 4.0 - 1.0;
35
44
  float y = float(gl_VertexID / 2) * 4.0 - 1.0;
36
45
  gl_Position = vec4(x, y, 0.0, 1.0);
37
46
  }
38
- `,ye=`
47
+ `,Qe=`
39
48
  #version 300 es
40
49
  precision mediump float;
41
50
  uniform vec2 iResolution;
@@ -43,19 +52,19 @@ out vec4 fragColor;
43
52
  void main() {
44
53
  fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
45
54
  }
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=`
55
+ `,Te=(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}`)},_e=(e,t=Ze,r=Qe,n=()=>{})=>{S(r)&&(r=G(r,{isWebGL:!0})),S(t)&&(t=F(r,{isWebGL:!0}));let o=e.createProgram(),s=Te(e,t,e.VERTEX_SHADER),u=Te(e,r,e.FRAGMENT_SHADER);if(!s||!u)return n();if(e.attachShader(o,s),e.attachShader(o,u),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let a=e.getProgramInfoLog(o);e.deleteProgram(o),n(),console.warn(`Could not link pg: ${a}`)},he=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array(t),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),r},Ee=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(t),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r},Pe=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Ne=(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)},Se=(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 Re=async e=>{let t=e.el.getContext("webgl2"),r=_e(t,e.vs,e.fs,()=>void(e.isLoop=!1));t.useProgram(r);let n=0,o=K(T=>t.getUniformLocation(r,T)),s=K(T=>t.getAttribLocation(r,T)),u=K(()=>n++);return{webgl:{context:t,program:r},render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(T="",E,P)=>{let N=s(T,!0),X=he(t,E),l=Ee(t,P),x=Pe(e.count,E,P);Ne(t,x,N,X,l)},_uniform:(T,E)=>{let P=o(T);if(g.num(E))return t.uniform1f(P,E);let N=E.length;if(N<=4)return t[`uniform${N}fv`](P,E);N=Math.sqrt(N)<<0,t[`uniformMatrix${N}fv`](P,!1,E)},_texture:(T,E)=>{let P=new Image;Object.assign(P,{src:E,crossOrigin:"anonymous"}),P.decode().then(()=>{let N=o(T),X=u(T);Se(t,P,N,X)})}}};import{nested as H}from"reev";var Je=`
47
56
  @vertex
48
57
  fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
49
58
  let x = f32(vertex_index % 2u) * 4.0 - 1.0;
50
59
  let y = f32(vertex_index / 2u) * 4.0 - 1.0;
51
60
  return vec4f(x, y, 0.0, 1.0);
52
61
  }
53
- `,br=`
62
+ `,et=`
54
63
  @group(0) @binding(0) var<uniform> iResolution: vec2f;
55
64
 
56
65
  @fragment
57
66
  fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
58
67
  return vec4f(position.xy / iResolution, 0.0, 1.0);
59
68
  }
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});
69
+ `,we=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}},Ce=(e,t,r,n,o=Je,s=et)=>{S(o)&&(o=F(o,{isWebGL:!1})),S(s)&&(s=G(s,{isWebGL:!1}));let u=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:o.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:u,primitive:{topology:"triangle-list"}})},Le=(e,t)=>{let r=[],n=[];t.forEach((u,a)=>{if(!u)return;let m="buffer"in u,y=u instanceof GPUTextureView,f=u instanceof GPUSampler;if(m)r.push({binding:a,visibility:3,buffer:{type:"uniform"}});else if(y)r.push({binding:a,visibility:2,texture:{}});else if(f)r.push({binding:a,visibility:2,sampler:{}});else return;n.push({binding:a,resource:u})});let o=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:o,entries:n});return{layout:o,bindGroup:s}},Oe=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),tt=e=>Math.ceil(e/256)*256,Ie=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},Ue=(e,t)=>{let r=new Float32Array(t),n=tt(r.byteLength),o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},Ge=(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}},rt=(e,t)=>e/t,ot=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Fe=(e,t,r=6)=>{let n=rt(t,r);return{arrayStride:n*4,attributes:[{shaderLocation:e,offset:0,format:ot(n)}]}};var Ae=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await we(t),o={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],u=[],a=[],m=H((X,l)=>{let{array:x,buffer:v}=Ie(r,l);return u.push(v),a.push(Fe(a.length,x.length,e.count)),o.needsUpdate=!0,{array:x,buffer:v}}),y=H((X,l)=>{let{array:x,buffer:v}=Ue(r,l);return o.resources[0].push({buffer:v}),o.needsUpdate=!0,{array:x,buffer:v}}),f=H((X,{width:l,height:x})=>{let{texture:v,sampler:A}=Ge(r,l,x);return o.resources[1].push(A,v.createView()),o.needsUpdate=!0,{texture:v,width:l,height:x}}),d=()=>{let X=[];s.length=0,o.resources.forEach(l=>{if(!l.length)return;let{layout:x,bindGroup:v}=Le(r,l);X.push(x),s.push(v)}),o.pipeline=Ce(r,n,a,X,e.vs,e.fs)};return{webgpu:o,render:()=>{if(o.loadingImg)return;o.needsUpdate&&d(),o.needsUpdate=!1;let X=r.createCommandEncoder(),l=X.beginRenderPass(Oe(t));l.setPipeline(o.pipeline),s.forEach((x,v)=>l.setBindGroup(v,x)),u.forEach((x,v)=>l.setVertexBuffer(v,x)),l.draw(e.count,1,0,0),l.end(),r.queue.submit([X.finish()])},clean:()=>{},_attribute:(X="",l)=>{let{array:x,buffer:v}=m(X,l);r.queue.writeBuffer(v,0,x)},_uniform:(X,l)=>{g.num(l)&&(l=[l]);let{array:x,buffer:v}=y(X,l);x.set(l),r.queue.writeBuffer(v,0,x)},_texture:(X,l)=>{o.loadingImg++;let x=Object.assign(new Image,{src:l,crossOrigin:"anonymous"});x.decode().then(()=>{let{texture:v,width:A,height:$e}=f(X,x);r.queue.copyExternalImageToTexture({source:x},{texture:v},{width:A,height:$e}),o.loadingImg--})}}};var mn=e=>g.obj(e)?"isGL"in e:!1,at=()=>typeof window>"u",ut=()=>at()?!1:"gpu"in navigator,Q=performance.now(),ct=e=>{let t=nt({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=it(),t.frame=st(),t.attribute=Z((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=Z((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=Z((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:Q}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,ut()||(t.isWebGL=!0),t.isWebGL?t(await Re(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,n=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=n,t.uniform("iResolution",t.size)}),t("mousemove",(r,n=r.clientX,o=r.clientY)=>{let[s,u]=t.size,{top:a,left:m}=t.el.getBoundingClientRect();t.mouse[0]=(n-a-s/2)/(s/2),t.mouse[1]=-(o-m-u/2)/(u/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{Q=performance.now()/1e3,t.uniform("iTime",Q)}),t(e)},dn=ct;export{Me as ADDITIONAL_FUNCTIONS,M as BOOL_RETURN_FUNCTIONS,oe as BUILTIN_TYPES,ne as COMPARISON_OPERATORS,k as COMPONENT_COUNT_TO_TYPE,L as CONSTANTS,J as CONVERSIONS,z as FIRST_ARG_TYPE_FUNCTIONS,te as FUNCTIONS,$t as Fn,W as HIGHEST_TYPE_FUNCTIONS,Gt as If,se as LOGICAL_OPERATORS,Ft as Loop,$ as OPERATORS,ee as OPERATOR_KEYS,V as PRESERVE_TYPE_FUNCTIONS,B as SCALAR_RETURN_FUNCTIONS,bt as SWIZZLES,At as Switch,re as TYPE_MAPPING,D as VEC3_RETURN_FUNCTIONS,q as VEC4_RETURN_FUNCTIONS,ie as WGSL_TO_GLSL_BUILTIN,Br as abs,Mr as acos,tt as alignTo256,Vr as all,Dr as any,zr as asin,ve as assign,Wr as atan,qr as atan2,Kt as attribute,kr as bitcast,Xr as bool,Zt as builtin,Or as bvec2,Ir as bvec3,Ur as bvec4,Yr as cbrt,jr as ceil,Kr as clamp,p as code,Gr as color,b as conversion,Hr as cos,Ne as createAttrib,Le as createBindGroup,Fe as createBufferLayout,Oe as createDescriptor,we as createDevice,ct as createGL,Ee as createIbo,Ce as createPipeline,_e as createProgram,Se as createTexture,Ge as createTextureSampler,Ue as createUniformBuffer,he as createVbo,Ie as createVertexBuffer,Zr as cross,Ar as cubeTexture,Qr as dFdx,Jr as dFdy,dn as default,Qe as defaultFragmentGLSL,Ze as defaultVertexGLSL,eo as degrees,to as difference,dt as dig,ro as distance,oo as dot,Be as each,no as equals,so as exp,io as exp2,lt as ext,ao as faceforward,mt as fig,br as float,uo as floor,pt as flush,C as formatConversions,co as fract,xr as fragCoord,or as fragDepth,G as fragment,rr as frontFacing,i as function_,po as fwidth,me as generateDefine,I as getId,fe as getOperator,Pe as getStride,pe as hex2rgb,Jt as iMouse,Qt as iResolution,er as iTime,_ as infer,ke as inferImpl,tr as instanceIndex,vr as int,fo as inverseSqrt,g as is,ce as isConversion,ue as isFunction,mn as isGL,S as isNodeProxy,ae as isOperator,at as isServer,Y as isSwizzle,ut as isWebGPUSupported,Nr as ivec2,Sr as ivec3,Rr as ivec4,U as joins,lo as length,mo as lengthSq,xo as log,go as log2,hr as mat2,Er as mat3,Pr as mat4,bo as max,vo as min,yo as mix,Xo as negate,c as node,pr as normalLocal,lr as normalView,fr as normalWorld,To as normalize,_o as oneMinus,je as operator,ir as pointCoord,Ke as position,ar as positionLocal,cr as positionView,ur as positionWorld,ho as pow,Eo as pow2,Po as pow3,No as pow4,So as radians,Ro as reciprocal,wo as reflect,Co as refract,ft as replace,Lo as round,nr as sampleIndex,sr as sampleMask,Oo as saturate,mr as screenCoordinate,dr as screenUV,Yt as select,xt as sig,Io as sign,Uo as sin,Go as smoothstep,Fo as sqrt,Ao as step,ye as swizzle,$o as tan,Fr as texture,$r as textureSize,be as toVar,Bo as transformDirection,Mo as trunc,yr as uint,j as uniform,wr as uvec2,Cr as uvec3,Lr as uvec4,Ht as variable,jt as varying,Tr as vec2,Xe as vec3,_r as vec4,F as vertex,gr as vertexId,He as vertexIndex,Re as webgl,Ae as webgpu};
61
70
  //# sourceMappingURL=index.js.map