epochs-pdf 0.1.3 → 0.1.5

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,31 +1,32 @@
1
- "use strict";var ji=Object.defineProperty;var ki=(e,t,n)=>t in e?ji(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Lt=(e,t,n)=>ki(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"),Mn=require("pdfjs-dist");function Mi(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=Mi(Mn),ut="#ffffff",Wt=[{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"}],Gt=[{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"}],Pn=Wt[0].hex,Pi=Gt[0].hex;Xt(Pn,"highlight");function St(){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 Xt(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 a=Number.parseInt(s[1],16),c=a>>16&255,l=a>>8&255,b=a&255;return`rgba(${c}, ${l}, ${b}, ${n})`}function Dt(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(),a=Array.from(i.getClientRects()).filter(j=>j.width>0&&j.height>0);if(!a.length)return null;const c=t||1,l=e.clientWidth||s.width,b=e.clientHeight||s.height;return{rects:a.map(j=>({x:s.width>0?(j.left-s.left)/s.width*(l/c):0,y:s.height>0?(j.top-s.top)/s.height*(b/c):0,w:s.width>0?j.width/s.width*(l/c):0,h:s.height>0?j.height/s.height*(b/c):0})),text:n.toString()}}function bn(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 Et(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 Nn(e,t,n){for(const i of t)for(const s of i.rects){const a=s.x*n,c=s.y*n,l=s.w*n,b=s.h*n;if(i.kind==="highlight")e.save(),e.globalCompositeOperation="multiply",e.fillStyle=i.color,e.fillRect(a,c,l,b),e.restore();else if(i.kind==="redact")e.fillStyle=i.color||ut,e.fillRect(a,c,l,b);else{const g=Math.max(2,n*1.5);e.fillStyle=i.color,e.fillRect(a,c+b-g,l,g)}}}function vt(){return`s_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}async function Cn(e,t,n){for(const i of t){const s=await Ci(i.imageDataUrl);e.drawImage(s,i.x*n,i.y*n,i.width*n,i.height*n)}}function Ni(e,t,n,i){e.save();for(const s of t){const a=n.has(s.id),c=s.x*i,l=s.y*i,b=s.width*i,g=s.height*i;e.fillStyle=a?"rgba(29, 78, 216, 0.08)":"rgba(29, 78, 216, 0.18)",e.strokeStyle=a?"rgba(29, 78, 216, 0.45)":"#1d4ed8",e.lineWidth=1.5,e.setLineDash(a?[]:[4,3]),e.fillRect(c,l,b,g),e.strokeRect(c,l,b,g)}e.restore()}function Ci(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 Ti(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 bt(e,t,n,i){const s=n.getBoundingClientRect(),a=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*(a/i),y:(t-s.top)/s.height*(c/i)}}function pt(e,t){return{width:e.clientWidth/t,height:e.clientHeight/t}}function $i(e,t,n,i){const s=n.getBoundingClientRect(),a=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*(a/i),dy:t/s.height*(c/i)}}function Ri(e,t,n){const i=t.getBoundingClientRect(),{width:s,height:a}=pt(t,n);return i.width<=0||i.height<=0?{left:0,top:0,right:s,bottom:a}:{left:(e.left-i.left)/i.width*s,top:(e.top-i.top)/i.height*a,right:(e.right-i.left)/i.width*s,bottom:(e.bottom-i.top)/i.height*a}}const gt=14,ft="#111827",Ft=24,At=20;function Bt(){return`t_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function lt(e,t){if(typeof document>"u")return{width:Math.max(Ft,e.length*t*.55),height:Math.max(At,t*1.25)};const i=document.createElement("canvas").getContext("2d");if(!i)return{width:Math.max(Ft,e.length*t*.55),height:Math.max(At,t*1.25)};i.font=`${t}px sans-serif`;const s=e.split(`
2
- `),a=t*1.25;let c=Ft;for(const l of s)c=Math.max(c,i.measureText(l||" ").width+4);return{width:c,height:Math.max(At,s.length*a)}}function Ii(e,t,n,i,s){var F;const a=n.getBoundingClientRect(),c=n.clientWidth||a.width,l=n.clientHeight||a.height,b=T=>a.width>0?(T-a.left)/a.width*(c/s):0,g=T=>a.height>0?(T-a.top)/a.height*(l/s):0,j=(T,Z)=>{const J=Z==="x"?a.width:a.height,G=Z==="x"?c:l;return J>0?T/J*(G/s):0};let v=b(e),w=g(t),M=gt;const C=Li(e,t,i);if(C)return{x:b(C.x),y:g(C.y),fontSize:Math.max(8,Math.round(j(C.fontSize,"y")*10)/10)};const W=document,E=(F=W.caretRangeFromPoint)==null?void 0:F.call(W,e,t);if(E&&i.contains(E.startContainer)){const T=E.getClientRects(),Z=T.length>0?T[0]:E.getBoundingClientRect();if(Z.height>0){w=g(Z.top),M=Di(E.startContainer,s,n);const J=b(Z.left);return Math.abs(J-v)<j(8,"x")&&(v=J),{x:v,y:w,fontSize:M}}}const O=Si(e,t,i);return O&&(w=g(O.top),M=Math.max(8,Math.round(j(O.height,"y")*10)/10)),{x:v,y:w,fontSize:M}}function Li(e,t,n){var a;const i=Array.from(n.querySelectorAll("span"));if(i.length<2)return null;const s=[];for(const c of i){if(!((a=c.textContent)!=null&&a.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],b=s[c+1],g=l.right,j=b.left;if(!(j-g<1)&&e>=g-2&&e<=j+2)return{x:e,y:Math.min(l.top,b.top),fontSize:Math.min(l.height,b.height)}}return null}function Si(e,t,n){var a;const i=Array.from(n.querySelectorAll("span"));let s=null;for(const c of i){if(!((a=c.textContent)!=null&&a.trim()))continue;const l=c.getBoundingClientRect();if(l.width<=0||l.height<=0||t<l.top-6||t>l.bottom+6)continue;const b=(l.left+l.right)/2,g=Math.abs(e-b);(!s||g<s.dist)&&(s={top:l.top,height:l.height,dist:g})}return s?{top:s.top,height:s.height}:null}function Di(e,t,n){const i=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return i?Ei(i,t,n):gt}function Ei(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,a=Number.parseFloat(s);return Number.isFinite(a)&&a>0?Math.max(8,Math.round(a/t*10)/10):gt}function Fi(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 Ai(e,t,n){var M;if(!n)return null;const i=document,s=(M=i.caretRangeFromPoint)==null?void 0:M.call(i,e,t);if(!s||!n.contains(s.startContainer))return null;const a=s.startContainer;if(a.nodeType!==Node.TEXT_NODE||!a.textContent)return null;const c=a.textContent;let l=s.startOffset;l=Math.min(Math.max(0,l),c.length);const b=C=>/[\p{L}\p{N}_'-]/u.test(C);let g=l,j=l;for(;g>0&&b(c[g-1]);)g-=1;for(;j<c.length&&b(c[j]);)j+=1;if(g===j)return null;const v=document.createRange();v.setStart(a,g),v.setEnd(a,j);const w=window.getSelection();return w==null||w.removeAllRanges(),w==null||w.addRange(v),c.slice(g,j)}function Tn(e,t,n){e.save();for(const i of t){if(!i.value.trim())continue;const s=i.x*n,a=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,b=i.value.split(`
3
- `);let g=a;for(const j of b)e.fillText(j,s,g),g+=l}e.restore()}function Bi(e,t,n,i){e.save();for(const s of t){const a=n.has(s.id),c=s.x*i,l=s.y*i,b=s.width*i,g=s.height*i;e.fillStyle=a?"rgba(5, 150, 105, 0.08)":"rgba(5, 150, 105, 0.16)",e.strokeStyle=a?"rgba(5, 150, 105, 0.45)":"#059669",e.lineWidth=1.5,e.setLineDash(a?[]:[4,3]),e.fillRect(c,l,b,g),e.strokeRect(c,l,b,g)}e.restore()}function ke({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 Oi(e){return r.jsx(ke,{...e,children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}function Hi(e){return r.jsx(ke,{...e,children:r.jsx("polyline",{points:"9 18 15 12 9 6"})})}function zi(e){return r.jsxs(ke,{...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 Ui(e){return r.jsxs(ke,{...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 Wi(e){return r.jsxs(ke,{...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 Gi(e){return r.jsx(ke,{...e,children:r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Xi(e){return r.jsxs(ke,{...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(ke,{...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 Yi(e){return r.jsxs(ke,{...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 Zi(e){return r.jsxs(ke,{...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 Ki(e){return r.jsxs(ke,{...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 Vi(e){return r.jsxs(ke,{...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 Qi(e){return r.jsxs(ke,{...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 Ji({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 er(e){return r.jsxs(ke,{...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 tr(e){return r.jsxs(ke,{...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 nr({pdfDoc:e,pageNumber:t,scale:n,rotation:i,pageRef:s,onRendered:a,markupTool:c="none",markupColor:l,annotations:b=[],onAddAnnotation:g,onRemoveAnnotation:j,signatures:v=[],pendingSignature:w=null,onAddSignature:M,onUpdateSignature:C,onRemoveSignature:W,onEditSignature:E,onDuplicateSignature:O,selectedSignatureId:F=null,onSelectSignature:T,signatureFields:Z=[],selectedSignatureFieldId:J=null,onSelectSignatureField:G,hasFixedSignatureFields:ie=!1,onOpenSignaturePad:be,fieldValues:me={},onFieldValueChange:L,onFieldValueCommit:se,pendingFieldValue:$=null,onPlaceFieldValue:S,texts:K=[],onAddText:xe,onUpdateText:Me,onRemoveText:he,selectedTextId:we=null,onSelectText:V,textFields:Se=[],selectedTextFieldId:We=null,onSelectTextField:_e,hasFixedTextFields:Ae=!1,editingTextId:ye=null,onEditingTextIdChange:A}){const ue=d.useRef(null),Fe=d.useRef(null),te=d.useRef(null),fe=d.useRef(null),le=d.useRef(null),p=d.useRef(null),[m,H]=d.useState(null),X=d.useRef(null),re=d.useRef(!1);d.useEffect(()=>{if(!e||!Fe.current||!te.current||!fe.current)return;let o=!1;const y=Fe.current,_=te.current,k=fe.current,P=y.getContext("2d");return P?((async()=>{try{if(le.current){try{le.current.cancel()}catch{}le.current=null}if(p.current){try{p.current.cancel()}catch{}p.current=null}const R=await e.getPage(t);if(o)return;const z=R.getViewport({scale:n,rotation:i}),Y=Math.floor(z.width),U=Math.floor(z.height);y.width=Y,y.height=U,k.style.width=`${Y}px`,k.style.height=`${U}px`;const B=R.render({canvasContext:P,viewport:z});if(le.current=B,await B.promise,o)return;_.replaceChildren(),_.style.setProperty("--scale-factor",String(z.scale));const ae=await R.getTextContent();if(o)return;const ce=new Mn.TextLayer({textContentSource:ae,container:_,viewport:z});if(p.current=ce,await ce.render(),o)return;a==null||a(t)}catch{}})(),()=>{if(o=!0,le.current){try{le.current.cancel()}catch{}le.current=null}if(p.current){try{p.current.cancel()}catch{}p.current=null}}):void 0},[e,t,n,i,a]),d.useEffect(()=>{const o=fe.current;if(!o)return;const y=N=>{var U;if(!g)return!1;const R=N==="redact"?ut:l;if(!R)return!1;const z=Dt(o,n);if(!z)return!1;const Y=N==="redact"?Et(z.rects):z.rects;return g({id:St(),pageNumber:t,kind:N,color:R,rects:Y,text:z.text}),(U=window.getSelection())==null||U.removeAllRanges(),!0},_=N=>{var ae;if(!g||!xe)return!1;const R=Dt(o,n);if(!R)return!1;const z=Et(R.rects);g({id:St(),pageNumber:t,kind:"redact",color:ut,rects:z,text:R.text});const Y=bn(R.rects),U=lt(N||" ",Y.fontSize),B={id:Bt(),pageNumber:t,x:Y.x,y:Y.y,width:U.width,height:U.height,value:N,fontSize:Y.fontSize,color:ft};return xe(B),V==null||V(B.id),A==null||A(B.id),(ae=window.getSelection())==null||ae.removeAllRanges(),re.current=!0,window.setTimeout(()=>{re.current=!1},0),!0},k=()=>{if(c==="highlight"||c==="underline"){y(c);return}if(c==="erase"){y("redact");return}if(c==="text"){const N=window.getSelection();N&&!N.isCollapsed&&N.toString().trim()&&N.anchorNode&&o.contains(N.anchorNode)&&_(N.toString())}},P=N=>{const R=N.target;if(R!=null&&R.closest("[contenteditable='true']")||R!=null&&R.closest("[contenteditable='']")||R!=null&&R.isContentEditable)return;const z=window.getSelection(),Y=z!=null&&!z.isCollapsed&&z.toString().trim().length>0&&z.anchorNode!=null&&o.contains(z.anchorNode);if(c==="text"&&Y){if(N.key==="Enter"&&!N.shiftKey){N.preventDefault(),_(z.toString());return}if(N.key.length===1&&!N.ctrlKey&&!N.metaKey&&!N.altKey){N.preventDefault(),_(N.key);return}}c!=="text"&&c!=="erase"||N.key!=="Backspace"&&N.key!=="Delete"||Y&&(N.preventDefault(),y("redact"))};return o.addEventListener("mouseup",k),window.addEventListener("keydown",P),()=>{o.removeEventListener("mouseup",k),window.removeEventListener("keydown",P)}},[c,l,g,xe,A,V,t,n]),d.useEffect(()=>{if(!m)return;let o=0,y=0,_=0,k=0;const P=()=>{var B;return(B=ue.current)==null?void 0:B.closest(".epochs-pdf-viewer__body")},N=(B,ae)=>{if(m.kind!=="resize"||!C||ie)return;const ce=v.find(ze=>ze.id===m.id);if(!ce)return;const ee=fe.current,ve=ee?pt(ee,n):{width:1/0,height:1/0},{dx:de,dy:pe}=ee?$i(B-m.startX,ae-m.startY,ee,n):{dx:0,dy:0},je=ve.width-ce.x,He=ve.height-ce.y,Le=Math.min(je,Math.max(40,m.startW+de)),st=Math.min(He,Math.max(20,m.startH+pe));C(m.id,{width:Le,height:st})},R=(B,ae)=>{var wt;if(m.kind!=="signature"||!C||ie)return;const ce=v.find(Xe=>Xe.id===m.id);if(!ce)return;let ee=(wt=document.elementFromPoint(B,ae))==null?void 0:wt.closest("[data-page-number]");if(ee||(ee=Array.from(document.querySelectorAll(".epochs-pdf-viewer__page[data-page-number]")).find(Mt=>{const Ze=Mt.getBoundingClientRect();return ae>=Ze.top&&ae<=Ze.bottom})??null),ee||(ee=ue.current),!ee)return;const ve=ee.querySelector(".epochs-pdf-viewer__surface");if(!ve)return;const de=Number.parseInt(ee.getAttribute("data-page-number")||String(ce.pageNumber),10),pe=bt(B,ae,ve,n),je=pt(ve,n);let He=pe.x-m.offsetX,Le=pe.y-m.offsetY;const st=Math.max(0,je.width-ce.width),ze=Math.max(0,je.height-ce.height);He=Math.min(Math.max(0,He),st),Le=Math.min(Math.max(0,Le),ze),C(m.id,{pageNumber:de,x:He,y:Le})},z=()=>{if(o=0,!k)return;const B=P();if(!B)return;const ae=B.scrollHeight-B.clientHeight;if(ae<=0)return;const ce=56,ee=B.getBoundingClientRect(),ve=_-ee.top,de=ee.bottom-_;let pe=0;if(k<0&&ve<ce)pe=-Math.max(6,(ce-ve)/ce*28);else if(k>0&&de<ce)pe=Math.max(6,(ce-de)/ce*28);else{k=0;return}const je=B.scrollTop;B.scrollTop=Math.min(ae,Math.max(0,je+pe)),B.scrollTop!==je&&R(y,_),pe<0&&B.scrollTop>0||pe>0&&B.scrollTop<ae?o=window.requestAnimationFrame(z):k=0},Y=B=>{y=B.clientX,_=B.clientY;const ae=P();if(ae){const ee=ae.getBoundingClientRect(),ve=B.clientY-ee.top,de=ee.bottom-B.clientY;ve<56?(k=-1,o||(o=window.requestAnimationFrame(z))):de<56?(k=1,o||(o=window.requestAnimationFrame(z))):k=0}m.kind==="resize"?N(B.clientX,B.clientY):R(B.clientX,B.clientY)},U=()=>{k=0,o&&(window.cancelAnimationFrame(o),o=0),H(null)};return window.addEventListener("pointermove",Y),window.addEventListener("pointerup",U),window.addEventListener("pointercancel",U),()=>{k=0,o&&window.cancelAnimationFrame(o),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",U),window.removeEventListener("pointercancel",U)}},[m,ie,C,n,v]),d.useEffect(()=>{if(!ye||!X.current)return;const o=X.current,y=K.find(P=>P.id===ye);o.textContent=(y==null?void 0:y.value)??"",o.focus();const _=document.createRange();_.selectNodeContents(o),_.collapse(!1);const k=window.getSelection();k==null||k.removeAllRanges(),k==null||k.addRange(_)},[ye]);const ne=o=>{ue.current=o,s==null||s(o)},Pe=b.filter(o=>o.pageNumber===t),oe=v.filter(o=>o.pageNumber===t),De=Z.filter(o=>o.pageNumber===t),Re=K.filter(o=>o.pageNumber===t),Be=(o,y)=>{const _=y.trim();if(!_){he==null||he(o.id),A==null||A(null);return}const k=lt(_,o.fontSize);Me==null||Me(o.id,{value:_,width:k.width,height:k.height}),A==null||A(null)},Ge=(o,y)=>{if(!xe)return;const _=fe.current,k=te.current;if(!_||!k)return;let P=Ii(o,y,_,k,n),N,R=ft;if(Ae){const U=Fi(P.x,P.y,Se,t);if(!U)return;const B=K.find(ae=>ae.fieldId===U.id);if(B){V==null||V(B.id),_e==null||_e(U.id),A==null||A(B.id);return}N=U.id,P={x:U.x,y:U.y,fontSize:U.fontSize??gt},R=U.color??ft,_e==null||_e(U.id)}const z=lt("",P.fontSize),Y={id:Bt(),fieldId:N,pageNumber:t,x:P.x,y:P.y,width:z.width,height:z.height,value:"",fontSize:P.fontSize,color:R};xe(Y),V==null||V(Y.id),A==null||A(Y.id)},Ne=o=>{var _;if(c!=="text"||o.target.closest(".epochs-pdf-viewer__inline-text"))return;if(re.current){re.current=!1;return}const y=window.getSelection();if(!(y&&!y.isCollapsed&&y.toString().trim())){if(o.detail>=2&&Ai(o.clientX,o.clientY,te.current)){const P=fe.current;if(P&&g&&xe){const N=Dt(P,n);if(N){g({id:St(),pageNumber:t,kind:"redact",color:ut,rects:Et(N.rects),text:N.text});const R=bn(N.rects),z=lt(N.text||" ",R.fontSize),Y={id:Bt(),pageNumber:t,x:R.x,y:R.y,width:z.width,height:z.height,value:N.text,fontSize:R.fontSize,color:ft};xe(Y),V==null||V(Y.id),A==null||A(Y.id),(_=window.getSelection())==null||_.removeAllRanges(),re.current=!0}}return}o.stopPropagation(),Ge(o.clientX,o.clientY)}},Oe=o=>{const y=o.target;if(!(y.closest(".epochs-pdf-viewer__signature")||y.closest(".epochs-pdf-viewer__signature-field")||y.closest(".epochs-pdf-viewer__inline-text"))){if(c==="text"){Ge(o.clientX,o.clientY);return}if(!ie&&c==="sign"&&$&&S){const _=fe.current;if(!_)return;const k=bt(o.clientX,o.clientY,_,n);S(t,Math.max(0,k.x-75),Math.max(0,k.y-12));return}if(!ie&&c==="sign"&&w&&M){const _=fe.current;if(!_)return;const k=pt(_,n),P=bt(o.clientX,o.clientY,_,n);let N=P.x-w.width/2,R=P.y-w.height/2;const z=Math.max(0,k.width-w.width),Y=Math.max(0,k.height-w.height);N=Math.min(Math.max(0,N),z),R=Math.min(Math.max(0,R),Y),M({id:vt(),pageNumber:t,x:N,y:R,width:w.width,height:w.height,imageDataUrl:w.imageDataUrl});return}}},mt=o=>ye===o.id?r.jsx("span",{ref:X,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox","aria-label":"Edit text",className:"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--editing",style:{left:o.x*n,top:o.y*n,fontSize:o.fontSize*n,color:o.color,minWidth:Math.max(12,o.fontSize*n*.5),width:Math.max(o.width*n,o.fontSize*n*.5)},onClick:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),onInput:_=>{const k=_.currentTarget.textContent??"",P=lt(k||" ",o.fontSize);Me==null||Me(o.id,{value:k,width:P.width,height:P.height})},onBlur:_=>{Be(o,_.currentTarget.textContent??"")},onKeyDown:_=>{_.stopPropagation(),_.key==="Escape"&&(_.preventDefault(),_.currentTarget.blur()),_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),_.currentTarget.blur())}},o.id):o.value.trim()?r.jsx("span",{className:we===o.id?"epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--selected":"epochs-pdf-viewer__inline-text",style:{left:o.x*n,top:o.y*n,fontSize:o.fontSize*n,color:o.color},onClick:_=>{if(_.stopPropagation(),c==="erase"){he==null||he(o.id);return}c==="text"&&(V==null||V(o.id),A==null||A(o.id))},children:o.value},o.id):null;return r.jsx("div",{ref:ne,"data-page-number":t,className:"epochs-pdf-viewer__page",children:r.jsxs("div",{ref:fe,className:`epochs-pdf-viewer__surface epochs-pdf-viewer__surface--tool-${c}`,onClick:Oe,children:[r.jsx("canvas",{ref:Fe,className:"epochs-pdf-viewer__canvas"}),r.jsx("div",{className:"epochs-pdf-viewer__markup-layer","aria-hidden":"true",children:Pe.map(o=>o.kind==="redact"?null:o.rects.map((y,_)=>o.kind==="highlight"?r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--highlight",style:{left:y.x*n,top:y.y*n,width:y.w*n,height:y.h*n,background:o.color},onClick:k=>{c==="erase"&&(k.stopPropagation(),j==null||j(o.id))}},`${o.id}_${_}`):r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--underline",style:{left:y.x*n,top:(y.y+y.h)*n-Math.max(2,n*1.5),width:y.w*n,height:Math.max(2,n*1.5),background:o.color},onClick:k=>{c==="erase"&&(k.stopPropagation(),j==null||j(o.id))}},`${o.id}_${_}`)))}),r.jsxs("div",{className:"epochs-pdf-viewer__signature-layer",children:[De.map(o=>{const y=oe.some(_=>_.fieldId===o.id);return r.jsx("button",{type:"button","data-signature-field-id":o.id,className:J===o.id?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--selected":y?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--filled":"epochs-pdf-viewer__signature-field",style:{left:o.x*n,top:o.y*n,width:o.width*n,height:o.height*n},onClick:_=>{_.stopPropagation();const k=o.type;if(k==="date"||k==="text")return;G==null||G(o.id);const P=oe.find(N=>N.fieldId===o.id);T==null||T((P==null?void 0:P.id)??null),P?E==null||E(P.id):be==null||be(o.type)},title:y?"Signed field":"Signature field",children:(()=>{const _=o.type;return _==="date"?r.jsx("input",{type:"date",className:"epochs-pdf-viewer__signature-field-input",value:me[o.id]??"",onClick:k=>k.stopPropagation(),onChange:k=>{k.stopPropagation(),L==null||L(o.id,k.target.value),se==null||se(o.id)},style:{width:"100%",height:"100%"}}):_==="text"?r.jsx("input",{type:"text",className:"epochs-pdf-viewer__signature-field-input",value:me[o.id]??"",placeholder:o.placeholder??"Enter text",onClick:k=>k.stopPropagation(),onChange:k=>{k.stopPropagation(),L==null||L(o.id,k.target.value)},onBlur:()=>se==null?void 0:se(o.id),style:{width:"100%",height:"100%"}}):y?null:r.jsx("span",{children:"Sign here"})})()},o.id)}),oe.map(o=>r.jsxs("div",{className:F===o.id?"epochs-pdf-viewer__signature epochs-pdf-viewer__signature--selected":"epochs-pdf-viewer__signature",style:{left:o.x*n,top:o.y*n,width:o.width*n,height:o.height*n},onPointerDown:y=>{if(y.stopPropagation(),y.preventDefault(),T==null||T(o.id),c==="erase"&&!ie){W==null||W(o.id);return}if(ie){G==null||G(o.fieldId??null),E==null||E(o.id);return}const _=fe.current;if(!_)return;const k=bt(y.clientX,y.clientY,_,n);H({kind:"signature",id:o.id,offsetX:k.x-o.x,offsetY:k.y-o.y})},children:[r.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-edit",title:"Edit signature","aria-label":"Edit signature",onPointerDown:y=>{y.stopPropagation()},onClick:y=>{y.stopPropagation(),T==null||T(o.id),E==null||E(o.id)},children:r.jsx(er,{size:12})}),ie?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:y=>{y.stopPropagation()},onClick:y=>{y.stopPropagation(),T==null||T(o.id),O==null||O(o.id)},children:"⧉"}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-remove",title:"Remove signature","aria-label":"Remove signature",onPointerDown:y=>{y.stopPropagation()},onClick:y=>{y.stopPropagation(),W==null||W(o.id)},children:"×"})]}),r.jsx("img",{src:o.imageDataUrl,alt:"Signature",draggable:!1}),ie?null:r.jsx("div",{className:"epochs-pdf-viewer__signature-resize",title:"Resize",onPointerDown:y=>{y.stopPropagation(),y.preventDefault(),T==null||T(o.id),H({kind:"resize",id:o.id,startX:y.clientX,startY:y.clientY,startW:o.width,startH:o.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"})})})]},o.id))]}),r.jsx("div",{className:"epochs-pdf-viewer__text-layer-overlay",children:Re.map(o=>mt(o))}),r.jsx("div",{ref:te,className:"textLayer epochs-pdf-viewer__text-layer",onClick:Ne}),r.jsx("div",{className:"epochs-pdf-viewer__redact-layer","aria-hidden":"true",children:Pe.map(o=>o.kind==="redact"?o.rects.map((y,_)=>r.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--redact",style:{left:y.x*n,top:y.y*n,width:y.w*n,height:y.h*n,background:o.color||ut},onClick:k=>{c==="erase"&&(k.stopPropagation(),j==null||j(o.id))}},`${o.id}_${_}`)):null)})]})})}function ir({pdfDoc:e,pageNumber:t,isActive:n,rotation:i,onSelect:s,width:a=140,annotations:c=[],signatures:l=[],signatureFields:b=[],texts:g=[],textFields:j=[]}){const v=d.useRef(null);return d.useEffect(()=>{if(!e||!v.current)return;let w=!1;const M=v.current,C=M.getContext("2d");if(!C)return;let W=null;return(async()=>{try{const O=await e.getPage(t);if(w)return;const F=O.getViewport({scale:1,rotation:i}),T=a/F.width,Z=O.getViewport({scale:T,rotation:i});M.width=Math.floor(Z.width),M.height=Math.floor(Z.height),W=O.render({canvasContext:C,viewport:Z}),await W.promise;const J=c.filter(L=>L.pageNumber===t);J.length>0&&Nn(C,J,T);const G=l.filter(L=>L.pageNumber===t),ie=b.filter(L=>L.pageNumber===t);ie.length>0&&Ni(C,ie,new Set(G.map(L=>L.fieldId).filter(Boolean)),T),G.length>0&&await Cn(C,G,T);const be=g.filter(L=>L.pageNumber===t),me=j.filter(L=>L.pageNumber===t);me.length>0&&Bi(C,me,new Set(be.filter(L=>L.fieldId&&L.value.trim()).map(L=>L.fieldId)),T),be.length>0&&Tn(C,be,T)}catch{}})(),()=>{if(w=!0,W)try{W.cancel()}catch{}}},[c,e,t,i,b,l,j,g,a]),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 rr=/^(blob:|https?:|data:)/i;let $n=!1;function Ht(e){rt.GlobalWorkerOptions.workerSrc=e,$n=!0}function sr(e){if(e){Ht(e);return}$n||rt.GlobalWorkerOptions.workerSrc||Ht(`https://unpkg.com/pdfjs-dist@${rt.version}/build/pdf.worker.min.mjs`)}function or(e,t,n=""){const i=t||e;if(!i)return"";if(rr.test(i))return i;const s=i.startsWith("/")?i:`/${i}`;return n?`${n.replace(/\/$/,"")}${s}`:s}async function ar(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 xn(e,t){if(typeof e=="string")return ar(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 cr(e,t,n){const{scale:i,rotation:s,annotations:a,signatures:c=[],texts:l=[],mimeType:b="image/jpeg",quality:g=.92}=n,j=await e.getPage(t),v=j.getViewport({scale:i,rotation:s}),w=j.getViewport({scale:1,rotation:s}),M=document.createElement("canvas"),C=M.getContext("2d",{alpha:!1});if(!C)throw new Error("Could not create canvas context");const W=Math.floor(v.width),E=Math.floor(v.height);M.width=W,M.height=E,C.fillStyle="#ffffff",C.fillRect(0,0,W,E),await j.render({canvasContext:C,viewport:v}).promise;const O=a.filter(G=>G.pageNumber===t);O.length>0&&Nn(C,O,i);const F=c.filter(G=>G.pageNumber===t);F.length>0&&await Cn(C,F,i);const T=l.filter(G=>G.pageNumber===t);T.length>0&&Tn(C,T,i);const Z=M.toDataURL(b,g),J=lr(Z);return M.width=0,M.height=0,{pageNumber:t,width:W,height:E,pageWidth:w.width,pageHeight:w.height,dataUrl:Z,jpegBytes:J}}async function _n(e,t){const n=[];for(let i=1;i<=e.numPages;i+=1)n.push(await cr(e,i,t));return n}function lr(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 Ee(e){return new TextEncoder().encode(e)}function vn(...e){const t=e.reduce((s,a)=>s+a.byteLength,0),n=new Uint8Array(t);let i=0;for(const s of e)n.set(s,i),i+=s.byteLength;return n}function dr(e){const t=[],n=w=>(t.push(w),t.length),i=[];for(const w of e){const M=vn(Ee(`<< /Type /XObject /Subtype /Image /Width ${w.width} /Height ${w.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${w.jpegBytes.byteLength} >>
1
+ "use strict";var Gi=Object.defineProperty;var Xi=(t,e,n)=>e in t?Gi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var qe=(t,e,n)=>Xi(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"),Gn=require("pdfjs-dist");function qi(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=qi(Gn),Ne="#ffffff",rn=[{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"}],on=[{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"}],Xn=rn[0].hex,Vi=on[0].hex;an(Xn,"highlight");function Ve(){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 an(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(x=>x.width>0&&x.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=>({x:r.width>0?(x.left-r.left)/r.width*(u/d):0,y:r.height>0?(x.top-r.top)/r.height*(w/d):0,w:r.width>0?x.width/r.width*(u/d):0,h:r.height>0?x.height/r.height*(w/d):0})),text:n.toString()}}function En(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 qn(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 g=Math.max(2,n*1.5);t.fillStyle=i.color,t.fillRect(o,d+w-g,u,g)}}}function Se(){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 Ki(i.imageDataUrl);t.drawImage(r,i.x*n,i.y*n,i.width*n,i.height*n)}}function Yi(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,g=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,g),t.strokeRect(d,u,w,g)}t.restore()}function Ki(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 Zi(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 Qi(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 An(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 Fe(){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 Ji(t,e,n,i,r){var Y;const o=n.getBoundingClientRect(),d=n.clientWidth||o.width,u=n.clientHeight||o.height,w=I=>o.width>0?(I-o.left)/o.width*(d/r):0,g=I=>o.height>0?(I-o.top)/o.height*(u/r):0,x=(I,st)=>{const rt=st==="x"?o.width:o.height,V=st==="x"?d:u;return rt>0?I/rt*(V/r):0};let b=w(t),y=g(e),j=ae;const C=ts(t,e,i);if(C)return{x:w(C.x),y:g(C.y),fontSize:Math.max(8,Math.round(x(C.fontSize,"y")*10)/10)};const E=document,U=(Y=E.caretRangeFromPoint)==null?void 0:Y.call(E,t,e);if(U&&i.contains(U.startContainer)){const I=U.getClientRects(),st=I.length>0?I[0]:U.getBoundingClientRect();if(st.height>0){y=g(st.top),j=ns(U.startContainer,r,n);const rt=w(st.left);return Math.abs(rt-b)<x(8,"x")&&(b=rt),{x:b,y,fontSize:j}}}const L=es(t,e,i);return L&&(y=g(L.top),j=Math.max(8,Math.round(x(L.height,"y")*10)/10)),{x:b,y,fontSize:j}}function ts(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],g=u.right,x=w.left;if(!(x-g<1)&&t>=g-2&&t<=x+2)return{x:t,y:Math.min(u.top,w.top),fontSize:Math.min(u.height,w.height)}}return null}function es(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,g=Math.abs(t-w);(!r||g<r.dist)&&(r={top:u.top,height:u.height,dist:g})}return r?{top:r.top,height:r.height}:null}function ns(t,e,n){const i=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;return i?is(i,e,n):ae}function is(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 ss(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 rs(t,e,n){var j;if(!n)return null;const i=document,r=(j=i.caretRangeFromPoint)==null?void 0:j.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 g=u,x=u;for(;g>0&&w(d[g-1]);)g-=1;for(;x<d.length&&w(d[x]);)x+=1;if(g===x)return null;const b=document.createRange();b.setStart(o,g),b.setEnd(o,x);const y=window.getSelection();return y==null||y.removeAllRanges(),y==null||y.addRange(b),d.slice(g,x)}function Yn(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 g=o;for(const x of w)t.fillText(x,r,g),g+=u}t.restore()}function os(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,g=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,g),t.strokeRect(d,u,w,g)}t.restore()}function Dt({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 as(t){return s.jsx(Dt,{...t,children:s.jsx("polyline",{points:"15 18 9 12 15 6"})})}function cs(t){return s.jsx(Dt,{...t,children:s.jsx("polyline",{points:"9 18 15 12 9 6"})})}function ls(t){return s.jsxs(Dt,{...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 ds(t){return s.jsxs(Dt,{...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 hs(t){return s.jsxs(Dt,{...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 us(t){return s.jsx(Dt,{...t,children:s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function fs(t){return s.jsxs(Dt,{...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 ps(t){return s.jsxs(Dt,{...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 gs(t){return s.jsxs(Dt,{...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 ms(t){return s.jsxs(Dt,{...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 ws(t){return s.jsxs(Dt,{...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 xs(t){return s.jsxs(Dt,{...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 ys(t){return s.jsxs(Dt,{...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 _s(t){return s.jsxs(Dt,{...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 vs(t){return s.jsxs(Dt,{...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 js({pdfDoc:t,pageNumber:e,scale:n,rotation:i,pageRef:r,onRendered:o,markupTool:d="none",markupColor:u,annotations:w=[],onAddAnnotation:g,onRemoveAnnotation:x,signatures:b=[],pendingSignature:y=null,onAddSignature:j,onUpdateSignature:C,onRemoveSignature:E,onEditSignature:U,onDuplicateSignature:L,selectedSignatureId:Y=null,onSelectSignature:I,signatureFields:st=[],selectedSignatureFieldId:rt=null,onSelectSignatureField:V,hasFixedSignatureFields:Z=!1,onOpenSignaturePad:mt,fieldValues:bt={},onFieldValueChange:X,onFieldValueCommit:Pt,pendingFieldValue:ut=null,onPlaceFieldValue:H,texts:J=[],onAddText:tt,onUpdateText:xt,onRemoveText:q,selectedTextId:Vt=null,onSelectText:dt,textFields:Yt=[],selectedTextFieldId:Ce=null,onSelectTextField:At,hasFixedTextFields:Ot=!1,editingTextId:zt=null,onEditingTextIdChange:K}){const Ct=f.useRef(null),ft=f.useRef(null),et=f.useRef(null),ot=f.useRef(null),$t=f.useRef(null),at=f.useRef(null),[wt,_t]=f.useState(null),qt=f.useRef(null),ht=f.useRef(!1);f.useEffect(()=>{if(!t||!ft.current||!et.current||!ot.current)return;let a=!1;const _=ft.current,v=et.current,k=ot.current,S=_.getContext("2d");return S?((async()=>{try{if($t.current){try{$t.current.cancel()}catch{}$t.current=null}if(at.current){try{at.current.cancel()}catch{}at.current=null}const T=await t.getPage(e);if(a)return;const M=T.getViewport({scale:n,rotation:i}),F=Math.floor(M.width),G=Math.floor(M.height);_.width=F,_.height=G,k.style.width=`${F}px`,k.style.height=`${G}px`;const D=T.render({canvasContext:S,viewport:M});if($t.current=D,await D.promise,a)return;v.replaceChildren(),v.style.setProperty("--scale-factor",String(M.scale));const nt=await T.getTextContent();if(a)return;const B=new Gn.TextLayer({textContentSource:nt,container:v,viewport:M});if(at.current=B,await B.render(),a)return;o==null||o(e)}catch{}})(),()=>{if(a=!0,$t.current){try{$t.current.cancel()}catch{}$t.current=null}if(at.current){try{at.current.cancel()}catch{}at.current=null}}):void 0},[t,e,n,i,o]),f.useEffect(()=>{const a=ot.current;if(!a)return;const _=P=>{var G;if(!g)return!1;const T=P==="redact"?Ne:u;if(!T)return!1;const M=Ye(a,n);if(!M)return!1;const F=P==="redact"?Ke(M.rects):M.rects;return g({id:Ve(),pageNumber:e,kind:P,color:T,rects:F,text:M.text}),(G=window.getSelection())==null||G.removeAllRanges(),!0},v=P=>{var nt;if(!g||!tt)return!1;const T=Ye(a,n);if(!T)return!1;const M=Ke(T.rects);g({id:Ve(),pageNumber:e,kind:"redact",color:Ne,rects:M,text:T.text});const F=En(T.rects),G=je(P||" ",F.fontSize),D={id:Fe(),pageNumber:e,x:F.x,y:F.y,width:G.width,height:G.height,value:P,fontSize:F.fontSize,color:oe};return tt(D),dt==null||dt(D.id),K==null||K(D.id),(nt=window.getSelection())==null||nt.removeAllRanges(),ht.current=!0,window.setTimeout(()=>{ht.current=!1},0),!0},k=()=>{if(d==="highlight"||d==="underline"){_(d);return}if(d==="erase"){_("redact");return}if(d==="text"){const P=window.getSelection();P&&!P.isCollapsed&&P.toString().trim()&&P.anchorNode&&a.contains(P.anchorNode)&&v(P.toString())}},S=P=>{const T=P.target;if(T!=null&&T.closest("[contenteditable='true']")||T!=null&&T.closest("[contenteditable='']")||T!=null&&T.isContentEditable)return;const M=window.getSelection(),F=M!=null&&!M.isCollapsed&&M.toString().trim().length>0&&M.anchorNode!=null&&a.contains(M.anchorNode);if(d==="text"&&F){if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),v(M.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"||F&&(P.preventDefault(),_("redact"))};return a.addEventListener("mouseup",k),window.addEventListener("keydown",S),()=>{a.removeEventListener("mouseup",k),window.removeEventListener("keydown",S)}},[d,u,g,tt,K,dt,e,n]),f.useEffect(()=>{if(!wt)return;let a=0,_=0,v=0,k=0;const S=()=>{var D;return(D=Ct.current)==null?void 0:D.closest(".epochs-pdf-viewer__body")},P=(D,nt)=>{if(wt.kind!=="resize"||!C||Z)return;const B=b.find(jt=>jt.id===wt.id);if(!B)return;const lt=ot.current,vt=lt?we(lt,n):{width:1/0,height:1/0},{dx:Wt,dy:It}=lt?Qi(D-wt.startX,nt-wt.startY,lt,n):{dx:0,dy:0},St=vt.width-B.x,pt=vt.height-B.y,Tt=Math.min(St,Math.max(40,wt.startW+Wt)),Rt=Math.min(pt,Math.max(20,wt.startH+It));C(wt.id,{width:Tt,height:Rt})},T=(D,nt)=>{var Zt;if(wt.kind!=="signature"||!C||Z)return;const B=b.find(ce=>ce.id===wt.id);if(!B)return;let lt=(Zt=document.elementFromPoint(D,nt))==null?void 0:Zt.closest("[data-page-number]");if(lt||(lt=Array.from(document.querySelectorAll(".epochs-pdf-viewer__page[data-page-number]")).find(Qt=>{const $e=Qt.getBoundingClientRect();return nt>=$e.top&&nt<=$e.bottom})??null),lt||(lt=Ct.current),!lt)return;const vt=lt.querySelector(".epochs-pdf-viewer__surface");if(!vt)return;const Wt=Number.parseInt(lt.getAttribute("data-page-number")||String(B.pageNumber),10),It=Re(D,nt,vt,n),St=we(vt,n);let pt=It.x-wt.offsetX,Tt=It.y-wt.offsetY;const Rt=Math.max(0,St.width-B.width),jt=Math.max(0,St.height-B.height);pt=Math.min(Math.max(0,pt),Rt),Tt=Math.min(Math.max(0,Tt),jt),C(wt.id,{pageNumber:Wt,x:pt,y:Tt})},M=()=>{if(a=0,!k)return;const D=S();if(!D)return;const nt=D.scrollHeight-D.clientHeight;if(nt<=0)return;const B=56,lt=D.getBoundingClientRect(),vt=v-lt.top,Wt=lt.bottom-v;let It=0;if(k<0&&vt<B)It=-Math.max(6,(B-vt)/B*28);else if(k>0&&Wt<B)It=Math.max(6,(B-Wt)/B*28);else{k=0;return}const St=D.scrollTop;D.scrollTop=Math.min(nt,Math.max(0,St+It)),D.scrollTop!==St&&T(_,v),It<0&&D.scrollTop>0||It>0&&D.scrollTop<nt?a=window.requestAnimationFrame(M):k=0},F=D=>{_=D.clientX,v=D.clientY;const nt=S();if(nt){const lt=nt.getBoundingClientRect(),vt=D.clientY-lt.top,Wt=lt.bottom-D.clientY;vt<56?(k=-1,a||(a=window.requestAnimationFrame(M))):Wt<56?(k=1,a||(a=window.requestAnimationFrame(M))):k=0}wt.kind==="resize"?P(D.clientX,D.clientY):T(D.clientX,D.clientY)},G=()=>{k=0,a&&(window.cancelAnimationFrame(a),a=0),_t(null)};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",G),window.addEventListener("pointercancel",G),()=>{k=0,a&&window.cancelAnimationFrame(a),window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",G),window.removeEventListener("pointercancel",G)}},[wt,Z,C,n,b]),f.useEffect(()=>{if(!zt||!qt.current)return;const a=qt.current,_=J.find(S=>S.id===zt);a.textContent=(_==null?void 0:_.value)??"",a.focus();const v=document.createRange();v.selectNodeContents(a),v.collapse(!1);const k=window.getSelection();k==null||k.removeAllRanges(),k==null||k.addRange(v)},[zt]);const Kt=a=>{Ct.current=a,r==null||r(a)},Nt=w.filter(a=>a.pageNumber===e),Bt=b.filter(a=>a.pageNumber===e),Ut=st.filter(a=>a.pageNumber===e),m=J.filter(a=>a.pageNumber===e),R=(a,_)=>{const v=_.trim();if(!v){q==null||q(a.id),K==null||K(null);return}const k=je(v,a.fontSize);xt==null||xt(a.id,{value:v,width:k.width,height:k.height}),K==null||K(null)},O=(a,_)=>{if(!tt)return;const v=ot.current,k=et.current;if(!v||!k)return;let S=Ji(a,_,v,k,n),P,T=oe;if(Ot){const G=ss(S.x,S.y,Yt,e);if(!G)return;const D=J.find(nt=>nt.fieldId===G.id);if(D){dt==null||dt(D.id),At==null||At(G.id),K==null||K(D.id);return}P=G.id,S={x:G.x,y:G.y,fontSize:G.fontSize??ae},T=G.color??oe,At==null||At(G.id)}const M=je("",S.fontSize),F={id:Fe(),fieldId:P,pageNumber:e,x:S.x,y:S.y,width:M.width,height:M.height,value:"",fontSize:S.fontSize,color:T};tt(F),dt==null||dt(F.id),K==null||K(F.id)},ct=a=>{var v;if(d!=="text"||a.target.closest(".epochs-pdf-viewer__inline-text"))return;if(ht.current){ht.current=!1;return}const _=window.getSelection();if(!(_&&!_.isCollapsed&&_.toString().trim())){if(a.detail>=2&&rs(a.clientX,a.clientY,et.current)){const S=ot.current;if(S&&g&&tt){const P=Ye(S,n);if(P){g({id:Ve(),pageNumber:e,kind:"redact",color:Ne,rects:Ke(P.rects),text:P.text});const T=En(P.rects),M=je(P.text||" ",T.fontSize),F={id:Fe(),pageNumber:e,x:T.x,y:T.y,width:M.width,height:M.height,value:P.text,fontSize:T.fontSize,color:oe};tt(F),dt==null||dt(F.id),K==null||K(F.id),(v=window.getSelection())==null||v.removeAllRanges(),ht.current=!0}}return}a.stopPropagation(),O(a.clientX,a.clientY)}},yt=a=>{const _=a.target;if(!(_.closest(".epochs-pdf-viewer__signature")||_.closest(".epochs-pdf-viewer__signature-field")||_.closest(".epochs-pdf-viewer__inline-text"))){if(d==="text"){O(a.clientX,a.clientY);return}if(!Z&&d==="sign"&&ut&&H){const v=ot.current;if(!v)return;const k=Re(a.clientX,a.clientY,v,n);H(e,Math.max(0,k.x-75),Math.max(0,k.y-12));return}if(!Z&&d==="sign"&&y&&j){const v=ot.current;if(!v)return;const k=we(v,n),S=Re(a.clientX,a.clientY,v,n);let P=S.x-y.width/2,T=S.y-y.height/2;const M=Math.max(0,k.width-y.width),F=Math.max(0,k.height-y.height);P=Math.min(Math.max(0,P),M),T=Math.min(Math.max(0,T),F),j({id:Se(),pageNumber:e,x:P,y:T,width:y.width,height:y.height,imageDataUrl:y.imageDataUrl});return}}},Gt=a=>zt===a.id?s.jsx("span",{ref:qt,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 k=v.currentTarget.textContent??"",S=je(k||" ",a.fontSize);xt==null||xt(a.id,{value:k,width:S.width,height:S.height})},onBlur:v=>{R(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"){q==null||q(a.id);return}d==="text"&&(dt==null||dt(a.id),K==null||K(a.id))},children:a.value},a.id):null;return s.jsx("div",{ref:Kt,"data-page-number":e,className:"epochs-pdf-viewer__page",children:s.jsxs("div",{ref:ot,className:`epochs-pdf-viewer__surface epochs-pdf-viewer__surface--tool-${d}`,onClick:yt,children:[s.jsx("canvas",{ref:ft,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((_,v)=>a.kind==="highlight"?s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--highlight",style:{left:_.x*n,top:_.y*n,width:_.w*n,height:_.h*n,background:a.color},onClick:k=>{d==="erase"&&(k.stopPropagation(),x==null||x(a.id))}},`${a.id}_${v}`):s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--underline",style:{left:_.x*n,top:(_.y+_.h)*n-Math.max(2,n*1.5),width:_.w*n,height:Math.max(2,n*1.5),background:a.color},onClick:k=>{d==="erase"&&(k.stopPropagation(),x==null||x(a.id))}},`${a.id}_${v}`)))}),s.jsxs("div",{className:"epochs-pdf-viewer__signature-layer",children:[Ut.map(a=>{const _=a.type??"sign",v=bt[a.id]??a.value??"",k=_==="date"||_==="text"?!!v.trim():Bt.some(S=>S.fieldId===a.id);return s.jsx("button",{type:"button","data-signature-field-id":a.id,className:rt===a.id?"epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--selected":k?"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:S=>{if(S.stopPropagation(),V==null||V(a.id),_==="date"||_==="text"){I==null||I(null),mt==null||mt(_);return}const P=Bt.find(T=>T.fieldId===a.id);I==null||I((P==null?void 0:P.id)??null),P?U==null||U(P.id):mt==null||mt(_)},title:k?"Completed field":_==="date"?"Date field":_==="text"?"Text field":"Signature field",children:_==="date"||_==="text"?v.trim()?s.jsx("span",{className:"epochs-pdf-viewer__signature-field-value",children:v}):_==="date"?s.jsx("span",{children:"Date here"}):s.jsx("span",{children:a.placeholder??"Enter text"}):k?null:s.jsx("span",{children:"Sign here"})},a.id)}),Bt.map(a=>s.jsxs("div",{className:Y===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:_=>{if(_.stopPropagation(),_.preventDefault(),I==null||I(a.id),d==="erase"&&!Z){E==null||E(a.id);return}if(Z){V==null||V(a.fieldId??null),U==null||U(a.id);return}const v=ot.current;if(!v)return;const k=Re(_.clientX,_.clientY,v,n);_t({kind:"signature",id:a.id,offsetX:k.x-a.x,offsetY:k.y-a.y})},children:[s.jsx("button",{type:"button",className:"epochs-pdf-viewer__signature-edit",title:"Edit signature","aria-label":"Edit signature",onPointerDown:_=>{_.stopPropagation()},onClick:_=>{_.stopPropagation(),I==null||I(a.id),U==null||U(a.id)},children:s.jsx(_s,{size:12})}),Z?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:_=>{_.stopPropagation()},onClick:_=>{_.stopPropagation(),I==null||I(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:_=>{_.stopPropagation()},onClick:_=>{_.stopPropagation(),E==null||E(a.id)},children:"×"})]}),s.jsx("img",{src:a.imageDataUrl,alt:"Signature",draggable:!1}),Z?null:s.jsx("div",{className:"epochs-pdf-viewer__signature-resize",title:"Resize",onPointerDown:_=>{_.stopPropagation(),_.preventDefault(),I==null||I(a.id),_t({kind:"resize",id:a.id,startX:_.clientX,startY:_.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:m.map(a=>Gt(a))}),s.jsx("div",{ref:et,className:"textLayer epochs-pdf-viewer__text-layer",onClick:ct}),s.jsx("div",{className:"epochs-pdf-viewer__redact-layer","aria-hidden":"true",children:Nt.map(a=>a.kind==="redact"?a.rects.map((_,v)=>s.jsx("div",{className:"epochs-pdf-viewer__markup epochs-pdf-viewer__markup--redact",style:{left:_.x*n,top:_.y*n,width:_.w*n,height:_.h*n,background:a.color||Ne},onClick:k=>{d==="erase"&&(k.stopPropagation(),x==null||x(a.id))}},`${a.id}_${v}`)):null)})]})})}function ks({pdfDoc:t,pageNumber:e,isActive:n,rotation:i,onSelect:r,width:o=140,annotations:d=[],signatures:u=[],signatureFields:w=[],texts:g=[],textFields:x=[]}){const b=f.useRef(null);return f.useEffect(()=>{if(!t||!b.current)return;let y=!1;const j=b.current,C=j.getContext("2d");if(!C)return;let E=null;return(async()=>{try{const L=await t.getPage(e);if(y)return;const Y=L.getViewport({scale:1,rotation:i}),I=o/Y.width,st=L.getViewport({scale:I,rotation:i});j.width=Math.floor(st.width),j.height=Math.floor(st.height),E=L.render({canvasContext:C,viewport:st}),await E.promise;const rt=d.filter(X=>X.pageNumber===e);rt.length>0&&qn(C,rt,I);const V=u.filter(X=>X.pageNumber===e),Z=w.filter(X=>X.pageNumber===e);Z.length>0&&Yi(C,Z,new Set(V.map(X=>X.fieldId).filter(Boolean)),I),V.length>0&&await Vn(C,V,I);const mt=g.filter(X=>X.pageNumber===e),bt=x.filter(X=>X.pageNumber===e);bt.length>0&&os(C,bt,new Set(mt.filter(X=>X.fieldId&&X.value.trim()).map(X=>X.fieldId)),I),mt.length>0&&Yn(C,mt,I)}catch{}})(),()=>{if(y=!0,E)try{E.cancel()}catch{}}},[d,t,e,i,w,u,x,g,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:b})}),s.jsx("span",{className:"epochs-pdf-viewer__thumb-label",children:e})]})}const Ms=/^(blob:|https?:|data:)/i;let Kn=!1;function en(t){me.GlobalWorkerOptions.workerSrc=t,Kn=!0}function Ns(t){if(t){en(t);return}Kn||me.GlobalWorkerOptions.workerSrc||en(`https://unpkg.com/pdfjs-dist@${me.version}/build/pdf.worker.min.mjs`)}function Ps(t,e,n=""){const i=e||t;if(!i)return"";if(Ms.test(i))return i;const r=i.startsWith("/")?i:`/${i}`;return n?`${n.replace(/\/$/,"")}${r}`:r}async function Cs(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 Un(t,e){if(typeof t=="string")return Cs(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 $s(t,e,n){const{scale:i,rotation:r,annotations:o,signatures:d=[],texts:u=[],mimeType:w="image/jpeg",quality:g=.92}=n,x=await t.getPage(e),b=x.getViewport({scale:i,rotation:r}),y=x.getViewport({scale:1,rotation:r}),j=document.createElement("canvas"),C=j.getContext("2d",{alpha:!1});if(!C)throw new Error("Could not create canvas context");const E=Math.floor(b.width),U=Math.floor(b.height);j.width=E,j.height=U,C.fillStyle="#ffffff",C.fillRect(0,0,E,U),await x.render({canvasContext:C,viewport:b}).promise;const L=o.filter(V=>V.pageNumber===e);L.length>0&&qn(C,L,i);const Y=d.filter(V=>V.pageNumber===e);Y.length>0&&await Vn(C,Y,i);const I=u.filter(V=>V.pageNumber===e);I.length>0&&Yn(C,I,i);const st=j.toDataURL(w,g),rt=Is(st);return j.width=0,j.height=0,{pageNumber:e,width:E,height:U,pageWidth:y.width,pageHeight:y.height,dataUrl:st,jpegBytes:rt}}async function Hn(t,e){const n=[];for(let i=1;i<=t.numPages;i+=1)n.push(await $s(t,i,e));return n}function Is(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 On(...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 Ts(t){const e=[],n=y=>(e.push(y),e.length),i=[];for(const y of t){const j=On(Xt(`<< /Type /XObject /Subtype /Image /Width ${y.width} /Height ${y.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${y.jpegBytes.byteLength} >>
4
4
  stream
5
- `),w.jpegBytes,Ee(`
6
- endstream`)),C=n(M),W=`q
7
- ${w.pageWidth.toFixed(2)} 0 0 ${w.pageHeight.toFixed(2)} 0 0 cm
5
+ `),y.jpegBytes,Xt(`
6
+ endstream`)),C=n(j),E=`q
7
+ ${y.pageWidth.toFixed(2)} 0 0 ${y.pageHeight.toFixed(2)} 0 0 cm
8
8
  /Im0 Do
9
- Q`,E=n(Ee(`<< /Length ${W.length} >>
9
+ Q`,U=n(Xt(`<< /Length ${E.length} >>
10
10
  stream
11
- ${W}
12
- endstream`)),O=n(Ee(`<< /Type /Page /Parent __PAGES__ 0 R /MediaBox [0 0 ${w.pageWidth.toFixed(2)} ${w.pageHeight.toFixed(2)}] /Contents ${E} 0 R /Resources << /XObject << /Im0 ${C} 0 R >> >> >>`));i.push(O)}const s=i.map(w=>`${w} 0 R`).join(" "),a=n(Ee(`<< /Type /Pages /Kids [${s}] /Count ${i.length} >>`));for(const w of i){const M=new TextDecoder().decode(t[w-1]);t[w-1]=Ee(M.replace("/Parent __PAGES__ 0 R",`/Parent ${a} 0 R`))}const c=n(Ee(`<< /Type /Catalog /Pages ${a} 0 R >>`)),l=[Ee(`%PDF-1.4
13
- `)],b=[0];let g=l[0].byteLength;for(let w=0;w<t.length;w+=1){b.push(g);const M=Ee(`${w+1} 0 obj
14
- `),C=Ee(`
11
+ ${E}
12
+ endstream`)),L=n(Xt(`<< /Type /Page /Parent __PAGES__ 0 R /MediaBox [0 0 ${y.pageWidth.toFixed(2)} ${y.pageHeight.toFixed(2)}] /Contents ${U} 0 R /Resources << /XObject << /Im0 ${C} 0 R >> >> >>`));i.push(L)}const r=i.map(y=>`${y} 0 R`).join(" "),o=n(Xt(`<< /Type /Pages /Kids [${r}] /Count ${i.length} >>`));for(const y of i){const j=new TextDecoder().decode(e[y-1]);e[y-1]=Xt(j.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 g=u[0].byteLength;for(let y=0;y<e.length;y+=1){w.push(g);const j=Xt(`${y+1} 0 obj
14
+ `),C=Xt(`
15
15
  endobj
16
- `);l.push(M,t[w],C),g+=M.byteLength+t[w].byteLength+C.byteLength}const j=g;let v=`xref
17
- 0 ${t.length+1}
18
- `;v+=`0000000000 65535 f
19
- `;for(let w=1;w<=t.length;w+=1)v+=`${String(b[w]).padStart(10,"0")} 00000 n
20
- `;return v+=`trailer
21
- << /Size ${t.length+1} /Root ${c} 0 R >>
22
- `,v+=`startxref
23
- ${j}
24
- %%EOF`,l.push(Ee(v)),vn(...l)}function Ot(e,t){const n=URL.createObjectURL(e),i=document.createElement("a");i.href=n,i.download=t,i.click(),URL.revokeObjectURL(n)}const jt=[{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"}],hr="https://fonts.googleapis.com/css2?family=Allura&family=Dancing+Script:wght@500;600&family=Great+Vibes&family=Pacifico&family=Satisfy&display=swap";let xt=null;function ur(){return typeof document>"u"?Promise.resolve():xt||(xt=new Promise(e=>{var i;if(!document.querySelector('link[data-epochs-signature-fonts="true"]')){const s=document.createElement("link");s.rel="stylesheet",s.href=hr,s.dataset.epochsSignatureFonts="true",document.head.appendChild(s)}const n=()=>Promise.all(jt.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)}),xt)}function fr({open:e,onClose:t,onSave:n,fieldType:i,showFieldTypeTabs:s=!1,textPlaceholder:a}){const c=d.useRef(null),l=d.useRef(!1),b=d.useRef(null),g=d.useRef([]),j=d.useRef([]),v=i??"sign",[w,M]=d.useState(v),[C,W]=d.useState(""),[E,O]=d.useState(""),[F,T]=d.useState("draw"),[Z,J]=d.useState(""),[G,ie]=d.useState(""),[be,me]=d.useState(!1),[L,se]=d.useState("signature"),[$,S]=d.useState("#111827"),[K,xe]=d.useState("dancing-script"),[Me,he]=d.useState(!1),we=jt.find(p=>p.id===K)??jt[0],V=L==="initials"?G.trim():Z.trim(),Se=V||(L==="initials"?"AB":"Signature");if(d.useEffect(()=>{e&&(M(v),W(new Date().toISOString().slice(0,10)),O(""))},[e,v]),d.useEffect(()=>{if(!e||w!=="sign")return;const p=c.current;if(!p)return;const m=p.getContext("2d");m&&(p.width=560,p.height=200,m.fillStyle="#ffffff",m.fillRect(0,0,p.width,p.height),m.lineCap="round",m.lineJoin="round",m.strokeStyle=$,m.lineWidth=2.5,b.current=null,l.current=!1)},[e,w]),d.useEffect(()=>{if(!e)return;let p=!1;return he(!1),ur().then(()=>{p||he(!0)}),()=>{p=!0}},[e]),d.useEffect(()=>{const p=c.current,m=p==null?void 0:p.getContext("2d");m&&(m.strokeStyle=$,m.fillStyle=$)},[$]),d.useEffect(()=>{if(!e||F!=="type")return;const p=c.current,m=p==null?void 0:p.getContext("2d");if(!p||!m||(m.fillStyle="#ffffff",m.fillRect(0,0,p.width,p.height),!V))return;const H=L==="initials"?72:we.family==="Great Vibes"||we.family==="Allura"?56:we.family==="Pacifico"?44:48;m.fillStyle=$,m.textAlign="center",m.textBaseline="middle",m.font=`${H}px "${we.family}", cursive`,m.fillText(V,p.width/2,p.height/2)},[V,L,F,$,e,we,Me]),!e)return null;const We=p=>{const m=c.current,H=m.getBoundingClientRect();return{x:(p.clientX-H.left)/H.width*m.width,y:(p.clientY-H.top)/H.height*m.height}},_e=p=>{if(F!=="draw")return;p.currentTarget.setPointerCapture(p.pointerId),l.current=!0;const m=We(p);b.current=m,j.current=[m]},Ae=p=>{if(!l.current||F!=="draw")return;const m=c.current,H=m==null?void 0:m.getContext("2d"),X=b.current;if(!H||!X)return;const re=We(p);H.beginPath(),H.moveTo(X.x,X.y),H.lineTo(re.x,re.y),H.stroke(),b.current=re,j.current.push(re)},ye=()=>{j.current.length>1&&g.current.push([...j.current]),j.current=[],l.current=!1,b.current=null},A=()=>{const p=c.current,m=p==null?void 0:p.getContext("2d");!p||!m||(m.fillStyle="#ffffff",m.fillRect(0,0,p.width,p.height),g.current=[],j.current=[],J(""),ie(""),me(!1))},ue=p=>{J(p),be||ie(pr(p))},Fe=()=>{if(F==="draw"){const p=g.current;if(p.length===0)return;let m=1/0,H=1/0,X=-1/0,re=-1/0;for(const Ge of p)for(const Ne of Ge)Ne.x<m&&(m=Ne.x),Ne.y<H&&(H=Ne.y),Ne.x>X&&(X=Ne.x),Ne.y>re&&(re=Ne.y);const ne=8;m=Math.max(0,m-ne),H=Math.max(0,H-ne),X+=ne,re+=ne;const Pe=X-m,oe=re-H,De=p.map(Ge=>"M"+Ge.map(Oe=>({x:Oe.x-m,y:Oe.y-H})).map(Oe=>`${Oe.x.toFixed(1)},${Oe.y.toFixed(1)}`).join("L")).join(" "),Re=`<svg xmlns="http://www.w3.org/2000/svg" width="${Pe.toFixed(0)}" height="${oe.toFixed(0)}" viewBox="0 0 ${Pe.toFixed(0)} ${oe.toFixed(0)}"><path d="${De}" fill="none" stroke="${$}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,Be=`data:image/svg+xml;base64,${btoa(Re)}`;n(Be,Pe,oe)}else{if(!V)return;const p=3,m=L==="initials"?72:we.family==="Great Vibes"||we.family==="Allura"?56:we.family==="Pacifico"?44:48,X=document.createElement("canvas").getContext("2d");X.font=`${m*p}px "${we.family}", cursive`;const re=X.measureText(V),ne=12*p,Pe=Math.ceil(re.width)+ne*2,oe=m*p+ne*2,De=document.createElement("canvas");De.width=Pe,De.height=oe;const Re=De.getContext("2d");Re.clearRect(0,0,Pe,oe),Re.font=`${m*p}px "${we.family}", cursive`,Re.fillStyle=$,Re.textBaseline="middle",Re.fillText(V,ne,oe/2);const Be=De.toDataURL("image/png");n(Be,Pe/p,oe/p)}},te=()=>{const p=w==="date"?C:E.trim();if(!p)return;const m=document.createElement("canvas"),H=m.getContext("2d"),X=16;H.font=`${X}px sans-serif`;const re=H.measureText(p),ne=8;m.width=Math.ceil(re.width)+ne*2,m.height=X+ne*2,H.clearRect(0,0,m.width,m.height),H.font=`${X}px sans-serif`,H.fillStyle="#111827",H.textBaseline="middle",H.fillText(p,ne,m.height/2);const Pe=m.toDataURL("image/png");n(Pe,m.width,m.height)},fe=w==="sign",le=w==="date"?"Pick a date":w==="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:le}),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":w===p,className:w===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:()=>M(p),children:p==="sign"?"Sign":p==="date"?"Date":"Text"},p))}):null,fe?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"epochs-pdf-viewer__sign-modes",children:[r.jsx("button",{type:"button",className:F==="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:()=>{T("draw"),A()},children:"Draw"}),r.jsx("button",{type:"button",className:F==="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:()=>T("type"),children:"Type"}),r.jsxs("label",{className:"epochs-pdf-viewer__sign-ink",children:["Ink",r.jsx("input",{type:"color",value:$,onChange:p=>S(p.target.value)})]})]}),F==="type"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"epochs-pdf-viewer__sign-fonts",role:"group","aria-label":"Handwriting style",children:jt.map(p=>r.jsx("button",{type:"button",className:K===p.id?"epochs-pdf-viewer__sign-font epochs-pdf-viewer__sign-font--active":"epochs-pdf-viewer__sign-font",style:{fontFamily:`"${p.family}", cursive`},onClick:()=>xe(p.id),title:p.label,children:Se},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:Z,onChange:p=>ue(p.target.value),onFocus:()=>se("signature"),placeholder:"Type your full name",style:{fontFamily:`"${we.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:G,onChange:p=>{me(!0),ie(p.target.value.toUpperCase())},onFocus:()=>se("initials"),placeholder:"e.g. JD",maxLength:4,style:{fontFamily:`"${we.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:L==="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:()=>se("signature"),children:"Use full name"}),r.jsx("button",{type:"button",className:L==="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:()=>se("initials"),children:"Use initials"})]})]}):r.jsx("p",{className:"epochs-pdf-viewer__sign-hint",children:"Draw your signature below"}),r.jsx("canvas",{ref:c,className:F==="draw"?"epochs-pdf-viewer__sign-canvas":"epochs-pdf-viewer__sign-canvas epochs-pdf-viewer__sign-canvas--preview",onPointerDown:_e,onPointerMove:Ae,onPointerUp:ye,onPointerLeave:ye})]}):w==="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:C,onChange:p=>W(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=>O(p.target.value),placeholder:a??"Enter text",autoFocus:!0})]}),r.jsxs("div",{className:"epochs-pdf-viewer__modal-actions",children:[fe?r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:A,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:fe?Fe:te,disabled:w==="date"?!C:w==="text"?!E.trim():!1,children:fe?"Use signature":"Place on page"})]})]})]})}function pr(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 kt="__epochsToolbarToolId";function $e(e,t){const n=(()=>null);return n.displayName=t,Object.defineProperty(n,kt,{value:e,enumerable:!0}),n}function jn(e){return e[kt]}function gr(e){return typeof e=="function"&&kt in e&&typeof e[kt]=="string"}const qt=$e("thumbnail","Thumbnail"),Yt=$e("navigation","Navigation"),Zt=$e("zoom","Zoom"),Kt=$e("rotate","Rotate"),Vt=$e("reload","Reload"),Qt=$e("print","Print"),Jt=$e("open","Open"),en=$e("download","Download"),tn=$e("highlight","Highlight"),nn=$e("underline","Underline"),rn=$e("signature","Signature"),sn=$e("text","AddText"),on=$e("erase","Erase"),an=$e("clear","Clear"),mr=[qt,Yt,Zt,Kt,tn,nn,rn,sn,on,an,Vt,Qt,Jt,en],zt=[[qt,Yt],[Zt,Kt,tn,nn,rn,sn,on,an,Vt,Qt,Jt,en]],wr=["highlight","underline","signature","text","erase","clear"];function kn(e){return wr.includes(e)}function yr(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(Wi,{})},"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(Oi,{})},"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 a=Number.parseInt(s.target.value,10);Number.isFinite(a)&&t.scrollToPage(Math.max(1,Math.min(t.numPages||1,a)))},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(Hi,{})},"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(Gi,{})},"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(Xi,{})},"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(Zi,{})},"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(Ki,{})},"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(Vi,{})},"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(Ji,{})},"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(tr,{})},"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(Qi,{})},"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(Yi,{})},"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(Ui,{})},"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(zi,{})},"download"));break}return i.length>0?i:null}function br(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,a=e.markupTool==="highlight"?Wt:Gt;n.push(r.jsxs("div",{className:"epochs-pdf-viewer__color-picker",role:"group","aria-label":`${e.markupTool} color`,children:[a.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 xr(e,t){if(!e)return null;if(Array.isArray(e)){const a=c=>(c??[]).filter(gr).map(jn);return{left:a(e[0]),right:a(e[1])}}const n=t.enableThumbnails,i=(a,c)=>a.map(jn).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(zt[0],s),right:i(zt[1],s)}}function Rn({file:e,fileUrl:t,baseUrl:n="",fetchOptions:i,height:s="80vh",title:a="PDF document",initialScale:c=1,withThumbnails:l=!1,thumbnailWidth:b=140,maxThumbnails:g=60,className:j,workerSrc:v,enableToolbar:w=!1,enableThumbnails:M,enableNavigation:C=!0,enableZoom:W=!0,enableRotate:E=!0,enableReload:O=!0,enablePrint:F=!0,enableOpen:T=!0,enableDownload:Z=!0,enableMarkup:J=!0,enableHighlight:G=!0,enableUnderline:ie=!0,enableSignature:be=!0,enableText:me=!0,enableErase:L=!0,enableClear:se=!0,signatureFields:$=[],textFields:S=[],onSignatureComplete:K,onFieldValueComplete:xe,openSignaturePad:Me=!1,onSignaturePadClose:he,onSubmit:we,submitLabel:V="Submit"}){const Se=d.useRef(null),We=d.useRef(null),_e=d.useRef(new Map),Ae=d.useRef(!1),ye=d.useMemo(()=>e&&typeof e!="string"?e:null,[e]),A=d.useMemo(()=>ye?"":or(typeof e=="string"?e:void 0,t,n),[ye,e,t,n]),[ue,Fe]=d.useState("idle"),[te,fe]=d.useState(null),[le,p]=d.useState(0),[m,H]=d.useState(1),[X,re]=d.useState(c),[ne,Pe]=d.useState(0),[oe,De]=d.useState(null),[Re,Be]=d.useState(!1),[Ge,Ne]=d.useState(!1),[Oe,mt]=d.useState(!1),[o,y]=d.useState("none"),[_,k]=d.useState([]),[P,N]=d.useState([]),[R,z]=d.useState([]),[Y,U]=d.useState(!1),[B,ae]=d.useState(void 0),[ce,ee]=d.useState(null),[ve,de]=d.useState(null),[pe,je]=d.useState(null),[He,Le]=d.useState(null),[st,ze]=d.useState(null),[wt,Xe]=d.useState(null),[Mt,Ze]=d.useState(null),[dn,qn]=d.useState(Pn),[hn,Yn]=d.useState(Pi),Ie=$.length>0,ot=S.length>0,[Je,Zn]=d.useState({});d.useEffect(()=>{Me&&U(!0)},[Me]);const Ke=d.useMemo(()=>xr(w,{enableThumbnails:M,enableNavigation:C,enableZoom:W,enableRotate:E,enableReload:O,enablePrint:F,enableOpen:T,enableDownload:Z,enableHighlight:G,enableUnderline:ie,enableSignature:be,enableText:me,enableErase:L,enableClear:se}),[w,M,C,W,E,O,F,T,Z,G,ie,be,me,L,se]),Ve=d.useMemo(()=>Ke?new Set([...Ke.left,...Ke.right]):new Set,[Ke]);d.useEffect(()=>{if(!Ve.has("thumbnail")){Be(!1);return}const f=window.matchMedia("(max-width: 720px)"),h=()=>{Be(f.matches?!1:l)};return h(),f.addEventListener("change",h),()=>f.removeEventListener("change",h)},[Ve,l]);const un=!Ie&&Ve.has("highlight"),fn=!Ie&&Ve.has("underline"),Pt=Ve.has("signature")||Ie,pn=Ve.has("text")||ot,gn=!Ie&&Ve.has("erase"),at=d.useCallback(()=>{We.current&&(URL.revokeObjectURL(We.current),We.current=null)},[]),Nt=d.useCallback(async()=>{if(!(!ye&&!A)){sr(v),Fe("loading"),fe(null),p(0),H(1),k([]),N([]),z([]),ee(null),de(null),je(null),Le(null),ze(null),Xe(null),Ze(null),y("none");try{const u=ye?await xn(ye,i):await xn(A,i),f=new Blob([u],{type:"application/pdf"}),h=URL.createObjectURL(f);at(),We.current=h,De(h);const D=await rt.getDocument({data:u,cMapUrl:`https://unpkg.com/pdfjs-dist@${rt.version}/cmaps/`,cMapPacked:!0,standardFontDataUrl:`https://unpkg.com/pdfjs-dist@${rt.version}/standard_fonts/`}).promise;fe(D),p(D.numPages),Fe("ready")}catch{Fe("error")}}},[ye,A,i,at,v]);d.useEffect(()=>{if(!ye&&!A){Fe("idle"),fe(null),p(0),De(null),at();return}return Nt(),()=>{at()}},[ye,A,Nt,at]),d.useEffect(()=>{(o==="highlight"&&!un||o==="underline"&&!fn||o==="sign"&&!Pt||o==="text"&&!pn||o==="erase"&&!gn)&&y("none")},[un,fn,Pt,pn,gn,o]);const et=d.useCallback(u=>{const f=Math.max(1,Math.min(le||1,u)),h=_e.current.get(f);if(!h){H(f);return}Ae.current=!0,h.scrollIntoView({behavior:"smooth",block:"start"}),H(f),window.setTimeout(()=>{Ae.current=!1},500)},[le]),tt=d.useCallback(u=>{const f=_e.current.get(u.pageNumber);f&&(Ae.current=!0,H(u.pageNumber));const h=()=>{var D;const x=(D=Se.current)==null?void 0:D.querySelector(`[data-signature-field-id="${CSS.escape(u.id)}"]`);x?x.scrollIntoView({behavior:"smooth",block:"center"}):f&&f.scrollIntoView({behavior:"smooth",block:"start"}),window.setTimeout(()=>{Ae.current=!1},500)};window.requestAnimationFrame(()=>{window.setTimeout(h,40)})},[]);d.useEffect(()=>{if(ue!=="ready"||!Se.current||!le)return;const u=Se.current,f=new IntersectionObserver(h=>{if(Ae.current)return;let x=null;for(const D of h){if(!D.isIntersecting)continue;const I=Number.parseInt(D.target.dataset.pageNumber||"0",10);I&&(!x||D.intersectionRatio>x.ratio)&&(x={page:I,ratio:D.intersectionRatio})}x&&H(x.page)},{root:u,threshold:[.25,.5,.75]});for(let h=1;h<=le;h+=1){const x=_e.current.get(h);x&&f.observe(x)}return()=>f.disconnect()},[ue,le]);const Ct=m>1,Tt=le?m<le:!1,Kn=d.useCallback(()=>{Ct&&et(m-1)},[Ct,m,et]),Vn=d.useCallback(()=>{Tt&&et(m+1)},[Tt,m,et]),Qn=d.useCallback(()=>{Pe(u=>(u+90)%360)},[]),Jn=d.useCallback(()=>{re(u=>Math.max(.25,Math.round((u-.1)*100)/100))},[]),ei=d.useCallback(()=>{re(u=>Math.min(5,Math.round((u+.1)*100)/100))},[]),$t=d.useCallback(async()=>{if(!(!te||!Se.current))try{const f=(await te.getPage(m)).getViewport({scale:1,rotation:ne}),x=window.matchMedia("(max-width: 720px)").matches?16:24,I=Math.max(0,Se.current.clientWidth-x)/f.width;re(Math.max(.25,Math.min(5,Math.round(I*100)/100)))}catch{}},[te,m,ne]);d.useEffect(()=>{if(ue!=="ready"||!te||!window.matchMedia("(max-width: 720px)").matches)return;let u=!1;const f=()=>{u||$t()};f();const h=Se.current,x=typeof ResizeObserver<"u"&&h?new ResizeObserver(()=>f()):null;x==null||x.observe(h);const D=window.matchMedia("(max-width: 720px)"),I=()=>{D.matches&&f()};return D.addEventListener("change",I),()=>{u=!0,x==null||x.disconnect(),D.removeEventListener("change",I)}},[ue,te,Re,ne,$t]);const ti=d.useCallback(async()=>{var u;if(!(!te||ue!=="ready")){Ne(!0);try{const f=await _n(te,{scale:1.5,rotation:ne,annotations:_,signatures:P,texts:R,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 x=(u=h.contentWindow)==null?void 0:u.document;if(!x)throw new Error("print iframe not available");x.open(),x.write(`<!doctype html>
16
+ `);u.push(j,e[y],C),g+=j.byteLength+e[y].byteLength+C.byteLength}const x=g;let b=`xref
17
+ 0 ${e.length+1}
18
+ `;b+=`0000000000 65535 f
19
+ `;for(let y=1;y<=e.length;y+=1)b+=`${String(w[y]).padStart(10,"0")} 00000 n
20
+ `;return b+=`trailer
21
+ << /Size ${e.length+1} /Root ${d} 0 R >>
22
+ `,b+=`startxref
23
+ ${x}
24
+ %%EOF`,u.push(Xt(b)),On(...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"}],Rs="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;const tn=new Map;function Ls(){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=Rs,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 Ds(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Ss(t){let e="";for(let i=0;i<t.length;i+=32768)e+=String.fromCharCode(...t.subarray(i,i+32768));return btoa(e)}function zn(t,e){return t==="initials"?72:e==="Great Vibes"||e==="Allura"?56:e==="Pacifico"?44:48}function Fs(t){const e=tn.get(t);if(e)return e;const n=(async()=>{const r=`https://fonts.googleapis.com/css2?family=${t.replace(/ /g,"+")}&display=swap`,o=await fetch(r).then(x=>{if(!x.ok)throw new Error(`Failed to load font CSS for ${t}`);return x.text()}),d=[...o.matchAll(/url\((['"]?)([^)'"]+)\1\)/g)].map(x=>x[2]),u=[...new Set(d)],w=await Promise.all(u.map(async x=>{const b=await fetch(x).then(E=>{if(!E.ok)throw new Error(`Failed to load font file: ${x}`);return E.arrayBuffer()}),y=x.includes(".woff2")?"woff2":x.includes(".woff")?"woff":"truetype",C=`data:${y==="woff2"?"font/woff2":y==="woff"?"font/woff":"font/ttf"};base64,${Ss(new Uint8Array(b))}`;return{fontUrl:x,dataUrl:C}}));let g=o;for(const{fontUrl:x,dataUrl:b}of w)g=g.split(x).join(b);return g})().catch(()=>(tn.delete(t),""));return tn.set(t,n),n}function Es({open:t,onClose:e,onSave:n,onSaveFieldValue:i,fieldType:r,showFieldTypeTabs:o=!1,textPlaceholder:d,initialFieldValue:u,rememberedByType:w,onRememberFill:g}){const x=f.useRef(null),b=f.useRef(!1),y=f.useRef(null),j=f.useRef([]),C=f.useRef([]),E=f.useRef(null),U=r??"sign",[L,Y]=f.useState(U),[I,st]=f.useState(""),[rt,V]=f.useState(""),[Z,mt]=f.useState("draw"),[bt,X]=f.useState(""),[Pt,ut]=f.useState(""),[H,J]=f.useState(!1),[tt,xt]=f.useState("signature"),[q,Vt]=f.useState("#111827"),[dt,Yt]=f.useState("dancing-script"),[Ce,At]=f.useState(!1),[Ot,zt]=f.useState(!1),[K,Ct]=f.useState(!1),ft=Pe.find(m=>m.id===dt)??Pe[0],et=tt==="initials"?Pt.trim():bt.trim(),ot=et||(tt==="initials"?"AB":"Signature");if(f.useEffect(()=>{var O,ct;if(!t)return;if(Y(U),U==="date"){st(u||((O=w==null?void 0:w.date)==null?void 0:O.value)||new Date().toISOString().slice(0,10));return}if(U==="text"){V(u||((ct=w==null?void 0:w.text)==null?void 0:ct.value)||"");return}const m=w==null?void 0:w.sign;if(!m){mt("draw"),X(""),ut(""),J(!1),xt("signature"),Vt("#111827"),Yt("dancing-script"),E.current=null,Ct(!1);return}mt(m.mode),X(m.typedName??""),ut(m.typedInitials??""),J(!!m.typedInitials),xt(m.typeKind??"signature"),Vt(m.inkColor??"#111827");const R=Pe.find(yt=>yt.id===m.fontId);R&&Yt(R.id),m.mode==="draw"?(E.current={imageDataUrl:m.imageDataUrl,width:m.width,height:m.height},Ct(!0)):(E.current=null,Ct(!1))},[t,U,w,u]),f.useEffect(()=>{if(!t||L!=="sign")return;const m=x.current;if(!m)return;const R=m.getContext("2d");if(!R||(m.width=560,m.height=200,R.fillStyle="#ffffff",R.fillRect(0,0,m.width,m.height),R.lineCap="round",R.lineJoin="round",R.strokeStyle=q,R.lineWidth=2.5,y.current=null,b.current=!1,j.current=[],C.current=[],Z!=="draw"))return;const O=E.current;if(!(O!=null&&O.imageDataUrl))return;const ct=new Image;ct.onload=()=>{const yt=Math.min(m.width/Math.max(1,O.width),m.height/Math.max(1,O.height),1),Gt=O.width*yt,a=O.height*yt;R.drawImage(ct,(m.width-Gt)/2,(m.height-a)/2,Gt,a)},ct.src=O.imageDataUrl},[t,L,Z]),f.useEffect(()=>{if(!t)return;let m=!1;return At(!1),Ls().then(()=>{m||At(!0)}),()=>{m=!0}},[t]),f.useEffect(()=>{const m=x.current,R=m==null?void 0:m.getContext("2d");R&&(R.strokeStyle=q,R.fillStyle=q)},[q]),f.useEffect(()=>{if(!t||Z!=="type")return;const m=x.current,R=m==null?void 0:m.getContext("2d");if(!m||!R||(R.fillStyle="#ffffff",R.fillRect(0,0,m.width,m.height),!et))return;const O=zn(tt,ft.family);R.fillStyle=q,R.textAlign="center",R.textBaseline="middle",R.font=`${O}px "${ft.family}", cursive`,R.fillText(et,m.width/2,m.height/2)},[et,tt,Z,q,t,ft,Ce]),!t)return null;const $t=m=>{const R=x.current,O=R.getBoundingClientRect();return{x:(m.clientX-O.left)/O.width*R.width,y:(m.clientY-O.top)/O.height*R.height}},at=m=>{if(Z!=="draw")return;if(E.current){E.current=null,Ct(!1);const O=x.current,ct=O==null?void 0:O.getContext("2d");O&&ct&&(ct.fillStyle="#ffffff",ct.fillRect(0,0,O.width,O.height),ct.strokeStyle=q,ct.lineWidth=2.5,ct.lineCap="round",ct.lineJoin="round"),j.current=[]}m.currentTarget.setPointerCapture(m.pointerId),b.current=!0;const R=$t(m);y.current=R,C.current=[R]},wt=m=>{if(!b.current||Z!=="draw")return;const R=x.current,O=R==null?void 0:R.getContext("2d"),ct=y.current;if(!O||!ct)return;const yt=$t(m);O.beginPath(),O.moveTo(ct.x,ct.y),O.lineTo(yt.x,yt.y),O.stroke(),y.current=yt,C.current.push(yt)},_t=()=>{C.current.length>1&&j.current.push([...C.current]),C.current=[],b.current=!1,y.current=null},qt=()=>{const m=x.current,R=m==null?void 0:m.getContext("2d");!m||!R||(R.fillStyle="#ffffff",R.fillRect(0,0,m.width,m.height),j.current=[],C.current=[],E.current=null,Ct(!1),X(""),ut(""),J(!1))},ht=m=>{X(m),H||ut(As(m))},Kt=()=>{if(Z==="draw"){const P=j.current,T=E.current;if(P.length===0){if(!T)return;g==null||g("sign",{mode:"draw",imageDataUrl:T.imageDataUrl,width:T.width,height:T.height,inkColor:q}),n(T.imageDataUrl,T.width,T.height);return}let M=1/0,F=1/0,G=-1/0,D=-1/0;for(const St of P)for(const pt of St)pt.x<M&&(M=pt.x),pt.y<F&&(F=pt.y),pt.x>G&&(G=pt.x),pt.y>D&&(D=pt.y);const nt=8;M=Math.max(0,M-nt),F=Math.max(0,F-nt),G+=nt,D+=nt;const B=G-M,lt=D-F,vt=P.map(St=>"M"+St.map(Tt=>({x:Tt.x-M,y:Tt.y-F})).map(Tt=>`${Tt.x.toFixed(1)},${Tt.y.toFixed(1)}`).join("L")).join(" "),Wt=`<svg xmlns="http://www.w3.org/2000/svg" width="${B.toFixed(0)}" height="${lt.toFixed(0)}" viewBox="0 0 ${B.toFixed(0)} ${lt.toFixed(0)}"><path d="${vt}" fill="none" stroke="${q}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,It=`data:image/svg+xml;base64,${btoa(Wt)}`;g==null||g("sign",{mode:"draw",imageDataUrl:It,width:B,height:lt,inkColor:q}),n(It,B,lt);return}if(!et)return;const m=zn(tt,ft.family),O=document.createElement("canvas").getContext("2d");O.font=`${m}px "${ft.family}", cursive`;const ct=O.measureText(et),yt=12,Gt=Math.ceil(ct.width)+yt*2,a=m+yt*2,_=et,v=ft.family,k=q,S={mode:"type",imageDataUrl:"",width:Gt,height:a,typedName:bt,typedInitials:Pt,fontId:dt,inkColor:k,typeKind:tt};zt(!0),(async()=>{try{const T=[await Fs(v),`text{font-family:'${v}',cursive;font-size:${m}px;fill:${k}}`].filter(Boolean).join(`
25
+ `),M=[`<svg xmlns="http://www.w3.org/2000/svg" width="${Gt}" height="${a}" viewBox="0 0 ${Gt} ${a}">`,`<style type="text/css"><![CDATA[${T}]]></style>`,`<text x="${yt}" y="${(a/2).toFixed(1)}" dominant-baseline="middle">${Ds(_)}</text>`,"</svg>"].join(""),F=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(M)}`;g==null||g("sign",{...S,imageDataUrl:F}),n(F,Gt,a)}finally{zt(!1)}})()},Nt=()=>{if(L!=="date"&&L!=="text")return;const m=L==="date"?I:rt.trim();m&&(g==null||g(L,{value:m}),i==null||i(m,L))},Bt=L==="sign",Ut=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:Ut}),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(m=>s.jsx("button",{type:"button",role:"tab","aria-selected":L===m,className:L===m?"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active":"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:()=>Y(m),children:m==="sign"?"Sign":m==="date"?"Date":"Text"},m))}):null,Bt?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"epochs-pdf-viewer__sign-modes",children:[s.jsx("button",{type:"button",className:Z==="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:()=>{mt("draw"),qt()},children:"Draw"}),s.jsx("button",{type:"button",className:Z==="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:()=>mt("type"),children:"Type"}),s.jsxs("label",{className:"epochs-pdf-viewer__sign-ink",children:["Ink",s.jsx("input",{type:"color",value:q,onChange:m=>Vt(m.target.value)})]})]}),Z==="type"?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"epochs-pdf-viewer__sign-fonts",role:"group","aria-label":"Handwriting style",children:Pe.map(m=>s.jsx("button",{type:"button",className:dt===m.id?"epochs-pdf-viewer__sign-font epochs-pdf-viewer__sign-font--active":"epochs-pdf-viewer__sign-font",style:{fontFamily:`"${m.family}", cursive`},onClick:()=>Yt(m.id),title:m.label,children:ot},m.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:bt,onChange:m=>ht(m.target.value),onFocus:()=>xt("signature"),placeholder:"Type your full name",style:{fontFamily:`"${ft.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:m=>{J(!0),ut(m.target.value.toUpperCase())},onFocus:()=>xt("initials"),placeholder:"e.g. JD",maxLength:4,style:{fontFamily:`"${ft.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:tt==="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:()=>xt("signature"),children:"Use full name"}),s.jsx("button",{type:"button",className:tt==="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:()=>xt("initials"),children:"Use initials"})]})]}):s.jsx("p",{className:"epochs-pdf-viewer__sign-hint",children:K?"Previous signature loaded — submit to reuse, or draw a new one":"Draw your signature below"}),s.jsx("canvas",{ref:x,className:Z==="draw"?"epochs-pdf-viewer__sign-canvas":"epochs-pdf-viewer__sign-canvas epochs-pdf-viewer__sign-canvas--preview",onPointerDown:at,onPointerMove:wt,onPointerUp:_t,onPointerLeave:_t})]}):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:I,onChange:m=>st(m.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:rt,onChange:m=>V(m.target.value),placeholder:d??"Enter text",autoFocus:!0})]}),s.jsxs("div",{className:"epochs-pdf-viewer__modal-actions",children:[Bt?s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",onClick:qt,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:Bt?Kt:Nt,disabled:Ot||(L==="date"?!I:L==="text"?!rt.trim():!1),children:Ot?"Saving…":Bt?"Use signature":"Place on page"})]})]})]})}function As(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 Bn(t){return t[Ee]}function Us(t){return typeof t=="function"&&Ee in t&&typeof t[Ee]=="string"}const cn=Et("thumbnail","Thumbnail"),ln=Et("navigation","Navigation"),dn=Et("zoom","Zoom"),hn=Et("rotate","Rotate"),un=Et("reload","Reload"),fn=Et("print","Print"),pn=Et("open","Open"),gn=Et("download","Download"),mn=Et("highlight","Highlight"),wn=Et("underline","Underline"),xn=Et("signature","Signature"),yn=Et("text","AddText"),bn=Et("erase","Erase"),_n=Et("clear","Clear"),Hs=[cn,ln,dn,hn,mn,wn,xn,yn,bn,_n,un,fn,pn,gn],nn=[[cn,ln],[dn,hn,mn,wn,xn,yn,bn,_n,un,fn,pn,gn]],Os=["highlight","underline","signature","text","erase","clear"];function Wn(t){return Os.includes(t)}function zs(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(hs,{})},"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(as,{})},"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(cs,{})},"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(us,{})},"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(fs,{})},"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(ms,{})},"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(ws,{})},"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(xs,{})},"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(vs,{})},"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(ys,{})},"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(gs,{})},"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(ps,{})},"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(ds,{})},"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(ls,{})},"download"));break}return i.length>0?i:null}function Bs(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"?rn:on;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 Ws(t,e){if(!t)return null;if(Array.isArray(t)){const o=d=>(d??[]).filter(Us).map(Bn);return{left:o(t[0]),right:o(t[1])}}const n=e.enableThumbnails,i=(o,d)=>o.map(Bn).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(nn[0],r),right:i(nn[1],r)}}function Zn({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:g=60,className:x,workerSrc:b,enableToolbar:y=!1,enableThumbnails:j,enableNavigation:C=!0,enableZoom:E=!0,enableRotate:U=!0,enableReload:L=!0,enablePrint:Y=!0,enableOpen:I=!0,enableDownload:st=!0,enableMarkup:rt=!0,enableHighlight:V=!0,enableUnderline:Z=!0,enableSignature:mt=!0,enableText:bt=!0,enableErase:X=!0,enableClear:Pt=!0,signatureFields:ut=[],textFields:H=[],onSignatureComplete:J,onSignatureFieldsChange:tt,applySignatureToSameTag:xt=!1,onFieldValueComplete:q,openSignaturePad:Vt=!1,onSignaturePadClose:dt,onSubmit:Yt,submitLabel:Ce="Submit",submitLoading:At=!1}){var Sn,Fn;const Ot=f.useRef(null),zt=f.useRef(null),K=f.useRef(new Map),Ct=f.useRef(!1),ft=f.useMemo(()=>t&&typeof t!="string"?t:null,[t]),et=f.useMemo(()=>ft?"":Ps(typeof t=="string"?t:void 0,e,n),[ft,t,e,n]),[ot,$t]=f.useState("idle"),[at,wt]=f.useState(null),[_t,qt]=f.useState(0),[ht,Kt]=f.useState(1),[Nt,Bt]=f.useState(d),[Ut,m]=f.useState(0),[R,O]=f.useState(null),[ct,yt]=f.useState(!1),[Gt,a]=f.useState(!1),[_,v]=f.useState(!1),[k,S]=f.useState("none"),[P,T]=f.useState([]),[M,F]=f.useState([]),[G,D]=f.useState([]),[nt,B]=f.useState(!1),[lt,vt]=f.useState(void 0),[Wt,It]=f.useState({}),[St,pt]=f.useState(null),[Tt,Rt]=f.useState(null),[jt,Zt]=f.useState(null),[ce,Qt]=f.useState(null),[$e,le]=f.useState(null),[fi,xe]=f.useState(null),[pi,Ie]=f.useState(null),[kn,gi]=f.useState(Xn),[Mn,mi]=f.useState(Vi),ye=H.length>0,[Ht,Ae]=f.useState({}),[A,Ue]=f.useState(ut),de=f.useRef(A);de.current=A,f.useEffect(()=>{de.current=ut,Ue(ut),Ae(c=>{const h={...c};for(const l of ut){const p=l.type??"sign";(p==="date"||p==="text")&&l.value!=null&&l.value!==""&&(h[l.id]=l.value)}return h})},[ut]);const Lt=A.length>0,be=f.useCallback((c,h,l)=>{var N;const p=c.type??"sign";return p==="date"||p==="text"?!!((N=l[c.id]??c.value)!=null&&N.trim()):h.some($=>$.fieldId===c.id)||!!c.signatureDataUrl},[]),Nn=f.useCallback((c,h)=>{const l=new Set(c),N=de.current.map($=>l.has($.id)?{...$,value:h}:$);de.current=N,Ue(N),tt==null||tt(N),Ae($=>{const z={...$};for(const it of c)z[it]=h;return z});for(const $ of c)q==null||q($,h)},[q,tt]),_e=f.useCallback((c,h,l)=>{const p=de.current,N=c==null?null:Array.isArray(c)?c:[c],$=N?new Set(N):null,z=$?p.map(it=>$.has(it.id)?{...it,signatureDataUrl:h.imageDataUrl}:it):[...p,{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=z,Ue(z),tt==null||tt(z),!N||N.length===0){J==null||J(void 0,h);return}for(const it of N)J==null||J(it,(l==null?void 0:l.get(it))??h)},[J,tt]);f.useEffect(()=>{Vt&&B(!0)},[Vt]);const ne=f.useMemo(()=>Ws(y,{enableThumbnails:j,enableNavigation:C,enableZoom:E,enableRotate:U,enableReload:L,enablePrint:Y,enableOpen:I,enableDownload:st,enableHighlight:V,enableUnderline:Z,enableSignature:mt,enableText:bt,enableErase:X,enableClear:Pt}),[y,j,C,E,U,L,Y,I,st,V,Z,mt,bt,X,Pt]),ie=f.useMemo(()=>ne?new Set([...ne.left,...ne.right]):new Set,[ne]);f.useEffect(()=>{if(!ie.has("thumbnail")){yt(!1);return}const h=window.matchMedia("(max-width: 720px)"),l=()=>{yt(h.matches?!1:u)};return l(),h.addEventListener("change",l),()=>h.removeEventListener("change",l)},[ie,u]);const Pn=!Lt&&ie.has("highlight"),Cn=!Lt&&ie.has("underline"),He=ie.has("signature")||Lt,$n=ie.has("text")||ye,In=!Lt&&ie.has("erase"),ve=f.useCallback(()=>{zt.current&&(URL.revokeObjectURL(zt.current),zt.current=null)},[]),Oe=f.useCallback(async()=>{if(!(!ft&&!et)){Ns(b),$t("loading"),wt(null),qt(0),Kt(1),T([]),F([]),D([]),pt(null),Rt(null),Zt(null),Qt(null),le(null),xe(null),Ie(null),S("none");try{const c=ft?await Un(ft,i):await Un(et,i),h=new Blob([c],{type:"application/pdf"}),l=URL.createObjectURL(h);ve(),zt.current=l,O(l);const N=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;wt(N),qt(N.numPages),$t("ready")}catch{$t("error")}}},[ft,et,i,ve,b]);f.useEffect(()=>{if(!ft&&!et){$t("idle"),wt(null),qt(0),O(null),ve();return}return Oe(),()=>{ve()}},[ft,et,Oe,ve]),f.useEffect(()=>{(k==="highlight"&&!Pn||k==="underline"&&!Cn||k==="sign"&&!He||k==="text"&&!$n||k==="erase"&&!In)&&S("none")},[Pn,Cn,He,$n,In,k]);const he=f.useCallback(c=>{const h=Math.max(1,Math.min(_t||1,c)),l=K.current.get(h);if(!l){Kt(h);return}Ct.current=!0,l.scrollIntoView({behavior:"smooth",block:"start"}),Kt(h),window.setTimeout(()=>{Ct.current=!1},500)},[_t]),ue=f.useCallback(c=>{const h=K.current.get(c.pageNumber);h&&(Ct.current=!0,Kt(c.pageNumber));const l=()=>{var N;const p=(N=Ot.current)==null?void 0:N.querySelector(`[data-signature-field-id="${CSS.escape(c.id)}"]`);p?p.scrollIntoView({behavior:"smooth",block:"center"}):h&&h.scrollIntoView({behavior:"smooth",block:"start"}),window.setTimeout(()=>{Ct.current=!1},500)};window.requestAnimationFrame(()=>{window.setTimeout(l,40)})},[]);f.useEffect(()=>{if(ot!=="ready"||!Ot.current||!_t)return;const c=Ot.current,h=new IntersectionObserver(l=>{if(Ct.current)return;let p=null;for(const N of l){if(!N.isIntersecting)continue;const $=Number.parseInt(N.target.dataset.pageNumber||"0",10);$&&(!p||N.intersectionRatio>p.ratio)&&(p={page:$,ratio:N.intersectionRatio})}p&&Kt(p.page)},{root:c,threshold:[.25,.5,.75]});for(let l=1;l<=_t;l+=1){const p=K.current.get(l);p&&h.observe(p)}return()=>h.disconnect()},[ot,_t]);const ze=ht>1,Be=_t?ht<_t:!1,wi=f.useCallback(()=>{ze&&he(ht-1)},[ze,ht,he]),xi=f.useCallback(()=>{Be&&he(ht+1)},[Be,ht,he]),yi=f.useCallback(()=>{m(c=>(c+90)%360)},[]),bi=f.useCallback(()=>{Bt(c=>Math.max(.25,Math.round((c-.1)*100)/100))},[]),_i=f.useCallback(()=>{Bt(c=>Math.min(5,Math.round((c+.1)*100)/100))},[]),We=f.useCallback(async()=>{if(!(!at||!Ot.current))try{const h=(await at.getPage(ht)).getViewport({scale:1,rotation:Ut}),p=window.matchMedia("(max-width: 720px)").matches?16:24,$=Math.max(0,Ot.current.clientWidth-p)/h.width;Bt(Math.max(.25,Math.min(5,Math.round($*100)/100)))}catch{}},[at,ht,Ut]);f.useEffect(()=>{if(ot!=="ready"||!at||!window.matchMedia("(max-width: 720px)").matches)return;let c=!1;const h=()=>{c||We()};h();const l=Ot.current,p=typeof ResizeObserver<"u"&&l?new ResizeObserver(()=>h()):null;p==null||p.observe(l);const N=window.matchMedia("(max-width: 720px)"),$=()=>{N.matches&&h()};return N.addEventListener("change",$),()=>{c=!0,p==null||p.disconnect(),N.removeEventListener("change",$)}},[ot,at,ct,Ut,We]);const Tn=f.useMemo(()=>A.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 p=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-p)/2),width:Math.max(12,c.width-8),height:Math.max(p*1.2,c.height-4),value:l,fontSize:p,color:oe}]}),[A,Ht]),fe=f.useMemo(()=>[...G,...Tn],[G,Tn]),vi=f.useCallback(async()=>{var c;if(!(!at||ot!=="ready")){a(!0);try{const h=await Hn(at,{scale:1.5,rotation:Ut,annotations:P,signatures:M,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 p=(c=l.contentWindow)==null?void 0:c.document;if(!p)throw new Error("print iframe not available");p.open(),p.write(`<!doctype html>
25
26
  <html>
26
27
  <head>
27
28
  <meta charset="utf-8" />
28
- <title>${a.replace(/</g,"&lt;")}</title>
29
+ <title>${o.replace(/</g,"&lt;")}</title>
29
30
  <style>
30
31
  html, body { margin: 0; padding: 0; }
31
32
  img { width: 100%; display: block; }
@@ -35,21 +36,21 @@ ${j}
35
36
  </style>
36
37
  </head>
37
38
  <body></body>
38
- </html>`),x.close();const D=x.body;for(const I of f){const q=x.createElement("img");q.src=I.dataUrl;const Ce=x.createElement("div");Ce.className="page",Ce.appendChild(q),D.appendChild(Ce)}await Promise.all(Array.from(D.querySelectorAll("img")).map(I=>{var q;return((q=I.decode)==null?void 0:q.call(I).catch(()=>{}))??Promise.resolve()})),setTimeout(()=>{var I,q;try{(I=h.contentWindow)==null||I.focus(),(q=h.contentWindow)==null||q.print()}finally{setTimeout(()=>{try{document.body.removeChild(h)}catch{}},1e3)}},50)}catch{try{oe?window.open(oe,"_blank","noopener,noreferrer"):A&&window.open(A,"_blank","noopener,noreferrer")}catch{}}finally{Ne(!1)}}},[te,ue,ne,a,oe,A,_,P,R]),ni=d.useCallback(async()=>{if(!te||ue!=="ready")return;const u=`${a.replace(/[^\w.-]+/g,"_")||"document"}.pdf`;if(!(_.length>0||P.length>0||R.length>0)&&oe){Ot(await fetch(oe).then(h=>h.blob()),u);return}mt(!0);try{const h=await _n(te,{scale:2,rotation:ne,annotations:_,signatures:P,texts:R,mimeType:"image/jpeg",quality:.92}),x=dr(h),D=new Uint8Array(x.byteLength);D.set(x),Ot(new Blob([D],{type:"application/pdf"}),u)}catch{oe&&Ot(await fetch(oe).then(h=>h.blob()),u)}finally{mt(!1)}},[te,ue,ne,a,oe,_,P,R]),ii=d.useCallback(u=>{y(f=>f===u?"none":u)},[]),ri=o==="highlight"||o==="underline"?Xt(o==="highlight"?dn:o==="underline"?hn:null,o):void 0,nt=ve!=null?P.find(u=>u.id===ve)??null:null,si=d.useCallback(u=>{k(f=>[...f,u])},[]),oi=d.useCallback(u=>{k(f=>f.filter(h=>h.id!==u))},[]),ai=d.useCallback(()=>{k([]),N([]),z([]),de(null),ze(null),Xe(null),Ze(null)},[]),ci=d.useCallback(u=>{ae(u),U(!0)},[]),li=d.useCallback((u,f)=>{Zn(h=>({...h,[u]:f}))},[]),di=d.useCallback(u=>{const f=Je[u];f&&(xe==null||xe(u,f));const h=$.findIndex(I=>I.id===u),x=new Set(Object.keys(Je).filter(I=>{var q;return(q=Je[I])==null?void 0:q.trim()}));x.add(u);const D=$.slice(h+1).find(I=>!x.has(I.id)&&!P.some(q=>q.fieldId===I.id))??$.slice(0,Math.max(0,h)).find(I=>!x.has(I.id)&&!P.some(q=>q.fieldId===I.id));if(D){je(D.id),tt(D);const I=D.type;(I==="sign"||!I)&&window.setTimeout(()=>U(!0),350)}},[$,Je,P,tt]),hi=d.useCallback((u,f,h)=>{const x=Ti(f,h);if(He){N(Q=>Q.map(Te=>Te.id===He?{...Te,imageDataUrl:u,width:Te.fieldId?Te.width:x.width,height:Te.fieldId?Te.height:x.height}:Te)),ee(null),y("none"),U(!1),Le(null);return}if(Ie){const Q=$.find(ge=>ge.id===pe&&!P.some(Qe=>Qe.fieldId===ge.id))??$.find(ge=>!P.some(Qe=>Qe.fieldId===ge.id));if(!Q){U(!1);return}const Te={id:vt(),fieldId:Q.id,pageNumber:Q.pageNumber,x:Q.x,y:Q.y,width:Q.width,height:Q.height,imageDataUrl:u};N(ge=>[...ge.filter(Qe=>Qe.fieldId!==Q.id),Te]),K==null||K(Q.id,Te),ee(null),y("none"),U(!1),Le(null);const qe=new Set(P.filter(ge=>ge.fieldId&&ge.fieldId!==Q.id).map(ge=>ge.fieldId));qe.add(Q.id);const yt=$.findIndex(ge=>ge.id===Q.id),ct=$.slice(yt+1).find(ge=>!qe.has(ge.id))??$.slice(0,Math.max(0,yt)).find(ge=>!qe.has(ge.id));ct?(je(ct.id),de(null),tt(ct),window.setTimeout(()=>{U(!0)},350)):(de(Te.id),je(Q.id));return}const D=_e.current.get(m),I=D==null?void 0:D.querySelector(".epochs-pdf-viewer__surface");let q=24,Ce=24;if(I){const Q=pt(I,X),Te=I.closest(".epochs-pdf-viewer__body");if(Te){const qe=Ri(Te.getBoundingClientRect(),I,X),yt=Math.max(0,qe.top),ct=Math.min(Q.height,qe.bottom),ge=Math.max(0,qe.left),Qe=Math.min(Q.width,qe.right);q=Math.max(0,(ge+Qe)/2-x.width/2),Ce=Math.max(0,(yt+ct)/2-x.height/2),q=Math.min(q,Math.max(0,Q.width-x.width)),Ce=Math.min(Ce,Math.max(0,Q.height-x.height))}else q=Math.max(0,(Q.width-x.width)/2),Ce=Math.max(0,(Q.height-x.height)/2)}const Ue={id:vt(),pageNumber:m,x:q,y:Ce,width:x.width,height:x.height,imageDataUrl:u};N(Q=>[...Q,Ue]),K==null||K(void 0,Ue),de(Ue.id),ee(null),y("none"),U(!1),Le(null)},[He,Ie,m,X,tt,pe,$,P,K]),ui=d.useCallback(u=>{N(f=>[...f,u]),de(u.id),ee(null),y("none")},[]),fi=d.useCallback((u,f)=>{N(h=>h.map(x=>x.id===u?{...x,...f}:x))},[]),pi=d.useCallback(u=>{const f=P.find(h=>h.id===u);N(h=>h.filter(x=>x.id!==u)),de(h=>h===u?null:h),f!=null&&f.fieldId&&je(f.fieldId)},[P]),gi=d.useCallback(u=>{const f=u?P.find(Ue=>Ue.id===u)??null:nt;if(!f)return;const h=_e.current.get(f.pageNumber),x=h==null?void 0:h.querySelector(".epochs-pdf-viewer__surface"),D=18;let I=f.x+D,q=f.y+D;if(x){const Ue=x.clientWidth/X,Q=x.clientHeight/X;I=Math.min(Math.max(0,I),Math.max(0,Ue-f.width)),q=Math.min(Math.max(0,q),Math.max(0,Q-f.height))}const Ce={...f,id:vt(),x:I,y:q};N(Ue=>[...Ue,Ce]),de(Ce.id),ee(null),y("none")},[X,nt,P]),mi=d.useCallback(u=>{const f=u??(nt==null?void 0:nt.id);f&&(de(f),Le(f),U(!0))},[nt]),wi=d.useCallback(u=>{z(f=>u.fieldId?[...f.filter(h=>h.fieldId!==u.fieldId),u]:[...f,u]),ze(u.id),u.fieldId&&Xe(u.fieldId)},[]),yi=d.useCallback((u,f)=>{z(h=>h.map(x=>x.id===u?{...x,...f}:x))},[]),bi=d.useCallback(u=>{const f=R.find(h=>h.id===u);z(h=>h.filter(x=>x.id!==u)),ze(h=>h===u?null:h),Ze(h=>h===u?null:h),f!=null&&f.fieldId&&Xe(f.fieldId)},[R]);d.useEffect(()=>{ot&&z(u=>u.map(f=>{if(!f.fieldId)return f;const h=S.find(x=>x.id===f.fieldId);return h?{...f,pageNumber:h.pageNumber,x:h.x,y:h.y,width:h.width,height:h.height,fontSize:h.fontSize??f.fontSize??gt,color:h.color??f.color??ft}:f}))},[ot,S]);const mn=d.useCallback(u=>{var D;if(!$.length)return;const f=pe!=null?$.findIndex(I=>I.id===pe):-1,h=Math.min($.length-1,Math.max(0,(f<0?0:f)+u)),x=$[h];x&&(je(x.id),de(((D=P.find(I=>I.fieldId===x.id))==null?void 0:D.id)??null),tt(x))},[tt,pe,$,P]);if(!ye&&!A)return r.jsx("div",{"data-testid":"pdf-viewer",className:`epochs-pdf-viewer epochs-pdf-viewer--empty ${j??""}`.trim(),children:"No PDF file provided."});const xi={height:s},wn={status:ue,showThumbnails:Re,setShowThumbnails:Be,canGoPrev:Ct,canGoNext:Tt,handlePrev:Kn,handleNext:Vn,pageNumber:m,numPages:le,scrollToPage:et,scale:X,handleZoomOut:Jn,handleZoomIn:ei,handleFitWidth:$t,handleRotate:Qn,markupTool:o,toggleMarkupTool:u=>ii(u),hasFixedSignatureFields:Ie,hasFixedTextFields:ot,pendingSignature:ce,setMarkupTool:y,setSignaturePadOpen:U,annotationsLength:_.length,signaturesLength:P.length,textsLength:R.length,handleClearAnnotations:ai,highlightHex:dn,underlineHex:hn,setHighlightHex:qn,setUnderlineHex:Yn,loadDocument:Nt,handlePrint:ti,isPrinting:Ge,pdfDoc:te,displayUrl:oe,resolvedUrl:A,handleDownload:ni,isDownloading:Oe},_i=u=>u.filter(f=>!(Ie&&(f==="highlight"||f==="underline"||f==="erase"))),Rt=pe?$.findIndex(u=>u.id===pe):0,vi=$.filter(u=>{var h;const f=u.type??"sign";return f==="date"||f==="text"?!!((h=Je[u.id])!=null&&h.trim()):P.some(x=>x.fieldId===u.id)}).length,It=$.length>0?Math.round(vi/$.length*100):0,yn=(u,f=!1)=>{const h=_i(u);if(h.length===0&&!f)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 x=h.map((D,I)=>{const q=h[I-1],Ce=kn(D)&&(!q||!kn(q));return r.jsx(d.Fragment,{children:yr(D,wn,{showMarkupSep:Ce})},D)});return r.jsxs("div",{className:f?"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end":"epochs-pdf-viewer__toolbar-group",children:[x,br(wn,new Set(h))]})};return r.jsxs("div",{"data-testid":"pdf-viewer","data-file-url":A||void 0,className:`epochs-pdf-viewer ${j??""}`.trim(),style:xi,children:[Ke?r.jsxs("div",{className:"epochs-pdf-viewer__toolbar",children:[yn(Ke.left),yn(Ke.right,!0)]}):null,Pt||Me||Ie?r.jsx(fr,{open:Y,onClose:()=>{U(!1),Le(null),he==null||he()},onSave:hi,fieldType:B,showFieldTypeTabs:!Ie}):null,r.jsxs("div",{className:"epochs-pdf-viewer__content",children:[Re?r.jsx("div",{className:"epochs-pdf-viewer__thumbnails",style:{width:b+24},children:ue==="ready"&&te?r.jsxs(r.Fragment,{children:[Array.from({length:Math.min(le||0,g)}).map((u,f)=>{const h=f+1;return r.jsx("div",{className:"epochs-pdf-viewer__thumb-wrap",children:r.jsx(ir,{pdfDoc:te,pageNumber:h,isActive:h===m,rotation:ne,onSelect:et,width:b,annotations:_,signatures:P,signatureFields:$,texts:R,textFields:S})},h)}),le>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:Se,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.",A?r.jsx("a",{className:"epochs-pdf-viewer__open-link",href:A,target:"_blank",rel:"noopener noreferrer",children:"Open file"}):null]}):null,ue==="ready"&&te?r.jsx("div",{children:Array.from({length:le}).map((u,f)=>{const h=f+1;return r.jsx(nr,{pdfDoc:te,pageNumber:h,scale:X,rotation:ne,markupTool:J?o:"none",markupColor:ri,annotations:_,onAddAnnotation:si,onRemoveAnnotation:oi,signatures:P,pendingSignature:ce,onAddSignature:ui,onUpdateSignature:fi,onRemoveSignature:pi,onEditSignature:mi,onDuplicateSignature:gi,selectedSignatureId:ve,onSelectSignature:de,signatureFields:$,selectedSignatureFieldId:pe,onSelectSignatureField:je,hasFixedSignatureFields:Ie,onOpenSignaturePad:ci,fieldValues:Je,onFieldValueChange:li,onFieldValueCommit:di,texts:R,onAddText:wi,onUpdateText:yi,onRemoveText:bi,selectedTextId:st,onSelectText:ze,textFields:S,selectedTextFieldId:wt,onSelectTextField:Xe,hasFixedTextFields:ot,editingTextId:Mt,onEditingTextIdChange:Ze,pageRef:x=>{x&&_e.current.set(h,x)}},h)})}):null]})]}),Ie||we?r.jsxs("div",{className:"epochs-pdf-viewer__footer",role:"navigation","aria-label":"Viewer actions",children:[Ie?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:$.length<=1||Rt<=0,onClick:()=>mn(-1),children:"Prev"}),r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:$.length<=1||Rt>=$.length-1,onClick:()=>mn(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,Rt+1)," of ",$.length]}),r.jsx("div",{className:"epochs-pdf-viewer__footer-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":It,"aria-label":"Signature progress",children:r.jsx("div",{className:"epochs-pdf-viewer__footer-progress-bar",style:{width:`${It}%`}})}),r.jsxs("span",{className:"epochs-pdf-viewer__footer-percent",children:[It,"%"]})]})]}):r.jsx("div",{className:"epochs-pdf-viewer__footer-center"}),we?r.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:we,children:V}):null]}):null]})}function In(e){return null}In.displayName="Document";function Ln(e){return null}Ln.displayName="Page";function Sn(e){return null}Sn.displayName="View";function Dn(e){return null}Dn.displayName="Text";function En(e){return null}En.displayName="Image";function Fn(e){return null}Fn.displayName="Link";const _r={Document:"DOCUMENT",Page:"PAGE",View:"VIEW",Text:"TEXT",Image:"IMAGE",Link:"LINK"};function vr(e){if(typeof e=="string")return e;if(typeof e=="function"){const t=e;return t.displayName||t.name||null}return null}function An(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 Bn(e){return An(e).map(t=>typeof t=="string"||typeof t=="number"?String(t):t&&typeof t=="object"&&"props"in t?Bn(t.props.children):"").join("")}function On(e){const t=vr(e.type),n=t?_r[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:Bn(s)};const a=An(s).filter(c=>!!c&&typeof c=="object"&&"type"in c).map(On);return{type:n,props:i,children:a}}const Hn={A4:[595.28,841.89],LETTER:[612,792],LEGAL:[612,1008]};function zn(e="A4",t="portrait"){const[n,i]=Array.isArray(e)?e:Hn[e];return t==="landscape"?[i,n]:[n,i]}function Un(e={}){const t=e.padding??0;return{top:e.paddingTop??t,right:e.paddingRight??t,bottom:e.paddingBottom??t,left:e.paddingLeft??t}}function dt(e={}){const t=e.margin??0;return{top:e.marginTop??t,right:e.marginRight??t,bottom:e.marginBottom??t,left:e.marginLeft??t}}function _t(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,a=parseInt(i[1]+i[1],16)/255,c=parseInt(i[2]+i[2],16)/255;return[s,a,c]}if(i.length===6){const s=parseInt(i.slice(0,2),16)/255,a=parseInt(i.slice(2,4),16)/255,c=parseInt(i.slice(4,6),16)/255;return[s,a,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 Ut(e){return e==="bold"?!0:typeof e=="number"?e>=600:!1}const jr=12,kr=1.4,Mr=.5;function Wn(e,t,n){const i=t.fontSize??jr,s=(t.lineHeight??kr)*i,a=i*(Ut(t.fontWeight)?.55:Mr);if(!e)return{width:0,height:s,lines:[""]};const c=e.split(/\s+/),l=[];let b="";for(const j of c){const v=b?`${b} ${j}`:j;v.length*a<=n||!b?b=v:(l.push(b),b=j)}b&&l.push(b);const g=Math.max(...l.map(j=>j.length*a),0);return{width:Math.min(g,n),height:l.length*s,lines:l}}function Gn(e,t,n,i,s){const a=e.props.style??{},c=dt(a),l=Un(a),b=t+c.left,g=n+c.top,j=Math.max(0,it(a.width,i,i)-c.left-c.right),v=Math.max(0,j-l.left-l.right);if(e.type==="TEXT"||e.type==="LINK"){const S=Wn(e.text??"",a,v),K=it(a.height,s,S.height+l.top+l.bottom);return{x:b,y:g,width:j,height:K,node:e,children:[],style:a,text:e.text}}if(e.type==="IMAGE"){const S=it(a.width,i,Math.min(200,i)),K=it(a.height,s,120);return{x:b,y:g,width:S-c.left-c.right,height:K,node:e,children:[],style:a}}const w=a.flexDirection??"column",M=a.gap??0,C=[];let W=b+l.left,E=g+l.top,O=0,F=0;for(let S=0;S<e.children.length;S++){const K=e.children[S],xe=w==="row"?Math.max(0,v-O-(S>0?M:0)):v,Me=w==="column"?Math.max(0,s-(E-n)-c.bottom):s,he=Gn(K,W,E,xe,Me);C.push(he),w==="row"?(O+=he.width+dt(K.props.style??{}).left+dt(K.props.style??{}).right,S<e.children.length-1&&(O+=M),W=b+l.left+O,F=Math.max(F,he.height)):(O+=he.height+dt(K.props.style??{}).top+dt(K.props.style??{}).bottom,S<e.children.length-1&&(O+=M),E=g+l.top+O,F=Math.max(F,he.width))}const T=it(a.height,s,w==="column"?O+l.top+l.bottom:F+l.top+l.bottom),Z=w==="row"?it(a.width,i,O+l.left+l.right):j,J=a.justifyContent??"flex-start",G=a.alignItems??"stretch",ie=w==="column"?T-l.top-l.bottom:Z-l.left-l.right,me=Math.max(0,ie-O);let L=0,se=M;J==="center"&&(L=me/2),J==="flex-end"&&(L=me),J==="space-between"&&C.length>1&&(se=M+me/(C.length-1)),J==="space-around"&&C.length>0&&(se=M+me/C.length,L=se/2);let $=0;for(const S of C)w==="column"?(S.y=g+l.top+L+$,G==="center"?S.x=b+l.left+Math.max(0,(v-S.width)/2):G==="flex-end"?S.x=b+l.left+Math.max(0,v-S.width):G==="stretch"&&S.style.width==null&&(S.width=v),$+=S.height+se):(S.x=b+l.left+L+$,G==="center"?S.y=g+l.top+Math.max(0,(T-l.top-l.bottom-S.height)/2):G==="flex-end"?S.y=g+l.top+Math.max(0,T-l.top-l.bottom-S.height):G==="stretch"&&S.style.height==null&&(S.height=T-l.top-l.bottom),$+=S.width+se);return{x:b,y:g,width:Z,height:T,node:e,children:C,style:a}}function Pr(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",[a,c]=zn(i,s),l=n.props.style??{},b=Un(l),g={type:"VIEW",props:{style:{...l,width:a,height:c,paddingTop:b.top,paddingRight:b.right,paddingBottom:b.bottom,paddingLeft:b.left}},children:n.children},j=Gn(g,0,0,a,c);t.push({width:a,height:c,boxes:j.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 ht(e){return e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}class Nr{constructor(){Lt(this,"objects",[null]);Lt(this,"offsets",[0])}addObject(t){return this.objects.push(t),this.objects.length-1}build(t){const n=this.addObject(`<< /Title (${ht(t.meta.title)}) /Author (${ht(t.meta.author)}) /Subject (${ht(t.meta.subject)}) /Creator (${ht(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 >>"),a=[];for(const v of t.pages){const w=this.renderPageContent(v.boxes,v.width,v.height,v.style),M=this.addObject(`<< /Length ${w.length} >>
39
+ </html>`),p.close();const N=p.body;for(const $ of h){const z=p.createElement("img");z.src=$.dataUrl;const it=p.createElement("div");it.className="page",it.appendChild(z),N.appendChild(it)}await Promise.all(Array.from(N.querySelectorAll("img")).map($=>{var z;return((z=$.decode)==null?void 0:z.call($).catch(()=>{}))??Promise.resolve()})),setTimeout(()=>{var $,z;try{($=l.contentWindow)==null||$.focus(),(z=l.contentWindow)==null||z.print()}finally{setTimeout(()=>{try{document.body.removeChild(l)}catch{}},1e3)}},50)}catch{try{R?window.open(R,"_blank","noopener,noreferrer"):et&&window.open(et,"_blank","noopener,noreferrer")}catch{}}finally{a(!1)}}},[at,ot,Ut,o,R,et,P,M,fe]),ji=f.useCallback(async()=>{if(!at||ot!=="ready")return;const c=`${o.replace(/[^\w.-]+/g,"_")||"document"}.pdf`;if(!(P.length>0||M.length>0||fe.length>0)&&R){Je(await fetch(R).then(l=>l.blob()),c);return}v(!0);try{const l=await Hn(at,{scale:2,rotation:Ut,annotations:P,signatures:M,texts:fe,mimeType:"image/jpeg",quality:.92}),p=Ts(l),N=new Uint8Array(p.byteLength);N.set(p),Je(new Blob([N],{type:"application/pdf"}),c)}catch{R&&Je(await fetch(R).then(l=>l.blob()),c)}finally{v(!1)}},[at,ot,Ut,o,R,P,M,fe]),ki=f.useCallback(c=>{S(h=>h===c?"none":c)},[]),Mi=k==="highlight"||k==="underline"?an(k==="highlight"?kn:k==="underline"?Mn:null,k):void 0,pe=Tt!=null?M.find(c=>c.id===Tt)??null:null,Ni=f.useCallback(c=>{T(h=>[...h,c])},[]),Pi=f.useCallback(c=>{T(h=>h.filter(l=>l.id!==c))},[]),Ci=f.useCallback(()=>{T([]),F([]),D([]),Rt(null),le(null),xe(null),Ie(null)},[]),Te=f.useCallback((c,h)=>{const l=A.findIndex(N=>N.id===c),p=A.slice(l+1).find(N=>!h.has(N.id))??A.slice(0,Math.max(0,l)).find(N=>!h.has(N.id));if(!p){B(!1),Qt(null);return}Zt(p.id),Rt(null),Qt(null),vt(p.type??"sign"),ue(p),window.setTimeout(()=>{B(!0)},350)},[ue,A]),$i=f.useCallback(c=>{vt(c),B(!0)},[]),Ii=f.useCallback((c,h)=>{Ae(l=>({...l,[c]:h}))},[]),Ti=f.useCallback(c=>{const h=Ht[c];h&&(q==null||q(c,h));const l=A.findIndex($=>$.id===c),p=new Set(Object.keys(Ht).filter($=>{var z;return(z=Ht[$])==null?void 0:z.trim()}));p.add(c);const N=A.slice(l+1).find($=>!p.has($.id)&&!M.some(z=>z.fieldId===$.id))??A.slice(0,Math.max(0,l)).find($=>!p.has($.id)&&!M.some(z=>z.fieldId===$.id));N&&(Zt(N.id),ue(N))},[A,Ht,M,ue,q]),Ri=f.useCallback((c,h,l)=>{var se;const p=Zi(h,l);if(ce){F(Q=>Q.map(kt=>kt.id===ce?{...kt,imageDataUrl:c,width:kt.fieldId?kt.width:p.width,height:kt.fieldId?kt.height:p.height}:kt)),pt(null),S("none"),B(!1),Qt(null);return}if(Lt){const Q=A.find(W=>W.id===jt&&(W.type??"sign")==="sign"&&!M.some(te=>te.fieldId===W.id))??A.find(W=>(W.type??"sign")==="sign"&&!M.some(te=>te.fieldId===W.id));if(!Q){B(!1);return}const kt=xt&&Q.signature_tag?A.filter(W=>(W.type??"sign")==="sign"&&W.signature_tag===Q.signature_tag&&!M.some(te=>te.fieldId===W.id)):[Q],Mt=kt.map(W=>({id:Se(),fieldId:W.id,pageNumber:W.pageNumber,x:W.x,y:W.y,width:W.width,height:W.height,imageDataUrl:c})),Jt=new Set(kt.map(W=>W.id));F(W=>[...W.filter(te=>!te.fieldId||!Jt.has(te.fieldId)),...Mt]);const re=new Map(Mt.map(W=>[W.fieldId,W]));_e(kt.map(W=>W.id),Mt[0],re),pt(null),S("none"),Rt(((se=Mt[0])==null?void 0:se.id)??null);const gt=new Set(A.filter(W=>be(W,[...M,...Mt],Ht)).map(W=>W.id));for(const W of Jt)gt.add(W);Te(Q.id,gt);return}const N=K.current.get(ht),$=N==null?void 0:N.querySelector(".epochs-pdf-viewer__surface");let z=24,it=24;if($){const Q=we($,Nt),kt=$.closest(".epochs-pdf-viewer__body");if(kt){const Mt=An(kt.getBoundingClientRect(),$,Nt),Jt=Math.max(0,Mt.top),re=Math.min(Q.height,Mt.bottom),gt=Math.max(0,Mt.left),W=Math.min(Q.width,Mt.right);z=Math.max(0,(gt+W)/2-p.width/2),it=Math.max(0,(Jt+re)/2-p.height/2),z=Math.min(z,Math.max(0,Q.width-p.width)),it=Math.min(it,Math.max(0,Q.height-p.height))}else z=Math.max(0,(Q.width-p.width)/2),it=Math.max(0,(Q.height-p.height)/2)}const Ft={id:Se(),pageNumber:ht,x:z,y:it,width:p.width,height:p.height,imageDataUrl:c};F(Q=>[...Q,Ft]),_e(void 0,Ft),Rt(Ft.id),pt(null),S("none"),B(!1),Qt(null)},[Te,xt,ce,Ht,Lt,be,ht,Nt,jt,A,M,_e]),Li=f.useCallback((c,h)=>{if(Lt){const Q=A.find(gt=>gt.id===jt&&(gt.type??"sign")===h)??A.find(gt=>(gt.type??"sign")===h);if(!Q){B(!1);return}const Mt=(xt&&Q.signature_tag?A.filter(gt=>(gt.type??"sign")===h&&gt.signature_tag===Q.signature_tag):[Q]).map(gt=>gt.id);Nn(Mt,c);const Jt={...Ht};for(const gt of Mt)Jt[gt]=c;const re=new Set(A.filter(gt=>be(gt,M,Jt)).map(gt=>gt.id));Te(Q.id,re);return}const l=ae,p=Math.max(80,c.length*l*.55),N=l*1.25;let $=24,z=24;const it=K.current.get(ht),Ft=it==null?void 0:it.querySelector(".epochs-pdf-viewer__surface");if(Ft){const Q=we(Ft,Nt),kt=Ft.closest(".epochs-pdf-viewer__body");if(kt){const Mt=An(kt.getBoundingClientRect(),Ft,Nt),Jt=Math.max(0,Mt.top),re=Math.min(Q.height,Mt.bottom),gt=Math.max(0,Mt.left),W=Math.min(Q.width,Mt.right);$=Math.max(0,(gt+W)/2-p/2),z=Math.max(0,(Jt+re)/2-N/2),$=Math.min($,Math.max(0,Q.width-p)),z=Math.min(z,Math.max(0,Q.height-N))}}const se={id:Fe(),pageNumber:ht,x:$,y:z,width:p,height:N,value:c,fontSize:l,color:oe};D(Q=>[...Q,se]),le(se.id),B(!1),S("none")},[Te,xt,Ht,Lt,be,ht,Nt,jt,A,M,Nn]),Di=f.useCallback(c=>{F(h=>[...h,c]),_e(void 0,c),Rt(c.id),pt(null),S("none")},[_e]),Si=f.useCallback((c,h)=>{F(l=>l.map(p=>p.id===c?{...p,...h}:p))},[]),Fi=f.useCallback(c=>{const h=M.find(l=>l.id===c);F(l=>l.filter(p=>p.id!==c)),Rt(l=>l===c?null:l),h!=null&&h.fieldId&&Zt(h.fieldId)},[M]),Ei=f.useCallback(c=>{const h=c?M.find(Ft=>Ft.id===c)??null:pe;if(!h)return;const l=K.current.get(h.pageNumber),p=l==null?void 0:l.querySelector(".epochs-pdf-viewer__surface"),N=18;let $=h.x+N,z=h.y+N;if(p){const Ft=p.clientWidth/Nt,se=p.clientHeight/Nt;$=Math.min(Math.max(0,$),Math.max(0,Ft-h.width)),z=Math.min(Math.max(0,z),Math.max(0,se-h.height))}const it={...h,id:Se(),x:$,y:z};F(Ft=>[...Ft,it]),Rt(it.id),pt(null),S("none")},[Nt,pe,M]),Ai=f.useCallback(c=>{const h=c??(pe==null?void 0:pe.id);if(!h)return;const l=M.find(N=>N.id===h),p=l!=null&&l.fieldId?A.find(N=>N.id===l.fieldId):void 0;vt((p==null?void 0:p.type)??"sign"),Rt(h),Qt(h),B(!0)},[pe,M,A]),Ui=f.useCallback(c=>{D(h=>c.fieldId?[...h.filter(l=>l.fieldId!==c.fieldId),c]:[...h,c]),le(c.id),c.fieldId&&xe(c.fieldId)},[]),Hi=f.useCallback((c,h)=>{D(l=>l.map(p=>p.id===c?{...p,...h}:p))},[]),Oi=f.useCallback(c=>{const h=G.find(l=>l.id===c);D(l=>l.filter(p=>p.id!==c)),le(l=>l===c?null:l),Ie(l=>l===c?null:l),h!=null&&h.fieldId&&xe(h.fieldId)},[G]);f.useEffect(()=>{ye&&D(c=>c.map(h=>{if(!h.fieldId)return h;const l=H.find(p=>p.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}))},[ye,H]);const Rn=f.useCallback(c=>{var N;if(!A.length)return;const h=jt!=null?A.findIndex($=>$.id===jt):-1,l=Math.min(A.length-1,Math.max(0,(h<0?0:h)+c)),p=A[l];p&&(Zt(p.id),Rt(((N=M.find($=>$.fieldId===p.id))==null?void 0:N.id)??null),ue(p))},[ue,jt,A,M]);if(!ft&&!et)return s.jsx("div",{"data-testid":"pdf-viewer",className:`epochs-pdf-viewer epochs-pdf-viewer--empty ${x??""}`.trim(),children:"No PDF file provided."});const zi={height:r},Ln={status:ot,showThumbnails:ct,setShowThumbnails:yt,canGoPrev:ze,canGoNext:Be,handlePrev:wi,handleNext:xi,pageNumber:ht,numPages:_t,scrollToPage:he,scale:Nt,handleZoomOut:bi,handleZoomIn:_i,handleFitWidth:We,handleRotate:yi,markupTool:k,toggleMarkupTool:c=>ki(c),hasFixedSignatureFields:Lt,hasFixedTextFields:ye,pendingSignature:St,setMarkupTool:S,setSignaturePadOpen:B,annotationsLength:P.length,signaturesLength:M.length,textsLength:G.length,handleClearAnnotations:Ci,highlightHex:kn,underlineHex:Mn,setHighlightHex:gi,setUnderlineHex:mi,loadDocument:Oe,handlePrint:vi,isPrinting:Gt,pdfDoc:at,displayUrl:R,resolvedUrl:et,handleDownload:ji,isDownloading:_},Bi=c=>c.filter(h=>!(Lt&&(h==="highlight"||h==="underline"||h==="erase"))),Ge=jt?A.findIndex(c=>c.id===jt):0,Wi=A.filter(c=>be(c,M,Ht)).length,Xe=A.length>0?Math.round(Wi/A.length*100):0,Dn=(c,h=!1)=>{const l=Bi(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 p=l.map((N,$)=>{const z=l[$-1],it=Wn(N)&&(!z||!Wn(z));return s.jsx(f.Fragment,{children:zs(N,Ln,{showMarkupSep:it})},N)});return s.jsxs("div",{className:h?"epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end":"epochs-pdf-viewer__toolbar-group",children:[p,Bs(Ln,new Set(l))]})};return s.jsxs("div",{"data-testid":"pdf-viewer","data-file-url":et||void 0,className:`epochs-pdf-viewer ${x??""}`.trim(),style:zi,children:[ne?s.jsxs("div",{className:"epochs-pdf-viewer__toolbar",children:[Dn(ne.left),Dn(ne.right,!0)]}):null,He||Vt||Lt?s.jsx(Es,{open:nt,onClose:()=>{B(!1),Qt(null),vt(void 0),dt==null||dt()},onSave:Ri,onSaveFieldValue:Li,fieldType:lt,showFieldTypeTabs:!Lt,textPlaceholder:(Sn=A.find(c=>c.id===jt))==null?void 0:Sn.placeholder,initialFieldValue:jt?Ht[jt]??((Fn=A.find(c=>c.id===jt))==null?void 0:Fn.value):void 0,rememberedByType:Wt,onRememberFill:(c,h)=>{It(l=>c==="sign"?{...l,sign:h}:c==="date"?{...l,date:h}:{...l,text:h})}}):null,s.jsxs("div",{className:"epochs-pdf-viewer__content",children:[ct?s.jsx("div",{className:"epochs-pdf-viewer__thumbnails",style:{width:w+24},children:ot==="ready"&&at?s.jsxs(s.Fragment,{children:[Array.from({length:Math.min(_t||0,g)}).map((c,h)=>{const l=h+1;return s.jsx("div",{className:"epochs-pdf-viewer__thumb-wrap",children:s.jsx(ks,{pdfDoc:at,pageNumber:l,isActive:l===ht,rotation:Ut,onSelect:he,width:w,annotations:P,signatures:M,signatureFields:A,texts:fe,textFields:H})},l)}),_t>g?s.jsxs("div",{className:"epochs-pdf-viewer__thumb-more",children:["Showing first ",g," pages"]}):null]}):s.jsx("div",{className:"epochs-pdf-viewer__muted",children:"Thumbnails"})}):null,s.jsxs("div",{ref:Ot,className:"epochs-pdf-viewer__body",children:[ot==="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,ot==="error"?s.jsxs("div",{className:"epochs-pdf-viewer__overlay epochs-pdf-viewer__error",children:["Unable to load PDF.",et?s.jsx("a",{className:"epochs-pdf-viewer__open-link",href:et,target:"_blank",rel:"noopener noreferrer",children:"Open file"}):null]}):null,ot==="ready"&&at?s.jsx("div",{children:Array.from({length:_t}).map((c,h)=>{const l=h+1;return s.jsx(js,{pdfDoc:at,pageNumber:l,scale:Nt,rotation:Ut,markupTool:rt?k:"none",markupColor:Mi,annotations:P,onAddAnnotation:Ni,onRemoveAnnotation:Pi,signatures:M,pendingSignature:St,onAddSignature:Di,onUpdateSignature:Si,onRemoveSignature:Fi,onEditSignature:Ai,onDuplicateSignature:Ei,selectedSignatureId:Tt,onSelectSignature:Rt,signatureFields:A,selectedSignatureFieldId:jt,onSelectSignatureField:Zt,hasFixedSignatureFields:Lt,onOpenSignaturePad:$i,fieldValues:Ht,onFieldValueChange:Ii,onFieldValueCommit:Ti,texts:G,onAddText:Ui,onUpdateText:Hi,onRemoveText:Oi,selectedTextId:$e,onSelectText:le,textFields:H,selectedTextFieldId:fi,onSelectTextField:xe,hasFixedTextFields:ye,editingTextId:pi,onEditingTextIdChange:Ie,pageRef:p=>{p&&K.current.set(l,p)}},l)})}):null]})]}),Lt||Yt?s.jsxs("div",{className:"epochs-pdf-viewer__footer",role:"navigation","aria-label":"Viewer actions",children:[Lt?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:A.length<=1||Ge<=0,onClick:()=>Rn(-1),children:"Prev"}),s.jsx("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",disabled:A.length<=1||Ge>=A.length-1,onClick:()=>Rn(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 ",A.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"}),Yt?s.jsxs("button",{type:"button",className:"epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",onClick:Yt,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 Qn(t){return null}Qn.displayName="Document";function Jn(t){return null}Jn.displayName="Page";function ti(t){return null}ti.displayName="View";function ei(t){return null}ei.displayName="Text";function ni(t){return null}ni.displayName="Image";function ii(t){return null}ii.displayName="Link";const Gs={Document:"DOCUMENT",Page:"PAGE",View:"VIEW",Text:"TEXT",Image:"IMAGE",Link:"LINK"};function Xs(t){if(typeof t=="string")return t;if(typeof t=="function"){const e=t;return e.displayName||e.name||null}return null}function si(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 ri(t){return si(t).map(e=>typeof e=="string"||typeof e=="number"?String(e):e&&typeof e=="object"&&"props"in e?ri(e.props.children):"").join("")}function oi(t){const e=Xs(t.type),n=e?Gs[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:ri(r)};const o=si(r).filter(d=>!!d&&typeof d=="object"&&"type"in d).map(oi);return{type:n,props:i,children:o}}const ai={A4:[595.28,841.89],LETTER:[612,792],LEGAL:[612,1008]};function ci(t="A4",e="portrait"){const[n,i]=Array.isArray(t)?t:ai[t];return e==="landscape"?[i,n]:[n,i]}function li(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 sn(t){return t==="bold"?!0:typeof t=="number"?t>=600:!1}const qs=12,Vs=1.4,Ys=.5;function di(t,e,n){const i=e.fontSize??qs,r=(e.lineHeight??Vs)*i,o=i*(sn(e.fontWeight)?.55:Ys);if(!t)return{width:0,height:r,lines:[""]};const d=t.split(/\s+/),u=[];let w="";for(const x of d){const b=w?`${w} ${x}`:x;b.length*o<=n||!w?w=b:(u.push(w),w=x)}w&&u.push(w);const g=Math.max(...u.map(x=>x.length*o),0);return{width:Math.min(g,n),height:u.length*r,lines:u}}function hi(t,e,n,i,r){const o=t.props.style??{},d=ke(o),u=li(o),w=e+d.left,g=n+d.top,x=Math.max(0,ge(o.width,i,i)-d.left-d.right),b=Math.max(0,x-u.left-u.right);if(t.type==="TEXT"||t.type==="LINK"){const H=di(t.text??"",o,b),J=ge(o.height,r,H.height+u.top+u.bottom);return{x:w,y:g,width:x,height:J,node:t,children:[],style:o,text:t.text}}if(t.type==="IMAGE"){const H=ge(o.width,i,Math.min(200,i)),J=ge(o.height,r,120);return{x:w,y:g,width:H-d.left-d.right,height:J,node:t,children:[],style:o}}const y=o.flexDirection??"column",j=o.gap??0,C=[];let E=w+u.left,U=g+u.top,L=0,Y=0;for(let H=0;H<t.children.length;H++){const J=t.children[H],tt=y==="row"?Math.max(0,b-L-(H>0?j:0)):b,xt=y==="column"?Math.max(0,r-(U-n)-d.bottom):r,q=hi(J,E,U,tt,xt);C.push(q),y==="row"?(L+=q.width+ke(J.props.style??{}).left+ke(J.props.style??{}).right,H<t.children.length-1&&(L+=j),E=w+u.left+L,Y=Math.max(Y,q.height)):(L+=q.height+ke(J.props.style??{}).top+ke(J.props.style??{}).bottom,H<t.children.length-1&&(L+=j),U=g+u.top+L,Y=Math.max(Y,q.width))}const I=ge(o.height,r,y==="column"?L+u.top+u.bottom:Y+u.top+u.bottom),st=y==="row"?ge(o.width,i,L+u.left+u.right):x,rt=o.justifyContent??"flex-start",V=o.alignItems??"stretch",Z=y==="column"?I-u.top-u.bottom:st-u.left-u.right,bt=Math.max(0,Z-L);let X=0,Pt=j;rt==="center"&&(X=bt/2),rt==="flex-end"&&(X=bt),rt==="space-between"&&C.length>1&&(Pt=j+bt/(C.length-1)),rt==="space-around"&&C.length>0&&(Pt=j+bt/C.length,X=Pt/2);let ut=0;for(const H of C)y==="column"?(H.y=g+u.top+X+ut,V==="center"?H.x=w+u.left+Math.max(0,(b-H.width)/2):V==="flex-end"?H.x=w+u.left+Math.max(0,b-H.width):V==="stretch"&&H.style.width==null&&(H.width=b),ut+=H.height+Pt):(H.x=w+u.left+X+ut,V==="center"?H.y=g+u.top+Math.max(0,(I-u.top-u.bottom-H.height)/2):V==="flex-end"?H.y=g+u.top+Math.max(0,I-u.top-u.bottom-H.height):V==="stretch"&&H.style.height==null&&(H.height=I-u.top-u.bottom),ut+=H.width+Pt);return{x:w,y:g,width:st,height:I,node:t,children:C,style:o}}function Ks(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]=ci(i,r),u=n.props.style??{},w=li(u),g={type:"VIEW",props:{style:{...u,width:o,height:d,paddingTop:w.top,paddingRight:w.right,paddingBottom:w.bottom,paddingLeft:w.left}},children:n.children},x=hi(g,0,0,o,d);e.push({width:o,height:d,boxes:x.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 Zs{constructor(){qe(this,"objects",[null]);qe(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 b of e.pages){const y=this.renderPageContent(b.boxes,b.width,b.height,b.style),j=this.addObject(`<< /Length ${y.length} >>
39
40
  stream
40
- ${w}
41
- endstream`),C=this.addObject("");a.push(C),this.objects[C]=`<< /Type /Page /Parent 0 0 R /MediaBox [0 0 ${v.width.toFixed(2)} ${v.height.toFixed(2)}] /Contents ${M} 0 R /Resources << /Font << /F1 ${i} 0 R /F2 ${s} 0 R >> >> >>`}const c=a.map(v=>`${v} 0 R`).join(" "),l=this.addObject(`<< /Type /Pages /Kids [${c}] /Count ${a.length} >>`);for(const v of a)this.objects[v]=this.objects[v].replace("/Parent 0 0 R",`/Parent ${l} 0 R`);const b=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]}
41
+ ${y}
42
+ endstream`),C=this.addObject("");o.push(C),this.objects[C]=`<< /Type /Page /Parent 0 0 R /MediaBox [0 0 ${b.width.toFixed(2)} ${b.height.toFixed(2)}] /Contents ${j} 0 R /Resources << /Font << /F1 ${i} 0 R /F2 ${r} 0 R >> >> >>`}const d=o.map(b=>`${b} 0 R`).join(" "),u=this.addObject(`<< /Type /Pages /Kids [${d}] /Count ${o.length} >>`);for(const b of o)this.objects[b]=this.objects[b].replace("/Parent 0 0 R",`/Parent ${u} 0 R`);const w=this.addObject(`<< /Type /Catalog /Pages ${u} 0 R >>`);let g=`%PDF-1.4
43
+ `;this.offsets=[0];for(let b=1;b<this.objects.length;b++)this.offsets[b]=g.length,g+=`${b} 0 obj
44
+ ${this.objects[b]}
44
45
  endobj
45
- `;const j=g.length;g+=`xref
46
+ `;const x=g.length;g+=`xref
46
47
  0 ${this.objects.length}
47
48
  `,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
+ `;for(let b=1;b<this.objects.length;b++)g+=`${String(this.offsets[b]).padStart(10,"0")} 00000 n
49
50
  `;return g+=`trailer
50
- << /Size ${this.objects.length} /Root ${b} 0 R /Info ${n} 0 R >>
51
+ << /Size ${this.objects.length} /Root ${w} 0 R /Info ${n} 0 R >>
51
52
  `,g+=`startxref
52
- ${j}
53
- %%EOF`,new TextEncoder().encode(g)}renderPageContent(t,n,i,s){const a=[],c=_t(s.backgroundColor);c&&(a.push("q"),a.push(`${c[0].toFixed(3)} ${c[1].toFixed(3)} ${c[2].toFixed(3)} rg`),a.push(`0 0 ${n.toFixed(2)} ${i.toFixed(2)} re f`),a.push("Q"));const l=b=>{const{x:g,y:j,width:v,height:w,style:M,node:C,text:W}=b,E=i-j-w,O=_t(M.backgroundColor);if(O&&(a.push("q"),a.push(`${O[0].toFixed(3)} ${O[1].toFixed(3)} ${O[2].toFixed(3)} rg`),a.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${w.toFixed(2)} re f`),a.push("Q")),M.borderWidth&&M.borderWidth>0){const F=_t(M.borderColor)??[0,0,0];a.push("q"),a.push(`${M.borderWidth} w`),a.push(`${F[0].toFixed(3)} ${F[1].toFixed(3)} ${F[2].toFixed(3)} RG`),a.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${w.toFixed(2)} re S`),a.push("Q")}if((C.type==="TEXT"||C.type==="LINK")&&W!=null){const F=M.fontSize??12,T=_t(M.color)??[0,0,0],Z=Ut(M.fontWeight)?"F2":"F1",J=M.paddingLeft??M.padding??0,G=M.paddingTop??M.padding??0,ie=Math.max(0,v-J-(M.paddingRight??M.padding??0)),be=Wn(W,M,ie||v),me=(M.lineHeight??1.4)*F;a.push("q"),a.push("BT"),a.push(`/${Z} ${F} Tf`),a.push(`${T[0].toFixed(3)} ${T[1].toFixed(3)} ${T[2].toFixed(3)} rg`),be.lines.forEach((L,se)=>{let $=g+J;const S=L.length*F*(Ut(M.fontWeight)?.55:.5);M.textAlign==="center"?$=g+(v-S)/2:M.textAlign==="right"&&($=g+v-S-(M.paddingRight??M.padding??0));const K=i-j-G-F-se*me;a.push(`1 0 0 1 ${$.toFixed(2)} ${K.toFixed(2)} Tm`),a.push(`(${ht(L)}) Tj`)}),a.push("ET"),a.push("Q")}C.type==="IMAGE"&&(a.push("q"),a.push("0.85 0.85 0.85 rg"),a.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${w.toFixed(2)} re f`),a.push("0.6 0.6 0.6 RG 1 w"),a.push(`${g.toFixed(2)} ${E.toFixed(2)} ${v.toFixed(2)} ${w.toFixed(2)} re S`),a.push(`BT /F1 10 Tf 0.4 0.4 0.4 rg 1 0 0 1 ${(g+8).toFixed(2)} ${(E+w/2-4).toFixed(2)} Tm (Image) Tj ET`),a.push("Q"));for(const F of b.children)l(F)};for(const b of t)l(b);return a.join(`
54
- `)}}function Cr(e){return new Nr().build(e)}function cn(e){const t=On(e),n=Pr(t);return Cr(n)}function Tr(e){return cn(e)}function ln(e){const t=cn(e),n=new Uint8Array(t.byteLength);return n.set(t),new Blob([n],{type:"application/pdf"})}function Xn(e){return URL.createObjectURL(ln(e))}function $r(e,t="document.pdf"){const n=Xn(e),i=document.createElement("a");i.href=n,i.download=t,i.click(),URL.revokeObjectURL(n)}async function Rr(e){return cn(e)}async function Ir(e){return ln(e)}exports.ALL_TOOLBAR_TOOLS=mr;exports.AddText=sn;exports.Clear=an;exports.DEFAULT_TOOLBAR_LAYOUT=zt;exports.Document=In;exports.Download=en;exports.Erase=on;exports.HIGHLIGHT_PRESETS=Wt;exports.Highlight=tn;exports.Image=En;exports.Link=Fn;exports.Navigation=Yt;exports.Open=Jt;exports.PAGE_SIZES=Hn;exports.Page=Ln;exports.PdfViewer=Rn;exports.Print=Qt;exports.Reload=Vt;exports.Rotate=Kt;exports.Signature=rn;exports.Text=Dn;exports.Thumbnail=qt;exports.UNDERLINE_PRESETS=Gt;exports.Underline=nn;exports.View=Sn;exports.Zoom=Zt;exports.default=Rn;exports.download=$r;exports.hexToMarkupColor=Xt;exports.pdf=Tr;exports.renderToBlob=Ir;exports.renderToBuffer=Rr;exports.resolvePageSize=zn;exports.setPdfWorkerSrc=Ht;exports.toBlob=ln;exports.toUrl=Xn;
53
+ ${x}
54
+ %%EOF`,new TextEncoder().encode(g)}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:g,y:x,width:b,height:y,style:j,node:C,text:E}=w,U=i-x-y,L=De(j.backgroundColor);if(L&&(o.push("q"),o.push(`${L[0].toFixed(3)} ${L[1].toFixed(3)} ${L[2].toFixed(3)} rg`),o.push(`${g.toFixed(2)} ${U.toFixed(2)} ${b.toFixed(2)} ${y.toFixed(2)} re f`),o.push("Q")),j.borderWidth&&j.borderWidth>0){const Y=De(j.borderColor)??[0,0,0];o.push("q"),o.push(`${j.borderWidth} w`),o.push(`${Y[0].toFixed(3)} ${Y[1].toFixed(3)} ${Y[2].toFixed(3)} RG`),o.push(`${g.toFixed(2)} ${U.toFixed(2)} ${b.toFixed(2)} ${y.toFixed(2)} re S`),o.push("Q")}if((C.type==="TEXT"||C.type==="LINK")&&E!=null){const Y=j.fontSize??12,I=De(j.color)??[0,0,0],st=sn(j.fontWeight)?"F2":"F1",rt=j.paddingLeft??j.padding??0,V=j.paddingTop??j.padding??0,Z=Math.max(0,b-rt-(j.paddingRight??j.padding??0)),mt=di(E,j,Z||b),bt=(j.lineHeight??1.4)*Y;o.push("q"),o.push("BT"),o.push(`/${st} ${Y} Tf`),o.push(`${I[0].toFixed(3)} ${I[1].toFixed(3)} ${I[2].toFixed(3)} rg`),mt.lines.forEach((X,Pt)=>{let ut=g+rt;const H=X.length*Y*(sn(j.fontWeight)?.55:.5);j.textAlign==="center"?ut=g+(b-H)/2:j.textAlign==="right"&&(ut=g+b-H-(j.paddingRight??j.padding??0));const J=i-x-V-Y-Pt*bt;o.push(`1 0 0 1 ${ut.toFixed(2)} ${J.toFixed(2)} Tm`),o.push(`(${Me(X)}) Tj`)}),o.push("ET"),o.push("Q")}C.type==="IMAGE"&&(o.push("q"),o.push("0.85 0.85 0.85 rg"),o.push(`${g.toFixed(2)} ${U.toFixed(2)} ${b.toFixed(2)} ${y.toFixed(2)} re f`),o.push("0.6 0.6 0.6 RG 1 w"),o.push(`${g.toFixed(2)} ${U.toFixed(2)} ${b.toFixed(2)} ${y.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)} ${(U+y/2-4).toFixed(2)} Tm (Image) Tj ET`),o.push("Q"));for(const Y of w.children)u(Y)};for(const w of e)u(w);return o.join(`
55
+ `)}}function Qs(t){return new Zs().build(t)}function vn(t){const e=oi(t),n=Ks(e);return Qs(n)}function Js(t){return vn(t)}function jn(t){const e=vn(t),n=new Uint8Array(e.byteLength);return n.set(e),new Blob([n],{type:"application/pdf"})}function ui(t){return URL.createObjectURL(jn(t))}function tr(t,e="document.pdf"){const n=ui(t),i=document.createElement("a");i.href=n,i.download=e,i.click(),URL.revokeObjectURL(n)}async function er(t){return vn(t)}async function nr(t){return jn(t)}exports.ALL_TOOLBAR_TOOLS=Hs;exports.AddText=yn;exports.Clear=_n;exports.DEFAULT_TOOLBAR_LAYOUT=nn;exports.Document=Qn;exports.Download=gn;exports.Erase=bn;exports.HIGHLIGHT_PRESETS=rn;exports.Highlight=mn;exports.Image=ni;exports.Link=ii;exports.Navigation=ln;exports.Open=pn;exports.PAGE_SIZES=ai;exports.Page=Jn;exports.PdfViewer=Zn;exports.Print=fn;exports.Reload=un;exports.Rotate=hn;exports.Signature=xn;exports.Text=ei;exports.Thumbnail=cn;exports.UNDERLINE_PRESETS=on;exports.Underline=wn;exports.View=ti;exports.Zoom=dn;exports.default=Zn;exports.download=tr;exports.hexToMarkupColor=an;exports.pdf=Js;exports.renderToBlob=nr;exports.renderToBuffer=er;exports.resolvePageSize=ci;exports.setPdfWorkerSrc=en;exports.toBlob=jn;exports.toUrl=ui;
55
56
  //# sourceMappingURL=epochs-pdf.cjs.map