@rive-app/webgl-single 1.0.3 → 1.0.7

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/README.md ADDED
@@ -0,0 +1,16 @@
1
+ ![npm](https://img.shields.io/npm/v/@rive-app/webgl-single)
2
+
3
+ # Rive
4
+ High level Rive API using WebGL and inline WASM. Please see https://github.com/rive-app/rive-wasm for a list of all the available web runtimes and their details.
5
+
6
+ ### WebGL
7
+ ```
8
+ npm install @rive-app/webgl-single
9
+ ```
10
+ An easy to use high level Rive API using the WebGL renderer. This lets Rive squeeze every last ounce of performance from the hardware and provide some newer advanced rendering features which will not be available to the Canvas renderers.
11
+ - Highest fidelity with edit-time experience.
12
+ - Best performance across all devices.
13
+ - Support for upcoming features like mesh deformations.
14
+
15
+
16
+ [Quickstart](https://github.com/rive-app/rive-wasm#quick-start)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/webgl-single",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "description": "Rive's webgl based web api with bundled wasm.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
@@ -22,8 +22,15 @@
22
22
  ],
23
23
  "license": "MIT",
24
24
  "files": [
25
- "rive.js"
25
+ "rive.js",
26
+ "rive.js.map",
27
+ "rive.d.ts",
28
+ "rive_advanced.mjs.d.ts"
26
29
  ],
27
30
  "typings": "rive.d.ts",
28
- "dependencies": {}
31
+ "dependencies": {},
32
+ "browser": {
33
+ "fs": false,
34
+ "path": false
35
+ }
29
36
  }
