@embedpdf/plugin-annotation 1.3.11 → 1.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +21 -5
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +21 -5
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +2 -1
- package/dist/shared-preact/components/annotation-layer.d.ts +1 -1
- package/dist/shared-preact/components/annotations.d.ts +1 -1
- package/dist/shared-preact/components/types.d.ts +51 -0
- package/dist/shared-preact/hooks/use-annotation.d.ts +5 -1
- package/dist/shared-preact/types.d.ts +1 -50
- package/dist/shared-react/components/annotation-container.d.ts +2 -1
- package/dist/shared-react/components/annotation-layer.d.ts +1 -1
- package/dist/shared-react/components/annotations.d.ts +1 -1
- package/dist/shared-react/components/types.d.ts +51 -0
- package/dist/shared-react/hooks/use-annotation.d.ts +5 -1
- package/dist/shared-react/types.d.ts +1 -50
- package/dist/vue/components/annotation-container.vue.d.ts +48 -0
- package/dist/vue/components/annotation-layer.vue.d.ts +27 -0
- package/dist/vue/components/annotation-paint-layer.vue.d.ts +6 -0
- package/dist/vue/components/annotations/circle.vue.d.ts +19 -0
- package/dist/vue/components/annotations/free-text.vue.d.ts +12 -0
- package/dist/vue/components/annotations/index.d.ts +8 -0
- package/dist/vue/components/annotations/ink.vue.d.ts +16 -0
- package/dist/vue/components/annotations/line.vue.d.ts +22 -0
- package/dist/vue/components/annotations/polygon.vue.d.ts +24 -0
- package/dist/vue/components/annotations/polyline.vue.d.ts +19 -0
- package/dist/vue/components/annotations/square.vue.d.ts +19 -0
- package/dist/vue/components/annotations/stamp.vue.d.ts +11 -0
- package/dist/vue/components/annotations.vue.d.ts +77 -0
- package/dist/vue/components/index.d.ts +9 -0
- package/dist/vue/components/preview-renderer.vue.d.ts +7 -0
- package/dist/vue/components/render-annotation.vue.d.ts +12 -0
- package/dist/vue/components/text-markup/highlight.vue.d.ts +14 -0
- package/dist/vue/components/text-markup/index.d.ts +4 -0
- package/dist/vue/components/text-markup/squiggly.vue.d.ts +14 -0
- package/dist/vue/components/text-markup/strikeout.vue.d.ts +14 -0
- package/dist/vue/components/text-markup/underline.vue.d.ts +14 -0
- package/dist/vue/components/text-markup.vue.d.ts +6 -0
- package/dist/vue/hooks/use-annotation.d.ts +2682 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +1921 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +10 -10
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-annotation"),n=require("react/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/react"),s=require("@embedpdf/plugin-selection/react"),r=require("react"),l=require("@embedpdf/utils/react"),a=()=>e.usePlugin(t.AnnotationPlugin.id),c=()=>e.useCapability(t.AnnotationPlugin.id),d={suppressContentEditableWarning:!0};function u({scale:e,pageIndex:t,rotation:o,pageWidth:i,pageHeight:s,trackedAnnotation:a,children:d,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:b,selectionMenu:y,outlineOffset:v=1,onDoubleClick:f,onSelect:m,zIndex:j=1,resizeUI:k,vertexUI:S,selectionOutlineColor:M="#007ACC",customAnnotationRenderer:A,...w}){const[z,P]=r.useState(a.object),{provides:C}=c(),R=r.useRef(null),D=z?{...a.object,...z}:a.object,I=(null==k?void 0:k.color)??"#007ACC",E=(null==S?void 0:S.color)??"#007ACC",B=(null==k?void 0:k.size)??12,T=(null==S?void 0:S.size)??12,{dragProps:$,vertices:L,resize:F}=l.useInteractionHandles({controller:{element:D.rect,vertices:null==b?void 0:b.extractVertices(D),constraints:{minWidth:10,minHeight:10,boundingBox:{width:i/e,height:s/e}},maintainAspectRatio:p,pageRotation:o,scale:e,enabled:u,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(R.current=D);const o=e.transformData.type,i=R.current??D,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==C?void 0:C.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});r&&P((e=>({...e,...r}))),"end"===e.state&&r&&(R.current=null,null==C||C.updateAnnotation(t,a.object.id,r))}},resizeUI:{handleSize:B,spacing:v,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:T,zIndex:j+2},includeVertices:!!b}),W=l.useDoublePressProps(f);return r.useEffect((()=>{P(a.object)}),[a.object]),n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...h&&u?$:{},...W,style:{position:"absolute",left:D.rect.origin.x*e,top:D.rect.origin.y*e,width:D.rect.size.width*e,height:D.rect.size.height*e,outline:u?`1px solid ${M}`:"none",outlineOffset:u?`${v}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...w,children:[(()=>{const n=null==A?void 0:A({annotation:D,isSelected:u,scale:e,rotation:o,pageWidth:i,pageHeight:s,pageIndex:t,onSelect:m});return null!=n?n:"function"==typeof d?d(D):d})(),u&&g&&F.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:I}):n.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&L.map((({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:E}):n.jsx("div",{...t,style:{...t.style,backgroundColor:E}},e)))]}),n.jsx(l.CounterRotate,{rect:{origin:{x:D.rect.origin.x*e,y:D.rect.origin.y*e},size:{width:D.rect.size.width*e,height:D.rect.size.height*e}},rotation:o,children:({rect:e,menuWrapperProps:t})=>y&&y({annotation:a,selected:u,rect:e,menuWrapperProps:t})})]})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){return n.jsx(n.Fragment,{children:o.map(((o,a)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:e,opacity:t,pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:void 0,...l}},a)))})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*s,top:(i?o.origin.y-i.origin.y:o.origin.y)*s,width:o.size.width*s,height:o.size.height*s,background:"transparent",pointerEvents:r?"auto":"none",cursor:r?"pointer":"default",zIndex:r?1:0,...l},children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,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 n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*s,top:(i?e.origin.y-i.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:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:d,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},o)))})}function b({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:s,rect:l,scale:a,onClick:c}){const d=r.useMemo((()=>s.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()}))),[s,l]),u=l.size.width*a,h=l.size.height*a;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map(((s,r)=>n.jsx("path",{d:s,fill:"none",opacity:o,onPointerDown:c,onTouchStart:c,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function y({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:l,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:g,height:p,x:x,y:b}=r.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]),y=(g+l)*u,v=(p+l)*u;return n.jsx("svg",{style:{position:"absolute",width:y,height:v,pointerEvents:"none",zIndex:2},width:y,height:v,viewBox:`0 0 ${g+l} ${p+l}`,children:n.jsx("rect",{x:x,y:b,width:g,height:p,fill:t,opacity:s,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:i??t,strokeWidth:l,...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function v({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:b,rx:y,ry:v}=r.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-s,0),o=Math.max(t-s,0);return{width:e,height:t,cx:s/2+n/2,cy:s/2+o/2,rx:n/2,ry:o/2}}),[c,s]),f=g*d,m=p*d;return n.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:x,cy:b,rx:y,ry:v,fill:e,opacity:i,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:s,...l===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function f({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:l="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:b,y1:y,x2:v,y2:f}=r.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=r.useMemo((()=>{const e=Math.atan2(f-y,v-b);return{start:t.patching.createEnding(null==h?void 0:h.start,s,e+Math.PI,b,y),end:t.patching.createEnding(null==h?void 0:h.end,s,e,v,f)}}),[h,s,b,y,v,f]),j=d.size.width*g,k=d.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:b,y1:y,x2:v,y2:f,opacity:i,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:s,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&n.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function m({rect:e,vertices:o,color:i="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=r.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),p=r.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[g]),x=r.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[0],g[1]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),b=e.size.width*c,y=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:y,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:l,style:{fill:"none",stroke:s??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:d?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&n.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:s,fill:x.start.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&n.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:s,fill:x.end.filled?i:"none",onPointerDown:u,onTouchStart:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:d?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function j({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const b=p?[...t,p]:t,y=r.useMemo((()=>b.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[b,e]),v=r.useMemo((()=>{if(!y.length)return"";const[e,...t]=y,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[y,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:m,height:j,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:j,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:v,onPointerDown:g,onTouchStart:g,opacity:l,style:{fill:p?"none":i,stroke:s??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),f&&t.length>1&&n.jsx("path",{d:`M ${y[y.length-1].x} ${y[y.length-1].y} L ${y[0].x} ${y[0].y}`,fill:"none",style:{stroke:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&n.jsx("rect",{x:y[0].x-x/u/2,y:y[0].y-x/u/2,width:x/u,height:x/u,fill:s,opacity:.4,stroke:s,strokeWidth:a/2})]})}function k({isSelected:e,isEditing:t,annotation:i,pageIndex:s,scale:l,onClick:a}){const u=r.useRef(null),{provides:h}=c(),[g,p]=r.useState(!1);r.useEffect((()=>{if(t&&u.current){const e=u.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]),r.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=i.object.fontSize*l,b=g&&t&&x>0&&x<16,y=b?16:x,v=b?x/16:1,f=b?100/v:100;return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*l,height:i.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:u,onBlur:()=>{h&&u.current&&h.updateAnnotation(s,i.object.id,{contents:u.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:y,fontFamily:o.standardFontCss(i.object.fontFamily),textAlign:o.textAlignmentToCss(i.object.textAlign),flexDirection:"column",justifyContent:i.object.verticalAlign===o.PdfVerticalAlignment.Top?"flex-start":i.object.verticalAlign===o.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:i.object.backgroundColor,opacity:i.object.opacity,width:b?`${f}%`:"100%",height:b?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:b?`scale(${v})`:void 0,transformOrigin:"top left"},contentEditable:t,...d,children:i.object.contents})})}function S({pageIndex:e,annotation:t,scaleFactor:i=1,style:s,...l}){const{provides:a}=c(),[d,u]=r.useState(null),h=r.useRef(null),{width:g,height:p}=t.rect.size;r.useEffect((()=>{if(a){const n=a.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:i,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);u(t),h.current=t}),o.ignore),()=>{h.current?(URL.revokeObjectURL(h.current),h.current=null):n.abort({code:o.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,i,a,t.id,g,p]);return n.jsx(r.Fragment,{children:d&&n.jsx("img",{src:d,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...l,style:{width:"100%",height:"100%",display:"block",...s||{}}})})}function M({isSelected:e,annotation:t,pageIndex:o,scale:i,onClick:s}){return n.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:s,onTouchStart:s,children:n.jsx(S,{pageIndex:o,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function A(e){const{pageIndex:l,scale:a,selectionMenu:d}=e,{provides:S}=c(),{provides:A}=s.useSelectionCapability(),[w,z]=r.useState([]),{register:P}=i.usePointerHandlers({pageIndex:l}),[C,R]=r.useState(null),[D,I]=r.useState(null);r.useEffect((()=>{S&&S.onStateChange((e=>{z(t.getAnnotationsByPageIndex(e,l)),R(t.getSelectedAnnotationByPageIndex(e,l))}))}),[S]);const E=r.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&S&&(S.deselectAnnotation(),I(null))}})),[S]),B=r.useCallback(((e,t)=>{e.stopPropagation(),S&&A&&(S.selectAnnotation(l,t.object.id),A.clear(),t.object.id!==D&&I(null))}),[S,A,D,l]);return r.useEffect((()=>P(E)),[P,E]),n.jsx(n.Fragment,{children:w.map((i=>{const s=(null==C?void 0:C.object.id)===i.object.id,c=D===i.object.id,A=null==S?void 0:S.findToolForAnnotation(i.object);return t.isInk(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isSquare(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isCircle(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(g,{...e,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(p,{...e,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{...e,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(h,{...e,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isLine(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(f,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(m,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(r.Fragment,{children:n.jsx(j,{...e,isSelected:s,scale:a,onClick:e=>B(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:((null==A?void 0:A.interaction.isDraggable)??!0)&&!c,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),I(i.object.id)},...e,children:e=>n.jsx(k,{isSelected:s,isEditing:c,annotation:{...i,object:e},pageIndex:l,scale:a,onClick:e=>B(e,i)})},i.object.id):t.isStamp(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:d,onSelect:e=>B(e,i),style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(M,{isSelected:s,annotation:i,pageIndex:l,scale:a,onClick:e=>B(e,i)})},i.object.id):null}))})}function w({pageIndex:e,scale:t}){var i,l,a,d,u,b,y,v,f,m,j,k;const{provides:S}=s.useSelectionCapability(),{provides:M}=c(),[A,w]=r.useState([]),[z,P]=r.useState(null),[C,R]=r.useState(null);if(r.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{w(S.getHighlightRectsForPage(e)),P(S.getBoundingRectForPage(e))}))}),[S,e]),r.useEffect((()=>{if(!M)return;return M.onActiveToolChange(R)}),[M]),!z)return null;if(!C||!C.defaults)return null;switch(C.defaults.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=C.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(l=C.defaults)?void 0:l.color,opacity:null==(a=C.defaults)?void 0:a.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(d=C.defaults)?void 0:d.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(h,{color:null==(u=C.defaults)?void 0:u.color,opacity:null==(b=C.defaults)?void 0:b.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(y=C.defaults)?void 0:y.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(v=C.defaults)?void 0:v.color,opacity:null==(f=C.defaults)?void 0:f.opacity,segmentRects:A,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(m=C.defaults)?void 0:m.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(j=C.defaults)?void 0:j.color,opacity:null==(k=C.defaults)?void 0:k.opacity,segmentRects:A,scale:t})});default:return null}}function z({preview:e,scale:t}){const{bounds:i}=e,s={position:"absolute",left:i.origin.x*t,top:i.origin.y*t,width:i.size.width*t,height:i.size.height*t,pointerEvents:"none",zIndex:10};return e.type===o.PdfAnnotationSubtype.CIRCLE?n.jsx("div",{style:s,children:n.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:s,children:n.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:s,children:n.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:s,children:n.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.LINE?n.jsx("div",{style:s,children:n.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.INK?n.jsx("div",{style:s,children:n.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.FREETEXT?n.jsx("div",{style:s,children:n.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function P({pageIndex:e,scale:t}){const{plugin:o}=a(),[i,s]=r.useState(new Map),l=r.useRef(null),c=r.useRef(null),d=r.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!l.current)return;const n=l.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),h=l*u,g=a*u;i.width=h,i.height=g,s.drawImage(r,0,0,h,g);const p=s.getImageData(0,0,h,g);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:h,height:g})},r.src="string"==typeof e?e:URL.createObjectURL(e)}})),[]);return r.useEffect((()=>{if(o)return o.registerPageHandlers(e,t,{services:d,onPreview:(e,t)=>{s((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,o,d]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:l,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(i.entries()).map((([e,o])=>n.jsx(z,{preview:o,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:o,selectionMenu:i,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:c,selectionOutlineColor:d,customAnnotationRenderer:u,...h}){return n.jsxs("div",{style:{...e},...h,children:[n.jsx(A,{selectionMenu:i,pageIndex:t,scale:o,rotation:c,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:d,customAnnotationRenderer:u}),n.jsx(w,{pageIndex:t,scale:o}),n.jsx(P,{pageIndex:t,scale:o})]})},exports.useAnnotationCapability=c,exports.useAnnotationPlugin=a,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/react"),t=require("@embedpdf/plugin-annotation"),n=require("react"),o=require("react/jsx-runtime"),i=require("@embedpdf/models"),s=require("@embedpdf/plugin-interaction-manager/react"),r=require("@embedpdf/plugin-selection/react"),l=require("@embedpdf/utils/react"),a={suppressContentEditableWarning:!0},c=()=>e.usePlugin(t.AnnotationPlugin.id),d=()=>e.useCapability(t.AnnotationPlugin.id);function u({scale:e,pageIndex:t,rotation:i,pageWidth:s,pageHeight:r,trackedAnnotation:a,children:c,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:b,selectionMenu:y,outlineOffset:v=1,onDoubleClick:f,onSelect:m,zIndex:j=1,resizeUI:k,vertexUI:S,selectionOutlineColor:M="#007ACC",customAnnotationRenderer:A,...w}){const[z,C]=n.useState(a.object),{provides:P}=d(),R=n.useRef(null),D=z?{...a.object,...z}:a.object,I=(null==k?void 0:k.color)??"#007ACC",E=(null==S?void 0:S.color)??"#007ACC",B=(null==k?void 0:k.size)??12,T=(null==S?void 0:S.size)??12,{dragProps:$,vertices:L,resize:F}=l.useInteractionHandles({controller:{element:D.rect,vertices:null==b?void 0:b.extractVertices(D),constraints:{minWidth:10,minHeight:10,boundingBox:{width:s/e,height:r/e}},maintainAspectRatio:p,pageRotation:i,scale:e,enabled:u,onUpdate:e=>{var n;if(!(null==(n=e.transformData)?void 0:n.type))return;"start"===e.state&&(R.current=D);const o=e.transformData.type,i=R.current??D,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(i,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},r=null==P?void 0:P.transformAnnotation(i,{type:o,changes:s,metadata:e.transformData.metadata});r&&C((e=>({...e,...r}))),"end"===e.state&&r&&(R.current=null,null==P||P.updateAnnotation(t,a.object.id,r))}},resizeUI:{handleSize:B,spacing:v,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:T,zIndex:j+2},includeVertices:!!b}),W=l.useDoublePressProps(f);return n.useEffect((()=>{C(a.object)}),[a.object]),o.jsxs("div",{"data-no-interaction":!0,children:[o.jsxs("div",{...h&&u?$:{},...W,style:{position:"absolute",left:D.rect.origin.x*e,top:D.rect.origin.y*e,width:D.rect.size.width*e,height:D.rect.size.height*e,outline:u?`1px solid ${M}`:"none",outlineOffset:u?`${v}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...w,children:[(()=>{const n="function"==typeof c?c(D):c,o=null==A?void 0:A({annotation:D,children:n,isSelected:u,scale:e,rotation:i,pageWidth:s,pageHeight:r,pageIndex:t,onSelect:m});return null!=o?o:n})(),u&&g&&F.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:I}):o.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&L.map((({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:E}):o.jsx("div",{...t,style:{...t.style,backgroundColor:E}},e)))]}),o.jsx(l.CounterRotate,{rect:{origin:{x:D.rect.origin.x*e,y:D.rect.origin.y*e},size:{width:D.rect.size.width*e,height:D.rect.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>y&&y({annotation:a,selected:u,rect:e,menuWrapperProps:t})})]})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:r,style:l}){return o.jsx(o.Fragment,{children:n.map(((n,a)=>o.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?n.origin.x-i.origin.x:n.origin.x)*s,top:(i?n.origin.y-i.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 g({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return o.jsx(o.Fragment,{children:n.map(((n,c)=>o.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?n.origin.x-i.origin.x:n.origin.x)*s,top:(i?n.origin.y-i.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:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},c)))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:r,style:l}){const a=2*s;return o.jsx(o.Fragment,{children:n.map(((n,c)=>o.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?n.origin.x-i.origin.x:n.origin.x)*s,top:(i?n.origin.y-i.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:o.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},c)))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,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 o.jsx(o.Fragment,{children:n.map(((e,n)=>o.jsx("div",{onPointerDown:r,onTouchStart:r,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*s,top:(i?e.origin.y-i.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: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 b({isSelected:e,color:t="#000000",opacity:i=1,strokeWidth:s,inkList:r,rect:l,scale:a,onClick:c}){const d=n.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,h=l.size.height*a;return o.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${l.size.width} ${l.size.height}`,children:d.map(((n,r)=>o.jsx("path",{d:n,fill:"none",opacity:i,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:s,opacity:r=1,strokeWidth:l,strokeStyle:a=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,scale:u,onClick:h}){const{width:g,height:p,x:x,y:b}=n.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]),y=(g+l)*u,v=(p+l)*u;return o.jsx("svg",{style:{position:"absolute",width:y,height:v,pointerEvents:"none",zIndex:2},width:y,height:v,viewBox:`0 0 ${g+l} ${p+l}`,children:o.jsx("rect",{x:x,y:b,width:g,height:p,fill:t,opacity:r,onPointerDown:h,onTouchStart:h,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:s??t,strokeWidth:l,...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}})})}function v({color:e="#000000",strokeColor:t,opacity:s=1,strokeWidth:r,strokeStyle:l=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:b,rx:y,ry:v}=n.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=g*d,m=p*d;return o.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${g} ${p}`,children:o.jsx("ellipse",{cx:x,cy:b,rx:y,ry:v,fill:e,opacity:s,onPointerDown:u,onTouchStart:u,style:{cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...l===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function f({color:e="transparent",opacity:s=1,strokeWidth:r,strokeColor:l="#000000",strokeStyle:a=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:b,y1:y,x2:v,y2:f}=n.useMemo((()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y})),[u,d]),m=n.useMemo((()=>{const e=Math.atan2(f-y,v-b);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,b,y),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,f)}}),[h,r,b,y,v,f]),j=d.size.width*g,k=d.size.height*g;return o.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[o.jsx("line",{x1:b,y1:y,x2:v,y2:f,opacity:s,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:l,strokeWidth:r,strokeLinecap:"butt",...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&o.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===i.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:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function m({rect:e,vertices:i,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const g=n.useMemo((()=>i.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[i,e]),p=n.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[g]),x=n.useMemo((()=>{if(g.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(g[0],g[1]),o=e(g[g.length-2],g[g.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,g[0].x,g[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,g[g.length-1].x,g[g.length-1].y)}}),[g,h,a]),b=e.size.width*c,y=e.size.height*c;return o.jsxs("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:y,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.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&&o.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&&o.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 j({rect:e,vertices:t,color:s="transparent",strokeColor:r="#000000",opacity:l=1,strokeWidth:a,strokeStyle:c=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const b=p?[...t,p]:t,y=n.useMemo((()=>b.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[b,e]),v=n.useMemo((()=>{if(!y.length)return"";const[e,...t]=y,n=!!p;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y}`)).join(" ")+(n?"":" Z")).trim()}),[y,p]),f=p&&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:v,onPointerDown:g,onTouchStart:g,opacity:l,style:{fill:p?"none":s,stroke:r??s,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:h?"none":"transparent"===s?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),f&&t.length>1&&o.jsx("path",{d:`M ${y[y.length-1].x} ${y[y.length-1].y} L ${y[0].x} ${y[0].y}`,fill:"none",style:{stroke:r,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&o.jsx("rect",{x:y[0].x-x/u/2,y:y[0].y-x/u/2,width:x/u,height:x/u,fill:r,opacity:.4,stroke:r,strokeWidth:a/2})]})}function k({isSelected:e,isEditing:t,annotation:s,pageIndex:r,scale:l,onClick:c}){const u=n.useRef(null),{provides:h}=d(),[g,p]=n.useState(!1);n.useEffect((()=>{if(t&&u.current){const e=u.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]),n.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=s.object.fontSize*l,b=g&&t&&x>0&&x<16,y=b?16:x,v=b?x/16:1,f=b?100/v:100;return o.jsx("div",{style:{position:"absolute",width:s.object.rect.size.width*l,height:s.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:c,onTouchStart:c,children:o.jsx("span",{ref:u,onBlur:()=>{h&&u.current&&h.updateAnnotation(r,s.object.id,{contents:u.current.innerText})},tabIndex:0,style:{color:s.object.fontColor,fontSize:y,fontFamily:i.standardFontCss(s.object.fontFamily),textAlign:i.textAlignmentToCss(s.object.textAlign),flexDirection:"column",justifyContent:s.object.verticalAlign===i.PdfVerticalAlignment.Top?"flex-start":s.object.verticalAlign===i.PdfVerticalAlignment.Middle?"center":"flex-end",display:"flex",backgroundColor:s.object.backgroundColor,opacity:s.object.opacity,width:b?`${f}%`:"100%",height:b?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:b?`scale(${v})`:void 0,transformOrigin:"top left"},contentEditable:t,...a,children:s.object.contents})})}function S({pageIndex:e,annotation:t,scaleFactor:s=1,style:r,...l}){const{provides:a}=d(),[c,u]=n.useState(null),h=n.useRef(null),{width:g,height:p}=t.rect.size;n.useEffect((()=>{if(a){const n=a.renderAnnotation({pageIndex:e,annotation:t,options:{scaleFactor:s,dpr:window.devicePixelRatio}});return n.wait((e=>{const t=URL.createObjectURL(e);u(t),h.current=t}),i.ignore),()=>{h.current?(URL.revokeObjectURL(h.current),h.current=null):n.abort({code:i.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[e,s,a,t.id,g,p]);return o.jsx(n.Fragment,{children:c&&o.jsx("img",{src:c,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...l,style:{width:"100%",height:"100%",display:"block",...r||{}}})})}function M({isSelected:e,annotation:t,pageIndex:n,scale:i,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(S,{pageIndex:n,annotation:{...t.object,id:t.object.id},scaleFactor:i})})}function A(e){const{pageIndex:l,scale:a,selectionMenu:c}=e,{provides:S}=d(),{provides:A}=r.useSelectionCapability(),[w,z]=n.useState([]),{register:C}=s.usePointerHandlers({pageIndex:l}),[P,R]=n.useState(null),[D,I]=n.useState(null);n.useEffect((()=>{S&&S.onStateChange((e=>{z(t.getAnnotationsByPageIndex(e,l)),R(t.getSelectedAnnotationByPageIndex(e,l))}))}),[S]);const E=n.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&S&&(S.deselectAnnotation(),I(null))}})),[S]),B=n.useCallback(((e,t)=>{e.stopPropagation(),S&&A&&(S.selectAnnotation(l,t.object.id),A.clear(),t.object.id!==D&&I(null))}),[S,A,D,l]);return n.useEffect((()=>C(E)),[C,E]),o.jsx(o.Fragment,{children:w.map((s=>{const r=(null==P?void 0:P.object.id)===s.object.id,d=D===s.object.id,A=null==S?void 0:S.findToolForAnnotation(s.object);return t.isInk(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(b,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isSquare(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(y,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isCircle(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(v,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isUnderline(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(g,{...e,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isStrikeout(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(p,{...e,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isSquiggly(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(x,{...e,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isHighlight(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!1,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(h,{...e,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isLine(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),vertexConfig:{extractVertices:e=>[e.linePoints.start,e.linePoints.end],transformAnnotation:(e,t)=>({...e,linePoints:{start:t[0],end:t[1]}})},style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(f,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})})},s.object.id):t.isPolyline(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(m,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})})},s.object.id):t.isPolygon(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!1,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),vertexConfig:{extractVertices:e=>e.vertices,transformAnnotation:(e,t)=>({...e,vertices:t})},style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(n.Fragment,{children:o.jsx(j,{...e,isSelected:r,scale:a,onClick:e=>B(e,s)})})},s.object.id):t.isFreeText(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:((null==A?void 0:A.interaction.isDraggable)??!0)&&!d,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),I(s.object.id)},...e,children:e=>o.jsx(k,{isSelected:r,isEditing:d,annotation:{...s,object:e},pageIndex:l,scale:a,onClick:e=>B(e,s)})},s.object.id):t.isStamp(s)?o.jsx(u,{trackedAnnotation:s,isSelected:r,isDraggable:(null==A?void 0:A.interaction.isDraggable)??!0,isResizable:(null==A?void 0:A.interaction.isResizable)??!0,lockAspectRatio:(null==A?void 0:A.interaction.lockAspectRatio)??!1,selectionMenu:c,onSelect:e=>B(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(M,{isSelected:r,annotation:s,pageIndex:l,scale:a,onClick:e=>B(e,s)})},s.object.id):null}))})}function w({pageIndex:e,scale:t}){var s,l,a,c,u,b,y,v,f,m,j,k;const{provides:S}=r.useSelectionCapability(),{provides:M}=d(),[A,w]=n.useState([]),[z,C]=n.useState(null),[P,R]=n.useState(null);if(n.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{w(S.getHighlightRectsForPage(e)),C(S.getBoundingRectForPage(e))}))}),[S,e]),n.useEffect((()=>{if(!M)return;return M.onActiveToolChange(R)}),[M]),!z)return null;if(!P||!P.defaults)return null;switch(P.defaults.type){case i.PdfAnnotationSubtype.UNDERLINE:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(s=P.defaults)?void 0:s.blendMode)??i.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(g,{color:null==(l=P.defaults)?void 0:l.color,opacity:null==(a=P.defaults)?void 0:a.opacity,segmentRects:A,scale:t})});case i.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(c=P.defaults)?void 0:c.blendMode)??i.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(h,{color:null==(u=P.defaults)?void 0:u.color,opacity:null==(b=P.defaults)?void 0:b.opacity,segmentRects:A,scale:t})});case i.PdfAnnotationSubtype.STRIKEOUT:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(y=P.defaults)?void 0:y.blendMode)??i.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(p,{color:null==(v=P.defaults)?void 0:v.color,opacity:null==(f=P.defaults)?void 0:f.opacity,segmentRects:A,scale:t})});case i.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(m=P.defaults)?void 0:m.blendMode)??i.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(x,{color:null==(j=P.defaults)?void 0:j.color,opacity:null==(k=P.defaults)?void 0:k.opacity,segmentRects:A,scale:t})});default:return null}}function z({preview:e,scale:t}){const{bounds:n}=e,s={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===i.PdfAnnotationSubtype.CIRCLE?o.jsx("div",{style:s,children:o.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:s,children:o.jsx(y,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.POLYGON?o.jsx("div",{style:s,children:o.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.POLYLINE?o.jsx("div",{style:s,children:o.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.LINE?o.jsx("div",{style:s,children:o.jsx(f,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.INK?o.jsx("div",{style:s,children:o.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.FREETEXT?o.jsx("div",{style:s,children:o.jsx("div",{style:{width:"100%",height:"100%",border:`1px dashed ${e.data.fontColor||"#000000"}`,backgroundColor:"transparent"}})}):null}function C({pageIndex:e,scale:t}){const{plugin:i}=c(),[s,r]=n.useState(new Map),l=n.useRef(null),a=n.useRef(null),d=n.useMemo((()=>({requestFile:({accept:e,onFile:t})=>{if(!l.current)return;const n=l.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=a.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),h=l*u,g=a*u;i.width=h,i.height=g,s.drawImage(r,0,0,h,g);const p=s.getImageData(0,0,h,g);"string"!=typeof e&&URL.revokeObjectURL(r.src),o({imageData:p,width:h,height:g})},r.src="string"==typeof e?e:URL.createObjectURL(e)}})),[]);return n.useEffect((()=>{if(i)return i.registerPageHandlers(e,t,{services:d,onPreview:(e,t)=>{r((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,i,d]),o.jsxs(o.Fragment,{children:[o.jsx("input",{ref:l,type:"file",style:{display:"none"}}),o.jsx("canvas",{ref:a,style:{display:"none"}}),Array.from(s.entries()).map((([e,n])=>o.jsx(z,{preview:n,scale:t},e)))]})}exports.AnnotationLayer=function({style:e,pageIndex:t,scale:n,selectionMenu:i,resizeUI:s,vertexUI:r,pageWidth:l,pageHeight:a,rotation:c,selectionOutlineColor:d,customAnnotationRenderer:u,...h}){return o.jsxs("div",{style:{...e},...h,children:[o.jsx(A,{selectionMenu:i,pageIndex:t,scale:n,rotation:c,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:d,customAnnotationRenderer:u}),o.jsx(w,{pageIndex:t,scale:n}),o.jsx(C,{pageIndex:t,scale:n})]})},exports.useAnnotation=()=>{const{provides:e}=d(),[o,i]=n.useState(t.initialState({enabled:!0}));return n.useEffect((()=>null==e?void 0:e.onStateChange((e=>{i(e)}))),[e]),{state:o,provides:e}},exports.useAnnotationCapability=d,exports.useAnnotationPlugin=c,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
|