@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.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import ce, { forwardRef as ue, useState as N, useRef as Z, useCallback as P, useEffect as re, useImperativeHandle as de } from "react";
2
- var Q = { exports: {} }, L = {};
1
+ import ue, { forwardRef as de, useState as D, useRef as U, useEffect as K, useCallback as F, useImperativeHandle as fe } from "react";
2
+ var ee = { exports: {} }, q = {};
3
3
  /**
4
4
  * @license React
5
5
  * react-jsx-runtime.production.js
@@ -9,29 +9,29 @@ var Q = { exports: {} }, L = {};
9
9
  * This source code is licensed under the MIT license found in the
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
- var ne;
13
- function fe() {
14
- if (ne) return L;
15
- ne = 1;
16
- var f = Symbol.for("react.transitional.element"), g = Symbol.for("react.fragment");
17
- function m(s, o, c) {
18
- var v = null;
19
- if (c !== void 0 && (v = "" + c), o.key !== void 0 && (v = "" + o.key), "key" in o) {
20
- c = {};
21
- for (var _ in o)
22
- _ !== "key" && (c[_] = o[_]);
23
- } else c = o;
24
- return o = c.ref, {
25
- $$typeof: f,
12
+ var oe;
13
+ function me() {
14
+ if (oe) return q;
15
+ oe = 1;
16
+ var p = Symbol.for("react.transitional.element"), v = Symbol.for("react.fragment");
17
+ function m(s, o, f) {
18
+ var h = null;
19
+ if (f !== void 0 && (h = "" + f), o.key !== void 0 && (h = "" + o.key), "key" in o) {
20
+ f = {};
21
+ for (var S in o)
22
+ S !== "key" && (f[S] = o[S]);
23
+ } else f = o;
24
+ return o = f.ref, {
25
+ $$typeof: p,
26
26
  type: s,
27
- key: v,
27
+ key: h,
28
28
  ref: o !== void 0 ? o : null,
29
- props: c
29
+ props: f
30
30
  };
31
31
  }
32
- return L.Fragment = g, L.jsx = m, L.jsxs = m, L;
32
+ return q.Fragment = v, q.jsx = m, q.jsxs = m, q;
33
33
  }
34
- var U = {};
34
+ var L = {};
35
35
  /**
36
36
  * @license React
37
37
  * react-jsx-runtime.development.js
@@ -41,126 +41,126 @@ var U = {};
41
41
  * This source code is licensed under the MIT license found in the
42
42
  * LICENSE file in the root directory of this source tree.
43
43
  */
