UNPKG

native-fn

Version:
2 lines (1 loc) 8.52 kB
"use strict";function t(t,e){if(void 0===e&&(e=!0),void 0!==globalThis.document){var n=globalThis.document.createElement(t);return"width"in n&&(n.width="0"),"height"in n&&(n.height="0"),"border"in n&&(n.border="0"),"frameBorder"in n&&(n.frameBorder="0"),"scrolling"in n&&(n.scrolling="no"),"cellPadding"in n&&(n.cellPadding="0"),"cellSpacing"in n&&(n.cellSpacing="0"),"frame"in n&&(n.frame="void"),"rules"in n&&(n.rules="none"),"noWrap"in n&&(n.noWrap=!0),n.tabIndex=-1,n.setAttribute("role","presentation"),e?(n.style.width="1px",n.style.height="1px"):(n.setAttribute("aria-hidden","true"),n.style.width="0",n.style.height="0",n.style.zIndex="-9999",n.style.display="none",n.style.visibility="hidden",n.style.pointerEvents="none"),n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.padding="0",n.style.margin="0",n.style.border="none",n.style.outline="none",n.style.clip="rect(1px, 1px, 1px, 1px)",n.style.clipPath="inset(50%)",n.style.overflow="hidden",n.style.whiteSpace="nowrap",n}}function e(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r="",o=0;o<e.length-2;o++){var i=e[o];void 0!==i&&(r=r+i.charAt(0).toUpperCase()+i.slice(1))}return r}function n(){this.returnValue=!1}function r(){this.cancelBubble=!0}var o=/(animation)(start|iteration|end|cancel)|(transition)(start|run|end|cancel)|(fullscreen)(change|error)|(lost|got)(pointer)(capture)|(pointer)(lock)(change|error)|(pointer)(cancel|down|enter|leave|move|out|over|up)/i,i=["","webkit","moz","ms","MS","o","O"],a={wheel:["wheel","mousewheel","DOMMouseScroll"],focus:["focus","focusin"],blur:["blur","focusout"],beforeinput:["beforeinput","textInput"]},l={useStd:void 0!==globalThis.document&&"function"==typeof globalThis.document.addEventListener,add:function(t,e){void 0===e&&(e={callback:null,options:!1});var o=e.callback;if(void 0!==t&&null!==o){var i=l.withVender(t,e.type),a=e.options;if("function"==typeof t.addEventListener)try{return t.addEventListener(i,o,a)}catch(t){}if("function"==typeof t.addListener)if("boolean"==typeof t.matches)try{return t.addListener(o)}catch(t){}else try{return t.addListener(i,o)}catch(t){}return"function"==typeof t.attachEvent?o.__ieWrapper?t.attachEvent("on"+i,o.__ieWrapper):t.attachEvent("on"+i,o.__ieWrapper=function(e){void 0===e&&(e=globalThis.event),void 0!==e&&(e.currentTarget=t,"function"!=typeof e.preventDefault&&(e.preventDefault=n),"function"!=typeof e.stopPropagation&&(e.stopPropagation=r),"function"==typeof o?o.call(t,e):o&&"function"==typeof o.handleEvent&&o.handleEvent.call(t,e))}):void 0}},remove:function(t,e){void 0===e&&(e={callback:null,options:!1});var n=e.callback;if(void 0!==t&&null!==n){var r=l.withVender(t,e.type),o=e.options;if("function"==typeof t.removeEventListener)try{return t.removeEventListener(r,n,o)}catch(t){}if("function"==typeof t.removeListener)if("boolean"==typeof t.matches)try{return t.removeListener(n)}catch(t){}else try{return t.removeListener(r,n)}catch(t){}if("function"!=typeof t.detachEvent);else{var i=n.__ieWrapper;void 0!==i&&(t.detachEvent("on"+r,i),delete n.__ieWrapper)}}},withVender:function(t,n){if(void 0===n)return"";if(t===globalThis.document&&["deviceready","pause","resume","backbutton","menubutton","searchbutton","startcallbutton","endcallbutton","volumedownbutton","volumeupbutton","activated","cordovacallbackerror"].indexOf(n)>-1)return n;if(void 0!==t.webkitEnterFullscreen&&["webkitbeginfullscreen","webkitendfullscreen","webkitpresentationmodechanged"].indexOf(n)>-1)return n;var r;r=n in a?a[n]:o.test(n)?[n,n.replace(o,e)]:[n];for(var l=0;l<i.length;l++)for(var c=0;c<r.length;c++){var u=i[l]+r[c];if(void 0!==t["on"+u])return u}return""}},c={copy:function(t){var e=function(t){if(s(t))return"value"in t&&"string"==typeof t.value?t.value:t.textContent;if(d(t))return t.toString();if(function(t){return u(t)||function(t){return Array.isArray(t)}(t)}(t))try{return JSON.stringify(t)}catch(e){return""+t}else if("string"!=typeof t)return""+t;return t}(t),n=function(t){var e=null;s(t)&&(e=t.outerHTML);if(d(t)&&t.rangeCount>0){for(var n=globalThis.document.createElement("div"),r=0;r<t.rangeCount;r++)n.appendChild(t.getRangeAt(r).cloneContents());e=n.innerHTML}if(null===e)return;return e}(t);if(f()&&("write"in navigator.clipboard||"writeText"in navigator.clipboard))return function(t,e){try{if("ClipboardItem"in window&&"write"in navigator.clipboard){var n={};return void 0!==e&&(n["text/html"]=new Blob([e],{type:"text/html"})),n["text/plain"]=new Blob([t],{type:"text/plain"}),navigator.clipboard.write([new ClipboardItem(n)]).then((function(){return!0})).catch((function(){return!1}))}if("writeText"in navigator.clipboard)return navigator.clipboard.writeText(t).then((function(){return!0})).catch((function(){return!1}))}catch(t){return Promise.resolve(!1)}return Promise.resolve(!1)}(e,n).then((function(t){return!!t||p(e,n)})).catch((function(){return p(e,n)}));return Promise.resolve(p(e,n))},paste:function(){if(f()&&("read"in navigator.clipboard||"readText"in navigator.clipboard))return function(){try{if("ClipboardItem"in window&&"read"in navigator.clipboard)return navigator.clipboard.read().then((function(t){if(0===t.length)return Promise.resolve(null);for(var e=t[0],n=e.types,r=0;r<n.length;r++)if("text/html"===n[r])return e.getType("text/html").then((function(t){return t.text()})).catch((function(){return null}));for(r=0;r<n.length;r++)if("text/plain"===n[r])return e.getType("text/plain").then((function(t){return t.text()})).catch((function(){return null}));return Promise.resolve(null)})).catch((function(){return null}));if("readText"in navigator.clipboard)return navigator.clipboard.readText().then((function(t){return t})).catch((function(){return null}))}catch(t){return Promise.resolve(null)}return Promise.resolve(null)}().then((function(t){return null!==t?t:v()})).catch((function(){return v()}));return Promise.resolve(v())},Constants:{},Errors:{}};function u(t){return null!==t&&"object"==typeof t}function s(t){return u(t)&&void 0!==t.innerText}function d(t){return"[object Selection]"===Object.prototype.toString.call(t)}function f(){return function(){if(void 0!==globalThis.isSecureContext)return globalThis.isSecureContext;var t=location.protocol,e=location.hostname;return"https:"===t||"localhost"===e||"127.0.0.1"===e||"[::1]"===e}()&&"undefined"!=typeof navigator&&"clipboard"in navigator}function p(e,n){return function(e,n){if(!globalThis.getSelection||!globalThis.document.createRange)return!1;var r=t("div");if(void 0===r)return!1;r.contentEditable="true",r.innerHTML=e,r.style.whiteSpace="pre",r.style.userSelect="text",r.style.setProperty("-webkit-user-select","text"),r.style.setProperty("-moz-user-select","text"),r.style.setProperty("-ms-user-select","text"),globalThis.document.body.appendChild(r);var o=globalThis.getSelection(),i=globalThis.document.createRange(),a=function(t){try{null!==t.clipboardData&&"function"==typeof t.clipboardData.setData&&(t.preventDefault(),void 0!==n&&t.clipboardData.setData("text/html",n),t.clipboardData.setData("text/plain",e))}catch(t){}};l.add(globalThis.document,{type:"copy",callback:a,options:{once:!0,capture:!0}});try{if(null===o)return h(r,o,a),!1;o.removeAllRanges(),i.selectNodeContents(r),o.addRange(i);var c=globalThis.document.execCommand("copy");return h(r,o,a),c}catch(t){return h(r,o,a),!1}}(e,n)||function(t,e){var n=window.clipboardData;if(void 0!==n&&"function"==typeof n.setData)try{return void 0!==e&&n.setData("HTML",e),n.setData("Text",t)}catch(t){return!1}return!1}(e,n)}function v(){return function(){var e=t("div");if(void 0===e)return null;e.contentEditable="true",globalThis.document.body.appendChild(e),e.focus();var n=null,r=function(t){try{null!==t.clipboardData&&"function"==typeof t.clipboardData.getData&&(t.preventDefault(),n=t.clipboardData.getData("text/html")||t.clipboardData.getData("text/plain")||null)}catch(t){}};l.add(globalThis.document,{type:"paste",callback:r,options:{once:!0,capture:!0}});try{return globalThis.document.execCommand("paste")||n||(n=e.innerHTML||e.textContent||null),b(e,r),n}catch(t){return b(e,r),null}}()||function(){var t=window.clipboardData;if(void 0!==t&&"function"==typeof t.getData)try{return t.getData("Text")||null}catch(t){return null}return null}()||""}function h(t,e,n){null!==e&&e.removeAllRanges(),globalThis.document.body.removeChild(t),l.remove(globalThis.document,{type:"copy",callback:n})}function b(t,e){globalThis.document.body.removeChild(t),l.remove(globalThis.document,{type:"paste",callback:e})}module.exports=c;