@microblink/blinkid-ux-manager 7.4.0 → 7.4.1

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.
@@ -939,18 +939,18 @@ class BlinkIdUxManager {
939
939
  }
940
940
  }
941
941
  );
942
- const unsubscribeVideoObserver = cameraManager.subscribe(
942
+ const unsubscribeVideoObserver = this.cameraManager.subscribe(
943
943
  (s2) => s2.videoElement,
944
944
  (videoElement) => {
945
945
  if (!videoElement) {
946
- console.debug("Removing timeout subscriptions");
946
+ console.debug("Removing camera manager subscriptions");
947
947
  this.reset();
948
948
  unsubscribeVideoObserver();
949
949
  unsubscribePlaybackState();
950
950
  }
951
951
  }
952
952
  );
953
- cameraManager.addFrameCaptureCallback(this.#frameCaptureCallback);
953
+ this.cameraManager.addFrameCaptureCallback(this.#frameCaptureCallback);
954
954
  }
955
955
  /**
956
956
  * Indicates whether the UI should display the demo overlay. Controlled by the
@@ -1184,6 +1184,26 @@ class BlinkIdUxManager {
1184
1184
  }
1185
1185
  }
1186
1186
  };
1187
+ /**
1188
+ * Handles document class filtering if configured.
1189
+ * Returns true if the document should be processed, false if it was filtered out.
1190
+ *
1191
+ * @param processResult - The result of processing the current frame
1192
+ * @returns boolean indicating if the document should be processed
1193
+ */
1194
+ #handleDocumentClassFiltering(processResult) {
1195
+ if (this.#documentClassFilter === void 0) {
1196
+ return true;
1197
+ }
1198
+ const documentClassInfo = this.#extractDocumentClassInfo(processResult);
1199
+ if (!this.#isDocumentClassified(documentClassInfo) || this.#documentClassFilter(documentClassInfo)) {
1200
+ return true;
1201
+ }
1202
+ this.cameraManager.stopFrameCapture();
1203
+ this.#invokeOnDocumentFilteredCallbacks(documentClassInfo);
1204
+ this.#invokeOnFrameProcessCallbacks(processResult);
1205
+ return false;
1206
+ }
1187
1207
  /**
1188
1208
  * The frame capture callback. This is the main function that is called when a
1189
1209
  * new frame is captured. It is responsible for processing the frame and
@@ -1213,11 +1233,8 @@ class BlinkIdUxManager {
1213
1233
  }
1214
1234
  const processResult = await this.scanningSession.process(imageDataLike);
1215
1235
  this.#threadBusy = false;
1216
- if (this.#documentClassFilter !== void 0) {
1217
- const documentClassInfo = this.#extractDocumentClassInfo(processResult);
1218
- if (this.#isDocumentClassified(documentClassInfo) && !this.#documentClassFilter(documentClassInfo)) {
1219
- this.#invokeOnDocumentFilteredCallbacks(documentClassInfo);
1220
- }
1236
+ if (!this.#handleDocumentClassFiltering(processResult)) {
1237
+ return processResult.arrayBuffer;
1221
1238
  }
1222
1239
  this.#handleUiStateChanges(processResult);
1223
1240
  this.#invokeOnFrameProcessCallbacks(processResult);
@@ -1290,8 +1307,7 @@ class BlinkIdUxManager {
1290
1307
  console.debug("⏳🟢 timeout triggered");
1291
1308
  this.cameraManager.stopFrameCapture();
1292
1309
  this.#invokeOnErrorCallbacks("timeout");
1293
- this.feedbackStabilizer.reset();
1294
- this.uiState = this.feedbackStabilizer.currentState;
1310
+ this.#resetUiState();
1295
1311
  }, this.#timeoutDuration);
1296
1312
  };
1297
1313
  /**
@@ -1368,6 +1384,14 @@ class BlinkIdUxManager {
1368
1384
  #isDocumentClassified(documentClassInfo) {
1369
1385
  return documentClassInfo?.country !== void 0 && documentClassInfo?.type !== void 0;
1370
1386
  }
1387
+ /**
1388
+ * Resets the feedback stabilizer and invokes the onUiStateChanged callbacks.
1389
+ */
1390
+ #resetUiState = () => {
1391
+ this.feedbackStabilizer.reset();
1392
+ this.uiState = this.feedbackStabilizer.currentState;
1393
+ this.#invokeOnUiStateChangedCallbacks(this.uiState);
1394
+ };
1371
1395
  /**
1372
1396
  * Clears the scanning session timeout.
1373
1397
  */
