idmission-web-sdk 2.3.124 → 2.3.126

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/sdk2.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import React__default, { useRef, useState, useEffect, useContext, createContext, useReducer, useCallback, useMemo, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
2
+ import React__default, { useRef, useState, useEffect, useContext, createContext, useReducer, useCallback, useMemo, useLayoutEffect, forwardRef, useImperativeHandle, memo } from 'react';
3
3
  import * as ReactDOM from 'react-dom/client';
4
4
  import platform from 'platform';
5
5
  import styled, { keyframes, useTheme, ThemeProvider as ThemeProvider$1 } from 'styled-components';
@@ -16,7 +16,6 @@ import { devtools } from 'zustand/middleware';
16
16
  import { useShallow } from 'zustand/react/shallow';
17
17
  import cn from 'clsx';
18
18
  import SignatureCanvas from 'react-signature-canvas';
19
- import { renderToString } from 'react-dom/server';
20
19
 
21
20
  /******************************************************************************
22
21
  Copyright (c) Microsoft Corporation.
@@ -205,7 +204,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
205
204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
206
205
  };
207
206
 
208
- var webSdkVersion = '2.3.124';
207
+ var webSdkVersion = '2.3.126';
209
208
 
210
209
  function getPlatform() {
211
210
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -14378,6 +14377,9 @@ function inferBlobType(blobPart) {
14378
14377
 
14379
14378
  var signatureRecorder = null;
14380
14379
  var signatureChunks = [];
14380
+ var ondataavailableInvocations = [];
14381
+ var ondataavailableStartTime;
14382
+ var lastCalculatedVideoChunkRate;
14381
14383
  var videoSignatureInitialState = {
14382
14384
  startRecording: function startRecording() {
14383
14385
  return null;
@@ -14402,6 +14404,10 @@ var videoSignatureInitialState = {
14402
14404
  signatureValid: false,
14403
14405
  supportsRequestVideoFrameCallback: undefined,
14404
14406
  supportsRoundRect: undefined,
14407
+ nullChunksReceived: 0,
14408
+ timesSignatureCleared: 0,
14409
+ finalChunkReceived: false,
14410
+ requestDataInterval: undefined,
14405
14411
  onSignatureVideoCaptured: function onSignatureVideoCaptured() {
14406
14412
  return null;
14407
14413
  }
@@ -14414,8 +14420,11 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14414
14420
  captureAudio = false;
14415
14421
  }
14416
14422
  if (!camera) throw new Error('Camera not found');
14417
- // set our flag and clear whatever we have recorded so far.
14423
+ // clear whatever we have recorded so far.
14418
14424
  signatureChunks = [];
14425
+ ondataavailableInvocations = [];
14426
+ ondataavailableStartTime = undefined;
14427
+ lastCalculatedVideoChunkRate = undefined;
14419
14428
  // start recording from the output canvas to capture the signature
14420
14429
  var outputStream = (_a = get().outputCanvas.current) === null || _a === void 0 ? void 0 : _a.captureStream(24);
14421
14430
  if (!outputStream) throw new Error('outputStream not found');
@@ -14433,77 +14442,123 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14433
14442
  recordingStartedAt: e.timeStamp
14434
14443
  });
14435
14444
  };
14436
- var hasFirstChunk = false;
14437
14445
  signatureRecorder.ondataavailable = function (event) {
14446
+ var now = performance.now();
14438
14447
  signatureChunks.push(event.data);
14439
- if (!hasFirstChunk) {
14440
- hasFirstChunk = true;
14441
- set({
14442
- firstChunkReceivedAt: performance.now(),
14443
- lastChunkReceivedAt: performance.now()
14448
+ trackVideoChunkRate(now);
14449
+ if (event.data.size > 0) {
14450
+ set(function (state) {
14451
+ var _a;
14452
+ return {
14453
+ firstChunkReceivedAt: (_a = state.firstChunkReceivedAt) !== null && _a !== void 0 ? _a : now,
14454
+ lastChunkReceivedAt: now
14455
+ };
14444
14456
  });
14445
14457
  } else {
14446
- set({
14447
- lastChunkReceivedAt: performance.now()
14458
+ set(function (state) {
14459
+ var _a;
14460
+ return {
14461
+ nullChunksReceived: state.nullChunksReceived + 1,
14462
+ firstNullChunkReceivedAt: (_a = state.firstNullChunkReceivedAt) !== null && _a !== void 0 ? _a : now,
14463
+ lastNullChunkReceivedAt: now
14464
+ };
14448
14465
  });
14449
14466
  }
14450
14467
  };
14451
- signatureRecorder.start(250);
14468
+ signatureRecorder.start();
14469
+ var interval = setInterval(function () {
14470
+ return signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14471
+ }, 250);
14452
14472
  set({
14473
+ requestDataInterval: interval,
14453
14474
  recordingStartRequestedAt: performance.now()
14454
14475
  });
14455
14476
  },
14456
14477
  stopRecording: function stopRecording(signatureData, imageUrl) {
14457
14478
  return __awaiter(this, void 0, void 0, function () {
14458
- var _this = this;
14459
- return __generator(this, function (_a) {
14460
- switch (_a.label) {
14479
+ function processVideo() {
14480
+ return __awaiter(this, void 0, void 0, function () {
14481
+ var recordingStoppedAt, mimeType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, acceptClickedAt, clearClickedAt, recordingStopRequestedAt, lastChunkReceivedAt, supportsRequestVideoFrameCallback, supportsRoundRect, nullChunksReceived, firstNullChunkReceivedAt, lastNullChunkReceivedAt, timesSignatureCleared, metadata;
14482
+ return __generator(this, function (_b) {
14483
+ if (get().recordingStoppedAt) return [2 /*return*/];
14484
+ recordingStoppedAt = performance.now();
14485
+ set({
14486
+ recordingStoppedAt: recordingStoppedAt
14487
+ });
14488
+ mimeType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14489
+ blob = new Blob(signatureChunks, {
14490
+ type: mimeType
14491
+ });
14492
+ signatureChunks = [];
14493
+ signatureRecorder = null;
14494
+ _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, acceptClickedAt = _a.acceptClickedAt, clearClickedAt = _a.clearClickedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt, supportsRequestVideoFrameCallback = _a.supportsRequestVideoFrameCallback, supportsRoundRect = _a.supportsRoundRect, nullChunksReceived = _a.nullChunksReceived, firstNullChunkReceivedAt = _a.firstNullChunkReceivedAt, lastNullChunkReceivedAt = _a.lastNullChunkReceivedAt, timesSignatureCleared = _a.timesSignatureCleared;
14495
+ metadata = {
14496
+ mimeType: mimeType,
14497
+ browserFeatures: {
14498
+ supportsRoundRect: supportsRoundRect,
14499
+ supportsRequestVideoFrameCallback: supportsRequestVideoFrameCallback
14500
+ },
14501
+ diagnostics: {
14502
+ nullChunksReceived: nullChunksReceived,
14503
+ firstNullChunkReceivedAt: firstNullChunkReceivedAt ? Math.ceil(firstNullChunkReceivedAt) : 0,
14504
+ lastNullChunkReceivedAt: lastNullChunkReceivedAt ? Math.ceil(lastNullChunkReceivedAt) : 0,
14505
+ finalChunkReceived: finalChunkReceived,
14506
+ finalChunkTimedOut: timedOut,
14507
+ finalChunkWaitedMs: Math.ceil(waitedMs),
14508
+ videoChunkRate: lastCalculatedVideoChunkRate,
14509
+ timesSignatureCleared: timesSignatureCleared
14510
+ },
14511
+ timingData: {
14512
+ recordingStartRequestedAt: recordingStartRequestedAt ? Math.ceil(recordingStartRequestedAt) : 0,
14513
+ recordingStartedAt: recordingStartedAt ? Math.ceil(recordingStartedAt) : 0,
14514
+ firstChunkReceivedAt: firstChunkReceivedAt ? Math.ceil(firstChunkReceivedAt) : 0,
14515
+ signatureStartedAt: signatureStartedAt ? Math.ceil(signatureStartedAt) : 0,
14516
+ signatureEndedAt: signatureEndedAt ? Math.ceil(signatureEndedAt) : 0,
14517
+ acceptClickedAt: acceptClickedAt ? Math.ceil(acceptClickedAt) : 0,
14518
+ clearClickedAt: clearClickedAt ? Math.ceil(clearClickedAt) : 0,
14519
+ recordingStopRequestedAt: recordingStopRequestedAt ? Math.ceil(recordingStopRequestedAt) : 0,
14520
+ recordingStoppedAt: Math.ceil(recordingStoppedAt),
14521
+ lastChunkReceivedAt: lastChunkReceivedAt ? Math.ceil(lastChunkReceivedAt) : 0
14522
+ }
14523
+ };
14524
+ debug('signature video metadata', metadata);
14525
+ onSignatureVideoCaptured(blob, signatureData !== null && signatureData !== void 0 ? signatureData : null, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, metadata);
14526
+ return [2 /*return*/];
14527
+ });
14528
+ });
14529
+ }
14530
+ var _a, recordingStartedAt, recordingStopRequestedAt, isRecording, _b, finalChunkReceived, timedOut, waitedMs;
14531
+ return __generator(this, function (_c) {
14532
+ switch (_c.label) {
14461
14533
  case 0:
14534
+ _a = get(), recordingStartedAt = _a.recordingStartedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt;
14535
+ isRecording = !!recordingStartedAt && !recordingStopRequestedAt;
14536
+ if (!isRecording) return [2 /*return*/];
14462
14537
  set({
14463
- recordingStopRequestedAt: performance.now()
14538
+ recordingStopRequestedAt: performance.now(),
14539
+ recordingStoppedAt: undefined
14464
14540
  });
14465
- if (!signatureRecorder) return [2 /*return*/];
14466
- return [4 /*yield*/, waitForOneMoreChunk()];
14541
+ clearInterval(get().requestDataInterval);
14542
+ return [4 /*yield*/, waitForOneMoreChunk()
14543
+ // this represents the time that it is safe to release the camera access
14544
+ ];
14467
14545
  case 1:
14468
- _a.sent();
14469
- signatureRecorder.onstop = function () {
14470
- return __awaiter(_this, void 0, void 0, function () {
14471
- var recordingStoppedAt, mimeType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, acceptClickedAt, recordingStopRequestedAt, lastChunkReceivedAt, supportsRequestVideoFrameCallback, supportsRoundRect;
14472
- return __generator(this, function (_b) {
14473
- recordingStoppedAt = performance.now();
14474
- set({
14475
- recordingStoppedAt: recordingStoppedAt
14476
- });
14477
- mimeType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14478
- blob = new Blob(signatureChunks, {
14479
- type: mimeType
14480
- });
14481
- signatureChunks = [];
14482
- signatureRecorder = null;
14483
- _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, acceptClickedAt = _a.acceptClickedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt, supportsRequestVideoFrameCallback = _a.supportsRequestVideoFrameCallback, supportsRoundRect = _a.supportsRoundRect;
14484
- onSignatureVideoCaptured(blob, signatureData !== null && signatureData !== void 0 ? signatureData : null, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14485
- mimeType: mimeType,
14486
- browserFeatures: {
14487
- supportsRoundRect: supportsRoundRect,
14488
- supportsRequestVideoFrameCallback: supportsRequestVideoFrameCallback
14489
- },
14490
- timingData: {
14491
- recordingStartRequestedAt: recordingStartRequestedAt ? Math.ceil(recordingStartRequestedAt) : 0,
14492
- recordingStartedAt: recordingStartedAt ? Math.ceil(recordingStartedAt) : 0,
14493
- firstChunkReceivedAt: firstChunkReceivedAt ? Math.ceil(firstChunkReceivedAt) : 0,
14494
- signatureStartedAt: signatureStartedAt ? Math.ceil(signatureStartedAt) : 0,
14495
- signatureEndedAt: signatureEndedAt ? Math.ceil(signatureEndedAt) : 0,
14496
- acceptClickedAt: acceptClickedAt ? Math.ceil(acceptClickedAt) : 0,
14497
- recordingStopRequestedAt: recordingStopRequestedAt ? Math.ceil(recordingStopRequestedAt) : 0,
14498
- recordingStoppedAt: Math.ceil(recordingStoppedAt),
14499
- lastChunkReceivedAt: lastChunkReceivedAt ? Math.ceil(lastChunkReceivedAt) : 0
14500
- }
14501
- });
14502
- return [2 /*return*/];
14503
- });
14504
- });
14505
- };
14546
+ _b = _c.sent(), finalChunkReceived = _b.finalChunkReceived, timedOut = _b.timedOut, waitedMs = _b.waitedMs;
14547
+ // this represents the time that it is safe to release the camera access
14548
+ set({
14549
+ finalChunkReceived: true
14550
+ });
14551
+ if (!signatureRecorder) return [3 /*break*/, 2];
14552
+ signatureRecorder.onstop = processVideo;
14506
14553
  signatureRecorder.stop();
14554
+ return [3 /*break*/, 4];
14555
+ case 2:
14556
+ warn('signature recorder not found, processing video immediately');
14557
+ return [4 /*yield*/, processVideo()];
14558
+ case 3:
14559
+ _c.sent();
14560
+ _c.label = 4;
14561
+ case 4:
14507
14562
  return [2 /*return*/];
14508
14563
  }
14509
14564
  });
