@iamjariwala/react-doc-viewer 1.0.0 → 1.1.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.
Files changed (105) hide show
  1. package/README.md +36 -26
  2. package/dist/DocViewer.d.ts +21 -0
  3. package/dist/components/DocumentNav.d.ts +3 -0
  4. package/dist/components/FileName.d.ts +3 -0
  5. package/dist/components/HeaderBar.d.ts +3 -0
  6. package/dist/components/LoadingTimout.d.ts +3 -0
  7. package/dist/components/ProxyRenderer.d.ts +3 -0
  8. package/dist/components/common/Button.d.ts +13 -0
  9. package/dist/components/common/index.d.ts +1 -0
  10. package/dist/components/icons/index.d.ts +8 -0
  11. package/dist/cssStyles.d.ts +1 -0
  12. package/dist/defaultTheme.d.ts +3 -0
  13. package/dist/empty-DBAFSQIv.cjs +1 -0
  14. package/dist/empty-GlqisfcO.js +4 -0
  15. package/dist/features/annotations/components/AnnotationLayer.d.ts +10 -0
  16. package/dist/features/annotations/components/AnnotationToolbar.d.ts +3 -0
  17. package/dist/features/annotations/components/ColorPicker.d.ts +3 -0
  18. package/dist/features/annotations/components/CommentMarker.d.ts +8 -0
  19. package/dist/features/annotations/components/CommentPopover.d.ts +9 -0
  20. package/dist/features/annotations/components/TextHighlight.d.ts +8 -0
  21. package/dist/features/annotations/components/icons/index.d.ts +13 -0
  22. package/dist/features/annotations/hooks/useAnnotationExport.d.ts +9 -0
  23. package/dist/features/annotations/hooks/useDrawingCanvas.d.ts +15 -0
  24. package/dist/features/annotations/hooks/useTextSelection.d.ts +10 -0
  25. package/dist/features/annotations/index.d.ts +13 -0
  26. package/dist/features/annotations/state/actions.d.ts +52 -0
  27. package/dist/features/annotations/state/index.d.ts +17 -0
  28. package/dist/features/annotations/state/reducer.d.ts +17 -0
  29. package/dist/features/annotations/types/index.d.ts +44 -0
  30. package/dist/features/drag-drop/components/DropZoneOverlay.d.ts +9 -0
  31. package/dist/features/drag-drop/hooks/useDragDrop.d.ts +11 -0
  32. package/dist/features/drag-drop/hooks/useFileProcessor.d.ts +13 -0
  33. package/dist/features/drag-drop/index.d.ts +4 -0
  34. package/dist/features/drag-drop/types/index.d.ts +19 -0
  35. package/dist/features/thumbnail-sidebar/components/ThumbnailItem.d.ts +11 -0
  36. package/dist/features/thumbnail-sidebar/components/ThumbnailSidebar.d.ts +8 -0
  37. package/dist/features/thumbnail-sidebar/components/ThumbnailToggle.d.ts +7 -0
  38. package/dist/features/thumbnail-sidebar/hooks/useThumbnailGenerator.d.ts +13 -0
  39. package/dist/features/thumbnail-sidebar/index.d.ts +6 -0
  40. package/dist/features/thumbnail-sidebar/state/actions.d.ts +31 -0
  41. package/dist/features/thumbnail-sidebar/state/index.d.ts +15 -0
  42. package/dist/features/thumbnail-sidebar/state/reducer.d.ts +11 -0
  43. package/dist/hooks/useDocumentLoader.d.ts +13 -0
  44. package/dist/hooks/useRendererSelector.d.ts +5 -0
  45. package/dist/hooks/useTranslation.d.ts +3 -0
  46. package/dist/hooks/useWindowSize.d.ts +4 -0
  47. package/dist/i18n.d.ts +158 -0
  48. package/dist/index-BRIDmekZ.js +3350 -0
  49. package/dist/index-BbWLdN1j.js +19664 -0
  50. package/dist/index-C5fDV20X.cjs +10 -0
  51. package/dist/index-Dr6cyq4L.js +42 -0
  52. package/dist/index-DtsNvZYP.cjs +1 -0
  53. package/dist/index-J-2Hm65K.cjs +46 -0
  54. package/dist/index.css +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/locales/ar.json.d.ts +13 -0
  57. package/dist/locales/de.json.d.ts +13 -0
  58. package/dist/locales/en.json.d.ts +26 -0
  59. package/dist/locales/es.json.d.ts +13 -0
  60. package/dist/locales/fr.json.d.ts +13 -0
  61. package/dist/locales/it.json.d.ts +13 -0
  62. package/dist/locales/ja.json.d.ts +13 -0
  63. package/dist/locales/pl.json.d.ts +13 -0
  64. package/dist/locales/pt.json.d.ts +13 -0
  65. package/dist/locales/ru.json.d.ts +13 -0
  66. package/dist/locales/se.json.d.ts +13 -0
  67. package/dist/locales/sr.json.d.ts +13 -0
  68. package/dist/locales/sr_cyr.json.d.ts +13 -0
  69. package/dist/locales/tr.json.d.ts +13 -0
  70. package/dist/models.d.ts +119 -0
  71. package/dist/react-doc-viewer.cjs +1 -0
  72. package/dist/react-doc-viewer.js +23 -0
  73. package/dist/renderers/bmp/index.d.ts +4 -0
  74. package/dist/renderers/csv/index.d.ts +4 -0
  75. package/dist/renderers/gif/index.d.ts +4 -0
  76. package/dist/renderers/html/index.d.ts +4 -0
  77. package/dist/renderers/image/index.d.ts +4 -0
  78. package/dist/renderers/index.d.ts +15 -0
  79. package/dist/renderers/jpg/index.d.ts +4 -0
  80. package/dist/renderers/msdoc/index.d.ts +4 -0
  81. package/dist/renderers/pdf/components/PDFControls.d.ts +4 -0
  82. package/dist/renderers/pdf/components/PDFPagination.d.ts +4 -0
  83. package/dist/renderers/pdf/components/PDFThumbnailGenerator.d.ts +3 -0
  84. package/dist/renderers/pdf/components/icons/index.d.ts +9 -0
  85. package/dist/renderers/pdf/components/pages/PDFAllPages.d.ts +7 -0
  86. package/dist/renderers/pdf/components/pages/PDFPages.d.ts +4 -0
  87. package/dist/renderers/pdf/components/pages/PDFSinglePage.d.ts +7 -0
  88. package/dist/renderers/pdf/index.d.ts +4 -0
  89. package/dist/renderers/pdf/state/actions.d.ts +32 -0
  90. package/dist/renderers/pdf/state/index.d.ts +13 -0
  91. package/dist/renderers/pdf/state/reducer.d.ts +15 -0
  92. package/dist/renderers/png/index.d.ts +4 -0
  93. package/dist/renderers/tiff/index.d.ts +4 -0
  94. package/dist/renderers/tiff/tiffToCanvas.d.ts +1 -0
  95. package/dist/renderers/txt/index.d.ts +4 -0
  96. package/dist/renderers/video/index.d.ts +4 -0
  97. package/dist/renderers/webp/index.d.ts +4 -0
  98. package/dist/store/DocViewerProvider.d.ts +22 -0
  99. package/dist/store/actions.d.ts +63 -0
  100. package/dist/store/mainStateReducer.d.ts +23 -0
  101. package/dist/url-5wjrlwUG.js +560 -0
  102. package/dist/url-DLGc3bZT.cjs +3 -0
  103. package/dist/utils/fileLoaders.d.ts +13 -0
  104. package/dist/utils/getFileName.d.ts +3 -0
  105. package/package.json +6 -8
