1 |
- import{e as D,q as F,ap as R,b4 as k}from"./index-756d83ce-1742434094105.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=(y,N)=>{const m=y?"#"+y:"#musicContent",L=N?"#"+N:"#selectionCouser",l=D({showDom:!1,synth:null,selectOptions:{startIndex:0,anchorOffset:0,endIndex:0,focusOffset:0},isSpeak:!1}),w=e=>{var n;const r=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 h=document.createElement("label");h.textContent=d.trim(),h.classList.add("speak-label"),r.appendChild(h)}})}else if(o.nodeType===Node.ELEMENT_NODE){const c=document.createElement(o.nodeName.toLowerCase());Array.from(o.attributes).forEach(h=>{c.setAttribute(h.name,h.value)});const d=w(o);c.appendChild(d),r.appendChild(c)}}),r},S=e=>{if(e.rangeCount>0){const r=e.anchorNode,n=e.anchorOffset,o=e.focusNode,c=e.focusOffset;if(r===o)return n<c?"up":"down";{const d=e.getRangeAt(0),h=d.startContainer,u=d.endContainer;return h===r&&u===o?"up":"down"}}else return"up"},p=()=>{const e=window.getSelection(),r=e.rangeCount>0?e.getRangeAt(0):null;if(e.toString().length>0){l.showDom=!0;const n=document.querySelector(m),o=n==null?void 0:n.querySelectorAll("label.speak-label");let c=0,d=0,h=0,u=0;if(console.log(e,"selection"),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((g,s)=>{g===t&&(c=s,d=0),g===i&&(h=s,u=i.textContent.length)})}else{const a=S(e)==="up"?e.anchorNode.parentNode:e.focusNode.parentNode,f=S(e)==="down"?e.anchorNode.parentNode:e.focusNode.parentNode;S(e)==="up"?(d=e.anchorOffset,u=e.focusOffset):(d=e.focusOffset,u=e.anchorOffset),o==null||o.forEach((t,i)=>{t===a&&(c=i,d=S(e)==="up"?e.anchorOffset:e.focusOffset),t===f&&(h=i,u=S(e)==="down"?e.anchorOffset:e.focusOffset)})}l.selectOptions.startIndex=c,l.selectOptions.anchorOffset=d,l.selectOptions.endIndex=h,l.selectOptions.focusOffset=u}else l.showDom=!1;if(setTimeout(()=>{e.type!=="Range"&&(l.showDom=!1)},200),r&&!e.isCollapsed){const n=r.getClientRects();if(n.length>0){const o=n[n.length-1],c=o.right,d=o.top,h=o.height,u=document.querySelector(m),a=u==null?void 0:u.getBoundingClientRect(),f=document.querySelector(L),t=f==null?void 0:f.getBoundingClientRect();f&&(f.style.top=(d-(a==null?void 0:a.top)+(t.height+h/2)+(u==null?void 0:u.scrollTop)).toFixed(2)+"px",(a==null?void 0:a.right)-c>=(a==null?void 0:a.width)-t.width?(f.style.right=((a==null?void 0:a.width)-t.width).toFixed(2)+"px",f.style.left="auto"):(f.style.right=((a==null?void 0:a.right)-c-6).toFixed(2)+"px",f.style.left="auto"))}}},q=()=>{x(),O({startIndex:l.selectOptions.startIndex,anchorOffset:l.selectOptions.anchorOffset})},v=()=>{x(),O(l.selectOptions)};function T(){var e;window.getSelection?(e=window.getSelection())==null||e.removeAllRanges():document.selection&&document.selection.empty(),l.showDom=!1}function b(){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 x=()=>{var n;(n=l.synth)==null||n.cancel(),l.isSpeak=!1;const e=document.querySelector(m),r=e==null?void 0:e.querySelectorAll("label.speak-label");r==null||r.forEach((o,c)=>{o.classList.toggle("highlight",c===-1)}),b(),T()},B=()=>{T();try{O({startIndex:0})}catch(e){console.log(e,"12")}},O=e=>{const r=document.querySelector(m),n=r==null?void 0:r.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((g,s)=>{g.classList.toggle("highlight",s===t)});const i=r==null?void 0:r.querySelector(".highlight");u(i)};function h(t,i){let g=0;for(;t&&t!==i;)g+=t.offsetTop,t=t.offsetParent;return g}function u(t){var C;const i=document.querySelector(m),g=i.getBoundingClientRect(),s=h(t,i),A=g.height/2;let E=0;s-A>=0?E=s-A:E=0,(C=document.querySelector(m))==null||C.scrollTo({top:E,behavior:"smooth"})}(()=>{n==null||n.forEach((t,i)=>{if(i>=o&&i<=c){const g=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)||g.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,g.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)||g.length);const A=document.createElement("label");A.classList.add("showBgColor"),s.surroundContents(A)}else t.classList.add("showBgColor")}})})();const f=()=>{try{l.synth=window.speechSynthesis,l.synth.speaking&&l.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=["长笛","打击乐","乐曲","曲"],g=["尝笛","打击月","月取","取"];t&&i.forEach((A,E)=>{if(t.includes(A)){const C=new RegExp(A,"g");t=t.replace(C,g[E])}});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=()=>{l.isSpeak=!0,d(o)},s.onend=()=>{console.log("朗读结束"),o++,o<=c&&l.isSpeak?f():(o=0,d(-1),b(),l.isSpeak=!1)},s.onerror=()=>{o++,o<=c&&l.isSpeak?f():l.isSpeak=!1},setTimeout(()=>{l.synth.speak(s)},80)}catch(t){console.log(t,"e")}};f()},I=()=>{document.removeEventListener("mouseup",p),document.removeEventListener("touchend",p),x()};return F(async()=>{document.addEventListener("mouseup",p),document.addEventListener("touchend",p)}),R(()=>{I()}),{...k(l),onAllSpeak:B,onTextStart:q,onDestory:I,onCloseSpeak:x,onTextReadOnly:v,processNode:w}};export{K as a,Y as b,Q as i,J as u};
|