@epam/ai-dial-react-pdf-highlighter 0.2.0-dev.37 → 0.2.0-dev.38

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