UNPKG

ideaz-element

Version:

<p align="center"> <a href="" target="_blank" rel="noopener noreferrer"> <img src="./docs/public/logo.svg" alt="Ideaz Element" width="180" style="width: 180px;" /> </a> </p>

76 lines (75 loc) 3.03 kB
import { defineComponent as L, ref as o, computed as N, nextTick as w, onMounted as $, createVNode as l, mergeProps as k, withDirectives as h, createTextVNode as v, vShow as x, Fragment as C } from "vue"; import "../../../shared/index.mjs"; import "../../../utils/index.mjs"; import { ElTooltip as V } from "element-plus"; import { textProps as D } from "./text.mjs"; import { useNamespace as M } from "../../../hooks/useNamespace.mjs"; import { useFormSize as P } from "../../../hooks/useFormSize.mjs"; import { getStyle as W } from "../../../utils/getStyle.mjs"; import { getStrFullLength as j, cutStrByFullLength as B } from "../../../utils/string.mjs"; import { isValid as H, isObject as E } from "../../../utils/is.mjs"; import { resolveDynamicComponent as I } from "../../../shared/resolveDynamicComponent.mjs"; const _ = /* @__PURE__ */ L({ name: "ZText", props: D, setup(e, { slots: m }) { const s = M("text", o("el")), S = P(), d = o(), g = o(!1), i = o(!1), y = o(""), u = o(), c = o(), R = N(() => [s.b(), s.m(e.type), s.m(S.value), s.is("truncated", e.truncated)]), r = () => { var n; return e.value || e.text || ((n = m.default) == null ? void 0 : n.call(m)[0].children); }, p = async () => { i.value = !1, g.value = !1, await w(); const n = u.value, a = d.value, T = c.value; let b = 1e3, t = r(), f = e.height || 0; if (!f && e.lines && (f = (Number.parseInt(W(a, "lineHeight") || "", 10) || 24) * e.lines), n) { if (e.length) (e.fullWidthRecognition ? j(t) : t.length) > e.length && (i.value = !0, T.style.display = "inline-block", t = e.fullWidthRecognition ? B(t, e.length) : t.slice(0, e.length)); else if (a.offsetHeight > f) for (i.value = !0, T.style.display = "inline-block"; a.offsetHeight > f && b > 0; ) a.offsetHeight > f * 3 ? n.textContent = t = t.substring(0, Math.floor(t.length / 2)) : n.textContent = t = t.substring(0, t.length - 1), b--; } y.value = t, z(); }; async function z() { g.value = !0, await w(); const n = u.value; n && (n.textContent = y.value); } return $(() => { (H(e.length) || H(e.lines)) && p(); }), () => { const { tag: n } = e, a = E(e.tooltip) ? e.tooltip : {}; return I({ name: n, attrs: { class: R.value, ref: d }, content: g.value ? i.value ? l(V, k({ content: r() }, a), { default: () => [l("div", null, [l("span", { ref: u }, [r()]), h(l("span", { ref: c }, [v("...")]), [[x, i.value]])])] }) : l(C, null, [l("span", { ref: u }, [r()]), h(l("span", { ref: c }, [v("...")]), [[x, i.value]])]) : l(C, null, [l("span", { ref: u }, [r()]), h(l("span", { ref: c }, [v("...")]), [[x, i.value]])]) }); }; } }); export { _ as default }; //# sourceMappingURL=index.mjs.map