import { DEFAULT_PLUGIN_OPTIONS , IVWaveDirectiveOptions , IVWavePluginOptions } from './options' ; import { getHooks } from './utils/hookKeys' ; import { wave } from './wave' ; import { App } from 'vue' ; const optionMap = new WeakMap < HTMLElement , Partial < IVWaveDirectiveOptions > | false > ( ) ; interface VWaveInstallObject { install : ( app : any , globalUserOptions : Partial < IVWavePluginOptions > ) => void ; installed : boolean ; } const VWave = { install ( app , globalUserOptions = { } ) { if ( this . installed ) return ; this . installed = true ; const globalOptions = { ... DEFAULT_PLUGIN_OPTIONS , ... globalUserOptions } ; const hooks = getHooks ( app ) ; app . directive ( globalOptions . directive , { [ hooks . mounted ] ( el , { value } ) { optionMap . set ( el , value ?? { } ) ; el . addEventListener ( 'pointerdown' , ( event ) => { const options = optionMap . get ( el ) ! ; if ( options === false ) return ; wave ( event , el , { ... globalOptions , ... options } ) ; } ) ; } , [ hooks . updated ] ( el , { value } ) { optionMap . set ( el , value ?? { } ) ; } } ) ; } , installed : false } ; export default VWave ;