@embedpdf/plugin-annotation 2.3.0 → 2.4.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.
Files changed (70) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +40 -13
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +2 -1
  6. package/dist/lib/annotation-plugin.d.ts +1 -0
  7. package/dist/lib/helpers.d.ts +2 -1
  8. package/dist/lib/tools/types.d.ts +22 -10
  9. package/dist/lib/types.d.ts +13 -0
  10. package/dist/preact/index.cjs +1 -1
  11. package/dist/preact/index.cjs.map +1 -1
  12. package/dist/preact/index.js +326 -50
  13. package/dist/preact/index.js.map +1 -1
  14. package/dist/react/index.cjs +1 -1
  15. package/dist/react/index.cjs.map +1 -1
  16. package/dist/react/index.js +325 -49
  17. package/dist/react/index.js.map +1 -1
  18. package/dist/shared/components/annotation-container.d.ts +6 -2
  19. package/dist/shared/components/annotation-layer.d.ts +4 -2
  20. package/dist/shared/components/annotations.d.ts +3 -1
  21. package/dist/shared/components/types.d.ts +43 -1
  22. package/dist/shared/context/index.d.ts +1 -0
  23. package/dist/shared/context/renderer-registry.d.ts +21 -0
  24. package/dist/shared/index.d.ts +2 -0
  25. package/dist/shared-preact/components/annotation-container.d.ts +6 -2
  26. package/dist/shared-preact/components/annotation-layer.d.ts +4 -2
  27. package/dist/shared-preact/components/annotations.d.ts +3 -1
  28. package/dist/shared-preact/components/types.d.ts +43 -1
  29. package/dist/shared-preact/context/index.d.ts +1 -0
  30. package/dist/shared-preact/context/renderer-registry.d.ts +21 -0
  31. package/dist/shared-preact/index.d.ts +2 -0
  32. package/dist/shared-react/components/annotation-container.d.ts +6 -2
  33. package/dist/shared-react/components/annotation-layer.d.ts +4 -2
  34. package/dist/shared-react/components/annotations.d.ts +3 -1
  35. package/dist/shared-react/components/types.d.ts +43 -1
  36. package/dist/shared-react/context/index.d.ts +1 -0
  37. package/dist/shared-react/context/renderer-registry.d.ts +21 -0
  38. package/dist/shared-react/index.d.ts +2 -0
  39. package/dist/svelte/components/AnnotationLayer.svelte.d.ts +3 -0
  40. package/dist/svelte/components/Annotations.svelte.d.ts +3 -0
  41. package/dist/svelte/components/RendererRegistryProvider.svelte.d.ts +7 -0
  42. package/dist/svelte/components/index.d.ts +1 -0
  43. package/dist/svelte/context/index.d.ts +2 -0
  44. package/dist/svelte/context/renderer-registry.svelte.d.ts +20 -0
  45. package/dist/svelte/context/types.d.ts +33 -0
  46. package/dist/svelte/index.cjs +1 -1
  47. package/dist/svelte/index.cjs.map +1 -1
  48. package/dist/svelte/index.d.ts +2 -0
  49. package/dist/svelte/index.js +412 -241
  50. package/dist/svelte/index.js.map +1 -1
  51. package/dist/vue/components/annotation-container.vue.d.ts +1 -1
  52. package/dist/vue/components/annotation-layer.vue.d.ts +3 -0
  53. package/dist/vue/components/annotations/free-text.vue.d.ts +1 -1
  54. package/dist/vue/components/annotations/stamp.vue.d.ts +1 -1
  55. package/dist/vue/components/annotations.vue.d.ts +94 -60
  56. package/dist/vue/components/group-selection-box.vue.d.ts +1 -1
  57. package/dist/vue/components/index.d.ts +1 -0
  58. package/dist/vue/components/preview-renderer.vue.d.ts +1 -1
  59. package/dist/vue/components/renderer-registry-provider.vue.d.ts +13 -0
  60. package/dist/vue/context/index.d.ts +2 -0
  61. package/dist/vue/context/renderer-registry.d.ts +26 -0
  62. package/dist/vue/context/types.d.ts +33 -0
  63. package/dist/vue/hooks/use-annotation.d.ts +5 -5
  64. package/dist/vue/index.cjs +1 -1
  65. package/dist/vue/index.cjs.map +1 -1
  66. package/dist/vue/index.d.ts +3 -1
  67. package/dist/vue/index.js +245 -120
  68. package/dist/vue/index.js.map +1 -1
  69. package/dist/vue/types.d.ts +1 -1
  70. package/package.json +10 -10
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../index.ts';
3
3
  import { JSX, CSSProperties } from '../../react/adapter.ts';
