import{e as q,q as L,T as b,aO as R}from"./index-9bce2519-1724244886557.js";const U="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAQJJREFUWEftmD0PAUEQhmdWcw0aLjlR+fhbOtHQoFQq7xQaEZ2/RVRESBTCiUjsiER19nZOKE4y197s7jvPO7tze+j5miBFD4ogxg0hxJXrfxBSiAMNsLdloxByWpNvilEKu5rgbB0P4GqiYTTGSCijsL7u4tI2YW1MxfBGRtHKwcKmjQfb+PKIandNi/QLKvnUiap0sjBftfBoy7A6IfcS0s5oWQJClSnlrydovBHiqj7u/beWxc2LIog7qYWQEAKAJAej7DKudQghISS9jGspQkgIvQj85weaF1AzaqECyGqi4JNr0LaHM64UEhH61Q+JbV+x67EBz4xEEOerEEoToQcvexD4nAzBpwAAAABJRU5ErkJggg==",Q="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4CAYAAACohjseAAAAAXNSR0IArs4c6QAAAodJREFUaEPtmz9oFFEQxn+zhSnuzs4gQcFLxMLCTkghEivFQtDWXjClhY2YImJjYWcE+7QKgmCXIBaBlIKgmD3BEES7271Cix15m+xxSe7cP9m97D3etjc7M983376dt29OyHip6onvPa6pcgu4iDKjMAM0M7ooahYK7CDsAJ9FeHuuwZqI/M3iUNKMOqGejpQllLvAyTT7Mf3eRVj1hOV2U37+L+ZIgKo61Ql5hPJAoTGmxHOFEeghPG83eSoif4bdPBSgqZpGvFGYzxXxmIwFNsTj9rBqHgLoh3pJlXcoZ44p32JhhW2Em3NN+TToYB/Avedtc+LAJYiEbU+4PFjJPsD4mQtYnxRZjiqzkWu7xULyTPYB+oEuq/K4mD7qdZcIT2ZbsmSyigHuLSrf6rpa5qXPrK7icd5INQa4FegKyv28jmptL7yca8mimA7FD/hdo5d4Wbx1Z1uckk6o16OI92V5rZMfz+OG+IG+UGWxTomVlYsIKwbgmioLZTmtkx8R1sXv6heFC1UntvEDnn3YjfLwKsyfr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egRtKC61AoGJYeHM7WCHkELqkutYFByeDgT+8FvGv/RffyXL7Ffn0V/ARr9FbZbeaMuQnCA0ZeROMioC4EcYPSlXHmq9o04i/Hy17yoyylzyKgLYnPIqEuah3cl0Ral/731qupnBb8BLD56cQ63aRAAAAAASUVORK5CYII=",K=(y,N)=>{const m=y?"#"+y:"#musicContent",v=N?"#"+N:"#selectionCouser",r=q({showDom:!1,synth:null,selectOptions:{startIndex:0,anchorOffset:0,endIndex:0,focusOffset:0},isSpeak:!1}),C=o=>{var d;const t=document.createDocumentFragment();return(d=o.childNodes)==null||d.forEach(n=>{if(n.nodeType===Node.TEXT_NODE){const s=n.textContent.split(new RegExp("(?<=[,,;;。])\\s*"));s==null||s.forEach(i=>{if(i.trim()){const a=document.createElement("label");a.textContent=i.trim(),a.classList.add("speak-label"),t.appendChild(a)}})}else if(n.nodeType===Node.ELEMENT_NODE){const s=document.createElement(n.nodeName.toLowerCase());Array.from(n.attributes).forEach(a=>{s.setAttribute(a.name,a.value)});const i=C(n);s.appendChild(i),t.appendChild(s)}}),t},p=o=>{if(o.rangeCount>0){const t=o.anchorNode,d=o.anchorOffset,n=o.focusNode,s=o.focusOffset;if(t===n)return d{o.preventDefault();const t=window.getSelection(),d=t.rangeCount>0?t.getRangeAt(0):null;if(t.toString().length>0){r.showDom=!0;const n=document.querySelector(m),s=n==null?void 0:n.querySelectorAll("label.speak-label");let i=0,a=0,A=0,h=0;if(console.log(t,"selection"),t.focusOffset===0&&t.anchorOffset===0){const c=t.anchorNode.parentNode.parentElement,f=c.childNodes[0],l=c.childNodes[c.childNodes.length-1];s==null||s.forEach((u,g)=>{u===f&&(i=g,a=0),u===l&&(A=g,h=l.textContent.length)})}else{const e=p(t)==="up"?t.anchorNode.parentNode:t.focusNode.parentNode,c=p(t)==="down"?t.anchorNode.parentNode:t.focusNode.parentNode;p(t)==="up"?(a=t.anchorOffset,h=t.focusOffset):(a=t.focusOffset,h=t.anchorOffset),s==null||s.forEach((f,l)=>{f===e&&(i=l,a=p(t)==="up"?t.anchorOffset:t.focusOffset),f===c&&(A=l,h=p(t)==="down"?t.anchorOffset:t.focusOffset)})}r.selectOptions.startIndex=i,r.selectOptions.anchorOffset=a,r.selectOptions.endIndex=A,r.selectOptions.focusOffset=h}else r.showDom=!1;if(setTimeout(()=>{t.type!=="Range"&&(r.showDom=!1)},200),d&&!t.isCollapsed){const n=d.getClientRects();if(n.length>0){console.log(n,"rects");const s=n[n.length-1],i=s.right,a=s.top;s.bottom;const A=s.height,h=document.querySelector(m),e=h==null?void 0:h.getBoundingClientRect(),c=document.querySelector(v),f=c==null?void 0:c.getBoundingClientRect();c&&(c.style.top=(a-(e==null?void 0:e.top)+(f.height+A/2)+(h==null?void 0:h.scrollTop)).toFixed(2)+"px",(e==null?void 0:e.right)-i>=(e==null?void 0:e.width)-f.width?(c.style.right=((e==null?void 0:e.width)-f.width).toFixed(2)+"px",c.style.left="auto"):(c.style.right=((e==null?void 0:e.right)-i-6).toFixed(2)+"px",c.style.left="auto"))}}},I=()=>{E(),x({startIndex:r.selectOptions.startIndex,anchorOffset:r.selectOptions.anchorOffset})},D=()=>{E(),x(r.selectOptions)};function T(){var o;window.getSelection?(o=window.getSelection())==null||o.removeAllRanges():document.selection&&document.selection.empty(),r.showDom=!1}const E=()=>{var d;(d=r.synth)==null||d.cancel(),r.isSpeak=!1;const o=document.querySelector(m),t=o==null?void 0:o.querySelectorAll("label.speak-label");t==null||t.forEach((n,s)=>{n.classList.toggle("highlight",s===-1)}),T()},F=()=>{T();try{x({startIndex:0})}catch(o){console.log(o,"12")}},x=o=>{const t=document.querySelector(m),d=t==null?void 0:t.querySelectorAll("label.speak-label");let n=o.startIndex||0;const s=o.endIndex===void 0?d.length-1:o.endIndex,i=e=>{d==null||d.forEach((f,l)=>{f.classList.toggle("highlight",l===e)});const c=t==null?void 0:t.querySelector(".highlight");A(c)};function a(e,c){let f=0;for(;e&&e!==c;)f+=e.offsetTop,e=e.offsetParent;return f}function A(e){var O;const c=document.querySelector(m),f=c.getBoundingClientRect(),l=a(e,c),u=f.height/2;let g=0;console.log(a(e,c),"12121"),l-u>=0?g=l-u:g=0,(O=document.querySelector(m))==null||O.scrollTo({top:g,behavior:"smooth"})}const h=()=>{try{r.synth=window.speechSynthesis,r.synth.speaking&&r.synth.cancel();let e=d[n].textContent;if(e.length<=0){console.error("暂无播放内容");return}o.startIndex===o.endIndex&&o.endIndex!==void 0?e=e.substr(o.anchorOffset,(o.focusOffset||0)-(o.anchorOffset||0)):(o.startIndex===n&&(e=e.substr(o.anchorOffset,e.length)),o.endIndex===n&&(e=e.substr(0,o.focusOffset)));const c=["长笛","打击乐","乐曲","曲"],f=["尝笛","打击月","月取","取"];e&&c.forEach((u,g)=>{if(e.includes(u)){const O=new RegExp(u,"g");e=e.replace(O,f[g])}}),console.log(e,n,s,"---------");const l=new SpeechSynthesisUtterance(e);l.lang="zh-CN",l.volume=1,l.rate=.8,l.pitch=1.5,l&&(l.onstart=null,l.onend=null,l.onerror=null),l.onstart=()=>{r.isSpeak=!0,i(n)},l.onend=()=>{console.log("朗读结束"),n++,n<=s&&r.isSpeak?h():(n=0,i(-1),r.isSpeak=!1)},l.onerror=()=>{n++,n<=s&&r.isSpeak?h():r.isSpeak=!1},setTimeout(()=>{r.synth.speak(l)},80)}catch(e){console.log(e,"e")}};h()},w=()=>{document.removeEventListener("mouseup",S),document.removeEventListener("touchend",S),document.removeEventListener("touchmove",S),E()};return L(async()=>{document.addEventListener("mouseup",S),document.addEventListener("touchend",S),document.addEventListener("touchmove",()=>{console.log(11111)})}),b(()=>{w()}),{...R(r),onAllSpeak:F,onTextStart:I,onDestory:w,onCloseSpeak:E,onTextReadOnly:D,processNode:C}};export{Q as a,B as b,U as i,K as u};