scandoc-ai-components 0.0.68 → 0.0.70
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 +12 -78
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11205,64 +11205,6 @@ class ExtractorVideo {
|
|
|
11205
11205
|
this.unsupportedDocCount = 0;
|
|
11206
11206
|
this.video = null;
|
|
11207
11207
|
}
|
|
11208
|
-
async getCameraMargins() {
|
|
11209
|
-
const video = document.getElementById('ScanDocAIVideoElement');
|
|
11210
|
-
const canvas = document.createElement('canvas');
|
|
11211
|
-
const ctx = canvas.getContext('2d');
|
|
11212
|
-
canvas.width = video.videoWidth;
|
|
11213
|
-
canvas.height = video.videoHeight;
|
|
11214
|
-
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
11215
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
11216
|
-
const isColumnBlack = x => {
|
|
11217
|
-
const threshold = 16;
|
|
11218
|
-
for (let y = 0; y < canvas.height; y++) {
|
|
11219
|
-
const i = (y * canvas.width + x) * 4;
|
|
11220
|
-
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11221
|
-
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11222
|
-
}
|
|
11223
|
-
return true;
|
|
11224
|
-
};
|
|
11225
|
-
const isRowBlack = y => {
|
|
11226
|
-
const threshold = 16;
|
|
11227
|
-
for (let x = 0; x < canvas.width; x++) {
|
|
11228
|
-
const i = (y * canvas.width + x) * 4;
|
|
11229
|
-
const [r, g, b] = [imageData[i], imageData[i + 1], imageData[i + 2]];
|
|
11230
|
-
if (r > threshold || g > threshold || b > threshold) return false;
|
|
11231
|
-
}
|
|
11232
|
-
return true;
|
|
11233
|
-
};
|
|
11234
|
-
let left = 0,
|
|
11235
|
-
right = 0,
|
|
11236
|
-
top = 0,
|
|
11237
|
-
bottom = 0;
|
|
11238
|
-
while (left < canvas.width && isColumnBlack(left)) left++;
|
|
11239
|
-
while (right < canvas.width && isColumnBlack(canvas.width - 1 - right)) right++;
|
|
11240
|
-
while (top < canvas.height && isRowBlack(top)) top++;
|
|
11241
|
-
while (bottom < canvas.height && isRowBlack(canvas.height - 1 - bottom)) bottom++;
|
|
11242
|
-
return {
|
|
11243
|
-
leftPct: left / canvas.width,
|
|
11244
|
-
rightPct: right / canvas.width,
|
|
11245
|
-
topPct: top / canvas.height,
|
|
11246
|
-
bottomPct: bottom / canvas.height
|
|
11247
|
-
};
|
|
11248
|
-
}
|
|
11249
|
-
updateRectangleOverlay = async () => {
|
|
11250
|
-
const margins = await this.getCameraMargins();
|
|
11251
|
-
const rectangle = document.querySelector('.desktopRectangle');
|
|
11252
|
-
const video = document.getElementById('ScanDocAIVideoElement');
|
|
11253
|
-
if (!rectangle || !video) return;
|
|
11254
|
-
const rect = video.getBoundingClientRect(); // the visible size
|
|
11255
|
-
const width = rect.width;
|
|
11256
|
-
const height = rect.height;
|
|
11257
|
-
const leftPx = margins.leftPct * width;
|
|
11258
|
-
const rightPx = margins.rightPct * width;
|
|
11259
|
-
const topPx = margins.topPct * height;
|
|
11260
|
-
const bottomPx = margins.bottomPct * height;
|
|
11261
|
-
rectangle.style.left = `${leftPx}px`;
|
|
11262
|
-
rectangle.style.top = `${topPx}px`;
|
|
11263
|
-
rectangle.style.width = `${width - leftPx - rightPx}px`;
|
|
11264
|
-
rectangle.style.height = `${height - topPx - bottomPx}px`;
|
|
11265
|
-
};
|
|
11266
11208
|
async analyzeVideoStream() {
|
|
11267
11209
|
if (!this.isRunning) {
|
|
11268
11210
|
return;
|
|
@@ -11423,16 +11365,6 @@ class ExtractorVideo {
|
|
|
11423
11365
|
await this.video.play().catch(e => {
|
|
11424
11366
|
console.warn(`Error on video play: ${e}`);
|
|
11425
11367
|
});
|
|
11426
|
-
this.video.onloadedmetadata = () => {
|
|
11427
|
-
this.updateRectangleOverlay();
|
|
11428
|
-
};
|
|
11429
|
-
setTimeout(() => this.updateRectangleOverlay(), 500);
|
|
11430
|
-
const scheduleOverlayUpdate = (delay = 500) => {
|
|
11431
|
-
clearTimeout(this.updateOverlayTimeout);
|
|
11432
|
-
this.updateOverlayTimeout = setTimeout(() => this.updateRectangleOverlay(), delay);
|
|
11433
|
-
};
|
|
11434
|
-
window.addEventListener("resize", () => scheduleOverlayUpdate());
|
|
11435
|
-
window.addEventListener("orientationchange", () => scheduleOverlayUpdate(700));
|
|
11436
11368
|
this.scanStartTime = Date.now(); // Reset timer
|
|
11437
11369
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11438
11370
|
this.showMessage("Starting scanning");
|
|
@@ -11490,18 +11422,20 @@ class ExtractorVideo {
|
|
|
11490
11422
|
}
|
|
11491
11423
|
|
|
11492
11424
|
.desktopVideoHolder {
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
overflow: hidden;
|
|
11425
|
+
position: relative;
|
|
11426
|
+
width: 100%;
|
|
11496
11427
|
aspect-ratio: 16 / 9;
|
|
11497
|
-
|
|
11428
|
+
overflow: hidden;
|
|
11429
|
+
}
|
|
11498
11430
|
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11431
|
+
.desktopVideo {
|
|
11432
|
+
position: absolute;
|
|
11433
|
+
top: 0;
|
|
11434
|
+
left: 0;
|
|
11435
|
+
width: 100%;
|
|
11436
|
+
height: 100%;
|
|
11437
|
+
object-fit: cover;
|
|
11438
|
+
}
|
|
11505
11439
|
|
|
11506
11440
|
.desktopRectangle {
|
|
11507
11441
|
position: absolute;
|