4
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI } from './types';
4
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
5
5
  import { VertexConfig } from '../types';
6
6
  interface AnnotationContainerProps<T extends PdfAnnotationObject> {
7
7
  scale: number;
@@ -29,11 +29,15 @@ interface AnnotationContainerProps<T extends PdfAnnotationObject> {
29
29
  vertexUI?: VertexHandleUI;
30
30
  selectionOutlineColor?: string;
31
31
  customAnnotationRenderer?: CustomAnnotationRenderer<T>;
32
+ /** Passed from parent but not used - destructured to prevent DOM spread */
33
+ groupSelectionMenu?: GroupSelectionMenuRenderFn;
34
+ /** Passed from parent but not used - destructured to prevent DOM spread */
35
+ annotationRenderers?: BoxedAnnotationRenderer[];
32
36
  }
33
37
  /**
34
38
  * AnnotationContainer wraps individual annotations with interaction handles.
35
39
  * When isMultiSelected is true, the container becomes passive - drag/resize
36
40
  * is handled by the GroupSelectionBox instead.
37
41
  */
38
- export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationContainerProps<T>): JSX.Element;
42
+ export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, groupSelectionMenu: _groupSelectionMenu, annotationRenderers: _annotationRenderers, ...props }: AnnotationContainerProps<T>): JSX.Element;
39
43
  export {};
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
2
- import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn } from './types';
2
+ import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
3
3
  import { PdfAnnotationObject } from '@embedpdf/models';
4
4
  type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
5
5
  /** The ID of the document that this layer displays annotations for */
@@ -20,6 +20,8 @@ type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
20
20
  selectionOutlineColor?: string;
21
21
  /** Customize annotation renderer */
22
22
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
23
+ /** Custom renderers for specific annotation types (provided by external plugins) */
24
+ annotationRenderers?: BoxedAnnotationRenderer[];
23
25
  };
