@scr2em/capacitor-scanner 6.0.21 → 6.0.22

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/README.md CHANGED
@@ -26,7 +26,7 @@ npx cap sync
26
26
  * [`removeAllListeners()`](#removealllisteners)
27
27
  * [`enableObjectDetection(...)`](#enableobjectdetection)
28
28
  * [`disableObjectDetection()`](#disableobjectdetection)
29
- * [`enableBarcodeDetection()`](#enablebarcodedetection)
29
+ * [`enableBarcodeDetection(...)`](#enablebarcodedetection)
30
30
  * [`disableBarcodeDetection()`](#disablebarcodedetection)
31
31
  * [`zoom(...)`](#zoom)
32
32
  * [Type Aliases](#type-aliases)
@@ -183,12 +183,12 @@ removeAllListeners() => any
183
183
  ### enableObjectDetection(...)
184
184
 
185
185
  ```typescript
186
- enableObjectDetection({ types }: ObjectDetectionOptions) => any
186
+ enableObjectDetection(options: ObjectDetectionOptions) => any
187
187
  ```
188
188
 
189
- | Param | Type |
190
- | --------- | ------------------------------------------------------------------------- |
191
- | **`__0`** | <code><a href="#objectdetectionoptions">ObjectDetectionOptions</a></code> |
189
+ | Param | Type |
190
+ | ------------- | ------------------------------------------------------------------------- |
191
+ | **`options`** | <code><a href="#objectdetectionoptions">ObjectDetectionOptions</a></code> |
192
192
 
193
193
  **Returns:** <code>any</code>
194
194
 
@@ -206,13 +206,17 @@ disableObjectDetection() => any
206
206
  --------------------
207
207
 
208
208
 
209
- ### enableBarcodeDetection()
209
+ ### enableBarcodeDetection(...)
210
210
 
211
211
  ```typescript
212
- enableBarcodeDetection() => any
212
+ enableBarcodeDetection(options?: BarcodeDetectionOptions | undefined) => any
213
213
  ```
214
214
 
215
- Enable barcode detection. This will start detecting barcodes and drawing overlays.
215
+ Enable barcode detection. This will start detecting barcodes.
216
+
217
+ | Param | Type | Description |
218
+ | ------------- | --------------------------------------------------------------------------- | ---------------------------------------------- |
219
+ | **`options`** | <code><a href="#barcodedetectionoptions">BarcodeDetectionOptions</a></code> | - Optional configuration for barcode detection |
216
220
 
217
221
  **Returns:** <code>any</code>
218
222
 
@@ -254,7 +258,7 @@ Set the camera zoom level.
254
258
 
255
259
  #### StartOptions
256
260
 
257
- <code>{ /** * Barcode formats to detect when barcodeDetection is enabled. */ formats?: BarcodeFormat[]; /** * Camera direction to use. Defaults to 'BACK'. */ cameraDirection?: 'BACK' | 'FRONT'; /** * Enable barcode detection on start. Defaults to false. * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events. */ barcodeDetection?: boolean; /** * Enable object detection (business card) on start. Defaults to false. * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events. */ objectDetection?: boolean; }</code>
261
+ <code>{ /** * Barcode formats to detect when barcodeDetection is enabled. */ formats?: BarcodeFormat[]; /** * Camera direction to use. Defaults to 'BACK'. */ cameraDirection?: 'BACK' | 'FRONT'; /** * Enable barcode detection on start. Defaults to false. * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events. */ barcodeDetection?: boolean; /** * Whether to show the highlight overlay for detected barcodes. Defaults to false. * Only applies when barcodeDetection is true. */ barcodeHighlight?: boolean; /** * Enable object detection (business card) on start. Defaults to false. * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events. */ objectDetection?: boolean; /** * Whether to show the highlight overlay for detected business cards. Defaults to true. * Only applies when objectDetection is true. */ objectHighlight?: boolean; }</code>
258
262
 
259
263
 
260
264
  #### CapturePhotoOptions
@@ -289,7 +293,12 @@ Set the camera zoom level.
289
293
 
290
294
  #### ObjectDetectionOptions
291
295
 
292
- <code>{ /** * Detection types to enable. Only 'businessCard' is supported. * For barcode detection, use enableBarcodeDetection() instead. */ types: ('businessCard')[], /** * Optional padding ratio to apply around detected rectangles when cropping. * Value must be between 0 and 1, where: * - 0 = no padding * - 1 = 100% padding (not recommended) * Default is 0.01 (1%) if not specified. */ paddingRatio?: number }</code>
296
+ <code>{ /** * Detection types to enable. Only 'businessCard' is supported. * For barcode detection, use enableBarcodeDetection() instead. */ types: ('businessCard')[], /** * Optional padding ratio to apply around detected rectangles when cropping. * Value must be between 0 and 1, where: * - 0 = no padding * - 1 = 100% padding (not recommended) * Default is 0.01 (1%) if not specified. */ paddingRatio?: number, /** * Whether to show the highlight overlay for detected business cards. * Defaults to true. */ showHighlight?: boolean }</code>
297
+
298
+
299
+ #### BarcodeDetectionOptions
300
+
301
+ <code>{ /** * Whether to show the highlight overlay for detected barcodes. * Defaults to false. */ showHighlight?: boolean; }</code>
293
302
 
294
303
 
295
304
  #### ZoomOptions
@@ -108,6 +108,7 @@ public class CapacitorScannerPlugin extends Plugin {
108
108
  private int currentLensFacing = CameraSelector.LENS_FACING_BACK;
109
109
 
110
110
  private final Set<String> enabledDetectionTypes = new HashSet<>();
111
+ private final Set<String> enabledHighlightTypes = new HashSet<>(); // Controls overlay display
111
112
  private float paddingRatio = 0.01f; // Default padding ratio of 1%
112
113
  // Add detection history for temporal smoothing
113
114
  private java.util.List<DetectionResult> recentDetectionResults = new java.util.ArrayList<>();
@@ -186,6 +187,9 @@ public class CapacitorScannerPlugin extends Plugin {
186
187
  // Read detection options (defaults to false)
187
188
  boolean enableBarcodeDetection = call.getBoolean("barcodeDetection", false);
188
189
  boolean enableObjectDetection = call.getBoolean("objectDetection", false);
190
+ // Read highlight options (barcode defaults to false, businessCard defaults to true)
191
+ boolean enableBarcodeHighlight = call.getBoolean("barcodeHighlight", false);
192
+ boolean enableObjectHighlight = call.getBoolean("objectHighlight", true);
189
193
 
190
194
  getActivity().runOnUiThread(() -> {
191
195
  // Stop any existing session first
@@ -196,11 +200,17 @@ public class CapacitorScannerPlugin extends Plugin {
196
200
  // Enable barcode detection if requested
197
201
  if (enableBarcodeDetection) {
198
202
  enabledDetectionTypes.add("barcode");
203
+ if (enableBarcodeHighlight) {
204
+ enabledHighlightTypes.add("barcode");
205
+ }
199
206
  }
200
207
 
201
208
  // Enable object detection (businessCard) if requested
202
209
  if (enableObjectDetection) {
203
210
  enabledDetectionTypes.add("businessCard");
211
+ if (enableObjectHighlight) {
212
+ enabledHighlightTypes.add("businessCard");
213
+ }
204
214
  }
205
215
 
206
216
  try {
@@ -413,8 +423,11 @@ public class CapacitorScannerPlugin extends Plugin {
413
423
  scanner.process(image)
414
424
  .addOnSuccessListener(executor, barcodes -> {
415
425
  processBarcodes(barcodes);
416
- displayDetectedBarcodes(barcodes, imageProxy.getWidth(), imageProxy.getHeight(),
417
- imageProxy.getImageInfo().getRotationDegrees());
426
+ // Only display barcode overlay if highlight is enabled
427
+ if (enabledHighlightTypes.contains("barcode")) {
428
+ displayDetectedBarcodes(barcodes, imageProxy.getWidth(), imageProxy.getHeight(),
429
+ imageProxy.getImageInfo().getRotationDegrees());
430
+ }
418
431
  })
419
432
  .addOnFailureListener(executor, e -> {
420
433
  echo("Failed to process image for barcode: " + e.getMessage());
@@ -525,7 +538,8 @@ public class CapacitorScannerPlugin extends Plugin {
525
538
  // This runs for both freshly detected rectangles and reused detection results
526
539
  final DetectionResult finalResult = detectionResult;
527
540
  getActivity().runOnUiThread(() -> {
528
- if (enabledDetectionTypes.contains("businessCard")) {
541
+ // Only display rectangle overlay if highlight is enabled
542
+ if (enabledHighlightTypes.contains("businessCard")) {
529
543
  // Show the rectangles
530
544
  displayDetectedRectangles(finalResult,
531
545
  imageProxy.getWidth(),
@@ -1065,34 +1079,35 @@ public class CapacitorScannerPlugin extends Plugin {
1065
1079
  detectionOverlay = null;
1066
1080
  }
1067
1081
 
1068
- scannedCodesVotes.clear();
1069
- isScanning.set(false);
1070
-
1071
- showWebViewBackground();
1082
+ scannedCodesVotes.clear();
1083
+ isScanning.set(false);
1072
1084
 
1073
- if (orientationEventListener != null) {
1074
- orientationEventListener.disable();
1075
- orientationEventListener = null;
1076
- }
1085
+ showWebViewBackground();
1077
1086
 
1078
- // Reset all detection state variables
1079
- lastGoodRectangleTime = 0;
1080
- lastGoodDetectionResult = null;
1081
- lastRectangleNotificationTime = 0;
1082
- lastRectangleProcessingTime = 0;
1083
- lastRectangleDetectionTime = 0;
1087
+ if (orientationEventListener != null) {
1088
+ orientationEventListener.disable();
1089
+ orientationEventListener = null;
1090
+ }
1084
1091
 
1085
- // Clear detection histories and caches
1086
- enabledDetectionTypes.clear();
1087
- recentDetectionResults.clear();
1088
- detectionHistory.clear();
1089
- lastGoodRects = Collections.emptyList();
1092
+ // Reset all detection state variables
1093
+ lastGoodRectangleTime = 0;
1094
+ lastGoodDetectionResult = null;
1095
+ lastRectangleNotificationTime = 0;
1096
+ lastRectangleProcessingTime = 0;
1097
+ lastRectangleDetectionTime = 0;
1098
+
1099
+ // Clear detection histories and caches
1100
+ enabledDetectionTypes.clear();
1101
+ enabledHighlightTypes.clear();
1102
+ recentDetectionResults.clear();
1103
+ detectionHistory.clear();
1104
+ lastGoodRects = Collections.emptyList();
1090
1105
 
1091
- // Clear overlay rectangles
1092
- synchronized (overlayLock) {
1093
- currentBarcodeRects.clear();
1094
- currentRectangleRects.clear();
1095
- }
1106
+ // Clear overlay rectangles
1107
+ synchronized (overlayLock) {
1108
+ currentBarcodeRects.clear();
1109
+ currentRectangleRects.clear();
1110
+ }
1096
1111
 
1097
1112
  echo("All detection state variables have been reset");
1098
1113
  }
@@ -1122,6 +1137,9 @@ public class CapacitorScannerPlugin extends Plugin {
1122
1137
  });
1123
1138
  }
1124
1139
 
1140
+ // Read showHighlight option (defaults to true for businessCard)
1141
+ boolean showHighlight = call.getBoolean("showHighlight", true);
1142
+
1125
1143
  // Only accept "businessCard" type - barcode detection is handled separately
1126
1144
  List<String> addedTypes = new ArrayList<>();
1127
1145
  try {
@@ -1129,6 +1147,9 @@ public class CapacitorScannerPlugin extends Plugin {
1129
1147
  String type = types.getString(i);
1130
1148
  if ("businessCard".equals(type)) {
1131
1149
  enabledDetectionTypes.add(type);
1150
+ if (showHighlight) {
1151
+ enabledHighlightTypes.add(type);
1152
+ }
1132
1153
  addedTypes.add(type);
1133
1154
  }
1134
1155
  }
@@ -1175,7 +1196,7 @@ public class CapacitorScannerPlugin extends Plugin {
1175
1196
  // this should not happen
1176
1197
  }
1177
1198
 
1178
- if (enabledDetectionTypes.contains("businessCard")) {
1199
+ if (enabledHighlightTypes.contains("businessCard")) {
1179
1200
  getActivity().runOnUiThread(() -> {
1180
1201
  setupDetectionOverlay();
1181
1202
  });
@@ -1186,8 +1207,9 @@ public class CapacitorScannerPlugin extends Plugin {
1186
1207
 
1187
1208
  @PluginMethod
1188
1209
  public void disableObjectDetection(PluginCall call) {
1189
- // Only remove businessCard - barcode detection is handled separately
1210
+ // Remove businessCard from both detection and highlight types
1190
1211
  enabledDetectionTypes.remove("businessCard");
1212
+ enabledHighlightTypes.remove("businessCard");
1191
1213
 
1192
1214
  // Reset businessCard detection state
1193
1215
  detectionHistory.clear();
@@ -1558,11 +1580,15 @@ public class CapacitorScannerPlugin extends Plugin {
1558
1580
  @PluginMethod
1559
1581
  public void enableBarcodeDetection(PluginCall call) {
1560
1582
  echo("enableBarcodeDetection");
1561
- enabledDetectionTypes.add("barcode");
1583
+ boolean showHighlight = call.getBoolean("showHighlight", false);
1562
1584
 
1563
- getActivity().runOnUiThread(() -> {
1564
- setupDetectionOverlay();
1565
- });
1585
+ enabledDetectionTypes.add("barcode");
1586
+ if (showHighlight) {
1587
+ enabledHighlightTypes.add("barcode");
1588
+ getActivity().runOnUiThread(() -> {
1589
+ setupDetectionOverlay();
1590
+ });
1591
+ }
1566
1592
 
1567
1593
  JSObject result = new JSObject();
1568
1594
  result.put("enabled", true);
@@ -1573,6 +1599,7 @@ public class CapacitorScannerPlugin extends Plugin {
1573
1599
  public void disableBarcodeDetection(PluginCall call) {
1574
1600
  echo("disableBarcodeDetection");
1575
1601
  enabledDetectionTypes.remove("barcode");
1602
+ enabledHighlightTypes.remove("barcode");
1576
1603
 
1577
1604
  // Clear cached barcodes
1578
1605
  scannedCodesVotes.clear();
package/dist/docs.json CHANGED
@@ -171,10 +171,10 @@
171
171
  },
172
172
  {
173
173
  "name": "enableObjectDetection",
174
- "signature": "({ types }: ObjectDetectionOptions) => any",
174
+ "signature": "(options: ObjectDetectionOptions) => any",
175
175
  "parameters": [
176
176
  {
177
- "name": "__0",
177
+ "name": "options",
178
178
  "docs": "",
179
179
  "type": "ObjectDetectionOptions"
180
180
  }
@@ -199,12 +199,25 @@
199
199
  },
200
200
  {
201
201
  "name": "enableBarcodeDetection",
202
- "signature": "() => any",
203
- "parameters": [],
202
+ "signature": "(options?: BarcodeDetectionOptions | undefined) => any",
203
+ "parameters": [
204
+ {
205
+ "name": "options",
206
+ "docs": "- Optional configuration for barcode detection",
207
+ "type": "BarcodeDetectionOptions | undefined"
208
+ }
209
+ ],
204
210
  "returns": "any",
205
- "tags": [],
206
- "docs": "Enable barcode detection. This will start detecting barcodes and drawing overlays.",
207
- "complexTypes": [],
211
+ "tags": [
212
+ {
213
+ "name": "param",
214
+ "text": "options - Optional configuration for barcode detection"
215
+ }
216
+ ],
217
+ "docs": "Enable barcode detection. This will start detecting barcodes.",
218
+ "complexTypes": [
219
+ "BarcodeDetectionOptions"
220
+ ],
208
221
  "slug": "enablebarcodedetection"
209
222
  },
210
223
  {
@@ -326,7 +339,7 @@
326
339
  "docs": "",
327
340
  "types": [
328
341
  {
329
- "text": "{\n /**\n * Barcode formats to detect when barcodeDetection is enabled.\n */\n formats?: BarcodeFormat[];\n /**\n * Camera direction to use. Defaults to 'BACK'.\n */\n cameraDirection?: 'BACK' | 'FRONT';\n /**\n * Enable barcode detection on start. Defaults to false.\n * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events.\n */\n barcodeDetection?: boolean;\n /**\n * Enable object detection (business card) on start. Defaults to false.\n * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events.\n */\n objectDetection?: boolean;\n}",
342
+ "text": "{\n /**\n * Barcode formats to detect when barcodeDetection is enabled.\n */\n formats?: BarcodeFormat[];\n /**\n * Camera direction to use. Defaults to 'BACK'.\n */\n cameraDirection?: 'BACK' | 'FRONT';\n /**\n * Enable barcode detection on start. Defaults to false.\n * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events.\n */\n barcodeDetection?: boolean;\n /**\n * Whether to show the highlight overlay for detected barcodes. Defaults to false.\n * Only applies when barcodeDetection is true.\n */\n barcodeHighlight?: boolean;\n /**\n * Enable object detection (business card) on start. Defaults to false.\n * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events.\n */\n objectDetection?: boolean;\n /**\n * Whether to show the highlight overlay for detected business cards. Defaults to true.\n * Only applies when objectDetection is true.\n */\n objectHighlight?: boolean;\n}",
330
343
  "complexTypes": [
331
344
  "BarcodeFormat"
332
345
  ]
@@ -405,7 +418,18 @@
405
418
  "docs": "",
406
419
  "types": [
407
420
  {
408
- "text": "{\n /**\n * Detection types to enable. Only 'businessCard' is supported.\n * For barcode detection, use enableBarcodeDetection() instead.\n */\n types: ('businessCard')[],\n /**\n * Optional padding ratio to apply around detected rectangles when cropping.\n * Value must be between 0 and 1, where:\n * - 0 = no padding\n * - 1 = 100% padding (not recommended)\n * Default is 0.01 (1%) if not specified.\n */\n paddingRatio?: number\n}",
421
+ "text": "{\n /**\n * Detection types to enable. Only 'businessCard' is supported.\n * For barcode detection, use enableBarcodeDetection() instead.\n */\n types: ('businessCard')[],\n /**\n * Optional padding ratio to apply around detected rectangles when cropping.\n * Value must be between 0 and 1, where:\n * - 0 = no padding\n * - 1 = 100% padding (not recommended)\n * Default is 0.01 (1%) if not specified.\n */\n paddingRatio?: number,\n /**\n * Whether to show the highlight overlay for detected business cards.\n * Defaults to true.\n */\n showHighlight?: boolean\n}",
422
+ "complexTypes": []
423
+ }
424
+ ]
425
+ },
426
+ {
427
+ "name": "BarcodeDetectionOptions",
428
+ "slug": "barcodedetectionoptions",
429
+ "docs": "",
430
+ "types": [
431
+ {
432
+ "text": "{\n /**\n * Whether to show the highlight overlay for detected barcodes.\n * Defaults to false.\n */\n showHighlight?: boolean;\n}",
409
433
  "complexTypes": []
410
434
  }
411
435
  ]
@@ -17,15 +17,16 @@ export interface CapacitorScannerPlugin {
17
17
  addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void): Promise<void>;
18
18
  addListener(event: 'rectangleDetected', listenerFunc: (result: RectangleDetectedEvent) => void): Promise<void>;
19
19
  removeAllListeners(): Promise<void>;
20
- enableObjectDetection({ types }: ObjectDetectionOptions): Promise<void>;
20
+ enableObjectDetection(options: ObjectDetectionOptions): Promise<void>;
21
21
  disableObjectDetection(): Promise<{
22
22
  enabled: false;
23
23
  types: [];
24
24
  }>;
25
25
  /**
26
- * Enable barcode detection. This will start detecting barcodes and drawing overlays.
26
+ * Enable barcode detection. This will start detecting barcodes.
27
+ * @param options - Optional configuration for barcode detection
27
28
  */
28
- enableBarcodeDetection(): Promise<{
29
+ enableBarcodeDetection(options?: BarcodeDetectionOptions): Promise<{
29
30
  enabled: true;
30
31
  }>;
31
32
  /**
@@ -40,6 +41,13 @@ export interface CapacitorScannerPlugin {
40
41
  */
41
42
  zoom(options: ZoomOptions): Promise<ZoomResult>;
42
43
  }
44
+ export declare type BarcodeDetectionOptions = {
45
+ /**
46
+ * Whether to show the highlight overlay for detected barcodes.
47
+ * Defaults to false.
48
+ */
49
+ showHighlight?: boolean;
50
+ };
43
51
  export declare type ObjectDetectionOptions = {
44
52
  /**
45
53
  * Detection types to enable. Only 'businessCard' is supported.
@@ -54,6 +62,11 @@ export declare type ObjectDetectionOptions = {
54
62
  * Default is 0.01 (1%) if not specified.
55
63
  */
56
64
  paddingRatio?: number;
65
+ /**
66
+ * Whether to show the highlight overlay for detected business cards.
67
+ * Defaults to true.
68
+ */
69
+ showHighlight?: boolean;
57
70
  };
58
71
  export declare type StartOptions = {
59
72
  /**
@@ -69,11 +82,21 @@ export declare type StartOptions = {
69
82
  * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events.
70
83
  */
71
84
  barcodeDetection?: boolean;
85
+ /**
86
+ * Whether to show the highlight overlay for detected barcodes. Defaults to false.
87
+ * Only applies when barcodeDetection is true.
88
+ */
89
+ barcodeHighlight?: boolean;
72
90
  /**
73
91
  * Enable object detection (business card) on start. Defaults to false.
74
92
  * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events.
75
93
  */
76
94
  objectDetection?: boolean;
95
+ /**
96
+ * Whether to show the highlight overlay for detected business cards. Defaults to true.
97
+ * Only applies when objectDetection is true.
98
+ */
99
+ objectHighlight?: boolean;
77
100
  };
78
101
  export declare type BarcodeScannedEvent = {
79
102
  scannedCode: string;
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA0HA,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,qCAAoB,CAAA;IACpB,2CAA0B,CAAA;IAC1B,+BAAc,CAAA;IACd,iCAAgB,CAAA;IAChB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,+BAAc,CAAA;AAChB,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB","sourcesContent":["export interface CapacitorScannerPlugin {\n /**\n * Start the camera preview with optional barcode and object detection.\n * @param options - Configuration options for the camera and detection\n */\n start(options?: StartOptions): Promise<void>;\n\n /**\n * Stop the camera preview and all detection.\n */\n stop(): Promise<void>;\n\n openSettings(): Promise<void>;\n\n capturePhoto(options?: CapturePhotoOptions): Promise<CapturePhotoResult>;\n\n checkPermissions(): Promise<PermissionsResult>;\n\n requestPermissions(): Promise<PermissionsResult>;\n\n flipCamera(): Promise<void>;\n\n toggleFlash(): Promise<FlashResult>;\n\n addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void): Promise<void>;\n\n addListener(event: 'rectangleDetected', listenerFunc: (result: RectangleDetectedEvent) => void): Promise<void>;\n\n removeAllListeners(): Promise<void>;\n\n enableObjectDetection({ types }: ObjectDetectionOptions): Promise<void>;\n\n disableObjectDetection(): Promise<{ enabled: false, types: [] }>;\n\n /**\n * Enable barcode detection. This will start detecting barcodes and drawing overlays.\n */\n enableBarcodeDetection(): Promise<{ enabled: true }>;\n\n /**\n * Disable barcode detection. This will stop detecting barcodes and clear cached barcodes.\n */\n disableBarcodeDetection(): Promise<{ enabled: false }>;\n\n /**\n * Set the camera zoom level.\n * @param options - The zoom options containing the level (1, 2, or 3)\n */\n zoom(options: ZoomOptions): Promise<ZoomResult>;\n}\n\nexport type ObjectDetectionOptions = {\n /**\n * Detection types to enable. Only 'businessCard' is supported.\n * For barcode detection, use enableBarcodeDetection() instead.\n */\n types: ('businessCard')[],\n /**\n * Optional padding ratio to apply around detected rectangles when cropping.\n * Value must be between 0 and 1, where:\n * - 0 = no padding\n * - 1 = 100% padding (not recommended)\n * Default is 0.01 (1%) if not specified.\n */\n paddingRatio?: number\n}\n\nexport type StartOptions = {\n /**\n * Barcode formats to detect when barcodeDetection is enabled.\n */\n formats?: BarcodeFormat[];\n /**\n * Camera direction to use. Defaults to 'BACK'.\n */\n cameraDirection?: 'BACK' | 'FRONT';\n /**\n * Enable barcode detection on start. Defaults to false.\n * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events.\n */\n barcodeDetection?: boolean;\n /**\n * Enable object detection (business card) on start. Defaults to false.\n * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events.\n */\n objectDetection?: boolean;\n};\n\nexport type BarcodeScannedEvent = { scannedCode: string; format: string };\n\n\nexport type RectangleDetectedEvent = {\n detected: true\n};\n\nexport type CapturePhotoOptions = {\n /**\n * The desired quality of the captured image, expressed as a value between 0.0 (lowest quality, smallest file size)\n * and 1.0 (highest quality, largest file size). Defaults to 1.0.\n * This parameter directly influences the compression level of the resulting JPEG image.\n */\n qualityRatio?: number;\n};\n\nexport type PermissionsResult = { camera: 'prompt' | 'denied' | 'granted' };\n\nexport type CapturePhotoResult = { imageBase64: string };\n\nexport type FlashResult = { enabled: boolean };\n\nexport type ZoomOptions = {\n /**\n * The zoom level to set. Must be 1, 2, or 3.\n * - 1 = 1.0x (no zoom)\n * - 2 = 2.0x\n * - 3 = 3.0x\n */\n level: 1 | 2 | 3;\n};\n\nexport type ZoomResult = { level: number };\n\nexport enum BarcodeFormat {\n Aztec = 'AZTEC',\n Code39 = 'CODE_39',\n Code93 = 'CODE_93',\n Code128 = 'CODE_128',\n DataMatrix = 'DATA_MATRIX',\n Ean8 = 'EAN_8',\n Ean13 = 'EAN_13',\n Itf14 = 'ITF14',\n Pdf417 = 'PDF_417',\n QrCode = 'QR_CODE',\n UpcE = 'UPC_E',\n}\n\ndeclare global {\n interface PluginRegistry {\n QRScanner: CapacitorScannerPlugin;\n }\n}"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkJA,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,qCAAoB,CAAA;IACpB,2CAA0B,CAAA;IAC1B,+BAAc,CAAA;IACd,iCAAgB,CAAA;IAChB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,+BAAc,CAAA;AAChB,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB","sourcesContent":["export interface CapacitorScannerPlugin {\n /**\n * Start the camera preview with optional barcode and object detection.\n * @param options - Configuration options for the camera and detection\n */\n start(options?: StartOptions): Promise<void>;\n\n /**\n * Stop the camera preview and all detection.\n */\n stop(): Promise<void>;\n\n openSettings(): Promise<void>;\n\n capturePhoto(options?: CapturePhotoOptions): Promise<CapturePhotoResult>;\n\n checkPermissions(): Promise<PermissionsResult>;\n\n requestPermissions(): Promise<PermissionsResult>;\n\n flipCamera(): Promise<void>;\n\n toggleFlash(): Promise<FlashResult>;\n\n addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void): Promise<void>;\n\n addListener(event: 'rectangleDetected', listenerFunc: (result: RectangleDetectedEvent) => void): Promise<void>;\n\n removeAllListeners(): Promise<void>;\n\n enableObjectDetection(options: ObjectDetectionOptions): Promise<void>;\n\n disableObjectDetection(): Promise<{ enabled: false, types: [] }>;\n\n /**\n * Enable barcode detection. This will start detecting barcodes.\n * @param options - Optional configuration for barcode detection\n */\n enableBarcodeDetection(options?: BarcodeDetectionOptions): Promise<{ enabled: true }>;\n\n /**\n * Disable barcode detection. This will stop detecting barcodes and clear cached barcodes.\n */\n disableBarcodeDetection(): Promise<{ enabled: false }>;\n\n /**\n * Set the camera zoom level.\n * @param options - The zoom options containing the level (1, 2, or 3)\n */\n zoom(options: ZoomOptions): Promise<ZoomResult>;\n}\n\nexport type BarcodeDetectionOptions = {\n /**\n * Whether to show the highlight overlay for detected barcodes.\n * Defaults to false.\n */\n showHighlight?: boolean;\n}\n\nexport type ObjectDetectionOptions = {\n /**\n * Detection types to enable. Only 'businessCard' is supported.\n * For barcode detection, use enableBarcodeDetection() instead.\n */\n types: ('businessCard')[],\n /**\n * Optional padding ratio to apply around detected rectangles when cropping.\n * Value must be between 0 and 1, where:\n * - 0 = no padding\n * - 1 = 100% padding (not recommended)\n * Default is 0.01 (1%) if not specified.\n */\n paddingRatio?: number,\n /**\n * Whether to show the highlight overlay for detected business cards.\n * Defaults to true.\n */\n showHighlight?: boolean\n}\n\nexport type StartOptions = {\n /**\n * Barcode formats to detect when barcodeDetection is enabled.\n */\n formats?: BarcodeFormat[];\n /**\n * Camera direction to use. Defaults to 'BACK'.\n */\n cameraDirection?: 'BACK' | 'FRONT';\n /**\n * Enable barcode detection on start. Defaults to false.\n * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events.\n */\n barcodeDetection?: boolean;\n /**\n * Whether to show the highlight overlay for detected barcodes. Defaults to false.\n * Only applies when barcodeDetection is true.\n */\n barcodeHighlight?: boolean;\n /**\n * Enable object detection (business card) on start. Defaults to false.\n * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events.\n */\n objectDetection?: boolean;\n /**\n * Whether to show the highlight overlay for detected business cards. Defaults to true.\n * Only applies when objectDetection is true.\n */\n objectHighlight?: boolean;\n};\n\nexport type BarcodeScannedEvent = { scannedCode: string; format: string };\n\n\nexport type RectangleDetectedEvent = {\n detected: true\n};\n\nexport type CapturePhotoOptions = {\n /**\n * The desired quality of the captured image, expressed as a value between 0.0 (lowest quality, smallest file size)\n * and 1.0 (highest quality, largest file size). Defaults to 1.0.\n * This parameter directly influences the compression level of the resulting JPEG image.\n */\n qualityRatio?: number;\n};\n\nexport type PermissionsResult = { camera: 'prompt' | 'denied' | 'granted' };\n\nexport type CapturePhotoResult = { imageBase64: string };\n\nexport type FlashResult = { enabled: boolean };\n\nexport type ZoomOptions = {\n /**\n * The zoom level to set. Must be 1, 2, or 3.\n * - 1 = 1.0x (no zoom)\n * - 2 = 2.0x\n * - 3 = 3.0x\n */\n level: 1 | 2 | 3;\n};\n\nexport type ZoomResult = { level: number };\n\nexport enum BarcodeFormat {\n Aztec = 'AZTEC',\n Code39 = 'CODE_39',\n Code93 = 'CODE_93',\n Code128 = 'CODE_128',\n DataMatrix = 'DATA_MATRIX',\n Ean8 = 'EAN_8',\n Ean13 = 'EAN_13',\n Itf14 = 'ITF14',\n Pdf417 = 'PDF_417',\n QrCode = 'QR_CODE',\n UpcE = 'UPC_E',\n}\n\ndeclare global {\n interface PluginRegistry {\n QRScanner: CapacitorScannerPlugin;\n }\n}"]}
@@ -58,7 +58,9 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
58
58
  private var lastBarcodeDetectionTime: Date?
59
59
  private let rectangleVisibilityTimeout: TimeInterval = 1.0 // Time in seconds before considering rectangle no longer visible
60
60
 
61
- // Object detection highlighting properties
61
+ // Detection state (controls what detection runs)
62
+ private var enabledDetectionTypes: Set<String> = []
63
+ // Highlight state (controls what overlay is shown)
62
64
  private var enabledHighlightTypes: Set<String> = []
63
65
  private var overlayView: UIView?
64
66
  private var barcodeOverlays: [CAShapeLayer] = []
@@ -119,10 +121,16 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
119
121
  return
120
122
  }
121
123
 
124
+ let showHighlight = call.getBool("showHighlight", true)
125
+
122
126
  DispatchQueue.main.async {
123
- // Add businessCard to enabled types (don't clear existing barcode detection)
124
- self.enabledHighlightTypes.insert("businessCard")
125
- self.setupOverlayView()
127
+ // Add businessCard to enabled detection types
128
+ self.enabledDetectionTypes.insert("businessCard")
129
+ // Add to highlight types if showHighlight is true (default)
130
+ if showHighlight {
131
+ self.enabledHighlightTypes.insert("businessCard")
132
+ self.setupOverlayView()
133
+ }
126
134
 
127
135
  call.resolve([
128
136
  "enabled": true,
@@ -133,7 +141,8 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
133
141
 
134
142
  @objc func disableObjectDetection(_ call: CAPPluginCall) {
135
143
  DispatchQueue.main.async {
136
- // Only remove businessCard - barcode detection is handled separately
144
+ // Remove businessCard from both detection and highlight types
145
+ self.enabledDetectionTypes.remove("businessCard")
137
146
  self.enabledHighlightTypes.remove("businessCard")
138
147
 
139
148
  // Clear only businessCard overlay (not barcode overlay)
@@ -319,7 +328,7 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
319
328
  self.capturePhotoCall = call
320
329
 
321
330
  // If business card detection is enabled, wait for 1 second before capturing
322
- if self.enabledHighlightTypes.contains("businessCard") {
331
+ if self.enabledDetectionTypes.contains("businessCard") {
323
332
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
324
333
  photoOutput.capturePhoto(with: photoSettings, delegate: self)
325
334
  }
@@ -341,7 +350,7 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
341
350
  }
342
351
 
343
352
  // Check if object detection is enabled and we have a detected rectangle with sufficient confidence
344
- if self.enabledHighlightTypes.contains("businessCard"),
353
+ if self.enabledDetectionTypes.contains("businessCard"),
345
354
  let detectedRect = self.lastDetectedRectangle { // Only use rectangles with sufficient confidence
346
355
  // If we have a snapshot from the detection, use it directly
347
356
  if let snapshot = detectedRect.snapshot {
@@ -514,6 +523,9 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
514
523
  // Read detection options (defaults to false)
515
524
  let enableBarcodeDetection = call.getBool("barcodeDetection", false)
516
525
  let enableObjectDetection = call.getBool("objectDetection", false)
526
+ // Read highlight options (barcode defaults to false, businessCard defaults to true)
527
+ let enableBarcodeHighlight = call.getBool("barcodeHighlight", false)
528
+ let enableObjectHighlight = call.getBool("objectHighlight", true)
517
529
 
518
530
  DispatchQueue.main.async {
519
531
  // Stop any existing session first (must be on main thread for UI operations)
@@ -525,12 +537,18 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
525
537
 
526
538
  // Enable barcode detection if requested
527
539
  if enableBarcodeDetection {
528
- self.enabledHighlightTypes.insert("barcode")
540
+ self.enabledDetectionTypes.insert("barcode")
541
+ if enableBarcodeHighlight {
542
+ self.enabledHighlightTypes.insert("barcode")
543
+ }
529
544
  }
530
545
 
531
546
  // Enable object detection (businessCard) if requested
532
547
  if enableObjectDetection {
533
- self.enabledHighlightTypes.insert("businessCard")
548
+ self.enabledDetectionTypes.insert("businessCard")
549
+ if enableObjectHighlight {
550
+ self.enabledHighlightTypes.insert("businessCard")
551
+ }
534
552
  }
535
553
 
536
554
  // Start monitoring device motion
@@ -646,6 +664,7 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
646
664
  self.scannedCodesVotes.clear()
647
665
  self.clearAllOverlays()
648
666
  self.showWebViewBackground()
667
+ self.enabledDetectionTypes.removeAll()
649
668
  self.enabledHighlightTypes.removeAll()
650
669
  self.lastRectangleDetectionTime = nil
651
670
  self.lastBarcodeDetectionTime = nil
@@ -1045,9 +1064,14 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
1045
1064
  }
1046
1065
 
1047
1066
  @objc func enableBarcodeDetection(_ call: CAPPluginCall) {
1067
+ let showHighlight = call.getBool("showHighlight", false)
1068
+
1048
1069
  DispatchQueue.main.async {
1049
- self.enabledHighlightTypes.insert("barcode")
1050
- self.setupOverlayView()
1070
+ self.enabledDetectionTypes.insert("barcode")
1071
+ if showHighlight {
1072
+ self.enabledHighlightTypes.insert("barcode")
1073
+ self.setupOverlayView()
1074
+ }
1051
1075
 
1052
1076
  call.resolve([
1053
1077
  "enabled": true,
@@ -1057,6 +1081,7 @@ public class CapacitorScannerPlugin: CAPPlugin, CAPBridgedPlugin, AVCaptureMetad
1057
1081
 
1058
1082
  @objc func disableBarcodeDetection(_ call: CAPPluginCall) {
1059
1083
  DispatchQueue.main.async {
1084
+ self.enabledDetectionTypes.remove("barcode")
1060
1085
  self.enabledHighlightTypes.remove("barcode")
1061
1086
 
1062
1087
  // Clear cached barcodes
@@ -1150,12 +1175,12 @@ extension CapacitorScannerPlugin: AVCaptureVideoDataOutputSampleBufferDelegate {
1150
1175
  var requests: [VNRequest] = []
1151
1176
 
1152
1177
  // Only include barcode detection if enabled
1153
- if self.enabledHighlightTypes.contains("barcode") {
1178
+ if self.enabledDetectionTypes.contains("barcode") {
1154
1179
  requests.append(self.barcodeDetectionRequest)
1155
1180
  }
1156
1181
 
1157
- // Add rectangle detection if business card highlighting is enabled
1158
- if self.enabledHighlightTypes.contains("businessCard") {
1182
+ // Add rectangle detection if business card detection is enabled
1183
+ if self.enabledDetectionTypes.contains("businessCard") {
1159
1184
  requests.append(self.rectangleDetectionRequest)
1160
1185
  }
1161
1186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scr2em/capacitor-scanner",
3
- "version": "6.0.21",
3
+ "version": "6.0.22",
4
4
  "description": "scan codes",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",