wsp-toolkit
Version:
Personal toolbox
2 lines (1 loc) • 6.95 kB
JavaScript
;var toolkit=(()=>{var S=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var ft=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},at=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ut(e))!st.call(t,i)&&i!==r&&S(t,i,{get:()=>e[i],enumerable:!(n=it(e,i))||n.enumerable});return t};var lt=t=>at(S({},"__esModule",{value:!0}),t);var gt={};ft(gt,{Vector:()=>R,and:()=>k,at:()=>E,clamp:()=>tt,concatMap:()=>F,curry:()=>y,debounce:()=>M,decimalLength:()=>L,emptyFn:()=>et,identity:()=>V,ifElse:()=>H,isEmpty:()=>a,isExist:()=>l,isIterable:()=>d,isNil:()=>f,isSafeNum:()=>N,iterative:()=>z,last:()=>C,matrixTo:()=>$,once:()=>j,or:()=>U,pipe:()=>K,promiseTry:()=>Y,prop:()=>w,sleep:()=>W,splitIntegerDecimal:()=>Z,throttle:()=>P,toArray:()=>B,toNumberStr:()=>O,toPromiseTuple:()=>J,toggle:()=>_,treeEach:()=>G,typeOf:()=>h,unique:()=>Q,when:()=>v,zip:()=>D,zipWidth:()=>X});function k(...t){for(let e of t)if(typeof e=="function"&&!e()||e===!1)return!1;return!0}var F=(t,...e)=>{let r=[];for(let n of e)if(Array.isArray(n))for(let i of n)r.push(t(i));else r.push(t(n));return r};var y=t=>{let e=(...r)=>r.length>=t.length?t(...r):e.bind(null,...r);return e};function f(t){return t==null}function P(t,e,r={}){let{maxWait:n=e,leading:i=!1,trailing:u=!0}=r||{},p,o=null;function c(){p=null,o=null}function s(...g){clearTimeout(p);let x=Date.now();f(o)&&(i&&t(...g),o=x),x-o>=n&&n!==0?(o=x,t(...g)):p=setTimeout(()=>{c(),u&&t(...g)},e)}return s}function M(t,e,r={}){return P(t,e,{leading:r.leading,trailing:r.trailing,maxWait:0})}var L=t=>{let e=typeof t=="string"?t:t.toString(),r=e.indexOf(".");return r===-1?0:e.length-r-1};function V(t){return t}function l(t){return t!=null}function h(t){return Object.prototype.toString.call(t).replace(/\[\w+ (\w+)]/,"$1")}function a(t){if(f(t))return!0;if(typeof t=="string"||Array.isArray(t))return t.length===0;if(h(t)==="Object")return Object.keys(t).length===0;if(h(t)==="FormData"){let e=t.keys().next().done;return l(e)?e:!0}return!1}var d=t=>l(t)&&typeof t[Symbol.iterator]=="function";function I(t){return typeof t=="number"}function N(t){return t==null?!1:I(t)&&isFinite(t)&&Number.MIN_SAFE_INTEGER<=t&&t<=Number.MAX_SAFE_INTEGER}function z(t){return function(e,...r){if(d(e)){let n=[];for(let i of e)n.push(t(i,...r));return n}return t(e,...r)}}var E=y((t,e)=>e[t<0?e.length+t:t]);function C(t){return E(-1,t)}function $(t){let e=t.replace("matrix(","").replace(")","").split(",").map(o=>Number(o)),r=e[0],n=e[1],i=n/r,u=Math.atan(i)*180/Math.PI,p=r/Math.cos(Math.PI/180*u);return{x:e[4],y:e[5],scale:p,rotate:u}}function j(t){let e=!1,r;return n=>(e||(e=!0,r=t(n)),r)}function U(...t){for(let e of t)if(typeof e=="function"&&e()||e===!0)return!0;return!1}function K(...t){return(...e)=>{let r=e;for(let n of t)r=[n(...r)];return r[0]}}function q(t){let e=[],r=[],n=[],i="",u=s=>/^\d+$/.test(s),p=s=>["'",'"'].includes(s),o=s=>s[s.length-1],c=s=>{(!a(i)||s===!0)&&(u(i)?e.push(parseInt(i)):e.push(i)),i=""};for(let s of t){if(p(s)){if(o(n)===s){n.pop(),c(!0);continue}c(),n.push(s);continue}if(s==="["&&a(n)){c(),r.push(s);continue}if(s==="]"&&a(n)){let g=r.pop();if(f(g))throw new SyntaxError("Unexpected token ']'");c();continue}if(s==="."&&a(r)&&a(n)){c();continue}i+=s}if(c(),!a(r))throw new SyntaxError("\u62EC\u53F7\u6570\u91CF\u4E0D\u5339\u914D");if(!a(n))throw new SyntaxError("\u5F15\u53F7\u6570\u91CF\u4E0D\u5339\u914D");return e}var w=y((t,e)=>(typeof t=="string"&&(t=q(t)),Array.isArray(t)||(t=[t]),t.reduce((r,n)=>{if(!f(r))return r[n]},e)));function W(t){return new Promise(e=>{setTimeout(()=>e(t),t)})}function Z(t){N(t)&&(t=t.toString());let e=[t,""];if(typeof t!="string")return e;let r=t.match(/\.(\d+)$/),n=r&&l(r.index)?r.index:-1;return!(t.indexOf(".")===n)||r&&typeof r[1]!="string"||!(r?N(parseInt(r[1])):!1)||(e[0]=t.substring(0,n),e[1]=t.substring(n+1,t.length)),e}function B(t){return Array.isArray(t)?t:f(t)?[]:I(t)||h(t)==="Boolean"?[t]:d(t)?Array.from(t):[]}function _(t){let e=t.length-1,r=0;return function(n){let i=t[r];return r+=1,r>e&&(r=0),typeof i=="function"?i(n):i}}var T={0:!0,1:!0,2:!0,3:!0,4:!0,5:!0,6:!0,7:!0,8:!0,9:!0},pt={"-":!0,"+":!0,".":!0};function O(t){if(typeof t=="number")return String(t);if(typeof t=="boolean")return t?"1":"0";if(Array.isArray(t))return O(t.flat(1/0).join(""));if(typeof t!="string")return a(t)?"0":"1";let e="",r="",n=0,i=-1,u=0,p=o=>{switch(o){case"-":e=e?"":"-";return;case"+":e=e||"";return;case".":n=6,r="0.",i=1;return;case"0":n=4,r=o;return}T[o]&&(n=1,r+=o)};for(let o of t)if(pt[o]||T[o]){if(n===0){p(o);continue}switch(n){case 4:if(o==="0")continue;o==="."?(n=5,i=r.length,r+=o):T[o]&&(n=1,r=o);continue;case 5:o==="0"?(n=3,r+=o):T[o]&&(n=2,r+=o,u=r.length);continue;case 1:o==="."?(n=6,i=r.length,r+=o):T[o]&&(r+=o);continue;case 6:o==="0"?(n=3,r+=o):T[o]&&(n=2,r+=o,u=r.length);continue;case 3:o==="0"?r+=o:T[o]&&(n=2,r+=o,u=r.length);continue;case 2:T[o]&&(r+=o,o!=="0"&&(u=r.length))}}return n===5?e?"0":"-0":n===3||n===6?`${e}${r.slice(0,i)}`:n===2?`${e}${r.slice(0,u)}`:a(r)||n===0?`${e}0`:`${e}${r}`}function G(t,e,r){let{childKey:n="children",filterNull:i=!0,filterEmpty:u=!0,startLeaf:p=!1}=r||{};if(!Array.isArray(t))return[];let o=(c,s,g)=>c.reduce((x,A,nt,ot)=>{let m=l(A)?A[n]:null;p&&Array.isArray(m)&&(m=o(m,s+1,A));let b=e(A,nt,ot,s,g);if(!p&&Array.isArray(m)&&(m=o(m,s+1,A)),typeof b=="object"&&l(b))f(m)&&i||l(m)&&a(m)&&u?Reflect.deleteProperty(b,n):b[n]=m;else if(i&&f(b))return x;return x.push(b),x},[]);return o(t,0,null)}function Q(t,e){if(!e)return[...new Set(t)];let r=new Map,n=[];for(let i of t){let u=typeof e=="function"?e(i):typeof i=="object"&&l(i)?w(e,i):i;r.get(u)||(r.set(u,!0),n.push(i))}return n}var D=(...t)=>{let e=[],r=[],n=Math.min.apply(null,t.map(i=>i.length));for(let i=0;i<n;i++)t.forEach(u=>r.push(u[i])),e.push(r),r=[];return e};var X=(t,...e)=>D(...e).map(r=>r.reduce(t));var H=(t,e,r)=>n=>t(n)?e(n):r(n);function J(t,e){return t.then(r=>[null,r]).catch(r=>e?[Object.assign({},r,e),void 0]:[r,void 0])}async function Y(t,...e){return new Promise(r=>{r(t(...e))})}var v=y((t,e,r)=>t(r)?e(r):r);function tt(t,e,r){return Math.max(t,Math.min(e,r))}function et(){}function ct(t,e){return{x:t.x-e.x,y:t.y-e.y}}function mt(t){let e=Math.abs(t.x),r=Math.abs(t.y);return Math.sqrt(e*e+r*r)}function rt(t,e){let r=t.x*e.y-e.x*t.y;return r===0?0:r>0?1:-1}function yt(t,e){let r=rt(t,e),n=t.getLength(),i=e.getLength(),u=n*i;if(u===0)return 0;let o=(t.x*e.x+t.y*e.y)/u;o>1&&(o=1),o<-1&&(o=-1);let c=Math.acos(o)*r*180/Math.PI;return c===0?0:c}function Tt(t,e){return e.getLength()/t.getLength()}var R=class t{constructor(e,r){e=e||{x:0,y:0},r=r||{x:0,y:0};let{x:n,y:i}=ct(e,r);this.x=n,this.y=i}static of(e,r){return new t(e,r)}getLength(){return mt(this)}getAngle(e){return yt(this,e)}getDirection(e){return rt(this,e)}getScale(e){return Tt(this,e)}};return lt(gt);})();