import"./_virtual_wxt-html-plugins-DPbbfBKe.js";let s=null;function c(e,r){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:r})}function a(e){e.audio.onended=null,e.audio.onerror=null,e.audio.pause(),e.audio.removeAttribute("src"),e.audio.load(),URL.revokeObjectURL(e.url)}function l(e,r){e.settled||(e.settled=!0,a(e),s===e&&(s=null),e.resolve(r))}function d(e,r){const t=s;return!t||r&&t.requestId!==r?!1:(l(t,{ok:!1,reason:e}),!0)}chrome.runtime.onMessage.addListener((e,r,t)=>{if(!e||typeof e!="object")return!1;if(e.type==="tts-offscreen-play"){d("interrupted");const n=c(e.audioBase64,e.contentType),o=URL.createObjectURL(n),u=new Audio(o),i={requestId:e.requestId,audio:u,url:o,settled:!1,resolve:f=>t(f)};return s=i,u.onended=()=>l(i,{ok:!0,reason:"ended"}),u.onerror=()=>l(i,{ok:!1,reason:"error"}),u.play().catch(()=>l(i,{ok:!1,reason:"error"})),!0}return e.type==="tts-offscreen-stop"&&(d("stopped",e.requestId),t({ok:!0})),!1});
