UNPKG

1.4 kBJavaScriptView Raw
1/**
2 * Bundle of @livelybone/copy
3 * Generated: 2020-05-30
4 * Version: 2.6.5
5 * License: MIT
6 * Author: 2631541504@qq.com
7 */
8
9!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).copyText=t()}(this,function(){"use strict";return function(r){return new Promise(function(e,n){if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(r).then(function(){return e(!0)}).catch(function(e){var t=new Error(e.message?"copyText failed, reason: ".concat(e.message):"copyText failed");n(t)});else{var t=document.createElement("span");t.style.position="fixed",t.style.left="0",t.style.top="0",t.style.zIndex="-999",t.innerText=r,document.body.appendChild(t);var o=function(e,t){var n,o,r=Object.assign({},{clearSelect:!1,cut:!1},t),c=r.clearSelect,i=r.cut;if(window.getSelection){if(!(o=window.getSelection()))return console.error("copyDom: window.getSelection() return null"),!1;n=window.document.createRange(),o.removeAllRanges(),n.selectNode(e),o.addRange(n)}else{var a=document.body.createTextRange;a&&((n=a()).moveToElementText(e),n.select())}var l=document.execCommand("copy");return o&&c&&o.removeAllRanges(),i&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.value="":e.innerHTML=""),l}(t);document.body.removeChild(t),o?e(o):n(new Error("copyText failed"))}})}});