import { ComponentPublicInstance , h } from 'vue' ; export function define ( tagName , clazz ) { const isClient = typeof window !== 'undefined' ; if ( isClient && ! customElements . get ( tagName ) ) customElements . define ( tagName , clazz ) ; } export function method ( name ) { return function proxy ( this , ... args ) { return this . $refs . ref [ name ] ( ... args ) ; } ; } function listen ( node , event , handler ) { node . addEventListener ( event , handler ) ; return ( ) => { node . removeEventListener ( event , handler ) ; } ; } export function render ( tagName , events ) { return function proxy ( this ) { let dispose = [ ] ; const forwardEvent = ( event ) => ( $event ) => { const { detail } = $event ; this . $emit ( event , detail ) ; } ; return h ( tagName , { ref : 'ref' , ... this . $props , onVnodeMounted ( vnode ) { events . forEach ( event => { dispose . push ( listen ( vnode . el ! as HTMLElement , event , forwardEvent ( event ) ) ) ; } ) ; } , onVnodeBeforeUnmount ( ) { dispose . forEach ( fn => fn ( ) ) ; dispose = [ ] ; } , } , this . $slots . default ?. ( ) ) ; } ; }