scandoc-ai-components 0.0.82 → 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 -90
- 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,100 +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
|
-
this.pastBlurValues.push(response["DetectedBlurValue"]);
|
|
11266
|
-
} else {
|
|
11267
|
-
this.pastBlurValues = [];
|
|
11268
|
-
}
|
|
11269
|
-
//
|
|
11270
|
-
if (response["InfoCode"] === "1007") {
|
|
11271
|
-
const imageId = response["Index"];
|
|
11272
|
-
const imageSide = response["Side"];
|
|
11273
|
-
//
|
|
11274
|
-
if (this.extractionImages[imageSide] !== undefined) {
|
|
11275
|
-
this.candidateImages = [];
|
|
11276
|
-
return;
|
|
11277
|
-
}
|
|
11278
|
-
this.extractionImages[imageSide] = images[imageId]["fullImg"];
|
|
11279
|
-
const extractionImages = {
|
|
11280
|
-
...this.extractionImages
|
|
11281
|
-
};
|
|
11282
|
-
//
|
|
11283
|
-
if (Object.keys(extractionImages).length === 1) {
|
|
11284
|
-
this.scanStartTime = Date.now();
|
|
11285
|
-
this.showMessage("Turn to the other side");
|
|
11286
|
-
}
|
|
11287
|
-
if (Object.keys(extractionImages).length === 2) {
|
|
11288
|
-
this.showMessage("Validation successful");
|
|
11289
|
-
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(extractionImages["FRONT"], extractionImages["BACK"], {
|
|
11290
|
-
IgnoreBackImage: false
|
|
11291
|
-
});
|
|
11292
|
-
this.onExtraction(isExtractionOk, extractionData);
|
|
11293
|
-
return;
|
|
11294
|
-
}
|
|
11295
|
-
} else if (response["InfoCode"] === "1000") {
|
|
11296
|
-
this.showMessage("Validation successful");
|
|
11297
|
-
this.showMessage("Extracting data");
|
|
11298
|
-
const imageId = response["Index"];
|
|
11299
|
-
const image = images[imageId]["fullImg"];
|
|
11300
|
-
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image, undefined, {
|
|
11301
|
-
IgnoreBackImage: true
|
|
11302
|
-
});
|
|
11303
|
-
this.onExtraction(isExtractionOk, extractionData);
|
|
11304
|
-
return;
|
|
11305
|
-
}
|
|
11306
|
-
}
|
|
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) {
|
|
11307
11262
|
this.candidateImages = [];
|
|
11263
|
+
return;
|
|
11308
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;
|
|
11309
11289
|
}
|
|
11290
|
+
this.candidateImages = [];
|
|
11310
11291
|
}).finally(() => {
|
|
11311
11292
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11312
11293
|
});
|
|
11313
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
|
+
}
|
|
11314
11303
|
onExtraction(isExtractionOk, extractionData) {
|
|
11315
11304
|
this.candidateImages = [];
|
|
11316
11305
|
this.extractionImages = {};
|
|
11317
|
-
this.lastMessage = null;
|
|
11318
11306
|
this.stopVideo();
|
|
11319
11307
|
if (isExtractionOk) {
|
|
11320
11308
|
this.showMessage("Success - data extracted", "success");
|
|
@@ -11339,8 +11327,7 @@ class ExtractorVideo {
|
|
|
11339
11327
|
async startVideo() {
|
|
11340
11328
|
try {
|
|
11341
11329
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11342
|
-
await serviceConfig.getAccessToken(true);
|
|
11343
|
-
|
|
11330
|
+
await serviceConfig.getAccessToken(true);
|
|
11344
11331
|
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11345
11332
|
if (!videoElem) {
|
|
11346
11333
|
throw new Error("Video element not found.");
|
|
@@ -11373,7 +11360,7 @@ class ExtractorVideo {
|
|
|
11373
11360
|
});
|
|
11374
11361
|
window.addEventListener('resize', () => this.adjustOverlayPosition());
|
|
11375
11362
|
setTimeout(() => this.adjustOverlayPosition(), 500);
|
|
11376
|
-
this.scanStartTime = Date.now();
|
|
11363
|
+
this.scanStartTime = Date.now();
|
|
11377
11364
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11378
11365
|
this.showMessage("Starting scanning");
|
|
11379
11366
|
return true;
|
|
@@ -11391,7 +11378,6 @@ class ExtractorVideo {
|
|
|
11391
11378
|
}
|
|
11392
11379
|
stopVideo() {
|
|
11393
11380
|
this.isRunning = false;
|
|
11394
|
-
this.lastMessage = null;
|
|
11395
11381
|
if (this.video) {
|
|
11396
11382
|
this.video.pause();
|
|
11397
11383
|
if (this.video.srcObject !== undefined && this.video.srcObject !== null) {
|
|
@@ -11400,14 +11386,6 @@ class ExtractorVideo {
|
|
|
11400
11386
|
this.video.srcObject = null;
|
|
11401
11387
|
}
|
|
11402
11388
|
}
|
|
11403
|
-
showMessage(message) {
|
|
11404
|
-
if (this.lastMessage === message) return;
|
|
11405
|
-
this.lastMessage = message;
|
|
11406
|
-
const messageElement = document.getElementById("ScanDocAIMessage");
|
|
11407
|
-
if (messageElement) {
|
|
11408
|
-
messageElement.innerText = message;
|
|
11409
|
-
}
|
|
11410
|
-
}
|
|
11411
11389
|
adjustOverlayPosition() {
|
|
11412
11390
|
const video = this.video;
|
|
11413
11391
|
const dot = document.querySelector(".centerGuideDot");
|