textmode.synth.js 1.0.0-beta.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.
Files changed (54) hide show
  1. package/README.md +180 -0
  2. package/dist/textmode.synth.esm.js +967 -0
  3. package/dist/textmode.synth.umd.js +399 -0
  4. package/dist/types/SynthPlugin.d.ts +22 -0
  5. package/dist/types/SynthPlugin.d.ts.map +1 -0
  6. package/dist/types/compiler/GLSLGenerator.d.ts +44 -0
  7. package/dist/types/compiler/GLSLGenerator.d.ts.map +1 -0
  8. package/dist/types/compiler/SynthCompiler.d.ts +20 -0
  9. package/dist/types/compiler/SynthCompiler.d.ts.map +1 -0
  10. package/dist/types/compiler/UniformManager.d.ts +48 -0
  11. package/dist/types/compiler/UniformManager.d.ts.map +1 -0
  12. package/dist/types/compiler/index.d.ts +9 -0
  13. package/dist/types/compiler/index.d.ts.map +1 -0
  14. package/dist/types/compiler/types.d.ts +94 -0
  15. package/dist/types/compiler/types.d.ts.map +1 -0
  16. package/dist/types/core/ISynthSource.d.ts +718 -0
  17. package/dist/types/core/ISynthSource.d.ts.map +1 -0
  18. package/dist/types/core/SynthChain.d.ts +62 -0
  19. package/dist/types/core/SynthChain.d.ts.map +1 -0
  20. package/dist/types/core/SynthSource.d.ts +126 -0
  21. package/dist/types/core/SynthSource.d.ts.map +1 -0
  22. package/dist/types/core/index.d.ts +7 -0
  23. package/dist/types/core/index.d.ts.map +1 -0
  24. package/dist/types/core/types.d.ts +106 -0
  25. package/dist/types/core/types.d.ts.map +1 -0
  26. package/dist/types/index.d.ts +395 -0
  27. package/dist/types/index.d.ts.map +1 -0
  28. package/dist/types/lib/ArrayUtils.d.ts +225 -0
  29. package/dist/types/lib/ArrayUtils.d.ts.map +1 -0
  30. package/dist/types/transforms/TransformDefinition.d.ts +54 -0
  31. package/dist/types/transforms/TransformDefinition.d.ts.map +1 -0
  32. package/dist/types/transforms/TransformFactory.d.ts +64 -0
  33. package/dist/types/transforms/TransformFactory.d.ts.map +1 -0
  34. package/dist/types/transforms/TransformRegistry.d.ts +72 -0
  35. package/dist/types/transforms/TransformRegistry.d.ts.map +1 -0
  36. package/dist/types/transforms/categories/charModifiers.d.ts +16 -0
  37. package/dist/types/transforms/categories/charModifiers.d.ts.map +1 -0
  38. package/dist/types/transforms/categories/colors.d.ts +29 -0
  39. package/dist/types/transforms/categories/colors.d.ts.map +1 -0
  40. package/dist/types/transforms/categories/combine.d.ts +19 -0
  41. package/dist/types/transforms/categories/combine.d.ts.map +1 -0
  42. package/dist/types/transforms/categories/combineCoord.d.ts +23 -0
  43. package/dist/types/transforms/categories/combineCoord.d.ts.map +1 -0
  44. package/dist/types/transforms/categories/coordinates.d.ts +22 -0
  45. package/dist/types/transforms/categories/coordinates.d.ts.map +1 -0
  46. package/dist/types/transforms/categories/index.d.ts +15 -0
  47. package/dist/types/transforms/categories/index.d.ts.map +1 -0
  48. package/dist/types/transforms/categories/sources.d.ts +19 -0
  49. package/dist/types/transforms/categories/sources.d.ts.map +1 -0
  50. package/dist/types/transforms/index.d.ts +8 -0
  51. package/dist/types/transforms/index.d.ts.map +1 -0
  52. package/dist/types/utils/CharacterResolver.d.ts +19 -0
  53. package/dist/types/utils/CharacterResolver.d.ts.map +1 -0
  54. package/package.json +54 -0
