@epam/ai-dial-react-pdf-highlighter 0.2.0-dev.15 → 0.2.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("@epam/ai-dial-ui-kit"),F=require("@epam/pdf-highlighter-kit"),t=require("react"),z=require("@tabler/icons-react"),R="auto",L="page-fit",V=[{value:R,label:"Auto"},{value:L,label:"Page Fit"},{value:"0.5",label:"50%"},{value:"0.75",label:"75%"},{value:"1",label:"100%"},{value:"1.25",label:"125%"},{value:"1.5",label:"150%"},{value:"2",label:"200%"},{value:"3",label:"300%"}],W={maxWidth:104,format:"image/jpeg",quality:.85},$=15,le="application/pdf",oe=".pdf",X=({pdf:a,highlights:r,selectedHighlightId:u,autoFocusFirstHighlight:l=!1,selectedPageNumber:m,zoom:c,containerClassName:h,onTotalPagesChange:v,onViewerReady:N,selectedPages:d,viewerOptions:y})=>{const f=t.useRef(null),n=t.useRef(null),[b,D]=t.useState(!1),[g,E]=t.useState(!1),T=t.useRef(v),O=t.useRef(N),S=t.useRef(y);t.useEffect(()=>{T.current=v},[v]),t.useEffect(()=>{O.current=N},[N]),t.useEffect(()=>{S.current=y},[y]);const j=t.useCallback(s=>n.current?.goToHighlight(s),[]);return t.useEffect(()=>{if(!f.current)return;D(!1),E(!1),n.current&&(n.current.destroy(),n.current=null);let s=null,x=!0;const p=()=>{x&&E(!0)};return(async()=>{try{if(s=new F.PDFHighlightViewer,await s.init(f.current,{enableTextSelection:!0,enableVirtualScrolling:!0,bboxOrigin:"top-left",...S.current}),!x){s.destroy();return}if(s.addEventListener("zoomChanged",p),await s.loadPDF(a,{selectedPages:d}),!x){s.destroy();return}const C=s.getTotalPages?.();typeof C=="number"&&C>0&&T.current?.(C),x&&(n.current=s,D(!0))}catch(C){if(!x)return;console.error("Error in initViewer:",C)}})(),()=>{x=!1,s&&(s.removeEventListener("zoomChanged",p),s.destroy())}},[a,d]),t.useEffect(()=>{!b||!n.current||(n.current.loadHighlights(r),l&&r&&r[0]&&j(r[0].id))},[l,j,r,b]),t.useEffect(()=>{b&&g&&u&&j(u)},[j,b,g,u]),t.useEffect(()=>{if(!(!b||!c))if(c===R)n.current?.setZoom?.(F.ZoomMode.AUTO);else if(c===L)n.current?.setZoom?.(F.ZoomMode.PAGE_FIT);else{const s=parseFloat(c);!Number.isNaN(s)&&s>0&&n.current?.setZoom?.(s)}},[b,c]),t.useEffect(()=>{b&&m&&n.current?.setPage?.(m)},[b,m]),t.useEffect(()=>{if(!b||!n.current)return;const s=n.current;O.current?.({getThumbnailsDataUrl:(x,p)=>s.getThumbnailsDataUrl(x,p),zoomIn:()=>s.zoomIn(),zoomOut:()=>s.zoomOut(),getZoom:()=>s.getZoom(),navigateToPage:x=>s.setPage?.(x),setPageDisplayRotation:(x,p,I)=>s.setPageDisplayRotation(x,p,I),getPageDisplayRotation:x=>s.getPageDisplayRotation(x)})},[b]),e.jsx("div",{ref:f,className:i.mergeClasses("grow min-w-0 overflow-auto bg-layer-3",h)})},P="h-4 rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave",Y=({className:a,ariaLabel:r="pdf preview loading"})=>e.jsx("div",{role:"status","aria-label":r,"aria-live":"polite",className:i.mergeClasses("h-full w-full bg-layer-3",a),children:e.jsxs("div",{className:"flex h-full w-full flex-col gap-10 px-[60px] pt-10",children:[e.jsx("div",{className:"mx-auto h-4 w-[208px] max-w-[40%] rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:i.mergeClasses(P,"w-[28%] max-w-[320px]")})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:i.mergeClasses(P,"w-[58%] max-w-[520px]")})]})]})}),J=t.createContext(null),Q=()=>t.useContext(J),_=V.filter(({value:a})=>{const r=Number.parseFloat(a);return!Number.isNaN(r)&&r>0}),ce=[..._].reverse(),ee=(a,r,u)=>{if(_.length===0)return a;const l=Number.parseFloat(a),m=!Number.isNaN(l)&&l>0?l:u,c=typeof m=="number"&&m>0?m:Number.parseFloat(_[0].value);return r===1?(_.find(({value:h})=>Number.parseFloat(h)>c)??_[_.length-1]).value:(ce.find(({value:h})=>Number.parseFloat(h)<c)??_[0]).value};function te(a,r){const u=(a??"").toLowerCase();return(r??"").toLowerCase()===le||u.endsWith(oe)}const K=V.map(a=>({value:a.value,label:a.label})),ae=({fileUrl:a,fileName:r,loadFileCb:u,highlights:l,selectedPageNumber:m,onTotalPagesChange:c,thumbnailPageNumbers:h,onThumbnailsLoaded:v,onViewerReady:N,showLoaderOverlay:d=!1,selectedPages:y})=>{const f=Q(),n=t.useRef(null),[b,D]=t.useState(!1),[g,E]=t.useState(0),[T,O]=t.useState(!1),[S,j]=t.useState(null),[s,x]=t.useState(null),[p,I]=t.useState(R),C=t.useMemo(()=>{let o=r||a;if(!r)try{o=new URL(a).pathname}catch{o=a.split("?")[0].split("#")[0]}return te(o.toLowerCase())},[r,a]),B=t.useCallback(o=>{E((g+o+l.length)%l.length)},[g,l.length]),H=t.useCallback(o=>{const w=n.current;!w?.getZoom||!o||I(ee(p,o,w.getZoom()))},[p]),k=t.useMemo(()=>{if(!(p===R||p===L||V.some(w=>w.value===p))){const w=parseFloat(p);if(!Number.isNaN(w)&&w>0)return[...K,{value:p,label:`${Math.round(w*100)}%`}]}return K},[p]);t.useEffect(()=>{let o=!1;if(j(!0),O(!1),x(null),D(!1),n.current=null,!C){O(!0),j(!1);return}return(async()=>{try{const Z=await(f?f.getFile(a,()=>u(a)):u(a));o||x(Z)}catch{o||(O(!0),x(null))}finally{o||j(!1)}})(),()=>{o=!0}},[a,f,u,C]);const M=t.useCallback(o=>{n.current=o,D(!0),N?.(o)},[N]);return t.useEffect(()=>{const o=h??[],w=n.current?.getThumbnailsDataUrl;if(!o.length||!w||!s||!v||!b)return;let Z=!1;return(async()=>{const G=new Map;for(let A=0;A<o.length&&!Z;A+=$){const se=o.slice(A,A+$);try{const U=await w(se,W);if(Z)break;U.forEach((re,ne)=>G.set(ne,re)),v(new Map(G))}catch(U){console.warn("Thumbnail batch load failed:",U);break}}})(),()=>{Z=!0}},[h,s,v,b]),{file:s,isLoading:S,isError:T,isSupportedFile:C,activeHighlightIndex:g,zoom:p,setZoom:I,zoomSelectOptions:k,viewerApiRef:n,showLoader:!T&&(!!S||d),changeIndex:B,handleZoomChange:H,handleViewerReady:M}},ie=({fileUrl:a,fileName:r,errorLabel:u,occurrencesLabel:l,unsupportedLabel:m,highlights:c,loadFileCb:h,showOccurrences:v=!0,selectedPageNumber:N,containerClassName:d,pdfViewerClassName:y,onTotalPagesChange:f,title:n,thumbnailPageNumbers:b,onThumbnailsLoaded:D,onViewerReady:g,showLoaderOverlay:E=!1,selectedPages:T,selectedHighlightId:O,viewerOptions:S})=>{const{file:j,isError:s,isSupportedFile:x,activeHighlightIndex:p,zoom:I,setZoom:C,zoomSelectOptions:B,showLoader:H,changeIndex:k,handleZoomChange:M,handleViewerReady:q}=ae({fileUrl:a,fileName:r,loadFileCb:h,highlights:c,selectedPageNumber:N,onTotalPagesChange:f,thumbnailPageNumbers:b,onThumbnailsLoaded:D,onViewerReady:g,showLoaderOverlay:E,selectedPages:T});return e.jsxs("div",{className:i.mergeClasses("flex flex-col self-center gap-4 py-3 px-6 h-full w-full bg-layer-2",d),children:[r&&e.jsx("div",{className:"shrink-0 min-h-0 w-full",children:e.jsx(i.DialEllipsisTooltip,{className:"dial-tiny-text text-secondary",text:r})}),e.jsxs("div",{className:i.mergeClasses("flex w-full justify-between items-center",v&&n?"gap-2":""),children:[e.jsx("div",{children:v?e.jsxs("div",{className:"flex gap-1 py-0.5 px-1.5 min-h-[26px] items-center bg-layer-4 rounded w-fit",children:[e.jsxs("span",{className:"dial-small-text",children:[l??"Occurrences",":",e.jsx("span",{className:"pl-0.5 min-w-3 inline-block text-right",children:c.length>0?`${p+1}/${c.length}`:"0"})]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(i.DialButton,{className:"p-0 text-primary !h-6.5",size:i.ElementSize.Small,iconAfter:e.jsx(z.IconChevronDown,{size:16}),"aria-label":"Next occurrence",onClick:()=>k(1)}),e.jsx(i.DialButton,{className:"p-0 text-primary !h-6.5",size:i.ElementSize.Small,iconAfter:e.jsx(z.IconChevronUp,{size:16}),"aria-label":"Previous occurrence",onClick:()=>k(-1)})]})]}):e.jsx("div",{})}),e.jsxs("div",{className:i.mergeClasses("flex flex-1 items-center gap-4 min-w-0",n!=null&&n!==""?"justify-between":"justify-end"),children:[n!=null&&n!==""&&e.jsx(i.DialEllipsisTooltip,{text:n,className:"dial-body-semi-text text-primary min-w-0"}),e.jsxs("div",{className:"flex gap-0.5 items-center shrink-0",children:[e.jsx("div",{className:"h-6",children:e.jsx(i.DialSelect,{size:i.SelectSize.Sm,className:"bg-layer-4 !py-0 h-6 min-h-6 dial-small-text max-h-full border-transparent hover:border-hover rounded",options:B,value:I,onChange:o=>C(o)})}),e.jsx(i.DialButton,{className:"py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",iconAfter:e.jsx(z.IconMinus,{size:16}),"aria-label":"Zoom out",size:i.ElementSize.Small,onClick:()=>M(-1)}),e.jsx(i.DialButton,{className:"py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",iconAfter:e.jsx(z.IconPlus,{size:16}),"aria-label":"Zoom in",size:i.ElementSize.Small,onClick:()=>M(1)})]})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[j&&e.jsx(X,{pdf:j,highlights:c,selectedHighlightId:v?c[p]?.id:O,selectedPageNumber:N,zoom:I,onTotalPagesChange:f,onViewerReady:q,containerClassName:y,selectedPages:T,viewerOptions:S}),H&&e.jsx(Y,{className:"absolute inset-0 z-10"}),s&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-layer-3",children:e.jsxs("div",{className:"flex flex-col items-center gap-6 p-10",children:[e.jsx(z.IconAlertTriangle,{size:60,stroke:2,className:"text-secondary"}),e.jsx("div",{className:"text-center dial-small-text whitespace-pre-wrap",children:!x&&m?m:u??"Failed to load document."})]})})]})]})},ue=1200*1e3,me=20,de=({children:a,ttlMs:r=ue,maxEntries:u=me})=>{const l=t.useRef(new Map),m=t.useCallback((d,y)=>{l.current.delete(d),l.current.set(d,y)},[]),c=t.useCallback(()=>{const d=Date.now();for(const[y,f]of l.current.entries())f.file&&d-f.timestamp>r&&l.current.delete(y)},[r]),h=t.useCallback(()=>{for(;l.current.size>u;){const d=l.current.keys().next().value;d&&l.current.delete(d)}},[u]),v=t.useCallback(()=>{l.current.clear()},[]),N=t.useCallback(async(d,y)=>{c();const f=l.current.get(d);if(f){if(m(d,{...f,timestamp:Date.now()}),f.file)return f.file;if(f.promise)return f.promise}const n=Date.now(),b=y().then(g=>{const E={file:g,timestamp:Date.now()};return m(d,E),h(),g}).catch(g=>{throw l.current.delete(d),g});return m(d,{promise:b,timestamp:n}),h(),b},[h,c,m]);return t.useEffect(()=>()=>v(),[v]),e.jsx(J.Provider,{value:{getFile:N,clearCache:v},children:a})},fe=({pageNum:a,onSelectPage:r,isSelected:u,isLoading:l,isMultiselect:m,thumbnailUrl:c,className:h})=>e.jsxs("button",{type:"button","aria-label":`Page ${a}`,"aria-pressed":u,onClick:v=>{m&&v.target.closest("[data-checkbox-wrapper]")||r(a)},className:i.mergeClasses("flex flex-col gap-2 p-2 h-[186px] w-[120px] items-center justify-center cursor-pointer transition-colors hover:bg-layer-4 rounded-sm",u&&(m?"border border-accent-primary bg-accent-primary-alpha":"border border-primary"),h),children:[e.jsxs("div",{className:"relative w-[104px] h-[146px] bg-model-icon rounded-sm overflow-hidden",children:[c?e.jsx("img",{src:c,alt:`Page ${a} thumbnail`,className:"w-full h-full object-cover rounded-sm"}):null,m&&e.jsx("div",{className:"absolute left-1 top-1 z-10","data-checkbox-wrapper":!0,children:e.jsx(i.DialCheckbox,{id:`page-thumbnail-${a}`,checked:u,onChange:()=>r(a),className:"before:border-primary before:bg-model-icon bg-model-icon"})}),l&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-blackout rounded-sm",children:e.jsx(i.DialLoader,{size:24,fullWidth:!1,ariaLabel:`Loading page ${a}`})})]}),e.jsx("span",{className:"dial-tiny-text text-primary",children:a})]});Object.defineProperty(exports,"RotationDirection",{enumerable:!0,get:()=>F.RotationDirection});exports.AUTO_ZOOM_ID=R;exports.DocumentPreview=ie;exports.DocumentPreviewCacheProvider=de;exports.FIT_ZOOM_ID=L;exports.PDFViewer=X;exports.PageThumbnail=fe;exports.PdfPreviewLoader=Y;exports.THUMBNAIL_BATCH_SIZE=$;exports.THUMBNAIL_IMAGE_OPTIONS=W;exports.ZOOM_OPTIONS=V;exports.getStepZoomOptionValue=ee;exports.isPdfFile=te;exports.useDocumentPreview=ae;exports.useDocumentPreviewCache=Q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("@epam/ai-dial-ui-kit"),F=require("@epam/pdf-highlighter-kit"),t=require("react"),z=require("@tabler/icons-react"),R="auto",L="page-fit",V=[{value:R,label:"Auto"},{value:L,label:"Page Fit"},{value:"0.5",label:"50%"},{value:"0.75",label:"75%"},{value:"1",label:"100%"},{value:"1.25",label:"125%"},{value:"1.5",label:"150%"},{value:"2",label:"200%"},{value:"3",label:"300%"}],X={maxWidth:104,format:"image/jpeg",quality:.85},$=15,le="application/pdf",oe=".pdf",Y=({pdf:s,highlights:r,selectedHighlightId:u,autoFocusFirstHighlight:l=!1,selectedPageNumber:m,zoom:i,containerClassName:h,onTotalPagesChange:v,onViewerReady:N,selectedPages:d,viewerOptions:w})=>{const f=t.useRef(null),n=t.useRef(null),[b,E]=t.useState(!1),[y,D]=t.useState(!1),T=t.useRef(v),O=t.useRef(N),I=t.useRef(w);t.useEffect(()=>{T.current=v},[v]),t.useEffect(()=>{O.current=N},[N]),t.useEffect(()=>{I.current=w},[w]);const j=t.useCallback(a=>n.current?.goToHighlight(a),[]);return t.useEffect(()=>{if(!f.current)return;E(!1),D(!1),n.current&&(n.current.destroy(),n.current=null);let a=null,x=!0;const p=()=>{x&&D(!0)};return(async()=>{try{if(a=new F.PDFHighlightViewer,await a.init(f.current,{enableTextSelection:!0,enableVirtualScrolling:!0,bboxOrigin:"top-left",...I.current}),!x){a.destroy();return}if(a.addEventListener("zoomChanged",p),await a.loadPDF(s,{selectedPages:d}),!x){a.destroy();return}const C=a.getTotalPages?.();typeof C=="number"&&C>0&&T.current?.(C),x&&(n.current=a,E(!0))}catch(C){if(!x)return;console.error("Error in initViewer:",C)}})(),()=>{x=!1,a&&(a.removeEventListener("zoomChanged",p),a.destroy())}},[s,d]),t.useEffect(()=>{!b||!n.current||(n.current.loadHighlights(r),l&&r&&r[0]&&j(r[0].id))},[l,j,r,b]),t.useEffect(()=>{b&&y&&u&&j(u)},[j,b,y,u]),t.useEffect(()=>{if(!(!b||!i))if(i===R)n.current?.setZoom?.(F.ZoomMode.AUTO);else if(i===L)n.current?.setZoom?.(F.ZoomMode.PAGE_FIT);else{const a=parseFloat(i);!Number.isNaN(a)&&a>0&&n.current?.setZoom?.(a)}},[b,i]),t.useEffect(()=>{b&&m&&n.current?.setPage?.(m)},[b,m]),t.useEffect(()=>{if(!b||!n.current)return;const a=n.current;O.current?.({getThumbnailsDataUrl:(x,p)=>a.getThumbnailsDataUrl(x,p),zoomIn:()=>a.zoomIn(),zoomOut:()=>a.zoomOut(),getZoom:()=>a.getZoom(),navigateToPage:x=>a.setPage?.(x),setPageDisplayRotation:(x,p,S)=>a.setPageDisplayRotation(x,p,S),getPageDisplayRotation:x=>a.getPageDisplayRotation(x)})},[b]),e.jsx("div",{ref:f,className:c.mergeClasses("grow min-w-0 overflow-auto bg-layer-3",h)})},P="h-4 rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave",J=({className:s,ariaLabel:r="pdf preview loading"})=>e.jsx("div",{role:"status","aria-label":r,"aria-live":"polite",className:c.mergeClasses("h-full w-full bg-layer-3",s),children:e.jsxs("div",{className:"flex h-full w-full flex-col gap-10 px-[60px] pt-10",children:[e.jsx("div",{className:"mx-auto h-4 w-[208px] max-w-[40%] rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:c.mergeClasses(P,"w-[28%] max-w-[320px]")})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:P}),e.jsx("div",{className:c.mergeClasses(P,"w-[58%] max-w-[520px]")})]})]})}),Q=t.createContext(null),ee=()=>t.useContext(Q),_=V.filter(({value:s})=>{const r=Number.parseFloat(s);return!Number.isNaN(r)&&r>0}),ie=[..._].reverse(),te=(s,r,u)=>{if(_.length===0)return s;const l=Number.parseFloat(s),m=!Number.isNaN(l)&&l>0?l:u,i=typeof m=="number"&&m>0?m:Number.parseFloat(_[0].value);return r===1?(_.find(({value:h})=>Number.parseFloat(h)>i)??_[_.length-1]).value:(ie.find(({value:h})=>Number.parseFloat(h)<i)??_[0]).value};function q(s,r){const u=(s??"").toLowerCase();return(r??"").toLowerCase()===le||u.endsWith(oe)}const W=V.map(s=>({value:s.value,label:s.label})),se=({fileUrl:s,fileName:r,loadFileCb:u,highlights:l,selectedPageNumber:m,onTotalPagesChange:i,thumbnailPageNumbers:h,onThumbnailsLoaded:v,onViewerReady:N,showLoaderOverlay:d=!1,selectedPages:w})=>{const f=ee(),n=t.useRef(null),[b,E]=t.useState(!1),[y,D]=t.useState(0),[T,O]=t.useState(!1),[I,j]=t.useState(null),[a,x]=t.useState(null),[p,S]=t.useState(R),C=t.useMemo(()=>{if(r)return q(r.toLowerCase());let o;try{o=new URL(s).pathname}catch{o=s.split("?")[0].split("#")[0]}const g=o.split("/").pop()??"";return!g.includes(".")||q(g.toLowerCase())},[r,s]),B=t.useCallback(o=>{D((y+o+l.length)%l.length)},[y,l.length]),U=t.useCallback(o=>{const g=n.current;!g?.getZoom||!o||S(te(p,o,g.getZoom()))},[p]),k=t.useMemo(()=>{if(!(p===R||p===L||V.some(g=>g.value===p))){const g=parseFloat(p);if(!Number.isNaN(g)&&g>0)return[...W,{value:p,label:`${Math.round(g*100)}%`}]}return W},[p]);t.useEffect(()=>{let o=!1;if(j(!0),O(!1),x(null),E(!1),n.current=null,!C){O(!0),j(!1);return}return(async()=>{try{const Z=await(f?f.getFile(s,()=>u(s)):u(s));o||x(Z)}catch{o||(O(!0),x(null))}finally{o||j(!1)}})(),()=>{o=!0}},[s,f,u,C]);const M=t.useCallback(o=>{n.current=o,E(!0),N?.(o)},[N]);return t.useEffect(()=>{const o=h??[],g=n.current?.getThumbnailsDataUrl;if(!o.length||!g||!a||!v||!b)return;let Z=!1;return(async()=>{const K=new Map;for(let A=0;A<o.length&&!Z;A+=$){const ae=o.slice(A,A+$);try{const H=await g(ae,X);if(Z)break;H.forEach((re,ne)=>K.set(ne,re)),v(new Map(K))}catch(H){console.warn("Thumbnail batch load failed:",H);break}}})(),()=>{Z=!0}},[h,a,v,b]),{file:a,isLoading:I,isError:T,isSupportedFile:C,activeHighlightIndex:y,zoom:p,setZoom:S,zoomSelectOptions:k,viewerApiRef:n,showLoader:!T&&(!!I||d),changeIndex:B,handleZoomChange:U,handleViewerReady:M}},ce=({fileUrl:s,fileName:r,errorLabel:u,occurrencesLabel:l,unsupportedLabel:m,highlights:i,loadFileCb:h,showOccurrences:v=!0,selectedPageNumber:N,containerClassName:d,pdfViewerClassName:w,onTotalPagesChange:f,title:n,thumbnailPageNumbers:b,onThumbnailsLoaded:E,onViewerReady:y,showLoaderOverlay:D=!1,selectedPages:T,selectedHighlightId:O,viewerOptions:I})=>{const{file:j,isError:a,isSupportedFile:x,activeHighlightIndex:p,zoom:S,setZoom:C,zoomSelectOptions:B,showLoader:U,changeIndex:k,handleZoomChange:M,handleViewerReady:G}=se({fileUrl:s,fileName:r,loadFileCb:h,highlights:i,selectedPageNumber:N,onTotalPagesChange:f,thumbnailPageNumbers:b,onThumbnailsLoaded:E,onViewerReady:y,showLoaderOverlay:D,selectedPages:T});return e.jsxs("div",{className:c.mergeClasses("flex flex-col self-center gap-4 py-3 px-6 h-full w-full bg-layer-2",d),children:[r&&e.jsx("div",{className:"shrink-0 min-h-0 w-full",children:e.jsx(c.DialEllipsisTooltip,{className:"dial-tiny-text text-secondary",text:r})}),e.jsxs("div",{className:c.mergeClasses("flex w-full justify-between items-center",v&&n?"gap-2":""),children:[e.jsx("div",{children:v?e.jsxs("div",{className:"flex gap-1 py-0.5 px-1.5 min-h-[26px] items-center bg-layer-4 rounded w-fit",children:[e.jsxs("span",{className:"dial-small-text",children:[l??"Occurrences",":",e.jsx("span",{className:"pl-0.5 min-w-3 inline-block text-right",children:i.length>0?`${p+1}/${i.length}`:"0"})]}),i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(c.DialButton,{className:"p-0 text-primary !h-6.5",size:c.ElementSize.Small,iconAfter:e.jsx(z.IconChevronDown,{size:16}),"aria-label":"Next occurrence",onClick:()=>k(1)}),e.jsx(c.DialButton,{className:"p-0 text-primary !h-6.5",size:c.ElementSize.Small,iconAfter:e.jsx(z.IconChevronUp,{size:16}),"aria-label":"Previous occurrence",onClick:()=>k(-1)})]})]}):e.jsx("div",{})}),e.jsxs("div",{className:c.mergeClasses("flex flex-1 items-center gap-4 min-w-0",n!=null&&n!==""?"justify-between":"justify-end"),children:[n!=null&&n!==""&&e.jsx(c.DialEllipsisTooltip,{text:n,className:"dial-body-semi-text text-primary min-w-0"}),e.jsxs("div",{className:"flex gap-0.5 items-center shrink-0",children:[e.jsx("div",{className:"h-6",children:e.jsx(c.DialSelect,{size:c.SelectSize.Sm,className:"bg-layer-4 !py-0 h-6 min-h-6 dial-small-text max-h-full border-transparent hover:border-hover rounded",options:B,value:S,onChange:o=>C(o)})}),e.jsx(c.DialButton,{className:"py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",iconAfter:e.jsx(z.IconMinus,{size:16}),"aria-label":"Zoom out",size:c.ElementSize.Small,onClick:()=>M(-1)}),e.jsx(c.DialButton,{className:"py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",iconAfter:e.jsx(z.IconPlus,{size:16}),"aria-label":"Zoom in",size:c.ElementSize.Small,onClick:()=>M(1)})]})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[j&&e.jsx(Y,{pdf:j,highlights:i,selectedHighlightId:v?i[p]?.id:O,selectedPageNumber:N,zoom:S,onTotalPagesChange:f,onViewerReady:G,containerClassName:w,selectedPages:T,viewerOptions:I}),U&&e.jsx(J,{className:"absolute inset-0 z-10"}),a&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-layer-3",children:e.jsxs("div",{className:"flex flex-col items-center gap-6 p-10",children:[e.jsx(z.IconAlertTriangle,{size:60,stroke:2,className:"text-secondary"}),e.jsx("div",{className:"text-center dial-small-text whitespace-pre-wrap",children:!x&&m?m:u??"Failed to load document."})]})})]})]})},ue=1200*1e3,me=20,de=({children:s,ttlMs:r=ue,maxEntries:u=me})=>{const l=t.useRef(new Map),m=t.useCallback((d,w)=>{l.current.delete(d),l.current.set(d,w)},[]),i=t.useCallback(()=>{const d=Date.now();for(const[w,f]of l.current.entries())f.file&&d-f.timestamp>r&&l.current.delete(w)},[r]),h=t.useCallback(()=>{for(;l.current.size>u;){const d=l.current.keys().next().value;d&&l.current.delete(d)}},[u]),v=t.useCallback(()=>{l.current.clear()},[]),N=t.useCallback(async(d,w)=>{i();const f=l.current.get(d);if(f){if(m(d,{...f,timestamp:Date.now()}),f.file)return f.file;if(f.promise)return f.promise}const n=Date.now(),b=w().then(y=>{const D={file:y,timestamp:Date.now()};return m(d,D),h(),y}).catch(y=>{throw l.current.delete(d),y});return m(d,{promise:b,timestamp:n}),h(),b},[h,i,m]);return t.useEffect(()=>()=>v(),[v]),e.jsx(Q.Provider,{value:{getFile:N,clearCache:v},children:s})},fe=({pageNum:s,onSelectPage:r,isSelected:u,isLoading:l,isMultiselect:m,thumbnailUrl:i,className:h})=>e.jsxs("button",{type:"button","aria-label":`Page ${s}`,"aria-pressed":u,onClick:v=>{m&&v.target.closest("[data-checkbox-wrapper]")||r(s)},className:c.mergeClasses("flex flex-col gap-2 p-2 h-[186px] w-[120px] items-center justify-center cursor-pointer transition-colors hover:bg-layer-4 rounded-sm",u&&(m?"border border-accent-primary bg-accent-primary-alpha":"border border-primary"),h),children:[e.jsxs("div",{className:"relative w-[104px] h-[146px] bg-model-icon rounded-sm overflow-hidden",children:[i?e.jsx("img",{src:i,alt:`Page ${s} thumbnail`,className:"w-full h-full object-cover rounded-sm"}):null,m&&e.jsx("div",{className:"absolute left-1 top-1 z-10","data-checkbox-wrapper":!0,children:e.jsx(c.DialCheckbox,{id:`page-thumbnail-${s}`,checked:u,onChange:()=>r(s),className:"before:border-primary before:bg-model-icon bg-model-icon"})}),l&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-blackout rounded-sm",children:e.jsx(c.DialLoader,{size:24,fullWidth:!1,ariaLabel:`Loading page ${s}`})})]}),e.jsx("span",{className:"dial-tiny-text text-primary",children:s})]});Object.defineProperty(exports,"RotationDirection",{enumerable:!0,get:()=>F.RotationDirection});exports.AUTO_ZOOM_ID=R;exports.DocumentPreview=ce;exports.DocumentPreviewCacheProvider=de;exports.FIT_ZOOM_ID=L;exports.PDFViewer=Y;exports.PageThumbnail=fe;exports.PdfPreviewLoader=J;exports.THUMBNAIL_BATCH_SIZE=$;exports.THUMBNAIL_IMAGE_OPTIONS=X;exports.ZOOM_OPTIONS=V;exports.getStepZoomOptionValue=te;exports.isPdfFile=q;exports.useDocumentPreview=se;exports.useDocumentPreviewCache=ee;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
2
|
-
import { mergeClasses as
|
|
3
|
-
import { ZoomMode as J, PDFHighlightViewer as
|
|
1
|
+
import { jsx as e, jsxs as x, Fragment as se } from "react/jsx-runtime";
|
|
2
|
+
import { mergeClasses as Z, DialEllipsisTooltip as Y, DialButton as j, ElementSize as B, DialSelect as ie, SelectSize as ce, DialCheckbox as ue, DialLoader as me } from "@epam/ai-dial-ui-kit";
|
|
3
|
+
import { ZoomMode as J, PDFHighlightViewer as de } from "@epam/pdf-highlighter-kit";
|
|
4
4
|
import { RotationDirection as Be } from "@epam/pdf-highlighter-kit";
|
|
5
|
-
import { useRef as
|
|
6
|
-
import { IconChevronDown as
|
|
7
|
-
const
|
|
8
|
-
{ value:
|
|
5
|
+
import { useRef as L, useState as S, useEffect as w, useCallback as D, createContext as fe, useContext as pe, useMemo as Q } from "react";
|
|
6
|
+
import { IconChevronDown as he, IconChevronUp as ve, IconMinus as be, IconPlus as xe, IconAlertTriangle as ge } from "@tabler/icons-react";
|
|
7
|
+
const U = "auto", G = "page-fit", X = [
|
|
8
|
+
{ value: U, label: "Auto" },
|
|
9
9
|
{ value: G, label: "Page Fit" },
|
|
10
10
|
{ value: "0.5", label: "50%" },
|
|
11
11
|
{ value: "0.75", label: "75%" },
|
|
@@ -14,31 +14,31 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
14
14
|
{ value: "1.5", label: "150%" },
|
|
15
15
|
{ value: "2", label: "200%" },
|
|
16
16
|
{ value: "3", label: "300%" }
|
|
17
|
-
],
|
|
17
|
+
], ye = {
|
|
18
18
|
maxWidth: 104,
|
|
19
19
|
format: "image/jpeg",
|
|
20
20
|
quality: 0.85
|
|
21
|
-
}, ee = 15,
|
|
21
|
+
}, ee = 15, we = "application/pdf", Ne = ".pdf", Ce = ({
|
|
22
22
|
pdf: t,
|
|
23
23
|
highlights: a,
|
|
24
|
-
selectedHighlightId:
|
|
24
|
+
selectedHighlightId: i,
|
|
25
25
|
autoFocusFirstHighlight: o = !1,
|
|
26
|
-
selectedPageNumber:
|
|
26
|
+
selectedPageNumber: c,
|
|
27
27
|
zoom: s,
|
|
28
|
-
containerClassName:
|
|
29
|
-
onTotalPagesChange:
|
|
28
|
+
containerClassName: v,
|
|
29
|
+
onTotalPagesChange: h,
|
|
30
30
|
onViewerReady: N,
|
|
31
31
|
selectedPages: u,
|
|
32
|
-
viewerOptions:
|
|
32
|
+
viewerOptions: y
|
|
33
33
|
}) => {
|
|
34
|
-
const m =
|
|
34
|
+
const m = L(null), n = L(null), [p, I] = S(!1), [g, _] = S(!1), E = L(h), O = L(N), R = L(y);
|
|
35
35
|
w(() => {
|
|
36
|
-
|
|
37
|
-
}, [
|
|
38
|
-
|
|
36
|
+
E.current = h;
|
|
37
|
+
}, [h]), w(() => {
|
|
38
|
+
O.current = N;
|
|
39
39
|
}, [N]), w(() => {
|
|
40
|
-
R.current =
|
|
41
|
-
}, [
|
|
40
|
+
R.current = y;
|
|
41
|
+
}, [y]);
|
|
42
42
|
const C = D(
|
|
43
43
|
(r) => n.current?.goToHighlight(r),
|
|
44
44
|
[]
|
|
@@ -52,7 +52,7 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
52
52
|
};
|
|
53
53
|
return (async () => {
|
|
54
54
|
try {
|
|
55
|
-
if (r = new
|
|
55
|
+
if (r = new de(), await r.init(m.current, {
|
|
56
56
|
enableTextSelection: !0,
|
|
57
57
|
enableVirtualScrolling: !0,
|
|
58
58
|
bboxOrigin: "top-left",
|
|
@@ -66,7 +66,7 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
const P = r.getTotalPages?.();
|
|
69
|
-
typeof P == "number" && P > 0 &&
|
|
69
|
+
typeof P == "number" && P > 0 && E.current?.(P), d && (n.current = r, I(!0));
|
|
70
70
|
} catch (P) {
|
|
71
71
|
if (!d)
|
|
72
72
|
return;
|
|
@@ -78,10 +78,10 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
78
78
|
}, [t, u]), w(() => {
|
|
79
79
|
!p || !n.current || (n.current.loadHighlights(a), o && a && a[0] && C(a[0].id));
|
|
80
80
|
}, [o, C, a, p]), w(() => {
|
|
81
|
-
p &&
|
|
82
|
-
}, [C, p,
|
|
81
|
+
p && g && i && C(i);
|
|
82
|
+
}, [C, p, g, i]), w(() => {
|
|
83
83
|
if (!(!p || !s))
|
|
84
|
-
if (s ===
|
|
84
|
+
if (s === U)
|
|
85
85
|
n.current?.setZoom?.(J.AUTO);
|
|
86
86
|
else if (s === G)
|
|
87
87
|
n.current?.setZoom?.(J.PAGE_FIT);
|
|
@@ -90,30 +90,30 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
90
90
|
!Number.isNaN(r) && r > 0 && n.current?.setZoom?.(r);
|
|
91
91
|
}
|
|
92
92
|
}, [p, s]), w(() => {
|
|
93
|
-
p &&
|
|
94
|
-
}, [p,
|
|
93
|
+
p && c && n.current?.setPage?.(c);
|
|
94
|
+
}, [p, c]), w(() => {
|
|
95
95
|
if (!p || !n.current) return;
|
|
96
96
|
const r = n.current;
|
|
97
|
-
|
|
97
|
+
O.current?.({
|
|
98
98
|
getThumbnailsDataUrl: (d, f) => r.getThumbnailsDataUrl(d, f),
|
|
99
99
|
zoomIn: () => r.zoomIn(),
|
|
100
100
|
zoomOut: () => r.zoomOut(),
|
|
101
101
|
getZoom: () => r.getZoom(),
|
|
102
102
|
navigateToPage: (d) => r.setPage?.(d),
|
|
103
|
-
setPageDisplayRotation: (d, f,
|
|
103
|
+
setPageDisplayRotation: (d, f, z) => r.setPageDisplayRotation(d, f, z),
|
|
104
104
|
getPageDisplayRotation: (d) => r.getPageDisplayRotation(d)
|
|
105
105
|
});
|
|
106
106
|
}, [p]), /* @__PURE__ */ e(
|
|
107
107
|
"div",
|
|
108
108
|
{
|
|
109
109
|
ref: m,
|
|
110
|
-
className:
|
|
110
|
+
className: Z(
|
|
111
111
|
"grow min-w-0 overflow-auto bg-layer-3",
|
|
112
|
-
|
|
112
|
+
v
|
|
113
113
|
)
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
-
}, T = "h-4 rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave",
|
|
116
|
+
}, T = "h-4 rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave", Pe = ({
|
|
117
117
|
className: t,
|
|
118
118
|
ariaLabel: a = "pdf preview loading"
|
|
119
119
|
}) => /* @__PURE__ */ e(
|
|
@@ -122,10 +122,10 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
122
122
|
role: "status",
|
|
123
123
|
"aria-label": a,
|
|
124
124
|
"aria-live": "polite",
|
|
125
|
-
className:
|
|
126
|
-
children: /* @__PURE__ */
|
|
125
|
+
className: Z("h-full w-full bg-layer-3", t),
|
|
126
|
+
children: /* @__PURE__ */ x("div", { className: "flex h-full w-full flex-col gap-10 px-[60px] pt-10", children: [
|
|
127
127
|
/* @__PURE__ */ e("div", { className: "mx-auto h-4 w-[208px] max-w-[40%] rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave" }),
|
|
128
|
-
/* @__PURE__ */
|
|
128
|
+
/* @__PURE__ */ x("div", { className: "flex flex-col gap-4", children: [
|
|
129
129
|
/* @__PURE__ */ e("div", { className: T }),
|
|
130
130
|
/* @__PURE__ */ e("div", { className: T }),
|
|
131
131
|
/* @__PURE__ */ e("div", { className: T }),
|
|
@@ -133,14 +133,14 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
133
133
|
/* @__PURE__ */ e(
|
|
134
134
|
"div",
|
|
135
135
|
{
|
|
136
|
-
className:
|
|
136
|
+
className: Z(
|
|
137
137
|
T,
|
|
138
138
|
"w-[28%] max-w-[320px]"
|
|
139
139
|
)
|
|
140
140
|
}
|
|
141
141
|
)
|
|
142
142
|
] }),
|
|
143
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ x("div", { className: "flex flex-col gap-4", children: [
|
|
144
144
|
/* @__PURE__ */ e("div", { className: T }),
|
|
145
145
|
/* @__PURE__ */ e("div", { className: T }),
|
|
146
146
|
/* @__PURE__ */ e("div", { className: T }),
|
|
@@ -148,7 +148,7 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
148
148
|
/* @__PURE__ */ e(
|
|
149
149
|
"div",
|
|
150
150
|
{
|
|
151
|
-
className:
|
|
151
|
+
className: Z(
|
|
152
152
|
T,
|
|
153
153
|
"w-[58%] max-w-[520px]"
|
|
154
154
|
)
|
|
@@ -157,91 +157,93 @@ const $ = "auto", G = "page-fit", X = [
|
|
|
157
157
|
] })
|
|
158
158
|
] })
|
|
159
159
|
}
|
|
160
|
-
),
|
|
160
|
+
), ae = fe(null), Te = () => pe(ae), F = X.filter(({ value: t }) => {
|
|
161
161
|
const a = Number.parseFloat(t);
|
|
162
162
|
return !Number.isNaN(a) && a > 0;
|
|
163
|
-
}),
|
|
163
|
+
}), De = [...F].reverse(), Ie = (t, a, i) => {
|
|
164
164
|
if (F.length === 0)
|
|
165
165
|
return t;
|
|
166
|
-
const o = Number.parseFloat(t),
|
|
166
|
+
const o = Number.parseFloat(t), c = !Number.isNaN(o) && o > 0 ? o : i, s = typeof c == "number" && c > 0 ? c : Number.parseFloat(F[0].value);
|
|
167
167
|
return a === 1 ? (F.find(
|
|
168
|
-
({ value:
|
|
169
|
-
) ?? F[F.length - 1]).value : (
|
|
170
|
-
({ value:
|
|
168
|
+
({ value: v }) => Number.parseFloat(v) > s
|
|
169
|
+
) ?? F[F.length - 1]).value : (De.find(
|
|
170
|
+
({ value: v }) => Number.parseFloat(v) < s
|
|
171
171
|
) ?? F[0]).value;
|
|
172
172
|
};
|
|
173
|
-
function
|
|
174
|
-
const
|
|
175
|
-
return (a ?? "").toLowerCase() ===
|
|
173
|
+
function te(t, a) {
|
|
174
|
+
const i = (t ?? "").toLowerCase();
|
|
175
|
+
return (a ?? "").toLowerCase() === we || i.endsWith(Ne);
|
|
176
176
|
}
|
|
177
|
-
const
|
|
177
|
+
const re = X.map((t) => ({
|
|
178
178
|
value: t.value,
|
|
179
179
|
label: t.label
|
|
180
180
|
})), _e = ({
|
|
181
181
|
fileUrl: t,
|
|
182
182
|
fileName: a,
|
|
183
|
-
loadFileCb:
|
|
183
|
+
loadFileCb: i,
|
|
184
184
|
highlights: o,
|
|
185
|
-
selectedPageNumber:
|
|
185
|
+
selectedPageNumber: c,
|
|
186
186
|
onTotalPagesChange: s,
|
|
187
|
-
thumbnailPageNumbers:
|
|
188
|
-
onThumbnailsLoaded:
|
|
187
|
+
thumbnailPageNumbers: v,
|
|
188
|
+
onThumbnailsLoaded: h,
|
|
189
189
|
onViewerReady: N,
|
|
190
190
|
showLoaderOverlay: u = !1,
|
|
191
|
-
selectedPages:
|
|
191
|
+
selectedPages: y
|
|
192
192
|
}) => {
|
|
193
|
-
const m =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
193
|
+
const m = Te(), n = L(null), [p, I] = S(!1), [g, _] = S(0), [E, O] = S(!1), [R, C] = S(null), [r, d] = S(null), [f, z] = S(U), P = Q(() => {
|
|
194
|
+
if (a)
|
|
195
|
+
return te(a.toLowerCase());
|
|
196
|
+
let l;
|
|
197
|
+
try {
|
|
198
|
+
l = new URL(t).pathname;
|
|
199
|
+
} catch {
|
|
200
|
+
l = t.split("?")[0].split("#")[0];
|
|
201
|
+
}
|
|
202
|
+
const b = l.split("/").pop() ?? "";
|
|
203
|
+
return !b.includes(".") || te(b.toLowerCase());
|
|
204
|
+
}, [a, t]), $ = D(
|
|
203
205
|
(l) => {
|
|
204
206
|
_(
|
|
205
|
-
(
|
|
207
|
+
(g + l + o.length) % o.length
|
|
206
208
|
);
|
|
207
209
|
},
|
|
208
|
-
[
|
|
209
|
-
),
|
|
210
|
+
[g, o.length]
|
|
211
|
+
), H = D(
|
|
210
212
|
(l) => {
|
|
211
|
-
const
|
|
212
|
-
!
|
|
213
|
+
const b = n.current;
|
|
214
|
+
!b?.getZoom || !l || z(Ie(f, l, b.getZoom()));
|
|
213
215
|
},
|
|
214
216
|
[f]
|
|
215
217
|
), A = Q(() => {
|
|
216
|
-
if (!(f ===
|
|
217
|
-
const
|
|
218
|
-
if (!Number.isNaN(
|
|
218
|
+
if (!(f === U || f === G || X.some((b) => b.value === f))) {
|
|
219
|
+
const b = parseFloat(f);
|
|
220
|
+
if (!Number.isNaN(b) && b > 0)
|
|
219
221
|
return [
|
|
220
|
-
...
|
|
221
|
-
{ value: f, label: `${Math.round(
|
|
222
|
+
...re,
|
|
223
|
+
{ value: f, label: `${Math.round(b * 100)}%` }
|
|
222
224
|
];
|
|
223
225
|
}
|
|
224
|
-
return
|
|
226
|
+
return re;
|
|
225
227
|
}, [f]);
|
|
226
228
|
w(() => {
|
|
227
229
|
let l = !1;
|
|
228
|
-
if (C(!0),
|
|
229
|
-
|
|
230
|
+
if (C(!0), O(!1), d(null), I(!1), n.current = null, !P) {
|
|
231
|
+
O(!0), C(!1);
|
|
230
232
|
return;
|
|
231
233
|
}
|
|
232
234
|
return (async () => {
|
|
233
235
|
try {
|
|
234
|
-
const
|
|
235
|
-
l || d(
|
|
236
|
+
const k = await (m ? m.getFile(t, () => i(t)) : i(t));
|
|
237
|
+
l || d(k);
|
|
236
238
|
} catch {
|
|
237
|
-
l || (
|
|
239
|
+
l || (O(!0), d(null));
|
|
238
240
|
} finally {
|
|
239
241
|
l || C(!1);
|
|
240
242
|
}
|
|
241
243
|
})(), () => {
|
|
242
244
|
l = !0;
|
|
243
245
|
};
|
|
244
|
-
}, [t, m,
|
|
246
|
+
}, [t, m, i, P]);
|
|
245
247
|
const M = D(
|
|
246
248
|
(l) => {
|
|
247
249
|
n.current = l, I(!0), N?.(l);
|
|
@@ -249,61 +251,61 @@ const te = X.map((t) => ({
|
|
|
249
251
|
[N]
|
|
250
252
|
);
|
|
251
253
|
return w(() => {
|
|
252
|
-
const l =
|
|
253
|
-
if (!l.length || !
|
|
254
|
+
const l = v ?? [], b = n.current?.getThumbnailsDataUrl;
|
|
255
|
+
if (!l.length || !b || !r || !h || !p)
|
|
254
256
|
return;
|
|
255
|
-
let
|
|
257
|
+
let k = !1;
|
|
256
258
|
return (async () => {
|
|
257
259
|
const K = /* @__PURE__ */ new Map();
|
|
258
|
-
for (let V = 0; V < l.length && !
|
|
259
|
-
const
|
|
260
|
+
for (let V = 0; V < l.length && !k; V += ee) {
|
|
261
|
+
const ne = l.slice(V, V + ee);
|
|
260
262
|
try {
|
|
261
|
-
const W = await
|
|
262
|
-
if (
|
|
263
|
-
W.forEach((
|
|
263
|
+
const W = await b(ne, ye);
|
|
264
|
+
if (k) break;
|
|
265
|
+
W.forEach((oe, le) => K.set(le, oe)), h(new Map(K));
|
|
264
266
|
} catch (W) {
|
|
265
267
|
console.warn("Thumbnail batch load failed:", W);
|
|
266
268
|
break;
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
271
|
})(), () => {
|
|
270
|
-
|
|
272
|
+
k = !0;
|
|
271
273
|
};
|
|
272
|
-
}, [
|
|
274
|
+
}, [v, r, h, p]), {
|
|
273
275
|
file: r,
|
|
274
276
|
isLoading: R,
|
|
275
|
-
isError:
|
|
277
|
+
isError: E,
|
|
276
278
|
isSupportedFile: P,
|
|
277
|
-
activeHighlightIndex:
|
|
279
|
+
activeHighlightIndex: g,
|
|
278
280
|
zoom: f,
|
|
279
|
-
setZoom:
|
|
281
|
+
setZoom: z,
|
|
280
282
|
zoomSelectOptions: A,
|
|
281
283
|
viewerApiRef: n,
|
|
282
|
-
showLoader: !
|
|
283
|
-
changeIndex:
|
|
284
|
-
handleZoomChange:
|
|
284
|
+
showLoader: !E && (!!R || u),
|
|
285
|
+
changeIndex: $,
|
|
286
|
+
handleZoomChange: H,
|
|
285
287
|
handleViewerReady: M
|
|
286
288
|
};
|
|
287
|
-
},
|
|
289
|
+
}, ke = ({
|
|
288
290
|
fileUrl: t,
|
|
289
291
|
fileName: a,
|
|
290
|
-
errorLabel:
|
|
292
|
+
errorLabel: i,
|
|
291
293
|
occurrencesLabel: o,
|
|
292
|
-
unsupportedLabel:
|
|
294
|
+
unsupportedLabel: c,
|
|
293
295
|
highlights: s,
|
|
294
|
-
loadFileCb:
|
|
295
|
-
showOccurrences:
|
|
296
|
+
loadFileCb: v,
|
|
297
|
+
showOccurrences: h = !0,
|
|
296
298
|
selectedPageNumber: N,
|
|
297
299
|
containerClassName: u,
|
|
298
|
-
pdfViewerClassName:
|
|
300
|
+
pdfViewerClassName: y,
|
|
299
301
|
onTotalPagesChange: m,
|
|
300
302
|
title: n,
|
|
301
303
|
thumbnailPageNumbers: p,
|
|
302
304
|
onThumbnailsLoaded: I,
|
|
303
|
-
onViewerReady:
|
|
305
|
+
onViewerReady: g,
|
|
304
306
|
showLoaderOverlay: _ = !1,
|
|
305
|
-
selectedPages:
|
|
306
|
-
selectedHighlightId:
|
|
307
|
+
selectedPages: E,
|
|
308
|
+
selectedHighlightId: O,
|
|
307
309
|
viewerOptions: R
|
|
308
310
|
}) => {
|
|
309
311
|
const {
|
|
@@ -311,30 +313,30 @@ const te = X.map((t) => ({
|
|
|
311
313
|
isError: r,
|
|
312
314
|
isSupportedFile: d,
|
|
313
315
|
activeHighlightIndex: f,
|
|
314
|
-
zoom:
|
|
316
|
+
zoom: z,
|
|
315
317
|
setZoom: P,
|
|
316
|
-
zoomSelectOptions:
|
|
317
|
-
showLoader:
|
|
318
|
+
zoomSelectOptions: $,
|
|
319
|
+
showLoader: H,
|
|
318
320
|
changeIndex: A,
|
|
319
321
|
handleZoomChange: M,
|
|
320
322
|
handleViewerReady: q
|
|
321
323
|
} = _e({
|
|
322
324
|
fileUrl: t,
|
|
323
325
|
fileName: a,
|
|
324
|
-
loadFileCb:
|
|
326
|
+
loadFileCb: v,
|
|
325
327
|
highlights: s,
|
|
326
328
|
selectedPageNumber: N,
|
|
327
329
|
onTotalPagesChange: m,
|
|
328
330
|
thumbnailPageNumbers: p,
|
|
329
331
|
onThumbnailsLoaded: I,
|
|
330
|
-
onViewerReady:
|
|
332
|
+
onViewerReady: g,
|
|
331
333
|
showLoaderOverlay: _,
|
|
332
|
-
selectedPages:
|
|
334
|
+
selectedPages: E
|
|
333
335
|
});
|
|
334
|
-
return /* @__PURE__ */
|
|
336
|
+
return /* @__PURE__ */ x(
|
|
335
337
|
"div",
|
|
336
338
|
{
|
|
337
|
-
className:
|
|
339
|
+
className: Z(
|
|
338
340
|
"flex flex-col self-center gap-4 py-3 px-6 h-full w-full bg-layer-2",
|
|
339
341
|
u
|
|
340
342
|
),
|
|
@@ -346,27 +348,27 @@ const te = X.map((t) => ({
|
|
|
346
348
|
text: a
|
|
347
349
|
}
|
|
348
350
|
) }),
|
|
349
|
-
/* @__PURE__ */
|
|
351
|
+
/* @__PURE__ */ x(
|
|
350
352
|
"div",
|
|
351
353
|
{
|
|
352
|
-
className:
|
|
354
|
+
className: Z(
|
|
353
355
|
"flex w-full justify-between items-center",
|
|
354
|
-
|
|
356
|
+
h && n ? "gap-2" : ""
|
|
355
357
|
),
|
|
356
358
|
children: [
|
|
357
|
-
/* @__PURE__ */ e("div", { children:
|
|
358
|
-
/* @__PURE__ */
|
|
359
|
+
/* @__PURE__ */ e("div", { children: h ? /* @__PURE__ */ x("div", { className: "flex gap-1 py-0.5 px-1.5 min-h-[26px] items-center bg-layer-4 rounded w-fit", children: [
|
|
360
|
+
/* @__PURE__ */ x("span", { className: "dial-small-text", children: [
|
|
359
361
|
o ?? "Occurrences",
|
|
360
362
|
":",
|
|
361
363
|
/* @__PURE__ */ e("span", { className: "pl-0.5 min-w-3 inline-block text-right", children: s.length > 0 ? `${f + 1}/${s.length}` : "0" })
|
|
362
364
|
] }),
|
|
363
|
-
s.length > 0 && /* @__PURE__ */
|
|
365
|
+
s.length > 0 && /* @__PURE__ */ x(se, { children: [
|
|
364
366
|
/* @__PURE__ */ e(
|
|
365
367
|
j,
|
|
366
368
|
{
|
|
367
369
|
className: "p-0 text-primary !h-6.5",
|
|
368
370
|
size: B.Small,
|
|
369
|
-
iconAfter: /* @__PURE__ */ e(
|
|
371
|
+
iconAfter: /* @__PURE__ */ e(he, { size: 16 }),
|
|
370
372
|
"aria-label": "Next occurrence",
|
|
371
373
|
onClick: () => A(1)
|
|
372
374
|
}
|
|
@@ -383,10 +385,10 @@ const te = X.map((t) => ({
|
|
|
383
385
|
)
|
|
384
386
|
] })
|
|
385
387
|
] }) : /* @__PURE__ */ e("div", {}) }),
|
|
386
|
-
/* @__PURE__ */
|
|
388
|
+
/* @__PURE__ */ x(
|
|
387
389
|
"div",
|
|
388
390
|
{
|
|
389
|
-
className:
|
|
391
|
+
className: Z(
|
|
390
392
|
"flex flex-1 items-center gap-4 min-w-0",
|
|
391
393
|
n != null && n !== "" ? "justify-between" : "justify-end"
|
|
392
394
|
),
|
|
@@ -398,14 +400,14 @@ const te = X.map((t) => ({
|
|
|
398
400
|
className: "dial-body-semi-text text-primary min-w-0"
|
|
399
401
|
}
|
|
400
402
|
),
|
|
401
|
-
/* @__PURE__ */
|
|
403
|
+
/* @__PURE__ */ x("div", { className: "flex gap-0.5 items-center shrink-0", children: [
|
|
402
404
|
/* @__PURE__ */ e("div", { className: "h-6", children: /* @__PURE__ */ e(
|
|
403
|
-
|
|
405
|
+
ie,
|
|
404
406
|
{
|
|
405
407
|
size: ce.Sm,
|
|
406
408
|
className: "bg-layer-4 !py-0 h-6 min-h-6 dial-small-text max-h-full border-transparent hover:border-hover rounded",
|
|
407
|
-
options:
|
|
408
|
-
value:
|
|
409
|
+
options: $,
|
|
410
|
+
value: z,
|
|
409
411
|
onChange: (l) => P(l)
|
|
410
412
|
}
|
|
411
413
|
) }),
|
|
@@ -413,7 +415,7 @@ const te = X.map((t) => ({
|
|
|
413
415
|
j,
|
|
414
416
|
{
|
|
415
417
|
className: "py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",
|
|
416
|
-
iconAfter: /* @__PURE__ */ e(
|
|
418
|
+
iconAfter: /* @__PURE__ */ e(be, { size: 16 }),
|
|
417
419
|
"aria-label": "Zoom out",
|
|
418
420
|
size: B.Small,
|
|
419
421
|
onClick: () => M(-1)
|
|
@@ -423,7 +425,7 @@ const te = X.map((t) => ({
|
|
|
423
425
|
j,
|
|
424
426
|
{
|
|
425
427
|
className: "py-0 flex items-center justify-center rounded text-primary bg-layer-4 border border-transparent hover:border-hover",
|
|
426
|
-
iconAfter: /* @__PURE__ */ e(
|
|
428
|
+
iconAfter: /* @__PURE__ */ e(xe, { size: 16 }),
|
|
427
429
|
"aria-label": "Zoom in",
|
|
428
430
|
size: B.Small,
|
|
429
431
|
onClick: () => M(1)
|
|
@@ -436,101 +438,101 @@ const te = X.map((t) => ({
|
|
|
436
438
|
]
|
|
437
439
|
}
|
|
438
440
|
),
|
|
439
|
-
/* @__PURE__ */
|
|
441
|
+
/* @__PURE__ */ x("div", { className: "relative flex min-h-0 flex-1", children: [
|
|
440
442
|
C && /* @__PURE__ */ e(
|
|
441
|
-
|
|
443
|
+
Ce,
|
|
442
444
|
{
|
|
443
445
|
pdf: C,
|
|
444
446
|
highlights: s,
|
|
445
|
-
selectedHighlightId:
|
|
447
|
+
selectedHighlightId: h ? s[f]?.id : O,
|
|
446
448
|
selectedPageNumber: N,
|
|
447
|
-
zoom:
|
|
449
|
+
zoom: z,
|
|
448
450
|
onTotalPagesChange: m,
|
|
449
451
|
onViewerReady: q,
|
|
450
|
-
containerClassName:
|
|
451
|
-
selectedPages:
|
|
452
|
+
containerClassName: y,
|
|
453
|
+
selectedPages: E,
|
|
452
454
|
viewerOptions: R
|
|
453
455
|
}
|
|
454
456
|
),
|
|
455
|
-
|
|
456
|
-
r && /* @__PURE__ */ e("div", { className: "absolute inset-0 z-20 flex items-center justify-center bg-layer-3", children: /* @__PURE__ */
|
|
457
|
+
H && /* @__PURE__ */ e(Pe, { className: "absolute inset-0 z-10" }),
|
|
458
|
+
r && /* @__PURE__ */ e("div", { className: "absolute inset-0 z-20 flex items-center justify-center bg-layer-3", children: /* @__PURE__ */ x("div", { className: "flex flex-col items-center gap-6 p-10", children: [
|
|
457
459
|
/* @__PURE__ */ e(
|
|
458
|
-
|
|
460
|
+
ge,
|
|
459
461
|
{
|
|
460
462
|
size: 60,
|
|
461
463
|
stroke: 2,
|
|
462
464
|
className: "text-secondary"
|
|
463
465
|
}
|
|
464
466
|
),
|
|
465
|
-
/* @__PURE__ */ e("div", { className: "text-center dial-small-text whitespace-pre-wrap", children: !d &&
|
|
467
|
+
/* @__PURE__ */ e("div", { className: "text-center dial-small-text whitespace-pre-wrap", children: !d && c ? c : i ?? "Failed to load document." })
|
|
466
468
|
] }) })
|
|
467
469
|
] })
|
|
468
470
|
]
|
|
469
471
|
}
|
|
470
472
|
);
|
|
471
|
-
},
|
|
473
|
+
}, Ee = 1200 * 1e3, Oe = 20, Ae = ({
|
|
472
474
|
children: t,
|
|
473
|
-
ttlMs: a =
|
|
474
|
-
maxEntries:
|
|
475
|
+
ttlMs: a = Ee,
|
|
476
|
+
maxEntries: i = Oe
|
|
475
477
|
}) => {
|
|
476
|
-
const o =
|
|
477
|
-
o.current.delete(u), o.current.set(u,
|
|
478
|
+
const o = L(/* @__PURE__ */ new Map()), c = D((u, y) => {
|
|
479
|
+
o.current.delete(u), o.current.set(u, y);
|
|
478
480
|
}, []), s = D(() => {
|
|
479
481
|
const u = Date.now();
|
|
480
|
-
for (const [
|
|
481
|
-
m.file && u - m.timestamp > a && o.current.delete(
|
|
482
|
-
}, [a]),
|
|
483
|
-
for (; o.current.size >
|
|
482
|
+
for (const [y, m] of o.current.entries())
|
|
483
|
+
m.file && u - m.timestamp > a && o.current.delete(y);
|
|
484
|
+
}, [a]), v = D(() => {
|
|
485
|
+
for (; o.current.size > i; ) {
|
|
484
486
|
const u = o.current.keys().next().value;
|
|
485
487
|
u && o.current.delete(u);
|
|
486
488
|
}
|
|
487
|
-
}, [
|
|
489
|
+
}, [i]), h = D(() => {
|
|
488
490
|
o.current.clear();
|
|
489
491
|
}, []), N = D(
|
|
490
|
-
async (u,
|
|
492
|
+
async (u, y) => {
|
|
491
493
|
s();
|
|
492
494
|
const m = o.current.get(u);
|
|
493
495
|
if (m) {
|
|
494
|
-
if (
|
|
496
|
+
if (c(u, { ...m, timestamp: Date.now() }), m.file)
|
|
495
497
|
return m.file;
|
|
496
498
|
if (m.promise)
|
|
497
499
|
return m.promise;
|
|
498
500
|
}
|
|
499
|
-
const n = Date.now(), p =
|
|
500
|
-
const _ = { file:
|
|
501
|
-
return
|
|
502
|
-
}).catch((
|
|
503
|
-
throw o.current.delete(u),
|
|
501
|
+
const n = Date.now(), p = y().then((g) => {
|
|
502
|
+
const _ = { file: g, timestamp: Date.now() };
|
|
503
|
+
return c(u, _), v(), g;
|
|
504
|
+
}).catch((g) => {
|
|
505
|
+
throw o.current.delete(u), g;
|
|
504
506
|
});
|
|
505
|
-
return
|
|
507
|
+
return c(u, { promise: p, timestamp: n }), v(), p;
|
|
506
508
|
},
|
|
507
|
-
[
|
|
509
|
+
[v, s, c]
|
|
508
510
|
);
|
|
509
|
-
return w(() => () =>
|
|
511
|
+
return w(() => () => h(), [h]), /* @__PURE__ */ e(ae.Provider, { value: { getFile: N, clearCache: h }, children: t });
|
|
510
512
|
}, Me = ({
|
|
511
513
|
pageNum: t,
|
|
512
514
|
onSelectPage: a,
|
|
513
|
-
isSelected:
|
|
515
|
+
isSelected: i,
|
|
514
516
|
isLoading: o,
|
|
515
|
-
isMultiselect:
|
|
517
|
+
isMultiselect: c,
|
|
516
518
|
thumbnailUrl: s,
|
|
517
|
-
className:
|
|
518
|
-
}) => /* @__PURE__ */
|
|
519
|
+
className: v
|
|
520
|
+
}) => /* @__PURE__ */ x(
|
|
519
521
|
"button",
|
|
520
522
|
{
|
|
521
523
|
type: "button",
|
|
522
524
|
"aria-label": `Page ${t}`,
|
|
523
|
-
"aria-pressed":
|
|
524
|
-
onClick: (
|
|
525
|
-
|
|
525
|
+
"aria-pressed": i,
|
|
526
|
+
onClick: (h) => {
|
|
527
|
+
c && h.target.closest("[data-checkbox-wrapper]") || a(t);
|
|
526
528
|
},
|
|
527
|
-
className:
|
|
529
|
+
className: Z(
|
|
528
530
|
"flex flex-col gap-2 p-2 h-[186px] w-[120px] items-center justify-center cursor-pointer transition-colors hover:bg-layer-4 rounded-sm",
|
|
529
|
-
|
|
530
|
-
|
|
531
|
+
i && (c ? "border border-accent-primary bg-accent-primary-alpha" : "border border-primary"),
|
|
532
|
+
v
|
|
531
533
|
),
|
|
532
534
|
children: [
|
|
533
|
-
/* @__PURE__ */
|
|
535
|
+
/* @__PURE__ */ x("div", { className: "relative w-[104px] h-[146px] bg-model-icon rounded-sm overflow-hidden", children: [
|
|
534
536
|
s ? /* @__PURE__ */ e(
|
|
535
537
|
"img",
|
|
536
538
|
{
|
|
@@ -539,17 +541,17 @@ const te = X.map((t) => ({
|
|
|
539
541
|
className: "w-full h-full object-cover rounded-sm"
|
|
540
542
|
}
|
|
541
543
|
) : null,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
+
c && /* @__PURE__ */ e("div", { className: "absolute left-1 top-1 z-10", "data-checkbox-wrapper": !0, children: /* @__PURE__ */ e(
|
|
545
|
+
ue,
|
|
544
546
|
{
|
|
545
547
|
id: `page-thumbnail-${t}`,
|
|
546
|
-
checked:
|
|
548
|
+
checked: i,
|
|
547
549
|
onChange: () => a(t),
|
|
548
550
|
className: "before:border-primary before:bg-model-icon bg-model-icon"
|
|
549
551
|
}
|
|
550
552
|
) }),
|
|
551
553
|
o && /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center bg-blackout rounded-sm", children: /* @__PURE__ */ e(
|
|
552
|
-
|
|
554
|
+
me,
|
|
553
555
|
{
|
|
554
556
|
size: 24,
|
|
555
557
|
fullWidth: !1,
|
|
@@ -562,19 +564,19 @@ const te = X.map((t) => ({
|
|
|
562
564
|
}
|
|
563
565
|
);
|
|
564
566
|
export {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
+
U as AUTO_ZOOM_ID,
|
|
568
|
+
ke as DocumentPreview,
|
|
567
569
|
Ae as DocumentPreviewCacheProvider,
|
|
568
570
|
G as FIT_ZOOM_ID,
|
|
569
|
-
|
|
571
|
+
Ce as PDFViewer,
|
|
570
572
|
Me as PageThumbnail,
|
|
571
|
-
|
|
573
|
+
Pe as PdfPreviewLoader,
|
|
572
574
|
Be as RotationDirection,
|
|
573
575
|
ee as THUMBNAIL_BATCH_SIZE,
|
|
574
|
-
|
|
576
|
+
ye as THUMBNAIL_IMAGE_OPTIONS,
|
|
575
577
|
X as ZOOM_OPTIONS,
|
|
576
|
-
|
|
577
|
-
|
|
578
|
+
Ie as getStepZoomOptionValue,
|
|
579
|
+
te as isPdfFile,
|
|
578
580
|
_e as useDocumentPreview,
|
|
579
|
-
|
|
581
|
+
Te as useDocumentPreviewCache
|
|
580
582
|
};
|
package/package.json
CHANGED