@uziee/document-scanner 1.1.0
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/README.md +18 -0
- package/dist/index.es.js +748 -0
- package/dist/index.umd.js +32 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @uzair2244/document-scanner
|
|
2
|
+
|
|
3
|
+
A high-performance, lightweight React component for real-time document detection, stability filtering, and perspective-corrected scanning.
|
|
4
|
+
|
|
5
|
+
## 🚀 Key Features
|
|
6
|
+
|
|
7
|
+
* **Real-Time Edge Detection:** Custom pixel-analysis algorithm to identify documents without the overhead of OpenCV.
|
|
8
|
+
* **Anti-Jitter Stability:** Built-in "Stability Counter" that prevents false triggers from noisy backgrounds or rugs.
|
|
9
|
+
* **Bilinear Warp Transformation:** Automatically "flattens" skewed documents into a clean, rectangular A4-proportioned image.
|
|
10
|
+
* **Zero Dependencies:** Runs entirely on native Canvas API—no massive WASM files or external ML models.
|
|
11
|
+
* **High-Res Capture:** Analyzes a low-res stream for performance but captures the final document from the full-resolution camera feed.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📦 Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @uzair2244/document-scanner
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
import $e, { useRef as z, useState as Ye, useEffect as vr } from "react";
|
|
2
|
+
var he = { exports: {} }, Q = {};
|
|
3
|
+
/**
|
|
4
|
+
* @license React
|
|
5
|
+
* react-jsx-runtime.production.min.js
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the MIT license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
var We;
|
|
13
|
+
function pr() {
|
|
14
|
+
if (We)
|
|
15
|
+
return Q;
|
|
16
|
+
We = 1;
|
|
17
|
+
var U = $e, m = Symbol.for("react.element"), V = Symbol.for("react.fragment"), k = Object.prototype.hasOwnProperty, W = U.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, B = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
18
|
+
function j(D, v, N) {
|
|
19
|
+
var E, M = {}, $ = null, J = null;
|
|
20
|
+
N !== void 0 && ($ = "" + N), v.key !== void 0 && ($ = "" + v.key), v.ref !== void 0 && (J = v.ref);
|
|
21
|
+
for (E in v)
|
|
22
|
+
k.call(v, E) && !B.hasOwnProperty(E) && (M[E] = v[E]);
|
|
23
|
+
if (D && D.defaultProps)
|
|
24
|
+
for (E in v = D.defaultProps, v)
|
|
25
|
+
M[E] === void 0 && (M[E] = v[E]);
|
|
26
|
+
return { $$typeof: m, type: D, key: $, ref: J, props: M, _owner: W.current };
|
|
27
|
+
}
|
|
28
|
+
return Q.Fragment = V, Q.jsx = j, Q.jsxs = j, Q;
|
|
29
|
+
}
|
|
30
|
+
var ee = {};
|
|
31
|
+
/**
|
|
32
|
+
* @license React
|
|
33
|
+
* react-jsx-runtime.development.js
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE file in the root directory of this source tree.
|
|
39
|
+
*/
|
|
40
|
+
var Me;
|
|
41
|
+
function hr() {
|
|
42
|
+
return Me || (Me = 1, {}.NODE_ENV !== "production" && function() {
|
|
43
|
+
var U = $e, m = Symbol.for("react.element"), V = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), W = Symbol.for("react.strict_mode"), B = Symbol.for("react.profiler"), j = Symbol.for("react.provider"), D = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), N = Symbol.for("react.suspense"), E = Symbol.for("react.suspense_list"), M = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), J = Symbol.for("react.offscreen"), a = Symbol.iterator, f = "@@iterator";
|
|
44
|
+
function d(e) {
|
|
45
|
+
if (e === null || typeof e != "object")
|
|
46
|
+
return null;
|
|
47
|
+
var r = a && e[a] || e[f];
|
|
48
|
+
return typeof r == "function" ? r : null;
|
|
49
|
+
}
|
|
50
|
+
var s = U.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
51
|
+
function l(e) {
|
|
52
|
+
{
|
|
53
|
+
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
|
|
54
|
+
t[n - 1] = arguments[n];
|
|
55
|
+
O("error", e, t);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function O(e, r, t) {
|
|
59
|
+
{
|
|
60
|
+
var n = s.ReactDebugCurrentFrame, u = n.getStackAddendum();
|
|
61
|
+
u !== "" && (r += "%s", t = t.concat([u]));
|
|
62
|
+
var c = t.map(function(i) {
|
|
63
|
+
return String(i);
|
|
64
|
+
});
|
|
65
|
+
c.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, c);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var h = !1, y = !1, C = !1, F = !1, Y = !1, P;
|
|
69
|
+
P = Symbol.for("react.module.reference");
|
|
70
|
+
function A(e) {
|
|
71
|
+
return !!(typeof e == "string" || typeof e == "function" || e === k || e === B || Y || e === W || e === N || e === E || F || e === J || h || y || C || typeof e == "object" && e !== null && (e.$$typeof === $ || e.$$typeof === M || e.$$typeof === j || e.$$typeof === D || e.$$typeof === v || // This needs to include all possible module reference object
|
|
72
|
+
// types supported by any Flight configuration anywhere since
|
|
73
|
+
// we don't know which Flight build this will end up being used
|
|
74
|
+
// with.
|
|
75
|
+
e.$$typeof === P || e.getModuleId !== void 0));
|
|
76
|
+
}
|
|
77
|
+
function _(e, r, t) {
|
|
78
|
+
var n = e.displayName;
|
|
79
|
+
if (n)
|
|
80
|
+
return n;
|
|
81
|
+
var u = r.displayName || r.name || "";
|
|
82
|
+
return u !== "" ? t + "(" + u + ")" : t;
|
|
83
|
+
}
|
|
84
|
+
function R(e) {
|
|
85
|
+
return e.displayName || "Context";
|
|
86
|
+
}
|
|
87
|
+
function b(e) {
|
|
88
|
+
if (e == null)
|
|
89
|
+
return null;
|
|
90
|
+
if (typeof e.tag == "number" && l("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
|
|
91
|
+
return e.displayName || e.name || null;
|
|
92
|
+
if (typeof e == "string")
|
|
93
|
+
return e;
|
|
94
|
+
switch (e) {
|
|
95
|
+
case k:
|
|
96
|
+
return "Fragment";
|
|
97
|
+
case V:
|
|
98
|
+
return "Portal";
|
|
99
|
+
case B:
|
|
100
|
+
return "Profiler";
|
|
101
|
+
case W:
|
|
102
|
+
return "StrictMode";
|
|
103
|
+
case N:
|
|
104
|
+
return "Suspense";
|
|
105
|
+
case E:
|
|
106
|
+
return "SuspenseList";
|
|
107
|
+
}
|
|
108
|
+
if (typeof e == "object")
|
|
109
|
+
switch (e.$$typeof) {
|
|
110
|
+
case D:
|
|
111
|
+
var r = e;
|
|
112
|
+
return R(r) + ".Consumer";
|
|
113
|
+
case j:
|
|
114
|
+
var t = e;
|
|
115
|
+
return R(t._context) + ".Provider";
|
|
116
|
+
case v:
|
|
117
|
+
return _(e, e.render, "ForwardRef");
|
|
118
|
+
case M:
|
|
119
|
+
var n = e.displayName || null;
|
|
120
|
+
return n !== null ? n : b(e.type) || "Memo";
|
|
121
|
+
case $: {
|
|
122
|
+
var u = e, c = u._payload, i = u._init;
|
|
123
|
+
try {
|
|
124
|
+
return b(i(c));
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
var w = Object.assign, L = 0, G, oe, ge, be, me, ye, Re;
|
|
133
|
+
function Ee() {
|
|
134
|
+
}
|
|
135
|
+
Ee.__reactDisabledLog = !0;
|
|
136
|
+
function Le() {
|
|
137
|
+
{
|
|
138
|
+
if (L === 0) {
|
|
139
|
+
G = console.log, oe = console.info, ge = console.warn, be = console.error, me = console.group, ye = console.groupCollapsed, Re = console.groupEnd;
|
|
140
|
+
var e = {
|
|
141
|
+
configurable: !0,
|
|
142
|
+
enumerable: !0,
|
|
143
|
+
value: Ee,
|
|
144
|
+
writable: !0
|
|
145
|
+
};
|
|
146
|
+
Object.defineProperties(console, {
|
|
147
|
+
info: e,
|
|
148
|
+
log: e,
|
|
149
|
+
warn: e,
|
|
150
|
+
error: e,
|
|
151
|
+
group: e,
|
|
152
|
+
groupCollapsed: e,
|
|
153
|
+
groupEnd: e
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
L++;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function Ue() {
|
|
160
|
+
{
|
|
161
|
+
if (L--, L === 0) {
|
|
162
|
+
var e = {
|
|
163
|
+
configurable: !0,
|
|
164
|
+
enumerable: !0,
|
|
165
|
+
writable: !0
|
|
166
|
+
};
|
|
167
|
+
Object.defineProperties(console, {
|
|
168
|
+
log: w({}, e, {
|
|
169
|
+
value: G
|
|
170
|
+
}),
|
|
171
|
+
info: w({}, e, {
|
|
172
|
+
value: oe
|
|
173
|
+
}),
|
|
174
|
+
warn: w({}, e, {
|
|
175
|
+
value: ge
|
|
176
|
+
}),
|
|
177
|
+
error: w({}, e, {
|
|
178
|
+
value: be
|
|
179
|
+
}),
|
|
180
|
+
group: w({}, e, {
|
|
181
|
+
value: me
|
|
182
|
+
}),
|
|
183
|
+
groupCollapsed: w({}, e, {
|
|
184
|
+
value: ye
|
|
185
|
+
}),
|
|
186
|
+
groupEnd: w({}, e, {
|
|
187
|
+
value: Re
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
L < 0 && l("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
var ie = s.ReactCurrentDispatcher, se;
|
|
195
|
+
function re(e, r, t) {
|
|
196
|
+
{
|
|
197
|
+
if (se === void 0)
|
|
198
|
+
try {
|
|
199
|
+
throw Error();
|
|
200
|
+
} catch (u) {
|
|
201
|
+
var n = u.stack.trim().match(/\n( *(at )?)/);
|
|
202
|
+
se = n && n[1] || "";
|
|
203
|
+
}
|
|
204
|
+
return `
|
|
205
|
+
` + se + e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
var ue = !1, te;
|
|
209
|
+
{
|
|
210
|
+
var Ve = typeof WeakMap == "function" ? WeakMap : Map;
|
|
211
|
+
te = new Ve();
|
|
212
|
+
}
|
|
213
|
+
function _e(e, r) {
|
|
214
|
+
if (!e || ue)
|
|
215
|
+
return "";
|
|
216
|
+
{
|
|
217
|
+
var t = te.get(e);
|
|
218
|
+
if (t !== void 0)
|
|
219
|
+
return t;
|
|
220
|
+
}
|
|
221
|
+
var n;
|
|
222
|
+
ue = !0;
|
|
223
|
+
var u = Error.prepareStackTrace;
|
|
224
|
+
Error.prepareStackTrace = void 0;
|
|
225
|
+
var c;
|
|
226
|
+
c = ie.current, ie.current = null, Le();
|
|
227
|
+
try {
|
|
228
|
+
if (r) {
|
|
229
|
+
var i = function() {
|
|
230
|
+
throw Error();
|
|
231
|
+
};
|
|
232
|
+
if (Object.defineProperty(i.prototype, "props", {
|
|
233
|
+
set: function() {
|
|
234
|
+
throw Error();
|
|
235
|
+
}
|
|
236
|
+
}), typeof Reflect == "object" && Reflect.construct) {
|
|
237
|
+
try {
|
|
238
|
+
Reflect.construct(i, []);
|
|
239
|
+
} catch (T) {
|
|
240
|
+
n = T;
|
|
241
|
+
}
|
|
242
|
+
Reflect.construct(e, [], i);
|
|
243
|
+
} else {
|
|
244
|
+
try {
|
|
245
|
+
i.call();
|
|
246
|
+
} catch (T) {
|
|
247
|
+
n = T;
|
|
248
|
+
}
|
|
249
|
+
e.call(i.prototype);
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
try {
|
|
253
|
+
throw Error();
|
|
254
|
+
} catch (T) {
|
|
255
|
+
n = T;
|
|
256
|
+
}
|
|
257
|
+
e();
|
|
258
|
+
}
|
|
259
|
+
} catch (T) {
|
|
260
|
+
if (T && n && typeof T.stack == "string") {
|
|
261
|
+
for (var o = T.stack.split(`
|
|
262
|
+
`), x = n.stack.split(`
|
|
263
|
+
`), p = o.length - 1, g = x.length - 1; p >= 1 && g >= 0 && o[p] !== x[g]; )
|
|
264
|
+
g--;
|
|
265
|
+
for (; p >= 1 && g >= 0; p--, g--)
|
|
266
|
+
if (o[p] !== x[g]) {
|
|
267
|
+
if (p !== 1 || g !== 1)
|
|
268
|
+
do
|
|
269
|
+
if (p--, g--, g < 0 || o[p] !== x[g]) {
|
|
270
|
+
var I = `
|
|
271
|
+
` + o[p].replace(" at new ", " at ");
|
|
272
|
+
return e.displayName && I.includes("<anonymous>") && (I = I.replace("<anonymous>", e.displayName)), typeof e == "function" && te.set(e, I), I;
|
|
273
|
+
}
|
|
274
|
+
while (p >= 1 && g >= 0);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} finally {
|
|
279
|
+
ue = !1, ie.current = c, Ue(), Error.prepareStackTrace = u;
|
|
280
|
+
}
|
|
281
|
+
var K = e ? e.displayName || e.name : "", q = K ? re(K) : "";
|
|
282
|
+
return typeof e == "function" && te.set(e, q), q;
|
|
283
|
+
}
|
|
284
|
+
function Ne(e, r, t) {
|
|
285
|
+
return _e(e, !1);
|
|
286
|
+
}
|
|
287
|
+
function Be(e) {
|
|
288
|
+
var r = e.prototype;
|
|
289
|
+
return !!(r && r.isReactComponent);
|
|
290
|
+
}
|
|
291
|
+
function ne(e, r, t) {
|
|
292
|
+
if (e == null)
|
|
293
|
+
return "";
|
|
294
|
+
if (typeof e == "function")
|
|
295
|
+
return _e(e, Be(e));
|
|
296
|
+
if (typeof e == "string")
|
|
297
|
+
return re(e);
|
|
298
|
+
switch (e) {
|
|
299
|
+
case N:
|
|
300
|
+
return re("Suspense");
|
|
301
|
+
case E:
|
|
302
|
+
return re("SuspenseList");
|
|
303
|
+
}
|
|
304
|
+
if (typeof e == "object")
|
|
305
|
+
switch (e.$$typeof) {
|
|
306
|
+
case v:
|
|
307
|
+
return Ne(e.render);
|
|
308
|
+
case M:
|
|
309
|
+
return ne(e.type, r, t);
|
|
310
|
+
case $: {
|
|
311
|
+
var n = e, u = n._payload, c = n._init;
|
|
312
|
+
try {
|
|
313
|
+
return ne(c(u), r, t);
|
|
314
|
+
} catch {
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return "";
|
|
319
|
+
}
|
|
320
|
+
var X = Object.prototype.hasOwnProperty, xe = {}, Ce = s.ReactDebugCurrentFrame;
|
|
321
|
+
function ae(e) {
|
|
322
|
+
if (e) {
|
|
323
|
+
var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
|
|
324
|
+
Ce.setExtraStackFrame(t);
|
|
325
|
+
} else
|
|
326
|
+
Ce.setExtraStackFrame(null);
|
|
327
|
+
}
|
|
328
|
+
function qe(e, r, t, n, u) {
|
|
329
|
+
{
|
|
330
|
+
var c = Function.call.bind(X);
|
|
331
|
+
for (var i in e)
|
|
332
|
+
if (c(e, i)) {
|
|
333
|
+
var o = void 0;
|
|
334
|
+
try {
|
|
335
|
+
if (typeof e[i] != "function") {
|
|
336
|
+
var x = Error((n || "React class") + ": " + t + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
|
|
337
|
+
throw x.name = "Invariant Violation", x;
|
|
338
|
+
}
|
|
339
|
+
o = e[i](r, i, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
|
|
340
|
+
} catch (p) {
|
|
341
|
+
o = p;
|
|
342
|
+
}
|
|
343
|
+
o && !(o instanceof Error) && (ae(u), l("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, i, typeof o), ae(null)), o instanceof Error && !(o.message in xe) && (xe[o.message] = !0, ae(u), l("Failed %s type: %s", t, o.message), ae(null));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
var Je = Array.isArray;
|
|
348
|
+
function le(e) {
|
|
349
|
+
return Je(e);
|
|
350
|
+
}
|
|
351
|
+
function He(e) {
|
|
352
|
+
{
|
|
353
|
+
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
354
|
+
return t;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function Ke(e) {
|
|
358
|
+
try {
|
|
359
|
+
return we(e), !1;
|
|
360
|
+
} catch {
|
|
361
|
+
return !0;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function we(e) {
|
|
365
|
+
return "" + e;
|
|
366
|
+
}
|
|
367
|
+
function Te(e) {
|
|
368
|
+
if (Ke(e))
|
|
369
|
+
return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", He(e)), we(e);
|
|
370
|
+
}
|
|
371
|
+
var Z = s.ReactCurrentOwner, ze = {
|
|
372
|
+
key: !0,
|
|
373
|
+
ref: !0,
|
|
374
|
+
__self: !0,
|
|
375
|
+
__source: !0
|
|
376
|
+
}, Se, je, ce;
|
|
377
|
+
ce = {};
|
|
378
|
+
function Ge(e) {
|
|
379
|
+
if (X.call(e, "ref")) {
|
|
380
|
+
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
|
|
381
|
+
if (r && r.isReactWarning)
|
|
382
|
+
return !1;
|
|
383
|
+
}
|
|
384
|
+
return e.ref !== void 0;
|
|
385
|
+
}
|
|
386
|
+
function Xe(e) {
|
|
387
|
+
if (X.call(e, "key")) {
|
|
388
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
389
|
+
if (r && r.isReactWarning)
|
|
390
|
+
return !1;
|
|
391
|
+
}
|
|
392
|
+
return e.key !== void 0;
|
|
393
|
+
}
|
|
394
|
+
function Ze(e, r) {
|
|
395
|
+
if (typeof e.ref == "string" && Z.current && r && Z.current.stateNode !== r) {
|
|
396
|
+
var t = b(Z.current.type);
|
|
397
|
+
ce[t] || (l('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', b(Z.current.type), e.ref), ce[t] = !0);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function Qe(e, r) {
|
|
401
|
+
{
|
|
402
|
+
var t = function() {
|
|
403
|
+
Se || (Se = !0, l("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
|
|
404
|
+
};
|
|
405
|
+
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
406
|
+
get: t,
|
|
407
|
+
configurable: !0
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function er(e, r) {
|
|
412
|
+
{
|
|
413
|
+
var t = function() {
|
|
414
|
+
je || (je = !0, l("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
|
|
415
|
+
};
|
|
416
|
+
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
|
|
417
|
+
get: t,
|
|
418
|
+
configurable: !0
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
var rr = function(e, r, t, n, u, c, i) {
|
|
423
|
+
var o = {
|
|
424
|
+
// This tag allows us to uniquely identify this as a React Element
|
|
425
|
+
$$typeof: m,
|
|
426
|
+
// Built-in properties that belong on the element
|
|
427
|
+
type: e,
|
|
428
|
+
key: r,
|
|
429
|
+
ref: t,
|
|
430
|
+
props: i,
|
|
431
|
+
// Record the component responsible for creating this element.
|
|
432
|
+
_owner: c
|
|
433
|
+
};
|
|
434
|
+
return o._store = {}, Object.defineProperty(o._store, "validated", {
|
|
435
|
+
configurable: !1,
|
|
436
|
+
enumerable: !1,
|
|
437
|
+
writable: !0,
|
|
438
|
+
value: !1
|
|
439
|
+
}), Object.defineProperty(o, "_self", {
|
|
440
|
+
configurable: !1,
|
|
441
|
+
enumerable: !1,
|
|
442
|
+
writable: !1,
|
|
443
|
+
value: n
|
|
444
|
+
}), Object.defineProperty(o, "_source", {
|
|
445
|
+
configurable: !1,
|
|
446
|
+
enumerable: !1,
|
|
447
|
+
writable: !1,
|
|
448
|
+
value: u
|
|
449
|
+
}), Object.freeze && (Object.freeze(o.props), Object.freeze(o)), o;
|
|
450
|
+
};
|
|
451
|
+
function tr(e, r, t, n, u) {
|
|
452
|
+
{
|
|
453
|
+
var c, i = {}, o = null, x = null;
|
|
454
|
+
t !== void 0 && (Te(t), o = "" + t), Xe(r) && (Te(r.key), o = "" + r.key), Ge(r) && (x = r.ref, Ze(r, u));
|
|
455
|
+
for (c in r)
|
|
456
|
+
X.call(r, c) && !ze.hasOwnProperty(c) && (i[c] = r[c]);
|
|
457
|
+
if (e && e.defaultProps) {
|
|
458
|
+
var p = e.defaultProps;
|
|
459
|
+
for (c in p)
|
|
460
|
+
i[c] === void 0 && (i[c] = p[c]);
|
|
461
|
+
}
|
|
462
|
+
if (o || x) {
|
|
463
|
+
var g = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
|
|
464
|
+
o && Qe(i, g), x && er(i, g);
|
|
465
|
+
}
|
|
466
|
+
return rr(e, o, x, u, n, Z.current, i);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
var fe = s.ReactCurrentOwner, Oe = s.ReactDebugCurrentFrame;
|
|
470
|
+
function H(e) {
|
|
471
|
+
if (e) {
|
|
472
|
+
var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
|
|
473
|
+
Oe.setExtraStackFrame(t);
|
|
474
|
+
} else
|
|
475
|
+
Oe.setExtraStackFrame(null);
|
|
476
|
+
}
|
|
477
|
+
var de;
|
|
478
|
+
de = !1;
|
|
479
|
+
function ve(e) {
|
|
480
|
+
return typeof e == "object" && e !== null && e.$$typeof === m;
|
|
481
|
+
}
|
|
482
|
+
function Pe() {
|
|
483
|
+
{
|
|
484
|
+
if (fe.current) {
|
|
485
|
+
var e = b(fe.current.type);
|
|
486
|
+
if (e)
|
|
487
|
+
return `
|
|
488
|
+
|
|
489
|
+
Check the render method of \`` + e + "`.";
|
|
490
|
+
}
|
|
491
|
+
return "";
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function nr(e) {
|
|
495
|
+
{
|
|
496
|
+
if (e !== void 0) {
|
|
497
|
+
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
|
|
498
|
+
return `
|
|
499
|
+
|
|
500
|
+
Check your code at ` + r + ":" + t + ".";
|
|
501
|
+
}
|
|
502
|
+
return "";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
var ke = {};
|
|
506
|
+
function ar(e) {
|
|
507
|
+
{
|
|
508
|
+
var r = Pe();
|
|
509
|
+
if (!r) {
|
|
510
|
+
var t = typeof e == "string" ? e : e.displayName || e.name;
|
|
511
|
+
t && (r = `
|
|
512
|
+
|
|
513
|
+
Check the top-level render call using <` + t + ">.");
|
|
514
|
+
}
|
|
515
|
+
return r;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function De(e, r) {
|
|
519
|
+
{
|
|
520
|
+
if (!e._store || e._store.validated || e.key != null)
|
|
521
|
+
return;
|
|
522
|
+
e._store.validated = !0;
|
|
523
|
+
var t = ar(r);
|
|
524
|
+
if (ke[t])
|
|
525
|
+
return;
|
|
526
|
+
ke[t] = !0;
|
|
527
|
+
var n = "";
|
|
528
|
+
e && e._owner && e._owner !== fe.current && (n = " It was passed a child from " + b(e._owner.type) + "."), H(e), l('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), H(null);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function Fe(e, r) {
|
|
532
|
+
{
|
|
533
|
+
if (typeof e != "object")
|
|
534
|
+
return;
|
|
535
|
+
if (le(e))
|
|
536
|
+
for (var t = 0; t < e.length; t++) {
|
|
537
|
+
var n = e[t];
|
|
538
|
+
ve(n) && De(n, r);
|
|
539
|
+
}
|
|
540
|
+
else if (ve(e))
|
|
541
|
+
e._store && (e._store.validated = !0);
|
|
542
|
+
else if (e) {
|
|
543
|
+
var u = d(e);
|
|
544
|
+
if (typeof u == "function" && u !== e.entries)
|
|
545
|
+
for (var c = u.call(e), i; !(i = c.next()).done; )
|
|
546
|
+
ve(i.value) && De(i.value, r);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function or(e) {
|
|
551
|
+
{
|
|
552
|
+
var r = e.type;
|
|
553
|
+
if (r == null || typeof r == "string")
|
|
554
|
+
return;
|
|
555
|
+
var t;
|
|
556
|
+
if (typeof r == "function")
|
|
557
|
+
t = r.propTypes;
|
|
558
|
+
else if (typeof r == "object" && (r.$$typeof === v || // Note: Memo only checks outer props here.
|
|
559
|
+
// Inner props are checked in the reconciler.
|
|
560
|
+
r.$$typeof === M))
|
|
561
|
+
t = r.propTypes;
|
|
562
|
+
else
|
|
563
|
+
return;
|
|
564
|
+
if (t) {
|
|
565
|
+
var n = b(r);
|
|
566
|
+
qe(t, e.props, "prop", n, e);
|
|
567
|
+
} else if (r.PropTypes !== void 0 && !de) {
|
|
568
|
+
de = !0;
|
|
569
|
+
var u = b(r);
|
|
570
|
+
l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
|
|
571
|
+
}
|
|
572
|
+
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function ir(e) {
|
|
576
|
+
{
|
|
577
|
+
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
|
|
578
|
+
var n = r[t];
|
|
579
|
+
if (n !== "children" && n !== "key") {
|
|
580
|
+
H(e), l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), H(null);
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
e.ref !== null && (H(e), l("Invalid attribute `ref` supplied to `React.Fragment`."), H(null));
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
var Ae = {};
|
|
588
|
+
function Ie(e, r, t, n, u, c) {
|
|
589
|
+
{
|
|
590
|
+
var i = A(e);
|
|
591
|
+
if (!i) {
|
|
592
|
+
var o = "";
|
|
593
|
+
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (o += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
|
|
594
|
+
var x = nr(u);
|
|
595
|
+
x ? o += x : o += Pe();
|
|
596
|
+
var p;
|
|
597
|
+
e === null ? p = "null" : le(e) ? p = "array" : e !== void 0 && e.$$typeof === m ? (p = "<" + (b(e.type) || "Unknown") + " />", o = " Did you accidentally export a JSX literal instead of a component?") : p = typeof e, l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", p, o);
|
|
598
|
+
}
|
|
599
|
+
var g = tr(e, r, t, u, c);
|
|
600
|
+
if (g == null)
|
|
601
|
+
return g;
|
|
602
|
+
if (i) {
|
|
603
|
+
var I = r.children;
|
|
604
|
+
if (I !== void 0)
|
|
605
|
+
if (n)
|
|
606
|
+
if (le(I)) {
|
|
607
|
+
for (var K = 0; K < I.length; K++)
|
|
608
|
+
Fe(I[K], e);
|
|
609
|
+
Object.freeze && Object.freeze(I);
|
|
610
|
+
} else
|
|
611
|
+
l("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
612
|
+
else
|
|
613
|
+
Fe(I, e);
|
|
614
|
+
}
|
|
615
|
+
if (X.call(r, "key")) {
|
|
616
|
+
var q = b(e), T = Object.keys(r).filter(function(dr) {
|
|
617
|
+
return dr !== "key";
|
|
618
|
+
}), pe = T.length > 0 ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
619
|
+
if (!Ae[q + pe]) {
|
|
620
|
+
var fr = T.length > 0 ? "{" + T.join(": ..., ") + ": ...}" : "{}";
|
|
621
|
+
l(`A props object containing a "key" prop is being spread into JSX:
|
|
622
|
+
let props = %s;
|
|
623
|
+
<%s {...props} />
|
|
624
|
+
React keys must be passed directly to JSX without using spread:
|
|
625
|
+
let props = %s;
|
|
626
|
+
<%s key={someKey} {...props} />`, pe, q, fr, q), Ae[q + pe] = !0;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return e === k ? ir(g) : or(g), g;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
function sr(e, r, t) {
|
|
633
|
+
return Ie(e, r, t, !0);
|
|
634
|
+
}
|
|
635
|
+
function ur(e, r, t) {
|
|
636
|
+
return Ie(e, r, t, !1);
|
|
637
|
+
}
|
|
638
|
+
var lr = ur, cr = sr;
|
|
639
|
+
ee.Fragment = k, ee.jsx = lr, ee.jsxs = cr;
|
|
640
|
+
}()), ee;
|
|
641
|
+
}
|
|
642
|
+
({}).NODE_ENV === "production" ? he.exports = pr() : he.exports = hr();
|
|
643
|
+
var S = he.exports;
|
|
644
|
+
const gr = ({ onCapture: U }) => {
|
|
645
|
+
const m = z(null), V = z(null), k = z(null), [W, B] = Ye(!1), j = z(null), D = z([]), v = z(0);
|
|
646
|
+
vr(() => {
|
|
647
|
+
k.current || (k.current = document.createElement("canvas"));
|
|
648
|
+
let a = null;
|
|
649
|
+
async function f() {
|
|
650
|
+
try {
|
|
651
|
+
const s = await navigator.mediaDevices.getUserMedia({
|
|
652
|
+
video: { facingMode: "environment", width: { ideal: 1920 } }
|
|
653
|
+
});
|
|
654
|
+
m.current && (m.current.srcObject = s, m.current.play(), a = requestAnimationFrame(d));
|
|
655
|
+
} catch (s) {
|
|
656
|
+
console.error("Camera access error:", s);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function d() {
|
|
660
|
+
var s;
|
|
661
|
+
if (((s = m.current) == null ? void 0 : s.readyState) >= 2) {
|
|
662
|
+
const l = m.current, O = V.current, h = O.getContext("2d");
|
|
663
|
+
O.width !== l.videoWidth && (O.width = l.videoWidth, O.height = l.videoHeight), h.drawImage(l, 0, 0);
|
|
664
|
+
const y = E(l);
|
|
665
|
+
y ? (j.current && N(y, j.current) ? v.current = Math.min(15, v.current + 1) : v.current = 0, D.current.push(y), D.current.length > 10 && D.current.shift(), j.current = M(D.current), v.current > 5 && B(!0)) : (v.current = Math.max(0, v.current - 2), v.current === 0 && (j.current = null, B(!1))), W && j.current && $(h, j.current);
|
|
666
|
+
}
|
|
667
|
+
a = requestAnimationFrame(d);
|
|
668
|
+
}
|
|
669
|
+
return f(), () => cancelAnimationFrame(a);
|
|
670
|
+
}, [W]);
|
|
671
|
+
const N = (a, f) => Math.abs(a.tl[0] - f.tl[0]) + Math.abs(a.tl[1] - f.tl[1]) < 50, E = (a) => {
|
|
672
|
+
const d = Math.floor(a.videoWidth * 0.15), s = Math.floor(a.videoHeight * 0.15), l = k.current.getContext("2d");
|
|
673
|
+
k.current.width = d, k.current.height = s, l.drawImage(a, 0, 0, d, s);
|
|
674
|
+
const O = l.getImageData(0, 0, d, s).data;
|
|
675
|
+
let h = [d, s], y = [0, s], C = [d, 0], F = [0, 0], Y = 0;
|
|
676
|
+
for (let _ = 10; _ < s - 10; _++)
|
|
677
|
+
for (let R = 10; R < d - 10; R++) {
|
|
678
|
+
const b = (_ * d + R) * 4, w = O[b], L = O[b + 1], G = O[b + 2];
|
|
679
|
+
w > 190 && L > 190 && G > 180 && Math.abs(w - L) < 20 && Math.abs(L - G) < 20 && (Y++, R + _ < h[0] + h[1] && (h = [R, _]), R - _ > y[0] - y[1] && (y = [R, _]), R - _ < C[0] - C[1] && (C = [R, _]), R + _ > F[0] + F[1] && (F = [R, _]));
|
|
680
|
+
}
|
|
681
|
+
const P = y[0] - h[0], A = C[1] - h[1];
|
|
682
|
+
return Y < d * s * 0.08 || P < d * 0.3 || A < s * 0.3 ? null : {
|
|
683
|
+
tl: [h[0] / 0.15, h[1] / 0.15],
|
|
684
|
+
tr: [y[0] / 0.15, y[1] / 0.15],
|
|
685
|
+
bl: [C[0] / 0.15, C[1] / 0.15],
|
|
686
|
+
br: [F[0] / 0.15, F[1] / 0.15]
|
|
687
|
+
};
|
|
688
|
+
}, M = (a) => {
|
|
689
|
+
const f = { tl: [0, 0], tr: [0, 0], bl: [0, 0], br: [0, 0] };
|
|
690
|
+
return a.forEach((d) => {
|
|
691
|
+
["tl", "tr", "bl", "br"].forEach((s) => {
|
|
692
|
+
f[s][0] += d[s][0] / a.length, f[s][1] += d[s][1] / a.length;
|
|
693
|
+
});
|
|
694
|
+
}), f;
|
|
695
|
+
}, $ = (a, f) => {
|
|
696
|
+
a.strokeStyle = "#00FF44", a.lineWidth = 12, a.lineCap = "round", a.shadowBlur = 15, a.shadowColor = "#00FF44", a.beginPath(), a.moveTo(...f.tl), a.lineTo(...f.tr), a.lineTo(...f.br), a.lineTo(...f.bl), a.closePath(), a.stroke(), a.shadowBlur = 0;
|
|
697
|
+
}, J = () => {
|
|
698
|
+
const a = m.current, f = j.current;
|
|
699
|
+
if (!a || !f)
|
|
700
|
+
return;
|
|
701
|
+
const d = 1240, s = 1754, l = document.createElement("canvas");
|
|
702
|
+
l.width = d, l.height = s;
|
|
703
|
+
const O = l.getContext("2d"), h = document.createElement("canvas");
|
|
704
|
+
h.width = a.videoWidth, h.height = a.videoHeight, h.getContext("2d").drawImage(a, 0, 0);
|
|
705
|
+
const y = h.getContext("2d").getImageData(0, 0, h.width, h.height), C = O.createImageData(d, s);
|
|
706
|
+
for (let F = 0; F < s; F++)
|
|
707
|
+
for (let Y = 0; Y < d; Y++) {
|
|
708
|
+
const P = Y / d, A = F / s, _ = Math.floor((1 - P) * (1 - A) * f.tl[0] + P * (1 - A) * f.tr[0] + (1 - P) * A * f.bl[0] + P * A * f.br[0]), R = Math.floor((1 - P) * (1 - A) * f.tl[1] + P * (1 - A) * f.tr[1] + (1 - P) * A * f.bl[1] + P * A * f.br[1]), b = (F * d + Y) * 4, w = (R * h.width + _) * 4;
|
|
709
|
+
C.data[b] = y.data[w], C.data[b + 1] = y.data[w + 1], C.data[b + 2] = y.data[w + 2], C.data[b + 3] = 255;
|
|
710
|
+
}
|
|
711
|
+
O.putImageData(C, 0, 0), U(l.toDataURL("image/jpeg", 0.92));
|
|
712
|
+
};
|
|
713
|
+
return /* @__PURE__ */ S.jsxs("div", { style: { textAlign: "center", background: "#111", minHeight: "100vh", padding: "20px" }, children: [
|
|
714
|
+
/* @__PURE__ */ S.jsxs("div", { style: { position: "relative", borderRadius: "30px", overflow: "hidden", border: "5px solid #333", display: "inline-block" }, children: [
|
|
715
|
+
/* @__PURE__ */ S.jsx("video", { ref: m, style: { display: "none" } }),
|
|
716
|
+
/* @__PURE__ */ S.jsx("canvas", { ref: V, style: { width: "100%", maxWidth: "500px", display: "block" } }),
|
|
717
|
+
W && /* @__PURE__ */ S.jsx("div", { style: { position: "absolute", bottom: "20px", left: "50%", transform: "translateX(-50%)", background: "#00FF44", color: "#000", padding: "8px 20px", borderRadius: "20px", fontWeight: "bold" }, children: "READY TO SCAN" })
|
|
718
|
+
] }),
|
|
719
|
+
/* @__PURE__ */ S.jsx("button", { onClick: J, disabled: !W, style: {
|
|
720
|
+
display: "block",
|
|
721
|
+
margin: "20px auto",
|
|
722
|
+
padding: "20px 50px",
|
|
723
|
+
borderRadius: "50px",
|
|
724
|
+
border: "none",
|
|
725
|
+
backgroundColor: W ? "#00FF44" : "#444",
|
|
726
|
+
color: W ? "#000" : "#888",
|
|
727
|
+
fontSize: "18px",
|
|
728
|
+
fontWeight: "bold",
|
|
729
|
+
cursor: "pointer"
|
|
730
|
+
}, children: "CROP & SAVE DOCUMENT" })
|
|
731
|
+
] });
|
|
732
|
+
};
|
|
733
|
+
function mr() {
|
|
734
|
+
const [U, m] = Ye(null);
|
|
735
|
+
return /* @__PURE__ */ S.jsxs("div", { style: { textAlign: "center", padding: "20px", fontFamily: "sans-serif" }, children: [
|
|
736
|
+
/* @__PURE__ */ S.jsx("h1", { children: "JS Doc Scanner" }),
|
|
737
|
+
U ? /* @__PURE__ */ S.jsxs("div", { children: [
|
|
738
|
+
/* @__PURE__ */ S.jsx("h3", { children: "Scanned Result:" }),
|
|
739
|
+
/* @__PURE__ */ S.jsx("img", { src: U, style: { width: "100%", maxWidth: "400px", border: "2px solid #ccc" } }),
|
|
740
|
+
/* @__PURE__ */ S.jsx("br", {}),
|
|
741
|
+
/* @__PURE__ */ S.jsx("button", { onClick: () => m(null), children: "Scan Again" })
|
|
742
|
+
] }) : /* @__PURE__ */ S.jsx(gr, { onCapture: (V) => m(V) })
|
|
743
|
+
] });
|
|
744
|
+
}
|
|
745
|
+
export {
|
|
746
|
+
mr as App,
|
|
747
|
+
gr as DocumentScanner
|
|
748
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
(function(N,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],E):(N=typeof globalThis<"u"?globalThis:N||self,E(N.DocumentScanner={},N.React))})(this,function(N,E){"use strict";var ie={exports:{}},Z={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var be;function Ue(){if(be)return Z;be=1;var B=E,m=Symbol.for("react.element"),J=Symbol.for("react.fragment"),k=Object.prototype.hasOwnProperty,M=B.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,K={key:!0,ref:!0,__self:!0,__source:!0};function O(F,v,H){var _,Y={},L=null,G=null;H!==void 0&&(L=""+H),v.key!==void 0&&(L=""+v.key),v.ref!==void 0&&(G=v.ref);for(_ in v)k.call(v,_)&&!K.hasOwnProperty(_)&&(Y[_]=v[_]);if(F&&F.defaultProps)for(_ in v=F.defaultProps,v)Y[_]===void 0&&(Y[_]=v[_]);return{$$typeof:m,type:F,key:L,ref:G,props:Y,_owner:M.current}}return Z.Fragment=J,Z.jsx=O,Z.jsxs=O,Z}var q={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var me;function Ve(){return me||(me=1,{}.NODE_ENV!=="production"&&function(){var B=E,m=Symbol.for("react.element"),J=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),M=Symbol.for("react.strict_mode"),K=Symbol.for("react.profiler"),O=Symbol.for("react.provider"),F=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),H=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),G=Symbol.for("react.offscreen"),a=Symbol.iterator,f="@@iterator";function d(e){if(e===null||typeof e!="object")return null;var r=a&&e[a]||e[f];return typeof r=="function"?r:null}var s=B.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function l(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];P("error",e,t)}}function P(e,r,t){{var n=s.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var c=t.map(function(i){return String(i)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var h=!1,y=!1,T=!1,A=!1,U=!1,D;D=Symbol.for("react.module.reference");function I(e){return!!(typeof e=="string"||typeof e=="function"||e===k||e===K||U||e===M||e===H||e===_||A||e===G||h||y||T||typeof e=="object"&&e!==null&&(e.$$typeof===L||e.$$typeof===Y||e.$$typeof===O||e.$$typeof===F||e.$$typeof===v||e.$$typeof===D||e.getModuleId!==void 0))}function x(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function R(e){return e.displayName||"Context"}function b(e){if(e==null)return null;if(typeof e.tag=="number"&&l("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case k:return"Fragment";case J:return"Portal";case K:return"Profiler";case M:return"StrictMode";case H:return"Suspense";case _:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case F:var r=e;return R(r)+".Consumer";case O:var t=e;return R(t._context)+".Provider";case v:return x(e,e.render,"ForwardRef");case Y:var n=e.displayName||null;return n!==null?n:b(e.type)||"Memo";case L:{var u=e,c=u._payload,i=u._init;try{return b(i(c))}catch{return null}}}return null}var S=Object.assign,V=0,Q,se,Re,Ee,_e,xe,Ce;function we(){}we.__reactDisabledLog=!0;function Be(){{if(V===0){Q=console.log,se=console.info,Re=console.warn,Ee=console.error,_e=console.group,xe=console.groupCollapsed,Ce=console.groupEnd;var e={configurable:!0,enumerable:!0,value:we,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}V++}}function Je(){{if(V--,V===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:Q}),info:S({},e,{value:se}),warn:S({},e,{value:Re}),error:S({},e,{value:Ee}),group:S({},e,{value:_e}),groupCollapsed:S({},e,{value:xe}),groupEnd:S({},e,{value:Ce})})}V<0&&l("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ue=s.ReactCurrentDispatcher,le;function te(e,r,t){{if(le===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);le=n&&n[1]||""}return`
|
|
18
|
+
`+le+e}}var ce=!1,ne;{var He=typeof WeakMap=="function"?WeakMap:Map;ne=new He}function Te(e,r){if(!e||ce)return"";{var t=ne.get(e);if(t!==void 0)return t}var n;ce=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=ue.current,ue.current=null,Be();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(j){n=j}Reflect.construct(e,[],i)}else{try{i.call()}catch(j){n=j}e.call(i.prototype)}}else{try{throw Error()}catch(j){n=j}e()}}catch(j){if(j&&n&&typeof j.stack=="string"){for(var o=j.stack.split(`
|
|
19
|
+
`),C=n.stack.split(`
|
|
20
|
+
`),p=o.length-1,g=C.length-1;p>=1&&g>=0&&o[p]!==C[g];)g--;for(;p>=1&&g>=0;p--,g--)if(o[p]!==C[g]){if(p!==1||g!==1)do if(p--,g--,g<0||o[p]!==C[g]){var W=`
|
|
21
|
+
`+o[p].replace(" at new "," at ");return e.displayName&&W.includes("<anonymous>")&&(W=W.replace("<anonymous>",e.displayName)),typeof e=="function"&&ne.set(e,W),W}while(p>=1&&g>=0);break}}}finally{ce=!1,ue.current=c,Je(),Error.prepareStackTrace=u}var $=e?e.displayName||e.name:"",z=$?te($):"";return typeof e=="function"&&ne.set(e,z),z}function Ke(e,r,t){return Te(e,!1)}function ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function ae(e,r,t){if(e==null)return"";if(typeof e=="function")return Te(e,ze(e));if(typeof e=="string")return te(e);switch(e){case H:return te("Suspense");case _:return te("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return Ke(e.render);case Y:return ae(e.type,r,t);case L:{var n=e,u=n._payload,c=n._init;try{return ae(c(u),r,t)}catch{}}}return""}var ee=Object.prototype.hasOwnProperty,Se={},je=s.ReactDebugCurrentFrame;function oe(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);je.setExtraStackFrame(t)}else je.setExtraStackFrame(null)}function Ge(e,r,t,n,u){{var c=Function.call.bind(ee);for(var i in e)if(c(e,i)){var o=void 0;try{if(typeof e[i]!="function"){var C=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw C.name="Invariant Violation",C}o=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(p){o=p}o&&!(o instanceof Error)&&(oe(u),l("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof o),oe(null)),o instanceof Error&&!(o.message in Se)&&(Se[o.message]=!0,oe(u),l("Failed %s type: %s",t,o.message),oe(null))}}}var Xe=Array.isArray;function fe(e){return Xe(e)}function $e(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ze(e){try{return Oe(e),!1}catch{return!0}}function Oe(e){return""+e}function Pe(e){if(Ze(e))return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",$e(e)),Oe(e)}var re=s.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0},De,ke,de;de={};function Qe(e){if(ee.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function er(e){if(ee.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function rr(e,r){if(typeof e.ref=="string"&&re.current&&r&&re.current.stateNode!==r){var t=b(re.current.type);de[t]||(l('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',b(re.current.type),e.ref),de[t]=!0)}}function tr(e,r){{var t=function(){De||(De=!0,l("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function nr(e,r){{var t=function(){ke||(ke=!0,l("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var ar=function(e,r,t,n,u,c,i){var o={$$typeof:m,type:e,key:r,ref:t,props:i,_owner:c};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function or(e,r,t,n,u){{var c,i={},o=null,C=null;t!==void 0&&(Pe(t),o=""+t),er(r)&&(Pe(r.key),o=""+r.key),Qe(r)&&(C=r.ref,rr(r,u));for(c in r)ee.call(r,c)&&!qe.hasOwnProperty(c)&&(i[c]=r[c]);if(e&&e.defaultProps){var p=e.defaultProps;for(c in p)i[c]===void 0&&(i[c]=p[c])}if(o||C){var g=typeof e=="function"?e.displayName||e.name||"Unknown":e;o&&tr(i,g),C&&nr(i,g)}return ar(e,o,C,u,n,re.current,i)}}var ve=s.ReactCurrentOwner,Fe=s.ReactDebugCurrentFrame;function X(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);Fe.setExtraStackFrame(t)}else Fe.setExtraStackFrame(null)}var pe;pe=!1;function he(e){return typeof e=="object"&&e!==null&&e.$$typeof===m}function Ae(){{if(ve.current){var e=b(ve.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function ir(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
|
|
24
|
+
|
|
25
|
+
Check your code at `+r+":"+t+"."}return""}}var Ie={};function sr(e){{var r=Ae();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
26
|
+
|
|
27
|
+
Check the top-level render call using <`+t+">.")}return r}}function We(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=sr(r);if(Ie[t])return;Ie[t]=!0;var n="";e&&e._owner&&e._owner!==ve.current&&(n=" It was passed a child from "+b(e._owner.type)+"."),X(e),l('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),X(null)}}function Me(e,r){{if(typeof e!="object")return;if(fe(e))for(var t=0;t<e.length;t++){var n=e[t];he(n)&&We(n,r)}else if(he(e))e._store&&(e._store.validated=!0);else if(e){var u=d(e);if(typeof u=="function"&&u!==e.entries)for(var c=u.call(e),i;!(i=c.next()).done;)he(i.value)&&We(i.value,r)}}}function ur(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===v||r.$$typeof===Y))t=r.propTypes;else return;if(t){var n=b(r);Ge(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!pe){pe=!0;var u=b(r);l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function lr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){X(e),l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),X(null);break}}e.ref!==null&&(X(e),l("Invalid attribute `ref` supplied to `React.Fragment`."),X(null))}}var Ye={};function Le(e,r,t,n,u,c){{var i=I(e);if(!i){var o="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C=ir(u);C?o+=C:o+=Ae();var p;e===null?p="null":fe(e)?p="array":e!==void 0&&e.$$typeof===m?(p="<"+(b(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):p=typeof e,l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",p,o)}var g=or(e,r,t,u,c);if(g==null)return g;if(i){var W=r.children;if(W!==void 0)if(n)if(fe(W)){for(var $=0;$<W.length;$++)Me(W[$],e);Object.freeze&&Object.freeze(W)}else l("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Me(W,e)}if(ee.call(r,"key")){var z=b(e),j=Object.keys(r).filter(function(hr){return hr!=="key"}),ge=j.length>0?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}";if(!Ye[z+ge]){var pr=j.length>0?"{"+j.join(": ..., ")+": ...}":"{}";l(`A props object containing a "key" prop is being spread into JSX:
|
|
28
|
+
let props = %s;
|
|
29
|
+
<%s {...props} />
|
|
30
|
+
React keys must be passed directly to JSX without using spread:
|
|
31
|
+
let props = %s;
|
|
32
|
+
<%s key={someKey} {...props} />`,ge,z,pr,z),Ye[z+ge]=!0}}return e===k?lr(g):ur(g),g}}function cr(e,r,t){return Le(e,r,t,!0)}function fr(e,r,t){return Le(e,r,t,!1)}var dr=fr,vr=cr;q.Fragment=k,q.jsx=dr,q.jsxs=vr}()),q}({}).NODE_ENV==="production"?ie.exports=Ue():ie.exports=Ve();var w=ie.exports;const ye=({onCapture:B})=>{const m=E.useRef(null),J=E.useRef(null),k=E.useRef(null),[M,K]=E.useState(!1),O=E.useRef(null),F=E.useRef([]),v=E.useRef(0);E.useEffect(()=>{k.current||(k.current=document.createElement("canvas"));let a=null;async function f(){try{const s=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment",width:{ideal:1920}}});m.current&&(m.current.srcObject=s,m.current.play(),a=requestAnimationFrame(d))}catch(s){console.error("Camera access error:",s)}}function d(){var s;if(((s=m.current)==null?void 0:s.readyState)>=2){const l=m.current,P=J.current,h=P.getContext("2d");P.width!==l.videoWidth&&(P.width=l.videoWidth,P.height=l.videoHeight),h.drawImage(l,0,0);const y=_(l);y?(O.current&&H(y,O.current)?v.current=Math.min(15,v.current+1):v.current=0,F.current.push(y),F.current.length>10&&F.current.shift(),O.current=Y(F.current),v.current>5&&K(!0)):(v.current=Math.max(0,v.current-2),v.current===0&&(O.current=null,K(!1))),M&&O.current&&L(h,O.current)}a=requestAnimationFrame(d)}return f(),()=>cancelAnimationFrame(a)},[M]);const H=(a,f)=>Math.abs(a.tl[0]-f.tl[0])+Math.abs(a.tl[1]-f.tl[1])<50,_=a=>{const d=Math.floor(a.videoWidth*.15),s=Math.floor(a.videoHeight*.15),l=k.current.getContext("2d");k.current.width=d,k.current.height=s,l.drawImage(a,0,0,d,s);const P=l.getImageData(0,0,d,s).data;let h=[d,s],y=[0,s],T=[d,0],A=[0,0],U=0;for(let x=10;x<s-10;x++)for(let R=10;R<d-10;R++){const b=(x*d+R)*4,S=P[b],V=P[b+1],Q=P[b+2];S>190&&V>190&&Q>180&&Math.abs(S-V)<20&&Math.abs(V-Q)<20&&(U++,R+x<h[0]+h[1]&&(h=[R,x]),R-x>y[0]-y[1]&&(y=[R,x]),R-x<T[0]-T[1]&&(T=[R,x]),R+x>A[0]+A[1]&&(A=[R,x]))}const D=y[0]-h[0],I=T[1]-h[1];return U<d*s*.08||D<d*.3||I<s*.3?null:{tl:[h[0]/.15,h[1]/.15],tr:[y[0]/.15,y[1]/.15],bl:[T[0]/.15,T[1]/.15],br:[A[0]/.15,A[1]/.15]}},Y=a=>{const f={tl:[0,0],tr:[0,0],bl:[0,0],br:[0,0]};return a.forEach(d=>{["tl","tr","bl","br"].forEach(s=>{f[s][0]+=d[s][0]/a.length,f[s][1]+=d[s][1]/a.length})}),f},L=(a,f)=>{a.strokeStyle="#00FF44",a.lineWidth=12,a.lineCap="round",a.shadowBlur=15,a.shadowColor="#00FF44",a.beginPath(),a.moveTo(...f.tl),a.lineTo(...f.tr),a.lineTo(...f.br),a.lineTo(...f.bl),a.closePath(),a.stroke(),a.shadowBlur=0},G=()=>{const a=m.current,f=O.current;if(!a||!f)return;const d=1240,s=1754,l=document.createElement("canvas");l.width=d,l.height=s;const P=l.getContext("2d"),h=document.createElement("canvas");h.width=a.videoWidth,h.height=a.videoHeight,h.getContext("2d").drawImage(a,0,0);const y=h.getContext("2d").getImageData(0,0,h.width,h.height),T=P.createImageData(d,s);for(let A=0;A<s;A++)for(let U=0;U<d;U++){const D=U/d,I=A/s,x=Math.floor((1-D)*(1-I)*f.tl[0]+D*(1-I)*f.tr[0]+(1-D)*I*f.bl[0]+D*I*f.br[0]),R=Math.floor((1-D)*(1-I)*f.tl[1]+D*(1-I)*f.tr[1]+(1-D)*I*f.bl[1]+D*I*f.br[1]),b=(A*d+U)*4,S=(R*h.width+x)*4;T.data[b]=y.data[S],T.data[b+1]=y.data[S+1],T.data[b+2]=y.data[S+2],T.data[b+3]=255}P.putImageData(T,0,0),B(l.toDataURL("image/jpeg",.92))};return w.jsxs("div",{style:{textAlign:"center",background:"#111",minHeight:"100vh",padding:"20px"},children:[w.jsxs("div",{style:{position:"relative",borderRadius:"30px",overflow:"hidden",border:"5px solid #333",display:"inline-block"},children:[w.jsx("video",{ref:m,style:{display:"none"}}),w.jsx("canvas",{ref:J,style:{width:"100%",maxWidth:"500px",display:"block"}}),M&&w.jsx("div",{style:{position:"absolute",bottom:"20px",left:"50%",transform:"translateX(-50%)",background:"#00FF44",color:"#000",padding:"8px 20px",borderRadius:"20px",fontWeight:"bold"},children:"READY TO SCAN"})]}),w.jsx("button",{onClick:G,disabled:!M,style:{display:"block",margin:"20px auto",padding:"20px 50px",borderRadius:"50px",border:"none",backgroundColor:M?"#00FF44":"#444",color:M?"#000":"#888",fontSize:"18px",fontWeight:"bold",cursor:"pointer"},children:"CROP & SAVE DOCUMENT"})]})};function Ne(){const[B,m]=E.useState(null);return w.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[w.jsx("h1",{children:"JS Doc Scanner"}),B?w.jsxs("div",{children:[w.jsx("h3",{children:"Scanned Result:"}),w.jsx("img",{src:B,style:{width:"100%",maxWidth:"400px",border:"2px solid #ccc"}}),w.jsx("br",{}),w.jsx("button",{onClick:()=>m(null),children:"Scan Again"})]}):w.jsx(ye,{onCapture:J=>m(J)})]})}N.App=Ne,N.DocumentScanner=ye,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uziee/document-scanner",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "A lightweight, zero-dependency React document scanner with real-time edge detection, stability filtering, and perspective correction (bilinear warping) for high-resolution A4 captures.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.es.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.es.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
19
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"lucide-react": "^0.263.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
26
|
+
"vite": "^4.3.9",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"dev": "vite",
|
|
32
|
+
"build": "vite build",
|
|
33
|
+
"preview": "vite preview"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"react",
|
|
37
|
+
"document",
|
|
38
|
+
"scanner",
|
|
39
|
+
"opencv",
|
|
40
|
+
"camera"
|
|
41
|
+
],
|
|
42
|
+
"author": "Uzair Shahid",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/uzair2244/document-scanner.git"
|
|
47
|
+
}
|
|
48
|
+
}
|