@embedpdf/plugin-annotation 1.5.0 → 2.0.0-next.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1760 -1444
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +58 -19
- package/dist/lib/annotation-plugin.d.ts +14 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/reducer.d.ts +2 -1
- package/dist/lib/selectors.d.ts +10 -8
- package/dist/lib/types.d.ts +53 -10
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +96 -48
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +96 -48
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/annotation-container.d.ts +4 -3
- package/dist/shared/components/annotation-layer.d.ts +7 -7
- package/dist/shared/components/annotation-paint-layer.d.ts +2 -1
- package/dist/shared/components/annotations/stamp.d.ts +2 -1
- package/dist/shared/components/annotations.d.ts +3 -2
- package/dist/shared/components/render-annotation.d.ts +2 -1
- package/dist/shared/components/text-markup.d.ts +2 -1
- package/dist/shared/components/types.d.ts +7 -7
- package/dist/shared/hooks/use-annotation.d.ts +8 -4
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared-preact/components/annotation-container.d.ts +4 -3
- package/dist/shared-preact/components/annotation-layer.d.ts +7 -7
- package/dist/shared-preact/components/annotation-paint-layer.d.ts +2 -1
- package/dist/shared-preact/components/annotations/stamp.d.ts +2 -1
- package/dist/shared-preact/components/annotations.d.ts +3 -2
- package/dist/shared-preact/components/render-annotation.d.ts +2 -1
- package/dist/shared-preact/components/text-markup.d.ts +2 -1
- package/dist/shared-preact/components/types.d.ts +7 -7
- package/dist/shared-preact/hooks/use-annotation.d.ts +8 -4
- package/dist/shared-preact/index.d.ts +1 -0
- package/dist/shared-react/components/annotation-container.d.ts +4 -3
- package/dist/shared-react/components/annotation-layer.d.ts +7 -7
- package/dist/shared-react/components/annotation-paint-layer.d.ts +2 -1
- package/dist/shared-react/components/annotations/stamp.d.ts +2 -1
- package/dist/shared-react/components/annotations.d.ts +3 -2
- package/dist/shared-react/components/render-annotation.d.ts +2 -1
- package/dist/shared-react/components/text-markup.d.ts +2 -1
- package/dist/shared-react/components/types.d.ts +7 -7
- package/dist/shared-react/hooks/use-annotation.d.ts +8 -4
- package/dist/shared-react/index.d.ts +1 -0
- package/dist/svelte/components/AnnotationContainer.svelte.d.ts +26 -0
- package/dist/svelte/components/AnnotationLayer.svelte.d.ts +27 -0
- package/dist/svelte/components/AnnotationPaintLayer.svelte.d.ts +8 -0
- package/dist/svelte/components/Annotations.svelte.d.ts +22 -0
- package/dist/svelte/components/PreviewRenderer.svelte.d.ts +8 -0
- package/dist/svelte/components/RenderAnnotation.svelte.d.ts +13 -0
- package/dist/svelte/components/TextMarkup.svelte.d.ts +8 -0
- package/dist/svelte/components/annotations/Circle.svelte.d.ts +26 -0
- package/dist/svelte/components/annotations/FreeText.svelte.d.ts +15 -0
- package/dist/svelte/components/annotations/Ink.svelte.d.ts +14 -0
- package/dist/svelte/components/annotations/Line.svelte.d.ts +18 -0
- package/dist/svelte/components/annotations/Polygon.svelte.d.ts +19 -0
- package/dist/svelte/components/annotations/Polyline.svelte.d.ts +17 -0
- package/dist/svelte/components/annotations/Square.svelte.d.ts +16 -0
- package/dist/svelte/components/annotations/Stamp.svelte.d.ts +13 -0
- package/dist/svelte/components/annotations/index.d.ts +8 -0
- package/dist/svelte/components/index.d.ts +9 -0
- package/dist/svelte/components/text-markup/Highlight.svelte.d.ts +13 -0
- package/dist/svelte/components/text-markup/Squiggly.svelte.d.ts +13 -0
- package/dist/svelte/components/text-markup/Strikeout.svelte.d.ts +13 -0
- package/dist/svelte/components/text-markup/Underline.svelte.d.ts +13 -0
- package/dist/svelte/components/text-markup/index.d.ts +4 -0
- package/dist/svelte/components/types.d.ts +32 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-annotation.svelte.d.ts +21 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +4 -0
- package/dist/svelte/index.js +3083 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/svelte/types.d.ts +54 -0
- package/dist/vue/components/annotation-container.vue.d.ts +10 -5
- package/dist/vue/components/annotation-layer.vue.d.ts +13 -7
- package/dist/vue/components/annotation-paint-layer.vue.d.ts +3 -1
- package/dist/vue/components/annotations/circle.vue.d.ts +2 -1
- package/dist/vue/components/annotations/free-text.vue.d.ts +2 -1
- package/dist/vue/components/annotations/ink.vue.d.ts +2 -1
- package/dist/vue/components/annotations/line.vue.d.ts +2 -1
- package/dist/vue/components/annotations/polygon.vue.d.ts +2 -1
- package/dist/vue/components/annotations/polyline.vue.d.ts +2 -1
- package/dist/vue/components/annotations/square.vue.d.ts +2 -1
- package/dist/vue/components/annotations/stamp.vue.d.ts +3 -1
- package/dist/vue/components/annotations.vue.d.ts +7 -3
- package/dist/vue/components/preview-renderer.vue.d.ts +2 -1
- package/dist/vue/components/render-annotation.vue.d.ts +3 -1
- package/dist/vue/components/text-markup/highlight.vue.d.ts +2 -1
- package/dist/vue/components/text-markup/squiggly.vue.d.ts +2 -1
- package/dist/vue/components/text-markup/strikeout.vue.d.ts +2 -1
- package/dist/vue/components/text-markup/underline.vue.d.ts +2 -1
- package/dist/vue/components/text-markup.vue.d.ts +3 -1
- package/dist/vue/hooks/use-annotation.d.ts +21 -2682
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +354 -250
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/types.d.ts +23 -0
- package/package.json +19 -11
package/dist/lib/actions.d.ts
CHANGED
|
@@ -1,39 +1,69 @@
|
|
|
1
1
|
import { Action } from '@embedpdf/core';
|
|
2
2
|
import { PdfAnnotationObject } from '@embedpdf/models';
|
|
3
3
|
import { AnnotationTool } from './tools/types';
|
|
4
|
+
import { AnnotationDocumentState } from './types';
|
|
5
|
+
export declare const INIT_ANNOTATION_STATE = "ANNOTATION/INIT_STATE";
|
|
6
|
+
export declare const CLEANUP_ANNOTATION_STATE = "ANNOTATION/CLEANUP_STATE";
|
|
7
|
+
export declare const SET_ACTIVE_DOCUMENT = "ANNOTATION/SET_ACTIVE_DOCUMENT";
|
|
4
8
|
export declare const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
|
|
5
9
|
export declare const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
|
|
6
10
|
export declare const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
|
|
7
|
-
export declare const
|
|
11
|
+
export declare const SET_ACTIVE_TOOL_ID = "ANNOTATION/SET_ACTIVE_TOOL_ID";
|
|
8
12
|
export declare const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
|
|
9
13
|
export declare const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
|
|
10
14
|
export declare const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
|
|
11
15
|
export declare const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
|
|
12
16
|
export declare const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
|
|
13
|
-
export declare const
|
|
17
|
+
export declare const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
|
|
14
18
|
export declare const SET_TOOL_DEFAULTS = "ANNOTATION/SET_TOOL_DEFAULTS";
|
|
15
19
|
export declare const ADD_TOOL = "ANNOTATION/ADD_TOOL";
|
|
20
|
+
export interface InitAnnotationStateAction extends Action {
|
|
21
|
+
type: typeof INIT_ANNOTATION_STATE;
|
|
22
|
+
payload: {
|
|
23
|
+
documentId: string;
|
|
24
|
+
state: AnnotationDocumentState;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface CleanupAnnotationStateAction extends Action {
|
|
28
|
+
type: typeof CLEANUP_ANNOTATION_STATE;
|
|
29
|
+
payload: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SetActiveDocumentAction extends Action {
|
|
32
|
+
type: typeof SET_ACTIVE_DOCUMENT;
|
|
33
|
+
payload: string | null;
|
|
34
|
+
}
|
|
16
35
|
export interface SetAnnotationsAction extends Action {
|
|
17
36
|
type: typeof SET_ANNOTATIONS;
|
|
18
|
-
payload:
|
|
37
|
+
payload: {
|
|
38
|
+
documentId: string;
|
|
39
|
+
annotations: Record<number, PdfAnnotationObject[]>;
|
|
40
|
+
};
|
|
19
41
|
}
|
|
20
42
|
export interface SelectAnnotationAction extends Action {
|
|
21
43
|
type: typeof SELECT_ANNOTATION;
|
|
22
44
|
payload: {
|
|
45
|
+
documentId: string;
|
|
23
46
|
pageIndex: number;
|
|
24
47
|
id: string;
|
|
25
48
|
};
|
|
26
49
|
}
|
|
27
50
|
export interface DeselectAnnotationAction extends Action {
|
|
28
51
|
type: typeof DESELECT_ANNOTATION;
|
|
52
|
+
payload: {
|
|
53
|
+
documentId: string;
|
|
54
|
+
};
|
|
29
55
|
}
|
|
30
|
-
export interface
|
|
31
|
-
type: typeof
|
|
32
|
-
payload:
|
|
56
|
+
export interface SetActiveToolIdAction extends Action {
|
|
57
|
+
type: typeof SET_ACTIVE_TOOL_ID;
|
|
58
|
+
payload: {
|
|
59
|
+
documentId: string;
|
|
60
|
+
toolId: string | null;
|
|
61
|
+
};
|
|
33
62
|
}
|
|
34
63
|
export interface CreateAnnotationAction extends Action {
|
|
35
64
|
type: typeof CREATE_ANNOTATION;
|
|
36
65
|
payload: {
|
|
66
|
+
documentId: string;
|
|
37
67
|
pageIndex: number;
|
|
38
68
|
annotation: PdfAnnotationObject;
|
|
39
69
|
};
|
|
@@ -41,6 +71,7 @@ export interface CreateAnnotationAction extends Action {
|
|
|
41
71
|
export interface PatchAnnotationAction extends Action {
|
|
42
72
|
type: typeof PATCH_ANNOTATION;
|
|
43
73
|
payload: {
|
|
74
|
+
documentId: string;
|
|
44
75
|
pageIndex: number;
|
|
45
76
|
id: string;
|
|
46
77
|
patch: Partial<PdfAnnotationObject>;
|
|
@@ -49,22 +80,27 @@ export interface PatchAnnotationAction extends Action {
|
|
|
49
80
|
export interface DeleteAnnotationAction extends Action {
|
|
50
81
|
type: typeof DELETE_ANNOTATION;
|
|
51
82
|
payload: {
|
|
83
|
+
documentId: string;
|
|
52
84
|
pageIndex: number;
|
|
53
85
|
id: string;
|
|
54
86
|
};
|
|
55
87
|
}
|
|
56
88
|
export interface CommitAction extends Action {
|
|
57
89
|
type: typeof COMMIT_PENDING_CHANGES;
|
|
90
|
+
payload: {
|
|
91
|
+
documentId: string;
|
|
92
|
+
};
|
|
58
93
|
}
|
|
59
94
|
export interface PurgeAnnotationAction extends Action {
|
|
60
95
|
type: typeof PURGE_ANNOTATION;
|
|
61
96
|
payload: {
|
|
97
|
+
documentId: string;
|
|
62
98
|
uid: string;
|
|
63
99
|
};
|
|
64
100
|
}
|
|
65
|
-
export interface
|
|
66
|
-
type: typeof
|
|
67
|
-
payload: string
|
|
101
|
+
export interface AddColorPresetAction extends Action {
|
|
102
|
+
type: typeof ADD_COLOR_PRESET;
|
|
103
|
+
payload: string;
|
|
68
104
|
}
|
|
69
105
|
export interface SetToolDefaultsAction extends Action {
|
|
70
106
|
type: typeof SET_TOOL_DEFAULTS;
|
|
@@ -77,16 +113,19 @@ export interface AddToolAction extends Action {
|
|
|
77
113
|
type: typeof ADD_TOOL;
|
|
78
114
|
payload: AnnotationTool;
|
|
79
115
|
}
|
|
80
|
-
export type AnnotationAction = SetAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction |
|
|
81
|
-
export declare
|
|
82
|
-
export declare
|
|
83
|
-
export declare
|
|
116
|
+
export type AnnotationAction = InitAnnotationStateAction | CleanupAnnotationStateAction | SetActiveDocumentAction | SetAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | SetActiveToolIdAction | CreateAnnotationAction | PatchAnnotationAction | DeleteAnnotationAction | CommitAction | PurgeAnnotationAction | AddColorPresetAction | SetToolDefaultsAction | AddToolAction;
|
|
117
|
+
export declare function initAnnotationState(documentId: string, state: AnnotationDocumentState): InitAnnotationStateAction;
|
|
118
|
+
export declare function cleanupAnnotationState(documentId: string): CleanupAnnotationStateAction;
|
|
119
|
+
export declare function setActiveDocument(documentId: string | null): SetActiveDocumentAction;
|
|
120
|
+
export declare const setAnnotations: (documentId: string, annotations: Record<number, PdfAnnotationObject[]>) => SetAnnotationsAction;
|
|
121
|
+
export declare const selectAnnotation: (documentId: string, pageIndex: number, id: string) => SelectAnnotationAction;
|
|
122
|
+
export declare const deselectAnnotation: (documentId: string) => DeselectAnnotationAction;
|
|
123
|
+
export declare const setActiveToolId: (documentId: string, toolId: string | null) => SetActiveToolIdAction;
|
|
124
|
+
export declare const createAnnotation: (documentId: string, pageIndex: number, annotation: PdfAnnotationObject) => CreateAnnotationAction;
|
|
125
|
+
export declare const patchAnnotation: (documentId: string, pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
|
|
126
|
+
export declare const deleteAnnotation: (documentId: string, pageIndex: number, id: string) => DeleteAnnotationAction;
|
|
127
|
+
export declare const commitPendingChanges: (documentId: string) => CommitAction;
|
|
128
|
+
export declare const purgeAnnotation: (documentId: string, uid: string) => PurgeAnnotationAction;
|
|
84
129
|
export declare const addColorPreset: (c: string) => AddColorPresetAction;
|
|
85
|
-
export declare const createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) => CreateAnnotationAction;
|
|
86
|
-
export declare const patchAnnotation: (pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
|
|
87
|
-
export declare const deleteAnnotation: (pageIndex: number, id: string) => DeleteAnnotationAction;
|
|
88
|
-
export declare const commitPendingChanges: () => CommitAction;
|
|
89
|
-
export declare const purgeAnnotation: (uid: string) => PurgeAnnotationAction;
|
|
90
|
-
export declare const setActiveToolId: (id: string | null) => SetActiveToolIdAction;
|
|
91
130
|
export declare const setToolDefaults: (toolId: string, patch: Partial<any>) => SetToolDefaultsAction;
|
|
92
131
|
export declare const addTool: (tool: AnnotationTool) => AddToolAction;
|
|
@@ -13,27 +13,35 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
|
|
|
13
13
|
private readonly selection;
|
|
14
14
|
private readonly history;
|
|
15
15
|
private pendingContexts;
|
|
16
|
+
private isInitialLoadComplete;
|
|
17
|
+
private importQueue;
|
|
16
18
|
private handlerFactories;
|
|
17
19
|
private readonly activeTool$;
|
|
18
20
|
private readonly events$;
|
|
21
|
+
private readonly toolsChange$;
|
|
19
22
|
private readonly patchRegistry;
|
|
20
|
-
private isInitialLoadComplete;
|
|
21
|
-
private importQueue;
|
|
22
23
|
constructor(id: string, registry: PluginRegistry, config: AnnotationPluginConfig);
|
|
24
|
+
protected onDocumentLoadingStarted(documentId: string): void;
|
|
25
|
+
protected onDocumentLoaded(documentId: string): void;
|
|
26
|
+
protected onDocumentClosed(documentId: string): void;
|
|
23
27
|
private registerHandlerFactories;
|
|
24
28
|
private registerBuiltInPatches;
|
|
25
29
|
initialize(): Promise<void>;
|
|
26
30
|
private registerInteractionForTool;
|
|
27
31
|
protected buildCapability(): AnnotationCapability;
|
|
32
|
+
private createAnnotationScope;
|
|
28
33
|
onStoreUpdated(prev: AnnotationState, next: AnnotationState): void;
|
|
29
34
|
private registerPatchFunction;
|
|
30
35
|
private transformAnnotation;
|
|
31
|
-
registerPageHandlers(pageIndex: number, scale: number, callbacks: {
|
|
36
|
+
registerPageHandlers(documentId: string, pageIndex: number, scale: number, callbacks: {
|
|
32
37
|
services: HandlerServices;
|
|
33
38
|
onPreview: (toolId: string, state: AnyPreviewState | null) => void;
|
|
34
39
|
}): () => void;
|
|
40
|
+
private getDocumentState;
|
|
35
41
|
private getAllAnnotations;
|
|
36
42
|
private getPageAnnotations;
|
|
43
|
+
private getSelectedAnnotation;
|
|
44
|
+
private getAnnotationById;
|
|
37
45
|
private renderAnnotation;
|
|
38
46
|
private importAnnotations;
|
|
39
47
|
private processImportQueue;
|
|
@@ -43,8 +51,9 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
|
|
|
43
51
|
private updateAnnotation;
|
|
44
52
|
private deleteAnnotation;
|
|
45
53
|
private selectAnnotation;
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
private deselectAnnotation;
|
|
55
|
+
getActiveTool(documentId?: string): AnnotationTool | null;
|
|
56
|
+
setActiveTool(toolId: string | null, documentId?: string): void;
|
|
48
57
|
getTool<T extends AnnotationTool>(toolId: string): T | undefined;
|
|
49
58
|
findToolForAnnotation(annotation: PdfAnnotationObject): AnnotationTool | null;
|
|
50
59
|
private commit;
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/reducer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Reducer } from '@embedpdf/core';
|
|
2
2
|
import { AnnotationAction } from './actions';
|
|
3
|
-
import { AnnotationPluginConfig, AnnotationState } from './types';
|
|
3
|
+
import { AnnotationPluginConfig, AnnotationState, AnnotationDocumentState } from './types';
|
|
4
|
+
export declare const initialDocumentState: () => AnnotationDocumentState;
|
|
4
5
|
export declare const initialState: (cfg: AnnotationPluginConfig) => AnnotationState;
|
|
5
6
|
export declare const reducer: Reducer<AnnotationState, AnnotationAction>;
|
package/dist/lib/selectors.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { AnnotationState, SidebarAnnotationEntry, TrackedAnnotation } from './types';
|
|
1
|
+
import { AnnotationState, AnnotationDocumentState, SidebarAnnotationEntry, TrackedAnnotation } from './types';
|
|
2
2
|
import { ToolMap } from './tools/tools-utils';
|
|
3
3
|
/** All annotations _objects_ on a single page (order preserved). */
|
|
4
|
-
export declare const getAnnotationsByPageIndex: (s:
|
|
4
|
+
export declare const getAnnotationsByPageIndex: (s: AnnotationDocumentState, page: number) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>[];
|
|
5
5
|
/** Shortcut: every page → list of annotation objects. */
|
|
6
|
-
export declare const getAnnotations: (s:
|
|
6
|
+
export declare const getAnnotations: (s: AnnotationDocumentState) => Record<number, TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>[]>;
|
|
7
7
|
/** The full `TrackedAnnotation` for the current selection. */
|
|
8
|
-
export declare const getSelectedAnnotation: (s:
|
|
9
|
-
|
|
8
|
+
export declare const getSelectedAnnotation: (s: AnnotationDocumentState) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
9
|
+
/** Get a tracked annotation by its ID */
|
|
10
|
+
export declare const getAnnotationByUid: (s: AnnotationDocumentState, uid: string) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>;
|
|
11
|
+
export declare const getSelectedAnnotationByPageIndex: (s: AnnotationDocumentState, pageIndex: number) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
10
12
|
/** Check if a given anno on a page is the current selection. */
|
|
11
|
-
export declare const isAnnotationSelected: (s:
|
|
13
|
+
export declare const isAnnotationSelected: (s: AnnotationDocumentState, id: string) => boolean;
|
|
12
14
|
/**
|
|
13
15
|
* Returns the current defaults for a specific tool by its ID.
|
|
14
16
|
* This is fully type-safe and infers the correct return type.
|
|
@@ -29,7 +31,7 @@ export declare function getToolDefaultsById<K extends keyof ToolMap>(state: Anno
|
|
|
29
31
|
* …
|
|
30
32
|
* }
|
|
31
33
|
*/
|
|
32
|
-
export declare const getSidebarAnnotationsWithRepliesGroupedByPage: (s:
|
|
34
|
+
export declare const getSidebarAnnotationsWithRepliesGroupedByPage: (s: AnnotationDocumentState) => Record<number, SidebarAnnotationEntry[]>;
|
|
33
35
|
/**
|
|
34
36
|
* Collect every sidebar-eligible annotation and attach its TEXT replies.
|
|
35
37
|
*
|
|
@@ -40,4 +42,4 @@ export declare const getSidebarAnnotationsWithRepliesGroupedByPage: (s: Annotati
|
|
|
40
42
|
* …
|
|
41
43
|
* ]
|
|
42
44
|
*/
|
|
43
|
-
export declare const getSidebarAnnotationsWithReplies: (s:
|
|
45
|
+
export declare const getSidebarAnnotationsWithReplies: (s: AnnotationDocumentState) => SidebarAnnotationEntry[];
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -3,25 +3,32 @@ import { AnnotationCreateContext, PdfAnnotationObject, PdfAnnotationSubtype, Pdf
|
|
|
3
3
|
import { AnnotationTool } from './tools/types';
|
|
4
4
|
export type AnnotationEvent = {
|
|
5
5
|
type: 'create';
|
|
6
|
+
documentId: string;
|
|
6
7
|
annotation: PdfAnnotationObject;
|
|
7
8
|
pageIndex: number;
|
|
8
9
|
ctx?: AnnotationCreateContext<any>;
|
|
9
10
|
committed: boolean;
|
|
10
11
|
} | {
|
|
11
12
|
type: 'update';
|
|
13
|
+
documentId: string;
|
|
12
14
|
annotation: PdfAnnotationObject;
|
|
13
15
|
pageIndex: number;
|
|
14
16
|
patch: Partial<PdfAnnotationObject>;
|
|
15
17
|
committed: boolean;
|
|
16
18
|
} | {
|
|
17
19
|
type: 'delete';
|
|
20
|
+
documentId: string;
|
|
18
21
|
annotation: PdfAnnotationObject;
|
|
19
22
|
pageIndex: number;
|
|
20
23
|
committed: boolean;
|
|
21
24
|
} | {
|
|
22
25
|
type: 'loaded';
|
|
26
|
+
documentId: string;
|
|
23
27
|
total: number;
|
|
24
28
|
};
|
|
29
|
+
export type AnnotationToolsChangeEvent = {
|
|
30
|
+
tools: AnnotationTool[];
|
|
31
|
+
};
|
|
25
32
|
export type CommitState = 'new' | 'dirty' | 'deleted' | 'synced' | 'ignored';
|
|
26
33
|
export interface TrackedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
27
34
|
commitState: CommitState;
|
|
@@ -32,15 +39,19 @@ export interface RenderAnnotationOptions {
|
|
|
32
39
|
annotation: PdfAnnotationObject;
|
|
33
40
|
options?: PdfRenderPageAnnotationOptions;
|
|
34
41
|
}
|
|
35
|
-
export interface
|
|
42
|
+
export interface AnnotationDocumentState {
|
|
36
43
|
pages: Record<number, string[]>;
|
|
37
44
|
byUid: Record<string, TrackedAnnotation>;
|
|
38
45
|
selectedUid: string | null;
|
|
39
46
|
activeToolId: string | null;
|
|
47
|
+
hasPendingChanges: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface AnnotationState {
|
|
50
|
+
documents: Record<string, AnnotationDocumentState>;
|
|
51
|
+
activeDocumentId: string | null;
|
|
40
52
|
/** The complete list of available tools, including any user modifications. */
|
|
41
53
|
tools: AnnotationTool[];
|
|
42
54
|
colorPresets: string[];
|
|
43
|
-
hasPendingChanges: boolean;
|
|
44
55
|
}
|
|
45
56
|
export interface AnnotationPluginConfig extends BasePluginConfig {
|
|
46
57
|
/** A list of custom tools to add or default tools to override. */
|
|
@@ -77,11 +88,48 @@ export type ImportAnnotationItem<T extends PdfAnnotationObject = PdfAnnotationOb
|
|
|
77
88
|
annotation: T;
|
|
78
89
|
ctx?: AnnotationCreateContext<T>;
|
|
79
90
|
};
|
|
91
|
+
export interface AnnotationStateChangeEvent {
|
|
92
|
+
documentId: string;
|
|
93
|
+
state: AnnotationDocumentState;
|
|
94
|
+
}
|
|
95
|
+
export interface AnnotationActiveToolChangeEvent {
|
|
96
|
+
documentId: string;
|
|
97
|
+
tool: AnnotationTool | null;
|
|
98
|
+
}
|
|
99
|
+
export interface AnnotationScope {
|
|
100
|
+
getState(): AnnotationDocumentState;
|
|
101
|
+
getPageAnnotations(options: GetPageAnnotationsOptions): Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
102
|
+
getSelectedAnnotation(): TrackedAnnotation | null;
|
|
103
|
+
getAnnotationById(id: string): TrackedAnnotation | null;
|
|
104
|
+
selectAnnotation(pageIndex: number, annotationId: string): void;
|
|
105
|
+
deselectAnnotation(): void;
|
|
106
|
+
getActiveTool(): AnnotationTool | null;
|
|
107
|
+
setActiveTool(toolId: string | null): void;
|
|
108
|
+
findToolForAnnotation(annotation: PdfAnnotationObject): AnnotationTool | null;
|
|
109
|
+
importAnnotations(items: ImportAnnotationItem<PdfAnnotationObject>[]): void;
|
|
110
|
+
createAnnotation<A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>): void;
|
|
111
|
+
updateAnnotation(pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>): void;
|
|
112
|
+
deleteAnnotation(pageIndex: number, annotationId: string): void;
|
|
113
|
+
renderAnnotation(options: RenderAnnotationOptions): Task<Blob, PdfErrorReason>;
|
|
114
|
+
commit(): Task<boolean, PdfErrorReason>;
|
|
115
|
+
onStateChange: EventHook<AnnotationDocumentState>;
|
|
116
|
+
onAnnotationEvent: EventHook<AnnotationEvent>;
|
|
117
|
+
onActiveToolChange: EventHook<AnnotationTool | null>;
|
|
118
|
+
}
|
|
80
119
|
export interface AnnotationCapability {
|
|
120
|
+
getState: () => AnnotationDocumentState;
|
|
81
121
|
getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
82
122
|
getSelectedAnnotation: () => TrackedAnnotation | null;
|
|
123
|
+
getAnnotationById(id: string): TrackedAnnotation | null;
|
|
83
124
|
selectAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
84
125
|
deselectAnnotation: () => void;
|
|
126
|
+
importAnnotations: (items: ImportAnnotationItem<PdfAnnotationObject>[]) => void;
|
|
127
|
+
createAnnotation: <A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>) => void;
|
|
128
|
+
updateAnnotation: (pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>) => void;
|
|
129
|
+
deleteAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
130
|
+
renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
|
|
131
|
+
commit: () => Task<boolean, PdfErrorReason>;
|
|
132
|
+
forDocument: (documentId: string) => AnnotationScope;
|
|
85
133
|
getActiveTool: () => AnnotationTool | null;
|
|
86
134
|
setActiveTool: (toolId: string | null) => void;
|
|
87
135
|
getTools: () => AnnotationTool[];
|
|
@@ -91,10 +139,6 @@ export interface AnnotationCapability {
|
|
|
91
139
|
setToolDefaults: (toolId: string, patch: Partial<any>) => void;
|
|
92
140
|
getColorPresets: () => string[];
|
|
93
141
|
addColorPreset: (color: string) => void;
|
|
94
|
-
importAnnotations: (items: ImportAnnotationItem<PdfAnnotationObject>[]) => void;
|
|
95
|
-
createAnnotation: <A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>) => void;
|
|
96
|
-
updateAnnotation: (pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>) => void;
|
|
97
|
-
deleteAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
98
142
|
/**
|
|
99
143
|
* Transform an annotation based on interaction (move, resize, etc.)
|
|
100
144
|
* This applies annotation-specific logic to ensure consistency.
|
|
@@ -105,11 +149,10 @@ export interface AnnotationCapability {
|
|
|
105
149
|
* This allows extending the transformation logic for custom annotations.
|
|
106
150
|
*/
|
|
107
151
|
registerPatchFunction: <T extends PdfAnnotationObject>(type: PdfAnnotationSubtype, patchFn: PatchFunction<T>) => void;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
onActiveToolChange: EventHook<AnnotationTool | null>;
|
|
152
|
+
onStateChange: EventHook<AnnotationStateChangeEvent>;
|
|
153
|
+
onActiveToolChange: EventHook<AnnotationActiveToolChangeEvent>;
|
|
111
154
|
onAnnotationEvent: EventHook<AnnotationEvent>;
|
|
112
|
-
|
|
155
|
+
onToolsChange: EventHook<AnnotationToolsChangeEvent>;
|
|
113
156
|
}
|
|
114
157
|
export interface GetPageAnnotationsOptions {
|
|
115
158
|
pageIndex: number;
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact"),o=require("preact/hooks"),i=require("preact/jsx-runtime"),s=require("@embedpdf/models"),r=require("@embedpdf/plugin-interaction-manager/preact"),l=require("@embedpdf/plugin-selection/preact"),a=require("@embedpdf/utils/preact"),c={},d=()=>e.usePlugin(t.AnnotationPlugin.id),u=()=>e.useCapability(t.AnnotationPlugin.id);function h({scale:e,pageIndex:t,rotation:n,pageWidth:s,pageHeight:r,trackedAnnotation:l,children:c,isSelected:d,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:b,selectionMenu:y,outlineOffset:v=1,onDoubleClick:f,onSelect:m,zIndex:j=1,resizeUI:k,vertexUI:S,selectionOutlineColor:M="#007ACC",customAnnotationRenderer:A,...w}){const[z,P]=o.useState(l.object),{provides:C}=u(),R=o.useRef(null),D=z?{...l.object,...z}:l.object,I=(null==k?void 0:k.color)??"#007ACC",E=(null==S?void 0:S.color)??"#007ACC",B=(null==k?void 0:k.size)??12,T=(null==S?void 0:S.size)??12,{dragProps:$,vertices:L,resize:F}=a.useInteractionHandles({controller:{element:D.rect,vertices:null==b?void 0:b.extractVertices(D),constraints:{minWidth:10,minHeight:10,boundingBox:{width:s/e,height:r/e}},maintainAspectRatio:p,pageRotation:n,scale:e,enabled:d,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(R.current=D);const o=e.transformData.type,i=R.current??D,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==C?void 0:C.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});r&&P((e=>({...e,...r}))),"end"===e.state&&r&&(R.current=null,null==C||C.updateAnnotation(t,l.object.id,r))}},resizeUI:{handleSize:B,spacing:v,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:T,zIndex:j+2},includeVertices:!!b}),W=a.useDoublePressProps(f);return o.useEffect((()=>{P(l.object)}),[l.object]),i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...h&&d?$:{},...W,style:{position:"absolute",left:D.rect.origin.x*e,top:D.rect.origin.y*e,width:D.rect.size.width*e,height:D.rect.size.height*e,outline:d?`1px solid ${M}`:"none",outlineOffset:d?`${v}px`:"0px",pointerEvents:d?"auto":"none",touchAction:"none",cursor:d&&h?"move":"default",zIndex:j,...x},...w,children:[(()=>{const o="function"==typeof c?c(D):c,i=null==A?void 0:A({annotation:D,children:o,isSelected:d,scale:e,rotation:n,pageWidth:s,pageHeight:r,pageIndex:t,onSelect:m});return null!=i?i:o})(),d&&g&&F.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:I}):i.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),d&&L.map((({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:E}):i.jsx("div",{...t,style:{...t.style,backgroundColor:E}},e)))]}),i.jsx(a.CounterRotate,{rect:{origin:{x:D.rect.origin.x*e,y:D.rect.origin.y*e},size:{width:D.rect.size.width*e,height:D.rect.size.height*e}},rotation:n,children:({rect:e,menuWrapperProps:t})=>y&&y({annotation:l,selected:d,rect:e,menuWrapperProps:t})})]})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){return i.jsx(i.Fragment,{children:n.map(((n,a)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map(((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map(((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function b({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s,c=6*s,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map(((e,n)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*s,top:(o?e.origin.y-o.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n)))})}function y({isSelected:e,color:t="#000000",opacity:n=1,strokeWidth:s,inkList:r,rect:l,scale:a,onClick:c}){const d=o.useMemo((()=>r.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-l.origin.x,s=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "})),t.trim()}))),[r,l]),u=l.size.width*a,h=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map(((o,r)=>i.jsx("path",{d:o,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function v({isSelected:e,color:t="#000000",strokeColor:n,opacity:r=1,strokeWidth:l,strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:g,height:p,x:x,y:b}=o.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}}),[d,l]),y=(g+l)*u,v=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:y,height:v,pointerEvents:"none",zIndex:2},width:y,height:v,viewBox:`0 0 ${g+l} ${p+l}`,children:i.jsx("rect",{x:x,y:b,width:g,height:p,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function f({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:r,strokeStyle:l=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:b,rx:y,ry:v}=o.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),f=g*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${g} ${p}`,children:i.jsx("ellipse",{cx:x,cy:b,rx:y,ry:v,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function m({color:e="transparent",opacity:n=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:b,y1:y,x2:v,y2:f}=o.useMemo((()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y})),[u,d]),m=o.useMemo((()=>{const e=Math.atan2(f-y,v-b);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,b,y),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,f)}}),[h,r,b,y,v,f]),j=d.size.width*g,k=d.size.height*g;return i.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[i.jsx("line",{x1:b,y1:y,x2:v,y2:f,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&i.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&i.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function j({rect:e,vertices:n,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=o.useMemo((()=>n.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[n,e]),p=o.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[g]),x=o.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[0],g[1]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),b=e.size.width*c,y=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:y,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??s,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&i.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:r,fill:x.start.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&i.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:r,fill:x.end.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({rect:e,vertices:t,color:n="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const b=p?[...t,p]:t,y=o.useMemo((()=>b.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[b,e]),v=o.useMemo((()=>{if(!y.length)return"";const[e,...t]=y,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[y,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return i.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:v,onPointerDown:g,onTouchStart:g,opacity:l,style:{fill:p?"none":n,stroke:r??n,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),f&&t.length>1&&i.jsx("path",{d:`M ${y[y.length-1].x} ${y[y.length-1].y} L ${y[0].x} ${y[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&i.jsx("rect",{x:y[0].x-x/u/2,y:y[0].y-x/u/2,width:x/u,height:x/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const d=o.useRef(null),{provides:h}=u(),[g,p]=o.useState(!1);o.useEffect((()=>{if(t&&d.current){const e=d.current;e.focus();const t=window.getSelection();if(t){const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}}),[t]),o.useLayoutEffect((()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}}),[]);const x=n.object.fontSize*l,b=g&&t&&x>0&&x<16,y=b?16:x,v=b?x/16:1,f=b?100/v:100;return i.jsx("div",{style:{position:"absolute",width:n.object.rect.size.width*l,height:n.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:i.jsx("span",{ref:d,onBlur:()=>{h&&d.current&&h.updateAnnotation(r,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:y,fontFamily:s.standardFontCss(n.object.fontFamily),textAlign:s.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===s.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===s.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.backgroundColor,opacity:n.object.opacity,width:b?`${f}%`:"100%",height:b?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:b?`scale(${v})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function M({pageIndex:e,annotation:t,scaleFactor:r=1,style:l,...a}){const{provides:c}=u(),[d,h]=o.useState(null),g=o.useRef(null),{width:p,height:x}=t.rect.size;o.useEffect((()=>{if(c){const n=c.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:r,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);h(t),g.current=t}),s.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,r,c,t.id,p,x]);return i.jsx(n.Fragment,{children:d&&i.jsx("img",{src:d,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...a,style:{width:"100%",height:"100%",display:"block",...l||{}}})})}function A({isSelected:e,annotation:t,pageIndex:n,scale:o,onClick:s}){return i.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:i.jsx(M,{pageIndex:n,annotation:{...t.object,id:t.object.id},scaleFactor:o})})}function w(e){const{pageIndex:a,scale:c,selectionMenu:d}=e,{provides:M}=u(),{provides:w}=l.useSelectionCapability(),[z,P]=o.useState([]),{register:C}=r.usePointerHandlers({pageIndex:a}),[R,D]=o.useState(null),[I,E]=o.useState(null);o.useEffect((()=>{M&&M.onStateChange((e=>{P(t.getAnnotationsByPageIndex(e,a)),D(t.getSelectedAnnotationByPageIndex(e,a))}))}),[M]);const B=o.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&M&&(M.deselectAnnotation(),E(null))}})),[M]),T=o.useCallback(((e,t)=>{e.stopPropagation(),M&&w&&(M.selectAnnotation(a,t.object.id),w.clear(),t.object.id!==I&&E(null))}),[M,w,I,a]);return o.useEffect((()=>C(B)),[C,B]),i.jsx(i.Fragment,{children:z.map((o=>{const r=(null==R?void 0:R.object.id)===o.object.id,l=I===o.object.id,u=null==M?void 0:M.findToolForAnnotation(o.object);return t.isInk(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isSquare(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isCircle(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isUnderline(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(p,{...e,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isStrikeout(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isSquiggly(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isHighlight(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(g,{...e,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isLine(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(m,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})})},o.object.id):t.isPolyline(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})})},o.object.id):t.isPolygon(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:r,scale:c,onClick:e=>T(e,o)})})},o.object.id):t.isFreeText(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:((null==u?void 0:u.interaction.isDraggable)??!0)&&!l,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),E(o.object.id)},...e,children:e=>i.jsx(S,{isSelected:r,isEditing:l,annotation:{...o,object:e},pageIndex:a,scale:c,onClick:e=>T(e,o)})},o.object.id):t.isStamp(o)?i.jsx(h,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>T(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:r,annotation:o,pageIndex:a,scale:c,onClick:e=>T(e,o)})},o.object.id):null}))})}function z({pageIndex:e,scale:t}){var n,r,a,c,d,h,y,v,f,m,j,k;const{provides:S}=l.useSelectionCapability(),{provides:M}=u(),[A,w]=o.useState([]),[z,P]=o.useState(null),[C,R]=o.useState(null);if(o.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{w(S.getHighlightRectsForPage(e)),P(S.getBoundingRectForPage(e))}))}),[S,e]),o.useEffect((()=>{if(!M)return;return M.onActiveToolChange(R)}),[M]),!z)return null;if(!C||!C.defaults)return null;switch(C.defaults.type){case s.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(n=C.defaults)?void 0:n.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{color:null==(r=C.defaults)?void 0:r.color,opacity:null==(a=C.defaults)?void 0:a.opacity,segmentRects:A,scale:t})});case s.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(c=C.defaults)?void 0:c.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(g,{color:null==(d=C.defaults)?void 0:d.color,opacity:null==(h=C.defaults)?void 0:h.opacity,segmentRects:A,scale:t})});case s.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(y=C.defaults)?void 0:y.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{color:null==(v=C.defaults)?void 0:v.color,opacity:null==(f=C.defaults)?void 0:f.opacity,segmentRects:A,scale:t})});case s.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(m=C.defaults)?void 0:m.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(b,{color:null==(j=C.defaults)?void 0:j.color,opacity:null==(k=C.defaults)?void 0:k.opacity,segmentRects:A,scale:t})});default:return null}}function P({preview:e,scale:t}){const{bounds:n}=e,o={position:"absolute",left:n.origin.x*t,top:n.origin.y*t,width:n.size.width*t,height:n.size.height*t,pointerEvents:"none",zIndex:10};return e.type===s.PdfAnnotationSubtype.CIRCLE?i.jsx("div",{style:o,children:i.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.FREETEXT?i.jsx("div",{style:o,children:i.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function C({pageIndex:e,scale:t}){const{plugin:n}=d(),[s,r]=o.useState(new Map),l=o.useRef(null),a=o.useRef(null),c=o.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!l.current)return;const n=l.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=a.current;if(!i||!i.getContext)return;const s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),h=l*u,g=a*u;i.width=h,i.height=g,s.drawImage(r,0,0,h,g);const p=s.getImageData(0,0,h,g);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:h,height:g})},r.src="string"==typeof e?e:URL.createObjectURL(e)}})),[]);return o.useEffect((()=>{if(n)return n.registerPageHandlers(e,t,{services:c,onPreview:(e,t)=>{r((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,n,c]),i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:l,type:"file",style:{display:"none"}}),i.jsx("canvas",{ref:a,style:{display:"none"}}),Array.from(s.entries()).map((([e,n])=>i.jsx(P,{preview:n,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:n,selectionMenu:o,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:c,selectionOutlineColor:d,customAnnotationRenderer:u,...h}){return i.jsxs("div",{style:{...e},...h,children:[i.jsx(w,{selectionMenu:o,pageIndex:t,scale:n,rotation:c,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:d,customAnnotationRenderer:u}),i.jsx(z,{pageIndex:t,scale:n}),i.jsx(C,{pageIndex:t,scale:n})]})},exports.useAnnotation=()=>{const{provides:e}=u(),[n,i]=o.useState(t.initialState({enabled:!0}));return o.useEffect((()=>null==e?void 0:e.onStateChange((e=>{i(e)}))),[e]),{state:n,provides:e}},exports.useAnnotationCapability=u,exports.useAnnotationPlugin=d,Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact"),o=require("preact/hooks"),i=require("preact/jsx-runtime"),s=require("@embedpdf/models"),r=require("@embedpdf/plugin-interaction-manager/preact"),l=require("@embedpdf/plugin-selection/preact"),a=require("@embedpdf/utils/preact"),c={},d=()=>e.usePlugin(t.AnnotationPlugin.id),u=()=>e.useCapability(t.AnnotationPlugin.id);function g({scale:e,documentId:t,pageIndex:n,rotation:s,pageWidth:r,pageHeight:l,trackedAnnotation:c,children:d,isSelected:g,isDraggable:h,isResizable:p,lockAspectRatio:x=!1,style:v={},vertexConfig:b,selectionMenu:y,outlineOffset:f=1,onDoubleClick:m,onSelect:j,zIndex:k=1,resizeUI:S,vertexUI:M,selectionOutlineColor:A="#007ACC",customAnnotationRenderer:w,...z}){const[D,P]=o.useState(c.object),{provides:R}=u(),C=o.useRef(null),I=o.useMemo(()=>R?R.forDocument(t):null,[R,t]),E=D?{...c.object,...D}:c.object,B=(null==S?void 0:S.color)??"#007ACC",T=(null==M?void 0:M.color)??"#007ACC",$=(null==S?void 0:S.size)??12,L=(null==M?void 0:M.size)??12,{dragProps:F,vertices:O,resize:U}=a.useInteractionHandles({controller:{element:E.rect,vertices:null==b?void 0:b.extractVertices(E),constraints:{minWidth:10,minHeight:10,boundingBox:{width:r,height:l}},maintainAspectRatio:x,pageRotation:s,scale:e,enabled:g,onUpdate:e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type))return;"start"===e.state&&(C.current=E);const o=e.transformData.type,i=C.current??E,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==R?void 0:R.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});r&&P(e=>({...e,...r})),"end"===e.state&&r&&(C.current=null,null==I||I.updateAnnotation(n,c.object.id,r))}},resizeUI:{handleSize:$,spacing:f,offsetMode:"outside",includeSides:!x,zIndex:k+1},vertexUI:{vertexSize:L,zIndex:k+2},includeVertices:!!b}),W=a.useDoublePressProps(m);return o.useEffect(()=>{P(c.object)},[c.object]),i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...h&&g?F:{},...W,style:{position:"absolute",left:E.rect.origin.x*e,top:E.rect.origin.y*e,width:E.rect.size.width*e,height:E.rect.size.height*e,outline:g?`1px solid ${A}`:"none",outlineOffset:g?`${f}px`:"0px",pointerEvents:g?"auto":"none",touchAction:"none",cursor:g&&h?"move":"default",zIndex:k,...v},...z,children:[(()=>{const t="function"==typeof d?d(E):d,o=null==w?void 0:w({annotation:E,children:t,isSelected:g,scale:e,rotation:s,pageWidth:r,pageHeight:l,pageIndex:n,onSelect:j});return null!=o?o:t})(),g&&p&&U.map(({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:B}):i.jsx("div",{...t,style:{...t.style,backgroundColor:B}},e)),g&&O.map(({key:e,...t})=>(null==M?void 0:M.component)?M.component({key:e,...t,backgroundColor:T}):i.jsx("div",{...t,style:{...t.style,backgroundColor:T}},e))]}),y&&i.jsx(a.CounterRotate,{rect:{origin:{x:E.rect.origin.x*e,y:E.rect.origin.y*e},size:{width:E.rect.size.width*e,height:E.rect.size.height*e}},rotation:s,children:e=>y({...e,context:{type:"annotation",annotation:c,pageIndex:n},selected:g,placement:{suggestTop:!1}})})]})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){return i.jsx(i.Fragment,{children:n.map((n,a)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c))})}function v({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s,c=6*s,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*s,top:(o?e.origin.y-o.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n))})}function b({isSelected:e,color:t="#000000",opacity:n=1,strokeWidth:s,inkList:r,rect:l,scale:a,onClick:c}){const d=o.useMemo(()=>r.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-l.origin.x,s=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "}),t.trim()}),[r,l]),u=l.size.width*a,g=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:u,height:g,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:g,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map((o,r)=>i.jsx("path",{d:o,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round"}},r))})}function y({isSelected:e,color:t="#000000",strokeColor:n,opacity:r=1,strokeWidth:l,strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:h,height:p,x:x,y:v}=o.useMemo(()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}},[d,l]),b=(h+l)*u,y=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2},width:b,height:y,viewBox:`0 0 ${h+l} ${p+l}`,children:i.jsx("rect",{x:x,y:v,width:h,height:p,fill:t,opacity:r,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function f({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:r,strokeStyle:l=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:g}){const{width:h,height:p,cx:x,cy:v,rx:b,ry:y}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}},[c,r]),f=h*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${h} ${p}`,children:i.jsx("ellipse",{cx:x,cy:v,rx:b,ry:y,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function m({color:e="transparent",opacity:n=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:g,scale:h,onClick:p,isSelected:x}){const{x1:v,y1:b,x2:y,y2:f}=o.useMemo(()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y}),[u,d]),m=o.useMemo(()=>{const e=Math.atan2(f-b,y-v);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,v,b),end:t.patching.createEnding(null==g?void 0:g.end,r,e,y,f)}},[g,r,v,b,y,f]),j=d.size.width*h,k=d.size.height*h;return i.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[i.jsx("line",{x1:v,y1:b,x2:y,y2:f,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&i.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&i.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function j({rect:e,vertices:n,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const h=o.useMemo(()=>n.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[n,e]),p=o.useMemo(()=>{if(!h.length)return"";const[e,...t]=h;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[h]),x=o.useMemo(()=>{if(h.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(h[0],h[1]),o=e(h[h.length-2],h[h.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,h[0].x,h[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,h[h.length-1].x,h[h.length-1].y)}},[h,g,a]),v=e.size.width*c,b=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2,overflow:"visible"},width:v,height:b,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??s,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&i.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:r,fill:x.start.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&i.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:r,fill:x.end.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({rect:e,vertices:t,color:n="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:h,currentVertex:p,handleSize:x=14}){const v=p?[...t,p]:t,b=o.useMemo(()=>v.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[v,e]),y=o.useMemo(()=>{if(!b.length)return"";const[e,...t]=b,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[b,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return i.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:y,onPointerDown:h,onTouchStart:h,opacity:l,style:{fill:p?"none":n,stroke:r??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),f&&t.length>1&&i.jsx("path",{d:`M ${b[b.length-1].x} ${b[b.length-1].y} L ${b[0].x} ${b[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&i.jsx("rect",{x:b[0].x-x/u/2,y:b[0].y-x/u/2,width:x/u,height:x/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const d=o.useRef(null),{provides:g}=u(),[h,p]=o.useState(!1);o.useEffect(()=>{if(t&&d.current){const e=d.current;e.focus();const t=window.getSelection();if(t){const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}},[t]),o.useLayoutEffect(()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}},[]);const x=n.object.fontSize*l,v=h&&t&&x>0&&x<16,b=v?16:x,y=v?x/16:1,f=v?100/y:100;return i.jsx("div",{style:{position:"absolute",width:n.object.rect.size.width*l,height:n.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:i.jsx("span",{ref:d,onBlur:()=>{g&&d.current&&g.updateAnnotation(r,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:b,fontFamily:s.standardFontCss(n.object.fontFamily),textAlign:s.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===s.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===s.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.backgroundColor,opacity:n.object.opacity,width:v?`${f}%`:"100%",height:v?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${y})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function M({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=u(),[g,h]=o.useState(null),p=o.useRef(null),{width:x,height:v}=r.rect.size;o.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);h(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,x,v]);return i.jsx(n.Fragment,{children:g&&i.jsx("img",{src:g,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function A({isSelected:e,annotation:t,documentId:n,pageIndex:o,scale:s,onClick:r}){return i.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:r,onTouchStart:r,children:i.jsx(M,{documentId:n,pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:s})})}function w(e){const{documentId:a,pageIndex:c,scale:d,selectionMenu:M}=e,{provides:w}=u(),{provides:z}=l.useSelectionCapability(),[D,P]=o.useState([]),{register:R}=r.usePointerHandlers({documentId:a,pageIndex:c}),[C,I]=o.useState(null),[E,B]=o.useState(null),T=o.useMemo(()=>w?w.forDocument(a):null,[w,a]);o.useEffect(()=>{if(T){const e=T.getState();return P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c)),T.onStateChange(e=>{P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c))})}},[T,c]);const $=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&T&&(T.deselectAnnotation(),B(null))}}),[T]),L=o.useCallback((e,t)=>{e.stopPropagation(),T&&z&&(T.selectAnnotation(c,t.object.id),z.clear(),t.object.id!==E&&B(null))},[T,z,E,c]);return o.useEffect(()=>R($,{documentId:a}),[R,$]),i.jsx(i.Fragment,{children:D.map(o=>{const r=(null==C?void 0:C.object.id)===o.object.id,l=E===o.object.id,u=null==T?void 0:T.findToolForAnnotation(o.object);return t.isInk(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquare(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isCircle(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isUnderline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(p,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStrikeout(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquiggly(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isHighlight(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(h,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isLine(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(m,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolyline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolygon(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isFreeText(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:((null==u?void 0:u.interaction.isDraggable)??!0)&&!l,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),B(o.object.id)},...e,children:e=>i.jsx(S,{isSelected:r,isEditing:l,annotation:{...o,object:e},pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStamp(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:r,annotation:o,documentId:a,pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):null})})}function z({documentId:e,pageIndex:t,scale:n}){var r,a,c,d,g,b,y,f,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:A}=u(),[w,z]=o.useState([]),[D,P]=o.useState(null),[R,C]=o.useState(null);if(o.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{z(M.forDocument(e).getHighlightRectsForPage(t)),P(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),o.useEffect(()=>{if(A)return C(A.forDocument(e).getActiveTool()),A.forDocument(e).onActiveToolChange(e=>C(e))},[A,e]),!D)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case s.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=R.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{color:null==(a=R.defaults)?void 0:a.color,opacity:null==(c=R.defaults)?void 0:c.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=R.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(h,{color:null==(g=R.defaults)?void 0:g.color,opacity:null==(b=R.defaults)?void 0:b.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(y=R.defaults)?void 0:y.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{color:null==(f=R.defaults)?void 0:f.color,opacity:null==(m=R.defaults)?void 0:m.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(j=R.defaults)?void 0:j.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(v,{color:null==(k=R.defaults)?void 0:k.color,opacity:null==(S=R.defaults)?void 0:S.opacity,segmentRects:w,scale:n})});default:return null}}function D({preview:e,scale:t}){const{bounds:n}=e,o={position:"absolute",left:n.origin.x*t,top:n.origin.y*t,width:n.size.width*t,height:n.size.height*t,pointerEvents:"none",zIndex:10};return e.type===s.PdfAnnotationSubtype.CIRCLE?i.jsx("div",{style:o,children:i.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.FREETEXT?i.jsx("div",{style:o,children:i.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function P({documentId:e,pageIndex:t,scale:n}){const{plugin:s}=d(),[r,l]=o.useState(new Map),a=o.useRef(null),c=o.useRef(null),u=o.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const n=a.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=c.current;if(!i||!i.getContext)return;const s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),g=l*u,h=a*u;i.width=g,i.height=h,s.drawImage(r,0,0,g,h);const p=s.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:g,height:h})},r.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(s)return s.registerPageHandlers(e,t,n,{services:u,onPreview:(e,t)=>{l(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,n,s,u]),i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:a,type:"file",style:{display:"none"}}),i.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(r.entries()).map(([e,t])=>i.jsx(D,{preview:t,scale:n},e))]})}exports.AnnotationLayer=function({style:t,documentId:n,pageIndex:r,scale:l,rotation:a,selectionMenu:c,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,...p}){var x,v,b,y;const f=e.useDocumentState(n),m=null==(v=null==(x=null==f?void 0:f.document)?void 0:x.pages)?void 0:v[r],j=(null==(b=null==m?void 0:m.size)?void 0:b.width)??0,k=(null==(y=null==m?void 0:m.size)?void 0:y.height)??0,S=o.useMemo(()=>void 0!==l?l:(null==f?void 0:f.scale)??1,[l,null==f?void 0:f.scale]),M=o.useMemo(()=>void 0!==a?a:(null==f?void 0:f.rotation)??s.Rotation.Degree0,[a,null==f?void 0:f.rotation]);return i.jsxs("div",{style:{...t},...p,children:[i.jsx(w,{documentId:n,selectionMenu:c,pageIndex:r,scale:S,rotation:M,pageWidth:j,pageHeight:k,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h}),i.jsx(z,{documentId:n,pageIndex:r,scale:S}),i.jsx(P,{documentId:n,pageIndex:r,scale:S})]})},exports.useAnnotation=e=>{var n;const{provides:i}=u(),[s,r]=o.useState((null==(n=null==i?void 0:i.forDocument(e))?void 0:n.getState())??t.initialDocumentState());return o.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return r(t.getState()),t.onStateChange(e=>{r(e)})},[i,e]),{state:s,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=u,exports.useAnnotationPlugin=d,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|