@@ -1379,11 +1403,31 @@ class BlinkIdUxManager {
1379
1403
  window.clearTimeout(this.#timeoutId);
1380
1404
  };
1381
1405
  /**
1382
- * Resets the BlinkIdUxManager.
1406
+ * Resets the scanning session.
1407
+ *
1408
+ * @param startFrameCapture Whether to start frame processing.
1409
+ */
1410
+ async resetScanningSession(startFrameCapture = true) {
1411
+ console.debug("🔁 Resetting scanning session");
1412
+ this.clearScanTimeout();
1413
+ this.#threadBusy = false;
1414
+ this.#successProcessResult = void 0;
1415
+ this.#resetUiState();
1416
+ await this.scanningSession.reset();
1417
+ if (startFrameCapture) {
1418
+ if (!this.cameraManager.isActive) {
1419
+ await this.cameraManager.startCameraStream();
1420
+ }
1421
+ await this.cameraManager.startFrameCapture();
1422
+ }
1423
+ }
1424
+ /**
1425
+ * Resets the BlinkIdUxManager. Clears all callbacks.
1383
1426
  *
1384
1427
  * Does not reset the camera manager or the scanning session.
1385
1428
  */
1386
1429
  reset() {
1430
+ console.debug("🔁 Resetting BlinkIdUxManager");
1387
1431
  this.clearScanTimeout();
1388
1432
  this.#threadBusy = false;
1389
1433
  this.#successProcessResult = void 0;
@@ -3051,6 +3095,9 @@ const BlinkIdUiStoreProvider = (props) => {
3051
3095
  showOnboardingGuide: props.showOnboardingGuide,
3052
3096
  showHelpTooltipTimeout: props.showHelpTooltipTimeout,
3053
3097
  showHelpButton: props.showHelpButton,
3098
+ showDocumentFilteredModal: props.showDocumentFilteredModal,
3099
+ showTimeoutModal: props.showTimeoutModal,
3100
+ showUnsupportedDocumentModal: props.showUnsupportedDocumentModal,
3054
3101
  dismountFeedbackUi: props.dismountFeedbackUi
3055
3102
  /* eslint-enable solid/reactivity */
3056
3103
  });
@@ -3709,7 +3756,8 @@ const ErrorModal = (props) => {
3709
3756
  } = useBlinkIdUiStore();
3710
3757
  const hideModal = () => {
3711
3758
  updateStore({
3712
- errorState: void 0
3759
+ errorState: void 0,
3760
+ documentFiltered: false
3713
3761
  });
3714
3762
  };
3715
3763
  const dismountCameraManagerUi = () => {
@@ -3718,7 +3766,7 @@ const ErrorModal = (props) => {
3718
3766
  const handlePrimaryClick = async () => {
3719
3767
  hideModal();
3720
3768
  if (props.shouldResetScanningSession) {
3721
- await store.blinkIdUxManager.scanningSession.reset();
3769
+ await store.blinkIdUxManager.resetScanningSession(false);
3722
3770
  }
3723
3771
  await store.blinkIdUxManager.cameraManager.startFrameCapture();
3724
3772
  };
@@ -3777,13 +3825,12 @@ const BlinkIdFeedbackUi = (props) => {
3777
3825
  onCleanup(() => errorCallbackCleanup());
3778
3826
  });
3779
3827
  createEffect(() => {
3780
- const errorCallbackCleanup = store.blinkIdUxManager.addOnDocumentFilteredCallback((_2) => {
3781
- store.blinkIdUxManager.cameraManager.stopFrameCapture();
3828
+ const documentFilteredCallbackCleanup = store.blinkIdUxManager.addOnDocumentFilteredCallback((_2) => {
3782
3829
  updateStore({
3783
3830
  documentFiltered: true
3784
3831
  });
3785
3832
  });
3786
- onCleanup(() => errorCallbackCleanup());
3833
+ onCleanup(() => documentFilteredCallbackCleanup());
3787
3834
  });
3788
3835
  const playbackState = createWithSignal(cameraManagerStore)((s2) => s2.playbackState);
3789
3836
  const isProcessing = () => playbackState() === "capturing";
@@ -3823,7 +3870,7 @@ const BlinkIdFeedbackUi = (props) => {
3823
3870
  get children() {
3824
3871
  return [createComponent(Match, {
3825
3872
  get when() {
3826
- return store.errorState === "timeout";
3873
+ return store.showTimeoutModal && store.errorState === "timeout";
3827
3874
  },
3828
3875
  get children() {
3829
3876
  return createComponent(ErrorModal, {
@@ -3838,7 +3885,7 @@ const BlinkIdFeedbackUi = (props) => {
3838
3885
  }
3839
3886
  }), createComponent(Match, {
3840
3887
  get when() {
3841
- return uiState().key === "UNSUPPORTED_DOCUMENT";
3888
+ return memo(() => !!store.showUnsupportedDocumentModal)() && uiState().key === "UNSUPPORTED_DOCUMENT";
3842
3889
  },
3843
3890
  get children() {
3844
3891
  return createComponent(ErrorModal, {
@@ -3853,7 +3900,7 @@ const BlinkIdFeedbackUi = (props) => {
3853
3900
  }
3854
3901
  }), createComponent(Match, {
3855
3902
  get when() {
3856
- return store.documentFiltered;
3903
+ return store.showDocumentFilteredModal && store.documentFiltered;
3857
3904
  },
3858
3905
  get children() {
3859
3906
  return createComponent(ErrorModal, {
@@ -3927,7 +3974,10 @@ function createBlinkIdFeedbackUi(blinkIdUxManager, cameraManagerComponent, {
3927
3974
  // todo - implement this
3928
3975
  preserveSdkInstance,
3929
3976
  showOnboardingGuide = true,
3930
- showHelpButton = true
3977
+ showHelpButton = true,
3978
+ showDocumentFilteredModal = true,
3979
+ showTimeoutModal = true,
3980
+ showUnsupportedDocumentModal = true
3931
3981
  } = {}) {
3932
3982
  const dismountFeedbackUiRef = {
3933
3983
  current: () => {
@@ -3941,6 +3991,9 @@ function createBlinkIdFeedbackUi(blinkIdUxManager, cameraManagerComponent, {
3941
3991
  cameraManagerComponent,
3942
3992
  showOnboardingGuide,
3943
3993
  showHelpButton,
3994
+ showDocumentFilteredModal,
3995
+ showTimeoutModal,
3996
+ showUnsupportedDocumentModal,
3944
3997
  dismountFeedbackUi: () => dismountFeedbackUiRef.current(),
3945
3998
  get children() {
3946
3999
  return createComponent(BlinkIdFeedbackUi, {