@rosalana/sandbox 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- var N = Object.defineProperty;
2
- var G = (u, e, t) => e in u ? N(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
- var o = (u, e, t) => G(u, typeof e != "symbol" ? e + "" : e, t);
4
- class b {
1
+ var B = Object.defineProperty;
2
+ var N = (u, e, t) => e in u ? B(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
+ var a = (u, e, t) => N(u, typeof e != "symbol" ? e + "" : e, t);
4
+ class y {
5
5
  constructor(e, t, n, i) {
6
6
  this.target = e, this.type = t, this.listener = n, this.options = i, this.target.addEventListener(
7
7
  this.type,
@@ -23,16 +23,16 @@ class b {
23
23
  class h extends Error {
24
24
  constructor(t, n) {
25
25
  super(t);
26
- o(this, "name", "SandboxError");
26
+ a(this, "name", "SandboxError");
27
27
  this.code = n;
28
28
  }
29
29
  }
30
- class W extends h {
30
+ class G extends h {
31
31
  constructor() {
32
32
  super("WebGL is not supported in this browser.", "CONTEXT_ERROR");
33
33
  }
34
34
  }
35
- class ve extends h {
35
+ class pe extends h {
36
36
  constructor() {
37
37
  super(
38
38
  "Failed to create WebGL context. The GPU may be unavailable.",
@@ -40,7 +40,7 @@ class ve extends h {
40
40
  );
41
41
  }
42
42
  }
43
- class z extends h {
43
+ class W extends h {
44
44
  constructor(e, t) {
45
45
  super(
46
46
  `Vertex and fragment shader WebGL versions do not match (${e} vs ${t})`,
@@ -57,7 +57,7 @@ class _ extends h {
57
57
  ${i}`,
58
58
  "SHADER_ERROR"
59
59
  );
60
- o(this, "lines");
60
+ a(this, "lines");
61
61
  this.shaderType = t, this.source = n, this.infoLog = i, this.lines = r;
62
62
  }
63
63
  static parseErrorLines(t) {
@@ -69,14 +69,14 @@ ${i}`,
69
69
  for (const r of n) {
70
70
  let s;
71
71
  for (; (s = r.exec(t)) !== null; ) {
72
- const a = parseInt(s[1], 10);
73
- a > 0 && i.add(a);
72
+ const o = parseInt(s[1], 10);
73
+ o > 0 && i.add(o);
74
74
  }
75
75
  }
76
76
  return [...i].sort((r, s) => r - s);
77
77
  }
78
78
  }
79
- class U extends h {
79
+ class T extends h {
80
80
  constructor(e, t, n, i) {
81
81
  super(
82
82
  `The shader ${e} "${t}" has type "${i}" but expected "${n}"`,
@@ -84,12 +84,12 @@ class U extends h {
84
84
  ), this.requirement = e, this.name = t, this.expectedType = n, this.actualType = i;
85
85
  }
86
86
  }
87
- class H extends h {
87
+ class z extends h {
88
88
  constructor() {
89
89
  super("Shader source does not contain any function.", "SHADER_ERROR");
90
90
  }
91
91
  }
92
- class q extends h {
92
+ class H extends h {
93
93
  constructor(e, t) {
94
94
  super(
95
95
  `Syntax error in shader import statement at line ${e}: ${t}`,
@@ -97,7 +97,7 @@ class q extends h {
97
97
  ), this.line = e, this.details = t;
98
98
  }
99
99
  }
100
- class j extends h {
100
+ class q extends h {
101
101
  constructor(e, t) {
102
102
  super(
103
103
  `Duplicate import name "${e}" found at line ${t}. Each import must have a unique name.`,
@@ -105,7 +105,7 @@ class j extends h {
105
105
  ), this.name = e, this.line = t;
106
106
  }
107
107
  }
108
- class X extends h {
108
+ class j extends h {
109
109
  constructor(e) {
110
110
  super(
111
111
  `Can not find module '${e}'. Check if it is defined before usage or if the name is correct.`,
@@ -113,7 +113,7 @@ class X extends h {
113
113
  ), this.moduleName = e;
114
114
  }
115
115
  }
116
- class Y extends h {
116
+ class X extends h {
117
117
  constructor(e, t) {
118
118
  super(
119
119
  `Method '${t}' not found in shader module '${e}'. Check if the method is defined in the module source code or if the name is correct.`,
@@ -121,7 +121,7 @@ class Y extends h {
121
121
  ), this.moduleName = e, this.methodName = t;
122
122
  }
123
123
  }
124
- class K extends h {
124
+ class Y extends h {
125
125
  constructor(e) {
126
126
  super(
127
127
  `Importing 'main' function from module '${e}' is forbidden.`,
@@ -129,7 +129,7 @@ class K extends h {
129
129
  ), this.moduleName = e;
130
130
  }
131
131
  }
132
- class Q extends h {
132
+ class K extends h {
133
133
  constructor(e) {
134
134
  super(
135
135
  `Name 'default' is reserved and cannot be used as a function name in module '${e}'.`,
@@ -137,7 +137,7 @@ class Q extends h {
137
137
  ), this.moduleName = e;
138
138
  }
139
139
  }
140
- class J extends h {
140
+ class Q extends h {
141
141
  constructor(e) {
142
142
  super(
143
143
  `Module name '${e}' is not allowed. Module names cannot be 'sandbox' or start with 'sandbox/'.`,
@@ -145,7 +145,7 @@ class J extends h {
145
145
  ), this.moduleName = e;
146
146
  }
147
147
  }
148
- class Z extends h {
148
+ class J extends h {
149
149
  constructor(e) {
150
150
  super(
151
151
  `Module '${e}' is already defined. Overwriting existing modules is not allowed.`,
@@ -153,7 +153,7 @@ class Z extends h {
153
153
  ), this.moduleName = e;
154
154
  }
155
155
  }
156
- class ee extends h {
156
+ class Z extends h {
157
157
  constructor(e, t, n) {
158
158
  super(
159
159
  `Uniform '${n}' mentioned for function '${t}' of module '${e}' was not found among the module's declared uniforms. Check if the uniform is declared in the module source code or if the name is correct.`,
@@ -161,7 +161,7 @@ class ee extends h {
161
161
  ), this.moduleName = e, this.functionName = t, this.uniformName = n;
162
162
  }
163
163
  }
164
- class te extends h {
164
+ class ee extends h {
165
165
  constructor(e, t) {
166
166
  super(
167
167
  `Uniform '${t}' mentioned for function '${e}' was not imported from any module. Check if the function is imported from the correct module and if the uniform is declared in that module's source code with the correct name.`,
@@ -169,7 +169,7 @@ class te extends h {
169
169
  ), this.functionName = e, this.uniformName = t;
170
170
  }
171
171
  }
172
- class ne extends h {
172
+ class te extends h {
173
173
  constructor(e, t) {
174
174
  super(
175
175
  `Mention '${e}' called in function '${t}' could not be replaced with the corresponding uniform reference. There might be an issue with the compilation process because the referenced uniform was not found among the shader requirements. Try use a different name for uniforms you want to mention in functions or check if the uniform is properly declared and mentioned in the module source code.`,
@@ -177,60 +177,60 @@ class ne extends h {
177
177
  ), this.mentionName = e, this.calledInFunction = t;
178
178
  }
179
179
  }
180
- class S extends h {
180
+ class R extends h {
181
181
  constructor(e) {
182
182
  super(`Shader program linking failed
183
183
 
184
184
  ${e}`, "PROGRAM_ERROR"), this.infoLog = e;
185
185
  }
186
186
  }
187
- class ge extends h {
187
+ class ve extends h {
188
188
  constructor(t) {
189
189
  super(
190
190
  `Failed to create WebGL texture for "${t}".`,
191
191
  "TEXTURE_ERROR"
192
192
  );
193
- o(this, "name", "SandboxTextureCreationError");
193
+ a(this, "name", "SandboxTextureCreationError");
194
194
  this.textureName = t;
195
195
  }
196
196
  }
197
- class xe extends h {
197
+ class ge extends h {
198
198
  constructor(t, n) {
199
199
  super(
200
200
  `Cannot bind texture "${t}": all ${n} texture units are in use.`,
201
201
  "TEXTURE_ERROR"
202
202
  );
203
- o(this, "name", "SandboxTextureUnitLimitError");
203
+ a(this, "name", "SandboxTextureUnitLimitError");
204
204
  this.textureName = t, this.maxUnits = n;
205
205
  }
206
206
  }
207
- class ie extends h {
207
+ class ne extends h {
208
208
  constructor(e) {
209
209
  super(`Error in onLoad callback: ${e}`, "UNKNOWN_ERROR");
210
210
  }
211
211
  }
212
- class re extends h {
212
+ class ie extends h {
213
213
  constructor(e, t) {
214
214
  super(`Error in onBefore/onAfter hook callback with ID ${e}: ${t}`, "UNKNOWN_ERROR");
215
215
  }
216
216
  }
217
- class se {
217
+ class re {
218
218
  constructor() {
219
219
  /** Total elapsed time in seconds */
220
- o(this, "time", 0);
220
+ a(this, "time", 0);
221
221
  /** Delta time since last frame in seconds */
222
- o(this, "delta", 0);
222
+ a(this, "delta", 0);
223
223
  /** Frame counter */
224
- o(this, "frame", 0);
224
+ a(this, "frame", 0);
225
225
  /** Is clock running */
226
- o(this, "running", !1);
226
+ a(this, "running", !1);
227
227
  /** Smoothed frames per second */
228
- o(this, "fps", 0);
229
- o(this, "startTime", 0);
230
- o(this, "lastTime", 0);
231
- o(this, "rafId", null);
232
- o(this, "callback", null);
233
- o(this, "maxFps", 0);
228
+ a(this, "fps", 0);
229
+ a(this, "startTime", 0);
230
+ a(this, "lastTime", 0);
231
+ a(this, "rafId", null);
232
+ a(this, "callback", null);
233
+ a(this, "maxFps", 0);
234
234
  this.loop = this.loop.bind(this);
235
235
  }
236
236
  /**
@@ -309,18 +309,18 @@ class se {
309
309
  this.fps = this.fps * 0.95 + t * 0.05, this.time = (e - this.startTime) / 1e3, this.frame++, this.callback && this.callback(this.getState()), this.rafId = requestAnimationFrame(this.loop);
310
310
  }
311
311
  }
312
- class k {
312
+ class A {
313
313
  constructor(e) {
314
- o(this, "gl");
315
- o(this, "vao", null);
316
- o(this, "vbo", null);
317
- o(this, "ibo", null);
318
- o(this, "vertexCount", 0);
319
- o(this, "indexCount", 0);
320
- o(this, "useIndices", !1);
314
+ a(this, "gl");
315
+ a(this, "vao", null);
316
+ a(this, "vbo", null);
317
+ a(this, "ibo", null);
318
+ a(this, "vertexCount", 0);
319
+ a(this, "indexCount", 0);
320
+ a(this, "useIndices", !1);
321
321
  // WebGL1 VAO extension (if available)
322
- o(this, "vaoExt", null);
323
- o(this, "isWebGL2");
322
+ a(this, "vaoExt", null);
323
+ a(this, "isWebGL2");
324
324
  this.gl = e, this.isWebGL2 = e instanceof WebGL2RenderingContext, this.isWebGL2 || (this.vaoExt = e.getExtension("OES_vertex_array_object"));
325
325
  }
326
326
  /**
@@ -328,7 +328,7 @@ class k {
328
328
  * This is the most common use case for shader effects.
329
329
  */
330
330
  static fullscreenQuad(e) {
331
- const t = new k(e), n = new Float32Array([
331
+ const t = new A(e), n = new Float32Array([
332
332
  // position texcoord
333
333
  -1,
334
334
  -1,
@@ -446,12 +446,12 @@ class k {
446
446
  this.vao && (this.isWebGL2 ? this.gl.deleteVertexArray(this.vao) : this.vaoExt && this.vaoExt.deleteVertexArrayOES(this.vao), this.vao = null);
447
447
  }
448
448
  }
449
- class oe {
449
+ class se {
450
450
  constructor(e) {
451
- o(this, "gl");
452
- o(this, "program", null);
453
- o(this, "vertexShader", null);
454
- o(this, "fragmentShader", null);
451
+ a(this, "gl");
452
+ a(this, "program", null);
453
+ a(this, "vertexShader", null);
454
+ a(this, "fragmentShader", null);
455
455
  this.gl = e;
456
456
  }
457
457
  /**
@@ -506,8 +506,8 @@ class oe {
506
506
  "Failed to create shader object"
507
507
  );
508
508
  if (n.shaderSource(r, t), n.compileShader(r), !n.getShaderParameter(r, n.COMPILE_STATUS)) {
509
- const a = n.getShaderInfoLog(r) || "Unknown error";
510
- throw n.deleteShader(r), new _(e, t, a);
509
+ const o = n.getShaderInfoLog(r) || "Unknown error";
510
+ throw n.deleteShader(r), new _(e, t, o);
511
511
  }
512
512
  return r;
513
513
  }
@@ -518,26 +518,26 @@ class oe {
518
518
  linkProgram() {
519
519
  const e = this.gl;
520
520
  if (!this.vertexShader || !this.fragmentShader)
521
- throw new S("Shaders not compiled");
521
+ throw new R("Shaders not compiled");
522
522
  const t = e.createProgram();
523
523
  if (!t)
524
- throw new S("Failed to create program object");
524
+ throw new R("Failed to create program object");
525
525
  if (e.attachShader(t, this.vertexShader), e.attachShader(t, this.fragmentShader), e.linkProgram(t), !e.getProgramParameter(t, e.LINK_STATUS)) {
526
526
  const i = e.getProgramInfoLog(t) || "Unknown error";
527
- throw e.deleteProgram(t), new S(i);
527
+ throw e.deleteProgram(t), new R(i);
528
528
  }
529
529
  this.program = t;
530
530
  }
531
531
  }
532
532
  class M {
533
533
  constructor(e, t) {
534
- o(this, "name");
535
- o(this, "method");
536
- o(this, "isArray");
537
- o(this, "isMatrix");
538
- o(this, "location", null);
539
- o(this, "locationResolved", !1);
540
- o(this, "value");
534
+ a(this, "name");
535
+ a(this, "method");
536
+ a(this, "isArray");
537
+ a(this, "isMatrix");
538
+ a(this, "location", null);
539
+ a(this, "locationResolved", !1);
540
+ a(this, "value");
541
541
  this.name = e, this.value = t;
542
542
  const n = M.inferMethodInfo(t);
543
543
  this.method = n.method, this.isArray = n.isArray, this.isMatrix = n.isMatrix;
@@ -648,9 +648,9 @@ class M {
648
648
  }
649
649
  }
650
650
  }
651
- class E {
651
+ class w {
652
652
  constructor(e) {
653
- o(this, "parsed", null);
653
+ a(this, "parsed", null);
654
654
  this.source = e;
655
655
  }
656
656
  /**
@@ -689,13 +689,13 @@ class E {
689
689
  }
690
690
  detectImports() {
691
691
  const e = /^[ \t]*#import\s+(\w+)(?:\s+as\s+(\w+))?\s+from\s+["'](.+)["']/gm, t = /^[ \t]*[^\w\s]?import\b/gm, n = [], i = /* @__PURE__ */ new Set();
692
- let r, s = 1, a = 0;
692
+ let r, s = 1, o = 0;
693
693
  for (; (r = e.exec(this.source)) !== null; ) {
694
- s += (this.source.substring(a, r.index).match(/\n/g) || []).length, a = r.index, i.add(s);
695
- const f = r[1], c = r[2] || r[1], m = r[3];
696
- if (n.some((p) => p.alias === c))
697
- throw new j(c, s);
698
- n.push({ name: f, alias: c, module: m, line: s });
694
+ s += (this.source.substring(o, r.index).match(/\n/g) || []).length, o = r.index, i.add(s);
695
+ const f = r[1], c = r[2] || r[1], d = r[3];
696
+ if (n.some((m) => m.alias === c))
697
+ throw new q(c, s);
698
+ n.push({ name: f, alias: c, module: d, line: s });
699
699
  }
700
700
  let l;
701
701
  for (; (l = t.exec(this.source)) !== null; ) {
@@ -703,7 +703,7 @@ class E {
703
703
  if (i.has(f)) continue;
704
704
  const c = this.source.split(`
705
705
  `)[f - 1].trim();
706
- throw new q(
706
+ throw new H(
707
707
  f,
708
708
  this.diagnoseImport(c)
709
709
  );
@@ -737,8 +737,8 @@ class E {
737
737
  let n, i = 1, r = 0;
738
738
  for (; (n = e.exec(this.source)) !== null; ) {
739
739
  i += (this.source.substring(r, n.index).match(/\n/g) || []).length, r = n.index;
740
- const s = n[1], a = n[2], l = n[3] ? parseInt(n[3], 10) : void 0;
741
- t.push({ name: a, type: s, line: i, arrayNum: l });
740
+ const s = n[1], o = n[2], l = n[3] ? parseInt(n[3], 10) : void 0;
741
+ t.push({ name: o, type: s, line: i, arrayNum: l });
742
742
  }
743
743
  return t;
744
744
  }
@@ -749,15 +749,15 @@ class E {
749
749
  );
750
750
  let r;
751
751
  for (; (r = i.exec(this.source)) !== null; ) {
752
- const s = r[1], a = r[2], l = r[3].trim(), f = r.index, c = (this.source.substring(0, f).match(/\n/g) || []).length + 1, m = this.source.indexOf("{", f), p = this.findClosingBrace(this.source, m);
753
- if (p === -1) continue;
754
- const g = this.source.slice(m, p + 1), P = this.parseParams(l), $ = this.findFunctionCalls(g), D = this.findUniformCalls(g, e), B = this.findMentionCalls(g);
752
+ const s = r[1], o = r[2], l = r[3].trim(), f = r.index, c = (this.source.substring(0, f).match(/\n/g) || []).length + 1, d = this.source.indexOf("{", f), m = this.findClosingBrace(this.source, d);
753
+ if (m === -1) continue;
754
+ const v = this.source.slice(d, m + 1), I = this.parseParams(l), P = this.findFunctionCalls(v), $ = this.findUniformCalls(v, e), D = this.findMentionCalls(v);
755
755
  t.push({
756
- name: a,
756
+ name: o,
757
757
  type: s,
758
- params: P,
759
- body: g,
760
- dependencies: [...$, ...D, ...B],
758
+ params: I,
759
+ body: v,
760
+ dependencies: [...P, ...$, ...D],
761
761
  line: c
762
762
  });
763
763
  }
@@ -769,19 +769,19 @@ class E {
769
769
  for (const i of n) {
770
770
  const r = i.trim();
771
771
  if (!r) continue;
772
- const a = r.replace(/\b(in|out|inout|const|highp|mediump|lowp)\b\s*/g, "").trim().match(/^(\w+)\s+(\w+)(?:\[\d*\])?$/);
773
- a && t.push({
774
- type: a[1],
775
- name: a[2]
772
+ const o = r.replace(/\b(in|out|inout|const|highp|mediump|lowp)\b\s*/g, "").trim().match(/^(\w+)\s+(\w+)(?:\[\d*\])?$/);
773
+ o && t.push({
774
+ type: o[1],
775
+ name: o[2]
776
776
  });
777
777
  }
778
778
  return t;
779
779
  }
780
780
  findClosingBrace(e, t) {
781
- let n = 0, i = !1, r = !1, s = !1, a = !1;
781
+ let n = 0, i = !1, r = !1, s = !1, o = !1;
782
782
  for (let l = t; l < e.length; l++) {
783
- const f = e[l], c = e[l + 1], m = e[l - 1];
784
- if (!r && !a && f === "/" && c === "/") {
783
+ const f = e[l], c = e[l + 1], d = e[l - 1];
784
+ if (!r && !o && f === "/" && c === "/") {
785
785
  s = !0;
786
786
  continue;
787
787
  }
@@ -791,15 +791,15 @@ class E {
791
791
  continue;
792
792
  }
793
793
  if (!r && !s && f === "/" && c === "*") {
794
- a = !0, l++;
794
+ o = !0, l++;
795
795
  continue;
796
796
  }
797
- if (a && f === "*" && c === "/") {
798
- a = !1, l++;
797
+ if (o && f === "*" && c === "/") {
798
+ o = !1, l++;
799
799
  continue;
800
800
  }
801
- if (!(s || a)) {
802
- if (f === '"' && m !== "\\") {
801
+ if (!(s || o)) {
802
+ if (f === '"' && d !== "\\") {
803
803
  r = !r;
804
804
  continue;
805
805
  }
@@ -866,20 +866,20 @@ class E {
866
866
  return t;
867
867
  }
868
868
  }
869
- class F {
869
+ class C {
870
870
  constructor(e) {
871
871
  /** Flag to track if the shader has been compiled */
872
- o(this, "isCompiled", !1);
872
+ a(this, "isCompiled", !1);
873
873
  /** Original and compiled shader parsers */
874
- o(this, "original");
874
+ a(this, "original");
875
875
  /** Compiled parser will be updated with rewritten source after processing imports */
876
- o(this, "compiled");
876
+ a(this, "compiled");
877
877
  /** Collected requirements from imports */
878
- o(this, "requirements", {
878
+ a(this, "requirements", {
879
879
  uniforms: /* @__PURE__ */ new Map(),
880
880
  functions: /* @__PURE__ */ new Map()
881
881
  });
882
- this.original = new E(e), this.compiled = new E(e);
882
+ this.original = new w(e), this.compiled = new w(e);
883
883
  }
884
884
  /**
885
885
  * Detect WebGL version from shader source
@@ -903,50 +903,50 @@ class F {
903
903
  /**
904
904
  * Compile the shader source, resolving all imports
905
905
  */
906
- compile() {
907
- return this.isCompiled ? this.compiled.source : (this.original.parse().imports.length > 0 && this.processImports(), this.compiled.setSource(this.build()), this.isCompiled = !0, this.compiled.source);
906
+ compile(e) {
907
+ return this.isCompiled ? this.compiled.source : (this.original.parse().imports.length > 0 && this.processImports(e), this.compiled.setSource(this.build()), this.isCompiled = !0, this.compiled.source);
908
908
  }
909
909
  /**
910
910
  * Process all #import directives
911
911
  */
912
- processImports() {
913
- const e = this.original.parse(), t = e.functions.flatMap((n) => n.dependencies.filter((i) => i.type === "mention").map((i) => ({
914
- name: i.name.split(".")[0],
915
- uniform: i.name.split(".")[1]
912
+ processImports(e) {
913
+ const t = this.original.parse(), n = t.functions.flatMap((i) => i.dependencies.filter((r) => r.type === "mention").map((r) => ({
914
+ name: r.name.split(".")[0],
915
+ uniform: r.name.split(".")[1]
916
916
  })));
917
- for (const n of e.imports) {
918
- const i = w.resolve(n.module), r = i.extract(n.name);
919
- let s = t.filter(
920
- (l) => l.name === r.function.name
917
+ for (const i of t.imports) {
918
+ const r = b.resolve(i.module), s = r.extract(i.name);
919
+ let o = n.filter(
920
+ (f) => f.name === s.function.name
921
921
  );
922
- if (s.length > 0) {
923
- const l = i.getDefinition().uniforms;
924
- if (s = s.filter((f) => {
925
- const c = l.find(
926
- (m) => m.name === `u_${f.uniform}` || m.name === f.uniform
922
+ if (o.length > 0) {
923
+ const f = r.getDefinition().uniforms;
924
+ if (o = o.filter((c) => {
925
+ const d = f.find(
926
+ (m) => m.name === `u_${c.uniform}` || m.name === c.uniform
927
927
  );
928
- if (c) {
929
- r.dependencies.uniforms.some(
930
- (p) => p.name === c.name
931
- ) || r.dependencies.uniforms.push(c);
932
- const m = t.indexOf(f);
933
- return m > -1 && t.splice(m, 1), !1;
928
+ if (d) {
929
+ s.dependencies.uniforms.some(
930
+ (v) => v.name === d.name
931
+ ) || s.dependencies.uniforms.push(d);
932
+ const m = n.indexOf(c);
933
+ return m > -1 && n.splice(m, 1), !1;
934
934
  }
935
935
  return !0;
936
- }), s.length > 0)
937
- throw new ee(
938
- n.module,
939
- r.function.name,
940
- s[0].uniform
936
+ }), o.length > 0)
937
+ throw new Z(
938
+ i.module,
939
+ s.function.name,
940
+ o[0].uniform
941
941
  );
942
942
  }
943
- const a = i.copy();
944
- this.processExtraction(r, n.alias, a.options), y.merge(n.module, a);
943
+ const l = r.copy();
944
+ this.processExtraction(s, i.alias, l.options), e == null || e.merge(i.module, l);
945
945
  }
946
- if (t.length > 0)
947
- throw new te(
948
- t[0].name,
949
- t[0].uniform
946
+ if (n.length > 0)
947
+ throw new ee(
948
+ n[0].name,
949
+ n[0].uniform
950
950
  );
951
951
  }
952
952
  /**
@@ -962,22 +962,22 @@ class F {
962
962
  });
963
963
  this.requirements.functions.set(c.name, c);
964
964
  }
965
- const a = this.rewriteFunction(i, t, {
965
+ const o = this.rewriteFunction(i, t, {
966
966
  uniforms: e.dependencies.uniforms,
967
967
  functions: e.dependencies.functions,
968
968
  rename: !0,
969
969
  unique: s
970
970
  });
971
- this.requirements.functions.set(a.name, a);
971
+ this.requirements.functions.set(o.name, o);
972
972
  for (const l of e.dependencies.uniforms) {
973
- if (R.has(l.name)) continue;
973
+ if (E.has(l.name)) continue;
974
974
  const f = {
975
975
  ...l,
976
976
  name: `${s}_${l.name}${l.arrayNum ? `[${l.arrayNum}]` : ""}`
977
977
  };
978
978
  if (n[i.name]) {
979
979
  const c = Object.entries(n[i.name]).find(
980
- ([m, p]) => p.uniform === l.name
980
+ ([d, m]) => m.uniform === l.name
981
981
  );
982
982
  c && (c[1].uniform = `${s}_${l.name}`);
983
983
  }
@@ -989,22 +989,22 @@ class F {
989
989
  * Rewrite a function: namespace all uniform and helper function references
990
990
  */
991
991
  rewriteFunction(e, t, n = { rename: !1, uniforms: [], functions: [], unique: "" }) {
992
- const i = new Set(n.uniforms.map((c) => c.name)), r = new Set(n.functions.map((c) => c.name)), s = [], a = n.unique ? n.unique : t;
992
+ const i = new Set(n.uniforms.map((c) => c.name)), r = new Set(n.functions.map((c) => c.name)), s = [], o = n.unique ? n.unique : t;
993
993
  for (const c of e.dependencies)
994
994
  if (c.index !== void 0)
995
995
  if (c.type === "uniform" && i.has(c.name)) {
996
- if (R.has(c.name)) continue;
996
+ if (E.has(c.name)) continue;
997
997
  s.push({
998
998
  index: c.index,
999
999
  oldText: c.name,
1000
- newText: `${a}_${c.name}`
1000
+ newText: `${o}_${c.name}`
1001
1001
  });
1002
1002
  } else c.type === "function" && r.has(c.name) && s.push({
1003
1003
  index: c.index,
1004
1004
  oldText: c.name,
1005
- newText: `${a}_${c.name}`
1005
+ newText: `${o}_${c.name}`
1006
1006
  });
1007
- const l = this.applyRewrites(e.body, s), f = n.rename ? t : `${a}_${e.name}`;
1007
+ const l = this.applyRewrites(e.body, s), f = n.rename ? t : `${o}_${e.name}`;
1008
1008
  return {
1009
1009
  ...e,
1010
1010
  name: f,
@@ -1042,19 +1042,19 @@ class F {
1042
1042
  (r) => r.dependencies.some((s) => s.type === "mention")
1043
1043
  );
1044
1044
  for (const r of i) {
1045
- const s = r.dependencies.filter((a) => a.type === "mention");
1046
- for (const a of s) {
1047
- const l = a.name.split("."), f = new RegExp(`\\b${l[0]}_(\\w+)_${l[1]}\\b`, "g"), c = this.requirements.uniforms.keys().find((p) => {
1048
- var g;
1049
- return ((g = p.match(f)) == null ? void 0 : g[0]) === p;
1045
+ const s = r.dependencies.filter((o) => o.type === "mention");
1046
+ for (const o of s) {
1047
+ const l = o.name.split("."), f = new RegExp(`\\b${l[0]}_(\\w+)_${l[1]}\\b`, "g"), c = this.requirements.uniforms.keys().find((m) => {
1048
+ var v;
1049
+ return ((v = m.match(f)) == null ? void 0 : v[0]) === m;
1050
1050
  });
1051
1051
  if (!c)
1052
- throw new ne(
1053
- a.name,
1052
+ throw new te(
1053
+ o.name,
1054
1054
  r.name
1055
1055
  );
1056
- const m = new RegExp(`@\\b${a.name}\\b`, "g");
1057
- n = n.replace(m, c);
1056
+ const d = new RegExp(`@\\b${o.name}\\b`, "g");
1057
+ n = n.replace(d, c);
1058
1058
  }
1059
1059
  }
1060
1060
  return n;
@@ -1066,13 +1066,13 @@ class F {
1066
1066
  const n = e.split(`
1067
1067
  `), i = new Set(t.imports.map((r) => r.line));
1068
1068
  return n.filter((r, s) => {
1069
- const a = i.has(s + 1);
1070
- if (!a && r.trim() === "" && s > 0) {
1069
+ const o = i.has(s + 1);
1070
+ if (!o && r.trim() === "" && s > 0) {
1071
1071
  const l = s - 1;
1072
1072
  if (i.has(l + 1))
1073
1073
  return !1;
1074
1074
  }
1075
- return !a;
1075
+ return !o;
1076
1076
  }).join(`
1077
1077
  `);
1078
1078
  }
@@ -1080,48 +1080,48 @@ class F {
1080
1080
  * Find insertion point for uniforms (after existing uniforms)
1081
1081
  */
1082
1082
  findInsertionPointForUniforms(e) {
1083
- const t = new E(e).parse(), n = t.uniforms.find(
1084
- (a) => a.line === Math.max(...t.uniforms.map((l) => l.line ?? 0))
1083
+ const t = new w(e).parse(), n = t.uniforms.find(
1084
+ (o) => o.line === Math.max(...t.uniforms.map((l) => l.line ?? 0))
1085
1085
  ), i = e.split(`
1086
1086
  `);
1087
1087
  let r = 0;
1088
1088
  if (n && n.line)
1089
1089
  r = n.line;
1090
1090
  else
1091
- for (let a = 0; a < i.length; a++) {
1092
- const l = i[a].trim();
1091
+ for (let o = 0; o < i.length; o++) {
1092
+ const l = i[o].trim();
1093
1093
  if (l.startsWith("#version")) {
1094
- r = a + 1;
1094
+ r = o + 1;
1095
1095
  continue;
1096
1096
  }
1097
1097
  if (l.startsWith("precision ")) {
1098
- r = a + 1;
1098
+ r = o + 1;
1099
1099
  continue;
1100
1100
  }
1101
1101
  if (l === "" || l.startsWith("//")) {
1102
- r === a && (r = a + 1);
1102
+ r === o && (r = o + 1);
1103
1103
  continue;
1104
1104
  }
1105
1105
  break;
1106
1106
  }
1107
1107
  let s = 0;
1108
- for (let a = 0; a < r; a++)
1109
- s += i[a].length + 1;
1108
+ for (let o = 0; o < r; o++)
1109
+ s += i[o].length + 1;
1110
1110
  return s;
1111
1111
  }
1112
1112
  findInsertionPointForFunctions(e) {
1113
- const t = new E(e).parse(), n = t.functions.find(
1114
- (a) => a.line === Math.min(...t.functions.map((l) => l.line ?? 1 / 0))
1113
+ const t = new w(e).parse(), n = t.functions.find(
1114
+ (o) => o.line === Math.min(...t.functions.map((l) => l.line ?? 1 / 0))
1115
1115
  ), i = e.split(`
1116
1116
  `);
1117
1117
  let r = 0;
1118
1118
  if (n && n.line)
1119
1119
  r = n.line - 2;
1120
1120
  else
1121
- throw new H();
1121
+ throw new z();
1122
1122
  let s = 0;
1123
- for (let a = 0; a < r; a++)
1124
- s += i[a].length + 1;
1123
+ for (let o = 0; o < r; o++)
1124
+ s += i[o].length + 1;
1125
1125
  return s;
1126
1126
  }
1127
1127
  /**
@@ -1157,13 +1157,13 @@ ${t.type} ${t.name}(${n}) ${t.body}`);
1157
1157
  checkUniformsPresence() {
1158
1158
  const e = this.original.parse(), t = [], n = this.requirements.uniforms;
1159
1159
  for (const [i, r] of n) {
1160
- const s = e.uniforms.find((a) => a.name === i);
1160
+ const s = e.uniforms.find((o) => o.name === i);
1161
1161
  if (!s) {
1162
1162
  t.push(r);
1163
1163
  continue;
1164
1164
  }
1165
1165
  if (s.type !== r.type)
1166
- throw new U(
1166
+ throw new T(
1167
1167
  "uniform",
1168
1168
  i,
1169
1169
  r.type,
@@ -1178,13 +1178,13 @@ ${t.type} ${t.name}(${n}) ${t.body}`);
1178
1178
  checkFunctionsPresence() {
1179
1179
  const e = this.original.parse(), t = [], n = this.requirements.functions;
1180
1180
  for (const [i, r] of n) {
1181
- const s = e.functions.find((a) => a.name === i);
1181
+ const s = e.functions.find((o) => o.name === i);
1182
1182
  if (!s) {
1183
1183
  t.push(r);
1184
1184
  continue;
1185
1185
  }
1186
1186
  if (s.type !== r.type)
1187
- throw new U(
1187
+ throw new T(
1188
1188
  "function",
1189
1189
  i,
1190
1190
  r.type,
@@ -1194,11 +1194,11 @@ ${t.type} ${t.name}(${n}) ${t.body}`);
1194
1194
  return t;
1195
1195
  }
1196
1196
  }
1197
- class v extends F {
1197
+ class g extends C {
1198
1198
  constructor(t, n, i = {}) {
1199
1199
  super(n);
1200
- o(this, "name");
1201
- o(this, "options", {});
1200
+ a(this, "name");
1201
+ a(this, "options", {});
1202
1202
  this.name = t, this.options = this.resolveOptions(i);
1203
1203
  }
1204
1204
  resolveOptions(t) {
@@ -1208,8 +1208,8 @@ class v extends F {
1208
1208
  if (!(r.name === "main" || r.name === "default"))
1209
1209
  if (t[r.name]) {
1210
1210
  const s = t[r.name];
1211
- for (const a in i)
1212
- a in s || (s[a] = i[a]);
1211
+ for (const o in i)
1212
+ o in s || (s[o] = i[o]);
1213
1213
  } else
1214
1214
  t[r.name] = { ...i };
1215
1215
  return delete t.default, t || {};
@@ -1220,24 +1220,24 @@ class v extends F {
1220
1220
  static define(t) {
1221
1221
  const { name: n, source: i, options: r } = t;
1222
1222
  if (n === "sandbox" || n.startsWith("sandbox/"))
1223
+ throw new Q(n);
1224
+ const s = new g(n, i, r);
1225
+ if (b.has(n))
1223
1226
  throw new J(n);
1224
- const s = new v(n, i, r);
1225
- if (w.has(n))
1226
- throw new Z(n);
1227
- return w.register(n, s), s;
1227
+ return b.register(n, s), s;
1228
1228
  }
1229
1229
  /**
1230
1230
  * Resolve a module by name from the registry, throwing an error if not found
1231
1231
  */
1232
1232
  static resolve(t) {
1233
- return w.resolve(t);
1233
+ return b.resolve(t);
1234
1234
  }
1235
1235
  /**
1236
1236
  * Create a copy of the module. To unplug references to the original object.
1237
1237
  * Used when copying module to the runtime registry to allow independent runtime changes to options without affecting the original module definition.
1238
1238
  */
1239
1239
  copy(t = "original") {
1240
- return new v(
1240
+ return new g(
1241
1241
  this.name,
1242
1242
  this[t].source,
1243
1243
  JSON.parse(JSON.stringify(this.options))
@@ -1253,8 +1253,8 @@ class v extends F {
1253
1253
  for (const [i, r] of Object.entries(t.options ?? {}))
1254
1254
  if (!this.options[i]) this.options[i] = r;
1255
1255
  else
1256
- for (const [s, a] of Object.entries(r))
1257
- n.includes(a.uniform) || (this.options[i][s] = a);
1256
+ for (const [s, o] of Object.entries(r))
1257
+ n.includes(o.uniform) || (this.options[i][s] = o);
1258
1258
  }
1259
1259
  /**
1260
1260
  * Get the module definition
@@ -1272,12 +1272,12 @@ class v extends F {
1272
1272
  */
1273
1273
  extract(t) {
1274
1274
  if (this.compile(), t === "main")
1275
- throw new K(this.name);
1275
+ throw new Y(this.name);
1276
1276
  if (t === "default")
1277
- throw new Q(this.name);
1278
- const n = this.compiled.parse(), i = n.functions.find((a) => a.name === t);
1277
+ throw new K(this.name);
1278
+ const n = this.compiled.parse(), i = n.functions.find((o) => o.name === t);
1279
1279
  if (!i)
1280
- throw new Y(this.name, t);
1280
+ throw new X(this.name, t);
1281
1281
  const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
1282
1282
  return this.collectDependencies({
1283
1283
  current: i,
@@ -1326,9 +1326,9 @@ class v extends F {
1326
1326
  }
1327
1327
  }
1328
1328
  }
1329
- class V {
1329
+ class F {
1330
1330
  constructor(e = []) {
1331
- o(this, "modules", /* @__PURE__ */ new Map());
1331
+ a(this, "modules", /* @__PURE__ */ new Map());
1332
1332
  e.forEach((t) => {
1333
1333
  this.register(t.name, t);
1334
1334
  });
@@ -1361,8 +1361,8 @@ class V {
1361
1361
  for (const i in n.options) {
1362
1362
  const r = n.options[i];
1363
1363
  for (const s in r) {
1364
- const a = r[s];
1365
- a.default !== void 0 && !n.uniforms.map((l) => l.name).includes(a.uniform) && (e[a.uniform] = a.default);
1364
+ const o = r[s];
1365
+ o.default !== void 0 && !n.uniforms.map((l) => l.name).includes(o.uniform) && (e[o.uniform] = o.default);
1366
1366
  }
1367
1367
  }
1368
1368
  }), e;
@@ -1396,7 +1396,7 @@ class V {
1396
1396
  resolve(e) {
1397
1397
  const t = this.modules.get(e);
1398
1398
  if (!t)
1399
- throw new X(e);
1399
+ throw new j(e);
1400
1400
  return t;
1401
1401
  }
1402
1402
  /**
@@ -1432,7 +1432,7 @@ class V {
1432
1432
  this.modules.clear();
1433
1433
  }
1434
1434
  }
1435
- const ae = `// ─── Constants ──────────────────────────────────────────────
1435
+ const oe = `// ─── Constants ──────────────────────────────────────────────
1436
1436
 
1437
1437
  const float PI = 3.14159265359;
1438
1438
  const float TAU = 6.28318530718;
@@ -1641,7 +1641,7 @@ vec2 voronoi(vec2 p) {
1641
1641
  }
1642
1642
 
1643
1643
  void main() {}
1644
- `, le = `/**
1644
+ `, ae = `/**
1645
1645
  * Hex integer to RGB.
1646
1646
  * Usage: hex(0xFF6600) → orange
1647
1647
  */
@@ -1740,7 +1740,7 @@ vec3 iridescent(vec2 uv, float time, float speed) {
1740
1740
  }
1741
1741
 
1742
1742
  void main() {}
1743
- `, ce = `// ─── Time Shapers ──────────────────────────────────────────
1743
+ `, le = `// ─── Time Shapers ──────────────────────────────────────────
1744
1744
  // Convert raw time (u_time) to normalized 0–1 range.
1745
1745
  // Output feeds directly into easing functions.
1746
1746
 
@@ -1862,7 +1862,7 @@ float teleport(float t) {
1862
1862
  }
1863
1863
 
1864
1864
  void main() {}
1865
- `, ue = `#import hash from 'sandbox'
1865
+ `, ce = `#import hash from 'sandbox'
1866
1866
  #import noise from 'sandbox'
1867
1867
  #import fbm from 'sandbox'
1868
1868
  #import voronoi from 'sandbox'
@@ -2057,7 +2057,7 @@ vec2 cells(vec2 uv, float intensity) {
2057
2057
  }
2058
2058
 
2059
2059
  void main() {}
2060
- `, fe = `#import hash from 'sandbox'
2060
+ `, ue = `#import hash from 'sandbox'
2061
2061
 
2062
2062
  uniform float u_intensity;
2063
2063
 
@@ -2244,11 +2244,11 @@ vec3 arcade(vec3 color, vec2 uv, float intensity) {
2244
2244
  }
2245
2245
 
2246
2246
  void main() {}
2247
- `, w = new V([
2248
- new v("sandbox", ae),
2249
- new v("sandbox/colors", le),
2250
- new v("sandbox/time", ce),
2251
- new v("sandbox/effects", ue, {
2247
+ `, b = new F([
2248
+ new g("sandbox", oe),
2249
+ new g("sandbox/colors", ae),
2250
+ new g("sandbox/time", le),
2251
+ new g("sandbox/effects", ce, {
2252
2252
  default: {
2253
2253
  intensity: { uniform: "u_intensity", default: 1 }
2254
2254
  },
@@ -2298,7 +2298,7 @@ void main() {}
2298
2298
  intensity: { uniform: "u_intensity", default: 1 }
2299
2299
  }
2300
2300
  }),
2301
- new v("sandbox/filters", fe, {
2301
+ new g("sandbox/filters", ue, {
2302
2302
  default: {
2303
2303
  intensity: { uniform: "u_intensity", default: 1 }
2304
2304
  },
@@ -2327,18 +2327,18 @@ void main() {}
2327
2327
  intensity: { uniform: "u_intensity", default: 0.5 }
2328
2328
  }
2329
2329
  })
2330
- ]), y = new V(), R = /* @__PURE__ */ new Map([
2330
+ ]), E = /* @__PURE__ */ new Map([
2331
2331
  ["u_resolution", "vec2"],
2332
2332
  ["u_time", "float"],
2333
2333
  ["u_delta", "float"],
2334
2334
  ["u_mouse", "vec2"],
2335
2335
  ["u_frame", "int"]
2336
2336
  ]);
2337
- class he {
2337
+ class fe {
2338
2338
  constructor(e) {
2339
- o(this, "gl");
2340
- o(this, "program", null);
2341
- o(this, "uniforms", /* @__PURE__ */ new Map());
2339
+ a(this, "gl");
2340
+ a(this, "program", null);
2341
+ a(this, "uniforms", /* @__PURE__ */ new Map());
2342
2342
  this.gl = e;
2343
2343
  }
2344
2344
  /**
@@ -2404,7 +2404,7 @@ class he {
2404
2404
  uploadBuiltIns(e, t, n) {
2405
2405
  if (this.set("u_resolution", t), this.set("u_time", e.time), this.set("u_delta", e.delta), this.set("u_mouse", n), this.set("u_frame", e.frame), !this.program)
2406
2406
  return this;
2407
- for (const i of R.keys()) {
2407
+ for (const i of E.keys()) {
2408
2408
  const r = this.uniforms.get(i);
2409
2409
  r && r.upload(this.gl, this.program);
2410
2410
  }
@@ -2437,16 +2437,16 @@ class he {
2437
2437
  }
2438
2438
  class x {
2439
2439
  constructor(e, t, n, i) {
2440
- o(this, "name");
2441
- o(this, "gl");
2442
- o(this, "texture", null);
2443
- o(this, "location", null);
2444
- o(this, "locationResolved", !1);
2445
- o(this, "source");
2446
- o(this, "options");
2447
- o(this, "dynamicOverride");
2448
- o(this, "needsUpload", !0);
2449
- o(this, "needsReupload", !1);
2440
+ a(this, "name");
2441
+ a(this, "gl");
2442
+ a(this, "texture", null);
2443
+ a(this, "location", null);
2444
+ a(this, "locationResolved", !1);
2445
+ a(this, "source");
2446
+ a(this, "options");
2447
+ a(this, "dynamicOverride");
2448
+ a(this, "needsUpload", !0);
2449
+ a(this, "needsReupload", !1);
2450
2450
  this.gl = e, this.name = t, this.source = n, this.dynamicOverride = i == null ? void 0 : i.dynamic, this.options = x.resolveOptions(n, i), this.needsReupload = this.options.dynamic;
2451
2451
  }
2452
2452
  /**
@@ -2564,11 +2564,11 @@ class x {
2564
2564
  return e instanceof HTMLVideoElement;
2565
2565
  }
2566
2566
  }
2567
- class me {
2567
+ class he {
2568
2568
  constructor(e) {
2569
- o(this, "gl");
2570
- o(this, "program", null);
2571
- o(this, "textures", /* @__PURE__ */ new Map());
2569
+ a(this, "gl");
2570
+ a(this, "program", null);
2571
+ a(this, "textures", /* @__PURE__ */ new Map());
2572
2572
  this.gl = e;
2573
2573
  }
2574
2574
  /**
@@ -2635,9 +2635,9 @@ class me {
2635
2635
  this.textures.clear(), this.program = null;
2636
2636
  }
2637
2637
  }
2638
- class L {
2638
+ class U {
2639
2639
  constructor() {
2640
- o(this, "hooks", /* @__PURE__ */ new Map());
2640
+ a(this, "hooks", /* @__PURE__ */ new Map());
2641
2641
  }
2642
2642
  id() {
2643
2643
  return Math.random().toString(36).substring(2, 10);
@@ -2657,7 +2657,7 @@ class L {
2657
2657
  try {
2658
2658
  n(e) === !1 && this.remove(t);
2659
2659
  } catch (i) {
2660
- throw new re(
2660
+ throw new ie(
2661
2661
  t,
2662
2662
  i instanceof Error ? i.message : String(i)
2663
2663
  );
@@ -2667,30 +2667,31 @@ class L {
2667
2667
  this.hooks.clear();
2668
2668
  }
2669
2669
  }
2670
- class T {
2670
+ class k {
2671
2671
  constructor(e, t) {
2672
- o(this, "canvas");
2673
- o(this, "gl");
2674
- o(this, "options");
2675
- o(this, "onBeforeHooks", new L());
2676
- o(this, "onAfterHooks", new L());
2677
- o(this, "_program");
2678
- o(this, "_geometry");
2679
- o(this, "_uniforms");
2680
- o(this, "_textures");
2681
- o(this, "_clock");
2682
- o(this, "_resolution", [1, 1]);
2683
- o(this, "_mouse", [0, 0]);
2684
- o(this, "_version", 1);
2685
- o(this, "playing", !1);
2686
- this.canvas = e, this.options = t, this.gl = this.initContext(), this.enableExtensions(), this._program = new oe(this.gl), this._geometry = k.fullscreenQuad(this.gl), this._uniforms = new he(this.gl), this._textures = new me(this.gl), this._clock = new se(), this.options.fps && this._clock.setMaxFps(this.options.fps), this.options.onBeforeRender && this.onBeforeHooks.add(this.options.onBeforeRender), this.options.onAfterRender && this.onAfterHooks.add(this.options.onAfterRender), this.onRender = this.onRender.bind(this);
2672
+ a(this, "canvas");
2673
+ a(this, "gl");
2674
+ a(this, "options");
2675
+ a(this, "onBeforeHooks", new U());
2676
+ a(this, "onAfterHooks", new U());
2677
+ a(this, "_program");
2678
+ a(this, "_geometry");
2679
+ a(this, "_uniforms");
2680
+ a(this, "_textures");
2681
+ a(this, "_clock");
2682
+ a(this, "_resolution", [1, 1]);
2683
+ a(this, "_mouse", [0, 0]);
2684
+ a(this, "_version", 1);
2685
+ a(this, "_runtimeModules", new F());
2686
+ a(this, "playing", !1);
2687
+ this.canvas = e, this.options = t, this.gl = this.initContext(), this.enableExtensions(), this._program = new se(this.gl), this._geometry = A.fullscreenQuad(this.gl), this._uniforms = new fe(this.gl), this._textures = new he(this.gl), this._clock = new re(), this.options.fps && this._clock.setMaxFps(this.options.fps), this.options.onBeforeRender && this.onBeforeHooks.add(this.options.onBeforeRender), this.options.onAfterRender && this.onAfterHooks.add(this.options.onAfterRender), this.onRender = this.onRender.bind(this);
2687
2688
  }
2688
2689
  /**
2689
2690
  * Factory method to create and setup WebGL instance.
2690
2691
  */
2691
2692
  static setup(e, t) {
2692
- const n = new T(e, t);
2693
- return t.vertex && t.fragment && n.shader(t.vertex, t.fragment), t.uniforms && n._uniforms.setMany(t.uniforms), t.textures && n.texturesFromSchema(t.textures), y.isEmpty() || n._uniforms.setMany(y.defaults()), n;
2693
+ const n = new k(e, t);
2694
+ return t.vertex && t.fragment && n.shader(t.vertex, t.fragment), t.uniforms && n._uniforms.setMany(t.uniforms), t.textures && n.texturesFromSchema(t.textures), n._runtimeModules.isEmpty() || n._uniforms.setMany(n._runtimeModules.defaults()), n;
2694
2695
  }
2695
2696
  /**
2696
2697
  * Initialize WebGL context.
@@ -2710,7 +2711,7 @@ class T {
2710
2711
  const n = this.canvas.getContext("webgl", e);
2711
2712
  if (n)
2712
2713
  return this._version = 1, n;
2713
- const i = new W();
2714
+ const i = new G();
2714
2715
  throw this.options.onError(i), i;
2715
2716
  }
2716
2717
  /**
@@ -2786,18 +2787,18 @@ class T {
2786
2787
  */
2787
2788
  shader(e, t) {
2788
2789
  try {
2789
- if (y.clear(), e.version() !== t.version())
2790
- throw new z(
2790
+ if (this._runtimeModules.clear(), e.version() !== t.version())
2791
+ throw new W(
2791
2792
  e.version(),
2792
2793
  t.version()
2793
2794
  );
2794
- this._program.compile(e.source(), t.compile()), this._version = t.version(), this._geometry.linkAttributes(this._program);
2795
+ this._program.compile(e.source(), t.compile(this._runtimeModules)), this._version = t.version(), this._geometry.linkAttributes(this._program);
2795
2796
  const n = this._program.getProgram();
2796
2797
  n && (this._uniforms.attachProgram(n), this._textures.attachProgram(n));
2797
2798
  try {
2798
2799
  this.options.onLoad();
2799
2800
  } catch (i) {
2800
- throw new ie(
2801
+ throw new ne(
2801
2802
  i instanceof Error ? i.message : String(i)
2802
2803
  );
2803
2804
  }
@@ -2843,6 +2844,12 @@ class T {
2843
2844
  getContext() {
2844
2845
  return this.gl;
2845
2846
  }
2847
+ /**
2848
+ * Get registered runtime modules.
2849
+ */
2850
+ getUsingModules() {
2851
+ return this._runtimeModules;
2852
+ }
2846
2853
  /**
2847
2854
  * Get detected WebGL version.
2848
2855
  */
@@ -2859,7 +2866,7 @@ class T {
2859
2866
  * Cleanup all resources.
2860
2867
  */
2861
2868
  destroy() {
2862
- this.pause(), this._clock.destroy(), this._geometry.destroy(), this._program.destroy(), this._uniforms.destroy(), this._textures.destroy(), this.onAfterHooks.destroy(), this.onBeforeHooks.destroy(), y.clear();
2869
+ this.pause(), this._clock.destroy(), this._geometry.destroy(), this._program.destroy(), this._uniforms.destroy(), this._textures.destroy(), this.onAfterHooks.destroy(), this.onBeforeHooks.destroy(), this._runtimeModules.clear();
2863
2870
  }
2864
2871
  /**
2865
2872
  * Internal render callback.
@@ -2879,14 +2886,14 @@ class T {
2879
2886
  }
2880
2887
  }
2881
2888
  }
2882
- class d extends F {
2889
+ class p extends C {
2883
2890
  constructor(e) {
2884
- super(e), R.forEach((t, n) => {
2891
+ super(e), E.forEach((t, n) => {
2885
2892
  this.requirements.uniforms.set(n, { name: n, type: t, line: 0 });
2886
2893
  });
2887
2894
  }
2888
2895
  }
2889
- const A = `#ifdef GL_ES
2896
+ const S = `#ifdef GL_ES
2890
2897
  precision mediump float;
2891
2898
  #endif
2892
2899
 
@@ -2899,7 +2906,7 @@ void main() {
2899
2906
  v_texcoord = a_texcoord;
2900
2907
  gl_Position = vec4(a_position, 0.0, 1.0);
2901
2908
  }
2902
- `, O = `#ifdef GL_ES
2909
+ `, L = `#ifdef GL_ES
2903
2910
  precision mediump float;
2904
2911
  #endif
2905
2912
 
@@ -2913,7 +2920,7 @@ void main() {
2913
2920
  vec3 color = vec3(uv.x, uv.y, 0.5 + 0.5 * sin(u_time));
2914
2921
  gl_FragColor = vec4(color, 1.0);
2915
2922
  }
2916
- `, C = `#version 300 es
2923
+ `, O = `#version 300 es
2917
2924
 
2918
2925
  in vec2 a_position;
2919
2926
  in vec2 a_texcoord;
@@ -2923,7 +2930,7 @@ out vec2 v_texcoord;
2923
2930
  void main() {
2924
2931
  v_texcoord = a_texcoord;
2925
2932
  gl_Position = vec4(a_position, 0.0, 1.0);
2926
- }`, de = `#version 300 es
2933
+ }`, me = `#version 300 es
2927
2934
  precision highp float;
2928
2935
 
2929
2936
  uniform vec2 u_resolution;
@@ -2938,19 +2945,19 @@ void main() {
2938
2945
  vec3 color = vec3(uv.x, uv.y, 0.5 + 0.5 * sin(u_time));
2939
2946
  fragColor = vec4(color, 1.0);
2940
2947
  }`;
2941
- class I {
2948
+ class V {
2942
2949
  constructor(e, t) {
2943
2950
  /** Active event listeners */
2944
- o(this, "listeners", []);
2951
+ a(this, "listeners", []);
2945
2952
  /** HTML canvas element */
2946
- o(this, "canvasEl");
2953
+ a(this, "canvasEl");
2947
2954
  /** Resolved options */
2948
- o(this, "options");
2955
+ a(this, "options");
2949
2956
  /** WebGL engine */
2950
- o(this, "engine");
2957
+ a(this, "engine");
2951
2958
  /** User sets custom vertex shader */
2952
- o(this, "usingCustomVertex", !1);
2953
- if (this.canvasEl = e, this.options = this.resolveOptions(t), this.engine = T.setup(this.canvasEl, this.options), this.setupListeners(), this.setViewport(), this.options.modules)
2959
+ a(this, "usingCustomVertex", !1);
2960
+ if (this.canvasEl = e, this.options = this.resolveOptions(t), this.engine = k.setup(this.canvasEl, this.options), this.setupListeners(), this.setViewport(), this.options.modules)
2954
2961
  for (const [n, i] of Object.entries(this.options.modules))
2955
2962
  this.module(n, i);
2956
2963
  this.options.autoplay && this.play();
@@ -2974,7 +2981,7 @@ class I {
2974
2981
  * });
2975
2982
  */
2976
2983
  static create(e, t) {
2977
- return new I(e, t);
2984
+ return new V(e, t);
2978
2985
  }
2979
2986
  /**
2980
2987
  * Define a shader module that can be imported in shader source with `#import <function> from "module_name"`.
@@ -2987,25 +2994,25 @@ class I {
2987
2994
  * // }
2988
2995
  */
2989
2996
  static defineModule(e, t, n = {}) {
2990
- v.define({ name: e, source: t, options: n });
2997
+ g.define({ name: e, source: t, options: n });
2991
2998
  }
2992
2999
  /**
2993
3000
  * Get the list of available shader modules that can be used with `#import` in shader source.
2994
3001
  */
2995
3002
  static availableModules() {
2996
- return w.available();
3003
+ return b.available();
2997
3004
  }
2998
3005
  /**
2999
3006
  * Compile a shader source with Sandbox's shader preprocessor and return the final GLSL code.
3000
3007
  * This is useful for debugging shader code or precompiling shaders for production use.
3001
3008
  */
3002
3009
  static compile(e) {
3003
- return new d(e).compile();
3010
+ return new p(e).compile();
3004
3011
  }
3005
3012
  resolveOptions(e) {
3006
3013
  const t = {
3007
- vertex: new d(A),
3008
- fragment: new d(O),
3014
+ vertex: new p(S),
3015
+ fragment: new p(L),
3009
3016
  autoplay: !0,
3010
3017
  pauseWhenHidden: !0,
3011
3018
  dpr: "auto",
@@ -3029,42 +3036,42 @@ You can handle errors programmatically by providing an onError callback to suppr
3029
3036
  textures: {}
3030
3037
  };
3031
3038
  if (e != null && e.vertex && (this.usingCustomVertex = !0), e != null && e.vertex && !(e != null && e.fragment)) {
3032
- t.vertex = new d(e.vertex);
3039
+ t.vertex = new p(e.vertex);
3033
3040
  const s = t.vertex.version();
3034
- t.fragment = new d(s === 2 ? de : O);
3041
+ t.fragment = new p(s === 2 ? me : L);
3035
3042
  }
3036
3043
  if (e != null && e.fragment && !(e != null && e.vertex)) {
3037
- t.fragment = new d(e.fragment);
3044
+ t.fragment = new p(e.fragment);
3038
3045
  const s = t.fragment.version();
3039
- t.vertex = new d(s === 2 ? C : A);
3046
+ t.vertex = new p(s === 2 ? O : S);
3040
3047
  }
3041
- e != null && e.vertex && (e != null && e.fragment) && (t.vertex = new d(e.vertex), t.fragment = new d(e.fragment));
3048
+ e != null && e.vertex && (e != null && e.fragment) && (t.vertex = new p(e.vertex), t.fragment = new p(e.fragment));
3042
3049
  const { vertex: n, fragment: i, ...r } = e || {};
3043
3050
  return { ...t, ...r };
3044
3051
  }
3045
3052
  setupListeners() {
3046
3053
  this.listeners.push(
3047
3054
  // Window resize
3048
- b.on(window, "resize", () => {
3055
+ y.on(window, "resize", () => {
3049
3056
  this.setViewport();
3050
3057
  }),
3051
3058
  // Canvas resize
3052
- b.on(this.canvasEl, "resize", () => {
3059
+ y.on(this.canvasEl, "resize", () => {
3053
3060
  this.setViewport();
3054
3061
  }),
3055
3062
  // Visibility check on scroll
3056
3063
  (() => {
3057
3064
  let e = !1;
3058
- return b.on(document, "scroll", (t) => {
3065
+ return y.on(document, "scroll", (t) => {
3059
3066
  this.options.pauseWhenHidden && (this.isInViewport() ? e && !this.isPlaying() && (this.play(), e = !1) : this.isPlaying() && (this.pause(), e = !0));
3060
3067
  });
3061
3068
  })(),
3062
3069
  // Mouse tracking
3063
- b.on(document, "mousemove", (e) => {
3070
+ y.on(document, "mousemove", (e) => {
3064
3071
  this.setMouse(e.clientX || e.pageX, e.clientY || e.pageY);
3065
3072
  }),
3066
3073
  // Touch tracking
3067
- b.on(document, "touchmove", (e) => {
3074
+ y.on(document, "touchmove", (e) => {
3068
3075
  e.touches.length > 0 && this.setMouse(e.touches[0].clientX, e.touches[0].clientY);
3069
3076
  })
3070
3077
  );
@@ -3156,7 +3163,7 @@ You can handle errors programmatically by providing an onError callback to suppr
3156
3163
  * sandbox.setShader(vertexSource, fragmentSource);
3157
3164
  */
3158
3165
  setShader(e, t) {
3159
- return this.options.vertex = new d(e), this.options.fragment = new d(t), this.usingCustomVertex = !0, this.engine.shader(this.options.vertex, this.options.fragment), this;
3166
+ return this.options.vertex = new p(e), this.options.fragment = new p(t), this.usingCustomVertex = !0, this.engine.shader(this.options.vertex, this.options.fragment), this;
3160
3167
  }
3161
3168
  /**
3162
3169
  * Update only fragment shader (uses default vertex).
@@ -3164,9 +3171,9 @@ You can handle errors programmatically by providing an onError callback to suppr
3164
3171
  * sandbox.setFragment(fragmentSource);
3165
3172
  */
3166
3173
  setFragment(e) {
3167
- const t = new d(e), n = t.version(), i = this.options.vertex.version();
3168
- return this.options.fragment = t, n !== i && (this.usingCustomVertex || (this.options.vertex = new d(
3169
- n === 2 ? C : A
3174
+ const t = new p(e), n = t.version(), i = this.options.vertex.version();
3175
+ return this.options.fragment = t, n !== i && (this.usingCustomVertex || (this.options.vertex = new p(
3176
+ n === 2 ? O : S
3170
3177
  ))), this.engine.shader(this.options.vertex, this.options.fragment), this;
3171
3178
  }
3172
3179
  /**
@@ -3203,20 +3210,20 @@ You can handle errors programmatically by providing an onError callback to suppr
3203
3210
  * sandbox.module("my_module", { intensity: 0.5 });
3204
3211
  */
3205
3212
  module(e, t) {
3206
- const n = y.resolveOptions(e);
3207
- if (!n)
3213
+ const i = this.engine.getUsingModules().resolveOptions(e);
3214
+ if (!i)
3208
3215
  return console.warn(
3209
3216
  `Sandbox: Counld not find options for '${e}' function. Make sure you used the correct imported name and the module is currently in use by the shader.`
3210
3217
  ), this;
3211
- for (const [i, r] of Object.entries(t)) {
3212
- const s = n[i];
3213
- if (!s) {
3218
+ for (const [r, s] of Object.entries(t)) {
3219
+ const o = i[r];
3220
+ if (!o) {
3214
3221
  console.warn(
3215
- `Sandbox: Option '${i}' not found for function '${e}'. Make sure to check available options with Sandbox.availableModules() and provide the correct option name.`
3222
+ `Sandbox: Option '${r}' not found for function '${e}'. Make sure to check available options with Sandbox.availableModules() and provide the correct option name.`
3216
3223
  );
3217
3224
  continue;
3218
3225
  }
3219
- this.setUniform(s.uniform, r);
3226
+ this.setUniform(o.uniform, s);
3220
3227
  }
3221
3228
  return this;
3222
3229
  }
@@ -3356,28 +3363,28 @@ You can handle errors programmatically by providing an onError callback to suppr
3356
3363
  }
3357
3364
  }
3358
3365
  export {
3359
- I as Sandbox,
3360
- Q as SandboxAttemptedToImportDefaultFunctionError,
3361
- K as SandboxAttemptedToImportMainFunctionError,
3362
- ve as SandboxContextCreationError,
3366
+ V as Sandbox,
3367
+ K as SandboxAttemptedToImportDefaultFunctionError,
3368
+ Y as SandboxAttemptedToImportMainFunctionError,
3369
+ pe as SandboxContextCreationError,
3363
3370
  h as SandboxError,
3364
- J as SandboxForbiddenModuleNameError,
3371
+ Q as SandboxForbiddenModuleNameError,
3365
3372
  _ as SandboxGLSLShaderCompilationError,
3366
- ne as SandboxMentionCouldNotBeReplacedError,
3367
- te as SandboxMentionFunctionNotFoundError,
3368
- ee as SandboxMentionUniformNotFoundError,
3369
- Y as SandboxModuleMethodNotFoundError,
3370
- X as SandboxModuleNotFoundError,
3371
- re as SandboxOnHookCallbackError,
3372
- ie as SandboxOnLoadCallbackError,
3373
- Z as SandboxOverwriteModuleError,
3374
- S as SandboxProgramError,
3375
- j as SandboxShaderDuplicateImportNameError,
3376
- q as SandboxShaderImportSyntaxError,
3377
- U as SandboxShaderRequirementMismatchError,
3378
- z as SandboxShaderVersionMismatchError,
3379
- H as SandboxShaderWithoutFunctionError,
3380
- ge as SandboxTextureCreationError,
3381
- xe as SandboxTextureUnitLimitError,
3382
- W as SandboxWebGLNotSupportedError
3373
+ te as SandboxMentionCouldNotBeReplacedError,
3374
+ ee as SandboxMentionFunctionNotFoundError,
3375
+ Z as SandboxMentionUniformNotFoundError,
3376
+ X as SandboxModuleMethodNotFoundError,
3377
+ j as SandboxModuleNotFoundError,
3378
+ ie as SandboxOnHookCallbackError,
3379
+ ne as SandboxOnLoadCallbackError,
3380
+ J as SandboxOverwriteModuleError,
3381
+ R as SandboxProgramError,
3382
+ q as SandboxShaderDuplicateImportNameError,
3383
+ H as SandboxShaderImportSyntaxError,
3384
+ T as SandboxShaderRequirementMismatchError,
3385
+ W as SandboxShaderVersionMismatchError,
3386
+ z as SandboxShaderWithoutFunctionError,
3387
+ ve as SandboxTextureCreationError,
3388
+ ge as SandboxTextureUnitLimitError,
3389
+ G as SandboxWebGLNotSupportedError
3383
3390
  };