import ClipboardJS from 'clipboard' ; import rootConfig from '@root/src/shared/config' ; export const canUseDom = ( ) => { return ! ! ( typeof window !== 'undefined' && window . document && window . document . createElement ) ; } ; export const setTitle = ( val ? ) => { return val || rootConfig . head . title ; } ; export const setKeywords = ( val ? ) => { return val || rootConfig . head . meta . keywords ; } ; export const setDescription = ( val ? ) => { return val || rootConfig . head . meta . description ; } ; export const headCore = { setTitle , setKeywords , setDescription } ; export const copyTextByDom = ( selector , { success , deep = false , error } ) => { let clipboard ; if ( deep ) { clipboard = new ClipboardJS ( `.${ selector }` , { text : ( el ) => { let div = el . parentNode . cloneNode ( true ) ; div . style . display = 'none' ; div . style . opacity = 0 ; div . style . whiteSpace = 'pre-wrap' ; div . children . forEach ( ( node ) => { if ( node . className === selector ) { div . removeChild ( node ) ; } } ) ; const text = div . innerText ; div = null ; return text ; } } ) ; } else { clipboard = new ClipboardJS ( `.${ selector }` , { text : ( el ) => { return el . innerText ; } } ) ; } clipboard . on ( 'success' , success ) ; clipboard . on ( 'error' , ( e ) => { error && error ( e ) ; } ) ; } ;