/** * Dailymotion Pro – Shared Preview Core (PLS-based) * * Centralizes preview logic for Dailymotion admin interfaces: * - PLS (Player Library Script) loading/unloading * - Player instance lifecycle (create/destroy) * - Per-scope state management * - DOM-based heading/title styling and player rendering * * Used by: * - Video Embed adapter (`src/Admin/VideoEmbed/Preview.ts`) * - Setup Wizard adapter (`src/Admin/SetupWizard/PreviewSettings.ts`) */ import { extractFontFamily, qs, replaceTagKeepAttrs } from '../../Libs/Utils'; export type ScopeId = string; /** * DOM selectors configuration for a preview scope. * Supports static strings or functions that return strings (for dynamic IDs). */ export interface PreviewDomSelectors { containerId: string | (() => string); headingId: string | (() => string); titleId: string | (() => string); playerId: string | (() => string); playerSelectId: string | (() => string); headingToggleId: string | (() => string); headingTextId: string | (() => string); headingFontId: string | (() => string); headingSizeId: string | (() => string); titleToggleId: string | (() => string); titleFontId: string | (() => string); titleSizeId: string | (() => string); muteId: string | (() => string); activeLabelSelector?: string; extraActiveLabelSelector?: string; } /** * Optional hooks to customize scope behavior. */ export interface ScopeBehaviorHooks { isScopeEnabled?: () => boolean; isHeadingEnabled?: () => boolean; isTitleEnabled?: () => boolean; getVideoId?: () => string; onAfterPlayerCreated?: (scope: ScopeId) => void; } /** * Configuration for a preview scope. */ export interface ScopeConfig { id: ScopeId; selectors: PreviewDomSelectors; hooks?: ScopeBehaviorHooks; } /** * Public API returned by initPreviewCore. */ export interface PreviewApi { updateScope(scopeId: ScopeId): void; teardown(scope?: ScopeId | 'all'): Promise; attachListeners(scopeId: ScopeId, elementIds: string[]): void; } /** * Helper to resolve a selector (string or function). */ function resolveSelector(selector: string | (() => string)): string { return typeof selector === 'function' ? selector() : selector; } /** * Global cache of PLS loader promises, keyed by playerId. * Ensures we don't inject duplicate