import{dr as E}from"./index-6Jqoo2rk.js";const I="_hidden_1403e_1",D="_Dot_1403e_5",g="_Dot2_1403e_9",C="_Dot3_1403e_12",m={hidden:I,Dot:D,"dot-animation":"_dot-animation_1403e_1",Dot2:g,Dot3:C};function Y({root:e,bubble:t,scrollable:a,isEnd:d=!1,prevPosition:o=-1}){const{maxPosition:i,nodeContents:s,allNodes:n,currentNodeIdx:f}=L({root:e,prevPosition:o});let c,l=!1,r=!1;function u(){l=!0,n.forEach(p=>s.delete(p))}function T(){r||(r=!0,!d&&c&&v(c))}const x={allNodes:n,bubble:t,clean:u,currentPosition:o,currentNodeIdx:f,nextIsEnd:d};return R({scrollable:a,typeNext:p=>y({result:x,setLastTextNode:_=>c=_,nodeContents:s,onEnd:T,length:p}),isCleaned:()=>l,maxPosition:i,prevPosition:o}),x}function L({root:e,prevPosition:t}){const a=document.createTreeWalker(e,NodeFilter.SHOW_ALL),d=[],o=new WeakMap;for(;a.nextNode();)d.push(a.currentNode);let i=-1,s=0;for(const n of d)n.nodeType===Node.TEXT_NODE?(o.set(n,n.textContent),n.textContent=n.textContent.slice(0,Math.max(0,t-i+1)),i+=o.get(n).length):n instanceof Element&&i>t&&n.classList.add(m.hidden),i<=t&&s++;return{maxPosition:i,nodeContents:o,allNodes:d,currentNodeIdx:s}}function v(e){const t=e.parentNode;if(!(t instanceof Element))return;const a=document.createElement("span");a.className=m.Dots,a.textContent=" ",new Array(3).fill(null).forEach((d,o)=>{const i=document.createElement("span");i.textContent=".",i.classList.add(m.Dot,m["Dot"+(o+1)]),a.appendChild(i)}),t.appendChild(a)}function y({result:e,setLastTextNode:t,onEnd:a,nodeContents:d,length:o}){const{allNodes:i,clean:s}=e;for(;e.currentNodeIdx<i.length&&o;){const n=i[e.currentNodeIdx];if(n instanceof Element)e.currentNodeIdx++,n.classList.remove(m.hidden);else if(n.nodeType===Node.TEXT_NODE){const f=n.textContent.length,c=d.get(n),l=Math.max(0,f+o-c.length),r=f,u=r+o-l;n.textContent+=c.slice(r,u),o=l,e.currentPosition+=u-r,l&&e.currentNodeIdx++,t(n)}}e.currentNodeIdx>=i.length&&(s(),a())}const A=60*1e3/(800*5),M=60*1e3/(2400*5),w=.3;function k(e){const t=Math.max(M,Math.min(A,e));return t+Math.random()*t*w}const O=5e3;function R({scrollable:e,typeNext:t,isCleaned:a,maxPosition:d,prevPosition:o}){const i=O/(d-o);let s=0;const n=H(e),f=()=>a()?(n.cleanup(),!0):!1;let c=-1;const l=2;E(()=>{if(f())return!1;if(c=(c+1)%l,c)return!0;const r=performance.now();s||(s=r);const u=Math.max(0,Math.round((r-s)/k(i)));return u&&(t(u),s=r),u&&!n.isInvalidated()&&e.scrollTop+e.clientHeight>e.scrollHeight-120&&(e.scrollTop=e.scrollHeight),!0})}const W=450,N=["wheel","touchstart","pointerdown","keydown"],h=new Map;function H(e){let t;if(h.has(e))t=h.get(e);else{t={count:0,cleanup:()=>{N.forEach(o=>{e.removeEventListener(o,d)})}};const d=()=>{t.invalidateTimeoutId&&self.clearTimeout(t.invalidateTimeoutId),t.invalidateTimeoutId=self.setTimeout(()=>{t.invalidateTimeoutId=void 0},W)};N.forEach(o=>{e.addEventListener(o,d,{passive:!0})}),h.set(e,t)}t.count++;let a=!1;return{isInvalidated:()=>!!t.invalidateTimeoutId,cleanup:()=>{a||(a=!0,t.count--,t.count<=0&&(t.cleanup(),h.delete(e)))}}}export{Y as wrapContinuouslyTypingMessage};
//# sourceMappingURL=continuouslyTypingMessage-CUWcHKBd.js.map