package/README.md CHANGED
@@ -23,7 +23,7 @@ Most React document viewers only handle PDFs or require expensive commercial lic
23
23
  | Feature | @iamjariwala/react-doc-viewer | react-pdf | @cyntler/react-doc-viewer | react-file-viewer |
24
24
  | ------- | :--: | :--: | :--: | :--: |
25
25
  | PDF rendering | Yes | Yes | Yes | Yes |
26
- | Office docs (Word, Excel, PPT) | Yes | -- | Yes | Partial |
26
+ | Office docs (Word, Excel, PPT) | Download card | -- | Yes | Partial |
27
27
  | Images (PNG, JPG, GIF, WebP, TIFF, BMP) | Yes | -- | Yes | Partial |
28
28
  | Video (MP4) | Yes | -- | Yes | Yes |
29
29
  | CSV / TXT / HTML | Yes | -- | Yes | Partial |
@@ -35,7 +35,7 @@ Most React document viewers only handle PDFs or require expensive commercial lic
35
35
  | Custom renderers | Yes | -- | Yes | -- |
36
36
  | Theming | Yes | -- | Yes | -- |
37
37
  | TypeScript | Yes | Yes | Yes | -- |
38
- | Actively maintained (2024+) | Yes | Yes | -- | -- |
38
+ | Actively maintained (2025+) | Yes | Yes | -- | -- |
39
39
  | License | Apache-2.0 | MIT | MIT | MIT |
