@rive-app/webgl-advanced-single 2.8.3 → 2.9.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.
- package/package.json +3 -2
- package/rive_advanced.mjs.d.ts +911 -0
- package/webgl_advanced_single.mjs +1 -1
|
@@ -0,0 +1,911 @@
|
|
|
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
|
+
* 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
|
+
export class Image {
|
|
264
|
+
unref(): void;
|
|
265
|
+
}
|
|
266
|
+
export interface ImageCallback {
|
|
267
|
+
(image: Image): void;
|
|
268
|
+
}
|
|
269
|
+
export interface DecodeImage {
|
|
270
|
+
(bytes: Uint8Array, callback: ImageCallback): void;
|
|
271
|
+
}
|
|
272
|
+
export class Font {
|
|
273
|
+
unref(): void;
|
|
274
|
+
}
|
|
275
|
+
export interface FontCallback {
|
|
276
|
+
(font: Font): void;
|
|
277
|
+
}
|
|
278
|
+
export interface DecodeFont {
|
|
279
|
+
(bytes: Uint8Array, callback: FontCallback): void;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//////////
|
|
283
|
+
// File //
|
|
284
|
+
//////////
|
|
285
|
+
/**
|
|
286
|
+
* Rive-specific File class that provides a number of functions to load instances of Artboards
|
|
287
|
+
*/
|
|
288
|
+
export declare class File {
|
|
289
|
+
/**
|
|
290
|
+
* Returns the first Artboard found in the Rive file as a new Artboard instance
|
|
291
|
+
* @returns An Artboard instance
|
|
292
|
+
*/
|
|
293
|
+
defaultArtboard(): Artboard; // rive::ArtboardInstance
|
|
294
|
+
/**
|
|
295
|
+
* Returns the named Artboard found in the Rive file as a new Artboard instance
|
|
296
|
+
* @param name - Name of the Artboard to create an instance for
|
|
297
|
+
*/
|
|
298
|
+
artboardByName(name: string): Artboard; // rive::ArtboardInstance
|
|
299
|
+
/**
|
|
300
|
+
* Returns a new Artboard instance for the Artboard at the given index in the Rive file
|
|
301
|
+
* @param index - Index of the Artboard in the file to create an Artboard instance for
|
|
302
|
+
*/
|
|
303
|
+
artboardByIndex(index: number): Artboard; // rive::ArtboardInstance
|
|
304
|
+
/**
|
|
305
|
+
* Returns the number of Artboards in the Rive File
|
|
306
|
+
* @returns Number of artboards in the Rive file
|
|
307
|
+
*/
|
|
308
|
+
artboardCount(): number;
|
|
309
|
+
|
|
310
|
+
delete(): void;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Rive class representing an Artboard instance. Use this class to create instances for
|
|
315
|
+
* LinearAnimations, StateMachines, Nodes, Bones, and more. This Artboard instance should also be
|
|
316
|
+
* advanced in the drawing render loop.
|
|
317
|
+
*
|
|
318
|
+
* Important: Make sure to delete this instance when it's no longer in use via the `delete()`
|
|
319
|
+
* method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
|
|
320
|
+
* be done in cases where the user navigates away from the page with this animation, the canvas is
|
|
321
|
+
* unmounted, etc.
|
|
322
|
+
*/
|
|
323
|
+
export declare class Artboard {
|
|
324
|
+
/**
|
|
325
|
+
* Get the name of this Artboard instance
|
|
326
|
+
*/
|
|
327
|
+
get name(): string;
|
|
328
|
+
/**
|
|
329
|
+
* Get the bounds of this Artboard instance
|
|
330
|
+
*/
|
|
331
|
+
get bounds(): AABB;
|
|
332
|
+
get frameOrigin(): boolean;
|
|
333
|
+
set frameOrigin(val: boolean);
|
|
334
|
+
/**
|
|
335
|
+
* Deletes the underlying instance created via the WASM. It's important to clean up this
|
|
336
|
+
* instance when no longer in use
|
|
337
|
+
*/
|
|
338
|
+
delete(): void;
|
|
339
|
+
/**
|
|
340
|
+
* Advances the Artboard instance by the set amount of seconds. This method updates each object
|
|
341
|
+
* in the Artboard with any changes that animations apply on properties of the objects. This
|
|
342
|
+
* should be called after calling `advance()` of a LinearAnimationInstance or StateMachineInstance
|
|
343
|
+
* @param sec - Scrub the Artboard instance by a number of seconds
|
|
344
|
+
*/
|
|
345
|
+
advance(sec: number): boolean;
|
|
346
|
+
/**
|
|
347
|
+
* Draws the artboard with a given rendering context.
|
|
348
|
+
* @param renderer - Renderer context to draw with
|
|
349
|
+
*/
|
|
350
|
+
draw(renderer: CanvasRenderer | Renderer): void;
|
|
351
|
+
/**
|
|
352
|
+
* Creates a LinearAnimation for the animation with the given name
|
|
353
|
+
*
|
|
354
|
+
* Note: This does not create a LinearAnimationInstance to advance in the render loop.
|
|
355
|
+
* That needs to be created separately.
|
|
356
|
+
*
|
|
357
|
+
* @param name - Name of the animation to create a LinearAnimation reference for
|
|
358
|
+
* @returns A new LinearAnimation object
|
|
359
|
+
*/
|
|
360
|
+
animationByName(name: string): LinearAnimation;
|
|
361
|
+
/**
|
|
362
|
+
* Creates a LinearAnimation for the animation with the given index
|
|
363
|
+
*
|
|
364
|
+
* Note: This does not create a LinearAnimationInstance to advance in the render loop.
|
|
365
|
+
* That needs to be created separately.
|
|
366
|
+
*
|
|
367
|
+
* @param index - Index of the animation to create a LinearAnimation reference for
|
|
368
|
+
* @returns A new LinearAnimation object
|
|
369
|
+
*/
|
|
370
|
+
animationByIndex(index: number): LinearAnimation;
|
|
371
|
+
/**
|
|
372
|
+
* Returns the number of animations in the artboard
|
|
373
|
+
* @returns Number of animations on the Artboard
|
|
374
|
+
*/
|
|
375
|
+
animationCount(): number;
|
|
376
|
+
/**
|
|
377
|
+
* Creates a StateMachine for the state machine with the given name.
|
|
378
|
+
*
|
|
379
|
+
* Note: This does not create a StateMachineInstance to advance in the render loop.
|
|
380
|
+
* That needs to be created separately.
|
|
381
|
+
*
|
|
382
|
+
* @param name - Name of the state machine to create a StateMachine reference for
|
|
383
|
+
* @returns A new StateMachine object
|
|
384
|
+
*/
|
|
385
|
+
stateMachineByName(name: string): StateMachine;
|
|
386
|
+
/**
|
|
387
|
+
* Creates a StateMachine for the state machine with the given index
|
|
388
|
+
*
|
|
389
|
+
* Note: This does not create a StateMachineInstance to advance in the render loop.
|
|
390
|
+
* That needs to be created separately.
|
|
391
|
+
*
|
|
392
|
+
* @param index - Index of the state machine to create a StateMachine reference for
|
|
393
|
+
* @returns A new StateMachine object
|
|
394
|
+
*/
|
|
395
|
+
stateMachineByIndex(index: number): StateMachine;
|
|
396
|
+
/**
|
|
397
|
+
* Returns the number of state machines in the artboard
|
|
398
|
+
* @returns Number of state machines on the Artboard
|
|
399
|
+
*/
|
|
400
|
+
stateMachineCount(): number;
|
|
401
|
+
/**
|
|
402
|
+
* Returns a reference for a Bone object of a given name.
|
|
403
|
+
* Learn more: https://help.rive.app/editor/manipulating-shapes/bones
|
|
404
|
+
*
|
|
405
|
+
* @param name - Name of the Bone to grab a reference to
|
|
406
|
+
*/
|
|
407
|
+
bone(name: string): Bone;
|
|
408
|
+
/**
|
|
409
|
+
* Returns a reference for a Node object of a given name from the Artboard hierarchy
|
|
410
|
+
* @param name - Name of the Node from the Artboard hierarchy to grab a reference to
|
|
411
|
+
*/
|
|
412
|
+
node(name: string): Node;
|
|
413
|
+
/**
|
|
414
|
+
* Returns a reference for a root Bone object of a given name
|
|
415
|
+
* @param name - Name of the root Bone to grab a reference to
|
|
416
|
+
*/
|
|
417
|
+
rootBone(name: string): RootBone;
|
|
418
|
+
/**
|
|
419
|
+
* Returns a reference for a transform component object of a given name
|
|
420
|
+
* @param name - Name of the transform component to grab a reference to
|
|
421
|
+
*/
|
|
422
|
+
transformComponent(name: string): TransformComponent;
|
|
423
|
+
/**
|
|
424
|
+
* Returns a reference for a TextValueRun object to get/set a text value for
|
|
425
|
+
* @param name - Name of the Text Run to grab a reference to
|
|
426
|
+
*/
|
|
427
|
+
textRun(name: string): TextValueRun;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export declare class Bone extends TransformComponent {
|
|
431
|
+
/**
|
|
432
|
+
* Length of the bone
|
|
433
|
+
*/
|
|
434
|
+
length: number;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export declare class RootBone extends Bone {
|
|
438
|
+
/**
|
|
439
|
+
* X coordinate of the position on the RootBone
|
|
440
|
+
*/
|
|
441
|
+
x: number;
|
|
442
|
+
/**
|
|
443
|
+
* Y coordinate of the position on the RootBone
|
|
444
|
+
*/
|
|
445
|
+
y: number;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Representation of a node in the Artboard hierarchy (i.e group, shape, etc.)
|
|
450
|
+
*/
|
|
451
|
+
export declare class Node extends TransformComponent {
|
|
452
|
+
/**
|
|
453
|
+
* X coordinate of the position on the Node
|
|
454
|
+
*/
|
|
455
|
+
x: number;
|
|
456
|
+
/**
|
|
457
|
+
* Y coordinate of the position on the RootBone
|
|
458
|
+
*/
|
|
459
|
+
y: number;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export declare class TransformComponent {
|
|
463
|
+
rotation: number;
|
|
464
|
+
scaleX: number;
|
|
465
|
+
scaleY: number;
|
|
466
|
+
worldTransform(): Mat2D;
|
|
467
|
+
parentWorldTransform(result: Mat2D): void;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
///////////////
|
|
471
|
+
// Animation //
|
|
472
|
+
///////////////
|
|
473
|
+
/**
|
|
474
|
+
* Rive class representing a LinearAnimation instance. Use this class to advance and control a
|
|
475
|
+
* particular animation in the render loop (i.e speed, scrub, mix, etc.).
|
|
476
|
+
*
|
|
477
|
+
* Important: Make sure to delete this instance when it's no longer in use via the `delete()`
|
|
478
|
+
* method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
|
|
479
|
+
* be done in cases where the user navigates away from the page with this animation, the canvas is
|
|
480
|
+
* unmounted, etc.
|
|
481
|
+
*/
|
|
482
|
+
export declare class LinearAnimationInstance {
|
|
483
|
+
/**
|
|
484
|
+
* Create a new LinearAnimationInstance reference
|
|
485
|
+
* @param animation - A LinearAnimation reference retrieved via the Artboard
|
|
486
|
+
* (i.e `artboard.animationByName('foo')`)
|
|
487
|
+
* @param artboard - The Artboard instance for this animation
|
|
488
|
+
*/
|
|
489
|
+
constructor(animation: LinearAnimation, artboard: Artboard);
|
|
490
|
+
get name(): string;
|
|
491
|
+
get duration(): number;
|
|
492
|
+
get fps(): number;
|
|
493
|
+
get workStart(): number;
|
|
494
|
+
get workEnd(): number;
|
|
495
|
+
get loopValue(): number;
|
|
496
|
+
get speed(): number;
|
|
497
|
+
/**
|
|
498
|
+
* Number of seconds the animation has advanced by
|
|
499
|
+
*/
|
|
500
|
+
time: number;
|
|
501
|
+
/**
|
|
502
|
+
* Flag to determine if the animation looped (this is reset when the loop restarts)
|
|
503
|
+
*/
|
|
504
|
+
didLoop: boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Advances/scrubs the LinearAnimationInstance by the set amount of seconds. Note that this only
|
|
507
|
+
* moves the "time" in the animation, but does not apply changes to the properties in the
|
|
508
|
+
* Artboard. This must be called before the `apply()` method of LinearAnimationInstance.
|
|
509
|
+
*
|
|
510
|
+
* @param sec - Scrub the animation instance by a number of seconds
|
|
511
|
+
*/
|
|
512
|
+
advance(sec: number): boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Apply a mixing value on the animation instance. This is useful if you are looking to blend
|
|
515
|
+
* multiple animations together and want to dictate a strength for each of the animations played
|
|
516
|
+
* back. This also applies new values to properties of objects on the Artboard according to the
|
|
517
|
+
* keys of the animation.
|
|
518
|
+
* This must be called after the `advance()` method of `LinearAnimationInstance`
|
|
519
|
+
*
|
|
520
|
+
* @param mix 0-1 the strength of the animation in the animations mix.
|
|
521
|
+
*/
|
|
522
|
+
apply(mix: number): void;
|
|
523
|
+
/**
|
|
524
|
+
* Deletes the underlying instance created via the WASM. It's important to clean up this instance
|
|
525
|
+
* when no longer in use
|
|
526
|
+
*/
|
|
527
|
+
delete(): void;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export declare class TextValueRun {
|
|
531
|
+
/**
|
|
532
|
+
* Getter for the name of the Text Run
|
|
533
|
+
*/
|
|
534
|
+
get name(): string;
|
|
535
|
+
/**
|
|
536
|
+
* Getter for text value of the Text Run
|
|
537
|
+
*/
|
|
538
|
+
get text(): string;
|
|
539
|
+
/**
|
|
540
|
+
* Setter for the text value of the Text Run
|
|
541
|
+
*/
|
|
542
|
+
set text(val: string);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Rive Event interface for "General" custom events defined in the Rive editor. Each event has a
|
|
547
|
+
* name and optionally some other custom properties and a type
|
|
548
|
+
*/
|
|
549
|
+
export interface RiveEvent {
|
|
550
|
+
/**
|
|
551
|
+
* Name of the event fired
|
|
552
|
+
*/
|
|
553
|
+
name: string;
|
|
554
|
+
/**
|
|
555
|
+
* Optional type of the specific kind of event fired (i.e. General, OpenUrl)
|
|
556
|
+
*/
|
|
557
|
+
type?: number;
|
|
558
|
+
/**
|
|
559
|
+
* Optional custom properties defined on the event
|
|
560
|
+
*/
|
|
561
|
+
properties?: RiveEventCustomProperties;
|
|
562
|
+
/**
|
|
563
|
+
* Optional elapsed time since the event specifically occurred
|
|
564
|
+
*/
|
|
565
|
+
delay?: number;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* A specific Rive Event type for "OpenUrl" events. This event type has a URL and optionally a
|
|
570
|
+
* target property to dictate how to open the URL
|
|
571
|
+
*/
|
|
572
|
+
export interface OpenUrlEvent extends RiveEvent {
|
|
573
|
+
/**
|
|
574
|
+
* URL to open when the event is invoked
|
|
575
|
+
*/
|
|
576
|
+
url: string;
|
|
577
|
+
/**
|
|
578
|
+
* Where to display the linked URL
|
|
579
|
+
*/
|
|
580
|
+
target?: string;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* A Rive Event may have any number of optional custom properties defined on itself with variable names
|
|
585
|
+
* and values that are either a number, boolean, or string
|
|
586
|
+
*/
|
|
587
|
+
export interface RiveEventCustomProperties {
|
|
588
|
+
/**
|
|
589
|
+
* Custom property may be named anything in the Rive editor, and given a value of
|
|
590
|
+
* a number, boolean, or string type
|
|
591
|
+
*/
|
|
592
|
+
[key: string]: number | boolean | string;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export declare class LinearAnimation {
|
|
596
|
+
/**
|
|
597
|
+
* The animation's loop type
|
|
598
|
+
*/
|
|
599
|
+
get loopValue(): number;
|
|
600
|
+
/**
|
|
601
|
+
* Name of the LinearAnimation
|
|
602
|
+
*/
|
|
603
|
+
get name(): string;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export declare class StateMachine {
|
|
607
|
+
/**
|
|
608
|
+
* Name of the StateMachine
|
|
609
|
+
*/
|
|
610
|
+
get name(): string;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Rive class representing a StateMachine instance. Use this class to advance and control a
|
|
615
|
+
* particular state machine in the render loop (i.e scrub, grab state machine inputs, set up
|
|
616
|
+
* listener events, etc.).
|
|
617
|
+
*
|
|
618
|
+
* Important: Make sure to delete this instance when it's no longer in use via the `delete()`
|
|
619
|
+
* method. This deletes the underlying c++ reference and frees up the backing WASM object. This can
|
|
620
|
+
* be done in cases where the user navigates away from the page with this animation, the canvas is
|
|
621
|
+
* unmounted, etc.
|
|
622
|
+
*/
|
|
623
|
+
export declare class StateMachineInstance {
|
|
624
|
+
/**
|
|
625
|
+
* Create a new StateMachineInstance reference
|
|
626
|
+
* @param stateMachine - A StateMachine retrieved via the Artboard
|
|
627
|
+
* (i.e `artboard.stateMachineByName('foo')`)
|
|
628
|
+
* @param artboard - The Artboard instance for this state machine
|
|
629
|
+
*/
|
|
630
|
+
constructor(stateMachine: StateMachine, artboard: Artboard);
|
|
631
|
+
get name(): string;
|
|
632
|
+
/**
|
|
633
|
+
* Returns the number of inputs associated with this state machine
|
|
634
|
+
* @returns Number of inputs
|
|
635
|
+
*/
|
|
636
|
+
inputCount(): number;
|
|
637
|
+
/**
|
|
638
|
+
* Returns the state machine input at the given index
|
|
639
|
+
* @param i - Index to retrieve the state machine input at
|
|
640
|
+
* @returns SMIInput reference
|
|
641
|
+
*/
|
|
642
|
+
input(i: number): SMIInput;
|
|
643
|
+
/**
|
|
644
|
+
* Advances/scrubs the StateMachineInstance by the set amount of seconds. Note that this does not
|
|
645
|
+
* apply changes to the properties of objects in the Artboard yet.
|
|
646
|
+
* @param sec - Scrub the state machine instance by a number of seconds
|
|
647
|
+
*/
|
|
648
|
+
advance(sec: number): boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Returns the number of states changed while the state machine played
|
|
651
|
+
* @returns Number of states changed in the duration of the state machine played
|
|
652
|
+
*/
|
|
653
|
+
stateChangedCount(): number;
|
|
654
|
+
/**
|
|
655
|
+
* Returns the name of the state/animation transitioned to, given the index in the array of state
|
|
656
|
+
* changes in total
|
|
657
|
+
* @param i
|
|
658
|
+
* @returns Name of the state/animation transitioned to
|
|
659
|
+
*/
|
|
660
|
+
stateChangedNameByIndex(i: number): string;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Returns the number of events reported from the last advance call
|
|
664
|
+
* @returns Number of events reported
|
|
665
|
+
*/
|
|
666
|
+
reportedEventCount(): number;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Returns a RiveEvent object emitted from the last advance call at the given index
|
|
670
|
+
* of a list of potentially multiple events. If an event at the index is not found,
|
|
671
|
+
* undefined is returned.
|
|
672
|
+
* @param i index of the event reported in a list of potentially multiple events
|
|
673
|
+
* @returns RiveEvent or extended RiveEvent object returned, or undefined
|
|
674
|
+
*/
|
|
675
|
+
reportedEventAt(i: number): OpenUrlEvent | RiveEvent | undefined;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Notifies the state machine that the pointer has pressed down at the given coordinate in
|
|
679
|
+
* Artboard space. Internally, Rive may advance a state machine if the listener coordinate is of
|
|
680
|
+
* interest at a given moment.
|
|
681
|
+
*
|
|
682
|
+
* @param x - X coordinate
|
|
683
|
+
* @param y - Y coordinate
|
|
684
|
+
*/
|
|
685
|
+
pointerDown(x: number, y: number): void;
|
|
686
|
+
/**
|
|
687
|
+
* Notifies the state machine that the pointer has moved to 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
|
+
pointerMove(x: number, y: number): void;
|
|
695
|
+
/**
|
|
696
|
+
* Notifies the state machine that the pointer has released at 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
|
+
* @param x - X coordinate
|
|
700
|
+
* @param y - Y coordinate
|
|
701
|
+
*/
|
|
702
|
+
pointerUp(x: number, y: number): void;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Deletes the underlying instance created via the WASM. It's important to clean up this instance
|
|
706
|
+
* when no longer in use
|
|
707
|
+
*/
|
|
708
|
+
delete(): void;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export declare class SMIInput {
|
|
712
|
+
// TODO: Keep only the base SMIInput properties and make SMIBool, SMINumber, SMITriger extend it
|
|
713
|
+
static bool: number;
|
|
714
|
+
static number: number;
|
|
715
|
+
static trigger: number;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Getter for name of the state machine input
|
|
719
|
+
*/
|
|
720
|
+
get name(): string;
|
|
721
|
+
get type(): number;
|
|
722
|
+
/**
|
|
723
|
+
* Getter for value of the state machine input
|
|
724
|
+
*/
|
|
725
|
+
get value(): boolean | number | undefined;
|
|
726
|
+
/**
|
|
727
|
+
* Setter for value of the state machine input
|
|
728
|
+
*/
|
|
729
|
+
set value(val: boolean | number | undefined);
|
|
730
|
+
/**
|
|
731
|
+
* Fires a trigger input on a state machine
|
|
732
|
+
*/
|
|
733
|
+
fire(): void;
|
|
734
|
+
asBool(): SMIInput;
|
|
735
|
+
asNumber(): SMIInput;
|
|
736
|
+
asTrigger(): SMIInput;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
export declare class SMIBool {}
|
|
740
|
+
|
|
741
|
+
export declare class SMINumber {}
|
|
742
|
+
|
|
743
|
+
export declare class SMITrigger {}
|
|
744
|
+
|
|
745
|
+
///////////
|
|
746
|
+
// ENUMS //
|
|
747
|
+
///////////
|
|
748
|
+
|
|
749
|
+
export enum Fit {
|
|
750
|
+
fill,
|
|
751
|
+
contain,
|
|
752
|
+
cover,
|
|
753
|
+
fitWidth,
|
|
754
|
+
fitHeight,
|
|
755
|
+
none,
|
|
756
|
+
scaleDown,
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export enum RenderPaintStyle {
|
|
760
|
+
fill,
|
|
761
|
+
stroke,
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export enum FillRule {
|
|
765
|
+
nonZero,
|
|
766
|
+
evenOdd,
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export enum StrokeCap {
|
|
770
|
+
butt,
|
|
771
|
+
round,
|
|
772
|
+
square,
|
|
773
|
+
}
|
|
774
|
+
export enum StrokeJoin {
|
|
775
|
+
miter,
|
|
776
|
+
round,
|
|
777
|
+
bevel,
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export enum BlendMode {
|
|
781
|
+
srcOver = 3,
|
|
782
|
+
screen = 14,
|
|
783
|
+
overlay = 15,
|
|
784
|
+
darken = 16,
|
|
785
|
+
lighten = 17,
|
|
786
|
+
colorDodge = 18,
|
|
787
|
+
colorBurn = 19,
|
|
788
|
+
hardLight = 20,
|
|
789
|
+
softLight = 21,
|
|
790
|
+
difference = 22,
|
|
791
|
+
exclusion = 23,
|
|
792
|
+
multiply = 24,
|
|
793
|
+
hue = 25,
|
|
794
|
+
saturation = 26,
|
|
795
|
+
color = 27,
|
|
796
|
+
luminosity = 28,
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
///////////
|
|
800
|
+
// UTILS //
|
|
801
|
+
///////////
|
|
802
|
+
|
|
803
|
+
export declare class Alignment {
|
|
804
|
+
get x(): number;
|
|
805
|
+
get y(): number;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
export declare class AlignmentFactory {
|
|
809
|
+
get topLeft(): Alignment;
|
|
810
|
+
get topCenter(): Alignment;
|
|
811
|
+
get topRight(): Alignment;
|
|
812
|
+
get centerLeft(): Alignment;
|
|
813
|
+
get center(): Alignment;
|
|
814
|
+
get centerRight(): Alignment;
|
|
815
|
+
get bottomLeft(): Alignment;
|
|
816
|
+
get bottomCenter(): Alignment;
|
|
817
|
+
get bottomRight(): Alignment;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Axis-aligned bounding box
|
|
822
|
+
*/
|
|
823
|
+
export interface AABB {
|
|
824
|
+
minX: number;
|
|
825
|
+
minY: number;
|
|
826
|
+
maxX: number;
|
|
827
|
+
maxY: number;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Column-major matrix described by the following:
|
|
832
|
+
* | xx yx tx |
|
|
833
|
+
* | xy yy ty |
|
|
834
|
+
* | 0 0 1 |
|
|
835
|
+
*/
|
|
836
|
+
export declare class Mat2D {
|
|
837
|
+
xx: number;
|
|
838
|
+
xy: number;
|
|
839
|
+
yx: number;
|
|
840
|
+
yy: number;
|
|
841
|
+
tx: number;
|
|
842
|
+
ty: number;
|
|
843
|
+
/**
|
|
844
|
+
* Returns whether or not a matrix could be inverted, and if yes, sets the resulting Mat2D into
|
|
845
|
+
* the passed-in `mat` parameter
|
|
846
|
+
*
|
|
847
|
+
* @param mat - Reference Mat2D to store the newly inverted matrix into if successful
|
|
848
|
+
* @returns True if the matrix could be inverted
|
|
849
|
+
*/
|
|
850
|
+
invert(mat: Mat2D): boolean;
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Deletes the underlying CPP object created for this instance
|
|
854
|
+
*/
|
|
855
|
+
delete(): void;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* Rive Vector class
|
|
860
|
+
*/
|
|
861
|
+
export declare class Vec2D {
|
|
862
|
+
constructor(x: number, y: number);
|
|
863
|
+
/**
|
|
864
|
+
* Returns the x coordinate of the vector
|
|
865
|
+
*/
|
|
866
|
+
x(): number;
|
|
867
|
+
/**
|
|
868
|
+
* Returns the y coordinate of the vector
|
|
869
|
+
*/
|
|
870
|
+
y(): number;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Deletes the underlying CPP object created for this instance
|
|
874
|
+
*/
|
|
875
|
+
delete(): void;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Rive class representing a FileAsset with relevant metadata fields to describe
|
|
880
|
+
* an asset associated wtih the Rive File
|
|
881
|
+
*/
|
|
882
|
+
export declare class FileAsset {
|
|
883
|
+
name: string;
|
|
884
|
+
fileExtension: string;
|
|
885
|
+
isImage: boolean;
|
|
886
|
+
isFont: boolean;
|
|
887
|
+
cdnUuid: string;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Rive class extending the FileAsset that exposes a `setRenderImage()` API with a
|
|
892
|
+
* decoded Image (via the `decodeImage()` API) to set a new Image on the Rive FileAsset
|
|
893
|
+
*/
|
|
894
|
+
export declare class ImageAsset extends FileAsset {
|
|
895
|
+
setRenderImage(image: Image): void;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Rive class extending the FileAsset that exposes a `setFont()` API with a
|
|
900
|
+
* decoded Font (via the `decodeFont()` API) to set a new Font on the Rive FileAsset
|
|
901
|
+
*/
|
|
902
|
+
export declare class FontAsset extends FileAsset {
|
|
903
|
+
setFont(font: Font): void;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
export declare class FileAssetLoader {}
|
|
907
|
+
|
|
908
|
+
export declare class CustomFileAssetLoader extends FileAssetLoader {
|
|
909
|
+
constructor({ loadContents }: { loadContents: Function });
|
|
910
|
+
loadContents(asset: FileAsset, bytes: any): boolean;
|
|
911
|
+
}
|