@effing/canvas 0.41.0 → 0.42.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/README.md +19 -13
- package/dist/index.d.ts +7 -7
- package/dist/index.js +346 -375
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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
|
-
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.
|
|
7
|
+
A canvas that can render JSX elements and Lottie animations, powered by Skia (via [@effing/skia](https://github.com/builtbyfew/effing-skia), Effing's fork of [@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
|
|
|
@@ -12,11 +12,7 @@ A canvas that can render JSX elements and Lottie animations, powered by Skia (vi
|
|
|
12
12
|
npm install @effing/canvas
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @napi-rs/canvas
|
|
19
|
-
```
|
|
15
|
+
The Skia backend, `@effing/skia`, is installed along with it. It ships prebuilt binaries for Linux x64 and arm64 (glibc and musl), macOS x64 and arm64, and Windows x64.
|
|
20
16
|
|
|
21
17
|
## Quick Start
|
|
22
18
|
|
|
@@ -289,6 +285,17 @@ const png = canvas.encodeSync("png");
|
|
|
289
285
|
| ----------- | ------------------------------------------------ |
|
|
290
286
|
| `objectFit` | `contain`, `cover`, `fill`, `none`, `scale-down` |
|
|
291
287
|
|
|
288
|
+
### Opacity and filters
|
|
289
|
+
|
|
290
|
+
`opacity` and `filter` apply to an element and its descendants as one group,
|
|
291
|
+
as in CSS: overlapping children fade together instead of showing through each
|
|
292
|
+
other, and a `drop-shadow()` is cast once by the whole group.
|
|
293
|
+
|
|
294
|
+
A filter covers the element as painted, so `blur()` softens its edge too,
|
|
295
|
+
rounded corners included. To keep the edge sharp, clip after the filter: give
|
|
296
|
+
the element a `clipPath` (for example `inset(0px round 8px)`), or wrap it in an
|
|
297
|
+
element with `overflow: hidden`.
|
|
298
|
+
|
|
292
299
|
### Clip paths
|
|
293
300
|
|
|
294
301
|
`clipPath` clips the element's entire rendering — background, borders,
|
|
@@ -347,10 +354,9 @@ pixels of the element and follow its `transform`, including non-uniform
|
|
|
347
354
|
scales and skews. At the canvas edge the backdrop is extended outward, like a
|
|
348
355
|
browser clamps it at the viewport edge, so a blur stays uniform there.
|
|
349
356
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
unfiltered backdrop instead of the ancestor forming its own backdrop root.
|
|
357
|
+
As in browsers, an ancestor with `opacity` below 1 or a `filter` is a backdrop
|
|
358
|
+
root: an element inside it sees only what that ancestor has painted so far,
|
|
359
|
+
not what lies behind the ancestor.
|
|
354
360
|
|
|
355
361
|
### Units
|
|
356
362
|
|
|
@@ -360,7 +366,7 @@ unfiltered backdrop instead of the ancestor forming its own backdrop root.
|
|
|
360
366
|
|
|
361
367
|
### `createCanvas(width, height)`
|
|
362
368
|
|
|
363
|
-
Create a new canvas. Re-exported from `@
|
|
369
|
+
Create a new canvas. Re-exported from `@effing/skia`.
|
|
364
370
|
|
|
365
371
|
```typescript
|
|
366
372
|
function createCanvas(width: number, height: number): Canvas;
|
|
@@ -402,7 +408,7 @@ for (let frame = 0; frame < frameCount; frame++) {
|
|
|
402
408
|
|
|
403
409
|
### `loadImage(source, options?)`
|
|
404
410
|
|
|
405
|
-
Load an image from a path, Buffer, data URI, or remote URL. Remote `http`/`https` URLs are fetched via the global `fetch()` — the same path `<img>` sources take in `renderReactElement` — so a global dispatcher / proxy (e.g. undici's `setGlobalDispatcher`) and the `userAgent` option are honored. All other sources delegate to `@
|
|
411
|
+
Load an image from a path, Buffer, data URI, or remote URL. Remote `http`/`https` URLs are fetched via the global `fetch()` — the same path `<img>` sources take in `renderReactElement` — so a global dispatcher / proxy (e.g. undici's `setGlobalDispatcher`) and the `userAgent` option are honored. All other sources delegate to `@effing/skia`'s native loader.
|
|
406
412
|
|
|
407
413
|
```typescript
|
|
408
414
|
function loadImage(
|
|
@@ -504,7 +510,7 @@ type EmojiStyle =
|
|
|
504
510
|
|
|
505
511
|
### Canvas Primitives
|
|
506
512
|
|
|
507
|
-
The building blocks you need alongside a context are re-exported from `@
|
|
513
|
+
The building blocks you need alongside a context are re-exported from `@effing/skia`, so you never need to import (or declare a dependency on) `@effing/skia` directly: `Canvas`, `SKRSContext2D`, `GlobalFonts`, `Image`, `ImageData`, `Path2D`, `DOMMatrix`, `DOMPoint`, `DOMRect`, `PathOp`, `FillType`, `StrokeJoin`, `StrokeCap`, and `LottieAnimation`. (`loadImage` is wrapped — see above — not re-exported directly.)
|
|
508
514
|
|
|
509
515
|
```typescript
|
|
510
516
|
import { createCanvas, Path2D } from "@effing/canvas";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Image, loadImage as loadImage$1, LottieAnimation, SKRSContext2D } from '@
|
|
3
|
-
export { Canvas, DOMMatrix, DOMPoint, DOMRect, FillType, GlobalFonts, Image, ImageData, LottieAnimation, Path2D, PathOp, SKRSContext2D, StrokeCap, StrokeJoin } from '@
|
|
1
|
+
import * as _effing_skia from '@effing/skia';
|
|
2
|
+
import { Image, loadImage as loadImage$1, LottieAnimation, SKRSContext2D } from '@effing/skia';
|
|
3
|
+
export { Canvas, DOMMatrix, DOMPoint, DOMRect, FillType, GlobalFonts, Image, ImageData, LottieAnimation, Path2D, PathOp, SKRSContext2D, StrokeCap, StrokeJoin } from '@effing/skia';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
-
/** Source types accepted by {@link loadImage}, mirroring @
|
|
6
|
+
/** Source types accepted by {@link loadImage}, mirroring @effing/skia. */
|
|
7
7
|
type LoadImageSource = Parameters<typeof loadImage$1>[0];
|
|
8
8
|
/** Options for {@link loadImage}. */
|
|
9
9
|
interface LoadImageOptions {
|
|
@@ -23,11 +23,11 @@ interface LoadImageOptions {
|
|
|
23
23
|
* native loader as bytes — the same path `<img>` sources take in
|
|
24
24
|
* `renderReactElement`. This keeps `loadImage(url)` and `<img src={url}>`
|
|
25
25
|
* consistent: both honor a global dispatcher / proxy (undici's
|
|
26
|
-
* setGlobalDispatcher) and the `userAgent` option. @
|
|
26
|
+
* setGlobalDispatcher) and the `userAgent` option. @effing/skia's own URL
|
|
27
27
|
* loader uses Node's raw http modules, which bypass any dispatcher, so it is
|
|
28
28
|
* only used for non-remote sources here.
|
|
29
29
|
*
|
|
30
|
-
* Note: @
|
|
30
|
+
* Note: @effing/skia's `maxRedirects` / `requestOptions` load options are
|
|
31
31
|
* intentionally not exposed — they only configure its built-in URL loader,
|
|
32
32
|
* which this wrapper bypasses. Control remote fetches via fetch/undici instead.
|
|
33
33
|
*/
|
|
@@ -331,6 +331,6 @@ type FindLargestUsableFontSizeOptions = {
|
|
|
331
331
|
*/
|
|
332
332
|
declare function findLargestUsableFontSize(options: FindLargestUsableFontSizeOptions): number;
|
|
333
333
|
|
|
334
|
-
declare function createCanvas(width: number, height: number):
|
|
334
|
+
declare function createCanvas(width: number, height: number): _effing_skia.Canvas;
|
|
335
335
|
|
|
336
336
|
export { type EmojiStyle, type FindLargestUsableFontSizeOptions, type FontData, type ImageCache, type LoadImageOptions, type LoadImageSource, type RenderReactElementOptions, createCanvas, findLargestUsableFontSize, loadImage, loadLottie, registerFont, registerFontFromPath, registeredFamilies, renderLottieFrame, renderReactElement };
|