UNPKG

pragma-views2

Version:

1 lines 6.38 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.clipboard=e():t.clipboard=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t,e,n){y("listener called"),t.success=!0,e.forEach(function(e,r){n.clipboardData.setData(r,e),r===x&&n.clipboardData.getData(r)!=e&&(y("setting text/plain failed"),t.success=!1)}),n.preventDefault()}function o(t){var e=new T,n=r.bind(this,e,t);document.addEventListener("copy",n);try{document.execCommand("copy")}finally{document.removeEventListener("copy",n)}return e.success}function i(t,e){u(t);var n=o(e);return s(),n}function a(t){var e=document.createElement("div");e.setAttribute("style","-webkit-user-select: text !important"),e.textContent="temporary element",document.body.appendChild(e);var n=i(e,t);return document.body.removeChild(e),n}function c(t){y("copyTextUsingDOM");var e=document.createElement("div");e.setAttribute("style","-webkit-user-select: text !important");var n=e;e.attachShadow&&(y("Using shadow DOM."),n=e.attachShadow({mode:"open"}));var r=document.createElement("span");r.innerText=t,n.appendChild(r),document.body.appendChild(e),u(r);var o=document.execCommand("copy");return s(),document.body.removeChild(e),o}function u(t){var e=document.getSelection(),n=document.createRange();n.selectNodeContents(t),e.removeAllRanges(),e.addRange(n)}function s(){document.getSelection().removeAllRanges()}function l(t){var e=new h.DT;return e.setData(x,t),e}function d(){return"undefined"==typeof ClipboardEvent&&void 0!==window.clipboardData&&void 0!==window.clipboardData.setData}function p(t){var e=t.getData(x);if(void 0!==e)return window.clipboardData.setData("Text",e);throw"No `text/plain` value was specified."}function f(){return v(this,void 0,void 0,function(){var t;return b(this,function(e){if(""===(t=window.clipboardData.getData("Text")))throw"Empty clipboard or could not read plain text from clipboard";return[2,t]})})}var v=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(a,c)}u((r=r.apply(t,e||[])).next())})},b=this&&this.__generator||function(t,e){function n(t){return function(e){return r([t,e])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(a=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(a=a.call(i,n[1])).done)return a;switch(i=0,a&&(n=[0,a.value]),n[0]){case 0:case 1:a=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,i=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(a=u.trys,!(a=a.length>0&&a[a.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!a||n[1]>a[0]&&n[1]<a[3])){u.label=n[1];break}if(6===n[0]&&u.label<a[1]){u.label=a[1],a=n;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(n);break}a[2]&&u.ops.pop(),u.trys.pop();continue}n=e.call(t,u)}catch(t){n=[6,t],i=0}finally{o=a=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,i,a,c,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return c={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c};Object.defineProperty(e,"__esModule",{value:!0});var h=n(1),y=function(t){},m=!0,g=function(){(console.warn||console.log).apply(console,arguments)},w=g.bind("[clipboard-polyfill]"),x="text/plain",D=function(){function t(){}return t.setDebugLog=function(t){y=t},t.suppressWarnings=function(){m=!1,h.suppressDTWarnings()},t.write=function(t){return v(this,void 0,void 0,function(){var e;return b(this,function(n){if(m&&!t.getData(x)&&w("clipboard.write() was called without a `text/plain` data type. On some platforms, this may result in an empty clipboard. Call clipboard.suppressWarnings() to suppress this warning."),d()){if(p(t))return[2];throw"Copying failed, possibly because the user rejected it."}if(o(t))return y("regular execCopy worked"),[2];if(navigator.userAgent.indexOf("Edge")>-1)return y('UA "Edge" => assuming success'),[2];if(i(document.body,t))return y("copyUsingTempSelection worked"),[2];if(a(t))return y("copyUsingTempElem worked"),[2];if(void 0!==(e=t.getData(x))&&c(e))return y("copyTextUsingDOM worked"),[2];throw"Copy command failed."})})},t.writeText=function(t){return v(this,void 0,void 0,function(){return b(this,function(e){return navigator.clipboard&&navigator.clipboard.writeText?(y("Using `navigator.clipboard.writeText()`."),[2,navigator.clipboard.writeText(t)]):[2,this.write(l(t))]})})},t.read=function(){return v(this,void 0,void 0,function(){var t;return b(this,function(e){switch(e.label){case 0:return t=l,[4,this.readText()];case 1:return[2,t.apply(void 0,[e.sent()])]}})})},t.readText=function(){return v(this,void 0,void 0,function(){return b(this,function(t){if(navigator.clipboard&&navigator.clipboard.readText)return y("Using `navigator.clipboard.readText()`."),[2,navigator.clipboard.readText()];if(d())return y("Reading text using IE strategy."),[2,f()];throw"Read is not supported in your browser."})})},t.DT=h.DT,t}();e.default=D;var T=function(){function t(){this.success=!1}return t}();t.exports=D},function(t,e,n){"use strict";function r(){c=!1}Object.defineProperty(e,"__esModule",{value:!0});var o=["text/plain","text/html"],i=function(){(console.warn||console.log).call(arguments)},a=i.bind(console,"[clipboard-polyfill]"),c=!0;e.suppressDTWarnings=r;var u=function(){function t(){this.m={}}return t.prototype.setData=function(t,e){c&&-1===o.indexOf(t)&&a("Unknown data type: "+t,"Call clipboard.suppressWarnings() to suppress this warning."),this.m[t]=e},t.prototype.getData=function(t){return this.m[t]},t.prototype.forEach=function(t){for(var e in this.m)t(this.m[e],e)},t}();e.DT=u}])});