useSpeak-legacy-04e21ea5-1731319840132.js 7.2 KB

1
  1. System.register(["./index-legacy-bb6bf184-1731319840132.js"],(function(e,t){"use strict";var o,n,s,c;return{setters:[e=>{o=e.e,n=e.q,s=e.T,c=e.aR}],execute:function(){e("i","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAQJJREFUWEftmD0PAUEQhmdWcw0aLjlR+fhbOtHQoFQq7xQaEZ2/RVRESBTCiUjsiER19nZOKE4y197s7jvPO7tze+j5miBFD4ogxg0hxJXrfxBSiAMNsLdloxByWpNvilEKu5rgbB0P4GqiYTTGSCijsL7u4tI2YW1MxfBGRtHKwcKmjQfb+PKIandNi/QLKvnUiap0sjBftfBoy7A6IfcS0s5oWQJClSnlrydovBHiqj7u/beWxc2LIog7qYWQEAKAJAej7DKudQghISS9jGspQkgIvQj85weaF1AzaqECyGqi4JNr0LaHM64UEhH61Q+JbV+x67EBz4xEEOerEEoToQcvexD4nAzBpwAAAABJRU5ErkJggg=="),e("a","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4CAYAAACohjseAAAAAXNSR0IArs4c6QAAAodJREFUaEPtmz9oFFEQxn+zhSnuzs4gQcFLxMLCTkghEivFQtDWXjClhY2YImJjYWcE+7QKgmCXIBaBlIKgmD3BEES7271Cix15m+xxSe7cP9m97D3etjc7M983376dt29OyHip6onvPa6pcgu4iDKjMAM0M7ooahYK7CDsAJ9FeHuuwZqI/M3iUNKMOqGejpQllLvAyTT7Mf3eRVj1hOV2U37+L+ZIgKo61Ql5hPJAoTGmxHOFEeghPG83eSoif4bdPBSgqZpGvFGYzxXxmIwFNsTj9rBqHgLoh3pJlXcoZ44p32JhhW2Em3NN+TToYB/Avedtc+LAJYiEbU+4PFjJPsD4mQtYnxRZjiqzkWu7xULyTPYB+oEuq/K4mD7qdZcIT2ZbsmSyigHuLSrf6rpa5qXPrK7icd5INQa4FegKyv28jmptL7yca8mimA7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aIVl7CegxUXkFrBWsHAI+Cdoltf4clb+L53tC9Cpxri/hVYPOsXSW/A2+tHD5cjOcgX7lzd46kBxwUt+hT1yJaZdPFO0Zl46zFoDegRtKC61AoGJYeHM7WCHkELqkutYFByeDgT+8FvGv/RffyXL7Ffn0V/ARr9FbZbeaMuQnCA0ZeROMioC4EcYPSlXHmq9o04i/Hy17yoyylzyKgLYnPIqEuah3cl0Ral/731qupnBb8BLD56cQ63aRAAAAAASUVORK5CYII="),e("u",((e,t)=>{const r=e?"#"+e:"#musicContent",l=t?"#"+t:"#selectionCouser",a=o({showDom:!1,synth:null,selectOptions:{startIndex:0,anchorOffset:0,endIndex:0,focusOffset:0},isSpeak:!1}),i=e=>{const t=document.createDocumentFragment();return e.childNodes?.forEach((e=>{if(e.nodeType===Node.TEXT_NODE){const o=e.textContent.split(/(?<=[,,;;。])\s*/);o?.forEach((e=>{if(e.trim()){const o=document.createElement("label");o.textContent=e.trim(),o.classList.add("speak-label"),t.appendChild(o)}}))}else if(e.nodeType===Node.ELEMENT_NODE){const o=document.createElement(e.nodeName.toLowerCase());Array.from(e.attributes).forEach((e=>{o.setAttribute(e.name,e.value)}));const n=i(e);o.appendChild(n),t.appendChild(o)}})),t},A=e=>{if(e.rangeCount>0){const t=e.anchorNode,o=e.anchorOffset,n=e.focusNode,s=e.focusOffset;if(t===n)return o<s?"up":"down";{const o=e.getRangeAt(0),s=o.startContainer,c=o.endContainer;return s===t&&c===n?"up":"down"}}return"up"},d=()=>{const e=window.getSelection(),t=e.rangeCount>0?e.getRangeAt(0):null;if(e.toString().length>0){a.showDom=!0;const t=document.querySelector(r),o=t?.querySelectorAll("label.speak-label");let n=0,s=0,c=0,l=0;if(0===e.focusOffset&&0===e.anchorOffset){const t=e.anchorNode.parentNode.parentElement,r=t.childNodes[0],a=t.childNodes[t.childNodes.length-1];o?.forEach(((e,t)=>{e===r&&(n=t,s=0),e===a&&(c=t,l=a.textContent.length)}))}else{const t="up"===A(e)?e.anchorNode.parentNode:e.focusNode.parentNode,r="down"===A(e)?e.anchorNode.parentNode:e.focusNode.parentNode;"up"===A(e)?(s=e.anchorOffset,l=e.focusOffset):(s=e.focusOffset,l=e.anchorOffset),o?.forEach(((o,a)=>{o===t&&(n=a,s="up"===A(e)?e.anchorOffset:e.focusOffset),o===r&&(c=a,l="down"===A(e)?e.anchorOffset:e.focusOffset)}))}a.selectOptions.startIndex=n,a.selectOptions.anchorOffset=s,a.selectOptions.endIndex=c,a.selectOptions.focusOffset=l}else a.showDom=!1;if(setTimeout((()=>{"Range"!==e.type&&(a.showDom=!1)}),200),t&&!e.isCollapsed){const e=t.getClientRects();if(e.length>0){const t=e[e.length-1],o=t.right,n=t.top;t.bottom;const s=t.height,c=document.querySelector(r),a=c?.getBoundingClientRect(),i=document.querySelector(l),A=i?.getBoundingClientRect();i&&(i.style.top=(n-a?.top+(A.height+s/2)+c?.scrollTop).toFixed(2)+"px",a?.right-o>=a?.width-A.width?(i.style.right=(a?.width-A.width).toFixed(2)+"px",i.style.left="auto"):(i.style.right=(a?.right-o-6).toFixed(2)+"px",i.style.left="auto"))}}};function h(){window.getSelection?window.getSelection()?.removeAllRanges():document.selection&&document.selection.empty(),a.showDom=!1}const f=()=>{a.synth?.cancel(),a.isSpeak=!1;const e=document.querySelector(r),t=e?.querySelectorAll("label.speak-label");t?.forEach(((e,t)=>{e.classList.toggle("highlight",-1===t)})),h()},u=e=>{const t=document.querySelector(r),o=t?.querySelectorAll("label.speak-label");let n=e.startIndex||0;const s=void 0===e.endIndex?o.length-1:e.endIndex,c=e=>{o?.forEach(((t,o)=>{t.classList.toggle("highlight",o===e)}));const n=t?.querySelector(".highlight");!function(e){const t=document.querySelector(r),o=t.getBoundingClientRect(),n=l(e,t),s=o.height/2;let c=0;console.log(l(e,t),"12121"),c=n-s>=0?n-s:0,document.querySelector(r)?.scrollTo({top:c,behavior:"smooth"})}(n)};function l(e,t){let o=0;for(;e&&e!==t;)o+=e.offsetTop,e=e.offsetParent;return o}const i=()=>{try{a.synth=window.speechSynthesis,a.synth.speaking&&a.synth.cancel();let t=o[n].textContent;if(t.length<=0)return void console.error("暂无播放内容");e.startIndex===e.endIndex&&void 0!==e.endIndex?t=t.substr(e.anchorOffset,(e.focusOffset||0)-(e.anchorOffset||0)):(e.startIndex===n&&(t=t.substr(e.anchorOffset,t.length)),e.endIndex===n&&(t=t.substr(0,e.focusOffset)));const r=["尝笛","打击月","月取","取"];t&&["长笛","打击乐","乐曲","曲"].forEach(((e,o)=>{if(t.includes(e)){const n=new RegExp(e,"g");t=t.replace(n,r[o])}})),console.log(t,n,s,"---------");const l=new SpeechSynthesisUtterance(t);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=()=>{a.isSpeak=!0,c(n)},l.onend=()=>{console.log("朗读结束"),n++,n<=s&&a.isSpeak?i():(n=0,c(-1),a.isSpeak=!1)},l.onerror=()=>{n++,n<=s&&a.isSpeak?i():a.isSpeak=!1},setTimeout((()=>{a.synth.speak(l)}),80)}catch(t){console.log(t,"e")}};i()},g=()=>{document.removeEventListener("mouseup",d),document.removeEventListener("touchend",d),f()};return n((async()=>{document.addEventListener("mouseup",d),document.addEventListener("touchend",d)})),s((()=>{g()})),{...c(a),onAllSpeak:()=>{h();try{u({startIndex:0})}catch(e){console.log(e,"12")}},onTextStart:()=>{f(),u({startIndex:a.selectOptions.startIndex,anchorOffset:a.selectOptions.anchorOffset})},onDestory:g,onCloseSpeak:f,onTextReadOnly:()=>{f(),u(a.selectOptions)},processNode:i}}))}}}));