| 1 |
- import{J as z,d as B,c as x,C as J,o as O,V as Q,ax as W,M as j,Q as D,g as A,a7 as F,R as f,O as G,q as K}from"./index-b3d5c748.js";const[U,b]=z("text-ellipsis"),X={rows:F(1),dots:f("..."),content:f(""),expandText:f(""),collapseText:f(""),position:f("end")};var Y=B({name:U,props:X,emits:["clickAction"],setup(n,{emit:L,slots:v}){const h=x(n.content),u=x(!1),M=x(!1),T=x(),g=x();let H=!1;const R=J(()=>u.value?n.collapseText:n.expandText),w=e=>{if(!e)return 0;const t=e.match(/^\d*(\.\d*)?/);return t?Number(t[0]):0},S=()=>{if(!T.value||!T.value.isConnected)return;const e=window.getComputedStyle(T.value),t=document.createElement("div");return Array.prototype.slice.apply(e).forEach(a=>{t.style.setProperty(a,e.getPropertyValue(a))}),t.style.position="fixed",t.style.zIndex="-9999",t.style.top="-9999px",t.style.height="auto",t.style.minHeight="auto",t.style.maxHeight="auto",t.innerText=n.content,document.body.appendChild(t),t},V=(e,t)=>{var r,a;const{content:s,position:p,dots:m}=n,d=s.length,N=0+d>>1,k=v.action?(a=(r=g.value)==null?void 0:r.outerHTML)!=null?a:"":n.expandText,q=()=>{const o=(c,l)=>{if(l-c<=1)return p==="end"?s.slice(0,c)+m:m+s.slice(l,d);const i=Math.round((c+l)/2);return p==="end"?e.innerText=s.slice(0,i)+m:e.innerText=m+s.slice(i,d),e.innerHTML+=k,e.offsetHeight>t?p==="end"?o(c,i):o(i,l):p==="end"?o(i,l):o(c,i)};return o(0,d)},C=(o,c)=>{if(o[1]-o[0]<=1&&c[1]-c[0]<=1)return s.slice(0,o[0])+m+s.slice(c[1],d);const l=Math.floor((o[0]+o[1])/2),i=Math.ceil((c[0]+c[1])/2);return e.innerText=n.content.slice(0,l)+n.dots+n.content.slice(i,d),e.innerHTML+=k,e.offsetHeight>=t?C([o[0],l],[i,c[1]]):C([l,o[1]],[c[0],i])};return n.position==="middle"?C([0,N],[N,d]):q()},y=()=>{const e=S();if(!e){H=!0;return}const{paddingBottom:t,paddingTop:r,lineHeight:a}=e.style,s=Math.ceil((Number(n.rows)+.5)*w(a)+w(r)+w(t));s<e.offsetHeight?(M.value=!0,h.value=V(e,s)):(M.value=!1,h.value=n.content),document.body.removeChild(e)},E=(e=!u.value)=>{u.value=e},_=e=>{E(),L("clickAction",e)},I=()=>{const e=v.action?v.action({expanded:u.value}):R.value;return A("span",{ref:g,class:b("action"),onClick:_},[e])};return O(()=>{y(),v.action&&Q(y)}),W(()=>{H&&(H=!1,y())}),j([G,()=>[n.content,n.rows,n.position]],y),D({toggle:E}),()=>A("div",{ref:T,class:b()},[u.value?n.content:h.value,M.value?I():null])}});const $=K(Y);export{$ as T};
|