@richard.fadiora/liveness-detection 1.0.2 → 1.0.3

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 X } from "react";
1
+ import oe, { useRef as se, useState as w, useEffect as Q } from "react";
2
2
  import ae from "react-webcam";
3
- var z = { exports: {} }, P = {};
3
+ var B = { exports: {} }, A = {};
4
4
  /**
5
5
  * @license React
6
6
  * react-jsx-runtime.production.js
@@ -10,29 +10,29 @@ var z = { exports: {} }, P = {};
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 Z;
14
- function ie() {
15
- if (Z) return P;
16
- Z = 1;
13
+ var K;
14
+ function le() {
15
+ if (K) return A;
16
+ K = 1;
17
17
  var d = Symbol.for("react.transitional.element"), m = Symbol.for("react.fragment");
18
- function b(u, i, a) {
18
+ function b(f, l, a) {
19
19
  var v = null;
20
- if (a !== void 0 && (v = "" + a), i.key !== void 0 && (v = "" + i.key), "key" in i) {
20
+ if (a !== void 0 && (v = "" + a), l.key !== void 0 && (v = "" + l.key), "key" in l) {
21
21
  a = {};
22
- for (var l in i)
23
- l !== "key" && (a[l] = i[l]);
24
- } else a = i;
25
- return i = a.ref, {
22
+ for (var i in l)
23
+ i !== "key" && (a[i] = l[i]);
24
+ } else a = l;
25
+ return l = a.ref, {
26
26
  $$typeof: d,
27
- type: u,
27
+ type: f,
28
28
  key: v,
29
- ref: i !== void 0 ? i : null,
29
+ ref: l !== void 0 ? l : null,
30
30
  props: a
31
31
  };
32
32
  }
33
- return P.Fragment = m, P.jsx = b, P.jsxs = b, P;
33
+ return A.Fragment = m, A.jsx = b, A.jsxs = b, A;
34
34
  }
35
- var A = {};
35
+ var O = {};
36
36
  /**
37
37
  * @license React
38
38
  * react-jsx-runtime.development.js
@@ -42,44 +42,44 @@ var A = {};
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 Q;
46
- function le() {
47
- return Q || (Q = 1, process.env.NODE_ENV !== "production" && function() {
45
+ var ee;
46
+ function ie() {
47
+ return ee || (ee = 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 === re ? null : e.displayName || e.name || null;
51
+ return e.$$typeof === T ? null : e.displayName || e.name || null;
52
52
  if (typeof e == "string") return e;
53
53
  switch (e) {
54
- case k:
54
+ case g:
55
55
  return "Fragment";
56
- case I:
56
+ case D:
57
57
  return "Profiler";
58
- case N:
58
+ case k:
59
59
  return "StrictMode";
60
- case h:
60
+ case F:
61
61
  return "Suspense";
62
- case f:
62
+ case c:
63
63
  return "SuspenseList";
64
- case ee:
64
+ case x:
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 S:
71
+ case L:
72
72
  return "Portal";
73
73
  case Y:
74
74
  return e.displayName || "Context";
75
- case L:
75
+ case P:
76
76
  return (e._context.displayName || "Context") + ".Consumer";
77
- case c:
77
+ case $:
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 y:
80
+ case h:
81
81
  return r = e.displayName || null, r !== null ? r : d(e.type) || "Memo";
82
- case E:
82
+ case u:
83
83
  r = e._payload, e = e._init;
84
84
  try {
85
85
  return d(e(r));
@@ -100,17 +100,17 @@ function le() {
100
100
  }
101
101
  if (r) {
102
102
  r = console;
103
- var t = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
- return t.call(
103
+ var n = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
+ return n.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
107
  o
108
108
  ), m(e);
109
109
  }
110
110
  }
111
- function u(e) {
112
- if (e === k) return "<>";
113
- if (typeof e == "object" && e !== null && e.$$typeof === E)
111
+ function f(e) {
112
+ if (e === g) return "<>";
113
+ if (typeof e == "object" && e !== null && e.$$typeof === u)
114
114
  return "<...>";
115
115
  try {
116
116
  var r = d(e);
@@ -119,45 +119,45 @@ function le() {
119
119
  return "<...>";
120
120
  }
121
121
  }
122
- function i() {
123
- var e = $.A;
122
+ function l() {
123
+ var e = M.A;
124
124
  return e === null ? null : e.getOwner();
125
125
  }
126
126
  function a() {
127
127
  return Error("react-stack-top-frame");
128
128
  }
129
129
  function v(e) {
130
- if (V.call(e, "key")) {
130
+ if (G.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 t() {
138
- G || (G = !0, console.error(
136
+ function i(e, r) {
137
+ function n() {
138
+ q || (q = !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
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
144
- get: t,
143
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
144
+ get: n,
145
145
  configurable: !0
146
146
  });
147
147
  }
148
148
  function p() {
149
149
  var e = d(this.type);
150
- return q[e] || (q[e] = !0, console.error(
150
+ return H[e] || (H[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 C(e, r, t, o, O, D) {
155
- var s = t.ref;
154
+ function I(e, r, n, o, C, W) {
155
+ var s = n.ref;
156
156
  return e = {
157
- $$typeof: R,
157
+ $$typeof: _,
158
158
  type: e,
159
159
  key: r,
160
- props: t,
160
+ props: n,
161
161
  _owner: o
162
162
  }, (s !== void 0 ? s : null) !== null ? Object.defineProperty(e, "ref", {
163
163
  enumerable: !1,
@@ -176,33 +176,33 @@ function le() {
176
176
  configurable: !1,
177
177
  enumerable: !1,
178
178
  writable: !0,
179
- value: O
179
+ value: C
180
180
  }), Object.defineProperty(e, "_debugTask", {
181
181
  configurable: !1,
182
182
  enumerable: !1,
183
183
  writable: !0,
184
- value: D
184
+ value: W
185
185
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
186
186
  }
187
- function T(e, r, t, o, O, D) {
187
+ function R(e, r, n, o, C, W) {
188
188
  var s = r.children;
189
189
  if (s !== void 0)
190
190
  if (o)
191
191
  if (te(s)) {
192
192
  for (o = 0; o < s.length; o++)
193
- g(s[o]);
193
+ E(s[o]);
194
194
  Object.freeze && Object.freeze(s);
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 g(s);
200
- if (V.call(r, "key")) {
199
+ else E(s);
200
+ if (G.call(r, "key")) {
201
201
  s = d(e);
202
- var x = Object.keys(r).filter(function(ne) {
202
+ var j = Object.keys(r).filter(function(ne) {
203
203
  return ne !== "key";
204
204
  });
205
- o = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", J[s + o] || (x = 0 < x.length ? "{" + x.join(": ..., ") + ": ...}" : "{}", console.error(
205
+ o = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", Z[s + o] || (j = 0 < j.length ? "{" + j.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} />
@@ -211,150 +211,157 @@ React keys must be passed directly to JSX without using spread:
211
211
  <%s key={someKey} {...props} />`,
212
212
  o,
213
213
  s,
214
- x,
214
+ j,
215
215
  s
216
- ), J[s + o] = !0);
216
+ ), Z[s + o] = !0);
217
217
  }
218
- if (s = null, t !== void 0 && (b(t), s = "" + t), v(r) && (b(r.key), s = "" + r.key), "key" in r) {
219
- t = {};
220
- for (var U in r)
221
- U !== "key" && (t[U] = r[U]);
222
- } else t = r;
223
- return s && l(
224
- t,
218
+ if (s = null, n !== void 0 && (b(n), s = "" + n), v(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 && i(
224
+ n,
225
225
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
226
- ), C(
226
+ ), I(
227
227
  e,
228
228
  s,
229
- t,
230
- i(),
231
- O,
232
- D
229
+ n,
230
+ l(),
231
+ C,
232
+ W
233
233
  );
234
234
  }
235
- function g(e) {
236
- j(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === E && (e._payload.status === "fulfilled" ? j(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
235
+ function E(e) {
236
+ S(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === u && (e._payload.status === "fulfilled" ? S(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
237
237
  }
238
- function j(e) {
239
- return typeof e == "object" && e !== null && e.$$typeof === R;
238
+ function S(e) {
239
+ return typeof e == "object" && e !== null && e.$$typeof === _;
240
240
  }
241
- var _ = oe, R = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), N = Symbol.for("react.strict_mode"), I = Symbol.for("react.profiler"), L = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), h = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), y = Symbol.for("react.memo"), E = Symbol.for("react.lazy"), ee = Symbol.for("react.activity"), re = Symbol.for("react.client.reference"), $ = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, te = Array.isArray, F = console.createTask ? console.createTask : function() {
241
+ var y = oe, _ = Symbol.for("react.transitional.element"), L = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), k = Symbol.for("react.strict_mode"), D = Symbol.for("react.profiler"), P = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), $ = Symbol.for("react.forward_ref"), F = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), u = Symbol.for("react.lazy"), x = Symbol.for("react.activity"), T = Symbol.for("react.client.reference"), M = y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, te = Array.isArray, U = console.createTask ? console.createTask : function() {
242
242
  return null;
243
243
  };
244
- _ = {
244
+ y = {
245
245
  react_stack_bottom_frame: function(e) {
246
246
  return e();
247
247
  }
248
248
  };
249
- var G, q = {}, B = _.react_stack_bottom_frame.bind(
250
- _,
249
+ var q, H = {}, J = y.react_stack_bottom_frame.bind(
250
+ y,
251
251
  a
252
- )(), H = F(u(a)), J = {};
253
- A.Fragment = k, A.jsx = function(e, r, t) {
254
- var o = 1e4 > $.recentlyCreatedOwnerStacks++;
255
- return T(
252
+ )(), X = U(f(a)), Z = {};
253
+ O.Fragment = g, O.jsx = function(e, r, n) {
254
+ var o = 1e4 > M.recentlyCreatedOwnerStacks++;
255
+ return R(
256
256
  e,
257
257
  r,
258
- t,
258
+ n,
259
259
  !1,
260
- o ? Error("react-stack-top-frame") : B,
261
- o ? F(u(e)) : H
260
+ o ? Error("react-stack-top-frame") : J,
261
+ o ? U(f(e)) : X
262
262
  );
263
- }, A.jsxs = function(e, r, t) {
264
- var o = 1e4 > $.recentlyCreatedOwnerStacks++;
265
- return T(
263
+ }, O.jsxs = function(e, r, n) {
264
+ var o = 1e4 > M.recentlyCreatedOwnerStacks++;
265
+ return R(
266
266
  e,
267
267
  r,
268
- t,
268
+ n,
269
269
  !0,
270
- o ? Error("react-stack-top-frame") : B,
271
- o ? F(u(e)) : H
270
+ o ? Error("react-stack-top-frame") : J,
271
+ o ? U(f(e)) : X
272
272
  );
273
273
  };
274
- }()), A;
274
+ }()), O;
275
275
  }
276
- process.env.NODE_ENV === "production" ? z.exports = ie() : z.exports = le();
277
- var n = z.exports;
278
- const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], K = 90, de = ({ apiUrl: d, onComplete: m }) => {
279
- const b = se(null), [u, i] = w([]), [a, v] = w(0), [l, p] = w("idle"), [C, T] = w(3), [g, j] = w(K), [_, R] = w(!1), S = () => {
276
+ process.env.NODE_ENV === "production" ? B.exports = le() : B.exports = ie();
277
+ var t = B.exports;
278
+ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], re = 60, pe = ({ apiUrl: d, onComplete: m }) => {
279
+ const b = se(null), [f, l] = w([]), [a, v] = w(0), [i, p] = w("idle"), [I, R] = w(3), [E, S] = w(re), [y, _] = w(!1), [L, g] = w(!1), k = () => {
280
280
  const c = [...ce].sort(() => 0.5 - Math.random()).slice(0, 3);
281
- i(c), v(0), p("idle"), T(3), j(K), R(!1);
281
+ l(c), v(0), p("idle"), R(3), S(re), _(!1), g(!1);
282
282
  };
283
- X(() => {
284
- S();
283
+ Q(() => {
284
+ k();
285
285
  }, []);
286
- const k = () => {
287
- S();
286
+ const D = () => {
287
+ k();
288
288
  };
289
- X(() => {
289
+ Q(() => {
290
290
  let c;
291
- return _ && g > 0 ? c = setInterval(() => {
292
- j((h) => h - 1);
293
- }, 1e3) : g === 0 && l !== "success" && (p("timeout"), R(!1), m && m(!1)), () => clearInterval(c);
294
- }, [_, g, l]);
295
- const N = async () => {
296
- _ || R(!0), p("counting");
291
+ return y && E > 0 ? c = setInterval(() => {
292
+ S((h) => h - 1);
293
+ }, 1e3) : E === 0 && i !== "success" && (p("timeout"), _(!1), g(!1), m && m(!1)), () => clearInterval(c);
294
+ }, [y, E, i]);
295
+ const P = async () => {
296
+ y || _(!0), p("counting");
297
297
  let c = 3;
298
298
  const h = setInterval(() => {
299
- c -= 1, T(c), c === 0 && (clearInterval(h), I());
299
+ c -= 1, R(c), c === 0 && (clearInterval(h), Y());
300
300
  }, 1e3);
301
- }, I = async () => {
301
+ }, Y = async () => {
302
302
  p("capturing");
303
303
  const c = [], h = 20;
304
- for (let f = 0; f < h; f++) {
305
- const y = b.current.getScreenshot();
306
- c.push(y), await new Promise((E) => setTimeout(E, 100));
304
+ for (let u = 0; u < h; u++) {
305
+ const x = b.current.getScreenshot();
306
+ c.push(x), await new Promise((T) => setTimeout(T, 100));
307
307
  }
308
- L(c);
309
- }, L = async (c) => {
310
- p("verifying");
308
+ $(c);
309
+ }, $ = async (c) => {
310
+ window.dummyTest = "I am working!", console.log("SEND TO BRAIN CALLED"), p("verifying");
311
311
  const h = new FormData();
312
- for (let f = 0; f < c.length; f++) {
313
- const y = await fetch(c[f]).then((E) => E.blob());
314
- h.append("files", y, `frame_${f}.jpg`);
312
+ for (let u = 0; u < c.length; u++) {
313
+ const x = await fetch(c[u]).then((T) => T.blob());
314
+ h.append("files", x, `frame_${u}.jpg`);
315
315
  }
316
- h.append("challenge", u[a]);
316
+ h.append("challenge", f[a]);
317
317
  try {
318
- const y = await (await fetch(`${d}/v1/verify`, {
318
+ const x = await (await fetch(`${d}/v1/verify`, {
319
319
  method: "POST",
320
320
  body: h
321
321
  })).json();
322
- console.log("API Response:", y.status), y.is_live ? a < 2 ? (v((E) => E + 1), T(3), p("idle")) : (p("success"), m && m(!0)) : (alert("Action not recognized. Please try again!"), p("idle"), T(3));
323
- } catch (f) {
324
- console.error("API Error:", f), p("fail");
322
+ console.log("API Response:", x.status), x.is_live ? a < 2 ? (v((T) => T + 1), R(3), p("idle")) : (p("success"), _(!1), m && m(!0)) : (console.log("Not live - Opening Modal"), _(!1), g(!0), p("idle"), R(3));
323
+ } catch (u) {
324
+ console.error("API Error:", u), g(!0), p("idle");
325
325
  }
326
- }, Y = {
326
+ }, F = {
327
327
  Smile: "Show us a big SMILE! 😁",
328
328
  Blink: "BLINK your eyes rapidly! 👁️",
329
329
  Turn_Head: "Slowly TURN your head left and right! ↔️",
330
330
  Thumbs_Up: "Give a THUMBS UP! 👍"
331
331
  };
332
- return /* @__PURE__ */ n.jsxs("div", { style: { textAlign: "center", padding: "20px", fontFamily: "sans-serif" }, children: [
333
- _ && l !== "success" && /* @__PURE__ */ n.jsxs("div", { style: { fontSize: "20px", fontWeight: "bold", color: g < 10 ? "red" : "black" }, children: [
332
+ return /* @__PURE__ */ t.jsxs("div", { style: { textAlign: "center", padding: "20px", fontFamily: "sans-serif" }, children: [
333
+ y && i !== "success" && /* @__PURE__ */ t.jsxs("div", { style: { fontSize: "20px", fontWeight: "bold", color: E < 10 ? "red" : "black" }, children: [
334
334
  "Time Remaining: ",
335
- g,
335
+ E,
336
336
  "s"
337
337
  ] }),
338
- l === "success" && /* @__PURE__ */ n.jsxs("div", { children: [
339
- /* @__PURE__ */ n.jsx("h2", { children: " Verification Passed!" }),
340
- /* @__PURE__ */ n.jsx("button", { onClick: k, style: { ...W, backgroundColor: "#6c757d" }, children: "Verify Again" })
338
+ L && /* @__PURE__ */ t.jsx("div", { style: ue, children: /* @__PURE__ */ t.jsxs("div", { style: fe, children: [
339
+ /* @__PURE__ */ t.jsx("h3", { style: { color: "#dc3545" }, children: "Action Not Detected" }),
340
+ /* @__PURE__ */ t.jsx("p", { children: "We couldn't verify that move. Please try again before time runs out!" }),
341
+ /* @__PURE__ */ t.jsx("button", { onClick: () => {
342
+ g(!1), P();
343
+ }, style: N, children: "Try Again" })
344
+ ] }) }),
345
+ i === "success" && /* @__PURE__ */ t.jsxs("div", { children: [
346
+ /* @__PURE__ */ t.jsx("h2", { children: "✅ Verification Passed!" }),
347
+ /* @__PURE__ */ t.jsx("button", { onClick: D, style: { ...N, backgroundColor: "#6c757d" }, children: "Verify Again" })
341
348
  ] }),
342
- l === "timeout" && /* @__PURE__ */ n.jsxs("div", { children: [
343
- /* @__PURE__ */ n.jsx("h2", { style: { color: "#dc3545" }, children: "⏰ Session Expired" }),
344
- /* @__PURE__ */ n.jsx("p", { children: "You didn't complete the challenges in time." }),
345
- /* @__PURE__ */ n.jsx("p", { children: "Please ensure you follow the instructions and perform the tasks within the time limit. (60 secsonds)" }),
346
- /* @__PURE__ */ n.jsx("button", { onClick: S, style: W, children: "🔄 Try Again" })
349
+ i === "timeout" && /* @__PURE__ */ t.jsxs("div", { children: [
350
+ /* @__PURE__ */ t.jsx("h2", { style: { color: "#dc3545" }, children: "⏰ Session Expired" }),
351
+ /* @__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: k, style: N, children: "🔄 Try Again" })
347
354
  ] }),
348
- ["idle", "counting", "capturing", "verifying"].includes(l) && /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
349
- /* @__PURE__ */ n.jsx("h2", { children: "Please be in a well-lit room where your face can be well seen." }),
350
- /* @__PURE__ */ n.jsxs("h3", { children: [
355
+ ["idle", "counting", "capturing", "verifying"].includes(i) && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
356
+ /* @__PURE__ */ t.jsx("h2", { children: "Please be in a well-lit room where your face can be well seen." }),
357
+ /* @__PURE__ */ t.jsxs("h3", { children: [
351
358
  "Challenge ",
352
359
  a + 1,
353
360
  " of 3"
354
361
  ] }),
355
- /* @__PURE__ */ n.jsx("h2", { style: { color: "#007bff" }, children: Y[u[a]] }),
356
- /* @__PURE__ */ n.jsxs("div", { style: { position: "relative", width: "fit-content", margin: "auto" }, children: [
357
- /* @__PURE__ */ n.jsx(
362
+ /* @__PURE__ */ t.jsx("h2", { style: { color: "#007bff" }, children: F[f[a]] }),
363
+ /* @__PURE__ */ t.jsxs("div", { style: { position: "relative", width: "fit-content", margin: "auto" }, children: [
364
+ /* @__PURE__ */ t.jsx(
358
365
  ae,
359
366
  {
360
367
  audio: !1,
@@ -363,14 +370,14 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], K = 90, de = ({ apiUrl:
363
370
  style: { borderRadius: "10px", width: "100%", maxWidth: "400px", transform: "scaleX(-1)" }
364
371
  }
365
372
  ),
366
- l === "counting" && /* @__PURE__ */ n.jsx("div", { style: M, children: C }),
367
- l === "verifying" && /* @__PURE__ */ n.jsx("div", { style: M, children: "Analyzing..." }),
368
- l === "capturing" && /* @__PURE__ */ n.jsx("div", { style: { ...M, background: "rgba(40, 167, 69, 0.3)" }, children: "Recording..." })
373
+ i === "counting" && /* @__PURE__ */ t.jsx("div", { style: V, children: I }),
374
+ i === "verifying" && /* @__PURE__ */ t.jsx("div", { style: V, children: "Analyzing..." }),
375
+ i === "capturing" && /* @__PURE__ */ t.jsx("div", { style: { ...V, background: "rgba(40, 167, 69, 0.3)" }, children: "Recording..." })
369
376
  ] }),
370
- /* @__PURE__ */ n.jsx("div", { style: { marginTop: "20px" }, children: l === "idle" && /* @__PURE__ */ n.jsx("button", { onClick: N, style: W, children: "I'm Ready" }) })
377
+ /* @__PURE__ */ t.jsx("div", { style: { marginTop: "20px" }, children: i === "idle" && /* @__PURE__ */ t.jsx("button", { onClick: P, style: N, children: "I'm Ready" }) })
371
378
  ] })
372
379
  ] });
373
- }, M = {
380
+ }, V = {
374
381
  position: "absolute",
375
382
  top: 0,
376
383
  left: 0,
@@ -383,7 +390,7 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], K = 90, de = ({ apiUrl:
383
390
  justifyContent: "center",
384
391
  fontSize: "48px",
385
392
  borderRadius: "10px"
386
- }, W = {
393
+ }, N = {
387
394
  padding: "10px 30px",
388
395
  fontSize: "18px",
389
396
  cursor: "pointer",
@@ -391,19 +398,38 @@ const ce = ["Smile", "Blink", "Turn_Head", "Thumbs_Up"], K = 90, de = ({ apiUrl:
391
398
  color: "white",
392
399
  border: "none",
393
400
  borderRadius: "5px"
394
- }, me = async (d, m, b) => {
395
- const u = new FormData();
401
+ }, ue = {
402
+ position: "absolute",
403
+ top: 0,
404
+ left: 0,
405
+ right: 0,
406
+ bottom: 0,
407
+ backgroundColor: "rgba(0,0,0,0.7)",
408
+ display: "flex",
409
+ alignItems: "center",
410
+ justifyContent: "center",
411
+ zIndex: 100,
412
+ borderRadius: "10px"
413
+ }, fe = {
414
+ backgroundColor: "white",
415
+ padding: "30px",
416
+ borderRadius: "15px",
417
+ maxWidth: "300px",
418
+ boxShadow: "0 4px 15px rgba(0,0,0,0.3)",
419
+ color: "#000"
420
+ }, he = async (d, m, b) => {
421
+ const f = new FormData();
396
422
  m.forEach((a, v) => {
397
- u.append("files", a, `frame_${v}.jpg`);
398
- }), u.append("challenge", b);
399
- const i = await fetch(`${d}/v1/verify`, {
423
+ f.append("files", a, `frame_${v}.jpg`);
424
+ }), f.append("challenge", b);
425
+ const l = await fetch(`${d}/v1/verify`, {
400
426
  method: "POST",
401
- body: u
427
+ body: f
402
428
  });
403
- if (!i.ok) throw new Error("Network response was not ok");
404
- return await i.json();
429
+ if (!l.ok) throw new Error("Network response was not ok");
430
+ return await l.json();
405
431
  };
406
432
  export {
407
- de as LivenessSDK,
408
- me as verifyLiveness
433
+ pe as LivenessSDK,
434
+ he as verifyLiveness
409
435
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(E,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):(E=typeof globalThis<"u"?globalThis:E||self,u(E.LivenessSDK={},E.React,E.Webcam))})(this,function(E,u,ee){"use strict";var N={exports:{}},j={};/**
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 L={exports:{}},k={};/**
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 B;function re(){if(B)return j;B=1;var m=Symbol.for("react.transitional.element"),p=Symbol.for("react.fragment");function v(f,i,a){var y=null;if(a!==void 0&&(y=""+a),i.key!==void 0&&(y=""+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:f,key:y,ref:i!==void 0?i:null,props:a}}return j.Fragment=p,j.jsx=v,j.jsxs=v,j}var k={};/**
9
+ */var J;function ne(){if(J)return k;J=1;var m=Symbol.for("react.transitional.element"),p=Symbol.for("react.fragment");function v(d,i,a){var y=null;if(a!==void 0&&(y=""+a),i.key!==void 0&&(y=""+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:y,ref:i!==void 0?i:null,props:a}}return k.Fragment=p,k.jsx=v,k.jsxs=v,k}var A={};/**
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 H;function te(){return H||(H=1,process.env.NODE_ENV!=="production"&&function(){function m(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case F:return"Profiler";case D:return"StrictMode";case b:return"Suspense";case d:return"SuspenseList";case ae: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 U:return e.displayName||"Context";case M:return(e._context.displayName||"Context")+".Consumer";case c:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case R:return r=e.displayName||null,r!==null?r:m(e.type)||"Memo";case g:r=e._payload,e=e._init;try{return m(e(r))}catch{}}return null}function p(e){return""+e}function v(e){try{p(e);var r=!1}catch{r=!0}if(r){r=console;var n=r.error,s=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",s),p(e)}}function f(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===g)return"<...>";try{var r=m(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function i(){var e=W.A;return e===null?null:e.getOwner()}function a(){return Error("react-stack-top-frame")}function y(e){if(X.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function l(e,r){function n(){K||(K=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function h(){var e=m(this.type);return Z[e]||(Z[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 Y(e,r,n,s,C,V){var o=n.ref;return e={$$typeof:x,type:e,key:r,props:n,_owner:s},(o!==void 0?o: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:C}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function S(e,r,n,s,C,V){var o=r.children;if(o!==void 0)if(s)if(le(o)){for(s=0;s<o.length;s++)T(o[s]);Object.freeze&&Object.freeze(o)}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 T(o);if(X.call(r,"key")){o=m(e);var w=Object.keys(r).filter(function(ce){return ce!=="key"});s=0<w.length?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}",q[o+s]||(w=0<w.length?"{"+w.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
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 _:return"Fragment";case M:return"Profiler";case P:return"StrictMode";case z:return"Suspense";case c:return"SuspenseList";case R: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 F:return"Portal";case U:return e.displayName||"Context";case N: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 v(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===_)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 y(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 Y(e,t,n,o,I,G){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:I}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function S(e,t,n,o,I,G){var s=t.children;if(s!==void 0)if(o)if(ue(s)){for(o=0;o<s.length;o++)x(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 x(s);if(Z.call(t,"key")){s=m(e);var j=Object.keys(t).filter(function(fe){return fe!=="key"});o=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",te[s+o]||(j=0<j.length?"{"+j.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} />`,s,o,w,o),q[o+s]=!0)}if(o=null,n!==void 0&&(v(n),o=""+n),y(r)&&(v(r.key),o=""+r.key),"key"in r){n={};for(var G in r)G!=="key"&&(n[G]=r[G])}else n=r;return o&&l(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),Y(e,o,n,i(),C,V)}function T(e){P(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===g&&(e._payload.status==="fulfilled"?P(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function P(e){return typeof e=="object"&&e!==null&&e.$$typeof===x}var _=u,x=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),U=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),ae=Symbol.for("react.activity"),ie=Symbol.for("react.client.reference"),W=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,le=Array.isArray,z=console.createTask?console.createTask:function(){return null};_={react_stack_bottom_frame:function(e){return e()}};var K,Z={},Q=_.react_stack_bottom_frame.bind(_,a)(),$=z(f(a)),q={};k.Fragment=O,k.jsx=function(e,r,n){var s=1e4>W.recentlyCreatedOwnerStacks++;return S(e,r,n,!1,s?Error("react-stack-top-frame"):Q,s?z(f(e)):$)},k.jsxs=function(e,r,n){var s=1e4>W.recentlyCreatedOwnerStacks++;return S(e,r,n,!0,s?Error("react-stack-top-frame"):Q,s?z(f(e)):$)}}()),k}process.env.NODE_ENV==="production"?N.exports=re():N.exports=te();var t=N.exports;const ne=["Smile","Blink","Turn_Head","Thumbs_Up"],J=90,se=({apiUrl:m,onComplete:p})=>{const v=u.useRef(null),[f,i]=u.useState([]),[a,y]=u.useState(0),[l,h]=u.useState("idle"),[Y,S]=u.useState(3),[T,P]=u.useState(J),[_,x]=u.useState(!1),A=()=>{const c=[...ne].sort(()=>.5-Math.random()).slice(0,3);i(c),y(0),h("idle"),S(3),P(J),x(!1)};u.useEffect(()=>{A()},[]);const O=()=>{A()};u.useEffect(()=>{let c;return _&&T>0?c=setInterval(()=>{P(b=>b-1)},1e3):T===0&&l!=="success"&&(h("timeout"),x(!1),p&&p(!1)),()=>clearInterval(c)},[_,T,l]);const D=async()=>{_||x(!0),h("counting");let c=3;const b=setInterval(()=>{c-=1,S(c),c===0&&(clearInterval(b),F())},1e3)},F=async()=>{h("capturing");const c=[],b=20;for(let d=0;d<b;d++){const R=v.current.getScreenshot();c.push(R),await new Promise(g=>setTimeout(g,100))}M(c)},M=async c=>{h("verifying");const b=new FormData;for(let d=0;d<c.length;d++){const R=await fetch(c[d]).then(g=>g.blob());b.append("files",R,`frame_${d}.jpg`)}b.append("challenge",f[a]);try{const R=await(await fetch(`${m}/v1/verify`,{method:"POST",body:b})).json();console.log("API Response:",R.status),R.is_live?a<2?(y(g=>g+1),S(3),h("idle")):(h("success"),p&&p(!0)):(alert("Action not recognized. Please try again!"),h("idle"),S(3))}catch(d){console.error("API Error:",d),h("fail")}},U={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 t.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[_&&l!=="success"&&t.jsxs("div",{style:{fontSize:"20px",fontWeight:"bold",color:T<10?"red":"black"},children:["Time Remaining: ",T,"s"]}),l==="success"&&t.jsxs("div",{children:[t.jsx("h2",{children:"✅ Verification Passed!"}),t.jsx("button",{onClick:O,style:{...L,backgroundColor:"#6c757d"},children:"Verify Again"})]}),l==="timeout"&&t.jsxs("div",{children:[t.jsx("h2",{style:{color:"#dc3545"},children:"⏰ Session Expired"}),t.jsx("p",{children:"You didn't complete the challenges in time."}),t.jsx("p",{children:"Please ensure you follow the instructions and perform the tasks within the time limit. (60 secsonds)"}),t.jsx("button",{onClick:A,style:L,children:"🔄 Try Again"})]}),["idle","counting","capturing","verifying"].includes(l)&&t.jsxs(t.Fragment,{children:[t.jsx("h2",{children:"Please be in a well-lit room where your face can be well seen."}),t.jsxs("h3",{children:["Challenge ",a+1," of 3"]}),t.jsx("h2",{style:{color:"#007bff"},children:U[f[a]]}),t.jsxs("div",{style:{position:"relative",width:"fit-content",margin:"auto"},children:[t.jsx(ee,{audio:!1,ref:v,screenshotFormat:"image/jpeg",style:{borderRadius:"10px",width:"100%",maxWidth:"400px",transform:"scaleX(-1)"}}),l==="counting"&&t.jsx("div",{style:I,children:Y}),l==="verifying"&&t.jsx("div",{style:I,children:"Analyzing..."}),l==="capturing"&&t.jsx("div",{style:{...I,background:"rgba(40, 167, 69, 0.3)"},children:"Recording..."})]}),t.jsx("div",{style:{marginTop:"20px"},children:l==="idle"&&t.jsx("button",{onClick:D,style:L,children:"I'm Ready"})})]})]})},I={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"},L={padding:"10px 30px",fontSize:"18px",cursor:"pointer",backgroundColor:"#28a745",color:"white",border:"none",borderRadius:"5px"},oe=async(m,p,v)=>{const f=new FormData;p.forEach((a,y)=>{f.append("files",a,`frame_${y}.jpg`)}),f.append("challenge",v);const i=await fetch(`${m}/v1/verify`,{method:"POST",body:f});if(!i.ok)throw new Error("Network response was not ok");return await i.json()};E.LivenessSDK=se,E.verifyLiveness=oe,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
22
+ <%s key={someKey} {...props} />`,o,s,j,s),te[s+o]=!0)}if(s=null,n!==void 0&&(v(n),s=""+n),y(t)&&(v(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),Y(e,s,n,i(),I,G)}function x(e){O(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===f&&(e._payload.status==="fulfilled"?O(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function O(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}var E=u,T=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),N=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"),R=Symbol.for("react.activity"),w=Symbol.for("react.client.reference"),V=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=Object.prototype.hasOwnProperty,ue=Array.isArray,B=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var Q,q={},$=E.react_stack_bottom_frame.bind(E,a)(),ee=B(d(a)),te={};A.Fragment=_,A.jsx=function(e,t,n){var o=1e4>V.recentlyCreatedOwnerStacks++;return S(e,t,n,!1,o?Error("react-stack-top-frame"):$,o?B(d(e)):ee)},A.jsxs=function(e,t,n){var o=1e4>V.recentlyCreatedOwnerStacks++;return S(e,t,n,!0,o?Error("react-stack-top-frame"):$,o?B(d(e)):ee)}}()),A}process.env.NODE_ENV==="production"?L.exports=ne():L.exports=oe();var r=L.exports;const se=["Smile","Blink","Turn_Head","Thumbs_Up"],K=60,ae=({apiUrl:m,onComplete:p})=>{const v=u.useRef(null),[d,i]=u.useState([]),[a,y]=u.useState(0),[l,h]=u.useState("idle"),[Y,S]=u.useState(3),[x,O]=u.useState(K),[E,T]=u.useState(!1),[F,_]=u.useState(!1),P=()=>{const c=[...se].sort(()=>.5-Math.random()).slice(0,3);i(c),y(0),h("idle"),S(3),O(K),T(!1),_(!1)};u.useEffect(()=>{P()},[]);const M=()=>{P()};u.useEffect(()=>{let c;return E&&x>0?c=setInterval(()=>{O(b=>b-1)},1e3):x===0&&l!=="success"&&(h("timeout"),T(!1),_(!1),p&&p(!1)),()=>clearInterval(c)},[E,x,l]);const N=async()=>{E||T(!0),h("counting");let c=3;const b=setInterval(()=>{c-=1,S(c),c===0&&(clearInterval(b),U())},1e3)},U=async()=>{h("capturing");const c=[],b=20;for(let f=0;f<b;f++){const R=v.current.getScreenshot();c.push(R),await new Promise(w=>setTimeout(w,100))}W(c)},W=async c=>{window.dummyTest="I am working!",console.log("SEND TO BRAIN CALLED"),h("verifying");const b=new FormData;for(let f=0;f<c.length;f++){const R=await fetch(c[f]).then(w=>w.blob());b.append("files",R,`frame_${f}.jpg`)}b.append("challenge",d[a]);try{const R=await(await fetch(`${m}/v1/verify`,{method:"POST",body:b})).json();console.log("API Response:",R.status),R.is_live?a<2?(y(w=>w+1),S(3),h("idle")):(h("success"),T(!1),p&&p(!0)):(console.log("Not live - Opening Modal"),T(!1),_(!0),h("idle"),S(3))}catch(f){console.error("API Error:",f),_(!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:[E&&l!=="success"&&r.jsxs("div",{style:{fontSize:"20px",fontWeight:"bold",color:x<10?"red":"black"},children:["Time Remaining: ",x,"s"]}),F&&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:()=>{_(!1),N()},style:C,children:"Try Again"})]})}),l==="success"&&r.jsxs("div",{children:[r.jsx("h2",{children:"✅ Verification Passed!"}),r.jsx("button",{onClick:M,style:{...C,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:P,style:C,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:v,screenshotFormat:"image/jpeg",style:{borderRadius:"10px",width:"100%",maxWidth:"400px",transform:"scaleX(-1)"}}),l==="counting"&&r.jsx("div",{style:D,children:Y}),l==="verifying"&&r.jsx("div",{style:D,children:"Analyzing..."}),l==="capturing"&&r.jsx("div",{style:{...D,background:"rgba(40, 167, 69, 0.3)"},children:"Recording..."})]}),r.jsx("div",{style:{marginTop:"20px"},children:l==="idle"&&r.jsx("button",{onClick:N,style:C,children:"I'm Ready"})})]})]})},D={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"},C={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,v)=>{const d=new FormData;p.forEach((a,y)=>{d.append("files",a,`frame_${y}.jpg`)}),d.append("challenge",v);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"})});
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.2",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"