@capacitor/barcode-scanner 2.2.1 → 2.2.2
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/CapacitorBarcodeScanner.podspec +1 -1
- package/Package.swift +2 -2
- package/README.md +2 -8
- package/android/build.gradle +19 -20
- package/dist/docs.json +3 -3
- package/dist/esm/definitions.d.ts +1 -8
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +10 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils.js +12 -15
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +35 -42
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +49 -62
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +49 -62
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorBarcodeScannerPlugin/CapacitorBarcodeScannerPlugin.swift +4 -4
- package/ios/Tests/CapacitorBarcodeScannerPluginTests/OSBarcodeTests.swift +9 -0
- package/package.json +20 -21
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.dependency 'OSBarcodeLib', '2.0.1'
|
|
17
17
|
s.swift_version = '5.1'
|
package/Package.swift
CHANGED
|
@@ -3,14 +3,14 @@ import PackageDescription
|
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
5
|
name: "CapacitorBarcodeScanner",
|
|
6
|
-
platforms: [.iOS(.
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
7
|
products: [
|
|
8
8
|
.library(
|
|
9
9
|
name: "CapacitorBarcodeScanner",
|
|
10
10
|
targets: ["CapacitorBarcodeScannerPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0"),
|
|
14
14
|
.package(url: "https://github.com/OutSystems/OSBarcodeLib-iOS.git", exact: "2.1.0")
|
|
15
15
|
],
|
|
16
16
|
targets: [
|
package/README.md
CHANGED
|
@@ -45,12 +45,6 @@ Note: iOS supports all formats except `MAXICODE` and `UPC_EAN_EXTENSION` - using
|
|
|
45
45
|
Interface defining the contract for a plugin capable of scanning barcodes.
|
|
46
46
|
Requires implementation of the scanBarcode method, which initiates a barcode scan with given options.
|
|
47
47
|
|
|
48
|
-
Starting in Android targetSdk 36, the scanOrientation parameter has no effect for large screens (e.g. tablets) on Android 16 and higher.
|
|
49
|
-
You may opt-out of this behavior in your app by adding `<property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />` to your `AndroidManifest.xml` inside `<application>` or `<activity>`.
|
|
50
|
-
Keep in mind though that this opt-out is temporary and will no longer work for Android 17. Android discourages setting specific orientations for large screens.
|
|
51
|
-
Regular Android phones are unaffected by this change.
|
|
52
|
-
For more information check the Android docs at https://developer.android.com/about/versions/16/behavior-changes-16#adaptive-layouts
|
|
53
|
-
|
|
54
48
|
### scanBarcode(...)
|
|
55
49
|
|
|
56
50
|
```typescript
|
|
@@ -147,7 +141,7 @@ Defines the options for configuring a barcode scan.
|
|
|
147
141
|
|
|
148
142
|
| Members | Value |
|
|
149
143
|
| ----------- | -------------------- |
|
|
150
|
-
| **`ZXING`** | <code>
|
|
151
|
-
| **`MLKIT`** | <code>
|
|
144
|
+
| **`ZXING`** | <code>'zxing'</code> |
|
|
145
|
+
| **`MLKIT`** | <code>'mlkit'</code> |
|
|
152
146
|
|
|
153
147
|
</docgen-api>
|
package/android/build.gradle
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
6
|
-
kotlinxCoroutinesVersion = project.hasProperty('kotlinxCoroutinesVersion') ? rootProject.ext.kotlinxCoroutinesVersion : '1.10.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
buildscript {
|
|
10
|
-
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '
|
|
9
|
+
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.24'
|
|
11
10
|
repositories {
|
|
12
11
|
google()
|
|
13
12
|
mavenCentral()
|
|
@@ -16,7 +15,7 @@ buildscript {
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
dependencies {
|
|
19
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
18
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
20
19
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
21
20
|
}
|
|
22
21
|
}
|
|
@@ -25,11 +24,11 @@ apply plugin: 'com.android.library'
|
|
|
25
24
|
apply plugin: 'kotlin-android'
|
|
26
25
|
|
|
27
26
|
android {
|
|
28
|
-
namespace
|
|
29
|
-
compileSdk
|
|
27
|
+
namespace "com.capacitorjs.barcodescanner"
|
|
28
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
30
29
|
defaultConfig {
|
|
31
30
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 26
|
|
32
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
31
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
33
32
|
versionCode 1
|
|
34
33
|
versionName "1.0"
|
|
35
34
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -41,7 +40,7 @@ android {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
lintOptions {
|
|
44
|
-
abortOnError
|
|
43
|
+
abortOnError false
|
|
45
44
|
}
|
|
46
45
|
compileOptions {
|
|
47
46
|
sourceCompatibility JavaVersion.VERSION_21
|
|
@@ -62,17 +61,17 @@ dependencies {
|
|
|
62
61
|
implementation "io.ionic.libs:ionbarcode-android:2.0.1@aar"
|
|
63
62
|
implementation project(':capacitor-android')
|
|
64
63
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
65
|
-
implementation 'androidx.activity:activity-ktx:1.
|
|
66
|
-
implementation
|
|
67
|
-
implementation
|
|
68
|
-
implementation 'com.google.zxing:core:3.
|
|
64
|
+
implementation 'androidx.activity:activity-ktx:1.9.3'
|
|
65
|
+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3'
|
|
66
|
+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
|
67
|
+
implementation 'com.google.zxing:core:3.4.1'
|
|
69
68
|
implementation 'com.google.mlkit:barcode-scanning:17.3.0'
|
|
70
|
-
implementation 'androidx.camera:camera-camera2:1.
|
|
71
|
-
implementation 'androidx.camera:camera-lifecycle:1.
|
|
72
|
-
implementation 'androidx.camera:camera-view:1.
|
|
73
|
-
implementation 'androidx.activity:activity-compose:1.
|
|
74
|
-
implementation 'androidx.compose.material3:material3:1.
|
|
75
|
-
implementation 'androidx.compose.material3:material3-window-size-class:1.
|
|
69
|
+
implementation 'androidx.camera:camera-camera2:1.4.0'
|
|
70
|
+
implementation 'androidx.camera:camera-lifecycle:1.4.0'
|
|
71
|
+
implementation 'androidx.camera:camera-view:1.4.0'
|
|
72
|
+
implementation 'androidx.activity:activity-compose:1.9.3'
|
|
73
|
+
implementation 'androidx.compose.material3:material3:1.3.1'
|
|
74
|
+
implementation 'androidx.compose.material3:material3-window-size-class:1.3.1'
|
|
76
75
|
testImplementation "junit:junit:$junitVersion"
|
|
77
76
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
78
77
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
package/dist/docs.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"api": {
|
|
3
3
|
"name": "CapacitorBarcodeScannerPlugin",
|
|
4
4
|
"slug": "capacitorbarcodescannerplugin",
|
|
5
|
-
"docs": "Interface defining the contract for a plugin capable of scanning barcodes.\nRequires implementation of the scanBarcode method, which initiates a barcode scan with given options
|
|
5
|
+
"docs": "Interface defining the contract for a plugin capable of scanning barcodes.\nRequires implementation of the scanBarcode method, which initiates a barcode scan with given options.",
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
@@ -197,13 +197,13 @@
|
|
|
197
197
|
"members": [
|
|
198
198
|
{
|
|
199
199
|
"name": "ZXING",
|
|
200
|
-
"value": "
|
|
200
|
+
"value": "'zxing'",
|
|
201
201
|
"tags": [],
|
|
202
202
|
"docs": ""
|
|
203
203
|
},
|
|
204
204
|
{
|
|
205
205
|
"name": "MLKIT",
|
|
206
|
-
"value": "
|
|
206
|
+
"value": "'mlkit'",
|
|
207
207
|
"tags": [],
|
|
208
208
|
"docs": ""
|
|
209
209
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Html5QrcodeSupportedFormats } from
|
|
1
|
+
import { Html5QrcodeSupportedFormats } from 'html5-qrcode';
|
|
2
2
|
/**
|
|
3
3
|
* Enum representing the direction of the camera to be used for barcode scanning.
|
|
4
4
|
*/
|
|
@@ -85,13 +85,6 @@ export type CapacitorBarcodeScannerOptions = {
|
|
|
85
85
|
/**
|
|
86
86
|
* Interface defining the contract for a plugin capable of scanning barcodes.
|
|
87
87
|
* Requires implementation of the scanBarcode method, which initiates a barcode scan with given options.
|
|
88
|
-
*
|
|
89
|
-
* Starting in Android targetSdk 36, the scanOrientation parameter has no effect for large screens (e.g. tablets) on Android 16 and higher.
|
|
90
|
-
* You may opt-out of this behavior in your app by adding `<property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />` to your `AndroidManifest.xml` inside `<application>` or `<activity>`.
|
|
91
|
-
* Keep in mind though that this opt-out is temporary and will no longer work for Android 17. Android discourages setting specific orientations for large screens.
|
|
92
|
-
* Regular Android phones are unaffected by this change.
|
|
93
|
-
* For more information check the Android docs at https://developer.android.com/about/versions/16/behavior-changes-16#adaptive-layouts
|
|
94
|
-
*
|
|
95
88
|
*/
|
|
96
89
|
export interface CapacitorBarcodeScannerPlugin {
|
|
97
90
|
scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult>;
|
package/dist/esm/definitions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D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Y,6CAGX;AAHD,WAAY,6CAA6C;IACvD,gEAAe,CAAA;IACf,gEAAe,CAAA;AACjB,CAAC,EAHW,6CAA6C,KAA7C,6CAA6C,QAGxD","sourcesContent":["import { Html5QrcodeSupportedFormats } from 'html5-qrcode';\n\n/**\n * Enum representing the direction of the camera to be used for barcode scanning.\n */\nexport enum CapacitorBarcodeScannerCameraDirection {\n BACK = 1,\n FRONT = 2,\n}\n\n/**\n * Enum representing the orientation of the scanner during barcode scanning.\n */\nexport enum CapacitorBarcodeScannerScanOrientation {\n PORTRAIT = 1,\n LANDSCAPE = 2,\n ADAPTIVE = 3,\n}\n\n/**\n * Enum representing a special option to indicate that all barcode types are supported.\n */\nexport enum CapacitorBarcodeScannerTypeHintALLOption {\n ALL = 17,\n}\n\n/**\n * Extends supported formats from Html5Qrcode with a special 'ALL' option,\n * indicating support for all barcode types.\n */\nexport const CapacitorBarcodeScannerTypeHint = {\n ...Html5QrcodeSupportedFormats,\n ...CapacitorBarcodeScannerTypeHintALLOption,\n};\n\n/**\n * Type definition combining Html5QrcodeSupportedFormats and OSBarcodeTypeHintALLOption\n * to represent the hint for the type of barcode to be scanned.\n */\nexport type CapacitorBarcodeScannerTypeHint = Html5QrcodeSupportedFormats | CapacitorBarcodeScannerTypeHintALLOption;\n\n/**\n * Enum representing the library to be used for barcode scanning on Android devices.\n */\nexport enum CapacitorBarcodeScannerAndroidScanningLibrary {\n ZXING = 'zxing',\n MLKIT = 'mlkit',\n}\n\n/**\n * Defines the structure of the result returned from a barcode scan.\n */\nexport type CapacitorBarcodeScannerScanResult = {\n ScanResult: string;\n format: CapacitorBarcodeScannerTypeHint;\n};\n\n/**\n * Defines the options for configuring a barcode scan.\n */\nexport type CapacitorBarcodeScannerOptions = {\n hint: CapacitorBarcodeScannerTypeHint;\n scanInstructions?: string;\n scanButton?: boolean;\n scanText?: string;\n cameraDirection?: CapacitorBarcodeScannerCameraDirection;\n scanOrientation?: CapacitorBarcodeScannerScanOrientation;\n android?: {\n scanningLibrary?: CapacitorBarcodeScannerAndroidScanningLibrary;\n };\n web?: {\n showCameraSelection?: boolean;\n scannerFPS?: number;\n };\n};\n\n/**\n * Interface defining the contract for a plugin capable of scanning barcodes.\n * Requires implementation of the scanBarcode method, which initiates a barcode scan with given options.\n */\nexport interface CapacitorBarcodeScannerPlugin {\n scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult>;\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type CapacitorBarcodeScannerOptions, type CapacitorBarcodeScannerScanResult } from
|
|
1
|
+
import { type CapacitorBarcodeScannerOptions, type CapacitorBarcodeScannerScanResult } from './definitions';
|
|
2
2
|
declare class CapacitorBarcodeScanner {
|
|
3
3
|
static scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult>;
|
|
4
4
|
}
|
|
5
5
|
export { CapacitorBarcodeScanner };
|
|
6
|
-
export * from
|
|
6
|
+
export * from './definitions';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import { registerPlugin } from
|
|
2
|
-
import { CapacitorBarcodeScannerCameraDirection, CapacitorBarcodeScannerScanOrientation, } from
|
|
3
|
-
import { applyCss, barcodeScannerCss } from
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
import { CapacitorBarcodeScannerCameraDirection, CapacitorBarcodeScannerScanOrientation, } from './definitions'; // Importing the interface for type checking.
|
|
3
|
+
import { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.
|
|
4
4
|
/**
|
|
5
5
|
* Registers the `OSBarcode` plugin with Capacitor.
|
|
6
6
|
* For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
|
|
7
7
|
* This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
|
|
8
8
|
*/
|
|
9
|
-
const CapacitorBarcodeScannerImpl = registerPlugin(
|
|
9
|
+
const CapacitorBarcodeScannerImpl = registerPlugin('CapacitorBarcodeScanner', {
|
|
10
10
|
web: () => {
|
|
11
11
|
applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.
|
|
12
|
-
return import(
|
|
12
|
+
return import('./web').then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
15
|
class CapacitorBarcodeScanner {
|
|
16
16
|
static async scanBarcode(options) {
|
|
17
|
-
options.scanInstructions = options.scanInstructions ||
|
|
17
|
+
options.scanInstructions = options.scanInstructions || ' '; // Ensure scanInstructions is at least a space.
|
|
18
18
|
options.scanButton = options.scanButton || false; // Set scanButton to false if not provided.
|
|
19
|
-
options.scanText = options.scanText ||
|
|
20
|
-
options.cameraDirection =
|
|
21
|
-
|
|
22
|
-
options.scanOrientation =
|
|
23
|
-
options.scanOrientation ||
|
|
24
|
-
CapacitorBarcodeScannerScanOrientation.ADAPTIVE; // Set scanOrientation to 'ADAPTIVE' if not provided.
|
|
19
|
+
options.scanText = options.scanText || ' '; // Ensure scanText is at least a space.
|
|
20
|
+
options.cameraDirection = options.cameraDirection || CapacitorBarcodeScannerCameraDirection.BACK; // Set cameraDirection to 'BACK' if not provided.
|
|
21
|
+
options.scanOrientation = options.scanOrientation || CapacitorBarcodeScannerScanOrientation.ADAPTIVE; // Set scanOrientation to 'ADAPTIVE' if not provided.
|
|
25
22
|
return CapacitorBarcodeScannerImpl.scanBarcode(options);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
export { CapacitorBarcodeScanner }; // Export the `CapacitorBarcodeScanner` class.
|
|
29
|
-
export * from
|
|
26
|
+
export * from './definitions'; // Re-export all exports from the definitions file.
|
|
30
27
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"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I,sCAAsC,CAAC,IAAI,CAAC,CAAC,iDAAiD;QACnJ,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,sCAAsC,CAAC,QAAQ,CAAC,CAAC,qDAAqD;QAC3J,OAAO,2BAA2B,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC,8CAA8C;AAClF,cAAc,eAAe,CAAC,CAAC,mDAAmD","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport {\n CapacitorBarcodeScannerCameraDirection,\n CapacitorBarcodeScannerScanOrientation,\n type CapacitorBarcodeScannerOptions,\n type CapacitorBarcodeScannerPlugin,\n type CapacitorBarcodeScannerScanResult,\n} from './definitions'; // Importing the interface for type checking.\nimport { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.\n\n/**\n * Registers the `OSBarcode` plugin with Capacitor.\n * For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.\n * This allows for lazy loading of the web code only when needed, optimizing overall bundle size.\n */\nconst CapacitorBarcodeScannerImpl = registerPlugin<CapacitorBarcodeScannerPlugin>('CapacitorBarcodeScanner', {\n web: () => {\n applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.\n return import('./web').then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.\n },\n});\n\nclass CapacitorBarcodeScanner {\n public static async scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult> {\n options.scanInstructions = options.scanInstructions || ' '; // Ensure scanInstructions is at least a space.\n options.scanButton = options.scanButton || false; // Set scanButton to false if not provided.\n options.scanText = options.scanText || ' '; // Ensure scanText is at least a space.\n options.cameraDirection = options.cameraDirection || CapacitorBarcodeScannerCameraDirection.BACK; // Set cameraDirection to 'BACK' if not provided.\n options.scanOrientation = options.scanOrientation || CapacitorBarcodeScannerScanOrientation.ADAPTIVE; // Set scanOrientation to 'ADAPTIVE' if not provided.\n return CapacitorBarcodeScannerImpl.scanBarcode(options);\n }\n}\n\nexport { CapacitorBarcodeScanner }; // Export the `CapacitorBarcodeScanner` class.\nexport * from './definitions'; // Re-export all exports from the definitions file.\n"]}
|
package/dist/esm/utils.js
CHANGED
|
@@ -3,21 +3,18 @@
|
|
|
3
3
|
* Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.
|
|
4
4
|
*/
|
|
5
5
|
export const barcodeScannerCss = [
|
|
6
|
-
{ selector:
|
|
6
|
+
{ selector: '.scanner-container-display', css: 'display: block;' },
|
|
7
7
|
{
|
|
8
|
-
selector:
|
|
9
|
-
css:
|
|
8
|
+
selector: '.scanner-dialog',
|
|
9
|
+
css: 'display: none; position: fixed; z-index: 999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4);',
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
|
-
selector:
|
|
13
|
-
css:
|
|
12
|
+
selector: '.scanner-dialog-inner',
|
|
13
|
+
css: 'background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;',
|
|
14
14
|
},
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
{ selector: ".close-button:hover", css: "color: #222;" },
|
|
20
|
-
{ selector: ".scanner-container-full-width", css: "width: 100%;" },
|
|
15
|
+
{ selector: '.close-button', css: 'color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;' },
|
|
16
|
+
{ selector: '.close-button:hover', css: 'color: #222;' },
|
|
17
|
+
{ selector: '.scanner-container-full-width', css: 'width: 100%;' },
|
|
21
18
|
];
|
|
22
19
|
/**
|
|
23
20
|
* Dynamically applies a set of CSS rules to the document.
|
|
@@ -28,12 +25,12 @@ export const barcodeScannerCss = [
|
|
|
28
25
|
* @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.
|
|
29
26
|
*/
|
|
30
27
|
export function applyCss(cssRules) {
|
|
31
|
-
const styleId =
|
|
28
|
+
const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.
|
|
32
29
|
let styleElement = document.getElementById(styleId);
|
|
33
30
|
if (!styleElement) {
|
|
34
31
|
// Create and append a new style element if it does not exist.
|
|
35
|
-
styleElement = document.createElement(
|
|
36
|
-
styleElement.type =
|
|
32
|
+
styleElement = document.createElement('style');
|
|
33
|
+
styleElement.type = 'text/css';
|
|
37
34
|
styleElement.id = styleId;
|
|
38
35
|
document.head.appendChild(styleElement);
|
|
39
36
|
}
|
|
@@ -49,7 +46,7 @@ export function applyCss(cssRules) {
|
|
|
49
46
|
}
|
|
50
47
|
else {
|
|
51
48
|
// Fallback for older browsers using textContent.
|
|
52
|
-
styleElement.textContent =
|
|
49
|
+
styleElement.textContent = '';
|
|
53
50
|
for (const { selector, css } of cssRules) {
|
|
54
51
|
styleElement.textContent += `${selector} { ${css} }`;
|
|
55
52
|
}
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,EAAE,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,iBAAiB,EAAE;IAClE;QACE,QAAQ,EAAE,iBAAiB;QAC3B,GAAG,EAAE,8IAA8I;KACpJ;IACD;QACE,QAAQ,EAAE,uBAAuB;QACjC,GAAG,EAAE,gGAAgG;KACtG;IACD
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,EAAE,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,iBAAiB,EAAE;IAClE;QACE,QAAQ,EAAE,iBAAiB;QAC3B,GAAG,EAAE,8IAA8I;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AG,EAAE,IAAI,QAAQ,EAAE,CAAC;YACzC,YAAY,CAAC,WAAW,IAAI,GAAG,QAAQ,MAAM,GAAG,IAAI,CAAC;QACvD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Predefined CSS rules for styling barcode scanner components.\n * Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.\n */\nexport const barcodeScannerCss = [\n { selector: '.scanner-container-display', css: 'display: block;' },\n {\n selector: '.scanner-dialog',\n css: 'display: none; position: fixed; z-index: 999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4);',\n },\n {\n selector: '.scanner-dialog-inner',\n css: 'background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;',\n },\n { selector: '.close-button', css: 'color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;' },\n { selector: '.close-button:hover', css: 'color: #222;' },\n { selector: '.scanner-container-full-width', css: 'width: 100%;' },\n];\n\n/**\n * Dynamically applies a set of CSS rules to the document.\n * If a custom style element with a specific ID does not exist, it is created and appended to the document's head.\n * Existing rules in the style element are cleared before new ones are applied.\n * This function supports both modern and older browsers by using `CSSStyleSheet.insertRule` and `textContent` respectively.\n *\n * @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.\n */\nexport function applyCss(cssRules: { selector: string; css: string }[]): void {\n const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.\n let styleElement = document.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleElement) {\n // Create and append a new style element if it does not exist.\n styleElement = document.createElement('style');\n styleElement.type = 'text/css';\n styleElement.id = styleId;\n document.head.appendChild(styleElement);\n }\n if (styleElement.sheet) {\n // Clear existing CSS rules.\n while (styleElement.sheet.cssRules.length) {\n styleElement.sheet.deleteRule(0);\n }\n // Insert new CSS rules.\n for (const { selector, css } of cssRules) {\n styleElement.sheet.insertRule(`${selector} { ${css} }`);\n }\n } else {\n // Fallback for older browsers using textContent.\n styleElement.textContent = '';\n for (const { selector, css } of cssRules) {\n styleElement.textContent += `${selector} { ${css} }`;\n }\n }\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebPlugin } from
|
|
2
|
-
import type { CapacitorBarcodeScannerPlugin, CapacitorBarcodeScannerOptions, CapacitorBarcodeScannerScanResult } from
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorBarcodeScannerPlugin, CapacitorBarcodeScannerOptions, CapacitorBarcodeScannerScanResult } from './definitions';
|
|
3
3
|
/**
|
|
4
4
|
* Implements OSBarcodePlugin to provide web functionality for barcode scanning.
|
|
5
5
|
*/
|
package/dist/esm/web.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerTypeHint, } from "./definitions";
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import { Html5Qrcode } from 'html5-qrcode';
|
|
3
|
+
import { CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerTypeHint } from './definitions';
|
|
5
4
|
/**
|
|
6
5
|
* Implements OSBarcodePlugin to provide web functionality for barcode scanning.
|
|
7
6
|
*/
|
|
@@ -17,7 +16,8 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
|
17
16
|
await window.OSBarcodeWebScanner.stop();
|
|
18
17
|
window.OSBarcodeWebScanner = null;
|
|
19
18
|
}
|
|
20
|
-
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
|
+
document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'none';
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Builds the HTML elements necessary for the barcode scanner UI.
|
|
@@ -26,38 +26,34 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
28
|
buildScannerElement() {
|
|
29
|
-
if (document.getElementById(
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (document.getElementById('cap-os-barcode-scanner-container')) {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
+
document.getElementById('cap-os-barcode-scanner-container').className = 'scanner-container-display';
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
// Create and configure scanner container elements
|
|
35
|
-
const caposbarcodescannercontainer = document.body.appendChild(document.createElement(
|
|
36
|
-
caposbarcodescannercontainer.id =
|
|
37
|
-
const caposbarcodescannercontainerdialog = document.createElement(
|
|
38
|
-
caposbarcodescannercontainerdialog.id =
|
|
39
|
-
|
|
40
|
-
caposbarcodescannercontainerdialog.className = "scanner-dialog";
|
|
35
|
+
const caposbarcodescannercontainer = document.body.appendChild(document.createElement('div'));
|
|
36
|
+
caposbarcodescannercontainer.id = 'cap-os-barcode-scanner-container';
|
|
37
|
+
const caposbarcodescannercontainerdialog = document.createElement('div');
|
|
38
|
+
caposbarcodescannercontainerdialog.id = 'cap-os-barcode-scanner-container-dialog';
|
|
39
|
+
caposbarcodescannercontainerdialog.className = 'scanner-dialog';
|
|
41
40
|
// Inner dialog elements including the close button and scanner view
|
|
42
|
-
const caposbarcodescannercontainerdialoginner = document.createElement(
|
|
43
|
-
caposbarcodescannercontainerdialoginner.className =
|
|
44
|
-
const caposbarcodescannercontainerdialoginnerclose = document.createElement(
|
|
45
|
-
caposbarcodescannercontainerdialoginnerclose.className =
|
|
46
|
-
caposbarcodescannercontainerdialoginnerclose.innerHTML =
|
|
41
|
+
const caposbarcodescannercontainerdialoginner = document.createElement('div');
|
|
42
|
+
caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';
|
|
43
|
+
const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');
|
|
44
|
+
caposbarcodescannercontainerdialoginnerclose.className = 'close-button';
|
|
45
|
+
caposbarcodescannercontainerdialoginnerclose.innerHTML = '×';
|
|
47
46
|
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);
|
|
48
|
-
const caposbarcodescannercontainerdialoginnercontainerp = document.createElement(
|
|
49
|
-
caposbarcodescannercontainerdialoginnercontainerp.innerHTML =
|
|
47
|
+
const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');
|
|
48
|
+
caposbarcodescannercontainerdialoginnercontainerp.innerHTML = ' ';
|
|
50
49
|
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);
|
|
51
|
-
const caposbarcodescannercontainerdialoginnercontainer = document.createElement(
|
|
52
|
-
caposbarcodescannercontainerdialoginnercontainer.className =
|
|
53
|
-
|
|
54
|
-
caposbarcodescannercontainerdialoginnercontainer.id =
|
|
55
|
-
"cap-os-barcode-scanner-container-scanner";
|
|
50
|
+
const caposbarcodescannercontainerdialoginnercontainer = document.createElement('div');
|
|
51
|
+
caposbarcodescannercontainerdialoginnercontainer.className = 'scanner-container-full-width';
|
|
52
|
+
caposbarcodescannercontainerdialoginnercontainer.id = 'cap-os-barcode-scanner-container-scanner';
|
|
56
53
|
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainer);
|
|
57
54
|
caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);
|
|
58
55
|
caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);
|
|
59
|
-
caposbarcodescannercontainerdialoginnerclose.onclick =
|
|
60
|
-
this.stopAndHideScanner;
|
|
56
|
+
caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;
|
|
61
57
|
}
|
|
62
58
|
/**
|
|
63
59
|
* Initiates a barcode scan using the user's camera and HTML5 QR code scanner.
|
|
@@ -67,30 +63,27 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
|
67
63
|
*/
|
|
68
64
|
async scanBarcode(options) {
|
|
69
65
|
this.buildScannerElement();
|
|
70
|
-
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
+
document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'block';
|
|
71
68
|
return new Promise((resolve, reject) => {
|
|
72
69
|
var _a, _b;
|
|
73
70
|
const param = {
|
|
74
|
-
facingMode: options.cameraDirection === 1 ?
|
|
71
|
+
facingMode: options.cameraDirection === 1 ? 'environment' : 'user',
|
|
75
72
|
hasScannerButton: false,
|
|
76
73
|
scanButton: options.scanButton === undefined ? false : options.scanButton,
|
|
77
74
|
showScanLine: false,
|
|
78
|
-
scanInstructions: options.scanInstructions
|
|
79
|
-
? options.scanInstructions
|
|
80
|
-
: "",
|
|
75
|
+
scanInstructions: options.scanInstructions ? options.scanInstructions : '',
|
|
81
76
|
orientation: options.scanOrientation
|
|
82
77
|
? options.scanOrientation
|
|
83
78
|
: CapacitorBarcodeScannerScanOrientation.PORTRAIT,
|
|
84
|
-
showCameraSelection: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection)
|
|
85
|
-
? options.web.showCameraSelection
|
|
86
|
-
: false,
|
|
79
|
+
showCameraSelection: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,
|
|
87
80
|
typeHint: options.hint === 17 ? undefined : options.hint,
|
|
88
81
|
scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,
|
|
89
82
|
};
|
|
90
83
|
// Set up and start the scanner
|
|
91
|
-
const scannerElement = document.getElementById(
|
|
84
|
+
const scannerElement = document.getElementById('cap-os-barcode-scanner-container-scanner');
|
|
92
85
|
if (!scannerElement) {
|
|
93
|
-
throw new Error(
|
|
86
|
+
throw new Error('Scanner Element is required for web');
|
|
94
87
|
}
|
|
95
88
|
window.OSBarcodeWebScanner = new Html5Qrcode(scannerElement.id, {
|
|
96
89
|
formatsToSupport: param.typeHint !== undefined ? [param.typeHint] : undefined,
|
|
@@ -101,7 +94,7 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
|
101
94
|
qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,
|
|
102
95
|
aspectRatio: 16 / 9,
|
|
103
96
|
videoConstraints: {
|
|
104
|
-
focusMode:
|
|
97
|
+
focusMode: 'continuous',
|
|
105
98
|
height: { min: 576, ideal: 1920 },
|
|
106
99
|
deviceId: undefined,
|
|
107
100
|
facingMode: param.facingMode,
|
|
@@ -118,9 +111,9 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
|
118
111
|
};
|
|
119
112
|
const OSBarcodeWebScannerErrorCallback = (error) => {
|
|
120
113
|
const allowedErrors = [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
'NotFoundException',
|
|
115
|
+
'No barcode or QR code detected',
|
|
116
|
+
'No MultiFormat Readers were able to detect the code',
|
|
124
117
|
];
|
|
125
118
|
if (!allowedErrors.find((e) => error.indexOf(e) !== -1)) {
|
|
126
119
|
this.stopAndHideScanner();
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,OAAO,EACL,sCAAsC,EACtC,+BAA+B,GAChC,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,OAAO,0BACX,SAAQ,SAAS;IAGjB;;;;OAIG;IACK,KAAK,CAAC,kBAAkB;QAC9B,OAAO,CAAC,GAAG,CAAE,MAAc,CAAC,mBAAmB,CAAC,CAAC;QACjD,IAAK,MAAc,CAAC,mBAAmB,EAAE,CAAC;YACxC,MAAO,MAAc,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;YAChD,MAAc,C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EAAE,CAAC;gBAC1B,OAAO,CAAC;oBACN,UAAU,EAAE,WAAW;oBACvB,MAAM,EACJ,MAAA,MAAA,aAAa,CAAC,MAAM,CAAC,MAAM,0CAAE,MAAM,mCACnC,+BAA+B,CAAC,GAAG;iBACtC,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,MAAM,gCAAgC,GAAG,CAAC,KAAa,EAAE,EAAE;gBACzD,MAAM,aAAa,GAAG;oBACpB,mBAAmB;oBACnB,gCAAgC;oBAChC,qDAAqD;iBACtD,CAAC;gBAEF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBACxD,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;oBAC9C,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC;YAED,MAAc,CAAC,mBAAmB,CAAC,KAAK,CACvC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAChC,iBAAiB,EACjB,kCAAkC,EAClC,gCAAgC,CACjC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/* eslint-env browser */\nimport { WebPlugin } from \"@capacitor/core\";\nimport type { Html5QrcodeResult } from \"html5-qrcode\";\nimport { Html5Qrcode } from \"html5-qrcode\";\n\nimport type {\n CapacitorBarcodeScannerPlugin,\n CapacitorBarcodeScannerOptions,\n CapacitorBarcodeScannerScanResult,\n} from \"./definitions\";\nimport {\n CapacitorBarcodeScannerScanOrientation,\n CapacitorBarcodeScannerTypeHint,\n} from \"./definitions\";\n\n/**\n * Implements OSBarcodePlugin to provide web functionality for barcode scanning.\n */\nexport class CapacitorBarcodeScannerWeb\n extends WebPlugin\n implements CapacitorBarcodeScannerPlugin\n{\n /**\n * Stops the barcode scanner and hides its UI.\n * @private\n * @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.\n */\n private async stopAndHideScanner(): Promise<void> {\n console.log((window as any).OSBarcodeWebScanner);\n if ((window as any).OSBarcodeWebScanner) {\n await (window as any).OSBarcodeWebScanner.stop();\n (window as any).OSBarcodeWebScanner = null;\n }\n\n document.getElementById(\n \"cap-os-barcode-scanner-container-dialog\",\n )!.style.display = \"none\";\n }\n\n /**\n * Builds the HTML elements necessary for the barcode scanner UI.\n * This method checks if the scanner container exists before creating it to avoid duplicates.\n * It also sets up the close button to stop and hide the scanner on click.\n * @private\n */\n private buildScannerElement(): void {\n if (document.getElementById(\"cap-os-barcode-scanner-container\")) {\n document.getElementById(\"cap-os-barcode-scanner-container\")!.className =\n \"scanner-container-display\";\n return;\n }\n // Create and configure scanner container elements\n const caposbarcodescannercontainer = document.body.appendChild(\n document.createElement(\"div\"),\n );\n caposbarcodescannercontainer.id = \"cap-os-barcode-scanner-container\";\n const caposbarcodescannercontainerdialog = document.createElement(\"div\");\n caposbarcodescannercontainerdialog.id =\n \"cap-os-barcode-scanner-container-dialog\";\n caposbarcodescannercontainerdialog.className = \"scanner-dialog\";\n\n // Inner dialog elements including the close button and scanner view\n const caposbarcodescannercontainerdialoginner =\n document.createElement(\"div\");\n caposbarcodescannercontainerdialoginner.className = \"scanner-dialog-inner\";\n\n const caposbarcodescannercontainerdialoginnerclose =\n document.createElement(\"span\");\n caposbarcodescannercontainerdialoginnerclose.className = \"close-button\";\n caposbarcodescannercontainerdialoginnerclose.innerHTML = \"×\";\n caposbarcodescannercontainerdialoginner.appendChild(\n caposbarcodescannercontainerdialoginnerclose,\n );\n\n const caposbarcodescannercontainerdialoginnercontainerp =\n document.createElement(\"p\");\n caposbarcodescannercontainerdialoginnercontainerp.innerHTML = \" \";\n caposbarcodescannercontainerdialoginner.appendChild(\n caposbarcodescannercontainerdialoginnercontainerp,\n );\n\n const caposbarcodescannercontainerdialoginnercontainer =\n document.createElement(\"div\");\n caposbarcodescannercontainerdialoginnercontainer.className =\n \"scanner-container-full-width\";\n caposbarcodescannercontainerdialoginnercontainer.id =\n \"cap-os-barcode-scanner-container-scanner\";\n caposbarcodescannercontainerdialoginner.appendChild(\n caposbarcodescannercontainerdialoginnercontainer,\n );\n\n caposbarcodescannercontainerdialog.appendChild(\n caposbarcodescannercontainerdialoginner,\n );\n caposbarcodescannercontainer.appendChild(\n caposbarcodescannercontainerdialog,\n );\n\n caposbarcodescannercontainerdialoginnerclose.onclick =\n this.stopAndHideScanner;\n }\n\n /**\n * Initiates a barcode scan using the user's camera and HTML5 QR code scanner.\n * Displays the scanner UI and waits for a scan to complete or fail.\n * @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.\n * @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.\n */\n async scanBarcode(\n options: CapacitorBarcodeScannerOptions,\n ): Promise<CapacitorBarcodeScannerScanResult> {\n this.buildScannerElement();\n\n document.getElementById(\n \"cap-os-barcode-scanner-container-dialog\",\n )!.style.display = \"block\";\n return new Promise((resolve, reject) => {\n const param = {\n facingMode: options.cameraDirection === 1 ? \"environment\" : \"user\",\n hasScannerButton: false,\n scanButton:\n options.scanButton === undefined ? false : options.scanButton,\n showScanLine: false,\n scanInstructions: options.scanInstructions\n ? options.scanInstructions\n : \"\",\n orientation: options.scanOrientation\n ? options.scanOrientation\n : CapacitorBarcodeScannerScanOrientation.PORTRAIT,\n showCameraSelection: options.web?.showCameraSelection\n ? options.web.showCameraSelection\n : false,\n typeHint: options.hint === 17 ? undefined : options.hint,\n scannerFPS: options.web?.scannerFPS ? options.web.scannerFPS : 50,\n };\n\n // Set up and start the scanner\n const scannerElement = document.getElementById(\n \"cap-os-barcode-scanner-container-scanner\",\n );\n if (!scannerElement) {\n throw new Error(\"Scanner Element is required for web\");\n }\n\n (window as any).OSBarcodeWebScanner = new Html5Qrcode(scannerElement.id, {\n formatsToSupport:\n param.typeHint !== undefined ? [param.typeHint] : undefined,\n verbose: undefined,\n });\n const Html5QrcodeConfig = {\n fps: param.scannerFPS,\n qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,\n aspectRatio: 16 / 9,\n videoConstraints: {\n focusMode: \"continuous\",\n height: { min: 576, ideal: 1920 },\n deviceId: undefined,\n facingMode: param.facingMode,\n },\n };\n\n // Success and error callbacks for the scanner\n const OSBarcodeWebScannerSuccessCallback = (\n decodedText: string,\n decodedResult: Html5QrcodeResult,\n ) => {\n this.stopAndHideScanner();\n resolve({\n ScanResult: decodedText,\n format:\n decodedResult.result.format?.format ??\n CapacitorBarcodeScannerTypeHint.ALL,\n });\n };\n\n const OSBarcodeWebScannerErrorCallback = (error: string) => {\n const allowedErrors = [\n \"NotFoundException\",\n \"No barcode or QR code detected\",\n \"No MultiFormat Readers were able to detect the code\",\n ];\n\n if (!allowedErrors.find((e) => error.indexOf(e) !== -1)) {\n this.stopAndHideScanner();\n console.error(`[Scanner Web Error] ${error}`);\n reject(error);\n }\n };\n\n (window as any).OSBarcodeWebScanner.start(\n { facingMode: param.facingMode },\n Html5QrcodeConfig,\n OSBarcodeWebScannerSuccessCallback,\n OSBarcodeWebScannerErrorCallback,\n );\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,OAAO,EAAE,sCAAsC,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAExG;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,SAAS;IACvD;;;;OAIG;IACK,KAAK,CAAC,kBAAkB;QAC9B,OAAO,CAAC,GAAG,CAAE,MAAc,CAAC,mBAAmB,CAAC,CAAC;QACjD,IAAK,MAAc,CAAC,mBAAmB,EAAE,CAAC;YACxC,MAAO,MAAc,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C9C,MAAM,kCAAkC,GAAG,CAAC,WAAmB,EAAE,aAAgC,EAAE,EAAE;;gBACnG,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC1B,OAAO,CAAC;oBACN,UAAU,EAAE,WAAW;oBACvB,MAAM,EAAE,MAAA,MAAA,aAAa,CAAC,MAAM,CAAC,MAAM,0CAAE,MAAM,mCAAI,+BAA+B,CAAC,GAAG;iBACnF,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,MAAM,gCAAgC,GAAG,CAAC,KAAa,EAAE,EAAE;gBACzD,MAAM,aAAa,GAAG;oBACpB,mBAAmB;oBACnB,gCAAgC;oBAChC,qDAAqD;iBACtD,CAAC;gBAEF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBACxD,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;oBAC9C,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC;YAED,MAAc,CAAC,mBAAmB,CAAC,KAAK,CACvC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAChC,iBAAiB,EACjB,kCAAkC,EAClC,gCAAgC,CACjC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { Html5QrcodeResult } from 'html5-qrcode';\nimport { Html5Qrcode } from 'html5-qrcode';\n\nimport type {\n CapacitorBarcodeScannerPlugin,\n CapacitorBarcodeScannerOptions,\n CapacitorBarcodeScannerScanResult,\n} from './definitions';\nimport { CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerTypeHint } from './definitions';\n\n/**\n * Implements OSBarcodePlugin to provide web functionality for barcode scanning.\n */\nexport class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBarcodeScannerPlugin {\n /**\n * Stops the barcode scanner and hides its UI.\n * @private\n * @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.\n */\n private async stopAndHideScanner(): Promise<void> {\n console.log((window as any).OSBarcodeWebScanner);\n if ((window as any).OSBarcodeWebScanner) {\n await (window as any).OSBarcodeWebScanner.stop();\n (window as any).OSBarcodeWebScanner = null;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n document.getElementById('cap-os-barcode-scanner-container-dialog')!.style.display = 'none';\n }\n\n /**\n * Builds the HTML elements necessary for the barcode scanner UI.\n * This method checks if the scanner container exists before creating it to avoid duplicates.\n * It also sets up the close button to stop and hide the scanner on click.\n * @private\n */\n private buildScannerElement(): void {\n if (document.getElementById('cap-os-barcode-scanner-container')) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n document.getElementById('cap-os-barcode-scanner-container')!.className = 'scanner-container-display';\n return;\n }\n // Create and configure scanner container elements\n const caposbarcodescannercontainer = document.body.appendChild(document.createElement('div'));\n caposbarcodescannercontainer.id = 'cap-os-barcode-scanner-container';\n const caposbarcodescannercontainerdialog = document.createElement('div');\n caposbarcodescannercontainerdialog.id = 'cap-os-barcode-scanner-container-dialog';\n caposbarcodescannercontainerdialog.className = 'scanner-dialog';\n\n // Inner dialog elements including the close button and scanner view\n const caposbarcodescannercontainerdialoginner = document.createElement('div');\n caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';\n\n const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');\n caposbarcodescannercontainerdialoginnerclose.className = 'close-button';\n caposbarcodescannercontainerdialoginnerclose.innerHTML = '×';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);\n\n const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');\n caposbarcodescannercontainerdialoginnercontainerp.innerHTML = ' ';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);\n\n const caposbarcodescannercontainerdialoginnercontainer = document.createElement('div');\n caposbarcodescannercontainerdialoginnercontainer.className = 'scanner-container-full-width';\n caposbarcodescannercontainerdialoginnercontainer.id = 'cap-os-barcode-scanner-container-scanner';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainer);\n\n caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);\n caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);\n\n caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;\n }\n\n /**\n * Initiates a barcode scan using the user's camera and HTML5 QR code scanner.\n * Displays the scanner UI and waits for a scan to complete or fail.\n * @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.\n * @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.\n */\n async scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult> {\n this.buildScannerElement();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n document.getElementById('cap-os-barcode-scanner-container-dialog')!.style.display = 'block';\n return new Promise((resolve, reject) => {\n const param = {\n facingMode: options.cameraDirection === 1 ? 'environment' : 'user',\n hasScannerButton: false,\n scanButton: options.scanButton === undefined ? false : options.scanButton,\n showScanLine: false,\n scanInstructions: options.scanInstructions ? options.scanInstructions : '',\n orientation: options.scanOrientation\n ? options.scanOrientation\n : CapacitorBarcodeScannerScanOrientation.PORTRAIT,\n showCameraSelection: options.web?.showCameraSelection ? options.web.showCameraSelection : false,\n typeHint: options.hint === 17 ? undefined : options.hint,\n scannerFPS: options.web?.scannerFPS ? options.web.scannerFPS : 50,\n };\n\n // Set up and start the scanner\n const scannerElement = document.getElementById('cap-os-barcode-scanner-container-scanner');\n if (!scannerElement) {\n throw new Error('Scanner Element is required for web');\n }\n\n (window as any).OSBarcodeWebScanner = new Html5Qrcode(scannerElement.id, {\n formatsToSupport: param.typeHint !== undefined ? [param.typeHint] : undefined,\n verbose: undefined,\n });\n const Html5QrcodeConfig = {\n fps: param.scannerFPS,\n qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,\n aspectRatio: 16 / 9,\n videoConstraints: {\n focusMode: 'continuous',\n height: { min: 576, ideal: 1920 },\n deviceId: undefined,\n facingMode: param.facingMode,\n },\n };\n\n // Success and error callbacks for the scanner\n const OSBarcodeWebScannerSuccessCallback = (decodedText: string, decodedResult: Html5QrcodeResult) => {\n this.stopAndHideScanner();\n resolve({\n ScanResult: decodedText,\n format: decodedResult.result.format?.format ?? CapacitorBarcodeScannerTypeHint.ALL,\n });\n };\n\n const OSBarcodeWebScannerErrorCallback = (error: string) => {\n const allowedErrors = [\n 'NotFoundException',\n 'No barcode or QR code detected',\n 'No MultiFormat Readers were able to detect the code',\n ];\n\n if (!allowedErrors.find((e) => error.indexOf(e) !== -1)) {\n this.stopAndHideScanner();\n console.error(`[Scanner Web Error] ${error}`);\n reject(error);\n }\n };\n\n (window as any).OSBarcodeWebScanner.start(\n { facingMode: param.facingMode },\n Html5QrcodeConfig,\n OSBarcodeWebScannerSuccessCallback,\n OSBarcodeWebScannerErrorCallback\n );\n });\n }\n}\n"]}
|