epochs-pdf 0.1.7 → 0.1.9

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