@vfx-js/effects 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +2 -0
  2. package/lib/cjs/_figma-common.d.ts +8 -0
  3. package/lib/cjs/_figma-common.js +46 -0
  4. package/lib/cjs/_figma-common.js.map +1 -0
  5. package/lib/cjs/ascii.d.ts +137 -0
  6. package/lib/cjs/ascii.js +482 -0
  7. package/lib/cjs/ascii.js.map +1 -0
  8. package/lib/cjs/chromatic.d.ts +15 -0
  9. package/lib/cjs/chromatic.js +70 -0
  10. package/lib/cjs/chromatic.js.map +1 -0
  11. package/lib/cjs/colored-edges.d.ts +23 -0
  12. package/lib/cjs/colored-edges.js +88 -0
  13. package/lib/cjs/colored-edges.js.map +1 -0
  14. package/lib/cjs/dither.d.ts +24 -0
  15. package/lib/cjs/dither.js +120 -0
  16. package/lib/cjs/dither.js.map +1 -0
  17. package/lib/cjs/duotone.d.ts +17 -0
  18. package/lib/cjs/duotone.js +62 -0
  19. package/lib/cjs/duotone.js.map +1 -0
  20. package/lib/cjs/glitch.d.ts +13 -0
  21. package/lib/cjs/glitch.js +108 -0
  22. package/lib/cjs/glitch.js.map +1 -0
  23. package/lib/cjs/gradient-map.d.ts +25 -0
  24. package/lib/cjs/gradient-map.js +154 -0
  25. package/lib/cjs/gradient-map.js.map +1 -0
  26. package/lib/cjs/hue-shift.d.ts +11 -0
  27. package/lib/cjs/hue-shift.js +65 -0
  28. package/lib/cjs/hue-shift.js.map +1 -0
  29. package/lib/cjs/index.d.ts +20 -0
  30. package/lib/cjs/index.js +43 -1
  31. package/lib/cjs/index.js.map +1 -1
  32. package/lib/cjs/matrix.d.ts +135 -0
  33. package/lib/cjs/matrix.js +593 -0
  34. package/lib/cjs/matrix.js.map +1 -0
  35. package/lib/cjs/package.json +1 -1
  36. package/lib/cjs/pattern-refraction.d.ts +31 -0
  37. package/lib/cjs/pattern-refraction.js +190 -0
  38. package/lib/cjs/pattern-refraction.js.map +1 -0
  39. package/lib/cjs/pixel-stretch.d.ts +21 -0
  40. package/lib/cjs/pixel-stretch.js +78 -0
  41. package/lib/cjs/pixel-stretch.js.map +1 -0
  42. package/lib/cjs/rainbow.d.ts +13 -0
  43. package/lib/cjs/rainbow.js +79 -0
  44. package/lib/cjs/rainbow.js.map +1 -0
  45. package/lib/cjs/rgb-glitch.d.ts +13 -0
  46. package/lib/cjs/rgb-glitch.js +79 -0
  47. package/lib/cjs/rgb-glitch.js.map +1 -0
  48. package/lib/cjs/rgb-shift.d.ts +13 -0
  49. package/lib/cjs/rgb-shift.js +76 -0
  50. package/lib/cjs/rgb-shift.js.map +1 -0
  51. package/lib/cjs/sinewave.d.ts +17 -0
  52. package/lib/cjs/sinewave.js +76 -0
  53. package/lib/cjs/sinewave.js.map +1 -0
  54. package/lib/cjs/slice-shift.d.ts +21 -0
  55. package/lib/cjs/slice-shift.js +75 -0
  56. package/lib/cjs/slice-shift.js.map +1 -0
  57. package/lib/cjs/tile-pixelate.d.ts +28 -0
  58. package/lib/cjs/tile-pixelate.js +168 -0
  59. package/lib/cjs/tile-pixelate.js.map +1 -0
  60. package/lib/cjs/tritone.d.ts +18 -0
  61. package/lib/cjs/tritone.js +67 -0
  62. package/lib/cjs/tritone.js.map +1 -0
  63. package/lib/cjs/vignette.d.ts +15 -0
  64. package/lib/cjs/vignette.js +59 -0
  65. package/lib/cjs/vignette.js.map +1 -0
  66. package/lib/cjs/warp.d.ts +22 -0
  67. package/lib/cjs/warp.js +92 -0
  68. package/lib/cjs/warp.js.map +1 -0
  69. package/lib/esm/_figma-common.d.ts +8 -0
  70. package/lib/esm/_figma-common.js +42 -0
  71. package/lib/esm/_figma-common.js.map +1 -0
  72. package/lib/esm/ascii.d.ts +137 -0
  73. package/lib/esm/ascii.js +478 -0
  74. package/lib/esm/ascii.js.map +1 -0
  75. package/lib/esm/chromatic.d.ts +15 -0
  76. package/lib/esm/chromatic.js +66 -0
  77. package/lib/esm/chromatic.js.map +1 -0
  78. package/lib/esm/colored-edges.d.ts +23 -0
  79. package/lib/esm/colored-edges.js +84 -0
  80. package/lib/esm/colored-edges.js.map +1 -0
  81. package/lib/esm/dither.d.ts +24 -0
  82. package/lib/esm/dither.js +116 -0
  83. package/lib/esm/dither.js.map +1 -0
  84. package/lib/esm/duotone.d.ts +17 -0
  85. package/lib/esm/duotone.js +58 -0
  86. package/lib/esm/duotone.js.map +1 -0
  87. package/lib/esm/glitch.d.ts +13 -0
  88. package/lib/esm/glitch.js +104 -0
  89. package/lib/esm/glitch.js.map +1 -0
  90. package/lib/esm/gradient-map.d.ts +25 -0
  91. package/lib/esm/gradient-map.js +150 -0
  92. package/lib/esm/gradient-map.js.map +1 -0
  93. package/lib/esm/hue-shift.d.ts +11 -0
  94. package/lib/esm/hue-shift.js +61 -0
  95. package/lib/esm/hue-shift.js.map +1 -0
  96. package/lib/esm/index.d.ts +20 -0
  97. package/lib/esm/index.js +20 -0
  98. package/lib/esm/index.js.map +1 -1
  99. package/lib/esm/matrix.d.ts +135 -0
  100. package/lib/esm/matrix.js +589 -0
  101. package/lib/esm/matrix.js.map +1 -0
  102. package/lib/esm/package.json +1 -1
  103. package/lib/esm/pattern-refraction.d.ts +31 -0
  104. package/lib/esm/pattern-refraction.js +186 -0
  105. package/lib/esm/pattern-refraction.js.map +1 -0
  106. package/lib/esm/pixel-stretch.d.ts +21 -0
  107. package/lib/esm/pixel-stretch.js +74 -0
  108. package/lib/esm/pixel-stretch.js.map +1 -0
  109. package/lib/esm/rainbow.d.ts +13 -0
  110. package/lib/esm/rainbow.js +75 -0
  111. package/lib/esm/rainbow.js.map +1 -0
  112. package/lib/esm/rgb-glitch.d.ts +13 -0
  113. package/lib/esm/rgb-glitch.js +75 -0
  114. package/lib/esm/rgb-glitch.js.map +1 -0
  115. package/lib/esm/rgb-shift.d.ts +13 -0
  116. package/lib/esm/rgb-shift.js +72 -0
  117. package/lib/esm/rgb-shift.js.map +1 -0
  118. package/lib/esm/sinewave.d.ts +17 -0
  119. package/lib/esm/sinewave.js +72 -0
  120. package/lib/esm/sinewave.js.map +1 -0
  121. package/lib/esm/slice-shift.d.ts +21 -0
  122. package/lib/esm/slice-shift.js +71 -0
  123. package/lib/esm/slice-shift.js.map +1 -0
  124. package/lib/esm/tile-pixelate.d.ts +28 -0
  125. package/lib/esm/tile-pixelate.js +164 -0
  126. package/lib/esm/tile-pixelate.js.map +1 -0
  127. package/lib/esm/tritone.d.ts +18 -0
  128. package/lib/esm/tritone.js +63 -0
  129. package/lib/esm/tritone.js.map +1 -0
  130. package/lib/esm/vignette.d.ts +15 -0
  131. package/lib/esm/vignette.js +55 -0
  132. package/lib/esm/vignette.js.map +1 -0
  133. package/lib/esm/warp.d.ts +22 -0
  134. package/lib/esm/warp.js +88 -0
  135. package/lib/esm/warp.js.map +1 -0
  136. package/package.json +1 -1
