@embedpdf/plugin-annotation 1.0.11 → 1.0.13

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.
Files changed (109) hide show
  1. package/dist/index.cjs +2 -693
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -266
  4. package/dist/index.js +509 -164
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +104 -0
  7. package/dist/lib/annotation-plugin.d.ts +34 -0
  8. package/dist/lib/helpers.d.ts +18 -0
  9. package/dist/lib/index.d.ts +12 -0
  10. package/dist/lib/manifest.d.ts +4 -0
  11. package/dist/lib/patching/derived-rect.d.ts +2 -0
  12. package/dist/lib/patching/index.d.ts +4 -0
  13. package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
  14. package/dist/lib/patching/line-endings.d.ts +13 -0
  15. package/dist/lib/patching/patch-utils.d.ts +7 -0
  16. package/dist/lib/reducer.d.ts +5 -0
  17. package/dist/lib/selectors.d.ts +25 -0
  18. package/dist/lib/types.d.ts +168 -0
  19. package/dist/lib/utils.d.ts +11 -0
  20. package/dist/lib/variant-key.d.ts +8 -0
  21. package/dist/preact/adapter.d.ts +8 -0
  22. package/dist/preact/core.d.ts +1 -0
  23. package/dist/preact/index.cjs +2 -1038
  24. package/dist/preact/index.cjs.map +1 -1
  25. package/dist/preact/index.d.ts +1 -28
  26. package/dist/preact/index.js +2150 -539
  27. package/dist/preact/index.js.map +1 -1
  28. package/dist/preact/interaction-manager.d.ts +1 -0
  29. package/dist/preact/selection.d.ts +1 -0
  30. package/dist/react/adapter.d.ts +2 -0
  31. package/dist/react/core.d.ts +1 -0
  32. package/dist/react/index.cjs +2 -0
  33. package/dist/react/index.cjs.map +1 -0
  34. package/dist/react/index.d.ts +1 -0
  35. package/dist/react/index.js +2624 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/react/interaction-manager.d.ts +1 -0
  38. package/dist/react/selection.d.ts +1 -0
  39. package/dist/shared-preact/components/annotation-container.d.ts +24 -0
  40. package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
  41. package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
  42. package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
  43. package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
  44. package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
  45. package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
  46. package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
  47. package/dist/shared-preact/components/annotations/line.d.ts +33 -0
  48. package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
  49. package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
  50. package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
  51. package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
  52. package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
  53. package/dist/shared-preact/components/annotations/square.d.ts +29 -0
  54. package/dist/shared-preact/components/annotations.d.ts +11 -0
  55. package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
  56. package/dist/shared-preact/components/index.d.ts +1 -0
  57. package/dist/shared-preact/components/render-annotation.d.ts +11 -0
  58. package/dist/shared-preact/components/resize-handles.d.ts +9 -0
  59. package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
  60. package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
  61. package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
  62. package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
  63. package/dist/shared-preact/components/text-markup.d.ts +6 -0
  64. package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
  65. package/dist/shared-preact/hooks/index.d.ts +1 -0
  66. package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
  67. package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
  68. package/dist/shared-preact/index.d.ts +2 -0
  69. package/dist/shared-preact/patch-ink.d.ts +16 -0
  70. package/dist/shared-preact/patchers.d.ts +9 -0
  71. package/dist/shared-preact/types.d.ts +12 -0
  72. package/dist/shared-preact/vertex-patchers.d.ts +10 -0
  73. package/dist/shared-react/components/annotation-container.d.ts +24 -0
  74. package/dist/shared-react/components/annotation-layer.d.ts +13 -0
  75. package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
  76. package/dist/shared-react/components/annotations/circle.d.ts +29 -0
  77. package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
  78. package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
  79. package/dist/shared-react/components/annotations/ink.d.ts +25 -0
  80. package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
  81. package/dist/shared-react/components/annotations/line.d.ts +33 -0
  82. package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
  83. package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
  84. package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
  85. package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
  86. package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
  87. package/dist/shared-react/components/annotations/square.d.ts +29 -0
  88. package/dist/shared-react/components/annotations.d.ts +11 -0
  89. package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
  90. package/dist/shared-react/components/index.d.ts +1 -0
  91. package/dist/shared-react/components/render-annotation.d.ts +11 -0
  92. package/dist/shared-react/components/resize-handles.d.ts +9 -0
  93. package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
  94. package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
  95. package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
  96. package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
  97. package/dist/shared-react/components/text-markup.d.ts +6 -0
  98. package/dist/shared-react/components/vertex-editor.d.ts +19 -0
  99. package/dist/shared-react/hooks/index.d.ts +1 -0
  100. package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
  101. package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
  102. package/dist/shared-react/index.d.ts +2 -0
  103. package/dist/shared-react/patch-ink.d.ts +16 -0
  104. package/dist/shared-react/patchers.d.ts +9 -0
  105. package/dist/shared-react/types.d.ts +12 -0
  106. package/dist/shared-react/vertex-patchers.d.ts +10 -0
  107. package/package.json +17 -15
  108. package/dist/index.d.cts +0 -266
  109. package/dist/preact/index.d.cts +0 -28
