@capgo/camera-preview 7.17.1 → 7.18.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.
- package/README.md +1 -0
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +5 -1
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +143 -79
- package/dist/docs.json +16 -0
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +99 -54
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1037,6 +1037,7 @@ Defines the options for capturing a picture.
|
|
|
1037
1037
|
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
|
|
1038
1038
|
| **`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 |
|
|
1039
1039
|
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code> | 7.17.0 |
|
|
1040
|
+
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code> | 7.18.0 |
|
|
1040
1041
|
|
|
1041
1042
|
|
|
1042
1043
|
#### CameraSampleOptions
|
|
@@ -372,6 +372,9 @@ public class CameraPreview
|
|
|
372
372
|
final boolean embedTimestamp = Boolean.TRUE.equals(
|
|
373
373
|
call.getBoolean("embedTimestamp")
|
|
374
374
|
);
|
|
375
|
+
final boolean embedLocation = Boolean.TRUE.equals(
|
|
376
|
+
call.getBoolean("embedLocation")
|
|
377
|
+
);
|
|
375
378
|
|
|
376
379
|
cameraXView.capturePhoto(
|
|
377
380
|
quality,
|
|
@@ -379,7 +382,8 @@ public class CameraPreview
|
|
|
379
382
|
width,
|
|
380
383
|
height,
|
|
381
384
|
location,
|
|
382
|
-
embedTimestamp
|
|
385
|
+
embedTimestamp,
|
|
386
|
+
embedLocation
|
|
383
387
|
);
|
|
384
388
|
}
|
|
385
389
|
|
|
@@ -1169,7 +1169,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1169
1169
|
Integer width,
|
|
1170
1170
|
Integer height,
|
|
1171
1171
|
Location location,
|
|
1172
|
-
final boolean embedTimestamp
|
|
1172
|
+
final boolean embedTimestamp,
|
|
1173
|
+
final boolean embedLocation
|
|
1173
1174
|
) {
|
|
1174
1175
|
// Prevent capture if a stop is pending
|
|
1175
1176
|
if (IsOperationRunning("capturePhoto")) {
|
|
@@ -1187,7 +1188,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1187
1188
|
", saveToGallery: " +
|
|
1188
1189
|
saveToGallery +
|
|
1189
1190
|
", embedTimestamp: " +
|
|
1190
|
-
embedTimestamp
|
|
1191
|
+
embedTimestamp +
|
|
1192
|
+
", embedLocation: " +
|
|
1193
|
+
embedLocation
|
|
1191
1194
|
);
|
|
1192
1195
|
|
|
1193
1196
|
if (imageCapture == null) {
|
|
@@ -1262,10 +1265,12 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1262
1265
|
width,
|
|
1263
1266
|
height
|
|
1264
1267
|
);
|
|
1265
|
-
if (embedTimestamp) {
|
|
1266
|
-
resizedBitmap =
|
|
1268
|
+
if (embedTimestamp || embedLocation) {
|
|
1269
|
+
resizedBitmap = drawTimestampAndLocationOntoBitmap(
|
|
1267
1270
|
resizedBitmap,
|
|
1268
|
-
exifInterface
|
|
1271
|
+
exifInterface,
|
|
1272
|
+
embedTimestamp,
|
|
1273
|
+
embedLocation
|
|
1269
1274
|
);
|
|
1270
1275
|
}
|
|
1271
1276
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
@@ -1302,10 +1307,12 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1302
1307
|
exifInterface
|
|
1303
1308
|
);
|
|
1304
1309
|
Bitmap previewCropped = cropBitmapToMatchPreview(originalBitmap);
|
|
1305
|
-
if (embedTimestamp) {
|
|
1306
|
-
previewCropped =
|
|
1310
|
+
if (embedTimestamp || embedLocation) {
|
|
1311
|
+
previewCropped = drawTimestampAndLocationOntoBitmap(
|
|
1307
1312
|
previewCropped,
|
|
1308
|
-
exifInterface
|
|
1313
|
+
exifInterface,
|
|
1314
|
+
embedTimestamp,
|
|
1315
|
+
embedLocation
|
|
1309
1316
|
);
|
|
1310
1317
|
}
|
|
1311
1318
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
@@ -1406,37 +1413,34 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1406
1413
|
);
|
|
1407
1414
|
}
|
|
1408
1415
|
|
|
1409
|
-
private Bitmap
|
|
1416
|
+
private Bitmap drawTimestampAndLocationOntoBitmap(
|
|
1417
|
+
Bitmap src,
|
|
1418
|
+
ExifInterface exif,
|
|
1419
|
+
boolean embedTimestamp,
|
|
1420
|
+
boolean embedLocation
|
|
1421
|
+
) {
|
|
1410
1422
|
if (src == null) return null;
|
|
1411
1423
|
|
|
1412
|
-
// Build
|
|
1413
|
-
final String
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
} catch (java.text.ParseException ignored) {}
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
if (when == null) {
|
|
1436
|
-
when = new java.text.SimpleDateFormat(
|
|
1437
|
-
fmt,
|
|
1438
|
-
java.util.Locale.getDefault()
|
|
1439
|
-
).format(new java.util.Date());
|
|
1424
|
+
// Build strings (null-safe)
|
|
1425
|
+
final String when = embedTimestamp
|
|
1426
|
+
? buildTimestampStringFromExif(exif)
|
|
1427
|
+
: null;
|
|
1428
|
+
final String where =
|
|
1429
|
+
(embedLocation ? buildLocationStringFromExif(exif) : null);
|
|
1430
|
+
|
|
1431
|
+
// Nothing to draw?
|
|
1432
|
+
if (
|
|
1433
|
+
(when == null || when.isEmpty()) && (where == null || where.isEmpty())
|
|
1434
|
+
) {
|
|
1435
|
+
Log.d(
|
|
1436
|
+
TAG,
|
|
1437
|
+
"capturePhoto:... embedTimestamp: " +
|
|
1438
|
+
embedTimestamp +
|
|
1439
|
+
", embedLocation: " +
|
|
1440
|
+
embedLocation
|
|
1441
|
+
);
|
|
1442
|
+
Log.d(TAG, "capturePhoto: nothing to draw");
|
|
1443
|
+
return src;
|
|
1440
1444
|
}
|
|
1441
1445
|
|
|
1442
1446
|
final Bitmap bmp = src.isMutable()
|
|
@@ -1444,14 +1448,16 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1444
1448
|
: src.copy(Bitmap.Config.ARGB_8888, true);
|
|
1445
1449
|
final Canvas canvas = new Canvas(bmp);
|
|
1446
1450
|
|
|
1447
|
-
// ----
|
|
1448
|
-
final float fontPx = Math.max(10f, bmp.getWidth() * 0.035f); //
|
|
1449
|
-
final float paddingH = 16f;
|
|
1450
|
-
final float paddingV = 10f;
|
|
1451
|
-
final float
|
|
1452
|
-
final float
|
|
1451
|
+
// ---- Visual constants (match timestamp style) ----
|
|
1452
|
+
final float fontPx = Math.max(10f, bmp.getWidth() * 0.035f); // ~3.5% of width
|
|
1453
|
+
final float paddingH = 16f; // horizontal inner padding
|
|
1454
|
+
final float paddingV = 10f; // vertical inner padding
|
|
1455
|
+
final float margin = 12f; // margin from image edges
|
|
1456
|
+
final float gap = 8f; // vertical gap between stacked pills
|
|
1457
|
+
final float corner = 10f; // corner radius
|
|
1458
|
+
final int bgColor = Color.argb(56, 31, 31, 31); // ~iOS gray at ~22% alpha
|
|
1453
1459
|
|
|
1454
|
-
// Text paint
|
|
1460
|
+
// Text paint
|
|
1455
1461
|
final Paint text = new Paint(
|
|
1456
1462
|
Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.LINEAR_TEXT_FLAG
|
|
1457
1463
|
);
|
|
@@ -1460,52 +1466,110 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1460
1466
|
text.setTextSize(fontPx);
|
|
1461
1467
|
text.setTextAlign(Paint.Align.LEFT);
|
|
1462
1468
|
text.setDither(true);
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
final float textWidth = text.measureText(when);
|
|
1469
|
+
text.setFilterBitmap(true);
|
|
1470
|
+
text.setHinting(Paint.HINTING_ON);
|
|
1466
1471
|
final Paint.FontMetrics fm = text.getFontMetrics();
|
|
1467
|
-
final float
|
|
1468
|
-
|
|
1469
|
-
// Bubble rect (top-right)
|
|
1470
|
-
final float bgWidth = textWidth + paddingH * 2f;
|
|
1471
|
-
final float bgHeight = textHeight + paddingV * 2f;
|
|
1472
|
-
final float bgLeft = Math.max(0, bmp.getWidth() - bgWidth - margin);
|
|
1473
|
-
final float bgTop = margin;
|
|
1474
|
-
final float bgRight = bgLeft + bgWidth;
|
|
1475
|
-
final float bgBottom = bgTop + bgHeight;
|
|
1476
|
-
|
|
1477
|
-
// Background color: UIColor(white:0.12, alpha:0.22)
|
|
1478
|
-
// -> alpha ≈ 0.22*255 ≈ 56, rgb ≈ 0.12*255 ≈ 31
|
|
1479
|
-
final int bgColor = Color.argb(56, 31, 31, 31);
|
|
1472
|
+
final float lineHeight = fm.descent - fm.ascent;
|
|
1480
1473
|
|
|
1474
|
+
// Background paint
|
|
1481
1475
|
final Paint bg = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
1482
1476
|
bg.setColor(bgColor);
|
|
1483
1477
|
bg.setStyle(Paint.Style.FILL);
|
|
1484
|
-
// Shadow: offset (0,2), blur ~6, alpha 0.25 black
|
|
1485
1478
|
bg.setShadowLayer(6f, 0f, 2f, Color.argb(64, 0, 0, 0));
|
|
1486
1479
|
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1480
|
+
float nextTop = margin;
|
|
1481
|
+
|
|
1482
|
+
// Helper to draw a pill aligned to the top-right, returns the bottom Y used
|
|
1483
|
+
java.util.function.BiFunction<String, Float, Float> drawPill = (
|
|
1484
|
+
label,
|
|
1485
|
+
top
|
|
1486
|
+
) -> {
|
|
1487
|
+
if (label == null || label.isEmpty()) return top;
|
|
1488
|
+
float textW = text.measureText(label);
|
|
1489
|
+
float bgW = textW + paddingH * 2f;
|
|
1490
|
+
float bgH = lineHeight + paddingV * 2f;
|
|
1491
|
+
|
|
1492
|
+
float left = Math.max(0, bmp.getWidth() - bgW - margin);
|
|
1493
|
+
float right = left + bgW;
|
|
1494
|
+
float bottom = top + bgH;
|
|
1495
|
+
|
|
1496
|
+
// Background
|
|
1497
|
+
canvas.drawRoundRect(left, top, right, bottom, corner, corner, bg);
|
|
1498
|
+
|
|
1499
|
+
// Text baseline
|
|
1500
|
+
float textX = left + paddingH;
|
|
1501
|
+
float textY = top + paddingV - fm.ascent; // convert top-left to baseline
|
|
1502
|
+
canvas.drawText(label, textX, textY, text);
|
|
1503
|
+
|
|
1504
|
+
return bottom;
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// 1) Timestamp (if any)
|
|
1508
|
+
if (when != null && !when.isEmpty()) {
|
|
1509
|
+
nextTop = drawPill.apply(when, nextTop);
|
|
1510
|
+
// add gap below
|
|
1511
|
+
nextTop += gap;
|
|
1512
|
+
}
|
|
1497
1513
|
|
|
1498
|
-
//
|
|
1499
|
-
|
|
1500
|
-
|
|
1514
|
+
// 2) Location (if any)
|
|
1515
|
+
if (where != null && !where.isEmpty()) {
|
|
1516
|
+
// If there was no timestamp drawn, we still start at top margin.
|
|
1517
|
+
// If there was, we use the accumulated nextTop (= bottom + gap).
|
|
1518
|
+
drawPill.apply(
|
|
1519
|
+
where,
|
|
1520
|
+
(when != null && !when.isEmpty()) ? nextTop : margin
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1501
1523
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
text.setHinting(Paint.HINTING_ON);
|
|
1524
|
+
return bmp;
|
|
1525
|
+
}
|
|
1505
1526
|
|
|
1506
|
-
|
|
1527
|
+
/** Build "yyyy-MM-dd HH:mm:ss" from EXIF, fallback to now. */
|
|
1528
|
+
private String buildTimestampStringFromExif(ExifInterface exif) {
|
|
1529
|
+
final String out = "yyyy-MM-dd HH:mm:ss";
|
|
1530
|
+
try {
|
|
1531
|
+
if (exif != null) {
|
|
1532
|
+
String exifDate = exif.getAttribute(
|
|
1533
|
+
ExifInterface.TAG_DATETIME_ORIGINAL
|
|
1534
|
+
);
|
|
1535
|
+
if (exifDate == null || exifDate.trim().isEmpty()) {
|
|
1536
|
+
exifDate = exif.getAttribute(ExifInterface.TAG_DATETIME);
|
|
1537
|
+
}
|
|
1538
|
+
if (exifDate != null && !exifDate.trim().isEmpty()) {
|
|
1539
|
+
java.text.SimpleDateFormat in = new java.text.SimpleDateFormat(
|
|
1540
|
+
"yyyy:MM:dd HH:mm:ss",
|
|
1541
|
+
java.util.Locale.US
|
|
1542
|
+
);
|
|
1543
|
+
java.util.Date d = in.parse(exifDate);
|
|
1544
|
+
if (d != null) {
|
|
1545
|
+
return new java.text.SimpleDateFormat(
|
|
1546
|
+
out,
|
|
1547
|
+
java.util.Locale.getDefault()
|
|
1548
|
+
).format(d);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
} catch (Throwable ignored) {}
|
|
1553
|
+
// Fallback to "now" if EXIF missing/invalid
|
|
1554
|
+
return new java.text.SimpleDateFormat(
|
|
1555
|
+
out,
|
|
1556
|
+
java.util.Locale.getDefault()
|
|
1557
|
+
).format(new java.util.Date());
|
|
1558
|
+
}
|
|
1507
1559
|
|
|
1508
|
-
|
|
1560
|
+
/** Build "lat, lon" from EXIF GPS. Returns null if absent (so caller can skip). */
|
|
1561
|
+
private String buildLocationStringFromExif(ExifInterface exif) {
|
|
1562
|
+
if (exif == null) return null;
|
|
1563
|
+
try {
|
|
1564
|
+
float[] latLong = new float[2];
|
|
1565
|
+
if (exif.getLatLong(latLong)) {
|
|
1566
|
+
// Keep a compact but readable precision (5 decimals ≈ ~1 m–10 m)
|
|
1567
|
+
String lat = String.format(java.util.Locale.US, "%.5f", latLong[0]);
|
|
1568
|
+
String lon = String.format(java.util.Locale.US, "%.5f", latLong[1]);
|
|
1569
|
+
return lat + ", " + lon;
|
|
1570
|
+
}
|
|
1571
|
+
} catch (Throwable ignored) {}
|
|
1572
|
+
return null; // No EXIF GPS → skip
|
|
1509
1573
|
}
|
|
1510
1574
|
|
|
1511
1575
|
private int exifToDegrees(int exifOrientation) {
|
package/dist/docs.json
CHANGED
|
@@ -1444,6 +1444,22 @@
|
|
|
1444
1444
|
"docs": "If true, the plugin will embed a timestamp in the top-right corner of the image.",
|
|
1445
1445
|
"complexTypes": [],
|
|
1446
1446
|
"type": "boolean | undefined"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
"name": "embedLocation",
|
|
1450
|
+
"tags": [
|
|
1451
|
+
{
|
|
1452
|
+
"text": "false",
|
|
1453
|
+
"name": "default"
|
|
1454
|
+
},
|
|
1455
|
+
{
|
|
1456
|
+
"text": "7.18.0",
|
|
1457
|
+
"name": "since"
|
|
1458
|
+
}
|
|
1459
|
+
],
|
|
1460
|
+
"docs": "If true, the plugin will embed the current location in the top-right corner of the image.\nRequires `withExifLocation` to be enabled.",
|
|
1461
|
+
"complexTypes": [],
|
|
1462
|
+
"type": "boolean | undefined"
|
|
1447
1463
|
}
|
|
1448
1464
|
]
|
|
1449
1465
|
},
|
|
@@ -244,6 +244,13 @@ export interface CameraPreviewPictureOptions {
|
|
|
244
244
|
* @since 7.17.0
|
|
245
245
|
*/
|
|
246
246
|
embedTimestamp?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* If true, the plugin will embed the current location in the top-right corner of the image.
|
|
249
|
+
* Requires `withExifLocation` to be enabled.
|
|
250
|
+
* @default false
|
|
251
|
+
* @since 7.18.0
|
|
252
|
+
*/
|
|
253
|
+
embedLocation?: boolean;
|
|
247
254
|
}
|
|
248
255
|
/** Represents EXIF data extracted from an image. */
|
|
249
256
|
export interface ExifData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,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":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\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 /**\n * If true, disables the visual focus indicator when tapping to focus.\n * @platform android, ios\n * @default false\n */\n disableFocusIndicator?: 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 * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n /**\n * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\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 * If true, the plugin will embed a timestamp in the top-right corner of the image.\n * @default false\n * @since 7.17.0\n */\n embedTimestamp?: 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/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = \"AUTO\" | \"LOCK\" | \"CONTINUOUS\" | \"CUSTOM\";\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 * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\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 * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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. Only iOS.\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\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 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n\n /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,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":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\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 /**\n * If true, disables the visual focus indicator when tapping to focus.\n * @platform android, ios\n * @default false\n */\n disableFocusIndicator?: 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 * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n /**\n * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\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 * If true, the plugin will embed a timestamp in the top-right corner of the image.\n * @default false\n * @since 7.17.0\n */\n embedTimestamp?: boolean;\n /**\n * If true, the plugin will embed the current location in the top-right corner of the image.\n * Requires `withExifLocation` to be enabled.\n * @default false\n * @since 7.18.0\n */\n embedLocation?: 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/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = \"AUTO\" | \"LOCK\" | \"CONTINUOUS\" | \"CUSTOM\";\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 * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\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 * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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. Only iOS.\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\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 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n\n /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n}\n"]}
|
|
@@ -889,7 +889,7 @@ extension CameraController {
|
|
|
889
889
|
self.updateVideoOrientation()
|
|
890
890
|
}
|
|
891
891
|
|
|
892
|
-
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, embedTimestamp: Bool, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
892
|
+
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, embedTimestamp: Bool, embedLocation: Bool, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
893
893
|
guard let photoOutput = self.photoOutput else {
|
|
894
894
|
completion(nil, nil, nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Photo output is not available"]))
|
|
895
895
|
return
|
|
@@ -973,10 +973,21 @@ extension CameraController {
|
|
|
973
973
|
print("[CameraPreview] Applied aspect ratio cropping for \(aspectRatio): \(finalImage.size.width)x\(finalImage.size.height)")
|
|
974
974
|
}
|
|
975
975
|
|
|
976
|
-
//
|
|
977
|
-
if embedTimestamp {
|
|
978
|
-
let when
|
|
979
|
-
|
|
976
|
+
// Draw overlays if either flag is set (timestamp and/or location)
|
|
977
|
+
if embedTimestamp || embedLocation {
|
|
978
|
+
let when: String? = embedTimestamp
|
|
979
|
+
? self.makeTimestampString(from: photoData, metadata: metadata)
|
|
980
|
+
: nil
|
|
981
|
+
|
|
982
|
+
let whereStr: String? = embedLocation
|
|
983
|
+
? self.makeLocationString(from: gpsLocation, photoData: photoData, metadata: metadata)
|
|
984
|
+
: nil
|
|
985
|
+
|
|
986
|
+
if (when?.isEmpty ?? true) && (whereStr?.isEmpty ?? true) {
|
|
987
|
+
// Nothing to draw (e.g., embedLocation=true but no GPS present) → skip
|
|
988
|
+
} else {
|
|
989
|
+
finalImage = self.drawTimestampAndLocation(on: finalImage, when: when, where: whereStr)
|
|
990
|
+
}
|
|
980
991
|
}
|
|
981
992
|
|
|
982
993
|
completion(finalImage, photoData, metadata, nil)
|
|
@@ -991,42 +1002,24 @@ extension CameraController {
|
|
|
991
1002
|
photoOutput.capturePhoto(with: settings, delegate: self)
|
|
992
1003
|
}
|
|
993
1004
|
|
|
994
|
-
/// Draws
|
|
995
|
-
func
|
|
996
|
-
let textColor: UIColor = .white
|
|
997
|
-
// Slightly lighter/clearer than before (matches iOS feel better)
|
|
998
|
-
let backgroundColor: UIColor = UIColor(white: 0.12, alpha: 0.22)
|
|
999
|
-
let paddingH: CGFloat = 16 // horizontal
|
|
1000
|
-
let paddingV: CGFloat = 10 // vertical
|
|
1001
|
-
let cornerRadius: CGFloat = 10
|
|
1002
|
-
let drawsShadow = true
|
|
1003
|
-
|
|
1005
|
+
/// Draws timestamp and/or location pills at the top-right. Pass nil to skip either line.
|
|
1006
|
+
func drawTimestampAndLocation(on image: UIImage, when: String?, where whereStr: String?) -> UIImage {
|
|
1004
1007
|
let base = image.fixedOrientation() ?? image
|
|
1005
1008
|
let scale = base.scale
|
|
1006
1009
|
let size = base.size
|
|
1007
1010
|
|
|
1008
|
-
//
|
|
1009
|
-
let
|
|
1010
|
-
|
|
1011
|
-
let
|
|
1012
|
-
|
|
1013
|
-
let
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
]
|
|
1017
|
-
let textSize = (text as NSString).size(withAttributes: attrs)
|
|
1018
|
-
|
|
1019
|
-
// Bubble rect (top-right)
|
|
1020
|
-
let bgSize = CGSize(width: textSize.width + paddingH * 2,
|
|
1021
|
-
height: textSize.height + paddingV * 2)
|
|
1022
|
-
let margin: CGFloat = 12 // distance from edges of the photo
|
|
1023
|
-
let bgOrigin = CGPoint(x: size.width - bgSize.width - margin,
|
|
1024
|
-
y: margin)
|
|
1025
|
-
let bgRect = CGRect(origin: bgOrigin, size: bgSize)
|
|
1011
|
+
// Style (match drawTimestamp)
|
|
1012
|
+
let textColor: UIColor = .white
|
|
1013
|
+
let backgroundColor = UIColor(white: 0.12, alpha: 0.22)
|
|
1014
|
+
let paddingH: CGFloat = 16
|
|
1015
|
+
let paddingV: CGFloat = 10
|
|
1016
|
+
let cornerRadius: CGFloat = 10
|
|
1017
|
+
let margin: CGFloat = 12
|
|
1018
|
+
let gap: CGFloat = 8
|
|
1026
1019
|
|
|
1027
|
-
//
|
|
1028
|
-
let
|
|
1029
|
-
|
|
1020
|
+
// ≈3.5% of image width (≥10pt)
|
|
1021
|
+
let fontPointSize = max(10, size.width * 0.035)
|
|
1022
|
+
let font: UIFont = .systemFont(ofSize: fontPointSize, weight: .semibold)
|
|
1030
1023
|
|
|
1031
1024
|
let format = UIGraphicsImageRendererFormat.default()
|
|
1032
1025
|
format.scale = scale
|
|
@@ -1035,32 +1028,46 @@ extension CameraController {
|
|
|
1035
1028
|
return UIGraphicsImageRenderer(size: size, format: format).image { ctx in
|
|
1036
1029
|
base.draw(in: CGRect(origin: .zero, size: size))
|
|
1037
1030
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1031
|
+
func drawPill(_ text: String, top: CGFloat) -> CGFloat {
|
|
1032
|
+
let attrs: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: textColor]
|
|
1033
|
+
let textSize = (text as NSString).size(withAttributes: attrs)
|
|
1034
|
+
let bgSize = CGSize(width: textSize.width + paddingH * 2,
|
|
1035
|
+
height: textSize.height + paddingV * 2)
|
|
1036
|
+
let origin = CGPoint(x: size.width - bgSize.width - margin, y: top)
|
|
1037
|
+
let rect = CGRect(origin: origin, size: bgSize)
|
|
1038
|
+
|
|
1039
|
+
// shadowed rounded bg
|
|
1040
|
+
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius)
|
|
1041
1041
|
ctx.cgContext.saveGState()
|
|
1042
1042
|
ctx.cgContext.setShadow(offset: CGSize(width: 0, height: 2),
|
|
1043
1043
|
blur: 6,
|
|
1044
1044
|
color: UIColor.black.withAlphaComponent(0.25).cgColor)
|
|
1045
1045
|
backgroundColor.setFill()
|
|
1046
|
-
|
|
1046
|
+
path.fill()
|
|
1047
1047
|
ctx.cgContext.restoreGState()
|
|
1048
|
-
} else {
|
|
1049
|
-
backgroundColor.setFill()
|
|
1050
|
-
bubblePath.fill()
|
|
1051
|
-
}
|
|
1052
1048
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1049
|
+
// high-quality text
|
|
1050
|
+
let g = ctx.cgContext
|
|
1051
|
+
g.setAllowsAntialiasing(true)
|
|
1052
|
+
g.setShouldAntialias(true)
|
|
1053
|
+
g.setAllowsFontSmoothing(true)
|
|
1054
|
+
g.setShouldSmoothFonts(true)
|
|
1055
|
+
g.setShouldSubpixelPositionFonts(true)
|
|
1056
|
+
g.interpolationQuality = .high
|
|
1057
|
+
|
|
1058
|
+
(text as NSString).draw(at: CGPoint(x: rect.minX + paddingH, y: rect.minY + paddingV),
|
|
1059
|
+
withAttributes: attrs)
|
|
1061
1060
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1061
|
+
return rect.maxY
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
var top = margin
|
|
1065
|
+
if let w = when, !w.isEmpty {
|
|
1066
|
+
top = drawPill(w, top: top) + gap
|
|
1067
|
+
}
|
|
1068
|
+
if let loc = whereStr, !loc.isEmpty {
|
|
1069
|
+
_ = drawPill(loc, top: (top == margin ? margin : top))
|
|
1070
|
+
}
|
|
1064
1071
|
}
|
|
1065
1072
|
}
|
|
1066
1073
|
|
|
@@ -1104,6 +1111,44 @@ extension CameraController {
|
|
|
1104
1111
|
return outFmt.string(from: Date())
|
|
1105
1112
|
}
|
|
1106
1113
|
|
|
1114
|
+
func makeLocationString(from location: CLLocation?,
|
|
1115
|
+
photoData: Data?,
|
|
1116
|
+
metadata: [AnyHashable: Any]?) -> String? {
|
|
1117
|
+
// 1) Prefer the explicit CLLocation that was just provided
|
|
1118
|
+
if let loc = location {
|
|
1119
|
+
let lat = String(format: "%.5f", loc.coordinate.latitude)
|
|
1120
|
+
let lon = String(format: "%.5f", loc.coordinate.longitude)
|
|
1121
|
+
return "\(lat), \(lon)"
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// 2) Fall back to EXIF GPS in metadata / photo data
|
|
1125
|
+
func extractGPS(_ meta: [String: Any]) -> (Double, Double)? {
|
|
1126
|
+
guard let gps = meta[kCGImagePropertyGPSDictionary as String] as? [String: Any] else { return nil }
|
|
1127
|
+
if let lat = gps[kCGImagePropertyGPSLatitude as String] as? Double,
|
|
1128
|
+
let latRef = gps[kCGImagePropertyGPSLatitudeRef as String] as? String,
|
|
1129
|
+
let lon = gps[kCGImagePropertyGPSLongitude as String] as? Double,
|
|
1130
|
+
let lonRef = gps[kCGImagePropertyGPSLongitudeRef as String] as? String {
|
|
1131
|
+
let signedLat = (latRef.uppercased() == "S") ? -lat : lat
|
|
1132
|
+
let signedLon = (lonRef.uppercased() == "W") ? -lon : lon
|
|
1133
|
+
return (signedLat, signedLon)
|
|
1134
|
+
}
|
|
1135
|
+
return nil
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if let md = metadata as? [String: Any], let (lat, lon) = extractGPS(md) {
|
|
1139
|
+
return String(format: "%.5f, %.5f", lat, lon)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
if let data = photoData,
|
|
1143
|
+
let src = CGImageSourceCreateWithData(data as CFData, nil),
|
|
1144
|
+
let props = CGImageSourceCopyPropertiesAtIndex(src, 0, nil) as? [String: Any],
|
|
1145
|
+
let (lat, lon) = extractGPS(props) {
|
|
1146
|
+
return String(format: "%.5f, %.5f", lat, lon)
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return nil
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1107
1152
|
// Create JPEG data from `image`, merging the original EXIF/GPS/etc. and forcing Orientation=1.
|
|
1108
1153
|
func jpegDataPreservingMetadata(from image: UIImage,
|
|
1109
1154
|
originalPhotoData: Data?,
|
|
@@ -856,12 +856,14 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
856
856
|
let saveToGallery = call.getBool("saveToGallery", false)
|
|
857
857
|
let withExifLocation = call.getBool("withExifLocation", false)
|
|
858
858
|
let embedTimestamp = call.getBool("embedTimestamp", false) ?? false
|
|
859
|
+
let embedLocationRequested = call.getBool("embedLocation", false) ?? false
|
|
860
|
+
let effectiveEmbedLocation = (withExifLocation ?? false) && embedLocationRequested
|
|
859
861
|
let width = call.getInt("width")
|
|
860
862
|
let height = call.getInt("height")
|
|
861
863
|
|
|
862
864
|
print("[CameraPreview] Raw parameter values - width: \(String(describing: width)), height: \(String(describing: height))")
|
|
863
865
|
|
|
864
|
-
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation), embedTimestamp: \(embedTimestamp), width: \(width ?? -1), height: \(height ?? -1)")
|
|
866
|
+
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation ?? false), embedTimestamp: \(embedTimestamp), embedLocation: \(effectiveEmbedLocation) (requested=\(embedLocationRequested)), width: \(width ?? -1), height: \(height ?? -1)")
|
|
865
867
|
print("[CameraPreview] Current location: \(self.currentLocation?.description ?? "nil")")
|
|
866
868
|
// Safely read frame from main thread for logging
|
|
867
869
|
let (previewWidth, previewHeight): (CGFloat, CGFloat) = {
|
|
@@ -878,7 +880,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
878
880
|
}()
|
|
879
881
|
print("[CameraPreview] Preview dimensions: \(previewWidth)x\(previewHeight)")
|
|
880
882
|
|
|
881
|
-
|
|
883
|
+
let gpsForThisCapture = (withExifLocation ?? false) ? self.currentLocation : nil
|
|
884
|
+
self.cameraController.captureImage(width: width, height: height, quality: quality, gpsLocation: gpsForThisCapture, embedTimestamp: embedTimestamp, embedLocation: effectiveEmbedLocation) { (image, originalPhotoData, _, error) in
|
|
882
885
|
print("[CameraPreview] captureImage callback received")
|
|
883
886
|
DispatchQueue.main.async {
|
|
884
887
|
print("[CameraPreview] Processing capture on main thread")
|