@embedpdf/plugin-annotation 2.3.0 → 2.4.1

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
@@ -121,6 +121,7 @@ export interface PurgeAnnotationAction extends Action {
121
121
  type: typeof PURGE_ANNOTATION;
122
122
  payload: {
123
123
  documentId: string;
124
+ pageIndex: number;
124
125
  uid: string;
125
126
  };
126
127
  }
@@ -154,7 +155,7 @@ export declare const createAnnotation: (documentId: string, pageIndex: number, a
154
155
  export declare const patchAnnotation: (documentId: string, pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
155
156
  export declare const deleteAnnotation: (documentId: string, pageIndex: number, id: string) => DeleteAnnotationAction;
156
157
  export declare const commitPendingChanges: (documentId: string, committedUids: string[]) => CommitAction;
157
- export declare const purgeAnnotation: (documentId: string, uid: string) => PurgeAnnotationAction;
158
+ export declare const purgeAnnotation: (documentId: string, pageIndex: number, uid: string) => PurgeAnnotationAction;
158
159
  export declare const addColorPreset: (c: string) => AddColorPresetAction;
159
160
  export declare const setToolDefaults: (toolId: string, patch: Partial<any>) => SetToolDefaultsAction;
160
161
  export declare const addTool: (tool: AnnotationTool) => AddToolAction;
@@ -56,6 +56,7 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
56
56
  private updateAnnotation;
57
57
  private deleteAnnotation;
58
58
  private deleteAnnotationsMethod;
59
+ private purgeAnnotationMethod;
59
60
  private selectAnnotation;
60
61
  private deselectAnnotation;
61
62
  private getSelectedAnnotationsMethod;
@@ -8,7 +8,7 @@ export type AnnoOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject
8
8
  type: S;
9
9
  }>;
10
10
  export type TextMarkupSubtype = PdfAnnotationSubtype.HIGHLIGHT | PdfAnnotationSubtype.UNDERLINE | PdfAnnotationSubtype.STRIKEOUT | PdfAnnotationSubtype.SQUIGGLY;
11
- export type SidebarSubtype = TextMarkupSubtype | PdfAnnotationSubtype.INK | PdfAnnotationSubtype.SQUARE | PdfAnnotationSubtype.CIRCLE | PdfAnnotationSubtype.POLYGON | PdfAnnotationSubtype.LINE | PdfAnnotationSubtype.POLYLINE | PdfAnnotationSubtype.FREETEXT | PdfAnnotationSubtype.STAMP;
11
+ export type SidebarSubtype = TextMarkupSubtype | PdfAnnotationSubtype.INK | PdfAnnotationSubtype.SQUARE | PdfAnnotationSubtype.CIRCLE | PdfAnnotationSubtype.POLYGON | PdfAnnotationSubtype.LINE | PdfAnnotationSubtype.POLYLINE | PdfAnnotationSubtype.FREETEXT | PdfAnnotationSubtype.STAMP | PdfAnnotationSubtype.REDACT;
12
12
  /** True when `a.object.type === INK` – and narrows the generic. */
13
13
  export declare function isInk(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.INK>>;
14
14
  /** Example for Circle – create similar ones for Square, Line, etc. */
@@ -26,4 +26,5 @@ export declare function isFreeText(a: TrackedAnnotation): a is TrackedAnnotation
26
26
  export declare function isStamp(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.STAMP>>;
27
27
  export declare function isText(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.TEXT>>;
28
28
  export declare function isLink(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.LINK>>;
29
+ export declare function isRedact(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.REDACT>>;
29
30
  export declare function isSidebarAnnotation(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<SidebarSubtype>>;
@@ -1,4 +1,16 @@
1
1
  import { PdfAnnotationObject, PdfAnnotationSubtype, Size } from '@embedpdf/models';
2
+ /**
3
+ * A dynamic boolean property that can be either a static boolean
4
+ * or a function that receives the annotation and returns a boolean.
5
+ */
6
+ export type DynamicBooleanProp = boolean | ((annotation: PdfAnnotationObject) => boolean);
7
+ /**
8
+ * Resolves a dynamic boolean property to its actual value.
9
+ * @param prop The dynamic property (boolean or function)
10
+ * @param annotation The annotation to pass to the function if prop is a function
11
+ * @param defaultValue The default value if prop is undefined
12
+ */
13
+ export declare function resolveInteractionProp(prop: DynamicBooleanProp | undefined, annotation: PdfAnnotationObject, defaultValue: boolean): boolean;
2
14
  /**
3
15
  * Specific configuration for Stamp tools.
4
16
  */
@@ -84,16 +96,16 @@ export type AnnotationTool<T extends PdfAnnotationObject = PdfAnnotationObject>
84
96
  cursor?: string;
85
97
  /** If true, this interaction mode is activated by selecting text. */
86
98
  textSelection?: boolean;
87
- /** Whether this annotation can be dragged when selected individually. */
88
- isDraggable?: boolean;
89
- /** Whether this annotation can be resized when selected individually. */
90
- isResizable?: boolean;
91
- /** Whether to maintain aspect ratio during resize. */
92
- lockAspectRatio?: boolean;
93
- /** Whether this annotation can be dragged when part of a group. Defaults to isDraggable. */
94
- isGroupDraggable?: boolean;
95
- /** Whether this annotation can be resized when part of a group. Defaults to isResizable. */
96
- isGroupResizable?: boolean;
99
+ /** Whether this annotation can be dragged when selected individually. Can be dynamic based on annotation. */
100
+ isDraggable?: DynamicBooleanProp;
101
+ /** Whether this annotation can be resized when selected individually. Can be dynamic based on annotation. */
102
+ isResizable?: DynamicBooleanProp;
103
+ /** Whether to maintain aspect ratio during resize. Can be dynamic based on annotation. */
104
+ lockAspectRatio?: DynamicBooleanProp;
105
+ /** Whether this annotation can be dragged when part of a group. Defaults to isDraggable. Can be dynamic based on annotation. */
106
+ isGroupDraggable?: DynamicBooleanProp;
107
+ /** Whether this annotation can be resized when part of a group. Defaults to isResizable. Can be dynamic based on annotation. */
108
+ isGroupResizable?: DynamicBooleanProp;
97
109
  };
98
110
  /** Tool-specific behavior settings that override plugin defaults */
99
111
  behavior?: {
@@ -1,6 +1,15 @@
1
1
  import { BasePluginConfig, EventHook } from '@embedpdf/core';
2
2
  import { AnnotationCreateContext, PdfAnnotationObject, PdfAnnotationSubtype, PdfErrorReason, PdfRenderPageAnnotationOptions, PdfTextAnnoObject, Position, Rect, Size, Task } from '@embedpdf/models';
3
3
  import { AnnotationTool } from './tools/types';
4
+ /**
5
+ * Metadata attached to annotation history commands for filtering/purging.
6
+ * Used by the history plugin's purgeByMetadata method to identify commands
7
+ * that should be removed (e.g., after a permanent redaction commit).
8
+ */
9
+ export interface AnnotationCommandMetadata {
10
+ /** The annotation IDs affected by this command */
11
+ annotationIds: string[];
12
+ }
4
13
  export type AnnotationEvent = {
5
14
  type: 'create';
6
15
  documentId: string;
@@ -176,6 +185,8 @@ export interface AnnotationScope {
176
185
  pageIndex: number;
177
186
  id: string;
178
187
  }>): void;
188
+ /** Remove an annotation from state without calling the engine (no PDF modification) */
189
+ purgeAnnotation(pageIndex: number, annotationId: string): void;
179
190
  renderAnnotation(options: RenderAnnotationOptions): Task<Blob, PdfErrorReason>;
180
191
  commit(): Task<boolean, PdfErrorReason>;
181
192
  /** Get link annotations attached to an annotation via IRT relationship */
@@ -235,6 +246,8 @@ export interface AnnotationCapability {
235
246
  pageIndex: number;
236
247
  id: string;
237
248
  }>, documentId?: string) => void;
249
+ /** Remove an annotation from state without calling the engine (no PDF modification) */
250
+ purgeAnnotation: (pageIndex: number, annotationId: string, documentId?: string) => void;
238
251
  renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
239
252
  commit: () => Task<boolean, PdfErrorReason>;
240
253
  /** Get link annotations attached to an annotation via IRT relationship */
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact"),o=require("preact/hooks"),i=require("preact/jsx-runtime"),r=require("@embedpdf/models"),s=require("@embedpdf/plugin-interaction-manager/preact"),l=require("@embedpdf/plugin-selection/preact"),a=require("@embedpdf/utils/preact"),c={},d=()=>e.usePlugin(t.AnnotationPlugin.id),u=()=>e.useCapability(t.AnnotationPlugin.id);function g({scale:t,documentId:n,pageIndex:r,rotation:s,pageWidth:l,pageHeight:c,trackedAnnotation:g,children:h,isSelected:p,isMultiSelected:x=!1,isDraggable:f,isResizable:v,lockAspectRatio:b=!1,style:y={},vertexConfig:m,selectionMenu:j,outlineOffset:k=1,onDoubleClick:S,onSelect:M,zIndex:z=1,resizeUI:A,vertexUI:w,selectionOutlineColor:C="#007ACC",customAnnotationRenderer:D,...R}){const[I,P]=o.useState(g.object),{provides:E}=u(),{plugin:B}=d(),{canModifyAnnotations:T}=e.useDocumentPermissions(n),$=o.useRef(null),L=T&&f&&!x,F=T&&v&&!x,U=o.useMemo(()=>E?E.forDocument(n):null,[E,n]),O=I?{...g.object,...I}:g.object,W=(null==A?void 0:A.color)??"#007ACC",H=(null==w?void 0:w.color)??"#007ACC",N=(null==A?void 0:A.size)??12,q=(null==w?void 0:w.size)??12,V=o.useRef(null),G=o.useCallback(e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type)||x||!B)return;const{type:o,changes:i,metadata:s}=e.transformData,a=g.object.id,d={width:l,height:c};if("start"===e.state&&(V.current=g.object.rect,$.current=g.object,"move"===o?B.startDrag(n,{annotationIds:[a],pageSize:d}):"resize"===o&&B.startResize(n,{annotationIds:[a],pageSize:d,resizeHandle:(null==s?void 0:s.handle)??"se"})),i.rect&&V.current)if("move"===o){const e={x:i.rect.origin.x-V.current.origin.x,y:i.rect.origin.y-V.current.origin.y};B.updateDrag(n,e)}else"resize"===o&&B.updateResize(n,i.rect);if("vertex-edit"===o&&i.vertices&&m){const t=$.current??g.object,n=m.transformAnnotation(t,i.vertices),l=null==E?void 0:E.transformAnnotation(t,{type:o,changes:n,metadata:s});l&&(P(e=>({...e,...l})),"end"===e.state&&(null==U||U.updateAnnotation(r,a,l)))}"end"===e.state&&(V.current=null,$.current=null,"move"===o?B.commitDrag(n):"resize"===o&&B.commitResize(n))},[B,n,g.object,l,c,r,x,m,E,U]),{dragProps:K,vertices:Y,resize:Q}=a.useInteractionHandles({controller:{element:O.rect,vertices:null==m?void 0:m.extractVertices(O),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:c}},maintainAspectRatio:b,pageRotation:s,scale:t,enabled:p&&!x,onUpdate:G},resizeUI:{handleSize:N,spacing:k,offsetMode:"outside",includeSides:!b,zIndex:z+1},vertexUI:{vertexSize:q,zIndex:z+2},includeVertices:!!m}),X=o.useMemo(()=>{if(T&&S)return S},[T,S]),Z=a.useDoublePressProps(X);o.useEffect(()=>{P(g.object)},[g.object]),o.useEffect(()=>{if(!B)return;const e=g.object.id,t=t=>{var o;if(t.documentId!==n)return;const i=null==(o=t.previewPatches)?void 0:o[e];"update"===t.type&&i?P(e=>({...e,...i})):"cancel"===t.type&&P(g.object)},o=[B.onDragChange(t),B.onResizeChange(t)];return()=>o.forEach(e=>e())},[B,n,g.object]);const J=p&&!x;return i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...L&&p?K:{},...Z,style:{position:"absolute",left:O.rect.origin.x*t,top:O.rect.origin.y*t,width:O.rect.size.width*t,height:O.rect.size.height*t,outline:J?`1px solid ${C}`:"none",outlineOffset:J?`${k}px`:"0px",pointerEvents:p&&!x?"auto":"none",touchAction:"none",cursor:p&&L?"move":"default",zIndex:z,...y},...R,children:[(()=>{const e="function"==typeof h?h(O):h,n=null==D?void 0:D({annotation:O,children:e,isSelected:p,scale:t,rotation:s,pageWidth:l,pageHeight:c,pageIndex:r,onSelect:M});return null!=n?n:e})(),p&&F&&Q.map(({key:e,...t})=>(null==A?void 0:A.component)?A.component({key:e,...t,backgroundColor:W}):i.jsx("div",{...t,style:{...t.style,backgroundColor:W}},e)),p&&T&&!x&&Y.map(({key:e,...t})=>(null==w?void 0:w.component)?w.component({key:e,...t,backgroundColor:H}):i.jsx("div",{...t,style:{...t.style,backgroundColor:H}},e))]}),j&&!x&&i.jsx(a.CounterRotate,{rect:{origin:{x:O.rect.origin.x*t,y:O.rect.origin.y*t},size:{width:O.rect.size.width*t,height:O.rect.size.height*t}},rotation:s,children:e=>j({...e,context:{type:"annotation",annotation:g,pageIndex:r},selected:p,placement:{suggestTop:!1}})})]})}function h({documentId:e,pageIndex:t,scale:n,rotation:s,pageWidth:l,pageHeight:c,selectedAnnotations:u,isDraggable:g,isResizable:h,resizeUI:p,selectionOutlineColor:x="#007ACC",outlineOffset:f=2,zIndex:v=100,groupSelectionMenu:b}){const{plugin:y}=d(),m=o.useRef(null),j=o.useRef(!1),k=o.useRef(!1),S=o.useMemo(()=>{const e=u.map(e=>e.object.rect);return r.boundingRectOrEmpty(e)},[u]),[M,z]=o.useState(S);o.useEffect(()=>{j.current||k.current||z(S)},[S]);const A=o.useCallback(t=>{var n,o;if(!(null==(n=t.transformData)?void 0:n.type))return;if(!y)return;const i=t.transformData.type,r="move"===i,s="resize"===i;if(r&&!g)return;"start"===t.state&&(m.current=S,r?(j.current=!0,y.startDrag(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:l,height:c}})):s&&(k.current=!0,y.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:l,height:c},resizeHandle:(null==(o=t.transformData.metadata)?void 0:o.handle)??"se"})));const a=m.current??S;if(r&&t.transformData.changes.rect){const n=t.transformData.changes.rect,o={x:n.origin.x-a.origin.x,y:n.origin.y-a.origin.y},i=y.updateDrag(e,o);z({...a,origin:{x:a.origin.x+i.x,y:a.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const n=t.transformData.changes.rect;y.updateResize(e,n),z(n)}"end"===t.state&&(m.current=null,r&&j.current?(j.current=!1,y.commitDrag(e)):s&&k.current&&(k.current=!1,y.commitResize(e)))},[y,e,l,c,S,g,u]),w=(null==p?void 0:p.color)??"#007ACC",C=(null==p?void 0:p.size)??12,{dragProps:D,resize:R}=a.useInteractionHandles({controller:{element:M,constraints:{minWidth:20,minHeight:20,boundingBox:{width:l,height:c}},maintainAspectRatio:!1,pageRotation:s,scale:n,enabled:!0,onUpdate:A},resizeUI:{handleSize:C,spacing:f,offsetMode:"outside",includeSides:!0,zIndex:v+1},vertexUI:{vertexSize:0,zIndex:v},includeVertices:!1});return u.length<2?null:i.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[i.jsx("div",{...g?D:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:M.origin.x*n,top:M.origin.y*n,width:M.size.width*n,height:M.size.height*n,outline:`2px dashed ${x}`,outlineOffset:f-1,cursor:g?"move":"default",touchAction:"none",zIndex:v},children:h&&R.map(({key:e,...t})=>(null==p?void 0:p.component)?p.component({key:e,...t,backgroundColor:w}):i.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),b&&i.jsx(a.CounterRotate,{rect:{origin:{x:M.origin.x*n,y:M.origin.y*n},size:{width:M.size.width*n,height:M.size.height*n}},rotation:s,children:e=>b({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function p({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:a,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l}},n))})}function x({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:a,opacity:t,pointerEvents:"none"}})},n))})}function f({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:a,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},n))})}function v({strokeColor:e,opacity:t=.5,segmentRects:n,rect:o,scale:r,onClick:s,style:l}){const a=2*r,c=6*r,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e??"#FFFF00"}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*r,top:(o?e.origin.y-o.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n))})}function b({isSelected:e,strokeColor:t,opacity:n=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=o.useMemo(()=>s.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-l.origin.x,r=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "}),t.trim()}),[s,l]),g=l.size.width*a,h=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:g,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:g,height:h,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:u.map((t,o)=>i.jsx("path",{d:t,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},o))})}function y({isSelected:e,color:t="#000000",strokeColor:n,opacity:s=1,strokeWidth:l,strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:h,height:p,x:x,y:f}=o.useMemo(()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}},[d,l]),v=(h+l)*u,b=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2},width:v,height:b,viewBox:`0 0 ${h+l} ${p+l}`,children:i.jsx("rect",{x:x,y:f,width:h,height:p,fill:t,opacity:s,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function m({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:s,strokeStyle:l=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:g}){const{width:h,height:p,cx:x,cy:f,rx:v,ry:b}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}},[c,s]),y=h*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:y,height:m,pointerEvents:"none",zIndex:2},width:y,height:m,viewBox:`0 0 ${h} ${p}`,children:i.jsx("ellipse",{cx:x,cy:f,rx:v,ry:b,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...l===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function j({color:e="transparent",opacity:n=1,strokeWidth:s,strokeColor:l="#000000",strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:g,scale:h,onClick:p,isSelected:x}){const{x1:f,y1:v,x2:b,y2:y}=o.useMemo(()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y}),[u,d]),m=o.useMemo(()=>{const e=Math.atan2(y-v,b-f);return{start:t.patching.createEnding(null==g?void 0:g.start,s,e+Math.PI,f,v),end:t.patching.createEnding(null==g?void 0:g.end,s,e,b,y)}},[g,s,f,v,b,y]),j=d.size.width*h,k=d.size.height*h;return i.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[i.jsx("line",{x1:f,y1:v,x2:b,y2:y,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:s,strokeLinecap:"butt",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&i.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&i.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function k({rect:e,vertices:n,color:r="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const h=o.useMemo(()=>n.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[n,e]),p=o.useMemo(()=>{if(!h.length)return"";const[e,...t]=h;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[h]),x=o.useMemo(()=>{if(h.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(h[0],h[1]),o=e(h[h.length-2],h[h.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,h[0].x,h[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,h[h.length-1].x,h[h.length-1].y)}},[h,g,a]),f=e.size.width*c,v=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2,overflow:"visible"},width:f,height:v,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:s??r,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&i.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:s,fill:x.start.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&i.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:s,fill:x.end.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function S({rect:e,vertices:t,color:n="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:h,currentVertex:p,handleSize:x=14}){const f=p?[...t,p]:t,v=o.useMemo(()=>f.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[f,e]),b=o.useMemo(()=>{if(!v.length)return"";const[e,...t]=v,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[v,p]),y=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return i.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:b,onPointerDown:h,onTouchStart:h,opacity:l,style:{fill:p?"none":n,stroke:s??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),y&&t.length>1&&i.jsx("path",{d:`M ${v[v.length-1].x} ${v[v.length-1].y} L ${v[0].x} ${v[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),y&&t.length>=2&&i.jsx("rect",{x:v[0].x-x/u/2,y:v[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function M({isSelected:e,isEditing:t,annotation:n,pageIndex:s,scale:l,onClick:a}){const d=o.useRef(null),{provides:g}=u(),[h,p]=o.useState(!1);o.useEffect(()=>{if(t&&d.current){const e=d.current;e.focus();const t=window.getSelection();if(t){const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}},[t]),o.useLayoutEffect(()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}},[]);const x=n.object.fontSize*l,f=h&&t&&x>0&&x<16,v=f?16:x,b=f?x/16:1,y=f?100/b:100;return i.jsx("div",{style:{position:"absolute",width:n.object.rect.size.width*l,height:n.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:i.jsx("span",{ref:d,onBlur:()=>{g&&d.current&&g.updateAnnotation(s,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:v,fontFamily:r.standardFontCss(n.object.fontFamily),textAlign:r.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===r.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===r.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.color??n.object.backgroundColor,opacity:n.object.opacity,width:f?`${y}%`:"100%",height:f?`${y}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:f?`scale(${b})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function z({documentId:e,pageIndex:t,annotation:s,scaleFactor:l=1,style:a,...c}){const{provides:d}=u(),[g,h]=o.useState(null),p=o.useRef(null),{width:x,height:f}=s.rect.size;o.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:s,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);h(t),p.current=t},r.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:r.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,s.id,x,f]);return i.jsx(n.Fragment,{children:g&&i.jsx("img",{src:g,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function A({isSelected:e,annotation:t,documentId:n,pageIndex:o,scale:r,onClick:s}){return i.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:i.jsx(z,{documentId:n,pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function w({isSelected:e,strokeColor:t="#0000FF",strokeWidth:n=2,strokeStyle:s=r.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:h}=o.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),p=g*c,x=h*c,f=o.useMemo(()=>{if(s===r.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*n},${n}`},[s,l,n]),v=s===r.PdfAnnotationBorderStyle.UNDERLINE;return i.jsxs("svg",{style:{position:"absolute",width:p,height:x,pointerEvents:"none",zIndex:2},width:p,height:x,viewBox:`0 0 ${g} ${h}`,children:[i.jsx("rect",{x:0,y:0,width:g,height:h,fill:"transparent",onPointerDown:u?void 0:d,onTouchStart:u?void 0:d,style:{cursor:u?"default":e?"move":"pointer",pointerEvents:u||e?"none":"visible"}}),v?i.jsx("line",{x1:1,y1:h-1,x2:g-1,y2:h-1,stroke:t,strokeWidth:n,strokeDasharray:f,style:{pointerEvents:"none"}}):i.jsx("rect",{x:n/2,y:n/2,width:Math.max(g-n,0),height:Math.max(h-n,0),fill:"transparent",stroke:t,strokeWidth:n,strokeDasharray:f,style:{pointerEvents:"none"}})]})}function C(e){const{documentId:a,pageIndex:c,scale:d,pageWidth:z,pageHeight:C,selectionMenu:D}=e,{provides:R}=u(),{provides:I}=l.useSelectionCapability(),[P,E]=o.useState([]),{register:B}=s.usePointerHandlers({documentId:a,pageIndex:c}),[T,$]=o.useState([]),[L,F]=o.useState(null),U=o.useMemo(()=>R?R.forDocument(a):null,[R,a]),O=T.length>1;o.useEffect(()=>{if(U){const e=U.getState();return E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e)),U.onStateChange(e=>{E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e))})}},[U,c]);const W=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&U&&(U.deselectAnnotation(),F(null))}}),[U]),H=o.useCallback((e,t)=>{if(e.stopPropagation(),U&&I){I.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?U.toggleSelection(c,t.object.id):U.selectAnnotation(c,t.object.id),t.object.id!==L&&F(null)}},[U,I,L,c]),N=o.useCallback((e,t)=>{if(e.stopPropagation(),U&&I){if(I.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,n=P.find(t=>t.object.id===e);if(n)return void U.selectAnnotation(n.object.pageIndex,e)}U.selectAnnotation(c,t.object.id)}},[U,I,P,c]);o.useEffect(()=>B(W,{documentId:a}),[B,W]);const q=o.useMemo(()=>P.filter(e=>T.includes(e.object.id)),[P,T]),V=o.useMemo(()=>!(q.length<2)&&q.every(e=>{const t=null==U?void 0:U.findToolForAnnotation(e.object);return(null==t?void 0:t.interaction.isGroupDraggable)??(null==t?void 0:t.interaction.isDraggable)??!0}),[q,U]),G=o.useMemo(()=>!(q.length<2)&&q.every(e=>{const t=null==U?void 0:U.findToolForAnnotation(e.object);return(null==t?void 0:t.interaction.isGroupResizable)??(null==t?void 0:t.interaction.isResizable)??!0}),[q,U]),K=o.useMemo(()=>{if(!U)return!1;const e=U.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===c)},[U,c,T]);return i.jsxs(i.Fragment,{children:[P.map(o=>{const s=T.includes(o.object.id),l=L===o.object.id,u=null==U?void 0:U.findToolForAnnotation(o.object);if(t.isInk(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isSquare(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isCircle(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(m,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isUnderline(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isStrikeout(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isSquiggly(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isHighlight(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),zIndex:0,style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(p,{...e,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isLine(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isPolyline(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isPolygon(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(S,{...e,isSelected:s,scale:d,onClick:e=>H(e,o)})})},o.object.id);if(t.isFreeText(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:((null==u?void 0:u.interaction.isDraggable)??!0)&&!l,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),F(o.object.id)},...e,children:e=>i.jsx(M,{isSelected:s,isEditing:l,annotation:{...o,object:e},pageIndex:c,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isStamp(o))return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:D,onSelect:e=>H(e,o),style:{mixBlendMode:r.blendModeToCss(o.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:s,annotation:o,documentId:a,pageIndex:c,scale:d,onClick:e=>H(e,o)})},o.object.id);if(t.isLink(o)){const t=!!o.object.inReplyToId;return i.jsx(g,{trackedAnnotation:o,isSelected:s,isMultiSelected:O,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:D,onSelect:e=>N(e,o),...e,children:e=>i.jsx(w,{...e,isSelected:s,scale:d,onClick:e=>N(e,o),hasIRT:t})},o.object.id)}return null}),K&&q.length>=2&&i.jsx(h,{documentId:a,pageIndex:c,scale:d,rotation:e.rotation,pageWidth:z,pageHeight:C,selectedAnnotations:q,isDraggable:V,isResizable:G,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function D({documentId:e,pageIndex:t,scale:n}){var s,a,c,d,g,h,b,y,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:z}=u(),[A,w]=o.useState([]),[C,D]=o.useState(null),[R,I]=o.useState(null);if(o.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{w(M.forDocument(e).getHighlightRectsForPage(t)),D(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),o.useEffect(()=>{if(z)return I(z.forDocument(e).getActiveTool()),z.forDocument(e).onActiveToolChange(e=>I(e))},[z,e]),!C)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case r.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(s=R.defaults)?void 0:s.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{strokeColor:null==(a=R.defaults)?void 0:a.strokeColor,opacity:null==(c=R.defaults)?void 0:c.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(d=R.defaults)?void 0:d.blendMode)??r.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{strokeColor:null==(g=R.defaults)?void 0:g.strokeColor,opacity:null==(h=R.defaults)?void 0:h.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(b=R.defaults)?void 0:b.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(f,{strokeColor:null==(y=R.defaults)?void 0:y.strokeColor,opacity:null==(m=R.defaults)?void 0:m.opacity,segmentRects:A,scale:n})});case r.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(j=R.defaults)?void 0:j.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(v,{strokeColor:null==(k=R.defaults)?void 0:k.strokeColor,opacity:null==(S=R.defaults)?void 0:S.opacity,segmentRects:A,scale:n})});default:return null}}function R({preview:e,scale:t}){const{bounds:n}=e,o={position:"absolute",left:n.origin.x*t,top:n.origin.y*t,width:n.size.width*t,height:n.size.height*t,pointerEvents:"none",zIndex:10};return e.type===r.PdfAnnotationSubtype.CIRCLE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.FREETEXT?i.jsx("div",{style:o,children:i.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function I({documentId:e,pageIndex:t,scale:n}){const{plugin:r}=d(),[s,l]=o.useState(new Map),a=o.useRef(null),c=o.useRef(null),u=o.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const n=a.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=c.current;if(!i||!i.getContext)return;const r=i.getContext("2d");if(!r)return;const s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),g=l*u,h=a*u;i.width=g,i.height=h,r.drawImage(s,0,0,g,h);const p=r.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(s.src),o({imageData:p,width:g,height:h})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,n,{services:u,onPreview:(e,t)=>{l(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,n,r,u]),i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:a,type:"file",style:{display:"none"}}),i.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(s.entries()).map(([e,t])=>i.jsx(R,{preview:t,scale:n},e))]})}exports.AnnotationLayer=function({style:t,documentId:n,pageIndex:s,scale:l,rotation:a,selectionMenu:c,groupSelectionMenu:d,resizeUI:u,vertexUI:g,selectionOutlineColor:h,customAnnotationRenderer:p,...x}){var f,v,b,y;const m=e.useDocumentState(n),j=null==(v=null==(f=null==m?void 0:m.document)?void 0:f.pages)?void 0:v[s],k=(null==(b=null==j?void 0:j.size)?void 0:b.width)??0,S=(null==(y=null==j?void 0:j.size)?void 0:y.height)??0,M=o.useMemo(()=>void 0!==l?l:(null==m?void 0:m.scale)??1,[l,null==m?void 0:m.scale]),z=o.useMemo(()=>void 0!==a?a:(null==m?void 0:m.rotation)??r.Rotation.Degree0,[a,null==m?void 0:m.rotation]);return i.jsxs("div",{style:{...t},...x,children:[i.jsx(C,{documentId:n,selectionMenu:c,groupSelectionMenu:d,pageIndex:s,scale:M,rotation:z,pageWidth:k,pageHeight:S,resizeUI:u,vertexUI:g,selectionOutlineColor:h,customAnnotationRenderer:p}),i.jsx(D,{documentId:n,pageIndex:s,scale:M}),i.jsx(I,{documentId:n,pageIndex:s,scale:M})]})},exports.GroupSelectionBox=h,exports.useAnnotation=e=>{var n;const{provides:i}=u(),[r,s]=o.useState((null==(n=null==i?void 0:i.forDocument(e))?void 0:n.getState())??t.initialDocumentState());return o.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return s(t.getState()),t.onStateChange(e=>{s(e)})},[i,e]),{state:r,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=u,exports.useAnnotationPlugin=d,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-annotation"),o=require("preact/jsx-runtime"),n=require("preact"),i=require("preact/hooks"),r=require("@embedpdf/core/preact"),s=require("@embedpdf/models"),l=require("@embedpdf/plugin-interaction-manager/preact"),a=require("@embedpdf/plugin-selection/preact"),c=require("@embedpdf/utils/preact"),d={},u=n.createContext(null),g=n.createContext([]);function p({children:e}){const[t,n]=i.useState([]),r=i.useCallback(e=>(n(t=>{const o=new Set(e.map(e=>e.id));return[...t.filter(e=>!o.has(e.id)),...e]}),()=>n(t=>t.filter(t=>!e.some(e=>e.id===t.id)))),[]);return o.jsx(u.Provider,{value:r,children:o.jsx(g.Provider,{value:t,children:e})})}function h(){return i.useContext(g)}const v=()=>r.usePlugin(t.AnnotationPlugin.id),b=()=>r.useCapability(t.AnnotationPlugin.id);function x({scale:e,documentId:t,pageIndex:n,rotation:s,pageWidth:l,pageHeight:a,trackedAnnotation:d,children:u,isSelected:g,isMultiSelected:p=!1,isDraggable:h,isResizable:x,lockAspectRatio:f=!1,style:y={},vertexConfig:m,selectionMenu:j,outlineOffset:k=1,onDoubleClick:S,onSelect:I,zIndex:M=1,resizeUI:P,vertexUI:z,selectionOutlineColor:R="#007ACC",customAnnotationRenderer:A,groupSelectionMenu:C,annotationRenderers:w,...D}){const[E,B]=i.useState(d.object),{provides:T}=b(),{plugin:$}=v(),{canModifyAnnotations:L}=r.useDocumentPermissions(t),F=i.useRef(null),U=L&&h&&!p,W=L&&x&&!p,O=i.useMemo(()=>T?T.forDocument(t):null,[T,t]),H=E?{...d.object,...E}:d.object,N=(null==P?void 0:P.color)??"#007ACC",q=(null==z?void 0:z.color)??"#007ACC",G=(null==P?void 0:P.size)??12,V=(null==z?void 0:z.size)??12,K=i.useRef(null),Y=i.useCallback(e=>{var o;if(!(null==(o=e.transformData)?void 0:o.type)||p||!$)return;const{type:i,changes:r,metadata:s}=e.transformData,c=d.object.id,u={width:l,height:a};if("start"===e.state&&(K.current=d.object.rect,F.current=d.object,"move"===i?$.startDrag(t,{annotationIds:[c],pageSize:u}):"resize"===i&&$.startResize(t,{annotationIds:[c],pageSize:u,resizeHandle:(null==s?void 0:s.handle)??"se"})),r.rect&&K.current)if("move"===i){const e={x:r.rect.origin.x-K.current.origin.x,y:r.rect.origin.y-K.current.origin.y};$.updateDrag(t,e)}else"resize"===i&&$.updateResize(t,r.rect);if("vertex-edit"===i&&r.vertices&&m){const t=F.current??d.object,o=m.transformAnnotation(t,r.vertices),l=null==T?void 0:T.transformAnnotation(t,{type:i,changes:o,metadata:s});l&&(B(e=>({...e,...l})),"end"===e.state&&(null==O||O.updateAnnotation(n,c,l)))}"end"===e.state&&(K.current=null,F.current=null,"move"===i?$.commitDrag(t):"resize"===i&&$.commitResize(t))},[$,t,d.object,l,a,n,p,m,T,O]),{dragProps:Q,vertices:X,resize:Z}=c.useInteractionHandles({controller:{element:H.rect,vertices:null==m?void 0:m.extractVertices(H),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:a}},maintainAspectRatio:f,pageRotation:s,scale:e,enabled:g&&!p,onUpdate:Y},resizeUI:{handleSize:G,spacing:k,offsetMode:"outside",includeSides:!f,zIndex:M+1},vertexUI:{vertexSize:V,zIndex:M+2},includeVertices:!!m}),J=i.useMemo(()=>{if(L&&S)return S},[L,S]),_=c.useDoublePressProps(J);i.useEffect(()=>{B(d.object)},[d.object]),i.useEffect(()=>{if(!$)return;const e=d.object.id,o=o=>{var n;if(o.documentId!==t)return;const i=null==(n=o.previewPatches)?void 0:n[e];"update"===o.type&&i?B(e=>({...e,...i})):"cancel"===o.type&&B(d.object)},n=[$.onDragChange(o),$.onResizeChange(o)];return()=>n.forEach(e=>e())},[$,t,d.object]);const ee=g&&!p;return o.jsxs("div",{"data-no-interaction":!0,children:[o.jsxs("div",{...U&&g?Q:{},..._,style:{position:"absolute",left:H.rect.origin.x*e,top:H.rect.origin.y*e,width:H.rect.size.width*e,height:H.rect.size.height*e,outline:ee?`1px solid ${R}`:"none",outlineOffset:ee?`${k}px`:"0px",pointerEvents:g&&!p?"auto":"none",touchAction:"none",cursor:g&&U?"move":"default",zIndex:M,...y},...D,children:[(()=>{const t="function"==typeof u?u(H):u,o=null==A?void 0:A({annotation:H,children:t,isSelected:g,scale:e,rotation:s,pageWidth:l,pageHeight:a,pageIndex:n,onSelect:I});return null!=o?o:t})(),g&&W&&Z.map(({key:e,...t})=>(null==P?void 0:P.component)?P.component({key:e,...t,backgroundColor:N}):o.jsx("div",{...t,style:{...t.style,backgroundColor:N}},e)),g&&L&&!p&&X.map(({key:e,...t})=>(null==z?void 0:z.component)?z.component({key:e,...t,backgroundColor:q}):o.jsx("div",{...t,style:{...t.style,backgroundColor:q}},e))]}),j&&!p&&o.jsx(c.CounterRotate,{rect:{origin:{x:H.rect.origin.x*e,y:H.rect.origin.y*e},size:{width:H.rect.size.width*e,height:H.rect.size.height*e}},rotation:s,children:e=>j({...e,context:{type:"annotation",annotation:d,pageIndex:n},selected:g,placement:{suggestTop:!1}})})]})}function f({documentId:e,pageIndex:t,scale:n,rotation:l,pageWidth:a,pageHeight:d,selectedAnnotations:u,isDraggable:g,isResizable:p,resizeUI:h,selectionOutlineColor:b="#007ACC",outlineOffset:x=2,zIndex:f=100,groupSelectionMenu:y}){const{plugin:m}=v(),{canModifyAnnotations:j}=r.useDocumentPermissions(e),k=i.useRef(null),S=i.useRef(!1),I=i.useRef(!1),M=j&&g,P=j&&p,z=i.useMemo(()=>{const e=u.map(e=>e.object.rect);return s.boundingRectOrEmpty(e)},[u]),[R,A]=i.useState(z);i.useEffect(()=>{S.current||I.current||A(z)},[z]);const C=i.useCallback(t=>{var o,n;if(!(null==(o=t.transformData)?void 0:o.type))return;if(!m)return;const i=t.transformData.type,r="move"===i,s="resize"===i;if(r&&!M)return;"start"===t.state&&(k.current=z,r?(S.current=!0,m.startDrag(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:a,height:d}})):s&&(I.current=!0,m.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:a,height:d},resizeHandle:(null==(n=t.transformData.metadata)?void 0:n.handle)??"se"})));const l=k.current??z;if(r&&t.transformData.changes.rect){const o=t.transformData.changes.rect,n={x:o.origin.x-l.origin.x,y:o.origin.y-l.origin.y},i=m.updateDrag(e,n);A({...l,origin:{x:l.origin.x+i.x,y:l.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const o=t.transformData.changes.rect;m.updateResize(e,o),A(o)}"end"===t.state&&(k.current=null,r&&S.current?(S.current=!1,m.commitDrag(e)):s&&I.current&&(I.current=!1,m.commitResize(e)))},[m,e,a,d,z,M,u]),w=(null==h?void 0:h.color)??"#007ACC",D=(null==h?void 0:h.size)??12,{dragProps:E,resize:B}=c.useInteractionHandles({controller:{element:R,constraints:{minWidth:20,minHeight:20,boundingBox:{width:a,height:d}},maintainAspectRatio:!1,pageRotation:l,scale:n,enabled:!0,onUpdate:C},resizeUI:{handleSize:D,spacing:x,offsetMode:"outside",includeSides:!0,zIndex:f+1},vertexUI:{vertexSize:0,zIndex:f},includeVertices:!1});return u.length<2?null:o.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[o.jsx("div",{...M?E:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:R.origin.x*n,top:R.origin.y*n,width:R.size.width*n,height:R.size.height*n,outline:`2px dashed ${b}`,outlineOffset:x-1,cursor:M?"move":"default",touchAction:"none",zIndex:f},children:P&&B.map(({key:e,...t})=>(null==h?void 0:h.component)?h.component({key:e,...t,backgroundColor:w}):o.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),y&&o.jsx(c.CounterRotate,{rect:{origin:{x:R.origin.x*n,y:R.origin.y*n},size:{width:R.size.width*n,height:R.size.height*n}},rotation:l,children:e=>y({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function y({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:a,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l}},n))})}function m({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:a,opacity:t,pointerEvents:"none"}})},n))})}function j({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:o.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:a,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},n))})}function k({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=2*r,c=6*r,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e??"#FFFF00"}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n))})}function S({isSelected:e,strokeColor:t,opacity:n=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=i.useMemo(()=>s.map(({points:e})=>{let t="";return e.forEach(({x:e,y:o},n)=>{const i=e-l.origin.x,r=o-l.origin.y;t+=(0===n?"M":"L")+i+" "+r+" "}),t.trim()}),[s,l]),g=l.size.width*a,p=l.size.height*a;return o.jsx("svg",{style:{position:"absolute",width:g,height:p,pointerEvents:"none",zIndex:2,overflow:"visible"},width:g,height:p,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:u.map((t,i)=>o.jsx("path",{d:t,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},i))})}function I({isSelected:e,color:t="#000000",strokeColor:n,opacity:r=1,strokeWidth:l,strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:p,height:h,x:v,y:b}=i.useMemo(()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}},[d,l]),x=(p+l)*u,f=(h+l)*u;return o.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2},width:x,height:f,viewBox:`0 0 ${p+l} ${h+l}`,children:o.jsx("rect",{x:v,y:b,width:p,height:h,fill:t,opacity:r,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function M({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:r,strokeStyle:l=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:g}){const{width:p,height:h,cx:v,cy:b,rx:x,ry:f}=i.useMemo(()=>{const e=c.size.width,t=c.size.height,o=Math.max(e-r,0),n=Math.max(t-r,0);return{width:e,height:t,cx:r/2+o/2,cy:r/2+n/2,rx:o/2,ry:n/2}},[c,r]),y=p*d,m=h*d;return o.jsx("svg",{style:{position:"absolute",width:y,height:m,pointerEvents:"none",zIndex:2},width:y,height:m,viewBox:`0 0 ${p} ${h}`,children:o.jsx("ellipse",{cx:v,cy:b,rx:x,ry:f,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function P({color:e="transparent",opacity:n=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:g,scale:p,onClick:h,isSelected:v}){const{x1:b,y1:x,x2:f,y2:y}=i.useMemo(()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y}),[u,d]),m=i.useMemo(()=>{const e=Math.atan2(y-x,f-b);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,b,x),end:t.patching.createEnding(null==g?void 0:g.end,r,e,f,y)}},[g,r,b,x,f,y]),j=d.size.width*p,k=d.size.height*p;return o.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[o.jsx("line",{x1:b,y1:x,x2:f,y2:y,opacity:n,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",pointerEvents:v?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&o.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:h,onTouchStart:h,stroke:l,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.start.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&o.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function z({rect:e,vertices:n,color:r="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const p=i.useMemo(()=>n.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[n,e]),h=i.useMemo(()=>{if(!p.length)return"";const[e,...t]=p;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[p]),v=i.useMemo(()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),o=e(p[0],p[1]),n=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,o+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,n,p[p.length-1].x,p[p.length-1].y)}},[p,g,a]),b=e.size.width*c,x=e.size.height*c;return o.jsxs("svg",{style:{position:"absolute",width:b,height:x,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:x,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.jsx("path",{d:h,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:s??r,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),v.start&&o.jsx("path",{d:v.start.d,transform:v.start.transform,stroke:s,fill:v.start.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),v.end&&o.jsx("path",{d:v.end.d,transform:v.end.transform,stroke:s,fill:v.end.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function R({rect:e,vertices:t,color:n="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:p,currentVertex:h,handleSize:v=14}){const b=h?[...t,h]:t,x=i.useMemo(()=>b.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[b,e]),f=i.useMemo(()=>{if(!x.length)return"";const[e,...t]=x,o=!!h;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(o?"":" Z")).trim()},[x,h]),y=h&&t.length>0,m=e.size.width*u,j=e.size.height*u;return o.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.jsx("path",{d:f,onPointerDown:p,onTouchStart:p,opacity:l,style:{fill:h?"none":n,stroke:r??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),y&&t.length>1&&o.jsx("path",{d:`M ${x[x.length-1].x} ${x[x.length-1].y} L ${x[0].x} ${x[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),y&&t.length>=2&&o.jsx("rect",{x:x[0].x-v/u/2,y:x[0].y-v/u/2,width:v/u,height:v/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function A({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const c=i.useRef(null),{provides:u}=b(),[g,p]=i.useState(!1);i.useEffect(()=>{if(t&&c.current){const e=c.current;e.focus();const t=window.getSelection();if(t){const o=document.createRange();o.selectNodeContents(e),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}}},[t]),i.useLayoutEffect(()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}},[]);const h=n.object.fontSize*l,v=g&&t&&h>0&&h<16,x=v?16:h,f=v?h/16:1,y=v?100/f:100;return o.jsx("div",{style:{position:"absolute",width:n.object.rect.size.width*l,height:n.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:o.jsx("span",{ref:c,onBlur:()=>{u&&c.current&&u.updateAnnotation(r,n.object.id,{contents:c.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:x,fontFamily:s.standardFontCss(n.object.fontFamily),textAlign:s.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===s.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===s.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.color??n.object.backgroundColor,opacity:n.object.opacity,width:v?`${y}%`:"100%",height:v?`${y}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${f})`:void 0,transformOrigin:"top left"},contentEditable:t,...d,children:n.object.contents})})}function C({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=b(),[u,g]=i.useState(null),p=i.useRef(null),{width:h,height:v}=r.rect.size;i.useEffect(()=>{if(d){const o=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return o.wait(e=>{const t=URL.createObjectURL(e);g(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):o.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,h,v]);return o.jsx(n.Fragment,{children:u&&o.jsx("img",{src:u,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function w({isSelected:e,annotation:t,documentId:n,pageIndex:i,scale:r,onClick:s}){return o.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:o.jsx(C,{documentId:n,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function D({isSelected:e,strokeColor:t="#0000FF",strokeWidth:n=2,strokeStyle:r=s.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:p}=i.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),h=g*c,v=p*c,b=i.useMemo(()=>{if(r===s.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*n},${n}`},[r,l,n]),x=r===s.PdfAnnotationBorderStyle.UNDERLINE;return o.jsxs("svg",{style:{position:"absolute",width:h,height:v,pointerEvents:"none",zIndex:2},width:h,height:v,viewBox:`0 0 ${g} ${p}`,children:[o.jsx("rect",{x:0,y:0,width:g,height:p,fill:"transparent",onPointerDown:u?void 0:d,onTouchStart:u?void 0:d,style:{cursor:u?"default":e?"move":"pointer",pointerEvents:u||e?"none":"visible"}}),x?o.jsx("line",{x1:1,y1:p-1,x2:g-1,y2:p-1,stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}}):o.jsx("rect",{x:n/2,y:n/2,width:Math.max(g-n,0),height:Math.max(p-n,0),fill:"transparent",stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}})]})}function E(e){const{documentId:r,pageIndex:c,scale:d,pageWidth:u,pageHeight:g,selectionMenu:p}=e,{provides:h}=b(),{provides:v}=a.useSelectionCapability(),[C,E]=i.useState([]),{register:B}=l.usePointerHandlers({documentId:r,pageIndex:c}),[T,$]=i.useState([]),[L,F]=i.useState(null),U=i.useMemo(()=>h?h.forDocument(r):null,[h,r]),W=T.length>1;i.useEffect(()=>{if(U){const e=U.getState();return E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e)),U.onStateChange(e=>{E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e))})}},[U,c]);const O=i.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&U&&(U.deselectAnnotation(),F(null))}}),[U]),H=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){v.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?U.toggleSelection(c,t.object.id):U.selectAnnotation(c,t.object.id),t.object.id!==L&&F(null)}},[U,v,L,c]),N=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){if(v.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,o=C.find(t=>t.object.id===e);if(o)return void U.selectAnnotation(o.object.pageIndex,e)}U.selectAnnotation(c,t.object.id)}},[U,v,C,c]);i.useEffect(()=>B(O,{documentId:r}),[B,O]);const q=i.useMemo(()=>C.filter(e=>T.includes(e.object.id)),[C,T]),G=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.isGroupDraggable,e.object,!0),i=t.resolveInteractionProp(null==o?void 0:o.interaction.isDraggable,e.object,!0);return void 0!==(null==o?void 0:o.interaction.isGroupDraggable)?n:i}),[q,U]),V=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.isGroupResizable,e.object,!0),i=t.resolveInteractionProp(null==o?void 0:o.interaction.isResizable,e.object,!0);return void 0!==(null==o?void 0:o.interaction.isGroupResizable)?n:i}),[q,U]),K=i.useMemo(()=>{if(!U)return!1;const e=U.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===c)},[U,c,T]);return o.jsxs(o.Fragment,{children:[C.map(i=>{const l=T.includes(i.object.id),a=L===i.object.id,u=null==U?void 0:U.findToolForAnnotation(i.object);for(const n of e.annotationRenderers??[]){const r=n.tryRender(i,{isSelected:l,scale:d,pageIndex:c,onClick:e=>H(e,i)});if(r)return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:()=>r},i.object.id)}if(t.isInk(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(S,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquare(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(I,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isCircle(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(M,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isUnderline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(m,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStrikeout(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(j,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquiggly(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(k,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isHighlight(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(y,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLine(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(P,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolyline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(z,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolygon(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(R,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isFreeText(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0)&&!a,isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),F(i.object.id)},...e,children:e=>o.jsx(A,{isSelected:l,isEditing:a,annotation:{...i,object:e},pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStamp(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(w,{isSelected:l,annotation:i,documentId:r,pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLink(i)){const t=!!i.object.inReplyToId;return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:p,onSelect:e=>N(e,i),...e,children:e=>o.jsx(D,{...e,isSelected:l,scale:d,onClick:e=>N(e,i),hasIRT:t})},i.object.id)}return null}),K&&q.length>=2&&o.jsx(f,{documentId:r,pageIndex:c,scale:d,rotation:e.rotation,pageWidth:u,pageHeight:g,selectedAnnotations:q,isDraggable:G,isResizable:V,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function B({documentId:e,pageIndex:t,scale:n}){var r,l,c,d,u,g,p,h,v,x,f,S;const{provides:I}=a.useSelectionCapability(),{provides:M}=b(),[P,z]=i.useState([]),[R,A]=i.useState(null),[C,w]=i.useState(null);if(i.useEffect(()=>{if(I)return I.forDocument(e).onSelectionChange(()=>{z(I.forDocument(e).getHighlightRectsForPage(t)),A(I.forDocument(e).getBoundingRectForPage(t))})},[I,e,t]),i.useEffect(()=>{if(M)return w(M.forDocument(e).getActiveTool()),M.forDocument(e).onActiveToolChange(e=>w(e))},[M,e]),!R)return null;if(!C||!C.defaults)return null;switch(C.defaults.type){case s.PdfAnnotationSubtype.UNDERLINE:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=C.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(m,{strokeColor:null==(l=C.defaults)?void 0:l.strokeColor,opacity:null==(c=C.defaults)?void 0:c.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(y,{strokeColor:null==(u=C.defaults)?void 0:u.strokeColor,opacity:null==(g=C.defaults)?void 0:g.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(p=C.defaults)?void 0:p.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(j,{strokeColor:null==(h=C.defaults)?void 0:h.strokeColor,opacity:null==(v=C.defaults)?void 0:v.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(x=C.defaults)?void 0:x.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(k,{strokeColor:null==(f=C.defaults)?void 0:f.strokeColor,opacity:null==(S=C.defaults)?void 0:S.opacity,segmentRects:P,scale:n})});default:return null}}function T({preview:e,scale:t}){const{bounds:n}=e,i={position:"absolute",left:n.origin.x*t,top:n.origin.y*t,width:n.size.width*t,height:n.size.height*t,pointerEvents:"none",zIndex:10};return e.type===s.PdfAnnotationSubtype.CIRCLE?o.jsx("div",{style:i,children:o.jsx(M,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:i,children:o.jsx(I,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?o.jsx("div",{style:i,children:o.jsx(R,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?o.jsx("div",{style:i,children:o.jsx(z,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?o.jsx("div",{style:i,children:o.jsx(P,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?o.jsx("div",{style:i,children:o.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.FREETEXT?o.jsx("div",{style:i,children:o.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function $({documentId:e,pageIndex:t,scale:n}){const{plugin:r}=v(),[s,l]=i.useState(new Map),a=i.useRef(null),c=i.useRef(null),d=i.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const o=a.current;o.accept=e,o.onchange=e=>{var n;const i=null==(n=e.target.files)?void 0:n[0];i&&(t(i),o.value="")},o.click()},processImage:({source:e,maxWidth:t,maxHeight:o,onComplete:n})=>{const i=c.current;if(!i||!i.getContext)return;const r=i.getContext("2d");if(!r)return;const s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;const c=t?t/l:1,d=o?o/a:1,u=Math.min(c,d,1),g=l*u,p=a*u;i.width=g,i.height=p,r.drawImage(s,0,0,g,p);const h=r.getImageData(0,0,g,p);"string"!=typeof e&&URL.revokeObjectURL(s.src),n({imageData:h,width:g,height:p})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return i.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,n,{services:d,onPreview:(e,t)=>{l(o=>{const n=new Map(o);return t?n.set(e,t):n.delete(e),n})}})},[e,t,n,r,d]),o.jsxs(o.Fragment,{children:[o.jsx("input",{ref:a,type:"file",style:{display:"none"}}),o.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(s.entries()).map(([e,t])=>o.jsx(T,{preview:t,scale:n},e))]})}const L=e.createPluginPackage(t.AnnotationPluginPackage).addWrapper(p).build();exports.AnnotationLayer=function({style:e,documentId:t,pageIndex:n,scale:l,rotation:a,selectionMenu:c,groupSelectionMenu:d,resizeUI:u,vertexUI:g,selectionOutlineColor:p,customAnnotationRenderer:v,annotationRenderers:b,...x}){var f,y,m,j;const k=r.useDocumentState(t),S=null==(y=null==(f=null==k?void 0:k.document)?void 0:f.pages)?void 0:y[n],I=(null==(m=null==S?void 0:S.size)?void 0:m.width)??0,M=(null==(j=null==S?void 0:S.size)?void 0:j.height)??0,P=h(),z=i.useMemo(()=>{const e=[...P];for(const t of b??[]){const o=e.findIndex(e=>e.id===t.id);o>=0?e[o]=t:e.push(t)}return e},[P,b]),R=i.useMemo(()=>void 0!==l?l:(null==k?void 0:k.scale)??1,[l,null==k?void 0:k.scale]),A=i.useMemo(()=>void 0!==a?a:(null==k?void 0:k.rotation)??s.Rotation.Degree0,[a,null==k?void 0:k.rotation]);return o.jsxs("div",{style:{...e},...x,children:[o.jsx(E,{documentId:t,selectionMenu:c,groupSelectionMenu:d,pageIndex:n,scale:R,rotation:A,pageWidth:I,pageHeight:M,resizeUI:u,vertexUI:g,selectionOutlineColor:p,customAnnotationRenderer:v,annotationRenderers:z}),o.jsx(B,{documentId:t,pageIndex:n,scale:R}),o.jsx($,{documentId:t,pageIndex:n,scale:R})]})},exports.AnnotationPluginPackage=L,exports.AnnotationRendererProvider=p,exports.GroupSelectionBox=f,exports.createRenderer=function(e){return{id:e.id,tryRender:(t,o)=>e.matches(t.object)?e.render({...o,annotation:t}):null}},exports.useAnnotation=e=>{var o;const{provides:n}=b(),[r,s]=i.useState((null==(o=null==n?void 0:n.forDocument(e))?void 0:o.getState())??t.initialDocumentState());return i.useEffect(()=>{if(!n)return;const t=n.forDocument(e);return s(t.getState()),t.onStateChange(e=>{s(e)})},[n,e]),{state:r,provides:(null==n?void 0:n.forDocument(e))??null}},exports.useAnnotationCapability=b,exports.useAnnotationPlugin=v,exports.useRegisterRenderers=function(e){const t=i.useContext(u),o=i.useRef(e);i.useEffect(()=>{if(t)return t(o.current)},[t])},exports.useRegisteredRenderers=h,exports.useRendererRegistry=function(){return i.useContext(u)},Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map