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