UNPKG

ant-design-x-vue

Version:

Craft AI-driven interfaces effortlessly

36 lines (35 loc) 1.82 kB
import o from "./calculator.mjs"; const u = "CALC_UNIT", f = new RegExp(u, "g"); function l(r) { return typeof r == "number" ? `${r}${u}` : r; } class e extends o { constructor(t, i) { super(), this.result = ""; const s = typeof t; this.unitlessCssVar = i, t instanceof e ? this.result = `(${t.result})` : s === "number" ? this.result = l(t) : s === "string" && (this.result = t); } add(t) { return t instanceof e ? this.result = `${this.result} + ${t.getResult()}` : (typeof t == "number" || typeof t == "string") && (this.result = `${this.result} + ${l(t)}`), this.lowPriority = !0, this; } sub(t) { return t instanceof e ? this.result = `${this.result} - ${t.getResult()}` : (typeof t == "number" || typeof t == "string") && (this.result = `${this.result} - ${l(t)}`), this.lowPriority = !0, this; } mul(t) { return this.lowPriority && (this.result = `(${this.result})`), t instanceof e ? this.result = `${this.result} * ${t.getResult(!0)}` : (typeof t == "number" || typeof t == "string") && (this.result = `${this.result} * ${t}`), this.lowPriority = !1, this; } div(t) { return this.lowPriority && (this.result = `(${this.result})`), t instanceof e ? this.result = `${this.result} / ${t.getResult(!0)}` : (typeof t == "number" || typeof t == "string") && (this.result = `${this.result} / ${t}`), this.lowPriority = !1, this; } getResult(t) { return this.lowPriority || t ? `(${this.result})` : this.result; } equal(t) { const { unit: i } = t || {}; let s = !0; return typeof i == "boolean" ? s = i : Array.from(this.unitlessCssVar).some((h) => this.result.includes(h)) && (s = !1), this.result = this.result.replace(f, s ? "px" : ""), typeof this.lowPriority < "u" ? `calc(${this.result})` : this.result; } } export { e as default };