@superdoc-dev/esign 1.1.2 → 1.2.0-next.2

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