@mleonard9/vin-scanner 0.1.1
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 +110 -0
- package/android/build.gradle +102 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/visioncamerabarcodescanner/VisionCameraBarcodeScannerModule.kt +93 -0
- package/android/src/main/java/com/visioncamerabarcodescanner/VisionCameraBarcodeScannerPackage.kt +27 -0
- package/android/src/main/java/com/visioncameratextrecognition/VisionCameraTextRecognitionModule.kt +130 -0
- package/ios/VisionCameraBarcodeScanner.m +175 -0
- package/ios/VisionCameraTextRecognition.m +114 -0
- package/lib/commonjs/index.js +87 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/scanBarcodes.js +46 -0
- package/lib/commonjs/scanBarcodes.js.map +1 -0
- package/lib/commonjs/scanText.js +29 -0
- package/lib/commonjs/scanText.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/vinUtils.js +240 -0
- package/lib/commonjs/vinUtils.js.map +1 -0
- package/lib/module/index.js +80 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/scanBarcodes.js +40 -0
- package/lib/module/scanBarcodes.js.map +1 -0
- package/lib/module/scanText.js +23 -0
- package/lib/module/scanText.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/vinUtils.js +230 -0
- package/lib/module/vinUtils.js.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/scanBarcodes.d.ts +3 -0
- package/lib/typescript/src/scanBarcodes.d.ts.map +1 -0
- package/lib/typescript/src/scanText.d.ts +3 -0
- package/lib/typescript/src/scanText.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +104 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/vinUtils.d.ts +19 -0
- package/lib/typescript/src/vinUtils.d.ts.map +1 -0
- package/package.json +168 -0
- package/src/index.tsx +131 -0
- package/src/scanBarcodes.ts +76 -0
- package/src/scanText.ts +36 -0
- package/src/types.ts +145 -0
- package/src/vinUtils.ts +368 -0
- package/vin-scanner.podspec +28 -0
package/package.json
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mleonard9/vin-scanner",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "High-performance VIN scanner for React Native Vision Camera powered by Google ML Kit barcode + text recognition.",
|
|
5
|
+
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
7
|
+
"types": "lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"*.podspec",
|
|
17
|
+
"!ios/build",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!android/gradle",
|
|
20
|
+
"!android/gradlew",
|
|
21
|
+
"!android/gradlew.bat",
|
|
22
|
+
"!android/local.properties",
|
|
23
|
+
"!**/__tests__",
|
|
24
|
+
"!**/__fixtures__",
|
|
25
|
+
"!**/__mocks__",
|
|
26
|
+
"!**/.*"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"example": "yarn workspace vin-scanner-example",
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
33
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
34
|
+
"prepare": "bob build",
|
|
35
|
+
"release": "release-it"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"react-native",
|
|
39
|
+
"vision-camera",
|
|
40
|
+
"vin",
|
|
41
|
+
"barcode",
|
|
42
|
+
"text-recognition",
|
|
43
|
+
"ios",
|
|
44
|
+
"android"
|
|
45
|
+
],
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/mleonard9/vin-scanner.git"
|
|
49
|
+
},
|
|
50
|
+
"author": "mleonard9",
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/mleonard9/vin-scanner/issues"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/mleonard9/vin-scanner#readme",
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
62
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
63
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
64
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
|
65
|
+
"@types/jest": "^29.5.5",
|
|
66
|
+
"@types/react": "^18.2.44",
|
|
67
|
+
"commitlint": "^17.0.2",
|
|
68
|
+
"del-cli": "^5.1.0",
|
|
69
|
+
"eslint": "^8.51.0",
|
|
70
|
+
"eslint-config-prettier": "^9.0.0",
|
|
71
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
72
|
+
"jest": "^29.7.0",
|
|
73
|
+
"prettier": "^3.0.3",
|
|
74
|
+
"react": "18.2.0",
|
|
75
|
+
"react-native": "0.73.6",
|
|
76
|
+
"react-native-builder-bob": "^0.20.0",
|
|
77
|
+
"react-native-vision-camera": "^4.0.1",
|
|
78
|
+
"react-native-worklets-core": "^1.2.0",
|
|
79
|
+
"release-it": "^15.0.0",
|
|
80
|
+
"turbo": "^1.10.7",
|
|
81
|
+
"typescript": "^5.2.2"
|
|
82
|
+
},
|
|
83
|
+
"resolutions": {
|
|
84
|
+
"@types/react": "^18.2.44"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "*",
|
|
88
|
+
"react-native": "*",
|
|
89
|
+
"react-native-vision-camera": "*"
|
|
90
|
+
},
|
|
91
|
+
"workspaces": [
|
|
92
|
+
"example"
|
|
93
|
+
],
|
|
94
|
+
"packageManager": "yarn@3.6.1",
|
|
95
|
+
"jest": {
|
|
96
|
+
"preset": "react-native",
|
|
97
|
+
"modulePathIgnorePatterns": [
|
|
98
|
+
"<rootDir>/example/node_modules",
|
|
99
|
+
"<rootDir>/lib/"
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"commitlint": {
|
|
103
|
+
"extends": [
|
|
104
|
+
"@commitlint/config-conventional"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"release-it": {
|
|
108
|
+
"git": {
|
|
109
|
+
"commitMessage": "chore: release ${version}",
|
|
110
|
+
"tagName": "v${version}"
|
|
111
|
+
},
|
|
112
|
+
"npm": {
|
|
113
|
+
"publish": true
|
|
114
|
+
},
|
|
115
|
+
"github": {
|
|
116
|
+
"release": true
|
|
117
|
+
},
|
|
118
|
+
"plugins": {
|
|
119
|
+
"@release-it/conventional-changelog": {
|
|
120
|
+
"preset": "angular"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"eslintConfig": {
|
|
125
|
+
"root": true,
|
|
126
|
+
"extends": [
|
|
127
|
+
"@react-native",
|
|
128
|
+
"prettier"
|
|
129
|
+
],
|
|
130
|
+
"rules": {
|
|
131
|
+
"prettier/prettier": [
|
|
132
|
+
"error",
|
|
133
|
+
{
|
|
134
|
+
"quoteProps": "consistent",
|
|
135
|
+
"singleQuote": true,
|
|
136
|
+
"tabWidth": 2,
|
|
137
|
+
"trailingComma": "es5",
|
|
138
|
+
"useTabs": false
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"eslintIgnore": [
|
|
144
|
+
"node_modules/",
|
|
145
|
+
"lib/"
|
|
146
|
+
],
|
|
147
|
+
"prettier": {
|
|
148
|
+
"quoteProps": "consistent",
|
|
149
|
+
"singleQuote": true,
|
|
150
|
+
"tabWidth": 2,
|
|
151
|
+
"trailingComma": "es5",
|
|
152
|
+
"useTabs": false
|
|
153
|
+
},
|
|
154
|
+
"react-native-builder-bob": {
|
|
155
|
+
"source": "src",
|
|
156
|
+
"output": "lib",
|
|
157
|
+
"targets": [
|
|
158
|
+
"commonjs",
|
|
159
|
+
"module",
|
|
160
|
+
[
|
|
161
|
+
"typescript",
|
|
162
|
+
{
|
|
163
|
+
"project": "tsconfig.build.json"
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Camera as VisionCamera,
|
|
4
|
+
type ReadonlyFrameProcessor,
|
|
5
|
+
useFrameProcessor,
|
|
6
|
+
} from 'react-native-vision-camera';
|
|
7
|
+
import { useRunOnJS } from 'react-native-worklets-core';
|
|
8
|
+
import { createBarcodeScannerPlugin } from './scanBarcodes';
|
|
9
|
+
import { createTextRecognitionPlugin } from './scanText';
|
|
10
|
+
import type {
|
|
11
|
+
BarcodeScannerPlugin,
|
|
12
|
+
CameraTypes,
|
|
13
|
+
ForwardedRef,
|
|
14
|
+
TextRecognitionPlugin,
|
|
15
|
+
WorkletPayload,
|
|
16
|
+
} from './types';
|
|
17
|
+
import {
|
|
18
|
+
buildVinCandidates,
|
|
19
|
+
pickBestCandidate,
|
|
20
|
+
resolveOptions,
|
|
21
|
+
type ResolvedVinScannerOptions,
|
|
22
|
+
} from './vinUtils';
|
|
23
|
+
|
|
24
|
+
export const Camera = forwardRef(function Camera(
|
|
25
|
+
props: CameraTypes,
|
|
26
|
+
ref: ForwardedRef<any>
|
|
27
|
+
) {
|
|
28
|
+
const { device, callback, options, ...rest } = props;
|
|
29
|
+
|
|
30
|
+
const resolvedOptions = useMemo<ResolvedVinScannerOptions>(
|
|
31
|
+
() => resolveOptions(options),
|
|
32
|
+
[options]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const barcodeScanner = useBarcodeScanner(resolvedOptions.barcode);
|
|
36
|
+
const textScanner = useTextScanner(resolvedOptions.text);
|
|
37
|
+
const lastEmissionRef = useRef<string | null | undefined>(undefined);
|
|
38
|
+
|
|
39
|
+
const handleDetections = useRunOnJS(
|
|
40
|
+
(payload: WorkletPayload) => {
|
|
41
|
+
const candidates = buildVinCandidates(payload, resolvedOptions);
|
|
42
|
+
const best = pickBestCandidate(candidates, resolvedOptions);
|
|
43
|
+
const mode = resolvedOptions.detection.resultMode;
|
|
44
|
+
const filteredCandidates =
|
|
45
|
+
mode === 'all' ? candidates : best ? [best] : [];
|
|
46
|
+
const fingerprint =
|
|
47
|
+
mode === 'all'
|
|
48
|
+
? filteredCandidates.map((candidate) => candidate.value).join('|') ||
|
|
49
|
+
null
|
|
50
|
+
: (best?.value ?? null);
|
|
51
|
+
|
|
52
|
+
if (!resolvedOptions.detection.emitDuplicates) {
|
|
53
|
+
if (
|
|
54
|
+
lastEmissionRef.current !== undefined &&
|
|
55
|
+
fingerprint === lastEmissionRef.current
|
|
56
|
+
) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
lastEmissionRef.current = fingerprint;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
callback({
|
|
63
|
+
mode,
|
|
64
|
+
timestamp: payload.timestamp,
|
|
65
|
+
candidates: filteredCandidates,
|
|
66
|
+
best: best ?? null,
|
|
67
|
+
raw: {
|
|
68
|
+
barcodes: payload.barcodes ?? [],
|
|
69
|
+
textBlocks: payload.textBlocks ?? [],
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
[callback, resolvedOptions]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const scanBarcodes = barcodeScanner?.scanBarcodes;
|
|
77
|
+
const scanText = textScanner?.scanText;
|
|
78
|
+
|
|
79
|
+
const frameProcessor: ReadonlyFrameProcessor = useFrameProcessor(
|
|
80
|
+
(frame) => {
|
|
81
|
+
'worklet';
|
|
82
|
+
const barcodes = scanBarcodes ? scanBarcodes(frame) : [];
|
|
83
|
+
const textBlocks = scanText ? scanText(frame) : [];
|
|
84
|
+
handleDetections({
|
|
85
|
+
barcodes: barcodes ?? [],
|
|
86
|
+
textBlocks: textBlocks ?? [],
|
|
87
|
+
timestamp:
|
|
88
|
+
typeof frame?.timestamp === 'number' ? frame.timestamp : Date.now(),
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
[scanBarcodes, scanText, handleDetections]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
{!!device && (
|
|
97
|
+
<VisionCamera
|
|
98
|
+
pixelFormat="yuv"
|
|
99
|
+
ref={ref}
|
|
100
|
+
frameProcessor={frameProcessor}
|
|
101
|
+
device={device}
|
|
102
|
+
{...rest}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
function useBarcodeScanner(
|
|
110
|
+
options: ResolvedVinScannerOptions['barcode']
|
|
111
|
+
): BarcodeScannerPlugin | null {
|
|
112
|
+
return useMemo(() => {
|
|
113
|
+
if (!options.enabled) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return createBarcodeScannerPlugin(options.formats);
|
|
117
|
+
}, [options.enabled, options.formats]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function useTextScanner(
|
|
121
|
+
options: ResolvedVinScannerOptions['text']
|
|
122
|
+
): TextRecognitionPlugin | null {
|
|
123
|
+
return useMemo(() => {
|
|
124
|
+
if (!options.enabled) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return createTextRecognitionPlugin({
|
|
128
|
+
language: options.language,
|
|
129
|
+
});
|
|
130
|
+
}, [options.enabled, options.language]);
|
|
131
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
type FrameProcessorPlugin,
|
|
4
|
+
VisionCameraProxy,
|
|
5
|
+
} from 'react-native-vision-camera';
|
|
6
|
+
import type {
|
|
7
|
+
BarcodeDetection,
|
|
8
|
+
BarcodeFormat,
|
|
9
|
+
BarcodeScannerPlugin,
|
|
10
|
+
Frame,
|
|
11
|
+
ScanBarcodeOptions,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
const LINKING_ERROR: string =
|
|
15
|
+
`The package '@mleonard9/vin-scanner' doesn't seem to be linked. Make sure: \n\n` +
|
|
16
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
17
|
+
'- You rebuilt the app after installing the package\n' +
|
|
18
|
+
'- You are not using Expo Go\n';
|
|
19
|
+
|
|
20
|
+
const DEFAULT_FORMATS: ScanBarcodeOptions = ['all'];
|
|
21
|
+
|
|
22
|
+
const KNOWN_FORMATS: BarcodeFormat[] = [
|
|
23
|
+
'all',
|
|
24
|
+
'aztec',
|
|
25
|
+
'code-128',
|
|
26
|
+
'code-39',
|
|
27
|
+
'code-93',
|
|
28
|
+
'codabar',
|
|
29
|
+
'data-matrix',
|
|
30
|
+
'ean-13',
|
|
31
|
+
'ean-8',
|
|
32
|
+
'itf',
|
|
33
|
+
'pdf-417',
|
|
34
|
+
'qr',
|
|
35
|
+
'upc-a',
|
|
36
|
+
'upc-e',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
type NativeBarcodeOptionMap = Partial<Record<BarcodeFormat, boolean>>;
|
|
40
|
+
|
|
41
|
+
const toNativeBarcodeOptions = (
|
|
42
|
+
formats?: ScanBarcodeOptions
|
|
43
|
+
): NativeBarcodeOptionMap => {
|
|
44
|
+
const sanitized = formats && formats.length > 0 ? formats : DEFAULT_FORMATS;
|
|
45
|
+
if (sanitized.includes('all')) {
|
|
46
|
+
return { all: true };
|
|
47
|
+
}
|
|
48
|
+
return sanitized.reduce<NativeBarcodeOptionMap>((acc, format) => {
|
|
49
|
+
if ((KNOWN_FORMATS as string[]).includes(format)) {
|
|
50
|
+
acc[format as BarcodeFormat] = true;
|
|
51
|
+
}
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export function createBarcodeScannerPlugin(
|
|
57
|
+
formats: ScanBarcodeOptions
|
|
58
|
+
): BarcodeScannerPlugin {
|
|
59
|
+
const pluginOptions = toNativeBarcodeOptions(formats);
|
|
60
|
+
const plugin: FrameProcessorPlugin | undefined =
|
|
61
|
+
VisionCameraProxy.initFrameProcessorPlugin('scanBarcodes', {
|
|
62
|
+
...pluginOptions,
|
|
63
|
+
});
|
|
64
|
+
if (!plugin) {
|
|
65
|
+
throw new Error(LINKING_ERROR);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
scanBarcodes: (frame: Frame): BarcodeDetection[] => {
|
|
69
|
+
'worklet';
|
|
70
|
+
const result = plugin.call(frame);
|
|
71
|
+
return (Array.isArray(result)
|
|
72
|
+
? result
|
|
73
|
+
: []) as unknown as BarcodeDetection[];
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/src/scanText.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
type FrameProcessorPlugin,
|
|
4
|
+
VisionCameraProxy,
|
|
5
|
+
} from 'react-native-vision-camera';
|
|
6
|
+
import type {
|
|
7
|
+
Frame,
|
|
8
|
+
TextDetection,
|
|
9
|
+
TextRecognitionOptions,
|
|
10
|
+
TextRecognitionPlugin,
|
|
11
|
+
} from './types';
|
|
12
|
+
|
|
13
|
+
const LINKING_ERROR: string =
|
|
14
|
+
`The package '@mleonard9/vin-scanner' doesn't seem to be linked. Make sure: \n\n` +
|
|
15
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
16
|
+
'- You rebuilt the app after installing the package\n' +
|
|
17
|
+
'- You are not using Expo Go\n';
|
|
18
|
+
|
|
19
|
+
export function createTextRecognitionPlugin(
|
|
20
|
+
options: TextRecognitionOptions
|
|
21
|
+
): TextRecognitionPlugin {
|
|
22
|
+
const plugin: FrameProcessorPlugin | undefined =
|
|
23
|
+
VisionCameraProxy.initFrameProcessorPlugin('scanText', {
|
|
24
|
+
...options,
|
|
25
|
+
});
|
|
26
|
+
if (!plugin) {
|
|
27
|
+
throw new Error(LINKING_ERROR);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
scanText: (frame: Frame): TextDetection[] => {
|
|
31
|
+
'worklet';
|
|
32
|
+
const result = plugin.call(frame);
|
|
33
|
+
return (Array.isArray(result) ? result : []) as TextDetection[];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { CameraProps } from 'react-native-vision-camera';
|
|
2
|
+
export type {
|
|
3
|
+
Frame,
|
|
4
|
+
ReadonlyFrameProcessor,
|
|
5
|
+
FrameProcessorPlugin,
|
|
6
|
+
} from 'react-native-vision-camera';
|
|
7
|
+
import type { Frame } from 'react-native-vision-camera';
|
|
8
|
+
export type { ForwardedRef } from 'react';
|
|
9
|
+
|
|
10
|
+
export type BarcodeFormat =
|
|
11
|
+
| 'all'
|
|
12
|
+
| 'aztec'
|
|
13
|
+
| 'code-128'
|
|
14
|
+
| 'code-39'
|
|
15
|
+
| 'code-93'
|
|
16
|
+
| 'codabar'
|
|
17
|
+
| 'data-matrix'
|
|
18
|
+
| 'ean-13'
|
|
19
|
+
| 'ean-8'
|
|
20
|
+
| 'itf'
|
|
21
|
+
| 'pdf-417'
|
|
22
|
+
| 'qr'
|
|
23
|
+
| 'upc-a'
|
|
24
|
+
| 'upc-e';
|
|
25
|
+
|
|
26
|
+
export type ScanBarcodeOptions = BarcodeFormat[];
|
|
27
|
+
|
|
28
|
+
export type BarcodeDetection = {
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
top?: number;
|
|
32
|
+
bottom?: number;
|
|
33
|
+
left?: number;
|
|
34
|
+
right?: number;
|
|
35
|
+
rawValue?: string;
|
|
36
|
+
displayValue?: string;
|
|
37
|
+
format?: string;
|
|
38
|
+
[key: string]: number | string | undefined;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type TextRecognitionLanguage =
|
|
42
|
+
| 'latin'
|
|
43
|
+
| 'chinese'
|
|
44
|
+
| 'devanagari'
|
|
45
|
+
| 'japanese'
|
|
46
|
+
| 'korean';
|
|
47
|
+
|
|
48
|
+
export type TextDetection = {
|
|
49
|
+
blockFrameBottom?: number;
|
|
50
|
+
blockFrameLeft?: number;
|
|
51
|
+
blockFrameRight?: number;
|
|
52
|
+
blockFrameTop?: number;
|
|
53
|
+
blockText?: string;
|
|
54
|
+
elementFrameBottom?: number;
|
|
55
|
+
elementFrameLeft?: number;
|
|
56
|
+
elementFrameRight?: number;
|
|
57
|
+
elementFrameTop?: number;
|
|
58
|
+
elementText?: string;
|
|
59
|
+
lineFrameBottom?: number;
|
|
60
|
+
lineFrameLeft?: number;
|
|
61
|
+
lineFrameRight?: number;
|
|
62
|
+
lineFrameTop?: number;
|
|
63
|
+
lineText?: string;
|
|
64
|
+
resultText?: string;
|
|
65
|
+
size?: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type TextRecognitionOptions = {
|
|
69
|
+
language?: TextRecognitionLanguage;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type VinResultMode = 'best' | 'all';
|
|
73
|
+
|
|
74
|
+
export type BoundingBox = {
|
|
75
|
+
top: number;
|
|
76
|
+
left: number;
|
|
77
|
+
right: number;
|
|
78
|
+
bottom: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
height?: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type VinCandidateSource = 'barcode' | 'text';
|
|
84
|
+
|
|
85
|
+
export type VinCandidate = {
|
|
86
|
+
value: string;
|
|
87
|
+
source: VinCandidateSource;
|
|
88
|
+
confidence: number;
|
|
89
|
+
boundingBox?: BoundingBox;
|
|
90
|
+
origin?: 'rawValue' | 'displayValue' | 'block' | 'line' | 'element';
|
|
91
|
+
rawPayload?: BarcodeDetection | TextDetection;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type VinScannerEvent = {
|
|
95
|
+
mode: VinResultMode;
|
|
96
|
+
timestamp: number;
|
|
97
|
+
candidates: VinCandidate[];
|
|
98
|
+
best?: VinCandidate | null;
|
|
99
|
+
raw: {
|
|
100
|
+
barcodes: BarcodeDetection[];
|
|
101
|
+
textBlocks: TextDetection[];
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type BarcodeScannerOptions = {
|
|
106
|
+
enabled?: boolean;
|
|
107
|
+
formats?: ScanBarcodeOptions;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type TextScannerOptions = {
|
|
111
|
+
enabled?: boolean;
|
|
112
|
+
language?: TextRecognitionLanguage;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type DetectionOptions = {
|
|
116
|
+
resultMode?: VinResultMode;
|
|
117
|
+
preferBarcode?: boolean;
|
|
118
|
+
validateChecksum?: boolean;
|
|
119
|
+
emitDuplicates?: boolean;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type VinScannerOptions = {
|
|
123
|
+
barcode?: BarcodeScannerOptions;
|
|
124
|
+
text?: TextScannerOptions;
|
|
125
|
+
detection?: DetectionOptions;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export type CameraTypes = {
|
|
129
|
+
callback: (event: VinScannerEvent) => void;
|
|
130
|
+
options?: VinScannerOptions;
|
|
131
|
+
} & CameraProps;
|
|
132
|
+
|
|
133
|
+
export type BarcodeScannerPlugin = {
|
|
134
|
+
scanBarcodes: (frame: Frame) => BarcodeDetection[] | undefined;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type TextRecognitionPlugin = {
|
|
138
|
+
scanText: (frame: Frame) => TextDetection[] | undefined;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type WorkletPayload = {
|
|
142
|
+
barcodes?: BarcodeDetection[];
|
|
143
|
+
textBlocks?: TextDetection[];
|
|
144
|
+
timestamp: number;
|
|
145
|
+
};
|