{"version":3,"file":"NamedFileDownload.DkoPcbQd.mjs","names":["React.useRef","React.useState","React.useId","React.useCallback","__exportAll","ne","init_npm_react_18_3_1","ie","ce","init_jsx_runtime","p","_e","de","RenderTarget","addPropertyControls","init_framer_DcGZRLrs","ControlType","NamedFileDownload_exports","__FramerMetadata__","NamedFileDownload","safeFilename","cleaned","value","extension","file","name","fileURL","props","cmsFile","root","resource","clicking","ready","setReady","busy","setBusy","error","setError","statusId","downloadName","filename","readyUrl","prepare","controller","entry","response","blob","reason","element","warm","observer","entries","activate","event","url","anchor","style","background","hoverBackground","paddingVertical","paddingHorizontal","font","textColor","label","init_NamedFileDownload","__esmMin","\"exports\"","\"default\"","\"type\"","\"name\"","\"slots\"","\"annotations\"","\"framerContractVersion\"","\"framerSupportedLayoutWidth\"","\"framerIntrinsicWidth\"","\"framerIntrinsicHeight\"","\"framerSupportedLayoutHeight\"","\"__FramerMetadata__\""],"sources":["https:/framerusercontent.com/modules/rExrevhCQrhdTMCFU0h9/zbxaGTKpmwOWQix7RB6L/NamedFileDownload.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";function safeFilename(value,file){const cleaned=value.trim().replace(/[\\\\/:*?\"<>|\\u0000-\\u001f]/g,\"-\");const extension=file.split(/[?#]/)[0].match(/\\.([a-z0-9]{1,10})$/i)?.[0]||\"\";const name=cleaned||`download${extension}`;return extension&&!/\\.[a-z0-9]{1,10}$/i.test(name)?`${name}${extension}`:name;}/**\n * A file download with an editor-controlled filename. It prepares a local blob\n * when its own button becomes visible so normal activation can use a native\n * same-origin download, including inside Framer Play. No surrounding DOM edits.\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n * @framerIntrinsicWidth 210\n * @framerIntrinsicHeight 34\n */export default function NamedFileDownload(props){const{file:fileURL=\"\",cmsFile=\"\",paddingVertical=8,paddingHorizontal=20,filename=\"download\",label=\"Download File\",background=\"#ee4f00\",hoverBackground=\"#ff7d3c\",textColor=\"#ffffff\",font,style}=props;const file=cmsFile||fileURL;const root=React.useRef(null);const resource=React.useRef(null);const clicking=React.useRef(false);const[ready,setReady]=React.useState(null);const[busy,setBusy]=React.useState(false);const[error,setError]=React.useState(\"\");const statusId=React.useId();const downloadName=safeFilename(filename,file);const readyUrl=ready?.file===file&&resource.current?.url===ready.url?ready.url:\"\";const prepare=React.useCallback(()=>{if(!file)return Promise.reject(new Error(\"No file selected\"));if(resource.current?.file===file)return resource.current.promise;const controller=new AbortController;const entry={file,controller,promise:Promise.resolve(\"\")};resource.current=entry;entry.promise=fetch(file,{signal:controller.signal,credentials:\"omit\"}).then(response=>{if(!response.ok)throw new Error(`File request failed (${response.status})`);return response.blob();}).then(blob=>{if(controller.signal.aborted||resource.current!==entry)throw new Error(\"Download cancelled\");if(!blob.size)throw new Error(\"The file is empty\");entry.url=URL.createObjectURL(blob);setReady({file,url:entry.url});return entry.url;}).catch(reason=>{if(resource.current===entry)resource.current=null;throw reason;});return entry.promise;},[file]);React.useEffect(()=>{setError(\"\");setReady(null);if(RenderTarget.current()===RenderTarget.canvas||!file||!root.current)return;const element=root.current;const warm=()=>{void prepare().catch(()=>{});};const observer=typeof IntersectionObserver===\"undefined\"?null:new IntersectionObserver(entries=>{if(entries.some(entry=>entry.isIntersecting)){observer?.disconnect();warm();}});if(observer)observer.observe(element);else warm();return()=>{observer?.disconnect();const entry=resource.current;if(entry?.file===file){entry.controller.abort();if(entry.url)URL.revokeObjectURL(entry.url);resource.current=null;}};},[file,prepare]);const activate=async event=>{if(readyUrl&&!clicking.current){setError(\"\");return;// Native anchor download, in the original user activation.\n}event.preventDefault();if(clicking.current)return;clicking.current=true;setBusy(true);setError(\"\");const element=root.current;try{const url=await prepare();if(!element?.isConnected)return;const anchor=element.ownerDocument.createElement(\"a\");anchor.href=url;anchor.download=downloadName;anchor.hidden=true;element.appendChild(anchor);anchor.click();anchor.remove();}catch{if(element?.isConnected)setError(file?\"The download could not start. Please try again.\":\"No file has been selected.\");}finally{clicking.current=false;if(element?.isConnected)setBusy(false);}};return /*#__PURE__*/_jsxs(\"div\",{ref:root,className:\"udig-named-download\",style:{...style,position:\"relative\",display:\"flex\",flexDirection:\"column\",alignItems:\"flex-start\",width:\"max-content\",maxWidth:\"100%\",height:\"auto\",\"--udig-download-fill\":background,\"--udig-download-hover\":hoverBackground},children:[/*#__PURE__*/_jsx(\"style\",{children:`.udig-named-download > a.udig-download-button{background:var(--udig-download-fill);transition:background-color .4s ease;text-decoration:none}.udig-named-download > a.udig-download-button:hover{background:var(--udig-download-hover)}.udig-named-download > a.udig-download-button:focus-visible{outline:2px solid currentColor;outline-offset:3px}@media(prefers-reduced-motion:reduce){.udig-named-download > a.udig-download-button{transition:none}}`}),/*#__PURE__*/_jsx(\"a\",{className:\"udig-download-button\",href:readyUrl||file||undefined,download:downloadName,onClick:activate,onFocus:()=>{void prepare().catch(()=>{});},\"aria-busy\":busy,\"aria-describedby\":error?statusId:undefined,style:{display:\"inline-flex\",alignItems:\"center\",justifyContent:\"center\",boxSizing:\"border-box\",padding:`${paddingVertical}px ${paddingHorizontal}px`,border:\"none\",borderRadius:22,margin:0,width:\"max-content\",maxWidth:\"100%\",fontFamily:'\"Century Gothic Bold\", \"Century Gothic Bold Placeholder\", sans-serif',fontSize:14,fontWeight:700,fontStyle:\"normal\",lineHeight:\"18px\",letterSpacing:\"-0.28px\",fontFeatureSettings:'\"blwf\" on, \"cv03\" on, \"cv04\" on, \"cv09\" on, \"cv11\" on',...font,color:textColor,whiteSpace:\"nowrap\",cursor:busy?\"progress\":\"pointer\",textDecoration:\"none\"},children:label}),/*#__PURE__*/_jsx(\"span\",{id:statusId,role:\"status\",\"aria-live\":\"polite\",style:error?{fontFamily:\"sans-serif\",fontSize:14,lineHeight:\"20px\",marginTop:8}:{position:\"absolute\",width:1,height:1,padding:0,margin:-1,overflow:\"hidden\",clipPath:\"inset(50%)\",whiteSpace:\"nowrap\"},children:error||(busy?\"Preparing download\":\"\")})]});}addPropertyControls(NamedFileDownload,{cmsFile:{type:ControlType.File,title:\"File Upload\",allowedFileTypes:[\"pdf\",\"xlsx\",\"pptx\"],description:\"For the article template: connect to the Blogs Download File field. Inline buttons continue to use File URL.\"},paddingVertical:{type:ControlType.Number,title:\"Vertical Padding\",defaultValue:8,min:0,max:40,step:1,unit:\"px\"},paddingHorizontal:{type:ControlType.Number,title:\"Horizontal Padding\",defaultValue:20,min:0,max:60,step:1,unit:\"px\"},file:{type:ControlType.String,title:\"File URL\",defaultValue:\"\",description:\"Paste the Framer-hosted file URL. Inline CMS embeds require a URL rather than a File upload control.\"},filename:{type:ControlType.String,title:\"Filename\",defaultValue:\"download\",description:\"The name visitors receive, including .xlsx or .pdf.\"},label:{type:ControlType.String,title:\"Button Label\",defaultValue:\"Download File\"},background:{type:ControlType.Color,title:\"Fill\",defaultValue:\"#ee4f00\"},hoverBackground:{type:ControlType.Color,title:\"Hover Fill\",defaultValue:\"#ff7d3c\"},textColor:{type:ControlType.Color,title:\"Text\",defaultValue:\"#ffffff\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{variant:\"Bold\",fontSize:\"14px\",lineHeight:\"18px\",letterSpacing:\"-0.28px\"}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NamedFileDownload\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\",\"framerIntrinsicWidth\":\"210\",\"framerIntrinsicHeight\":\"34\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NamedFileDownload.map"],"mappings":"A,oRAAsJ,SAASoB,EAAa,EAAM,EAAK,CAAC,IAAMC,EAAQC,EAAM,KAAK,CAAC,CAAC,QAAQ,6BAA6B,GAAG,EAAQC,EAAUC,EAAK,MAAM,MAAM,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