24
- export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationLayerProps): import("react/jsx-runtime").JSX.Element;
26
+ export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, annotationRenderers, ...props }: AnnotationLayerProps): import("react/jsx-runtime").JSX.Element;
25
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI } from './types';
2
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI, BoxedAnnotationRenderer } from './types';
3
3
  interface AnnotationsProps {
4
4
  documentId: string;
5
5
  pageIndex: number;
@@ -13,6 +13,8 @@ interface AnnotationsProps {
13
13
  vertexUI?: VertexHandleUI;
14
14
  selectionOutlineColor?: string;
15
15
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
16
+ /** Custom renderers for specific annotation types (provided by external plugins) */
17
+ annotationRenderers?: BoxedAnnotationRenderer[];
16
18
  }
17
19
  export declare function Annotations(annotationsProps: AnnotationsProps): import("react/jsx-runtime").JSX.Element;
18
20
  export {};
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../index.ts';
3
3
  import { HandleElementProps, SelectionMenuPropsBase, SelectionMenuRenderFn } from '../../react/utils.ts';
4
- import { JSX } from '../../react/adapter.ts';
4
+ import { JSX, MouseEvent, TouchEvent } from '../../react/adapter.ts';
5
5
  export type ResizeDirection = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'none';
6
6
  export interface AnnotationSelectionContext {
7
7
  type: 'annotation';
@@ -56,3 +56,45 @@ export interface CustomAnnotationRendererProps<T extends PdfAnnotationObject> {
56
56
  * Custom renderer for an annotation
57
57
  */
58
58
  export type CustomAnnotationRenderer<T extends PdfAnnotationObject> = (props: CustomAnnotationRendererProps<T>) => JSX.Element | null;
59
+ /**
60
+ * Props for an annotation renderer entry
61
+ */
62
+ export interface AnnotationRendererProps<T extends PdfAnnotationObject> {
63
+ annotation: TrackedAnnotation<T>;
64
+ isSelected: boolean;
65
+ scale: number;
66
+ pageIndex: number;
67
+ onClick: (e: MouseEvent<Element> | TouchEvent<Element>) => void;
68
+ }
69
+ /**
70
+ * Entry for a custom annotation renderer that handles specific annotation types.
71
+ * This allows external plugins to provide their own rendering for annotation subtypes.
72
+ * Used at definition time for type safety.
73
+ */
74
+ export interface AnnotationRendererEntry<T extends PdfAnnotationObject = PdfAnnotationObject> {
75
+ /** Unique identifier for this renderer (usually matches tool id) */
76
+ id: string;
77
+ /** Returns true if this renderer should handle the annotation */
78
+ matches: (annotation: PdfAnnotationObject) => annotation is T;
79
+ /** The component to render the annotation */
80
+ render: (props: AnnotationRendererProps<T>) => JSX.Element;
81
+ }
82
+ /**
83
+ * Props passed to tryRender (everything except annotation which is passed separately)
84
+ */
85
+ export type BoxedRendererProps = Omit<AnnotationRendererProps<PdfAnnotationObject>, 'annotation'>;
86
+ /**
87
+ * Boxed renderer that encapsulates type safety internally.
88
+ * The generic is erased - this is what the registry actually stores.
89
+ */
90
+ export interface BoxedAnnotationRenderer {
91
+ /** Unique identifier for this renderer */
92
+ id: string;
93
+ /** Combined match + render: returns null if doesn't match, JSX.Element if it does */
94
+ tryRender: (annotation: TrackedAnnotation, props: BoxedRendererProps) => JSX.Element | null;
95
+ }
96
+ /**
97
+ * Creates a boxed renderer from a typed entry.
98
+ * Type safety is enforced at definition time, then erased for storage.
99
+ */
100
+ export declare function createRenderer<T extends PdfAnnotationObject>(entry: AnnotationRendererEntry<T>): BoxedAnnotationRenderer;
@@ -0,0 +1 @@
1
+ export * from './renderer-registry';
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from '../../react/adapter.ts';
2
+ import { BoxedAnnotationRenderer } from '../components/types';
3
+ type RegisterFn = (entries: BoxedAnnotationRenderer[]) => () => void;
4
+ export declare function AnnotationRendererProvider({ children }: {
5
+ children: ReactNode;
6
+ }): import("react/jsx-runtime").JSX.Element;
7
+ /**
8
+ * Hook to register annotation renderers. Handles all registration lifecycle internally.
9
+ * Plugin authors just call this with their renderers array.
10
+ */
11
+ export declare function useRegisterRenderers(renderers: BoxedAnnotationRenderer[]): void;
12
+ /**
13
+ * Hook to get all registered renderers (for rendering components).
14
+ */
15
+ export declare function useRegisteredRenderers(): BoxedAnnotationRenderer[];
16
+ /**
17
+ * Low-level hook if someone needs direct access to register function.
18
+ * Most plugins should use useRegisterRenderers instead.
19
+ */
20
+ export declare function useRendererRegistry(): RegisterFn | null;
21
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from './hooks';
2
2
  export * from './components';
3
3
  export * from './components/types';
4
+ export * from './context';
4
5
  export * from '../index.ts';
6
+ export declare const AnnotationPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../index.ts').AnnotationPlugin, import('../index.ts').AnnotationPluginConfig, import('../index.ts').AnnotationState, import('../lib/actions').AnnotationAction>>;
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../lib/index.ts';
3
3
  import { JSX, CSSProperties } from '../../preact/adapter.ts';
4
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI } from './types';
4
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
5
5
  import { VertexConfig } from '../types';
6
6
  interface AnnotationContainerProps<T extends PdfAnnotationObject> {
7
7
  scale: number;
@@ -29,11 +29,15 @@ interface AnnotationContainerProps<T extends PdfAnnotationObject> {
29
29
  vertexUI?: VertexHandleUI;
30
30
  selectionOutlineColor?: string;
31
31
  customAnnotationRenderer?: CustomAnnotationRenderer<T>;
32
+ /** Passed from parent but not used - destructured to prevent DOM spread */
33
+ groupSelectionMenu?: GroupSelectionMenuRenderFn;
34
+ /** Passed from parent but not used - destructured to prevent DOM spread */
35
+ annotationRenderers?: BoxedAnnotationRenderer[];
32
36
  }
33
37
  /**
34
38
  * AnnotationContainer wraps individual annotations with interaction handles.
35
39
  * When isMultiSelected is true, the container becomes passive - drag/resize
36
40
  * is handled by the GroupSelectionBox instead.
37
41
  */
38
- export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationContainerProps<T>): JSX.Element;
42
+ export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, groupSelectionMenu: _groupSelectionMenu, annotationRenderers: _annotationRenderers, ...props }: AnnotationContainerProps<T>): JSX.Element;
39
43
  export {};
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributes, CSSProperties } from '../../preact/adapter.ts';
2
- import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn } from './types';
2
+ import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
3
3
  import { PdfAnnotationObject } from '@embedpdf/models';
