scandoc-ai-components 0.0.99 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +50 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11180,8 +11180,7 @@ class ExtractorVideo {
11180
11180
  },
11181
11181
  height: {
11182
11182
  ideal: 1080
11183
- },
11184
- facingMode: "environment"
11183
+ }
11185
11184
  });
11186
11185
  constructor(onExtractedResults) {
11187
11186
  this.candidateImages = [];
@@ -11358,22 +11357,47 @@ class ExtractorVideo {
11358
11357
  this.video = videoElem;
11359
11358
  this.isRunning = true;
11360
11359
  this.scanStartTime = Date.now();
11360
+ const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
11361
+ const mode = cfgValues.VIDEO_FACING_MODE ?? "environment";
11361
11362
  const devices = await navigator.mediaDevices.enumerateDevices();
11362
11363
  const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
11363
- const cameras = await checkAutofocusSupport(environmentCameras);
11364
11364
  let deviceId;
11365
- if (cameras.length > 0) {
11366
- deviceId = cameras[0].deviceId;
11365
+ if (mode === "environment") {
11366
+ const af = await checkAutofocusSupport(environmentCameras);
11367
+ deviceId = af[0]?.deviceId || environmentCameras[0]?.deviceId;
11367
11368
  }
11368
- const userMediaConstraints = {
11369
- ...ExtractorVideo.VIDEO_SETTINGS
11369
+ const buildConstraints = () => {
11370
+ const base = {
11371
+ ...ExtractorVideo.VIDEO_SETTINGS
11372
+ };
11373
+ if (typeof mode === "string") {
11374
+ base.facingMode = {
11375
+ ideal: mode
11376
+ }; // "environment" | "user"
11377
+ } else if (mode && typeof mode === "object") {
11378
+ base.facingMode = mode; // e.g. { exact: "user" }
11379
+ } else {
11380
+ base.facingMode = {
11381
+ ideal: "environment"
11382
+ };
11383
+ }
11384
+ if (mode === "environment" && deviceId) {
11385
+ base.deviceId = {
11386
+ exact: deviceId
11387
+ };
11388
+ }
11389
+ return {
11390
+ video: base
11391
+ };
11370
11392
  };
11371
- if (deviceId) {
11372
- userMediaConstraints.deviceId = deviceId;
11393
+ let stream;
11394
+ try {
11395
+ stream = await navigator.mediaDevices.getUserMedia(buildConstraints());
11396
+ } catch (e) {
11397
+ stream = await navigator.mediaDevices.getUserMedia({
11398
+ video: true
11399
+ });
11373
11400
  }
11374
- const stream = await navigator.mediaDevices.getUserMedia({
11375
- video: userMediaConstraints
11376
- });
11377
11401
  this.video.srcObject = stream;
11378
11402
  await this.video.play().catch(e => {
11379
11403
  console.warn(`Error on video play: ${e}`);
@@ -11438,8 +11462,7 @@ class ExtractorVideo {
11438
11462
  const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
11439
11463
  const borderColor = cfgValues.VIDEO_COLORS?.borderColor;
11440
11464
  const messageColor = cfgValues.VIDEO_COLORS?.messageColor;
11441
- const isMobile = window.innerWidth < 768 || window.innerHeight > window.innerWidth;
11442
- window.innerWidth < 768 || window.innerHeight > window.innerWidth && window.innerWidth < 1024;
11465
+ const isMobile = window.innerWidth < 768 || window.innerHeight > window.innerWidth && window.innerWidth < 1024;
11443
11466
  if (isMobile) {
11444
11467
  // Mobile version with overlay feedback
11445
11468
  return `
@@ -11508,7 +11531,7 @@ class ExtractorVideo {
11508
11531
  <div class="desktopFeedback" id="ScanDocAIMessage"></div>
11509
11532
  <div class="desktopVideoArea">
11510
11533
  <div class="desktopVideoHolder">
11511
- <video id="ScanDocAIVideoElement" class="desktopVideo" autoPlay muted playsInline></video>
11534
+ <video id="ScanDocAIVideoElement" class="desktopVideo" autoplay muted playsinline></video>
11512
11535
  <div class="backgroundOverlay"></div>
11513
11536
  <div class="centerGuideDot"></div>
11514
11537
  </div>
@@ -11611,12 +11634,14 @@ async function checkAutofocusSupport(environmentCameras) {
11611
11634
  // Try to access camera stream with autofocus enabled
11612
11635
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
11613
11636
  const tracks = stream.getVideoTracks();
11614
-
11615
- // Check if autofocus is supported
11616
- const capabilities = tracks[0].getCapabilities();
11617
- // console.log(capabilities);
11618
- if (capabilities.focusMode && capabilities.focusMode.includes("continuous")) {
11619
- camerasWithAutofocus.push(camera);
11637
+ const track = tracks[0];
11638
+ if (track) {
11639
+ // Check if autofocus is supported
11640
+ const capabilities = track.getCapabilities();
11641
+ // console.log(capabilities);
11642
+ if (capabilities.focusMode && capabilities.focusMode.includes("continuous")) {
11643
+ camerasWithAutofocus.push(camera);
11644
+ }
11620
11645
  }
11621
11646
 
11622
11647
  // Cleanup
@@ -11694,6 +11719,7 @@ let internalConfig = {
11694
11719
  MAX_REQUEST_TRY: 3,
11695
11720
  MAX_AUTH_TRY: 3,
11696
11721
  USE_KEY_SERVICE: true,
11722
+ VIDEO_FACING_MODE: "environment",
11697
11723
  // validation settings:
11698
11724
  VALIDATION_CONTRAST_BORDER_SIZE: null,
11699
11725
  VALIDATION_CONTRAST_THRESHOLD: null,
@@ -11732,9 +11758,9 @@ function setScanDocAIConfig(newConfig = {}) {
11732
11758
  internalConfig = {
11733
11759
  ...internalConfig,
11734
11760
  ...newConfig,
11735
- COLORS: {
11736
- ...internalConfig.COLORS,
11737
- ...newConfig.COLORS
11761
+ VIDEO_COLORS: {
11762
+ ...internalConfig.VIDEO_COLORS,
11763
+ ...newConfig.VIDEO_COLORS
11738
11764
  }
11739
11765
  };
11740
11766
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.0.99",
4
+ "version": "0.1.0",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [