@rive-app/canvas-single 2.41.0 → 2.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.
@@ -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
@@ -164,12 +206,19 @@ export declare class RendererWrapper {
164
206
  drawPath(path: RenderPath, paint: RenderPaint): void;
165
207
  clipPath(path: RenderPath): void;
166
208
  /**
167
- * Calls the context's clearRect() function to clear the entire canvas. Crucial to call
168
- * this at the start of the render loop to clear the canvas before drawing the next frame
209
+ * Begins a frame. Crucial to call this at the start of the render loop: besides clearing
210
+ * the canvas, it registers the renderer so that its queued draws actually get flushed.
169
211
  *
170
- * For the underlying API, check
212
+ * Pass clear=false to draw on top of whatever the canvas already holds instead of
213
+ * starting from a blank one.
214
+ *
215
+ * For the underlying clear, check
171
216
  * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clearRect
172
217
  */
218
+ beginFrame(clear?: boolean): void;
219
+ /**
220
+ * @deprecated Use {@link beginFrame} instead. Equivalent to `beginFrame(true)`.
221
+ */
173
222
  clear(): void;
174
223
  delete(): void;
175
224
  flush(): void;
@@ -180,11 +229,38 @@ export declare class RendererWrapper {
180
229
  * performing any WASM teardown that frees resources
181
230
  */
182
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;
183
251
  }
184
252
 
185
253
  export declare class RenderPathWrapper {
186
254
  reset(): void;
187
- addPath(path: CommandPath, transform: Mat2D): void;
255
+ addPath(
256
+ path: CommandPath,
257
+ xx: number,
258
+ xy: number,
259
+ yx: number,
260
+ yy: number,
261
+ tx: number,
262
+ ty: number,
263
+ ): void;
188
264
  fillRule(value: FillRule): void;
189
265
  moveTo(x: number, y: number): void;
190
266
  lineTo(x: number, y: number): void;
@@ -233,11 +309,11 @@ export declare class Renderer extends RendererWrapper {
233
309
  ): void;
234
310
  }
235
311
 
236
- export declare class CommandPath {}
312
+ export declare class CommandPath { }
237
313
 
238
- export declare class RenderPath extends RenderPathWrapper {}
314
+ export declare class RenderPath extends RenderPathWrapper { }
239
315
 
240
- export declare class RenderPaint extends RenderPaintWrapper {}
316
+ export declare class RenderPaint extends RenderPaintWrapper { }
241
317
 
242
318
  /////////////////////
243
319
  // CANVAS RENDERER //
@@ -287,7 +363,7 @@ export declare class CanvasRenderPaint extends RenderPaint {
287
363
  ): void;
288
364
  }
289
365
 
290
- export declare class CanvasRenderPath extends RenderPath {}
366
+ export declare class CanvasRenderPath extends RenderPath { }
291
367
 
