@embedpdf/plugin-annotation 1.0.12 → 1.0.14
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 +391 -31
- package/dist/index.js.map +1 -1
- package/dist/lib/annotation-plugin.d.ts +1 -0
- package/dist/lib/helpers.d.ts +24 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/patching/derived-rect.d.ts +2 -0
- package/dist/lib/patching/index.d.ts +4 -0
- package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
- package/dist/lib/patching/line-endings.d.ts +13 -0
- package/dist/lib/patching/patch-utils.d.ts +7 -0
- package/dist/lib/selectors.d.ts +17 -5
- package/dist/lib/types.d.ts +97 -12
- package/dist/preact/adapter.d.ts +6 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +2348 -447
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +6 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2347 -446
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +14 -8
- package/dist/shared-preact/components/annotation-layer.d.ts +3 -1
- package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
- package/dist/shared-preact/components/annotations/free-text-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/free-text.d.ts +13 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +2 -1
- package/dist/shared-preact/components/annotations/ink.d.ts +3 -1
- package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/line.d.ts +33 -0
- package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/square.d.ts +29 -0
- package/dist/shared-preact/components/annotations.d.ts +4 -0
- package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-preact/components/resize-handles.d.ts +9 -0
- package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
- package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-preact/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
- package/dist/shared-preact/patchers.d.ts +9 -0
- package/dist/shared-preact/types.d.ts +11 -0
- package/dist/shared-preact/vertex-patchers.d.ts +10 -0
- package/dist/shared-react/components/annotation-container.d.ts +14 -8
- package/dist/shared-react/components/annotation-layer.d.ts +3 -1
- package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/circle.d.ts +29 -0
- package/dist/shared-react/components/annotations/free-text-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/free-text.d.ts +13 -0
- package/dist/shared-react/components/annotations/ink.d.ts +3 -1
- package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/line.d.ts +33 -0
- package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/square.d.ts +29 -0
- package/dist/shared-react/components/annotations.d.ts +4 -0
- package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-react/components/resize-handles.d.ts +9 -0
- package/dist/shared-react/components/vertex-editor.d.ts +19 -0
- package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-react/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
- package/dist/shared-react/patchers.d.ts +9 -0
- package/dist/shared-react/types.d.ts +11 -0
- package/dist/shared-react/vertex-patchers.d.ts +10 -0
- package/package.json +9 -9
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface PolygonPaintProps {
|
|
2
|
+
pageIndex: number;
|
|
3
|
+
scale: number;
|
|
4
|
+
pageWidth: number;
|
|
5
|
+
pageHeight: number;
|
|
6
|
+
cursor?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const PolygonPaint: ({ pageIndex, scale, pageWidth, pageHeight, cursor, }: PolygonPaintProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MouseEvent } from '../../../react/adapter.ts';
|
|
2
|
+
import { Rect, Position, PdfAnnotationBorderStyle } from '@embedpdf/models';
|
|
3
|
+
interface PolygonProps {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
vertices: Position[];
|
|
6
|
+
color?: string;
|
|
7
|
+
strokeColor?: string;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
strokeWidth: number;
|
|
10
|
+
strokeStyle?: PdfAnnotationBorderStyle;
|
|
11
|
+
strokeDashArray?: number[];
|
|
12
|
+
scale: number;
|
|
13
|
+
isSelected: boolean;
|
|
14
|
+
onClick?: (e: MouseEvent<SVGElement>) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function Polygon({ rect, vertices, color, strokeColor, opacity, strokeWidth, strokeStyle, strokeDashArray, scale, isSelected, onClick, }: PolygonProps): JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface PolylinePaintProps {
|
|
2
|
+
pageIndex: number;
|
|
3
|
+
scale: number;
|
|
4
|
+
pageWidth: number;
|
|
5
|
+
pageHeight: number;
|
|
6
|
+
/** Optional preview cursor */
|
|
7
|
+
cursor?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const PolylinePaint: ({ pageIndex, scale, pageWidth, pageHeight, cursor, }: PolylinePaintProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MouseEvent } from '../../../react/adapter.ts';
|
|
2
|
+
import { Rect, Position, LineEndings } from '@embedpdf/models';
|
|
3
|
+
interface PolylineProps {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
vertices: Position[];
|
|
6
|
+
color?: string;
|
|
7
|
+
strokeColor?: string;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
strokeWidth: number;
|
|
10
|
+
scale: number;
|
|
11
|
+
isSelected: boolean;
|
|
12
|
+
onClick?: (e: MouseEvent<SVGElement>) => void;
|
|
13
|
+
/** Optional start & end endings */
|
|
14
|
+
lineEndings?: LineEndings;
|
|
15
|
+
}
|
|
16
|
+
export declare function Polyline({ rect, vertices, color, strokeColor, opacity, strokeWidth, scale, isSelected, onClick, lineEndings, }: PolylineProps): JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface SquarePaintProps {
|
|
2
|
+
pageIndex: number;
|
|
3
|
+
scale: number;
|
|
4
|
+
pageWidth: number;
|
|
5
|
+
pageHeight: number;
|
|
6
|
+
/** Optional preview cursor */
|
|
7
|
+
cursor?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const SquarePaint: ({ pageIndex, scale, pageWidth, pageHeight, cursor, }: SquarePaintProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MouseEvent } from '../../../react/adapter.ts';
|
|
2
|
+
import { PdfAnnotationBorderStyle, Rect } from '@embedpdf/models';
|
|
3
|
+
interface SquareProps {
|
|
4
|
+
/** Fill colour – defaults to PDFium’s black if omitted */
|
|
5
|
+
color?: string;
|
|
6
|
+
/** Stroke colour – defaults to same as fill when omitted */
|
|
7
|
+
strokeColor?: string;
|
|
8
|
+
/** 0 – 1 */
|
|
9
|
+
opacity?: number;
|
|
10
|
+
/** Stroke width in PDF units */
|
|
11
|
+
strokeWidth: number;
|
|
12
|
+
/** Stroke type – defaults to solid when omitted */
|
|
13
|
+
strokeStyle?: PdfAnnotationBorderStyle;
|
|
14
|
+
/** Stroke dash array – defaults to undefined when omitted */
|
|
15
|
+
strokeDashArray?: number[];
|
|
16
|
+
/** Bounding box of the annotation (PDF units) */
|
|
17
|
+
rect: Rect;
|
|
18
|
+
/** Current page zoom factor */
|
|
19
|
+
scale: number;
|
|
20
|
+
/** Click handler (used for selection) */
|
|
21
|
+
onClick?: (e: MouseEvent<SVGElement>) => void;
|
|
22
|
+
/** Cursor shown over the annotation */
|
|
23
|
+
cursor?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Renders a PDF Square annotation (rectangle) as SVG.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Square({ color, strokeColor, opacity, strokeWidth, strokeStyle, strokeDashArray, rect, scale, onClick, cursor, }: SquareProps): JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { SelectionMenu } from '../types';
|
|
1
2
|
interface AnnotationsProps {
|
|
2
3
|
pageIndex: number;
|
|
3
4
|
scale: number;
|
|
4
5
|
rotation: number;
|
|
6
|
+
pageWidth: number;
|
|
7
|
+
pageHeight: number;
|
|
8
|
+
selectionMenu?: SelectionMenu;
|
|
5
9
|
}
|
|
6
10
|
export declare function Annotations(annotationsProps: AnnotationsProps): import("react/jsx-runtime").JSX.Element;
|
|
7
11
|
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Rect, Rotation } from '@embedpdf/models';
|
|
2
|
+
import { ReactNode, CSSProperties, PointerEvent } from '../../react/adapter.ts';
|
|
3
|
+
interface CounterRotateProps {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
rotation: Rotation;
|
|
6
|
+
}
|
|
7
|
+
interface CounterTransformResult {
|
|
8
|
+
matrix: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Given an already-placed rect (left/top/width/height in px) and the page rotation,
|
|
14
|
+
* return the counter-rotation matrix + adjusted width/height.
|
|
15
|
+
*
|
|
16
|
+
* transform-origin is expected to be "0 0".
|
|
17
|
+
* left/top DO NOT change, apply them as-is.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult;
|
|
20
|
+
export interface MenuWrapperProps {
|
|
21
|
+
style: CSSProperties;
|
|
22
|
+
onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
|
|
23
|
+
}
|
|
24
|
+
interface CounterRotateComponentProps extends CounterRotateProps {
|
|
25
|
+
children: (props: {
|
|
26
|
+
matrix: string;
|
|
27
|
+
rect: Rect;
|
|
28
|
+
menuWrapperProps: MenuWrapperProps;
|
|
29
|
+
}) => ReactNode;
|
|
30
|
+
}
|
|
31
|
+
export declare function CounterRotate({ children, ...props }: CounterRotateComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResizeDirection } from '../types';
|
|
2
|
+
import { PointerEvent } from '../../react/adapter.ts';
|
|
3
|
+
interface Props {
|
|
4
|
+
rotation: number;
|
|
5
|
+
outlineOffset?: number;
|
|
6
|
+
startResize: (d: ResizeDirection) => (e: PointerEvent<HTMLDivElement>) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function ResizeHandles({ rotation, outlineOffset, startResize }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSX } from '../../react/adapter.ts';
|
|
2
|
+
import { Position, Rect } from '@embedpdf/models';
|
|
3
|
+
export interface VertexEditorProps {
|
|
4
|
+
/** Bounding box (PDF units) of the annotation */
|
|
5
|
+
rect: Rect;
|
|
6
|
+
/** Page rotation (0-3) */
|
|
7
|
+
rotation: number;
|
|
8
|
+
/** Current zoom factor */
|
|
9
|
+
scale: number;
|
|
10
|
+
/** Array of vertices in PDF units */
|
|
11
|
+
vertices: Position[];
|
|
12
|
+
/** Called *every* drag frame with new vertices */
|
|
13
|
+
onEdit: (v: Position[]) => void;
|
|
14
|
+
/** Called once at end of drag to commit changes */
|
|
15
|
+
onCommit: (v: Position[]) => void;
|
|
16
|
+
/** Size of handle in CSS px */
|
|
17
|
+
handleSize?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function VertexEditor({ rect, rotation, scale, vertices, onEdit, onCommit, handleSize, }: VertexEditorProps): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PointerEvent } from '../../react/adapter.ts';
|
|
2
|
+
import { PdfAnnotationObject, Position, Rect } from '@embedpdf/models';
|
|
3
|
+
import { TrackedAnnotation } from '../../lib/index.ts';
|
|
4
|
+
import { ResizeDirection } from '../types';
|
|
5
|
+
import { ComputePatch } from '../patchers';
|
|
6
|
+
interface UseDragResizeOpts<T extends PdfAnnotationObject> {
|
|
7
|
+
scale: number;
|
|
8
|
+
pageWidth: number;
|
|
9
|
+
pageHeight: number;
|
|
10
|
+
rotation: number;
|
|
11
|
+
tracked: TrackedAnnotation<T>;
|
|
12
|
+
isSelected: boolean;
|
|
13
|
+
isDraggable: boolean;
|
|
14
|
+
isResizable: boolean;
|
|
15
|
+
computePatch?: ComputePatch<T>;
|
|
16
|
+
computeVertices?: (a: T) => Position[];
|
|
17
|
+
currentRect: Rect;
|
|
18
|
+
setCurrentRect: (r: Rect) => void;
|
|
19
|
+
setCurrentVertices: (v: Position[]) => void;
|
|
20
|
+
setPreviewObject: (p: Partial<T> | null) => void;
|
|
21
|
+
commit: (patch: Partial<T>) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare function useDragResize<T extends PdfAnnotationObject>({ scale, pageWidth, pageHeight, rotation, tracked, isSelected, isDraggable, isResizable, computePatch, computeVertices, currentRect, setCurrentRect, setCurrentVertices, setPreviewObject, commit, }: UseDragResizeOpts<T>): {
|
|
24
|
+
rootHandlers: {
|
|
25
|
+
onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
|
|
26
|
+
onPointerMove: (e: PointerEvent<HTMLDivElement>) => void;
|
|
27
|
+
onPointerUp: () => void;
|
|
28
|
+
};
|
|
29
|
+
startResize: (direction: ResizeDirection) => (e: PointerEvent<HTMLDivElement>) => void;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PdfInkAnnoObject } from '@embedpdf/models';
|
|
2
|
+
import { ComputePatch } from './patchers';
|
|
3
3
|
/**
|
|
4
4
|
* Computes a patch for resizing an ink annotation.
|
|
5
5
|
* - Scales all points in inkList to fit the new rect.
|
|
@@ -13,5 +13,4 @@ import { ResizeDirection } from './types';
|
|
|
13
13
|
* @param uniform If true, constrains to uniform scaling (uses min scale factor).
|
|
14
14
|
* @returns Partial patch { rect, inkList, strokeWidth } to apply.
|
|
15
15
|
*/
|
|
16
|
-
export declare
|
|
17
|
-
newRect: Rect, direction: ResizeDirection, uniform?: boolean): Partial<PdfInkAnnoObject>;
|
|
16
|
+
export declare const patchInk: ComputePatch<PdfInkAnnoObject>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PdfAnnotationObject, Rect, Position } from '@embedpdf/models';
|
|
2
|
+
import { ResizeDirection } from './types';
|
|
3
|
+
export interface PatchContext {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
vertices?: Position[];
|
|
6
|
+
direction?: ResizeDirection;
|
|
7
|
+
uniform?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type ComputePatch<T extends PdfAnnotationObject> = (original: T, ctx: PatchContext) => Partial<T>;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Rect } from '@embedpdf/models';
|
|
2
|
+
import { TrackedAnnotation } from '../lib/index.ts';
|
|
3
|
+
import { JSX } from '../react/adapter.ts';
|
|
4
|
+
import { MenuWrapperProps } from './components/counter-rotate-container';
|
|
1
5
|
export type ResizeDirection = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'none';
|
|
6
|
+
export interface SelectionMenuProps {
|
|
7
|
+
annotation: TrackedAnnotation;
|
|
8
|
+
selected: boolean;
|
|
9
|
+
rect: Rect;
|
|
10
|
+
menuWrapperProps: MenuWrapperProps;
|
|
11
|
+
}
|
|
12
|
+
export type SelectionMenu = (props: SelectionMenuProps) => JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PdfAnnotationSubtype, PdfAnnotationObject, PdfLineAnnoObject, PdfPolylineAnnoObject, PdfPolygonAnnoObject, Rect, Position } from '@embedpdf/models';
|
|
2
|
+
export interface PatchContext {
|
|
3
|
+
rect: Rect;
|
|
4
|
+
vertices?: Position[];
|
|
5
|
+
}
|
|
6
|
+
export type PatchFn<T extends PdfAnnotationObject> = (original: T, ctx: PatchContext) => Partial<T>;
|
|
7
|
+
export declare const patchLine: PatchFn<PdfLineAnnoObject>;
|
|
8
|
+
export declare const patchPolyline: PatchFn<PdfPolylineAnnoObject>;
|
|
9
|
+
export declare const patchPolygon: PatchFn<PdfPolygonAnnoObject>;
|
|
10
|
+
export declare function getPatchFn(type: PdfAnnotationSubtype): PatchFn<PdfLineAnnoObject> | PatchFn<PdfPolylineAnnoObject> | PatchFn<PdfPolygonAnnoObject> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-annotation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,24 +18,24 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@embedpdf/models": "1.0.
|
|
21
|
+
"@embedpdf/models": "1.0.14"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/react": "^18.2.0",
|
|
25
25
|
"typescript": "^5.0.0",
|
|
26
|
+
"@embedpdf/plugin-selection": "1.0.14",
|
|
26
27
|
"@embedpdf/build": "1.0.0",
|
|
27
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
28
|
-
"@embedpdf/plugin-
|
|
29
|
-
"@embedpdf/plugin-history": "1.0.12"
|
|
28
|
+
"@embedpdf/plugin-interaction-manager": "1.0.14",
|
|
29
|
+
"@embedpdf/plugin-history": "1.0.14"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">=16.8.0",
|
|
33
33
|
"react-dom": ">=16.8.0",
|
|
34
34
|
"preact": "^10.26.4",
|
|
35
|
-
"@embedpdf/core": "1.0.
|
|
36
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
37
|
-
"@embedpdf/plugin-selection": "1.0.
|
|
38
|
-
"@embedpdf/plugin-history": "1.0.
|
|
35
|
+
"@embedpdf/core": "1.0.14",
|
|
36
|
+
"@embedpdf/plugin-interaction-manager": "1.0.14",
|
|
37
|
+
"@embedpdf/plugin-selection": "1.0.14",
|
|
38
|
+
"@embedpdf/plugin-history": "1.0.14"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"dist",
|