const e=require("./toggle-selection.js");var t={"text/plain":`Text`,"text/html":`Url`,default:`Text`},n=`Copy to clipboard: #{key}, Enter`;function r(e){let t=`${/mac os x/i.test(navigator.userAgent)?`⌘`:`Ctrl`}+C`;return e.replace(/#\{\s*key\s*\}/g,t)}function i(i,a){let o,s,c,l,u,d=!1;a||(a={});let f=a.debug||!1;try{if(s=e.default(),c=document.createRange(),l=document.getSelection(),u=document.createElement(`span`),u.textContent=i,u.style.all=`unset`,u.style.position=`fixed`,u.style.top=0,u.style.clip=`rect(0, 0, 0, 0)`,u.style.whiteSpace=`pre`,u.style.webkitUserSelect=`text`,u.style.MozUserSelect=`text`,u.style.msUserSelect=`text`,u.style.userSelect=`text`,u.addEventListener(`copy`,e=>{if(e.stopPropagation(),a.format)if(e.preventDefault(),e.clipboardData===void 0){f&&console.warn(`unable to use e.clipboardData`),f&&console.warn(`trying IE specific stuff`),window.clipboardData.clearData();let e=t[a.format]||t.default;window.clipboardData.setData(e,i)}else e.clipboardData.clearData(),e.clipboardData.setData(a.format,i);a.onCopy&&(e.preventDefault(),a.onCopy(e.clipboardData))}),document.body.appendChild(u),c.selectNodeContents(u),l.addRange(c),!document.execCommand(`copy`))throw Error(`copy command was unsuccessful`);d=!0}catch(e){f&&console.error(`unable to copy using execCommand: `,e),f&&console.warn(`trying IE specific stuff`);try{window.clipboardData.setData(a.format||`text`,i),a.onCopy&&a.onCopy(window.clipboardData),d=!0}catch(e){f&&console.error(`unable to copy using clipboardData: `,e),f&&console.error(`falling back to prompt`),o=r(`message`in a?a.message:n),window.prompt(o,i)}}finally{l&&(typeof l.removeRange==`function`?l.removeRange(c):l.removeAllRanges()),u&&document.body.removeChild(u),s()}return d}exports.default=i;