UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

71 lines (70 loc) 2.94 kB
"use client"; import r from "../../../../decimal.js-light/decimal.js"; import { memoize as w, reverse as f, range as s, compose as I, map as x } from "./util/utils.js"; import { rangeStep as g, getDigitCount as p } from "./util/arithmetic.js"; var M = (m) => { var [t, n] = m, [e, i] = [t, n]; return t > n && ([e, i] = [n, t]), [e, i]; }, b = (m, t, n) => { if (m.lte(0)) return new r(0); var e = p(m.toNumber()), i = new r(10).pow(e), o = m.div(i), a = e !== 1 ? 0.05 : 0.1, u = new r(Math.ceil(o.div(a).toNumber())).add(n).mul(a), v = u.mul(i); return t ? new r(v.toNumber()) : new r(Math.ceil(v.toNumber())); }, y = (m, t, n) => { var e = new r(1), i = new r(m); if (!i.isint() && n) { var o = Math.abs(m); o < 1 ? (e = new r(10).pow(p(m) - 1), i = new r(Math.floor(i.div(e).toNumber())).mul(e)) : o > 1 && (i = new r(Math.floor(m))); } else m === 0 ? i = new r(Math.floor((t - 1) / 2)) : n || (i = new r(Math.floor(m))); var a = Math.floor((t - 1) / 2), u = I(x((v) => i.add(new r(v - a).mul(e)).toNumber()), s); return u(0, t); }, h = function(t, n, e, i) { var o = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 0; if (!Number.isFinite((n - t) / (e - 1))) return { step: new r(0), tickMin: new r(0), tickMax: new r(0) }; var a = b(new r(n).sub(t).div(e - 1), i, o), u; t <= 0 && n >= 0 ? u = new r(0) : (u = new r(t).add(n).div(2), u = u.sub(new r(u).mod(a))); var v = Math.ceil(u.sub(t).div(a).toNumber()), l = Math.ceil(new r(n).sub(u).div(a).toNumber()), d = v + l + 1; return d > e ? h(t, n, e, i, o + 1) : (d < e && (l = n > 0 ? l + (e - d) : l, v = n > 0 ? v : v + (e - d)), { step: a, tickMin: u.sub(new r(v).mul(a)), tickMax: u.add(new r(l).mul(a)) }); }; function F(m) { var [t, n] = m, e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 6, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !0, o = Math.max(e, 2), [a, u] = M([t, n]); if (a === -1 / 0 || u === 1 / 0) { var v = u === 1 / 0 ? [a, ...s(0, e - 1).map(() => 1 / 0)] : [...s(0, e - 1).map(() => -1 / 0), u]; return t > n ? f(v) : v; } if (a === u) return y(a, e, i); var { step: l, tickMin: d, tickMax: N } = h(a, u, o, i, 0), c = g(d, N.add(new r(0.1).mul(l)), l); return t > n ? f(c) : c; } function S(m, t) { var [n, e] = m, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !0, [o, a] = M([n, e]); if (o === -1 / 0 || a === 1 / 0) return [n, e]; if (o === a) return [o]; var u = Math.max(t, 2), v = b(new r(a).sub(o).div(u - 1), i, 0), l = [...g(new r(o), new r(a), v), a]; return i === !1 && (l = l.map((d) => Math.round(d))), n > e ? f(l) : l; } var D = w(F), R = w(S); export { h as calculateStep, b as getFormatStep, D as getNiceTickValues, y as getTickOfSingleValue, R as getTickValuesFixedDomain, M as getValidInterval };