epochs-pdf 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,27 @@
1
- "use strict";var Ci=Object.defineProperty;var Ti=(e,t,n)=>t in e?Ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Et=(e,t,n)=>Ti(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react"),r=require("react/jsx-runtime"),$n=require("pdfjs-dist");function $i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const rt=$i($n),pt="#ffffff",Yt=[{id:"yellow",label:"Yellow",hex:"#facc15"},{id:"green",label:"Green",hex:"#4ade80"},{id:"pink",label:"Pink",hex:"#f472b6"},{id:"blue",label:"Blue",hex:"#60a5fa"},{id:"orange",label:"Orange",hex:"#fb923c"},{id:"purple",label:"Purple",hex:"#c084fc"}],Zt=[{id:"blue",label:"Blue",hex:"#2563eb"},{id:"red",label:"Red",hex:"#dc2626"},{id:"green",label:"Green",hex:"#16a34a"},{id:"orange",label:"Orange",hex:"#ea580c"},{id:"purple",label:"Purple",hex:"#7c3aed"},{id:"black",label:"Black",hex:"#111827"}],Rn=Yt[0].hex,Ri=Zt[0].hex;Kt(Rn,"highlight");function At(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Ye(e){const t=e.trim();if(/^#[0-9a-fA-F]{6}$/.test(t))return t.toLowerCase();if(/^#[0-9a-fA-F]{3}$/.test(t)){const n=t[1],i=t[2],s=t[3];return`#${n}${n}${i}${i}${s}${s}`.toLowerCase()}return t}function Kt(e,t,n=.45){const i=Ye(e);if(t==="underline"||t==="redact")return i;const s=/^#([0-9a-f]{6})$/i.exec(i);if(!s)return`rgba(250, 204, 21, ${n})`;const o=Number.parseInt(s[1],16),c=o>>16&255,l=o>>8&255,x=o&255;return`rgba(${c}, ${l}, ${x}, ${n})`}function Bt(e,t){const n=window.getSelection();if(!n||n.isCollapsed||n.rangeCount===0)return null;const i=n.getRangeAt(0);if(!e.contains(i.commonAncestorContainer))return null;const s=e.getBoundingClientRect(),o=Array.from(i.getClientRects()).filter(M=>M.width>0&&M.height>0);if(!o.length)return null;const c=t||1,l=e.clientWidth||s.width,x=e.clientHeight||s.height;return{rects:o.map(M=>({x:s.width>0?(M.left-s.left)/s.width*(l/c):0,y:s.height>0?(M.top-s.top)/s.height*(x/c):0,w:s.width>0?M.width/s.width*(l/c):0,h:s.height>0?M.height/s.height*(x/c):0})),text:n.toString()}}function kn(e){const n=[...e].sort((i,s)=>i.y-s.y||i.x-s.x)[0]??{x:0,y:0,h:14};return{x:n.x,y:n.y,fontSize:Math.max(8,Math.round(n.h*.9)||14)}}function Ot(e,t=2){return e.map(n=>({x:Math.max(0,n.x-t),y:Math.max(0,n.y-t),w:n.w+t*2,h:n.h+t*2}))}function In(e,t,n){for(const i of t)for(const s of i.rects){const o=s.x*n,c=s.y*n,l=s.w*n,x=s.h*n;if(i.kind==="highlight")e.save(),e.globalCompositeOperation="multiply",e.fillStyle=i.color,e.fillRect(o,c,l,x),e.restore();else if(i.kind==="redact")e.fillStyle=i.color||pt,e.fillRect(o,c,l,x);else{const g=Math.max(2,n*1.5);e.fillStyle=i.color,e.fillRect(o,c+x-g,l,g)}}}function Pt(){return`s_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}async function Ln(e,t,n){for(const i of t){const s=await Li(i.imageDataUrl);e.drawImage(s,i.x*n,i.y*n,i.width*n,i.height*n)}}function Ii(e,t,n,i){e.save();for(const s of t){const o=n.has(s.id),c=s.x*i,l=s.y*i,x=s.width*i,g=s.height*i;e.fillStyle=o?"rgba(29, 78, 216, 0.08)":"rgba(29, 78, 216, 0.18)",e.strokeStyle=o?"rgba(29, 78, 216, 0.45)":"#1d4ed8",e.lineWidth=1.5,e.setLineDash(o?[]:[4,3]),e.fillRect(c,l,x,g),e.strokeRect(c,l,x,g)}e.restore()}function Li(e){return new Promise((t,n)=>{const i=new Image;i.onload=()=>t(i),i.onerror=()=>n(new Error("Failed to load signature image")),i.src=e})}function Si(e,t,n=180,i=64){if(e<=0||t<=0)return{width:n,height:i};const s=Math.min(n/e,i/t);return{width:Math.max(40,e*s),height:Math.max(20,t*s)}}function jt(e,t,n,i){const s=n.getBoundingClientRect(),o=n.clientWidth||s.width,c=n.clientHeight||s.height;return s.width<=0||s.height<=0||i<=0?{x:0,y:0}:{x:(e-s.left)/s.width*(o/i),y:(t-s.top)/s.height*(c/i)}}function mt(e,t){return{width:e.clientWidth/t,height:e.clientHeight/t}}function Fi(e,t,n,i){const s=n.getBoundingClientRect(),o=n.clientWidth||s.width,c=n.clientHeight||s.height;return s.width<=0||s.height<=0||i<=0?{dx:0,dy:0}:{dx:e/s.width*(o/i),dy:t/s.height*(c/i)}}function Di(e,t,n){const i=t.getBoundingClientRect(),{width:s,height:o}=mt(t,n);return i.width<=0||i.height<=0?{left:0,top:0,right:s,bottom:o}:{left:(e.left-i.left)/i.width*s,top:(e.top-i.top)/i.height*o,right:(e.right-i.left)/i.width*s,bottom:(e.bottom-i.top)/i.height*o}}const wt=14,gt="#111827",Ht=24,Ut=20;function zt(){return`t_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function ht(e,t){if(typeof document>"u")return{width:Math.max(Ht,e.length*t*.55),height:Math.max(Ut,t*1.25)};const i=document.createElement("canvas").getContext("2d");if(!i)return{width:Math.max(Ht,e.length*t*.55),height:Math.max(Ut,t*1.25)};i.font=`${t}px sans-serif`;const s=e.split(`
2
- `),o=t*1.25;let c=Ht;for(const l of s)c=Math.max(c,i.measureText(l||" ").width+4);return{width:c,height:Math.max(Ut,s.length*o)}}function Ei(e,t,n,i,s){var A;const o=n.getBoundingClientRect(),c=n.clientWidth||o.width,l=n.clientHeight||o.height,x=C=>o.width>0?(C-o.left)/o.width*(c/s):0,g=C=>o.height>0?(C-o.top)/o.height*(l/s):0,M=(C,K)=>{const Q=K==="x"?o.width:o.height,z=K==="x"?c:l;return Q>0?C/Q*(z/s):0};let v=x(e),m=g(t),P=wt;const N=Ai(e,t,i);if(N)return{x:x(N.x),y:g(N.y),fontSize:Math.max(8,Math.round(M(N.fontSize,"y")*10)/10)};const U=document,E=(A=U.caretRangeFromPoint)==null?void 0:A.call(U,e,t);if(E&&i.contains(E.startContainer)){const C=E.getClientRects(),K=C.length>0?C[0]:E.getBoundingClientRect();if(K.height>0){m=g(K.top),P=Oi(E.startContainer,s,n);const Q=x(K.left);return Math.abs(Q-v)<M(8,"x")&&(v=Q),{x:v,y:m,fontSize:P}}}const B=Bi(e,t,i);return B&&(m=g(B.top),P=Math.max(8,Math.round(M(B.height,"y")*10)/10)),{x:v,y:m,fontSize:P}}function Ai(e,t,n){var o;const i=Array.from(n.querySelectorAll("span"));if(i.length<2)return null;const s=[];for(const c of i){if(!((o=c.textContent)!=null&&o.trim()))continue;const l=c.getBoundingClientRect();l.width<=0||l.height<=0||t<l.top-4||t>l.bottom+4||s.push({left:l.left,right:l.right,top:l.top,bottom:l.bottom,height:l.height})}s.sort((c,l)=>c.left-l.left);for(let c=0;c<s.length-1;c+=1){const l=s[c],x=s[c+1],g=l.right,M=x.left;if(!(M-g<1)&&e>=g-2&&e<=M+2)return{x:e,y:Math.min(l.top,x.top),fontSize:Math.min(l.height,x.height)}}return null}function Bi(e,t,n){var o;const i=Array.from(n.querySelectorAll("span"));let s=null;for(const c of i){if(!((o=c.textContent)!=null&&o.trim()))continue;const l=c.getBoundingClientRect();if(l.width<=0||l.height<=0||t<l.top-6||t>l.bottom+6)continue;const x=(l.left+l.right)/2,g=Math.abs(e-x);(!s||g<s.dist)&&(s={top:l.top,height:l.height,dist:g})}return s?{top:s.top,height:s.height}:null}function Oi(e,t,n){const i=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return i?Hi(i,t,n):wt}function Hi(e,t,n){const i=e.getBoundingClientRect().height;if(i>0){if(n){const c=n.getBoundingClientRect(),l=n.clientHeight||c.height;if(c.height>0)return Math.max(8,Math.round(i/c.height*(l/t)*10)/10)}return Math.max(8,Math.round(i/t*10)/10)}const s=window.getComputedStyle(e).fontSize,o=Number.parseFloat(s);return Number.isFinite(o)&&o>0?Math.max(8,Math.round(o/t*10)/10):wt}function Ui(e,t,n,i){for(const s of n)if(s.pageNumber===i&&e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height)return s;return null}function zi(e,t,n){var P;if(!n)return null;const i=document,s=(P=i.caretRangeFromPoint)==null?void 0:P.call(i,e,t);if(!s||!n.contains(s.startContainer))return null;const o=s.startContainer;if(o.nodeType!==Node.TEXT_NODE||!o.textContent)return null;const c=o.textContent;let l=s.startOffset;l=Math.min(Math.max(0,l),c.length);const x=N=>/[\p{L}\p{N}_'-]/u.test(N);let g=l,M=l;for(;g>0&&x(c[g-1]);)g-=1;for(;M<c.length&&x(c[M]);)M+=1;if(g===M)return null;const v=document.createRange();v.setStart(o,g),v.setEnd(o,M);const m=window.getSelection();return m==null||m.removeAllRanges(),m==null||m.addRange(v),c.slice(g,M)}function Sn(e,t,n){e.save();for(const i of t){if(!i.value.trim())continue;const s=i.x*n,o=i.y*n,c=Math.max(8,i.fontSize*n);e.fillStyle=i.color,e.font=`${c}px sans-serif`,e.textBaseline="top";const l=c*1.25,x=i.value.split(`
3
- `);let g=o;for(const M of x)e.fillText(M,s,g),g+=l}e.restore()}function Wi(e,t,n,i){e.save();for(const s of t){const o=n.has(s.id),c=s.x*i,l=s.y*i,x=s.width*i,g=s.height*i;e.fillStyle=o?"rgba(5, 150, 105, 0.08)":"rgba(5, 150, 105, 0.16)",e.strokeStyle=o?"rgba(5, 150, 105, 0.45)":"#059669",e.lineWidth=1.5,e.setLineDash(o?[]:[4,3]),e.fillRect(c,l,x,g),e.strokeRect(c,l,x,g)}e.restore()}function ve({size:e=14,className:t,children:n}){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,"aria-hidden":"true",children:n})}function Gi(e){return r.jsx(ve,{...e,children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}function Xi(e){return r.jsx(ve,{...e,children:r.jsx("polyline",{points:"9 18 15 12 9 6"})})}function qi(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),r.jsx("polyline",{points:"7 10 12 15 17 10"}),r.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function Yi(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),r.jsx("polyline",{points:"15 3 21 3 21 9"}),r.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}function Zi(e){return r.jsxs(ve,{...e,children:[r.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),r.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}function Ki(e){return r.jsx(ve,{...e,children:r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Vi(e){return r.jsxs(ve,{...e,children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Qi(e){return r.jsxs(ve,{...e,children:[r.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),r.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),r.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})}function Ji(e){return r.jsxs(ve,{...e,children:[r.jsx("polyline",{points:"23 4 23 10 17 10"}),r.jsx("polyline",{points:"1 20 1 14 7 14"}),r.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})}function er(e){return r.jsxs(ve,{...e,children:[r.jsx("polyline",{points:"23 4 23 10 17 10"}),r.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function tr(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"M12 20h9"}),r.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})}function nr(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),r.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function ir(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"}),r.jsx("path",{d:"M22 21H7"}),r.jsx("path",{d:"m5 11 9 9"})]})}function rr({size:e=16,className:t}){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 256 256",fill:"currentColor",stroke:"currentColor",strokeWidth:"12",strokeLinejoin:"round",className:t,"aria-hidden":"true",children:r.jsx("path",{d:"M232,172H57.32c4-7.83,8.18-16.11,12.21-24.56,15.14,3.55,34.13-8.06,56.54-34.59,3.67,12.5,12.53,34.83,29.08,35.15h.35c8.71,0,17.64-6.25,27.16-19.06C187.17,137.14,199.31,148,232,148a4,4,0,0,0,0-8c-42.88,0-44-19.24-44-20a4,4,0,0,0-7.35-2.18C168.74,136.1,160.42,140,155.48,140h-.18c-13-.25-21.29-26.52-23.38-36.61a4,4,0,0,0-7-1.69c-20.94,26.27-39.06,39.55-51.8,38.2C97.31,87.5,105.19,53.16,96.49,37.77,94,33.31,88.7,28,77.91,28,64.09,28,52.54,42.41,47,66.54A122.7,122.7,0,0,0,45.46,113c2.64,15.29,8.39,26.05,16.69,31.35-4.58,9.6-9.3,19-13.84,27.68H24a4,4,0,0,0,0,8H44.1c-12.87,24.17-23.37,41.68-23.53,41.94a4,4,0,0,0,1.37,5.49A3.93,3.93,0,0,0,24,228a4,4,0,0,0,3.43-1.94c.16-.27,11.85-19.75,25.72-46.06H232a4,4,0,0,0,0-8ZM53.34,111.61a114.81,114.81,0,0,1,1.49-43.29C58.4,52.7,66.34,36,77.91,36c7.52,0,10.23,3.26,11.61,5.7C99,58.4,79.92,106,65.6,137,59.76,132.69,55.46,123.83,53.34,111.61Z"})})}function sr(e){return r.jsxs(ve,{...e,children:[r.jsx("path",{d:"M12 20h9"}),r.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})}function or(e){return r.jsxs(ve,{...e,children:[r.jsx("polyline",{points:"4 7 4 4 20 4 20 7"}),r.jsx("line",{x1:"9",y1:"20",x2:"15",y2:"20"}),r.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"})]})}function ar({pdfDoc:e,pageNumber:t,scale:n,rotation:i,pageRef:s,onRendered:o,markupTool:c="none",markupColor:l,annotations:x=[],onAddAnnotation:g,onRemoveAnnotation:M,signatures:v=[],pendingSignature:m=null,onAddSignature:P,onUpdateSignature:N,onRemoveSignature:U,onEditSignature:E,onDuplicateSignature:B,selectedSignatureId:A=null,onSelectSignature:C,signatureFields:K=[],selectedSignatureFieldId:Q=null,onSelectSignatureField:z,hasFixedSignatureFields:ne=!1,onOpenSignaturePad:_e,fieldValues:pe={},onFieldValueChange:S,onFieldValueCommit:re,pendingFieldValue:J=null,onPlaceFieldValue:D,texts:ie=[],onAddText:be,onUpdateText:je,onRemoveText:de,selectedTextId:ge=null,onSelectText:X,textFields:st=[],selectedTextFieldId:Ee=null,onSelectTextField:Ce,hasFixedTextFields:Be=!1,editingTextId:Te=null,onEditingTextIdChange:H}){const he=d.useRef(null),ue=d.useRef(null),Se=d.useRef(null),W=d.useRef(null),$e=d.useRef(null),p=d.useRef(null),[_,$]=d.useState(null),ee=d.useRef(null),q=d.useRef(!1);d.useEffect(()=>{if(!e||!ue.current||!Se.current||!W.current)return;let a=!1;const w=ue.current,y=Se.current,j=W.current,O=w.getContext("2d");return O?((async()=>{try{if($e.current){try{$e.current.cancel()}catch{}$e.current=null}if(p.current){try{p.current.cancel()}catch{}p.current=null}const R=await e.getPage(t);if(a)return;const F=R.getViewport({scale:n,rotation:i}),G=Math.floor(F.width),te=Math.floor(F.height);w.width=G,w.height=te,j.style.width=`${G}px`,j.style.height=`${te}px`;const T=R.render({canvasContext:O,viewport:F});if($e.current=T,await T.promise,a)return;y.replaceChildren(),y.style.setProperty("--scale-factor",String(F.scale));const oe=await R.getTextContent();if(a)return;const ce=new $n.TextLayer({textContentSource:oe,container:y,viewport:F});if(p.current=ce,await ce.render(),a)return;o==null||o(t)}catch{}})(),()=>{if(a=!0,$e.current){try{$e.current.cancel()}catch{}$e.current=null}if(p.current){try{p.current.cancel()}catch{}p.current=null}}):void 0},[e,t,n,i,o]),d.useEffect(()=>{const a=W.current;if(!a)return;const w=k=>{var te;if(!g)return!1;const R=k==="redact"?pt:l;if(!R)return!1;const F=Bt(a,n);if(!F)return!1;const G=k==="redact"?Ot(F.rects):F.rects;return g({id:At(),pageNumber:t,kind:k,color:R,rects:G,text:F.text}),(te=window.getSelection())==null||te.removeAllRanges(),!0},y=k=>{var oe;if(!g||!be)return!1;const R=Bt(a,n);if(!R)return!1;const F=Ot(R.rects);g({id:At(),pageNumber:t,kind:"redact",color:pt,rects:F,text:R.text});const G=kn(R.rects),te=ht(k||" ",G.fontSize),T={id:zt(),pageNumber:t,x:G.x,y:G.y,width:te.width,height:te.height,value:k,fontSize:G.fontSize,color:gt};return be(T),X==null||X(T.id),H==null||H(T.id),(oe=window.getSelection())==null||oe.removeAllRanges(),q.current=!0,window.setTimeout(()=>{q.current=!1},0),!0},j=()=>{if(c==="highlight"||c==="underline"){w(c);return}if(c==="erase"){w("redact");return}if(c==="text"){const k=window.getSelection();k&&!k.isCollapsed&&k.toString().trim()&&k.anchorNode&&a.contains(k.anchorNode)&&y(k.toString())}},O=k=>{const R=k.target;if(R!=null&&R.closest("[contenteditable='true']")||R!=null&&R.closest("[contenteditable='']")||R!=null&&R.isContentEditable)return;const F=window.getSelection(),G=F!=null&&!F.isCollapsed&&F.toString().trim().length>0&&F.anchorNode!=null&&a.contains(F.anchorNode);if(c==="text"&&G){if(k.key==="Enter"&&!k.shiftKey){k.preventDefault(),y(F.toString());return}if(k.key.length===1&&!k.ctrlKey&&!k.metaKey&&!k.altKey){k.preventDefault(),y(k.key);return}}c!=="text"&&c!=="erase"||k.key!=="Backspace"&&k.key!=="Delete"||G&&(k.preventDefault(),w("redact"))};return a.addEventListener("mouseup",j),window.addEventListener("keydown",O),()=>{a.removeEventListener("mouseup",j),window.removeEventListener("keydown",O)}},[c,l,g,be,H,X,t,n]),d.useEffect(()=>{if(!_)return;let a=0,w=0,y=0,j=0;const O=()=>{var T;return(T=he.current)==null?void 0:T.closest(".epochs-pdf-viewer__body")},k=(T,oe)=>{if(_.kind!=="resize"||!N||ne)return;const ce=v.find(ot=>ot.id===_.id);if(!ce)return;const le=W.current,ye=le?mt(le,n):{width:1/0,height:1/0},{dx:De,dy:ae}=le?Fi(T-_.startX,oe-_.startY,le,n):{dx:0,dy:0},xe=ye.width-ce.x,Ie=ye.height-ce.y,We=Math.min(xe,Math.max(40,_.startW+De)),Ue=Math.min(Ie,Math.max(20,_.startH+ae));N(_.id,{width:We,height:Ue})},R=(T,oe)=>{var Xe;if(_.kind!=="signature"||!N||ne)return;const ce=v.find(yt=>yt.id===_.id);if(!ce)return;let le=(Xe=document.elementFromPoint(T,oe))==null?void 0:Xe.closest("[data-page-number]");if(le||(le=Array.from(document.querySelectorAll(".epochs-pdf-viewer__page[data-page-number]")).find(Ze=>{const bt=Ze.getBoundingClientRect();return oe>=bt.top&&oe<=bt.bottom})??null),le||(le=he.current),!le)return;const ye=le.querySelector(".epochs-pdf-viewer__surface");if(!ye)return;const De=Number.parseInt(le.getAttribute("data-page-number")||String(ce.pageNumber),10),ae=jt(T,oe,ye,n),xe=mt(ye,n);let Ie=ae.x-_.offsetX,We=ae.y-_.offsetY;const Ue=Math.max(0,xe.width-ce.width),ot=Math.max(0,xe.height-ce.height);Ie=Math.min(Math.max(0,Ie),Ue),We=Math.min(Math.max(0,We),ot),N(_.id,{pageNumber:De,x:Ie,y:We})},F=()=>{if(a=0,!j)return;const T=O();if(!T)return;const oe=T.scrollHeight-T.clientHeight;if(oe<=0)return;const ce=56,le=T.getBoundingClientRect(),ye=y-le.top,De=le.bottom-y;let ae=0;if(j<0&&ye<ce)ae=-Math.max(6,(ce-ye)/ce*28);else if(j>0&&De<ce)ae=Math.max(6,(ce-De)/ce*28);else{j=0;return}const xe=T.scrollTop;T.scrollTop=Math.min(oe,Math.max(0,xe+ae)),T.scrollTop!==xe&&R(w,y),ae<0&&T.scrollTop>0||ae>0&&T.scrollTop<oe?a=window.requestAnimationFrame(F):j=0},G=T=>{w=T.clientX,y=T.clientY;const oe=O();if(oe){const le=oe.getBoundingClientRect(),ye=T.clientY-le.top,De=le.bottom-T.clientY;ye<56?(j=-1,a||(a=window.requestAnimationFrame(F))):De<56?(j=1,a||(a=window.requestAnimationFrame(F))):j=0}_.kind==="resize"?k(T.clientX,T.clientY):R(T.clientX,T.clientY)},te=()=>{j=0,a&&(window.cancelAnimationFrame(a),a=0),$(null)};return window.addEventListener("pointermove",G),window.addEventListener("pointerup",te),window.addEventListener("pointercancel",te),()=>{j=0,a&&window.cancelAnimationFrame(a),window.removeEventListener("pointermove",G),window.removeEventListener("pointerup",te),window.removeEventListener("pointercancel",te)}},[_,ne,N,n,v]),d.useEffect(()=>{if(!Te||!ee.current)return;const a=ee.current,w=ie.find(O=>O.id===Te);a.textContent=(w==null?void 0:w.value)??"",a.focus();const y=document.createRange();y.selectNodeContents(a),y.collapse(!1);const j=window.getSelection();j==null||j.removeAllRanges(),j==null||j.addRange(y)},[Te]);const me=a=>{he.current=a,s==null||s(a)},se=x.filter(a=>a.pageNumber===t),ke=v.filter(a=>a.pageNumber===t),we=K.filter(a=>a.pageNumber===t),Fe=ie.filter(a=>a.pageNumber===t),ze=(a,w)=>{const y=w.trim();if(!y){de==null||de(a.id),H==null||H(null);return}const j=ht(y,a.fontSize);je==null||je(a.id,{value:y,width:j.width,height:j.height}),H==null||H(null)},Oe=(a,w)=>{if(!be)return;const y=W.current,j=Se.current;if(!y||!j)return;let O=Ei(a,w,y,j,n),k,R=gt;if(Be){const te=Ui(O.x,O.y,st,t);if(!te)return;const T=ie.find(oe=>oe.fieldId===te.id);if(T){X==null||X(T.id),Ce==null||Ce(te.id),H==null||H(T.id);return}k=te.id,O={x:te.x,y:te.y,fontSize:te.fontSize??wt},R=te.color??gt,Ce==null||Ce(te.id)}const F=ht("",O.fontSize),G={id:zt(),fieldId:k,pageNumber:t,x:O.x,y:O.y,width:F.width,height:F.height,value:"",fontSize:O.fontSize,color:R};be(G),X==null||X(G.id),H==null||H(G.id)},Re=a=>{var y;if(c!=="text"||a.target.closest(".epochs-pdf-viewer__inline-text"))return;if(q.current){q.current=!1;return}const w=window.getSelection();if(!(w&&!w.isCollapsed&&w.toString().trim())){if(a.detail>=2&&zi(a.clientX,a.clientY,Se.current)){const O=W.current;if(O&&g&&be){const k=Bt(O,n);if(k){g({id:At(),pageNumber:t,kind:"redact",color:pt,rects:Ot(k.rects),text:k.text});const R=kn(k.rects),F=ht(k.text||" ",R.fontSize),G={id:zt(),pageNumber:t,x:R.x,y:R.y,width:F.width,height:F.height,value:k.text,fontSize:R.fontSize,color:gt};be(G),X==null||X(G.id),H==null||H(G.id),(y=window.getSelection())==null||y.removeAllRanges(),q.current=!0}}return}a.stopPropagation(),Oe(a.clientX,a.clientY)}},He=a=>{const w=a.target;if(!(w.closest(".epochs-pdf-viewer__signature")||w.closest(".epochs-pdf-viewer__signature-field")||w.closest(".epochs-pdf-viewer__inline-text"))){if(c==="text"){Oe(a.clientX,a.clientY);return}if(!ne&&c==="sign"&&J&&D){const y=W.current;if(!y)return;const j=jt(a.clientX,a.clientY,y,n);D(t,Math.max(0,j.x-75),Math.max(0,j.y-12));return}if(!ne&&c==="sign"&&m&&P){const y=W.current;if(!y)return;const j=mt(y,n),O=jt(a.clientX,a.clientY,y,n);let k=O.x-m.width/2,R=O.y-m.height/2;const F=Math.max(0,j.width-m.width),G=Math.max(0,j.height-m.height);k=Math.min(Math.max(0,k),F),R=Math.min(Math.max(0,R),G),P({id:Pt(),pageNumber:t,x:k,y:R,width:m.width,height:m.height,imageDataUrl:m.imageDataUrl});return}}},Tt=a=>Te===a.id?r.jsx("span",{ref:ee,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox","aria-label":"Edit text",className:"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--editing",style:{left:a.x*n,top:a.y*n,fontSize:a.fontSize*n,color:a.color,minWidth:Math.max(12,a.fontSize*n*.5),width:Math.max(a.width*n,a.fontSize*n*.5)},onClick:y=>y.stopPropagation(),onPointerDown:y=>y.stopPropagation(),onInput:y=>{const j=y.currentTarget.textContent??"",O=ht(j||" ",a.fontSize);je==null||je(a.id,{value:j,width:O.width,height:O.height})},onBlur:y=>{ze(a,y.currentTarget.textContent??"")},onKeyDown:y=>{y.stopPropagation(),y.key==="Escape"&&(y.preventDefault(),y.currentTarget.blur()),y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),y.currentTarget.blur())}},a.id):a.value.trim()?r.jsx("span",{className:ge===a.id?"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--selected":"epochs-pdf-viewer__inline-text",style:{left:a.x*n,top:a.y*n,fontSize:a.fontSize*n,color:a.color},onClick:y=>{if(y.stopPropagation(),c==="erase"){de==null||de(a.id);return}c==="text"&&(X==null||X(a.id),H==null||H(a.id))},children:a.value},a.id):null;return r.jsx("div",{ref:me,"data-page-number":t,className:"epochs-pdf-viewer__page",children:r.jsxs("div",{ref:W,className:`epochs-pdf-viewer__surface epochs-pdf-viewer__surface--tool-${c}`,onClick:He,children:[r.jsx("canvas",{ref:ue,className:"epochs-pdf-viewer__canvas"}),r.jsx("div",{className:"epochs-pdf-viewer__markup-layer","aria-hidden":"true",children:se.map(a=>a.kind==="redact"?null:a.rects.map((w,y)=>a.kind==="highlight"?r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--highlight",style:{left:w.x*n,top:w.y*n,width:w.w*n,height:w.h*n,background:a.color},onClick:j=>{c==="erase"&&(j.stopPropagation(),M==null||M(a.id))}},`${a.id}_${y}`):r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--underline",style:{left:w.x*n,top:(w.y+w.h)*n-Math.max(2,n*1.5),width:w.w*n,height:Math.max(2,n*1.5),background:a.color},onClick:j=>{c==="erase"&&(j.stopPropagation(),M==null||M(a.id))}},`${a.id}_${y}`)))}),r.jsxs("div",{className:"epochs-pdf-viewer__signature-layer",children:[we.map(a=>{const w=ke.some(y=>y.fieldId===a.id);return r.jsx("button",{type:"button","data-signature-field-id":a.id,className:Q===a.id?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--selected":w?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--filled":"epochs-pdf-viewer__signature-field",style:{left:a.x*n,top:a.y*n,width:a.width*n,height:a.height*n},onClick:y=>{y.stopPropagation();const j=a.type;if(j==="date"||j==="text")return;z==null||z(a.id);const O=ke.find(k=>k.fieldId===a.id);C==null||C((O==null?void 0:O.id)??null),O?E==null||E(O.id):_e==null||_e(a.type)},title:w?"Signed field":"Signature field",children:(()=>{const y=a.type;return y==="date"?r.jsx("input",{type:"date",className:"epochs-pdf-viewer__signature-field-input",value:pe[a.id]??"",onClick:j=>j.stopPropagation(),onChange:j=>{j.stopPropagation(),S==null||S(a.id,j.target.value),re==null||re(a.id)},style:{width:"100%",height:"100%"}}):y==="text"?r.jsx("input",{type:"text",className:"epochs-pdf-viewer__signature-field-input",value:pe[a.id]??"",placeholder:a.placeholder??"Enter text",onClick:j=>j.stopPropagation(),onChange:j=>{j.stopPropagation(),S==null||S(a.id,j.target.value)},onBlur:()=>re==null?void 0:re(a.id),style:{width:"100%",height:"100%"}}):w?null:r.jsx("span",{children:"Sign here"})})()},a.id)}),ke.map(a=>r.jsxs("div",{className:A===a.id?"epochs-pdf-viewer__signature epochs-pdf-viewer__signature--selected":"epochs-pdf-viewer__signature",style:{left:a.x*n,top:a.y*n,width:a.width*n,height:a.height*n},onPointerDown:w=>{if(w.stopPropagation(),w.preventDefault(),C==null||C(a.id),c==="erase"&&!ne){U==null||U(a.id);return}if(ne){z==null||z(a.fieldId??null),E==null||E(a.id);return}const y=W.current;if(!y)return;const j=jt(w.clientX,w.clientY,y,n);$({kind:"signature",id:a.id,offsetX:j.x-a.x,offsetY:j.y-a.y})},children:[r.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-edit",title:"Edit signature","aria-label":"Edit signature",onPointerDown:w=>{w.stopPropagation()},onClick:w=>{w.stopPropagation(),C==null||C(a.id),E==null||E(a.id)},children:r.jsx(sr,{size:12})}),ne?null:r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-duplicate",title:"Duplicate signature","aria-label":"Duplicate signature",onPointerDown:w=>{w.stopPropagation()},onClick:w=>{w.stopPropagation(),C==null||C(a.id),B==null||B(a.id)},children:"⧉"}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-remove",title:"Remove signature","aria-label":"Remove signature",onPointerDown:w=>{w.stopPropagation()},onClick:w=>{w.stopPropagation(),U==null||U(a.id)},children:"×"})]}),r.jsx("img",{src:a.imageDataUrl,alt:"Signature",draggable:!1}),ne?null:r.jsx("div",{className:"epochs-pdf-viewer__signature-resize",title:"Resize",onPointerDown:w=>{w.stopPropagation(),w.preventDefault(),C==null||C(a.id),$({kind:"resize",id:a.id,startX:w.clientX,startY:w.clientY,startW:a.width,startH:a.height})},children:r.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:r.jsx("path",{d:"M7 1L1 7M7 4L4 7",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round"})})})]},a.id))]}),r.jsx("div",{className:"epochs-pdf-viewer__text-layer-overlay",children:Fe.map(a=>Tt(a))}),r.jsx("div",{ref:Se,className:"textLayer epochs-pdf-viewer__text-layer",onClick:Re}),r.jsx("div",{className:"epochs-pdf-viewer__redact-layer","aria-hidden":"true",children:se.map(a=>a.kind==="redact"?a.rects.map((w,y)=>r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--redact",style:{left:w.x*n,top:w.y*n,width:w.w*n,height:w.h*n,background:a.color||pt},onClick:j=>{c==="erase"&&(j.stopPropagation(),M==null||M(a.id))}},`${a.id}_${y}`)):null)})]})})}function cr({pdfDoc:e,pageNumber:t,isActive:n,rotation:i,onSelect:s,width:o=140,annotations:c=[],signatures:l=[],signatureFields:x=[],texts:g=[],textFields:M=[]}){const v=d.useRef(null);return d.useEffect(()=>{if(!e||!v.current)return;let m=!1;const P=v.current,N=P.getContext("2d");if(!N)return;let U=null;return(async()=>{try{const B=await e.getPage(t);if(m)return;const A=B.getViewport({scale:1,rotation:i}),C=o/A.width,K=B.getViewport({scale:C,rotation:i});P.width=Math.floor(K.width),P.height=Math.floor(K.height),U=B.render({canvasContext:N,viewport:K}),await U.promise;const Q=c.filter(S=>S.pageNumber===t);Q.length>0&&In(N,Q,C);const z=l.filter(S=>S.pageNumber===t),ne=x.filter(S=>S.pageNumber===t);ne.length>0&&Ii(N,ne,new Set(z.map(S=>S.fieldId).filter(Boolean)),C),z.length>0&&await Ln(N,z,C);const _e=g.filter(S=>S.pageNumber===t),pe=M.filter(S=>S.pageNumber===t);pe.length>0&&Wi(N,pe,new Set(_e.filter(S=>S.fieldId&&S.value.trim()).map(S=>S.fieldId)),C),_e.length>0&&Sn(N,_e,C)}catch{}})(),()=>{if(m=!0,U)try{U.cancel()}catch{}}},[c,e,t,i,x,l,M,g,o]),r.jsxs("button",{type:"button",onClick:()=>s(t),className:n?"epochs-pdf-viewer__thumb epochs-pdf-viewer__thumb--active":"epochs-pdf-viewer__thumb",title:`Page ${t}`,children:[r.jsx("div",{className:"epochs-pdf-viewer__thumb-frame",children:r.jsx("canvas",{ref:v})}),r.jsx("span",{className:"epochs-pdf-viewer__thumb-label",children:t})]})}const lr=/^(blob:|https?:|data:)/i;let Fn=!1;function Gt(e){rt.GlobalWorkerOptions.workerSrc=e,Fn=!0}function dr(e){if(e){Gt(e);return}Fn||rt.GlobalWorkerOptions.workerSrc||Gt(`https://unpkg.com/pdfjs-dist@${rt.version}/build/pdf.worker.min.mjs`)}function hr(e,t,n=""){const i=t||e;if(!i)return"";if(lr.test(i))return i;const s=i.startsWith("/")?i:`/${i}`;return n?`${n.replace(/\/$/,"")}${s}`:s}async function ur(e,t){const n=await fetch(e,t);if(!n.ok)throw new Error(`Failed to fetch PDF (${n.status})`);return n.arrayBuffer()}async function Mn(e,t){if(typeof e=="string")return ur(e,t);if(e instanceof ArrayBuffer)return e.slice(0);if(e instanceof Uint8Array){const n=new Uint8Array(e.byteLength);return n.set(e),n.buffer}return e.arrayBuffer()}async function fr(e,t,n){const{scale:i,rotation:s,annotations:o,signatures:c=[],texts:l=[],mimeType:x="image/jpeg",quality:g=.92}=n,M=await e.getPage(t),v=M.getViewport({scale:i,rotation:s}),m=M.getViewport({scale:1,rotation:s}),P=document.createElement("canvas"),N=P.getContext("2d",{alpha:!1});if(!N)throw new Error("Could not create canvas context");const U=Math.floor(v.width),E=Math.floor(v.height);P.width=U,P.height=E,N.fillStyle="#ffffff",N.fillRect(0,0,U,E),await M.render({canvasContext:N,viewport:v}).promise;const B=o.filter(z=>z.pageNumber===t);B.length>0&&In(N,B,i);const A=c.filter(z=>z.pageNumber===t);A.length>0&&await Ln(N,A,i);const C=l.filter(z=>z.pageNumber===t);C.length>0&&Sn(N,C,i);const K=P.toDataURL(x,g),Q=pr(K);return P.width=0,P.height=0,{pageNumber:t,width:U,height:E,pageWidth:m.width,pageHeight:m.height,dataUrl:K,jpegBytes:Q}}async function Pn(e,t){const n=[];for(let i=1;i<=e.numPages;i+=1)n.push(await fr(e,i,t));return n}function pr(e){const t=e.split(",")[1]??"",n=atob(t),i=new Uint8Array(n.length);for(let s=0;s<n.length;s+=1)i[s]=n.charCodeAt(s);return i}function Ae(e){return new TextEncoder().encode(e)}function Nn(...e){const t=e.reduce((s,o)=>s+o.byteLength,0),n=new Uint8Array(t);let i=0;for(const s of e)n.set(s,i),i+=s.byteLength;return n}function gr(e){const t=[],n=m=>(t.push(m),t.length),i=[];for(const m of e){const P=Nn(Ae(`<< /Type /XObject /Subtype /Image /Width ${m.width} /Height ${m.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${m.jpegBytes.byteLength} >>
1
+ "use strict";var Wi=Object.defineProperty;var Gi=(t,e,n)=>e in t?Wi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ve=(t,e,n)=>Gi(t,typeof e!="symbol"?e+"":e,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react"),s=require("react/jsx-runtime"),Wn=require("pdfjs-dist");function Xi(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const me=Xi(Wn),Ne="#ffffff",sn=[{id:"yellow",label:"Yellow",hex:"#facc15"},{id:"green",label:"Green",hex:"#4ade80"},{id:"pink",label:"Pink",hex:"#f472b6"},{id:"blue",label:"Blue",hex:"#60a5fa"},{id:"orange",label:"Orange",hex:"#fb923c"},{id:"purple",label:"Purple",hex:"#c084fc"}],rn=[{id:"blue",label:"Blue",hex:"#2563eb"},{id:"red",label:"Red",hex:"#dc2626"},{id:"green",label:"Green",hex:"#16a34a"},{id:"orange",label:"Orange",hex:"#ea580c"},{id:"purple",label:"Purple",hex:"#7c3aed"},{id:"black",label:"Black",hex:"#111827"}],Gn=sn[0].hex,Vi=rn[0].hex;on(Gn,"highlight");function qe(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function ee(t){const e=t.trim();if(/^#[0-9a-fA-F]{6}$/.test(e))return e.toLowerCase();if(/^#[0-9a-fA-F]{3}$/.test(e)){const n=e[1],i=e[2],r=e[3];return`#${n}${n}${i}${i}${r}${r}`.toLowerCase()}return e}function on(t,e,n=.45){const i=ee(t);if(e==="underline"||e==="redact")return i;const r=/^#([0-9a-f]{6})$/i.exec(i);if(!r)return`rgba(250, 204, 21, ${n})`;const o=Number.parseInt(r[1],16),d=o>>16&255,u=o>>8&255,w=o&255;return`rgba(${d}, ${u}, ${w}, ${n})`}function Ye(t,e){const n=window.getSelection();if(!n||n.isCollapsed||n.rangeCount===0)return null;const i=n.getRangeAt(0);if(!t.contains(i.commonAncestorContainer))return null;const r=t.getBoundingClientRect(),o=Array.from(i.getClientRects()).filter(_=>_.width>0&&_.height>0);if(!o.length)return null;const d=e||1,u=t.clientWidth||r.width,w=t.clientHeight||r.height;return{rects:o.map(_=>({x:r.width>0?(_.left-r.left)/r.width*(u/d):0,y:r.height>0?(_.top-r.top)/r.height*(w/d):0,w:r.width>0?_.width/r.width*(u/d):0,h:r.height>0?_.height/r.height*(w/d):0})),text:n.toString()}}function Sn(t){const n=[...t].sort((i,r)=>i.y-r.y||i.x-r.x)[0]??{x:0,y:0,h:14};return{x:n.x,y:n.y,fontSize:Math.max(8,Math.round(n.h*.9)||14)}}function Ke(t,e=2){return t.map(n=>({x:Math.max(0,n.x-e),y:Math.max(0,n.y-e),w:n.w+e*2,h:n.h+e*2}))}function Xn(t,e,n){for(const i of e)for(const r of i.rects){const o=r.x*n,d=r.y*n,u=r.w*n,w=r.h*n;if(i.kind==="highlight")t.save(),t.globalCompositeOperation="multiply",t.fillStyle=i.color,t.fillRect(o,d,u,w),t.restore();else if(i.kind==="redact")t.fillStyle=i.color||Ne,t.fillRect(o,d,u,w);else{const m=Math.max(2,n*1.5);t.fillStyle=i.color,t.fillRect(o,d+w-m,u,m)}}}function Fe(){return`s_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}async function Vn(t,e,n){for(const i of e){const r=await Yi(i.imageDataUrl);t.drawImage(r,i.x*n,i.y*n,i.width*n,i.height*n)}}function qi(t,e,n,i){t.save();for(const r of e){const o=n.has(r.id),d=r.x*i,u=r.y*i,w=r.width*i,m=r.height*i;t.fillStyle=o?"rgba(29, 78, 216, 0.08)":"rgba(29, 78, 216, 0.18)",t.strokeStyle=o?"rgba(29, 78, 216, 0.45)":"#1d4ed8",t.lineWidth=1.5,t.setLineDash(o?[]:[4,3]),t.fillRect(d,u,w,m),t.strokeRect(d,u,w,m)}t.restore()}function Yi(t){return new Promise((e,n)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>n(new Error("Failed to load signature image")),i.src=t})}function Ki(t,e,n=180,i=64){if(t<=0||e<=0)return{width:n,height:i};const r=Math.min(n/t,i/e);return{width:Math.max(40,t*r),height:Math.max(20,e*r)}}function Re(t,e,n,i){const r=n.getBoundingClientRect(),o=n.clientWidth||r.width,d=n.clientHeight||r.height;return r.width<=0||r.height<=0||i<=0?{x:0,y:0}:{x:(t-r.left)/r.width*(o/i),y:(e-r.top)/r.height*(d/i)}}function we(t,e){return{width:t.clientWidth/e,height:t.clientHeight/e}}function Zi(t,e,n,i){const r=n.getBoundingClientRect(),o=n.clientWidth||r.width,d=n.clientHeight||r.height;return r.width<=0||r.height<=0||i<=0?{dx:0,dy:0}:{dx:t/r.width*(o/i),dy:e/r.height*(d/i)}}function En(t,e,n){const i=e.getBoundingClientRect(),{width:r,height:o}=we(e,n);return i.width<=0||i.height<=0?{left:0,top:0,right:r,bottom:o}:{left:(t.left-i.left)/i.width*r,top:(t.top-i.top)/i.height*o,right:(t.right-i.left)/i.width*r,bottom:(t.bottom-i.top)/i.height*o}}const ae=14,oe="#111827",Ze=24,Qe=20;function Se(){return`t_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function je(t,e){if(typeof document>"u")return{width:Math.max(Ze,t.length*e*.55),height:Math.max(Qe,e*1.25)};const i=document.createElement("canvas").getContext("2d");if(!i)return{width:Math.max(Ze,t.length*e*.55),height:Math.max(Qe,e*1.25)};i.font=`${e}px sans-serif`;const r=t.split(`
2
+ `),o=e*1.25;let d=Ze;for(const u of r)d=Math.max(d,i.measureText(u||" ").width+4);return{width:d,height:Math.max(Qe,r.length*o)}}function Qi(t,e,n,i,r){var Z;const o=n.getBoundingClientRect(),d=n.clientWidth||o.width,u=n.clientHeight||o.height,w=T=>o.width>0?(T-o.left)/o.width*(d/r):0,m=T=>o.height>0?(T-o.top)/o.height*(u/r):0,_=(T,rt)=>{const ot=rt==="x"?o.width:o.height,Y=rt==="x"?d:u;return ot>0?T/ot*(Y/r):0};let y=w(t),b=m(e),k=ae;const C=Ji(t,e,i);if(C)return{x:w(C.x),y:m(C.y),fontSize:Math.max(8,Math.round(_(C.fontSize,"y")*10)/10)};const H=document,A=(Z=H.caretRangeFromPoint)==null?void 0:Z.call(H,t,e);if(A&&i.contains(A.startContainer)){const T=A.getClientRects(),rt=T.length>0?T[0]:A.getBoundingClientRect();if(rt.height>0){b=m(rt.top),k=es(A.startContainer,r,n);const ot=w(rt.left);return Math.abs(ot-y)<_(8,"x")&&(y=ot),{x:y,y:b,fontSize:k}}}const L=ts(t,e,i);return L&&(b=m(L.top),k=Math.max(8,Math.round(_(L.height,"y")*10)/10)),{x:y,y:b,fontSize:k}}function Ji(t,e,n){var o;const i=Array.from(n.querySelectorAll("span"));if(i.length<2)return null;const r=[];for(const d of i){if(!((o=d.textContent)!=null&&o.trim()))continue;const u=d.getBoundingClientRect();u.width<=0||u.height<=0||e<u.top-4||e>u.bottom+4||r.push({left:u.left,right:u.right,top:u.top,bottom:u.bottom,height:u.height})}r.sort((d,u)=>d.left-u.left);for(let d=0;d<r.length-1;d+=1){const u=r[d],w=r[d+1],m=u.right,_=w.left;if(!(_-m<1)&&t>=m-2&&t<=_+2)return{x:t,y:Math.min(u.top,w.top),fontSize:Math.min(u.height,w.height)}}return null}function ts(t,e,n){var o;const i=Array.from(n.querySelectorAll("span"));let r=null;for(const d of i){if(!((o=d.textContent)!=null&&o.trim()))continue;const u=d.getBoundingClientRect();if(u.width<=0||u.height<=0||e<u.top-6||e>u.bottom+6)continue;const w=(u.left+u.right)/2,m=Math.abs(t-w);(!r||m<r.dist)&&(r={top:u.top,height:u.height,dist:m})}return r?{top:r.top,height:r.height}:null}function es(t,e,n){const i=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;return i?ns(i,e,n):ae}function ns(t,e,n){const i=t.getBoundingClientRect().height;if(i>0){if(n){const d=n.getBoundingClientRect(),u=n.clientHeight||d.height;if(d.height>0)return Math.max(8,Math.round(i/d.height*(u/e)*10)/10)}return Math.max(8,Math.round(i/e*10)/10)}const r=window.getComputedStyle(t).fontSize,o=Number.parseFloat(r);return Number.isFinite(o)&&o>0?Math.max(8,Math.round(o/e*10)/10):ae}function is(t,e,n,i){for(const r of n)if(r.pageNumber===i&&t>=r.x&&t<=r.x+r.width&&e>=r.y&&e<=r.y+r.height)return r;return null}function ss(t,e,n){var k;if(!n)return null;const i=document,r=(k=i.caretRangeFromPoint)==null?void 0:k.call(i,t,e);if(!r||!n.contains(r.startContainer))return null;const o=r.startContainer;if(o.nodeType!==Node.TEXT_NODE||!o.textContent)return null;const d=o.textContent;let u=r.startOffset;u=Math.min(Math.max(0,u),d.length);const w=C=>/[\p{L}\p{N}_'-]/u.test(C);let m=u,_=u;for(;m>0&&w(d[m-1]);)m-=1;for(;_<d.length&&w(d[_]);)_+=1;if(m===_)return null;const y=document.createRange();y.setStart(o,m),y.setEnd(o,_);const b=window.getSelection();return b==null||b.removeAllRanges(),b==null||b.addRange(y),d.slice(m,_)}function qn(t,e,n){t.save();for(const i of e){if(!i.value.trim())continue;const r=i.x*n,o=i.y*n,d=Math.max(8,i.fontSize*n);t.fillStyle=i.color,t.font=`${d}px sans-serif`,t.textBaseline="top";const u=d*1.25,w=i.value.split(`
3
+ `);let m=o;for(const _ of w)t.fillText(_,r,m),m+=u}t.restore()}function rs(t,e,n,i){t.save();for(const r of e){const o=n.has(r.id),d=r.x*i,u=r.y*i,w=r.width*i,m=r.height*i;t.fillStyle=o?"rgba(5, 150, 105, 0.08)":"rgba(5, 150, 105, 0.16)",t.strokeStyle=o?"rgba(5, 150, 105, 0.45)":"#059669",t.lineWidth=1.5,t.setLineDash(o?[]:[4,3]),t.fillRect(d,u,w,m),t.strokeRect(d,u,w,m)}t.restore()}function Lt({size:t=14,className:e,children:n}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:n})}function os(t){return s.jsx(Lt,{...t,children:s.jsx("polyline",{points:"15 18 9 12 15 6"})})}function as(t){return s.jsx(Lt,{...t,children:s.jsx("polyline",{points:"9 18 15 12 9 6"})})}function cs(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),s.jsx("polyline",{points:"7 10 12 15 17 10"}),s.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function ls(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),s.jsx("polyline",{points:"15 3 21 3 21 9"}),s.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}function ds(t){return s.jsxs(Lt,{...t,children:[s.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),s.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),s.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),s.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}function hs(t){return s.jsx(Lt,{...t,children:s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(t){return s.jsxs(Lt,{...t,children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function fs(t){return s.jsxs(Lt,{...t,children:[s.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),s.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),s.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})}function ps(t){return s.jsxs(Lt,{...t,children:[s.jsx("polyline",{points:"23 4 23 10 17 10"}),s.jsx("polyline",{points:"1 20 1 14 7 14"}),s.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})}function gs(t){return s.jsxs(Lt,{...t,children:[s.jsx("polyline",{points:"23 4 23 10 17 10"}),s.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function ms(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"M12 20h9"}),s.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})}function ws(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),s.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function xs(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"}),s.jsx("path",{d:"M22 21H7"}),s.jsx("path",{d:"m5 11 9 9"})]})}function bs({size:t=16,className:e}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 256 256",fill:"currentColor",stroke:"currentColor",strokeWidth:"12",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:s.jsx("path",{d:"M232,172H57.32c4-7.83,8.18-16.11,12.21-24.56,15.14,3.55,34.13-8.06,56.54-34.59,3.67,12.5,12.53,34.83,29.08,35.15h.35c8.71,0,17.64-6.25,27.16-19.06C187.17,137.14,199.31,148,232,148a4,4,0,0,0,0-8c-42.88,0-44-19.24-44-20a4,4,0,0,0-7.35-2.18C168.74,136.1,160.42,140,155.48,140h-.18c-13-.25-21.29-26.52-23.38-36.61a4,4,0,0,0-7-1.69c-20.94,26.27-39.06,39.55-51.8,38.2C97.31,87.5,105.19,53.16,96.49,37.77,94,33.31,88.7,28,77.91,28,64.09,28,52.54,42.41,47,66.54A122.7,122.7,0,0,0,45.46,113c2.64,15.29,8.39,26.05,16.69,31.35-4.58,9.6-9.3,19-13.84,27.68H24a4,4,0,0,0,0,8H44.1c-12.87,24.17-23.37,41.68-23.53,41.94a4,4,0,0,0,1.37,5.49A3.93,3.93,0,0,0,24,228a4,4,0,0,0,3.43-1.94c.16-.27,11.85-19.75,25.72-46.06H232a4,4,0,0,0,0-8ZM53.34,111.61a114.81,114.81,0,0,1,1.49-43.29C58.4,52.7,66.34,36,77.91,36c7.52,0,10.23,3.26,11.61,5.7C99,58.4,79.92,106,65.6,137,59.76,132.69,55.46,123.83,53.34,111.61Z"})})}function ys(t){return s.jsxs(Lt,{...t,children:[s.jsx("path",{d:"M12 20h9"}),s.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})}function _s(t){return s.jsxs(Lt,{...t,children:[s.jsx("polyline",{points:"4 7 4 4 20 4 20 7"}),s.jsx("line",{x1:"9",y1:"20",x2:"15",y2:"20"}),s.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"})]})}function vs({pdfDoc:t,pageNumber:e,scale:n,rotation:i,pageRef:r,onRendered:o,markupTool:d="none",markupColor:u,annotations:w=[],onAddAnnotation:m,onRemoveAnnotation:_,signatures:y=[],pendingSignature:b=null,onAddSignature:k,onUpdateSignature:C,onRemoveSignature:H,onEditSignature:A,onDuplicateSignature:L,selectedSignatureId:Z=null,onSelectSignature:T,signatureFields:rt=[],selectedSignatureFieldId:ot=null,onSelectSignatureField:Y,hasFixedSignatureFields:Q=!1,onOpenSignaturePad:wt,fieldValues:yt={},onFieldValueChange:q,onFieldValueCommit:Pt,pendingFieldValue:ft=null,onPlaceFieldValue:U,texts:tt=[],onAddText:et,onUpdateText:bt,onRemoveText:V,selectedTextId:Vt=null,onSelectText:dt,textFields:qt=[],selectedTextFieldId:Ce=null,onSelectTextField:At,hasFixedTextFields:Gt=!1,editingTextId:Ct=null,onEditingTextIdChange:z}){const jt=f.useRef(null),$t=f.useRef(null),pt=f.useRef(null),at=f.useRef(null),Dt=f.useRef(null),nt=f.useRef(null),[gt,kt]=f.useState(null),Yt=f.useRef(null),ht=f.useRef(!1);f.useEffect(()=>{if(!t||!$t.current||!pt.current||!at.current)return;let a=!1;const x=$t.current,v=pt.current,j=at.current,D=x.getContext("2d");return D?((async()=>{try{if(Dt.current){try{Dt.current.cancel()}catch{}Dt.current=null}if(nt.current){try{nt.current.cancel()}catch{}nt.current=null}const F=await t.getPage(e);if(a)return;const N=F.getViewport({scale:n,rotation:i}),S=Math.floor(N.width),B=Math.floor(N.height);x.width=S,x.height=B,j.style.width=`${S}px`,j.style.height=`${B}px`;const R=F.render({canvasContext:D,viewport:N});if(Dt.current=R,await R.promise,a)return;v.replaceChildren(),v.style.setProperty("--scale-factor",String(N.scale));const it=await F.getTextContent();if(a)return;const W=new Wn.TextLayer({textContentSource:it,container:v,viewport:N});if(nt.current=W,await W.render(),a)return;o==null||o(e)}catch{}})(),()=>{if(a=!0,Dt.current){try{Dt.current.cancel()}catch{}Dt.current=null}if(nt.current){try{nt.current.cancel()}catch{}nt.current=null}}):void 0},[t,e,n,i,o]),f.useEffect(()=>{const a=at.current;if(!a)return;const x=P=>{var B;if(!m)return!1;const F=P==="redact"?Ne:u;if(!F)return!1;const N=Ye(a,n);if(!N)return!1;const S=P==="redact"?Ke(N.rects):N.rects;return m({id:qe(),pageNumber:e,kind:P,color:F,rects:S,text:N.text}),(B=window.getSelection())==null||B.removeAllRanges(),!0},v=P=>{var it;if(!m||!et)return!1;const F=Ye(a,n);if(!F)return!1;const N=Ke(F.rects);m({id:qe(),pageNumber:e,kind:"redact",color:Ne,rects:N,text:F.text});const S=Sn(F.rects),B=je(P||" ",S.fontSize),R={id:Se(),pageNumber:e,x:S.x,y:S.y,width:B.width,height:B.height,value:P,fontSize:S.fontSize,color:oe};return et(R),dt==null||dt(R.id),z==null||z(R.id),(it=window.getSelection())==null||it.removeAllRanges(),ht.current=!0,window.setTimeout(()=>{ht.current=!1},0),!0},j=()=>{if(d==="highlight"||d==="underline"){x(d);return}if(d==="erase"){x("redact");return}if(d==="text"){const P=window.getSelection();P&&!P.isCollapsed&&P.toString().trim()&&P.anchorNode&&a.contains(P.anchorNode)&&v(P.toString())}},D=P=>{const F=P.target;if(F!=null&&F.closest("[contenteditable='true']")||F!=null&&F.closest("[contenteditable='']")||F!=null&&F.isContentEditable)return;const N=window.getSelection(),S=N!=null&&!N.isCollapsed&&N.toString().trim().length>0&&N.anchorNode!=null&&a.contains(N.anchorNode);if(d==="text"&&S){if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),v(N.toString());return}if(P.key.length===1&&!P.ctrlKey&&!P.metaKey&&!P.altKey){P.preventDefault(),v(P.key);return}}d!=="text"&&d!=="erase"||P.key!=="Backspace"&&P.key!=="Delete"||S&&(P.preventDefault(),x("redact"))};return a.addEventListener("mouseup",j),window.addEventListener("keydown",D),()=>{a.removeEventListener("mouseup",j),window.removeEventListener("keydown",D)}},[d,u,m,et,z,dt,e,n]),f.useEffect(()=>{if(!gt)return;let a=0,x=0,v=0,j=0;const D=()=>{var R;return(R=jt.current)==null?void 0:R.closest(".epochs-pdf-viewer__body")},P=(R,it)=>{if(gt.kind!=="resize"||!C||Q)return;const W=y.find(ut=>ut.id===gt.id);if(!W)return;const ct=at.current,xt=ct?we(ct,n):{width:1/0,height:1/0},{dx:It,dy:Ft}=ct?Zi(R-gt.startX,it-gt.startY,ct,n):{dx:0,dy:0},Wt=xt.width-W.x,Tt=xt.height-W.y,Ut=Math.min(Wt,Math.max(40,gt.startW+It)),lt=Math.min(Tt,Math.max(20,gt.startH+Ft));C(gt.id,{width:Ut,height:lt})},F=(R,it)=>{var Kt;if(gt.kind!=="signature"||!C||Q)return;const W=y.find(ce=>ce.id===gt.id);if(!W)return;let ct=(Kt=document.elementFromPoint(R,it))==null?void 0:Kt.closest("[data-page-number]");if(ct||(ct=Array.from(document.querySelectorAll(".epochs-pdf-viewer__page[data-page-number]")).find(Zt=>{const $e=Zt.getBoundingClientRect();return it>=$e.top&&it<=$e.bottom})??null),ct||(ct=jt.current),!ct)return;const xt=ct.querySelector(".epochs-pdf-viewer__surface");if(!xt)return;const It=Number.parseInt(ct.getAttribute("data-page-number")||String(W.pageNumber),10),Ft=Re(R,it,xt,n),Wt=we(xt,n);let Tt=Ft.x-gt.offsetX,Ut=Ft.y-gt.offsetY;const lt=Math.max(0,Wt.width-W.width),ut=Math.max(0,Wt.height-W.height);Tt=Math.min(Math.max(0,Tt),lt),Ut=Math.min(Math.max(0,Ut),ut),C(gt.id,{pageNumber:It,x:Tt,y:Ut})},N=()=>{if(a=0,!j)return;const R=D();if(!R)return;const it=R.scrollHeight-R.clientHeight;if(it<=0)return;const W=56,ct=R.getBoundingClientRect(),xt=v-ct.top,It=ct.bottom-v;let Ft=0;if(j<0&&xt<W)Ft=-Math.max(6,(W-xt)/W*28);else if(j>0&&It<W)Ft=Math.max(6,(W-It)/W*28);else{j=0;return}const Wt=R.scrollTop;R.scrollTop=Math.min(it,Math.max(0,Wt+Ft)),R.scrollTop!==Wt&&F(x,v),Ft<0&&R.scrollTop>0||Ft>0&&R.scrollTop<it?a=window.requestAnimationFrame(N):j=0},S=R=>{x=R.clientX,v=R.clientY;const it=D();if(it){const ct=it.getBoundingClientRect(),xt=R.clientY-ct.top,It=ct.bottom-R.clientY;xt<56?(j=-1,a||(a=window.requestAnimationFrame(N))):It<56?(j=1,a||(a=window.requestAnimationFrame(N))):j=0}gt.kind==="resize"?P(R.clientX,R.clientY):F(R.clientX,R.clientY)},B=()=>{j=0,a&&(window.cancelAnimationFrame(a),a=0),kt(null)};return window.addEventListener("pointermove",S),window.addEventListener("pointerup",B),window.addEventListener("pointercancel",B),()=>{j=0,a&&window.cancelAnimationFrame(a),window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",B),window.removeEventListener("pointercancel",B)}},[gt,Q,C,n,y]),f.useEffect(()=>{if(!Ct||!Yt.current)return;const a=Yt.current,x=tt.find(D=>D.id===Ct);a.textContent=(x==null?void 0:x.value)??"",a.focus();const v=document.createRange();v.selectNodeContents(a),v.collapse(!1);const j=window.getSelection();j==null||j.removeAllRanges(),j==null||j.addRange(v)},[Ct]);const Ot=a=>{jt.current=a,r==null||r(a)},Nt=w.filter(a=>a.pageNumber===e),p=y.filter(a=>a.pageNumber===e),I=rt.filter(a=>a.pageNumber===e),G=tt.filter(a=>a.pageNumber===e),K=(a,x)=>{const v=x.trim();if(!v){V==null||V(a.id),z==null||z(null);return}const j=je(v,a.fontSize);bt==null||bt(a.id,{value:v,width:j.width,height:j.height}),z==null||z(null)},Mt=(a,x)=>{if(!et)return;const v=at.current,j=pt.current;if(!v||!j)return;let D=Qi(a,x,v,j,n),P,F=oe;if(Gt){const B=is(D.x,D.y,qt,e);if(!B)return;const R=tt.find(it=>it.fieldId===B.id);if(R){dt==null||dt(R.id),At==null||At(B.id),z==null||z(R.id);return}P=B.id,D={x:B.x,y:B.y,fontSize:B.fontSize??ae},F=B.color??oe,At==null||At(B.id)}const N=je("",D.fontSize),S={id:Se(),fieldId:P,pageNumber:e,x:D.x,y:D.y,width:N.width,height:N.height,value:"",fontSize:D.fontSize,color:F};et(S),dt==null||dt(S.id),z==null||z(S.id)},zt=a=>{var v;if(d!=="text"||a.target.closest(".epochs-pdf-viewer__inline-text"))return;if(ht.current){ht.current=!1;return}const x=window.getSelection();if(!(x&&!x.isCollapsed&&x.toString().trim())){if(a.detail>=2&&ss(a.clientX,a.clientY,pt.current)){const D=at.current;if(D&&m&&et){const P=Ye(D,n);if(P){m({id:qe(),pageNumber:e,kind:"redact",color:Ne,rects:Ke(P.rects),text:P.text});const F=Sn(P.rects),N=je(P.text||" ",F.fontSize),S={id:Se(),pageNumber:e,x:F.x,y:F.y,width:N.width,height:N.height,value:P.text,fontSize:F.fontSize,color:oe};et(S),dt==null||dt(S.id),z==null||z(S.id),(v=window.getSelection())==null||v.removeAllRanges(),ht.current=!0}}return}a.stopPropagation(),Mt(a.clientX,a.clientY)}},Bt=a=>{const x=a.target;if(!(x.closest(".epochs-pdf-viewer__signature")||x.closest(".epochs-pdf-viewer__signature-field")||x.closest(".epochs-pdf-viewer__inline-text"))){if(d==="text"){Mt(a.clientX,a.clientY);return}if(!Q&&d==="sign"&&ft&&U){const v=at.current;if(!v)return;const j=Re(a.clientX,a.clientY,v,n);U(e,Math.max(0,j.x-75),Math.max(0,j.y-12));return}if(!Q&&d==="sign"&&b&&k){const v=at.current;if(!v)return;const j=we(v,n),D=Re(a.clientX,a.clientY,v,n);let P=D.x-b.width/2,F=D.y-b.height/2;const N=Math.max(0,j.width-b.width),S=Math.max(0,j.height-b.height);P=Math.min(Math.max(0,P),N),F=Math.min(Math.max(0,F),S),k({id:Fe(),pageNumber:e,x:P,y:F,width:b.width,height:b.height,imageDataUrl:b.imageDataUrl});return}}},Jt=a=>Ct===a.id?s.jsx("span",{ref:Yt,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox","aria-label":"Edit text",className:"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--editing",style:{left:a.x*n,top:a.y*n,fontSize:a.fontSize*n,color:a.color,minWidth:Math.max(12,a.fontSize*n*.5),width:Math.max(a.width*n,a.fontSize*n*.5)},onClick:v=>v.stopPropagation(),onPointerDown:v=>v.stopPropagation(),onInput:v=>{const j=v.currentTarget.textContent??"",D=je(j||" ",a.fontSize);bt==null||bt(a.id,{value:j,width:D.width,height:D.height})},onBlur:v=>{K(a,v.currentTarget.textContent??"")},onKeyDown:v=>{v.stopPropagation(),v.key==="Escape"&&(v.preventDefault(),v.currentTarget.blur()),v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),v.currentTarget.blur())}},a.id):a.value.trim()?s.jsx("span",{className:Vt===a.id?"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--selected":"epochs-pdf-viewer__inline-text",style:{left:a.x*n,top:a.y*n,fontSize:a.fontSize*n,color:a.color},onClick:v=>{if(v.stopPropagation(),d==="erase"){V==null||V(a.id);return}d==="text"&&(dt==null||dt(a.id),z==null||z(a.id))},children:a.value},a.id):null;return s.jsx("div",{ref:Ot,"data-page-number":e,className:"epochs-pdf-viewer__page",children:s.jsxs("div",{ref:at,className:`epochs-pdf-viewer__surface epochs-pdf-viewer__surface--tool-${d}`,onClick:Bt,children:[s.jsx("canvas",{ref:$t,className:"epochs-pdf-viewer__canvas"}),s.jsx("div",{className:"epochs-pdf-viewer__markup-layer","aria-hidden":"true",children:Nt.map(a=>a.kind==="redact"?null:a.rects.map((x,v)=>a.kind==="highlight"?s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--highlight",style:{left:x.x*n,top:x.y*n,width:x.w*n,height:x.h*n,background:a.color},onClick:j=>{d==="erase"&&(j.stopPropagation(),_==null||_(a.id))}},`${a.id}_${v}`):s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--underline",style:{left:x.x*n,top:(x.y+x.h)*n-Math.max(2,n*1.5),width:x.w*n,height:Math.max(2,n*1.5),background:a.color},onClick:j=>{d==="erase"&&(j.stopPropagation(),_==null||_(a.id))}},`${a.id}_${v}`)))}),s.jsxs("div",{className:"epochs-pdf-viewer__signature-layer",children:[I.map(a=>{const x=a.type??"sign",v=yt[a.id]??a.value??"",j=x==="date"||x==="text"?!!v.trim():p.some(D=>D.fieldId===a.id);return s.jsx("button",{type:"button","data-signature-field-id":a.id,className:ot===a.id?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--selected":j?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--filled":"epochs-pdf-viewer__signature-field",style:{left:a.x*n,top:a.y*n,width:a.width*n,height:a.height*n},onClick:D=>{if(D.stopPropagation(),Y==null||Y(a.id),x==="date"||x==="text"){T==null||T(null),wt==null||wt(x);return}const P=p.find(F=>F.fieldId===a.id);T==null||T((P==null?void 0:P.id)??null),P?A==null||A(P.id):wt==null||wt(x)},title:j?"Completed field":x==="date"?"Date field":x==="text"?"Text field":"Signature field",children:x==="date"||x==="text"?v.trim()?s.jsx("span",{className:"epochs-pdf-viewer__signature-field-value",children:v}):x==="date"?s.jsx("span",{children:"Date here"}):s.jsx("span",{children:a.placeholder??"Enter text"}):j?null:s.jsx("span",{children:"Sign here"})},a.id)}),p.map(a=>s.jsxs("div",{className:Z===a.id?"epochs-pdf-viewer__signature epochs-pdf-viewer__signature--selected":"epochs-pdf-viewer__signature",style:{left:a.x*n,top:a.y*n,width:a.width*n,height:a.height*n},onPointerDown:x=>{if(x.stopPropagation(),x.preventDefault(),T==null||T(a.id),d==="erase"&&!Q){H==null||H(a.id);return}if(Q){Y==null||Y(a.fieldId??null),A==null||A(a.id);return}const v=at.current;if(!v)return;const j=Re(x.clientX,x.clientY,v,n);kt({kind:"signature",id:a.id,offsetX:j.x-a.x,offsetY:j.y-a.y})},children:[s.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-edit",title:"Edit signature","aria-label":"Edit signature",onPointerDown:x=>{x.stopPropagation()},onClick:x=>{x.stopPropagation(),T==null||T(a.id),A==null||A(a.id)},children:s.jsx(ys,{size:12})}),Q?null:s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-duplicate",title:"Duplicate signature","aria-label":"Duplicate signature",onPointerDown:x=>{x.stopPropagation()},onClick:x=>{x.stopPropagation(),T==null||T(a.id),L==null||L(a.id)},children:"⧉"}),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-remove",title:"Remove signature","aria-label":"Remove signature",onPointerDown:x=>{x.stopPropagation()},onClick:x=>{x.stopPropagation(),H==null||H(a.id)},children:"×"})]}),s.jsx("img",{src:a.imageDataUrl,alt:"Signature",draggable:!1}),Q?null:s.jsx("div",{className:"epochs-pdf-viewer__signature-resize",title:"Resize",onPointerDown:x=>{x.stopPropagation(),x.preventDefault(),T==null||T(a.id),kt({kind:"resize",id:a.id,startX:x.clientX,startY:x.clientY,startW:a.width,startH:a.height})},children:s.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s.jsx("path",{d:"M7 1L1 7M7 4L4 7",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round"})})})]},a.id))]}),s.jsx("div",{className:"epochs-pdf-viewer__text-layer-overlay",children:G.map(a=>Jt(a))}),s.jsx("div",{ref:pt,className:"textLayer epochs-pdf-viewer__text-layer",onClick:zt}),s.jsx("div",{className:"epochs-pdf-viewer__redact-layer","aria-hidden":"true",children:Nt.map(a=>a.kind==="redact"?a.rects.map((x,v)=>s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--redact",style:{left:x.x*n,top:x.y*n,width:x.w*n,height:x.h*n,background:a.color||Ne},onClick:j=>{d==="erase"&&(j.stopPropagation(),_==null||_(a.id))}},`${a.id}_${v}`)):null)})]})})}function js({pdfDoc:t,pageNumber:e,isActive:n,rotation:i,onSelect:r,width:o=140,annotations:d=[],signatures:u=[],signatureFields:w=[],texts:m=[],textFields:_=[]}){const y=f.useRef(null);return f.useEffect(()=>{if(!t||!y.current)return;let b=!1;const k=y.current,C=k.getContext("2d");if(!C)return;let H=null;return(async()=>{try{const L=await t.getPage(e);if(b)return;const Z=L.getViewport({scale:1,rotation:i}),T=o/Z.width,rt=L.getViewport({scale:T,rotation:i});k.width=Math.floor(rt.width),k.height=Math.floor(rt.height),H=L.render({canvasContext:C,viewport:rt}),await H.promise;const ot=d.filter(q=>q.pageNumber===e);ot.length>0&&Xn(C,ot,T);const Y=u.filter(q=>q.pageNumber===e),Q=w.filter(q=>q.pageNumber===e);Q.length>0&&qi(C,Q,new Set(Y.map(q=>q.fieldId).filter(Boolean)),T),Y.length>0&&await Vn(C,Y,T);const wt=m.filter(q=>q.pageNumber===e),yt=_.filter(q=>q.pageNumber===e);yt.length>0&&rs(C,yt,new Set(wt.filter(q=>q.fieldId&&q.value.trim()).map(q=>q.fieldId)),T),wt.length>0&&qn(C,wt,T)}catch{}})(),()=>{if(b=!0,H)try{H.cancel()}catch{}}},[d,t,e,i,w,u,_,m,o]),s.jsxs("button",{type:"button",onClick:()=>r(e),className:n?"epochs-pdf-viewer__thumb epochs-pdf-viewer__thumb--active":"epochs-pdf-viewer__thumb",title:`Page ${e}`,children:[s.jsx("div",{className:"epochs-pdf-viewer__thumb-frame",children:s.jsx("canvas",{ref:y})}),s.jsx("span",{className:"epochs-pdf-viewer__thumb-label",children:e})]})}const ks=/^(blob:|https?:|data:)/i;let Yn=!1;function tn(t){me.GlobalWorkerOptions.workerSrc=t,Yn=!0}function Ms(t){if(t){tn(t);return}Yn||me.GlobalWorkerOptions.workerSrc||tn(`https://unpkg.com/pdfjs-dist@${me.version}/build/pdf.worker.min.mjs`)}function Ns(t,e,n=""){const i=e||t;if(!i)return"";if(ks.test(i))return i;const r=i.startsWith("/")?i:`/${i}`;return n?`${n.replace(/\/$/,"")}${r}`:r}async function Ps(t,e){const n=await fetch(t,e);if(!n.ok)throw new Error(`Failed to fetch PDF (${n.status})`);return n.arrayBuffer()}async function An(t,e){if(typeof t=="string")return Ps(t,e);if(t instanceof ArrayBuffer)return t.slice(0);if(t instanceof Uint8Array){const n=new Uint8Array(t.byteLength);return n.set(t),n.buffer}return t.arrayBuffer()}async function Cs(t,e,n){const{scale:i,rotation:r,annotations:o,signatures:d=[],texts:u=[],mimeType:w="image/jpeg",quality:m=.92}=n,_=await t.getPage(e),y=_.getViewport({scale:i,rotation:r}),b=_.getViewport({scale:1,rotation:r}),k=document.createElement("canvas"),C=k.getContext("2d",{alpha:!1});if(!C)throw new Error("Could not create canvas context");const H=Math.floor(y.width),A=Math.floor(y.height);k.width=H,k.height=A,C.fillStyle="#ffffff",C.fillRect(0,0,H,A),await _.render({canvasContext:C,viewport:y}).promise;const L=o.filter(Y=>Y.pageNumber===e);L.length>0&&Xn(C,L,i);const Z=d.filter(Y=>Y.pageNumber===e);Z.length>0&&await Vn(C,Z,i);const T=u.filter(Y=>Y.pageNumber===e);T.length>0&&qn(C,T,i);const rt=k.toDataURL(w,m),ot=$s(rt);return k.width=0,k.height=0,{pageNumber:e,width:H,height:A,pageWidth:b.width,pageHeight:b.height,dataUrl:rt,jpegBytes:ot}}async function Un(t,e){const n=[];for(let i=1;i<=t.numPages;i+=1)n.push(await Cs(t,i,e));return n}function $s(t){const e=t.split(",")[1]??"",n=atob(e),i=new Uint8Array(n.length);for(let r=0;r<n.length;r+=1)i[r]=n.charCodeAt(r);return i}function Xt(t){return new TextEncoder().encode(t)}function Hn(...t){const e=t.reduce((r,o)=>r+o.byteLength,0),n=new Uint8Array(e);let i=0;for(const r of t)n.set(r,i),i+=r.byteLength;return n}function Is(t){const e=[],n=b=>(e.push(b),e.length),i=[];for(const b of t){const k=Hn(Xt(`<< /Type /XObject /Subtype /Image /Width ${b.width} /Height ${b.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${b.jpegBytes.byteLength} >>
4
4
  stream
5
- `),m.jpegBytes,Ae(`
6
- endstream`)),N=n(P),U=`q
7
- ${m.pageWidth.toFixed(2)} 0 0 ${m.pageHeight.toFixed(2)} 0 0 cm
5
+ `),b.jpegBytes,Xt(`
6
+ endstream`)),C=n(k),H=`q
7
+ ${b.pageWidth.toFixed(2)} 0 0 ${b.pageHeight.toFixed(2)} 0 0 cm
8
8
  /Im0 Do
9
- Q`,E=n(Ae(`<< /Length ${U.length} >>
9
+ Q`,A=n(Xt(`<< /Length ${H.length} >>
10
10
  stream
11
- ${U}
12
- endstream`)),B=n(Ae(`<< /Type /Page /Parent __PAGES__ 0 R /MediaBox [0 0 ${m.pageWidth.toFixed(2)} ${m.pageHeight.toFixed(2)}] /Contents ${E} 0 R /Resources << /XObject << /Im0 ${N} 0 R >> >> >>`));i.push(B)}const s=i.map(m=>`${m} 0 R`).join(" "),o=n(Ae(`<< /Type /Pages /Kids [${s}] /Count ${i.length} >>`));for(const m of i){const P=new TextDecoder().decode(t[m-1]);t[m-1]=Ae(P.replace("/Parent __PAGES__ 0 R",`/Parent ${o} 0 R`))}const c=n(Ae(`<< /Type /Catalog /Pages ${o} 0 R >>`)),l=[Ae(`%PDF-1.4
13
- `)],x=[0];let g=l[0].byteLength;for(let m=0;m<t.length;m+=1){x.push(g);const P=Ae(`${m+1} 0 obj
14
- `),N=Ae(`
11
+ ${H}
12
+ endstream`)),L=n(Xt(`<< /Type /Page /Parent __PAGES__ 0 R /MediaBox [0 0 ${b.pageWidth.toFixed(2)} ${b.pageHeight.toFixed(2)}] /Contents ${A} 0 R /Resources << /XObject << /Im0 ${C} 0 R >> >> >>`));i.push(L)}const r=i.map(b=>`${b} 0 R`).join(" "),o=n(Xt(`<< /Type /Pages /Kids [${r}] /Count ${i.length} >>`));for(const b of i){const k=new TextDecoder().decode(e[b-1]);e[b-1]=Xt(k.replace("/Parent __PAGES__ 0 R",`/Parent ${o} 0 R`))}const d=n(Xt(`<< /Type /Catalog /Pages ${o} 0 R >>`)),u=[Xt(`%PDF-1.4
13
+ `)],w=[0];let m=u[0].byteLength;for(let b=0;b<e.length;b+=1){w.push(m);const k=Xt(`${b+1} 0 obj
14
+ `),C=Xt(`
15
15
  endobj
16
- `);l.push(P,t[m],N),g+=P.byteLength+t[m].byteLength+N.byteLength}const M=g;let v=`xref
17
- 0 ${t.length+1}
18
- `;v+=`0000000000 65535 f
19
- `;for(let m=1;m<=t.length;m+=1)v+=`${String(x[m]).padStart(10,"0")} 00000 n
20
- `;return v+=`trailer
21
- << /Size ${t.length+1} /Root ${c} 0 R >>
22
- `,v+=`startxref
23
- ${M}
24
- %%EOF`,l.push(Ae(v)),Nn(...l)}function Wt(e,t){const n=URL.createObjectURL(e),i=document.createElement("a");i.href=n,i.download=t,i.click(),URL.revokeObjectURL(n)}const Nt=[{id:"dancing-script",label:"Dancing Script",family:"Dancing Script"},{id:"great-vibes",label:"Great Vibes",family:"Great Vibes"},{id:"pacifico",label:"Pacifico",family:"Pacifico"},{id:"satisfy",label:"Satisfy",family:"Satisfy"},{id:"allura",label:"Allura",family:"Allura"}],mr="https://fonts.googleapis.com/css2?family=Allura&family=Dancing+Script:wght@500;600&family=Great+Vibes&family=Pacifico&family=Satisfy&display=swap";let kt=null;function wr(){return typeof document>"u"?Promise.resolve():kt||(kt=new Promise(e=>{var i;if(!document.querySelector('link[data-epochs-signature-fonts="true"]')){const s=document.createElement("link");s.rel="stylesheet",s.href=mr,s.dataset.epochsSignatureFonts="true",document.head.appendChild(s)}const n=()=>Promise.all(Nt.map(s=>document.fonts.load(`48px "${s.family}"`))).then(()=>{});(i=document.fonts)!=null&&i.ready?document.fonts.ready.then(n).then(e).catch(()=>e()):window.setTimeout(()=>{n().then(e).catch(()=>e())},300)}),kt)}function yr({open:e,onClose:t,onSave:n,fieldType:i,showFieldTypeTabs:s=!1,textPlaceholder:o}){const c=d.useRef(null),l=d.useRef(!1),x=d.useRef(null),g=d.useRef([]),M=d.useRef([]),v=i??"sign",[m,P]=d.useState(v),[N,U]=d.useState(""),[E,B]=d.useState(""),[A,C]=d.useState("draw"),[K,Q]=d.useState(""),[z,ne]=d.useState(""),[_e,pe]=d.useState(!1),[S,re]=d.useState("signature"),[J,D]=d.useState("#111827"),[ie,be]=d.useState("dancing-script"),[je,de]=d.useState(!1),ge=Nt.find(p=>p.id===ie)??Nt[0],X=S==="initials"?z.trim():K.trim(),st=X||(S==="initials"?"AB":"Signature");if(d.useEffect(()=>{e&&(P(v),U(new Date().toISOString().slice(0,10)),B(""))},[e,v]),d.useEffect(()=>{if(!e||m!=="sign")return;const p=c.current;if(!p)return;const _=p.getContext("2d");_&&(p.width=560,p.height=200,_.fillStyle="#ffffff",_.fillRect(0,0,p.width,p.height),_.lineCap="round",_.lineJoin="round",_.strokeStyle=J,_.lineWidth=2.5,x.current=null,l.current=!1)},[e,m]),d.useEffect(()=>{if(!e)return;let p=!1;return de(!1),wr().then(()=>{p||de(!0)}),()=>{p=!0}},[e]),d.useEffect(()=>{const p=c.current,_=p==null?void 0:p.getContext("2d");_&&(_.strokeStyle=J,_.fillStyle=J)},[J]),d.useEffect(()=>{if(!e||A!=="type")return;const p=c.current,_=p==null?void 0:p.getContext("2d");if(!p||!_||(_.fillStyle="#ffffff",_.fillRect(0,0,p.width,p.height),!X))return;const $=S==="initials"?72:ge.family==="Great Vibes"||ge.family==="Allura"?56:ge.family==="Pacifico"?44:48;_.fillStyle=J,_.textAlign="center",_.textBaseline="middle",_.font=`${$}px "${ge.family}", cursive`,_.fillText(X,p.width/2,p.height/2)},[X,S,A,J,e,ge,je]),!e)return null;const Ee=p=>{const _=c.current,$=_.getBoundingClientRect();return{x:(p.clientX-$.left)/$.width*_.width,y:(p.clientY-$.top)/$.height*_.height}},Ce=p=>{if(A!=="draw")return;p.currentTarget.setPointerCapture(p.pointerId),l.current=!0;const _=Ee(p);x.current=_,M.current=[_]},Be=p=>{if(!l.current||A!=="draw")return;const _=c.current,$=_==null?void 0:_.getContext("2d"),ee=x.current;if(!$||!ee)return;const q=Ee(p);$.beginPath(),$.moveTo(ee.x,ee.y),$.lineTo(q.x,q.y),$.stroke(),x.current=q,M.current.push(q)},Te=()=>{M.current.length>1&&g.current.push([...M.current]),M.current=[],l.current=!1,x.current=null},H=()=>{const p=c.current,_=p==null?void 0:p.getContext("2d");!p||!_||(_.fillStyle="#ffffff",_.fillRect(0,0,p.width,p.height),g.current=[],M.current=[],Q(""),ne(""),pe(!1))},he=p=>{Q(p),_e||ne(br(p))},ue=()=>{if(A==="draw"){const p=g.current;if(p.length===0)return;let _=1/0,$=1/0,ee=-1/0,q=-1/0;for(const Oe of p)for(const Re of Oe)Re.x<_&&(_=Re.x),Re.y<$&&($=Re.y),Re.x>ee&&(ee=Re.x),Re.y>q&&(q=Re.y);const me=8;_=Math.max(0,_-me),$=Math.max(0,$-me),ee+=me,q+=me;const se=ee-_,ke=q-$,we=p.map(Oe=>"M"+Oe.map(He=>({x:He.x-_,y:He.y-$})).map(He=>`${He.x.toFixed(1)},${He.y.toFixed(1)}`).join("L")).join(" "),Fe=`<svg xmlns="http://www.w3.org/2000/svg" width="${se.toFixed(0)}" height="${ke.toFixed(0)}" viewBox="0 0 ${se.toFixed(0)} ${ke.toFixed(0)}"><path d="${we}" fill="none" stroke="${J}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,ze=`data:image/svg+xml;base64,${btoa(Fe)}`;n(ze,se,ke)}else{if(!X)return;const p=3,_=S==="initials"?72:ge.family==="Great Vibes"||ge.family==="Allura"?56:ge.family==="Pacifico"?44:48,ee=document.createElement("canvas").getContext("2d");ee.font=`${_*p}px "${ge.family}", cursive`;const q=ee.measureText(X),me=12*p,se=Math.ceil(q.width)+me*2,ke=_*p+me*2,we=document.createElement("canvas");we.width=se,we.height=ke;const Fe=we.getContext("2d");Fe.clearRect(0,0,se,ke),Fe.font=`${_*p}px "${ge.family}", cursive`,Fe.fillStyle=J,Fe.textBaseline="middle",Fe.fillText(X,me,ke/2);const ze=we.toDataURL("image/png");n(ze,se/p,ke/p)}},Se=()=>{const p=m==="date"?N:E.trim();if(!p)return;const _=document.createElement("canvas"),$=_.getContext("2d"),ee=16;$.font=`${ee}px sans-serif`;const q=$.measureText(p),me=8;_.width=Math.ceil(q.width)+me*2,_.height=ee+me*2,$.clearRect(0,0,_.width,_.height),$.font=`${ee}px sans-serif`,$.fillStyle="#111827",$.textBaseline="middle",$.fillText(p,me,_.height/2);const se=_.toDataURL("image/png");n(se,_.width,_.height)},W=m==="sign",$e=m==="date"?"Pick a date":m==="text"?"Enter text":"Create e-signature";return r.jsxs("div",{className:"epochs-pdf-viewer__modal",role:"dialog","aria-modal":"true",children:[r.jsx("div",{className:"epochs-pdf-viewer__modal-backdrop",onClick:t}),r.jsxs("div",{className:"epochs-pdf-viewer__modal-card",children:[r.jsxs("div",{className:"epochs-pdf-viewer__modal-header",children:[r.jsx("h3",{children:$e}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t,title:"Close",children:"×"})]}),s&&!i?r.jsx("div",{className:"epochs-pdf-viewer__field-type-tabs",role:"tablist",children:["sign","date","text"].map(p=>r.jsx("button",{type:"button",role:"tab","aria-selected":m===p,className:m===p?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>P(p),children:p==="sign"?"Sign":p==="date"?"Date":"Text"},p))}):null,W?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"epochs-pdf-viewer__sign-modes",children:[r.jsx("button",{type:"button",className:A==="draw"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>{C("draw"),H()},children:"Draw"}),r.jsx("button",{type:"button",className:A==="type"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>C("type"),children:"Type"}),r.jsxs("label",{className:"epochs-pdf-viewer__sign-ink",children:["Ink",r.jsx("input",{type:"color",value:J,onChange:p=>D(p.target.value)})]})]}),A==="type"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"epochs-pdf-viewer__sign-fonts",role:"group","aria-label":"Handwriting style",children:Nt.map(p=>r.jsx("button",{type:"button",className:ie===p.id?"epochs-pdf-viewer__sign-font epochs-pdf-viewer__sign-font--active":"epochs-pdf-viewer__sign-font",style:{fontFamily:`"${p.family}", cursive`},onClick:()=>be(p.id),title:p.label,children:st},p.id))}),r.jsxs("div",{className:"epochs-pdf-viewer__sign-type-fields",children:[r.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",children:[r.jsx("span",{children:"Full name"}),r.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:K,onChange:p=>he(p.target.value),onFocus:()=>re("signature"),placeholder:"Type your full name",style:{fontFamily:`"${ge.family}", cursive`},autoFocus:!0})]}),r.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",children:[r.jsx("span",{children:"Initials"}),r.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:z,onChange:p=>{pe(!0),ne(p.target.value.toUpperCase())},onFocus:()=>re("initials"),placeholder:"e.g. JD",maxLength:4,style:{fontFamily:`"${ge.family}", cursive`}})]})]}),r.jsxs("div",{className:"epochs-pdf-viewer__sign-type-kind",role:"group","aria-label":"Preview type",children:[r.jsx("button",{type:"button",className:S==="signature"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>re("signature"),children:"Use full name"}),r.jsx("button",{type:"button",className:S==="initials"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>re("initials"),children:"Use initials"})]})]}):r.jsx("p",{className:"epochs-pdf-viewer__sign-hint",children:"Draw your signature below"}),r.jsx("canvas",{ref:c,className:A==="draw"?"epochs-pdf-viewer__sign-canvas":"epochs-pdf-viewer__sign-canvas epochs-pdf-viewer__sign-canvas--preview",onPointerDown:Ce,onPointerMove:Be,onPointerUp:Te,onPointerLeave:Te})]}):m==="date"?r.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",style:{padding:"1rem"},children:[r.jsx("span",{children:"Date"}),r.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"date",value:N,onChange:p=>U(p.target.value),autoFocus:!0})]}):r.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",style:{padding:"1rem"},children:[r.jsx("span",{children:"Text"}),r.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:E,onChange:p=>B(p.target.value),placeholder:o??"Enter text",autoFocus:!0})]}),r.jsxs("div",{className:"epochs-pdf-viewer__modal-actions",children:[W?r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:H,children:"Clear"}):null,r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:t,children:"Cancel"}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:W?ue:Se,disabled:m==="date"?!N:m==="text"?!E.trim():!1,children:W?"Use signature":"Place on page"})]})]})]})}function br(e){const t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?"":t.length===1?t[0].slice(0,2).toUpperCase():t.slice(0,3).map(n=>{var i;return((i=n[0])==null?void 0:i.toUpperCase())??""}).join("")}const Ct="__epochsToolbarToolId";function Ne(e,t){const n=(()=>null);return n.displayName=t,Object.defineProperty(n,Ct,{value:e,enumerable:!0}),n}function Cn(e){return e[Ct]}function xr(e){return typeof e=="function"&&Ct in e&&typeof e[Ct]=="string"}const Vt=Ne("thumbnail","Thumbnail"),Qt=Ne("navigation","Navigation"),Jt=Ne("zoom","Zoom"),en=Ne("rotate","Rotate"),tn=Ne("reload","Reload"),nn=Ne("print","Print"),rn=Ne("open","Open"),sn=Ne("download","Download"),on=Ne("highlight","Highlight"),an=Ne("underline","Underline"),cn=Ne("signature","Signature"),ln=Ne("text","AddText"),dn=Ne("erase","Erase"),hn=Ne("clear","Clear"),_r=[Vt,Qt,Jt,en,on,an,cn,ln,dn,hn,tn,nn,rn,sn],Xt=[[Vt,Qt],[Jt,en,on,an,cn,ln,dn,hn,tn,nn,rn,sn]],vr=["highlight","underline","signature","text","erase","clear"];function Tn(e){return vr.includes(e)}function jr(e,t,n){const i=[];switch(n!=null&&n.showMarkupSep&&i.push(r.jsx("span",{className:"epochs-pdf-viewer__toolbar-sep","aria-hidden":"true"},`${e}-sep`)),e){case"thumbnail":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>t.setShowThumbnails(s=>!s),title:t.showThumbnails?"Hide thumbnails":"Show thumbnails",children:r.jsx(Zi,{})},"thumbnail"));break;case"navigation":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t.handlePrev,disabled:!t.canGoPrev||t.status!=="ready",title:"Previous page",children:r.jsx(Gi,{})},"nav-prev"),r.jsxs("div",{className:"epochs-pdf-viewer__page-input",children:[r.jsx("input",{type:"number",value:t.pageNumber,min:1,max:t.numPages||1,onChange:s=>{const o=Number.parseInt(s.target.value,10);Number.isFinite(o)&&t.scrollToPage(Math.max(1,Math.min(t.numPages||1,o)))},disabled:t.status!=="ready","aria-label":"Page number"}),r.jsxs("span",{children:["/ ",t.numPages||"-"]})]},"nav-page"),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t.handleNext,disabled:!t.canGoNext||t.status!=="ready",title:"Next page",children:r.jsx(Xi,{})},"nav-next"));break;case"zoom":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t.handleZoomOut,disabled:t.status!=="ready",title:"Zoom out",children:r.jsx(Ki,{})},"zoom-out"),r.jsxs("span",{className:"epochs-pdf-viewer__zoom-label",children:[Math.round(t.scale*100),"%"]},"zoom-label"),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t.handleZoomIn,disabled:t.status!=="ready",title:"Zoom in",children:r.jsx(Vi,{})},"zoom-in"),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>void t.handleFitWidth(),disabled:t.status!=="ready",title:"Fit to width",children:"Fit"},"zoom-fit"));break;case"rotate":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:t.handleRotate,disabled:t.status!=="ready",title:"Rotate",children:r.jsx(er,{})},"rotate"));break;case"highlight":i.push(r.jsx("button",{type:"button",className:t.markupTool==="highlight"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>t.toggleMarkupTool("highlight"),disabled:t.status!=="ready",title:"Highlight text — select text to highlight",children:r.jsx(tr,{})},"highlight"));break;case"underline":i.push(r.jsx("button",{type:"button",className:t.markupTool==="underline"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>t.toggleMarkupTool("underline"),disabled:t.status!=="ready",title:"Underline text — select text to underline",children:r.jsx(nr,{})},"underline"));break;case"signature":i.push(r.jsx("button",{type:"button",className:t.markupTool==="sign"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>{if(!t.hasFixedSignatureFields&&t.pendingSignature&&t.markupTool!=="sign"){t.setMarkupTool("sign");return}t.setSignaturePadOpen(!0)},disabled:t.status!=="ready",title:t.hasFixedSignatureFields?"Create e-signature for a fixed field":t.pendingSignature?"Place signature — click on the page, then drag to move":"Create e-signature",children:r.jsx(rr,{})},"signature"));break;case"text":i.push(r.jsx("button",{type:"button",className:t.markupTool==="text"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>t.toggleMarkupTool("text"),disabled:t.status!=="ready",title:t.hasFixedTextFields?"Edit text in predefined areas — click to type":"Edit PDF text — select words, then change them",children:r.jsx(or,{})},"text"));break;case"erase":i.push(r.jsx("button",{type:"button",className:t.markupTool==="erase"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>t.toggleMarkupTool("erase"),disabled:t.status!=="ready",title:"Remove text — select PDF words to cover them, or click added markup",children:r.jsx(ir,{})},"erase"));break;case"clear":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:t.handleClearAnnotations,disabled:t.status!=="ready"||t.annotationsLength===0&&t.signaturesLength===0&&t.textsLength===0,title:"Clear all markup",children:"Clear"},"clear"));break;case"reload":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void t.loadDocument(),title:"Reload",children:r.jsx(Ji,{})},"reload"));break;case"print":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void t.handlePrint(),disabled:t.status!=="ready"||!t.pdfDoc||t.isPrinting,title:t.isPrinting?"Preparing print…":"Print (includes highlights & underlines)",children:r.jsx(Qi,{})},"print"));break;case"open":i.push(r.jsx("a",{className:"epochs-pdf-viewer__btn",href:t.displayUrl||t.resolvedUrl||void 0,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:r.jsx(Yi,{})},"open"));break;case"download":i.push(r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void t.handleDownload(),disabled:t.status!=="ready"||!t.pdfDoc||t.isDownloading,title:t.isDownloading?"Preparing download…":t.annotationsLength>0||t.signaturesLength>0||t.textsLength>0?"Download PDF with markup":"Download PDF",children:r.jsx(qi,{})},"download"));break}return i.length>0?i:null}function kr(e,t){const n=[];if(e.markupTool==="sign"&&e.pendingSignature&&!e.hasFixedSignatureFields&&t.has("signature")&&n.push(r.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:"Click page to place duplicate/new signature"},"sign-hint")),e.markupTool==="text"&&t.has("text")&&n.push(r.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:e.hasFixedTextFields?"Click in a predefined text area to type":"Select text to edit it — e.g. change this PDF to this is PDF"},"text-hint")),e.markupTool==="erase"&&t.has("erase")&&n.push(r.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:"Select PDF words to remove · click added text/markup to erase"},"erase-hint")),e.markupTool==="highlight"&&t.has("highlight")||e.markupTool==="underline"&&t.has("underline")){const i=e.markupTool==="highlight"?e.highlightHex:e.underlineHex,s=e.markupTool==="highlight"?e.setHighlightHex:e.setUnderlineHex,o=e.markupTool==="highlight"?Yt:Zt;n.push(r.jsxs("div",{className:"epochs-pdf-viewer__color-picker",role:"group","aria-label":`${e.markupTool} color`,children:[o.map(c=>r.jsx("button",{type:"button",className:Ye(i)===Ye(c.hex)?"epochs-pdf-viewer__swatch epochs-pdf-viewer__swatch--active":"epochs-pdf-viewer__swatch",style:{background:c.hex},title:c.label,"aria-label":c.label,"aria-pressed":Ye(i)===Ye(c.hex),onClick:()=>s(Ye(c.hex))},c.id)),r.jsxs("label",{className:"epochs-pdf-viewer__custom-color",title:"Custom color",children:[r.jsx("span",{className:"epochs-pdf-viewer__custom-color-chip",style:{background:i}}),r.jsx("input",{type:"color",value:Ye(i),onChange:c=>s(Ye(c.target.value)),"aria-label":"Custom color"})]})]},"color-picker"))}return n.length>0?n:null}function Mr(e,t){if(!e)return null;if(Array.isArray(e)){const o=c=>(c??[]).filter(xr).map(Cn);return{left:o(e[0]),right:o(e[1])}}const n=t.enableThumbnails,i=(o,c)=>o.map(Cn).filter(l=>c[l]!==!1),s={thumbnail:n,navigation:t.enableNavigation,zoom:t.enableZoom,rotate:t.enableRotate,reload:t.enableReload,print:t.enablePrint,open:t.enableOpen,download:t.enableDownload,highlight:t.enableHighlight,underline:t.enableUnderline,signature:t.enableSignature,text:t.enableText,erase:t.enableErase,clear:t.enableClear};return{left:i(Xt[0],s),right:i(Xt[1],s)}}function Dn({file:e,fileUrl:t,baseUrl:n="",fetchOptions:i,height:s="80vh",title:o="PDF document",initialScale:c=1,withThumbnails:l=!1,thumbnailWidth:x=140,maxThumbnails:g=60,className:M,workerSrc:v,enableToolbar:m=!1,enableThumbnails:P,enableNavigation:N=!0,enableZoom:U=!0,enableRotate:E=!0,enableReload:B=!0,enablePrint:A=!0,enableOpen:C=!0,enableDownload:K=!0,enableMarkup:Q=!0,enableHighlight:z=!0,enableUnderline:ne=!0,enableSignature:_e=!0,enableText:pe=!0,enableErase:S=!0,enableClear:re=!0,signatureFields:J=[],textFields:D=[],onSignatureComplete:ie,onSignatureFieldsChange:be,onFieldValueComplete:je,openSignaturePad:de=!1,onSignaturePadClose:ge,onSubmit:X,submitLabel:st="Submit"}){const Ee=d.useRef(null),Ce=d.useRef(null),Be=d.useRef(new Map),Te=d.useRef(!1),H=d.useMemo(()=>e&&typeof e!="string"?e:null,[e]),he=d.useMemo(()=>H?"":hr(typeof e=="string"?e:void 0,t,n),[H,e,t,n]),[ue,Se]=d.useState("idle"),[W,$e]=d.useState(null),[p,_]=d.useState(0),[$,ee]=d.useState(1),[q,me]=d.useState(c),[se,ke]=d.useState(0),[we,Fe]=d.useState(null),[ze,Oe]=d.useState(!1),[Re,He]=d.useState(!1),[Tt,a]=d.useState(!1),[w,y]=d.useState("none"),[j,O]=d.useState([]),[k,R]=d.useState([]),[F,G]=d.useState([]),[te,T]=d.useState(!1),[oe,ce]=d.useState(void 0),[le,ye]=d.useState(null),[De,ae]=d.useState(null),[xe,Ie]=d.useState(null),[We,Ue]=d.useState(null),[ot,Xe]=d.useState(null),[yt,Ze]=d.useState(null),[bt,xt]=d.useState(null),[pn,Qn]=d.useState(Rn),[gn,Jn]=d.useState(Ri),at=D.length>0,[Je,ei]=d.useState({}),[Y,mn]=d.useState(J),_t=d.useRef(Y);_t.current=Y,d.useEffect(()=>{_t.current=J,mn(J)},[J]);const Le=Y.length>0,ct=d.useCallback((f,u)=>{const h=_t.current,b=f?h.map(I=>I.id===f?{...I,signatureDataUrl:u.imageDataUrl}:I):[...h,{id:u.id,pageNumber:u.pageNumber,x:u.x,y:u.y,width:u.width,height:u.height,type:"sign",signatureDataUrl:u.imageDataUrl}];_t.current=b,mn(b),be==null||be(b),ie==null||ie(f,u)},[ie,be]);d.useEffect(()=>{de&&T(!0)},[de]);const Ke=d.useMemo(()=>Mr(m,{enableThumbnails:P,enableNavigation:N,enableZoom:U,enableRotate:E,enableReload:B,enablePrint:A,enableOpen:C,enableDownload:K,enableHighlight:z,enableUnderline:ne,enableSignature:_e,enableText:pe,enableErase:S,enableClear:re}),[m,P,N,U,E,B,A,C,K,z,ne,_e,pe,S,re]),Ve=d.useMemo(()=>Ke?new Set([...Ke.left,...Ke.right]):new Set,[Ke]);d.useEffect(()=>{if(!Ve.has("thumbnail")){Oe(!1);return}const u=window.matchMedia("(max-width: 720px)"),h=()=>{Oe(u.matches?!1:l)};return h(),u.addEventListener("change",h),()=>u.removeEventListener("change",h)},[Ve,l]);const wn=!Le&&Ve.has("highlight"),yn=!Le&&Ve.has("underline"),$t=Ve.has("signature")||Le,bn=Ve.has("text")||at,xn=!Le&&Ve.has("erase"),lt=d.useCallback(()=>{Ce.current&&(URL.revokeObjectURL(Ce.current),Ce.current=null)},[]),Rt=d.useCallback(async()=>{if(!(!H&&!he)){dr(v),Se("loading"),$e(null),_(0),ee(1),O([]),R([]),G([]),ye(null),ae(null),Ie(null),Ue(null),Xe(null),Ze(null),xt(null),y("none");try{const f=H?await Mn(H,i):await Mn(he,i),u=new Blob([f],{type:"application/pdf"}),h=URL.createObjectURL(u);lt(),Ce.current=h,Fe(h);const I=await rt.getDocument({data:f,cMapUrl:`https://unpkg.com/pdfjs-dist@${rt.version}/cmaps/`,cMapPacked:!0,standardFontDataUrl:`https://unpkg.com/pdfjs-dist@${rt.version}/standard_fonts/`}).promise;$e(I),_(I.numPages),Se("ready")}catch{Se("error")}}},[H,he,i,lt,v]);d.useEffect(()=>{if(!H&&!he){Se("idle"),$e(null),_(0),Fe(null),lt();return}return Rt(),()=>{lt()}},[H,he,Rt,lt]),d.useEffect(()=>{(w==="highlight"&&!wn||w==="underline"&&!yn||w==="sign"&&!$t||w==="text"&&!bn||w==="erase"&&!xn)&&y("none")},[wn,yn,$t,bn,xn,w]);const et=d.useCallback(f=>{const u=Math.max(1,Math.min(p||1,f)),h=Be.current.get(u);if(!h){ee(u);return}Te.current=!0,h.scrollIntoView({behavior:"smooth",block:"start"}),ee(u),window.setTimeout(()=>{Te.current=!1},500)},[p]),tt=d.useCallback(f=>{const u=Be.current.get(f.pageNumber);u&&(Te.current=!0,ee(f.pageNumber));const h=()=>{var I;const b=(I=Ee.current)==null?void 0:I.querySelector(`[data-signature-field-id="${CSS.escape(f.id)}"]`);b?b.scrollIntoView({behavior:"smooth",block:"center"}):u&&u.scrollIntoView({behavior:"smooth",block:"start"}),window.setTimeout(()=>{Te.current=!1},500)};window.requestAnimationFrame(()=>{window.setTimeout(h,40)})},[]);d.useEffect(()=>{if(ue!=="ready"||!Ee.current||!p)return;const f=Ee.current,u=new IntersectionObserver(h=>{if(Te.current)return;let b=null;for(const I of h){if(!I.isIntersecting)continue;const L=Number.parseInt(I.target.dataset.pageNumber||"0",10);L&&(!b||I.intersectionRatio>b.ratio)&&(b={page:L,ratio:I.intersectionRatio})}b&&ee(b.page)},{root:f,threshold:[.25,.5,.75]});for(let h=1;h<=p;h+=1){const b=Be.current.get(h);b&&u.observe(b)}return()=>u.disconnect()},[ue,p]);const It=$>1,Lt=p?$<p:!1,ti=d.useCallback(()=>{It&&et($-1)},[It,$,et]),ni=d.useCallback(()=>{Lt&&et($+1)},[Lt,$,et]),ii=d.useCallback(()=>{ke(f=>(f+90)%360)},[]),ri=d.useCallback(()=>{me(f=>Math.max(.25,Math.round((f-.1)*100)/100))},[]),si=d.useCallback(()=>{me(f=>Math.min(5,Math.round((f+.1)*100)/100))},[]),St=d.useCallback(async()=>{if(!(!W||!Ee.current))try{const u=(await W.getPage($)).getViewport({scale:1,rotation:se}),b=window.matchMedia("(max-width: 720px)").matches?16:24,L=Math.max(0,Ee.current.clientWidth-b)/u.width;me(Math.max(.25,Math.min(5,Math.round(L*100)/100)))}catch{}},[W,$,se]);d.useEffect(()=>{if(ue!=="ready"||!W||!window.matchMedia("(max-width: 720px)").matches)return;let f=!1;const u=()=>{f||St()};u();const h=Ee.current,b=typeof ResizeObserver<"u"&&h?new ResizeObserver(()=>u()):null;b==null||b.observe(h);const I=window.matchMedia("(max-width: 720px)"),L=()=>{I.matches&&u()};return I.addEventListener("change",L),()=>{f=!0,b==null||b.disconnect(),I.removeEventListener("change",L)}},[ue,W,ze,se,St]);const oi=d.useCallback(async()=>{var f;if(!(!W||ue!=="ready")){He(!0);try{const u=await Pn(W,{scale:1.5,rotation:se,annotations:j,signatures:k,texts:F,mimeType:"image/png"}),h=document.createElement("iframe");h.style.position="fixed",h.style.right="0",h.style.bottom="0",h.style.width="0",h.style.height="0",h.style.border="0",h.setAttribute("aria-hidden","true"),document.body.appendChild(h);const b=(f=h.contentWindow)==null?void 0:f.document;if(!b)throw new Error("print iframe not available");b.open(),b.write(`<!doctype html>
16
+ `);u.push(k,e[b],C),m+=k.byteLength+e[b].byteLength+C.byteLength}const _=m;let y=`xref
17
+ 0 ${e.length+1}
18
+ `;y+=`0000000000 65535 f
19
+ `;for(let b=1;b<=e.length;b+=1)y+=`${String(w[b]).padStart(10,"0")} 00000 n
20
+ `;return y+=`trailer
21
+ << /Size ${e.length+1} /Root ${d} 0 R >>
22
+ `,y+=`startxref
23
+ ${_}
24
+ %%EOF`,u.push(Xt(y)),Hn(...u)}function Je(t,e){const n=URL.createObjectURL(t),i=document.createElement("a");i.href=n,i.download=e,i.click(),URL.revokeObjectURL(n)}const Pe=[{id:"dancing-script",label:"Dancing Script",family:"Dancing Script"},{id:"great-vibes",label:"Great Vibes",family:"Great Vibes"},{id:"pacifico",label:"Pacifico",family:"Pacifico"},{id:"satisfy",label:"Satisfy",family:"Satisfy"},{id:"allura",label:"Allura",family:"Allura"}],Ts="https://fonts.googleapis.com/css2?family=Allura&family=Dancing+Script:wght@500;600&family=Great+Vibes&family=Pacifico&family=Satisfy&display=swap";let Le=null;function Rs(){return typeof document>"u"?Promise.resolve():Le||(Le=new Promise(t=>{var i;if(!document.querySelector('link[data-epochs-signature-fonts="true"]')){const r=document.createElement("link");r.rel="stylesheet",r.href=Ts,r.dataset.epochsSignatureFonts="true",document.head.appendChild(r)}const n=()=>Promise.all(Pe.map(r=>document.fonts.load(`48px "${r.family}"`))).then(()=>{});(i=document.fonts)!=null&&i.ready?document.fonts.ready.then(n).then(t).catch(()=>t()):window.setTimeout(()=>{n().then(t).catch(()=>t())},300)}),Le)}function On(t,e){return t==="initials"?72:e==="Great Vibes"||e==="Allura"?56:e==="Pacifico"?44:48}function Ls({open:t,onClose:e,onSave:n,onSaveFieldValue:i,fieldType:r,showFieldTypeTabs:o=!1,textPlaceholder:d,initialFieldValue:u,rememberedByType:w,onRememberFill:m}){const _=f.useRef(null),y=f.useRef(!1),b=f.useRef(null),k=f.useRef([]),C=f.useRef([]),H=f.useRef(null),A=r??"sign",[L,Z]=f.useState(A),[T,rt]=f.useState(""),[ot,Y]=f.useState(""),[Q,wt]=f.useState("draw"),[yt,q]=f.useState(""),[Pt,ft]=f.useState(""),[U,tt]=f.useState(!1),[et,bt]=f.useState("signature"),[V,Vt]=f.useState("#111827"),[dt,qt]=f.useState("dancing-script"),[Ce,At]=f.useState(!1),[Gt,Ct]=f.useState(!1),z=Pe.find(p=>p.id===dt)??Pe[0],jt=et==="initials"?Pt.trim():yt.trim(),$t=jt||(et==="initials"?"AB":"Signature");if(f.useEffect(()=>{var G,K;if(!t)return;if(Z(A),A==="date"){rt(u||((G=w==null?void 0:w.date)==null?void 0:G.value)||new Date().toISOString().slice(0,10));return}if(A==="text"){Y(u||((K=w==null?void 0:w.text)==null?void 0:K.value)||"");return}const p=w==null?void 0:w.sign;if(!p){wt("draw"),q(""),ft(""),tt(!1),bt("signature"),Vt("#111827"),qt("dancing-script"),H.current=null,Ct(!1);return}wt(p.mode),q(p.typedName??""),ft(p.typedInitials??""),tt(!!p.typedInitials),bt(p.typeKind??"signature"),Vt(p.inkColor??"#111827");const I=Pe.find(Mt=>Mt.id===p.fontId);I&&qt(I.id),p.mode==="draw"?(H.current={imageDataUrl:p.imageDataUrl,width:p.width,height:p.height},Ct(!0)):(H.current=null,Ct(!1))},[t,A,w,u]),f.useEffect(()=>{if(!t||L!=="sign")return;const p=_.current;if(!p)return;const I=p.getContext("2d");if(!I||(p.width=560,p.height=200,I.fillStyle="#ffffff",I.fillRect(0,0,p.width,p.height),I.lineCap="round",I.lineJoin="round",I.strokeStyle=V,I.lineWidth=2.5,b.current=null,y.current=!1,k.current=[],C.current=[],Q!=="draw"))return;const G=H.current;if(!(G!=null&&G.imageDataUrl))return;const K=new Image;K.onload=()=>{const Mt=Math.min(p.width/Math.max(1,G.width),p.height/Math.max(1,G.height),1),zt=G.width*Mt,Bt=G.height*Mt;I.drawImage(K,(p.width-zt)/2,(p.height-Bt)/2,zt,Bt)},K.src=G.imageDataUrl},[t,L,Q]),f.useEffect(()=>{if(!t)return;let p=!1;return At(!1),Rs().then(()=>{p||At(!0)}),()=>{p=!0}},[t]),f.useEffect(()=>{const p=_.current,I=p==null?void 0:p.getContext("2d");I&&(I.strokeStyle=V,I.fillStyle=V)},[V]),f.useEffect(()=>{if(!t||Q!=="type")return;const p=_.current,I=p==null?void 0:p.getContext("2d");if(!p||!I||(I.fillStyle="#ffffff",I.fillRect(0,0,p.width,p.height),!jt))return;const G=On(et,z.family);I.fillStyle=V,I.textAlign="center",I.textBaseline="middle",I.font=`${G}px "${z.family}", cursive`,I.fillText(jt,p.width/2,p.height/2)},[jt,et,Q,V,t,z,Ce]),!t)return null;const pt=p=>{const I=_.current,G=I.getBoundingClientRect();return{x:(p.clientX-G.left)/G.width*I.width,y:(p.clientY-G.top)/G.height*I.height}},at=p=>{if(Q!=="draw")return;if(H.current){H.current=null,Ct(!1);const G=_.current,K=G==null?void 0:G.getContext("2d");G&&K&&(K.fillStyle="#ffffff",K.fillRect(0,0,G.width,G.height),K.strokeStyle=V,K.lineWidth=2.5,K.lineCap="round",K.lineJoin="round"),k.current=[]}p.currentTarget.setPointerCapture(p.pointerId),y.current=!0;const I=pt(p);b.current=I,C.current=[I]},Dt=p=>{if(!y.current||Q!=="draw")return;const I=_.current,G=I==null?void 0:I.getContext("2d"),K=b.current;if(!G||!K)return;const Mt=pt(p);G.beginPath(),G.moveTo(K.x,K.y),G.lineTo(Mt.x,Mt.y),G.stroke(),b.current=Mt,C.current.push(Mt)},nt=()=>{C.current.length>1&&k.current.push([...C.current]),C.current=[],y.current=!1,b.current=null},gt=()=>{const p=_.current,I=p==null?void 0:p.getContext("2d");!p||!I||(I.fillStyle="#ffffff",I.fillRect(0,0,p.width,p.height),k.current=[],C.current=[],H.current=null,Ct(!1),q(""),ft(""),tt(!1))},kt=p=>{q(p),U||ft(Ds(p))},Yt=()=>{if(Q==="draw"){const N=k.current,S=H.current;if(N.length===0){if(!S)return;m==null||m("sign",{mode:"draw",imageDataUrl:S.imageDataUrl,width:S.width,height:S.height,inkColor:V}),n(S.imageDataUrl,S.width,S.height);return}let B=1/0,R=1/0,it=-1/0,W=-1/0;for(const Ut of N)for(const lt of Ut)lt.x<B&&(B=lt.x),lt.y<R&&(R=lt.y),lt.x>it&&(it=lt.x),lt.y>W&&(W=lt.y);const ct=8;B=Math.max(0,B-ct),R=Math.max(0,R-ct),it+=ct,W+=ct;const xt=it-B,It=W-R,Ft=N.map(Ut=>"M"+Ut.map(ut=>({x:ut.x-B,y:ut.y-R})).map(ut=>`${ut.x.toFixed(1)},${ut.y.toFixed(1)}`).join("L")).join(" "),Wt=`<svg xmlns="http://www.w3.org/2000/svg" width="${xt.toFixed(0)}" height="${It.toFixed(0)}" viewBox="0 0 ${xt.toFixed(0)} ${It.toFixed(0)}"><path d="${Ft}" fill="none" stroke="${V}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,Tt=`data:image/svg+xml;base64,${btoa(Wt)}`;m==null||m("sign",{mode:"draw",imageDataUrl:Tt,width:xt,height:It,inkColor:V}),n(Tt,xt,It);return}if(!jt)return;const p=3,I=On(et,z.family),K=document.createElement("canvas").getContext("2d");K.font=`${I*p}px "${z.family}", cursive`;const Mt=K.measureText(jt),zt=12*p,Bt=Math.ceil(Mt.width)+zt*2,Jt=I*p+zt*2,a=document.createElement("canvas");a.width=Bt,a.height=Jt;const x=a.getContext("2d");x.clearRect(0,0,Bt,Jt),x.font=`${I*p}px "${z.family}", cursive`,x.fillStyle=V,x.textBaseline="middle",x.fillText(jt,zt,Jt/2);const v=a.toDataURL("image/png"),j=Bt/p,D=Jt/p,P=`<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"><image href="${v}"/></svg>`,F=`data:image/svg+xml;base64,${btoa(P)}`;m==null||m("sign",{mode:"type",imageDataUrl:F,width:j,height:D,typedName:yt,typedInitials:Pt,fontId:dt,inkColor:V,typeKind:et}),n(F,j,D)},ht=()=>{if(L!=="date"&&L!=="text")return;const p=L==="date"?T:ot.trim();p&&(m==null||m(L,{value:p}),i==null||i(p,L))},Ot=L==="sign",Nt=L==="date"?"Pick a date":L==="text"?"Enter text":"Create e-signature";return s.jsxs("div",{className:"epochs-pdf-viewer__modal",role:"dialog","aria-modal":"true",children:[s.jsx("div",{className:"epochs-pdf-viewer__modal-backdrop",onClick:e}),s.jsxs("div",{className:"epochs-pdf-viewer__modal-card",children:[s.jsxs("div",{className:"epochs-pdf-viewer__modal-header",children:[s.jsx("h3",{children:Nt}),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e,title:"Close",children:"×"})]}),o&&!r?s.jsx("div",{className:"epochs-pdf-viewer__field-type-tabs",role:"tablist",children:["sign","date","text"].map(p=>s.jsx("button",{type:"button",role:"tab","aria-selected":L===p,className:L===p?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>Z(p),children:p==="sign"?"Sign":p==="date"?"Date":"Text"},p))}):null,Ot?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"epochs-pdf-viewer__sign-modes",children:[s.jsx("button",{type:"button",className:Q==="draw"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>{wt("draw"),gt()},children:"Draw"}),s.jsx("button",{type:"button",className:Q==="type"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>wt("type"),children:"Type"}),s.jsxs("label",{className:"epochs-pdf-viewer__sign-ink",children:["Ink",s.jsx("input",{type:"color",value:V,onChange:p=>Vt(p.target.value)})]})]}),Q==="type"?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"epochs-pdf-viewer__sign-fonts",role:"group","aria-label":"Handwriting style",children:Pe.map(p=>s.jsx("button",{type:"button",className:dt===p.id?"epochs-pdf-viewer__sign-font epochs-pdf-viewer__sign-font--active":"epochs-pdf-viewer__sign-font",style:{fontFamily:`"${p.family}", cursive`},onClick:()=>qt(p.id),title:p.label,children:$t},p.id))}),s.jsxs("div",{className:"epochs-pdf-viewer__sign-type-fields",children:[s.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",children:[s.jsx("span",{children:"Full name"}),s.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:yt,onChange:p=>kt(p.target.value),onFocus:()=>bt("signature"),placeholder:"Type your full name",style:{fontFamily:`"${z.family}", cursive`},autoFocus:!0})]}),s.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",children:[s.jsx("span",{children:"Initials"}),s.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:Pt,onChange:p=>{tt(!0),ft(p.target.value.toUpperCase())},onFocus:()=>bt("initials"),placeholder:"e.g. JD",maxLength:4,style:{fontFamily:`"${z.family}", cursive`}})]})]}),s.jsxs("div",{className:"epochs-pdf-viewer__sign-type-kind",role:"group","aria-label":"Preview type",children:[s.jsx("button",{type:"button",className:et==="signature"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>bt("signature"),children:"Use full name"}),s.jsx("button",{type:"button",className:et==="initials"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>bt("initials"),children:"Use initials"})]})]}):s.jsx("p",{className:"epochs-pdf-viewer__sign-hint",children:Gt?"Previous signature loaded — submit to reuse, or draw a new one":"Draw your signature below"}),s.jsx("canvas",{ref:_,className:Q==="draw"?"epochs-pdf-viewer__sign-canvas":"epochs-pdf-viewer__sign-canvas epochs-pdf-viewer__sign-canvas--preview",onPointerDown:at,onPointerMove:Dt,onPointerUp:nt,onPointerLeave:nt})]}):L==="date"?s.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",style:{padding:"1rem"},children:[s.jsx("span",{children:"Date"}),s.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"date",value:T,onChange:p=>rt(p.target.value),autoFocus:!0})]}):s.jsxs("label",{className:"epochs-pdf-viewer__sign-type-field",style:{padding:"1rem"},children:[s.jsx("span",{children:"Text"}),s.jsx("input",{className:"epochs-pdf-viewer__sign-type-input",type:"text",value:ot,onChange:p=>Y(p.target.value),placeholder:d??"Enter text",autoFocus:!0})]}),s.jsxs("div",{className:"epochs-pdf-viewer__modal-actions",children:[Ot?s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:gt,children:"Clear"}):null,s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:e,children:"Cancel"}),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:Ot?Yt:ht,disabled:L==="date"?!T:L==="text"?!ot.trim():!1,children:Ot?"Use signature":"Place on page"})]})]})]})}function Ds(t){const e=t.trim().split(/\s+/).filter(Boolean);return e.length===0?"":e.length===1?e[0].slice(0,2).toUpperCase():e.slice(0,3).map(n=>{var i;return((i=n[0])==null?void 0:i.toUpperCase())??""}).join("")}const Ee="__epochsToolbarToolId";function Et(t,e){const n=(()=>null);return n.displayName=e,Object.defineProperty(n,Ee,{value:t,enumerable:!0}),n}function zn(t){return t[Ee]}function Fs(t){return typeof t=="function"&&Ee in t&&typeof t[Ee]=="string"}const an=Et("thumbnail","Thumbnail"),cn=Et("navigation","Navigation"),ln=Et("zoom","Zoom"),dn=Et("rotate","Rotate"),hn=Et("reload","Reload"),un=Et("print","Print"),fn=Et("open","Open"),pn=Et("download","Download"),gn=Et("highlight","Highlight"),mn=Et("underline","Underline"),wn=Et("signature","Signature"),xn=Et("text","AddText"),bn=Et("erase","Erase"),yn=Et("clear","Clear"),Ss=[an,cn,ln,dn,gn,mn,wn,xn,bn,yn,hn,un,fn,pn],en=[[an,cn],[ln,dn,gn,mn,wn,xn,bn,yn,hn,un,fn,pn]],Es=["highlight","underline","signature","text","erase","clear"];function Bn(t){return Es.includes(t)}function As(t,e,n){const i=[];switch(n!=null&&n.showMarkupSep&&i.push(s.jsx("span",{className:"epochs-pdf-viewer__toolbar-sep","aria-hidden":"true"},`${t}-sep`)),t){case"thumbnail":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>e.setShowThumbnails(r=>!r),title:e.showThumbnails?"Hide thumbnails":"Show thumbnails",children:s.jsx(ds,{})},"thumbnail"));break;case"navigation":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e.handlePrev,disabled:!e.canGoPrev||e.status!=="ready",title:"Previous page",children:s.jsx(os,{})},"nav-prev"),s.jsxs("div",{className:"epochs-pdf-viewer__page-input",children:[s.jsx("input",{type:"number",value:e.pageNumber,min:1,max:e.numPages||1,onChange:r=>{const o=Number.parseInt(r.target.value,10);Number.isFinite(o)&&e.scrollToPage(Math.max(1,Math.min(e.numPages||1,o)))},disabled:e.status!=="ready","aria-label":"Page number"}),s.jsxs("span",{children:["/ ",e.numPages||"-"]})]},"nav-page"),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e.handleNext,disabled:!e.canGoNext||e.status!=="ready",title:"Next page",children:s.jsx(as,{})},"nav-next"));break;case"zoom":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e.handleZoomOut,disabled:e.status!=="ready",title:"Zoom out",children:s.jsx(hs,{})},"zoom-out"),s.jsxs("span",{className:"epochs-pdf-viewer__zoom-label",children:[Math.round(e.scale*100),"%"]},"zoom-label"),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e.handleZoomIn,disabled:e.status!=="ready",title:"Zoom in",children:s.jsx(us,{})},"zoom-in"),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>void e.handleFitWidth(),disabled:e.status!=="ready",title:"Fit to width",children:"Fit"},"zoom-fit"));break;case"rotate":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:e.handleRotate,disabled:e.status!=="ready",title:"Rotate",children:s.jsx(gs,{})},"rotate"));break;case"highlight":i.push(s.jsx("button",{type:"button",className:e.markupTool==="highlight"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>e.toggleMarkupTool("highlight"),disabled:e.status!=="ready",title:"Highlight text — select text to highlight",children:s.jsx(ms,{})},"highlight"));break;case"underline":i.push(s.jsx("button",{type:"button",className:e.markupTool==="underline"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>e.toggleMarkupTool("underline"),disabled:e.status!=="ready",title:"Underline text — select text to underline",children:s.jsx(ws,{})},"underline"));break;case"signature":i.push(s.jsx("button",{type:"button",className:e.markupTool==="sign"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>{if(!e.hasFixedSignatureFields&&e.pendingSignature&&e.markupTool!=="sign"){e.setMarkupTool("sign");return}e.setSignaturePadOpen(!0)},disabled:e.status!=="ready",title:e.hasFixedSignatureFields?"Create e-signature for a fixed field":e.pendingSignature?"Place signature — click on the page, then drag to move":"Create e-signature",children:s.jsx(bs,{})},"signature"));break;case"text":i.push(s.jsx("button",{type:"button",className:e.markupTool==="text"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>e.toggleMarkupTool("text"),disabled:e.status!=="ready",title:e.hasFixedTextFields?"Edit text in predefined areas — click to type":"Edit PDF text — select words, then change them",children:s.jsx(_s,{})},"text"));break;case"erase":i.push(s.jsx("button",{type:"button",className:e.markupTool==="erase"?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn",onClick:()=>e.toggleMarkupTool("erase"),disabled:e.status!=="ready",title:"Remove text — select PDF words to cover them, or click added markup",children:s.jsx(xs,{})},"erase"));break;case"clear":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:e.handleClearAnnotations,disabled:e.status!=="ready"||e.annotationsLength===0&&e.signaturesLength===0&&e.textsLength===0,title:"Clear all markup",children:"Clear"},"clear"));break;case"reload":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void e.loadDocument(),title:"Reload",children:s.jsx(ps,{})},"reload"));break;case"print":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void e.handlePrint(),disabled:e.status!=="ready"||!e.pdfDoc||e.isPrinting,title:e.isPrinting?"Preparing print…":"Print (includes highlights & underlines)",children:s.jsx(fs,{})},"print"));break;case"open":i.push(s.jsx("a",{className:"epochs-pdf-viewer__btn",href:e.displayUrl||e.resolvedUrl||void 0,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:s.jsx(ls,{})},"open"));break;case"download":i.push(s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn",onClick:()=>void e.handleDownload(),disabled:e.status!=="ready"||!e.pdfDoc||e.isDownloading,title:e.isDownloading?"Preparing download…":e.annotationsLength>0||e.signaturesLength>0||e.textsLength>0?"Download PDF with markup":"Download PDF",children:s.jsx(cs,{})},"download"));break}return i.length>0?i:null}function Us(t,e){const n=[];if(t.markupTool==="sign"&&t.pendingSignature&&!t.hasFixedSignatureFields&&e.has("signature")&&n.push(s.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:"Click page to place duplicate/new signature"},"sign-hint")),t.markupTool==="text"&&e.has("text")&&n.push(s.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:t.hasFixedTextFields?"Click in a predefined text area to type":"Select text to edit it — e.g. change this PDF to this is PDF"},"text-hint")),t.markupTool==="erase"&&e.has("erase")&&n.push(s.jsx("span",{className:"epochs-pdf-viewer__markup-hint",children:"Select PDF words to remove · click added text/markup to erase"},"erase-hint")),t.markupTool==="highlight"&&e.has("highlight")||t.markupTool==="underline"&&e.has("underline")){const i=t.markupTool==="highlight"?t.highlightHex:t.underlineHex,r=t.markupTool==="highlight"?t.setHighlightHex:t.setUnderlineHex,o=t.markupTool==="highlight"?sn:rn;n.push(s.jsxs("div",{className:"epochs-pdf-viewer__color-picker",role:"group","aria-label":`${t.markupTool} color`,children:[o.map(d=>s.jsx("button",{type:"button",className:ee(i)===ee(d.hex)?"epochs-pdf-viewer__swatch epochs-pdf-viewer__swatch--active":"epochs-pdf-viewer__swatch",style:{background:d.hex},title:d.label,"aria-label":d.label,"aria-pressed":ee(i)===ee(d.hex),onClick:()=>r(ee(d.hex))},d.id)),s.jsxs("label",{className:"epochs-pdf-viewer__custom-color",title:"Custom color",children:[s.jsx("span",{className:"epochs-pdf-viewer__custom-color-chip",style:{background:i}}),s.jsx("input",{type:"color",value:ee(i),onChange:d=>r(ee(d.target.value)),"aria-label":"Custom color"})]})]},"color-picker"))}return n.length>0?n:null}function Hs(t,e){if(!t)return null;if(Array.isArray(t)){const o=d=>(d??[]).filter(Fs).map(zn);return{left:o(t[0]),right:o(t[1])}}const n=e.enableThumbnails,i=(o,d)=>o.map(zn).filter(u=>d[u]!==!1),r={thumbnail:n,navigation:e.enableNavigation,zoom:e.enableZoom,rotate:e.enableRotate,reload:e.enableReload,print:e.enablePrint,open:e.enableOpen,download:e.enableDownload,highlight:e.enableHighlight,underline:e.enableUnderline,signature:e.enableSignature,text:e.enableText,erase:e.enableErase,clear:e.enableClear};return{left:i(en[0],r),right:i(en[1],r)}}function Kn({file:t,fileUrl:e,baseUrl:n="",fetchOptions:i,height:r="80vh",title:o="PDF document",initialScale:d=1,withThumbnails:u=!1,thumbnailWidth:w=140,maxThumbnails:m=60,className:_,workerSrc:y,enableToolbar:b=!1,enableThumbnails:k,enableNavigation:C=!0,enableZoom:H=!0,enableRotate:A=!0,enableReload:L=!0,enablePrint:Z=!0,enableOpen:T=!0,enableDownload:rt=!0,enableMarkup:ot=!0,enableHighlight:Y=!0,enableUnderline:Q=!0,enableSignature:wt=!0,enableText:yt=!0,enableErase:q=!0,enableClear:Pt=!0,signatureFields:ft=[],textFields:U=[],onSignatureComplete:tt,onSignatureFieldsChange:et,applySignatureToSameTag:bt=!1,onFieldValueComplete:V,openSignaturePad:Vt=!1,onSignaturePadClose:dt,onSubmit:qt,submitLabel:Ce="Submit",submitLoading:At=!1}){var Dn,Fn;const Gt=f.useRef(null),Ct=f.useRef(null),z=f.useRef(new Map),jt=f.useRef(!1),$t=f.useMemo(()=>t&&typeof t!="string"?t:null,[t]),pt=f.useMemo(()=>$t?"":Ns(typeof t=="string"?t:void 0,e,n),[$t,t,e,n]),[at,Dt]=f.useState("idle"),[nt,gt]=f.useState(null),[kt,Yt]=f.useState(0),[ht,Ot]=f.useState(1),[Nt,p]=f.useState(d),[I,G]=f.useState(0),[K,Mt]=f.useState(null),[zt,Bt]=f.useState(!1),[Jt,a]=f.useState(!1),[x,v]=f.useState(!1),[j,D]=f.useState("none"),[P,F]=f.useState([]),[N,S]=f.useState([]),[B,R]=f.useState([]),[it,W]=f.useState(!1),[ct,xt]=f.useState(void 0),[It,Ft]=f.useState({}),[Wt,Tt]=f.useState(null),[Ut,lt]=f.useState(null),[ut,Kt]=f.useState(null),[ce,Zt]=f.useState(null),[$e,le]=f.useState(null),[ui,xe]=f.useState(null),[fi,Ie]=f.useState(null),[jn,pi]=f.useState(Gn),[kn,gi]=f.useState(Vi),be=U.length>0,[Ht,Ae]=f.useState({}),[E,Ue]=f.useState(ft),de=f.useRef(E);de.current=E,f.useEffect(()=>{de.current=ft,Ue(ft),Ae(c=>{const h={...c};for(const l of ft){const g=l.type??"sign";(g==="date"||g==="text")&&l.value!=null&&l.value!==""&&(h[l.id]=l.value)}return h})},[ft]);const Rt=E.length>0,ye=f.useCallback((c,h,l)=>{var M;const g=c.type??"sign";return g==="date"||g==="text"?!!((M=l[c.id]??c.value)!=null&&M.trim()):h.some($=>$.fieldId===c.id)||!!c.signatureDataUrl},[]),Mn=f.useCallback((c,h)=>{const l=new Set(c),M=de.current.map($=>l.has($.id)?{...$,value:h}:$);de.current=M,Ue(M),et==null||et(M),Ae($=>{const O={...$};for(const st of c)O[st]=h;return O});for(const $ of c)V==null||V($,h)},[V,et]),_e=f.useCallback((c,h,l)=>{const g=de.current,M=c==null?null:Array.isArray(c)?c:[c],$=M?new Set(M):null,O=$?g.map(st=>$.has(st.id)?{...st,signatureDataUrl:h.imageDataUrl}:st):[...g,{id:h.id,pageNumber:h.pageNumber,x:h.x,y:h.y,width:h.width,height:h.height,type:"sign",signatureDataUrl:h.imageDataUrl}];if(de.current=O,Ue(O),et==null||et(O),!M||M.length===0){tt==null||tt(void 0,h);return}for(const st of M)tt==null||tt(st,(l==null?void 0:l.get(st))??h)},[tt,et]);f.useEffect(()=>{Vt&&W(!0)},[Vt]);const ne=f.useMemo(()=>Hs(b,{enableThumbnails:k,enableNavigation:C,enableZoom:H,enableRotate:A,enableReload:L,enablePrint:Z,enableOpen:T,enableDownload:rt,enableHighlight:Y,enableUnderline:Q,enableSignature:wt,enableText:yt,enableErase:q,enableClear:Pt}),[b,k,C,H,A,L,Z,T,rt,Y,Q,wt,yt,q,Pt]),ie=f.useMemo(()=>ne?new Set([...ne.left,...ne.right]):new Set,[ne]);f.useEffect(()=>{if(!ie.has("thumbnail")){Bt(!1);return}const h=window.matchMedia("(max-width: 720px)"),l=()=>{Bt(h.matches?!1:u)};return l(),h.addEventListener("change",l),()=>h.removeEventListener("change",l)},[ie,u]);const Nn=!Rt&&ie.has("highlight"),Pn=!Rt&&ie.has("underline"),He=ie.has("signature")||Rt,Cn=ie.has("text")||be,$n=!Rt&&ie.has("erase"),ve=f.useCallback(()=>{Ct.current&&(URL.revokeObjectURL(Ct.current),Ct.current=null)},[]),Oe=f.useCallback(async()=>{if(!(!$t&&!pt)){Ms(y),Dt("loading"),gt(null),Yt(0),Ot(1),F([]),S([]),R([]),Tt(null),lt(null),Kt(null),Zt(null),le(null),xe(null),Ie(null),D("none");try{const c=$t?await An($t,i):await An(pt,i),h=new Blob([c],{type:"application/pdf"}),l=URL.createObjectURL(h);ve(),Ct.current=l,Mt(l);const M=await me.getDocument({data:c,cMapUrl:`https://unpkg.com/pdfjs-dist@${me.version}/cmaps/`,cMapPacked:!0,standardFontDataUrl:`https://unpkg.com/pdfjs-dist@${me.version}/standard_fonts/`}).promise;gt(M),Yt(M.numPages),Dt("ready")}catch{Dt("error")}}},[$t,pt,i,ve,y]);f.useEffect(()=>{if(!$t&&!pt){Dt("idle"),gt(null),Yt(0),Mt(null),ve();return}return Oe(),()=>{ve()}},[$t,pt,Oe,ve]),f.useEffect(()=>{(j==="highlight"&&!Nn||j==="underline"&&!Pn||j==="sign"&&!He||j==="text"&&!Cn||j==="erase"&&!$n)&&D("none")},[Nn,Pn,He,Cn,$n,j]);const he=f.useCallback(c=>{const h=Math.max(1,Math.min(kt||1,c)),l=z.current.get(h);if(!l){Ot(h);return}jt.current=!0,l.scrollIntoView({behavior:"smooth",block:"start"}),Ot(h),window.setTimeout(()=>{jt.current=!1},500)},[kt]),ue=f.useCallback(c=>{const h=z.current.get(c.pageNumber);h&&(jt.current=!0,Ot(c.pageNumber));const l=()=>{var M;const g=(M=Gt.current)==null?void 0:M.querySelector(`[data-signature-field-id="${CSS.escape(c.id)}"]`);g?g.scrollIntoView({behavior:"smooth",block:"center"}):h&&h.scrollIntoView({behavior:"smooth",block:"start"}),window.setTimeout(()=>{jt.current=!1},500)};window.requestAnimationFrame(()=>{window.setTimeout(l,40)})},[]);f.useEffect(()=>{if(at!=="ready"||!Gt.current||!kt)return;const c=Gt.current,h=new IntersectionObserver(l=>{if(jt.current)return;let g=null;for(const M of l){if(!M.isIntersecting)continue;const $=Number.parseInt(M.target.dataset.pageNumber||"0",10);$&&(!g||M.intersectionRatio>g.ratio)&&(g={page:$,ratio:M.intersectionRatio})}g&&Ot(g.page)},{root:c,threshold:[.25,.5,.75]});for(let l=1;l<=kt;l+=1){const g=z.current.get(l);g&&h.observe(g)}return()=>h.disconnect()},[at,kt]);const ze=ht>1,Be=kt?ht<kt:!1,mi=f.useCallback(()=>{ze&&he(ht-1)},[ze,ht,he]),wi=f.useCallback(()=>{Be&&he(ht+1)},[Be,ht,he]),xi=f.useCallback(()=>{G(c=>(c+90)%360)},[]),bi=f.useCallback(()=>{p(c=>Math.max(.25,Math.round((c-.1)*100)/100))},[]),yi=f.useCallback(()=>{p(c=>Math.min(5,Math.round((c+.1)*100)/100))},[]),We=f.useCallback(async()=>{if(!(!nt||!Gt.current))try{const h=(await nt.getPage(ht)).getViewport({scale:1,rotation:I}),g=window.matchMedia("(max-width: 720px)").matches?16:24,$=Math.max(0,Gt.current.clientWidth-g)/h.width;p(Math.max(.25,Math.min(5,Math.round($*100)/100)))}catch{}},[nt,ht,I]);f.useEffect(()=>{if(at!=="ready"||!nt||!window.matchMedia("(max-width: 720px)").matches)return;let c=!1;const h=()=>{c||We()};h();const l=Gt.current,g=typeof ResizeObserver<"u"&&l?new ResizeObserver(()=>h()):null;g==null||g.observe(l);const M=window.matchMedia("(max-width: 720px)"),$=()=>{M.matches&&h()};return M.addEventListener("change",$),()=>{c=!0,g==null||g.disconnect(),M.removeEventListener("change",$)}},[at,nt,zt,I,We]);const In=f.useMemo(()=>E.flatMap(c=>{const h=c.type??"sign";if(h!=="date"&&h!=="text")return[];const l=(Ht[c.id]??c.value??"").trim();if(!l)return[];const g=Math.max(10,Math.min(ae,c.height*.55));return[{id:`fv_${c.id}`,pageNumber:c.pageNumber,fieldId:c.id,x:c.x+4,y:c.y+Math.max(2,(c.height-g)/2),width:Math.max(12,c.width-8),height:Math.max(g*1.2,c.height-4),value:l,fontSize:g,color:oe}]}),[E,Ht]),fe=f.useMemo(()=>[...B,...In],[B,In]),_i=f.useCallback(async()=>{var c;if(!(!nt||at!=="ready")){a(!0);try{const h=await Un(nt,{scale:1.5,rotation:I,annotations:P,signatures:N,texts:fe,mimeType:"image/png"}),l=document.createElement("iframe");l.style.position="fixed",l.style.right="0",l.style.bottom="0",l.style.width="0",l.style.height="0",l.style.border="0",l.setAttribute("aria-hidden","true"),document.body.appendChild(l);const g=(c=l.contentWindow)==null?void 0:c.document;if(!g)throw new Error("print iframe not available");g.open(),g.write(`<!doctype html>
25
25
  <html>
26
26
  <head>
27
27
  <meta charset="utf-8" />
@@ -35,21 +35,21 @@ ${M}
35
35
  </style>
36
36
  </head>
37
37
  <body></body>
38
- </html>`),b.close();const I=b.body;for(const L of u){const Z=b.createElement("img");Z.src=L.dataUrl;const Me=b.createElement("div");Me.className="page",Me.appendChild(Z),I.appendChild(Me)}await Promise.all(Array.from(I.querySelectorAll("img")).map(L=>{var Z;return((Z=L.decode)==null?void 0:Z.call(L).catch(()=>{}))??Promise.resolve()})),setTimeout(()=>{var L,Z;try{(L=h.contentWindow)==null||L.focus(),(Z=h.contentWindow)==null||Z.print()}finally{setTimeout(()=>{try{document.body.removeChild(h)}catch{}},1e3)}},50)}catch{try{we?window.open(we,"_blank","noopener,noreferrer"):he&&window.open(he,"_blank","noopener,noreferrer")}catch{}}finally{He(!1)}}},[W,ue,se,o,we,he,j,k,F]),ai=d.useCallback(async()=>{if(!W||ue!=="ready")return;const f=`${o.replace(/[^\w.-]+/g,"_")||"document"}.pdf`;if(!(j.length>0||k.length>0||F.length>0)&&we){Wt(await fetch(we).then(h=>h.blob()),f);return}a(!0);try{const h=await Pn(W,{scale:2,rotation:se,annotations:j,signatures:k,texts:F,mimeType:"image/jpeg",quality:.92}),b=gr(h),I=new Uint8Array(b.byteLength);I.set(b),Wt(new Blob([I],{type:"application/pdf"}),f)}catch{we&&Wt(await fetch(we).then(h=>h.blob()),f)}finally{a(!1)}},[W,ue,se,o,we,j,k,F]),ci=d.useCallback(f=>{y(u=>u===f?"none":f)},[]),li=w==="highlight"||w==="underline"?Kt(w==="highlight"?pn:w==="underline"?gn:null,w):void 0,nt=De!=null?k.find(f=>f.id===De)??null:null,di=d.useCallback(f=>{O(u=>[...u,f])},[]),hi=d.useCallback(f=>{O(u=>u.filter(h=>h.id!==f))},[]),ui=d.useCallback(()=>{O([]),R([]),G([]),ae(null),Xe(null),Ze(null),xt(null)},[]),fi=d.useCallback(f=>{ce(f),T(!0)},[]),pi=d.useCallback((f,u)=>{ei(h=>({...h,[f]:u}))},[]),gi=d.useCallback(f=>{const u=Je[f];u&&(je==null||je(f,u));const h=Y.findIndex(L=>L.id===f),b=new Set(Object.keys(Je).filter(L=>{var Z;return(Z=Je[L])==null?void 0:Z.trim()}));b.add(f);const I=Y.slice(h+1).find(L=>!b.has(L.id)&&!k.some(Z=>Z.fieldId===L.id))??Y.slice(0,Math.max(0,h)).find(L=>!b.has(L.id)&&!k.some(Z=>Z.fieldId===L.id));if(I){Ie(I.id),tt(I);const L=I.type;(L==="sign"||!L)&&window.setTimeout(()=>T(!0),350)}},[Y,Je,k,tt]),mi=d.useCallback((f,u,h)=>{const b=Si(u,h);if(We){R(V=>V.map(Pe=>Pe.id===We?{...Pe,imageDataUrl:f,width:Pe.fieldId?Pe.width:b.width,height:Pe.fieldId?Pe.height:b.height}:Pe)),ye(null),y("none"),T(!1),Ue(null);return}if(Le){const V=Y.find(fe=>fe.id===xe&&!k.some(Qe=>Qe.fieldId===fe.id))??Y.find(fe=>!k.some(Qe=>Qe.fieldId===fe.id));if(!V){T(!1);return}const Pe={id:Pt(),fieldId:V.id,pageNumber:V.pageNumber,x:V.x,y:V.y,width:V.width,height:V.height,imageDataUrl:f};R(fe=>[...fe.filter(Qe=>Qe.fieldId!==V.id),Pe]),ct(V.id,Pe),ye(null),y("none"),T(!1),Ue(null);const qe=new Set(k.filter(fe=>fe.fieldId&&fe.fieldId!==V.id).map(fe=>fe.fieldId));qe.add(V.id);const vt=Y.findIndex(fe=>fe.id===V.id),dt=Y.slice(vt+1).find(fe=>!qe.has(fe.id))??Y.slice(0,Math.max(0,vt)).find(fe=>!qe.has(fe.id));dt?(Ie(dt.id),ae(null),tt(dt),window.setTimeout(()=>{T(!0)},350)):(ae(Pe.id),Ie(V.id));return}const I=Be.current.get($),L=I==null?void 0:I.querySelector(".epochs-pdf-viewer__surface");let Z=24,Me=24;if(L){const V=mt(L,q),Pe=L.closest(".epochs-pdf-viewer__body");if(Pe){const qe=Di(Pe.getBoundingClientRect(),L,q),vt=Math.max(0,qe.top),dt=Math.min(V.height,qe.bottom),fe=Math.max(0,qe.left),Qe=Math.min(V.width,qe.right);Z=Math.max(0,(fe+Qe)/2-b.width/2),Me=Math.max(0,(vt+dt)/2-b.height/2),Z=Math.min(Z,Math.max(0,V.width-b.width)),Me=Math.min(Me,Math.max(0,V.height-b.height))}else Z=Math.max(0,(V.width-b.width)/2),Me=Math.max(0,(V.height-b.height)/2)}const Ge={id:Pt(),pageNumber:$,x:Z,y:Me,width:b.width,height:b.height,imageDataUrl:f};R(V=>[...V,Ge]),ct(void 0,Ge),ae(Ge.id),ye(null),y("none"),T(!1),Ue(null)},[We,Le,$,q,tt,xe,Y,k,ct]),wi=d.useCallback(f=>{R(u=>[...u,f]),ct(void 0,f),ae(f.id),ye(null),y("none")},[ct]),yi=d.useCallback((f,u)=>{R(h=>h.map(b=>b.id===f?{...b,...u}:b))},[]),bi=d.useCallback(f=>{const u=k.find(h=>h.id===f);R(h=>h.filter(b=>b.id!==f)),ae(h=>h===f?null:h),u!=null&&u.fieldId&&Ie(u.fieldId)},[k]),xi=d.useCallback(f=>{const u=f?k.find(Ge=>Ge.id===f)??null:nt;if(!u)return;const h=Be.current.get(u.pageNumber),b=h==null?void 0:h.querySelector(".epochs-pdf-viewer__surface"),I=18;let L=u.x+I,Z=u.y+I;if(b){const Ge=b.clientWidth/q,V=b.clientHeight/q;L=Math.min(Math.max(0,L),Math.max(0,Ge-u.width)),Z=Math.min(Math.max(0,Z),Math.max(0,V-u.height))}const Me={...u,id:Pt(),x:L,y:Z};R(Ge=>[...Ge,Me]),ae(Me.id),ye(null),y("none")},[q,nt,k]),_i=d.useCallback(f=>{const u=f??(nt==null?void 0:nt.id);u&&(ae(u),Ue(u),T(!0))},[nt]),vi=d.useCallback(f=>{G(u=>f.fieldId?[...u.filter(h=>h.fieldId!==f.fieldId),f]:[...u,f]),Xe(f.id),f.fieldId&&Ze(f.fieldId)},[]),ji=d.useCallback((f,u)=>{G(h=>h.map(b=>b.id===f?{...b,...u}:b))},[]),ki=d.useCallback(f=>{const u=F.find(h=>h.id===f);G(h=>h.filter(b=>b.id!==f)),Xe(h=>h===f?null:h),xt(h=>h===f?null:h),u!=null&&u.fieldId&&Ze(u.fieldId)},[F]);d.useEffect(()=>{at&&G(f=>f.map(u=>{if(!u.fieldId)return u;const h=D.find(b=>b.id===u.fieldId);return h?{...u,pageNumber:h.pageNumber,x:h.x,y:h.y,width:h.width,height:h.height,fontSize:h.fontSize??u.fontSize??wt,color:h.color??u.color??gt}:u}))},[at,D]);const _n=d.useCallback(f=>{var I;if(!Y.length)return;const u=xe!=null?Y.findIndex(L=>L.id===xe):-1,h=Math.min(Y.length-1,Math.max(0,(u<0?0:u)+f)),b=Y[h];b&&(Ie(b.id),ae(((I=k.find(L=>L.fieldId===b.id))==null?void 0:I.id)??null),tt(b))},[tt,xe,Y,k]);if(!H&&!he)return r.jsx("div",{"data-testid":"pdf-viewer",className:`epochs-pdf-viewer epochs-pdf-viewer--empty ${M??""}`.trim(),children:"No PDF file provided."});const Mi={height:s},vn={status:ue,showThumbnails:ze,setShowThumbnails:Oe,canGoPrev:It,canGoNext:Lt,handlePrev:ti,handleNext:ni,pageNumber:$,numPages:p,scrollToPage:et,scale:q,handleZoomOut:ri,handleZoomIn:si,handleFitWidth:St,handleRotate:ii,markupTool:w,toggleMarkupTool:f=>ci(f),hasFixedSignatureFields:Le,hasFixedTextFields:at,pendingSignature:le,setMarkupTool:y,setSignaturePadOpen:T,annotationsLength:j.length,signaturesLength:k.length,textsLength:F.length,handleClearAnnotations:ui,highlightHex:pn,underlineHex:gn,setHighlightHex:Qn,setUnderlineHex:Jn,loadDocument:Rt,handlePrint:oi,isPrinting:Re,pdfDoc:W,displayUrl:we,resolvedUrl:he,handleDownload:ai,isDownloading:Tt},Pi=f=>f.filter(u=>!(Le&&(u==="highlight"||u==="underline"||u==="erase"))),Ft=xe?Y.findIndex(f=>f.id===xe):0,Ni=Y.filter(f=>{var h;const u=f.type??"sign";return u==="date"||u==="text"?!!((h=Je[f.id])!=null&&h.trim()):k.some(b=>b.fieldId===f.id)}).length,Dt=Y.length>0?Math.round(Ni/Y.length*100):0,jn=(f,u=!1)=>{const h=Pi(f);if(h.length===0&&!u)return r.jsx("div",{className:"epochs-pdf-viewer__toolbar-group"});if(h.length===0)return r.jsx("div",{className:"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end"});const b=h.map((I,L)=>{const Z=h[L-1],Me=Tn(I)&&(!Z||!Tn(Z));return r.jsx(d.Fragment,{children:jr(I,vn,{showMarkupSep:Me})},I)});return r.jsxs("div",{className:u?"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end":"epochs-pdf-viewer__toolbar-group",children:[b,kr(vn,new Set(h))]})};return r.jsxs("div",{"data-testid":"pdf-viewer","data-file-url":he||void 0,className:`epochs-pdf-viewer ${M??""}`.trim(),style:Mi,children:[Ke?r.jsxs("div",{className:"epochs-pdf-viewer__toolbar",children:[jn(Ke.left),jn(Ke.right,!0)]}):null,$t||de||Le?r.jsx(yr,{open:te,onClose:()=>{T(!1),Ue(null),ge==null||ge()},onSave:mi,fieldType:oe,showFieldTypeTabs:!Le}):null,r.jsxs("div",{className:"epochs-pdf-viewer__content",children:[ze?r.jsx("div",{className:"epochs-pdf-viewer__thumbnails",style:{width:x+24},children:ue==="ready"&&W?r.jsxs(r.Fragment,{children:[Array.from({length:Math.min(p||0,g)}).map((f,u)=>{const h=u+1;return r.jsx("div",{className:"epochs-pdf-viewer__thumb-wrap",children:r.jsx(cr,{pdfDoc:W,pageNumber:h,isActive:h===$,rotation:se,onSelect:et,width:x,annotations:j,signatures:k,signatureFields:Y,texts:F,textFields:D})},h)}),p>g?r.jsxs("div",{className:"epochs-pdf-viewer__thumb-more",children:["Showing first ",g," pages"]}):null]}):r.jsx("div",{className:"epochs-pdf-viewer__muted",children:"Thumbnails"})}):null,r.jsxs("div",{ref:Ee,className:"epochs-pdf-viewer__body",children:[ue==="loading"?r.jsxs("div",{className:"epochs-pdf-viewer__overlay epochs-pdf-viewer__muted",children:["Loading PDF…",r.jsx("span",{className:"epochs-pdf-viewer__spinner"})]}):null,ue==="error"?r.jsxs("div",{className:"epochs-pdf-viewer__overlay epochs-pdf-viewer__error",children:["Unable to load PDF.",he?r.jsx("a",{className:"epochs-pdf-viewer__open-link",href:he,target:"_blank",rel:"noopener noreferrer",children:"Open file"}):null]}):null,ue==="ready"&&W?r.jsx("div",{children:Array.from({length:p}).map((f,u)=>{const h=u+1;return r.jsx(ar,{pdfDoc:W,pageNumber:h,scale:q,rotation:se,markupTool:Q?w:"none",markupColor:li,annotations:j,onAddAnnotation:di,onRemoveAnnotation:hi,signatures:k,pendingSignature:le,onAddSignature:wi,onUpdateSignature:yi,onRemoveSignature:bi,onEditSignature:_i,onDuplicateSignature:xi,selectedSignatureId:De,onSelectSignature:ae,signatureFields:Y,selectedSignatureFieldId:xe,onSelectSignatureField:Ie,hasFixedSignatureFields:Le,onOpenSignaturePad:fi,fieldValues:Je,onFieldValueChange:pi,onFieldValueCommit:gi,texts:F,onAddText:vi,onUpdateText:ji,onRemoveText:ki,selectedTextId:ot,onSelectText:Xe,textFields:D,selectedTextFieldId:yt,onSelectTextField:Ze,hasFixedTextFields:at,editingTextId:bt,onEditingTextIdChange:xt,pageRef:b=>{b&&Be.current.set(h,b)}},h)})}):null]})]}),Le||X?r.jsxs("div",{className:"epochs-pdf-viewer__footer",role:"navigation","aria-label":"Viewer actions",children:[Le?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"epochs-pdf-viewer__footer-nav",children:[r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:Y.length<=1||Ft<=0,onClick:()=>_n(-1),children:"Prev"}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:Y.length<=1||Ft>=Y.length-1,onClick:()=>_n(1),children:"Next"})]}),r.jsxs("div",{className:"epochs-pdf-viewer__footer-center",children:[r.jsxs("span",{className:"epochs-pdf-viewer__footer-label",children:["Field ",Math.max(1,Ft+1)," of ",Y.length]}),r.jsx("div",{className:"epochs-pdf-viewer__footer-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Dt,"aria-label":"Signature progress",children:r.jsx("div",{className:"epochs-pdf-viewer__footer-progress-bar",style:{width:`${Dt}%`}})}),r.jsxs("span",{className:"epochs-pdf-viewer__footer-percent",children:[Dt,"%"]})]})]}):r.jsx("div",{className:"epochs-pdf-viewer__footer-center"}),X?r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:X,children:st}):null]}):null]})}function En(e){return null}En.displayName="Document";function An(e){return null}An.displayName="Page";function Bn(e){return null}Bn.displayName="View";function On(e){return null}On.displayName="Text";function Hn(e){return null}Hn.displayName="Image";function Un(e){return null}Un.displayName="Link";const Pr={Document:"DOCUMENT",Page:"PAGE",View:"VIEW",Text:"TEXT",Image:"IMAGE",Link:"LINK"};function Nr(e){if(typeof e=="string")return e;if(typeof e=="function"){const t=e;return t.displayName||t.name||null}return null}function zn(e){const t=[],n=i=>{if(!(i==null||typeof i=="boolean")){if(Array.isArray(i)){i.forEach(n);return}t.push(i)}};return n(e),t}function Wn(e){return zn(e).map(t=>typeof t=="string"||typeof t=="number"?String(t):t&&typeof t=="object"&&"props"in t?Wn(t.props.children):"").join("")}function Gn(e){const t=Nr(e.type),n=t?Pr[t]:void 0;if(!n)throw new Error(`[epochs-pdf] Unsupported element "${t??"unknown"}". Use Document, Page, View, Text, Image, or Link.`);const i={...e.props},s=i.children;if(delete i.children,n==="TEXT"||n==="LINK")return{type:n,props:i,children:[],text:Wn(s)};const o=zn(s).filter(c=>!!c&&typeof c=="object"&&"type"in c).map(Gn);return{type:n,props:i,children:o}}const Xn={A4:[595.28,841.89],LETTER:[612,792],LEGAL:[612,1008]};function qn(e="A4",t="portrait"){const[n,i]=Array.isArray(e)?e:Xn[e];return t==="landscape"?[i,n]:[n,i]}function Yn(e={}){const t=e.padding??0;return{top:e.paddingTop??t,right:e.paddingRight??t,bottom:e.paddingBottom??t,left:e.paddingLeft??t}}function ut(e={}){const t=e.margin??0;return{top:e.marginTop??t,right:e.marginRight??t,bottom:e.marginBottom??t,left:e.marginLeft??t}}function Mt(e){if(!e)return null;const t=e.trim();if(t.startsWith("#")){const i=t.slice(1);if(i.length===3){const s=parseInt(i[0]+i[0],16)/255,o=parseInt(i[1]+i[1],16)/255,c=parseInt(i[2]+i[2],16)/255;return[s,o,c]}if(i.length===6){const s=parseInt(i.slice(0,2),16)/255,o=parseInt(i.slice(2,4),16)/255,c=parseInt(i.slice(4,6),16)/255;return[s,o,c]}}const n=e.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);return n?[Math.min(1,Number(n[1])/255),Math.min(1,Number(n[2])/255),Math.min(1,Number(n[3])/255)]:null}function it(e,t,n=0){if(e==null)return n;if(typeof e=="number")return e;if(e.endsWith("%")){const s=Number.parseFloat(e);return Number.isFinite(s)?s/100*t:n}const i=Number.parseFloat(e);return Number.isFinite(i)?i:n}function qt(e){return e==="bold"?!0:typeof e=="number"?e>=600:!1}const Cr=12,Tr=1.4,$r=.5;function Zn(e,t,n){const i=t.fontSize??Cr,s=(t.lineHeight??Tr)*i,o=i*(qt(t.fontWeight)?.55:$r);if(!e)return{width:0,height:s,lines:[""]};const c=e.split(/\s+/),l=[];let x="";for(const M of c){const v=x?`${x} ${M}`:M;v.length*o<=n||!x?x=v:(l.push(x),x=M)}x&&l.push(x);const g=Math.max(...l.map(M=>M.length*o),0);return{width:Math.min(g,n),height:l.length*s,lines:l}}function Kn(e,t,n,i,s){const o=e.props.style??{},c=ut(o),l=Yn(o),x=t+c.left,g=n+c.top,M=Math.max(0,it(o.width,i,i)-c.left-c.right),v=Math.max(0,M-l.left-l.right);if(e.type==="TEXT"||e.type==="LINK"){const D=Zn(e.text??"",o,v),ie=it(o.height,s,D.height+l.top+l.bottom);return{x,y:g,width:M,height:ie,node:e,children:[],style:o,text:e.text}}if(e.type==="IMAGE"){const D=it(o.width,i,Math.min(200,i)),ie=it(o.height,s,120);return{x,y:g,width:D-c.left-c.right,height:ie,node:e,children:[],style:o}}const m=o.flexDirection??"column",P=o.gap??0,N=[];let U=x+l.left,E=g+l.top,B=0,A=0;for(let D=0;D<e.children.length;D++){const ie=e.children[D],be=m==="row"?Math.max(0,v-B-(D>0?P:0)):v,je=m==="column"?Math.max(0,s-(E-n)-c.bottom):s,de=Kn(ie,U,E,be,je);N.push(de),m==="row"?(B+=de.width+ut(ie.props.style??{}).left+ut(ie.props.style??{}).right,D<e.children.length-1&&(B+=P),U=x+l.left+B,A=Math.max(A,de.height)):(B+=de.height+ut(ie.props.style??{}).top+ut(ie.props.style??{}).bottom,D<e.children.length-1&&(B+=P),E=g+l.top+B,A=Math.max(A,de.width))}const C=it(o.height,s,m==="column"?B+l.top+l.bottom:A+l.top+l.bottom),K=m==="row"?it(o.width,i,B+l.left+l.right):M,Q=o.justifyContent??"flex-start",z=o.alignItems??"stretch",ne=m==="column"?C-l.top-l.bottom:K-l.left-l.right,pe=Math.max(0,ne-B);let S=0,re=P;Q==="center"&&(S=pe/2),Q==="flex-end"&&(S=pe),Q==="space-between"&&N.length>1&&(re=P+pe/(N.length-1)),Q==="space-around"&&N.length>0&&(re=P+pe/N.length,S=re/2);let J=0;for(const D of N)m==="column"?(D.y=g+l.top+S+J,z==="center"?D.x=x+l.left+Math.max(0,(v-D.width)/2):z==="flex-end"?D.x=x+l.left+Math.max(0,v-D.width):z==="stretch"&&D.style.width==null&&(D.width=v),J+=D.height+re):(D.x=x+l.left+S+J,z==="center"?D.y=g+l.top+Math.max(0,(C-l.top-l.bottom-D.height)/2):z==="flex-end"?D.y=g+l.top+Math.max(0,C-l.top-l.bottom-D.height):z==="stretch"&&D.style.height==null&&(D.height=C-l.top-l.bottom),J+=D.width+re);return{x,y:g,width:K,height:C,node:e,children:N,style:o}}function Rr(e){if(e.type!=="DOCUMENT")throw new Error("[epochs-pdf] Root element must be <Document>.");const t=[];for(const n of e.children){if(n.type!=="PAGE")throw new Error("[epochs-pdf] Direct children of <Document> must be <Page>.");const i=n.props.size,s=n.props.orientation??"portrait",[o,c]=qn(i,s),l=n.props.style??{},x=Yn(l),g={type:"VIEW",props:{style:{...l,width:o,height:c,paddingTop:x.top,paddingRight:x.right,paddingBottom:x.bottom,paddingLeft:x.left}},children:n.children},M=Kn(g,0,0,o,c);t.push({width:o,height:c,boxes:M.children,style:l})}return{meta:{title:String(e.props.title??"Untitled"),author:String(e.props.author??""),subject:String(e.props.subject??""),creator:String(e.props.creator??"epochs-pdf")},pages:t}}function ft(e){return e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}class Ir{constructor(){Et(this,"objects",[null]);Et(this,"offsets",[0])}addObject(t){return this.objects.push(t),this.objects.length-1}build(t){const n=this.addObject(`<< /Title (${ft(t.meta.title)}) /Author (${ft(t.meta.author)}) /Subject (${ft(t.meta.subject)}) /Creator (${ft(t.meta.creator)}) /Producer (epochs-pdf) >>`),i=this.addObject("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"),s=this.addObject("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold >>"),o=[];for(const v of t.pages){const m=this.renderPageContent(v.boxes,v.width,v.height,v.style),P=this.addObject(`<< /Length ${m.length} >>
38
+ </html>`),g.close();const M=g.body;for(const $ of h){const O=g.createElement("img");O.src=$.dataUrl;const st=g.createElement("div");st.className="page",st.appendChild(O),M.appendChild(st)}await Promise.all(Array.from(M.querySelectorAll("img")).map($=>{var O;return((O=$.decode)==null?void 0:O.call($).catch(()=>{}))??Promise.resolve()})),setTimeout(()=>{var $,O;try{($=l.contentWindow)==null||$.focus(),(O=l.contentWindow)==null||O.print()}finally{setTimeout(()=>{try{document.body.removeChild(l)}catch{}},1e3)}},50)}catch{try{K?window.open(K,"_blank","noopener,noreferrer"):pt&&window.open(pt,"_blank","noopener,noreferrer")}catch{}}finally{a(!1)}}},[nt,at,I,o,K,pt,P,N,fe]),vi=f.useCallback(async()=>{if(!nt||at!=="ready")return;const c=`${o.replace(/[^\w.-]+/g,"_")||"document"}.pdf`;if(!(P.length>0||N.length>0||fe.length>0)&&K){Je(await fetch(K).then(l=>l.blob()),c);return}v(!0);try{const l=await Un(nt,{scale:2,rotation:I,annotations:P,signatures:N,texts:fe,mimeType:"image/jpeg",quality:.92}),g=Is(l),M=new Uint8Array(g.byteLength);M.set(g),Je(new Blob([M],{type:"application/pdf"}),c)}catch{K&&Je(await fetch(K).then(l=>l.blob()),c)}finally{v(!1)}},[nt,at,I,o,K,P,N,fe]),ji=f.useCallback(c=>{D(h=>h===c?"none":c)},[]),ki=j==="highlight"||j==="underline"?on(j==="highlight"?jn:j==="underline"?kn:null,j):void 0,pe=Ut!=null?N.find(c=>c.id===Ut)??null:null,Mi=f.useCallback(c=>{F(h=>[...h,c])},[]),Ni=f.useCallback(c=>{F(h=>h.filter(l=>l.id!==c))},[]),Pi=f.useCallback(()=>{F([]),S([]),R([]),lt(null),le(null),xe(null),Ie(null)},[]),Te=f.useCallback((c,h)=>{const l=E.findIndex(M=>M.id===c),g=E.slice(l+1).find(M=>!h.has(M.id))??E.slice(0,Math.max(0,l)).find(M=>!h.has(M.id));if(!g){W(!1),Zt(null);return}Kt(g.id),lt(null),Zt(null),xt(g.type??"sign"),ue(g),window.setTimeout(()=>{W(!0)},350)},[ue,E]),Ci=f.useCallback(c=>{xt(c),W(!0)},[]),$i=f.useCallback((c,h)=>{Ae(l=>({...l,[c]:h}))},[]),Ii=f.useCallback(c=>{const h=Ht[c];h&&(V==null||V(c,h));const l=E.findIndex($=>$.id===c),g=new Set(Object.keys(Ht).filter($=>{var O;return(O=Ht[$])==null?void 0:O.trim()}));g.add(c);const M=E.slice(l+1).find($=>!g.has($.id)&&!N.some(O=>O.fieldId===$.id))??E.slice(0,Math.max(0,l)).find($=>!g.has($.id)&&!N.some(O=>O.fieldId===$.id));M&&(Kt(M.id),ue(M))},[E,Ht,N,ue,V]),Ti=f.useCallback((c,h,l)=>{var se;const g=Ki(h,l);if(ce){S(J=>J.map(_t=>_t.id===ce?{..._t,imageDataUrl:c,width:_t.fieldId?_t.width:g.width,height:_t.fieldId?_t.height:g.height}:_t)),Tt(null),D("none"),W(!1),Zt(null);return}if(Rt){const J=E.find(X=>X.id===ut&&(X.type??"sign")==="sign"&&!N.some(te=>te.fieldId===X.id))??E.find(X=>(X.type??"sign")==="sign"&&!N.some(te=>te.fieldId===X.id));if(!J){W(!1);return}const _t=bt&&J.signature_tag?E.filter(X=>(X.type??"sign")==="sign"&&X.signature_tag===J.signature_tag&&!N.some(te=>te.fieldId===X.id)):[J],vt=_t.map(X=>({id:Fe(),fieldId:X.id,pageNumber:X.pageNumber,x:X.x,y:X.y,width:X.width,height:X.height,imageDataUrl:c})),Qt=new Set(_t.map(X=>X.id));S(X=>[...X.filter(te=>!te.fieldId||!Qt.has(te.fieldId)),...vt]);const re=new Map(vt.map(X=>[X.fieldId,X]));_e(_t.map(X=>X.id),vt[0],re),Tt(null),D("none"),lt(((se=vt[0])==null?void 0:se.id)??null);const mt=new Set(E.filter(X=>ye(X,[...N,...vt],Ht)).map(X=>X.id));for(const X of Qt)mt.add(X);Te(J.id,mt);return}const M=z.current.get(ht),$=M==null?void 0:M.querySelector(".epochs-pdf-viewer__surface");let O=24,st=24;if($){const J=we($,Nt),_t=$.closest(".epochs-pdf-viewer__body");if(_t){const vt=En(_t.getBoundingClientRect(),$,Nt),Qt=Math.max(0,vt.top),re=Math.min(J.height,vt.bottom),mt=Math.max(0,vt.left),X=Math.min(J.width,vt.right);O=Math.max(0,(mt+X)/2-g.width/2),st=Math.max(0,(Qt+re)/2-g.height/2),O=Math.min(O,Math.max(0,J.width-g.width)),st=Math.min(st,Math.max(0,J.height-g.height))}else O=Math.max(0,(J.width-g.width)/2),st=Math.max(0,(J.height-g.height)/2)}const St={id:Fe(),pageNumber:ht,x:O,y:st,width:g.width,height:g.height,imageDataUrl:c};S(J=>[...J,St]),_e(void 0,St),lt(St.id),Tt(null),D("none"),W(!1),Zt(null)},[Te,bt,ce,Ht,Rt,ye,ht,Nt,ut,E,N,_e]),Ri=f.useCallback((c,h)=>{if(Rt){const J=E.find(mt=>mt.id===ut&&(mt.type??"sign")===h)??E.find(mt=>(mt.type??"sign")===h);if(!J){W(!1);return}const vt=(bt&&J.signature_tag?E.filter(mt=>(mt.type??"sign")===h&&mt.signature_tag===J.signature_tag):[J]).map(mt=>mt.id);Mn(vt,c);const Qt={...Ht};for(const mt of vt)Qt[mt]=c;const re=new Set(E.filter(mt=>ye(mt,N,Qt)).map(mt=>mt.id));Te(J.id,re);return}const l=ae,g=Math.max(80,c.length*l*.55),M=l*1.25;let $=24,O=24;const st=z.current.get(ht),St=st==null?void 0:st.querySelector(".epochs-pdf-viewer__surface");if(St){const J=we(St,Nt),_t=St.closest(".epochs-pdf-viewer__body");if(_t){const vt=En(_t.getBoundingClientRect(),St,Nt),Qt=Math.max(0,vt.top),re=Math.min(J.height,vt.bottom),mt=Math.max(0,vt.left),X=Math.min(J.width,vt.right);$=Math.max(0,(mt+X)/2-g/2),O=Math.max(0,(Qt+re)/2-M/2),$=Math.min($,Math.max(0,J.width-g)),O=Math.min(O,Math.max(0,J.height-M))}}const se={id:Se(),pageNumber:ht,x:$,y:O,width:g,height:M,value:c,fontSize:l,color:oe};R(J=>[...J,se]),le(se.id),W(!1),D("none")},[Te,bt,Ht,Rt,ye,ht,Nt,ut,E,N,Mn]),Li=f.useCallback(c=>{S(h=>[...h,c]),_e(void 0,c),lt(c.id),Tt(null),D("none")},[_e]),Di=f.useCallback((c,h)=>{S(l=>l.map(g=>g.id===c?{...g,...h}:g))},[]),Fi=f.useCallback(c=>{const h=N.find(l=>l.id===c);S(l=>l.filter(g=>g.id!==c)),lt(l=>l===c?null:l),h!=null&&h.fieldId&&Kt(h.fieldId)},[N]),Si=f.useCallback(c=>{const h=c?N.find(St=>St.id===c)??null:pe;if(!h)return;const l=z.current.get(h.pageNumber),g=l==null?void 0:l.querySelector(".epochs-pdf-viewer__surface"),M=18;let $=h.x+M,O=h.y+M;if(g){const St=g.clientWidth/Nt,se=g.clientHeight/Nt;$=Math.min(Math.max(0,$),Math.max(0,St-h.width)),O=Math.min(Math.max(0,O),Math.max(0,se-h.height))}const st={...h,id:Fe(),x:$,y:O};S(St=>[...St,st]),lt(st.id),Tt(null),D("none")},[Nt,pe,N]),Ei=f.useCallback(c=>{const h=c??(pe==null?void 0:pe.id);if(!h)return;const l=N.find(M=>M.id===h),g=l!=null&&l.fieldId?E.find(M=>M.id===l.fieldId):void 0;xt((g==null?void 0:g.type)??"sign"),lt(h),Zt(h),W(!0)},[pe,N,E]),Ai=f.useCallback(c=>{R(h=>c.fieldId?[...h.filter(l=>l.fieldId!==c.fieldId),c]:[...h,c]),le(c.id),c.fieldId&&xe(c.fieldId)},[]),Ui=f.useCallback((c,h)=>{R(l=>l.map(g=>g.id===c?{...g,...h}:g))},[]),Hi=f.useCallback(c=>{const h=B.find(l=>l.id===c);R(l=>l.filter(g=>g.id!==c)),le(l=>l===c?null:l),Ie(l=>l===c?null:l),h!=null&&h.fieldId&&xe(h.fieldId)},[B]);f.useEffect(()=>{be&&R(c=>c.map(h=>{if(!h.fieldId)return h;const l=U.find(g=>g.id===h.fieldId);return l?{...h,pageNumber:l.pageNumber,x:l.x,y:l.y,width:l.width,height:l.height,fontSize:l.fontSize??h.fontSize??ae,color:l.color??h.color??oe}:h}))},[be,U]);const Tn=f.useCallback(c=>{var M;if(!E.length)return;const h=ut!=null?E.findIndex($=>$.id===ut):-1,l=Math.min(E.length-1,Math.max(0,(h<0?0:h)+c)),g=E[l];g&&(Kt(g.id),lt(((M=N.find($=>$.fieldId===g.id))==null?void 0:M.id)??null),ue(g))},[ue,ut,E,N]);if(!$t&&!pt)return s.jsx("div",{"data-testid":"pdf-viewer",className:`epochs-pdf-viewer epochs-pdf-viewer--empty ${_??""}`.trim(),children:"No PDF file provided."});const Oi={height:r},Rn={status:at,showThumbnails:zt,setShowThumbnails:Bt,canGoPrev:ze,canGoNext:Be,handlePrev:mi,handleNext:wi,pageNumber:ht,numPages:kt,scrollToPage:he,scale:Nt,handleZoomOut:bi,handleZoomIn:yi,handleFitWidth:We,handleRotate:xi,markupTool:j,toggleMarkupTool:c=>ji(c),hasFixedSignatureFields:Rt,hasFixedTextFields:be,pendingSignature:Wt,setMarkupTool:D,setSignaturePadOpen:W,annotationsLength:P.length,signaturesLength:N.length,textsLength:B.length,handleClearAnnotations:Pi,highlightHex:jn,underlineHex:kn,setHighlightHex:pi,setUnderlineHex:gi,loadDocument:Oe,handlePrint:_i,isPrinting:Jt,pdfDoc:nt,displayUrl:K,resolvedUrl:pt,handleDownload:vi,isDownloading:x},zi=c=>c.filter(h=>!(Rt&&(h==="highlight"||h==="underline"||h==="erase"))),Ge=ut?E.findIndex(c=>c.id===ut):0,Bi=E.filter(c=>ye(c,N,Ht)).length,Xe=E.length>0?Math.round(Bi/E.length*100):0,Ln=(c,h=!1)=>{const l=zi(c);if(l.length===0&&!h)return s.jsx("div",{className:"epochs-pdf-viewer__toolbar-group"});if(l.length===0)return s.jsx("div",{className:"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end"});const g=l.map((M,$)=>{const O=l[$-1],st=Bn(M)&&(!O||!Bn(O));return s.jsx(f.Fragment,{children:As(M,Rn,{showMarkupSep:st})},M)});return s.jsxs("div",{className:h?"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end":"epochs-pdf-viewer__toolbar-group",children:[g,Us(Rn,new Set(l))]})};return s.jsxs("div",{"data-testid":"pdf-viewer","data-file-url":pt||void 0,className:`epochs-pdf-viewer ${_??""}`.trim(),style:Oi,children:[ne?s.jsxs("div",{className:"epochs-pdf-viewer__toolbar",children:[Ln(ne.left),Ln(ne.right,!0)]}):null,He||Vt||Rt?s.jsx(Ls,{open:it,onClose:()=>{W(!1),Zt(null),xt(void 0),dt==null||dt()},onSave:Ti,onSaveFieldValue:Ri,fieldType:ct,showFieldTypeTabs:!Rt,textPlaceholder:(Dn=E.find(c=>c.id===ut))==null?void 0:Dn.placeholder,initialFieldValue:ut?Ht[ut]??((Fn=E.find(c=>c.id===ut))==null?void 0:Fn.value):void 0,rememberedByType:It,onRememberFill:(c,h)=>{Ft(l=>c==="sign"?{...l,sign:h}:c==="date"?{...l,date:h}:{...l,text:h})}}):null,s.jsxs("div",{className:"epochs-pdf-viewer__content",children:[zt?s.jsx("div",{className:"epochs-pdf-viewer__thumbnails",style:{width:w+24},children:at==="ready"&&nt?s.jsxs(s.Fragment,{children:[Array.from({length:Math.min(kt||0,m)}).map((c,h)=>{const l=h+1;return s.jsx("div",{className:"epochs-pdf-viewer__thumb-wrap",children:s.jsx(js,{pdfDoc:nt,pageNumber:l,isActive:l===ht,rotation:I,onSelect:he,width:w,annotations:P,signatures:N,signatureFields:E,texts:fe,textFields:U})},l)}),kt>m?s.jsxs("div",{className:"epochs-pdf-viewer__thumb-more",children:["Showing first ",m," pages"]}):null]}):s.jsx("div",{className:"epochs-pdf-viewer__muted",children:"Thumbnails"})}):null,s.jsxs("div",{ref:Gt,className:"epochs-pdf-viewer__body",children:[at==="loading"?s.jsxs("div",{className:"epochs-pdf-viewer__overlay epochs-pdf-viewer__muted",children:["Loading PDF…",s.jsx("span",{className:"epochs-pdf-viewer__spinner"})]}):null,at==="error"?s.jsxs("div",{className:"epochs-pdf-viewer__overlay epochs-pdf-viewer__error",children:["Unable to load PDF.",pt?s.jsx("a",{className:"epochs-pdf-viewer__open-link",href:pt,target:"_blank",rel:"noopener noreferrer",children:"Open file"}):null]}):null,at==="ready"&&nt?s.jsx("div",{children:Array.from({length:kt}).map((c,h)=>{const l=h+1;return s.jsx(vs,{pdfDoc:nt,pageNumber:l,scale:Nt,rotation:I,markupTool:ot?j:"none",markupColor:ki,annotations:P,onAddAnnotation:Mi,onRemoveAnnotation:Ni,signatures:N,pendingSignature:Wt,onAddSignature:Li,onUpdateSignature:Di,onRemoveSignature:Fi,onEditSignature:Ei,onDuplicateSignature:Si,selectedSignatureId:Ut,onSelectSignature:lt,signatureFields:E,selectedSignatureFieldId:ut,onSelectSignatureField:Kt,hasFixedSignatureFields:Rt,onOpenSignaturePad:Ci,fieldValues:Ht,onFieldValueChange:$i,onFieldValueCommit:Ii,texts:B,onAddText:Ai,onUpdateText:Ui,onRemoveText:Hi,selectedTextId:$e,onSelectText:le,textFields:U,selectedTextFieldId:ui,onSelectTextField:xe,hasFixedTextFields:be,editingTextId:fi,onEditingTextIdChange:Ie,pageRef:g=>{g&&z.current.set(l,g)}},l)})}):null]})]}),Rt||qt?s.jsxs("div",{className:"epochs-pdf-viewer__footer",role:"navigation","aria-label":"Viewer actions",children:[Rt?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"epochs-pdf-viewer__footer-nav",children:[s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:E.length<=1||Ge<=0,onClick:()=>Tn(-1),children:"Prev"}),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:E.length<=1||Ge>=E.length-1,onClick:()=>Tn(1),children:"Next"})]}),s.jsxs("div",{className:"epochs-pdf-viewer__footer-center",children:[s.jsxs("span",{className:"epochs-pdf-viewer__footer-label",children:["Field ",Math.max(1,Ge+1)," of ",E.length]}),s.jsx("div",{className:"epochs-pdf-viewer__footer-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Xe,"aria-label":"Signature progress",children:s.jsx("div",{className:"epochs-pdf-viewer__footer-progress-bar",style:{width:`${Xe}%`}})}),s.jsxs("span",{className:"epochs-pdf-viewer__footer-percent",children:[Xe,"%"]})]})]}):s.jsx("div",{className:"epochs-pdf-viewer__footer-center"}),qt?s.jsxs("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:qt,disabled:At,"aria-busy":At||void 0,children:[At?s.jsx("span",{className:"epochs-pdf-viewer__spinner epochs-pdf-viewer__spinner--btn","aria-hidden":"true"}):null,Ce]}):null]}):null]})}function Zn(t){return null}Zn.displayName="Document";function Qn(t){return null}Qn.displayName="Page";function Jn(t){return null}Jn.displayName="View";function ti(t){return null}ti.displayName="Text";function ei(t){return null}ei.displayName="Image";function ni(t){return null}ni.displayName="Link";const Os={Document:"DOCUMENT",Page:"PAGE",View:"VIEW",Text:"TEXT",Image:"IMAGE",Link:"LINK"};function zs(t){if(typeof t=="string")return t;if(typeof t=="function"){const e=t;return e.displayName||e.name||null}return null}function ii(t){const e=[],n=i=>{if(!(i==null||typeof i=="boolean")){if(Array.isArray(i)){i.forEach(n);return}e.push(i)}};return n(t),e}function si(t){return ii(t).map(e=>typeof e=="string"||typeof e=="number"?String(e):e&&typeof e=="object"&&"props"in e?si(e.props.children):"").join("")}function ri(t){const e=zs(t.type),n=e?Os[e]:void 0;if(!n)throw new Error(`[epochs-pdf] Unsupported element "${e??"unknown"}". Use Document, Page, View, Text, Image, or Link.`);const i={...t.props},r=i.children;if(delete i.children,n==="TEXT"||n==="LINK")return{type:n,props:i,children:[],text:si(r)};const o=ii(r).filter(d=>!!d&&typeof d=="object"&&"type"in d).map(ri);return{type:n,props:i,children:o}}const oi={A4:[595.28,841.89],LETTER:[612,792],LEGAL:[612,1008]};function ai(t="A4",e="portrait"){const[n,i]=Array.isArray(t)?t:oi[t];return e==="landscape"?[i,n]:[n,i]}function ci(t={}){const e=t.padding??0;return{top:t.paddingTop??e,right:t.paddingRight??e,bottom:t.paddingBottom??e,left:t.paddingLeft??e}}function ke(t={}){const e=t.margin??0;return{top:t.marginTop??e,right:t.marginRight??e,bottom:t.marginBottom??e,left:t.marginLeft??e}}function De(t){if(!t)return null;const e=t.trim();if(e.startsWith("#")){const i=e.slice(1);if(i.length===3){const r=parseInt(i[0]+i[0],16)/255,o=parseInt(i[1]+i[1],16)/255,d=parseInt(i[2]+i[2],16)/255;return[r,o,d]}if(i.length===6){const r=parseInt(i.slice(0,2),16)/255,o=parseInt(i.slice(2,4),16)/255,d=parseInt(i.slice(4,6),16)/255;return[r,o,d]}}const n=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);return n?[Math.min(1,Number(n[1])/255),Math.min(1,Number(n[2])/255),Math.min(1,Number(n[3])/255)]:null}function ge(t,e,n=0){if(t==null)return n;if(typeof t=="number")return t;if(t.endsWith("%")){const r=Number.parseFloat(t);return Number.isFinite(r)?r/100*e:n}const i=Number.parseFloat(t);return Number.isFinite(i)?i:n}function nn(t){return t==="bold"?!0:typeof t=="number"?t>=600:!1}const Bs=12,Ws=1.4,Gs=.5;function li(t,e,n){const i=e.fontSize??Bs,r=(e.lineHeight??Ws)*i,o=i*(nn(e.fontWeight)?.55:Gs);if(!t)return{width:0,height:r,lines:[""]};const d=t.split(/\s+/),u=[];let w="";for(const _ of d){const y=w?`${w} ${_}`:_;y.length*o<=n||!w?w=y:(u.push(w),w=_)}w&&u.push(w);const m=Math.max(...u.map(_=>_.length*o),0);return{width:Math.min(m,n),height:u.length*r,lines:u}}function di(t,e,n,i,r){const o=t.props.style??{},d=ke(o),u=ci(o),w=e+d.left,m=n+d.top,_=Math.max(0,ge(o.width,i,i)-d.left-d.right),y=Math.max(0,_-u.left-u.right);if(t.type==="TEXT"||t.type==="LINK"){const U=li(t.text??"",o,y),tt=ge(o.height,r,U.height+u.top+u.bottom);return{x:w,y:m,width:_,height:tt,node:t,children:[],style:o,text:t.text}}if(t.type==="IMAGE"){const U=ge(o.width,i,Math.min(200,i)),tt=ge(o.height,r,120);return{x:w,y:m,width:U-d.left-d.right,height:tt,node:t,children:[],style:o}}const b=o.flexDirection??"column",k=o.gap??0,C=[];let H=w+u.left,A=m+u.top,L=0,Z=0;for(let U=0;U<t.children.length;U++){const tt=t.children[U],et=b==="row"?Math.max(0,y-L-(U>0?k:0)):y,bt=b==="column"?Math.max(0,r-(A-n)-d.bottom):r,V=di(tt,H,A,et,bt);C.push(V),b==="row"?(L+=V.width+ke(tt.props.style??{}).left+ke(tt.props.style??{}).right,U<t.children.length-1&&(L+=k),H=w+u.left+L,Z=Math.max(Z,V.height)):(L+=V.height+ke(tt.props.style??{}).top+ke(tt.props.style??{}).bottom,U<t.children.length-1&&(L+=k),A=m+u.top+L,Z=Math.max(Z,V.width))}const T=ge(o.height,r,b==="column"?L+u.top+u.bottom:Z+u.top+u.bottom),rt=b==="row"?ge(o.width,i,L+u.left+u.right):_,ot=o.justifyContent??"flex-start",Y=o.alignItems??"stretch",Q=b==="column"?T-u.top-u.bottom:rt-u.left-u.right,yt=Math.max(0,Q-L);let q=0,Pt=k;ot==="center"&&(q=yt/2),ot==="flex-end"&&(q=yt),ot==="space-between"&&C.length>1&&(Pt=k+yt/(C.length-1)),ot==="space-around"&&C.length>0&&(Pt=k+yt/C.length,q=Pt/2);let ft=0;for(const U of C)b==="column"?(U.y=m+u.top+q+ft,Y==="center"?U.x=w+u.left+Math.max(0,(y-U.width)/2):Y==="flex-end"?U.x=w+u.left+Math.max(0,y-U.width):Y==="stretch"&&U.style.width==null&&(U.width=y),ft+=U.height+Pt):(U.x=w+u.left+q+ft,Y==="center"?U.y=m+u.top+Math.max(0,(T-u.top-u.bottom-U.height)/2):Y==="flex-end"?U.y=m+u.top+Math.max(0,T-u.top-u.bottom-U.height):Y==="stretch"&&U.style.height==null&&(U.height=T-u.top-u.bottom),ft+=U.width+Pt);return{x:w,y:m,width:rt,height:T,node:t,children:C,style:o}}function Xs(t){if(t.type!=="DOCUMENT")throw new Error("[epochs-pdf] Root element must be <Document>.");const e=[];for(const n of t.children){if(n.type!=="PAGE")throw new Error("[epochs-pdf] Direct children of <Document> must be <Page>.");const i=n.props.size,r=n.props.orientation??"portrait",[o,d]=ai(i,r),u=n.props.style??{},w=ci(u),m={type:"VIEW",props:{style:{...u,width:o,height:d,paddingTop:w.top,paddingRight:w.right,paddingBottom:w.bottom,paddingLeft:w.left}},children:n.children},_=di(m,0,0,o,d);e.push({width:o,height:d,boxes:_.children,style:u})}return{meta:{title:String(t.props.title??"Untitled"),author:String(t.props.author??""),subject:String(t.props.subject??""),creator:String(t.props.creator??"epochs-pdf")},pages:e}}function Me(t){return t.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}class Vs{constructor(){Ve(this,"objects",[null]);Ve(this,"offsets",[0])}addObject(e){return this.objects.push(e),this.objects.length-1}build(e){const n=this.addObject(`<< /Title (${Me(e.meta.title)}) /Author (${Me(e.meta.author)}) /Subject (${Me(e.meta.subject)}) /Creator (${Me(e.meta.creator)}) /Producer (epochs-pdf) >>`),i=this.addObject("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"),r=this.addObject("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold >>"),o=[];for(const y of e.pages){const b=this.renderPageContent(y.boxes,y.width,y.height,y.style),k=this.addObject(`<< /Length ${b.length} >>
39
39
  stream
40
- ${m}
41
- endstream`),N=this.addObject("");o.push(N),this.objects[N]=`<< /Type /Page /Parent 0 0 R /MediaBox [0 0 ${v.width.toFixed(2)} ${v.height.toFixed(2)}] /Contents ${P} 0 R /Resources << /Font << /F1 ${i} 0 R /F2 ${s} 0 R >> >> >>`}const c=o.map(v=>`${v} 0 R`).join(" "),l=this.addObject(`<< /Type /Pages /Kids [${c}] /Count ${o.length} >>`);for(const v of o)this.objects[v]=this.objects[v].replace("/Parent 0 0 R",`/Parent ${l} 0 R`);const x=this.addObject(`<< /Type /Catalog /Pages ${l} 0 R >>`);let g=`%PDF-1.4
42
- `;this.offsets=[0];for(let v=1;v<this.objects.length;v++)this.offsets[v]=g.length,g+=`${v} 0 obj
43
- ${this.objects[v]}
40
+ ${b}
41
+ endstream`),C=this.addObject("");o.push(C),this.objects[C]=`<< /Type /Page /Parent 0 0 R /MediaBox [0 0 ${y.width.toFixed(2)} ${y.height.toFixed(2)}] /Contents ${k} 0 R /Resources << /Font << /F1 ${i} 0 R /F2 ${r} 0 R >> >> >>`}const d=o.map(y=>`${y} 0 R`).join(" "),u=this.addObject(`<< /Type /Pages /Kids [${d}] /Count ${o.length} >>`);for(const y of o)this.objects[y]=this.objects[y].replace("/Parent 0 0 R",`/Parent ${u} 0 R`);const w=this.addObject(`<< /Type /Catalog /Pages ${u} 0 R >>`);let m=`%PDF-1.4
42
+ `;this.offsets=[0];for(let y=1;y<this.objects.length;y++)this.offsets[y]=m.length,m+=`${y} 0 obj
43
+ ${this.objects[y]}
44
44
  endobj
45
- `;const M=g.length;g+=`xref
45
+ `;const _=m.length;m+=`xref
46
46
  0 ${this.objects.length}
47
- `,g+=`0000000000 65535 f
48
- `;for(let v=1;v<this.objects.length;v++)g+=`${String(this.offsets[v]).padStart(10,"0")} 00000 n
49
- `;return g+=`trailer
50
- << /Size ${this.objects.length} /Root ${x} 0 R /Info ${n} 0 R >>
51
- `,g+=`startxref
52
- ${M}
53
- %%EOF`,new TextEncoder().encode(g)}renderPageContent(t,n,i,s){const o=[],c=Mt(s.backgroundColor);c&&(o.push("q"),o.push(`${c[0].toFixed(3)} ${c[1].toFixed(3)} ${c[2].toFixed(3)} rg`),o.push(`0 0 ${n.toFixed(2)} ${i.toFixed(2)} re f`),o.push("Q"));const l=x=>{const{x:g,y:M,width:v,height:m,style:P,node:N,text:U}=x,E=i-M-m,B=Mt(P.backgroundColor);if(B&&(o.push("q"),o.push(`${B[0].toFixed(3)} ${B[1].toFixed(3)} ${B[2].toFixed(3)} rg`),o.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re f`),o.push("Q")),P.borderWidth&&P.borderWidth>0){const A=Mt(P.borderColor)??[0,0,0];o.push("q"),o.push(`${P.borderWidth} w`),o.push(`${A[0].toFixed(3)} ${A[1].toFixed(3)} ${A[2].toFixed(3)} RG`),o.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re S`),o.push("Q")}if((N.type==="TEXT"||N.type==="LINK")&&U!=null){const A=P.fontSize??12,C=Mt(P.color)??[0,0,0],K=qt(P.fontWeight)?"F2":"F1",Q=P.paddingLeft??P.padding??0,z=P.paddingTop??P.padding??0,ne=Math.max(0,v-Q-(P.paddingRight??P.padding??0)),_e=Zn(U,P,ne||v),pe=(P.lineHeight??1.4)*A;o.push("q"),o.push("BT"),o.push(`/${K} ${A} Tf`),o.push(`${C[0].toFixed(3)} ${C[1].toFixed(3)} ${C[2].toFixed(3)} rg`),_e.lines.forEach((S,re)=>{let J=g+Q;const D=S.length*A*(qt(P.fontWeight)?.55:.5);P.textAlign==="center"?J=g+(v-D)/2:P.textAlign==="right"&&(J=g+v-D-(P.paddingRight??P.padding??0));const ie=i-M-z-A-re*pe;o.push(`1 0 0 1 ${J.toFixed(2)} ${ie.toFixed(2)} Tm`),o.push(`(${ft(S)}) Tj`)}),o.push("ET"),o.push("Q")}N.type==="IMAGE"&&(o.push("q"),o.push("0.85 0.85 0.85 rg"),o.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re f`),o.push("0.6 0.6 0.6 RG 1 w"),o.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re S`),o.push(`BT /F1 10 Tf 0.4 0.4 0.4 rg 1 0 0 1 ${(g+8).toFixed(2)} ${(E+m/2-4).toFixed(2)} Tm (Image) Tj ET`),o.push("Q"));for(const A of x.children)l(A)};for(const x of t)l(x);return o.join(`
54
- `)}}function Lr(e){return new Ir().build(e)}function un(e){const t=Gn(e),n=Rr(t);return Lr(n)}function Sr(e){return un(e)}function fn(e){const t=un(e),n=new Uint8Array(t.byteLength);return n.set(t),new Blob([n],{type:"application/pdf"})}function Vn(e){return URL.createObjectURL(fn(e))}function Fr(e,t="document.pdf"){const n=Vn(e),i=document.createElement("a");i.href=n,i.download=t,i.click(),URL.revokeObjectURL(n)}async function Dr(e){return un(e)}async function Er(e){return fn(e)}exports.ALL_TOOLBAR_TOOLS=_r;exports.AddText=ln;exports.Clear=hn;exports.DEFAULT_TOOLBAR_LAYOUT=Xt;exports.Document=En;exports.Download=sn;exports.Erase=dn;exports.HIGHLIGHT_PRESETS=Yt;exports.Highlight=on;exports.Image=Hn;exports.Link=Un;exports.Navigation=Qt;exports.Open=rn;exports.PAGE_SIZES=Xn;exports.Page=An;exports.PdfViewer=Dn;exports.Print=nn;exports.Reload=tn;exports.Rotate=en;exports.Signature=cn;exports.Text=On;exports.Thumbnail=Vt;exports.UNDERLINE_PRESETS=Zt;exports.Underline=an;exports.View=Bn;exports.Zoom=Jt;exports.default=Dn;exports.download=Fr;exports.hexToMarkupColor=Kt;exports.pdf=Sr;exports.renderToBlob=Er;exports.renderToBuffer=Dr;exports.resolvePageSize=qn;exports.setPdfWorkerSrc=Gt;exports.toBlob=fn;exports.toUrl=Vn;
47
+ `,m+=`0000000000 65535 f
48
+ `;for(let y=1;y<this.objects.length;y++)m+=`${String(this.offsets[y]).padStart(10,"0")} 00000 n
49
+ `;return m+=`trailer
50
+ << /Size ${this.objects.length} /Root ${w} 0 R /Info ${n} 0 R >>
51
+ `,m+=`startxref
52
+ ${_}
53
+ %%EOF`,new TextEncoder().encode(m)}renderPageContent(e,n,i,r){const o=[],d=De(r.backgroundColor);d&&(o.push("q"),o.push(`${d[0].toFixed(3)} ${d[1].toFixed(3)} ${d[2].toFixed(3)} rg`),o.push(`0 0 ${n.toFixed(2)} ${i.toFixed(2)} re f`),o.push("Q"));const u=w=>{const{x:m,y:_,width:y,height:b,style:k,node:C,text:H}=w,A=i-_-b,L=De(k.backgroundColor);if(L&&(o.push("q"),o.push(`${L[0].toFixed(3)} ${L[1].toFixed(3)} ${L[2].toFixed(3)} rg`),o.push(`${m.toFixed(2)} ${A.toFixed(2)} ${y.toFixed(2)} ${b.toFixed(2)} re f`),o.push("Q")),k.borderWidth&&k.borderWidth>0){const Z=De(k.borderColor)??[0,0,0];o.push("q"),o.push(`${k.borderWidth} w`),o.push(`${Z[0].toFixed(3)} ${Z[1].toFixed(3)} ${Z[2].toFixed(3)} RG`),o.push(`${m.toFixed(2)} ${A.toFixed(2)} ${y.toFixed(2)} ${b.toFixed(2)} re S`),o.push("Q")}if((C.type==="TEXT"||C.type==="LINK")&&H!=null){const Z=k.fontSize??12,T=De(k.color)??[0,0,0],rt=nn(k.fontWeight)?"F2":"F1",ot=k.paddingLeft??k.padding??0,Y=k.paddingTop??k.padding??0,Q=Math.max(0,y-ot-(k.paddingRight??k.padding??0)),wt=li(H,k,Q||y),yt=(k.lineHeight??1.4)*Z;o.push("q"),o.push("BT"),o.push(`/${rt} ${Z} Tf`),o.push(`${T[0].toFixed(3)} ${T[1].toFixed(3)} ${T[2].toFixed(3)} rg`),wt.lines.forEach((q,Pt)=>{let ft=m+ot;const U=q.length*Z*(nn(k.fontWeight)?.55:.5);k.textAlign==="center"?ft=m+(y-U)/2:k.textAlign==="right"&&(ft=m+y-U-(k.paddingRight??k.padding??0));const tt=i-_-Y-Z-Pt*yt;o.push(`1 0 0 1 ${ft.toFixed(2)} ${tt.toFixed(2)} Tm`),o.push(`(${Me(q)}) Tj`)}),o.push("ET"),o.push("Q")}C.type==="IMAGE"&&(o.push("q"),o.push("0.85 0.85 0.85 rg"),o.push(`${m.toFixed(2)} ${A.toFixed(2)} ${y.toFixed(2)} ${b.toFixed(2)} re f`),o.push("0.6 0.6 0.6 RG 1 w"),o.push(`${m.toFixed(2)} ${A.toFixed(2)} ${y.toFixed(2)} ${b.toFixed(2)} re S`),o.push(`BT /F1 10 Tf 0.4 0.4 0.4 rg 1 0 0 1 ${(m+8).toFixed(2)} ${(A+b/2-4).toFixed(2)} Tm (Image) Tj ET`),o.push("Q"));for(const Z of w.children)u(Z)};for(const w of e)u(w);return o.join(`
54
+ `)}}function qs(t){return new Vs().build(t)}function _n(t){const e=ri(t),n=Xs(e);return qs(n)}function Ys(t){return _n(t)}function vn(t){const e=_n(t),n=new Uint8Array(e.byteLength);return n.set(e),new Blob([n],{type:"application/pdf"})}function hi(t){return URL.createObjectURL(vn(t))}function Ks(t,e="document.pdf"){const n=hi(t),i=document.createElement("a");i.href=n,i.download=e,i.click(),URL.revokeObjectURL(n)}async function Zs(t){return _n(t)}async function Qs(t){return vn(t)}exports.ALL_TOOLBAR_TOOLS=Ss;exports.AddText=xn;exports.Clear=yn;exports.DEFAULT_TOOLBAR_LAYOUT=en;exports.Document=Zn;exports.Download=pn;exports.Erase=bn;exports.HIGHLIGHT_PRESETS=sn;exports.Highlight=gn;exports.Image=ei;exports.Link=ni;exports.Navigation=cn;exports.Open=fn;exports.PAGE_SIZES=oi;exports.Page=Qn;exports.PdfViewer=Kn;exports.Print=un;exports.Reload=hn;exports.Rotate=dn;exports.Signature=wn;exports.Text=ti;exports.Thumbnail=an;exports.UNDERLINE_PRESETS=rn;exports.Underline=mn;exports.View=Jn;exports.Zoom=ln;exports.default=Kn;exports.download=Ks;exports.hexToMarkupColor=on;exports.pdf=Ys;exports.renderToBlob=Qs;exports.renderToBuffer=Zs;exports.resolvePageSize=ai;exports.setPdfWorkerSrc=tn;exports.toBlob=vn;exports.toUrl=hi;
55
55
  //# sourceMappingURL=epochs-pdf.cjs.map