40
40
 
41
41
  ---
@@ -50,12 +50,13 @@ Most React document viewers only handle PDFs or require expensive commercial lic
50
50
 
51
51
  ---
52
52
 
53
- ### What's New in v0.2.0
53
+ ### What's New in v1.1.0
54
54
 
55
- - **Drag & Drop** -- Drop files directly onto the viewer to add or replace documents
56
- - **Thumbnail Sidebar** -- Visual page navigation with auto-scroll for PDFs
57
- - **Annotations** -- Highlight text, freehand draw, and add comments with export support
58
- - **Page Jump** -- Navigate to any page programmatically via ref or prop
55
+ - **Security: HTML XSS fix** -- HTML renderer now sanitizes content with DOMPurify before rendering
56
+ - **Security: MS Office docs** -- Removed external iframe dependency; Office files now render as download cards with file info
57
+ - **Removed styled-components** -- All styling migrated to plain CSS with CSS custom properties, reducing bundle size
58
+ - **Smaller bundle** -- Removed `styled-components`, `core-js`, and `ajv` dependencies (~300-400KB savings)
59
+ - **CSS custom properties** -- Theming now uses `--rdv-*` CSS variables for full customizability
59
60
 
60
61
  ## Table of Contents
61
62
 
@@ -114,16 +115,16 @@ Most React document viewers only handle PDFs or require expensive commercial lic
114
115
  | txt | `text/plain` | |
115
116
  | htm / html | `text/htm`, `text/html` | |
116
117
  | mp4 | `video/mp4` | |
117
- | doc | `application/msword` | Public URLs only |
118
- | docx | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` | Public URLs only |
119
- | xls | `application/vnd.ms-excel` | Public URLs only |
120
- | xlsx | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` | Public URLs only |
121
- | ppt | `application/vnd.ms-powerpoint` | Public URLs only |
122
- | pptx | `application/vnd.openxmlformats-officedocument.presentationml.presentation` | Public URLs only |
118
+ | doc | `application/msword` | Download card |
119
+ | docx | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` | Download card |
120
+ | xls | `application/vnd.ms-excel` | Download card |
121
+ | xlsx | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` | Download card |
122
+ | ppt | `application/vnd.ms-powerpoint` | Download card |
123
+ | pptx | `application/vnd.openxmlformats-officedocument.presentationml.presentation` | Download card |
123
124
  | odt | `application/vnd.oasis.opendocument.text` | |
124
125
 
125
- > [!IMPORTANT]
126
- > MS Office documents (doc, docx, xls, xlsx, ppt, pptx) use Microsoft's online viewing service via iframe and **require publicly accessible URLs**.
126
+ > [!NOTE]
127
+ > MS Office documents (doc, docx, xls, xlsx, ppt, pptx) render as download cards showing file name, type, and a download link. No external service or public URL is required.
127
128
 
128
129
  ## Live Demo
129
130
 
@@ -580,24 +581,33 @@ Customize the viewer's appearance with a theme object:
580
581
  <DocViewer documents={docs} pluginRenderers={DocViewerRenderers} style={{ width: 500, height: 500 }} />
581
582
  ```
582
583
 
583
- **Styled Components:**
584
+ **Override internal elements with CSS classes:**
584
585
 
585
- ```tsx
586
- import styled from "styled-components";
587
- import DocViewer from "@iamjariwala/react-doc-viewer";
586
+ All internal elements use `.rdv-*` class names that you can target:
588
587
 
