@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
package/README.md CHANGED
@@ -42,10 +42,12 @@ await vfx.add(img, {
42
42
 
43
43
  | Effect | Description |
44
44
  | ------------------------ | --------------------------------------------------------------- |
45
+ | `AsciiEffect` | ASCII / glyph mosaic from a dark→light character ramp |
45
46
  | `BloomEffect` | COD:AW-style bloom pyramid with soft-knee threshold |
46
47
  | `FluidEffect` | Stable-Fluids advection driven by pointer events |
47
48
  | `HalftoneEffect` | RGB / CMYK halftone screen with configurable ink presets |
48
49
  | `JPEGGlitchEffect` | Real codec-level JPEG glitch — corrupts the encoded byte stream |
50
+ | `MatrixEffect` | Matrix-movie digital rain — random glyphs over the source grayscale |
49
51
  | `ParticleEffect` | Mouse-emitter GPU particles, skips transparent source regions |
50
52
  | `ParticleExplodeEffect` | One-shot curl-noise burst that shatters the source element |
51
53
  | `VoronoiEffect` | Voronoi cells shrunken in a halo around the cursor |
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parse a hex color into an RGBA tuple in [0, 1].
3
+ * Accepts `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa` (with or without `#`).
4
+ * Alpha defaults to 1. Falls back to transparent black on a malformed value.
5
+ */
6
+ export declare function parseHexColor(hex: string): [number, number, number, number];
7
+ /** 2D rotation matrix and a small hash, shared by the warp/slice ports. */
8
+ export declare const GLSL_COMMON = "\nmat2 rot2d(float a) {\n float c = cos(a), s = sin(a);\n return mat2(c, -s, s, c);\n}\n\nfloat hash11(float p) {\n p = fract(p * 0.1031);\n p *= p + 33.33;\n p *= p + p;\n return fract(p);\n}\n";
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // Shared helpers for the Figma Shader effect ports.
3
+ // Internal module — not part of the public @vfx-js/effects API.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.GLSL_COMMON = void 0;
6
+ exports.parseHexColor = parseHexColor;
7
+ /**
8
+ * Parse a hex color into an RGBA tuple in [0, 1].
9
+ * Accepts `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa` (with or without `#`).
10
+ * Alpha defaults to 1. Falls back to transparent black on a malformed value.
11
+ */
12
+ function parseHexColor(hex) {
13
+ let s = hex.startsWith("#") ? hex.slice(1) : hex;
14
+ if (s.length === 3 || s.length === 4) {
15
+ s = s
16
+ .split("")
17
+ .map((c) => c + c)
18
+ .join("");
19
+ }
20
+ if (s.length === 6) {
21
+ s += "ff";
22
+ }
23
+ if (s.length !== 8) {
24
+ return [0, 0, 0, 0];
25
+ }
26
+ const r = Number.parseInt(s.slice(0, 2), 16) / 255;
27
+ const g = Number.parseInt(s.slice(2, 4), 16) / 255;
28
+ const b = Number.parseInt(s.slice(4, 6), 16) / 255;
29
+ const a = Number.parseInt(s.slice(6, 8), 16) / 255;
30
+ return [r, g, b, a];
31
+ }
32
+ /** 2D rotation matrix and a small hash, shared by the warp/slice ports. */
33
+ exports.GLSL_COMMON = `
34
+ mat2 rot2d(float a) {
35
+ float c = cos(a), s = sin(a);
36
+ return mat2(c, -s, s, c);
37
+ }
38
+
39
+ float hash11(float p) {
40
+ p = fract(p * 0.1031);
41
+ p *= p + 33.33;
42
+ p *= p + p;
43
+ return fract(p);
44
+ }
45
+ `;
46
+ //# sourceMappingURL=_figma-common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_figma-common.js","sourceRoot":"","sources":["../../src/_figma-common.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,gEAAgE;;;AAOhE,sCAmBC;AAxBD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,CAAC,GAAG,CAAC;aACA,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;aACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,CAAC,IAAI,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACnD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACnD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACnD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACnD,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,2EAA2E;AAC9D,QAAA,WAAW,GAAG;;;;;;;;;;;;CAY1B,CAAC"}
@@ -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
+ }