@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.
@@ -0,0 +1,233 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@capacitor/core');
6
+ var html5Qrcode = require('html5-qrcode');
7
+
8
+ /**
9
+ * Predefined CSS rules for styling barcode scanner components.
10
+ * Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.
11
+ */
12
+ const barcodeScannerCss = [
13
+ { selector: '.scanner-container-display', css: 'display: block;' },
14
+ {
15
+ selector: '.scanner-dialog',
16
+ 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);',
17
+ },
18
+ {
19
+ selector: '.scanner-dialog-inner',
20
+ css: 'background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;',
21
+ },
22
+ { selector: '.close-button', css: 'color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;' },
23
+ { selector: '.close-button:hover', css: 'color: #222;' },
24
+ { selector: '.scanner-container-full-width', css: 'width: 100%;' },
25
+ ];
26
+ /**
27
+ * Dynamically applies a set of CSS rules to the document.
28
+ * If a custom style element with a specific ID does not exist, it is created and appended to the document's head.
29
+ * Existing rules in the style element are cleared before new ones are applied.
30
+ * This function supports both modern and older browsers by using `CSSStyleSheet.insertRule` and `textContent` respectively.
31
+ *
32
+ * @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.
33
+ */
34
+ function applyCss(cssRules) {
35
+ const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.
36
+ let styleElement = document.getElementById(styleId);
37
+ if (!styleElement) {
38
+ // Create and append a new style element if it does not exist.
39
+ styleElement = document.createElement('style');
40
+ styleElement.type = 'text/css';
41
+ styleElement.id = styleId;
42
+ document.head.appendChild(styleElement);
43
+ }
44
+ if (styleElement.sheet) {
45
+ // Clear existing CSS rules.
46
+ while (styleElement.sheet.cssRules.length) {
47
+ styleElement.sheet.deleteRule(0);
48
+ }
49
+ // Insert new CSS rules.
50
+ for (const { selector, css } of cssRules) {
51
+ styleElement.sheet.insertRule(`${selector} { ${css} }`);
52
+ }
53
+ }
54
+ else {
55
+ // Fallback for older browsers using textContent.
56
+ styleElement.textContent = '';
57
+ for (const { selector, css } of cssRules) {
58
+ styleElement.textContent += `${selector} { ${css} }`;
59
+ }
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Enum representing the direction of the camera to be used for barcode scanning.
65
+ */
66
+ exports.CapacitorBarcodeScannerCameraDirection = void 0;
67
+ (function (CapacitorBarcodeScannerCameraDirection) {
68
+ CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["BACK"] = 1] = "BACK";
69
+ CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["FRONT"] = 2] = "FRONT";
70
+ })(exports.CapacitorBarcodeScannerCameraDirection || (exports.CapacitorBarcodeScannerCameraDirection = {}));
71
+ /**
72
+ * Enum representing the orientation of the scanner during barcode scanning.
73
+ */
74
+ exports.CapacitorBarcodeScannerScanOrientation = void 0;
75
+ (function (CapacitorBarcodeScannerScanOrientation) {
76
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["PORTRAIT"] = 1] = "PORTRAIT";
77
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["LANDSCAPE"] = 2] = "LANDSCAPE";
78
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["ADAPTIVE"] = 3] = "ADAPTIVE";
79
+ })(exports.CapacitorBarcodeScannerScanOrientation || (exports.CapacitorBarcodeScannerScanOrientation = {}));
80
+ /**
81
+ * Enum representing a special option to indicate that all barcode types are supported.
82
+ */
83
+ exports.CapacitorBarcodeScannerTypeHintALLOption = void 0;
84
+ (function (CapacitorBarcodeScannerTypeHintALLOption) {
85
+ CapacitorBarcodeScannerTypeHintALLOption[CapacitorBarcodeScannerTypeHintALLOption["ALL"] = 17] = "ALL";
86
+ })(exports.CapacitorBarcodeScannerTypeHintALLOption || (exports.CapacitorBarcodeScannerTypeHintALLOption = {}));
87
+ /**
88
+ * Extends supported formats from Html5Qrcode with a special 'ALL' option,
89
+ * indicating support for all barcode types.
90
+ */
91
+ const CapacitorBarcodeScannerTypeHint = Object.assign(Object.assign({}, html5Qrcode.Html5QrcodeSupportedFormats), exports.CapacitorBarcodeScannerTypeHintALLOption);
92
+ /**
93
+ * Enum representing the library to be used for barcode scanning on Android devices.
94
+ */
95
+ exports.CapacitorBarcodeScannerAndroidScanningLibrary = void 0;
96
+ (function (CapacitorBarcodeScannerAndroidScanningLibrary) {
97
+ CapacitorBarcodeScannerAndroidScanningLibrary["ZXING"] = "zxing";
98
+ CapacitorBarcodeScannerAndroidScanningLibrary["MLKIT"] = "mlkit";
99
+ })(exports.CapacitorBarcodeScannerAndroidScanningLibrary || (exports.CapacitorBarcodeScannerAndroidScanningLibrary = {}));
100
+
101
+ /**
102
+ * Registers the `OSBarcode` plugin with Capacitor.
103
+ * For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
104
+ * This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
105
+ */
106
+ const CapacitorBarcodeScanner = core.registerPlugin('CapacitorBarcodeScanner', {
107
+ web: () => {
108
+ applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.
109
+ return Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.
110
+ },
111
+ });
112
+
113
+ /**
114
+ * Implements OSBarcodePlugin to provide web functionality for barcode scanning.
115
+ */
116
+ class CapacitorBarcodeScannerWeb extends core.WebPlugin {
117
+ /**
118
+ * Stops the barcode scanner and hides its UI.
119
+ * @private
120
+ * @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.
121
+ */
122
+ async stopAndHideScanner() {
123
+ console.log(window.OSBarcodeWebScanner);
124
+ if (window.OSBarcodeWebScanner) {
125
+ await window.OSBarcodeWebScanner.stop();
126
+ window.OSBarcodeWebScanner = null;
127
+ }
128
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
+ document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'none';
130
+ }
131
+ /**
132
+ * Builds the HTML elements necessary for the barcode scanner UI.
133
+ * This method checks if the scanner container exists before creating it to avoid duplicates.
134
+ * It also sets up the close button to stop and hide the scanner on click.
135
+ * @private
136
+ */
137
+ buildScannerElement() {
138
+ if (document.getElementById('cap-os-barcode-scanner-container')) {
139
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140
+ document.getElementById('cap-os-barcode-scanner-container').className = 'scanner-container-display';
141
+ return;
142
+ }
143
+ // Create and configure scanner container elements
144
+ const caposbarcodescannercontainer = document.body.appendChild(document.createElement('div'));
145
+ caposbarcodescannercontainer.id = 'cap-os-barcode-scanner-container';
146
+ const caposbarcodescannercontainerdialog = document.createElement('div');
147
+ caposbarcodescannercontainerdialog.id = 'cap-os-barcode-scanner-container-dialog';
148
+ caposbarcodescannercontainerdialog.className = 'scanner-dialog';
149
+ // Inner dialog elements including the close button and scanner view
150
+ const caposbarcodescannercontainerdialoginner = document.createElement('div');
151
+ caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';
152
+ const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');
153
+ caposbarcodescannercontainerdialoginnerclose.className = 'close-button';
154
+ caposbarcodescannercontainerdialoginnerclose.innerHTML = '&times;';
155
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);
156
+ const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');
157
+ caposbarcodescannercontainerdialoginnercontainerp.innerHTML = '&nbsp;';
158
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);
159
+ const caposbarcodescannercontainerdialoginnercontainer = document.createElement('div');
160
+ caposbarcodescannercontainerdialoginnercontainer.className = 'scanner-container-full-width';
161
+ caposbarcodescannercontainerdialoginnercontainer.id = 'cap-os-barcode-scanner-container-scanner';
162
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainer);
163
+ caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);
164
+ caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);
165
+ caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;
166
+ }
167
+ /**
168
+ * Initiates a barcode scan using the user's camera and HTML5 QR code scanner.
169
+ * Displays the scanner UI and waits for a scan to complete or fail.
170
+ * @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.
171
+ * @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.
172
+ */
173
+ async scanBarcode(options) {
174
+ this.buildScannerElement();
175
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
176
+ document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'block';
177
+ return new Promise((resolve, reject) => {
178
+ var _a, _b;
179
+ const param = {
180
+ facingMode: options.cameraDirection === 1 ? 'environment' : 'user',
181
+ hasScannerButton: false,
182
+ scanButton: options.scanButton === undefined ? false : options.scanButton,
183
+ showScanLine: false,
184
+ scanInstructions: options.scanInstructions ? options.scanInstructions : '',
185
+ orientation: options.scanOrientation
186
+ ? options.scanOrientation
187
+ : exports.CapacitorBarcodeScannerScanOrientation.PORTRAIT,
188
+ showCameraSelection: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,
189
+ typeHint: options.hint === 17 ? undefined : options.hint,
190
+ scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,
191
+ };
192
+ // Set up and start the scanner
193
+ const scannerElement = document.getElementById('cap-os-barcode-scanner-container-scanner');
194
+ if (!scannerElement) {
195
+ throw new Error('Scanner Element is required for web');
196
+ }
197
+ window.OSBarcodeWebScanner = new html5Qrcode.Html5Qrcode(scannerElement.id);
198
+ const Html5QrcodeConfig = {
199
+ fps: param.scannerFPS,
200
+ qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,
201
+ aspectRatio: 16 / 9,
202
+ videoConstraints: {
203
+ focusMode: 'continuous',
204
+ height: { min: 576, ideal: 1920 },
205
+ deviceId: undefined,
206
+ facingMode: undefined,
207
+ },
208
+ };
209
+ // Success and error callbacks for the scanner
210
+ const OSBarcodeWebScannerSuccessCallback = (decodedText, _decodedResult) => {
211
+ this.stopAndHideScanner();
212
+ resolve({ ScanResult: decodedText });
213
+ };
214
+ const OSBarcodeWebScannerErrorCallback = (error) => {
215
+ if (error.indexOf('NotFoundException') === -1) {
216
+ this.stopAndHideScanner();
217
+ console.error(`[Scanner Web Error] ${error}`);
218
+ reject(error);
219
+ }
220
+ };
221
+ window.OSBarcodeWebScanner.start({ facingMode: param.facingMode }, Html5QrcodeConfig, OSBarcodeWebScannerSuccessCallback, OSBarcodeWebScannerErrorCallback);
222
+ });
223
+ }
224
+ }
225
+
226
+ var web = /*#__PURE__*/Object.freeze({
227
+ __proto__: null,
228
+ CapacitorBarcodeScannerWeb: CapacitorBarcodeScannerWeb
229
+ });
230
+
231
+ exports.CapacitorBarcodeScanner = CapacitorBarcodeScanner;
232
+ exports.CapacitorBarcodeScannerTypeHint = CapacitorBarcodeScannerTypeHint;
233
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/utils.js","esm/definitions.js","esm/index.js","esm/web.js"],"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 * 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) {\n const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.\n let styleElement = document.getElementById(styleId);\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 }\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//# sourceMappingURL=utils.js.map","import { Html5QrcodeSupportedFormats } from 'html5-qrcode';\n/**\n * Enum representing the direction of the camera to be used for barcode scanning.\n */\nexport var CapacitorBarcodeScannerCameraDirection;\n(function (CapacitorBarcodeScannerCameraDirection) {\n CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection[\"BACK\"] = 1] = \"BACK\";\n CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection[\"FRONT\"] = 2] = \"FRONT\";\n})(CapacitorBarcodeScannerCameraDirection || (CapacitorBarcodeScannerCameraDirection = {}));\n/**\n * Enum representing the orientation of the scanner during barcode scanning.\n */\nexport var CapacitorBarcodeScannerScanOrientation;\n(function (CapacitorBarcodeScannerScanOrientation) {\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"PORTRAIT\"] = 1] = \"PORTRAIT\";\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"LANDSCAPE\"] = 2] = \"LANDSCAPE\";\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"ADAPTIVE\"] = 3] = \"ADAPTIVE\";\n})(CapacitorBarcodeScannerScanOrientation || (CapacitorBarcodeScannerScanOrientation = {}));\n/**\n * Enum representing a special option to indicate that all barcode types are supported.\n */\nexport var CapacitorBarcodeScannerTypeHintALLOption;\n(function (CapacitorBarcodeScannerTypeHintALLOption) {\n CapacitorBarcodeScannerTypeHintALLOption[CapacitorBarcodeScannerTypeHintALLOption[\"ALL\"] = 17] = \"ALL\";\n})(CapacitorBarcodeScannerTypeHintALLOption || (CapacitorBarcodeScannerTypeHintALLOption = {}));\n/**\n * Extends supported formats from Html5Qrcode with a special 'ALL' option,\n * indicating support for all barcode types.\n */\nexport const CapacitorBarcodeScannerTypeHint = Object.assign(Object.assign({}, Html5QrcodeSupportedFormats), CapacitorBarcodeScannerTypeHintALLOption);\n/**\n * Enum representing the library to be used for barcode scanning on Android devices.\n */\nexport var CapacitorBarcodeScannerAndroidScanningLibrary;\n(function (CapacitorBarcodeScannerAndroidScanningLibrary) {\n CapacitorBarcodeScannerAndroidScanningLibrary[\"ZXING\"] = \"zxing\";\n CapacitorBarcodeScannerAndroidScanningLibrary[\"MLKIT\"] = \"mlkit\";\n})(CapacitorBarcodeScannerAndroidScanningLibrary || (CapacitorBarcodeScannerAndroidScanningLibrary = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nimport { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.\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('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});\nexport * from './definitions'; // Re-export all exports from the definitions file.\nexport { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects.\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Html5Qrcode } from 'html5-qrcode';\nimport { CapacitorBarcodeScannerScanOrientation } from './definitions';\n/**\n * Implements OSBarcodePlugin to provide web functionality for barcode scanning.\n */\nexport class CapacitorBarcodeScannerWeb extends WebPlugin {\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 async stopAndHideScanner() {\n console.log(window.OSBarcodeWebScanner);\n if (window.OSBarcodeWebScanner) {\n await window.OSBarcodeWebScanner.stop();\n window.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 * 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 buildScannerElement() {\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 // Inner dialog elements including the close button and scanner view\n const caposbarcodescannercontainerdialoginner = document.createElement('div');\n caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';\n const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');\n caposbarcodescannercontainerdialoginnerclose.className = 'close-button';\n caposbarcodescannercontainerdialoginnerclose.innerHTML = '&times;';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);\n const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');\n caposbarcodescannercontainerdialoginnercontainerp.innerHTML = '&nbsp;';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);\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 caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);\n caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);\n caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;\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) {\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 var _a, _b;\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: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,\n typeHint: options.hint === 17 ? undefined : options.hint,\n scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,\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 window.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 // Success and error callbacks for the scanner\n const OSBarcodeWebScannerSuccessCallback = (decodedText, _decodedResult) => {\n this.stopAndHideScanner();\n resolve({ ScanResult: decodedText });\n };\n const OSBarcodeWebScannerErrorCallback = (error) => {\n if (error.indexOf('NotFoundException') === -1) {\n this.stopAndHideScanner();\n console.error(`[Scanner Web Error] ${error}`);\n reject(error);\n }\n };\n window.OSBarcodeWebScanner.start({ facingMode: param.facingMode }, Html5QrcodeConfig, OSBarcodeWebScannerSuccessCallback, OSBarcodeWebScannerErrorCallback);\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CapacitorBarcodeScannerCameraDirection","CapacitorBarcodeScannerScanOrientation","CapacitorBarcodeScannerTypeHintALLOption","Html5QrcodeSupportedFormats","Cap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BAAoB,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;AACrD,oBAAoB,QAAQ,EAAE,SAAS;AACvC,oBAAoB,UAAU,EAAE,SAAS;AACzC,iBAAiB;AACjB,aAAa,CAAC;AACd;AACA,YAAY,MAAM,kCAAkC,GAAG,CAAC,WAAW,EAAE,cAAc,KAAK;AACxF,gBAAgB,IAAI,CAAC,kBAAkB,EAAE,CAAC;AAC1C,gBAAgB,OAAO,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AACrD,aAAa,CAAC;AACd,YAAY,MAAM,gCAAgC,GAAG,CAAC,KAAK,KAAK;AAChE,gBAAgB,IAAI,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE;AAC/D,oBAAoB,IAAI,CAAC,kBAAkB,EAAE,CAAC;AAC9C,oBAAoB,OAAO,CAAC,KAAK,CAAC,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAClE,oBAAoB,MAAM,CAAC,KAAK,CAAC,CAAC;AAClC,iBAAiB;AACjB,aAAa,CAAC;AACd,YAAY,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,iBAAiB,EAAE,kCAAkC,EAAE,gCAAgC,CAAC,CAAC;AACxK,SAAS,CAAC,CAAC;AACX,KAAK;AACL;;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,235 @@
1
+ var capacitorOSBarcode = (function (exports, core, html5Qrcode) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * Predefined CSS rules for styling barcode scanner components.
6
+ * Each object in the array defines a CSS rule, with a selector and the CSS properties to apply.
7
+ */
8
+ const barcodeScannerCss = [
9
+ { selector: '.scanner-container-display', css: 'display: block;' },
10
+ {
11
+ selector: '.scanner-dialog',
12
+ 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);',
13
+ },
14
+ {
15
+ selector: '.scanner-dialog-inner',
16
+ css: 'background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;',
17
+ },
18
+ { selector: '.close-button', css: 'color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;' },
19
+ { selector: '.close-button:hover', css: 'color: #222;' },
20
+ { selector: '.scanner-container-full-width', css: 'width: 100%;' },
21
+ ];
22
+ /**
23
+ * Dynamically applies a set of CSS rules to the document.
24
+ * If a custom style element with a specific ID does not exist, it is created and appended to the document's head.
25
+ * Existing rules in the style element are cleared before new ones are applied.
26
+ * This function supports both modern and older browsers by using `CSSStyleSheet.insertRule` and `textContent` respectively.
27
+ *
28
+ * @param {Array<{selector: string, css: string}>} cssRules - An array of objects containing CSS selectors and styles to apply.
29
+ */
30
+ function applyCss(cssRules) {
31
+ const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.
32
+ let styleElement = document.getElementById(styleId);
33
+ if (!styleElement) {
34
+ // Create and append a new style element if it does not exist.
35
+ styleElement = document.createElement('style');
36
+ styleElement.type = 'text/css';
37
+ styleElement.id = styleId;
38
+ document.head.appendChild(styleElement);
39
+ }
40
+ if (styleElement.sheet) {
41
+ // Clear existing CSS rules.
42
+ while (styleElement.sheet.cssRules.length) {
43
+ styleElement.sheet.deleteRule(0);
44
+ }
45
+ // Insert new CSS rules.
46
+ for (const { selector, css } of cssRules) {
47
+ styleElement.sheet.insertRule(`${selector} { ${css} }`);
48
+ }
49
+ }
50
+ else {
51
+ // Fallback for older browsers using textContent.
52
+ styleElement.textContent = '';
53
+ for (const { selector, css } of cssRules) {
54
+ styleElement.textContent += `${selector} { ${css} }`;
55
+ }
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Enum representing the direction of the camera to be used for barcode scanning.
61
+ */
62
+ exports.CapacitorBarcodeScannerCameraDirection = void 0;
63
+ (function (CapacitorBarcodeScannerCameraDirection) {
64
+ CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["BACK"] = 1] = "BACK";
65
+ CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection["FRONT"] = 2] = "FRONT";
66
+ })(exports.CapacitorBarcodeScannerCameraDirection || (exports.CapacitorBarcodeScannerCameraDirection = {}));
67
+ /**
68
+ * Enum representing the orientation of the scanner during barcode scanning.
69
+ */
70
+ exports.CapacitorBarcodeScannerScanOrientation = void 0;
71
+ (function (CapacitorBarcodeScannerScanOrientation) {
72
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["PORTRAIT"] = 1] = "PORTRAIT";
73
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["LANDSCAPE"] = 2] = "LANDSCAPE";
74
+ CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation["ADAPTIVE"] = 3] = "ADAPTIVE";
75
+ })(exports.CapacitorBarcodeScannerScanOrientation || (exports.CapacitorBarcodeScannerScanOrientation = {}));
76
+ /**
77
+ * Enum representing a special option to indicate that all barcode types are supported.
78
+ */
79
+ exports.CapacitorBarcodeScannerTypeHintALLOption = void 0;
80
+ (function (CapacitorBarcodeScannerTypeHintALLOption) {
81
+ CapacitorBarcodeScannerTypeHintALLOption[CapacitorBarcodeScannerTypeHintALLOption["ALL"] = 17] = "ALL";
82
+ })(exports.CapacitorBarcodeScannerTypeHintALLOption || (exports.CapacitorBarcodeScannerTypeHintALLOption = {}));
83
+ /**
84
+ * Extends supported formats from Html5Qrcode with a special 'ALL' option,
85
+ * indicating support for all barcode types.
86
+ */
87
+ const CapacitorBarcodeScannerTypeHint = Object.assign(Object.assign({}, html5Qrcode.Html5QrcodeSupportedFormats), exports.CapacitorBarcodeScannerTypeHintALLOption);
88
+ /**
89
+ * Enum representing the library to be used for barcode scanning on Android devices.
90
+ */
91
+ exports.CapacitorBarcodeScannerAndroidScanningLibrary = void 0;
92
+ (function (CapacitorBarcodeScannerAndroidScanningLibrary) {
93
+ CapacitorBarcodeScannerAndroidScanningLibrary["ZXING"] = "zxing";
94
+ CapacitorBarcodeScannerAndroidScanningLibrary["MLKIT"] = "mlkit";
95
+ })(exports.CapacitorBarcodeScannerAndroidScanningLibrary || (exports.CapacitorBarcodeScannerAndroidScanningLibrary = {}));
96
+
97
+ /**
98
+ * Registers the `OSBarcode` plugin with Capacitor.
99
+ * For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
100
+ * This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
101
+ */
102
+ const CapacitorBarcodeScanner = core.registerPlugin('CapacitorBarcodeScanner', {
103
+ web: () => {
104
+ applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.
105
+ return Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.
106
+ },
107
+ });
108
+
109
+ /**
110
+ * Implements OSBarcodePlugin to provide web functionality for barcode scanning.
111
+ */
112
+ class CapacitorBarcodeScannerWeb extends core.WebPlugin {
113
+ /**
114
+ * Stops the barcode scanner and hides its UI.
115
+ * @private
116
+ * @returns {Promise<void>} A promise that resolves when the scanner has stopped and its UI is hidden.
117
+ */
118
+ async stopAndHideScanner() {
119
+ console.log(window.OSBarcodeWebScanner);
120
+ if (window.OSBarcodeWebScanner) {
121
+ await window.OSBarcodeWebScanner.stop();
122
+ window.OSBarcodeWebScanner = null;
123
+ }
124
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
+ document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'none';
126
+ }
127
+ /**
128
+ * Builds the HTML elements necessary for the barcode scanner UI.
129
+ * This method checks if the scanner container exists before creating it to avoid duplicates.
130
+ * It also sets up the close button to stop and hide the scanner on click.
131
+ * @private
132
+ */
133
+ buildScannerElement() {
134
+ if (document.getElementById('cap-os-barcode-scanner-container')) {
135
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
136
+ document.getElementById('cap-os-barcode-scanner-container').className = 'scanner-container-display';
137
+ return;
138
+ }
139
+ // Create and configure scanner container elements
140
+ const caposbarcodescannercontainer = document.body.appendChild(document.createElement('div'));
141
+ caposbarcodescannercontainer.id = 'cap-os-barcode-scanner-container';
142
+ const caposbarcodescannercontainerdialog = document.createElement('div');
143
+ caposbarcodescannercontainerdialog.id = 'cap-os-barcode-scanner-container-dialog';
144
+ caposbarcodescannercontainerdialog.className = 'scanner-dialog';
145
+ // Inner dialog elements including the close button and scanner view
146
+ const caposbarcodescannercontainerdialoginner = document.createElement('div');
147
+ caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';
148
+ const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');
149
+ caposbarcodescannercontainerdialoginnerclose.className = 'close-button';
150
+ caposbarcodescannercontainerdialoginnerclose.innerHTML = '&times;';
151
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);
152
+ const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');
153
+ caposbarcodescannercontainerdialoginnercontainerp.innerHTML = '&nbsp;';
154
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);
155
+ const caposbarcodescannercontainerdialoginnercontainer = document.createElement('div');
156
+ caposbarcodescannercontainerdialoginnercontainer.className = 'scanner-container-full-width';
157
+ caposbarcodescannercontainerdialoginnercontainer.id = 'cap-os-barcode-scanner-container-scanner';
158
+ caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainer);
159
+ caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);
160
+ caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);
161
+ caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;
162
+ }
163
+ /**
164
+ * Initiates a barcode scan using the user's camera and HTML5 QR code scanner.
165
+ * Displays the scanner UI and waits for a scan to complete or fail.
166
+ * @param {OSBarcodeScanOptions} options Configuration options for the scan, including camera direction and UI preferences.
167
+ * @returns {Promise<OSBarcodeScanResult>} A promise that resolves with the scan result or rejects with an error.
168
+ */
169
+ async scanBarcode(options) {
170
+ this.buildScannerElement();
171
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
172
+ document.getElementById('cap-os-barcode-scanner-container-dialog').style.display = 'block';
173
+ return new Promise((resolve, reject) => {
174
+ var _a, _b;
175
+ const param = {
176
+ facingMode: options.cameraDirection === 1 ? 'environment' : 'user',
177
+ hasScannerButton: false,
178
+ scanButton: options.scanButton === undefined ? false : options.scanButton,
179
+ showScanLine: false,
180
+ scanInstructions: options.scanInstructions ? options.scanInstructions : '',
181
+ orientation: options.scanOrientation
182
+ ? options.scanOrientation
183
+ : exports.CapacitorBarcodeScannerScanOrientation.PORTRAIT,
184
+ showCameraSelection: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,
185
+ typeHint: options.hint === 17 ? undefined : options.hint,
186
+ scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,
187
+ };
188
+ // Set up and start the scanner
189
+ const scannerElement = document.getElementById('cap-os-barcode-scanner-container-scanner');
190
+ if (!scannerElement) {
191
+ throw new Error('Scanner Element is required for web');
192
+ }
193
+ window.OSBarcodeWebScanner = new html5Qrcode.Html5Qrcode(scannerElement.id);
194
+ const Html5QrcodeConfig = {
195
+ fps: param.scannerFPS,
196
+ qrbox: scannerElement.getBoundingClientRect().width * (9 / 16) - 10,
197
+ aspectRatio: 16 / 9,
198
+ videoConstraints: {
199
+ focusMode: 'continuous',
200
+ height: { min: 576, ideal: 1920 },
201
+ deviceId: undefined,
202
+ facingMode: undefined,
203
+ },
204
+ };
205
+ // Success and error callbacks for the scanner
206
+ const OSBarcodeWebScannerSuccessCallback = (decodedText, _decodedResult) => {
207
+ this.stopAndHideScanner();
208
+ resolve({ ScanResult: decodedText });
209
+ };
210
+ const OSBarcodeWebScannerErrorCallback = (error) => {
211
+ if (error.indexOf('NotFoundException') === -1) {
212
+ this.stopAndHideScanner();
213
+ console.error(`[Scanner Web Error] ${error}`);
214
+ reject(error);
215
+ }
216
+ };
217
+ window.OSBarcodeWebScanner.start({ facingMode: param.facingMode }, Html5QrcodeConfig, OSBarcodeWebScannerSuccessCallback, OSBarcodeWebScannerErrorCallback);
218
+ });
219
+ }
220
+ }
221
+
222
+ var web = /*#__PURE__*/Object.freeze({
223
+ __proto__: null,
224
+ CapacitorBarcodeScannerWeb: CapacitorBarcodeScannerWeb
225
+ });
226
+
227
+ exports.CapacitorBarcodeScanner = CapacitorBarcodeScanner;
228
+ exports.CapacitorBarcodeScannerTypeHint = CapacitorBarcodeScannerTypeHint;
229
+
230
+ Object.defineProperty(exports, '__esModule', { value: true });
231
+
232
+ return exports;
233
+
234
+ })({}, capacitorExports, html5Qrcode);
235
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/utils.js","esm/definitions.js","esm/index.js","esm/web.js"],"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 * 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) {\n const styleId = 'custom-style-os-cap-barcode'; // Unique identifier for the style element.\n let styleElement = document.getElementById(styleId);\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 }\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//# sourceMappingURL=utils.js.map","import { Html5QrcodeSupportedFormats } from 'html5-qrcode';\n/**\n * Enum representing the direction of the camera to be used for barcode scanning.\n */\nexport var CapacitorBarcodeScannerCameraDirection;\n(function (CapacitorBarcodeScannerCameraDirection) {\n CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection[\"BACK\"] = 1] = \"BACK\";\n CapacitorBarcodeScannerCameraDirection[CapacitorBarcodeScannerCameraDirection[\"FRONT\"] = 2] = \"FRONT\";\n})(CapacitorBarcodeScannerCameraDirection || (CapacitorBarcodeScannerCameraDirection = {}));\n/**\n * Enum representing the orientation of the scanner during barcode scanning.\n */\nexport var CapacitorBarcodeScannerScanOrientation;\n(function (CapacitorBarcodeScannerScanOrientation) {\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"PORTRAIT\"] = 1] = \"PORTRAIT\";\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"LANDSCAPE\"] = 2] = \"LANDSCAPE\";\n CapacitorBarcodeScannerScanOrientation[CapacitorBarcodeScannerScanOrientation[\"ADAPTIVE\"] = 3] = \"ADAPTIVE\";\n})(CapacitorBarcodeScannerScanOrientation || (CapacitorBarcodeScannerScanOrientation = {}));\n/**\n * Enum representing a special option to indicate that all barcode types are supported.\n */\nexport var CapacitorBarcodeScannerTypeHintALLOption;\n(function (CapacitorBarcodeScannerTypeHintALLOption) {\n CapacitorBarcodeScannerTypeHintALLOption[CapacitorBarcodeScannerTypeHintALLOption[\"ALL\"] = 17] = \"ALL\";\n})(CapacitorBarcodeScannerTypeHintALLOption || (CapacitorBarcodeScannerTypeHintALLOption = {}));\n/**\n * Extends supported formats from Html5Qrcode with a special 'ALL' option,\n * indicating support for all barcode types.\n */\nexport const CapacitorBarcodeScannerTypeHint = Object.assign(Object.assign({}, Html5QrcodeSupportedFormats), CapacitorBarcodeScannerTypeHintALLOption);\n/**\n * Enum representing the library to be used for barcode scanning on Android devices.\n */\nexport var CapacitorBarcodeScannerAndroidScanningLibrary;\n(function (CapacitorBarcodeScannerAndroidScanningLibrary) {\n CapacitorBarcodeScannerAndroidScanningLibrary[\"ZXING\"] = \"zxing\";\n CapacitorBarcodeScannerAndroidScanningLibrary[\"MLKIT\"] = \"mlkit\";\n})(CapacitorBarcodeScannerAndroidScanningLibrary || (CapacitorBarcodeScannerAndroidScanningLibrary = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nimport { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.\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('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});\nexport * from './definitions'; // Re-export all exports from the definitions file.\nexport { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects.\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Html5Qrcode } from 'html5-qrcode';\nimport { CapacitorBarcodeScannerScanOrientation } from './definitions';\n/**\n * Implements OSBarcodePlugin to provide web functionality for barcode scanning.\n */\nexport class CapacitorBarcodeScannerWeb extends WebPlugin {\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 async stopAndHideScanner() {\n console.log(window.OSBarcodeWebScanner);\n if (window.OSBarcodeWebScanner) {\n await window.OSBarcodeWebScanner.stop();\n window.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 * 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 buildScannerElement() {\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 // Inner dialog elements including the close button and scanner view\n const caposbarcodescannercontainerdialoginner = document.createElement('div');\n caposbarcodescannercontainerdialoginner.className = 'scanner-dialog-inner';\n const caposbarcodescannercontainerdialoginnerclose = document.createElement('span');\n caposbarcodescannercontainerdialoginnerclose.className = 'close-button';\n caposbarcodescannercontainerdialoginnerclose.innerHTML = '&times;';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnerclose);\n const caposbarcodescannercontainerdialoginnercontainerp = document.createElement('p');\n caposbarcodescannercontainerdialoginnercontainerp.innerHTML = '&nbsp;';\n caposbarcodescannercontainerdialoginner.appendChild(caposbarcodescannercontainerdialoginnercontainerp);\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 caposbarcodescannercontainerdialog.appendChild(caposbarcodescannercontainerdialoginner);\n caposbarcodescannercontainer.appendChild(caposbarcodescannercontainerdialog);\n caposbarcodescannercontainerdialoginnerclose.onclick = this.stopAndHideScanner;\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) {\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 var _a, _b;\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: ((_a = options.web) === null || _a === void 0 ? void 0 : _a.showCameraSelection) ? options.web.showCameraSelection : false,\n typeHint: options.hint === 17 ? undefined : options.hint,\n scannerFPS: ((_b = options.web) === null || _b === void 0 ? void 0 : _b.scannerFPS) ? options.web.scannerFPS : 50,\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 window.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 // Success and error callbacks for the scanner\n const OSBarcodeWebScannerSuccessCallback = (decodedText, _decodedResult) => {\n this.stopAndHideScanner();\n resolve({ ScanResult: decodedText });\n };\n const OSBarcodeWebScannerErrorCallback = (error) => {\n if (error.indexOf('NotFoundException') === -1) {\n this.stopAndHideScanner();\n console.error(`[Scanner Web Error] ${error}`);\n reject(error);\n }\n };\n window.OSBarcodeWebScanner.start({ facingMode: param.facingMode }, Html5QrcodeConfig, OSBarcodeWebScannerSuccessCallback, OSBarcodeWebScannerErrorCallback);\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CapacitorBarcodeScannerCameraDirection","CapacitorBarcodeScannerScanOrientation","CapacitorBarcodeScannerTypeHintALLOption","Html5QrcodeSupportedFormats","CapacitorBarcodeScannerAndroidScanningLibrary","registerPlugin","WebPlugin","Html5Qrcode"],"mappings":";;;IAAA;IACA;IACA;IACA;IACO,MAAM,iBAAiB,GAAG;IACjC,IAAI,EAAE,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,iBAAiB,EAAE;IACtE,IAAI;IACJ,QAAQ,QAAQ,EAAE,iBAAiB;IACnC,QAAQ,GAAG,EAAE,8IAA8I;IAC3J,KAAK;IACL,IAAI;IACJ,QAAQ,QAAQ,EAAE,uBAAuB;IACzC,QAAQ,GAAG,EAAE,gGAAgG;IAC7G,KAAK;IACL,IAAI,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AM,gCAAgC,GAAG,CAAC,KAAK,KAAK;IAChE,gBAAgB,IAAI,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE;IAC/D,oBAAoB,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9C,oBAAoB,OAAO,CAAC,KAAK,CAAC,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAClE,oBAAoB,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,iBAAiB;IACjB,aAAa,CAAC;IACd,YAAY,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,iBAAiB,EAAE,kCAAkC,EAAE,gCAAgC,CAAC,CAAC;IACxK,SAAS,CAAC,CAAC;IACX,KAAK;IACL;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,10 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for Plugin.
4
+ FOUNDATION_EXPORT double PluginVersionNumber;
5
+
6
+ //! Project version string for Plugin.
7
+ FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
+
@@ -0,0 +1,8 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(CapacitorBarcodeScannerPlugin, "CapacitorBarcodeScanner",
7
+ CAP_PLUGIN_METHOD(scanBarcode, CAPPluginReturnPromise);
8
+ )
@@ -0,0 +1,48 @@
1
+ // swiftlint:disable line_length
2
+ import Foundation
3
+ import Capacitor
4
+ import OSBarcodeLib
5
+
6
+ @objc(CapacitorBarcodeScannerPlugin)
7
+ public class CapacitorBarcodeScannerPlugin: CAPPlugin {
8
+ var manager: OSBARCManagerProtocol?
9
+
10
+ override public func load() {
11
+ guard let viewController = self.bridge?.viewController else {
12
+ CAPLog.print("Error (Barcode Plugin Load): Capacitor bridge or viewController is not initialized.")
13
+ return
14
+ }
15
+
16
+ self.manager = OSBARCManagerFactory.createManager(with: viewController)
17
+ }
18
+
19
+ @objc func scanBarcode(_ call: CAPPluginCall) {
20
+ if self.manager == nil {
21
+ self.load()
22
+ }
23
+
24
+ guard let manager = self.manager else {
25
+ call.reject("Capacitor bridge or viewController is not initialized.")
26
+ return
27
+ }
28
+
29
+ guard let argumentsData = try? JSONSerialization.data(withJSONObject: call.jsObjectRepresentation),
30
+ let scanArguments = try? JSONDecoder().decode(OSBarcodeScanArgumentsModel.self, from: argumentsData) else {
31
+ call.reject("Error decoding scan arguments")
32
+ return
33
+ }
34
+
35
+ Task {
36
+ do {
37
+ let scannedBarcode = try await manager.scanBarcode(with: scanArguments.scanInstructions, scanArguments.scanButtonText, scanArguments.cameraDirection, and: scanArguments.scanOrientation)
38
+ call.resolve(["ScanResult": scannedBarcode])
39
+ } catch OSBARCManagerError.cameraAccessDenied {
40
+ call.reject("Camera access denied")
41
+ } catch OSBARCManagerError.scanningCancelled {
42
+ call.reject("Scanning cancelled")
43
+ } catch {
44
+ call.reject("An unexpected error occurred: \(error.localizedDescription)")
45
+ }
46
+ }
47
+ }
48
+ }