4
4
  type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
5
5
  /** The ID of the document that this layer displays annotations for */
@@ -20,6 +20,8 @@ type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
20
20
  selectionOutlineColor?: string;
21
21
  /** Customize annotation renderer */
22
22
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
23
+ /** Custom renderers for specific annotation types (provided by external plugins) */
24
+ annotationRenderers?: BoxedAnnotationRenderer[];
23
25
  };
24
- export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationLayerProps): import("preact").JSX.Element;
26
+ export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, annotationRenderers, ...props }: AnnotationLayerProps): import("preact").JSX.Element;
25
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI } from './types';
2
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI, BoxedAnnotationRenderer } from './types';
3
3
  interface AnnotationsProps {
4
4
  documentId: string;
5
5
  pageIndex: number;
@@ -13,6 +13,8 @@ interface AnnotationsProps {
13
13
  vertexUI?: VertexHandleUI;
14
14
  selectionOutlineColor?: string;
15
15
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
16
+ /** Custom renderers for specific annotation types (provided by external plugins) */
17
+ annotationRenderers?: BoxedAnnotationRenderer[];
16
18
  }
17
19
  export declare function Annotations(annotationsProps: AnnotationsProps): import("preact").JSX.Element;
18
20
  export {};
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../lib/index.ts';
3
3
  import { HandleElementProps, SelectionMenuPropsBase, SelectionMenuRenderFn } from '../../preact/utils.ts';
4
- import { JSX } from '../../preact/adapter.ts';
4
+ import { JSX, MouseEvent, TouchEvent } from '../../preact/adapter.ts';
5
5
  export type ResizeDirection = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'none';
6
6
  export interface AnnotationSelectionContext {
7
7
  type: 'annotation';
@@ -56,3 +56,45 @@ export interface CustomAnnotationRendererProps<T extends PdfAnnotationObject> {
56
56
  * Custom renderer for an annotation
57
57
  */
58
58
  export type CustomAnnotationRenderer<T extends PdfAnnotationObject> = (props: CustomAnnotationRendererProps<T>) => JSX.Element | null;
59
+ /**
60
+ * Props for an annotation renderer entry
61
+ */
62
+ export interface AnnotationRendererProps<T extends PdfAnnotationObject> {
63
+ annotation: TrackedAnnotation<T>;
64
+ isSelected: boolean;
65
+ scale: number;
66
+ pageIndex: number;
67
+ onClick: (e: MouseEvent<Element> | TouchEvent<Element>) => void;
68
+ }
69
+ /**
70
+ * Entry for a custom annotation renderer that handles specific annotation types.
71
+ * This allows external plugins to provide their own rendering for annotation subtypes.
72
+ * Used at definition time for type safety.
73
+ */
74
+ export interface AnnotationRendererEntry<T extends PdfAnnotationObject = PdfAnnotationObject> {
75
+ /** Unique identifier for this renderer (usually matches tool id) */
76
+ id: string;
77
+ /** Returns true if this renderer should handle the annotation */
78
+ matches: (annotation: PdfAnnotationObject) => annotation is T;
79
+ /** The component to render the annotation */
80
+ render: (props: AnnotationRendererProps<T>) => JSX.Element;
81
+ }
82
+ /**
83
+ * Props passed to tryRender (everything except annotation which is passed separately)
84
+ */
85
+ export type BoxedRendererProps = Omit<AnnotationRendererProps<PdfAnnotationObject>, 'annotation'>;
86
+ /**
87
+ * Boxed renderer that encapsulates type safety internally.
88
+ * The generic is erased - this is what the registry actually stores.
89
+ */
90
+ export interface BoxedAnnotationRenderer {
91
+ /** Unique identifier for this renderer */
92
+ id: string;
93
+ /** Combined match + render: returns null if doesn't match, JSX.Element if it does */
94
+ tryRender: (annotation: TrackedAnnotation, props: BoxedRendererProps) => JSX.Element | null;
95
+ }
96
+ /**
97
+ * Creates a boxed renderer from a typed entry.
98
+ * Type safety is enforced at definition time, then erased for storage.
99
+ */
100
+ export declare function createRenderer<T extends PdfAnnotationObject>(entry: AnnotationRendererEntry<T>): BoxedAnnotationRenderer;
@@ -0,0 +1 @@
1
+ export * from './renderer-registry';
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from '../../preact/adapter.ts';
2
+ import { BoxedAnnotationRenderer } from '../components/types';
3
+ type RegisterFn = (entries: BoxedAnnotationRenderer[]) => () => void;
4
+ export declare function AnnotationRendererProvider({ children }: {
5
+ children: ReactNode;
6
+ }): import("preact").JSX.Element;
7
+ /**
8
+ * Hook to register annotation renderers. Handles all registration lifecycle internally.
9
+ * Plugin authors just call this with their renderers array.
10
+ */
11
+ export declare function useRegisterRenderers(renderers: BoxedAnnotationRenderer[]): void;
12
+ /**
13
+ * Hook to get all registered renderers (for rendering components).
14
+ */
15
+ export declare function useRegisteredRenderers(): BoxedAnnotationRenderer[];
16
+ /**
17
+ * Low-level hook if someone needs direct access to register function.
18
+ * Most plugins should use useRegisterRenderers instead.
19
+ */
20
+ export declare function useRendererRegistry(): RegisterFn | null;
21
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from './hooks';
2
2
  export * from './components';
3
3
  export * from './components/types';
4
+ export * from './context';
4
5
  export * from '../lib/index.ts';
6
+ export declare const AnnotationPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').AnnotationPlugin, import('../lib/index.ts').AnnotationPluginConfig, import('../lib/index.ts').AnnotationState, import('../lib/actions').AnnotationAction>>;
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../lib/index.ts';
3
3
  import { JSX, CSSProperties } from '../../react/adapter.ts';
4
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI } from './types';
4
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, VertexHandleUI, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
5
5
  import { VertexConfig } from '../types';
6
6
  interface AnnotationContainerProps<T extends PdfAnnotationObject> {
7
7
  scale: number;
@@ -29,11 +29,15 @@ interface AnnotationContainerProps<T extends PdfAnnotationObject> {
29
29
  vertexUI?: VertexHandleUI;
30
30
  selectionOutlineColor?: string;
31
31
  customAnnotationRenderer?: CustomAnnotationRenderer<T>;
32
+ /** Passed from parent but not used - destructured to prevent DOM spread */
33
+ groupSelectionMenu?: GroupSelectionMenuRenderFn;
34
+ /** Passed from parent but not used - destructured to prevent DOM spread */
35
+ annotationRenderers?: BoxedAnnotationRenderer[];
32
36
  }
33
37
  /**
34
38
  * AnnotationContainer wraps individual annotations with interaction handles.
35
39
  * When isMultiSelected is true, the container becomes passive - drag/resize
36
40
  * is handled by the GroupSelectionBox instead.
37
41
  */
38
- export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationContainerProps<T>): JSX.Element;
42
+ export declare function AnnotationContainer<T extends PdfAnnotationObject>({ scale, documentId, pageIndex, rotation, pageWidth, pageHeight, trackedAnnotation, children, isSelected, isMultiSelected, isDraggable, isResizable, lockAspectRatio, style, vertexConfig, selectionMenu, outlineOffset, onDoubleClick, onSelect, zIndex, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, groupSelectionMenu: _groupSelectionMenu, annotationRenderers: _annotationRenderers, ...props }: AnnotationContainerProps<T>): JSX.Element;
39
43
  export {};
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
2
- import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn } from './types';
2
+ import { ResizeHandleUI, VertexHandleUI, CustomAnnotationRenderer, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, BoxedAnnotationRenderer } from './types';
3
3
  import { PdfAnnotationObject } from '@embedpdf/models';
4
4
  type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
5
5
  /** The ID of the document that this layer displays annotations for */
@@ -20,6 +20,8 @@ type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
20
20
  selectionOutlineColor?: string;
21
21
  /** Customize annotation renderer */
22
22
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
23
+ /** Custom renderers for specific annotation types (provided by external plugins) */
24
+ annotationRenderers?: BoxedAnnotationRenderer[];
23
25
  };
