@octane-xplat/barcode-scanner 0.18.0 → 0.20.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 +3 -25
- package/package.json +91 -97
- package/src/BarcodeScanner.macos.tsrx +15 -0
- package/src/BarcodeScanner.tsrx +98 -87
- package/src/BarcodeScanner.web.tsrx +127 -108
- package/src/barcode-scanner.macos.ts +175 -9
- package/src/barcode-scanner.ts +115 -94
- package/src/barcode-scanner.web.ts +49 -39
- package/src/barcode-scanner.windows.ts +6 -3
- package/src/format-map.ts +16 -16
- package/src/format-map.web.ts +16 -16
- package/src/index.macos.ts +1 -0
- package/src/native-elements.d.ts +5 -6
- package/src/props.ts +32 -23
- package/src/types.ts +29 -26
- package/types/generated/.tsrx-typegen-manifest.json +0 -9
- package/types/generated/barcode-scanner.d.ts +1 -0
- package/types/generated/props.d.ts +9 -0
- package/types/generated/types.d.ts +3 -0
- package/LICENSE +0 -21
- package/types/generated/BarcodeScanner.web.d.ts +0 -5
- package/types/generated/barcode-scanner.linux.d.ts +0 -1
- package/types/generated/barcode-scanner.macos.d.ts +0 -2
- package/types/generated/barcode-scanner.web.d.ts +0 -2
- package/types/generated/barcode-scanner.windows.d.ts +0 -2
- package/types/generated/format-map.web.d.ts +0 -3
- package/types/generated/index.macos.d.ts +0 -3
- package/types/generated/index.web.d.ts +0 -4
- package/types/generated/native-elements.d.ts +0 -8
package/README.md
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @octane-xplat/barcode-scanner
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
pnpm add @octane-xplat/barcode-scanner
|
|
5
|
-
```
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-barcode-scanner).
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
decoder. ML Kit (`@nativescript/mlkit-core`) on iOS/Android, the
|
|
9
|
-
`BarcodeDetector` API on web. Decoding only: photo capture stays in
|
|
10
|
-
`@octane-xplat/camera`, gallery picking in `@octane-xplat/media`.
|
|
11
|
-
|
|
12
|
-
```tsx
|
|
13
|
-
import { BarcodeScanner, barcodeScanner } from '@octane-xplat/barcode-scanner'
|
|
14
|
-
|
|
15
|
-
<BarcodeScanner
|
|
16
|
-
formats={['qr', 'ean13']}
|
|
17
|
-
onCodeScanned={({ type, data }) => openCode(data)}
|
|
18
|
-
torch={false}
|
|
19
|
-
/>
|
|
20
|
-
|
|
21
|
-
// Still-image decode — no camera needed.
|
|
22
|
-
const codes = await barcodeScanner.scanImage(fileRef.uri, ['qr'])
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`barcodeScanner.ensure()` requests camera permission (registered as the
|
|
26
|
-
`'camera'` kind on the platform `permissions` seam). Web support depends on
|
|
27
|
-
`BarcodeDetector` — absent on Firefox; `supported` reflects it.
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-barcode-scanner).
|
package/package.json
CHANGED
|
@@ -1,98 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"scripts": {
|
|
94
|
-
"typegen": "tsrx-typegen --target octane",
|
|
95
|
-
"pack:check": "tsrx-typegen --pack-check",
|
|
96
|
-
"typecheck": "node ../../scripts/typecheck.ts"
|
|
97
|
-
}
|
|
98
|
-
}
|
|
2
|
+
"name": "@octane-xplat/barcode-scanner",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Barcode and QR scanning for Octane xplat — ML Kit camera preview + still decode on iOS/Android, Vision still decode on macOS, BarcodeDetector on web",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"nativescript",
|
|
9
|
+
"octane",
|
|
10
|
+
"xplat",
|
|
11
|
+
"barcode",
|
|
12
|
+
"qr",
|
|
13
|
+
"scanner",
|
|
14
|
+
"mlkit"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/barcode-scanner",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
21
|
+
"directory": "packages/barcode-scanner"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"platforms",
|
|
26
|
+
"types",
|
|
27
|
+
"!src/**/*.test.*",
|
|
28
|
+
"!src/**/*.spec.*"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./types/generated/index.d.ts",
|
|
34
|
+
"macos": "./src/index.macos.ts",
|
|
35
|
+
"web": "./src/index.web.ts",
|
|
36
|
+
"native": "./src/index.ts",
|
|
37
|
+
"default": "./src/index.ts"
|
|
38
|
+
},
|
|
39
|
+
"./*": {
|
|
40
|
+
"types": "./types/generated/*.d.ts",
|
|
41
|
+
"default": "./src/*"
|
|
42
|
+
},
|
|
43
|
+
"./*.ts": {
|
|
44
|
+
"types": "./types/generated/*.d.ts",
|
|
45
|
+
"default": "./src/*.ts"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"typegen": "tsrx-typegen --target octane",
|
|
53
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
54
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
55
|
+
"test": "node --test tests/*.test.ts",
|
|
56
|
+
"typecheck": "node ../../scripts/typecheck.ts"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@nativescript-community/octane": "0.2.5",
|
|
60
|
+
"@nativescript/core": "9.1.3",
|
|
61
|
+
"@nativescript/types": "9.1.4",
|
|
62
|
+
"octane": "0.16.3",
|
|
63
|
+
"tsrx-typegen": "0.6.1",
|
|
64
|
+
"typescript": "7.1.0-beta",
|
|
65
|
+
"@tsrx/content-mapper": "0.1.2"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
69
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
70
|
+
"octane": ">=0.6.3 <1"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@nativescript-community/octane": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@nativescript/core": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"nativescript": {
|
|
81
|
+
"platforms": {
|
|
82
|
+
"android": "9.1.0",
|
|
83
|
+
"ios": "9.1.0"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"@nativescript/mlkit-barcode-scanning": "3.0.4",
|
|
88
|
+
"@nativescript/mlkit-core": "3.0.4",
|
|
89
|
+
"@octane-xplat/jsx": "0.20.0",
|
|
90
|
+
"@octane-xplat/platform": "0.20.0"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
+
// Live barcode scanner — AppKit stub. Still-image decoding works through
|
|
3
|
+
// barcodeScanner.scanImage (Vision); live camera scanning needs an
|
|
4
|
+
// AVCaptureVideoDataOutput frame path the camera leaf does not expose yet
|
|
5
|
+
// (decision #140). Renders nothing and reports once via onError.
|
|
6
|
+
import { useEffect } from 'octane'
|
|
7
|
+
import type { BarcodeScannerProps } from './props'
|
|
8
|
+
|
|
9
|
+
export function BarcodeScanner(props: BarcodeScannerProps): unknown @{
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
props.onError?.({ message: 'unsupported: live barcode scanning is not wired on macOS' })
|
|
12
|
+
}, [])
|
|
13
|
+
|
|
14
|
+
<masonview style={props.style} className={props.className} />
|
|
15
|
+
}
|
package/src/BarcodeScanner.tsrx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
|
|
3
3
|
import { isAndroid } from '@nativescript/core'
|
|
4
4
|
import { registerElement } from '@nativescript-community/octane'
|
|
@@ -9,94 +9,105 @@ import { fromNativeFormat, toNativeFormats } from './format-map'
|
|
|
9
9
|
registerElement('xplatbarcodescanner', MLKitView)
|
|
10
10
|
|
|
11
11
|
function applyEscapeProps(view: any, props: BarcodeScannerProps): void {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const bag = isAndroid ? props.android : props.ios
|
|
13
|
+
|
|
14
|
+
if (bag) {
|
|
15
|
+
Object.assign(view, bag)
|
|
16
|
+
}
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/** Live barcode/QR scanner — ML Kit's camera preview with `detectionType:
|
|
19
20
|
* barcode`. Decoding only; photo capture stays in @octane-xplat/camera. */
|
|
20
|
-
export function BarcodeScanner(props: BarcodeScannerProps) @{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
21
|
+
export function BarcodeScanner(props: BarcodeScannerProps): unknown @{
|
|
22
|
+
const host = useRef<MLKitView | null>(null)
|
|
23
|
+
|
|
24
|
+
const bindHost = useCallback((v: MLKitView | null) => {
|
|
25
|
+
host.current = v
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
useImperativeHandle(
|
|
29
|
+
props.ref,
|
|
30
|
+
(): BarcodeScannerHandle => ({
|
|
31
|
+
setPaused: (paused) => {
|
|
32
|
+
if (host.current) {
|
|
33
|
+
host.current.pause = paused
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
toggleCamera: () => host.current?.toggleCamera(),
|
|
37
|
+
native: host.current?.nativeViewProtected ?? host.current,
|
|
38
|
+
}),
|
|
39
|
+
[],
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
// Mount wiring — listeners before any prop assignment.
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const v = host.current
|
|
45
|
+
|
|
46
|
+
if (!v) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
v.detectionType = DetectionType.Barcode
|
|
51
|
+
v.on(MLKitView.detectionEvent, (e: any) => {
|
|
52
|
+
const data = e?.data ?? e?.data?.data ?? e
|
|
53
|
+
const list = Array.isArray(data) ? data : [data]
|
|
54
|
+
|
|
55
|
+
for (const item of list) {
|
|
56
|
+
if (!item) {
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const bounds = item.bounds
|
|
61
|
+
|
|
62
|
+
props.onCodeScanned?.({
|
|
63
|
+
type: fromNativeFormat(item.format),
|
|
64
|
+
data: String(item.rawValue ?? item.displayValue ?? ''),
|
|
65
|
+
bounds: bounds
|
|
66
|
+
? {
|
|
67
|
+
x: bounds.origin?.x ?? bounds.x ?? 0,
|
|
68
|
+
y: bounds.origin?.y ?? bounds.y ?? 0,
|
|
69
|
+
width: bounds.size?.width ?? bounds.width ?? 0,
|
|
70
|
+
height: bounds.size?.height ?? bounds.height ?? 0,
|
|
71
|
+
}
|
|
72
|
+
: undefined,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
applyEscapeProps(v, props)
|
|
78
|
+
}, [])
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const v = host.current
|
|
82
|
+
|
|
83
|
+
if (v) {
|
|
84
|
+
v.barcodeFormats = toNativeFormats(props.formats)
|
|
85
|
+
}
|
|
86
|
+
}, [JSON.stringify(props.formats)])
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const v = host.current
|
|
90
|
+
|
|
91
|
+
if (v) {
|
|
92
|
+
v.cameraPosition = props.facing === 'front' ? CameraPosition.FRONT : CameraPosition.BACK
|
|
93
|
+
}
|
|
94
|
+
}, [props.facing])
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const v = host.current
|
|
98
|
+
|
|
99
|
+
if (v) {
|
|
100
|
+
v.pause = props.paused ?? false
|
|
101
|
+
}
|
|
102
|
+
}, [props.paused])
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const v = host.current
|
|
106
|
+
|
|
107
|
+
if (v) {
|
|
108
|
+
v.torchOn = props.torch ?? false
|
|
109
|
+
}
|
|
110
|
+
}, [props.torch])
|
|
111
|
+
|
|
112
|
+
<xplatbarcodescanner ref={bindHost} style={props.style} className={props.className} />
|
|
102
113
|
}
|