@superdoc-dev/esign 1.4.2 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,22 +37,22 @@ function App() {
37
37
 
38
38
  fields={{
39
39
  document: [
40
- { id: 'user_name', value: 'John Doe' },
41
- { id: 'agreement_date', value: new Date().toLocaleDateString() },
42
- { id: 'company_name', value: 'SuperDoc' },
43
- { id: 'service_type', value: 'Premium' },
44
- { id: 'agreement_jurisdiction', value: 'CA' },
45
- { id: 'company_address', value: '123 Main St, Anytown, USA' }
40
+ { id: '1', value: 'John Doe' },
41
+ { id: '2', value: new Date().toLocaleDateString() },
42
+ { id: '3', value: 'SuperDoc' },
43
+ { id: '4', value: 'Premium' },
44
+ { id: '5', value: 'CA' },
45
+ { id: '6', value: '123 Main St, Anytown, USA' }
46
46
  ],
47
47
  signer: [
48
48
  {
49
- id: 'signature',
49
+ id: '7',
50
50
  type: 'signature',
51
51
  validation: { required: true },
52
52
  label: 'Type your full name'
53
53
  },
54
54
  {
55
- id: 'accept_terms',
55
+ id: '8',
56
56
  type: 'checkbox',
57
57
  validation: { required: true },
58
58
  label: 'I accept the terms'
@@ -118,11 +118,11 @@ See [Python, Node.js, and more examples](https://docs.superdoc.dev/solutions/esi
118
118
  timestamp: "2024-01-15T10:30:00Z",
119
119
  duration: 45000,
120
120
  documentFields: [
121
- { id: "user_name", value: "John Doe" }
121
+ { id: "1", value: "John Doe" }
122
122
  ],
123
123
  signerFields: [
124
- { id: "signature", value: "John Doe" },
125
- { id: "accept_terms", value: true }
124
+ { id: "7", value: "John Doe" },
125
+ { id: "8", value: true }
126
126
  ],
127
127
  auditTrail: [
128
128
  { type: "ready", timestamp: "..." },
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signature.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/signature.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../src/defaults/DownloadButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpE,eAAO,MAAM,oBAAoB,GAAI,SAAS,cAAc,kCA2B3D,CAAC"}
1
+ {"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../src/defaults/DownloadButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpE,eAAO,MAAM,oBAAoB,GAAI,SAAS,cAAc,kCAuC3D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SubmitButton.d.ts","sourceRoot":"","sources":["../../src/defaults/SubmitButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,YAAY,gCAkCvD,CAAC"}
1
+ {"version":3,"file":"SubmitButton.d.ts","sourceRoot":"","sources":["../../src/defaults/SubmitButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,YAAY,gCAsCvD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import { textToImageDataUrl } from './utils/signature';
1
2
  import { SignatureInput, CheckboxInput } from './defaults';
2
3
  import type * as Types from './types';
3
4
  export * from './types';
5
+ export { textToImageDataUrl };
4
6
  export { SignatureInput, CheckboxInput };
5
7
  declare const SuperDocESign: import('react').ForwardRefExoticComponent<Types.SuperDocESignProps & import('react').RefAttributes<Types.SuperDocESignHandle>>;
6
8
  export default SuperDocESign;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,gIAwblB,CAAC;AAIF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,gIAuflB,CAAC;AAIF,eAAe,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var le=Object.create;var z=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var me=(c,d,u,s)=>{if(d&&typeof d=="object"||typeof d=="function")for(let n of de(d))!ge.call(c,n)&&n!==u&&z(c,n,{get:()=>d[n],enumerable:!(s=ue(d,n))||s.enumerable});return c};var fe=(c,d,u)=>(u=c!=null?le(pe(c)):{},me(d||!c||!c.__esModule?z(u,"default",{value:c,enumerable:!0}):u,c));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),i=require("react"),L=({value:c,onChange:d,isDisabled:u,label:s})=>l.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[s&&l.jsx("label",{children:s}),l.jsx("input",{type:"text",value:String(c||""),onChange:n=>d(n.target.value),disabled:u,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),P=({value:c,onChange:d,isDisabled:u,label:s})=>l.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[l.jsx("input",{type:"checkbox",checked:!!c,onChange:n=>d(n.target.checked),disabled:u}),l.jsx("span",{children:s})]}),he=c=>({onClick:u,fileName:s,isDisabled:n})=>{const g=c?.label||"Download";return l.jsxs("button",{onClick:u,disabled:n,className:"superdoc-esign-btn superdoc-esign-btn--download",style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #d0d5dd",background:"#ffffff",color:"#333",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,fontSize:"16px",fontWeight:"bold"},children:[g," ",s&&`(${s})`]})},ve=c=>({onClick:u,isValid:s,isDisabled:n,isSubmitting:g})=>{const C=()=>c?.label||"Submit";return l.jsx("button",{onClick:u,disabled:!s||n||g,className:"superdoc-esign-btn superdoc-esign-btn--submit",style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:!s||n?"not-allowed":"pointer",opacity:!s||n?.5:1,fontSize:"16px",fontWeight:"bold"},children:C()})},W=i.forwardRef((c,d)=>{const{eventId:u,document:s,fields:n={},download:g,submit:C,onSubmit:R,onDownload:k,onStateChange:E,onFieldChange:T,onFieldsDiscovered:N,isDisabled:f=!1,className:$,style:K,documentHeight:X="600px"}=c,[x,F]=i.useState(!s.validation?.scroll?.required),[p,M]=i.useState(new Map),[b,I]=i.useState(!1),[h,A]=i.useState(!1),[q,_]=i.useState([]),[B,Y]=i.useState(!1),w=i.useRef(null),D=i.useRef(null),G=i.useRef(Date.now()),v=i.useRef(n),y=i.useRef([]),U=i.useRef(N);v.current=n,U.current=N,i.useEffect(()=>{y.current=q},[q]);const j=i.useCallback(e=>{if(!D.current?.activeEditor)return;const t=D.current.activeEditor,r=v.current.signer?.find(o=>o.id===e.id);let a;r?.type==="signature"&&e.value?a={json:{type:"image",attrs:{src:typeof e.value=="string"&&e.value.startsWith("data:image/")?e.value:J(String(e.value)),alt:"Signature"}}}:a={text:String(e.value??"")},e.id&&t.commands.updateStructuredContentById(e.id,a)},[]);function J(e){const t=globalThis.document.createElement("canvas"),r=t.getContext("2d"),a=30;r.font=`italic ${a}px cursive`;const m=r.measureText(e).width,ie=a*1.3,ae=4,ce=6;return t.width=Math.ceil(m+ae*2)+20,t.height=Math.ceil(ie+ce*2),r.font=`italic ${a}px cursive`,r.fillStyle="black",r.textAlign="center",r.textBaseline="middle",r.fillText(e,t.width/2,t.height/2),t.toDataURL("image/png")}const V=i.useCallback(e=>{if(!e)return;const t=e.helpers.structuredContentCommands.getStructuredContentTags(e.state),r=new Map;v.current.document?.forEach(o=>{o.id&&r.set(o.id,o.value)}),v.current.signer?.forEach(o=>{o.value!==void 0&&r.set(o.id,o.value)});const a=t.map(({node:o})=>({id:o.attrs.id,label:o.attrs.label,value:r.get(o.attrs.id)??o.textContent??""})).filter(o=>o.id);a.length>0&&(U.current?.(a),[...v.current.document||[],...v.current.signer||[]].filter(m=>m.value!==void 0).forEach(m=>j({id:m.id,value:m.value})))},[j]),S=e=>{const t={...e,timestamp:new Date().toISOString()},r=globalThis?.__SUPERDOC_AUDIT_MOCK__;r&&r(t);const a=[...y.current,t];return y.current=a,_(a),a};i.useEffect(()=>{if(!w.current)return;let e=!1,t=null;return(async()=>{const{SuperDoc:a}=await import("superdoc");e||(t=new a({selector:w.current,document:s.source,documentMode:"viewing",modules:{comments:!1},onReady:()=>{e||(t?.activeEditor&&V(t.activeEditor),S({type:"ready"}),Y(!0))}}),D.current=t)})(),()=>{e=!0,t&&typeof t.destroy=="function"&&t.destroy(),D.current=null}},[s.source,s.mode,V]),i.useEffect(()=>{if(!s.validation?.scroll?.required||!B)return;const e=w.current;if(!e)return;const t=()=>{const{scrollTop:r,scrollHeight:a,clientHeight:o}=e,m=r/(a-o);(m>=.95||a<=o)&&(F(!0),S({type:"scroll",data:{percent:Math.round(m*100)}}))};return e.addEventListener("scroll",t),t(),()=>e.removeEventListener("scroll",t)},[s.validation?.scroll?.required,B]);const Q=i.useCallback((e,t)=>{M(r=>{const a=r.get(e),o=new Map(r);return o.set(e,t),j({id:e,value:t}),S({type:"field_change",data:{fieldId:e,value:t,previousValue:a}}),T?.({id:e,value:t,previousValue:a}),o})},[T,j]),H=i.useCallback(()=>s.validation?.scroll?.required&&!x?!1:(n.signer||[]).every(e=>{if(!e.validation?.required)return!0;const t=p.get(e.id);return t&&(typeof t!="string"||t.trim())}),[x,n.signer,p,s.validation?.scroll?.required]);i.useEffect(()=>{const e=H();I(e),E?.({scrolled:x,fields:p,isValid:e,isSubmitting:h})},[x,p,h,H,E]);const Z=i.useCallback(async()=>{if(f)return;const e={eventId:u,documentSource:s.source,fields:{document:n.document||[],signer:(n.signer||[]).map(t=>({id:t.id,value:p.get(t.id)??null}))},fileName:g?.fileName||"document.pdf"};await k?.(e)},[f,u,s.source,n,p,g,k]),ee=i.useCallback(async()=>{if(!b||f||h)return;A(!0),S({type:"submit"});const e=S({type:"submit"}),t={eventId:u,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-G.current)/1e3),auditTrail:e,documentFields:n.document||[],signerFields:(n.signer||[]).map(r=>({id:r.id,value:p.get(r.id)??null})),isFullyCompleted:b};try{await R(t)}finally{A(!1)}},[b,f,h,u,n,p,R]),te=e=>{const t=e.component||ne(e.type);return l.jsx(t,{value:p.get(e.id)??null,onChange:r=>Q(e.id,r),isDisabled:f,label:e.label},e.id)},ne=e=>{switch(e){case"signature":case"text":return L;case"checkbox":return P}},se=()=>{const e=g?.component||he(g);return e?l.jsx(e,{onClick:Z,fileName:g?.fileName,isDisabled:f}):null},re=()=>{if(s.mode==="download")return null;const e=C?.component||ve(C);return l.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",children:l.jsx(e,{onClick:ee,isValid:b,isDisabled:f,isSubmitting:h})})},O=se(),oe=re();return i.useImperativeHandle(d,()=>({getState:()=>({scrolled:x,fields:p,isValid:b,isSubmitting:h}),getAuditTrail:()=>y.current,reset:()=>{F(!s.validation?.scroll?.required),M(new Map),I(!1),y.current=[],_([])}})),l.jsxs("div",{className:`superdoc-esign-container ${$||""}`,style:K,children:[l.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",children:[O&&l.jsx("div",{className:"superdoc-esign-document-toolbar",children:l.jsx("div",{className:"superdoc-esign-document-controls",children:O})}),l.jsx("div",{ref:w,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:X,overflow:"auto"}})]}),l.jsxs("div",{className:"superdoc-esign-controls","data-testid":"superdoc-esign-controls",children:[n.signer&&n.signer.length>0&&l.jsx("div",{className:"superdoc-esign-fields","data-testid":"superdoc-esign-fields",children:n.signer.map(te)}),oe]})]})});W.displayName="SuperDocESign";exports.CheckboxInput=P;exports.SignatureInput=L;exports.default=W;
1
+ "use strict";var ye=Object.create;var J=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var Ce=(i,c,r,n)=>{if(c&&typeof c=="object"||typeof c=="function")for(let o of xe(c))!we.call(i,o)&&o!==r&&J(i,o,{get:()=>c[o],enumerable:!(n=be(c,o))||n.enumerable});return i};var De=(i,c,r)=>(r=i!=null?ye(Se(i)):{},Ce(c||!i||!i.__esModule?J(r,"default",{value:i,enumerable:!0}):r,i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),a=require("react"),Q=i=>{const c=globalThis.document.createElement("canvas"),r=c.getContext("2d"),n=30;r.font=`italic ${n}px cursive`;const u=r.measureText(i).width,f=n*1.3,g=4,M=6;return c.width=Math.ceil(u+g*2)+20,c.height=Math.ceil(f+M*2),r.font=`italic ${n}px cursive`,r.fillStyle="black",r.textAlign="center",r.textBaseline="middle",r.fillText(i,c.width/2,c.height/2),c.toDataURL("image/png")},Z=({value:i,onChange:c,isDisabled:r,label:n})=>l.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n&&l.jsx("label",{children:n}),l.jsx("input",{type:"text",value:String(i||""),onChange:o=>c(o.target.value),disabled:r,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),ee=({value:i,onChange:c,isDisabled:r,label:n})=>l.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[l.jsx("input",{type:"checkbox",checked:!!i,onChange:o=>c(o.target.checked),disabled:r}),l.jsx("span",{children:n})]}),je=i=>({onClick:r,fileName:n,isDisabled:o,isDownloading:u})=>{const f=i?.label||"Download",g=o||u;return l.jsxs("button",{onClick:r,disabled:g,className:`superdoc-esign-btn superdoc-esign-btn--download${u?" superdoc-esign-btn--loading":""}`,style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #d0d5dd",background:"#ffffff",color:"#333",cursor:g?"not-allowed":"pointer",opacity:g?.7:1,fontSize:"16px",fontWeight:"bold",display:"inline-flex",alignItems:"center",gap:"8px",transition:"opacity 0.2s ease"},children:[u&&l.jsx("span",{className:"superdoc-esign-spinner"}),u?"Downloading...":f,!u&&n&&` (${n})`]})},Me=i=>({onClick:r,isValid:n,isDisabled:o,isSubmitting:u})=>{const f=i?.label||"Submit",g=!n||o||u;return l.jsxs("button",{onClick:r,disabled:g,className:`superdoc-esign-btn superdoc-esign-btn--submit${u?" superdoc-esign-btn--loading":""}`,style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:g?"not-allowed":"pointer",opacity:g&&!u?.5:1,fontSize:"16px",fontWeight:"bold",display:"inline-flex",alignItems:"center",gap:"8px",transition:"opacity 0.2s ease"},children:[u&&l.jsx("span",{className:"superdoc-esign-spinner superdoc-esign-spinner--light"}),u?"Submitting...":f]})},te=a.forwardRef((i,c)=>{const{eventId:r,document:n,fields:o={},download:u,submit:f,onSubmit:g,onDownload:M,onStateChange:F,onFieldChange:A,onFieldsDiscovered:q,isDisabled:h=!1,className:ne,style:se,documentHeight:oe="600px"}=i,[b,_]=a.useState(!n.validation?.scroll?.required),[m,B]=a.useState(new Map),[x,V]=a.useState(!1),[v,U]=a.useState(!1),[N,z]=a.useState(!1),[O,$]=a.useState([]),[H,re]=a.useState(!1),R=a.useRef(null),T=a.useRef(null),ae=a.useRef(Date.now()),S=a.useRef(o),w=a.useRef([]),P=a.useRef(q);S.current=o,P.current=q,a.useEffect(()=>{w.current=O},[O]);const y=a.useCallback(e=>{if(!T.current?.activeEditor)return;const t=T.current.activeEditor,d=S.current.signer?.find(s=>s.id===e.id);if(e.type==="table"&&Array.isArray(e.value)){const D=t.helpers?.structuredContentCommands?.getStructuredContentTablesById?.(e.id,t.state)||[];if(D.length){const{node:k,pos:fe}=D[0],X=k.childCount;if(X>1){let j=t.state.tr;for(let E=X-1;E>=1;E--){let Y=1;for(let I=0;I<E;I++)Y+=k.child(I).nodeSize;const he=k.child(E),G=fe+Y,ve=G+he.nodeSize;j=j.delete(j.mapping.map(G),j.mapping.map(ve))}t.view?.dispatch(j)}t.commands?.appendRowsToStructuredContentTable?.({id:e.id,rows:e.value,copyRowStyle:!0})}return}let p;d?.type==="signature"&&e.value?p={json:{type:"image",attrs:{src:typeof e.value=="string"&&e.value.startsWith("data:image/")?e.value:Q(String(e.value)),alt:"Signature"}}}:p={text:String(e.value??"")},e.id&&t.commands?.updateStructuredContentById?.(e.id,p)},[]),W=a.useCallback(e=>{if(!e)return;const t=e.helpers.structuredContentCommands.getStructuredContentTags(e.state),d=new Map;S.current.document?.forEach(s=>{s.id&&d.set(s.id,s.value)}),S.current.signer?.forEach(s=>{s.value!==void 0&&d.set(s.id,s.value)});const p=t.map(({node:s})=>({id:s.attrs.id,label:s.attrs.label,value:d.get(s.attrs.id)??s.textContent??""})).filter(s=>s.id);p.length>0&&(P.current?.(p),(S.current.document||[]).filter(s=>s.value!==void 0).forEach(s=>y({id:s.id,value:s.value,type:s.type})),(S.current.signer||[]).filter(s=>s.value!==void 0).forEach(s=>y({id:s.id,value:s.value})))},[y]),C=e=>{const t={...e,timestamp:new Date().toISOString()},d=globalThis?.__SUPERDOC_AUDIT_MOCK__;d&&d(t);const p=[...w.current,t];return w.current=p,$(p),p};a.useEffect(()=>{if(!R.current)return;let e=!1,t=null;return(async()=>{const{SuperDoc:p}=await import("superdoc");e||(t=new p({selector:R.current,document:n.source,documentMode:"viewing",modules:{comments:!1},layoutMode:n.layoutMode,layoutMargins:n.layoutMargins,onReady:()=>{e||(t?.activeEditor&&W(t.activeEditor),C({type:"ready"}),re(!0))}}),T.current=t)})(),()=>{e=!0,t&&typeof t.destroy=="function"&&t.destroy(),T.current=null}},[n.source,n.mode,n.layoutMode,n.layoutMargins?.top,n.layoutMargins?.bottom,n.layoutMargins?.left,n.layoutMargins?.right,W]),a.useEffect(()=>{if(!n.validation?.scroll?.required||!H)return;const e=R.current;if(!e)return;const t=()=>{const{scrollTop:d,scrollHeight:p,clientHeight:s}=e,D=d/(p-s);(D>=.95||p<=s)&&(_(!0),C({type:"scroll",data:{percent:Math.round(D*100)}}))};return e.addEventListener("scroll",t),t(),()=>e.removeEventListener("scroll",t)},[n.validation?.scroll?.required,H]);const ie=a.useCallback((e,t)=>{B(d=>{const p=d.get(e),s=new Map(d);return s.set(e,t),y({id:e,value:t}),C({type:"field_change",data:{fieldId:e,value:t,previousValue:p}}),A?.({id:e,value:t,previousValue:p}),s})},[A,y]),L=a.useCallback(()=>n.validation?.scroll?.required&&!b?!1:(o.signer||[]).every(e=>{if(!e.validation?.required)return!0;const t=m.get(e.id);return t&&(typeof t!="string"||t.trim())}),[b,o.signer,m,n.validation?.scroll?.required]);a.useEffect(()=>{const e=L();V(e),F?.({scrolled:b,fields:m,isValid:e,isSubmitting:v})},[b,m,v,L,F]);const ce=a.useCallback(async()=>{if(h||N)return;z(!0);const e={eventId:r,documentSource:n.source,fields:{document:o.document||[],signer:(o.signer||[]).map(t=>({id:t.id,value:m.get(t.id)??null}))},fileName:u?.fileName||"document.pdf"};try{await M?.(e)}finally{z(!1)}},[h,N,r,n.source,o,m,u,M]),le=a.useCallback(async()=>{if(!x||h||v)return;U(!0),C({type:"submit"});const e=C({type:"submit"}),t={eventId:r,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-ae.current)/1e3),auditTrail:e,documentFields:o.document||[],signerFields:(o.signer||[]).map(d=>({id:d.id,value:m.get(d.id)??null})),isFullyCompleted:x};try{await g(t)}finally{U(!1)}},[x,h,v,r,o,m,g]),ue=e=>{const t=e.component||de(e.type);return l.jsx(t,{value:m.get(e.id)??null,onChange:d=>ie(e.id,d),isDisabled:h,label:e.label},e.id)},de=e=>{switch(e){case"signature":case"text":return Z;case"checkbox":return ee}},pe=()=>{const e=u?.component||je(u);return e?l.jsx(e,{onClick:ce,fileName:u?.fileName,isDisabled:h,isDownloading:N}):null},ge=()=>{if(n.mode==="download")return null;const e=f?.component||Me(f);return l.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",children:l.jsx(e,{onClick:le,isValid:x,isDisabled:h,isSubmitting:v})})},K=pe(),me=ge();return a.useImperativeHandle(c,()=>({getState:()=>({scrolled:b,fields:m,isValid:x,isSubmitting:v}),getAuditTrail:()=>w.current,reset:()=>{_(!n.validation?.scroll?.required),B(new Map),V(!1),w.current=[],$([])},updateFieldInDocument:y}),[b,m,x,v,n.validation?.scroll?.required,y]),l.jsxs("div",{className:`superdoc-esign-container ${ne||""}`,style:se,children:[l.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",children:[K&&l.jsx("div",{className:"superdoc-esign-document-toolbar",children:l.jsx("div",{className:"superdoc-esign-document-controls",children:K})}),l.jsx("div",{ref:R,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:oe,overflow:"auto"}})]}),l.jsxs("div",{className:"superdoc-esign-controls","data-testid":"superdoc-esign-controls",children:[o.signer&&o.signer.length>0&&l.jsx("div",{className:"superdoc-esign-fields","data-testid":"superdoc-esign-fields",children:o.signer.map(ue)}),me]})]})});te.displayName="SuperDocESign";exports.CheckboxInput=ee;exports.SignatureInput=Z;exports.default=te;exports.textToImageDataUrl=Q;