scanic 0.1.4 → 0.1.5

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/scanic.js CHANGED
@@ -22,57 +22,57 @@ const K = {
22
22
  ];
23
23
  function V(I, A = {}) {
24
24
  const g = A.width || Math.sqrt(I.length), C = A.height || I.length / g, E = A.mode !== void 0 ? A.mode : z, B = A.method !== void 0 ? A.method : x, Q = A.minArea || K.MIN_CONTOUR_AREA, i = g + 2, s = C + 2, t = new Int32Array(i * s);
25
- for (let n = 0; n < C; n++)
25
+ for (let a = 0; a < C; a++)
26
26
  for (let D = 0; D < g; D++)
27
- I[n * g + D] > 0 && (t[(n + 1) * i + (D + 1)] = 1);
28
- const e = [];
29
- let o = 2;
30
- for (let n = 1; n <= C; n++)
27
+ I[a * g + D] > 0 && (t[(a + 1) * i + (D + 1)] = 1);
28
+ const o = [];
29
+ let n = 2;
30
+ for (let a = 1; a <= C; a++)
31
31
  for (let D = 1; D <= g; D++) {
32
- const h = t[n * i + D], y = t[n * i + (D - 1)];
32
+ const h = t[a * i + D], y = t[a * i + (D - 1)];
33
33
  let c = null, r = !1, w = -1;
34
- if (h === 1 && y === 0 ? (r = !0, c = { x: D, y: n }, w = 2) : h === 0 && y >= 1 && y !== -1 && y === 1 && (r = !1, c = { x: D - 1, y: n }, w = 6), c) {
34
+ if (h === 1 && y === 0 ? (r = !0, c = { x: D, y: a }, w = 2) : h === 0 && y >= 1 && y !== -1 && y === 1 && (r = !1, c = { x: D - 1, y: a }, w = 6), c) {
35
35
  if (E === O && !r) {
36
36
  t[c.y * i + c.x] = -1;
37
37
  continue;
38
38
  }
39
- const F = o++, R = _(t, i, s, c, w, F);
39
+ const F = n++, R = _(t, i, s, c, w, F);
40
40
  if (R && R.length > 0) {
41
- let S = R;
42
- B === x && (S = $(R));
43
- const d = S.map((G) => ({ x: G.x - 1, y: G.y - 1 }));
44
- if (d.length >= (B === x ? 4 : K.MIN_CONTOUR_POINTS)) {
41
+ let d = R;
42
+ B === x && (d = $(R));
43
+ const S = d.map((G) => ({ x: G.x - 1, y: G.y - 1 }));
44
+ if (S.length >= (B === x ? 4 : K.MIN_CONTOUR_POINTS)) {
45
45
  const G = {
46
46
  id: F,
47
- points: d,
47
+ points: S,
48
48
  isOuter: r
49
49
  // Calculate area and bounding box later if needed for filtering/sorting
50
50
  };
51
- e.push(G);
51
+ o.push(G);
52
52
  }
53
53
  } else
54
54
  t[c.y * i + c.x] === 1 && (t[c.y * i + c.x] = F);
55
55
  }
56
56
  }
57
- e.forEach((n) => {
58
- n.area = AA(n.points), n.boundingBox = IA(n.points);
57
+ o.forEach((a) => {
58
+ a.area = AA(a.points), a.boundingBox = IA(a.points);
59
59
  });
60
- const a = e.filter((n) => n.area >= Q);
61
- return a.sort((n, D) => D.area - n.area), A.debug && (A.debug.labels = t, A.debug.rawContours = e, A.debug.finalContours = a), a;
60
+ const e = o.filter((a) => a.area >= Q);
61
+ return e.sort((a, D) => D.area - a.area), A.debug && (A.debug.labels = t, A.debug.rawContours = o, A.debug.finalContours = e), e;
62
62
  }
63
63
  function _(I, A, g, C, E, B) {
64
64
  const Q = [], i = /* @__PURE__ */ new Set();
65
65
  let s = { ...C }, t = -1;
66
66
  I[C.y * A + C.x] = B;
67
- let e = 0;
68
- const o = A * g;
69
- for (; e++ < o; ) {
70
- let a;
67
+ let o = 0;
68
+ const n = A * g;
69
+ for (; o++ < n; ) {
70
+ let e;
71
71
  if (t === -1) {
72
72
  let h = !1;
73
73
  for (let y = 0; y < 8; y++) {
74
- a = (E + y) % 8;
75
- const c = s.x + Y[a].dx, r = s.y + Y[a].dy;
74
+ e = (E + y) % 8;
75
+ const c = s.x + Y[e].dx, r = s.y + Y[e].dy;
76
76
  if (c >= 0 && c < A && r >= 0 && r < g && I[r * A + c] > 0) {
77
77
  h = !0;
78
78
  break;
@@ -80,34 +80,34 @@ function _(I, A, g, C, E, B) {
80
80
  }
81
81
  if (!h) return null;
82
82
  } else
83
- a = (t + 2) % 8;
84
- let n = null;
83
+ e = (t + 2) % 8;
84
+ let a = null;
85
85
  for (let h = 0; h < 8; h++) {
86
- const y = (a + h) % 8, c = s.x + Y[y].dx, r = s.y + Y[y].dy;
86
+ const y = (e + h) % 8, c = s.x + Y[y].dx, r = s.y + Y[y].dy;
87
87
  if (c >= 0 && c < A && r >= 0 && r < g && I[r * A + c] > 0) {
88
- n = { x: c, y: r }, t = (y + 4) % 8;
88
+ a = { x: c, y: r }, t = (y + 4) % 8;
89
89
  break;
90
90
  }
91
91
  }
92
- if (!n) {
92
+ if (!a) {
93
93
  Q.length === 0 && Q.push({ ...s }), console.warn(`Contour tracing stopped unexpectedly at (${s.x - 1}, ${s.y - 1}) for contour ${B}`);
94
94
  break;
95
95
  }
96
96
  const D = `${s.x},${s.y}`;
97
97
  if (i.has(D))
98
98
  return Q;
99
- if (Q.push({ ...s }), i.add(D), I[n.y * A + n.x] === 1 && (I[n.y * A + n.x] = B), s = n, s.x === C.x && s.y === C.y)
99
+ if (Q.push({ ...s }), i.add(D), I[a.y * A + a.x] === 1 && (I[a.y * A + a.x] = B), s = a, s.x === C.x && s.y === C.y)
100
100
  break;
101
101
  }
102
- return e >= o ? (console.warn(`Contour tracing exceeded max steps for contour ${B}`), null) : Q;
102
+ return o >= n ? (console.warn(`Contour tracing exceeded max steps for contour ${B}`), null) : Q;
103
103
  }
104
104
  function $(I) {
105
105
  if (I.length <= 2)
106
106
  return I;
107
107
  const A = [], g = I.length;
108
108
  for (let C = 0; C < g; C++) {
109
- const E = I[(C + g - 1) % g], B = I[C], Q = I[(C + 1) % g], i = B.x - E.x, s = B.y - E.y, t = Q.x - B.x, e = Q.y - B.y;
110
- i * e !== s * t && A.push(B);
109
+ const E = I[(C + g - 1) % g], B = I[C], Q = I[(C + 1) % g], i = B.x - E.x, s = B.y - E.y, t = Q.x - B.x, o = Q.y - B.y;
110
+ i * o !== s * t && A.push(B);
111
111
  }
112
112
  if (A.length === 0 && g > 0) {
113
113
  if (g === 1) return [I[0]];
@@ -166,8 +166,8 @@ function gA(I, A, g) {
166
166
  const Q = ((I.x - A.x) * C + (I.y - A.y) * E) / B;
167
167
  let i, s;
168
168
  Q < 0 ? (i = A.x, s = A.y) : Q > 1 ? (i = g.x, s = g.y) : (i = A.x + Q * C, s = A.y + Q * E);
169
- const t = I.x - i, e = I.y - s;
170
- return Math.sqrt(t * t + e * e);
169
+ const t = I.x - i, o = I.y - s;
170
+ return Math.sqrt(t * t + o * o);
171
171
  }
172
172
  function BA(I, A = 0.02) {
173
173
  const g = QA(I), C = A * g;
@@ -203,8 +203,8 @@ function iA(I) {
203
203
  if (!I || I.length === 0) return null;
204
204
  let A = I[0], g = I[0], C = I[0], E = I[0], B = A.x + A.y, Q = g.x - g.y, i = C.x + C.y, s = E.x - E.y;
205
205
  for (let t = 1; t < I.length; t++) {
206
- const e = I[t], o = e.x + e.y, a = e.x - e.y;
207
- o < B && (B = o, A = e), o > i && (i = o, C = e), a > Q && (Q = a, g = e), a < s && (s = a, E = e);
206
+ const o = I[t], n = o.x + o.y, e = o.x - o.y;
207
+ n < B && (B = n, A = o), n > i && (i = n, C = o), e > Q && (Q = e, g = o), e < s && (s = e, E = o);
208
208
  }
209
209
  return {
210
210
  topLeft: A,
@@ -259,12 +259,12 @@ let L = null;
259
259
  function Z() {
260
260
  return (L === null || L.byteLength === 0) && (L = new Float32Array(N.memory.buffer)), L;
261
261
  }
262
- function eA(I, A) {
262
+ function oA(I, A) {
263
263
  const g = A(I.length * 4, 4) >>> 0;
264
264
  return Z().set(I, g / 4), k = I.length, g;
265
265
  }
266
- function oA(I, A, g, C, E) {
267
- const B = eA(I, N.__wbindgen_malloc), Q = k, i = N.hysteresis_thresholding(B, Q, A, g, C, E);
266
+ function eA(I, A, g, C, E) {
267
+ const B = oA(I, N.__wbindgen_malloc), Q = k, i = N.hysteresis_thresholding(B, Q, A, g, C, E);
268
268
  var s = b(i[0], i[1]).slice();
269
269
  return N.__wbindgen_free(i[0], i[1] * 1, 1), s;
270
270
  }
@@ -286,8 +286,8 @@ function DA(I, A) {
286
286
  }
287
287
  function cA(I, A, g, C, E) {
288
288
  const B = p(I, N.__wbindgen_malloc), Q = k, i = p(A, N.__wbindgen_malloc), s = k, t = N.non_maximum_suppression(B, Q, i, s, g, C, E);
289
- var e = DA(t[0], t[1]).slice();
290
- return N.__wbindgen_free(t[0], t[1] * 4, 4), e;
289
+ var o = DA(t[0], t[1]).slice();
290
+ return N.__wbindgen_free(t[0], t[1] * 4, 4), o;
291
291
  }
292
292
  async function hA(I, A) {
293
293
  if (typeof Response == "function" && I instanceof Response) {
@@ -336,24 +336,24 @@ function NA(I, A, g, C = 5, E = 0) {
336
336
  E === 0 && (E = 0.3 * ((C - 1) * 0.5 - 1) + 0.8);
337
337
  const B = Math.floor(C / 2), Q = FA(C, E), i = new Uint8ClampedArray(A * g), s = new Uint8ClampedArray(A * g);
338
338
  for (let t = 0; t < g; t++) {
339
- const e = t * A;
340
- for (let o = 0; o < A; o++) {
341
- let a = 0;
342
- for (let n = -B; n <= B; n++) {
343
- const D = Math.min(A - 1, Math.max(0, o + n));
344
- a += I[e + D] * Q[B + n];
339
+ const o = t * A;
340
+ for (let n = 0; n < A; n++) {
341
+ let e = 0;
342
+ for (let a = -B; a <= B; a++) {
343
+ const D = Math.min(A - 1, Math.max(0, n + a));
344
+ e += I[o + D] * Q[B + a];
345
345
  }
346
- i[e + o] = a;
346
+ i[o + n] = e;
347
347
  }
348
348
  }
349
349
  for (let t = 0; t < A; t++)
350
- for (let e = 0; e < g; e++) {
351
- let o = 0;
352
- for (let a = -B; a <= B; a++) {
353
- const n = Math.min(g - 1, Math.max(0, e + a));
354
- o += i[n * A + t] * Q[B + a];
350
+ for (let o = 0; o < g; o++) {
351
+ let n = 0;
352
+ for (let e = -B; e <= B; e++) {
353
+ const a = Math.min(g - 1, Math.max(0, o + e));
354
+ n += i[a * A + t] * Q[B + e];
355
355
  }
356
- s[e * A + t] = Math.round(o);
356
+ s[o * A + t] = Math.round(n);
357
357
  }
358
358
  return s;
359
359
  }
@@ -373,8 +373,8 @@ function RA(I, A, g) {
373
373
  for (let B = 1; B < g - 1; B++) {
374
374
  const Q = B * A, i = (B - 1) * A, s = (B + 1) * A;
375
375
  for (let t = 1; t < A - 1; t++) {
376
- const e = Q + t, o = I[i + t - 1], a = I[i + t], n = I[i + t + 1], D = I[Q + t - 1], h = I[Q + t + 1], y = I[s + t - 1], c = I[s + t], r = I[s + t + 1], w = n - o + 2 * (h - D) + (r - y), F = y + 2 * c + r - (o + 2 * a + n);
377
- C[e] = w, E[e] = F;
376
+ const o = Q + t, n = I[i + t - 1], e = I[i + t], a = I[i + t + 1], D = I[Q + t - 1], h = I[Q + t + 1], y = I[s + t - 1], c = I[s + t], r = I[s + t + 1], w = a - n + 2 * (h - D) + (r - y), F = y + 2 * c + r - (n + 2 * e + a);
377
+ C[o] = w, E[o] = F;
378
378
  }
379
379
  }
380
380
  return { dx: C, dy: E };
@@ -387,32 +387,32 @@ function lA(I, A, g, C, E) {
387
387
  }
388
388
  for (let i = 1; i < C - 1; i++)
389
389
  for (let s = 1; s < g - 1; s++) {
390
- const t = i * g + s, e = B[t];
391
- if (e === 0) {
390
+ const t = i * g + s, o = B[t];
391
+ if (o === 0) {
392
392
  Q[t] = 0;
393
393
  continue;
394
394
  }
395
- const o = I[t], a = A[t];
396
- let n = 0, D = 0;
397
- const h = Math.abs(o), y = Math.abs(a);
395
+ const n = I[t], e = A[t];
396
+ let a = 0, D = 0;
397
+ const h = Math.abs(n), y = Math.abs(e);
398
398
  if (y > h * 2.4142)
399
- n = B[t - g], D = B[t + g];
399
+ a = B[t - g], D = B[t + g];
400
400
  else if (h > y * 2.4142)
401
- n = B[t - 1], D = B[t + 1];
401
+ a = B[t - 1], D = B[t + 1];
402
402
  else {
403
- const c = (o ^ a) < 0 ? -1 : 1;
404
- a > 0 ? (n = B[(i - 1) * g + (s - c)], D = B[(i + 1) * g + (s + c)]) : (n = B[(i + 1) * g + (s - c)], D = B[(i - 1) * g + (s + c)]), o > 0 && a > 0 || o < 0 && a < 0 ? (n = B[(i - 1) * g + (s + 1)], D = B[(i + 1) * g + (s - 1)]) : (n = B[(i - 1) * g + (s - 1)], D = B[(i + 1) * g + (s + 1)]);
403
+ const c = (n ^ e) < 0 ? -1 : 1;
404
+ e > 0 ? (a = B[(i - 1) * g + (s - c)], D = B[(i + 1) * g + (s + c)]) : (a = B[(i + 1) * g + (s - c)], D = B[(i - 1) * g + (s + c)]), n > 0 && e > 0 || n < 0 && e < 0 ? (a = B[(i - 1) * g + (s + 1)], D = B[(i + 1) * g + (s - 1)]) : (a = B[(i - 1) * g + (s - 1)], D = B[(i + 1) * g + (s + 1)]);
405
405
  }
406
- e >= n && e >= D ? Q[t] = e : Q[t] = 0;
406
+ o >= a && o >= D ? Q[t] = o : Q[t] = 0;
407
407
  }
408
408
  return Q;
409
409
  }
410
410
  function v(I, A, g, C, E) {
411
411
  const B = new Uint8Array(A * g), Q = [];
412
412
  for (let t = 1; t < g - 1; t++)
413
- for (let e = 1; e < A - 1; e++) {
414
- const o = t * A + e, a = I[o];
415
- a >= E ? (B[o] = 2, Q.push({ x: e, y: t })) : a >= C ? B[o] = 0 : B[o] = 1;
413
+ for (let o = 1; o < A - 1; o++) {
414
+ const n = t * A + o, e = I[n];
415
+ e >= E ? (B[n] = 2, Q.push({ x: o, y: t })) : e >= C ? B[n] = 0 : B[n] = 1;
416
416
  }
417
417
  for (let t = 0; t < A; t++)
418
418
  B[t] = 1, B[(g - 1) * A + t] = 1;
@@ -420,10 +420,10 @@ function v(I, A, g, C, E) {
420
420
  B[t * A] = 1, B[t * A + A - 1] = 1;
421
421
  const i = [-1, 0, 1, -1, 1, -1, 0, 1], s = [-1, -1, -1, 0, 0, 1, 1, 1];
422
422
  for (; Q.length > 0; ) {
423
- const { x: t, y: e } = Q.pop();
424
- for (let o = 0; o < 8; o++) {
425
- const a = t + i[o], n = e + s[o], D = n * A + a;
426
- B[D] === 0 && (B[D] = 2, Q.push({ x: a, y: n }));
423
+ const { x: t, y: o } = Q.pop();
424
+ for (let n = 0; n < 8; n++) {
425
+ const e = t + i[n], a = o + s[n], D = a * A + e;
426
+ B[D] === 0 && (B[D] = 2, Q.push({ x: e, y: a }));
427
427
  }
428
428
  }
429
429
  return B;
@@ -433,35 +433,35 @@ function GA(I, A, g, C = 5) {
433
433
  for (let i = 0; i < g; i++) {
434
434
  const s = i * A;
435
435
  for (let t = 0; t < A; t++) {
436
- let e = 0;
437
- for (let o = -E; o <= E; o++) {
438
- const a = t + o;
439
- if (a >= 0 && a < A) {
440
- const n = I[s + a];
441
- n > e && (e = n);
436
+ let o = 0;
437
+ for (let n = -E; n <= E; n++) {
438
+ const e = t + n;
439
+ if (e >= 0 && e < A) {
440
+ const a = I[s + e];
441
+ a > o && (o = a);
442
442
  }
443
443
  }
444
- B[s + t] = e;
444
+ B[s + t] = o;
445
445
  }
446
446
  }
447
447
  for (let i = 0; i < A; i++)
448
448
  for (let s = 0; s < g; s++) {
449
449
  let t = 0;
450
- for (let e = -E; e <= E; e++) {
451
- const o = s + e;
452
- if (o >= 0 && o < g) {
453
- const a = B[o * A + i];
454
- a > t && (t = a);
450
+ for (let o = -E; o <= E; o++) {
451
+ const n = s + o;
452
+ if (n >= 0 && n < g) {
453
+ const e = B[n * A + i];
454
+ e > t && (t = e);
455
455
  }
456
456
  }
457
457
  Q[s * A + i] = t;
458
458
  }
459
459
  return Q;
460
460
  }
461
- async function dA(I, A = {}) {
461
+ async function SA(I, A = {}) {
462
462
  const g = [], C = performance.now(), { width: E, height: B } = I;
463
463
  let Q = A.lowThreshold !== void 0 ? A.lowThreshold : 75, i = A.highThreshold !== void 0 ? A.highThreshold : 200;
464
- const s = A.kernelSize || 5, t = A.sigma || 0, e = A.L2gradient === void 0 ? !1 : A.L2gradient, o = A.applyDilation !== void 0 ? A.applyDilation : !0, a = A.dilationKernelSize || 5, n = A.useWasmHysteresis !== void 0 ? A.useWasmHysteresis : !1;
464
+ const s = A.kernelSize || 5, t = A.sigma || 0, o = A.L2gradient === void 0 ? !1 : A.L2gradient, n = A.applyDilation !== void 0 ? A.applyDilation : !0, e = A.dilationKernelSize || 5, a = A.useWasmHysteresis !== void 0 ? A.useWasmHysteresis : !1;
465
465
  Q >= i && (console.warn(`Canny Edge Detector: lowThreshold (${Q}) should be lower than highThreshold (${i}). Swapping them.`), [Q, i] = [i, Q]);
466
466
  let D = performance.now();
467
467
  const h = wA(I);
@@ -483,46 +483,46 @@ async function dA(I, A = {}) {
483
483
  y = performance.now(), g.push({ step: "Gradients", ms: (y - D).toFixed(2) }), D = performance.now();
484
484
  let F;
485
485
  try {
486
- await u, F = await cA(r, w, E, B, e);
486
+ await u, F = await cA(r, w, E, B, o);
487
487
  } catch {
488
- F = lA(r, w, E, B, e);
488
+ F = lA(r, w, E, B, o);
489
489
  }
490
490
  y = performance.now(), g.push({ step: "Non-Max Suppression", ms: (y - D).toFixed(2) }), D = performance.now();
491
- const R = e ? Q * Q : Q, S = e ? i * i : i;
492
- let d;
493
- if (n)
491
+ const R = o ? Q * Q : Q, d = o ? i * i : i;
492
+ let S;
493
+ if (a)
494
494
  try {
495
- await u, d = oA(F, E, B, R, S);
495
+ await u, S = eA(F, E, B, R, d);
496
496
  } catch (l) {
497
- console.warn("WASM hysteresis failed, falling back to JS:", l), d = v(F, E, B, R, S);
497
+ console.warn("WASM hysteresis failed, falling back to JS:", l), S = v(F, E, B, R, d);
498
498
  }
499
499
  else
500
- d = v(F, E, B, R, S);
500
+ S = v(F, E, B, R, d);
501
501
  y = performance.now(), g.push({ step: "Hysteresis", ms: (y - D).toFixed(2) }), D = performance.now();
502
502
  const G = new Uint8ClampedArray(E * B);
503
- for (let l = 0; l < d.length; l++)
504
- G[l] = d[l] === 2 ? 255 : 0;
503
+ for (let l = 0; l < S.length; l++)
504
+ G[l] = S[l] === 2 ? 255 : 0;
505
505
  y = performance.now(), g.push({ step: "Binary Image", ms: (y - D).toFixed(2) }), D = performance.now();
506
506
  let f = G;
507
- if (o)
507
+ if (n)
508
508
  try {
509
- await u, f = sA(G, E, B, a);
509
+ await u, f = sA(G, E, B, e);
510
510
  } catch {
511
- f = GA(G, E, B, a);
511
+ f = GA(G, E, B, e);
512
512
  }
513
513
  if (y = performance.now(), g.push({ step: "Dilation", ms: (y - D).toFixed(2) }), A.debug) {
514
514
  A.debug.dx = r, A.debug.dy = w;
515
515
  const l = new Float32Array(E * B);
516
516
  for (let J = 0; J < r.length; J++) {
517
517
  const U = r[J], H = w[J];
518
- l[J] = e ? Math.sqrt(U * U + H * H) : Math.abs(U) + Math.abs(H);
518
+ l[J] = o ? Math.sqrt(U * U + H * H) : Math.abs(U) + Math.abs(H);
519
519
  }
520
- A.debug.magnitude = l, A.debug.suppressed = F, A.debug.edgeMap = d, A.debug.cannyEdges = G, A.debug.finalEdges = f, A.debug.timings = g;
520
+ A.debug.magnitude = l, A.debug.suppressed = F, A.debug.edgeMap = S, A.debug.cannyEdges = G, A.debug.finalEdges = f, A.debug.timings = g;
521
521
  }
522
522
  const j = performance.now();
523
523
  return g.unshift({ step: "Total", ms: (j - C).toFixed(2) }), console.table(g), f;
524
524
  }
525
- class SA {
525
+ class dA {
526
526
  constructor(A = {}) {
527
527
  this.options = {
528
528
  targetFPS: A.targetFPS || 10,
@@ -738,11 +738,11 @@ function fA(I, A = 800) {
738
738
  };
739
739
  const B = A / E, Q = Math.round(g * B), i = Math.round(C * B), s = document.createElement("canvas");
740
740
  s.width = g, s.height = C, s.getContext("2d").putImageData(I, 0, 0);
741
- const e = document.createElement("canvas");
742
- e.width = Q, e.height = i;
743
- const o = e.getContext("2d");
744
- return o.imageSmoothingEnabled = !0, o.imageSmoothingQuality = "high", o.drawImage(s, 0, 0, g, C, 0, 0, Q, i), {
745
- scaledImageData: o.getImageData(0, 0, Q, i),
741
+ const o = document.createElement("canvas");
742
+ o.width = Q, o.height = i;
743
+ const n = o.getContext("2d");
744
+ return n.imageSmoothingEnabled = !0, n.imageSmoothingQuality = "high", n.drawImage(s, 0, 0, g, C, 0, 0, Q, i), {
745
+ scaledImageData: n.getImageData(0, 0, Q, i),
746
746
  scaleFactor: 1 / B,
747
747
  // Return inverse for compatibility with existing code
748
748
  originalDimensions: { width: g, height: C },
@@ -757,7 +757,7 @@ async function JA(I, A = {}) {
757
757
  scaleFactor: B,
758
758
  maxProcessingDimension: C
759
759
  });
760
- const { width: s, height: t } = E, e = await dA(E, {
760
+ const { width: s, height: t } = E, o = await SA(E, {
761
761
  lowThreshold: A.lowThreshold || 75,
762
762
  // Match OpenCV values
763
763
  highThreshold: A.highThreshold || 200,
@@ -766,32 +766,32 @@ async function JA(I, A = {}) {
766
766
  // Match OpenCV value
767
767
  dilationIterations: A.dilationIterations || 1,
768
768
  debug: g
769
- }), o = V(e, {
769
+ }), n = V(o, {
770
770
  minArea: (A.minArea || 1e3) / (B * B),
771
771
  // Adjust minArea for scaled image
772
772
  debug: g,
773
773
  width: s,
774
774
  height: t
775
775
  });
776
- if (!o || o.length === 0)
776
+ if (!n || n.length === 0)
777
777
  return console.log("No document detected"), {
778
778
  success: !1,
779
779
  message: "No document detected",
780
780
  debug: g
781
781
  };
782
- const a = o[0], n = EA(a, {
782
+ const e = n[0], a = EA(e, {
783
783
  epsilon: A.epsilon
784
784
  // Pass epsilon for approximation
785
785
  });
786
- let D = n;
786
+ let D = a;
787
787
  return B !== 1 && (D = {
788
- topLeft: { x: n.topLeft.x * B, y: n.topLeft.y * B },
789
- topRight: { x: n.topRight.x * B, y: n.topRight.y * B },
790
- bottomRight: { x: n.bottomRight.x * B, y: n.bottomRight.y * B },
791
- bottomLeft: { x: n.bottomLeft.x * B, y: n.bottomLeft.y * B }
788
+ topLeft: { x: a.topLeft.x * B, y: a.topLeft.y * B },
789
+ topRight: { x: a.topRight.x * B, y: a.topRight.y * B },
790
+ bottomRight: { x: a.bottomRight.x * B, y: a.bottomRight.y * B },
791
+ bottomLeft: { x: a.bottomLeft.x * B, y: a.bottomLeft.y * B }
792
792
  }), {
793
793
  success: !0,
794
- contour: a,
794
+ contour: e,
795
795
  corners: D,
796
796
  debug: g
797
797
  };
@@ -799,9 +799,9 @@ async function JA(I, A = {}) {
799
799
  function MA(I, A) {
800
800
  function g(s) {
801
801
  const t = [];
802
- for (let e = 0; e < 4; e++) {
803
- const [o, a] = s[e];
804
- t.push([o, a, 1, 0, 0, 0, -o * A[e][0], -a * A[e][0]]), t.push([0, 0, 0, o, a, 1, -o * A[e][1], -a * A[e][1]]);
802
+ for (let o = 0; o < 4; o++) {
803
+ const [n, e] = s[o];
804
+ t.push([n, e, 1, 0, 0, 0, -n * A[o][0], -e * A[o][0]]), t.push([0, 0, 0, n, e, 1, -n * A[o][1], -e * A[o][1]]);
805
805
  }
806
806
  return t;
807
807
  }
@@ -816,25 +816,25 @@ function MA(I, A) {
816
816
  A[3][1]
817
817
  ];
818
818
  function B(s, t) {
819
- const e = s.length, o = s[0].length, a = s.map((h) => h.slice()), n = t.slice();
820
- for (let h = 0; h < o; h++) {
819
+ const o = s.length, n = s[0].length, e = s.map((h) => h.slice()), a = t.slice();
820
+ for (let h = 0; h < n; h++) {
821
821
  let y = h;
822
- for (let c = h + 1; c < e; c++)
823
- Math.abs(a[c][h]) > Math.abs(a[y][h]) && (y = c);
824
- [a[h], a[y]] = [a[y], a[h]], [n[h], n[y]] = [n[y], n[h]];
825
- for (let c = h + 1; c < e; c++) {
826
- const r = a[c][h] / a[h][h];
827
- for (let w = h; w < o; w++)
828
- a[c][w] -= r * a[h][w];
829
- n[c] -= r * n[h];
822
+ for (let c = h + 1; c < o; c++)
823
+ Math.abs(e[c][h]) > Math.abs(e[y][h]) && (y = c);
824
+ [e[h], e[y]] = [e[y], e[h]], [a[h], a[y]] = [a[y], a[h]];
825
+ for (let c = h + 1; c < o; c++) {
826
+ const r = e[c][h] / e[h][h];
827
+ for (let w = h; w < n; w++)
828
+ e[c][w] -= r * e[h][w];
829
+ a[c] -= r * a[h];
830
830
  }
831
831
  }
832
- const D = new Array(o);
833
- for (let h = o - 1; h >= 0; h--) {
834
- let y = n[h];
835
- for (let c = h + 1; c < o; c++)
836
- y -= a[h][c] * D[c];
837
- D[h] = y / a[h][h];
832
+ const D = new Array(n);
833
+ for (let h = n - 1; h >= 0; h--) {
834
+ let y = a[h];
835
+ for (let c = h + 1; c < n; c++)
836
+ y -= e[h][c] * D[c];
837
+ D[h] = y / e[h][h];
838
838
  }
839
839
  return D;
840
840
  }
@@ -846,9 +846,9 @@ function MA(I, A) {
846
846
  ];
847
847
  }
848
848
  function LA(I, A, g) {
849
- const { topLeft: C, topRight: E, bottomRight: B, bottomLeft: Q } = g, i = Math.hypot(B.x - Q.x, B.y - Q.y), s = Math.hypot(E.x - C.x, E.y - C.y), t = Math.round(Math.max(i, s)), e = Math.hypot(E.x - B.x, E.y - B.y), o = Math.hypot(C.x - Q.x, C.y - Q.y), a = Math.round(Math.max(e, o));
850
- I.canvas.width = t, I.canvas.height = a;
851
- const n = [
849
+ const { topLeft: C, topRight: E, bottomRight: B, bottomLeft: Q } = g, i = Math.hypot(B.x - Q.x, B.y - Q.y), s = Math.hypot(E.x - C.x, E.y - C.y), t = Math.round(Math.max(i, s)), o = Math.hypot(E.x - B.x, E.y - B.y), n = Math.hypot(C.x - Q.x, C.y - Q.y), e = Math.round(Math.max(o, n));
850
+ I.canvas.width = t, I.canvas.height = e;
851
+ const a = [
852
852
  [C.x, C.y],
853
853
  [E.x, E.y],
854
854
  [B.x, B.y],
@@ -856,18 +856,18 @@ function LA(I, A, g) {
856
856
  ], D = [
857
857
  [0, 0],
858
858
  [t - 1, 0],
859
- [t - 1, a - 1],
860
- [0, a - 1]
861
- ], h = MA(n, D);
862
- YA(I, A, h, t, a);
859
+ [t - 1, e - 1],
860
+ [0, e - 1]
861
+ ], h = MA(a, D);
862
+ YA(I, A, h, t, e);
863
863
  }
864
864
  function mA(I) {
865
- const A = I[0][0], g = I[0][1], C = I[0][2], E = I[1][0], B = I[1][1], Q = I[1][2], i = I[2][0], s = I[2][1], t = I[2][2], e = B * t - Q * s, o = -(E * t - Q * i), a = E * s - B * i, n = -(g * t - C * s), D = A * t - C * i, h = -(A * s - g * i), y = g * Q - C * B, c = -(A * Q - C * E), r = A * B - g * E, w = A * e + g * o + C * a;
865
+ const A = I[0][0], g = I[0][1], C = I[0][2], E = I[1][0], B = I[1][1], Q = I[1][2], i = I[2][0], s = I[2][1], t = I[2][2], o = B * t - Q * s, n = -(E * t - Q * i), e = E * s - B * i, a = -(g * t - C * s), D = A * t - C * i, h = -(A * s - g * i), y = g * Q - C * B, c = -(A * Q - C * E), r = A * B - g * E, w = A * o + g * n + C * e;
866
866
  if (w === 0) throw new Error("Singular matrix");
867
867
  return [
868
- [e / w, n / w, y / w],
869
- [o / w, D / w, c / w],
870
- [a / w, h / w, r / w]
868
+ [o / w, a / w, y / w],
869
+ [n / w, D / w, c / w],
870
+ [e / w, h / w, r / w]
871
871
  ];
872
872
  }
873
873
  function YA(I, A, g, C, E) {
@@ -876,12 +876,12 @@ function YA(I, A, g, C, E) {
876
876
  const i = Q.getContext("2d");
877
877
  i.drawImage(A, 0, 0, Q.width, Q.height);
878
878
  const s = i.getImageData(0, 0, Q.width, Q.height), t = I.createImageData(C, E);
879
- for (let e = 0; e < E; e++)
880
- for (let o = 0; o < C; o++) {
881
- const a = B[2][0] * o + B[2][1] * e + B[2][2], n = (B[0][0] * o + B[0][1] * e + B[0][2]) / a, D = (B[1][0] * o + B[1][1] * e + B[1][2]) / a, h = Math.max(0, Math.min(Q.width - 2, n)), y = Math.max(0, Math.min(Q.height - 2, D)), c = Math.floor(h), r = Math.floor(y), w = h - c, F = y - r;
879
+ for (let o = 0; o < E; o++)
880
+ for (let n = 0; n < C; n++) {
881
+ const e = B[2][0] * n + B[2][1] * o + B[2][2], a = (B[0][0] * n + B[0][1] * o + B[0][2]) / e, D = (B[1][0] * n + B[1][1] * o + B[1][2]) / e, h = Math.max(0, Math.min(Q.width - 2, a)), y = Math.max(0, Math.min(Q.height - 2, D)), c = Math.floor(h), r = Math.floor(y), w = h - c, F = y - r;
882
882
  for (let R = 0; R < 4; R++) {
883
- const S = s.data[(r * Q.width + c) * 4 + R], d = s.data[(r * Q.width + (c + 1)) * 4 + R], G = s.data[((r + 1) * Q.width + c) * 4 + R], f = s.data[((r + 1) * Q.width + (c + 1)) * 4 + R];
884
- t.data[(e * C + o) * 4 + R] = (1 - w) * (1 - F) * S + w * (1 - F) * d + (1 - w) * F * G + w * F * f;
883
+ const d = s.data[(r * Q.width + c) * 4 + R], S = s.data[(r * Q.width + (c + 1)) * 4 + R], G = s.data[((r + 1) * Q.width + c) * 4 + R], f = s.data[((r + 1) * Q.width + (c + 1)) * 4 + R];
884
+ t.data[(o * C + n) * 4 + R] = (1 - w) * (1 - F) * d + w * (1 - F) * S + (1 - w) * F * G + w * F * f;
885
885
  }
886
886
  }
887
887
  I.putImageData(t, 0, 0);
@@ -889,51 +889,50 @@ function YA(I, A, g, C, E) {
889
889
  async function X(I, A = {}) {
890
890
  const g = A.mode || "detect", C = A.output || "canvas";
891
891
  A.debug;
892
- let E, B, Q;
892
+ let E;
893
893
  if (I instanceof ImageData)
894
- E = I, B = I.width, Q = I.height;
894
+ E = I, I.width, I.height;
895
895
  else {
896
- const e = document.createElement("canvas");
897
- e.width = I.width || I.naturalWidth, e.height = I.height || I.naturalHeight;
898
- const o = e.getContext("2d");
899
- o.drawImage(I, 0, 0, e.width, e.height), E = o.getImageData(0, 0, e.width, e.height), B = e.width, Q = e.height;
896
+ const s = document.createElement("canvas");
897
+ s.width = I.width || I.naturalWidth, s.height = I.height || I.naturalHeight;
898
+ const t = s.getContext("2d");
899
+ t.drawImage(I, 0, 0, s.width, s.height), E = t.getImageData(0, 0, s.width, s.height), s.width, s.height;
900
900
  }
901
- const i = await JA(E, A);
902
- if (!i.success)
901
+ const B = await JA(E, A);
902
+ if (!B.success)
903
903
  return {
904
904
  output: null,
905
905
  corners: null,
906
906
  contour: null,
907
- debug: i.debug,
907
+ debug: B.debug,
908
908
  success: !1,
909
- message: i.message || "No document detected"
909
+ message: B.message || "No document detected"
910
910
  };
911
- let s, t;
911
+ let Q, i;
912
912
  if (g === "detect")
913
- t = null;
913
+ i = null;
914
914
  else if (g === "extract") {
915
- s = document.createElement("canvas");
916
- const e = s.getContext("2d");
917
- LA(e, I, i.corners);
918
- } else
919
- s = document.createElement("canvas"), s.width = B, s.height = Q, s.getContext("2d").drawImage(I, 0, 0, B, Q);
920
- return g !== "detect" && s && (C === "canvas" ? t = s : C === "imagedata" ? t = s.getContext("2d").getImageData(0, 0, s.width, s.height) : C === "dataurl" ? t = s.toDataURL() : t = s), {
921
- output: t,
922
- corners: i.corners,
923
- contour: i.contour,
924
- debug: i.debug,
915
+ Q = document.createElement("canvas");
916
+ const s = Q.getContext("2d");
917
+ LA(s, I, B.corners);
918
+ }
919
+ return g !== "detect" && Q && (C === "canvas" ? i = Q : C === "imagedata" ? i = Q.getContext("2d").getImageData(0, 0, Q.width, Q.height) : C === "dataurl" ? i = Q.toDataURL() : i = Q), {
920
+ output: i,
921
+ corners: B.corners,
922
+ contour: B.contour,
923
+ debug: B.debug,
925
924
  success: !0,
926
925
  message: "Document detected"
927
926
  };
928
927
  }
929
928
  const uA = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
930
929
  __proto__: null,
931
- LiveScanner: SA,
930
+ LiveScanner: dA,
932
931
  checkWebcamAvailability: kA,
933
932
  scanDocument: X
934
933
  }, Symbol.toStringTag, { value: "Module" }));
935
934
  export {
936
- SA as LiveScanner,
935
+ dA as LiveScanner,
937
936
  kA as checkWebcamAvailability,
938
937
  X as scanDocument
939
938
  };