@@ -14511,6 +14566,9 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14511
14566
  },
14512
14567
  clearRecordedData: function clearRecordedData() {
14513
14568
  signatureChunks = [];
14569
+ ondataavailableInvocations = [];
14570
+ ondataavailableStartTime = undefined;
14571
+ lastCalculatedVideoChunkRate = undefined;
14514
14572
  signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.stop();
14515
14573
  signatureRecorder = null;
14516
14574
  set({
@@ -14525,8 +14583,13 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14525
14583
  signatureStartedAt: undefined,
14526
14584
  signatureEndedAt: undefined,
14527
14585
  acceptClickedAt: undefined,
14586
+ // Note: clearClickedAt is intentionally preserved for telemetry metadata
14528
14587
  supportsRequestVideoFrameCallback: undefined,
14529
- supportsRoundRect: undefined
14588
+ supportsRoundRect: undefined,
14589
+ nullChunksReceived: 0,
14590
+ firstNullChunkReceivedAt: undefined,
14591
+ lastNullChunkReceivedAt: undefined,
14592
+ finalChunkReceived: false
14530
14593
  });
14531
14594
  }
14532
14595
  });
@@ -14536,11 +14599,11 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14536
14599
  * @param delayMs - The delay in milliseconds before the first check -- this is used to make sure we get at least one extra second of video.
