license import { Support , Supported } from '../../defs/lib.js' ; import { fire } from '../utils/fire.js' ; export class DeviceSupport { static supportsEvent = 'supports' ; useEvents = false ; private detectors = new Map < string , Supported > ( ) ; addDetector ( detector ) { const { name , supported } = detector ; if ( this . detectors . has ( name ) ) { throw new Error ( `${ name } already added` ) ; } this . detectors . set ( name , supported ) ; } removeDetector ( name ) { this . detectors . delete ( name ) ; } async detect ( ) { const support = { } ; for ( const [ name , detector ] of this . detectors ) { support [ name ] = await detector ( ) ; } if ( this . useEvents ) { fire ( DeviceSupport . supportsEvent , self , support ) ; } return support ; } }