UNPKG

@vueuse/math

Version:
2 lines (1 loc) 2.11 kB
(function(o,n,a){"use strict";function l(t,u,e){return c=>n.computed(()=>e(n.toValue(c),n.toValue(t),n.toValue(u)))}function M(t,u,e){return(t-u[0])/(u[1]-u[0])*(e[1]-e[0])+e[0]}function s(t,u,e=M){return l(t,u,e)}function d(...t){return n.computed(()=>t.every(u=>n.toValue(u)))}function f(t){return n.computed(()=>!n.toValue(t))}function V(...t){return n.computed(()=>t.some(u=>n.toValue(u)))}function g(t){return n.computed(()=>Math.abs(n.toValue(t)))}function i(t){return t.flatMap(u=>{const e=n.toValue(u);return Array.isArray(e)?e.map(c=>n.toValue(c)):[e]})}function h(...t){return n.computed(()=>{const u=i(t);return u.reduce((e,c)=>e+=c,0)/u.length})}function P(t){return n.computed(()=>Math.ceil(n.toValue(t)))}function y(t,u,e){if(typeof t=="function"||n.isReadonly(t))return n.computed(()=>a.clamp(n.toValue(t),n.toValue(u),n.toValue(e)));const c=n.ref(t);return n.computed({get(){return c.value=a.clamp(c.value,n.toValue(u),n.toValue(e))},set(r){c.value=a.clamp(r,n.toValue(u),n.toValue(e))}})}function A(t){return n.computed(()=>Math.floor(n.toValue(t)))}function j(t,...u){return a.reactify(Math[t])(...u)}function p(...t){return n.computed(()=>{const u=i(t);return Math.max(...u)})}function _(...t){return n.computed(()=>{const u=i(t);return Math.min(...u)})}function C(t,u){const e=t.toString();if(t>0&&e.includes(".")){const r=10**e.split(".")[1].length;return t*r*u/r}else return t*u}function S(t,u,e){return n.computed(()=>{var c;const r=n.toValue(t),m=10**n.toValue(u);return Math[((c=n.toValue(e))==null?void 0:c.math)||"round"](C(r,m))/m})}function b(t,u,e,c){return s(u,e,c)(t)}function F(t){return n.computed(()=>Math.round(n.toValue(t)))}function N(...t){return n.computed(()=>i(t).reduce((u,e)=>u+=e,0))}function R(t){return n.computed(()=>Math.trunc(n.toValue(t)))}o.and=d,o.createGenericProjection=l,o.createProjection=s,o.logicAnd=d,o.logicNot=f,o.logicOr=V,o.not=f,o.or=V,o.useAbs=g,o.useAverage=h,o.useCeil=P,o.useClamp=y,o.useFloor=A,o.useMath=j,o.useMax=p,o.useMin=_,o.usePrecision=S,o.useProjection=b,o.useRound=F,o.useSum=N,o.useTrunc=R})(this.VueUse=this.VueUse||{},Vue,VueUse);