@flare-engine/render-web 0.2.0 → 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 +142 -0
- 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 -418
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +532 -380
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -9
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Grzegorz Otto
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# @flare-engine/render-web
|
|
2
|
+
|
|
3
|
+
CanvasKit-backed web renderer for `@flare-engine/render`. Provides a WebGL surface, a frame-renderer module wired to CanvasKit primitives, and a post-processing surface with a full ping-pong shader pipeline.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/render-web canvaskit-wasm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`canvaskit-wasm` is an optional peer dependency — only required in web environments.
|
|
12
|
+
|
|
13
|
+
## Entry points
|
|
14
|
+
|
|
15
|
+
### `loadCanvasKit` — `loader.ts`
|
|
16
|
+
|
|
17
|
+
Loads the CanvasKit WASM binary and returns a ready `CanvasKit` instance. Takes the URL/path to the `canvaskit.wasm` binary (required), an optional `onProgress(fraction)` download callback, and an optional `LoadCanvasKitOptions` (`stallMs`, default 15000; `deadlineMs`, default 45000) bounding the load.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { loadCanvasKit } from '@flare-engine/render-web';
|
|
21
|
+
|
|
22
|
+
const kit = await loadCanvasKit('/canvaskit.wasm', undefined, { stallMs: 10_000, deadlineMs: 30_000 });
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
A successful load is cached — later calls return the same instance. A **failed** load is not cached: a later call retries from scratch instead of being stranded on the earlier rejection.
|
|
26
|
+
|
|
27
|
+
### `createWebSurface` — `web-surface.ts`
|
|
28
|
+
|
|
29
|
+
Creates a WebGL-backed `CanvasKit` surface from an `HTMLCanvasElement`. Returns `null` when WebGL is unavailable.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import type { CanvasKit } from 'canvaskit-wasm';
|
|
33
|
+
import { createWebSurface } from '@flare-engine/render-web';
|
|
34
|
+
|
|
35
|
+
declare const kit: CanvasKit;
|
|
36
|
+
declare const canvasEl: HTMLCanvasElement;
|
|
37
|
+
|
|
38
|
+
const surface = createWebSurface(kit, canvasEl);
|
|
39
|
+
if (!surface) throw new Error('WebGL unavailable');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### `createWebSkiaModule` — `web-skia-module.ts`
|
|
43
|
+
|
|
44
|
+
Adapts a `CanvasKit` instance into the `FrameRendererModule` interface consumed by `@flare-engine/render`'s `createFrameRenderer`. Wraps `PictureRecorder`, `Paint`, `RSXform`, `XYWHRect`, and shader helpers.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import type { CanvasKit } from 'canvaskit-wasm';
|
|
48
|
+
import type { SkImageLike } from '@flare-engine/assets';
|
|
49
|
+
import type { SpriteDrawCommand } from '@flare-engine/render';
|
|
50
|
+
import { createWebSkiaModule } from '@flare-engine/render-web';
|
|
51
|
+
import { createFrameRenderer } from '@flare-engine/render';
|
|
52
|
+
|
|
53
|
+
declare const kit: CanvasKit;
|
|
54
|
+
declare const width: number;
|
|
55
|
+
declare const height: number;
|
|
56
|
+
declare const atlasImage: SkImageLike;
|
|
57
|
+
declare const commands: SpriteDrawCommand[];
|
|
58
|
+
declare const canvasEl: HTMLCanvasElement;
|
|
59
|
+
|
|
60
|
+
const mod = createWebSkiaModule(kit);
|
|
61
|
+
const renderer = createFrameRenderer(mod);
|
|
62
|
+
|
|
63
|
+
// Present onto a WebGL-backed CanvasKit surface.
|
|
64
|
+
const surface = kit.MakeWebGLCanvasSurface(canvasEl);
|
|
65
|
+
if (!surface) throw new Error('WebGL unavailable');
|
|
66
|
+
const canvas = surface.getCanvas();
|
|
67
|
+
|
|
68
|
+
renderer.beginFrame(width, height, 0, 1);
|
|
69
|
+
renderer.drawAtlas(atlasImage, commands);
|
|
70
|
+
const picture = renderer.endFrame();
|
|
71
|
+
// endFrame() returns the backend-neutral PictureLike; cast to CanvasKit's Picture to present.
|
|
72
|
+
if (picture) canvas.drawPicture(picture as Parameters<typeof canvas.drawPicture>[0]);
|
|
73
|
+
surface.flush();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `createPostFxSurface` — `postfx-surface.ts`
|
|
77
|
+
|
|
78
|
+
Creates a `PostFxSurface` that owns an offscreen scene canvas, a ping-pong intermediate, and an onscreen WebGL surface. At `composite()` time it runs the caller-supplied `EffectChain` through compiled SkSL shaders and blits the result to screen.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import type { Canvas, CanvasKit } from 'canvaskit-wasm';
|
|
82
|
+
import { createPostFxSurface } from '@flare-engine/render-web';
|
|
83
|
+
import { EffectChain, createVignette, createBloom } from '@flare-engine/postfx';
|
|
84
|
+
|
|
85
|
+
declare const kit: CanvasKit;
|
|
86
|
+
declare const canvasEl: HTMLCanvasElement;
|
|
87
|
+
declare const newW: number;
|
|
88
|
+
declare const newH: number;
|
|
89
|
+
declare function drawHud(canvas: Canvas): void;
|
|
90
|
+
|
|
91
|
+
const chain = new EffectChain();
|
|
92
|
+
chain.add(createVignette('vig', { intensity: 0.6, radius: 0.8 }));
|
|
93
|
+
chain.add(createBloom('bloom', { threshold: 0.5, intensity: 0.9 }));
|
|
94
|
+
|
|
95
|
+
const surface = createPostFxSurface(kit, canvasEl, chain);
|
|
96
|
+
if (!surface) throw new Error('WebGL unavailable');
|
|
97
|
+
|
|
98
|
+
// Game loop:
|
|
99
|
+
surface.clear([0, 0, 0]);
|
|
100
|
+
// ...draw to surface.sceneCanvas()...
|
|
101
|
+
surface.composite(1); // runs the shader chain, presents the scene to onscreenCanvas()
|
|
102
|
+
|
|
103
|
+
// Draw crisp overlays AFTER composite() but BEFORE flush(). Null while the context is lost.
|
|
104
|
+
const overlay = surface.onscreenCanvas();
|
|
105
|
+
if (overlay) drawHud(overlay);
|
|
106
|
+
|
|
107
|
+
surface.flush(); // present the frame
|
|
108
|
+
|
|
109
|
+
// On resize:
|
|
110
|
+
surface.resize(newW, newH);
|
|
111
|
+
surface.clear([0, 0, 0]);
|
|
112
|
+
|
|
113
|
+
// Teardown:
|
|
114
|
+
surface.dispose();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Pass an empty `new EffectChain()` for a zero-overhead passthrough (no shader compilation).
|
|
118
|
+
|
|
119
|
+
### Context loss and restore
|
|
120
|
+
|
|
121
|
+
`sceneCanvas()` and `onscreenCanvas()` return `Canvas | null` — both are `null` while the WebGL context is lost. `PostFxSurface` self-heals: on `webglcontextlost` it marks itself lost and stops touching GPU objects (`clear`/`fadeTrail`/`composite`/`flush` become no-ops); on `webglcontextrestored` it rebuilds the context and surfaces on the same canvas and re-clears to the last background. Poll `isLost()` to drive a host-side fallback while recovery is pending:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import type { PostFxSurface } from '@flare-engine/render-web';
|
|
125
|
+
|
|
126
|
+
declare const surface: PostFxSurface;
|
|
127
|
+
declare function showStaticFallback(): void;
|
|
128
|
+
|
|
129
|
+
if (surface.isLost()) showStaticFallback();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Architecture notes
|
|
133
|
+
|
|
134
|
+
- `@flare-engine/postfx` is backend-neutral; `render-web` provides the CanvasKit shim (`SkiaPostFxModuleLike`) that routes `RuntimeEffect.Make` to CanvasKit.
|
|
135
|
+
- The ping-pong loop is allocation-free in the hot path: the children array and rect scratch buffer are pre-allocated at surface creation.
|
|
136
|
+
- `buildPass` is called every frame (no memoization) because `EffectChain` has no mutation signal; a future `buildPassInto` zero-alloc form in `@flare-engine/postfx` is the correct fix.
|
|
137
|
+
|
|
138
|
+
See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md) and [architecture](https://github.com/grzott/flare-engine/blob/main/docs/design/architecture.md) for the full rendering pipeline.
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
Apache-2.0
|
package/dist/index.d.mts
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CanvasLike, FrameRendererModule } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { EffectChain } from "@flare-engine/postfx";
|
|
2
|
+
import { CanvasLike, FrameRenderer, FrameRendererModule } from "@flare-engine/render";
|
|
3
|
+
import { Canvas, CanvasKit } from "canvaskit-wasm";
|
|
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","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"}
|