1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7173],{97173:(e,t,a)=>{a.r(t),a.d(t,{OfflinePDFViewer:()=>b,default:()=>x,invalidateOfflinePdfCache:()=>y,stripLegacyStickyNotes:()=>g});var l=a(95155),n=a(12115),r=a(67909),i=a(35299),o=a(6132),s=a(14219),d=a(5903),c=a(26405),u=a(18955),f=a(44517);let m=(0,r.default)(()=>Promise.all([a.e(1126),a.e(6475),a.e(1539),a.e(8720),a.e(4433),a.e(5166),a.e(9857),a.e(4436),a.e(8250),a.e(5086)]).then(a.bind(a,69870)),{loadableGenerated:{webpack:()=>[69870]},ssr:!1,loading:()=>(0,l.jsxs)("div",{className:"w-full h-full min-h-125 bg-dashboard-card flex flex-col items-center justify-center gap-4 rounded-3xl",children:[(0,l.jsx)(i.A,{className:"w-10 h-10 text-dynamic-primary-500 animate-spin"}),(0,l.jsx)("p",{className:"text-gray-500 dark:text-gray-400 text-sm font-medium animate-pulse",children:"Loading viewer..."})]})}),h=new Map;function y(e){if(e){let t=h.get(e);if(t){try{URL.revokeObjectURL(t.blobUrl)}catch(e){}h.delete(e)}}else h.forEach(e=>{try{URL.revokeObjectURL(e.blobUrl)}catch(e){}}),h.clear()}async function g(e){try{let{PDFDocument:l,PDFName:n,PDFArray:r,PDFDict:i}=await a.e(3394).then(a.bind(a,63394)),o=await l.load(e,{ignoreEncryption:!0}),s=o.getPages(),d=!1;for(let e of s){let a=e.node.lookupMaybe(n.of("Annots"),r);if(a&&a.size()>0){let l=[];for(let e=0;e<a.size();e++){let r=a.lookup(e,i);if(r){var t;let e=null==(t=r.lookupMaybe(n.of("Subtype"),n))?void 0:t.asString();if("/Text"===e||"/FreeText"===e){d=!0;continue}}l.push(a.get(e))}d&&(l.length>0?e.node.set(n.of("Annots"),o.context.obj(l)):e.node.delete(n.of("Annots")))}}if(d){let e=await o.save();return{cleanBytes:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),wasCleaned:!0}}}catch(e){console.warn("Could not strip legacy sticky notes from offline PDF:",e)}return{cleanBytes:e,wasCleaned:!1}}function b(e){let{pdfId:t,title:r,settings_watermark:y,fullHeight:b=!1,downloadable:x="download_on_device"}=e,p=(0,u.c)("dashboard.downloads"),{user:w}=(0,c.x)(),v=null==w?void 0:w.id,[j,S]=(0,n.useState)(()=>{let e=t?h.get(t):null;return e&&v&&String(e.userId)===String(v)?e.blobUrl:null}),[k,D]=(0,n.useState)(()=>{let e=t?h.get(t):null;return e&&v&&String(e.userId)===String(v)?e.meta:null}),[F,N]=(0,n.useState)(()=>{let e=t?h.get(t):null;return!(e&&v&&String(e.userId)===String(v))}),[P,U]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!t||!v)return;let e=!0,l=h.get(t);if(l&&String(l.userId)===String(v)){D(l.meta),S(l.blobUrl),N(!1);return}return N(!0),U(null),(async()=>{try{let[l,n]=await Promise.all([s.V.getPDF(t),s.V.getPDFFile(t)]);if(!e)return;if(!n||!n.encryptedData)throw Error("Encrypted PDF data not found in offline storage");let i=await (0,d.A$)(n.encryptedData,n.iv,v);if(!e)return;let{cleanBytes:o,wasCleaned:c}=await g(i),u=l||{id:t,userId:v,title:r||"Document",originalUrl:"",timestamp:Date.now(),totalSize:o.byteLength,annotations:[]};if(c)try{let{getOrDeriveKey:e,encryptData:l}=await Promise.resolve().then(a.bind(a,5903)),n=await e(v),{encrypted:r,iv:i}=await l(o,n);await s.V.savePDF(u,{id:t,encryptedData:r,iv:i})}catch(e){console.warn("Could not re-encrypt sanitized offline PDF:",e)}let f=new Blob([o],{type:"application/pdf"}),m=URL.createObjectURL(f);h.set(t,{blobUrl:m,meta:u,userId:v}),D(u),S(m),N(!1)}catch(t){e&&(console.error("Failed to decrypt offline PDF:",t),U(t.message||"Failed to load offline document"),N(!1))}})(),()=>{e=!1}},[t,v,r]);let A=(0,n.useMemo)(()=>(null==k?void 0:k.annotations)||[],[t,!!j]),E=async e=>{try{await s.V.updatePDFAnnotations(t,e);let a=h.get(t);a&&(a.meta={...a.meta,annotations:e}),f.default.success(p("saved")||"Saved successfully")}catch(e){console.error("Failed to save offline annotations:",e),f.default.error(p("failedToSaveAnnotations")||"Failed to save annotations")}};return P?(0,l.jsxs)("div",{className:"w-full ".concat(b?"h-full min-h-125":"h-[75vh]"," bg-dashboard-card rounded-3xl flex flex-col items-center justify-center p-8 border border-red-500/20 text-center space-y-4"),children:[(0,l.jsx)("div",{className:"w-16 h-16 rounded-full bg-red-500/10 flex items-center justify-center",children:(0,l.jsx)(o.A,{className:"w-8 h-8 text-red-500"})}),(0,l.jsxs)("div",{className:"space-y-1 max-w-md",children:[(0,l.jsx)("h4",{className:"text-lg font-bold text-gray-800 dark:text-gray-100",children:p("loadError")||"Failed to load document"}),(0,l.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:P})]})]}):F||!j?(0,l.jsxs)("div",{className:"w-full ".concat(b?"h-full min-h-125":"h-[75vh]"," bg-dashboard-card rounded-3xl flex flex-col items-center justify-center gap-4 p-8 border border-gray-100 dark:border-white/5"),children:[(0,l.jsx)(i.A,{className:"w-10 h-10 text-dynamic-primary-500 animate-spin"}),(0,l.jsx)("p",{className:"text-sm font-semibold text-gray-600 dark:text-gray-300 animate-pulse",children:p("loading")||"Decrypting document..."})]}):(0,l.jsx)("div",{className:"w-full ".concat(b?"h-full":"h-[75vh]"," relative"),children:(0,l.jsx)(m,{url:j,title:r||(null==k?void 0:k.title)||"Document",contentId:t,fullHeight:b,settings_watermark:y,initialAnnotations:A,onSave:E,downloadable:x})})}let x=b}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.