--- name: example-svelte description: Patterns for using Helios with Svelte. Use when building compositions in a Svelte environment, utilizing Svelte stores for reactive frame updates. --- # Svelte Composition Patterns Integrate Helios into Svelte components using Svelte Stores to manage frame state reactivity efficiently. ## Quick Start ### 1. Create Helios Store Wrap the Helios instance in a readable store to make state reactive. ```javascript // lib/store.js import { readable } from 'svelte/store'; export const createHeliosStore = (helios) => { return readable(helios.getState(), (set) => { // Set initial value set(helios.getState()); // Subscribe to updates const unsubscribe = helios.subscribe((state) => { set(state); }); return unsubscribe; }); }; ``` ### 2. Create Composition Component ```svelte ``` ## Svelte 5 (Runes) For Svelte 5, use the `$state` rune to create a reactive state class. ### 1. Create Helios State Class ```javascript // lib/helios.svelte.ts import { Helios } from '@helios-project/core'; export class HeliosState { currentFrame = $state(0); fps = $state(0); duration = $state(0); isPlaying = $state(false); constructor(helios) { this.fps = helios.fps; this.duration = helios.duration; this.isPlaying = helios.isPlaying; helios.subscribe((state) => { this.currentFrame = state.currentFrame; this.isPlaying = state.isPlaying; }); } } ``` ### 2. Use in Component ```svelte