UNPKG

saltfish

Version:

An interactive video-guided tour system for web applications

167 lines 6.33 kB
import type { PlaylistPathInfo } from '../types'; /** * Manages playlist triggers for playlists with hasTriggers enabled * Evaluates trigger conditions and launches playlists automatically */ export declare class TriggerManager { private triggeredPlaylists; private triggeredPlaylistsSet; private isMonitoring; private elementClickedListeners; private clickedElements; private elementVisibleObservers; private visibleElements; constructor(); /** * Registers playlists with triggers and their trigger configurations * @param playlists - List of all playlists from backend */ registerTriggers(playlists: PlaylistPathInfo[]): void; /** * Starts monitoring for trigger conditions */ startMonitoring(): void; /** * Stops monitoring for trigger conditions */ stopMonitoring(): void; /** * Evaluates all registered triggers against current conditions * Called by TransitionManager when URL changes occur * Stops after the first playlist is triggered to prevent multiple playlists from conflicting */ evaluateAllTriggers(): void; /** * Evaluates triggers for a specific playlist * @param playlist - The playlist to evaluate triggers for * @returns true if the playlist was triggered, false otherwise */ private evaluatePlaylistTrigger; /** * Gets watched playlists from backend userData or localStorage (for anonymous users) * @returns WatchedPlaylists object */ private getWatchedPlaylists; /** * Evaluates the 'maxVisits' condition for a playlist * @param maxVisits - Maximum number of times user can see this playlist (null = unlimited) * @param playlistId - The playlist ID to check * @param watchedPlaylists - User's watched playlists data */ private evaluateMaxVisitsCondition; /** * Normalizes a URL by removing trailing slash (unless it's the root path) * @param url - The URL to normalize */ private normalizeUrl; /** * Evaluates the URL condition for a playlist * @param triggers - The trigger configuration containing URL pattern and match type */ private evaluateURLCondition; /** * Evaluates the playlistSeen condition * User must have seen ALL specified playlists * @param requiredPlaylists - Array of playlist IDs that user must have seen * @param watchedPlaylists - User's watched playlists data */ private evaluatePlaylistSeenCondition; /** * Evaluates the playlistNotSeen condition * User must NOT have seen ANY of the specified playlists * @param forbiddenPlaylists - Array of playlist IDs that user must not have seen * @param watchedPlaylists - User's watched playlists data */ private evaluatePlaylistNotSeenCondition; /** * Evaluates the elementClicked condition for a playlist * @param selector - CSS selector for element that should trigger the playlist (null = no element condition) */ private evaluateElementClickCondition; /** * Evaluates the elementVisible condition for a playlist * @param selector - CSS selector for element that should trigger the playlist when visible (null = no element condition) */ private evaluateElementVisibleCondition; /** * Evaluates user attribute conditions for a playlist * All conditions must be met (AND logic) * @param conditions - Array of user attribute conditions to evaluate */ private evaluateUserAttributesCondition; /** * Compares two values based on attribute type and operator * @param userValue - The user's actual value * @param expectedValue - The expected value from trigger condition (always a string) * @param attributeType - The data type for comparison * @param operator - The comparison operator */ private compareValues; /** * Applies the comparison operator to two values */ private applyOperator; /** * Sets up click event listeners for all playlists with elementClicked triggers */ private setupElementClickListeners; /** * Sets up a click event listener for a specific playlist and selector * @param playlistId - The playlist ID * @param selector - CSS selector for the target element * @param expectedElement - Optional expected tag+text for validation * @param expectedSize - Optional expected size for validation */ private setupElementClickListener; /** * Clears all element click event listeners */ private clearElementClickListeners; /** * Sets up visibility observers for all playlists with elementVisible triggers */ private setupElementVisibleObservers; /** * Sets up a visibility observer for a specific playlist and selector * @param playlistId - The playlist ID * @param selector - CSS selector for the target element * @param expectedElement - Optional expected tag+text for validation * @param expectedSize - Optional expected size for validation */ private setupElementVisibleObserver; /** * Clears all element visibility observers */ private clearElementVisibleObservers; /** * Applies logical operators to combine multiple conditions * @param conditions - Array of boolean conditions to combine * @param operators - Array of operators ("AND" or "OR") */ private applyOperators; /** * Triggers a playlist to start * @param playlistId - ID of the playlist to trigger */ private triggerPlaylist; /** * Resets the triggered playlists tracking * Useful for testing or when user context changes */ resetTriggeredPlaylists(): void; /** * Gets list of playlists that have been triggered this session */ getTriggeredPlaylists(): string[]; /** * Marks a playlist as triggered to prevent re-triggering during URL changes * This should be called when a playlist is started programmatically * @param playlistId - The playlist ID to mark as triggered */ markPlaylistAsTriggered(playlistId: string): void; /** * Cleanup method to be called on destroy */ destroy(): void; } //# sourceMappingURL=TriggerManager.d.ts.map