14537
14600
  * @param checkEveryMs - The interval in milliseconds between checks after the initial delay has passed.
14538
14601
  * @param timeoutMs - The maximum time in milliseconds to wait for the chunk -- this is used to prevent infinite loops.
14539
- * @returns A promise that resolves when the delay has passed and at least one chunk has been received received.
14602
+ * @returns A promise that resolves when the delay has passed and at least one chunk has been received received. The return value is the number of milliseconds that we waited, whether we received a chunk, and whether we timed out.
14540
14603
  */
14541
14604
  function waitForOneMoreChunk(delayMs, checkEveryMs, timeoutMs) {
14542
14605
  if (delayMs === void 0) {
14543
- delayMs = 1000;
14606
+ delayMs = 250;
14544
14607
  }
14545
14608
  if (checkEveryMs === void 0) {
14546
14609
  checkEveryMs = 100;
@@ -14548,29 +14611,44 @@ function waitForOneMoreChunk(delayMs, checkEveryMs, timeoutMs) {
14548
14611
  if (timeoutMs === void 0) {
14549
14612
  timeoutMs = 3000;
14550
14613
  }
14551
- var start = performance.now();
14552
14614
  return new Promise(function (resolve) {
14553
- var initialLastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14554
- function gotAChunk() {
14615
+ var _a;
14616
+ var start = performance.now();
14617
+ var initialLastChunkReceivedAt = (_a = useVideoSignatureStore.getState().lastChunkReceivedAt) !== null && _a !== void 0 ? _a : start;
14618
+ signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14619
+ function checkForChunk() {
14555
14620
  var lastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14556
- return performance.now() - start > timeoutMs || !lastChunkReceivedAt || !initialLastChunkReceivedAt || lastChunkReceivedAt > initialLastChunkReceivedAt;
14621
+ var waitedMs = performance.now() - start;
14622
+ var timedOut = waitedMs > timeoutMs;
14623
+ var finalChunkReceived = !!lastChunkReceivedAt && !!initialLastChunkReceivedAt && lastChunkReceivedAt > initialLastChunkReceivedAt;
14624
+ return {
14625
+ waitedMs: waitedMs,
14626
+ finalChunkReceived: finalChunkReceived,
14627
+ timedOut: timedOut
14628
+ };
14557
14629
  }
14558
14630
  setTimeout(function () {
14559
- if (gotAChunk()) return resolve(); // check immediately
14631
+ // check immediately
14632
+ var result = checkForChunk();
14633
+ if (result.finalChunkReceived || result.timedOut) return resolve(result);
14560
14634
  // otherwise, check on a configured interval
14561
14635
  var interval = setInterval(function () {
14562
- if (gotAChunk()) {
14636
+ var result = checkForChunk();
14637
+ if (result.finalChunkReceived || result.timedOut) {
14563
14638
  clearInterval(interval);
14564
- resolve();
14639
+ resolve(result);
14565
14640
  }
14566
14641
  }, checkEveryMs);
14567
14642
  }, delayMs);
14568
14643
  });
14569
14644
  }
14570
14645
  function VideoSignatureContextProvider(_a) {
14571
- var _b, _c;
14572
14646
  var children = _a.children;
14573
- var videoRef = useCameraStore().videoRef;
14647
+ var _b = useCameraStore(),
14648
+ videoRef = _b.videoRef,
14649
+ videoWidth = _b.videoWidth,
14650
+ videoHeight = _b.videoHeight,
14651
+ releaseCameraAccess = _b.releaseCameraAccess;
14574
14652
  var outputCanvas = useRef(null);
14575
14653
  useEffect(function () {
14576
14654
  return useVideoSignatureStore.setState({
@@ -14578,18 +14656,13 @@ function VideoSignatureContextProvider(_a) {
14578
14656
  });
14579
14657
  }, []);
14580
14658
  var drawOutputFrame = useCallback(function () {
14581
- if (!outputCanvas.current || !videoRef.current) return;
14659
+ if (!outputCanvas.current) return;
14582
14660
  var ctx = outputCanvas.current.getContext('2d');
14583
14661
  if (!ctx) return;
14584
- var _a = [videoRef.current.videoWidth, videoRef.current.videoHeight],
14662
+ var _a = [outputCanvas.current.width, outputCanvas.current.height],
14585
14663
  w = _a[0],
14586
14664
  h = _a[1];
14587
14665
  var isPortrait = w < h;
14588
- // Only update canvas dimensions if they changed (setting dimensions clears the canvas!)
14589
- if (outputCanvas.current.width !== w || outputCanvas.current.height !== h) {
14590
- outputCanvas.current.width = w;
14591
- outputCanvas.current.height = h;
14592
- }
14593
14666
  var rect = [w * (isPortrait ? 0.02 : 0.15),
14594
14667
  // x
14595
14668
  h * (isPortrait ? 0.15 : 0.25),
@@ -14598,7 +14671,9 @@ function VideoSignatureContextProvider(_a) {
14598
14671
  // width
14599
14672
  h * (isPortrait ? 0.7 : 0.5) // height
14600
14673
  ];
14601
- ctx.drawImage(videoRef.current, 0, 0, w, h);
14674
+ if (videoRef.current) {
14675
+ ctx.drawImage(videoRef.current, 0, 0, w, h);
14676
+ }
14602
14677
  ctx.beginPath();
14603
14678
  ctx.fillStyle = 'rgba(255,255,255,0.5)';
14604
14679
  var supportsRoundRect = typeof ctx.roundRect === 'function';
@@ -14620,11 +14695,15 @@ function VideoSignatureContextProvider(_a) {
14620
14695
  ctx.drawImage.apply(ctx, __spreadArray([signatureCanvas], rect, false));
14621
14696
  }
14622
14697
  }, [videoRef]);
14623
- useVideoFrameLoop(videoRef, drawOutputFrame);
14698
+ var finalChunkReceived = useVideoSignatureStore().finalChunkReceived;
14699
+ useEffect(function () {
14700
+ if (finalChunkReceived) releaseCameraAccess();
14701
+ }, [finalChunkReceived, releaseCameraAccess]);
14702
+ useVideoFrameLoop(videoRef, drawOutputFrame, !finalChunkReceived);
14624
14703
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, children, /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
14625
14704
  ref: outputCanvas,
14626
- width: (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth,
14627
- height: (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.videoHeight
14705
+ width: videoWidth,
14706
+ height: videoHeight
14628
14707
  }));
14629
14708
  }
14630
14709
  function requestVideoFrameCallback(video, onFrame) {
@@ -14644,8 +14723,11 @@ function requestVideoFrameCallback(video, onFrame) {
14644
14723
  };
14645
14724
  }
14646
14725
  }
14647
- function videoFrameLoop(video, onFrame) {
14648
- if (!video) return;
14726
+ function videoFrameLoop(video, onFrame, running) {
14727
+ if (running === void 0) {
14728
+ running = true;
14729
+ }
14730
+ if (!video || !running) return;
14649
14731
  var cancelFn;
14650
14732
  var canceled = false;
14651
14733
  function onFrameRecursive() {
@@ -14666,10 +14748,51 @@ function videoFrameLoop(video, onFrame) {
14666
14748
  if (cancelFn !== undefined) cancelFn();
14667
14749
  };
14668
14750
  }
14669
- function useVideoFrameLoop(ref, onFrame) {
14751
+ function useVideoFrameLoop(ref, onFrame, running) {
14752
+ if (running === void 0) {
14753
+ running = true;
14754
+ }
14670
14755
  useEffect(function () {
14671
- return videoFrameLoop(ref.current, onFrame);
14672
- }, [onFrame, ref]);
14756
+ return videoFrameLoop(ref.current, onFrame, running);
14757
+ }, [onFrame, ref, running]);
14758
+ }
14759
+ function calculateAndStoreOndataavailableRate() {
14760
+ if (ondataavailableInvocations.length < 2 || !ondataavailableStartTime) {
14761
+ lastCalculatedVideoChunkRate = {
14762
+ averageRate: 0,
14763
+ minRate: 0,
14764
+ maxRate: 0,
14765
+ totalChunksReceived: ondataavailableInvocations.length,
14766
+ recordingDurationMs: 0
14767
+ };
14768
+ return;
14769
+ }
14770
+ var totalDuration = ondataavailableInvocations[ondataavailableInvocations.length - 1] - ondataavailableStartTime;
14771
+ var averageRate = (ondataavailableInvocations.length - 1) / (totalDuration / 1000); // invocations per second
14772
+ // Calculate rates for each interval between invocations
14773
+ var rates = [];
14774
+ for (var i = 1; i < ondataavailableInvocations.length; i++) {
14775
+ var intervalMs = ondataavailableInvocations[i] - ondataavailableInvocations[i - 1];
14776
+ var rate = 1000 / intervalMs; // invocations per second for this interval
14777
+ rates.push(rate);
14778
+ }
14779
+ var minRate = Math.min.apply(Math, rates);
14780
+ var maxRate = Math.max.apply(Math, rates);
14781
+ lastCalculatedVideoChunkRate = {
14782
+ averageRate: Math.round(averageRate * 100) / 100,
14783
+ // Round to 2 decimal places
14784
+ minRate: Math.round(minRate * 100) / 100,
14785
+ maxRate: Math.round(maxRate * 100) / 100,
14786
+ totalChunksReceived: ondataavailableInvocations.length,
14787
+ recordingDurationMs: Math.round(totalDuration)
14788
+ };
14789
+ }
14790
+ function trackVideoChunkRate(now) {
14791
+ // Track ondataavailable invocations for rate calculation
14792
+ ondataavailableStartTime !== null && ondataavailableStartTime !== void 0 ? ondataavailableStartTime : ondataavailableStartTime = now;
14793
+ ondataavailableInvocations.push(now);
14794
+ // Calculate and store the current rate
14795
+ calculateAndStoreOndataavailableRate();
14673
14796
  }
14674
14797
 
14675
14798
  function VideoSignaturePad(_a) {
@@ -15607,13 +15730,18 @@ function VideoSignatureWizardGuides(_a) {
15607
15730
  });
15608
15731
  }, []);
15609
15732
  var onClearBtnClicked = useCallback(function () {
15610
- var _a, _b;
15733
+ var _a;
15734
+ var _b = useVideoSignatureStore.getState(),
15735
+ timesSignatureCleared = _b.timesSignatureCleared,
15736
+ signaturePad = _b.signaturePad;
15611
15737
  useVideoSignatureStore.setState({
15738
+ clearClickedAt: performance.now(),
15739
+ timesSignatureCleared: timesSignatureCleared + 1,
15612
15740
  signatureStartedAt: undefined,
15613
15741
  signaturePadEmpty: true,
15614
15742
  signatureValid: false
15615
15743
  });
15616
- (_b = (_a = useVideoSignatureStore.getState().signaturePad) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.clear();
15744
+ (_a = signaturePad.current) === null || _a === void 0 ? void 0 : _a.clear();
15617
15745
  if (restartVideoOnSignaturePadCleared) {
15618
15746
  setTimeout(function () {
15619
15747
  useVideoSignatureStore.getState().clearRecordedData();
@@ -16002,6 +16130,13 @@ var useVideoRecorder = function useVideoRecorder(mergeAVStreams) {
16002
16130
  }, [audioRecordingIntentionallyStopped, audioRecordingStopped, audioUrl, isRecordingAudio, isRecordingVideo, videoRecordingIntentionallyStopped, videoRecordingStopped, videoUrl]);
16003
16131
  };
16004
16132
 
16133
+ var DEFAULT_CLASSNAMES = {};
16134
+ var DEFAULT_VERBIAGE = {};
16135
+ var VERBIAGE_FALLBACKS = {
16136
+ headingText: 'Please read the following text aloud',
16137
+ promptText: '',
16138
+ doneBtnText: 'Done'
16139
+ };
16005
16140
  var ReadTextPrompt = function ReadTextPrompt(_a) {
16006
16141
  var onComplete = _a.onComplete,
16007
16142
  _b = _a.durationMs,
@@ -16009,18 +16144,27 @@ var ReadTextPrompt = function ReadTextPrompt(_a) {
16009
16144
  _c = _a.minReadingMs,
16010
16145
  minReadingMs = _c === void 0 ? 10000 : _c,
16011
16146
  _d = _a.classNames,
16012
- classNames = _d === void 0 ? {} : _d,
16147
+ classNames = _d === void 0 ? DEFAULT_CLASSNAMES : _d,
16013
16148
  _e = _a.verbiage,
16014
- rawVerbiage = _e === void 0 ? {} : _e;
16149
+ rawVerbiage = _e === void 0 ? DEFAULT_VERBIAGE : _e,
16150
+ onPromptTextRendered = _a.onPromptTextRendered;
16015
16151
  var countdownTimeoutRef = useRef(undefined);
16016
16152
  var _f = useState(durationMs / 1000),
16017
16153
  countdownRemaining = _f[0],
16018
16154
  setCountdownRemaining = _f[1];
16019
- var verbiage = useTranslations(rawVerbiage, {
16020
- headingText: 'Please read the following text aloud',
16021
- promptText: '',
16022
- doneBtnText: 'Done'
16023
- });
16155
+ var promptTextRef = useRef(null);
16156
+ var verbiage = useTranslations(rawVerbiage, VERBIAGE_FALLBACKS);
16157
+ // Each time the rendered DOM contents changes for the prompt text,
16158
+ // notify the parent via callback so it can respond.
16159
+ // [NOTE]
16160
+ // This is a bit of a workaround for extracting the text of a react component.
16161
+ // Grabbing from the dom is not ideal but it works for now.
16162
+ // [TODO] Can this be pulled form the react tree instead?
16163
+ useEffect(function () {
16164
+ if (promptTextRef.current && onPromptTextRendered) {
16165
+ onPromptTextRendered(promptTextRef.current);
16166
+ }
16167
+ }, [onPromptTextRendered, verbiage.promptText]);
16024
16168
  var manualCountdown = useCallback(function (remainingTime) {
16025
16169
  if (remainingTime > 0) {
16026
16170
  var nextCycle_1 = remainingTime - 1;
@@ -16055,7 +16199,8 @@ var ReadTextPrompt = function ReadTextPrompt(_a) {
16055
16199
  }, /*#__PURE__*/React__default.createElement(ReadTextPromptHeading, {
16056
16200
  className: classNames.heading
16057
16201
  }, verbiage.headingText), /*#__PURE__*/React__default.createElement(ReadTextPromptText, {
16058
- className: classNames.prompt
16202
+ className: classNames.prompt,
16203
+ ref: promptTextRef
16059
16204
  }, verbiage.promptText), /*#__PURE__*/React__default.createElement(ReadTextPromptButtonsRow, {
16060
16205
  className: classNames.buttonsRow
16061
16206
  }, /*#__PURE__*/React__default.createElement(ReadTextPromptTimeRemaining, {
@@ -16101,8 +16246,101 @@ var ReadTextPromptTimeRemaining = styled.div(templateObject_5$1 || (templateObje
16101
16246
  return ((_c = (_b = (_a = props.theme.idVideoCapture) === null || _a === void 0 ? void 0 : _a.readTextPrompt) === null || _b === void 0 ? void 0 : _b.timeRemaining) === null || _c === void 0 ? void 0 : _c.borderRadius) ? "border-radius: ".concat((_f = (_e = (_d = props.theme.idVideoCapture) === null || _d === void 0 ? void 0 : _d.readTextPrompt) === null || _e === void 0 ? void 0 : _e.timeRemaining) === null || _f === void 0 ? void 0 : _f.borderRadius, ";") : "";
16102
16247
  });
16103
16248
  var DoneButton = styled(LoaderButton)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n margin: auto 0;\n"], ["\n margin: auto 0;\n"])));
16249
+ var ReadTextPromptWrapped = /*#__PURE__*/memo(ReadTextPrompt);
16104
16250
  var templateObject_1$6, templateObject_2$6, templateObject_3$5, templateObject_4$1, templateObject_5$1, templateObject_6;
16105
16251
 
16252
+ // Precompiled regexes for performance and clarity
16253
+ var RE_ESCAPE_N = /\\n/g;
16254
+ var RE_ESCAPE_T = /\\t/g;
16255
+ var RE_ESCAPE_R = /\\r/g;
16256
+ // Remove entire script/style blocks before anything else
16257
+ var RE_SCRIPT_BLOCK = /<script[\s\S]*?<\/script>/gi;
16258
+ var RE_STYLE_BLOCK = /<style[\s\S]*?<\/style>/gi;
16259
+ // Replace common block-level tags with spaces to preserve boundaries
16260
+ var RE_BLOCK_OPEN = /<(div|p|h[1-6]|li|ul|ol|blockquote|pre|section|article|header|footer|aside|nav|main|form|fieldset|table|tr|td|th|br)[^>]*>/gi;
16261
+ var RE_BLOCK_CLOSE = /<\/(div|p|h[1-6]|li|ul|ol|blockquote|pre|section|article|header|footer|aside|nav|main|form|fieldset|table|tr|td|th|br)>/gi;
16262
+ // Any remaining HTML tag
16263
+ var RE_ALL_TAGS = /<[^>]*>/g;
16264
+ // Numeric entities (be lenient on optional semicolon)
16265
+ var RE_NUM_DEC = /&#(\d+);?/g;
16266
+ var RE_NUM_HEX = /&#x([0-9a-f]+);?/gi;
16267
+ // Invisible/whitespace variants
16268
+ var RE_NBSP_CHAR = /\u00A0/g;
16269
+ var RE_ZERO_WIDTH = /[\u200B-\u200D\uFEFF]/g;
16270
+ // Named entities map; case-insensitive replacement will be applied
16271
+ var NAMED_ENTITIES = {
16272
+ nbsp: ' ',
16273
+ amp: '&',
16274
+ lt: '<',
16275
+ gt: '>',
16276
+ quot: '"',
16277
+ '#39': "'",
16278
+ // some encoders output &#39; but handle via numeric too
16279
+ apos: "'",
16280
+ cent: '¢',
16281
+ pound: '£',
16282
+ yen: '¥',
16283
+ euro: '€',
16284
+ copy: '©',
16285
+ reg: '®',
16286
+ mdash: '—',
16287
+ ndash: '–',
16288
+ hellip: '…',
16289
+ ldquo: '"',
16290
+ rdquo: '"',
16291
+ lsquo: "'",
16292
+ rsquo: "'"
16293
+ };
16294
+ function decodeNamedEntities(input) {
16295
+ return input.replace(/&([a-z#0-9]+);/gi, function (_, name) {
16296
+ var key = name.toLowerCase();
16297
+ if (Object.prototype.hasOwnProperty.call(NAMED_ENTITIES, key)) {
16298
+ return NAMED_ENTITIES[key];
16299
+ }
16300
+ return "&".concat(name, ";");
16301
+ });
16302
+ }
16303
+ function getRawTextFromHtml(str) {
16304
+ if (!str) return '';
16305
+ var s = str;
16306
+ // 1) Handle literal escape sequences (avoid confusing with HTML)
16307
+ s = s.replace(RE_ESCAPE_N, ' ').replace(RE_ESCAPE_T, ' ').replace(RE_ESCAPE_R, ' ');
16308
+ // 2) Remove script/style blocks entirely
16309
+ s = s.replace(RE_SCRIPT_BLOCK, ' ').replace(RE_STYLE_BLOCK, ' ');
16310
+ // 3) Replace block-level elements with spaces, then strip remaining tags
16311
+ s = s.replace(RE_BLOCK_OPEN, ' ').replace(RE_BLOCK_CLOSE, ' ');
16312
+ s = s.replace(RE_ALL_TAGS, '');
16313
+ // 4) Decode numeric entities using code points (handles >0xFFFF)
16314
+ s = s.replace(RE_NUM_DEC, function (_, dec) {
16315
+ var codePoint = parseInt(dec, 10);
16316
+ if (Number.isFinite(codePoint) && codePoint >= 0) {
16317
+ try {
16318
+ return String.fromCodePoint(codePoint);
16319
+ } catch (_a) {
16320
+ return '';
16321
+ }
16322
+ }
16323
+ return '';
16324
+ }).replace(RE_NUM_HEX, function (_, hex) {
16325
+ var codePoint = parseInt(hex, 16);
16326
+ if (Number.isFinite(codePoint) && codePoint >= 0) {
16327
+ try {
16328
+ return String.fromCodePoint(codePoint);
16329
+ } catch (_a) {
16330
+ return '';
16331
+ }
16332
+ }
16333
+ return '';
16334
+ });
16335
+ // 5) Decode common named entities (case-insensitive)
16336
+ s = decodeNamedEntities(s);
16337
+ // 6) Replace Unicode NBSP and remove zero-width characters
16338
+ s = s.replace(RE_NBSP_CHAR, ' ').replace(RE_ZERO_WIDTH, '');
16339
+ // 7) Normalize whitespace
16340
+ s = s.replace(/\s+/g, ' ').trim();
16341
+ return s;
16342
+ }
16343
+
16106
16344
  var edgeBoundary = 0.05;
16107
16345
  var defaultVideoIdCaptureThresholds = {
16108
16346
  detection: {
@@ -16333,18 +16571,22 @@ var IdVideoCapture = function IdVideoCapture(_a) {
16333
16571
  }, [goodFramesCount]);
16334
16572
  var delaySatisfied = !['SHOW_ID_FRONT', 'SHOW_PASSPORT'].includes(requestedAction) || idFrontCaptureStartedAt !== null && new Date().getTime() > idFrontCaptureStartedAt + idCardFrontDelay;
16335
16573
  var translatedText = useVerbiage(readTextPrompt, '');
16574
+ var handlePromptTextRendered = useCallback(function (element) {
16575
+ if (element) {
16576
+ var rawText = getRawTextFromHtml(element.innerHTML);
16577
+ setExpectedAudioText(rawText);
16578
+ }
16579
+ }, [setExpectedAudioText]);
16336
16580
  var onIdCaptureComplete = useCallback(function () {
16337
16581
  var _a;
16338
16582
  if (translatedText) {
16339
16583
  setRequestedAction('READ_TEXT');
16340
16584
  useVideoRecorderStore.getState().startRecordingAudio();
16341
16585
  setIdCaptureVideoAudioStartsAt(new Date().getTime() - ((_a = videoStartsAt === null || videoStartsAt === void 0 ? void 0 : videoStartsAt.getTime()) !== null && _a !== void 0 ? _a : 0));
16342
- var renderedTranslatedText = typeof translatedText === 'string' ? translatedText : renderToString(translatedText);
16343
- setExpectedAudioText(renderedTranslatedText);
16344
16586
  } else {
16345
16587
  useVideoRecorderStore.getState().stopRecordingVideo();
16346
16588
  }
16347
- }, [setExpectedAudioText, setIdCaptureVideoAudioStartsAt, translatedText, videoStartsAt]);
16589
+ }, [setIdCaptureVideoAudioStartsAt, translatedText, videoStartsAt]);
16348
16590
  var frameWidth = (_c = (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) !== null && _c !== void 0 ? _c : 0;
16349
16591
  var frameHeight = (_e = (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) !== null && _e !== void 0 ? _e : 0;
16350
16592
  var faceBox = face === null || face === void 0 ? void 0 : face.box;
@@ -16502,13 +16744,14 @@ var IdVideoCapture = function IdVideoCapture(_a) {
16502
16744
  className: classNames.container
16503
16745
  }, /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
16504
16746
  ref: photoCanvas
16505
- }), requestedAction === 'READ_TEXT' ? ( /*#__PURE__*/React__default.createElement(ReadTextPrompt, {
16747
+ }), requestedAction === 'READ_TEXT' ? ( /*#__PURE__*/React__default.createElement(ReadTextPromptWrapped, {
16506
16748
  startedAt: timeoutStartedAt || undefined,
16507
16749
  durationMs: readTextTimeoutDurationMs,
16508
16750
  minReadingMs: readTextMinReadingMs,
16509
16751
  classNames: classNames.readTextPrompt,
16510
16752
  verbiage: readTextPromptVerbiage,
16511
- onComplete: stopRecording
16753
+ onComplete: stopRecording,
16754
+ onPromptTextRendered: handlePromptTextRendered
16512
16755
  })) : ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IdVideoCaptureGuides, {
16513
16756
  classNames: classNames.guides,
16514
16757
  verbiage: rawVerbiage.guides,