@microblink/blinkid-ux-manager 7.2.2 → 7.3.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.
@@ -817,9 +817,15 @@ class BlinkIdUxManager {
817
817
  #successProcessResult;
818
818
  #threadBusy = false;
819
819
  #timeoutId;
820
- /** Timeout duration in ms */
820
+ /** Timeout duration in ms for the scanning session. If null, timeout won't be triggered ever. */
821
821
  #timeoutDuration = 1e4;
822
822
  // 10s
823
+ /** Time in ms before the help tooltip is shown. If null, tooltip won't be auto shown. */
824
+ #helpTooltipShowDelay = 5e3;
825
+ // 5s
826
+ /** Time in ms before the help tooltip is hidden. If null, tooltip won't be auto hidden. */
827
+ #helpTooltipHideDelay = 5e3;
828
+ // 5s
823
829
  #onUiStateChangedCallbacks = /* @__PURE__ */ new Set();
824
830
  #onResultCallbacks = /* @__PURE__ */ new Set();
825
831
  #onFrameProcessCallbacks = /* @__PURE__ */ new Set();
@@ -847,6 +853,9 @@ class BlinkIdUxManager {
847
853
  (s2) => s2.playbackState,
848
854
  (playbackState) => {
849
855
  console.debug(`⏯️ ${playbackState}`);
856
+ if (this.#timeoutDuration === null) {
857
+ return;
858
+ }
850
859
  if (playbackState !== "capturing") {
851
860
  this.clearScanTimeout();
852
861
  } else {
@@ -880,6 +889,27 @@ class BlinkIdUxManager {
880
889
  getShowProductionOverlay() {
881
890
  return this.showProductionOverlay;
882
891
  }
892
+ /**
893
+ * Returns the timeout duration in ms. Null if timeout won't be triggered ever.
894
+ * @returns The timeout duration in ms.
895
+ */
896
+ getTimeoutDuration() {
897
+ return this.#timeoutDuration;
898
+ }
899
+ /**
900
+ * Returns the time in ms before the help tooltip is shown. Null if tooltip won't be auto shown.
901
+ * @returns The time in ms before the help tooltip is shown.
902
+ */
903
+ getHelpTooltipShowDelay() {
904
+ return this.#helpTooltipShowDelay;
905
+ }
906
+ /**
907
+ * Returns the time in ms before the help tooltip is hidden. Null if tooltip won't be auto hidden.
908
+ * @returns The time in ms before the help tooltip is hidden.
909
+ */
910
+ getHelpTooltipHideDelay() {
911
+ return this.#helpTooltipHideDelay;
912
+ }
883
913
  /**
884
914
  * Adds a callback function to be executed when the UI state changes.
885
915
  * @param callback - Function to be called when UI state changes. Receives the new UI state as parameter.
@@ -1058,15 +1088,55 @@ class BlinkIdUxManager {
1058
1088
  return processResult.arrayBuffer;
1059
1089
  };
1060
1090
  /**
1061
- * Set the duration of the timeout in milliseconds.
1091
+ * Sets the duration after which the scanning session will timeout. The timeout can occur in various scenarios
1092
+ * and may be restarted by different scanning events.
1093
+ *
1094
+ * @param duration The timeout duration in milliseconds. If null, timeout won't be triggered ever.
1095
+ * @param setHelpTooltipShowDelay If true, also sets the help tooltip show delay to half of the provided duration. If timeout duration is null, help tooltip show delay will be set to null. Defaults to true.
1096
+ * @throws {Error} Throws an error if duration is less than or equal to 0 when not null.
1062
1097
  */
1063
- setTimeoutDuration(duration) {
1098
+ setTimeoutDuration(duration, setHelpTooltipShowDelay = true) {
1099
+ if (duration !== null && duration <= 0) {
1100
+ throw new Error("Timeout duration must be greater than 0");
1101
+ }
1064
1102
  this.#timeoutDuration = duration;
1103
+ if (setHelpTooltipShowDelay) {
1104
+ this.setHelpTooltipShowDelay(duration !== null ? duration / 2 : null);
1105
+ }
1106
+ }
1107
+ /**
1108
+ * Sets the duration in milliseconds before the help tooltip is shown.
1109
+ * A value of null means the help tooltip will not be auto shown.
1110
+ * @param duration The duration in milliseconds before the help tooltip is shown. If null, tooltip won't be auto shown.
1111
+ * @throws {Error} Throws an error if duration is less than or equal to 0 when not null.
1112
+ */
1113
+ setHelpTooltipShowDelay(duration) {
1114
+ if (duration !== null && duration <= 0) {
1115
+ throw new Error("Help tooltip show delay must be greater than 0");
1116
+ }
1117
+ this.#helpTooltipShowDelay = duration;
1118
+ }
1119
+ /**
1120
+ * Sets the duration in milliseconds before the help tooltip is hidden.
1121
+ * A value of null means the help tooltip will not be auto hidden.
1122
+ * @param duration The duration in milliseconds before the help tooltip is hidden. If null, tooltip won't be auto hidden.
1123
+ * @throws {Error} Throws an error if duration is less than or equal to 0 when not null.
1124
+ */
1125
+ setHelpTooltipHideDelay(duration) {
1126
+ if (duration !== null && duration <= 0) {
1127
+ throw new Error("Help tooltip display duration must be greater than 0");
1128
+ }
1129
+ this.#helpTooltipHideDelay = duration;
1065
1130
  }
1066
1131
  #setTimeout = (uiState) => {
1132
+ if (this.#timeoutDuration === null) {
1133
+ console.debug("⏳🟢 timeout duration is null, not starting timeout");
1134
+ return;
1135
+ }
1067
1136
  this.clearScanTimeout();
1068
1137
  console.debug(`⏳🟢 starting timeout for ${uiState.key}`);
1069
1138
  this.#timeoutId = window.setTimeout(() => {
1139
+ console.debug("⏳🟢 timeout triggered");
1070
1140
  this.cameraManager.stopFrameCapture();
1071
1141
  this.#invokeOnErrorCallbacks("timeout");
1072
1142
  this.feedbackStabilizer.reset();
@@ -1092,7 +1162,9 @@ class BlinkIdUxManager {
1092
1162
  };
1093
1163
  // Side-effects are handled here
1094
1164
  #handleUiStateChange = async (uiState) => {
1095
- this.#setTimeout(uiState);
1165
+ if (this.#timeoutDuration !== null) {
1166
+ this.#setTimeout(uiState);
1167
+ }
1096
1168
  if (firstSideCapturedStates.includes(uiState.key)) {
1097
1169
  this.cameraManager.stopFrameCapture();
1098
1170
  await sleep(
@@ -1123,6 +1195,9 @@ class BlinkIdUxManager {
1123
1195
  * Clears any active timeout.
1124
1196
  */
1125
1197
  clearScanTimeout = () => {
1198
+ if (!this.#timeoutId) {
1199
+ return;
1200
+ }
1126
1201
  console.debug("⏳🔴 clearing timeout");
1127
1202
  window.clearTimeout(this.#timeoutId);
1128
1203
  };
@@ -2453,13 +2528,6 @@ const UiFeedbackOverlay = (props) => {
2453
2528
  get children() {
2454
2529
  return createComponent(SuccessFeedback, {});
2455
2530
  }
2456
- }), createComponent(Match, {
2457
- get when() {
2458
- return props.uiState.reticleType === "done" || showSuccessOnly();
2459
- },
2460
- get children() {
2461
- return createComponent(SuccessFeedback, {});
2462
- }
2463
2531
  }), createComponent(Match, {
2464
2532
  get when() {
2465
2533
  return memo(() => props.uiState.reticleType === "flip")() && !showSuccessOnly();
@@ -2805,6 +2873,7 @@ const BlinkIdUiStoreProvider = (props) => {
2805
2873
  cameraManagerComponent: props.cameraManagerComponent,
2806
2874
  showOnboardingGuide: props.showOnboardingGuide,
2807
2875
  showHelpTooltipTimeout: props.showHelpTooltipTimeout,
2876
+ showHelpButton: props.showHelpButton,
2808
2877
  dismountFeedbackUi: props.dismountFeedbackUi
2809
2878
  /* eslint-enable solid/reactivity */
2810
2879
  });
@@ -3362,26 +3431,47 @@ const HelpButton = (props) => {
3362
3431
  updateStore
3363
3432
  } = useBlinkIdUiStore();
3364
3433
  const [tooltipOpen, setTooltipOpen] = createSignal(false);
3365
- let timeoutId;
3366
- onCleanup(() => {
3367
- if (timeoutId !== void 0) {
3368
- window.clearTimeout(timeoutId);
3434
+ const [wasAutoShown, setWasAutoShown] = createSignal(false);
3435
+ let showTooltipTimeoutId;
3436
+ let hideTooltipTimeoutId;
3437
+ const clearTimeouts = () => {
3438
+ if (showTooltipTimeoutId !== void 0) {
3439
+ window.clearTimeout(showTooltipTimeoutId);
3440
+ showTooltipTimeoutId = void 0;
3441
+ }
3442
+ if (hideTooltipTimeoutId !== void 0) {
3443
+ window.clearTimeout(hideTooltipTimeoutId);
3444
+ hideTooltipTimeoutId = void 0;
3369
3445
  }
3370
- });
3446
+ };
3447
+ const scheduleAutoHide = () => {
3448
+ const displayDuration = store.blinkIdUxManager.getHelpTooltipHideDelay();
3449
+ if (displayDuration && displayDuration > 0) {
3450
+ hideTooltipTimeoutId = window.setTimeout(() => {
3451
+ setTooltipOpen(false);
3452
+ }, displayDuration);
3453
+ }
3454
+ };
3455
+ const showTooltipAutomatically = () => {
3456
+ const timeout = store.blinkIdUxManager.getHelpTooltipShowDelay();
3457
+ if (timeout && timeout > 0) {
3458
+ showTooltipTimeoutId = window.setTimeout(() => {
3459
+ setTooltipOpen(true);
3460
+ setWasAutoShown(true);
3461
+ scheduleAutoHide();
3462
+ }, timeout);
3463
+ }
3464
+ };
3465
+ onCleanup(clearTimeouts);
3371
3466
  createEffect(() => {
3372
- if (timeoutId !== void 0) {
3373
- window.clearTimeout(timeoutId);
3374
- timeoutId = void 0;
3467
+ if (!props.isProcessing) {
3468
+ setTooltipOpen(false);
3469
+ setWasAutoShown(false);
3470
+ clearTimeouts();
3471
+ return;
3375
3472
  }
3376
- if (props.isProcessing && !tooltipOpen()) {
3377
- const {
3378
- showHelpTooltipTimeout
3379
- } = store;
3380
- if (showHelpTooltipTimeout && showHelpTooltipTimeout > 0) {
3381
- timeoutId = window.setTimeout(() => {
3382
- setTooltipOpen(true);
3383
- }, showHelpTooltipTimeout);
3384
- }
3473
+ if (!tooltipOpen() && !wasAutoShown()) {
3474
+ showTooltipAutomatically();
3385
3475
  }
3386
3476
  });
3387
3477
  return createComponent(Tooltip.Root, {
@@ -3396,6 +3486,7 @@ const HelpButton = (props) => {
3396
3486
  onOpenChange: (details) => setTooltipOpen(details.open),
3397
3487
  get children() {
3398
3488
  return [createComponent(Tooltip.Trigger, {
3489
+ part: "help-button-part",
3399
3490
  get ["aria-label"]() {
3400
3491
  return t2.help_aria_label;
3401
3492
  },
@@ -3411,6 +3502,7 @@ const HelpButton = (props) => {
3411
3502
  }), createComponent(Tooltip.Positioner, {
3412
3503
  get children() {
3413
3504
  return createComponent(Tooltip.Content, {
3505
+ part: "help-button-tooltip-part",
3414
3506
  get ["class"]() {
3415
3507
  return styles$1.tooltip;
3416
3508
  },
@@ -3634,9 +3726,16 @@ const BlinkIdFeedbackUi = (props) => {
3634
3726
  effect(() => className(_el$4, styles.microblinkOverlay));
3635
3727
  return _el$4;
3636
3728
  }
3637
- }), createComponent(HelpButton, {
3638
- get isProcessing() {
3639
- return isProcessing();
3729
+ }), createComponent(Show, {
3730
+ get when() {
3731
+ return store.showHelpButton;
3732
+ },
3733
+ get children() {
3734
+ return createComponent(HelpButton, {
3735
+ get isProcessing() {
3736
+ return isProcessing();
3737
+ }
3738
+ });
3640
3739
  }
3641
3740
  })];
3642
3741
  }
@@ -3651,7 +3750,7 @@ function createBlinkIdFeedbackUi(blinkIdUxManager, cameraManagerComponent, {
3651
3750
  // todo - implement this
3652
3751
  preserveSdkInstance,
3653
3752
  showOnboardingGuide = true,
3654
- showHelpTooltipTimeout = 8e3
3753
+ showHelpButton = true
3655
3754
  } = {}) {
3656
3755
  const dismountFeedbackUiRef = {
3657
3756
  current: () => {
@@ -3664,7 +3763,7 @@ function createBlinkIdFeedbackUi(blinkIdUxManager, cameraManagerComponent, {
3664
3763
  blinkIdUxManager,
3665
3764
  cameraManagerComponent,
3666
3765
  showOnboardingGuide,
3667
- showHelpTooltipTimeout,
3766
+ showHelpButton,
3668
3767
  dismountFeedbackUi: () => dismountFeedbackUiRef.current(),
3669
3768
  get children() {
3670
3769
  return createComponent(BlinkIdFeedbackUi, {