UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

317 lines (316 loc) 9.24 kB
import { defineComponent as j, ref as E, computed as z, onBeforeMount as J, onMounted as K, createVNode as c, Fragment as Q, withModifiers as I, createTextVNode as n } from "vue"; const U = { /** * 组件标识 */ id: String }; function Y() { function x(l, t = 12) { return +parseFloat(l.toPrecision(t)); } function d(l) { const t = l.toString().split(/[eE]/), r = (t[0].split(".")[1] || "").length - +(t[1] || 0); return r > 0 ? r : 0; } function i(l) { if (l.toString().indexOf("e") === -1) return Number(l.toString().replace(".", "")); const t = d(l); return t > 0 ? x(l * 10 ** t) : l; } function y(l) { a && (l > Number.MAX_SAFE_INTEGER || l < Number.MIN_SAFE_INTEGER) && console.warn( `${l} is beyond boundary when transfer to integer, the results may not be accurate` ); } function v(l, t, ...r) { if (r.length > 0) return v(v(l, t), r[0], ...r.slice(1)); const f = i(l), C = i(t), M = d(l) + d(t), S = f * C; return y(S), S / 10 ** M; } function m(l, t, ...r) { if (r.length > 0) return m(m(l, t), r[0], ...r.slice(1)); const f = 10 ** Math.max(d(l), d(t)); return (v(l, f) + v(t, f)) / f; } function g(l, t, ...r) { if (r.length > 0) return g(g(l, t), r[0], ...r.slice(1)); const f = 10 ** Math.max(d(l), d(t)); return (v(l, f) - v(t, f)) / f; } function b(l, t, ...r) { if (r.length > 0) return b(b(l, t), r[0], ...r.slice(1)); const f = i(l), C = i(t); return y(f), y(C), v( f / C, 10 ** (d(t) - d(l)) ); } function s(l, t) { const r = 10 ** t; return b(Math.round(v(l, r)), r); } let a = !1; function o(l = !0) { a = l; } return { strip: x, plus: m, minus: g, times: v, divide: b, round: s, digitLength: d, float2Fixed: i, enableBoundaryChecking: o }; } const L = /* @__PURE__ */ j({ name: "FCalculator", props: U, emits: [], setup(x, d) { const i = E(), y = E(), v = E(), m = E(), g = E(), b = E(); let s = "", a = "0", o = [], l = [], t, r; const { plus: f, minus: C, times: M, divide: S } = Y(); function q() { i.value && m.value && g.value && b.value && (i.value.scrollWidth > m.value.offsetWidth ? (g.value.style.display = "block", b.value.style.display = "block") : (g.value.style.display = "none", b.value.style.display = "none")); } function _(e) { i.value && (i.value.innerHTML = e); } function A(e) { y.value && (y.value.innerHTML = e); } function H() { return s.lastIndexOf("+") !== -1 || s.lastIndexOf("-") !== -1 || s.lastIndexOf("×") !== -1 || s.lastIndexOf("÷") !== -1; } function B(e, u, p) { let h = 0; switch (e = Number(e), u = Number(u), p) { case "+": h = f(e, u); break; case "-": h = C(e, u); break; case "×": h = M(e, u); break; case "÷": h = S(e, u); break; } return h; } function R(e) { a.indexOf("0") === 0 && a.indexOf(".") === -1 || t === !0 ? a = e : a += e, t = !1, r = !1; } function V(e) { t === !0 ? a = "0" + e : a.indexOf(".") === -1 && (a += e), t = !1, r = !1; } function W() { a.indexOf("-") === -1 && a !== "0" ? a = "-" + a : a.indexOf("-") > -1 && a !== "0" && (a = a.substring(1)); } function D(e) { if (o.length < 2 && (t !== !0 || r === !0) ? (a = parseFloat(a) + "", s = s + " " + a + " " + e, o.push(a), l.push(e), t = !0) : o.length < 2 && H() && (s = s.substring(0, s.length - 1) + "" + e, l.push(e)), o.length === 2) { const u = l[l.length - 2]; if (o[1] === "0" && u === "÷") { o = [], a = "除数不能为零", s = "", t = !0; return; } const p = B(o[0], o[1], u); o = [], o.push(p), a = p + "", t = !0; } } function G() { if (o.length > 0) { const e = l.pop(); if (a === "0" && e === "÷") { o = [], a = "除数不能为零", s = "", t = !0, r = !0; return; } const u = B(o[0], a, e); o = [], a = u + "", s = "", t = !0, r = !0; } } function P() { a = "0"; } function $() { a = "0", s = "", t = !0, o = [], l = []; } function X() { a = a.length > 1 ? a.substring(0, a.length - 1) : "0"; } const k = z(() => `fv-calculator-main${Math.floor(Math.random() * 1e3).toString()}`); function N(e) { i.value && (i.value.scrollLeft += 50); } function O(e) { i.value && (i.value.scrollLeft -= 50); } function T(e) { var p; if (v.value && !v.value.contains(e.target)) return; const u = (p = e.target) == null ? void 0 : p.innerHTML; switch (u) { case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": R(u); break; case ".": V(u); break; case "±": W(); break; case "+": case "-": case "×": case "÷": D(u); break; case "=": G(); break; case "CE": P(); break; case "C": $(); break; case "Back": X(); break; } _(s), A(a); } return J(() => { }), K(() => { var e, u, p, h, w, F; i.value = (e = document.getElementById(k.value)) == null ? void 0 : e.querySelector("#fv-calculator-pre-step"), y.value = (u = document.getElementById(k.value)) == null ? void 0 : u.querySelector("#fv-calculator-show-input"), v.value = (p = document.getElementById(k.value)) == null ? void 0 : p.querySelector("#fv-calculator-num-symbol"), m.value = (h = document.getElementById(k.value)) == null ? void 0 : h.querySelector(".fv-calculator-pre"), g.value = (w = document.getElementById(k.value)) == null ? void 0 : w.querySelector(".fv-calculator-pre-left"), b.value = (F = document.getElementById(k.value)) == null ? void 0 : F.querySelector(".fv-calculator-pre-right"), q(); }), () => c(Q, null, [c("div", { class: "fv-calculator-standard-main", id: k.value, onMousedown: I((e) => T(e), ["prevent"]), onTouchstart: I((e) => T(e), ["prevent"]) }, [c("div", { class: "fv-calculator-title" }, [n("计算器")]), c("div", { class: "fv-calculator-result" }, [c("div", { class: "fv-calculator-type", id: "fv-calculator-show-bar" }, [n("Standard")]), c("div", { class: "fv-calculator-pre" }, [c("div", { class: "fv-calculator-pre-left", style: "display:none;", onMousedown: I((e) => O(), ["prevent"]), onTouchstart: I((e) => O(), ["prevent"]) }, [n("<")]), c("div", { class: "fv-calculator-pre-content", id: "fv-calculator-pre-step" }, null), c("div", { class: "fv-calculator-pre-right", style: "display:none;", onMousedown: I((e) => N(), ["prevent"]), onTouchstart: I((e) => N(), ["prevent"]) }, [n(">")])]), c("div", { class: "fv-calculator-result-out" }, [c("div", { class: "fv-calculator-second", id: "fv-calculator-show-input" }, [n("0")])])]), c("ul", { id: "fv-calculator-num-symbol" }, [c("li", { value: "37", class: "fv-calculator-letter" }, [n("CE")]), c("li", { value: "38", class: "fv-calculator-letter" }, [n("C")]), c("li", { value: "39", class: "fv-calculator-letter" }, [n("Back")]), c("li", { value: "16", class: "fv-calculator-operator" }, [n("÷")]), c("li", { class: "fv-calculator-number", value: "7" }, [n("7")]), c("li", { class: "fv-calculator-number", value: "8" }, [n("8")]), c("li", { class: "fv-calculator-number", value: "9" }, [n("9")]), c("li", { value: "15", class: "fv-calculator-operator" }, [n("×")]), c("li", { class: "fv-calculator-number", value: "4" }, [n("4")]), c("li", { class: "fv-calculator-number", value: "5" }, [n("5")]), c("li", { class: "fv-calculator-number", value: "6" }, [n("6")]), c("li", { value: "14", class: "fv-calculator-operator" }, [n("-")]), c("li", { class: "fv-calculator-number", value: "1" }, [n("1")]), c("li", { class: "fv-calculator-number", value: "2" }, [n("2")]), c("li", { class: "fv-calculator-number", value: "3" }, [n("3")]), c("li", { value: "13", class: "fv-calculator-operator" }, [n("+")]), c("li", { value: "11" }, [n("±")]), c("li", { class: "fv-calculator-number", value: "0" }, [n("0")]), c("li", { value: "10" }, [n(".")]), c("li", { value: "12", class: "fv-calculator-operator" }, [n("=")])])])]); } }), ee = { install(x) { x.component(L.name, L); } }; export { L as FCalculator, U as calculatorProps, ee as default };