@embedpdf/plugin-annotation 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ export declare const defaultTools: ({
4
4
  name: string;
5
5
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
6
6
  interaction: {
7
- mode: string;
8
7
  exclusive: false;
9
8
  textSelection: true;
10
9
  cursor?: undefined;
@@ -33,7 +32,6 @@ export declare const defaultTools: ({
33
32
  name: string;
34
33
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
35
34
  interaction: {
36
- mode: string;
37
35
  exclusive: false;
38
36
  textSelection: true;
39
37
  cursor?: undefined;
@@ -62,7 +60,6 @@ export declare const defaultTools: ({
62
60
  name: string;
63
61
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
64
62
  interaction: {
65
- mode: string;
66
63
  exclusive: false;
67
64
  textSelection: true;
68
65
  cursor?: undefined;
@@ -91,7 +88,6 @@ export declare const defaultTools: ({
91
88
  name: string;
92
89
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
93
90
  interaction: {
94
- mode: string;
95
91
  exclusive: false;
96
92
  textSelection: true;
97
93
  cursor?: undefined;
@@ -120,7 +116,6 @@ export declare const defaultTools: ({
120
116
  name: string;
121
117
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 0 | 5;
122
118
  interaction: {
123
- mode: string;
124
119
  exclusive: false;
125
120
  cursor: string;
126
121
  textSelection?: undefined;
@@ -149,7 +144,6 @@ export declare const defaultTools: ({
149
144
  name: string;
150
145
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 0 | 10;
151
146
  interaction: {
152
- mode: string;
153
147
  exclusive: false;
154
148
  cursor: string;
155
149
  textSelection?: undefined;
@@ -178,7 +172,6 @@ export declare const defaultTools: ({
178
172
  name: string;
179
173
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
180
174
  interaction: {
181
- mode: string;
182
175
  exclusive: false;
183
176
  cursor: string;
184
177
  textSelection?: undefined;
@@ -216,7 +209,6 @@ export declare const defaultTools: ({
216
209
  name: string;
217
210
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
218
211
  interaction: {
219
- mode: string;
220
212
  exclusive: false;
221
213
  cursor: string;
222
214
  textSelection?: undefined;
@@ -254,7 +246,6 @@ export declare const defaultTools: ({
254
246
  name: string;
255
247
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 0 | 5;
256
248
  interaction: {
257
- mode: string;
258
249
  exclusive: false;
259
250
  cursor: string;
260
251
  textSelection?: undefined;
@@ -289,7 +280,6 @@ export declare const defaultTools: ({
289
280
  name: string;
290
281
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 0 | 10;
291
282
  interaction: {
292
- mode: string;
293
283
  exclusive: false;
294
284
  cursor: string;
295
285
  textSelection?: undefined;
@@ -327,7 +317,6 @@ export declare const defaultTools: ({
327
317
  name: string;
328
318
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
329
319
  interaction: {
330
- mode: string;
331
320
  exclusive: false;
332
321
  cursor: string;
333
322
  textSelection?: undefined;
@@ -356,7 +345,6 @@ export declare const defaultTools: ({
356
345
  name: string;
357
346
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
358
347
  interaction: {
359
- mode: string;
360
348
  exclusive: false;
361
349
  cursor: string;
362
350
  textSelection?: undefined;
@@ -385,7 +373,6 @@ export declare const defaultTools: ({
385
373
  name: string;
386
374
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
387
375
  interaction: {
388
- mode: string;
389
376
  exclusive: false;
390
377
  cursor: string;
391
378
  textSelection?: undefined;
@@ -423,7 +410,6 @@ export declare const defaultTools: ({
423
410
  name: string;
424
411
  matchScore: (a: import('@embedpdf/models').PdfAnnotationObject) => 1 | 0;
425
412
  interaction: {
426
- mode: string;
427
413
  exclusive: false;
428
414
  cursor: string;
429
415
  textSelection?: undefined;
@@ -79,7 +79,7 @@ export type AnnotationTool<T extends PdfAnnotationObject = PdfAnnotationObject>
79
79
  defaults: Partial<T> & GetToolConfig<T>;
80
80
  /** Defines how this tool interacts with the viewer. */
81
81
  interaction: {
82
- mode: string;
82
+ mode?: string;
83
83
  exclusive: boolean;
84
84
  cursor?: string;
85
85
  /** If true, this interaction mode is activated by selecting text. */
@@ -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"},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"),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]})}));
2
2
  //# sourceMappingURL=index.cjs.map