292
368
  export interface CanvasRenderFactory {
293
369
  makeRenderPaint(): CanvasRenderPaint;
@@ -304,8 +380,16 @@ export class Audio {
304
380
  export interface AudioCallback {
305
381
  (audio: Audio): void;
306
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
+ */
307
387
  export interface DecodeAudio {
308
- (bytes: Uint8Array, callback: AudioCallback): void;
388
+ (
389
+ bytes: Uint8Array,
390
+ callback: AudioCallback,
391
+ session?: DeferredSession | null,
392
+ ): void;
309
393
  }
310
394
  export class ImageInternal {
311
395
  unref(): void;
@@ -318,7 +402,11 @@ export interface ImageCallback {
318
402
  (image: Image): void;
319
403
  }
320
404
  export interface DecodeImage {
321
- (bytes: Uint8Array, callback: ImageCallback): void;
405
+ (
406
+ bytes: Uint8Array,
407
+ callback: ImageCallback,
408
+ session?: DeferredSession | null,
409
+ ): void;
322
410
  }
323
411
  export class FontInternal {
324
412
  unref(): void;
@@ -333,7 +421,11 @@ export interface FontCallback {
333
421
  (font: Font): void;
334
422
  }
335
423
  export interface DecodeFont {
336
- (bytes: Uint8Array, callback: FontCallback): void;
424
+ (
425
+ bytes: Uint8Array,
426
+ callback: FontCallback,
427
+ session?: DeferredSession | null,
428
+ ): void;
337
429
  }
338
430
 
339
431
  //////////
@@ -1202,11 +1294,11 @@ export declare class DataEnum {
1202
1294
  get values(): string[];
1203
1295
  }
1204
1296
 
1205
- export declare class SMIBool {}
1297
+ export declare class SMIBool { }
1206
1298
 
1207
- export declare class SMINumber {}
1299
+ export declare class SMINumber { }
1208
1300
 
1209
- export declare class SMITrigger {}
1301
+ export declare class SMITrigger { }
1210
1302
 
1211
1303
  ///////////
1212
1304
  // ENUMS //
@@ -1371,7 +1463,12 @@ export declare class FileAsset {
1371
1463
  isFont: boolean;
1372
1464
  cdnUuid: string;
1373
1465
 
1374
- 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;
1375
1472
  get nativeAsset(): FileAssetInternal;
1376
1473
  }
1377
1474
 
@@ -1388,7 +1485,7 @@ export declare class FileAssetInternal {
1388
1485
  isFont: boolean;
1389
1486
  cdnUuid: string;
1390
1487
 
1391
- decode(bytes: Uint8Array): void;
1488
+ decode(bytes: Uint8Array, session?: DeferredSession | null): void;
1392
1489
  }
1393
1490
 
1394
1491
  export declare class AudioAssetInternal extends FileAssetInternal {
@@ -1428,7 +1525,7 @@ export declare class FontAsset extends FileAsset {
1428
1525
  setFont(font: Font | FontWrapper): void;
1429
1526
  }
1430
1527
 
1431
- export declare class FileAssetLoader {}
1528
+ export declare class FileAssetLoader { }
1432
1529
 
1433
1530
  export declare class CustomFileAssetLoader extends FileAssetLoader {
1434
1531
  constructor({ loadContents }: { loadContents: Function });
@@ -1,5 +1,5 @@
1
1
  export { SemanticTreeModel } from "./semanticTreeModel";
2
2
  export { AccessibilityOverlay } from "./accessibilityOverlay";
3
3
  export type { AccessibilityOverlayOptions } from "./accessibilityOverlay";
4
- export { SemanticRole, SemanticState, SemanticTrait, SemanticActionType, SemanticMode, hasState, hasTrait, roleName, stateNames, traitNames, } from "./types";
4
+ export { SemanticRole, SemanticState, SemanticCheckState, SemanticTrait, SemanticActionType, SemanticMode, CHECK_STATE_OFFSET, CHECK_STATE_MASK, checkStateOf, hasState, hasTrait, roleName, stateNames, traitNames, } from "./types";
5
5
  export type { SemanticsDiffNode, SemanticsDiff, SemanticNodeData, RiveSemanticsOptions, } from "./types";
@@ -25,8 +25,6 @@ export declare const SemanticState: {
25
25
  readonly None: 0;
26
26
  readonly Expanded: number;
27
27
  readonly Selected: number;
28
- readonly Checked: number;
29
- readonly Mixed: number;
30
28
  readonly Toggled: number;
31
29
  readonly Required: number;
32
30
  readonly Disabled: number;
@@ -39,6 +37,21 @@ export declare const SemanticState: {
39
37
  readonly Multiline: number;
40
38
  };
41
39
  export declare function hasState(flags: number, state: number): boolean;
40
+ export declare const SemanticCheckState: {
41
+ readonly Unchecked: 0;
42
+ readonly Checked: 1;
43
+ readonly Mixed: 2;
44
+ };
45
+ export type SemanticCheckState = (typeof SemanticCheckState)[keyof typeof SemanticCheckState];
46
+ /** Bit offset of the check field within stateFlags. */
47
+ export declare const CHECK_STATE_OFFSET = 2;
48
+ /** Mask of the check field within stateFlags. */
49
+ export declare const CHECK_STATE_MASK: number;
50
+ /**
51
+ * Decodes the check field out of `flags`. The field is two bits. Returns 0, 1, or 2
52
+ * per the mapping in SemanticCheckState.
53
+ */
54
+ export declare function checkStateOf(flags: number): SemanticCheckState;
42
55
  /**
43
56
  * Controls when the instance builds semantic trees and accessibility overlays.
44
57
  *
@@ -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;