scandoc-ai-components 0.0.61 → 0.0.63

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.
Files changed (2) hide show
  1. package/dist/index.js +72 -31
  2. 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;
@@ -11364,6 +11405,21 @@ class ExtractorVideo {
11364
11405
  await this.video.play().catch(e => {
11365
11406
  console.warn(`Error on video play: ${e}`);
11366
11407
  });
11408
+ window.addEventListener("resize", () => {
11409
+ if (this.isRunning) {
11410
+ setTimeout(() => this.getCameraMargins().then(margins => {
11411
+ const rectangle = document.querySelector('.desktopRectangle');
11412
+ const clamp = (v, max = 0.25) => Math.min(v, max) * 100;
11413
+ const buffer = 0.03;
11414
+ if (rectangle) {
11415
+ rectangle.style.top = `${clamp(margins.topPct + buffer)}%`;
11416
+ rectangle.style.bottom = `${clamp(margins.bottomPct + buffer)}%`;
11417
+ rectangle.style.left = `${clamp(margins.leftPct + buffer)}%`;
11418
+ rectangle.style.right = `${clamp(margins.rightPct + buffer)}%`;
11419
+ }
11420
+ }), 500);
11421
+ }
11422
+ });
11367
11423
  this.scanStartTime = Date.now(); // Reset timer
11368
11424
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11369
11425
  this.showMessage("Starting scanning");
@@ -11401,11 +11457,9 @@ class ExtractorVideo {
11401
11457
  <div class="desktopFeedback" id="ScanDocAIMessage"></div>
11402
11458
  <div class="desktopVideoArea">
11403
11459
  <div class="desktopVideoHolder">
11404
- <div class="videoWrapper">
11405
- <video id="ScanDocAIVideoElement" class="desktopVideo" autoPlay muted playsInline></video>
11406
- <div class="backgroundOverlay"></div>
11407
- <div class="desktopRectangle dashedRectangle"></div>
11408
- </div>
11460
+ <video id="ScanDocAIVideoElement" class="desktopVideo" autoPlay muted playsInline></video>
11461
+ <div class="backgroundOverlay"></div>
11462
+ <div class="desktopRectangle dashedRectangle"></div>
11409
11463
  </div>
11410
11464
  </div>
11411
11465
 
@@ -11426,39 +11480,26 @@ class ExtractorVideo {
11426
11480
  position: relative;
11427
11481
  max-width: 100%;
11428
11482
  overflow: hidden;
11483
+ aspect-ratio: 16 / 9;
11429
11484
  }
11430
-
11431
- .videoWrapper {
11432
- position: relative;
11433
- width: 100%;
11434
- aspect-ratio: 16 / 9;
11435
- }
11485
+
11436
11486
  .desktopVideo {
11437
11487
  width: 100%;
11438
11488
  height: 100%;
11439
- object-fit: cover;
11489
+ object-fit: contain;
11440
11490
  display: block;
11441
11491
  }
11492
+
11442
11493
  .desktopRectangle {
11443
- position: absolute;
11444
- top: 5%;
11445
- left: 5%;
11446
- right: 5%;
11447
- bottom: 5%;
11448
- border-radius: 30px;
11449
- display: flex;
11450
- justify-content: center;
11451
- align-items: center;
11452
- z-index: 3;
11453
- }
11454
-
11455
- .dashedRectangle {
11456
- border: 5px dashed #5078bb;
11457
- }
11458
-
11459
- .solidRectangle {
11460
- border: 5px solid #5078bb;
11461
- }
11494
+ position: absolute;
11495
+ border-radius: 30px;
11496
+ display: flex;
11497
+ justify-content: center;
11498
+ align-items: center;
11499
+ z-index: 3;
11500
+ border: 5px dashed #5078bb;
11501
+ transition: all 0.3s ease;
11502
+ }
11462
11503
 
11463
11504
  .backgroundOverlay {
11464
11505
  position: absolute;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.0.61",
4
+ "version": "0.0.63",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [