@richard.fadiora/liveness-detection 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- import oe, { useRef as se, useState as w, useEffect as Q } from "react";
1
+ import se, { useRef as q, useState as _, useEffect as H } from "react";
2
2
  import ae from "react-webcam";
3
- var G = { exports: {} }, O = {};
3
+ var X = { exports: {} }, N = {};
4
4
  /**
5
5
  * @license React
6
6
  * react-jsx-runtime.production.js
@@ -10,29 +10,29 @@ var G = { exports: {} }, O = {};
10
10
  * This source code is licensed under the MIT license found in the
11
11
  * LICENSE file in the root directory of this source tree.
12
12
  */
13
- var K;
13
+ var re;
14
14
  function ie() {
15
- if (K) return O;
16
- K = 1;
17
- var d = Symbol.for("react.transitional.element"), m = Symbol.for("react.fragment");
18
- function b(f, i, a) {
19
- var y = null;
20
- if (a !== void 0 && (y = "" + a), i.key !== void 0 && (y = "" + i.key), "key" in i) {
21
- a = {};
22
- for (var l in i)
23
- l !== "key" && (a[l] = i[l]);
24
- } else a = i;
25
- return i = a.ref, {
15
+ if (re) return N;
16
+ re = 1;
17
+ var d = Symbol.for("react.transitional.element"), p = Symbol.for("react.fragment");
18
+ function f(s, n, c) {
19
+ var v = null;
20
+ if (c !== void 0 && (v = "" + c), n.key !== void 0 && (v = "" + n.key), "key" in n) {
21
+ c = {};
22
+ for (var g in n)
23
+ g !== "key" && (c[g] = n[g]);
24
+ } else c = n;
25
+ return n = c.ref, {
26
26
  $$typeof: d,
27
- type: f,
28
- key: y,
29
- ref: i !== void 0 ? i : null,
30
- props: a
27
+ type: s,
28
+ key: v,
29
+ ref: n !== void 0 ? n : null,
30
+ props: c
31
31
  };
32
32
  }
33
- return O.Fragment = m, O.jsx = b, O.jsxs = b, O;
33
+ return N.Fragment = p, N.jsx = f, N.jsxs = f, N;
34
34
  }
35
- var P = {};
35
+ var I = {};
36
36
  /**
37
37
  * @license React
38
38
  * react-jsx-runtime.development.js
@@ -42,44 +42,44 @@ var P = {};
42
42
  * This source code is licensed under the MIT license found in the
43
43
  * LICENSE file in the root directory of this source tree.
44
44
  */
45
- var ee;
45
+ var te;
46
46
  function le() {
47
- return ee || (ee = 1, process.env.NODE_ENV !== "production" && function() {
47
+ return te || (te = 1, process.env.NODE_ENV !== "production" && function() {
48
48
  function d(e) {
49
49
  if (e == null) return null;
50
50
  if (typeof e == "function")
51
- return e.$$typeof === T ? null : e.displayName || e.name || null;
51
+ return e.$$typeof === u ? null : e.displayName || e.name || null;
52
52
  if (typeof e == "string") return e;
53
53
  switch (e) {
54
- case _:
54
+ case x:
55
55
  return "Fragment";
56
- case Y:
56
+ case S:
57
57
  return "Profiler";
58
- case A:
58
+ case w:
59
59
  return "StrictMode";
60
- case D:
60
+ case W:
61
61
  return "Suspense";
62
- case c:
62
+ case $:
63
63
  return "SuspenseList";
64
- case j:
64
+ case V:
65
65
  return "Activity";
66
66
  }
67
67
  if (typeof e == "object")
68
68
  switch (typeof e.tag == "number" && console.error(
69
69
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
70
70
  ), e.$$typeof) {
71
- case R:
71
+ case k:
72
72
  return "Portal";
73
- case $:
73
+ case M:
74
74
  return e.displayName || "Context";
75
- case C:
75
+ case Y:
76
76
  return (e._context.displayName || "Context") + ".Consumer";
77
- case F:
77
+ case P:
78
78
  var r = e.render;
79
79
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
80
- case h:
80
+ case z:
81
81
  return r = e.displayName || null, r !== null ? r : d(e.type) || "Memo";
82
- case u:
82
+ case C:
83
83
  r = e._payload, e = e._init;
84
84
  try {
85
85
  return d(e(r));
@@ -88,29 +88,29 @@ function le() {
88
88
  }
89
89
  return null;
90
90
  }
91
- function m(e) {
91
+ function p(e) {
92
92
  return "" + e;
93
93
  }
94
- function b(e) {
94
+ function f(e) {
95
95
  try {
96
- m(e);
96
+ p(e);
97
97
  var r = !1;
98
98
  } catch {
99
99
  r = !0;
100
100
  }
101
101
  if (r) {
102
102
  r = console;
103
- var n = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
- return n.call(
103
+ var o = r.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
+ return o.call(
105
105
  r,
106
106
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
107
- o
108
- ), m(e);
107
+ i
108
+ ), p(e);
109
109
  }
110
110
  }
111
- function f(e) {
112
- if (e === _) return "<>";
113
- if (typeof e == "object" && e !== null && e.$$typeof === u)
111
+ function s(e) {
112
+ if (e === x) return "<>";
113
+ if (typeof e == "object" && e !== null && e.$$typeof === C)
114
114
  return "<...>";
115
115
  try {
116
116
  var r = d(e);
@@ -119,49 +119,49 @@ function le() {
119
119
  return "<...>";
120
120
  }
121
121
  }
122
- function i() {
123
- var e = M.A;
122
+ function n() {
123
+ var e = R.A;
124
124
  return e === null ? null : e.getOwner();
125
125
  }
126
- function a() {
126
+ function c() {
127
127
  return Error("react-stack-top-frame");
128
128
  }
129
- function y(e) {
130
- if (q.call(e, "key")) {
129
+ function v(e) {
130
+ if (E.call(e, "key")) {
131
131
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
132
132
  if (r && r.isReactWarning) return !1;
133
133
  }
134
134
  return e.key !== void 0;
135
135
  }
136
- function l(e, r) {
137
- function n() {
138
- B || (B = !0, console.error(
136
+ function g(e, r) {
137
+ function o() {
138
+ y || (y = !0, console.error(
139
139
  "%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)",
140
140
  r
141
141
  ));
142
142
  }
143
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
144
- get: n,
143
+ o.isReactWarning = !0, Object.defineProperty(e, "key", {
144
+ get: o,
145
145
  configurable: !0
146
146
  });
147
147
  }
148
- function p() {
148
+ function L() {
149
149
  var e = d(this.type);
150
- return H[e] || (H[e] = !0, console.error(
150
+ return Z[e] || (Z[e] = !0, console.error(
151
151
  "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."
152
152
  )), e = this.props.ref, e !== void 0 ? e : null;
153
153
  }
154
- function L(e, r, n, o, N, W) {
155
- var s = n.ref;
154
+ function a(e, r, o, i, D, B) {
155
+ var l = o.ref;
156
156
  return e = {
157
- $$typeof: E,
157
+ $$typeof: O,
158
158
  type: e,
159
159
  key: r,
160
- props: n,
161
- _owner: o
162
- }, (s !== void 0 ? s : null) !== null ? Object.defineProperty(e, "ref", {
160
+ props: o,
161
+ _owner: i
162
+ }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
163
163
  enumerable: !1,
164
- get: p
164
+ get: L
165
165
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
166
166
  configurable: !1,
167
167
  enumerable: !1,
@@ -176,213 +176,265 @@ function le() {
176
176
  configurable: !1,
177
177
  enumerable: !1,
178
178
  writable: !0,
179
- value: N
179
+ value: D
180
180
  }), Object.defineProperty(e, "_debugTask", {
181
181
  configurable: !1,
182
182
  enumerable: !1,
183
183
  writable: !0,
184
- value: W
184
+ value: B
185
185
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
186
186
  }
187
- function x(e, r, n, o, N, W) {
188
- var s = r.children;
189
- if (s !== void 0)
190
- if (o)
191
- if (te(s)) {
192
- for (o = 0; o < s.length; o++)
193
- v(s[o]);
194
- Object.freeze && Object.freeze(s);
187
+ function m(e, r, o, i, D, B) {
188
+ var l = r.children;
189
+ if (l !== void 0)
190
+ if (i)
191
+ if (h(l)) {
192
+ for (i = 0; i < l.length; i++)
193
+ F(l[i]);
194
+ Object.freeze && Object.freeze(l);
195
195
  } else
196
196
  console.error(
197
197
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
198
198
  );
199
- else v(s);
200
- if (q.call(r, "key")) {
201
- s = d(e);
202
- var S = Object.keys(r).filter(function(ne) {
203
- return ne !== "key";
199
+ else F(l);
200
+ if (E.call(r, "key")) {
201
+ l = d(e);
202
+ var A = Object.keys(r).filter(function(oe) {
203
+ return oe !== "key";
204
204
  });
205
- o = 0 < S.length ? "{key: someKey, " + S.join(": ..., ") + ": ...}" : "{key: someKey}", Z[s + o] || (S = 0 < S.length ? "{" + S.join(": ..., ") + ": ...}" : "{}", console.error(
205
+ i = 0 < A.length ? "{key: someKey, " + A.join(": ..., ") + ": ...}" : "{key: someKey}", ee[l + i] || (A = 0 < A.length ? "{" + A.join(": ..., ") + ": ...}" : "{}", console.error(
206
206
  `A props object containing a "key" prop is being spread into JSX:
207
207
  let props = %s;
208
208
  <%s {...props} />
209
209
  React keys must be passed directly to JSX without using spread:
210
210
  let props = %s;
211
211
  <%s key={someKey} {...props} />`,
212
- o,
213
- s,
214
- S,
215
- s
216
- ), Z[s + o] = !0);
212
+ i,
213
+ l,
214
+ A,
215
+ l
216
+ ), ee[l + i] = !0);
217
217
  }
218
- if (s = null, n !== void 0 && (b(n), s = "" + n), y(r) && (b(r.key), s = "" + r.key), "key" in r) {
219
- n = {};
220
- for (var z in r)
221
- z !== "key" && (n[z] = r[z]);
222
- } else n = r;
223
- return s && l(
224
- n,
218
+ if (l = null, o !== void 0 && (f(o), l = "" + o), v(r) && (f(r.key), l = "" + r.key), "key" in r) {
219
+ o = {};
220
+ for (var G in r)
221
+ G !== "key" && (o[G] = r[G]);
222
+ } else o = r;
223
+ return l && g(
224
+ o,
225
225
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
226
- ), L(
226
+ ), a(
227
227
  e,
228
- s,
229
- n,
230
- i(),
231
- N,
232
- W
228
+ l,
229
+ o,
230
+ n(),
231
+ D,
232
+ B
233
233
  );
234
234
  }
235
- function v(e) {
236
- k(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === u && (e._payload.status === "fulfilled" ? k(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
235
+ function F(e) {
236
+ T(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === C && (e._payload.status === "fulfilled" ? T(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
237
237
  }
238
- function k(e) {
239
- return typeof e == "object" && e !== null && e.$$typeof === E;
238
+ function T(e) {
239
+ return typeof e == "object" && e !== null && e.$$typeof === O;
240
240
  }
241
- var g = oe, E = Symbol.for("react.transitional.element"), R = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), C = Symbol.for("react.consumer"), $ = Symbol.for("react.context"), F = Symbol.for("react.forward_ref"), D = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), u = Symbol.for("react.lazy"), j = Symbol.for("react.activity"), T = Symbol.for("react.client.reference"), M = g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, te = Array.isArray, U = console.createTask ? console.createTask : function() {
241
+ var b = se, O = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), w = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), Y = Symbol.for("react.consumer"), M = Symbol.for("react.context"), P = Symbol.for("react.forward_ref"), W = Symbol.for("react.suspense"), $ = Symbol.for("react.suspense_list"), z = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), V = Symbol.for("react.activity"), u = Symbol.for("react.client.reference"), R = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, E = Object.prototype.hasOwnProperty, h = Array.isArray, j = console.createTask ? console.createTask : function() {
242
242
  return null;
243
243
  };
244
- g = {
244
+ b = {
245
245
  react_stack_bottom_frame: function(e) {
246
246
  return e();
247
247
  }
248
248
  };
249
- var B, H = {}, J = g.react_stack_bottom_frame.bind(
250
- g,
251
- a
252
- )(), X = U(f(a)), Z = {};
253
- P.Fragment = _, P.jsx = function(e, r, n) {
254
- var o = 1e4 > M.recentlyCreatedOwnerStacks++;
255
- return x(
249
+ var y, Z = {}, Q = b.react_stack_bottom_frame.bind(
250
+ b,
251
+ c
252
+ )(), K = j(s(c)), ee = {};
253
+ I.Fragment = x, I.jsx = function(e, r, o) {
254
+ var i = 1e4 > R.recentlyCreatedOwnerStacks++;
255
+ return m(
256
256
  e,
257
257
  r,
258
- n,
258
+ o,
259
259
  !1,
260
- o ? Error("react-stack-top-frame") : J,
261
- o ? U(f(e)) : X
260
+ i ? Error("react-stack-top-frame") : Q,
261
+ i ? j(s(e)) : K
262
262
  );
263
- }, P.jsxs = function(e, r, n) {
264
- var o = 1e4 > M.recentlyCreatedOwnerStacks++;
265
- return x(
263
+ }, I.jsxs = function(e, r, o) {
264
+ var i = 1e4 > R.recentlyCreatedOwnerStacks++;
265
+ return m(
266
266
  e,
267
267
  r,
268
- n,
268
+ o,
269
269
  !0,
270
- o ? Error("react-stack-top-frame") : J,
271
- o ? U(f(e)) : X
270
+ i ? Error("react-stack-top-frame") : Q,
271
+ i ? j(s(e)) : K
272
272
  );
273
273
  };
274
- }()), P;
274
+ }()), I;
275
275
  }
276
- process.env.NODE_ENV === "production" ? G.exports = ie() : G.exports = le();
277
- var t = G.exports;
278
- const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], re = 60, pe = ({ apiUrl: d, onComplete: m }) => {
279
- const b = se(null), [f, i] = w([]), [a, y] = w(0), [l, p] = w("idle"), [L, x] = w(3), [v, k] = w(re), [g, E] = w(!1), [R, _] = w(!1), A = () => {
280
- const c = [...ce].sort(() => 0.5 - Math.random()).slice(0, 3);
281
- i(c), y(0), p("idle"), x(3), k(re), E(!1), _(!1);
276
+ process.env.NODE_ENV === "production" ? X.exports = ie() : X.exports = le();
277
+ var t = X.exports;
278
+ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], ne = 60, ue = (d) => {
279
+ if (!d) return null;
280
+ const p = d.split(","), f = p[0].match(/:(.*?);/)[1], s = atob(p[1]);
281
+ let n = s.length;
282
+ const c = new Uint8Array(n);
283
+ for (; n--; ) c[n] = s.charCodeAt(n);
284
+ return new Blob([c], { type: f });
285
+ }, ye = ({ apiUrl: d, onComplete: p }) => {
286
+ const f = q(null), s = q(null), n = q(null), [c, v] = _([]), [g, L] = _(0), [a, m] = _("idle"), [F, T] = _(3), [b, O] = _(ne), [k, x] = _(!1), [w, S] = _(!1), [Y, M] = _(null), P = () => {
287
+ const u = [...ce].sort(() => 0.5 - Math.random()).slice(0, 3);
288
+ v(u), L(0), m("idle"), T(3), O(ne), x(!1), S(!1);
282
289
  };
283
- Q(() => {
284
- A();
290
+ H(() => {
291
+ P();
285
292
  }, []);
286
- const Y = () => {
287
- A();
293
+ const W = () => {
294
+ P();
288
295
  };
289
- Q(() => {
290
- let c;
291
- return g && v > 0 ? c = setInterval(() => {
292
- k((h) => h - 1);
293
- }, 1e3) : v === 0 && l !== "success" && (p("timeout"), E(!1), _(!1), m && m(!1)), () => clearInterval(c);
294
- }, [g, v, l]);
295
- const C = async () => {
296
- g || E(!0), p("counting");
297
- let c = 3;
298
- const h = setInterval(() => {
299
- c -= 1, x(c), c === 0 && (clearInterval(h), $());
296
+ H(() => () => {
297
+ n.current && clearInterval(n.current), s.current && s.current.abort();
298
+ }, []), H(() => {
299
+ let u;
300
+ return k && b > 0 ? u = setInterval(() => {
301
+ O((R) => R - 1);
302
+ }, 1e3) : b === 0 && a !== "success" && (n.current && (clearInterval(n.current), n.current = null), s.current && s.current.abort(), m("timeout"), x(!1), S(!1), p && p(!1)), () => clearInterval(u);
303
+ }, [k, b, a]);
304
+ const $ = async () => {
305
+ if (a === "capturing" || a === "verifying") return;
306
+ n.current && clearInterval(n.current), k || x(!0), m("counting");
307
+ let u = 3;
308
+ n.current = setInterval(() => {
309
+ u -= 1, T(u), u === 0 && (clearInterval(n.current), n.current = null, z());
300
310
  }, 1e3);
301
- }, $ = async () => {
302
- p("capturing");
303
- const c = [], h = 20;
304
- for (let u = 0; u < h; u++) {
305
- if (v <= 0) return;
306
- const j = b.current.getScreenshot();
307
- c.push(j), await new Promise((T) => setTimeout(T, 100));
308
- }
309
- F(c);
310
- }, F = async (c) => {
311
- p("verifying");
312
- const h = new FormData();
313
- for (let u = 0; u < c.length; u++) {
314
- const j = await fetch(c[u]).then((T) => T.blob());
315
- h.append("files", j, `frame_${u}.jpg`);
311
+ }, z = async () => {
312
+ if (!f.current)
313
+ return;
314
+ m("capturing");
315
+ const u = [], R = 20;
316
+ for (let E = 0; E < R; E++) {
317
+ if (!f.current || b <= 0) return;
318
+ try {
319
+ const h = f.current.getScreenshot();
320
+ h && u.push(h);
321
+ } catch {
322
+ break;
323
+ }
324
+ await new Promise((h) => setTimeout(h, 100));
316
325
  }
317
- h.append("challenge", f[a]);
326
+ u.length > 0 && a !== "timeout" && C(u);
327
+ }, C = async (u) => {
328
+ if (a === "verifying" || a === "timeout") return;
329
+ m("verifying"), s.current = new AbortController();
330
+ const { signal: R } = s.current, E = new FormData();
331
+ u.forEach((h, j) => {
332
+ const y = ue(h);
333
+ y && E.append("files", y, `frame_${j}.jpg`);
334
+ }), E.append("challenge", c[g]);
318
335
  try {
319
- (await (await fetch(`${d}/v1/verify`, {
336
+ const h = await fetch(`${d}/v1/verify`, {
320
337
  method: "POST",
321
- body: h
322
- })).json()).is_live ? a < 2 ? (y((T) => T + 1), x(3), p("idle")) : (p("success"), E(!1), m && m(!0)) : (E(!1), _(!0), p("idle"), x(3));
323
- } catch (u) {
324
- console.error("API Error:", u), _(!0), p("idle");
338
+ body: E,
339
+ signal: R
340
+ });
341
+ u = [];
342
+ const j = await h.json();
343
+ if (a === "timeout") return;
344
+ if (j.is_live)
345
+ if (g < 2)
346
+ L((y) => y + 1), T(3), m("idle");
347
+ else {
348
+ const y = f.current.getScreenshot();
349
+ y && M(y), m("success"), x(!1), p && p({
350
+ success: !0,
351
+ image: y
352
+ // This is the base64 string
353
+ });
354
+ }
355
+ else
356
+ x(!1), S(!0), m("idle"), T(3);
357
+ } catch {
358
+ S(!0), m("idle");
359
+ } finally {
360
+ s.current = null;
325
361
  }
326
- }, D = {
362
+ }, V = {
327
363
  Smile: "Show us a big SMILE! 😁",
328
364
  Blink: "BLINK your eyes rapidly! 👁️",
329
- Turn_Head: "Slowly TURN your head left and right! ↔️",
365
+ Turn_Head: "Slowly TURN your head left or right! ↔️",
330
366
  Thumbs_Up: "Give a THUMBS UP! 👍"
331
367
  };
332
368
  return /* @__PURE__ */ t.jsxs("div", { style: { textAlign: "center", padding: "20px", fontFamily: "sans-serif" }, children: [
333
- g && l !== "success" && /* @__PURE__ */ t.jsxs("div", { style: { fontSize: "20px", fontWeight: "bold", color: v < 10 ? "red" : "black" }, children: [
369
+ k && a !== "success" && /* @__PURE__ */ t.jsxs("div", { style: { fontSize: "20px", fontWeight: "bold", color: b < 10 ? "red" : "black" }, children: [
334
370
  "Time Remaining: ",
335
- v,
371
+ b,
336
372
  "s"
337
373
  ] }),
338
- R && /* @__PURE__ */ t.jsx("div", { style: ue, children: /* @__PURE__ */ t.jsxs("div", { style: fe, children: [
374
+ w && /* @__PURE__ */ t.jsx("div", { style: fe, children: /* @__PURE__ */ t.jsxs("div", { style: de, children: [
339
375
  /* @__PURE__ */ t.jsx("h3", { style: { color: "#dc3545" }, children: "Action Not Detected" }),
340
376
  /* @__PURE__ */ t.jsx("p", { children: "We couldn't verify that move. Please try again before time runs out!" }),
341
377
  /* @__PURE__ */ t.jsx("button", { onClick: () => {
342
- _(!1), C();
343
- }, style: I, children: "Try Again" })
378
+ S(!1), $();
379
+ }, style: U, children: "Try Again" })
344
380
  ] }) }),
345
- l === "success" && /* @__PURE__ */ t.jsxs("div", { children: [
381
+ a === "success" && /* @__PURE__ */ t.jsxs("div", { children: [
346
382
  /* @__PURE__ */ t.jsx("h2", { children: "✅ Verification Passed!" }),
347
- /* @__PURE__ */ t.jsx("button", { onClick: Y, style: { ...I, backgroundColor: "#6c757d" }, children: "Verify Again" })
383
+ Y && /* @__PURE__ */ t.jsxs("div", { style: { margin: "20px auto", width: "200px" }, children: [
384
+ /* @__PURE__ */ t.jsx("p", { children: "Verified Photo:" }),
385
+ /* @__PURE__ */ t.jsx(
386
+ "img",
387
+ {
388
+ src: Y,
389
+ alt: "Verified",
390
+ style: { width: "100%", borderRadius: "10px", border: "3px solid #28a745" }
391
+ }
392
+ )
393
+ ] }),
394
+ /* @__PURE__ */ t.jsx("button", { onClick: W, style: { ...U, backgroundColor: "#6c757d" }, children: "Verify Again" })
348
395
  ] }),
349
- l === "timeout" && /* @__PURE__ */ t.jsxs("div", { children: [
396
+ a === "timeout" && /* @__PURE__ */ t.jsxs("div", { children: [
350
397
  /* @__PURE__ */ t.jsx("h2", { style: { color: "#dc3545" }, children: "⏰ Session Expired" }),
351
398
  /* @__PURE__ */ t.jsx("p", { children: "You didn't complete the challenges in time." }),
352
- /* @__PURE__ */ t.jsx("p", { children: "Please ensure you follow the instructions and perform the tasks within the time limit. (60 secsonds)" }),
353
- /* @__PURE__ */ t.jsx("button", { onClick: A, style: I, children: "🔄 Try Again" })
399
+ /* @__PURE__ */ t.jsx("p", { children: "Please ensure you follow the instructions and perform the tasks within the time limit. (60 seconds)" }),
400
+ /* @__PURE__ */ t.jsx("button", { onClick: P, style: U, children: "🔄 Try Again" })
354
401
  ] }),
355
- ["idle", "counting", "capturing", "verifying"].includes(l) && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
402
+ ["idle", "counting", "capturing", "verifying"].includes(a) && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
356
403
  /* @__PURE__ */ t.jsx("h2", { children: "Please be in a well-lit room where your face can be well seen." }),
357
404
  /* @__PURE__ */ t.jsxs("h3", { children: [
358
405
  "Challenge ",
359
- a + 1,
406
+ g + 1,
360
407
  " of 3"
361
408
  ] }),
362
- /* @__PURE__ */ t.jsx("h2", { style: { color: "#007bff" }, children: D[f[a]] }),
363
- /* @__PURE__ */ t.jsxs("div", { style: { position: "relative", width: "fit-content", margin: "auto" }, children: [
409
+ /* @__PURE__ */ t.jsx("h2", { style: { color: "#007bff" }, children: V[c[g]] }),
410
+ /* @__PURE__ */ t.jsxs("div", { style: { position: "relative", width: "fit-content", margin: "auto", overflow: "hidden", borderRadius: "10px" }, children: [
364
411
  /* @__PURE__ */ t.jsx(
365
412
  ae,
366
413
  {
367
414
  audio: !1,
368
- ref: b,
415
+ ref: f,
369
416
  screenshotFormat: "image/jpeg",
370
417
  style: { borderRadius: "10px", width: "100%", maxWidth: "400px", transform: "scaleX(-1)" }
371
418
  }
372
419
  ),
373
- l === "counting" && /* @__PURE__ */ t.jsx("div", { style: V, children: L }),
374
- l === "verifying" && /* @__PURE__ */ t.jsx("div", { style: V, children: "Analyzing..." }),
375
- l === "capturing" && /* @__PURE__ */ t.jsx("div", { style: { ...V, background: "rgba(40, 167, 69, 0.3)" }, children: "Recording..." })
420
+ /* @__PURE__ */ t.jsx("div", { style: {
421
+ ...pe,
422
+ borderColor: a === "capturing" ? "#28a745" : "rgba(255, 255, 255, 0.6)",
423
+ borderStyle: a === "capturing" ? "solid" : "dashed"
424
+ }, children: /* @__PURE__ */ t.jsx("div", { style: me }) }),
425
+ a === "counting" && /* @__PURE__ */ t.jsx("div", { style: J, children: F }),
426
+ a === "verifying" && /* @__PURE__ */ t.jsx("div", { style: J, children: "Analyzing..." }),
427
+ a === "capturing" && /* @__PURE__ */ t.jsx("div", { style: { ...J, background: "rgba(40, 167, 69, 0.3)" }, children: "Recording..." })
376
428
  ] }),
377
- /* @__PURE__ */ t.jsx("div", { style: { marginTop: "20px" }, children: l === "idle" && /* @__PURE__ */ t.jsx("button", { onClick: C, disabled: R, style: {
378
- ...I,
379
- filter: R ? "grayscale(1)" : "none",
380
- cursor: R ? "not-allowed" : "pointer",
381
- opacity: R ? 0.6 : 1
429
+ /* @__PURE__ */ t.jsx("div", { style: { marginTop: "20px" }, children: a === "idle" && /* @__PURE__ */ t.jsx("button", { onClick: $, disabled: w, style: {
430
+ ...U,
431
+ filter: w ? "grayscale(1)" : "none",
432
+ cursor: w ? "not-allowed" : "pointer",
433
+ opacity: w ? 0.6 : 1
382
434
  }, children: "I'm Ready" }) })
383
435
  ] })
384
436
  ] });
385
- }, V = {
437
+ }, J = {
386
438
  position: "absolute",
387
439
  top: 0,
388
440
  left: 0,
@@ -395,7 +447,7 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], re = 60, pe = ({ apiUrl
395
447
  justifyContent: "center",
396
448
  fontSize: "48px",
397
449
  borderRadius: "10px"
398
- }, I = {
450
+ }, U = {
399
451
  padding: "10px 30px",
400
452
  fontSize: "18px",
401
453
  cursor: "pointer",
@@ -403,7 +455,7 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], re = 60, pe = ({ apiUrl
403
455
  color: "white",
404
456
  border: "none",
405
457
  borderRadius: "5px"
406
- }, ue = {
458
+ }, fe = {
407
459
  position: "absolute",
408
460
  top: 0,
409
461
  left: 0,
@@ -415,26 +467,50 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], re = 60, pe = ({ apiUrl
415
467
  justifyContent: "center",
416
468
  zIndex: 100,
417
469
  borderRadius: "10px"
418
- }, fe = {
470
+ }, de = {
419
471
  backgroundColor: "white",
420
472
  padding: "30px",
421
473
  borderRadius: "15px",
422
474
  maxWidth: "300px",
423
475
  boxShadow: "0 4px 15px rgba(0,0,0,0.3)",
424
476
  color: "#000"
425
- }, he = async (d, m, b) => {
426
- const f = new FormData();
427
- m.forEach((a, y) => {
428
- f.append("files", a, `frame_${y}.jpg`);
429
- }), f.append("challenge", b);
430
- const i = await fetch(`${d}/v1/verify`, {
477
+ }, pe = {
478
+ position: "absolute",
479
+ top: "50%",
480
+ left: "50%",
481
+ transform: "translate(-50%, -50%)",
482
+ width: "260px",
483
+ // Adjust width based on your model's preference
484
+ height: "240px",
485
+ // Adjust height
486
+ borderRadius: "50%",
487
+ border: "2px dashed rgba(255, 255, 255, 0.6)",
488
+ boxShadow: "0 0 0 9999px rgba(0, 0, 0, 0.5)",
489
+ // This creates the dark "vignette"
490
+ pointerEvents: "none",
491
+ // Critical: clicks pass through to the webcam/buttons
492
+ zIndex: 10
493
+ }, me = {
494
+ position: "absolute",
495
+ top: 0,
496
+ left: 0,
497
+ right: 0,
498
+ bottom: 0,
499
+ borderRadius: "50%",
500
+ boxShadow: "inset 0 0 30px rgba(255, 255, 255, 0.2)"
501
+ }, ge = async (d, p, f) => {
502
+ const s = new FormData();
503
+ p.forEach((c, v) => {
504
+ s.append("files", c, `frame_${v}.jpg`);
505
+ }), s.append("challenge", f);
506
+ const n = await fetch(`${d}/v1/verify`, {
431
507
  method: "POST",
432
- body: f
508
+ body: s
433
509
  });
434
- if (!i.ok) throw new Error("Network response was not ok");
435
- return await i.json();
510
+ if (!n.ok) throw new Error("Network response was not ok");
511
+ return await n.json();
436
512
  };
437
513
  export {
438
- pe as LivenessSDK,
439
- he as verifyLiveness
514
+ ye as LivenessSDK,
515
+ ge as verifyLiveness
440
516
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(g,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("react-webcam")):typeof define=="function"&&define.amd?define(["exports","react","react-webcam"],u):(g=typeof globalThis<"u"?globalThis:g||self,u(g.LivenessSDK={},g.React,g.Webcam))})(this,function(g,u,re){"use strict";var D={exports:{}},O={};/**
1
+ (function(x,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react-webcam")):typeof define=="function"&&define.amd?define(["exports","react","react-webcam"],i):(x=typeof globalThis<"u"?globalThis:x||self,i(x.LivenessSDK={},x.React,x.Webcam))})(this,function(x,i,ne){"use strict";var z={exports:{}},P={};/**
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 J;function ne(){if(J)return O;J=1;var m=Symbol.for("react.transitional.element"),p=Symbol.for("react.fragment");function y(d,i,a){var v=null;if(a!==void 0&&(v=""+a),i.key!==void 0&&(v=""+i.key),"key"in i){a={};for(var l in i)l!=="key"&&(a[l]=i[l])}else a=i;return i=a.ref,{$$typeof:m,type:d,key:v,ref:i!==void 0?i:null,props:a}}return O.Fragment=p,O.jsx=y,O.jsxs=y,O}var P={};/**
9
+ */var Z;function oe(){if(Z)return P;Z=1;var p=Symbol.for("react.transitional.element"),m=Symbol.for("react.fragment");function d(s,n,u){var R=null;if(u!==void 0&&(R=""+u),n.key!==void 0&&(R=""+n.key),"key"in n){u={};for(var g in n)g!=="key"&&(u[g]=n[g])}else u=n;return n=u.ref,{$$typeof:p,type:s,key:R,ref:n!==void 0?n:null,props:u}}return P.Fragment=m,P.jsx=d,P.jsxs=d,P}var C={};/**
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 X;function oe(){return X||(X=1,process.env.NODE_ENV!=="production"&&function(){function m(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===w?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case x:return"Fragment";case M:return"Profiler";case C:return"StrictMode";case z:return"Suspense";case c: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 S:return"Portal";case U:return e.displayName||"Context";case I:return(e._context.displayName||"Context")+".Consumer";case W:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case b:return t=e.displayName||null,t!==null?t:m(e.type)||"Memo";case f:t=e._payload,e=e._init;try{return m(e(t))}catch{}}return null}function p(e){return""+e}function y(e){try{p(e);var t=!1}catch{t=!0}if(t){t=console;var n=t.error,o=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),p(e)}}function d(e){if(e===x)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===f)return"<...>";try{var t=m(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function i(){var e=V.A;return e===null?null:e.getOwner()}function a(){return Error("react-stack-top-frame")}function v(e){if(Z.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function l(e,t){function n(){Q||(Q=!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)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function h(){var e=m(this.type);return q[e]||(q[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 F(e,t,n,o,L,B){var s=n.ref;return e={$$typeof:T,type:e,key:t,props:n,_owner:o},(s!==void 0?s:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:h}):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:L}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function R(e,t,n,o,L,B){var s=t.children;if(s!==void 0)if(o)if(ue(s)){for(o=0;o<s.length;o++)E(s[o]);Object.freeze&&Object.freeze(s)}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 E(s);if(Z.call(t,"key")){s=m(e);var k=Object.keys(t).filter(function(fe){return fe!=="key"});o=0<k.length?"{key: someKey, "+k.join(": ..., ")+": ...}":"{key: someKey}",te[s+o]||(k=0<k.length?"{"+k.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var Q;function se(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&function(){function p(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===f?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case E:return"Fragment";case j:return"Profiler";case w:return"StrictMode";case G:return"Suspense";case U: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 A:return"Portal";case B:return e.displayName||"Context";case M:return(e._context.displayName||"Context")+".Consumer";case I:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case H:return t=e.displayName||null,t!==null?t:p(e.type)||"Memo";case L:t=e._payload,e=e._init;try{return p(e(t))}catch{}}return null}function m(e){return""+e}function d(e){try{m(e);var t=!1}catch{t=!0}if(t){t=console;var o=t.error,l=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",l),m(e)}}function s(e){if(e===E)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===L)return"<...>";try{var t=p(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function n(){var e=S.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function R(e){if(_.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function g(e,t){function o(){v||(v=!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)",t))}o.isReactWarning=!0,Object.defineProperty(e,"key",{get:o,configurable:!0})}function F(){var e=p(this.type);return $[e]||($[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 a(e,t,o,l,W,X){var c=o.ref;return e={$$typeof:N,type:e,key:t,props:o,_owner:l},(c!==void 0?c:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:F}):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:W}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function h(e,t,o,l,W,X){var c=t.children;if(c!==void 0)if(l)if(b(c)){for(l=0;l<c.length;l++)Y(c[l]);Object.freeze&&Object.freeze(c)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Y(c);if(_.call(t,"key")){c=p(e);var O=Object.keys(t).filter(function(me){return me!=="key"});l=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",re[c+l]||(O=0<O.length?"{"+O.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} />`,o,s,k,s),te[s+o]=!0)}if(s=null,n!==void 0&&(y(n),s=""+n),v(t)&&(y(t.key),s=""+t.key),"key"in t){n={};for(var H in t)H!=="key"&&(n[H]=t[H])}else n=t;return s&&l(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),F(e,s,n,i(),L,B)}function E(e){A(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===f&&(e._payload.status==="fulfilled"?A(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function A(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}var _=u,T=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),U=Symbol.for("react.context"),W=Symbol.for("react.forward_ref"),z=Symbol.for("react.suspense"),c=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),j=Symbol.for("react.activity"),w=Symbol.for("react.client.reference"),V=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=Object.prototype.hasOwnProperty,ue=Array.isArray,G=console.createTask?console.createTask:function(){return null};_={react_stack_bottom_frame:function(e){return e()}};var Q,q={},$=_.react_stack_bottom_frame.bind(_,a)(),ee=G(d(a)),te={};P.Fragment=x,P.jsx=function(e,t,n){var o=1e4>V.recentlyCreatedOwnerStacks++;return R(e,t,n,!1,o?Error("react-stack-top-frame"):$,o?G(d(e)):ee)},P.jsxs=function(e,t,n){var o=1e4>V.recentlyCreatedOwnerStacks++;return R(e,t,n,!0,o?Error("react-stack-top-frame"):$,o?G(d(e)):ee)}}()),P}process.env.NODE_ENV==="production"?D.exports=ne():D.exports=oe();var r=D.exports;const se=["Smile","Blink","Turn_Head","Thumbs_Up"],K=60,ae=({apiUrl:m,onComplete:p})=>{const y=u.useRef(null),[d,i]=u.useState([]),[a,v]=u.useState(0),[l,h]=u.useState("idle"),[F,R]=u.useState(3),[E,A]=u.useState(K),[_,T]=u.useState(!1),[S,x]=u.useState(!1),C=()=>{const c=[...se].sort(()=>.5-Math.random()).slice(0,3);i(c),v(0),h("idle"),R(3),A(K),T(!1),x(!1)};u.useEffect(()=>{C()},[]);const M=()=>{C()};u.useEffect(()=>{let c;return _&&E>0?c=setInterval(()=>{A(b=>b-1)},1e3):E===0&&l!=="success"&&(h("timeout"),T(!1),x(!1),p&&p(!1)),()=>clearInterval(c)},[_,E,l]);const I=async()=>{_||T(!0),h("counting");let c=3;const b=setInterval(()=>{c-=1,R(c),c===0&&(clearInterval(b),U())},1e3)},U=async()=>{h("capturing");const c=[],b=20;for(let f=0;f<b;f++){if(E<=0)return;const j=y.current.getScreenshot();c.push(j),await new Promise(w=>setTimeout(w,100))}W(c)},W=async c=>{h("verifying");const b=new FormData;for(let f=0;f<c.length;f++){const j=await fetch(c[f]).then(w=>w.blob());b.append("files",j,`frame_${f}.jpg`)}b.append("challenge",d[a]);try{(await(await fetch(`${m}/v1/verify`,{method:"POST",body:b})).json()).is_live?a<2?(v(w=>w+1),R(3),h("idle")):(h("success"),T(!1),p&&p(!0)):(T(!1),x(!0),h("idle"),R(3))}catch(f){console.error("API Error:",f),x(!0),h("idle")}},z={Smile:"Show us a big SMILE! 😁",Blink:"BLINK your eyes rapidly! 👁️",Turn_Head:"Slowly TURN your head left and right! ↔️",Thumbs_Up:"Give a THUMBS UP! 👍"};return r.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[_&&l!=="success"&&r.jsxs("div",{style:{fontSize:"20px",fontWeight:"bold",color:E<10?"red":"black"},children:["Time Remaining: ",E,"s"]}),S&&r.jsx("div",{style:ie,children:r.jsxs("div",{style:le,children:[r.jsx("h3",{style:{color:"#dc3545"},children:"Action Not Detected"}),r.jsx("p",{children:"We couldn't verify that move. Please try again before time runs out!"}),r.jsx("button",{onClick:()=>{x(!1),I()},style:N,children:"Try Again"})]})}),l==="success"&&r.jsxs("div",{children:[r.jsx("h2",{children:"✅ Verification Passed!"}),r.jsx("button",{onClick:M,style:{...N,backgroundColor:"#6c757d"},children:"Verify Again"})]}),l==="timeout"&&r.jsxs("div",{children:[r.jsx("h2",{style:{color:"#dc3545"},children:"⏰ Session Expired"}),r.jsx("p",{children:"You didn't complete the challenges in time."}),r.jsx("p",{children:"Please ensure you follow the instructions and perform the tasks within the time limit. (60 secsonds)"}),r.jsx("button",{onClick:C,style:N,children:"🔄 Try Again"})]}),["idle","counting","capturing","verifying"].includes(l)&&r.jsxs(r.Fragment,{children:[r.jsx("h2",{children:"Please be in a well-lit room where your face can be well seen."}),r.jsxs("h3",{children:["Challenge ",a+1," of 3"]}),r.jsx("h2",{style:{color:"#007bff"},children:z[d[a]]}),r.jsxs("div",{style:{position:"relative",width:"fit-content",margin:"auto"},children:[r.jsx(re,{audio:!1,ref:y,screenshotFormat:"image/jpeg",style:{borderRadius:"10px",width:"100%",maxWidth:"400px",transform:"scaleX(-1)"}}),l==="counting"&&r.jsx("div",{style:Y,children:F}),l==="verifying"&&r.jsx("div",{style:Y,children:"Analyzing..."}),l==="capturing"&&r.jsx("div",{style:{...Y,background:"rgba(40, 167, 69, 0.3)"},children:"Recording..."})]}),r.jsx("div",{style:{marginTop:"20px"},children:l==="idle"&&r.jsx("button",{onClick:I,disabled:S,style:{...N,filter:S?"grayscale(1)":"none",cursor:S?"not-allowed":"pointer",opacity:S?.6:1},children:"I'm Ready"})})]})]})},Y={position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",borderRadius:"10px"},N={padding:"10px 30px",fontSize:"18px",cursor:"pointer",backgroundColor:"#28a745",color:"white",border:"none",borderRadius:"5px"},ie={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:100,borderRadius:"10px"},le={backgroundColor:"white",padding:"30px",borderRadius:"15px",maxWidth:"300px",boxShadow:"0 4px 15px rgba(0,0,0,0.3)",color:"#000"},ce=async(m,p,y)=>{const d=new FormData;p.forEach((a,v)=>{d.append("files",a,`frame_${v}.jpg`)}),d.append("challenge",y);const i=await fetch(`${m}/v1/verify`,{method:"POST",body:d});if(!i.ok)throw new Error("Network response was not ok");return await i.json()};g.LivenessSDK=ae,g.verifyLiveness=ce,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
22
+ <%s key={someKey} {...props} />`,l,c,O,c),re[c+l]=!0)}if(c=null,o!==void 0&&(d(o),c=""+o),R(t)&&(d(t.key),c=""+t.key),"key"in t){o={};for(var K in t)K!=="key"&&(o[K]=t[K])}else o=t;return c&&g(o,typeof e=="function"?e.displayName||e.name||"Unknown":e),a(e,c,o,n(),W,X)}function Y(e){T(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===L&&(e._payload.status==="fulfilled"?T(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function T(e){return typeof e=="object"&&e!==null&&e.$$typeof===N}var y=i,N=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),w=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),B=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),G=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),J=Symbol.for("react.activity"),f=Symbol.for("react.client.reference"),S=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,_=Object.prototype.hasOwnProperty,b=Array.isArray,k=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(e){return e()}};var v,$={},ee=y.react_stack_bottom_frame.bind(y,u)(),te=k(s(u)),re={};C.Fragment=E,C.jsx=function(e,t,o){var l=1e4>S.recentlyCreatedOwnerStacks++;return h(e,t,o,!1,l?Error("react-stack-top-frame"):ee,l?k(s(e)):te)},C.jsxs=function(e,t,o){var l=1e4>S.recentlyCreatedOwnerStacks++;return h(e,t,o,!0,l?Error("react-stack-top-frame"):ee,l?k(s(e)):te)}}()),C}process.env.NODE_ENV==="production"?z.exports=oe():z.exports=se();var r=z.exports;const ae=["Smile","Blink","Turn_Head","Thumbs_Up"],q=60,ie=p=>{if(!p)return null;const m=p.split(","),d=m[0].match(/:(.*?);/)[1],s=atob(m[1]);let n=s.length;const u=new Uint8Array(n);for(;n--;)u[n]=s.charCodeAt(n);return new Blob([u],{type:d})},le=({apiUrl:p,onComplete:m})=>{const d=i.useRef(null),s=i.useRef(null),n=i.useRef(null),[u,R]=i.useState([]),[g,F]=i.useState(0),[a,h]=i.useState("idle"),[Y,T]=i.useState(3),[y,N]=i.useState(q),[A,E]=i.useState(!1),[w,j]=i.useState(!1),[M,B]=i.useState(null),I=()=>{const f=[...ae].sort(()=>.5-Math.random()).slice(0,3);R(f),F(0),h("idle"),T(3),N(q),E(!1),j(!1)};i.useEffect(()=>{I()},[]);const G=()=>{I()};i.useEffect(()=>()=>{n.current&&clearInterval(n.current),s.current&&s.current.abort()},[]),i.useEffect(()=>{let f;return A&&y>0?f=setInterval(()=>{N(S=>S-1)},1e3):y===0&&a!=="success"&&(n.current&&(clearInterval(n.current),n.current=null),s.current&&s.current.abort(),h("timeout"),E(!1),j(!1),m&&m(!1)),()=>clearInterval(f)},[A,y,a]);const U=async()=>{if(a==="capturing"||a==="verifying")return;n.current&&clearInterval(n.current),A||E(!0),h("counting");let f=3;n.current=setInterval(()=>{f-=1,T(f),f===0&&(clearInterval(n.current),n.current=null,H())},1e3)},H=async()=>{if(!d.current)return;h("capturing");const f=[],S=20;for(let _=0;_<S;_++){if(!d.current||y<=0)return;try{const b=d.current.getScreenshot();b&&f.push(b)}catch{break}await new Promise(b=>setTimeout(b,100))}f.length>0&&a!=="timeout"&&L(f)},L=async f=>{if(a==="verifying"||a==="timeout")return;h("verifying"),s.current=new AbortController;const{signal:S}=s.current,_=new FormData;f.forEach((b,k)=>{const v=ie(b);v&&_.append("files",v,`frame_${k}.jpg`)}),_.append("challenge",u[g]);try{const b=await fetch(`${p}/v1/verify`,{method:"POST",body:_,signal:S});f=[];const k=await b.json();if(a==="timeout")return;if(k.is_live)if(g<2)F(v=>v+1),T(3),h("idle");else{const v=d.current.getScreenshot();v&&B(v),h("success"),E(!1),m&&m({success:!0,image:v})}else E(!1),j(!0),h("idle"),T(3)}catch{j(!0),h("idle")}finally{s.current=null}},J={Smile:"Show us a big SMILE! 😁",Blink:"BLINK your eyes rapidly! 👁️",Turn_Head:"Slowly TURN your head left or right! ↔️",Thumbs_Up:"Give a THUMBS UP! 👍"};return r.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[A&&a!=="success"&&r.jsxs("div",{style:{fontSize:"20px",fontWeight:"bold",color:y<10?"red":"black"},children:["Time Remaining: ",y,"s"]}),w&&r.jsx("div",{style:ce,children:r.jsxs("div",{style:ue,children:[r.jsx("h3",{style:{color:"#dc3545"},children:"Action Not Detected"}),r.jsx("p",{children:"We couldn't verify that move. Please try again before time runs out!"}),r.jsx("button",{onClick:()=>{j(!1),U()},style:D,children:"Try Again"})]})}),a==="success"&&r.jsxs("div",{children:[r.jsx("h2",{children:"✅ Verification Passed!"}),M&&r.jsxs("div",{style:{margin:"20px auto",width:"200px"},children:[r.jsx("p",{children:"Verified Photo:"}),r.jsx("img",{src:M,alt:"Verified",style:{width:"100%",borderRadius:"10px",border:"3px solid #28a745"}})]}),r.jsx("button",{onClick:G,style:{...D,backgroundColor:"#6c757d"},children:"Verify Again"})]}),a==="timeout"&&r.jsxs("div",{children:[r.jsx("h2",{style:{color:"#dc3545"},children:"⏰ Session Expired"}),r.jsx("p",{children:"You didn't complete the challenges in time."}),r.jsx("p",{children:"Please ensure you follow the instructions and perform the tasks within the time limit. (60 seconds)"}),r.jsx("button",{onClick:I,style:D,children:"🔄 Try Again"})]}),["idle","counting","capturing","verifying"].includes(a)&&r.jsxs(r.Fragment,{children:[r.jsx("h2",{children:"Please be in a well-lit room where your face can be well seen."}),r.jsxs("h3",{children:["Challenge ",g+1," of 3"]}),r.jsx("h2",{style:{color:"#007bff"},children:J[u[g]]}),r.jsxs("div",{style:{position:"relative",width:"fit-content",margin:"auto",overflow:"hidden",borderRadius:"10px"},children:[r.jsx(ne,{audio:!1,ref:d,screenshotFormat:"image/jpeg",style:{borderRadius:"10px",width:"100%",maxWidth:"400px",transform:"scaleX(-1)"}}),r.jsx("div",{style:{...fe,borderColor:a==="capturing"?"#28a745":"rgba(255, 255, 255, 0.6)",borderStyle:a==="capturing"?"solid":"dashed"},children:r.jsx("div",{style:de})}),a==="counting"&&r.jsx("div",{style:V,children:Y}),a==="verifying"&&r.jsx("div",{style:V,children:"Analyzing..."}),a==="capturing"&&r.jsx("div",{style:{...V,background:"rgba(40, 167, 69, 0.3)"},children:"Recording..."})]}),r.jsx("div",{style:{marginTop:"20px"},children:a==="idle"&&r.jsx("button",{onClick:U,disabled:w,style:{...D,filter:w?"grayscale(1)":"none",cursor:w?"not-allowed":"pointer",opacity:w?.6:1},children:"I'm Ready"})})]})]})},V={position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",borderRadius:"10px"},D={padding:"10px 30px",fontSize:"18px",cursor:"pointer",backgroundColor:"#28a745",color:"white",border:"none",borderRadius:"5px"},ce={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:100,borderRadius:"10px"},ue={backgroundColor:"white",padding:"30px",borderRadius:"15px",maxWidth:"300px",boxShadow:"0 4px 15px rgba(0,0,0,0.3)",color:"#000"},fe={position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"260px",height:"240px",borderRadius:"50%",border:"2px dashed rgba(255, 255, 255, 0.6)",boxShadow:"0 0 0 9999px rgba(0, 0, 0, 0.5)",pointerEvents:"none",zIndex:10},de={position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:"50%",boxShadow:"inset 0 0 30px rgba(255, 255, 255, 0.2)"},pe=async(p,m,d)=>{const s=new FormData;m.forEach((u,R)=>{s.append("files",u,`frame_${R}.jpg`)}),s.append("challenge",d);const n=await fetch(`${p}/v1/verify`,{method:"POST",body:s});if(!n.ok)throw new Error("Network response was not ok");return await n.json()};x.LivenessSDK=le,x.verifyLiveness=pe,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@richard.fadiora/liveness-detection",
3
3
  "private": false,
4
- "version": "1.0.4",
4
+ "version": "2.0.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -25,6 +25,7 @@
25
25
  "react-webcam": "^7.2.0"
26
26
  },
27
27
  "dependencies": {
28
+ "@mediapipe/tasks-vision": "^0.10.32",
28
29
  "react-webcam": "^7.2.0"
29
30
  },
30
31
  "devDependencies": {