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