589
- const MyDocViewer = styled(DocViewer)`
588
+ ```css
589
+ .rdv-container {
590
590
  border-radius: 10px;
591
- `;
591
+ }
592
592
 
593
- <MyDocViewer documents={docs} />;
593
+ .rdv-header-bar {
594
+ background-color: #faf;
595
+ }
596
+
597
+ .rdv-pdf-controls {
598
+ gap: 12px;
599
+ }
594
600
  ```
595
601
 
596
- **Override internal elements by DOM ID:**
602
+ **Override CSS custom properties:**
603
+
604
+ Theming is powered by CSS variables. Override them on the container or globally:
597
605
 
598
606
  ```css
599
- #react-doc-viewer #header-bar {
600
- background-color: #faf;
607
+ #react-doc-viewer {
608
+ --rdv-primary: #1a1a2e;
609
+ --rdv-secondary: #16213e;
610
+ --rdv-text-primary: #e94560;
601
611
  }
602
612
  ```
603
613
 
@@ -681,7 +691,7 @@ Provide custom headers for authenticated requests:
681
691
  Install `@iamjariwala/react-doc-viewer`, import `DocViewer` and `DocViewerRenderers`, pass your PDF URL as a document, and the component handles rendering, zoom, pagination, and page navigation automatically. See [Quick Start](#quick-start).
682
692
 
683
693
  **Can I view Word, Excel, and PowerPoint files in React?**
684
- Yes. This library renders `.doc`, `.docx`, `.xls`, `.xlsx`, `.ppt`, and `.pptx` files using Microsoft's online viewing service. The files must be accessible via a public URL.
694
+ Yes. This library recognizes `.doc`, `.docx`, `.xls`, `.xlsx`, `.ppt`, and `.pptx` files and renders them as download cards showing file name, type, and a download link. No external service or public URL is required.
685
695
 
686
696
  **Does it support annotations and highlighting?**
687
697
  Yes. Enable annotations via config to get text highlighting, freehand drawing, comments, and an eraser tool. Annotations can be exported as JSON and pre-loaded from saved data. See [Annotations](#annotations).
@@ -0,0 +1,21 @@
1
+ import { default as React, CSSProperties } from 'react';
2
+ import { AvailableLanguages } from './i18n';
3
+ import { DocRenderer, DocViewerRef, IConfig, IDocument, ITheme } from './models';
4
+
5
+ export interface DocViewerProps {
6
+ documents: IDocument[];
7
+ className?: string;
8
+ style?: CSSProperties;
9
+ config?: IConfig;
10
+ theme?: ITheme;
11
+ pluginRenderers?: DocRenderer[];
12
+ prefetchMethod?: string;
13
+ requestHeaders?: Record<string, string>;
14
+ initialActiveDocument?: IDocument;
15
+ language?: AvailableLanguages;
16
+ activeDocument?: IDocument;
17
+ onDocumentChange?: (document: IDocument) => void;
18
+ jumpToPage?: number;
19
+ }
20
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<DocViewerProps & React.RefAttributes<DocViewerRef>>>;
21
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const DocumentNav: FC;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const FileName: FC;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const HeaderBar: FC;
@@ -0,0 +1,3 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+
3
+ export declare const LoadingTimeout: FC<PropsWithChildren>;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const ProxyRenderer: FC;
@@ -0,0 +1,13 @@
1
+ import { FC, ButtonHTMLAttributes, AnchorHTMLAttributes } from 'react';
2
+
3
+ type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
4
+ className?: string;
5
+ };
6
+ export declare const Button: FC<ButtonProps>;
7
+ export declare const ButtonPrimary: FC<ButtonProps>;
8
+ export declare const ButtonSecondary: FC<ButtonProps>;
9
+ type LinkButtonProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
10
+ className?: string;
11
+ };
12
+ export declare const LinkButton: FC<LinkButtonProps>;
13
+ export {};
@@ -0,0 +1 @@
1
+ export * from './Button';
@@ -0,0 +1,8 @@
1
+ export interface IIconProps {
2
+ color?: string;
3
+ size?: string | number | string | undefined;
4
+ reverse?: boolean;
5
+ }
6
+ export declare const PrevDocIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const NextDocIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const LoadingIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,3 @@
1
+ import { ITheme } from '.';
2
+
3
+ export declare const defaultTheme: ITheme;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null;exports.default=e;
@@ -0,0 +1,4 @@
1
+ var a = null;
2
+ export {
3
+ a as default
4
+ };
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+
3
+ interface AnnotationLayerProps {
4
+ pageNumber: number;
5
+ documentUri: string;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export declare const AnnotationLayer: FC<AnnotationLayerProps>;
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const AnnotationToolbar: FC;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare const ColorPicker: FC;
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { IAnnotation } from '../types';
3
+
4
+ interface CommentMarkerProps {
5
+ annotation: IAnnotation;
6
+ }
7
+ export declare const CommentMarker: FC<CommentMarkerProps>;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { IAnnotation } from '../types';
3
+
4
+ interface CommentPopoverProps {
5
+ annotation: IAnnotation;
6
+ onClose: () => void;
7
+ }
8
+ export declare const CommentPopover: FC<CommentPopoverProps>;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { IAnnotation } from '../types';
3
+
4
+ interface TextHighlightProps {
5
+ annotation: IAnnotation;
6
+ }
7
+ export declare const TextHighlight: FC<TextHighlightProps>;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { FC } from 'react';
2
+
3
+ export interface IIconProps {
4
+ color?: string;
5
+ size?: string | number;
6
+ isActive?: boolean;
7
+ }
8
+ export declare const SelectIcon: FC<IIconProps>;
9
+ export declare const HighlightIcon: FC<IIconProps>;
10
+ export declare const PenIcon: FC<IIconProps>;
11
+ export declare const CommentIcon: FC<IIconProps>;
12
+ export declare const EraserIcon: FC<IIconProps>;
13
+ export declare const DeleteIcon: FC<IIconProps>;
@@ -0,0 +1,9 @@
1
+ import { IAnnotation } from '../types';
2
+
3
+ export declare const useAnnotationExport: () => {
4
+ exportAnnotations: () => IAnnotation[];
5
+ exportAsJSON: () => string;
6
+ downloadAnnotations: (filename?: string) => void;
7
+ getAnnotationsForPage: (pageNumber: number, documentUri: string) => IAnnotation[];
8
+ annotationCount: number;
9
+ };
@@ -0,0 +1,15 @@
1
+ import { IAnnotation } from '../types';
2
+
3
+ interface UseDrawingCanvasProps {
4
+ canvasRef: React.RefObject<HTMLCanvasElement>;
5
+ pageNumber: number;
6
+ documentUri: string;
7
+ }
8
+ export declare const useDrawingCanvas: ({ canvasRef, pageNumber, documentUri, }: UseDrawingCanvasProps) => {
9
+ startDrawing: (e: React.MouseEvent<HTMLCanvasElement>) => void;
10
+ draw: (e: React.MouseEvent<HTMLCanvasElement>) => void;
11
+ stopDrawing: () => void;
12
+ redrawAnnotations: (annotations: IAnnotation[]) => void;
13
+ isDrawing: boolean;
14
+ };
15
+ export {};
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ interface UseTextSelectionProps {
3
+ pageNumber: number;
4
+ documentUri: string;
5
+ containerRef: React.RefObject<HTMLDivElement>;
6
+ }
7
+ export declare const useTextSelection: ({ pageNumber, documentUri, containerRef, }: UseTextSelectionProps) => {
8
+ handleTextSelection: () => void;
9
+ };
10
+ export {};
@@ -0,0 +1,13 @@
1
+ export { AnnotationLayer } from './components/AnnotationLayer';
2
+ export { AnnotationToolbar } from './components/AnnotationToolbar';
3
+ export { TextHighlight } from './components/TextHighlight';
4
+ export { CommentMarker } from './components/CommentMarker';
5
+ export { CommentPopover } from './components/CommentPopover';
6
+ export { ColorPicker } from './components/ColorPicker';
7
+ export * from './components/icons';
8
+ export { AnnotationProvider, AnnotationContext } from './state';
9
+ export { useDrawingCanvas } from './hooks/useDrawingCanvas';
10
+ export { useTextSelection } from './hooks/useTextSelection';
11
+ export { useAnnotationExport } from './hooks/useAnnotationExport';
12
+ export * from './state/actions';
13
+ export * from './types';
@@ -0,0 +1,52 @@
1
+ import { AnnotationTool, IAnnotation } from '../types';
2
+
3
+ export declare const SET_ACTIVE_TOOL = "SET_ACTIVE_TOOL";
4
+ export declare const SET_CURRENT_COLOR = "SET_CURRENT_COLOR";
5
+ export declare const ADD_ANNOTATION = "ADD_ANNOTATION";
6
+ export declare const UPDATE_ANNOTATION = "UPDATE_ANNOTATION";
7
+ export declare const DELETE_ANNOTATION = "DELETE_ANNOTATION";
8
+ export declare const SET_ANNOTATIONS = "SET_ANNOTATIONS";
9
+ export declare const SET_SELECTED_ANNOTATION = "SET_SELECTED_ANNOTATION";
10
+ export declare const SET_IS_DRAWING = "SET_IS_DRAWING";
11
+ export interface SetActiveTool {
12
+ type: typeof SET_ACTIVE_TOOL;
13
+ tool: AnnotationTool;
14
+ }
15
+ export declare const setActiveTool: (tool: AnnotationTool) => SetActiveTool;
16
+ export interface SetCurrentColor {
17
+ type: typeof SET_CURRENT_COLOR;
18
+ color: string;
19
+ }
20
+ export declare const setCurrentColor: (color: string) => SetCurrentColor;
21
+ export interface AddAnnotation {
22
+ type: typeof ADD_ANNOTATION;
23
+ annotation: IAnnotation;
24
+ }
25
+ export declare const addAnnotation: (annotation: IAnnotation) => AddAnnotation;
26
+ export interface UpdateAnnotation {
27
+ type: typeof UPDATE_ANNOTATION;
28
+ id: string;
29
+ updates: Partial<IAnnotation>;
30
+ }
31
+ export declare const updateAnnotation: (id: string, updates: Partial<IAnnotation>) => UpdateAnnotation;
32
+ export interface DeleteAnnotation {
33
+ type: typeof DELETE_ANNOTATION;
34
+ id: string;
35
+ }
36
+ export declare const deleteAnnotation: (id: string) => DeleteAnnotation;
37
+ export interface SetAnnotations {
38
+ type: typeof SET_ANNOTATIONS;
39
+ annotations: IAnnotation[];
40
+ }
41
+ export declare const setAnnotations: (annotations: IAnnotation[]) => SetAnnotations;
42
+ export interface SetSelectedAnnotation {
43
+ type: typeof SET_SELECTED_ANNOTATION;
44
+ id: string | null;
45
+ }
46
+ export declare const setSelectedAnnotation: (id: string | null) => SetSelectedAnnotation;
47
+ export interface SetIsDrawing {
48
+ type: typeof SET_IS_DRAWING;
49
+ isDrawing: boolean;
50
+ }
51
+ export declare const setIsDrawing: (isDrawing: boolean) => SetIsDrawing;
52
+ export type AnnotationActions = SetActiveTool | SetCurrentColor | AddAnnotation | UpdateAnnotation | DeleteAnnotation | SetAnnotations | SetSelectedAnnotation | SetIsDrawing;
@@ -0,0 +1,17 @@
1
+ import { default as React, Dispatch, FC, PropsWithChildren } from 'react';
2
+ import { IAnnotationConfig } from '../../../models';
3
+ import { AnnotationActions } from './actions';
4
+ import { IAnnotationState } from './reducer';
5
+
6
+ interface AnnotationContextValue {
7
+ state: IAnnotationState;
8
+ dispatch: Dispatch<AnnotationActions>;
9
+ config?: IAnnotationConfig;
10
+ }
11
+ export declare const AnnotationContext: React.Context<AnnotationContextValue>;
12
+ interface AnnotationProviderProps {
13
+ config?: IAnnotationConfig;
14
+ documentUri?: string;
15
+ }
16
+ export declare const AnnotationProvider: FC<PropsWithChildren<AnnotationProviderProps>>;
17
+ export {};
@@ -0,0 +1,17 @@
1
+ import { AnnotationTool, IAnnotation } from '../types';
2
+ import { AnnotationActions } from './actions';
3
+
4
+ export interface IAnnotationState {
5
+ activeTool: AnnotationTool;
6
+ currentColor: string;
7
+ annotations: IAnnotation[];
8
+ selectedAnnotationId: string | null;
9
+ isDrawing: boolean;
10
+ availableColors: string[];
11
+ availableTools: AnnotationTool[];
12
+ }
13
+ export declare const DEFAULT_COLORS: string[];
14
+ export declare const DEFAULT_TOOLS: AnnotationTool[];
15
+ export declare const initialAnnotationState: IAnnotationState;
16
+ export type AnnotationStateReducer = (state: IAnnotationState, action: AnnotationActions) => IAnnotationState;
17
+ export declare const annotationReducer: AnnotationStateReducer;
@@ -0,0 +1,44 @@
1
+ export type AnnotationTool = "select" | "highlight" | "pen" | "comment" | "eraser";
2
+ export interface IAnnotation {
3
+ id: string;
4
+ type: "highlight" | "drawing" | "comment";
5
+ documentUri: string;
6
+ pageNumber: number;
7
+ color: string;
8
+ data?: IHighlightData | IDrawingData | ICommentData;
9
+ }
10
+ export interface IHighlightData {
11
+ rects: Array<{
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ }>;
17
+ text?: string;
18
+ }
19
+ export interface IDrawingData {
20
+ paths: Array<{
21
+ x: number;
22
+ y: number;
23
+ }[]>;
24
+ strokeWidth: number;
25
+ }
26
+ export interface ICommentData {
27
+ x: number;
28
+ y: number;
29
+ text: string;
30
+ author?: string;
31
+ timestamp?: number;
32
+ }
33
+ export interface IAnnotationConfig {
34
+ enableAnnotations?: boolean;
35
+ defaultColor?: string;
36
+ colors?: string[];
37
+ tools?: AnnotationTool[];
38
+ onAnnotationChange?: (annotations: IAnnotation[]) => void;
39
+ initialAnnotations?: IAnnotation[];
40
+ }
41
+ export interface IPoint {
42
+ x: number;
43
+ y: number;
44
+ }
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { IDragState } from '../types';
3
+
4
+ interface DropZoneOverlayProps {
5
+ dragState: IDragState;
6
+ dropMessage?: string;
7
+ }
8
+ export declare const DropZoneOverlay: FC<DropZoneOverlayProps>;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import { DragEvent } from 'react';
2
+ import { IDragState } from '../types';
3
+
4
+ export declare const useDragDrop: () => {
5
+ dragState: IDragState;
6
+ handleDragEnter: (e: DragEvent<HTMLDivElement>) => void;
7
+ handleDragLeave: (e: DragEvent<HTMLDivElement>) => void;
8
+ handleDragOver: (e: DragEvent<HTMLDivElement>) => void;
9
+ handleDrop: (e: DragEvent<HTMLDivElement>, onFilesDropped: (files: File[]) => void) => void;
10
+ resetDragState: () => void;
11
+ };
@@ -0,0 +1,13 @@
1
+ import { IDocument } from '../../../models';
2
+ import { IDragDropConfig } from '../types';
3
+
4
+ export declare const useFileProcessor: (config?: IDragDropConfig) => {
5
+ processFiles: (files: File[]) => Promise<IDocument[]>;
6
+ validateFiles: (files: File[]) => {
7
+ valid: File[];
8
+ invalidType: File[];
9
+ invalidSize: File[];
10
+ };
11
+ isFileTypeAccepted: (file: File) => boolean;
12
+ isFileSizeValid: (file: File) => boolean;
13
+ };
@@ -0,0 +1,4 @@
1
+ export { DropZoneOverlay } from './components/DropZoneOverlay';
2
+ export { useDragDrop } from './hooks/useDragDrop';
3
+ export { useFileProcessor } from './hooks/useFileProcessor';
4
+ export * from './types';
@@ -0,0 +1,19 @@
1
+ export interface IDragDropConfig {
2
+ enableDragDrop?: boolean;
3
+ acceptedFileTypes?: string[];
4
+ maxFileSize?: number;
5
+ dropBehavior?: "append" | "replace";
6
+ onDrop?: (files: File[]) => void;
7
+ onDropRejected?: (files: File[], reason: DropRejectionReason) => void;
8
+ }
9
+ export type DropRejectionReason = "file-type" | "file-size" | "unknown";
10
+ export interface IDragState {
11
+ isDragging: boolean;
12
+ isOverDropZone: boolean;
13
+ }
14
+ export interface IProcessedFile {
15
+ uri: string;
16
+ fileType: string;
17
+ fileName: string;
18
+ fileData: string;
19
+ }
@@ -0,0 +1,11 @@
1
+ import { FC } from 'react';
2
+ import { IThumbnail } from '../state/actions';
3
+
4
+ interface ThumbnailItemProps {
5
+ thumbnail: IThumbnail;
6
+ isSelected: boolean;
7
+ width: number;
8
+ onClick: () => void;
9
+ }
10
+ export declare const ThumbnailItem: FC<ThumbnailItemProps>;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+
3
+ interface ThumbnailSidebarProps {
4
+ onPageSelect: (pageNumber: number) => void;
5
+ currentPage: number;
6
+ }
7
+ export declare const ThumbnailSidebar: FC<ThumbnailSidebarProps>;
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { FC } from 'react';
2
+
3
+ interface ThumbnailToggleProps {
4
+ title?: string;
5
+ }
6
+ export declare const ThumbnailToggle: FC<ThumbnailToggleProps>;
7
+ export {};
@@ -0,0 +1,13 @@
1
+ import { IThumbnail } from '../state/actions';
2
+
3
+ interface UseThumbnailGeneratorProps {
4
+ numPages: number;
5
+ documentUri?: string;
6
+ scale?: number;
7
+ }
8
+ export declare const useThumbnailGenerator: ({ numPages, documentUri, scale, }: UseThumbnailGeneratorProps) => {
9
+ thumbnails: IThumbnail[];
10
+ generateThumbnailFromCanvas: (canvas: HTMLCanvasElement, pageNumber: number) => void;
11
+ scale: number;
12
+ };
13
+ export {};
@@ -0,0 +1,6 @@
1
+ export { ThumbnailSidebar } from './components/ThumbnailSidebar';
2
+ export { ThumbnailItem } from './components/ThumbnailItem';
3
+ export { ThumbnailToggle } from './components/ThumbnailToggle';
4
+ export { ThumbnailProvider, ThumbnailContext } from './state';
5
+ export { useThumbnailGenerator } from './hooks/useThumbnailGenerator';
6
+ export * from './state/actions';
@@ -0,0 +1,31 @@
1
+ export declare const SET_SIDEBAR_OPEN = "SET_SIDEBAR_OPEN";
2
+ export declare const SET_THUMBNAILS = "SET_THUMBNAILS";
3
+ export declare const SET_SELECTED_PAGE = "SET_SELECTED_PAGE";
4
+ export declare const UPDATE_SINGLE_THUMBNAIL = "UPDATE_SINGLE_THUMBNAIL";
5
+ export interface SetSidebarOpen {
6
+ type: typeof SET_SIDEBAR_OPEN;
7
+ isOpen: boolean;
8
+ }
9
+ export declare const setSidebarOpen: (isOpen: boolean) => SetSidebarOpen;
10
+ export interface IThumbnail {
11
+ pageNumber: number;
12
+ dataUrl?: string;
13
+ isLoading: boolean;
14
+ }
15
+ export interface SetThumbnails {
16
+ type: typeof SET_THUMBNAILS;
17
+ thumbnails: IThumbnail[];
18
+ }
19
+ export declare const setThumbnails: (thumbnails: IThumbnail[]) => SetThumbnails;
20
+ export interface SetSelectedPage {
21
+ type: typeof SET_SELECTED_PAGE;
22
+ pageNumber: number;
23
+ }
24
+ export declare const setSelectedPage: (pageNumber: number) => SetSelectedPage;
25
+ export interface UpdateSingleThumbnail {
26
+ type: typeof UPDATE_SINGLE_THUMBNAIL;
27
+ pageNumber: number;
28
+ dataUrl: string;
29
+ }
30
+ export declare const updateSingleThumbnail: (pageNumber: number, dataUrl: string) => UpdateSingleThumbnail;
31
+ export type ThumbnailActions = SetSidebarOpen | SetThumbnails | SetSelectedPage | UpdateSingleThumbnail;
@@ -0,0 +1,15 @@
1
+ import { default as React, Dispatch, FC, PropsWithChildren } from 'react';
2
+ import { IThumbnailConfig } from '../../../models';
3
+ import { ThumbnailActions } from './actions';
4
+ import { IThumbnailState } from './reducer';
5
+
6
+ interface ThumbnailContextValue {
7
+ state: IThumbnailState;
8
+ dispatch: Dispatch<ThumbnailActions>;
9
+ }
10
+ export declare const ThumbnailContext: React.Context<ThumbnailContextValue>;
11
+ interface ThumbnailProviderProps {
12
+ config?: IThumbnailConfig;
13
+ }
14
+ export declare const ThumbnailProvider: FC<PropsWithChildren<ThumbnailProviderProps>>;
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { ThumbnailActions, IThumbnail } from './actions';
2
+
3
+ export interface IThumbnailState {
4
+ isOpen: boolean;
5
+ thumbnails: IThumbnail[];
6
+ selectedPage: number;
7
+ thumbnailWidth: number;
8
+ }
9
+ export declare const initialThumbnailState: IThumbnailState;
10
+ export type ThumbnailStateReducer = (state: IThumbnailState, action: ThumbnailActions) => IThumbnailState;
11
+ export declare const thumbnailReducer: ThumbnailStateReducer;