import{a as ie}from"./chunk-533YBOH2.js";import{k as Z,s as ee}from"./chunk-KO4WPNRU.js";import"./chunk-F5622KQ7.js";import"./chunk-WC6QURV6.js";import{c as X}from"./chunk-TIGAXALM.js";import"./chunk-ZQRXZJGY.js";import"./chunk-6S4AP2UG.js";import"./chunk-O3LC63CS.js";import"./chunk-AG3QEKLJ.js";import{$a as _,Cd as oe,Ea as M,G as O,Na as f,Oa as w,Qa as $,ab as z,cb as V,cd as te,db as K,gb as Q,i as I,ma as k,ob as Y,pb as H,sb as y,tb as q,ub as J,wa as A}from"./chunk-RISKGE32.js";import"./chunk-6O6MLDWR.js";import{b as C,c as D,g as U,k as j}from"./chunk-F4AZU7R4.js";import{b as N,f as fe,g as ye}from"./chunk-GQY3J744.js";import{d as pe,f as p,g as c,i as r,k as L,m as ge,n as d}from"./chunk-CLPINNGF.js";d();c();ge();d();c();function ne(){let{usePlayingState:e}=w,t=e(),i=t==="playing",o=t==="buffering",a=t==="errored",n=k(()=>{i?f.pause():f.play()});return r("div",{onClick:n,style:{display:"flex",justifyContent:"center",padding:8}},r(Z,{onClick:n,isLoading:o,isPlaying:i,isLoadingFailed:a,size:"22px",outlined:!0}))}d();c();var b=pe(ye());fe();var S=3;function se({wrapper:e,isExpanded:t}){let[i,o]=(0,b.useState)(0);N(()=>{(async()=>{let me="gdocsTooltipShownCount",{gdocsTooltipShownCount:ue}=await p.storage.local.get(me),E=Number(ue||0);o(E),E<S&&await p.storage.local.set({gdocsTooltipShownCount:E+1})})()},[]);let a=j(X)`
    position: fixed;
    margin-bottom: -80px;
  `,{usePlayingState:n}=w,l=n(),m=l==="playing",g=l==="buffering",u=l==="errored",[s,h]=(0,b.useState)(!1);N(()=>{m&&h(!0)},[m]);let le=(0,b.useMemo)(()=>D({key:"player-emotion-cache",container:e}),[e]),ce=async()=>{f.play(),o(S),await p.storage.local.set({gdocsTooltipShownCount:S})},de=v=>!!((v||i<S&&!s)&&!m&&!t);return r(U,{value:le},r(ee,{onClick:ce,root:e,isPlaying:m,isLoading:g,isLoadingFailed:u,color:C.sfPrimCta,hoverColor:C.sfPrimCtaHov,background:"transparent"},v=>r(a,{id:"gdocs-header-button",background:"rgba(20, 32, 46, 1)",display:de(v),direction:"up",tooltipStyle:{whiteSpace:"nowrap",justifyContent:"space-evenly",marginLeft:"80px"}},r(Q,{color:C.bgSecInv1000},"Listen to this document"))))}d();c();var re=()=>{let e;return O.on("update",({autoScrollTemporary:t})=>{if(t&&t!==e){let i=K();i!==null&&V(i)}e=t})};var W="speechify-bubble-player",F="speechify-gdocs-nudge-root",T="speechify-gdocs-nudge-root-container",x,B,P=!1,ae,be=ie({padding:0,width:40,height:40});async function G(e){await A(),ae&&ae.disconnect(),oe("pill_player-ocr-recommendation");let t=_().map(a=>z(a)),i=Math.min(...t)??0,o=await H(e,i);$(o,!0)}async function he(e){await ve(e);let t=await I();te(t)||await Ce(e),x=new URLSearchParams(window.location.search).get("tab")||"",B=q().heading||"",P=document.visibilityState==="hidden",P||await G(e);let i=()=>{requestAnimationFrame(async()=>{let n=new URLSearchParams(window.location.search).get("tab")||"";if(x&&n!==x)x=n,Y(),await G(e);else{let l=q().heading||"";l&&B!==l&&(B=l,setTimeout(()=>{J(e)},500))}})},o=async()=>{document.visibilityState!=="hidden"&&P&&(P=!1,await G(e))};document.addEventListener("visibilitychange",o),window.navigation.addEventListener("navigate",i);let a=re();return()=>{document.querySelector(`div.${W}`)?.remove(),document.querySelector(`#${F}`)?.remove(),document.querySelector(`div.${T}`)?.remove(),document.removeEventListener("visibilitychange",o),window.navigation.removeEventListener("navigate",i),a()}}async function ve(e){let t=document.querySelector(e.selectors.bubbleContainer),i=40,o=0;for(;!t&&(await M(100),t=document.querySelector(e.selectors.bubbleContainer),o++,!(o>=i)););if(!t)return;if(!document.querySelector(`div.${W}`)){let n=document.createElement("div");n.classList.add(W),n.classList.add("instant-button"),n.classList.add(be),t.firstChild?.insertBefore(n,t.firstChild.childNodes[1]),L(r(ne,null),n)}}async function Ce(e){if(document.querySelector(`#${F}`))return;let i=document.querySelector(e.selectors.leftSidebarContainer),o=document.createElement("div");o.id=F;let a=await y(e.selectors.navigationWidget),n=(m=!1)=>{let g=!1;a.classList.contains(e.selectors.navigationWidgetHidden)?(g=!1,m||y(e.selectors.navigationWidgetSummaryContainer).then(u=>{let s=u.querySelector(`.${T}`);s&&s.remove()}),o.style.cssText="position: absolute;top:70px;left:25px;height:20px;width:20px;pointer-events:all",i?.appendChild(o)):(g=!0,m||y(e.selectors.navigationWidgetSummaryContainer).then(u=>{let s=u?.querySelector(`.${T}`);s&&s.remove()}),y(e.selectors.navigationWidgetSummaryContainer).then(u=>{o.style.cssText="position: absolute;top: -4px; right:15px; height:20px;width:20px;";let s=document.createElement("div");s.className=T,s.style.cssText="margin-bottom: 15px; padding-left: 24px;";let h=document.createElement("span");h.textContent="Listen to this document",s.appendChild(h),s.appendChild(o),u.prepend(s)})),L(r(se,{wrapper:o,isExpanded:g}),o)};n(!0),new MutationObserver(()=>{n()}).observe(a,{attributes:!0})}export{he as default};
//# sourceMappingURL=init-OMNPNJMS.js.map