24
- export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, ...props }: AnnotationLayerProps): import("react/jsx-runtime").JSX.Element;
26
+ export declare function AnnotationLayer({ style, documentId, pageIndex, scale: overrideScale, rotation: overrideRotation, selectionMenu, groupSelectionMenu, resizeUI, vertexUI, selectionOutlineColor, customAnnotationRenderer, annotationRenderers, ...props }: AnnotationLayerProps): import("react/jsx-runtime").JSX.Element;
25
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
- import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI } from './types';
2
+ import { CustomAnnotationRenderer, ResizeHandleUI, AnnotationSelectionMenuRenderFn, GroupSelectionMenuRenderFn, VertexHandleUI, BoxedAnnotationRenderer } from './types';
3
3
  interface AnnotationsProps {
4
4
  documentId: string;
5
5
  pageIndex: number;
@@ -13,6 +13,8 @@ interface AnnotationsProps {
13
13
  vertexUI?: VertexHandleUI;
14
14
  selectionOutlineColor?: string;
15
15
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
16
+ /** Custom renderers for specific annotation types (provided by external plugins) */
17
+ annotationRenderers?: BoxedAnnotationRenderer[];
16
18
  }
17
19
  export declare function Annotations(annotationsProps: AnnotationsProps): import("react/jsx-runtime").JSX.Element;
18
20
  export {};
@@ -1,7 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { TrackedAnnotation } from '../../lib/index.ts';
3
3
  import { HandleElementProps, SelectionMenuPropsBase, SelectionMenuRenderFn } from '../../react/utils.ts';
4
- import { JSX } from '../../react/adapter.ts';
4
+ import { JSX, MouseEvent, TouchEvent } from '../../react/adapter.ts';
5
5
  export type ResizeDirection = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'none';
6
6
  export interface AnnotationSelectionContext {
7
7
  type: 'annotation';
@@ -56,3 +56,45 @@ export interface CustomAnnotationRendererProps<T extends PdfAnnotationObject> {
56
56
  * Custom renderer for an annotation
57
57
  */
58
58
  export type CustomAnnotationRenderer<T extends PdfAnnotationObject> = (props: CustomAnnotationRendererProps<T>) => JSX.Element | null;
59
+ /**
60
+ * Props for an annotation renderer entry
61
+ */
62
+ export interface AnnotationRendererProps<T extends PdfAnnotationObject> {
63
+ annotation: TrackedAnnotation<T>;
64
+ isSelected: boolean;
65
+ scale: number;
66
+ pageIndex: number;
67
+ onClick: (e: MouseEvent<Element> | TouchEvent<Element>) => void;
68
+ }
69
+ /**
70
+ * Entry for a custom annotation renderer that handles specific annotation types.
71
+ * This allows external plugins to provide their own rendering for annotation subtypes.
72
+ * Used at definition time for type safety.
73
+ */
74
+ export interface AnnotationRendererEntry<T extends PdfAnnotationObject = PdfAnnotationObject> {
75
+ /** Unique identifier for this renderer (usually matches tool id) */
76
+ id: string;
77
+ /** Returns true if this renderer should handle the annotation */
78
+ matches: (annotation: PdfAnnotationObject) => annotation is T;
79
+ /** The component to render the annotation */
80
+ render: (props: AnnotationRendererProps<T>) => JSX.Element;
81
+ }
82
+ /**
83
+ * Props passed to tryRender (everything except annotation which is passed separately)
84
+ */
85
+ export type BoxedRendererProps = Omit<AnnotationRendererProps<PdfAnnotationObject>, 'annotation'>;
86
+ /**
87
+ * Boxed renderer that encapsulates type safety internally.
88
+ * The generic is erased - this is what the registry actually stores.
89
+ */
90
+ export interface BoxedAnnotationRenderer {
91
+ /** Unique identifier for this renderer */
92
+ id: string;
93
+ /** Combined match + render: returns null if doesn't match, JSX.Element if it does */
94
+ tryRender: (annotation: TrackedAnnotation, props: BoxedRendererProps) => JSX.Element | null;
95
+ }
96
+ /**
97
+ * Creates a boxed renderer from a typed entry.
98
+ * Type safety is enforced at definition time, then erased for storage.
99
+ */
100
+ export declare function createRenderer<T extends PdfAnnotationObject>(entry: AnnotationRendererEntry<T>): BoxedAnnotationRenderer;
@@ -0,0 +1 @@
1
+ export * from './renderer-registry';
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from '../../react/adapter.ts';
2
+ import { BoxedAnnotationRenderer } from '../components/types';
3
+ type RegisterFn = (entries: BoxedAnnotationRenderer[]) => () => void;
4
+ export declare function AnnotationRendererProvider({ children }: {
5
+ children: ReactNode;
6
+ }): import("react/jsx-runtime").JSX.Element;
7
+ /**
8
+ * Hook to register annotation renderers. Handles all registration lifecycle internally.
9
+ * Plugin authors just call this with their renderers array.
10
+ */
11
+ export declare function useRegisterRenderers(renderers: BoxedAnnotationRenderer[]): void;
12
+ /**
13
+ * Hook to get all registered renderers (for rendering components).
14
+ */
15
+ export declare function useRegisteredRenderers(): BoxedAnnotationRenderer[];
16
+ /**
17
+ * Low-level hook if someone needs direct access to register function.
18
+ * Most plugins should use useRegisterRenderers instead.
19
+ */
20
+ export declare function useRendererRegistry(): RegisterFn | null;
21
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from './hooks';
2
2
  export * from './components';
3
3
  export * from './components/types';
4
+ export * from './context';
4
5
  export * from '../lib/index.ts';
6
+ export declare const AnnotationPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').AnnotationPlugin, import('../lib/index.ts').AnnotationPluginConfig, import('../lib/index.ts').AnnotationState, import('../lib/actions').AnnotationAction>>;
@@ -1,6 +1,7 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
2
  import { HTMLAttributes } from 'svelte/elements';
3
3
  import { AnnotationSelectionMenuProps, AnnotationSelectionMenuRenderFn, GroupSelectionMenuProps, GroupSelectionMenuRenderFn, CustomAnnotationRenderer, ResizeHandleUI, VertexHandleUI } from '../types';
4
+ import { BoxedAnnotationRenderer } from '../context';
4
5
  import { Snippet } from 'svelte';
5
6
  type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
6
7
  /** The ID of the document that this layer displays annotations for */
@@ -25,6 +26,8 @@ type AnnotationLayerProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
25
26
  selectionOutlineColor?: string;
26
27
  /** Customize annotation renderer */
27
28
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
29
+ /** Custom annotation renderers from props */
30
+ annotationRenderers?: BoxedAnnotationRenderer[];
28
31
  };
29
32
  declare const AnnotationLayer: import('svelte', { with: { "resolution-mode": "import" } }).Component<AnnotationLayerProps, {}, "">;
30
33
  type AnnotationLayer = ReturnType<typeof AnnotationLayer>;
@@ -1,4 +1,5 @@
1
1
  import { PdfAnnotationObject } from '@embedpdf/models';
2
+ import { BoxedAnnotationRenderer } from '../context';
2
3
  import { AnnotationSelectionMenuProps, AnnotationSelectionMenuRenderFn, GroupSelectionMenuProps, GroupSelectionMenuRenderFn, CustomAnnotationRenderer, ResizeHandleUI, VertexHandleUI } from '../types';
3
4
  import { Snippet } from 'svelte';
4
5
  interface AnnotationsProps {
@@ -20,6 +21,8 @@ interface AnnotationsProps {
20
21
  vertexUI?: VertexHandleUI;
21
22
  selectionOutlineColor?: string;
22
23
  customAnnotationRenderer?: CustomAnnotationRenderer<PdfAnnotationObject>;
24
+ /** Custom annotation renderers from registry/props */
25
+ annotationRenderers?: BoxedAnnotationRenderer[];
23
26
  }
24
27
  declare const Annotations: import('svelte', { with: { "resolution-mode": "import" } }).Component<AnnotationsProps, {}, "">;
25
28
  type Annotations = ReturnType<typeof Annotations>;
@@ -0,0 +1,7 @@
1
+ import { Snippet } from 'svelte';
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ };
5
+ declare const RendererRegistryProvider: import('svelte', { with: { "resolution-mode": "import" } }).Component<$$ComponentProps, {}, "">;
6
+ type RendererRegistryProvider = ReturnType<typeof RendererRegistryProvider>;
7
+ export default RendererRegistryProvider;
@@ -5,6 +5,7 @@ export { default as Annotations } from './Annotations.svelte';
5
5
  export { default as GroupSelectionBox } from './GroupSelectionBox.svelte';
6
6
  export { default as PreviewRenderer } from './PreviewRenderer.svelte';
7
7
  export { default as RenderAnnotation } from './RenderAnnotation.svelte';
8
+ export { default as RendererRegistryProvider } from './RendererRegistryProvider.svelte';
8
9
  export { default as TextMarkup } from './TextMarkup.svelte';
9
10
  export * from './annotations';
10
11
  export * from './text-markup';
@@ -0,0 +1,2 @@
1
+ export * from './renderer-registry.svelte';
2
+ export * from './types';
@@ -0,0 +1,20 @@
1
+ import { BoxedAnnotationRenderer, AnnotationRendererEntry, AnnotationRendererProps } from './types';
2
+ import { PdfAnnotationObject } from '@embedpdf/models';
3
+ /**
4
+ * Annotation Renderer Registry
5
+ *
6
+ * Allows external plugins to register custom annotation renderers
7
+ * that integrate with the annotation layer.
8
+ */
9
+ export interface AnnotationRendererRegistry {
10
+ register(entries: BoxedAnnotationRenderer[]): () => void;
11
+ getAll(): BoxedAnnotationRenderer[];
12
+ }
13
+ export declare function createRendererRegistry(): AnnotationRendererRegistry;
14
+ export declare function provideRendererRegistry(): AnnotationRendererRegistry;
15
+ export declare function getRendererRegistry(): AnnotationRendererRegistry | null;
16
+ /**
17
+ * Factory to create a boxed renderer from a typed entry.
18
+ */
19
+ export declare function createRenderer<T extends PdfAnnotationObject>(entry: AnnotationRendererEntry<T>): BoxedAnnotationRenderer;
20
+ export type { AnnotationRendererProps, AnnotationRendererEntry, BoxedAnnotationRenderer };
@@ -0,0 +1,33 @@
1
+ import { Component } from 'svelte';
2
+ import { PdfAnnotationObject } from '@embedpdf/models';
3
+ import { TrackedAnnotation } from '../../lib';
4
+ /**
5
+ * Props passed to custom annotation renderer components
6
+ */
7
+ export interface AnnotationRendererProps<T extends PdfAnnotationObject = PdfAnnotationObject> {
8
+ annotation: TrackedAnnotation<T>;
9
+ isSelected: boolean;
10
+ scale: number;
11
+ pageIndex: number;
12
+ onClick: (e: PointerEvent | TouchEvent) => void;
13
+ }
14
+ /**
15
+ * Entry for defining a custom annotation renderer.
16
+ * Type safety enforced at definition time via generic.
17
+ */
18
+ export interface AnnotationRendererEntry<T extends PdfAnnotationObject = PdfAnnotationObject> {
19
+ /** Unique identifier for this renderer */
20
+ id: string;
21
+ /** Returns true if this renderer handles the annotation */
22
+ matches: (annotation: PdfAnnotationObject) => annotation is T;
23
+ /** Svelte component to render the annotation */
24
+ component: Component<AnnotationRendererProps<T>>;
25
+ }
26
+ /**
27
+ * Boxed renderer stored in registry (generic erased for storage)
28
+ */
29
+ export interface BoxedAnnotationRenderer {
30
+ id: string;
31
+ matches: (annotation: PdfAnnotationObject) => boolean;
32
+ component: Component<AnnotationRendererProps>;
33
+ }