@bluesyoung/call-app
Version:
3 lines (2 loc) • 7.35 kB
JavaScript
;var m=Object.defineProperty;var g=(t,e,o)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var a=(t,e,o)=>(g(t,typeof e!="symbol"?e+"":e,o),o);function y(t){let e;if(t.nodeName==="SELECT")t.focus(),e=t.value;else if(t.nodeName==="INPUT"||t.nodeName==="TEXTAREA"){var o=t.hasAttribute("readonly");o||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),o||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();const r=window.getSelection(),i=document.createRange();i.selectNodeContents(t),r.removeAllRanges(),r.addRange(i),e=r.toString()}return e}function x(t,e){let o,r,i=!1;e=e||{},o=e.debug||!1;try{const s=document.documentElement.getAttribute("dir")=="rtl";r=document.createElement("textarea"),r.style.fontSize="12pt",r.style.border="0",r.style.padding="0",r.style.margin="0",r.style.position="absolute",r.style[s?"right":"left"]="-9999px";let n=window.pageYOffset||document.documentElement.scrollTop;if(r.style.top=`${n}px`,r.setAttribute("readonly",""),r.value=t,document.body.appendChild(r),y(r),!document.execCommand("copy"))throw new Error("copy command was unsuccessful");i=!0}catch(s){o&&console.error("unable to copy using execCommand: ",s),o&&console.warn("trying IE specific stuff");try{window.clipboardData.setData("text",t),i=!0}catch(n){o&&console.error("unable to copy using clipboardData: ",n)}}finally{r&&document.body.removeChild(r)}return i}function c(t){return function(e){return Object.prototype.toString.call(e)==="[object "+t+"]"}}function v(t,e){for(let o=0,r=t.length;o<r&&e.call(t,t[o],o)!==!1;o++);}class _{constructor(e){this._rules=e}_detect(e,o,r){const i=c("Function")(o)?o.call(null,r):o;if(!i)return null;const s={name:e,version:"0",codename:""};if(i===!0)return s;if(c("String")(i)){if(r.indexOf(i)!==-1)return s}else{if(c("Object")(i))return i.hasOwnProperty("version")&&(s.version=i.version),s;if(c("RegExp")(i)){const n=i.exec(r);if(n)return n.length>=2&&n[1]&&(s.version=n[1].replace(/_/g,".")),s}}}_parseItem(e,o,r,i){let s=this,n={name:"na",version:"0"};v(o,function(u){const l=s._detect(u[0],u[1],e);if(l)return n=l,!1}),r.call(i,n.name,n.version)}parse(e){e=(e||"").toLowerCase();const o={};return this._parseItem(e,this._rules.os,function(r,i){const s=parseFloat(i);o.os={name:r,version:s,fullVersion:i},o.os[r]=s},o),this._parseItem(e,this._rules.browser,function(r,i){let s=i;const n=parseFloat(i);o.browser={name:r,version:n,fullVersion:i,mode:parseFloat(s),fullMode:s},o.browser[r]=n},o),o}}const O=[["ios",function(t){return/\bcpu(?: iphone)? os /.test(t)?/\bcpu(?: iphone)? os ([0-9._]+)/:t.indexOf("iph os ")!==-1?/\biph os ([0-9_]+)/:/\bios\b/}],["android",function(t){return t.indexOf("android")>=0?/\bandroid[ \/-]?([0-9.x]+)?/:t.indexOf("adr")>=0?t.indexOf("mqqbrowser")>=0?/\badr[ ]\(linux; u; ([0-9.]+)?/:/\badr(?:[ ]([0-9.]+))?/:"android"}],["wp",function(t){return t.indexOf("windows phone ")!==-1?/\bwindows phone (?:os )?([0-9.]+)/:t.indexOf("xblwp")!==-1?/\bxblwp([0-9.]+)/:t.indexOf("zunewp")!==-1?/\bzunewp([0-9.]+)/:"windows phone"}],["symbian",/\bsymbian(?:os)?\/([0-9.]+)/],["chromeos",/\bcros i686 ([0-9.]+)/],["linux","linux"],["windowsce",/\bwindows ce(?: ([0-9.]+))?/]],q=[["micromessenger",/\bmicromessenger\/([\d.]+)/],["qq",/\bqq/i],["qzone",/qzone\/.*_qz_([\d.]+)/i],["qqbrowser",/\bm?qqbrowser\/([0-9.]+)/],["tt",/\btencenttraveler ([0-9.]+)/],["weibo",/weibo__([0-9.]+)/],["uc",function(t){return t.indexOf("ucbrowser/")>=0?/\bucbrowser\/([0-9.]+)/:t.indexOf("ubrowser/")>=0?/\bubrowser\/([0-9.]+)/:/\buc\/[0-9]/.test(t)?/\buc\/([0-9.]+)/:t.indexOf("ucweb")>=0?/\bucweb([0-9.]+)?/:/\b(?:ucbrowser|uc)\b/}],["360",function(t){return t.indexOf("360 aphone browser")!==-1?/\b360 aphone browser \(([^\)]+)\)/:/\b360(?:se|ee|chrome|browser)\b/}],["baidu",function(t){let e=0,o;return/ baiduboxapp\//i.test(t)?((o=/([\d+.]+)_(?:diordna|enohpi)_/.exec(t))?(o=o[1].split("."),e=o.reverse().join(".")):(o=/baiduboxapp\/([\d+.]+)/.exec(t))&&(e=o[1]),{version:e}):!1}],["baidubrowser",/\b(?:ba?idubrowser|baiduhd)[ \/]([0-9.x]+)/],["bdminivideo",/bdminivideo\/([0-9.]+)/],["sogou",function(t){return t.indexOf("sogoumobilebrowser")>=0?/sogoumobilebrowser\/([0-9.]+)/:t.indexOf("sogoumse")>=0?!0:/ se ([0-9.x]+)/}],["ali-ap",function(t){return t.indexOf("aliapp")>0?/\baliapp\(ap\/([0-9.]+)\)/:/\balipayclient\/([0-9.]+)\b/}],["ali-tb",/\baliapp\(tb\/([0-9.]+)\)/],["ali-tm",/\baliapp\(tm\/([0-9.]+)\)/],["tao",/\btaobrowser\/([0-9.]+)/],["mi",/\bmiuibrowser\/([0-9.]+)/],["oppo",/\boppobrowser\/([0-9.]+)/],["vivo",/\bvivobrowser\/([0-9.]+)/],["meizu",/\bmzbrowser\/([0-9.]+)/],["nokia",/\bnokiabrowser\/([0-9.]+)/],["samsung",/\bsamsungbrowser\/([0-9.]+)/],["maxthon",/\b(?:maxthon|mxbrowser)(?:[ \/]([0-9.]+))?/],["opera",function(t){const e=/\bopera.+version\/([0-9.ab]+)/,o=/\bopr\/([0-9.]+)/;return e.test(t)?e:o}],["edge",/edge\/([0-9.]+)/],["firefox",/\bfirefox\/([0-9.ab]+)/],["chrome",/ (?:chrome|crios|crmo)\/([0-9.]+)/],["android",function(t){if(t.indexOf("android")!==-1)return/\bversion\/([0-9.]+(?: beta)?)/}],["safari",/\bversion\/([0-9.]+(?: beta)?)(?: mobile(?:\/[a-z0-9]+)?)? safari\//],["webview",/\bcpu(?: iphone)? os (?:[0-9._]+).+\bapplewebkit\b/]],A=new _({os:O,browser:q}),E=navigator.userAgent+" "+navigator.appVersion+" "+navigator.vendor,p=A.parse(E);function d(t){return t!==null&&typeof t=="object"}function b(t,e,o=".",r){if(!d(e))return b(t,{},o,r);const i=Object.assign({},e);for(const s in t){if(s==="__proto__"||s==="constructor")continue;const n=t[s];n!=null&&(r&&r(i,s,n,o)||(Array.isArray(n)&&Array.isArray(i[s])?i[s]=[...n,...i[s]]:d(n)&&d(i[s])?i[s]=b(n,i[s],(o?`${o}.`:"")+s.toString(),r):i[s]=n))}return i}function F(t){return(...e)=>e.reduce((o,r)=>b(o,r,"",t),{})}const k=F(),S=p.os.name==="ios",f=p.browser.name==="micromessenger";var w=(t=>(t.wechat="weixin://",t))(w||{});const T={timeout:2500,mask:{wechat:()=>null},startCall:()=>console.log("---\u5F00\u59CB\u5524\u7AEF---"),callFail:()=>console.log("---\u5524\u8D77\u5931\u8D25\uFF0C\u8DF3\u8F6C\u4E0B\u8F7D---")};class h{constructor(e,o={}){a(this,"scheme");a(this,"download");a(this,"info");a(this,"options");this.options=k(o,T),e.quickType?(this.scheme=e.quickType,this.info=(e==null?void 0:e.copyInfo)||""):this.generateScheme(e)}generateScheme(e){var s,n,u;let o="",r="",i="(\u590D\u5236\u6B64\u6D88\u606F\u6253\u5F00app)|";if(S?(e.ios_shceme.includes("://")?o=e.ios_shceme:o=`${e.ios_shceme}://`,r=((s=e==null?void 0:e.download)==null?void 0:s.ios)||e.landpage):(e.android_shceme.includes("://")?o=e.android_shceme:o=`${e.android_shceme}://`,r=((n=e==null?void 0:e.download)==null?void 0:n.yyb)||e.landpage,f&&((u=e==null?void 0:e.download)==null?void 0:u.yyb)&&(r=e.download.yyb)),e.path&&(o+=e.path),e.params){const l=new URLSearchParams(e.params).toString();o+=`?${l}`,i+=l}this.scheme=o,this.download=r,this.info=i}call(){const{mask:e,startCall:o}=this.options;if(f&&e.wechat){e.wechat();return}x(this.info),o==null||o(),window.location.href=this.scheme,this.fallback()}fallback(){const e=setTimeout(()=>{this.options.callFail(),this.download&&(window.location.href=this.download)},this.options.timeout);setTimeout(()=>{window.addEventListener("blur",()=>clearTimeout(e))},this.options.timeout-500)}}a(h,"QuickCall",w);module.exports=h;
//# sourceMappingURL=index.cjs.js.map