/*! *****************************************************************************
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 t(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}c((r=r.apply(t,e||[])).next())}))}function e(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}var n=function(t){};function r(t){n(t)}function i(t){n=t}var o=!0;function a(){o=!1}function u(){return o}(function(){(console.warn||console.log).apply(console,arguments)}).bind("[clipboard-polyfill]");var c,s,l,d,f="undefined"==typeof navigator?void 0:navigator,p=null==f?void 0:f.clipboard,v=null===(c=null==p?void 0:p.read)||void 0===c?void 0:c.bind(p),h=null===(s=null==p?void 0:p.readText)||void 0===s?void 0:s.bind(p),y=null===(l=null==p?void 0:p.write)||void 0===l?void 0:l.bind(p),b=null===(d=null==p?void 0:p.writeText)||void 0===d?void 0:d.bind(p),w="undefined"==typeof window?void 0:window,m=null==w?void 0:w.ClipboardItem,g=w;function x(){return"undefined"==typeof ClipboardEvent&&void 0!==g.clipboardData&&void 0!==g.clipboardData.setData}function E(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){if(""===(t=g.clipboardData.getData("Text")))throw new Error("Empty clipboard or could not read plain text from clipboard");return[2,t]}))}))}var T=function(){this.success=!1};function C(t,e,n){for(var i in r("listener called"),t.success=!0,e){var o=e[i],a=n.clipboardData;a.setData(i,o),"text/plain"===i&&a.getData(i)!==o&&(r("setting text/plain failed"),t.success=!1)}n.preventDefault()}function D(t){var e=new T,n=C.bind(this,e,t);document.addEventListener("copy",n);try{document.execCommand("copy")}finally{document.removeEventListener("copy",n)}return e.success}function S(t,e){k(t);var n=D(e);return U(),n}function k(t){var e=document.getSelection();if(e){var n=document.createRange();n.selectNodeContents(t),e.removeAllRanges(),e.addRange(n)}}function U(){var t=document.getSelection();t&&t.removeAllRanges()}function A(n){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){if(t="text/plain"in n,x()){if(!t)throw new Error("No `text/plain` value was specified.");if(i=n["text/plain"],g.clipboardData.setData("Text",i))return[2,!0];throw new Error("Copying failed, possibly because the user rejected it.")}var i;return D(n)?(r("regular execCopy worked"),[2,!0]):navigator.userAgent.indexOf("Edge")>-1?(r('UA "Edge" => assuming success'),[2,!0]):S(document.body,n)?(r("copyUsingTempSelection worked"),[2,!0]):function(t){var e=document.createElement("div");e.setAttribute("style","-webkit-user-select: text !important"),e.textContent="temporary element",document.body.appendChild(e);var n=S(e,t);return document.body.removeChild(e),n}(n)?(r("copyUsingTempElem worked"),[2,!0]):function(t){r("copyTextUsingDOM");var e=document.createElement("div");e.setAttribute("style","-webkit-user-select: text !important");var n=e;e.attachShadow&&(r("Using shadow DOM."),n=e.attachShadow({mode:"open"}));var i=document.createElement("span");i.innerText=t,n.appendChild(i),document.body.appendChild(e),k(i);var o=document.execCommand("copy");return U(),document.body.removeChild(e),o}(n["text/plain"])?(r("copyTextUsingDOM worked"),[2,!0]):[2,!1]}))}))}function O(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){if(b)return r("Using `navigator.clipboard.writeText()`."),[2,b(n)];if(!A(function(t){var e={};return e["text/plain"]=t,e}(n)))throw new Error("writeText() failed");return[2]}))}))}function R(){return t(this,void 0,void 0,(function(){return e(this,(function(t){if(h)return r("Using `navigator.clipboard.readText()`."),[2,h()];if(x())return r("Reading text using IE strategy."),[2,E()];throw new Error("Read is not supported in your browser.")}))}))}function I(t,e){for(var n=0,r=t;n<r.length;n++){if(-1!==r[n].types.indexOf(e))return!0}return!1}var L=function(){function n(t,e){var n;for(var r in void 0===e&&(e={}),this.types=Object.keys(t),this._items={},t){var i=t[r];this._items[r]="string"==typeof i?M(r,i):i}this.presentationStyle=null!==(n=null==e?void 0:e.presentationStyle)&&void 0!==n?n:"unspecified"}return n.prototype.getType=function(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,this._items[n]]}))}))},n}();function M(t,e){return new Blob([e],{type:t})}function P(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,new Promise((function(t,e){var r=new FileReader;r.addEventListener("load",(function(){var n=r.result;"string"==typeof n?t(n):e("could not convert blob to string")})),r.readAsText(n)}))]}))}))}function _(n){return t(this,void 0,void 0,(function(){var t,r,i,o,a,u,c;return e(this,(function(e){switch(e.label){case 0:t={},r=0,i=n.types,e.label=1;case 1:return r<i.length?(o=i[r],a=t,u=o,[4,n.getType(o)]):[3,4];case 2:a[u]=e.sent(),e.label=3;case 3:return r++,[3,1];case 4:return c={},n.presentationStyle&&(c.presentationStyle=n.presentationStyle),[2,new m(t,c)]}}))}))}function j(t){var e={};return e["text/plain"]=M(t,"text/plain"),new L(e)}function N(n,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getType(r)];case 1:return[4,P(t.sent())];case 2:return[2,t.sent()]}}))}))}function B(n){return t(this,void 0,void 0,(function(){var t,r,i,o,a,u;return e(this,(function(e){switch(e.label){case 0:t={},r=0,i=n.types,e.label=1;case 1:return r<i.length?(o=i[r],a=t,u=o,[4,N(n,o)]):[3,4];case 2:a[u]=e.sent(),e.label=3;case 3:return r++,[3,1];case 4:return[2,t]}}))}))}function F(n){return t(this,void 0,void 0,(function(){var t,i,o,a;return e(this,(function(e){switch(e.label){case 0:return y&&m?(r("Using `navigator.clipboard.write()`."),[4,Promise.all(n.map(_))]):[3,5];case 1:t=e.sent(),e.label=2;case 2:return e.trys.push([2,4,,5]),[4,y(t)];case 3:return[2,e.sent()];case 4:if(i=e.sent(),!I(n,"text/plain")&&!I(n,"text/html"))throw i;return[3,5];case 5:return o=I(n,"text/plain"),u&&!o&&r("clipboard.write() was called without a `text/plain` data type. On some platforms, this may result in an empty clipboard. Call suppressWarnings() to suppress this warning."),a=A,[4,B(n[0])];case 6:if(!a.apply(void 0,[e.sent()]))throw new Error("write() failed");return[2]}}))}))}function G(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return v?(r("Using `navigator.clipboard.read()`."),[2,v()]):(t=j,[4,R()]);case 1:return[2,[t.apply(void 0,[e.sent()])]]}}))}))}export{L as ClipboardItem,G as read,R as readText,i as setDebugLog,a as suppressWarnings,F as write,O as writeText};
//# sourceMappingURL=clipboard-polyfill.esm.js.map
