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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  const X = { src: { returnType: "vec4", args: [{ type: "vec2", name: "_st" }] }, coord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }] }, color: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }] }, combine: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }, { type: "vec4", name: "_c1" }] }, combineCoord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }, { type: "vec4", name: "_c0" }] } };
2
2
  function D(t) {
3
- const e = X[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}) {
3
+ const e = X[t.type], r = [...e.args, ...t.inputs.map((n) => ({ type: n.type, name: n.name }))].map((n) => `${n.type} ${n.name}`).join(", "), a = `
4
+ ${e.returnType} ${t.name}(${r}) {
5
5
  ${t.glsl}
6
6
  }`;
7
7
  return { ...t, glslFunction: a };
@@ -13,24 +13,24 @@ class j {
13
13
  this._transforms.has(e.name) && console.warn(`[TransformRegistry] Overwriting existing transform: ${e.name}`), this._transforms.set(e.name, e), this._processedCache.delete(e.name);
14
14
  }
15
15
  registerMany(e) {
16
- for (const n of e) this.register(n);
16
+ for (const r of e) this.register(r);
17
17
  }
18
18
  get(e) {
19
19
  return this._transforms.get(e);
20
20
  }
21
21
  getProcessed(e) {
22
- let n = this._processedCache.get(e);
23
- if (!n) {
22
+ let r = this._processedCache.get(e);
23
+ if (!r) {
24
24
  const a = this._transforms.get(e);
25
- a && (n = D(a), this._processedCache.set(e, n));
25
+ a && (r = D(a), this._processedCache.set(e, r));
26
26
  }
27
- return n;
27
+ return r;
28
28
  }
29
29
  has(e) {
30
30
  return this._transforms.has(e);
31
31
  }
32
32
  getByType(e) {
33
- return Array.from(this._transforms.values()).filter((n) => n.type === e);
33
+ return Array.from(this._transforms.values()).filter((r) => r.type === e);
34
34
  }
35
35
  getNames() {
36
36
  return Array.from(this._transforms.keys());
@@ -59,26 +59,26 @@ class G {
59
59
  this._synthSourceClass = e;
60
60
  }
61
61
  injectMethods(e) {
62
- const n = k.getAll();
63
- for (const a of n) this._injectMethod(e, a);
64
- }
65
- _injectMethod(e, n) {
66
- const { name: a, inputs: r, type: o } = n;
67
- e[a] = o === "combine" || o === "combineCoord" ? function(c, ...s) {
68
- const i = r.map((m, h) => s[h] ?? m.default);
69
- return this.addCombineTransform(a, c, i);
70
- } : function(...c) {
71
- const s = r.map((i, m) => c[m] ?? i.default);
62
+ const r = k.getAll();
63
+ for (const a of r) this._injectMethod(e, a);
64
+ }
65
+ _injectMethod(e, r) {
66
+ const { name: a, inputs: n, type: o } = r;
67
+ e[a] = o === "combine" || o === "combineCoord" ? function(l, ...s) {
68
+ const i = n.map((m, h) => s[h] ?? m.default);
69
+ return this.addCombineTransform(a, l, i);
70
+ } : function(...l) {
71
+ const s = n.map((i, m) => l[m] ?? i.default);
72
72
  return this.addTransform(a, s);
73
73
  };
74
74
  }
75
75
  generateStandaloneFunctions() {
76
76
  if (!this._synthSourceClass) throw new Error("[TransformFactory] SynthSource class not set. Call setSynthSourceClass first.");
77
- const e = {}, n = k.getAll(), a = this._synthSourceClass;
78
- for (const r of n) if (O.has(r.type)) {
79
- const { name: o, inputs: c } = r;
77
+ const e = {}, r = k.getAll(), a = this._synthSourceClass;
78
+ for (const n of r) if (O.has(n.type)) {
79
+ const { name: o, inputs: l } = n;
80
80
  e[o] = (...s) => {
81
- const i = new a(), m = c.map((h, y) => s[y] ?? h.default);
81
+ const i = new a(), m = l.map((h, y) => s[y] ?? h.default);
82
82
  return i.addTransform(o, m);
83
83
  };
84
84
  }
@@ -87,12 +87,12 @@ class G {
87
87
  getGeneratedFunctions() {
88
88
  return this._generatedFunctions;
89
89
  }
90
- addTransform(e, n) {
91
- if (k.register(e), n && this._injectMethod(n, e), O.has(e.type) && this._synthSourceClass) {
92
- const a = this._synthSourceClass, { name: r, inputs: o } = e;
93
- this._generatedFunctions[r] = (...c) => {
94
- const s = new a(), i = o.map((m, h) => c[h] ?? m.default);
95
- return s.addTransform(r, i);
90
+ addTransform(e, r) {
91
+ if (k.register(e), r && this._injectMethod(r, e), O.has(e.type) && this._synthSourceClass) {
92
+ const a = this._synthSourceClass, { name: n, inputs: o } = e;
93
+ this._generatedFunctions[n] = (...l) => {
94
+ const s = new a(), i = o.map((m, h) => l[h] ?? m.default);
95
+ return s.addTransform(n, i);
96
96
  };
97
97
  }
98
98
  }
@@ -147,12 +147,12 @@ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency",
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" }, ne = { name: "scale", type: "coord", inputs: [{ name: "amount", type: "float", default: 1.5 }, { name: "xMult", type: "float", default: 1 }, { name: "yMult", type: "float", default: 1 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
150
+ `, description: "Rotate coordinates" }, re = { name: "scale", type: "coord", inputs: [{ name: "amount", type: "float", default: 1.5 }, { name: "xMult", type: "float", default: 1 }, { name: "yMult", type: "float", default: 1 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
151
151
  vec2 xy = _st - vec2(offsetX, offsetY);
152
152
  xy *= (1.0 / vec2(amount * xMult, amount * yMult));
153
153
  xy += vec2(offsetX, offsetY);
154
154
  return xy;
155
- `, description: "Scale coordinates" }, re = { name: "scroll", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "scrollY", type: "float", default: 0.5 }, { name: "speedX", type: "float", default: 0 }, { name: "speedY", type: "float", default: 0 }], glsl: `
155
+ `, description: "Scale coordinates" }, ne = { name: "scroll", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "scrollY", type: "float", default: 0.5 }, { name: "speedX", type: "float", default: 0 }, { name: "speedY", type: "float", default: 0 }], glsl: `
156
156
  vec2 st = _st;
157
157
  st.x += scrollX + time * speedX;
158
158
  st.y += scrollY + time * speedY;
@@ -190,7 +190,7 @@ const P = new G(), q = { 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" }, fe = [te, ne, re, ae, oe, se, ce, le, ie, ue], pe = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
193
+ `, description: "Kaleidoscope effect" }, fe = [te, re, ne, ae, oe, se, ce, le, ie, ue], pe = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
194
194
  return vec4(_c0.rgb + vec3(amount), _c0.a);
195
195
  `, description: "Adjust brightness" }, me = { name: "contrast", type: "color", inputs: [{ name: "amount", type: "float", default: 1.6 }], glsl: `
196
196
  vec4 c = (_c0 - vec4(0.5)) * vec4(amount) + vec4(0.5);
@@ -312,16 +312,16 @@ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency",
312
312
  `, description: "Modulate Y repeat with another source" }, Ke = { name: "modulateHue", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
313
313
  return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0 / resolution);
314
314
  `, description: "Modulate coordinates based on hue differences" }, Qe = [Ve, Ee, Be, Ne, Ye, Xe, De, je, Ge, qe, Ke], He = [...ee, ...fe, ...Te, ...Ue, ...Qe];
315
- class w {
315
+ class F {
316
316
  _transforms;
317
317
  constructor(e) {
318
318
  this._transforms = e;
319
319
  }
320
320
  static empty() {
321
- return new w([]);
321
+ return new F([]);
322
322
  }
323
323
  static from(e) {
324
- return new w([...e]);
324
+ return new F([...e]);
325
325
  }
326
326
  get transforms() {
327
327
  return this._transforms;
@@ -336,7 +336,7 @@ class w {
336
336
  return this._transforms.length === 0;
337
337
  }
338
338
  append(e) {
339
- return new w([...this._transforms, e]);
339
+ return new F([...this._transforms, e]);
340
340
  }
341
341
  get(e) {
342
342
  return this._transforms[e];
@@ -345,7 +345,7 @@ class w {
345
345
  return this._transforms[Symbol.iterator]();
346
346
  }
347
347
  }
348
- class b {
348
+ class S {
349
349
  _chain;
350
350
  _charMapping;
351
351
  _nestedSources;
@@ -353,32 +353,31 @@ class b {
353
353
  _colorSource;
354
354
  _cellColorSource;
355
355
  _charSource;
356
- _charCount;
357
356
  constructor(e) {
358
- this._chain = e?.chain ?? w.empty(), this._charMapping = e?.charMapping, this._colorSource = e?.colorSource, this._cellColorSource = e?.cellColorSource, this._charSource = e?.charSource, this._charCount = e?.charCount, this._nestedSources = e?.nestedSources ?? /* @__PURE__ */ new Map(), this._externalLayerRefs = e?.externalLayerRefs ?? /* @__PURE__ */ new Map();
357
+ this._chain = e?.chain ?? F.empty(), this._charMapping = e?.charMapping, this._colorSource = e?.colorSource, this._cellColorSource = e?.cellColorSource, this._charSource = e?.charSource, this._nestedSources = e?.nestedSources ?? /* @__PURE__ */ new Map(), this._externalLayerRefs = e?.externalLayerRefs ?? /* @__PURE__ */ new Map();
359
358
  }
360
- addTransform(e, n) {
361
- const a = { name: e, userArgs: n };
359
+ addTransform(e, r) {
360
+ const a = { name: e, userArgs: r };
362
361
  return this._chain.push(a), this;
363
362
  }
364
- addCombineTransform(e, n, a) {
365
- const r = this._chain.length;
366
- return this._nestedSources.set(r, n), this.addTransform(e, a);
363
+ addCombineTransform(e, r, a) {
364
+ const n = this._chain.length;
365
+ return this._nestedSources.set(n, r), this.addTransform(e, a);
367
366
  }
368
367
  addExternalLayerRef(e) {
369
- const n = this._chain.length;
370
- return this._externalLayerRefs.set(n, e), this.addTransform("src", []);
368
+ const r = this._chain.length;
369
+ return this._externalLayerRefs.set(r, e), this.addTransform("src", []);
371
370
  }
372
371
  charMap(e) {
373
- const n = Array.from(e), a = [];
374
- for (const r of n) a.push(r.codePointAt(0) ?? 32);
372
+ const r = Array.from(e), a = [];
373
+ for (const n of r) a.push(n.codePointAt(0) ?? 32);
375
374
  return this._charMapping = { chars: e, indices: a }, this;
376
375
  }
377
376
  charColor(e) {
378
377
  return this._colorSource = e, this;
379
378
  }
380
- char(e, n) {
381
- return this._charSource = e, this._charCount = n, this;
379
+ char(e) {
380
+ return this._charSource = e, this;
382
381
  }
383
382
  cellColor(e) {
384
383
  return this._cellColorSource = e, this;
@@ -388,10 +387,10 @@ class b {
388
387
  }
389
388
  clone() {
390
389
  const e = /* @__PURE__ */ new Map();
391
- for (const [a, r] of this._nestedSources) e.set(a, r.clone());
392
- const n = /* @__PURE__ */ new Map();
393
- for (const [a, r] of this._externalLayerRefs) n.set(a, { ...r });
394
- return new b({ chain: w.from(this._chain.transforms), charMapping: this._charMapping, colorSource: this._colorSource?.clone(), cellColorSource: this._cellColorSource?.clone(), charSource: this._charSource?.clone(), charCount: this._charCount, nestedSources: e, externalLayerRefs: n });
390
+ for (const [a, n] of this._nestedSources) e.set(a, n.clone());
391
+ const r = /* @__PURE__ */ new Map();
392
+ for (const [a, n] of this._externalLayerRefs) r.set(a, { ...n });
393
+ return new S({ chain: F.from(this._chain.transforms), charMapping: this._charMapping, colorSource: this._colorSource?.clone(), cellColorSource: this._cellColorSource?.clone(), charSource: this._charSource?.clone(), nestedSources: e, externalLayerRefs: r });
395
394
  }
396
395
  get transforms() {
397
396
  return this._chain.transforms;
@@ -408,9 +407,6 @@ class b {
408
407
  get charSource() {
409
408
  return this._charSource;
410
409
  }
411
- get charCount() {
412
- return this._charCount;
413
- }
414
410
  get nestedSources() {
415
411
  return this._nestedSources;
416
412
  }
@@ -422,8 +418,8 @@ const I = { linear: (t) => t, easeInQuad: (t) => t * t, easeOutQuad: (t) => t *
422
418
  function T(t, e) {
423
419
  return (t % e + e) % e;
424
420
  }
425
- function We(t, e, n, a, r) {
426
- return (t - e) * (r - a) / (n - e) + a;
421
+ function We(t, e, r, a, n) {
422
+ return (t - e) * (n - a) / (r - e) + a;
427
423
  }
428
424
  function Je() {
429
425
  "fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
@@ -435,24 +431,24 @@ function Je() {
435
431
  }, Array.prototype.offset = function(t = 0.5) {
436
432
  return this._offset = t % 1, this;
437
433
  }, Array.prototype.fit = function(t = 0, e = 1) {
438
- const n = Math.min(...this), a = Math.max(...this), r = this.map((o) => We(o, n, a, t, e));
439
- return r._speed = this._speed, r._smooth = this._smooth, r._ease = this._ease, r._offset = this._offset, r;
434
+ const r = Math.min(...this), a = Math.max(...this), n = this.map((o) => We(o, r, a, t, e));
435
+ return n._speed = this._speed, n._smooth = this._smooth, n._ease = this._ease, n._offset = this._offset, n;
440
436
  });
441
437
  }
442
438
  function Ze(t, e) {
443
- const n = t._speed ?? 1, a = t._smooth ?? 0;
444
- let r = e.time * n * (e.bpm / 60) + (t._offset ?? 0);
439
+ const r = t._speed ?? 1, a = t._smooth ?? 0;
440
+ let n = e.time * r * (e.bpm / 60) + (t._offset ?? 0);
445
441
  if (a !== 0) {
446
- const o = t._ease ?? I.linear, c = r - a / 2, s = t[Math.floor(T(c, t.length))], i = t[Math.floor(T(c + 1, t.length))];
447
- return o(Math.min(T(c, 1) / a, 1)) * (i - s) + s;
442
+ const o = t._ease ?? I.linear, l = n - a / 2, s = t[Math.floor(T(l, t.length))], i = t[Math.floor(T(l + 1, t.length))];
443
+ return o(Math.min(T(l, 1) / a, 1)) * (i - s) + s;
448
444
  }
449
- return t[Math.floor(T(r, t.length))];
445
+ return t[Math.floor(T(n, t.length))];
450
446
  }
451
447
  function et(t) {
452
448
  return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
453
449
  }
454
- Je(), k.registerMany(He), P.setSynthSourceClass(b), P.injectMethods(b.prototype);
455
- const M = P.generateStandaloneFunctions(), C = "textmode.synth.js";
450
+ Je(), k.registerMany(He), P.setSynthSourceClass(S), P.injectMethods(S.prototype);
451
+ const $ = P.generateStandaloneFunctions(), b = "textmode.synth.js";
456
452
  class tt {
457
453
  _usesFeedback = !1;
458
454
  _usesCharFeedback = !1;
@@ -488,26 +484,26 @@ class tt {
488
484
  return this._usesCellColorFeedback;
489
485
  }
490
486
  }
491
- class nt {
487
+ class rt {
492
488
  _externalLayers = /* @__PURE__ */ new Map();
493
489
  _counter = 0;
494
490
  _layerIdToPrefix = /* @__PURE__ */ new Map();
495
491
  getPrefix(e) {
496
- let n = this._layerIdToPrefix.get(e);
497
- return n || (n = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, n)), n;
492
+ let r = this._layerIdToPrefix.get(e);
493
+ return r || (r = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, r)), r;
498
494
  }
499
- trackUsage(e, n) {
495
+ trackUsage(e, r) {
500
496
  const a = this.getPrefix(e.layerId);
501
- let r = this._externalLayers.get(e.layerId);
502
- switch (r || (r = { layerId: e.layerId, uniformPrefix: a, usesChar: !1, usesCharColor: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, r)), n) {
497
+ let n = this._externalLayers.get(e.layerId);
498
+ switch (n || (n = { layerId: e.layerId, uniformPrefix: a, usesChar: !1, usesCharColor: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, n)), r) {
503
499
  case "char":
504
- r.usesChar = !0;
500
+ n.usesChar = !0;
505
501
  break;
506
502
  case "cellColor":
507
- r.usesCellColor = !0;
503
+ n.usesCellColor = !0;
508
504
  break;
509
505
  default:
510
- r.usesCharColor = !0;
506
+ n.usesCharColor = !0;
511
507
  }
512
508
  }
513
509
  hasLayer(e) {
@@ -529,58 +525,58 @@ class nt {
529
525
  this._externalLayers.clear(), this._counter = 0, this._layerIdToPrefix.clear();
530
526
  }
531
527
  }
532
- const rt = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
528
+ const nt = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
533
529
  class at {
534
- getContextAwareGlslFunction(e, n, a, r, o) {
535
- return n !== "src" ? e.glslFunction : r && o ? this._generateExternalSrcFunction(r, a, o) : this._generateSelfFeedbackSrcFunction(a);
530
+ getContextAwareGlslFunction(e, r, a, n, o) {
531
+ return r !== "src" ? e.glslFunction : n && o ? this._generateExternalSrcFunction(n, a, o) : this._generateSelfFeedbackSrcFunction(a);
536
532
  }
537
- getFunctionName(e, n, a, r) {
538
- return e.name !== "src" ? e.name : a && r ? `src_ext_${r(a.layerId)}_${n}` : `src_${n}`;
533
+ getFunctionName(e, r, a, n) {
534
+ return e.name !== "src" ? e.name : a && n ? `src_ext_${n(a.layerId)}_${r}` : `src_${r}`;
539
535
  }
540
- generateTransformCode(e, n, a, r, o, c, s, i, m, h, y, g, v) {
541
- const p = this.getFunctionName(n, h, g, v), u = (..._) => [..._, ...m].join(", ");
542
- let l = o, d = c, f = s, F = i;
543
- switch (n.type) {
536
+ generateTransformCode(e, r, a, n, o, l, s, i, m, h, y, d, v) {
537
+ const p = this.getFunctionName(r, h, d, v), f = (...u) => [...u, ...m].join(", ");
538
+ let c = o, g = l, _ = s, C = i;
539
+ switch (r.type) {
544
540
  case "src": {
545
- const _ = `c${a}`;
546
- e.push(` vec4 ${_} = ${p}(${u(r)});`), l = _;
541
+ const u = `c${a}`;
542
+ e.push(` vec4 ${u} = ${p}(${f(n)});`), c = u;
547
543
  break;
548
544
  }
549
545
  case "coord": {
550
- const _ = `st${a}`;
551
- e.push(` vec2 ${_} = ${p}(${u(r)});`), e.push(` ${r} = ${_};`);
546
+ const u = `st${a}`;
547
+ e.push(` vec2 ${u} = ${p}(${f(n)});`), e.push(` ${n} = ${u};`);
552
548
  break;
553
549
  }
554
550
  case "color": {
555
- const _ = `c${a}`;
556
- e.push(` vec4 ${_} = ${p}(${u(o)});`), l = _;
551
+ const u = `c${a}`;
552
+ e.push(` vec4 ${u} = ${p}(${f(o)});`), c = u;
557
553
  break;
558
554
  }
559
555
  case "combine": {
560
- const _ = `c${a}`;
561
- e.push(` vec4 ${_} = ${p}(${u(o, y ?? "vec4(0.0)")});`), l = _;
556
+ const u = `c${a}`;
557
+ e.push(` vec4 ${u} = ${p}(${f(o, y ?? "vec4(0.0)")});`), c = u;
562
558
  break;
563
559
  }
564
560
  case "combineCoord": {
565
- const _ = `st${a}`;
566
- e.push(` vec2 ${_} = ${p}(${u(r, y ?? "vec4(0.0)")});`), e.push(` ${r} = ${_};`);
561
+ const u = `st${a}`;
562
+ e.push(` vec2 ${u} = ${p}(${f(n, y ?? "vec4(0.0)")});`), e.push(` ${n} = ${u};`);
567
563
  break;
568
564
  }
569
565
  }
570
- return { colorVar: l, charVar: d, flagsVar: f, rotationVar: F };
566
+ return { colorVar: c, charVar: g, flagsVar: _, rotationVar: C };
571
567
  }
572
- _generateExternalSrcFunction(e, n, a) {
573
- const r = a(e.layerId);
568
+ _generateExternalSrcFunction(e, r, a) {
569
+ const n = a(e.layerId);
574
570
  return `
575
- vec4 ${`src_ext_${r}_${n}`}(vec2 _st) {
576
- return texture(${{ char: `${r}_char`, charColor: `${r}_primary`, cellColor: `${r}_cell`, main: `${r}_primary` }[n]}, fract(_st));
571
+ vec4 ${`src_ext_${n}_${r}`}(vec2 _st) {
572
+ return texture(${{ char: `${n}_char`, charColor: `${n}_primary`, cellColor: `${n}_cell`, main: `${n}_primary` }[r]}, fract(_st));
577
573
  }
578
574
  `;
579
575
  }
580
576
  _generateSelfFeedbackSrcFunction(e) {
581
577
  return `
582
578
  vec4 ${`src_${e}`}(vec2 _st) {
583
- return texture(${rt[e]}, fract(_st));
579
+ return texture(${nt[e]}, fract(_st));
584
580
  }
585
581
  `;
586
582
  }
@@ -588,27 +584,27 @@ vec4 ${`src_${e}`}(vec2 _st) {
588
584
  class ot {
589
585
  _uniforms = /* @__PURE__ */ new Map();
590
586
  _dynamicUpdaters = /* @__PURE__ */ new Map();
591
- processArgument(e, n, a) {
587
+ processArgument(e, r, a) {
592
588
  if (et(e)) {
593
- const r = `${a}_${n.name}`, o = { name: r, type: n.type, value: n.default ?? 0, isDynamic: !0 }, c = (s) => Ze(e, s);
594
- return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, c), { glslValue: r, uniform: o, updater: c };
589
+ const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 }, l = (s) => Ze(e, s);
590
+ return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, l), { glslValue: n, uniform: o, updater: l };
595
591
  }
596
592
  if (typeof e == "function") {
597
- const r = `${a}_${n.name}`, o = { name: r, type: n.type, value: n.default ?? 0, isDynamic: !0 };
598
- return this._uniforms.set(r, o), this._dynamicUpdaters.set(r, e), { glslValue: r, uniform: o, updater: e };
593
+ const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 };
594
+ return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, e), { glslValue: n, uniform: o, updater: e };
599
595
  }
600
596
  if (typeof e == "number") return { glslValue: x(e) };
601
597
  if (Array.isArray(e) && typeof e[0] == "number") {
602
- const r = e;
603
- if (r.length === 2) return { glslValue: `vec2(${x(r[0])}, ${x(r[1])})` };
604
- if (r.length === 3) return { glslValue: `vec3(${x(r[0])}, ${x(r[1])}, ${x(r[2])})` };
605
- if (r.length === 4) return { glslValue: `vec4(${x(r[0])}, ${x(r[1])}, ${x(r[2])}, ${x(r[3])})` };
598
+ const n = e;
599
+ if (n.length === 2) return { glslValue: `vec2(${x(n[0])}, ${x(n[1])})` };
600
+ if (n.length === 3) return { glslValue: `vec3(${x(n[0])}, ${x(n[1])}, ${x(n[2])})` };
601
+ if (n.length === 4) return { glslValue: `vec4(${x(n[0])}, ${x(n[1])}, ${x(n[2])}, ${x(n[3])})` };
606
602
  }
607
- return this.processDefault(n);
603
+ return this.processDefault(r);
608
604
  }
609
605
  processDefault(e) {
610
- const n = e.default;
611
- return typeof n == "number" ? { glslValue: x(n) } : Array.isArray(n) ? { glslValue: `vec${n.length}(${n.map(x).join(", ")})` } : { glslValue: "0.0" };
606
+ const r = e.default;
607
+ return typeof r == "number" ? { glslValue: x(r) } : Array.isArray(r) ? { glslValue: `vec${r.length}(${r.map(x).join(", ")})` } : { glslValue: "0.0" };
612
608
  }
613
609
  getUniforms() {
614
610
  return new Map(this._uniforms);
@@ -722,21 +718,21 @@ float _noise(vec3 v) {
722
718
  }
723
719
  `;
724
720
  function ct(t) {
725
- const { uniforms: e, glslFunctions: n, mainCode: a, charOutputCode: r, primaryColorVar: o, cellColorVar: c, charMapping: s, usesFeedback: i, usesCharFeedback: m, usesCellColorFeedback: h, externalLayers: y } = t, g = Array.from(e.values()).map((f) => `uniform ${f.type} ${f.name};`).join(`
721
+ const { uniforms: e, glslFunctions: r, mainCode: a, charOutputCode: n, primaryColorVar: o, cellColorVar: l, charMapping: s, usesFeedback: i, usesCharFeedback: m, usesCellColorFeedback: h, usesCharSource: y, externalLayers: d } = t, v = Array.from(e.values()).map((u) => `uniform ${u.type} ${u.name};`).join(`
726
722
  `);
727
- let v = "", p = "";
728
- s && (v = `uniform int u_charMap[${s.indices.length}];
729
- uniform int u_charMapSize;`, p = `
723
+ let p = "", f = "";
724
+ s && (p = `uniform int u_charMap[${s.indices.length}];
725
+ uniform int u_charMapSize;`, f = `
730
726
  // Apply character mapping
731
727
  int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
732
728
  int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
733
729
  charOutput.r = float(mappedCharIdx % 256) / 255.0;
734
730
  charOutput.g = float(mappedCharIdx / 256) / 255.0;`);
735
- const u = [];
736
- i && u.push("uniform sampler2D prevCharColorBuffer;"), m && u.push("uniform sampler2D prevCharBuffer;"), h && u.push("uniform sampler2D prevCellColorBuffer;");
737
- const l = u.join(`
738
- `), d = [];
739
- if (y) for (const [, f] of y) f.usesChar && d.push(`uniform sampler2D ${f.uniformPrefix}_char;`), f.usesCharColor && d.push(`uniform sampler2D ${f.uniformPrefix}_primary;`), f.usesCellColor && d.push(`uniform sampler2D ${f.uniformPrefix}_cell;`);
731
+ const c = [];
732
+ i && c.push("uniform sampler2D prevCharColorBuffer;"), m && c.push("uniform sampler2D prevCharBuffer;"), h && c.push("uniform sampler2D prevCellColorBuffer;");
733
+ const g = c.join(`
734
+ `), _ = y ? "uniform float u_charSourceCount;" : "", C = [];
735
+ if (d) for (const [, u] of d) u.usesChar && C.push(`uniform sampler2D ${u.uniformPrefix}_char;`), u.usesCharColor && C.push(`uniform sampler2D ${u.uniformPrefix}_primary;`), u.usesCellColor && C.push(`uniform sampler2D ${u.uniformPrefix}_cell;`);
740
736
  return `#version 300 es
741
737
  precision highp float;
742
738
 
@@ -751,19 +747,20 @@ layout(location = 2) out vec4 o_secondaryColor;
751
747
  // Standard uniforms
752
748
  uniform float time;
753
749
  uniform vec2 resolution;
754
- ${l}
755
- ${d.length > 0 ? `// External layer samplers
756
- ${d.join(`
750
+ ${g}
751
+ ${C.length > 0 ? `// External layer samplers
752
+ ${C.join(`
757
753
  `)}` : ""}
758
- ${v}
754
+ ${p}
755
+ ${_}
759
756
 
760
757
  // Dynamic uniforms
761
- ${g}
758
+ ${v}
762
759
 
763
760
  ${st}
764
761
 
765
762
  // Transform functions
766
- ${Array.from(n).join(`
763
+ ${Array.from(r).join(`
767
764
  `)}
768
765
 
769
766
  void main() {
@@ -771,22 +768,22 @@ void main() {
771
768
  ${a.join(`
772
769
  `)}
773
770
 
774
- ${r}
775
- ${p}
771
+ ${n}
772
+ ${f}
776
773
 
777
774
  // Output to MRT
778
775
  o_character = charOutput;
779
776
  o_primaryColor = ${o};
780
- o_secondaryColor = ${c};
777
+ o_secondaryColor = ${l};
781
778
  }
782
779
  `;
783
780
  }
784
- function lt(t, e, n) {
781
+ function lt(t, e, r) {
785
782
  return t ? `
786
783
  // Character output from generator
787
784
  vec4 charOutput = ${e};` : `
788
785
  // Derive character from color luminance
789
- float lum = _luminance(${n}.rgb);
786
+ float lum = _luminance(${r}.rgb);
790
787
  int charIdx = int(lum * 255.0);
791
788
  vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`;
792
789
  }
@@ -796,64 +793,66 @@ function A(t) {
796
793
  class it {
797
794
  _uniformManager = new ot();
798
795
  _feedbackTracker = new tt();
799
- _externalLayerManager = new nt();
796
+ _externalLayerManager = new rt();
800
797
  _codeGenerator = new at();
801
798
  _glslFunctions = /* @__PURE__ */ new Set();
802
799
  _mainCode = [];
803
800
  _varCounter = 0;
804
801
  _currentTarget = "main";
802
+ _usesCharSource = !1;
805
803
  compile(e) {
806
804
  this._reset();
807
- const n = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
808
- let a = n.charVar;
805
+ const r = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
806
+ let a = r.charVar;
809
807
  e.charSource && (a = this._compileCharSource(e));
810
- let r = n.colorVar;
811
- e.colorSource && (r = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
808
+ let n = r.colorVar;
809
+ e.colorSource && (n = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
812
810
  let o = "vec4(0.0, 0.0, 0.0, 0.0)";
813
811
  e.cellColorSource && (o = this._compileChain(e.cellColorSource, "cellColor", "vec4(0.0, 0.0, 0.0, 0.0)", "v_uv", "cellColor").colorVar);
814
- const c = lt(!!a, a ?? "vec4(0.0)", n.colorVar), s = this._feedbackTracker.getUsage();
815
- return { fragmentSource: ct({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: c, primaryColorVar: r, cellColorVar: o, charMapping: e.charMapping, usesFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, externalLayers: this._externalLayerManager.getExternalLayers() }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesCharColorFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, externalLayers: this._externalLayerManager.getExternalLayers() };
812
+ const l = lt(!!a, a ?? "vec4(0.0)", r.colorVar), s = this._feedbackTracker.getUsage();
813
+ return { fragmentSource: ct({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: l, primaryColorVar: n, cellColorVar: o, charMapping: e.charMapping, usesFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesCharColorFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() };
816
814
  }
817
815
  _reset() {
818
- this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main";
816
+ this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main", this._usesCharSource = !1;
819
817
  }
820
818
  _compileCharSource(e) {
821
- const n = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char"), a = "charFromSource_" + this._varCounter++, r = e.charCount ?? 256;
822
- return this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${a} = _luminance(${n.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * ${r.toFixed(1)});`), this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`), a;
819
+ this._usesCharSource = !0;
820
+ const r = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char"), a = "charFromSource_" + this._varCounter++;
821
+ return this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${a} = _luminance(${r.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * u_charSourceCount);`), this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`), a;
823
822
  }
824
- _compileChain(e, n, a, r = "v_uv", o = "main") {
825
- const c = this._currentTarget;
823
+ _compileChain(e, r, a, n = "v_uv", o = "main") {
824
+ const l = this._currentTarget;
826
825
  this._currentTarget = o;
827
- const s = `${n}_st`;
828
- let i, m, h, y = `${n}_c`;
829
- this._mainCode.push(` vec2 ${s} = ${r};`), this._mainCode.push(` vec4 ${y} = ${a};`);
830
- const g = e.transforms, v = g.map((l) => this._getProcessedTransform(l.name)), p = this._identifyCoordTransforms(v), u = (l) => {
831
- const d = g[l], f = v[l];
832
- if (!f) return void console.warn(`[SynthCompiler] Unknown transform: ${d.name}`);
833
- const F = e.externalLayerRefs.get(l);
834
- d.name === "src" && this._trackSrcUsage(F);
835
- const _ = this._codeGenerator.getContextAwareGlslFunction(f, d.name, this._currentTarget, F, (L) => this._externalLayerManager.getPrefix(L));
836
- this._glslFunctions.add(_);
837
- const Y = this._processArguments(d.userArgs, f.inputs, `${n}_${l}_${d.name}`), R = e.nestedSources.get(l);
826
+ const s = `${r}_st`;
827
+ let i, m, h, y = `${r}_c`;
828
+ this._mainCode.push(` vec2 ${s} = ${n};`), this._mainCode.push(` vec4 ${y} = ${a};`);
829
+ const d = e.transforms, v = d.map((c) => this._getProcessedTransform(c.name)), p = this._identifyCoordTransforms(v), f = (c) => {
830
+ const g = d[c], _ = v[c];
831
+ if (!_) return void console.warn(`[SynthCompiler] Unknown transform: ${g.name}`);
832
+ const C = e.externalLayerRefs.get(c);
833
+ g.name === "src" && this._trackSrcUsage(C);
834
+ const u = this._codeGenerator.getContextAwareGlslFunction(_, g.name, this._currentTarget, C, (L) => this._externalLayerManager.getPrefix(L));
835
+ this._glslFunctions.add(u);
836
+ const Y = this._processArguments(g.userArgs, _.inputs, `${r}_${c}_${g.name}`), R = e.nestedSources.get(c);
838
837
  let z;
839
- R && (f.type === "combine" || f.type === "combineCoord") && (z = this._compileChain(R, `${n}_nested_${l}`, a, s, o).colorVar);
840
- const S = this._codeGenerator.generateTransformCode(this._mainCode, f, this._varCounter++, s, y, i, m, h, Y, this._currentTarget, z, F, (L) => this._externalLayerManager.getPrefix(L));
841
- y = S.colorVar, S.charVar && (i = S.charVar), S.flagsVar && (m = S.flagsVar), S.rotationVar && (h = S.rotationVar);
838
+ R && (_.type === "combine" || _.type === "combineCoord") && (z = this._compileChain(R, `${r}_nested_${c}`, a, s, o).colorVar);
839
+ const M = this._codeGenerator.generateTransformCode(this._mainCode, _, this._varCounter++, s, y, i, m, h, Y, this._currentTarget, z, C, (L) => this._externalLayerManager.getPrefix(L));
840
+ y = M.colorVar, M.charVar && (i = M.charVar), M.flagsVar && (m = M.flagsVar), M.rotationVar && (h = M.rotationVar);
842
841
  };
843
- for (let l = p.length - 1; l >= 0; l--) u(p[l]);
844
- for (let l = 0; l < g.length; l++) {
845
- const d = v[l];
846
- (!d || d.type !== "coord" && d.type !== "combineCoord") && u(l);
842
+ for (let c = p.length - 1; c >= 0; c--) f(p[c]);
843
+ for (let c = 0; c < d.length; c++) {
844
+ const g = v[c];
845
+ (!g || g.type !== "coord" && g.type !== "combineCoord") && f(c);
847
846
  }
848
- return this._currentTarget = c, { coordVar: s, colorVar: y, charVar: i, flagsVar: m, rotationVar: h };
847
+ return this._currentTarget = l, { coordVar: s, colorVar: y, charVar: i, flagsVar: m, rotationVar: h };
849
848
  }
850
849
  _identifyCoordTransforms(e) {
851
- const n = [];
850
+ const r = [];
852
851
  for (let a = 0; a < e.length; a++) {
853
- const r = e[a];
854
- r && (r.type !== "coord" && r.type !== "combineCoord" || n.push(a));
852
+ const n = e[a];
853
+ n && (n.type !== "coord" && n.type !== "combineCoord" || r.push(a));
855
854
  }
856
- return n;
855
+ return r;
857
856
  }
858
857
  _trackSrcUsage(e) {
859
858
  e ? this._externalLayerManager.trackUsage(e, this._currentTarget) : this._feedbackTracker.trackUsage(this._currentTarget);
@@ -861,28 +860,28 @@ class it {
861
860
  _getProcessedTransform(e) {
862
861
  return k.getProcessed(e);
863
862
  }
864
- _processArguments(e, n, a) {
865
- const r = [];
866
- for (let o = 0; o < n.length; o++) {
867
- const c = n[o], s = e[o] ?? c.default, i = this._uniformManager.processArgument(s, c, a);
868
- r.push(i.glslValue);
863
+ _processArguments(e, r, a) {
864
+ const n = [];
865
+ for (let o = 0; o < r.length; o++) {
866
+ const l = r[o], s = e[o] ?? l.default, i = this._uniformManager.processArgument(s, l, a);
867
+ n.push(i.glslValue);
869
868
  }
870
- return r;
869
+ return n;
871
870
  }
872
871
  }
873
872
  class ut {
874
873
  _resolvedIndices;
875
874
  _lastFontCharacterCount = 0;
876
875
  _lastChars = "";
877
- resolve(e, n) {
878
- const a = n.characters.length;
876
+ resolve(e, r) {
877
+ const a = r.characters.length;
879
878
  if (this._resolvedIndices && this._lastFontCharacterCount === a && this._lastChars === e) return this._resolvedIndices;
880
- const r = Array.from(e), o = new Int32Array(r.length), c = n.characterMap, s = n.characters;
881
- for (let i = 0; i < r.length; i++) {
882
- const m = r[i], h = c.get(m);
879
+ const n = Array.from(e), o = new Int32Array(n.length), l = r.characterMap, s = r.characters;
880
+ for (let i = 0; i < n.length; i++) {
881
+ const m = n[i], h = l.get(m);
883
882
  if (h !== void 0) o[i] = s.indexOf(h);
884
883
  else {
885
- const y = c.get(" ");
884
+ const y = l.get(" ");
886
885
  o[i] = y !== void 0 ? s.indexOf(y) : 0;
887
886
  }
888
887
  }
@@ -893,25 +892,25 @@ class ut {
893
892
  }
894
893
  }
895
894
  function V(t = {}) {
896
- return { source: t.source ?? new b(), compiled: t.compiled, shader: t.shader, characterResolver: t.characterResolver ?? new ut(), needsCompile: t.needsCompile ?? !1, pingPongBuffers: t.pingPongBuffers, pingPongIndex: t.pingPongIndex ?? 0, externalLayerMap: t.externalLayerMap, bpm: t.bpm };
895
+ return { source: t.source ?? new S(), compiled: t.compiled, shader: t.shader, characterResolver: t.characterResolver ?? new ut(), needsCompile: t.needsCompile ?? !1, pingPongBuffers: t.pingPongBuffers, pingPongIndex: t.pingPongIndex ?? 0, externalLayerMap: t.externalLayerMap, bpm: t.bpm };
897
896
  }
898
897
  function ft(t) {
899
898
  t.extendLayer("synth", function(e) {
900
- const n = this.grid !== void 0 && this.drawFramebuffer !== void 0;
901
- let a = this.getPluginState(C);
902
- a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(), n && (a.compiled = A(e))) : a = V({ source: e, compiled: n ? A(e) : void 0, needsCompile: !0 }), this.setPluginState(C, a);
899
+ const r = this.grid !== void 0 && this.drawFramebuffer !== void 0;
900
+ let a = this.getPluginState(b);
901
+ a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(), r && (a.compiled = A(e))) : a = V({ source: e, compiled: r ? A(e) : void 0, needsCompile: !0 }), this.setPluginState(b, a);
903
902
  });
904
903
  }
905
904
  function pt(t) {
906
905
  t.extendLayer("clearSynth", function() {
907
- const e = this.getPluginState(C);
908
- e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(C, void 0));
906
+ const e = this.getPluginState(b);
907
+ e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(b, void 0));
909
908
  });
910
909
  }
911
910
  function mt(t) {
912
911
  t.extendLayer("bpm", function(e) {
913
- let n = this.getPluginState(C);
914
- n ? n.bpm = e : n = V({ bpm: e }), this.setPluginState(C, n);
912
+ let r = this.getPluginState(b);
913
+ r ? r.bpm = e : r = V({ bpm: e }), this.setPluginState(b, r);
915
914
  });
916
915
  }
917
916
  let E = 60;
@@ -926,24 +925,24 @@ function yt(t) {
926
925
  return dt(e), e;
927
926
  };
928
927
  }
929
- function $(t) {
928
+ function w(t) {
930
929
  const e = /* @__PURE__ */ new Map();
931
- for (const [, n] of t.externalLayerRefs) e.set(n.layerId, n.layer);
932
- for (const [, n] of t.nestedSources) {
933
- const a = $(n);
934
- for (const [r, o] of a) e.set(r, o);
930
+ for (const [, r] of t.externalLayerRefs) e.set(r.layerId, r.layer);
931
+ for (const [, r] of t.nestedSources) {
932
+ const a = w(r);
933
+ for (const [n, o] of a) e.set(n, o);
935
934
  }
936
935
  if (t.charSource) {
937
- const n = $(t.charSource);
938
- for (const [a, r] of n) e.set(a, r);
936
+ const r = w(t.charSource);
937
+ for (const [a, n] of r) e.set(a, n);
939
938
  }
940
939
  if (t.colorSource) {
941
- const n = $(t.colorSource);
942
- for (const [a, r] of n) e.set(a, r);
940
+ const r = w(t.colorSource);
941
+ for (const [a, n] of r) e.set(a, n);
943
942
  }
944
943
  if (t.cellColorSource) {
945
- const n = $(t.cellColorSource);
946
- for (const [a, r] of n) e.set(a, r);
944
+ const r = w(t.cellColorSource);
945
+ for (const [a, n] of r) e.set(a, n);
947
946
  }
948
947
  return e;
949
948
  }
@@ -951,21 +950,21 @@ let B = null;
951
950
  function Ct(t) {
952
951
  B = t;
953
952
  }
954
- function U(t, e, n) {
955
- const a = n ?? B;
953
+ function U(t, e, r) {
954
+ const a = r ?? B;
956
955
  if (a) try {
957
956
  a(t, e);
958
957
  } catch {
959
958
  }
960
959
  }
961
- function gt(t, e, n, a = {}) {
962
- let r;
960
+ function gt(t, e, r, a = {}) {
961
+ let n;
963
962
  try {
964
- r = t();
963
+ n = t();
965
964
  } catch (o) {
966
- return U(o, e, a.onError), n;
965
+ return U(o, e, a.onError), r;
967
966
  }
968
- return _t(r) ? r : (U(new Error(`[textmode.synth.js] Invalid dynamic parameter value for "${e}": ${N(r)}`), e, a.onError), n);
967
+ return _t(n) ? n : (U(new Error(`[textmode.synth.js] Invalid dynamic parameter value for "${e}": ${N(n)}`), e, a.onError), r);
969
968
  }
970
969
  function N(t) {
971
970
  if (t === void 0) return "undefined";
@@ -975,7 +974,7 @@ function N(t) {
975
974
  if (!Number.isFinite(t)) return t > 0 ? "Infinity" : "-Infinity";
976
975
  }
977
976
  if (Array.isArray(t)) {
978
- const e = t.findIndex((n) => typeof n != "number" || !Number.isFinite(n));
977
+ const e = t.findIndex((r) => typeof r != "number" || !Number.isFinite(r));
979
978
  if (e >= 0) return `array with invalid element at index ${e}: ${N(t[e])}`;
980
979
  }
981
980
  return String(t);
@@ -984,97 +983,101 @@ function _t(t) {
984
983
  return t != null && (typeof t == "number" ? Number.isFinite(t) : !!Array.isArray(t) && t.length > 0 && t.every((e) => typeof e == "number" && Number.isFinite(e)));
985
984
  }
986
985
  async function vt(t, e) {
987
- const n = t.getPluginState(C);
988
- if (!n) return;
989
- const a = t.grid, r = t.drawFramebuffer;
990
- if (!a || !r || (n.compiled || (n.compiled = A(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;
991
- const o = n.compiled.usesCharColorFeedback, c = n.compiled.usesCharFeedback, s = n.compiled.usesCellColorFeedback, i = o || c || s;
992
- i && !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);
993
- const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm: n.bpm ?? ht() }, h = /* @__PURE__ */ new Map();
994
- for (const [g, v] of n.compiled.dynamicUpdaters) {
995
- const p = n.compiled.uniforms.get(g), u = gt(() => v(m), g, p?.value ?? 0, { onError: n.onDynamicError });
996
- h.set(g, u);
997
- }
998
- const y = (g) => {
986
+ const r = t.getPluginState(b);
987
+ if (!r) return;
988
+ const a = t.grid, n = t.drawFramebuffer;
989
+ if (!a || !n || (r.compiled || (r.compiled = A(r.source), r.externalLayerMap = w(r.source), r.needsCompile = !0), r.needsCompile && r.compiled && (r.shader?.dispose && r.shader.dispose(), r.externalLayerMap = w(r.source), r.shader = await e.createFilterShader(r.compiled.fragmentSource), r.needsCompile = !1), !r.shader || !r.compiled)) return;
990
+ const o = r.compiled.usesCharColorFeedback, l = r.compiled.usesCharFeedback, s = r.compiled.usesCellColorFeedback, i = o || l || s;
991
+ i && !r.pingPongBuffers && (r.pingPongBuffers = [e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 }), e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 })], r.pingPongIndex = 0);
992
+ const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm: r.bpm ?? ht() }, h = /* @__PURE__ */ new Map();
993
+ for (const [d, v] of r.compiled.dynamicUpdaters) {
994
+ const p = r.compiled.uniforms.get(d), f = gt(() => v(m), d, p?.value ?? 0, { onError: r.onDynamicError });
995
+ h.set(d, f);
996
+ }
997
+ const y = (d) => {
999
998
  e.setUniform("time", e.secs), e.setUniform("resolution", [m.cols, m.rows]);
1000
- for (const [p, u] of h) e.setUniform(p, u);
1001
- for (const [p, u] of n.compiled.uniforms) u.isDynamic || typeof u.value == "function" || e.setUniform(p, u.value);
1002
- if (n.compiled.charMapping) {
1003
- const p = n.characterResolver.resolve(n.compiled.charMapping.chars, t.font);
999
+ for (const [p, f] of h) e.setUniform(p, f);
1000
+ for (const [p, f] of r.compiled.uniforms) f.isDynamic || typeof f.value == "function" || e.setUniform(p, f.value);
1001
+ if (r.compiled.charMapping) {
1002
+ const p = r.characterResolver.resolve(r.compiled.charMapping.chars, t.font);
1004
1003
  e.setUniform("u_charMap", p), e.setUniform("u_charMapSize", p.length);
1005
1004
  }
1006
- g && (o && e.setUniform("prevCharColorBuffer", g.textures[1]), c && e.setUniform("prevCharBuffer", g.textures[0]), s && e.setUniform("prevCellColorBuffer", g.textures[2]));
1007
- const v = n.compiled.externalLayers;
1008
- if (v && v.size > 0 && n.externalLayerMap) for (const [p, u] of v) {
1009
- const l = n.externalLayerMap.get(p);
1010
- if (!l) {
1005
+ if (r.compiled.usesCharSource) {
1006
+ const p = r.compiled.charMapping ? r.compiled.charMapping.chars.length : t.font.characters.length;
1007
+ e.setUniform("u_charSourceCount", p);
1008
+ }
1009
+ d && (o && e.setUniform("prevCharColorBuffer", d.textures[1]), l && e.setUniform("prevCharBuffer", d.textures[0]), s && e.setUniform("prevCellColorBuffer", d.textures[2]));
1010
+ const v = r.compiled.externalLayers;
1011
+ if (v && v.size > 0 && r.externalLayerMap) for (const [p, f] of v) {
1012
+ const c = r.externalLayerMap.get(p);
1013
+ if (!c) {
1011
1014
  console.warn(`[textmode.synth.js] External layer not found: ${p}`);
1012
1015
  continue;
1013
1016
  }
1014
- const d = l.getPluginState(C);
1015
- let f;
1016
- d?.pingPongBuffers ? f = d.pingPongBuffers[d.pingPongIndex].textures : l.drawFramebuffer && (f = l.drawFramebuffer.textures), f && (u.usesChar && e.setUniform(`${u.uniformPrefix}_char`, f[0]), u.usesCharColor && e.setUniform(`${u.uniformPrefix}_primary`, f[1]), u.usesCellColor && e.setUniform(`${u.uniformPrefix}_cell`, f[2]));
1017
+ const g = c.getPluginState(b);
1018
+ let _;
1019
+ g?.pingPongBuffers ? _ = g.pingPongBuffers[g.pingPongIndex].textures : c.drawFramebuffer && (_ = c.drawFramebuffer.textures), _ && (f.usesChar && e.setUniform(`${f.uniformPrefix}_char`, _[0]), f.usesCharColor && e.setUniform(`${f.uniformPrefix}_primary`, _[1]), f.usesCellColor && e.setUniform(`${f.uniformPrefix}_cell`, _[2]));
1017
1020
  }
1018
1021
  };
1019
- if (i && n.pingPongBuffers) {
1020
- const g = n.pingPongBuffers[n.pingPongIndex], v = n.pingPongBuffers[1 - n.pingPongIndex];
1021
- v.begin(), e.clear(), e.shader(n.shader), y(g), e.rect(a.cols, a.rows), v.end(), r.begin(), e.clear(), e.shader(n.shader), y(g), e.rect(a.cols, a.rows), r.end(), n.pingPongIndex = 1 - n.pingPongIndex;
1022
- } else r.begin(), e.clear(), e.shader(n.shader), y(null), e.rect(a.cols, a.rows), r.end();
1022
+ if (i && r.pingPongBuffers) {
1023
+ const d = r.pingPongBuffers[r.pingPongIndex], v = r.pingPongBuffers[1 - r.pingPongIndex];
1024
+ v.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), v.end(), n.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), n.end(), r.pingPongIndex = 1 - r.pingPongIndex;
1025
+ } else n.begin(), e.clear(), e.shader(r.shader), y(null), e.rect(a.cols, a.rows), n.end();
1023
1026
  }
1024
1027
  function xt(t) {
1025
- const e = t.getPluginState(C);
1028
+ const e = t.getPluginState(b);
1026
1029
  e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()));
1027
1030
  }
1028
- const bt = { name: C, version: "1.0.0", install(t, e) {
1029
- yt(t), ft(e), mt(e), pt(e), e.registerLayerPreRenderHook((n) => vt(n, t)), e.registerLayerDisposedHook(xt);
1031
+ const bt = { name: b, version: "1.0.0", install(t, e) {
1032
+ yt(t), ft(e), mt(e), pt(e), e.registerLayerPreRenderHook((r) => vt(r, t)), e.registerLayerDisposedHook(xt);
1030
1033
  }, uninstall(t, e) {
1031
- const n = [e.layerManager.base, ...e.layerManager.all];
1032
- for (const a of n) {
1033
- const r = a.getPluginState(C);
1034
- r && (r.shader?.dispose && r.shader.dispose(), r.pingPongBuffers && (r.pingPongBuffers[0].dispose?.(), r.pingPongBuffers[1].dispose?.()));
1034
+ const r = [e.layerManager.base, ...e.layerManager.all];
1035
+ for (const a of r) {
1036
+ const n = a.getPluginState(b);
1037
+ n && (n.shader?.dispose && n.shader.dispose(), n.pingPongBuffers && (n.pingPongBuffers[0].dispose?.(), n.pingPongBuffers[1].dispose?.()));
1035
1038
  }
1036
1039
  delete t.bpm, e.removeLayerExtension("synth"), e.removeLayerExtension("bpm"), e.removeLayerExtension("clearSynth");
1037
1040
  } }, St = (t) => {
1038
- const e = new b();
1041
+ const e = new S();
1039
1042
  return e._colorSource = t, e;
1040
1043
  }, Mt = (t, e) => {
1041
- const n = new b();
1042
- return n._charSource = t, n._charCount = e, n;
1044
+ const r = new S();
1045
+ return r._charSource = t, r._charCount = e, r;
1043
1046
  }, $t = (t) => {
1044
- const e = new b();
1047
+ const e = new S();
1045
1048
  return e._colorSource = t, e;
1046
1049
  };
1047
1050
  function wt(t) {
1048
- return M.gradient(t);
1051
+ return $.gradient(t);
1049
1052
  }
1050
1053
  function Ft(t, e) {
1051
- return M.noise(t, e);
1054
+ return $.noise(t, e);
1052
1055
  }
1053
- function kt(t, e, n) {
1054
- return M.osc(t, e, n);
1056
+ function kt(t, e, r) {
1057
+ return $.osc(t, e, r);
1055
1058
  }
1056
1059
  const Tt = (t) => {
1057
- const e = new b();
1060
+ const e = new S();
1058
1061
  return e._colorSource = t, e._cellColorSource = t, e;
1059
1062
  };
1060
- function Lt(t, e, n) {
1061
- return M.shape(t, e, n);
1063
+ function Lt(t, e, r) {
1064
+ return $.shape(t, e, r);
1062
1065
  }
1063
- function Pt(t, e, n, a) {
1064
- return M.solid(t, e, n, a);
1066
+ function Pt(t, e, r, a) {
1067
+ return $.solid(t, e, r, a);
1065
1068
  }
1066
1069
  const It = (t) => {
1067
- const e = M.src;
1070
+ const e = $.src;
1068
1071
  if (!t) return e();
1069
- const n = new b(), a = t.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
1070
- return n.addExternalLayerRef({ layerId: a, layer: t }), n;
1072
+ const r = new S(), a = t.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
1073
+ return r.addExternalLayerRef({ layerId: a, layer: t }), r;
1071
1074
  };
1072
- function At(t, e, n) {
1073
- return M.voronoi(t, e, n);
1075
+ function At(t, e, r) {
1076
+ return $.voronoi(t, e, r);
1074
1077
  }
1075
1078
  export {
1076
1079
  bt as SynthPlugin,
1077
- b as SynthSource,
1080
+ S as SynthSource,
1078
1081
  St as cellColor,
1079
1082
  Mt as char,
1080
1083
  $t as charColor,