{"version":3,"file":"AudioPlayerButton.DtqF9Mt8.mjs","names":["useRef","useState","useCallback","__esmMin","init_ssg_sandbox_shims","te","ne","_e","de","init_jsx_runtime","p","init_npm_react_18_3_1","ce","window","motion","init_framer_BL70qLPA","addPropertyControls","ControlType","AudioPlayerButton","audioRef","buttonRef","isPlaying","setIsPlaying","ACTIVE_COLOR","TEXT_COLOR","updatePlayingState","next","dispatchPlaybackState","node","AUDIO_BUTTON_STATE_EVENT","audioSrc","audio","registryItem","allAudioButtons","handleEnded","handlePause","handlePlay","togglePlayback","currentAudio","item","error","c","PauseIcon","PlayIcon","buttonText","init_AudioPlayerButton","color"],"sources":["https:/framerusercontent.com/modules/zbOnnAjXQc14Czg6npfD/a5cw7d6VTPOYmBcaA4QG/AudioPlayerButton.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{startTransition,useCallback,useEffect,useRef,useState}from\"react\";import{motion,addPropertyControls,ControlType}from\"framer\";// --- Icons ---\n// An SVG icon for the Play button (Triangle)\nconst PlayIcon=({color=\"#0a6cff\"})=>/*#__PURE__*/_jsx(\"svg\",{width:\"1em\",height:\"1em\",viewBox:\"0 0 24 24\",fill:\"none\",xmlns:\"http://www.w3.org/2000/svg\",children:/*#__PURE__*/_jsx(\"path\",{d:\"M5 20V4L19 12L5 20Z\",fill:color})});// An SVG icon for the Pause button (Two Bars)\nconst PauseIcon=({color=\"#0a6cff\"})=>/*#__PURE__*/_jsxs(\"svg\",{width:\"1em\",height:\"1em\",viewBox:\"0 0 24 24\",fill:\"none\",xmlns:\"http://www.w3.org/2000/svg\",children:[/*#__PURE__*/_jsx(\"rect\",{x:\"6\",y:\"5\",width:\"4\",height:\"14\",fill:color}),/*#__PURE__*/_jsx(\"rect\",{x:\"14\",y:\"5\",width:\"4\",height:\"14\",fill:color})]});const AUDIO_BUTTON_STATE_EVENT=\"audio-player-button-state\";const allAudioButtons=new Set;// --- Component Definition ---\nexport function AudioPlayerButton({audioSrc,buttonText=\"Hear Demo\",width=200,height=50}){// 1. Setup Audio Element Ref\nconst audioRef=useRef(null);const buttonRef=useRef(null);// 2. Setup Playback State\nconst[isPlaying,setIsPlaying]=useState(false);const PRIMARY_COLOR=\"#fff\";const ACTIVE_COLOR=\"#fff\"// Use the same color for the active (playing) state\n;const HOVER_COLOR=\"#fff\";const TEXT_COLOR=\"#0a6cff\";const updatePlayingState=useCallback(next=>{startTransition(()=>setIsPlaying(next));},[]);const dispatchPlaybackState=useCallback(state=>{if(typeof window===\"undefined\")return;const node=buttonRef.current;if(!node)return;node.dispatchEvent(new CustomEvent(AUDIO_BUTTON_STATE_EVENT,{bubbles:true,composed:true,detail:{state,audioSrc}}));},[audioSrc]);// Create and manage the Audio object whenever the audio source changes\nuseEffect(()=>{// Stop and clean up any existing audio object\nif(audioRef.current){audioRef.current.pause();audioRef.current.currentTime=0;// Note: We don't remove the 'ended' listener here, as we're creating a new object.\n// If we were re-using the object, we'd need to clean up listeners explicitly.\n}// Only create a new audio object if we have a valid source string\nif(audioSrc){// Create a new Audio object and assign it to the ref\nconst audio=new Audio(audioSrc);audioRef.current=audio;const stop=()=>{audio.pause();try{audio.currentTime=0;}catch(_error){// no-op for streams that disallow seeking\n}};const registryItem={audio,stop};allAudioButtons.add(registryItem);// Event listener for when the audio ends naturally\nconst handleEnded=()=>{updatePlayingState(false);dispatchPlaybackState(\"ended\");};const handlePause=()=>{updatePlayingState(false);dispatchPlaybackState(\"pause\");};const handlePlay=()=>{updatePlayingState(true);dispatchPlaybackState(\"play\");};// Add the listener\naudio.addEventListener(\"ended\",handleEnded);audio.addEventListener(\"pause\",handlePause);audio.addEventListener(\"play\",handlePlay);// Cleanup function: runs when the component unmounts or before this effect runs again\nreturn()=>{allAudioButtons.delete(registryItem);if(audioRef.current===audio){audioRef.current=null;}audio.removeEventListener(\"ended\",handleEnded);audio.removeEventListener(\"pause\",handlePause);audio.removeEventListener(\"play\",handlePlay);audio.pause();try{audio.currentTime=0;}catch(_error){// no-op\n}if(buttonRef.current){dispatchPlaybackState(\"pause\");}};}else{audioRef.current=null// Ensure ref is null if no source is provided\n;updatePlayingState(false);}},[audioSrc,dispatchPlaybackState,updatePlayingState])// Depend on audioSrc\n;// 3. Playback Toggle Logic\nconst togglePlayback=useCallback(()=>{const currentAudio=audioRef.current;if(!currentAudio){console.log(\"No audio source available.\");return;// Do nothing if no audio object exists\n}if(isPlaying){// Pause the audio\ncurrentAudio.pause();return;}// Ensure global exclusivity among detached audio players.\nallAudioButtons.forEach(item=>{if(item.audio!==currentAudio){item.stop();}});// If the audio has ended, reset it to the start before playing\nif(currentAudio.ended){currentAudio.currentTime=0;}// Play returns a promise that can catch errors (e.g., if the user hasn't interacted with the page yet)\ncurrentAudio.play().catch(error=>{console.error(\"Audio playback failed (usually due to browser autoplay policy):\",error);updatePlayingState(false);dispatchPlaybackState(\"pause\");});},[dispatchPlaybackState,isPlaying,updatePlayingState]);return /*#__PURE__*/_jsxs(motion.button,{ref:buttonRef,// Framer properties for the component's outer container/button\nstyle:{width:width,height:height,display:\"flex\",alignItems:\"center\",justifyContent:\"center\",gap:\"8px\",borderRadius:\"8px\",padding:\"0 20px\",cursor:\"pointer\",// Set background based on play state\nbackground:isPlaying?ACTIVE_COLOR:PRIMARY_COLOR,border:\"none\",color:TEXT_COLOR,fontWeight:\"bold\",fontSize:\"16px\",transition:\"background 0.3s ease\"},// Framer's tap/click event\nonTap:togglePlayback,// Add interaction effects\nwhileHover:{scale:1.02,background:HOVER_COLOR},whileTap:{scale:.98,background:ACTIVE_COLOR},children:[isPlaying?/*#__PURE__*/_jsx(PauseIcon,{color:TEXT_COLOR}):/*#__PURE__*/_jsx(PlayIcon,{color:TEXT_COLOR}),/*#__PURE__*/_jsx(\"span\",{children:isPlaying?\"Hear Demo\":buttonText})]});}// --- Framer Properties Control ---\naddPropertyControls(AudioPlayerButton,{audioSrc:{type:ControlType.String,title:\"Audio URL\",placeholder:\"https://yourdomain.com/audio.mp3\",description:\"Paste the direct URL to the audio file (.mp3, .wav, etc.).\"},buttonText:{type:ControlType.String,title:\"Text (Paused)\",defaultValue:\"Hear Demo\",description:\"The text displayed when the audio is paused.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"AudioPlayerButton\":{\"type\":\"reactComponent\",\"name\":\"AudioPlayerButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AudioPlayerButton.map"],"mappings":"A,gQAIA,SAAgBkB,EAAkB,CAAC,WAAS,aAAW,YAAY,QAAM,IAAI,SAAO,IAAI,CACxF,IAAMC,EAASnB,EAAO,IAAI,EAAQoB,EAAUpB,EAAO,IAAI,EAClD,CAACqB,EAAUC,GAAcrB,EAAS,EAAK,EAAmCsB,EAAa,OAC5DC,EAAW,UAAgBC,EAAmBvB,EAAY,GAAM,CAACG,MAAoBiB,EAAaI,CAAI,CAAC,CAAE,EAAE,CAAC,CAAC,EAAQC,EAAsBzB,EAAY,GAAO,CAAC,GAAUW,IAAS,OAAY,OAAO,IAAMe,EAAKR,EAAU,QAAYQ,GAAYA,EAAK,cAAc,IAAI,YAAYC,EAAyB,CAAC,QAAQ,GAAK,SAAS,GAAK,OAAO,CAAC,QAAM,UAAQ,CAAC,CAAC,CAAC,CAAE,EAAE,CAACC,CAAQ,CAAC,EACjZlB,MAAc,CAId,GAHGO,EAAS,UAASA,EAAS,QAAQ,MAAM,EAAE,EAAS,QAAQ,YAAY,GAGxEW,EAAS,CACZ,IAAMC,EAAM,IAAI,MAAMD,CAAQ,EAAE,EAAS,QAAQC,EAC9C,IAAMC,EAAa,CAAC,QAAM,SADyC,CAACD,EAAM,MAAM,EAAE,GAAG,CAAC,EAAM,YAAY,CAAE,MAAc,CAC3H,CAAC,CAAgC,EAAEE,EAAgB,IAAID,CAAY,EACnE,IAAME,MAAgB,CAACT,EAAmB,EAAK,EAAEE,EAAsB,OAAO,CAAE,EAAQQ,MAAgB,CAACV,EAAmB,EAAK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