@embedpdf/plugin-annotation 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +345 -22
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/annotation-plugin.d.ts +1 -0
  6. package/dist/lib/helpers.d.ts +18 -0
  7. package/dist/lib/index.d.ts +2 -0
  8. package/dist/lib/patching/derived-rect.d.ts +2 -0
  9. package/dist/lib/patching/index.d.ts +4 -0
  10. package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
  11. package/dist/lib/patching/line-endings.d.ts +13 -0
  12. package/dist/lib/patching/patch-utils.d.ts +7 -0
  13. package/dist/lib/selectors.d.ts +17 -5
  14. package/dist/lib/types.d.ts +55 -8
  15. package/dist/preact/adapter.d.ts +1 -1
  16. package/dist/preact/index.cjs +1 -1
  17. package/dist/preact/index.cjs.map +1 -1
  18. package/dist/preact/index.js +2062 -421
  19. package/dist/preact/index.js.map +1 -1
  20. package/dist/react/adapter.d.ts +1 -1
  21. package/dist/react/index.cjs +1 -1
  22. package/dist/react/index.cjs.map +1 -1
  23. package/dist/react/index.js +2061 -420
  24. package/dist/react/index.js.map +1 -1
  25. package/dist/shared-preact/components/annotation-container.d.ts +12 -7
  26. package/dist/shared-preact/components/annotation-layer.d.ts +3 -1
  27. package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
  28. package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
  29. package/dist/shared-preact/components/annotations/ink-paint.d.ts +2 -1
  30. package/dist/shared-preact/components/annotations/ink.d.ts +3 -1
  31. package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
  32. package/dist/shared-preact/components/annotations/line.d.ts +33 -0
  33. package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
  34. package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
  35. package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
  36. package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
  37. package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
  38. package/dist/shared-preact/components/annotations/square.d.ts +29 -0
  39. package/dist/shared-preact/components/annotations.d.ts +4 -0
  40. package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
  41. package/dist/shared-preact/components/resize-handles.d.ts +9 -0
  42. package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
  43. package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
  44. package/dist/shared-preact/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
  45. package/dist/shared-preact/patchers.d.ts +9 -0
  46. package/dist/shared-preact/types.d.ts +11 -0
  47. package/dist/shared-preact/vertex-patchers.d.ts +10 -0
  48. package/dist/shared-react/components/annotation-container.d.ts +12 -7
  49. package/dist/shared-react/components/annotation-layer.d.ts +3 -1
  50. package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
  51. package/dist/shared-react/components/annotations/circle.d.ts +29 -0
  52. package/dist/shared-react/components/annotations/ink.d.ts +3 -1
  53. package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
  54. package/dist/shared-react/components/annotations/line.d.ts +33 -0
  55. package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
  56. package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
  57. package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
  58. package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
  59. package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
  60. package/dist/shared-react/components/annotations/square.d.ts +29 -0
  61. package/dist/shared-react/components/annotations.d.ts +4 -0
  62. package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
  63. package/dist/shared-react/components/resize-handles.d.ts +9 -0
  64. package/dist/shared-react/components/vertex-editor.d.ts +19 -0
  65. package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
  66. package/dist/shared-react/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
  67. package/dist/shared-react/patchers.d.ts +9 -0
  68. package/dist/shared-react/types.d.ts +11 -0
  69. package/dist/shared-react/vertex-patchers.d.ts +10 -0
  70. package/package.json +9 -9
