-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
27 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import { registerPlugin } from '@capacitor/core'; | ||
|
||
import type { CapacitorBarcodeScannerPlugin } from './definitions'; // Importing the interface for type checking. | ||
import { | ||
CapacitorBarcodeScannerCameraDirection, | ||
CapacitorBarcodeScannerScanOrientation, | ||
type CapacitorBarcodeScannerOptions, | ||
type CapacitorBarcodeScannerPlugin, | ||
type CapacitorBarcodeScannerScanResult, | ||
} from './definitions'; // Importing the interface for type checking. | ||
import { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS. | ||
|
||
/** | ||
* Registers the `OSBarcode` plugin with Capacitor. | ||
* For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation. | ||
* This allows for lazy loading of the web code only when needed, optimizing overall bundle size. | ||
*/ | ||
const CapacitorBarcodeScanner = registerPlugin<CapacitorBarcodeScannerPlugin>('CapacitorBarcodeScanner', { | ||
const CapacitorBarcodeScannerImpl = registerPlugin<CapacitorBarcodeScannerPlugin>('CapacitorBarcodeScanner', { | ||
web: () => { | ||
applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner. | ||
return import('./web').then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it. | ||
}, | ||
}); | ||
|
||
class CapacitorBarcodeScanner { | ||
public static async scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult> { | ||
options.scanInstructions = options.scanInstructions || ' '; // Ensure scanInstructions is at least a space. | ||
options.scanButton = options.scanButton || false; // Set scanButton to false if not provided. | ||
options.scanText = options.scanText || ' '; // Ensure scanText is at least a space. | ||
options.cameraDirection = options.cameraDirection || CapacitorBarcodeScannerCameraDirection.BACK; // Set cameraDirection to 'BACK' if not provided. | ||
options.scanOrientation = options.scanOrientation || CapacitorBarcodeScannerScanOrientation.ADAPTIVE; // Set scanOrientation to 'ADAPTIVE' if not provided. | ||
return CapacitorBarcodeScannerImpl.scanBarcode(options); | ||
} | ||
} | ||
|
||
export { CapacitorBarcodeScanner }; // Export the `CapacitorBarcodeScanner` class. | ||
export * from './definitions'; // Re-export all exports from the definitions file. | ||
export { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects. |