@embedpdf/plugin-annotation 2.2.0 → 2.3.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 +1196 -92
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +31 -2
- package/dist/lib/annotation-plugin.d.ts +177 -2
- package/dist/lib/handlers/types.d.ts +1 -1
- package/dist/lib/helpers.d.ts +6 -1
- package/dist/lib/selectors.d.ts +97 -8
- package/dist/lib/tools/default-tools.d.ts +39 -11
- package/dist/lib/tools/types.d.ts +7 -1
- package/dist/lib/types.d.ts +265 -1
- package/dist/preact/adapter.d.ts +3 -3
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +857 -403
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +857 -403
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/annotation-container.d.ts +8 -1
- package/dist/shared/components/annotation-layer.d.ts +4 -2
- package/dist/shared/components/annotations/ink.d.ts +3 -3
- package/dist/shared/components/annotations/link.d.ts +28 -0
- package/dist/shared/components/annotations.d.ts +2 -1
- package/dist/shared/components/group-selection-box.d.ts +32 -0
- package/dist/shared/components/index.d.ts +1 -0
- package/dist/shared/components/text-markup/highlight.d.ts +3 -2
- package/dist/shared/components/text-markup/squiggly.d.ts +3 -2
- package/dist/shared/components/text-markup/strikeout.d.ts +3 -2
- package/dist/shared/components/text-markup/underline.d.ts +3 -2
- package/dist/shared/components/types.d.ts +7 -0
- package/dist/shared-preact/components/annotation-container.d.ts +8 -1
- package/dist/shared-preact/components/annotation-layer.d.ts +4 -2
- package/dist/shared-preact/components/annotations/ink.d.ts +3 -3
- package/dist/shared-preact/components/annotations/link.d.ts +28 -0
- package/dist/shared-preact/components/annotations.d.ts +2 -1
- package/dist/shared-preact/components/group-selection-box.d.ts +32 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/text-markup/highlight.d.ts +3 -2
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +3 -2
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +3 -2
- package/dist/shared-preact/components/text-markup/underline.d.ts +3 -2
- package/dist/shared-preact/components/types.d.ts +7 -0
- package/dist/shared-react/components/annotation-container.d.ts +8 -1
- package/dist/shared-react/components/annotation-layer.d.ts +4 -2
- package/dist/shared-react/components/annotations/ink.d.ts +3 -3
- package/dist/shared-react/components/annotations/link.d.ts +28 -0
- package/dist/shared-react/components/annotations.d.ts +2 -1
- package/dist/shared-react/components/group-selection-box.d.ts +32 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/text-markup/highlight.d.ts +3 -2
- package/dist/shared-react/components/text-markup/squiggly.d.ts +3 -2
- package/dist/shared-react/components/text-markup/strikeout.d.ts +3 -2
- package/dist/shared-react/components/text-markup/underline.d.ts +3 -2
- package/dist/shared-react/components/types.d.ts +7 -0
- package/dist/svelte/components/AnnotationLayer.svelte.d.ts +5 -1
- package/dist/svelte/components/Annotations.svelte.d.ts +5 -1
- package/dist/svelte/components/GroupSelectionBox.svelte.d.ts +32 -0
- package/dist/svelte/components/annotations/Ink.svelte.d.ts +2 -1
- package/dist/svelte/components/annotations/Link.svelte.d.ts +24 -0
- package/dist/svelte/components/annotations/index.d.ts +1 -0
- package/dist/svelte/components/index.d.ts +1 -0
- package/dist/svelte/components/text-markup/Highlight.svelte.d.ts +2 -1
- package/dist/svelte/components/text-markup/Squiggly.svelte.d.ts +2 -1
- package/dist/svelte/components/text-markup/Strikeout.svelte.d.ts +2 -1
- package/dist/svelte/components/text-markup/Underline.svelte.d.ts +2 -1
- package/dist/svelte/components/types.d.ts +2 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +905 -255
- package/dist/svelte/index.js.map +1 -1
- package/dist/svelte/types.d.ts +7 -0
- package/dist/vue/components/annotation-container.vue.d.ts +2 -0
- package/dist/vue/components/annotation-layer.vue.d.ts +28 -5
- package/dist/vue/components/annotations/index.d.ts +1 -0
- package/dist/vue/components/annotations/ink.vue.d.ts +2 -2
- package/dist/vue/components/annotations/line.vue.d.ts +1 -1
- package/dist/vue/components/annotations/link.vue.d.ts +29 -0
- package/dist/vue/components/annotations/polygon.vue.d.ts +1 -1
- package/dist/vue/components/annotations/polyline.vue.d.ts +1 -1
- package/dist/vue/components/annotations.vue.d.ts +65 -1
- package/dist/vue/components/group-selection-box.vue.d.ts +73 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/text-markup/highlight.vue.d.ts +2 -2
- package/dist/vue/components/text-markup/squiggly.vue.d.ts +2 -2
- package/dist/vue/components/text-markup/strikeout.vue.d.ts +2 -2
- package/dist/vue/components/text-markup/underline.vue.d.ts +2 -2
- package/dist/vue/hooks/use-annotation.d.ts +2 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +946 -406
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/types.d.ts +7 -0
- package/package.json +10 -10
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
-
import { AnnotationCreateContext, PdfAnnotationObject, PdfAnnotationSubtype, PdfErrorReason, PdfRenderPageAnnotationOptions, PdfTextAnnoObject, Task } from '@embedpdf/models';
|
|
2
|
+
import { AnnotationCreateContext, PdfAnnotationObject, PdfAnnotationSubtype, PdfErrorReason, PdfRenderPageAnnotationOptions, PdfTextAnnoObject, Position, Rect, Size, Task } from '@embedpdf/models';
|
|
3
3
|
import { AnnotationTool } from './tools/types';
|
|
4
4
|
export type AnnotationEvent = {
|
|
5
5
|
type: 'create';
|
|
@@ -34,6 +34,32 @@ export interface TrackedAnnotation<T extends PdfAnnotationObject = PdfAnnotation
|
|
|
34
34
|
commitState: CommitState;
|
|
35
35
|
object: T;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Represents a batch of pending annotation changes to be committed.
|
|
39
|
+
* Separates the collection of changes from their execution.
|
|
40
|
+
*/
|
|
41
|
+
export interface CommitBatch {
|
|
42
|
+
/** Annotations that need to be created in the PDF */
|
|
43
|
+
creations: Array<{
|
|
44
|
+
uid: string;
|
|
45
|
+
ta: TrackedAnnotation;
|
|
46
|
+
ctx?: AnnotationCreateContext<PdfAnnotationObject>;
|
|
47
|
+
}>;
|
|
48
|
+
/** Annotations that need to be updated in the PDF */
|
|
49
|
+
updates: Array<{
|
|
50
|
+
uid: string;
|
|
51
|
+
ta: TrackedAnnotation;
|
|
52
|
+
}>;
|
|
53
|
+
/** Annotations that need to be deleted from the PDF */
|
|
54
|
+
deletions: Array<{
|
|
55
|
+
uid: string;
|
|
56
|
+
ta: TrackedAnnotation;
|
|
57
|
+
}>;
|
|
58
|
+
/** All UIDs that are part of this commit batch */
|
|
59
|
+
committedUids: string[];
|
|
60
|
+
/** Whether this batch has any changes */
|
|
61
|
+
isEmpty: boolean;
|
|
62
|
+
}
|
|
37
63
|
export interface RenderAnnotationOptions {
|
|
38
64
|
pageIndex: number;
|
|
39
65
|
annotation: PdfAnnotationObject;
|
|
@@ -42,6 +68,13 @@ export interface RenderAnnotationOptions {
|
|
|
42
68
|
export interface AnnotationDocumentState {
|
|
43
69
|
pages: Record<number, string[]>;
|
|
44
70
|
byUid: Record<string, TrackedAnnotation>;
|
|
71
|
+
/** Array of selected annotation UIDs (supports multi-selection) */
|
|
72
|
+
selectedUids: string[];
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated Use `selectedUids` array or `getSelectedAnnotation()` instead.
|
|
75
|
+
* Returns the UID only when exactly one annotation is selected, otherwise null.
|
|
76
|
+
* Will be removed in next major version.
|
|
77
|
+
*/
|
|
45
78
|
selectedUid: string | null;
|
|
46
79
|
activeToolId: string | null;
|
|
47
80
|
hasPendingChanges: boolean;
|
|
@@ -96,12 +129,34 @@ export interface AnnotationActiveToolChangeEvent {
|
|
|
96
129
|
documentId: string;
|
|
97
130
|
tool: AnnotationTool | null;
|
|
98
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Represents what grouping action is available for the current selection.
|
|
134
|
+
* - 'group': Selection can be grouped (2+ annotations, not all in same group)
|
|
135
|
+
* - 'ungroup': Selection is exactly one complete group that can be ungrouped
|
|
136
|
+
* - 'disabled': No valid grouping action (0-1 annotations selected)
|
|
137
|
+
*/
|
|
138
|
+
export type GroupingAction = 'group' | 'ungroup' | 'disabled';
|
|
99
139
|
export interface AnnotationScope {
|
|
100
140
|
getState(): AnnotationDocumentState;
|
|
101
141
|
getPageAnnotations(options: GetPageAnnotationsOptions): Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
142
|
+
/** @deprecated Use getSelectedAnnotations() for multi-select support. Returns first selected or null. */
|
|
102
143
|
getSelectedAnnotation(): TrackedAnnotation | null;
|
|
144
|
+
/** Get all selected annotations */
|
|
145
|
+
getSelectedAnnotations(): TrackedAnnotation[];
|
|
146
|
+
/** Get the IDs of all selected annotations */
|
|
147
|
+
getSelectedAnnotationIds(): string[];
|
|
103
148
|
getAnnotationById(id: string): TrackedAnnotation | null;
|
|
149
|
+
/** Select a single annotation (clears previous selection) */
|
|
104
150
|
selectAnnotation(pageIndex: number, annotationId: string): void;
|
|
151
|
+
/** Toggle an annotation in/out of the current selection */
|
|
152
|
+
toggleSelection(pageIndex: number, annotationId: string): void;
|
|
153
|
+
/** Add an annotation to the current selection */
|
|
154
|
+
addToSelection(pageIndex: number, annotationId: string): void;
|
|
155
|
+
/** Remove an annotation from the current selection */
|
|
156
|
+
removeFromSelection(annotationId: string): void;
|
|
157
|
+
/** Set the selection to a specific set of annotation IDs (for marquee) */
|
|
158
|
+
setSelection(ids: string[]): void;
|
|
159
|
+
/** Clear all selection */
|
|
105
160
|
deselectAnnotation(): void;
|
|
106
161
|
getActiveTool(): AnnotationTool | null;
|
|
107
162
|
setActiveTool(toolId: string | null): void;
|
|
@@ -109,9 +164,36 @@ export interface AnnotationScope {
|
|
|
109
164
|
importAnnotations(items: ImportAnnotationItem<PdfAnnotationObject>[]): void;
|
|
110
165
|
createAnnotation<A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>): void;
|
|
111
166
|
updateAnnotation(pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>): void;
|
|
167
|
+
/** Batch update multiple annotations at once */
|
|
168
|
+
updateAnnotations(patches: Array<{
|
|
169
|
+
pageIndex: number;
|
|
170
|
+
id: string;
|
|
171
|
+
patch: Partial<PdfAnnotationObject>;
|
|
172
|
+
}>): void;
|
|
112
173
|
deleteAnnotation(pageIndex: number, annotationId: string): void;
|
|
174
|
+
/** Delete multiple annotations in batch */
|
|
175
|
+
deleteAnnotations(annotations: Array<{
|
|
176
|
+
pageIndex: number;
|
|
177
|
+
id: string;
|
|
178
|
+
}>): void;
|
|
113
179
|
renderAnnotation(options: RenderAnnotationOptions): Task<Blob, PdfErrorReason>;
|
|
114
180
|
commit(): Task<boolean, PdfErrorReason>;
|
|
181
|
+
/** Get link annotations attached to an annotation via IRT relationship */
|
|
182
|
+
getAttachedLinks(annotationId: string): TrackedAnnotation[];
|
|
183
|
+
/** Check if an annotation has attached link children */
|
|
184
|
+
hasAttachedLinks(annotationId: string): boolean;
|
|
185
|
+
/** Delete all link annotations attached to an annotation */
|
|
186
|
+
deleteAttachedLinks(annotationId: string): void;
|
|
187
|
+
/** Group the currently selected annotations (first selected becomes leader) */
|
|
188
|
+
groupAnnotations(): void;
|
|
189
|
+
/** Ungroup all annotations in the group containing the specified annotation */
|
|
190
|
+
ungroupAnnotations(annotationId: string): void;
|
|
191
|
+
/** Get all annotations in the same group as the specified annotation */
|
|
192
|
+
getGroupMembers(annotationId: string): TrackedAnnotation<PdfAnnotationObject>[];
|
|
193
|
+
/** Check if an annotation is part of a group */
|
|
194
|
+
isInGroup(annotationId: string): boolean;
|
|
195
|
+
/** Get the available grouping action for the current selection */
|
|
196
|
+
getGroupingAction(): GroupingAction;
|
|
115
197
|
onStateChange: EventHook<AnnotationDocumentState>;
|
|
116
198
|
onAnnotationEvent: EventHook<AnnotationEvent>;
|
|
117
199
|
onActiveToolChange: EventHook<AnnotationTool | null>;
|
|
@@ -119,16 +201,56 @@ export interface AnnotationScope {
|
|
|
119
201
|
export interface AnnotationCapability {
|
|
120
202
|
getState: () => AnnotationDocumentState;
|
|
121
203
|
getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
204
|
+
/** @deprecated Use getSelectedAnnotations() for multi-select support. Returns first selected or null. */
|
|
122
205
|
getSelectedAnnotation: () => TrackedAnnotation | null;
|
|
206
|
+
/** Get all selected annotations */
|
|
207
|
+
getSelectedAnnotations: () => TrackedAnnotation[];
|
|
208
|
+
/** Get the IDs of all selected annotations */
|
|
209
|
+
getSelectedAnnotationIds: () => string[];
|
|
123
210
|
getAnnotationById(id: string): TrackedAnnotation | null;
|
|
211
|
+
/** Select a single annotation (clears previous selection) */
|
|
124
212
|
selectAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
213
|
+
/** Toggle an annotation in/out of the current selection */
|
|
214
|
+
toggleSelection: (pageIndex: number, annotationId: string) => void;
|
|
215
|
+
/** Add an annotation to the current selection */
|
|
216
|
+
addToSelection: (pageIndex: number, annotationId: string) => void;
|
|
217
|
+
/** Remove an annotation from the current selection */
|
|
218
|
+
removeFromSelection: (annotationId: string) => void;
|
|
219
|
+
/** Set the selection to a specific set of annotation IDs (for marquee) */
|
|
220
|
+
setSelection: (ids: string[]) => void;
|
|
221
|
+
/** Clear all selection */
|
|
125
222
|
deselectAnnotation: () => void;
|
|
126
223
|
importAnnotations: (items: ImportAnnotationItem<PdfAnnotationObject>[]) => void;
|
|
127
224
|
createAnnotation: <A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>) => void;
|
|
128
225
|
updateAnnotation: (pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>) => void;
|
|
226
|
+
/** Batch update multiple annotations at once */
|
|
227
|
+
updateAnnotations: (patches: Array<{
|
|
228
|
+
pageIndex: number;
|
|
229
|
+
id: string;
|
|
230
|
+
patch: Partial<PdfAnnotationObject>;
|
|
231
|
+
}>) => void;
|
|
129
232
|
deleteAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
233
|
+
/** Delete multiple annotations in batch */
|
|
234
|
+
deleteAnnotations: (annotations: Array<{
|
|
235
|
+
pageIndex: number;
|
|
236
|
+
id: string;
|
|
237
|
+
}>, documentId?: string) => void;
|
|
130
238
|
renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
|
|
131
239
|
commit: () => Task<boolean, PdfErrorReason>;
|
|
240
|
+
/** Get link annotations attached to an annotation via IRT relationship */
|
|
241
|
+
getAttachedLinks: (annotationId: string, documentId?: string) => TrackedAnnotation[];
|
|
242
|
+
/** Check if an annotation has attached link children */
|
|
243
|
+
hasAttachedLinks: (annotationId: string, documentId?: string) => boolean;
|
|
244
|
+
/** Delete all link annotations attached to an annotation */
|
|
245
|
+
deleteAttachedLinks: (annotationId: string, documentId?: string) => void;
|
|
246
|
+
/** Group the currently selected annotations (first selected becomes leader) */
|
|
247
|
+
groupAnnotations: (documentId?: string) => void;
|
|
248
|
+
/** Ungroup all annotations in the group containing the specified annotation */
|
|
249
|
+
ungroupAnnotations: (annotationId: string, documentId?: string) => void;
|
|
250
|
+
/** Get all annotations in the same group as the specified annotation */
|
|
251
|
+
getGroupMembers: (annotationId: string, documentId?: string) => TrackedAnnotation<PdfAnnotationObject>[];
|
|
252
|
+
/** Check if an annotation is part of a group */
|
|
253
|
+
isInGroup: (annotationId: string, documentId?: string) => boolean;
|
|
132
254
|
forDocument: (documentId: string) => AnnotationScope;
|
|
133
255
|
getActiveTool: () => AnnotationTool | null;
|
|
134
256
|
setActiveTool: (toolId: string | null) => void;
|
|
@@ -162,3 +284,145 @@ export interface SidebarAnnotationEntry {
|
|
|
162
284
|
annotation: TrackedAnnotation;
|
|
163
285
|
replies: TrackedAnnotation<PdfTextAnnoObject>[];
|
|
164
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Information about an annotation needed for constraint calculation.
|
|
289
|
+
*/
|
|
290
|
+
export interface AnnotationConstraintInfo {
|
|
291
|
+
id: string;
|
|
292
|
+
rect: Rect;
|
|
293
|
+
pageIndex: number;
|
|
294
|
+
pageSize: Size;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Combined constraints representing the intersection of all selected annotations' movement limits.
|
|
298
|
+
* These are the maximum distances the group can move in each direction without any annotation
|
|
299
|
+
* leaving its page bounds.
|
|
300
|
+
*/
|
|
301
|
+
export interface CombinedConstraints {
|
|
302
|
+
/** Maximum distance we can move up (positive = can move up) */
|
|
303
|
+
maxUp: number;
|
|
304
|
+
/** Maximum distance we can move down */
|
|
305
|
+
maxDown: number;
|
|
306
|
+
/** Maximum distance we can move left */
|
|
307
|
+
maxLeft: number;
|
|
308
|
+
/** Maximum distance we can move right */
|
|
309
|
+
maxRight: number;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Options for starting a unified drag operation.
|
|
313
|
+
* The plugin will automatically expand to include attached links.
|
|
314
|
+
*/
|
|
315
|
+
export interface UnifiedDragOptions {
|
|
316
|
+
/** The explicitly selected/dragged annotation IDs */
|
|
317
|
+
annotationIds: string[];
|
|
318
|
+
/** Page size for constraint calculation */
|
|
319
|
+
pageSize: Size;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* State of the unified drag operation.
|
|
323
|
+
* Managed entirely by the plugin - framework components just subscribe.
|
|
324
|
+
*/
|
|
325
|
+
export interface UnifiedDragState {
|
|
326
|
+
/** The document this drag belongs to */
|
|
327
|
+
documentId: string;
|
|
328
|
+
/** Whether a drag is currently in progress */
|
|
329
|
+
isDragging: boolean;
|
|
330
|
+
/** The explicitly selected annotation IDs (what the user selected) */
|
|
331
|
+
primaryIds: string[];
|
|
332
|
+
/** Auto-expanded attached link IDs */
|
|
333
|
+
attachedLinkIds: string[];
|
|
334
|
+
/** All participant IDs (primaryIds + attachedLinkIds) */
|
|
335
|
+
allParticipantIds: string[];
|
|
336
|
+
/** Original rects for all participants (for computing final patches) */
|
|
337
|
+
originalRects: Map<string, Rect>;
|
|
338
|
+
/** Current cumulative delta (already clamped to constraints) */
|
|
339
|
+
delta: Position;
|
|
340
|
+
/** Combined constraints computed at drag start */
|
|
341
|
+
combinedConstraints: CombinedConstraints;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Event emitted when unified drag state changes.
|
|
345
|
+
*/
|
|
346
|
+
export interface UnifiedDragEvent {
|
|
347
|
+
/** The document this event belongs to */
|
|
348
|
+
documentId: string;
|
|
349
|
+
/** The type of change */
|
|
350
|
+
type: 'start' | 'update' | 'end' | 'cancel';
|
|
351
|
+
/** Current state */
|
|
352
|
+
state: UnifiedDragState;
|
|
353
|
+
/** Pre-computed patches for ALL participants - components just apply directly! */
|
|
354
|
+
previewPatches: Record<string, Partial<PdfAnnotationObject>>;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Options for starting a unified resize operation.
|
|
358
|
+
* The plugin will automatically expand to include attached links.
|
|
359
|
+
*/
|
|
360
|
+
export interface UnifiedResizeOptions {
|
|
361
|
+
/** The explicitly selected annotation IDs */
|
|
362
|
+
annotationIds: string[];
|
|
363
|
+
/** Page size for constraint calculation */
|
|
364
|
+
pageSize: Size;
|
|
365
|
+
/** Which resize handle is being used */
|
|
366
|
+
resizeHandle: string;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Information about an annotation participating in unified resize.
|
|
370
|
+
*/
|
|
371
|
+
export interface UnifiedResizeAnnotationInfo {
|
|
372
|
+
id: string;
|
|
373
|
+
originalRect: Rect;
|
|
374
|
+
pageIndex: number;
|
|
375
|
+
/** Whether this is an attached link (auto-expanded) */
|
|
376
|
+
isAttachedLink: boolean;
|
|
377
|
+
/** The parent annotation ID (if this is an attached link) */
|
|
378
|
+
parentId?: string;
|
|
379
|
+
/** Relative X position within group (0-1) */
|
|
380
|
+
relativeX: number;
|
|
381
|
+
/** Relative Y position within group (0-1) */
|
|
382
|
+
relativeY: number;
|
|
383
|
+
/** Relative width within group (0-1) */
|
|
384
|
+
relativeWidth: number;
|
|
385
|
+
/** Relative height within group (0-1) */
|
|
386
|
+
relativeHeight: number;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* State of the unified resize operation.
|
|
390
|
+
* Managed entirely by the plugin - framework components just subscribe.
|
|
391
|
+
*/
|
|
392
|
+
export interface UnifiedResizeState {
|
|
393
|
+
/** The document this resize belongs to */
|
|
394
|
+
documentId: string;
|
|
395
|
+
/** Whether a resize is currently in progress */
|
|
396
|
+
isResizing: boolean;
|
|
397
|
+
/** The explicitly selected annotation IDs (what the user selected) */
|
|
398
|
+
primaryIds: string[];
|
|
399
|
+
/** Auto-expanded attached link IDs */
|
|
400
|
+
attachedLinkIds: string[];
|
|
401
|
+
/** All participant IDs (primaryIds + attachedLinkIds) */
|
|
402
|
+
allParticipantIds: string[];
|
|
403
|
+
/** The original group bounding box at resize start */
|
|
404
|
+
originalGroupBox: Rect;
|
|
405
|
+
/** The current (resized) group bounding box */
|
|
406
|
+
currentGroupBox: Rect;
|
|
407
|
+
/** All annotations participating with their relative positions */
|
|
408
|
+
participatingAnnotations: UnifiedResizeAnnotationInfo[];
|
|
409
|
+
/** Which resize handle is being used */
|
|
410
|
+
resizeHandle: string;
|
|
411
|
+
/** Current computed rects for all participants */
|
|
412
|
+
computedRects: Map<string, Rect>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Event emitted when unified resize state changes.
|
|
416
|
+
*/
|
|
417
|
+
export interface UnifiedResizeEvent {
|
|
418
|
+
/** The document this event belongs to */
|
|
419
|
+
documentId: string;
|
|
420
|
+
/** The type of change */
|
|
421
|
+
type: 'start' | 'update' | 'end' | 'cancel';
|
|
422
|
+
/** Current state */
|
|
423
|
+
state: UnifiedResizeState;
|
|
424
|
+
/** Per-annotation computed rects for convenience (id -> new rect) */
|
|
425
|
+
computedRects: Record<string, Rect>;
|
|
426
|
+
/** Pre-computed patches for ALL participants - components just apply directly! */
|
|
427
|
+
previewPatches: Record<string, Partial<PdfAnnotationObject>>;
|
|
428
|
+
}
|
package/dist/preact/adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { JSX, Fragment } from 'preact';
|
|
2
|
-
export { useEffect, useRef, useState, useCallback, useMemo, useLayoutEffect } from 'preact/hooks';
|
|
1
|
+
import { JSX, Fragment, createContext } from 'preact';
|
|
2
|
+
export { useEffect, useRef, useState, useCallback, useMemo, useLayoutEffect, useContext, } from 'preact/hooks';
|
|
3
3
|
export type { ComponentChildren as ReactNode, JSX } from 'preact';
|
|
4
|
-
export { Fragment };
|
|
4
|
+
export { Fragment, createContext };
|
|
5
5
|
export type CSSProperties = import('preact').JSX.CSSProperties;
|
|
6
6
|
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
|
7
7
|
export type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;
|
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 g({scale:t,documentId:n,pageIndex:s,rotation:r,pageWidth:l,pageHeight:c,trackedAnnotation:d,children:g,isSelected:h,isDraggable:p,isResizable:x,lockAspectRatio:v=!1,style:b={},vertexConfig:y,selectionMenu:f,outlineOffset:m=1,onDoubleClick:j,onSelect:k,zIndex:S=1,resizeUI:M,vertexUI:A,selectionOutlineColor:w="#007ACC",customAnnotationRenderer:z,...D}){const[P,R]=o.useState(d.object),{provides:C}=u(),{canModifyAnnotations:I}=e.useDocumentPermissions(n),E=o.useRef(null),B=I&&p,T=I&&x,$=o.useMemo(()=>C?C.forDocument(n):null,[C,n]),L=P?{...d.object,...P}:d.object,F=(null==M?void 0:M.color)??"#007ACC",O=(null==A?void 0:A.color)??"#007ACC",U=(null==M?void 0:M.size)??12,W=(null==A?void 0:A.size)??12,{dragProps:H,vertices:N,resize:q}=a.useInteractionHandles({controller:{element:L.rect,vertices:null==y?void 0:y.extractVertices(L),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:c}},maintainAspectRatio:v,pageRotation:r,scale:t,enabled:h,onUpdate:e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type))return;"start"===e.state&&(E.current=L);const n=e.transformData.type,o=E.current??L,i=e.transformData.changes.vertices?null==y?void 0:y.transformAnnotation(o,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==C?void 0:C.transformAnnotation(o,{type:n,changes:i,metadata:e.transformData.metadata});r&&R(e=>({...e,...r})),"end"===e.state&&r&&(E.current=null,null==$||$.updateAnnotation(s,d.object.id,r))}},resizeUI:{handleSize:U,spacing:m,offsetMode:"outside",includeSides:!v,zIndex:S+1},vertexUI:{vertexSize:W,zIndex:S+2},includeVertices:!!y}),V=o.useMemo(()=>{if(I&&j)return j},[I,j]),G=a.useDoublePressProps(V);return o.useEffect(()=>{R(d.object)},[d.object]),i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...B&&h?H:{},...G,style:{position:"absolute",left:L.rect.origin.x*t,top:L.rect.origin.y*t,width:L.rect.size.width*t,height:L.rect.size.height*t,outline:h?`1px solid ${w}`:"none",outlineOffset:h?`${m}px`:"0px",pointerEvents:h?"auto":"none",touchAction:"none",cursor:h&&B?"move":"default",zIndex:S,...b},...D,children:[(()=>{const e="function"==typeof g?g(L):g,n=null==z?void 0:z({annotation:L,children:e,isSelected:h,scale:t,rotation:r,pageWidth:l,pageHeight:c,pageIndex:s,onSelect:k});return null!=n?n:e})(),h&&T&&q.map(({key:e,...t})=>(null==M?void 0:M.component)?M.component({key:e,...t,backgroundColor:F}):i.jsx("div",{...t,style:{...t.style,backgroundColor:F}},e)),h&&I&&N.map(({key:e,...t})=>(null==A?void 0:A.component)?A.component({key:e,...t,backgroundColor:O}):i.jsx("div",{...t,style:{...t.style,backgroundColor:O}},e))]}),f&&i.jsx(a.CounterRotate,{rect:{origin:{x:L.rect.origin.x*t,y:L.rect.origin.y*t},size:{width:L.rect.size.width*t,height:L.rect.size.height*t}},rotation:r,children:e=>f({...e,context:{type:"annotation",annotation:d,pageIndex:s},selected:h,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]})});
|
|
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"),r=require("@embedpdf/models"),s=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:t,documentId:n,pageIndex:r,rotation:s,pageWidth:l,pageHeight:c,trackedAnnotation:g,children:h,isSelected:p,isMultiSelected:x=!1,isDraggable:f,isResizable:v,lockAspectRatio:b=!1,style:y={},vertexConfig:m,selectionMenu:j,outlineOffset:k=1,onDoubleClick:S,onSelect:M,zIndex:z=1,resizeUI:A,vertexUI:w,selectionOutlineColor:C="#007ACC",customAnnotationRenderer:D,...R}){const[I,P]=o.useState(g.object),{provides:E}=u(),{plugin:B}=d(),{canModifyAnnotations:T}=e.useDocumentPermissions(n),$=o.useRef(null),L=T&&f&&!x,F=T&&v&&!x,U=o.useMemo(()=>E?E.forDocument(n):null,[E,n]),O=I?{...g.object,...I}:g.object,W=(null==A?void 0:A.color)??"#007ACC",H=(null==w?void 0:w.color)??"#007ACC",N=(null==A?void 0:A.size)??12,q=(null==w?void 0:w.size)??12,V=o.useRef(null),G=o.useCallback(e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type)||x||!B)return;const{type:o,changes:i,metadata:s}=e.transformData,a=g.object.id,d={width:l,height:c};if("start"===e.state&&(V.current=g.object.rect,$.current=g.object,"move"===o?B.startDrag(n,{annotationIds:[a],pageSize:d}):"resize"===o&&B.startResize(n,{annotationIds:[a],pageSize:d,resizeHandle:(null==s?void 0:s.handle)??"se"})),i.rect&&V.current)if("move"===o){const e={x:i.rect.origin.x-V.current.origin.x,y:i.rect.origin.y-V.current.origin.y};B.updateDrag(n,e)}else"resize"===o&&B.updateResize(n,i.rect);if("vertex-edit"===o&&i.vertices&&m){const t=$.current??g.object,n=m.transformAnnotation(t,i.vertices),l=null==E?void 0:E.transformAnnotation(t,{type:o,changes:n,metadata:s});l&&(P(e=>({...e,...l})),"end"===e.state&&(null==U||U.updateAnnotation(r,a,l)))}"end"===e.state&&(V.current=null,$.current=null,"move"===o?B.commitDrag(n):"resize"===o&&B.commitResize(n))},[B,n,g.object,l,c,r,x,m,E,U]),{dragProps:K,vertices:Y,resize:Q}=a.useInteractionHandles({controller:{element:O.rect,vertices:null==m?void 0:m.extractVertices(O),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:c}},maintainAspectRatio:b,pageRotation:s,scale:t,enabled:p&&!x,onUpdate:G},resizeUI:{handleSize:N,spacing:k,offsetMode:"outside",includeSides:!b,zIndex:z+1},vertexUI:{vertexSize:q,zIndex:z+2},includeVertices:!!m}),X=o.useMemo(()=>{if(T&&S)return S},[T,S]),Z=a.useDoublePressProps(X);o.useEffect(()=>{P(g.object)},[g.object]),o.useEffect(()=>{if(!B)return;const e=g.object.id,t=t=>{var o;if(t.documentId!==n)return;const i=null==(o=t.previewPatches)?void 0:o[e];"update"===t.type&&i?P(e=>({...e,...i})):"cancel"===t.type&&P(g.object)},o=[B.onDragChange(t),B.onResizeChange(t)];return()=>o.forEach(e=>e())},[B,n,g.object]);const J=p&&!x;return i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...L&&p?K:{},...Z,style:{position:"absolute",left:O.rect.origin.x*t,top:O.rect.origin.y*t,width:O.rect.size.width*t,height:O.rect.size.height*t,outline:J?`1px solid ${C}`:"none",outlineOffset:J?`${k}px`:"0px",pointerEvents:p&&!x?"auto":"none",touchAction:"none",cursor:p&&L?"move":"default",zIndex:z,...y},...R,children:[(()=>{const e="function"==typeof h?h(O):h,n=null==D?void 0:D({annotation:O,children:e,isSelected:p,scale:t,rotation:s,pageWidth:l,pageHeight:c,pageIndex:r,onSelect:M});return null!=n?n:e})(),p&&F&&Q.map(({key:e,...t})=>(null==A?void 0:A.component)?A.component({key:e,...t,backgroundColor:W}):i.jsx("div",{...t,style:{...t.style,backgroundColor:W}},e)),p&&T&&!x&&Y.map(({key:e,...t})=>(null==w?void 0:w.component)?w.component({key:e,...t,backgroundColor:H}):i.jsx("div",{...t,style:{...t.style,backgroundColor:H}},e))]}),j&&!x&&i.jsx(a.CounterRotate,{rect:{origin:{x:O.rect.origin.x*t,y:O.rect.origin.y*t},size:{width:O.rect.size.width*t,height:O.rect.size.height*t}},rotation:s,children:e=>j({...e,context:{type:"annotation",annotation:g,pageIndex:r},selected:p,placement:{suggestTop:!1}})})]})}function h({documentId:e,pageIndex:t,scale:n,rotation:s,pageWidth:l,pageHeight:c,selectedAnnotations:u,isDraggable:g,isResizable:h,resizeUI:p,selectionOutlineColor:x="#007ACC",outlineOffset:f=2,zIndex:v=100,groupSelectionMenu:b}){const{plugin:y}=d(),m=o.useRef(null),j=o.useRef(!1),k=o.useRef(!1),S=o.useMemo(()=>{const e=u.map(e=>e.object.rect);return r.boundingRectOrEmpty(e)},[u]),[M,z]=o.useState(S);o.useEffect(()=>{j.current||k.current||z(S)},[S]);const A=o.useCallback(t=>{var n,o;if(!(null==(n=t.transformData)?void 0:n.type))return;if(!y)return;const i=t.transformData.type,r="move"===i,s="resize"===i;if(r&&!g)return;"start"===t.state&&(m.current=S,r?(j.current=!0,y.startDrag(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:l,height:c}})):s&&(k.current=!0,y.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:l,height:c},resizeHandle:(null==(o=t.transformData.metadata)?void 0:o.handle)??"se"})));const a=m.current??S;if(r&&t.transformData.changes.rect){const n=t.transformData.changes.rect,o={x:n.origin.x-a.origin.x,y:n.origin.y-a.origin.y},i=y.updateDrag(e,o);z({...a,origin:{x:a.origin.x+i.x,y:a.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const n=t.transformData.changes.rect;y.updateResize(e,n),z(n)}"end"===t.state&&(m.current=null,r&&j.current?(j.current=!1,y.commitDrag(e)):s&&k.current&&(k.current=!1,y.commitResize(e)))},[y,e,l,c,S,g,u]),w=(null==p?void 0:p.color)??"#007ACC",C=(null==p?void 0:p.size)??12,{dragProps:D,resize:R}=a.useInteractionHandles({controller:{element:M,constraints:{minWidth:20,minHeight:20,boundingBox:{width:l,height:c}},maintainAspectRatio:!1,pageRotation:s,scale:n,enabled:!0,onUpdate:A},resizeUI:{handleSize:C,spacing:f,offsetMode:"outside",includeSides:!0,zIndex:v+1},vertexUI:{vertexSize:0,zIndex:v},includeVertices:!1});return u.length<2?null:i.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[i.jsx("div",{...g?D:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:M.origin.x*n,top:M.origin.y*n,width:M.size.width*n,height:M.size.height*n,outline:`2px dashed ${x}`,outlineOffset:f-1,cursor:g?"move":"default",touchAction:"none",zIndex:v},children:h&&R.map(({key:e,...t})=>(null==p?void 0:p.component)?p.component({key:e,...t,backgroundColor:w}):i.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),b&&i.jsx(a.CounterRotate,{rect:{origin:{x:M.origin.x*n,y:M.origin.y*n},size:{width:M.size.width*n,height:M.size.height*n}},rotation:s,children:e=>b({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function p({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:a,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l}},n))})}function x({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:a,opacity:t,pointerEvents:"none"}})},n))})}function f({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:a,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},n))})}function v({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=2*r,c=6*r,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??"#FFFF00"}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?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,strokeColor:t,opacity:n=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=o.useMemo(()=>s.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-l.origin.x,r=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "}),t.trim()}),[s,l]),g=l.size.width*a,h=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:g,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:g,height:h,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:u.map((t,o)=>i.jsx("path",{d:t,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},o))})}function y({isSelected:e,color:t="#000000",strokeColor:n,opacity:s=1,strokeWidth:l,strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:h,height:p,x:x,y:f}=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]),v=(h+l)*u,b=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2},width:v,height:b,viewBox:`0 0 ${h+l} ${p+l}`,children:i.jsx("rect",{x:x,y:f,width:h,height:p,fill:t,opacity:s,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function m({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:s,strokeStyle:l=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:g}){const{width:h,height:p,cx:x,cy:f,rx:v,ry:b}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}},[c,s]),y=h*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:y,height:m,pointerEvents:"none",zIndex:2},width:y,height:m,viewBox:`0 0 ${h} ${p}`,children:i.jsx("ellipse",{cx:x,cy:f,rx:v,ry:b,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...l===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function j({color:e="transparent",opacity:n=1,strokeWidth:s,strokeColor:l="#000000",strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:g,scale:h,onClick:p,isSelected:x}){const{x1:f,y1:v,x2:b,y2:y}=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(y-v,b-f);return{start:t.patching.createEnding(null==g?void 0:g.start,s,e+Math.PI,f,v),end:t.patching.createEnding(null==g?void 0:g.end,s,e,b,y)}},[g,s,f,v,b,y]),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:f,y1:v,x2:b,y2:y,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:s,strokeLinecap:"butt",...a===r.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:s,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===r.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:s,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function k({rect:e,vertices:n,color:r="transparent",strokeColor:s="#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]),f=e.size.width*c,v=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2,overflow:"visible"},width:f,height:v,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:s??r,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:s,fill:x.start.filled?r:"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:s,fill:x.end.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function S({rect:e,vertices:t,color:n="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:h,currentVertex:p,handleSize:x=14}){const f=p?[...t,p]:t,v=o.useMemo(()=>f.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[f,e]),b=o.useMemo(()=>{if(!v.length)return"";const[e,...t]=v,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[v,p]),y=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:b,onPointerDown:h,onTouchStart:h,opacity:l,style:{fill:p?"none":n,stroke:s??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),y&&t.length>1&&i.jsx("path",{d:`M ${v[v.length-1].x} ${v[v.length-1].y} L ${v[0].x} ${v[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),y&&t.length>=2&&i.jsx("rect",{x:v[0].x-x/u/2,y:v[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function M({isSelected:e,isEditing:t,annotation:n,pageIndex:s,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,f=h&&t&&x>0&&x<16,v=f?16:x,b=f?x/16:1,y=f?100/b: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(s,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:v,fontFamily:r.standardFontCss(n.object.fontFamily),textAlign:r.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===r.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===r.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.color??n.object.backgroundColor,opacity:n.object.opacity,width:f?`${y}%`:"100%",height:f?`${y}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:f?`scale(${b})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function z({documentId:e,pageIndex:t,annotation:s,scaleFactor:l=1,style:a,...c}){const{provides:d}=u(),[g,h]=o.useState(null),p=o.useRef(null),{width:x,height:f}=s.rect.size;o.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:s,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);h(t),p.current=t},r.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:r.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,s.id,x,f]);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:r,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(z,{documentId:n,pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function w({isSelected:e,strokeColor:t="#0000FF",strokeWidth:n=2,strokeStyle:s=r.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:h}=o.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),p=g*c,x=h*c,f=o.useMemo(()=>{if(s===r.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*n},${n}`},[s,l,n]),v=s===r.PdfAnnotationBorderStyle.UNDERLINE;return i.jsxs("svg",{style:{position:"absolute",width:p,height:x,pointerEvents:"none",zIndex:2},width:p,height:x,viewBox:`0 0 ${g} ${h}`,children:[i.jsx("rect",{x:0,y:0,width:g,height:h,fill:"transparent",onPointerDown:u?void 0:d,onTouchStart:u?void 0:d,style:{cursor:u?"default":e?"move":"pointer",pointerEvents:u||e?"none":"visible"}}),v?i.jsx("line",{x1:1,y1:h-1,x2:g-1,y2:h-1,stroke:t,strokeWidth:n,strokeDasharray:f,style:{pointerEvents:"none"}}):i.jsx("rect",{x:n/2,y:n/2,width:Math.max(g-n,0),height:Math.max(h-n,0),fill:"transparent",stroke:t,strokeWidth:n,strokeDasharray:f,style:{pointerEvents:"none"}})]})}function C(e){const{documentId:a,pageIndex:c,scale:d,pageWidth:z,pageHeight:C,selectionMenu:D}=e,{provides:R}=u(),{provides:I}=l.useSelectionCapability(),[P,E]=o.useState([]),{register:B}=s.usePointerHandlers({documentId:a,pageIndex:c}),[T,$]=o.useState([]),[L,F]=o.useState(null),U=o.useMemo(()=>R?R.forDocument(a):null,[R,a]),O=T.length>1;o.useEffect(()=>{if(U){const e=U.getState();return E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e)),U.onStateChange(e=>{E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e))})}},[U,c]);const W=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&U&&(U.deselectAnnotation(),F(null))}}),[U]),H=o.useCallback((e,t)=>{if(e.stopPropagation(),U&&I){I.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?U.toggleSelection(c,t.object.id):U.selectAnnotation(c,t.object.id),t.object.id!==L&&F(null)}},[U,I,L,c]),N=o.useCallback((e,t)=>{if(e.stopPropagation(),U&&I){if(I.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,n=P.find(t=>t.object.id===e);if(n)return void U.selectAnnotation(n.object.pageIndex,e)}U.selectAnnotation(c,t.object.id)}},[U,I,P,c]);o.useEffect(()=>B(W,{documentId:a}),[B,W]);const q=o.useMemo(()=>P.filter(e=>T.includes(e.object.id)),[P,T]),V=o.useMemo(()=>!(q.length<2)&&q.every(e=>{const t=null==U?void 0:U.findToolForAnnotation(e.object);return(null==t?void 0:t.interaction.isGroupDraggable)??(null==t?void 0:t.interaction.isDraggable)??!0}),[q,U]),G=o.useMemo(()=>!(q.length<2)&&q.every(e=>{const t=null==U?void 0:U.findToolForAnnotation(e.object);return(null==t?void 0:t.interaction.isGroupResizable)??(null==t?void 0:t.interaction.isResizable)??!0}),[q,U]),K=o.useMemo(()=>{if(!U)return!1;const e=U.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===c)},[U,c,T]);return i.jsxs(i.Fragment,{children:[P.map(o=>{const s=T.includes(o.object.id),l=L===o.object.id,u=null==U?void 0:U.findToolForAnnotation(o.object);if(t.isInk(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isSquare(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isCircle(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(m,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isUnderline(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isStrikeout(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isSquiggly(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isHighlight(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(p,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isLine(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isPolyline(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isPolygon(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(S,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isFreeText(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),F(o.object.id)},...e,children:e=>i.jsx(M,{isSelected:s,isEditing:l,annotation:{...o,object:e},pageIndex:c,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isStamp(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,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=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:s,annotation:o,documentId:a,pageIndex:c,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isLink(o)){const t=!!o.object.inReplyToId;return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:D,onSelect:e=>N(e,o),...e,children:e=>i.jsx(w,{...e,isSelected:s,scale:d,onClick:e=>N(e,o),hasIRT:t})},o.object.id)}return null}),K&&q.length>=2&&i.jsx(h,{documentId:a,pageIndex:c,scale:d,rotation:e.rotation,pageWidth:z,pageHeight:C,selectedAnnotations:q,isDraggable:V,isResizable:G,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function D({documentId:e,pageIndex:t,scale:n}){var s,a,c,d,g,h,b,y,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:z}=u(),[A,w]=o.useState([]),[C,D]=o.useState(null),[R,I]=o.useState(null);if(o.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{w(M.forDocument(e).getHighlightRectsForPage(t)),D(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),o.useEffect(()=>{if(z)return I(z.forDocument(e).getActiveTool()),z.forDocument(e).onActiveToolChange(e=>I(e))},[z,e]),!C)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case r.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(s=R.defaults)?void 0:s.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{strokeColor:null==(a=R.defaults)?void 0:a.strokeColor,opacity:null==(c=R.defaults)?void 0:c.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(d=R.defaults)?void 0:d.blendMode)??r.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{strokeColor:null==(g=R.defaults)?void 0:g.strokeColor,opacity:null==(h=R.defaults)?void 0:h.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(b=R.defaults)?void 0:b.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(f,{strokeColor:null==(y=R.defaults)?void 0:y.strokeColor,opacity:null==(m=R.defaults)?void 0:m.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(j=R.defaults)?void 0:j.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(v,{strokeColor:null==(k=R.defaults)?void 0:k.strokeColor,opacity:null==(S=R.defaults)?void 0:S.opacity,segmentRects:A,scale:n})});default:return null}}function R({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===r.PdfAnnotationSubtype.CIRCLE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===r.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 I({documentId:e,pageIndex:t,scale:n}){const{plugin:r}=d(),[s,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 r=i.getContext("2d");if(!r)return;const s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;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,r.drawImage(s,0,0,g,h);const p=r.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(s.src),o({imageData:p,width:g,height:h})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(r)return r.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,r,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(s.entries()).map(([e,t])=>i.jsx(R,{preview:t,scale:n},e))]})}exports.AnnotationLayer=function({style:t,documentId:n,pageIndex:s,scale:l,rotation:a,selectionMenu:c,groupSelectionMenu:d,resizeUI:u,vertexUI:g,selectionOutlineColor:h,customAnnotationRenderer:p,...x}){var f,v,b,y;const m=e.useDocumentState(n),j=null==(v=null==(f=null==m?void 0:m.document)?void 0:f.pages)?void 0:v[s],k=(null==(b=null==j?void 0:j.size)?void 0:b.width)??0,S=(null==(y=null==j?void 0:j.size)?void 0:y.height)??0,M=o.useMemo(()=>void 0!==l?l:(null==m?void 0:m.scale)??1,[l,null==m?void 0:m.scale]),z=o.useMemo(()=>void 0!==a?a:(null==m?void 0:m.rotation)??r.Rotation.Degree0,[a,null==m?void 0:m.rotation]);return i.jsxs("div",{style:{...t},...x,children:[i.jsx(C,{documentId:n,selectionMenu:c,groupSelectionMenu:d,pageIndex:s,scale:M,rotation:z,pageWidth:k,pageHeight:S,resizeUI:u,vertexUI:g,selectionOutlineColor:h,customAnnotationRenderer:p}),i.jsx(D,{documentId:n,pageIndex:s,scale:M}),i.jsx(I,{documentId:n,pageIndex:s,scale:M})]})},exports.GroupSelectionBox=h,exports.useAnnotation=e=>{var n;const{provides:i}=u(),[r,s]=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 s(t.getState()),t.onStateChange(e=>{s(e)})},[i,e]),{state:r,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
|