@superdoc-dev/esign 1.2.0 → 1.3.0

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SuperDocESign.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuperDocESign.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/SuperDocESign.test.tsx"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"SignatureInput.d.ts","sourceRoot":"","sources":["../../src/defaults/SignatureInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAsBxD,CAAC"}
1
+ {"version":3,"file":"SignatureInput.d.ts","sourceRoot":"","sources":["../../src/defaults/SignatureInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAyBxD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,6 @@ import { SignatureInput, CheckboxInput } from './defaults';
2
2
  import type * as Types from "./types";
3
3
  export * from './types';
4
4
  export { SignatureInput, CheckboxInput };
5
- declare const SuperDocESign: import('react').ForwardRefExoticComponent<Types.SuperDocESignProps & import('react').RefAttributes<any>>;
5
+ declare const SuperDocESign: import('react').ForwardRefExoticComponent<Types.SuperDocESignProps & import('react').RefAttributes<Types.SuperDocESignHandle>>;
6
6
  export default SuperDocESign;
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -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,0GAyalB,CAAC;AAIF,eAAe,aAAa,CAAC"}
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,gIAyelB,CAAC;AAIF,eAAe,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("react");var X={exports:{}},Y={};/**
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react");var K={exports:{}},U={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ee;function ce(){if(ee)return Y;ee=1;var p=Symbol.for("react.transitional.element"),v=Symbol.for("react.fragment");function m(o,a,d){var h=null;if(d!==void 0&&(h=""+d),a.key!==void 0&&(h=""+a.key),"key"in a){d={};for(var _ in a)_!=="key"&&(d[_]=a[_])}else d=a;return a=d.ref,{$$typeof:p,type:o,key:h,ref:a!==void 0?a:null,props:d}}return Y.Fragment=v,Y.jsx=m,Y.jsxs=m,Y}var $={};/**
9
+ */var oe;function pe(){if(oe)return U;oe=1;var v=Symbol.for("react.transitional.element"),b=Symbol.for("react.fragment");function g(a,n,p){var h=null;if(p!==void 0&&(h=""+p),n.key!==void 0&&(h=""+n.key),"key"in n){p={};for(var T in n)T!=="key"&&(p[T]=n[T])}else p=n;return n=p.ref,{$$typeof:v,type:a,key:h,ref:n!==void 0?n:null,props:p}}return U.Fragment=b,U.jsx=g,U.jsxs=g,U}var L={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,9 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var te;function ue(){return te||(te=1,process.env.NODE_ENV!=="production"&&(function(){function p(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case b:return"Profiler";case U:return"StrictMode";case T:return"Suspense";case B:return"SuspenseList";case J: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 Z:return"Portal";case k:return e.displayName||"Context";case V:return(e._context.displayName||"Context")+".Consumer";case z:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case F:return n=e.displayName||null,n!==null?n:p(e.type)||"Memo";case O:n=e._payload,e=e._init;try{return p(e(n))}catch{}}return null}function v(e){return""+e}function m(e){try{v(e);var n=!1}catch{n=!0}if(n){n=console;var i=n.error,u=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",u),v(e)}}function o(e){if(e===y)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===O)return"<...>";try{var n=p(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function a(){var e=w.A;return e===null?null:e.getOwner()}function d(){return Error("react-stack-top-frame")}function h(e){if(S.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function _(e,n){function i(){j||(j=!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))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function q(){var e=p(this.type);return H[e]||(H[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 L(e,n,i,u,N,M){var t=i.ref;return e={$$typeof:W,type:e,key:n,props:i,_owner:u},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:q}):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:N}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function P(e,n,i,u,N,M){var t=n.children;if(t!==void 0)if(u)if(K(t)){for(u=0;u<t.length;u++)D(t[u]);Object.freeze&&Object.freeze(t)}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 D(t);if(S.call(n,"key")){t=p(e);var r=Object.keys(n).filter(function(f){return f!=="key"});u=0<r.length?"{key: someKey, "+r.join(": ..., ")+": ...}":"{key: someKey}",G[t+u]||(r=0<r.length?"{"+r.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var ae;function me(){return ae||(ae=1,process.env.NODE_ENV!=="production"&&(function(){function v(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 R: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 r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case X:return r=e.displayName||null,r!==null?r:v(e.type)||"Memo";case D:r=e._payload,e=e._init;try{return v(e(r))}catch{}}return null}function b(e){return""+e}function g(e){try{b(e);var r=!1}catch{r=!0}if(r){r=console;var c=r.error,d=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",d),b(e)}}function a(e){if(e===R)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===D)return"<...>";try{var r=v(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function n(){var e=k.A;return e===null?null:e.getOwner()}function p(){return Error("react-stack-top-frame")}function h(e){if(y.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function T(e,r){function c(){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)",r))}c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}function W(){var e=v(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,r,c,d,F,q){var f=c.ref;return e={$$typeof:z,type:e,key:r,props:c,_owner:d},(f!==void 0?f: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,r,c,d,F,q){var f=r.children;if(f!==void 0)if(d)if(re(f)){for(d=0;d<f.length;d++)Y(f[d]);Object.freeze&&Object.freeze(f)}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(f);if(y.call(r,"key")){f=v(e);var A=Object.keys(r).filter(function(ne){return ne!=="key"});d=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",j[f+d]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,u,t,r,t),G[t+u]=!0)}if(t=null,i!==void 0&&(m(i),t=""+i),h(n)&&(m(n.key),t=""+n.key),"key"in n){i={};for(var s in n)s!=="key"&&(i[s]=n[s])}else i=n;return t&&_(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),L(e,t,i,a(),N,M)}function D(e){E(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===O&&(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===W}var A=c,W=Symbol.for("react.transitional.element"),Z=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),U=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),V=Symbol.for("react.consumer"),k=Symbol.for("react.context"),z=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),F=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),J=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),w=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,S=Object.prototype.hasOwnProperty,K=Array.isArray,x=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var j,H={},I=A.react_stack_bottom_frame.bind(A,d)(),C=x(o(d)),G={};$.Fragment=y,$.jsx=function(e,n,i){var u=1e4>w.recentlyCreatedOwnerStacks++;return P(e,n,i,!1,u?Error("react-stack-top-frame"):I,u?x(o(e)):C)},$.jsxs=function(e,n,i){var u=1e4>w.recentlyCreatedOwnerStacks++;return P(e,n,i,!0,u?Error("react-stack-top-frame"):I,u?x(o(e)):C)}})()),$}var re;function de(){return re||(re=1,process.env.NODE_ENV==="production"?X.exports=ce():X.exports=ue()),X.exports}var g=de();const ne=({value:p,onChange:v,isDisabled:m,label:o})=>g.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[o&&g.jsx("label",{children:o}),g.jsx("input",{type:"text",value:String(p||""),onChange:a=>v(a.target.value),disabled:m,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),ae=({value:p,onChange:v,isDisabled:m,label:o})=>g.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[g.jsx("input",{type:"checkbox",checked:!!p,onChange:a=>v(a.target.checked),disabled:m}),g.jsx("span",{children:o})]}),fe=p=>({onClick:m,fileName:o,isDisabled:a})=>{const d=p?.label||"Download";return g.jsxs("button",{onClick:m,disabled:a,className:"superdoc-esign-btn",style:{padding:"10px 20px",borderRadius:"6px",border:"none",background:"#fff",color:"#333",cursor:a?"not-allowed":"pointer",opacity:a?.5:1,fontSize:"16px",fontWeight:"bold"},children:[d," ",o&&`(${o})`]})},me=p=>({onClick:m,isValid:o,isDisabled:a,isSubmitting:d})=>{const h=()=>p?.label||"Submit";return g.jsx("button",{onClick:m,disabled:!o||a||d,className:"superdoc-esign-btn",style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:!o||a?"not-allowed":"pointer",opacity:!o||a?.5:1,fontSize:"16px",fontWeight:"bold"},children:h()})},oe=c.forwardRef((p,v)=>{const{eventId:m,document:o,fields:a={},download:d,submit:h,onSubmit:_,onDownload:q,onStateChange:L,onFieldChange:P,onFieldsDiscovered:D,isDisabled:E=!1,className:A,style:W,documentHeight:Z="600px"}=p,[y,U]=c.useState(!o.validation?.scroll?.required),[b,V]=c.useState(new Map),[k,z]=c.useState(!1),[T,B]=c.useState(!1),[F,O]=c.useState([]),[J,Q]=c.useState(!1),w=c.useRef(null),S=c.useRef(null),K=c.useRef(Date.now()),x=c.useRef(a);x.current=a;const j=c.useCallback(t=>{if(!S.current?.activeEditor)return;const r=S.current.activeEditor,s=x.current.signer?.find(l=>l.id===t.id);let f;s?.type==="signature"&&t.value?f={json:{type:"image",attrs:{src:typeof t.value=="string"&&t.value.startsWith("data:image/")?t.value:H(String(t.value)),alt:"Signature"}}}:f={text:String(t.value??"")},t.id&&r.commands.updateStructuredContentById(t.id,f)},[]);function H(t){const r=globalThis.document.createElement("canvas"),s=r.getContext("2d"),f=30;s.font=`italic ${f}px cursive`;const R=s.measureText(t).width,se=f*1.3,le=4,ie=6;return r.width=Math.ceil(R+le*2)+20,r.height=Math.ceil(se+ie*2),s.font=`italic ${f}px cursive`,s.fillStyle="black",s.textAlign="center",s.textBaseline="middle",s.fillText(t,r.width/2,r.height/2),r.toDataURL("image/png")}const I=c.useCallback(t=>{if(!t)return;const r=t.helpers.structuredContentCommands.getStructuredContentTags(t.state),s=new Map;x.current.document?.forEach(l=>{l.id&&s.set(l.id,l.value)}),x.current.signer?.forEach(l=>{l.value!==void 0&&s.set(l.id,l.value)});const f=r.map(({node:l})=>({id:l.attrs.id,label:l.attrs.label,value:s.get(l.attrs.id)??l.textContent??""})).filter(l=>l.id);f.length>0&&(D?.(f),[...x.current.document||[],...x.current.signer||[]].filter(R=>R.value!==void 0).forEach(R=>j({id:R.id,value:R.value})))},[D,j]),C=t=>{const r={...t,timestamp:new Date().toISOString()};O(s=>[...s,r])};c.useEffect(()=>w.current?((async()=>{const{SuperDoc:r}=await Promise.resolve().then(()=>require("./superdoc.es-DfpwGgyj.cjs")).then(f=>f.superdoc_es),s=new r({selector:w.current,document:o.source,documentMode:"viewing",onReady:()=>{s.activeEditor&&I(s.activeEditor),C({type:"ready"}),Q(!0)}});S.current=s})(),()=>{S.current&&(S.current.destroy(),S.current=null)}):void 0,[o.source,o.mode,I]),c.useEffect(()=>{if(!o.validation?.scroll?.required||!J)return;const t=w.current;if(!t)return;const r=()=>{const{scrollTop:s,scrollHeight:f,clientHeight:l}=t,R=s/(f-l);(R>=.95||f<=l)&&(U(!0),C({type:"scroll",data:{percent:Math.round(R*100)}}))};return t.addEventListener("scroll",r),r(),()=>t.removeEventListener("scroll",r)},[o.validation?.scroll?.required,J]);const G=c.useCallback((t,r)=>{V(s=>{const f=s.get(t),l=new Map(s);return l.set(t,r),j({id:t,value:r}),C({type:"field_change",data:{fieldId:t,value:r,previousValue:f}}),P?.({id:t,value:r,previousValue:f}),l})},[P,j]),e=c.useCallback(()=>o.validation?.scroll?.required&&!y?!1:(a.signer||[]).every(t=>{if(!t.validation?.required)return!0;const r=b.get(t.id);return r&&(typeof r!="string"||r.trim())}),[y,a.signer,b,o.validation?.scroll?.required]);c.useEffect(()=>{const t=e();z(t),L?.({scrolled:y,fields:b,isValid:t,isSubmitting:T})},[y,b,T,e,L]);const n=c.useCallback(async()=>{if(E)return;const t={eventId:m,documentSource:o.source,fields:{document:a.document||[],signer:(a.signer||[]).map(r=>({id:r.id,value:b.get(r.id)??null}))},fileName:d?.fileName||"document.pdf"};await q?.(t)},[E,m,o.source,a,b,d,q]),i=c.useCallback(async()=>{if(!k||E||T)return;B(!0),C({type:"submit"});const t={eventId:m,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-K.current)/1e3),auditTrail:F,documentFields:a.document||[],signerFields:(a.signer||[]).map(r=>({id:r.id,value:b.get(r.id)??null})),isFullyCompleted:k};try{await _(t)}finally{B(!1)}},[k,E,T,m,F,a,b,_]),u=t=>{const r=t.component||N(t.type);return g.jsx(r,{value:b.get(t.id)??null,onChange:s=>G(t.id,s),isDisabled:E,label:t.label},t.id)},N=t=>{switch(t){case"signature":case"text":return ne;case"checkbox":return ae}},M=()=>{const t=d?.component||fe(d),r=h?.component||me(h);return g.jsxs("div",{className:"superdoc-esign-actions",style:{display:"flex",gap:"10px"},children:[o.mode!=="download"&&g.jsx(r,{onClick:i,isValid:k,isDisabled:E,isSubmitting:T}),g.jsx(t,{onClick:n,fileName:d?.fileName,isDisabled:E})]})};return c.useImperativeHandle(v,()=>({getState:()=>({scrolled:y,fields:b,isValid:k,isSubmitting:T}),getAuditTrail:()=>F,reset:()=>{U(!o.validation?.scroll?.required),V(new Map),z(!1),O([])}})),g.jsxs("div",{className:`superdoc-esign-container ${A||""}`,style:W,children:[g.jsx("div",{className:"superdoc-esign-document",children:g.jsx("div",{ref:w,style:{height:Z,overflow:"auto"}})}),g.jsxs("div",{className:"superdoc-esign-controls",style:{marginTop:"20px"},children:[a.signer&&a.signer.length>0&&g.jsx("div",{className:"superdoc-esign-fields",style:{marginBottom:"20px"},children:a.signer.map(u)}),M()]})]})});oe.displayName="SuperDocESign";exports.CheckboxInput=ae;exports.SignatureInput=ne;exports.default=oe;
22
+ <%s key={someKey} {...props} />`,d,f,A,f),j[f+d]=!0)}if(f=null,c!==void 0&&(g(c),f=""+c),h(r)&&(g(r.key),f=""+r.key),"key"in r){c={};for(var I in r)I!=="key"&&(c[I]=r[I])}else c=r;return f&&T(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),V(e,f,c,n(),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=l,z=Symbol.for("react.transitional.element"),ee=Symbol.for("react.portal"),R=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,_=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,p)(),$=_(a(p)),j={};L.Fragment=R,L.jsx=function(e,r,c){var d=1e4>k.recentlyCreatedOwnerStacks++;return M(e,r,c,!1,d?Error("react-stack-top-frame"):Q,d?_(a(e)):$)},L.jsxs=function(e,r,c){var d=1e4>k.recentlyCreatedOwnerStacks++;return M(e,r,c,!0,d?Error("react-stack-top-frame"):Q,d?_(a(e)):$)}})()),L}var se;function ge(){return se||(se=1,process.env.NODE_ENV==="production"?K.exports=pe():K.exports=me()),K.exports}var m=ge();const ie=({value:v,onChange:b,isDisabled:g,label:a})=>m.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[a&&m.jsx("label",{children:a}),m.jsx("input",{type:"text",value:String(v||""),onChange:n=>b(n.target.value),disabled:g,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),ce=({value:v,onChange:b,isDisabled:g,label:a})=>m.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[m.jsx("input",{type:"checkbox",checked:!!v,onChange:n=>b(n.target.checked),disabled:g}),m.jsx("span",{children:a})]}),ve=v=>({onClick:g,fileName:a,isDisabled:n})=>{const p=v?.label||"Download";return m.jsxs("button",{onClick:g,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:[p," ",a&&`(${a})`]})},be=v=>({onClick:g,isValid:a,isDisabled:n,isSubmitting:p})=>{const h=()=>v?.label||"Submit";return m.jsx("button",{onClick:g,disabled:!a||n||p,className:"superdoc-esign-btn superdoc-esign-btn--submit",style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:!a||n?"not-allowed":"pointer",opacity:!a||n?.5:1,fontSize:"16px",fontWeight:"bold"},children:h()})},le=l.forwardRef((v,b)=>{const{eventId:g,document:a,fields:n={},download:p,submit:h,onSubmit:T,onDownload:W,onStateChange:V,onFieldChange:M,onFieldsDiscovered:Y,isDisabled:E=!1,className:P,style:z,documentHeight:ee="600px"}=v,[R,B]=l.useState(!a.validation?.scroll?.required),[x,J]=l.useState(new Map),[O,H]=l.useState(!1),[w,G]=l.useState(!1),[X,D]=l.useState([]),[Z,te]=l.useState(!1),k=l.useRef(null),y=l.useRef(null),re=l.useRef(Date.now()),_=l.useRef(n),C=l.useRef([]);_.current=n,l.useEffect(()=>{C.current=X},[X]);const N=l.useCallback(t=>{if(!y.current?.activeEditor)return;const o=y.current.activeEditor,s=_.current.signer?.find(i=>i.id===t.id);let u;s?.type==="signature"&&t.value?u={json:{type:"image",attrs:{src:typeof t.value=="string"&&t.value.startsWith("data:image/")?t.value:Q(String(t.value)),alt:"Signature"}}}:u={text:String(t.value??"")},t.id&&o.commands.updateStructuredContentById(t.id,u)},[]);function Q(t){const o=globalThis.document.createElement("canvas"),s=o.getContext("2d"),u=30;s.font=`italic ${u}px cursive`;const S=s.measureText(t).width,ue=u*1.3,de=4,fe=6;return o.width=Math.ceil(S+de*2)+20,o.height=Math.ceil(ue+fe*2),s.font=`italic ${u}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 $=l.useCallback(t=>{if(!t)return;const o=t.helpers.structuredContentCommands.getStructuredContentTags(t.state),s=new Map;_.current.document?.forEach(i=>{i.id&&s.set(i.id,i.value)}),_.current.signer?.forEach(i=>{i.value!==void 0&&s.set(i.id,i.value)});const u=o.map(({node:i})=>({id:i.attrs.id,label:i.attrs.label,value:s.get(i.attrs.id)??i.textContent??""})).filter(i=>i.id);u.length>0&&(Y?.(u),[..._.current.document||[],..._.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 u=[...C.current,o];return C.current=u,D(u),u};l.useEffect(()=>k.current?((async()=>{const{SuperDoc:o}=await Promise.resolve().then(()=>require("./superdoc.es-DfpwGgyj.cjs")).then(u=>u.superdoc_es),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,$]),l.useEffect(()=>{if(!a.validation?.scroll?.required||!Z)return;const t=k.current;if(!t)return;const o=()=>{const{scrollTop:s,scrollHeight:u,clientHeight:i}=t,S=s/(u-i);(S>=.95||u<=i)&&(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=l.useCallback((t,o)=>{J(s=>{const u=s.get(t),i=new Map(s);return i.set(t,o),N({id:t,value:o}),j({type:"field_change",data:{fieldId:t,value:o,previousValue:u}}),M?.({id:t,value:o,previousValue:u}),i})},[M,N]),r=l.useCallback(()=>a.validation?.scroll?.required&&!R?!1:(n.signer||[]).every(t=>{if(!t.validation?.required)return!0;const o=x.get(t.id);return o&&(typeof o!="string"||o.trim())}),[R,n.signer,x,a.validation?.scroll?.required]);l.useEffect(()=>{const t=r();H(t),V?.({scrolled:R,fields:x,isValid:t,isSubmitting:w})},[R,x,w,r,V]);const c=l.useCallback(async()=>{if(E)return;const t={eventId:g,documentSource:a.source,fields:{document:n.document||[],signer:(n.signer||[]).map(o=>({id:o.id,value:x.get(o.id)??null}))},fileName:p?.fileName||"document.pdf"};await W?.(t)},[E,g,a.source,n,x,p,W]),d=l.useCallback(async()=>{if(!O||E||w)return;G(!0),j({type:"submit"});const t=j({type:"submit"}),o={eventId:g,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-re.current)/1e3),auditTrail:t,documentFields:n.document||[],signerFields:(n.signer||[]).map(s=>({id:s.id,value:x.get(s.id)??null})),isFullyCompleted:O};try{await T(o)}finally{G(!1)}},[O,E,w,g,n,x,T]),F=t=>{const o=t.component||q(t.type);return m.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 ie;case"checkbox":return ce}},f=()=>{const t=p?.component||ve(p);return t?m.jsx(t,{onClick:c,fileName:p?.fileName,isDisabled:E}):null},A=()=>{if(a.mode==="download")return null;const t=h?.component||be(h);return m.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",style:{display:"flex",gap:"10px"},children:m.jsx(t,{onClick:d,isValid:O,isDisabled:E,isSubmitting:w})})},I=f(),ne=A();return l.useImperativeHandle(b,()=>({getState:()=>({scrolled:R,fields:x,isValid:O,isSubmitting:w}),getAuditTrail:()=>C.current,reset:()=>{B(!a.validation?.scroll?.required),J(new Map),H(!1),C.current=[],D([])}})),m.jsxs("div",{className:`superdoc-esign-container ${P||""}`,style:z,children:[m.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",style:{display:"flex",flexDirection:"column"},children:[I&&m.jsx("div",{className:"superdoc-esign-document-toolbar",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"8px 12px"},children:m.jsx("div",{className:"superdoc-esign-document-controls",style:{display:"flex",gap:"8px"},children:I})}),m.jsx("div",{ref:k,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:ee,overflow:"auto"}})]}),m.jsxs("div",{className:"superdoc-esign-controls",style:{marginTop:"20px"},"data-testid":"superdoc-esign-controls",children:[n.signer&&n.signer.length>0&&m.jsx("div",{className:"superdoc-esign-fields",style:{marginBottom:"20px"},"data-testid":"superdoc-esign-fields",children:n.signer.map(F)}),ne]})]})});le.displayName="SuperDocESign";exports.CheckboxInput=ce;exports.SignatureInput=ie;exports.default=le;