var v=[{name:"typewriter",containerClass:"persona-stream-typewriter",wrap:"char",useCaret:!0},{name:"pop-bubble",bubbleClass:"persona-stream-pop",wrap:"none"},{name:"letter-rise",containerClass:"persona-stream-letter-rise",wrap:"char"},{name:"word-fade",containerClass:"persona-stream-word-fade",wrap:"word"}],h=new Map;for(let e of v)h.set(e.name,e);var y=e=>{h.set(e.name,e)};var L=`
[data-persona-root] .persona-stream-glyph-cycle .persona-stream-char {
  animation: persona-stream-glyph-cycle-fade
    calc(var(--persona-stream-step, 120ms) * 1.5) ease-out both;
}
[data-persona-root] .persona-stream-glyph-cycle .persona-stream-char[data-glyph-cycle-final] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@keyframes persona-stream-glyph-cycle-fade {
  from { opacity: 0.35; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  [data-persona-root] .persona-stream-glyph-cycle .persona-stream-char {
    animation: none !important;
    opacity: 1 !important;
  }
}
`.trim(),l="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#$%&@",P=10,H=120,d=120,W=.4,R=50,N=e=>{var r;if(!e)return d;let n=((r=e.style.getPropertyValue("--persona-stream-step"))==null?void 0:r.trim()).match(/([\d.]+)\s*ms/);return n?parseFloat(n[1]):d},E=e=>{let t=e.closest(".persona-stream-glyph-cycle"),n=N(t);return H*n/d},u=e=>{let t=l[Math.floor(Math.random()*l.length)];return e&&t===e&&(t=l[(l.indexOf(t)+1)%l.length]),t},k=e=>{let t=e.closest(".persona-stream-glyph-cycle");if(!t)return;let n=t.querySelectorAll(".persona-stream-char[data-glyph-cycle-final]"),r=!1;for(let a of Array.from(n)){if(a===e){r=!0;continue}r&&Math.random()<W&&(a.textContent=u())}},f=new WeakMap,A=25,S=.5,D=6,T=.25,C=new WeakMap,M=new WeakMap,_=(e,t)=>{var a;if(!e)return A*S;let n=C.get(e);C.set(e,t);let r=(a=M.get(e))!=null?a:A;if(n!==void 0){let s=t-n;s>1&&(r=r*(1-T)+s*T,M.set(e,r))}return Math.max(D,r*S)},i=new Map,I=e=>{var n;let t=e.closest("[data-message-id]");return(n=t==null?void 0:t.dataset.messageId)!=null?n:null},F=e=>{var t;e&&i.set(e,((t=i.get(e))!=null?t:0)+1)},B=e=>{var n;if(!e)return;let t=(n=i.get(e))!=null?n:0;t<=1?i.delete(e):i.set(e,t-1)},b=e=>{var p;if(e.dataset.glyphCycleScheduled==="true")return;let t=(p=e.textContent)!=null?p:"";if(!t||/\s/.test(t))return;e.dataset.glyphCycleScheduled="true",e.dataset.glyphCycleFinal=t,e.setAttribute("data-preserve-runtime","stream-glyph-cycle"),e.textContent=u();let n=I(e);n&&(e.dataset.glyphCycleMessageId=n),F(n);let r=e.closest(".persona-stream-glyph-cycle"),a=Date.now(),s=_(r,a),c=E(e),m=P*c,o=a+m;if(r){let g=f.get(r);g!==void 0&&(o=Math.max(o,g)),f.set(r,o+s)}O(e,t,o)},O=(e,t,n)=>{var c;if(e.dataset.glyphCycleStarted==="true")return;e.dataset.glyphCycleStarted="true";let r=E(e),a=(c=e.textContent)!=null?c:void 0,s=()=>{var o;if(!e.isConnected)return;if(Date.now()>=n){e.textContent=t,e.removeAttribute("data-preserve-runtime"),delete e.dataset.glyphCycleStarted,delete e.dataset.glyphCycleFinal,B((o=e.dataset.glyphCycleMessageId)!=null?o:null),delete e.dataset.glyphCycleMessageId;return}let m=u(a);e.textContent=m,a=m,k(e),setTimeout(s,r)};setTimeout(s,r)},w=e=>{var n;let t=(n=e.querySelectorAll)==null?void 0:n.call(e,".persona-stream-glyph-cycle .persona-stream-char:not([data-glyph-cycle-scheduled])");if(t)for(let r of Array.from(t))b(r)},G=e=>e.nodeType===1,x={name:"glyph-cycle",containerClass:"persona-stream-glyph-cycle",wrap:"char",skipTags:["a","script","style"],styles:L,bufferContent(e){if(e.length<R)return"";let t=0,n=-1,r=0;for(;r<e.length;){if(e[r]==="*"&&e[r+1]==="*"){t+=1,r+=2;continue}/\s/.test(e[r])&&t%2===0&&(n=r),r+=1}return n<0?"":e.slice(0,n)},isAnimating(e){var t;return((t=i.get(e.id))!=null?t:0)>0},onAttach(e){w(e);let t=new MutationObserver(n=>{for(let r of n)for(let a of Array.from(r.addedNodes))G(a)&&(a.classList.contains("persona-stream-char")&&a.closest(".persona-stream-glyph-cycle")?b(a):w(a))});return t.observe(e,{childList:!0,subtree:!0}),()=>t.disconnect()}};y(x);var j=x;export{j as default,x as glyphCycle};
