1"use strict";(self.webpackChunkheaded2=self.webpackChunkheaded2||[]).push([[5887],{15887(e,t,i){i.d(t,{x:()=>k});var r,s,n,a,o,h=i(96540),l=i(38267),c=i(46784),d=i(6776),u=i(53209),p=i(86497),g=i(73830),y=i(36657);function f(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}!function(e){e.EN_US="en-US";e.ES_US="es-US";e.ES_ES="es-ES"}(r||(r={}));!function(e){e.JOANNA="Joanna";e.MATTHEW="Matthew";e.ALEX="Alex";e.SAMANTHA="Samantha";e.JORGE="Jorge";e.LUCIA="Lucia";e.LUPE="Lupe";e.PEDRO="Pedro"}(s||(s={}));!function(e){e.MALE="Male";e.FEMALE="Female"}(n||(n={}));!function(e){e.WEB_SPEECH_API="webSpeechApi";e.HTML_MEDIA_ELEMENT="htmlMediaElement"}(a||(a={}));!function(e){e.END="end";e.ERROR="error";e.READY="ready";e.LOADED="audioloaded";e.PAUSED="paused";e.PLAYING="playing"}(o||(o={}));class m extends EventTarget{constructor(e,t,i){super();f(this,"text",void 0);f(this,"target",void 0);f(this,"marks",[]);f(this,"name",s.JOANNA);f(this,"gender",n.FEMALE);f(this,"locale",r.EN_US);f(this,"synthesizer",new Audio);f(this,"provider",a.HTML_MEDIA_ELEMENT);this.text=e;this.provider=t??this.provider;this.target=this.synthesizer;this.locale=(null==i?void 0:i.locale)??this.locale;this.name=(null==i?void 0:i.name)??this.name;this.gender=(null==i?void 0:i.gender)??this.gender;if(this.provider===a.WEB_SPEECH_API){const e=window.speechSynthesis.getVoices();this.synthesizer=window.speechSynthesis;this.target=new SpeechSynthesisUtterance(this.text);if(e.length)this.initWebSpeechVoice(e,null==i?void 0:i.name);else window.speechSynthesis.addEventListener("voiceschanged",()=>{this.initWebSpeechVoice(window.speechSynthesis.getVoices(),null==i?void 0:i.name)})}}initWebSpeechVoice(e,t){const i=e.filter(e=>e.lang===this.locale),r=i.find(e=>e.name===s.SAMANTHA),n=this.target;n.voice=r??i[0]??e[0];if(t){const e=i.find(e=>e.name===t);if(e)n.voice=e}}async attachAudioSource(){let e=null;try{e=await y.F.fetch("/early/speech/read",{method:"POST",version:"v2",body:JSON.stringify({text:this.text,language:this.locale,name:this.name,gender:this.gender})})}catch{this.dispatchError()}finally{if(e&&this.synthesizer instanceof HTMLAudioElement){this.synthesizer.src=e.audio;this.marks=e.text}}}dispatchEnd(){this.dispatchEvent(new Event(o.END))}dispatchError(){this.dispatchEvent(new Event(o.ERROR))}dispatchReady(){this.dispatchEvent(new Event(o.READY))}dispatchPlaying(){this.dispatchEvent(new Event(o.PLAYING))}dispatchPaused(){this.dispatchEvent(new Event(o.PAUSED))}async playHtmlAudio(){const e=this.synthesizer;if(!e.src)await this.attachAudioSource();try{await e.play()}catch{this.dispatchError()}}getSpeechMarkForAudioTime(e){const t=this.marks.length;let i=this.marks[0],r=!1,s=1;for(;s<t&&!r;){if(this.marks[s].time<=e)i=this.marks[s];else r=!0;s++}return i}getBoundaryWordCharLength(e){const t=this.text.substring(e).match(/.+?\b/);return t?t[0].length:0}init(e){if(this.target instanceof SpeechSynthesisUtterance){this.target.pitch=1;this.target.rate=.9;this.target.volume=1;this.target.addEventListener("end",this.dispatchEnd.bind(this));this.target.addEventListener("start",this.dispatchPlaying.bind(this));this.target.addEventListener("resume",this.dispatchPlaying.bind(this));this.target.addEventListener("pause",this.dispatchPaused.bind(this));if(e)this.target.addEventListener("boundary",t=>{const{charIndex:i}=t,r=i+(t.charLength??this.getBoundaryWordCharLength(i)),s=this.text.substring(i,r);if(s)e({word:s,startChar:i,endChar:r})});this.dispatchReady()}if(this.target instanceof HTMLAudioElement){const t=()=>{this.dispatchReady();this.target.removeEventListener("canplay",t)};this.target.addEventListener("ended",this.dispatchEnd.bind(this));this.target.addEventListener("canplay",t);if(e)this.target.addEventListener("timeupdate",()=>{const t=1e3*this.target.currentTime,i=this.getSpeechMarkForAudioTime(t);if(i)e({word:i.value,startChar:i.start,endChar:i.end})})}this.target.addEventListener("error",this.dispatchError.bind(this))}play(){if(this.synthesizer instanceof HTMLAudioElement)this.playHtmlAudio();else this.synthesizer.speak(this.target)}pause(){this.synthesizer.pause()}resume(){if(this.synthesizer instanceof HTMLAudioElement)this.playHtmlAudio();else this.synthesizer.resume()}reset(){if(this.synthesizer instanceof HTMLAudioElement){this.synthesizer.load();this.playHtmlAudio()}else{this.synthesizer.cancel();this.synthesizer.speak(this.target)}}clear(){if(this.synthesizer instanceof HTMLAudioElement){this.synthesizer.pause();this.synthesizer.currentTime=0}else this.synthesizer.cancel()}}var E,b=i(74848);function v(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,r)}return i}function w(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};
1t%2?v(Object(i),!0).forEach(function(t){P(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):v(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function P(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}!function(e){e.TL="topLeft";e.TR="topRight";e.BL="bottomLeft";e.BR="bottomRight";e.TC="topCenter";e.RC="rightCenter";e.BC="bottomCenter";e.LC="leftCenter"}(E||(E={}));const A=l.Ay.div.withConfig({displayName:"textToSpeech__Wrap",componentId:"sc-qbs305-0"})(["display:grid;gap:15px;",";"],({position:e})=>{let t="'cnt ctl'",i="1fr auto",r="start";switch(e){case E.TL:t="'ctl cnt'";i="auto 1fr";break;case E.BL:t="'ctl cnt'";r="end";i="auto 1fr";break;case E.BR:t="'cnt ctl'";r="end";break;case E.TC:i="1fr";t="'ctl'\n'cnt'";r="center";break;case E.RC:r="center";break;case E.BC:i="1fr";t="'cnt'\n'ctl'";r="center";break;case E.LC:t="'ctl cnt'";i="auto 1fr";r="center"}return{alignItems:r,gridTemplateAreas:t,gridTemplateColumns:i}}),C=l.Ay.button.withConfig({displayName:"textToSpeech__Control",componentId:"sc-qbs305-1"})(["margin:0;padding:0;border:none;cursor:pointer;background:white;border-radius:15px;border-color:",";border-style:solid;display:flex;align-items:center;justify-content:center;"],g.wqj),L=l.Ay.div.withConfig({displayName:"textToSpeech__Controls",componentId:"sc-qbs305-2"})(["position:relative;grid-area:ctl;display:inline-flex;margin:",";flex-direction:",";gap:3px;padding:","px;background-color:",";color:",";","{width:","px;height:","px;padding:","px;border-width:","px;> svg{",";}}"],({position:e})=>e.includes("Center")?"auto":0,({align:e})=>"vertical"===e?"column":"row",({size:e})=>"small"===e?0:5,g.XpY,g.wqj,C,({size:e})=>"small"===e?16:30,({size:e})=>"small"===e?16:30,({size:e})=>"small"===e?0:3,({size:e})=>"small"===e?1:2,({size:e})=>"small"===e?"font-size: 0.5em; height: 11px":"height: 18px"),S=l.Ay.div.withConfig({displayName:"textToSpeech__Content",componentId:"sc-qbs305-3"})(["grid-area:cnt;"]),x=e=>e.join(" ").replace(/\s+/g," ").trim(),T=(e,t,i,r)=>h.Children.map(e,e=>{let s=e;if((0,h.isValidElement)(e))s=(0,h.cloneElement)(e,w(w({},e.props),{},{children:T(e.props.children,t,i,r)}));if("string"==typeof(n=e)||"number"==typeof n){const s=e.toString(),{word:n,startChar:a,endChar:o}=i,h=x(t),l=x([s]),c=h.length;t.push(s);if(n){const e=t.length?a-(c+1):a-c,i=o-c,s=l.substring(0,e),n=l.substring(e,i),h=l.substring(i,l.length);if(n)return(0,b.jsxs)(b.Fragment,{children:[s,(0,b.jsx)(p.M,{text:n,highlightBgColor:r.highlightBgColor,highlightFgColor:r.highlightFgColor,mark:n.replace(/[.!?,:]/,"").trim()}),h]})}}var n;return s}),j={word:"",startChar:0,endChar:0},R=(e,t)=>{switch(t.type){case"pause":return w(w({},e),{},{isPlaying:!1,isPaused:!0,isError:!1});case"play":case"reset":return w(w({},e),{},{isPlaying:!0,isPaused:!1,isError:!1,boundary:j});case"end":return w(w({},e),{},{isPlaying:!1,isPaused:!1,isError:!1,boundary:j});case"error":return w(w({},e),{},{isPlaying:!1,isPaused:!1,isError:!0,boundary:j});case"ready":return w(w({},e),{},{isReady:!0});case"boundary":return w(w({},e),{},{boundary:w(w({},e.boundary),t.payload)});default:throw new Error(`TextToSpeech: invalid action type ${t.type}`)}},k=({name:e,gender:t,locale:i,children:s,onToggleAutoPlay:n,native:l=!1,autoPlay:p=!1,size:g="medium",align:y="vertical",position:f=E.TR,highlightBgColor:v,highlightFgColor:w,markTextAsSpoken:P=!1})=>{const k=(0,h.useRef)(null),[z,M]=(0,h.useReducer)(R,{boundary:j,isPlaying:!1,isPaused:!1,isError:!1,isReady:!1}),[O,_]=(0,h.useMemo)(()=>{const e=[],t={};if(v)t.highlightBgColor=v;if(w)t.highlightFgColor=w;return[T(s,e,z.boundary,t),x(e)]},[s,v,w,z.boundary]),N=(0,h.useMemo)(()=>{const s={locale:r.EN_US};if(e)s.name=e;if(i)s.locale=i;if(t)s.gender=t;return new m(_,l?a.WEB_SPEECH_API:a.HTML_MEDIA_ELEMENT,s)},[_,t,i,l,e]),D=(0,h.useMemo)(()=>"small"===g?"xs":"sm",[g]),H=(0,h.useCallback)(()=>
1{if(z.isPaused)N.resume();else N.play();M({type:"play"})},[N,z.isPaused]),B=(0,h.useCallback)(()=>{N.pause();M({type:"pause"})},[N]),I=(0,h.useCallback)(()=>{N.reset();M({type:"reset"})},[N]),U=(0,h.useCallback)(()=>{if(z.isPlaying){N.clear();M({type:"end"})}if("function"==typeof n)n(p)},[n,p,z.isPlaying,N]),F=(0,h.useMemo)(()=>z.isPlaying?B:H,[z.isPlaying,B,H]);(0,h.useEffect)(()=>{const e=()=>{N.clear()},t=()=>{M({type:"end"})},i=()=>{M({type:"ready"});if(p){N.play();M({type:"play"})}},r=()=>{M({type:"error"})};N.addEventListener(o.END,t);N.addEventListener(o.ERROR,r);N.addEventListener(o.READY,i);window.addEventListener("beforeunload",e);N.init(!P?void 0:e=>{if(k.current)M({type:"boundary",payload:e})});return()=>{N.clear();N.removeEventListener(o.END,t);N.removeEventListener(o.ERROR,r);N.removeEventListener(o.READY,i);window.removeEventListener("beforeunload",e)}},[N,p,P]);return(0,b.jsxs)(A,{ref:k,position:f,children:[(0,b.jsxs)(L,{align:y,size:g,position:f,children:[(0,b.jsx)(C,{onClick:U,title:u.t`Toggle audio`,children:z.isPlaying?(0,b.jsx)(c.g,{size:D,icon:d.jY_}):(0,b.jsx)(c.g,{size:D,icon:d.tJ_})}),(0,b.jsx)(C,{onClick:F,title:z.isPlaying?u.t`Pause`:u.t`Play`,children:z.isPlaying?(0,b.jsx)(c.g,{size:D,icon:d.G1Y}):(0,b.jsx)(c.g,{size:D,icon:d.ijD})}),z.isPaused&&(0,b.jsx)(C,{onClick:I,title:u.t`Restart`,children:(0,b.jsx)(c.g,{size:D,icon:d.U23})})]}),(0,b.jsx)(S,{children:O})]})}}}]); 2//# sourceMappingURL=5887.09d8d1b2.chunk.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.