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