@embedpdf/plugin-annotation 1.1.1 → 1.2.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 +1916 -390
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +21 -15
- package/dist/lib/annotation-plugin.d.ts +30 -7
- package/dist/lib/handlers/circle.handler.d.ts +3 -0
- package/dist/lib/handlers/click-detector.d.ts +27 -0
- package/dist/lib/handlers/free-text.handler.d.ts +3 -0
- package/dist/lib/handlers/index.d.ts +8 -0
- package/dist/lib/handlers/ink.handler.d.ts +3 -0
- package/dist/lib/handlers/line.handler.d.ts +3 -0
- package/dist/lib/handlers/polygon.handler.d.ts +3 -0
- package/dist/lib/handlers/polyline.handler.d.ts +3 -0
- package/dist/lib/handlers/square.handler.d.ts +3 -0
- package/dist/lib/handlers/stamp.handler.d.ts +3 -0
- package/dist/lib/handlers/types.d.ts +139 -0
- package/dist/lib/helpers.d.ts +1 -6
- package/dist/lib/index.d.ts +3 -1
- package/dist/lib/patching/index.d.ts +1 -1
- package/dist/lib/patching/patch-registry.d.ts +27 -0
- package/dist/lib/patching/patches/index.d.ts +4 -0
- package/dist/lib/patching/patches/ink.patch.d.ts +3 -0
- package/dist/lib/patching/patches/line.patch.d.ts +3 -0
- package/dist/lib/patching/patches/polygon.patch.d.ts +3 -0
- package/dist/lib/patching/patches/polyline.patch.d.ts +3 -0
- package/dist/lib/selectors.d.ts +8 -12
- package/dist/lib/tools/default-tools.d.ts +450 -0
- package/dist/lib/tools/tools-utils.d.ts +25 -0
- package/dist/lib/tools/types.d.ts +96 -0
- package/dist/lib/types.d.ts +78 -161
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/use-state.d.ts +12 -0
- package/dist/preact/adapter.d.ts +1 -5
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +390 -1795
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -4
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +391 -1794
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +18 -16
- package/dist/shared-preact/components/annotation-layer.d.ts +9 -2
- package/dist/shared-preact/components/annotation-paint-layer.d.ts +6 -0
- package/dist/shared-preact/components/annotations/free-text.d.ts +1 -0
- package/dist/shared-preact/components/annotations/polygon.d.ts +4 -1
- package/dist/shared-preact/components/annotations.d.ts +4 -1
- package/dist/shared-preact/components/preview-renderer.d.ts +7 -0
- package/dist/shared-preact/components/text-markup/highlight.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/underline.d.ts +2 -2
- package/dist/shared-preact/types.d.ts +32 -2
- package/dist/shared-react/components/annotation-container.d.ts +18 -16
- package/dist/shared-react/components/annotation-layer.d.ts +9 -2
- package/dist/shared-react/components/annotation-paint-layer.d.ts +6 -0
- package/dist/shared-react/components/annotations/free-text.d.ts +1 -0
- package/dist/shared-react/components/annotations/polygon.d.ts +4 -1
- package/dist/shared-react/components/annotations.d.ts +4 -1
- package/dist/shared-react/components/preview-renderer.d.ts +7 -0
- package/dist/shared-react/components/text-markup/highlight.d.ts +2 -2
- package/dist/shared-react/components/text-markup/squiggly.d.ts +2 -2
- package/dist/shared-react/components/text-markup/strikeout.d.ts +2 -2
- package/dist/shared-react/components/text-markup/underline.d.ts +2 -2
- package/dist/shared-react/types.d.ts +32 -2
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-annotation.d.ts +3 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +10 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +18 -11
- package/dist/lib/patching/derived-rect.d.ts +0 -2
- package/dist/lib/variant-key.d.ts +0 -8
- package/dist/shared-preact/components/annotations/circle-paint.d.ts +0 -10
- package/dist/shared-preact/components/annotations/free-text-paint.d.ts +0 -10
- package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +0 -18
- package/dist/shared-preact/components/annotations/line-paint.d.ts +0 -10
- package/dist/shared-preact/components/annotations/polygon-paint.d.ts +0 -9
- package/dist/shared-preact/components/annotations/polyline-paint.d.ts +0 -10
- package/dist/shared-preact/components/annotations/square-paint.d.ts +0 -10
- package/dist/shared-preact/components/annotations/stamp-paint.d.ts +0 -8
- package/dist/shared-preact/components/resize-handles.d.ts +0 -9
- package/dist/shared-preact/components/vertex-editor.d.ts +0 -19
- package/dist/shared-preact/hooks/use-drag-resize.d.ts +0 -38
- package/dist/shared-preact/patch-ink.d.ts +0 -16
- package/dist/shared-preact/patchers.d.ts +0 -9
- package/dist/shared-preact/vertex-patchers.d.ts +0 -10
- package/dist/shared-react/components/annotations/circle-paint.d.ts +0 -10
- package/dist/shared-react/components/annotations/free-text-paint.d.ts +0 -10
- package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-react/components/annotations/ink-paint.d.ts +0 -17
- package/dist/shared-react/components/annotations/line-paint.d.ts +0 -10
- package/dist/shared-react/components/annotations/polygon-paint.d.ts +0 -9
- package/dist/shared-react/components/annotations/polyline-paint.d.ts +0 -10
- package/dist/shared-react/components/annotations/square-paint.d.ts +0 -10
- package/dist/shared-react/components/annotations/stamp-paint.d.ts +0 -8
- package/dist/shared-react/components/resize-handles.d.ts +0 -9
- package/dist/shared-react/components/vertex-editor.d.ts +0 -19
- package/dist/shared-react/hooks/use-drag-resize.d.ts +0 -38
- package/dist/shared-react/patch-ink.d.ts +0 -16
- package/dist/shared-react/patchers.d.ts +0 -9
- package/dist/shared-react/vertex-patchers.d.ts +0 -10
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
-
import {
|
|
2
|
+
import { AnnotationCreateContext, PdfAnnotationObject, PdfAnnotationSubtype, PdfErrorReason, PdfRenderPageAnnotationOptions, PdfTextAnnoObject, Task } from '@embedpdf/models';
|
|
3
|
+
import { AnnotationTool } from './tools/types';
|
|
4
|
+
export type AnnotationEvent = {
|
|
5
|
+
type: 'create';
|
|
6
|
+
annotation: PdfAnnotationObject;
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
ctx?: AnnotationCreateContext<any>;
|
|
9
|
+
committed: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'update';
|
|
12
|
+
annotation: PdfAnnotationObject;
|
|
13
|
+
pageIndex: number;
|
|
14
|
+
patch: Partial<PdfAnnotationObject>;
|
|
15
|
+
committed: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'delete';
|
|
18
|
+
annotation: PdfAnnotationObject;
|
|
19
|
+
pageIndex: number;
|
|
20
|
+
committed: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'loaded';
|
|
23
|
+
total: number;
|
|
24
|
+
};
|
|
3
25
|
export type CommitState = 'new' | 'dirty' | 'deleted' | 'synced' | 'ignored';
|
|
4
26
|
export interface TrackedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
5
|
-
/** local commit bookkeeping */
|
|
6
27
|
commitState: CommitState;
|
|
7
|
-
/** the actual annotation object, where `object.id` is the stable string ID */
|
|
8
28
|
object: T;
|
|
9
29
|
}
|
|
10
30
|
export interface RenderAnnotationOptions {
|
|
@@ -12,193 +32,90 @@ export interface RenderAnnotationOptions {
|
|
|
12
32
|
annotation: PdfAnnotationObject;
|
|
13
33
|
options?: PdfRenderPageAnnotationOptions;
|
|
14
34
|
}
|
|
15
|
-
export interface BaseAnnotationDefaults {
|
|
16
|
-
name: string;
|
|
17
|
-
subtype: PdfAnnotationSubtype;
|
|
18
|
-
interaction: {
|
|
19
|
-
mode: string;
|
|
20
|
-
exclusive: boolean;
|
|
21
|
-
cursor?: string;
|
|
22
|
-
};
|
|
23
|
-
textSelection?: boolean;
|
|
24
|
-
blendMode?: PdfBlendMode;
|
|
25
|
-
}
|
|
26
|
-
export interface HighlightDefaults extends BaseAnnotationDefaults {
|
|
27
|
-
subtype: PdfAnnotationSubtype.HIGHLIGHT;
|
|
28
|
-
blendMode: PdfBlendMode;
|
|
29
|
-
color: string;
|
|
30
|
-
opacity: number;
|
|
31
|
-
}
|
|
32
|
-
export interface UnderlineDefaults extends BaseAnnotationDefaults {
|
|
33
|
-
subtype: PdfAnnotationSubtype.UNDERLINE;
|
|
34
|
-
blendMode: PdfBlendMode;
|
|
35
|
-
color: string;
|
|
36
|
-
opacity: number;
|
|
37
|
-
}
|
|
38
|
-
export interface StrikeoutDefaults extends BaseAnnotationDefaults {
|
|
39
|
-
subtype: PdfAnnotationSubtype.STRIKEOUT;
|
|
40
|
-
blendMode: PdfBlendMode;
|
|
41
|
-
color: string;
|
|
42
|
-
opacity: number;
|
|
43
|
-
}
|
|
44
|
-
export interface SquigglyDefaults extends BaseAnnotationDefaults {
|
|
45
|
-
subtype: PdfAnnotationSubtype.SQUIGGLY;
|
|
46
|
-
blendMode: PdfBlendMode;
|
|
47
|
-
color: string;
|
|
48
|
-
opacity: number;
|
|
49
|
-
}
|
|
50
|
-
export interface InkDefaults extends BaseAnnotationDefaults {
|
|
51
|
-
subtype: PdfAnnotationSubtype.INK;
|
|
52
|
-
strokeWidth: number;
|
|
53
|
-
intent?: string;
|
|
54
|
-
color: string;
|
|
55
|
-
opacity: number;
|
|
56
|
-
}
|
|
57
|
-
export interface TextDefaults extends BaseAnnotationDefaults {
|
|
58
|
-
subtype: PdfAnnotationSubtype.FREETEXT;
|
|
59
|
-
fontSize: number;
|
|
60
|
-
fontColor: string;
|
|
61
|
-
fontFamily: PdfStandardFont;
|
|
62
|
-
textAlign: PdfTextAlignment;
|
|
63
|
-
verticalAlign: PdfVerticalAlignment;
|
|
64
|
-
content: string;
|
|
65
|
-
backgroundColor: string;
|
|
66
|
-
opacity: number;
|
|
67
|
-
}
|
|
68
|
-
export interface CircleDefaults extends BaseAnnotationDefaults {
|
|
69
|
-
subtype: PdfAnnotationSubtype.CIRCLE;
|
|
70
|
-
strokeWidth: number;
|
|
71
|
-
strokeColor: string;
|
|
72
|
-
strokeStyle: PdfAnnotationBorderStyle;
|
|
73
|
-
strokeDashArray?: number[];
|
|
74
|
-
color: string;
|
|
75
|
-
opacity: number;
|
|
76
|
-
}
|
|
77
|
-
export interface SquareDefaults extends BaseAnnotationDefaults {
|
|
78
|
-
subtype: PdfAnnotationSubtype.SQUARE;
|
|
79
|
-
strokeWidth: number;
|
|
80
|
-
strokeColor: string;
|
|
81
|
-
strokeStyle: PdfAnnotationBorderStyle;
|
|
82
|
-
strokeDashArray?: number[];
|
|
83
|
-
color: string;
|
|
84
|
-
opacity: number;
|
|
85
|
-
}
|
|
86
|
-
export interface LineDefaults extends BaseAnnotationDefaults {
|
|
87
|
-
subtype: PdfAnnotationSubtype.LINE;
|
|
88
|
-
intent?: string;
|
|
89
|
-
strokeWidth: number;
|
|
90
|
-
strokeColor: string;
|
|
91
|
-
strokeStyle: PdfAnnotationBorderStyle;
|
|
92
|
-
strokeDashArray?: number[];
|
|
93
|
-
lineEndings?: LineEndings;
|
|
94
|
-
color: string;
|
|
95
|
-
opacity: number;
|
|
96
|
-
}
|
|
97
|
-
export interface PolylineDefaults extends BaseAnnotationDefaults {
|
|
98
|
-
subtype: PdfAnnotationSubtype.POLYLINE;
|
|
99
|
-
strokeWidth: number;
|
|
100
|
-
strokeColor: string;
|
|
101
|
-
strokeStyle: PdfAnnotationBorderStyle;
|
|
102
|
-
strokeDashArray?: number[];
|
|
103
|
-
lineEndings?: LineEndings;
|
|
104
|
-
color: string;
|
|
105
|
-
opacity: number;
|
|
106
|
-
}
|
|
107
|
-
export interface PolygonDefaults extends BaseAnnotationDefaults {
|
|
108
|
-
subtype: PdfAnnotationSubtype.POLYGON;
|
|
109
|
-
strokeWidth: number;
|
|
110
|
-
strokeColor: string;
|
|
111
|
-
strokeStyle: PdfAnnotationBorderStyle;
|
|
112
|
-
strokeDashArray?: number[];
|
|
113
|
-
color: string;
|
|
114
|
-
opacity: number;
|
|
115
|
-
}
|
|
116
|
-
export interface PhotoDefaults extends BaseAnnotationDefaults {
|
|
117
|
-
subtype: PdfAnnotationSubtype.STAMP;
|
|
118
|
-
}
|
|
119
|
-
export type AnnotationDefaults = HighlightDefaults | UnderlineDefaults | StrikeoutDefaults | SquigglyDefaults | InkDefaults | TextDefaults | CircleDefaults | SquareDefaults | LineDefaults | PolylineDefaults | PolygonDefaults | PhotoDefaults;
|
|
120
|
-
export type ToolDefaultsByMode = {
|
|
121
|
-
[K in string]: AnnotationDefaults;
|
|
122
|
-
};
|
|
123
|
-
export type ActiveTool = {
|
|
124
|
-
variantKey: null;
|
|
125
|
-
defaults: null;
|
|
126
|
-
} | {
|
|
127
|
-
[K in string]: {
|
|
128
|
-
variantKey: K;
|
|
129
|
-
defaults: ToolDefaultsByMode[K];
|
|
130
|
-
};
|
|
131
|
-
}[string];
|
|
132
35
|
export interface AnnotationState {
|
|
133
36
|
pages: Record<number, string[]>;
|
|
134
37
|
byUid: Record<string, TrackedAnnotation>;
|
|
135
38
|
selectedUid: string | null;
|
|
136
|
-
|
|
137
|
-
|
|
39
|
+
activeToolId: string | null;
|
|
40
|
+
/** The complete list of available tools, including any user modifications. */
|
|
41
|
+
tools: AnnotationTool[];
|
|
138
42
|
colorPresets: string[];
|
|
139
43
|
hasPendingChanges: boolean;
|
|
140
44
|
}
|
|
141
45
|
export interface AnnotationPluginConfig extends BasePluginConfig {
|
|
142
|
-
|
|
46
|
+
/** A list of custom tools to add or default tools to override. */
|
|
47
|
+
tools?: AnnotationTool[];
|
|
143
48
|
colorPresets?: string[];
|
|
144
|
-
/**
|
|
145
|
-
* When `false` mutations are kept in memory and must be
|
|
146
|
-
* flushed with `commitPendingChanges()`.
|
|
147
|
-
*/
|
|
49
|
+
/** When true (default), automatically commit the annotation changes into the PDF document. */
|
|
148
50
|
autoCommit?: boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Author of the annotation
|
|
151
|
-
*/
|
|
51
|
+
/** The author of the annotation. */
|
|
152
52
|
annotationAuthor?: string;
|
|
53
|
+
/** When true (default false), deactivate the active tool after creating an annotation. */
|
|
54
|
+
deactivateToolAfterCreate?: boolean;
|
|
55
|
+
/** When true (default false), select the annotation immediately after creation. */
|
|
56
|
+
selectAfterCreate?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options for transforming an annotation
|
|
60
|
+
*/
|
|
61
|
+
export interface TransformOptions<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
62
|
+
/** The type of transformation */
|
|
63
|
+
type: 'move' | 'resize' | 'vertex-edit' | 'property-update';
|
|
64
|
+
/** The changes to apply */
|
|
65
|
+
changes: Partial<T>;
|
|
66
|
+
/** Optional metadata */
|
|
67
|
+
metadata?: {
|
|
68
|
+
maintainAspectRatio?: boolean;
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
};
|
|
153
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Function type for custom patch functions
|
|
74
|
+
*/
|
|
75
|
+
export type PatchFunction<T extends PdfAnnotationObject> = (original: T, context: TransformOptions<T>) => Partial<T>;
|
|
76
|
+
export type ImportAnnotationItem<T extends PdfAnnotationObject = PdfAnnotationObject> = {
|
|
77
|
+
annotation: T;
|
|
78
|
+
ctx?: AnnotationCreateContext<T>;
|
|
79
|
+
};
|
|
154
80
|
export interface AnnotationCapability {
|
|
155
81
|
getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
156
82
|
getSelectedAnnotation: () => TrackedAnnotation | null;
|
|
157
83
|
selectAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
158
84
|
deselectAnnotation: () => void;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
getToolDefaultsBySubtype: <Sub extends AnnotationDefaults['subtype']>(subtype: Sub) => Extract<AnnotationDefaults, {
|
|
167
|
-
subtype: Sub;
|
|
168
|
-
}>;
|
|
169
|
-
/** Return the subtype and intent for a given variant key */
|
|
170
|
-
getSubtypeAndIntentByVariant: (variantKey: string) => {
|
|
171
|
-
subtype: PdfAnnotationSubtype;
|
|
172
|
-
intent?: string;
|
|
173
|
-
};
|
|
174
|
-
/** Partially patch a single tool’s defaults */
|
|
175
|
-
setToolDefaults: (variantKey: string, patch: Partial<AnnotationDefaults>) => void;
|
|
176
|
-
/** current palette – UI just reads this */
|
|
85
|
+
getActiveTool: () => AnnotationTool | null;
|
|
86
|
+
setActiveTool: (toolId: string | null) => void;
|
|
87
|
+
getTools: () => AnnotationTool[];
|
|
88
|
+
getTool: <T extends AnnotationTool>(toolId: string) => T | undefined;
|
|
89
|
+
addTool: <T extends AnnotationTool>(tool: T) => void;
|
|
90
|
+
findToolForAnnotation: (annotation: PdfAnnotationObject) => AnnotationTool | null;
|
|
91
|
+
setToolDefaults: (toolId: string, patch: Partial<any>) => void;
|
|
177
92
|
getColorPresets: () => string[];
|
|
178
|
-
/** append a swatch (deduped by RGBA) */
|
|
179
93
|
addColorPreset: (color: string) => void;
|
|
180
|
-
|
|
94
|
+
importAnnotations: (items: ImportAnnotationItem<PdfAnnotationObject>[]) => void;
|
|
95
|
+
createAnnotation: <A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>) => void;
|
|
181
96
|
updateAnnotation: (pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>) => void;
|
|
182
97
|
deleteAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Transform an annotation based on interaction (move, resize, etc.)
|
|
100
|
+
* This applies annotation-specific logic to ensure consistency.
|
|
101
|
+
*/
|
|
102
|
+
transformAnnotation: <T extends PdfAnnotationObject>(annotation: T, options: TransformOptions<T>) => Partial<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Register a custom patch function for a specific annotation type.
|
|
105
|
+
* This allows extending the transformation logic for custom annotations.
|
|
106
|
+
*/
|
|
107
|
+
registerPatchFunction: <T extends PdfAnnotationObject>(type: PdfAnnotationSubtype, patchFn: PatchFunction<T>) => void;
|
|
183
108
|
renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
|
|
184
|
-
/** undo / redo */
|
|
185
109
|
onStateChange: EventHook<AnnotationState>;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
commit: () =>
|
|
110
|
+
onActiveToolChange: EventHook<AnnotationTool | null>;
|
|
111
|
+
onAnnotationEvent: EventHook<AnnotationEvent>;
|
|
112
|
+
commit: () => Task<boolean, PdfErrorReason>;
|
|
189
113
|
}
|
|
190
114
|
export interface GetPageAnnotationsOptions {
|
|
191
115
|
pageIndex: number;
|
|
192
116
|
}
|
|
193
|
-
export interface UpdateAnnotationColorOptions extends WebAlphaColor {
|
|
194
|
-
pageIndex: number;
|
|
195
|
-
annotationId: string;
|
|
196
|
-
}
|
|
197
117
|
export interface SidebarAnnotationEntry {
|
|
198
|
-
/** Zero-based page index */
|
|
199
118
|
page: number;
|
|
200
|
-
/** The tracked root annotation shown in the sidebar */
|
|
201
119
|
annotation: TrackedAnnotation;
|
|
202
|
-
/** Any TEXT-type annotations whose `inReplyToId` points to the root */
|
|
203
120
|
replies: TrackedAnnotation<PdfTextAnnoObject>[];
|
|
204
121
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-state';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple, framework-agnostic state management utility for use within handlers.
|
|
3
|
+
* It creates a closure to hold a value that persists across multiple calls
|
|
4
|
+
* to the handler's methods (e.g., onPointerDown, onPointerMove).
|
|
5
|
+
*
|
|
6
|
+
* @param initialValue The initial value to store.
|
|
7
|
+
* @returns A tuple containing:
|
|
8
|
+
* - The current value.
|
|
9
|
+
* - A function to set a new value.
|
|
10
|
+
* - A function to get the current value without causing re-renders (useful inside closures).
|
|
11
|
+
*/
|
|
12
|
+
export declare function useState<T>(initialValue: T): [() => T, (newValue: T) => void];
|
package/dist/preact/adapter.d.ts
CHANGED
|
@@ -8,8 +8,4 @@ export type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarg
|
|
|
8
8
|
export type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;
|
|
9
9
|
export type ChangeEvent<T = Element> = JSX.TargetedInputEvent<T extends EventTarget ? T : never>;
|
|
10
10
|
export type TouchEvent<T = Element> = JSX.TargetedTouchEvent<T extends EventTarget ? T : never>;
|
|
11
|
-
export declare const
|
|
12
|
-
onDblClick: any;
|
|
13
|
-
} | {
|
|
14
|
-
onDblClick?: undefined;
|
|
15
|
-
};
|
|
11
|
+
export declare const suppressContentEditableWarningProps: {};
|
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/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),r=require("@embedpdf/plugin-selection/preact"),s=require("preact"),l=require("preact/hooks"),a=require("@embedpdf/utils/preact"),c=require("@embedpdf/core"),d=()=>e.useCapability(t.AnnotationPlugin.id);function u({rect:e,rotation:t,scale:i,vertices:r,onEdit:a,onCommit:c,handleSize:d=12}){const[u,h]=l.useState(null),p=l.useRef(null),g=l.useRef([]),y=e=>{const n=o.restoreOffset(e,t,i),r=[...g.current];return null!==u&&(r[u]={x:r[u].x+n.x,y:r[u].y+n.y}),r},x=e=>{if(null===u||!p.current)return;const t={x:e.clientX-p.current.x,y:e.clientY-p.current.y};a(y(t))},f=e=>{if(null===u||!p.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-p.current.x,y:e.clientY-p.current.y};c(y(t)),h(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-d/2,l=(t.y-e.origin.y)*i-d/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:d,height:d,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),h(a),p.current={x:e.clientX,y:e.clientY},g.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:x,onPointerUp:f},o);var a}))})}function h({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:s,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,lockAspectRatio:h=!1,currentRect:p,setCurrentRect:g,setCurrentVertices:y,setPreviewObject:x,commit:f}){const v=l.useRef("idle"),b=l.useRef("none"),m=l.useRef(null),k=l.useRef(null),j=(e,t,n)=>Math.max(t,Math.min(n,e)),P=t/e,S=n/e,M=(e,t,n)=>{v.current=e,m.current={x:t,y:n},k.current=p},w=(t,n)=>{if("idle"===v.current||!m.current)return;const s={x:t-m.current.x,y:n-m.current.y},{x:l,y:a}=o.restoreOffset(s,i,e),c=((e,t)=>{if(!k.current)return p;let{origin:n,size:o}=k.current,i=n.x,r=n.y,s=o.width,l=o.height;if("dragging"===v.current)i+=e,r+=t;else if("resizing"===v.current&&(b.current.includes("right")?s+=e:b.current.includes("left")&&(i+=e,s-=e),b.current.includes("bottom")?l+=t:b.current.includes("top")&&(r+=t,l-=t),h&&k.current)){const e=k.current.size.width/k.current.size.height,t=i+s,n=r+l;b.current.includes("left")||b.current.includes("right")?l=s/e:s=l*e,b.current.includes("left")&&(i=t-s),b.current.includes("top")&&(r=n-l)}return s<1||l<1?p:(s=j(s,1,P),l=j(l,1,S),i=j(i,0,P-s),r=j(r,0,S-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(l,a);let f={rect:c};d&&(f=d(r.object,{rect:c,direction:"resizing"===v.current?b.current:"bottom-right"}),u&&y(u({...r.object,...f}))),g(f.rect??c),x(f)},A=()=>{if("idle"===v.current)return;const e=b.current||"bottom-right";v.current="idle";let t={rect:p};d&&(t=d(r.object,{rect:p,direction:e})),f(t),m.current=null,k.current=null,b.current="none",x(null)},C=e=>{if(A(),(null==e?void 0:e.currentTarget)&&void 0!==e.pointerId)try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},z=()=>A();return l.useEffect((()=>{v.current="idle",b.current="none",m.current=null,k.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{s&&a&&(e.stopPropagation(),e.preventDefault(),M("dragging",e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>w(e.clientX,e.clientY),onPointerUp:C,onPointerCancel:()=>C(),onLostPointerCapture:()=>C(),onTouchStart:e=>{if(!s||!a)return;e.stopPropagation(),e.preventDefault();const t=e.touches[0];t&&M("dragging",t.clientX,t.clientY)},onTouchMove:e=>{const t=e.touches[0];t&&w(t.clientX,t.clientY)},onTouchEnd:z,onTouchCancel:z},startResize:e=>t=>{s&&c&&(t.stopPropagation(),t.preventDefault(),b.current=e,M("resizing",t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))}}}function p({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function g({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:c,trackedAnnotation:g,children:y,style:x,outlineOffset:f=1,isSelected:v=!1,isDraggable:b=!0,isResizable:m=!0,lockAspectRatio:k=!1,computeVertices:j,computePatch:P,selectionMenu:S,onDoubleClick:M,...w}){const{provides:A}=d(),[C,z]=l.useState(g.object.rect),[E,D]=l.useState((null==j?void 0:j(g.object))??[]),[I,W]=l.useState(null),{rootHandlers:R,startResize:T}=h({scale:e,pageWidth:r,pageHeight:c,rotation:i,tracked:g,isSelected:v,isDraggable:b,isResizable:m,lockAspectRatio:k,computePatch:P,computeVertices:j,currentRect:C,setCurrentRect:z,setCurrentVertices:D,setPreviewObject:W,commit:e=>null==A?void 0:A.updateAnnotation(t,g.object.id,e)});l.useLayoutEffect((()=>{o.rectEquals(g.object.rect,C)||(z(g.object.rect),W((e=>e?{...e,rect:g.object.rect}:null)),D((null==j?void 0:j(g.object))??[]))}),[g]);const B=I?{...g.object,...I}:g.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...R,...(L=M,L?{onDblClick:L}:{}),style:{position:"absolute",outline:v?"1px solid #007ACC":"none",outlineOffset:v?`${f}px`:"0px",left:C.origin.x*e+"px",top:C.origin.y*e+"px",width:C.size.width*e+"px",height:C.size.height*e+"px",pointerEvents:v?"auto":"none",touchAction:v?"auto":"none",cursor:v&&b?"move":"default",...v&&{zIndex:3},...x},...w,children:["function"==typeof y?y(B):y,v&&E.length>0&&n.jsx(u,{rect:C,rotation:i,scale:e,vertices:E,onEdit:e=>{if(D(e),P){const t=P(g.object,{rect:C,vertices:e});W(t),z(t.rect||C)}},onCommit:e=>{if(A&&P){const n=P(g.object,{rect:C,vertices:e});A.updateAnnotation(t,g.object.id,n)}}}),v&&m&&n.jsx(p,{rotation:i,outlineOffset:f,startResize:T})]}),n.jsx(a.CounterRotate,{rect:{origin:{x:C.origin.x*e,y:C.origin.y*e},size:{width:C.size.width*e,height:C.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>S&&S({annotation:g,selected:v,rect:e,menuWrapperProps:t})})]});var L}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function v({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function b({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:r,rect:s,scale:a,onClick:c}){const d=l.useMemo((()=>r.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-s.origin.x,r=n-s.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}))),[r,s]),u=s.size.width*a,h=s.size.height*a;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${s.size.width} ${s.size.height}`,children:d.map(((r,s)=>n.jsx("path",{d:r,fill:"none",opacity:o,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},s)))})}function m({isSelected:e,color:t="#000000",strokeColor:i,opacity:r=1,strokeWidth:s,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:p,height:g,x:y,y:x}=l.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-s,0),height:Math.max(t-s,0),x:s/2,y:s/2}}),[d,s]),f=(p+s)*u,v=(g+s)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${p+s} ${g+s}`,children:n.jsx("rect",{x:y,y:x,width:p,height:g,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:s,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function k({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:p,height:g,cx:y,cy:x,rx:f,ry:v}=l.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]),b=p*d,m=g*d;return n.jsx("svg",{style:{position:"absolute",width:b,height:m,pointerEvents:"none",zIndex:2},width:b,height:m,viewBox:`0 0 ${p} ${g}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const j=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function P({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:s="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:p,onClick:g,isSelected:y}){const{x1:x,y1:f,x2:v,y2:b}=l.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=l.useMemo((()=>{const e=Math.atan2(b-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,b)}}),[h,r,x,f,v,b]),k=d.size.width*p,j=d.size.height*p;return n.jsxs("svg",{style:{position:"absolute",width:k,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:k,height:j,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:b,opacity:i,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",pointerEvents:y?"none":"visibleStroke",stroke:s,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:g,onTouchStart:g,stroke:s,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&n.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:s,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function S({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const p=l.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),g=l.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[p]),y=l.useMemo((()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(p[1],p[0]),o=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,p[p.length-1].x,p[p.length-1].y)}}),[p,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:g,onPointerDown:u,onTouchStart:u,opacity:s,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function M({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:p}){const g=l.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=l.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[g]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onPointerDown:p,onTouchStart:p,opacity:s,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const w=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},A=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},C=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function z({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:s,onClick:a}){const c=l.useRef(null),{provides:u}=d();l.useEffect((()=>{if(t&&c.current){const e=c.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]);return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*s,height:i.object.rect.size.height*s,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:c,onBlur:()=>{u&&c.current&&u.updateAnnotation(r,i.object.id,{contents:c.current.innerText})},style:{color:i.object.fontColor,fontSize:i.object.fontSize*s,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:"100%",height:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer"},contentEditable:t,children:i.object.contents})})}function E({pageIndex:e,annotation:t,scaleFactor:i=1,style:r,...a}){const{provides:c}=d(),[u,h]=l.useState(null),p=l.useRef(null),{width:g,height:y}=t.rect.size;l.useEffect((()=>{if(c){const n=c.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:i,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);h(t),p.current=t}),o.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,c,t.id,g,y]);return n.jsx(s.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...a,style:{width:"100%",height:"100%",...r||{}}})})}function D({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:r}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:r,onTouchStart:r,children:n.jsx(E,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function I(e){const{pageIndex:a,scale:c,selectionMenu:u}=e,{provides:h}=d(),{provides:p}=r.useSelectionCapability(),[E,I]=l.useState([]),{register:W}=i.usePointerHandlers({pageIndex:a}),[R,T]=l.useState(null),[B,L]=l.useState(null);l.useEffect((()=>{h&&h.onStateChange((e=>{I(t.getAnnotationsByPageIndex(e,a)),T(t.getSelectedAnnotationByPageIndex(e,a))}))}),[h]);const $=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&h&&(h.deselectAnnotation(),L(null))}})),[h]),H=l.useCallback(((e,t)=>{e.stopPropagation(),h&&p&&(h.selectAnnotation(a,t.object.id),p.clear(),L(null))}),[h,p,a]);return l.useEffect((()=>W($)),[W,$]),n.jsx(n.Fragment,{children:E.map((i=>{const r=(null==R?void 0:R.object.id)===i.object.id,l=B===i.object.id;return t.isInk(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,computePatch:j,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{isSelected:r,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isSquare(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isCircle(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(k,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(y,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,rect:e.rect,onClick:e=>H(e,i)})},i.object.id):t.isLine(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:w,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>H(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:A,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(S,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:c,onClick:e=>H(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computeVertices:e=>e.vertices,computePatch:C,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(M,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>H(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,outlineOffset:6,onDoubleClick:e=>{e.stopPropagation(),L(i.object.id)},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(z,{isSelected:r,isEditing:l,annotation:{...i,object:e},pageIndex:a,scale:c,onClick:e=>H(e,i)})},i.object.id):t.isStamp(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(D,{isSelected:r,annotation:i,pageIndex:a,scale:c,onClick:e=>H(e,i)})},i.object.id):null}))})}function W({pageIndex:e,scale:t}){var i,s,a,c,u,h,p,g,b,m,k,j;const{provides:P}=r.useSelectionCapability(),{provides:S}=d(),[M,w]=l.useState([]),[A,C]=l.useState(null),[z,E]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!P)return;return P.onSelectionChange((()=>{w(P.getHighlightRectsForPage(e)),C(P.getBoundingRectForPage(e))}))}),[P,e]),l.useEffect((()=>{if(!S)return;return S.onActiveToolChange(E)}),[S]),!A)return null;if(!z.defaults)return null;switch(z.defaults.subtype){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=z.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(s=z.defaults)?void 0:s.color,opacity:null==(a=z.defaults)?void 0:a.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(c=z.defaults)?void 0:c.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(u=z.defaults)?void 0:u.color,opacity:null==(h=z.defaults)?void 0:h.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(p=z.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(g=z.defaults)?void 0:g.color,opacity:null==(b=z.defaults)?void 0:b.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(m=z.defaults)?void 0:m.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(v,{color:null==(k=z.defaults)?void 0:k.color,opacity:null==(j=z.defaults)?void 0:j.opacity,rects:M,scale:t})});default:return null}}const R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s})=>{var a,u,h,p,g;const{provides:y}=d(),[x,f]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!y)return;return y.onActiveToolChange(f)}),[y]),!x.defaults)return null;if(x.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const v=(null==(a=x.defaults)?void 0:a.color)??"#000000",b=(null==(u=x.defaults)?void 0:u.opacity)??1,m=(null==(h=x.defaults)?void 0:h.strokeWidth)??2,k=(null==(p=x.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal,j=null==(g=x.defaults)?void 0:g.intent,{register:P}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),[S,M]=l.useState([]),[w,A]=l.useState(!1),C=l.useRef(null),z=r/t,E=s/t,D=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=c.clamp(e.x,0,z),i=c.clamp(e.y,0,E);A(!0),C.current?(clearTimeout(C.current),C.current=null,M((e=>[...e,{points:[{x:o,y:i}]}]))):M([{points:[{x:o,y:i}]}]),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!w)return;const t=c.clamp(e.x,0,z),n=c.clamp(e.y,0,E);M((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i;A(!1),null==(i=n.releasePointerCapture)||i.call(n),C.current&&clearTimeout(C.current),C.current=setTimeout((()=>{if(S.length&&y){const t=S.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),m/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:j,blendMode:k,rect:n,inkList:S,color:v,opacity:b,strokeWidth:m,created:new Date,pageIndex:e,id:o.uuidV4()};y.createAnnotation(e,i),y.setActiveVariant(null),y.selectAnnotation(e,i.id)}M([]),C.current=null}),3e3)},onPointerCancel:(e,t)=>{var n;A(!1),null==(n=t.releasePointerCapture)||n.call(t),M([]),C.current&&(clearTimeout(C.current),C.current=null)}})),[z,E,S,y,e,v,b,m,w]);if(l.useEffect((()=>{if(P)return P(D)}),[P,D]),l.useEffect((()=>()=>{C.current&&clearTimeout(C.current)}),[]),!S.length)return null;const I=S.flatMap((e=>e.points));if(!I.length)return null;const W=o.expandRect(o.rectFromPoints(I),m/2),R=S.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:R.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:b,style:{stroke:v,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},T=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:a})=>{const{provides:u}=d(),[h,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),k=r/t,j=s/t,[P,S]=l.useState(null),[M,w]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=c.clamp(e.x,0,k),i=c.clamp(e.y,0,j);S({x:o,y:i}),w({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!P)return;const t=c.clamp(e.x,0,k),n=c.clamp(e.y,0,j);w({x:t,y:n})},onPointerUp:(t,n)=>{var i;if(P&&M&&u){const t=Math.min(P.x,M.x),n=Math.min(P.y,M.y),i=Math.max(P.x,M.x),r=Math.max(P.y,M.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,created:new Date,pageIndex:e,id:o.uuidV4()};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(i=n.releasePointerCapture)||i.call(n),S(null),w(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),S(null),w(null)}})),[P,M,u,e,k,j,g,y,x]);if(l.useEffect((()=>m?m(A):void 0),[m,A]),!P||!M)return null;const C=Math.min(P.x,M.x),z=Math.min(P.y,M.y),E=Math.max(P.x,M.x),D=Math.max(P.y,M.y),I=x/2,W=C-I,R=z-I,T=E-C,B=D-z,L=T+x,$=B+x,H=I+T/2,F=I+B/2,O=T/2,N=B/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("ellipse",{cx:H,cy:F,rx:O,ry:N,fill:g,opacity:y,style:{cursor:a,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:b.join(",")}}})})},B=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:a})=>{const{provides:u}=d(),[h,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"square",pageIndex:e}),k=r/t,j=s/t,[P,S]=l.useState(null),[M,w]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=c.clamp(e.x,0,k),r=c.clamp(e.y,0,j);S({x:i,y:r}),w({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!P)return;const t=c.clamp(e.x,0,k),n=c.clamp(e.y,0,j);w({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(P&&M&&u){const t=Math.min(P.x,M.x),n=Math.min(P.y,M.y),i=Math.max(P.x,M.x),r=Math.max(P.y,M.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),S(null),w(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),S(null),w(null)}})),[P,M,u,e,k,j,g,y,x]);if(l.useEffect((()=>m?m(A):void 0),[m,A]),!P||!M)return null;const C=Math.min(P.x,M.x),z=Math.min(P.y,M.y),E=Math.max(P.x,M.x),D=Math.max(P.y,M.y),I=x/2,W=C-I,R=z-I,T=E-C,B=D-z,L=T+x,$=B+x;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("rect",{x:I,y:I,width:T,height:B,fill:g,opacity:y,style:{cursor:a,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:b.join(",")}}})})},L=({pageIndex:e,scale:r,pageWidth:s,pageHeight:a,cursor:u})=>{const{provides:h}=d(),[p,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",b=p.defaults.lineEndings,m=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=p.defaults.strokeDashArray,{register:j}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),P=s/r,M=a/r,[w,A]=l.useState([]),[C,z]=l.useState(null),E=l.useMemo((()=>({onClick:e=>{const t=c.clamp(e.x,0,P),n=c.clamp(e.y,0,M);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{w.length>=1&&h&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,f,b),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:m,strokeDashArray:k,lineEndings:b,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,r),h.setActiveVariant(null),h.selectAnnotation(e,r.id)})(w),A([]),z(null)},onPointerMove:e=>{if(!w.length)return;const t=c.clamp(e.x,0,P),n=c.clamp(e.y,0,M);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[w,h,P,M]);if(l.useEffect((()=>j?j(E):void 0),[j,E]),!w.length||!C)return null;const D=[...w,C],I=t.patching.lineRectWithEndings(D,f,b);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(S,{rect:I,vertices:D,strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:b})})},$=({pageIndex:e,scale:r,pageWidth:s,pageHeight:a,cursor:u})=>{const{provides:h}=d(),[p,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",b=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=p.defaults.strokeDashArray,k=p.defaults.lineEndings,j=p.defaults.intent,{register:S}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),M=s/r,w=a/r,[A,C]=l.useState(null),[z,E]=l.useState(null),D=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=c.clamp(e.x,0,M),i=c.clamp(e.y,0,w);C({x:o,y:i}),E({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!A)return;const t=c.clamp(e.x,0,M),n=c.clamp(e.y,0,w);E({x:t,y:n})},onPointerUp:(n,i)=>{var r;A&&z&&h&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],f,k),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:b,strokeDashArray:m,lineEndings:k,intent:j,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,s),h.setActiveVariant(null),h.selectAnnotation(e,s.id)})(A,z),null==(r=i.releasePointerCapture)||r.call(i),C(null),E(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),C(null),E(null)}})),[A,z,h,M,w]);if(l.useEffect((()=>S?S(D):void 0),[S,D]),!A||!z)return null;const I=t.patching.lineRectWithEndings([A,z],f,k);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(P,{rect:I,linePoints:{start:A,end:z},strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:k,strokeStyle:b,strokeDashArray:m})})},H=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:a})=>{const{provides:u}=d(),[h,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==u?void 0:u.onActiveToolChange(p)),[u]),!h.defaults||h.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray,{register:m}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),k=r/t,j=s/t,[P,S]=l.useState([]),[M,w]=l.useState(null),A=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=x/2,d={origin:{x:r-c,y:s-c},size:{width:l-r+x,height:a-s+x}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:d,vertices:t,color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,h),u.setActiveVariant(null),u.selectAnnotation(e,h.id)},C=l.useMemo((()=>({onClick:e=>{const n=c.clamp(e.x,0,k),o=c.clamp(e.y,0,j);if(((e,n)=>{if(P.length<2)return!1;const o=14/t/2,i=P[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&P.length>=3&&u)return A(P),S([]),void w(null);S((e=>[...e,{x:n,y:o}])),w({x:n,y:o})},onDoubleClick:()=>{P.length>=3&&u?(A(P),S([]),w(null)):(S([]),w(null))},onPointerMove:e=>{if(!P.length)return;const t=c.clamp(e.x,0,k),n=c.clamp(e.y,0,j);w({x:t,y:n})},onPointerCancel:()=>{S([]),w(null)}})),[P,M,u,k,j]);if(l.useEffect((()=>m?m(C):void 0),[m,C]),!P.length||!M)return null;const z=[...P,M],E=z.map((e=>e.x)),D=z.map((e=>e.y)),I=Math.min(...E),W=Math.min(...D),R=Math.max(...E),T=Math.max(...D),B=x/2,L=I-B,$=W-B,H=R+B-L,F=T+B-$,O=l.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-$)+" "})),e.trim()}),[z,L,$]),N=P.length>=2?`M ${M.x-L} ${M.y-$} L ${P[0].x-L} ${P[0].y-$}`:null,V=14/t,U=V/2,q=P[0].x-U-L,Y=P[0].y-U-$;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:$*t,width:H*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:H*t,height:F*t,viewBox:`0 0 ${H} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:y,style:{cursor:a,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==b?void 0:b.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:f,strokeWidth:x,strokeDasharray:"4,4"}}),P.length>=3&&n.jsx("rect",{x:q,y:Y,width:V,height:V,fill:f,opacity:.4,stroke:f,strokeWidth:x/2,style:{pointerEvents:"none"}})]})},F=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:a="text"})=>{const{provides:c}=d(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==c?void 0:c.onActiveToolChange(h)),[c]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.FREETEXT)return null;const p=u.defaults.fontColor??"#000000",g=u.defaults.opacity??1,y=u.defaults.fontSize??12,x=u.defaults.fontFamily,f=u.defaults.backgroundColor??"transparent",v=u.defaults.textAlign,b=u.defaults.verticalAlign,m=u.defaults.content??"Insert text here",{register:k}=i.usePointerHandlers({modeId:"freeText",pageIndex:e}),j=(e,t,n)=>Math.max(t,Math.min(n,e)),P=r/t,S=s/t,[M,w]=l.useState(null),[A,C]=l.useState(null),z=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=j(e.x,0,P),i=j(e.y,0,S);w({x:o,y:i}),C({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!M)return;const t=j(e.x,0,P),n=j(e.y,0,S);C({x:t,y:n})},onPointerUp:(t,n)=>{var i;M&&A&&c&&((t,n)=>{const i=Math.min(t.x,n.x),r=Math.min(t.y,n.y),s=Math.max(t.x,n.x)-i,l=Math.max(t.y,n.y)-r;if(s<1||l<1)return;const a={origin:{x:i,y:r},size:{width:s,height:l}},d={type:o.PdfAnnotationSubtype.FREETEXT,rect:a,contents:m,fontColor:p,fontSize:y,fontFamily:x,opacity:g,backgroundColor:f,textAlign:v,verticalAlign:b,pageIndex:e,id:o.uuidV4(),created:new Date};c.createAnnotation(e,d),c.setActiveVariant(null),c.selectAnnotation(e,d.id)})(M,A),null==(i=n.releasePointerCapture)||i.call(n),w(null),C(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),w(null),C(null)}})),[M,A,c,P,S]);if(l.useEffect((()=>k?k(z):void 0),[k,z]),!M||!A)return null;const E=Math.min(M.x,A.x),D=Math.min(M.y,A.y),I=Math.max(M.x,A.x)-E,W=Math.max(M.y,A.y)-D;return n.jsx("svg",{style:{position:"absolute",left:E*t,top:D*t,width:I*t,height:W*t,pointerEvents:"none",zIndex:2},width:I*t,height:W*t,viewBox:`0 0 ${I} ${W}`,children:n.jsx("rect",{x:0,y:0,width:I,height:W,fill:"transparent",style:{stroke:p,strokeWidth:1,strokeDasharray:"4,4",cursor:a}})})},O=({pageIndex:e,scale:t,pageWidth:r,pageHeight:a})=>{const{provides:u}=d(),h=l.useRef(null),p=l.useRef(null),[g,y]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(y)}),[u]),!g.defaults)return null;if(g.defaults.subtype!==o.PdfAnnotationSubtype.STAMP)return null;const{register:x}=i.usePointerHandlers({modeId:"stamp",pageIndex:e}),f=r/t,v=a/t,[b,m]=l.useState(null),k=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=c.clamp(e.x,0,f),i=c.clamp(e.y,0,v);m({x:o,y:i}),null==(n=h.current)||n.click()}})),[f,v]);l.useEffect((()=>x?x(k):void 0),[x,k]);return n.jsxs(s.Fragment,{children:[n.jsx("canvas",{style:{display:"none"},ref:p}),n.jsx("input",{ref:h,type:"file",accept:"image/png,image/jpeg",style:{display:"none"},onChange:async t=>{var n;if(!u||!b)return;const i=null==(n=t.currentTarget.files)?void 0:n[0];if(!i)return;const r=await new Promise(((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=URL.createObjectURL(i)})),s=r.naturalWidth,l=r.naturalHeight,a=f,d=v,h=Math.min(1,a/s,d/l),g=s*h,y=l*h,x={origin:{x:c.clamp(b.x,0,a-g),y:c.clamp(b.y,0,d-y)},size:{width:g,height:y}},k=p.current;if(!k)return;k.width=g,k.height=y;const j=k.getContext("2d");j.drawImage(r,0,0,g,y);const P=j.getImageData(0,0,g,y),S={type:o.PdfAnnotationSubtype.STAMP,flags:["print"],pageIndex:e,id:o.uuidV4(),created:new Date,rect:x};u.createAnnotation(e,S,{imageData:P}),u.setActiveVariant(null),u.selectAnnotation(e,S.id),m(null)}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(I,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(W,{pageIndex:e,scale:t}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(T,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(H,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(L,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx($,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(F,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(O,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=d,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id),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/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),s=require("@embedpdf/plugin-selection/preact"),r=require("preact"),l=require("preact/hooks"),a=require("@embedpdf/utils/preact"),d=()=>e.usePlugin(t.AnnotationPlugin.id),c=()=>e.useCapability(t.AnnotationPlugin.id),u={};function h({scale:e,pageIndex:t,rotation:o,pageWidth:i,pageHeight:s,trackedAnnotation:r,children:d,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:y,selectionMenu:f,outlineOffset:b=1,onDoubleClick:v,zIndex:j=1,resizeUI:m,vertexUI:k,selectionOutlineColor:S="#007ACC",...M}){const[w,P]=l.useState(r.object),{provides:C}=c(),z=l.useRef(null),A=w?{...r.object,...w}:r.object,I=(null==m?void 0:m.color)??"#007ACC",D=(null==k?void 0:k.color)??"#007ACC",E=(null==m?void 0:m.size)??12,B=(null==k?void 0:k.size)??12,{dragProps:R,vertices:T,resize:$}=a.useInteractionHandles({controller:{element:A.rect,vertices:null==y?void 0:y.extractVertices(A),constraints:{minWidth:10,minHeight:10,boundingBox:{width:i/e,height:s/e}},maintainAspectRatio:p,pageRotation:o,scale:e,enabled:u,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(z.current=A);const o=e.transformData.type,i=z.current??A,s=e.transformData.changes.vertices?null==y?void 0:y.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},l=null==C?void 0:C.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});l&&P((e=>({...e,...l}))),"end"===e.state&&l&&(z.current=null,null==C||C.updateAnnotation(t,r.object.id,l))}},resizeUI:{handleSize:E,spacing:b,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:B,zIndex:j+2},includeVertices:!!y}),L=a.useDoublePressProps(v);return l.useEffect((()=>{P(r.object)}),[r.object]),n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...h&&u?R:{},...L,style:{position:"absolute",left:A.rect.origin.x*e,top:A.rect.origin.y*e,width:A.rect.size.width*e,height:A.rect.size.height*e,outline:u?`1px solid ${S}`:"none",outlineOffset:u?`${b}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...M,children:["function"==typeof d?d(A):d,u&&g&&$.map((({key:e,...t})=>(null==m?void 0:m.component)?m.component({key:e,...t,backgroundColor:I}):n.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&T.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:D}):n.jsx("div",{...t,style:{...t.style,backgroundColor:D}},e)))]}),n.jsx(a.CounterRotate,{rect:{origin:{x:A.rect.origin.x*e,y:A.rect.origin.y*e},size:{width:A.rect.size.width*e,height:A.rect.size.height*e}},rotation:o,children:({rect:e,menuWrapperProps:t})=>f&&f({annotation:r,selected:u,rect:e,menuWrapperProps:t})})]})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l},...a},d)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:d,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:d,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function y({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s,c=6*s,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*d}" viewBox="0 0 ${c} ${2*d}">\n <path d="M0 ${d} Q ${c/4} 0 ${c/2} ${d} T ${c} ${d}"\n fill="none" stroke="${e}" stroke-width="${d}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*s,top:(i?e.origin.y-i.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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*d,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*d}px`,opacity:t,pointerEvents:"none"}})},o)))})}function f({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:s,rect:r,scale:a,onClick:d}){const c=l.useMemo((()=>s.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-r.origin.x,s=n-r.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "})),t.trim()}))),[s,r]),u=r.size.width*a,h=r.size.height*a;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${r.size.width} ${r.size.height}`,children:c.map(((s,r)=>n.jsx("path",{d:s,fill:"none",opacity:o,onPointerDown:d,onTouchStart:d,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function b({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:r,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,scale:u,onClick:h}){const{width:g,height:p,x:x,y:y}=l.useMemo((()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}}),[c,r]),f=(g+r)*u,b=(p+r)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:b,pointerEvents:"none",zIndex:2},width:f,height:b,viewBox:`0 0 ${g+r} ${p+r}`,children:n.jsx("rect",{x:x,y:y,width:g,height:p,fill:t,opacity:s,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:r,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}function v({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:r=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:d,scale:c,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:y,rx:f,ry:b}=l.useMemo((()=>{const e=d.size.width,t=d.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}}),[d,s]),v=g*c,j=p*c;return n.jsx("svg",{style:{position:"absolute",width:v,height:j,pointerEvents:"none",zIndex:2},width:v,height:j,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:x,cy:y,rx:f,ry:b,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...r===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function j({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:r="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:y,y1:f,x2:b,y2:v}=l.useMemo((()=>({x1:u.start.x-c.origin.x,y1:u.start.y-c.origin.y,x2:u.end.x-c.origin.x,y2:u.end.y-c.origin.y})),[u,c]),j=l.useMemo((()=>{const e=Math.atan2(v-f,b-y);return{start:t.patching.createEnding(null==h?void 0:h.start,s,e+Math.PI,y,f),end:t.patching.createEnding(null==h?void 0:h.end,s,e,b,v)}}),[h,s,y,f,b,v]),m=c.size.width*g,k=c.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:m,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:k,viewBox:`0 0 ${c.size.width} ${c.size.height}`,children:[n.jsx("line",{x1:y,y1:f,x2:b,y2:v,opacity:i,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:r,strokeWidth:s,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),j.start&&n.jsx("path",{d:j.start.d,transform:j.start.transform,onPointerDown:p,onTouchStart:p,stroke:r,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.start.filled?e:"none"}),j.end&&n.jsx("path",{d:j.end.d,transform:j.end.transform,stroke:r,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.end.filled?e:"none"})]})}function m({rect:e,vertices:o,color:i="transparent",strokeColor:s="#000000",opacity:r=1,strokeWidth:a,scale:d,isSelected:c,onClick:u,lineEndings:h}){const g=l.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),p=l.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=l.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]),y=e.size.width*d,f=e.size.height*d;return n.jsxs("svg",{style:{position:"absolute",width:y,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:y,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:r,style:{fill:"none",stroke:s??i,strokeWidth:a,cursor:c?"move":"pointer",pointerEvents:c?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&n.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:s,fill:x.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&n.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:s,fill:x.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:r=1,strokeWidth:a,strokeStyle:d=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const y=p?[...t,p]:t,f=l.useMemo((()=>y.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[y,e]),b=l.useMemo((()=>{if(!f.length)return"";const[e,...t]=f,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[f,p]),v=p&&t.length>0,j=e.size.width*u,m=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:j,height:m,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:m,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:b,onPointerDown:g,onTouchStart:g,opacity:r,style:{fill:p?"none":i,stroke:s??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...d===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),v&&t.length>1&&n.jsx("path",{d:`M ${f[f.length-1].x} ${f[f.length-1].y} L ${f[0].x} ${f[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),v&&t.length>=2&&n.jsx("rect",{x:f[0].x-x/u/2,y:f[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:i,pageIndex:s,scale:r,onClick:a}){const d=l.useRef(null),{provides:h}=c(),[g,p]=l.useState(!1);l.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]),l.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=i.object.fontSize*r,y=g&&t&&x>0&&x<16,f=y?16:x,b=y?x/16:1,v=y?100/b:100;return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*r,height:i.object.rect.size.height*r,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:d,onBlur:()=>{h&&d.current&&h.updateAnnotation(s,i.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:f,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:y?`${v}%`:"100%",height:y?`${v}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:y?`scale(${b})`:void 0,transformOrigin:"top left"},contentEditable:t,...u,children:i.object.contents})})}function M({pageIndex:e,annotation:t,scaleFactor:i=1,style:s,...a}){const{provides:d}=c(),[u,h]=l.useState(null),g=l.useRef(null),{width:p,height:x}=t.rect.size;l.useEffect((()=>{if(d){const n=d.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:i,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);h(t),g.current=t}),o.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,d,t.id,p,x]);return n.jsx(r.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...a,style:{width:"100%",height:"100%",...s||{}}})})}function w({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:s}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:s,onTouchStart:s,children:n.jsx(M,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function P(e){const{pageIndex:a,scale:d,selectionMenu:u}=e,{provides:M}=c(),{provides:P}=s.useSelectionCapability(),[C,z]=l.useState([]),{register:A}=i.usePointerHandlers({pageIndex:a}),[I,D]=l.useState(null),[E,B]=l.useState(null);l.useEffect((()=>{M&&M.onStateChange((e=>{z(t.getAnnotationsByPageIndex(e,a)),D(t.getSelectedAnnotationByPageIndex(e,a))}))}),[M]);const R=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&M&&(M.deselectAnnotation(),B(null))}})),[M]),T=l.useCallback(((e,t)=>{e.stopPropagation(),M&&P&&(M.selectAnnotation(a,t.object.id),P.clear(),t.object.id!==E&&B(null))}),[M,P,E,a]);return l.useEffect((()=>A(R)),[A,R]),n.jsx(n.Fragment,{children:C.map((i=>{const s=(null==I?void 0:I.object.id)===i.object.id,l=E===i.object.id;return t.isInk(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isSquare(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isCircle(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(p,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isLine(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(j,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(m,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(k,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!l,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),B(i.object.id)},...e,children:e=>n.jsx(S,{isSelected:s,isEditing:l,annotation:{...i,object:e},pageIndex:a,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isStamp(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(w,{isSelected:s,annotation:i,pageIndex:a,scale:d,onClick:e=>T(e,i)})},i.object.id):null}))})}function C({pageIndex:e,scale:t}){var i,r,a,d,u,h,f,b,v,j,m,k;const{provides:S}=s.useSelectionCapability(),{provides:M}=c(),[w,P]=l.useState([]),[C,z]=l.useState(null),[A,I]=l.useState(null);if(l.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{P(S.getHighlightRectsForPage(e)),z(S.getBoundingRectForPage(e))}))}),[S,e]),l.useEffect((()=>{if(!M)return;return M.onActiveToolChange(I)}),[M]),!C)return null;if(!A||!A.defaults)return null;switch(A.defaults.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=A.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(r=A.defaults)?void 0:r.color,opacity:null==(a=A.defaults)?void 0:a.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=A.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(u=A.defaults)?void 0:u.color,opacity:null==(h=A.defaults)?void 0:h.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(f=A.defaults)?void 0:f.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(b=A.defaults)?void 0:b.color,opacity:null==(v=A.defaults)?void 0:v.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(j=A.defaults)?void 0:j.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(m=A.defaults)?void 0:m.color,opacity:null==(k=A.defaults)?void 0:k.opacity,segmentRects:w,scale:t})});default:return null}}function z({preview:e,scale:t}){const{bounds:i}=e,s={position:"absolute",left:i.origin.x*t,top:i.origin.y*t,width:i.size.width*t,height:i.size.height*t,pointerEvents:"none",zIndex:10};return e.type===o.PdfAnnotationSubtype.CIRCLE?n.jsx("div",{style:s,children:n.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:s,children:n.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:s,children:n.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:s,children:n.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.LINE?n.jsx("div",{style:s,children:n.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.INK?n.jsx("div",{style:s,children:n.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.FREETEXT?n.jsx("div",{style:s,children:n.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function A({pageIndex:e,scale:t}){const{plugin:o}=d(),[i,s]=l.useState(new Map),r=l.useRef(null),a=l.useRef(null),c=l.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!r.current)return;const n=r.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 d=t?t/l:1,c=n?n/a:1,u=Math.min(d,c,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 l.useEffect((()=>{if(o)return o.registerPageHandlers(e,t,{services:c,onPreview:(e,t)=>{s((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,o,c]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:r,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:a,style:{display:"none"}}),Array.from(i.entries()).map((([e,o])=>n.jsx(z,{preview:o,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:o,selectionMenu:i,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:d,selectionOutlineColor:c,...u}){return n.jsxs("div",{style:{...e},...u,children:[n.jsx(P,{selectionMenu:i,pageIndex:t,scale:o,rotation:d,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:c}),n.jsx(C,{pageIndex:t,scale:o}),n.jsx(A,{pageIndex:t,scale:o})]})},exports.useAnnotationCapability=c,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
|