Rive JS API
What It Would Look Like
1. Global Rive Manager (similar to MediaPlayerManager)
// RiveManager.ts
class RiveManager {
private instances: Map<string, any> = new Map();
register(id: string, riveInstance: any) {
this.instances.set(id, riveInstance);
}
unregister(id: string) {
this.instances.delete(id);
}
// Artboard control
setArtboard(id: string, artboardName: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
try {
instance.artboard = artboardName;
return true;
} catch (error) {
console.error(`Failed to set artboard for ${id}:`, error);
return false;
}
}
// State machine control
setStateMachine(id: string, stateMachineName: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
try {
instance.stateMachineName = stateMachineName;
return true;
} catch (error) {
console.error(`Failed to set state machine for ${id}:`, error);
return false;
}
}
// Input control (the powerful one)
setInput(id: string, inputName: string, value: number | boolean): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
try {
const input = instance.stateMachineInputs(instance.stateMachineName)
?.find((i: any) => i.name === inputName);
if (!input) {
console.warn(`Input "${inputName}" not found`);
return false;
}
input.value = value;
return true;
} catch (error) {
console.error(`Failed to set input for ${id}:`, error);
return false;
}
}
// Trigger control
fireTrigger(id: string, triggerName: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
try {
const trigger = instance.stateMachineInputs(instance.stateMachineName)
?.find((i: any) => i.name === triggerName && i.type === 'trigger');
if (!trigger) return false;
trigger.fire();
return true;
} catch (error) {
console.error(`Failed to fire trigger for ${id}:`, error);
return false;
}
}
// Playback control
play(id: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
instance.play();
return true;
}
pause(id: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
instance.pause();
return true;
}
reset(id: string): boolean {
const instance = this.instances.get(id);
if (!instance) return false;
instance.reset();
return true;
}
// Utility
getInstanceIds(): string[] {
return Array.from(this.instances.keys());
}
getInstance(id: string): any | null {
return this.instances.get(id) || null;
}
}
// Global singleton
export const riveManager = new RiveManager();
// Add to window for external access
declare global {
interface Window {
riveManager: RiveManager;
}
}
if (typeof window !== 'undefined') {
window.riveManager = riveManager;
}2. Updated Component (RiveWebGL2.tsx)
3. Webflow Props Declaration
Usage Examples
In Webflow Designer:
External JavaScript Control:
Event-Driven Example:
Real-World Use Cases
Advanced: Type-Safe API
Key Considerations
Last updated