package/rive.d.ts ADDED
@@ -0,0 +1,426 @@
1
+ import * as rc from './rive_advanced.mjs';
2
+ /**
3
+ * Generic type for a parameterless void callback
4
+ */
5
+ export declare type VoidCallback = () => void;
6
+ /**
7
+ * Interface for artboard bounds
8
+ */
9
+ export interface Bounds extends rc.AABB {
10
+ }
11
+ export declare enum Fit {
12
+ Cover = "cover",
13
+ Contain = "contain",
14
+ Fill = "fill",
15
+ FitWidth = "fitWidth",
16
+ FitHeight = "fitHeight",
17
+ None = "none",
18
+ ScaleDown = "scaleDown"
19
+ }
20
+ export declare enum Alignment {
21
+ Center = "center",
22
+ TopLeft = "topLeft",
23
+ TopCenter = "topCenter",
24
+ TopRight = "topRight",
25
+ CenterLeft = "centerLeft",
26
+ CenterRight = "centerRight",
27
+ BottomLeft = "bottomLeft",
28
+ BottomCenter = "bottomCenter",
29
+ BottomRight = "bottomRight"
30
+ }
31
+ export interface LayoutParameters {
32
+ fit?: Fit;
33
+ alignment?: Alignment;
34
+ minX?: number;
35
+ minY?: number;
36
+ maxX?: number;
37
+ maxY?: number;
38
+ }
39
+ export declare class Layout {
40
+ private cachedRuntimeFit;
41
+ private cachedRuntimeAlignment;
42
+ readonly fit: Fit;
43
+ readonly alignment: Alignment;
44
+ readonly minX: number;
45
+ readonly minY: number;
46
+ readonly maxX: number;
47
+ readonly maxY: number;
48
+ constructor(params?: LayoutParameters);
49
+ static new({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
50
+ /**
51
+ * Makes a copy of the layout, replacing any specified parameters
52
+ */
53
+ copyWith({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
54
+ runtimeFit(rive: rc.RiveCanvas): rc.Fit;
55
+ runtimeAlignment(rive: rc.RiveCanvas): rc.Alignment;
56
+ }
57
+ export declare type RuntimeCallback = (rive: rc.RiveCanvas) => void;
58
+ export declare class RuntimeLoader {
59
+ private static runtime;
60
+ private static isLoading;
61
+ private static callBackQueue;
62
+ private static rive;
63
+ private static wasmURL;
64
+ private constructor();
65
+ private static loadRuntime;
66
+ static getInstance(callback: RuntimeCallback): void;
67
+ static awaitInstance(): Promise<rc.RiveCanvas>;
68
+ static setWasmUrl(url: string): void;
69
+ }
70
+ export declare enum StateMachineInputType {
71
+ Number = 56,
72
+ Trigger = 58,
73
+ Boolean = 59
74
+ }
75
+ /**
76
+ * An input for a state machine
77
+ */
78
+ export declare class StateMachineInput {
79
+ readonly type: StateMachineInputType;
80
+ private runtimeInput;
81
+ constructor(type: StateMachineInputType, runtimeInput: rc.SMIInput);
82
+ /**
83
+ * Returns the name of the input
84
+ */
85
+ get name(): string;
86
+ /**
87
+ * Returns the current value of the input
88
+ */
89
+ get value(): number | boolean;
90
+ /**
91
+ * Sets the value of the input
92
+ */
93
+ set value(value: number | boolean);
94
+ /**
95
+ * Fires a trigger; does nothing on Number or Boolean input types
96
+ */
97
+ fire(): void;
98
+ }
99
+ /**
100
+ * Supported event types triggered in Rive
101
+ */
102
+ export declare enum EventType {
103
+ Load = "load",
104
+ LoadError = "loaderror",
105
+ Play = "play",
106
+ Pause = "pause",
107
+ Stop = "stop",
108
+ Loop = "loop",
109
+ Draw = "draw",
110
+ StateChange = "statechange"
111
+ }
112
+ export interface Event {
113
+ type: EventType;
114
+ data?: string | string[] | LoopEvent;
115
+ }
116
+ /**
117
+ * Looping types: one-shot, loop, and ping-pong
118
+ */
119
+ export declare enum LoopType {
120
+ OneShot = "oneshot",
121
+ Loop = "loop",
122
+ PingPong = "pingpong"
123
+ }
124
+ /**
125
+ * Loop events are returned through onloop callbacks
126
+ */
127
+ export interface LoopEvent {
128
+ animation: string;
129
+ type: LoopType;
130
+ }
131
+ /**
132
+ * Loop events are returned through onloop callbacks
133
+ */
134
+ export declare type EventCallback = (event: Event) => void;
135
+ /**
136
+ * Event listeners registered with the event manager
137
+ */
138
+ export interface EventListener {
139
+ type: EventType;
140
+ callback: EventCallback;
141
+ }
142
+ declare class EventManager {
143
+ private listeners;
144
+ constructor(listeners?: EventListener[]);
145
+ private getListeners;
146
+ add(listener: EventListener): void;
147
+ /**
148
+ * Removes a listener
149
+ * @param listener the listener with the callback to be removed
150
+ */
151
+ remove(listener: EventListener): void;
152
+ /**
153
+ * Clears all listeners of specified type, or every listener if no type is
154
+ * specified
155
+ * @param type the type of listeners to clear, or all listeners if not
156
+ * specified
157
+ */
158
+ removeAll(type?: EventType): void;
159
+ fire(event: Event): void;
160
+ }
161
+ export interface Task {
162
+ action: VoidCallback;
163
+ event?: Event;
164
+ }
165
+ declare class TaskQueueManager {
166
+ private eventManager;
167
+ private queue;
168
+ constructor(eventManager: EventManager);
169
+ add(task: Task): void;
170
+ process(): void;
171
+ }
172
+ export interface RiveParameters {
173
+ canvas: HTMLCanvasElement | OffscreenCanvas;
174
+ src?: string;
175
+ buffer?: ArrayBuffer;
176
+ artboard?: string;
177
+ animations?: string | string[];
178
+ stateMachines?: string | string[];
179
+ layout?: Layout;
180
+ autoplay?: boolean;
181
+ onLoad?: EventCallback;
182
+ onLoadError?: EventCallback;
183
+ onPlay?: EventCallback;
184
+ onPause?: EventCallback;
185
+ onStop?: EventCallback;
186
+ onLoop?: EventCallback;
187
+ onStateChange?: EventCallback;
188
+ /**
189
+ * @deprecated Use `onLoad()` instead
190
+ */
191
+ onload?: EventCallback;
192
+ /**
193
+ * @deprecated Use `onLoadError()` instead
194
+ */
195
+ onloaderror?: EventCallback;
196
+ /**
197
+ * @deprecated Use `onPoad()` instead
198
+ */
199
+ onplay?: EventCallback;
200
+ /**
201
+ * @deprecated Use `onPause()` instead
202
+ */
203
+ onpause?: EventCallback;
204
+ /**
205
+ * @deprecated Use `onStop()` instead
206
+ */
207
+ onstop?: EventCallback;
208
+ /**
209
+ * @deprecated Use `onLoop()` instead
210
+ */
211
+ onloop?: EventCallback;
212
+ /**
213
+ * @deprecated Use `onStateChange()` instead
214
+ */
215
+ onstatechange?: EventCallback;
216
+ }
217
+ export interface RiveLoadParameters {
218
+ src?: string;
219
+ buffer?: ArrayBuffer;
220
+ autoplay?: boolean;
221
+ artboard?: string;
222
+ animations?: string | string[];
223
+ stateMachines?: string | string[];
224
+ }
225
+ export interface RiveResetParameters {
226
+ artboard?: string;
227
+ animations?: string | string[];
228
+ stateMachines?: string | string[];
229
+ autoplay?: boolean;
230
+ }
231
+ export declare class Rive {
232
+ private readonly canvas;
233
+ private src;
234
+ private buffer;
235
+ private _layout;
236
+ private _updateLayout;
237
+ private renderer;
238
+ /**
239
+ * Flag to active/deactivate renderer
240
+ */
241
+ private isRendererActive;
242
+ private loaded;
243
+ /**
244
+ * Tracks if a Rive file is loaded; we need this in addition to loaded as some
245
+ * commands (e.g. contents) can be called as soon as the file is loaded.
246
+ * However, playback commands need to be queued and run in order once initial
247
+ * animations and autoplay has been sorted out. This applies to play, pause,
248
+ * and start.
249
+ */
250
+ private readyForPlaying;
251
+ private runtime;
252
+ private artboard;
253
+ private file;
254
+ private eventManager;
255
+ private taskQueue;
256
+ private animator;
257
+ private static readonly missingErrorMessage;
258
+ constructor(params: RiveParameters);
259
+ static new(params: RiveParameters): Rive;
260
+ private init;
261
+ private initData;
262
+ private initArtboard;
263
+ drawFrame(): void;
264
+ private lastRenderTime;
265
+ private frameRequestId;
266
+ /**
267
+ * Used be draw to track when a second of active rendering time has passed. Used for debugging purposes
268
+ */
269
+ private renderSecondTimer;
270
+ /**
271
+ * Draw rendering loop; renders animation frames at the correct time interval.
272
+ * @param time the time at which to render a frame
273
+ */
274
+ private draw;
275
+ /**
276
+ * Align the renderer
277
+ */
278
+ private alignRenderer;
279
+ /**
280
+ * Cleans up any Wasm-generated objects that need to be manually destroyed:
281
+ * artboard instances, animation instances, state machine instances.
282
+ *
283
+ * Once this is called, things will need to be reinitialized or bad things
284
+ * might happen.
285
+ */
286
+ cleanup(): void;
287
+ play(animationNames?: string | string[], autoplay?: true): void;
288
+ pause(animationNames?: string | string[]): void;
289
+ scrub(animationNames?: string | string[], value?: number): void;
290
+ stop(animationNames?: string | string[] | undefined): void;
291
+ /**
292
+ * Resets the animation
293
+ * @param artboard the name of the artboard, or default if none given
294
+ * @param animations the names of animations for playback
295
+ * @param stateMachines the names of state machines for playback
296
+ * @param autoplay whether to autoplay when reset, defaults to false
297
+ *
298
+ */
299
+ reset(params?: RiveResetParameters): void;
300
+ load(params: RiveLoadParameters): void;
301
+ set layout(layout: Layout);
302
+ /**
303
+ * Returns the current layout. Note that layout should be treated as
304
+ * immutable. If you want to change the layout, create a new one use the
305
+ * layout setter
306
+ */
307
+ get layout(): Layout;
308
+ /**
309
+ * Sets the layout bounds to the current canvas size; this is typically called
310
+ * when the canvas is resized
311
+ */
312
+ resizeToCanvas(): void;
313
+ get source(): string;
314
+ /**
315
+ * Returns the name of the active artboard
316
+ */
317
+ get activeArtboard(): string;
318
+ get animationNames(): string[];
319
+ /**
320
+ * Returns a list of state machine names from the current artboard
321
+ */
322
+ get stateMachineNames(): string[];
323
+ /**
324
+ * Returns the inputs for the specified instanced state machine, or an empty
325
+ * list if the name is invalid or the state machine is not instanced
326
+ * @param name the state machine name
327
+ * @returns the inputs for the named state machine
328
+ */
329
+ stateMachineInputs(name: string): StateMachineInput[];
330
+ get playingStateMachineNames(): string[];
331
+ get playingAnimationNames(): string[];
332
+ get pausedAnimationNames(): string[];
333
+ /**
334
+ * Returns a list of paused machine names
335
+ * @returns a list of state machine names that are paused
336
+ */
337
+ get pausedStateMachineNames(): string[];
338
+ /**
339
+ * @returns true if any animation is playing
340
+ */
341
+ get isPlaying(): boolean;
342
+ /**
343
+ * @returns true if all instanced animations are paused
344
+ */
345
+ get isPaused(): boolean;
346
+ /**
347
+ * @returns true if no animations are playing or paused
348
+ */
349
+ get isStopped(): boolean;
350
+ /**
351
+ * @returns the bounds of the current artboard, or undefined if the artboard
352
+ * isn't loaded yet.
353
+ */
354
+ get bounds(): Bounds;
355
+ /**
356
+ * Subscribe to Rive-generated events
357
+ * @param type the type of event to subscribe to
358
+ * @param callback callback to fire when the event occurs
359
+ */
360
+ on(type: EventType, callback: EventCallback): void;
361
+ /**
362
+ * Unsubscribes from a Rive-generated event
363
+ * @param callback the callback to unsubscribe from
364
+ */
365
+ unsubscribe(type: EventType, callback: EventCallback): void;
366
+ /**
367
+ * Unsubscribes all listeners from an event type, or everything if no type is
368
+ * given
369
+ * @param type the type of event to unsubscribe from, or all types if
370
+ * undefined
371
+ */
372
+ unsubscribeAll(type?: EventType): void;
373
+ /**
374
+ * Stops the rendering loop; this is different from pausing in that it doesn't
375
+ * change the state of any animation. It stops rendering from occurring. This
376
+ * is designed for situations such as when Rive isn't visible.
377
+ *
378
+ * The only way to start rendering again is to call `startRendering`.
379
+ * Animations that are marked as playing will start from the position that
380
+ * they would have been at if rendering had not been stopped.
381
+ */
382
+ stopRendering(): void;
383
+ /**
384
+ * Starts the rendering loop if it has been previously stopped. If the
385
+ * renderer is already active, then this will have zero effect.
386
+ */
387
+ startRendering(): void;
388
+ /**
389
+ * Returns the contents of a Rive file: the artboards, animations, and state machines
390
+ */
391
+ get contents(): RiveFileContents;
392
+ }
393
+ /**
394
+ * Contents of a state machine input
395
+ */
396
+ interface StateMachineInputContents {
397
+ name: string;
398
+ type: StateMachineInputType;
399
+ initialValue?: boolean | number;
400
+ }
401
+ /**
402
+ * Contents of a state machine
403
+ */
404
+ interface StateMachineContents {
405
+ name: string;
406
+ inputs: StateMachineInputContents[];
407
+ }
408
+ /**
409
+ * Contents of an artboard
410
+ */
411
+ interface ArtboardContents {
412
+ animations: string[];
413
+ stateMachines: StateMachineContents[];
414
+ name: string;
415
+ }
416
+ /**
417
+ * contents of a Rive file
418
+ */
419
+ interface RiveFileContents {
420
+ artboards?: ArtboardContents[];
421
+ }
422
+ export declare const Testing: {
423
+ EventManager: typeof EventManager;
424
+ TaskQueueManager: typeof TaskQueueManager;
425
+ };
426
+ export {};