/** * dynamically map a name to an adapter and call instantiate it * * author: db123 at db * creation: 29/4/2026 */ import { AdapterAPI } from '../types'; import { AdapterConfig } from '../types/AdapterAPI'; type AdapterConstructor = new ( video: HTMLVideoElement, options?: AdapterConfig ) => AdapterAPI; export class AdapterRegistry { private adapters: Map = new Map(); registerAdapter(type: string, constructor: AdapterConstructor): void { this.adapters.set(type, constructor); } createAdapter( type: string, video: HTMLVideoElement, options?: AdapterConfig ): AdapterAPI { if (!this.adapters.has(type)) { throw new Error('Adapter not found in registry.' + type); } const construct = this.adapters.get(type); if (!construct) { throw new Error('Adapter does not have constructor.' + type); } return new construct(video, options); } }