@equinor/react-native-mad-tag-ocr 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @equinor/react-native-mad-ocr
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0ef529f: Add mad-tag-ocr package
@@ -0,0 +1,44 @@
1
+ # How we work
2
+
3
+ In Equinor,
4
+ [how we deliver is as important as what we deliver](https://www.equinor.com/en/careers/our-culture.html).
5
+
6
+ This set the expectations for how we collaborate in our open source projects, and applies to all
7
+ community members and participants in any Equinor maintained project.
8
+
9
+ ## Handling issues within the communities
10
+
11
+ We expect all to have a low threshold for raising issues, or in general discuss how we live up to
12
+ our [values](https://www.equinor.com/en/about-us.html#our-values). Equally, we also encourage all
13
+ community members to appreciate when concerns are raised, and make its best effort in solving them.
14
+
15
+ As well as responsibility for what is delivered the project maintainers are also responsible
16
+ creating an environment for proper handling of issues raised within the communities.
17
+
18
+ ## Call out for assistance
19
+
20
+ For any problem not directly resolvable within the community, we encourage you to call out for
21
+ assistance. Getting an outsiders perspective on the topic might be just what is needed for you to
22
+ proceed.
23
+
24
+ Send an e-mail to opensource_at_equinor.com and invite for a discussion. The email will be handled
25
+ by a team within the Equinor organization.
26
+
27
+ Your request will be kept confidential from the team or community in question, unless you chose to
28
+ disclose it yourself.
29
+
30
+ ## Ethics helpline
31
+
32
+ In Equinor, we want you to speak up whenever you see unethical behaviour that conflicts with our
33
+ values or threatens our reputation.
34
+
35
+ To underline this, we continuously encourage and remind our employees and any external third parties
36
+ interacting with us to raise concerns or report any suspected or potential breaches of law or
37
+ company policies.
38
+
39
+ For any questions or issues that one suspect falls outside the scope of behaviour regulated, and
40
+ handled within the open source code of conduct, or you wish to place an anonymous, confidential
41
+ report we encourage to use the
42
+ [Equinor Ethics helpline](https://secure.ethicspoint.eu/domain/media/en/gui/102166/index.html).
43
+
44
+ This helpline is hosted by a third party helpline provider.
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Equinor ASA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
17
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # React Native Mad Optical Character Recognition (OCR)
2
+
3
+ Mad Tag Optical Character Recognition (OCR) adds a camera component that recognizes and highlights
4
+ text in real-time. The highlighted text can also be selected by the user. This is useful for tasks
5
+ such as scanning tags on Equinor facilities, but can also be used to scan other types of text.
6
+
7
+ ## 🖌️ How to use
8
+
9
+ This library exports a component called `OCRCamera` that you can import into your project. The
10
+ example below shows how it can be used.
11
+
12
+ ```tsx
13
+ import { OCRCamera } from "@equinor/react-native-mad-tag-ocr";
14
+
15
+ export const MyComponent = () => {
16
+ const { hasPermission, requestPermission } = useCameraPermission();
17
+
18
+ useFocusEffect(() => void requestPermission());
19
+
20
+ const onScanResult = (tag: string) => {
21
+ // do someting here
22
+ };
23
+
24
+ const onScanCancel = () => {
25
+ // do something here
26
+ };
27
+
28
+ return <OCRCamera onSelectTag={onScanResult} onClose={onScanCancel} />;
29
+ };
30
+ ```
31
+
32
+ Remember to call the `requestPermission` function from `react-native-vision-camera` before using the
33
+ OCR camera. Also, if your project is using the [React Navigation](https://reactnavigation.org/)
34
+ package, you can call `useFocusEffect` to make sure permission is requested every time you navigate
35
+ to the OCR camera. This ensures the user is always asked for permissions even if the user initially
36
+ clicked decline.
37
+
38
+ Note that the OCR camera only supports viewing in portrait mode.
39
+
40
+ ## ⚙️ Installation
41
+
42
+ This library has the following peer dependencies that you need to install in your project. Please
43
+ refer to the documentation below for information on how to do this.
44
+
45
+ - [React Native Vision Camera](https://github.com/mrousavy/react-native-vision-camera) provides
46
+ the underlying camera component that support frame processor plugins such as OCR
47
+ - [Vision Camera OCR](https://github.com/ismaelsousa/vision-camera-ocr#readme) is a frame
48
+ processor plugin for the vision camera package that provides OCR
49
+ - [React Native Worklets Core](https://github.com/margelo/react-native-worklets-core) for running
50
+ frame processors on a seperate thread
51
+ - [React Native Skia](https://shopify.github.io/react-native-skia/) for drawing on the camera
52
+ screen
File without changes
@@ -0,0 +1,44 @@
1
+ // src/components/SelectTagDialog.tsx
2
+ import React from "react";
3
+ import { Button, TextField, Typography } from "@equinor/mad-components";
4
+ import { Dialog } from "@equinor/mad-components/dist/components/Dialog";
5
+ import { DialogActions } from "@equinor/mad-components/dist/components/Dialog/DialogActions";
6
+ import { DialogCustomContent } from "@equinor/mad-components/dist/components/Dialog/DialogCustomContent";
7
+ import { DialogHeader } from "@equinor/mad-components/dist/components/Dialog/DialogHeader";
8
+ import { View } from "react-native";
9
+ var SelectTagDialog = ({
10
+ show,
11
+ tagText,
12
+ maxTagLength,
13
+ onChangeTagText,
14
+ onClickRetry,
15
+ onClickConfirm
16
+ }) => {
17
+ return /* @__PURE__ */ React.createElement(Dialog, { isOpen: show }, /* @__PURE__ */ React.createElement(DialogHeader, null, /* @__PURE__ */ React.createElement(Typography, { variant: "h6" }, "Confirm & edit selection")), /* @__PURE__ */ React.createElement(DialogCustomContent, null, /* @__PURE__ */ React.createElement(
18
+ TextField,
19
+ {
20
+ multiline: false,
21
+ label: "Selected tag",
22
+ value: tagText,
23
+ onChange: onChangeTagText,
24
+ maxLength: maxTagLength,
25
+ style: { textAlign: "center" }
26
+ }
27
+ )), /* @__PURE__ */ React.createElement(DialogActions, { align: "left" }, /* @__PURE__ */ React.createElement(
28
+ View,
29
+ {
30
+ style: {
31
+ display: "flex",
32
+ flexDirection: "row",
33
+ justifyContent: "space-between",
34
+ width: "100%"
35
+ }
36
+ },
37
+ /* @__PURE__ */ React.createElement(Button, { title: "Retry", onPress: onClickRetry }),
38
+ /* @__PURE__ */ React.createElement(Button, { title: "Confirm", disabled: !tagText.length, onPress: onClickConfirm })
39
+ )));
40
+ };
41
+
42
+ export {
43
+ SelectTagDialog
44
+ };
@@ -0,0 +1,14 @@
1
+ // src/hooks/useSharedState.ts
2
+ import { useEffect } from "react";
3
+ import { useSharedValue } from "react-native-worklets-core";
4
+ function useStateToSharedValue(state) {
5
+ const sharedValue = useSharedValue(state);
6
+ useEffect(() => {
7
+ sharedValue.value = state;
8
+ }, [state, sharedValue]);
9
+ return sharedValue;
10
+ }
11
+
12
+ export {
13
+ useStateToSharedValue
14
+ };
@@ -0,0 +1,24 @@
1
+ // src/consts.ts
2
+ var MaxTagLength = 20;
3
+ var MinTagLength = 4;
4
+ var BoundingBoxPadding = 10;
5
+ var OcrUsageSteps = [
6
+ "1. Place the tag in the view of the camera",
7
+ "2. A rectangle should appear around the tag",
8
+ "3. Click within the rectanble to select the tag",
9
+ "4. A new prompt appears where you can make adjustments to the tag text if needed",
10
+ "5. Click confirm to search"
11
+ ];
12
+ var defaultButtonConfig = {
13
+ showCloseButton: true,
14
+ showInfoButton: true,
15
+ extraButtons: []
16
+ };
17
+
18
+ export {
19
+ MaxTagLength,
20
+ MinTagLength,
21
+ BoundingBoxPadding,
22
+ OcrUsageSteps,
23
+ defaultButtonConfig
24
+ };
@@ -0,0 +1,60 @@
1
+ import {
2
+ BoundingBoxPadding
3
+ } from "./chunk-JFXZ5SLD.js";
4
+
5
+ // src/utils.ts
6
+ import { PaintStyle, Skia } from "@shopify/react-native-skia";
7
+ var getSkiaRoundedRect = (boundingBox) => {
8
+ "worklet";
9
+ return {
10
+ rx: 10,
11
+ ry: 10,
12
+ rect: boundingBox
13
+ };
14
+ };
15
+ var getBoundingBox = (centerX, centerY, width, height) => {
16
+ "worklet";
17
+ return {
18
+ x: centerX - width / 2 - BoundingBoxPadding,
19
+ y: centerY - height / 2 - BoundingBoxPadding,
20
+ width: width + BoundingBoxPadding * 2,
21
+ height: height + BoundingBoxPadding * 2
22
+ };
23
+ };
24
+ var isPointInsideBoundingBox = (boundingBox, point) => {
25
+ "worklet";
26
+ return point.x >= boundingBox.x && point.x <= boundingBox.x + boundingBox.width && point.y >= boundingBox.y && point.y <= boundingBox.y + boundingBox.height;
27
+ };
28
+ var translatePointToFrame = (frameWidth, frameHeight, cameraWidth, cameraHeight, screenScale, point) => {
29
+ "worklet";
30
+ const aspectRatioCamera = cameraWidth / cameraHeight;
31
+ const aspectRatioFrame = frameWidth / frameHeight;
32
+ const aspectRatioDifference = aspectRatioCamera - aspectRatioFrame;
33
+ const pxZoomHeight = aspectRatioDifference > 0 ? aspectRatioDifference * frameHeight : 0;
34
+ const pxZoomWidth = aspectRatioDifference < 0 ? -aspectRatioDifference * frameWidth : 0;
35
+ const densityRatio = frameWidth / cameraWidth;
36
+ return {
37
+ x: point.x * densityRatio + pxZoomWidth / 2 / screenScale,
38
+ y: point.y * densityRatio + pxZoomHeight / 2 / screenScale
39
+ };
40
+ };
41
+ var formatTag = (text) => {
42
+ "worklet";
43
+ return text.split("").filter((char) => new RegExp(/^[a-zæøå0-9-]/i).test(char)).join("");
44
+ };
45
+ function getPaintConfig(color) {
46
+ const paint = Skia.Paint();
47
+ paint.setColor(Skia.Color(color));
48
+ paint.setStyle(PaintStyle.Stroke);
49
+ paint.setStrokeWidth(2);
50
+ return paint;
51
+ }
52
+
53
+ export {
54
+ getSkiaRoundedRect,
55
+ getBoundingBox,
56
+ isPointInsideBoundingBox,
57
+ translatePointToFrame,
58
+ formatTag,
59
+ getPaintConfig
60
+ };
@@ -0,0 +1,41 @@
1
+ // src/components/PopoverButton.tsx
2
+ import React, { useRef, useState } from "react";
3
+ import {
4
+ Button,
5
+ EDSStyleSheet,
6
+ Popover,
7
+ Typography,
8
+ useStyles
9
+ } from "@equinor/mad-components";
10
+ var PopoverButton = ({ icon, title, text }) => {
11
+ const style = useStyles(themeStyles);
12
+ const buttonRef = useRef(null);
13
+ const [showPopover, setShowPopover] = useState(false);
14
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
15
+ Popover,
16
+ {
17
+ open: showPopover,
18
+ placement: "bottom",
19
+ anchorEl: buttonRef,
20
+ style: style.popover
21
+ },
22
+ /* @__PURE__ */ React.createElement(Typography, { variant: "h5", style: style.title }, title),
23
+ /* @__PURE__ */ React.createElement(Typography, null, text)
24
+ ), /* @__PURE__ */ React.createElement(
25
+ Button.Icon,
26
+ {
27
+ ref: buttonRef,
28
+ name: icon,
29
+ iconSize: 30,
30
+ onPress: () => setShowPopover(!showPopover)
31
+ }
32
+ ));
33
+ };
34
+ var themeStyles = EDSStyleSheet.create(() => ({
35
+ title: { marginBottom: 10 },
36
+ popover: { maxWidth: 500 }
37
+ }));
38
+
39
+ export {
40
+ PopoverButton
41
+ };
@@ -0,0 +1,206 @@
1
+ import {
2
+ formatTag,
3
+ getBoundingBox,
4
+ getPaintConfig,
5
+ getSkiaRoundedRect,
6
+ isPointInsideBoundingBox,
7
+ translatePointToFrame
8
+ } from "./chunk-WA2RO7BG.js";
9
+ import {
10
+ MaxTagLength,
11
+ OcrUsageSteps,
12
+ defaultButtonConfig
13
+ } from "./chunk-JFXZ5SLD.js";
14
+ import {
15
+ PopoverButton
16
+ } from "./chunk-XLETJGD5.js";
17
+ import {
18
+ SelectTagDialog
19
+ } from "./chunk-GWY64QKM.js";
20
+ import {
21
+ useStateToSharedValue
22
+ } from "./chunk-JE4UMMVX.js";
23
+ import {
24
+ __spreadValues
25
+ } from "./chunk-ZSUG26OQ.js";
26
+
27
+ // src/components/Camera/OCRCamera.tsx
28
+ import React, { useState } from "react";
29
+ import {
30
+ Camera,
31
+ useCameraDevice,
32
+ useCameraFormat,
33
+ useCameraPermission,
34
+ useSkiaFrameProcessor
35
+ } from "react-native-vision-camera";
36
+ import { View, useWindowDimensions } from "react-native";
37
+ import { useRunOnJS, useSharedValue } from "react-native-worklets-core";
38
+ import { Button, EDSStyleSheet, useStyles } from "@equinor/mad-components";
39
+ import { scanOCR } from "@ismaelmoreiraa/vision-camera-ocr";
40
+ var OCRCamera = ({
41
+ buttonConfig = defaultButtonConfig,
42
+ enableConfirmTextDialog = true,
43
+ fps = 60,
44
+ textHighlightColor = "red",
45
+ onSelectTag,
46
+ onClose,
47
+ shouldHighlightText
48
+ }) => {
49
+ var _a;
50
+ const dim = useWindowDimensions();
51
+ const paintConfig = useStateToSharedValue(getPaintConfig(textHighlightColor));
52
+ const styles = useStyles(themeStyles);
53
+ const device = useCameraDevice("back");
54
+ const { hasPermission } = useCameraPermission();
55
+ const [showDialog, setShowDialog] = useState(false);
56
+ const [clickedText, setClickedText] = useState("");
57
+ const enableDialogShared = useStateToSharedValue(enableConfirmTextDialog);
58
+ const clickedPointShared = useSharedValue(void 0);
59
+ const [cameraWidth, setCameraWidth] = useState(dim.width);
60
+ const cameraWidthShared = useStateToSharedValue(cameraWidth);
61
+ const [cameraHeight, setCameraHeight] = useState(dim.height);
62
+ const cameraHeightShared = useSharedValue(cameraHeight);
63
+ const onLayout = (event) => {
64
+ setCameraWidth(event.nativeEvent.layout.width);
65
+ setCameraHeight(event.nativeEvent.layout.height);
66
+ };
67
+ const setScannedTagOnJS = useRunOnJS(
68
+ (text) => {
69
+ if (!enableDialogShared.value)
70
+ confirmSelection(text);
71
+ else {
72
+ if (text)
73
+ setShowDialog(true);
74
+ setClickedText(text);
75
+ }
76
+ },
77
+ [enableDialogShared.value]
78
+ );
79
+ const clearSelection = () => {
80
+ setClickedText("");
81
+ setShowDialog(false);
82
+ };
83
+ const confirmSelection = (text) => {
84
+ if (onSelectTag)
85
+ onSelectTag(text);
86
+ setShowDialog(false);
87
+ };
88
+ const format = useCameraFormat(device, [
89
+ {
90
+ fps,
91
+ videoResolution: {
92
+ width: cameraWidth,
93
+ height: cameraHeight
94
+ }
95
+ }
96
+ ]);
97
+ const shouldHighlightTextWorklet = (text, boundingBox) => {
98
+ "worklet";
99
+ return shouldHighlightText ? shouldHighlightText(text, boundingBox) : true;
100
+ };
101
+ const handleHighlightedTextClickWorklet = (text) => {
102
+ "worklet";
103
+ void setScannedTagOnJS(formatTag(text));
104
+ };
105
+ const frameProcessor = useSkiaFrameProcessor(
106
+ (frame) => {
107
+ "worklet";
108
+ try {
109
+ const scannedOcr = scanOCR(frame);
110
+ frame.render();
111
+ const translatedPoint = clickedPointShared.value && translatePointToFrame(
112
+ frame.width,
113
+ frame.height,
114
+ cameraWidthShared.value,
115
+ cameraHeightShared.value,
116
+ dim.scale,
117
+ clickedPointShared.value
118
+ );
119
+ for (const block of scannedOcr.result.blocks) {
120
+ if (!(block == null ? void 0 : block.frame))
121
+ continue;
122
+ const boundingBox = getBoundingBox(
123
+ block.frame.boundingCenterX,
124
+ block.frame.boundingCenterY,
125
+ block.frame.width,
126
+ block.frame.height
127
+ );
128
+ if (shouldHighlightTextWorklet(block.text, boundingBox)) {
129
+ frame.drawRRect(getSkiaRoundedRect(boundingBox), paintConfig.value);
130
+ if (translatedPoint && isPointInsideBoundingBox(boundingBox, translatedPoint)) {
131
+ handleHighlightedTextClickWorklet(block.text);
132
+ }
133
+ }
134
+ }
135
+ clickedPointShared.value = void 0;
136
+ } catch (error) {
137
+ console.error(error);
138
+ }
139
+ },
140
+ [clickedPointShared.value, cameraWidthShared.value, cameraHeightShared.value, paintConfig]
141
+ );
142
+ const onTap = (event) => {
143
+ clickedPointShared.value = {
144
+ x: event.nativeEvent.locationX,
145
+ y: event.nativeEvent.locationY
146
+ };
147
+ };
148
+ const onClickClose = () => onClose == null ? void 0 : onClose();
149
+ if (!device || !hasPermission) {
150
+ console.error(!device ? "No camera device found" : "No camera permission");
151
+ onClickClose();
152
+ return null;
153
+ }
154
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
155
+ SelectTagDialog,
156
+ {
157
+ show: showDialog,
158
+ tagText: clickedText,
159
+ maxTagLength: MaxTagLength,
160
+ onChangeTagText: (text) => setClickedText(text),
161
+ onClickRetry: clearSelection,
162
+ onClickConfirm: () => confirmSelection(clickedText)
163
+ }
164
+ ), /* @__PURE__ */ React.createElement(View, { style: styles.container }, !!buttonConfig && /* @__PURE__ */ React.createElement(View, { style: styles.buttonContainer }, buttonConfig.showCloseButton && /* @__PURE__ */ React.createElement(Button.Icon, { name: "close", iconSize: 30, onPress: onClickClose }), buttonConfig.showInfoButton && /* @__PURE__ */ React.createElement(
165
+ PopoverButton,
166
+ {
167
+ icon: "information",
168
+ title: "How to use the tag scanner",
169
+ text: OcrUsageSteps.join("\n")
170
+ }
171
+ ), (_a = buttonConfig.extraButtons) == null ? void 0 : _a.map((buttonProps, index) => /* @__PURE__ */ React.createElement(Button.Icon, __spreadValues({ key: index, iconSize: 30 }, buttonProps)))), /* @__PURE__ */ React.createElement(
172
+ Camera,
173
+ {
174
+ onLayout,
175
+ onTouchStart: onTap,
176
+ device,
177
+ format,
178
+ fps,
179
+ isActive: !showDialog,
180
+ style: { flex: 1 },
181
+ resizeMode: "cover",
182
+ frameProcessor,
183
+ enableZoomGesture: true,
184
+ videoStabilizationMode: "auto",
185
+ orientation: "portrait"
186
+ }
187
+ )));
188
+ };
189
+ var themeStyles = EDSStyleSheet.create((theme) => ({
190
+ container: {
191
+ flex: 1,
192
+ position: "relative"
193
+ },
194
+ buttonContainer: {
195
+ zIndex: 1,
196
+ position: "absolute",
197
+ right: 0,
198
+ gap: theme.spacing.spacer.small,
199
+ paddingHorizontal: theme.spacing.container.paddingHorizontal,
200
+ paddingVertical: theme.spacing.container.paddingVertical * 2
201
+ }
202
+ }));
203
+
204
+ export {
205
+ OCRCamera
206
+ };
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ export {
19
+ __spreadValues
20
+ };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { OCRCameraProps } from "../../types";
3
+ export declare const OCRCamera: ({ buttonConfig, enableConfirmTextDialog, fps, textHighlightColor, onSelectTag, onClose, shouldHighlightText, }: OCRCameraProps) => React.JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import {
2
+ OCRCamera
3
+ } from "../../chunk-Z34UOWCG.js";
4
+ import "../../chunk-WA2RO7BG.js";
5
+ import "../../chunk-JFXZ5SLD.js";
6
+ import "../../chunk-XLETJGD5.js";
7
+ import "../../chunk-GWY64QKM.js";
8
+ import "../../chunk-JE4UMMVX.js";
9
+ import "../../chunk-ZSUG26OQ.js";
10
+ export {
11
+ OCRCamera
12
+ };
@@ -0,0 +1,2 @@
1
+ import { OCRCameraProps } from "../../types";
2
+ export declare const OCRCamera: ({ buttonConfig, enableConfirmTextDialog, fps, textHighlightColor, onSelectTag, onClose, shouldHighlightText, }: OCRCameraProps) => null;
@@ -0,0 +1,15 @@
1
+ import "../../chunk-ZSUG26OQ.js";
2
+
3
+ // src/components/Camera/OCRCamera.web.tsx
4
+ var OCRCamera = ({
5
+ buttonConfig,
6
+ enableConfirmTextDialog,
7
+ fps,
8
+ textHighlightColor,
9
+ onSelectTag,
10
+ onClose,
11
+ shouldHighlightText
12
+ }) => null;
13
+ export {
14
+ OCRCamera
15
+ };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { IconName } from "@equinor/mad-components";
3
+ type PopoverButtonProps = {
4
+ icon: IconName;
5
+ title: string;
6
+ text: string;
7
+ };
8
+ export declare const PopoverButton: ({ icon, title, text }: PopoverButtonProps) => React.JSX.Element;
9
+ export {};
@@ -0,0 +1,7 @@
1
+ import {
2
+ PopoverButton
3
+ } from "../chunk-XLETJGD5.js";
4
+ import "../chunk-ZSUG26OQ.js";
5
+ export {
6
+ PopoverButton
7
+ };
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ export type DialogOptions = {
3
+ show: boolean;
4
+ tagText: string;
5
+ maxTagLength: number;
6
+ onChangeTagText: (text: string) => void;
7
+ onClickRetry: () => void;
8
+ onClickConfirm: () => void;
9
+ };
10
+ export declare const SelectTagDialog: ({ show, tagText, maxTagLength, onChangeTagText, onClickRetry, onClickConfirm, }: DialogOptions) => React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import {
2
+ SelectTagDialog
3
+ } from "../chunk-GWY64QKM.js";
4
+ import "../chunk-ZSUG26OQ.js";
5
+ export {
6
+ SelectTagDialog
7
+ };
@@ -0,0 +1,6 @@
1
+ import { ButtonConfig } from "./types";
2
+ export declare const MaxTagLength = 20;
3
+ export declare const MinTagLength = 4;
4
+ export declare const BoundingBoxPadding = 10;
5
+ export declare const OcrUsageSteps: string[];
6
+ export declare const defaultButtonConfig: ButtonConfig;
package/dist/consts.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ BoundingBoxPadding,
3
+ MaxTagLength,
4
+ MinTagLength,
5
+ OcrUsageSteps,
6
+ defaultButtonConfig
7
+ } from "./chunk-JFXZ5SLD.js";
8
+ import "./chunk-ZSUG26OQ.js";
9
+ export {
10
+ BoundingBoxPadding,
11
+ MaxTagLength,
12
+ MinTagLength,
13
+ OcrUsageSteps,
14
+ defaultButtonConfig
15
+ };
@@ -0,0 +1 @@
1
+ export declare function useStateToSharedValue<T>(state: T): import("react-native-worklets-core").ISharedValue<T>;
@@ -0,0 +1,7 @@
1
+ import {
2
+ useStateToSharedValue
3
+ } from "../chunk-JE4UMMVX.js";
4
+ import "../chunk-ZSUG26OQ.js";
5
+ export {
6
+ useStateToSharedValue
7
+ };
@@ -0,0 +1,2 @@
1
+ export { OCRCamera } from "./components/Camera/OCRCamera";
2
+ export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import "./chunk-6F4PWJZI.js";
2
+ import {
3
+ OCRCamera
4
+ } from "./chunk-Z34UOWCG.js";
5
+ import "./chunk-WA2RO7BG.js";
6
+ import "./chunk-JFXZ5SLD.js";
7
+ import "./chunk-XLETJGD5.js";
8
+ import "./chunk-GWY64QKM.js";
9
+ import "./chunk-JE4UMMVX.js";
10
+ import "./chunk-ZSUG26OQ.js";
11
+ export {
12
+ OCRCamera
13
+ };
@@ -0,0 +1,50 @@
1
+ import { IconButtonProps } from "@equinor/mad-components";
2
+ export type Color = string | number | Float32Array | number[];
3
+ export type Point = {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ export type BoundingBox = {
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ };
13
+ export type ButtonConfig = {
14
+ showCloseButton?: boolean;
15
+ showInfoButton?: boolean;
16
+ extraButtons?: IconButtonProps[];
17
+ };
18
+ export type OCRCameraProps = {
19
+ /**
20
+ * Target frames per second that the camera should use
21
+ * Can be reduced to limit fps drops when scanning many text blocks simultaneously
22
+ */
23
+ fps?: number;
24
+ /**
25
+ * Controls whether a confirm selection dialog is shown when the user clicks a highlighted text block
26
+ * If true, `onSelectTag` is called after the user presses `confirm` in the dialog
27
+ * If false, `onSelectTag` is called immediately when the user clicks a highlighted text block
28
+ */
29
+ enableConfirmTextDialog?: boolean;
30
+ /**
31
+ * Color of the bounding box shown around text blocks
32
+ */
33
+ textHighlightColor?: Color;
34
+ /**
35
+ * Customize which buttons to show on the top right of the screen
36
+ */
37
+ buttonConfig?: ButtonConfig;
38
+ /**
39
+ * Is called when the user confirms selected text
40
+ */
41
+ onSelectTag?: (tag: string) => void;
42
+ /**
43
+ * Is called when the user clicks the close button
44
+ */
45
+ onClose?: () => void;
46
+ /**
47
+ * Is called whenever a block of text is detected. If this returns false, then the text block is not highlighted on screen and is not pressable
48
+ */
49
+ shouldHighlightText?: (text: string, textBoundingBox: BoundingBox) => boolean;
50
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ import "./chunk-6F4PWJZI.js";
@@ -0,0 +1,8 @@
1
+ import { Color, InputRRect } from "@shopify/react-native-skia";
2
+ import { BoundingBox, Point } from "./types";
3
+ export declare const getSkiaRoundedRect: (boundingBox: BoundingBox) => InputRRect;
4
+ export declare const getBoundingBox: (centerX: number, centerY: number, width: number, height: number) => BoundingBox;
5
+ export declare const isPointInsideBoundingBox: (boundingBox: BoundingBox, point: Point) => boolean;
6
+ export declare const translatePointToFrame: (frameWidth: number, frameHeight: number, cameraWidth: number, cameraHeight: number, screenScale: number, point: Point) => Point;
7
+ export declare const formatTag: (text: string) => string;
8
+ export declare function getPaintConfig(color: Color): import("@shopify/react-native-skia").SkPaint;
package/dist/utils.js ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ formatTag,
3
+ getBoundingBox,
4
+ getPaintConfig,
5
+ getSkiaRoundedRect,
6
+ isPointInsideBoundingBox,
7
+ translatePointToFrame
8
+ } from "./chunk-WA2RO7BG.js";
9
+ import "./chunk-JFXZ5SLD.js";
10
+ import "./chunk-ZSUG26OQ.js";
11
+ export {
12
+ formatTag,
13
+ getBoundingBox,
14
+ getPaintConfig,
15
+ getSkiaRoundedRect,
16
+ isPointInsideBoundingBox,
17
+ translatePointToFrame
18
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@equinor/react-native-mad-tag-ocr",
3
+ "version": "0.0.1",
4
+ "description": "A React Native library for scanning tags",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsup-node && echo '\n ⚙️ Generating typescript declarations..' && tsc --project tsconfig.json --emitDeclarationOnly --declaration",
8
+ "dev": "tsup-node --watch --clean=false",
9
+ "lint": "eslint src/",
10
+ "clean": "rm -rf node_modules/ && rm -rf dist/"
11
+ },
12
+ "keywords": [
13
+ "react native",
14
+ "OCR",
15
+ "markup",
16
+ "typescript"
17
+ ],
18
+ "author": {
19
+ "name": "Equinor Mobile App Delivery team (MAD)"
20
+ },
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/equinor/mad/issues"
24
+ },
25
+ "homepage": "https://github.com/equinor/mad/",
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "dependencies": {
29
+ "@equinor/mad-components": "*"
30
+ },
31
+ "devDependencies": {
32
+ "@types/react": "~18.2.43",
33
+ "@equinor/eslint-config-mad": "*",
34
+ "@ismaelmoreiraa/vision-camera-ocr": "^3.0.1",
35
+ "react-native-vision-camera": "^4.0.4",
36
+ "react-native-worklets-core": "^1.3.3",
37
+ "@shopify/react-native-skia": "1.2.3",
38
+ "react-native-gesture-handler": "^2.14.0"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=18.0",
42
+ "react-native": ">=0.70",
43
+ "@ismaelmoreiraa/vision-camera-ocr": "^3.0.1",
44
+ "react-native-vision-camera": "^4.0.4",
45
+ "react-native-worklets-core": "^1.3.3",
46
+ "@shopify/react-native-skia": "1.2.3",
47
+ "react-native-gesture-handler": "^2.14.0"
48
+ },
49
+ "files": [
50
+ "CODE_OF_CONDUCT.md",
51
+ "LICENSE",
52
+ "CHANGELOG.md",
53
+ "dist"
54
+ ]
55
+ }