{"version":3,"file":"SoundButton.YnuYyFDA.mjs","names":["React.useRef","React.useState","__esmMin","init_npm_react_18_3_1","_e","p","c","init_jsx_runtime","ce","de","RenderTarget","addPropertyControls","ControlType","init_framer_BpuvUAiZ","SoundButton","props","audioRef","on","setOn","failed","setFailed","isCanvas","current","file","stop","a","currentStop","size","color","init_SoundButton"],"sources":["https:/framerusercontent.com/modules/cucr1U2ko0RfRuIFtgoV/ux4m2qEvhuWNujI8mVCB/SoundButton.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";let current=null;let currentStop=null;/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function SoundButton(props){const{file,color,size}=props;const audioRef=React.useRef(null);const[on,setOn]=React.useState(false);const[failed,setFailed]=React.useState(false);const isCanvas=RenderTarget.current()===RenderTarget.canvas;React.useEffect(()=>{return()=>{if(audioRef.current){audioRef.current.pause();if(current===audioRef.current){current=null;currentStop=null;}}};},[]);if(!file&&!isCanvas)return null;const stop=()=>{if(audioRef.current)audioRef.current.pause();setOn(false);};const toggle=e=>{e.stopPropagation();if(!file)return;if(!audioRef.current){const a=new Audio(file);a.loop=true;a.volume=.5;a.preload=\"auto\";a.addEventListener(\"error\",()=>{setFailed(true);setOn(false);});audioRef.current=a;}const a=audioRef.current;if(on){stop();return;}if(current&&current!==a&&currentStop)currentStop();setFailed(false);const p=a.play();current=a;currentStop=stop;setOn(true);if(p&&p.catch)p.catch(()=>{setOn(false);setFailed(true);});};return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",pointerEvents:\"auto\"},children:/*#__PURE__*/_jsx(\"button\",{type:\"button\",onClick:toggle,\"aria-label\":on?\"Turn sound off\":\"Turn sound on\",\"aria-pressed\":on,style:{width:size,height:size,borderRadius:\"50%\",border:\"1px solid \"+(failed?\"#b5483a\":color),background:on?color:\"transparent\",color:on?\"#0c2c22\":color,cursor:\"pointer\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",padding:0,transition:\"background 0.3s, color 0.3s\"},children:/*#__PURE__*/_jsxs(\"svg\",{width:size*.5,height:size*.5,viewBox:\"0 0 24 24\",fill:\"none\",stroke:\"currentColor\",strokeWidth:\"1.6\",strokeLinecap:\"round\",strokeLinejoin:\"round\",children:[/*#__PURE__*/_jsx(\"path\",{d:\"M4 9v6h4l5 4V5L8 9H4z\"}),on?/*#__PURE__*/_jsx(\"path\",{d:\"M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12\"}):/*#__PURE__*/_jsx(\"path\",{d:\"M17 9l5 6M22 9l-5 6\"})]})})});}SoundButton.defaultProps={color:\"#d4af5f\",size:44};addPropertyControls(SoundButton,{file:{type:ControlType.File,title:\"Audio\",allowedFileTypes:[\"mp3\",\"m4a\",\"wav\"]},color:{type:ControlType.Color,title:\"Color\"},size:{type:ControlType.Number,title:\"Size\",min:28,max:80,step:2}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SoundButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SoundButton.map"],"mappings":"A,uMAGG,SAAwBc,EAAY,EAAM,CAAC,GAAK,CAAC,OAAK,QAAM,QAAMC,EAAYC,EAAShB,EAAa,IAAI,EAAO,CAACiB,EAAGC,GAAOjB,EAAe,EAAK,EAAO,CAACkB,EAAOC,GAAWnB,EAAe,EAAK,EAAQoB,EAASX,EAAa,QAAQ,IAAIA,EAAa,OAA4J,GAArJF,UAA+B,CAAIQ,EAAS,UAASA,EAAS,QAAQ,MAAM,EAAKM,IAAUN,EAAS,UAAS,EAAQ,KAAK,EAAY,MAAO,EA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