storybook-prebuilt
Version:
A prebuilt storybook version for web components
3 lines (2 loc) • 1.79 kB
JavaScript
var e=function(e,t){var o,n,a,r,c,s,l=!1;t||(t={}),o=t.debug||!1;try{if(a=function(){var e=document.getSelection();if(!e.rangeCount)return function(){};for(var t=document.activeElement,o=[],n=0;n<e.rangeCount;n++)o.push(e.getRangeAt(n));switch(t.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":t.blur();break;default:t=null}return e.removeAllRanges(),function(){"Caret"===e.type&&e.removeAllRanges(),e.rangeCount||o.forEach((function(t){e.addRange(t)})),t&&t.focus()}}(),r=document.createRange(),c=document.getSelection(),(s=document.createElement("span")).textContent=e,s.style.all="unset",s.style.position="fixed",s.style.top=0,s.style.clip="rect(0, 0, 0, 0)",s.style.whiteSpace="pre",s.style.webkitUserSelect="text",s.style.MozUserSelect="text",s.style.msUserSelect="text",s.style.userSelect="text",s.addEventListener("copy",(function(o){o.stopPropagation(),t.format&&(o.preventDefault(),o.clipboardData.clearData(),o.clipboardData.setData(t.format,e))})),document.body.appendChild(s),r.selectNodeContents(s),c.addRange(r),!document.execCommand("copy"))throw new Error("copy command was unsuccessful");l=!0}catch(a){o&&console.error("unable to copy using execCommand: ",a),o&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(t.format||"text",e),l=!0}catch(a){o&&console.error("unable to copy using clipboardData: ",a),o&&console.error("falling back to prompt"),n=function(e){var t=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return e.replace(/#{\s*key\s*}/g,t)}("message"in t?t.message:"Copy to clipboard: #{key}, Enter"),window.prompt(n,e)}}finally{c&&("function"==typeof c.removeRange?c.removeRange(r):c.removeAllRanges()),s&&document.body.removeChild(s),a()}return l};export{e as r};
//# sourceMappingURL=storybook-prebuilt-1188e5c0.js.map