@@ -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 {};
@@ -0,0 +1,11 @@
1
+ import { SelectionMenu } from '../types';
2
+ interface AnnotationsProps {
3
+ pageIndex: number;
4
+ scale: number;
5
+ rotation: number;
6
+ pageWidth: number;
7
+ pageHeight: number;
8
+ selectionMenu?: SelectionMenu;
9
+ }
10
+ export declare function Annotations(annotationsProps: AnnotationsProps): import("react/jsx-runtime").JSX.Element;
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 @@
1
+ export * from './annotation-layer';
@@ -0,0 +1,11 @@
1
+ import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
2
+ import { PdfAnnotationObject } from '@embedpdf/models';
3
+ type RenderAnnotationProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {
4
+ pageIndex: number;
5
+ annotation: PdfAnnotationObject;
6
+ scaleFactor?: number;
7
+ dpr?: number;
8
+ style?: CSSProperties;
9
+ };
10
+ export declare function RenderAnnotation({ pageIndex, annotation, scaleFactor, dpr, style, ...props }: RenderAnnotationProps): import("react/jsx-runtime").JSX.Element;
11
+ 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,13 @@
1
+ import { HTMLAttributes, CSSProperties, MouseEvent } from '../../../react/adapter.ts';
2
+ import { Rect } from '@embedpdf/models';
3
+ type HighlightProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
4
+ color?: string;
5
+ opacity?: number;
6
+ rects: Rect[];
7
+ rect?: Rect;
8
+ scale: number;
9
+ onClick?: (e: MouseEvent<HTMLDivElement>) => void;
10
+ style?: CSSProperties;
11
+ };
12
+ export declare function Highlight({ color, opacity, rects, rect, scale, onClick, style, ...props }: HighlightProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { HTMLAttributes, CSSProperties, MouseEvent } from '../../../react/adapter.ts';
2
+ import { Rect } from '@embedpdf/models';
3
+ type SquigglyProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
4
+ color?: string;
5
+ opacity?: number;
6
+ rects: Rect[];
7
+ rect?: Rect;
8
+ scale: number;
9
+ onClick?: (e: MouseEvent<HTMLDivElement>) => void;
10
+ style?: CSSProperties;
11
+ };
12
+ export declare function Squiggly({ color, opacity, rects, rect, scale, onClick, style, ...props }: SquigglyProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { HTMLAttributes, CSSProperties, MouseEvent } from '../../../react/adapter.ts';
2
+ import { Rect } from '@embedpdf/models';
3
+ type StrikeoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
4
+ color?: string;
5
+ opacity?: number;
6
+ rects: Rect[];
7
+ rect?: Rect;
8
+ scale: number;
9
+ onClick?: (e: MouseEvent<HTMLDivElement>) => void;
10
+ style?: CSSProperties;
11
+ };
12
+ export declare function Strikeout({ color, opacity, rects, rect, scale, onClick, style, ...props }: StrikeoutProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { HTMLAttributes, CSSProperties, MouseEvent } from '../../../react/adapter.ts';
2
+ import { Rect } from '@embedpdf/models';
3
+ type UnderlineProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
4
+ color?: string;
5
+ opacity?: number;
6
+ rects: Rect[];
7
+ rect?: Rect;
8
+ scale: number;
9
+ onClick?: (e: MouseEvent<HTMLDivElement>) => void;
10
+ style?: CSSProperties;
11
+ };
12
+ export declare function Underline({ color, opacity, rects, rect, scale, onClick, style, ...props }: UnderlineProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,6 @@
1
+ interface TextMarkupProps {
2
+ pageIndex: number;
3
+ scale: number;
4
+ }
5
+ export declare function TextMarkup({ pageIndex, scale }: TextMarkupProps): import("react/jsx-runtime").JSX.Element | null;
6
+ 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 @@
1
+ export * from './use-annotation';
@@ -0,0 +1,11 @@
1
+ import { AnnotationPlugin } from '../../lib/index.ts';
2
+ export declare const useAnnotationPlugin: () => {
3
+ plugin: AnnotationPlugin | null;
4
+ isLoading: boolean;
5
+ ready: Promise<void>;
6
+ };
7
+ export declare const useAnnotationCapability: () => {
8
+ provides: Readonly<import('../../lib/index.ts').AnnotationCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
@@ -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 {};
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from './components';
@@ -0,0 +1,16 @@
1
+ import { PdfInkAnnoObject } from '@embedpdf/models';
2
+ import { ComputePatch } from './patchers';
3
+ /**
4
+ * Computes a patch for resizing an ink annotation.
5
+ * - Scales all points in inkList to fit the new rect.
6
+ * - Scales strokeWidth proportionally (using average scale factor).
7
+ * - Handles non-uniform scaling (stretch).
8
+ * - Optionally preserves aspect ratio (set uniform=true).
9
+ *
10
+ * @param original The original ink annotation object.
11
+ * @param newRect The new bounding rect after resize.
12
+ * @param direction The resize handle direction (affects origin adjustments if needed).
13
+ * @param uniform If true, constrains to uniform scaling (uses min scale factor).
14
+ * @returns Partial patch { rect, inkList, strokeWidth } to apply.
15
+ */
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>;
@@ -0,0 +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';
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.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -18,23 +18,24 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@embedpdf/models": "1.0.11"
21
+ "@embedpdf/models": "1.0.13"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/react": "^18.2.0",
25
- "tsup": "^8.0.0",
26
25
  "typescript": "^5.0.0",
27
- "@embedpdf/plugin-interaction-manager": "1.0.11",
28
- "@embedpdf/plugin-selection": "1.0.11",
29
- "@embedpdf/plugin-history": "1.0.11"
26
+ "@embedpdf/plugin-selection": "1.0.13",
27
+ "@embedpdf/plugin-interaction-manager": "1.0.13",
28
+ "@embedpdf/build": "1.0.0",
29
+ "@embedpdf/plugin-history": "1.0.13"
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.11",
36
- "@embedpdf/plugin-selection": "1.0.11",
37
- "@embedpdf/plugin-interaction-manager": "1.0.11"
35
+ "@embedpdf/core": "1.0.13",
36
+ "@embedpdf/plugin-history": "1.0.13",
37
+ "@embedpdf/plugin-interaction-manager": "1.0.13",
38
+ "@embedpdf/plugin-selection": "1.0.13"
38
39
  },
39
40
  "files": [
40
41
  "dist",
@@ -53,11 +54,12 @@
53
54
  "access": "public"
54
55
  },
55
56
  "scripts": {
56
- "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
57
- "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
58
- "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
59
- "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
60
- "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
61
- "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
57
+ "build:base": "vite build --mode base",
58
+ "build:react": "vite build --mode react",
59
+ "build:preact": "vite build --mode preact",
60
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\"",
61
+ "clean": "rimraf dist",
62
+ "lint": "eslint src --color",
63
+ "lint:fix": "eslint src --color --fix"
62
64
  }
63
65
  }
