textmode.synth.js 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +104 -121
- package/dist/textmode.synth.esm.js +491 -410
- package/dist/textmode.synth.umd.js +31 -52
- package/dist/types/api/index.d.ts +7 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/sources.d.ts +327 -0
- package/dist/types/api/sources.d.ts.map +1 -0
- package/dist/types/augmentations/index.d.ts +7 -0
- package/dist/types/augmentations/index.d.ts.map +1 -0
- package/dist/types/augmentations/textmode.d.ts +65 -0
- package/dist/types/augmentations/textmode.d.ts.map +1 -0
- package/dist/types/bootstrap.d.ts +11 -0
- package/dist/types/bootstrap.d.ts.map +1 -0
- package/dist/types/compiler/ExternalLayerManager.d.ts +60 -0
- package/dist/types/compiler/ExternalLayerManager.d.ts.map +1 -0
- package/dist/types/compiler/FeedbackTracker.d.ts +53 -0
- package/dist/types/compiler/FeedbackTracker.d.ts.map +1 -0
- package/dist/types/compiler/GLSLGenerator.d.ts +2 -2
- package/dist/types/compiler/GLSLGenerator.d.ts.map +1 -1
- package/dist/types/compiler/SynthCompiler.d.ts +7 -1
- package/dist/types/compiler/SynthCompiler.d.ts.map +1 -1
- package/dist/types/compiler/TransformCodeGenerator.d.ts +77 -0
- package/dist/types/compiler/TransformCodeGenerator.d.ts.map +1 -0
- package/dist/types/compiler/UniformManager.d.ts.map +1 -1
- package/dist/types/compiler/index.d.ts +14 -3
- package/dist/types/compiler/index.d.ts.map +1 -1
- package/dist/types/compiler/types.d.ts +7 -7
- package/dist/types/compiler/types.d.ts.map +1 -1
- package/dist/types/core/GlobalState.d.ts +30 -0
- package/dist/types/core/GlobalState.d.ts.map +1 -0
- package/dist/types/core/ISynthSource.d.ts +173 -202
- package/dist/types/core/ISynthSource.d.ts.map +1 -1
- package/dist/types/core/SynthChain.d.ts +0 -2
- package/dist/types/core/SynthChain.d.ts.map +1 -1
- package/dist/types/core/SynthSource.d.ts +4 -3
- package/dist/types/core/SynthSource.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +9 -3
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +57 -4
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/extensions/index.d.ts +10 -0
- package/dist/types/extensions/index.d.ts.map +1 -0
- package/dist/types/extensions/textmodelayer.d.ts +22 -0
- package/dist/types/extensions/textmodelayer.d.ts.map +1 -0
- package/dist/types/extensions/textmodifier.d.ts +11 -0
- package/dist/types/extensions/textmodifier.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -364
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lifecycle/index.d.ts +10 -0
- package/dist/types/lifecycle/index.d.ts.map +1 -0
- package/dist/types/lifecycle/synthDispose.d.ts +11 -0
- package/dist/types/lifecycle/synthDispose.d.ts.map +1 -0
- package/dist/types/lifecycle/synthRender.d.ts +11 -0
- package/dist/types/lifecycle/synthRender.d.ts.map +1 -0
- package/dist/types/{SynthPlugin.d.ts → plugin/SynthPlugin.d.ts} +1 -1
- package/dist/types/plugin/SynthPlugin.d.ts.map +1 -0
- package/dist/types/plugin/constants.d.ts +5 -0
- package/dist/types/plugin/constants.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +10 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/transforms/TransformDefinition.d.ts +0 -12
- package/dist/types/transforms/TransformDefinition.d.ts.map +1 -1
- package/dist/types/transforms/TransformFactory.d.ts +4 -7
- package/dist/types/transforms/TransformFactory.d.ts.map +1 -1
- package/dist/types/transforms/TransformRegistry.d.ts +3 -6
- package/dist/types/transforms/TransformRegistry.d.ts.map +1 -1
- package/dist/types/transforms/categories/colors.d.ts +1 -1
- package/dist/types/transforms/categories/colors.d.ts.map +1 -1
- package/dist/types/transforms/categories/combine.d.ts.map +1 -1
- package/dist/types/transforms/categories/index.d.ts +3 -4
- package/dist/types/transforms/categories/index.d.ts.map +1 -1
- package/dist/types/transforms/categories/sources.d.ts.map +1 -1
- package/dist/types/{lib → utils}/ArrayUtils.d.ts +20 -5
- package/dist/types/utils/ArrayUtils.d.ts.map +1 -0
- package/dist/types/utils/CharacterResolver.d.ts.map +1 -1
- package/dist/types/utils/collectExternalLayerRefs.d.ts +7 -0
- package/dist/types/utils/collectExternalLayerRefs.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +12 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +16 -9
- package/dist/types/SynthPlugin.d.ts.map +0 -1
- package/dist/types/lib/ArrayUtils.d.ts.map +0 -1
- package/dist/types/transforms/categories/charModifiers.d.ts +0 -16
- package/dist/types/transforms/categories/charModifiers.d.ts.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
3
|
-
const e = Y[t.type],
|
|
4
|
-
${e.returnType} ${t.name}(${
|
|
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}) {
|
|
5
5
|
${t.glsl}
|
|
6
6
|
}`;
|
|
7
|
-
return { ...t, glslFunction:
|
|
7
|
+
return { ...t, glslFunction: a };
|
|
8
8
|
}
|
|
9
9
|
class X {
|
|
10
10
|
_transforms = /* @__PURE__ */ new Map();
|
|
@@ -13,24 +13,24 @@ class X {
|
|
|
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
|
|
16
|
+
for (const n of e) this.register(n);
|
|
17
17
|
}
|
|
18
18
|
get(e) {
|
|
19
19
|
return this._transforms.get(e);
|
|
20
20
|
}
|
|
21
21
|
getProcessed(e) {
|
|
22
|
-
let
|
|
23
|
-
if (!
|
|
24
|
-
const
|
|
25
|
-
|
|
22
|
+
let n = this._processedCache.get(e);
|
|
23
|
+
if (!n) {
|
|
24
|
+
const a = this._transforms.get(e);
|
|
25
|
+
a && (n = E(a), this._processedCache.set(e, n));
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return n;
|
|
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((
|
|
33
|
+
return Array.from(this._transforms.values()).filter((n) => n.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
|
|
55
|
-
class
|
|
54
|
+
const k = new X(), O = /* @__PURE__ */ new Set(["src"]);
|
|
55
|
+
class j {
|
|
56
56
|
_generatedFunctions = {};
|
|
57
57
|
_synthSourceClass = null;
|
|
58
58
|
setSynthSourceClass(e) {
|
|
59
59
|
this._synthSourceClass = e;
|
|
60
60
|
}
|
|
61
61
|
injectMethods(e) {
|
|
62
|
-
const
|
|
63
|
-
for (const
|
|
64
|
-
}
|
|
65
|
-
_injectMethod(e,
|
|
66
|
-
const { name:
|
|
67
|
-
e[
|
|
68
|
-
const
|
|
69
|
-
return this.addCombineTransform(
|
|
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
70
|
} : function(...c) {
|
|
71
|
-
const
|
|
72
|
-
return this.addTransform(
|
|
71
|
+
const s = r.map((l, m) => c[m] ?? l.default);
|
|
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 = {},
|
|
78
|
-
for (const r of
|
|
77
|
+
const e = {}, n = k.getAll(), a = this._synthSourceClass;
|
|
78
|
+
for (const r of n) if (O.has(r.type)) {
|
|
79
79
|
const { name: o, inputs: c } = r;
|
|
80
|
-
e[o] = (...
|
|
81
|
-
const
|
|
82
|
-
return
|
|
80
|
+
e[o] = (...s) => {
|
|
81
|
+
const l = new a(), m = c.map((d, p) => s[p] ?? d.default);
|
|
82
|
+
return l.addTransform(o, m);
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
return this._generatedFunctions = e, e;
|
|
@@ -87,25 +87,25 @@ class B {
|
|
|
87
87
|
getGeneratedFunctions() {
|
|
88
88
|
return this._generatedFunctions;
|
|
89
89
|
}
|
|
90
|
-
addTransform(e,
|
|
91
|
-
if (
|
|
92
|
-
const
|
|
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
93
|
this._generatedFunctions[r] = (...c) => {
|
|
94
|
-
const
|
|
95
|
-
return
|
|
94
|
+
const s = new a(), l = o.map((m, d) => c[d] ?? m.default);
|
|
95
|
+
return s.addTransform(r, l);
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
const
|
|
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: `
|
|
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" },
|
|
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: `
|
|
107
107
|
return vec4(vec3(_noise(vec3(_st * scale, offset * time))), 1.0);
|
|
108
|
-
`, description: "Generate noise pattern" },
|
|
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 I = new B(), E = { 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" },
|
|
132
|
+
`, description: "Generate voronoi pattern" }, G = { 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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
141
141
|
return vec4(r, g, b, a);
|
|
142
|
-
`, description: "Generate solid color" },
|
|
143
|
-
return texture(
|
|
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)." },
|
|
142
|
+
`, description: "Generate solid color" }, H = { name: "src", type: "src", inputs: [], glsl: `
|
|
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: `
|
|
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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
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" },
|
|
160
|
+
`, description: "Scroll coordinates" }, te = { 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" },
|
|
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: `
|
|
165
165
|
vec2 st = _st;
|
|
166
166
|
st.y += scrollY + time * speed;
|
|
167
167
|
return fract(st);
|
|
168
|
-
`, description: "Scroll Y coordinate" },
|
|
168
|
+
`, description: "Scroll Y coordinate" }, re = { 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" },
|
|
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: `
|
|
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" },
|
|
176
|
+
`, description: "Repeat pattern" }, oe = { 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" },
|
|
180
|
+
`, description: "Repeat pattern horizontally" }, se = { 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" },
|
|
184
|
+
`, description: "Repeat pattern vertically" }, ce = { 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,94 +190,94 @@ const I = new B(), E = { 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" },
|
|
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: `
|
|
194
194
|
return vec4(_c0.rgb + vec3(amount), _c0.a);
|
|
195
|
-
`, description: "Adjust brightness" },
|
|
195
|
+
`, description: "Adjust brightness" }, ue = { 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" },
|
|
198
|
+
`, description: "Adjust contrast" }, fe = { 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" },
|
|
200
|
+
`, description: "Invert colors" }, pe = { 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" },
|
|
204
|
+
`, description: "Adjust saturation" }, me = { 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" },
|
|
208
|
+
`, description: "Shift hue" }, de = { 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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
225
225
|
return vec4(vec3(smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb))), _c0.a);
|
|
226
|
-
`, description: "Threshold" },
|
|
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: `
|
|
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" },
|
|
230
|
+
`, description: "Multiply by color" }, ve = { 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" },
|
|
232
|
+
`, description: "Extract red channel" }, xe = { 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" },
|
|
234
|
+
`, description: "Extract green channel" }, Ce = { 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" },
|
|
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: `
|
|
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" },
|
|
243
|
+
`, description: "Shift color channels by adding offset values" }, Se = { 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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
251
251
|
return vec4(clamp(_c0.rgb, vec3(min), vec3(max)), _c0.a);
|
|
252
|
-
`, description: "Clamp color values to a range" },
|
|
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: `
|
|
253
253
|
return (_c0 + _c1) * amount + _c0 * (1.0 - amount);
|
|
254
|
-
`, description: "Add another source" },
|
|
254
|
+
`, description: "Add another source" }, ke = { 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" },
|
|
256
|
+
`, description: "Subtract another source" }, Te = { 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" },
|
|
258
|
+
`, description: "Multiply with another source" }, Le = { 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" },
|
|
260
|
+
`, description: "Blend with another source" }, Pe = { name: "diff", type: "combine", inputs: [], glsl: `
|
|
261
261
|
return vec4(abs(_c0.rgb - _c1.rgb), max(_c0.a, _c1.a));
|
|
262
262
|
`, description: "Difference with another source" }, Ie = { 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" },
|
|
264
|
+
`, description: "Layer another source on top" }, Re = { 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 = [
|
|
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: `
|
|
268
268
|
return _st + _c0.xy * amount;
|
|
269
|
-
`, description: "Modulate coordinates with another source" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
281
281
|
vec2 xy = vec2(offset + _c0.x * multiple, offset + _c0.y * multiple);
|
|
282
282
|
return (floor(_st * xy) + 0.5) / xy;
|
|
283
283
|
`, description: "Modulate pixelation with another source" }, Ve = { name: "modulateKaleid", type: "combineCoord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
|
|
@@ -292,7 +292,7 @@ const I = new B(), E = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
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" },
|
|
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: `
|
|
296
296
|
vec2 st = _st;
|
|
297
297
|
st.y += _c0.r * scrollY + time * speed;
|
|
298
298
|
return fract(st);
|
|
@@ -301,48 +301,27 @@ const I = new B(), E = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
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" },
|
|
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: `
|
|
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" },
|
|
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: `
|
|
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" },
|
|
312
|
+
`, description: "Modulate Y repeat with another source" }, Ne = { 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" },
|
|
315
|
-
|
|
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 {
|
|
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 {
|
|
337
316
|
_transforms;
|
|
338
317
|
constructor(e) {
|
|
339
318
|
this._transforms = e;
|
|
340
319
|
}
|
|
341
320
|
static empty() {
|
|
342
|
-
return new
|
|
321
|
+
return new w([]);
|
|
343
322
|
}
|
|
344
323
|
static from(e) {
|
|
345
|
-
return new
|
|
324
|
+
return new w([...e]);
|
|
346
325
|
}
|
|
347
326
|
get transforms() {
|
|
348
327
|
return this._transforms;
|
|
@@ -357,7 +336,7 @@ class M {
|
|
|
357
336
|
return this._transforms.length === 0;
|
|
358
337
|
}
|
|
359
338
|
append(e) {
|
|
360
|
-
return new
|
|
339
|
+
return new w([...this._transforms, e]);
|
|
361
340
|
}
|
|
362
341
|
get(e) {
|
|
363
342
|
return this._transforms[e];
|
|
@@ -366,7 +345,7 @@ class M {
|
|
|
366
345
|
return this._transforms[Symbol.iterator]();
|
|
367
346
|
}
|
|
368
347
|
}
|
|
369
|
-
class
|
|
348
|
+
class b {
|
|
370
349
|
_chain;
|
|
371
350
|
_charMapping;
|
|
372
351
|
_nestedSources;
|
|
@@ -376,30 +355,30 @@ class x {
|
|
|
376
355
|
_charSource;
|
|
377
356
|
_charCount;
|
|
378
357
|
constructor(e) {
|
|
379
|
-
this._chain = e?.chain ??
|
|
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();
|
|
380
359
|
}
|
|
381
|
-
addTransform(e,
|
|
382
|
-
const
|
|
383
|
-
return this._chain.push(
|
|
360
|
+
addTransform(e, n) {
|
|
361
|
+
const a = { name: e, userArgs: n };
|
|
362
|
+
return this._chain.push(a), this;
|
|
384
363
|
}
|
|
385
|
-
addCombineTransform(e,
|
|
364
|
+
addCombineTransform(e, n, a) {
|
|
386
365
|
const r = this._chain.length;
|
|
387
|
-
return this._nestedSources.set(r,
|
|
366
|
+
return this._nestedSources.set(r, n), this.addTransform(e, a);
|
|
388
367
|
}
|
|
389
368
|
addExternalLayerRef(e) {
|
|
390
|
-
const
|
|
391
|
-
return this._externalLayerRefs.set(
|
|
369
|
+
const n = this._chain.length;
|
|
370
|
+
return this._externalLayerRefs.set(n, e), this.addTransform("src", []);
|
|
392
371
|
}
|
|
393
372
|
charMap(e) {
|
|
394
|
-
const
|
|
395
|
-
for (const r of
|
|
396
|
-
return this._charMapping = { chars: e, indices:
|
|
373
|
+
const n = Array.from(e), a = [];
|
|
374
|
+
for (const r of n) a.push(r.codePointAt(0) ?? 32);
|
|
375
|
+
return this._charMapping = { chars: e, indices: a }, this;
|
|
397
376
|
}
|
|
398
377
|
charColor(e) {
|
|
399
378
|
return this._colorSource = e, this;
|
|
400
379
|
}
|
|
401
|
-
char(e,
|
|
402
|
-
return this._charSource = e, this._charCount =
|
|
380
|
+
char(e, n) {
|
|
381
|
+
return this._charSource = e, this._charCount = n, this;
|
|
403
382
|
}
|
|
404
383
|
cellColor(e) {
|
|
405
384
|
return this._cellColorSource = e, this;
|
|
@@ -409,10 +388,10 @@ class x {
|
|
|
409
388
|
}
|
|
410
389
|
clone() {
|
|
411
390
|
const e = /* @__PURE__ */ new Map();
|
|
412
|
-
for (const [
|
|
413
|
-
const
|
|
414
|
-
for (const [
|
|
415
|
-
return new
|
|
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 });
|
|
416
395
|
}
|
|
417
396
|
get transforms() {
|
|
418
397
|
return this._chain.transforms;
|
|
@@ -439,63 +418,197 @@ class x {
|
|
|
439
418
|
return this._externalLayerRefs;
|
|
440
419
|
}
|
|
441
420
|
}
|
|
442
|
-
const
|
|
421
|
+
const I = { 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
422
|
function T(t, e) {
|
|
444
423
|
return (t % e + e) % e;
|
|
445
424
|
}
|
|
446
|
-
function
|
|
447
|
-
return (t - e) * (r -
|
|
425
|
+
function Ke(t, e, n, a, r) {
|
|
426
|
+
return (t - e) * (r - a) / (n - e) + a;
|
|
448
427
|
}
|
|
449
|
-
function
|
|
428
|
+
function Qe() {
|
|
450
429
|
"fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
|
|
451
430
|
return this._speed = t, this;
|
|
452
431
|
}, Array.prototype.smooth = function(t = 1) {
|
|
453
432
|
return this._smooth = t, this;
|
|
454
433
|
}, Array.prototype.ease = function(t = "linear") {
|
|
455
|
-
return typeof t == "function" ? (this._smooth = 1, this._ease = t) :
|
|
434
|
+
return typeof t == "function" ? (this._smooth = 1, this._ease = t) : I[t] && (this._smooth = 1, this._ease = I[t]), this;
|
|
456
435
|
}, Array.prototype.offset = function(t = 0.5) {
|
|
457
436
|
return this._offset = t % 1, this;
|
|
458
437
|
}, Array.prototype.fit = function(t = 0, e = 1) {
|
|
459
|
-
const
|
|
438
|
+
const n = Math.min(...this), a = Math.max(...this), r = this.map((o) => Ke(o, n, a, t, e));
|
|
460
439
|
return r._speed = this._speed, r._smooth = this._smooth, r._ease = this._ease, r._offset = this._offset, r;
|
|
461
440
|
});
|
|
462
441
|
}
|
|
463
|
-
function
|
|
464
|
-
const
|
|
465
|
-
let r = e.time *
|
|
466
|
-
if (
|
|
467
|
-
const o = t._ease ??
|
|
468
|
-
return o(Math.min(T(c, 1) /
|
|
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);
|
|
445
|
+
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;
|
|
469
448
|
}
|
|
470
449
|
return t[Math.floor(T(r, t.length))];
|
|
471
450
|
}
|
|
472
|
-
function
|
|
451
|
+
function We(t) {
|
|
473
452
|
return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
|
|
474
453
|
}
|
|
454
|
+
Qe(), k.registerMany(Ge), P.setSynthSourceClass(b), P.injectMethods(b.prototype);
|
|
455
|
+
const M = P.generateStandaloneFunctions(), C = "textmode.synth.js";
|
|
456
|
+
class Je {
|
|
457
|
+
_usesFeedback = !1;
|
|
458
|
+
_usesCharFeedback = !1;
|
|
459
|
+
_usesCellColorFeedback = !1;
|
|
460
|
+
trackUsage(e) {
|
|
461
|
+
switch (e) {
|
|
462
|
+
case "char":
|
|
463
|
+
this._usesCharFeedback = !0;
|
|
464
|
+
break;
|
|
465
|
+
case "cellColor":
|
|
466
|
+
this._usesCellColorFeedback = !0;
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
this._usesFeedback = !0;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
reset() {
|
|
473
|
+
this._usesFeedback = !1, this._usesCharFeedback = !1, this._usesCellColorFeedback = !1;
|
|
474
|
+
}
|
|
475
|
+
getUsage() {
|
|
476
|
+
return { usesCharColorFeedback: this._usesFeedback, usesCharFeedback: this._usesCharFeedback, usesCellColorFeedback: this._usesCellColorFeedback };
|
|
477
|
+
}
|
|
478
|
+
get usesAnyFeedback() {
|
|
479
|
+
return this._usesFeedback || this._usesCharFeedback || this._usesCellColorFeedback;
|
|
480
|
+
}
|
|
481
|
+
get usesCharColorFeedback() {
|
|
482
|
+
return this._usesFeedback;
|
|
483
|
+
}
|
|
484
|
+
get usesCharFeedback() {
|
|
485
|
+
return this._usesCharFeedback;
|
|
486
|
+
}
|
|
487
|
+
get usesCellColorFeedback() {
|
|
488
|
+
return this._usesCellColorFeedback;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
class Ze {
|
|
492
|
+
_externalLayers = /* @__PURE__ */ new Map();
|
|
493
|
+
_counter = 0;
|
|
494
|
+
_layerIdToPrefix = /* @__PURE__ */ new Map();
|
|
495
|
+
getPrefix(e) {
|
|
496
|
+
let n = this._layerIdToPrefix.get(e);
|
|
497
|
+
return n || (n = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, n)), n;
|
|
498
|
+
}
|
|
499
|
+
trackUsage(e, n) {
|
|
500
|
+
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) {
|
|
503
|
+
case "char":
|
|
504
|
+
r.usesChar = !0;
|
|
505
|
+
break;
|
|
506
|
+
case "cellColor":
|
|
507
|
+
r.usesCellColor = !0;
|
|
508
|
+
break;
|
|
509
|
+
default:
|
|
510
|
+
r.usesCharColor = !0;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
hasLayer(e) {
|
|
514
|
+
return this._externalLayers.has(e);
|
|
515
|
+
}
|
|
516
|
+
getLayerInfo(e) {
|
|
517
|
+
return this._externalLayers.get(e);
|
|
518
|
+
}
|
|
519
|
+
getExternalLayers() {
|
|
520
|
+
return new Map(this._externalLayers);
|
|
521
|
+
}
|
|
522
|
+
get hasExternalLayers() {
|
|
523
|
+
return this._externalLayers.size > 0;
|
|
524
|
+
}
|
|
525
|
+
get count() {
|
|
526
|
+
return this._externalLayers.size;
|
|
527
|
+
}
|
|
528
|
+
reset() {
|
|
529
|
+
this._externalLayers.clear(), this._counter = 0, this._layerIdToPrefix.clear();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const et = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
|
|
475
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) {
|
|
544
|
+
case "src": {
|
|
545
|
+
const _ = `c${a}`;
|
|
546
|
+
e.push(` vec4 ${_} = ${u}(${y(r)});`), i = _;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case "coord": {
|
|
550
|
+
const _ = `st${a}`;
|
|
551
|
+
e.push(` vec2 ${_} = ${u}(${y(r)});`), e.push(` ${r} = ${_};`);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case "color": {
|
|
555
|
+
const _ = `c${a}`;
|
|
556
|
+
e.push(` vec4 ${_} = ${u}(${y(o)});`), i = _;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case "combine": {
|
|
560
|
+
const _ = `c${a}`;
|
|
561
|
+
e.push(` vec4 ${_} = ${u}(${y(o, p ?? "vec4(0.0)")});`), i = _;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case "combineCoord": {
|
|
565
|
+
const _ = `st${a}`;
|
|
566
|
+
e.push(` vec2 ${_} = ${u}(${y(r, p ?? "vec4(0.0)")});`), e.push(` ${r} = ${_};`);
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return { colorVar: i, charVar: f, flagsVar: g, rotationVar: F };
|
|
571
|
+
}
|
|
572
|
+
_generateExternalSrcFunction(e, n, a) {
|
|
573
|
+
const r = a(e.layerId);
|
|
574
|
+
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));
|
|
577
|
+
}
|
|
578
|
+
`;
|
|
579
|
+
}
|
|
580
|
+
_generateSelfFeedbackSrcFunction(e) {
|
|
581
|
+
return `
|
|
582
|
+
vec4 ${`src_${e}`}(vec2 _st) {
|
|
583
|
+
return texture(${et[e]}, fract(_st));
|
|
584
|
+
}
|
|
585
|
+
`;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
class nt {
|
|
476
589
|
_uniforms = /* @__PURE__ */ new Map();
|
|
477
590
|
_dynamicUpdaters = /* @__PURE__ */ new Map();
|
|
478
|
-
processArgument(e,
|
|
479
|
-
if (
|
|
480
|
-
const r = `${
|
|
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);
|
|
481
594
|
return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, c), { glslValue: r, uniform: o, updater: c };
|
|
482
595
|
}
|
|
483
596
|
if (typeof e == "function") {
|
|
484
|
-
const r = `${
|
|
597
|
+
const r = `${a}_${n.name}`, o = { name: r, type: n.type, value: n.default ?? 0, isDynamic: !0 };
|
|
485
598
|
return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, e), { glslValue: r, uniform: o, updater: e };
|
|
486
599
|
}
|
|
487
|
-
if (typeof e == "number") return { glslValue:
|
|
600
|
+
if (typeof e == "number") return { glslValue: x(e) };
|
|
488
601
|
if (Array.isArray(e) && typeof e[0] == "number") {
|
|
489
602
|
const r = e;
|
|
490
|
-
if (r.length === 2) return { glslValue: `vec2(${
|
|
491
|
-
if (r.length === 3) return { glslValue: `vec3(${
|
|
492
|
-
if (r.length === 4) return { glslValue: `vec4(${
|
|
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])})` };
|
|
493
606
|
}
|
|
494
|
-
return this.processDefault(
|
|
607
|
+
return this.processDefault(n);
|
|
495
608
|
}
|
|
496
609
|
processDefault(e) {
|
|
497
|
-
const
|
|
498
|
-
return typeof
|
|
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" };
|
|
499
612
|
}
|
|
500
613
|
getUniforms() {
|
|
501
614
|
return new Map(this._uniforms);
|
|
@@ -507,11 +620,11 @@ class tt {
|
|
|
507
620
|
this._uniforms.clear(), this._dynamicUpdaters.clear();
|
|
508
621
|
}
|
|
509
622
|
}
|
|
510
|
-
function
|
|
623
|
+
function x(t) {
|
|
511
624
|
const e = t.toString();
|
|
512
625
|
return e.includes(".") ? e : e + ".0";
|
|
513
626
|
}
|
|
514
|
-
const
|
|
627
|
+
const rt = `
|
|
515
628
|
// Utility functions
|
|
516
629
|
float _luminance(vec3 rgb) {
|
|
517
630
|
const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
|
@@ -608,22 +721,22 @@ float _noise(vec3 v) {
|
|
|
608
721
|
return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
|
|
609
722
|
}
|
|
610
723
|
`;
|
|
611
|
-
function
|
|
612
|
-
const { uniforms: e, glslFunctions:
|
|
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(`
|
|
613
726
|
`);
|
|
614
|
-
let
|
|
615
|
-
|
|
616
|
-
uniform int u_charMapSize;`,
|
|
727
|
+
let h = "", u = "";
|
|
728
|
+
s && (h = `uniform int u_charMap[${s.indices.length}];
|
|
729
|
+
uniform int u_charMapSize;`, u = `
|
|
617
730
|
// Apply character mapping
|
|
618
731
|
int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
|
|
619
732
|
int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
|
|
620
733
|
charOutput.r = float(mappedCharIdx % 256) / 255.0;
|
|
621
734
|
charOutput.g = float(mappedCharIdx / 256) / 255.0;`);
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
`),
|
|
626
|
-
if (p) for (const [,
|
|
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;`);
|
|
627
740
|
return `#version 300 es
|
|
628
741
|
precision highp float;
|
|
629
742
|
|
|
@@ -638,28 +751,28 @@ layout(location = 2) out vec4 o_secondaryColor;
|
|
|
638
751
|
// Standard uniforms
|
|
639
752
|
uniform float time;
|
|
640
753
|
uniform vec2 resolution;
|
|
641
|
-
${
|
|
642
|
-
${
|
|
643
|
-
${
|
|
754
|
+
${i}
|
|
755
|
+
${f.length > 0 ? `// External layer samplers
|
|
756
|
+
${f.join(`
|
|
644
757
|
`)}` : ""}
|
|
645
|
-
${
|
|
758
|
+
${h}
|
|
646
759
|
|
|
647
760
|
// Dynamic uniforms
|
|
648
|
-
${
|
|
761
|
+
${v}
|
|
649
762
|
|
|
650
|
-
${
|
|
763
|
+
${rt}
|
|
651
764
|
|
|
652
765
|
// Transform functions
|
|
653
|
-
${Array.from(
|
|
766
|
+
${Array.from(n).join(`
|
|
654
767
|
`)}
|
|
655
768
|
|
|
656
769
|
void main() {
|
|
657
770
|
// Transform chain
|
|
658
|
-
${
|
|
771
|
+
${a.join(`
|
|
659
772
|
`)}
|
|
660
773
|
|
|
661
774
|
${r}
|
|
662
|
-
${
|
|
775
|
+
${u}
|
|
663
776
|
|
|
664
777
|
// Output to MRT
|
|
665
778
|
o_character = charOutput;
|
|
@@ -668,300 +781,268 @@ ${m}
|
|
|
668
781
|
}
|
|
669
782
|
`;
|
|
670
783
|
}
|
|
671
|
-
function
|
|
784
|
+
function ot(t, e, n) {
|
|
672
785
|
return t ? `
|
|
673
786
|
// Character output from generator
|
|
674
787
|
vec4 charOutput = ${e};` : `
|
|
675
788
|
// Derive character from color luminance
|
|
676
|
-
float lum = _luminance(${
|
|
789
|
+
float lum = _luminance(${n}.rgb);
|
|
677
790
|
int charIdx = int(lum * 255.0);
|
|
678
791
|
vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`;
|
|
679
792
|
}
|
|
680
793
|
function R(t) {
|
|
681
|
-
return new
|
|
794
|
+
return new st().compile(t);
|
|
682
795
|
}
|
|
683
|
-
class
|
|
684
|
-
|
|
685
|
-
|
|
796
|
+
class st {
|
|
797
|
+
_uniformManager = new nt();
|
|
798
|
+
_feedbackTracker = new Je();
|
|
799
|
+
_externalLayerManager = new Ze();
|
|
800
|
+
_codeGenerator = new tt();
|
|
686
801
|
_glslFunctions = /* @__PURE__ */ new Set();
|
|
687
802
|
_mainCode = [];
|
|
688
|
-
|
|
689
|
-
_usesCharFeedback = !1;
|
|
690
|
-
_usesCellColorFeedback = !1;
|
|
803
|
+
_varCounter = 0;
|
|
691
804
|
_currentTarget = "main";
|
|
692
|
-
_externalLayers = /* @__PURE__ */ new Map();
|
|
693
|
-
_externalLayerCounter = 0;
|
|
694
|
-
_layerIdToPrefix = /* @__PURE__ */ new Map();
|
|
695
805
|
compile(e) {
|
|
696
|
-
this.
|
|
697
|
-
const
|
|
698
|
-
let
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
806
|
+
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;
|
|
809
|
+
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);
|
|
812
|
+
let o = "vec4(0.0, 0.0, 0.0, 0.0)";
|
|
813
|
+
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() };
|
|
816
|
+
}
|
|
817
|
+
_reset() {
|
|
818
|
+
this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main";
|
|
819
|
+
}
|
|
820
|
+
_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;
|
|
823
|
+
}
|
|
824
|
+
_compileChain(e, n, a, r = "v_uv", o = "main") {
|
|
711
825
|
const c = this._currentTarget;
|
|
712
826
|
this._currentTarget = o;
|
|
713
|
-
const
|
|
714
|
-
let
|
|
715
|
-
this._mainCode.push(` vec2 ${
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
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);
|
|
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);
|
|
838
|
+
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);
|
|
743
842
|
};
|
|
744
|
-
for (let
|
|
745
|
-
for (let
|
|
746
|
-
const
|
|
747
|
-
(!
|
|
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);
|
|
748
847
|
}
|
|
749
|
-
return this._currentTarget = c, { coordVar:
|
|
750
|
-
}
|
|
751
|
-
_getProcessedTransform(e) {
|
|
752
|
-
return w.getProcessed(e);
|
|
848
|
+
return this._currentTarget = c, { coordVar: s, colorVar: p, charVar: l, flagsVar: m, rotationVar: d };
|
|
753
849
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
vec4 ${`src_ext_${o}_${this._currentTarget}`}(vec2 _st) {
|
|
760
|
-
return texture(${c}, fract(_st));
|
|
761
|
-
}
|
|
762
|
-
`;
|
|
850
|
+
_identifyCoordTransforms(e) {
|
|
851
|
+
const n = [];
|
|
852
|
+
for (let a = 0; a < e.length; a++) {
|
|
853
|
+
const r = e[a];
|
|
854
|
+
r && (r.type !== "coord" && r.type !== "combineCoord" || n.push(a));
|
|
763
855
|
}
|
|
764
|
-
|
|
765
|
-
return `
|
|
766
|
-
vec4 ${`src_${this._currentTarget}`}(vec2 _st) {
|
|
767
|
-
return texture(${r}, fract(_st));
|
|
768
|
-
}
|
|
769
|
-
`;
|
|
856
|
+
return n;
|
|
770
857
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
return a || (a = "extLayer" + this._externalLayerCounter++, this._layerIdToPrefix.set(e, a)), a;
|
|
858
|
+
_trackSrcUsage(e) {
|
|
859
|
+
e ? this._externalLayerManager.trackUsage(e, this._currentTarget) : this._feedbackTracker.trackUsage(this._currentTarget);
|
|
774
860
|
}
|
|
775
|
-
|
|
776
|
-
|
|
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
|
-
}
|
|
861
|
+
_getProcessedTransform(e) {
|
|
862
|
+
return k.getProcessed(e);
|
|
788
863
|
}
|
|
789
|
-
_processArguments(e,
|
|
864
|
+
_processArguments(e, n, a) {
|
|
790
865
|
const r = [];
|
|
791
|
-
for (let o = 0; o <
|
|
792
|
-
const c =
|
|
793
|
-
r.push(
|
|
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);
|
|
794
869
|
}
|
|
795
870
|
return r;
|
|
796
871
|
}
|
|
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
872
|
}
|
|
834
|
-
class
|
|
873
|
+
class ct {
|
|
835
874
|
_resolvedIndices;
|
|
836
875
|
_lastFontCharacterCount = 0;
|
|
837
876
|
_lastChars = "";
|
|
838
|
-
resolve(e,
|
|
839
|
-
const
|
|
840
|
-
if (this._resolvedIndices && this._lastFontCharacterCount ===
|
|
841
|
-
const r = Array.from(e), o = new Int32Array(r.length), c =
|
|
842
|
-
for (let
|
|
843
|
-
const
|
|
844
|
-
if (
|
|
877
|
+
resolve(e, n) {
|
|
878
|
+
const a = n.characters.length;
|
|
879
|
+
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);
|
|
845
884
|
else {
|
|
846
885
|
const p = c.get(" ");
|
|
847
|
-
o[
|
|
886
|
+
o[l] = p !== void 0 ? s.indexOf(p) : 0;
|
|
848
887
|
}
|
|
849
888
|
}
|
|
850
|
-
return this._resolvedIndices = o, this._lastFontCharacterCount =
|
|
889
|
+
return this._resolvedIndices = o, this._lastFontCharacterCount = a, this._lastChars = e, o;
|
|
851
890
|
}
|
|
852
891
|
invalidate() {
|
|
853
892
|
this._resolvedIndices = void 0, this._lastFontCharacterCount = 0, this._lastChars = "";
|
|
854
893
|
}
|
|
855
894
|
}
|
|
856
|
-
|
|
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 };
|
|
897
|
+
}
|
|
898
|
+
function lt(t) {
|
|
899
|
+
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);
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
function it(t) {
|
|
906
|
+
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));
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function ut(t) {
|
|
912
|
+
t.extendLayer("bpm", function(e) {
|
|
913
|
+
let n = this.getPluginState(C);
|
|
914
|
+
n ? n.bpm = e : n = U({ bpm: e }), this.setPluginState(C, n);
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
let B = 60;
|
|
918
|
+
function ft(t) {
|
|
919
|
+
B = t;
|
|
920
|
+
}
|
|
921
|
+
function pt() {
|
|
922
|
+
return B;
|
|
923
|
+
}
|
|
924
|
+
function mt(t) {
|
|
925
|
+
t.bpm = function(e) {
|
|
926
|
+
return ft(e), e;
|
|
927
|
+
};
|
|
928
|
+
}
|
|
857
929
|
function $(t) {
|
|
858
930
|
const e = /* @__PURE__ */ new Map();
|
|
859
|
-
for (const [,
|
|
860
|
-
for (const [,
|
|
861
|
-
const
|
|
862
|
-
for (const [r, o] of
|
|
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);
|
|
863
935
|
}
|
|
864
936
|
if (t.charSource) {
|
|
865
|
-
const
|
|
866
|
-
for (const [
|
|
937
|
+
const n = $(t.charSource);
|
|
938
|
+
for (const [a, r] of n) e.set(a, r);
|
|
867
939
|
}
|
|
868
940
|
if (t.colorSource) {
|
|
869
|
-
const
|
|
870
|
-
for (const [
|
|
941
|
+
const n = $(t.colorSource);
|
|
942
|
+
for (const [a, r] of n) e.set(a, r);
|
|
871
943
|
}
|
|
872
944
|
if (t.cellColorSource) {
|
|
873
|
-
const
|
|
874
|
-
for (const [
|
|
945
|
+
const n = $(t.cellColorSource);
|
|
946
|
+
for (const [a, r] of n) e.set(a, r);
|
|
875
947
|
}
|
|
876
948
|
return e;
|
|
877
949
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
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]));
|
|
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) => {
|
|
958
|
+
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);
|
|
964
|
+
}
|
|
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}`);
|
|
971
|
+
continue;
|
|
909
972
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
const n =
|
|
917
|
-
|
|
918
|
-
});
|
|
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]));
|
|
976
|
+
}
|
|
977
|
+
};
|
|
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();
|
|
982
|
+
}
|
|
983
|
+
function ht(t) {
|
|
984
|
+
const e = t.getPluginState(C);
|
|
985
|
+
e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()));
|
|
986
|
+
}
|
|
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);
|
|
919
989
|
}, uninstall(t, e) {
|
|
920
|
-
const
|
|
921
|
-
for (const
|
|
922
|
-
const r =
|
|
990
|
+
const n = [e.layerManager.base, ...e.layerManager.all];
|
|
991
|
+
for (const a of n) {
|
|
992
|
+
const r = a.getPluginState(C);
|
|
923
993
|
r && (r.shader?.dispose && r.shader.dispose(), r.pingPongBuffers && (r.pingPongBuffers[0].dispose?.(), r.pingPongBuffers[1].dispose?.()));
|
|
924
994
|
}
|
|
925
|
-
e.removeLayerExtension("synth");
|
|
926
|
-
} }
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
}
|
|
935
|
-
const ut = ct(), ft = (t) => {
|
|
936
|
-
const e = new x();
|
|
995
|
+
delete t.bpm, e.removeLayerExtension("synth"), e.removeLayerExtension("bpm"), e.removeLayerExtension("clearSynth");
|
|
996
|
+
} }, gt = (t) => {
|
|
997
|
+
const e = new b();
|
|
998
|
+
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();
|
|
937
1004
|
return e._colorSource = t, e;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
return
|
|
941
|
-
}
|
|
942
|
-
|
|
1005
|
+
};
|
|
1006
|
+
function xt(t) {
|
|
1007
|
+
return M.gradient(t);
|
|
1008
|
+
}
|
|
1009
|
+
function Ct(t, e) {
|
|
1010
|
+
return M.noise(t, e);
|
|
1011
|
+
}
|
|
1012
|
+
function bt(t, e, n) {
|
|
1013
|
+
return M.osc(t, e, n);
|
|
1014
|
+
}
|
|
1015
|
+
const St = (t) => {
|
|
1016
|
+
const e = new b();
|
|
943
1017
|
return e._colorSource = t, e._cellColorSource = t, e;
|
|
944
|
-
}
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1018
|
+
};
|
|
1019
|
+
function Mt(t, e, n) {
|
|
1020
|
+
return M.shape(t, e, n);
|
|
1021
|
+
}
|
|
1022
|
+
function $t(t, e, n, a) {
|
|
1023
|
+
return M.solid(t, e, n, a);
|
|
1024
|
+
}
|
|
1025
|
+
const wt = (t) => {
|
|
1026
|
+
const e = M.src;
|
|
1027
|
+
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;
|
|
1030
|
+
};
|
|
1031
|
+
function Ft(t, e, n) {
|
|
1032
|
+
return M.voronoi(t, e, n);
|
|
952
1033
|
}
|
|
953
1034
|
export {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
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
|
|
967
1048
|
};
|