UNPKG

@cmtlyt/base

Version:
2 lines (1 loc) 14.4 kB
import Ye from"ms";const g=Symbol&&Symbol("internal-empty")||{},Ke=Symbol&&Symbol("empty")||{},qe=["url","map","set","weakmap","weakset"];function O(...e){globalThis?.__ClConfig__?.disableWarning||console.warn("@cmtlyt/base:>",...e)}const u=function(e){const t=e?.clength||e?.length||0;if(!t)throw new TypeError("\u65E0\u6CD5\u8BFB\u53D6\u51FD\u6570\u53C2\u6570\u5217\u8868\u7684\u957F\u5EA6\uFF0C\u4E0D\u80FD\u4F7F\u7528\u53EF\u9009\u53C2\u6570\u548C\u5269\u4F59\u53C2\u6570\uFF01\uFF01\uFF01");const n=(...i)=>{if(i.length>=t)return e(...i);{const a=(...o)=>n(...i.concat(o));return a.clength=t-i.length,a}};return n.clength=t,n};function U(e,t){return e(...t)}const Qe=u(U);function $(e,t){return t(e)}const Je=u($);function V(e,t){if(t=Number(t),be(t))throw new TypeError("limit must be a number");const n=(...i)=>e(...i.slice(0,t));return n.clength=t,n}const Ze=u(V),C=Symbol&&Symbol("__")||{};function X(e){return(...t)=>{const n=(...i)=>{let a=0;const o=t.map(p=>p===C?i[a++]:p);if(i.length!==a)throw new TypeError("\u975E\u6CD5\u8C03\u7528, \u53C2\u6570\u6570\u91CF\u4E0D\u5339\u914D");return e(...o)};return n.clength=t.reduce((i,a)=>i+(a===C?1:0),0),n}}X.__=C;function z(e){return!!(m(e)||e instanceof String||e&&typeof e=="object"&&typeof e.length=="number")}function m(e){return Array.isArray(e)}function s(e){let t=g;return function(...n){return t!==g?t:t=e(...n)}}const et=s;class nt{#e=new Map;#t=new WeakMap;#n(t){return typeof t=="object"&&t!==null}set(t,n){this.#n(t)?this.#t.set(t,n):this.#e.set(t,n)}get(t){return this.#n(t)?this.#t.get(t):this.#e.get(t)}has(t){return this.#n(t)?this.#t.has(t):this.#e.has(t)}}function st(e,t){const n=function(...i){const a=t?t(...i):i[0],o=n.cache;if(o.has(a))return o.get(a);const p=e(...i);return o.set(a,p),p};return n.cache=new nt,n}const it=Reflect?.apply?e=>{let t=g;return(...n)=>(t===g&&(t=e()),typeof t!="function"?t:Reflect.apply(t,null,n))}:e=>{let t=g;return(...n)=>(t===g&&(t=e()),typeof t!="function"?t:t(...n))},c=s(()=>!r().toLocaleLowerCase().includes("node")&&window&&"onload"in window),G=s(()=>c()?window?.frames?.length!==window?.parent?.frames?.length:!1),h=s(()=>r().toLocaleLowerCase().includes("node")),L=s(()=>typeof my<"u"&&my!==null&&typeof my.alert<"u"),f=L,A=s(()=>typeof tt<"u"&&tt!==null&&typeof tt.showToast<"u"),y=s(()=>!c()&&!A()&&!b(typeof wx)&&(!b(wx?.login)||!b(wx?.miniProgram))),N=s(()=>typeof WXEnvironment<"u"&&WXEnvironment.platform!=="Web"),w=s(()=>{const e=r().toLocaleLowerCase();return e.includes("iphone")||e.includes("ipad")}),Y=s(()=>r().toLocaleLowerCase().includes("android")),K=s(()=>{const e=r();return/\sOpenHarmony\s\d/i.test(e)}),q=s(()=>{const e=r().toLocaleLowerCase();return e.includes("chrome")||e.includes("crios")||e.includes("headlesschrome")}),at=s(()=>r().toLocaleLowerCase().includes("firefox")),rt=s(()=>r().toLocaleLowerCase().includes("safari")&&!q()),ot=s(()=>r().toLocaleLowerCase().includes("edg")),ut=s(()=>{const e=r().toLocaleLowerCase();return e.includes("edge")&&!e.includes("edg")}),ct=s(()=>r().toLocaleLowerCase().includes("edge")),pt=s(()=>typeof __kraken__<"u"),lt=s(()=>typeof global<"u"&&global!==null&&typeof global.callNative<"u"&&!N()),T=s(()=>{const e=r();return c()&&/AliApp\(TB/i.test(e)}),v=s(()=>{const e=r();return c()&&/AliApp\(LT/i.test(e)}),x=s(()=>{const e=r();return(c()||h())&&/AliApp\(TAOBAOLIVEAPP/i.test(e)}),ft=s(()=>T()||c()&&x()),S=s(()=>{const e=r();return c()&&/MicroMessenger/i.test(e)}),W=s(()=>{const e=r();return c()&&/AliApp\(AP/i.test(e)}),dt=s(()=>{const e=r();return c()&&/AliApp\(DingTalk/i.test(e)}),Q=s(()=>{const e=r();return c()&&/AliApp\(MMC/i.test(e)}),gt=s(()=>{const e=r();return c()&&/AliApp\(RetailTrader/i.test(e)}),ht=s(()=>{const e=r();return c()&&/AliApp\(RETAIL(?!Trader)/i.test(e)}),mt=s(()=>T()||v()||x()||W()),J=["taobao","tb"],Z=["lt"],ee=["mmc","hmjs-c"],te=["xiniao"],yt=[...J,...Z,...ee,...te,"cngl"],ne=["alipay"],se=["cn","cainiao","com.cainiao.wireless"],wt=[...ne,...se],bt=s(()=>!b(typeof dd)&&dd!==null&&!b(typeof dd.alert)&&!c()),At=s(()=>{const{appName:e}=l();return f()&&yt.includes(e)}),M=s(()=>{const{appName:e}=l();return f()&&wt.includes(e)}),B=s(()=>{const{appName:e}=l();return f()&&J.includes(e)}),F=s(()=>{const{appName:e}=l();return f()&&Z.includes(e)}),ie=s(()=>{const{appName:e}=l();return f()&&ee.includes(e)}),Tt=s(()=>{const{appName:e}=l();return f()&&te.includes(e)}),_t=s(()=>{const{appName:e}=l();return f()&&se.includes(e)}),Ct=s(()=>{const{appName:e}=l();return f()&&ne.includes(e)}),Lt=s(()=>typeof swan<"u"&&swan!==null&&typeof swan.showToast<"u"),Nt=s(()=>typeof ks<"u"&&ks!==null&&typeof ks.showToast<"u"),vt=s(()=>f()||y()||A()),ae=s(()=>{const e=r().toLocaleLowerCase();return h()&&/AliApp\(TB/i.test(e)}),re=s(()=>{const e=r().toLocaleLowerCase();return h()&&/AliApp\(LT/i.test(e)}),oe=s(()=>{const e=r().toLocaleLowerCase();return h()&&/MicroMessenger/i.test(e)}),ue=s(()=>B()||T()||ae()),ce=s(()=>F()||v()||re()),pe=s(()=>M()||W()),le=s(()=>{const{appName:e}=l();return e==="tm"}),xt=s(()=>ue()||ce()||pe()||x()||le()),St=s(()=>S()||y()||oe()),fe=s(()=>{const e=r();return c()&&/AliApp\(group_leader/i.test(e)}),Et=s(()=>{const e=r();return c()&&(/AliApp\(CN/i.test(e)||/AliApp\(cainiao/i.test(e))}),Wt=s(()=>c()&&/AliApp\(/.test(window.navigator.userAgent)),Mt=s(()=>{const{appName:e}=l();return e==="wdkhema"}),Bt=s(()=>{const{appName:e}=l();return e==="youku"}),P=s(()=>!!(c()&&window?.location?.search?.includes?.("__webview__=alipay"))),R=s(()=>!!(v()&&window?.location?.search?.includes?.("__webview__=taobao"))),E=s(()=>!!(T()&&window?.location?.search?.includes?.("__webview__=taobao"))),Ft=s(()=>E()),Pt=s(()=>{const e=r();return c()&&/AliApp\(DingTalk/i.test(e)}),Rt=s(()=>c()&&(Q()||fe()||window?.location?.search?.includes?.("__webview__=mmc"))),k=s(()=>{const e=r();return S()&&/miniProgram/i.test(e)}),kt=s(()=>S()&&!k()),It=s(()=>P()||k()||E()||R()),Dt=s(()=>P()||E()||R()),jt=s(()=>B()||F()||M()||ie()),de=s(()=>{const{screenHeight:e}=_();return w()&&[812,896,844,926,693,780,932,852].includes(y()?(wx.getSystemInfoSync()||{}).screenHeight:e)}),ge=s(()=>{const{screenHeight:e,devicePixelRatio:t}=_();return w()&&e===896&&t===3}),he=s(()=>{const{screenHeight:e,devicePixelRatio:t}=_();return w()&&e===896&&t===2}),me=s(()=>{const{screenHeight:e}=_();return w()&&e===932}),Ht=s(()=>de()||ge()||he()||me());function Ot(e=8){let t="";for(let n=0;n<e;n=t.length){const i=Math.random().toString(36).slice(2,e+2);t+=i.slice(0,e-n)}return t}function Ut(e){const t=new Blob([e]);return URL.createObjectURL(t)}function I(...e){return e.length?e.map(t=>typeof t=="string"?t:Array.isArray(t)?I(...t):typeof t=="object"&&t!==null?Object.keys(t).filter(n=>t[n]).join(" "):"").join(" ").replace(/\s+/g," ").trimEnd():""}const $t=I,ye=s(()=>{if(w())return"ios";if(Y())return"android";if(K())return"openHarmony";if(h()){const e=process.platform;return e==="darwin"?"mac":e==="win32"?"windows":e==="linux"?"linux":e}return"other"});function we(e){const t=typeof e;return t!=="object"&&t!=="function"?t:Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}const r=s(()=>globalThis.navigator?globalThis.navigator.userAgent||globalThis.navigator.swuserAgent:process?`Node.js/${process.version} (${process.platform}; ${process.arch}) ${process.env.SHELL} ${process.env.LANG} ${process.env.TERM_PROGRAM}`:"");function Vt(e=1){return Array.from({length:e},()=>" ").join("")}function Xt(e,t=1){return Array.from({length:t},()=>e).join("")}const zt=s(()=>c()?window:globalThis||(N()?weex:L()?my:y()?wx:A()?tt:{}));function Gt(e={}){const{duration:t,expires:n,domain:i,maxAge:a,path:o}=e;let p="";if(Le(e))return p;if(t){const d=new Date;d.setTime(d.getTime()+t),p+=`expires=${d.toUTCString()};`}else if(n)if(typeof n=="string"){const d=new Date;d.setTime(d.getTime()+Ye(n)),p+=`expires=${d.toUTCString()};`}else if(n instanceof Date)p+=`expires=${n.toUTCString()};`;else throw new TypeError("expires \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6216 Date (\u63A8\u8350\u4F7F\u7528Date)");return i&&(p+=`domain=${i};`),a&&(p+=`max-age=${a};`),o&&(p+=`path=${o};`),p}function Yt(e){let t=()=>{},n=()=>{};const i=new Promise((a,o)=>{t=a,n=o,e?.(a,o)});return{resolve:t,reject:n,promise:i}}const l=s(()=>{let e="",t="";if(c()||h()){const n=r();if(n){const i=n.match(/AliApp\(([\w-]+)\/([\d.]+)\)/i);i&&([,e,t]=i.map(a=>j(a)?a.toLowerCase():a))}}else if(f()){const n=my.getSystemInfoSync()||{},{version:i="",app:a=""}=n;e=a.toLowerCase(),t=i.toLowerCase()}return{appName:e,appVersion:t}}),_=s(()=>{const e={platform:ye(),userAgent:r()};if(c())return{...e,appName:navigator.appName,appVersion:navigator.appVersion,screenWidth:window.screen.width,screenHeight:window.screen.height,devicePixelRatio:window.devicePixelRatio};if(N())return{...e,appName:navigator.appName,appVersion:navigator.appVersion,screenWidth:window.screen.width/window.devicePixelRatio,screenHeight:window.screen.height/window.devicePixelRatio,devicePixelRatio:window.devicePixelRatio};if(L()){const t=my.getSystemInfoSync()||{};return{...e,appName:t.app,appVersion:t.version,platform:t.platform,screenWidth:t.screenWidth,screenHeight:t.screenHeight,devicePixelRatio:t.pixelRatio}}if(y()){const t=wx?.getSystemInfoSync?.()||{};return{...e,appName:"wechat",appVersion:t.version,platform:t.platform,screenWidth:t.screenWidth,screenHeight:t.screenHeight,devicePixelRatio:t.pixelRatio}}if(A()){const t=tt.getSystemInfoSync()||{};return{...e,appName:"bytedance",appVersion:t.version,platform:t.platform,screenWidth:t.screenWidth,screenHeight:t.screenHeight,devicePixelRatio:t.pixelRatio}}return{...e,appName:"",appVersion:"",platform:"",screenWidth:0,screenHeight:0,devicePixelRatio:0}});function D(e){return typeof e>"u"||typeof e=="object"&&e===null}function be(e){return typeof e=="number"&&e!==e}function Kt(e){return typeof e=="number"}function Ae(e){return typeof e=="string"&&(/^http:\/\//.test(e)||/^\/\//.test(e))}function Te(e){return typeof e=="string"&&/^https:\/\//.test(e)||/^\/\//.test(e)}function _e(e){return typeof e=="string"&&e.startsWith("blob:")}function Ce(e){return typeof e=="string"&&e.startsWith("data:")}function qt(e){return G()?(O("iframe \u4E2D\u65E0\u6CD5\u6B63\u786E\u5224\u65AD!!!"),!1):e instanceof URL||Ae(e)||Te(e)||_e(e)||Ce(e)}function Qt(e){return e===!0||String(e).toLowerCase()==="true"}function Jt(e){return e===!1||String(e).toLowerCase()==="false"}function Le(e){if(e===g)return!0;if(typeof e=="boolean")return!1;if(typeof e=="number")return Number.isNaN(e)||!1;if(typeof e=="object"&&e!==null){const t=we(e);return["set","map"].includes(t)||["weakmap","weakset"].includes(t)?e.size===0:Object.keys(e).length===0}return D(e)||!e}function j(e){return typeof e=="string"}function b(e){return e==="undefined"||typeof e>"u"}function Ne(e,t,n){const i=[...n];return i[e]=t(i[e],e),i}const Zt=u(Ne);function ve(e,t){return e<=0?[t]:(e=~~e,Array.from({length:Math.ceil(t.length/e)},(n,i)=>t.slice(i*e,i*e+e)))}const en=u(ve);function xe(e,t){return[...ze(t),e]}const tn=u(xe);function Se(e,t){if(!m(t))throw new TypeError("arr \u5FC5\u987B\u662F\u6570\u7EC4");if(!t.length)return[];const n=[];return t.reduce((i,a,o)=>{const p=e(a,o),d=n.indexOf(p),Ge=~d?d:n.push(p)-1;return(i[Ge]||=[]).push(a),i},[])}const nn=u(Se);function Ee(e,t){return t.every((n,i)=>e(n,i))}const sn=u(Ee);function We(e,t){return t.filter((n,i)=>e(n,i))}const an=u(We);function Me(e,t){return t.find((n,i)=>e(n,i))}const rn=u(Me);function Be(e,t){return t.findIndex((n,i)=>e(n,i))}const on=u(Be);function Fe(e,t){return t.reduce((n,i)=>{const a=e(i);return n[a]||=[],n[a].push(i),n},{})}const un=u(Fe);function Pe(e,t){const n=t.length;let i=0;const a=[];for(;i<n;){let o=i+1;for(;o<n&&e(t[o],t[o-1]);)++o;a.push(t.slice(i,o)),i=o}return a}const cn=u(Pe);function Re(e,t){return t.includes(e)}const pn=u(Re);function ke(e,t){return t.join(e)}const ln=u(ke);function Ie(e,t){return Array.from({length:t},(n,i)=>e(i))}const De=u(Ie);function je(e,t){return t.map((n,i)=>e(n,i))}const fn=u(je);function He(e,t){if(!m(t)&&typeof t!="string")throw new TypeError("arr \u5FC5\u987B\u662F\u6570\u7EC4");if(e<0&&(e=t.length+e),!(e<0||e>=t.length))return t[e]}const dn=u(He);function H(e,t,n){return n.reduce((i,a,o)=>e(i,a,o),t)}const gn=u(H);function Oe(e,t){return H((n,i,a)=>(n[e(i,a)?"right":"left"].push(i),n),{left:[],right:[]},t)}const hn=u(Oe);function Ue(e,t){return De(()=>e,t)}const mn=u(Ue);function $e(e,t){return t.some((n,i)=>e(n,i))}const yn=u($e);function Ve(e,t){if(!m(t)&&!j(t))throw new TypeError("arr \u5FC5\u987B\u662F\u6570\u7EC4\u6216\u5B57\u7B26\u4E32");return t.slice(0,e)}const wn=u(Ve);function Xe(e,t){return[e,t]}const bn=u(Xe);function ze(e){return D(e)?[]:m(e)?e:z(e)?Array.from(e):[e]}function An(e,t=0,n=0){return t<=0?[e]:e.slice(n).reduce((i,a,o)=>(o%t===0&&i.push([]),i[i.length-1].push(a),i),[])}async function Tn(e,t){if(!Array.isArray(e))throw new TypeError("arr \u5FC5\u987B\u662F\u6570\u7EC4");return!t||typeof t!="function"?e:(await Promise.all(e.map(async(n,i)=>await t(n,i)?n:null))).filter(Boolean)}export{pn as $,Ze as A,ze as B,Tn as C,Ne as D,Ke as E,Zt as F,ve as G,en as H,g as I,xe as J,tn as K,Se as L,nn as M,Ee as N,sn as O,We as P,an as Q,Me as R,qe as S,rn as T,Be as U,on as V,Fe as W,un as X,Pe as Y,cn as Z,Re as _,Yt as a,_t as a$,ke as a0,ln as a1,Ie as a2,De as a3,je as a4,fn as a5,He as a6,dn as a7,Oe as a8,hn as a9,K as aA,q as aB,at as aC,rt as aD,ot as aE,ut as aF,ct as aG,pt as aH,lt as aI,T as aJ,v as aK,x as aL,ft as aM,S as aN,W as aO,dt as aP,Q as aQ,gt as aR,ht as aS,mt as aT,bt as aU,At as aV,M as aW,B as aX,F as aY,ie as aZ,Tt as a_,H as aa,gn as ab,Ue as ac,mn as ad,$e as ae,yn as af,Ve as ag,wn as ah,Xe as ai,bn as aj,et as ak,st as al,l as am,_ as an,I as ao,$t as ap,ye as aq,r as ar,Vt as as,L as at,f as au,A as av,y as aw,N as ax,w as ay,Y as az,c as b,Ct as b0,Lt as b1,Nt as b2,vt as b3,ae as b4,re as b5,oe as b6,ue as b7,ce as b8,pe as b9,be as bA,_e as bB,Ce as bC,Qt as bD,Jt as bE,Le as bF,j as bG,b as bH,C as bI,le as ba,xt as bb,St as bc,fe as bd,Et as be,Wt as bf,Mt as bg,Bt as bh,P as bi,R as bj,E as bk,Ft as bl,Pt as bm,Rt as bn,k as bo,kt as bp,It as bq,Dt as br,jt as bs,de as bt,ge as bu,he as bv,me as bw,Ht as bx,z as by,m as bz,it as c,D as d,h as e,Ae as f,we as g,Te as h,G as i,Xt as j,Kt as k,Ot as l,Gt as m,Ut as n,s as o,An as p,qt as q,u as r,zt as s,X as t,U as u,Qe as v,O as w,$ as x,Je as y,V as z};