@rive-app/webgl2 2.11.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.
@@ -0,0 +1,920 @@
1
+ interface RiveOptions {
2
+ locateFile(file: string): string;
3
+ }
4
+
5
+ declare function Rive(options?: RiveOptions): Promise<RiveCanvas>;
6
+ export default Rive;
7
+
8
+ /**
9
+ * RiveCanvas is the main export object that contains references to different Rive classes to help
10
+ * build the Rive render loop for low-level API usage. In addition, this contains multiple methods
11
+ * that help aid in setup, such as loading in a Rive file, creating the renderer, and
12
+ * starting/finishing the render loop (requestAnimationFrame)
13
+ */
14
+ export interface RiveCanvas {
15
+ Alignment: AlignmentFactory;
16
+ CanvasRenderer: typeof CanvasRenderer;
17
+ LinearAnimationInstance: typeof LinearAnimationInstance;
18
+ StateMachineInstance: typeof StateMachineInstance;
19
+ CustomFileAssetLoader: typeof CustomFileAssetLoader;
20
+ Mat2D: typeof Mat2D;
21
+ Vec2D: typeof Vec2D;
22
+ AABB: AABB;
23
+ SMIInput: typeof SMIInput;
24
+ renderFactory: CanvasRenderFactory;
25
+
26
+ BlendMode: typeof BlendMode;
27
+ FillRule: typeof FillRule;
28
+ Fit: typeof Fit;
29
+ RenderPaintStyle: typeof RenderPaintStyle;
30
+ StrokeCap: typeof StrokeCap;
31
+ StrokeJoin: typeof StrokeJoin;
32
+ decodeImage: DecodeFont;
33
+ decodeFont: DecodeFont;
34
+
35
+ /**
36
+ * Loads a Rive file for the runtime and returns a Rive-specific File class
37
+ *
38
+ * @param buffer - Array buffer of a Rive file
39
+ * @param assetLoader - FileAssetLoader used to optionally customize loading of font and image assets
40
+ * @param enableRiveAssetCDN - boolean flag to allow loading assets from the Rive CDN, enabled by default.
41
+ * @returns A Promise for a Rive File class
42
+ */
43
+ load(
44
+ buffer: Uint8Array,
45
+ assetLoader?: FileAssetLoader,
46
+ enableRiveAssetCDN?: boolean,
47
+ ): Promise<File>;
48
+
49
+ /**
50
+ * Creates the renderer to draw the Rive on the provided canvas element
51
+ *
52
+ * @param canvas - Canvas to draw the Rive on
53
+ * @param useOffscreenRenderer - Option for those using the WebGL-variant of the Rive JS library.
54
+ * This uses an offscreen renderer to draw on the canvas, allowing for multiple Rives/canvases on
55
+ * a given screen. It is highly recommended to set this to `true` when using with the
56
+ * `@rive-app/webgl` package
57
+ * @returns A Rive CanvasRenderer (Canvas2D) or Renderer (WebGL) class
58
+ */
59
+ makeRenderer(
60
+ canvas: HTMLCanvasElement | OffscreenCanvas,
61
+ useOffscreenRenderer?: boolean,
62
+ ): WrappedRenderer;
63
+
64
+ /**
65
+ * Computes how the Rive is laid out onto the canvas
66
+ * @param {Fit} fit - Fit enum (i.e Fit.contain)
67
+ * @param alignment - Alignment enum (i.e Alignment.center)
68
+ * @param frame - AABB object representing the bounds of the canvas frame
69
+ * @param content - AABB object representing the bounds of what to draw the Rive onto
70
+ * (i.e an artboard's size)
71
+ * @returns Mat2D - A Mat2D view matrix
72
+ */
73
+ computeAlignment(
74
+ fit: Fit,
75
+ alignment: Alignment,
76
+ frame: AABB,
77
+ content: AABB,
78
+ ): Mat2D;
79
+ mapXY(matrix: Mat2D, canvasPoints: Vec2D): Vec2D;
80
+ /**
81
+ * A Rive-specific requestAnimationFrame function; this must be used instead of the global
82
+ * requestAnimationFrame function.
83
+ * @param cb - Callback function to call with an elapsed timestamp
84
+ * @returns number - An ID of the requestAnimationFrame request
85
+ */
86
+ requestAnimationFrame(cb: (timestamp: DOMHighResTimeStamp) => void): number;
87
+ /**
88
+ * A Rive-specific cancelAnimationFrame function; this must be used instead of the global
89
+ * cancelAnimationFrame function.
90
+ * @param requestID - ID of the requestAnimationFrame request to cancel
91
+ */
92
+ cancelAnimationFrame(requestID: number): void;
93
+ /**
94
+ * A Rive-specific function to "flush" queued up draw calls from using the renderer.
95
+ *
96
+ * This should only be invoked once at the end of a loop in a regular JS
97
+ * requestAnimationFrame loop, and should not be used with the Rive-wrapped
98
+ * requestAnimationFrame (aka, the requestAnimationFrame() API on this object) as that
99
+ * API will handle flushing the draw calls implicitly.
100
+ */
101
+ resolveAnimationFrame(): void;
102
+ /**
103
+ * Debugging tool to showcase the FPS in the corner of the screen in a new div. If a callback
104
+ * function is provided, this function passes the FPS count to the callback instead of creating a
105
+ * new div so the client can decide what to do with that data.
106
+ */
107
+ enableFPSCounter(cb?: (fps: number) => void): void;
108
+ /**
109
+ * Debugging tool to remove the FPS counter that displays from enableFPSCounter
110
+ */
111
+ disableFPSCounter(): void;
112
+
113
+ /**
114
+ * Cleans up any WASM-generate objects that need to be destroyed manually.
115
+ * This should be called when you wish to remove a rive animation from view.
116
+ */
117
+ cleanup(): void;
118
+
119
+ /**
120
+ * Returns whether or not there are Rive Listeners configured on a given StateMachineInstance
121
+ * @param stateMachine - StateMachineInstance to check for Listeners
122
+ * @returns bool - Boolean of if there are Listners on the state machine
123
+ */
124
+ hasListeners(stateMachine: StateMachineInstance): boolean;
125
+ }
126
+
127
+ //////////////
128
+ // RENDERER //
129
+ //////////////
130
+
131
+ /**
132
+ * Rive wrapper around a rendering context for a canvas element, implementing a subset of the APIs
133
+ * from the rendering context interface
134
+ */
135
+ export declare class RendererWrapper {
136
+ /**
137
+ * Saves the state of the canvas and pushes it onto a stack
138
+ *
139
+ * For the underlying API, check
140
+ * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
141
+ */
142
+ save(): void;
143
+ /**
144
+ * Restores the most recent state of the canvas saved on the stack
145
+ *
146
+ * For the underlying API, check
147
+ * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
148
+ */
149
+ restore(): void;
150
+ transform(tranform: Mat2D): void;
151
+ drawPath(path: RenderPath, paint: RenderPaint): void;
152
+ clipPath(path: RenderPath): void;
153
+ /**
154
+ * Calls the context's clearRect() function to clear the entire canvas. Crucial to call
155
+ * this at the start of the render loop to clear the canvas before drawing the next frame
156
+ *
157
+ * For the underlying API, check
158
+ * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clearRect
159
+ */
160
+ clear(): void;
161
+ delete(): void;
162
+ flush(): void;
163
+ translate(x: number, y: number): void;
164
+ rotate(angle: number): void;
165
+ }
166
+
167
+ export declare class RenderPathWrapper {
168
+ reset(): void;
169
+ addPath(path: CommandPath, transform: Mat2D): void;
170
+ fillRule(value: FillRule): void;
171
+ moveTo(x: number, y: number): void;
172
+ lineTo(x: number, y: number): void;
173
+ cubicTo(
174
+ ox: number,
175
+ oy: number,
176
+ ix: number,
177
+ iy: number,
178
+ x: number,
179
+ y: number,
180
+ ): void;
181
+ close(): void;
182
+ }
183
+
184
+ export declare class RenderPaintWrapper {
185
+ color(value: number): void;
186
+ thickness(value: number): void;
187
+ join(value: StrokeJoin): void;
188
+ cap(value: StrokeCap): void;
189
+ blendMode(value: BlendMode): void;
190
+ style(value: RenderPaintStyle): void;
191
+ linearGradient(sx: number, sy: number, ex: number, ey: number): void;
192
+ radialGradient(sx: number, sy: number, ex: number, ey: number): void;
193
+ addStop(color: number, stop: number): void;
194
+ completeGradient(): void;
195
+ }
196
+
197
+ /**
198
+ * Renderer returned when Rive makes a renderer via `makeRenderer()`
199
+ */
200
+ export declare class Renderer extends RendererWrapper {
201
+ /**
202
+ * Aligns the Rive content on the canvas space
203
+ * @param fit - Fit enum value
204
+ * @param alignment - Alignment enum value
205
+ * @param frame - Bounds of the canvas space
206
+ * @param content - Bounds of the Rive content
207
+ */
208
+ align(fit: Fit, alignment: Alignment, frame: AABB, content: AABB): void;
209
+ }
210
+
211
+ export declare class CommandPath {}
212
+
213
+ export declare class RenderPath extends RenderPathWrapper {}
214
+
215
+ export declare class RenderPaint extends RenderPaintWrapper {}
216
+
217
+ /////////////////////
218
+ // CANVAS RENDERER //
219
+ /////////////////////
220
+ export declare class CanvasRenderer extends Renderer {
221
+ constructor(
222
+ ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,
223
+ );
224
+ }
225
+
226
+ type OmittedCanvasRenderingContext2DMethods =
227
+ | "createConicGradient"
228
+ | "createImageData"
229
+ | "createLinearGradient"
230
+ | "createPattern"
231
+ | "createRadialGradient"
232
+ | "getContextAttributes"
233
+ | "getImageData"
234
+ | "getLineDash"
235
+ | "getTransform"
236
+ | "isContextLost"
237
+ | "isPointInPath"
238
+ | "isPointInStroke"
239
+ | "measureText";
240
+
241
+ /**
242
+ * Proxy class that handles calls to a CanvasRenderer instance and handles Rive-related rendering calls such
243
+ * as `save`, `restore`, `transform`, and more, effectively overriding and/or wrapping Canvas2D context
244
+ * APIs for Rive-specific purposes. Other calls not intentionally overridden are passed through to the
245
+ * Canvas2D context directly.
246
+ *
247
+ * Note: Currently, any calls to the Canvas2D context that you expect to return a value (i.e. `isPointInStroke()`)
248
+ * will return undefined
249
+ */
250
+ export type CanvasRendererProxy = CanvasRenderer &
251
+ Omit<CanvasRenderingContext2D, OmittedCanvasRenderingContext2DMethods>;
252
+
253
+ /**
254
+ * Renderer type for `makeRenderer()` that returns Renderer (webgl) or a CanvasRendererProxy (canvas2d)
255
+ */
256
+ export type WrappedRenderer = Renderer | CanvasRendererProxy;
257
+
258
+ export declare class CanvasRenderPaint extends RenderPaint {
259
+ draw(
260
+ ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,
261
+ path: RenderPath,
262
+ ): void;
263
+ }
264
+
265
+ export declare class CanvasRenderPath extends RenderPath {}
266
+
267
+ export interface CanvasRenderFactory {
268
+ makeRenderPaint(): CanvasRenderPaint;
269
+ makeRenderPath(): CanvasRenderPath;
270
+ }
271
+
272
+ export class Image {
273
+ unref(): void;
274
+ }
275
+ export interface ImageCallback {
276
+ (image: Image): void;
277
+ }
278
+ export interface DecodeImage {
279
+ (bytes: Uint8Array, callback: ImageCallback): void;
280
+ }
281
+ export class Font {
282
+ unref(): void;
283
+ }
284
+ export interface FontCallback {
285
+ (font: Font): void;
286
+ }
287
+ export interface DecodeFont {
288
+ (bytes: Uint8Array, callback: FontCallback): void;
289
+ }
290
+
291
+ //////////
292
+ // File //
293
+ //////////
294
+ /**
295
+ * Rive-specific File class that provides a number of functions to load instances of Artboards
296
+ */
297
+ export declare class File {
298
+ /**
299
+ * Returns the first Artboard found in the Rive file as a new Artboard instance
300
+ * @returns An Artboard instance
301
+ */
302
+ defaultArtboard(): Artboard; // rive::ArtboardInstance
303
+ /**
304
+ * Returns the named Artboard found in the Rive file as a new Artboard instance
305
+ * @param name - Name of the Artboard to create an instance for
306
+ */
307
+ artboardByName(name: string): Artboard; // rive::ArtboardInstance
308
+ /**
309
+ * Returns a new Artboard instance for the Artboard at the given index in the Rive file
310
+ * @param index - Index of the Artboard in the file to create an Artboard instance for
311
+ */
312
+ artboardByIndex(index: number): Artboard; // rive::ArtboardInstance
313
+ /**
314
+ * Returns the number of Artboards in the Rive File
315
+ * @returns Number of artboards in the Rive file
316
+ */
317
+ artboardCount(): number;
318
+
319
+ delete(): void;
320
+ }
321
+
322
+ /**
323
+ * Rive class representing an Artboard instance. Use this class to create instances for
324
+ * LinearAnimations, StateMachines, Nodes, Bones, and more. This Artboard instance should also be
325
+ * advanced in the drawing render loop.
326
+ *
327
+ * Important: Make sure to delete this instance when it's no longer in use via the `delete()`
328
+ * method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
329
+ * be done in cases where the user navigates away from the page with this animation, the canvas is
330
+ * unmounted, etc.
331
+ */
332
+ export declare class Artboard {
333
+ /**
334
+ * Get the name of this Artboard instance
335
+ */
336
+ get name(): string;
337
+ /**
338
+ * Get the bounds of this Artboard instance
339
+ */
340
+ get bounds(): AABB;
341
+ get frameOrigin(): boolean;
342
+ set frameOrigin(val: boolean);
343
+ /**
344
+ * Deletes the underlying instance created via the WASM. It's important to clean up this
345
+ * instance when no longer in use
346
+ */
347
+ delete(): void;
348
+ /**
349
+ * Advances the Artboard instance by the set amount of seconds. This method updates each object
350
+ * in the Artboard with any changes that animations apply on properties of the objects. This
351
+ * should be called after calling `advance()` of a LinearAnimationInstance or StateMachineInstance
352
+ * @param sec - Scrub the Artboard instance by a number of seconds
353
+ */
354
+ advance(sec: number): boolean;
355
+ /**
356
+ * Draws the artboard with a given rendering context.
357
+ * @param renderer - Renderer context to draw with
358
+ */
359
+ draw(renderer: CanvasRenderer | Renderer): void;
360
+ /**
361
+ * Creates a LinearAnimation for the animation with the given name
362
+ *
363
+ * Note: This does not create a LinearAnimationInstance to advance in the render loop.
364
+ * That needs to be created separately.
365
+ *
366
+ * @param name - Name of the animation to create a LinearAnimation reference for
367
+ * @returns A new LinearAnimation object
368
+ */
369
+ animationByName(name: string): LinearAnimation;
370
+ /**
371
+ * Creates a LinearAnimation for the animation with the given index
372
+ *
373
+ * Note: This does not create a LinearAnimationInstance to advance in the render loop.
374
+ * That needs to be created separately.
375
+ *
376
+ * @param index - Index of the animation to create a LinearAnimation reference for
377
+ * @returns A new LinearAnimation object
378
+ */
379
+ animationByIndex(index: number): LinearAnimation;
380
+ /**
381
+ * Returns the number of animations in the artboard
382
+ * @returns Number of animations on the Artboard
383
+ */
384
+ animationCount(): number;
385
+ /**
386
+ * Creates a StateMachine for the state machine with the given name.
387
+ *
388
+ * Note: This does not create a StateMachineInstance to advance in the render loop.
389
+ * That needs to be created separately.
390
+ *
391
+ * @param name - Name of the state machine to create a StateMachine reference for
392
+ * @returns A new StateMachine object
393
+ */
394
+ stateMachineByName(name: string): StateMachine;
395
+ /**
396
+ * Creates a StateMachine for the state machine with the given index
397
+ *
398
+ * Note: This does not create a StateMachineInstance to advance in the render loop.
399
+ * That needs to be created separately.
400
+ *
401
+ * @param index - Index of the state machine to create a StateMachine reference for
402
+ * @returns A new StateMachine object
403
+ */
404
+ stateMachineByIndex(index: number): StateMachine;
405
+ /**
406
+ * Returns the number of state machines in the artboard
407
+ * @returns Number of state machines on the Artboard
408
+ */
409
+ stateMachineCount(): number;
410
+ /**
411
+ * Returns a reference for a Bone object of a given name.
412
+ * Learn more: https://help.rive.app/editor/manipulating-shapes/bones
413
+ *
414
+ * @param name - Name of the Bone to grab a reference to
415
+ */
416
+ bone(name: string): Bone;
417
+ /**
418
+ * Returns a reference for a Node object of a given name from the Artboard hierarchy
419
+ * @param name - Name of the Node from the Artboard hierarchy to grab a reference to
420
+ */
421
+ node(name: string): Node;
422
+ /**
423
+ * Returns a reference for a root Bone object of a given name
424
+ * @param name - Name of the root Bone to grab a reference to
425
+ */
426
+ rootBone(name: string): RootBone;
427
+ /**
428
+ * Returns a reference for a transform component object of a given name
429
+ * @param name - Name of the transform component to grab a reference to
430
+ */
431
+ transformComponent(name: string): TransformComponent;
432
+ /**
433
+ * Returns a reference for a TextValueRun object to get/set a text value for
434
+ * @param name - Name of the Text Run to grab a reference to
435
+ */
436
+ textRun(name: string): TextValueRun;
437
+ }
438
+
439
+ export declare class Bone extends TransformComponent {
440
+ /**
441
+ * Length of the bone
442
+ */
443
+ length: number;
444
+ }
445
+
446
+ export declare class RootBone extends Bone {
447
+ /**
448
+ * X coordinate of the position on the RootBone
449
+ */
450
+ x: number;
451
+ /**
452
+ * Y coordinate of the position on the RootBone
453
+ */
454
+ y: number;
455
+ }
456
+
457
+ /**
458
+ * Representation of a node in the Artboard hierarchy (i.e group, shape, etc.)
459
+ */
460
+ export declare class Node extends TransformComponent {
461
+ /**
462
+ * X coordinate of the position on the Node
463
+ */
464
+ x: number;
465
+ /**
466
+ * Y coordinate of the position on the RootBone
467
+ */
468
+ y: number;
469
+ }
470
+
471
+ export declare class TransformComponent {
472
+ rotation: number;
473
+ scaleX: number;
474
+ scaleY: number;
475
+ worldTransform(): Mat2D;
476
+ parentWorldTransform(result: Mat2D): void;
477
+ }
478
+
479
+ ///////////////
480
+ // Animation //
481
+ ///////////////
482
+ /**
483
+ * Rive class representing a LinearAnimation instance. Use this class to advance and control a
484
+ * particular animation in the render loop (i.e speed, scrub, mix, etc.).
485
+ *
486
+ * Important: Make sure to delete this instance when it's no longer in use via the `delete()`
487
+ * method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
488
+ * be done in cases where the user navigates away from the page with this animation, the canvas is
489
+ * unmounted, etc.
490
+ */
491
+ export declare class LinearAnimationInstance {
492
+ /**
493
+ * Create a new LinearAnimationInstance reference
494
+ * @param animation - A LinearAnimation reference retrieved via the Artboard
495
+ * (i.e `artboard.animationByName('foo')`)
496
+ * @param artboard - The Artboard instance for this animation
497
+ */
498
+ constructor(animation: LinearAnimation, artboard: Artboard);
499
+ get name(): string;
500
+ get duration(): number;
501
+ get fps(): number;
502
+ get workStart(): number;
503
+ get workEnd(): number;
504
+ get loopValue(): number;
505
+ get speed(): number;
506
+ /**
507
+ * Number of seconds the animation has advanced by
508
+ */
509
+ time: number;
510
+ /**
511
+ * Flag to determine if the animation looped (this is reset when the loop restarts)
512
+ */
513
+ didLoop: boolean;
514
+ /**
515
+ * Advances/scrubs the LinearAnimationInstance by the set amount of seconds. Note that this only
516
+ * moves the "time" in the animation, but does not apply changes to the properties in the
517
+ * Artboard. This must be called before the `apply()` method of LinearAnimationInstance.
518
+ *
519
+ * @param sec - Scrub the animation instance by a number of seconds
520
+ */
521
+ advance(sec: number): boolean;
522
+ /**
523
+ * Apply a mixing value on the animation instance. This is useful if you are looking to blend
524
+ * multiple animations together and want to dictate a strength for each of the animations played
525
+ * back. This also applies new values to properties of objects on the Artboard according to the
526
+ * keys of the animation.
527
+ * This must be called after the `advance()` method of `LinearAnimationInstance`
528
+ *
529
+ * @param mix 0-1 the strength of the animation in the animations mix.
530
+ */
531
+ apply(mix: number): void;
532
+ /**
533
+ * Deletes the underlying instance created via the WASM. It's important to clean up this instance
534
+ * when no longer in use
535
+ */
536
+ delete(): void;
537
+ }
538
+
539
+ export declare class TextValueRun {
540
+ /**
541
+ * Getter for the name of the Text Run
542
+ */
543
+ get name(): string;
544
+ /**
545
+ * Getter for text value of the Text Run
546
+ */
547
+ get text(): string;
548
+ /**
549
+ * Setter for the text value of the Text Run
550
+ */
551
+ set text(val: string);
552
+ }
553
+
554
+ /**
555
+ * Rive Event interface for "General" custom events defined in the Rive editor. Each event has a
556
+ * name and optionally some other custom properties and a type
557
+ */
558
+ export interface RiveEvent {
559
+ /**
560
+ * Name of the event fired
561
+ */
562
+ name: string;
563
+ /**
564
+ * Optional type of the specific kind of event fired (i.e. General, OpenUrl)
565
+ */
566
+ type?: number;
567
+ /**
568
+ * Optional custom properties defined on the event
569
+ */
570
+ properties?: RiveEventCustomProperties;
571
+ /**
572
+ * Optional elapsed time since the event specifically occurred
573
+ */
574
+ delay?: number;
575
+ }
576
+
577
+ /**
578
+ * A specific Rive Event type for "OpenUrl" events. This event type has a URL and optionally a
579
+ * target property to dictate how to open the URL
580
+ */
581
+ export interface OpenUrlEvent extends RiveEvent {
582
+ /**
583
+ * URL to open when the event is invoked
584
+ */
585
+ url: string;
586
+ /**
587
+ * Where to display the linked URL
588
+ */
589
+ target?: string;
590
+ }
591
+
592
+ /**
593
+ * A Rive Event may have any number of optional custom properties defined on itself with variable names
594
+ * and values that are either a number, boolean, or string
595
+ */
596
+ export interface RiveEventCustomProperties {
597
+ /**
598
+ * Custom property may be named anything in the Rive editor, and given a value of
599
+ * a number, boolean, or string type
600
+ */
601
+ [key: string]: number | boolean | string;
602
+ }
603
+
604
+ export declare class LinearAnimation {
605
+ /**
606
+ * The animation's loop type
607
+ */
608
+ get loopValue(): number;
609
+ /**
610
+ * Name of the LinearAnimation
611
+ */
612
+ get name(): string;
613
+ }
614
+
615
+ export declare class StateMachine {
616
+ /**
617
+ * Name of the StateMachine
618
+ */
619
+ get name(): string;
620
+ }
621
+
622
+ /**
623
+ * Rive class representing a StateMachine instance. Use this class to advance and control a
624
+ * particular state machine in the render loop (i.e scrub, grab state machine inputs, set up
625
+ * listener events, etc.).
626
+ *
627
+ * Important: Make sure to delete this instance when it's no longer in use via the `delete()`
628
+ * method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
629
+ * be done in cases where the user navigates away from the page with this animation, the canvas is
630
+ * unmounted, etc.
631
+ */
632
+ export declare class StateMachineInstance {
633
+ /**
634
+ * Create a new StateMachineInstance reference
635
+ * @param stateMachine - A StateMachine retrieved via the Artboard
636
+ * (i.e `artboard.stateMachineByName('foo')`)
637
+ * @param artboard - The Artboard instance for this state machine
638
+ */
639
+ constructor(stateMachine: StateMachine, artboard: Artboard);
640
+ get name(): string;
641
+ /**
642
+ * Returns the number of inputs associated with this state machine
643
+ * @returns Number of inputs
644
+ */
645
+ inputCount(): number;
646
+ /**
647
+ * Returns the state machine input at the given index
648
+ * @param i - Index to retrieve the state machine input at
649
+ * @returns SMIInput reference
650
+ */
651
+ input(i: number): SMIInput;
652
+ /**
653
+ * Advances/scrubs the StateMachineInstance by the set amount of seconds. Note that this does not
654
+ * apply changes to the properties of objects in the Artboard yet.
655
+ * @param sec - Scrub the state machine instance by a number of seconds
656
+ */
657
+ advance(sec: number): boolean;
658
+ /**
659
+ * Returns the number of states changed while the state machine played
660
+ * @returns Number of states changed in the duration of the state machine played
661
+ */
662
+ stateChangedCount(): number;
663
+ /**
664
+ * Returns the name of the state/animation transitioned to, given the index in the array of state
665
+ * changes in total
666
+ * @param i
667
+ * @returns Name of the state/animation transitioned to
668
+ */
669
+ stateChangedNameByIndex(i: number): string;
670
+
671
+ /**
672
+ * Returns the number of events reported from the last advance call
673
+ * @returns Number of events reported
674
+ */
675
+ reportedEventCount(): number;
676
+
677
+ /**
678
+ * Returns a RiveEvent object emitted from the last advance call at the given index
679
+ * of a list of potentially multiple events. If an event at the index is not found,
680
+ * undefined is returned.
681
+ * @param i index of the event reported in a list of potentially multiple events
682
+ * @returns RiveEvent or extended RiveEvent object returned, or undefined
683
+ */
684
+ reportedEventAt(i: number): OpenUrlEvent | RiveEvent | undefined;
685
+
686
+ /**
687
+ * Notifies the state machine that the pointer has pressed down at the given coordinate in
688
+ * Artboard space. Internally, Rive may advance a state machine if the listener coordinate is of
689
+ * interest at a given moment.
690
+ *
691
+ * @param x - X coordinate
692
+ * @param y - Y coordinate
693
+ */
694
+ pointerDown(x: number, y: number): void;
695
+ /**
696
+ * Notifies the state machine that the pointer has moved to the given coordinate in
697
+ * Artboard space. Internally, Rive may advance a state machine if the listener coordinate is of
698
+ * interest at a given moment.
699
+ *
700
+ * @param x - X coordinate
701
+ * @param y - Y coordinate
702
+ */
703
+ pointerMove(x: number, y: number): void;
704
+ /**
705
+ * Notifies the state machine that the pointer has released at the given coordinate in
706
+ * Artboard space. Internally, Rive may advance a state machine if the listener coordinate is of
707
+ * interest at a given moment.
708
+ * @param x - X coordinate
709
+ * @param y - Y coordinate
710
+ */
711
+ pointerUp(x: number, y: number): void;
712
+
713
+ /**
714
+ * Deletes the underlying instance created via the WASM. It's important to clean up this instance
715
+ * when no longer in use
716
+ */
717
+ delete(): void;
718
+ }
719
+
720
+ export declare class SMIInput {
721
+ // TODO: Keep only the base SMIInput properties and make SMIBool, SMINumber, SMITriger extend it
722
+ static bool: number;
723
+ static number: number;
724
+ static trigger: number;
725
+
726
+ /**
727
+ * Getter for name of the state machine input
728
+ */
729
+ get name(): string;
730
+ get type(): number;
731
+ /**
732
+ * Getter for value of the state machine input
733
+ */
734
+ get value(): boolean | number | undefined;
735
+ /**
736
+ * Setter for value of the state machine input
737
+ */
738
+ set value(val: boolean | number | undefined);
739
+ /**
740
+ * Fires a trigger input on a state machine
741
+ */
742
+ fire(): void;
743
+ asBool(): SMIInput;
744
+ asNumber(): SMIInput;
745
+ asTrigger(): SMIInput;
746
+ }
747
+
748
+ export declare class SMIBool {}
749
+
750
+ export declare class SMINumber {}
751
+
752
+ export declare class SMITrigger {}
753
+
754
+ ///////////
755
+ // ENUMS //
756
+ ///////////
757
+
758
+ export enum Fit {
759
+ fill,
760
+ contain,
761
+ cover,
762
+ fitWidth,
763
+ fitHeight,
764
+ none,
765
+ scaleDown,
766
+ }
767
+
768
+ export enum RenderPaintStyle {
769
+ fill,
770
+ stroke,
771
+ }
772
+
773
+ export enum FillRule {
774
+ nonZero,
775
+ evenOdd,
776
+ }
777
+
778
+ export enum StrokeCap {
779
+ butt,
780
+ round,
781
+ square,
782
+ }
783
+ export enum StrokeJoin {
784
+ miter,
785
+ round,
786
+ bevel,
787
+ }
788
+
789
+ export enum BlendMode {
790
+ srcOver = 3,
791
+ screen = 14,
792
+ overlay = 15,
793
+ darken = 16,
794
+ lighten = 17,
795
+ colorDodge = 18,
796
+ colorBurn = 19,
797
+ hardLight = 20,
798
+ softLight = 21,
799
+ difference = 22,
800
+ exclusion = 23,
801
+ multiply = 24,
802
+ hue = 25,
803
+ saturation = 26,
804
+ color = 27,
805
+ luminosity = 28,
806
+ }
807
+
808
+ ///////////
809
+ // UTILS //
810
+ ///////////
811
+
812
+ export declare class Alignment {
813
+ get x(): number;
814
+ get y(): number;
815
+ }
816
+
817
+ export declare class AlignmentFactory {
818
+ get topLeft(): Alignment;
819
+ get topCenter(): Alignment;
820
+ get topRight(): Alignment;
821
+ get centerLeft(): Alignment;
822
+ get center(): Alignment;
823
+ get centerRight(): Alignment;
824
+ get bottomLeft(): Alignment;
825
+ get bottomCenter(): Alignment;
826
+ get bottomRight(): Alignment;
827
+ }
828
+
829
+ /**
830
+ * Axis-aligned bounding box
831
+ */
832
+ export interface AABB {
833
+ minX: number;
834
+ minY: number;
835
+ maxX: number;
836
+ maxY: number;
837
+ }
838
+
839
+ /**
840
+ * Column-major matrix described by the following:
841
+ * | xx yx tx |
842
+ * | xy yy ty |
843
+ * | 0 0 1 |
844
+ */
845
+ export declare class Mat2D {
846
+ xx: number;
847
+ xy: number;
848
+ yx: number;
849
+ yy: number;
850
+ tx: number;
851
+ ty: number;
852
+ /**
853
+ * Returns whether or not a matrix could be inverted, and if yes, sets the resulting Mat2D into
854
+ * the passed-in `mat` parameter
855
+ *
856
+ * @param mat - Reference Mat2D to store the newly inverted matrix into if successful
857
+ * @returns True if the matrix could be inverted
858
+ */
859
+ invert(mat: Mat2D): boolean;
860
+
861
+ /**
862
+ * Deletes the underlying CPP object created for this instance
863
+ */
864
+ delete(): void;
865
+ }
866
+
867
+ /**
868
+ * Rive Vector class
869
+ */
870
+ export declare class Vec2D {
871
+ constructor(x: number, y: number);
872
+ /**
873
+ * Returns the x coordinate of the vector
874
+ */
875
+ x(): number;
876
+ /**
877
+ * Returns the y coordinate of the vector
878
+ */
879
+ y(): number;
880
+
881
+ /**
882
+ * Deletes the underlying CPP object created for this instance
883
+ */
884
+ delete(): void;
885
+ }
886
+
887
+ /**
888
+ * Rive class representing a FileAsset with relevant metadata fields to describe
889
+ * an asset associated wtih the Rive File
890
+ */
891
+ export declare class FileAsset {
892
+ name: string;
893
+ fileExtension: string;
894
+ isImage: boolean;
895
+ isFont: boolean;
896
+ cdnUuid: string;
897
+ }
898
+
899
+ /**
900
+ * Rive class extending the FileAsset that exposes a `setRenderImage()` API with a
901
+ * decoded Image (via the `decodeImage()` API) to set a new Image on the Rive FileAsset
902
+ */
903
+ export declare class ImageAsset extends FileAsset {
904
+ setRenderImage(image: Image): void;
905
+ }
906
+
907
+ /**
908
+ * Rive class extending the FileAsset that exposes a `setFont()` API with a
909
+ * decoded Font (via the `decodeFont()` API) to set a new Font on the Rive FileAsset
910
+ */
911
+ export declare class FontAsset extends FileAsset {
912
+ setFont(font: Font): void;
913
+ }
914
+
915
+ export declare class FileAssetLoader {}
916
+
917
+ export declare class CustomFileAssetLoader extends FileAssetLoader {
918
+ constructor({ loadContents }: { loadContents: Function });
919
+ loadContents(asset: FileAsset, bytes: any): boolean;
920
+ }