/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{ref as e,watch as i,onMounted as n,onUnmounted as l,openBlock as t,createElementBlock as s,normalizeClass as o,createElementVNode as r,renderSlot as u}from"vue";import{isSupportResizeObserver as a}from"@gsc-basic/utils";import{useWindowSizeFn as c}from"@gsc-basic/hooks";import{getLineHeight as p,registerWordBreak as v,getElementHeight as f,setWordBreak as d,wrapTextChildNodesWithSpan as m,binarySearch as h}from"../utils/utils.js";import './JsEllipsis.css';/* empty css               */import x from"../../../_virtual/_plugin-vue_export-helper.js";import y from"../../../node_modules/lodash-es/isString.js";import g from"../../../node_modules/lodash-es/isRegExp.js";const H="l--ellipsis-js",b=/* @__PURE__ */x({__name:"JsEllipsis",props:{text:{type:String,required:!0},visibleLine:{type:Number,default:1},visibleHeight:{type:Number},maxLine:{type:Number},maxHeight:{type:Number},ellipsis:{type:Boolean},endExcludes:{type:Array,default:()=>[]},useInnerHtml:{type:Boolean},reflowOnResize:{type:Boolean},onReflow:{type:Function},onEllipsisClick:{type:Function}},setup(x){const b=x,E=e(),L=e(),_=e(),T=e(),N=e();function C(e,i){b?.onReflow?.(e,i)}function R(){b?.onEllipsisClick?.()}function k(){if(!E.value||!L.value||!_.value||T.value)return;if(_.value.style.display="none",b.useInnerHtml?L.value.innerHTML=b.text:L.value.innerText=b.text,!b.ellipsis)return;const e=p(E.value),i=v(L.value),n=void 0===b.visibleHeight?e*b.visibleLine:b.visibleHeight,l=void 0===b.maxHeight?void 0===b.maxLine?n:e*b.maxLine:b.maxHeight;if(f(E.value)<=Math.max(l,n))return C(!1,b.text),void(y(i)&&d(L.value,i));T.value=!0,_.value.style.display="inline",b.useInnerHtml?(m(L.value),j(E.value,L.value,n)):M(E.value,L.value,n),y(i)&&d(L.value,i),T.value=!1}function M(e,i,n){const l=i.textContent||"";let t="";h(0,l.length,(s,o,r)=>{const u=l.slice(s,r);i.innerText=t+u;const a=f(e)>n;return a||(t+=u),a},(e,i,n)=>e===n),t=function(e){for(;e.length&&w(e[e.length-1]);)e=e.slice(0,-1);return e}(t),i.innerText=t,C(!0,t)}function j(e,i,n){const l=i.childNodes;if(1===l.length){const t=l[0];if(t.nodeType===Node.TEXT_NODE)M(e,i,n);else{const l=t.innerHTML;t.innerHTML="";if(f(e)>n)return i.removeChild(t),void C(!0,i.innerHTML);t.innerHTML=l,j(e,t,n)}}else{const t=[].slice.call(l),s=[];let o=0;h(0,t.length,(l,o,r)=>{i.innerHTML="";const u=t.slice(l,r);s.forEach(e=>{i.appendChild(e)}),u.forEach(e=>{i.appendChild(e)});const a=f(e)>n;return a||u.forEach(e=>{s.push(e)}),a},(l,s,r)=>{if(l===r){const l=f(e);return o=r,l>n||i.appendChild(t[o]),!0}return!1}),i.childNodes[o]&&j(e,i.childNodes[o],n)}}function w(e){for(const i of b.endExcludes)if(g(i)){if(i.test(e))return!0}else if(i===e)return!0;return!1}i(()=>b.text,k),i(()=>b.ellipsis,k),i(()=>b.useInnerHtml,k),i(()=>b.maxLine,k),i(()=>b.visibleLine,k),i(()=>b.maxHeight,k),i(()=>b.visibleHeight,k),i(()=>b.endExcludes,k);const[I,O]=c(k);return n(()=>{k(),E.value&&b.reflowOnResize&&(a?(N.value=new ResizeObserver(k),N.value.observe(E.value)):I())}),l(()=>{a&&N.value?N.value?.disconnect?.():O()}),(e,i)=>(t(),s("div",{ref_key:"aref",ref:E,class:o([H])},[r("span",{ref_key:"textRef",ref:L,class:o([`${H}-content`])},null,2),r("span",{ref_key:"ellipsisRef",ref:_,class:o([`${H}-ellipsis`]),onClick:R},[u(e.$slots,"ellipsisNode",{},void 0,!0)],2)],2))}},[["__scopeId","data-v-6d208c0a"]]);export{b as default};