@superdoc-dev/esign 1.3.1 → 1.4.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.
@@ -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
- import type * as Types from "./types";
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":"AASA,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,gIAwejB,CAAC;AAIH,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,gIAqclB,CAAC;AAIF,eAAe,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,22 +1 @@
1
- "use strict";var me=Object.create;var oe=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var he=(i,f,l,a)=>{if(f&&typeof f=="object"||typeof f=="function")for(let r of ve(f))!xe.call(i,r)&&r!==l&&oe(i,r,{get:()=>f[r],enumerable:!(a=ge(f,r))||a.enumerable});return i};var Ee=(i,f,l)=>(l=i!=null?me(be(i)):{},he(f||!i||!i.__esModule?oe(l,"default",{value:i,enumerable:!0}):l,i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react");var K={exports:{}},U={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var ae;function ye(){if(ae)return U;ae=1;var i=Symbol.for("react.transitional.element"),f=Symbol.for("react.fragment");function l(a,r,g){var h=null;if(g!==void 0&&(h=""+g),r.key!==void 0&&(h=""+r.key),"key"in r){g={};for(var T in r)T!=="key"&&(g[T]=r[T])}else g=r;return r=g.ref,{$$typeof:i,type:a,key:h,ref:r!==void 0?r:null,props:g}}return U.Fragment=f,U.jsx=l,U.jsxs=l,U}var L={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var se;function Re(){return se||(se=1,process.env.NODE_ENV!=="production"&&(function(){function i(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===te?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case _:return"Fragment";case x:return"Profiler";case B:return"StrictMode";case w:return"Suspense";case G:return"SuspenseList";case Z:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case ee:return"Portal";case O:return e.displayName||"Context";case J:return(e._context.displayName||"Context")+".Consumer";case H:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case X:return n=e.displayName||null,n!==null?n:i(e.type)||"Memo";case D:n=e._payload,e=e._init;try{return i(e(n))}catch{}}return null}function f(e){return""+e}function l(e){try{f(e);var n=!1}catch{n=!0}if(n){n=console;var u=n.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),f(e)}}function a(e){if(e===_)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===D)return"<...>";try{var n=i(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function r(){var e=k.A;return e===null?null:e.getOwner()}function g(){return Error("react-stack-top-frame")}function h(e){if(y.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function T(e,n){function u(){C||(C=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",n))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function W(){var e=i(this.type);return N[e]||(N[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function V(e,n,u,p,F,q){var m=u.ref;return e={$$typeof:z,type:e,key:n,props:u,_owner:p},(m!==void 0?m:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:W}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:F}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function M(e,n,u,p,F,q){var m=n.children;if(m!==void 0)if(p)if(re(m)){for(p=0;p<m.length;p++)Y(m[p]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Y(m);if(y.call(n,"key")){m=i(e);var A=Object.keys(n).filter(function(ne){return ne!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",j[m+p]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
- let props = %s;
19
- <%s {...props} />
20
- React keys must be passed directly to JSX without using spread:
21
- let props = %s;
22
- <%s key={someKey} {...props} />`,p,m,A,m),j[m+p]=!0)}if(m=null,u!==void 0&&(l(u),m=""+u),h(n)&&(l(n.key),m=""+n.key),"key"in n){u={};for(var I in n)I!=="key"&&(u[I]=n[I])}else u=n;return m&&T(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),V(e,m,u,r(),F,q)}function Y(e){E(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===D&&(e._payload.status==="fulfilled"?E(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function E(e){return typeof e=="object"&&e!==null&&e.$$typeof===z}var P=d,z=Symbol.for("react.transitional.element"),ee=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),B=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),J=Symbol.for("react.consumer"),O=Symbol.for("react.context"),H=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),G=Symbol.for("react.suspense_list"),X=Symbol.for("react.memo"),D=Symbol.for("react.lazy"),Z=Symbol.for("react.activity"),te=Symbol.for("react.client.reference"),k=P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,y=Object.prototype.hasOwnProperty,re=Array.isArray,R=console.createTask?console.createTask:function(){return null};P={react_stack_bottom_frame:function(e){return e()}};var C,N={},Q=P.react_stack_bottom_frame.bind(P,g)(),$=R(a(g)),j={};L.Fragment=_,L.jsx=function(e,n,u){var p=1e4>k.recentlyCreatedOwnerStacks++;return M(e,n,u,!1,p?Error("react-stack-top-frame"):Q,p?R(a(e)):$)},L.jsxs=function(e,n,u){var p=1e4>k.recentlyCreatedOwnerStacks++;return M(e,n,u,!0,p?Error("react-stack-top-frame"):Q,p?R(a(e)):$)}})()),L}var ie;function _e(){return ie||(ie=1,process.env.NODE_ENV==="production"?K.exports=ye():K.exports=Re()),K.exports}var b=_e();const ce=({value:i,onChange:f,isDisabled:l,label:a})=>b.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[a&&b.jsx("label",{children:a}),b.jsx("input",{type:"text",value:String(i||""),onChange:r=>f(r.target.value),disabled:l,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),le=({value:i,onChange:f,isDisabled:l,label:a})=>b.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[b.jsx("input",{type:"checkbox",checked:!!i,onChange:r=>f(r.target.checked),disabled:l}),b.jsx("span",{children:a})]}),Se=i=>({onClick:l,fileName:a,isDisabled:r})=>{const g=i?.label||"Download";return b.jsxs("button",{onClick:l,disabled:r,className:"superdoc-esign-btn superdoc-esign-btn--download",style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #d0d5dd",background:"#ffffff",color:"#333",cursor:r?"not-allowed":"pointer",opacity:r?.5:1,fontSize:"16px",fontWeight:"bold"},children:[g," ",a&&`(${a})`]})},Te=i=>({onClick:l,isValid:a,isDisabled:r,isSubmitting:g})=>{const h=()=>i?.label||"Submit";return b.jsx("button",{onClick:l,disabled:!a||r||g,className:"superdoc-esign-btn superdoc-esign-btn--submit",style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:!a||r?"not-allowed":"pointer",opacity:!a||r?.5:1,fontSize:"16px",fontWeight:"bold"},children:h()})},ue=d.forwardRef((i,f)=>{const{eventId:l,document:a,fields:r={},download:g,submit:h,onSubmit:T,onDownload:W,onStateChange:V,onFieldChange:M,onFieldsDiscovered:Y,isDisabled:E=!1,className:P,style:z,documentHeight:ee="600px"}=i,[_,B]=d.useState(!a.validation?.scroll?.required),[x,J]=d.useState(new Map),[O,H]=d.useState(!1),[w,G]=d.useState(!1),[X,D]=d.useState([]),[Z,te]=d.useState(!1),k=d.useRef(null),y=d.useRef(null),re=d.useRef(Date.now()),R=d.useRef(r),C=d.useRef([]);R.current=r,d.useEffect(()=>{C.current=X},[X]);const N=d.useCallback(t=>{if(!y.current?.activeEditor)return;const o=y.current.activeEditor,s=R.current.signer?.find(c=>c.id===t.id);let v;s?.type==="signature"&&t.value?v={json:{type:"image",attrs:{src:typeof t.value=="string"&&t.value.startsWith("data:image/")?t.value:Q(String(t.value)),alt:"Signature"}}}:v={text:String(t.value??"")},t.id&&o.commands.updateStructuredContentById(t.id,v)},[]);function Q(t){const o=globalThis.document.createElement("canvas"),s=o.getContext("2d"),v=30;s.font=`italic ${v}px cursive`;const S=s.measureText(t).width,de=v*1.3,fe=4,pe=6;return o.width=Math.ceil(S+fe*2)+20,o.height=Math.ceil(de+pe*2),s.font=`italic ${v}px cursive`,s.fillStyle="black",s.textAlign="center",s.textBaseline="middle",s.fillText(t,o.width/2,o.height/2),o.toDataURL("image/png")}const $=d.useCallback(t=>{if(!t)return;const o=t.helpers.structuredContentCommands.getStructuredContentTags(t.state),s=new Map;R.current.document?.forEach(c=>{c.id&&s.set(c.id,c.value)}),R.current.signer?.forEach(c=>{c.value!==void 0&&s.set(c.id,c.value)});const v=o.map(({node:c})=>({id:c.attrs.id,label:c.attrs.label,value:s.get(c.attrs.id)??c.textContent??""})).filter(c=>c.id);v.length>0&&(Y?.(v),[...R.current.document||[],...R.current.signer||[]].filter(S=>S.value!==void 0).forEach(S=>N({id:S.id,value:S.value})))},[Y,N]),j=t=>{const o={...t,timestamp:new Date().toISOString()},s=globalThis?.__SUPERDOC_AUDIT_MOCK__;s&&s(o);const v=[...C.current,o];return C.current=v,D(v),v};d.useEffect(()=>k.current?((async()=>{const{SuperDoc:o}=await import("superdoc"),s=new o({selector:k.current,document:a.source,documentMode:"viewing",onReady:()=>{s.activeEditor&&$(s.activeEditor),j({type:"ready"}),te(!0)}});y.current=s})(),()=>{y.current&&(typeof y.current.destroy=="function"&&y.current.destroy(),y.current=null)}):void 0,[a.source,a.mode,$]),d.useEffect(()=>{if(!a.validation?.scroll?.required||!Z)return;const t=k.current;if(!t)return;const o=()=>{const{scrollTop:s,scrollHeight:v,clientHeight:c}=t,S=s/(v-c);(S>=.95||v<=c)&&(B(!0),j({type:"scroll",data:{percent:Math.round(S*100)}}))};return t.addEventListener("scroll",o),o(),()=>t.removeEventListener("scroll",o)},[a.validation?.scroll?.required,Z]);const e=d.useCallback((t,o)=>{J(s=>{const v=s.get(t),c=new Map(s);return c.set(t,o),N({id:t,value:o}),j({type:"field_change",data:{fieldId:t,value:o,previousValue:v}}),M?.({id:t,value:o,previousValue:v}),c})},[M,N]),n=d.useCallback(()=>a.validation?.scroll?.required&&!_?!1:(r.signer||[]).every(t=>{if(!t.validation?.required)return!0;const o=x.get(t.id);return o&&(typeof o!="string"||o.trim())}),[_,r.signer,x,a.validation?.scroll?.required]);d.useEffect(()=>{const t=n();H(t),V?.({scrolled:_,fields:x,isValid:t,isSubmitting:w})},[_,x,w,n,V]);const u=d.useCallback(async()=>{if(E)return;const t={eventId:l,documentSource:a.source,fields:{document:r.document||[],signer:(r.signer||[]).map(o=>({id:o.id,value:x.get(o.id)??null}))},fileName:g?.fileName||"document.pdf"};await W?.(t)},[E,l,a.source,r,x,g,W]),p=d.useCallback(async()=>{if(!O||E||w)return;G(!0),j({type:"submit"});const t=j({type:"submit"}),o={eventId:l,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-re.current)/1e3),auditTrail:t,documentFields:r.document||[],signerFields:(r.signer||[]).map(s=>({id:s.id,value:x.get(s.id)??null})),isFullyCompleted:O};try{await T(o)}finally{G(!1)}},[O,E,w,l,r,x,T]),F=t=>{const o=t.component||q(t.type);return b.jsx(o,{value:x.get(t.id)??null,onChange:s=>e(t.id,s),isDisabled:E,label:t.label},t.id)},q=t=>{switch(t){case"signature":case"text":return ce;case"checkbox":return le}},m=()=>{const t=g?.component||Se(g);return t?b.jsx(t,{onClick:u,fileName:g?.fileName,isDisabled:E}):null},A=()=>{if(a.mode==="download")return null;const t=h?.component||Te(h);return b.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",style:{display:"flex",gap:"10px"},children:b.jsx(t,{onClick:p,isValid:O,isDisabled:E,isSubmitting:w})})},I=m(),ne=A();return d.useImperativeHandle(f,()=>({getState:()=>({scrolled:_,fields:x,isValid:O,isSubmitting:w}),getAuditTrail:()=>C.current,reset:()=>{B(!a.validation?.scroll?.required),J(new Map),H(!1),C.current=[],D([])}})),b.jsxs("div",{className:`superdoc-esign-container ${P||""}`,style:z,children:[b.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",style:{display:"flex",flexDirection:"column"},children:[I&&b.jsx("div",{className:"superdoc-esign-document-toolbar",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"8px 12px"},children:b.jsx("div",{className:"superdoc-esign-document-controls",style:{display:"flex",gap:"8px"},children:I})}),b.jsx("div",{ref:k,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:ee,overflow:"auto"}})]}),b.jsxs("div",{className:"superdoc-esign-controls",style:{marginTop:"20px"},"data-testid":"superdoc-esign-controls",children:[r.signer&&r.signer.length>0&&b.jsx("div",{className:"superdoc-esign-fields",style:{marginBottom:"20px"},"data-testid":"superdoc-esign-fields",children:r.signer.map(F)}),ne]})]})});ue.displayName="SuperDocESign";exports.CheckboxInput=le;exports.SignatureInput=ce;exports.default=ue;
1
+ "use strict";var ce=Object.create;var P=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var ge=(i,c,o,t)=>{if(c&&typeof c=="object"||typeof c=="function")for(let s of ue(c))!pe.call(i,s)&&s!==o&&P(i,s,{get:()=>c[s],enumerable:!(t=le(c,s))||t.enumerable});return i};var me=(i,c,o)=>(o=i!=null?ce(de(i)):{},ge(c||!i||!i.__esModule?P(o,"default",{value:i,enumerable:!0}):o,i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),r=require("react"),W=i=>{const c=globalThis.document.createElement("canvas"),o=c.getContext("2d"),t=30;o.font=`italic ${t}px cursive`;const u=o.measureText(i).width,f=t*1.3,g=4,D=6;return c.width=Math.ceil(u+g*2)+20,c.height=Math.ceil(f+D*2),o.font=`italic ${t}px cursive`,o.fillStyle="black",o.textAlign="center",o.textBaseline="middle",o.fillText(i,c.width/2,c.height/2),c.toDataURL("image/png")},L=({value:i,onChange:c,isDisabled:o,label:t})=>l.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t&&l.jsx("label",{children:t}),l.jsx("input",{type:"text",value:String(i||""),onChange:s=>c(s.target.value),disabled:o,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),K=({value:i,onChange:c,isDisabled:o,label:t})=>l.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[l.jsx("input",{type:"checkbox",checked:!!i,onChange:s=>c(s.target.checked),disabled:o}),l.jsx("span",{children:t})]}),fe=i=>({onClick:o,fileName:t,isDisabled:s,isDownloading:u})=>{const f=i?.label||"Download",g=s||u;return l.jsxs("button",{onClick:o,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&&t&&` (${t})`]})},he=i=>({onClick:o,isValid:t,isDisabled:s,isSubmitting:u})=>{const f=i?.label||"Submit",g=!t||s||u;return l.jsxs("button",{onClick:o,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]})},X=r.forwardRef((i,c)=>{const{eventId:o,document:t,fields:s={},download:u,submit:f,onSubmit:g,onDownload:D,onStateChange:E,onFieldChange:N,onFieldsDiscovered:T,isDisabled:h=!1,className:Y,style:G,documentHeight:J="600px"}=i,[y,F]=r.useState(!t.validation?.scroll?.required),[m,I]=r.useState(new Map),[b,q]=r.useState(!1),[x,A]=r.useState(!1),[k,_]=r.useState(!1),[V,B]=r.useState([]),[U,Q]=r.useState(!1),j=r.useRef(null),M=r.useRef(null),Z=r.useRef(Date.now()),S=r.useRef(s),w=r.useRef([]),$=r.useRef(T);S.current=s,$.current=T,r.useEffect(()=>{w.current=V},[V]);const C=r.useCallback(e=>{if(!M.current?.activeEditor)return;const n=M.current.activeEditor,d=S.current.signer?.find(a=>a.id===e.id);let p;d?.type==="signature"&&e.value?p={json:{type:"image",attrs:{src:typeof e.value=="string"&&e.value.startsWith("data:image/")?e.value:W(String(e.value)),alt:"Signature"}}}:p={text:String(e.value??"")},e.id&&n.commands.updateStructuredContentById?.(e.id,p)},[]),H=r.useCallback(e=>{if(!e)return;const n=e.helpers.structuredContentCommands.getStructuredContentTags(e.state),d=new Map;S.current.document?.forEach(a=>{a.id&&d.set(a.id,a.value)}),S.current.signer?.forEach(a=>{a.value!==void 0&&d.set(a.id,a.value)});const p=n.map(({node:a})=>({id:a.attrs.id,label:a.attrs.label,value:d.get(a.attrs.id)??a.textContent??""})).filter(a=>a.id);p.length>0&&($.current?.(p),[...S.current.document||[],...S.current.signer||[]].filter(v=>v.value!==void 0).forEach(v=>C({id:v.id,value:v.value})))},[C]),R=e=>{const n={...e,timestamp:new Date().toISOString()},d=globalThis?.__SUPERDOC_AUDIT_MOCK__;d&&d(n);const p=[...w.current,n];return w.current=p,B(p),p};r.useEffect(()=>{if(!j.current)return;let e=!1,n=null;return(async()=>{const{SuperDoc:p}=await import("superdoc");e||(n=new p({selector:j.current,document:t.source,documentMode:"viewing",modules:{comments:!1},layoutMode:t.layoutMode,layoutMargins:t.layoutMargins,onReady:()=>{e||(n?.activeEditor&&H(n.activeEditor),R({type:"ready"}),Q(!0))}}),M.current=n)})(),()=>{e=!0,n&&typeof n.destroy=="function"&&n.destroy(),M.current=null}},[t.source,t.mode,t.layoutMode,t.layoutMargins?.top,t.layoutMargins?.bottom,t.layoutMargins?.left,t.layoutMargins?.right,H]),r.useEffect(()=>{if(!t.validation?.scroll?.required||!U)return;const e=j.current;if(!e)return;const n=()=>{const{scrollTop:d,scrollHeight:p,clientHeight:a}=e,v=d/(p-a);(v>=.95||p<=a)&&(F(!0),R({type:"scroll",data:{percent:Math.round(v*100)}}))};return e.addEventListener("scroll",n),n(),()=>e.removeEventListener("scroll",n)},[t.validation?.scroll?.required,U]);const ee=r.useCallback((e,n)=>{I(d=>{const p=d.get(e),a=new Map(d);return a.set(e,n),C({id:e,value:n}),R({type:"field_change",data:{fieldId:e,value:n,previousValue:p}}),N?.({id:e,value:n,previousValue:p}),a})},[N,C]),O=r.useCallback(()=>t.validation?.scroll?.required&&!y?!1:(s.signer||[]).every(e=>{if(!e.validation?.required)return!0;const n=m.get(e.id);return n&&(typeof n!="string"||n.trim())}),[y,s.signer,m,t.validation?.scroll?.required]);r.useEffect(()=>{const e=O();q(e),E?.({scrolled:y,fields:m,isValid:e,isSubmitting:x})},[y,m,x,O,E]);const te=r.useCallback(async()=>{if(h||k)return;_(!0);const e={eventId:o,documentSource:t.source,fields:{document:s.document||[],signer:(s.signer||[]).map(n=>({id:n.id,value:m.get(n.id)??null}))},fileName:u?.fileName||"document.pdf"};try{await D?.(e)}finally{_(!1)}},[h,k,o,t.source,s,m,u,D]),ne=r.useCallback(async()=>{if(!b||h||x)return;A(!0);const e=R({type:"submit"}),n={eventId:o,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-Z.current)/1e3),auditTrail:e,documentFields:s.document||[],signerFields:(s.signer||[]).map(d=>({id:d.id,value:m.get(d.id)??null})),isFullyCompleted:b};try{await g(n)}finally{A(!1)}},[b,h,x,o,s,m,g]),se=e=>{const n=e.component||oe(e.type);return l.jsx(n,{value:m.get(e.id)??null,onChange:d=>ee(e.id,d),isDisabled:h,label:e.label},e.id)},oe=e=>{switch(e){case"signature":case"text":return L;case"checkbox":return K}},re=()=>{const e=u?.component||fe(u);return e?l.jsx(e,{onClick:te,fileName:u?.fileName,isDisabled:h,isDownloading:k}):null},ae=()=>{if(t.mode==="download")return null;const e=f?.component||he(f);return l.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",children:l.jsx(e,{onClick:ne,isValid:b,isDisabled:h,isSubmitting:x})})},z=re(),ie=ae();return r.useImperativeHandle(c,()=>({getState:()=>({scrolled:y,fields:m,isValid:b,isSubmitting:x}),getAuditTrail:()=>w.current,reset:()=>{F(!t.validation?.scroll?.required),I(new Map),q(!1),w.current=[],B([])},updateFieldInDocument:C}),[y,m,b,x,t.validation?.scroll?.required,C]),l.jsxs("div",{className:`superdoc-esign-container ${Y||""}`,style:G,children:[l.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",children:[z&&l.jsx("div",{className:"superdoc-esign-document-toolbar",children:l.jsx("div",{className:"superdoc-esign-document-controls",children:z})}),l.jsx("div",{ref:j,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:J,overflow:"auto"}})]}),l.jsxs("div",{className:"superdoc-esign-controls","data-testid":"superdoc-esign-controls",children:[s.signer&&s.signer.length>0&&l.jsx("div",{className:"superdoc-esign-fields","data-testid":"superdoc-esign-fields",children:s.signer.map(se)}),ie]})]})});X.displayName="SuperDocESign";exports.CheckboxInput=K;exports.SignatureInput=L;exports.default=X;exports.textToImageDataUrl=W;