import{a as D,b as F}from"./chunk-U7XK3CBQ.js";import{a as k}from"./chunk-SSSSNVF5.js";import{a as w}from"./chunk-ZQRXZJGY.js";import"./chunk-AG3QEKLJ.js";import{Ca as M,Ha as N,Ra as G,Ta as h,Wa as O,lb as R,ta as P}from"./chunk-RISKGE32.js";import{V as L,ba as W,ja as q}from"./chunk-6O6MLDWR.js";import{k as T}from"./chunk-F4AZU7R4.js";import{g as A}from"./chunk-GQY3J744.js";import{d as S,g as p,i as l,n as y}from"./chunk-CLPINNGF.js";y();p();var x=S(A()),$=S(W());y();p();var g=S(A());var Y=T(h)`
  font-family: var(--font-family);
  margin-left: 8px;
  background: rgba(32, 33, 36, 0.059);
  border-radius: 4px;
  cursor: pointer;
  height: 20px;
  padding: 3px 4px;
  overflow: hidden;
`,z=T(h)`
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
`,_=(e,n,r="")=>{if(e instanceof HTMLElement&&(n.some(t=>e.classList.contains(t))||r.split(", ").some(t=>e.matches(t))||e.clientWidth===1||e.style.display==="none"||e.style.visibility==="hidden"))return[];let o=Array.from(e.childNodes);return o.length===0?e.nodeType===Node.TEXT_NODE?[{text:e.textContent??"",elem:e}]:[]:o.flatMap(t=>t.nodeType===Node.TEXT_NODE?[{text:t.textContent??"",elem:t}]:t.nodeType===Node.ELEMENT_NODE?_(t,n,r):[]).filter(t=>t.text.trim().replace(/\n|\r\n/,"").length>1).filter(t=>(t.text.match(/\w+/)?.length??0)>0)},H=async(e,n,r="")=>({getContent:await G(async()=>({content:_(e,n,r).map(i=>i.elem),chunksAfter:0,chunksBefore:0})),converter:o=>({text:k(o),ref:{ref:o}}),options:{autoplay:!0,sideEffects:!1},metadata:{source:"Google"}}),J=({isPlaying:e,isLoading:n,...r})=>{let o=(0,g.useMemo)(()=>n?"loading":e?"playing":"paused",[e,n]);return l(h,{...r},o==="playing"&&l(D,null),o==="loading"&&l(w,{color:"#4A4A4A",width:"14",height:"14"}),o==="paused"&&l(F,null))},E=({ignoreClasses:e,ignoreTags:n,handle:r,onStateChange:o,wrapper:i})=>{let[t,s]=(0,g.useState)(null),{play:a,pause:c,isActive:u,state:m,queueAndPlayContent:I}=N(t)??{},{duration:v}=M(t,u),C=u&&m==="playing",b=u&&m==="buffering";(0,g.useEffect)(()=>{H(i,e,n).then(s)},[i]),(0,g.useEffect)(()=>{o(r,m,c)},[m]);let Q=async f=>{if(f.preventDefault(),f.stopPropagation(),L()||q("browser-action",{animate:!1},"pill-player"),!u)return I();if(!b){if(C)return c();if(!C)return a()}};return l(Y,{yAlign:!0,relative:!0,column:!1,onClick:f=>Q(f),separation:"4px"},!v.isLoading&&l(J,{isLoading:b,isPlaying:C}),l(z,{yAlign:!0,xAlign:!0},l(R,{color:"#676767",fixedWidthNumbers:!0,duration:v})))};var d="speechify-google-play-button-container";async function B(e,n,r=250){return new Promise(o=>{setTimeout(()=>{(0,x.render)(e,n),o(!0)},r)})}async function j(e,n,r,o){let i=Array.from(document.querySelectorAll(e.selector)).filter(Boolean);for(let[t,s]of i.entries())if(s){if(s.querySelector(`.${d}`))continue;let a=s.querySelector(e.player);if(!a)continue;let c=document.createElement("div");c.className=d,c.setAttribute("style",e.css),B(l(E,{ignoreClasses:n,ignoreTags:r,handle:`google-faq-${t}`,key:`google-faq-${t}}`,onStateChange:o,wrapper:s}),c),a.prepend(c)}}async function K(e,n,r,o){let i=document.querySelector(e.selector);if(!i||i.querySelector(`.${d}`))return;let t=i.querySelector(e.player);if(!t)return;let s=document.createElement("div");s.className=d,s.setAttribute("style",e.css),s.setAttribute("data-testId",O.GOOGLE_ABOUT_PLAY_BUTTON),B(l(E,{ignoreClasses:n,ignoreTags:r,handle:"google-panel",key:"google-panel",onStateChange:o,wrapper:i}),s),t.prepend(s)}async function V(e,n,r,o){let i=Array.from(document.querySelectorAll(e.selector)).filter(Boolean);for(let[t,s]of i.entries()){let a=s.parentElement?.parentElement;if(a){if(a.querySelector(`.${d}`))continue;let c=a.querySelector(e.player);if(!c)continue;let u=document.createElement("div");u.className=d,u.setAttribute("style",e.css),(0,x.render)(l(E,{ignoreClasses:n,ignoreTags:r,handle:`google-site-${t}`,key:`google-site-${t}`,onStateChange:o,wrapper:a}),u),c.append(u)}}}var Z=e=>e.some(n=>n.target instanceof HTMLElement?n.target?.className?.includes("speechify")||n.target?.id?.includes("speechify"):!1);async function ee(e){await P(e.selectors.mutationContainer);let n=()=>{},r=(0,$.default)(t=>{if(Z(t))return;let{ignoreClasses:s,ignoreTags:a}=e.selectors;if(e.selectors.faq?.enabled&&j(e.selectors.faq,s,a,n),e.selectors.panels)for(let c of e.selectors.panels.variants){let u={...e.selectors.panels,...c};u.enabled&&K(u,s,a,n)}e.selectors.sites?.enabled&&V(e.selectors.sites,s,a,n)},100);r([]);let o=document.querySelector(e.selectors.mutationContainer),i=new MutationObserver(r);return o&&i.observe(o,{subtree:!0,childList:!0}),()=>{i.disconnect(),document.querySelectorAll(`.${d}`).forEach(t=>t.remove())}}export{ee as default};
//# sourceMappingURL=init-BSU3BUTQ.js.map
