(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 Ne}from"./chunk-QLRPE3XY.js";import{a as _e}from"./chunk-UJD7WEL5.js";import{Ad as be,Ae as Ie,Ee as ve,Fb as pe,Pd as Te,Rd as he,Sd as Me,Ua as ue,Ue as Le,Vd as Se,Wd as Ge,Ye as mt,Za as fe,b as ae,bf as Oe,ca as ce,ec as de,ef as Be,f as le,gc as _,gd as Ce,hc as L,hd as Ee,ic as I,id as ye,jc as ge,lc as N,rd as k,yg as V,ze as xe,zg as Pe}from"./chunk-XMRXO6YU.js";import{g as me,o as F}from"./chunk-ODCFEFOB.js";import{i as O,l as B}from"./chunk-24ZZP5UQ.js";import{b as j,f as lt,g as D}from"./chunk-GQY3J744.js";import{H as se,M as R}from"./chunk-NWEJW7RD.js";import"./chunk-ASZMUWWE.js";import"./chunk-4XRFE7WB.js";import"./chunk-6I7EUWRH.js";import{d as x,g as m,i,k as b,m as Y,n as c}from"./chunk-CLPINNGF.js";c();m();Y();c();m();lt();c();m();Y();c();m();var q=x(D()),$e=x(me());c();m();c();m();c();m();var Ae=e=>e.nodeType===Node.TEXT_NODE||["inline","inline-block"].includes(getComputedStyle(e).display),K=e=>e.every(Ae),ct=(e,t)=>{let o=document.createElement("span");e.forEach((n,r)=>{o.appendChild(n.cloneNode(!0)),r!==e.length-1?t.removeChild(n):t.replaceChild(o,n)})},we=e=>{let t=Array.from(e.childNodes);if(K(t))return;let o=!1;t.reduce((r,s)=>{let a=Ae(s);return a&&(o?r[r.length-1].elements?.push(s):r[r.length]={elements:[s],parentElement:s.parentElement}),o=a,r},[]).forEach(r=>{r.elements.length>1&&ct(r.elements,r.parentElement)})};var ut=["gmail_attr","h5",".gmail_signature"],X=e=>{if(e instanceof HTMLElement&&ut.some(n=>e.classList.contains(n)))return[];we(e);let t=Array.from(e.childNodes);return t.length===0||K(t)?[{text:e.textContent??"",elem:e}]:t.flatMap(n=>n.nodeType===Node.TEXT_NODE?[{text:n.textContent??"",elem:n}]:n.nodeType===Node.ELEMENT_NODE?X(n):[]).filter(n=>n.text.trim().replace(/\n|\r\n/,"").length>0).filter(n=>(n.text.match(/\w+/)??[]).length>0)};c();m();var ft="div.nH",pt=".aDh > table tr:nth-child(1)",dt=".Am.Al.editable";var gt="div.h7[aria-expanded]",Ct="div.ii.gt",Et=".adP",Re="data-message-id",yt=`[${Re}]`,bt=".gmail_quote";var De=e=>e?.selectors?.main||ft,P=e=>e?.selectors?.composeToolbar||pt,Fe=e=>e?.selectors?.composeEmailBody||dt;var Z=e=>e?.selectors?.messageContainer||gt,ke=e=>e?.selectors?.messageBody||Ct,Ve=e=>e?.selectors?.messageBodyFallback||Et,qe=e=>e?.selectors?.messageIdElement||yt,We=e=>e?.selectors?.messageIdAttributeName||Re,Ue=e=>e?.selectors?.messageQuoteArea||bt;var z=e=>{let t=Fe(e),o=document.querySelector("div[speechify-play-window-id]");if(!o)return null;let n=o.querySelector(t);if(!n)return null;let r=()=>{let s=[];if(!e.shouldOnlyReadEmailBody){let a=o.querySelector("input[name=subjectbox]");a&&s.push({text:a.value,elem:a})}return s.push(...X(n)),s.map(a=>a.elem)};return{converter:s=>({text:k(s),ref:{ref:s}}),contentGenerator:async function*(s){let{waitForMutation:a}=_e(n,{childList:!0,subtree:!0,characterData:!0},s);do yield{content:r(),chunksAfter:0,chunksBefore:0,index:0},await a();while(!s.aborted)},options:{autoplay:!0},metadata:{source:"GmailCompose"}}};c();m();var He="speechify-gmail-root";function Qe(e){Array.from(document.querySelectorAll("div[speechify-play-window-id]")).forEach(r=>r.removeAttribute("speechify-play-window-id"));let o=e.closest(".M9"),n=de({avoidNumbers:!0});return o?.setAttribute("speechify-play-window-id",n),o}var Gt=({isLoading:e,isLoadingFailed:t,isPlaying:o,playPause:n})=>i(Se,{onClick:n,isLoading:e,isPlaying:o,isLoadingFailed:t,"data-tooltip":"Listen to email"});function Ye({wrapper:e,config:t}){let[o,n]=(0,q.useState)(null),{usePlayingState:r,useCurrentContent:s}=L,{play:a,pause:E}=_,u=r(),T=u==="buffering",l=u==="playing",f=u==="errored",p=s(),d=!!p&&p?.id===o?.id;(0,q.useEffect)(()=>{let G=new MutationObserver((0,$e.default)(async()=>{let y=u==="playing"||u==="buffering";if(d){let h=z(t);if(!h)return;I(h,y),_.pause()}},1e3));return G.observe(e,{childList:!0}),()=>{G.disconnect()}},[e,u,d]);let S=async()=>{if(N("extension_gmail_compose_button_clicked",{}),F()||R("browser-action",{animate:!1},"pill-player"),d)return l?E():a();Qe(e);let G=z(t);if(!G)return;let y=I(G,!0);n(y)},w=()=>{N("extension_gmail_compose_tooltip_disabled",{})};return t.playButtons&&t.playButtons.gmail&&t.playButtons.gmail.listenBeforeSending===!1?null:i(Gt,{isLoading:d&&T,isPlaying:d&&l,isLoadingFailed:f,playPause:S,onTooltipDismiss:w})}c();m();var M=x(D());var xt=Me(O.button`
  position: relative;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  border: none;
  padding: 0;
  margin: 0;
  background: none;
  z-index: 0;

  &:before {
    content: '';
    position: absolute;
    z-index: -1;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);

    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 0.15s;
    transition-property: transform, opacity;
  }

  &:hover:before,
  &:active:before {
    opacity: 1;
    transform: scale(1);
  }

  &:hover:before {
    background-color: #f2f2f2;
  }

  &:active:before {
    background-color: #e4e4e4;
  }
`),It=()=>i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},i("path",{d:"M12.8213 6.13965C13.263 6.13976 13.6211 6.49769 13.6211 6.93945V7.20605C13.6211 10.0333 11.5236 12.3688 8.7998 12.7451V14.3652L9.99512 14.3584C10.4369 14.3557 10.7971 14.7115 10.7998 15.1533C10.8025 15.5951 10.4467 15.9553 10.0049 15.958L6.00488 15.9824C5.5632 15.9851 5.20307 15.6291 5.2002 15.1875C5.19753 14.7457 5.55336 14.3855 5.99512 14.3828L7.2002 14.375V12.7383C4.50318 12.3384 2.43359 10.0143 2.43359 7.20605V6.93945C2.43359 6.49769 2.79165 6.13975 3.2334 6.13965C3.67523 6.13965 4.0332 6.49763 4.0332 6.93945V7.20605C4.0332 9.41173 5.82169 11.2001 8.02734 11.2002C10.233 11.2001 12.0215 9.41176 12.0215 7.20605V6.93945C12.0215 6.49769 12.3795 6.13975 12.8213 6.13965ZM8 0.943359C9.65685 0.943359 11 2.28651 11 3.94336V7C11 8.65685 9.65685 10 8 10C6.34315 9.99999 5 8.65685 5 7V3.94336C5 2.28651 6.34315 0.943366 8 0.943359ZM8 2.54297C7.22681 2.54298 6.59961 3.17016 6.59961 3.94336V7C6.59961 7.77319 7.22681 8.40038 8 8.40039C8.7732 8.40039 9.40039 7.7732 9.40039 7V3.94336C9.40039 3.17016 8.7732 2.54297 8 2.54297Z",fill:"#454746"})),vt=()=>i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},i("g",{clipPath:"url(#clip0_672_53029)"},i("path",{d:"M8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0ZM6 5C5.44772 5 5 5.44772 5 6V10C5 10.5523 5.44772 11 6 11H10C10.5523 11 11 10.5523 11 10V6C11 5.44772 10.5523 5 10 5H6Z",fill:"#454746"})),i("defs",null,i("clipPath",{id:"clip0_672_53029"},i("rect",{width:"16",height:"16",fill:B["icn-txt-prim"]})))),Lt=O.div`
  margin-left: -4px;
`,je=({config:e,wrapper:t})=>{let n=Le().status==="recording",{shortcuts:r}=ve(),{voiceDictation:s}=pe(),a=(0,M.useRef)(null),E=(0,M.useCallback)(p=>{p.preventDefault(),p.stopPropagation(),Be(!1,"gmail_compose")},[]),u=(0,M.useCallback)(()=>{let p=a.current?.querySelector('[aria-label="Dismiss"]');p&&p.click()},[]),T=(0,M.useCallback)(()=>{u()},[u]),l=P(e);(0,M.useEffect)(()=>{let p=l?t.closest(l):null;if(!p)return;let d=p.querySelectorAll('button, [role="button"]');for(let S of d)S.addEventListener("mouseenter",u,{once:!0});return()=>{for(let S of d)S.removeEventListener("mouseenter",u)}},[u,t,l]);let f=(0,M.useCallback)(()=>{N("extension_gmail_compose_tooltip_disabled",{})},[]);return s===!1?null:i("div",{ref:a},i(he,{id:"gmail-voice-typing-button",variant:"gmailStyle",onToolTipDismiss:f,direction:"down",text:i(Lt,null,"Tap",i(Ie,{keys:r["voice-typing"]?.shortcut||"",variant:"gmail"})," to speak"),style:{width:"fit-content",whiteSpace:"nowrap"}},i(xt,{id:"speechify-gmail-draft-mic-button",onClick:E,onMouseEnter:T,"data-tooltip":n?"Stop Recording":`Tap to speak ${xe(r["voice-typing"]?.shortcut||"")}`},n?i(vt,null):i(It,null))))};var oe=x(mt()),ee="speechify-gmail-draft-play-button-container",te="speechify-gmail-draft-mic-button-container",W;function U(){let e=document.querySelectorAll(`.${ee}`),t=document.querySelectorAll(`.${te}`);W&&W.disconnect();for(let o of Array.from(e))b(()=>null,o),o.remove();for(let o of Array.from(t))b(()=>null,o),o.remove()}var Ke=(0,oe.debounce)(({config:e,entries:t})=>{if(ze(t))return;let o=P(e),n=document.querySelectorAll(o);for(let r of Array.from(n)){if(r.querySelector(`.${ee}`))continue;let s=document.createElement("td");s.className="gU gmail-draft-wrapper";let a=document.createElement("div");a.className=ee,b(i(Ye,{wrapper:a,config:e}),a),s.appendChild(a),r.insertBefore(s,r.querySelector("td:nth-child(2)"))}},32),Xe=(0,oe.debounce)(({config:e,entries:t})=>{if(ze(t))return;let o=P(e),n=document.querySelectorAll(o);for(let r of Array.from(n)){if(r.querySelector(`.${te}`))continue;let s=document.createElement("td");s.className="gU gmail-draft-wrapper";let a=document.createElement("div");a.className=te,b(i(je,{wrapper:a,config:e}),a),s.appendChild(a),r.insertBefore(s,r.querySelector("td:nth-child(2)"))}},32);async function Ze(e){let t=await Oe();Ke({config:e,entries:[]}),t&&Xe({config:e,entries:[]}),W=new MutationObserver(o=>{Ke({config:e,entries:o}),t&&Xe({config:e,entries:o})}),W.observe(document,{subtree:!0,childList:!0})}var ze=e=>e.some(t=>{if(t.target instanceof HTMLElement&&J(t.target))return!0;for(let o of t.addedNodes)if(o instanceof HTMLScriptElement||o instanceof HTMLElement&&J(o))return!0;for(let o of t.removedNodes)if(o instanceof HTMLScriptElement||o instanceof HTMLElement&&J(o))return!0;return!1}),J=e=>e.className?.includes("speechify")||e.id?.includes("speechify");c();m();var rt=x(me());Y();c();m();var Ot=e=>{let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?ue(t):!1},H=e=>{let t=l=>l(e),o=()=>{let l=t(Z);return Array.from(document.querySelectorAll(l))},n=l=>Ce({startingNode:l,ignoreCache:!0,shouldFindHeadings:!1,minimumTotalCharThresholdForGaussianHeuristic:4,getAllTextBlocksInitialThreshold:1}).filter(Ot),r=l=>{let f=t(qe),p=t(We),d=l.querySelector(f)?.getAttribute(p)??"";return d||se(new Error("Message ID not found in message view"),{type:"gmail-rewrite"}),d};return{getMessageViews:o,getParagraphs:n,getMessageId:r,findMatchingMessageView:l=>o().find(d=>r(d)===l)||null,findMessageViewForParagraph:l=>{let f=t(Z);return l.closest(f)},getMessageViewBody:l=>l.querySelector(t(ke))||l.querySelector(t(Ve)),getMessageViewBodyQuotedArea:l=>{let f=t(Ue);return l.querySelector(f)},getToWhomDiv:l=>l.querySelector(".ady")}};c();m();var v=x(D());c();m();var Je=(e,t)=>{let o=e.getMessageViewBody(t);return o?e.getParagraphs(o):[]},A=async(e,t)=>{let o=H(e),n=Je(o,t),r=document.querySelector("div.Tm.aeJ");return{getContent:await ge(async()=>({content:n.some(a=>a.isConnected)?n:Je(o,t),chunksAfter:0,chunksBefore:0})),converter:s=>({text:k(s),ref:{ref:s,highlightInfo:{scrollElement:r,startOffset:0}}}),options:{autoplay:!0,sideEffects:!1},metadata:{source:"GmailInbox"}}};var _t=O(ae)`
  position: relative;
  flex-direction: row;
  align-items: center;
  overflow: hidden;
  cursor: pointer;
  justify-content: center;
  gap: 6px;
  margin-left: 8px;
  padding: 4px 6px;
  border-radius: 6px;

  &:hover {
    background-color: ${({styleThemes:e})=>e.hoverBackgroundColor};

    > button {
      ${({styleThemes:e})=>e.hoverButtonColor?`border: 1.8px solid ${e.hoverButtonColor}`:""};
      color: ${({styleThemes:e})=>e.hoverButtonColor};
    }
  }

  > button {
    background: none;
    border: 1.8px solid ${({styleThemes:e})=>e.buttonColor};
    color: ${({styleThemes:e})=>e.buttonColor};
  }

  &:active {
    background-color: ${({styleThemes:e})=>e.activeBackgroundColor};
  }
`,et={buttonColor:"#454746",iconBackground:B["bg-prim-inv-b-w"],hoverBackgroundColor:"#F2F2F2",activeBackgroundColor:"#E4E4E4"},tt={buttonColor:B["icn-txt-prim-inv"],iconBackground:"#1B1F23",hoverBackgroundColor:"rgba(71, 74, 77, 1)",activeBackgroundColor:"#556478"},ot=({messageViewElement:e,config:t})=>{let{usePlayingState:o,useCurrentContent:n}=L,r=be(document.body),[s,a]=(0,v.useState)(null),{play:E,pause:u}=_,T=o(),l=n(),f=!!l&&l?.id===s?.id,p=!!f&&T==="playing",d=!!f&&T==="buffering",S=T==="errored";(0,v.useEffect)(()=>{(async()=>{let y=await A(t,e);a(y)})()},[e,t]),(0,v.useEffect)(()=>{if(!e)return;let y=new MutationObserver(()=>w(!0)),h=new MutationObserver(()=>w(!1));y.observe(e,{attributes:!0,attributeFilter:["aria-expanded"],subtree:!0});let ie=document.querySelector(t.selectors.forwardedEmailExpandContent);if(ie)return h.observe(ie,{attributes:!0,attributeFilter:["aria-expanded"],subtree:!0}),()=>{y.disconnect(),h.disconnect()}},[e,t]);let w=async y=>{if(!e||y&&!f)return;let h=await A(t,e);a(h)},G=(0,v.useCallback)(async y=>{if(e&&(y.stopPropagation(),F()||R("browser-action",{animate:!1},"pill-player"),V("individual-post-button-hint"),!d)){if(p)return u();if(f)return E();if(!f&&s){let h=I(s,!0);a(h)}}},[d,p,f,E,u,s]);return t.playButtons&&t.playButtons.gmail&&t.playButtons.gmail.listenInInbox===!1?null:i(_t,{styleThemes:r?tt:et,onClick:G},i(Ge,{isLoading:d,isLoadingFailed:S,isPlaying:p,iconSize:"20px",onClick:G}),i(Te,{color:r?tt.buttonColor:et.buttonColor,fontSize:"14px",fontFamily:"Google Sans",letterSpacing:"0.2px",medium:!0},p?"Pause":"Listen"))};var ne="speechify-gmail-inbox-play-button-container-v2",Nt="ady",Q,nt=(0,rt.default)((e,t,o)=>{if(Pt(e))return;let n=o.getMessageViews();n&&n.forEach((r,s)=>{let a=o.getToWhomDiv(r);if(!a||a.querySelector(`.${ne}`))return;let E=document.createElement("div");E.className=ne,E.setAttribute(le,"true"),b(i(ot,{config:t,messageViewElement:r}),E),a.appendChild(E),s===n.length-1&&A(t,r).then(async u=>{let{screenshotMode:T}=await ce();T?.isDraggable||(u.options?.autoplay&&(u.options.autoplay=!1),I(u,!0))})})},32);async function it(e){st();let t=H(e);nt([],e,t),Q=new MutationObserver(o=>nt(o,e,t)),Q.observe(document,{childList:!0,subtree:!0})}async function $(){Q&&Q.disconnect(),st()}async function st(){let e=document.querySelectorAll(`.${ne}`);for(let t of e)b(()=>null,t),t.remove()}var Pt=(e,t=[])=>e.some(o=>{if(o.target instanceof HTMLElement&&At(o.target))return!0;for(let n of o.addedNodes)if(n instanceof HTMLIFrameElement&&!t.includes(n.src))return!0;for(let n of o.removedNodes)if(n instanceof HTMLIFrameElement&&!t.includes(n.src))return!0;return!1}),At=e=>e.className?.includes("speechify")||e.id?.includes("speechify")||e.className?.includes(Nt);var at=x(D());function re({config:e}){let t=L.useCurrentCursor(),[o,n]=(0,at.useState)(0);return j(()=>{let r=e.playButtons?.gmail;return(!r||r.listenInInbox!==!1)&&it(e),(!r||r.listenBeforeSending!==!1)&&Ze(e),()=>{$(),U()}},[o]),j(()=>{let r=t?.ref?.ref;r&&!r.isConnected&&n(Date.now())},[t]),null}async function wt(e){let t=De(e);await fe(t);let o=document.createElement("div");return o.id=He,document.body.append(o),b(i(re,{config:e}),o),Rt(),()=>{U(),$(),b(()=>null,o),o.remove()}}var Rt=async()=>{let e="gmail",t=await Ee("SHOULD_SHOW_PLAY_BUTTON_HINT");if(t.includes(e)===!0){V("individual-post-button-hint");return}await Pe({component:!0,duration:0,id:"individual-post-button-hint",priority:101,showOnMobile:!1,timeSensitive:!0,redesigned:!0,render:()=>i(Ne,null)}),await ye("SHOULD_SHOW_PLAY_BUTTON_HINT",[...t,e])};export{wt as default};
//# sourceMappingURL=init-XZ2W6UGD.js.map
