capacitor-community-multilens-camerapreview 0.0.9-a → 0.0.9-a1
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 +10 -0
- package/dist/docs.json +10 -0
- package/dist/esm/definitions.d.ts +1 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +1 -0
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +3 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npx cap sync
|
|
|
20
20
|
* [`getSupportedFlashModes()`](#getsupportedflashmodes)
|
|
21
21
|
* [`setFlashMode(...)`](#setflashmode)
|
|
22
22
|
* [`flip()`](#flip)
|
|
23
|
+
* [`changeOrientation()`](#changeorientation)
|
|
23
24
|
* [`setOpacity(...)`](#setopacity)
|
|
24
25
|
* [`setZoom(...)`](#setzoom)
|
|
25
26
|
* [`getSupportedZoomLevels()`](#getsupportedzoomlevels)
|
|
@@ -120,6 +121,15 @@ flip() => Promise<void>
|
|
|
120
121
|
--------------------
|
|
121
122
|
|
|
122
123
|
|
|
124
|
+
### changeOrientation()
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
changeOrientation() => Promise<void>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
--------------------
|
|
131
|
+
|
|
132
|
+
|
|
123
133
|
### setOpacity(...)
|
|
124
134
|
|
|
125
135
|
```typescript
|
package/dist/docs.json
CHANGED
|
@@ -109,6 +109,16 @@
|
|
|
109
109
|
"complexTypes": [],
|
|
110
110
|
"slug": "flip"
|
|
111
111
|
},
|
|
112
|
+
{
|
|
113
|
+
"name": "changeOrientation",
|
|
114
|
+
"signature": "() => Promise<void>",
|
|
115
|
+
"parameters": [],
|
|
116
|
+
"returns": "Promise<void>",
|
|
117
|
+
"tags": [],
|
|
118
|
+
"docs": "",
|
|
119
|
+
"complexTypes": [],
|
|
120
|
+
"slug": "changeorientation"
|
|
121
|
+
},
|
|
112
122
|
{
|
|
113
123
|
"name": "setOpacity",
|
|
114
124
|
"signature": "(options: CameraOpacityOptions) => Promise<{}>",
|
|
@@ -72,6 +72,7 @@ export interface CameraPreviewPlugin {
|
|
|
72
72
|
flashMode: CameraPreviewFlashMode | string;
|
|
73
73
|
}): Promise<void>;
|
|
74
74
|
flip(): Promise<void>;
|
|
75
|
+
changeOrientation(): Promise<void>;
|
|
75
76
|
setOpacity(options: CameraOpacityOptions): Promise<{}>;
|
|
76
77
|
setZoom(options: CameraPreviewOptions): Promise<void>;
|
|
77
78
|
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 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":"","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}"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
|
|
|
22
22
|
flashMode: CameraPreviewFlashMode | string;
|
|
23
23
|
}): Promise<void>;
|
|
24
24
|
flip(): Promise<void>;
|
|
25
|
+
changeOrientation(): Promise<void>;
|
|
25
26
|
setOpacity(_options: CameraOpacityOptions): Promise<any>;
|
|
26
27
|
}
|
|
27
28
|
declare const CameraPreview: CameraPreviewWeb;
|
package/dist/esm/web.js
CHANGED
|
@@ -143,6 +143,9 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
143
143
|
async flip() {
|
|
144
144
|
throw new Error('flip not supported under the web platform');
|
|
145
145
|
}
|
|
146
|
+
async changeOrientation() {
|
|
147
|
+
throw new Error('changeOrientation not supported under the web platform');
|
|
148
|
+
}
|
|
146
149
|
async setOpacity(_options) {
|
|
147
150
|
const video = document.getElementById('video');
|
|
148
151
|
if (!!video && !!_options['opacity']) {
|
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AAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAwD;QACzE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,QAA8B;QAC7C,MAAM,KAAK,GAAqB,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,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\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
|
+
{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AAsB;QACpB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAwD;QACzE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,KAAK,CAAC,iBAAiB;QACrB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,QAA8B;QAC7C,MAAM,KAAK,GAAqB,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,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);"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -147,6 +147,9 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
147
147
|
async flip() {
|
|
148
148
|
throw new Error('flip not supported under the web platform');
|
|
149
149
|
}
|
|
150
|
+
async changeOrientation() {
|
|
151
|
+
throw new Error('changeOrientation not supported under the web platform');
|
|
152
|
+
}
|
|
150
153
|
async setOpacity(_options) {
|
|
151
154
|
const video = document.getElementById('video');
|
|
152
155
|
if (!!video && !!_options['opacity']) {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -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 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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AE;AAC5B,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,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 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","registerPlug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AAC,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;;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -144,6 +144,9 @@ var capacitorCameraPreview = (function (exports, core) {
|
|
|
144
144
|
async flip() {
|
|
145
145
|
throw new Error('flip not supported under the web platform');
|
|
146
146
|
}
|
|
147
|
+
async changeOrientation() {
|
|
148
|
+
throw new Error('changeOrientation not supported under the web platform');
|
|
149
|
+
}
|
|
147
150
|
async setOpacity(_options) {
|
|
148
151
|
const video = document.getElementById('video');
|
|
149
152
|
if (!!video && !!_options['opacity']) {
|
package/dist/plugin.js.map
CHANGED
|
@@ -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 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,EAAE,CAAC;IACpE,CAAC;;ICHD;IAOO,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IA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"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 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,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,MAAM,KAAK;IACtD,YAAY,IAAI,EAAE,CAAC;IACnB,YAAY,MAAM,SAAS,CAAC,YAAY;IACxC,iBAAiB,YAAY,CAAC;IAC9B,gBAAgB,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;IAC5C,gBAAgB,KAAK,EAAE,IAAI;IAC3B,aAAa,CAAC;IACd,iBAAiB,IAAI,CAAC,CAAC,MAAM,KAAK;IAClC;IACA,gBAAgB,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,aAAa,CAAC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AG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACrE,KAAK;IACL,IAAI,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAClF,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;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-community-multilens-camerapreview",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9a1",
|
|
4
4
|
"description": "fork of capacitor community camera preview with support for switchting lenses and changing orientation",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|