{"version":3,"file":"NamedFileDownload.DWOlFHwr.mjs","names":["React.useRef","React.useState","React.useId","React.useCallback"],"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":"mQAAsJ,SAAS,EAAa,EAAM,EAAK,CAAC,IAAM,EAAQ,EAAM,KAAK,CAAC,CAAC,QAAQ,6BAA6B,GAAG,EAAQ,EAAU,EAAK,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,sBAAsB,CAAC,GAAG,IAAI,GAAS,EAAK,GAAS,WAAW,IAAY,OAAO,GAAW,CAAC,qBAAqB,KAAK,CAAI,EAAE,GAAG,IAAO,IAAY,CAAK,CAShc,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,KAAK,EAAQ,GAAG,UAAQ,GAAG,kBAAgB,EAAE,oBAAkB,GAAG,WAAS,WAAW,QAAM,gBAAgB,aAAW,UAAU,kBAAgB,UAAU,YAAU,UAAU,OAAK,SAAO,EAAY,EAAK,GAAS,EAAc,EAAKA,EAAa,IAAI,EAAQ,EAASA,EAAa,IAAI,EAAQ,EAASA,EAAa,EAAK,EAAO,CAAC,EAAM,GAAUC,EAAe,IAAI,EAAO,CAAC,EAAK,GAASA,EAAe,EAAK,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