react-native-vision-camera-v3-text-recognition
Advanced tools
Comparing version 1.0.6 to 1.1.1
@@ -7,12 +7,7 @@ "use strict"; | ||
exports.Camera = void 0; | ||
Object.defineProperty(exports, "scanText", { | ||
enumerable: true, | ||
get: function () { | ||
return _scanText.scanText; | ||
} | ||
}); | ||
exports.useTextRecognition = useTextRecognition; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _reactNativeVisionCamera = require("react-native-vision-camera"); | ||
var _scanText = require("./scanText"); | ||
var _reactNativeWorkletsCore = require("react-native-worklets-core"); | ||
var _scanText = require("./scanText"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
@@ -23,24 +18,35 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
const { | ||
device, | ||
callback, | ||
device, | ||
options | ||
options = {}, | ||
...p | ||
} = props; | ||
// @ts-ignore | ||
const { | ||
scanText | ||
} = useTextRecognition(options); | ||
const useWorklets = (0, _reactNativeWorkletsCore.useRunInJS)(data => { | ||
callback(data); | ||
}, []); | ||
}, [options]); | ||
const frameProcessor = (0, _reactNativeVisionCamera.useFrameProcessor)(frame => { | ||
'worklet'; | ||
const data = scanText(frame); | ||
console.log(data, 666); | ||
// @ts-ignore | ||
const data = (0, _scanText.scanText)(frame, options); | ||
// @ts-ignore | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useWorklets(data); | ||
}, []); | ||
return !!device && /*#__PURE__*/_react.default.createElement(_reactNativeVisionCamera.Camera, _extends({ | ||
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !!device && /*#__PURE__*/_react.default.createElement(_reactNativeVisionCamera.Camera, _extends({ | ||
pixelFormat: "yuv", | ||
ref: ref, | ||
frameProcessor: frameProcessor | ||
}, props)); | ||
frameProcessor: frameProcessor, | ||
device: device | ||
}, p))); | ||
}); | ||
function useTextRecognition(options) { | ||
return (0, _react.useMemo)(() => (0, _scanText.createTextRecognitionPlugin)(options || { | ||
language: 'latin' | ||
}), [options]); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -6,6 +6,5 @@ "use strict"; | ||
}); | ||
exports.scanText = scanText; | ||
exports.createTextRecognitionPlugin = createTextRecognitionPlugin; | ||
var _reactNativeVisionCamera = require("react-native-vision-camera"); | ||
var _reactNative = require("react-native"); | ||
const plugin = _reactNativeVisionCamera.VisionCameraProxy.initFrameProcessorPlugin('scanText'); | ||
const LINKING_ERROR = `The package 'react-native-vision-camera-v3-text-recognition' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({ | ||
@@ -15,9 +14,17 @@ ios: "- You have run 'pod install'\n", | ||
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; | ||
function scanText(frame, options) { | ||
'worklet'; | ||
function createTextRecognitionPlugin(options) { | ||
const plugin = _reactNativeVisionCamera.VisionCameraProxy.initFrameProcessorPlugin('scanText', { | ||
...options | ||
}); | ||
if (!plugin) { | ||
throw new Error(LINKING_ERROR); | ||
} | ||
return { | ||
scanText: frame => { | ||
'worklet'; | ||
if (plugin == null) throw new Error(LINKING_ERROR); | ||
// @ts-ignore | ||
return options ? plugin.call(frame, options) : plugin.call(frame); | ||
return plugin.call(frame); | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=scanText.js.map |
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import React, { forwardRef } from 'react'; | ||
import React, { forwardRef, useMemo } from 'react'; | ||
import { Camera as VisionCamera, useFrameProcessor } from 'react-native-vision-camera'; | ||
import { createTextRecognitionPlugin } from './scanText'; | ||
import { useRunInJS } from 'react-native-worklets-core'; | ||
import { scanText } from './scanText'; | ||
export { scanText } from './scanText'; | ||
export const Camera = /*#__PURE__*/forwardRef(function Camera(props, ref) { | ||
const { | ||
device, | ||
callback, | ||
device, | ||
options | ||
options = {}, | ||
...p | ||
} = props; | ||
// @ts-ignore | ||
const { | ||
scanText | ||
} = useTextRecognition(options); | ||
const useWorklets = useRunInJS(data => { | ||
callback(data); | ||
}, []); | ||
}, [options]); | ||
const frameProcessor = useFrameProcessor(frame => { | ||
'worklet'; | ||
const data = scanText(frame); | ||
console.log(data, 666); | ||
// @ts-ignore | ||
const data = scanText(frame, options); | ||
// @ts-ignore | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useWorklets(data); | ||
}, []); | ||
return !!device && /*#__PURE__*/React.createElement(VisionCamera, _extends({ | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, !!device && /*#__PURE__*/React.createElement(VisionCamera, _extends({ | ||
pixelFormat: "yuv", | ||
ref: ref, | ||
frameProcessor: frameProcessor | ||
}, props)); | ||
frameProcessor: frameProcessor, | ||
device: device | ||
}, p))); | ||
}); | ||
export function useTextRecognition(options) { | ||
return useMemo(() => createTextRecognitionPlugin(options || { | ||
language: 'latin' | ||
}), [options]); | ||
} | ||
//# sourceMappingURL=index.js.map |
import { VisionCameraProxy } from 'react-native-vision-camera'; | ||
import { Platform } from 'react-native'; | ||
const plugin = VisionCameraProxy.initFrameProcessorPlugin('scanText'); | ||
const LINKING_ERROR = `The package 'react-native-vision-camera-v3-text-recognition' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ | ||
@@ -8,9 +7,17 @@ ios: "- You have run 'pod install'\n", | ||
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; | ||
export function scanText(frame, options) { | ||
'worklet'; | ||
export function createTextRecognitionPlugin(options) { | ||
const plugin = VisionCameraProxy.initFrameProcessorPlugin('scanText', { | ||
...options | ||
}); | ||
if (!plugin) { | ||
throw new Error(LINKING_ERROR); | ||
} | ||
return { | ||
scanText: frame => { | ||
'worklet'; | ||
if (plugin == null) throw new Error(LINKING_ERROR); | ||
// @ts-ignore | ||
return options ? plugin.call(frame, options) : plugin.call(frame); | ||
return plugin.call(frame); | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=scanText.js.map |
import React from 'react'; | ||
import type { TextDataMap } from './types'; | ||
export { scanText } from './scanText'; | ||
export type { TextData, TextDataMap } from './types'; | ||
import type { TextRecognitionOptions, TextRecognitionPlugin, Text } from './types'; | ||
export declare const Camera: React.ForwardRefExoticComponent<{ | ||
callback: (data: TextDataMap) => void; | ||
options: import("./types").TextRecognitionOptions; | ||
callback: (data: Text) => void; | ||
options: TextRecognitionOptions; | ||
} & import("react-native-vision-camera").CameraProps & React.RefAttributes<any>>; | ||
export declare function useTextRecognition(options?: TextRecognitionOptions): TextRecognitionPlugin; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import type { Frame, TextRecognitionOptions, TextDataMap } from './types'; | ||
export declare function scanText(frame: Frame, options: TextRecognitionOptions): TextDataMap; | ||
import type { TextRecognitionPlugin, TextRecognitionOptions } from './types'; | ||
export declare function createTextRecognitionPlugin(options: TextRecognitionOptions): TextRecognitionPlugin; | ||
//# sourceMappingURL=scanText.d.ts.map |
@@ -1,3 +0,4 @@ | ||
export type { CameraProps, Frame, FrameProcessorPlugin, FrameProcessor, } from 'react-native-vision-camera'; | ||
import type { CameraProps } from 'react-native-vision-camera'; | ||
export type { Frame, FrameProcessor, FrameProcessorPlugin, FrameInternal, CameraProps, CameraDevice, } from 'react-native-vision-camera'; | ||
export type { ForwardedRef } from 'react'; | ||
import type { CameraProps, Frame } from 'react-native-vision-camera'; | ||
export interface TextRecognitionOptions { | ||
@@ -25,9 +26,12 @@ language: 'latin' | 'chinese' | 'devanagari' | 'japanese' | 'korean'; | ||
}; | ||
export type TextDataMap = { | ||
[key: number]: TextData; | ||
}; | ||
export interface Text { | ||
[key: number | string]: TextData; | ||
} | ||
export type CameraTypes = { | ||
callback: (data: TextDataMap) => void; | ||
callback: (data: Text) => void; | ||
options: TextRecognitionOptions; | ||
} & CameraProps; | ||
export type TextRecognitionPlugin = { | ||
scanText: (frame: Frame) => Text; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "react-native-vision-camera-v3-text-recognition", | ||
"version": "1.0.6", | ||
"version": "1.1.1", | ||
"description": "The frame processor plugin for text recognition using Google ML Kit library for react-native-vision-camera with high performance.", | ||
@@ -72,4 +72,4 @@ "main": "lib/commonjs/index", | ||
"react-native-builder-bob": "^0.23.2", | ||
"react-native-vision-camera": "3.9.1", | ||
"react-native-worklets-core": "0.4.0", | ||
"react-native-vision-camera": "3.9.2", | ||
"react-native-worklets-core": "0.5.0", | ||
"release-it": "^15.0.0", | ||
@@ -76,0 +76,0 @@ "turbo": "^1.10.7", |
The frame processor plugin for text recognition using Google ML Kit library for react-native-vision-camera with high performance. | ||
# 🚨 Required Modules | ||
react-native-vision-camera = 3.9.2 <br/> | ||
react-native-worklets-core = 0.5.0 | ||
react-native-vision-camera => 3.9.0 <br /> | ||
react-native-worklets-core = 0.4.0 | ||
## 💻 Installation | ||
@@ -26,17 +24,64 @@ | ||
```js | ||
import React, { useState } from 'react' | ||
import { useCameraDevice } from 'react-native-vision-camera' | ||
import { Camera } from 'react-native-vision-camera-v3-text-recognition'; | ||
const [text,setText] = useState(null) | ||
function App (){ | ||
const [data,setData] = useState(null) | ||
const device = useCameraDevice('back'); | ||
console.log(data) | ||
return( | ||
<> | ||
{!!device && ( | ||
<Camera | ||
style={StyleSheet.absoluteFill} | ||
device={device} | ||
isActive | ||
// optional | ||
options={{ | ||
language:'latin' | ||
}} | ||
callback={(d) => setData(d)} | ||
/> | ||
)} | ||
</> | ||
) | ||
} | ||
console.log(text) | ||
``` | ||
### Also You Can Use Like This | ||
<Camera | ||
options={{ | ||
language: "latin" | ||
}} | ||
style={StyleSheet.absoluteFill} | ||
device={device} | ||
callback={(data) => setText(data)} | ||
{...props} | ||
/> | ||
```js | ||
import React from 'react'; | ||
import { StyleSheet } from "react-native"; | ||
import { | ||
Camera, | ||
useCameraDevice, | ||
useFrameProcessor, | ||
} from "react-native-vision-camera"; | ||
import { useTextRecognition } from "react-native-vision-camera-v3-text-recognition"; | ||
function App() { | ||
const device = useCameraDevice('back'); | ||
const options = { language : 'latin' } | ||
const {scanText} = useTextRecognition(options) | ||
const frameProcessor = useFrameProcessor((frame) => { | ||
'worklet' | ||
const data = scanText(frame) | ||
console.log(data, 'data') | ||
}, []) | ||
return ( | ||
<> | ||
{!!device && ( | ||
<Camera | ||
style={StyleSheet.absoluteFill} | ||
device={device} | ||
isActive | ||
frameProcessor={frameProcessor} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
export default App; | ||
``` | ||
@@ -46,3 +91,2 @@ | ||
--- | ||
## ⚙️ Options | ||
@@ -49,0 +93,0 @@ |
@@ -0,14 +1,12 @@ | ||
import { VisionCameraProxy } from 'react-native-vision-camera'; | ||
import type { | ||
Frame, | ||
TextRecognitionPlugin, | ||
TextRecognitionOptions, | ||
Text, | ||
FrameProcessorPlugin, | ||
TextRecognitionOptions, | ||
TextDataMap, | ||
} from './types'; | ||
import { VisionCameraProxy } from 'react-native-vision-camera'; | ||
import { Platform } from 'react-native'; | ||
const plugin: FrameProcessorPlugin | undefined = | ||
VisionCameraProxy.initFrameProcessorPlugin('scanText'); | ||
const LINKING_ERROR = | ||
const LINKING_ERROR: string = | ||
`The package 'react-native-vision-camera-v3-text-recognition' doesn't seem to be linked. Make sure: \n\n` + | ||
@@ -19,10 +17,18 @@ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + | ||
export function scanText( | ||
frame: Frame, | ||
export function createTextRecognitionPlugin( | ||
options: TextRecognitionOptions | ||
): TextDataMap { | ||
'worklet'; | ||
if (plugin == null) throw new Error(LINKING_ERROR); | ||
// @ts-ignore | ||
return options ? plugin.call(frame, options) : plugin.call(frame); | ||
): TextRecognitionPlugin { | ||
const plugin: FrameProcessorPlugin | undefined = | ||
VisionCameraProxy.initFrameProcessorPlugin('scanText', { | ||
...options, | ||
}); | ||
if (!plugin) { | ||
throw new Error(LINKING_ERROR); | ||
} | ||
return { | ||
scanText: (frame: Frame): Text => { | ||
'worklet'; | ||
return plugin.call(frame) as unknown as Text; | ||
}, | ||
}; | ||
} |
export type { | ||
CameraProps, | ||
Frame, | ||
FrameProcessor, | ||
FrameProcessorPlugin, | ||
FrameProcessor, | ||
FrameInternal, | ||
CameraProps, | ||
CameraDevice, | ||
} from 'react-native-vision-camera'; | ||
import type { CameraProps } from 'react-native-vision-camera'; | ||
export type { ForwardedRef } from 'react'; | ||
import type { CameraProps, Frame } from 'react-native-vision-camera'; | ||
export interface TextRecognitionOptions { | ||
@@ -32,9 +35,13 @@ language: 'latin' | 'chinese' | 'devanagari' | 'japanese' | 'korean'; | ||
export type TextDataMap = { | ||
[key: number]: TextData; | ||
}; | ||
export interface Text { | ||
[key: number | string]: TextData; | ||
} | ||
export type CameraTypes = { | ||
callback: (data: TextDataMap) => void; | ||
callback: (data: Text) => void; | ||
options: TextRecognitionOptions; | ||
} & CameraProps; | ||
export type TextRecognitionPlugin = { | ||
scanText: (frame: Frame) => Text; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44237
314
112