@epam/ai-dial-react-pdf-highlighter 0.1.0-rc.0

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.
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Work or Derivative
98
+ Works that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work, excluding
100
+ those notices that do not pertain to any part of the Derivative
101
+ Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the attribution
105
+ notices contained within such NOTICE file, in one of the following
106
+ places: within a NOTICE text file distributed as part of the
107
+ Derivative Works; within the Source form or documentation, if
108
+ provided along with the Derivative Works; or, within a display
109
+ generated by the Derivative Works, if and wherever such
110
+ third-party notices normally appear. The contents of the NOTICE
111
+ file are for informational purposes only and do not modify the
112
+ License. You may add Your own attribution notices within Derivative
113
+ Works that You distribute, alongside or as an addendum to the NOTICE
114
+ text from the Work, provided that such additional attribution notices
115
+ cannot be construed as modifying the License.
116
+
117
+ You may add Your own license statement for Your modifications and may
118
+ provide additional grant of rights to use, copy, modify, and distribute
119
+ those modifications and rights in such additional grants,
120
+ provided Your use of the Work is not for commercial purposes or is not
121
+ combined with other works distributed under this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
137
+ to in writing, Licensor provides the Work (and each Contributor
138
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
139
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
140
+ without limitation, any warranties of condition, merchantability,
141
+ fitness for a particular purpose and noninfringement. In no event and
142
+ under no legal theory, whether in tort (including negligence), contract,
143
+ or otherwise, unless required by applicable law (such as deliberate and
144
+ grossly negligent acts) or agreed to in writing, shall any Contributor
145
+ be liable to You for damages, including any direct, indirect, special,
146
+ incidental, or exemplary damages of any character arising as a result of
147
+ this License or out of the use or inability to use the Work (including
148
+ but not limited to damages for loss of goodwill, work stoppage, computer
149
+ failure or malfunction, or all other commercial damages or losses), even
150
+ if such Contributor has been advised of the possibility of such damages.
151
+
152
+ 8. Accepting Warranty or Additional Liability. While redistributing
153
+ the Work or Derivative Works thereof, You may choose to offer, and
154
+ charge a fee for, acceptance of support, warranty, indemnity, or other
155
+ liability obligations and/or rights consistent with this License.
156
+ However, in accepting such obligations, You may offer only conditions
157
+ on Your own behalf and on behalf of all other Contributors, subject to
158
+ the conditions applicable to them. You may additionally state that you
159
+ impose restrictions on your behalf on the applicable Contributors.
160
+
161
+ 9. By accepting the terms and conditions of this License, you agree to
162
+ be bound by all terms and conditions of Apache License Version 2.0.
163
+
164
+ Copyright 2024 EPAM Systems
165
+
166
+ Licensed under the Apache License, Version 2.0 (the "License");
167
+ you may not use this file except in compliance with the License.
168
+ You may obtain a copy of the License at
169
+
170
+ http://www.apache.org/licenses/LICENSE-2.0
171
+
172
+ Unless required by applicable law or agreed to in writing, software
173
+ distributed under the License is distributed on an "AS IS" BASIS,
174
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ See the License for the specific language governing permissions and
176
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # @epam/ai-dial-react-pdf-highlighter
2
+
3
+ AI DIAL React PDF Highlighter is a React component library for PDF viewing and highlights.
4
+ It builds on top of [@epam/pdf-highlighter-kit](https://github.com/epam/pdf-highlighter-kit)
5
+ and uses [@epam/ai-dial-ui-kit](https://github.com/epam/ai-dial-ui-kit) styles and components.
6
+
7
+ Part of the [AI DIAL ecosystem](https://github.com/epam/ai-dial).
8
+
9
+ [![npm version](https://badge.fury.io/js/@epam%2Fai-dial-react-pdf-highlighter.svg)](https://badge.fury.io/js/@epam%2Fai-dial-react-pdf-highlighter)
10
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
11
+
12
+ ## Table of Contents
13
+
14
+ - [Highlights](#highlights)
15
+ - [Documentation](#documentation)
16
+ - [Quick Start](#quick-start)
17
+ - [Prerequisites](#prerequisites)
18
+ - [Installation](#installation)
19
+ - [Peer Dependencies](#peer-dependencies)
20
+ - [Basic Usage](#basic-usage)
21
+ - [Exported API](#exported-api)
22
+ - [Styles](#styles)
23
+ - [Development](#development)
24
+ - [Setup](#setup)
25
+ - [Quality Checks](#quality-checks)
26
+ - [Storybook](#storybook)
27
+ - [Usage in Projects](#usage-in-projects)
28
+ - [Next.js](#nextjs)
29
+ - [Contributing](#contributing)
30
+ - [Security](#security)
31
+ - [License](#license)
32
+
33
+ ## Highlights
34
+
35
+ - React components for PDF viewing, thumbnailing, and highlights
36
+ - Higher-level API over pdf-highlighter-kit
37
+ - Built with TypeScript and strict typing
38
+ - Storybook + Vitest test setup
39
+ - Ready to publish and consume as an npm package
40
+
41
+ ## Documentation
42
+
43
+ You can explore components in Storybook during local development.
44
+
45
+ ```bash
46
+ npm run storybook
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### Prerequisites
52
+
53
+ - Node.js >= 22.2.0
54
+ - npm >= 10.7.0
55
+
56
+ ### Installation
57
+
58
+ ```bash
59
+ npm install @epam/ai-dial-react-pdf-highlighter
60
+ ```
61
+
62
+ ### Peer Dependencies
63
+
64
+ ```bash
65
+ npm install react react-dom \
66
+ @epam/ai-dial-ui-kit \
67
+ @epam/pdf-highlighter-kit \
68
+ @tabler/icons-react \
69
+ pdfjs-dist
70
+ ```
71
+
72
+ Your `pdfjs-dist` version should satisfy [pdf-highlighter-kit requirements](https://github.com/epam/pdf-highlighter-kit?tab=readme-ov-file#requirements).
73
+
74
+ ### Basic Usage
75
+
76
+ ```tsx
77
+ import {
78
+ DocumentPreview,
79
+ DocumentPreviewCacheProvider,
80
+ } from '@epam/ai-dial-react-pdf-highlighter';
81
+ import '@epam/ai-dial-ui-kit/styles.css';
82
+ import '@epam/ai-dial-react-pdf-highlighter/styles.css';
83
+
84
+ function App() {
85
+ return (
86
+ <DocumentPreviewCacheProvider>
87
+ <DocumentPreview
88
+ fileUrl="https://example.com/document.pdf"
89
+ loadFileCb={(url) => fetch(url).then((response) => response.blob())}
90
+ highlights={[]}
91
+ />
92
+ </DocumentPreviewCacheProvider>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ## Exported API
98
+
99
+ ### Components
100
+
101
+ | Name | Description |
102
+ | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
103
+ | `PDFViewer` | Low-level PDF viewer component wrapping `@epam/pdf-highlighter-kit`. Accepts `PdfViewerProps`. |
104
+ | `DocumentPreview` | High-level document preview with built-in loading, zoom, highlight navigation, and thumbnail support. Accepts `DocumentPreviewProps`. |
105
+ | `DocumentPreviewCacheProvider` | Context provider that enables cross-component sharing of loaded PDF blobs. Wrap your app (or subtree) with this to avoid re-fetching the same files. |
106
+ | `PdfPreviewLoader` | Standalone loading/error state overlay used internally by `DocumentPreview`. Accepts `PdfPreviewLoaderProps`. |
107
+ | `PageThumbnail` | Renders a single PDF page as a thumbnail image. Accepts `PageThumbnailProps`. |
108
+
109
+ ### Hooks
110
+
111
+ #### `useDocumentPreview(options: UseDocumentPreviewOptions): UseDocumentPreviewResult`
112
+
113
+ Encapsulates all logic for a document preview: file fetching (with optional cache integration), highlight-index navigation, zoom state, and thumbnail generation. Use it to build a fully custom preview UI without taking on `DocumentPreview`'s default layout.
114
+
115
+ #### `useDocumentPreviewCache(): DocumentPreviewCacheContext | null`
116
+
117
+ Returns the document preview cache context provided by `DocumentPreviewCacheProvider`. Returns `null` when called outside the provider. Consumed internally by `useDocumentPreview` to avoid re-fetching files already in the cache.
118
+
119
+ ## Styles
120
+
121
+ Import both stylesheets in your app entry point:
122
+
123
+ ```ts
124
+ import '@epam/ai-dial-ui-kit/styles.css';
125
+ import '@epam/ai-dial-react-pdf-highlighter/styles.css';
126
+ ```
127
+
128
+ ## Development
129
+
130
+ ### Setup
131
+
132
+ ```bash
133
+ git clone https://github.com/epam/ai-dial-react-pdf-highlighter.git
134
+ cd ai-dial-react-pdf-highlighter
135
+ npm install
136
+ ```
137
+
138
+ Useful commands:
139
+
140
+ ```bash
141
+ npm run dev
142
+ npm run storybook
143
+ npm run test:run
144
+ npm run test
145
+ ```
146
+
147
+ ### Quality Checks
148
+
149
+ Before opening a PR, run:
150
+
151
+ ```bash
152
+ npm run typecheck
153
+ npm run lint:check
154
+ npm run test:run
155
+ ```
156
+
157
+ Or run the combined check:
158
+
159
+ ```bash
160
+ npm run verify:agent-hook
161
+ ```
162
+
163
+ ## Storybook
164
+
165
+ Development mode:
166
+
167
+ ```bash
168
+ npm run storybook
169
+ ```
170
+
171
+ Production build:
172
+
173
+ ```bash
174
+ npm run build-storybook
175
+ ```
176
+
177
+ ## Usage in Projects
178
+
179
+ ### Next.js
180
+
181
+ In some cases, PDF-related UI works only with dynamic imports on the client side.
182
+ If you hit SSR issues, load viewer components with `next/dynamic` and `ssr: false`.
183
+
184
+ ## Contributing
185
+
186
+ Please read the [contributing guide](./CONTRIBUTING.md).
187
+
188
+ ## Security
189
+
190
+ If you find a vulnerability, please read our [security policy](./SECURITY.md).
191
+
192
+ ## License
193
+
194
+ [Apache 2.0](./LICENSE) © EPAM Systems
@@ -0,0 +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"),Z="auto",A="page-fit",L=[{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%"}],K={maxWidth:104,format:"image/jpeg",quality:.85},$=15,ne="application/pdf",le=".pdf",W=({pdf:s,highlights:a,selectedHighlightId:m,autoFocusFirstHighlight:n=!1,selectedPageNumber:d,zoom:c,containerClassName:x,onTotalPagesChange:p,onViewerReady:y,selectedPages:f})=>{const h=t.useRef(null),r=t.useRef(null),[o,C]=t.useState(!1),[I,v]=t.useState(!1),P=t.useRef(p),E=t.useRef(y);t.useEffect(()=>{P.current=p},[p]),t.useEffect(()=>{E.current=y},[y]);const N=t.useCallback(l=>r.current?.goToHighlight(l),[]);return t.useEffect(()=>{if(!h.current)return;C(!1),v(!1),r.current&&(r.current.destroy(),r.current=null);let l=null,b=!0;return(async()=>{try{if(l=new U.PDFHighlightViewer,await l.init(h.current,{enableTextSelection:!0,enableVirtualScrolling:!0,bboxOrigin:"top-left"}),!b){l.destroy();return}if(await l.loadPDF(s,{selectedPages:f}),!b){l.destroy();return}const g=l.getTotalPages?.();typeof g=="number"&&g>0&&P.current?.(g),b&&(r.current=l,C(!0))}catch(g){if(!b)return;console.error("Error in initViewer:",g)}})(),()=>{b=!1,l&&l.destroy()}},[s,f]),t.useEffect(()=>{!o||!r.current||(r.current.loadHighlights(a),n&&a&&a[0]&&N(a[0].id))},[n,N,a,o]),t.useEffect(()=>{v(!0)},[a]),t.useEffect(()=>{o&&I&&m&&N(m)},[N,o,I,m]),t.useEffect(()=>{if(!(!o||!c))if(c===Z)r.current?.setZoom?.(U.ZoomMode.AUTO);else if(c===A)r.current?.setZoom?.(U.ZoomMode.PAGE_FIT);else{const l=parseFloat(c);!Number.isNaN(l)&&l>0&&r.current?.setZoom?.(l)}},[o,c]),t.useEffect(()=>{o&&d&&r.current?.setPage?.(d)},[o,d]),t.useEffect(()=>{if(!o||!r.current)return;const l=r.current;E.current?.({getThumbnailsDataUrl:(b,T)=>l.getThumbnailsDataUrl(b,T),zoomIn:()=>l.zoomIn(),zoomOut:()=>l.zoomOut(),getZoom:()=>l.getZoom(),navigateToPage:b=>l.setPage?.(b)})},[o]),e.jsx("div",{ref:h,className:i.mergeClasses("grow min-w-0 overflow-auto bg-layer-3",x)})},O="h-4 rounded-[120px] bg-gradient-to-r from-layer-4 via-layer-3 to-layer-4 bg-[length:200%_100%] animate-skeleton-wave",X=({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:O}),e.jsx("div",{className:O}),e.jsx("div",{className:O}),e.jsx("div",{className:O}),e.jsx("div",{className:i.mergeClasses(O,"w-[28%] max-w-[320px]")})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:O}),e.jsx("div",{className:O}),e.jsx("div",{className:O}),e.jsx("div",{className:O}),e.jsx("div",{className:i.mergeClasses(O,"w-[58%] max-w-[520px]")})]})]})}),Y=t.createContext(null),J=()=>t.useContext(Y),S=L.filter(({value:s})=>{const a=Number.parseFloat(s);return!Number.isNaN(a)&&a>0}),oe=[...S].reverse(),Q=(s,a,m)=>{if(S.length===0)return s;const n=Number.parseFloat(s),d=!Number.isNaN(n)&&n>0?n:m,c=typeof d=="number"&&d>0?d:Number.parseFloat(S[0].value);return a===1?(S.find(({value:x})=>Number.parseFloat(x)>c)??S[S.length-1]).value:(oe.find(({value:x})=>Number.parseFloat(x)<c)??S[0]).value};function ee(s,a){const m=(s??"").toLowerCase();return(a??"").toLowerCase()===ne||m.endsWith(le)}const G=L.map(s=>({value:s.value,label:s.label})),te=({fileUrl:s,fileName:a,loadFileCb:m,highlights:n,selectedPageNumber:d,onTotalPagesChange:c,thumbnailPageNumbers:x,onThumbnailsLoaded:p,onViewerReady:y,showLoaderOverlay:f=!1,selectedPages:h})=>{const r=J(),o=t.useRef(null),[C,I]=t.useState(!1),[v,P]=t.useState(0),[E,N]=t.useState(!1),[l,b]=t.useState(null),[T,g]=t.useState(null),[j,k]=t.useState(Z),D=t.useMemo(()=>{let u=a||s;if(!a)try{u=new URL(s).pathname}catch{u=s.split("?")[0].split("#")[0]}return ee(u.toLowerCase())},[a,s]),M=t.useCallback(u=>{P((v+u+n.length)%n.length)},[v,n.length]),F=t.useCallback(u=>{const w=o.current;!w?.getZoom||!u||k(Q(j,u,w.getZoom()))},[j]),V=t.useMemo(()=>{if(!(j===Z||j===A||L.some(w=>w.value===j))){const w=parseFloat(j);if(!Number.isNaN(w)&&w>0)return[...G,{value:j,label:`${Math.round(w*100)}%`}]}return G},[j]);t.useEffect(()=>{let u=!1;if(b(!0),N(!1),g(null),I(!1),o.current=null,!D){N(!0),b(!1);return}return(async()=>{try{const _=await(r?r.getFile(s,()=>m(s)):m(s));u||g(_)}catch{u||(N(!0),g(null))}finally{u||b(!1)}})(),()=>{u=!0}},[s,r,m,D]);const B=t.useCallback(u=>{o.current=u,I(!0),y?.(u)},[y]);return t.useEffect(()=>{const u=x??[],w=o.current?.getThumbnailsDataUrl;if(!u.length||!w||!T||!p||!C)return;let _=!1;return(async()=>{const q=new Map;for(let R=0;R<u.length&&!_;R+=$){const se=u.slice(R,R+$);try{const H=await w(se,K);if(_)break;H.forEach((re,ae)=>q.set(ae,re)),p(new Map(q))}catch(H){console.warn("Thumbnail batch load failed:",H);break}}})(),()=>{_=!0}},[x,T,p,C]),{file:T,isLoading:l,isError:E,isSupportedFile:D,activeHighlightIndex:v,zoom:j,setZoom:k,zoomSelectOptions:V,viewerApiRef:o,showLoader:!E&&(!!l||f),changeIndex:M,handleZoomChange:F,handleViewerReady:B}},ce=({fileUrl:s,fileName:a,errorLabel:m,occurrencesLabel:n,unsupportedLabel:d,highlights:c,loadFileCb:x,showOccurrences:p=!0,selectedPageNumber:y,containerClassName:f,pdfViewerClassName:h,onTotalPagesChange:r,title:o,thumbnailPageNumbers:C,onThumbnailsLoaded:I,onViewerReady:v,showLoaderOverlay:P=!1,selectedPages:E})=>{const{file:N,isError:l,isSupportedFile:b,activeHighlightIndex:T,zoom:g,setZoom:j,zoomSelectOptions:k,showLoader:D,changeIndex:M,handleZoomChange:F,handleViewerReady:V}=te({fileUrl:s,fileName:a,loadFileCb:x,highlights:c,selectedPageNumber:y,onTotalPagesChange:r,thumbnailPageNumbers:C,onThumbnailsLoaded:I,onViewerReady:v,showLoaderOverlay:P,selectedPages:E});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",f),children:[a&&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&&o?"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:[n??"Occurrences",":",e.jsx("span",{className:"pl-0.5 min-w-3 inline-block text-right",children:c.length>0?`${T+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",o!=null&&o!==""?"justify-between":"justify-end"),children:[o!=null&&o!==""&&e.jsx(i.DialEllipsisTooltip,{text:o,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:k,value:g,onChange:B=>j(B)})}),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:()=>F(-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:()=>F(1)})]})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[N&&e.jsx(W,{pdf:N,highlights:c,selectedHighlightId:c[T]?.id,selectedPageNumber:y,zoom:g,onTotalPagesChange:r,onViewerReady:V,containerClassName:h,selectedPages:E}),D&&e.jsx(X,{className:"absolute inset-0 z-10"}),l&&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:!b&&d?d:m??"Failed to load document."})]})})]})]})},ie=1200*1e3,ue=20,me=({children:s,ttlMs:a=ie,maxEntries:m=ue})=>{const n=t.useRef(new Map),d=t.useCallback((f,h)=>{n.current.delete(f),n.current.set(f,h)},[]),c=t.useCallback(()=>{const f=Date.now();for(const[h,r]of n.current.entries())r.file&&f-r.timestamp>a&&n.current.delete(h)},[a]),x=t.useCallback(()=>{for(;n.current.size>m;){const f=n.current.keys().next().value;f&&n.current.delete(f)}},[m]),p=t.useCallback(()=>{n.current.clear()},[]),y=t.useCallback(async(f,h)=>{c();const r=n.current.get(f);if(r){if(d(f,{...r,timestamp:Date.now()}),r.file)return r.file;if(r.promise)return r.promise}const o=Date.now(),C=h().then(v=>{const P={file:v,timestamp:Date.now()};return d(f,P),x(),v}).catch(v=>{throw n.current.delete(f),v});return d(f,{promise:C,timestamp:o}),x(),C},[x,c,d]);return t.useEffect(()=>()=>p(),[p]),e.jsx(Y.Provider,{value:{getFile:y,clearCache:p},children:s})},de=({pageNum:s,onSelectPage:a,isSelected:m,isLoading:n,isMultiselect:d,thumbnailUrl:c,className:x})=>e.jsxs("button",{type:"button","aria-label":`Page ${s}`,"aria-pressed":m,onClick:p=>{d&&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",m&&(d?"border border-accent-primary bg-accent-primary-alpha":"border border-primary"),x),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,d&&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:m,onChange:()=>a(s),className:"before:border-primary before:bg-model-icon bg-model-icon"})}),n&&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=Z;exports.DocumentPreview=ce;exports.DocumentPreviewCacheProvider=me;exports.FIT_ZOOM_ID=A;exports.PDFViewer=W;exports.PageThumbnail=de;exports.PdfPreviewLoader=X;exports.THUMBNAIL_BATCH_SIZE=$;exports.THUMBNAIL_IMAGE_OPTIONS=K;exports.ZOOM_OPTIONS=L;exports.getStepZoomOptionValue=Q;exports.isPdfFile=ee;exports.useDocumentPreview=te;exports.useDocumentPreviewCache=J;