@embedpdf/plugin-annotation 2.1.2 → 2.2.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/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact"),o=require("preact/hooks"),i=require("preact/jsx-runtime"),s=require("@embedpdf/models"),r=require("@embedpdf/plugin-interaction-manager/preact"),l=require("@embedpdf/plugin-selection/preact"),a=require("@embedpdf/utils/preact"),c={},d=()=>e.usePlugin(t.AnnotationPlugin.id),u=()=>e.useCapability(t.AnnotationPlugin.id);function g({scale:e,documentId:t,pageIndex:n,rotation:s,pageWidth:r,pageHeight:l,trackedAnnotation:c,children:d,isSelected:g,isDraggable:h,isResizable:p,lockAspectRatio:x=!1,style:v={},vertexConfig:b,selectionMenu:y,outlineOffset:f=1,onDoubleClick:m,onSelect:j,zIndex:k=1,resizeUI:S,vertexUI:M,selectionOutlineColor:A="#007ACC",customAnnotationRenderer:w,...z}){const[D,P]=o.useState(c.object),{provides:R}=u(),C=o.useRef(null),I=o.useMemo(()=>R?R.forDocument(t):null,[R,t]),E=D?{...c.object,...D}:c.object,B=(null==S?void 0:S.color)??"#007ACC",T=(null==M?void 0:M.color)??"#007ACC",$=(null==S?void 0:S.size)??12,L=(null==M?void 0:M.size)??12,{dragProps:F,vertices:O,resize:U}=a.useInteractionHandles({controller:{element:E.rect,vertices:null==b?void 0:b.extractVertices(E),constraints:{minWidth:10,minHeight:10,boundingBox:{width:r,height:l}},maintainAspectRatio:x,pageRotation:s,scale:e,enabled:g,onUpdate:e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type))return;"start"===e.state&&(C.current=E);const o=e.transformData.type,i=C.current??E,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==R?void 0:R.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});r&&P(e=>({...e,...r})),"end"===e.state&&r&&(C.current=null,null==I||I.updateAnnotation(n,c.object.id,r))}},resizeUI:{handleSize:$,spacing:f,offsetMode:"outside",includeSides:!x,zIndex:k+1},vertexUI:{vertexSize:L,zIndex:k+2},includeVertices:!!b}),W=a.useDoublePressProps(m);return o.useEffect(()=>{P(c.object)},[c.object]),i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...h&&g?F:{},...W,style:{position:"absolute",left:E.rect.origin.x*e,top:E.rect.origin.y*e,width:E.rect.size.width*e,height:E.rect.size.height*e,outline:g?`1px solid ${A}`:"none",outlineOffset:g?`${f}px`:"0px",pointerEvents:g?"auto":"none",touchAction:"none",cursor:g&&h?"move":"default",zIndex:k,...v},...z,children:[(()=>{const t="function"==typeof d?d(E):d,o=null==w?void 0:w({annotation:E,children:t,isSelected:g,scale:e,rotation:s,pageWidth:r,pageHeight:l,pageIndex:n,onSelect:j});return null!=o?o:t})(),g&&p&&U.map(({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:B}):i.jsx("div",{...t,style:{...t.style,backgroundColor:B}},e)),g&&O.map(({key:e,...t})=>(null==M?void 0:M.component)?M.component({key:e,...t,backgroundColor:T}):i.jsx("div",{...t,style:{...t.style,backgroundColor:T}},e))]}),y&&i.jsx(a.CounterRotate,{rect:{origin:{x:E.rect.origin.x*e,y:E.rect.origin.y*e},size:{width:E.rect.size.width*e,height:E.rect.size.height*e}},rotation:s,children:e=>y({...e,context:{type:"annotation",annotation:c,pageIndex:n},selected:g,placement:{suggestTop:!1}})})]})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){return i.jsx(i.Fragment,{children:n.map((n,a)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c))})}function v({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s,c=6*s,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}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*s,top:(o?e.origin.y-o.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.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 b({isSelected:e,color:t="#000000",opacity:n=1,strokeWidth:s,inkList:r,rect:l,scale:a,onClick:c}){const d=o.useMemo(()=>r.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-l.origin.x,s=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "}),t.trim()}),[r,l]),u=l.size.width*a,g=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:u,height:g,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:g,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map((o,r)=>i.jsx("path",{d:o,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round"}},r))})}function y({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:h,height:p,x:x,y:v}=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]),b=(h+l)*u,y=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2},width:b,height:y,viewBox:`0 0 ${h+l} ${p+l}`,children:i.jsx("rect",{x:x,y:v,width:h,height:p,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 f({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:h,height:p,cx:x,cy:v,rx:b,ry:y}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}},[c,r]),f=h*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${h} ${p}`,children:i.jsx("ellipse",{cx:x,cy:v,rx:b,ry:y,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 m({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:h,onClick:p,isSelected:x}){const{x1:v,y1:b,x2:y,y2:f}=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(f-b,y-v);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,v,b),end:t.patching.createEnding(null==g?void 0:g.end,r,e,y,f)}},[g,r,v,b,y,f]),j=d.size.width*h,k=d.size.height*h;return i.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:[i.jsx("line",{x1:v,y1:b,x2:y,y2:f,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&i.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"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&&i.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function j({rect:e,vertices:n,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const h=o.useMemo(()=>n.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[n,e]),p=o.useMemo(()=>{if(!h.length)return"";const[e,...t]=h;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[h]),x=o.useMemo(()=>{if(h.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(h[0],h[1]),o=e(h[h.length-2],h[h.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,h[0].x,h[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,h[h.length-1].x,h[h.length-1].y)}},[h,g,a]),v=e.size.width*c,b=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2,overflow:"visible"},width:v,height:b,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??s,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&i.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:r,fill:x.start.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&i.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:r,fill:x.end.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({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:h,currentVertex:p,handleSize:x=14}){const v=p?[...t,p]:t,b=o.useMemo(()=>v.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[v,e]),y=o.useMemo(()=>{if(!b.length)return"";const[e,...t]=b,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[b,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return i.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:[i.jsx("path",{d:y,onPointerDown:h,onTouchStart:h,opacity:l,style:{fill:p?"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(",")}}}),f&&t.length>1&&i.jsx("path",{d:`M ${b[b.length-1].x} ${b[b.length-1].y} L ${b[0].x} ${b[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&i.jsx("rect",{x:b[0].x-x/u/2,y:b[0].y-x/u/2,width:x/u,height:x/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const d=o.useRef(null),{provides:g}=u(),[h,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 x=n.object.fontSize*l,v=h&&t&&x>0&&x<16,b=v?16:x,y=v?x/16:1,f=v?100/y:100;return i.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:i.jsx("span",{ref:d,onBlur:()=>{g&&d.current&&g.updateAnnotation(r,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:b,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.backgroundColor,opacity:n.object.opacity,width:v?`${f}%`:"100%",height:v?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${y})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function M({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=u(),[g,h]=o.useState(null),p=o.useRef(null),{width:x,height:v}=r.rect.size;o.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);h(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,x,v]);return i.jsx(n.Fragment,{children:g&&i.jsx("img",{src:g,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function A({isSelected:e,annotation:t,documentId:n,pageIndex:o,scale:s,onClick:r}){return i.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:r,onTouchStart:r,children:i.jsx(M,{documentId:n,pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:s})})}function w(e){const{documentId:a,pageIndex:c,scale:d,selectionMenu:M}=e,{provides:w}=u(),{provides:z}=l.useSelectionCapability(),[D,P]=o.useState([]),{register:R}=r.usePointerHandlers({documentId:a,pageIndex:c}),[C,I]=o.useState(null),[E,B]=o.useState(null),T=o.useMemo(()=>w?w.forDocument(a):null,[w,a]);o.useEffect(()=>{if(T){const e=T.getState();return P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c)),T.onStateChange(e=>{P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c))})}},[T,c]);const $=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&T&&(T.deselectAnnotation(),B(null))}}),[T]),L=o.useCallback((e,t)=>{e.stopPropagation(),T&&z&&(T.selectAnnotation(c,t.object.id),z.clear(),t.object.id!==E&&B(null))},[T,z,E,c]);return o.useEffect(()=>R($,{documentId:a}),[R,$]),i.jsx(i.Fragment,{children:D.map(o=>{const r=(null==C?void 0:C.object.id)===o.object.id,l=E===o.object.id,u=null==T?void 0:T.findToolForAnnotation(o.object);return t.isInk(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquare(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isCircle(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isUnderline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(p,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStrikeout(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquiggly(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isHighlight(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(h,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isLine(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(m,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolyline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolygon(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isFreeText(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:((null==u?void 0:u.interaction.isDraggable)??!0)&&!l,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),B(o.object.id)},...e,children:e=>i.jsx(S,{isSelected:r,isEditing:l,annotation:{...o,object:e},pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStamp(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:r,annotation:o,documentId:a,pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):null})})}function z({documentId:e,pageIndex:t,scale:n}){var r,a,c,d,g,b,y,f,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:A}=u(),[w,z]=o.useState([]),[D,P]=o.useState(null),[R,C]=o.useState(null);if(o.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{z(M.forDocument(e).getHighlightRectsForPage(t)),P(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),o.useEffect(()=>{if(A)return C(A.forDocument(e).getActiveTool()),A.forDocument(e).onActiveToolChange(e=>C(e))},[A,e]),!D)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case s.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=R.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{color:null==(a=R.defaults)?void 0:a.color,opacity:null==(c=R.defaults)?void 0:c.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=R.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(h,{color:null==(g=R.defaults)?void 0:g.color,opacity:null==(b=R.defaults)?void 0:b.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(y=R.defaults)?void 0:y.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{color:null==(f=R.defaults)?void 0:f.color,opacity:null==(m=R.defaults)?void 0:m.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(j=R.defaults)?void 0:j.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(v,{color:null==(k=R.defaults)?void 0:k.color,opacity:null==(S=R.defaults)?void 0:S.opacity,segmentRects:w,scale:n})});default:return null}}function D({preview:e,scale:t}){const{bounds:n}=e,o={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?i.jsx("div",{style:o,children:i.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.FREETEXT?i.jsx("div",{style:o,children:i.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function P({documentId:e,pageIndex:t,scale:n}){const{plugin:s}=d(),[r,l]=o.useState(new Map),a=o.useRef(null),c=o.useRef(null),u=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 s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),g=l*u,h=a*u;i.width=g,i.height=h,s.drawImage(r,0,0,g,h);const p=s.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:g,height:h})},r.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(s)return s.registerPageHandlers(e,t,n,{services:u,onPreview:(e,t)=>{l(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,n,s,u]),i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:a,type:"file",style:{display:"none"}}),i.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(r.entries()).map(([e,t])=>i.jsx(D,{preview:t,scale:n},e))]})}exports.AnnotationLayer=function({style:t,documentId:n,pageIndex:r,scale:l,rotation:a,selectionMenu:c,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,...p}){var x,v,b,y;const f=e.useDocumentState(n),m=null==(v=null==(x=null==f?void 0:f.document)?void 0:x.pages)?void 0:v[r],j=(null==(b=null==m?void 0:m.size)?void 0:b.width)??0,k=(null==(y=null==m?void 0:m.size)?void 0:y.height)??0,S=o.useMemo(()=>void 0!==l?l:(null==f?void 0:f.scale)??1,[l,null==f?void 0:f.scale]),M=o.useMemo(()=>void 0!==a?a:(null==f?void 0:f.rotation)??s.Rotation.Degree0,[a,null==f?void 0:f.rotation]);return i.jsxs("div",{style:{...t},...p,children:[i.jsx(w,{documentId:n,selectionMenu:c,pageIndex:r,scale:S,rotation:M,pageWidth:j,pageHeight:k,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h}),i.jsx(z,{documentId:n,pageIndex:r,scale:S}),i.jsx(P,{documentId:n,pageIndex:r,scale:S})]})},exports.useAnnotation=e=>{var n;const{provides:i}=u(),[s,r]=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 r(t.getState()),t.onStateChange(e=>{r(e)})},[i,e]),{state:s,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=u,exports.useAnnotationPlugin=d,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact"),o=require("preact/hooks"),i=require("preact/jsx-runtime"),s=require("@embedpdf/models"),r=require("@embedpdf/plugin-interaction-manager/preact"),l=require("@embedpdf/plugin-selection/preact"),a=require("@embedpdf/utils/preact"),c={},d=()=>e.usePlugin(t.AnnotationPlugin.id),u=()=>e.useCapability(t.AnnotationPlugin.id);function g({scale:t,documentId:n,pageIndex:s,rotation:r,pageWidth:l,pageHeight:c,trackedAnnotation:d,children:g,isSelected:h,isDraggable:p,isResizable:x,lockAspectRatio:v=!1,style:b={},vertexConfig:y,selectionMenu:f,outlineOffset:m=1,onDoubleClick:j,onSelect:k,zIndex:S=1,resizeUI:M,vertexUI:A,selectionOutlineColor:w="#007ACC",customAnnotationRenderer:z,...D}){const[P,R]=o.useState(d.object),{provides:C}=u(),{canModifyAnnotations:I}=e.useDocumentPermissions(n),E=o.useRef(null),B=I&&p,T=I&&x,$=o.useMemo(()=>C?C.forDocument(n):null,[C,n]),L=P?{...d.object,...P}:d.object,F=(null==M?void 0:M.color)??"#007ACC",O=(null==A?void 0:A.color)??"#007ACC",U=(null==M?void 0:M.size)??12,W=(null==A?void 0:A.size)??12,{dragProps:H,vertices:N,resize:q}=a.useInteractionHandles({controller:{element:L.rect,vertices:null==y?void 0:y.extractVertices(L),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:c}},maintainAspectRatio:v,pageRotation:r,scale:t,enabled:h,onUpdate:e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type))return;"start"===e.state&&(E.current=L);const n=e.transformData.type,o=E.current??L,i=e.transformData.changes.vertices?null==y?void 0:y.transformAnnotation(o,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==C?void 0:C.transformAnnotation(o,{type:n,changes:i,metadata:e.transformData.metadata});r&&R(e=>({...e,...r})),"end"===e.state&&r&&(E.current=null,null==$||$.updateAnnotation(s,d.object.id,r))}},resizeUI:{handleSize:U,spacing:m,offsetMode:"outside",includeSides:!v,zIndex:S+1},vertexUI:{vertexSize:W,zIndex:S+2},includeVertices:!!y}),V=o.useMemo(()=>{if(I&&j)return j},[I,j]),G=a.useDoublePressProps(V);return o.useEffect(()=>{R(d.object)},[d.object]),i.jsxs("div",{"data-no-interaction":!0,children:[i.jsxs("div",{...B&&h?H:{},...G,style:{position:"absolute",left:L.rect.origin.x*t,top:L.rect.origin.y*t,width:L.rect.size.width*t,height:L.rect.size.height*t,outline:h?`1px solid ${w}`:"none",outlineOffset:h?`${m}px`:"0px",pointerEvents:h?"auto":"none",touchAction:"none",cursor:h&&B?"move":"default",zIndex:S,...b},...D,children:[(()=>{const e="function"==typeof g?g(L):g,n=null==z?void 0:z({annotation:L,children:e,isSelected:h,scale:t,rotation:r,pageWidth:l,pageHeight:c,pageIndex:s,onSelect:k});return null!=n?n:e})(),h&&T&&q.map(({key:e,...t})=>(null==M?void 0:M.component)?M.component({key:e,...t,backgroundColor:F}):i.jsx("div",{...t,style:{...t.style,backgroundColor:F}},e)),h&&I&&N.map(({key:e,...t})=>(null==A?void 0:A.component)?A.component({key:e,...t,backgroundColor:O}):i.jsx("div",{...t,style:{...t.style,backgroundColor:O}},e))]}),f&&i.jsx(a.CounterRotate,{rect:{origin:{x:L.rect.origin.x*t,y:L.rect.origin.y*t},size:{width:L.rect.size.width*t,height:L.rect.size.height*t}},rotation:r,children:e=>f({...e,context:{type:"annotation",annotation:d,pageIndex:s},selected:h,placement:{suggestTop:!1}})})]})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){return i.jsx(i.Fragment,{children:n.map((n,a)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s;return i.jsx(i.Fragment,{children:n.map((n,c)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?n.origin.x-o.origin.x:n.origin.x)*s,top:(o?n.origin.y-o.origin.y:n.origin.y)*s,width:n.size.width*s,height:n.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c))})}function v({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:o,scale:s,onClick:r,style:l}){const a=2*s,c=6*s,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}" stroke-width="${a}" stroke-linecap="round"/>\n </svg>`)}")`;return i.jsx(i.Fragment,{children:n.map((e,n)=>i.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(o?e.origin.x-o.origin.x:e.origin.x)*s,top:(o?e.origin.y-o.origin.y:e.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:i.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 b({isSelected:e,color:t="#000000",opacity:n=1,strokeWidth:s,inkList:r,rect:l,scale:a,onClick:c}){const d=o.useMemo(()=>r.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-l.origin.x,s=n-l.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "}),t.trim()}),[r,l]),u=l.size.width*a,g=l.size.height*a;return i.jsx("svg",{style:{position:"absolute",width:u,height:g,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:g,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map((o,r)=>i.jsx("path",{d:o,fill:"none",opacity:n,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round"}},r))})}function y({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:h,height:p,x:x,y:v}=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]),b=(h+l)*u,y=(p+l)*u;return i.jsx("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2},width:b,height:y,viewBox:`0 0 ${h+l} ${p+l}`,children:i.jsx("rect",{x:x,y:v,width:h,height:p,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 f({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:h,height:p,cx:x,cy:v,rx:b,ry:y}=o.useMemo(()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}},[c,r]),f=h*d,m=p*d;return i.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${h} ${p}`,children:i.jsx("ellipse",{cx:x,cy:v,rx:b,ry:y,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 m({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:h,onClick:p,isSelected:x}){const{x1:v,y1:b,x2:y,y2:f}=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(f-b,y-v);return{start:t.patching.createEnding(null==g?void 0:g.start,r,e+Math.PI,v,b),end:t.patching.createEnding(null==g?void 0:g.end,r,e,y,f)}},[g,r,v,b,y,f]),j=d.size.width*h,k=d.size.height*h;return i.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:[i.jsx("line",{x1:v,y1:b,x2:y,y2:f,opacity:n,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&i.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"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&&i.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===s.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function j({rect:e,vertices:n,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:g}){const h=o.useMemo(()=>n.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[n,e]),p=o.useMemo(()=>{if(!h.length)return"";const[e,...t]=h;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[h]),x=o.useMemo(()=>{if(h.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(h[0],h[1]),o=e(h[h.length-2],h[h.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,h[0].x,h[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,h[h.length-1].x,h[h.length-1].y)}},[h,g,a]),v=e.size.width*c,b=e.size.height*c;return i.jsxs("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2,overflow:"visible"},width:v,height:b,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[i.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:r??s,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&i.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:r,fill:x.start.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&i.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:r,fill:x.end.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function k({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:h,currentVertex:p,handleSize:x=14}){const v=p?[...t,p]:t,b=o.useMemo(()=>v.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[v,e]),y=o.useMemo(()=>{if(!b.length)return"";const[e,...t]=b,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[b,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return i.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:[i.jsx("path",{d:y,onPointerDown:h,onTouchStart:h,opacity:l,style:{fill:p?"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(",")}}}),f&&t.length>1&&i.jsx("path",{d:`M ${b[b.length-1].x} ${b[b.length-1].y} L ${b[0].x} ${b[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&i.jsx("rect",{x:b[0].x-x/u/2,y:b[0].y-x/u/2,width:x/u,height:x/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function S({isSelected:e,isEditing:t,annotation:n,pageIndex:r,scale:l,onClick:a}){const d=o.useRef(null),{provides:g}=u(),[h,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 x=n.object.fontSize*l,v=h&&t&&x>0&&x<16,b=v?16:x,y=v?x/16:1,f=v?100/y:100;return i.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:i.jsx("span",{ref:d,onBlur:()=>{g&&d.current&&g.updateAnnotation(r,n.object.id,{contents:d.current.innerText})},tabIndex:0,style:{color:n.object.fontColor,fontSize:b,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.backgroundColor,opacity:n.object.opacity,width:v?`${f}%`:"100%",height:v?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${y})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:n.object.contents})})}function M({documentId:e,pageIndex:t,annotation:r,scaleFactor:l=1,style:a,...c}){const{provides:d}=u(),[g,h]=o.useState(null),p=o.useRef(null),{width:x,height:v}=r.rect.size;o.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:r,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);h(t),p.current=t},s.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):n.abort({code:s.PdfErrorCode.Cancelled,message:"canceled render task"})}}},[t,l,d,e,r.id,x,v]);return i.jsx(n.Fragment,{children:g&&i.jsx("img",{src:g,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...c,style:{width:"100%",height:"100%",display:"block",...a||{}}})})}function A({isSelected:e,annotation:t,documentId:n,pageIndex:o,scale:s,onClick:r}){return i.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:r,onTouchStart:r,children:i.jsx(M,{documentId:n,pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:s})})}function w(e){const{documentId:a,pageIndex:c,scale:d,selectionMenu:M}=e,{provides:w}=u(),{provides:z}=l.useSelectionCapability(),[D,P]=o.useState([]),{register:R}=r.usePointerHandlers({documentId:a,pageIndex:c}),[C,I]=o.useState(null),[E,B]=o.useState(null),T=o.useMemo(()=>w?w.forDocument(a):null,[w,a]);o.useEffect(()=>{if(T){const e=T.getState();return P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c)),T.onStateChange(e=>{P(t.getAnnotationsByPageIndex(e,c)),I(t.getSelectedAnnotationByPageIndex(e,c))})}},[T,c]);const $=o.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&T&&(T.deselectAnnotation(),B(null))}}),[T]),L=o.useCallback((e,t)=>{e.stopPropagation(),T&&z&&(T.selectAnnotation(c,t.object.id),z.clear(),t.object.id!==E&&B(null))},[T,z,E,c]);return o.useEffect(()=>R($,{documentId:a}),[R,$]),i.jsx(i.Fragment,{children:D.map(o=>{const r=(null==C?void 0:C.object.id)===o.object.id,l=E===o.object.id,u=null==T?void 0:T.findToolForAnnotation(o.object);return t.isInk(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(b,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquare(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(y,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isCircle(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(f,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isUnderline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(p,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStrikeout(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(x,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isSquiggly(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(v,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isHighlight(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!1,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),zIndex:0,style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Multiply)},...e,children:e=>i.jsx(h,{...e,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isLine(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(m,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolyline(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(j,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isPolygon(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!1,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(n.Fragment,{children:i.jsx(k,{...e,isSelected:r,scale:d,onClick:e=>L(e,o)})})},o.object.id):t.isFreeText(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:((null==u?void 0:u.interaction.isDraggable)??!0)&&!l,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),B(o.object.id)},...e,children:e=>i.jsx(S,{isSelected:r,isEditing:l,annotation:{...o,object:e},pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):t.isStamp(o)?i.jsx(g,{trackedAnnotation:o,isSelected:r,isDraggable:(null==u?void 0:u.interaction.isDraggable)??!0,isResizable:(null==u?void 0:u.interaction.isResizable)??!0,lockAspectRatio:(null==u?void 0:u.interaction.lockAspectRatio)??!1,selectionMenu:M,onSelect:e=>L(e,o),style:{mixBlendMode:s.blendModeToCss(o.object.blendMode??s.PdfBlendMode.Normal)},...e,children:e=>i.jsx(A,{isSelected:r,annotation:o,documentId:a,pageIndex:c,scale:d,onClick:e=>L(e,o)})},o.object.id):null})})}function z({documentId:e,pageIndex:t,scale:n}){var r,a,c,d,g,b,y,f,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:A}=u(),[w,z]=o.useState([]),[D,P]=o.useState(null),[R,C]=o.useState(null);if(o.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{z(M.forDocument(e).getHighlightRectsForPage(t)),P(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),o.useEffect(()=>{if(A)return C(A.forDocument(e).getActiveTool()),A.forDocument(e).onActiveToolChange(e=>C(e))},[A,e]),!D)return null;if(!R||!R.defaults)return null;switch(R.defaults.type){case s.PdfAnnotationSubtype.UNDERLINE:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(r=R.defaults)?void 0:r.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(p,{color:null==(a=R.defaults)?void 0:a.color,opacity:null==(c=R.defaults)?void 0:c.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.HIGHLIGHT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(d=R.defaults)?void 0:d.blendMode)??s.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(h,{color:null==(g=R.defaults)?void 0:g.color,opacity:null==(b=R.defaults)?void 0:b.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.STRIKEOUT:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(y=R.defaults)?void 0:y.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(x,{color:null==(f=R.defaults)?void 0:f.color,opacity:null==(m=R.defaults)?void 0:m.opacity,segmentRects:w,scale:n})});case s.PdfAnnotationSubtype.SQUIGGLY:return i.jsx("div",{style:{mixBlendMode:s.blendModeToCss((null==(j=R.defaults)?void 0:j.blendMode)??s.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:i.jsx(v,{color:null==(k=R.defaults)?void 0:k.color,opacity:null==(S=R.defaults)?void 0:S.opacity,segmentRects:w,scale:n})});default:return null}}function D({preview:e,scale:t}){const{bounds:n}=e,o={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?i.jsx("div",{style:o,children:i.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.SQUARE?i.jsx("div",{style:o,children:i.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYGON?i.jsx("div",{style:o,children:i.jsx(k,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.POLYLINE?i.jsx("div",{style:o,children:i.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.LINE?i.jsx("div",{style:o,children:i.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.INK?i.jsx("div",{style:o,children:i.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===s.PdfAnnotationSubtype.FREETEXT?i.jsx("div",{style:o,children:i.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function P({documentId:e,pageIndex:t,scale:n}){const{plugin:s}=d(),[r,l]=o.useState(new Map),a=o.useRef(null),c=o.useRef(null),u=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 s=i.getContext("2d");if(!s)return;const r=new Image;r.crossOrigin="Anonymous",r.onload=()=>{let{naturalWidth:l,naturalHeight:a}=r;const c=t?t/l:1,d=n?n/a:1,u=Math.min(c,d,1),g=l*u,h=a*u;i.width=g,i.height=h,s.drawImage(r,0,0,g,h);const p=s.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:g,height:h})},r.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return o.useEffect(()=>{if(s)return s.registerPageHandlers(e,t,n,{services:u,onPreview:(e,t)=>{l(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,n,s,u]),i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:a,type:"file",style:{display:"none"}}),i.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(r.entries()).map(([e,t])=>i.jsx(D,{preview:t,scale:n},e))]})}exports.AnnotationLayer=function({style:t,documentId:n,pageIndex:r,scale:l,rotation:a,selectionMenu:c,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,...p}){var x,v,b,y;const f=e.useDocumentState(n),m=null==(v=null==(x=null==f?void 0:f.document)?void 0:x.pages)?void 0:v[r],j=(null==(b=null==m?void 0:m.size)?void 0:b.width)??0,k=(null==(y=null==m?void 0:m.size)?void 0:y.height)??0,S=o.useMemo(()=>void 0!==l?l:(null==f?void 0:f.scale)??1,[l,null==f?void 0:f.scale]),M=o.useMemo(()=>void 0!==a?a:(null==f?void 0:f.rotation)??s.Rotation.Degree0,[a,null==f?void 0:f.rotation]);return i.jsxs("div",{style:{...t},...p,children:[i.jsx(w,{documentId:n,selectionMenu:c,pageIndex:r,scale:S,rotation:M,pageWidth:j,pageHeight:k,resizeUI:d,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h}),i.jsx(z,{documentId:n,pageIndex:r,scale:S}),i.jsx(P,{documentId:n,pageIndex:r,scale:S})]})},exports.useAnnotation=e=>{var n;const{provides:i}=u(),[s,r]=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 r(t.getState()),t.onStateChange(e=>{r(e)})},[i,e]),{state:s,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=u,exports.useAnnotationPlugin=d,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map