web-mrz-reader-react 1.0.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 ADDED
@@ -0,0 +1,94 @@
1
+ # web-mrz-reader-react
2
+
3
+ React wrapper for [web-mrz-reader](https://www.npmjs.com/package/web-mrz-reader) — MRZ OCR component for React apps.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install web-mrz-reader-react web-mrz-reader tesseract.js
9
+ ```
10
+
11
+ ## Copy Static Assets
12
+
13
+ ```bash
14
+ mkdir -p public/model public/tesseract
15
+ cp node_modules/web-mrz-reader/public/model/mrz.traineddata.gz public/model/
16
+ cp node_modules/web-mrz-reader/public/tesseract/* public/tesseract/
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import { useRef } from 'react';
23
+ import { MRZReader, type MRZReaderHandle } from 'web-mrz-reader-react';
24
+
25
+ function App() {
26
+ const readerRef = useRef<MRZReaderHandle>(null);
27
+
28
+ return (
29
+ <>
30
+ <MRZReader
31
+ ref={readerRef}
32
+ workerPath="/tesseract/worker.min.js"
33
+ corePath="/tesseract/"
34
+ langPath="/model/"
35
+ onResult={(result) => {
36
+ console.log('MRZ text:', result.raw);
37
+ console.log('Parsed data:', result.parsed);
38
+ }}
39
+ onError={(error) => console.error(error)}
40
+ />
41
+ <button onClick={() => readerRef.current?.capture()}>
42
+ Capture & Read MRZ
43
+ </button>
44
+ </>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ## Props
50
+
51
+ | Prop | Type | Default | Description |
52
+ |------|------|---------|-------------|
53
+ | `ref` | `Ref<MRZReaderHandle>` | — | Imperative handle for `capture`, `reset`, `stop` |
54
+ | `workerPath` | `string` | `/tesseract/worker.min.js` | Path to Tesseract worker |
55
+ | `corePath` | `string` | `/tesseract/` | Path to Tesseract WASM cores |
56
+ | `langPath` | `string` | `/model/` | Path to MRZ trained model |
57
+ | `onResult` | `(result) => void` | — | Called when MRZ is detected |
58
+ | `onError` | `(error: string) => void` | — | Called on camera or OCR errors |
59
+ | `autoStart` | `boolean` | `true` | Start camera on mount |
60
+ | `className` | `string` | — | CSS class on container |
61
+ | `style` | `CSSProperties` | — | Inline styles on container |
62
+
63
+ ## Imperative Handle
64
+
65
+ ```tsx
66
+ const ref = useRef<MRZReaderHandle>(null);
67
+
68
+ ref.current?.capture(); // capture frame and run OCR
69
+ ref.current?.reset(); // clear canvas
70
+ ref.current?.stop(); // stop camera stream
71
+ ```
72
+
73
+ ## Standalone Parsing
74
+
75
+ Re-exported from `web-mrz-reader`:
76
+
77
+ ```tsx
78
+ import { isMRZ, extractMRZData, parseMrz } from 'web-mrz-reader-react';
79
+
80
+ const parsed = parseMrz('P<GBRNEGUS<<JOHN...');
81
+ ```
82
+
83
+ ## Local Development
84
+
85
+ ```bash
86
+ npm install
87
+ npm run dev
88
+ ```
89
+
90
+ ## Build
91
+
92
+ ```bash
93
+ npm run build
94
+ ```
@@ -0,0 +1,14 @@
1
+ import { type MRZReaderOptions } from 'web-mrz-reader';
2
+ export interface MRZReaderProps extends Omit<MRZReaderOptions, 'container' | 'onResult'> {
3
+ className?: string;
4
+ style?: React.CSSProperties;
5
+ onResult?: (result: NonNullable<ReturnType<typeof import('web-mrz-reader').extractMRZData>>) => void;
6
+ onError?: (error: string) => void;
7
+ autoStart?: boolean;
8
+ }
9
+ export interface MRZReaderHandle {
10
+ capture: () => void;
11
+ reset: () => void;
12
+ stop: () => void;
13
+ }
14
+ export declare const MRZReader: import("react").ForwardRefExoticComponent<MRZReaderProps & import("react").RefAttributes<MRZReaderHandle>>;
@@ -0,0 +1,4 @@
1
+ export { MRZReader } from './MRZReader.js';
2
+ export type { MRZReaderProps, MRZReaderHandle } from './MRZReader.js';
3
+ export type { MRZResult, TD1Result, TD2Result, TD3Result, ValidationResult, TD3ValidationResult, MRZReaderOptions, MRZReaderInstance } from 'web-mrz-reader';
4
+ export { isMRZ, extractMRZData, parseMrz } from 'web-mrz-reader';
@@ -0,0 +1,41 @@
1
+ import { jsx as R } from "react/jsx-runtime";
2
+ import { forwardRef as l, useRef as s, useImperativeHandle as m, useCallback as d, useEffect as M } from "react";
3
+ import { initMRZReader as x } from "web-mrz-reader";
4
+ import { extractMRZData as j, isMRZ as k, parseMrz as z } from "web-mrz-reader";
5
+ const Z = l(
6
+ ({ className: o, style: f, onResult: t, onError: n, autoStart: c = !0, ...u }, p) => {
7
+ const r = s(null), e = s(null);
8
+ m(p, () => ({
9
+ capture: () => e.current?.capture(),
10
+ reset: () => e.current?.reset(),
11
+ stop: () => e.current?.stop()
12
+ }), []);
13
+ const i = d(() => {
14
+ !r.current || e.current || (e.current = x({
15
+ container: r.current,
16
+ onResult: (a) => {
17
+ a && t?.(a);
18
+ },
19
+ onError: n,
20
+ ...u
21
+ }));
22
+ }, [t, n, u]);
23
+ return M(() => (c && i(), () => {
24
+ e.current?.stop(), e.current = null;
25
+ }), [c, i]), /* @__PURE__ */ R(
26
+ "div",
27
+ {
28
+ ref: r,
29
+ className: o,
30
+ style: { width: "100%", maxWidth: 888, ...f }
31
+ }
32
+ );
33
+ }
34
+ );
35
+ Z.displayName = "MRZReader";
36
+ export {
37
+ Z as MRZReader,
38
+ j as extractMRZData,
39
+ k as isMRZ,
40
+ z as parseMrz
41
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "web-mrz-reader-react",
3
+ "version": "1.0.0",
4
+ "description": "React wrapper for web-mrz-reader — MRZ OCR component for React apps.",
5
+ "type": "module",
6
+ "main": "./dist/web-mrz-reader-react.js",
7
+ "module": "./dist/web-mrz-reader-react.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/web-mrz-reader-react.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "dev": "vite",
17
+ "build": "tsc --emitDeclarationOnly && vite build --emptyOutDir false",
18
+ "preview": "vite preview",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "keywords": [
22
+ "mrz",
23
+ "ocr",
24
+ "passport",
25
+ "react",
26
+ "tesseract",
27
+ "web-mrz-reader"
28
+ ],
29
+ "author": "ilhan negis",
30
+ "license": "ISC",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/eringen/web-mrz-reader-react.git"
34
+ },
35
+ "files": [
36
+ "dist/",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "peerDependencies": {
41
+ "react": ">=18",
42
+ "react-dom": ">=18",
43
+ "web-mrz-reader": ">=2.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/react": "^18.3.0",
47
+ "@types/react-dom": "^18.3.0",
48
+ "@vitejs/plugin-react": "^4.3.0",
49
+ "react": "^18.3.0",
50
+ "react-dom": "^18.3.0",
51
+ "typescript": "^5.7.3",
52
+ "vite": "^7.3.1",
53
+ "web-mrz-reader": "file:../web-mrz/web-mrz-reader-2.0.0.tgz"
54
+ }
55
+ }