@embedpdf/plugin-annotation 1.5.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1760 -1444
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +58 -19
  6. package/dist/lib/annotation-plugin.d.ts +14 -5
  7. package/dist/lib/index.d.ts +1 -1
  8. package/dist/lib/reducer.d.ts +2 -1
  9. package/dist/lib/selectors.d.ts +10 -8
  10. package/dist/lib/types.d.ts +53 -10
  11. package/dist/preact/index.cjs +1 -1
  12. package/dist/preact/index.cjs.map +1 -1
  13. package/dist/preact/index.js +96 -48
  14. package/dist/preact/index.js.map +1 -1
  15. package/dist/react/index.cjs +1 -1
  16. package/dist/react/index.cjs.map +1 -1
  17. package/dist/react/index.js +96 -48
  18. package/dist/react/index.js.map +1 -1
  19. package/dist/shared/components/annotation-container.d.ts +4 -3
  20. package/dist/shared/components/annotation-layer.d.ts +7 -7
  21. package/dist/shared/components/annotation-paint-layer.d.ts +2 -1
  22. package/dist/shared/components/annotations/stamp.d.ts +2 -1
  23. package/dist/shared/components/annotations.d.ts +3 -2
  24. package/dist/shared/components/render-annotation.d.ts +2 -1
  25. package/dist/shared/components/text-markup.d.ts +2 -1
  26. package/dist/shared/components/types.d.ts +7 -7
  27. package/dist/shared/hooks/use-annotation.d.ts +8 -4
  28. package/dist/shared/index.d.ts +1 -0
  29. package/dist/shared-preact/components/annotation-container.d.ts +4 -3
  30. package/dist/shared-preact/components/annotation-layer.d.ts +7 -7
  31. package/dist/shared-preact/components/annotation-paint-layer.d.ts +2 -1
  32. package/dist/shared-preact/components/annotations/stamp.d.ts +2 -1
  33. package/dist/shared-preact/components/annotations.d.ts +3 -2
  34. package/dist/shared-preact/components/render-annotation.d.ts +2 -1
  35. package/dist/shared-preact/components/text-markup.d.ts +2 -1
  36. package/dist/shared-preact/components/types.d.ts +7 -7
  37. package/dist/shared-preact/hooks/use-annotation.d.ts +8 -4
  38. package/dist/shared-preact/index.d.ts +1 -0
  39. package/dist/shared-react/components/annotation-container.d.ts +4 -3
  40. package/dist/shared-react/components/annotation-layer.d.ts +7 -7
  41. package/dist/shared-react/components/annotation-paint-layer.d.ts +2 -1
  42. package/dist/shared-react/components/annotations/stamp.d.ts +2 -1
  43. package/dist/shared-react/components/annotations.d.ts +3 -2
  44. package/dist/shared-react/components/render-annotation.d.ts +2 -1
  45. package/dist/shared-react/components/text-markup.d.ts +2 -1
  46. package/dist/shared-react/components/types.d.ts +7 -7
  47. package/dist/shared-react/hooks/use-annotation.d.ts +8 -4
  48. package/dist/shared-react/index.d.ts +1 -0
  49. package/dist/svelte/components/AnnotationContainer.svelte.d.ts +26 -0
  50. package/dist/svelte/components/AnnotationLayer.svelte.d.ts +27 -0
  51. package/dist/svelte/components/AnnotationPaintLayer.svelte.d.ts +8 -0
  52. package/dist/svelte/components/Annotations.svelte.d.ts +22 -0
  53. package/dist/svelte/components/PreviewRenderer.svelte.d.ts +8 -0
  54. package/dist/svelte/components/RenderAnnotation.svelte.d.ts +13 -0
  55. package/dist/svelte/components/TextMarkup.svelte.d.ts +8 -0
  56. package/dist/svelte/components/annotations/Circle.svelte.d.ts +26 -0
  57. package/dist/svelte/components/annotations/FreeText.svelte.d.ts +15 -0
  58. package/dist/svelte/components/annotations/Ink.svelte.d.ts +14 -0
  59. package/dist/svelte/components/annotations/Line.svelte.d.ts +18 -0
  60. package/dist/svelte/components/annotations/Polygon.svelte.d.ts +19 -0
  61. package/dist/svelte/components/annotations/Polyline.svelte.d.ts +17 -0
  62. package/dist/svelte/components/annotations/Square.svelte.d.ts +16 -0
  63. package/dist/svelte/components/annotations/Stamp.svelte.d.ts +13 -0
  64. package/dist/svelte/components/annotations/index.d.ts +8 -0
  65. package/dist/svelte/components/index.d.ts +9 -0
  66. package/dist/svelte/components/text-markup/Highlight.svelte.d.ts +13 -0
  67. package/dist/svelte/components/text-markup/Squiggly.svelte.d.ts +13 -0
  68. package/dist/svelte/components/text-markup/Strikeout.svelte.d.ts +13 -0
  69. package/dist/svelte/components/text-markup/Underline.svelte.d.ts +13 -0
  70. package/dist/svelte/components/text-markup/index.d.ts +4 -0
  71. package/dist/svelte/components/types.d.ts +32 -0
  72. package/dist/svelte/hooks/index.d.ts +1 -0
  73. package/dist/svelte/hooks/use-annotation.svelte.d.ts +21 -0
  74. package/dist/svelte/index.cjs +2 -0
  75. package/dist/svelte/index.cjs.map +1 -0
  76. package/dist/svelte/index.d.ts +4 -0
  77. package/dist/svelte/index.js +3083 -0
  78. package/dist/svelte/index.js.map +1 -0
  79. package/dist/svelte/types.d.ts +54 -0
  80. package/dist/vue/components/annotation-container.vue.d.ts +10 -5
  81. package/dist/vue/components/annotation-layer.vue.d.ts +13 -7
  82. package/dist/vue/components/annotation-paint-layer.vue.d.ts +3 -1
  83. package/dist/vue/components/annotations/circle.vue.d.ts +2 -1
  84. package/dist/vue/components/annotations/free-text.vue.d.ts +2 -1
  85. package/dist/vue/components/annotations/ink.vue.d.ts +2 -1
  86. package/dist/vue/components/annotations/line.vue.d.ts +2 -1
  87. package/dist/vue/components/annotations/polygon.vue.d.ts +2 -1
  88. package/dist/vue/components/annotations/polyline.vue.d.ts +2 -1
  89. package/dist/vue/components/annotations/square.vue.d.ts +2 -1
  90. package/dist/vue/components/annotations/stamp.vue.d.ts +3 -1
  91. package/dist/vue/components/annotations.vue.d.ts +7 -3
  92. package/dist/vue/components/preview-renderer.vue.d.ts +2 -1
  93. package/dist/vue/components/render-annotation.vue.d.ts +3 -1
  94. package/dist/vue/components/text-markup/highlight.vue.d.ts +2 -1
  95. package/dist/vue/components/text-markup/squiggly.vue.d.ts +2 -1
  96. package/dist/vue/components/text-markup/strikeout.vue.d.ts +2 -1
  97. package/dist/vue/components/text-markup/underline.vue.d.ts +2 -1
  98. package/dist/vue/components/text-markup.vue.d.ts +3 -1
  99. package/dist/vue/hooks/use-annotation.d.ts +21 -2682
  100. package/dist/vue/index.cjs +1 -1
  101. package/dist/vue/index.cjs.map +1 -1
  102. package/dist/vue/index.d.ts +1 -0
  103. package/dist/vue/index.js +354 -250
  104. package/dist/vue/index.js.map +1 -1
  105. package/dist/vue/types.d.ts +23 -0
  106. package/package.json +19 -11
