import{__awaiter,__generator}from"tslib";import{c as computePosition,o as offset,f as flip,s as shift}from"./floating-ui.dom-DDtwbwIl.js";var TOOLTIP_CLASS="pds-truncation-tooltip";function injectStyles(){if(document.querySelector("[data-pds-truncation-tooltip]"))return;var n=document.createElement("style");n.setAttribute("data-pds-truncation-tooltip","");n.textContent="\n    .".concat(TOOLTIP_CLASS," {\n      position: fixed;\n      z-index: var(--pine-z-index-nuclear, 9999);\n    }\n    .").concat(TOOLTIP_CLASS,"__content {\n      background-color: var(--pine-color-primary, #1a1a2e);\n      border-radius: calc(var(--pine-dimension-xs, 4px) * 1.25);\n      box-shadow: var(--pine-box-shadow, 0 2px 8px rgba(0,0,0,0.15));\n      color: var(--pine-color-text-primary, #fff);\n      cursor: text;\n      font-family: var(--pine-font-family-body, sans-serif);\n      font-size: var(--pine-font-size-body-sm, 0.875rem);\n      letter-spacing: var(--pine-letter-spacing, normal);\n      line-height: var(--pine-line-height-body, 1.5);\n      max-width: 320px;\n      opacity: 0;\n      padding: var(--pine-dimension-xs, 4px) calc(var(--pine-dimension-md, 12px) / 2);\n      transition: opacity 0.15s ease-in-out, visibility 0.15s ease-in-out;\n      user-select: text;\n      visibility: hidden;\n      width: max-content;\n      word-break: break-word;\n    }\n    .").concat(TOOLTIP_CLASS,"--visible .").concat(TOOLTIP_CLASS,"__content {\n      opacity: 1;\n      visibility: visible;\n    }\n  ");document.head.appendChild(n)}function isOverflowing(n){return n.scrollWidth>n.clientWidth}function setupTruncationTooltip(n){var e=n.hostEl,i=n.contentEl,t=n.getTooltipText,o=n.placement,r=o===void 0?"top":o;injectStyles();var a=null;var u=false;var s=false;var f=false;var c=null;var l=null;var p=null;if(typeof ResizeObserver!=="undefined"){l=new ResizeObserver((function(){if(p){clearTimeout(p)}p=setTimeout((function(){p=null;if(a&&a.isConnected&&!isOverflowing(i)){O()}}),100)}));l.observe(i)}function d(){if(a)return;var n=t();if(!n||n.trim()==="")return;a=document.createElement("div");a.className=TOOLTIP_CLASS;a.setAttribute("role","tooltip");a.setAttribute("aria-hidden","false");var e=document.createElement("div");e.className="".concat(TOOLTIP_CLASS,"__content");e.textContent=n.trim();a.appendChild(e);document.body.appendChild(a);a.addEventListener("mouseenter",h);a.addEventListener("mouseleave",y);v().then((function(){if(a){a.classList.add("".concat(TOOLTIP_CLASS,"--visible"))}}))}function v(){return __awaiter(this,void 0,void 0,(function(){var n,i,t,o,u,s,f,c,l;return __generator(this,(function(p){switch(p.label){case 0:if(!a)return[2];p.label=1;case 1:p.trys.push([1,3,,4]);return[4,computePosition(e,a,{placement:r,strategy:"fixed",middleware:[offset(4),flip(),shift({padding:5})]})];case 2:n=p.sent(),i=n.x,t=n.y;Object.assign(a.style,{left:"".concat(i,"px"),top:"".concat(t,"px")});return[3,4];case 3:o=p.sent();if(a){u=e.getBoundingClientRect();s=a.getBoundingClientRect();f=5;c=Math.max(f,Math.min(u.left,window.innerWidth-s.width-f));l=Math.max(f,u.top-s.height-8);a.style.left="".concat(c,"px");a.style.top="".concat(l,"px")}return[3,4];case 4:return[2]}}))}))}function m(){if(a){a.removeEventListener("mouseenter",h);a.removeEventListener("mouseleave",y);a.classList.remove("".concat(TOOLTIP_CLASS,"--visible"));if(a.parentNode&&a.isConnected){try{a.parentNode.removeChild(a)}catch(n){}}a=null}}function T(){if(c!==null){clearTimeout(c);c=null}}function x(){T();if(!isOverflowing(i))return;d()}function O(){if(u||s||f)return;m()}function _(){T();c=setTimeout((function(){c=null;O()}),100)}function b(){u=true;x()}function S(){u=false;_()}function h(){s=true;T()}function y(){s=false;_()}function w(){f=true;x()}function L(){f=false;_()}e.addEventListener("mouseenter",b);e.addEventListener("mouseleave",S);e.addEventListener("focusin",w);e.addEventListener("focusout",L);return function(){T();if(p){clearTimeout(p);p=null}if(l){l.disconnect()}e.removeEventListener("mouseenter",b);e.removeEventListener("mouseleave",S);e.removeEventListener("focusin",w);e.removeEventListener("focusout",L);m()}}export{setupTruncationTooltip as s};
//# sourceMappingURL=truncation-tooltip-Blk4GigP.js.map