@embedpdf/plugin-annotation 1.0.20 → 1.0.22

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.
@@ -0,0 +1 @@
1
+ export * from '@embedpdf/utils/preact';
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-annotation"),n=require("react/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/react"),r=require("@embedpdf/plugin-selection/react"),s=require("react"),l=require("@embedpdf/core"),a=()=>e.useCapability(t.AnnotationPlugin.id);function c({children:e,...t}){const{rect:o,rotation:i}=t,{matrix:r,width:l,height:a}=function(e,t){const{width:n,height:o}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${o})`,width:o,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${o})`,width:n,height:o};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:o,height:n};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:n,height:o}}}(o,i),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:r,transformOrigin:"0 0",width:l,height:a,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation()};return n.jsx(s.Fragment,{children:e({menuWrapperProps:c,matrix:r,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:l,height:a}}})})}function d({rect:e,rotation:t,scale:i,vertices:r,onEdit:l,onCommit:a,handleSize:c=12}){const[d,u]=s.useState(null),h=s.useRef(null),p=s.useRef([]),g=e=>{const n=o.restoreOffset(e,t,i),r=[...p.current];return null!==d&&(r[d]={x:r[d].x+n.x,y:r[d].y+n.y}),r},y=e=>{if(null===d||!h.current)return;const t={x:e.clientX-h.current.x,y:e.clientY-h.current.y};l(g(t))},x=e=>{if(null===d||!h.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-h.current.x,y:e.clientY-h.current.y};a(g(t)),u(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-c/2,l=(t.y-e.origin.y)*i-c/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:c,height:c,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),u(a),h.current={x:e.clientX,y:e.clientY},p.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:y,onPointerUp:x},o);var a}))})}function u({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:l,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,lockAspectRatio:h=!1,currentRect:p,setCurrentRect:g,setCurrentVertices:y,setPreviewObject:x,commit:f}){const v=s.useRef("idle"),m=s.useRef("none"),b=s.useRef(null),k=s.useRef(null),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=t/e,j=n/e,w=(e,t,n)=>{v.current=e,b.current={x:t,y:n},k.current=p},M=(t,n)=>{if("idle"===v.current||!b.current)return;const s={x:t-b.current.x,y:n-b.current.y},{x:l,y:a}=o.restoreOffset(s,i,e),c=((e,t)=>{if(!k.current)return p;let{origin:n,size:o}=k.current,i=n.x,r=n.y,s=o.width,l=o.height;if("dragging"===v.current)i+=e,r+=t;else if("resizing"===v.current&&(m.current.includes("right")?s+=e:m.current.includes("left")&&(i+=e,s-=e),m.current.includes("bottom")?l+=t:m.current.includes("top")&&(r+=t,l-=t),h&&k.current)){const e=k.current.size.width/k.current.size.height,t=i+s,n=r+l;m.current.includes("left")||m.current.includes("right")?l=s/e:s=l*e,m.current.includes("left")&&(i=t-s),m.current.includes("top")&&(r=n-l)}return s<1||l<1?p:(s=P(s,1,S),l=P(l,1,j),i=P(i,0,S-s),r=P(r,0,j-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(l,a);let f={rect:c};d&&(f=d(r.object,{rect:c,direction:"resizing"===v.current?m.current:"bottom-right"}),u&&y(u({...r.object,...f}))),g(f.rect??c),x(f)},A=()=>{if("idle"===v.current)return;const e=m.current||"bottom-right";v.current="idle";let t={rect:p};d&&(t=d(r.object,{rect:p,direction:e})),f(t),b.current=null,k.current=null,m.current="none",x(null)},C=e=>{if(A(),(null==e?void 0:e.currentTarget)&&void 0!==e.pointerId)try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},z=()=>A();return s.useEffect((()=>{v.current="idle",m.current="none",b.current=null,k.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{l&&a&&(e.stopPropagation(),e.preventDefault(),w("dragging",e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>M(e.clientX,e.clientY),onPointerUp:C,onPointerCancel:()=>C(),onLostPointerCapture:()=>C(),onTouchStart:e=>{if(!l||!a)return;e.stopPropagation(),e.preventDefault();const t=e.touches[0];t&&w("dragging",t.clientX,t.clientY)},onTouchMove:e=>{const t=e.touches[0];t&&M(t.clientX,t.clientY)},onTouchEnd:z,onTouchCancel:z},startResize:e=>t=>{l&&c&&(t.stopPropagation(),t.preventDefault(),m.current=e,w("resizing",t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))}}}function h({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function p({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:l,trackedAnnotation:p,children:g,style:y,outlineOffset:x=1,isSelected:f=!1,isDraggable:v=!0,isResizable:m=!0,lockAspectRatio:b=!1,computeVertices:k,computePatch:P,selectionMenu:S,onDoubleClick:j,...w}){const{provides:M}=a(),[A,C]=s.useState(p.object.rect),[z,D]=s.useState((null==k?void 0:k(p.object))??[]),[E,I]=s.useState(null),{rootHandlers:W,startResize:R}=u({scale:e,pageWidth:r,pageHeight:l,rotation:i,tracked:p,isSelected:f,isDraggable:v,isResizable:m,lockAspectRatio:b,computePatch:P,computeVertices:k,currentRect:A,setCurrentRect:C,setCurrentVertices:D,setPreviewObject:I,commit:e=>null==M?void 0:M.updateAnnotation(t,p.object.id,e)});s.useLayoutEffect((()=>{o.rectEquals(p.object.rect,A)||(C(p.object.rect),I((e=>e?{...e,rect:p.object.rect}:null)),D((null==k?void 0:k(p.object))??[]))}),[p]);const T=E?{...p.object,...E}:p.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...W,...(B=j,B?{onDoubleClick:B}:{}),style:{position:"absolute",outline:f?"1px solid #007ACC":"none",outlineOffset:f?`${x}px`:"0px",left:A.origin.x*e+"px",top:A.origin.y*e+"px",width:A.size.width*e+"px",height:A.size.height*e+"px",pointerEvents:f?"auto":"none",touchAction:f?"auto":"none",cursor:f&&v?"move":"default",...f&&{zIndex:3},...y},...w,children:["function"==typeof g?g(T):g,f&&z.length>0&&n.jsx(d,{rect:A,rotation:i,scale:e,vertices:z,onEdit:e=>{if(D(e),P){const t=P(p.object,{rect:A,vertices:e});I(t),C(t.rect||A)}},onCommit:e=>{if(M&&P){const n=P(p.object,{rect:A,vertices:e});M.updateAnnotation(t,p.object.id,n)}}}),f&&m&&n.jsx(h,{rotation:i,outlineOffset:x,startResize:R})]}),n.jsx(c,{rect:{origin:{x:A.origin.x*e,y:A.origin.y*e},size:{width:A.size.width*e,height:A.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>S&&S({annotation:p,selected:f,rect:e,menuWrapperProps:t})})]});var B}function g({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function v({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:r,rect:l,scale:a,onClick:c}){const d=s.useMemo((()=>r.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-l.origin.x,r=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}))),[r,l]),u=l.size.width*a,h=l.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 ${l.size.width} ${l.size.height}`,children:d.map(((r,s)=>n.jsx("path",{d:r,fill:"none",opacity:o,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},s)))})}function m({isSelected:e,color:t="#000000",strokeColor:i,opacity:r=1,strokeWidth:l,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:p,height:g,x:y,y:x}=s.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}}),[d,l]),f=(p+l)*u,v=(g+l)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${p+l} ${g+l}`,children:n.jsx("rect",{x:y,y:x,width:p,height:g,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:l,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function b({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:p,height:g,cx:y,cy:x,rx:f,ry:v}=s.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),m=p*d,b=g*d;return n.jsx("svg",{style:{position:"absolute",width:m,height:b,pointerEvents:"none",zIndex:2},width:m,height:b,viewBox:`0 0 ${p} ${g}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const k=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function P({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:p,onClick:g,isSelected:y}){const{x1:x,y1:f,x2:v,y2:m}=s.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]),b=s.useMemo((()=>{const e=Math.atan2(m-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,m)}}),[h,r,x,f,v,m]),k=d.size.width*p,P=d.size.height*p;return n.jsxs("svg",{style:{position:"absolute",width:k,height:P,pointerEvents:"none",zIndex:2,overflow:"visible"},width:k,height:P,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:m,opacity:i,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",pointerEvents:y?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),b.start&&n.jsx("path",{d:b.start.d,transform:b.start.transform,onPointerDown:g,onTouchStart:g,stroke:l,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":b.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:b.start.filled?e:"none"}),b.end&&n.jsx("path",{d:b.end.d,transform:b.end.transform,stroke:l,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":b.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:b.end.filled?e:"none"})]})}function S({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const p=s.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),g=s.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[p]),y=s.useMemo((()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(p[1],p[0]),o=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,p[p.length-1].x,p[p.length-1].y)}}),[p,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:g,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function j({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:p}){const g=s.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=s.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[g]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onPointerDown:p,onTouchStart:p,opacity:l,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const w=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},M=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},A=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function C({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:l,onClick:c}){const d=s.useRef(null),{provides:u}=a();s.useEffect((()=>{if(t&&d.current){const e=d.current;e.focus();const t=window.getSelection();if(t){const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}}),[t]);return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*l,height:i.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:c,onTouchStart:c,children:n.jsx("span",{ref:d,onBlur:()=>{u&&d.current&&u.updateAnnotation(r,i.object.id,{contents:d.current.innerText})},style:{color:i.object.fontColor,fontSize:i.object.fontSize*l,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:"100%",height:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer"},contentEditable:t,children:i.object.contents})})}function z({pageIndex:e,annotation:t,scaleFactor:i=1,style:r,...l}){const{provides:c}=a(),[d,u]=s.useState(null),h=s.useRef(null),{width:p,height:g}=t.rect.size;s.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);u(t),h.current=t}),o.ignore),()=>{h.current?(URL.revokeObjectURL(h.current),h.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,c,t.id,p,g]);return n.jsx(s.Fragment,{children:d&&n.jsx("img",{src:d,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...l,style:{width:"100%",height:"100%",...r||{}}})})}function D({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:r}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:r,onTouchStart:r,children:n.jsx(z,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function E(e){const{pageIndex:l,scale:c,selectionMenu:d}=e,{provides:u}=a(),{provides:h}=r.useSelectionCapability(),[z,E]=s.useState([]),{register:I}=i.usePointerHandlers({pageIndex:l}),[W,R]=s.useState(null),[T,B]=s.useState(null);s.useEffect((()=>{u&&u.onStateChange((e=>{E(t.getAnnotationsByPageIndex(e,l)),R(t.getSelectedAnnotationByPageIndex(e,l))}))}),[u]);const L=s.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&u&&(u.deselectAnnotation(),B(null))}})),[u]),$=s.useCallback(((e,t)=>{e.stopPropagation(),u&&h&&(u.selectAnnotation(l,t.object.id),h.clear(),B(null))}),[u,h,l]);return s.useEffect((()=>I(L)),[I,L]),n.jsx(n.Fragment,{children:z.map((i=>{const r=(null==W?void 0:W.object.id)===i.object.id,a=T===i.object.id;return t.isInk(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,computePatch:k,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{isSelected:r,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isSquare(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isCircle(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,rect:e.rect,onClick:e=>$(e,i)})},i.object.id):t.isLine(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:w,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>$(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:M,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(S,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:c,onClick:e=>$(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computeVertices:e=>e.vertices,computePatch:A,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(j,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>$(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,outlineOffset:6,onDoubleClick:e=>{e.stopPropagation(),B(i.object.id)},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(C,{isSelected:r,isEditing:a,annotation:{...i,object:e},pageIndex:l,scale:c,onClick:e=>$(e,i)})},i.object.id):t.isStamp(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(D,{isSelected:r,annotation:i,pageIndex:l,scale:c,onClick:e=>$(e,i)})},i.object.id):null}))})}function I({pageIndex:e,scale:t}){var i,l,c,d,u,h,p,v,m,b,k,P;const{provides:S}=r.useSelectionCapability(),{provides:j}=a(),[w,M]=s.useState([]),[A,C]=s.useState(null),[z,D]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{M(S.getHighlightRectsForPage(e)),C(S.getBoundingRectForPage(e))}))}),[S,e]),s.useEffect((()=>{if(!j)return;return j.onActiveToolChange(D)}),[j]),!A)return null;if(!z.defaults)return null;switch(z.defaults.subtype){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=z.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(l=z.defaults)?void 0:l.color,opacity:null==(c=z.defaults)?void 0:c.opacity,rects:w,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=z.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(u=z.defaults)?void 0:u.color,opacity:null==(h=z.defaults)?void 0:h.opacity,rects:w,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(p=z.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(v=z.defaults)?void 0:v.color,opacity:null==(m=z.defaults)?void 0:m.opacity,rects:w,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(b=z.defaults)?void 0:b.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(k=z.defaults)?void 0:k.color,opacity:null==(P=z.defaults)?void 0:P.opacity,rects:w,scale:t})});default:return null}}const W=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c})=>{var d,u,h,p,g;const{provides:y}=a(),[x,f]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!y)return;return y.onActiveToolChange(f)}),[y]),!x.defaults)return null;if(x.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const v=(null==(d=x.defaults)?void 0:d.color)??"#000000",m=(null==(u=x.defaults)?void 0:u.opacity)??1,b=(null==(h=x.defaults)?void 0:h.strokeWidth)??2,k=(null==(p=x.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal,P=null==(g=x.defaults)?void 0:g.intent,{register:S}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),[j,w]=s.useState([]),[M,A]=s.useState(!1),C=s.useRef(null),z=r/t,D=c/t,E=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=l.clamp(e.x,0,z),i=l.clamp(e.y,0,D);A(!0),C.current?(clearTimeout(C.current),C.current=null,w((e=>[...e,{points:[{x:o,y:i}]}]))):w([{points:[{x:o,y:i}]}]),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!M)return;const t=l.clamp(e.x,0,z),n=l.clamp(e.y,0,D);w((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i;A(!1),null==(i=n.releasePointerCapture)||i.call(n),C.current&&clearTimeout(C.current),C.current=setTimeout((()=>{if(j.length&&y){const t=j.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),b/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:P,blendMode:k,rect:n,inkList:j,color:v,opacity:m,strokeWidth:b,created:new Date,pageIndex:e,id:o.uuidV4()};y.createAnnotation(e,i),y.setActiveVariant(null),y.selectAnnotation(e,i.id)}w([]),C.current=null}),3e3)},onPointerCancel:(e,t)=>{var n;A(!1),null==(n=t.releasePointerCapture)||n.call(t),w([]),C.current&&(clearTimeout(C.current),C.current=null)}})),[z,D,j,y,e,v,m,b,M]);if(s.useEffect((()=>{if(S)return S(E)}),[S,E]),s.useEffect((()=>()=>{C.current&&clearTimeout(C.current)}),[]),!j.length)return null;const I=j.flatMap((e=>e.points));if(!I.length)return null;const W=o.expandRect(o.rectFromPoints(I),b/2),R=j.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:R.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:m,style:{stroke:v,strokeWidth:b,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray??[],{register:b}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),k=r/t,P=c/t,[S,j]=s.useState(null),[w,M]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=l.clamp(e.x,0,k),i=l.clamp(e.y,0,P);j({x:o,y:i}),M({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!S)return;const t=l.clamp(e.x,0,k),n=l.clamp(e.y,0,P);M({x:t,y:n})},onPointerUp:(t,n)=>{var i;if(S&&w&&u){const t=Math.min(S.x,w.x),n=Math.min(S.y,w.y),i=Math.max(S.x,w.x),r=Math.max(S.y,w.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:m,created:new Date,pageIndex:e,id:o.uuidV4()};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(i=n.releasePointerCapture)||i.call(n),j(null),M(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),j(null),M(null)}})),[S,w,u,e,k,P,g,y,x]);if(s.useEffect((()=>b?b(A):void 0),[b,A]),!S||!w)return null;const C=Math.min(S.x,w.x),z=Math.min(S.y,w.y),D=Math.max(S.x,w.x),E=Math.max(S.y,w.y),I=x/2,W=C-I,R=z-I,T=D-C,B=E-z,L=T+x,$=B+x,H=I+T/2,F=I+B/2,O=T/2,N=B/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("ellipse",{cx:H,cy:F,rx:O,ry:N,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:m.join(",")}}})})},T=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray??[],{register:b}=i.usePointerHandlers({modeId:"square",pageIndex:e}),k=r/t,P=c/t,[S,j]=s.useState(null),[w,M]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=l.clamp(e.x,0,k),r=l.clamp(e.y,0,P);j({x:i,y:r}),M({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!S)return;const t=l.clamp(e.x,0,k),n=l.clamp(e.y,0,P);M({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(S&&w&&u){const t=Math.min(S.x,w.x),n=Math.min(S.y,w.y),i=Math.max(S.x,w.x),r=Math.max(S.y,w.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:m,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),j(null),M(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),j(null),M(null)}})),[S,w,u,e,k,P,g,y,x]);if(s.useEffect((()=>b?b(A):void 0),[b,A]),!S||!w)return null;const C=Math.min(S.x,w.x),z=Math.min(S.y,w.y),D=Math.max(S.x,w.x),E=Math.max(S.y,w.y),I=x/2,W=C-I,R=z-I,T=D-C,B=E-z,L=T+x,$=B+x;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("rect",{x:I,y:I,width:T,height:B,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:m.join(",")}}})})},B=({pageIndex:e,scale:r,pageWidth:c,pageHeight:d,cursor:u})=>{const{provides:h}=a(),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",m=p.defaults.lineEndings,b=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=p.defaults.strokeDashArray,{register:P}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),j=c/r,w=d/r,[M,A]=s.useState([]),[C,z]=s.useState(null),D=s.useMemo((()=>({onClick:e=>{const t=l.clamp(e.x,0,j),n=l.clamp(e.y,0,w);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{M.length>=1&&h&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,f,m),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:b,strokeDashArray:k,lineEndings:m,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,r),h.setActiveVariant(null),h.selectAnnotation(e,r.id)})(M),A([]),z(null)},onPointerMove:e=>{if(!M.length)return;const t=l.clamp(e.x,0,j),n=l.clamp(e.y,0,w);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[M,h,j,w]);if(s.useEffect((()=>P?P(D):void 0),[P,D]),!M.length||!C)return null;const E=[...M,C],I=t.patching.lineRectWithEndings(E,f,m);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(S,{rect:I,vertices:E,strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:m})})},L=({pageIndex:e,scale:r,pageWidth:c,pageHeight:d,cursor:u})=>{const{provides:h}=a(),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",m=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=p.defaults.strokeDashArray,k=p.defaults.lineEndings,S=p.defaults.intent,{register:j}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),w=c/r,M=d/r,[A,C]=s.useState(null),[z,D]=s.useState(null),E=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=l.clamp(e.x,0,w),i=l.clamp(e.y,0,M);C({x:o,y:i}),D({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!A)return;const t=l.clamp(e.x,0,w),n=l.clamp(e.y,0,M);D({x:t,y:n})},onPointerUp:(n,i)=>{var r;A&&z&&h&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],f,k),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:m,strokeDashArray:b,lineEndings:k,intent:S,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,s),h.setActiveVariant(null),h.selectAnnotation(e,s.id)})(A,z),null==(r=i.releasePointerCapture)||r.call(i),C(null),D(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),C(null),D(null)}})),[A,z,h,w,M]);if(s.useEffect((()=>j?j(E):void 0),[j,E]),!A||!z)return null;const I=t.patching.lineRectWithEndings([A,z],f,k);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(P,{rect:I,linePoints:{start:A,end:z},strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:k,strokeStyle:m,strokeDashArray:b})})},$=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>null==u?void 0:u.onActiveToolChange(p)),[u]),!h.defaults||h.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray,{register:b}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),k=r/t,P=c/t,[S,j]=s.useState([]),[w,M]=s.useState(null),A=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=x/2,d={origin:{x:r-c,y:s-c},size:{width:l-r+x,height:a-s+x}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:d,vertices:t,color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:m,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,h),u.setActiveVariant(null),u.selectAnnotation(e,h.id)},C=s.useMemo((()=>({onClick:e=>{const n=l.clamp(e.x,0,k),o=l.clamp(e.y,0,P);if(((e,n)=>{if(S.length<2)return!1;const o=14/t/2,i=S[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&S.length>=3&&u)return A(S),j([]),void M(null);j((e=>[...e,{x:n,y:o}])),M({x:n,y:o})},onDoubleClick:()=>{S.length>=3&&u?(A(S),j([]),M(null)):(j([]),M(null))},onPointerMove:e=>{if(!S.length)return;const t=l.clamp(e.x,0,k),n=l.clamp(e.y,0,P);M({x:t,y:n})},onPointerCancel:()=>{j([]),M(null)}})),[S,w,u,k,P]);if(s.useEffect((()=>b?b(C):void 0),[b,C]),!S.length||!w)return null;const z=[...S,w],D=z.map((e=>e.x)),E=z.map((e=>e.y)),I=Math.min(...D),W=Math.min(...E),R=Math.max(...D),T=Math.max(...E),B=x/2,L=I-B,$=W-B,H=R+B-L,F=T+B-$,O=s.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-$)+" "})),e.trim()}),[z,L,$]),N=S.length>=2?`M ${w.x-L} ${w.y-$} L ${S[0].x-L} ${S[0].y-$}`:null,V=14/t,U=V/2,Y=S[0].x-U-L,K=S[0].y-U-$;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:$*t,width:H*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:H*t,height:F*t,viewBox:`0 0 ${H} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==m?void 0:m.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:f,strokeWidth:x,strokeDasharray:"4,4"}}),S.length>=3&&n.jsx("rect",{x:Y,y:K,width:V,height:V,fill:f,opacity:.4,stroke:f,strokeWidth:x/2,style:{pointerEvents:"none"}})]})},H=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l,cursor:c="text"})=>{const{provides:d}=a(),[u,h]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.FREETEXT)return null;const p=u.defaults.fontColor??"#000000",g=u.defaults.opacity??1,y=u.defaults.fontSize??12,x=u.defaults.fontFamily,f=u.defaults.backgroundColor??"transparent",v=u.defaults.textAlign,m=u.defaults.verticalAlign,b=u.defaults.content??"Insert text here",{register:k}=i.usePointerHandlers({modeId:"freeText",pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=r/t,j=l/t,[w,M]=s.useState(null),[A,C]=s.useState(null),z=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=P(e.x,0,S),i=P(e.y,0,j);M({x:o,y:i}),C({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!w)return;const t=P(e.x,0,S),n=P(e.y,0,j);C({x:t,y:n})},onPointerUp:(t,n)=>{var i;w&&A&&d&&((t,n)=>{const i=Math.min(t.x,n.x),r=Math.min(t.y,n.y),s=Math.max(t.x,n.x)-i,l=Math.max(t.y,n.y)-r;if(s<1||l<1)return;const a={origin:{x:i,y:r},size:{width:s,height:l}},c={type:o.PdfAnnotationSubtype.FREETEXT,rect:a,contents:b,fontColor:p,fontSize:y,fontFamily:x,opacity:g,backgroundColor:f,textAlign:v,verticalAlign:m,pageIndex:e,id:o.uuidV4(),created:new Date};d.createAnnotation(e,c),d.setActiveVariant(null),d.selectAnnotation(e,c.id)})(w,A),null==(i=n.releasePointerCapture)||i.call(n),M(null),C(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),M(null),C(null)}})),[w,A,d,S,j]);if(s.useEffect((()=>k?k(z):void 0),[k,z]),!w||!A)return null;const D=Math.min(w.x,A.x),E=Math.min(w.y,A.y),I=Math.max(w.x,A.x)-D,W=Math.max(w.y,A.y)-E;return n.jsx("svg",{style:{position:"absolute",left:D*t,top:E*t,width:I*t,height:W*t,pointerEvents:"none",zIndex:2},width:I*t,height:W*t,viewBox:`0 0 ${I} ${W}`,children:n.jsx("rect",{x:0,y:0,width:I,height:W,fill:"transparent",style:{stroke:p,strokeWidth:1,strokeDasharray:"4,4",cursor:c}})})},F=({pageIndex:e,scale:t,pageWidth:r,pageHeight:c})=>{const{provides:d}=a(),u=s.useRef(null),h=s.useRef(null),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(d)return d.onActiveToolChange(g)}),[d]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.STAMP)return null;const{register:y}=i.usePointerHandlers({modeId:"stamp",pageIndex:e}),x=r/t,f=c/t,[v,m]=s.useState(null),b=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=l.clamp(e.x,0,x),i=l.clamp(e.y,0,f);m({x:o,y:i}),null==(n=u.current)||n.click()}})),[x,f]);s.useEffect((()=>y?y(b):void 0),[y,b]);return n.jsxs(s.Fragment,{children:[n.jsx("canvas",{style:{display:"none"},ref:h}),n.jsx("input",{ref:u,type:"file",accept:"image/png,image/jpeg",style:{display:"none"},onChange:async t=>{var n;if(!d||!v)return;const i=null==(n=t.currentTarget.files)?void 0:n[0];if(!i)return;const r=await new Promise(((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=URL.createObjectURL(i)})),s=r.naturalWidth,a=r.naturalHeight,c=x,u=f,p=Math.min(1,c/s,u/a),g=s*p,y=a*p,b={origin:{x:l.clamp(v.x,0,c-g),y:l.clamp(v.y,0,u-y)},size:{width:g,height:y}},k=h.current;if(!k)return;k.width=g,k.height=y;const P=k.getContext("2d");P.drawImage(r,0,0,g,y);const S=P.getImageData(0,0,g,y),j={type:o.PdfAnnotationSubtype.STAMP,flags:["print"],pageIndex:e,id:o.uuidV4(),created:new Date,rect:b};d.createAnnotation(e,j,{imageData:S}),d.setActiveVariant(null),d.selectAnnotation(e,j.id),m(null)}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(E,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(I,{pageIndex:e,scale:t}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(T,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx($,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(L,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(H,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(F,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=a,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id);
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-annotation"),n=require("react/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/react"),r=require("@embedpdf/plugin-selection/react"),s=require("react"),l=require("@embedpdf/utils/react"),a=require("@embedpdf/core"),c=()=>e.useCapability(t.AnnotationPlugin.id);function d({rect:e,rotation:t,scale:i,vertices:r,onEdit:l,onCommit:a,handleSize:c=12}){const[d,u]=s.useState(null),h=s.useRef(null),p=s.useRef([]),g=e=>{const n=o.restoreOffset(e,t,i),r=[...p.current];return null!==d&&(r[d]={x:r[d].x+n.x,y:r[d].y+n.y}),r},y=e=>{if(null===d||!h.current)return;const t={x:e.clientX-h.current.x,y:e.clientY-h.current.y};l(g(t))},x=e=>{if(null===d||!h.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-h.current.x,y:e.clientY-h.current.y};a(g(t)),u(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-c/2,l=(t.y-e.origin.y)*i-c/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:c,height:c,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),u(a),h.current={x:e.clientX,y:e.clientY},p.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:y,onPointerUp:x},o);var a}))})}function u({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:l,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,lockAspectRatio:h=!1,currentRect:p,setCurrentRect:g,setCurrentVertices:y,setPreviewObject:x,commit:f}){const v=s.useRef("idle"),b=s.useRef("none"),m=s.useRef(null),k=s.useRef(null),j=(e,t,n)=>Math.max(t,Math.min(n,e)),P=t/e,S=n/e,M=(e,t,n)=>{v.current=e,m.current={x:t,y:n},k.current=p},w=(t,n)=>{if("idle"===v.current||!m.current)return;const s={x:t-m.current.x,y:n-m.current.y},{x:l,y:a}=o.restoreOffset(s,i,e),c=((e,t)=>{if(!k.current)return p;let{origin:n,size:o}=k.current,i=n.x,r=n.y,s=o.width,l=o.height;if("dragging"===v.current)i+=e,r+=t;else if("resizing"===v.current&&(b.current.includes("right")?s+=e:b.current.includes("left")&&(i+=e,s-=e),b.current.includes("bottom")?l+=t:b.current.includes("top")&&(r+=t,l-=t),h&&k.current)){const e=k.current.size.width/k.current.size.height,t=i+s,n=r+l;b.current.includes("left")||b.current.includes("right")?l=s/e:s=l*e,b.current.includes("left")&&(i=t-s),b.current.includes("top")&&(r=n-l)}return s<1||l<1?p:(s=j(s,1,P),l=j(l,1,S),i=j(i,0,P-s),r=j(r,0,S-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(l,a);let f={rect:c};d&&(f=d(r.object,{rect:c,direction:"resizing"===v.current?b.current:"bottom-right"}),u&&y(u({...r.object,...f}))),g(f.rect??c),x(f)},A=()=>{if("idle"===v.current)return;const e=b.current||"bottom-right";v.current="idle";let t={rect:p};d&&(t=d(r.object,{rect:p,direction:e})),f(t),m.current=null,k.current=null,b.current="none",x(null)},C=e=>{if(A(),(null==e?void 0:e.currentTarget)&&void 0!==e.pointerId)try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},z=()=>A();return s.useEffect((()=>{v.current="idle",b.current="none",m.current=null,k.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{l&&a&&(e.stopPropagation(),e.preventDefault(),M("dragging",e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>w(e.clientX,e.clientY),onPointerUp:C,onPointerCancel:()=>C(),onLostPointerCapture:()=>C(),onTouchStart:e=>{if(!l||!a)return;e.stopPropagation(),e.preventDefault();const t=e.touches[0];t&&M("dragging",t.clientX,t.clientY)},onTouchMove:e=>{const t=e.touches[0];t&&w(t.clientX,t.clientY)},onTouchEnd:z,onTouchCancel:z},startResize:e=>t=>{l&&c&&(t.stopPropagation(),t.preventDefault(),b.current=e,M("resizing",t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))}}}function h({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function p({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:a,trackedAnnotation:p,children:g,style:y,outlineOffset:x=1,isSelected:f=!1,isDraggable:v=!0,isResizable:b=!0,lockAspectRatio:m=!1,computeVertices:k,computePatch:j,selectionMenu:P,onDoubleClick:S,...M}){const{provides:w}=c(),[A,C]=s.useState(p.object.rect),[z,E]=s.useState((null==k?void 0:k(p.object))??[]),[D,I]=s.useState(null),{rootHandlers:W,startResize:R}=u({scale:e,pageWidth:r,pageHeight:a,rotation:i,tracked:p,isSelected:f,isDraggable:v,isResizable:b,lockAspectRatio:m,computePatch:j,computeVertices:k,currentRect:A,setCurrentRect:C,setCurrentVertices:E,setPreviewObject:I,commit:e=>null==w?void 0:w.updateAnnotation(t,p.object.id,e)});s.useLayoutEffect((()=>{o.rectEquals(p.object.rect,A)||(C(p.object.rect),I((e=>e?{...e,rect:p.object.rect}:null)),E((null==k?void 0:k(p.object))??[]))}),[p]);const T=D?{...p.object,...D}:p.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...W,...(B=S,B?{onDoubleClick:B}:{}),style:{position:"absolute",outline:f?"1px solid #007ACC":"none",outlineOffset:f?`${x}px`:"0px",left:A.origin.x*e+"px",top:A.origin.y*e+"px",width:A.size.width*e+"px",height:A.size.height*e+"px",pointerEvents:f?"auto":"none",touchAction:f?"auto":"none",cursor:f&&v?"move":"default",...f&&{zIndex:3},...y},...M,children:["function"==typeof g?g(T):g,f&&z.length>0&&n.jsx(d,{rect:A,rotation:i,scale:e,vertices:z,onEdit:e=>{if(E(e),j){const t=j(p.object,{rect:A,vertices:e});I(t),C(t.rect||A)}},onCommit:e=>{if(w&&j){const n=j(p.object,{rect:A,vertices:e});w.updateAnnotation(t,p.object.id,n)}}}),f&&b&&n.jsx(h,{rotation:i,outlineOffset:x,startResize:R})]}),n.jsx(l.CounterRotate,{rect:{origin:{x:A.origin.x*e,y:A.origin.y*e},size:{width:A.size.width*e,height:A.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>P&&P({annotation:p,selected:f,rect:e,menuWrapperProps:t})})]});var B}function g({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:s,onTouchStart:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function v({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:r,rect:l,scale:a,onClick:c}){const d=s.useMemo((()=>r.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-l.origin.x,r=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}))),[r,l]),u=l.size.width*a,h=l.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 ${l.size.width} ${l.size.height}`,children:d.map(((r,s)=>n.jsx("path",{d:r,fill:"none",opacity:o,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},s)))})}function b({isSelected:e,color:t="#000000",strokeColor:i,opacity:r=1,strokeWidth:l,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:p,height:g,x:y,y:x}=s.useMemo((()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}}),[d,l]),f=(p+l)*u,v=(g+l)*u;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${p+l} ${g+l}`,children:n.jsx("rect",{x:y,y:x,width:p,height:g,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:l,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function m({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:p,height:g,cx:y,cy:x,rx:f,ry:v}=s.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),b=p*d,m=g*d;return n.jsx("svg",{style:{position:"absolute",width:b,height:m,pointerEvents:"none",zIndex:2},width:b,height:m,viewBox:`0 0 ${p} ${g}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const k=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function j({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:p,onClick:g,isSelected:y}){const{x1:x,y1:f,x2:v,y2:b}=s.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=s.useMemo((()=>{const e=Math.atan2(b-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,b)}}),[h,r,x,f,v,b]),k=d.size.width*p,j=d.size.height*p;return n.jsxs("svg",{style:{position:"absolute",width:k,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:k,height:j,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:b,opacity:i,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",pointerEvents:y?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:g,onTouchStart:g,stroke:l,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&n.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:g,onTouchStart:g,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:y?"none":m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function P({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const p=s.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),g=s.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[p]),y=s.useMemo((()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(p[1],p[0]),o=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,p[p.length-1].x,p[p.length-1].y)}}),[p,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:g,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function S({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:p}){const g=s.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=s.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[g]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onPointerDown:p,onTouchStart:p,opacity:l,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const M=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},w=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},A=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function C({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:l,onClick:a}){const d=s.useRef(null),{provides:u}=c();s.useEffect((()=>{if(t&&d.current){const e=d.current;e.focus();const t=window.getSelection();if(t){const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}}),[t]);return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*l,height:i.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:d,onBlur:()=>{u&&d.current&&u.updateAnnotation(r,i.object.id,{contents:d.current.innerText})},style:{color:i.object.fontColor,fontSize:i.object.fontSize*l,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:"100%",height:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer"},contentEditable:t,children:i.object.contents})})}function z({pageIndex:e,annotation:t,scaleFactor:i=1,style:r,...l}){const{provides:a}=c(),[d,u]=s.useState(null),h=s.useRef(null),{width:p,height:g}=t.rect.size;s.useEffect((()=>{if(a){const n=a.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:i,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);u(t),h.current=t}),o.ignore),()=>{h.current?(URL.revokeObjectURL(h.current),h.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,a,t.id,p,g]);return n.jsx(s.Fragment,{children:d&&n.jsx("img",{src:d,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...l,style:{width:"100%",height:"100%",...r||{}}})})}function E({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:r}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto"},onPointerDown:r,onTouchStart:r,children:n.jsx(z,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function D(e){const{pageIndex:l,scale:a,selectionMenu:d}=e,{provides:u}=c(),{provides:h}=r.useSelectionCapability(),[z,D]=s.useState([]),{register:I}=i.usePointerHandlers({pageIndex:l}),[W,R]=s.useState(null),[T,B]=s.useState(null);s.useEffect((()=>{u&&u.onStateChange((e=>{D(t.getAnnotationsByPageIndex(e,l)),R(t.getSelectedAnnotationByPageIndex(e,l))}))}),[u]);const L=s.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&u&&(u.deselectAnnotation(),B(null))}})),[u]),$=s.useCallback(((e,t)=>{e.stopPropagation(),u&&h&&(u.selectAnnotation(l,t.object.id),h.clear(),B(null))}),[u,h,l]);return s.useEffect((()=>I(L)),[I,L]),n.jsx(n.Fragment,{children:z.map((i=>{const r=(null==W?void 0:W.object.id)===i.object.id,c=T===i.object.id;return t.isInk(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,computePatch:k,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{isSelected:r,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isSquare(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isCircle(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:d,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:a,rect:e.rect,onClick:e=>$(e,i)})},i.object.id):t.isLine(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:M,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(j,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:a,onClick:e=>$(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:w,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:a,onClick:e=>$(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computeVertices:e=>e.vertices,computePatch:A,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(S,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:a,onClick:e=>$(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,outlineOffset:6,onDoubleClick:e=>{e.stopPropagation(),B(i.object.id)},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(C,{isSelected:r,isEditing:c,annotation:{...i,object:e},pageIndex:l,scale:a,onClick:e=>$(e,i)})},i.object.id):t.isStamp(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,lockAspectRatio:!0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(E,{isSelected:r,annotation:i,pageIndex:l,scale:a,onClick:e=>$(e,i)})},i.object.id):null}))})}function I({pageIndex:e,scale:t}){var i,l,a,d,u,h,p,v,b,m,k,j;const{provides:P}=r.useSelectionCapability(),{provides:S}=c(),[M,w]=s.useState([]),[A,C]=s.useState(null),[z,E]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!P)return;return P.onSelectionChange((()=>{w(P.getHighlightRectsForPage(e)),C(P.getBoundingRectForPage(e))}))}),[P,e]),s.useEffect((()=>{if(!S)return;return S.onActiveToolChange(E)}),[S]),!A)return null;if(!z.defaults)return null;switch(z.defaults.subtype){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=z.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(l=z.defaults)?void 0:l.color,opacity:null==(a=z.defaults)?void 0:a.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=z.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(u=z.defaults)?void 0:u.color,opacity:null==(h=z.defaults)?void 0:h.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(p=z.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(v=z.defaults)?void 0:v.color,opacity:null==(b=z.defaults)?void 0:b.opacity,rects:M,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(m=z.defaults)?void 0:m.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(k=z.defaults)?void 0:k.color,opacity:null==(j=z.defaults)?void 0:j.opacity,rects:M,scale:t})});default:return null}}const W=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l})=>{var d,u,h,p,g;const{provides:y}=c(),[x,f]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!y)return;return y.onActiveToolChange(f)}),[y]),!x.defaults)return null;if(x.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const v=(null==(d=x.defaults)?void 0:d.color)??"#000000",b=(null==(u=x.defaults)?void 0:u.opacity)??1,m=(null==(h=x.defaults)?void 0:h.strokeWidth)??2,k=(null==(p=x.defaults)?void 0:p.blendMode)??o.PdfBlendMode.Normal,j=null==(g=x.defaults)?void 0:g.intent,{register:P}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),[S,M]=s.useState([]),[w,A]=s.useState(!1),C=s.useRef(null),z=r/t,E=l/t,D=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=a.clamp(e.x,0,z),i=a.clamp(e.y,0,E);A(!0),C.current?(clearTimeout(C.current),C.current=null,M((e=>[...e,{points:[{x:o,y:i}]}]))):M([{points:[{x:o,y:i}]}]),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!w)return;const t=a.clamp(e.x,0,z),n=a.clamp(e.y,0,E);M((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i;A(!1),null==(i=n.releasePointerCapture)||i.call(n),C.current&&clearTimeout(C.current),C.current=setTimeout((()=>{if(S.length&&y){const t=S.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),m/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:j,blendMode:k,rect:n,inkList:S,color:v,opacity:b,strokeWidth:m,created:new Date,pageIndex:e,id:o.uuidV4()};y.createAnnotation(e,i),y.setActiveVariant(null),y.selectAnnotation(e,i.id)}M([]),C.current=null}),3e3)},onPointerCancel:(e,t)=>{var n;A(!1),null==(n=t.releasePointerCapture)||n.call(t),M([]),C.current&&(clearTimeout(C.current),C.current=null)}})),[z,E,S,y,e,v,b,m,w]);if(s.useEffect((()=>{if(P)return P(D)}),[P,D]),s.useEffect((()=>()=>{C.current&&clearTimeout(C.current)}),[]),!S.length)return null;const I=S.flatMap((e=>e.points));if(!I.length)return null;const W=o.expandRect(o.rectFromPoints(I),m/2),R=S.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:R.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:b,style:{stroke:v,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l,cursor:d})=>{const{provides:u}=c(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),k=r/t,j=l/t,[P,S]=s.useState(null),[M,w]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=a.clamp(e.x,0,k),i=a.clamp(e.y,0,j);S({x:o,y:i}),w({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!P)return;const t=a.clamp(e.x,0,k),n=a.clamp(e.y,0,j);w({x:t,y:n})},onPointerUp:(t,n)=>{var i;if(P&&M&&u){const t=Math.min(P.x,M.x),n=Math.min(P.y,M.y),i=Math.max(P.x,M.x),r=Math.max(P.y,M.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,created:new Date,pageIndex:e,id:o.uuidV4()};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(i=n.releasePointerCapture)||i.call(n),S(null),w(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),S(null),w(null)}})),[P,M,u,e,k,j,g,y,x]);if(s.useEffect((()=>m?m(A):void 0),[m,A]),!P||!M)return null;const C=Math.min(P.x,M.x),z=Math.min(P.y,M.y),E=Math.max(P.x,M.x),D=Math.max(P.y,M.y),I=x/2,W=C-I,R=z-I,T=E-C,B=D-z,L=T+x,$=B+x,H=I+T/2,F=I+B/2,O=T/2,N=B/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("ellipse",{cx:H,cy:F,rx:O,ry:N,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:b.join(",")}}})})},T=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l,cursor:d})=>{const{provides:u}=c(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray??[],{register:m}=i.usePointerHandlers({modeId:"square",pageIndex:e}),k=r/t,j=l/t,[P,S]=s.useState(null),[M,w]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=a.clamp(e.x,0,k),r=a.clamp(e.y,0,j);S({x:i,y:r}),w({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!P)return;const t=a.clamp(e.x,0,k),n=a.clamp(e.y,0,j);w({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(P&&M&&u){const t=Math.min(P.x,M.x),n=Math.min(P.y,M.y),i=Math.max(P.x,M.x),r=Math.max(P.y,M.y);if(i-t>=1&&r-n>=1){const s=x/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+x,height:r-n+x}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,a),u.setActiveVariant(null),u.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),S(null),w(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),S(null),w(null)}})),[P,M,u,e,k,j,g,y,x]);if(s.useEffect((()=>m?m(A):void 0),[m,A]),!P||!M)return null;const C=Math.min(P.x,M.x),z=Math.min(P.y,M.y),E=Math.max(P.x,M.x),D=Math.max(P.y,M.y),I=x/2,W=C-I,R=z-I,T=E-C,B=D-z,L=T+x,$=B+x;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:R*t,width:L*t,height:$*t,pointerEvents:"none",zIndex:2},width:L*t,height:$*t,viewBox:`0 0 ${L} ${$}`,children:n.jsx("rect",{x:I,y:I,width:T,height:B,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:b.join(",")}}})})},B=({pageIndex:e,scale:r,pageWidth:l,pageHeight:d,cursor:u})=>{const{provides:h}=c(),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",b=p.defaults.lineEndings,m=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=p.defaults.strokeDashArray,{register:j}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),S=l/r,M=d/r,[w,A]=s.useState([]),[C,z]=s.useState(null),E=s.useMemo((()=>({onClick:e=>{const t=a.clamp(e.x,0,S),n=a.clamp(e.y,0,M);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{w.length>=1&&h&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,f,b),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:m,strokeDashArray:k,lineEndings:b,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,r),h.setActiveVariant(null),h.selectAnnotation(e,r.id)})(w),A([]),z(null)},onPointerMove:e=>{if(!w.length)return;const t=a.clamp(e.x,0,S),n=a.clamp(e.y,0,M);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[w,h,S,M]);if(s.useEffect((()=>j?j(E):void 0),[j,E]),!w.length||!C)return null;const D=[...w,C],I=t.patching.lineRectWithEndings(D,f,b);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(P,{rect:I,vertices:D,strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:b})})},L=({pageIndex:e,scale:r,pageWidth:l,pageHeight:d,cursor:u})=>{const{provides:h}=c(),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(h)return h.onActiveToolChange(g)}),[h]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const y=p.defaults.color??"#000000",x=p.defaults.opacity??1,f=p.defaults.strokeWidth??2,v=p.defaults.strokeColor??"#000000",b=p.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=p.defaults.strokeDashArray,k=p.defaults.lineEndings,P=p.defaults.intent,{register:S}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),M=l/r,w=d/r,[A,C]=s.useState(null),[z,E]=s.useState(null),D=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=a.clamp(e.x,0,M),i=a.clamp(e.y,0,w);C({x:o,y:i}),E({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!A)return;const t=a.clamp(e.x,0,M),n=a.clamp(e.y,0,w);E({x:t,y:n})},onPointerUp:(n,i)=>{var r;A&&z&&h&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],f,k),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:y,opacity:x,strokeWidth:f,strokeColor:v,strokeStyle:b,strokeDashArray:m,lineEndings:k,intent:P,pageIndex:e,id:o.uuidV4(),created:new Date};h.createAnnotation(e,s),h.setActiveVariant(null),h.selectAnnotation(e,s.id)})(A,z),null==(r=i.releasePointerCapture)||r.call(i),C(null),E(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),C(null),E(null)}})),[A,z,h,M,w]);if(s.useEffect((()=>S?S(D):void 0),[S,D]),!A||!z)return null;const I=t.patching.lineRectWithEndings([A,z],f,k);return n.jsx("div",{style:{position:"absolute",left:I.origin.x*r,top:I.origin.y*r,width:I.size.width*r,height:I.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:u},children:n.jsx(j,{rect:I,linePoints:{start:A,end:z},strokeWidth:f,scale:r,isSelected:!1,color:y,strokeColor:v,opacity:x,lineEndings:k,strokeStyle:b,strokeDashArray:m})})},$=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l,cursor:d})=>{const{provides:u}=c(),[h,p]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>null==u?void 0:u.onActiveToolChange(p)),[u]),!h.defaults||h.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,b=h.defaults.strokeDashArray,{register:m}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),k=r/t,j=l/t,[P,S]=s.useState([]),[M,w]=s.useState(null),A=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=x/2,d={origin:{x:r-c,y:s-c},size:{width:l-r+x,height:a-s+x}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:d,vertices:t,color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:b,pageIndex:e,id:o.uuidV4(),created:new Date};u.createAnnotation(e,h),u.setActiveVariant(null),u.selectAnnotation(e,h.id)},C=s.useMemo((()=>({onClick:e=>{const n=a.clamp(e.x,0,k),o=a.clamp(e.y,0,j);if(((e,n)=>{if(P.length<2)return!1;const o=14/t/2,i=P[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&P.length>=3&&u)return A(P),S([]),void w(null);S((e=>[...e,{x:n,y:o}])),w({x:n,y:o})},onDoubleClick:()=>{P.length>=3&&u?(A(P),S([]),w(null)):(S([]),w(null))},onPointerMove:e=>{if(!P.length)return;const t=a.clamp(e.x,0,k),n=a.clamp(e.y,0,j);w({x:t,y:n})},onPointerCancel:()=>{S([]),w(null)}})),[P,M,u,k,j]);if(s.useEffect((()=>m?m(C):void 0),[m,C]),!P.length||!M)return null;const z=[...P,M],E=z.map((e=>e.x)),D=z.map((e=>e.y)),I=Math.min(...E),W=Math.min(...D),R=Math.max(...E),T=Math.max(...D),B=x/2,L=I-B,$=W-B,H=R+B-L,F=T+B-$,O=s.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-$)+" "})),e.trim()}),[z,L,$]),N=P.length>=2?`M ${M.x-L} ${M.y-$} L ${P[0].x-L} ${P[0].y-$}`:null,V=14/t,U=V/2,Y=P[0].x-U-L,q=P[0].y-U-$;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:$*t,width:H*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:H*t,height:F*t,viewBox:`0 0 ${H} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:y,style:{cursor:d,stroke:f,strokeWidth:x,...v===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==b?void 0:b.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:f,strokeWidth:x,strokeDasharray:"4,4"}}),P.length>=3&&n.jsx("rect",{x:Y,y:q,width:V,height:V,fill:f,opacity:.4,stroke:f,strokeWidth:x/2,style:{pointerEvents:"none"}})]})},H=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l,cursor:a="text"})=>{const{provides:d}=c(),[u,h]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.FREETEXT)return null;const p=u.defaults.fontColor??"#000000",g=u.defaults.opacity??1,y=u.defaults.fontSize??12,x=u.defaults.fontFamily,f=u.defaults.backgroundColor??"transparent",v=u.defaults.textAlign,b=u.defaults.verticalAlign,m=u.defaults.content??"Insert text here",{register:k}=i.usePointerHandlers({modeId:"freeText",pageIndex:e}),j=(e,t,n)=>Math.max(t,Math.min(n,e)),P=r/t,S=l/t,[M,w]=s.useState(null),[A,C]=s.useState(null),z=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=j(e.x,0,P),i=j(e.y,0,S);w({x:o,y:i}),C({x:o,y:i}),null==(n=t.setPointerCapture)||n.call(t)},onPointerMove:e=>{if(!M)return;const t=j(e.x,0,P),n=j(e.y,0,S);C({x:t,y:n})},onPointerUp:(t,n)=>{var i;M&&A&&d&&((t,n)=>{const i=Math.min(t.x,n.x),r=Math.min(t.y,n.y),s=Math.max(t.x,n.x)-i,l=Math.max(t.y,n.y)-r;if(s<1||l<1)return;const a={origin:{x:i,y:r},size:{width:s,height:l}},c={type:o.PdfAnnotationSubtype.FREETEXT,rect:a,contents:m,fontColor:p,fontSize:y,fontFamily:x,opacity:g,backgroundColor:f,textAlign:v,verticalAlign:b,pageIndex:e,id:o.uuidV4(),created:new Date};d.createAnnotation(e,c),d.setActiveVariant(null),d.selectAnnotation(e,c.id)})(M,A),null==(i=n.releasePointerCapture)||i.call(n),w(null),C(null)},onPointerCancel:(e,t)=>{var n;null==(n=t.releasePointerCapture)||n.call(t),w(null),C(null)}})),[M,A,d,P,S]);if(s.useEffect((()=>k?k(z):void 0),[k,z]),!M||!A)return null;const E=Math.min(M.x,A.x),D=Math.min(M.y,A.y),I=Math.max(M.x,A.x)-E,W=Math.max(M.y,A.y)-D;return n.jsx("svg",{style:{position:"absolute",left:E*t,top:D*t,width:I*t,height:W*t,pointerEvents:"none",zIndex:2},width:I*t,height:W*t,viewBox:`0 0 ${I} ${W}`,children:n.jsx("rect",{x:0,y:0,width:I,height:W,fill:"transparent",style:{stroke:p,strokeWidth:1,strokeDasharray:"4,4",cursor:a}})})},F=({pageIndex:e,scale:t,pageWidth:r,pageHeight:l})=>{const{provides:d}=c(),u=s.useRef(null),h=s.useRef(null),[p,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(d)return d.onActiveToolChange(g)}),[d]),!p.defaults)return null;if(p.defaults.subtype!==o.PdfAnnotationSubtype.STAMP)return null;const{register:y}=i.usePointerHandlers({modeId:"stamp",pageIndex:e}),x=r/t,f=l/t,[v,b]=s.useState(null),m=s.useMemo((()=>({onPointerDown:(e,t)=>{var n;const o=a.clamp(e.x,0,x),i=a.clamp(e.y,0,f);b({x:o,y:i}),null==(n=u.current)||n.click()}})),[x,f]);s.useEffect((()=>y?y(m):void 0),[y,m]);return n.jsxs(s.Fragment,{children:[n.jsx("canvas",{style:{display:"none"},ref:h}),n.jsx("input",{ref:u,type:"file",accept:"image/png,image/jpeg",style:{display:"none"},onChange:async t=>{var n;if(!d||!v)return;const i=null==(n=t.currentTarget.files)?void 0:n[0];if(!i)return;const r=await new Promise(((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=URL.createObjectURL(i)})),s=r.naturalWidth,l=r.naturalHeight,c=x,u=f,p=Math.min(1,c/s,u/l),g=s*p,y=l*p,m={origin:{x:a.clamp(v.x,0,c-g),y:a.clamp(v.y,0,u-y)},size:{width:g,height:y}},k=h.current;if(!k)return;k.width=g,k.height=y;const j=k.getContext("2d");j.drawImage(r,0,0,g,y);const P=j.getImageData(0,0,g,y),S={type:o.PdfAnnotationSubtype.STAMP,flags:["print"],pageIndex:e,id:o.uuidV4(),created:new Date,rect:m};d.createAnnotation(e,S,{imageData:P}),d.setActiveVariant(null),d.selectAnnotation(e,S.id),b(null)}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(D,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(I,{pageIndex:e,scale:t}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(T,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx($,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(L,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(H,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(F,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=c,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id),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