@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 CHANGED
@@ -1,27 +1,5 @@
1
- # `@octane-xplat/barcode-scanner`
1
+ # @octane-xplat/barcode-scanner
2
2
 
3
- ```sh
4
- pnpm add @octane-xplat/barcode-scanner
5
- ```
3
+ [Documentation](https://octane-xplat.goddardai.org/package-barcode-scanner).
6
4
 
7
- Barcode and QR decoding — a live scanning view plus a headless still-image
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
- "name": "@octane-xplat/barcode-scanner",
3
- "version": "0.18.0",
4
- "description": "Barcode and QR scanning for Octane xplat — ML Kit camera preview + still decode on iOS/Android, 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
- "macos": {
34
- "types": "./types/generated/index.macos.d.ts",
35
- "default": "./src/index.macos.ts"
36
- },
37
- "web": {
38
- "types": "./types/generated/index.web.d.ts",
39
- "default": "./src/index.web.ts"
40
- },
41
- "native": {
42
- "types": "./types/generated/index.d.ts",
43
- "default": "./src/index.ts"
44
- },
45
- "types": "./types/generated/index.d.ts",
46
- "default": "./src/index.ts"
47
- },
48
- "./*": {
49
- "types": "./types/generated/*.d.ts",
50
- "default": "./src/*"
51
- },
52
- "./*.ts": {
53
- "types": "./types/generated/*.d.ts",
54
- "default": "./src/*.ts"
55
- }
56
- },
57
- "publishConfig": {
58
- "access": "public"
59
- },
60
- "devDependencies": {
61
- "@nativescript-community/octane": "0.2.5",
62
- "@nativescript/core": "9.1.3",
63
- "@nativescript/types": "9.1.4",
64
- "@tsrx/typescript-plugin": "0.4.11",
65
- "octane": "0.14.0",
66
- "tsrx-typegen": "0.4.0",
67
- "typescript": "5.9.3"
68
- },
69
- "peerDependencies": {
70
- "@nativescript-community/octane": ">=0.2.1 <1",
71
- "@nativescript/core": ">=9.1.0 <10",
72
- "octane": ">=0.6.3 <1"
73
- },
74
- "peerDependenciesMeta": {
75
- "@nativescript-community/octane": {
76
- "optional": true
77
- },
78
- "@nativescript/core": {
79
- "optional": true
80
- }
81
- },
82
- "nativescript": {
83
- "platforms": {
84
- "android": "9.1.0",
85
- "ios": "9.1.0"
86
- }
87
- },
88
- "dependencies": {
89
- "@nativescript/mlkit-barcode-scanning": "3.0.4",
90
- "@nativescript/mlkit-core": "3.0.4",
91
- "@octane-xplat/platform": "0.18.0"
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
+ }
@@ -1,4 +1,4 @@
1
- /** @jsxImportSource @nativescript-community/octane */
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
- const bag = isAndroid ? props.android : props.ios
13
- if (bag) {
14
- Object.assign(view, bag)
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
- const host = useRef<MLKitView | null>(null)
22
-
23
- const bindHost = useCallback((v: MLKitView | null) => {
24
- host.current = v
25
- }, [])
26
-
27
- useImperativeHandle(
28
- props.ref,
29
- (): BarcodeScannerHandle => ({
30
- setPaused: (paused) => {
31
- if (host.current) {
32
- host.current.pause = paused
33
- }
34
- },
35
- toggleCamera: () => host.current?.toggleCamera(),
36
- native: host.current?.nativeViewProtected ?? host.current,
37
- }),
38
- [],
39
- )
40
-
41
- // Mount wiring — listeners before any prop assignment.
42
- useEffect(() => {
43
- const v = host.current
44
- if (!v) {
45
- return
46
- }
47
- v.detectionType = DetectionType.Barcode
48
- v.on(MLKitView.detectionEvent, (e: any) => {
49
- const data = e?.data ?? e?.data?.data ?? e
50
- const list = Array.isArray(data) ? data : [data]
51
- for (const item of list) {
52
- if (!item) {
53
- continue
54
- }
55
- const bounds = item.bounds
56
- props.onCodeScanned?.({
57
- type: fromNativeFormat(item.format),
58
- data: String(item.rawValue ?? item.displayValue ?? ''),
59
- bounds: bounds
60
- ? {
61
- x: bounds.origin?.x ?? bounds.x ?? 0,
62
- y: bounds.origin?.y ?? bounds.y ?? 0,
63
- width: bounds.size?.width ?? bounds.width ?? 0,
64
- height: bounds.size?.height ?? bounds.height ?? 0,
65
- }
66
- : undefined,
67
- })
68
- }
69
- })
70
- applyEscapeProps(v, props)
71
- }, [])
72
-
73
- useEffect(() => {
74
- const v = host.current
75
- if (v) {
76
- v.barcodeFormats = toNativeFormats(props.formats)
77
- }
78
- }, [JSON.stringify(props.formats)])
79
-
80
- useEffect(() => {
81
- const v = host.current
82
- if (v) {
83
- v.cameraPosition = props.facing === 'front' ? CameraPosition.FRONT : CameraPosition.BACK
84
- }
85
- }, [props.facing])
86
-
87
- useEffect(() => {
88
- const v = host.current
89
- if (v) {
90
- v.pause = props.paused ?? false
91
- }
92
- }, [props.paused])
93
-
94
- useEffect(() => {
95
- const v = host.current
96
- if (v) {
97
- v.torchOn = props.torch ?? false
98
- }
99
- }, [props.torch])
100
-
101
- <xplatbarcodescanner ref={bindHost} style={props.style} className={props.className} />
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
  }