@clypra-studio/engine 0.1.0 → 0.1.2
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/README.md +37 -657
- package/dist/index.js +48 -48
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,677 +1,57 @@
|
|
|
1
|
-
# @clypra/engine
|
|
1
|
+
# @clypra-studio/engine
|
|
2
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
|
|
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 timeline capabilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @clypra/engine
|
|
8
|
+
npm install @clypra-studio/engine
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @clypra-studio/engine
|
|
11
|
+
# or
|
|
12
|
+
yarn add @clypra-studio/engine
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
## Usage
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
import { EffectRenderer } from "@clypra-studio/engine";
|
|
19
|
+
import { TransitionRenderer } from "@clypra-studio/engine/transitions";
|
|
20
|
+
import { TextEffectConfig } from "@clypra-studio/engine/textEffects";
|
|
21
|
+
import { PixiRenderBackend } from "@clypra-studio/engine/v2/backends";
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
// Create an effect renderer
|
|
24
|
+
const renderer = new EffectRenderer(canvas, effect);
|
|
17
25
|
|
|
18
|
-
//
|
|
19
|
-
|
|
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 });
|
|
26
|
+
// Render a frame
|
|
27
|
+
await renderer.render(frame);
|
|
570
28
|
```
|
|
571
29
|
|
|
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
|
-
```
|
|
30
|
+
## Features
|
|
605
31
|
|
|
606
|
-
|
|
32
|
+
- ✅ **Text Effects** - Canvas 2D text rendering with advanced effects
|
|
33
|
+
- ✅ **Video Effects** - GPU-accelerated effects using PixiJS
|
|
34
|
+
- ✅ **Transitions** - Professional transition effects
|
|
35
|
+
- ✅ **Lottie Support** - Full Lottie JSON animation tooling
|
|
36
|
+
- ✅ **Keyframe Animation** - Timeline-based animation system
|
|
37
|
+
- ✅ **Render Backends** - Pixi.js GPU rendering support
|
|
607
38
|
|
|
608
|
-
|
|
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
|
-
```
|
|
39
|
+
## Entry Points
|
|
665
40
|
|
|
666
|
-
|
|
41
|
+
- **`@clypra-studio/engine`** - Main engine exports
|
|
42
|
+
- **`@clypra-studio/engine/transitions`** - Transition effects
|
|
43
|
+
- **`@clypra-studio/engine/videoEffects`** - Video effect definitions
|
|
44
|
+
- **`@clypra-studio/engine/textEffects`** - Text effect system
|
|
45
|
+
- **`@clypra-studio/engine/v2/backends`** - Rendering backends
|
|
46
|
+
- **`@clypra-studio/engine/v2/contract`** - V2 API contracts
|
|
667
47
|
|
|
668
48
|
## License
|
|
669
49
|
|
|
670
|
-
MIT
|
|
50
|
+
MIT
|
|
671
51
|
|
|
672
|
-
|
|
52
|
+
## Links
|
|
673
53
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
54
|
+
- [GitHub Repository](https://github.com/AIEraDev/clypra-studio)
|
|
55
|
+
- [Documentation](https://github.com/AIEraDev/clypra-studio/tree/main/packages/clypra-engine#readme)
|
|
56
|
+
- [Report Issues](https://github.com/AIEraDev/clypra-studio/issues)
|
|
57
|
+
- [npm Package](https://www.npmjs.com/package/@clypra-studio/engine)
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TRANSITION_CATEGORIES,
|
|
3
|
-
TRANSITION_PRESETS,
|
|
4
|
-
TransitionRenderer,
|
|
5
|
-
getAllTransitionTags,
|
|
6
|
-
getAllTransitions,
|
|
7
|
-
getRecommendedDuration,
|
|
8
|
-
getTransitionById,
|
|
9
|
-
getTransitionByRenderer,
|
|
10
|
-
getTransitionCategories,
|
|
11
|
-
getTransitionCountByCategory,
|
|
12
|
-
getTransitionsByCategory,
|
|
13
|
-
getTransitionsByTags,
|
|
14
|
-
searchTransitions
|
|
15
|
-
} from "./chunk-QMRMNH52.js";
|
|
16
|
-
import {
|
|
17
|
-
EFFECTS_REGISTRY,
|
|
18
|
-
EffectEngine,
|
|
19
|
-
EffectGraph,
|
|
20
|
-
EffectRenderer,
|
|
21
|
-
PixiRenderer,
|
|
22
|
-
addNoise,
|
|
23
|
-
blendColors,
|
|
24
|
-
camera_exports,
|
|
25
|
-
clearCanvas,
|
|
26
|
-
effectMetadataToApi,
|
|
27
|
-
example_exports,
|
|
28
|
-
generateEffectsManifest,
|
|
29
|
-
getAllEffectsForApi,
|
|
30
|
-
getEffectByIdForApi,
|
|
31
|
-
getEffectCategoriesSummary,
|
|
32
|
-
getEffectMetadata,
|
|
33
|
-
getEffectPreviewUrl,
|
|
34
|
-
getEffectRenderer,
|
|
35
|
-
getEffectsByCategory,
|
|
36
|
-
getEffectsByCategoryForApi,
|
|
37
|
-
hexToRgba,
|
|
38
|
-
isCanvas2DEffect,
|
|
39
|
-
isCompositeEffect,
|
|
40
|
-
isFilterEffect,
|
|
41
|
-
isMotionEffect,
|
|
42
|
-
isPixiEffect,
|
|
43
|
-
light_exports,
|
|
44
|
-
rgbaToComponents,
|
|
45
|
-
searchEffects,
|
|
46
|
-
searchEffectsForApi,
|
|
47
|
-
withContext
|
|
48
|
-
} from "./chunk-CJRH4PAV.js";
|
|
49
1
|
import {
|
|
50
2
|
COMPOSITION_PRESETS,
|
|
51
3
|
CUSTOM_ENGINE_IDS,
|
|
@@ -120,6 +72,54 @@ import {
|
|
|
120
72
|
textEffectConfigToScene,
|
|
121
73
|
wrapTextToWidth
|
|
122
74
|
} from "./chunk-EVQAI3P3.js";
|
|
75
|
+
import {
|
|
76
|
+
TRANSITION_CATEGORIES,
|
|
77
|
+
TRANSITION_PRESETS,
|
|
78
|
+
TransitionRenderer,
|
|
79
|
+
getAllTransitionTags,
|
|
80
|
+
getAllTransitions,
|
|
81
|
+
getRecommendedDuration,
|
|
82
|
+
getTransitionById,
|
|
83
|
+
getTransitionByRenderer,
|
|
84
|
+
getTransitionCategories,
|
|
85
|
+
getTransitionCountByCategory,
|
|
86
|
+
getTransitionsByCategory,
|
|
87
|
+
getTransitionsByTags,
|
|
88
|
+
searchTransitions
|
|
89
|
+
} from "./chunk-QMRMNH52.js";
|
|
90
|
+
import {
|
|
91
|
+
EFFECTS_REGISTRY,
|
|
92
|
+
EffectEngine,
|
|
93
|
+
EffectGraph,
|
|
94
|
+
EffectRenderer,
|
|
95
|
+
PixiRenderer,
|
|
96
|
+
addNoise,
|
|
97
|
+
blendColors,
|
|
98
|
+
camera_exports,
|
|
99
|
+
clearCanvas,
|
|
100
|
+
effectMetadataToApi,
|
|
101
|
+
example_exports,
|
|
102
|
+
generateEffectsManifest,
|
|
103
|
+
getAllEffectsForApi,
|
|
104
|
+
getEffectByIdForApi,
|
|
105
|
+
getEffectCategoriesSummary,
|
|
106
|
+
getEffectMetadata,
|
|
107
|
+
getEffectPreviewUrl,
|
|
108
|
+
getEffectRenderer,
|
|
109
|
+
getEffectsByCategory,
|
|
110
|
+
getEffectsByCategoryForApi,
|
|
111
|
+
hexToRgba,
|
|
112
|
+
isCanvas2DEffect,
|
|
113
|
+
isCompositeEffect,
|
|
114
|
+
isFilterEffect,
|
|
115
|
+
isMotionEffect,
|
|
116
|
+
isPixiEffect,
|
|
117
|
+
light_exports,
|
|
118
|
+
rgbaToComponents,
|
|
119
|
+
searchEffects,
|
|
120
|
+
searchEffectsForApi,
|
|
121
|
+
withContext
|
|
122
|
+
} from "./chunk-CJRH4PAV.js";
|
|
123
123
|
import {
|
|
124
124
|
ColorAdjustmentsEffect,
|
|
125
125
|
PixiRenderBackend
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clypra-studio/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"pixi-filters": "^6.0.0",
|
|
67
67
|
"pixi.js": "^8.0.0",
|
|
68
68
|
"zod": "^4.4.3",
|
|
69
|
-
"@clypra-studio/types": "^0.1.
|
|
69
|
+
"@clypra-studio/types": "^0.1.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@napi-rs/canvas": "^0.1.70",
|
|
@@ -83,8 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public",
|
|
86
|
-
"registry": "https://registry.npmjs.org/"
|
|
87
|
-
"provenance": true
|
|
86
|
+
"registry": "https://registry.npmjs.org/"
|
|
88
87
|
},
|
|
89
88
|
"release": {
|
|
90
89
|
"branches": [
|