@@ -0,0 +1,137 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ /** RGBA colour, each channel in [0, 1]. */
3
+ export type AsciiColor = [number, number, number, number];
4
+ /**
5
+ * A character ramp ordered **dark → light**: index `0` maps to the
6
+ * darkest input luminance, the last entry to the brightest. Pass a
7
+ * string (split per Unicode code point) or an array of single chars.
8
+ */
9
+ export type AsciiCharRamp = string | readonly string[];
10
+ /**
11
+ * An image tile source. Strings are treated as URLs (loaded and decoded
12
+ * in `init()`); the rest are used directly.
13
+ */
14
+ export type AsciiImageSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap | string;
15
+ /** Name of a built-in {@link ASCII_PRESETS} ramp. */
16
+ export type AsciiPresetName = "standard" | "minimal" | "blocks" | "dots" | "circles" | "detailed";
17
+ /**
18
+ * Built-in character ramps, ordered dark → light. Suited for
19
+ * light-on-dark output (more "ink" = brighter); flip with
20
+ * `invert: true` for dark-on-light.
21
+ */
22
+ export declare const ASCII_PRESETS: Record<AsciiPresetName, string>;
23
+ export type AsciiParams = {
24
+ /**
25
+ * Cell size in CSS px. A single number is a square cell; a
26
+ * `[width, height]` tuple sets the axes independently.
27
+ *
28
+ * Glyphs always keep their native aspect ratio — a cell wider/taller
29
+ * than the character box letterboxes the glyph rather than stretching
30
+ * it. Set the cell to the font's character aspect (≈ advance : em, so
31
+ * cells narrower than they are tall) for gap-free tiling.
32
+ */
33
+ grid: number | [number, number];
34
+ /**
35
+ * Character ramp, ordered dark → light. Overrides {@link preset}.
36
+ *
37
+ * Baked into the glyph atlas at `init()`; changing it (or `font` /
38
+ * `fontWeight`) after the effect is added has no effect until it is
39
+ * re-added.
40
+ */
41
+ chars?: AsciiCharRamp;
42
+ /** Built-in ramp to use when {@link chars} is omitted. */
43
+ preset: AsciiPresetName;
44
+ /**
45
+ * Image tiles, ordered dark → light — an alternative to character
46
+ * glyphs. Takes precedence over {@link chars} / {@link preset} when
47
+ * non-empty. Each tile keeps its own colour (the `color` RGB /
48
+ * `colorFromSource` tint is bypassed, though `color`'s alpha still
49
+ * scales opacity), is contain-fitted into the cell at a shared aspect
50
+ * (taken from the first tile), and the atlas is auto-downscaled to
51
+ * stay within GPU texture limits.
52
+ *
53
+ * Baked into the atlas at `init()`; change by re-adding the effect.
54
+ */
55
+ tiles?: readonly AsciiImageSource[];
56
+ /**
57
+ * CSS font family used to render the glyph atlas (e.g. `"monospace"`,
58
+ * `"Helvetica"`). Loaded via the Font Loading API before the atlas is
59
+ * built. Construction-time only (see {@link chars}).
60
+ */
61
+ font: string;
62
+ /**
63
+ * Character box aspect ratio (width / height) used to keep glyphs
64
+ * undistorted when the cell is non-square.
65
+ *
66
+ * Omit (default) to auto-measure it from the font — the glyph advance
67
+ * (`measureText`) over the em height. That is exact for monospace
68
+ * fonts; set it explicitly for proportional fonts, non-browser
69
+ * builds, or to force a specific look (e.g. `0.5` for tall, narrow
70
+ * characters). Construction-time only (see {@link chars}).
71
+ */
72
+ charAspect?: number;
73
+ /**
74
+ * CSS font weight for the glyph atlas — a keyword (`"normal"`,
75
+ * `"bold"`) or numeric weight (`100`–`900`). Construction-time only
76
+ * (see {@link chars}).
77
+ */
78
+ fontWeight: string | number;
79
+ /** Fixed glyph colour, used when {@link colorFromSource} is `false`. */
80
+ color: AsciiColor;
81
+ /** Cell backdrop behind the glyphs, non-premultiplied. */
82
+ background: AsciiColor;
83
+ /** Tint each glyph with the average colour of its source cell. */
84
+ colorFromSource: boolean;
85
+ /** Flip the luminance → glyph mapping (for dark-on-light output). */
86
+ invert: boolean;
87
+ /**
88
+ * Ordered (Bayer 4×4) dithering amount, [0, 1]. `0` disables it; `1`
89
+ * spreads each quantisation step across a full ramp level so short
90
+ * ramps (e.g. `minimal`, `dots`) render smooth gradients instead of
91
+ * hard bands. Applied per cell, so each character stays consistent.
92
+ */
93
+ dither: number;
94
+ };
95
+ /**
96
+ * ASCII / glyph-mosaic effect.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * vfx.add(el, { effect: new AsciiEffect({ font: "Helvetica", grid: 16 }) });
101
+ * vfx.add(el, { effect: new AsciiEffect({ chars: [" ", ".", "+", "#"] }) });
102
+ * // Image tiles (dark → light), each keeping its own colour:
103
+ * vfx.add(el, { effect: new AsciiEffect({ tiles: ["/0.png", "/1.png"] }) });
104
+ * ```
105
+ *
106
+ * Glyphs keep their native aspect ratio regardless of the `grid` ratio:
107
+ * each is fitted (contain) into its cell, so a non-square cell letterboxes
108
+ * rather than stretching the character. Match `grid` to the font's
109
+ * character box (≈ advance : em) for gap-free tiling.
110
+ *
111
+ * `grid`, `color`, `background`, `colorFromSource`, `invert`, and `dither`
112
+ * are live (read every frame). `chars` / `tiles` / `font` / `fontWeight` /
113
+ * `charAspect` are baked into the atlas at `init()` — after changing them
114
+ * via `setParams`, call {@link AsciiEffect.updateAtlas} (or re-add the
115
+ * effect) to rebuild.
116
+ */
117
+ export declare class AsciiEffect implements Effect {
118
+ #private;
119
+ params: AsciiParams;
120
+ constructor(initial?: Partial<AsciiParams>);
121
+ setParams(updates: Partial<AsciiParams>): void;
122
+ init(ctx: EffectContext): Promise<void>;
123
+ /**
124
+ * Rebuild the atlas from the current params, applying changes to the
125
+ * baked fields (`chars` / `tiles` / `font` / `fontWeight` /
126
+ * `charAspect`) without removing and re-adding the effect. Async — it
127
+ * may load fonts or decode image tiles. No-op before `init()`.
128
+ *
129
+ * Allocates a fresh atlas texture and disposes the previous one once the
130
+ * swap is live, so repeated calls don't leak. Still does real work
131
+ * (rasterising / decoding), so prefer occasional calls (e.g. on a
132
+ * settings change) over per-frame use.
133
+ */
134
+ updateAtlas(): Promise<void>;
135
+ render(ctx: EffectContext): void;
136
+ dispose(): void;
137
+ }
@@ -0,0 +1,478 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _AsciiEffect_instances, _AsciiEffect_atlas, _AsciiEffect_cols, _AsciiEffect_rows, _AsciiEffect_charCount, _AsciiEffect_glyphAspect, _AsciiEffect_atlasCellPx, _AsciiEffect_tileColor, _AsciiEffect_ctx, _AsciiEffect_build;
13
+ /**
14
+ * Built-in character ramps, ordered dark → light. Suited for
15
+ * light-on-dark output (more "ink" = brighter); flip with
16
+ * `invert: true` for dark-on-light.
17
+ */
18
+ export const ASCII_PRESETS = {
19
+ // Paul Bourke's short 10-step grey-scale ramp, reversed to dark → light.
20
+ // ref. https://paulbourke.net/dataformats/asciiart/
21
+ standard: " .:-=+*#%@",
22
+ minimal: " .#",
23
+ // Unicode shade blocks — smooth, font-independent gradient.
24
+ blocks: " ░▒▓█",
25
+ // Round symbols growing from a dot to a filled bullet.
26
+ dots: " .·•●",
27
+ // Outline → filled circles (the ◯ … ● family).
28
+ circles: " ◌○◉●",
29
+ // Paul Bourke's 70-step grey-scale ramp, reversed to dark → light.
30
+ // ref. https://paulbourke.net/dataformats/asciiart/
31
+ detailed: " .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$",
32
+ };
33
+ const FRAG_ASCII = `#version 300 es
34
+ precision highp float;
35
+
36
+ in vec2 uvContent;
37
+ out vec4 outColor;
38
+
39
+ uniform sampler2D src;
40
+ uniform sampler2D atlas;
41
+ uniform vec4 srcRectUv;
42
+ uniform vec2 elementPx; // element size, physical px
43
+ uniform vec2 cellPx; // cell size, physical px
44
+ uniform float cols; // atlas columns
45
+ uniform float rows; // atlas rows
46
+ uniform float charCount; // number of glyphs in the ramp
47
+ uniform vec4 color; // fixed glyph colour (when colorFromSource == 0)
48
+ uniform vec4 background; // cell backdrop, non-premultiplied
49
+ uniform int colorFromSource; // 1 = tint glyph with the cell's avg colour
50
+ uniform int invert; // 1 = flip the luminance → glyph mapping
51
+ uniform float glyphAspect; // font's character box aspect (advance / em)
52
+ uniform int tileColor; // 1 = use the atlas tile's own RGBA (image tiles)
53
+ uniform float dither; // ordered-dither amount in index units (0 = off)
54
+ uniform vec2 atlasCellPx; // atlas cell size in texels (for edge inset)
55
+
56
+ // Box-average TAPS x TAPS samples per cell. A single centre tap throws
57
+ // away most of the cell; this keeps the glyph choice representative. 3x3
58
+ // keeps the luminance stable enough for the discrete glyph mapping while
59
+ // costing far fewer fetches than a 4x4 grid.
60
+ const int TAPS = 3;
61
+
62
+ vec4 readSrc(vec2 contentUv) {
63
+ vec2 p = clamp(contentUv, 0.0, 1.0);
64
+ return texture(src, srcRectUv.xy + p * srcRectUv.zw);
65
+ }
66
+
67
+ // 4x4 ordered (Bayer) dither threshold in (0, 1), keyed by cell index so
68
+ // the offset is constant across a cell (one character per cell).
69
+ float bayer4x4(vec2 cell) {
70
+ int x = int(mod(cell.x, 4.0));
71
+ int y = int(mod(cell.y, 4.0));
72
+ float m[16] = float[16](
73
+ 0.0, 8.0, 2.0, 10.0,
74
+ 12.0, 4.0, 14.0, 6.0,
75
+ 3.0, 11.0, 1.0, 9.0,
76
+ 15.0, 7.0, 13.0, 5.0
77
+ );
78
+ return (m[y * 4 + x] + 0.5) / 16.0;
79
+ }
80
+
81
+ void main() {
82
+ if (uvContent.x < 0.0 || uvContent.x > 1.0 ||
83
+ uvContent.y < 0.0 || uvContent.y > 1.0) {
84
+ outColor = vec4(0.0);
85
+ return;
86
+ }
87
+
88
+ // Anchor the grid at the element (srcRect) centre so cells are
89
+ // symmetric about the middle instead of growing from the bottom-left
90
+ // corner — any partial cells split evenly between opposite edges.
91
+ vec2 fragPx = uvContent * elementPx;
92
+ vec2 gridOrigin = elementPx * 0.5;
93
+ vec2 rel = fragPx - gridOrigin;
94
+ vec2 cellIdx = floor(rel / cellPx);
95
+ vec2 cellOriginPx = gridOrigin + cellIdx * cellPx;
96
+
97
+ vec4 acc = vec4(0.0);
98
+ for (int y = 0; y < TAPS; ++y) {
99
+ for (int x = 0; x < TAPS; ++x) {
100
+ vec2 o = (vec2(float(x), float(y)) + 0.5) / float(TAPS);
101
+ vec2 samplePx = cellOriginPx + o * cellPx;
102
+ acc += readSrc(samplePx / elementPx);
103
+ }
104
+ }
105
+ acc /= float(TAPS * TAPS);
106
+
107
+ float lum = dot(acc.rgb, vec3(0.299, 0.587, 0.114));
108
+ if (invert == 1) {
109
+ lum = 1.0 - lum;
110
+ }
111
+
112
+ // Pick the glyph and its cell in the atlas (top-row origin in canvas
113
+ // space; the texture is uploaded Y-flipped, hence the 1.0 - ... on v).
114
+ // Ordered dither perturbs the continuous index by up to ±0.5 cell
115
+ // (at dither == 1), so neighbouring cells round to different glyphs
116
+ // and short ramps gain apparent tonal steps without banding.
117
+ float li = lum * charCount;
118
+ if (dither > 0.0) {
119
+ li += (bayer4x4(cellIdx) - 0.5) * dither;
120
+ }
121
+ float idx = clamp(floor(li), 0.0, charCount - 1.0);
122
+ float col = mod(idx, cols);
123
+ float rowTop = floor(idx / cols);
124
+
125
+ // Fit the glyph's character box into the cell with its native
126
+ // aspect preserved (contain): scale by the limiting axis and centre,
127
+ // so a wide cell letterboxes left/right and a tall cell top/bottom
128
+ // instead of stretching the glyph to the cell's aspect.
129
+ vec2 local = fract(rel / cellPx);
130
+ float cellAspect = cellPx.x / cellPx.y;
131
+ vec2 frac = min(vec2(1.0), vec2(glyphAspect / cellAspect, cellAspect / glyphAspect));
132
+ vec2 gloc = (local - 0.5) / frac + 0.5;
133
+
134
+ vec4 tile = vec4(0.0);
135
+ if (gloc.x >= 0.0 && gloc.x <= 1.0 && gloc.y >= 0.0 && gloc.y <= 1.0) {
136
+ // Image tiles can fill the cell edge-to-edge, so linear filtering
137
+ // would bleed a neighbouring tile's colour across the shared
138
+ // border — inset the sample by half a texel to stop it. Glyphs
139
+ // have transparent side bearings, so they need no inset.
140
+ vec2 inset = tileColor == 1 ? 0.5 / atlasCellPx : vec2(0.0);
141
+ vec2 g2 = mix(inset, 1.0 - inset, gloc);
142
+ float u = (col + g2.x) / cols;
143
+ float v = 1.0 - (rowTop + 1.0 - g2.y) / rows;
144
+ tile = texture(atlas, vec2(u, v));
145
+ }
146
+
147
+ // Image tiles keep their own RGBA; glyph tiles are a coverage mask in
148
+ // .a, tinted by color (or the cell's average colour). The alpha is the
149
+ // same either way: tile coverage x color.a (global opacity) x the
150
+ // cell's source alpha, so transparent regions (e.g. text captures)
151
+ // fall back to the background.
152
+ vec3 fg;
153
+ if (tileColor == 1) {
154
+ fg = tile.rgb;
155
+ } else {
156
+ fg = colorFromSource == 1 ? acc.rgb : color.rgb;
157
+ }
158
+ float fgA = tile.a * color.a * acc.a;
159
+
160
+ float outA = fgA + background.a * (1.0 - fgA);
161
+ vec3 premul = fg * fgA + background.rgb * background.a * (1.0 - fgA);
162
+ outColor = vec4(premul, outA);
163
+ }
164
+ `;
165
+ const DEFAULT_PARAMS = {
166
+ grid: 12,
167
+ preset: "standard",
168
+ font: "monospace",
169
+ fontWeight: "normal",
170
+ color: [1, 1, 1, 1],
171
+ background: [0, 0, 0, 0],
172
+ colorFromSource: false,
173
+ invert: false,
174
+ dither: 0,
175
+ };
176
+ // Atlas glyph cell height (physical px). Fixed and oversized vs. typical
177
+ // on-screen cells so linear minification keeps glyphs crisp. Cell width
178
+ // is measured from the font's advance so glyphs sit flush horizontally.
179
+ const GLYPH_PX = 64;
180
+ /**
181
+ * Split a ramp into single-character cells (per Unicode code point).
182
+ */
183
+ function resolveChars(ramp) {
184
+ return Array.isArray(ramp) ? [...ramp] : Array.from(ramp);
185
+ }
186
+ /** Normalize `grid` to a `[width, height]` pair in CSS px. */
187
+ function resolveGrid(grid) {
188
+ return typeof grid === "number" ? [grid, grid] : grid;
189
+ }
190
+ /**
191
+ * Best-effort wait for `font` to be ready before rasterising the atlas,
192
+ * so the first build doesn't fall back to a system font. No-op outside
193
+ * the browser / when the Font Loading API is unavailable.
194
+ */
195
+ async function ensureFont(font, weight) {
196
+ const fonts = (typeof document !== "undefined"
197
+ ? document.fonts
198
+ : undefined);
199
+ if (!fonts?.load) {
200
+ return;
201
+ }
202
+ try {
203
+ await fonts.load(`${weight} ${GLYPH_PX}px ${font}`);
204
+ await fonts.ready;
205
+ }
206
+ catch {
207
+ // Font unavailable — fall through and let canvas pick a fallback.
208
+ }
209
+ }
210
+ /**
211
+ * Render the ramp into a single glyph atlas canvas, laid out as a near-
212
+ * square grid of cells. Cell height is `GLYPH_PX`; cell width tracks the
213
+ * widest glyph's advance so glyphs sit flush (no baked-in side bearings
214
+ * that would show as wide gaps on screen) yet wide glyphs (e.g. full-width
215
+ * CJK) stay within their cell. White glyphs on transparent; the shader
216
+ * reads coverage from the alpha channel.
217
+ */
218
+ function buildAtlas(chars, font, weight, aspectOverride) {
219
+ const n = Math.max(1, chars.length);
220
+ const cols = Math.ceil(Math.sqrt(n));
221
+ const rows = Math.ceil(n / cols);
222
+ const fontStr = `${weight} ${GLYPH_PX}px ${font}`;
223
+ const canvas = document.createElement("canvas");
224
+ // Cell width = explicit aspect, or the widest glyph's advance (measure
225
+ // first; resizing the canvas later resets context state).
226
+ let cellW;
227
+ if (aspectOverride && aspectOverride > 0) {
228
+ cellW = Math.max(1, Math.round(aspectOverride * GLYPH_PX));
229
+ }
230
+ else {
231
+ const probe = canvas.getContext("2d");
232
+ cellW = GLYPH_PX;
233
+ if (probe) {
234
+ probe.font = fontStr;
235
+ // Size the cell to the widest glyph in the ramp — not a fixed
236
+ // probe char — so wide glyphs (e.g. full-width CJK) don't spill
237
+ // into the neighbouring cell in the atlas.
238
+ let maxAdvance = 0;
239
+ for (const ch of chars) {
240
+ maxAdvance = Math.max(maxAdvance, probe.measureText(ch).width);
241
+ }
242
+ if (maxAdvance > 0) {
243
+ cellW = Math.max(1, Math.ceil(maxAdvance));
244
+ }
245
+ }
246
+ }
247
+ canvas.width = cols * cellW;
248
+ canvas.height = rows * GLYPH_PX;
249
+ const g = canvas.getContext("2d");
250
+ if (g) {
251
+ g.clearRect(0, 0, canvas.width, canvas.height);
252
+ g.fillStyle = "#fff";
253
+ g.textAlign = "center";
254
+ g.textBaseline = "middle";
255
+ g.font = fontStr;
256
+ for (let i = 0; i < chars.length; i++) {
257
+ const col = i % cols;
258
+ const row = Math.floor(i / cols);
259
+ const cx = col * cellW + cellW / 2;
260
+ const cy = row * GLYPH_PX + GLYPH_PX / 2;
261
+ // Clip to the cell so ink that overshoots the advance can't bleed
262
+ // into the next cell (extra guard on top of the max-advance width).
263
+ g.save();
264
+ g.beginPath();
265
+ g.rect(col * cellW, row * GLYPH_PX, cellW, GLYPH_PX);
266
+ g.clip();
267
+ g.fillText(chars[i], cx, cy);
268
+ g.restore();
269
+ }
270
+ }
271
+ return { canvas, cols, rows, cellW, cellH: GLYPH_PX };
272
+ }
273
+ // Upper bound on a single atlas axis (px). The image atlas is scaled to
274
+ // fit so it stays within common GPU max-texture-size limits.
275
+ const MAX_ATLAS_PX = 2048;
276
+ // Upper bound on a single tile cell (px) before the atlas-fit scale.
277
+ const MAX_TILE_PX = 256;
278
+ /** Intrinsic pixel size of an image source. */
279
+ function imageSize(src) {
280
+ if (typeof HTMLImageElement !== "undefined" &&
281
+ src instanceof HTMLImageElement) {
282
+ return [src.naturalWidth || src.width, src.naturalHeight || src.height];
283
+ }
284
+ const s = src;
285
+ return [s.width || 1, s.height || 1];
286
+ }
287
+ /** Load a tile source: decode URL strings, pass through ready images. */
288
+ async function resolveImage(src) {
289
+ if (typeof src !== "string") {
290
+ return src;
291
+ }
292
+ const img = new Image();
293
+ img.crossOrigin = "anonymous";
294
+ img.src = src;
295
+ try {
296
+ await img.decode();
297
+ }
298
+ catch {
299
+ // Broken / tainted source — drawImage will just paint nothing.
300
+ }
301
+ return img;
302
+ }
303
+ /**
304
+ * Render image tiles (dark → light order) into one atlas. All tiles share
305
+ * a single cell aspect (from the first tile) and are contain-fitted so
306
+ * odd sizes letterbox instead of distorting. The cell size is derived
307
+ * from the tallest tile, capped, then the whole atlas is scaled down to
308
+ * fit {@link MAX_ATLAS_PX}.
309
+ */
310
+ function buildImageAtlas(images) {
311
+ const n = Math.max(1, images.length);
312
+ const cols = Math.ceil(Math.sqrt(n));
313
+ const rows = Math.ceil(n / cols);
314
+ const sizes = images.map(imageSize);
315
+ const [w0, h0] = sizes[0] ?? [1, 1];
316
+ const aspect = w0 / Math.max(1, h0);
317
+ const tallest = Math.max(1, ...sizes.map((s) => s[1]));
318
+ let cellH = Math.min(MAX_TILE_PX, Math.max(8, Math.round(tallest)));
319
+ let cellW = Math.max(1, Math.round(cellH * aspect));
320
+ // Shrink uniformly so neither atlas axis exceeds the cap.
321
+ const fit = Math.min(1, MAX_ATLAS_PX / (cols * cellW), MAX_ATLAS_PX / (rows * cellH));
322
+ cellW = Math.max(1, Math.floor(cellW * fit));
323
+ cellH = Math.max(1, Math.floor(cellH * fit));
324
+ const canvas = document.createElement("canvas");
325
+ canvas.width = cols * cellW;
326
+ canvas.height = rows * cellH;
327
+ const g = canvas.getContext("2d");
328
+ if (g) {
329
+ g.clearRect(0, 0, canvas.width, canvas.height);
330
+ for (let i = 0; i < images.length; i++) {
331
+ const [iw, ih] = sizes[i];
332
+ const s = Math.min(cellW / iw, cellH / ih);
333
+ const dw = iw * s;
334
+ const dh = ih * s;
335
+ const dx = (i % cols) * cellW + (cellW - dw) / 2;
336
+ const dy = Math.floor(i / cols) * cellH + (cellH - dh) / 2;
337
+ g.drawImage(images[i], dx, dy, dw, dh);
338
+ }
339
+ }
340
+ return { canvas, cols, rows, cellW, cellH };
341
+ }
342
+ /**
343
+ * ASCII / glyph-mosaic effect.
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * vfx.add(el, { effect: new AsciiEffect({ font: "Helvetica", grid: 16 }) });
348
+ * vfx.add(el, { effect: new AsciiEffect({ chars: [" ", ".", "+", "#"] }) });
349
+ * // Image tiles (dark → light), each keeping its own colour:
350
+ * vfx.add(el, { effect: new AsciiEffect({ tiles: ["/0.png", "/1.png"] }) });
351
+ * ```
352
+ *
353
+ * Glyphs keep their native aspect ratio regardless of the `grid` ratio:
354
+ * each is fitted (contain) into its cell, so a non-square cell letterboxes
355
+ * rather than stretching the character. Match `grid` to the font's
356
+ * character box (≈ advance : em) for gap-free tiling.
357
+ *
358
+ * `grid`, `color`, `background`, `colorFromSource`, `invert`, and `dither`
359
+ * are live (read every frame). `chars` / `tiles` / `font` / `fontWeight` /
360
+ * `charAspect` are baked into the atlas at `init()` — after changing them
361
+ * via `setParams`, call {@link AsciiEffect.updateAtlas} (or re-add the
362
+ * effect) to rebuild.
363
+ */
364
+ export class AsciiEffect {
365
+ constructor(initial = {}) {
366
+ _AsciiEffect_instances.add(this);
367
+ _AsciiEffect_atlas.set(this, null);
368
+ _AsciiEffect_cols.set(this, 1);
369
+ _AsciiEffect_rows.set(this, 1);
370
+ _AsciiEffect_charCount.set(this, 1);
371
+ _AsciiEffect_glyphAspect.set(this, 1);
372
+ _AsciiEffect_atlasCellPx.set(this, [1, 1]);
373
+ _AsciiEffect_tileColor.set(this, false);
374
+ _AsciiEffect_ctx.set(this, null);
375
+ this.params = { ...DEFAULT_PARAMS, ...initial };
376
+ }
377
+ setParams(updates) {
378
+ Object.assign(this.params, updates);
379
+ }
380
+ async init(ctx) {
381
+ if (typeof document === "undefined") {
382
+ return;
383
+ }
384
+ __classPrivateFieldSet(this, _AsciiEffect_ctx, ctx, "f");
385
+ await __classPrivateFieldGet(this, _AsciiEffect_instances, "m", _AsciiEffect_build).call(this, ctx);
386
+ }
387
+ /**
388
+ * Rebuild the atlas from the current params, applying changes to the
389
+ * baked fields (`chars` / `tiles` / `font` / `fontWeight` /
390
+ * `charAspect`) without removing and re-adding the effect. Async — it
391
+ * may load fonts or decode image tiles. No-op before `init()`.
392
+ *
393
+ * Allocates a fresh atlas texture and disposes the previous one once the
394
+ * swap is live, so repeated calls don't leak. Still does real work
395
+ * (rasterising / decoding), so prefer occasional calls (e.g. on a
396
+ * settings change) over per-frame use.
397
+ */
398
+ async updateAtlas() {
399
+ if (!__classPrivateFieldGet(this, _AsciiEffect_ctx, "f")) {
400
+ return;
401
+ }
402
+ await __classPrivateFieldGet(this, _AsciiEffect_instances, "m", _AsciiEffect_build).call(this, __classPrivateFieldGet(this, _AsciiEffect_ctx, "f"));
403
+ }
404
+ render(ctx) {
405
+ if (!__classPrivateFieldGet(this, _AsciiEffect_atlas, "f")) {
406
+ return;
407
+ }
408
+ const [ew, eh] = ctx.dims.elementPixel;
409
+ const [gx, gy] = resolveGrid(this.params.grid);
410
+ const cellPx = [
411
+ Math.max(1, gx) * ctx.pixelRatio,
412
+ Math.max(1, gy) * ctx.pixelRatio,
413
+ ];
414
+ ctx.draw({
415
+ frag: FRAG_ASCII,
416
+ uniforms: {
417
+ src: ctx.src,
418
+ atlas: __classPrivateFieldGet(this, _AsciiEffect_atlas, "f"),
419
+ elementPx: [Math.max(1, ew), Math.max(1, eh)],
420
+ cellPx,
421
+ cols: __classPrivateFieldGet(this, _AsciiEffect_cols, "f"),
422
+ rows: __classPrivateFieldGet(this, _AsciiEffect_rows, "f"),
423
+ charCount: __classPrivateFieldGet(this, _AsciiEffect_charCount, "f"),
424
+ glyphAspect: __classPrivateFieldGet(this, _AsciiEffect_glyphAspect, "f"),
425
+ atlasCellPx: __classPrivateFieldGet(this, _AsciiEffect_atlasCellPx, "f"),
426
+ tileColor: __classPrivateFieldGet(this, _AsciiEffect_tileColor, "f") ? 1 : 0,
427
+ color: this.params.color,
428
+ background: this.params.background,
429
+ colorFromSource: this.params.colorFromSource ? 1 : 0,
430
+ invert: this.params.invert ? 1 : 0,
431
+ dither: Math.min(1, Math.max(0, this.params.dither)),
432
+ },
433
+ target: ctx.target,
434
+ });
435
+ }
436
+ dispose() {
437
+ __classPrivateFieldGet(this, _AsciiEffect_atlas, "f")?.dispose();
438
+ __classPrivateFieldSet(this, _AsciiEffect_atlas, null, "f");
439
+ __classPrivateFieldSet(this, _AsciiEffect_ctx, null, "f");
440
+ }
441
+ }
442
+ _AsciiEffect_atlas = new WeakMap(), _AsciiEffect_cols = new WeakMap(), _AsciiEffect_rows = new WeakMap(), _AsciiEffect_charCount = new WeakMap(), _AsciiEffect_glyphAspect = new WeakMap(), _AsciiEffect_atlasCellPx = new WeakMap(), _AsciiEffect_tileColor = new WeakMap(), _AsciiEffect_ctx = new WeakMap(), _AsciiEffect_instances = new WeakSet(), _AsciiEffect_build = async function _AsciiEffect_build(ctx) {
443
+ const tiles = this.params.tiles;
444
+ let built;
445
+ if (tiles && tiles.length > 0) {
446
+ const images = await Promise.all(tiles.map(resolveImage));
447
+ __classPrivateFieldSet(this, _AsciiEffect_charCount, images.length, "f");
448
+ __classPrivateFieldSet(this, _AsciiEffect_tileColor, true, "f");
449
+ built = buildImageAtlas(images);
450
+ }
451
+ else {
452
+ if (tiles && tiles.length === 0) {
453
+ console.warn("[VFX-JS] AsciiEffect: `tiles` is empty; falling back to characters.");
454
+ }
455
+ const chars = resolveChars(this.params.chars ?? ASCII_PRESETS[this.params.preset]);
456
+ if (chars.length === 0) {
457
+ console.warn("[VFX-JS] AsciiEffect: empty character ramp; nothing will be rendered.");
458
+ }
459
+ __classPrivateFieldSet(this, _AsciiEffect_charCount, Math.max(1, chars.length), "f");
460
+ __classPrivateFieldSet(this, _AsciiEffect_tileColor, false, "f");
461
+ await ensureFont(this.params.font, this.params.fontWeight);
462
+ built = buildAtlas(chars, this.params.font, this.params.fontWeight, this.params.charAspect);
463
+ }
464
+ // Swap in the new atlas, then free the old one. Disposing after the
465
+ // swap means any render() that ran between the awaits above still
466
+ // sampled the previous, valid texture. No-op on the first build.
467
+ const previous = __classPrivateFieldGet(this, _AsciiEffect_atlas, "f");
468
+ __classPrivateFieldSet(this, _AsciiEffect_cols, built.cols, "f");
469
+ __classPrivateFieldSet(this, _AsciiEffect_rows, built.rows, "f");
470
+ __classPrivateFieldSet(this, _AsciiEffect_glyphAspect, built.cellW / built.cellH, "f");
471
+ __classPrivateFieldSet(this, _AsciiEffect_atlasCellPx, [built.cellW, built.cellH], "f");
472
+ __classPrivateFieldSet(this, _AsciiEffect_atlas, ctx.wrapTexture(built.canvas, {
473
+ autoUpdate: false,
474
+ filter: "linear",
475
+ }), "f");
476
+ previous?.dispose();
477
+ };
478
+ //# sourceMappingURL=ascii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ascii.js","sourceRoot":"","sources":["../../src/ascii.ts"],"names":[],"mappings":";;;;;;;;;;;;AAmCA;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAoC;IAC1D,yEAAyE;IACzE,oDAAoD;IACpD,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,KAAK;IAC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,uBAAA,IAAI,sBAAU,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE;QACxC,UAAU,EAAE,KAAK;QACjB,MAAM,EAAE,QAAQ;KACnB,CAAC,MAAA,CAAC;IACH,QAAQ,EAAE,OAAO,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ export type ChromaticParams = {
3
+ /** Strength of the colour separation. */
4
+ intensity: number;
5
+ /** Radius (in normalised units) where the aberration begins. */
6
+ radius: number;
7
+ /** Falloff exponent of the aberration curve. */
8
+ power: number;
9
+ };
10
+ export declare class ChromaticEffect implements Effect {
11
+ params: ChromaticParams;
12
+ constructor(initial?: Partial<ChromaticParams>);
13
+ setParams(updates: Partial<ChromaticParams>): void;
14
+ render(ctx: EffectContext): void;
15
+ }