@flare-engine/render-web 0.2.1 → 0.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.
- package/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +55 -7
- package/dist/index.d.mts +79 -47
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +79 -47
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +537 -434
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +532 -396
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Canvas, CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
import { EffectChain } from "@flare-engine/postfx";
|
|
3
|
+
import { CanvasLike, FrameRenderer, FrameRendererModule } from "@flare-engine/render";
|
|
4
|
+
//#region src/loader.d.ts
|
|
5
|
+
/** Tuning for the load's failure bounds. Defaults suit a browser on a slow connection. */
|
|
6
|
+
interface LoadCanvasKitOptions {
|
|
7
|
+
/** Abort the stream if no bytes arrive for this long. Default 15000. */
|
|
8
|
+
stallMs?: number;
|
|
9
|
+
/** Hard ceiling on the whole load. Default 45000. */
|
|
10
|
+
deadlineMs?: number;
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Load CanvasKit exactly once. Subsequent calls return the same promise.
|
|
7
14
|
*
|
|
15
|
+
* A rejected load is NOT cached — a transient failure would otherwise strand every later caller
|
|
16
|
+
* on the same rejection for the module's lifetime.
|
|
17
|
+
*
|
|
8
18
|
* @param wasmUrl Absolute URL or filesystem path to canvaskit.wasm.
|
|
9
19
|
* @param onProgress Optional callback receiving download fraction [0,1].
|
|
20
|
+
* @param options Stall and deadline bounds.
|
|
10
21
|
*/
|
|
11
|
-
declare function loadCanvasKit(wasmUrl: string, onProgress?: (fraction: number) => void): Promise<CanvasKit>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create a `FrameRendererModule` backed by CanvasKit.
|
|
17
|
-
*
|
|
18
|
-
* The returned module satisfies the same structural interface that the
|
|
19
|
-
* real RN-Skia module satisfies, so `createFrameRenderer` can accept it.
|
|
20
|
-
*
|
|
21
|
-
* CK differences handled here:
|
|
22
|
-
* - `drawAtlas` takes flat Float32Arrays — the wrapper flattens object pools.
|
|
23
|
-
* - `rotate` is forwarded verbatim (no radians→degrees conversion) to match
|
|
24
|
-
* the native bridge; the dormant radians/degrees mismatch is tracked separately.
|
|
25
|
-
* - `ColorFilter.MakeBlend(color, mode)` takes an EmbindEnumEntity — the
|
|
26
|
-
* wrapper maps the numeric literal (3=SrcOver, 5=SrcIn) to the CK enum.
|
|
27
|
-
* - `RSXform` objects carry `scos/ssin/tx/ty` fields for flat-array flattening.
|
|
28
|
-
*/
|
|
29
|
-
declare function createWebSkiaModule(kit: CanvasKit): FrameRendererModule;
|
|
30
|
-
|
|
22
|
+
declare function loadCanvasKit(wasmUrl: string, onProgress?: (fraction: number) => void, options?: LoadCanvasKitOptions): Promise<CanvasKit>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/postfx-surface.d.ts
|
|
31
25
|
/**
|
|
32
26
|
* A CanvasKit-backed render surface with a parameterized postfx chain.
|
|
33
27
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
28
|
+
* Manages an offscreen scene surface and an on-screen surface, owns the WebGL
|
|
29
|
+
* `GrDirectContext`, handles context loss/restore, and composites the scene
|
|
30
|
+
* through a caller-supplied effect chain each frame.
|
|
36
31
|
*
|
|
37
32
|
* Usage:
|
|
38
33
|
* const chain = new EffectChain();
|
|
@@ -40,25 +35,27 @@ declare function createWebSkiaModule(kit: CanvasKit): FrameRendererModule;
|
|
|
40
35
|
* const surface = createPostFxSurface(kit, canvas, chain);
|
|
41
36
|
*/
|
|
42
37
|
interface PostFxSurface {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
38
|
+
/** Current backing-store width (device px), floored. */
|
|
39
|
+
readonly width: number;
|
|
40
|
+
/** Current backing-store height (device px), floored. */
|
|
41
|
+
readonly height: number;
|
|
42
|
+
/** The offscreen scene canvas — draw the scene here each frame. Null while the context is lost. */
|
|
43
|
+
sceneCanvas(): Canvas | null;
|
|
44
|
+
/** The on-screen canvas — draw crisp overlays here AFTER composite(). Null while lost. */
|
|
45
|
+
onscreenCanvas(): Canvas | null;
|
|
46
|
+
/** Hard-clear the scene to an opaque background (call once after create + after resize). */
|
|
47
|
+
clear(bgRgb: readonly number[]): void;
|
|
48
|
+
/** Motion-blur trail: fade the previous scene frame toward bg instead of clearing. */
|
|
49
|
+
fadeTrail(bgRgb: readonly number[], alpha: number): void;
|
|
50
|
+
/** Snapshot the scene, run the chain at `globalIntensity`, composite to screen. */
|
|
51
|
+
composite(globalIntensity: number): void;
|
|
52
|
+
/** Flush the on-screen surface (after drawing crisp overlays). */
|
|
53
|
+
flush(): void;
|
|
54
|
+
/** Resize the canvas backing store + offscreen surfaces (does NOT clear — call clear() after). */
|
|
55
|
+
resize(width: number, height: number): void;
|
|
56
|
+
/** True while the WebGL context is lost or GPU surfaces could not be allocated. */
|
|
57
|
+
isLost(): boolean;
|
|
58
|
+
dispose(): void;
|
|
62
59
|
}
|
|
63
60
|
/**
|
|
64
61
|
* Create a `PostFxSurface` backed by a WebGL CanvasKit context.
|
|
@@ -71,5 +68,40 @@ interface PostFxSurface {
|
|
|
71
68
|
* Pass a new empty `EffectChain()` for a passthrough surface.
|
|
72
69
|
*/
|
|
73
70
|
declare function createPostFxSurface(kit: CanvasKit, canvas: HTMLCanvasElement, chain: EffectChain): PostFxSurface | null;
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/web-frame-renderer.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Create a `FrameRenderer` backed by CanvasKit (web/WASM).
|
|
75
|
+
*
|
|
76
|
+
* The web analog of `createSkiaFrameRenderer` from `@flare-engine/react`:
|
|
77
|
+
* delegates to `createFrameRenderer(createWebSkiaModule(kit))` so the
|
|
78
|
+
* frame-renderer body is backend-neutral and shared with native.
|
|
79
|
+
*
|
|
80
|
+
* Presentation (drawing the `endFrame()` picture onto a surface and flushing)
|
|
81
|
+
* is the consumer's responsibility — use `createWebSurface` or
|
|
82
|
+
* `createPostFxSurface` for that step.
|
|
83
|
+
*/
|
|
84
|
+
declare function createWebFrameRenderer(kit: CanvasKit): FrameRenderer;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/web-skia-module.d.ts
|
|
87
|
+
/**
|
|
88
|
+
* Create a `FrameRendererModule` backed by CanvasKit.
|
|
89
|
+
*
|
|
90
|
+
* The returned module satisfies the same structural interface that the
|
|
91
|
+
* real RN-Skia module satisfies, so `createFrameRenderer` can accept it.
|
|
92
|
+
*
|
|
93
|
+
* CK differences handled here:
|
|
94
|
+
* - `drawAtlas` takes flat Float32Arrays — the wrapper flattens object pools.
|
|
95
|
+
* - `rotate` is forwarded verbatim (no radians→degrees conversion) to match
|
|
96
|
+
* the native bridge; the dormant radians/degrees mismatch is tracked separately.
|
|
97
|
+
* - `ColorFilter.MakeBlend(color, mode)` takes an EmbindEnumEntity — the
|
|
98
|
+
* wrapper maps the numeric literal (3=SrcOver, 5=SrcIn) to the CK enum.
|
|
99
|
+
* - `RSXform` objects carry `scos/ssin/tx/ty` fields for flat-array flattening.
|
|
100
|
+
*/
|
|
101
|
+
declare function createWebSkiaModule(kit: CanvasKit): FrameRendererModule;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/web-surface.d.ts
|
|
104
|
+
declare function createWebSurface(kit: CanvasKit, canvas: HTMLCanvasElement): CanvasLike | null;
|
|
105
|
+
//#endregion
|
|
106
|
+
export { type LoadCanvasKitOptions, type PostFxSurface, createPostFxSurface, createWebFrameRenderer, createWebSkiaModule, createWebSurface, loadCanvasKit };
|
|
107
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/loader.ts","../src/postfx-surface.ts","../src/web-frame-renderer.ts","../src/web-skia-module.ts","../src/web-surface.ts"],"mappings":";;;;;UAQiB;;EAEf;;EAEA;;;;;;;;;;;;iBAkBc,cACd,iBACA,cAAc,2BACd,UAAS,uBACR,QAAQ;;;;;;;;;;;;;;;UCPM;;WAEN;;WAEA;;EAET,eAAe;;EAEf,kBAAkB;;EAElB,MAAM;;EAEN,UAAU,0BAA0B;;EAEpC,UAAU;;EAEV;;EAEA,OAAO,eAAe;;EAEtB;EACA;;;;;;;;;;;;iBAac,oBACd,KAAK,WACL,QAAQ,mBACR,OAAO,cACN;;;;;;;;;;;;;;iBClDa,uBAAuB,KAAK,YAAY;;;;;;;;;;;;;;;;;iBCyJxC,oBAAoB,KAAK,YAAY;;;iBC3IrC,iBAAiB,KAAK,WAAW,QAAQ,oBAAoB"}
|