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