{"version":3,"file":"PDFViewer.BU4SAnAY.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/LOK8FAC6erCWPgyV3yer/dJoA63HwTG9TZvz1ZXkG/PDFViewer.js"],"sourcesContent":["// PDF to JPEG converter component\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef,useState,startTransition}from\"react\";/**\n * PDF to JPEG Converter\n *\n * @framerIntrinsicWidth 800\n * @framerIntrinsicHeight 600\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function PDFViewer(props){const{pdfFile=\"https://framerusercontent.com/assets/4vMMSMH8hRU6R0RxLdpOWAOaXo.pdf\",backgroundColor,jpegQuality=.95,style}=props;const containerRef=useRef(null);const[loading,setLoading]=useState(true);const[error,setError]=useState(null);const[jpegImages,setJpegImages]=useState([]);useEffect(()=>{if(typeof window===\"undefined\")return;startTransition(()=>{setLoading(true);setError(null);setJpegImages([]);});// Load PDF.js library\nconst script=document.createElement(\"script\");script.src=\"https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js\";script.async=true;script.onload=()=>{loadPDF();};script.onerror=()=>{startTransition(()=>{setError(\"Failed to load PDF library\");setLoading(false);});};document.head.appendChild(script);return()=>{if(document.head.contains(script)){document.head.removeChild(script);}};},[pdfFile,jpegQuality]);const loadPDF=async()=>{try{// @ts-ignore - PDF.js global\nconst pdfjsLib=window[\"pdfjs-dist/build/pdf\"];if(!pdfjsLib){throw new Error(\"PDF.js not loaded\");}// Set worker\npdfjsLib.GlobalWorkerOptions.workerSrc=\"https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js\";// Load PDF\nconst loadingTask=pdfjsLib.getDocument(pdfFile);const pdf=await loadingTask.promise;// Get container width for proper scaling\nconst containerWidth=containerRef.current?.clientWidth||800;const pixelRatio=window.devicePixelRatio||1;const images=[];// Render all pages and convert to JPEG\nfor(let pageNum=1;pageNum<=pdf.numPages;pageNum++){const page=await pdf.getPage(pageNum);// Create a temporary canvas for rendering\nconst canvas=document.createElement(\"canvas\");const context=canvas.getContext(\"2d\");if(!context)continue;// Get viewport at scale 1.0 first to get original dimensions\nconst viewport=page.getViewport({scale:1});// Calculate scale to fit container width perfectly\nconst scale=containerWidth/viewport.width;// Use higher resolution for crisp rendering (multiply by devicePixelRatio)\nconst outputScale=scale*pixelRatio;const scaledViewport=page.getViewport({scale:outputScale});// Set canvas size at high resolution\ncanvas.height=scaledViewport.height;canvas.width=scaledViewport.width;const renderContext={canvasContext:context,viewport:scaledViewport};await page.render(renderContext).promise;// Convert canvas to JPEG data URL\nconst jpegDataUrl=canvas.toDataURL(\"image/jpeg\",jpegQuality);images.push(jpegDataUrl);}startTransition(()=>{setJpegImages(images);setLoading(false);});}catch(err){console.error(\"Error loading PDF:\",err);startTransition(()=>{setError(\"Failed to load PDF. Please check the file URL.\");setLoading(false);});}};return /*#__PURE__*/_jsxs(\"div\",{style:{...style,position:\"relative\",width:\"100%\",height:\"100%\",backgroundColor,overflow:\"auto\",display:\"flex\",flexDirection:\"column\",alignItems:\"center\"},ref:containerRef,children:[loading&&/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",justifyContent:\"center\",alignItems:\"center\",height:\"100%\",color:\"#666\",fontSize:\"16px\"},children:\"Converting PDF to JPEG...\"}),error&&/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",justifyContent:\"center\",alignItems:\"center\",height:\"100%\",color:\"#d32f2f\",fontSize:\"16px\",padding:\"20px\",textAlign:\"center\"},children:error}),!loading&&!error&&jpegImages.length>0&&/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"column\",gap:\"10px\",padding:\"20px\",width:\"100%\"},children:jpegImages.map((imgSrc,i)=>/*#__PURE__*/_jsx(\"img\",{src:imgSrc,alt:`PDF Page ${i+1}`,style:{width:\"100%\",height:\"auto\",boxShadow:\"0 2px 8px rgba(0,0,0,0.1)\",display:\"block\"}},i))})]});}addPropertyControls(PDFViewer,{pdfFile:{type:ControlType.File,title:\"PDF File\",allowedFileTypes:[\"pdf\"]},jpegQuality:{type:ControlType.Number,title:\"JPEG Quality\",defaultValue:.95,min:.1,max:1,step:.05,displayStepper:true},backgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#F5F5F5\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"PDFViewer\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"800\",\"framerIntrinsicHeight\":\"600\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PDFViewer.map"],"mappings":"gNASG,SAAwB,EAAU,EAAM,CAAC,GAAK,CAAC,UAAQ,sEAAsE,kBAAgB,cAAY,IAAI,SAAO,EAAY,EAAaA,EAAO,IAAI,EAAO,CAAC,EAAQ,GAAYC,EAAS,EAAI,EAAO,CAAC,EAAM,GAAUA,EAAS,IAAI,EAAO,CAAC,EAAW,GAAeA,EAAS,CAAC,CAAC,EAAE,MAAc,CAAC,GAAU,IAAS,OAAY,OAAO,MAAoB,CAAC,EAAW,EAAI,EAAE,EAAS,IAAI,EAAE,EAAc,CAAC,CAAC,CAAE,CAAC,EACrc,IAAM,EAAO,SAAS,cAAc,QAAQ,EAA2Q,MAAzQ,GAAO,IAAI,oEAAoE,EAAO,MAAM,GAAK,EAAO,WAAW,CAAC,EAAQ,CAAE,EAAE,EAAO,YAAY,CAAC,MAAoB,CAAC,EAAS,4BAA4B,EAAE,EAAW,EAAK,CAAE,CAAC,CAAE,EAAE,SAAS,KAAK,YAAY,CAAM,MAAY,CAAI,SAAS,KAAK,SAAS,CAAM,GAAG,SAAS,KAAK,YAAY,CAAM,CAAG,CAAE,EAAE,CAAC,EAAQ,CAAW,CAAC,EAAE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