capacitor-community-multilens-camerapreview 0.0.11-a → 6.0.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 CHANGED
@@ -20,7 +20,6 @@ npx cap sync
20
20
  * [`getSupportedFlashModes()`](#getsupportedflashmodes)
21
21
  * [`setFlashMode(...)`](#setflashmode)
22
22
  * [`flip()`](#flip)
23
- * [`changeOrientation()`](#changeorientation)
24
23
  * [`setOpacity(...)`](#setopacity)
25
24
  * [`setZoom(...)`](#setzoom)
26
25
  * [`getSupportedZoomLevels()`](#getsupportedzoomlevels)
@@ -121,15 +120,6 @@ flip() => Promise<void>
121
120
  --------------------
122
121
 
123
122
 
124
- ### changeOrientation()
125
-
126
- ```typescript
127
- changeOrientation() => Promise<void>
128
- ```
129
-
130
- --------------------
131
-
132
-
133
123
  ### setOpacity(...)
134
124
 
135
125
  ```typescript
@@ -1,8 +1,9 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
+ androidxExifInterfaceVersion = project.hasProperty('androidxExifInterfaceVersion') ? rootProject.ext.androidxExifInterfaceVersion : '1.3.6'
5
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
6
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
7
  }
7
8
 
8
9
  buildscript {
@@ -11,20 +12,21 @@ buildscript {
11
12
  google()
12
13
  }
13
14
  dependencies {
14
- classpath 'com.android.tools.build:gradle:7.2.1'
15
+ classpath 'com.android.tools.build:gradle:8.2.1'
15
16
  }
16
17
  }
17
18
 
18
19
  apply plugin: 'com.android.library'
19
20
 
20
21
  android {
21
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
22
+ namespace "com.ahm.capacitor.camera.preview.capacitorcamerapreview"
23
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
22
24
  defaultConfig {
23
25
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
24
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
25
27
  versionCode 1
26
28
  versionName "1.0"
27
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
29
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
30
  }
29
31
  buildTypes {
30
32
  release {
@@ -47,7 +49,7 @@ dependencies {
47
49
  implementation fileTree(dir: 'libs', include: ['*.jar'])
48
50
  implementation project(':capacitor-android')
49
51
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
50
- implementation 'androidx.exifinterface:exifinterface:1.3.2'
52
+ implementation "androidx.exifinterface:exifinterface:$androidxExifInterfaceVersion"
51
53
  testImplementation "junit:junit:$junitVersion"
52
54
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
53
55
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -1,5 +1,5 @@
1
1
 
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- package="com.ahm.capacitor.camera.preview.capacitorcamerapreview">
3
+ >
4
4
  </manifest>
5
5
 
@@ -156,7 +156,6 @@ public class CameraActivity extends Fragment {
156
156
  }
157
157
  }
158
158
 
159
-
160
159
  private void setupTouchAndBackButton() {
161
160
  final GestureDetector gestureDetector = new GestureDetector(getActivity().getApplicationContext(), new TapGestureDetector());
162
161
 
@@ -401,15 +400,16 @@ public class CameraActivity extends Fragment {
401
400
  super.onConfigurationChanged(newConfig);
402
401
 
403
402
  final FrameLayout frameContainerLayout = (FrameLayout) view.findViewById(
404
- getResources().getIdentifier("frame_container", "id", appResourcesPackage)
403
+ getResources().getIdentifier("frame_container", "id", appResourcesPackage)
405
404
  );
406
405
 
407
- final int previousOrientation = frameContainerLayout.getHeight() > frameContainerLayout.getWidth() ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
406
+ final int previousOrientation = frameContainerLayout.getHeight() > frameContainerLayout.getWidth()
407
+ ? Configuration.ORIENTATION_PORTRAIT
408
+ : Configuration.ORIENTATION_LANDSCAPE;
408
409
  // Checks if the orientation of the screen has changed
409
410
  if (newConfig.orientation != previousOrientation) {
410
-
411
411
  final RelativeLayout frameCamContainerLayout = (RelativeLayout) view.findViewById(
412
- getResources().getIdentifier("frame_camera_cont", "id", appResourcesPackage)
412
+ getResources().getIdentifier("frame_camera_cont", "id", appResourcesPackage)
413
413
  );
414
414
 
415
415
  frameContainerLayout.getLayoutParams().width = frameCamContainerLayout.getHeight();
@@ -424,12 +424,9 @@ public class CameraActivity extends Fragment {
424
424
  frameCamContainerLayout.forceLayout();
425
425
 
426
426
  mPreview.setCameraDisplayOrientation();
427
-
428
427
  }
429
-
430
428
  }
431
429
 
432
-
433
430
  public Camera getCamera() {
434
431
  return mCamera;
435
432
  }
@@ -303,11 +303,9 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
303
303
  call.reject("Permission failed: user denied access to camera.");
304
304
  }
305
305
  }
306
-
307
306
 
308
307
  private void startCamera(final PluginCall call) {
309
308
  String position = call.getString("position");
310
- //int zoomFactor = call.getInt("zoomFactor", 0);
311
309
 
312
310
  if (position == null || position.isEmpty() || "rear".equals(position)) {
313
311
  position = "back";
@@ -339,6 +337,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
339
337
  fragment.toBack = toBack;
340
338
  fragment.enableOpacity = enableOpacity;
341
339
  fragment.enableZoom = enableZoom;
340
+
342
341
  bridge
343
342
  .getActivity()
344
343
  .runOnUiThread(
@@ -1,4 +1,4 @@
1
- export declare type CameraPosition = 'rear' | 'front';
1
+ export type CameraPosition = 'rear' | 'front';
2
2
  export interface CameraPreviewOptions {
3
3
  /** Parent element to attach the video preview element to (applicable to the web platform only) */
4
4
  parent?: string;
@@ -51,14 +51,16 @@ export interface CameraSampleOptions {
51
51
  /** The picture quality, 0 - 100, default 85 */
52
52
  quality?: number;
53
53
  }
54
- export declare type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';
54
+ export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';
55
55
  export interface CameraOpacityOptions {
56
56
  /** The percent opacity to set for camera view, default 1 */
57
57
  opacity?: number;
58
58
  }
59
59
  export interface CameraPreviewPlugin {
60
60
  start(options: CameraPreviewOptions): Promise<{}>;
61
+ startRecordVideo(options: CameraPreviewOptions): Promise<{}>;
61
62
  stop(): Promise<{}>;
63
+ stopRecordVideo(): Promise<{}>;
62
64
  capture(options: CameraPreviewPictureOptions): Promise<{
63
65
  value: string;
64
66
  }>;
@@ -72,7 +74,6 @@ export interface CameraPreviewPlugin {
72
74
  flashMode: CameraPreviewFlashMode | string;
73
75
  }): Promise<void>;
74
76
  flip(): Promise<void>;
75
- changeOrientation(): Promise<void>;
76
77
  setOpacity(options: CameraOpacityOptions): Promise<{}>;
77
78
  setZoom(options: CameraPreviewOptions): Promise<void>;
78
79
  getSupportedZoomLevels(): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nexport type CameraPosition = 'rear' | 'front';\nexport interface CameraPreviewOptions {\n /** Parent element to attach the video preview element to (applicable to the web platform only) */\n parent?: string;\n /** Class name to add to the video preview element (applicable to the web platform only) */\n className?: string;\n /** The preview width in pixels, default window.screen.width */\n width?: number;\n /** The preview height in pixels, default window.screen.height */\n height?: number;\n /** The x origin, default 0 (applicable to the android and ios platforms only) */\n x?: number;\n /** The y origin, default 0 (applicable to the android and ios platforms only) */\n y?: number;\n /** Brings your html in front of your preview, default false (applicable to the android only) */\n toBack?: boolean;\n /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */\n paddingBottom?: number;\n /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */\n rotateWhenOrientationChanged?: boolean;\n /** Choose the camera to use 'front' or 'rear', default 'front' */\n position?: CameraPosition | string;\n /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */\n storeToFile?: boolean;\n /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */\n disableExifHeaderStripping?: boolean;\n /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/\n enableHighResolution?: boolean;\n /** Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching */\n disableAudio?: boolean;\n /** Android Only - Locks device orientation when camera is showing. */\n lockAndroidOrientation?: boolean;\n /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */\n enableOpacity?: boolean;\n /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */\n enableZoom?: boolean;\n /** override defualt lens choice ios String 'ultra','wide','tele' android int example 100, 200 etc */\n zoomFactor?: any;\n}\nexport interface CameraPreviewPictureOptions {\n /** The picture height, optional, default 0 (Device default) */\n height?: number;\n /** The picture width, optional, default 0 (Device default) */\n width?: number;\n /** The picture quality, 0 - 100, default 85 on `iOS/Android`.\n *\n * If left undefined, the `web` implementation will export a PNG, otherwise a JPEG will be generated */\n quality?: number;\n}\n\nexport interface CameraSampleOptions {\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n}\n\nexport type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';\n\nexport interface CameraOpacityOptions {\n /** The percent opacity to set for camera view, default 1 */\n opacity?: number;\n}\n\nexport interface CameraPreviewPlugin {\n start(options: CameraPreviewOptions): Promise<{}>;\n stop(): Promise<{}>;\n capture(options: CameraPreviewPictureOptions): Promise<{ value: string }>;\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise<void>;\n flip(): Promise<void>;\n changeOrientation(): Promise<void>;\n setOpacity(options: CameraOpacityOptions): Promise<{}>;\n setZoom(options: CameraPreviewOptions): Promise<void>;\n getSupportedZoomLevels(): Promise<{\n result: any[];\n }>;\n}"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,aAAa,GAAG,cAAc,CAAsB,eAAe,EAAE;IACzE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CameraPreviewPlugin } from './definitions';\n\nconst CameraPreview = registerPlugin<CameraPreviewPlugin>('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\n\nexport * from './definitions';\nexport { CameraPreview };"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,aAAa,GAAG,cAAc,CAAsB,eAAe,EAAE;IACzE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/esm/web.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
8
8
  private isBackCamera;
9
9
  constructor();
10
10
  start(options: CameraPreviewOptions): Promise<{}>;
11
+ startRecordVideo(): Promise<{}>;
12
+ stopRecordVideo(): Promise<{}>;
11
13
  stop(): Promise<any>;
12
14
  capture(options: CameraPreviewPictureOptions): Promise<any>;
13
15
  captureSample(_options: CameraSampleOptions): Promise<any>;
@@ -22,7 +24,6 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
22
24
  flashMode: CameraPreviewFlashMode | string;
23
25
  }): Promise<void>;
24
26
  flip(): Promise<void>;
25
- changeOrientation(): Promise<void>;
26
27
  setOpacity(_options: CameraOpacityOptions): Promise<any>;
27
28
  }
28
29
  declare const CameraPreview: CameraPreviewWeb;
package/dist/esm/web.js CHANGED
@@ -1,29 +1,17 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable @typescript-eslint/prefer-for-of */
3
- /* eslint-disable @typescript-eslint/ban-types */
4
- /* eslint-disable no-async-promise-executor */
5
- /* eslint-disable @typescript-eslint/consistent-type-assertions */
6
- /* eslint-disable @typescript-eslint/no-inferrable-types */
7
- import { WebPlugin, registerWebPlugin } from '@capacitor/core';
1
+ import { WebPlugin } from '@capacitor/core';
8
2
  export class CameraPreviewWeb extends WebPlugin {
9
3
  constructor() {
10
4
  super({
11
5
  name: 'CameraPreview',
12
6
  platforms: ['web'],
13
7
  });
14
- /**
15
- * track which camera is used based on start options
16
- * used in capture
17
- */
18
- this.isBackCamera = false;
19
8
  }
20
9
  async start(options) {
21
10
  return new Promise(async (resolve, reject) => {
22
- var _a;
23
11
  await navigator.mediaDevices
24
12
  .getUserMedia({
25
13
  audio: !options.disableAudio,
26
- video: true
14
+ video: true,
27
15
  })
28
16
  .then((stream) => {
29
17
  // Stop any existing stream so we can request media with different constraints based on user input
@@ -52,15 +40,13 @@ export class CameraPreviewWeb extends WebPlugin {
52
40
  videoElement.setAttribute('muted', 'true');
53
41
  videoElement.setAttribute('playsinline', 'true');
54
42
  }
55
- if (parent) {
56
- parent.appendChild(videoElement);
57
- }
58
- if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
43
+ parent.appendChild(videoElement);
44
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
59
45
  const constraints = {
60
46
  video: {
61
47
  width: { ideal: options.width },
62
- height: { ideal: options.height }
63
- }
48
+ height: { ideal: options.height },
49
+ },
64
50
  };
65
51
  if (options.position === 'rear') {
66
52
  constraints.video.facingMode = 'environment';
@@ -84,6 +70,12 @@ export class CameraPreviewWeb extends WebPlugin {
84
70
  }
85
71
  });
86
72
  }
73
+ async startRecordVideo() {
74
+ throw this.unimplemented('Not implemented on web.');
75
+ }
76
+ async stopRecordVideo() {
77
+ throw this.unimplemented('Not implemented on web.');
78
+ }
87
79
  async stop() {
88
80
  const video = document.getElementById('video');
89
81
  if (video) {
@@ -106,16 +98,16 @@ export class CameraPreviewWeb extends WebPlugin {
106
98
  canvas.width = video.videoWidth;
107
99
  canvas.height = video.videoHeight;
108
100
  // flip horizontally back camera isn't used
109
- if (context) {
110
- if (!this.isBackCamera) {
111
- context.translate(video.videoWidth, 0);
112
- context.scale(-1, 1);
113
- }
114
- context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
101
+ if (!this.isBackCamera) {
102
+ context.translate(video.videoWidth, 0);
103
+ context.scale(-1, 1);
115
104
  }
105
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
116
106
  let base64EncodedImage;
117
107
  if (options.quality != undefined) {
118
- base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');
108
+ base64EncodedImage = canvas
109
+ .toDataURL('image/jpeg', options.quality / 100.0)
110
+ .replace('data:image/jpeg;base64,', '');
119
111
  }
120
112
  else {
121
113
  base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
@@ -143,9 +135,6 @@ export class CameraPreviewWeb extends WebPlugin {
143
135
  async flip() {
144
136
  throw new Error('flip not supported under the web platform');
145
137
  }
146
- async changeOrientation() {
147
- throw new Error('changeOrientation not supported under the web platform');
148
- }
149
138
  async setOpacity(_options) {
150
139
  const video = document.getElementById('video');
151
140
  if (!!video && !!_options['opacity']) {
@@ -155,5 +144,4 @@ export class CameraPreviewWeb extends WebPlugin {
155
144
  }
156
145
  const CameraPreview = new CameraPreviewWeb();
157
146
  export { CameraPreview };
158
- registerWebPlugin(CameraPreview);
159
147
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,qDAAqD;AACrD,iDAAiD;AACjD,8CAA8C;AAC9C,kEAAkE;AAClE,2DAA2D;AAC3D,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAY/D,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC;QAVL;;;WAGG;QACK,iBAAY,GAAY,KAAK,CAAC;IAOtC,CAAC;IAED,KAAK,CAAC,KAAK,CAA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AC,CAAC;QACjE,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACpC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpE;IACH,CAAC;CACF;AAED,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,iBAAiB,CAAC,aAAa,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/prefer-for-of */\n/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable no-async-promise-executor */\n/* eslint-disable @typescript-eslint/consistent-type-assertions */\n/* eslint-disable @typescript-eslint/no-inferrable-types */\nimport { WebPlugin, registerWebPlugin } from '@capacitor/core';\n\nimport type {\n CameraPreviewOptions,\n CameraPreviewPictureOptions,\n CameraPreviewPlugin,\n CameraPreviewFlashMode,\n CameraSampleOptions,\n CameraOpacityOptions,\n} from './definitions';\n\n\nexport class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {\n /**\n * track which camera is used based on start options\n * used in capture\n */\n private isBackCamera: boolean = false;\n\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n\n async start(options: CameraPreviewOptions): Promise<{}> {\n return new Promise(async (resolve, reject) => {\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true\n })\n .then((stream: MediaStream) => {\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 })\n .catch((error) => {\n reject(error);\n });\n\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent as string);\n\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n\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\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n\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 if(parent){\n parent.appendChild(videoElement);\n }\n\n if (navigator.mediaDevices?.getUserMedia) {\n const constraints: MediaStreamConstraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height }\n }\n };\n\n if (options.position === 'rear') {\n (constraints.video as MediaTrackConstraints).facingMode = 'environment';\n this.isBackCamera = true;\n } else {\n this.isBackCamera = false;\n }\n\n navigator.mediaDevices.getUserMedia(constraints).then(\n function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve({});\n },\n (err) => {\n reject(err);\n }\n );\n }\n } else {\n reject({ message: 'camera already started' });\n }\n });\n }\n\n async stop(): Promise<any> {\n const video = <HTMLVideoElement>document.getElementById('video');\n if (video) {\n video.pause();\n\n const st: any = video.srcObject;\n const tracks = st.getTracks();\n\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n\n async capture(options: CameraPreviewPictureOptions): Promise<any> {\n return new Promise((resolve, _) => {\n const video = <HTMLVideoElement>document.getElementById('video');\n const canvas = document.createElement('canvas');\n\n // video.width = video.offsetWidth;\n\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n // flip horizontally back camera isn't used\n if(context){\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 }\n\n let base64EncodedImage;\n\n if (options.quality != undefined) {\n base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');\n } else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n\n async captureSample(_options: CameraSampleOptions): Promise<any> {\n return this.capture(_options);\n }\n\n async setZoom(_options: CameraPreviewOptions): Promise<void> {\n throw new Error('set zoom not supported under the web platform');\n }\n async getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }> {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n getSupportedZoomLevels(): Promise<{ result: any[]; }> {\n throw new Error('getSupportedFlashModes not supported under the web platform.');\n }\n\n async setFlashMode(_options: { flashMode: CameraPreviewFlashMode | string }): Promise<void> {\n throw new Error('setFlashMode not supported under the web platform');\n }\n\n async flip(): Promise<void> {\n throw new Error('flip not supported under the web platform');\n }\n async changeOrientation(): Promise<void> {\n throw new Error('changeOrientation not supported under the web platform');\n }\n \n async setOpacity(_options: CameraOpacityOptions): Promise<any> {\n const video = <HTMLVideoElement>document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n}\n\nconst CameraPreview = new CameraPreviewWeb();\n\nexport { CameraPreview };\n\nregisterWebPlugin(CameraPreview);"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA6B;QACvC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EA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ACjE,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACpC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpE;IACH,CAAC;CACF;AAED,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -8,26 +8,19 @@ const CameraPreview$1 = core.registerPlugin('CameraPreview', {
8
8
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
9
9
  });
10
10
 
11
- /* eslint-disable @typescript-eslint/no-unused-vars */
12
11
  class CameraPreviewWeb extends core.WebPlugin {
13
12
  constructor() {
14
13
  super({
15
14
  name: 'CameraPreview',
16
15
  platforms: ['web'],
17
16
  });
18
- /**
19
- * track which camera is used based on start options
20
- * used in capture
21
- */
22
- this.isBackCamera = false;
23
17
  }
24
18
  async start(options) {
25
19
  return new Promise(async (resolve, reject) => {
26
- var _a;
27
20
  await navigator.mediaDevices
28
21
  .getUserMedia({
29
22
  audio: !options.disableAudio,
30
- video: true
23
+ video: true,
31
24
  })
32
25
  .then((stream) => {
33
26
  // Stop any existing stream so we can request media with different constraints based on user input
@@ -56,15 +49,13 @@ class CameraPreviewWeb extends core.WebPlugin {
56
49
  videoElement.setAttribute('muted', 'true');
57
50
  videoElement.setAttribute('playsinline', 'true');
58
51
  }
59
- if (parent) {
60
- parent.appendChild(videoElement);
61
- }
62
- if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
52
+ parent.appendChild(videoElement);
53
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
63
54
  const constraints = {
64
55
  video: {
65
56
  width: { ideal: options.width },
66
- height: { ideal: options.height }
67
- }
57
+ height: { ideal: options.height },
58
+ },
68
59
  };
69
60
  if (options.position === 'rear') {
70
61
  constraints.video.facingMode = 'environment';
@@ -88,6 +79,12 @@ class CameraPreviewWeb extends core.WebPlugin {
88
79
  }
89
80
  });
90
81
  }
82
+ async startRecordVideo() {
83
+ throw this.unimplemented('Not implemented on web.');
84
+ }
85
+ async stopRecordVideo() {
86
+ throw this.unimplemented('Not implemented on web.');
87
+ }
91
88
  async stop() {
92
89
  const video = document.getElementById('video');
93
90
  if (video) {
@@ -110,16 +107,16 @@ class CameraPreviewWeb extends core.WebPlugin {
110
107
  canvas.width = video.videoWidth;
111
108
  canvas.height = video.videoHeight;
112
109
  // flip horizontally back camera isn't used
113
- if (context) {
114
- if (!this.isBackCamera) {
115
- context.translate(video.videoWidth, 0);
116
- context.scale(-1, 1);
117
- }
118
- context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
110
+ if (!this.isBackCamera) {
111
+ context.translate(video.videoWidth, 0);
112
+ context.scale(-1, 1);
119
113
  }
114
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
120
115
  let base64EncodedImage;
121
116
  if (options.quality != undefined) {
122
- base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');
117
+ base64EncodedImage = canvas
118
+ .toDataURL('image/jpeg', options.quality / 100.0)
119
+ .replace('data:image/jpeg;base64,', '');
123
120
  }
124
121
  else {
125
122
  base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
@@ -147,9 +144,6 @@ class CameraPreviewWeb extends core.WebPlugin {
147
144
  async flip() {
148
145
  throw new Error('flip not supported under the web platform');
149
146
  }
150
- async changeOrientation() {
151
- throw new Error('changeOrientation not supported under the web platform');
152
- }
153
147
  async setOpacity(_options) {
154
148
  const video = document.getElementById('video');
155
149
  if (!!video && !!_options['opacity']) {
@@ -158,7 +152,6 @@ class CameraPreviewWeb extends core.WebPlugin {
158
152
  }
159
153
  }
160
154
  const CameraPreview = new CameraPreviewWeb();
161
- core.registerWebPlugin(CameraPreview);
162
155
 
163
156
  var web = /*#__PURE__*/Object.freeze({
164
157
  __proto__: null,
@@ -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","/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/prefer-for-of */\n/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable no-async-promise-executor */\n/* eslint-disable @typescript-eslint/consistent-type-assertions */\n/* eslint-disable @typescript-eslint/no-inferrable-types */\nimport { WebPlugin, registerWebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n /**\n * track which camera is used based on start options\n * used in capture\n */\n this.isBackCamera = false;\n }\n async start(options) {\n return new Promise(async (resolve, reject) => {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true\n })\n .then((stream) => {\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 })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\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 if (parent) {\n parent.appendChild(videoElement);\n }\n if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\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 navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve({});\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\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 (context) {\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 }\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).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 setZoom(_options) {\n throw new Error('set zoom not supported under the web platform');\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n getSupportedZoomLevels() {\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 changeOrientation() {\n throw new Error('changeOrientation 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}\nconst CameraPreview = new CameraPreviewWeb();\nexport { CameraPreview };\nregisterWebPlugin(CameraPreview);\n//# sourceMappingURL=web.js.map"],"names":["CameraPreview","registerPlugin","WebPlugin","registerWebPlugin"],"mappings":";;;;;;AACK,MAACA,eAAa,GAAGC,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACHD;AAOO,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;AAC9B,SAAS,CAAC,CAAC;AACX;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;AAClC,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,MAAM,KAAK;AACtD,YAAY,IAAI,EAAE,CAAC;AACnB,YAAY,MAAM,SAAS,CAAC,YAAY;AACxC,iBAAiB,YAAY,CAAC;AAC9B,gBAAgB,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;AAC5C,gBAAgB,KAAK,EAAE,IAAI;AAC3B,aAAa,CAAC;AACd,iBAAiB,IAAI,CAAC,CAAC,MAAM,KAAK;AAClC;AACA,gBAAgB,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAA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K,CAAC,mDAAmD,CAAC,CAAC;AAC7E,KAAK;AACL,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AACrE,KAAK;AACL,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;AAClF,KAAK;AACL,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;AAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACvD,QAAQ,IAAI,CAAC,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,CAAC;AAC/E,SAAS;AACT,KAAK;AACL,CAAC;AACD,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAE7CC,sBAAiB,CAAC,aAAa,CAAC;;;;;;;;;;"}
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 name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\n return new Promise(async (resolve, reject) => {\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\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 })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\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 (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {\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 navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve({});\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\n }\n async startRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\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 setZoom(_options) {\n throw new Error('set zoom not supported under the web platform');\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n getSupportedZoomLevels() {\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}\nconst CameraPreview = new CameraPreviewWeb();\nexport { CameraPreview };\n//# sourceMappingURL=web.js.map"],"names":["CameraPreview","registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAACA,eAAa,GAAGC,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,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;AAC9B,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,MAAM,KAAK;AACtD,YAAY,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B,QAAQ,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACzE,KAAK;AACL,IAAI,MAAM,sBAAsB,GAAG;AACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;AACvF,KAAK;AACL,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AACxF,KAAK;AACL,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AAC7E,KAAK;AACL,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AACrE,KAAK;AACL,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;AAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACvD,QAAQ,IAAI,CAAC,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,CAAC;AAC/E,SAAS;AACT,KAAK;AACL,CAAC;AACD,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE;;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -1,30 +1,23 @@
1
- var capacitorCameraPreview = (function (exports, core) {
1
+ var capacitorSplashScreen = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
4
  const CameraPreview$1 = core.registerPlugin('CameraPreview', {
5
5
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
6
6
  });
7
7
 
8
- /* eslint-disable @typescript-eslint/no-unused-vars */
9
8
  class CameraPreviewWeb extends core.WebPlugin {
10
9
  constructor() {
11
10
  super({
12
11
  name: 'CameraPreview',
13
12
  platforms: ['web'],
14
13
  });
15
- /**
16
- * track which camera is used based on start options
17
- * used in capture
18
- */
19
- this.isBackCamera = false;
20
14
  }
21
15
  async start(options) {
22
16
  return new Promise(async (resolve, reject) => {
23
- var _a;
24
17
  await navigator.mediaDevices
25
18
  .getUserMedia({
26
19
  audio: !options.disableAudio,
27
- video: true
20
+ video: true,
28
21
  })
29
22
  .then((stream) => {
30
23
  // Stop any existing stream so we can request media with different constraints based on user input
@@ -53,15 +46,13 @@ var capacitorCameraPreview = (function (exports, core) {
53
46
  videoElement.setAttribute('muted', 'true');
54
47
  videoElement.setAttribute('playsinline', 'true');
55
48
  }
56
- if (parent) {
57
- parent.appendChild(videoElement);
58
- }
59
- if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
49
+ parent.appendChild(videoElement);
50
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
60
51
  const constraints = {
61
52
  video: {
62
53
  width: { ideal: options.width },
63
- height: { ideal: options.height }
64
- }
54
+ height: { ideal: options.height },
55
+ },
65
56
  };
66
57
  if (options.position === 'rear') {
67
58
  constraints.video.facingMode = 'environment';
@@ -85,6 +76,12 @@ var capacitorCameraPreview = (function (exports, core) {
85
76
  }
86
77
  });
87
78
  }
79
+ async startRecordVideo() {
80
+ throw this.unimplemented('Not implemented on web.');
81
+ }
82
+ async stopRecordVideo() {
83
+ throw this.unimplemented('Not implemented on web.');
84
+ }
88
85
  async stop() {
89
86
  const video = document.getElementById('video');
90
87
  if (video) {
@@ -107,16 +104,16 @@ var capacitorCameraPreview = (function (exports, core) {
107
104
  canvas.width = video.videoWidth;
108
105
  canvas.height = video.videoHeight;
109
106
  // flip horizontally back camera isn't used
110
- if (context) {
111
- if (!this.isBackCamera) {
112
- context.translate(video.videoWidth, 0);
113
- context.scale(-1, 1);
114
- }
115
- context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
107
+ if (!this.isBackCamera) {
108
+ context.translate(video.videoWidth, 0);
109
+ context.scale(-1, 1);
116
110
  }
111
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
117
112
  let base64EncodedImage;
118
113
  if (options.quality != undefined) {
119
- base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');
114
+ base64EncodedImage = canvas
115
+ .toDataURL('image/jpeg', options.quality / 100.0)
116
+ .replace('data:image/jpeg;base64,', '');
120
117
  }
121
118
  else {
122
119
  base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
@@ -144,9 +141,6 @@ var capacitorCameraPreview = (function (exports, core) {
144
141
  async flip() {
145
142
  throw new Error('flip not supported under the web platform');
146
143
  }
147
- async changeOrientation() {
148
- throw new Error('changeOrientation not supported under the web platform');
149
- }
150
144
  async setOpacity(_options) {
151
145
  const video = document.getElementById('video');
152
146
  if (!!video && !!_options['opacity']) {
@@ -155,7 +149,6 @@ var capacitorCameraPreview = (function (exports, core) {
155
149
  }
156
150
  }
157
151
  const CameraPreview = new CameraPreviewWeb();
158
- core.registerWebPlugin(CameraPreview);
159
152
 
160
153
  var web = /*#__PURE__*/Object.freeze({
161
154
  __proto__: null,