@capgo/camera-preview 7.4.0-beta.12 → 7.4.0-beta.15
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 +28 -10
- package/android/.gradle/8.14.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.14.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.14.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +200 -15
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +770 -98
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraSessionConfiguration.java +9 -0
- package/dist/docs.json +56 -23
- package/dist/esm/definitions.d.ts +26 -10
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -0
- package/dist/esm/web.js +256 -34
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +256 -34
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +256 -34
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreview/CameraController.swift +418 -66
- package/ios/Sources/CapgoCameraPreview/Plugin.swift +69 -18
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -62,47 +62,57 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
62
62
|
this.videoElement.playsInline = true;
|
|
63
63
|
this.videoElement.muted = true;
|
|
64
64
|
this.videoElement.autoplay = true;
|
|
65
|
+
// Remove objectFit as we'll match camera's native aspect ratio
|
|
66
|
+
this.videoElement.style.backgroundColor = "transparent";
|
|
67
|
+
// Reset any default margins that might interfere
|
|
68
|
+
this.videoElement.style.margin = "0";
|
|
69
|
+
this.videoElement.style.padding = "0";
|
|
65
70
|
container.appendChild(this.videoElement);
|
|
66
71
|
if (options.toBack) {
|
|
67
72
|
this.videoElement.style.zIndex = "-1";
|
|
68
73
|
}
|
|
74
|
+
// Default to 16:9 vertical (9:16 for portrait) if no aspect ratio or size specified
|
|
75
|
+
const useDefaultAspectRatio = !options.aspectRatio && !options.width && !options.height;
|
|
76
|
+
const effectiveAspectRatio = options.aspectRatio || (useDefaultAspectRatio ? "16:9" : null);
|
|
69
77
|
if (options.width) {
|
|
70
78
|
this.videoElement.width = options.width;
|
|
79
|
+
this.videoElement.style.width = `${options.width}px`;
|
|
71
80
|
}
|
|
72
81
|
if (options.height) {
|
|
73
82
|
this.videoElement.height = options.height;
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
this.videoElement.style.height = `${options.height}px`;
|
|
84
|
+
}
|
|
85
|
+
// Handle positioning - center if x or y not provided
|
|
86
|
+
const centerX = options.x === undefined;
|
|
87
|
+
const centerY = options.y === undefined;
|
|
88
|
+
// Always set position to absolute for proper positioning
|
|
89
|
+
this.videoElement.style.position = "absolute";
|
|
90
|
+
console.log("Initial positioning flags:", {
|
|
91
|
+
centerX,
|
|
92
|
+
centerY,
|
|
93
|
+
x: options.x,
|
|
94
|
+
y: options.y,
|
|
95
|
+
});
|
|
96
|
+
if (options.x !== undefined) {
|
|
76
97
|
this.videoElement.style.left = `${options.x}px`;
|
|
77
98
|
}
|
|
99
|
+
if (options.y !== undefined) {
|
|
100
|
+
this.videoElement.style.top = `${options.y}px`;
|
|
101
|
+
}
|
|
78
102
|
// Create and add grid overlay if needed
|
|
79
103
|
if (gridMode !== "none") {
|
|
80
104
|
const gridOverlay = this.createGridOverlay(gridMode);
|
|
81
105
|
gridOverlay.id = "camera-grid-overlay";
|
|
82
106
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(gridOverlay);
|
|
83
107
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.map(Number);
|
|
91
|
-
const ratio = widthRatio / heightRatio;
|
|
92
|
-
if (options.width) {
|
|
93
|
-
this.videoElement.height = options.width / ratio;
|
|
94
|
-
}
|
|
95
|
-
else if (options.height) {
|
|
96
|
-
this.videoElement.width = options.height * ratio;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.videoElement.style.objectFit = "cover";
|
|
101
|
-
}
|
|
108
|
+
// Aspect ratio handling is now done after getting camera stream
|
|
109
|
+
// Store centering flags for later use
|
|
110
|
+
const needsCenterX = centerX;
|
|
111
|
+
const needsCenterY = centerY;
|
|
112
|
+
console.log("Centering flags stored:", { needsCenterX, needsCenterY });
|
|
113
|
+
// First get the camera stream with basic constraints
|
|
102
114
|
const constraints = {
|
|
103
115
|
video: {
|
|
104
|
-
width: { ideal: this.videoElement.width || 640 },
|
|
105
|
-
height: { ideal: this.videoElement.height || window.innerHeight },
|
|
106
116
|
facingMode: this.isBackCamera ? "environment" : "user",
|
|
107
117
|
},
|
|
108
118
|
};
|
|
@@ -113,16 +123,182 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
113
123
|
if (!this.videoElement) {
|
|
114
124
|
throw new Error("video element not found");
|
|
115
125
|
}
|
|
126
|
+
// Get the actual camera dimensions from the video track
|
|
127
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
128
|
+
const settings = videoTrack.getSettings();
|
|
129
|
+
const cameraWidth = settings.width || 640;
|
|
130
|
+
const cameraHeight = settings.height || 480;
|
|
131
|
+
const cameraAspectRatio = cameraWidth / cameraHeight;
|
|
132
|
+
console.log("Camera native dimensions:", {
|
|
133
|
+
width: cameraWidth,
|
|
134
|
+
height: cameraHeight,
|
|
135
|
+
aspectRatio: cameraAspectRatio,
|
|
136
|
+
});
|
|
137
|
+
console.log("Container dimensions:", {
|
|
138
|
+
width: container.offsetWidth,
|
|
139
|
+
height: container.offsetHeight,
|
|
140
|
+
id: container.id,
|
|
141
|
+
});
|
|
142
|
+
// Now adjust video element size based on camera's native aspect ratio
|
|
143
|
+
if (!options.width && !options.height && !options.aspectRatio) {
|
|
144
|
+
// No size specified, fit camera view within container bounds
|
|
145
|
+
const containerWidth = container.offsetWidth || window.innerWidth;
|
|
146
|
+
const containerHeight = container.offsetHeight || window.innerHeight;
|
|
147
|
+
// Calculate dimensions that fit within container while maintaining camera aspect ratio
|
|
148
|
+
let targetWidth, targetHeight;
|
|
149
|
+
// Try fitting to container width first
|
|
150
|
+
targetWidth = containerWidth;
|
|
151
|
+
targetHeight = targetWidth / cameraAspectRatio;
|
|
152
|
+
// If height exceeds container, fit to height instead
|
|
153
|
+
if (targetHeight > containerHeight) {
|
|
154
|
+
targetHeight = containerHeight;
|
|
155
|
+
targetWidth = targetHeight * cameraAspectRatio;
|
|
156
|
+
}
|
|
157
|
+
console.log("Video element dimensions:", {
|
|
158
|
+
width: targetWidth,
|
|
159
|
+
height: targetHeight,
|
|
160
|
+
container: { width: containerWidth, height: containerHeight },
|
|
161
|
+
});
|
|
162
|
+
this.videoElement.width = targetWidth;
|
|
163
|
+
this.videoElement.height = targetHeight;
|
|
164
|
+
this.videoElement.style.width = `${targetWidth}px`;
|
|
165
|
+
this.videoElement.style.height = `${targetHeight}px`;
|
|
166
|
+
// Center the video element within its parent container
|
|
167
|
+
if (needsCenterX || options.x === undefined) {
|
|
168
|
+
const x = Math.round((containerWidth - targetWidth) / 2);
|
|
169
|
+
this.videoElement.style.left = `${x}px`;
|
|
170
|
+
}
|
|
171
|
+
if (needsCenterY || options.y === undefined) {
|
|
172
|
+
const y = Math.round((window.innerHeight - targetHeight) / 2);
|
|
173
|
+
this.videoElement.style.setProperty("top", `${y}px`, "important");
|
|
174
|
+
// Force a style recalculation
|
|
175
|
+
this.videoElement.offsetHeight;
|
|
176
|
+
console.log("Centering video:", {
|
|
177
|
+
viewportHeight: window.innerHeight,
|
|
178
|
+
targetHeight,
|
|
179
|
+
calculatedY: y,
|
|
180
|
+
actualTop: this.videoElement.style.top,
|
|
181
|
+
position: this.videoElement.style.position,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (effectiveAspectRatio && !options.width && !options.height) {
|
|
186
|
+
// Aspect ratio specified but no size
|
|
187
|
+
const [widthRatio, heightRatio] = effectiveAspectRatio
|
|
188
|
+
.split(":")
|
|
189
|
+
.map(Number);
|
|
190
|
+
const targetRatio = widthRatio / heightRatio;
|
|
191
|
+
const viewportWidth = window.innerWidth;
|
|
192
|
+
const viewportHeight = window.innerHeight;
|
|
193
|
+
let targetWidth, targetHeight;
|
|
194
|
+
// Try fitting to viewport width first
|
|
195
|
+
targetWidth = viewportWidth;
|
|
196
|
+
targetHeight = targetWidth / targetRatio;
|
|
197
|
+
// If height exceeds viewport, fit to height instead
|
|
198
|
+
if (targetHeight > viewportHeight) {
|
|
199
|
+
targetHeight = viewportHeight;
|
|
200
|
+
targetWidth = targetHeight * targetRatio;
|
|
201
|
+
}
|
|
202
|
+
this.videoElement.width = targetWidth;
|
|
203
|
+
this.videoElement.height = targetHeight;
|
|
204
|
+
this.videoElement.style.width = `${targetWidth}px`;
|
|
205
|
+
this.videoElement.style.height = `${targetHeight}px`;
|
|
206
|
+
// Center the video element within its parent container
|
|
207
|
+
if (needsCenterX || options.x === undefined) {
|
|
208
|
+
const parentWidth = container.offsetWidth || viewportWidth;
|
|
209
|
+
const x = Math.round((parentWidth - targetWidth) / 2);
|
|
210
|
+
this.videoElement.style.left = `${x}px`;
|
|
211
|
+
}
|
|
212
|
+
if (needsCenterY || options.y === undefined) {
|
|
213
|
+
const parentHeight = container.offsetHeight || viewportHeight;
|
|
214
|
+
const y = Math.round((parentHeight - targetHeight) / 2);
|
|
215
|
+
this.videoElement.style.top = `${y}px`;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
116
218
|
this.videoElement.srcObject = stream;
|
|
117
219
|
if (!this.isBackCamera) {
|
|
118
220
|
this.videoElement.style.transform = "scaleX(-1)";
|
|
119
221
|
}
|
|
222
|
+
// Set initial zoom level if specified and supported
|
|
223
|
+
if (options.initialZoomLevel && options.initialZoomLevel !== 1.0) {
|
|
224
|
+
// videoTrack already declared above
|
|
225
|
+
if (videoTrack) {
|
|
226
|
+
const capabilities = videoTrack.getCapabilities();
|
|
227
|
+
if (capabilities.zoom) {
|
|
228
|
+
const zoomLevel = options.initialZoomLevel;
|
|
229
|
+
const minZoom = capabilities.zoom.min || 1;
|
|
230
|
+
const maxZoom = capabilities.zoom.max || 1;
|
|
231
|
+
if (zoomLevel < minZoom || zoomLevel > maxZoom) {
|
|
232
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
233
|
+
throw new Error(`Initial zoom level ${zoomLevel} is not available. Valid range is ${minZoom} to ${maxZoom}`);
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
await videoTrack.applyConstraints({
|
|
237
|
+
advanced: [{ zoom: zoomLevel }],
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.warn(`Failed to set initial zoom level: ${error}`);
|
|
242
|
+
// Don't throw, just continue without zoom
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
120
247
|
this.isStarted = true;
|
|
248
|
+
// Wait for video to be ready and get actual dimensions
|
|
249
|
+
await new Promise((resolve) => {
|
|
250
|
+
if (this.videoElement.readyState >= 2) {
|
|
251
|
+
resolve();
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
this.videoElement.addEventListener("loadeddata", () => resolve(), {
|
|
255
|
+
once: true,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
// Ensure centering is applied after DOM updates
|
|
260
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
261
|
+
console.log("About to re-center, flags:", { needsCenterX, needsCenterY });
|
|
262
|
+
// Re-apply centering with correct parent dimensions
|
|
263
|
+
if (needsCenterX) {
|
|
264
|
+
const parentWidth = container.offsetWidth;
|
|
265
|
+
const x = Math.round((parentWidth - this.videoElement.offsetWidth) / 2);
|
|
266
|
+
this.videoElement.style.left = `${x}px`;
|
|
267
|
+
console.log("Re-centering X:", {
|
|
268
|
+
parentWidth,
|
|
269
|
+
videoWidth: this.videoElement.offsetWidth,
|
|
270
|
+
x,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (needsCenterY) {
|
|
274
|
+
const y = Math.round((window.innerHeight - this.videoElement.offsetHeight) / 2);
|
|
275
|
+
this.videoElement.style.setProperty("top", `${y}px`, "important");
|
|
276
|
+
console.log("Re-centering Y:", {
|
|
277
|
+
viewportHeight: window.innerHeight,
|
|
278
|
+
videoHeight: this.videoElement.offsetHeight,
|
|
279
|
+
y,
|
|
280
|
+
position: this.videoElement.style.position,
|
|
281
|
+
top: this.videoElement.style.top,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
// Get the actual rendered dimensions after video is loaded
|
|
285
|
+
const rect = this.videoElement.getBoundingClientRect();
|
|
286
|
+
const computedStyle = window.getComputedStyle(this.videoElement);
|
|
287
|
+
console.log("Final video element state:", {
|
|
288
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
289
|
+
style: {
|
|
290
|
+
position: computedStyle.position,
|
|
291
|
+
left: computedStyle.left,
|
|
292
|
+
top: computedStyle.top,
|
|
293
|
+
width: computedStyle.width,
|
|
294
|
+
height: computedStyle.height,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
121
297
|
return {
|
|
122
|
-
width:
|
|
123
|
-
height:
|
|
124
|
-
x:
|
|
125
|
-
y:
|
|
298
|
+
width: Math.round(rect.width),
|
|
299
|
+
height: Math.round(rect.height),
|
|
300
|
+
x: Math.round(rect.x),
|
|
301
|
+
y: Math.round(rect.y),
|
|
126
302
|
};
|
|
127
303
|
}
|
|
128
304
|
stopStream(stream) {
|
|
@@ -395,6 +571,7 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
395
571
|
throw new Error("zoom not supported by this device");
|
|
396
572
|
}
|
|
397
573
|
const zoomLevel = Math.max(capabilities.zoom.min || 1, Math.min(capabilities.zoom.max || 1, options.level));
|
|
574
|
+
// Note: autoFocus is not supported on web platform
|
|
398
575
|
try {
|
|
399
576
|
await videoTrack.applyConstraints({
|
|
400
577
|
advanced: [{ zoom: zoomLevel }],
|
|
@@ -517,21 +694,25 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
517
694
|
video.style.left = `${x}px`;
|
|
518
695
|
video.style.top = `${y}px`;
|
|
519
696
|
video.style.position = "absolute";
|
|
697
|
+
const offsetX = newWidth / 8;
|
|
698
|
+
const offsetY = newHeight / 8;
|
|
520
699
|
return {
|
|
521
700
|
width: Math.round(newWidth),
|
|
522
701
|
height: Math.round(newHeight),
|
|
523
|
-
x: Math.round(x),
|
|
524
|
-
y: Math.round(y),
|
|
702
|
+
x: Math.round(x + offsetX),
|
|
703
|
+
y: Math.round(y + offsetY),
|
|
525
704
|
};
|
|
526
705
|
}
|
|
527
706
|
else {
|
|
528
707
|
video.style.objectFit = "cover";
|
|
529
708
|
const rect = video.getBoundingClientRect();
|
|
709
|
+
const offsetX = rect.width / 8;
|
|
710
|
+
const offsetY = rect.height / 8;
|
|
530
711
|
return {
|
|
531
712
|
width: Math.round(rect.width),
|
|
532
713
|
height: Math.round(rect.height),
|
|
533
|
-
x: Math.round(rect.left),
|
|
534
|
-
y: Math.round(rect.top),
|
|
714
|
+
x: Math.round(rect.left + offsetX),
|
|
715
|
+
y: Math.round(rect.top + offsetY),
|
|
535
716
|
};
|
|
536
717
|
}
|
|
537
718
|
}
|
|
@@ -590,9 +771,11 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
590
771
|
if (!video) {
|
|
591
772
|
throw new Error("camera is not running");
|
|
592
773
|
}
|
|
774
|
+
const offsetX = video.width / 8;
|
|
775
|
+
const offsetY = video.height / 8;
|
|
593
776
|
return {
|
|
594
|
-
x: video.offsetLeft,
|
|
595
|
-
y: video.offsetTop,
|
|
777
|
+
x: video.offsetLeft + offsetX,
|
|
778
|
+
y: video.offsetTop + offsetY,
|
|
596
779
|
width: video.width,
|
|
597
780
|
height: video.height,
|
|
598
781
|
};
|
|
@@ -606,13 +789,52 @@ var capacitorCapacitorCameraView = (function (exports, core) {
|
|
|
606
789
|
video.style.top = `${options.y}px`;
|
|
607
790
|
video.width = options.width;
|
|
608
791
|
video.height = options.height;
|
|
792
|
+
const offsetX = options.width / 8;
|
|
793
|
+
const offsetY = options.height / 8;
|
|
609
794
|
return {
|
|
610
795
|
width: options.width,
|
|
611
796
|
height: options.height,
|
|
612
|
-
x: options.x,
|
|
613
|
-
y: options.y,
|
|
797
|
+
x: options.x + offsetX,
|
|
798
|
+
y: options.y + offsetY,
|
|
614
799
|
};
|
|
615
800
|
}
|
|
801
|
+
async setFocus(options) {
|
|
802
|
+
// Reject if values are outside 0-1 range
|
|
803
|
+
if (options.x < 0 || options.x > 1 || options.y < 0 || options.y > 1) {
|
|
804
|
+
throw new Error("Focus coordinates must be between 0 and 1");
|
|
805
|
+
}
|
|
806
|
+
const video = document.getElementById(DEFAULT_VIDEO_ID);
|
|
807
|
+
if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
|
|
808
|
+
throw new Error("camera is not running");
|
|
809
|
+
}
|
|
810
|
+
const stream = video.srcObject;
|
|
811
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
812
|
+
if (!videoTrack) {
|
|
813
|
+
throw new Error("no video track found");
|
|
814
|
+
}
|
|
815
|
+
const capabilities = videoTrack.getCapabilities();
|
|
816
|
+
// Check if focusing is supported
|
|
817
|
+
if (capabilities.focusMode) {
|
|
818
|
+
try {
|
|
819
|
+
// Web API supports focus mode settings but not coordinate-based focus
|
|
820
|
+
// Setting to manual mode allows for coordinate focus if supported
|
|
821
|
+
await videoTrack.applyConstraints({
|
|
822
|
+
advanced: [
|
|
823
|
+
{
|
|
824
|
+
focusMode: "manual",
|
|
825
|
+
focusDistance: 0.5, // Mid-range focus as fallback
|
|
826
|
+
},
|
|
827
|
+
],
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
catch (error) {
|
|
831
|
+
console.warn(`setFocus is not fully supported on this device: ${error}. Focus coordinates (${options.x}, ${options.y}) were provided but cannot be applied.`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
console.warn("Focus control is not supported on this device. Focus coordinates were provided but cannot be applied.");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
616
838
|
}
|
|
617
839
|
|
|
618
840
|
var web = /*#__PURE__*/Object.freeze({
|