@capgo/camera-preview 7.4.0-beta.15 → 7.4.0-beta.16
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 +9 -8
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +118 -25
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +113 -69
- package/dist/docs.json +12 -0
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +43 -4
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +43 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +43 -4
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreview/CameraController.swift +59 -8
- package/ios/Sources/CapgoCameraPreview/Plugin.swift +107 -95
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -725,14 +725,15 @@ Represents EXIF data extracted from an image.
|
|
|
725
725
|
|
|
726
726
|
Defines the options for capturing a picture.
|
|
727
727
|
|
|
728
|
-
| Prop | Type | Description
|
|
729
|
-
| ---------------------- | ------------------------------------------------------- |
|
|
730
|
-
| **`height`** | <code>number</code> | The desired height of the picture in pixels. If not provided, the device default is used.
|
|
731
|
-
| **`width`** | <code>number</code> | The desired width of the picture in pixels. If not provided, the device default is used.
|
|
732
|
-
| **`
|
|
733
|
-
| **`
|
|
734
|
-
| **`
|
|
735
|
-
| **`
|
|
728
|
+
| Prop | Type | Description | Default | Since |
|
|
729
|
+
| ---------------------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- |
|
|
730
|
+
| **`height`** | <code>number</code> | The desired height of the picture in pixels. If not provided, the device default is used. | | |
|
|
731
|
+
| **`width`** | <code>number</code> | The desired width of the picture in pixels. If not provided, the device default is used. | | |
|
|
732
|
+
| **`aspectRatio`** | <code>string</code> | The desired aspect ratio of the captured image (e.g., '4:3', '16:9'). If specified without width/height, captures the largest possible image with this ratio. Cannot be used together with width or height - the capture will be rejected with an error. | | 7.7.0 |
|
|
733
|
+
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
|
|
734
|
+
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
|
|
735
|
+
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
|
|
736
|
+
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
|
|
736
737
|
|
|
737
738
|
|
|
738
739
|
#### CameraSampleOptions
|
|
@@ -9,6 +9,7 @@ import android.location.Location;
|
|
|
9
9
|
import android.util.DisplayMetrics;
|
|
10
10
|
import android.util.Log;
|
|
11
11
|
import android.util.Size;
|
|
12
|
+
import android.view.View;
|
|
12
13
|
import android.view.ViewGroup;
|
|
13
14
|
import android.webkit.WebView;
|
|
14
15
|
import com.ahm.capacitor.camera.preview.model.CameraDevice;
|
|
@@ -171,8 +172,9 @@ public class CameraPreview
|
|
|
171
172
|
final boolean saveToGallery = call.getBoolean("saveToGallery", false);
|
|
172
173
|
Integer width = call.getInt("width");
|
|
173
174
|
Integer height = call.getInt("height");
|
|
175
|
+
String aspectRatio = call.getString("aspectRatio");
|
|
174
176
|
|
|
175
|
-
cameraXView.capturePhoto(quality, saveToGallery, width, height, location);
|
|
177
|
+
cameraXView.capturePhoto(quality, saveToGallery, width, height, aspectRatio, location);
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
@PluginMethod
|
|
@@ -574,6 +576,41 @@ public class CameraPreview
|
|
|
574
576
|
|
|
575
577
|
// Calculate pixel ratio
|
|
576
578
|
float pixelRatio = metrics.density;
|
|
579
|
+
|
|
580
|
+
// The key insight: JavaScript coordinates are relative to the WebView's viewport
|
|
581
|
+
// If the WebView is positioned below the status bar (webViewLocationOnScreen[1] > 0),
|
|
582
|
+
// we need to add that offset when placing native views
|
|
583
|
+
int webViewTopInset = webViewLocationOnScreen[1];
|
|
584
|
+
boolean isEdgeToEdgeActive = webViewLocationOnScreen[1] > 0;
|
|
585
|
+
|
|
586
|
+
// Log all the positioning information for debugging
|
|
587
|
+
Log.d("CameraPreview", "WebView Position Debug:");
|
|
588
|
+
Log.d("CameraPreview", " - webView.getTop(): " + webViewTop);
|
|
589
|
+
Log.d("CameraPreview", " - webView.getLeft(): " + webViewLeft);
|
|
590
|
+
Log.d("CameraPreview", " - webView locationInWindow: (" + webViewLocationInWindow[0] + ", " + webViewLocationInWindow[1] + ")");
|
|
591
|
+
Log.d("CameraPreview", " - webView locationOnScreen: (" + webViewLocationOnScreen[0] + ", " + webViewLocationOnScreen[1] + ")");
|
|
592
|
+
Log.d("CameraPreview", " - parent locationInWindow: (" + parentLocationInWindow[0] + ", " + parentLocationInWindow[1] + ")");
|
|
593
|
+
Log.d("CameraPreview", " - parent locationOnScreen: (" + parentLocationOnScreen[0] + ", " + parentLocationOnScreen[1] + ")");
|
|
594
|
+
|
|
595
|
+
// Check if WebView has margins
|
|
596
|
+
View webView = getBridge().getWebView();
|
|
597
|
+
ViewGroup.LayoutParams webViewLayoutParams = webView.getLayoutParams();
|
|
598
|
+
if (webViewLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
|
599
|
+
ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) webViewLayoutParams;
|
|
600
|
+
Log.d("CameraPreview", " - webView margins: left=" + marginParams.leftMargin +
|
|
601
|
+
", top=" + marginParams.topMargin +
|
|
602
|
+
", right=" + marginParams.rightMargin +
|
|
603
|
+
", bottom=" + marginParams.bottomMargin);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Check WebView padding
|
|
607
|
+
Log.d("CameraPreview", " - webView padding: left=" + webView.getPaddingLeft() +
|
|
608
|
+
", top=" + webView.getPaddingTop() +
|
|
609
|
+
", right=" + webView.getPaddingRight() +
|
|
610
|
+
", bottom=" + webView.getPaddingBottom());
|
|
611
|
+
|
|
612
|
+
Log.d("CameraPreview", " - Using webViewTopInset: " + webViewTopInset);
|
|
613
|
+
Log.d("CameraPreview", " - isEdgeToEdgeActive: " + isEdgeToEdgeActive);
|
|
577
614
|
|
|
578
615
|
// Calculate position - center if x or y is -1
|
|
579
616
|
int computedX;
|
|
@@ -588,7 +625,13 @@ public class CameraPreview
|
|
|
588
625
|
: getBridge().getWebView().getHeight();
|
|
589
626
|
computedHeight -= (int) (paddingBottom * pixelRatio);
|
|
590
627
|
|
|
591
|
-
Log.d("CameraPreview", "
|
|
628
|
+
Log.d("CameraPreview", "========================");
|
|
629
|
+
Log.d("CameraPreview", "POSITIONING CALCULATIONS:");
|
|
630
|
+
Log.d("CameraPreview", "1. INPUT - x: " + x + ", y: " + y + ", width: " + width + ", height: " + height);
|
|
631
|
+
Log.d("CameraPreview", "2. PIXEL RATIO: " + pixelRatio);
|
|
632
|
+
Log.d("CameraPreview", "3. SCREEN - width: " + metrics.widthPixels + ", height: " + metrics.heightPixels);
|
|
633
|
+
Log.d("CameraPreview", "4. WEBVIEW - width: " + getBridge().getWebView().getWidth() + ", height: " + getBridge().getWebView().getHeight());
|
|
634
|
+
Log.d("CameraPreview", "5. COMPUTED DIMENSIONS - width: " + computedWidth + ", height: " + computedHeight);
|
|
592
635
|
|
|
593
636
|
if (x == -1) {
|
|
594
637
|
// Center horizontally
|
|
@@ -617,20 +660,51 @@ public class CameraPreview
|
|
|
617
660
|
}
|
|
618
661
|
|
|
619
662
|
if (y == -1) {
|
|
620
|
-
// Center vertically
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
663
|
+
// Center vertically
|
|
664
|
+
if (isEdgeToEdgeActive) {
|
|
665
|
+
// When WebView is offset from top, center within the available space
|
|
666
|
+
// The camera should be centered in the full screen, not just the WebView area
|
|
667
|
+
computedY = (metrics.heightPixels - computedHeight) / 2;
|
|
668
|
+
Log.d(
|
|
669
|
+
"CameraPreview",
|
|
670
|
+
"Centering vertically with WebView offset: screenHeight=" +
|
|
671
|
+
metrics.heightPixels +
|
|
672
|
+
", webViewTop=" +
|
|
673
|
+
webViewTopInset +
|
|
674
|
+
", computedHeight=" +
|
|
675
|
+
computedHeight +
|
|
676
|
+
", computedY=" +
|
|
677
|
+
computedY
|
|
678
|
+
);
|
|
679
|
+
} else {
|
|
680
|
+
// Normal mode - use full screen height
|
|
681
|
+
computedY = (metrics.heightPixels - computedHeight) / 2;
|
|
682
|
+
Log.d(
|
|
683
|
+
"CameraPreview",
|
|
684
|
+
"Centering vertically (normal): screenHeight=" +
|
|
685
|
+
metrics.heightPixels +
|
|
686
|
+
", computedHeight=" +
|
|
687
|
+
computedHeight +
|
|
688
|
+
", computedY=" +
|
|
689
|
+
computedY
|
|
690
|
+
);
|
|
691
|
+
}
|
|
632
692
|
} else {
|
|
633
693
|
computedY = (int) (y * pixelRatio);
|
|
694
|
+
// If edge-to-edge is active, JavaScript Y is relative to WebView content area
|
|
695
|
+
// We need to add the inset to get absolute screen position
|
|
696
|
+
if (isEdgeToEdgeActive) {
|
|
697
|
+
computedY += webViewTopInset;
|
|
698
|
+
Log.d(
|
|
699
|
+
"CameraPreview",
|
|
700
|
+
"Edge-to-edge adjustment: Y position " +
|
|
701
|
+
(int)(y * pixelRatio) +
|
|
702
|
+
" + inset " +
|
|
703
|
+
webViewTopInset +
|
|
704
|
+
" = " +
|
|
705
|
+
computedY
|
|
706
|
+
);
|
|
707
|
+
}
|
|
634
708
|
Log.d(
|
|
635
709
|
"CameraPreview",
|
|
636
710
|
"Using provided Y position: " +
|
|
@@ -638,10 +712,15 @@ public class CameraPreview
|
|
|
638
712
|
" * " +
|
|
639
713
|
pixelRatio +
|
|
640
714
|
" = " +
|
|
641
|
-
computedY
|
|
715
|
+
computedY +
|
|
716
|
+
(isEdgeToEdgeActive ? " (adjusted for edge-to-edge)" : "")
|
|
642
717
|
);
|
|
643
718
|
}
|
|
644
719
|
|
|
720
|
+
Log.d(
|
|
721
|
+
"CameraPreview",
|
|
722
|
+
"2b. EDGE-TO-EDGE - " + (isEdgeToEdgeActive ? "ACTIVE (inset=" + webViewTopInset + ")" : "INACTIVE")
|
|
723
|
+
);
|
|
645
724
|
Log.d(
|
|
646
725
|
"CameraPreview",
|
|
647
726
|
"3. COMPUTED POSITION - x=" + computedX + ", y=" + computedY
|
|
@@ -776,18 +855,16 @@ public class CameraPreview
|
|
|
776
855
|
.getDisplayMetrics();
|
|
777
856
|
float pixelRatio = metrics.density;
|
|
778
857
|
|
|
779
|
-
//
|
|
780
|
-
//
|
|
781
|
-
// and
|
|
858
|
+
// When WebView is offset from the top (e.g., below status bar),
|
|
859
|
+
// we need to convert between JavaScript coordinates (relative to WebView)
|
|
860
|
+
// and native coordinates (relative to screen)
|
|
861
|
+
WebView webView = getBridge().getWebView();
|
|
782
862
|
int webViewTopInset = 0;
|
|
783
863
|
boolean isEdgeToEdgeActive = false;
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
webView
|
|
787
|
-
|
|
788
|
-
) {
|
|
789
|
-
webViewTopInset =
|
|
790
|
-
((ViewGroup.MarginLayoutParams) webView.getLayoutParams()).topMargin;
|
|
864
|
+
if (webView != null) {
|
|
865
|
+
int[] location = new int[2];
|
|
866
|
+
webView.getLocationOnScreen(location);
|
|
867
|
+
webViewTopInset = location[1];
|
|
791
868
|
isEdgeToEdgeActive = webViewTopInset > 0;
|
|
792
869
|
}
|
|
793
870
|
|
|
@@ -972,8 +1049,24 @@ public class CameraPreview
|
|
|
972
1049
|
.getDisplayMetrics();
|
|
973
1050
|
float pixelRatio = metrics.density;
|
|
974
1051
|
|
|
1052
|
+
// Check if edge-to-edge mode is active
|
|
1053
|
+
WebView webView = getBridge().getWebView();
|
|
1054
|
+
int webViewTopInset = 0;
|
|
1055
|
+
boolean isEdgeToEdgeActive = false;
|
|
1056
|
+
if (webView != null) {
|
|
1057
|
+
int[] location = new int[2];
|
|
1058
|
+
webView.getLocationOnScreen(location);
|
|
1059
|
+
webViewTopInset = location[1];
|
|
1060
|
+
isEdgeToEdgeActive = webViewTopInset > 0;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
975
1063
|
int x = (xParam != null && xParam > 0) ? (int) (xParam * pixelRatio) : 0;
|
|
976
1064
|
int y = (yParam != null && yParam > 0) ? (int) (yParam * pixelRatio) : 0;
|
|
1065
|
+
|
|
1066
|
+
// Add edge-to-edge inset to Y if active
|
|
1067
|
+
if (isEdgeToEdgeActive && y > 0) {
|
|
1068
|
+
y += webViewTopInset;
|
|
1069
|
+
}
|
|
977
1070
|
int width = (widthParam != null && widthParam > 0)
|
|
978
1071
|
? (int) (widthParam * pixelRatio)
|
|
979
1072
|
: 0;
|
|
@@ -480,6 +480,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
480
480
|
|
|
481
481
|
if (height != oldHeight) {
|
|
482
482
|
int screenHeight = metrics.heightPixels;
|
|
483
|
+
// Always center based on full screen height
|
|
483
484
|
y = (screenHeight - height) / 2;
|
|
484
485
|
Log.d(
|
|
485
486
|
TAG,
|
|
@@ -516,27 +517,10 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
516
517
|
height
|
|
517
518
|
);
|
|
518
519
|
|
|
519
|
-
//
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
// Don't add insets if centered or full-screen
|
|
524
|
-
if (sessionConfig.isCentered() || (x == 0 && y == 0)) {
|
|
525
|
-
layoutParams.leftMargin = x;
|
|
526
|
-
layoutParams.topMargin = y;
|
|
527
|
-
Log.d(
|
|
528
|
-
TAG,
|
|
529
|
-
"calculatePreviewLayoutParams: Centered/Full-screen mode - keeping position without insets. isCentered=" +
|
|
530
|
-
sessionConfig.isCentered()
|
|
531
|
-
);
|
|
532
|
-
} else {
|
|
533
|
-
layoutParams.leftMargin = x + webViewLeftInset;
|
|
534
|
-
layoutParams.topMargin = y + webViewTopInset;
|
|
535
|
-
Log.d(
|
|
536
|
-
TAG,
|
|
537
|
-
"calculatePreviewLayoutParams: Positioned mode - applying insets"
|
|
538
|
-
);
|
|
539
|
-
}
|
|
520
|
+
// The X and Y positions passed from CameraPreview already include webView insets
|
|
521
|
+
// when edge-to-edge is active, so we don't need to add them again here
|
|
522
|
+
layoutParams.leftMargin = x;
|
|
523
|
+
layoutParams.topMargin = y;
|
|
540
524
|
|
|
541
525
|
Log.d(
|
|
542
526
|
TAG,
|
|
@@ -562,18 +546,6 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
562
546
|
" height:" +
|
|
563
547
|
height
|
|
564
548
|
);
|
|
565
|
-
Log.d(
|
|
566
|
-
TAG,
|
|
567
|
-
"calculatePreviewLayoutParams: Final margins - leftMargin:" +
|
|
568
|
-
layoutParams.leftMargin +
|
|
569
|
-
" topMargin:" +
|
|
570
|
-
layoutParams.topMargin +
|
|
571
|
-
" (WebView insets: left=" +
|
|
572
|
-
webViewLeftInset +
|
|
573
|
-
", top=" +
|
|
574
|
-
webViewTopInset +
|
|
575
|
-
")"
|
|
576
|
-
);
|
|
577
549
|
return layoutParams;
|
|
578
550
|
}
|
|
579
551
|
|
|
@@ -852,9 +824,18 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
852
824
|
final boolean saveToGallery,
|
|
853
825
|
Integer width,
|
|
854
826
|
Integer height,
|
|
827
|
+
String aspectRatio,
|
|
855
828
|
Location location
|
|
856
829
|
) {
|
|
857
|
-
Log.d(TAG, "capturePhoto: Starting photo capture with quality: " + quality);
|
|
830
|
+
Log.d(TAG, "capturePhoto: Starting photo capture with quality: " + quality + ", aspectRatio: " + aspectRatio);
|
|
831
|
+
|
|
832
|
+
// Check for conflicting parameters
|
|
833
|
+
if (aspectRatio != null && (width != null || height != null)) {
|
|
834
|
+
if (listener != null) {
|
|
835
|
+
listener.onPictureTakenError("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.");
|
|
836
|
+
}
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
858
839
|
|
|
859
840
|
if (imageCapture == null) {
|
|
860
841
|
if (listener != null) {
|
|
@@ -902,7 +883,63 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
902
883
|
|
|
903
884
|
JSONObject exifData = getExifData(exifInterface);
|
|
904
885
|
|
|
905
|
-
|
|
886
|
+
// Handle aspect ratio if no width/height specified
|
|
887
|
+
if (width == null && height == null && aspectRatio != null && !aspectRatio.isEmpty()) {
|
|
888
|
+
// Get the original image dimensions
|
|
889
|
+
Bitmap originalBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
|
890
|
+
int originalWidth = originalBitmap.getWidth();
|
|
891
|
+
int originalHeight = originalBitmap.getHeight();
|
|
892
|
+
|
|
893
|
+
// Parse aspect ratio
|
|
894
|
+
String[] ratios = aspectRatio.split(":");
|
|
895
|
+
if (ratios.length == 2) {
|
|
896
|
+
try {
|
|
897
|
+
float widthRatio = Float.parseFloat(ratios[0]);
|
|
898
|
+
float heightRatio = Float.parseFloat(ratios[1]);
|
|
899
|
+
|
|
900
|
+
// For capture in portrait orientation, swap the aspect ratio (16:9 becomes 9:16)
|
|
901
|
+
boolean isPortrait = originalHeight > originalWidth;
|
|
902
|
+
float targetAspectRatio = isPortrait ? heightRatio / widthRatio : widthRatio / heightRatio;
|
|
903
|
+
float originalAspectRatio = (float) originalWidth / originalHeight;
|
|
904
|
+
|
|
905
|
+
int targetWidth, targetHeight;
|
|
906
|
+
|
|
907
|
+
if (originalAspectRatio > targetAspectRatio) {
|
|
908
|
+
// Original is wider than target - fit by height
|
|
909
|
+
targetHeight = originalHeight;
|
|
910
|
+
targetWidth = (int) (targetHeight * targetAspectRatio);
|
|
911
|
+
} else {
|
|
912
|
+
// Original is taller than target - fit by width
|
|
913
|
+
targetWidth = originalWidth;
|
|
914
|
+
targetHeight = (int) (targetWidth / targetAspectRatio);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// Center crop the image
|
|
918
|
+
int xOffset = (originalWidth - targetWidth) / 2;
|
|
919
|
+
int yOffset = (originalHeight - targetHeight) / 2;
|
|
920
|
+
|
|
921
|
+
Bitmap croppedBitmap = Bitmap.createBitmap(
|
|
922
|
+
originalBitmap,
|
|
923
|
+
xOffset,
|
|
924
|
+
yOffset,
|
|
925
|
+
targetWidth,
|
|
926
|
+
targetHeight
|
|
927
|
+
);
|
|
928
|
+
|
|
929
|
+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
930
|
+
croppedBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
|
|
931
|
+
bytes = stream.toByteArray();
|
|
932
|
+
|
|
933
|
+
// Write EXIF data back to cropped image
|
|
934
|
+
bytes = writeExifToImageBytes(bytes, exifInterface);
|
|
935
|
+
|
|
936
|
+
originalBitmap.recycle();
|
|
937
|
+
croppedBitmap.recycle();
|
|
938
|
+
} catch (NumberFormatException e) {
|
|
939
|
+
Log.e(TAG, "Invalid aspect ratio format: " + aspectRatio, e);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
} else if (width != null && height != null) {
|
|
906
943
|
Bitmap bitmap = BitmapFactory.decodeByteArray(
|
|
907
944
|
bytes,
|
|
908
945
|
0,
|
|
@@ -1543,6 +1580,12 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1543
1580
|
throw new Exception("Preview view not initialized");
|
|
1544
1581
|
}
|
|
1545
1582
|
|
|
1583
|
+
// Validate that coordinates are within bounds (0-1 range)
|
|
1584
|
+
if (x < 0f || x > 1f || y < 0f || y > 1f) {
|
|
1585
|
+
Log.w(TAG, "setFocus: Coordinates out of bounds - x: " + x + ", y: " + y);
|
|
1586
|
+
throw new Exception("Focus coordinates must be between 0 and 1");
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1546
1589
|
// Cancel any ongoing focus operation
|
|
1547
1590
|
if (currentFocusFuture != null && !currentFocusFuture.isDone()) {
|
|
1548
1591
|
Log.d(TAG, "setFocus: Cancelling previous focus operation");
|
|
@@ -1551,16 +1594,18 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1551
1594
|
|
|
1552
1595
|
int viewWidth = previewView.getWidth();
|
|
1553
1596
|
int viewHeight = previewView.getHeight();
|
|
1554
|
-
|
|
1555
|
-
float indicatorY = y * viewHeight;
|
|
1556
|
-
showFocusIndicator(indicatorX, indicatorY);
|
|
1557
|
-
|
|
1597
|
+
|
|
1558
1598
|
if (viewWidth <= 0 || viewHeight <= 0) {
|
|
1559
1599
|
throw new Exception(
|
|
1560
1600
|
"Preview view has invalid dimensions: " + viewWidth + "x" + viewHeight
|
|
1561
1601
|
);
|
|
1562
1602
|
}
|
|
1563
1603
|
|
|
1604
|
+
// Only show focus indicator after validation passes
|
|
1605
|
+
float indicatorX = x * viewWidth;
|
|
1606
|
+
float indicatorY = y * viewHeight;
|
|
1607
|
+
showFocusIndicator(indicatorX, indicatorY);
|
|
1608
|
+
|
|
1564
1609
|
// Create MeteringPoint using the preview view
|
|
1565
1610
|
MeteringPointFactory factory = previewView.getMeteringPointFactory();
|
|
1566
1611
|
MeteringPoint point = factory.createPoint(x * viewWidth, y * viewHeight);
|
|
@@ -2736,10 +2781,10 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2736
2781
|
private int getWebViewTopInset() {
|
|
2737
2782
|
try {
|
|
2738
2783
|
if (webView != null) {
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2784
|
+
// Get the actual WebView position on screen
|
|
2785
|
+
int[] location = new int[2];
|
|
2786
|
+
webView.getLocationOnScreen(location);
|
|
2787
|
+
return location[1]; // Y position is the top inset
|
|
2743
2788
|
}
|
|
2744
2789
|
} catch (Exception e) {
|
|
2745
2790
|
Log.w(TAG, "Failed to get WebView top inset", e);
|
|
@@ -2750,10 +2795,10 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2750
2795
|
private int getWebViewLeftInset() {
|
|
2751
2796
|
try {
|
|
2752
2797
|
if (webView != null) {
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2798
|
+
// Get the actual WebView position on screen for consistency
|
|
2799
|
+
int[] location = new int[2];
|
|
2800
|
+
webView.getLocationOnScreen(location);
|
|
2801
|
+
return location[0]; // X position is the left inset
|
|
2757
2802
|
}
|
|
2758
2803
|
} catch (Exception e) {
|
|
2759
2804
|
Log.w(TAG, "Failed to get WebView left inset", e);
|
|
@@ -2769,31 +2814,30 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2769
2814
|
return new int[] { 0, 0, 0, 0 }; // x, y, width, height
|
|
2770
2815
|
}
|
|
2771
2816
|
|
|
2772
|
-
|
|
2773
|
-
int
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
(ViewGroup.MarginLayoutParams) layoutParams;
|
|
2817
|
+
// Get actual camera preview bounds (accounts for letterboxing/pillarboxing)
|
|
2818
|
+
int actualX = getPreviewX();
|
|
2819
|
+
int actualY = getPreviewY();
|
|
2820
|
+
int actualWidth = getPreviewWidth();
|
|
2821
|
+
int actualHeight = getPreviewHeight();
|
|
2778
2822
|
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2823
|
+
// Convert to logical pixels for JavaScript
|
|
2824
|
+
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
|
2825
|
+
float pixelRatio = metrics.density;
|
|
2782
2826
|
|
|
2783
|
-
|
|
2784
|
-
|
|
2827
|
+
// Remove WebView insets from coordinates
|
|
2828
|
+
int webViewTopInset = getWebViewTopInset();
|
|
2829
|
+
int webViewLeftInset = getWebViewLeftInset();
|
|
2785
2830
|
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
}
|
|
2831
|
+
int x = Math.max(
|
|
2832
|
+
0,
|
|
2833
|
+
(int) ((actualX - webViewLeftInset) / pixelRatio)
|
|
2834
|
+
);
|
|
2835
|
+
int y = Math.max(
|
|
2836
|
+
0,
|
|
2837
|
+
(int) ((actualY - webViewTopInset) / pixelRatio)
|
|
2838
|
+
);
|
|
2839
|
+
int width = (int) (actualWidth / pixelRatio);
|
|
2840
|
+
int height = (int) (actualHeight / pixelRatio);
|
|
2797
2841
|
|
|
2798
2842
|
return new int[] { x, y, width, height };
|
|
2799
2843
|
}
|
package/dist/docs.json
CHANGED
|
@@ -1006,6 +1006,18 @@
|
|
|
1006
1006
|
"complexTypes": [],
|
|
1007
1007
|
"type": "number | undefined"
|
|
1008
1008
|
},
|
|
1009
|
+
{
|
|
1010
|
+
"name": "aspectRatio",
|
|
1011
|
+
"tags": [
|
|
1012
|
+
{
|
|
1013
|
+
"text": "7.7.0",
|
|
1014
|
+
"name": "since"
|
|
1015
|
+
}
|
|
1016
|
+
],
|
|
1017
|
+
"docs": "The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\nIf specified without width/height, captures the largest possible image with this ratio.\nCannot be used together with width or height - the capture will be rejected with an error.",
|
|
1018
|
+
"complexTypes": [],
|
|
1019
|
+
"type": "string | undefined"
|
|
1020
|
+
},
|
|
1009
1021
|
{
|
|
1010
1022
|
"name": "quality",
|
|
1011
1023
|
"tags": [
|
|
@@ -198,6 +198,13 @@ export interface CameraPreviewPictureOptions {
|
|
|
198
198
|
height?: number;
|
|
199
199
|
/** The desired width of the picture in pixels. If not provided, the device default is used. */
|
|
200
200
|
width?: number;
|
|
201
|
+
/**
|
|
202
|
+
* The desired aspect ratio of the captured image (e.g., '4:3', '16:9').
|
|
203
|
+
* If specified without width/height, captures the largest possible image with this ratio.
|
|
204
|
+
* Cannot be used together with width or height - the capture will be rejected with an error.
|
|
205
|
+
* @since 7.7.0
|
|
206
|
+
*/
|
|
207
|
+
aspectRatio?: string;
|
|
201
208
|
/**
|
|
202
209
|
* The quality of the captured image, from 0 to 100.
|
|
203
210
|
* Does not apply to `png` format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** The desired height of the picture in pixels. If not provided, the device default is used. */\n height?: number;\n /** The desired width of the picture in pixels. If not provided, the device default is used. */\n width?: number;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.4.0\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.4.0\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.4.0\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.4.0\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.4.0\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.4.0\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.4.0\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.4.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.4.0\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.4.0\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 8.1.0\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** The desired height of the picture in pixels. If not provided, the device default is used. */\n height?: number;\n /** The desired width of the picture in pixels. If not provided, the device default is used. */\n width?: number;\n /**\n * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\n * If specified without width/height, captures the largest possible image with this ratio.\n * Cannot be used together with width or height - the capture will be rejected with an error.\n * @since 7.7.0\n */\n aspectRatio?: string;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.4.0\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.4.0\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.4.0\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.4.0\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.4.0\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.4.0\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.4.0\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.4.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.4.0\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.4.0\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 8.1.0\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n}\n"]}
|