scandoc-ai-components 0.0.98 → 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.
- package/dist/index.js +50 -50
- 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 = [];
|
|
@@ -11262,9 +11261,6 @@ class ExtractorVideo {
|
|
|
11262
11261
|
const imageSide = response["Side"];
|
|
11263
11262
|
const message = response["Info"];
|
|
11264
11263
|
const isNewSide = this.extractionImages[imageSide] === undefined;
|
|
11265
|
-
console.log("Received side from validation:", imageSide);
|
|
11266
|
-
console.log("Image index:", imageId);
|
|
11267
|
-
console.log("Available sides in extractionImages:", Object.keys(this.extractionImages));
|
|
11268
11264
|
if (!this.waitingForSecondSide || isNewSide) {
|
|
11269
11265
|
this.showMessage(message);
|
|
11270
11266
|
}
|
|
@@ -11296,7 +11292,6 @@ class ExtractorVideo {
|
|
|
11296
11292
|
this.waitingForSecondSide = false;
|
|
11297
11293
|
this.hasShownTurnMessage = false;
|
|
11298
11294
|
this.showMessage("Validation successful", true);
|
|
11299
|
-
console.log(this.extractionImages);
|
|
11300
11295
|
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(this.extractionImages["FRONT"], this.extractionImages["BACK"], false);
|
|
11301
11296
|
this.onExtraction(isExtractionOk, extractionData);
|
|
11302
11297
|
return;
|
|
@@ -11362,22 +11357,47 @@ class ExtractorVideo {
|
|
|
11362
11357
|
this.video = videoElem;
|
|
11363
11358
|
this.isRunning = true;
|
|
11364
11359
|
this.scanStartTime = Date.now();
|
|
11360
|
+
const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
|
|
11361
|
+
const mode = cfgValues.VIDEO_FACING_MODE ?? "environment";
|
|
11365
11362
|
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
11366
11363
|
const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
|
|
11367
|
-
const cameras = await checkAutofocusSupport(environmentCameras);
|
|
11368
11364
|
let deviceId;
|
|
11369
|
-
if (
|
|
11370
|
-
|
|
11365
|
+
if (mode === "environment") {
|
|
11366
|
+
const af = await checkAutofocusSupport(environmentCameras);
|
|
11367
|
+
deviceId = af[0]?.deviceId || environmentCameras[0]?.deviceId;
|
|
11371
11368
|
}
|
|
11372
|
-
const
|
|
11373
|
-
|
|
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
|
+
};
|
|
11374
11392
|
};
|
|
11375
|
-
|
|
11376
|
-
|
|
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
|
+
});
|
|
11377
11400
|
}
|
|
11378
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
11379
|
-
video: userMediaConstraints
|
|
11380
|
-
});
|
|
11381
11401
|
this.video.srcObject = stream;
|
|
11382
11402
|
await this.video.play().catch(e => {
|
|
11383
11403
|
console.warn(`Error on video play: ${e}`);
|
|
@@ -11442,8 +11462,7 @@ class ExtractorVideo {
|
|
|
11442
11462
|
const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
|
|
11443
11463
|
const borderColor = cfgValues.VIDEO_COLORS?.borderColor;
|
|
11444
11464
|
const messageColor = cfgValues.VIDEO_COLORS?.messageColor;
|
|
11445
|
-
const isMobile = window.innerWidth < 768 || window.innerHeight > window.innerWidth;
|
|
11446
|
-
window.innerWidth < 768 || window.innerHeight > window.innerWidth && window.innerWidth < 1024;
|
|
11465
|
+
const isMobile = window.innerWidth < 768 || window.innerHeight > window.innerWidth && window.innerWidth < 1024;
|
|
11447
11466
|
if (isMobile) {
|
|
11448
11467
|
// Mobile version with overlay feedback
|
|
11449
11468
|
return `
|
|
@@ -11512,7 +11531,7 @@ class ExtractorVideo {
|
|
|
11512
11531
|
<div class="desktopFeedback" id="ScanDocAIMessage"></div>
|
|
11513
11532
|
<div class="desktopVideoArea">
|
|
11514
11533
|
<div class="desktopVideoHolder">
|
|
11515
|
-
<video id="ScanDocAIVideoElement" class="desktopVideo"
|
|
11534
|
+
<video id="ScanDocAIVideoElement" class="desktopVideo" autoplay muted playsinline></video>
|
|
11516
11535
|
<div class="backgroundOverlay"></div>
|
|
11517
11536
|
<div class="centerGuideDot"></div>
|
|
11518
11537
|
</div>
|
|
@@ -11615,12 +11634,14 @@ async function checkAutofocusSupport(environmentCameras) {
|
|
|
11615
11634
|
// Try to access camera stream with autofocus enabled
|
|
11616
11635
|
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
11617
11636
|
const tracks = stream.getVideoTracks();
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
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
|
+
}
|
|
11624
11645
|
}
|
|
11625
11646
|
|
|
11626
11647
|
// Cleanup
|
|
@@ -11698,6 +11719,7 @@ let internalConfig = {
|
|
|
11698
11719
|
MAX_REQUEST_TRY: 3,
|
|
11699
11720
|
MAX_AUTH_TRY: 3,
|
|
11700
11721
|
USE_KEY_SERVICE: true,
|
|
11722
|
+
VIDEO_FACING_MODE: "environment",
|
|
11701
11723
|
// validation settings:
|
|
11702
11724
|
VALIDATION_CONTRAST_BORDER_SIZE: null,
|
|
11703
11725
|
VALIDATION_CONTRAST_THRESHOLD: null,
|
|
@@ -11736,9 +11758,9 @@ function setScanDocAIConfig(newConfig = {}) {
|
|
|
11736
11758
|
internalConfig = {
|
|
11737
11759
|
...internalConfig,
|
|
11738
11760
|
...newConfig,
|
|
11739
|
-
|
|
11740
|
-
...internalConfig.
|
|
11741
|
-
...newConfig.
|
|
11761
|
+
VIDEO_COLORS: {
|
|
11762
|
+
...internalConfig.VIDEO_COLORS,
|
|
11763
|
+
...newConfig.VIDEO_COLORS
|
|
11742
11764
|
}
|
|
11743
11765
|
};
|
|
11744
11766
|
}
|
|
@@ -11961,11 +11983,6 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
11961
11983
|
FaceImageResize: cfgValues.FACE_IMAGE_RESIZE
|
|
11962
11984
|
};
|
|
11963
11985
|
const currentSettings = (0,_utility_utils__WEBPACK_IMPORTED_MODULE_1__.removeNullFields)(settings);
|
|
11964
|
-
console.log("Starting document extraction...");
|
|
11965
|
-
console.log("Ignore back image:", ignoreBackImage);
|
|
11966
|
-
console.log("Front image (first 100 chars):", frontImage?.substring(0, 100));
|
|
11967
|
-
console.log("Back image (first 100 chars):", backImage?.substring(0, 100));
|
|
11968
|
-
console.log("Sending settings:", currentSettings);
|
|
11969
11986
|
const response = await fetch(`${cfgValues.SCAN_APP_URL}extraction/`, {
|
|
11970
11987
|
method: "POST",
|
|
11971
11988
|
headers: {
|
|
@@ -11989,23 +12006,6 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
11989
12006
|
Browser: browser
|
|
11990
12007
|
})
|
|
11991
12008
|
});
|
|
11992
|
-
const requestBody = {
|
|
11993
|
-
AcceptTermsAndConditions: true,
|
|
11994
|
-
DataFields: {
|
|
11995
|
-
BackImage: ignoreBackImage ? "" : backImage,
|
|
11996
|
-
BackImageCropped: false,
|
|
11997
|
-
BackImageType: "base64",
|
|
11998
|
-
FrontImage: frontImage,
|
|
11999
|
-
FrontImageCropped: false,
|
|
12000
|
-
FrontImageType: "base64"
|
|
12001
|
-
},
|
|
12002
|
-
Settings: currentSettings,
|
|
12003
|
-
OS: os,
|
|
12004
|
-
Device: device,
|
|
12005
|
-
Browser: browser
|
|
12006
|
-
};
|
|
12007
|
-
console.log("Extraction request body:", requestBody);
|
|
12008
|
-
|
|
12009
12009
|
//
|
|
12010
12010
|
if (response.status === 200) {
|
|
12011
12011
|
const data = await response.json();
|