UNPKG

@bluesyoung/call-app

Version:
3 lines (2 loc) 7.55 kB
(function(a,u){typeof exports=="object"&&typeof module<"u"?module.exports=u():typeof define=="function"&&define.amd?define(u):(a=typeof globalThis<"u"?globalThis:a||self,a.YoungCallApp=u())})(this,function(){"use strict";var S=Object.defineProperty;var T=(a,u,l)=>u in a?S(a,u,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[u]=l;var d=(a,u,l)=>(T(a,typeof u!="symbol"?u+"":u,l),l);function a(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 i=window.getSelection(),r=document.createRange();r.selectNodeContents(t),i.removeAllRanges(),i.addRange(r),e=i.toString()}return e}function u(t,e){let o,i,r=!1;e=e||{},o=e.debug||!1;try{const n=document.documentElement.getAttribute("dir")=="rtl";i=document.createElement("textarea"),i.style.fontSize="12pt",i.style.border="0",i.style.padding="0",i.style.margin="0",i.style.position="absolute",i.style[n?"right":"left"]="-9999px";let s=window.pageYOffset||document.documentElement.scrollTop;if(i.style.top=`${s}px`,i.setAttribute("readonly",""),i.value=t,document.body.appendChild(i),a(i),!document.execCommand("copy"))throw new Error("copy command was unsuccessful");r=!0}catch(n){o&&console.error("unable to copy using execCommand: ",n),o&&console.warn("trying IE specific stuff");try{window.clipboardData.setData("text",t),r=!0}catch(s){o&&console.error("unable to copy using clipboardData: ",s)}}finally{i&&document.body.removeChild(i)}return r}function l(t){return function(e){return Object.prototype.toString.call(e)==="[object "+t+"]"}}function y(t,e){for(let o=0,i=t.length;o<i&&e.call(t,t[o],o)!==!1;o++);}class x{constructor(e){this._rules=e}_detect(e,o,i){const r=l("Function")(o)?o.call(null,i):o;if(!r)return null;const n={name:e,version:"0",codename:""};if(r===!0)return n;if(l("String")(r)){if(i.indexOf(r)!==-1)return n}else{if(l("Object")(r))return r.hasOwnProperty("version")&&(n.version=r.version),n;if(l("RegExp")(r)){const s=r.exec(i);if(s)return s.length>=2&&s[1]&&(n.version=s[1].replace(/_/g,".")),n}}}_parseItem(e,o,i,r){let n=this,s={name:"na",version:"0"};y(o,function(c){const b=n._detect(c[0],c[1],e);if(b)return s=b,!1}),i.call(r,s.name,s.version)}parse(e){e=(e||"").toLowerCase();const o={};return this._parseItem(e,this._rules.os,function(i,r){const n=parseFloat(r);o.os={name:i,version:n,fullVersion:r},o.os[i]=n},o),this._parseItem(e,this._rules.browser,function(i,r){let n=r;const s=parseFloat(r);o.browser={name:i,version:s,fullVersion:r,mode:parseFloat(n),fullMode:n},o.browser[i]=s},o),o}}const v=[["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.]+))?/]],_=[["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/]],O=new x({os:v,browser:_}),q=navigator.userAgent+" "+navigator.appVersion+" "+navigator.vendor,w=O.parse(q);function f(t){return t!==null&&typeof t=="object"}function p(t,e,o=".",i){if(!f(e))return p(t,{},o,i);const r=Object.assign({},e);for(const n in t){if(n==="__proto__"||n==="constructor")continue;const s=t[n];s!=null&&(i&&i(r,n,s,o)||(Array.isArray(s)&&Array.isArray(r[n])?r[n]=[...s,...r[n]]:f(s)&&f(r[n])?r[n]=p(s,r[n],(o?`${o}.`:"")+n.toString(),i):r[n]=s))}return r}function A(t){return(...e)=>e.reduce((o,i)=>p(o,i,"",t),{})}const E=A(),F=w.os.name==="ios",h=w.browser.name==="micromessenger";var m=(t=>(t.wechat="weixin://",t))(m||{});const k={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 g{constructor(e,o={}){d(this,"scheme");d(this,"download");d(this,"info");d(this,"options");this.options=E(o,k),e.quickType?(this.scheme=e.quickType,this.info=(e==null?void 0:e.copyInfo)||""):this.generateScheme(e)}generateScheme(e){var n,s,c;let o="",i="",r="(\u590D\u5236\u6B64\u6D88\u606F\u6253\u5F00app)|";if(F?(e.ios_shceme.includes("://")?o=e.ios_shceme:o=`${e.ios_shceme}://`,i=((n=e==null?void 0:e.download)==null?void 0:n.ios)||e.landpage):(e.android_shceme.includes("://")?o=e.android_shceme:o=`${e.android_shceme}://`,i=((s=e==null?void 0:e.download)==null?void 0:s.yyb)||e.landpage,h&&((c=e==null?void 0:e.download)==null?void 0:c.yyb)&&(i=e.download.yyb)),e.path&&(o+=e.path),e.params){const b=new URLSearchParams(e.params).toString();o+=`?${b}`,r+=b}this.scheme=o,this.download=i,this.info=r}call(){const{mask:e,startCall:o}=this.options;if(h&&e.wechat){e.wechat();return}u(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)}}return d(g,"QuickCall",m),g}); //# sourceMappingURL=index.umd.js.map