@embedpdf/plugin-annotation 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -13
- package/dist/index.js.map +1 -1
- package/dist/lib/tools/default-tools.d.ts +42 -0
- package/dist/lib/tools/types.d.ts +4 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +76 -40
- 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 +76 -40
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +4 -2
- package/dist/shared-preact/components/annotation-layer.d.ts +5 -2
- package/dist/shared-preact/components/annotations.d.ts +3 -1
- package/dist/shared-preact/components/text-markup/highlight.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +3 -3
- package/dist/shared-preact/components/text-markup/underline.d.ts +3 -3
- package/dist/shared-preact/types.d.ts +17 -0
- package/dist/shared-react/components/annotation-container.d.ts +4 -2
- package/dist/shared-react/components/annotation-layer.d.ts +5 -2
- package/dist/shared-react/components/annotations.d.ts +3 -1
- package/dist/shared-react/components/text-markup/highlight.d.ts +3 -3
- package/dist/shared-react/components/text-markup/squiggly.d.ts +3 -3
- package/dist/shared-react/components/text-markup/strikeout.d.ts +3 -3
- package/dist/shared-react/components/text-markup/underline.d.ts +3 -3
- package/dist/shared-react/types.d.ts +17 -0
- package/package.json +12 -11
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),d=()=>e.useCapability(t.AnnotationPlugin.id),c={suppressContentEditableWarning:!0};function u({scale:e,pageIndex:t,rotation:o,pageWidth:i,pageHeight:s,trackedAnnotation:a,children:c,isSelected:u,isDraggable:h,isResizable:g,lockAspectRatio:p=!1,style:x={},vertexConfig:y,selectionMenu:b,outlineOffset:f=1,onDoubleClick:v,zIndex:j=1,resizeUI:m,vertexUI:k,selectionOutlineColor:S="#007ACC",...M}){const[w,P]=r.useState(a.object),{provides:C}=d(),z=r.useRef(null),A=w?{...a.object,...w}:a.object,I=(null==m?void 0:m.color)??"#007ACC",D=(null==k?void 0:k.color)??"#007ACC",E=(null==m?void 0:m.size)??12,B=(null==k?void 0:k.size)??12,{dragProps:R,vertices:T,resize:$}=l.useInteractionHandles({controller:{element:A.rect,vertices:null==y?void 0:y.extractVertices(A),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&&(z.current=A);const o=e.transformData.type,i=z.current??A,s=e.transformData.changes.vertices?null==y?void 0:y.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&&(z.current=null,null==C||C.updateAnnotation(t,a.object.id,r))}},resizeUI:{handleSize:E,spacing:f,offsetMode:"outside",includeSides:!p,zIndex:j+1},vertexUI:{vertexSize:B,zIndex:j+2},includeVertices:!!y}),L=l.useDoublePressProps(v);return r.useEffect((()=>{P(a.object)}),[a.object]),n.jsxs("div",{"data-no-interaction":!0,children:[n.jsxs("div",{...h&&u?R:{},...L,style:{position:"absolute",left:A.rect.origin.x*e,top:A.rect.origin.y*e,width:A.rect.size.width*e,height:A.rect.size.height*e,outline:u?`1px solid ${S}`:"none",outlineOffset:u?`${f}px`:"0px",pointerEvents:u?"auto":"none",touchAction:"none",cursor:u&&h?"move":"default",zIndex:j,...x},...M,children:["function"==typeof c?c(A):c,u&&g&&$.map((({key:e,...t})=>(null==m?void 0:m.component)?m.component({key:e,...t,backgroundColor:I}):n.jsx("div",{...t,style:{...t.style,backgroundColor:I}},e))),u&&T.map((({key:e,...t})=>(null==k?void 0:k.component)?k.component({key:e,...t,backgroundColor:D}):n.jsx("div",{...t,style:{...t.style,backgroundColor:D}},e)))]}),n.jsx(l.CounterRotate,{rect:{origin:{x:A.rect.origin.x*e,y:A.rect.origin.y*e},size:{width:A.rect.size.width*e,height:A.rect.size.height*e}},rotation:o,children:({rect:e,menuWrapperProps:t})=>b&&b({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,...a}){return n.jsx(n.Fragment,{children:o.map(((o,d)=>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},d)))})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:o,rect:i,scale:s,onClick:r,style:l,...a}){const d=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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:d,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,...a}){const d=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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:d,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,...a}){const d=2*s,c=6*s,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${2*d}" viewBox="0 0 ${c} ${2*d}">\n <path d="M0 ${d} Q ${c/4} 0 ${c/2} ${d} T ${c} ${d}"\n fill="none" stroke="${e}" stroke-width="${d}" 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},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*d,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${c}px ${2*d}px`,opacity:t,pointerEvents:"none"}})},o)))})}function y({isSelected:e,color:t="#000000",opacity:o=1,strokeWidth:i,inkList:s,rect:l,scale:a,onClick:d}){const c=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:c.map(((s,r)=>n.jsx("path",{d:s,fill:"none",opacity:o,onPointerDown:d,onTouchStart:d,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function b({isSelected:e,color:t="#000000",strokeColor:i,opacity:s=1,strokeWidth:l,strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,scale:u,onClick:h}){const{width:g,height:p,x:x,y:y}=r.useMemo((()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-l,0),height:Math.max(t-l,0),x:l/2,y:l/2}}),[c,l]),b=(g+l)*u,f=(p+l)*u;return n.jsx("svg",{style:{position:"absolute",width:b,height:f,pointerEvents:"none",zIndex:2},width:b,height:f,viewBox:`0 0 ${g+l} ${p+l}`,children:n.jsx("rect",{x:x,y:y,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==d?void 0:d.join(",")}}})})}function f({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:s,strokeStyle:l=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:d,scale:c,onClick:u,isSelected:h}){const{width:g,height:p,cx:x,cy:y,rx:b,ry:f}=r.useMemo((()=>{const e=d.size.width,t=d.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}}),[d,s]),v=g*c,j=p*c;return n.jsx("svg",{style:{position:"absolute",width:v,height:j,pointerEvents:"none",zIndex:2},width:v,height:j,viewBox:`0 0 ${g} ${p}`,children:n.jsx("ellipse",{cx:x,cy:y,rx:b,ry:f,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 v({color:e="transparent",opacity:i=1,strokeWidth:s,strokeColor:l="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,linePoints:u,lineEndings:h,scale:g,onClick:p,isSelected:x}){const{x1:y,y1:b,x2:f,y2:v}=r.useMemo((()=>({x1:u.start.x-c.origin.x,y1:u.start.y-c.origin.y,x2:u.end.x-c.origin.x,y2:u.end.y-c.origin.y})),[u,c]),j=r.useMemo((()=>{const e=Math.atan2(v-b,f-y);return{start:t.patching.createEnding(null==h?void 0:h.start,s,e+Math.PI,y,b),end:t.patching.createEnding(null==h?void 0:h.end,s,e,f,v)}}),[h,s,y,b,f,v]),m=c.size.width*g,k=c.size.height*g;return n.jsxs("svg",{style:{position:"absolute",width:m,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:m,height:k,viewBox:`0 0 ${c.size.width} ${c.size.height}`,children:[n.jsx("line",{x1:y,y1:b,x2:f,y2:v,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==d?void 0:d.join(",")}}}),j.start&&n.jsx("path",{d:j.start.d,transform:j.start.transform,onPointerDown:p,onTouchStart:p,stroke:l,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.start.filled?e:"none"}),j.end&&n.jsx("path",{d:j.end.d,transform:j.end.transform,stroke:l,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:s,strokeLinecap:"butt",pointerEvents:x?"none":j.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:j.end.filled?e:"none"})]})}function j({rect:e,vertices:o,color:i="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,scale:d,isSelected:c,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]),y=e.size.width*d,b=e.size.height*d;return n.jsxs("svg",{style:{position:"absolute",width:y,height:b,pointerEvents:"none",zIndex:2,overflow:"visible"},width:y,height:b,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:c?"move":"pointer",pointerEvents:c?"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:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"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:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function m({rect:e,vertices:t,color:i="transparent",strokeColor:s="#000000",opacity:l=1,strokeWidth:a,strokeStyle:d=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,scale:u,isSelected:h,onClick:g,currentVertex:p,handleSize:x=14}){const y=p?[...t,p]:t,b=r.useMemo((()=>y.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[y,e]),f=r.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]),v=p&&t.length>0,j=e.size.width*u,m=e.size.height*u;return n.jsxs("svg",{style:{position:"absolute",width:j,height:m,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:m,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:f,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",...d===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),v&&t.length>1&&n.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:s,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),v&&t.length>=2&&n.jsx("rect",{x:b[0].x-x/u/2,y:b[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}=d(),[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,y=g&&t&&x>0&&x<16,b=y?16:x,f=y?x/16:1,v=y?100/f:100;return n.jsx("div",{style:{position:"absolute",width:i.object.rect.size.width*l,height:i.object.rect.size.height*l,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:a,onTouchStart:a,children:n.jsx("span",{ref:u,onBlur:()=>{h&&u.current&&h.updateAnnotation(s,i.object.id,{contents:u.current.innerText})},tabIndex:0,style:{color:i.object.fontColor,fontSize:b,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:y?`${v}%`:"100%",height:y?`${v}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:y?`scale(${f})`:void 0,transformOrigin:"top left"},contentEditable:t,...c,children:i.object.contents})})}function S({pageIndex:e,annotation:t,scaleFactor:i=1,style:s,...l}){const{provides:a}=d(),[c,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:c&&n.jsx("img",{src:c,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...l,style:{width:"100%",height:"100%",...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 w(e){const{pageIndex:l,scale:a,selectionMenu:c}=e,{provides:S}=d(),{provides:w}=s.useSelectionCapability(),[P,C]=r.useState([]),{register:z}=i.usePointerHandlers({pageIndex:l}),[A,I]=r.useState(null),[D,E]=r.useState(null);r.useEffect((()=>{S&&S.onStateChange((e=>{C(t.getAnnotationsByPageIndex(e,l)),I(t.getSelectedAnnotationByPageIndex(e,l))}))}),[S]);const B=r.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&S&&(S.deselectAnnotation(),E(null))}})),[S]),R=r.useCallback(((e,t)=>{e.stopPropagation(),S&&w&&(S.selectAnnotation(l,t.object.id),w.clear(),t.object.id!==D&&E(null))}),[S,w,D,l]);return r.useEffect((()=>z(B)),[z,B]),n.jsx(n.Fragment,{children:P.map((i=>{const s=(null==A?void 0:A.object.id)===i.object.id,d=D===i.object.id;return t.isInk(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:c,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{...e,isSelected:s,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isSquare(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:c,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(b,{...e,isSelected:s,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isCircle(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:c,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{...e,isSelected:s,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isUnderline(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:c,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(g,{...e,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isStrikeout(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:c,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(p,{...e,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isSquiggly(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:c,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{...e,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isHighlight(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!1,isResizable:!1,selectionMenu:c,zIndex:0,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(h,{...e,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isLine(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:c,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(v,{...e,isSelected:s,scale:a,onClick:e=>R(e,i)})})},i.object.id):t.isPolyline(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:c,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=>R(e,i)})})},i.object.id):t.isPolygon(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!1,selectionMenu:c,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=>R(e,i)})})},i.object.id):t.isFreeText(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!d,isResizable:!0,selectionMenu:c,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),E(i.object.id)},...e,children:e=>n.jsx(k,{isSelected:s,isEditing:d,annotation:{...i,object:e},pageIndex:l,scale:a,onClick:e=>R(e,i)})},i.object.id):t.isStamp(i)?n.jsx(u,{trackedAnnotation:i,isSelected:s,isDraggable:!0,isResizable:!0,selectionMenu:c,lockAspectRatio:!0,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=>R(e,i)})},i.object.id):null}))})}function P({pageIndex:e,scale:t}){var i,l,a,c,u,y,b,f,v,j,m,k;const{provides:S}=s.useSelectionCapability(),{provides:M}=d(),[w,P]=r.useState([]),[C,z]=r.useState(null),[A,I]=r.useState(null);if(r.useEffect((()=>{if(!S)return;return S.onSelectionChange((()=>{P(S.getHighlightRectsForPage(e)),z(S.getBoundingRectForPage(e))}))}),[S,e]),r.useEffect((()=>{if(!M)return;return M.onActiveToolChange(I)}),[M]),!C)return null;if(!A||!A.defaults)return null;switch(A.defaults.type){case o.PdfAnnotationSubtype.UNDERLINE:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(i=A.defaults)?void 0:i.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(l=A.defaults)?void 0:l.color,opacity:null==(a=A.defaults)?void 0:a.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.HIGHLIGHT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(c=A.defaults)?void 0:c.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(h,{color:null==(u=A.defaults)?void 0:u.color,opacity:null==(y=A.defaults)?void 0:y.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.STRIKEOUT:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(b=A.defaults)?void 0:b.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(p,{color:null==(f=A.defaults)?void 0:f.color,opacity:null==(v=A.defaults)?void 0:v.opacity,segmentRects:w,scale:t})});case o.PdfAnnotationSubtype.SQUIGGLY:return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(j=A.defaults)?void 0:j.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(m=A.defaults)?void 0:m.color,opacity:null==(k=A.defaults)?void 0:k.opacity,segmentRects:w,scale:t})});default:return null}}function C({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(f,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.SQUARE?n.jsx("div",{style:s,children:n.jsx(b,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYGON?n.jsx("div",{style:s,children:n.jsx(m,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.POLYLINE?n.jsx("div",{style:s,children:n.jsx(j,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.LINE?n.jsx("div",{style:s,children:n.jsx(v,{isSelected:!1,scale:t,...e.data})}):e.type===o.PdfAnnotationSubtype.INK?n.jsx("div",{style:s,children:n.jsx(y,{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 z({pageIndex:e,scale:t}){const{plugin:o}=a(),[i,s]=r.useState(new Map),l=r.useRef(null),d=r.useRef(null),c=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=d.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 d=t?t/l:1,c=n?n/a:1,u=Math.min(d,c,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:c,onPreview:(e,t)=>{s((n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o}))}})}),[e,t,o,c]),n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:l,type:"file",style:{display:"none"}}),n.jsx("canvas",{ref:d,style:{display:"none"}}),Array.from(i.entries()).map((([e,o])=>n.jsx(C,{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:d,selectionOutlineColor:c,...u}){return n.jsxs("div",{style:{...e},...u,children:[n.jsx(w,{selectionMenu:i,pageIndex:t,scale:o,rotation:d,pageWidth:l,pageHeight:a,resizeUI:s,vertexUI:r,selectionOutlineColor:c}),n.jsx(P,{pageIndex:t,scale:o}),n.jsx(z,{pageIndex:t,scale:o})]})},exports.useAnnotationCapability=d,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/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]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|