@embedpdf/plugin-annotation 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -190
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +8 -26
- package/dist/lib/annotation-plugin.d.ts +1 -1
- package/dist/lib/helpers.d.ts +5 -1
- package/dist/lib/selectors.d.ts +29 -7
- package/dist/lib/types.d.ts +18 -19
- package/dist/preact/adapter.d.ts +1 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +137 -87
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +137 -87
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotations/circle.d.ts +5 -5
- package/dist/shared-preact/components/annotations/free-text.d.ts +2 -2
- package/dist/shared-preact/components/annotations/ink.d.ts +5 -5
- package/dist/shared-preact/components/annotations/line.d.ts +2 -2
- package/dist/shared-preact/components/annotations/polygon.d.ts +2 -2
- package/dist/shared-preact/components/annotations/polyline.d.ts +2 -2
- package/dist/shared-preact/components/annotations/square.d.ts +5 -5
- package/dist/shared-preact/components/annotations/stamp.d.ts +2 -2
- package/dist/shared-preact/components/counter-rotate-container.d.ts +2 -1
- package/dist/shared-preact/components/text-markup/highlight.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +2 -2
- package/dist/shared-preact/components/text-markup/underline.d.ts +2 -2
- package/dist/shared-preact/hooks/use-drag-resize.d.ts +5 -1
- package/dist/shared-react/components/annotations/circle.d.ts +5 -5
- package/dist/shared-react/components/annotations/free-text.d.ts +2 -2
- package/dist/shared-react/components/annotations/ink.d.ts +5 -5
- package/dist/shared-react/components/annotations/line.d.ts +2 -2
- package/dist/shared-react/components/annotations/polygon.d.ts +2 -2
- package/dist/shared-react/components/annotations/polyline.d.ts +2 -2
- package/dist/shared-react/components/annotations/square.d.ts +5 -5
- package/dist/shared-react/components/annotations/stamp.d.ts +2 -2
- package/dist/shared-react/components/counter-rotate-container.d.ts +2 -1
- package/dist/shared-react/components/text-markup/highlight.d.ts +2 -2
- package/dist/shared-react/components/text-markup/squiggly.d.ts +2 -2
- package/dist/shared-react/components/text-markup/strikeout.d.ts +2 -2
- package/dist/shared-react/components/text-markup/underline.d.ts +2 -2
- package/dist/shared-react/hooks/use-drag-resize.d.ts +5 -1
- package/package.json +14 -9
- package/dist/lib/utils.d.ts +0 -11
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
-
import { PdfAnnotationObject, PdfErrorReason, Task, PdfAnnotationSubtype, WebAlphaColor, Rotation, ImageConversionTypes, AppearanceMode, PdfBlendMode, PdfAnnotationBorderStyle, LineEndings, PdfStandardFont, PdfTextAlignment, PdfVerticalAlignment, AnnotationCreateContext } from '@embedpdf/models';
|
|
2
|
+
import { PdfAnnotationObject, PdfErrorReason, Task, PdfAnnotationSubtype, WebAlphaColor, Rotation, ImageConversionTypes, AppearanceMode, PdfBlendMode, PdfAnnotationBorderStyle, LineEndings, PdfStandardFont, PdfTextAlignment, PdfVerticalAlignment, AnnotationCreateContext, PdfTextAnnoObject } from '@embedpdf/models';
|
|
3
3
|
export type CommitState = 'new' | 'dirty' | 'deleted' | 'synced' | 'ignored';
|
|
4
4
|
export interface TrackedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
5
|
-
/** A stable, client-side unique identifier for history and state management. */
|
|
6
|
-
localId: number;
|
|
7
|
-
/**
|
|
8
|
-
* If the engine has already created the annotation in the PDF
|
|
9
|
-
* this is the definitive id coming from the engine.
|
|
10
|
-
* It is **never** cleared once set.
|
|
11
|
-
*/
|
|
12
|
-
pdfId?: number;
|
|
13
5
|
/** local commit bookkeeping */
|
|
14
6
|
commitState: CommitState;
|
|
15
|
-
/** the actual annotation object */
|
|
7
|
+
/** the actual annotation object, where `object.id` is the stable string ID */
|
|
16
8
|
object: T;
|
|
17
9
|
}
|
|
18
10
|
export interface RenderAnnotationOptions {
|
|
@@ -158,11 +150,15 @@ export interface AnnotationPluginConfig extends BasePluginConfig {
|
|
|
158
150
|
* flushed with `commitPendingChanges()`.
|
|
159
151
|
*/
|
|
160
152
|
autoCommit?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Author of the annotation
|
|
155
|
+
*/
|
|
156
|
+
annotationAuthor?: string;
|
|
161
157
|
}
|
|
162
158
|
export interface AnnotationCapability {
|
|
163
159
|
getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
|
|
164
160
|
getSelectedAnnotation: () => TrackedAnnotation | null;
|
|
165
|
-
selectAnnotation: (pageIndex: number, annotationId:
|
|
161
|
+
selectAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
166
162
|
deselectAnnotation: () => void;
|
|
167
163
|
getActiveVariant: () => string | null;
|
|
168
164
|
setActiveVariant: (variantKey: string | null) => void;
|
|
@@ -186,8 +182,8 @@ export interface AnnotationCapability {
|
|
|
186
182
|
/** append a swatch (deduped by RGBA) */
|
|
187
183
|
addColorPreset: (color: string) => void;
|
|
188
184
|
createAnnotation: <A extends PdfAnnotationObject>(pageIndex: number, annotation: A, ctx?: AnnotationCreateContext<A>) => void;
|
|
189
|
-
updateAnnotation: (pageIndex: number, annotationId:
|
|
190
|
-
deleteAnnotation: (pageIndex: number, annotationId:
|
|
185
|
+
updateAnnotation: (pageIndex: number, annotationId: string, patch: Partial<PdfAnnotationObject>) => void;
|
|
186
|
+
deleteAnnotation: (pageIndex: number, annotationId: string) => void;
|
|
191
187
|
renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
|
|
192
188
|
/** undo / redo */
|
|
193
189
|
onStateChange: EventHook<AnnotationState>;
|
|
@@ -195,15 +191,18 @@ export interface AnnotationCapability {
|
|
|
195
191
|
onActiveToolChange: EventHook<ActiveTool>;
|
|
196
192
|
commit: () => void;
|
|
197
193
|
}
|
|
198
|
-
export interface SelectedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
|
|
199
|
-
pageIndex: number;
|
|
200
|
-
localId: number;
|
|
201
|
-
annotation: T;
|
|
202
|
-
}
|
|
203
194
|
export interface GetPageAnnotationsOptions {
|
|
204
195
|
pageIndex: number;
|
|
205
196
|
}
|
|
206
197
|
export interface UpdateAnnotationColorOptions extends WebAlphaColor {
|
|
207
198
|
pageIndex: number;
|
|
208
|
-
annotationId:
|
|
199
|
+
annotationId: string;
|
|
200
|
+
}
|
|
201
|
+
export interface SidebarAnnotationEntry {
|
|
202
|
+
/** Zero-based page index */
|
|
203
|
+
page: number;
|
|
204
|
+
/** The tracked root annotation shown in the sidebar */
|
|
205
|
+
annotation: TrackedAnnotation;
|
|
206
|
+
/** Any TEXT-type annotations whose `inReplyToId` points to the root */
|
|
207
|
+
replies: TrackedAnnotation<PdfTextAnnoObject>[];
|
|
209
208
|
}
|
package/dist/preact/adapter.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T exte
|
|
|
7
7
|
export type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;
|
|
8
8
|
export type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;
|
|
9
9
|
export type ChangeEvent<T = Element> = JSX.TargetedInputEvent<T extends EventTarget ? T : never>;
|
|
10
|
+
export type TouchEvent<T = Element> = JSX.TargetedTouchEvent<T extends EventTarget ? T : never>;
|
|
10
11
|
export declare const mapDoubleClick: (handler: any) => {
|
|
11
12
|
onDblClick: any;
|
|
12
13
|
} | {
|
package/dist/preact/index.cjs
CHANGED
|
@@ -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/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),r=require("@embedpdf/plugin-selection/preact"),s=require("preact"),l=require("preact/hooks"),a=()=>e.useCapability(t.AnnotationPlugin.id);function c({children:e,...t}){const{rect:o,rotation:i}=t,{matrix:r,width:l,height:a}=function(e,t){const{width:n,height:o}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${o})`,width:o,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${o})`,width:n,height:o};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:o,height:n};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:n,height:o}}}(o,i),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:r,transformOrigin:"0 0",width:l,height:a,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation()};return n.jsx(s.Fragment,{children:e({menuWrapperProps:c,matrix:r,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:l,height:a}}})})}function d({rect:e,rotation:t,scale:i,vertices:r,onEdit:a,onCommit:c,handleSize:d=12}){const[u,h]=l.useState(null),g=l.useRef(null),p=l.useRef([]),y=e=>{const n=o.restoreOffset(e,t,i),r=[...p.current];return null!==u&&(r[u]={x:r[u].x+n.x,y:r[u].y+n.y}),r},x=e=>{if(null===u||!g.current)return;const t={x:e.clientX-g.current.x,y:e.clientY-g.current.y};a(y(t))},f=e=>{if(null===u||!g.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-g.current.x,y:e.clientY-g.current.y};c(y(t)),h(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-d/2,l=(t.y-e.origin.y)*i-d/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:d,height:d,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),h(a),g.current={x:e.clientX,y:e.clientY},p.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:x,onPointerUp:f},o);var a}))})}function u({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:s,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,lockAspectRatio:h=!1,currentRect:g,setCurrentRect:p,setCurrentVertices:y,setPreviewObject:x,commit:f}){const v=l.useRef("idle"),m=l.useRef("none"),k=l.useRef(null),b=l.useRef(null),M=(e,t,n)=>Math.max(t,Math.min(n,e)),w=t/e,P=n/e,j=e=>{if("idle"===v.current)return;if((null==e?void 0:e.currentTarget)&&void 0!==e.pointerId)try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}const t=m.current||"bottom-right";v.current="idle";let n={rect:g};d&&(n=d(r.object,{rect:g,direction:t})),f(n),k.current=null,b.current=null,m.current="none",x(null)};return l.useEffect((()=>{v.current="idle",m.current="none",k.current=null,b.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{s&&a&&(e.stopPropagation(),e.preventDefault(),v.current="dragging",k.current={x:e.clientX,y:e.clientY},b.current=g,e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:t=>{if("idle"===v.current||!k.current)return;const n={x:t.clientX-k.current.x,y:t.clientY-k.current.y},{x:s,y:l}=o.restoreOffset(n,i,e),a=((e,t)=>{if(!b.current)return g;let{origin:n,size:o}=b.current,i=n.x,r=n.y,s=o.width,l=o.height;if("dragging"===v.current)i+=e,r+=t;else if("resizing"===v.current&&(m.current.includes("right")?s+=e:m.current.includes("left")&&(i+=e,s-=e),m.current.includes("bottom")?l+=t:m.current.includes("top")&&(r+=t,l-=t),h&&b.current)){const e=b.current.size.width/b.current.size.height,t=i+s,n=r+l;m.current.includes("left")||m.current.includes("right")?l=s/e:s=l*e,m.current.includes("left")&&(i=t-s),m.current.includes("top")&&(r=n-l)}return s<1||l<1?g:(s=M(s,1,w),l=M(l,1,P),i=M(i,0,w-s),r=M(r,0,P-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(s,l);let c={rect:a};d&&(c=d(r.object,{rect:a,direction:"resizing"===v.current?m.current:"bottom-right"}),u&&y(u({...r.object,...c}))),p(c.rect??a),x(c)},onPointerUp:j,onPointerCancel:()=>j(),onLostPointerCapture:()=>j()},startResize:e=>t=>{s&&c&&(t.stopPropagation(),t.preventDefault(),v.current="resizing",m.current=e,k.current={x:t.clientX,y:t.clientY},b.current=g,t.currentTarget.setPointerCapture(t.pointerId))}}}function h({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function g({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:g,trackedAnnotation:p,children:y,style:x,outlineOffset:f=1,isSelected:v=!1,isDraggable:m=!0,isResizable:k=!0,lockAspectRatio:b=!1,computeVertices:M,computePatch:w,selectionMenu:P,onDoubleClick:j,...S}){const{provides:I}=a(),[A,C]=l.useState(p.object.rect),[z,E]=l.useState((null==M?void 0:M(p.object))??[]),[D,W]=l.useState(null),{rootHandlers:R,startResize:B}=u({scale:e,pageWidth:r,pageHeight:g,rotation:i,tracked:p,isSelected:v,isDraggable:m,isResizable:k,lockAspectRatio:b,computePatch:w,computeVertices:M,currentRect:A,setCurrentRect:C,setCurrentVertices:E,setPreviewObject:W,commit:e=>null==I?void 0:I.updateAnnotation(t,p.localId,e)});l.useLayoutEffect((()=>{o.rectEquals(p.object.rect,A)||(C(p.object.rect),W((e=>e?{...e,rect:p.object.rect}:null)),E((null==M?void 0:M(p.object))??[]))}),[p]);const L=D?{...p.object,...D}:p.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...R,...($=j,$?{onDblClick:$}:{}),style:{position:"absolute",outline:v?"1px solid #007ACC":"none",outlineOffset:v?`${f}px`:"0px",left:A.origin.x*e+"px",top:A.origin.y*e+"px",width:A.size.width*e+"px",height:A.size.height*e+"px",pointerEvents:v?"auto":"none",cursor:v&&m?"move":"default",...v&&{zIndex:3},...x},...S,children:["function"==typeof y?y(L):y,v&&z.length>0&&n.jsx(d,{rect:A,rotation:i,scale:e,vertices:z,onEdit:e=>{if(E(e),w){const t=w(p.object,{rect:A,vertices:e});W(t),C(t.rect||A)}},onCommit:e=>{if(I&&w){const n=w(p.object,{rect:A,vertices:e});I.updateAnnotation(t,p.localId,n)}}}),v&&k&&n.jsx(h,{rotation:i,outlineOffset:f,startResize:B})]}),n.jsx(c,{rect:{origin:{x:A.origin.x*e,y:A.origin.y*e},size:{width:A.size.width*e,height:A.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>P&&P({annotation:p,selected:v,rect:e,menuWrapperProps:t})})]});var $}function p({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onMouseDown: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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function v({color:e="#000000",opacity:t=1,strokeWidth:o,inkList:i,rect:r,scale:s,onClick:a,cursor:c}){const d=l.useMemo((()=>i.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-r.origin.x,s=n-r.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "})),t.trim()}))),[i,r]),u=r.size.width*s,h=r.size.height*s;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${r.size.width} ${r.size.height}`,children:d.map(((i,r)=>n.jsx("path",{d:i,fill:"none",opacity:t,onMouseDown:a,style:{cursor:c,pointerEvents:"visibleStroke",stroke:e,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function m({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:g,height:p,x:y,y:x}=l.useMemo((()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}}),[c,r]),f=(g+r)*d,v=(p+r)*d;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${g+r} ${p+r}`,children:n.jsx("rect",{x:y,y:x,width:g,height:p,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function k({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:g,height:p,cx:y,cy:x,rx:f,ry:v}=l.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),m=g*d,k=p*d;return n.jsx("svg",{style:{position:"absolute",width:m,height:k,pointerEvents:"none",zIndex:2},width:m,height:k,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const b=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function M({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:s="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:y}){const{x1:x,y1:f,x2:v,y2:m}=l.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]),k=l.useMemo((()=>{const e=Math.atan2(m-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,m)}}),[h,r,x,f,v,m]),b=d.size.width*g,M=d.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:b,height:M,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:M,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:m,opacity:i,onMouseDown:p,style:{cursor:y?"move":"pointer",pointerEvents:"visibleStroke",stroke:s,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),k.start&&n.jsx("path",{d:k.start.d,transform:k.start.transform,onMouseDown:p,stroke:s,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:k.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:k.start.filled?e:"none"}),k.end&&n.jsx("path",{d:k.end.d,transform:k.end.transform,stroke:s,onMouseDown:p,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:k.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:k.end.filled?e:"none"})]})}function w({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=l.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),p=l.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[g]),y=l.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[1],g[0]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onMouseDown:u,opacity:s,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function P({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g}){const p=l.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=l.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[p]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onMouseDown:g,opacity:s,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const j=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},S=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},I=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function A({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:s,onClick:c}){const d=l.useRef(null),{provides:u}=a();l.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]);return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*s,height:i.object.rect.size.height*s,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:c,children:n.jsx("span",{ref:d,onBlur:()=>{u&&d.current&&u.updateAnnotation(r,i.localId,{contents:d.current.innerText})},style:{color:i.object.fontColor,fontSize:i.object.fontSize*s,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:"100%",height:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer"},contentEditable:t,suppressContentEditableWarning:!0,children:i.object.contents})})}function C({pageIndex:e,annotation:t,scaleFactor:i=1,style:r,...c}){const{provides:d}=a(),[u,h]=l.useState(null),g=l.useRef(null),{width:p,height:y}=t.rect.size;l.useEffect((()=>{if(d){const n=d.renderAnnotation({pageIndex:e,annotation:t,scaleFactor:i,dpr:window.devicePixelRatio});return n.wait((e=>{const t=URL.createObjectURL(e);h(t),g.current=t}),o.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,d,t.id,p,y]);return n.jsx(s.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...c,style:{width:"100%",height:"100%",...r||{}}})})}function z({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:r}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:r,children:void 0!==t.pdfId&&n.jsx(C,{pageIndex:o,annotation:{...t.object,id:t.pdfId},scaleFactor:i})})}function E(e){const{pageIndex:c,scale:d,selectionMenu:u}=e,{provides:h}=a(),{provides:C}=r.useSelectionCapability(),[E,D]=l.useState([]),{register:W}=i.usePointerHandlers({pageIndex:c}),[R,B]=l.useState(null),[L,$]=l.useState(null);l.useEffect((()=>{h&&h.onStateChange((e=>{D(t.getAnnotationsByPageIndex(e,c)),B(t.getSelectedAnnotationByPageIndex(e,c))}))}),[h]);const T=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&h&&(h.deselectAnnotation(),$(null))}})),[h]),H=l.useCallback(((e,t)=>{e.stopPropagation(),h&&C&&(h.selectAnnotation(c,t.localId),C.clear(),$(null))}),[h,C,c]);return l.useEffect((()=>W(T)),[W,T]),n.jsx(n.Fragment,{children:E.map((i=>{const r=(null==R?void 0:R.localId)===i.localId,l=L===i.localId;return t.isInk(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,computePatch:b,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{cursor:r?"move":"pointer",color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:d,onClick:e=>H(e,i)})},i.localId):t.isSquare(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})},i.localId):t.isCircle(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(k,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})},i.localId):t.isUnderline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>H(e,i)})},i.localId):t.isStrikeout(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>H(e,i)})},i.localId):t.isSquiggly(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:d,onClick:e=>H(e,i)})},i.localId):t.isHighlight(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(p,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,rect:e.rect,onClick:e=>H(e,i)})},i.localId):t.isLine(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:j,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(M,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})})},i.localId):t.isPolyline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:S,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(w,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:d,onClick:e=>H(e,i)})})},i.localId):t.isPolygon(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computeVertices:e=>e.vertices,computePatch:I,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})})},i.localId):t.isFreeText(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,outlineOffset:6,onDoubleClick:e=>{e.stopPropagation(),$(i.localId)},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(A,{isSelected:r,isEditing:l,annotation:{...i,object:e},pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.localId):t.isStamp(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(z,{isSelected:r,annotation:i,pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.localId):null}))})}function D({pageIndex:e,scale:t}){var i,s,c,d,u,h,g,v,m,k,b,M;const{provides:w}=r.useSelectionCapability(),{provides:P}=a(),[j,S]=l.useState([]),[I,A]=l.useState(null),[C,z]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!w)return;return w.onSelectionChange((()=>{S(w.getHighlightRectsForPage(e)),A(w.getBoundingRectForPage(e))}))}),[w,e]),l.useEffect((()=>{if(!P)return;return P.onActiveToolChange(z)}),[P]),!I)return null;if(!C.defaults)return null;switch(C.defaults.subtype){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=C.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(s=C.defaults)?void 0:s.color,opacity:null==(c=C.defaults)?void 0:c.opacity,rects:j,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(u=C.defaults)?void 0:u.color,opacity:null==(h=C.defaults)?void 0:h.opacity,rects:j,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(g=C.defaults)?void 0:g.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(v=C.defaults)?void 0:v.color,opacity:null==(m=C.defaults)?void 0:m.opacity,rects:j,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(k=C.defaults)?void 0:k.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(b=C.defaults)?void 0:b.color,opacity:null==(M=C.defaults)?void 0:M.opacity,rects:j,scale:t})});default:return null}}const W=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s})=>{var c,d,u,h,g;const{provides:p}=a(),[y,x]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!p)return;return p.onActiveToolChange(x)}),[p]),!y.defaults)return null;if(y.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const f=(null==(c=y.defaults)?void 0:c.color)??"#000000",v=(null==(d=y.defaults)?void 0:d.opacity)??1,m=(null==(u=y.defaults)?void 0:u.strokeWidth)??2,k=(null==(h=y.defaults)?void 0:h.blendMode)??o.PdfBlendMode.Normal,b=null==(g=y.defaults)?void 0:g.intent,{register:M}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),w=(e,t,n)=>Math.max(t,Math.min(n,e)),[P,j]=l.useState([]),[S,I]=l.useState(!1),A=l.useRef(null),C=r/t,z=s/t,E=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=w(e.x,0,C),r=w(e.y,0,z);I(!0),A.current?(clearTimeout(A.current),A.current=null,j((e=>[...e,{points:[{x:i,y:r}]}]))):j([{points:[{x:i,y:r}]}]),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!S)return;const t=w(e.x,0,C),n=w(e.y,0,z);j((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i,r;I(!1),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),A.current&&clearTimeout(A.current),A.current=setTimeout((()=>{if(P.length&&p){const t=P.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),m/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:b,blendMode:k,rect:n,inkList:P,color:f,opacity:v,strokeWidth:m,pageIndex:e,id:Date.now()+Math.random()};p.createAnnotation(e,i),p.setActiveVariant(null),p.selectAnnotation(e,i.id)}j([]),A.current=null}),3e3)},onPointerCancel:(e,t)=>{var n,o;I(!1),null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),j([]),A.current&&(clearTimeout(A.current),A.current=null)}})),[C,z,P,p,e,f,v,m,S]);if(l.useEffect((()=>{if(M)return M(E)}),[M,E]),l.useEffect((()=>()=>{A.current&&clearTimeout(A.current)}),[]),!P.length)return null;const D=P.flatMap((e=>e.points));if(!D.length)return null;const W=o.expandRect(o.rectFromPoints(D),m/2),R=P.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:R.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:v,style:{stroke:f,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),k=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState(null),[j,S]=l.useState(null),I=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=k(e.x,0,b),r=k(e.y,0,M);P({x:i,y:r}),S({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=k(e.x,0,b),n=k(e.y,0,M);S({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&j&&d){const t=Math.min(w.x,j.x),n=Math.min(w.y,j.y),i=Math.max(w.x,j.x),r=Math.max(w.y,j.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),S(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),S(null)}})),[w,j,d,e,b,M,g,p,y]);if(l.useEffect((()=>m?m(I):void 0),[m,I]),!w||!j)return null;const A=Math.min(w.x,j.x),C=Math.min(w.y,j.y),z=Math.max(w.x,j.x),E=Math.max(w.y,j.y),D=y/2,W=A-D,R=C-D,B=z-A,L=E-C,$=B+y,T=L+y,H=D+B/2,F=D+L/2,O=B/2,N=L/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:$*t,height:T*t,pointerEvents:"none",zIndex:2},width:$*t,height:T*t,viewBox:`0 0 ${$} ${T}`,children:n.jsx("ellipse",{cx:H,cy:F,rx:O,ry:N,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},B=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"square",pageIndex:e}),k=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState(null),[j,S]=l.useState(null),I=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=k(e.x,0,b),r=k(e.y,0,M);P({x:i,y:r}),S({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=k(e.x,0,b),n=k(e.y,0,M);S({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&j&&d){const t=Math.min(w.x,j.x),n=Math.min(w.y,j.y),i=Math.max(w.x,j.x),r=Math.max(w.y,j.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),S(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),S(null)}})),[w,j,d,e,b,M,g,p,y]);if(l.useEffect((()=>m?m(I):void 0),[m,I]),!w||!j)return null;const A=Math.min(w.x,j.x),C=Math.min(w.y,j.y),z=Math.max(w.x,j.x),E=Math.max(w.y,j.y),D=y/2,W=A-D,R=C-D,B=z-A,L=E-C,$=B+y,T=L+y;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:$*t,height:T*t,pointerEvents:"none",zIndex:2},width:$*t,height:T*t,viewBox:`0 0 ${$} ${T}`,children:n.jsx("rect",{x:D,y:D,width:B,height:L,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},L=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.lineEndings,m=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=h.defaults.strokeDashArray,{register:b}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),M=(e,t,n)=>Math.max(t,Math.min(n,e)),P=s/r,j=c/r,[S,I]=l.useState([]),[A,C]=l.useState(null),z=l.useMemo((()=>({onClick:e=>{const t=M(e.x,0,P),n=M(e.y,0,j);I((e=>[...e,{x:t,y:n}])),C({x:t,y:n})},onDoubleClick:()=>{S.length>=1&&u&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,x,v),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:m,strokeDashArray:k,lineEndings:v,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,r),u.setActiveVariant(null),u.selectAnnotation(e,r.id)})(S),I([]),C(null)},onPointerMove:e=>{if(!S.length)return;const t=M(e.x,0,P),n=M(e.y,0,j);C({x:t,y:n})},onPointerCancel:()=>{I([]),C(null)}})),[S,u,P,j]);if(l.useEffect((()=>b?b(z):void 0),[b,z]),!S.length||!A)return null;const E=[...S,A],D=t.patching.lineRectWithEndings(E,x,v);return n.jsx("div",{style:{position:"absolute",left:D.origin.x*r,top:D.origin.y*r,width:D.size.width*r,height:D.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(w,{rect:D,vertices:E,strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:v})})},$=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray,k=h.defaults.lineEndings,b=h.defaults.intent,{register:w}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),j=s/r,S=c/r,[I,A]=l.useState(null),[C,z]=l.useState(null),E=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=P(e.x,0,j),r=P(e.y,0,S);A({x:i,y:r}),z({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!I)return;const t=P(e.x,0,j),n=P(e.y,0,S);z({x:t,y:n})},onPointerUp:(n,i)=>{var r,s;I&&C&&u&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],x,k),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:m,lineEndings:k,intent:b,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,s),u.setActiveVariant(null),u.selectAnnotation(e,s.id)})(I,C),null==(s=null==(r=i.target)?void 0:r.releasePointerCapture)||s.call(r,i.pointerId),A(null),z(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),A(null),z(null)}})),[I,C,u,j,S]);if(l.useEffect((()=>w?w(E):void 0),[w,E]),!I||!C)return null;const D=t.patching.lineRectWithEndings([I,C],x,k);return n.jsx("div",{style:{position:"absolute",left:D.origin.x*r,top:D.origin.y*r,width:D.size.width*r,height:D.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(M,{rect:D,linePoints:{start:I,end:C},strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:k,strokeStyle:v,strokeDashArray:m})})},T=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray,{register:m}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),k=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState([]),[j,S]=l.useState(null),I=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=y/2,u={origin:{x:r-c,y:s-c},size:{width:l-r+y,height:a-s+y}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:u,vertices:t,color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,h),d.setActiveVariant(null),d.selectAnnotation(e,h.id)},A=l.useMemo((()=>({onClick:e=>{const n=k(e.x,0,b),o=k(e.y,0,M);if(((e,n)=>{if(w.length<2)return!1;const o=14/t/2,i=w[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&w.length>=3&&d)return I(w),P([]),void S(null);P((e=>[...e,{x:n,y:o}])),S({x:n,y:o})},onDoubleClick:()=>{w.length>=3&&d?(I(w),P([]),S(null)):(P([]),S(null))},onPointerMove:e=>{if(!w.length)return;const t=k(e.x,0,b),n=k(e.y,0,M);S({x:t,y:n})},onPointerCancel:()=>{P([]),S(null)}})),[w,j,d,b,M]);if(l.useEffect((()=>m?m(A):void 0),[m,A]),!w.length||!j)return null;const C=[...w,j],z=C.map((e=>e.x)),E=C.map((e=>e.y)),D=Math.min(...z),W=Math.min(...E),R=Math.max(...z),B=Math.max(...E),L=y/2,$=D-L,T=W-L,H=R+L-$,F=B+L-T,O=l.useMemo((()=>{let e="";return C.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-$)+" "+(n-T)+" "})),e.trim()}),[C,$,T]),N=w.length>=2?`M ${j.x-$} ${j.y-T} L ${w[0].x-$} ${w[0].y-T}`:null,U=14/t,V=U/2,K=w[0].x-V-$,q=w[0].y-V-T;return n.jsxs("svg",{style:{position:"absolute",left:$*t,top:T*t,width:H*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:H*t,height:F*t,viewBox:`0 0 ${H} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==v?void 0:v.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:x,strokeWidth:y,strokeDasharray:"4,4"}}),w.length>=3&&n.jsx("rect",{x:K,y:q,width:U,height:U,fill:x,opacity:.4,stroke:x,strokeWidth:y/2,style:{pointerEvents:"none"}})]})},H=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c="text"})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.FREETEXT)return null;const g=u.defaults.fontColor??"#000000",p=u.defaults.opacity??1,y=u.defaults.fontSize??12,x=u.defaults.fontFamily,f=u.defaults.backgroundColor??"transparent",v=u.defaults.textAlign,m=u.defaults.verticalAlign,k=u.defaults.content??"Insert text here",{register:b}=i.usePointerHandlers({modeId:"freeText",pageIndex:e}),M=(e,t,n)=>Math.max(t,Math.min(n,e)),w=r/t,P=s/t,[j,S]=l.useState(null),[I,A]=l.useState(null),C=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=M(e.x,0,w),r=M(e.y,0,P);S({x:i,y:r}),A({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!j)return;const t=M(e.x,0,w),n=M(e.y,0,P);A({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;j&&I&&d&&((t,n)=>{const i=Math.min(t.x,n.x),r=Math.min(t.y,n.y),s=Math.max(t.x,n.x)-i,l=Math.max(t.y,n.y)-r;if(s<1||l<1)return;const a={origin:{x:i,y:r},size:{width:s,height:l}},c={type:o.PdfAnnotationSubtype.FREETEXT,rect:a,contents:k,fontColor:g,fontSize:y,fontFamily:x,opacity:p,backgroundColor:f,textAlign:v,verticalAlign:m,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,c),d.setActiveVariant(null),d.selectAnnotation(e,c.id)})(j,I),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),S(null),A(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),S(null),A(null)}})),[j,I,d,w,P]);if(l.useEffect((()=>b?b(C):void 0),[b,C]),!j||!I)return null;const z=Math.min(j.x,I.x),E=Math.min(j.y,I.y),D=Math.max(j.x,I.x)-z,W=Math.max(j.y,I.y)-E;return n.jsx("svg",{style:{position:"absolute",left:z*t,top:E*t,width:D*t,height:W*t,pointerEvents:"none",zIndex:2},width:D*t,height:W*t,viewBox:`0 0 ${D} ${W}`,children:n.jsx("rect",{x:0,y:0,width:D,height:W,fill:"transparent",style:{stroke:g,strokeWidth:1,strokeDasharray:"4,4",cursor:c}})})},F=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c})=>{const{provides:d}=a(),u=l.useRef(null),h=l.useRef(null),[g,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(p)}),[d]),!g.defaults)return null;if(g.defaults.subtype!==o.PdfAnnotationSubtype.STAMP)return null;const{register:y}=i.usePointerHandlers({modeId:"stamp",pageIndex:e}),x=r/t,f=c/t,v=(e,t,n)=>Math.max(t,Math.min(n,e)),[m,k]=l.useState(null),b=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=v(e.x,0,x),i=v(e.y,0,f);k({x:o,y:i}),null==(n=u.current)||n.click()}})),[x,f]);l.useEffect((()=>y?y(b):void 0),[y,b]);return n.jsxs(s.Fragment,{children:[n.jsx("canvas",{style:{display:"none"},ref:h}),n.jsx("input",{ref:u,type:"file",accept:"image/png,image/jpeg",style:{display:"none"},onChange:async t=>{var n;if(!d||!m)return;const i=null==(n=t.currentTarget.files)?void 0:n[0];if(!i)return;const r=await new Promise(((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=URL.createObjectURL(i)})),s=r.naturalWidth,l=r.naturalHeight,a=x,c=f,u=Math.min(1,a/s,c/l),g=s*u,p=l*u,y={origin:{x:v(m.x,0,a-g),y:v(m.y,0,c-p)},size:{width:g,height:p}},b=h.current;if(!b)return;b.width=g,b.height=p;const M=b.getContext("2d");M.drawImage(r,0,0,g,p);const w=M.getImageData(0,0,g,p),P={type:o.PdfAnnotationSubtype.STAMP,flags:["print"],pageIndex:e,id:Date.now()+Math.random(),rect:y};d.createAnnotation(e,P,{imageData:w}),d.setActiveVariant(null),d.selectAnnotation(e,P.id),k(null)}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(E,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(D,{pageIndex:e,scale:t}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(T,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(L,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx($,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(H,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(F,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=a,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id);
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),r=require("@embedpdf/plugin-selection/preact"),s=require("preact"),l=require("preact/hooks"),a=()=>e.useCapability(t.AnnotationPlugin.id);function c({children:e,...t}){const{rect:o,rotation:i}=t,{matrix:r,width:l,height:a}=function(e,t){const{width:n,height:o}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${o})`,width:o,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${o})`,width:n,height:o};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:o,height:n};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:n,height:o}}}(o,i),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:r,transformOrigin:"0 0",width:l,height:a,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation()};return n.jsx(s.Fragment,{children:e({menuWrapperProps:c,matrix:r,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:l,height:a}}})})}function d({rect:e,rotation:t,scale:i,vertices:r,onEdit:a,onCommit:c,handleSize:d=12}){const[u,h]=l.useState(null),g=l.useRef(null),p=l.useRef([]),y=e=>{const n=o.restoreOffset(e,t,i),r=[...p.current];return null!==u&&(r[u]={x:r[u].x+n.x,y:r[u].y+n.y}),r},x=e=>{if(null===u||!g.current)return;const t={x:e.clientX-g.current.x,y:e.clientY-g.current.y};a(y(t))},f=e=>{if(null===u||!g.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-g.current.x,y:e.clientY-g.current.y};c(y(t)),h(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-d/2,l=(t.y-e.origin.y)*i-d/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:d,height:d,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),h(a),g.current={x:e.clientX,y:e.clientY},p.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:x,onPointerUp:f},o);var a}))})}function u({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:s,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,lockAspectRatio:h=!1,currentRect:g,setCurrentRect:p,setCurrentVertices:y,setPreviewObject:x,commit:f}){const v=l.useRef("idle"),b=l.useRef("none"),m=l.useRef(null),k=l.useRef(null),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=t/e,j=n/e,M=(e,t,n)=>{v.current=e,m.current={x:t,y:n},k.current=g},w=(t,n)=>{if("idle"===v.current||!m.current)return;const s={x:t-m.current.x,y:n-m.current.y},{x:l,y:a}=o.restoreOffset(s,i,e),c=((e,t)=>{if(!k.current)return g;let{origin:n,size:o}=k.current,i=n.x,r=n.y,s=o.width,l=o.height;if("dragging"===v.current)i+=e,r+=t;else if("resizing"===v.current&&(b.current.includes("right")?s+=e:b.current.includes("left")&&(i+=e,s-=e),b.current.includes("bottom")?l+=t:b.current.includes("top")&&(r+=t,l-=t),h&&k.current)){const e=k.current.size.width/k.current.size.height,t=i+s,n=r+l;b.current.includes("left")||b.current.includes("right")?l=s/e:s=l*e,b.current.includes("left")&&(i=t-s),b.current.includes("top")&&(r=n-l)}return s<1||l<1?g:(s=P(s,1,S),l=P(l,1,j),i=P(i,0,S-s),r=P(r,0,j-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(l,a);let f={rect:c};d&&(f=d(r.object,{rect:c,direction:"resizing"===v.current?b.current:"bottom-right"}),u&&y(u({...r.object,...f}))),p(f.rect??c),x(f)},A=()=>{if("idle"===v.current)return;const e=b.current||"bottom-right";v.current="idle";let t={rect:g};d&&(t=d(r.object,{rect:g,direction:e})),f(t),m.current=null,k.current=null,b.current="none",x(null)},C=e=>{if(A(),(null==e?void 0:e.currentTarget)&&void 0!==e.pointerId)try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},z=()=>A();return l.useEffect((()=>{v.current="idle",b.current="none",m.current=null,k.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{s&&a&&(e.stopPropagation(),e.preventDefault(),M("dragging",e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>w(e.clientX,e.clientY),onPointerUp:C,onPointerCancel:()=>C(),onLostPointerCapture:()=>C(),onTouchStart:e=>{if(!s||!a)return;e.stopPropagation(),e.preventDefault();const t=e.touches[0];t&&M("dragging",t.clientX,t.clientY)},onTouchMove:e=>{const t=e.touches[0];t&&w(t.clientX,t.clientY)},onTouchEnd:z,onTouchCancel:z},startResize:e=>t=>{s&&c&&(t.stopPropagation(),t.preventDefault(),b.current=e,M("resizing",t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))}}}function h({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function g({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:g,trackedAnnotation:p,children:y,style:x,outlineOffset:f=1,isSelected:v=!1,isDraggable:b=!0,isResizable:m=!0,lockAspectRatio:k=!1,computeVertices:P,computePatch:S,selectionMenu:j,onDoubleClick:M,...w}){const{provides:A}=a(),[C,z]=l.useState(p.object.rect),[I,E]=l.useState((null==P?void 0:P(p.object))??[]),[D,W]=l.useState(null),{rootHandlers:R,startResize:T}=u({scale:e,pageWidth:r,pageHeight:g,rotation:i,tracked:p,isSelected:v,isDraggable:b,isResizable:m,lockAspectRatio:k,computePatch:S,computeVertices:P,currentRect:C,setCurrentRect:z,setCurrentVertices:E,setPreviewObject:W,commit:e=>null==A?void 0:A.updateAnnotation(t,p.object.id,e)});l.useLayoutEffect((()=>{o.rectEquals(p.object.rect,C)||(z(p.object.rect),W((e=>e?{...e,rect:p.object.rect}:null)),E((null==P?void 0:P(p.object))??[]))}),[p]);const B=D?{...p.object,...D}:p.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...R,...(L=M,L?{onDblClick:L}:{}),style:{position:"absolute",outline:v?"1px solid #007ACC":"none",outlineOffset:v?`${f}px`:"0px",left:C.origin.x*e+"px",top:C.origin.y*e+"px",width:C.size.width*e+"px",height:C.size.height*e+"px",pointerEvents:v?"auto":"none",touchAction:v?"auto":"none",cursor:v&&b?"move":"default",...v&&{zIndex:3},...x},...w,children:["function"==typeof y?y(B):y,v&&I.length>0&&n.jsx(d,{rect:C,rotation:i,scale:e,vertices:I,onEdit:e=>{if(E(e),S){const t=S(p.object,{rect:C,vertices:e});W(t),z(t.rect||C)}},onCommit:e=>{if(A&&S){const n=S(p.object,{rect:C,vertices:e});A.updateAnnotation(t,p.object.id,n)}}}),v&&m&&n.jsx(h,{rotation:i,outlineOffset:f,startResize:T})]}),n.jsx(c,{rect:{origin:{x:C.origin.x*e,y:C.origin.y*e},size:{width:C.size.width*e,height:C.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>j&&j({annotation:p,selected:v,rect:e,menuWrapperProps:t})})]});var L}function p({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function v({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:r,rect:s,scale:a,onClick:c}){const d=l.useMemo((()=>r.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-s.origin.x,r=n-s.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}))),[r,s]),u=s.size.width*a,h=s.size.height*a;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${s.size.width} ${s.size.height}`,children:d.map(((r,s)=>n.jsx("path",{d:r,fill:"none",opacity:o,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},s)))})}function b({isSelected:e,color:t="#000000",strokeColor:i,opacity:r=1,strokeWidth:s,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:g,height:p,x:y,y:x}=l.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-s,0),height:Math.max(t-s,0),x:s/2,y:s/2}}),[d,s]),f=(g+s)*u,v=(p+s)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${g+s} ${p+s}`,children:n.jsx("rect",{x:y,y:x,width:g,height:p,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:s,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function m({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:g,height:p,cx:y,cy:x,rx:f,ry:v}=l.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),b=g*d,m=p*d;return n.jsx("svg",{style:{position:"absolute",width:b,height:m,pointerEvents:"none",zIndex:2},width:b,height:m,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const k=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function P({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:s="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:y}){const{x1:x,y1:f,x2:v,y2:b}=l.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=l.useMemo((()=>{const e=Math.atan2(b-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,b)}}),[h,r,x,f,v,b]),k=d.size.width*g,P=d.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:k,height:P,pointerEvents:"none",zIndex:2,overflow:"visible"},width:k,height:P,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:b,opacity:i,onPointerDown:p,onTouchStart:p,style:{cursor:y?"move":"pointer",pointerEvents:y?"none":"visibleStroke",stroke:s,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:s,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&n.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:s,onPointerDown:p,onTouchStart:p,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function S({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=l.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),p=l.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[g]),y=l.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[1],g[0]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:s,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function j({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g}){const p=l.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=l.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[p]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onPointerDown:g,onTouchStart:g,opacity:s,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const M=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},w=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},A=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function C({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:s,onClick:c}){const d=l.useRef(null),{provides:u}=a();l.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]);return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*s,height:i.object.rect.size.height*s,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:c,onTouchStart:c,children:n.jsx("span",{ref:d,onBlur:()=>{u&&d.current&&u.updateAnnotation(r,i.object.id,{contents:d.current.innerText})},style:{color:i.object.fontColor,fontSize:i.object.fontSize*s,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:"100%",height:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer"},contentEditable:t,suppressContentEditableWarning:!0,children:i.object.contents})})}function z({pageIndex:e,annotation:t,scaleFactor:i=1,style:r,...c}){const{provides:d}=a(),[u,h]=l.useState(null),g=l.useRef(null),{width:p,height:y}=t.rect.size;l.useEffect((()=>{if(d){const n=d.renderAnnotation({pageIndex:e,annotation:t,scaleFactor:i,dpr:window.devicePixelRatio});return n.wait((e=>{const t=URL.createObjectURL(e);h(t),g.current=t}),o.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,d,t.id,p,y]);return n.jsx(s.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...c,style:{width:"100%",height:"100%",...r||{}}})})}function I({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:r}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:r,onTouchStart:r,children:n.jsx(z,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function E(e){const{pageIndex:c,scale:d,selectionMenu:u}=e,{provides:h}=a(),{provides:z}=r.useSelectionCapability(),[E,D]=l.useState([]),{register:W}=i.usePointerHandlers({pageIndex:c}),[R,T]=l.useState(null),[B,L]=l.useState(null);l.useEffect((()=>{h&&h.onStateChange((e=>{D(t.getAnnotationsByPageIndex(e,c)),T(t.getSelectedAnnotationByPageIndex(e,c))}))}),[h]);const $=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&h&&(h.deselectAnnotation(),L(null))}})),[h]),H=l.useCallback(((e,t)=>{e.stopPropagation(),h&&z&&(h.selectAnnotation(c,t.object.id),z.clear(),L(null))}),[h,z,c]);return l.useEffect((()=>W($)),[W,$]),n.jsx(n.Fragment,{children:E.map((i=>{const r=(null==R?void 0:R.object.id)===i.object.id,l=B===i.object.id;return t.isInk(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,computePatch:k,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{isSelected:r,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isSquare(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isCircle(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(p,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,rect:e.rect,onClick:e=>H(e,i)})},i.object.id):t.isLine(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:M,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:w,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(S,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:d,onClick:e=>H(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computeVertices:e=>e.vertices,computePatch:A,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(j,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>H(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,outlineOffset:6,onDoubleClick:e=>{e.stopPropagation(),L(i.object.id)},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(C,{isSelected:r,isEditing:l,annotation:{...i,object:e},pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id):t.isStamp(i)?n.jsx(g,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(I,{isSelected:r,annotation:i,pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id):null}))})}function D({pageIndex:e,scale:t}){var i,s,c,d,u,h,g,v,b,m,k,P;const{provides:S}=r.useSelectionCapability(),{provides:j}=a(),[M,w]=l.useState([]),[A,C]=l.useState(null),[z,I]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{w(S.getHighlightRectsForPage(e)),C(S.getBoundingRectForPage(e))}))}),[S,e]),l.useEffect((()=>{if(!j)return;return j.onActiveToolChange(I)}),[j]),!A)return null;if(!z.defaults)return null;switch(z.defaults.subtype){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=z.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(s=z.defaults)?void 0:s.color,opacity:null==(c=z.defaults)?void 0:c.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=z.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(u=z.defaults)?void 0:u.color,opacity:null==(h=z.defaults)?void 0:h.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(g=z.defaults)?void 0:g.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(v=z.defaults)?void 0:v.color,opacity:null==(b=z.defaults)?void 0:b.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(m=z.defaults)?void 0:m.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(k=z.defaults)?void 0:k.color,opacity:null==(P=z.defaults)?void 0:P.opacity,rects:M,scale:t})});default:return null}}const W=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s})=>{var c,d,u,h,g;const{provides:p}=a(),[y,x]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!p)return;return p.onActiveToolChange(x)}),[p]),!y.defaults)return null;if(y.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const f=(null==(c=y.defaults)?void 0:c.color)??"#000000",v=(null==(d=y.defaults)?void 0:d.opacity)??1,b=(null==(u=y.defaults)?void 0:u.strokeWidth)??2,m=(null==(h=y.defaults)?void 0:h.blendMode)??o.PdfBlendMode.Normal,k=null==(g=y.defaults)?void 0:g.intent,{register:P}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),S=(e,t,n)=>Math.max(t,Math.min(n,e)),[j,M]=l.useState([]),[w,A]=l.useState(!1),C=l.useRef(null),z=r/t,I=s/t,E=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=S(e.x,0,z),r=S(e.y,0,I);A(!0),C.current?(clearTimeout(C.current),C.current=null,M((e=>[...e,{points:[{x:i,y:r}]}]))):M([{points:[{x:i,y:r}]}]),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=S(e.x,0,z),n=S(e.y,0,I);M((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i,r;A(!1),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),C.current&&clearTimeout(C.current),C.current=setTimeout((()=>{if(j.length&&p){const t=j.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),b/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:k,blendMode:m,rect:n,inkList:j,color:f,opacity:v,strokeWidth:b,created:new Date,pageIndex:e,id:o.uuidV4()};p.createAnnotation(e,i),p.setActiveVariant(null),p.selectAnnotation(e,i.id)}M([]),C.current=null}),3e3)},onPointerCancel:(e,t)=>{var n,o;A(!1),null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),M([]),C.current&&(clearTimeout(C.current),C.current=null)}})),[z,I,j,p,e,f,v,b,w]);if(l.useEffect((()=>{if(P)return P(E)}),[P,E]),l.useEffect((()=>()=>{C.current&&clearTimeout(C.current)}),[]),!j.length)return null;const D=j.flatMap((e=>e.points));if(!D.length)return null;const W=o.expandRect(o.rectFromPoints(D),b/2),R=j.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:R.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:v,style:{stroke:f,strokeWidth:b,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:b}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),k=r/t,P=s/t,[S,j]=l.useState(null),[M,w]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,k),r=m(e.y,0,P);j({x:i,y:r}),w({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!S)return;const t=m(e.x,0,k),n=m(e.y,0,P);w({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(S&&M&&d){const t=Math.min(S.x,M.x),n=Math.min(S.y,M.y),i=Math.max(S.x,M.x),r=Math.max(S.y,M.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,created:new Date,pageIndex:e,id:o.uuidV4()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),j(null),w(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),j(null),w(null)}})),[S,M,d,e,k,P,g,p,y]);if(l.useEffect((()=>b?b(A):void 0),[b,A]),!S||!M)return null;const C=Math.min(S.x,M.x),z=Math.min(S.y,M.y),I=Math.max(S.x,M.x),E=Math.max(S.y,M.y),D=y/2,W=C-D,R=z-D,T=I-C,B=E-z,L=T+y,$=B+y,H=D+T/2,F=D+B/2,O=T/2,N=B/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("ellipse",{cx:H,cy:F,rx:O,ry:N,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},T=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:b}=i.usePointerHandlers({modeId:"square",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),k=r/t,P=s/t,[S,j]=l.useState(null),[M,w]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,k),r=m(e.y,0,P);j({x:i,y:r}),w({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!S)return;const t=m(e.x,0,k),n=m(e.y,0,P);w({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(S&&M&&d){const t=Math.min(S.x,M.x),n=Math.min(S.y,M.y),i=Math.max(S.x,M.x),r=Math.max(S.y,M.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:o.uuidV4(),created:new Date};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),j(null),w(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),j(null),w(null)}})),[S,M,d,e,k,P,g,p,y]);if(l.useEffect((()=>b?b(A):void 0),[b,A]),!S||!M)return null;const C=Math.min(S.x,M.x),z=Math.min(S.y,M.y),I=Math.max(S.x,M.x),E=Math.max(S.y,M.y),D=y/2,W=C-D,R=z-D,T=I-C,B=E-z,L=T+y,$=B+y;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("rect",{x:D,y:D,width:T,height:B,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},B=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.lineEndings,b=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray,{register:k}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),j=s/r,M=c/r,[w,A]=l.useState([]),[C,z]=l.useState(null),I=l.useMemo((()=>({onClick:e=>{const t=P(e.x,0,j),n=P(e.y,0,M);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{w.length>=1&&u&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,x,v),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:b,strokeDashArray:m,lineEndings:v,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,r),u.setActiveVariant(null),u.selectAnnotation(e,r.id)})(w),A([]),z(null)},onPointerMove:e=>{if(!w.length)return;const t=P(e.x,0,j),n=P(e.y,0,M);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[w,u,j,M]);if(l.useEffect((()=>k?k(I):void 0),[k,I]),!w.length||!C)return null;const E=[...w,C],D=t.patching.lineRectWithEndings(E,x,v);return n.jsx("div",{style:{position:"absolute",left:D.origin.x*r,top:D.origin.y*r,width:D.size.width*r,height:D.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(S,{rect:D,vertices:E,strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:v})})},L=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,g]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray,m=h.defaults.lineEndings,k=h.defaults.intent,{register:S}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),j=(e,t,n)=>Math.max(t,Math.min(n,e)),M=s/r,w=c/r,[A,C]=l.useState(null),[z,I]=l.useState(null),E=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=j(e.x,0,M),r=j(e.y,0,w);C({x:i,y:r}),I({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!A)return;const t=j(e.x,0,M),n=j(e.y,0,w);I({x:t,y:n})},onPointerUp:(n,i)=>{var r,s;A&&z&&u&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],x,m),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,lineEndings:m,intent:k,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,s),u.setActiveVariant(null),u.selectAnnotation(e,s.id)})(A,z),null==(s=null==(r=i.target)?void 0:r.releasePointerCapture)||s.call(r,i.pointerId),C(null),I(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),C(null),I(null)}})),[A,z,u,M,w]);if(l.useEffect((()=>S?S(E):void 0),[S,E]),!A||!z)return null;const D=t.patching.lineRectWithEndings([A,z],x,m);return n.jsx("div",{style:{position:"absolute",left:D.origin.x*r,top:D.origin.y*r,width:D.size.width*r,height:D.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(P,{rect:D,linePoints:{start:A,end:z},strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:m,strokeStyle:v,strokeDashArray:b})})},$=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray,{register:b}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),k=r/t,P=s/t,[S,j]=l.useState([]),[M,w]=l.useState(null),A=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=y/2,u={origin:{x:r-c,y:s-c},size:{width:l-r+y,height:a-s+y}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:u,vertices:t,color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:o.uuidV4(),created:new Date};d.createAnnotation(e,h),d.setActiveVariant(null),d.selectAnnotation(e,h.id)},C=l.useMemo((()=>({onClick:e=>{const n=m(e.x,0,k),o=m(e.y,0,P);if(((e,n)=>{if(S.length<2)return!1;const o=14/t/2,i=S[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&S.length>=3&&d)return A(S),j([]),void w(null);j((e=>[...e,{x:n,y:o}])),w({x:n,y:o})},onDoubleClick:()=>{S.length>=3&&d?(A(S),j([]),w(null)):(j([]),w(null))},onPointerMove:e=>{if(!S.length)return;const t=m(e.x,0,k),n=m(e.y,0,P);w({x:t,y:n})},onPointerCancel:()=>{j([]),w(null)}})),[S,M,d,k,P]);if(l.useEffect((()=>b?b(C):void 0),[b,C]),!S.length||!M)return null;const z=[...S,M],I=z.map((e=>e.x)),E=z.map((e=>e.y)),D=Math.min(...I),W=Math.min(...E),R=Math.max(...I),T=Math.max(...E),B=y/2,L=D-B,$=W-B,H=R+B-L,F=T+B-$,O=l.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-$)+" "})),e.trim()}),[z,L,$]),N=S.length>=2?`M ${M.x-L} ${M.y-$} L ${S[0].x-L} ${S[0].y-$}`:null,V=14/t,U=V/2,Y=S[0].x-U-L,K=S[0].y-U-$;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:$*t,width:H*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:H*t,height:F*t,viewBox:`0 0 ${H} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==v?void 0:v.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:x,strokeWidth:y,strokeDasharray:"4,4"}}),S.length>=3&&n.jsx("rect",{x:Y,y:K,width:V,height:V,fill:x,opacity:.4,stroke:x,strokeWidth:y/2,style:{pointerEvents:"none"}})]})},H=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c="text"})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.FREETEXT)return null;const g=u.defaults.fontColor??"#000000",p=u.defaults.opacity??1,y=u.defaults.fontSize??12,x=u.defaults.fontFamily,f=u.defaults.backgroundColor??"transparent",v=u.defaults.textAlign,b=u.defaults.verticalAlign,m=u.defaults.content??"Insert text here",{register:k}=i.usePointerHandlers({modeId:"freeText",pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=r/t,j=s/t,[M,w]=l.useState(null),[A,C]=l.useState(null),z=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=P(e.x,0,S),r=P(e.y,0,j);w({x:i,y:r}),C({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!M)return;const t=P(e.x,0,S),n=P(e.y,0,j);C({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;M&&A&&d&&((t,n)=>{const i=Math.min(t.x,n.x),r=Math.min(t.y,n.y),s=Math.max(t.x,n.x)-i,l=Math.max(t.y,n.y)-r;if(s<1||l<1)return;const a={origin:{x:i,y:r},size:{width:s,height:l}},c={type:o.PdfAnnotationSubtype.FREETEXT,rect:a,contents:m,fontColor:g,fontSize:y,fontFamily:x,opacity:p,backgroundColor:f,textAlign:v,verticalAlign:b,pageIndex:e,id:o.uuidV4(),created:new Date};d.createAnnotation(e,c),d.setActiveVariant(null),d.selectAnnotation(e,c.id)})(M,A),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),w(null),C(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),w(null),C(null)}})),[M,A,d,S,j]);if(l.useEffect((()=>k?k(z):void 0),[k,z]),!M||!A)return null;const I=Math.min(M.x,A.x),E=Math.min(M.y,A.y),D=Math.max(M.x,A.x)-I,W=Math.max(M.y,A.y)-E;return n.jsx("svg",{style:{position:"absolute",left:I*t,top:E*t,width:D*t,height:W*t,pointerEvents:"none",zIndex:2},width:D*t,height:W*t,viewBox:`0 0 ${D} ${W}`,children:n.jsx("rect",{x:0,y:0,width:D,height:W,fill:"transparent",style:{stroke:g,strokeWidth:1,strokeDasharray:"4,4",cursor:c}})})},F=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c})=>{const{provides:d}=a(),u=l.useRef(null),h=l.useRef(null),[g,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(p)}),[d]),!g.defaults)return null;if(g.defaults.subtype!==o.PdfAnnotationSubtype.STAMP)return null;const{register:y}=i.usePointerHandlers({modeId:"stamp",pageIndex:e}),x=r/t,f=c/t,v=(e,t,n)=>Math.max(t,Math.min(n,e)),[b,m]=l.useState(null),k=l.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=v(e.x,0,x),i=v(e.y,0,f);m({x:o,y:i}),null==(n=u.current)||n.click()}})),[x,f]);l.useEffect((()=>y?y(k):void 0),[y,k]);return n.jsxs(s.Fragment,{children:[n.jsx("canvas",{style:{display:"none"},ref:h}),n.jsx("input",{ref:u,type:"file",accept:"image/png,image/jpeg",style:{display:"none"},onChange:async t=>{var n;if(!d||!b)return;const i=null==(n=t.currentTarget.files)?void 0:n[0];if(!i)return;const r=await new Promise(((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=URL.createObjectURL(i)})),s=r.naturalWidth,l=r.naturalHeight,a=x,c=f,u=Math.min(1,a/s,c/l),g=s*u,p=l*u,y={origin:{x:v(b.x,0,a-g),y:v(b.y,0,c-p)},size:{width:g,height:p}},k=h.current;if(!k)return;k.width=g,k.height=p;const P=k.getContext("2d");P.drawImage(r,0,0,g,p);const S=P.getImageData(0,0,g,p),j={type:o.PdfAnnotationSubtype.STAMP,flags:["print"],pageIndex:e,id:o.uuidV4(),created:new Date,rect:y};d.createAnnotation(e,j,{imageData:S}),d.setActiveVariant(null),d.selectAnnotation(e,j.id),m(null)}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(E,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(D,{pageIndex:e,scale:t}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(T,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx($,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(L,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(H,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(F,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=a,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id);
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|