(function(){try{var g=typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};g["__faroBundleId_Speechify Chrome Extension"]="13.4.1"}catch(l){}})();
import{a as $e}from"./chunk-IKU6LQOS.js";import{a as qe}from"./chunk-4W2OHDCC.js";import{$b as Ge,$f as Xe,Db as Be,Ib as ue,Ne as Ue,Of as ge,Uf as W,Ya as De,Yf as ze,_f as Ze,ag as je,bb as Me,bg as Ke,cg as Je,dg as Qe,eg as et,fg as tt,gc as Z,gg as rt,hc as k,hg as nt,ig as ot,jg as it,kc as Fe,lc as We,lg as at,mg as st,pc as Ye,sb as ke,tb as Ve,tc as me,u as Ne,uc as he}from"./chunk-XMRXO6YU.js";import{g as xt,h as He}from"./chunk-ODCFEFOB.js";import{a as fe,e as Le,i as z,n as ne}from"./chunk-24ZZP5UQ.js";import{b as F,f as St,g as Ot}from"./chunk-GQY3J744.js";import{H as Ae,I as be,K as _e,p as Ce}from"./chunk-NWEJW7RD.js";import"./chunk-ASZMUWWE.js";import"./chunk-4XRFE7WB.js";import"./chunk-6I7EUWRH.js";import{d as Oe,g as y,i as c,k as xe,m as Tt,n as P}from"./chunk-CLPINNGF.js";P();y();P();y();var Ie=Oe(xt());Tt();P();y();var pe=e=>{let t=Math.min(...e.map(o=>o.x)),n=Math.min(...e.map(o=>o.y)),d=Math.max(...e.map(o=>o.x+o.width)),i=Math.max(...e.map(o=>o.y+o.height)),h=d-t,T=i-n;return new DOMRect(t,n,h,T)},X=({rect:e,horizontalPadding:t,verticalPadding:n})=>new DOMRect(e.x-t,e.y-n,e.width+2*t,e.height+2*n);P();y();var S=Oe(Ot());St();P();y();var lt="speechify-hover-player-icon";P();y();var ct=e=>c("svg",{width:"80%",height:"80%",viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},c("path",{d:"M23.7334 18.3094C25.5112 17.283 25.5112 14.717 23.7334 13.6906L11.7334 6.76237C9.95562 5.73597 7.7334 7.01897 7.7334 9.07177V22.9282C7.7334 24.981 9.95562 26.264 11.7334 25.2376L23.7334 18.3094Z",fill:"currentColor"})),dt=e=>c("svg",{width:"70%",height:"70%",viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},c("path",{d:"M9.33317 5.33337C7.86041 5.33337 6.6665 6.52728 6.6665 8.00004V24C6.6665 25.4728 7.86041 26.6667 9.33317 26.6667H11.9998C13.4726 26.6667 14.6665 25.4728 14.6665 24V8.00004C14.6665 6.52728 13.4726 5.33337 11.9998 5.33337H9.33317Z",fill:"currentColor"}),c("path",{d:"M19.9998 5.33337C18.5271 5.33337 17.3332 6.52728 17.3332 8.00004V24C17.3332 25.4728 18.5271 26.6667 19.9998 26.6667H22.6665C24.1393 26.6667 25.3332 25.4728 25.3332 24V8.00004C25.3332 6.52728 24.1393 5.33337 22.6665 5.33337H19.9998Z",fill:"currentColor"})),ft=z(qe)`
  width: 60%;
  height: 60%;
  circle {
    stroke-width: 4px;
  }
`;var{usePlayingState:bt,useCurrentContent:_t}=k;var Lt=2147483640,Nt=z.button`
  position: absolute;
  cursor: pointer;
  background: transparent;
  border: none;
  outline: none;
  margin: 0;
  padding: 0;
  pointer-events: all;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;

  display: flex;
  justify-content: center;

  @keyframes fadeOut {
    from {
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes loading {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(360deg);
    }
  }

  .fadeOut {
    animation-name: fadeOut;
    animation-duration: ${200}ms;
    animation-timing-function: ease-out;
    animation-fill-mode: forwards;
  }

  .fadeIn {
    animation-name: fadeIn;
    animation-timing-function: ease-out;
    animation-duration: ${100}ms;
    animation-fill-mode: forwards;
  }

  .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: ${ne["bg-prim-w-100"]};
    color: ${ne["icn-txt-prim"]};
    box-shadow: 0px 3px 12px 0 #0000001f;
    border-radius: 9999px;

    &:hover {
      color: ${ne["icn-txt-prim-electric"]};
    }
  }
`,br=z($e)`
  height: ${({size:e})=>e};
  left: -${4}px;
  top: -${4}px;
  width: ${({size:e})=>e};
  g circle {
    stroke-width: 3;
  }
`,ye=e=>[e.ariaLabel,...Array.from(e.children).map(t=>ye(t))].join(""),Ht=(e,t)=>e?e===t.element||"isConnected"in e&&!e.isConnected&&ye(e)===ye(t.element):!1,Dt=(e,t)=>{let n=(0,S.useCallback)(d=>setTimeout(()=>{t(i=>i.filter(h=>d.instanceId!==h.instanceId))},200),[]);F(()=>{let d=e.filter(i=>!i.destroyingTimeout&&i.hoverPlayerState==="Initial").map(i=>i.instanceId);d.length>0&&t(i=>i.map(h=>d.includes(h.instanceId)?{...h,destroyingTimeout:n(h)}:h))},[e,n])};function mt({hoveredParagraph:e,emotionCache:t,onPlaybackStarted:n}){let d=Be(),i=bt(),h=_t(),{activeElement:T}=Me(),[o,R]=(0,S.useState)(),[m,E]=(0,S.useState)([]);Dt(m,E),F(()=>{i!=="paused"&&i!=="stopped"&&n()},[i]);let I=(0,S.useCallback)(a=>{R(l=>l&&a(l)),E(l=>{let f=!1,A=l.map(b=>{let u=a(b);return f=f||u!==b,u});return f?A:l})},[]),x=(0,S.useCallback)((a,l)=>I(f=>f.instanceId!==a?f:l(f)),[]);F(()=>{!e&&o&&(R(void 0),E(a=>[o,...a]))},[e,o]),F(()=>{e&&(e.reactKey!==o?.hoveredParagraph.reactKey?(o&&E(a=>[o,...a].filter(l=>l.hoveredParagraph.reactKey!==e.reactKey)),R({instanceId:ke(),hoveredParagraph:e,hoverPlayerState:"Initial",destroyingTimeout:void 0,buttonRef:(0,S.createRef)()})):e!==o.hoveredParagraph&&R(a=>a&&{...a,hoveredParagraph:e}))},[e,o]),F(()=>{i==="buffering"||i==="seeking"||I(a=>a.hoverPlayerState!=="BufferingInProgress"?a:{...a,hoverPlayerState:"Initial"})},[i,I,o,m]);let D=(0,S.useCallback)(async()=>{if(!o||(n(),x(o.instanceId,l=>({...l,hoverPlayerState:"BufferingStarting"})),await Ue(),!o.hoveredParagraph.id))return;Z.seekToPosition(o.hoveredParagraph.id,[0,0]),Ge(k.getPlayingState())||Z.play(),We("extension_hover_player_button_clicked",{isClonedVoice:d}),Ye({triggeredFrom:"HoverPlayer"}),x(o.instanceId,l=>({...l,hoverPlayerState:"BufferingInProgress"}))},[o,R,h]),L={x:window.scrollX,y:window.scrollY},M=(0,S.useMemo)(()=>[o,...m].filter(Boolean),[[o,m]]);return c(Le,{value:t},M.map(a=>{let l=a===o,{getPlayerIconRect:f}=a.hoveredParagraph,A=i==="buffering"||i==="seeking",b=m.some($=>$.hoverPlayerState!=="Initial"),u=a.hoverPlayerState!=="Initial"||A&&l&&!b,v=f();if(!v)return null;let _=Ht(T,a.hoveredParagraph),Q=_&&(i==="playing"||i==="buffering"||i==="seeking")&&!u,U=()=>{l&&(Q?Z.pause():_?Z.play():D())};return c(S.default.Fragment,{key:a.hoveredParagraph.reactKey},c("div",{"aria-label":me("HOVER_PLAYER"),"data-testid":l?he.HOVER_PLAYER:void 0,style:{position:"absolute",left:`${v.left+L.x-4}px`,top:`${v.top+L.y}px`,width:`${v.width+2*4}px`,height:`${v.height+2*4}px`,zIndex:Lt}},c(Nt,{"aria-label":me("HOVER_PLAYER_BUTTON"),"data-testid":l?he.HOVER_PLAYER_BUTTON:void 0,onClick:U,ref:a.buttonRef},c("div",{id:l?lt:void 0,style:{width:`${v.width}px`,height:`${v.height}px`},className:["icon",l||u?"fadeIn":"fadeOut"].join(" ")},u?c(ft,null):Q?c(dt,null):c(ct,null)))))}))}P();y();P();y();var Mt=/^\s*$/,ht=e=>e.nodeType===Node.TEXT_NODE&&!Mt.test(e.textContent??""),gt=e=>{if(!e)return null;if(ht(e))return e;for(let t of Array.from(e.childNodes)){if(ht(t))return t;let n=gt(t);if(n!==null)return n}return null};function*pt(e){if(e.nodeType===Node.TEXT_NODE){let t=e.textContent?.trim().split(" ")??"";for(let n of t)yield{node:e,word:n}}else for(let t=0;t<e.childNodes.length;t++)yield*pt(e.childNodes[t])}var Pe=(e,t)=>{if(!e||!gt(e))return null;let n=document.createRange(),d=pt(e),i=null,h="",T=0,o=1;for(;o<=t;){let R=d.next();if(R.done)return o<t&&n.setEnd(i,Math.min(T+h.length,i?.textContent?.length??0)),null;let{node:m,word:E}=R.value;if(!(!m||!E)){if(i!==m&&(T=0),o===1&&n.setStart(m,T),o===t){let I=(m.textContent?.indexOf(E,T)??0)+E.length;n.setEnd(m,Math.min(I,m.textContent?.length??0))}T+=E.length+1,h=E,i=m,o++}}return n};var Y=He(Ve({hoveredParagraph:null,shouldShowHint:!1},e=>({updateHoveredParagraph:t=>e(n=>({...n,hoveredParagraph:t})),updateShouldShowHint:t=>e(n=>({...n,shouldShowHint:t}))}))),Re=({wasLifecycleAudioLoadedTriggered:e,id:t,element:n,ref:d,index:i})=>{if(!n)return null;let h=Pe(n,1),T=Pe(n,3),o=()=>(h??n).getBoundingClientRect(),R=()=>(T??n).getBoundingClientRect();if(W()){let u=n.firstElementChild??n;R=()=>u.getBoundingClientRect();let v=null;o=()=>{let _=u?.getBoundingClientRect();return _.height>0&&_.width>0&&(v=_),v}}let m=window.getComputedStyle(n),E=parseFloat(m.fontSize||"16")||16,I=Math.max(E,20),x=R(),D=new DOMRect(x.x-16,x.y,x.width+16,x.height),L=()=>{let u=o();if(!u)return null;let v=(u.height-I)/2;return new DOMRect(D.x-I,u.top+v,I,I)},M=()=>{let u=o();return u?new DOMRect(u.x,u.top+u.height,x.width+4,x.height):null},a=L();if(!a)return null;let l=X({rect:a,horizontalPadding:4,verticalPadding:4}),f=pe([x,D,l]);e&&(f=pe([f,n.getBoundingClientRect()]));let A=X({rect:f,horizontalPadding:4,verticalPadding:0}),b=T?.toString();return{element:n,getUnderlineRect:M,elementFontSize:E,firstThreeWords:b,getFirstThreeWordsRect:R,hoverAreaRect:A,hoverPlayerSize:I,getPlayerIconRect:L,id:t,ref:d,index:i,get reactKey(){return`${t}-${b}-${i}`}}};var Pt="speechify-hover-player-shadow-root",Rt="speechify-hover-player-container",j=null,H=null,Et=fe({key:"hover-player-emotion-cache"}),Ee=()=>{},Gt="h1 h2 h3 h4 h5 h6 select textarea button label audio video dialog embed menu nav noframes noscript object script style svg aside footer #footer pre summary form input iframe img map meta link title track area base basefont col colgroup head html param source table tbody td tfoot th thead tr",Ft="span a li ol ul h1 h2 h3 h4 h5 h6 select textarea button label audio video dialog embed menu nav noframes noscript object script style svg aside footer #footer pre summary form input iframe img map meta link title track area base basefont col colgroup head html param source table tbody td tfoot th thead tr",Wt=e=>e.nodeType===Node.ELEMENT_NODE;async function Yt(){return(await ge("ceHoverPlayerIgnoredTags")||Gt).split(" ").map(t=>t.toLowerCase())}async function Ut(){return(await ge("ceHoverPlayerTopLevelIgnoredTags")||Ft).split(" ").map(t=>t.toLowerCase())}function It(e,t){return e.clientX>t.x&&e.clientX<t.x+t.width&&e.clientY>t.y&&e.clientY<t.y+t.height}function $t(){let t=document.getElementById("speechify-hint-tooltip-shadow-root")?.shadowRoot?.getElementById("speechify-hint-tooltip");if(t)return t.getBoundingClientRect()}var ve=!1,qt=()=>{let e=async()=>{ve=!0,_e("audio-loading",e)};be("audio-loading",e,"hover-player")};qt();async function oe(e){["boot","init"].includes(e)||(ve=!0);let t=[];if(j=document.querySelector(`#${Pt}`)?.shadowRoot??null,!j){let r=document.createElement("div");r.id=Pt,document.body.appendChild(r),j=r.attachShadow({mode:"open"})}H=j.querySelector(`#${Rt}`),H||(H=document.createElement("div"),H.id=Rt,Et=fe({key:"hover-player-emotion-cache",container:H}),j.appendChild(H));let{updateHoveredParagraph:n,updateShouldShowHint:d}=Y.getState(),i=await Ut(),h=await Yt(),T=r=>W()?!0:!(!r||!Wt(r)||i.includes(r.tagName.toLowerCase())||r.querySelector(h.join(","))!==null||(r.textContent?.trim().split(/\s+/).length??0)<=10||r.closest("a, button, form")),o=()=>{d(!1)},R=r=>{if(!H){Ae(new Error("hover-player renderHoverPlayer is called with no container"),{type:"hover-player"});return}xe(c(mt,{hoveredParagraph:r,emotionCache:Et,onPlaybackStarted:()=>o()}),H)},m=()=>{R(null)},E=async()=>{if(!t||t.length===0)return;Ee();let r=(0,Ie.default)(s=>{let O=t.map(({element:g,id:w,ref:G,index:C})=>Re({wasLifecycleAudioLoadedTriggered:ve,element:g,id:w,ref:G,index:C})).filter(g=>!!g).find(({hoverAreaRect:g})=>It(s,g));if(Y.getState().shouldShowHint){if(!O)return;let g=$t(),w=g&&X({rect:g,horizontalPadding:10,verticalPadding:10});if(w&&It(s,w))return}n(O??null)},16);window.addEventListener("mousemove",r),Ee=()=>{window.removeEventListener("mousemove",r)}},I=async r=>{let s=[],O=Ne(r),g=!O&&(r?.options?.sideEffects??!1),{orator:w}=k.getState();g&&!O||(w&&(s=w.machine.getContext().queue.map((C,q)=>({element:C.ref.ref,id:C.id,ref:C.ref,index:q})).filter(({element:C})=>T(C))),Ce(s,t)||(t=s,E()))},x=await Fe("PLAYABLE_CONTENT_UPDATED",async({changed:r})=>{r&&r.metadata.source!=="Selection Player"&&I(r)}),{currentContent:D,orator:L}=k.getState();D&&I(D);let M=null;L&&(M=L.machine.onContextChange("queue",()=>{let{currentContent:r}=k.getState();r&&I(r)}));function a(r,s=20,O=4){if(!r)return!0;let w=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,{acceptNode:te=>te.nodeValue?.trim()?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}).nextNode();if(!w)return!0;let G=w.nodeValue,C=G.trim().split(/\s+/).slice(0,O).join(" ");if(!C)return!0;let q=G.indexOf(C);if(q===-1)return!0;let se=document.createRange();se.setStart(w,q),se.setEnd(w,q+C.length);let p=se.getBoundingClientRect();if(p.bottom<=0||p.top>=window.innerHeight||p.right<=0||p.left>=window.innerWidth)return!0;let Te=[{x:p.left+p.width*.25,y:p.top+p.height*.5},{x:p.left+p.width*.5,y:p.top+p.height*.5},{x:p.left+p.width*.75,y:p.top+p.height*.5}],Se=0;for(let te of Te){let le=document.elementFromPoint(te.x,te.y),ce=!1,re=le;for(;re&&!ce;){if(re===r){ce=!0;break}re=re.parentElement}let de=le?window.getComputedStyle(le):null,wt=de?.pointerEvents==="none"||de?.visibility==="hidden"||parseFloat(de?.opacity||"1")<.1;!ce&&!wt&&Se++}return Se/Te.length*100>=s}function l(r){if(!r?.element)return!1;try{let s=r.element,O=s.getBoundingClientRect(),g=r.ref?.highlightInfo?.scrollElement??(ue()?document.querySelector(ue()):null);if(g){let w=g.getBoundingClientRect();return O.top>=w.top&&O.bottom<=w.bottom}return!a(s,20)}catch(s){return console.error("Error in isElementVisible Hover Player:",s),!1}}let f=null,A=!1,b=Y.subscribe((r,s)=>{s?.hoveredParagraph!==r?.hoveredParagraph&&(r?.hoveredParagraph&&l(r.hoveredParagraph)?(f=r?.hoveredParagraph?.getFirstThreeWordsRect()??null,R(r.hoveredParagraph)):m(),r?.hoveredParagraph?.element!==s?.hoveredParagraph?.element&&(s?.hoveredParagraph?.element&&(U.unobserve(s?.hoveredParagraph?.element),$.unobserve(s?.hoveredParagraph?.element)),r?.hoveredParagraph?.element&&(U.observe(r?.hoveredParagraph?.element),$.observe(r?.hoveredParagraph?.element))))}),u=(0,Ie.default)(()=>{A=!1;let{hoveredParagraph:r}=Y.getState();r&&(f=r.getFirstThreeWordsRect(),l(r)||m())},100),v=()=>{A=!0,u()};window.addEventListener("scroll",v);let _=()=>{let{hoveredParagraph:r}=Y.getState();if(!r)return;let s=r.getFirstThreeWordsRect();if(!s||!(s.x!==f?.x||s.y!==f?.y||s.width!==f?.width||s.height!==f?.height))return;let g=Re({wasLifecycleAudioLoadedTriggered:!1,element:r.element,id:r.id,ref:r.ref,index:r.index});n(g),f=s},ae=!1,Q=r=>{ae=r[0].isIntersecting},U=new ResizeObserver(_),$=new IntersectionObserver(Q),ee,we=()=>{!A&&ae&&_(),ee=requestAnimationFrame(we)};return ee=requestAnimationFrame(we),()=>{o(),ee&&cancelAnimationFrame(ee),window.removeEventListener("scroll",v),U.disconnect(),$.disconnect(),x(),b(),Ee(),M&&M(),m()}}var zt=()=>!(Je()||et()||nt()||Qe()||tt()||ot()||Xe()||Ze()||je()||ze()||at()||rt()||Ke()||st()||it());var J={"paragraph-player":!1,"hover-player":!1},K=()=>Object.values(J).filter(Boolean).length,Zt=e=>K()===1&&J[e],ie=[],vt=e=>{Zt(e)&&(ie.forEach(t=>t()),ie=[]),J[e]=!1};async function Xt(e,t,n){let d=n.name;if(d==="paragraph-player"&&W()&&e?.playButtons?.googledocs?.paragraphPlayer===!1||d==="hover-player"&&!zt())return;if(K()>0)return J[d]=!0,()=>vt(d);J[d]=!0;let i=await oe(t);if(K()===0){i();return}if(ie.push(i),ie.push(De(async()=>{i(),i=await oe(t),K()===0&&i()})),K()!==0)return()=>vt(d)}export{Xt as default};
//# sourceMappingURL=init-7ROPORNP.js.map
