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