import Canvas2d from './canvas2d' ; export default class DocumentEx { static events = { } ; constructor ( ) { } public static createElement ( name ) { return { tag : name , getContext : DocumentEx . getContext } ; } public static getContext ( contextName ) { if ( contextName === '2d' ) { return new Canvas2d ( ) ; } throw new Error ( 'Context ' + contextName + ' is not supported.' ) ; } public static addEventListener ( eventName , cb , flag ) { let listeners = this . events [ eventName ] ; if ( ! listeners ) { listeners = [ ] ; this . events [ eventName ] = listeners ; } listeners . push ( cb ) ; } public static removeEventListener ( eventName , cb ) { const listeners = this . events [ eventName ] ; if ( listeners ) { listeners . remove ( cb ) ; } } }