@@ -0,0 +1,967 @@
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" }] }, charModify: { returnType: "vec4", args: [{ type: "vec4", name: "_char" }] } };
2
+ function U(t) {
3
+ const e = Y[t.type], a = [...e.args, ...t.inputs.map((r) => ({ type: r.type, name: r.name }))].map((r) => `${r.type} ${r.name}`).join(", "), n = `
4
+ ${e.returnType} ${t.name}(${a}) {
5
+ ${t.glsl}
6
+ }`;
7
+ return { ...t, glslFunction: n };
8
+ }
9
+ class X {
10
+ _transforms = /* @__PURE__ */ new Map();
11
+ _processedCache = /* @__PURE__ */ new Map();
12
+ register(e) {
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
+ }
15
+ registerMany(e) {
16
+ for (const a of e) this.register(a);
17
+ }
18
+ get(e) {
19
+ return this._transforms.get(e);
20
+ }
21
+ getProcessed(e) {
22
+ let a = this._processedCache.get(e);
23
+ if (!a) {
24
+ const n = this._transforms.get(e);
25
+ n && (a = U(n), this._processedCache.set(e, a));
26
+ }
27
+ return a;
28
+ }
29
+ has(e) {
30
+ return this._transforms.has(e);
31
+ }
32
+ getByType(e) {
33
+ return Array.from(this._transforms.values()).filter((a) => a.type === e);
34
+ }
35
+ getNames() {
36
+ return Array.from(this._transforms.keys());
37
+ }
38
+ getAll() {
39
+ return Array.from(this._transforms.values());
40
+ }
41
+ getSourceTransforms() {
42
+ return this.getByType("src");
43
+ }
44
+ remove(e) {
45
+ return this._processedCache.delete(e), this._transforms.delete(e);
46
+ }
47
+ clear() {
48
+ this._transforms.clear(), this._processedCache.clear();
49
+ }
50
+ get size() {
51
+ return this._transforms.size;
52
+ }
53
+ }
54
+ const w = new X(), L = /* @__PURE__ */ new Set(["src"]);
55
+ class B {
56
+ _generatedFunctions = {};
57
+ _synthSourceClass = null;
58
+ setSynthSourceClass(e) {
59
+ this._synthSourceClass = e;
60
+ }
61
+ injectMethods(e) {
62
+ const a = w.getAll();
63
+ for (const n of a) this._injectMethod(e, n);
64
+ }
65
+ _injectMethod(e, a) {
66
+ const { name: n, inputs: r, type: o } = a;
67
+ e[n] = o === "combine" || o === "combineCoord" ? function(c, ...i) {
68
+ const u = r.map((_, h) => i[h] ?? _.default);
69
+ return this.addCombineTransform(n, c, u);
70
+ } : function(...c) {
71
+ const i = r.map((u, _) => c[_] ?? u.default);
72
+ return this.addTransform(n, i);
73
+ };
74
+ }
75
+ generateStandaloneFunctions() {
76
+ if (!this._synthSourceClass) throw new Error("[TransformFactory] SynthSource class not set. Call setSynthSourceClass first.");
77
+ const e = {}, a = w.getAll(), n = this._synthSourceClass;
78
+ for (const r of a) if (L.has(r.type)) {
79
+ const { name: o, inputs: c } = r;
80
+ e[o] = (...i) => {
81
+ const u = new n(), _ = c.map((h, p) => i[p] ?? h.default);
82
+ return u.addTransform(o, _);
83
+ };
84
+ }
85
+ return this._generatedFunctions = e, e;
86
+ }
87
+ getGeneratedFunctions() {
88
+ return this._generatedFunctions;
89
+ }
90
+ addTransform(e, a) {
91
+ if (w.register(e), a && this._injectMethod(a, e), L.has(e.type) && this._synthSourceClass) {
92
+ const n = this._synthSourceClass, { name: r, inputs: o } = e;
93
+ this._generatedFunctions[r] = (...c) => {
94
+ const i = new n(), u = o.map((_, h) => c[h] ?? _.default);
95
+ return i.addTransform(r, u);
96
+ };
97
+ }
98
+ }
99
+ }
100
+ const I = new B(), E = { 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
+ vec2 st = _st;
102
+ float r = sin((st.x - offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
103
+ float g = sin((st.x + time*sync) * frequency) * 0.5 + 0.5;
104
+ float b = sin((st.x + offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
105
+ return vec4(r, g, b, 1.0);
106
+ `, description: "Generate oscillating color pattern" }, j = { name: "noise", type: "src", inputs: [{ name: "scale", type: "float", default: 10 }, { name: "offset", type: "float", default: 0.1 }], glsl: `
107
+ return vec4(vec3(_noise(vec3(_st * scale, offset * time))), 1.0);
108
+ `, description: "Generate noise pattern" }, D = { 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
+ vec3 color = vec3(0.0);
110
+ vec2 st = _st * scale;
111
+ vec2 i_st = floor(st);
112
+ vec2 f_st = fract(st);
113
+ float m_dist = 10.0;
114
+ vec2 m_point;
115
+ for (int j = -1; j <= 1; j++) {
116
+ for (int i = -1; i <= 1; i++) {
117
+ vec2 neighbor = vec2(float(i), float(j));
118
+ vec2 p = i_st + neighbor;
119
+ vec2 point = fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
120
+ point = 0.5 + 0.5 * sin(time * speed + 6.2831 * point);
121
+ vec2 diff = neighbor + point - f_st;
122
+ float dist = length(diff);
123
+ if (dist < m_dist) {
124
+ m_dist = dist;
125
+ m_point = point;
126
+ }
127
+ }
128
+ }
129
+ color += dot(m_point, vec2(0.3, 0.6));
130
+ color *= 1.0 - blending * m_dist;
131
+ return vec4(color, 1.0);
132
+ `, description: "Generate voronoi pattern" }, N = { name: "gradient", type: "src", inputs: [{ name: "speed", type: "float", default: 0 }], glsl: `
133
+ return vec4(_st, sin(time * speed), 1.0);
134
+ `, description: "Generate gradient pattern" }, q = { 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
+ vec2 st = _st * 2.0 - 1.0;
136
+ float a = atan(st.x, st.y) + 3.1416;
137
+ float r = (2.0 * 3.1416) / sides;
138
+ float d = cos(floor(0.5 + a/r) * r - a) * length(st);
139
+ return vec4(vec3(1.0 - smoothstep(radius, radius + smoothing + 0.0000001, d)), 1.0);
140
+ `, description: "Generate polygon shape" }, G = { 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
+ return vec4(r, g, b, a);
142
+ `, description: "Generate solid color" }, K = { name: "src", type: "src", inputs: [], glsl: `
143
+ return texture(prevBuffer, 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)." }, Q = [E, j, D, N, q, G, K], H = { name: "rotate", type: "coord", inputs: [{ name: "angle", type: "float", default: 10 }, { name: "speed", type: "float", default: 0 }], glsl: `
145
+ vec2 xy = _st - vec2(0.5);
146
+ float ang = angle + speed * time;
147
+ xy = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * xy;
148
+ xy += 0.5;
149
+ return xy;
150
+ `, description: "Rotate coordinates" }, W = { 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
+ vec2 xy = _st - vec2(offsetX, offsetY);
152
+ xy *= (1.0 / vec2(amount * xMult, amount * yMult));
153
+ xy += vec2(offsetX, offsetY);
154
+ return xy;
155
+ `, description: "Scale coordinates" }, J = { 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
+ vec2 st = _st;
157
+ st.x += scrollX + time * speedX;
158
+ st.y += scrollY + time * speedY;
159
+ return fract(st);
160
+ `, description: "Scroll coordinates" }, Z = { name: "scrollX", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
161
+ vec2 st = _st;
162
+ st.x += scrollX + time * speed;
163
+ return fract(st);
164
+ `, description: "Scroll X coordinate" }, ee = { name: "scrollY", type: "coord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
165
+ vec2 st = _st;
166
+ st.y += scrollY + time * speed;
167
+ return fract(st);
168
+ `, description: "Scroll Y coordinate" }, te = { name: "pixelate", type: "coord", inputs: [{ name: "pixelX", type: "float", default: 20 }, { name: "pixelY", type: "float", default: 20 }], glsl: `
169
+ vec2 xy = vec2(pixelX, pixelY);
170
+ return (floor(_st * xy) + 0.5) / xy;
171
+ `, description: "Pixelate coordinates" }, ne = { 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
+ vec2 st = _st * vec2(repeatX, repeatY);
173
+ st.x += step(1.0, mod(st.y, 2.0)) * offsetX;
174
+ st.y += step(1.0, mod(st.x, 2.0)) * offsetY;
175
+ return fract(st);
176
+ `, description: "Repeat pattern" }, re = { name: "repeatX", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
177
+ vec2 st = _st * vec2(reps, 1.0);
178
+ st.y += step(1.0, mod(st.x, 2.0)) * offset;
179
+ return fract(st);
180
+ `, description: "Repeat pattern horizontally" }, ae = { name: "repeatY", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
181
+ vec2 st = _st * vec2(1.0, reps);
182
+ st.x += step(1.0, mod(st.y, 2.0)) * offset;
183
+ return fract(st);
184
+ `, description: "Repeat pattern vertically" }, oe = { name: "kaleid", type: "coord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
185
+ vec2 st = _st;
186
+ st -= 0.5;
187
+ float r = length(st);
188
+ float a = atan(st.y, st.x);
189
+ float pi = 2.0 * 3.1416;
190
+ a = mod(a, pi / nSides);
191
+ a = abs(a - pi / nSides / 2.0);
192
+ return r * vec2(cos(a), sin(a));
193
+ `, description: "Kaleidoscope effect" }, se = [H, W, J, Z, ee, te, ne, re, ae, oe], ce = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
194
+ return vec4(_c0.rgb + vec3(amount), _c0.a);
195
+ `, description: "Adjust brightness" }, le = { name: "contrast", type: "color", inputs: [{ name: "amount", type: "float", default: 1.6 }], glsl: `
196
+ vec4 c = (_c0 - vec4(0.5)) * vec4(amount) + vec4(0.5);
197
+ return vec4(c.rgb, _c0.a);
198
+ `, description: "Adjust contrast" }, ie = { name: "invert", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
199
+ return vec4((1.0 - _c0.rgb) * amount + _c0.rgb * (1.0 - amount), _c0.a);
200
+ `, description: "Invert colors" }, ue = { name: "saturate", type: "color", inputs: [{ name: "amount", type: "float", default: 2 }], glsl: `
201
+ const vec3 W = vec3(0.2125, 0.7154, 0.0721);
202
+ vec3 intensity = vec3(dot(_c0.rgb, W));
203
+ return vec4(mix(intensity, _c0.rgb, amount), _c0.a);
204
+ `, description: "Adjust saturation" }, fe = { name: "hue", type: "color", inputs: [{ name: "hue", type: "float", default: 0.4 }], glsl: `
205
+ vec3 c = _rgbToHsv(_c0.rgb);
206
+ c.r += hue;
207
+ return vec4(_hsvToRgb(c), _c0.a);
208
+ `, description: "Shift hue" }, pe = { name: "colorama", type: "color", inputs: [{ name: "amount", type: "float", default: 5e-3 }], glsl: `
209
+ vec3 c = _rgbToHsv(_c0.rgb);
210
+ c += vec3(amount);
211
+ c = _hsvToRgb(c);
212
+ c = fract(c);
213
+ return vec4(c, _c0.a);
214
+ `, description: "Color cycle effect" }, me = { name: "posterize", type: "color", inputs: [{ name: "bins", type: "float", default: 3 }, { name: "gamma", type: "float", default: 0.6 }], glsl: `
215
+ vec4 c2 = pow(_c0, vec4(gamma));
216
+ c2 *= vec4(bins);
217
+ c2 = floor(c2);
218
+ c2 /= vec4(bins);
219
+ c2 = pow(c2, vec4(1.0 / gamma));
220
+ return vec4(c2.xyz, _c0.a);
221
+ `, description: "Posterize colors" }, de = { name: "luma", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.1 }], glsl: `
222
+ float a = smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb));
223
+ return vec4(_c0.rgb * a, a);
224
+ `, description: "Luma key" }, he = { name: "thresh", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.04 }], glsl: `
225
+ return vec4(vec3(smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb))), _c0.a);
226
+ `, description: "Threshold" }, ye = { 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
+ vec4 c = vec4(r, g, b, a);
228
+ vec4 pos = step(0.0, c);
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" }, _e = { name: "r", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
231
+ return vec4(_c0.r * scale + offset);
232
+ `, description: "Extract red channel" }, ge = { name: "g", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
233
+ return vec4(_c0.g * scale + offset);
234
+ `, description: "Extract green channel" }, ve = { name: "b", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
235
+ return vec4(_c0.b * scale + offset);
236
+ `, description: "Extract blue channel" }, xe = { 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
+ vec4 c2 = vec4(_c0);
238
+ c2.r += fract(r);
239
+ c2.g += fract(g);
240
+ c2.b += fract(b);
241
+ c2.a += fract(a);
242
+ return vec4(c2.rgba);
243
+ `, description: "Shift color channels by adding offset values" }, Ce = { name: "gamma", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
244
+ return vec4(pow(max(vec3(0.0), _c0.rgb), vec3(1.0 / amount)), _c0.a);
245
+ `, description: "Apply gamma correction" }, be = { 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
+ vec3 v = clamp((_c0.rgb - vec3(inMin)) / (vec3(inMax - inMin) + 0.0000001), 0.0, 1.0);
247
+ v = pow(v, vec3(1.0 / gamma));
248
+ v = mix(vec3(outMin), vec3(outMax), v);
249
+ return vec4(v, _c0.a);
250
+ `, description: "Adjust input/output levels and gamma" }, Se = { name: "clampColor", type: "color", inputs: [{ name: "min", type: "float", default: 0 }, { name: "max", type: "float", default: 1 }], glsl: `
251
+ return vec4(clamp(_c0.rgb, vec3(min), vec3(max)), _c0.a);
252
+ `, description: "Clamp color values to a range" }, $e = [ce, le, ie, ue, fe, pe, me, de, he, ye, _e, ge, ve, xe, Ce, be, Se], Me = { name: "add", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
253
+ return (_c0 + _c1) * amount + _c0 * (1.0 - amount);
254
+ `, description: "Add another source" }, we = { name: "sub", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
255
+ return (_c0 - _c1) * amount + _c0 * (1.0 - amount);
256
+ `, description: "Subtract another source" }, Fe = { name: "mult", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
257
+ return _c0 * (1.0 - amount) + (_c0 * _c1) * amount;
258
+ `, description: "Multiply with another source" }, Te = { name: "blend", type: "combine", inputs: [{ name: "amount", type: "float", default: 0.5 }], glsl: `
259
+ return _c0 * (1.0 - amount) + _c1 * amount;
260
+ `, description: "Blend with another source" }, Re = { name: "diff", type: "combine", inputs: [], glsl: `
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: `
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" }, Pe = { name: "mask", type: "combine", inputs: [], glsl: `
265
+ float a = _luminance(_c1.rgb);
266
+ return vec4(_c0.rgb * a, a * _c0.a);
267
+ `, description: "Mask with another source" }, Ae = [Me, we, Fe, Te, Re, Ie, Pe], ke = { name: "modulate", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 0.1 }], glsl: `
268
+ return _st + _c0.xy * amount;
269
+ `, description: "Modulate coordinates with another source" }, Le = { name: "modulateScale", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 1 }], glsl: `
270
+ vec2 xy = _st - vec2(0.5);
271
+ xy *= (1.0 / vec2(offset + multiple * _c0.r, offset + multiple * _c0.g));
272
+ xy += vec2(0.5);
273
+ return xy;
274
+ `, description: "Modulate scale with another source" }, Oe = { name: "modulateRotate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
275
+ vec2 xy = _st - vec2(0.5);
276
+ float angle = offset + _c0.x * multiple;
277
+ xy = mat2(cos(angle), -sin(angle), sin(angle), cos(angle)) * xy;
278
+ xy += 0.5;
279
+ return xy;
280
+ `, description: "Modulate rotation with another source" }, ze = { name: "modulatePixelate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 10 }, { name: "offset", type: "float", default: 3 }], glsl: `
281
+ vec2 xy = vec2(offset + _c0.x * multiple, offset + _c0.y * multiple);
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: `
284
+ vec2 st = _st - 0.5;
285
+ float r = length(st);
286
+ float a = atan(st.y, st.x);
287
+ float pi = 2.0 * 3.1416;
288
+ a = mod(a, pi / nSides);
289
+ a = abs(a - pi / nSides / 2.0);
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: `
292
+ vec2 st = _st;
293
+ st.x += _c0.r * scrollX + time * speed;
294
+ return fract(st);
295
+ `, description: "Modulate X scroll with another source" }, Ue = { name: "modulateScrollY", type: "combineCoord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
296
+ vec2 st = _st;
297
+ st.y += _c0.r * scrollY + time * speed;
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: `
300
+ vec2 st = _st * vec2(repeatX, repeatY);
301
+ st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offsetX;
302
+ st.y += step(1.0, mod(st.x, 2.0)) + _c0.g * offsetY;
303
+ return fract(st);
304
+ `, description: "Modulate repeat pattern with another source" }, Be = { name: "modulateRepeatX", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
305
+ vec2 st = _st * vec2(reps, 1.0);
306
+ st.y += step(1.0, mod(st.x, 2.0)) + _c0.r * offset;
307
+ return fract(st);
308
+ `, description: "Modulate X repeat with another source" }, Ee = { name: "modulateRepeatY", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
309
+ vec2 st = _st * vec2(1.0, reps);
310
+ st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offset;
311
+ return fract(st);
312
+ `, description: "Modulate Y repeat with another source" }, je = { name: "modulateHue", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
313
+ return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0 / resolution);
314
+ `, description: "Modulate coordinates based on hue differences" }, De = [ke, Le, Oe, ze, Ve, Ye, Ue, Xe, Be, Ee, je], Ne = { name: "charFlipX", type: "charModify", inputs: [{ name: "toggle", type: "float", default: 1 }], glsl: `
315
+ int flags = int(_char.b * 255.0 + 0.5);
316
+ if (toggle > 0.5) {
317
+ flags = flags | 2;
318
+ }
319
+ return vec4(_char.rg, float(flags) / 255.0, _char.a);
320
+ `, description: "Flip characters horizontally" }, qe = { name: "charFlipY", type: "charModify", inputs: [{ name: "toggle", type: "float", default: 1 }], glsl: `
321
+ int flags = int(_char.b * 255.0 + 0.5);
322
+ if (toggle > 0.5) {
323
+ flags = flags | 4;
324
+ }
325
+ return vec4(_char.rg, float(flags) / 255.0, _char.a);
326
+ `, description: "Flip characters vertically" }, Ge = { name: "charInvert", type: "charModify", inputs: [{ name: "toggle", type: "float", default: 1 }], glsl: `
327
+ int flags = int(_char.b * 255.0 + 0.5);
328
+ if (toggle > 0.5) {
329
+ flags = flags | 1;
330
+ }
331
+ return vec4(_char.rg, float(flags) / 255.0, _char.a);
332
+ `, description: "Invert character colors" }, Ke = { name: "charRotate", type: "charModify", inputs: [{ name: "angle", type: "float", default: 0.25 }, { name: "speed", type: "float", default: 0 }], glsl: `
333
+ float rotation = fract(angle + time * speed);
334
+ return vec4(_char.rgb, rotation);
335
+ `, description: "Rotate characters" }, Qe = [Ne, qe, Ge, Ke], He = [...Q, ...se, ...$e, ...Ae, ...De, ...Qe];
336
+ class M {
337
+ _transforms;
338
+ constructor(e) {
339
+ this._transforms = e;
340
+ }
341
+ static empty() {
342
+ return new M([]);
343
+ }
344
+ static from(e) {
345
+ return new M([...e]);
346
+ }
347
+ get transforms() {
348
+ return this._transforms;
349
+ }
350
+ push(e) {
351
+ this._transforms.push(e);
352
+ }
353
+ get length() {
354
+ return this._transforms.length;
355
+ }
356
+ get isEmpty() {
357
+ return this._transforms.length === 0;
358
+ }
359
+ append(e) {
360
+ return new M([...this._transforms, e]);
361
+ }
362
+ get(e) {
363
+ return this._transforms[e];
364
+ }
365
+ [Symbol.iterator]() {
366
+ return this._transforms[Symbol.iterator]();
367
+ }
368
+ }
369
+ class x {
370
+ _chain;
371
+ _charMapping;
372
+ _nestedSources;
373
+ _externalLayerRefs;
374
+ _colorSource;
375
+ _cellColorSource;
376
+ _charSource;
377
+ _charCount;
378
+ constructor(e) {
379
+ this._chain = e?.chain ?? M.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();
380
+ }
381
+ addTransform(e, a) {
382
+ const n = { name: e, userArgs: a };
383
+ return this._chain.push(n), this;
384
+ }
385
+ addCombineTransform(e, a, n) {
386
+ const r = this._chain.length;
387
+ return this._nestedSources.set(r, a), this.addTransform(e, n);
388
+ }
389
+ addExternalLayerRef(e) {
390
+ const a = this._chain.length;
391
+ return this._externalLayerRefs.set(a, e), this.addTransform("src", []);
392
+ }
393
+ charMap(e) {
394
+ const a = Array.from(e), n = [];
395
+ for (const r of a) n.push(r.codePointAt(0) ?? 32);
396
+ return this._charMapping = { chars: e, indices: n }, this;
397
+ }
398
+ charColor(e) {
399
+ return this._colorSource = e, this;
400
+ }
401
+ char(e, a) {
402
+ return this._charSource = e, this._charCount = a, this;
403
+ }
404
+ cellColor(e) {
405
+ return this._cellColorSource = e, this;
406
+ }
407
+ paint(e) {
408
+ return this._colorSource = e, this._cellColorSource = e, this;
409
+ }
410
+ clone() {
411
+ const e = /* @__PURE__ */ new Map();
412
+ for (const [n, r] of this._nestedSources) e.set(n, r.clone());
413
+ const a = /* @__PURE__ */ new Map();
414
+ for (const [n, r] of this._externalLayerRefs) a.set(n, { ...r });
415
+ return new x({ chain: M.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: a });
416
+ }
417
+ get transforms() {
418
+ return this._chain.transforms;
419
+ }
420
+ get charMapping() {
421
+ return this._charMapping;
422
+ }
423
+ get colorSource() {
424
+ return this._colorSource;
425
+ }
426
+ get cellColorSource() {
427
+ return this._cellColorSource;
428
+ }
429
+ get charSource() {
430
+ return this._charSource;
431
+ }
432
+ get charCount() {
433
+ return this._charCount;
434
+ }
435
+ get nestedSources() {
436
+ return this._nestedSources;
437
+ }
438
+ get externalLayerRefs() {
439
+ return this._externalLayerRefs;
440
+ }
441
+ }
442
+ const P = { linear: (t) => t, easeInQuad: (t) => t * t, easeOutQuad: (t) => t * (2 - t), easeInOutQuad: (t) => t < 0.5 ? 2 * t * t : (4 - 2 * t) * t - 1, easeInCubic: (t) => t * t * t, easeOutCubic: (t) => --t * t * t + 1, easeInOutCubic: (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1, easeInQuart: (t) => t * t * t * t, easeOutQuart: (t) => 1 - --t * t * t * t, easeInOutQuart: (t) => t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t, easeInQuint: (t) => t * t * t * t * t, easeOutQuint: (t) => 1 + --t * t * t * t * t, easeInOutQuint: (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t, sin: (t) => (1 + Math.sin(Math.PI * t - Math.PI / 2)) / 2 };
443
+ function T(t, e) {
444
+ return (t % e + e) % e;
445
+ }
446
+ function We(t, e, a, n, r) {
447
+ return (t - e) * (r - n) / (a - e) + n;
448
+ }
449
+ function Je() {
450
+ "fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
451
+ return this._speed = t, this;
452
+ }, Array.prototype.smooth = function(t = 1) {
453
+ return this._smooth = t, this;
454
+ }, Array.prototype.ease = function(t = "linear") {
455
+ return typeof t == "function" ? (this._smooth = 1, this._ease = t) : P[t] && (this._smooth = 1, this._ease = P[t]), this;
456
+ }, Array.prototype.offset = function(t = 0.5) {
457
+ return this._offset = t % 1, this;
458
+ }, Array.prototype.fit = function(t = 0, e = 1) {
459
+ const a = Math.min(...this), n = Math.max(...this), r = this.map((o) => We(o, a, n, t, e));
460
+ return r._speed = this._speed, r._smooth = this._smooth, r._ease = this._ease, r._offset = this._offset, r;
461
+ });
462
+ }
463
+ function Ze(t, e) {
464
+ const a = t._speed ?? 1, n = t._smooth ?? 0;
465
+ let r = e.time * a * 1 + (t._offset ?? 0);
466
+ if (n !== 0) {
467
+ const o = t._ease ?? P.linear, c = r - n / 2, i = t[Math.floor(T(c, t.length))], u = t[Math.floor(T(c + 1, t.length))];
468
+ return o(Math.min(T(c, 1) / n, 1)) * (u - i) + i;
469
+ }
470
+ return t[Math.floor(T(r, t.length))];
471
+ }
472
+ function et(t) {
473
+ return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
474
+ }
475
+ class tt {
476
+ _uniforms = /* @__PURE__ */ new Map();
477
+ _dynamicUpdaters = /* @__PURE__ */ new Map();
478
+ processArgument(e, a, n) {
479
+ if (et(e)) {
480
+ const r = `${n}_${a.name}`, o = { name: r, type: a.type, value: a.default ?? 0, isDynamic: !0 }, c = (i) => Ze(e, i);
481
+ return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, c), { glslValue: r, uniform: o, updater: c };
482
+ }
483
+ if (typeof e == "function") {
484
+ const r = `${n}_${a.name}`, o = { name: r, type: a.type, value: a.default ?? 0, isDynamic: !0 };
485
+ return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, e), { glslValue: r, uniform: o, updater: e };
486
+ }
487
+ if (typeof e == "number") return { glslValue: v(e) };
488
+ if (Array.isArray(e) && typeof e[0] == "number") {
489
+ const r = e;
490
+ if (r.length === 2) return { glslValue: `vec2(${v(r[0])}, ${v(r[1])})` };
491
+ if (r.length === 3) return { glslValue: `vec3(${v(r[0])}, ${v(r[1])}, ${v(r[2])})` };
492
+ if (r.length === 4) return { glslValue: `vec4(${v(r[0])}, ${v(r[1])}, ${v(r[2])}, ${v(r[3])})` };
493
+ }
494
+ return this.processDefault(a);
495
+ }
496
+ processDefault(e) {
497
+ const a = e.default;
498
+ return typeof a == "number" ? { glslValue: v(a) } : Array.isArray(a) ? { glslValue: `vec${a.length}(${a.map(v).join(", ")})` } : { glslValue: "0.0" };
499
+ }
500
+ getUniforms() {
501
+ return new Map(this._uniforms);
502
+ }
503
+ getDynamicUpdaters() {
504
+ return new Map(this._dynamicUpdaters);
505
+ }
506
+ clear() {
507
+ this._uniforms.clear(), this._dynamicUpdaters.clear();
508
+ }
509
+ }
510
+ function v(t) {
511
+ const e = t.toString();
512
+ return e.includes(".") ? e : e + ".0";
513
+ }
514
+ const nt = `
515
+ // Utility functions
516
+ float _luminance(vec3 rgb) {
517
+ const vec3 W = vec3(0.2125, 0.7154, 0.0721);
518
+ return dot(rgb, W);
519
+ }
520
+
521
+ vec3 _rgbToHsv(vec3 c) {
522
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
523
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
524
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
525
+ float d = q.x - min(q.w, q.y);
526
+ float e = 1.0e-10;
527
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
528
+ }
529
+
530
+ vec3 _hsvToRgb(vec3 c) {
531
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
532
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
533
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
534
+ }
535
+
536
+ // Simplex 3D Noise by Ian McEwan, Ashima Arts
537
+ vec4 permute(vec4 x) {
538
+ return mod(((x*34.0)+1.0)*x, 289.0);
539
+ }
540
+
541
+ vec4 taylorInvSqrt(vec4 r) {
542
+ return 1.79284291400159 - 0.85373472095314 * r;
543
+ }
544
+
545
+ float _noise(vec3 v) {
546
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0);
547
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
548
+
549
+ // First corner
550
+ vec3 i = floor(v + dot(v, C.yyy));
551
+ vec3 x0 = v - i + dot(i, C.xxx);
552
+
553
+ // Other corners
554
+ vec3 g = step(x0.yzx, x0.xyz);
555
+ vec3 l = 1.0 - g;
556
+ vec3 i1 = min(g.xyz, l.zxy);
557
+ vec3 i2 = max(g.xyz, l.zxy);
558
+
559
+ vec3 x1 = x0 - i1 + 1.0 * C.xxx;
560
+ vec3 x2 = x0 - i2 + 2.0 * C.xxx;
561
+ vec3 x3 = x0 - 1.0 + 3.0 * C.xxx;
562
+
563
+ // Permutations
564
+ i = mod(i, 289.0);
565
+ vec4 p = permute(permute(permute(
566
+ i.z + vec4(0.0, i1.z, i2.z, 1.0))
567
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0))
568
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0));
569
+
570
+ // Gradients: N*N points uniformly over a square, mapped onto an octahedron.
571
+ float n_ = 1.0/7.0;
572
+ vec3 ns = n_ * D.wyz - D.xzx;
573
+
574
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
575
+
576
+ vec4 x_ = floor(j * ns.z);
577
+ vec4 y_ = floor(j - 7.0 * x_);
578
+
579
+ vec4 x = x_ * ns.x + ns.yyyy;
580
+ vec4 y = y_ * ns.x + ns.yyyy;
581
+ vec4 h = 1.0 - abs(x) - abs(y);
582
+
583
+ vec4 b0 = vec4(x.xy, y.xy);
584
+ vec4 b1 = vec4(x.zw, y.zw);
585
+
586
+ vec4 s0 = floor(b0) * 2.0 + 1.0;
587
+ vec4 s1 = floor(b1) * 2.0 + 1.0;
588
+ vec4 sh = -step(h, vec4(0.0));
589
+
590
+ vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
591
+ vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
592
+
593
+ vec3 p0 = vec3(a0.xy, h.x);
594
+ vec3 p1 = vec3(a0.zw, h.y);
595
+ vec3 p2 = vec3(a1.xy, h.z);
596
+ vec3 p3 = vec3(a1.zw, h.w);
597
+
598
+ // Normalize gradients
599
+ vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
600
+ p0 *= norm.x;
601
+ p1 *= norm.y;
602
+ p2 *= norm.z;
603
+ p3 *= norm.w;
604
+
605
+ // Mix final noise value
606
+ vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);
607
+ m = m * m;
608
+ return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
609
+ }
610
+ `;
611
+ function rt(t) {
612
+ const { uniforms: e, glslFunctions: a, mainCode: n, charOutputCode: r, primaryColorVar: o, cellColorVar: c, charMapping: i, usesFeedback: u, usesCharFeedback: _, usesCellColorFeedback: h, externalLayers: p } = t, y = Array.from(e.values()).map((d) => `uniform ${d.type} ${d.name};`).join(`
613
+ `);
614
+ let g = "", m = "";
615
+ i && (g = `uniform int u_charMap[${i.indices.length}];
616
+ uniform int u_charMapSize;`, m = `
617
+ // Apply character mapping
618
+ int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
619
+ int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
620
+ charOutput.r = float(mappedCharIdx % 256) / 255.0;
621
+ charOutput.g = float(mappedCharIdx / 256) / 255.0;`);
622
+ const f = [];
623
+ u && f.push("uniform sampler2D prevBuffer;"), _ && f.push("uniform sampler2D prevCharBuffer;"), h && f.push("uniform sampler2D prevCellColorBuffer;");
624
+ const l = f.join(`
625
+ `), s = [];
626
+ if (p) for (const [, d] of p) d.usesChar && s.push(`uniform sampler2D ${d.uniformPrefix}_char;`), d.usesPrimary && s.push(`uniform sampler2D ${d.uniformPrefix}_primary;`), d.usesCellColor && s.push(`uniform sampler2D ${d.uniformPrefix}_cell;`);
627
+ return `#version 300 es
628
+ precision highp float;
629
+
630
+ // Varyings
631
+ in vec2 v_uv;
632
+
633
+ // MRT outputs
634
+ layout(location = 0) out vec4 o_character;
635
+ layout(location = 1) out vec4 o_primaryColor;
636
+ layout(location = 2) out vec4 o_secondaryColor;
637
+
638
+ // Standard uniforms
639
+ uniform float time;
640
+ uniform vec2 resolution;
641
+ ${l}
642
+ ${s.length > 0 ? `// External layer samplers
643
+ ${s.join(`
644
+ `)}` : ""}
645
+ ${g}
646
+
647
+ // Dynamic uniforms
648
+ ${y}
649
+
650
+ ${nt}
651
+
652
+ // Transform functions
653
+ ${Array.from(a).join(`
654
+ `)}
655
+
656
+ void main() {
657
+ // Transform chain
658
+ ${n.join(`
659
+ `)}
660
+
661
+ ${r}
662
+ ${m}
663
+
664
+ // Output to MRT
665
+ o_character = charOutput;
666
+ o_primaryColor = ${o};
667
+ o_secondaryColor = ${c};
668
+ }
669
+ `;
670
+ }
671
+ function at(t, e, a) {
672
+ return t ? `
673
+ // Character output from generator
674
+ vec4 charOutput = ${e};` : `
675
+ // Derive character from color luminance
676
+ float lum = _luminance(${a}.rgb);
677
+ int charIdx = int(lum * 255.0);
678
+ vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`;
679
+ }
680
+ function R(t) {
681
+ return new ot().compile(t);
682
+ }
683
+ class ot {
684
+ _varCounter = 0;
685
+ _uniformManager = new tt();
686
+ _glslFunctions = /* @__PURE__ */ new Set();
687
+ _mainCode = [];
688
+ _usesFeedback = !1;
689
+ _usesCharFeedback = !1;
690
+ _usesCellColorFeedback = !1;
691
+ _currentTarget = "main";
692
+ _externalLayers = /* @__PURE__ */ new Map();
693
+ _externalLayerCounter = 0;
694
+ _layerIdToPrefix = /* @__PURE__ */ new Map();
695
+ compile(e) {
696
+ this._varCounter = 0, this._uniformManager.clear(), this._glslFunctions.clear(), this._mainCode.length = 0, this._usesFeedback = !1, this._usesCharFeedback = !1, this._usesCellColorFeedback = !1, this._externalLayers.clear(), this._externalLayerCounter = 0, this._layerIdToPrefix.clear();
697
+ const a = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
698
+ let n, r = a.charVar;
699
+ if (e.charSource) {
700
+ const u = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char");
701
+ r = "charFromSource_" + this._varCounter++, n = e.charCount ?? 256, this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${r} = _luminance(${u.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${r} = int(charLum_${r} * ${n.toFixed(1)});`), this._mainCode.push(` vec4 ${r} = vec4(float(charIdx_${r} % 256) / 255.0, float(charIdx_${r} / 256) / 255.0, 0.0, 0.0);`);
702
+ }
703
+ let o = a.colorVar;
704
+ e.colorSource && (o = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
705
+ let c = "vec4(0.0, 0.0, 0.0, 0.0)";
706
+ e.cellColorSource && (c = this._compileChain(e.cellColorSource, "cellColor", "vec4(0.0, 0.0, 0.0, 0.0)", "v_uv", "cellColor").colorVar);
707
+ const i = at(!!r, r ?? "vec4(0.0)", a.colorVar);
708
+ return { fragmentSource: rt({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: i, primaryColorVar: o, cellColorVar: c, charMapping: e.charMapping, usesFeedback: this._usesFeedback, usesCharFeedback: this._usesCharFeedback, usesCellColorFeedback: this._usesCellColorFeedback, externalLayers: this._externalLayers }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesFeedback: this._usesFeedback, usesCharFeedback: this._usesCharFeedback, usesCellColorFeedback: this._usesCellColorFeedback, externalLayers: new Map(this._externalLayers) };
709
+ }
710
+ _compileChain(e, a, n, r = "v_uv", o = "main") {
711
+ const c = this._currentTarget;
712
+ this._currentTarget = o;
713
+ const i = `${a}_st`;
714
+ let u, _, h, p = `${a}_c`;
715
+ this._mainCode.push(` vec2 ${i} = ${r};`), this._mainCode.push(` vec4 ${p} = ${n};`);
716
+ const y = e.transforms, g = y.map((l) => this._getProcessedTransform(l.name)), m = [];
717
+ for (let l = 0; l < g.length; l++) {
718
+ const s = g[l];
719
+ s && (s.type !== "coord" && s.type !== "combineCoord" || m.push(l));
720
+ }
721
+ const f = (l) => {
722
+ const s = y[l], d = g[l];
723
+ if (!d) return void console.warn(`[SynthCompiler] Unknown transform: ${s.name}`);
724
+ const F = e.externalLayerRefs.get(l);
725
+ if (s.name === "src") if (F) this._trackExternalLayerUsage(F, this._currentTarget);
726
+ else switch (this._currentTarget) {
727
+ case "char":
728
+ this._usesCharFeedback = !0;
729
+ break;
730
+ case "cellColor":
731
+ this._usesCellColorFeedback = !0;
732
+ break;
733
+ default:
734
+ this._usesFeedback = !0;
735
+ }
736
+ const O = this._getContextAwareGlslFunction(d, s.name, F);
737
+ this._glslFunctions.add(O);
738
+ const z = this._processArguments(s.userArgs, d.inputs, `${a}_${l}_${s.name}`), A = e.nestedSources.get(l);
739
+ let k;
740
+ A && (d.type === "combine" || d.type === "combineCoord") && (k = this._compileChain(A, `${a}_nested_${l}`, n, i, o).colorVar);
741
+ const V = this._varCounter++, C = this._generateTransformCode(d, V, i, p, u, _, h, z, k, F);
742
+ p = C.colorVar, C.charVar && (u = C.charVar), C.flagsVar && (_ = C.flagsVar), C.rotationVar && (h = C.rotationVar);
743
+ };
744
+ for (let l = m.length - 1; l >= 0; l--) f(m[l]);
745
+ for (let l = 0; l < y.length; l++) {
746
+ const s = g[l];
747
+ (!s || s.type !== "coord" && s.type !== "combineCoord") && f(l);
748
+ }
749
+ return this._currentTarget = c, { coordVar: i, colorVar: p, charVar: u, flagsVar: _, rotationVar: h };
750
+ }
751
+ _getProcessedTransform(e) {
752
+ return w.getProcessed(e);
753
+ }
754
+ _getContextAwareGlslFunction(e, a, n) {
755
+ if (a !== "src") return e.glslFunction;
756
+ if (n) {
757
+ const o = this._getExternalLayerPrefix(n.layerId), c = { char: `${o}_char`, charColor: `${o}_primary`, cellColor: `${o}_cell`, main: `${o}_primary` }[this._currentTarget];
758
+ return `
759
+ vec4 ${`src_ext_${o}_${this._currentTarget}`}(vec2 _st) {
760
+ return texture(${c}, fract(_st));
761
+ }
762
+ `;
763
+ }
764
+ const r = { char: "prevCharBuffer", charColor: "prevBuffer", cellColor: "prevCellColorBuffer", main: "prevBuffer" }[this._currentTarget];
765
+ return `
766
+ vec4 ${`src_${this._currentTarget}`}(vec2 _st) {
767
+ return texture(${r}, fract(_st));
768
+ }
769
+ `;
770
+ }
771
+ _getExternalLayerPrefix(e) {
772
+ let a = this._layerIdToPrefix.get(e);
773
+ return a || (a = "extLayer" + this._externalLayerCounter++, this._layerIdToPrefix.set(e, a)), a;
774
+ }
775
+ _trackExternalLayerUsage(e, a) {
776
+ const n = this._getExternalLayerPrefix(e.layerId);
777
+ let r = this._externalLayers.get(e.layerId);
778
+ switch (r || (r = { layerId: e.layerId, uniformPrefix: n, usesChar: !1, usesPrimary: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, r)), a) {
779
+ case "char":
780
+ r.usesChar = !0;
781
+ break;
782
+ case "cellColor":
783
+ r.usesCellColor = !0;
784
+ break;
785
+ default:
786
+ r.usesPrimary = !0;
787
+ }
788
+ }
789
+ _processArguments(e, a, n) {
790
+ const r = [];
791
+ for (let o = 0; o < a.length; o++) {
792
+ const c = a[o], i = e[o] ?? c.default, u = this._uniformManager.processArgument(i, c, n);
793
+ r.push(u.glslValue);
794
+ }
795
+ return r;
796
+ }
797
+ _generateTransformCode(e, a, n, r, o, c, i, u, _, h) {
798
+ const p = (...s) => [...s, ...u].join(", ");
799
+ let y = e.name;
800
+ e.name === "src" && (h ? y = `src_ext_${this._getExternalLayerPrefix(h.layerId)}_${this._currentTarget}` : y = `src_${this._currentTarget}`);
801
+ let g = r, m = o, f = c, l = i;
802
+ switch (e.type) {
803
+ case "src": {
804
+ const s = `c${a}`;
805
+ this._mainCode.push(` vec4 ${s} = ${y}(${p(n)});`), g = s;
806
+ break;
807
+ }
808
+ case "coord": {
809
+ const s = `st${a}`;
810
+ this._mainCode.push(` vec2 ${s} = ${y}(${p(n)});`), this._mainCode.push(` ${n} = ${s};`);
811
+ break;
812
+ }
813
+ case "color": {
814
+ const s = `c${a}`;
815
+ this._mainCode.push(` vec4 ${s} = ${y}(${p(r)});`), g = s;
816
+ break;
817
+ }
818
+ case "combine": {
819
+ const s = `c${a}`;
820
+ this._mainCode.push(` vec4 ${s} = ${y}(${p(r, _ ?? "vec4(0.0)")});`), g = s;
821
+ break;
822
+ }
823
+ case "combineCoord": {
824
+ const s = `st${a}`;
825
+ this._mainCode.push(` vec2 ${s} = ${y}(${p(n, _ ?? "vec4(0.0)")});`), this._mainCode.push(` ${n} = ${s};`);
826
+ break;
827
+ }
828
+ case "charModify":
829
+ m || (m = `char${a}`, f = `flags${a}`, l = `rot${a}`, this._mainCode.push(` vec4 ${m} = vec4(0.0);`), this._mainCode.push(` float ${f} = 0.0;`), this._mainCode.push(` float ${l} = 0.0;`)), this._mainCode.push(` ${m} = ${y}(${p(m)});`);
830
+ }
831
+ return { colorVar: g, charVar: m, flagsVar: f, rotationVar: l };
832
+ }
833
+ }
834
+ class st {
835
+ _resolvedIndices;
836
+ _lastFontCharacterCount = 0;
837
+ _lastChars = "";
838
+ resolve(e, a) {
839
+ const n = a.characters.length;
840
+ if (this._resolvedIndices && this._lastFontCharacterCount === n && this._lastChars === e) return this._resolvedIndices;
841
+ const r = Array.from(e), o = new Int32Array(r.length), c = a.characterMap, i = a.characters;
842
+ for (let u = 0; u < r.length; u++) {
843
+ const _ = r[u], h = c.get(_);
844
+ if (h !== void 0) o[u] = i.indexOf(h);
845
+ else {
846
+ const p = c.get(" ");
847
+ o[u] = p !== void 0 ? i.indexOf(p) : 0;
848
+ }
849
+ }
850
+ return this._resolvedIndices = o, this._lastFontCharacterCount = n, this._lastChars = e, o;
851
+ }
852
+ invalidate() {
853
+ this._resolvedIndices = void 0, this._lastFontCharacterCount = 0, this._lastChars = "";
854
+ }
855
+ }
856
+ const b = "textmode.synth.js";
857
+ function $(t) {
858
+ const e = /* @__PURE__ */ new Map();
859
+ for (const [, a] of t.externalLayerRefs) e.set(a.layerId, a.layer);
860
+ for (const [, a] of t.nestedSources) {
861
+ const n = $(a);
862
+ for (const [r, o] of n) e.set(r, o);
863
+ }
864
+ if (t.charSource) {
865
+ const a = $(t.charSource);
866
+ for (const [n, r] of a) e.set(n, r);
867
+ }
868
+ if (t.colorSource) {
869
+ const a = $(t.colorSource);
870
+ for (const [n, r] of a) e.set(n, r);
871
+ }
872
+ if (t.cellColorSource) {
873
+ const a = $(t.cellColorSource);
874
+ for (const [n, r] of a) e.set(n, r);
875
+ }
876
+ return e;
877
+ }
878
+ const it = { name: b, version: "1.0.0", install(t, e) {
879
+ e.extendLayer("synth", function(a) {
880
+ const n = performance.now() / 1e3, r = this.grid !== void 0 && this.drawFramebuffer !== void 0;
881
+ let o = this.getPluginState(b);
882
+ o ? (o.source = a, o.startTime = n, o.needsCompile = !0, o.characterResolver.invalidate(), r && (o.compiled = R(a))) : o = { source: a, compiled: r ? R(a) : void 0, shader: void 0, characterResolver: new st(), startTime: n, needsCompile: !0, pingPongBuffers: void 0, pingPongIndex: 0 }, this.setPluginState(b, o);
883
+ }), e.registerLayerPreRenderHook(async (a) => {
884
+ const n = a.getPluginState(b);
885
+ if (!n) return;
886
+ const r = a.grid, o = a.drawFramebuffer;
887
+ if (!r || !o || (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 t.createFilterShader(n.compiled.fragmentSource), n.needsCompile = !1), !n.shader || !n.compiled)) return;
888
+ const c = n.compiled.usesFeedback, i = n.compiled.usesCharFeedback, u = n.compiled.usesCellColorFeedback, _ = c || i || u;
889
+ _ && !n.pingPongBuffers && (n.pingPongBuffers = [t.createFramebuffer({ width: r.cols, height: r.rows, attachments: 3 }), t.createFramebuffer({ width: r.cols, height: r.rows, attachments: 3 })], n.pingPongIndex = 0);
890
+ const h = { time: t.millis() / 1e3, frameCount: t.frameCount, width: r.width, height: r.height, cols: r.cols, rows: r.rows }, p = (y) => {
891
+ t.setUniform("time", h.time), t.setUniform("resolution", [h.cols, h.rows]);
892
+ for (const [m, f] of n.compiled.dynamicUpdaters) t.setUniform(m, f(h));
893
+ for (const [m, f] of n.compiled.uniforms) f.isDynamic || typeof f.value == "function" || t.setUniform(m, f.value);
894
+ if (n.compiled.charMapping) {
895
+ const m = n.characterResolver.resolve(n.compiled.charMapping.chars, a.font);
896
+ t.setUniform("u_charMap", m), t.setUniform("u_charMapSize", m.length);
897
+ }
898
+ y && (c && t.setUniform("prevBuffer", y.textures[1]), i && t.setUniform("prevCharBuffer", y.textures[0]), u && t.setUniform("prevCellColorBuffer", y.textures[2]));
899
+ const g = n.compiled.externalLayers;
900
+ if (g && g.size > 0 && n.externalLayerMap) for (const [m, f] of g) {
901
+ const l = n.externalLayerMap.get(m);
902
+ if (!l) {
903
+ console.warn(`[SynthPlugin] External layer not found: ${m}`);
904
+ continue;
905
+ }
906
+ const s = l.getPluginState(b);
907
+ let d;
908
+ s?.pingPongBuffers ? d = s.pingPongBuffers[s.pingPongIndex].textures : l.drawFramebuffer && (d = l.drawFramebuffer.textures), d && (f.usesChar && t.setUniform(`${f.uniformPrefix}_char`, d[0]), f.usesPrimary && t.setUniform(`${f.uniformPrefix}_primary`, d[1]), f.usesCellColor && t.setUniform(`${f.uniformPrefix}_cell`, d[2]));
909
+ }
910
+ };
911
+ if (_ && n.pingPongBuffers) {
912
+ const y = n.pingPongBuffers[n.pingPongIndex], g = n.pingPongBuffers[1 - n.pingPongIndex];
913
+ g.begin(), t.clear(), t.shader(n.shader), p(y), t.rect(r.cols, r.rows), g.end(), o.begin(), t.clear(), t.shader(n.shader), p(y), t.rect(r.cols, r.rows), o.end(), n.pingPongIndex = 1 - n.pingPongIndex;
914
+ } else o.begin(), t.clear(), t.shader(n.shader), p(null), t.rect(r.cols, r.rows), o.end();
915
+ }), e.registerLayerDisposedHook((a) => {
916
+ const n = a.getPluginState(b);
917
+ n && (n.shader?.dispose && n.shader.dispose(), n.pingPongBuffers && (n.pingPongBuffers[0].dispose?.(), n.pingPongBuffers[1].dispose?.()));
918
+ });
919
+ }, uninstall(t, e) {
920
+ const a = [e.layerManager.base, ...e.layerManager.all];
921
+ for (const n of a) {
922
+ const r = n.getPluginState(b);
923
+ r && (r.shader?.dispose && r.shader.dispose(), r.pingPongBuffers && (r.pingPongBuffers[0].dispose?.(), r.pingPongBuffers[1].dispose?.()));
924
+ }
925
+ e.removeLayerExtension("synth");
926
+ } };
927
+ Je(), w.registerMany(He), I.setSynthSourceClass(x), I.injectMethods(x.prototype);
928
+ const S = I.generateStandaloneFunctions();
929
+ function ct() {
930
+ return (t, e = 256) => {
931
+ const a = new x();
932
+ return a._charSource = t, a._charCount = e, a;
933
+ };
934
+ }
935
+ const ut = ct(), ft = (t) => {
936
+ const e = new x();
937
+ return e._colorSource = t, e;
938
+ }, pt = (t) => {
939
+ const e = new x();
940
+ return e._cellColorSource = t, e;
941
+ }, mt = (t) => {
942
+ const e = new x();
943
+ return e._colorSource = t, e._cellColorSource = t, e;
944
+ }, dt = S.osc, ht = S.noise, yt = S.voronoi, _t = S.gradient, gt = S.shape, vt = S.solid, xt = lt();
945
+ function lt() {
946
+ const t = S.src;
947
+ return (e) => {
948
+ if (!e) return t();
949
+ const a = new x(), n = e.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
950
+ return a.addExternalLayerRef({ layerId: n, layer: e }), a;
951
+ };
952
+ }
953
+ export {
954
+ it as SynthPlugin,
955
+ x as SynthSource,
956
+ pt as cellColor,
957
+ ut as char,
958
+ ft as charColor,
959
+ _t as gradient,
960
+ ht as noise,
961
+ dt as osc,
962
+ mt as paint,
963
+ gt as shape,
964
+ vt as solid,
965
+ xt as src,
966
+ yt as voronoi
967
+ };