@embedpdf/plugin-annotation 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-annotation"),o=require("preact/jsx-runtime"),n=require("preact"),i=require("preact/hooks"),r=require("@embedpdf/core/preact"),s=require("@embedpdf/models"),l=require("@embedpdf/plugin-interaction-manager/preact"),a=require("@embedpdf/plugin-selection/preact"),c=require("@embedpdf/utils/preact"),d={},u=n.createContext(null),g=n.createContext([]);function p({children:e}){const[t,n]=i.useState([]),r=i.useCallback(e=>(n(t=>{const o=new Set(e.map(e=>e.id));return[...t.filter(e=>!o.has(e.id)),...e]}),()=>n(t=>t.filter(t=>!e.some(e=>e.id===t.id)))),[]);return o.jsx(u.Provider,{value:r,children:o.jsx(g.Provider,{value:t,children:e})})}function h(){return i.useContext(g)}const v=()=>r.usePlugin(t.AnnotationPlugin.id),b=()=>r.useCapability(t.AnnotationPlugin.id);function x({scale:e,documentId:t,pageIndex:n,rotation:s,pageWidth:l,pageHeight:a,trackedAnnotation:d,children:u,isSelected:g,isMultiSelected:p=!1,isDraggable:h,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]=i.useState(d.object),{provides:T}=b(),{plugin:$}=v(),{canModifyAnnotations:L}=r.useDocumentPermissions(t),F=i.useRef(null),U=L&&h&&!p,W=L&&x&&!p,O=i.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=i.useRef(null),Y=i.useCallback(e=>{var o;if(!(null==(o=e.transformData)?void 0:o.type)||p||!$)return;const{type:i,changes:r,metadata:s}=e.transformData,c=d.object.id,u={width:l,height:a};if("start"===e.state&&(K.current=d.object.rect,F.current=d.object,"move"===i?$.startDrag(t,{annotationIds:[c],pageSize:u}):"resize"===i&&$.startResize(t,{annotationIds:[c],pageSize:u,resizeHandle:(null==s?void 0:s.handle)??"se"})),r.rect&&K.current)if("move"===i){const e={x:r.rect.origin.x-K.current.origin.x,y:r.rect.origin.y-K.current.origin.y};$.updateDrag(t,e)}else"resize"===i&&$.updateResize(t,r.rect);if("vertex-edit"===i&&r.vertices&&m){const t=F.current??d.object,o=m.transformAnnotation(t,r.vertices),l=null==T?void 0:T.transformAnnotation(t,{type:i,changes:o,metadata:s});l&&(B(e=>({...e,...l})),"end"===e.state&&(null==O||O.updateAnnotation(n,c,l)))}"end"===e.state&&(K.current=null,F.current=null,"move"===i?$.commitDrag(t):"resize"===i&&$.commitResize(t))},[$,t,d.object,l,a,n,p,m,T,O]),{dragProps:Q,vertices:X,resize:Z}=c.useInteractionHandles({controller:{element:H.rect,vertices:null==m?void 0:m.extractVertices(H),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:a}},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=i.useMemo(()=>{if(L&&S)return S},[L,S]),_=c.useDoublePressProps(J);i.useEffect(()=>{B(d.object)},[d.object]),i.useEffect(()=>{if(!$)return;const e=d.object.id,o=o=>{var n;if(o.documentId!==t)return;const i=null==(n=o.previewPatches)?void 0:n[e];"update"===o.type&&i?B(e=>({...e,...i})):"cancel"===o.type&&B(d.object)},n=[$.onDragChange(o),$.onResizeChange(o)];return()=>n.forEach(e=>e())},[$,t,d.object]);const ee=g&&!p;return o.jsxs("div",{"data-no-interaction":!0,children:[o.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,o=null==A?void 0:A({annotation:H,children:t,isSelected:g,scale:e,rotation:s,pageWidth:l,pageHeight:a,pageIndex:n,onSelect:I});return null!=o?o:t})(),g&&W&&Z.map(({key:e,...t})=>(null==P?void 0:P.component)?P.component({key:e,...t,backgroundColor:N}):o.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}):o.jsx("div",{...t,style:{...t.style,backgroundColor:q}},e))]}),j&&!p&&o.jsx(c.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:n},selected:g,placement:{suggestTop:!1}})})]})}function f({documentId:e,pageIndex:t,scale:n,rotation:l,pageWidth:a,pageHeight:d,selectedAnnotations:u,isDraggable:g,isResizable:p,resizeUI:h,selectionOutlineColor:b="#007ACC",outlineOffset:x=2,zIndex:f=100,groupSelectionMenu:y}){const{plugin:m}=v(),{canModifyAnnotations:j}=r.useDocumentPermissions(e),k=i.useRef(null),S=i.useRef(!1),I=i.useRef(!1),M=j&&g,P=j&&p,z=i.useMemo(()=>{const e=u.map(e=>e.object.rect);return s.boundingRectOrEmpty(e)},[u]),[R,A]=i.useState(z);i.useEffect(()=>{S.current||I.current||A(z)},[z]);const C=i.useCallback(t=>{var o,n;if(!(null==(o=t.transformData)?void 0:o.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:a,height:d}})):s&&(I.current=!0,m.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:a,height:d},resizeHandle:(null==(n=t.transformData.metadata)?void 0:n.handle)??"se"})));const l=k.current??z;if(r&&t.transformData.changes.rect){const o=t.transformData.changes.rect,n={x:o.origin.x-l.origin.x,y:o.origin.y-l.origin.y},i=m.updateDrag(e,n);A({...l,origin:{x:l.origin.x+i.x,y:l.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const o=t.transformData.changes.rect;m.updateResize(e,o),A(o)}"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,a,d,z,M,u]),w=(null==h?void 0:h.color)??"#007ACC",D=(null==h?void 0:h.size)??12,{dragProps:E,resize:B}=c.useInteractionHandles({controller:{element:R,constraints:{minWidth:20,minHeight:20,boundingBox:{width:a,height:d}},maintainAspectRatio:!1,pageRotation:l,scale:n,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:o.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[o.jsx("div",{...M?E:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:R.origin.x*n,top:R.origin.y*n,width:R.size.width*n,height:R.size.height*n,outline:`2px dashed ${b}`,outlineOffset:x-1,cursor:M?"move":"default",touchAction:"none",zIndex:f},children:P&&B.map(({key:e,...t})=>(null==h?void 0:h.component)?h.component({key:e,...t,backgroundColor:w}):o.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),y&&o.jsx(c.CounterRotate,{rect:{origin:{x:R.origin.x*n,y:R.origin.y*n},size:{width:R.size.width*n,height:R.size.height*n}},rotation:l,children:e=>y({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function y({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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}},n))})}function m({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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: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 o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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:n=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=i.useMemo(()=>s.map(({points:e})=>{let t="";return e.forEach(({x:e,y:o},n)=>{const i=e-l.origin.x,r=o-l.origin.y;t+=(0===n?"M":"L")+i+" "+r+" "}),t.trim()}),[s,l]),g=l.size.width*a,p=l.size.height*a;return o.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,i)=>o.jsx("path",{d:t,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},i))})}function I({isSelected:e,color:t="#000000",strokeColor:n,opacity:r=1,strokeWidth:l,strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:p,height:h,x:v,y:b}=i.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 o.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:o.jsx("rect",{x:v,y:b,width:p,height:h,fill:t,opacity:r,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function M({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:r,strokeStyle:l=s.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}=i.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=p*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 ${p} ${h}`,children:o.jsx("ellipse",{cx:v,cy:b,rx:x,ry:f,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function P({color:e="transparent",opacity:n=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=s.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}=i.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=i.useMemo(()=>{const e=Math.atan2(y-x,f-b);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,b,x),end:t.patching.createEnding(null==g?void 0:g.end,r,e,f,y)}},[g,r,b,x,f,y]),j=d.size.width*p,k=d.size.height*p;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:n,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",pointerEvents:v?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.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:l,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.start.filled?"visible":"visibleStroke",...a===s.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:l,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function z({rect:e,vertices:n,color:r="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const p=i.useMemo(()=>n.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[n,e]),h=i.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=i.useMemo(()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),o=e(p[0],p[1]),n=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,o+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,n,p[p.length-1].x,p[p.length-1].y)}},[p,g,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:l,style:{fill:"none",stroke:s??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: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&&o.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 R({rect:e,vertices:t,color:n="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:p,currentVertex:h,handleSize:v=14}){const b=h?[...t,h]:t,x=i.useMemo(()=>b.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[b,e]),f=i.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:p,onTouchStart:p,opacity:l,style:{fill:h?"none":n,stroke:r??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===s.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 A({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const c=i.useRef(null),{provides:u}=b(),[g,p]=i.useState(!1);i.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]),i.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=n.object.fontSize*l,v=g&&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:n.object.rect.size.width*l,height:n.object.rect.size.height*l,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,n.object.id,{contents:c.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:x,fontFamily:s.standardFontCss(n.object.fontFamily),textAlign:s.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===s.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===s.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.color??n.object.backgroundColor,opacity:n.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:n.object.contents})})}function C({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=b(),[u,g]=i.useState(null),p=i.useRef(null),{width:h,height:v}=r.rect.size;i.useEffect(()=>{if(d){const o=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return o.wait(e=>{const t=URL.createObjectURL(e);g(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):o.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,h,v]);return o.jsx(n.Fragment,{children:u&&o.jsx("img",{src:u,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function w({isSelected:e,annotation:t,documentId:n,pageIndex:i,scale:r,onClick:s}){return o.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:o.jsx(C,{documentId:n,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function D({isSelected:e,strokeColor:t="#0000FF",strokeWidth:n=2,strokeStyle:r=s.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:p}=i.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),h=g*c,v=p*c,b=i.useMemo(()=>{if(r===s.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*n},${n}`},[r,l,n]),x=r===s.PdfAnnotationBorderStyle.UNDERLINE;return o.jsxs("svg",{style:{position:"absolute",width:h,height:v,pointerEvents:"none",zIndex:2},width:h,height:v,viewBox:`0 0 ${g} ${p}`,children:[o.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?o.jsx("line",{x1:1,y1:p-1,x2:g-1,y2:p-1,stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}}):o.jsx("rect",{x:n/2,y:n/2,width:Math.max(g-n,0),height:Math.max(p-n,0),fill:"transparent",stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}})]})}function E(e){const{documentId:r,pageIndex:c,scale:d,pageWidth:u,pageHeight:g,selectionMenu:p}=e,{provides:h}=b(),{provides:v}=a.useSelectionCapability(),[C,E]=i.useState([]),{register:B}=l.usePointerHandlers({documentId:r,pageIndex:c}),[T,$]=i.useState([]),[L,F]=i.useState(null),U=i.useMemo(()=>h?h.forDocument(r):null,[h,r]),W=T.length>1;i.useEffect(()=>{if(U){const e=U.getState();return E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e)),U.onStateChange(e=>{E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e))})}},[U,c]);const O=i.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&U&&(U.deselectAnnotation(),F(null))}}),[U]),H=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){v.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?U.toggleSelection(c,t.object.id):U.selectAnnotation(c,t.object.id),t.object.id!==L&&F(null)}},[U,v,L,c]),N=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){if(v.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,o=C.find(t=>t.object.id===e);if(o)return void U.selectAnnotation(o.object.pageIndex,e)}U.selectAnnotation(c,t.object.id)}},[U,v,C,c]);i.useEffect(()=>B(O,{documentId:r}),[B,O]);const q=i.useMemo(()=>C.filter(e=>T.includes(e.object.id)),[C,T]),G=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.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}),[q,U]),V=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.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}),[q,U]),K=i.useMemo(()=>{if(!U)return!1;const e=U.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===c)},[U,c,T]);return o.jsxs(o.Fragment,{children:[C.map(i=>{const l=T.includes(i.object.id),a=L===i.object.id,u=null==U?void 0:U.findToolForAnnotation(i.object);for(const n of e.annotationRenderers??[]){const r=n.tryRender(i,{isSelected:l,scale:d,pageIndex:c,onClick:e=>H(e,i)});if(r)return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:()=>r},i.object.id)}if(t.isInk(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(S,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquare(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(I,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isCircle(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(M,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isUnderline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(m,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStrikeout(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(j,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquiggly(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(k,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isHighlight(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(y,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLine(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(P,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolyline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(z,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolygon(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(R,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isFreeText(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0)&&!a,isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),F(i.object.id)},...e,children:e=>o.jsx(A,{isSelected:l,isEditing:a,annotation:{...i,object:e},pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStamp(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(w,{isSelected:l,annotation:i,documentId:r,pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLink(i)){const t=!!i.object.inReplyToId;return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:p,onSelect:e=>N(e,i),...e,children:e=>o.jsx(D,{...e,isSelected:l,scale:d,onClick:e=>N(e,i),hasIRT:t})},i.object.id)}return null}),K&&q.length>=2&&o.jsx(f,{documentId:r,pageIndex:c,scale:d,rotation:e.rotation,pageWidth:u,pageHeight:g,selectedAnnotations:q,isDraggable:G,isResizable:V,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function B({documentId:e,pageIndex:t,scale:n}){var r,l,c,d,u,g,p,h,v,x,f,S;const{provides:I}=a.useSelectionCapability(),{provides:M}=b(),[P,z]=i.useState([]),[R,A]=i.useState(null),[C,w]=i.useState(null);if(i.useEffect(()=>{if(I)return I.forDocument(e).onSelectionChange(()=>{z(I.forDocument(e).getHighlightRectsForPage(t)),A(I.forDocument(e).getBoundingRectForPage(t))})},[I,e,t]),i.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 s.PdfAnnotationSubtype.UNDERLINE:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=C.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(m,{strokeColor:null==(l=C.defaults)?void 0:l.strokeColor,opacity:null==(c=C.defaults)?void 0:c.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(y,{strokeColor:null==(u=C.defaults)?void 0:u.strokeColor,opacity:null==(g=C.defaults)?void 0:g.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(p=C.defaults)?void 0:p.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(j,{strokeColor:null==(h=C.defaults)?void 0:h.strokeColor,opacity:null==(v=C.defaults)?void 0:v.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(x=C.defaults)?void 0:x.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(k,{strokeColor:null==(f=C.defaults)?void 0:f.strokeColor,opacity:null==(S=C.defaults)?void 0:S.opacity,segmentRects:P,scale:n})});default:return null}}function T({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===s.PdfAnnotationSubtype.CIRCLE?o.jsx("div",{style:i,children:o.jsx(M,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:i,children:o.jsx(I,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?o.jsx("div",{style:i,children:o.jsx(R,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?o.jsx("div",{style:i,children:o.jsx(z,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?o.jsx("div",{style:i,children:o.jsx(P,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?o.jsx("div",{style:i,children:o.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===s.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 $({documentId:e,pageIndex:t,scale:n}){const{plugin:r}=v(),[s,l]=i.useState(new Map),a=i.useRef(null),c=i.useRef(null),d=i.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 s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;const c=t?t/l:1,d=o?o/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),n({imageData:h,width:g,height:p})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return i.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,n,{services:d,onPreview:(e,t)=>{l(o=>{const n=new Map(o);return t?n.set(e,t):n.delete(e),n})}})},[e,t,n,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(s.entries()).map(([e,t])=>o.jsx(T,{preview:t,scale:n},e))]})}const L=e.createPluginPackage(t.AnnotationPluginPackage).addWrapper(p).build();exports.AnnotationLayer=function({style:e,documentId:t,pageIndex:n,scale:l,rotation:a,selectionMenu:c,groupSelectionMenu:d,resizeUI:u,vertexUI:g,selectionOutlineColor:p,customAnnotationRenderer:v,annotationRenderers:b,...x}){var f,y,m,j;const k=r.useDocumentState(t),S=null==(y=null==(f=null==k?void 0:k.document)?void 0:f.pages)?void 0:y[n],I=(null==(m=null==S?void 0:S.size)?void 0:m.width)??0,M=(null==(j=null==S?void 0:S.size)?void 0:j.height)??0,P=h(),z=i.useMemo(()=>{const e=[...P];for(const t of b??[]){const o=e.findIndex(e=>e.id===t.id);o>=0?e[o]=t:e.push(t)}return e},[P,b]),R=i.useMemo(()=>void 0!==l?l:(null==k?void 0:k.scale)??1,[l,null==k?void 0:k.scale]),A=i.useMemo(()=>void 0!==a?a:(null==k?void 0:k.rotation)??s.Rotation.Degree0,[a,null==k?void 0:k.rotation]);return o.jsxs("div",{style:{...e},...x,children:[o.jsx(E,{documentId:t,selectionMenu:c,groupSelectionMenu:d,pageIndex:n,scale:R,rotation:A,pageWidth:I,pageHeight:M,resizeUI:u,vertexUI:g,selectionOutlineColor:p,customAnnotationRenderer:v,annotationRenderers:z}),o.jsx(B,{documentId:t,pageIndex:n,scale:R}),o.jsx($,{documentId:t,pageIndex:n,scale:R})]})},exports.AnnotationPluginPackage=L,exports.AnnotationRendererProvider=p,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:n}=b(),[r,s]=i.useState((null==(o=null==n?void 0:n.forDocument(e))?void 0:o.getState())??t.initialDocumentState());return i.useEffect(()=>{if(!n)return;const t=n.forDocument(e);return s(t.getState()),t.onStateChange(e=>{s(e)})},[n,e]),{state:r,provides:(null==n?void 0:n.forDocument(e))??null}},exports.useAnnotationCapability=b,exports.useAnnotationPlugin=v,exports.useRegisterRenderers=function(e){const t=i.useContext(u),o=i.useRef(e);i.useEffect(()=>{if(t)return t(o.current)},[t])},exports.useRegisteredRenderers=h,exports.useRendererRegistry=function(){return i.useContext(u)},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("preact/jsx-runtime"),n=require("preact"),i=require("preact/hooks"),r=require("@embedpdf/core/preact"),s=require("@embedpdf/models"),l=require("@embedpdf/plugin-interaction-manager/preact"),a=require("@embedpdf/plugin-selection/preact"),c=require("@embedpdf/utils/preact"),d={},u=n.createContext(null),g=n.createContext([]);function p({children:e}){const[t,n]=i.useState([]),r=i.useCallback(e=>(n(t=>{const o=new Set(e.map(e=>e.id));return[...t.filter(e=>!o.has(e.id)),...e]}),()=>n(t=>t.filter(t=>!e.some(e=>e.id===t.id)))),[]);return o.jsx(u.Provider,{value:r,children:o.jsx(g.Provider,{value:t,children:e})})}function h(){return i.useContext(g)}const v=()=>r.usePlugin(t.AnnotationPlugin.id),b=()=>r.useCapability(t.AnnotationPlugin.id);function x({scale:e,documentId:t,pageIndex:n,rotation:s,pageWidth:l,pageHeight:a,trackedAnnotation:d,children:u,isSelected:g,isMultiSelected:p=!1,isDraggable:h,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]=i.useState(d.object),{provides:T}=b(),{plugin:$}=v(),{canModifyAnnotations:L}=r.useDocumentPermissions(t),F=i.useRef(null),U=L&&h&&!p,W=L&&x&&!p,O=i.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=i.useRef(null),Y=i.useCallback(e=>{var o;if(!(null==(o=e.transformData)?void 0:o.type)||p||!$)return;const{type:i,changes:r,metadata:s}=e.transformData,c=d.object.id,u={width:l,height:a};if("start"===e.state&&(K.current=d.object.rect,F.current=d.object,"move"===i?$.startDrag(t,{annotationIds:[c],pageSize:u}):"resize"===i&&$.startResize(t,{annotationIds:[c],pageSize:u,resizeHandle:(null==s?void 0:s.handle)??"se"})),r.rect&&K.current)if("move"===i){const e={x:r.rect.origin.x-K.current.origin.x,y:r.rect.origin.y-K.current.origin.y};$.updateDrag(t,e)}else"resize"===i&&$.updateResize(t,r.rect);if("vertex-edit"===i&&r.vertices&&m){const t=F.current??d.object,o=m.transformAnnotation(t,r.vertices),l=null==T?void 0:T.transformAnnotation(t,{type:i,changes:o,metadata:s});l&&(B(e=>({...e,...l})),"end"===e.state&&(null==O||O.updateAnnotation(n,c,l)))}"end"===e.state&&(K.current=null,F.current=null,"move"===i?$.commitDrag(t):"resize"===i&&$.commitResize(t))},[$,t,d.object,l,a,n,p,m,T,O]),{dragProps:Q,vertices:X,resize:Z}=c.useInteractionHandles({controller:{element:H.rect,vertices:null==m?void 0:m.extractVertices(H),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:a}},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=i.useMemo(()=>{if(L&&S)return S},[L,S]),_=c.useDoublePressProps(J);i.useEffect(()=>{B(d.object)},[d.object]),i.useEffect(()=>{if(!$)return;const e=d.object.id,o=o=>{var n;if(o.documentId!==t)return;const i=null==(n=o.previewPatches)?void 0:n[e];"update"===o.type&&i?B(e=>({...e,...i})):"cancel"===o.type&&B(d.object)},n=[$.onDragChange(o),$.onResizeChange(o)];return()=>n.forEach(e=>e())},[$,t,d.object]);const ee=g&&!p;return o.jsxs("div",{"data-no-interaction":!0,children:[o.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,o=null==A?void 0:A({annotation:H,children:t,isSelected:g,scale:e,rotation:s,pageWidth:l,pageHeight:a,pageIndex:n,onSelect:I});return null!=o?o:t})(),g&&W&&Z.map(({key:e,...t})=>(null==P?void 0:P.component)?P.component({key:e,...t,backgroundColor:N}):o.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}):o.jsx("div",{...t,style:{...t.style,backgroundColor:q}},e))]}),j&&!p&&o.jsx(c.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:n},selected:g,placement:{suggestTop:!1}})})]})}function f({documentId:e,pageIndex:t,scale:n,rotation:l,pageWidth:a,pageHeight:d,selectedAnnotations:u,isDraggable:g,isResizable:p,resizeUI:h,selectionOutlineColor:b="#007ACC",outlineOffset:x=2,zIndex:f=100,groupSelectionMenu:y}){const{plugin:m}=v(),{canModifyAnnotations:j}=r.useDocumentPermissions(e),k=i.useRef(null),S=i.useRef(!1),I=i.useRef(!1),M=j&&g,P=j&&p,z=i.useMemo(()=>{const e=u.map(e=>e.object.rect);return s.boundingRectOrEmpty(e)},[u]),[R,A]=i.useState(z);i.useEffect(()=>{S.current||I.current||A(z)},[z]);const C=i.useCallback(t=>{var o,n;if(!(null==(o=t.transformData)?void 0:o.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:a,height:d}})):s&&(I.current=!0,m.startResize(e,{annotationIds:u.map(e=>e.object.id),pageSize:{width:a,height:d},resizeHandle:(null==(n=t.transformData.metadata)?void 0:n.handle)??"se"})));const l=k.current??z;if(r&&t.transformData.changes.rect){const o=t.transformData.changes.rect,n={x:o.origin.x-l.origin.x,y:o.origin.y-l.origin.y},i=m.updateDrag(e,n);A({...l,origin:{x:l.origin.x+i.x,y:l.origin.y+i.y}})}else if(s&&t.transformData.changes.rect){const o=t.transformData.changes.rect;m.updateResize(e,o),A(o)}"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,a,d,z,M,u]),w=(null==h?void 0:h.color)??"#007ACC",D=(null==h?void 0:h.size)??12,{dragProps:E,resize:B}=c.useInteractionHandles({controller:{element:R,constraints:{minWidth:20,minHeight:20,boundingBox:{width:a,height:d}},maintainAspectRatio:!1,pageRotation:l,scale:n,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:o.jsxs("div",{"data-group-selection-box":!0,"data-no-interaction":!0,children:[o.jsx("div",{...M?E:{onPointerDown:e=>e.stopPropagation()},style:{position:"absolute",left:R.origin.x*n,top:R.origin.y*n,width:R.size.width*n,height:R.size.height*n,outline:`2px dashed ${b}`,outlineOffset:x-1,cursor:M?"move":"default",touchAction:"none",zIndex:f},children:P&&B.map(({key:e,...t})=>(null==h?void 0:h.component)?h.component({key:e,...t,backgroundColor:w}):o.jsx("div",{...t,style:{...t.style,backgroundColor:w}},e))}),y&&o.jsx(c.CounterRotate,{rect:{origin:{x:R.origin.x*n,y:R.origin.y*n},size:{width:R.size.width*n,height:R.size.height*n}},rotation:l,children:e=>y({...e,context:{type:"group",annotations:u,pageIndex:t},selected:!0,placement:{suggestTop:!1}})})]})}function y({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00";return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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}},n))})}function m({strokeColor:e,opacity:t=.5,segmentRects:n,rect:i,scale:r,onClick:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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:s,style:l}){const a=e??"#FFFF00",c=2*r;return o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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: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 o.jsx(o.Fragment,{children:n.map((e,n)=>o.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: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:n=1,strokeWidth:r,inkList:s,rect:l,scale:a,onClick:c}){const d=t??"#000000",u=i.useMemo(()=>s.map(({points:e})=>{let t="";return e.forEach(({x:e,y:o},n)=>{const i=e-l.origin.x,r=o-l.origin.y;t+=(0===n?"M":"L")+i+" "+r+" "}),t.trim()}),[s,l]),g=l.size.width*a,p=l.size.height*a;return o.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,i)=>o.jsx("path",{d:t,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:d,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round"}},i))})}function I({isSelected:e,color:t="#000000",strokeColor:n,opacity:r=1,strokeWidth:l,strokeStyle:a=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:g}){const{width:p,height:h,x:v,y:b}=i.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 o.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:o.jsx("rect",{x:v,y:b,width:p,height:h,fill:t,opacity:r,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:n??t,strokeWidth:l,...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function M({color:e="#000000",strokeColor:t,opacity:n=1,strokeWidth:r,strokeStyle:l=s.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}=i.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=p*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 ${p} ${h}`,children:o.jsx("ellipse",{cx:v,cy:b,rx:x,ry:f,fill:e,opacity:n,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function P({color:e="transparent",opacity:n=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=s.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}=i.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=i.useMemo(()=>{const e=Math.atan2(y-x,f-b);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,b,x),end:t.patching.createEnding(null==g?void 0:g.end,r,e,f,y)}},[g,r,b,x,f,y]),j=d.size.width*p,k=d.size.height*p;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:n,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",pointerEvents:v?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.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:l,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.start.filled?"visible":"visibleStroke",...a===s.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:l,onPointerDown:h,onTouchStart:h,style:{cursor:v?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:v?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function z({rect:e,vertices:n,color:r="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const p=i.useMemo(()=>n.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[n,e]),h=i.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=i.useMemo(()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),o=e(p[0],p[1]),n=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,o+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,n,p[p.length-1].x,p[p.length-1].y)}},[p,g,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:l,style:{fill:"none",stroke:s??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: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&&o.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 R({rect:e,vertices:t,color:n="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=s.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:g,onClick:p,currentVertex:h,handleSize:v=14}){const b=h?[...t,h]:t,x=i.useMemo(()=>b.map(({x:t,y:o})=>({x:t-e.origin.x,y:o-e.origin.y})),[b,e]),f=i.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:p,onTouchStart:p,opacity:l,style:{fill:h?"none":n,stroke:r??n,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===n?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===s.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 A({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const c=i.useRef(null),{provides:u}=b(),[g,p]=i.useState(!1);i.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]),i.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=n.object.fontSize*l,v=g&&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:n.object.rect.size.width*l,height:n.object.rect.size.height*l,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,n.object.id,{contents:c.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:x,fontFamily:s.standardFontCss(n.object.fontFamily),textAlign:s.textAlignmentToCss(n.object.textAlign),flexDirection:"column",justifyContent:n.object.verticalAlign===s.PdfVerticalAlignment.Top?"flex-start":n.object.verticalAlign===s.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:n.object.color??n.object.backgroundColor,opacity:n.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:n.object.contents})})}function C({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=b(),[u,g]=i.useState(null),p=i.useRef(null),{width:h,height:v}=r.rect.size;i.useEffect(()=>{if(d){const o=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return o.wait(e=>{const t=URL.createObjectURL(e);g(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):o.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,h,v]);return o.jsx(n.Fragment,{children:u&&o.jsx("img",{src:u,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function w({isSelected:e,annotation:t,documentId:n,pageIndex:i,scale:r,onClick:s}){return o.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:o.jsx(C,{documentId:n,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:r})})}function D({isSelected:e,strokeColor:t="#0000FF",strokeWidth:n=2,strokeStyle:r=s.PdfAnnotationBorderStyle.UNDERLINE,strokeDashArray:l,rect:a,scale:c,onClick:d,hasIRT:u=!1}){const{width:g,height:p}=i.useMemo(()=>({width:a.size.width,height:a.size.height}),[a]),h=g*c,v=p*c,b=i.useMemo(()=>{if(r===s.PdfAnnotationBorderStyle.DASHED)return(null==l?void 0:l.join(","))??`${3*n},${n}`},[r,l,n]),x=r===s.PdfAnnotationBorderStyle.UNDERLINE;return o.jsxs("svg",{style:{position:"absolute",width:h,height:v,pointerEvents:"none",zIndex:2},width:h,height:v,viewBox:`0 0 ${g} ${p}`,children:[o.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?o.jsx("line",{x1:1,y1:p-1,x2:g-1,y2:p-1,stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}}):o.jsx("rect",{x:n/2,y:n/2,width:Math.max(g-n,0),height:Math.max(p-n,0),fill:"transparent",stroke:t,strokeWidth:n,strokeDasharray:b,style:{pointerEvents:"none"}})]})}function E(e){const{documentId:r,pageIndex:c,scale:d,pageWidth:u,pageHeight:g,selectionMenu:p}=e,{provides:h}=b(),{provides:v}=a.useSelectionCapability(),[C,E]=i.useState([]),{register:B}=l.usePointerHandlers({documentId:r,pageIndex:c}),[T,$]=i.useState([]),[L,F]=i.useState(null),U=i.useMemo(()=>h?h.forDocument(r):null,[h,r]),W=T.length>1;i.useEffect(()=>{if(U){const e=U.getState();return E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e)),U.onStateChange(e=>{E(t.getAnnotationsByPageIndex(e,c)),$(t.getSelectedAnnotationIds(e))})}},[U,c]);const O=i.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&U&&(U.deselectAnnotation(),F(null))}}),[U]),H=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){v.clear();"metaKey"in e&&(e.metaKey||e.ctrlKey)?U.toggleSelection(c,t.object.id):U.selectAnnotation(c,t.object.id),t.object.id!==L&&F(null)}},[U,v,L,c]),N=i.useCallback((e,t)=>{if(e.stopPropagation(),U&&v){if(v.clear(),t.object.inReplyToId){const e=t.object.inReplyToId,o=C.find(t=>t.object.id===e);if(o)return void U.selectAnnotation(o.object.pageIndex,e)}U.selectAnnotation(c,t.object.id)}},[U,v,C,c]);i.useEffect(()=>B(O,{documentId:r}),[B,O]);const q=i.useMemo(()=>C.filter(e=>T.includes(e.object.id)),[C,T]),G=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.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}),[q,U]),V=i.useMemo(()=>!(q.length<2)&&q.every(e=>{const o=null==U?void 0:U.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}),[q,U]),K=i.useMemo(()=>{if(!U)return!1;const e=U.getSelectedAnnotations();return e.length>1&&e.every(e=>e.object.pageIndex===c)},[U,c,T]);return o.jsxs(o.Fragment,{children:[C.map(i=>{const l=T.includes(i.object.id),a=L===i.object.id,u=null==U?void 0:U.findToolForAnnotation(i.object);for(const n of e.annotationRenderers??[]){const r=n.tryRender(i,{isSelected:l,scale:d,pageIndex:c,onClick:e=>H(e,i)});if(r)return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:()=>r},i.object.id)}if(t.isInk(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(S,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquare(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(I,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isCircle(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(M,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isUnderline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(m,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStrikeout(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(j,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isSquiggly(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(k,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isHighlight(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!1),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),zIndex:0,style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(y,{...e,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLine(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(P,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolyline(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(z,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isPolygon(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!1),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(R,{...e,isSelected:l,scale:d,onClick:e=>H(e,i)})})},i.object.id);if(t.isFreeText(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0)&&!a,isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),F(i.object.id)},...e,children:e=>o.jsx(A,{isSelected:l,isEditing:a,annotation:{...i,object:e},pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isStamp(i))return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:t.resolveInteractionProp(null==u?void 0:u.interaction.isDraggable,i.object,!0),isResizable:t.resolveInteractionProp(null==u?void 0:u.interaction.isResizable,i.object,!0),lockAspectRatio:t.resolveInteractionProp(null==u?void 0:u.interaction.lockAspectRatio,i.object,!1),selectionMenu:p,onSelect:e=>H(e,i),style:{mixBlendMode:s.blendModeToCss(i.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>o.jsx(w,{isSelected:l,annotation:i,documentId:r,pageIndex:c,scale:d,onClick:e=>H(e,i)})},i.object.id);if(t.isLink(i)){const t=!!i.object.inReplyToId;return o.jsx(x,{trackedAnnotation:i,isSelected:l,isMultiSelected:W,isDraggable:!1,isResizable:!1,lockAspectRatio:!1,selectionMenu:t?void 0:p,onSelect:e=>N(e,i),...e,children:e=>o.jsx(D,{...e,isSelected:l,scale:d,onClick:e=>N(e,i),hasIRT:t})},i.object.id)}return null}),K&&q.length>=2&&o.jsx(f,{documentId:r,pageIndex:c,scale:d,rotation:e.rotation,pageWidth:u,pageHeight:g,selectedAnnotations:q,isDraggable:G,isResizable:V,resizeUI:e.resizeUI,selectionOutlineColor:e.selectionOutlineColor,groupSelectionMenu:e.groupSelectionMenu})]})}function B({documentId:e,pageIndex:t,scale:n}){var r,l,c,d,u,g,p,h,v,x,f,S;const{provides:I}=a.useSelectionCapability(),{provides:M}=b(),[P,z]=i.useState([]),[R,A]=i.useState(null),[C,w]=i.useState(null);if(i.useEffect(()=>{if(I)return I.forDocument(e).onSelectionChange(()=>{z(I.forDocument(e).getHighlightRectsForPage(t)),A(I.forDocument(e).getBoundingRectForPage(t))})},[I,e,t]),i.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 s.PdfAnnotationSubtype.UNDERLINE:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=C.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(m,{strokeColor:null==(l=C.defaults)?void 0:l.strokeColor,opacity:null==(c=C.defaults)?void 0:c.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(y,{strokeColor:null==(u=C.defaults)?void 0:u.strokeColor,opacity:null==(g=C.defaults)?void 0:g.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(p=C.defaults)?void 0:p.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(j,{strokeColor:null==(h=C.defaults)?void 0:h.strokeColor,opacity:null==(v=C.defaults)?void 0:v.opacity,segmentRects:P,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(x=C.defaults)?void 0:x.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(k,{strokeColor:null==(f=C.defaults)?void 0:f.strokeColor,opacity:null==(S=C.defaults)?void 0:S.opacity,segmentRects:P,scale:n})});default:return null}}function T({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===s.PdfAnnotationSubtype.CIRCLE?o.jsx("div",{style:i,children:o.jsx(M,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:i,children:o.jsx(I,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?o.jsx("div",{style:i,children:o.jsx(R,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?o.jsx("div",{style:i,children:o.jsx(z,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?o.jsx("div",{style:i,children:o.jsx(P,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?o.jsx("div",{style:i,children:o.jsx(S,{isSelected:!1,scale:t,...e.data})}):e.type===s.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 $({documentId:e,pageIndex:t,scale:n}){const{plugin:r}=v(),[s,l]=i.useState(new Map),a=i.useRef(null),c=i.useRef(null),d=i.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 s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{naturalWidth:l,naturalHeight:a}=s;const c=t?t/l:1,d=o?o/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),n({imageData:h,width:g,height:p})},s.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return i.useEffect(()=>{if(r)return r.registerPageHandlers(e,t,n,{services:d,onPreview:(e,t)=>{l(o=>{const n=new Map(o);return t?n.set(e,t):n.delete(e),n})}})},[e,t,n,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(s.entries()).map(([e,t])=>o.jsx(T,{preview:t,scale:n},e))]})}const L=e.createPluginPackage(t.AnnotationPluginPackage).addWrapper(p).build();exports.AnnotationLayer=function({style:e,documentId:t,pageIndex:n,scale:s,rotation:l,selectionMenu:a,groupSelectionMenu:c,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:p,annotationRenderers:v,...b}){var x,f,y,m;const j=r.useDocumentState(t),k=null==(f=null==(x=null==j?void 0:j.document)?void 0:x.pages)?void 0:f[n],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=h(),P=i.useMemo(()=>{const e=[...M];for(const t of v??[]){const o=e.findIndex(e=>e.id===t.id);o>=0?e[o]=t:e.push(t)}return e},[M,v]),z=i.useMemo(()=>void 0!==s?s:(null==j?void 0:j.scale)??1,[s,null==j?void 0:j.scale]),R=i.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 o.jsxs("div",{style:{...e},...b,children:[o.jsx(E,{documentId:t,selectionMenu:a,groupSelectionMenu:c,pageIndex:n,scale:z,rotation:R,pageWidth:S,pageHeight:I,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:p,annotationRenderers:P}),o.jsx(B,{documentId:t,pageIndex:n,scale:z}),o.jsx($,{documentId:t,pageIndex:n,scale:z})]})},exports.AnnotationPluginPackage=L,exports.AnnotationRendererProvider=p,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:n}=b(),[r,s]=i.useState((null==(o=null==n?void 0:n.forDocument(e))?void 0:o.getState())??t.initialDocumentState());return i.useEffect(()=>{if(!n)return;const t=n.forDocument(e);return s(t.getState()),t.onStateChange(e=>{s(e)})},[n,e]),{state:r,provides:(null==n?void 0:n.forDocument(e))??null}},exports.useAnnotationCapability=b,exports.useAnnotationPlugin=v,exports.useRegisterRenderers=function(e){const t=i.useContext(u),o=i.useRef(e);i.useEffect(()=>{if(t)return t(o.current)},[t])},exports.useRegisteredRenderers=h,exports.useRendererRegistry=function(){return i.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