scandoc-ai-components 0.0.83 → 0.0.84
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 +68 -102
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11191,6 +11191,7 @@ class ExtractorVideo {
|
|
|
11191
11191
|
this.unsupportedDocCount = 0;
|
|
11192
11192
|
this.video = null;
|
|
11193
11193
|
this.lastMessage = null;
|
|
11194
|
+
this.waitingForSecondSide = false;
|
|
11194
11195
|
}
|
|
11195
11196
|
reset() {
|
|
11196
11197
|
this.stopVideo();
|
|
@@ -11204,12 +11205,10 @@ class ExtractorVideo {
|
|
|
11204
11205
|
this.unsupportedDocCount = 0;
|
|
11205
11206
|
this.video = null;
|
|
11206
11207
|
this.lastMessage = null;
|
|
11208
|
+
this.waitingForSecondSide = false;
|
|
11207
11209
|
}
|
|
11208
11210
|
async analyzeVideoStream() {
|
|
11209
|
-
if (!this.isRunning)
|
|
11210
|
-
return;
|
|
11211
|
-
}
|
|
11212
|
-
//
|
|
11211
|
+
if (!this.isRunning) return;
|
|
11213
11212
|
const now = Date.now();
|
|
11214
11213
|
const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
|
|
11215
11214
|
if (this.scanStartTime && now - this.scanStartTime > cfgValues.MAX_SCAN_DURATION_MS) {
|
|
@@ -11221,111 +11220,89 @@ class ExtractorVideo {
|
|
|
11221
11220
|
});
|
|
11222
11221
|
return;
|
|
11223
11222
|
}
|
|
11224
|
-
//
|
|
11225
11223
|
const canvas = document.createElement("canvas");
|
|
11226
|
-
|
|
11224
|
+
const video = document.getElementById("ScanDocAIVideoElement");
|
|
11227
11225
|
if (video && video.videoWidth < video.videoHeight) {
|
|
11228
11226
|
this.showMessage("Please rotate your device to landscape mode.");
|
|
11229
11227
|
this.candidateImages = [];
|
|
11230
11228
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11231
11229
|
return;
|
|
11232
11230
|
}
|
|
11233
|
-
//
|
|
11234
11231
|
const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, 1280, 720, false);
|
|
11235
11232
|
const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
|
|
11236
11233
|
DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
|
|
11237
|
-
if (isPresent)
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11253
|
-
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11266
|
-
// Show feedback only if both sides are not yet scanned
|
|
11267
|
-
// Avoid overwriting "Turn to the other side" until second side appears
|
|
11268
|
-
if (scannedSides < 1) {
|
|
11269
|
-
this.showMessage(response["Info"]); // normal feedback before first side
|
|
11270
|
-
} else if (!isAlreadyScanned && scannedSides === 1) {
|
|
11271
|
-
// We are seeing a new side after 1 side has already been scanned
|
|
11272
|
-
this.showMessage(response["Info"]); // allow resuming feedback (if desired)
|
|
11273
|
-
}
|
|
11274
|
-
//
|
|
11275
|
-
if ("DetectedBlurValue" in response) {
|
|
11276
|
-
this.pastBlurValues.push(response["DetectedBlurValue"]);
|
|
11277
|
-
} else {
|
|
11278
|
-
this.pastBlurValues = [];
|
|
11279
|
-
}
|
|
11280
|
-
//
|
|
11281
|
-
if (response["InfoCode"] === "1007") {
|
|
11282
|
-
const imageId = response["Index"];
|
|
11283
|
-
const imageSide = response["Side"];
|
|
11284
|
-
//
|
|
11285
|
-
if (this.extractionImages[imageSide] !== undefined) {
|
|
11286
|
-
this.candidateImages = [];
|
|
11287
|
-
return;
|
|
11288
|
-
}
|
|
11289
|
-
this.extractionImages[imageSide] = images[imageId]["fullImg"];
|
|
11290
|
-
const extractionImages = {
|
|
11291
|
-
...this.extractionImages
|
|
11292
|
-
};
|
|
11293
|
-
//
|
|
11294
|
-
if (Object.keys(extractionImages).length === 1) {
|
|
11295
|
-
this.scanStartTime = Date.now();
|
|
11296
|
-
this.showMessage("Turn to the other side");
|
|
11297
|
-
}
|
|
11298
|
-
if (Object.keys(extractionImages).length === 2) {
|
|
11299
|
-
this.showMessage("Validation successful");
|
|
11300
|
-
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(extractionImages["FRONT"], extractionImages["BACK"], {
|
|
11301
|
-
IgnoreBackImage: false
|
|
11302
|
-
});
|
|
11303
|
-
this.onExtraction(isExtractionOk, extractionData);
|
|
11304
|
-
return;
|
|
11305
|
-
}
|
|
11306
|
-
} else if (response["InfoCode"] === "1000") {
|
|
11307
|
-
this.showMessage("Validation successful");
|
|
11308
|
-
this.showMessage("Extracting data");
|
|
11309
|
-
const imageId = response["Index"];
|
|
11310
|
-
const image = images[imageId]["fullImg"];
|
|
11311
|
-
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image, undefined, {
|
|
11312
|
-
IgnoreBackImage: true
|
|
11313
|
-
});
|
|
11314
|
-
this.onExtraction(isExtractionOk, extractionData);
|
|
11315
|
-
return;
|
|
11316
|
-
}
|
|
11317
|
-
}
|
|
11234
|
+
if (!isPresent) return;
|
|
11235
|
+
this.candidateImages.push({
|
|
11236
|
+
fullImg: fullImage,
|
|
11237
|
+
validationImg: validationImage
|
|
11238
|
+
});
|
|
11239
|
+
const images = [...this.candidateImages];
|
|
11240
|
+
if (images.length < ExtractorVideo.VALIDATION_BATCH_SIZE) return;
|
|
11241
|
+
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e.validationImg), this.pastBlurValues, {});
|
|
11242
|
+
if (!isValidationOk) {
|
|
11243
|
+
this.candidateImages = [];
|
|
11244
|
+
return;
|
|
11245
|
+
}
|
|
11246
|
+
const infoCode = response["InfoCode"];
|
|
11247
|
+
const imageId = response["Index"];
|
|
11248
|
+
const imageSide = response["Side"];
|
|
11249
|
+
const message = response["Info"];
|
|
11250
|
+
const isNewSide = this.extractionImages[imageSide] === undefined;
|
|
11251
|
+
const numScannedSides = Object.keys(this.extractionImages).length;
|
|
11252
|
+
if (!this.waitingForSecondSide || isNewSide) {
|
|
11253
|
+
this.showMessage(message);
|
|
11254
|
+
}
|
|
11255
|
+
if ("DetectedBlurValue" in response) {
|
|
11256
|
+
this.pastBlurValues.push(response["DetectedBlurValue"]);
|
|
11257
|
+
} else {
|
|
11258
|
+
this.pastBlurValues = [];
|
|
11259
|
+
}
|
|
11260
|
+
if (infoCode === "1007") {
|
|
11261
|
+
if (!isNewSide) {
|
|
11318
11262
|
this.candidateImages = [];
|
|
11263
|
+
return;
|
|
11319
11264
|
}
|
|
11265
|
+
this.extractionImages[imageSide] = images[imageId].fullImg;
|
|
11266
|
+
if (Object.keys(this.extractionImages).length === 1) {
|
|
11267
|
+
this.waitingForSecondSide = true;
|
|
11268
|
+
this.scanStartTime = Date.now();
|
|
11269
|
+
this.showMessage("Turn to the other side");
|
|
11270
|
+
} else if (Object.keys(this.extractionImages).length === 2) {
|
|
11271
|
+
this.waitingForSecondSide = false;
|
|
11272
|
+
this.showMessage("Validation successful");
|
|
11273
|
+
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(this.extractionImages["FRONT"], this.extractionImages["BACK"], {
|
|
11274
|
+
IgnoreBackImage: false
|
|
11275
|
+
});
|
|
11276
|
+
this.onExtraction(isExtractionOk, extractionData);
|
|
11277
|
+
return;
|
|
11278
|
+
}
|
|
11279
|
+
} else if (infoCode === "1000") {
|
|
11280
|
+
this.waitingForSecondSide = false;
|
|
11281
|
+
this.showMessage("Validation successful");
|
|
11282
|
+
this.showMessage("Extracting data");
|
|
11283
|
+
const image = images[imageId].fullImg;
|
|
11284
|
+
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image, undefined, {
|
|
11285
|
+
IgnoreBackImage: true
|
|
11286
|
+
});
|
|
11287
|
+
this.onExtraction(isExtractionOk, extractionData);
|
|
11288
|
+
return;
|
|
11320
11289
|
}
|
|
11290
|
+
this.candidateImages = [];
|
|
11321
11291
|
}).finally(() => {
|
|
11322
11292
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11323
11293
|
});
|
|
11324
11294
|
}
|
|
11295
|
+
showMessage(message) {
|
|
11296
|
+
if (!message || this.lastMessage === message) return;
|
|
11297
|
+
this.lastMessage = message;
|
|
11298
|
+
const messageElement = document.getElementById("ScanDocAIMessage");
|
|
11299
|
+
if (messageElement) {
|
|
11300
|
+
messageElement.innerText = message;
|
|
11301
|
+
}
|
|
11302
|
+
}
|
|
11325
11303
|
onExtraction(isExtractionOk, extractionData) {
|
|
11326
11304
|
this.candidateImages = [];
|
|
11327
11305
|
this.extractionImages = {};
|
|
11328
|
-
this.lastMessage = null;
|
|
11329
11306
|
this.stopVideo();
|
|
11330
11307
|
if (isExtractionOk) {
|
|
11331
11308
|
this.showMessage("Success - data extracted", "success");
|
|
@@ -11350,8 +11327,7 @@ class ExtractorVideo {
|
|
|
11350
11327
|
async startVideo() {
|
|
11351
11328
|
try {
|
|
11352
11329
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11353
|
-
await serviceConfig.getAccessToken(true);
|
|
11354
|
-
|
|
11330
|
+
await serviceConfig.getAccessToken(true);
|
|
11355
11331
|
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11356
11332
|
if (!videoElem) {
|
|
11357
11333
|
throw new Error("Video element not found.");
|
|
@@ -11384,7 +11360,7 @@ class ExtractorVideo {
|
|
|
11384
11360
|
});
|
|
11385
11361
|
window.addEventListener('resize', () => this.adjustOverlayPosition());
|
|
11386
11362
|
setTimeout(() => this.adjustOverlayPosition(), 500);
|
|
11387
|
-
this.scanStartTime = Date.now();
|
|
11363
|
+
this.scanStartTime = Date.now();
|
|
11388
11364
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11389
11365
|
this.showMessage("Starting scanning");
|
|
11390
11366
|
return true;
|
|
@@ -11402,7 +11378,6 @@ class ExtractorVideo {
|
|
|
11402
11378
|
}
|
|
11403
11379
|
stopVideo() {
|
|
11404
11380
|
this.isRunning = false;
|
|
11405
|
-
this.lastMessage = null;
|
|
11406
11381
|
if (this.video) {
|
|
11407
11382
|
this.video.pause();
|
|
11408
11383
|
if (this.video.srcObject !== undefined && this.video.srcObject !== null) {
|
|
@@ -11411,15 +11386,6 @@ class ExtractorVideo {
|
|
|
11411
11386
|
this.video.srcObject = null;
|
|
11412
11387
|
}
|
|
11413
11388
|
}
|
|
11414
|
-
showMessage(message) {
|
|
11415
|
-
if (!message || message.trim() === "") return;
|
|
11416
|
-
if (this.lastMessage === message) return;
|
|
11417
|
-
this.lastMessage = message;
|
|
11418
|
-
const messageElement = document.getElementById("ScanDocAIMessage");
|
|
11419
|
-
if (messageElement) {
|
|
11420
|
-
messageElement.innerText = message;
|
|
11421
|
-
}
|
|
11422
|
-
}
|
|
11423
11389
|
adjustOverlayPosition() {
|
|
11424
11390
|
const video = this.video;
|
|
11425
11391
|
const dot = document.querySelector(".centerGuideDot");
|