@grandgular/rive-angular 0.2.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
@@ -66,6 +103,37 @@ declare class RiveCanvasComponent implements AfterViewInit {
66
103
  * - false/undefined: use global level
67
104
  */
68
105
  readonly debugMode: _angular_core.InputSignal<boolean | undefined>;
106
+ /**
107
+ * Record of text run names to values for declarative text setting.
108
+ * Keys present in this input are CONTROLLED — the input is the source of truth.
109
+ * Keys absent from this input are UNCONTROLLED — managed imperatively.
110
+ * Values are applied reactively when input changes.
111
+ */
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>;
69
137
  readonly loaded: _angular_core.OutputEmitterRef<void>;
70
138
  readonly loadError: _angular_core.OutputEmitterRef<Error>;
71
139
  /**
@@ -84,6 +152,12 @@ declare class RiveCanvasComponent implements AfterViewInit {
84
152
  * Note: This fires AFTER the animation is loaded, not just instantiated.
85
153
  */
86
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>;
87
161
  readonly isPlaying: _angular_core.Signal<boolean>;
88
162
  readonly isPaused: _angular_core.Signal<boolean>;
89
163
  readonly isLoaded: _angular_core.Signal<boolean>;
@@ -92,6 +166,12 @@ declare class RiveCanvasComponent implements AfterViewInit {
92
166
  * Use this to access advanced Rive SDK features.
93
167
  */
94
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>;
95
175
  private readonly logger;
96
176
  private resizeObserver;
97
177
  private isInitialized;
@@ -157,12 +237,123 @@ declare class RiveCanvasComponent implements AfterViewInit {
157
237
  * Fire a state machine trigger
158
238
  */
159
239
  fireTrigger(stateMachineName: string, triggerName: string): void;
240
+ /**
241
+ * Get the current value of a text run.
242
+ * Returns undefined if the text run doesn't exist or Rive instance is not loaded.
243
+ */
244
+ getTextRunValue(textRunName: string): string | undefined;
245
+ /**
246
+ * Set a text run value.
247
+ * Warning: If the text run is controlled by textRuns input, this change will be overwritten
248
+ * on the next input update.
249
+ */
250
+ setTextRunValue(textRunName: string, textRunValue: string): void;
251
+ /**
252
+ * Get the current value of a text run at a specific path (for nested artboards/components).
253
+ * Returns undefined if the text run doesn't exist or Rive instance is not loaded.
254
+ */
255
+ getTextRunValueAtPath(textRunName: string, path: string): string | undefined;
256
+ /**
257
+ * Set a text run value at a specific path (for nested artboards/components).
258
+ * Note: AtPath text runs are always uncontrolled (not managed by textRuns input).
259
+ */
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;
304
+ /**
305
+ * Apply all text runs from input (controlled keys).
306
+ * Called on every input change or load.
307
+ */
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;
160
351
  /**
161
352
  * Clean up Rive instance only
162
353
  */
163
354
  private cleanupRive;
164
355
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<RiveCanvasComponent, never>;
165
- 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; }; }, { "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>;
166
357
  }
167
358
 
168
359
  /**
@@ -258,6 +449,7 @@ declare class RiveFileService {
258
449
  * - RIVE_1xx: Load errors (file not found, network, bad format)
259
450
  * - RIVE_2xx: Validation errors (artboard, animation, state machine mismatch)
260
451
  * - RIVE_3xx: Configuration/Usage errors (missing source, bad canvas)
452
+ * - RIVE_4xx: Data Binding errors (ViewModel, property not found, type mismatch)
261
453
  */
262
454
  declare enum RiveErrorCode {
263
455
  FileNotFound = "RIVE_101",
@@ -267,8 +459,12 @@ declare enum RiveErrorCode {
267
459
  AnimationNotFound = "RIVE_202",
268
460
  StateMachineNotFound = "RIVE_203",
269
461
  InputNotFound = "RIVE_204",
462
+ TextRunNotFound = "RIVE_205",
270
463
  NoSource = "RIVE_301",
271
- InvalidCanvas = "RIVE_302"
464
+ InvalidCanvas = "RIVE_302",
465
+ ViewModelNotFound = "RIVE_401",
466
+ DataBindingPropertyNotFound = "RIVE_402",
467
+ DataBindingTypeMismatch = "RIVE_403"
272
468
  }
273
469
 
274
470
  /**
@@ -297,6 +493,48 @@ interface RiveDebugConfig {
297
493
  */
298
494
  declare function provideRiveDebug(config: RiveDebugConfig): Provider;
299
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
+
300
538
  /**
301
539
  * Options for constructing a RiveLoadError with detailed context.
302
540
  */
@@ -329,5 +567,5 @@ declare class RiveValidationError extends Error {
329
567
  constructor(message: string, code: RiveErrorCode, availableOptions?: string[] | undefined, suggestion?: string | undefined);
330
568
  }
331
569
 
332
- export { RiveCanvasComponent, RiveErrorCode, RiveFileService, RiveLoadError, RiveValidationError, provideRiveDebug };
333
- 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 };