UNPKG

@cmtlyt/base

Version:
34 lines (31 loc) 31.1 kB
import{c as y,a as v,b as O,w as g,g as E,S as I,d as it,s as m,e as N,f as at,h as P,j as ot,k as ut,o as k,l as A,m as ct,I as B,n as _,p as lt,q as ht}from"./shared/base.CBZTi4S8.mjs";export{E as EMPTY,F as adjust,D as adjust_,H as aperture,G as aperture_,K as append,J as append_,v as apply,y as applyTo,x as applyTo_,u as apply_,A as argNumLimit,z as argNumLimit_,C as asyncFilter,ak as cacheReturnValue,M as collectBy,L as collectBy_,r as curry,O as every,N as every_,Q as filter,P as filter_,T as find,V as findIndex,U as findIndex_,R as find_,ap as gc,ao as generateClassName,am as getAliAppEnv,B as getArray,an as getDeviceInfo,aq as getOsType,as as getSpace,ar as getUserAgent,X as groupBy,W as groupBy_,Z as groupWith,Y as groupWith_,$ as includes,_ as includes_,bb as isAliApp,bs as isAliAppMiniApp,aT as isAliAppWeb,au as isAliMiniApp,b3 as isAliMiniappPlatform,b9 as isAliPay,aO as isAliPayWeb,bf as isAliUa,br as isAliWebInMiniApp,b0 as isAlipayApp,bi as isAlipayMiniWeb,aW as isAlipayMiniapp,az as isAndroid,bz as isArray,by as isArrayLike,b1 as isBaiduSmartProgram,bB as isBlobUrlString,av as isByteDanceMicroApp,be as isCaiNiao,a$ as isCaiNiaoApp,bd as isCaiNiaoBusiness,aB as isChrome,bC as isDataUrlString,bm as isDingTalk,aU as isDingdingMiniapp,aG as isEdge,bF as isEmpty,bE as isFalse,aC as isFirefox,bg as isHmApp,ay as isIOS,bx as isIOSNotchScreen,bw as isIPhone14PM,bt as isIPhoneX,bv as isIPhoneXR,bu as isIPhoneXSMax,i as isInIframe,aH as isKraken,b2 as isKuaiShouMiniProgram,bk as isLBMiniWeb,aR as isLST,b8 as isLT,bj as isLTMiniWeb,aY as isLTMiniapp,b5 as isLTNode,aK as isLTWeb,aS as isLXB,aZ as isMMCMiniapp,at as isMiniApp,bA as isNaN,aE as isNewEdge,aF as isOldEdge,aA as isOpenHarmony,aI as isQuickApp,aD as isSafari,bG as isString,b7 as isTB,bl as isTBMiniWeb,aX as isTBMiniapp,b4 as isTBNode,aJ as isTBWeb,aV as isTaobaoMiniapp,aL as isTbLive,aM as isTbWebEnv,ba as isTmall,bD as isTrue,aQ as isTuan,bn as isTuanWebview,bH as isUndef,aw as isWeChatMiniProgram,aP as isWebInDingding,bq as isWebInMiniApp,bc as isWechat,bp as isWechatH5,bo as isWechatMiniWeb,b6 as isWechatNode,aN as isWechatWeb,ax as isWeex,a_ as isXiNiaoapp,bh as isYouKu,a1 as join,a0 as join_,a3 as makeBy,a2 as makeBy_,a5 as map,a4 as map_,al as memoize,a7 as nth,a6 as nth_,a9 as partition,a8 as partition_,t as placeholderFunc,ab as reduce,aa as reduce_,ad as replicate,ac as replicate_,af as some,ae as some_,ah as take,ag as take_,aj as zip,ai as zip_}from"./shared/base.CBZTi4S8.mjs";import{a as $,b as ft,c as pt}from"./shared/base.BoMT0SDK.mjs";export{i as functor,d as isObject,e as isPlainObject}from"./shared/base.BoMT0SDK.mjs";export{c as compose,p as pipe,i as utils}from"./shared/base.HzEhohIW.mjs";import"ms";const ne=()=>{};function S(e,t){const s=n=>{if(t){t(n);return}throw n};try{const n=e();return $(n)&&n.catch(s),n}catch(n){s(n)}}function re(e,...t){try{return e(...t)}catch(s){return s}}function dt(e,t){return e(...t||[])}function yt(e){try{return[null,e()]}catch(t){return[t,null]}}async function mt(e){try{return[null,await e()]}catch(t){return[t,null]}}async function ie(e){try{return[null,await e]}catch(t){return[t,null]}}const ae=e=>new Promise(t=>setTimeout(t,e));function oe(e){const t=x();for(;x()-t<e;);}function bt(e,t=1e3,s=!1){if(t<=0)return e;let n=null,r=null;const i=()=>{n=null,r=null};return y(()=>s?(...a)=>(r||=v(),n?clearTimeout(n):S(()=>{const o=e(...a);$(o)?o.then(r.resolve,r.reject):r.resolve(o)},r.reject),n=setTimeout(i,t),r.promise):(...a)=>{r||=v();const o=r;return n&&clearTimeout(n),n=setTimeout(()=>{S(()=>{const u=e(...a);$(u)?u.then(c=>{o.resolve(c),i()},o.reject):(o.resolve(u),i())},o.reject)},t),r.promise})}function ue(e,t=1e3,s=!1){if(t<=0)return e;const n=bt(e,t,s);return(...r)=>{n(...r)}}function ce(e,t=100,s=!0){if(t<=0)return e;let n=null;return y(()=>s?(...r)=>{n||(e(...r),n=setTimeout(()=>{n=null},t))}:(...r)=>{n||(n=setTimeout(()=>{e(...r),n=null},t))})}const q=y(()=>globalThis.requestIdleCallback?(e,t,s,n)=>{requestIdleCallback(r=>{if(r.timeRemaining()>0)try{const i=e(...t);s(i)}catch(i){n(i)}else q(e,t,s,n)})}:globalThis.requestAnimationFrame?(e,t,s,n)=>{const r=x();requestAnimationFrame(()=>{if(x()-r<16.6)try{const i=e(...t);s(i)}catch(i){n(i)}else q(e,t,s,n)})}:(e,t,s,n)=>{setTimeout(()=>{try{const r=e(...t);s(r)}catch(r){n(r)}},0)});function le(e){return t=>{const s=[];return new Promise((n,r)=>{const i=async a=>new Promise(q.bind(null,e,a)).then(o=>s.push(o),r);(async()=>{if(typeof t=="number")for(let a=0;a<t;++a)await i([a]);else if(Array.isArray(t))for(const a in t){const o=t[a];await i(o)}n(s)})()})}}function he(e){return(...t)=>e(...t.reverse())}function fe(e,t){return(...s)=>S(()=>e(...s),t)}function pe(e){return function(...t){return yt(()=>e.call(this,...t))}}function de(e){return function(...t){return mt(()=>e.call(this,...t))}}const x=y(()=>typeof performance<"u"?()=>performance.now():()=>Date.now());function ye(e){return O()?typeof window>"u"?!1:window?.CSS?.supports?.(e)||!1:(g("caniuse \u53EA\u80FD\u5728\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u4F7F\u7528"),!1)}function U(e){return O()?typeof window>"u"?!1:typeof window[e]<"u":(g("caniuse \u53EA\u80FD\u5728\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u4F7F\u7528"),!1)}function me(e){return typeof e=="function"}function be(e){return g("\u8BE5\u65B9\u6CD5\u5B58\u5728\u751F\u4EA7\u73AF\u5883\u548C\u5F00\u53D1\u73AF\u5883\u7ED3\u679C\u4E0D\u4E00\u81F4\u98CE\u9669, \u8BF7\u8C28\u614E\u4F7F\u7528, \u4F8B\u5982\u4F7F\u7528 babel \u8F6C\u6362\u540E async \u51FD\u6570\u4F1A\u53D8\u6210\u666E\u901A\u51FD\u6570"),E(e)==="asyncfunction"}function ge(e){return e instanceof Object?typeof Object.getPrototypeOf(e).constructor=="function":!1}function z(e,t=new WeakMap){if(e===null||typeof e!="object"||I.includes(E(e)))return e;if(t.has(e))return t.get(e);const s=Array.isArray(e)?[]:{};t.set(e,s);for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(s[n]=z(e[n],t));return s}function gt(e,t){const s=E(e);if(I.includes(s))return e;if(s!==E(t))return I.includes(E(t))?t:(g("\u4F20\u5165\u7684\u4E24\u4E2A\u53C2\u6570\u7C7B\u578B\u4E0D\u540C,\u65E0\u6CD5\u5408\u5E76"),e);if(s==="string"||s==="number")return e+t;if(Array.isArray(e))return e.concat(t);if(s==="object")for(const n in t){const r=t[n];let i=e[n]??r;!I.includes(E(i))&&typeof r=="object"&&r!==null&&(i=e[n]||(Array.isArray(r)?[]:{}),i=gt(i,r)),e[n]=i}return e||t}function wt(e,...t){return t.reduce((s,n)=>gt(s,n),e)}function we(e,...t){return e=z(e),wt(e,...t)}const j=y(()=>typeof Object.fromEntries=="function"?e=>Object.fromEntries(e):typeof Array.from=="function"&&typeof Object.assign=="function"?e=>{const t={};return Array.from(e,([s,n])=>t[s]=n),t}:e=>{const t={};return S(()=>{for(const[s,n]of e)t[s]=n},()=>{const s=e[Symbol.iterator]();let n=s.next();for(;!n.done;){const[r,i]=n.value;t[r]=i,n=s.next()}}),t}),Ct=y(()=>typeof Object.entries=="function"?(e,t)=>{it(e)||Object.entries(e).forEach(([s,n])=>t(n,s))}:(e,t)=>{Object.keys(e).forEach(s=>{t(e[s],s)})}),Ce=y(()=>typeof Object.entries=="function"?(e,t)=>j(Object.entries(e).map(([s,n])=>[s,t(n,s)])):(e,t)=>{const s={};return Object.keys(e).forEach(n=>{s[n]=t(e[n],n)}),s}),Fe=y(()=>typeof Object.entries=="function"?(e,t)=>j(Object.entries(e).filter(([s,n])=>t(n,s))):(e,t)=>{const s={};return Object.keys(e).forEach(n=>{t(e[n],n)&&(s[n]=e[n])}),s}),Ee=y(()=>typeof Object.entries=="function"?(e,t,s)=>Object.entries(e).reduce((n,[r,i])=>t(n,i,r,e),s):(e,t,s)=>Object.keys(e).reduce((n,r)=>t(n,e[r],r,e),s)),ke=y(()=>typeof Object.entries=="function"?(e,t)=>Object.entries(e).some(([s,n])=>t(n,s)):(e,t)=>Object.keys(e).some(s=>t(e[s],s))),Te=y(()=>typeof Object.entries=="function"?(e,t)=>Object.entries(e).every(([s,n])=>t(n,s)):(e,t)=>Object.keys(e).every(s=>t(e[s],s))),Ft=y(()=>typeof Object.entries=="function"?(e,t)=>Object.entries(e).find(([s,n])=>t(n,s))?.[1]:(e,t)=>{const s=Object.keys(e).find(n=>t(e[n],n));return s?e[s]:void 0});function Et(e,t,s){return new Promise((n,r)=>{t=new RegExp(t);const i=e.match(t);if(!i){n(e);return}(async()=>{try{const a=await s(...Array.from(i)).catch(r);n(e.replace(t,a))}catch(a){r(a)}})()})}async function Ae(e,t,s){if(typeof s=="string")return e.replace(t,s);if(typeof s!="function")throw new TypeError("replacer \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6216\u51FD\u6570");return typeof t=="string"?Et(e,t,s):t instanceof RegExp?t.global?new Promise((n,r)=>{let i,a=0;const o=[];for(i=t.exec(e);i!==null;){const c=s(...Array.from(i)),h=e.slice(a,i.index);a=i.index+i[0].length,o.push(h,c),i=t.exec(e)}const u=e.slice(a);o.push(u),(async()=>{const c=await Promise.all(o).catch(r);c&&n(c.join(""))})()}):Et(e,t,s):e}async function Be(e){const t=e.getReader(),s=[];let n="";for(;;){const{done:i,value:a}=await t.read();if(i)break;s.push(a)}const r=new TextDecoder("utf-8");for(const i of s)n+=r.decode(i);return n+=r.decode(),n}async function kt(e){const t=e.getReader(),s=[];let n=0;for(;;){const{done:a,value:o}=await t.read();if(a)break;s.push(o),n+=o.byteLength}const r=new ArrayBuffer(n);let i=0;for(const a of s){const o=new Uint8Array(a);new Uint8Array(r,i,o.length).set(o),i+=o.length}return r}function W(e){const t=new Uint8Array(e).reduce((s,n)=>s+String.fromCharCode(n),"");return btoa(t)}const Se=W;function K(e){const t=atob(e),s=t.length,n=new Uint8Array(s);for(let r=0;r<s;r++)n[r]=t.charCodeAt(r);return n}function Tt(e){g("\u5F53\u524D\u5B57\u7B26\u4E32\u4F7F\u7528 chunk \u65B9\u5F0F\u751F\u6210, \u8BF7\u4F7F\u7528 base64StringToBlob \u4EE3\u66FF, \u540E\u7EED chunkBase64StringToBlob \u65B9\u6CD5\u5C06\u4F1A\u79FB\u9664");const t=e.split("|");return new Blob(t.map(s=>K(s)))}function X(e){return e.includes("|")?Tt(e):new Blob([K(e)])}const je=At;async function At(e){return X(e).arrayBuffer()}function De(e){const t=new TextEncoder;return new ReadableStream({start(s){s.enqueue(t.encode(e)),s.close()}})}function ve(e){return new TextEncoder().encode(e)}function Oe(e){return new TextDecoder().decode(e)}async function Bt(e){const t=await kt(e);return W(t)}const $e=Bt,xe=St;function St(e){return X(e).stream()}function Me(e){return new ReadableStream({start(t){t.enqueue(e),t.close()}})}const Ie=jt;async function jt(e){const t=await e.arrayBuffer();return W(t)}function Pe(e,t){if(!e&&!m().location)throw new TypeError("\u5F53\u524D\u73AF\u5883\u4E0D\u5B58\u5728 location, \u65E0\u6CD5\u4F7F\u7528\u9ED8\u8BA4\u503C, \u8BF7\u4F20\u9012 path \u53C2\u6570");if(O()&&!U("URL")||N()&&!m().URL)throw new TypeError("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 URL, \u65E0\u6CD5\u4F7F\u7528 parseUrl \u65B9\u6CD5");const{hashQueryToSearchParams:s}=t||{};let n=e||=m().location.href;if(s&&(at(n)||P(n))){const[r,i]=n.split("#"),[a,o]=(i||"").split("?"),[u,c]=r.split("?"),h=`${c||""}${c?o?`&${o}`:"":o||""}`;n=`${u}${h?`?${h}`:""}${a?`#${a}`:""}`}return new URL(n)}function Dt(e){if(O()&&!U("URLSearchParams")||N()&&!m().URLSearchParams)throw new TypeError("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 URL, \u65E0\u6CD5\u4F7F\u7528 parseSearch \u65B9\u6CD5");return new URLSearchParams(e)}function _e(e){return typeof e=="string"?S(()=>j(Dt(e).entries()),()=>j(e.replace(/^\?/,"").split("&").map(t=>t.split("=")))):j(e.entries())}function G(e,t){const{singleQuotes:s=!1}=t||{};switch(typeof e){case"string":return s?`'${e}'`:`"${e}"`;case"number":case"boolean":case"bigint":return e.toString();case"symbol":return e.toString().replace(/^Symbol\((.*)\)$/,`Symbol(${s?"'$1'":'"$1"'})`);case"function":{const n=e.toString();return n.startsWith("(")||n.startsWith("function ")?n:`function ${n}`}case"object":return Q(e,t);default:return JSON.stringify(e)}}function Q(e,t){const s=E(e);if(s==="regexp")return e.toString();if(s==="null")return"null";if(s==="date")return`new Date(${e.getTime()})`;const{wrap:n=!1,indentChar:r=" ",indent:i=n?2:0}=t||{},a=ot(r,i),o=Array.isArray(e),u=[];return Ct(e,(c,h)=>{const f=dt(()=>o?`${n?a:""}${G(c,t)}`:typeof c=="object"?`${n?a:""}${h}: ${Q(c,{...t,indent:i+2})}`:`${n?a:""}${h}: ${G(c,t)}`);u.push(f)}),o?`[${n?` `:""}${u.join(n?`, `:", ")}${n?` `:""}]`:`{${n?` `:""}${u.join(n?`, `:", ")}${n?` `:""}}`}function Ue(e=new Date,t){return g("\u672A\u6765\u4F1A\u5B9E\u73B0~"),t?e.toLocaleString():`${e.valueOf()}`}class L{#e;#t;static group(t,s=0){if(typeof t!="function")throw new TypeError("func \u5FC5\u987B\u662F\u4E00\u4E2A\u51FD\u6570");const n=new L(s);return t(n)??n}constructor(t=0){this.#e=t,this.#t=0}#s(t){if(t instanceof L)return t.getCurrValue();if(ut(t))return t;throw new TypeError("value \u5FC5\u987B\u662F\u4E00\u4E2A\u6570\u5B57\u6216 Calculator")}add(t){return t=this.#s(t),this.#t=this.#t+this.#e,this.#e=t,this}sub(t){return t=this.#s(t),this.#t=this.#t+this.#e,this.#e=-t,this}mut(t){return t=this.#s(t),this.#e*=t,this}div(t){return t=this.#s(t),this.#e/=t,this}getCurrValue(){return this.#t+this.#e}valueOf(){return this.#e=this.getCurrValue(),this.#t=0,this.#e}}const vt=k(()=>typeof m().document?.execCommand=="function"),V=k(()=>m().document?.queryCommandSupported?.("copy")&&vt()),Ot=k(()=>m().document?.queryCommandSupported?.("paste")&&vt()),Y=k(()=>P(m().location?.href)&&!!navigator.clipboard?.writeText||!1),$t=k(()=>Y()||V()||!1),xt=k(()=>P(m().location?.href)&&!!navigator.clipboard?.readText||!1),We=k(()=>xt()||Ot()||!1),Re=Y,Le=$t,He=y(()=>{if(Y())return e=>{navigator.clipboard.writeText(e)};if(V()){const e=m().document;return t=>{const s=e.createElement("input");s.setAttribute("value",t),e.body.appendChild(s),s.select(),e.execCommand("copy"),e.body.removeChild(s)}}return e=>{g("copy not supported:> ",e)}}),Ne=y(()=>{if(xt())return()=>navigator.clipboard.readText();if(Ot()){const e=m().document;return()=>{const t=e.createElement("input");e.body.appendChild(t),t.select();try{e.execCommand("paste")}catch{return Promise.reject(new Error("paste not supported"))}const s=t.value;return e.body.removeChild(t),Promise.resolve(s)}}return()=>(g("paste not supported"),Promise.reject(new Error("paste not supported")))}),qe=y(()=>{if(Re())return()=>{navigator.clipboard.writeText("")};if(V()){const e=m().document;return()=>{const t=e.createElement("input");e.body.appendChild(t),t.select(),e.execCommand("copy"),e.body.removeChild(t)}}return()=>{g("clear not supported")}}),ze={copy:He,paste:Ne,clear:qe,get isCopyable(){return $t()},get isPasteable(){return We()},get isClearable(){return Le()}};function Ke(e){return{maxConcurrent:3,autoRun:!0,...e}}let J=class Kt{static instanceMap={};#e;#t=[];#s=0;#n=[];#c=!1;#r=null;get#a(){return this.#r&&this.#r.promise}set#a(t){if(t==="finished"&&this.#r){this.#r.resolve(),this.#r=null,this.status="finished";return}this.status=this.#e.autoRun?"running":this.status;const{promise:s,resolve:n}=v();this.#r={promise:s,resolve:n}}get finished(){return this.#i(),this.#a||Promise.resolve()}status="stopped";id;get#p(){if(this.status==="stopped"||this.#s>=this.#e.maxConcurrent)return;let t;do if(t=this.#t.shift(),!t)return;while(t.status!=="waiting");return this.#n.push(t),t}constructor(t,s){const n=Ke(s);this.id=t,this.#e=n}#i(){if(this.#c)throw new Error("queue has been disposed")}#l(){const{maxConcurrent:t}=this.#e;for(let s=this.#s;s<t;++s){const n=this.#p;if(!n){this.#s===0&&this.status==="running"&&(this.#a="finished");break}this.#s++,n.task(n).then(n.resolve.bind(null,n),n.reject)}}#o(t){const{promise:s,resolve:n,reject:r}=v();return{id:A(),promise:s,oriTask:t,task:i=>(i.status="running",t()),status:"waiting",resolve:(i,a)=>{const{id:o,status:u}=i;if(this.#n=this.#n.filter(c=>c.id!==o),this.#s--,n(a),this.#l(),u==="remove")throw new Error(`task ${i.id} Abnormal termination`)},reject:r,changeStatus:(i,a)=>{i.status=a}}}add(t,s={return:"promise"}){this.#i(),this.#a||(this.#a="init");const n=this.#o(t);this.#t.push(n),this.#e.autoRun&&this.#l();let{return:r="promise"}=s;return["id","promise"].includes(r)||(r="promise"),n[r]}#u(t,s){const n=s?[...this.#t,...this.#n]:this.#t;return typeof t=="string"?n.find(r=>r.id===t):n.find(r=>r.oriTask===t)}remove(t){this.#i();const s=this.#u(t,!1);return!s||s?.id==="running"?!1:(s.changeStatus(s,"remove"),!0)}clear(){this.#i(),this.#t=[]}getTaskInfo(t){this.#i();const s=this.#u(t,!0);if(s)return{id:s.id,status:s.status,promise:s.promise,task:s.oriTask}}run(){this.#i(),this.status!=="running"&&(this.status="running",this.#l())}stop(){this.#i(),this.status="stopped"}dispose(){this.#i(),this.stop(),this.clear(),this.status="disposed",this.#c=!0,delete Kt.instanceMap[this.id]}get remainingCount(){return this.#i(),this.#t.length}};function Xe(){return Object.keys(J.instanceMap)}function Ge(e,t="default"){return J.instanceMap[t]||=new J(t,e)}const Qe={get(e){return m().document?.cookie.split("; ").find(t=>t.startsWith(`${e}=`))?.split("=")[1]||""},set(e,t,s={}){const n=m().document;n?.cookie&&(n.cookie=`${e}=${t};${ct(s)}`)},remove(e){const t=m().document;t?.cookie&&(t.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT`)}},Mt={};class M{static getPool(t="",s=5,n){const r=n||(()=>B);return t?Mt[t]??=new M(s,r,t):new M(s,r,t)}#e;#t;#s;#n;usableCount;isClose;constructor(t=5,s=()=>B,n=Symbol("")){this.#e=n,this.#t=Array.from({length:t},(r,i)=>this.#c(s(i))),this.#s=[],this.usableCount=this.#t.reduce((r,i)=>(i.data!==B&&r++,r),0),this.isClose=!1,this.#n=()=>{}}#c(t){return{data:t,__id:A(32)}}#r(t,s=null){if(this.isClose)throw this.#n(t),new Error("\u6C60\u5B50\u5DF2\u5173\u95ED");if(typeof s=="number"){const n=this.#t[s];n.data=t,n.__id=A(32)}else{const n=this.#t.findIndex(r=>r.data===B);if(!~n)throw new Error("\u6C60\u5B50\u5DF2\u6EE1");this.#t[n]=this.#c(t)}++this.usableCount}async#a(t){if(this.isClose)throw new Error("\u6C60\u5B50\u5DF2\u5173\u95ED");const s=this.#t[t];if(!s||s.data===B)return new Promise((h,f)=>{this.#s.push({resolve:h,reject:f})});const{data:n,__id:r}=s,i=()=>{if(this.isClose)throw this.#r(n,t),new Error("\u6C60\u5B50\u5DF2\u5173\u95ED");if(r!==s.__id)throw new Error("\u6570\u636E\u5DF2\u88AB\u8FD4\u8FD8")},a=()=>{this.#r(n,t)};--this.usableCount;const o=function(){if(this===c)return i(),n},u=function(){if(this===c)return i(),a()},c={data(){return o.call(this)},unUse(){return u.call(this)}};return Promise.resolve(c)}put(t){if(this.#r(t),this.#s.length){const{resolve:s}=this.#s.shift();this.get().then(n=>{s(n)})}}async get(){const t=this.#t.findIndex(s=>s.data!==B);return this.#a(t)}close(t){this.#t.forEach(({data:s})=>t(s)),this.#t=[],this.#s=[],this.usableCount=0,this.isClose=!0,this.#n=t,delete Mt[this.#e]}}function It(e,t=5,s){return M.getPool(s,t,e)}function Ve(e=""){return M.getPool(e)}function Ye(e,t=[],s=!1){return` ${t.length?`importScripts("${t.join('", "')}");`:""} const func = ${e}; const { postMessage } = (()=>{ const postMessage = (data) => { self.postMessage({ __clUserCall: true, data }) }; return { postMessage: (data) => postMessage(data) }; })(); self.onmessage = async (e) => { const { callId, data: args } = e.data try { const result = await func.apply(null, ${s?"[postMessage, ...args]":"args"}); self.postMessage({ __clSysCall: true, type: 'success', result, callId }); } catch (e) { self.postMessage({ __clSysCall: true, callId, type: 'error', error: e }) } } self.onerror = (e) => { self.postMessage({ __clSysCall: true, type: 'error', error: e }) }`}function Pt(e){return new Worker(e)}function Z(){const e=[],t=n=>{e.push(n)},s=n=>{e.splice(e.indexOf(n),1)};return{on:t,remove:s,clearOn:()=>{e.length=0},onOnce:n=>{const r=(...i)=>{n(...i),s(r)};t(r)},emit:n=>{for(const r of e)r(n)}}}function _t({emit:e,type:t,result:s,error:n,resolve:r=()=>{},reject:i=()=>{},isSysCall:a,eventData:o}){if(a)t==="success"?r(s):i(n);else{const{__clUserCall:u,data:c}=o;e(u?c:o)}}function Je(e){const t=Pt(e);let s=!1,n={};const{emit:r,...i}=Z();return t.onmessage=a=>{const{type:o,result:u,error:c,callId:h,__clSysCall:f}=a.data,{resolve:d,reject:b}=n[h]||{};f&&delete n[h],_t({emit:r,type:o,result:u,error:c,resolve:d,reject:b,isSysCall:f,eventData:a.data})},{run:async(...a)=>{if(s)throw new Error("worker\u8D44\u6E90\u5DF2\u91CA\u653E");const o=A(16);return new Promise((u,c)=>{n[o]={resolve:u,reject:c},t.postMessage({callId:o,data:a})})},dispose:()=>{t.terminate(),n=null,s=!0,URL.revokeObjectURL(e)},...i}}function Ze(e){let t=!1;const{emit:s,...n}=Z();return{run:async(...r)=>{if(t)throw new Error("worker\u8D44\u6E90\u5DF2\u91CA\u653E");const i=Pt(e);return new Promise((a,o)=>{i.onmessage=u=>{const{type:c,result:h,error:f,__clSysCall:d}=u.data;d&&i.terminate(),_t({emit:s,type:c,result:h,error:f,resolve:a,reject:o,isSysCall:d,eventData:u.data})},i.postMessage({data:r})})},dispose:()=>{t=!0,URL.revokeObjectURL(e)},...n}}function ts(e){const t=[],s=[];return e.forEach(n=>{typeof n=="string"?s.push(n):typeof n=="function"&&t.push(n)}),s.push(_(t.map(n=>`function ${n.name}(...args) { return (${n})(...args); }`).join(` `))),s}function Ut(e,t=[],s={}){if(!U("Worker"))return g("\u4E0D\u652F\u6301 web worker \u5DF2\u964D\u7EA7"),{run:async(...o)=>await e(...o),dispose:()=>{},...Z()};const{reuse:n=!0,needPost:r=!1}=s||{},i=Ye(e,ts(t),r),a=_(i);return n?Je(a):Ze(a)}const es=["FormData","binary"],ss=["json","string"],ns=["POST","PUT"],rs=["chunk","file"];function w(e,t,s,n,r){return(Array.isArray(t)?!t.includes(E(s)):E(s)!==t)||r&&!r.includes(s)?(g(`options.${e} \u5FC5\u987B\u662F${t}\uFF0C\u5DF2\u4F7F\u7528\u9ED8\u8BA4\u503C ${n} \u4EE3\u66FF`),n):s}function is(e){if(!e)throw new TypeError("options \u4E0D\u80FD\u4E3A\u7A7A");if(typeof e!="object")throw new TypeError("options \u5FC5\u987B\u662F\u5BF9\u8C61");if(!e.url&&e.url!=="string")throw new TypeError("options.url \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32");const{url:t,maxConcurrent:s,concurrentNode:n,chunkSize:r,dataType:i,dataKey:a,responseType:o,retryCount:u,requestMethod:c,headers:h,headersHandler:f,bodyHandler:d,requestOptions:b}=e,T=w("dataType","string",i,"FormData",es);return{url:t,maxConcurrent:w("maxConcurrent","number",s,3),concurrentNode:w("concurrentNode","string",n,"chunk",rs),chunkSize:w("chunkSize","number",r,1024*512),dataType:T,dataKey:w("dataKey","string",a,"file"),responseType:w("responseType","string",o,"json",ss),retryCount:w("retryCount","number",u,0),requestMethod:w("requestMethod","string",c,"POST",ns),headers:w("headers","object",h,{"Content-Type":T==="FormData"?"multipart/form-data":"application/octet-stream"}),headersHandler:w("headersHandler",["function","asyncfunction"],f,()=>{}),bodyHandler:w("bodyHandler",["function","asyncfunction"],d,()=>{}),requestOptions:w("requestOptions","object",b,{})}}const as=async({uploadInfo:e,fileUrl:t,chunkIdxInfo:s,chunkSize:n,serverPath:r,dataKey:i,responseType:a,requestMethod:o,headers:u,chunkIdxs:c,retryCount:h,dataType:f,requestOptions:d})=>{const b=[],T=await fetch(t).then(l=>l.blob()),[tt,Xt]=s,et=c.length>0?c:Array.from({length:Xt-tt},(l,p)=>tt+p),st=l=>{if(n<=0)return T.slice();const p=l*n,C=Math.min(T.size,p+n);return T.slice(p,C)},Gt=async l=>a==="json"?await l.json():a==="string"?await l.text():"none",Qt=async(l,p)=>{const C=await Gt(p),F={chunkIdx:l,status:"loading",response:C};p.status===200?F.status="success":(F.status="fail",b.push(l)),self.postMessage(F)},Vt=(l,p)=>{b.push(l),self.postMessage({chunkIdx:l,status:"error",message:p,uploadInfo:e})},Yt=userHeadersHandler||(()=>{}),Jt=userBodyHandler||(()=>{}),Zt=async l=>{const p=st(l),C=new FormData;C.append(i,p),C.append("chunkIdx",`${l}`);const F=await Jt({chunk:p,chunkIdx:l,customOption:e.customOption});return typeof F=="object"&&Object.keys(F).forEach(rt=>{C.append(rt,F[rt])}),C},te=async l=>st(l),ee=async l=>{if(f==="FormData")return Zt(l);if(f==="binary")return te(l)},se=async l=>{const p=await Yt({chunkIdx:l,currentHeanders:u,customOption:e.customOption});return{...u,...p}},nt=async l=>{for(const p of l){const C=await ee(p),F=await se(p);console.log("run",F),await fetch(r,{...d,method:o,body:C,headers:F}).then(Qt.bind(null,p)).catch(Vt.bind(null,p))}};await nt(et);for(let l=0;l<h&&b.length!==0;++l){const p=[...b];b.length=0,await nt(p)}return{status:"finished",message:"\u4E0A\u4F20\u7ED3\u675F",chunks:et,errorChunks:b}},D={waiting:"waiting",uploading:"uploading",closed:"closed"};async function os(e){if(ft(e)||pt(e))return Promise.resolve(e);if(ht(e))return await fetch(e).then(t=>t.blob())}function Wt(e){return e?e.includes("=>")||e.startsWith("function")||e.startsWith("async function")?e:e.startsWith("async")?e.replace("async","async function "):`function ${e}`:""}function us({bodyHandler:e,headersHandler:t}){const s=Wt(e?.toString()),n=Wt(t?.toString());return _(` ${e?`const userBodyHandler = ${s};`:""} ${t?`const userHeadersHandler = ${n};`:""} `)}const Rt={};class H{static getInstance(t,s=!1){const{url:n}=t;return s?Rt[n]=new H(t):Rt[n]??=new H(t)}#e;#t;#s;#n;#c;#r;#a;#p;#i;#l;#o;#u;#f;#h;constructor(t){const s=t;this.#e=t.url,this.#t=s.maxConcurrent,this.#s=s.concurrentNode,this.#n=s.chunkSize,this.#c=s.dataType,this.#r=s.dataKey,this.#a=s.responseType,this.#p=s.retryCount,this.#i=s.requestMethod;const{bodyHandler:n,headersHandler:r}=s;this.#l=s,this.#o=[],this.#u=D.waiting,this.#f={};const i=us({bodyHandler:n,headersHandler:r});this.#h=It(()=>Ut(as,[i],{reuse:!1}),this.#t,Symbol("uploader"))}#b(t,s){t(s)}#g(t){return t.some(s=>s.data?.errorChunks?.length)?"error":"success"}#w(t){return t.reduce((s,n)=>s.concat(n.data?.errorChunks||[]),[])}async#C(t,s,n){const{id:r,workerTotal:i}=s,a=this.#f[r];a.push({data:n}),a.length>=i&&(t({taskInfo:a,taskStatus:this.#g(a),errorChunks:this.#w(a),customOption:s.customOption}),delete this.#f[r],Object.keys(this.#f)||(this.#u=D.waiting))}async#d({uploadInfo:t,fileUrl:s,start:n,end:r,onProgress:i,worker:a,resolve:o,reject:u,chunkIdxs:c=[]}){const h={uploadInfo:t,chunkIdxs:c,fileUrl:s,chunkIdxInfo:[n,r],chunkSize:this.#n,serverPath:this.#e,dataKey:this.#r,responseType:this.#a,requestMethod:this.#i,headers:this.#l.headers,retryCount:this.#p,dataType:this.#c},f=this.#b.bind(this,i);return a.on(f),a.run(h).then(this.#C.bind(this,o,t),u).finally(()=>{a.remove(f),this.#y()})}async#F({runWorkerBaseData:t,retryChunksMap:s,taskChunkSize:n,chunkTotal:r}){if(s.length){for(const i in s){const a=await this.#h.get();this.#d({chunkIdxs:s[i],start:0,end:0,worker:a.data(),...t})}return}if(this.#s==="chunk"){for(let i=0;i<this.#t;++i){const a=await this.#h.get(),o=i*n,u=Math.min(r,o+n);this.#d({start:o,end:u,worker:a.data(),...t})}return}if(this.#s==="file"){t.workerTotal=1;const i=await this.#h.get();this.#d({start:0,end:r,worker:i.data(),...t})}}#E(t){return t.length?t.length:this.#s==="chunk"?this.#t:this.#s==="file"?1:0}async#y(){if(this.#u===D.closed||this.#o.length===0||this.#h.usableCount===0)return;this.#u=D.uploading;const{file:t,resolve:s,reject:n,chunkIdxs:r=[],onProgress:i=()=>{},customOption:a={}}=this.#o.shift(),o=await os(t),u=URL.createObjectURL(o),c=this.#n<=0?1:Math.ceil(o.size/this.#n),h=Math.ceil(c/this.#t),f=lt(r,this.#t),d={id:A(32),workerTotal:this.#E(f),customOption:a};this.#f[d.id]=[];const b={uploadInfo:d,fileUrl:u,onProgress:i,resolve:s,reject:n};this.#F({runWorkerBaseData:b,retryChunksMap:f,taskChunkSize:h,chunkTotal:c})}async#m(t,{onProgress:s=()=>{},chunkIdxs:n=[],customOption:r}){return new Promise((i,a)=>{this.#o.push({file:t,onProgress:s,chunkIdxs:n,resolve:i,reject:a,customOption:r}),this.#y()})}retry(t,s,n){return this.#m(t,{...n,chunkIdxs:s})}upload(t,s){if(this.#u!==D.closed)return this.#m(t,{...s||{},chunkIdxs:[]})}abort(t){return!!this.#o.splice(this.#o.findIndex(s=>s.file===t),1)?.length}clear(){this.#o=[]}close(){this.#u=D.closed,this.#h.close(t=>t.dispose())}}function cs(e,t=!1){const s=is(e);return H.getInstance(s,t)}function R(e){return e.join("|")}function ls(e,t){const{types:s,match:n,base:r}=e;if(n&&n.matchFunc(t,s))return n.callback(...t);if(!r)throw new TypeError("\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u51FD\u6570");return r.callback(...t)}function Lt(e){return $(e)?"promise<any>":Array.isArray(e)?`${Lt(e[0])}[]`:typeof e}function hs(e){return e.map(Lt)}function Ht(e,t){return e.startsWith("promise")?t.toLowerCase().startsWith("promise"):e===t}function Nt(e,t){const s=R(e).includes("..."),n=e.length-(s?1:0);if(n>t.length||!s&&n!==t.length)return!1;for(let r=0,i=0,a=e[r],o=t[i];i<t.length;a=e[r],o=t[++i]){if(a==="any"){++r;continue}if(a.startsWith("...")){const[,u]=a.split("...");if(!Ht(u,o))return!1;continue}if(!Ht(a,o))return!1;++r}return!0}function qt(e,t,s){if(s){const r=hs(s);return Ft(e,({types:i})=>Nt(i,r))}if(!t)return;const n=R(t);return e[n]}function fs(e){return{register(t,...s){if(typeof t!="function")throw new TypeError("\u7B2C\u4E00\u4E2A\u53C2\u6570\u5FC5\u987B\u4E3A function \u7C7B\u578B");const[n,...r]=s,i=typeof n=="function";if(i||r.unshift(n),r.some(d=>typeof d!="string"))throw new TypeError("\u5269\u4F59\u53C2\u6570\u5FC5\u987B\u4E3A string \u7C7B\u578B");const a=r.map(d=>d==="void"?"undefined":d==="unknown"?"any":d),o={callback:t,matchFunc:i?n:void 0},u=i?"match":"base",c=a.pop(),h=qt(e,a);if(h?.[u])throw new TypeError(`\u5F53\u524D\u591A\u6001\u5DF2\u5B9E\u73B0, \u7C7B\u578B: ${h.types}`);const f={types:a,returnType:c,[u]:o};return e[R(a)]=Object.assign({},e[R(a)],f),this}}}function zt(){const e={},t=fs(e);return new Proxy((...s)=>{const n=qt(e,void 0,s);if(!n)throw new TypeError("\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u51FD\u6570");return ls(n,s)},{get(s,n,r){return n in t?t[n].bind(r):Reflect.get(s,n,r)}})}export{L as Calculator,W as arrayBufferToBase64String,Se as arrayBufferToChunkBase64String,Me as arrayBufferToStream,Ae as asyncReplace,At as base64StringToArrayBuffer,X as base64StringToBlob,St as base64StringToStream,K as base64StringToUint8Array,Oe as binaryToString,jt as blobToBase64String,Ie as blobToChunkBase64String,y as cacheByReturn,U as caniuse,ye as caniuseCSSFeature,je as chunkBase64StringToArrayBuffer,Tt as chunkBase64StringToBlob,xe as chunkBase64StringToStream,le as chunkTask,ze as clipboard,we as cloneMerge,re as completion,Qe as cookie,_ as createLinkByString,zt as createOverloadFunc,zt as createPolymorphismFunc,It as createPool,cs as createUploader,Ut as createWorkerFunc,ue as debounce,bt as debounceAsync,z as deepClone,Ue as formatDate,j as fromEntries,ct as generateCookieInfo,Xe as getAllQueueIds,lt as getArraySlice,ot as getChar,Ge as getConcurrentQueue,x as getNow,Ve as getPool,A as getRandomString,E as getType,dt as iife,be as isAsyncFunc,pt as isBlob,ge as isConstructor,ft as isFile,me as isFunc,at as isHttpUrlString,P as isHttpsUrlString,N as isNode,it as isNull,ut as isNumber,$ as isPromise,ht as isUrl,O as isWeb,wt as merge,ne as noop,Te as objectEvery,Fe as objectFilter,Ft as objectFind,Ct as objectForEach,Ce as objectMap,Ee as objectReduce,ke as objectSome,Q as objectToString,k as onceFunc,Dt as parseSearch,_e as parseSearchObject,Pe as parseUrl,ie as resultOrError,he as reverseArgs,m as safeGetGlobal,ae as sleep,oe as sleepSync,kt as streamToArrayBuffer,Bt as streamToBase64String,$e as streamToChunkBase64String,Be as streamToString,ve as stringToBinary,De as stringToStream,ce as throttle,G as toString,S as tryCall,fe as tryCallFunc,yt as tryOrError,mt as tryOrErrorAsync,de as tryOrErrorAsyncFunc,pe as tryOrErrorFunc,Nt as typesMatch,g as warning,v as withResolvers};