@clypra-studio/engine 0.1.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.
- package/LICENSE +9 -0
- package/README.md +677 -0
- package/dist/chunk-5JOAEDIQ.js +446 -0
- package/dist/chunk-5JOAEDIQ.js.map +1 -0
- package/dist/chunk-CJRH4PAV.js +2826 -0
- package/dist/chunk-CJRH4PAV.js.map +1 -0
- package/dist/chunk-EVQAI3P3.js +3725 -0
- package/dist/chunk-EVQAI3P3.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-QMRMNH52.js +811 -0
- package/dist/chunk-QMRMNH52.js.map +1 -0
- package/dist/index-BWo6qV_z.d.cts +139 -0
- package/dist/index-BWo6qV_z.d.ts +139 -0
- package/dist/index-lNWEWqab.d.cts +633 -0
- package/dist/index-lNWEWqab.d.ts +633 -0
- package/dist/index.cjs +21232 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12254 -0
- package/dist/index.d.ts +12254 -0
- package/dist/index.js +13320 -0
- package/dist/index.js.map +1 -0
- package/dist/textEffects/index.cjs +3341 -0
- package/dist/textEffects/index.cjs.map +1 -0
- package/dist/textEffects/index.d.cts +1 -0
- package/dist/textEffects/index.d.ts +1 -0
- package/dist/textEffects/index.js +30 -0
- package/dist/textEffects/index.js.map +1 -0
- package/dist/transitions/index.cjs +848 -0
- package/dist/transitions/index.cjs.map +1 -0
- package/dist/transitions/index.d.cts +170 -0
- package/dist/transitions/index.d.ts +170 -0
- package/dist/transitions/index.js +32 -0
- package/dist/transitions/index.js.map +1 -0
- package/dist/v2/backends/index.cjs +480 -0
- package/dist/v2/backends/index.cjs.map +1 -0
- package/dist/v2/backends/index.d.cts +3 -0
- package/dist/v2/backends/index.d.ts +3 -0
- package/dist/v2/backends/index.js +8 -0
- package/dist/v2/backends/index.js.map +1 -0
- package/dist/v2/contract/index.cjs +18 -0
- package/dist/v2/contract/index.cjs.map +1 -0
- package/dist/v2/contract/index.d.cts +165 -0
- package/dist/v2/contract/index.d.ts +165 -0
- package/dist/v2/contract/index.js +1 -0
- package/dist/v2/contract/index.js.map +1 -0
- package/dist/videoEffects/index.cjs +2883 -0
- package/dist/videoEffects/index.cjs.map +1 -0
- package/dist/videoEffects/index.d.cts +801 -0
- package/dist/videoEffects/index.d.ts +801 -0
- package/dist/videoEffects/index.js +68 -0
- package/dist/videoEffects/index.js.map +1 -0
- package/package.json +119 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Abdulkabir Musa(AIEraDev)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
# @clypra/engine
|
|
2
|
+
|
|
3
|
+
The rendering and animation engine powering [Clypra Studio](https://github.com/AIEraDev/clypra-studio) — a high-performance Canvas 2D text effects system with GPU-accelerated PixiJS video effects, full Lottie JSON tooling, keyframe animation, and CapCut-style template support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @clypra/engine
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**New in v1.27+**: GPU-accelerated video effects via PixiJS 8! See [PixiJS Video Effects](#pixijs-video-effects) below.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { textEffectConfigToScene, evaluateScene, defaultConfig } from "@clypra/engine";
|
|
17
|
+
|
|
18
|
+
// Build a scene from a config
|
|
19
|
+
const scene = textEffectConfigToScene({
|
|
20
|
+
...defaultConfig,
|
|
21
|
+
text: "CLYPRA",
|
|
22
|
+
fontFamily: "Poppins",
|
|
23
|
+
fontWeight: 900,
|
|
24
|
+
fontSize: 80,
|
|
25
|
+
fillType: "linear",
|
|
26
|
+
fillGradientStops: [
|
|
27
|
+
{ color: "#FF5500", offset: 0 },
|
|
28
|
+
{ color: "#FF0080", offset: 100 },
|
|
29
|
+
],
|
|
30
|
+
bevelEnabled: true,
|
|
31
|
+
bevelDepth: 16,
|
|
32
|
+
bevelShadow: "#880000",
|
|
33
|
+
bevelHighlight: "#FFFFFF",
|
|
34
|
+
glowLayers: [{ enabled: true, color: "#FF2200", blur: 30, opacity: 60, type: "outer", strength: 2 }],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Size the canvas to match the config
|
|
38
|
+
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
|
39
|
+
canvas.width = scene.canvas.width;
|
|
40
|
+
canvas.height = scene.canvas.height;
|
|
41
|
+
const ctx = canvas.getContext("2d")!;
|
|
42
|
+
|
|
43
|
+
// Wait for fonts, then draw
|
|
44
|
+
const fontSpec = `${scene.text.fontWeight} ${scene.text.fontSize}px "${scene.text.fontFamily}"`;
|
|
45
|
+
await document.fonts.load(fontSpec);
|
|
46
|
+
evaluateScene(scene, 0, ctx);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## PixiJS Video Effects
|
|
52
|
+
|
|
53
|
+
**v1.27+** introduces 37 GPU-accelerated video effects powered by PixiJS 8 and WebGL.
|
|
54
|
+
|
|
55
|
+
### Quick Start
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { PixiRenderer, EffectEngine, EffectGraph, NeonGlowEffect, RGBSplitEffect, MotionBlurEffect } from "@clypra/engine";
|
|
59
|
+
|
|
60
|
+
// Create renderer
|
|
61
|
+
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
|
62
|
+
const renderer = new PixiRenderer(canvas);
|
|
63
|
+
|
|
64
|
+
// Create effect engine
|
|
65
|
+
const engine = new EffectEngine();
|
|
66
|
+
|
|
67
|
+
// Build effect graph
|
|
68
|
+
let graph = new EffectGraph();
|
|
69
|
+
graph = graph.addNode("glow", NeonGlowEffect, {
|
|
70
|
+
distance: 20,
|
|
71
|
+
innerStrength: 1.5,
|
|
72
|
+
outerStrength: 3.0,
|
|
73
|
+
color: "#7C6FFF",
|
|
74
|
+
quality: 0.3,
|
|
75
|
+
knockout: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Apply to video element
|
|
79
|
+
const video = document.getElementById("video") as HTMLVideoElement;
|
|
80
|
+
renderer.mount(graph, video);
|
|
81
|
+
|
|
82
|
+
// Animate (60fps)
|
|
83
|
+
function animate() {
|
|
84
|
+
renderer.render();
|
|
85
|
+
requestAnimationFrame(animate);
|
|
86
|
+
}
|
|
87
|
+
animate();
|
|
88
|
+
|
|
89
|
+
// Update parameters in real-time
|
|
90
|
+
graph = graph.updateNode("glow", { color: "#FF00FF", distance: 30 });
|
|
91
|
+
renderer.mount(graph, video);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Effect Categories (37 Total)
|
|
95
|
+
|
|
96
|
+
#### 💡 Light Effects (10)
|
|
97
|
+
|
|
98
|
+
- `NeonGlowEffect` - Premium neon outline glow
|
|
99
|
+
- `GlowEffect` - Standard glow with inner/outer strength
|
|
100
|
+
- `LightLeakEffect` - Cinematic light sweep
|
|
101
|
+
- `LensFlareEffect` - Dual-stage godray + starburst
|
|
102
|
+
- `VignetteEffect` - Edge darkening with falloff
|
|
103
|
+
- `ColorGradientEffect` - Gradient overlays
|
|
104
|
+
- `ColorOverlayEffect` - Blend color layers
|
|
105
|
+
- `ColorMatrixEffect` - Advanced color transformation
|
|
106
|
+
- `HslAdjustmentEffect` - Hue/saturation/lightness
|
|
107
|
+
- `AlphaEffect` - Transparency control
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { NeonGlowEffect } from "@clypra/engine";
|
|
111
|
+
|
|
112
|
+
const params = {
|
|
113
|
+
distance: 15,
|
|
114
|
+
innerStrength: 1.0,
|
|
115
|
+
outerStrength: 2.0,
|
|
116
|
+
color: "#7C6FFF",
|
|
117
|
+
quality: 0.1,
|
|
118
|
+
knockout: false,
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### 🌀 Glitch Effects (5)
|
|
123
|
+
|
|
124
|
+
- `RGBSplitEffect` - Chromatic aberration
|
|
125
|
+
- `VHSEffect` - Vintage tape artifacts
|
|
126
|
+
- `CRTEffect` - Cathode ray tube simulation
|
|
127
|
+
- `GlitchBandEffect` - Horizontal displacement
|
|
128
|
+
- `StaticNoiseEffect` - Film grain and TV static
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { RGBSplitEffect } from "@clypra/engine";
|
|
132
|
+
|
|
133
|
+
const params = {
|
|
134
|
+
redX: 4,
|
|
135
|
+
redY: 0,
|
|
136
|
+
blueX: -4,
|
|
137
|
+
blueY: 0,
|
|
138
|
+
greenX: 0,
|
|
139
|
+
greenY: 0,
|
|
140
|
+
speed: 1.5,
|
|
141
|
+
animated: true,
|
|
142
|
+
};
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### 🎬 Cinematic Effects (10)
|
|
146
|
+
|
|
147
|
+
- `GaussianBlurEffect` - Classic Gaussian blur
|
|
148
|
+
- `KawaseBlurEffect` - Efficient iterative blur
|
|
149
|
+
- `MotionBlurEffect` - Directional motion blur
|
|
150
|
+
- `RadialBlurEffect` - Zoom-style blur
|
|
151
|
+
- `ZoomBlurEffect` - Perspective zoom
|
|
152
|
+
- `TiltShiftEffect` - Miniature/DoF simulation
|
|
153
|
+
- `FilmGrainEffect` - Organic film grain
|
|
154
|
+
- `OldFilmEffect` - Vintage aging
|
|
155
|
+
- `CinematicLUTEffect` - Color grading
|
|
156
|
+
- `DropShadowEffect` - Soft shadow projection
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { MotionBlurEffect } from "@clypra/engine";
|
|
160
|
+
|
|
161
|
+
const params = {
|
|
162
|
+
velocity: [10, 0], // [x, y] direction
|
|
163
|
+
kernelSize: 5,
|
|
164
|
+
offset: 0,
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 🌊 Distortion Effects (5)
|
|
169
|
+
|
|
170
|
+
- `BulgePinchEffect` - Lens distortion
|
|
171
|
+
- `TwistEffect` - Rotational twist
|
|
172
|
+
- `ShockwaveEffect` - Animated ripple wave
|
|
173
|
+
- `ReflectionEffect` - Water reflection
|
|
174
|
+
- `DisplacementEffect` - Texture-based displacement
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { BulgePinchEffect } from "@clypra/engine";
|
|
178
|
+
|
|
179
|
+
const params = {
|
|
180
|
+
center: [0.5, 0.5], // normalized coordinates
|
|
181
|
+
radius: 200,
|
|
182
|
+
strength: 0.5, // -1 to 1 (negative = pinch)
|
|
183
|
+
};
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### 🎨 Stylization Effects (7)
|
|
187
|
+
|
|
188
|
+
- `AsciiEffect` - ASCII art conversion
|
|
189
|
+
- `PixelateEffect` - Retro pixel art
|
|
190
|
+
- `DotEffect` - Halftone dot pattern
|
|
191
|
+
- `OutlineEffect` - Edge detection
|
|
192
|
+
- `EmbossEffect` - 3D embossed relief
|
|
193
|
+
- `CrossHatchEffect` - Pen-and-ink style
|
|
194
|
+
- `GrayscaleEffect` - Monochrome conversion
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { PixelateEffect } from "@clypra/engine";
|
|
198
|
+
|
|
199
|
+
const params = {
|
|
200
|
+
size: 10, // pixel block size (1-50)
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Effect Graph Composition
|
|
205
|
+
|
|
206
|
+
Chain multiple effects for complex visuals:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { EffectGraph, GlowEffect, RGBSplitEffect, VHSEffect } from "@clypra/engine";
|
|
210
|
+
|
|
211
|
+
let graph = new EffectGraph();
|
|
212
|
+
|
|
213
|
+
// Add effects in order
|
|
214
|
+
graph = graph.addNode("glow", GlowEffect, { distance: 20, color: "#FF00FF" });
|
|
215
|
+
graph = graph.addNode("rgb", RGBSplitEffect, { redX: 5, blueX: -5 });
|
|
216
|
+
graph = graph.addNode("vhs", VHSEffect, { noise: 0.1, scanlines: true });
|
|
217
|
+
|
|
218
|
+
// Update individual effect parameters
|
|
219
|
+
graph = graph.updateNode("glow", { distance: 30 });
|
|
220
|
+
|
|
221
|
+
// Remove an effect
|
|
222
|
+
graph = graph.removeNode("rgb");
|
|
223
|
+
|
|
224
|
+
// Get execution order (respects dependencies)
|
|
225
|
+
const order = graph.getExecutionOrder(); // ["glow", "vhs"]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### PixiRenderer Lifecycle
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { PixiRenderer } from "@clypra/engine";
|
|
232
|
+
|
|
233
|
+
const renderer = new PixiRenderer(canvas);
|
|
234
|
+
|
|
235
|
+
// Mount effect graph to video/image source
|
|
236
|
+
renderer.mount(effectGraph, videoElement);
|
|
237
|
+
|
|
238
|
+
// Render frame (call in animation loop)
|
|
239
|
+
renderer.render();
|
|
240
|
+
|
|
241
|
+
// Update graph without remounting
|
|
242
|
+
renderer.updateGraph(newGraph);
|
|
243
|
+
|
|
244
|
+
// Cleanup
|
|
245
|
+
renderer.unmount();
|
|
246
|
+
renderer.destroy();
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Effect Definition Schema
|
|
250
|
+
|
|
251
|
+
Create custom PixiJS effects:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import type { PixiEffectDefinition } from "@clypra/engine";
|
|
255
|
+
import { GlowFilter } from "pixi-filters";
|
|
256
|
+
|
|
257
|
+
export const CustomGlowEffect: PixiEffectDefinition = {
|
|
258
|
+
backend: "pixi",
|
|
259
|
+
subtype: "filter", // "filter" | "motion" | "composite"
|
|
260
|
+
id: "custom-glow",
|
|
261
|
+
name: "Custom Glow",
|
|
262
|
+
category: "light",
|
|
263
|
+
description: "My custom glow effect",
|
|
264
|
+
tags: ["light", "glow"],
|
|
265
|
+
thumbnail: "",
|
|
266
|
+
params: [
|
|
267
|
+
{ key: "distance", label: "Distance", type: "range", value: 10, min: 0, max: 50, step: 1 },
|
|
268
|
+
{ key: "color", label: "Color", type: "color", value: "#FFFFFF" },
|
|
269
|
+
{ key: "enabled", label: "Enabled", type: "toggle", value: true },
|
|
270
|
+
],
|
|
271
|
+
filterSpec: {
|
|
272
|
+
create(params) {
|
|
273
|
+
return new GlowFilter({
|
|
274
|
+
distance: params.distance as number,
|
|
275
|
+
color: parseInt((params.color as string).replace("#", "0x"), 16),
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
updateUniforms(filter, params) {
|
|
279
|
+
filter.distance = params.distance as number;
|
|
280
|
+
filter.color = parseInt((params.color as string).replace("#", "0x"), 16);
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Example Presets
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { ExamplePixiEffects } from "@clypra/engine";
|
|
290
|
+
|
|
291
|
+
// NeonGlowEffect - Purple neon with preset parameters
|
|
292
|
+
const neonGlow = ExamplePixiEffects.NeonGlowEffect;
|
|
293
|
+
|
|
294
|
+
// VHSCompositeEffect - Multi-effect vintage tape
|
|
295
|
+
const vhs = ExamplePixiEffects.VHSCompositeEffect;
|
|
296
|
+
|
|
297
|
+
// ParticleBurstEffect - Motion + filter composite
|
|
298
|
+
const particles = ExamplePixiEffects.ParticleBurstEffect;
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Effect Registry
|
|
302
|
+
|
|
303
|
+
Access metadata for all effects:
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
import { getEffectMetadata, EFFECTS_REGISTRY } from "@clypra/engine";
|
|
307
|
+
|
|
308
|
+
// Get single effect metadata
|
|
309
|
+
const metadata = getEffectMetadata("neon-glow");
|
|
310
|
+
console.log(metadata.name); // "Neon Glow"
|
|
311
|
+
console.log(metadata.category); // "light"
|
|
312
|
+
console.log(metadata.defaultParams); // { distance: 15, color: "#7C6FFF", ... }
|
|
313
|
+
|
|
314
|
+
// Browse all effects
|
|
315
|
+
Object.keys(EFFECTS_REGISTRY).forEach((id) => {
|
|
316
|
+
const meta = EFFECTS_REGISTRY[id];
|
|
317
|
+
console.log(`${meta.name} (${meta.category}): ${meta.description}`);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// Filter by category
|
|
321
|
+
const glitchEffects = Object.values(EFFECTS_REGISTRY).filter((e) => e.category === "glitch");
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Browser Compatibility
|
|
325
|
+
|
|
326
|
+
- Requires WebGL 1.0+ support
|
|
327
|
+
- Tested on Chrome 90+, Firefox 88+, Safari 15+
|
|
328
|
+
- Falls back to Canvas2D on WebGL failure
|
|
329
|
+
- Mobile support via hardware acceleration
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Core Concepts
|
|
334
|
+
|
|
335
|
+
### TextEffectConfig
|
|
336
|
+
|
|
337
|
+
The flat config object that describes every visual property of a text effect. Pass it to `textEffectConfigToScene()` to convert it into a `SceneDocument` for rendering.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
import { type TextEffectConfig, defaultConfig } from "@clypra/engine";
|
|
341
|
+
|
|
342
|
+
const config: TextEffectConfig = {
|
|
343
|
+
...defaultConfig,
|
|
344
|
+
text: "MY TEXT",
|
|
345
|
+
fontFamily: "Montserrat",
|
|
346
|
+
fontWeight: 900,
|
|
347
|
+
fontSize: 100,
|
|
348
|
+
|
|
349
|
+
// Fill
|
|
350
|
+
fillType: "solid", // "solid" | "linear" | "radial" | "pattern" | "none"
|
|
351
|
+
fillColor: "#FFFFFF",
|
|
352
|
+
fillGradientAngle: 90,
|
|
353
|
+
fillGradientStops: [
|
|
354
|
+
{ color: "#FF5500", offset: 0 },
|
|
355
|
+
{ color: "#FF0080", offset: 100 },
|
|
356
|
+
],
|
|
357
|
+
patternType: "grunge", // "chalk" | "noise" | "grunge" | "carbon" | "stripes" | "film" | "brushed" | "marble" | "halftone" | "paper"
|
|
358
|
+
|
|
359
|
+
// Stroke
|
|
360
|
+
strokeEnabled: true,
|
|
361
|
+
strokeColor: "#FFFFFF",
|
|
362
|
+
strokeWidth: 3,
|
|
363
|
+
strokePosition: "outside", // "outside" | "center" | "inside"
|
|
364
|
+
strokeOpacity: 100,
|
|
365
|
+
strokeLineJoin: "round", // "round" | "miter" | "bevel"
|
|
366
|
+
strokeBlur: 4, // soft glow on stroke edge
|
|
367
|
+
strokeType: "single", // "single" | "double" | "neon"
|
|
368
|
+
strokeColorSecondary: "#000000",
|
|
369
|
+
strokeWidthSecondary: 6,
|
|
370
|
+
strokeFadeRange: 0, // 0-100, vertical fade
|
|
371
|
+
|
|
372
|
+
// Shadow
|
|
373
|
+
shadowEnabled: true,
|
|
374
|
+
shadowColor: "#000000",
|
|
375
|
+
shadowBlur: 12,
|
|
376
|
+
shadowOffsetX: 4,
|
|
377
|
+
shadowOffsetY: 6,
|
|
378
|
+
shadowOpacity: 80,
|
|
379
|
+
shadowType: "drop", // "drop" | "inner"
|
|
380
|
+
|
|
381
|
+
// Glow (up to 6 layers)
|
|
382
|
+
glowLayers: [{ enabled: true, color: "#FF2200", blur: 30, opacity: 60, type: "outer", strength: 2, spread: 0 }],
|
|
383
|
+
|
|
384
|
+
// 3D Bevel / Extrusion
|
|
385
|
+
bevelEnabled: true,
|
|
386
|
+
bevelDepth: 20,
|
|
387
|
+
bevelHighlight: "#FFFFFF",
|
|
388
|
+
bevelShadow: "#1A0000",
|
|
389
|
+
bevelCoreColor: "#880000",
|
|
390
|
+
bevelDirection: "bottom-right", // "bottom-right" | "bottom" | "right"
|
|
391
|
+
bevelEdgeColor: "#333333",
|
|
392
|
+
bevelEdgeWidth: 1,
|
|
393
|
+
bevelBlur: 8,
|
|
394
|
+
bevelBlurColor: "#000000",
|
|
395
|
+
bevelPerspectiveEnabled: false,
|
|
396
|
+
bevelVanishingPointX: 40,
|
|
397
|
+
bevelVanishingPointY: 80,
|
|
398
|
+
bevelFocalLength: 400,
|
|
399
|
+
|
|
400
|
+
// Multi-stack extrusion
|
|
401
|
+
stackEnabled: false,
|
|
402
|
+
stackCount: 4,
|
|
403
|
+
stackOffsetX: 10,
|
|
404
|
+
stackOffsetY: -10,
|
|
405
|
+
stackOpacityDecay: 20,
|
|
406
|
+
stackColor1: "#FF7C00",
|
|
407
|
+
stackColor2: "#00FFDD",
|
|
408
|
+
stackColor3: "#FF00AA",
|
|
409
|
+
stackColor4: "#AA00FF",
|
|
410
|
+
|
|
411
|
+
// Background panel
|
|
412
|
+
panelEnabled: false,
|
|
413
|
+
panelColor: "#1A1A2E",
|
|
414
|
+
panelOpacity: 90,
|
|
415
|
+
panelRadius: 12,
|
|
416
|
+
panelPaddingX: 40,
|
|
417
|
+
panelPaddingY: 20,
|
|
418
|
+
panelStrokeEnabled: false,
|
|
419
|
+
panelStrokeColor: "#333333",
|
|
420
|
+
panelStrokeWidth: 1,
|
|
421
|
+
|
|
422
|
+
// Canvas
|
|
423
|
+
canvasWidth: 800,
|
|
424
|
+
canvasHeight: 200,
|
|
425
|
+
textPosX: "center", // "left" | "center" | "right"
|
|
426
|
+
textPosY: "middle", // "top" | "middle" | "bottom"
|
|
427
|
+
wrapText: true,
|
|
428
|
+
autoFitText: false,
|
|
429
|
+
|
|
430
|
+
// Per-character fill
|
|
431
|
+
perCharFillEnabled: false,
|
|
432
|
+
charFillColors: [],
|
|
433
|
+
};
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
## Rendering
|
|
439
|
+
|
|
440
|
+
### `evaluateScene(scene, time, ctx)`
|
|
441
|
+
|
|
442
|
+
The main render function. Applies timeline animation at time `t` and draws to a Canvas 2D context.
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
import { evaluateScene, textEffectConfigToScene, defaultConfig } from "@clypra/engine";
|
|
446
|
+
|
|
447
|
+
const scene = textEffectConfigToScene({ ...defaultConfig, text: "HELLO" });
|
|
448
|
+
const ctx = canvas.getContext("2d")!;
|
|
449
|
+
|
|
450
|
+
// Static render at t=0
|
|
451
|
+
evaluateScene(scene, 0, ctx);
|
|
452
|
+
|
|
453
|
+
// Animated render loop
|
|
454
|
+
let t = 0;
|
|
455
|
+
const fps = 30;
|
|
456
|
+
setInterval(() => {
|
|
457
|
+
t = (t + 1 / fps) % scene.timeline.duration;
|
|
458
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
459
|
+
evaluateScene(scene, t, ctx);
|
|
460
|
+
}, 1000 / fps);
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Font Loading (Critical)
|
|
464
|
+
|
|
465
|
+
Always wait for fonts before drawing. Rendering before fonts are ready produces incorrect layout and missing effects like stroke blur.
|
|
466
|
+
|
|
467
|
+
```ts
|
|
468
|
+
import { preloadGoogleFont } from "@clypra/engine";
|
|
469
|
+
|
|
470
|
+
// Preload specific font
|
|
471
|
+
preloadGoogleFont("Montserrat", [400, 700, 900]);
|
|
472
|
+
|
|
473
|
+
// Wait for a specific face before drawing
|
|
474
|
+
const fontSpec = `${config.fontWeight} ${config.fontSize}px "${config.fontFamily}"`;
|
|
475
|
+
await document.fonts.load(fontSpec);
|
|
476
|
+
|
|
477
|
+
// Now draw
|
|
478
|
+
evaluateScene(scene, 0, ctx);
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### Canvas Sizing
|
|
482
|
+
|
|
483
|
+
Always set canvas dimensions to match the config **before** drawing:
|
|
484
|
+
|
|
485
|
+
```ts
|
|
486
|
+
canvas.width = config.canvasWidth || 800;
|
|
487
|
+
canvas.height = config.canvasHeight || 200;
|
|
488
|
+
evaluateScene(scene, 0, ctx);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### ctx.filter Support
|
|
492
|
+
|
|
493
|
+
Stroke blur, bevel ambient blur, and bloom effects use `ctx.filter`. Verify support in your environment:
|
|
494
|
+
|
|
495
|
+
```ts
|
|
496
|
+
const testCtx = document.createElement("canvas").getContext("2d")!;
|
|
497
|
+
testCtx.filter = "blur(4px)";
|
|
498
|
+
const filterSupported = testCtx.filter !== "none" && testCtx.filter !== "";
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
If `ctx.filter` is not supported (some WebViews, React Native canvas), use the `WebGLCompositor` fallback:
|
|
502
|
+
|
|
503
|
+
```ts
|
|
504
|
+
import { evaluateScene, WebGLCompositor } from "@clypra/engine";
|
|
505
|
+
|
|
506
|
+
const compositor = new WebGLCompositor();
|
|
507
|
+
if (compositor.isSupported) {
|
|
508
|
+
const off = new OffscreenCanvas(canvas.width, canvas.height);
|
|
509
|
+
const offCtx = off.getContext("2d")!;
|
|
510
|
+
evaluateScene(scene, 0, offCtx);
|
|
511
|
+
compositor.renderToContext(ctx, off, { blur: 2, bloom: 0, bloomThreshold: 0.6 });
|
|
512
|
+
} else {
|
|
513
|
+
evaluateScene(scene, 0, ctx);
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## Presets
|
|
520
|
+
|
|
521
|
+
```ts
|
|
522
|
+
import { builtInPresets, getPresetScene, blendScenes } from "@clypra/engine";
|
|
523
|
+
|
|
524
|
+
// Apply a built-in preset
|
|
525
|
+
const preset = builtInPresets.find((p) => p.id === "neon-crimson")!;
|
|
526
|
+
const scene = getPresetScene(preset);
|
|
527
|
+
|
|
528
|
+
// Blend two presets (0.0 = all A, 1.0 = all B)
|
|
529
|
+
const blended = blendScenes(sceneA, sceneB, 0.6);
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
## Timeline Animation
|
|
535
|
+
|
|
536
|
+
```ts
|
|
537
|
+
import { addTrack, addKeyframeAtTime, updateTimeline, ensureDefaultTimeline } from "@clypra/engine";
|
|
538
|
+
|
|
539
|
+
// Add a shadow drift animation track
|
|
540
|
+
let scene = addTrack(scene, shadowLayerId, "shadowOffsetY", [
|
|
541
|
+
{ time: 0, value: 4, easing: "easeInOut" },
|
|
542
|
+
{ time: 1.5, value: 16, easing: "easeInOut" },
|
|
543
|
+
{ time: 3, value: 4, easing: "easeInOut" },
|
|
544
|
+
]);
|
|
545
|
+
|
|
546
|
+
// Change timeline duration / fps
|
|
547
|
+
scene = updateTimeline(scene, { duration: 3, fps: 30, loop: true });
|
|
548
|
+
|
|
549
|
+
// Apply built-in demo animation (shadow drift + mask reveal)
|
|
550
|
+
scene = ensureDefaultTimeline(scene);
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Export
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
import { downloadPngSequenceZip, downloadSceneWebM, isWebMExportSupported, buildDotLottie, downloadLottieJson } from "@clypra/engine";
|
|
559
|
+
|
|
560
|
+
// PNG sequence as ZIP
|
|
561
|
+
downloadPngSequenceZip(scene, "my-effect", { fps: 30, duration: 2 });
|
|
562
|
+
|
|
563
|
+
// WebM video
|
|
564
|
+
if (isWebMExportSupported()) {
|
|
565
|
+
await downloadSceneWebM(scene, "my-effect.webm", { fps: 30, duration: 2 });
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// dotLottie (.lottie) file
|
|
569
|
+
await buildDotLottie(lottieJson, "animation-id", { loop: true, autoplay: true });
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
## Lottie Tooling
|
|
575
|
+
|
|
576
|
+
### Build Lottie from scratch
|
|
577
|
+
|
|
578
|
+
```ts
|
|
579
|
+
import { createBlankLottie, addTextLayer, addSolidLayer, addOrUpdateKeyframe, enableKeyframing } from "@clypra/engine";
|
|
580
|
+
|
|
581
|
+
let lottie = createBlankLottie(1920, 1080, 30, 120);
|
|
582
|
+
lottie = addSolidLayer(lottie, "Background", "#0A0A0F", 1920, 1080);
|
|
583
|
+
lottie = addTextLayer(lottie, "Title", "HELLO WORLD");
|
|
584
|
+
|
|
585
|
+
// Animate position
|
|
586
|
+
lottie = enableKeyframing(lottie, 0, "ks.p");
|
|
587
|
+
lottie = addOrUpdateKeyframe(lottie, 0, "ks.p", 0, [960, 200, 0], "easeOut");
|
|
588
|
+
lottie = addOrUpdateKeyframe(lottie, 0, "ks.p", 30, [960, 540, 0], "easeInOut");
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Inject text and styles
|
|
592
|
+
|
|
593
|
+
```ts
|
|
594
|
+
import { injectBatch } from "@clypra/engine";
|
|
595
|
+
|
|
596
|
+
const result = injectBatch(lottieJson, {
|
|
597
|
+
textCustomization: {
|
|
598
|
+
customization: { primary: "BREAKING NEWS", secondary: "Reporter", accent: "9:41 PM" },
|
|
599
|
+
layers: mappedLayers,
|
|
600
|
+
},
|
|
601
|
+
colorOverrides: [{ layerName: "Accent Bar", color: "#FF2200" }],
|
|
602
|
+
hiddenLayers: new Set([3]),
|
|
603
|
+
});
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### CapCut-style animation presets (30+)
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
import { getAnimPreset, bakeAnimationIntoLayer } from "@clypra/engine";
|
|
610
|
+
|
|
611
|
+
const preset = getAnimPreset("zoom-in-bounce")!;
|
|
612
|
+
const animated = bakeAnimationIntoLayer(lottieJson, 0, preset, {
|
|
613
|
+
startFrame: 0,
|
|
614
|
+
endFrame: preset.defaultDurationFrames,
|
|
615
|
+
totalFrames: 120,
|
|
616
|
+
compW: 1920,
|
|
617
|
+
compH: 1080,
|
|
618
|
+
});
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
Available presets — **Entrance:** `fade-in`, `slide-up`, `slide-down`, `slide-left`, `slide-right`, `zoom-in`, `zoom-in-bounce`, `pop-in`, `flip-x`, `flip-y`, `rotate-in`, `blur-in`, `drop-in`, `typewriter`, `wipe-left`, `glitch-in` — **Exit:** `fade-out`, `slide-out-up`, `slide-out-down`, `zoom-out`, `zoom-blast`, `glitch-out` — **Loop:** `pulse`, `breathe`, `float`, `shake`, `wobble`, `neon-flicker`, `wave` — **Emphasis:** `attention`, `jello`, `swing`
|
|
622
|
+
|
|
623
|
+
### Built-in templates (13)
|
|
624
|
+
|
|
625
|
+
```ts
|
|
626
|
+
import { getTemplatePreset } from "@clypra/engine";
|
|
627
|
+
|
|
628
|
+
const template = getTemplatePreset("neon-title")!;
|
|
629
|
+
const lottieJson = template.build(); // ready-to-use Lottie JSON
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Available: `clean-lower-third`, `minimal-lower-third`, `neon-title`, `cinematic-title`, `minimal-caption`, `typewriter-caption`, `bold-callout`, `sports-score`, `social-quote`, `kinetic-text`, `glitch-title`, `vertical-story`, `drop-in-title`
|
|
633
|
+
|
|
634
|
+
---
|
|
635
|
+
|
|
636
|
+
## Per-Character Fill
|
|
637
|
+
|
|
638
|
+
```ts
|
|
639
|
+
import { resizeCharFillColors, setCharFillColor, rainbowCharFillColors } from "@clypra/engine";
|
|
640
|
+
|
|
641
|
+
let colors = resizeCharFillColors("HELLO", [], "#FFFFFF");
|
|
642
|
+
colors = setCharFillColor(colors, 0, "#FF0000"); // H → red
|
|
643
|
+
colors = setCharFillColor(colors, 4, "#0080FF"); // O → blue
|
|
644
|
+
|
|
645
|
+
// Or rainbow fill
|
|
646
|
+
const rainbow = rainbowCharFillColors("HELLO");
|
|
647
|
+
|
|
648
|
+
const config = { ...myConfig, perCharFillEnabled: true, charFillColors: colors };
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
---
|
|
652
|
+
|
|
653
|
+
## Undo / History
|
|
654
|
+
|
|
655
|
+
```ts
|
|
656
|
+
import { snapshotScene, parseHistorySnapshot } from "@clypra/engine";
|
|
657
|
+
|
|
658
|
+
// Save
|
|
659
|
+
const snapshot = snapshotScene(scene);
|
|
660
|
+
undoStack.push(snapshot);
|
|
661
|
+
|
|
662
|
+
// Restore
|
|
663
|
+
const { scene: prevScene } = parseHistorySnapshot(undoStack.pop()!);
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
---
|
|
667
|
+
|
|
668
|
+
## License
|
|
669
|
+
|
|
670
|
+
MIT License - [Clypra Studio](https://github.com/AIEraDev/clypra-studio)
|
|
671
|
+
|
|
672
|
+
---
|
|
673
|
+
|
|
674
|
+
**Package Version:** 1.28.0
|
|
675
|
+
**Last Updated:** June 2026
|
|
676
|
+
**Repository:** [github.com/AIEraDev/clypra-studio](https://github.com/AIEraDev/clypra-studio)
|
|
677
|
+
**NPM:** [@clypra/engine](https://www.npmjs.com/package/@clypra/engine)
|