@capgo/capacitor-document-scanner 7.2.5 → 8.1.0

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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/Package.swift CHANGED
@@ -3,14 +3,14 @@ import PackageDescription
3
3
 
4
4
  let package = Package(
5
5
  name: "CapgoCapacitorDocumentScanner",
6
- platforms: [.iOS(.v14)],
6
+ platforms: [.iOS(.v15)],
7
7
  products: [
8
8
  .library(
9
9
  name: "CapgoCapacitorDocumentScanner",
10
10
  targets: ["DocumentScannerPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
package/README.md CHANGED
@@ -73,12 +73,15 @@ Opens the device camera and starts the document scanning experience.
73
73
 
74
74
  #### ScanDocumentOptions
75
75
 
76
- | Prop | Type | Description | Default |
77
- | ------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
78
- | **`croppedImageQuality`** | <code>number</code> | Android only: quality of the cropped image from 0 - 100 (100 is best). | <code>100</code> |
79
- | **`letUserAdjustCrop`** | <code>boolean</code> | Android only: allow the user to adjust the detected crop before saving. Disabling this forces single-document capture. | <code>true</code> |
80
- | **`maxNumDocuments`** | <code>number</code> | Android only: maximum number of documents the user can scan. | <code>24</code> |
81
- | **`responseType`** | <code><a href="#responsetype">ResponseType</a></code> | Format to return scanned images in (file paths or base64 strings). | <code>ResponseType.ImageFilePath</code> |
76
+ | Prop | Type | Description | Default |
77
+ | ------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
78
+ | **`croppedImageQuality`** | <code>number</code> | Android only: quality of the cropped image from 0 - 100 (100 is best). | <code>100</code> |
79
+ | **`letUserAdjustCrop`** | <code>boolean</code> | Android only: allow the user to adjust the detected crop before saving. Disabling this forces single-document capture. | <code>true</code> |
80
+ | **`maxNumDocuments`** | <code>number</code> | Android only: maximum number of documents the user can scan. | <code>24</code> |
81
+ | **`responseType`** | <code><a href="#responsetype">ResponseType</a></code> | Format to return scanned images in (file paths or base64 strings). | <code>ResponseType.ImageFilePath</code> |
82
+ | **`brightness`** | <code>number</code> | Brightness adjustment applied to scanned images. Range: -255 to 255 (0 = no change, positive = brighter, negative = darker) Useful for compensating low-light scans. | <code>0</code> |
83
+ | **`contrast`** | <code>number</code> | Contrast adjustment applied to scanned images. Range: 0.0 to 10.0 (1.0 = no change, &gt;1 = more contrast, &lt;1 = less contrast) Helps improve text clarity in poorly lit scans. | <code>1.0</code> |
84
+ | **`scannerMode`** | <code><a href="#scannermode">ScannerMode</a></code> | Android only: scanner mode that controls ML Kit features and filters. - 'base': Basic scan with crop/rotate, no filters or ML cleaning - 'base_with_filter': Adds grayscale and auto-enhancement filters - 'full': All features including ML-based image cleaning (erases stains, fingers, etc.) | <code>ScannerMode.Full</code> |
82
85
 
83
86
 
84
87
  ### Enums
@@ -99,6 +102,15 @@ Opens the device camera and starts the document scanning experience.
99
102
  | **`Base64`** | <code>'base64'</code> | Return scanned images as base64-encoded strings. |
100
103
  | **`ImageFilePath`** | <code>'imageFilePath'</code> | Return scanned images as file paths on disk. |
101
104
 
105
+
106
+ #### ScannerMode
107
+
108
+ | Members | Value | Description |
109
+ | -------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------- |
110
+ | **`Base`** | <code>'base'</code> | Basic document scanning with crop and rotate features only. No filters or ML-based enhancements. |
111
+ | **`BaseWithFilter`** | <code>'base_with_filter'</code> | Basic features plus automatic filters (grayscale, auto-enhancement). |
112
+ | **`Full`** | <code>'full'</code> | Full feature set including ML-based image cleaning. Automatically removes stains, fingers, and other artifacts. |
113
+
102
114
  </docgen-api>
103
115
 
104
116
  ## credits
@@ -1,8 +1,8 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
6
  }
7
7
 
8
8
  buildscript {
@@ -11,18 +11,18 @@ buildscript {
11
11
  mavenCentral()
12
12
  }
13
13
  dependencies {
14
- classpath 'com.android.tools.build:gradle:8.7.2'
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
15
  }
16
16
  }
17
17
 
18
18
  apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
- namespace "app.capgo.plugin.documentscanner"
22
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
21
+ namespace = "app.capgo.plugin.documentscanner"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
23
  defaultConfig {
24
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
26
26
  versionCode 1
27
27
  versionName "1.0"
28
28
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -34,7 +34,7 @@ android {
34
34
  }
35
35
  }
36
36
  lintOptions {
37
- abortOnError false
37
+ abortOnError = false
38
38
  }
39
39
  compileOptions {
40
40
  sourceCompatibility JavaVersion.VERSION_21
@@ -5,6 +5,10 @@ import android.content.Context;
5
5
  import android.content.Intent;
6
6
  import android.graphics.Bitmap;
7
7
  import android.graphics.BitmapFactory;
8
+ import android.graphics.Canvas;
9
+ import android.graphics.ColorMatrix;
10
+ import android.graphics.ColorMatrixColorFilter;
11
+ import android.graphics.Paint;
8
12
  import android.net.Uri;
9
13
  import android.util.Base64;
10
14
  import androidx.activity.result.ActivityResult;
@@ -43,6 +47,10 @@ public class DocumentScannerPlugin extends Plugin {
43
47
  private static final String RESPONSE_TYPE_BASE64 = "base64";
44
48
  private static final String RESPONSE_TYPE_FILE_PATH = "imageFilePath";
45
49
 
50
+ private static final String SCANNER_MODE_BASE = "base";
51
+ private static final String SCANNER_MODE_BASE_WITH_FILTER = "base_with_filter";
52
+ private static final String SCANNER_MODE_FULL = "full";
53
+
46
54
  private ActivityResultLauncher<IntentSenderRequest> scannerLauncher;
47
55
  private PendingScan pendingScan;
48
56
 
@@ -51,11 +59,15 @@ public class DocumentScannerPlugin extends Plugin {
51
59
  private final String callId;
52
60
  private final String responseType;
53
61
  private final int quality;
62
+ private final float brightness;
63
+ private final float contrast;
54
64
 
55
- PendingScan(String callId, String responseType, int quality) {
65
+ PendingScan(String callId, String responseType, int quality, float brightness, float contrast) {
56
66
  this.callId = callId;
57
67
  this.responseType = responseType;
58
68
  this.quality = quality;
69
+ this.brightness = brightness;
70
+ this.contrast = contrast;
59
71
  }
60
72
  }
61
73
 
@@ -90,20 +102,23 @@ public class DocumentScannerPlugin extends Plugin {
90
102
  String responseType = normalizeResponseType(call.getString("responseType"));
91
103
  int pageLimit = clamp(call.getInt("maxNumDocuments", 24), 1, 24);
92
104
  boolean allowAdjustCrop = call.getBoolean("letUserAdjustCrop", true);
105
+ float brightness = clampFloat(call.getFloat("brightness", 0f), -255f, 255f);
106
+ float contrast = clampFloat(call.getFloat("contrast", 1f), 0f, 10f);
107
+ String scannerMode = normalizeScannerMode(call.getString("scannerMode"));
93
108
 
94
109
  GmsDocumentScannerOptions.Builder optionsBuilder = new GmsDocumentScannerOptions.Builder()
95
110
  .setGalleryImportAllowed(false)
96
111
  .setResultFormats(GmsDocumentScannerOptions.RESULT_FORMAT_JPEG)
97
112
  .setPageLimit(pageLimit);
98
113
 
99
- optionsBuilder.setScannerMode(
100
- allowAdjustCrop ? GmsDocumentScannerOptions.SCANNER_MODE_FULL : GmsDocumentScannerOptions.SCANNER_MODE_BASE
101
- );
114
+ // Determine scanner mode based on scannerMode parameter and letUserAdjustCrop
115
+ int mlKitScannerMode = determineScannerMode(scannerMode, allowAdjustCrop);
116
+ optionsBuilder.setScannerMode(mlKitScannerMode);
102
117
 
103
118
  GmsDocumentScanner scanner = GmsDocumentScanning.getClient(optionsBuilder.build());
104
119
 
105
120
  bridge.saveCall(call);
106
- pendingScan = new PendingScan(call.getCallbackId(), responseType, quality);
121
+ pendingScan = new PendingScan(call.getCallbackId(), responseType, quality, brightness, contrast);
107
122
 
108
123
  scanner
109
124
  .getStartScanIntent(activity)
@@ -194,8 +209,11 @@ public class DocumentScannerPlugin extends Plugin {
194
209
  }
195
210
 
196
211
  byte[] imageBytes = readBytesFromUri(imageUri);
197
- if (scan.quality < 100) {
198
- imageBytes = reencodeImage(imageBytes, scan.quality);
212
+
213
+ // Apply brightness/contrast adjustments if needed
214
+ boolean needsAdjustment = scan.brightness != 0f || scan.contrast != 1f;
215
+ if (needsAdjustment || scan.quality < 100) {
216
+ imageBytes = processImage(imageBytes, scan.quality, scan.brightness, scan.contrast);
199
217
  }
200
218
 
201
219
  if (RESPONSE_TYPE_BASE64.equals(scan.responseType)) {
@@ -225,21 +243,55 @@ public class DocumentScannerPlugin extends Plugin {
225
243
  }
226
244
  }
227
245
 
228
- private byte[] reencodeImage(byte[] source, int quality) throws IOException {
246
+ private byte[] processImage(byte[] source, int quality, float brightness, float contrast) throws IOException {
229
247
  Bitmap bitmap = BitmapFactory.decodeByteArray(source, 0, source.length);
230
248
  if (bitmap == null) {
231
249
  throw new IOException("Unable to decode scanned image.");
232
250
  }
233
- try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
234
- if (!bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)) {
235
- throw new IOException("Unable to compress scanned image.");
251
+
252
+ try {
253
+ // Apply brightness and contrast adjustments if needed
254
+ if (brightness != 0f || contrast != 1f) {
255
+ bitmap = applyBrightnessContrast(bitmap, brightness, contrast);
256
+ }
257
+
258
+ // Compress with quality setting
259
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
260
+ if (!bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)) {
261
+ throw new IOException("Unable to compress scanned image.");
262
+ }
263
+ return outputStream.toByteArray();
236
264
  }
237
- return outputStream.toByteArray();
238
265
  } finally {
239
266
  bitmap.recycle();
240
267
  }
241
268
  }
242
269
 
270
+ /**
271
+ * Applies brightness and contrast adjustments to a bitmap using ColorMatrix.
272
+ * @param bitmap The source bitmap
273
+ * @param brightness Brightness adjustment (-255 to 255, 0 = no change)
274
+ * @param contrast Contrast adjustment (0.0 to 10.0, 1.0 = no change)
275
+ * @return A new bitmap with adjustments applied
276
+ */
277
+ private Bitmap applyBrightnessContrast(Bitmap bitmap, float brightness, float contrast) {
278
+ // Create ColorMatrix for brightness and contrast
279
+ ColorMatrix colorMatrix = new ColorMatrix(
280
+ new float[] { contrast, 0, 0, 0, brightness, 0, contrast, 0, 0, brightness, 0, 0, contrast, 0, brightness, 0, 0, 0, 1, 0 }
281
+ );
282
+
283
+ // Create a new bitmap with the same dimensions
284
+ Bitmap adjustedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
285
+
286
+ // Apply the color matrix
287
+ Canvas canvas = new Canvas(adjustedBitmap);
288
+ Paint paint = new Paint();
289
+ paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
290
+ canvas.drawBitmap(bitmap, 0, 0, paint);
291
+
292
+ return adjustedBitmap;
293
+ }
294
+
243
295
  private String writeImageFile(byte[] imageBytes, int pageIndex) throws IOException {
244
296
  Context context = getContext();
245
297
  if (context == null) {
@@ -281,6 +333,13 @@ public class DocumentScannerPlugin extends Plugin {
281
333
  return Math.max(min, Math.min(max, value));
282
334
  }
283
335
 
336
+ private float clampFloat(Float value, float min, float max) {
337
+ if (value == null) {
338
+ return min;
339
+ }
340
+ return Math.max(min, Math.min(max, value));
341
+ }
342
+
284
343
  private String normalizeResponseType(String value) {
285
344
  if (value == null) {
286
345
  return RESPONSE_TYPE_FILE_PATH;
@@ -292,6 +351,45 @@ public class DocumentScannerPlugin extends Plugin {
292
351
  return RESPONSE_TYPE_FILE_PATH;
293
352
  }
294
353
 
354
+ private String normalizeScannerMode(String value) {
355
+ if (value == null) {
356
+ return SCANNER_MODE_FULL;
357
+ }
358
+ String normalized = value.toLowerCase(Locale.ROOT);
359
+ if (
360
+ SCANNER_MODE_BASE.equals(normalized) || SCANNER_MODE_BASE_WITH_FILTER.equals(normalized) || SCANNER_MODE_FULL.equals(normalized)
361
+ ) {
362
+ return normalized;
363
+ }
364
+ return SCANNER_MODE_FULL;
365
+ }
366
+
367
+ /**
368
+ * Determines the ML Kit scanner mode based on scannerMode and letUserAdjustCrop settings.
369
+ * Note: letUserAdjustCrop requires SCANNER_MODE_FULL, so it takes precedence over scannerMode.
370
+ * @param scannerMode The requested scanner mode (base, base_with_filter, full)
371
+ * @param allowAdjustCrop Whether to allow manual crop adjustment
372
+ * @return The ML Kit scanner mode constant
373
+ */
374
+ private int determineScannerMode(String scannerMode, boolean allowAdjustCrop) {
375
+ // If letUserAdjustCrop is true, we must use SCANNER_MODE_FULL
376
+ // because only FULL mode supports manual crop adjustment
377
+ if (allowAdjustCrop) {
378
+ return GmsDocumentScannerOptions.SCANNER_MODE_FULL;
379
+ }
380
+
381
+ // Otherwise, use the requested scanner mode
382
+ switch (scannerMode) {
383
+ case SCANNER_MODE_BASE:
384
+ return GmsDocumentScannerOptions.SCANNER_MODE_BASE;
385
+ case SCANNER_MODE_BASE_WITH_FILTER:
386
+ return GmsDocumentScannerOptions.SCANNER_MODE_BASE_WITH_FILTER;
387
+ case SCANNER_MODE_FULL:
388
+ default:
389
+ return GmsDocumentScannerOptions.SCANNER_MODE_FULL;
390
+ }
391
+ }
392
+
295
393
  @PluginMethod
296
394
  public void getPluginVersion(final PluginCall call) {
297
395
  try {
package/dist/docs.json CHANGED
@@ -129,6 +129,44 @@
129
129
  "ResponseType"
130
130
  ],
131
131
  "type": "ResponseType"
132
+ },
133
+ {
134
+ "name": "brightness",
135
+ "tags": [
136
+ {
137
+ "text": "0",
138
+ "name": "default"
139
+ }
140
+ ],
141
+ "docs": "Brightness adjustment applied to scanned images.\nRange: -255 to 255 (0 = no change, positive = brighter, negative = darker)\nUseful for compensating low-light scans.",
142
+ "complexTypes": [],
143
+ "type": "number | undefined"
144
+ },
145
+ {
146
+ "name": "contrast",
147
+ "tags": [
148
+ {
149
+ "text": "1.0",
150
+ "name": "default"
151
+ }
152
+ ],
153
+ "docs": "Contrast adjustment applied to scanned images.\nRange: 0.0 to 10.0 (1.0 = no change, >1 = more contrast, <1 = less contrast)\nHelps improve text clarity in poorly lit scans.",
154
+ "complexTypes": [],
155
+ "type": "number | undefined"
156
+ },
157
+ {
158
+ "name": "scannerMode",
159
+ "tags": [
160
+ {
161
+ "text": "ScannerMode.Full",
162
+ "name": "default"
163
+ }
164
+ ],
165
+ "docs": "Android only: scanner mode that controls ML Kit features and filters.\n- 'base': Basic scan with crop/rotate, no filters or ML cleaning\n- 'base_with_filter': Adds grayscale and auto-enhancement filters\n- 'full': All features including ML-based image cleaning (erases stains, fingers, etc.)",
166
+ "complexTypes": [
167
+ "ScannerMode"
168
+ ],
169
+ "type": "ScannerMode"
132
170
  }
133
171
  ]
134
172
  }
@@ -169,6 +207,30 @@
169
207
  "docs": "Return scanned images as file paths on disk."
170
208
  }
171
209
  ]
210
+ },
211
+ {
212
+ "name": "ScannerMode",
213
+ "slug": "scannermode",
214
+ "members": [
215
+ {
216
+ "name": "Base",
217
+ "value": "'base'",
218
+ "tags": [],
219
+ "docs": "Basic document scanning with crop and rotate features only.\nNo filters or ML-based enhancements."
220
+ },
221
+ {
222
+ "name": "BaseWithFilter",
223
+ "value": "'base_with_filter'",
224
+ "tags": [],
225
+ "docs": "Basic features plus automatic filters (grayscale, auto-enhancement)."
226
+ },
227
+ {
228
+ "name": "Full",
229
+ "value": "'full'",
230
+ "tags": [],
231
+ "docs": "Full feature set including ML-based image cleaning.\nAutomatically removes stains, fingers, and other artifacts."
232
+ }
233
+ ]
172
234
  }
173
235
  ],
174
236
  "typeAliases": [],
@@ -26,6 +26,44 @@ export interface ScanDocumentOptions {
26
26
  * @default ResponseType.ImageFilePath
27
27
  */
28
28
  responseType?: ResponseType;
29
+ /**
30
+ * Brightness adjustment applied to scanned images.
31
+ * Range: -255 to 255 (0 = no change, positive = brighter, negative = darker)
32
+ * Useful for compensating low-light scans.
33
+ * @default 0
34
+ */
35
+ brightness?: number;
36
+ /**
37
+ * Contrast adjustment applied to scanned images.
38
+ * Range: 0.0 to 10.0 (1.0 = no change, >1 = more contrast, <1 = less contrast)
39
+ * Helps improve text clarity in poorly lit scans.
40
+ * @default 1.0
41
+ */
42
+ contrast?: number;
43
+ /**
44
+ * Android only: scanner mode that controls ML Kit features and filters.
45
+ * - 'base': Basic scan with crop/rotate, no filters or ML cleaning
46
+ * - 'base_with_filter': Adds grayscale and auto-enhancement filters
47
+ * - 'full': All features including ML-based image cleaning (erases stains, fingers, etc.)
48
+ * @default ScannerMode.Full
49
+ */
50
+ scannerMode?: ScannerMode;
51
+ }
52
+ export declare enum ScannerMode {
53
+ /**
54
+ * Basic document scanning with crop and rotate features only.
55
+ * No filters or ML-based enhancements.
56
+ */
57
+ Base = "base",
58
+ /**
59
+ * Basic features plus automatic filters (grayscale, auto-enhancement).
60
+ */
61
+ BaseWithFilter = "base_with_filter",
62
+ /**
63
+ * Full feature set including ML-based image cleaning.
64
+ * Automatically removes stains, fingers, and other artifacts.
65
+ */
66
+ Full = "full"
29
67
  }
30
68
  export declare enum ResponseType {
31
69
  /**
@@ -1,3 +1,20 @@
1
+ export var ScannerMode;
2
+ (function (ScannerMode) {
3
+ /**
4
+ * Basic document scanning with crop and rotate features only.
5
+ * No filters or ML-based enhancements.
6
+ */
7
+ ScannerMode["Base"] = "base";
8
+ /**
9
+ * Basic features plus automatic filters (grayscale, auto-enhancement).
10
+ */
11
+ ScannerMode["BaseWithFilter"] = "base_with_filter";
12
+ /**
13
+ * Full feature set including ML-based image cleaning.
14
+ * Automatically removes stains, fingers, and other artifacts.
15
+ */
16
+ ScannerMode["Full"] = "full";
17
+ })(ScannerMode || (ScannerMode = {}));
1
18
  export var ResponseType;
2
19
  (function (ResponseType) {
3
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkCA,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB;;OAEG;IACH,iCAAiB,CAAA;IAEjB;;OAEG;IACH,+CAA+B,CAAA;AACjC,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB;AAsBD,MAAM,CAAN,IAAY,0BAUX;AAVD,WAAY,0BAA0B;IACpC;;OAEG;IACH,iDAAmB,CAAA;IAEnB;;OAEG;IACH,+CAAiB,CAAA;AACnB,CAAC,EAVW,0BAA0B,KAA1B,0BAA0B,QAUrC","sourcesContent":["export interface DocumentScannerPlugin {\n /**\n * Opens the device camera and starts the document scanning experience.\n */\n scanDocument(options?: ScanDocumentOptions): Promise<ScanDocumentResponse>;\n}\n\nexport interface ScanDocumentOptions {\n /**\n * Android only: quality of the cropped image from 0 - 100 (100 is best).\n * @default 100\n */\n croppedImageQuality?: number;\n\n /**\n * Android only: allow the user to adjust the detected crop before saving.\n * Disabling this forces single-document capture.\n * @default true\n */\n letUserAdjustCrop?: boolean;\n\n /**\n * Android only: maximum number of documents the user can scan.\n * @default 24\n */\n maxNumDocuments?: number;\n\n /**\n * Format to return scanned images in (file paths or base64 strings).\n * @default ResponseType.ImageFilePath\n */\n responseType?: ResponseType;\n}\n\nexport enum ResponseType {\n /**\n * Return scanned images as base64-encoded strings.\n */\n Base64 = 'base64',\n\n /**\n * Return scanned images as file paths on disk.\n */\n ImageFilePath = 'imageFilePath',\n}\n\nexport interface ScanDocumentResponse {\n /**\n * Scanned images in the requested response format.\n */\n scannedImages?: string[];\n\n /**\n * Indicates whether the scan completed or was cancelled.\n */\n status?: ScanDocumentResponseStatus;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\nexport enum ScanDocumentResponseStatus {\n /**\n * The scan completed successfully.\n */\n Success = 'success',\n\n /**\n * The user cancelled the scan flow.\n */\n Cancel = 'cancel',\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA2DA,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB;;;OAGG;IACH,4BAAa,CAAA;IAEb;;OAEG;IACH,kDAAmC,CAAA;IAEnC;;;OAGG;IACH,4BAAa,CAAA;AACf,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB;AAED,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB;;OAEG;IACH,iCAAiB,CAAA;IAEjB;;OAEG;IACH,+CAA+B,CAAA;AACjC,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB;AAsBD,MAAM,CAAN,IAAY,0BAUX;AAVD,WAAY,0BAA0B;IACpC;;OAEG;IACH,iDAAmB,CAAA;IAEnB;;OAEG;IACH,+CAAiB,CAAA;AACnB,CAAC,EAVW,0BAA0B,KAA1B,0BAA0B,QAUrC","sourcesContent":["export interface DocumentScannerPlugin {\n /**\n * Opens the device camera and starts the document scanning experience.\n */\n scanDocument(options?: ScanDocumentOptions): Promise<ScanDocumentResponse>;\n}\n\nexport interface ScanDocumentOptions {\n /**\n * Android only: quality of the cropped image from 0 - 100 (100 is best).\n * @default 100\n */\n croppedImageQuality?: number;\n\n /**\n * Android only: allow the user to adjust the detected crop before saving.\n * Disabling this forces single-document capture.\n * @default true\n */\n letUserAdjustCrop?: boolean;\n\n /**\n * Android only: maximum number of documents the user can scan.\n * @default 24\n */\n maxNumDocuments?: number;\n\n /**\n * Format to return scanned images in (file paths or base64 strings).\n * @default ResponseType.ImageFilePath\n */\n responseType?: ResponseType;\n\n /**\n * Brightness adjustment applied to scanned images.\n * Range: -255 to 255 (0 = no change, positive = brighter, negative = darker)\n * Useful for compensating low-light scans.\n * @default 0\n */\n brightness?: number;\n\n /**\n * Contrast adjustment applied to scanned images.\n * Range: 0.0 to 10.0 (1.0 = no change, >1 = more contrast, <1 = less contrast)\n * Helps improve text clarity in poorly lit scans.\n * @default 1.0\n */\n contrast?: number;\n\n /**\n * Android only: scanner mode that controls ML Kit features and filters.\n * - 'base': Basic scan with crop/rotate, no filters or ML cleaning\n * - 'base_with_filter': Adds grayscale and auto-enhancement filters\n * - 'full': All features including ML-based image cleaning (erases stains, fingers, etc.)\n * @default ScannerMode.Full\n */\n scannerMode?: ScannerMode;\n}\n\nexport enum ScannerMode {\n /**\n * Basic document scanning with crop and rotate features only.\n * No filters or ML-based enhancements.\n */\n Base = 'base',\n\n /**\n * Basic features plus automatic filters (grayscale, auto-enhancement).\n */\n BaseWithFilter = 'base_with_filter',\n\n /**\n * Full feature set including ML-based image cleaning.\n * Automatically removes stains, fingers, and other artifacts.\n */\n Full = 'full',\n}\n\nexport enum ResponseType {\n /**\n * Return scanned images as base64-encoded strings.\n */\n Base64 = 'base64',\n\n /**\n * Return scanned images as file paths on disk.\n */\n ImageFilePath = 'imageFilePath',\n}\n\nexport interface ScanDocumentResponse {\n /**\n * Scanned images in the requested response format.\n */\n scannedImages?: string[];\n\n /**\n * Indicates whether the scan completed or was cancelled.\n */\n status?: ScanDocumentResponseStatus;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\nexport enum ScanDocumentResponseStatus {\n /**\n * The scan completed successfully.\n */\n Success = 'success',\n\n /**\n * The user cancelled the scan flow.\n */\n Cancel = 'cancel',\n}\n"]}
@@ -2,6 +2,23 @@
2
2
 
3
3
  var core = require('@capacitor/core');
4
4
 
5
+ exports.ScannerMode = void 0;
6
+ (function (ScannerMode) {
7
+ /**
8
+ * Basic document scanning with crop and rotate features only.
9
+ * No filters or ML-based enhancements.
10
+ */
11
+ ScannerMode["Base"] = "base";
12
+ /**
13
+ * Basic features plus automatic filters (grayscale, auto-enhancement).
14
+ */
15
+ ScannerMode["BaseWithFilter"] = "base_with_filter";
16
+ /**
17
+ * Full feature set including ML-based image cleaning.
18
+ * Automatically removes stains, fingers, and other artifacts.
19
+ */
20
+ ScannerMode["Full"] = "full";
21
+ })(exports.ScannerMode || (exports.ScannerMode = {}));
5
22
  exports.ResponseType = void 0;
6
23
  (function (ResponseType) {
7
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var ResponseType;\n(function (ResponseType) {\n /**\n * Return scanned images as base64-encoded strings.\n */\n ResponseType[\"Base64\"] = \"base64\";\n /**\n * Return scanned images as file paths on disk.\n */\n ResponseType[\"ImageFilePath\"] = \"imageFilePath\";\n})(ResponseType || (ResponseType = {}));\nexport var ScanDocumentResponseStatus;\n(function (ScanDocumentResponseStatus) {\n /**\n * The scan completed successfully.\n */\n ScanDocumentResponseStatus[\"Success\"] = \"success\";\n /**\n * The user cancelled the scan flow.\n */\n ScanDocumentResponseStatus[\"Cancel\"] = \"cancel\";\n})(ScanDocumentResponseStatus || (ScanDocumentResponseStatus = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst DocumentScanner = registerPlugin('DocumentScanner', {\n web: () => import('./web').then((m) => new m.DocumentScannerWeb()),\n});\nexport * from './definitions';\nexport { DocumentScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DocumentScannerWeb extends WebPlugin {\n async scanDocument(_options) {\n throw this.unimplemented('Document scanning is not supported on the web.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ResponseType","ScanDocumentResponseStatus","registerPlugin","WebPlugin"],"mappings":";;;;AAAWA;AACX,CAAC,UAAU,YAAY,EAAE;AACzB;AACA;AACA;AACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACrC;AACA;AACA;AACA,IAAI,YAAY,CAAC,eAAe,CAAC,GAAG,eAAe;AACnD,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;AAC5BC;AACX,CAAC,UAAU,0BAA0B,EAAE;AACvC;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,SAAS,CAAC,GAAG,SAAS;AACrD;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACnD,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;;ACpB9D,MAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;AAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtE,CAAC;;ACFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;AAClD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var ScannerMode;\n(function (ScannerMode) {\n /**\n * Basic document scanning with crop and rotate features only.\n * No filters or ML-based enhancements.\n */\n ScannerMode[\"Base\"] = \"base\";\n /**\n * Basic features plus automatic filters (grayscale, auto-enhancement).\n */\n ScannerMode[\"BaseWithFilter\"] = \"base_with_filter\";\n /**\n * Full feature set including ML-based image cleaning.\n * Automatically removes stains, fingers, and other artifacts.\n */\n ScannerMode[\"Full\"] = \"full\";\n})(ScannerMode || (ScannerMode = {}));\nexport var ResponseType;\n(function (ResponseType) {\n /**\n * Return scanned images as base64-encoded strings.\n */\n ResponseType[\"Base64\"] = \"base64\";\n /**\n * Return scanned images as file paths on disk.\n */\n ResponseType[\"ImageFilePath\"] = \"imageFilePath\";\n})(ResponseType || (ResponseType = {}));\nexport var ScanDocumentResponseStatus;\n(function (ScanDocumentResponseStatus) {\n /**\n * The scan completed successfully.\n */\n ScanDocumentResponseStatus[\"Success\"] = \"success\";\n /**\n * The user cancelled the scan flow.\n */\n ScanDocumentResponseStatus[\"Cancel\"] = \"cancel\";\n})(ScanDocumentResponseStatus || (ScanDocumentResponseStatus = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst DocumentScanner = registerPlugin('DocumentScanner', {\n web: () => import('./web').then((m) => new m.DocumentScannerWeb()),\n});\nexport * from './definitions';\nexport { DocumentScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DocumentScannerWeb extends WebPlugin {\n async scanDocument(_options) {\n throw this.unimplemented('Document scanning is not supported on the web.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ScannerMode","ResponseType","ScanDocumentResponseStatus","registerPlugin","WebPlugin"],"mappings":";;;;AAAWA;AACX,CAAC,UAAU,WAAW,EAAE;AACxB;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;AAChC;AACA;AACA;AACA,IAAI,WAAW,CAAC,gBAAgB,CAAC,GAAG,kBAAkB;AACtD;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;AAChC,CAAC,EAAEA,mBAAW,KAAKA,mBAAW,GAAG,EAAE,CAAC,CAAC;AAC1BC;AACX,CAAC,UAAU,YAAY,EAAE;AACzB;AACA;AACA;AACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACrC;AACA;AACA;AACA,IAAI,YAAY,CAAC,eAAe,CAAC,GAAG,eAAe;AACnD,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;AAC5BC;AACX,CAAC,UAAU,0BAA0B,EAAE;AACvC;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,SAAS,CAAC,GAAG,SAAS;AACrD;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACnD,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;;ACrC9D,MAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;AAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtE,CAAC;;ACFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;AAClD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -1,6 +1,23 @@
1
1
  var capacitorDocumentScanner = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
+ exports.ScannerMode = void 0;
5
+ (function (ScannerMode) {
6
+ /**
7
+ * Basic document scanning with crop and rotate features only.
8
+ * No filters or ML-based enhancements.
9
+ */
10
+ ScannerMode["Base"] = "base";
11
+ /**
12
+ * Basic features plus automatic filters (grayscale, auto-enhancement).
13
+ */
14
+ ScannerMode["BaseWithFilter"] = "base_with_filter";
15
+ /**
16
+ * Full feature set including ML-based image cleaning.
17
+ * Automatically removes stains, fingers, and other artifacts.
18
+ */
19
+ ScannerMode["Full"] = "full";
20
+ })(exports.ScannerMode || (exports.ScannerMode = {}));
4
21
  exports.ResponseType = void 0;
5
22
  (function (ResponseType) {
6
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var ResponseType;\n(function (ResponseType) {\n /**\n * Return scanned images as base64-encoded strings.\n */\n ResponseType[\"Base64\"] = \"base64\";\n /**\n * Return scanned images as file paths on disk.\n */\n ResponseType[\"ImageFilePath\"] = \"imageFilePath\";\n})(ResponseType || (ResponseType = {}));\nexport var ScanDocumentResponseStatus;\n(function (ScanDocumentResponseStatus) {\n /**\n * The scan completed successfully.\n */\n ScanDocumentResponseStatus[\"Success\"] = \"success\";\n /**\n * The user cancelled the scan flow.\n */\n ScanDocumentResponseStatus[\"Cancel\"] = \"cancel\";\n})(ScanDocumentResponseStatus || (ScanDocumentResponseStatus = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst DocumentScanner = registerPlugin('DocumentScanner', {\n web: () => import('./web').then((m) => new m.DocumentScannerWeb()),\n});\nexport * from './definitions';\nexport { DocumentScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DocumentScannerWeb extends WebPlugin {\n async scanDocument(_options) {\n throw this.unimplemented('Document scanning is not supported on the web.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ResponseType","ScanDocumentResponseStatus","registerPlugin","WebPlugin"],"mappings":";;;AAAWA;IACX,CAAC,UAAU,YAAY,EAAE;IACzB;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACrC;IACA;IACA;IACA,IAAI,YAAY,CAAC,eAAe,CAAC,GAAG,eAAe;IACnD,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;AAC5BC;IACX,CAAC,UAAU,0BAA0B,EAAE;IACvC;IACA;IACA;IACA,IAAI,0BAA0B,CAAC,SAAS,CAAC,GAAG,SAAS;IACrD;IACA;IACA;IACA,IAAI,0BAA0B,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACnD,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;;ACpB9D,UAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACtE,CAAC;;ICFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;IAClF,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var ScannerMode;\n(function (ScannerMode) {\n /**\n * Basic document scanning with crop and rotate features only.\n * No filters or ML-based enhancements.\n */\n ScannerMode[\"Base\"] = \"base\";\n /**\n * Basic features plus automatic filters (grayscale, auto-enhancement).\n */\n ScannerMode[\"BaseWithFilter\"] = \"base_with_filter\";\n /**\n * Full feature set including ML-based image cleaning.\n * Automatically removes stains, fingers, and other artifacts.\n */\n ScannerMode[\"Full\"] = \"full\";\n})(ScannerMode || (ScannerMode = {}));\nexport var ResponseType;\n(function (ResponseType) {\n /**\n * Return scanned images as base64-encoded strings.\n */\n ResponseType[\"Base64\"] = \"base64\";\n /**\n * Return scanned images as file paths on disk.\n */\n ResponseType[\"ImageFilePath\"] = \"imageFilePath\";\n})(ResponseType || (ResponseType = {}));\nexport var ScanDocumentResponseStatus;\n(function (ScanDocumentResponseStatus) {\n /**\n * The scan completed successfully.\n */\n ScanDocumentResponseStatus[\"Success\"] = \"success\";\n /**\n * The user cancelled the scan flow.\n */\n ScanDocumentResponseStatus[\"Cancel\"] = \"cancel\";\n})(ScanDocumentResponseStatus || (ScanDocumentResponseStatus = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst DocumentScanner = registerPlugin('DocumentScanner', {\n web: () => import('./web').then((m) => new m.DocumentScannerWeb()),\n});\nexport * from './definitions';\nexport { DocumentScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DocumentScannerWeb extends WebPlugin {\n async scanDocument(_options) {\n throw this.unimplemented('Document scanning is not supported on the web.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ScannerMode","ResponseType","ScanDocumentResponseStatus","registerPlugin","WebPlugin"],"mappings":";;;AAAWA;IACX,CAAC,UAAU,WAAW,EAAE;IACxB;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;IAChC;IACA;IACA;IACA,IAAI,WAAW,CAAC,gBAAgB,CAAC,GAAG,kBAAkB;IACtD;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;IAChC,CAAC,EAAEA,mBAAW,KAAKA,mBAAW,GAAG,EAAE,CAAC,CAAC;AAC1BC;IACX,CAAC,UAAU,YAAY,EAAE;IACzB;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACrC;IACA;IACA;IACA,IAAI,YAAY,CAAC,eAAe,CAAC,GAAG,eAAe;IACnD,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;AAC5BC;IACX,CAAC,UAAU,0BAA0B,EAAE;IACvC;IACA;IACA;IACA,IAAI,0BAA0B,CAAC,SAAS,CAAC,GAAG,SAAS;IACrD;IACA;IACA;IACA,IAAI,0BAA0B,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACnD,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;;ACrC9D,UAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACtE,CAAC;;ICFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;IAClF,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -12,6 +12,8 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
12
12
  private var cancelHandler: () -> Void
13
13
  private var responseType: String
14
14
  private var croppedImageQuality: Int
15
+ private var brightness: Float
16
+ private var contrast: Float
15
17
 
16
18
  init(
17
19
  _ viewController: UIViewController? = nil,
@@ -19,7 +21,9 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
19
21
  errorHandler: @escaping (String) -> Void = { _ in },
20
22
  cancelHandler: @escaping () -> Void = {},
21
23
  responseType: String = ResponseType.imageFilePath,
22
- croppedImageQuality: Int = 100
24
+ croppedImageQuality: Int = 100,
25
+ brightness: Float = 0.0,
26
+ contrast: Float = 1.0
23
27
  ) {
24
28
  self.viewController = viewController
25
29
  self.successHandler = successHandler
@@ -27,6 +31,8 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
27
31
  self.cancelHandler = cancelHandler
28
32
  self.responseType = responseType
29
33
  self.croppedImageQuality = croppedImageQuality
34
+ self.brightness = brightness
35
+ self.contrast = contrast
30
36
  }
31
37
 
32
38
  override convenience init() {
@@ -52,7 +58,9 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
52
58
  errorHandler: @escaping (String) -> Void = { _ in },
53
59
  cancelHandler: @escaping () -> Void = {},
54
60
  responseType: String? = ResponseType.imageFilePath,
55
- croppedImageQuality: Int? = 100
61
+ croppedImageQuality: Int? = 100,
62
+ brightness: Float? = 0.0,
63
+ contrast: Float? = 1.0
56
64
  ) {
57
65
  self.viewController = viewController
58
66
  self.successHandler = successHandler
@@ -60,6 +68,8 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
60
68
  self.cancelHandler = cancelHandler
61
69
  self.responseType = responseType ?? ResponseType.imageFilePath
62
70
  self.croppedImageQuality = croppedImageQuality ?? 100
71
+ self.brightness = brightness ?? 0.0
72
+ self.contrast = contrast ?? 1.0
63
73
 
64
74
  startScan()
65
75
  }
@@ -71,8 +81,15 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
71
81
  var results: [String] = []
72
82
 
73
83
  for pageNumber in 0 ..< scan.pageCount {
84
+ var processedImage = scan.imageOfPage(at: pageNumber)
85
+
86
+ // Apply brightness and contrast adjustments if needed
87
+ if brightness != 0.0 || contrast != 1.0 {
88
+ processedImage = applyBrightnessContrast(to: processedImage, brightness: brightness, contrast: contrast)
89
+ }
90
+
74
91
  guard
75
- let scannedImageData = scan.imageOfPage(at: pageNumber)
92
+ let scannedImageData = processedImage
76
93
  .jpegData(compressionQuality: CGFloat(croppedImageQuality) / CGFloat(100))
77
94
  else {
78
95
  goBackToPreviousView(controller)
@@ -123,4 +140,36 @@ class DocScanner: NSObject, VNDocumentCameraViewControllerDelegate {
123
140
  controller.dismiss(animated: true)
124
141
  }
125
142
  }
143
+
144
+ /**
145
+ Applies brightness and contrast adjustments to a UIImage using CIFilter.
146
+ - Parameter image: The source image
147
+ - Parameter brightness: Brightness adjustment (-255 to 255, 0 = no change)
148
+ - Parameter contrast: Contrast adjustment (0.0 to 10.0, 1.0 = no change)
149
+ - Returns: A new UIImage with adjustments applied
150
+ */
151
+ private func applyBrightnessContrast(to image: UIImage, brightness: Float, contrast: Float) -> UIImage {
152
+ guard let ciImage = CIImage(image: image) else {
153
+ return image
154
+ }
155
+
156
+ // Normalize brightness from (-255, 255) to (-1, 1) for CIColorControls
157
+ let normalizedBrightness = brightness / 255.0
158
+
159
+ let filter = CIFilter(name: "CIColorControls")
160
+ filter?.setValue(ciImage, forKey: kCIInputImageKey)
161
+ filter?.setValue(normalizedBrightness, forKey: kCIInputBrightnessKey)
162
+ filter?.setValue(contrast, forKey: kCIInputContrastKey)
163
+
164
+ guard let outputImage = filter?.outputImage else {
165
+ return image
166
+ }
167
+
168
+ let context = CIContext()
169
+ guard let cgImage = context.createCGImage(outputImage, from: outputImage.extent) else {
170
+ return image
171
+ }
172
+
173
+ return UIImage(cgImage: cgImage, scale: image.scale, orientation: image.imageOrientation)
174
+ }
126
175
  }
@@ -4,7 +4,7 @@ import Foundation
4
4
  @available(iOS 13.0, *)
5
5
  @objc(DocumentScannerPlugin)
6
6
  public class DocumentScannerPlugin: CAPPlugin, CAPBridgedPlugin {
7
- private let pluginVersion: String = "7.2.5"
7
+ private let pluginVersion: String = "8.1.0"
8
8
  public let identifier = "DocumentScannerPlugin"
9
9
  public let jsName = "DocumentScanner"
10
10
  public let pluginMethods: [CAPPluginMethod] = [
@@ -40,7 +40,9 @@ public class DocumentScannerPlugin: CAPPlugin, CAPBridgedPlugin {
40
40
  self?.documentScanner = nil
41
41
  },
42
42
  responseType: call.getString("responseType") ?? ResponseType.imageFilePath,
43
- croppedImageQuality: clampQuality(call.getInt("croppedImageQuality"))
43
+ croppedImageQuality: clampQuality(call.getInt("croppedImageQuality")),
44
+ brightness: clampBrightness(call.getFloat("brightness")),
45
+ contrast: clampContrast(call.getFloat("contrast"))
44
46
  )
45
47
 
46
48
  documentScanner?.startScan()
@@ -51,6 +53,16 @@ public class DocumentScannerPlugin: CAPPlugin, CAPBridgedPlugin {
51
53
  return max(0, min(100, quality))
52
54
  }
53
55
 
56
+ private func clampBrightness(_ value: Float?) -> Float {
57
+ let brightness = value ?? 0.0
58
+ return max(-255.0, min(255.0, brightness))
59
+ }
60
+
61
+ private func clampContrast(_ value: Float?) -> Float {
62
+ let contrast = value ?? 1.0
63
+ return max(0.0, min(10.0, contrast))
64
+ }
65
+
54
66
  @objc func getPluginVersion(_ call: CAPPluginCall) {
55
67
  call.resolve(["version": self.pluginVersion])
56
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-document-scanner",
3
- "version": "7.2.5",
3
+ "version": "8.1.0",
4
4
  "description": "Capacitor plugin to scan document iOS and Android",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -46,23 +46,23 @@
46
46
  "prepublishOnly": "npm run build"
47
47
  },
48
48
  "devDependencies": {
49
- "@capacitor/android": "^7.0.0",
50
- "@capacitor/core": "^7.0.0",
51
- "@capacitor/docgen": "^0.3.0",
52
- "@capacitor/ios": "^7.0.0",
49
+ "@capacitor/android": "^8.0.0",
50
+ "@capacitor/core": "^8.0.0",
51
+ "@capacitor/docgen": "^0.3.1",
52
+ "@capacitor/ios": "^8.0.0",
53
53
  "@ionic/eslint-config": "^0.4.0",
54
54
  "@ionic/prettier-config": "^4.0.0",
55
55
  "@ionic/swiftlint-config": "^2.0.0",
56
- "eslint": "^8.57.0",
57
- "prettier": "^3.4.2",
58
- "prettier-plugin-java": "^2.6.6",
59
- "rimraf": "^6.0.1",
60
- "rollup": "^4.30.1",
56
+ "eslint": "^8.57.1",
57
+ "prettier": "^3.6.2",
58
+ "prettier-plugin-java": "^2.7.7",
59
+ "rimraf": "^6.1.0",
60
+ "rollup": "^4.53.2",
61
61
  "swiftlint": "^2.0.0",
62
- "typescript": "~4.1.5"
62
+ "typescript": "^5.9.3"
63
63
  },
64
64
  "peerDependencies": {
65
- "@capacitor/core": ">=7.0.0"
65
+ "@capacitor/core": ">=8.0.0"
66
66
  },
67
67
  "prettier": "@ionic/prettier-config",
68
68
  "swiftlint": "@ionic/swiftlint-config",