import"./_virtual_wxt-html-plugins-Dc9xbmo1.js";import{o as c}from"./_virtual_wxt-plugins-ClZn3qS1.js";let o=null;function h(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function y(e){e.audio.onended=null,e.audio.onerror=null,e.audio.pause(),e.audio.removeAttribute("src"),e.audio.load(),URL.revokeObjectURL(e.audioUrl)}function U(e,t){return e.settled?!1:(e.settled=!0,y(e),o===e&&(o=null),e.resolve(t),!0)}function f(e,t){return e.settled?!1:(e.settled=!0,y(e),o===e&&(o=null),e.reject(t),!0)}function w(e,t){const n=o;return!n||t&&n.requestId!==t?!1:U(n,{ok:!1,reason:e})}c("ttsOffscreenPlay",async e=>{w("interrupted");const{requestId:t,audioBase64:n,contentType:r}=e.data;return new Promise((A,b)=>{const a=h(n),d=new ArrayBuffer(a.byteLength);new Uint8Array(d).set(a);const P=new Blob([d],{type:r}),l=URL.createObjectURL(P),u=new Audio(l),s={requestId:t,audio:u,audioUrl:l,settled:!1,resolve:A,reject:b};o=s,u.onended=()=>{U(s,{ok:!0})},u.onerror=()=>{f(s,new Error("Failed to play audio in offscreen document"))},u.play().catch(i=>{const m=i instanceof Error?i:new Error(typeof i=="string"?i:"Unknown audio playback error");f(s,m)})})});c("ttsOffscreenStop",async e=>(w(e.data.reason??"stopped",e.data.requestId),{ok:!0}));
