// #ifdef H5 /** * clipboard.min.js Add support for ES6 module import * @author echo. * https://www.thorui.cn/doc **/ function select(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var i=t.hasAttribute("readonly");i||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),i||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var n=window.getSelection(),r=document.createRange();r.selectNodeContents(t),n.removeAllRanges(),n.addRange(r),e=n.toString()}return e}class ClipboardAction{constructor(t){this.resolveOptions(t),this.initSelection()}resolveOptions(t={}){this.action=t.action,this.container=t.container,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}initSelection(){this.text?this.selectFake():this.target&&this.selectTarget()}selectFake(){const t="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=(()=>this.removeFake()),this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[t?"right":"left"]="-9999px";let e=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=`${e}px`,this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=select(this.fakeElem),this.copyText()}removeFake(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}selectTarget(){this.selectedText=select(this.target),this.copyText()}copyText(){let t;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}handleResult(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}clearSelection(){this.trigger&&this.trigger.focus(),window.getSelection().removeAllRanges()}set action(t="copy"){if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')}get action(){return this._action}set target(t){if(void 0!==t){if(!t||"object"!=typeof t||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}}get target(){return this._target}destroy(){this.removeFake()}}function Emitter(){}Emitter.prototype={on:function(t,e,i){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var n=this;function r(){n.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),n=0,r=i.length;nthis.onClick(t))}onClick(t){const e=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new ClipboardAction({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}defaultAction(t){return getAttributeValue("action",t)}defaultTarget(t){const e=getAttributeValue("target",t);if(e)return document.querySelector(e)}static isSupported(t=["copy","cut"]){const e="string"==typeof t?[t]:t;let i=!!document.queryCommandSupported;return e.forEach(t=>{i=i&&!!document.queryCommandSupported(t)}),i}defaultText(t){return getAttributeValue("text",t)}destroy(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}function getAttributeValue(t,e){const i=`data-clipboard-${t}`;if(e.hasAttribute(i))return e.getAttribute(i)}export default Clipboard; // #endif