@scr2em/capacitor-scanner 6.0.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.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorScanner'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '13.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/Package.swift ADDED
@@ -0,0 +1,24 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapacitorScanner",
6
+ platforms: [.iOS(.v13)],
7
+ products: [
8
+ .library(
9
+ name: "CapacitorScanner",
10
+ targets: ["CapacitorScannerPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "CapacitorScannerPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/CapacitorScannerPlugin")
23
+ ]
24
+ )
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # Capacitor Scanner
2
+
3
+ scan codes
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install capacitor-scanner
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`startScanning(...)`](#startscanning)
17
+ * [`stopScanning()`](#stopscanning)
18
+ * [`openSettings()`](#opensettings)
19
+ * [`capturePhoto()`](#capturephoto)
20
+ * [`checkPermissions()`](#checkpermissions)
21
+ * [`requestPermissions()`](#requestpermissions)
22
+ * [`addListener('barcodeScanned', ...)`](#addlistenerbarcodescanned-)
23
+ * [`removeAllListeners()`](#removealllisteners)
24
+ * [Type Aliases](#type-aliases)
25
+ * [Enums](#enums)
26
+
27
+ </docgen-index>
28
+
29
+ <docgen-api>
30
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
31
+
32
+ ### startScanning(...)
33
+
34
+ ```typescript
35
+ startScanning(options?: ScannerOptions | undefined) => Promise<void>
36
+ ```
37
+
38
+ | Param | Type |
39
+ | ------------- | --------------------------------------------------------- |
40
+ | **`options`** | <code><a href="#scanneroptions">ScannerOptions</a></code> |
41
+
42
+ --------------------
43
+
44
+
45
+ ### stopScanning()
46
+
47
+ ```typescript
48
+ stopScanning() => Promise<void>
49
+ ```
50
+
51
+ --------------------
52
+
53
+
54
+ ### openSettings()
55
+
56
+ ```typescript
57
+ openSettings() => Promise<void>
58
+ ```
59
+
60
+ --------------------
61
+
62
+
63
+ ### capturePhoto()
64
+
65
+ ```typescript
66
+ capturePhoto() => Promise<CapturePhotoResult>
67
+ ```
68
+
69
+ **Returns:** <code>Promise&lt;<a href="#capturephotoresult">CapturePhotoResult</a>&gt;</code>
70
+
71
+ --------------------
72
+
73
+
74
+ ### checkPermissions()
75
+
76
+ ```typescript
77
+ checkPermissions() => Promise<PermissionsResult>
78
+ ```
79
+
80
+ **Returns:** <code>Promise&lt;<a href="#permissionsresult">PermissionsResult</a>&gt;</code>
81
+
82
+ --------------------
83
+
84
+
85
+ ### requestPermissions()
86
+
87
+ ```typescript
88
+ requestPermissions() => Promise<PermissionsResult>
89
+ ```
90
+
91
+ **Returns:** <code>Promise&lt;<a href="#permissionsresult">PermissionsResult</a>&gt;</code>
92
+
93
+ --------------------
94
+
95
+
96
+ ### addListener('barcodeScanned', ...)
97
+
98
+ ```typescript
99
+ addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void) => Promise<void>
100
+ ```
101
+
102
+ | Param | Type |
103
+ | ------------------ | ---------------------------------------------------------------------------------------- |
104
+ | **`event`** | <code>'barcodeScanned'</code> |
105
+ | **`listenerFunc`** | <code>(result: <a href="#barcodescannedevent">BarcodeScannedEvent</a>) =&gt; void</code> |
106
+
107
+ --------------------
108
+
109
+
110
+ ### removeAllListeners()
111
+
112
+ ```typescript
113
+ removeAllListeners() => Promise<void>
114
+ ```
115
+
116
+ --------------------
117
+
118
+
119
+ ### Type Aliases
120
+
121
+
122
+ #### ScannerOptions
123
+
124
+ <code>{ formats?: BarcodeFormat[]; cameraDirection?: 'BACK' | 'FRONT'; }</code>
125
+
126
+
127
+ #### CapturePhotoResult
128
+
129
+ <code>{ imageBase64: string }</code>
130
+
131
+
132
+ #### PermissionsResult
133
+
134
+ <code>{ camera: 'prompt' | 'denied' | 'granted' }</code>
135
+
136
+
137
+ #### BarcodeScannedEvent
138
+
139
+ <code>{ scannedCode: string; format: string }</code>
140
+
141
+
142
+ ### Enums
143
+
144
+
145
+ #### BarcodeFormat
146
+
147
+ | Members | Value |
148
+ | ---------------- | -------------------------- |
149
+ | **`Aztec`** | <code>'AZTEC'</code> |
150
+ | **`Code39`** | <code>'CODE_39'</code> |
151
+ | **`Code93`** | <code>'CODE_93'</code> |
152
+ | **`Code128`** | <code>'CODE_128'</code> |
153
+ | **`DataMatrix`** | <code>'DATA_MATRIX'</code> |
154
+ | **`Ean8`** | <code>'EAN_8'</code> |
155
+ | **`Ean13`** | <code>'EAN_13'</code> |
156
+ | **`Itf14`** | <code>'ITF14'</code> |
157
+ | **`Pdf417`** | <code>'PDF_417'</code> |
158
+ | **`QrCode`** | <code>'QR_CODE'</code> |
159
+ | **`UpcE`** | <code>'UPC_E'</code> |
160
+
161
+ </docgen-api>
@@ -0,0 +1,74 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "com.leadliaion.capacitorscanner"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_17
41
+ targetCompatibility JavaVersion.VERSION_17
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+
59
+ // CameraX dependencies
60
+ implementation "androidx.camera:camera-core:1.1.0"
61
+ implementation "androidx.camera:camera-camera2:1.1.0"
62
+ implementation "androidx.camera:camera-lifecycle:1.1.0"
63
+ implementation "androidx.camera:camera-view:1.1.0"
64
+
65
+ // ML Kit Barcode Scanning
66
+ implementation "com.google.mlkit:barcode-scanning:17.3.0"
67
+
68
+ // Other dependencies
69
+ implementation "androidx.lifecycle:lifecycle-common-java8:2.6.1"
70
+ implementation "com.google.guava:guava:31.1-android" // For ListenableFuture
71
+
72
+ // implementation 'com.google.zxing:core:3.5.3'
73
+ // implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
74
+ }
@@ -0,0 +1,5 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.CAMERA" />
3
+ <uses-feature android:name="android.hardware.camera" android:required="true" />
4
+
5
+ </manifest>
@@ -0,0 +1,40 @@
1
+ package com.leadliaion.capacitorscanner;
2
+
3
+ import com.google.mlkit.vision.barcode.common.Barcode;
4
+
5
+ public class BarcodeFormatHelper {
6
+
7
+ public static int stringToBarcodeFormat(String formatStr) {
8
+ return switch (formatStr) {
9
+ case "AZTEC" -> Barcode.FORMAT_AZTEC;
10
+ case "CODE_39" -> Barcode.FORMAT_CODE_39;
11
+ case "CODE_93" -> Barcode.FORMAT_CODE_93;
12
+ case "CODE_128" -> Barcode.FORMAT_CODE_128;
13
+ case "DATA_MATRIX" -> Barcode.FORMAT_DATA_MATRIX;
14
+ case "EAN_8" -> Barcode.FORMAT_EAN_8;
15
+ case "EAN_13" -> Barcode.FORMAT_EAN_13;
16
+ case "ITF14" -> Barcode.FORMAT_ITF;
17
+ case "PDF_417" -> Barcode.FORMAT_PDF417;
18
+ case "QR_CODE" -> Barcode.FORMAT_QR_CODE;
19
+ case "UPC_E" -> Barcode.FORMAT_UPC_E;
20
+ default -> -1;
21
+ };
22
+ }
23
+
24
+ public static String barcodeFormatToString(int format) {
25
+ return switch (format) {
26
+ case Barcode.FORMAT_AZTEC -> "AZTEC";
27
+ case Barcode.FORMAT_CODE_39 -> "CODE_39";
28
+ case Barcode.FORMAT_CODE_93 -> "CODE_93";
29
+ case Barcode.FORMAT_CODE_128 -> "CODE_128";
30
+ case Barcode.FORMAT_DATA_MATRIX -> "DATA_MATRIX";
31
+ case Barcode.FORMAT_EAN_8 -> "EAN_8";
32
+ case Barcode.FORMAT_EAN_13 -> "EAN_13";
33
+ case Barcode.FORMAT_ITF -> "ITF14";
34
+ case Barcode.FORMAT_PDF417 -> "PDF_417";
35
+ case Barcode.FORMAT_QR_CODE -> "QR_CODE";
36
+ case Barcode.FORMAT_UPC_E -> "UPC_E";
37
+ default -> "UNKNOWN";
38
+ };
39
+ }
40
+ }