@carviz/capacitor-camera-preview 8.0.3 → 8.0.4

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.
@@ -61,6 +61,10 @@ public class CameraActivity extends Fragment {
61
61
  private Preview mPreview;
62
62
  private boolean canTakePicture = true;
63
63
 
64
+ // True when the user has set focus manually via tap-to-focus. While true, the manual focus is
65
+ // kept (locked) instead of being restored to continuous auto-focus, so the captured photo uses it.
66
+ private boolean manualFocusActive = false;
67
+
64
68
  private View view;
65
69
  private Camera.Parameters cameraParameters;
66
70
  private Camera mCamera;
@@ -197,6 +201,9 @@ public class CameraActivity extends Fragment {
197
201
  } else if (tapToTakePicture) {
198
202
  takePicture(0, 0, 85);
199
203
  } else if (tapToFocus) {
204
+ // Remember the manual focus so it is kept (locked) and not
205
+ // overridden by continuous auto-focus when capturing.
206
+ manualFocusActive = true;
200
207
  setFocusArea(
201
208
  (int) event.getX(0),
202
209
  (int) event.getY(0),
@@ -586,6 +593,11 @@ public class CameraActivity extends Fragment {
586
593
  Log.d(TAG, "CameraPreview onPictureTaken general exception");
587
594
  } finally {
588
595
  canTakePicture = true;
596
+ // Reset to continuous auto-focus after each photo so the next capture refocuses
597
+ // automatically unless the user taps to focus again.
598
+ if (manualFocusActive) {
599
+ resetFocus();
600
+ }
589
601
  mCamera.startPreview();
590
602
  }
591
603
  }
@@ -822,23 +834,27 @@ public class CameraActivity extends Fragment {
822
834
  mCamera.autoFocus(new Camera.AutoFocusCallback() {
823
835
  @Override
824
836
  public void onAutoFocus(boolean success, Camera camera) {
825
- // Restore the original focus mode
837
+ // Restore the original focus mode, unless the user set focus manually via
838
+ // tap-to-focus. In that case keep FOCUS_MODE_AUTO with the focus areas so the
839
+ // focus stays locked on the tapped point for the next capture.
826
840
  try {
827
- Camera.Parameters params = camera.getParameters();
828
- List<String> supportedFocusModes = params.getSupportedFocusModes();
829
-
830
- // Only restore if the original mode is still supported
831
- if (supportedFocusModes != null && supportedFocusModes.contains(originalFocusMode)) {
832
- params.setFocusMode(originalFocusMode);
833
- params.setFocusAreas(null);
834
- params.setMeteringAreas(null);
835
- camera.setParameters(params);
836
- Log.d(TAG, "Focus mode restored to: " + originalFocusMode);
841
+ if (!manualFocusActive) {
842
+ Camera.Parameters params = camera.getParameters();
843
+ List<String> supportedFocusModes = params.getSupportedFocusModes();
844
+
845
+ // Only restore if the original mode is still supported
846
+ if (supportedFocusModes != null && supportedFocusModes.contains(originalFocusMode)) {
847
+ params.setFocusMode(originalFocusMode);
848
+ params.setFocusAreas(null);
849
+ params.setMeteringAreas(null);
850
+ camera.setParameters(params);
851
+ Log.d(TAG, "Focus mode restored to: " + originalFocusMode);
852
+ }
837
853
  }
838
854
  } catch (Exception e) {
839
855
  Log.e(TAG, "Error restoring focus mode: " + e.getMessage());
840
856
  }
841
-
857
+
842
858
  // Call the original callback if provided
843
859
  if (callback != null) {
844
860
  callback.onAutoFocus(success, camera);
@@ -854,6 +870,45 @@ public class CameraActivity extends Fragment {
854
870
  }
855
871
  }
856
872
 
873
+ /**
874
+ * Reset the focus back to continuous auto-focus, discarding any manual (tap-to-focus) focus.
875
+ * Clears the focus/metering areas and resumes the device's continuous focus mode if supported.
876
+ */
877
+ public void resetFocus() {
878
+ manualFocusActive = false;
879
+
880
+ if (mCamera == null) {
881
+ return;
882
+ }
883
+
884
+ try {
885
+ mCamera.cancelAutoFocus();
886
+
887
+ Camera.Parameters parameters = mCamera.getParameters();
888
+ List<String> supportedFocusModes = parameters.getSupportedFocusModes();
889
+
890
+ if (supportedFocusModes != null) {
891
+ if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
892
+ parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
893
+ } else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
894
+ parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
895
+ }
896
+ }
897
+
898
+ if (parameters.getMaxNumFocusAreas() > 0) {
899
+ parameters.setFocusAreas(null);
900
+ }
901
+ if (parameters.getMaxNumMeteringAreas() > 0) {
902
+ parameters.setMeteringAreas(null);
903
+ }
904
+
905
+ setCameraParameters(parameters);
906
+ Log.d(TAG, "Focus reset to continuous auto-focus");
907
+ } catch (Exception e) {
908
+ Log.e(TAG, "Error resetting focus: " + e.getMessage());
909
+ }
910
+ }
911
+
857
912
  private Rect calculateTapArea(float x, float y, float coefficient) {
858
913
  if (x < 100) {
859
914
  x = 100;
@@ -188,6 +188,17 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
188
188
  call.resolve();
189
189
  }
190
190
 
191
+ @PluginMethod
192
+ public void resetFocus(PluginCall call) {
193
+ if (!this.hasCamera(call)) {
194
+ call.reject("Camera is not running");
195
+ return;
196
+ }
197
+
198
+ fragment.resetFocus();
199
+ call.resolve();
200
+ }
201
+
191
202
  @PluginMethod
192
203
  public void setZoom(PluginCall call) {
193
204
  if (!this.hasCamera(call)) {
@@ -123,6 +123,8 @@ export interface CameraPreviewPlugin {
123
123
  }>;
124
124
  /** Get the preview position and dimensions - Android / iOS only */
125
125
  getPreviewPosition(): Promise<CameraPreviewPosition>;
126
+ /** Reset the focus to continuous auto-focus, discarding any manual (tap-to-focus) focus - Android / iOS only */
127
+ resetFocus(): Promise<void>;
126
128
  /** Check camera permission */
127
129
  checkPermissions(): Promise<PermissionState>;
128
130
  /** Request camera permission */
package/dist/esm/web.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
22
22
  setOpacity(_options: CameraOpacityOptions): Promise<any>;
23
23
  setZoom(_options: CameraZoomOptions): Promise<any>;
24
24
  getZoom(): Promise<any>;
25
+ resetFocus(): Promise<void>;
25
26
  getPreviewPosition(): Promise<CameraPreviewPosition>;
26
27
  checkPermissions(): Promise<PermissionState>;
27
28
  requestPermissions(): Promise<PermissionState>;
package/dist/esm/web.js CHANGED
@@ -116,6 +116,9 @@ export class CameraPreviewWeb extends WebPlugin {
116
116
  async getZoom() {
117
117
  throw new Error('getZoom not supported under the web platform');
118
118
  }
119
+ async resetFocus() {
120
+ throw new Error('resetFocus not supported under the web platform');
121
+ }
119
122
  async getPreviewPosition() {
120
123
  throw new Error('getPreviewPosition not supported under the web platform');
121
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAc5C,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA6B;;QACvC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAE1E,kGAAkG;QAClG,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAEpD,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEvD,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACrD,YAAY,CAAC,EAAE,GAAG,OAAO,CAAC;QAC1B,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QAE5D,iDAAiD;QACjD,IAAI,OAAO,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YAChC,YAAY,CAAC,YAAY,CAAC,OAAO,E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 +123,9 @@ class CameraPreviewWeb extends core.WebPlugin {
123
123
  async getZoom() {
124
124
  throw new Error('getZoom not supported under the web platform');
125
125
  }
126
+ async resetFocus() {
127
+ throw new Error('resetFocus not supported under the web platform');
128
+ }
126
129
  async getPreviewPosition() {
127
130
  throw new Error('getPreviewPosition not supported under the web platform');
128
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n return {};\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async getPreviewPosition() {\n throw new Error('getPreviewPosition not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,EAAE;AACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACjF;AACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;AAC3D,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;AACtD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;AAC9D,QAAQ,IAAI,KAAK,EAAE;AACnB,YAAY,OAAO,EAAE;AACrB,QAAQ;AACR,QAAQ,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;AAC5D,QAAQ,YAAY,CAAC,EAAE,GAAG,OAAO;AACjC,QAAQ,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;AACnE;AACA,QAAQ,IAAI,OAAO,CAAC,QAAQ,KAAK,MAAM,EAAE;AACzC,YAAY,Y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AAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9E,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,OAAO,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACvE,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACvE,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AAChF,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC;AAC3E,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n return {};\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async resetFocus() {\n throw new Error('resetFocus not supported under the web platform');\n }\n async getPreviewPosition() {\n throw new Error('getPreviewPosition not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf,IAAI;AACJ,IAAI,MAAM,KAAK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D,CAAC;AAC1E,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AAChF,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC;AAC3E,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -122,6 +122,9 @@ var capacitorSplashScreen = (function (exports, core) {
122
122
  async getZoom() {
123
123
  throw new Error('getZoom not supported under the web platform');
124
124
  }
125
+ async resetFocus() {
126
+ throw new Error('resetFocus not supported under the web platform');
127
+ }
125
128
  async getPreviewPosition() {
126
129
  throw new Error('getPreviewPosition not supported under the web platform');
127
130
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n return {};\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async getPreviewPosition() {\n throw new Error('getPreviewPosition not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE;IACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACjF;IACA,QAAQ,MAAM,CAAC,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AK,CAAC,yDAAyD,CAAC;IAClF,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;IACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC;IAC3E,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;IAClF,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n return {};\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async resetFocus() {\n throw new Error('resetFocus not supported under the web platform');\n }\n async getPreviewPosition() {\n throw new Error('getPreviewPosition not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE;IACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACjF;IACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3D,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACtD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAC9D,QAAQ,IAAI,KAAK,EAAE;IACnB,YAAY,OAAO,EAAE;IACrB,QAAQ;IACR,QAAQ,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;IAC5D,QAAQ,YAAY,CAAC,EAAE,GAAG,OAAO;IACjC,QAAQ,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,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Float = 1
61
-
61
+
62
+ /** True when the user has set focus manually via tap-to-focus. While true, the manual focus is
63
+ kept (locked) instead of being overridden by continuous auto-focus when a photo is captured. */
64
+ var manualFocusActive = false
65
+
62
66
  /** Delegate for camera events */
63
67
  weak var delegate: CameraControllerDelegate?
64
68
 
@@ -305,6 +309,37 @@ class CameraController: NSObject {
305
309
  self.photoCaptureCompletionBlock = completion
306
310
  }
307
311
 
312
+ /** Reset the focus (and exposure) back to continuous auto-focus, discarding any manual
313
+ tap-to-focus the user may have set. */
314
+ func resetFocus() {
315
+ guard let device = self.currentCamera else { return }
316
+
317
+ do {
318
+ try device.lockForConfiguration()
319
+ defer { device.unlockForConfiguration() }
320
+
321
+ let focusMode = AVCaptureDevice.FocusMode.continuousAutoFocus
322
+ if device.isFocusModeSupported(focusMode) {
323
+ if device.isFocusPointOfInterestSupported {
324
+ device.focusPointOfInterest = CGPoint(x: 0.5, y: 0.5)
325
+ }
326
+ device.focusMode = focusMode
327
+ }
328
+
329
+ let exposureMode = AVCaptureDevice.ExposureMode.continuousAutoExposure
330
+ if device.isExposureModeSupported(exposureMode) {
331
+ if device.isExposurePointOfInterestSupported {
332
+ device.exposurePointOfInterest = CGPoint(x: 0.5, y: 0.5)
333
+ }
334
+ device.exposureMode = exposureMode
335
+ }
336
+
337
+ self.manualFocusActive = false
338
+ } catch {
339
+ debugPrint(error)
340
+ }
341
+ }
342
+
308
343
  func captureSample(completion: @escaping (UIImage?, Error?) -> Void) {
309
344
  guard let captureSession = captureSession, captureSession.isRunning else {
310
345
  completion(nil, CameraControllerError.captureSessionIsMissing)
@@ -531,7 +566,13 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
531
566
  self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
532
567
  return
533
568
  }
534
-
569
+
570
+ // Reset to continuous auto-focus after each photo so the next capture refocuses
571
+ // automatically unless the user taps to focus again.
572
+ if self.manualFocusActive {
573
+ self.resetFocus()
574
+ }
575
+
535
576
  self.photoCaptureCompletionBlock?(image.fixedOrientation(), nil)
536
577
  }
537
578
  }
@@ -595,17 +636,22 @@ extension CameraController: UIGestureRecognizerDelegate {
595
636
  try device.lockForConfiguration()
596
637
  defer { device.unlockForConfiguration() }
597
638
 
598
- let focusMode = AVCaptureDevice.FocusMode.continuousAutoFocus
639
+ // Use one-shot auto-focus so the focus locks on the tapped point instead of being
640
+ // re-evaluated continuously (which would override the user's manual focus on capture).
641
+ let focusMode = AVCaptureDevice.FocusMode.autoFocus
599
642
  if device.isFocusPointOfInterestSupported && device.isFocusModeSupported(focusMode) {
600
643
  device.focusPointOfInterest = CGPoint(x: CGFloat(devicePoint.x), y: CGFloat(devicePoint.y))
601
644
  device.focusMode = focusMode
602
645
  }
603
646
 
604
- let exposureMode = AVCaptureDevice.ExposureMode.continuousAutoExposure
647
+ let exposureMode = AVCaptureDevice.ExposureMode.autoExpose
605
648
  if device.isExposurePointOfInterestSupported && device.isExposureModeSupported(exposureMode) {
606
649
  device.exposurePointOfInterest = CGPoint(x: CGFloat(devicePoint.x), y: CGFloat(devicePoint.y))
607
650
  device.exposureMode = exposureMode
608
651
  }
652
+
653
+ // Remember that the user set focus manually so capture keeps it instead of refocusing.
654
+ self.manualFocusActive = true
609
655
  } catch {
610
656
  debugPrint(error)
611
657
  }
@@ -16,4 +16,5 @@ CAP_PLUGIN(CameraPreview, "CameraPreview",
16
16
  CAP_PLUGIN_METHOD(checkPermissions, CAPPluginReturnPromise);
17
17
  CAP_PLUGIN_METHOD(requestPermissions, CAPPluginReturnPromise);
18
18
  CAP_PLUGIN_METHOD(getPreviewPosition, CAPPluginReturnPromise);
19
+ CAP_PLUGIN_METHOD(resetFocus, CAPPluginReturnPromise);
19
20
  )
@@ -256,6 +256,21 @@ public class CameraPreview: CAPPlugin, CameraControllerDelegate {
256
256
  }
257
257
  }
258
258
 
259
+ /**
260
+ Reset the focus back to continuous auto-focus, discarding any manual tap-to-focus
261
+ */
262
+ @objc func resetFocus(_ call: CAPPluginCall) {
263
+ guard let captureSession = self.cameraController.captureSession, captureSession.isRunning else {
264
+ call.reject("camera is not running")
265
+ return
266
+ }
267
+
268
+ DispatchQueue.main.async {
269
+ self.cameraController.resetFocus()
270
+ call.resolve()
271
+ }
272
+ }
273
+
259
274
  /**
260
275
  Get the preview position and dimensions
261
276
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carviz/capacitor-camera-preview",
3
- "version": "8.0.3",
3
+ "version": "8.0.4",
4
4
  "description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.cjs.js",