/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function u(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}c((r=r.apply(e,t||[])).next())}))}function t(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var n=function(e){};function r(e){n(e)}function o(e){n=e}(function(){(console.warn||console.log).apply(console,arguments)}).bind("[clipboard-polyfill]");var i,a,u,c,l="undefined"==typeof navigator?void 0:navigator,d=null==l?void 0:l.clipboard,s=(null===(i=null==d?void 0:d.read)||void 0===i||i.bind(d),null===(a=null==d?void 0:d.readText)||void 0===a?void 0:a.bind(d)),f=(null===(u=null==d?void 0:d.write)||void 0===u||u.bind(d),null===(c=null==d?void 0:d.writeText)||void 0===c?void 0:c.bind(d)),p="undefined"==typeof window?void 0:window,v=(null==p||p.ClipboardItem,p);function b(){return"undefined"==typeof ClipboardEvent&&void 0!==v.clipboardData&&void 0!==v.clipboardData.setData}function y(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){if(""===(e=v.clipboardData.getData("Text")))throw new Error("Empty clipboard or could not read plain text from clipboard");return[2,e]}))}))}var m=function(){this.success=!1};function h(e,t,n){for(var o in r("listener called"),e.success=!0,t){var i=t[o],a=n.clipboardData;a.setData(o,i),"text/plain"===o&&a.getData(o)!==i&&(r("setting text/plain failed"),e.success=!1)}n.preventDefault()}function w(e){var t=new m,n=h.bind(this,t,e);document.addEventListener("copy",n);try{document.execCommand("copy")}finally{document.removeEventListener("copy",n)}return t.success}function g(e,t){x(e);var n=w(t);return E(),n}function x(e){var t=document.getSelection();if(t){var n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}}function E(){var e=document.getSelection();e&&e.removeAllRanges()}function D(n){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){if(e="text/plain"in n,b()){if(!e)throw new Error("No `text/plain` value was specified.");if(o=n["text/plain"],v.clipboardData.setData("Text",o))return[2,!0];throw new Error("Copying failed, possibly because the user rejected it.")}var o;return w(n)?(r("regular execCopy worked"),[2,!0]):navigator.userAgent.indexOf("Edge")>-1?(r('UA "Edge" => assuming success'),[2,!0]):g(document.body,n)?(r("copyUsingTempSelection worked"),[2,!0]):function(e){var t=document.createElement("div");t.setAttribute("style","-webkit-user-select: text !important"),t.textContent="temporary element",document.body.appendChild(t);var n=g(t,e);return document.body.removeChild(t),n}(n)?(r("copyUsingTempElem worked"),[2,!0]):function(e){r("copyTextUsingDOM");var t=document.createElement("div");t.setAttribute("style","-webkit-user-select: text !important");var n=t;t.attachShadow&&(r("Using shadow DOM."),n=t.attachShadow({mode:"open"}));var o=document.createElement("span");o.innerText=e,n.appendChild(o),document.body.appendChild(t),x(o);var i=document.execCommand("copy");return E(),document.body.removeChild(t),i}(n["text/plain"])?(r("copyTextUsingDOM worked"),[2,!0]):[2,!1]}))}))}function C(n){return e(this,void 0,void 0,(function(){return t(this,(function(e){if(f)return r("Using `navigator.clipboard.writeText()`."),[2,f(n)];if(!D(function(e){var t={};return t["text/plain"]=e,t}(n)))throw new Error("writeText() failed");return[2]}))}))}function T(){return e(this,void 0,void 0,(function(){return t(this,(function(e){if(s)return r("Using `navigator.clipboard.readText()`."),[2,s()];if(b())return r("Reading text using IE strategy."),[2,y()];throw new Error("Read is not supported in your browser.")}))}))}export{T as readText,o as setDebugLog,C as writeText};
//# sourceMappingURL=clipboard-polyfill.text.esm.js.map
