{"version":3,"file":"SoundToggle.CMNPoFWd.mjs","names":["useState","useRef","startTransition"],"sources":["https:/framerusercontent.com/modules/DWjsDdkn6RAFIHUqGQqm/TnUEi2y3pzRwZvKTXDkY/SoundToggle.js"],"sourcesContent":["// Sound button with customizable icons, text, and audio controls that auto-plays on all browsers\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useRef,useEffect,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * Sound Button with customizable icons, text, and audio controls\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function SoundToggle(props){const{soundOnIcon={src:\"https://framerusercontent.com/images/GfGkADagM4KEibNcIiRUWlfrR0.jpg\",alt:\"Sound On\"},soundOffIcon={src:\"https://framerusercontent.com/images/aNsAT3jCvt4zglbWCUoFe33Q.jpg\",alt:\"Sound Off\"},audioFile=\"https://framerusercontent.com/assets/8w3IUatLX9a5JVJ6XPCVuHi94.mp3\",autoPlay=true,loop=true,volume=.5,showControls=false,iconSize=42,backgroundColor=\"#F5F5F5\",borderRadius=8,padding=16,showText=false,textOn=\"Sound On\",textOff=\"Sound Off\",textFont,textColor=\"#000000\",textAlignment=\"bottom\"}=props;const[isPlaying,setIsPlaying]=useState(autoPlay);const[isLoaded,setIsLoaded]=useState(false);const audioRef=useRef(null);const isStatic=useIsStaticRenderer();useEffect(()=>{if(isStatic||typeof window===\"undefined\")return;const audio=audioRef.current;if(!audio)return;const handleCanPlay=()=>{startTransition(()=>setIsLoaded(true));if(autoPlay){// Create a user interaction promise for better browser compatibility\nconst playAudio=async()=>{try{await audio.play();}catch(error){// Auto-play was prevented, wait for user interaction\nstartTransition(()=>setIsPlaying(false));}};playAudio();}};const handlePlay=()=>startTransition(()=>setIsPlaying(true));const handlePause=()=>startTransition(()=>setIsPlaying(false));const handleEnded=()=>{if(!loop){startTransition(()=>setIsPlaying(false));}};audio.addEventListener(\"canplay\",handleCanPlay);audio.addEventListener(\"play\",handlePlay);audio.addEventListener(\"pause\",handlePause);audio.addEventListener(\"ended\",handleEnded);// Set volume\naudio.volume=Math.max(0,Math.min(1,volume));return()=>{audio.removeEventListener(\"canplay\",handleCanPlay);audio.removeEventListener(\"play\",handlePlay);audio.removeEventListener(\"pause\",handlePause);audio.removeEventListener(\"ended\",handleEnded);};},[autoPlay,loop,volume,isStatic]);const toggleSound=async()=>{if(isStatic||!audioRef.current)return;const audio=audioRef.current;if(isPlaying){audio.pause();}else{try{await audio.play();}catch(error){console.warn(\"Audio play failed:\",error);// Try to enable audio context for Safari/iOS\nif(typeof window!==\"undefined\"&&window.AudioContext){const audioContext=new(window.AudioContext||window.webkitAudioContext);if(audioContext.state===\"suspended\"){await audioContext.resume();try{await audio.play();}catch(retryError){console.warn(\"Audio play retry failed:\",retryError);}}}}}};const currentIcon=isPlaying?soundOnIcon:soundOffIcon;const getFlexDirection=()=>{switch(textAlignment){case\"left\":return\"row-reverse\";case\"right\":return\"row\";case\"top\":return\"column-reverse\";case\"bottom\":return\"column\";default:return\"column\";}};const containerStyle={display:\"flex\",alignItems:\"center\",justifyContent:\"center\",flexDirection:showText?getFlexDirection():\"row\",gap:showText?\"8px\":\"0\",width:showText?\"auto\":`${iconSize}px`,height:showText?\"auto\":`${iconSize}px`,padding:`${padding}px`,backgroundColor,borderRadius:`${borderRadius}px`,cursor:isStatic?\"default\":\"pointer\",userSelect:\"none\",transition:\"all 0.2s ease\",...props.style};const iconStyle={width:`${iconSize}px`,height:`${iconSize}px`,objectFit:\"contain\",transition:\"transform 0.2s ease\"};return /*#__PURE__*/_jsxs(\"div\",{style:containerStyle,onClick:toggleSound,onMouseEnter:e=>{if(!isStatic){e.currentTarget.style.transform=\"scale(1.05)\";}},onMouseLeave:e=>{if(!isStatic){e.currentTarget.style.transform=\"scale(1)\";}},role:\"button\",tabIndex:0,\"aria-label\":`Sound ${isPlaying?\"on\":\"off\"} - Click to ${isPlaying?\"pause\":\"play\"}`,onKeyDown:e=>{if(e.key===\"Enter\"||e.key===\" \"){e.preventDefault();toggleSound();}},children:[/*#__PURE__*/_jsx(\"img\",{src:currentIcon.src,alt:currentIcon.alt,style:iconStyle}),showText&&/*#__PURE__*/_jsx(\"span\",{style:{...textFont,color:textColor,fontSize:textFont?.fontSize||\"14px\",fontWeight:textFont?.fontWeight||\"normal\",textAlign:\"center\",userSelect:\"none\"},children:isPlaying?textOn:textOff}),!isStatic&&/*#__PURE__*/_jsx(\"audio\",{ref:audioRef,src:audioFile,loop:loop,preload:\"auto\",controls:showControls,style:{display:showControls?\"block\":\"none\",position:showControls?\"absolute\":\"static\",top:showControls?\"100%\":\"auto\",left:showControls?\"0\":\"auto\",width:showControls?\"100%\":\"0\",height:showControls?\"auto\":\"0\"}})]});}addPropertyControls(SoundToggle,{soundOnIcon:{type:ControlType.ResponsiveImage,title:\"Sound On Icon\"},soundOffIcon:{type:ControlType.ResponsiveImage,title:\"Sound Off Icon\"},audioFile:{type:ControlType.File,title:\"Audio File\",allowedFileTypes:[\"mp3\",\"wav\",\"ogg\",\"m4a\"]},autoPlay:{type:ControlType.Boolean,title:\"Auto Play\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},volume:{type:ControlType.Number,title:\"Volume\",defaultValue:.5,min:0,max:1,step:.1},showControls:{type:ControlType.Boolean,title:\"Show Audio Controls\",defaultValue:false,enabledTitle:\"Show\",disabledTitle:\"Hide\"},iconSize:{type:ControlType.Number,title:\"Icon Size\",defaultValue:42,min:12,max:64,step:1,unit:\"px\"},backgroundColor:{type:ControlType.Color,title:\"Background Color\",defaultValue:\"#F5F5F5\"},borderRadius:{type:ControlType.Number,title:\"Border Radius\",defaultValue:8,min:0,max:32,step:1,unit:\"px\"},padding:{type:ControlType.Number,title:\"Padding\",defaultValue:16,min:0,max:32,step:1,unit:\"px\"},showText:{type:ControlType.Boolean,title:\"Show Text\",defaultValue:false,enabledTitle:\"Show\",disabledTitle:\"Hide\"},textOn:{type:ControlType.String,title:\"Text On\",defaultValue:\"Sound On\",hidden:({showText})=>!showText},textOff:{type:ControlType.String,title:\"Text Off\",defaultValue:\"Sound Off\",hidden:({showText})=>!showText},textFont:{type:ControlType.Font,title:\"Text Font\",defaultValue:{fontSize:\"14px\",variant:\"Medium\",letterSpacing:\"-0.01em\",lineHeight:\"1em\"},controls:\"extended\",defaultFontType:\"sans-serif\",hidden:({showText})=>!showText},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\",hidden:({showText})=>!showText},textAlignment:{type:ControlType.Enum,title:\"Text Alignment\",defaultValue:\"bottom\",options:[\"left\",\"right\",\"top\",\"bottom\"],hidden:({showText})=>!showText}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SoundToggle\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SoundToggle.map"],"mappings":"uNAMG,SAAwB,EAAY,EAAM,CAAC,GAAK,CAAC,cAAY,CAAC,IAAI,sEAAsE,IAAI,WAAW,CAAC,eAAa,CAAC,IAAI,oEAAoE,IAAI,YAAY,CAAC,YAAU,qEAAqE,WAAS,GAAK,OAAK,GAAK,SAAO,GAAG,eAAa,GAAM,WAAS,GAAG,kBAAgB,UAAU,eAAa,EAAE,UAAQ,GAAG,WAAS,GAAM,SAAO,WAAW,UAAQ,YAAY,WAAS,YAAU,UAAU,gBAAc,UAAU,EAAW,CAAC,EAAU,GAAcA,EAAS,EAAS,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAM,CAAO,EAASC,EAAO,KAAK,CAAO,EAAS,GAAqB,CAAC,MAAc,CAAC,GAAG,GAAiB,IAAS,OAAY,OAA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