@octane-xplat/barcode-scanner 0.19.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 +2 -63
- package/package.json +6 -6
- package/src/BarcodeScanner.macos.tsrx +5 -6
- package/src/BarcodeScanner.tsrx +96 -88
- package/src/BarcodeScanner.web.tsrx +124 -117
- package/src/barcode-scanner.macos.ts +147 -107
- package/src/barcode-scanner.ts +114 -99
- package/src/barcode-scanner.web.ts +48 -39
- package/src/barcode-scanner.windows.ts +5 -4
- package/src/format-map.ts +16 -16
- package/src/format-map.web.ts +16 -16
- package/src/native-elements.d.ts +3 -3
- package/src/props.ts +31 -31
- package/src/types.ts +27 -27
- package/types/generated/.tsrx-typegen-manifest.json +0 -10
- package/types/generated/BarcodeScanner.macos.d.ts +0 -3
- package/types/generated/BarcodeScanner.web.d.ts +0 -6
- package/types/generated/barcode-scanner.linux.d.ts +0 -1
- package/types/generated/barcode-scanner.macos.d.ts +0 -3
- package/types/generated/barcode-scanner.web.d.ts +0 -3
- package/types/generated/barcode-scanner.windows.d.ts +0 -3
- package/types/generated/format-map.web.d.ts +0 -3
- package/types/generated/index.macos.d.ts +0 -4
- package/types/generated/index.web.d.ts +0 -4
- package/types/generated/native-elements.d.ts +0 -7
package/src/format-map.ts
CHANGED
|
@@ -3,29 +3,29 @@ import { BarcodeFormats } from '@nativescript/mlkit-core'
|
|
|
3
3
|
import type { BarcodeFormat } from './types'
|
|
4
4
|
|
|
5
5
|
const TO_MLKIT: Record<BarcodeFormat, BarcodeFormats> = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
qr: BarcodeFormats.QR_CODE,
|
|
7
|
+
ean13: BarcodeFormats.EAN_13,
|
|
8
|
+
ean8: BarcodeFormats.EAN_8,
|
|
9
|
+
upc_a: BarcodeFormats.UPC_A,
|
|
10
|
+
upc_e: BarcodeFormats.UPC_E,
|
|
11
|
+
code128: BarcodeFormats.CODE_128,
|
|
12
|
+
code39: BarcodeFormats.CODE_39,
|
|
13
|
+
code93: BarcodeFormats.CODE_93,
|
|
14
|
+
codabar: BarcodeFormats.CODABAR,
|
|
15
|
+
itf: BarcodeFormats.ITF,
|
|
16
|
+
datamatrix: BarcodeFormats.DATA_MATRIX,
|
|
17
|
+
pdf417: BarcodeFormats.PDF417,
|
|
18
|
+
aztec: BarcodeFormats.AZTEC,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const FROM_MLKIT: Record<string, string> = Object.fromEntries(
|
|
22
|
-
|
|
22
|
+
Object.entries(TO_MLKIT).map(([ours, theirs]) => [String(theirs), ours]),
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
export function toNativeFormats(formats?: BarcodeFormat[]): BarcodeFormats[] {
|
|
26
|
-
|
|
26
|
+
return formats?.length ? formats.map((f) => TO_MLKIT[f]) : [BarcodeFormats.ALL]
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function fromNativeFormat(format: unknown): string {
|
|
30
|
-
|
|
30
|
+
return FROM_MLKIT[String(format)] ?? String(format ?? 'unknown')
|
|
31
31
|
}
|
package/src/format-map.web.ts
CHANGED
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
import type { BarcodeFormat } from './types'
|
|
3
3
|
|
|
4
4
|
const TO_DETECTOR: Record<BarcodeFormat, string> = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
qr: 'qr_code',
|
|
6
|
+
ean13: 'ean_13',
|
|
7
|
+
ean8: 'ean_8',
|
|
8
|
+
upc_a: 'upc_a',
|
|
9
|
+
upc_e: 'upc_e',
|
|
10
|
+
code128: 'code_128',
|
|
11
|
+
code39: 'code_39',
|
|
12
|
+
code93: 'code_93',
|
|
13
|
+
codabar: 'codabar',
|
|
14
|
+
itf: 'itf',
|
|
15
|
+
datamatrix: 'data_matrix',
|
|
16
|
+
pdf417: 'pdf417',
|
|
17
|
+
aztec: 'aztec',
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const FROM_DETECTOR: Record<string, string> = Object.fromEntries(
|
|
21
|
-
|
|
21
|
+
Object.entries(TO_DETECTOR).map(([ours, theirs]) => [theirs, ours]),
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
export function toDetectorFormats(formats?: BarcodeFormat[]): string[] | undefined {
|
|
25
|
-
|
|
25
|
+
return formats?.length ? formats.map((f) => TO_DETECTOR[f]) : undefined
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function fromDetectorFormat(format: unknown): string {
|
|
29
|
-
|
|
29
|
+
return FROM_DETECTOR[String(format)] ?? String(format ?? 'unknown')
|
|
30
30
|
}
|
package/src/native-elements.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Attributes } from '@octane-xplat/jsx/intrinsics'
|
|
2
2
|
|
|
3
3
|
declare module '@octane-xplat/jsx/intrinsics' {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
interface NativeElements<TElement> {
|
|
5
|
+
xplatbarcodescanner: Attributes<TElement>
|
|
6
|
+
}
|
|
7
7
|
}
|
package/src/props.ts
CHANGED
|
@@ -3,41 +3,41 @@ import type { BarcodeFormat, ScannedCode } from './types'
|
|
|
3
3
|
|
|
4
4
|
/** Imperative handle exposed through the BarcodeScanner `ref`. */
|
|
5
5
|
export interface BarcodeScannerHandle {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/** Pause/resume preview processing (not the camera feed itself). */
|
|
7
|
+
setPaused(paused: boolean): void
|
|
8
|
+
/** Switch between the front and back cameras while scanning. */
|
|
9
|
+
toggleCamera(): void
|
|
10
|
+
/** The underlying MLKitView on native, the <video> element on web. */
|
|
11
|
+
native: unknown
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** Live barcode/QR scanning view — ML Kit on native, BarcodeDetector on web.
|
|
15
15
|
* Decoding only: photo capture stays in `@octane-xplat/camera`, gallery
|
|
16
16
|
* picking in `@octane-xplat/media`. */
|
|
17
17
|
export interface BarcodeScannerProps {
|
|
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
|
-
|
|
18
|
+
/** Class list applied to the preview element. */
|
|
19
|
+
className?: any
|
|
20
|
+
/** Inline style applied to the preview element (string CSS or object). */
|
|
21
|
+
style?: any
|
|
22
|
+
/** Restrict decoded symbologies — all supported formats by default. */
|
|
23
|
+
formats?: BarcodeFormat[]
|
|
24
|
+
/** Fires for each detected code (the OS may deliver batches). */
|
|
25
|
+
onCodeScanned?: (e: { type: string; data: string; bounds?: ScannedCode['bounds'] }) => void
|
|
26
|
+
/** Freeze detection; preview keeps running. Default false. */
|
|
27
|
+
paused?: boolean
|
|
28
|
+
/** Illuminate the camera torch while scanning. Default false. */
|
|
29
|
+
torch?: boolean
|
|
30
|
+
/** 'back' | 'front'. Default 'back'. */
|
|
31
|
+
facing?: 'back' | 'front'
|
|
32
|
+
/** Detector/preview failures (permission is requested separately via the
|
|
33
|
+
* `barcodeScanner` service, not surfaced here). */
|
|
34
|
+
onError?: (e: { message: string }) => void
|
|
35
|
+
/** Imperative handle — see BarcodeScannerHandle. */
|
|
36
|
+
ref?: Octane.Ref<BarcodeScannerHandle>
|
|
37
|
+
/** Platform escape hatches, applied after the shared props. */
|
|
38
|
+
ios?: Record<string, any>
|
|
39
|
+
/** Platform escape hatch — same bag contract as `ios`. */
|
|
40
|
+
android?: Record<string, any>
|
|
41
|
+
/** Platform escape hatch — same bag contract as `ios`. */
|
|
42
|
+
web?: Record<string, any>
|
|
43
43
|
}
|
package/src/types.ts
CHANGED
|
@@ -4,41 +4,41 @@ export type PermissionResult = 'granted' | 'denied' | 'unsupported'
|
|
|
4
4
|
/** Code symbologies — expo-camera spellings; each platform maps them onto
|
|
5
5
|
* its own detector vocabulary (ML Kit BarcodeFormats / BarcodeDetector). */
|
|
6
6
|
export type BarcodeFormat =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
| 'qr'
|
|
8
|
+
| 'ean13'
|
|
9
|
+
| 'ean8'
|
|
10
|
+
| 'upc_a'
|
|
11
|
+
| 'upc_e'
|
|
12
|
+
| 'code128'
|
|
13
|
+
| 'code39'
|
|
14
|
+
| 'code93'
|
|
15
|
+
| 'codabar'
|
|
16
|
+
| 'itf'
|
|
17
|
+
| 'datamatrix'
|
|
18
|
+
| 'pdf417'
|
|
19
|
+
| 'aztec'
|
|
20
20
|
|
|
21
21
|
/** One decoded barcode/QR value. */
|
|
22
22
|
export interface ScannedCode {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
/** The symbology, in our BarcodeFormat spelling. */
|
|
24
|
+
type: string
|
|
25
|
+
/** Decoded payload. */
|
|
26
|
+
data: string
|
|
27
|
+
/** Corner points / bounding rect where the detector reports it. */
|
|
28
|
+
bounds?: { x: number; y: number; width: number; height: number }
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Headless decode + permission service — the scanning view is
|
|
32
32
|
* `<BarcodeScanner>` from the same package. */
|
|
33
33
|
export interface BarcodeScannerService {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
/** Synchronous fast check — a detector backend exists on this platform. */
|
|
35
|
+
readonly supported: boolean
|
|
36
|
+
/** Ensure camera permission for live scanning. */
|
|
37
|
+
ensure(): Promise<PermissionResult>
|
|
38
|
+
/** Decode codes from a still image (platform image ref: a path or
|
|
39
|
+
* ImageSource on native, Blob/HTMLImageElement/data URL on web).
|
|
40
|
+
* Returns [] when the detector finds nothing. */
|
|
41
|
+
scanImage(image: unknown, formats?: BarcodeFormat[]): Promise<ScannedCode[]>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export declare const barcodeScanner: BarcodeScannerService
|
|
@@ -2,19 +2,9 @@
|
|
|
2
2
|
"version": 1,
|
|
3
3
|
"files": [
|
|
4
4
|
"BarcodeScanner.d.ts",
|
|
5
|
-
"BarcodeScanner.macos.d.ts",
|
|
6
|
-
"BarcodeScanner.web.d.ts",
|
|
7
5
|
"barcode-scanner.d.ts",
|
|
8
|
-
"barcode-scanner.linux.d.ts",
|
|
9
|
-
"barcode-scanner.macos.d.ts",
|
|
10
|
-
"barcode-scanner.web.d.ts",
|
|
11
|
-
"barcode-scanner.windows.d.ts",
|
|
12
6
|
"format-map.d.ts",
|
|
13
|
-
"format-map.web.d.ts",
|
|
14
7
|
"index.d.ts",
|
|
15
|
-
"index.macos.d.ts",
|
|
16
|
-
"index.web.d.ts",
|
|
17
|
-
"native-elements.d.ts",
|
|
18
8
|
"props.d.ts",
|
|
19
9
|
"types.d.ts"
|
|
20
10
|
]
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BarcodeScannerProps } from './props.js';
|
|
2
|
-
import type { JSX } from 'octane/jsx-runtime';
|
|
3
|
-
/** Live barcode/QR scanner — getUserMedia + the BarcodeDetector API
|
|
4
|
-
* (Chromium/Safari 18.4+; Firefox lacks the detector). Polling runs on
|
|
5
|
-
* requestVideoFrameCallback where available, else a 250ms interval. */
|
|
6
|
-
export declare function BarcodeScanner(props: BarcodeScannerProps): JSX.Element;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { barcodeScanner } from './barcode-scanner.web.js';
|