@@ -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"),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]})}));
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"),l=require("@embedpdf/plugin-selection/react"),r=require("@embedpdf/utils/react"),a={suppressContentEditableWarning:!0},d=()=>e.usePlugin(t.AnnotationPlugin.id),c=()=>e.useCapability(t.AnnotationPlugin.id);function u({scale:e,documentId:t,pageIndex:i,rotation:s,pageWidth:l,pageHeight:a,trackedAnnotation:d,children:u,isSelected:g,isDraggable:h,isResizable:p,lockAspectRatio:x=!1,style:v={},vertexConfig:b,selectionMenu:y,outlineOffset:f=1,onDoubleClick:m,onSelect:j,zIndex:k=1,resizeUI:S,vertexUI:M,selectionOutlineColor:A="#007ACC",customAnnotationRenderer:w,...z}){const[D,C]=n.useState(d.object),{provides:P}=c(),R=n.useRef(null),I=n.useMemo(()=>P?P.forDocument(t):null,[P,t]),E=D?{...d.object,...D}:d.object,B=(null==S?void 0:S.color)??"#007ACC",T=(null==M?void 0:M.color)??"#007ACC",$=(null==S?void 0:S.size)??12,L=(null==M?void 0:M.size)??12,{dragProps:F,vertices:O,resize:U}=r.useInteractionHandles({controller:{element:E.rect,vertices:null==b?void 0:b.extractVertices(E),constraints:{minWidth:10,minHeight:10,boundingBox:{width:l,height:a}},maintainAspectRatio:x,pageRotation:s,scale:e,enabled:g,onUpdate:e=>{var t;if(!(null==(t=e.transformData)?void 0:t.type))return;"start"===e.state&&(R.current=E);const n=e.transformData.type,o=R.current??E,s=e.transformData.changes.vertices?null==b?void 0:b.transformAnnotation(o,e.transformData.changes.vertices):{rect:e.transformData.changes.rect},l=null==P?void 0:P.transformAnnotation(o,{type:n,changes:s,metadata:e.transformData.metadata});l&&C(e=>({...e,...l})),"end"===e.state&&l&&(R.current=null,null==I||I.updateAnnotation(i,d.object.id,l))}},resizeUI:{handleSize:$,spacing:f,offsetMode:"outside",includeSides:!x,zIndex:k+1},vertexUI:{vertexSize:L,zIndex:k+2},includeVertices:!!b}),W=r.useDoublePressProps(m);return n.useEffect(()=>{C(d.object)},[d.object]),o.jsxs("div",{"data-no-interaction":!0,children:[o.jsxs("div",{...h&&g?F:{},...W,style:{position:"absolute",left:E.rect.origin.x*e,top:E.rect.origin.y*e,width:E.rect.size.width*e,height:E.rect.size.height*e,outline:g?`1px solid ${A}`:"none",outlineOffset:g?`${f}px`:"0px",pointerEvents:g?"auto":"none",touchAction:"none",cursor:g&&h?"move":"default",zIndex:k,...v},...z,children:[(()=>{const t="function"==typeof u?u(E):u,n=null==w?void 0:w({annotation:E,children:t,isSelected:g,scale:e,rotation:s,pageWidth:l,pageHeight:a,pageIndex:i,onSelect:j});return null!=n?n:t})(),g&&p&&U.map(({key:e,...t})=>(null==S?void 0:S.component)?S.component({key:e,...t,backgroundColor:B}):o.jsx("div",{...t,style:{...t.style,backgroundColor:B}},e)),g&&O.map(({key:e,...t})=>(null==M?void 0:M.component)?M.component({key:e,...t,backgroundColor:T}):o.jsx("div",{...t,style:{...t.style,backgroundColor:T}},e))]}),y&&o.jsx(r.CounterRotate,{rect:{origin:{x:E.rect.origin.x*e,y:E.rect.origin.y*e},size:{width:E.rect.size.width*e,height:E.rect.size.height*e}},rotation:s,children:e=>y({...e,context:{type:"annotation",annotation:d,pageIndex:i},selected:g,placement:{suggestTop:!1}})})]})}function g({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:l,style:r}){return o.jsx(o.Fragment,{children:n.map((n,a)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:void 0,...r}},a))})}function h({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:l,style:r}){const a=2*s;return o.jsx(o.Fragment,{children:n.map((n,d)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...r},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:a,background:e,opacity:t,pointerEvents:"none"}})},d))})}function p({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:l,style:r}){const a=2*s;return o.jsx(o.Fragment,{children:n.map((n,d)=>o.jsx("div",{onPointerDown:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...r},children:o.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:a,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d))})}function x({color:e="#FFFF00",opacity:t=.5,segmentRects:n,rect:i,scale:s,onClick:l,style:r}){const a=2*s,d=6*s,c=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*a}" viewBox="0 0 ${d} ${2*a}">\n <path d="M0 ${a} Q ${d/4} 0 ${d/2} ${a} T ${d} ${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:l,onTouchStart:l,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:l?"auto":"none",cursor:l?"pointer":"default",zIndex:l?1:0,...r},children:o.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*a,backgroundImage:c,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*a}px`,opacity:t,pointerEvents:"none"}})},n))})}function v({isSelected:e,color:t="#000000",opacity:i=1,strokeWidth:s,inkList:l,rect:r,scale:a,onClick:d}){const c=n.useMemo(()=>l.map(({points:e})=>{let t="";return e.forEach(({x:e,y:n},o)=>{const i=e-r.origin.x,s=n-r.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "}),t.trim()}),[l,r]),u=r.size.width*a,g=r.size.height*a;return o.jsx("svg",{style:{position:"absolute",width:u,height:g,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:g,viewBox:`0 0 ${r.size.width} ${r.size.height}`,children:c.map((n,l)=>o.jsx("path",{d:n,fill:"none",opacity:i,onPointerDown:d,onTouchStart:d,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"visibleStroke",stroke:t,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round"}},l))})}function b({isSelected:e,color:t="#000000",strokeColor:s,opacity:l=1,strokeWidth:r,strokeStyle:a=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,scale:u,onClick:g}){const{width:h,height:p,x:x,y:v}=n.useMemo(()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}},[c,r]),b=(h+r)*u,y=(p+r)*u;return o.jsx("svg",{style:{position:"absolute",width:b,height:y,pointerEvents:"none",zIndex:2},width:b,height:y,viewBox:`0 0 ${h+r} ${p+r}`,children:o.jsx("rect",{x:x,y:v,width:h,height:p,fill:t,opacity:l,onPointerDown:g,onTouchStart:g,style:{cursor:e?"move":"pointer",pointerEvents:e?"none":"transparent"===t?"visibleStroke":"visible",stroke:s??t,strokeWidth:r,...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}function y({color:e="#000000",strokeColor:t,opacity:s=1,strokeWidth:l,strokeStyle:r=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:d,scale:c,onClick:u,isSelected:g}){const{width:h,height:p,cx:x,cy:v,rx:b,ry:y}=n.useMemo(()=>{const e=d.size.width,t=d.size.height,n=Math.max(e-l,0),o=Math.max(t-l,0);return{width:e,height:t,cx:l/2+n/2,cy:l/2+o/2,rx:n/2,ry:o/2}},[d,l]),f=h*c,m=p*c;return o.jsx("svg",{style:{position:"absolute",width:f,height:m,pointerEvents:"none",zIndex:2},width:f,height:m,viewBox:`0 0 ${h} ${p}`,children:o.jsx("ellipse",{cx:x,cy:v,rx:b,ry:y,fill:e,opacity:s,onPointerDown:u,onTouchStart:u,style:{cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:l,...r===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function f({color:e="transparent",opacity:s=1,strokeWidth:l,strokeColor:r="#000000",strokeStyle:a=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,rect:c,linePoints:u,lineEndings:g,scale:h,onClick:p,isSelected:x}){const{x1:v,y1:b,x2:y,y2:f}=n.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]),m=n.useMemo(()=>{const e=Math.atan2(f-b,y-v);return{start:t.patching.createEnding(null==g?void 0:g.start,l,e+Math.PI,v,b),end:t.patching.createEnding(null==g?void 0:g.end,l,e,y,f)}},[g,l,v,b,y,f]),j=c.size.width*h,k=c.size.height*h;return o.jsxs("svg",{style:{position:"absolute",width:j,height:k,pointerEvents:"none",zIndex:2,overflow:"visible"},width:j,height:k,viewBox:`0 0 ${c.size.width} ${c.size.height}`,children:[o.jsx("line",{x1:v,y1:b,x2:y,y2:f,opacity:s,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",pointerEvents:x?"none":"visibleStroke",stroke:r,strokeWidth:l,strokeLinecap:"butt",...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}}),m.start&&o.jsx("path",{d:m.start.d,transform:m.start.transform,onPointerDown:p,onTouchStart:p,stroke:r,style:{cursor:x?"move":"pointer",strokeWidth:l,strokeLinecap:"butt",pointerEvents:x?"none":m.start.filled?"visible":"visibleStroke",...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:m.start.filled?e:"none"}),m.end&&o.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:r,onPointerDown:p,onTouchStart:p,style:{cursor:x?"move":"pointer",strokeWidth:l,strokeLinecap:"butt",pointerEvents:x?"none":m.end.filled?"visible":"visibleStroke",...a===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}},fill:m.end.filled?e:"none"})]})}function m({rect:e,vertices:i,color:s="transparent",strokeColor:l="#000000",opacity:r=1,strokeWidth:a,scale:d,isSelected:c,onClick:u,lineEndings:g}){const h=n.useMemo(()=>i.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[i,e]),p=n.useMemo(()=>{if(!h.length)return"";const[e,...t]=h;return`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y} `).join("").trim()},[h]),x=n.useMemo(()=>{if(h.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(h[0],h[1]),o=e(h[h.length-2],h[h.length-1]);return{start:t.patching.createEnding(null==g?void 0:g.start,a,n+Math.PI,h[0].x,h[0].y),end:t.patching.createEnding(null==g?void 0:g.end,a,o,h[h.length-1].x,h[h.length-1].y)}},[h,g,a]),v=e.size.width*d,b=e.size.height*d;return o.jsxs("svg",{style:{position:"absolute",width:v,height:b,pointerEvents:"none",zIndex:2,overflow:"visible"},width:v,height:b,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[o.jsx("path",{d:p,onPointerDown:u,onTouchStart:u,opacity:r,style:{fill:"none",stroke:l??s,strokeWidth:a,cursor:c?"move":"pointer",pointerEvents:c?"none":"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),x.start&&o.jsx("path",{d:x.start.d,transform:x.start.transform,stroke:l,fill:x.start.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),x.end&&o.jsx("path",{d:x.end.d,transform:x.end.transform,stroke:l,fill:x.end.filled?s:"none",onPointerDown:u,onTouchStart:u,style:{cursor:c?"move":"pointer",strokeWidth:a,pointerEvents:c?"none":x.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function j({rect:e,vertices:t,color:s="transparent",strokeColor:l="#000000",opacity:r=1,strokeWidth:a,strokeStyle:d=i.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,scale:u,isSelected:g,onClick:h,currentVertex:p,handleSize:x=14}){const v=p?[...t,p]:t,b=n.useMemo(()=>v.map(({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})),[v,e]),y=n.useMemo(()=>{if(!b.length)return"";const[e,...t]=b,n=!!p;return(`M ${e.x} ${e.y} `+t.map(e=>`L ${e.x} ${e.y}`).join(" ")+(n?"":" Z")).trim()},[b,p]),f=p&&t.length>0,m=e.size.width*u,j=e.size.height*u;return 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:y,onPointerDown:h,onTouchStart:h,opacity:r,style:{fill:p?"none":s,stroke:l??s,strokeWidth:a,cursor:g?"move":"pointer",pointerEvents:g?"none":"transparent"===s?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...d===i.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),f&&t.length>1&&o.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:l,strokeWidth:a,strokeDasharray:"4,4",opacity:.7}}),f&&t.length>=2&&o.jsx("rect",{x:b[0].x-x/u/2,y:b[0].y-x/u/2,width:x/u,height:x/u,fill:l,opacity:.4,stroke:l,strokeWidth:a/2})]})}function k({isSelected:e,isEditing:t,annotation:s,pageIndex:l,scale:r,onClick:d}){const u=n.useRef(null),{provides:g}=c(),[h,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*r,v=h&&t&&x>0&&x<16,b=v?16:x,y=v?x/16:1,f=v?100/y:100;return o.jsx("div",{style:{position:"absolute",width:s.object.rect.size.width*r,height:s.object.rect.size.height*r,cursor:e&&!t?"move":"default",pointerEvents:e&&!t?"none":"auto",zIndex:2},onPointerDown:d,onTouchStart:d,children:o.jsx("span",{ref:u,onBlur:()=>{g&&u.current&&g.updateAnnotation(l,s.object.id,{contents:u.current.innerText})},tabIndex:0,style:{color:s.object.fontColor,fontSize:b,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:v?`${f}%`:"100%",height:v?`${f}%`:"100%",lineHeight:"1.18",overflow:"hidden",cursor:t?"text":"pointer",outline:"none",transform:v?`scale(${y})`:void 0,transformOrigin:"top left"},contentEditable:t,...a,children:s.object.contents})})}function S({documentId:e,pageIndex:t,annotation:s,scaleFactor:l=1,style:r,...a}){const{provides:d}=c(),[u,g]=n.useState(null),h=n.useRef(null),{width:p,height:x}=s.rect.size;n.useEffect(()=>{if(d){const n=d.forDocument(e).renderAnnotation({pageIndex:t,annotation:s,options:{scaleFactor:l,dpr:window.devicePixelRatio}});return n.wait(e=>{const t=URL.createObjectURL(e);g(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"})}}},[t,l,d,e,s.id,p,x]);return o.jsx(n.Fragment,{children:u&&o.jsx("img",{src:u,onLoad:()=>{h.current&&(URL.revokeObjectURL(h.current),h.current=null)},...a,style:{width:"100%",height:"100%",display:"block",...r||{}}})})}function M({isSelected:e,annotation:t,documentId:n,pageIndex:i,scale:s,onClick:l}){return o.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",zIndex:2,pointerEvents:e?"none":"auto",cursor:"pointer"},onPointerDown:l,onTouchStart:l,children:o.jsx(S,{documentId:n,pageIndex:i,annotation:{...t.object,id:t.object.id},scaleFactor:s})})}function A(e){const{documentId:r,pageIndex:a,scale:d,selectionMenu:S}=e,{provides:A}=c(),{provides:w}=l.useSelectionCapability(),[z,D]=n.useState([]),{register:C}=s.usePointerHandlers({documentId:r,pageIndex:a}),[P,R]=n.useState(null),[I,E]=n.useState(null),B=n.useMemo(()=>A?A.forDocument(r):null,[A,r]);n.useEffect(()=>{if(B){const e=B.getState();return D(t.getAnnotationsByPageIndex(e,a)),R(t.getSelectedAnnotationByPageIndex(e,a)),B.onStateChange(e=>{D(t.getAnnotationsByPageIndex(e,a)),R(t.getSelectedAnnotationByPageIndex(e,a))})}},[B,a]);const T=n.useMemo(()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&B&&(B.deselectAnnotation(),E(null))}}),[B]),$=n.useCallback((e,t)=>{e.stopPropagation(),B&&w&&(B.selectAnnotation(a,t.object.id),w.clear(),t.object.id!==I&&E(null))},[B,w,I,a]);return n.useEffect(()=>C(T,{documentId:r}),[C,T]),o.jsx(o.Fragment,{children:z.map(s=>{const l=(null==P?void 0:P.object.id)===s.object.id,c=I===s.object.id,A=null==B?void 0:B.findToolForAnnotation(s.object);return t.isInk(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(v,{...e,isSelected:l,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isSquare(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(b,{...e,isSelected:l,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isCircle(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(y,{...e,isSelected:l,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isUnderline(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(h,{...e,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isStrikeout(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(p,{...e,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isSquiggly(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(x,{...e,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isHighlight(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),zIndex:0,style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Multiply)},...e,children:e=>o.jsx(g,{...e,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isLine(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(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:l,scale:d,onClick:e=>$(e,s)})})},s.object.id):t.isPolyline(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(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:l,scale:d,onClick:e=>$(e,s)})})},s.object.id):t.isPolygon(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(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:l,scale:d,onClick:e=>$(e,s)})})},s.object.id):t.isFreeText(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},onDoubleClick:e=>{e.stopPropagation(),E(s.object.id)},...e,children:e=>o.jsx(k,{isSelected:l,isEditing:c,annotation:{...s,object:e},pageIndex:a,scale:d,onClick:e=>$(e,s)})},s.object.id):t.isStamp(s)?o.jsx(u,{trackedAnnotation:s,isSelected:l,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:S,onSelect:e=>$(e,s),style:{mixBlendMode:i.blendModeToCss(s.object.blendMode??i.PdfBlendMode.Normal)},...e,children:e=>o.jsx(M,{isSelected:l,annotation:s,documentId:r,pageIndex:a,scale:d,onClick:e=>$(e,s)})},s.object.id):null})})}function w({documentId:e,pageIndex:t,scale:s}){var r,a,d,u,v,b,y,f,m,j,k,S;const{provides:M}=l.useSelectionCapability(),{provides:A}=c(),[w,z]=n.useState([]),[D,C]=n.useState(null),[P,R]=n.useState(null);if(n.useEffect(()=>{if(M)return M.forDocument(e).onSelectionChange(()=>{z(M.forDocument(e).getHighlightRectsForPage(t)),C(M.forDocument(e).getBoundingRectForPage(t))})},[M,e,t]),n.useEffect(()=>{if(A)return R(A.forDocument(e).getActiveTool()),A.forDocument(e).onActiveToolChange(e=>R(e))},[A,e]),!D)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==(r=P.defaults)?void 0:r.blendMode)??i.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(h,{color:null==(a=P.defaults)?void 0:a.color,opacity:null==(d=P.defaults)?void 0:d.opacity,segmentRects:w,scale:s})});case i.PdfAnnotationSubtype.HIGHLIGHT:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(u=P.defaults)?void 0:u.blendMode)??i.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(g,{color:null==(v=P.defaults)?void 0:v.color,opacity:null==(b=P.defaults)?void 0:b.opacity,segmentRects:w,scale:s})});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==(f=P.defaults)?void 0:f.color,opacity:null==(m=P.defaults)?void 0:m.opacity,segmentRects:w,scale:s})});case i.PdfAnnotationSubtype.SQUIGGLY:return o.jsx("div",{style:{mixBlendMode:i.blendModeToCss((null==(j=P.defaults)?void 0:j.blendMode)??i.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:o.jsx(x,{color:null==(k=P.defaults)?void 0:k.color,opacity:null==(S=P.defaults)?void 0:S.opacity,segmentRects:w,scale:s})});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(y,{isSelected:!1,scale:t,...e.data})}):e.type===i.PdfAnnotationSubtype.SQUARE?o.jsx("div",{style:s,children:o.jsx(b,{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(v,{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 D({documentId:e,pageIndex:t,scale:i}){const{plugin:s}=d(),[l,r]=n.useState(new Map),a=n.useRef(null),c=n.useRef(null),u=n.useMemo(()=>({requestFile:({accept:e,onFile:t})=>{if(!a.current)return;const n=a.current;n.accept=e,n.onchange=e=>{var o;const i=null==(o=e.target.files)?void 0:o[0];i&&(t(i),n.value="")},n.click()},processImage:({source:e,maxWidth:t,maxHeight:n,onComplete:o})=>{const i=c.current;if(!i||!i.getContext)return;const s=i.getContext("2d");if(!s)return;const l=new Image;l.crossOrigin="Anonymous",l.onload=()=>{let{naturalWidth:r,naturalHeight:a}=l;const d=t?t/r:1,c=n?n/a:1,u=Math.min(d,c,1),g=r*u,h=a*u;i.width=g,i.height=h,s.drawImage(l,0,0,g,h);const p=s.getImageData(0,0,g,h);"string"!=typeof e&&URL.revokeObjectURL(l.src),o({imageData:p,width:g,height:h})},l.src="string"==typeof e?e:URL.createObjectURL(e)}}),[]);return n.useEffect(()=>{if(s)return s.registerPageHandlers(e,t,i,{services:u,onPreview:(e,t)=>{r(n=>{const o=new Map(n);return t?o.set(e,t):o.delete(e),o})}})},[e,t,i,s,u]),o.jsxs(o.Fragment,{children:[o.jsx("input",{ref:a,type:"file",style:{display:"none"}}),o.jsx("canvas",{ref:c,style:{display:"none"}}),Array.from(l.entries()).map(([e,t])=>o.jsx(z,{preview:t,scale:i},e))]})}exports.AnnotationLayer=function({style:t,documentId:s,pageIndex:l,scale:r,rotation:a,selectionMenu:d,resizeUI:c,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h,...p}){var x,v,b,y;const f=e.useDocumentState(s),m=null==(v=null==(x=null==f?void 0:f.document)?void 0:x.pages)?void 0:v[l],j=(null==(b=null==m?void 0:m.size)?void 0:b.width)??0,k=(null==(y=null==m?void 0:m.size)?void 0:y.height)??0,S=n.useMemo(()=>void 0!==r?r:(null==f?void 0:f.scale)??1,[r,null==f?void 0:f.scale]),M=n.useMemo(()=>void 0!==a?a:(null==f?void 0:f.rotation)??i.Rotation.Degree0,[a,null==f?void 0:f.rotation]);return o.jsxs("div",{style:{...t},...p,children:[o.jsx(A,{documentId:s,selectionMenu:d,pageIndex:l,scale:S,rotation:M,pageWidth:j,pageHeight:k,resizeUI:c,vertexUI:u,selectionOutlineColor:g,customAnnotationRenderer:h}),o.jsx(w,{documentId:s,pageIndex:l,scale:S}),o.jsx(D,{documentId:s,pageIndex:l,scale:S})]})},exports.useAnnotation=e=>{var o;const{provides:i}=c(),[s,l]=n.useState((null==(o=null==i?void 0:i.forDocument(e))?void 0:o.getState())??t.initialDocumentState());return n.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return l(t.getState()),t.onStateChange(e=>{l(e)})},[i,e]),{state:s,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useAnnotationCapability=c,exports.useAnnotationPlugin=d,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map