{"version":3,"file":"Direct_Download.BujNDM3r.mjs","names":["useMemo","Children"],"sources":["https:/framerusercontent.com/modules/m9UGUJ8DKqEttktt0WS8/PPqVYQDXsk8viVPhn9Pm/Direct_Download.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useMemo,Children,cloneElement}from\"react\";import{motion}from\"framer-motion\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function Direct_Download_Button(props){const{sourceType,file,url,children,style,downloadName}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const finalHref=useMemo(()=>{return sourceType===\"File\"?file:url;},[sourceType,file,url]);const handleDownload=async e=>{if(e){e.preventDefault();e.stopPropagation();}if(!finalHref||isCanvas)return;try{const response=await fetch(finalHref);const blob=await response.blob();// Extract the original extension from the file (e.g., .pdf, .zip, .png)\nconst extension=finalHref.split(\".\").pop().split(/[?#]/)[0]||\"pdf\";// --- AUTO FETCH LOGIC ---\nlet fileName=\"document\";if(downloadName&&downloadName.trim()!==\"\"){// Use custom name if provided\nfileName=downloadName.trim();}else{// Auto-fetch: Extract name from URL/Path\nconst rawName=finalHref.split(\"/\").pop().split(\"?\")[0]||\"\";// Clean Framer hashes: takes the part before the first '-' or '.'\nfileName=rawName.split(\"-\")[0].split(\".\")[0]||\"document\";}const finalFileName=`${fileName}.${extension}`;// ------------------------\nconst blobUrl=window.URL.createObjectURL(blob);const link=document.createElement(\"a\");link.href=blobUrl;link.download=finalFileName;document.body.appendChild(link);link.click();// Cleanup\nsetTimeout(()=>{document.body.removeChild(link);window.URL.revokeObjectURL(blobUrl);},100);}catch(error){// Fallback for CORS: Open in new tab\nwindow.open(finalHref,\"_blank\");}};// --- Marketplace Setup Guide ---\nif(isCanvas&&(!children||children.length===0)){return /*#__PURE__*/_jsxs(\"div\",{style:{...style,...guideContainerStyle},children:[/*#__PURE__*/_jsx(\"div\",{style:badgeStyle,children:\"How to use\"}),/*#__PURE__*/_jsxs(\"div\",{style:stepsWrapperStyle,children:[/*#__PURE__*/_jsxs(\"p\",{style:instructionStyle,children:[\"1. Attach or select your button in \",/*#__PURE__*/_jsx(\"b\",{children:\"Button UI\"})]}),/*#__PURE__*/_jsxs(\"p\",{style:instructionStyle,children:[\"2. Upload your \",/*#__PURE__*/_jsx(\"b\",{children:\"File\"}),\" or Enter \",/*#__PURE__*/_jsx(\"b\",{children:\"URL\"})]}),/*#__PURE__*/_jsxs(\"p\",{style:instructionStyle,children:[\"3. Set the \",/*#__PURE__*/_jsx(\"b\",{children:\"Download Filename\"})]})]})]});}// --- NEW: Force children to \"Fill\" ---\nconst fluidChildren=Children.map(children,child=>{if(!child)return null;return /*#__PURE__*/cloneElement(child,{style:{...child.props.style,width:\"100%\",height:\"100%\"}});});return /*#__PURE__*/_jsx(motion.div,{style:{...style,cursor:finalHref?\"pointer\":\"default\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",// Ensure the wrapper itself can fill space if placed in a flex layout\nwidth:\"100%\",height:\"100%\"},onClick:handleDownload,whileTap:finalHref?{scale:.99}:{},children:fluidChildren});}/* =====================\n   This Component was created by Anwash\n===================== */const guideContainerStyle={display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",padding:\"24px\",background:\"rgba(0, 122, 255, 0.04)\",borderRadius:\"16px\",border:\"1px dashed rgba(0, 122, 255, 0.3)\",color:\"#1188FF\"};const stepsWrapperStyle={display:\"flex\",flexDirection:\"column\",alignItems:\"flex-start\",width:\"100%\",maxWidth:\"240px\",gap:\"8px\",marginTop:\"12px\"};const instructionStyle={fontFamily:\"Nunito\",fontSize:\"12px\",margin:0,lineHeight:\"1.4em\",textAlign:\"left\",opacity:.9};const badgeStyle={fontFamily:\"Nunito\",fontSize:\"10px\",fontWeight:\"bold\",textTransform:\"uppercase\",background:\"#1188FF\",color:\"white\",padding:\"4px 12px\",borderRadius:\"100px\"};// --- Property Controls ---\naddPropertyControls(Direct_Download_Button,{children:{type:ControlType.ComponentInstance,title:\"Button UI\",description:\"Attach your custom button you want to use.\"},sourceType:{type:ControlType.Enum,title:\"Source\",options:[\"File\",\"URL\"],displaySegmentedControl:true},file:{type:ControlType.File,title:\" \",allowedFileTypes:[],hidden:props=>props.sourceType!==\"File\"},url:{type:ControlType.String,title:\" \",placeholder:\"https://site.com/file.png\",hidden:props=>props.sourceType!==\"URL\"},downloadName:{type:ControlType.String,title:\"File name\",placeholder:\"e.g. Anwash's CV\",description:\"The name your users will see when saving.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Direct_Download_Button\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth any\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Direct_Download.map"],"mappings":"2PAIG,SAAwB,EAAuB,EAAM,CAAC,GAAK,CAAC,aAAW,OAAK,MAAI,WAAS,QAAM,gBAAc,EAAY,EAAS,EAAa,QAAQ,IAAI,EAAa,OAAa,EAAUA,MAAoB,IAAa,OAAO,EAAK,EAAM,CAAC,EAAW,EAAK,CAAG,CAAC,EAAQ,EAAe,KAAM,IAAG,CAAC,GAAG,IAAG,EAAE,eAAe,EAAE,EAAE,gBAAgB,GAAM,GAAC,GAAW,GAAgB,GAAG,CAAuC,IAAM,EAAK,MAAM,MAAlC,MAAM,CAAS,EAAA,CAA4B,KAAK,EAC3b,EAAU,EAAU,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,IAAI,MACzD,EAAS,WAAW,AAGxB,EAH2B,GAAc,EAAa,KAAK,IAAI,GACtD,EAAa,KAAK,GACb,EAAU,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAA,CACvC,MA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