@rive-app/canvas-single 2.41.1 → 2.42.1

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.
@@ -42,18 +42,42 @@ export interface RiveCanvas {
42
42
  // Returns a pointer value to the FontWrapper
43
43
  setFallbackFontCallback: (callback: (missingGlyph: number, fallbackFontIndex: number, weight: number) => number | null) => void;
44
44
 
45
+ /**
46
+ * @experimental Creates a deferred recording session. Only present in builds
47
+ * with deferred rendering compiled in, so always feature-detect it.
48
+ *
49
+ * The session is a Factory: pass it to `load()` and to the decode APIs of the
50
+ * assets that belong to that file, and attach it to exactly one renderer with
51
+ * `attachSession()`.
52
+ *
53
+ * Teardown order should be:
54
+ * 1. release the file the session imported,
55
+ * 2. `detachSession()` on the renderer it is attached to,
56
+ * 3. `delete()` the session.
57
+ * Deleting an attached session leaves the renderer pointing at freed memory
58
+ * on the canvas2d build — the next frame either draws from freed heap or
59
+ * throws `Cannot pass deleted object`. Detach first, always, even when the
60
+ * renderer is about to be deleted too.
61
+ *
62
+ * @returns A DeferredSession, or undefined if the session could not be created
63
+ */
64
+ makeDeferredSession?(): DeferredSession | undefined;
65
+
45
66
  /**
46
67
  * Loads a Rive file for the runtime and returns a Rive-specific File class
47
68
  *
48
69
  * @param buffer - Array buffer of a Rive file
49
70
  * @param assetLoader - FileAssetLoader used to optionally customize loading of font and image assets
50
71
  * @param enableRiveAssetCDN - boolean flag to allow loading assets from the Rive CDN, enabled by default.
72
+ * @param session - @experimental Deferred session to import through. The file's mode is fixed
73
+ * at import: pass null (the default) for an immediate file.
51
74
  * @returns A Promise for a Rive File class
52
75
  */
53
76
  load(
54
77
  buffer: Uint8Array,
55
78
  assetLoader?: FileAssetLoader,
56
79
  enableRiveAssetCDN?: boolean,
80
+ session?: DeferredSession | null,
57
81
  ): Promise<File>;
58
82
 
59
83
  /**
@@ -141,6 +165,24 @@ export interface RiveCanvas {
141
165
  // RENDERER //
142
166
  //////////////
143
167
 
168
+ /**
169
+ * @experimental A deferred recording session, owned by the RiveFile that imported
170
+ * through it.
171
+ *
172
+ * A session records for one ore/GL context, so it binds to exactly one renderer
173
+ * and can never rebind once detached. It must outlive the file it imported.
174
+ */
175
+ export declare class DeferredSession {
176
+ delete(): void;
177
+ /**
178
+ * @experimental Whether anything was recorded into this session's stream this
179
+ * frame, including ore content the artboard's own change flag cannot see.
180
+ * Only meaningful before the renderer clears: clear opens a recording window
181
+ * that marks the stream, so a later read reports every frame as recorded.
182
+ */
183
+ recordedThisFrame(): boolean;
184
+ }
185
+
144
186
  /**
145
187
  * Rive wrapper around a rendering context for a canvas element, implementing a subset of the APIs
146
188
  * from the rendering context interface
@@ -187,6 +229,25 @@ export declare class RendererWrapper {
187
229
  * performing any WASM teardown that frees resources
188
230
  */
189
231
  bindContext?(): void;
232
+ /**
233
+ * @experimental Binds a deferred session to this renderer's context: draws record
234
+ * into the session and replay at flush. Absent on renderers that cannot replay a
235
+ * session (an offscreen renderer, or a build without deferred support).
236
+ *
237
+ * @param session - The session the file was imported through
238
+ * @returns false if this renderer already has a session, or the session is (or was)
239
+ * bound elsewhere. Attaching is once per session: re-import into a fresh session instead
240
+ */
241
+ attachSession?(session: DeferredSession): boolean;
242
+ /**
243
+ * @experimental Releases the attached session's replay state. The session can never
244
+ * be attached again.
245
+ */
246
+ detachSession?(): void;
247
+ /**
248
+ * @experimental Whether a deferred session is currently attached.
249
+ */
250
+ deferredActive?(): boolean;
190
251
  }
191
252
 
