@embedpdf/plugin-annotation 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1061 -430
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/annotation-plugin.d.ts +24 -6
  6. package/dist/lib/geometry/index.d.ts +1 -0
  7. package/dist/lib/geometry/rotation.d.ts +32 -0
  8. package/dist/lib/handlers/types.d.ts +3 -1
  9. package/dist/lib/index.d.ts +1 -0
  10. package/dist/lib/patching/base-patch.d.ts +87 -0
  11. package/dist/lib/patching/index.d.ts +1 -0
  12. package/dist/lib/patching/insert-upright.d.ts +20 -0
  13. package/dist/lib/patching/patch-registry.d.ts +14 -1
  14. package/dist/lib/patching/patch-utils.d.ts +54 -1
  15. package/dist/lib/patching/patches/circle.patch.d.ts +3 -0
  16. package/dist/lib/patching/patches/freetext.patch.d.ts +3 -0
  17. package/dist/lib/patching/patches/index.d.ts +4 -0
  18. package/dist/lib/patching/patches/square.patch.d.ts +3 -0
  19. package/dist/lib/patching/patches/stamp.patch.d.ts +3 -0
  20. package/dist/lib/tools/default-tools.d.ts +32 -0
  21. package/dist/lib/tools/types.d.ts +20 -1
  22. package/dist/lib/types.d.ts +67 -3
  23. package/dist/preact/adapter.d.ts +3 -0
  24. package/dist/preact/index.cjs +1 -1
  25. package/dist/preact/index.cjs.map +1 -1
  26. package/dist/preact/index.js +793 -126
  27. package/dist/preact/index.js.map +1 -1
  28. package/dist/react/adapter.d.ts +2 -1
  29. package/dist/react/index.cjs +1 -1
  30. package/dist/react/index.cjs.map +1 -1
  31. package/dist/react/index.js +793 -126
  32. package/dist/react/index.js.map +1 -1
  33. package/dist/shared/components/annotation-container.d.ts +10 -2
  34. package/dist/shared/components/annotation-layer.d.ts +9 -3
  35. package/dist/shared/components/annotations.d.ts +4 -1
  36. package/dist/shared/components/group-selection-box.d.ts +12 -4
  37. package/dist/shared/components/render-annotation.d.ts +2 -1
  38. package/dist/shared/components/types.d.ts +51 -1
  39. package/dist/shared-preact/components/annotation-container.d.ts +10 -2
  40. package/dist/shared-preact/components/annotation-layer.d.ts +9 -3
  41. package/dist/shared-preact/components/annotations.d.ts +4 -1
  42. package/dist/shared-preact/components/group-selection-box.d.ts +12 -4
  43. package/dist/shared-preact/components/render-annotation.d.ts +2 -1
  44. package/dist/shared-preact/components/types.d.ts +51 -1
  45. package/dist/shared-react/components/annotation-container.d.ts +10 -2
  46. package/dist/shared-react/components/annotation-layer.d.ts +9 -3
  47. package/dist/shared-react/components/annotations.d.ts +4 -1
  48. package/dist/shared-react/components/group-selection-box.d.ts +12 -4
  49. package/dist/shared-react/components/render-annotation.d.ts +2 -1
  50. package/dist/shared-react/components/types.d.ts +51 -1
  51. package/dist/svelte/components/AnnotationLayer.svelte.d.ts +8 -2
  52. package/dist/svelte/components/Annotations.svelte.d.ts +7 -1
  53. package/dist/svelte/components/GroupSelectionBox.svelte.d.ts +11 -3
  54. package/dist/svelte/components/RenderAnnotation.svelte.d.ts +1 -0
  55. package/dist/svelte/components/types.d.ts +14 -1
  56. package/dist/svelte/index.cjs +1 -1
  57. package/dist/svelte/index.cjs.map +1 -1
  58. package/dist/svelte/index.js +1166 -330
  59. package/dist/svelte/index.js.map +1 -1
  60. package/dist/svelte/types.d.ts +53 -0
  61. package/dist/vue/components/annotation-container.vue.d.ts +35 -9
  62. package/dist/vue/components/annotation-layer.vue.d.ts +29 -5
  63. package/dist/vue/components/annotations.vue.d.ts +278 -134
  64. package/dist/vue/components/group-selection-box.vue.d.ts +35 -10
  65. package/dist/vue/components/render-annotation.vue.d.ts +2 -0
  66. package/dist/vue/index.cjs +1 -1
  67. package/dist/vue/index.cjs.map +1 -1
  68. package/dist/vue/index.js +945 -161
  69. package/dist/vue/index.js.map +1 -1
  70. package/dist/vue/types.d.ts +52 -0
  71. package/package.json +11 -10
@@ -1,5 +1,6 @@
1
1
  export { Fragment, useEffect, useRef, useState, useCallback, useMemo, useLayoutEffect, createContext, useContext, JSX, ChangeEvent, } from 'react';
