@embedpdf/plugin-annotation 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -13
- package/dist/index.js.map +1 -1
- package/dist/lib/tools/default-tools.d.ts +42 -0
- package/dist/lib/tools/types.d.ts +4 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +76 -40
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +76 -40
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +4 -2
- package/dist/shared-preact/components/annotation-layer.d.ts +5 -2
- package/dist/shared-preact/components/annotations.d.ts +3 -1
- package/dist/shared-preact/components/text-markup/highlight.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/underline.d.ts +3 -3
- package/dist/shared-preact/types.d.ts +17 -0
- package/dist/shared-react/components/annotation-container.d.ts +4 -2
- package/dist/shared-react/components/annotation-layer.d.ts +5 -2
- package/dist/shared-react/components/annotations.d.ts +3 -1
- package/dist/shared-react/components/text-markup/highlight.d.ts +3 -3
- package/dist/shared-react/components/text-markup/squiggly.d.ts +3 -3
- package/dist/shared-react/components/text-markup/strikeout.d.ts +3 -3
- package/dist/shared-react/components/text-markup/underline.d.ts +3 -3
- package/dist/shared-react/types.d.ts +17 -0
- package/package.json +12 -11
|
@@ -6,7 +6,10 @@ export declare const defaultTools: ({
|
|
|
6
6
|
interaction: {
|
|
7
7
|
exclusive: false;
|
|
8
8
|
textSelection: true;
|
|
9
|
+
isDraggable: false;
|
|
10
|
+
isResizable: false;
|
|
9
11
|
cursor?: undefined;
|
|
12
|
+
lockAspectRatio?: undefined;
|
|
10
13
|
};
|
|
11
14
|
defaults: {
|
|
12
15
|
type: PdfAnnotationSubtype.HIGHLIGHT;
|
|
@@ -34,7 +37,10 @@ export declare const defaultTools: ({
|
|
|
34
37
|
interaction: {
|
|
35
38
|
exclusive: false;
|
|
36
39
|
textSelection: true;
|
|
40
|
+
isDraggable: false;
|
|
41
|
+
isResizable: false;
|
|
37
42
|
cursor?: undefined;
|
|
43
|
+
lockAspectRatio?: undefined;
|
|
38
44
|
};
|
|
39
45
|
defaults: {
|
|
40
46
|
type: PdfAnnotationSubtype.UNDERLINE;
|
|
@@ -62,7 +68,10 @@ export declare const defaultTools: ({
|
|
|
62
68
|
interaction: {
|
|
63
69
|
exclusive: false;
|
|
64
70
|
textSelection: true;
|
|
71
|
+
isDraggable?: undefined;
|
|
72
|
+
isResizable?: undefined;
|
|
65
73
|
cursor?: undefined;
|
|
74
|
+
lockAspectRatio?: undefined;
|
|
66
75
|
};
|
|
67
76
|
defaults: {
|
|
68
77
|
type: PdfAnnotationSubtype.STRIKEOUT;
|
|
@@ -90,7 +99,10 @@ export declare const defaultTools: ({
|
|
|
90
99
|
interaction: {
|
|
91
100
|
exclusive: false;
|
|
92
101
|
textSelection: true;
|
|
102
|
+
isDraggable: false;
|
|
103
|
+
isResizable: false;
|
|
93
104
|
cursor?: undefined;
|
|
105
|
+
lockAspectRatio?: undefined;
|
|
94
106
|
};
|
|
95
107
|
defaults: {
|
|
96
108
|
type: PdfAnnotationSubtype.SQUIGGLY;
|
|
@@ -118,6 +130,9 @@ export declare const defaultTools: ({
|
|
|
118
130
|
interaction: {
|
|
119
131
|
exclusive: false;
|
|
120
132
|
cursor: string;
|
|
133
|
+
isDraggable: true;
|
|
134
|
+
isResizable: true;
|
|
135
|
+
lockAspectRatio: false;
|
|
121
136
|
textSelection?: undefined;
|
|
122
137
|
};
|
|
123
138
|
defaults: {
|
|
@@ -146,6 +161,9 @@ export declare const defaultTools: ({
|
|
|
146
161
|
interaction: {
|
|
147
162
|
exclusive: false;
|
|
148
163
|
cursor: string;
|
|
164
|
+
isDraggable: true;
|
|
165
|
+
isResizable: true;
|
|
166
|
+
lockAspectRatio: false;
|
|
149
167
|
textSelection?: undefined;
|
|
150
168
|
};
|
|
151
169
|
defaults: {
|
|
@@ -174,6 +192,9 @@ export declare const defaultTools: ({
|
|
|
174
192
|
interaction: {
|
|
175
193
|
exclusive: false;
|
|
176
194
|
cursor: string;
|
|
195
|
+
isDraggable: true;
|
|
196
|
+
isResizable: true;
|
|
197
|
+
lockAspectRatio: false;
|
|
177
198
|
textSelection?: undefined;
|
|
178
199
|
};
|
|
179
200
|
defaults: {
|
|
@@ -211,6 +232,9 @@ export declare const defaultTools: ({
|
|
|
211
232
|
interaction: {
|
|
212
233
|
exclusive: false;
|
|
213
234
|
cursor: string;
|
|
235
|
+
isDraggable: true;
|
|
236
|
+
isResizable: true;
|
|
237
|
+
lockAspectRatio: false;
|
|
214
238
|
textSelection?: undefined;
|
|
215
239
|
};
|
|
216
240
|
defaults: {
|
|
@@ -248,6 +272,9 @@ export declare const defaultTools: ({
|
|
|
248
272
|
interaction: {
|
|
249
273
|
exclusive: false;
|
|
250
274
|
cursor: string;
|
|
275
|
+
isDraggable: true;
|
|
276
|
+
isResizable: false;
|
|
277
|
+
lockAspectRatio: false;
|
|
251
278
|
textSelection?: undefined;
|
|
252
279
|
};
|
|
253
280
|
defaults: {
|
|
@@ -282,6 +309,9 @@ export declare const defaultTools: ({
|
|
|
282
309
|
interaction: {
|
|
283
310
|
exclusive: false;
|
|
284
311
|
cursor: string;
|
|
312
|
+
isDraggable: true;
|
|
313
|
+
isResizable: false;
|
|
314
|
+
lockAspectRatio: false;
|
|
285
315
|
textSelection?: undefined;
|
|
286
316
|
};
|
|
287
317
|
defaults: {
|
|
@@ -319,6 +349,9 @@ export declare const defaultTools: ({
|
|
|
319
349
|
interaction: {
|
|
320
350
|
exclusive: false;
|
|
321
351
|
cursor: string;
|
|
352
|
+
isDraggable: true;
|
|
353
|
+
isResizable: false;
|
|
354
|
+
lockAspectRatio: false;
|
|
322
355
|
textSelection?: undefined;
|
|
323
356
|
};
|
|
324
357
|
defaults: {
|
|
@@ -347,6 +380,9 @@ export declare const defaultTools: ({
|
|
|
347
380
|
interaction: {
|
|
348
381
|
exclusive: false;
|
|
349
382
|
cursor: string;
|
|
383
|
+
isDraggable: true;
|
|
384
|
+
isResizable: false;
|
|
385
|
+
lockAspectRatio: false;
|
|
350
386
|
textSelection?: undefined;
|
|
351
387
|
};
|
|
352
388
|
defaults: {
|
|
@@ -375,6 +411,9 @@ export declare const defaultTools: ({
|
|
|
375
411
|
interaction: {
|
|
376
412
|
exclusive: false;
|
|
377
413
|
cursor: string;
|
|
414
|
+
isDraggable: true;
|
|
415
|
+
isResizable: true;
|
|
416
|
+
lockAspectRatio: false;
|
|
378
417
|
textSelection?: undefined;
|
|
379
418
|
};
|
|
380
419
|
defaults: {
|
|
@@ -412,6 +451,9 @@ export declare const defaultTools: ({
|
|
|
412
451
|
interaction: {
|
|
413
452
|
exclusive: false;
|
|
414
453
|
cursor: string;
|
|
454
|
+
isDraggable: true;
|
|
455
|
+
isResizable: true;
|
|
456
|
+
lockAspectRatio: true;
|
|
415
457
|
textSelection?: undefined;
|
|
416
458
|
};
|
|
417
459
|
defaults: {
|
|
@@ -84,6 +84,10 @@ export type AnnotationTool<T extends PdfAnnotationObject = PdfAnnotationObject>
|
|
|
84
84
|
cursor?: string;
|
|
85
85
|
/** If true, this interaction mode is activated by selecting text. */
|
|
86
86
|
textSelection?: boolean;
|
|
87
|
+
/** Annotation interaction behaviors */
|
|
88
|
+
isDraggable?: boolean;
|
|
89
|
+
isResizable?: boolean;
|
|
90
|
+
lockAspectRatio?: boolean;
|
|
87
91
|
};
|
|
88
92
|
/** Tool-specific behavior settings that override plugin defaults */
|
|
89
93
|
behavior?: {
|
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"),s=require("@embedpdf/plugin-selection/preact"),r=require("preact"),l=require("preact/hooks"),a=require("@embedpdf/utils/preact"),d=()=>e.usePlugin(t.AnnotationPlugin.id),c=()=>e.useCapability(t.AnnotationPlugin.id),u={};function h({scale:e,pageIndex:t,rotation:o,pageWidth:i,pageHeight:s,trackedAnnotation:r,children:d,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:y,selectionMenu:f,outlineOffset:b=1,onDoubleClick:v,zIndex:j=1,resizeUI:m,vertexUI:k,selectionOutlineColor:S="#007ACC",...M}){const[w,P]=l.useState(r.object),{provides:C}=c(),z=l.useRef(null),A=w?{...r.object,...w}:r.object,I=(null==m?void 0:m.color)??"#007ACC",D=(null==k?void 0:k.color)??"#007ACC",E=(null==m?void 0:m.size)??12,B=(null==k?void 0:k.size)??12,{dragProps:R,vertices:T,resize:$}=a.useInteractionHandles({controller:{element:A.rect,vertices:null==y?void 0:y.extractVertices(A),constraints:{minWidth:10,minHeight:10,boundingBox:{width:i/e,height:s/e}},maintainAspectRatio:p,pageRotation:o,scale:e,enabled:u,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(z.current=A);const o=e.transformData.type,i=z.current??A,s=e.transformData.changes.vertices?null==y?void 0:y.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},l=null==C?void 0:C.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});l&&P((e=>({...e,...l}))),"end"===e.state&&l&&(z.current=null,null==C||C.updateAnnotation(t,r.object.id,l))}},resizeUI:{handleSize:E,spacing:b,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:B,zIndex:j+2},includeVertices:!!y}),L=a.useDoublePressProps(v);return l.useEffect((()=>{P(r.object)}),[r.object]),n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...h&&u?R:{},...L,style:{position:"absolute",left:A.rect.origin.x*e,top:A.rect.origin.y*e,width:A.rect.size.width*e,height:A.rect.size.height*e,outline:u?`1px solid ${S}`:"none",outlineOffset:u?`${b}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...M,children:["function"==typeof d?d(A):d,u&&g&&$.map((({key:e,...t})=>(null==m?void 0:m.component)?m.component({key:e,...t,backgroundColor:I}):n.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&T.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:D}):n.jsx("div",{...t,style:{...t.style,backgroundColor:D}},e)))]}),n.jsx(a.CounterRotate,{rect:{origin:{x:A.rect.origin.x*e,y:A.rect.origin.y*e},size:{width:A.rect.size.width*e,height:A.rect.size.height*e}},rotation:o,children:({rect:e,menuWrapperProps:t})=>f&&f({annotation:r,selected:u,rect:e,menuWrapperProps:t})})]})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l},...a},d)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:d,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:d,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function y({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=2*s,c=6*s,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*d}" viewBox="0 0 ${c} ${2*d}">\n <path d="M0 ${d} Q ${c/4} 0 ${c/2} ${d} T ${c} ${d}"\n fill="none" stroke="${e}" stroke-width="${d}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*s,top:(i?e.origin.y-i.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*d,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*d}px`,opacity:t,pointerEvents:"none"}})},o)))})}function f({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:s,rect:r,scale:a,onClick:d}){const c=l.useMemo((()=>s.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()}))),[s,r]),u=r.size.width*a,h=r.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 ${r.size.width} ${r.size.height}`,children:c.map(((s,r)=>n.jsx("path",{d:s,fill:"none",opacity:o,onPointerDown:d,onTouchStart:d,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function b({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:r,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,scale:u,onClick:h}){const{width:g,height:p,x:x,y:y}=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)*u,b=(p+r)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:b,pointerEvents:"none",zIndex:2},width:f,height:b,viewBox:`0 0 ${g+r} ${p+r}`,children:n.jsx("rect",{x:x,y:y,width:g,height:p,fill:t,opacity:s,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:r,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}function v({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:r=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:d,scale:c,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:y,rx:f,ry:b}=l.useMemo((()=>{const e=d.size.width,t=d.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}}),[d,s]),v=g*c,j=p*c;return n.jsx("svg",{style:{position:"absolute",width:v,height:j,pointerEvents:"none",zIndex:2},width:v,height:j,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:x,cy:y,rx:f,ry:b,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...r===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function j({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:r="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:y,y1:f,x2:b,y2:v}=l.useMemo((()=>({x1:u.start.x-c.origin.x,y1:u.start.y-c.origin.y,x2:u.end.x-c.origin.x,y2:u.end.y-c.origin.y})),[u,c]),j=l.useMemo((()=>{const e=Math.atan2(v-f,b-y);return{start:t.patching.createEnding(null==h?void 0:h.start,s,e+Math.PI,y,f),end:t.patching.createEnding(null==h?void 0:h.end,s,e,b,v)}}),[h,s,y,f,b,v]),m=c.size.width*g,k=c.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:m,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:k,viewBox:`0 0 ${c.size.width} ${c.size.height}`,children:[n.jsx("line",{x1:y,y1:f,x2:b,y2:v,opacity:i,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:r,strokeWidth:s,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),j.start&&n.jsx("path",{d:j.start.d,transform:j.start.transform,onPointerDown:p,onTouchStart:p,stroke:r,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.start.filled?e:"none"}),j.end&&n.jsx("path",{d:j.end.d,transform:j.end.transform,stroke:r,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.end.filled?e:"none"})]})}function m({rect:e,vertices:o,color:i="transparent",strokeColor:s="#000000",opacity:r=1,strokeWidth:a,scale:d,isSelected:c,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]),x=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[0],g[1]),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]),y=e.size.width*d,f=e.size.height*d;return n.jsxs("svg",{style:{position:"absolute",width:y,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:y,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:r,style:{fill:"none",stroke:s??i,strokeWidth:a,cursor:c?"move":"pointer",pointerEvents:c?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&n.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:s,fill:x.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&n.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:s,fill:x.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:r=1,strokeWidth:a,strokeStyle:d=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const y=p?[...t,p]:t,f=l.useMemo((()=>y.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[y,e]),b=l.useMemo((()=>{if(!f.length)return"";const[e,...t]=f,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[f,p]),v=p&&t.length>0,j=e.size.width*u,m=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:j,height:m,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:m,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:b,onPointerDown:g,onTouchStart:g,opacity:r,style:{fill:p?"none":i,stroke:s??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...d===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),v&&t.length>1&&n.jsx("path",{d:`M ${f[f.length-1].x} ${f[f.length-1].y} L ${f[0].x} ${f[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),v&&t.length>=2&&n.jsx("rect",{x:f[0].x-x/u/2,y:f[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:i,pageIndex:s,scale:r,onClick:a}){const d=l.useRef(null),{provides:h}=c(),[g,p]=l.useState(!1);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]),l.useLayoutEffect((()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}}),[]);const x=i.object.fontSize*r,y=g&&t&&x>0&&x<16,f=y?16:x,b=y?x/16:1,v=y?100/b:100;return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*r,height:i.object.rect.size.height*r,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:d,onBlur:()=>{h&&d.current&&h.updateAnnotation(s,i.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:f,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:y?`${v}%`:"100%",height:y?`${v}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:y?`scale(${b})`:void 0,transformOrigin:"top left"},contentEditable:t,...u,children:i.object.contents})})}function M({pageIndex:e,annotation:t,scaleFactor:i=1,style:s,...a}){const{provides:d}=c(),[u,h]=l.useState(null),g=l.useRef(null),{width:p,height:x}=t.rect.size;l.useEffect((()=>{if(d){const n=d.renderAnnotation({pageIndex:e,annotation:t,options:{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,x]);return n.jsx(r.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...a,style:{width:"100%",height:"100%",...s||{}}})})}function w({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:s}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:n.jsx(M,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function P(e){const{pageIndex:a,scale:d,selectionMenu:u}=e,{provides:M}=c(),{provides:P}=s.useSelectionCapability(),[C,z]=l.useState([]),{register:A}=i.usePointerHandlers({pageIndex:a}),[I,D]=l.useState(null),[E,B]=l.useState(null);l.useEffect((()=>{M&&M.onStateChange((e=>{z(t.getAnnotationsByPageIndex(e,a)),D(t.getSelectedAnnotationByPageIndex(e,a))}))}),[M]);const R=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&M&&(M.deselectAnnotation(),B(null))}})),[M]),T=l.useCallback(((e,t)=>{e.stopPropagation(),M&&P&&(M.selectAnnotation(a,t.object.id),P.clear(),t.object.id!==E&&B(null))}),[M,P,E,a]);return l.useEffect((()=>A(R)),[A,R]),n.jsx(n.Fragment,{children:C.map((i=>{const s=(null==I?void 0:I.object.id)===i.object.id,l=E===i.object.id;return t.isInk(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isSquare(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isCircle(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(p,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:u,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{...e,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isLine(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(j,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(m,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:u,vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(k,{...e,isSelected:s,scale:d,onClick:e=>T(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!l,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),B(i.object.id)},...e,children:e=>n.jsx(S,{isSelected:s,isEditing:l,annotation:{...i,object:e},pageIndex:a,scale:d,onClick:e=>T(e,i)})},i.object.id):t.isStamp(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:u,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(w,{isSelected:s,annotation:i,pageIndex:a,scale:d,onClick:e=>T(e,i)})},i.object.id):null}))})}function C({pageIndex:e,scale:t}){var i,r,a,d,u,h,f,b,v,j,m,k;const{provides:S}=s.useSelectionCapability(),{provides:M}=c(),[w,P]=l.useState([]),[C,z]=l.useState(null),[A,I]=l.useState(null);if(l.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{P(S.getHighlightRectsForPage(e)),z(S.getBoundingRectForPage(e))}))}),[S,e]),l.useEffect((()=>{if(!M)return;return M.onActiveToolChange(I)}),[M]),!C)return null;if(!A||!A.defaults)return null;switch(A.defaults.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=A.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(r=A.defaults)?void 0:r.color,opacity:null==(a=A.defaults)?void 0:a.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=A.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(u=A.defaults)?void 0:u.color,opacity:null==(h=A.defaults)?void 0:h.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(f=A.defaults)?void 0:f.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(b=A.defaults)?void 0:b.color,opacity:null==(v=A.defaults)?void 0:v.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(j=A.defaults)?void 0:j.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(m=A.defaults)?void 0:m.color,opacity:null==(k=A.defaults)?void 0:k.opacity,segmentRects:w,scale:t})});default:return null}}function z({preview:e,scale:t}){const{bounds:i}=e,s={position:"absolute",left:i.origin.x*t,top:i.origin.y*t,width:i.size.width*t,height:i.size.height*t,pointerEvents:"none",zIndex:10};return e.type===o.PdfAnnotationSubtype.CIRCLE?n.jsx("div",{style:s,children:n.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:s,children:n.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:s,children:n.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:s,children:n.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.LINE?n.jsx("div",{style:s,children:n.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.INK?n.jsx("div",{style:s,children:n.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.FREETEXT?n.jsx("div",{style:s,children:n.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function A({pageIndex:e,scale:t}){const{plugin:o}=d(),[i,s]=l.useState(new Map),r=l.useRef(null),a=l.useRef(null),c=l.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!r.current)return;const n=r.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=a.current;if(!i||!i.getContext)return;const s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const d=t?t/l:1,c=n?n/a:1,u=Math.min(d,c,1),h=l*u,g=a*u;i.width=h,i.height=g,s.drawImage(r,0,0,h,g);const p=s.getImageData(0,0,h,g);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:h,height:g})},r.src="string"==typeof e?e:URL.createObjectURL(e)}})),[]);return l.useEffect((()=>{if(o)return o.registerPageHandlers(e,t,{services:c,onPreview:(e,t)=>{s((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,o,c]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:r,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:a,style:{display:"none"}}),Array.from(i.entries()).map((([e,o])=>n.jsx(z,{preview:o,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:o,selectionMenu:i,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:d,selectionOutlineColor:c,...u}){return n.jsxs("div",{style:{...e},...u,children:[n.jsx(P,{selectionMenu:i,pageIndex:t,scale:o,rotation:d,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:c}),n.jsx(C,{pageIndex:t,scale:o}),n.jsx(A,{pageIndex:t,scale:o})]})},exports.useAnnotationCapability=c,exports.useAnnotationPlugin=d,Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),s=require("@embedpdf/plugin-selection/preact"),r=require("preact"),l=require("preact/hooks"),a=require("@embedpdf/utils/preact"),c=()=>e.usePlugin(t.AnnotationPlugin.id),d=()=>e.useCapability(t.AnnotationPlugin.id),u={};function h({scale:e,pageIndex:t,rotation:o,pageWidth:i,pageHeight:s,trackedAnnotation:r,children:c,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:b,selectionMenu:y,outlineOffset:v=1,onDoubleClick:f,onSelect:m,zIndex:j=1,resizeUI:k,vertexUI:S,selectionOutlineColor:M="#007ACC",customAnnotationRenderer:A,...w}){const[z,P]=l.useState(r.object),{provides:R}=d(),C=l.useRef(null),D=z?{...r.object,...z}:r.object,I=(null==k?void 0:k.color)??"#007ACC",E=(null==S?void 0:S.color)??"#007ACC",B=(null==k?void 0:k.size)??12,T=(null==S?void 0:S.size)??12,{dragProps:$,vertices:L,resize:F}=a.useInteractionHandles({controller:{element:D.rect,vertices:null==b?void 0:b.extractVertices(D),constraints:{minWidth:10,minHeight:10,boundingBox:{width:i/e,height:s/e}},maintainAspectRatio:p,pageRotation:o,scale:e,enabled:u,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(C.current=D);const o=e.transformData.type,i=C.current??D,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},l=null==R?void 0:R.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});l&&P((e=>({...e,...l}))),"end"===e.state&&l&&(C.current=null,null==R||R.updateAnnotation(t,r.object.id,l))}},resizeUI:{handleSize:B,spacing:v,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:T,zIndex:j+2},includeVertices:!!b}),W=a.useDoublePressProps(f);return l.useEffect((()=>{P(r.object)}),[r.object]),n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...h&&u?$:{},...W,style:{position:"absolute",left:D.rect.origin.x*e,top:D.rect.origin.y*e,width:D.rect.size.width*e,height:D.rect.size.height*e,outline:u?`1px solid ${M}`:"none",outlineOffset:u?`${v}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...w,children:[(()=>{const n=null==A?void 0:A({annotation:D,isSelected:u,scale:e,rotation:o,pageWidth:i,pageHeight:s,pageIndex:t,onSelect:m});return null!=n?n:"function"==typeof c?c(D):c})(),u&&g&&F.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:I}):n.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&L.map((({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:E}):n.jsx("div",{...t,style:{...t.style,backgroundColor:E}},e)))]}),n.jsx(a.CounterRotate,{rect:{origin:{x:D.rect.origin.x*e,y:D.rect.origin.y*e},size:{width:D.rect.size.width*e,height:D.rect.size.height*e}},rotation:o,children:({rect:e,menuWrapperProps:t})=>y&&y({annotation:r,selected:u,rect:e,menuWrapperProps:t})})]})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){return n.jsx(n.Fragment,{children:o.map(((o,a)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function b({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){const a=2*s,c=6*s,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*s,top:(i?e.origin.y-i.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},o)))})}function y({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:s,rect:r,scale:a,onClick:c}){const d=l.useMemo((()=>s.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()}))),[s,r]),u=r.size.width*a,h=r.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 ${r.size.width} ${r.size.height}`,children:d.map(((s,r)=>n.jsx("path",{d:s,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"}},r)))})}function v({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:r,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:g,height:p,x:x,y:b}=l.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}}),[d,r]),y=(g+r)*u,v=(p+r)*u;return n.jsx("svg",{style:{position:"absolute",width:y,height:v,pointerEvents:"none",zIndex:2},width:y,height:v,viewBox:`0 0 ${g+r} ${p+r}`,children:n.jsx("rect",{x:x,y:b,width:g,height:p,fill:t,opacity:s,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:r,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function f({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:r=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:b,rx:y,ry:v}=l.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}}),[c,s]),f=g*d,m=p*d;return n.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:x,cy:b,rx:y,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:s,...r===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function m({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:r="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:b,y1:y,x2:v,y2:f}=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(f-y,v-b);return{start:t.patching.createEnding(null==h?void 0:h.start,s,e+Math.PI,b,y),end:t.patching.createEnding(null==h?void 0:h.end,s,e,v,f)}}),[h,s,b,y,v,f]),j=d.size.width*g,k=d.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:b,y1:y,x2:v,y2:f,opacity:i,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:r,strokeWidth:s,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:r,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"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:r,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function j({rect:e,vertices:o,color:i="transparent",strokeColor:s="#000000",opacity:r=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]),x=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[0],g[1]),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]),b=e.size.width*c,y=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:y,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:r,style:{fill:"none",stroke:s??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&n.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:s,fill:x.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&n.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:s,fill:x.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:r=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const b=p?[...t,p]:t,y=l.useMemo((()=>b.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[b,e]),v=l.useMemo((()=>{if(!y.length)return"";const[e,...t]=y,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[y,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:v,onPointerDown:g,onTouchStart:g,opacity:r,style:{fill:p?"none":i,stroke:s??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(",")}}}),f&&t.length>1&&n.jsx("path",{d:`M ${y[y.length-1].x} ${y[y.length-1].y} L ${y[0].x} ${y[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&n.jsx("rect",{x:y[0].x-x/u/2,y:y[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:i,pageIndex:s,scale:r,onClick:a}){const c=l.useRef(null),{provides:h}=d(),[g,p]=l.useState(!1);l.useEffect((()=>{if(t&&c.current){const e=c.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]),l.useLayoutEffect((()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}}),[]);const x=i.object.fontSize*r,b=g&&t&&x>0&&x<16,y=b?16:x,v=b?x/16:1,f=b?100/v:100;return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*r,height:i.object.rect.size.height*r,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:c,onBlur:()=>{h&&c.current&&h.updateAnnotation(s,i.object.id,{contents:c.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:y,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:b?`${f}%`:"100%",height:b?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:b?`scale(${v})`:void 0,transformOrigin:"top left"},contentEditable:t,...u,children:i.object.contents})})}function M({pageIndex:e,annotation:t,scaleFactor:i=1,style:s,...a}){const{provides:c}=d(),[u,h]=l.useState(null),g=l.useRef(null),{width:p,height:x}=t.rect.size;l.useEffect((()=>{if(c){const n=c.renderAnnotation({pageIndex:e,annotation:t,options:{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,c,t.id,p,x]);return n.jsx(r.Fragment,{children:u&&n.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...a,style:{width:"100%",height:"100%",display:"block",...s||{}}})})}function A({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:s}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:n.jsx(M,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function w(e){const{pageIndex:a,scale:c,selectionMenu:u}=e,{provides:M}=d(),{provides:w}=s.useSelectionCapability(),[z,P]=l.useState([]),{register:R}=i.usePointerHandlers({pageIndex:a}),[C,D]=l.useState(null),[I,E]=l.useState(null);l.useEffect((()=>{M&&M.onStateChange((e=>{P(t.getAnnotationsByPageIndex(e,a)),D(t.getSelectedAnnotationByPageIndex(e,a))}))}),[M]);const B=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&M&&(M.deselectAnnotation(),E(null))}})),[M]),T=l.useCallback(((e,t)=>{e.stopPropagation(),M&&w&&(M.selectAnnotation(a,t.object.id),w.clear(),t.object.id!==I&&E(null))}),[M,w,I,a]);return l.useEffect((()=>R(B)),[R,B]),n.jsx(n.Fragment,{children:z.map((i=>{const s=(null==C?void 0:C.object.id)===i.object.id,l=I===i.object.id,d=null==M?void 0:M.findToolForAnnotation(i.object);return t.isInk(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!0,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isSquare(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!0,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isCircle(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!0,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!1,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(p,{...e,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!1,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{...e,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!1,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{...e,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!1,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{...e,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isLine(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(m,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(j,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!1,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(k,{...e,isSelected:s,scale:c,onClick:e=>T(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:((null==d?void 0:d.interaction.isDraggable)??!0)&&!l,isResizable:(null==d?void 0:d.interaction.isResizable)??!0,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),E(i.object.id)},...e,children:e=>n.jsx(S,{isSelected:s,isEditing:l,annotation:{...i,object:e},pageIndex:a,scale:c,onClick:e=>T(e,i)})},i.object.id):t.isStamp(i)?n.jsx(h,{trackedAnnotation:i,isSelected:s,isDraggable:(null==d?void 0:d.interaction.isDraggable)??!0,isResizable:(null==d?void 0:d.interaction.isResizable)??!0,lockAspectRatio:(null==d?void 0:d.interaction.lockAspectRatio)??!1,selectionMenu:u,onSelect:e=>T(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(A,{isSelected:s,annotation:i,pageIndex:a,scale:c,onClick:e=>T(e,i)})},i.object.id):null}))})}function z({pageIndex:e,scale:t}){var i,r,a,c,u,h,y,v,f,m,j,k;const{provides:S}=s.useSelectionCapability(),{provides:M}=d(),[A,w]=l.useState([]),[z,P]=l.useState(null),[R,C]=l.useState(null);if(l.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{w(S.getHighlightRectsForPage(e)),P(S.getBoundingRectForPage(e))}))}),[S,e]),l.useEffect((()=>{if(!M)return;return M.onActiveToolChange(C)}),[M]),!z)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=R.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(r=R.defaults)?void 0:r.color,opacity:null==(a=R.defaults)?void 0:a.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(c=R.defaults)?void 0:c.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(u=R.defaults)?void 0:u.color,opacity:null==(h=R.defaults)?void 0:h.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(y=R.defaults)?void 0:y.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(v=R.defaults)?void 0:v.color,opacity:null==(f=R.defaults)?void 0:f.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(m=R.defaults)?void 0:m.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(b,{color:null==(j=R.defaults)?void 0:j.color,opacity:null==(k=R.defaults)?void 0:k.opacity,segmentRects:A,scale:t})});default:return null}}function P({preview:e,scale:t}){const{bounds:i}=e,s={position:"absolute",left:i.origin.x*t,top:i.origin.y*t,width:i.size.width*t,height:i.size.height*t,pointerEvents:"none",zIndex:10};return e.type===o.PdfAnnotationSubtype.CIRCLE?n.jsx("div",{style:s,children:n.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:s,children:n.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:s,children:n.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:s,children:n.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.LINE?n.jsx("div",{style:s,children:n.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.INK?n.jsx("div",{style:s,children:n.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.FREETEXT?n.jsx("div",{style:s,children:n.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function R({pageIndex:e,scale:t}){const{plugin:o}=c(),[i,s]=l.useState(new Map),r=l.useRef(null),a=l.useRef(null),d=l.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!r.current)return;const n=r.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=a.current;if(!i||!i.getContext)return;const s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),h=l*u,g=a*u;i.width=h,i.height=g,s.drawImage(r,0,0,h,g);const p=s.getImageData(0,0,h,g);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:h,height:g})},r.src="string"==typeof e?e:URL.createObjectURL(e)}})),[]);return l.useEffect((()=>{if(o)return o.registerPageHandlers(e,t,{services:d,onPreview:(e,t)=>{s((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,o,d]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:r,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:a,style:{display:"none"}}),Array.from(i.entries()).map((([e,o])=>n.jsx(P,{preview:o,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:o,selectionMenu:i,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:c,selectionOutlineColor:d,customAnnotationRenderer:u,...h}){return n.jsxs("div",{style:{...e},...h,children:[n.jsx(w,{selectionMenu:i,pageIndex:t,scale:o,rotation:c,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:d,customAnnotationRenderer:u}),n.jsx(z,{pageIndex:t,scale:o}),n.jsx(R,{pageIndex:t,scale:o})]})},exports.useAnnotationCapability=d,exports.useAnnotationPlugin=c,Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|