192
253
  export declare class RenderPathWrapper {
@@ -319,8 +380,16 @@ export class Audio {
319
380
  export interface AudioCallback {
320
381
  (audio: Audio): void;
321
382
  }
383
+ /**
384
+ * The trailing session is the one of the deferred file the asset is bound into;
385
+ * an asset decoded against any other factory is dropped when that file draws.
386
+ */
322
387
  export interface DecodeAudio {
323
- (bytes: Uint8Array, callback: AudioCallback): void;
388
+ (
389
+ bytes: Uint8Array,
390
+ callback: AudioCallback,
391
+ session?: DeferredSession | null,
392
+ ): void;
324
393
  }
325
394
  export class ImageInternal {
326
395
  unref(): void;
@@ -333,7 +402,11 @@ export interface ImageCallback {
333
402
  (image: Image): void;
334
403
  }
335
404
  export interface DecodeImage {
336
- (bytes: Uint8Array, callback: ImageCallback): void;
405
+ (
406
+ bytes: Uint8Array,
407
+ callback: ImageCallback,
408
+ session?: DeferredSession | null,
409
+ ): void;
337
410
  }
338
411
  export class FontInternal {
339
412
  unref(): void;
@@ -348,7 +421,11 @@ export interface FontCallback {
348
421
  (font: Font): void;
349
422
  }
350
423
  export interface DecodeFont {
351
- (bytes: Uint8Array, callback: FontCallback): void;
424
+ (
425
+ bytes: Uint8Array,
426
+ callback: FontCallback,
427
+ session?: DeferredSession | null,
428
+ ): void;
352
429
  }
353
430
 
354
431
  //////////
@@ -1386,7 +1463,12 @@ export declare class FileAsset {
1386
1463
  isFont: boolean;
1387
1464
  cdnUuid: string;
1388
1465
 
1389
- decode(bytes: Uint8Array): void;
1466
+ /**
1467
+ * @param session - @experimental The session of the deferred file this asset belongs
1468
+ * to, null for an immediate file. Wired by the runtime; pass it explicitly only when
1469
+ * calling the native asset directly.
1470
+ */
1471
+ decode(bytes: Uint8Array, session?: DeferredSession | null): void;
1390
1472
  get nativeAsset(): FileAssetInternal;
1391
1473
  }
1392
1474
 
@@ -1403,7 +1485,7 @@ export declare class FileAssetInternal {
1403
1485
  isFont: boolean;
1404
1486
  cdnUuid: string;
1405
1487
 
1406
- decode(bytes: Uint8Array): void;
1488
+ decode(bytes: Uint8Array, session?: DeferredSession | null): void;
1407
1489
  }
1408
1490
 
1409
1491
  export declare class AudioAssetInternal extends FileAssetInternal {
@@ -4,9 +4,11 @@ interface Finalizable {
4
4
  }
5
5
  declare class FileFinalizer implements Finalizable {
6
6
  private _file;
7
+ private _session;
7
8
  selfUnref: boolean;
8
- constructor(file: rc.File);
9
+ constructor(file: rc.File, session?: rc.DeferredSession | null);
9
10
  unref(): void;
11
+ release(): void;
10
12
  }
11
13
  declare class AssetWrapper implements rc.FinalizableTarget {
12
14
  selfUnref: boolean;
@@ -34,7 +36,8 @@ export type AssetLoadCallbackWrapper = (asset: rc.FileAssetInternal, bytes: Uint
34
36
  declare class CustomFileAssetLoaderWrapper {
35
37
  assetLoader: rc.CustomFileAssetLoader;
36
38
  _assetLoaderCallback: AssetLoadCallbackWrapper;
37
- constructor(runtime: rc.RiveCanvas, loaderCallback: AssetLoadCallbackWrapper);
39
+ _session: rc.DeferredSession | null;
40
+ constructor(runtime: rc.RiveCanvas, loaderCallback: AssetLoadCallbackWrapper, session?: rc.DeferredSession | null);
38
41
  loadContents(asset: rc.FileAsset, bytes: any): false | Boolean;
39
42
  }
40
43
  /**
@@ -43,7 +46,8 @@ declare class CustomFileAssetLoaderWrapper {
43
46
  */
44
47
  declare class FileAssetWrapper {
45
48
  _nativeFileAsset: rc.FileAssetInternal;
46
- constructor(nativeAsset: rc.FileAssetInternal);
49
+ _session: rc.DeferredSession | null;
50
+ constructor(nativeAsset: rc.FileAssetInternal, session?: rc.DeferredSession | null);
47
51
  decode(bytes: Uint8Array): void;
48
52
  get name(): string;
49
53
  get fileExtension(): string;