@capgo/camera-preview 3.2.8 → 3.3.1

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.
Files changed (34) hide show
  1. package/CapgoCameraPreview.podspec +1 -1
  2. package/README.md +234 -46
  3. package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
  4. package/android/.gradle/7.4.2/checksums/md5-checksums.bin +0 -0
  5. package/android/.gradle/7.4.2/checksums/sha1-checksums.bin +0 -0
  6. package/android/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  7. package/android/.gradle/7.4.2/dependencies-accessors/gc.properties +0 -0
  8. package/android/.gradle/7.4.2/executionHistory/executionHistory.lock +0 -0
  9. package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
  10. package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
  11. package/android/.gradle/7.4.2/gc.properties +0 -0
  12. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  13. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  14. package/android/.gradle/vcs-1/gc.properties +0 -0
  15. package/android/build.gradle +8 -8
  16. package/android/gradle/wrapper/gradle-wrapper.properties +2 -3
  17. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +5 -7
  18. package/dist/docs.json +373 -0
  19. package/dist/esm/definitions.d.ts +3 -3
  20. package/dist/esm/index.d.ts +1 -1
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/web.d.ts +2 -2
  23. package/dist/esm/web.js +64 -65
  24. package/dist/esm/web.js.map +1 -1
  25. package/dist/plugin.cjs.js +148 -0
  26. package/dist/plugin.cjs.js.map +1 -0
  27. package/dist/plugin.js +151 -0
  28. package/dist/plugin.js.map +1 -0
  29. package/ios/Plugin/CameraController.swift +1 -1
  30. package/ios/Plugin/Plugin.swift +5 -5
  31. package/ios/Plugin.xcodeproj/project.pbxproj +8 -2
  32. package/ios/Podfile +1 -1
  33. package/ios/Podfile.lock +4 -4
  34. package/package.json +40 -35
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const CameraPreview$1 = core.registerPlugin('CameraPreview', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
7
+ });
8
+
9
+ class CameraPreviewWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super({
12
+ name: 'CameraPreview',
13
+ platforms: ['web'],
14
+ });
15
+ }
16
+ async start(options) {
17
+ var _a;
18
+ await navigator.mediaDevices
19
+ .getUserMedia({
20
+ audio: !options.disableAudio,
21
+ video: true,
22
+ })
23
+ .then((stream) => {
24
+ // Stop any existing stream so we can request media with different constraints based on user input
25
+ stream.getTracks().forEach((track) => track.stop());
26
+ })
27
+ .catch((error) => {
28
+ Promise.reject(error);
29
+ });
30
+ const video = document.getElementById('video');
31
+ const parent = document.getElementById(options.parent);
32
+ if (!video) {
33
+ const videoElement = document.createElement('video');
34
+ videoElement.id = 'video';
35
+ videoElement.setAttribute('class', options.className || '');
36
+ // Don't flip video feed if camera is rear facing
37
+ if (options.position !== 'rear') {
38
+ videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');
39
+ }
40
+ const userAgent = navigator.userAgent.toLowerCase();
41
+ const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');
42
+ // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
43
+ // Without these attributes videoElement.play() will throw a NotAllowedError
44
+ // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
45
+ if (isSafari) {
46
+ videoElement.setAttribute('autoplay', 'true');
47
+ videoElement.setAttribute('muted', 'true');
48
+ videoElement.setAttribute('playsinline', 'true');
49
+ }
50
+ parent.appendChild(videoElement);
51
+ if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
52
+ const constraints = {
53
+ video: {
54
+ width: { ideal: options.width },
55
+ height: { ideal: options.height },
56
+ },
57
+ };
58
+ if (options.position === 'rear') {
59
+ constraints.video.facingMode = 'environment';
60
+ this.isBackCamera = true;
61
+ }
62
+ else {
63
+ this.isBackCamera = false;
64
+ }
65
+ navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
66
+ //video.src = window.URL.createObjectURL(stream);
67
+ videoElement.srcObject = stream;
68
+ videoElement.play();
69
+ Promise.resolve();
70
+ }, (err) => {
71
+ Promise.reject(err);
72
+ });
73
+ }
74
+ }
75
+ else {
76
+ Promise.reject({ message: 'camera already started' });
77
+ }
78
+ }
79
+ async stop() {
80
+ const video = document.getElementById('video');
81
+ if (video) {
82
+ video.pause();
83
+ const st = video.srcObject;
84
+ const tracks = st.getTracks();
85
+ for (const i in tracks) {
86
+ const track = tracks[i];
87
+ track.stop();
88
+ }
89
+ video.remove();
90
+ }
91
+ }
92
+ async capture(options) {
93
+ return new Promise((resolve, _) => {
94
+ const video = document.getElementById('video');
95
+ const canvas = document.createElement('canvas');
96
+ // video.width = video.offsetWidth;
97
+ const context = canvas.getContext('2d');
98
+ canvas.width = video.videoWidth;
99
+ canvas.height = video.videoHeight;
100
+ // flip horizontally back camera isn't used
101
+ if (!this.isBackCamera) {
102
+ context.translate(video.videoWidth, 0);
103
+ context.scale(-1, 1);
104
+ }
105
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
106
+ let base64EncodedImage;
107
+ if (options.quality != undefined) {
108
+ base64EncodedImage = canvas
109
+ .toDataURL('image/jpeg', options.quality / 100.0)
110
+ .replace('data:image/jpeg;base64,', '');
111
+ }
112
+ else {
113
+ base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
114
+ }
115
+ resolve({
116
+ value: base64EncodedImage,
117
+ });
118
+ });
119
+ }
120
+ async captureSample(_options) {
121
+ return this.capture(_options);
122
+ }
123
+ async getSupportedFlashModes() {
124
+ throw new Error('getSupportedFlashModes not supported under the web platform');
125
+ }
126
+ async setFlashMode(_options) {
127
+ throw new Error('setFlashMode not supported under the web platform' + _options);
128
+ }
129
+ async flip() {
130
+ throw new Error('flip not supported under the web platform');
131
+ }
132
+ async setOpacity(_options) {
133
+ const video = document.getElementById('video');
134
+ if (!!video && !!_options['opacity']) {
135
+ video.style.setProperty('opacity', _options['opacity'].toString());
136
+ }
137
+ }
138
+ }
139
+ const CameraPreview = new CameraPreviewWeb();
140
+
141
+ var web = /*#__PURE__*/Object.freeze({
142
+ __proto__: null,
143
+ CameraPreviewWeb: CameraPreviewWeb,
144
+ CameraPreview: CameraPreview
145
+ });
146
+
147
+ exports.CameraPreview = CameraPreview$1;
148
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\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 Promise.reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator === null || navigator === void 0 ? void 0 : 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 Promise.resolve();\n }, (err) => {\n Promise.reject(err);\n });\n }\n }\n else {\n Promise.reject({ message: 'camera already started' });\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 (const i in tracks) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform' + _options);\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n}\nconst CameraPreview = new CameraPreviewWeb();\nexport { CameraPreview };\n//# sourceMappingURL=web.js.map"],"names":["CameraPreview","registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAACA,eAAa,GAAGC,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;AAC9B,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,EAAE,CAAC;AACf,QAAQ,MAAM,SAAS,CAAC,YAAY;AACpC,aAAa,YAAY,CAAC;AAC1B,YAAY,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;AACxC,YAAY,KAAK,EAAE,IAAI;AACvB,SAAS,CAAC;AACV,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK;AAC9B;AACA,YAAY,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAChE,SAAS,CAAC;AACV,aAAa,KAAK,CAAC,CAAC,KAAK,KAAK;AAC9B,YAAY,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClC,SAAS,CAAC,CAAC;AACX,Q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T,KAAK;AACL,CAAC;AACD,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAE;;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,151 @@
1
+ var capacitorApp = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const CameraPreview$1 = core.registerPlugin('CameraPreview', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
6
+ });
7
+
8
+ class CameraPreviewWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super({
11
+ name: 'CameraPreview',
12
+ platforms: ['web'],
13
+ });
14
+ }
15
+ async start(options) {
16
+ var _a;
17
+ await navigator.mediaDevices
18
+ .getUserMedia({
19
+ audio: !options.disableAudio,
20
+ video: true,
21
+ })
22
+ .then((stream) => {
23
+ // Stop any existing stream so we can request media with different constraints based on user input
24
+ stream.getTracks().forEach((track) => track.stop());
25
+ })
26
+ .catch((error) => {
27
+ Promise.reject(error);
28
+ });
29
+ const video = document.getElementById('video');
30
+ const parent = document.getElementById(options.parent);
31
+ if (!video) {
32
+ const videoElement = document.createElement('video');
33
+ videoElement.id = 'video';
34
+ videoElement.setAttribute('class', options.className || '');
35
+ // Don't flip video feed if camera is rear facing
36
+ if (options.position !== 'rear') {
37
+ videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');
38
+ }
39
+ const userAgent = navigator.userAgent.toLowerCase();
40
+ const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');
41
+ // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
42
+ // Without these attributes videoElement.play() will throw a NotAllowedError
43
+ // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
44
+ if (isSafari) {
45
+ videoElement.setAttribute('autoplay', 'true');
46
+ videoElement.setAttribute('muted', 'true');
47
+ videoElement.setAttribute('playsinline', 'true');
48
+ }
49
+ parent.appendChild(videoElement);
50
+ if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
51
+ const constraints = {
52
+ video: {
53
+ width: { ideal: options.width },
54
+ height: { ideal: options.height },
55
+ },
56
+ };
57
+ if (options.position === 'rear') {
58
+ constraints.video.facingMode = 'environment';
59
+ this.isBackCamera = true;
60
+ }
61
+ else {
62
+ this.isBackCamera = false;
63
+ }
64
+ navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
65
+ //video.src = window.URL.createObjectURL(stream);
66
+ videoElement.srcObject = stream;
67
+ videoElement.play();
68
+ Promise.resolve();
69
+ }, (err) => {
70
+ Promise.reject(err);
71
+ });
72
+ }
73
+ }
74
+ else {
75
+ Promise.reject({ message: 'camera already started' });
76
+ }
77
+ }
78
+ async stop() {
79
+ const video = document.getElementById('video');
80
+ if (video) {
81
+ video.pause();
82
+ const st = video.srcObject;
83
+ const tracks = st.getTracks();
84
+ for (const i in tracks) {
85
+ const track = tracks[i];
86
+ track.stop();
87
+ }
88
+ video.remove();
89
+ }
90
+ }
91
+ async capture(options) {
92
+ return new Promise((resolve, _) => {
93
+ const video = document.getElementById('video');
94
+ const canvas = document.createElement('canvas');
95
+ // video.width = video.offsetWidth;
96
+ const context = canvas.getContext('2d');
97
+ canvas.width = video.videoWidth;
98
+ canvas.height = video.videoHeight;
99
+ // flip horizontally back camera isn't used
100
+ if (!this.isBackCamera) {
101
+ context.translate(video.videoWidth, 0);
102
+ context.scale(-1, 1);
103
+ }
104
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
105
+ let base64EncodedImage;
106
+ if (options.quality != undefined) {
107
+ base64EncodedImage = canvas
108
+ .toDataURL('image/jpeg', options.quality / 100.0)
109
+ .replace('data:image/jpeg;base64,', '');
110
+ }
111
+ else {
112
+ base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
113
+ }
114
+ resolve({
115
+ value: base64EncodedImage,
116
+ });
117
+ });
118
+ }
119
+ async captureSample(_options) {
120
+ return this.capture(_options);
121
+ }
122
+ async getSupportedFlashModes() {
123
+ throw new Error('getSupportedFlashModes not supported under the web platform');
124
+ }
125
+ async setFlashMode(_options) {
126
+ throw new Error('setFlashMode not supported under the web platform' + _options);
127
+ }
128
+ async flip() {
129
+ throw new Error('flip not supported under the web platform');
130
+ }
131
+ async setOpacity(_options) {
132
+ const video = document.getElementById('video');
133
+ if (!!video && !!_options['opacity']) {
134
+ video.style.setProperty('opacity', _options['opacity'].toString());
135
+ }
136
+ }
137
+ }
138
+ const CameraPreview = new CameraPreviewWeb();
139
+
140
+ var web = /*#__PURE__*/Object.freeze({
141
+ __proto__: null,
142
+ CameraPreviewWeb: CameraPreviewWeb,
143
+ CameraPreview: CameraPreview
144
+ });
145
+
146
+ exports.CameraPreview = CameraPreview$1;
147
+
148
+ return exports;
149
+
150
+ })({}, capacitorExports);
151
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\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 Promise.reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator === null || navigator === void 0 ? void 0 : 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 Promise.resolve();\n }, (err) => {\n Promise.reject(err);\n });\n }\n }\n else {\n Promise.reject({ message: 'camera already started' });\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 (const i in tracks) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform' + _options);\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n}\nconst CameraPreview = new CameraPreviewWeb();\nexport { CameraPreview };\n//# sourceMappingURL=web.js.map"],"names":["CameraPreview","registerPlugin","WebPlugin"],"mappings":";;;AACK,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;;ICFM,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,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE,CAAC;IACf,QAAQ,MAAM,SAAS,CAAC,YAAY;IACpC,aAAa,YAAY,CAAC;IAC1B,YAAY,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;IACxC,YAAY,KAAK,EAAE,IAAI;IACvB,SAAS,CAAC;IACV,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK;IAC9B;IACA,YAAY,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,SAAS,CAAC;IACV,aAAa,KAAK,CAAC,CAAC,KAAK,K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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;;;;;;;;;;;;;;;;"}
@@ -487,7 +487,7 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
487
487
  public func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
488
488
  resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Swift.Error?) {
489
489
  if let error = error { self.photoCaptureCompletionBlock?(nil, error) } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
490
- let image = UIImage(data: data) {
490
+ let image = UIImage(data: data) {
491
491
  self.photoCaptureCompletionBlock?(image.fixedOrientation(), nil)
492
492
  } else {
493
493
  self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
@@ -24,7 +24,7 @@ public class CameraPreview: CAPPlugin {
24
24
  var disableAudio: Bool = false
25
25
 
26
26
  @objc func rotated() {
27
- let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
27
+ let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!
28
28
 
29
29
  if UIApplication.shared.statusBarOrientation.isLandscape {
30
30
  self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: max(height, self.width!), height: min(height, self.width!))
@@ -32,7 +32,7 @@ public class CameraPreview: CAPPlugin {
32
32
  }
33
33
 
34
34
  if UIApplication.shared.statusBarOrientation.isPortrait {
35
- if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
35
+ if self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil {
36
36
  self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: min(height, self.width!), height: max(height, self.width!))
37
37
  }
38
38
  self.cameraController.previewLayer?.frame = self.previewView.frame
@@ -67,7 +67,7 @@ public class CameraPreview: CAPPlugin {
67
67
  self.storeToFile = call.getBool("storeToFile") ?? false
68
68
  self.enableZoom = call.getBool("enableZoom") ?? false
69
69
  self.disableAudio = call.getBool("disableAudio") ?? false
70
-
70
+
71
71
  AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
72
72
  guard granted else {
73
73
  call.reject("permission failed")
@@ -78,7 +78,7 @@ public class CameraPreview: CAPPlugin {
78
78
  if self.cameraController.captureSession?.isRunning ?? false {
79
79
  call.reject("camera already started")
80
80
  } else {
81
- self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio){error in
81
+ self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio) {error in
82
82
  if let error = error {
83
83
  print(error)
84
84
  call.reject(error.localizedDescription)
@@ -235,7 +235,7 @@ public class CameraPreview: CAPPlugin {
235
235
  do {
236
236
  var flashModeAsEnum: AVCaptureDevice.FlashMode?
237
237
  switch flashMode {
238
- case "off" :
238
+ case "off":
239
239
  flashModeAsEnum = AVCaptureDevice.FlashMode.off
240
240
  case "on":
241
241
  flashModeAsEnum = AVCaptureDevice.FlashMode.on
@@ -493,12 +493,15 @@
493
493
  DYLIB_INSTALL_NAME_BASE = "@rpath";
494
494
  INFOPLIST_FILE = Plugin/Info.plist;
495
495
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
496
- IPHONEOS_DEPLOYMENT_TARGET = 12.1;
496
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
497
497
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)";
498
498
  ONLY_ACTIVE_ARCH = YES;
499
499
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
500
500
  PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
501
501
  SKIP_INSTALL = YES;
502
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
503
+ SUPPORTS_MACCATALYST = NO;
504
+ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
502
505
  SWIFT_OPTIMIZATION_LEVEL = "-Onone";
503
506
  SWIFT_VERSION = 4.2;
504
507
  TARGETED_DEVICE_FAMILY = "1,2";
@@ -518,12 +521,15 @@
518
521
  DYLIB_INSTALL_NAME_BASE = "@rpath";
519
522
  INFOPLIST_FILE = Plugin/Info.plist;
520
523
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
521
- IPHONEOS_DEPLOYMENT_TARGET = 12.1;
524
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
522
525
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
523
526
  ONLY_ACTIVE_ARCH = NO;
524
527
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
525
528
  PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
526
529
  SKIP_INSTALL = YES;
530
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
531
+ SUPPORTS_MACCATALYST = NO;
532
+ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
527
533
  SWIFT_VERSION = 4.2;
528
534
  TARGETED_DEVICE_FAMILY = "1,2";
529
535
  };
package/ios/Podfile CHANGED
@@ -1,4 +1,4 @@
1
- platform :ios, '12.1'
1
+ platform :ios, '13.0'
2
2
 
3
3
  target 'Plugin' do
4
4
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
package/ios/Podfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  PODS:
2
- - Capacitor (3.0.0):
2
+ - Capacitor (4.4.0):
3
3
  - CapacitorCordova
4
4
  - CapacitorCordova (2.0.1)
5
5
 
@@ -15,9 +15,9 @@ EXTERNAL SOURCES:
15
15
  :path: "../node_modules/@capacitor/ios"
16
16
 
17
17
  SPEC CHECKSUMS:
18
- Capacitor: 06cd8cd01340f5b162e9528bf5569d87a6f29009
18
+ Capacitor: 868367fcfeb3ba6bfabaefc63c072e6478bd046d
19
19
  CapacitorCordova: 9fee2eb6780331b6ff09710d6a7d1f2e4707f1b9
20
20
 
21
- PODFILE CHECKSUM: d3e2703a3105a8e75e11dfc45c25f5cbf9801486
21
+ PODFILE CHECKSUM: e80ffb7ef3a0ac7d0d6143f3e64f287d4d027c84
22
22
 
23
- COCOAPODS: 1.9.3
23
+ COCOAPODS: 1.11.3
package/package.json CHANGED
@@ -1,58 +1,52 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "3.2.8",
3
+ "version": "3.3.1",
4
4
  "description": "Camera preview",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
7
7
  "scripts": {
8
- "build": "npm run clean && tsc",
9
- "clean": "rimraf './dist'",
10
- "watch": "tsc --watch",
11
- "lint": "concurrently -g \"npm:eslint\" \"npm:prettier -- --check\" \"npm run swiftlint -- lint ios\"",
12
- "fmt": "concurrently -g \"npm:eslint -- --fix\" \"npm:prettier -- --write\" \"npm:swiftlint -- lint --fix --format ios\"",
8
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
9
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
10
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
11
+ "verify:web": "npm run build",
12
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
13
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
13
14
  "eslint": "eslint . --ext ts",
14
15
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
15
16
  "swiftlint": "node-swiftlint",
17
+ "docgen": "docgen --api CameraPreviewPlugin --output-readme README.md --output-json dist/docs.json",
18
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
19
+ "clean": "rimraf ./dist && cd android && ./gradlew clean && cd ..",
20
+ "watch": "tsc --watch",
16
21
  "prepublishOnly": "npm run build",
17
- "prepare": "husky install && npm run build"
22
+ "prepare": "husky install"
18
23
  },
19
- "author": "Martin Donadieu",
24
+ "author": "Martin Donadieu <martindonadieu@gmail.com>",
20
25
  "license": "MIT",
21
- "dependencies": {
22
- "@capacitor/core": "latest"
23
- },
24
26
  "devDependencies": {
25
- "@capacitor/android": "latest",
26
- "@capacitor/ios": "latest",
27
+ "@capacitor/android": "^4.4.0",
28
+ "@capacitor/cli": "^4.4.0",
29
+ "@capacitor/core": "^4.4.0",
30
+ "@capacitor/docgen": "^0.2.0",
31
+ "@capacitor/ios": "^4.4.0",
27
32
  "@ionic/eslint-config": "^0.3.0",
28
33
  "@ionic/prettier-config": "^2.0.0",
29
34
  "@ionic/swiftlint-config": "^1.1.2",
30
- "concurrently": "^7.0.0",
31
- "eslint": "^7.32.0",
32
- "husky": "^7.0.4",
33
- "prettier": "^2.5.1",
34
- "prettier-plugin-java": "^1.6.1",
35
- "pretty-quick": "^3.1.3",
35
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
36
+ "@typescript-eslint/parser": "^5.42.1",
37
+ "eslint": "^8.27.0",
38
+ "eslint-plugin-import": "^2.26.0",
39
+ "husky": "^8.0.2",
40
+ "prettier": "^2.7.1",
41
+ "prettier-plugin-java": "^1.6.2",
36
42
  "rimraf": "^3.0.2",
43
+ "rollup": "^3.2.5",
37
44
  "swiftlint": "^1.0.1",
38
- "typescript": "^4.3.2"
45
+ "typescript": "^4.8.4"
39
46
  },
40
- "husky": {
41
- "hooks": {
42
- "pre-commit": "pretty-quick --staged"
43
- }
47
+ "peerDependencies": {
48
+ "@capacitor/core": "^4.0.0"
44
49
  },
45
- "files": [
46
- "dist/",
47
- "ios/",
48
- "android/",
49
- "CapgoCameraPreview.podspec"
50
- ],
51
- "keywords": [
52
- "capacitor",
53
- "plugin",
54
- "native"
55
- ],
56
50
  "capacitor": {
57
51
  "ios": {
58
52
  "src": "ios"
@@ -66,6 +60,17 @@
66
60
  "eslintConfig": {
67
61
  "extends": "@ionic/eslint-config/recommended"
68
62
  },
63
+ "files": [
64
+ "dist/",
65
+ "ios/",
66
+ "android/",
67
+ "CapgoCameraPreview.podspec"
68
+ ],
69
+ "keywords": [
70
+ "capacitor",
71
+ "plugin",
72
+ "native"
73
+ ],
69
74
  "repository": {
70
75
  "type": "git",
71
76
  "url": "https://github.com/Cap-go/camera-preview.git"