{"version":3,"file":"PdfDownload.ClNEOSoy.mjs","names":["element"],"sources":["https:/framerusercontent.com/modules/8MqSmwvXMcBl6GQ7YFT9/Y3QJEnCY7d0Vpx5UvPia/PdfDownload.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";export default function PdfDownload({children,className=\"\",style={},elementId,elementClass,filename=\"section-download.pdf\",buttonText=\"Download PDF\"}){const downloadSectionAsTextPDF=()=>{let element=null;// Try to find element by ID first, then by class\nif(elementId){element=document.getElementById(elementId);}else if(elementClass){element=document.querySelector(`.${elementClass}`);}if(!element){const selector=elementId?`id \"${elementId}\"`:elementClass?`class \"${elementClass}\"`:\"specified selector\";console.error(`Element with ${selector} not found`);return;}// Check if jsPDF is loaded\nconst jsPDF=window.jsPDF||window.jspdf?.jsPDF;if(!jsPDF){console.error(\"jsPDF not loaded\");return;}const pdf=new jsPDF;const pageWidth=pdf.internal.pageSize.getWidth();const pageHeight=pdf.internal.pageSize.height;const leftMargin=20;const rightMargin=20;const textWidth=pageWidth-leftMargin-rightMargin;let y=20;// Function to extract all text content while preserving structure\nfunction getTextWithFormatting(el){let result=[];function traverse(node,isBold=false,fontSize=12){if(node.nodeType===Node.TEXT_NODE){const text=node.textContent?.trim();if(text){result.push({text,isBold,fontSize});}}else if(node.nodeType===Node.ELEMENT_NODE){const element=node;const tagName=element.tagName.toLowerCase();let childIsBold=isBold;let childFontSize=fontSize;// Check if this element should be bold\nif(tagName===\"strong\"||tagName===\"b\"){childIsBold=true;}// Adjust font size for headings\nif(tagName.match(/^h[1-6]$/)){childFontSize=18-parseInt(tagName.charAt(1))*2;childIsBold=true;}// Process all child nodes\nfor(let child of node.childNodes){traverse(child,childIsBold,childFontSize);}// Add line break after block elements\nif([\"p\",\"div\",\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"].includes(tagName)){result.push({text:\"\\n\",isBold:false,fontSize});}}}traverse(el);return result;}// Function to add formatted text to PDF\nfunction addFormattedText(textArray){let currentLine=\"\";let currentLineElements=[];for(let item of textArray){if(item.text===\"\\n\"){// Process current line\nif(currentLine.trim()){addLineWithFormatting(currentLineElements);}currentLine=\"\";currentLineElements=[];y+=5// Add some space after paragraphs\n;}else{// Add space between words if needed\nif(currentLine&&!currentLine.endsWith(\" \")&&!item.text.startsWith(\" \")){currentLine+=\" \";currentLineElements.push({text:\" \",isBold:false,fontSize:item.fontSize});}currentLine+=item.text;currentLineElements.push(item);}}// Process final line\nif(currentLine.trim()){addLineWithFormatting(currentLineElements);}}function addLineWithFormatting(elements){// Combine text for line breaking calculation\nconst combinedText=elements.map(e=>e.text).join(\"\");const baseFontSize=elements[0]?.fontSize||12;// Set font for measuring\npdf.setFontSize(baseFontSize);const lines=pdf.splitTextToSize(combinedText,textWidth);// Check if we need a new page\nconst lineHeight=baseFontSize*.6;if(y+lines.length*lineHeight>pageHeight-20){pdf.addPage();y=20;}// For each line, we need to render with proper formatting\nlines.forEach(line=>{let xOffset=leftMargin;let currentPos=0;for(let element of elements){const elementText=element.text;const endPos=currentPos+elementText.length;// Find what part of this element appears in current line\nconst lineStart=combinedText.indexOf(line);const lineEnd=lineStart+line.length;if(currentPos<lineEnd&&endPos>lineStart){const startInElement=Math.max(0,lineStart-currentPos);const endInElement=Math.min(elementText.length,lineEnd-currentPos);const textPart=elementText.substring(startInElement,endInElement);if(textPart){// Set font style\npdf.setFontSize(element.fontSize);if(element.isBold){pdf.setFont(undefined,\"bold\");}else{pdf.setFont(undefined,\"normal\");}// Add text and move x position\npdf.text(textPart,xOffset,y);xOffset+=pdf.getTextWidth(textPart);}}currentPos=endPos;}y+=lineHeight;});}// Process the content\nconst textContent=getTextWithFormatting(element);addFormattedText(textContent);pdf.save(filename);};const handleDownload=()=>{// Load jsPDF if not already loaded\nif(typeof window!==\"undefined\"&&!window.jsPDF&&!window.jspdf){const script=document.createElement(\"script\");script.src=\"https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js\";script.onload=()=>{// jsPDF is now loaded\nwindow.jsPDF=window.jspdf?.jsPDF;downloadSectionAsTextPDF();};script.onerror=()=>{console.error(\"Failed to load jsPDF library\");};document.head.appendChild(script);}else{downloadSectionAsTextPDF();}};const defaultStyle={// Minimal styles for visibility while allowing inheritance\ncursor:\"pointer\",display:\"inline-block\",minWidth:\"fit-content\",minHeight:\"20px\",// Only add basic styling if no className is provided\n...className?{}:{padding:\"8px 16px\",backgroundColor:\"#007AFF\",color:\"white\",borderRadius:\"4px\",border:\"none\",fontSize:\"14px\"},...style};return /*#__PURE__*/_jsx(\"button\",{onClick:handleDownload,className:className,style:defaultStyle,children:children||buttonText});}// Add property controls for Framer\naddPropertyControls(PdfDownload,{buttonText:{type:ControlType.String,title:\"Button Text\",defaultValue:\"Download PDF\"},elementId:{type:ControlType.String,title:\"Element ID\",description:\"ID of the element to convert to PDF\"},elementClass:{type:ControlType.String,title:\"Element Class\",description:\"CSS class of the element to convert to PDF\"},filename:{type:ControlType.String,title:\"File Name\",defaultValue:\"section-download.pdf\",description:\"Name of the downloaded PDF file\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"PdfDownload\",\"slots\":[\"children\"],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PdfDownload.map"],"mappings":"0KAA+F,SAAwB,EAAY,CAAC,WAAS,YAAU,GAAG,QAAM,EAAE,CAAC,YAAU,eAAa,WAAS,uBAAuB,aAAW,gBAAgB,CAAC,IAAM,MAA6B,CAAC,IAAI,EAAQ,KAClK,GAAjI,EAAW,EAAQ,SAAS,eAAe,EAAU,CAAU,IAAc,EAAQ,SAAS,cAAc,IAAI,IAAe,EAAK,CAAC,EAAQ,CAAC,IAAM,EAAS,EAAU,OAAO,EAAU,GAAG,EAAa,UAAU,EAAa,GAAG,qBAAqB,QAAQ,MAAM,gBAAgB,EAAS,YAAY,CAAC,OAC9S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