scandoc-ai-components 0.0.60 → 0.0.62
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 +112 -108
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11204,6 +11204,47 @@ class ExtractorVideo {
|
|
|
11204
11204
|
this.unsupportedDocCount = 0;
|
|
11205
11205
|
this.video = null;
|
|
11206
11206
|
}
|
|
11207
|
+
async getCameraMargins() {
|
|
11208
|
+
const video = document.getElementById('ScanDocAIVideoElement');
|
|
11209
|
+
const canvas = document.createElement('canvas');
|
|
11210
|
+
const ctx = canvas.getContext('2d');
|
|
11211
|
+
canvas.width = video.videoWidth;
|
|
11212
|
+
canvas.height = video.videoHeight;
|
|
11213
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
11214
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
11215
|
+
const isColumnBlack = x => {
|
|
11216
|
+
const threshold = 16;
|
|
11217
|
+
for (let y = 0; y < canvas.height; y++) {
|
|
11218
|
+
const i = (y * canvas.width + x) * 4;
|
|
11219
|
+
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11220
|
+
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11221
|
+
}
|
|
11222
|
+
return true;
|
|
11223
|
+
};
|
|
11224
|
+
const isRowBlack = y => {
|
|
11225
|
+
const threshold = 16;
|
|
11226
|
+
for (let x = 0; x < canvas.width; x++) {
|
|
11227
|
+
const i = (y * canvas.width + x) * 4;
|
|
11228
|
+
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11229
|
+
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11230
|
+
}
|
|
11231
|
+
return true;
|
|
11232
|
+
};
|
|
11233
|
+
let left = 0,
|
|
11234
|
+
right = 0,
|
|
11235
|
+
top = 0,
|
|
11236
|
+
bottom = 0;
|
|
11237
|
+
while (left < canvas.width && isColumnBlack(left)) left++;
|
|
11238
|
+
while (right < canvas.width && isColumnBlack(canvas.width - 1 - right)) right++;
|
|
11239
|
+
while (top < canvas.height && isRowBlack(top)) top++;
|
|
11240
|
+
while (bottom < canvas.height && isRowBlack(canvas.height - 1 - bottom)) bottom++;
|
|
11241
|
+
return {
|
|
11242
|
+
leftPct: left / canvas.width,
|
|
11243
|
+
rightPct: right / canvas.width,
|
|
11244
|
+
topPct: top / canvas.height,
|
|
11245
|
+
bottomPct: bottom / canvas.height
|
|
11246
|
+
};
|
|
11247
|
+
}
|
|
11207
11248
|
async analyzeVideoStream() {
|
|
11208
11249
|
if (!this.isRunning) {
|
|
11209
11250
|
return;
|
|
@@ -11332,47 +11373,6 @@ class ExtractorVideo {
|
|
|
11332
11373
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11333
11374
|
}
|
|
11334
11375
|
}
|
|
11335
|
-
async getCameraMargins() {
|
|
11336
|
-
const video = document.getElementById('ScanDocAIVideoElement');
|
|
11337
|
-
const canvas = document.createElement('canvas');
|
|
11338
|
-
const ctx = canvas.getContext('2d');
|
|
11339
|
-
canvas.width = video.videoWidth;
|
|
11340
|
-
canvas.height = video.videoHeight;
|
|
11341
|
-
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
11342
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
11343
|
-
const isColumnBlack = x => {
|
|
11344
|
-
const threshold = 16;
|
|
11345
|
-
for (let y = 0; y < canvas.height; y++) {
|
|
11346
|
-
const i = (y * canvas.width + x) * 4;
|
|
11347
|
-
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11348
|
-
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11349
|
-
}
|
|
11350
|
-
return true;
|
|
11351
|
-
};
|
|
11352
|
-
const isRowBlack = y => {
|
|
11353
|
-
const threshold = 16;
|
|
11354
|
-
for (let x = 0; x < canvas.width; x++) {
|
|
11355
|
-
const i = (y * canvas.width + x) * 4;
|
|
11356
|
-
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11357
|
-
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11358
|
-
}
|
|
11359
|
-
return true;
|
|
11360
|
-
};
|
|
11361
|
-
let left = 0,
|
|
11362
|
-
right = 0,
|
|
11363
|
-
top = 0,
|
|
11364
|
-
bottom = 0;
|
|
11365
|
-
while (left < canvas.width && isColumnBlack(left)) left++;
|
|
11366
|
-
while (right < canvas.width && isColumnBlack(canvas.width - 1 - right)) right++;
|
|
11367
|
-
while (top < canvas.height && isRowBlack(top)) top++;
|
|
11368
|
-
while (bottom < canvas.height && isRowBlack(canvas.height - 1 - bottom)) bottom++;
|
|
11369
|
-
return {
|
|
11370
|
-
leftPct: left / canvas.width,
|
|
11371
|
-
rightPct: right / canvas.width,
|
|
11372
|
-
topPct: top / canvas.height,
|
|
11373
|
-
bottomPct: bottom / canvas.height
|
|
11374
|
-
};
|
|
11375
|
-
}
|
|
11376
11376
|
async startVideo() {
|
|
11377
11377
|
try {
|
|
11378
11378
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
@@ -11405,6 +11405,17 @@ class ExtractorVideo {
|
|
|
11405
11405
|
await this.video.play().catch(e => {
|
|
11406
11406
|
console.warn(`Error on video play: ${e}`);
|
|
11407
11407
|
});
|
|
11408
|
+
setTimeout(async () => {
|
|
11409
|
+
const margins = await this.getCameraMargins();
|
|
11410
|
+
const rectangle = document.querySelector('.desktopRectangle');
|
|
11411
|
+
if (rectangle) {
|
|
11412
|
+
rectangle.style.top = `${margins.topPct * 100}%`;
|
|
11413
|
+
rectangle.style.bottom = `${margins.bottomPct * 100}%`;
|
|
11414
|
+
rectangle.style.left = `${margins.leftPct * 100}%`;
|
|
11415
|
+
rectangle.style.right = `${margins.rightPct * 100}%`;
|
|
11416
|
+
}
|
|
11417
|
+
}, 500); // Give time for video frame to show
|
|
11418
|
+
|
|
11408
11419
|
this.scanStartTime = Date.now(); // Reset timer
|
|
11409
11420
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11410
11421
|
this.showMessage("Starting scanning");
|
|
@@ -11439,83 +11450,76 @@ class ExtractorVideo {
|
|
|
11439
11450
|
}
|
|
11440
11451
|
getHTML() {
|
|
11441
11452
|
return `
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11453
|
+
<div class="desktopFeedback" id="ScanDocAIMessage"></div>
|
|
11454
|
+
<div class="desktopVideoArea">
|
|
11455
|
+
<div class="desktopVideoHolder">
|
|
11445
11456
|
<video id="ScanDocAIVideoElement" class="desktopVideo" autoPlay muted playsInline></video>
|
|
11446
11457
|
<div class="backgroundOverlay"></div>
|
|
11447
11458
|
<div class="desktopRectangle dashedRectangle"></div>
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
.desktopRectangle {
|
|
11459
|
+
</div>
|
|
11460
|
+
</div>
|
|
11461
|
+
|
|
11462
|
+
<style>
|
|
11463
|
+
.desktopVideoArea {
|
|
11464
|
+
display: flex;
|
|
11465
|
+
flex-direction: column;
|
|
11466
|
+
gap: 8px;
|
|
11467
|
+
padding: 16px;
|
|
11468
|
+
background-color: rgba(255, 255, 255, 0.05);
|
|
11469
|
+
border: 1px solid #5078bb;
|
|
11470
|
+
border-radius: 15px;
|
|
11471
|
+
margin-left: 20%;
|
|
11472
|
+
margin-right: 20%;
|
|
11473
|
+
}
|
|
11474
|
+
|
|
11475
|
+
.desktopVideoHolder {
|
|
11476
|
+
position: relative;
|
|
11477
|
+
max-width: 100%;
|
|
11478
|
+
overflow: hidden;
|
|
11479
|
+
aspect-ratio: 16 / 9;
|
|
11480
|
+
}
|
|
11481
|
+
|
|
11482
|
+
.desktopVideo {
|
|
11483
|
+
width: 100%;
|
|
11484
|
+
height: 100%;
|
|
11485
|
+
object-fit: contain;
|
|
11486
|
+
display: block;
|
|
11487
|
+
}
|
|
11488
|
+
|
|
11489
|
+
.desktopRectangle {
|
|
11480
11490
|
position: absolute;
|
|
11481
11491
|
border-radius: 30px;
|
|
11482
11492
|
display: flex;
|
|
11483
11493
|
justify-content: center;
|
|
11484
11494
|
align-items: center;
|
|
11485
|
-
|
|
11486
|
-
}
|
|
11487
|
-
|
|
11488
|
-
.dashedRectangle {
|
|
11495
|
+
z-index: 3;
|
|
11489
11496
|
border: 5px dashed #5078bb;
|
|
11497
|
+
transition: all 0.3s ease;
|
|
11490
11498
|
}
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
color: #5078bb;
|
|
11516
|
-
}
|
|
11517
|
-
</style>
|
|
11518
|
-
`;
|
|
11499
|
+
|
|
11500
|
+
.backgroundOverlay {
|
|
11501
|
+
position: absolute;
|
|
11502
|
+
top: 0;
|
|
11503
|
+
left: 0;
|
|
11504
|
+
width: 100%;
|
|
11505
|
+
height: 100%;
|
|
11506
|
+
background-color: rgba(0, 0, 0, 0.051);
|
|
11507
|
+
z-index: 2;
|
|
11508
|
+
pointer-events: none;
|
|
11509
|
+
}
|
|
11510
|
+
|
|
11511
|
+
.desktopFeedback {
|
|
11512
|
+
position: relative;
|
|
11513
|
+
display: flex;
|
|
11514
|
+
font-size: 22px;
|
|
11515
|
+
font-weight: 600;
|
|
11516
|
+
min-height: 36px;
|
|
11517
|
+
justify-content: center;
|
|
11518
|
+
align-items: center;
|
|
11519
|
+
color: #5078bb;
|
|
11520
|
+
}
|
|
11521
|
+
</style>
|
|
11522
|
+
`;
|
|
11519
11523
|
}
|
|
11520
11524
|
}
|
|
11521
11525
|
let EXTRACTION_VIDEO = undefined;
|