{"version":3,"file":"Direct_Download.DPXTtoUC.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":"qQAIG,SAAwB,EAAuB,EAAM,CAAC,GAAK,CAAC,aAAW,OAAK,MAAI,WAAS,QAAM,gBAAc,EAAY,EAAS,EAAa,SAAS,GAAG,EAAa,OAAa,EAAUA,MAAoB,IAAa,OAAO,EAAK,EAAM,CAAC,EAAW,EAAK,EAAI,CAAC,CAAO,EAAe,KAAM,IAAG,CAAC,GAAG,IAAG,EAAE,gBAAgB,CAAC,EAAE,iBAAiB,EAAK,GAAC,GAAW,GAAgB,GAAG,CAAuC,IAAM,EAAK,MAAlC,MAAM,MAAM,EAAU,EAA2B,MAAM,CAC5b,EAAU,EAAU,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,MACzD,EAAS,WAAW,AAGxB,EAH2B,GAAc,EAAa,MAAM,GAAG,GACtD,EAAa,MAAM,EACd,EAAU,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,IACvC,MAAM,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,W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