text2.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var text = require('./text.js');
  5. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  6. var useFormCommonProps = require('../../form/src/hooks/use-form-common-props.js');
  7. var index = require('../../../hooks/use-namespace/index.js');
  8. var types = require('../../../utils/types.js');
  9. const __default__ = vue.defineComponent({
  10. name: "ElText"
  11. });
  12. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  13. ...__default__,
  14. props: text.textProps,
  15. setup(__props) {
  16. const props = __props;
  17. const textRef = vue.ref();
  18. const textSize = useFormCommonProps.useFormSize();
  19. const ns = index.useNamespace("text");
  20. const textKls = vue.computed(() => [
  21. ns.b(),
  22. ns.m(props.type),
  23. ns.m(textSize.value),
  24. ns.is("truncated", props.truncated),
  25. ns.is("line-clamp", !types.isUndefined(props.lineClamp))
  26. ]);
  27. const inheritTitle = vue.useAttrs().title;
  28. const bindTitle = () => {
  29. var _a, _b, _c, _d, _e;
  30. if (inheritTitle)
  31. return;
  32. let shouldAddTitle = false;
  33. const text = ((_a = textRef.value) == null ? void 0 : _a.textContent) || "";
  34. if (props.truncated) {
  35. const width = (_b = textRef.value) == null ? void 0 : _b.offsetWidth;
  36. const scrollWidth = (_c = textRef.value) == null ? void 0 : _c.scrollWidth;
  37. if (width && scrollWidth && scrollWidth > width) {
  38. shouldAddTitle = true;
  39. }
  40. } else if (!types.isUndefined(props.lineClamp)) {
  41. const height = (_d = textRef.value) == null ? void 0 : _d.offsetHeight;
  42. const scrollHeight = (_e = textRef.value) == null ? void 0 : _e.scrollHeight;
  43. if (height && scrollHeight && scrollHeight > height) {
  44. shouldAddTitle = true;
  45. }
  46. }
  47. if (shouldAddTitle) {
  48. textRef.value.setAttribute("title", text);
  49. } else {
  50. textRef.value.removeAttribute("title");
  51. }
  52. };
  53. vue.onMounted(bindTitle);
  54. vue.onUpdated(bindTitle);
  55. return (_ctx, _cache) => {
  56. return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), {
  57. ref_key: "textRef",
  58. ref: textRef,
  59. class: vue.normalizeClass(vue.unref(textKls)),
  60. style: vue.normalizeStyle({ "-webkit-line-clamp": _ctx.lineClamp })
  61. }, {
  62. default: vue.withCtx(() => [
  63. vue.renderSlot(_ctx.$slots, "default")
  64. ]),
  65. _: 3
  66. }, 8, ["class", "style"]);
  67. };
  68. }
  69. });
  70. var Text = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "text.vue"]]);
  71. exports["default"] = Text;
  72. //# sourceMappingURL=text2.js.map