@capacitor/barcode-scanner 1.0.0-alpha.1
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 +18 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/capacitorjs/barcodescanner/OSBarcodePlugin.kt +76 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +262 -0
- package/dist/esm/definitions.d.ts +90 -0
- package/dist/esm/definitions.js +39 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils.d.ts +20 -0
- package/dist/esm/utils.js +55 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +116 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +233 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +235 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/CapacitorBarcodeScannerPlugin.h +10 -0
- package/ios/Plugin/CapacitorBarcodeScannerPlugin.m +8 -0
- package/ios/Plugin/CapacitorBarcodeScannerPlugin.swift +48 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/OSBARCArgumentMappable.swift +19 -0
- package/ios/Plugin/OSBarcodeError.swift +30 -0
- package/ios/Plugin/OSBarcodeScanArgumentsModel.swift +44 -0
- package/package.json +84 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Html5QrcodeSupportedFormats } from 'html5-qrcode';
|
|
2
|
+
/**
|
|
3
|
+
* Enum representing the direction of the camera to be used for barcode scanning.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum CapacitorBarcodeScannerCameraDirection {
|
|
6
|
+
BACK = 1,
|
|
7
|
+
FRONT = 2
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Enum representing the orientation of the scanner during barcode scanning.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum CapacitorBarcodeScannerScanOrientation {
|
|
13
|
+
PORTRAIT = 1,
|
|
14
|
+
LANDSCAPE = 2,
|
|
15
|
+
ADAPTIVE = 3
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Enum representing a special option to indicate that all barcode types are supported.
|
|
19
|
+
*/
|
|
20
|
+
export declare enum CapacitorBarcodeScannerTypeHintALLOption {
|
|
21
|
+
ALL = 17
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extends supported formats from Html5Qrcode with a special 'ALL' option,
|
|
25
|
+
* indicating support for all barcode types.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CapacitorBarcodeScannerTypeHint: {
|
|
28
|
+
[x: number]: string;
|
|
29
|
+
ALL: CapacitorBarcodeScannerTypeHintALLOption.ALL;
|
|
30
|
+
QR_CODE: Html5QrcodeSupportedFormats.QR_CODE;
|
|
31
|
+
AZTEC: Html5QrcodeSupportedFormats.AZTEC;
|
|
32
|
+
CODABAR: Html5QrcodeSupportedFormats.CODABAR;
|
|
33
|
+
CODE_39: Html5QrcodeSupportedFormats.CODE_39;
|
|
34
|
+
CODE_93: Html5QrcodeSupportedFormats.CODE_93;
|
|
35
|
+
CODE_128: Html5QrcodeSupportedFormats.CODE_128;
|
|
36
|
+
DATA_MATRIX: Html5QrcodeSupportedFormats.DATA_MATRIX;
|
|
37
|
+
MAXICODE: Html5QrcodeSupportedFormats.MAXICODE;
|
|
38
|
+
ITF: Html5QrcodeSupportedFormats.ITF;
|
|
39
|
+
EAN_13: Html5QrcodeSupportedFormats.EAN_13;
|
|
40
|
+
EAN_8: Html5QrcodeSupportedFormats.EAN_8;
|
|
41
|
+
PDF_417: Html5QrcodeSupportedFormats.PDF_417;
|
|
42
|
+
RSS_14: Html5QrcodeSupportedFormats.RSS_14;
|
|
43
|
+
RSS_EXPANDED: Html5QrcodeSupportedFormats.RSS_EXPANDED;
|
|
44
|
+
UPC_A: Html5QrcodeSupportedFormats.UPC_A;
|
|
45
|
+
UPC_E: Html5QrcodeSupportedFormats.UPC_E;
|
|
46
|
+
UPC_EAN_EXTENSION: Html5QrcodeSupportedFormats.UPC_EAN_EXTENSION;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Type definition combining Html5QrcodeSupportedFormats and OSBarcodeTypeHintALLOption
|
|
50
|
+
* to represent the hint for the type of barcode to be scanned.
|
|
51
|
+
*/
|
|
52
|
+
export type CapacitorBarcodeScannerTypeHint = Html5QrcodeSupportedFormats | CapacitorBarcodeScannerTypeHintALLOption;
|
|
53
|
+
/**
|
|
54
|
+
* Enum representing the library to be used for barcode scanning on Android devices.
|
|
55
|
+
*/
|
|
56
|
+
export declare enum CapacitorBarcodeScannerAndroidScanningLibrary {
|
|
57
|
+
ZXING = "zxing",
|
|
58
|
+
MLKIT = "mlkit"
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Defines the structure of the result returned from a barcode scan.
|
|
62
|
+
*/
|
|
63
|
+
export type CapacitorBarcodeScannerScanResult = {
|
|
64
|
+
ScanResult: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Defines the options for configuring a barcode scan.
|
|
68
|
+
*/
|
|
69
|
+
export type CapacitorBarcodeScannerOptions = {
|
|
70
|
+
hint: CapacitorBarcodeScannerTypeHint;
|
|
71
|
+
scanInstructions?: string;
|
|
72
|
+
scanButton?: boolean;
|
|
73
|
+
scanText?: string;
|
|
74
|
+
cameraDirection?: CapacitorBarcodeScannerCameraDirection;
|
|
75
|
+
scanOrientation?: CapacitorBarcodeScannerScanOrientation;
|
|
76
|
+
android?: {
|
|
77
|
+
scanningLibrary?: CapacitorBarcodeScannerAndroidScanningLibrary;
|
|
78
|
+
};
|
|
79
|
+
web?: {
|
|
80
|
+
showCameraSelection?: boolean;
|
|
81
|
+
scannerFPS?: number;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Interface defining the contract for a plugin capable of scanning barcodes.
|
|
86
|
+
* Requires implementation of the scanBarcode method, which initiates a barcode scan with given options.
|
|
87
|
+
*/
|
|
88
|
+
export interface CapacitorBarcodeScannerPlugin {
|
|
89
|
+
scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult>;
|
|
90
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Html5QrcodeSupportedFormats } from 'html5-qrcode';
|
|
2
|
+
/**
|
|
3
|
+
* Enum representing the direction of the camera to be used for barcode scanning.
|
|
4
|
+
*/
|
|
5
|
+
export var CapacitorBarcodeScannerCameraDirection;
|
|
6
|
+
(function (CapacitorBarcodeScannerCameraDirection) {
|
|
7
|
+
CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["BACK"] = 1] = "BACK";
|
|
8
|
+
CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["FRONT"] = 2] = "FRONT";
|
|
9
|
+
})(CapacitorBarcodeScannerCameraDirection || (CapacitorBarcodeScannerCameraDirection = {}));
|
|
10
|
+
/**
|
|
11
|
+
* Enum representing the orientation of the scanner during barcode scanning.
|
|
12
|
+
*/
|
|
13
|
+
export var CapacitorBarcodeScannerScanOrientation;
|
|
14
|
+
(function (CapacitorBarcodeScannerScanOrientation) {
|
|
15
|
+
CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["PORTRAIT"] = 1] = "PORTRAIT";
|
|
16
|
+
CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["LANDSCAPE"] = 2] = "LANDSCAPE";
|
|
17
|
+
CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["ADAPTIVE"] = 3] = "ADAPTIVE";
|
|
18
|
+
})(CapacitorBarcodeScannerScanOrientation || (CapacitorBarcodeScannerScanOrientation = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Enum representing a special option to indicate that all barcode types are supported.
|
|
21
|
+
*/
|
|
22
|
+
export var CapacitorBarcodeScannerTypeHintALLOption;
|
|
23
|
+
(function (CapacitorBarcodeScannerTypeHintALLOption) {
|
|
24
|
+
CapacitorBarcodeScannerTypeHintALLOption[CapacitorBarcodeScannerTypeHintALLOption["ALL"] = 17] = "ALL";
|
|
25
|
+
})(CapacitorBarcodeScannerTypeHintALLOption || (CapacitorBarcodeScannerTypeHintALLOption = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Extends supported formats from Html5Qrcode with a special 'ALL' option,
|
|
28
|
+
* indicating support for all barcode types.
|
|
29
|
+
*/
|
|
30
|
+
export const CapacitorBarcodeScannerTypeHint = Object.assign(Object.assign({}, Html5QrcodeSupportedFormats), CapacitorBarcodeScannerTypeHintALLOption);
|
|
31
|
+
/**
|
|
32
|
+
* Enum representing the library to be used for barcode scanning on Android devices.
|
|
33
|
+
*/
|
|
34
|
+
export var CapacitorBarcodeScannerAndroidScanningLibrary;
|
|
35
|
+
(function (CapacitorBarcodeScannerAndroidScanningLibrary) {
|
|
36
|
+
CapacitorBarcodeScannerAndroidScanningLibrary["ZXING"] = "zxing";
|
|
37
|
+
CapacitorBarcodeScannerAndroidScanningLibrary["MLKIT"] = "mlkit";
|
|
38
|
+
})(CapacitorBarcodeScannerAndroidScanningLibrary || (CapacitorBarcodeScannerAndroidScanningLibrary = {}));
|
|
39
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAN,IAAY,sCAGX;AAHD,WAAY,sCAAsC;IAChD,mGAAQ,CAAA;IACR,qGAAS,CAAA;AACX,CAAC,EAHW,sCAAsC,KAAtC,sCAAsC,QAGjD;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,sCAIX;AAJD,WAAY,sCAAsC;IAChD,2GAAY,CAAA;IACZ,6GAAa,CAAA;IACb,2GAAY,CAAA;AACd,CAAC,EAJW,sCAAsC,KAAtC,sCAAsC,QAIjD;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,wCAEX;AAFD,WAAY,wCAAwC;IAClD,sGAAQ,CAAA;AACV,CAAC,EAFW,wCAAwC,KAAxC,wCAAwC,QAEnD;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,mCACvC,2BAA2B,GAC3B,wCAAwC,CAC5C,CAAC;AAQF;;GAEG;AACH,MAAM,CAAN,IAAY,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 = { ScanResult: string };\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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CapacitorBarcodeScannerPlugin } from './definitions';
|
|
2
|
+
/**
|
|
3
|
+
* Registers the `OSBarcode` plugin with Capacitor.
|
|
4
|
+
* For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
|
|
5
|
+
* This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
|
|
6
|
+
*/
|
|
7
|
+
declare const CapacitorBarcodeScanner: CapacitorBarcodeScannerPlugin;
|
|
8
|
+
export * from './definitions';
|
|
9
|
+
export { CapacitorBarcodeScanner };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
import { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.
|
|
3
|
+
/**
|
|
4
|
+
* Registers the `OSBarcode` plugin with Capacitor.
|
|
5
|
+
* For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
|
|
6
|
+
* This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
|
|
7
|
+
*/
|
|
8
|
+
const CapacitorBarcodeScanner = registerPlugin('CapacitorBarcodeScanner', {
|
|
9
|
+
web: () => {
|
|
10
|
+
applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.
|
|
11
|
+
return import('./web').then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export * from './definitions'; // Re-export all exports from the definitions file.
|
|
15
|
+
export { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects.
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC,CAAC,qCAAqC;AAE5F;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,cAAc,CAAgC,yBAAyB,EAAE;IACvG,GAAG,EAAE,GAAG,EAAE;QACR,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,oFAAoF;QACjH,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC,gEAAgE;IAC1I,CAAC;CACF,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC,CAAC,mDAAmD;AAClF,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC,6DAA6D","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorBarcodeScannerPlugin } 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 CapacitorBarcodeScanner = 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\nexport * from './definitions'; // Re-export all exports from the definitions file.\nexport { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects.\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined CSS rules for styling barcode scanner components.
|
|
3
|
+
* Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.
|
|
4
|
+
*/
|
|
5
|
+
export declare const barcodeScannerCss: {
|
|
6
|
+
selector: string;
|
|
7
|
+
css: string;
|
|
8
|
+
}[];
|
|
9
|
+
/**
|
|
10
|
+
* Dynamically applies a set of CSS rules to the document.
|
|
11
|
+
* If a custom style element with a specific ID does not exist, it is created and appended to the document's head.
|
|
12
|
+
* Existing rules in the style element are cleared before new ones are applied.
|
|
13
|
+
* This function supports both modern and older browsers by using `CSSStyleSheet.insertRule` and `textContent` respectively.
|
|
14
|
+
*
|
|
15
|
+
* @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyCss(cssRules: {
|
|
18
|
+
selector: string;
|
|
19
|
+
css: string;
|
|
20
|
+
}[]): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined CSS rules for styling barcode scanner components.
|
|
3
|
+
* Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.
|
|
4
|
+
*/
|
|
5
|
+
export const barcodeScannerCss = [
|
|
6
|
+
{ selector: '.scanner-container-display', css: 'display: block;' },
|
|
7
|
+
{
|
|
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
|
+
},
|
|
11
|
+
{
|
|
12
|
+
selector: '.scanner-dialog-inner',
|
|
13
|
+
css: 'background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;',
|
|
14
|
+
},
|
|
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%;' },
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Dynamically applies a set of CSS rules to the document.
|
|
21
|
+
* If a custom style element with a specific ID does not exist, it is created and appended to the document's head.
|
|
22
|
+
* Existing rules in the style element are cleared before new ones are applied.
|
|
23
|
+
* This function supports both modern and older browsers by using `CSSStyleSheet.insertRule` and `textContent` respectively.
|
|
24
|
+
*
|
|
25
|
+
* @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.
|
|
26
|
+
*/
|
|
27
|
+
export function applyCss(cssRules) {
|
|
28
|
+
const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.
|
|
29
|
+
let styleElement = document.getElementById(styleId);
|
|
30
|
+
if (!styleElement) {
|
|
31
|
+
// Create and append a new style element if it does not exist.
|
|
32
|
+
styleElement = document.createElement('style');
|
|
33
|
+
styleElement.type = 'text/css';
|
|
34
|
+
styleElement.id = styleId;
|
|
35
|
+
document.head.appendChild(styleElement);
|
|
36
|
+
}
|
|
37
|
+
if (styleElement.sheet) {
|
|
38
|
+
// Clear existing CSS rules.
|
|
39
|
+
while (styleElement.sheet.cssRules.length) {
|
|
40
|
+
styleElement.sheet.deleteRule(0);
|
|
41
|
+
}
|
|
42
|
+
// Insert new CSS rules.
|
|
43
|
+
for (const { selector, css } of cssRules) {
|
|
44
|
+
styleElement.sheet.insertRule(`${selector} { ${css} }`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Fallback for older browsers using textContent.
|
|
49
|
+
styleElement.textContent = '';
|
|
50
|
+
for (const { selector, css } of cssRules) {
|
|
51
|
+
styleElement.textContent += `${selector} { ${css} }`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +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,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,EAAE,iFAAiF,EAAE;IACrH,EAAE,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,cAAc,EAAE;IACxD,EAAE,QAAQ,EAAE,+BAA+B,EAAE,GAAG,EAAE,cAAc,EAAE;CACnE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,QAA6C;IACpE,MAAM,OAAO,GAAG,6BAA6B,CAAC,CAAC,2CAA2C;IAC1F,IAAI,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAA4B,CAAC;IAC/E,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,8DAA8D;QAC9D,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/C,YAAY,CAAC,IAAI,GAAG,UAAU,CAAC;QAC/B,YAAY,CAAC,EAAE,GAAG,OAAO,CAAC;QAC1B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,4BAA4B;QAC5B,OAAO,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC1C,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;QACD,wBAAwB;QACxB,KAAK,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YACzC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,QAAQ,MAAM,GAAG,IAAI,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;SAAM,CAAC;QACN,iDAAiD;QACjD,YAAY,CAAC,WAAW,GAAG,EAAE,CAAC;QAC9B,KAAK,MAAM,EAAE,QAAQ,EAAE,GAAG,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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorBarcodeScannerPlugin, CapacitorBarcodeScannerOptions, CapacitorBarcodeScannerScanResult } from './definitions';
|
|
3
|
+
/**
|
|
4
|
+
* Implements OSBarcodePlugin to provide web functionality for barcode scanning.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBarcodeScannerPlugin {
|
|
7
|
+
/**
|
|
8
|
+
* Stops the barcode scanner and hides its UI.
|
|
9
|
+
* @private
|
|
10
|
+
* @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.
|
|
11
|
+
*/
|
|
12
|
+
private stopAndHideScanner;
|
|
13
|
+
/**
|
|
14
|
+
* Builds the HTML elements necessary for the barcode scanner UI.
|
|
15
|
+
* This method checks if the scanner container exists before creating it to avoid duplicates.
|
|
16
|
+
* It also sets up the close button to stop and hide the scanner on click.
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private buildScannerElement;
|
|
20
|
+
/**
|
|
21
|
+
* Initiates a barcode scan using the user's camera and HTML5 QR code scanner.
|
|
22
|
+
* Displays the scanner UI and waits for a scan to complete or fail.
|
|
23
|
+
* @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.
|
|
24
|
+
* @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.
|
|
25
|
+
*/
|
|
26
|
+
scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult>;
|
|
27
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import { Html5Qrcode } from 'html5-qrcode';
|
|
3
|
+
import { CapacitorBarcodeScannerScanOrientation } from './definitions';
|
|
4
|
+
/**
|
|
5
|
+
* Implements OSBarcodePlugin to provide web functionality for barcode scanning.
|
|
6
|
+
*/
|
|
7
|
+
export class CapacitorBarcodeScannerWeb extends WebPlugin {
|
|
8
|
+
/**
|
|
9
|
+
* Stops the barcode scanner and hides its UI.
|
|
10
|
+
* @private
|
|
11
|
+
* @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.
|
|
12
|
+
*/
|
|
13
|
+
async stopAndHideScanner() {
|
|
14
|
+
console.log(window.OSBarcodeWebScanner);
|
|
15
|
+
if (window.OSBarcodeWebScanner) {
|
|
16
|
+
await window.OSBarcodeWebScanner.stop();
|
|
17
|
+
window.OSBarcodeWebScanner = null;
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
|
+
document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'none';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the HTML elements necessary for the barcode scanner UI.
|
|
24
|
+
* This method checks if the scanner container exists before creating it to avoid duplicates.
|
|
25
|
+
* It also sets up the close button to stop and hide the scanner on click.
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
buildScannerElement() {
|
|
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
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Create and configure scanner container elements
|
|
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';
|
|
40
|
+
// Inner dialog elements including the close button and scanner view
|
|
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 = '×';
|
|
46
|
+
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);
|
|
47
|
+
const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');
|
|
48
|
+
caposbarcodescannercontainerdialoginnercontainerp.innerHTML = ' ';
|
|
49
|
+
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);
|
|
50
|
+
const caposbarcodescannercontainerdialoginnercontainer = document.createElement('div');
|
|
51
|
+
caposbarcodescannercontainerdialoginnercontainer.className = 'scanner-container-full-width';
|
|
52
|
+
caposbarcodescannercontainerdialoginnercontainer.id = 'cap-os-barcode-scanner-container-scanner';
|
|
53
|
+
caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainer);
|
|
54
|
+
caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);
|
|
55
|
+
caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);
|
|
56
|
+
caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initiates a barcode scan using the user's camera and HTML5 QR code scanner.
|
|
60
|
+
* Displays the scanner UI and waits for a scan to complete or fail.
|
|
61
|
+
* @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.
|
|
62
|
+
* @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.
|
|
63
|
+
*/
|
|
64
|
+
async scanBarcode(options) {
|
|
65
|
+
this.buildScannerElement();
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
+
document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'block';
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const param = {
|
|
71
|
+
facingMode: options.cameraDirection === 1 ? 'environment' : 'user',
|
|
72
|
+
hasScannerButton: false,
|
|
73
|
+
scanButton: options.scanButton === undefined ? false : options.scanButton,
|
|
74
|
+
showScanLine: false,
|
|
75
|
+
scanInstructions: options.scanInstructions ? options.scanInstructions : '',
|
|
76
|
+
orientation: options.scanOrientation
|
|
77
|
+
? options.scanOrientation
|
|
78
|
+
: CapacitorBarcodeScannerScanOrientation.PORTRAIT,
|
|
79
|
+
showCameraSelection: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,
|
|
80
|
+
typeHint: options.hint === 17 ? undefined : options.hint,
|
|
81
|
+
scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,
|
|
82
|
+
};
|
|
83
|
+
// Set up and start the scanner
|
|
84
|
+
const scannerElement = document.getElementById('cap-os-barcode-scanner-container-scanner');
|
|
85
|
+
if (!scannerElement) {
|
|
86
|
+
throw new Error('Scanner Element is required for web');
|
|
87
|
+
}
|
|
88
|
+
window.OSBarcodeWebScanner = new Html5Qrcode(scannerElement.id);
|
|
89
|
+
const Html5QrcodeConfig = {
|
|
90
|
+
fps: param.scannerFPS,
|
|
91
|
+
qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,
|
|
92
|
+
aspectRatio: 16 / 9,
|
|
93
|
+
videoConstraints: {
|
|
94
|
+
focusMode: 'continuous',
|
|
95
|
+
height: { min: 576, ideal: 1920 },
|
|
96
|
+
deviceId: undefined,
|
|
97
|
+
facingMode: undefined,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
// Success and error callbacks for the scanner
|
|
101
|
+
const OSBarcodeWebScannerSuccessCallback = (decodedText, _decodedResult) => {
|
|
102
|
+
this.stopAndHideScanner();
|
|
103
|
+
resolve({ ScanResult: decodedText });
|
|
104
|
+
};
|
|
105
|
+
const OSBarcodeWebScannerErrorCallback = (error) => {
|
|
106
|
+
if (error.indexOf('NotFoundException') === -1) {
|
|
107
|
+
this.stopAndHideScanner();
|
|
108
|
+
console.error(`[Scanner Web Error] ${error}`);
|
|
109
|
+
reject(error);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
window.OSBarcodeWebScanner.start({ facingMode: param.facingMode }, Html5QrcodeConfig, OSBarcodeWebScannerSuccessCallback, OSBarcodeWebScannerErrorCallback);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 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G,EAAE,CAAC,GAAG,EAAE;gBACnE,WAAW,EAAE,EAAE,GAAG,CAAC;gBACnB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,YAAY;oBACvB,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;oBACjC,QAAQ,EAAE,SAAS;oBACnB,UAAU,EAAE,SAAS;iBACtB;aACF,CAAC;YAEF,8CAA8C;YAC9C,MAAM,kCAAkC,GAAG,CAAC,WAAmB,EAAE,cAAiC,EAAE,EAAE;gBACpG,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC1B,OAAO,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;YACvC,CAAC,CAAC;YAEF,MAAM,gCAAgC,GAAG,CAAC,KAAa,EAAE,EAAE;gBACzD,IAAI,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC9C,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 } 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 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: undefined,\n },\n };\n\n // Success and error callbacks for the scanner\n const OSBarcodeWebScannerSuccessCallback = (decodedText: string, _decodedResult: Html5QrcodeResult) => {\n this.stopAndHideScanner();\n resolve({ ScanResult: decodedText });\n };\n\n const OSBarcodeWebScannerErrorCallback = (error: string) => {\n if (error.indexOf('NotFoundException') === -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"]}
|