capacitor-community-multilens-camerapreview 0.0.1 → 0.0.2

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
@@ -21,6 +21,7 @@ npx cap sync
21
21
  * [`setFlashMode(...)`](#setflashmode)
22
22
  * [`flip()`](#flip)
23
23
  * [`setOpacity(...)`](#setopacity)
24
+ * [`setZoom(...)`](#setzoom)
24
25
  * [`getSupportedZoomLevels()`](#getsupportedzoomlevels)
25
26
  * [Interfaces](#interfaces)
26
27
  * [Type Aliases](#type-aliases)
@@ -134,6 +135,19 @@ setOpacity(options: CameraOpacityOptions) => Promise<{}>
134
135
  --------------------
135
136
 
136
137
 
138
+ ### setZoom(...)
139
+
140
+ ```typescript
141
+ setZoom(options: CameraPreviewOptions) => Promise<void>
142
+ ```
143
+
144
+ | Param | Type |
145
+ | ------------- | --------------------------------------------------------------------- |
146
+ | **`options`** | <code><a href="#camerapreviewoptions">CameraPreviewOptions</a></code> |
147
+
148
+ --------------------
149
+
150
+
137
151
  ### getSupportedZoomLevels()
138
152
 
139
153
  ```typescript
package/dist/docs.json CHANGED
@@ -127,6 +127,24 @@
127
127
  ],
128
128
  "slug": "setopacity"
129
129
  },
130
+ {
131
+ "name": "setZoom",
132
+ "signature": "(options: CameraPreviewOptions) => Promise<void>",
133
+ "parameters": [
134
+ {
135
+ "name": "options",
136
+ "docs": "",
137
+ "type": "CameraPreviewOptions"
138
+ }
139
+ ],
140
+ "returns": "Promise<void>",
141
+ "tags": [],
142
+ "docs": "",
143
+ "complexTypes": [
144
+ "CameraPreviewOptions"
145
+ ],
146
+ "slug": "setzoom"
147
+ },
130
148
  {
131
149
  "name": "getSupportedZoomLevels",
132
150
  "signature": "() => Promise<{ result: any[]; }>",
@@ -73,6 +73,7 @@ export interface CameraPreviewPlugin {
73
73
  }): Promise<void>;
74
74
  flip(): Promise<void>;
75
75
  setOpacity(options: CameraOpacityOptions): Promise<{}>;
76
+ setZoom(options: CameraPreviewOptions): Promise<void>;
76
77
  getSupportedZoomLevels(): Promise<{
77
78
  result: any[];
78
79
  }>;
@@ -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 setOpacity(options: CameraOpacityOptions): Promise<{}>;\n getSupportedZoomLevels(): Promise<{\n result: any[];\n }>;\n}"]}
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 setOpacity(options: CameraOpacityOptions): Promise<{}>;\n setZoom(options: CameraPreviewOptions): Promise<void>;\n getSupportedZoomLevels(): Promise<{\n result: any[];\n }>;\n}"]}
package/dist/esm/web.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
11
11
  stop(): Promise<any>;
12
12
  capture(options: CameraPreviewPictureOptions): Promise<any>;
13
13
  captureSample(_options: CameraSampleOptions): Promise<any>;
14
+ setZoom(_options: CameraPreviewOptions): Promise<void>;
14
15
  getSupportedFlashModes(): Promise<{
15
16
  result: CameraPreviewFlashMode[];
16
17
  }>;
package/dist/esm/web.js CHANGED
@@ -128,6 +128,9 @@ export class CameraPreviewWeb extends WebPlugin {
128
128
  async captureSample(_options) {
129
129
  return this.capture(_options);
130
130
  }
131
+ async setZoom(_options) {
132
+ throw new Error('set zoom not supported under the web platform');
133
+ }
131
134
  async getSupportedFlashModes() {
132
135
  throw new Error('getSupportedFlashModes not supported under the web platform');
133
136
  }
@@ -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,CAAC,OAA6B;QACvC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;;YAC3C,MAAM,SAAS,CAAC,YAAY;i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AC;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 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\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,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,CAAC,OAA6B;QACvC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;;YAC3C,MAAM,SAAS,CAAC,YAAY;iBACzB,YAAY,CAAC;gBACZ,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;gBAC5B,KAAK,EAAE,IAAI;aACZ,CAAC;iBACD,IAAI,CAAC,CAAC,MAAmB,EAAE,EAAE;gBAC5B,kGAAkG;gBAClG,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,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@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\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);"]}
@@ -132,6 +132,9 @@ class CameraPreviewWeb extends core.WebPlugin {
132
132
  async captureSample(_options) {
133
133
  return this.capture(_options);
134
134
  }
135
+ async setZoom(_options) {
136
+ throw new Error('set zoom not supported under the web platform');
137
+ }
135
138
  async getSupportedFlashModes() {
136
139
  throw new Error('getSupportedFlashModes not supported under the web platform');
137
140
  }
@@ -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 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 };\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,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QAAQ,EAAE;AAClC,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACtC,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,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","/* 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 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":";;;;;;AAC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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;;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -129,6 +129,9 @@ var capacitorCameraPreview = (function (exports, core) {
129
129
  async captureSample(_options) {
130
130
  return this.capture(_options);
131
131
  }
132
+ async setZoom(_options) {
133
+ throw new Error('set zoom not supported under the web platform');
134
+ }
132
135
  async getSupportedFlashModes() {
133
136
  throw new Error('getSupportedFlashModes not supported under the web platform');
134
137
  }
@@ -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","/* 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 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 };\nregisterWebPlugin(CameraPreview);\n//# sourceMappingURL=web.js.map"],"names":["CameraPreview","registerPlugin","WebPlugin","registerWebPlugin"],"mappings":";;;AACK,UAACA,eAAa,GAAGC,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICHD;IAOO,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC;IACd,YAAY,IAAI,EAAE,eAAe;IACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;IAC9B,SAAS,CAAC,CAAC;IACX;IACA;IACA;IACA;IACA,QAAQ,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAClC,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,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AAC,6DAA6D,CAAC,CAAC;IACvF,KAAK;IACL,IAAI,sBAAsB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IACxF,KAAK;IACL,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAC7E,KAAK;IACL,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACrE,KAAK;IACL,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;IAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/E,SAAS;IACT,KAAK;IACL,CAAC;IACD,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAE7CC,0BAAiB,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;"}
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","/* 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 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,UAACA,eAAa,GAAGC,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAA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gBAAgB,EAAE,CAAC;AAE7CC,0BAAiB,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;"}
@@ -263,6 +263,55 @@ extension CameraController {
263
263
 
264
264
  captureSession.commitConfiguration()
265
265
  }
266
+ func setZoom(lens: String) throws {
267
+ print(lens)
268
+ guard let captureSession = self.captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }
269
+
270
+ captureSession.beginConfiguration()
271
+
272
+ guard let rearCameraInput = self.rearCameraInput, captureSession.inputs.contains(rearCameraInput) else { throw CameraControllerError.invalidOperation }
273
+
274
+ var session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,.builtInUltraWideCamera,.builtInTelephotoCamera], mediaType: AVMediaType.video, position: .unspecified)
275
+ if(lens == "ultra"){
276
+ session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,.builtInUltraWideCamera], mediaType: AVMediaType.video, position: .unspecified)
277
+ } else if(lens == "wide"){
278
+ session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
279
+ } else if(lens == "tele"){
280
+ session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,.builtInTelephotoCamera], mediaType: AVMediaType.video, position: .unspecified)
281
+ }
282
+ let cameras = session.devices.compactMap { $0 }
283
+ guard !cameras.isEmpty else { throw CameraControllerError.noCamerasAvailable }
284
+
285
+ for camera in cameras {
286
+ if camera.position == .front {
287
+ self.frontCamera = camera
288
+ }
289
+
290
+ if camera.position == .back {
291
+ self.rearCamera = camera
292
+
293
+ try camera.lockForConfiguration()
294
+ camera.focusMode = .continuousAutoFocus
295
+ camera.unlockForConfiguration()
296
+ }
297
+ }
298
+
299
+ if let inputs = captureSession.inputs as? [AVCaptureDeviceInput] {
300
+ for input in inputs {
301
+ captureSession.removeInput(input)
302
+ }
303
+ }
304
+ captureSession.commitConfiguration()
305
+
306
+ self.rearCameraInput = try AVCaptureDeviceInput(device: rearCamera!)
307
+
308
+ //captureSession.removeInput(frontCameraInput)
309
+
310
+ if captureSession.canAddInput(self.rearCameraInput!) {
311
+ captureSession.addInput(self.rearCameraInput!)
312
+ self.currentCameraPosition = .rear
313
+ }
314
+ }
266
315
 
267
316
  func captureImage(completion: @escaping (UIImage?, Error?) -> Void) {
268
317
  guard let captureSession = captureSession, captureSession.isRunning else { completion(nil, CameraControllerError.captureSessionIsMissing); return }
@@ -9,6 +9,7 @@ CAP_PLUGIN(CameraPreview, "CameraPreview",
9
9
  CAP_PLUGIN_METHOD(capture, CAPPluginReturnPromise);
10
10
  CAP_PLUGIN_METHOD(captureSample, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(setZoom, CAPPluginReturnPromise);
12
13
  CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise);
13
14
  CAP_PLUGIN_METHOD(getSupportedZoomLevels, CAPPluginReturnPromise);
14
15
  CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-community-multilens-camerapreview",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "fork of capacitor community camera preview with support for switchting lenses",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",