@epam/ai-dial-react-pdf-highlighter 0.2.0-dev.1 → 0.2.0-dev.11

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