@effing/canvas 0.23.1 → 0.23.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 +5 -39
- package/dist/index.d.ts +1 -1
- package/dist/index.js +507 -437
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
> Part of the [**Effing**](../../README.md) family — programmatic video creation with TypeScript.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A canvas that can render JSX elements and Lottie animations, powered by Skia (via [@napi-rs/canvas](https://github.com/Brooooooklyn/canvas)) and Yoga flexbox layout. Supports emoji, font management, and CSS properties including transforms, gradients, and text effects.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -57,21 +57,7 @@ const png = await canvas.encode("png");
|
|
|
57
57
|
await fs.writeFile("output.png", png);
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
##
|
|
61
|
-
|
|
62
|
-
### Rendering Pipeline
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
JSX → Yoga layout → Skia canvas → PNG
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
1. **Yoga** calculates flex layout from your JSX tree (flexbox, positioning, text measurement)
|
|
69
|
-
2. **Skia** draws each node to a canvas context (backgrounds, borders, text, images, SVG, gradients)
|
|
70
|
-
3. **Encode** the canvas to PNG or JPEG via `canvas.encode()` or `canvas.encodeSync()`
|
|
71
|
-
|
|
72
|
-
Canvas dimensions default to `ctx.canvas.width` / `ctx.canvas.height`, but you can override them with the `width` and `height` options. This is useful for HiDPI rendering where the canvas is larger than the logical layout size.
|
|
73
|
-
|
|
74
|
-
### Font Loading
|
|
60
|
+
## Font Loading
|
|
75
61
|
|
|
76
62
|
Fonts must be registered before rendering text. You can pass them via the `fonts` option (registered automatically), or register them manually:
|
|
77
63
|
|
|
@@ -92,7 +78,7 @@ registerFontFromPath("./fonts/Inter-Bold.ttf", "Inter");
|
|
|
92
78
|
console.log(registeredFamilies()); // ["Inter", ...]
|
|
93
79
|
```
|
|
94
80
|
|
|
95
|
-
|
|
81
|
+
## Emoji Support
|
|
96
82
|
|
|
97
83
|
Emoji characters are automatically rendered as images from CDNs. Supported styles:
|
|
98
84
|
|
|
@@ -107,7 +93,7 @@ Emoji characters are automatically rendered as images from CDNs. Supported style
|
|
|
107
93
|
|
|
108
94
|
Pass `emoji: "none"` to disable emoji image rendering.
|
|
109
95
|
|
|
110
|
-
|
|
96
|
+
## Lottie Animations
|
|
111
97
|
|
|
112
98
|
Render individual frames of Lottie animations to a canvas:
|
|
113
99
|
|
|
@@ -249,7 +235,7 @@ function createCanvas(width: number, height: number): Canvas;
|
|
|
249
235
|
Render a React element tree to a canvas context.
|
|
250
236
|
|
|
251
237
|
```typescript
|
|
252
|
-
function renderReactElement(
|
|
238
|
+
async function renderReactElement(
|
|
253
239
|
ctx: SKRSContext2D,
|
|
254
240
|
element: ReactNode,
|
|
255
241
|
options: RenderReactElementOptions,
|
|
@@ -389,27 +375,7 @@ await renderReactElement(ctx, <MyComponent />, {
|
|
|
389
375
|
});
|
|
390
376
|
```
|
|
391
377
|
|
|
392
|
-
### HiDPI Rendering
|
|
393
|
-
|
|
394
|
-
For sharp output on high-DPI displays, you can create a larger canvas and use `width`/`height` overrides to keep layout at the logical size:
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
const dpr = 2;
|
|
398
|
-
const canvas = createCanvas(1080 * dpr, 1080 * dpr);
|
|
399
|
-
const ctx = canvas.getContext("2d");
|
|
400
|
-
ctx.scale(dpr, dpr);
|
|
401
|
-
|
|
402
|
-
await renderReactElement(ctx, <MyComponent />, {
|
|
403
|
-
fonts,
|
|
404
|
-
width: 1080,
|
|
405
|
-
height: 1080,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
const png = await canvas.encode("png");
|
|
409
|
-
```
|
|
410
|
-
|
|
411
378
|
## Related Packages
|
|
412
379
|
|
|
413
380
|
- [`@effing/tween`](../tween) — Step iteration and easing for frame generation
|
|
414
381
|
- [`@effing/annie`](../annie) — Package rendered frames into animations
|
|
415
|
-
- [`@effing/satori`](../satori) — Alternative JSX-to-PNG renderer (Satori + Resvg)
|