44
- var oe;
44
+ var ae;
45
45
  function pe() {
46
- return oe || (oe = 1, process.env.NODE_ENV !== "production" && (function() {
47
- function f(e) {
46
+ return ae || (ae = 1, process.env.NODE_ENV !== "production" && (function() {
47
+ function p(e) {
48
48
  if (e == null) return null;
49
49
  if (typeof e == "function")
50
- return e.$$typeof === ee ? null : e.displayName || e.name || null;
50
+ return e.$$typeof === re ? null : e.displayName || e.name || null;
51
51
  if (typeof e == "string") return e;
52
52
  switch (e) {
53
- case y:
53
+ case _:
54
54
  return "Fragment";
55
- case h:
55
+ case b:
56
56
  return "Profiler";
57
- case V:
57
+ case B:
58
58
  return "StrictMode";
59
- case S:
59
+ case T:
60
60
  return "Suspense";
61
- case J:
61
+ case G:
62
62
  return "SuspenseList";
63
- case H:
63
+ case Z:
64
64
  return "Activity";
65
65
  }
66
66
  if (typeof e == "object")
67
67
  switch (typeof e.tag == "number" && console.error(
68
68
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
69
  ), e.$$typeof) {
70
- case K:
70
+ case te:
71
71
  return "Portal";
72
- case w:
72
+ case A:
73
73
  return e.displayName || "Context";
74
- case z:
74
+ case J:
75
75
  return (e._context.displayName || "Context") + ".Consumer";
76
- case B:
76
+ case H:
77
77
  var n = e.render;
78
78
  return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case M:
80
- return n = e.displayName || null, n !== null ? n : f(e.type) || "Memo";
81
- case C:
79
+ case X:
80
+ return n = e.displayName || null, n !== null ? n : p(e.type) || "Memo";
81
+ case N:
82
82
  n = e._payload, e = e._init;
83
83
  try {
84
- return f(e(n));
84
+ return p(e(n));
85
85
  } catch {
86
86
  }
87
87
  }
88
88
  return null;
89
89
  }
90
- function g(e) {
90
+ function v(e) {
91
91
  return "" + e;
92
92
  }
93
93
  function m(e) {
94
94
  try {
95
- g(e);
95
+ v(e);
96
96
  var n = !1;
97
97
  } catch {
98
98
  n = !0;
99
99
  }
100
100
  if (n) {
101
101
  n = console;
102
- var l = n.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return l.call(
102
+ var c = n.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
+ return c.call(
104
104
  n,
105
105
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
106
  u
107
- ), g(e);
107
+ ), v(e);
108
108
  }
109
109
  }
110
110
  function s(e) {
111
- if (e === y) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === C)
111
+ if (e === _) return "<>";
112
+ if (typeof e == "object" && e !== null && e.$$typeof === N)
113
113
  return "<...>";
114
114
  try {
115
- var n = f(e);
115
+ var n = p(e);
116
116
  return n ? "<" + n + ">" : "<...>";
117
117
  } catch {
118
118
  return "<...>";
119
119
  }
120
120
  }
121
121
  function o() {
122
- var e = T.A;
122
+ var e = w.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function c() {
125
+ function f() {
126
126
  return Error("react-stack-top-frame");
127
127
  }
128
- function v(e) {
129
- if (E.call(e, "key")) {
128
+ function h(e) {
129
+ if (x.call(e, "key")) {
130
130
  var n = Object.getOwnPropertyDescriptor(e, "key").get;
131
131
  if (n && n.isReactWarning) return !1;
132
132
  }
133
133
  return e.key !== void 0;
134
134
  }
135
- function _(e, n) {
136
- function l() {
135
+ function S(e, n) {
136
+ function c() {
137
137
  k || (k = !0, console.error(
138
138
  "%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)",
139
139
  n
140
140
  ));
141
141
  }
142
- l.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: l,
142
+ c.isReactWarning = !0, Object.defineProperty(e, "key", {
143
+ get: c,
144
144
  configurable: !0
145
145
  });
146
146
  }
147
- function D() {
148
- var e = f(this.type);
149
- return G[e] || (G[e] = !0, console.error(
147
+ function W() {
148
+ var e = p(this.type);
149
+ return C[e] || (C[e] = !0, console.error(
150
150
  "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."
151
151
  )), e = this.props.ref, e !== void 0 ? e : null;
152
152
  }
153
- function q(e, n, l, u, O, $) {
154
- var t = l.ref;
153
+ function V(e, n, c, u, P, $) {
154
+ var d = c.ref;
155
155
  return e = {
156
- $$typeof: W,
156
+ $$typeof: z,
157
157
  type: e,
158
158
  key: n,
159
- props: l,
159
+ props: c,
160
160
  _owner: u
161
- }, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
161
+ }, (d !== void 0 ? d : null) !== null ? Object.defineProperty(e, "ref", {
162
162
  enumerable: !1,
163
- get: D
163
+ get: W
164
164
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
165
165
  configurable: !1,
166
166
  enumerable: !1,
@@ -175,7 +175,7 @@ function pe() {
175
175
  configurable: !1,
176
176
  enumerable: !1,
177
177
  writable: !0,
178
- value: O
178
+ value: P
179
179
  }), Object.defineProperty(e, "_debugTask", {
180
180
  configurable: !1,
181
181
  enumerable: !1,
@@ -183,25 +183,25 @@ function pe() {
183
183
  value: $
184
184
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
185
185
  }
186
- function F(e, n, l, u, O, $) {
187
- var t = n.children;
188
- if (t !== void 0)
186
+ function I(e, n, c, u, P, $) {
187
+ var d = n.children;
188
+ if (d !== void 0)
189
189
  if (u)
190
- if (te(t)) {
191
- for (u = 0; u < t.length; u++)
192
- I(t[u]);
193
- Object.freeze && Object.freeze(t);
190
+ if (ne(d)) {
191
+ for (u = 0; u < d.length; u++)
192
+ M(d[u]);
193
+ Object.freeze && Object.freeze(d);
194
194
  } else
195
195
  console.error(
196
196
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
197
197
  );
198
- else I(t);
199
- if (E.call(n, "key")) {
200
- t = f(e);
201
- var r = Object.keys(n).filter(function(d) {
202
- return d !== "key";
198
+ else M(d);
199
+ if (x.call(n, "key")) {
200
+ d = p(e);
201
+ var t = Object.keys(n).filter(function(a) {
202
+ return a !== "key";
203
203
  });
204
- u = 0 < r.length ? "{key: someKey, " + r.join(": ..., ") + ": ...}" : "{key: someKey}", X[t + u] || (r = 0 < r.length ? "{" + r.join(": ..., ") + ": ...}" : "{}", console.error(
204
+ u = 0 < t.length ? "{key: someKey, " + t.join(": ..., ") + ": ...}" : "{key: someKey}", j[d + u] || (t = 0 < t.length ? "{" + t.join(": ..., ") + ": ...}" : "{}", console.error(
205
205
  `A props object containing a "key" prop is being spread into JSX:
206
206
  let props = %s;
207
207
  <%s {...props} />
@@ -209,125 +209,132 @@ React keys must be passed directly to JSX without using spread:
209
209
  let props = %s;
210
210
  <%s key={someKey} {...props} />`,
211
211
  u,
212
+ d,
212
213
  t,
213
- r,
214
- t
215
- ), X[t + u] = !0);
214
+ d
215
+ ), j[d + u] = !0);
216
216
  }
217
- if (t = null, l !== void 0 && (m(l), t = "" + l), v(n) && (m(n.key), t = "" + n.key), "key" in n) {
218
- l = {};
219
- for (var a in n)
220
- a !== "key" && (l[a] = n[a]);
221
- } else l = n;
222
- return t && _(
223
- l,
217
+ if (d = null, c !== void 0 && (m(c), d = "" + c), h(n) && (m(n.key), d = "" + n.key), "key" in n) {
218
+ c = {};
219
+ for (var r in n)
220
+ r !== "key" && (c[r] = n[r]);
221
+ } else c = n;
222
+ return d && S(
223
+ c,
224
224
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
225
- ), q(
225
+ ), V(
226
226
  e,
227
- t,
228
- l,
227
+ d,
228
+ c,
229
229
  o(),
230
- O,
230
+ P,
231
231
  $
232
232
  );
233
233
  }
234
- function I(e) {
235
- b(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === C && (e._payload.status === "fulfilled" ? b(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
234
+ function M(e) {
235
+ E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === N && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
236
236
  }
237
- function b(e) {
238
- return typeof e == "object" && e !== null && e.$$typeof === W;
237
+ function E(e) {
238
+ return typeof e == "object" && e !== null && e.$$typeof === z;
239
239
  }
240
- var A = ce, W = Symbol.for("react.transitional.element"), K = Symbol.for("react.portal"), y = Symbol.for("react.fragment"), V = Symbol.for("react.strict_mode"), h = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), w = Symbol.for("react.context"), B = Symbol.for("react.forward_ref"), S = Symbol.for("react.suspense"), J = Symbol.for("react.suspense_list"), M = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), ee = Symbol.for("react.client.reference"), T = A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, E = Object.prototype.hasOwnProperty, te = Array.isArray, x = console.createTask ? console.createTask : function() {
240
+ var O = ue, z = Symbol.for("react.transitional.element"), te = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), B = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), J = Symbol.for("react.consumer"), A = Symbol.for("react.context"), H = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), G = Symbol.for("react.suspense_list"), X = Symbol.for("react.memo"), N = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), re = Symbol.for("react.client.reference"), w = O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, ne = Array.isArray, y = console.createTask ? console.createTask : function() {
241
241
  return null;
242
242
  };
243
- A = {
243
+ O = {
244
244
  react_stack_bottom_frame: function(e) {
245
245
  return e();
246
246
  }
247
247
  };
248
- var k, G = {}, Y = A.react_stack_bottom_frame.bind(
249
- A,
250
- c
251
- )(), j = x(s(c)), X = {};
252
- U.Fragment = y, U.jsx = function(e, n, l) {
253
- var u = 1e4 > T.recentlyCreatedOwnerStacks++;
254
- return F(
248
+ var k, C = {}, Q = O.react_stack_bottom_frame.bind(
249
+ O,
250
+ f
251
+ )(), Y = y(s(f)), j = {};
252
+ L.Fragment = _, L.jsx = function(e, n, c) {
253
+ var u = 1e4 > w.recentlyCreatedOwnerStacks++;
254
+ return I(
255
255
  e,
256
256
  n,
257
- l,
257
+ c,
258
258
  !1,
259
- u ? Error("react-stack-top-frame") : Y,
260
- u ? x(s(e)) : j
259
+ u ? Error("react-stack-top-frame") : Q,
260
+ u ? y(s(e)) : Y
261
261
  );
262
- }, U.jsxs = function(e, n, l) {
263
- var u = 1e4 > T.recentlyCreatedOwnerStacks++;
264
- return F(
262
+ }, L.jsxs = function(e, n, c) {
263
+ var u = 1e4 > w.recentlyCreatedOwnerStacks++;
264
+ return I(
265
265
  e,
266
266
  n,
267
- l,
267
+ c,
268
268
  !0,
269
- u ? Error("react-stack-top-frame") : Y,
270
- u ? x(s(e)) : j
269
+ u ? Error("react-stack-top-frame") : Q,
270
+ u ? y(s(e)) : Y
271
271
  );
272
272
  };
273
- })()), U;
273
+ })()), L;
274
274
  }
275
- var ae;
276
- function me() {
277
- return ae || (ae = 1, process.env.NODE_ENV === "production" ? Q.exports = fe() : Q.exports = pe()), Q.exports;
275
+ var se;
276
+ function ge() {
277
+ return se || (se = 1, process.env.NODE_ENV === "production" ? ee.exports = me() : ee.exports = pe()), ee.exports;
278
278
  }
279
- var p = me();
280
- const ge = ({
281
- value: f,
282
- onChange: g,
279
+ var g = ge();
280
+ const ve = ({
281
+ value: p,
282
+ onChange: v,
283
283
  isDisabled: m,
284
284
  label: s
285
- }) => /* @__PURE__ */ p.jsxs("div", { className: "superdoc-esign-signature-input", style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
286
- s && /* @__PURE__ */ p.jsx("label", { children: s }),
287
- /* @__PURE__ */ p.jsx(
288
- "input",
289
- {
290
- type: "text",
291
- value: String(f || ""),
292
- onChange: (o) => g(o.target.value),
293
- disabled: m,
294
- placeholder: "Type your full name",
295
- style: {
296
- fontFamily: "cursive",
297
- fontSize: "18px"
298
- }
299
- }
300
- )
301
- ] }), ve = ({
302
- value: f,
303
- onChange: g,
285
+ }) => /* @__PURE__ */ g.jsxs(
286
+ "div",
287
+ {
288
+ className: "superdoc-esign-signature-input",
289
+ style: { display: "flex", flexDirection: "column", gap: "8px" },
290
+ children: [
291
+ s && /* @__PURE__ */ g.jsx("label", { children: s }),
292
+ /* @__PURE__ */ g.jsx(
293
+ "input",
294
+ {
295
+ type: "text",
296
+ value: String(p || ""),
297
+ onChange: (o) => v(o.target.value),
298
+ disabled: m,
299
+ placeholder: "Type your full name",
300
+ style: {
301
+ fontFamily: "cursive",
302
+ fontSize: "18px"
303
+ }
304
+ }
305
+ )
306
+ ]
307
+ }
308
+ ), be = ({
309
+ value: p,
310
+ onChange: v,
304
311
  isDisabled: m,
305
312
  label: s
306
- }) => /* @__PURE__ */ p.jsxs(
313
+ }) => /* @__PURE__ */ g.jsxs(
307
314
  "label",
308
315
  {
309
316
  className: "superdoc-esign-checkbox-input",
310
317
  style: { display: "flex", gap: "8px" },
311
318
  children: [
312
- /* @__PURE__ */ p.jsx(
319
+ /* @__PURE__ */ g.jsx(
313
320
  "input",
314
321
  {
315
322
  type: "checkbox",
316
- checked: !!f,
317
- onChange: (o) => g(o.target.checked),
323
+ checked: !!p,
324
+ onChange: (o) => v(o.target.checked),
318
325
  disabled: m
319
326
  }
320
327
  ),
321
- /* @__PURE__ */ p.jsx("span", { children: s })
328
+ /* @__PURE__ */ g.jsx("span", { children: s })
322
329
  ]
323
330
  }
324
- ), be = (f) => ({
331
+ ), he = (p) => ({
325
332
  onClick: m,
326
333
  fileName: s,
327
334
  isDisabled: o
328
335
  }) => {
329
- const c = f?.label || "Download";
330
- return /* @__PURE__ */ p.jsxs(
336
+ const f = p?.label || "Download";
337
+ return /* @__PURE__ */ g.jsxs(
331
338
  "button",
332
339
  {
333
340
  onClick: m,
@@ -345,24 +352,24 @@ const ge = ({
345
352
  fontWeight: "bold"
346
353
  },
347
354
  children: [
348
- c,
355
+ f,
349
356
  " ",
350
357
  s && `(${s})`
351
358
  ]
352
359
  }
353
360
  );
354
- }, he = (f) => ({
361
+ }, Ee = (p) => ({
355
362
  onClick: m,
356
363
  isValid: s,
357
364
  isDisabled: o,
358
- isSubmitting: c
365
+ isSubmitting: f
359
366
  }) => {
360
- const v = () => f?.label || "Submit";
361
- return /* @__PURE__ */ p.jsx(
367
+ const h = () => p?.label || "Submit";
368
+ return /* @__PURE__ */ g.jsx(
362
369
  "button",
363
370
  {
364
371
  onClick: m,
365
- disabled: !s || o || c,
372
+ disabled: !s || o || f,
366
373
  className: "superdoc-esign-btn",
367
374
  style: {
368
375
  padding: "12px 24px",
@@ -375,279 +382,309 @@ const ge = ({
375
382
  fontSize: "16px",
376
383
  fontWeight: "bold"
377
384
  },
378
- children: v()
385
+ children: h()
379
386
  }
380
387
  );
381
- }, Ee = ue(
382
- (f, g) => {
383
- const {
384
- eventId: m,
385
- document: s,
386
- fields: o = {},
387
- download: c,
388
- submit: v,
389
- onSubmit: _,
390
- onDownload: D,
391
- onStateChange: q,
392
- onFieldChange: F,
393
- onFieldsDiscovered: I,
394
- isDisabled: b = !1,
395
- className: A,
396
- style: W,
397
- documentHeight: K = "600px"
398
- } = f, [y, V] = N(
399
- !s.validation?.scroll?.required
400
- ), [h, z] = N(/* @__PURE__ */ new Map()), [w, B] = N(!1), [S, J] = N(!1), [M, C] = N([]), [H, ee] = N(!1), T = Z(null), E = Z(null), te = Z(Date.now()), x = Z(o);
401
- x.current = o;
402
- const k = P((t) => {
403
- if (!E.current?.activeEditor) return;
404
- const r = E.current.activeEditor, a = x.current.signer?.find((i) => i.id === t.id);
405
- let d;
406
- a?.type === "signature" && t.value ? d = {
407
- json: {
408
- type: "image",
409
- attrs: { src: typeof t.value == "string" && t.value.startsWith("data:image/") ? t.value : G(String(t.value)), alt: "Signature" }
410
- }
411
- } : d = { text: String(t.value ?? "") }, t.id && r.commands.updateStructuredContentById(
412
- t.id,
413
- d
414
- );
415
- }, []);
416
- function G(t) {
417
- const r = globalThis.document.createElement("canvas"), a = r.getContext("2d"), d = 30;
418
- a.font = `italic ${d}px cursive`;
419
- const R = a.measureText(t).width, se = d * 1.3, ie = 4, le = 6;
420
- return r.width = Math.ceil(R + ie * 2) + 20, r.height = Math.ceil(se + le * 2), a.font = `italic ${d}px cursive`, a.fillStyle = "black", a.textAlign = "center", a.textBaseline = "middle", a.fillText(
421
- t,
422
- r.width / 2,
423
- r.height / 2
424
- ), r.toDataURL("image/png");
425
- }
426
- const Y = P(
427
- (t) => {
428
- if (!t) return;
429
- const r = t.helpers.structuredContentCommands.getStructuredContentTags(
430
- t.state
431
- ), a = /* @__PURE__ */ new Map();
432
- x.current.document?.forEach((i) => {
433
- i.id && a.set(i.id, i.value);
434
- }), x.current.signer?.forEach((i) => {
435
- i.value !== void 0 && a.set(i.id, i.value);
436
- });
437
- const d = r.map(({ node: i }) => ({
438
- id: i.attrs.id,
439
- label: i.attrs.label,
440
- value: a.get(i.attrs.id) ?? i.textContent ?? ""
441
- })).filter((i) => i.id);
442
- d.length > 0 && (I?.(d), [
443
- ...x.current.document || [],
444
- ...x.current.signer || []
445
- ].filter((R) => R.value !== void 0).forEach(
446
- (R) => k({
447
- id: R.id,
448
- value: R.value
449
- })
450
- ));
451
- },
452
- [I, k]
453
- ), j = (t) => {
454
- const r = {
455
- ...t,
456
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
457
- };
458
- C((a) => [...a, r]);
459
- };
460
- re(() => T.current ? ((async () => {
461
- const { SuperDoc: r } = await import("./superdoc.es-CqejOF1J.js").then((d) => d.D), a = new r({
462
- selector: T.current,
463
- document: s.source,
464
- documentMode: "viewing",
465
- onReady: () => {
466
- a.activeEditor && Y(a.activeEditor), j({ type: "ready" }), ee(!0);
467
- }
468
- });
469
- E.current = a;
470
- })(), () => {
471
- E.current && (E.current.destroy(), E.current = null);
472
- }) : void 0, [s.source, s.mode, Y]), re(() => {
473
- if (!s.validation?.scroll?.required || !H) return;
474
- const t = T.current;
388
+ }, xe = de((p, v) => {
389
+ const {
390
+ eventId: m,
391
+ document: s,
392
+ fields: o = {},
393
+ download: f,
394
+ submit: h,
395
+ onSubmit: S,
396
+ onDownload: W,
397
+ onStateChange: V,
398
+ onFieldChange: I,
399
+ onFieldsDiscovered: M,
400
+ isDisabled: E = !1,
401
+ className: O,
402
+ style: z,
403
+ documentHeight: te = "600px"
404
+ } = p, [_, B] = D(
405
+ !s.validation?.scroll?.required
406
+ ), [b, J] = D(
407
+ /* @__PURE__ */ new Map()
408
+ ), [A, H] = D(!1), [T, G] = D(!1), [X, N] = D([]), [Z, re] = D(!1), w = U(null), x = U(null), ne = U(Date.now()), y = U(o), k = U([]);
409
+ y.current = o, K(() => {
410
+ k.current = X;
411
+ }, [X]);
412
+ const C = F((t) => {
413
+ if (!x.current?.activeEditor) return;
414
+ const r = x.current.activeEditor, a = y.current.signer?.find(
415
+ (i) => i.id === t.id
416
+ );
417
+ let l;
418
+ a?.type === "signature" && t.value ? l = {
419
+ json: {
420
+ type: "image",
421
+ attrs: { src: typeof t.value == "string" && t.value.startsWith("data:image/") ? t.value : Q(String(t.value)), alt: "Signature" }
422
+ }
423
+ } : l = { text: String(t.value ?? "") }, t.id && r.commands.updateStructuredContentById(t.id, l);
424
+ }, []);
425
+ function Q(t) {
426
+ const r = globalThis.document.createElement("canvas"), a = r.getContext("2d"), l = 30;
427
+ a.font = `italic ${l}px cursive`;
428
+ const R = a.measureText(t).width, ie = l * 1.3, ce = 4, le = 6;
429
+ return r.width = Math.ceil(R + ce * 2) + 20, r.height = Math.ceil(ie + le * 2), a.font = `italic ${l}px cursive`, a.fillStyle = "black", a.textAlign = "center", a.textBaseline = "middle", a.fillText(t, r.width / 2, r.height / 2), r.toDataURL("image/png");
430
+ }
431
+ const Y = F(
432
+ (t) => {
475
433
  if (!t) return;
476
- const r = () => {
477
- const { scrollTop: a, scrollHeight: d, clientHeight: i } = t, R = a / (d - i);
478
- (R >= 0.95 || d <= i) && (V(!0), j({
479
- type: "scroll",
480
- data: { percent: Math.round(R * 100) }
481
- }));
482
- };
483
- return t.addEventListener("scroll", r), r(), () => t.removeEventListener("scroll", r);
484
- }, [s.validation?.scroll?.required, H]);
485
- const X = P(
486
- (t, r) => {
487
- z((a) => {
488
- const d = a.get(t), i = new Map(a);
489
- return i.set(t, r), k({
490
- id: t,
491
- value: r
492
- }), j({
493
- type: "field_change",
494
- data: { fieldId: t, value: r, previousValue: d }
495
- }), F?.({
496
- id: t,
497
- value: r,
498
- previousValue: d
499
- }), i;
500
- });
501
- },
502
- [F, k]
503
- ), e = P(() => s.validation?.scroll?.required && !y ? !1 : (o.signer || []).every((t) => {
504
- if (!t.validation?.required) return !0;
505
- const r = h.get(t.id);
506
- return r && (typeof r != "string" || r.trim());
507
- }), [y, o.signer, h, s.validation?.scroll?.required]);
508
- re(() => {
509
- const t = e();
510
- B(t), q?.({
511
- scrolled: y,
512
- fields: h,
513
- isValid: t,
514
- isSubmitting: S
434
+ const r = t.helpers.structuredContentCommands.getStructuredContentTags(
435
+ t.state
436
+ ), a = /* @__PURE__ */ new Map();
437
+ y.current.document?.forEach((i) => {
438
+ i.id && a.set(i.id, i.value);
439
+ }), y.current.signer?.forEach((i) => {
440
+ i.value !== void 0 && a.set(i.id, i.value);
515
441
  });
516
- }, [y, h, S, e, q]);
517
- const n = P(async () => {
518
- if (b) return;
519
- const t = await E.current?.export({
520
- exportType: ["pdf"],
521
- isFinalDoc: !0,
522
- triggerDownload: !1
523
- });
524
- if (t && D)
525
- D(t, c?.fileName || "document.pdf");
526
- else if (t) {
527
- const r = URL.createObjectURL(t), a = globalThis.document.createElement("a");
528
- a.href = r, a.download = c?.fileName || "document.pdf", a.click(), URL.revokeObjectURL(r);
442
+ const l = r.map(({ node: i }) => ({
443
+ id: i.attrs.id,
444
+ label: i.attrs.label,
445
+ value: a.get(i.attrs.id) ?? i.textContent ?? ""
446
+ })).filter((i) => i.id);
447
+ l.length > 0 && (M?.(l), [
448
+ ...y.current.document || [],
449
+ ...y.current.signer || []
450
+ ].filter((R) => R.value !== void 0).forEach(
451
+ (R) => C({
452
+ id: R.id,
453
+ value: R.value
454
+ })
455
+ ));
456
+ },
457
+ [M, C]
458
+ ), j = (t) => {
459
+ const r = {
460
+ ...t,
461
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
462
+ }, a = globalThis?.__SUPERDOC_AUDIT_MOCK__;
463
+ a && a(r);
464
+ const l = [...k.current, r];
465
+ return k.current = l, N(l), l;
466
+ };
467
+ K(() => w.current ? ((async () => {
468
+ const { SuperDoc: r } = await import("./superdoc.es-CqejOF1J.js").then((l) => l.D), a = new r({
469
+ selector: w.current,
470
+ document: s.source,
471
+ documentMode: "viewing",
472
+ onReady: () => {
473
+ a.activeEditor && Y(a.activeEditor), j({ type: "ready" }), re(!0);
529
474
  }
530
- }, [b, c, D]), l = P(async () => {
531
- if (!w || b || S) return;
532
- J(!0), j({ type: "submit" });
533
- const t = {
534
- eventId: m,
535
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
536
- duration: Math.floor((Date.now() - te.current) / 1e3),
537
- auditTrail: M,
538
- documentFields: o.document || [],
539
- signerFields: (o.signer || []).map((r) => ({
475
+ });
476
+ x.current = a;
477
+ })(), () => {
478
+ x.current && (typeof x.current.destroy == "function" && x.current.destroy(), x.current = null);
479
+ }) : void 0, [s.source, s.mode, Y]), K(() => {
480
+ if (!s.validation?.scroll?.required || !Z) return;
481
+ const t = w.current;
482
+ if (!t) return;
483
+ const r = () => {
484
+ const { scrollTop: a, scrollHeight: l, clientHeight: i } = t, R = a / (l - i);
485
+ (R >= 0.95 || l <= i) && (B(!0), j({
486
+ type: "scroll",
487
+ data: { percent: Math.round(R * 100) }
488
+ }));
489
+ };
490
+ return t.addEventListener("scroll", r), r(), () => t.removeEventListener("scroll", r);
491
+ }, [s.validation?.scroll?.required, Z]);
492
+ const e = F(
493
+ (t, r) => {
494
+ J((a) => {
495
+ const l = a.get(t), i = new Map(a);
496
+ return i.set(t, r), C({
497
+ id: t,
498
+ value: r
499
+ }), j({
500
+ type: "field_change",
501
+ data: { fieldId: t, value: r, previousValue: l }
502
+ }), I?.({
503
+ id: t,
504
+ value: r,
505
+ previousValue: l
506
+ }), i;
507
+ });
508
+ },
509
+ [I, C]
510
+ ), n = F(() => s.validation?.scroll?.required && !_ ? !1 : (o.signer || []).every((t) => {
511
+ if (!t.validation?.required) return !0;
512
+ const r = b.get(t.id);
513
+ return r && (typeof r != "string" || r.trim());
514
+ }), [
515
+ _,
516
+ o.signer,
517
+ b,
518
+ s.validation?.scroll?.required
519
+ ]);
520
+ K(() => {
521
+ const t = n();
522
+ H(t), V?.({
523
+ scrolled: _,
524
+ fields: b,
525
+ isValid: t,
526
+ isSubmitting: T
527
+ });
528
+ }, [_, b, T, n, V]);
529
+ const c = F(async () => {
530
+ if (E) return;
531
+ const t = {
532
+ eventId: m,
533
+ documentSource: s.source,
534
+ fields: {
535
+ document: o.document || [],
536
+ signer: (o.signer || []).map((r) => ({
540
537
  id: r.id,
541
- value: h.get(r.id) ?? null
542
- })),
543
- isFullyCompleted: w
544
- };
545
- try {
546
- await _(t);
547
- } finally {
548
- J(!1);
549
- }
550
- }, [
551
- w,
552
- b,
553
- S,
554
- m,
555
- M,
556
- o,
557
- h,
558
- _
559
- ]), u = (t) => {
560
- const r = t.component || O(t.type);
561
- return /* @__PURE__ */ p.jsx(
562
- r,
563
- {
564
- value: h.get(t.id) ?? null,
565
- onChange: (a) => X(t.id, a),
566
- isDisabled: b,
567
- label: t.label
568
- },
569
- t.id
570
- );
571
- }, O = (t) => {
572
- switch (t) {
573
- case "signature":
574
- case "text":
575
- return ge;
576
- case "checkbox":
577
- return ve;
578
- }
579
- }, $ = () => {
580
- const t = c?.component || be(c), r = v?.component || he(v);
581
- return /* @__PURE__ */ p.jsxs(
582
- "div",
583
- {
584
- className: "superdoc-esign-actions",
585
- style: { display: "flex", gap: "10px" },
586
- children: [
587
- s.mode !== "download" && /* @__PURE__ */ p.jsx(
588
- r,
589
- {
590
- onClick: l,
591
- isValid: w,
592
- isDisabled: b,
593
- isSubmitting: S
594
- }
595
- ),
596
- /* @__PURE__ */ p.jsx(
597
- t,
598
- {
599
- onClick: n,
600
- fileName: c?.fileName,
601
- isDisabled: b
602
- }
603
- )
604
- ]
605
- }
606
- );
538
+ value: b.get(r.id) ?? null
539
+ }))
540
+ },
541
+ fileName: f?.fileName || "document.pdf"
607
542
  };
608
- return de(g, () => ({
609
- getState: () => ({
610
- scrolled: y,
611
- fields: h,
612
- isValid: w,
613
- isSubmitting: S
614
- }),
615
- getAuditTrail: () => M,
616
- reset: () => {
617
- V(!s.validation?.scroll?.required), z(/* @__PURE__ */ new Map()), B(!1), C([]);
618
- }
619
- })), /* @__PURE__ */ p.jsxs(
543
+ await W?.(t);
544
+ }, [
545
+ E,
546
+ m,
547
+ s.source,
548
+ o,
549
+ b,
550
+ f,
551
+ W
552
+ ]), u = F(async () => {
553
+ if (!A || E || T) return;
554
+ G(!0), j({ type: "submit" });
555
+ const t = j({ type: "submit" }), r = {
556
+ eventId: m,
557
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
558
+ duration: Math.floor((Date.now() - ne.current) / 1e3),
559
+ auditTrail: t,
560
+ documentFields: o.document || [],
561
+ signerFields: (o.signer || []).map((a) => ({
562
+ id: a.id,
563
+ value: b.get(a.id) ?? null
564
+ })),
565
+ isFullyCompleted: A
566
+ };
567
+ try {
568
+ await S(r);
569
+ } finally {
570
+ G(!1);
571
+ }
572
+ }, [
573
+ A,
574
+ E,
575
+ T,
576
+ m,
577
+ o,
578
+ b,
579
+ S
580
+ ]), P = (t) => {
581
+ const r = t.component || $(t.type);
582
+ return /* @__PURE__ */ g.jsx(
583
+ r,
584
+ {
585
+ value: b.get(t.id) ?? null,
586
+ onChange: (a) => e(t.id, a),
587
+ isDisabled: E,
588
+ label: t.label
589
+ },
590
+ t.id
591
+ );
592
+ }, $ = (t) => {
593
+ switch (t) {
594
+ case "signature":
595
+ case "text":
596
+ return ve;
597
+ case "checkbox":
598
+ return be;
599
+ }
600
+ }, d = () => {
601
+ const t = f?.component || he(f), r = h?.component || Ee(h);
602
+ return /* @__PURE__ */ g.jsxs(
620
603
  "div",
621
604
  {
622
- className: `superdoc-esign-container ${A || ""}`,
623
- style: W,
605
+ className: "superdoc-esign-actions",
606
+ style: { display: "flex", gap: "10px" },
624
607
  children: [
625
- /* @__PURE__ */ p.jsx("div", { className: "superdoc-esign-document", children: /* @__PURE__ */ p.jsx(
626
- "div",
608
+ s.mode !== "download" && /* @__PURE__ */ g.jsx(
609
+ r,
627
610
  {
628
- ref: T,
629
- style: { height: K, overflow: "auto" }
611
+ onClick: u,
612
+ isValid: A,
613
+ isDisabled: E,
614
+ isSubmitting: T
630
615
  }
631
- ) }),
632
- /* @__PURE__ */ p.jsxs("div", { className: "superdoc-esign-controls", style: { marginTop: "20px" }, children: [
633
- o.signer && o.signer.length > 0 && /* @__PURE__ */ p.jsx(
634
- "div",
635
- {
636
- className: "superdoc-esign-fields",
637
- style: { marginBottom: "20px" },
638
- children: o.signer.map(u)
639
- }
640
- ),
641
- $()
642
- ] })
616
+ ),
617
+ /* @__PURE__ */ g.jsx(
618
+ t,
619
+ {
620
+ onClick: c,
621
+ fileName: f?.fileName,
622
+ isDisabled: E
623
+ }
624
+ )
643
625
  ]
644
626
  }
645
627
  );
646
- }
647
- );
648
- Ee.displayName = "SuperDocESign";
628
+ };
629
+ return fe(v, () => ({
630
+ getState: () => ({
631
+ scrolled: _,
632
+ fields: b,
633
+ isValid: A,
634
+ isSubmitting: T
635
+ }),
636
+ getAuditTrail: () => k.current,
637
+ reset: () => {
638
+ B(!s.validation?.scroll?.required), J(/* @__PURE__ */ new Map()), H(!1), k.current = [], N([]);
639
+ }
640
+ })), /* @__PURE__ */ g.jsxs(
641
+ "div",
642
+ {
643
+ className: `superdoc-esign-container ${O || ""}`,
644
+ style: z,
645
+ children: [
646
+ /* @__PURE__ */ g.jsx(
647
+ "div",
648
+ {
649
+ className: "superdoc-esign-document",
650
+ "data-testid": "superdoc-esign-document",
651
+ children: /* @__PURE__ */ g.jsx(
652
+ "div",
653
+ {
654
+ ref: w,
655
+ "data-testid": "superdoc-scroll-container",
656
+ style: { height: te, overflow: "auto" }
657
+ }
658
+ )
659
+ }
660
+ ),
661
+ /* @__PURE__ */ g.jsxs(
662
+ "div",
663
+ {
664
+ className: "superdoc-esign-controls",
665
+ style: { marginTop: "20px" },
666
+ "data-testid": "superdoc-esign-controls",
667
+ children: [
668
+ o.signer && o.signer.length > 0 && /* @__PURE__ */ g.jsx(
669
+ "div",
670
+ {
671
+ className: "superdoc-esign-fields",
672
+ style: { marginBottom: "20px" },
673
+ "data-testid": "superdoc-esign-fields",
674
+ children: o.signer.map(P)
675
+ }
676
+ ),
677
+ d()
678
+ ]
679
+ }
680
+ )
681
+ ]
682
+ }
683
+ );
684
+ });
685
+ xe.displayName = "SuperDocESign";
649
686
  export {
650
- ve as CheckboxInput,
651
- ge as SignatureInput,
652
- Ee as default
687
+ be as CheckboxInput,
688
+ ve as SignatureInput,
689
+ xe as default
653
690
  };