@progress/kendo-vue-inputs
Version:
181 lines (180 loc) • 9.64 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
const C = 11111111111111e-7, le = 0.31111111111111117, ae = 1, Q = 1, Y = 0, m = /\d/, w = 15, he = (t, n) => t !== void 0 ? t : n, p = (t, n, r) => t === null && t === void 0 ? "" : typeof t == "string" ? t : r.formatNumber(t, n), H = (t) => (String(t).split(".")[1] || "").length, ee = (t, n) => Math.max(H(t), H(n)), de = (t) => Math.min(t, w), ne = (t, n) => {
const r = de(n);
return parseFloat(t.toFixed(r));
}, Ne = (t, n, r, e, u, o, a) => {
const s = ee(t || 0, r || 0), i = te(ne((t || 0) + (r || 0), s), e, u);
n.eventValue = i, n.currentLooseValue = p(i, o, a), n.selectionStart = n.selectionEnd = D(n.currentLooseValue, m);
}, Ie = (t, n, r, e, u, o, a) => {
const s = ee(t || 0, r || 0), i = te(ne((t || 0) - (r || 0), s), e, u);
n.eventValue = i, n.currentLooseValue = p(i, o, a), n.selectionStart = n.selectionEnd = D(n.currentLooseValue, m);
}, te = (t, n, r) => t == null ? t : !(t > 1 || t < 1 || t === 1) || r !== void 0 && n !== void 0 && r < n ? null : (r !== void 0 && t > r && (t = r), n !== void 0 && t < n && (t = n), t), ge = (t, n) => {
const r = n.findIndex(([u, o]) => !!o && t.indexOf(o) === t.length - o.length);
if (r === -1)
return -1;
const e = n[r][1];
return t.length - e.length;
}, fe = (t, n) => {
const r = n.findIndex(([u, o]) => !!u && t.indexOf(u) === 0);
return r === -1 ? -1 : n[r][0].length;
}, me = (t, n, r) => {
const e = ge(t, n);
if (e !== -1 && r.selectionStart > e) {
r.selectionStart = r.selectionEnd = e;
return;
}
r.selectionStart > t.length && (r.selectionStart = r.selectionEnd = t.length);
const u = fe(t, n);
u !== -1 && r.selectionStart < u && (r.selectionStart = r.selectionEnd = u), r.selectionStart === -1 && (r.selectionStart = r.selectionEnd = 0);
}, L = (t, n, r, e) => {
t.selectionStart = t.selectionEnd = n, me(r, e, t);
}, _ = (t, n, r, e) => {
t.eventValue = e.parseNumber(t.prevLooseValue, n), t.currentLooseValue = t.prevLooseValue, t.valueIsCorrected = !0, L(t, t.selectionStart, t.currentLooseValue, r);
}, Ve = (t, n) => {
const r = String(t.currentLooseValue), e = String(t.prevLooseValue);
return r.split(n.minusSign).length !== e.split(n.minusSign).length && r.length === e.length + n.minusSign.length;
}, pe = (t, n) => {
const r = String(t.currentLooseValue), e = String(t.prevLooseValue);
return r.indexOf(n.minusSign) === -1 && e.indexOf(n.minusSign) !== -1;
}, xe = (t, n) => String(t.currentLooseValue).split(n.decimal).length > 2, Le = (t, n) => {
const r = n.formatNumber(C, t), e = n.formatNumber(-C, t), u = n.formatNumber(Y, t), o = n.formatNumber(Q, t), a = P(r), s = P(e), i = P(u), l = P(o), I = M(r), E = M(e), x = M(u), b = M(o);
return {
positiveInfo: [a, I],
negativeInfo: [s, E],
zeroInfo: [i, x],
oneInfo: [l, b]
};
}, be = (t, n) => {
const r = n.formatNumber(C, t), e = n.formatNumber(-C, t), u = n.formatNumber(Y, t), o = n.formatNumber(Q, t), a = n.numberSymbols(), s = new RegExp(`[\\d\\${a.decimal}${a.group}]`, "g");
return [r, e, u, o].map((l) => l.replace(s, "")).join("").split("").filter((l, I, E) => E.indexOf(l) === I).join("");
}, T = (t, n) => {
const r = t.indexOf(n.decimal);
return r > -1 ? r : D(t, m);
}, $ = (t) => t.split("").reverse().join(""), D = (t, n) => t.length - $(t).search(n), P = (t) => t.split(t[t.search(m)])[0], M = (t) => {
const n = $(t);
return $(n.split(n[n.search(m)])[0]);
}, B = (t, n) => t.search(n), J = (t, n) => {
const r = t.indexOf(n);
return r > -1 ? t.length - r - 1 : 0;
}, K = (t, n, r, e, u) => {
const o = t.replace(u, "")[0] === "0", a = n.replace(u, "")[0] === "0";
if (o && !a)
return r - 1;
if (a && e)
return r + 1;
let s = 0;
for (let l = 0; l < r; l++)
m.test(t.charAt(l)) && s++;
let i = 0;
for (; s > 0 && n.length > i; )
m.test(n.charAt(i)) && s--, i++;
return i;
}, Ee = (t, n, r) => {
const e = {
...t
}, {
prevLooseValue: u
} = e, o = r.numberSymbols(), a = be(n, r), s = String(e.currentLooseValue), i = String(u), l = new RegExp(`[^\\d\\${o.decimal}]`, "g"), I = new RegExp(`[^\\d\\${o.decimal}\\${o.group}]`, "g"), E = new RegExp(`[\\d\\${o.decimal}\\${o.group}]`), x = s.replace(l, ""), b = B(s, m), R = b === -1 ? -1 : D(s, m), re = s.indexOf(o.decimal), G = (s.substring(0, b) + s.substring(b, R).replace(I, "") + s.substring(R, s.length)).split("").filter((V) => a.indexOf(V) !== -1 || V.search(E) !== -1).join(""), U = r.formatNumber(le, n).replace(l, ""), j = U.indexOf(o.decimal), N = j > -1 ? U.length - j - 1 : 0, v = r.formatNumber(ae, n).replace(l, ""), X = v.indexOf(o.decimal), O = X > -1 ? v.length - X - 1 : 0, {
positiveInfo: se,
negativeInfo: oe,
zeroInfo: ue,
oneInfo: ce
} = Le(n, r), g = [se, oe, ue, ce], ie = g.findIndex((V) => V.findIndex((h) => !!h) !== -1) !== 1, F = s.length > 0 && s.length < i.length, Z = n && n[0] === "p" && s && s.indexOf(o.percentSign) === -1;
if (!e.isPaste) {
if (s === "")
return e.eventValue = null, e.currentLooseValue = "", e;
if (e.currentLooseValue === o.minusSign && r.formatNumber(-0, n) !== i)
return e.eventValue = -0, e.currentLooseValue = p(e.eventValue, n, r), L(e, T(e.currentLooseValue, o), e.currentLooseValue, g), e;
if (Ve(e, o)) {
const f = r.parseNumber(u, n);
e.eventValue = -(f !== null ? f : 0), e.currentLooseValue = p(e.eventValue, n, r);
const c = B(e.currentLooseValue, m), d = B(i, m);
return L(e, e.selectionEnd - 1 + (c - d), e.currentLooseValue, g), e;
}
if (pe(e, o))
return e.eventValue = r.parseNumber(e.currentLooseValue, n), L(e, e.selectionStart, e.currentLooseValue, g), e;
if (e.currentLooseValue === o.decimal) {
e.eventValue = 0;
const f = p(e.eventValue, n, r);
if (O === 0 && N > 0) {
const c = D(f, m);
e.currentLooseValue = f.substring(0, c) + o.decimal + f.substring(c);
} else
e.currentLooseValue = f;
return L(e, T(e.currentLooseValue, o) + 1, e.currentLooseValue, g), e;
}
if (xe(e, o))
return _(e, n, g, r), e;
if (Z)
return e.eventValue = r.parseNumber(s, n) / 100, e.currentLooseValue = p(e.eventValue, n, r), e;
if (String(e.currentLooseValue).replace(/[^\d]/g, "").length > w || x !== s && s && ie && g.findIndex(([c, d]) => {
const z = s.indexOf(c), A = s.indexOf(d), W = z === 0, S = A === s.length - d.length, k = z + c.length !== b && b !== -1 && s[z + c.length] !== o.decimal, q = A !== R && R !== -1 && s[A - 1] !== o.decimal;
return c && d ? k || q ? !1 : W && S : c ? k ? !1 : W : d ? q ? !1 : S : !1;
}) === -1)
return _(e, n, g, r), e;
if (x[x.length - 1] === o.decimal && N > 0)
return e.eventValue = r.parseNumber(s, n), e.currentLooseValue = G, e;
if (e.currentLooseValue && u && (a + o.decimal + o.group).split("").findIndex((c) => s.split("").filter((d) => d === c).length < i.split("").filter((d) => d === c).length && s.length + 1 === i.length ? !(c === o.decimal && J(i.replace(l, ""), o.decimal) === 0) : !1) > -1)
return e.eventValue = r.parseNumber(t.prevLooseValue, n), e.currentLooseValue = t.prevLooseValue, e;
const h = J(x, o.decimal), y = x[x.length - 1] === "0";
if (F && y && h < O)
return e.eventValue = r.parseNumber(e.currentLooseValue, n), e.currentLooseValue = p(e.eventValue, n, r), e;
if (h > 0) {
const f = s.substring(0, re);
if (y && (!f || i.indexOf(f) !== 0)) {
e.eventValue = r.parseNumber(e.currentLooseValue, n);
const c = p(e.eventValue, n, r);
return L(e, K(s, c, e.selectionEnd, F, l), c, g), e.currentLooseValue = c, e;
}
if (h > N) {
const c = s.indexOf(o.decimal), d = s.substring(0, c) + s.substring(c, c + 1 + N) + s.substring(R, String(e.currentLooseValue).length);
return e.eventValue = r.parseNumber(d, n), e.currentLooseValue = d, L(e, e.selectionStart, d, g), e;
}
if (O !== N && h <= N && y)
return e.eventValue = r.parseNumber(e.currentLooseValue, n), e.currentLooseValue = G, e;
if (h < O)
return e.eventValue = r.parseNumber(e.currentLooseValue, n), e.currentLooseValue = p(e.eventValue, n, r), e;
}
}
if (e.eventValue = r.parseNumber(e.currentLooseValue, n), Z && (e.eventValue = e.eventValue / 100), typeof e.eventValue == "number") {
const V = p(e.eventValue, n, r);
s.length === 1 ? L(e, T(V, o), V, g) : L(e, K(s, V, e.selectionEnd, F, l), V, g), e.currentLooseValue = V;
} else
e.currentLooseValue = p(r.parseNumber(x), n, r);
return e;
};
export {
K as changeBasedSelection,
Ie as decreaseValue,
p as formatValue,
H as fractionLength,
J as getDecimalCount,
B as getFirstNumberIndex,
Le as getFormatPrefixSufix,
be as getFormatSymbols,
T as getInitialPosition,
D as getLastNumberIndex,
ge as getMaxCursorPosition,
fe as getMinCursorPosition,
P as getPrefix,
he as getStateOrPropsValue,
M as getSuffix,
Ne as increaseValue,
xe as isDecimalDuplicated,
Ve as isMinusSymbolAdded,
pe as isMinusSymbolRemoved,
de as limitPrecision,
me as rangeSelection,
te as rangeValue,
$ as reverseString,
Ee as sanitizeNumber,
_ as setInvalid,
L as setSelection,
ne as toFixedPrecision
};