@embedpdf/plugin-annotation 1.1.0 → 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/actions.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Action } from '@embedpdf/core';
|
|
2
2
|
import { PdfAnnotationObject } from '@embedpdf/models';
|
|
3
|
-
import {
|
|
3
|
+
import { AnnotationTool } from './tools/types';
|
|
4
4
|
export declare const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
|
|
5
5
|
export declare const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
|
|
6
6
|
export declare const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
|
|
7
|
-
export declare const UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
|
|
8
7
|
export declare const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
|
|
9
8
|
export declare const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
|
|
10
9
|
export declare const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
|
|
11
10
|
export declare const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
|
|
12
11
|
export declare const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
|
|
13
12
|
export declare const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
|
|
14
|
-
export declare const
|
|
13
|
+
export declare const SET_ACTIVE_TOOL_ID = "ANNOTATION/SET_ACTIVE_TOOL_ID";
|
|
14
|
+
export declare const SET_TOOL_DEFAULTS = "ANNOTATION/SET_TOOL_DEFAULTS";
|
|
15
|
+
export declare const ADD_TOOL = "ANNOTATION/ADD_TOOL";
|
|
15
16
|
export interface SetAnnotationsAction extends Action {
|
|
16
17
|
type: typeof SET_ANNOTATIONS;
|
|
17
18
|
payload: Record<number, PdfAnnotationObject[]>;
|
|
@@ -26,13 +27,6 @@ export interface SelectAnnotationAction extends Action {
|
|
|
26
27
|
export interface DeselectAnnotationAction extends Action {
|
|
27
28
|
type: typeof DESELECT_ANNOTATION;
|
|
28
29
|
}
|
|
29
|
-
export interface UpdateToolDefaultsAction extends Action {
|
|
30
|
-
type: typeof UPDATE_TOOL_DEFAULTS;
|
|
31
|
-
payload: {
|
|
32
|
-
variantKey: string;
|
|
33
|
-
patch: Partial<AnnotationDefaults>;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
30
|
export interface AddColorPresetAction extends Action {
|
|
37
31
|
type: typeof ADD_COLOR_PRESET;
|
|
38
32
|
payload: string;
|
|
@@ -68,19 +62,31 @@ export interface PurgeAnnotationAction extends Action {
|
|
|
68
62
|
uid: string;
|
|
69
63
|
};
|
|
70
64
|
}
|
|
71
|
-
export interface
|
|
72
|
-
type: typeof
|
|
65
|
+
export interface SetActiveToolIdAction extends Action {
|
|
66
|
+
type: typeof SET_ACTIVE_TOOL_ID;
|
|
73
67
|
payload: string | null;
|
|
74
68
|
}
|
|
75
|
-
export
|
|
69
|
+
export interface SetToolDefaultsAction extends Action {
|
|
70
|
+
type: typeof SET_TOOL_DEFAULTS;
|
|
71
|
+
payload: {
|
|
72
|
+
toolId: string;
|
|
73
|
+
patch: Partial<any>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface AddToolAction extends Action {
|
|
77
|
+
type: typeof ADD_TOOL;
|
|
78
|
+
payload: AnnotationTool;
|
|
79
|
+
}
|
|
80
|
+
export type AnnotationAction = SetAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | AddColorPresetAction | CreateAnnotationAction | PatchAnnotationAction | DeleteAnnotationAction | CommitAction | PurgeAnnotationAction | SetActiveToolIdAction | SetToolDefaultsAction | AddToolAction;
|
|
76
81
|
export declare const setAnnotations: (p: Record<number, PdfAnnotationObject[]>) => SetAnnotationsAction;
|
|
77
82
|
export declare const selectAnnotation: (pageIndex: number, id: string) => SelectAnnotationAction;
|
|
78
83
|
export declare const deselectAnnotation: () => DeselectAnnotationAction;
|
|
79
|
-
export declare const updateToolDefaults: (variantKey: string, patch: Partial<AnnotationDefaults>) => UpdateToolDefaultsAction;
|
|
80
84
|
export declare const addColorPreset: (c: string) => AddColorPresetAction;
|
|
81
85
|
export declare const createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) => CreateAnnotationAction;
|
|
82
86
|
export declare const patchAnnotation: (pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
|
|
83
87
|
export declare const deleteAnnotation: (pageIndex: number, id: string) => DeleteAnnotationAction;
|
|
84
88
|
export declare const commitPendingChanges: () => CommitAction;
|
|
85
89
|
export declare const purgeAnnotation: (uid: string) => PurgeAnnotationAction;
|
|
86
|
-
export declare const
|
|
90
|
+
export declare const setActiveToolId: (id: string | null) => SetActiveToolIdAction;
|
|
91
|
+
export declare const setToolDefaults: (toolId: string, patch: Partial<any>) => SetToolDefaultsAction;
|
|
92
|
+
export declare const addTool: (tool: AnnotationTool) => AddToolAction;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { BasePlugin, PluginRegistry } from '@embedpdf/core';
|
|
2
|
+
import { PdfAnnotationObject } from '@embedpdf/models';
|
|
2
3
|
import { AnnotationCapability, AnnotationPluginConfig, AnnotationState } from './types';
|
|
3
4
|
import { AnnotationAction } from './actions';
|
|
5
|
+
import { AnnotationTool } from './tools/types';
|
|
6
|
+
import { AnyPreviewState, HandlerServices } from './handlers/types';
|
|
4
7
|
export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig, AnnotationCapability, AnnotationState, AnnotationAction> {
|
|
5
8
|
static readonly id: "annotation";
|
|
6
9
|
private readonly ANNOTATION_HISTORY_TOPIC;
|
|
@@ -9,25 +12,45 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
|
|
|
9
12
|
private readonly interactionManager;
|
|
10
13
|
private readonly selection;
|
|
11
14
|
private readonly history;
|
|
12
|
-
private readonly modeByVariant;
|
|
13
|
-
private readonly variantByMode;
|
|
14
15
|
private pendingContexts;
|
|
15
|
-
private
|
|
16
|
+
private handlerFactories;
|
|
16
17
|
private readonly activeTool$;
|
|
18
|
+
private readonly events$;
|
|
19
|
+
private readonly patchRegistry;
|
|
20
|
+
private isInitialLoadComplete;
|
|
21
|
+
private importQueue;
|
|
17
22
|
constructor(id: string, registry: PluginRegistry, config: AnnotationPluginConfig);
|
|
23
|
+
private registerHandlerFactories;
|
|
24
|
+
private registerBuiltInPatches;
|
|
18
25
|
initialize(): Promise<void>;
|
|
19
|
-
private
|
|
26
|
+
private registerInteractionForTool;
|
|
20
27
|
protected buildCapability(): AnnotationCapability;
|
|
21
|
-
private createActiveTool;
|
|
22
|
-
private emitActiveTool;
|
|
23
28
|
onStoreUpdated(prev: AnnotationState, next: AnnotationState): void;
|
|
29
|
+
private registerPatchFunction;
|
|
30
|
+
private transformAnnotation;
|
|
31
|
+
registerPageHandlers(pageIndex: number, scale: number, callbacks: {
|
|
32
|
+
services: HandlerServices;
|
|
33
|
+
onPreview: (toolId: string, state: AnyPreviewState | null) => void;
|
|
34
|
+
}): () => void;
|
|
24
35
|
private getAllAnnotations;
|
|
25
36
|
private getPageAnnotations;
|
|
26
37
|
private renderAnnotation;
|
|
27
|
-
private
|
|
38
|
+
private importAnnotations;
|
|
39
|
+
private processImportQueue;
|
|
40
|
+
private processImportItems;
|
|
28
41
|
private createAnnotation;
|
|
29
42
|
private buildPatch;
|
|
30
43
|
private updateAnnotation;
|
|
31
44
|
private deleteAnnotation;
|
|
45
|
+
private selectAnnotation;
|
|
46
|
+
getActiveTool(): AnnotationTool | null;
|
|
47
|
+
setActiveTool(toolId: string | null): void;
|
|
48
|
+
getTool<T extends AnnotationTool>(toolId: string): T | undefined;
|
|
49
|
+
findToolForAnnotation(annotation: PdfAnnotationObject): AnnotationTool | null;
|
|
32
50
|
private commit;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the effective behavior setting for a tool, checking tool-specific config first,
|
|
53
|
+
* then falling back to plugin config.
|
|
54
|
+
*/
|
|
55
|
+
private getToolBehavior;
|
|
33
56
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PdfAnnotationObject } from '@embedpdf/models';
|
|
2
|
+
import { AnnotationTool } from '../tools/types';
|
|
3
|
+
interface ClickDetectorOptions<T extends PdfAnnotationObject> {
|
|
4
|
+
threshold?: number;
|
|
5
|
+
getTool: () => AnnotationTool<T> | undefined;
|
|
6
|
+
onClickDetected: (pos: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}, tool: AnnotationTool<T>) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function useClickDetector<T extends PdfAnnotationObject>({ threshold, getTool, onClickDetected, }: ClickDetectorOptions<T>): {
|
|
12
|
+
onStart: (pos: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}) => void;
|
|
16
|
+
onMove: (pos: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}) => void;
|
|
20
|
+
onEnd: (pos: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}) => void;
|
|
24
|
+
hasMoved: () => boolean;
|
|
25
|
+
reset: () => void;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './ink.handler';
|
|
2
|
+
export * from './free-text.handler';
|
|
3
|
+
export * from './line.handler';
|
|
4
|
+
export * from './polyline.handler';
|
|
5
|
+
export * from './polygon.handler';
|
|
6
|
+
export * from './square.handler';
|
|
7
|
+
export * from './stamp.handler';
|
|
8
|
+
export * from './circle.handler';
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';
|
|
2
|
+
import { PdfAnnotationObject, PdfAnnotationSubtype, Rect, Size, AnnotationCreateContext, PdfAnnotationBorderStyle, Position, LineEndings, PdfInkListObject, PdfStandardFont, PdfTextAlignment, PdfVerticalAlignment } from '@embedpdf/models';
|
|
3
|
+
import { AnnotationTool } from '../tools/types';
|
|
4
|
+
export interface CirclePreviewData {
|
|
5
|
+
rect: Rect;
|
|
6
|
+
color: string;
|
|
7
|
+
opacity: number;
|
|
8
|
+
strokeWidth: number;
|
|
9
|
+
strokeColor: string;
|
|
10
|
+
strokeStyle: PdfAnnotationBorderStyle;
|
|
11
|
+
strokeDashArray: number[];
|
|
12
|
+
}
|
|
13
|
+
interface SquarePreviewData extends CirclePreviewData {
|
|
14
|
+
}
|
|
15
|
+
export interface PolygonPreviewData {
|
|
16
|
+
rect: Rect;
|
|
17
|
+
vertices: Position[];
|
|
18
|
+
currentVertex: Position;
|
|
19
|
+
color?: string;
|
|
20
|
+
opacity?: number;
|
|
21
|
+
strokeWidth: number;
|
|
22
|
+
strokeColor?: string;
|
|
23
|
+
strokeStyle?: PdfAnnotationBorderStyle;
|
|
24
|
+
strokeDashArray?: number[];
|
|
25
|
+
}
|
|
26
|
+
export interface PolylinePreviewData {
|
|
27
|
+
rect: Rect;
|
|
28
|
+
vertices: Position[];
|
|
29
|
+
currentVertex: Position;
|
|
30
|
+
color: string;
|
|
31
|
+
strokeColor: string;
|
|
32
|
+
opacity: number;
|
|
33
|
+
strokeWidth: number;
|
|
34
|
+
lineEndings?: LineEndings;
|
|
35
|
+
}
|
|
36
|
+
export interface LinePreviewData {
|
|
37
|
+
rect: Rect;
|
|
38
|
+
linePoints: {
|
|
39
|
+
start: Position;
|
|
40
|
+
end: Position;
|
|
41
|
+
};
|
|
42
|
+
strokeWidth: number;
|
|
43
|
+
color: string;
|
|
44
|
+
strokeColor: string;
|
|
45
|
+
opacity: number;
|
|
46
|
+
lineEndings?: LineEndings;
|
|
47
|
+
strokeStyle: PdfAnnotationBorderStyle;
|
|
48
|
+
strokeDashArray: number[];
|
|
49
|
+
}
|
|
50
|
+
export interface InkPreviewData {
|
|
51
|
+
rect: Rect;
|
|
52
|
+
inkList: PdfInkListObject[];
|
|
53
|
+
strokeWidth: number;
|
|
54
|
+
color: string;
|
|
55
|
+
opacity: number;
|
|
56
|
+
}
|
|
57
|
+
export interface FreeTextPreviewData {
|
|
58
|
+
rect: Rect;
|
|
59
|
+
fontColor?: string;
|
|
60
|
+
opacity?: number;
|
|
61
|
+
fontSize?: number;
|
|
62
|
+
fontFamily?: PdfStandardFont;
|
|
63
|
+
backgroundColor?: string;
|
|
64
|
+
textAlign?: PdfTextAlignment;
|
|
65
|
+
verticalAlign?: PdfVerticalAlignment;
|
|
66
|
+
contents?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Map types to their preview data
|
|
70
|
+
*/
|
|
71
|
+
export interface PreviewDataMap {
|
|
72
|
+
[PdfAnnotationSubtype.CIRCLE]: CirclePreviewData;
|
|
73
|
+
[PdfAnnotationSubtype.SQUARE]: SquarePreviewData;
|
|
74
|
+
[PdfAnnotationSubtype.POLYGON]: PolygonPreviewData;
|
|
75
|
+
[PdfAnnotationSubtype.POLYLINE]: PolylinePreviewData;
|
|
76
|
+
[PdfAnnotationSubtype.LINE]: LinePreviewData;
|
|
77
|
+
[PdfAnnotationSubtype.INK]: InkPreviewData;
|
|
78
|
+
[PdfAnnotationSubtype.FREETEXT]: FreeTextPreviewData;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Typed preview state - constrain T to keys that exist in PreviewDataMap
|
|
82
|
+
*/
|
|
83
|
+
export type TypedPreviewState<T extends keyof PreviewDataMap> = {
|
|
84
|
+
type: T;
|
|
85
|
+
bounds: Rect;
|
|
86
|
+
data: PreviewDataMap[T];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Union of all preview states
|
|
90
|
+
*/
|
|
91
|
+
export type AnyPreviewState = {
|
|
92
|
+
[K in keyof PreviewDataMap]: TypedPreviewState<K>;
|
|
93
|
+
}[keyof PreviewDataMap];
|
|
94
|
+
/**
|
|
95
|
+
* Generic version for handlers - use conditional type for safety
|
|
96
|
+
*/
|
|
97
|
+
export interface PreviewState<T extends PdfAnnotationSubtype = PdfAnnotationSubtype> {
|
|
98
|
+
type: T;
|
|
99
|
+
bounds: Rect;
|
|
100
|
+
data: T extends keyof PreviewDataMap ? PreviewDataMap[T] : any;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Defines the DOM-based services that the UI layer must provide to the handlers.
|
|
104
|
+
* This is the bridge that keeps the core logic framework-agnostic.
|
|
105
|
+
*/
|
|
106
|
+
export interface HandlerServices {
|
|
107
|
+
requestFile(options: {
|
|
108
|
+
accept: string;
|
|
109
|
+
onFile: (file: File) => void;
|
|
110
|
+
}): void;
|
|
111
|
+
processImage(options: {
|
|
112
|
+
source: string | File;
|
|
113
|
+
maxWidth?: number;
|
|
114
|
+
maxHeight?: number;
|
|
115
|
+
onComplete: (result: {
|
|
116
|
+
imageData: ImageData;
|
|
117
|
+
width: number;
|
|
118
|
+
height: number;
|
|
119
|
+
}) => void;
|
|
120
|
+
}): void;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The context object passed to a handler factory when creating a handler.
|
|
124
|
+
* It contains all the necessary information and callbacks.
|
|
125
|
+
*/
|
|
126
|
+
export interface HandlerFactory<A extends PdfAnnotationObject> {
|
|
127
|
+
annotationType: PdfAnnotationSubtype;
|
|
128
|
+
create(context: HandlerContext<A>): PointerEventHandlersWithLifecycle;
|
|
129
|
+
}
|
|
130
|
+
export interface HandlerContext<A extends PdfAnnotationObject> {
|
|
131
|
+
getTool: () => AnnotationTool<A> | undefined;
|
|
132
|
+
pageIndex: number;
|
|
133
|
+
pageSize: Size;
|
|
134
|
+
scale: number;
|
|
135
|
+
services: HandlerServices;
|
|
136
|
+
onPreview: (state: AnyPreviewState | null) => void;
|
|
137
|
+
onCommit: (annotation: A, context?: AnnotationCreateContext<A>) => void;
|
|
138
|
+
}
|
|
139
|
+
export {};
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfAnnotationSubtype, PdfAnnotationObject } from '@embedpdf/models';
|
|
2
|
-
import { TrackedAnnotation
|
|
2
|
+
import { TrackedAnnotation } from './types';
|
|
3
3
|
export type AnnoOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject, {
|
|
4
4
|
type: S;
|
|
5
5
|
}>;
|
|
@@ -22,8 +22,3 @@ export declare function isFreeText(a: TrackedAnnotation): a is TrackedAnnotation
|
|
|
22
22
|
export declare function isStamp(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.STAMP>>;
|
|
23
23
|
export declare function isText(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.TEXT>>;
|
|
24
24
|
export declare function isSidebarAnnotation(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<SidebarSubtype>>;
|
|
25
|
-
export declare function isHighlightDefaults(defaults: AnnotationDefaults): defaults is HighlightDefaults;
|
|
26
|
-
export declare function isUnderlineDefaults(defaults: AnnotationDefaults): defaults is UnderlineDefaults;
|
|
27
|
-
export declare function isStrikeoutDefaults(defaults: AnnotationDefaults): defaults is StrikeoutDefaults;
|
|
28
|
-
export declare function isSquigglyDefaults(defaults: AnnotationDefaults): defaults is SquigglyDefaults;
|
|
29
|
-
export declare function isTextMarkupDefaults(defaults: AnnotationDefaults): defaults is HighlightDefaults | UnderlineDefaults | StrikeoutDefaults | SquigglyDefaults;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export * from './annotation-plugin';
|
|
|
7
7
|
export * from './types';
|
|
8
8
|
export * from './manifest';
|
|
9
9
|
export * from './selectors';
|
|
10
|
-
export * from './variant-key';
|
|
11
10
|
export * from './helpers';
|
|
11
|
+
export * from './handlers/types';
|
|
12
|
+
export * from './tools/types';
|
|
13
|
+
export * from './tools/tools-utils';
|
|
12
14
|
export * as patching from './patching';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PdfAnnotationObject, PdfAnnotationSubtype } from '@embedpdf/models';
|
|
2
|
+
export interface TransformContext<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
3
|
+
/** The type of transformation being applied */
|
|
4
|
+
type: 'move' | 'resize' | 'vertex-edit' | 'property-update';
|
|
5
|
+
/** The changes being applied - can be any properties of the annotation */
|
|
6
|
+
changes: Partial<T>;
|
|
7
|
+
/** Optional metadata about the transformation */
|
|
8
|
+
metadata?: {
|
|
9
|
+
maintainAspectRatio?: boolean;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type PatchFunction<T extends PdfAnnotationObject> = (original: T, context: TransformContext<T>) => Partial<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Registry for annotation-specific patch functions.
|
|
16
|
+
* Each patch function knows how to transform its annotation type.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PatchRegistry {
|
|
19
|
+
private patches;
|
|
20
|
+
register<T extends PdfAnnotationObject>(type: PdfAnnotationSubtype, patchFn: PatchFunction<T>): void;
|
|
21
|
+
/**
|
|
22
|
+
* Transform an annotation based on the context.
|
|
23
|
+
* Returns the transformed properties or just the changes if no patch function exists.
|
|
24
|
+
*/
|
|
25
|
+
transform<T extends PdfAnnotationObject>(annotation: T, context: TransformContext<T>): Partial<T>;
|
|
26
|
+
}
|
|
27
|
+
export declare const patchRegistry: PatchRegistry;
|
package/dist/lib/selectors.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnnotationState, SidebarAnnotationEntry, TrackedAnnotation } from './types';
|
|
2
|
+
import { ToolMap } from './tools/tools-utils';
|
|
2
3
|
/** All annotations _objects_ on a single page (order preserved). */
|
|
3
4
|
export declare const getAnnotationsByPageIndex: (s: AnnotationState, page: number) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>[];
|
|
4
5
|
/** Shortcut: every page → list of annotation objects. */
|
|
@@ -6,22 +7,17 @@ export declare const getAnnotations: (s: AnnotationState) => Record<number, Trac
|
|
|
6
7
|
/** The full `TrackedAnnotation` for the current selection. */
|
|
7
8
|
export declare const getSelectedAnnotation: (s: AnnotationState) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
8
9
|
export declare const getSelectedAnnotationByPageIndex: (s: AnnotationState, pageIndex: number) => TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
9
|
-
export declare const isInAnnotationVariant: (s: AnnotationState) => boolean;
|
|
10
|
-
export declare const getSelectedAnnotationVariant: (s: AnnotationState) => string | null;
|
|
11
10
|
/** Check if a given anno on a page is the current selection. */
|
|
12
11
|
export declare const isAnnotationSelected: (s: AnnotationState, id: string) => boolean;
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* falls back to the plain subtype variant.
|
|
13
|
+
* Returns the current defaults for a specific tool by its ID.
|
|
14
|
+
* This is fully type-safe and infers the correct return type.
|
|
17
15
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* `
|
|
16
|
+
* @param state The annotation plugin's state.
|
|
17
|
+
* @param toolId The ID of the tool (e.g., 'highlight', 'pen').
|
|
18
|
+
* @returns The tool's current `defaults` object, or `undefined` if not found.
|
|
21
19
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
subtype: TSub;
|
|
24
|
-
}>;
|
|
20
|
+
export declare function getToolDefaultsById<K extends keyof ToolMap>(state: AnnotationState, toolId: K): ToolMap[K]['defaults'] | undefined;
|
|
25
21
|
/**
|
|
26
22
|
* Collect every sidebar-eligible annotation and attach its TEXT replies,
|
|
27
23
|
* grouped by page for efficient rendering.
|