@@ -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("react"),s=require("@embedpdf/plugin-selection/react"),l=()=>e.useCapability(t.AnnotationPlugin.id);function a({scale:e,pageIndex:t,rotation:i,trackedAnnotation:s,children:a,style:c,outlineOffset:d=1,isSelected:u=!1,isDraggable:p=!0,isResizable:g=!0,computeResizePatch:h,...f}){const{provides:x}=l(),y=r.useRef(null),[b,m]=r.useState("idle"),[v,j]=r.useState(null),[M,w]=r.useState(null),[z,k]=r.useState(null),[I,P]=r.useState(s.object.rect),[S,C]=r.useState(null);r.useEffect((()=>{P(s.object.rect),C(null)}),[s]);const A=S?{...s.object,...S}:s.object;return n.jsxs("div",{ref:y,onPointerDown:e=>{var t;if(!u)return;e.stopPropagation(),e.preventDefault();const n=e.target;if(g&&n.classList.contains("resize-handle"))m("resizing"),j(n.dataset.direction);else{if(!p)return;m("dragging")}w({x:e.clientX,y:e.clientY}),k(I),null==(t=y.current)||t.setPointerCapture(e.pointerId)},onPointerMove:t=>{if("idle"===b||!M||!z)return;const n={x:t.clientX-M.x,y:t.clientY-M.y},{x:r,y:l}=o.restoreOffset(n,i,e);let a=z.origin.x,c=z.origin.y,d=z.size.width,u=z.size.height;if("dragging"===b)a+=r,c+=l;else if("resizing"===b&&v&&(v.includes("right")?d+=r:v.includes("left")&&(a+=r,d-=r),v.includes("bottom")?u+=l:v.includes("top")&&(c+=l,u-=l),d<1||u<1))return;const p={origin:{x:a,y:c},size:{width:d,height:u}};let g={rect:p};if(h){const e="resizing"===b?v:"bottom-right";e&&(g=h(s.object,p,e))}P(g.rect||p),C(g)},onPointerUp:e=>{var n;if("idle"===b)return;const o=v||"bottom-right";if(m("idle"),j(null),null==(n=y.current)||n.releasePointerCapture(e.pointerId),x&&s){let e={rect:I};h&&o&&(e=h(s.object,I,o)),x.updateAnnotation(t,s.localId,e)}w(null),k(null),C(null)},style:{position:"absolute",outline:u?"1px solid #007ACC":"none",outlineOffset:u?`${d}px`:"0px",left:I.origin.x*e+"px",top:I.origin.y*e+"px",width:I.size.width*e+"px",height:I.size.height*e+"px",pointerEvents:u?"auto":"none",cursor:u&&p?"move":"default",...c},...f,children:["function"==typeof a?a(A):a,u&&g&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"resize-handle","data-direction":"top-left",style:{position:"absolute",top:-7-d,left:-7-d,width:13,height:13,background:"blue",borderRadius:"50%",cursor:i%2?"nesw-resize":"nwse-resize"}}),n.jsx("div",{className:"resize-handle","data-direction":"top-right",style:{position:"absolute",top:-7-d,right:-7-d,width:13,height:13,background:"blue",borderRadius:"50%",cursor:i%2?"nwse-resize":"nesw-resize"}}),n.jsx("div",{className:"resize-handle","data-direction":"bottom-left",style:{position:"absolute",bottom:-7-d,left:-7-d,width:13,height:13,background:"blue",borderRadius:"50%",cursor:i%2?"nwse-resize":"nesw-resize"}}),n.jsx("div",{className:"resize-handle","data-direction":"bottom-right",style:{position:"absolute",bottom:-7-d,right:-7-d,width:13,height:13,background:"blue",borderRadius:"50%",cursor:i%2?"nesw-resize":"nwse-resize"}})]})]})}function c({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function d({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function u({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function p({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function g({color:e="#000000",opacity:t=1,strokeWidth:o,inkList:i,rect:s,scale:l,onClick:a}){const c=r.useMemo((()=>i.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-s.origin.x,r=n-s.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}))),[i,s]),d=s.size.width*l,u=s.size.height*l;return n.jsx("svg",{style:{position:"absolute",width:d,height:u,pointerEvents:"none",zIndex:2},width:d,height:u,viewBox:`0 0 ${s.size.width} ${s.size.height}`,children:c.map(((i,r)=>n.jsx("path",{d:i,fill:"none",stroke:e,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round",opacity:t,pointerEvents:"visibleStroke",onMouseDown:a,style:{cursor:"pointer"}},r)))})}function h(e,t,n,i=!1){if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const r=e.rect;let s=t.size.width/r.size.width,l=t.size.height/r.size.height;if((t.size.width<10||t.size.height<10)&&(s=Math.max(s,10/r.size.width),l=Math.max(l,10/r.size.height),t={origin:t.origin,size:{width:r.size.width*s,height:r.size.height*l}}),i){const e=Math.min(s,l);s=e,l=e,t.size={width:r.size.width*e,height:r.size.height*e}}const a=e.inkList.map((e=>({points:e.points.map((e=>({x:t.origin.x+(e.x-r.origin.x)*s,y:t.origin.y+(e.y-r.origin.y)*l})))}))),c=(s+l)/2,d=e.strokeWidth*c;return{rect:t,inkList:a,strokeWidth:d}}function f(e){const{pageIndex:f,scale:x}=e,{provides:y}=l(),{provides:b}=s.useSelectionCapability(),[m,v]=r.useState([]),{register:j}=i.usePointerHandlers({pageIndex:f}),[M,w]=r.useState(null);r.useEffect((()=>{y&&y.onStateChange((e=>{v(t.getAnnotationsByPageIndex(e,f)),w(t.getSelectedAnnotationByPageIndex(e,f))}))}),[y]);const z=r.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&y&&y.deselectAnnotation()}})),[y]),k=r.useCallback(((e,t)=>{e.stopPropagation(),y&&b&&(y.selectAnnotation(f,t.localId),b.clear())}),[y,b,f]);return r.useEffect((()=>j(z)),[j,z]),n.jsx(n.Fragment,{children:m.map((t=>{const i=(null==M?void 0:M.localId)===t.localId;switch(t.object.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx(a,{trackedAnnotation:t,isSelected:i,isDraggable:!1,isResizable:!1,style:{mixBlendMode:o.blendModeToCss(t.object.blendMode??o.PdfBlendMode.Normal)},...e,children:n.jsx(d,{rect:t.object.rect,color:t.object.color,opacity:t.object.opacity,rects:t.object.segmentRects,scale:x,onClick:e=>k(e,t)})},t.localId);case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx(a,{trackedAnnotation:t,isSelected:i,isDraggable:!1,isResizable:!1,style:{mixBlendMode:o.blendModeToCss(t.object.blendMode??o.PdfBlendMode.Normal)},...e,children:n.jsx(u,{rect:t.object.rect,color:t.object.color,opacity:t.object.opacity,rects:t.object.segmentRects,scale:x,onClick:e=>k(e,t)})},t.localId);case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx(a,{trackedAnnotation:t,isSelected:i,isDraggable:!1,isResizable:!1,style:{mixBlendMode:o.blendModeToCss(t.object.blendMode??o.PdfBlendMode.Normal)},...e,children:n.jsx(p,{color:t.object.color,opacity:t.object.opacity,rects:t.object.segmentRects,rect:t.object.rect,scale:x,onClick:e=>k(e,t)})},t.localId);case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx(a,{trackedAnnotation:t,isSelected:i,isDraggable:!1,isResizable:!1,style:{mixBlendMode:o.blendModeToCss(t.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:n.jsx(c,{color:t.object.color,opacity:t.object.opacity,rects:t.object.segmentRects,scale:x,rect:t.object.rect,onClick:e=>k(e,t)})},t.localId);case o.PdfAnnotationSubtype.INK:return n.jsx(a,{isSelected:i,trackedAnnotation:t,outlineOffset:6,computeResizePatch:h,style:{mixBlendMode:o.blendModeToCss(t.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(g,{color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:x,onClick:e=>k(e,t)})},t.localId);default:return null}}))})}function x({pageIndex:e,scale:i}){var a,g,h,f,x,y,b,m,v,j,M,w;const{provides:z}=s.useSelectionCapability(),{provides:k}=l(),[I,P]=r.useState([]),[S,C]=r.useState(null),[A,E]=r.useState({variantKey:null,defaults:null});if(r.useEffect((()=>{if(!z)return;return z.onSelectionChange((()=>{P(z.getHighlightRectsForPage(e)),C(z.getBoundingRectForPage(e))}))}),[z,e]),r.useEffect((()=>{if(!k)return;return k.onActiveToolChange(E)}),[k]),!S)return null;switch(A.variantKey){case t.makeVariantKey(o.PdfAnnotationSubtype.UNDERLINE):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(a=A.defaults)?void 0:a.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(d,{color:null==(g=A.defaults)?void 0:g.color,opacity:null==(h=A.defaults)?void 0:h.opacity,rects:I,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.HIGHLIGHT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(f=A.defaults)?void 0:f.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(c,{color:null==(x=A.defaults)?void 0:x.color,opacity:null==(y=A.defaults)?void 0:y.opacity,rects:I,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.STRIKEOUT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(b=A.defaults)?void 0:b.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(u,{color:null==(m=A.defaults)?void 0:m.color,opacity:null==(v=A.defaults)?void 0:v.opacity,rects:I,scale:i})});case t.makeVariantKey(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(p,{color:null==(M=A.defaults)?void 0:M.color,opacity:null==(w=A.defaults)?void 0:w.opacity,rects:I,scale:i})});default:return null}}const y=({pageIndex:e,scale:t,pageWidth:s,pageHeight:a})=>{var c,d,u;const{provides:p}=l(),[g,h]=r.useState({variantKey:null,defaults:null});if(r.useEffect((()=>{if(!p)return;return p.onActiveToolChange(h)}),[p]),!g.defaults)return null;if(g.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const f=(null==(c=g.defaults)?void 0:c.color)??"#000000",x=(null==(d=g.defaults)?void 0:d.opacity)??1,y=(null==(u=g.defaults)?void 0:u.strokeWidth)??2,{register:b}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),[v,j]=r.useState([]),[M,w]=r.useState(!1),z=r.useRef(null),k=s/t,I=a/t,P=r.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,k),r=m(e.y,0,I);w(!0),z.current?(clearTimeout(z.current),z.current=null,j((e=>[...e,{points:[{x:i,y:r}]}]))):j([{points:[{x:i,y:r}]}]),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!M)return;const t=m(e.x,0,k),n=m(e.y,0,I);j((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i,r;w(!1),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),z.current&&clearTimeout(z.current),z.current=setTimeout((()=>{if(v.length&&p){const t=v.flatMap((e=>e.points));if(!t.length)return;const n=15,i=Math.min(...t.map((e=>e.x)))-n,r=Math.min(...t.map((e=>e.y)))-n,s=Math.max(...t.map((e=>e.x)))+n,l=Math.max(...t.map((e=>e.y)))+n;if(s-i<1||l-r<1)return;const a={origin:{x:i,y:r},size:{width:s-i,height:l-r}},c={type:o.PdfAnnotationSubtype.INK,rect:a,inkList:v,color:f,opacity:x,strokeWidth:y,pageIndex:e,id:Date.now()+Math.random()};p.createAnnotation(e,c),p.setActiveVariant(null),p.selectAnnotation(e,c.id)}j([]),z.current=null}),3e3)},onPointerCancel:(e,t)=>{var n,o;w(!1),null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),j([]),z.current&&(clearTimeout(z.current),z.current=null)}})),[k,I,v,p,e,f,x,y,M]);if(r.useEffect((()=>{if(b)return b(P)}),[b,P]),r.useEffect((()=>()=>{z.current&&clearTimeout(z.current)}),[]),!v.length)return null;const S=v.flatMap((e=>e.points));if(!S.length)return null;const C=Math.min(...S.map((e=>e.x))),A=Math.min(...S.map((e=>e.y))),E=Math.max(...S.map((e=>e.x))),R=Math.max(...S.map((e=>e.y))),T=C-15,B=A-15,F=E+15-T,L=R+15-B,$=v.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{t+=(0===o?"M":"L")+(e-T)+" "+(n-B)+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:T*t,top:B*t,width:F*t,height:L*t,pointerEvents:"none",zIndex:2},width:F*t,height:L*t,viewBox:`0 0 ${F} ${L}`,children:$.map(((e,t)=>n.jsx("path",{d:e,fill:"none",stroke:f,strokeWidth:y,strokeLinecap:"round",strokeLinejoin:"round",opacity:x},t)))})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,style:s,...l}){return n.jsxs("div",{style:{...s},...l,children:[n.jsx(f,{pageIndex:e,scale:t,rotation:r}),n.jsx(x,{pageIndex:e,scale:t}),n.jsx(y,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=l,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=()=>e.useCapability(t.AnnotationPlugin.id);function a({children:e,...t}){const{rect:o,rotation:i}=t,{matrix:r,width:l,height:a}=function(e,t){const{width:n,height:o}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${o})`,width:o,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${o})`,width:n,height:o};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:o,height:n};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:n,height:o}}}(o,i),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:r,transformOrigin:"0 0",width:l,height:a,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation()};return n.jsx(s.Fragment,{children:e({menuWrapperProps:c,matrix:r,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:l,height:a}}})})}function c({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),g=s.useRef([]),p=e=>{const n=o.restoreOffset(e,t,i),r=[...g.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(p(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(p(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},g.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:y,onPointerUp:x},o);var a}))})}function d({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:l,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,currentRect:h,setCurrentRect:g,setCurrentVertices:p,setPreviewObject:y,commit:x}){const f=s.useRef("idle"),v=s.useRef("none"),k=s.useRef(null),m=s.useRef(null),b=(e,t,n)=>Math.max(t,Math.min(n,e)),M=t/e,w=n/e;return s.useEffect((()=>{f.current="idle",v.current="none",k.current=null,m.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{l&&a&&(e.stopPropagation(),e.preventDefault(),f.current="dragging",k.current={x:e.clientX,y:e.clientY},m.current=h,e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:t=>{if("idle"===f.current||!k.current)return;const n={x:t.clientX-k.current.x,y:t.clientY-k.current.y},{x:s,y:l}=o.restoreOffset(n,i,e),a=((e,t)=>{if(!m.current)return h;let{origin:n,size:o}=m.current,i=n.x,r=n.y,s=o.width,l=o.height;return"dragging"===f.current?(i+=e,r+=t):"resizing"===f.current&&(v.current.includes("right")?s+=e:v.current.includes("left")&&(i+=e,s-=e),v.current.includes("bottom")?l+=t:v.current.includes("top")&&(r+=t,l-=t)),s<1||l<1?h:(s=b(s,1,M),l=b(l,1,w),i=b(i,0,M-s),r=b(r,0,w-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(s,l);let c={rect:a};d&&(c=d(r.object,{rect:a,direction:"resizing"===f.current?v.current:"bottom-right"}),u&&p(u({...r.object,...c}))),g(c.rect??a),y(c)},onPointerUp:()=>{if("idle"===f.current)return;const e=v.current||"bottom-right";f.current="idle";let t={rect:h};d&&(t=d(r.object,{rect:h,direction:e})),x(t),k.current=null,m.current=null,v.current="none",y(null)}},startResize:e=>t=>{l&&c&&(t.stopPropagation(),t.preventDefault(),f.current="resizing",v.current=e,k.current={x:t.clientX,y:t.clientY},m.current=h,t.currentTarget.setPointerCapture(t.pointerId))}}}function u({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 h({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:h,trackedAnnotation:g,children:p,style:y,outlineOffset:x=1,isSelected:f=!1,isDraggable:v=!0,isResizable:k=!0,computeVertices:m,computePatch:b,selectionMenu:M,...w}){const{provides:P}=l(),[S,j]=s.useState(g.object.rect),[A,I]=s.useState((null==m?void 0:m(g.object))??[]),[z,C]=s.useState(null),{rootHandlers:D,startResize:E}=d({scale:e,pageWidth:r,pageHeight:h,rotation:i,tracked:g,isSelected:f,isDraggable:v,isResizable:k,computePatch:b,computeVertices:m,currentRect:S,setCurrentRect:j,setCurrentVertices:I,setPreviewObject:C,commit:e=>null==P?void 0:P.updateAnnotation(t,g.localId,e)});s.useLayoutEffect((()=>{o.rectEquals(g.object.rect,S)||(j(g.object.rect),C((e=>e?{...e,rect:g.object.rect}:null)),I((null==m?void 0:m(g.object))??[]))}),[g]);const W=z?{...g.object,...z}:g.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...D,style:{position:"absolute",outline:f?"1px solid #007ACC":"none",outlineOffset:f?`${x}px`:"0px",left:S.origin.x*e+"px",top:S.origin.y*e+"px",width:S.size.width*e+"px",height:S.size.height*e+"px",pointerEvents:f?"auto":"none",cursor:f&&v?"move":"default",...y},...w,children:["function"==typeof p?p(W):p,f&&A.length>0&&n.jsx(c,{rect:S,rotation:i,scale:e,vertices:A,onEdit:e=>{if(I(e),b){const t=b(g.object,{rect:S,vertices:e});C(t),j(t.rect||S)}},onCommit:e=>{if(P&&b){const n=b(g.object,{rect:S,vertices:e});P.updateAnnotation(t,g.localId,n)}}}),f&&k&&n.jsx(u,{rotation:i,outlineOffset:x,startResize:E})]}),n.jsx(a,{rect:{origin:{x:S.origin.x*e,y:S.origin.y*e},size:{width:S.size.width*e,height:S.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>M&&M({annotation:g,selected:f,rect:e,menuWrapperProps:t})})]})}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",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function p({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",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,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function f({color:e="#000000",opacity:t=1,strokeWidth:o,inkList:i,rect:r,scale:l,onClick:a,cursor:c}){const d=s.useMemo((()=>i.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-r.origin.x,s=n-r.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "})),t.trim()}))),[i,r]),u=r.size.width*l,h=r.size.height*l;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${r.size.width} ${r.size.height}`,children:d.map(((i,r)=>n.jsx("path",{d:i,fill:"none",opacity:t,onMouseDown:a,style:{cursor:c,pointerEvents:"visibleStroke",stroke:e,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function v({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:g,height:p,x:y,y:x}=s.useMemo((()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}}),[c,r]),f=(g+r)*d,v=(p+r)*d;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${g+r} ${p+r}`,children:n.jsx("rect",{x:y,y:x,width:g,height:p,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function k({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:g,height:p,cx:y,cy:x,rx:f,ry:v}=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]),k=g*d,m=p*d;return n.jsx("svg",{style:{position:"absolute",width:k,height:m,pointerEvents:"none",zIndex:2},width:k,height:m,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const m=(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 b({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:g,onClick:p,isSelected:y}){const{x1:x,y1:f,x2:v,y2:k}=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(k-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,k)}}),[h,r,x,f,v,k]),b=d.size.width*g,M=d.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:b,height:M,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:M,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:k,opacity:i,onMouseDown:p,style:{cursor:y?"move":"pointer",pointerEvents:"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,onMouseDown:p,stroke:l,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents: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,onMouseDown:p,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function M({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=s.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),p=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("").trim()}),[g]),y=s.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[1],g[0]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onMouseDown:u,opacity:l,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function w({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:g}){const p=s.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=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("")+"Z").trim()}),[p]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onMouseDown:g,opacity:l,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const P=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},S=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},j=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function A(e){const{pageIndex:a,scale:c,selectionMenu:d}=e,{provides:u}=l(),{provides:A}=r.useSelectionCapability(),[I,z]=s.useState([]),{register:C}=i.usePointerHandlers({pageIndex:a}),[D,E]=s.useState(null);s.useEffect((()=>{u&&u.onStateChange((e=>{z(t.getAnnotationsByPageIndex(e,a)),E(t.getSelectedAnnotationByPageIndex(e,a))}))}),[u]);const W=s.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&u&&u.deselectAnnotation()}})),[u]),B=s.useCallback(((e,t)=>{e.stopPropagation(),u&&A&&(u.selectAnnotation(a,t.localId),A.clear())}),[u,A,a]);return s.useEffect((()=>C(W)),[C,W]),n.jsx(n.Fragment,{children:I.map((i=>{const r=(null==D?void 0:D.localId)===i.localId;return t.isInk(i)?n.jsx(h,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:d,computePatch:m,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{cursor:r?"move":"pointer",color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:c,onClick:e=>B(e,i)})},i.localId):t.isSquare(i)?n.jsx(h,{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(v,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>B(e,i)})},i.localId):t.isCircle(i)?n.jsx(h,{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(k,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>B(e,i)})},i.localId):t.isUnderline(i)?n.jsx(h,{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(p,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:c,onClick:e=>B(e,i)})},i.localId):t.isStrikeout(i)?n.jsx(h,{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=>B(e,i)})},i.localId):t.isSquiggly(i)?n.jsx(h,{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,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:c,onClick:e=>B(e,i)})},i.localId):t.isHighlight(i)?n.jsx(h,{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=>B(e,i)})},i.localId):t.isLine(i)?n.jsx(h,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:P,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(b,{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=>B(e,i)})})},i.localId):t.isPolyline(i)?n.jsx(h,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computePatch:S,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(M,{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=>B(e,i)})})},i.localId):t.isPolygon(i)?n.jsx(h,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:d,computeVertices:e=>e.vertices,computePatch:j,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(w,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:c,onClick:e=>B(e,i)})})},i.localId):null}))})}function I({pageIndex:e,scale:i}){var a,c,d,u,h,f,v,k,m,b,M,w;const{provides:P}=r.useSelectionCapability(),{provides:S}=l(),[j,A]=s.useState([]),[I,z]=s.useState(null),[C,D]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!P)return;return P.onSelectionChange((()=>{A(P.getHighlightRectsForPage(e)),z(P.getBoundingRectForPage(e))}))}),[P,e]),s.useEffect((()=>{if(!S)return;return S.onActiveToolChange(D)}),[S]),!I)return null;switch(C.variantKey){case t.makeVariantKey(o.PdfAnnotationSubtype.UNDERLINE):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(a=C.defaults)?void 0:a.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(c=C.defaults)?void 0:c.color,opacity:null==(d=C.defaults)?void 0:d.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.HIGHLIGHT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(u=C.defaults)?void 0:u.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(h=C.defaults)?void 0:h.color,opacity:null==(f=C.defaults)?void 0:f.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.STRIKEOUT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(v=C.defaults)?void 0:v.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(k=C.defaults)?void 0:k.color,opacity:null==(m=C.defaults)?void 0:m.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.SQUIGGLY):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(b=C.defaults)?void 0:b.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(M=C.defaults)?void 0:M.color,opacity:null==(w=C.defaults)?void 0:w.opacity,rects:j,scale:i})});default:return null}}const z=({pageIndex:e,scale:t,pageWidth:r,pageHeight:a})=>{var c,d,u,h,g;const{provides:p}=l(),[y,x]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(!p)return;return p.onActiveToolChange(x)}),[p]),!y.defaults)return null;if(y.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const f=(null==(c=y.defaults)?void 0:c.color)??"#000000",v=(null==(d=y.defaults)?void 0:d.opacity)??1,k=(null==(u=y.defaults)?void 0:u.strokeWidth)??2,m=(null==(h=y.defaults)?void 0:h.blendMode)??o.PdfBlendMode.Normal,b=null==(g=y.defaults)?void 0:g.intent,{register:M}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),w=(e,t,n)=>Math.max(t,Math.min(n,e)),[P,S]=s.useState([]),[j,A]=s.useState(!1),I=s.useRef(null),z=r/t,C=a/t,D=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=w(e.x,0,z),r=w(e.y,0,C);A(!0),I.current?(clearTimeout(I.current),I.current=null,S((e=>[...e,{points:[{x:i,y:r}]}]))):S([{points:[{x:i,y:r}]}]),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!j)return;const t=w(e.x,0,z),n=w(e.y,0,C);S((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i,r;A(!1),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),I.current&&clearTimeout(I.current),I.current=setTimeout((()=>{if(P.length&&p){const t=P.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),k/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:b,blendMode:m,rect:n,inkList:P,color:f,opacity:v,strokeWidth:k,pageIndex:e,id:Date.now()+Math.random()};p.createAnnotation(e,i),p.setActiveVariant(null),p.selectAnnotation(e,i.id)}S([]),I.current=null}),3e3)},onPointerCancel:(e,t)=>{var n,o;A(!1),null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),S([]),I.current&&(clearTimeout(I.current),I.current=null)}})),[z,C,P,p,e,f,v,k,j]);if(s.useEffect((()=>{if(M)return M(D)}),[M,D]),s.useEffect((()=>()=>{I.current&&clearTimeout(I.current)}),[]),!P.length)return null;const E=P.flatMap((e=>e.points));if(!E.length)return null;const W=o.expandRect(o.rectFromPoints(E),k/2),B=P.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:B.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:v,style:{stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},C=({pageIndex:e,scale:t,pageWidth:r,pageHeight:a,cursor:c})=>{const{provides:d}=l(),[u,h]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:k}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=a/t,[w,P]=s.useState(null),[S,j]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,b),r=m(e.y,0,M);P({x:i,y:r}),j({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&S&&d){const t=Math.min(w.x,S.x),n=Math.min(w.y,S.y),i=Math.max(w.x,S.x),r=Math.max(w.y,S.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),j(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),j(null)}})),[w,S,d,e,b,M,g,p,y]);if(s.useEffect((()=>k?k(A):void 0),[k,A]),!w||!S)return null;const I=Math.min(w.x,S.x),z=Math.min(w.y,S.y),C=Math.max(w.x,S.x),D=Math.max(w.y,S.y),E=y/2,W=I-E,B=z-E,R=C-I,$=D-z,L=R+y,H=$+y,T=E+R/2,F=E+$/2,O=R/2,N=$/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:B*t,width:L*t,height:H*t,pointerEvents:"none",zIndex:2},width:L*t,height:H*t,viewBox:`0 0 ${L} ${H}`,children:n.jsx("ellipse",{cx:T,cy:F,rx:O,ry:N,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},D=({pageIndex:e,scale:t,pageWidth:r,pageHeight:a,cursor:c})=>{const{provides:d}=l(),[u,h]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:k}=i.usePointerHandlers({modeId:"square",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=a/t,[w,P]=s.useState(null),[S,j]=s.useState(null),A=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,b),r=m(e.y,0,M);P({x:i,y:r}),j({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&S&&d){const t=Math.min(w.x,S.x),n=Math.min(w.y,S.y),i=Math.max(w.x,S.x),r=Math.max(w.y,S.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),j(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),j(null)}})),[w,S,d,e,b,M,g,p,y]);if(s.useEffect((()=>k?k(A):void 0),[k,A]),!w||!S)return null;const I=Math.min(w.x,S.x),z=Math.min(w.y,S.y),C=Math.max(w.x,S.x),D=Math.max(w.y,S.y),E=y/2,W=I-E,B=z-E,R=C-I,$=D-z,L=R+y,H=$+y;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:B*t,width:L*t,height:H*t,pointerEvents:"none",zIndex:2},width:L*t,height:H*t,viewBox:`0 0 ${L} ${H}`,children:n.jsx("rect",{x:E,y:E,width:R,height:$,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},E=({pageIndex:e,scale:r,pageWidth:a,pageHeight:c,cursor:d})=>{const{provides:u}=l(),[h,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.lineEndings,k=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray,{register:b}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),w=(e,t,n)=>Math.max(t,Math.min(n,e)),P=a/r,S=c/r,[j,A]=s.useState([]),[I,z]=s.useState(null),C=s.useMemo((()=>({onClick:e=>{const t=w(e.x,0,P),n=w(e.y,0,S);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{j.length>=1&&u&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,x,v),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:k,strokeDashArray:m,lineEndings:v,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,r),u.setActiveVariant(null),u.selectAnnotation(e,r.id)})(j),A([]),z(null)},onPointerMove:e=>{if(!j.length)return;const t=w(e.x,0,P),n=w(e.y,0,S);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[j,u,P,S]);if(s.useEffect((()=>b?b(C):void 0),[b,C]),!j.length||!I)return null;const D=[...j,I],E=t.patching.lineRectWithEndings(D,x,v);return n.jsx("div",{style:{position:"absolute",left:E.origin.x*r,top:E.origin.y*r,width:E.size.width*r,height:E.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(M,{rect:E,vertices:D,strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:v})})},W=({pageIndex:e,scale:r,pageWidth:a,pageHeight:c,cursor:d})=>{const{provides:u}=l(),[h,g]=s.useState({variantKey:null,defaults:null});if(s.useEffect((()=>{if(u)return u.onActiveToolChange(g)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const p=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=h.defaults.strokeDashArray,m=h.defaults.lineEndings,M=h.defaults.intent,{register:w}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=a/r,j=c/r,[A,I]=s.useState(null),[z,C]=s.useState(null),D=s.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=P(e.x,0,S),r=P(e.y,0,j);I({x:i,y:r}),C({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!A)return;const t=P(e.x,0,S),n=P(e.y,0,j);C({x:t,y:n})},onPointerUp:(n,i)=>{var r,s;A&&z&&u&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],x,m),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:p,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:k,lineEndings:m,intent:M,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,s),u.setActiveVariant(null),u.selectAnnotation(e,s.id)})(A,z),null==(s=null==(r=i.target)?void 0:r.releasePointerCapture)||s.call(r,i.pointerId),I(null),C(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),I(null),C(null)}})),[A,z,u,S,j]);if(s.useEffect((()=>w?w(D):void 0),[w,D]),!A||!z)return null;const E=t.patching.lineRectWithEndings([A,z],x,m);return n.jsx("div",{style:{position:"absolute",left:E.origin.x*r,top:E.origin.y*r,width:E.size.width*r,height:E.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(b,{rect:E,linePoints:{start:A,end:z},strokeWidth:x,scale:r,isSelected:!1,color:p,strokeColor:f,opacity:y,lineEndings:m,strokeStyle:v,strokeDashArray:k})})},B=({pageIndex:e,scale:t,pageWidth:r,pageHeight:a,cursor:c})=>{const{provides:d}=l(),[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.POLYGON)return null;const g=u.defaults.color??"#000000",p=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray,{register:k}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=a/t,[w,P]=s.useState([]),[S,j]=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=y/2,u={origin:{x:r-c,y:s-c},size:{width:l-r+y,height:a-s+y}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:u,vertices:t,color:g,opacity:p,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,h),d.setActiveVariant(null),d.selectAnnotation(e,h.id)},I=s.useMemo((()=>({onClick:e=>{const n=m(e.x,0,b),o=m(e.y,0,M);if(((e,n)=>{if(w.length<2)return!1;const o=14/t/2,i=w[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&w.length>=3&&d)return A(w),P([]),void j(null);P((e=>[...e,{x:n,y:o}])),j({x:n,y:o})},onDoubleClick:()=>{w.length>=3&&d?(A(w),P([]),j(null)):(P([]),j(null))},onPointerMove:e=>{if(!w.length)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerCancel:()=>{P([]),j(null)}})),[w,S,d,b,M]);if(s.useEffect((()=>k?k(I):void 0),[k,I]),!w.length||!S)return null;const z=[...w,S],C=z.map((e=>e.x)),D=z.map((e=>e.y)),E=Math.min(...C),W=Math.min(...D),B=Math.max(...C),R=Math.max(...D),$=y/2,L=E-$,H=W-$,T=B+$-L,F=R+$-H,O=s.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-H)+" "})),e.trim()}),[z,L,H]),N=w.length>=2?`M ${S.x-L} ${S.y-H} L ${w[0].x-L} ${w[0].y-H}`:null,V=14/t,K=V/2,U=w[0].x-K-L,Y=w[0].y-K-H;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:H*t,width:T*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:T*t,height:F*t,viewBox:`0 0 ${T} ${F}`,children:[n.jsx("path",{d:O,fill:g,opacity:p,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==v?void 0:v.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:x,strokeWidth:y,strokeDasharray:"4,4"}}),w.length>=3&&n.jsx("rect",{x:U,y:Y,width:V,height:V,fill:x,opacity:.4,stroke:x,strokeWidth:y/2,style:{pointerEvents:"none"}})]})};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(A,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(I,{pageIndex:e,scale:t}),n.jsx(z,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(C,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(D,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(E,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=l,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id);
2
2
  //# sourceMappingURL=index.cjs.map