{"version":3,"file":"AudioPlayerButton.DcsS1yz5.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/CjSjTQKzvOFxqTirmWUx/VWusZtsNpL1bOWUCn0aV/AudioPlayerButton.js"],"sourcesContent":["// Circular button with play/pause icons that reads array contents through TTS\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useRef,useEffect,startTransition}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";// Global reference to track currently playing instance\nconst globalAudioState={currentUtterance:null,currentSetIsPlaying:null};/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function AudioPlayerButton(props){const{textArray=[\"Hello\",\"Welcome to Framer\",\"This is a text to speech component\"],buttonColor=\"#353535\",iconColor=\"#FFFFFF\",size=30,rate=1,pitch=1,voice=\"default\"}=props;const[isPlaying,setIsPlaying]=useState(false);const utteranceRef=useRef(null);// Cleanup effect to stop audio when component unmounts\nuseEffect(()=>{return()=>{if(typeof window!==\"undefined\"&&utteranceRef.current){window.speechSynthesis.cancel();// Clear global state if this instance was playing\nif(globalAudioState.currentUtterance===utteranceRef.current){globalAudioState.currentUtterance=null;globalAudioState.currentSetIsPlaying=null;}}};},[]);const handleClick=()=>{if(typeof window===\"undefined\")return;// Only allow audio playback during runtime\nif(RenderTarget.current()!==RenderTarget.preview)return;if(isPlaying){window.speechSynthesis.cancel();startTransition(()=>setIsPlaying(false));// Only clear global state if this instance is the current one\nif(globalAudioState.currentUtterance===utteranceRef.current){globalAudioState.currentUtterance=null;globalAudioState.currentSetIsPlaying=null;}}else{// Stop any currently playing audio from other instances\nif(globalAudioState.currentUtterance){window.speechSynthesis.cancel();if(globalAudioState.currentSetIsPlaying){startTransition(()=>{if(globalAudioState.currentSetIsPlaying){globalAudioState.currentSetIsPlaying(false);}});}// Clear global state\nglobalAudioState.currentUtterance=null;globalAudioState.currentSetIsPlaying=null;}const textToSpeak=textArray.join(\". \");const utterance=new SpeechSynthesisUtterance(textToSpeak);// Set voice properties\nutterance.rate=rate;utterance.pitch=pitch;// Set voice if not default\nif(voice!==\"default\"&&typeof window!==\"undefined\"){const voices=window.speechSynthesis.getVoices();const selectedVoice=voices.find(v=>v.name===voice);if(selectedVoice){utterance.voice=selectedVoice;}}utterance.onend=()=>{// Only update state if this utterance is still the current one\nif(globalAudioState.currentUtterance===utterance){startTransition(()=>setIsPlaying(false));globalAudioState.currentUtterance=null;globalAudioState.currentSetIsPlaying=null;}};utterance.onerror=()=>{// Only update state if this utterance is still the current one\nif(globalAudioState.currentUtterance===utterance){startTransition(()=>setIsPlaying(false));globalAudioState.currentUtterance=null;globalAudioState.currentSetIsPlaying=null;}};utteranceRef.current=utterance;globalAudioState.currentUtterance=utterance;globalAudioState.currentSetIsPlaying=setIsPlaying;window.speechSynthesis.speak(utterance);startTransition(()=>setIsPlaying(true));}};return /*#__PURE__*/_jsx(\"button\",{onClick:handleClick,style:{width:size,height:size,borderRadius:\"50%\",backgroundColor:buttonColor,border:\"none\",cursor:\"pointer\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",padding:0,transition:\"transform 0.2s ease\"},onMouseDown:e=>{e.currentTarget.style.transform=\"scale(0.95)\";},onMouseUp:e=>{e.currentTarget.style.transform=\"scale(1)\";},onMouseLeave:e=>{e.currentTarget.style.transform=\"scale(1)\";},\"aria-label\":isPlaying?\"Pause\":\"Play\",children:isPlaying?/*#__PURE__*/_jsxs(\"svg\",{width:size*.4,height:size*.4,viewBox:\"0 0 24 24\",fill:iconColor,children:[/*#__PURE__*/_jsx(\"rect\",{x:\"6\",y:\"4\",width:\"4\",height:\"16\",rx:\"1\"}),/*#__PURE__*/_jsx(\"rect\",{x:\"14\",y:\"4\",width:\"4\",height:\"16\",rx:\"1\"})]}):/*#__PURE__*/_jsx(\"svg\",{width:size*.4,height:size*.4,viewBox:\"0 0 24 24\",fill:iconColor,style:{marginLeft:size*.05},children:/*#__PURE__*/_jsx(\"path\",{d:\"M8 5v14l11-7z\"})})});}addPropertyControls(AudioPlayerButton,{textArray:{type:ControlType.Array,control:{type:ControlType.String,defaultValue:\"Enter text here\"},defaultValue:[\"Hello\",\"Welcome to Framer\",\"This is a text to speech component\"],maxCount:20},voice:{type:ControlType.Enum,title:\"Voice\",defaultValue:\"default\",options:[\"default\",\"Google US English\",\"Google UK English Female\",\"Google UK English Male\",\"Microsoft David - English (United States)\",\"Microsoft Zira - English (United States)\",\"Microsoft Mark - English (United States)\",\"Samantha\",\"Alex\",\"Karen\",\"Daniel\",\"Moira\",\"Tessa\"],optionTitles:[\"Default\",\"Google US English\",\"Google UK English Female\",\"Google UK English Male\",\"Microsoft David (US)\",\"Microsoft Zira (US)\",\"Microsoft Mark (US)\",\"Samantha (macOS)\",\"Alex (macOS)\",\"Karen (macOS)\",\"Daniel (macOS)\",\"Moira (macOS)\",\"Tessa (macOS)\"]},rate:{type:ControlType.Number,title:\"Rate\",defaultValue:1,min:.1,max:10,step:.1},pitch:{type:ControlType.Number,title:\"Pitch\",defaultValue:1,min:0,max:2,step:.1},buttonColor:{type:ControlType.Color,title:\"Button Color\",defaultValue:\"#353535\"},iconColor:{type:ControlType.Color,title:\"Icon Color\",defaultValue:\"#FFFFFF\"},size:{type:ControlType.Number,title:\"Size\",defaultValue:30,min:20,max:120,step:1,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AudioPlayerButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AudioPlayerButton.map"],"mappings":"2NAKG,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,YAAU,CAAC,QAAQ,oBAAoB,qCAAqC,CAAC,cAAY,UAAU,YAAU,UAAU,OAAK,GAAG,OAAK,EAAE,QAAM,EAAE,QAAM,WAAW,EAAW,CAAC,E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