package/dist/index.d.cts DELETED
@@ -1,266 +0,0 @@
1
- import { BasePluginConfig, EventHook, Action, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
2
- import { PdfAnnotationSubtype, WebAlphaColor, Task, PdfAnnotationObject, PdfErrorReason, Rotation, AppearanceMode, ImageConversionTypes, PdfEngine } from '@embedpdf/models';
3
-
4
- type CommitState = 'new' | 'dirty' | 'deleted' | 'synced' | 'ignored';
5
- interface TrackedAnnotation {
6
- /** A stable, client-side unique identifier for history and state management. */
7
- localId: number;
8
- /**
9
- * If the engine has already created the annotation in the PDF
10
- * this is the definitive id coming from the engine.
11
- * It is **never** cleared once set.
12
- */
13
- pdfId?: number;
14
- /** local commit bookkeeping */
15
- commitState: CommitState;
16
- /** the actual annotation object */
17
- object: PdfAnnotationObject;
18
- }
19
- interface RenderAnnotationOptions {
20
- pageIndex: number;
21
- annotation: PdfAnnotationObject;
22
- scaleFactor?: number;
23
- rotation?: Rotation;
24
- dpr?: number;
25
- mode?: AppearanceMode;
26
- imageType?: ImageConversionTypes;
27
- }
28
- interface BaseAnnotationDefaults extends WebAlphaColor {
29
- interaction: {
30
- mode: string;
31
- exclusive: boolean;
32
- cursor?: string;
33
- };
34
- textSelection?: boolean;
35
- }
36
- interface HighlightDefaults extends BaseAnnotationDefaults {
37
- name: 'Highlight';
38
- }
39
- interface UnderlineDefaults extends BaseAnnotationDefaults {
40
- name: 'Underline';
41
- }
42
- interface StrikeoutDefaults extends BaseAnnotationDefaults {
43
- name: 'Strikeout';
44
- }
45
- interface SquigglyDefaults extends BaseAnnotationDefaults {
46
- name: 'Squiggly';
47
- }
48
- interface InkDefaults extends BaseAnnotationDefaults {
49
- name: 'Ink';
50
- strokeWidth: number;
51
- }
52
- type AnnotationDefaults = HighlightDefaults | UnderlineDefaults | StrikeoutDefaults | SquigglyDefaults | InkDefaults;
53
- type ToolDefaultsBySubtype = {
54
- [PdfAnnotationSubtype.HIGHLIGHT]: HighlightDefaults;
55
- [PdfAnnotationSubtype.UNDERLINE]: UnderlineDefaults;
56
- [PdfAnnotationSubtype.STRIKEOUT]: StrikeoutDefaults;
57
- [PdfAnnotationSubtype.SQUIGGLY]: SquigglyDefaults;
58
- [PdfAnnotationSubtype.INK]: InkDefaults;
59
- };
60
- type StylableSubtype = keyof ToolDefaultsBySubtype;
61
- type ToolDefaults<S extends PdfAnnotationSubtype> = ToolDefaultsBySubtype[Extract<S, keyof ToolDefaultsBySubtype>];
62
- type ActiveTool = {
63
- mode: null;
64
- defaults: null;
65
- } | {
66
- [K in StylableSubtype]: {
67
- mode: K;
68
- defaults: ToolDefaultsBySubtype[K];
69
- };
70
- }[StylableSubtype];
71
- interface AnnotationState {
72
- pages: Record<number, string[]>;
73
- byUid: Record<string, TrackedAnnotation>;
74
- selectedUid: string | null;
75
- annotationMode: StylableSubtype | null;
76
- toolDefaults: ToolDefaultsBySubtype;
77
- colorPresets: string[];
78
- hasPendingChanges: boolean;
79
- }
80
- interface AnnotationPluginConfig extends BasePluginConfig {
81
- toolDefaults?: Partial<ToolDefaultsBySubtype>;
82
- colorPresets?: string[];
83
- /**
84
- * When `false` mutations are kept in memory and must be
85
- * flushed with `commitPendingChanges()`.
86
- */
87
- autoCommit?: boolean;
88
- }
89
- interface AnnotationCapability {
90
- getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
91
- getSelectedAnnotation: () => TrackedAnnotation | null;
92
- selectAnnotation: (pageIndex: number, annotationId: number) => void;
93
- deselectAnnotation: () => void;
94
- getAnnotationMode: () => StylableSubtype | null;
95
- setAnnotationMode: (mode: StylableSubtype | null) => void;
96
- /** strongly typed – only sub-types we have defaults for */
97
- getToolDefaults: <S extends StylableSubtype>(subtype: S) => ToolDefaultsBySubtype[S];
98
- /** Partially patch a single tool’s defaults */
99
- setToolDefaults: <S extends StylableSubtype>(subtype: S, patch: Partial<ToolDefaultsBySubtype[S]>) => void;
100
- /** current palette – UI just reads this */
101
- getColorPresets: () => string[];
102
- /** append a swatch (deduped by RGBA) */
103
- addColorPreset: (color: string) => void;
104
- createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) => void;
105
- updateAnnotation: (pageIndex: number, annotationId: number, patch: Partial<PdfAnnotationObject>) => void;
106
- deleteAnnotation: (pageIndex: number, annotationId: number) => void;
107
- renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
108
- /** undo / redo */
109
- onStateChange: EventHook<AnnotationState>;
110
- onModeChange: EventHook<StylableSubtype | null>;
111
- onActiveToolChange: EventHook<ActiveTool>;
112
- commit: () => void;
113
- }
114
- interface SelectedAnnotation {
115
- pageIndex: number;
116
- localId: number;
117
- annotation: PdfAnnotationObject;
118
- }
119
- interface GetPageAnnotationsOptions {
120
- pageIndex: number;
121
- }
122
- interface UpdateAnnotationColorOptions extends WebAlphaColor {
123
- pageIndex: number;
124
- annotationId: number;
125
- }
126
-
127
- declare const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
128
- declare const REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
129
- declare const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
130
- declare const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
131
- declare const SET_ANNOTATION_MODE = "ANNOTATION/SET_ANNOTATION_MODE";
132
- declare const UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
133
- declare const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
134
- declare const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
135
- declare const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
136
- declare const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
137
- declare const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
138
- declare const STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
139
- declare const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
140
- interface SetAnnotationsAction extends Action {
141
- type: typeof SET_ANNOTATIONS;
142
- payload: Record<number, PdfAnnotationObject[]>;
143
- }
144
- interface ReindexPageAnnotationsAction extends Action {
145
- type: typeof REINDEX_PAGE_ANNOTATIONS;
146
- payload: {
147
- pageIndex: number;
148
- };
149
- }
150
- interface SelectAnnotationAction extends Action {
151
- type: typeof SELECT_ANNOTATION;
152
- payload: {
153
- pageIndex: number;
154
- localId: number;
155
- };
156
- }
157
- interface DeselectAnnotationAction extends Action {
158
- type: typeof DESELECT_ANNOTATION;
159
- }
160
- interface SetAnnotationModeAction extends Action {
161
- type: typeof SET_ANNOTATION_MODE;
162
- payload: StylableSubtype | null;
163
- }
164
- interface UpdateToolDefaultsAction extends Action {
165
- type: typeof UPDATE_TOOL_DEFAULTS;
166
- payload: {
167
- subtype: StylableSubtype;
168
- patch: Partial<ToolDefaultsBySubtype[StylableSubtype]>;
169
- };
170
- }
171
- interface AddColorPresetAction extends Action {
172
- type: typeof ADD_COLOR_PRESET;
173
- payload: string;
174
- }
175
- interface CreateAnnotationAction extends Action {
176
- type: typeof CREATE_ANNOTATION;
177
- payload: {
178
- pageIndex: number;
179
- localId: number;
180
- annotation: PdfAnnotationObject;
181
- };
182
- }
183
- interface PatchAnnotationAction extends Action {
184
- type: typeof PATCH_ANNOTATION;
185
- payload: {
186
- pageIndex: number;
187
- localId: number;
188
- patch: Partial<PdfAnnotationObject>;
189
- };
190
- }
191
- interface DeleteAnnotationAction extends Action {
192
- type: typeof DELETE_ANNOTATION;
193
- payload: {
194
- pageIndex: number;
195
- localId: number;
196
- };
197
- }
198
- interface CommitAction extends Action {
199
- type: typeof COMMIT_PENDING_CHANGES;
200
- }
201
- interface StorePdfIdAction extends Action {
202
- type: typeof STORE_PDF_ID;
203
- payload: {
204
- uid: string;
205
- pdfId: number;
206
- };
207
- }
208
- interface PurgeAnnotationAction extends Action {
209
- type: typeof PURGE_ANNOTATION;
210
- payload: {
211
- uid: string;
212
- };
213
- }
214
- type AnnotationAction = SetAnnotationsAction | ReindexPageAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | SetAnnotationModeAction | UpdateToolDefaultsAction | AddColorPresetAction | CreateAnnotationAction | PatchAnnotationAction | DeleteAnnotationAction | CommitAction | StorePdfIdAction | PurgeAnnotationAction;
215
-
216
- declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig, AnnotationCapability, AnnotationState, AnnotationAction> {
217
- static readonly id: "annotation";
218
- private readonly ANNOTATION_HISTORY_TOPIC;
219
- private readonly config;
220
- private engine;
221
- private readonly state$;
222
- private readonly interactionManager;
223
- private readonly selection;
224
- private readonly history;
225
- /** Map <subtype> → <modeId>. Filled once in `initialize()`. */
226
- private readonly modeBySubtype;
227
- /** The inverse map for quick lookup in onModeChange(). */
228
- private readonly subtypeByMode;
229
- private readonly modeChange$;
230
- private readonly activeTool$;
231
- constructor(id: string, registry: PluginRegistry, engine: PdfEngine, config: AnnotationPluginConfig);
232
- initialize(): Promise<void>;
233
- private registerTool;
234
- protected buildCapability(): AnnotationCapability;
235
- private createActiveTool;
236
- private emitActiveTool;
237
- onStoreUpdated(prev: AnnotationState, next: AnnotationState): void;
238
- private getAllAnnotations;
239
- private getPageAnnotations;
240
- private renderAnnotation;
241
- private selectAnnotation;
242
- private createAnnotation;
243
- private updateAnnotation;
244
- private deleteAnnotation;
245
- private commit;
246
- }
247
-
248
- declare const ANNOTATION_PLUGIN_ID = "annotation";
249
- declare const manifest: PluginManifest<AnnotationPluginConfig>;
250
-
251
- /** All annotations _objects_ on a single page (order preserved). */
252
- declare const getAnnotationsByPageIndex: (s: AnnotationState, page: number) => TrackedAnnotation[];
253
- /** Shortcut: every page → list of annotation objects. */
254
- declare const getAnnotations: (s: AnnotationState) => Record<number, TrackedAnnotation[]>;
255
- /** The full `TrackedAnnotation` for the current selection. */
256
- declare const getSelectedAnnotation: (s: AnnotationState) => TrackedAnnotation | null;
257
- declare const getSelectedAnnotationWithPageIndex: (s: AnnotationState) => SelectedAnnotation | null;
258
- declare const getSelectedAnnotationByPageIndex: (s: AnnotationState, pageIndex: number) => TrackedAnnotation | null;
259
- declare const isInAnnotationMode: (s: AnnotationState) => boolean;
260
- declare const getSelectedAnnotationMode: (s: AnnotationState) => keyof ToolDefaultsBySubtype | null;
261
- /** Check if a given anno on a page is the current selection. */
262
- declare const isAnnotationSelected: (s: AnnotationState, page: number, id: number) => boolean;
263
-
264
- declare const AnnotationPluginPackage: PluginPackage<AnnotationPlugin, AnnotationPluginConfig, AnnotationState, AnnotationAction>;
265
-
266
- export { ANNOTATION_PLUGIN_ID, type ActiveTool, type AnnotationCapability, type AnnotationDefaults, AnnotationPlugin, type AnnotationPluginConfig, AnnotationPluginPackage, type AnnotationState, type BaseAnnotationDefaults, type CommitState, type GetPageAnnotationsOptions, type HighlightDefaults, type InkDefaults, type RenderAnnotationOptions, type SelectedAnnotation, type SquigglyDefaults, type StrikeoutDefaults, type StylableSubtype, type ToolDefaults, type ToolDefaultsBySubtype, type TrackedAnnotation, type UnderlineDefaults, type UpdateAnnotationColorOptions, getAnnotations, getAnnotationsByPageIndex, getSelectedAnnotation, getSelectedAnnotationByPageIndex, getSelectedAnnotationMode, getSelectedAnnotationWithPageIndex, isAnnotationSelected, isInAnnotationMode, manifest };