2
- export type { ReactNode, HTMLAttributes, CSSProperties, MouseEvent, PointerEvent, TouchEvent, } from 'react';
2
+ export type { ReactNode, HTMLAttributes, CSSProperties, MouseEvent, PointerEvent, TouchEvent, KeyboardEvent, FormEvent, } from 'react';
3
+ export { createPortal } from 'react-dom';
3
4
  export declare const suppressContentEditableWarningProps: {
4
5
  suppressContentEditableWarning: boolean;
5
6
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-annotation"),n=require("react/jsx-runtime"),o=require("react"),i=require("@embedpdf/core/react"),r=require("@embedpdf/models"),s=require("@embedpdf/plugin-interaction-manager/react"),l=require("@embedpdf/plugin-selection/react"),a=require("@embedpdf/utils/react"),c={suppressContentEditableWarning:!0},d=o.createContext(null),u=o.createContext([]);function g({children:e}){const[t,i]=o.useState([]),r=o.useCallback(e=>(i(t=>{const n=new Set(e.map(e=>e.id));return[...t.filter(e=>!n.has(e.id)),...e]}),()=>i(t=>t.filter(t=>!e.some(e=>e.id===t.id)))),[]);return n.jsx(d.Provider,{value:r,children:n.jsx(u.Provider,{value:t,children:e})})}function p(){return o.useContext(u)}const h=()=>i.usePlugin(t.AnnotationPlugin.id),v=()=>i.useCapability(t.AnnotationPlugin.id);function b({scale:e,documentId:t,pageIndex:r,rotation:s,pageWidth:l,pageHeight:c,trackedAnnotation:d,children:u,isSelected:g,isMultiSelected:p=!1,isDraggable:b,isResizable:x,lockAspectRatio:f=!1,style:y={},vertexConfig:m,selectionMenu:j,outlineOffset:k=1,onDoubleClick:S,onSelect:I,zIndex:M=1,resizeUI:P,vertexUI:z,selectionOutlineColor:R="#007ACC",customAnnotationRenderer:A,groupSelectionMenu:C,annotationRenderers:w,...D}){const[E,B]=o.useState(d.object),{provides:T}=v(),{plugin:$}=h(),{canModifyAnnotations:L}=i.useDocumentPermissions(t),F=o.useRef(null),U=L&&b&&!p,W=L&&x&&!p,O=o.useMemo(()=>T?T.forDocument(t):null,[T,t]),H=E?{...d.object,...E}:d.object,N=(null==P?void 0:P.color)??"#007ACC",q=(null==z?void 0:z.color)??"#007ACC",G=(null==P?void 0:P.size)??12,V=(null==z?void 0:z.size)??12,K=o.useRef(null),Y=o.useCallback(e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type)||p||!$)return;const{type:o,changes:i,metadata:s}=e.transformData,a=d.object.id,u={width:l,height:c};if("start"===e.state&&(K.current=d.object.rect,F.current=d.object,"move"===o?$.startDrag(t,{annotationIds:[a],pageSize:u}):"resize"===o&&$.startResize(t,{annotationIds:[a],pageSize:u,resizeHandle:(null==s?void 0:s.handle)??"se"})),i.rect&&K.current)if("move"===o){const e={x:i.rect.origin.x-K.current.origin.x,y:i.rect.origin.y-K.current.origin.y};$.updateDrag(t,e)}else"resize"===o&&$.updateResize(t,i.rect);if("vertex-edit"===o&&i.vertices&&m){const t=F.current??d.object,n=m.transformAnnotation(t,i.vertices),l=null==T?void 0:T.transformAnnotation(t,{type:o,changes:n,metadata:s});l&&(B(e=>({...e,...l})),"end"===e.state&&(null==O||O.updateAnnotation(r,a,l)))}"end"===e.state&&(K.current=null,F.current=null,"move"===o?$.commitDrag(t):"resize"===o&&$.commitResize(t))},[$,t,d.object,l,c,r,p,m,T,O]),{dragProps:Q,vertices:X,resize:Z}=a.useInteractionHandles({controller:{element:H.rect,vertices:null==m?void 0:m.extractVertices(H),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:c}},maintainAspectRatio:f,pageRotation:s,scale:e,enabled:g&&!p,onUpdate:Y},resizeUI:{handleSize:G,spacing:k,offsetMode:"outside",includeSides:!f,zIndex:M+1},vertexUI:{vertexSize:V,zIndex:M+2},includeVertices:!!m}),J=o.useMemo(()=>{if(L&&S)return S},[L,S]),_=a.useDoublePressProps(J);o.useEffect(()=>{B(d.object)},[d.object]),o.useEffect(()=>{if(!$)return;const e=d.object.id,n=n=>{var o;if(n.documentId!==t)return;const i=null==(o=n.previewPatches)?void 0:o[e];"update"===n.type&&i?B(e=>({...e,...i})):"cancel"===n.type&&B(d.object)},o=[$.onDragChange(n),$.onResizeChange(n)];return()=>o.forEach(e=>e())},[$,t,d.object]);const ee=g&&!p;return n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...U&&g?Q:{},..._,style:{position:"absolute",left:H.rect.origin.x*e,top:H.rect.origin.y*e,width:H.rect.size.width*e,height:H.rect.size.height*e,outline:ee?`1px solid ${R}`:"none",outlineOffset:ee?`${k}px`:"0px",pointerEvents:g&&!p?"auto":"none",touchAction:"none",cursor:g&&U?"move":"default",zIndex:M,...y},...D,children:[(()=>{const t="function"==typeof u?u(H):u,n=null==A?void 0:A({annotation:H,children:t,isSelected:g,scale:e,rotation:s,pageWidth:l,pageHeight:c,pageIndex:r,onSelect:I});return null!=n?n:t})(),g&&W&&Z.map(({key:e,...t})=>(null==P?void 0:P.component)?P.component({key:e,...t,backgroundColor:N}):n.jsx("div",{...t,style:{...t.style,backgroundColor:N}},e)),g&&L&&!p&&X.map(({key:e,...t})=>(null==z?void 0:z.component)?z.component({key:e,...t,backgroundColor:q}):n.jsx("div",{...t,style:{...t.style,backgroundColor:q}},e))]}),j&&!p&&n.jsx(a.CounterRotate,{rect:{origin:{x:H.rect.origin.x*e,y:H.rect.origin.y*e},size:{width:H.rect.size.width*e,height:H.rect.size.height*e}},rotation:s,children:e=>j({...e,context:{type:"annotation",annotation:d,pageIndex:r},selected:g,placement:{suggestTop:!1}})})]})}function x({documentId:e,pageIndex:t,scale:s,rotation:l,pageWidth:c,pageHeight:d,selectedAnnotations:u,isDraggable:g,isResizable:p,resizeUI:v,selectionOutlineColor:b="#007ACC",outlineOffset:x=2,zIndex:f=100,groupSelectionMenu:y}){const{plugin:m}=h(),{canModifyAnnotations:j}=i.useDocumentPermissions(e),k=o.useRef(null),S=o.useRef(!1),I=o.useRef(!1),M=j&&g,P=j&&p,z=o.useMemo(()=>{const e=u.map(e=>e.object.rect);return r.boundingRectOrEmpty(e)},[u]),[R,A]=o.useState(z);o.useEffect(()=>{S.current||I.current||A(z)},[z]);const C=o.useCallback(t=>{var n,o;if(!(null==(n=t.transformData)?void 0:n.type))return;if(!m)return;const i=t.transformData.type,r="move"===i,s="resize"===i;if(r&&!M)return;"start"===t.state&&(k.current=z,r?(S.current=!0,m.startDrag(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:c,height:d}})):s&&(I.current=!0,m.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:c,height:d},resizeHandle:(null==(o=t.transformData.metadata)?void 0:o.handle)??"se"})));const l=k.current??z;if(r&&t.transformData.changes.rect){const n=t.transformData.changes.rect,o={x:n.origin.x-l.origin.x,y:n.origin.y-l.origin.y},i=m.updateDrag(e,o);A({...l,origin:{x:l.origin.x+i.x,y:l.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const n=t.transformData.changes.rect;m.updateResize(e,n),A(n)}"end"===t.state&&(k.current=null,r&&S.current?(S.current=!1,m.commitDrag(e)):s&&I.current&&(I.current=!1,m.commitResize(e)))},[m,e,c,d,z,M,u]),w=(null==v?void 0:v.color)??"#007ACC",D=(null==v?void 0:v.size)??12,{dragProps:E,resize:B}=a.useInteractionHandles({controller:{element:R,constraints:{minWidth:20,minHeight:20,boundingBox:{width:c,height:d}},maintainAspectRatio:!1,pageRotation:l,scale:s,enabled:!0,onUpdate:C},resizeUI:{handleSize:D,spacing:x,offsetMode:"outside",includeSides:!0,zIndex:f+1},vertexUI:{vertexSize:0,zIndex:f},includeVertices:!1});return u.length<2?null:n.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[n.jsx("div",{...M?E:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:R.origin.x*s,top:R.origin.y*s,width:R.size.width*s,height:R.size.height*s,outline:`2px dashed ${b}`,outlineOffset:x-1,cursor:M?"move":"default",touchAction:"none",zIndex:f},children:P&&B.map(({key:e,...t})=>(null==v?void 0:v.component)?v.component({key:e,...t,backgroundColor:w}):n.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),y&&n.jsx(a.CounterRotate,{rect:{origin:{x:R.origin.x*s,y:R.origin.y*s},size:{width:R.size.width*s,height:R.size.height*s}},rotation:l,children:e=>y({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function f({strokeColor:e,opacity:t=.5,segmentRects:o,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";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:a,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l}},o))})}function y({strokeColor:e,opacity:t=.5,segmentRects:o,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;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},children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:a,opacity:t,pointerEvents:"none"}})},o))})}function m({strokeColor:e,opacity:t=.5,segmentRects:o,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;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},children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:a,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},o))})}function j({strokeColor:e,opacity:t=.5,segmentRects:o,rect:i,scale:r,onClick:s,style:l}){const a=2*r,c=6*r,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e??"#FFFF00"}" stroke-width="${a}" 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},children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},o))})}function k({isSelected:e,strokeColor:t,opacity:i=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=o.useMemo(()=>s.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()}),[s,l]),g=l.size.width*a,p=l.size.height*a;return n.jsx("svg",{style:{position:"absolute",width:g,height:p,pointerEvents:"none",zIndex:2,overflow:"visible"},width:g,height:p,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:u.map((t,o)=>n.jsx("path",{d:t,fill:"none",opacity:i,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},o))})}function S({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:l,strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:p,height:h,x:v,y:b}=o.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]),x=(p+l)*u,f=(h+l)*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2},width:x,height:f,viewBox:`0 0 ${p+l} ${h+l}`,children:n.jsx("rect",{x:v,y:b,width:p,height:h,fill:t,opacity:s,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:l,...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function I({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:l=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:g}){const{width:p,height:h,cx:v,cy:b,rx:x,ry:f}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}},[c,s]),y=p*d,m=h*d;return n.jsx("svg",{style:{position:"absolute",width:y,height:m,pointerEvents:"none",zIndex:2},width:y,height:m,viewBox:`0 0 ${p} ${h}`,children:n.jsx("ellipse",{cx:v,cy:b,rx:x,ry:f,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...l===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function M({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:l="#000000",strokeStyle:a=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:g,scale:p,onClick:h,isSelected:v}){const{x1:b,y1:x,x2:f,y2:y}=o.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=o.useMemo(()=>{const e=Math.atan2(y-x,f-b);return{start:t.patching.createEnding(null==g?void 0:g.start,s,e+Math.PI,b,x),end:t.patching.createEnding(null==g?void 0:g.end,s,e,f,y)}},[g,s,b,x,f,y]),j=d.size.width*p,k=d.size.height*p;return n.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:b,y1:x,x2:f,y2:y,opacity:i,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",pointerEvents:v?"none":"visibleStroke",stroke:l,strokeWidth:s,strokeLinecap:"butt",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:h,onTouchStart:h,stroke:l,style:{cursor:v?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:v?"none":m.start.filled?"visible":"visibleStroke",...a===r.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:h,onTouchStart:h,style:{cursor:v?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:v?"none":m.end.filled?"visible":"visibleStroke",...a===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function P({rect:e,vertices:i,color:r="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const p=o.useMemo(()=>i.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[i,e]),h=o.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]),v=o.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[0],p[1]),o=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,p[p.length-1].x,p[p.length-1].y)}},[p,g,a]),b=e.size.width*c,x=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:b,height:x,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:x,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:h,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:s??r,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),v.start&&n.jsx("path",{d:v.start.d,transform:v.start.transform,stroke:s,fill:v.start.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),v.end&&n.jsx("path",{d:v.end.d,transform:v.end.transform,stroke:s,fill:v.end.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function z({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=r.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:p,currentVertex:h,handleSize:v=14}){const b=h?[...t,h]:t,x=o.useMemo(()=>b.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[b,e]),f=o.useMemo(()=>{if(!x.length)return"";const[e,...t]=x,n=!!h;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[x,h]),y=h&&t.length>0,m=e.size.width*u,j=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:f,onPointerDown:p,onTouchStart:p,opacity:l,style:{fill:h?"none":i,stroke:s??i,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===r.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),y&&t.length>1&&n.jsx("path",{d:`M ${x[x.length-1].x} ${x[x.length-1].y} L ${x[0].x} ${x[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),y&&t.length>=2&&n.jsx("rect",{x:x[0].x-v/u/2,y:x[0].y-v/u/2,width:v/u,height:v/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function R({isSelected:e,isEditing:t,annotation:i,pageIndex:s,scale:l,onClick:a}){const d=o.useRef(null),{provides:u}=v(),[g,p]=o.useState(!1);o.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]),o.useLayoutEffect(()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;p(t)}catch{p(!1)}},[]);const h=i.object.fontSize*l,b=g&&t&&h>0&&h<16,x=b?16:h,f=b?h/16:1,y=b?100/f:100;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(s,i.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:x,fontFamily:r.standardFontCss(i.object.fontFamily),textAlign:r.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===r.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===r.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.color??i.object.backgroundColor,opacity:i.object.opacity,width:b?`${y}%`:"100%",height:b?`${y}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:b?`scale(${f})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:i.object.contents})})}function A({documentId:e,pageIndex:t,annotation:i,scaleFactor:s=1,style:l,...a}){const{provides:c}=v(),[d,u]=o.useState(null),g=o.useRef(null),{width:p,height:h}=i.rect.size;o.useEffect(()=>{if(c){const n=c.forDocument(e).renderAnnotation({pageIndex:t,annotation:i,options:{scaleFactor:s,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);u(t),g.current=t},r.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:r.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,s,c,e,i.id,p,h]);return n.jsx(o.Fragment,{children:d&&n.jsx("img",{src:d,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...a,style:{width:"100%",height:"100%",display:"block",...l||{}}})})}function C({isSelected:e,annotation:t,documentId:o,pageIndex:i,scale:r,onClick:s}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:n.jsx(A,{documentId:o,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function w({isSelected:e,strokeColor:t="#0000FF",strokeWidth:i=2,strokeStyle:s=r.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:p}=o.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),h=g*c,v=p*c,b=o.useMemo(()=>{if(s===r.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*i},${i}`},[s,l,i]),x=s===r.PdfAnnotationBorderStyle.UNDERLINE;return n.jsxs("svg",{style:{position:"absolute",width:h,height:v,pointerEvents:"none",zIndex:2},width:h,height:v,viewBox:`0 0 ${g} ${p}`,children:[n.jsx("rect",{x:0,y:0,width:g,height:p,fill:"transparent",onPointerDown:u?void 0:d,onTouchStart:u?void 0:d,style:{cursor:u?"default":e?"move":"pointer",pointerEvents:u||e?"none":"visible"}}),x?n.jsx("line",{x1:1,y1:p-1,x2:g-1,y2:p-1,stroke:t,strokeWidth:i,strokeDasharray:b,style:{pointerEvents:"none"}}):n.jsx("rect",{x:i/2,y:i/2,width:Math.max(g-i,0),height:Math.max(p-i,0),fill:"transparent",stroke:t,strokeWidth:i,strokeDasharray:b,style:{pointerEvents:"none"}})]})}function D(e){const{documentId:i,pageIndex:a,scale:c,pageWidth:d,pageHeight:u,selectionMenu:g}=e,{provides:p}=v(),{provides:h}=l.useSelectionCapability(),[A,D]=o.useState([]),{register:E}=s.usePointerHandlers({documentId:i,pageIndex:a}),[B,T]=o.useState([]),[$,L]=o.useState(null),F=o.useMemo(()=>p?p.forDocument(i):null,[p,i]),U=B.length>1;o.useEffect(()=>{if(F){const e=F.getState();return D(t.getAnnotationsByPageIndex(e,a)),T(t.getSelectedAnnotationIds(e)),F.onStateChange(e=>{D(t.getAnnotationsByPageIndex(e,a)),T(t.getSelectedAnnotationIds(e))})}},[F,a]);const W=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&F&&(F.deselectAnnotation(),L(null))}}),[F]),O=o.useCallback((e,t)=>{if(e.stopPropagation(),F&&h){h.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?F.toggleSelection(a,t.object.id):F.selectAnnotation(a,t.object.id),t.object.id!==$&&L(null)}},[F,h,$,a]),H=o.useCallback((e,t)=>{if(e.stopPropagation(),F&&h){if(h.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,n=A.find(t=>t.object.id===e);if(n)return void F.selectAnnotation(n.object.pageIndex,e)}F.selectAnnotation(a,t.object.id)}},[F,h,A,a]);o.useEffect(()=>E(W,{documentId:i}),[E,W]);const N=o.useMemo(()=>A.filter(e=>B.includes(e.object.id)),[A,B]),q=o.useMemo(()=>!(N.length<2)&&N.every(e=>{const n=null==F?void 0:F.findToolForAnnotation(e.object),o=t.resolveInteractionProp(null==n?void 0:n.interaction.isGroupDraggable,e.object,!0),i=t.resolveInteractionProp(null==n?void 0:n.interaction.isDraggable,e.object,!0);return void 0!==(null==n?void 0:n.interaction.isGroupDraggable)?o:i}),[N,F]),G=o.useMemo(()=>!(N.length<2)&&N.every(e=>{const n=null==F?void 0:F.findToolForAnnotation(e.object),o=t.resolveInteractionProp(null==n?void 0:n.interaction.isGroupResizable,e.object,!0),i=t.resolveInteractionProp(null==n?void 0:n.interaction.isResizable,e.object,!0);return void 0!==(null==n?void 0:n.interaction.isGroupResizable)?o:i}),[N,F]),V=o.useMemo(()=>{if(!F)return!1;const e=F.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===a)},[F,a,B]);return n.jsxs(n.Fragment,{children:[A.map(s=>{const l=B.includes(s.object.id),d=$===s.object.id,u=null==F?void 0:F.findToolForAnnotation(s.object);for(const o of e.annotationRenderers??[]){const i=o.tryRender(s,{isSelected:l,scale:c,pageIndex:a,onClick:e=>O(e,s)});if(i)return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:()=>i},s.object.id)}if(t.isInk(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(k,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isSquare(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(S,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isCircle(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(I,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isUnderline(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),zIndex:0,style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isStrikeout(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),zIndex:0,style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{...e,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isSquiggly(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),zIndex:0,style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(j,{...e,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isHighlight(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),zIndex:0,style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(f,{...e,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isLine(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(o.Fragment,{children:n.jsx(M,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})})},s.object.id);if(t.isPolyline(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(o.Fragment,{children:n.jsx(P,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})})},s.object.id);if(t.isPolygon(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(o.Fragment,{children:n.jsx(z,{...e,isSelected:l,scale:c,onClick:e=>O(e,s)})})},s.object.id);if(t.isFreeText(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0)&&!d,isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),L(s.object.id)},...e,children:e=>n.jsx(R,{isSelected:l,isEditing:d,annotation:{...s,object:e},pageIndex:a,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isStamp(s))return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),selectionMenu:g,onSelect:e=>O(e,s),style:{mixBlendMode:r.blendModeToCss(s.object.blendMode??r.PdfBlendMode.Normal)},...e,children:e=>n.jsx(C,{isSelected:l,annotation:s,documentId:i,pageIndex:a,scale:c,onClick:e=>O(e,s)})},s.object.id);if(t.isLink(s)){const t=!!s.object.inReplyToId;return n.jsx(b,{trackedAnnotation:s,isSelected:l,isMultiSelected:U,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:g,onSelect:e=>H(e,s),...e,children:e=>n.jsx(w,{...e,isSelected:l,scale:c,onClick:e=>H(e,s),hasIRT:t})},s.object.id)}return null}),V&&N.length>=2&&n.jsx(x,{documentId:i,pageIndex:a,scale:c,rotation:e.rotation,pageWidth:d,pageHeight:u,selectedAnnotations:N,isDraggable:q,isResizable:G,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function E({documentId:e,pageIndex:t,scale:i}){var s,a,c,d,u,g,p,h,b,x,k,S;const{provides:I}=l.useSelectionCapability(),{provides:M}=v(),[P,z]=o.useState([]),[R,A]=o.useState(null),[C,w]=o.useState(null);if(o.useEffect(()=>{if(I)return I.forDocument(e).onSelectionChange(()=>{z(I.forDocument(e).getHighlightRectsForPage(t)),A(I.forDocument(e).getBoundingRectForPage(t))})},[I,e,t]),o.useEffect(()=>{if(M)return w(M.forDocument(e).getActiveTool()),M.forDocument(e).onActiveToolChange(e=>w(e))},[M,e]),!R)return null;if(!C||!C.defaults)return null;switch(C.defaults.type){case r.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(s=C.defaults)?void 0:s.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{strokeColor:null==(a=C.defaults)?void 0:a.strokeColor,opacity:null==(c=C.defaults)?void 0:c.opacity,segmentRects:P,scale:i})});case r.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??r.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{strokeColor:null==(u=C.defaults)?void 0:u.strokeColor,opacity:null==(g=C.defaults)?void 0:g.opacity,segmentRects:P,scale:i})});case r.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(p=C.defaults)?void 0:p.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(m,{strokeColor:null==(h=C.defaults)?void 0:h.strokeColor,opacity:null==(b=C.defaults)?void 0:b.opacity,segmentRects:P,scale:i})});case r.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:r.blendModeToCss((null==(x=C.defaults)?void 0:x.blendMode)??r.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(j,{strokeColor:null==(k=C.defaults)?void 0:k.strokeColor,opacity:null==(S=C.defaults)?void 0:S.opacity,segmentRects:P,scale:i})});default:return null}}function B({preview:e,scale:t}){const{bounds:o}=e,i={position:"absolute",left:o.origin.x*t,top:o.origin.y*t,width:o.size.width*t,height:o.size.height*t,pointerEvents:"none",zIndex:10};return e.type===r.PdfAnnotationSubtype.CIRCLE?n.jsx("div",{style:i,children:n.jsx(I,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:i,children:n.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:i,children:n.jsx(z,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:i,children:n.jsx(P,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.LINE?n.jsx("div",{style:i,children:n.jsx(M,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.INK?n.jsx("div",{style:i,children:n.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===r.PdfAnnotationSubtype.FREETEXT?n.jsx("div",{style:i,children:n.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function T({documentId:e,pageIndex:t,scale:i}){const{plugin:r}=h(),[s,l]=o.useState(new Map),a=o.useRef(null),c=o.useRef(null),d=o.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const n=a.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=c.current;if(!i||!i.getContext)return;const r=i.getContext("2d");if(!r)return;const s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),g=l*u,p=a*u;i.width=g,i.height=p,r.drawImage(s,0,0,g,p);const h=r.getImageData(0,0,g,p);"string"!=typeof e&&URL.revokeObjectURL(s.src),o({imageData:h,width:g,height:p})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,i,{services:d,onPreview:(e,t)=>{l(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,i,r,d]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:a,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(s.entries()).map(([e,t])=>n.jsx(B,{preview:t,scale:i},e))]})}const $=e.createPluginPackage(t.AnnotationPluginPackage).addWrapper(g).build();exports.AnnotationLayer=function({style:e,documentId:t,pageIndex:r,scale:s,rotation:l,selectionMenu:a,groupSelectionMenu:c,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,annotationRenderers:v,...b}){var x,f,y,m;const j=i.useDocumentState(t),k=null==(f=null==(x=null==j?void 0:j.document)?void 0:x.pages)?void 0:f[r],S=(null==(y=null==k?void 0:k.size)?void 0:y.width)??0,I=(null==(m=null==k?void 0:k.size)?void 0:m.height)??0,M=p(),P=o.useMemo(()=>{const e=[...M];for(const t of v??[]){const n=e.findIndex(e=>e.id===t.id);n>=0?e[n]=t:e.push(t)}return e},[M,v]),z=o.useMemo(()=>void 0!==s?s:(null==j?void 0:j.scale)??1,[s,null==j?void 0:j.scale]),R=o.useMemo(()=>{if(void 0!==l)return l;return(((null==k?void 0:k.rotation)??0)+((null==j?void 0:j.rotation)??0))%4},[l,null==k?void 0:k.rotation,null==j?void 0:j.rotation]);return n.jsxs("div",{style:{...e},...b,children:[n.jsx(D,{documentId:t,selectionMenu:a,groupSelectionMenu:c,pageIndex:r,scale:z,rotation:R,pageWidth:S,pageHeight:I,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,annotationRenderers:P}),n.jsx(E,{documentId:t,pageIndex:r,scale:z}),n.jsx(T,{documentId:t,pageIndex:r,scale:z})]})},exports.AnnotationPluginPackage=$,exports.AnnotationRendererProvider=g,exports.GroupSelectionBox=x,exports.createRenderer=function(e){return{id:e.id,tryRender:(t,n)=>e.matches(t.object)?e.render({...n,annotation:t}):null}},exports.useAnnotation=e=>{var n;const{provides:i}=v(),[r,s]=o.useState((null==(n=null==i?void 0:i.forDocument(e))?void 0:n.getState())??t.initialDocumentState());return o.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return s(t.getState()),t.onStateChange(e=>{s(e)})},[i,e]),{state:r,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=v,exports.useAnnotationPlugin=h,exports.useRegisterRenderers=function(e){const t=o.useContext(d),n=o.useRef(e);o.useEffect(()=>{if(t)return t(n.current)},[t])},exports.useRegisteredRenderers=p,exports.useRendererRegistry=function(){return o.useContext(d)},Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-annotation"),o=require("react/jsx-runtime"),n=require("react"),i=require("react-dom"),r=require("@embedpdf/core/react"),l=require("@embedpdf/models"),s=require("@embedpdf/plugin-interaction-manager/react"),a=require("@embedpdf/plugin-selection/react"),c=require("@embedpdf/utils/react"),d={suppressContentEditableWarning:!0},u=n.createContext(null),p=n.createContext([]);function g({children:e}){const[t,i]=n.useState([]),r=n.useCallback(e=>(i(t=>{const o=new Set(e.map(e=>e.id));return[...t.filter(e=>!o.has(e.id)),...e]}),()=>i(t=>t.filter(t=>!e.some(e=>e.id===t.id)))),[]);return o.jsx(u.Provider,{value:r,children:o.jsx(p.Provider,{value:t,children:e})})}function h(){return n.useContext(p)}const v=()=>r.usePlugin(t.AnnotationPlugin.id),b=()=>r.useCapability(t.AnnotationPlugin.id);function x({scale:e,documentId:t,pageIndex:s,rotation:a,pageWidth:d,pageHeight:u,trackedAnnotation:p,children:g,isSelected:h,isMultiSelected:x=!1,isDraggable:f,isResizable:y,isRotatable:m=!0,lockAspectRatio:j=!1,style:k={},vertexConfig:S,selectionMenu:I,outlineOffset:R=1,onDoubleClick:P,onSelect:C,zIndex:M=1,resizeUI:z,vertexUI:w,rotationUI:A,selectionOutlineColor:D,selectionOutline:E,customAnnotationRenderer:B,groupSelectionMenu:$,groupSelectionOutline:T,annotationRenderers:L,...F}){var O,U,W;const[H,N]=n.useState(p.object),[G,q]=n.useState(null),[Y,V]=n.useState(null),[X,K]=n.useState(!1),{provides:Q}=b(),{plugin:Z}=v(),{canModifyAnnotations:J}=r.useDocumentPermissions(t),_=n.useRef(null),ee=J&&f&&!x,te=J&&y&&!x,oe=J&&m&&!x,ne=n.useMemo(()=>Q?Q.forDocument(t):null,[Q,t]),ie=H?{...p.object,...H}:p.object,re=(null==z?void 0:z.color)??"#007ACC",le=(null==w?void 0:w.color)??"#007ACC",se=(null==A?void 0:A.color)??"white",ae=(null==A?void 0:A.connectorColor)??"#007ACC",ce=(null==z?void 0:z.size)??12,de=(null==w?void 0:w.size)??12,ue=(null==A?void 0:A.size)??32,pe=null==A?void 0:A.margin,ge=(null==A?void 0:A.iconColor)??"#007ACC",he=(null==A?void 0:A.showConnector)??!1,ve=(null==(O=null==A?void 0:A.border)?void 0:O.color)??"#007ACC",be=(null==(U=null==A?void 0:A.border)?void 0:U.width)??1,xe=(null==(W=null==A?void 0:A.border)?void 0:W.style)??"solid",fe=(null==E?void 0:E.color)??D??"#007ACC",ye=(null==E?void 0:E.style)??"solid",me=(null==E?void 0:E.width)??1,je=(null==E?void 0:E.offset)??R??1,ke=G??ie.rotation??0,Se=G??ie.rotation??0,Ie=Number.isFinite(Se)?Math.round(10*Se)/10:0,Re=null!==G,Pe=n.useRef(null),Ce=n.useCallback(e=>{var o;if(!(null==(o=e.transformData)?void 0:o.type)||x||!Z)return;const{type:n,changes:i,metadata:r}=e.transformData,l=p.object.id,a={width:d,height:u};if("start"===e.state&&(Pe.current=p.object.unrotatedRect??p.object.rect,_.current=p.object,"move"===n?Z.startDrag(t,{annotationIds:[l],pageSize:a}):"resize"===n&&Z.startResize(t,{annotationIds:[l],pageSize:a,resizeHandle:(null==r?void 0:r.handle)??"se"})),i.rect&&Pe.current)if("move"===n){const e={x:i.rect.origin.x-Pe.current.origin.x,y:i.rect.origin.y-Pe.current.origin.y};Z.updateDrag(t,e)}else"resize"===n&&Z.updateResize(t,i.rect);if("vertex-edit"===n&&i.vertices&&S){const t=_.current??p.object,o=S.transformAnnotation(t,i.vertices),a=null==Q?void 0:Q.transformAnnotation(t,{type:n,changes:o,metadata:r});a&&(N(e=>({...e,...a})),"end"===e.state&&(null==ne||ne.updateAnnotation(s,l,a)))}if("rotate"===n){const o=(null==r?void 0:r.rotationAngle)??ke,n=null==r?void 0:r.cursorPosition;return n&&V({x:n.clientX,y:n.clientY}),void("start"===e.state?(q(o),Z.startRotation(t,{annotationIds:[l],cursorAngle:o,rotationCenter:null==r?void 0:r.rotationCenter})):"move"===e.state?(q(o),Z.updateRotation(t,o,null==r?void 0:r.rotationDelta)):"end"===e.state&&(q(null),V(null),Z.commitRotation(t)))}"end"===e.state&&(Pe.current=null,_.current=null,"move"===n?Z.commitDrag(t):"resize"===n&&Z.commitResize(t))},[Z,t,p.object,d,u,s,x,S,Q,ne,ke]),Me=ie.unrotatedRect,ze=Me??ie.rect,we=Me&&0!==ke?l.inferRotationCenterFromRects(ze,ie.rect,ke):void 0,Ae=ze,{dragProps:De,vertices:Ee,resize:Be,rotation:$e}=c.useInteractionHandles({controller:{element:Ae,vertices:null==S?void 0:S.extractVertices(ie),constraints:{minWidth:10,minHeight:10,boundingBox:{width:d,height:u}},maintainAspectRatio:j,pageRotation:a,annotationRotation:ke,rotationCenter:we,rotationElement:ie.rect,scale:e,enabled:h&&!x,onUpdate:Ce},resizeUI:{handleSize:ce,spacing:je,offsetMode:"outside",includeSides:!j,zIndex:M+1},vertexUI:{vertexSize:de,zIndex:M+2},rotationUI:{handleSize:ue,margin:pe,zIndex:M+3,showConnector:he},includeVertices:!!S,includeRotation:oe,currentRotation:ke}),Te=n.useMemo(()=>{if(J&&P)return P},[J,P]),Le=c.useDoublePressProps(Te);n.useEffect(()=>{N(p.object)},[p.object]),n.useEffect(()=>{if(!Z)return;const e=p.object.id,o=o=>{var n;if(o.documentId!==t)return;"end"!==o.type&&"cancel"!==o.type||q(null);const i=null==(n=o.previewPatches)?void 0:n[e];"update"===o.type&&i?N(e=>({...e,...i})):"cancel"===o.type&&N(p.object)},n=[Z.onDragChange(o),Z.onResizeChange(o),Z.onRotateChange(o)];return()=>n.forEach(e=>e())},[Z,t,p.object]);const Fe=h&&!x,Oe=ie.rect.size.width*e,Ue=ie.rect.size.height*e,We=ze.size.width*e,He=ze.size.height*e,Ne=Boolean(Me)&&0!==ke,Ge=Ne?(ze.origin.x-ie.rect.origin.x)*e:(Oe-We)/2,qe=Ne?(ze.origin.y-ie.rect.origin.y)*e:(Ue-He)/2,Ye=Ne&&we?`${(we.x-ze.origin.x)*e}px ${(we.y-ze.origin.y)*e}px`:"center center",Ve=we?(we.x-ie.rect.origin.x)*e:Oe/2,Xe=we?(we.y-ie.rect.origin.y)*e:Ue/2,Ke=Math.max(300,Math.max(Oe,Ue)+80),Qe=n.useMemo(()=>Me?{...ie,rect:Me}:ie,[ie,Me]);return o.jsxs("div",{"data-no-interaction":!0,children:[o.jsxs("div",{style:{position:"absolute",left:ie.rect.origin.x*e,top:ie.rect.origin.y*e,width:Oe,height:Ue,pointerEvents:"none",zIndex:M,...k},...F,children:[Re&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{position:"absolute",left:Ve-Ke/2,top:Xe,width:Ke,height:1,backgroundColor:ae,opacity:.35,pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",left:Ve,top:Xe-Ke/2,width:1,height:Ke,backgroundColor:ae,opacity:.35,pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",left:Ve-Ke/2,top:Xe,width:Ke,height:1,transformOrigin:"center center",transform:`rotate(${ke}deg)`,backgroundColor:ae,opacity:.8,pointerEvents:"none"}})]}),h&&oe&&$e&&((null==A?void 0:A.component)?o.jsx("div",{onPointerEnter:()=>K(!0),onPointerLeave:()=>{K(!1),V(null)},onPointerMove:e=>{Re||V({x:e.clientX,y:e.clientY})},style:{display:"contents"},children:A.component({...$e.handle,backgroundColor:se,iconColor:ge,connectorStyle:{...$e.connector.style,backgroundColor:ae,opacity:Re?0:1},showConnector:he,opacity:Re?0:1,border:{color:ve,width:be,style:xe}})}):o.jsxs("div",{onPointerEnter:()=>K(!0),onPointerLeave:()=>{K(!1),V(null)},onPointerMove:e=>{Re||V({x:e.clientX,y:e.clientY})},style:{display:"contents"},children:[he&&o.jsx("div",{style:{...$e.connector.style,backgroundColor:ae,opacity:Re?0:1}}),o.jsx("div",{...$e.handle,style:{...$e.handle.style,backgroundColor:se,border:`${be}px ${xe} ${ve}`,boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",opacity:Re?0:1},children:o.jsxs("svg",{width:Math.round(.6*ue),height:Math.round(.6*ue),viewBox:"0 0 24 24",fill:"none",stroke:ge,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),o.jsx("path",{d:"M21 3v5h-5"})]})})]})),o.jsxs("div",{...ee&&h?De:{},...Le,style:{position:"absolute",left:Ge,top:qe,width:We,height:He,transform:0!==ke?`rotate(${ke}deg)`:void 0,transformOrigin:Ye,outline:Fe?`${me}px ${ye} ${fe}`:"none",outlineOffset:Fe?`${je}px`:"0px",pointerEvents:h&&!x?"auto":"none",touchAction:"none",cursor:h&&ee?"move":"default"},children:[(()=>{const t="function"==typeof g?g(Qe):g,o=null==B?void 0:B({annotation:Qe,children:t,isSelected:h,scale:e,rotation:a,pageWidth:d,pageHeight:u,pageIndex:s,onSelect:C});return null!=o?o:t})(),h&&te&&!Re&&Be.map(({key:e,...t})=>(null==z?void 0:z.component)?z.component({key:e,...t,backgroundColor:re}):o.jsx("div",{...t,style:{...t.style,backgroundColor:re}},e)),h&&J&&!x&&!Re&&Ee.map(({key:e,...t})=>(null==w?void 0:w.component)?w.component({key:e,...t,backgroundColor:le}):o.jsx("div",{...t,style:{...t.style,backgroundColor:le}},e))]})]}),I&&!x&&!Re&&o.jsx(c.CounterRotate,{rect:{origin:{x:ie.rect.origin.x*e,y:ie.rect.origin.y*e},size:{width:ie.rect.size.width*e,height:ie.rect.size.height*e}},rotation:a,children:e=>{const t=((ke+90*a)%360+360)%360;return I({...e,context:{type:"annotation",annotation:p,pageIndex:s},selected:h,placement:{suggestTop:oe&&t>90&&t<270}})}}),(Re||X)&&Y&&i.createPortal(o.jsxs("div",{style:{position:"fixed",left:Y.x+16,top:Y.y-16,background:"rgba(0,0,0,0.8)",color:"#fff",padding:"4px 8px",borderRadius:4,fontSize:12,fontFamily:"monospace",pointerEvents:"none",zIndex:1e4,whiteSpace:"nowrap"},children:[Ie.toFixed(0),"°"]}),document.body)]})}function f({documentId:e,pageIndex:t,scale:s,rotation:a,pageWidth:d,pageHeight:u,selectedAnnotations:p,isDraggable:g,isResizable:h,isRotatable:b=!0,lockAspectRatio:x=!1,resizeUI:f,rotationUI:y,selectionOutlineColor:m,outlineOffset:j,selectionOutline:k,zIndex:S=2,groupSelectionMenu:I}){var R,P,C;const{plugin:M}=v(),{canModifyAnnotations:z}=r.useDocumentPermissions(e),w=n.useRef(null),A=n.useRef(!1),D=n.useRef(!1),[E,B]=n.useState(null),[$,T]=n.useState(null),[L,F]=n.useState(!1),O=z&&g,U=z&&h,W=z&&b,H=n.useMemo(()=>{const e=p.map(e=>e.object.rect);return l.boundingRectOrEmpty(e)},[p]),[N,G]=n.useState(H);n.useEffect(()=>{A.current||D.current||G(H)},[H]),n.useEffect(()=>{if(!M)return;return M.onRotateChange(t=>{t.documentId===e&&("end"!==t.type&&"cancel"!==t.type||B(null))})},[M,e]);const q=n.useCallback(t=>{var o,n,i,r,l,s;if(!(null==(o=t.transformData)?void 0:o.type))return;if(!M)return;const a=t.transformData.type,c="move"===a,g="resize"===a;if(c&&!O)return;if("start"===t.state&&(w.current=H,c?(A.current=!0,M.startDrag(e,{annotationIds:p.map(e=>e.object.id),pageSize:{width:d,height:u}})):g&&(D.current=!0,M.startResize(e,{annotationIds:p.map(e=>e.object.id),pageSize:{width:d,height:u},resizeHandle:(null==(n=t.transformData.metadata)?void 0:n.handle)??"se"}))),"rotate"===a){if(!b)return;const o=p.map(e=>e.object.id),n=(null==(i=t.transformData.metadata)?void 0:i.rotationAngle)??0,a=null==(r=t.transformData.metadata)?void 0:r.cursorPosition;return a&&T({x:a.clientX,y:a.clientY}),void("start"===t.state?(B(n),M.startRotation(e,{annotationIds:o,cursorAngle:n,rotationCenter:null==(l=t.transformData.metadata)?void 0:l.rotationCenter})):"move"===t.state?(B(n),M.updateRotation(e,n,null==(s=t.transformData.metadata)?void 0:s.rotationDelta)):"end"===t.state&&(B(null),T(null),M.commitRotation(e)))}const h=w.current??H;if(c&&t.transformData.changes.rect){const o=t.transformData.changes.rect,n={x:o.origin.x-h.origin.x,y:o.origin.y-h.origin.y},i=M.updateDrag(e,n);G({...h,origin:{x:h.origin.x+i.x,y:h.origin.y+i.y}})}else if(g&&t.transformData.changes.rect){const o=t.transformData.changes.rect;M.updateResize(e,o),G(o)}"end"===t.state&&(w.current=null,c&&A.current?(A.current=!1,M.commitDrag(e)):g&&D.current&&(D.current=!1,M.commitResize(e)))},[M,e,d,u,H,O,p,b]),Y=E??0,V=null!==E,X=Number.isFinite(Y)?Math.round(10*Y)/10:0,K=(null==f?void 0:f.color)??"#007ACC",Q=(null==f?void 0:f.size)??12,Z=(null==y?void 0:y.color)??"white",J=(null==y?void 0:y.connectorColor)??"#007ACC",_=(null==y?void 0:y.size)??32,ee=null==y?void 0:y.margin,te=(null==y?void 0:y.iconColor)??"#007ACC",oe=(null==y?void 0:y.showConnector)??!1,ne=(null==(R=null==y?void 0:y.border)?void 0:R.color)??"#007ACC",ie=(null==(P=null==y?void 0:y.border)?void 0:P.width)??1,re=(null==(C=null==y?void 0:y.border)?void 0:C.style)??"solid",le=(null==k?void 0:k.color)??m??"#007ACC",se=(null==k?void 0:k.style)??"dashed",ae=(null==k?void 0:k.width)??2,ce=(null==k?void 0:k.offset)??j??2,{dragProps:de,resize:ue,rotation:pe}=c.useInteractionHandles({controller:{element:N,constraints:{minWidth:20,minHeight:20,boundingBox:{width:d,height:u}},maintainAspectRatio:x,pageRotation:a,scale:s,enabled:!0,onUpdate:q},resizeUI:{handleSize:Q,spacing:ce,offsetMode:"outside",includeSides:!x,zIndex:S+1},vertexUI:{vertexSize:0,zIndex:S},rotationUI:{handleSize:_,margin:ee,zIndex:S+2,showConnector:oe},includeVertices:!1,includeRotation:W,currentRotation:E??0});if(p.length<2)return null;const ge=N.size.width*s,he=N.size.height*s,ve=ge/2,be=he/2,xe=Math.max(300,Math.max(ge,he)+80);return o.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[o.jsxs("div",{style:{position:"absolute",left:N.origin.x*s,top:N.origin.y*s,width:ge,height:he,pointerEvents:"none",zIndex:S},children:[V&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{position:"absolute",left:ve-xe/2,top:be,width:xe,height:1,backgroundColor:K,opacity:.35,pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",left:ve,top:be-xe/2,width:1,height:xe,backgroundColor:K,opacity:.35,pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",left:ve-xe/2,top:be,width:xe,height:1,transformOrigin:"center center",transform:`rotate(${Y}deg)`,backgroundColor:K,opacity:.8,pointerEvents:"none"}})]}),W&&pe&&((null==y?void 0:y.component)?o.jsx("div",{onPointerEnter:()=>F(!0),onPointerLeave:()=>{F(!1),T(null)},onPointerMove:e=>{V||T({x:e.clientX,y:e.clientY})},style:{display:"contents"},children:y.component({...pe.handle,backgroundColor:Z,iconColor:te,connectorStyle:{...pe.connector.style,backgroundColor:J,opacity:V?0:1},showConnector:oe,opacity:V?0:1,border:{color:ne,width:ie,style:re}})}):o.jsxs("div",{onPointerEnter:()=>F(!0),onPointerLeave:()=>{F(!1),T(null)},onPointerMove:e=>{V||T({x:e.clientX,y:e.clientY})},style:{display:"contents"},children:[oe&&o.jsx("div",{style:{...pe.connector.style,backgroundColor:J,opacity:V?0:1}}),o.jsx("div",{...pe.handle,style:{...pe.handle.style,backgroundColor:Z,border:`${ie}px ${re} ${ne}`,boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",opacity:V?0:1},children:o.jsxs("svg",{width:Math.round(.6*_),height:Math.round(.6*_),viewBox:"0 0 24 24",fill:"none",stroke:te,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),o.jsx("path",{d:"M21 3v5h-5"})]})})]})),o.jsx("div",{...O?de:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:0,top:0,width:ge,height:he,outline:V?"none":`${ae}px ${se} ${le}`,outlineOffset:ce-1,cursor:O?"move":"default",touchAction:"none",pointerEvents:"auto"},children:U&&!V&&ue.map(({key:e,...t})=>(null==f?void 0:f.component)?f.component({key:e,...t,backgroundColor:K}):o.jsx("div",{...t,style:{...t.style,backgroundColor:K}},e))})]}),(V||L)&&$&&i.createPortal(o.jsxs("div",{style:{position:"fixed",left:$.x+16,top:$.y-16,background:"rgba(0,0,0,0.8)",color:"#fff",padding:"4px 8px",borderRadius:4,fontSize:12,fontFamily:"monospace",pointerEvents:"none",zIndex:1e4,whiteSpace:"nowrap"},children:[X.toFixed(0),"°"]}),document.body),I&&o.jsx(c.CounterRotate,{rect:{origin:{x:N.origin.x*s,y:N.origin.y*s},size:{width:N.size.width*s,height:N.size.height*s}},rotation:a,children:e=>{const o=((Y+90*a)%360+360)%360;return I({...e,context:{type:"group",annotations:p,pageIndex:t},selected:!0,placement:{suggestTop:W&&o>90&&o<270}})}})]})}function y({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:l,style:s}){const a=e??"#FFFF00";return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:a,opacity:t,pointerEvents:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:void 0,...s}},n))})}function m({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:l,style:s}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...s},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:a,opacity:t,pointerEvents:"none"}})},n))})}function j({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:l,style:s}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...s},children:o.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:a,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},n))})}function k({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:l,style:s}){const a=2*r,c=6*r,d=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*a}" viewBox="0 0 ${c} ${2*a}">\n <path d="M0 ${a} Q ${c/4} 0 ${c/2} ${a} T ${c} ${a}"\n fill="none" stroke="${e??"#FFFF00"}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...s},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n))})}function S({isSelected:e,strokeColor:t,opacity:i=1,strokeWidth:r,inkList:l,rect:s,scale:a,onClick:c}){const d=t??"#000000",u=n.useMemo(()=>l.map(({points:e})=>{let t="";return e.forEach(({x:e,y:o},n)=>{const i=e-s.origin.x,r=o-s.origin.y;t+=(0===n?"M":"L")+i+" "+r+" "}),t.trim()}),[l,s]),p=s.size.width*a,g=s.size.height*a;return o.jsx("svg",{style:{position:"absolute",width:p,height:g,pointerEvents:"none",zIndex:2,overflow:"visible"},width:p,height:g,viewBox:`0 0 ${s.size.width} ${s.size.height}`,children:u.map((t,n)=>o.jsx("path",{d:t,fill:"none",opacity:i,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},n))})}function I({isSelected:e,color:t="#000000",strokeColor:i,opacity:r=1,strokeWidth:s,strokeStyle:a=l.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:p}){const{width:g,height:h,x:v,y:b}=n.useMemo(()=>{const e=d.size.width,t=d.size.height;return{width:Math.max(e-s,0),height:Math.max(t-s,0),x:s/2,y:s/2}},[d,s]),x=(g+s)*u,f=(h+s)*u;return o.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2},width:x,height:f,viewBox:`0 0 ${g+s} ${h+s}`,children:o.jsx("rect",{x:v,y:b,width:g,height:h,fill:t,opacity:r,onPointerDown:p,onTouchStart:p,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:s,...a===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function R({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=l.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:p}){const{width:g,height:h,cx:v,cy:b,rx:x,ry:f}=n.useMemo(()=>{const e=c.size.width,t=c.size.height,o=Math.max(e-r,0),n=Math.max(t-r,0);return{width:e,height:t,cx:r/2+o/2,cy:r/2+n/2,rx:o/2,ry:n/2}},[c,r]),y=g*d,m=h*d;return o.jsx("svg",{style:{position:"absolute",width:y,height:m,pointerEvents:"none",zIndex:2},width:y,height:m,viewBox:`0 0 ${g} ${h}`,children:o.jsx("ellipse",{cx:v,cy:b,rx:x,ry:f,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:p?"move":"pointer",pointerEvents:p?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function P({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:s="#000000",strokeStyle:a=l.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:p,scale:g,onClick:h,isSelected:v}){const{x1:b,y1:x,x2:f,y2:y}=n.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=n.useMemo(()=>{const e=Math.atan2(y-x,f-b);return{start:t.patching.createEnding(null==p?void 0:p.start,r,e+Math.PI,b,x),end:t.patching.createEnding(null==p?void 0:p.end,r,e,f,y)}},[p,r,b,x,f,y]),j=d.size.width*g,k=d.size.height*g;return o.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[o.jsx("line",{x1:b,y1:x,x2:f,y2:y,opacity:i,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",pointerEvents:v?"none":"visibleStroke",stroke:s,strokeWidth:r,strokeLinecap:"butt",...a===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&o.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:h,onTouchStart:h,stroke:s,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.start.filled?"visible":"visibleStroke",...a===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&o.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:s,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.end.filled?"visible":"visibleStroke",...a===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function C({rect:e,vertices:i,color:r="transparent",strokeColor:l="#000000",opacity:s=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:p}){const g=n.useMemo(()=>i.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[i,e]),h=n.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]),v=n.useMemo(()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),o=e(g[0],g[1]),n=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==p?void 0:p.start,a,o+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==p?void 0:p.end,a,n,g[g.length-1].x,g[g.length-1].y)}},[g,p,a]),b=e.size.width*c,x=e.size.height*c;return o.jsxs("svg",{style:{position:"absolute",width:b,height:x,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:x,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.jsx("path",{d:h,onPointerDown:u,onTouchStart:u,opacity:s,style:{fill:"none",stroke:l??r,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),v.start&&o.jsx("path",{d:v.start.d,transform:v.start.transform,stroke:l,fill:v.start.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),v.end&&o.jsx("path",{d:v.end.d,transform:v.end.transform,stroke:l,fill:v.end.filled?r:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":v.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function M({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,strokeStyle:c=l.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:p,onClick:g,currentVertex:h,handleSize:v=14}){const b=h?[...t,h]:t,x=n.useMemo(()=>b.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[b,e]),f=n.useMemo(()=>{if(!x.length)return"";const[e,...t]=x,o=!!h;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(o?"":" Z")).trim()},[x,h]),y=h&&t.length>0,m=e.size.width*u,j=e.size.height*u;return o.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.jsx("path",{d:f,onPointerDown:g,onTouchStart:g,opacity:s,style:{fill:h?"none":i,stroke:r??i,strokeWidth:a,cursor:p?"move":"pointer",pointerEvents:p?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===l.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),y&&t.length>1&&o.jsx("path",{d:`M ${x[x.length-1].x} ${x[x.length-1].y} L ${x[0].x} ${x[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),y&&t.length>=2&&o.jsx("rect",{x:x[0].x-v/u/2,y:x[0].y-v/u/2,width:v/u,height:v/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function z({isSelected:e,isEditing:t,annotation:i,pageIndex:r,scale:s,onClick:a}){const c=n.useRef(null),{provides:u}=b(),[p,g]=n.useState(!1);n.useEffect(()=>{if(t&&c.current){const e=c.current;e.focus();const t=window.getSelection();if(t){const o=document.createRange();o.selectNodeContents(e),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}}},[t]),n.useLayoutEffect(()=>{try{const e=navigator,t=/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&(null==e?void 0:e.maxTouchPoints)>1;g(t)}catch{g(!1)}},[]);const h=i.object.fontSize*s,v=p&&t&&h>0&&h<16,x=v?16:h,f=v?h/16:1,y=v?100/f:100;return o.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*s,height:i.object.rect.size.height*s,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:o.jsx("span",{ref:c,onBlur:()=>{u&&c.current&&u.updateAnnotation(r,i.object.id,{contents:c.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:x,...l.standardFontCssProperties(i.object.fontFamily),textAlign:l.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===l.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===l.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.color??i.object.backgroundColor,opacity:i.object.opacity,width:v?`${y}%`:"100%",height:v?`${y}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${f})`:void 0,transformOrigin:"top left"},contentEditable:t,...d,children:i.object.contents})})}function w({documentId:e,pageIndex:t,annotation:i,scaleFactor:r=1,unrotated:s,style:a,...c}){const{provides:d}=b(),[u,p]=n.useState(null),g=n.useRef(null),{width:h,height:v}=i.rect.size;n.useEffect(()=>{if(d){const o=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:i,options:{scaleFactor:r,dpr:window.devicePixelRatio,unrotated:s}});return o.wait(e=>{const t=URL.createObjectURL(e);p(t),g.current=t},l.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):o.abort({code:l.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,r,s,d,e,i.id,h,v]);return o.jsx(n.Fragment,{children:u&&o.jsx("img",{src:u,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function A({isSelected:e,annotation:t,documentId:n,pageIndex:i,scale:r,onClick:l}){const s=!!t.object.rotation&&!!t.object.unrotatedRect;return o.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:l,onTouchStart:l,children:o.jsx(w,{documentId:n,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:r,unrotated:s})})}function D({isSelected:e,strokeColor:t="#0000FF",strokeWidth:i=2,strokeStyle:r=l.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:s,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:p,height:g}=n.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),h=p*c,v=g*c,b=n.useMemo(()=>{if(r===l.PdfAnnotationBorderStyle.DASHED)return(null==s?void 0:s.join(","))??`${3*i},${i}`},[r,s,i]),x=r===l.PdfAnnotationBorderStyle.UNDERLINE;return o.jsxs("svg",{style:{position:"absolute",width:h,height:v,pointerEvents:"none",zIndex:2},width:h,height:v,viewBox:`0 0 ${p} ${g}`,children:[o.jsx("rect",{x:0,y:0,width:p,height:g,fill:"transparent",onPointerDown:u?void 0:d,onTouchStart:u?void 0:d,style:{cursor:u?"default":e?"move":"pointer",pointerEvents:u||e?"none":"visible"}}),x?o.jsx("line",{x1:1,y1:g-1,x2:p-1,y2:g-1,stroke:t,strokeWidth:i,strokeDasharray:b,style:{pointerEvents:"none"}}):o.jsx("rect",{x:i/2,y:i/2,width:Math.max(p-i,0),height:Math.max(g-i,0),fill:"transparent",stroke:t,strokeWidth:i,strokeDasharray:b,style:{pointerEvents:"none"}})]})}function E(e){const{documentId:i,pageIndex:r,scale:c,pageWidth:d,pageHeight:u,selectionMenu:p}=e,{provides:g}=b(),{provides:h}=a.useSelectionCapability(),[v,w]=n.useState([]),{register:E}=s.usePointerHandlers({documentId:i,pageIndex:r}),[B,$]=n.useState([]),[T,L]=n.useState(null),F=n.useMemo(()=>g?g.forDocument(i):null,[g,i]),O=B.length>1;n.useEffect(()=>{if(F){const e=F.getState();return w(t.getAnnotationsByPageIndex(e,r)),$(t.getSelectedAnnotationIds(e)),F.onStateChange(e=>{w(t.getAnnotationsByPageIndex(e,r)),$(t.getSelectedAnnotationIds(e))})}},[F,r]);const U=n.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&F&&(F.deselectAnnotation(),L(null))}}),[F]),W=n.useCallback((e,t)=>{if(e.stopPropagation(),F&&h){h.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?F.toggleSelection(r,t.object.id):F.selectAnnotation(r,t.object.id),t.object.id!==T&&L(null)}},[F,h,T,r]),H=n.useCallback((e,t)=>{if(e.stopPropagation(),F&&h){if(h.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,o=v.find(t=>t.object.id===e);if(o)return void F.selectAnnotation(o.object.pageIndex,e)}F.selectAnnotation(r,t.object.id)}},[F,h,v,r]);n.useEffect(()=>E(U,{documentId:i}),[E,U]);const N=n.useMemo(()=>v.filter(e=>B.includes(e.object.id)),[v,B]),G=n.useMemo(()=>!(N.length<2)&&N.every(e=>{const o=null==F?void 0:F.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.isGroupDraggable,e.object,!0),i=t.resolveInteractionProp(null==o?void 0:o.interaction.isDraggable,e.object,!0);return void 0!==(null==o?void 0:o.interaction.isGroupDraggable)?n:i}),[N,F]),q=n.useMemo(()=>!(N.length<2)&&N.every(e=>{const o=null==F?void 0:F.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.isGroupResizable,e.object,!0),i=t.resolveInteractionProp(null==o?void 0:o.interaction.isResizable,e.object,!0);return void 0!==(null==o?void 0:o.interaction.isGroupResizable)?n:i}),[N,F]),Y=n.useMemo(()=>!(N.length<2)&&N.every(e=>{const o=null==F?void 0:F.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.isGroupRotatable,e.object,!0),i=t.resolveInteractionProp(null==o?void 0:o.interaction.isRotatable,e.object,!0);return void 0!==(null==o?void 0:o.interaction.isGroupRotatable)?n:i}),[N,F]),V=n.useMemo(()=>!(N.length<2)&&N.some(e=>{const o=null==F?void 0:F.findToolForAnnotation(e.object),n=t.resolveInteractionProp(null==o?void 0:o.interaction.lockGroupAspectRatio,e.object,!1),i=t.resolveInteractionProp(null==o?void 0:o.interaction.lockAspectRatio,e.object,!1);return void 0!==(null==o?void 0:o.interaction.lockGroupAspectRatio)?n:i}),[N,F]),X=n.useMemo(()=>{if(!F)return!1;const e=F.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===r)},[F,r,B]);return o.jsxs(o.Fragment,{children:[v.map(s=>{const a=B.includes(s.object.id),d=T===s.object.id,u=null==F?void 0:F.findToolForAnnotation(s.object);for(const n of e.annotationRenderers??[]){const i=n.tryRender(s,{isSelected:a,scale:c,pageIndex:r,onClick:e=>W(e,s)});if(i)return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!1),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:()=>i},s.object.id)}if(t.isInk(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(S,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isSquare(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(I,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isCircle(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(R,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isUnderline(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!1),selectionMenu:p,onSelect:e=>W(e,s),zIndex:0,style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(m,{...e,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isStrikeout(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!1),selectionMenu:p,onSelect:e=>W(e,s),zIndex:0,style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(j,{...e,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isSquiggly(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!1),selectionMenu:p,onSelect:e=>W(e,s),zIndex:0,style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(k,{...e,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isHighlight(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!1),selectionMenu:p,onSelect:e=>W(e,s),zIndex:0,style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(y,{...e,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isLine(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(P,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})})},s.object.id);if(t.isPolyline(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(C,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})})},s.object.id);if(t.isPolygon(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(M,{...e,isSelected:a,scale:c,onClick:e=>W(e,s)})})},s.object.id);if(t.isFreeText(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0)&&!d,isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),L(s.object.id)},...e,children:e=>o.jsx(z,{isSelected:a,isEditing:d,annotation:{...s,object:e},pageIndex:r,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isStamp(s))return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,s.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,s.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,s.object,!1),isRotatable:t.resolveInteractionProp(null==u?void 0:u.interaction.isRotatable,s.object,!0),selectionMenu:p,onSelect:e=>W(e,s),style:{mixBlendMode:l.blendModeToCss(s.object.blendMode??l.PdfBlendMode.Normal)},...e,children:e=>o.jsx(A,{isSelected:a,annotation:s,documentId:i,pageIndex:r,scale:c,onClick:e=>W(e,s)})},s.object.id);if(t.isLink(s)){const t=!!s.object.inReplyToId;return o.jsx(x,{trackedAnnotation:s,isSelected:a,isMultiSelected:O,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,isRotatable:!1,selectionMenu:t?void 0:p,onSelect:e=>H(e,s),...e,children:e=>o.jsx(D,{...e,isSelected:a,scale:c,onClick:e=>H(e,s),hasIRT:t})},s.object.id)}return null}),X&&N.length>=2&&o.jsx(f,{documentId:i,pageIndex:r,scale:c,rotation:e.rotation,pageWidth:d,pageHeight:u,selectedAnnotations:N,isDraggable:G,isResizable:q,isRotatable:Y,lockAspectRatio:V,resizeUI:e.resizeUI,rotationUI:e.rotationUI,selectionOutlineColor:e.selectionOutlineColor,selectionOutline:e.groupSelectionOutline??e.selectionOutline,groupSelectionMenu:e.groupSelectionMenu})]})}function B({documentId:e,pageIndex:t,scale:i}){var r,s,c,d,u,p,g,h,v,x,f,S;const{provides:I}=a.useSelectionCapability(),{provides:R}=b(),[P,C]=n.useState([]),[M,z]=n.useState(null),[w,A]=n.useState(null);if(n.useEffect(()=>{if(I)return I.forDocument(e).onSelectionChange(()=>{C(I.forDocument(e).getHighlightRectsForPage(t)),z(I.forDocument(e).getBoundingRectForPage(t))})},[I,e,t]),n.useEffect(()=>{if(R)return A(R.forDocument(e).getActiveTool()),R.forDocument(e).onActiveToolChange(e=>A(e))},[R,e]),!M)return null;if(!w||!w.defaults)return null;switch(w.defaults.type){case l.PdfAnnotationSubtype.UNDERLINE:return o.jsx("div",{style:{mixBlendMode:l.blendModeToCss((null==(r=w.defaults)?void 0:r.blendMode)??l.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(m,{strokeColor:null==(s=w.defaults)?void 0:s.strokeColor,opacity:null==(c=w.defaults)?void 0:c.opacity,segmentRects:P,scale:i})});case l.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:l.blendModeToCss((null==(d=w.defaults)?void 0:d.blendMode)??l.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(y,{strokeColor:null==(u=w.defaults)?void 0:u.strokeColor,opacity:null==(p=w.defaults)?void 0:p.opacity,segmentRects:P,scale:i})});case l.PdfAnnotationSubtype.STRIKEOUT:return o.jsx("div",{style:{mixBlendMode:l.blendModeToCss((null==(g=w.defaults)?void 0:g.blendMode)??l.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(j,{strokeColor:null==(h=w.defaults)?void 0:h.strokeColor,opacity:null==(v=w.defaults)?void 0:v.opacity,segmentRects:P,scale:i})});case l.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:l.blendModeToCss((null==(x=w.defaults)?void 0:x.blendMode)??l.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(k,{strokeColor:null==(f=w.defaults)?void 0:f.strokeColor,opacity:null==(S=w.defaults)?void 0:S.opacity,segmentRects:P,scale:i})});default:return null}}function $({preview:e,scale:t}){const{bounds:n}=e,i={position:"absolute",left:n.origin.x*t,top:n.origin.y*t,width:n.size.width*t,height:n.size.height*t,pointerEvents:"none",zIndex:10};return e.type===l.PdfAnnotationSubtype.CIRCLE?o.jsx("div",{style:i,children:o.jsx(R,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:i,children:o.jsx(I,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.POLYGON?o.jsx("div",{style:i,children:o.jsx(M,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.POLYLINE?o.jsx("div",{style:i,children:o.jsx(C,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.LINE?o.jsx("div",{style:i,children:o.jsx(P,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.INK?o.jsx("div",{style:i,children:o.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===l.PdfAnnotationSubtype.FREETEXT?o.jsx("div",{style:i,children:o.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function T({documentId:e,pageIndex:t,scale:i}){const{plugin:r}=v(),[l,s]=n.useState(new Map),a=n.useRef(null),c=n.useRef(null),d=n.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const o=a.current;o.accept=e,o.onchange=e=>{var n;const i=null==(n=e.target.files)?void 0:n[0];i&&(t(i),o.value="")},o.click()},processImage:({source:e,maxWidth:t,maxHeight:o,onComplete:n})=>{const i=c.current;if(!i||!i.getContext)return;const r=i.getContext("2d");if(!r)return;const l=new Image;l.crossOrigin="Anonymous",l.onload=()=>{let{naturalWidth:s,naturalHeight:a}=l;const c=t?t/s:1,d=o?o/a:1,u=Math.min(c,d,1),p=s*u,g=a*u;i.width=p,i.height=g,r.drawImage(l,0,0,p,g);const h=r.getImageData(0,0,p,g);"string"!=typeof e&&URL.revokeObjectURL(l.src),n({imageData:h,width:p,height:g})},l.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return n.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,i,{services:d,onPreview:(e,t)=>{s(o=>{const n=new Map(o);return t?n.set(e,t):n.delete(e),n})}})},[e,t,i,r,d]),o.jsxs(o.Fragment,{children:[o.jsx("input",{ref:a,type:"file",style:{display:"none"}}),o.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(l.entries()).map(([e,t])=>o.jsx($,{preview:t,scale:i},e))]})}const L=e.createPluginPackage(t.AnnotationPluginPackage).addWrapper(g).build();exports.AnnotationLayer=function({style:e,documentId:t,pageIndex:i,scale:l,rotation:s,selectionMenu:a,groupSelectionMenu:c,resizeUI:d,vertexUI:u,rotationUI:p,selectionOutlineColor:g,selectionOutline:v,groupSelectionOutline:b,customAnnotationRenderer:x,annotationRenderers:f,...y}){var m,j,k,S;const I=r.useDocumentState(t),R=null==(j=null==(m=null==I?void 0:I.document)?void 0:m.pages)?void 0:j[i],P=(null==(k=null==R?void 0:R.size)?void 0:k.width)??0,C=(null==(S=null==R?void 0:R.size)?void 0:S.height)??0,M=h(),z=n.useMemo(()=>{const e=[...M];for(const t of f??[]){const o=e.findIndex(e=>e.id===t.id);o>=0?e[o]=t:e.push(t)}return e},[M,f]),w=n.useMemo(()=>void 0!==l?l:(null==I?void 0:I.scale)??1,[l,null==I?void 0:I.scale]),A=n.useMemo(()=>{if(void 0!==s)return s;return(((null==R?void 0:R.rotation)??0)+((null==I?void 0:I.rotation)??0))%4},[s,null==R?void 0:R.rotation,null==I?void 0:I.rotation]);return o.jsxs("div",{style:{...e},...y,children:[o.jsx(E,{documentId:t,selectionMenu:a,groupSelectionMenu:c,pageIndex:i,scale:w,rotation:A,pageWidth:P,pageHeight:C,resizeUI:d,vertexUI:u,rotationUI:p,selectionOutlineColor:g,selectionOutline:v,groupSelectionOutline:b,customAnnotationRenderer:x,annotationRenderers:z}),o.jsx(B,{documentId:t,pageIndex:i,scale:w}),o.jsx(T,{documentId:t,pageIndex:i,scale:w})]})},exports.AnnotationPluginPackage=L,exports.AnnotationRendererProvider=g,exports.GroupSelectionBox=f,exports.createRenderer=function(e){return{id:e.id,tryRender:(t,o)=>e.matches(t.object)?e.render({...o,annotation:t}):null}},exports.useAnnotation=e=>{var o;const{provides:i}=b(),[r,l]=n.useState((null==(o=null==i?void 0:i.forDocument(e))?void 0:o.getState())??t.initialDocumentState());return n.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return l(t.getState()),t.onStateChange(e=>{l(e)})},[i,e]),{state:r,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=b,exports.useAnnotationPlugin=v,exports.useRegisterRenderers=function(e){const t=n.useContext(u),o=n.useRef(e);n.useEffect(()=>{if(t)return t(o.current)},[t])},exports.useRegisteredRenderers=h,exports.useRendererRegistry=function(){return n.useContext(u)},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