textmode.synth.js 1.0.0-beta.3 → 1.0.0-beta.5

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.
@@ -1,36 +1,36 @@
1
- const Y = { src: { returnType: "vec4", args: [{ type: "vec2", name: "_st" }] }, coord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }] }, color: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }] }, combine: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }, { type: "vec4", name: "_c1" }] }, combineCoord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }, { type: "vec4", name: "_c0" }] } };
2
- function E(t) {
3
- const e = Y[t.type], n = [...e.args, ...t.inputs.map((r) => ({ type: r.type, name: r.name }))].map((r) => `${r.type} ${r.name}`).join(", "), a = `
4
- ${e.returnType} ${t.name}(${n}) {
1
+ const X = { src: { returnType: "vec4", args: [{ type: "vec2", name: "_st" }] }, coord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }] }, color: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }] }, combine: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }, { type: "vec4", name: "_c1" }] }, combineCoord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }, { type: "vec4", name: "_c0" }] } };
2
+ function D(t) {
3
+ const e = X[t.type], r = [...e.args, ...t.inputs.map((n) => ({ type: n.type, name: n.name }))].map((n) => `${n.type} ${n.name}`).join(", "), a = `
4
+ ${e.returnType} ${t.name}(${r}) {
5
5
  ${t.glsl}
6
6
  }`;
7
7
  return { ...t, glslFunction: a };
8
8
  }
9
- class X {
9
+ class j {
10
10
  _transforms = /* @__PURE__ */ new Map();
11
11
  _processedCache = /* @__PURE__ */ new Map();
12
12
  register(e) {
13
13
  this._transforms.has(e.name) && console.warn(`[TransformRegistry] Overwriting existing transform: ${e.name}`), this._transforms.set(e.name, e), this._processedCache.delete(e.name);
14
14
  }
15
15
  registerMany(e) {
16
- for (const n of e) this.register(n);
16
+ for (const r of e) this.register(r);
17
17
  }
18
18
  get(e) {
19
19
  return this._transforms.get(e);
20
20
  }
21
21
  getProcessed(e) {
22
- let n = this._processedCache.get(e);
23
- if (!n) {
22
+ let r = this._processedCache.get(e);
23
+ if (!r) {
24
24
  const a = this._transforms.get(e);
25
- a && (n = E(a), this._processedCache.set(e, n));
25
+ a && (r = D(a), this._processedCache.set(e, r));
26
26
  }
27
- return n;
27
+ return r;
28
28
  }
29
29
  has(e) {
30
30
  return this._transforms.has(e);
31
31
  }
32
32
  getByType(e) {
33
- return Array.from(this._transforms.values()).filter((n) => n.type === e);
33
+ return Array.from(this._transforms.values()).filter((r) => r.type === e);
34
34
  }
35
35
  getNames() {
36
36
  return Array.from(this._transforms.keys());
@@ -51,35 +51,35 @@ class X {
51
51
  return this._transforms.size;
52
52
  }
53
53
  }
54
- const k = new X(), O = /* @__PURE__ */ new Set(["src"]);
55
- class j {
54
+ const k = new j(), O = /* @__PURE__ */ new Set(["src"]);
55
+ class G {
56
56
  _generatedFunctions = {};
57
57
  _synthSourceClass = null;
58
58
  setSynthSourceClass(e) {
59
59
  this._synthSourceClass = e;
60
60
  }
61
61
  injectMethods(e) {
62
- const n = k.getAll();
63
- for (const a of n) this._injectMethod(e, a);
64
- }
65
- _injectMethod(e, n) {
66
- const { name: a, inputs: r, type: o } = n;
67
- e[a] = o === "combine" || o === "combineCoord" ? function(c, ...s) {
68
- const l = r.map((m, d) => s[d] ?? m.default);
69
- return this.addCombineTransform(a, c, l);
70
- } : function(...c) {
71
- const s = r.map((l, m) => c[m] ?? l.default);
62
+ const r = k.getAll();
63
+ for (const a of r) this._injectMethod(e, a);
64
+ }
65
+ _injectMethod(e, r) {
66
+ const { name: a, inputs: n, type: o } = r;
67
+ e[a] = o === "combine" || o === "combineCoord" ? function(l, ...s) {
68
+ const i = n.map((m, h) => s[h] ?? m.default);
69
+ return this.addCombineTransform(a, l, i);
70
+ } : function(...l) {
71
+ const s = n.map((i, m) => l[m] ?? i.default);
72
72
  return this.addTransform(a, s);
73
73
  };
74
74
  }
75
75
  generateStandaloneFunctions() {
76
76
  if (!this._synthSourceClass) throw new Error("[TransformFactory] SynthSource class not set. Call setSynthSourceClass first.");
77
- const e = {}, n = k.getAll(), a = this._synthSourceClass;
78
- for (const r of n) if (O.has(r.type)) {
79
- const { name: o, inputs: c } = r;
77
+ const e = {}, r = k.getAll(), a = this._synthSourceClass;
78
+ for (const n of r) if (O.has(n.type)) {
79
+ const { name: o, inputs: l } = n;
80
80
  e[o] = (...s) => {
81
- const l = new a(), m = c.map((d, p) => s[p] ?? d.default);
82
- return l.addTransform(o, m);
81
+ const i = new a(), m = l.map((h, y) => s[y] ?? h.default);
82
+ return i.addTransform(o, m);
83
83
  };
84
84
  }
85
85
  return this._generatedFunctions = e, e;
@@ -87,25 +87,25 @@ class j {
87
87
  getGeneratedFunctions() {
88
88
  return this._generatedFunctions;
89
89
  }
90
- addTransform(e, n) {
91
- if (k.register(e), n && this._injectMethod(n, e), O.has(e.type) && this._synthSourceClass) {
92
- const a = this._synthSourceClass, { name: r, inputs: o } = e;
93
- this._generatedFunctions[r] = (...c) => {
94
- const s = new a(), l = o.map((m, d) => c[d] ?? m.default);
95
- return s.addTransform(r, l);
90
+ addTransform(e, r) {
91
+ if (k.register(e), r && this._injectMethod(r, e), O.has(e.type) && this._synthSourceClass) {
92
+ const a = this._synthSourceClass, { name: n, inputs: o } = e;
93
+ this._generatedFunctions[n] = (...l) => {
94
+ const s = new a(), i = o.map((m, h) => l[h] ?? m.default);
95
+ return s.addTransform(n, i);
96
96
  };
97
97
  }
98
98
  }
99
99
  }
100
- const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency", type: "float", default: 60 }, { name: "sync", type: "float", default: 0.1 }, { name: "offset", type: "float", default: 0 }], glsl: `
100
+ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency", type: "float", default: 60 }, { name: "sync", type: "float", default: 0.1 }, { name: "offset", type: "float", default: 0 }], glsl: `
101
101
  vec2 st = _st;
102
102
  float r = sin((st.x - offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
103
103
  float g = sin((st.x + time*sync) * frequency) * 0.5 + 0.5;
104
104
  float b = sin((st.x + offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
105
105
  return vec4(r, g, b, 1.0);
106
- `, description: "Generate oscillating color pattern" }, N = { name: "noise", type: "src", inputs: [{ name: "scale", type: "float", default: 10 }, { name: "offset", type: "float", default: 0.1 }], glsl: `
106
+ `, description: "Generate oscillating color pattern" }, K = { name: "noise", type: "src", inputs: [{ name: "scale", type: "float", default: 10 }, { name: "offset", type: "float", default: 0.1 }], glsl: `
107
107
  return vec4(vec3(_noise(vec3(_st * scale, offset * time))), 1.0);
108
- `, description: "Generate noise pattern" }, q = { name: "voronoi", type: "src", inputs: [{ name: "scale", type: "float", default: 5 }, { name: "speed", type: "float", default: 0.3 }, { name: "blending", type: "float", default: 0.3 }], glsl: `
108
+ `, description: "Generate noise pattern" }, Q = { name: "voronoi", type: "src", inputs: [{ name: "scale", type: "float", default: 5 }, { name: "speed", type: "float", default: 0.3 }, { name: "blending", type: "float", default: 0.3 }], glsl: `
109
109
  vec3 color = vec3(0.0);
110
110
  vec2 st = _st * scale;
111
111
  vec2 i_st = floor(st);
@@ -129,59 +129,59 @@ const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency",
129
129
  color += dot(m_point, vec2(0.3, 0.6));
130
130
  color *= 1.0 - blending * m_dist;
131
131
  return vec4(color, 1.0);
132
- `, description: "Generate voronoi pattern" }, G = { name: "gradient", type: "src", inputs: [{ name: "speed", type: "float", default: 0 }], glsl: `
132
+ `, description: "Generate voronoi pattern" }, H = { name: "gradient", type: "src", inputs: [{ name: "speed", type: "float", default: 0 }], glsl: `
133
133
  return vec4(_st, sin(time * speed), 1.0);
134
- `, description: "Generate gradient pattern" }, K = { name: "shape", type: "src", inputs: [{ name: "sides", type: "float", default: 3 }, { name: "radius", type: "float", default: 0.3 }, { name: "smoothing", type: "float", default: 0.01 }], glsl: `
134
+ `, description: "Generate gradient pattern" }, W = { name: "shape", type: "src", inputs: [{ name: "sides", type: "float", default: 3 }, { name: "radius", type: "float", default: 0.3 }, { name: "smoothing", type: "float", default: 0.01 }], glsl: `
135
135
  vec2 st = _st * 2.0 - 1.0;
136
136
  float a = atan(st.x, st.y) + 3.1416;
137
137
  float r = (2.0 * 3.1416) / sides;
138
138
  float d = cos(floor(0.5 + a/r) * r - a) * length(st);
139
139
  return vec4(vec3(1.0 - smoothstep(radius, radius + smoothing + 0.0000001, d)), 1.0);
140
- `, description: "Generate polygon shape" }, Q = { name: "solid", type: "src", inputs: [{ name: "r", type: "float", default: 0 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 1 }], glsl: `
140
+ `, description: "Generate polygon shape" }, J = { name: "solid", type: "src", inputs: [{ name: "r", type: "float", default: 0 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 1 }], glsl: `
141
141
  return vec4(r, g, b, a);
142
- `, description: "Generate solid color" }, H = { name: "src", type: "src", inputs: [], glsl: `
142
+ `, description: "Generate solid color" }, Z = { name: "src", type: "src", inputs: [], glsl: `
143
143
  return texture(prevCharColorBuffer, fract(_st));
144
- `, description: "Sample the previous frame for feedback effects. Context-aware: automatically samples the appropriate texture based on where it is used (char, charColor, or cellColor context)." }, W = [D, N, q, G, K, Q, H], J = { name: "rotate", type: "coord", inputs: [{ name: "angle", type: "float", default: 10 }, { name: "speed", type: "float", default: 0 }], glsl: `
144
+ `, description: "Sample the previous frame for feedback effects. Context-aware: automatically samples the appropriate texture based on where it is used (char, charColor, or cellColor context)." }, ee = [q, K, Q, H, W, J, Z], te = { name: "rotate", type: "coord", inputs: [{ name: "angle", type: "float", default: 10 }, { name: "speed", type: "float", default: 0 }], glsl: `
145
145
  vec2 xy = _st - vec2(0.5);
146
146
  float ang = angle + speed * time;
147
147
  xy = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * xy;
148
148
  xy += 0.5;
149
149
  return xy;
150
- `, description: "Rotate coordinates" }, Z = { name: "scale", type: "coord", inputs: [{ name: "amount", type: "float", default: 1.5 }, { name: "xMult", type: "float", default: 1 }, { name: "yMult", type: "float", default: 1 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
150
+ `, description: "Rotate coordinates" }, re = { name: "scale", type: "coord", inputs: [{ name: "amount", type: "float", default: 1.5 }, { name: "xMult", type: "float", default: 1 }, { name: "yMult", type: "float", default: 1 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
151
151
  vec2 xy = _st - vec2(offsetX, offsetY);
152
152
  xy *= (1.0 / vec2(amount * xMult, amount * yMult));
153
153
  xy += vec2(offsetX, offsetY);
154
154
  return xy;
155
- `, description: "Scale coordinates" }, ee = { name: "scroll", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "scrollY", type: "float", default: 0.5 }, { name: "speedX", type: "float", default: 0 }, { name: "speedY", type: "float", default: 0 }], glsl: `
155
+ `, description: "Scale coordinates" }, ne = { name: "scroll", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "scrollY", type: "float", default: 0.5 }, { name: "speedX", type: "float", default: 0 }, { name: "speedY", type: "float", default: 0 }], glsl: `
156
156
  vec2 st = _st;
157
157
  st.x += scrollX + time * speedX;
158
158
  st.y += scrollY + time * speedY;
159
159
  return fract(st);
160
- `, description: "Scroll coordinates" }, te = { name: "scrollX", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
160
+ `, description: "Scroll coordinates" }, ae = { name: "scrollX", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
161
161
  vec2 st = _st;
162
162
  st.x += scrollX + time * speed;
163
163
  return fract(st);
164
- `, description: "Scroll X coordinate" }, ne = { name: "scrollY", type: "coord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
164
+ `, description: "Scroll X coordinate" }, oe = { name: "scrollY", type: "coord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
165
165
  vec2 st = _st;
166
166
  st.y += scrollY + time * speed;
167
167
  return fract(st);
168
- `, description: "Scroll Y coordinate" }, re = { name: "pixelate", type: "coord", inputs: [{ name: "pixelX", type: "float", default: 20 }, { name: "pixelY", type: "float", default: 20 }], glsl: `
168
+ `, description: "Scroll Y coordinate" }, se = { name: "pixelate", type: "coord", inputs: [{ name: "pixelX", type: "float", default: 20 }, { name: "pixelY", type: "float", default: 20 }], glsl: `
169
169
  vec2 xy = vec2(pixelX, pixelY);
170
170
  return (floor(_st * xy) + 0.5) / xy;
171
- `, description: "Pixelate coordinates" }, ae = { name: "repeat", type: "coord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0 }, { name: "offsetY", type: "float", default: 0 }], glsl: `
171
+ `, description: "Pixelate coordinates" }, ce = { name: "repeat", type: "coord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0 }, { name: "offsetY", type: "float", default: 0 }], glsl: `
172
172
  vec2 st = _st * vec2(repeatX, repeatY);
173
173
  st.x += step(1.0, mod(st.y, 2.0)) * offsetX;
174
174
  st.y += step(1.0, mod(st.x, 2.0)) * offsetY;
175
175
  return fract(st);
176
- `, description: "Repeat pattern" }, oe = { name: "repeatX", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
176
+ `, description: "Repeat pattern" }, le = { name: "repeatX", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
177
177
  vec2 st = _st * vec2(reps, 1.0);
178
178
  st.y += step(1.0, mod(st.x, 2.0)) * offset;
179
179
  return fract(st);
180
- `, description: "Repeat pattern horizontally" }, se = { name: "repeatY", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
180
+ `, description: "Repeat pattern horizontally" }, ie = { name: "repeatY", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
181
181
  vec2 st = _st * vec2(1.0, reps);
182
182
  st.x += step(1.0, mod(st.y, 2.0)) * offset;
183
183
  return fract(st);
184
- `, description: "Repeat pattern vertically" }, ce = { name: "kaleid", type: "coord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
184
+ `, description: "Repeat pattern vertically" }, ue = { name: "kaleid", type: "coord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
185
185
  vec2 st = _st;
186
186
  st -= 0.5;
187
187
  float r = length(st);
@@ -190,97 +190,97 @@ const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency",
190
190
  a = mod(a, pi / nSides);
191
191
  a = abs(a - pi / nSides / 2.0);
192
192
  return r * vec2(cos(a), sin(a));
193
- `, description: "Kaleidoscope effect" }, le = [J, Z, ee, te, ne, re, ae, oe, se, ce], ie = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
193
+ `, description: "Kaleidoscope effect" }, fe = [te, re, ne, ae, oe, se, ce, le, ie, ue], pe = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
194
194
  return vec4(_c0.rgb + vec3(amount), _c0.a);
195
- `, description: "Adjust brightness" }, ue = { name: "contrast", type: "color", inputs: [{ name: "amount", type: "float", default: 1.6 }], glsl: `
195
+ `, description: "Adjust brightness" }, me = { name: "contrast", type: "color", inputs: [{ name: "amount", type: "float", default: 1.6 }], glsl: `
196
196
  vec4 c = (_c0 - vec4(0.5)) * vec4(amount) + vec4(0.5);
197
197
  return vec4(c.rgb, _c0.a);
198
- `, description: "Adjust contrast" }, fe = { name: "invert", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
198
+ `, description: "Adjust contrast" }, de = { name: "invert", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
199
199
  return vec4((1.0 - _c0.rgb) * amount + _c0.rgb * (1.0 - amount), _c0.a);
200
- `, description: "Invert colors" }, pe = { name: "saturate", type: "color", inputs: [{ name: "amount", type: "float", default: 2 }], glsl: `
200
+ `, description: "Invert colors" }, he = { name: "saturate", type: "color", inputs: [{ name: "amount", type: "float", default: 2 }], glsl: `
201
201
  const vec3 W = vec3(0.2125, 0.7154, 0.0721);
202
202
  vec3 intensity = vec3(dot(_c0.rgb, W));
203
203
  return vec4(mix(intensity, _c0.rgb, amount), _c0.a);
204
- `, description: "Adjust saturation" }, me = { name: "hue", type: "color", inputs: [{ name: "hue", type: "float", default: 0.4 }], glsl: `
204
+ `, description: "Adjust saturation" }, ye = { name: "hue", type: "color", inputs: [{ name: "hue", type: "float", default: 0.4 }], glsl: `
205
205
  vec3 c = _rgbToHsv(_c0.rgb);
206
206
  c.r += hue;
207
207
  return vec4(_hsvToRgb(c), _c0.a);
208
- `, description: "Shift hue" }, de = { name: "colorama", type: "color", inputs: [{ name: "amount", type: "float", default: 5e-3 }], glsl: `
208
+ `, description: "Shift hue" }, ge = { name: "colorama", type: "color", inputs: [{ name: "amount", type: "float", default: 5e-3 }], glsl: `
209
209
  vec3 c = _rgbToHsv(_c0.rgb);
210
210
  c += vec3(amount);
211
211
  c = _hsvToRgb(c);
212
212
  c = fract(c);
213
213
  return vec4(c, _c0.a);
214
- `, description: "Color cycle effect" }, he = { name: "posterize", type: "color", inputs: [{ name: "bins", type: "float", default: 3 }, { name: "gamma", type: "float", default: 0.6 }], glsl: `
214
+ `, description: "Color cycle effect" }, _e = { name: "posterize", type: "color", inputs: [{ name: "bins", type: "float", default: 3 }, { name: "gamma", type: "float", default: 0.6 }], glsl: `
215
215
  vec4 c2 = pow(_c0, vec4(gamma));
216
216
  c2 *= vec4(bins);
217
217
  c2 = floor(c2);
218
218
  c2 /= vec4(bins);
219
219
  c2 = pow(c2, vec4(1.0 / gamma));
220
220
  return vec4(c2.xyz, _c0.a);
221
- `, description: "Posterize colors" }, ye = { name: "luma", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.1 }], glsl: `
221
+ `, description: "Posterize colors" }, ve = { name: "luma", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.1 }], glsl: `
222
222
  float a = smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb));
223
223
  return vec4(_c0.rgb * a, a);
224
- `, description: "Luma key" }, ge = { name: "thresh", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.04 }], glsl: `
224
+ `, description: "Luma key" }, xe = { name: "thresh", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.04 }], glsl: `
225
225
  return vec4(vec3(smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb))), _c0.a);
226
- `, description: "Threshold" }, _e = { name: "color", type: "color", inputs: [{ name: "r", type: "float", default: 1 }, { name: "g", type: "float", default: 1 }, { name: "b", type: "float", default: 1 }, { name: "a", type: "float", default: 1 }], glsl: `
226
+ `, description: "Threshold" }, Ce = { name: "color", type: "color", inputs: [{ name: "r", type: "float", default: 1 }, { name: "g", type: "float", default: 1 }, { name: "b", type: "float", default: 1 }, { name: "a", type: "float", default: 1 }], glsl: `
227
227
  vec4 c = vec4(r, g, b, a);
228
228
  vec4 pos = step(0.0, c);
229
229
  return vec4(mix((1.0 - _c0.rgb) * abs(c.rgb), c.rgb * _c0.rgb, pos.rgb), c.a * _c0.a);
230
- `, description: "Multiply by color" }, ve = { name: "r", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
230
+ `, description: "Multiply by color" }, be = { name: "r", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
231
231
  return vec4(_c0.r * scale + offset);
232
- `, description: "Extract red channel" }, xe = { name: "g", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
232
+ `, description: "Extract red channel" }, Se = { name: "g", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
233
233
  return vec4(_c0.g * scale + offset);
234
- `, description: "Extract green channel" }, Ce = { name: "b", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
234
+ `, description: "Extract green channel" }, Me = { name: "b", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
235
235
  return vec4(_c0.b * scale + offset);
236
- `, description: "Extract blue channel" }, be = { name: "shift", type: "color", inputs: [{ name: "r", type: "float", default: 0.5 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 0 }], glsl: `
236
+ `, description: "Extract blue channel" }, $e = { name: "shift", type: "color", inputs: [{ name: "r", type: "float", default: 0.5 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 0 }], glsl: `
237
237
  vec4 c2 = vec4(_c0);
238
238
  c2.r += fract(r);
239
239
  c2.g += fract(g);
240
240
  c2.b += fract(b);
241
241
  c2.a += fract(a);
242
242
  return vec4(c2.rgba);
243
- `, description: "Shift color channels by adding offset values" }, Se = { name: "gamma", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
243
+ `, description: "Shift color channels by adding offset values" }, we = { name: "gamma", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
244
244
  return vec4(pow(max(vec3(0.0), _c0.rgb), vec3(1.0 / amount)), _c0.a);
245
- `, description: "Apply gamma correction" }, Me = { name: "levels", type: "color", inputs: [{ name: "inMin", type: "float", default: 0 }, { name: "inMax", type: "float", default: 1 }, { name: "outMin", type: "float", default: 0 }, { name: "outMax", type: "float", default: 1 }, { name: "gamma", type: "float", default: 1 }], glsl: `
245
+ `, description: "Apply gamma correction" }, Fe = { name: "levels", type: "color", inputs: [{ name: "inMin", type: "float", default: 0 }, { name: "inMax", type: "float", default: 1 }, { name: "outMin", type: "float", default: 0 }, { name: "outMax", type: "float", default: 1 }, { name: "gamma", type: "float", default: 1 }], glsl: `
246
246
  vec3 v = clamp((_c0.rgb - vec3(inMin)) / (vec3(inMax - inMin) + 0.0000001), 0.0, 1.0);
247
247
  v = pow(v, vec3(1.0 / gamma));
248
248
  v = mix(vec3(outMin), vec3(outMax), v);
249
249
  return vec4(v, _c0.a);
250
- `, description: "Adjust input/output levels and gamma" }, $e = { name: "clamp", type: "color", inputs: [{ name: "min", type: "float", default: 0 }, { name: "max", type: "float", default: 1 }], glsl: `
250
+ `, description: "Adjust input/output levels and gamma" }, ke = { name: "clamp", type: "color", inputs: [{ name: "min", type: "float", default: 0 }, { name: "max", type: "float", default: 1 }], glsl: `
251
251
  return vec4(clamp(_c0.rgb, vec3(min), vec3(max)), _c0.a);
252
- `, description: "Clamp color values to a range" }, we = [ie, ue, fe, pe, me, de, he, ye, ge, _e, ve, xe, Ce, be, Se, Me, $e], Fe = { name: "add", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
252
+ `, description: "Clamp color values to a range" }, Te = [pe, me, de, he, ye, ge, _e, ve, xe, Ce, be, Se, Me, $e, we, Fe, ke], Le = { name: "add", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
253
253
  return (_c0 + _c1) * amount + _c0 * (1.0 - amount);
254
- `, description: "Add another source" }, ke = { name: "sub", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
254
+ `, description: "Add another source" }, Pe = { name: "sub", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
255
255
  return (_c0 - _c1) * amount + _c0 * (1.0 - amount);
256
- `, description: "Subtract another source" }, Te = { name: "mult", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
256
+ `, description: "Subtract another source" }, Ie = { name: "mult", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
257
257
  return _c0 * (1.0 - amount) + (_c0 * _c1) * amount;
258
- `, description: "Multiply with another source" }, Le = { name: "blend", type: "combine", inputs: [{ name: "amount", type: "float", default: 0.5 }], glsl: `
258
+ `, description: "Multiply with another source" }, Ae = { name: "blend", type: "combine", inputs: [{ name: "amount", type: "float", default: 0.5 }], glsl: `
259
259
  return _c0 * (1.0 - amount) + _c1 * amount;
260
- `, description: "Blend with another source" }, Pe = { name: "diff", type: "combine", inputs: [], glsl: `
260
+ `, description: "Blend with another source" }, Re = { name: "diff", type: "combine", inputs: [], glsl: `
261
261
  return vec4(abs(_c0.rgb - _c1.rgb), max(_c0.a, _c1.a));
262
- `, description: "Difference with another source" }, Ie = { name: "layer", type: "combine", inputs: [], glsl: `
262
+ `, description: "Difference with another source" }, ze = { name: "layer", type: "combine", inputs: [], glsl: `
263
263
  return vec4(mix(_c0.rgb, _c1.rgb, _c1.a), clamp(_c0.a + _c1.a, 0.0, 1.0));
264
- `, description: "Layer another source on top" }, Re = { name: "mask", type: "combine", inputs: [], glsl: `
264
+ `, description: "Layer another source on top" }, Oe = { name: "mask", type: "combine", inputs: [], glsl: `
265
265
  float a = _luminance(_c1.rgb);
266
266
  return vec4(_c0.rgb * a, a * _c0.a);
267
- `, description: "Mask with another source" }, Ae = [Fe, ke, Te, Le, Pe, Ie, Re], ze = { name: "modulate", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 0.1 }], glsl: `
267
+ `, description: "Mask with another source" }, Ue = [Le, Pe, Ie, Ae, Re, ze, Oe], Ve = { name: "modulate", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 0.1 }], glsl: `
268
268
  return _st + _c0.xy * amount;
269
- `, description: "Modulate coordinates with another source" }, Oe = { name: "modulateScale", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 1 }], glsl: `
269
+ `, description: "Modulate coordinates with another source" }, Ee = { name: "modulateScale", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 1 }], glsl: `
270
270
  vec2 xy = _st - vec2(0.5);
271
271
  xy *= (1.0 / vec2(offset + multiple * _c0.r, offset + multiple * _c0.g));
272
272
  xy += vec2(0.5);
273
273
  return xy;
274
- `, description: "Modulate scale with another source" }, Ue = { name: "modulateRotate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
274
+ `, description: "Modulate scale with another source" }, Be = { name: "modulateRotate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
275
275
  vec2 xy = _st - vec2(0.5);
276
276
  float angle = offset + _c0.x * multiple;
277
277
  xy = mat2(cos(angle), -sin(angle), sin(angle), cos(angle)) * xy;
278
278
  xy += 0.5;
279
279
  return xy;
280
- `, description: "Modulate rotation with another source" }, Be = { name: "modulatePixelate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 10 }, { name: "offset", type: "float", default: 3 }], glsl: `
280
+ `, description: "Modulate rotation with another source" }, Ne = { name: "modulatePixelate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 10 }, { name: "offset", type: "float", default: 3 }], glsl: `
281
281
  vec2 xy = vec2(offset + _c0.x * multiple, offset + _c0.y * multiple);
282
282
  return (floor(_st * xy) + 0.5) / xy;
283
- `, description: "Modulate pixelation with another source" }, Ve = { name: "modulateKaleid", type: "combineCoord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
283
+ `, description: "Modulate pixelation with another source" }, Ye = { name: "modulateKaleid", type: "combineCoord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
284
284
  vec2 st = _st - 0.5;
285
285
  float r = length(st);
286
286
  float a = atan(st.y, st.x);
@@ -288,40 +288,40 @@ const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency",
288
288
  a = mod(a, pi / nSides);
289
289
  a = abs(a - pi / nSides / 2.0);
290
290
  return (_c0.r + r) * vec2(cos(a), sin(a));
291
- `, description: "Modulate kaleidoscope with another source" }, Ye = { name: "modulateScrollX", type: "combineCoord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
291
+ `, description: "Modulate kaleidoscope with another source" }, Xe = { name: "modulateScrollX", type: "combineCoord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
292
292
  vec2 st = _st;
293
293
  st.x += _c0.r * scrollX + time * speed;
294
294
  return fract(st);
295
- `, description: "Modulate X scroll with another source" }, Ee = { name: "modulateScrollY", type: "combineCoord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
295
+ `, description: "Modulate X scroll with another source" }, De = { name: "modulateScrollY", type: "combineCoord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
296
296
  vec2 st = _st;
297
297
  st.y += _c0.r * scrollY + time * speed;
298
298
  return fract(st);
299
- `, description: "Modulate Y scroll with another source" }, Xe = { name: "modulateRepeat", type: "combineCoord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
299
+ `, description: "Modulate Y scroll with another source" }, je = { name: "modulateRepeat", type: "combineCoord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
300
300
  vec2 st = _st * vec2(repeatX, repeatY);
301
301
  st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offsetX;
302
302
  st.y += step(1.0, mod(st.x, 2.0)) + _c0.g * offsetY;
303
303
  return fract(st);
304
- `, description: "Modulate repeat pattern with another source" }, je = { name: "modulateRepeatX", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
304
+ `, description: "Modulate repeat pattern with another source" }, Ge = { name: "modulateRepeatX", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
305
305
  vec2 st = _st * vec2(reps, 1.0);
306
306
  st.y += step(1.0, mod(st.x, 2.0)) + _c0.r * offset;
307
307
  return fract(st);
308
- `, description: "Modulate X repeat with another source" }, De = { name: "modulateRepeatY", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
308
+ `, description: "Modulate X repeat with another source" }, qe = { name: "modulateRepeatY", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
309
309
  vec2 st = _st * vec2(1.0, reps);
310
310
  st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offset;
311
311
  return fract(st);
312
- `, description: "Modulate Y repeat with another source" }, Ne = { name: "modulateHue", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
312
+ `, description: "Modulate Y repeat with another source" }, Ke = { name: "modulateHue", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
313
313
  return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0 / resolution);
314
- `, description: "Modulate coordinates based on hue differences" }, qe = [ze, Oe, Ue, Be, Ve, Ye, Ee, Xe, je, De, Ne], Ge = [...W, ...le, ...we, ...Ae, ...qe];
315
- class w {
314
+ `, description: "Modulate coordinates based on hue differences" }, Qe = [Ve, Ee, Be, Ne, Ye, Xe, De, je, Ge, qe, Ke], He = [...ee, ...fe, ...Te, ...Ue, ...Qe];
315
+ class F {
316
316
  _transforms;
317
317
  constructor(e) {
318
318
  this._transforms = e;
319
319
  }
320
320
  static empty() {
321
- return new w([]);
321
+ return new F([]);
322
322
  }
323
323
  static from(e) {
324
- return new w([...e]);
324
+ return new F([...e]);
325
325
  }
326
326
  get transforms() {
327
327
  return this._transforms;
@@ -336,7 +336,7 @@ class w {
336
336
  return this._transforms.length === 0;
337
337
  }
338
338
  append(e) {
339
- return new w([...this._transforms, e]);
339
+ return new F([...this._transforms, e]);
340
340
  }
341
341
  get(e) {
342
342
  return this._transforms[e];
@@ -345,7 +345,7 @@ class w {
345
345
  return this._transforms[Symbol.iterator]();
346
346
  }
347
347
  }
348
- class b {
348
+ class S {
349
349
  _chain;
350
350
  _charMapping;
351
351
  _nestedSources;
@@ -353,32 +353,31 @@ class b {
353
353
  _colorSource;
354
354
  _cellColorSource;
355
355
  _charSource;
356
- _charCount;
357
356
  constructor(e) {
358
- this._chain = e?.chain ?? w.empty(), this._charMapping = e?.charMapping, this._colorSource = e?.colorSource, this._cellColorSource = e?.cellColorSource, this._charSource = e?.charSource, this._charCount = e?.charCount, this._nestedSources = e?.nestedSources ?? /* @__PURE__ */ new Map(), this._externalLayerRefs = e?.externalLayerRefs ?? /* @__PURE__ */ new Map();
357
+ this._chain = e?.chain ?? F.empty(), this._charMapping = e?.charMapping, this._colorSource = e?.colorSource, this._cellColorSource = e?.cellColorSource, this._charSource = e?.charSource, this._nestedSources = e?.nestedSources ?? /* @__PURE__ */ new Map(), this._externalLayerRefs = e?.externalLayerRefs ?? /* @__PURE__ */ new Map();
359
358
  }
360
- addTransform(e, n) {
361
- const a = { name: e, userArgs: n };
359
+ addTransform(e, r) {
360
+ const a = { name: e, userArgs: r };
362
361
  return this._chain.push(a), this;
363
362
  }
364
- addCombineTransform(e, n, a) {
365
- const r = this._chain.length;
366
- return this._nestedSources.set(r, n), this.addTransform(e, a);
363
+ addCombineTransform(e, r, a) {
364
+ const n = this._chain.length;
365
+ return this._nestedSources.set(n, r), this.addTransform(e, a);
367
366
  }
368
367
  addExternalLayerRef(e) {
369
- const n = this._chain.length;
370
- return this._externalLayerRefs.set(n, e), this.addTransform("src", []);
368
+ const r = this._chain.length;
369
+ return this._externalLayerRefs.set(r, e), this.addTransform("src", []);
371
370
  }
372
371
  charMap(e) {
373
- const n = Array.from(e), a = [];
374
- for (const r of n) a.push(r.codePointAt(0) ?? 32);
372
+ const r = Array.from(e), a = [];
373
+ for (const n of r) a.push(n.codePointAt(0) ?? 32);
375
374
  return this._charMapping = { chars: e, indices: a }, this;
376
375
  }
377
376
  charColor(e) {
378
377
  return this._colorSource = e, this;
379
378
  }
380
- char(e, n) {
381
- return this._charSource = e, this._charCount = n, this;
379
+ char(e) {
380
+ return this._charSource = e, this;
382
381
  }
383
382
  cellColor(e) {
384
383
  return this._cellColorSource = e, this;
@@ -388,10 +387,10 @@ class b {
388
387
  }
389
388
  clone() {
390
389
  const e = /* @__PURE__ */ new Map();
391
- for (const [a, r] of this._nestedSources) e.set(a, r.clone());
392
- const n = /* @__PURE__ */ new Map();
393
- for (const [a, r] of this._externalLayerRefs) n.set(a, { ...r });
394
- return new b({ chain: w.from(this._chain.transforms), charMapping: this._charMapping, colorSource: this._colorSource?.clone(), cellColorSource: this._cellColorSource?.clone(), charSource: this._charSource?.clone(), charCount: this._charCount, nestedSources: e, externalLayerRefs: n });
390
+ for (const [a, n] of this._nestedSources) e.set(a, n.clone());
391
+ const r = /* @__PURE__ */ new Map();
392
+ for (const [a, n] of this._externalLayerRefs) r.set(a, { ...n });
393
+ return new S({ chain: F.from(this._chain.transforms), charMapping: this._charMapping, colorSource: this._colorSource?.clone(), cellColorSource: this._cellColorSource?.clone(), charSource: this._charSource?.clone(), nestedSources: e, externalLayerRefs: r });
395
394
  }
396
395
  get transforms() {
397
396
  return this._chain.transforms;
@@ -408,9 +407,6 @@ class b {
408
407
  get charSource() {
409
408
  return this._charSource;
410
409
  }
411
- get charCount() {
412
- return this._charCount;
413
- }
414
410
  get nestedSources() {
415
411
  return this._nestedSources;
416
412
  }
@@ -422,10 +418,10 @@ const I = { linear: (t) => t, easeInQuad: (t) => t * t, easeOutQuad: (t) => t *
422
418
  function T(t, e) {
423
419
  return (t % e + e) % e;
424
420
  }
425
- function Ke(t, e, n, a, r) {
426
- return (t - e) * (r - a) / (n - e) + a;
421
+ function We(t, e, r, a, n) {
422
+ return (t - e) * (n - a) / (r - e) + a;
427
423
  }
428
- function Qe() {
424
+ function Je() {
429
425
  "fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
430
426
  return this._speed = t, this;
431
427
  }, Array.prototype.smooth = function(t = 1) {
@@ -435,25 +431,25 @@ function Qe() {
435
431
  }, Array.prototype.offset = function(t = 0.5) {
436
432
  return this._offset = t % 1, this;
437
433
  }, Array.prototype.fit = function(t = 0, e = 1) {
438
- const n = Math.min(...this), a = Math.max(...this), r = this.map((o) => Ke(o, n, a, t, e));
439
- return r._speed = this._speed, r._smooth = this._smooth, r._ease = this._ease, r._offset = this._offset, r;
434
+ const r = Math.min(...this), a = Math.max(...this), n = this.map((o) => We(o, r, a, t, e));
435
+ return n._speed = this._speed, n._smooth = this._smooth, n._ease = this._ease, n._offset = this._offset, n;
440
436
  });
441
437
  }
442
- function He(t, e) {
443
- const n = t._speed ?? 1, a = t._smooth ?? 0;
444
- let r = e.time * n * (e.bpm / 60) + (t._offset ?? 0);
438
+ function Ze(t, e) {
439
+ const r = t._speed ?? 1, a = t._smooth ?? 0;
440
+ let n = e.time * r * (e.bpm / 60) + (t._offset ?? 0);
445
441
  if (a !== 0) {
446
- const o = t._ease ?? I.linear, c = r - a / 2, s = t[Math.floor(T(c, t.length))], l = t[Math.floor(T(c + 1, t.length))];
447
- return o(Math.min(T(c, 1) / a, 1)) * (l - s) + s;
442
+ const o = t._ease ?? I.linear, l = n - a / 2, s = t[Math.floor(T(l, t.length))], i = t[Math.floor(T(l + 1, t.length))];
443
+ return o(Math.min(T(l, 1) / a, 1)) * (i - s) + s;
448
444
  }
449
- return t[Math.floor(T(r, t.length))];
445
+ return t[Math.floor(T(n, t.length))];
450
446
  }
451
- function We(t) {
447
+ function et(t) {
452
448
  return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
453
449
  }
454
- Qe(), k.registerMany(Ge), P.setSynthSourceClass(b), P.injectMethods(b.prototype);
455
- const M = P.generateStandaloneFunctions(), C = "textmode.synth.js";
456
- class Je {
450
+ Je(), k.registerMany(He), P.setSynthSourceClass(S), P.injectMethods(S.prototype);
451
+ const $ = P.generateStandaloneFunctions(), b = "textmode.synth.js";
452
+ class tt {
457
453
  _usesFeedback = !1;
458
454
  _usesCharFeedback = !1;
459
455
  _usesCellColorFeedback = !1;
@@ -488,26 +484,26 @@ class Je {
488
484
  return this._usesCellColorFeedback;
489
485
  }
490
486
  }
491
- class Ze {
487
+ class rt {
492
488
  _externalLayers = /* @__PURE__ */ new Map();
493
489
  _counter = 0;
494
490
  _layerIdToPrefix = /* @__PURE__ */ new Map();
495
491
  getPrefix(e) {
496
- let n = this._layerIdToPrefix.get(e);
497
- return n || (n = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, n)), n;
492
+ let r = this._layerIdToPrefix.get(e);
493
+ return r || (r = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, r)), r;
498
494
  }
499
- trackUsage(e, n) {
495
+ trackUsage(e, r) {
500
496
  const a = this.getPrefix(e.layerId);
501
- let r = this._externalLayers.get(e.layerId);
502
- switch (r || (r = { layerId: e.layerId, uniformPrefix: a, usesChar: !1, usesCharColor: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, r)), n) {
497
+ let n = this._externalLayers.get(e.layerId);
498
+ switch (n || (n = { layerId: e.layerId, uniformPrefix: a, usesChar: !1, usesCharColor: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, n)), r) {
503
499
  case "char":
504
- r.usesChar = !0;
500
+ n.usesChar = !0;
505
501
  break;
506
502
  case "cellColor":
507
- r.usesCellColor = !0;
503
+ n.usesCellColor = !0;
508
504
  break;
509
505
  default:
510
- r.usesCharColor = !0;
506
+ n.usesCharColor = !0;
511
507
  }
512
508
  }
513
509
  hasLayer(e) {
@@ -529,86 +525,86 @@ class Ze {
529
525
  this._externalLayers.clear(), this._counter = 0, this._layerIdToPrefix.clear();
530
526
  }
531
527
  }
532
- const et = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
533
- class tt {
534
- getContextAwareGlslFunction(e, n, a, r, o) {
535
- return n !== "src" ? e.glslFunction : r && o ? this._generateExternalSrcFunction(r, a, o) : this._generateSelfFeedbackSrcFunction(a);
536
- }
537
- getFunctionName(e, n, a, r) {
538
- return e.name !== "src" ? e.name : a && r ? `src_ext_${r(a.layerId)}_${n}` : `src_${n}`;
539
- }
540
- generateTransformCode(e, n, a, r, o, c, s, l, m, d, p, v, h) {
541
- const u = this.getFunctionName(n, d, v, h), y = (..._) => [..._, ...m].join(", ");
542
- let i = o, f = c, g = s, F = l;
543
- switch (n.type) {
528
+ const nt = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
529
+ class at {
530
+ getContextAwareGlslFunction(e, r, a, n, o) {
531
+ return r !== "src" ? e.glslFunction : n && o ? this._generateExternalSrcFunction(n, a, o) : this._generateSelfFeedbackSrcFunction(a);
532
+ }
533
+ getFunctionName(e, r, a, n) {
534
+ return e.name !== "src" ? e.name : a && n ? `src_ext_${n(a.layerId)}_${r}` : `src_${r}`;
535
+ }
536
+ generateTransformCode(e, r, a, n, o, l, s, i, m, h, y, d, v) {
537
+ const p = this.getFunctionName(r, h, d, v), f = (...u) => [...u, ...m].join(", ");
538
+ let c = o, g = l, _ = s, C = i;
539
+ switch (r.type) {
544
540
  case "src": {
545
- const _ = `c${a}`;
546
- e.push(` vec4 ${_} = ${u}(${y(r)});`), i = _;
541
+ const u = `c${a}`;
542
+ e.push(` vec4 ${u} = ${p}(${f(n)});`), c = u;
547
543
  break;
548
544
  }
549
545
  case "coord": {
550
- const _ = `st${a}`;
551
- e.push(` vec2 ${_} = ${u}(${y(r)});`), e.push(` ${r} = ${_};`);
546
+ const u = `st${a}`;
547
+ e.push(` vec2 ${u} = ${p}(${f(n)});`), e.push(` ${n} = ${u};`);
552
548
  break;
553
549
  }
554
550
  case "color": {
555
- const _ = `c${a}`;
556
- e.push(` vec4 ${_} = ${u}(${y(o)});`), i = _;
551
+ const u = `c${a}`;
552
+ e.push(` vec4 ${u} = ${p}(${f(o)});`), c = u;
557
553
  break;
558
554
  }
559
555
  case "combine": {
560
- const _ = `c${a}`;
561
- e.push(` vec4 ${_} = ${u}(${y(o, p ?? "vec4(0.0)")});`), i = _;
556
+ const u = `c${a}`;
557
+ e.push(` vec4 ${u} = ${p}(${f(o, y ?? "vec4(0.0)")});`), c = u;
562
558
  break;
563
559
  }
564
560
  case "combineCoord": {
565
- const _ = `st${a}`;
566
- e.push(` vec2 ${_} = ${u}(${y(r, p ?? "vec4(0.0)")});`), e.push(` ${r} = ${_};`);
561
+ const u = `st${a}`;
562
+ e.push(` vec2 ${u} = ${p}(${f(n, y ?? "vec4(0.0)")});`), e.push(` ${n} = ${u};`);
567
563
  break;
568
564
  }
569
565
  }
570
- return { colorVar: i, charVar: f, flagsVar: g, rotationVar: F };
566
+ return { colorVar: c, charVar: g, flagsVar: _, rotationVar: C };
571
567
  }
572
- _generateExternalSrcFunction(e, n, a) {
573
- const r = a(e.layerId);
568
+ _generateExternalSrcFunction(e, r, a) {
569
+ const n = a(e.layerId);
574
570
  return `
575
- vec4 ${`src_ext_${r}_${n}`}(vec2 _st) {
576
- return texture(${{ char: `${r}_char`, charColor: `${r}_primary`, cellColor: `${r}_cell`, main: `${r}_primary` }[n]}, fract(_st));
571
+ vec4 ${`src_ext_${n}_${r}`}(vec2 _st) {
572
+ return texture(${{ char: `${n}_char`, charColor: `${n}_primary`, cellColor: `${n}_cell`, main: `${n}_primary` }[r]}, fract(_st));
577
573
  }
578
574
  `;
579
575
  }
580
576
  _generateSelfFeedbackSrcFunction(e) {
581
577
  return `
582
578
  vec4 ${`src_${e}`}(vec2 _st) {
583
- return texture(${et[e]}, fract(_st));
579
+ return texture(${nt[e]}, fract(_st));
584
580
  }
585
581
  `;
586
582
  }
587
583
  }
588
- class nt {
584
+ class ot {
589
585
  _uniforms = /* @__PURE__ */ new Map();
590
586
  _dynamicUpdaters = /* @__PURE__ */ new Map();
591
- processArgument(e, n, a) {
592
- if (We(e)) {
593
- const r = `${a}_${n.name}`, o = { name: r, type: n.type, value: n.default ?? 0, isDynamic: !0 }, c = (s) => He(e, s);
594
- return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, c), { glslValue: r, uniform: o, updater: c };
587
+ processArgument(e, r, a) {
588
+ if (et(e)) {
589
+ const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 }, l = (s) => Ze(e, s);
590
+ return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, l), { glslValue: n, uniform: o, updater: l };
595
591
  }
596
592
  if (typeof e == "function") {
597
- const r = `${a}_${n.name}`, o = { name: r, type: n.type, value: n.default ?? 0, isDynamic: !0 };
598
- return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, e), { glslValue: r, uniform: o, updater: e };
593
+ const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 };
594
+ return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, e), { glslValue: n, uniform: o, updater: e };
599
595
  }
600
596
  if (typeof e == "number") return { glslValue: x(e) };
601
597
  if (Array.isArray(e) && typeof e[0] == "number") {
602
- const r = e;
603
- if (r.length === 2) return { glslValue: `vec2(${x(r[0])}, ${x(r[1])})` };
604
- if (r.length === 3) return { glslValue: `vec3(${x(r[0])}, ${x(r[1])}, ${x(r[2])})` };
605
- if (r.length === 4) return { glslValue: `vec4(${x(r[0])}, ${x(r[1])}, ${x(r[2])}, ${x(r[3])})` };
598
+ const n = e;
599
+ if (n.length === 2) return { glslValue: `vec2(${x(n[0])}, ${x(n[1])})` };
600
+ if (n.length === 3) return { glslValue: `vec3(${x(n[0])}, ${x(n[1])}, ${x(n[2])})` };
601
+ if (n.length === 4) return { glslValue: `vec4(${x(n[0])}, ${x(n[1])}, ${x(n[2])}, ${x(n[3])})` };
606
602
  }
607
- return this.processDefault(n);
603
+ return this.processDefault(r);
608
604
  }
609
605
  processDefault(e) {
610
- const n = e.default;
611
- return typeof n == "number" ? { glslValue: x(n) } : Array.isArray(n) ? { glslValue: `vec${n.length}(${n.map(x).join(", ")})` } : { glslValue: "0.0" };
606
+ const r = e.default;
607
+ return typeof r == "number" ? { glslValue: x(r) } : Array.isArray(r) ? { glslValue: `vec${r.length}(${r.map(x).join(", ")})` } : { glslValue: "0.0" };
612
608
  }
613
609
  getUniforms() {
614
610
  return new Map(this._uniforms);
@@ -624,7 +620,7 @@ function x(t) {
624
620
  const e = t.toString();
625
621
  return e.includes(".") ? e : e + ".0";
626
622
  }
627
- const rt = `
623
+ const st = `
628
624
  // Utility functions
629
625
  float _luminance(vec3 rgb) {
630
626
  const vec3 W = vec3(0.2125, 0.7154, 0.0721);
@@ -721,22 +717,22 @@ float _noise(vec3 v) {
721
717
  return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
722
718
  }
723
719
  `;
724
- function at(t) {
725
- const { uniforms: e, glslFunctions: n, mainCode: a, charOutputCode: r, primaryColorVar: o, cellColorVar: c, charMapping: s, usesFeedback: l, usesCharFeedback: m, usesCellColorFeedback: d, externalLayers: p } = t, v = Array.from(e.values()).map((g) => `uniform ${g.type} ${g.name};`).join(`
720
+ function ct(t) {
721
+ const { uniforms: e, glslFunctions: r, mainCode: a, charOutputCode: n, primaryColorVar: o, cellColorVar: l, charMapping: s, usesFeedback: i, usesCharFeedback: m, usesCellColorFeedback: h, usesCharSource: y, externalLayers: d } = t, v = Array.from(e.values()).map((u) => `uniform ${u.type} ${u.name};`).join(`
726
722
  `);
727
- let h = "", u = "";
728
- s && (h = `uniform int u_charMap[${s.indices.length}];
729
- uniform int u_charMapSize;`, u = `
723
+ let p = "", f = "";
724
+ s && (p = `uniform int u_charMap[${s.indices.length}];
725
+ uniform int u_charMapSize;`, f = `
730
726
  // Apply character mapping
731
727
  int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
732
728
  int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
733
729
  charOutput.r = float(mappedCharIdx % 256) / 255.0;
734
730
  charOutput.g = float(mappedCharIdx / 256) / 255.0;`);
735
- const y = [];
736
- l && y.push("uniform sampler2D prevCharColorBuffer;"), m && y.push("uniform sampler2D prevCharBuffer;"), d && y.push("uniform sampler2D prevCellColorBuffer;");
737
- const i = y.join(`
738
- `), f = [];
739
- if (p) for (const [, g] of p) g.usesChar && f.push(`uniform sampler2D ${g.uniformPrefix}_char;`), g.usesCharColor && f.push(`uniform sampler2D ${g.uniformPrefix}_primary;`), g.usesCellColor && f.push(`uniform sampler2D ${g.uniformPrefix}_cell;`);
731
+ const c = [];
732
+ i && c.push("uniform sampler2D prevCharColorBuffer;"), m && c.push("uniform sampler2D prevCharBuffer;"), h && c.push("uniform sampler2D prevCellColorBuffer;");
733
+ const g = c.join(`
734
+ `), _ = y ? "uniform float u_charSourceCount;" : "", C = [];
735
+ if (d) for (const [, u] of d) u.usesChar && C.push(`uniform sampler2D ${u.uniformPrefix}_char;`), u.usesCharColor && C.push(`uniform sampler2D ${u.uniformPrefix}_primary;`), u.usesCellColor && C.push(`uniform sampler2D ${u.uniformPrefix}_cell;`);
740
736
  return `#version 300 es
741
737
  precision highp float;
742
738
 
@@ -751,19 +747,20 @@ layout(location = 2) out vec4 o_secondaryColor;
751
747
  // Standard uniforms
752
748
  uniform float time;
753
749
  uniform vec2 resolution;
754
- ${i}
755
- ${f.length > 0 ? `// External layer samplers
756
- ${f.join(`
750
+ ${g}
751
+ ${C.length > 0 ? `// External layer samplers
752
+ ${C.join(`
757
753
  `)}` : ""}
758
- ${h}
754
+ ${p}
755
+ ${_}
759
756
 
760
757
  // Dynamic uniforms
761
758
  ${v}
762
759
 
763
- ${rt}
760
+ ${st}
764
761
 
765
762
  // Transform functions
766
- ${Array.from(n).join(`
763
+ ${Array.from(r).join(`
767
764
  `)}
768
765
 
769
766
  void main() {
@@ -771,89 +768,91 @@ void main() {
771
768
  ${a.join(`
772
769
  `)}
773
770
 
774
- ${r}
775
- ${u}
771
+ ${n}
772
+ ${f}
776
773
 
777
774
  // Output to MRT
778
775
  o_character = charOutput;
779
776
  o_primaryColor = ${o};
780
- o_secondaryColor = ${c};
777
+ o_secondaryColor = ${l};
781
778
  }
782
779
  `;
783
780
  }
784
- function ot(t, e, n) {
781
+ function lt(t, e, r) {
785
782
  return t ? `
786
783
  // Character output from generator
787
784
  vec4 charOutput = ${e};` : `
788
785
  // Derive character from color luminance
789
- float lum = _luminance(${n}.rgb);
786
+ float lum = _luminance(${r}.rgb);
790
787
  int charIdx = int(lum * 255.0);
791
788
  vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`;
792
789
  }
793
- function R(t) {
794
- return new st().compile(t);
790
+ function A(t) {
791
+ return new it().compile(t);
795
792
  }
796
- class st {
797
- _uniformManager = new nt();
798
- _feedbackTracker = new Je();
799
- _externalLayerManager = new Ze();
800
- _codeGenerator = new tt();
793
+ class it {
794
+ _uniformManager = new ot();
795
+ _feedbackTracker = new tt();
796
+ _externalLayerManager = new rt();
797
+ _codeGenerator = new at();
801
798
  _glslFunctions = /* @__PURE__ */ new Set();
802
799
  _mainCode = [];
803
800
  _varCounter = 0;
804
801
  _currentTarget = "main";
802
+ _usesCharSource = !1;
805
803
  compile(e) {
806
804
  this._reset();
807
- const n = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
808
- let a = n.charVar;
805
+ const r = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
806
+ let a = r.charVar;
809
807
  e.charSource && (a = this._compileCharSource(e));
810
- let r = n.colorVar;
811
- e.colorSource && (r = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
808
+ let n = r.colorVar;
809
+ e.colorSource && (n = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
812
810
  let o = "vec4(0.0, 0.0, 0.0, 0.0)";
813
811
  e.cellColorSource && (o = this._compileChain(e.cellColorSource, "cellColor", "vec4(0.0, 0.0, 0.0, 0.0)", "v_uv", "cellColor").colorVar);
814
- const c = ot(!!a, a ?? "vec4(0.0)", n.colorVar), s = this._feedbackTracker.getUsage();
815
- return { fragmentSource: at({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: c, primaryColorVar: r, cellColorVar: o, charMapping: e.charMapping, usesFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, externalLayers: this._externalLayerManager.getExternalLayers() }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesCharColorFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, externalLayers: this._externalLayerManager.getExternalLayers() };
812
+ const l = lt(!!a, a ?? "vec4(0.0)", r.colorVar), s = this._feedbackTracker.getUsage();
813
+ return { fragmentSource: ct({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: l, primaryColorVar: n, cellColorVar: o, charMapping: e.charMapping, usesFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesCharColorFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() };
816
814
  }
817
815
  _reset() {
818
- this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main";
816
+ this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main", this._usesCharSource = !1;
819
817
  }
820
818
  _compileCharSource(e) {
821
- const n = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char"), a = "charFromSource_" + this._varCounter++, r = e.charCount ?? 256;
822
- return this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${a} = _luminance(${n.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * ${r.toFixed(1)});`), this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`), a;
819
+ this._usesCharSource = !0;
820
+ const r = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char"), a = "charFromSource_" + this._varCounter++;
821
+ return this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${a} = _luminance(${r.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * u_charSourceCount);`), this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`), a;
823
822
  }
824
- _compileChain(e, n, a, r = "v_uv", o = "main") {
825
- const c = this._currentTarget;
823
+ _compileChain(e, r, a, n = "v_uv", o = "main") {
824
+ const l = this._currentTarget;
826
825
  this._currentTarget = o;
827
- const s = `${n}_st`;
828
- let l, m, d, p = `${n}_c`;
829
- this._mainCode.push(` vec2 ${s} = ${r};`), this._mainCode.push(` vec4 ${p} = ${a};`);
830
- const v = e.transforms, h = v.map((i) => this._getProcessedTransform(i.name)), u = this._identifyCoordTransforms(h), y = (i) => {
831
- const f = v[i], g = h[i];
832
- if (!g) return void console.warn(`[SynthCompiler] Unknown transform: ${f.name}`);
833
- const F = e.externalLayerRefs.get(i);
834
- f.name === "src" && this._trackSrcUsage(F);
835
- const _ = this._codeGenerator.getContextAwareGlslFunction(g, f.name, this._currentTarget, F, (L) => this._externalLayerManager.getPrefix(L));
836
- this._glslFunctions.add(_);
837
- const V = this._processArguments(f.userArgs, g.inputs, `${n}_${i}_${f.name}`), A = e.nestedSources.get(i);
826
+ const s = `${r}_st`;
827
+ let i, m, h, y = `${r}_c`;
828
+ this._mainCode.push(` vec2 ${s} = ${n};`), this._mainCode.push(` vec4 ${y} = ${a};`);
829
+ const d = e.transforms, v = d.map((c) => this._getProcessedTransform(c.name)), p = this._identifyCoordTransforms(v), f = (c) => {
830
+ const g = d[c], _ = v[c];
831
+ if (!_) return void console.warn(`[SynthCompiler] Unknown transform: ${g.name}`);
832
+ const C = e.externalLayerRefs.get(c);
833
+ g.name === "src" && this._trackSrcUsage(C);
834
+ const u = this._codeGenerator.getContextAwareGlslFunction(_, g.name, this._currentTarget, C, (L) => this._externalLayerManager.getPrefix(L));
835
+ this._glslFunctions.add(u);
836
+ const Y = this._processArguments(g.userArgs, _.inputs, `${r}_${c}_${g.name}`), R = e.nestedSources.get(c);
838
837
  let z;
839
- A && (g.type === "combine" || g.type === "combineCoord") && (z = this._compileChain(A, `${n}_nested_${i}`, a, s, o).colorVar);
840
- const S = this._codeGenerator.generateTransformCode(this._mainCode, g, this._varCounter++, s, p, l, m, d, V, this._currentTarget, z, F, (L) => this._externalLayerManager.getPrefix(L));
841
- p = S.colorVar, S.charVar && (l = S.charVar), S.flagsVar && (m = S.flagsVar), S.rotationVar && (d = S.rotationVar);
838
+ R && (_.type === "combine" || _.type === "combineCoord") && (z = this._compileChain(R, `${r}_nested_${c}`, a, s, o).colorVar);
839
+ const M = this._codeGenerator.generateTransformCode(this._mainCode, _, this._varCounter++, s, y, i, m, h, Y, this._currentTarget, z, C, (L) => this._externalLayerManager.getPrefix(L));
840
+ y = M.colorVar, M.charVar && (i = M.charVar), M.flagsVar && (m = M.flagsVar), M.rotationVar && (h = M.rotationVar);
842
841
  };
843
- for (let i = u.length - 1; i >= 0; i--) y(u[i]);
844
- for (let i = 0; i < v.length; i++) {
845
- const f = h[i];
846
- (!f || f.type !== "coord" && f.type !== "combineCoord") && y(i);
842
+ for (let c = p.length - 1; c >= 0; c--) f(p[c]);
843
+ for (let c = 0; c < d.length; c++) {
844
+ const g = v[c];
845
+ (!g || g.type !== "coord" && g.type !== "combineCoord") && f(c);
847
846
  }
848
- return this._currentTarget = c, { coordVar: s, colorVar: p, charVar: l, flagsVar: m, rotationVar: d };
847
+ return this._currentTarget = l, { coordVar: s, colorVar: y, charVar: i, flagsVar: m, rotationVar: h };
849
848
  }
850
849
  _identifyCoordTransforms(e) {
851
- const n = [];
850
+ const r = [];
852
851
  for (let a = 0; a < e.length; a++) {
853
- const r = e[a];
854
- r && (r.type !== "coord" && r.type !== "combineCoord" || n.push(a));
852
+ const n = e[a];
853
+ n && (n.type !== "coord" && n.type !== "combineCoord" || r.push(a));
855
854
  }
856
- return n;
855
+ return r;
857
856
  }
858
857
  _trackSrcUsage(e) {
859
858
  e ? this._externalLayerManager.trackUsage(e, this._currentTarget) : this._feedbackTracker.trackUsage(this._currentTarget);
@@ -861,29 +860,29 @@ class st {
861
860
  _getProcessedTransform(e) {
862
861
  return k.getProcessed(e);
863
862
  }
864
- _processArguments(e, n, a) {
865
- const r = [];
866
- for (let o = 0; o < n.length; o++) {
867
- const c = n[o], s = e[o] ?? c.default, l = this._uniformManager.processArgument(s, c, a);
868
- r.push(l.glslValue);
863
+ _processArguments(e, r, a) {
864
+ const n = [];
865
+ for (let o = 0; o < r.length; o++) {
866
+ const l = r[o], s = e[o] ?? l.default, i = this._uniformManager.processArgument(s, l, a);
867
+ n.push(i.glslValue);
869
868
  }
870
- return r;
869
+ return n;
871
870
  }
872
871
  }
873
- class ct {
872
+ class ut {
874
873
  _resolvedIndices;
875
874
  _lastFontCharacterCount = 0;
876
875
  _lastChars = "";
877
- resolve(e, n) {
878
- const a = n.characters.length;
876
+ resolve(e, r) {
877
+ const a = r.characters.length;
879
878
  if (this._resolvedIndices && this._lastFontCharacterCount === a && this._lastChars === e) return this._resolvedIndices;
880
- const r = Array.from(e), o = new Int32Array(r.length), c = n.characterMap, s = n.characters;
881
- for (let l = 0; l < r.length; l++) {
882
- const m = r[l], d = c.get(m);
883
- if (d !== void 0) o[l] = s.indexOf(d);
879
+ const n = Array.from(e), o = new Int32Array(n.length), l = r.characterMap, s = r.characters;
880
+ for (let i = 0; i < n.length; i++) {
881
+ const m = n[i], h = l.get(m);
882
+ if (h !== void 0) o[i] = s.indexOf(h);
884
883
  else {
885
- const p = c.get(" ");
886
- o[l] = p !== void 0 ? s.indexOf(p) : 0;
884
+ const y = l.get(" ");
885
+ o[i] = y !== void 0 ? s.indexOf(y) : 0;
887
886
  }
888
887
  }
889
888
  return this._resolvedIndices = o, this._lastFontCharacterCount = a, this._lastChars = e, o;
@@ -892,157 +891,203 @@ class ct {
892
891
  this._resolvedIndices = void 0, this._lastFontCharacterCount = 0, this._lastChars = "";
893
892
  }
894
893
  }
895
- function U(t = {}) {
896
- return { source: t.source ?? new b(), compiled: t.compiled, shader: t.shader, characterResolver: t.characterResolver ?? new ct(), needsCompile: t.needsCompile ?? !1, pingPongBuffers: t.pingPongBuffers, pingPongIndex: t.pingPongIndex ?? 0, externalLayerMap: t.externalLayerMap, bpm: t.bpm };
894
+ function V(t = {}) {
895
+ return { source: t.source ?? new S(), compiled: t.compiled, shader: t.shader, characterResolver: t.characterResolver ?? new ut(), needsCompile: t.needsCompile ?? !1, pingPongBuffers: t.pingPongBuffers, pingPongIndex: t.pingPongIndex ?? 0, externalLayerMap: t.externalLayerMap, bpm: t.bpm };
897
896
  }
898
- function lt(t) {
897
+ function ft(t) {
899
898
  t.extendLayer("synth", function(e) {
900
- const n = this.grid !== void 0 && this.drawFramebuffer !== void 0;
901
- let a = this.getPluginState(C);
902
- a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(), n && (a.compiled = R(e))) : a = U({ source: e, compiled: n ? R(e) : void 0, needsCompile: !0 }), this.setPluginState(C, a);
899
+ const r = this.grid !== void 0 && this.drawFramebuffer !== void 0;
900
+ let a = this.getPluginState(b);
901
+ a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(), r && (a.compiled = A(e))) : a = V({ source: e, compiled: r ? A(e) : void 0, needsCompile: !0 }), this.setPluginState(b, a);
903
902
  });
904
903
  }
905
- function it(t) {
904
+ function pt(t) {
906
905
  t.extendLayer("clearSynth", function() {
907
- const e = this.getPluginState(C);
908
- e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(C, void 0));
906
+ const e = this.getPluginState(b);
907
+ e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(b, void 0));
909
908
  });
910
909
  }
911
- function ut(t) {
910
+ function mt(t) {
912
911
  t.extendLayer("bpm", function(e) {
913
- let n = this.getPluginState(C);
914
- n ? n.bpm = e : n = U({ bpm: e }), this.setPluginState(C, n);
912
+ let r = this.getPluginState(b);
913
+ r ? r.bpm = e : r = V({ bpm: e }), this.setPluginState(b, r);
915
914
  });
916
915
  }
917
- let B = 60;
918
- function ft(t) {
919
- B = t;
916
+ let E = 60;
917
+ function dt(t) {
918
+ E = t;
920
919
  }
921
- function pt() {
922
- return B;
920
+ function ht() {
921
+ return E;
923
922
  }
924
- function mt(t) {
923
+ function yt(t) {
925
924
  t.bpm = function(e) {
926
- return ft(e), e;
925
+ return dt(e), e;
927
926
  };
928
927
  }
929
- function $(t) {
928
+ function w(t) {
930
929
  const e = /* @__PURE__ */ new Map();
931
- for (const [, n] of t.externalLayerRefs) e.set(n.layerId, n.layer);
932
- for (const [, n] of t.nestedSources) {
933
- const a = $(n);
934
- for (const [r, o] of a) e.set(r, o);
930
+ for (const [, r] of t.externalLayerRefs) e.set(r.layerId, r.layer);
931
+ for (const [, r] of t.nestedSources) {
932
+ const a = w(r);
933
+ for (const [n, o] of a) e.set(n, o);
935
934
  }
936
935
  if (t.charSource) {
937
- const n = $(t.charSource);
938
- for (const [a, r] of n) e.set(a, r);
936
+ const r = w(t.charSource);
937
+ for (const [a, n] of r) e.set(a, n);
939
938
  }
940
939
  if (t.colorSource) {
941
- const n = $(t.colorSource);
942
- for (const [a, r] of n) e.set(a, r);
940
+ const r = w(t.colorSource);
941
+ for (const [a, n] of r) e.set(a, n);
943
942
  }
944
943
  if (t.cellColorSource) {
945
- const n = $(t.cellColorSource);
946
- for (const [a, r] of n) e.set(a, r);
944
+ const r = w(t.cellColorSource);
945
+ for (const [a, n] of r) e.set(a, n);
947
946
  }
948
947
  return e;
949
948
  }
950
- async function dt(t, e) {
951
- const n = t.getPluginState(C);
952
- if (!n) return;
953
- const a = t.grid, r = t.drawFramebuffer;
954
- if (!a || !r || (n.compiled || (n.compiled = R(n.source), n.externalLayerMap = $(n.source), n.needsCompile = !0), n.needsCompile && n.compiled && (n.shader?.dispose && n.shader.dispose(), n.externalLayerMap = $(n.source), n.shader = await e.createFilterShader(n.compiled.fragmentSource), n.needsCompile = !1), !n.shader || !n.compiled)) return;
955
- const o = n.compiled.usesCharColorFeedback, c = n.compiled.usesCharFeedback, s = n.compiled.usesCellColorFeedback, l = o || c || s;
956
- l && !n.pingPongBuffers && (n.pingPongBuffers = [e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 }), e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 })], n.pingPongIndex = 0);
957
- const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm: n.bpm ?? pt() }, d = (p) => {
949
+ let B = null;
950
+ function Ct(t) {
951
+ B = t;
952
+ }
953
+ function U(t, e, r) {
954
+ const a = r ?? B;
955
+ if (a) try {
956
+ a(t, e);
957
+ } catch {
958
+ }
959
+ }
960
+ function gt(t, e, r, a = {}) {
961
+ let n;
962
+ try {
963
+ n = t();
964
+ } catch (o) {
965
+ return U(o, e, a.onError), r;
966
+ }
967
+ return _t(n) ? n : (U(new Error(`[textmode.synth.js] Invalid dynamic parameter value for "${e}": ${N(n)}`), e, a.onError), r);
968
+ }
969
+ function N(t) {
970
+ if (t === void 0) return "undefined";
971
+ if (t === null) return "null";
972
+ if (typeof t == "number") {
973
+ if (Number.isNaN(t)) return "NaN";
974
+ if (!Number.isFinite(t)) return t > 0 ? "Infinity" : "-Infinity";
975
+ }
976
+ if (Array.isArray(t)) {
977
+ const e = t.findIndex((r) => typeof r != "number" || !Number.isFinite(r));
978
+ if (e >= 0) return `array with invalid element at index ${e}: ${N(t[e])}`;
979
+ }
980
+ return String(t);
981
+ }
982
+ function _t(t) {
983
+ return t != null && (typeof t == "number" ? Number.isFinite(t) : !!Array.isArray(t) && t.length > 0 && t.every((e) => typeof e == "number" && Number.isFinite(e)));
984
+ }
985
+ async function vt(t, e) {
986
+ const r = t.getPluginState(b);
987
+ if (!r) return;
988
+ const a = t.grid, n = t.drawFramebuffer;
989
+ if (!a || !n || (r.compiled || (r.compiled = A(r.source), r.externalLayerMap = w(r.source), r.needsCompile = !0), r.needsCompile && r.compiled && (r.shader?.dispose && r.shader.dispose(), r.externalLayerMap = w(r.source), r.shader = await e.createFilterShader(r.compiled.fragmentSource), r.needsCompile = !1), !r.shader || !r.compiled)) return;
990
+ const o = r.compiled.usesCharColorFeedback, l = r.compiled.usesCharFeedback, s = r.compiled.usesCellColorFeedback, i = o || l || s;
991
+ i && !r.pingPongBuffers && (r.pingPongBuffers = [e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 }), e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 })], r.pingPongIndex = 0);
992
+ const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm: r.bpm ?? ht() }, h = /* @__PURE__ */ new Map();
993
+ for (const [d, v] of r.compiled.dynamicUpdaters) {
994
+ const p = r.compiled.uniforms.get(d), f = gt(() => v(m), d, p?.value ?? 0, { onError: r.onDynamicError });
995
+ h.set(d, f);
996
+ }
997
+ const y = (d) => {
958
998
  e.setUniform("time", e.secs), e.setUniform("resolution", [m.cols, m.rows]);
959
- for (const [h, u] of n.compiled.dynamicUpdaters) e.setUniform(h, u(m));
960
- for (const [h, u] of n.compiled.uniforms) u.isDynamic || typeof u.value == "function" || e.setUniform(h, u.value);
961
- if (n.compiled.charMapping) {
962
- const h = n.characterResolver.resolve(n.compiled.charMapping.chars, t.font);
963
- e.setUniform("u_charMap", h), e.setUniform("u_charMapSize", h.length);
999
+ for (const [p, f] of h) e.setUniform(p, f);
1000
+ for (const [p, f] of r.compiled.uniforms) f.isDynamic || typeof f.value == "function" || e.setUniform(p, f.value);
1001
+ if (r.compiled.charMapping) {
1002
+ const p = r.characterResolver.resolve(r.compiled.charMapping.chars, t.font);
1003
+ e.setUniform("u_charMap", p), e.setUniform("u_charMapSize", p.length);
1004
+ }
1005
+ if (r.compiled.usesCharSource) {
1006
+ const p = r.compiled.charMapping ? r.compiled.charMapping.chars.length : t.font.characters.length;
1007
+ e.setUniform("u_charSourceCount", p);
964
1008
  }
965
- p && (o && e.setUniform("prevCharColorBuffer", p.textures[1]), c && e.setUniform("prevCharBuffer", p.textures[0]), s && e.setUniform("prevCellColorBuffer", p.textures[2]));
966
- const v = n.compiled.externalLayers;
967
- if (v && v.size > 0 && n.externalLayerMap) for (const [h, u] of v) {
968
- const y = n.externalLayerMap.get(h);
969
- if (!y) {
970
- console.warn(`[textmode.synth.js] External layer not found: ${h}`);
1009
+ d && (o && e.setUniform("prevCharColorBuffer", d.textures[1]), l && e.setUniform("prevCharBuffer", d.textures[0]), s && e.setUniform("prevCellColorBuffer", d.textures[2]));
1010
+ const v = r.compiled.externalLayers;
1011
+ if (v && v.size > 0 && r.externalLayerMap) for (const [p, f] of v) {
1012
+ const c = r.externalLayerMap.get(p);
1013
+ if (!c) {
1014
+ console.warn(`[textmode.synth.js] External layer not found: ${p}`);
971
1015
  continue;
972
1016
  }
973
- const i = y.getPluginState(C);
974
- let f;
975
- i?.pingPongBuffers ? f = i.pingPongBuffers[i.pingPongIndex].textures : y.drawFramebuffer && (f = y.drawFramebuffer.textures), f && (u.usesChar && e.setUniform(`${u.uniformPrefix}_char`, f[0]), u.usesCharColor && e.setUniform(`${u.uniformPrefix}_primary`, f[1]), u.usesCellColor && e.setUniform(`${u.uniformPrefix}_cell`, f[2]));
1017
+ const g = c.getPluginState(b);
1018
+ let _;
1019
+ g?.pingPongBuffers ? _ = g.pingPongBuffers[g.pingPongIndex].textures : c.drawFramebuffer && (_ = c.drawFramebuffer.textures), _ && (f.usesChar && e.setUniform(`${f.uniformPrefix}_char`, _[0]), f.usesCharColor && e.setUniform(`${f.uniformPrefix}_primary`, _[1]), f.usesCellColor && e.setUniform(`${f.uniformPrefix}_cell`, _[2]));
976
1020
  }
977
1021
  };
978
- if (l && n.pingPongBuffers) {
979
- const p = n.pingPongBuffers[n.pingPongIndex], v = n.pingPongBuffers[1 - n.pingPongIndex];
980
- v.begin(), e.clear(), e.shader(n.shader), d(p), e.rect(a.cols, a.rows), v.end(), r.begin(), e.clear(), e.shader(n.shader), d(p), e.rect(a.cols, a.rows), r.end(), n.pingPongIndex = 1 - n.pingPongIndex;
981
- } else r.begin(), e.clear(), e.shader(n.shader), d(null), e.rect(a.cols, a.rows), r.end();
1022
+ if (i && r.pingPongBuffers) {
1023
+ const d = r.pingPongBuffers[r.pingPongIndex], v = r.pingPongBuffers[1 - r.pingPongIndex];
1024
+ v.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), v.end(), n.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), n.end(), r.pingPongIndex = 1 - r.pingPongIndex;
1025
+ } else n.begin(), e.clear(), e.shader(r.shader), y(null), e.rect(a.cols, a.rows), n.end();
982
1026
  }
983
- function ht(t) {
984
- const e = t.getPluginState(C);
1027
+ function xt(t) {
1028
+ const e = t.getPluginState(b);
985
1029
  e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()));
986
1030
  }
987
- const yt = { name: C, version: "1.0.0", install(t, e) {
988
- mt(t), lt(e), ut(e), it(e), e.registerLayerPreRenderHook((n) => dt(n, t)), e.registerLayerDisposedHook(ht);
1031
+ const bt = { name: b, version: "1.0.0", install(t, e) {
1032
+ yt(t), ft(e), mt(e), pt(e), e.registerLayerPreRenderHook((r) => vt(r, t)), e.registerLayerDisposedHook(xt);
989
1033
  }, uninstall(t, e) {
990
- const n = [e.layerManager.base, ...e.layerManager.all];
991
- for (const a of n) {
992
- const r = a.getPluginState(C);
993
- r && (r.shader?.dispose && r.shader.dispose(), r.pingPongBuffers && (r.pingPongBuffers[0].dispose?.(), r.pingPongBuffers[1].dispose?.()));
1034
+ const r = [e.layerManager.base, ...e.layerManager.all];
1035
+ for (const a of r) {
1036
+ const n = a.getPluginState(b);
1037
+ n && (n.shader?.dispose && n.shader.dispose(), n.pingPongBuffers && (n.pingPongBuffers[0].dispose?.(), n.pingPongBuffers[1].dispose?.()));
994
1038
  }
995
1039
  delete t.bpm, e.removeLayerExtension("synth"), e.removeLayerExtension("bpm"), e.removeLayerExtension("clearSynth");
996
- } }, gt = (t) => {
997
- const e = new b();
1040
+ } }, St = (t) => {
1041
+ const e = new S();
998
1042
  return e._colorSource = t, e;
999
- }, _t = (t, e) => {
1000
- const n = new b();
1001
- return n._charSource = t, n._charCount = e, n;
1002
- }, vt = (t) => {
1003
- const e = new b();
1043
+ }, Mt = (t, e) => {
1044
+ const r = new S();
1045
+ return r._charSource = t, r._charCount = e, r;
1046
+ }, $t = (t) => {
1047
+ const e = new S();
1004
1048
  return e._colorSource = t, e;
1005
1049
  };
1006
- function xt(t) {
1007
- return M.gradient(t);
1050
+ function wt(t) {
1051
+ return $.gradient(t);
1008
1052
  }
1009
- function Ct(t, e) {
1010
- return M.noise(t, e);
1053
+ function Ft(t, e) {
1054
+ return $.noise(t, e);
1011
1055
  }
1012
- function bt(t, e, n) {
1013
- return M.osc(t, e, n);
1056
+ function kt(t, e, r) {
1057
+ return $.osc(t, e, r);
1014
1058
  }
1015
- const St = (t) => {
1016
- const e = new b();
1059
+ const Tt = (t) => {
1060
+ const e = new S();
1017
1061
  return e._colorSource = t, e._cellColorSource = t, e;
1018
1062
  };
1019
- function Mt(t, e, n) {
1020
- return M.shape(t, e, n);
1063
+ function Lt(t, e, r) {
1064
+ return $.shape(t, e, r);
1021
1065
  }
1022
- function $t(t, e, n, a) {
1023
- return M.solid(t, e, n, a);
1066
+ function Pt(t, e, r, a) {
1067
+ return $.solid(t, e, r, a);
1024
1068
  }
1025
- const wt = (t) => {
1026
- const e = M.src;
1069
+ const It = (t) => {
1070
+ const e = $.src;
1027
1071
  if (!t) return e();
1028
- const n = new b(), a = t.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
1029
- return n.addExternalLayerRef({ layerId: a, layer: t }), n;
1072
+ const r = new S(), a = t.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
1073
+ return r.addExternalLayerRef({ layerId: a, layer: t }), r;
1030
1074
  };
1031
- function Ft(t, e, n) {
1032
- return M.voronoi(t, e, n);
1075
+ function At(t, e, r) {
1076
+ return $.voronoi(t, e, r);
1033
1077
  }
1034
1078
  export {
1035
- yt as SynthPlugin,
1036
- b as SynthSource,
1037
- gt as cellColor,
1038
- _t as char,
1039
- vt as charColor,
1040
- xt as gradient,
1041
- Ct as noise,
1042
- bt as osc,
1043
- St as paint,
1044
- Mt as shape,
1045
- $t as solid,
1046
- wt as src,
1047
- Ft as voronoi
1079
+ bt as SynthPlugin,
1080
+ S as SynthSource,
1081
+ St as cellColor,
1082
+ Mt as char,
1083
+ $t as charColor,
1084
+ wt as gradient,
1085
+ Ft as noise,
1086
+ kt as osc,
1087
+ Tt as paint,
1088
+ Ct as setGlobalErrorCallback,
1089
+ Lt as shape,
1090
+ Pt as solid,
1091
+ It as src,
1092
+ At as voronoi
1048
1093
  };