@grandgular/rive-angular 0.3.0 → 0.4.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.
|
@@ -1,7 +1,44 @@
|
|
|
1
1
|
import * as _angular_core from '@angular/core';
|
|
2
2
|
import { AfterViewInit, Signal, Provider } from '@angular/core';
|
|
3
|
-
import { RiveFile, Fit, Alignment, Event, Rive } from '@rive-app/canvas';
|
|
4
|
-
export { Alignment, EventType, Fit, Layout, LayoutParameters, Rive, Event as RiveEvent, RiveFile, RiveFileParameters, RiveParameters, StateMachineInput } from '@rive-app/canvas';
|
|
3
|
+
import { RiveFile, Fit, Alignment, Event, Rive, ViewModelInstance } from '@rive-app/canvas';
|
|
4
|
+
export { Alignment, EventType, Fit, Layout, LayoutParameters, Rive, Event as RiveEvent, RiveFile, RiveFileParameters, RiveParameters, StateMachineInput, ViewModelInstance } from '@rive-app/canvas';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a color value in RGBA format for Rive animations.
|
|
8
|
+
* All components are in the range 0-255.
|
|
9
|
+
*/
|
|
10
|
+
interface RiveColor {
|
|
11
|
+
/** Red component (0-255) */
|
|
12
|
+
r: number;
|
|
13
|
+
/** Green component (0-255) */
|
|
14
|
+
g: number;
|
|
15
|
+
/** Blue component (0-255) */
|
|
16
|
+
b: number;
|
|
17
|
+
/** Alpha component (0-255), defaults to 255 (fully opaque) */
|
|
18
|
+
a: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Union type representing all possible data binding values.
|
|
22
|
+
* Used in the dataBindings input to support multiple property types.
|
|
23
|
+
*/
|
|
24
|
+
type DataBindingValue = number | string | boolean | RiveColor;
|
|
25
|
+
/**
|
|
26
|
+
* Enum representing the type of a ViewModel property.
|
|
27
|
+
* Used for type detection and validation.
|
|
28
|
+
*/
|
|
29
|
+
type DataBindingPropertyType = 'number' | 'string' | 'boolean' | 'color' | 'enum' | 'trigger';
|
|
30
|
+
/**
|
|
31
|
+
* Event emitted when a ViewModel property changes from within the animation.
|
|
32
|
+
* This enables two-way data binding between the animation and Angular application.
|
|
33
|
+
*/
|
|
34
|
+
interface DataBindingChangeEvent {
|
|
35
|
+
/** Path to the property in the ViewModel */
|
|
36
|
+
path: string;
|
|
37
|
+
/** New value of the property */
|
|
38
|
+
value: DataBindingValue;
|
|
39
|
+
/** Type of the property that changed */
|
|
40
|
+
propertyType: DataBindingPropertyType;
|
|
41
|
+
}
|
|
5
42
|
|
|
6
43
|
/**
|
|
7
44
|
* Standalone Angular component for Rive animations
|
|
@@ -73,6 +110,30 @@ declare class RiveCanvasComponent implements AfterViewInit {
|
|
|
73
110
|
* Values are applied reactively when input changes.
|
|
74
111
|
*/
|
|
75
112
|
readonly textRuns: _angular_core.InputSignal<Record<string, string> | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* Name of the ViewModel to use for data binding.
|
|
115
|
+
* If not provided, uses the default ViewModel for the artboard.
|
|
116
|
+
* Only relevant if the .riv file contains ViewModels.
|
|
117
|
+
*/
|
|
118
|
+
readonly viewModelName: _angular_core.InputSignal<string | undefined>;
|
|
119
|
+
/**
|
|
120
|
+
* Record of ViewModel property paths to values for declarative data binding.
|
|
121
|
+
* Keys present in this input are CONTROLLED — the input is the source of truth.
|
|
122
|
+
* Keys absent from this input are UNCONTROLLED — managed imperatively.
|
|
123
|
+
* Values are applied reactively when input changes.
|
|
124
|
+
*
|
|
125
|
+
* Supports multiple data types: number, string, boolean, RiveColor.
|
|
126
|
+
* The component auto-detects the property type from the ViewModel.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* [dataBindings]="{
|
|
130
|
+
* backgroundColor: '#FF5733',
|
|
131
|
+
* score: 42,
|
|
132
|
+
* playerName: 'Alice',
|
|
133
|
+
* isActive: true
|
|
134
|
+
* }"
|
|
135
|
+
*/
|
|
136
|
+
readonly dataBindings: _angular_core.InputSignal<Record<string, DataBindingValue> | undefined>;
|
|
76
137
|
readonly loaded: _angular_core.OutputEmitterRef<void>;
|
|
77
138
|
readonly loadError: _angular_core.OutputEmitterRef<Error>;
|
|
78
139
|
/**
|
|
@@ -91,6 +152,12 @@ declare class RiveCanvasComponent implements AfterViewInit {
|
|
|
91
152
|
* Note: This fires AFTER the animation is loaded, not just instantiated.
|
|
92
153
|
*/
|
|
93
154
|
readonly riveReady: _angular_core.OutputEmitterRef<Rive>;
|
|
155
|
+
/**
|
|
156
|
+
* Emitted when a ViewModel property changes from within the animation.
|
|
157
|
+
* Enables two-way data binding between the animation and Angular application.
|
|
158
|
+
* Only fires if the .riv file uses ViewModels with callbacks.
|
|
159
|
+
*/
|
|
160
|
+
readonly dataBindingChange: _angular_core.OutputEmitterRef<DataBindingChangeEvent>;
|
|
94
161
|
readonly isPlaying: _angular_core.Signal<boolean>;
|
|
95
162
|
readonly isPaused: _angular_core.Signal<boolean>;
|
|
96
163
|
readonly isLoaded: _angular_core.Signal<boolean>;
|
|
@@ -99,6 +166,12 @@ declare class RiveCanvasComponent implements AfterViewInit {
|
|
|
99
166
|
* Use this to access advanced Rive SDK features.
|
|
100
167
|
*/
|
|
101
168
|
readonly riveInstance: _angular_core.Signal<Rive | null>;
|
|
169
|
+
/**
|
|
170
|
+
* Public signal providing access to the ViewModel instance.
|
|
171
|
+
* Use this to access advanced ViewModel features for data binding.
|
|
172
|
+
* Returns null if the .riv file doesn't use ViewModels.
|
|
173
|
+
*/
|
|
174
|
+
readonly viewModelInstance: _angular_core.Signal<ViewModelInstance | null>;
|
|
102
175
|
private readonly logger;
|
|
103
176
|
private resizeObserver;
|
|
104
177
|
private isInitialized;
|
|
@@ -185,17 +258,102 @@ declare class RiveCanvasComponent implements AfterViewInit {
|
|
|
185
258
|
* Note: AtPath text runs are always uncontrolled (not managed by textRuns input).
|
|
186
259
|
*/
|
|
187
260
|
setTextRunValueAtPath(textRunName: string, textRunValue: string, path: string): void;
|
|
261
|
+
/**
|
|
262
|
+
* Set a data binding value in the ViewModel.
|
|
263
|
+
* Auto-detects the property type and applies the value accordingly.
|
|
264
|
+
* Warning: If the property is controlled by dataBindings input, this change
|
|
265
|
+
* will be overwritten on the next input update.
|
|
266
|
+
*/
|
|
267
|
+
setDataBinding(path: string, value: DataBindingValue): void;
|
|
268
|
+
/**
|
|
269
|
+
* Get a data binding value from the ViewModel.
|
|
270
|
+
* Auto-detects the property type and returns the value accordingly.
|
|
271
|
+
* Returns undefined if the property doesn't exist or ViewModel is not loaded.
|
|
272
|
+
*/
|
|
273
|
+
getDataBinding(path: string): DataBindingValue | undefined;
|
|
274
|
+
/**
|
|
275
|
+
* Fire a trigger property in the ViewModel.
|
|
276
|
+
* Use this for ViewModel-based triggers (data binding).
|
|
277
|
+
* For state machine triggers, use fireTrigger(stateMachineName, triggerName).
|
|
278
|
+
*/
|
|
279
|
+
fireViewModelTrigger(path: string): void;
|
|
280
|
+
/**
|
|
281
|
+
* Set a color value in the ViewModel.
|
|
282
|
+
* Accepts hex string ('#RRGGBB' or '#RRGGBBAA'), ARGB integer, or RiveColor object.
|
|
283
|
+
* Warning: If the property is controlled by dataBindings input, this change
|
|
284
|
+
* will be overwritten on the next input update.
|
|
285
|
+
*/
|
|
286
|
+
setColor(path: string, color: string | number | RiveColor): void;
|
|
287
|
+
/**
|
|
288
|
+
* Get a color value from the ViewModel.
|
|
289
|
+
* Returns undefined if the property doesn't exist or ViewModel is not loaded.
|
|
290
|
+
*/
|
|
291
|
+
getColor(path: string): RiveColor | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Set a color value using RGBA components (0-255).
|
|
294
|
+
* Warning: If the property is controlled by dataBindings input, this change
|
|
295
|
+
* will be overwritten on the next input update.
|
|
296
|
+
*/
|
|
297
|
+
setColorRgba(path: string, r: number, g: number, b: number, a?: number): void;
|
|
298
|
+
/**
|
|
299
|
+
* Set the opacity of a color (0.0-1.0) while preserving RGB values.
|
|
300
|
+
* Warning: If the property is controlled by dataBindings input, this change
|
|
301
|
+
* will be overwritten on the next input update.
|
|
302
|
+
*/
|
|
303
|
+
setColorOpacity(path: string, opacity: number): void;
|
|
188
304
|
/**
|
|
189
305
|
* Apply all text runs from input (controlled keys).
|
|
190
306
|
* Called on every input change or load.
|
|
191
307
|
*/
|
|
192
308
|
private applyTextRuns;
|
|
309
|
+
/**
|
|
310
|
+
* Initialize ViewModel instance if available in the loaded file.
|
|
311
|
+
* Called once after animation loads successfully.
|
|
312
|
+
*/
|
|
313
|
+
private initializeViewModel;
|
|
314
|
+
/**
|
|
315
|
+
* Get list of available ViewModel names for error messages.
|
|
316
|
+
*/
|
|
317
|
+
private getAvailableViewModelNames;
|
|
318
|
+
/**
|
|
319
|
+
* Get ViewModel property information for debug logging.
|
|
320
|
+
*/
|
|
321
|
+
private getViewModelPropertyInfo;
|
|
322
|
+
/**
|
|
323
|
+
* Subscribe to ViewModel property changes for two-way data binding.
|
|
324
|
+
* Emits dataBindingChange output when properties change from within the animation.
|
|
325
|
+
*/
|
|
326
|
+
private subscribeToViewModelChanges;
|
|
327
|
+
/**
|
|
328
|
+
* Subscribe to changes for a specific ViewModel property.
|
|
329
|
+
* Uses multiple event APIs to maximize compatibility with @rive-app/canvas runtime versions.
|
|
330
|
+
*/
|
|
331
|
+
private subscribeToPropertyChanges;
|
|
332
|
+
private buildUnsubscribeFromHandler;
|
|
333
|
+
private withLocalMutation;
|
|
334
|
+
private shouldSuppressLocalMutation;
|
|
335
|
+
private readPropertyValue;
|
|
336
|
+
private normalizeViewModelPropertyType;
|
|
337
|
+
private resolveViewModelProperty;
|
|
338
|
+
private emitDataBindingTypeMismatch;
|
|
339
|
+
private cleanupViewModelSubscriptions;
|
|
340
|
+
/**
|
|
341
|
+
* Apply all data bindings from input (controlled keys).
|
|
342
|
+
* Called on every input change or load.
|
|
343
|
+
* Auto-detects property type from ViewModel and applies the value accordingly.
|
|
344
|
+
*/
|
|
345
|
+
private applyDataBindings;
|
|
346
|
+
/**
|
|
347
|
+
* Try to apply a binding value to a resolved ViewModel property.
|
|
348
|
+
* Returns true if successful, false on type mismatch.
|
|
349
|
+
*/
|
|
350
|
+
private tryApplyBinding;
|
|
193
351
|
/**
|
|
194
352
|
* Clean up Rive instance only
|
|
195
353
|
*/
|
|
196
354
|
private cleanupRive;
|
|
197
355
|
static ɵfac: _angular_core.ɵɵFactoryDeclaration<RiveCanvasComponent, never>;
|
|
198
|
-
static ɵcmp: _angular_core.ɵɵComponentDeclaration<RiveCanvasComponent, "rive-canvas", never, { "src": { "alias": "src"; "required": false; "isSignal": true; }; "buffer": { "alias": "buffer"; "required": false; "isSignal": true; }; "riveFile": { "alias": "riveFile"; "required": false; "isSignal": true; }; "artboard": { "alias": "artboard"; "required": false; "isSignal": true; }; "animations": { "alias": "animations"; "required": false; "isSignal": true; }; "stateMachines": { "alias": "stateMachines"; "required": false; "isSignal": true; }; "autoplay": { "alias": "autoplay"; "required": false; "isSignal": true; }; "fit": { "alias": "fit"; "required": false; "isSignal": true; }; "alignment": { "alias": "alignment"; "required": false; "isSignal": true; }; "useOffscreenRenderer": { "alias": "useOffscreenRenderer"; "required": false; "isSignal": true; }; "shouldUseIntersectionObserver": { "alias": "shouldUseIntersectionObserver"; "required": false; "isSignal": true; }; "shouldDisableRiveListeners": { "alias": "shouldDisableRiveListeners"; "required": false; "isSignal": true; }; "automaticallyHandleEvents": { "alias": "automaticallyHandleEvents"; "required": false; "isSignal": true; }; "debugMode": { "alias": "debugMode"; "required": false; "isSignal": true; }; "textRuns": { "alias": "textRuns"; "required": false; "isSignal": true; }; }, { "loaded": "loaded"; "loadError": "loadError"; "stateChange": "stateChange"; "riveEvent": "riveEvent"; "riveReady": "riveReady"; }, never, never, true, never>;
|
|
356
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<RiveCanvasComponent, "rive-canvas", never, { "src": { "alias": "src"; "required": false; "isSignal": true; }; "buffer": { "alias": "buffer"; "required": false; "isSignal": true; }; "riveFile": { "alias": "riveFile"; "required": false; "isSignal": true; }; "artboard": { "alias": "artboard"; "required": false; "isSignal": true; }; "animations": { "alias": "animations"; "required": false; "isSignal": true; }; "stateMachines": { "alias": "stateMachines"; "required": false; "isSignal": true; }; "autoplay": { "alias": "autoplay"; "required": false; "isSignal": true; }; "fit": { "alias": "fit"; "required": false; "isSignal": true; }; "alignment": { "alias": "alignment"; "required": false; "isSignal": true; }; "useOffscreenRenderer": { "alias": "useOffscreenRenderer"; "required": false; "isSignal": true; }; "shouldUseIntersectionObserver": { "alias": "shouldUseIntersectionObserver"; "required": false; "isSignal": true; }; "shouldDisableRiveListeners": { "alias": "shouldDisableRiveListeners"; "required": false; "isSignal": true; }; "automaticallyHandleEvents": { "alias": "automaticallyHandleEvents"; "required": false; "isSignal": true; }; "debugMode": { "alias": "debugMode"; "required": false; "isSignal": true; }; "textRuns": { "alias": "textRuns"; "required": false; "isSignal": true; }; "viewModelName": { "alias": "viewModelName"; "required": false; "isSignal": true; }; "dataBindings": { "alias": "dataBindings"; "required": false; "isSignal": true; }; }, { "loaded": "loaded"; "loadError": "loadError"; "stateChange": "stateChange"; "riveEvent": "riveEvent"; "riveReady": "riveReady"; "dataBindingChange": "dataBindingChange"; }, never, never, true, never>;
|
|
199
357
|
}
|
|
200
358
|
|
|
201
359
|
/**
|
|
@@ -291,6 +449,7 @@ declare class RiveFileService {
|
|
|
291
449
|
* - RIVE_1xx: Load errors (file not found, network, bad format)
|
|
292
450
|
* - RIVE_2xx: Validation errors (artboard, animation, state machine mismatch)
|
|
293
451
|
* - RIVE_3xx: Configuration/Usage errors (missing source, bad canvas)
|
|
452
|
+
* - RIVE_4xx: Data Binding errors (ViewModel, property not found, type mismatch)
|
|
294
453
|
*/
|
|
295
454
|
declare enum RiveErrorCode {
|
|
296
455
|
FileNotFound = "RIVE_101",
|
|
@@ -302,7 +461,10 @@ declare enum RiveErrorCode {
|
|
|
302
461
|
InputNotFound = "RIVE_204",
|
|
303
462
|
TextRunNotFound = "RIVE_205",
|
|
304
463
|
NoSource = "RIVE_301",
|
|
305
|
-
InvalidCanvas = "RIVE_302"
|
|
464
|
+
InvalidCanvas = "RIVE_302",
|
|
465
|
+
ViewModelNotFound = "RIVE_401",
|
|
466
|
+
DataBindingPropertyNotFound = "RIVE_402",
|
|
467
|
+
DataBindingTypeMismatch = "RIVE_403"
|
|
306
468
|
}
|
|
307
469
|
|
|
308
470
|
/**
|
|
@@ -331,6 +493,48 @@ interface RiveDebugConfig {
|
|
|
331
493
|
*/
|
|
332
494
|
declare function provideRiveDebug(config: RiveDebugConfig): Provider;
|
|
333
495
|
|
|
496
|
+
/**
|
|
497
|
+
* Parses various color input formats into a normalized RiveColor object.
|
|
498
|
+
*
|
|
499
|
+
* Supported formats:
|
|
500
|
+
* - Hex string: '#RRGGBB' or '#RRGGBBAA'
|
|
501
|
+
* - ARGB integer: 0xAARRGGBB (32-bit integer)
|
|
502
|
+
* - RiveColor object: { r, g, b, a? }
|
|
503
|
+
*
|
|
504
|
+
* @param input - Color in any supported format
|
|
505
|
+
* @returns Normalized RiveColor object with all components in 0-255 range
|
|
506
|
+
* @throws Error if the input format is invalid
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* parseRiveColor('#FF5733') // { r: 255, g: 87, b: 51, a: 255 }
|
|
510
|
+
* parseRiveColor('#FF573380') // { r: 255, g: 87, b: 51, a: 128 }
|
|
511
|
+
* parseRiveColor(0x80FF5733) // { r: 255, g: 87, b: 51, a: 128 }
|
|
512
|
+
* parseRiveColor({ r: 255, g: 0, b: 0 }) // { r: 255, g: 0, b: 0, a: 255 }
|
|
513
|
+
*/
|
|
514
|
+
declare function parseRiveColor(input: string | number | RiveColor): RiveColor;
|
|
515
|
+
/**
|
|
516
|
+
* Converts a RiveColor object to an ARGB 32-bit integer.
|
|
517
|
+
*
|
|
518
|
+
* @param color - RiveColor object
|
|
519
|
+
* @returns ARGB integer in format 0xAARRGGBB
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* riveColorToArgb({ r: 255, g: 0, b: 0, a: 255 }) // 0xFFFF0000
|
|
523
|
+
* riveColorToArgb({ r: 0, g: 128, b: 255, a: 128 }) // 0x800080FF
|
|
524
|
+
*/
|
|
525
|
+
declare function riveColorToArgb(color: RiveColor): number;
|
|
526
|
+
/**
|
|
527
|
+
* Converts a RiveColor object to a hex string.
|
|
528
|
+
*
|
|
529
|
+
* @param color - RiveColor object
|
|
530
|
+
* @returns Hex string in format '#RRGGBBAA'
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* riveColorToHex({ r: 255, g: 0, b: 0, a: 255 }) // '#FF0000FF'
|
|
534
|
+
* riveColorToHex({ r: 0, g: 128, b: 255, a: 128 }) // '#0080FF80'
|
|
535
|
+
*/
|
|
536
|
+
declare function riveColorToHex(color: RiveColor): string;
|
|
537
|
+
|
|
334
538
|
/**
|
|
335
539
|
* Options for constructing a RiveLoadError with detailed context.
|
|
336
540
|
*/
|
|
@@ -363,5 +567,5 @@ declare class RiveValidationError extends Error {
|
|
|
363
567
|
constructor(message: string, code: RiveErrorCode, availableOptions?: string[] | undefined, suggestion?: string | undefined);
|
|
364
568
|
}
|
|
365
569
|
|
|
366
|
-
export { RiveCanvasComponent, RiveErrorCode, RiveFileService, RiveLoadError, RiveValidationError, provideRiveDebug };
|
|
367
|
-
export type { FileStatus, LogLevel, RiveDebugConfig, RiveErrorOptions, RiveFileParams, RiveFileState };
|
|
570
|
+
export { RiveCanvasComponent, RiveErrorCode, RiveFileService, RiveLoadError, RiveValidationError, parseRiveColor, provideRiveDebug, riveColorToArgb, riveColorToHex };
|
|
571
|
+
export type { DataBindingChangeEvent, DataBindingPropertyType, DataBindingValue, FileStatus, LogLevel, RiveColor, RiveDebugConfig, RiveErrorOptions, RiveFileParams, RiveFileState };
|