@capgo/camera-preview 3.6.22 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -405
- package/android/build.gradle +8 -7
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -2
- package/android/gradle.properties +1 -1
- package/android/gradlew +14 -4
- package/android/gradlew.bat +34 -32
- package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +6 -6
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +1105 -854
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +543 -428
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +15 -10
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +31 -21
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +386 -332
- package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +13 -13
- package/android/src/test/java/com/getcapacitor/ExampleUnitTest.java +4 -4
- package/dist/docs.json +208 -37
- package/dist/esm/definitions.d.ts +76 -3
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +39 -36
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +39 -36
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +39 -36
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraController.swift +1 -1
- package/ios/Plugin/Plugin.swift +1 -1
- package/ios/Podfile.lock +3 -3
- package/package.json +22 -22
- package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4.2/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.4.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
package/dist/esm/web.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { WebPlugin } from
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
2
|
export class CameraPreviewWeb extends WebPlugin {
|
|
3
3
|
constructor() {
|
|
4
4
|
super({
|
|
5
|
-
name:
|
|
6
|
-
platforms: [
|
|
5
|
+
name: "CameraPreview",
|
|
6
|
+
platforms: ["web"],
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
async start(options) {
|
|
@@ -20,25 +20,25 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
20
20
|
.catch((error) => {
|
|
21
21
|
Promise.reject(error);
|
|
22
22
|
});
|
|
23
|
-
const video = document.getElementById(
|
|
23
|
+
const video = document.getElementById("video");
|
|
24
24
|
const parent = document.getElementById(options.parent);
|
|
25
25
|
if (!video) {
|
|
26
|
-
const videoElement = document.createElement(
|
|
27
|
-
videoElement.id =
|
|
28
|
-
videoElement.setAttribute(
|
|
26
|
+
const videoElement = document.createElement("video");
|
|
27
|
+
videoElement.id = "video";
|
|
28
|
+
videoElement.setAttribute("class", options.className || "");
|
|
29
29
|
// Don't flip video feed if camera is rear facing
|
|
30
|
-
if (options.position !==
|
|
31
|
-
videoElement.setAttribute(
|
|
30
|
+
if (options.position !== "rear") {
|
|
31
|
+
videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);");
|
|
32
32
|
}
|
|
33
33
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
34
|
-
const isSafari = userAgent.includes(
|
|
34
|
+
const isSafari = userAgent.includes("safari") && !userAgent.includes("chrome");
|
|
35
35
|
// Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
|
|
36
36
|
// Without these attributes videoElement.play() will throw a NotAllowedError
|
|
37
37
|
// https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
|
|
38
38
|
if (isSafari) {
|
|
39
|
-
videoElement.setAttribute(
|
|
40
|
-
videoElement.setAttribute(
|
|
41
|
-
videoElement.setAttribute(
|
|
39
|
+
videoElement.setAttribute("autoplay", "true");
|
|
40
|
+
videoElement.setAttribute("muted", "true");
|
|
41
|
+
videoElement.setAttribute("playsinline", "true");
|
|
42
42
|
}
|
|
43
43
|
parent.appendChild(videoElement);
|
|
44
44
|
if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
|
|
@@ -48,8 +48,9 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
48
48
|
height: { ideal: options.height },
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
if (options.position ===
|
|
52
|
-
constraints.video.facingMode =
|
|
51
|
+
if (options.position === "rear") {
|
|
52
|
+
constraints.video.facingMode =
|
|
53
|
+
"environment";
|
|
53
54
|
this.isBackCamera = true;
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
@@ -57,7 +58,7 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
57
58
|
}
|
|
58
59
|
const self = this;
|
|
59
60
|
await navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
|
60
|
-
if (document.getElementById(
|
|
61
|
+
if (document.getElementById("video")) {
|
|
61
62
|
//video.src = window.URL.createObjectURL(stream);
|
|
62
63
|
videoElement.srcObject = stream;
|
|
63
64
|
videoElement.play();
|
|
@@ -65,7 +66,7 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
68
|
self.stopStream(stream);
|
|
68
|
-
Promise.reject({ message:
|
|
69
|
+
Promise.reject({ message: "camera already stopped" });
|
|
69
70
|
}
|
|
70
71
|
}, (err) => {
|
|
71
72
|
Promise.reject(err);
|
|
@@ -73,7 +74,7 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
else {
|
|
76
|
-
Promise.reject({ message:
|
|
77
|
+
Promise.reject({ message: "camera already started" });
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
stopStream(stream) {
|
|
@@ -85,7 +86,7 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
async stop() {
|
|
88
|
-
const video = document.getElementById(
|
|
89
|
+
const video = document.getElementById("video");
|
|
89
90
|
if (video) {
|
|
90
91
|
video.pause();
|
|
91
92
|
this.stopStream(video.srcObject);
|
|
@@ -94,16 +95,16 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
94
95
|
}
|
|
95
96
|
async capture(options) {
|
|
96
97
|
return new Promise((resolve, reject) => {
|
|
97
|
-
const video = document.getElementById(
|
|
98
|
+
const video = document.getElementById("video");
|
|
98
99
|
if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
|
|
99
|
-
reject({ message:
|
|
100
|
+
reject({ message: "camera is not running" });
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
// video.width = video.offsetWidth;
|
|
103
104
|
let base64EncodedImage;
|
|
104
105
|
if (video && video.videoWidth > 0 && video.videoHeight > 0) {
|
|
105
|
-
const canvas = document.createElement(
|
|
106
|
-
const context = canvas.getContext(
|
|
106
|
+
const canvas = document.createElement("canvas");
|
|
107
|
+
const context = canvas.getContext("2d");
|
|
107
108
|
canvas.width = video.videoWidth;
|
|
108
109
|
canvas.height = video.videoHeight;
|
|
109
110
|
// flip horizontally back camera isn't used
|
|
@@ -112,13 +113,15 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
112
113
|
context.scale(-1, 1);
|
|
113
114
|
}
|
|
114
115
|
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
|
115
|
-
if ((options.format ||
|
|
116
|
+
if ((options.format || "jpeg") === "jpeg") {
|
|
116
117
|
base64EncodedImage = canvas
|
|
117
|
-
.toDataURL(
|
|
118
|
-
.replace(
|
|
118
|
+
.toDataURL("image/jpeg", (options.quality || 85) / 100.0)
|
|
119
|
+
.replace("data:image/jpeg;base64,", "");
|
|
119
120
|
}
|
|
120
121
|
else {
|
|
121
|
-
base64EncodedImage = canvas
|
|
122
|
+
base64EncodedImage = canvas
|
|
123
|
+
.toDataURL("image/png")
|
|
124
|
+
.replace("data:image/png;base64,", "");
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
resolve({
|
|
@@ -130,27 +133,27 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
130
133
|
return this.capture(_options);
|
|
131
134
|
}
|
|
132
135
|
async stopRecordVideo() {
|
|
133
|
-
throw new Error(
|
|
136
|
+
throw new Error("stopRecordVideo not supported under the web platform");
|
|
134
137
|
}
|
|
135
138
|
async startRecordVideo(_options) {
|
|
136
|
-
throw new Error(
|
|
139
|
+
throw new Error("startRecordVideo not supported under the web platform");
|
|
137
140
|
}
|
|
138
141
|
async getSupportedFlashModes() {
|
|
139
|
-
throw new Error(
|
|
142
|
+
throw new Error("getSupportedFlashModes not supported under the web platform");
|
|
140
143
|
}
|
|
141
144
|
async getHorizontalFov() {
|
|
142
|
-
throw new Error(
|
|
145
|
+
throw new Error("getHorizontalFov not supported under the web platform");
|
|
143
146
|
}
|
|
144
147
|
async setFlashMode(_options) {
|
|
145
|
-
throw new Error(
|
|
148
|
+
throw new Error("setFlashMode not supported under the web platform" + _options);
|
|
146
149
|
}
|
|
147
150
|
async flip() {
|
|
148
|
-
throw new Error(
|
|
151
|
+
throw new Error("flip not supported under the web platform");
|
|
149
152
|
}
|
|
150
153
|
async setOpacity(_options) {
|
|
151
|
-
const video = document.getElementById(
|
|
152
|
-
if (!!video && !!_options[
|
|
153
|
-
video.style.setProperty(
|
|
154
|
+
const video = document.getElementById("video");
|
|
155
|
+
if (!!video && !!_options["opacity"]) {
|
|
156
|
+
video.style.setProperty("opacity", _options["opacity"].toString());
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA6B;;QACvC,MAAM,SAAS,CAAC,YAAY;aACzB,YAAY,CAAC;YACZ,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;YAC5B,KAAK,EAAE,IAAI;SACZ,CAAC;aACD,IAAI,CAAC,CAAC,MAAmB,EAAE,EAAE;YAC5B,kGAAkG;YAClG,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QAEL,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEvD,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,YAAY,GA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ACH,CAAC;CACF"}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
-
const CameraPreview = core.registerPlugin(
|
|
5
|
+
const CameraPreview = core.registerPlugin("CameraPreview", {
|
|
6
6
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
class CameraPreviewWeb extends core.WebPlugin {
|
|
10
10
|
constructor() {
|
|
11
11
|
super({
|
|
12
|
-
name:
|
|
13
|
-
platforms: [
|
|
12
|
+
name: "CameraPreview",
|
|
13
|
+
platforms: ["web"],
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
async start(options) {
|
|
@@ -27,25 +27,25 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
27
27
|
.catch((error) => {
|
|
28
28
|
Promise.reject(error);
|
|
29
29
|
});
|
|
30
|
-
const video = document.getElementById(
|
|
30
|
+
const video = document.getElementById("video");
|
|
31
31
|
const parent = document.getElementById(options.parent);
|
|
32
32
|
if (!video) {
|
|
33
|
-
const videoElement = document.createElement(
|
|
34
|
-
videoElement.id =
|
|
35
|
-
videoElement.setAttribute(
|
|
33
|
+
const videoElement = document.createElement("video");
|
|
34
|
+
videoElement.id = "video";
|
|
35
|
+
videoElement.setAttribute("class", options.className || "");
|
|
36
36
|
// Don't flip video feed if camera is rear facing
|
|
37
|
-
if (options.position !==
|
|
38
|
-
videoElement.setAttribute(
|
|
37
|
+
if (options.position !== "rear") {
|
|
38
|
+
videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);");
|
|
39
39
|
}
|
|
40
40
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
41
|
-
const isSafari = userAgent.includes(
|
|
41
|
+
const isSafari = userAgent.includes("safari") && !userAgent.includes("chrome");
|
|
42
42
|
// Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
|
|
43
43
|
// Without these attributes videoElement.play() will throw a NotAllowedError
|
|
44
44
|
// https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
|
|
45
45
|
if (isSafari) {
|
|
46
|
-
videoElement.setAttribute(
|
|
47
|
-
videoElement.setAttribute(
|
|
48
|
-
videoElement.setAttribute(
|
|
46
|
+
videoElement.setAttribute("autoplay", "true");
|
|
47
|
+
videoElement.setAttribute("muted", "true");
|
|
48
|
+
videoElement.setAttribute("playsinline", "true");
|
|
49
49
|
}
|
|
50
50
|
parent.appendChild(videoElement);
|
|
51
51
|
if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
|
|
@@ -55,8 +55,9 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
55
55
|
height: { ideal: options.height },
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
if (options.position ===
|
|
59
|
-
constraints.video.facingMode =
|
|
58
|
+
if (options.position === "rear") {
|
|
59
|
+
constraints.video.facingMode =
|
|
60
|
+
"environment";
|
|
60
61
|
this.isBackCamera = true;
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
@@ -64,7 +65,7 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
64
65
|
}
|
|
65
66
|
const self = this;
|
|
66
67
|
await navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
|
67
|
-
if (document.getElementById(
|
|
68
|
+
if (document.getElementById("video")) {
|
|
68
69
|
//video.src = window.URL.createObjectURL(stream);
|
|
69
70
|
videoElement.srcObject = stream;
|
|
70
71
|
videoElement.play();
|
|
@@ -72,7 +73,7 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
75
|
self.stopStream(stream);
|
|
75
|
-
Promise.reject({ message:
|
|
76
|
+
Promise.reject({ message: "camera already stopped" });
|
|
76
77
|
}
|
|
77
78
|
}, (err) => {
|
|
78
79
|
Promise.reject(err);
|
|
@@ -80,7 +81,7 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
else {
|
|
83
|
-
Promise.reject({ message:
|
|
84
|
+
Promise.reject({ message: "camera already started" });
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
stopStream(stream) {
|
|
@@ -92,7 +93,7 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
async stop() {
|
|
95
|
-
const video = document.getElementById(
|
|
96
|
+
const video = document.getElementById("video");
|
|
96
97
|
if (video) {
|
|
97
98
|
video.pause();
|
|
98
99
|
this.stopStream(video.srcObject);
|
|
@@ -101,16 +102,16 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
101
102
|
}
|
|
102
103
|
async capture(options) {
|
|
103
104
|
return new Promise((resolve, reject) => {
|
|
104
|
-
const video = document.getElementById(
|
|
105
|
+
const video = document.getElementById("video");
|
|
105
106
|
if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
|
|
106
|
-
reject({ message:
|
|
107
|
+
reject({ message: "camera is not running" });
|
|
107
108
|
return;
|
|
108
109
|
}
|
|
109
110
|
// video.width = video.offsetWidth;
|
|
110
111
|
let base64EncodedImage;
|
|
111
112
|
if (video && video.videoWidth > 0 && video.videoHeight > 0) {
|
|
112
|
-
const canvas = document.createElement(
|
|
113
|
-
const context = canvas.getContext(
|
|
113
|
+
const canvas = document.createElement("canvas");
|
|
114
|
+
const context = canvas.getContext("2d");
|
|
114
115
|
canvas.width = video.videoWidth;
|
|
115
116
|
canvas.height = video.videoHeight;
|
|
116
117
|
// flip horizontally back camera isn't used
|
|
@@ -119,13 +120,15 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
119
120
|
context.scale(-1, 1);
|
|
120
121
|
}
|
|
121
122
|
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
|
122
|
-
if ((options.format ||
|
|
123
|
+
if ((options.format || "jpeg") === "jpeg") {
|
|
123
124
|
base64EncodedImage = canvas
|
|
124
|
-
.toDataURL(
|
|
125
|
-
.replace(
|
|
125
|
+
.toDataURL("image/jpeg", (options.quality || 85) / 100.0)
|
|
126
|
+
.replace("data:image/jpeg;base64,", "");
|
|
126
127
|
}
|
|
127
128
|
else {
|
|
128
|
-
base64EncodedImage = canvas
|
|
129
|
+
base64EncodedImage = canvas
|
|
130
|
+
.toDataURL("image/png")
|
|
131
|
+
.replace("data:image/png;base64,", "");
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
resolve({
|
|
@@ -137,27 +140,27 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
137
140
|
return this.capture(_options);
|
|
138
141
|
}
|
|
139
142
|
async stopRecordVideo() {
|
|
140
|
-
throw new Error(
|
|
143
|
+
throw new Error("stopRecordVideo not supported under the web platform");
|
|
141
144
|
}
|
|
142
145
|
async startRecordVideo(_options) {
|
|
143
|
-
throw new Error(
|
|
146
|
+
throw new Error("startRecordVideo not supported under the web platform");
|
|
144
147
|
}
|
|
145
148
|
async getSupportedFlashModes() {
|
|
146
|
-
throw new Error(
|
|
149
|
+
throw new Error("getSupportedFlashModes not supported under the web platform");
|
|
147
150
|
}
|
|
148
151
|
async getHorizontalFov() {
|
|
149
|
-
throw new Error(
|
|
152
|
+
throw new Error("getHorizontalFov not supported under the web platform");
|
|
150
153
|
}
|
|
151
154
|
async setFlashMode(_options) {
|
|
152
|
-
throw new Error(
|
|
155
|
+
throw new Error("setFlashMode not supported under the web platform" + _options);
|
|
153
156
|
}
|
|
154
157
|
async flip() {
|
|
155
|
-
throw new Error(
|
|
158
|
+
throw new Error("flip not supported under the web platform");
|
|
156
159
|
}
|
|
157
160
|
async setOpacity(_options) {
|
|
158
|
-
const video = document.getElementById(
|
|
159
|
-
if (!!video && !!_options[
|
|
160
|
-
video.style.setProperty(
|
|
161
|
+
const video = document.getElementById("video");
|
|
162
|
+
if (!!video && !!_options["opacity"]) {
|
|
163
|
+
video.style.setProperty("opacity", _options["opacity"].toString());
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
}
|
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","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 const self = this;\n await navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n if (document.getElementById('video')) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n Promise.resolve({});\n }\n else {\n self.stopStream(stream);\n Promise.reject({ message: 'camera already stopped' });\n }\n }, (err) => {\n Promise.reject(err);\n });\n }\n }\n else {\n Promise.reject({ message: 'camera already started' });\n }\n }\n stopStream(stream) {\n if (stream) {\n const tracks = stream.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n }\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n this.stopStream(video.srcObject);\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, reject) => {\n const video = document.getElementById('video');\n if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {\n reject({ message: 'camera is not running' });\n return;\n }\n // video.width = video.offsetWidth;\n let base64EncodedImage;\n if (video && video.videoWidth > 0 && video.videoHeight > 0) {\n const canvas = document.createElement('canvas');\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 if ((options.format || 'jpeg') === 'jpeg') {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', (options.quality || 85) / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async stopRecordVideo() {\n throw new Error('stopRecordVideo not supported under the web platform');\n }\n async startRecordVideo(_options) {\n throw new Error('startRecordVideo not supported under the web platform');\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async getHorizontalFov() {\n throw new Error('getHorizontalFov 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}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,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,KA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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 =\n \"environment\";\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n const self = this;\n await navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n if (document.getElementById(\"video\")) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n Promise.resolve({});\n }\n else {\n self.stopStream(stream);\n Promise.reject({ message: \"camera already stopped\" });\n }\n }, (err) => {\n Promise.reject(err);\n });\n }\n }\n else {\n Promise.reject({ message: \"camera already started\" });\n }\n }\n stopStream(stream) {\n if (stream) {\n const tracks = stream.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n }\n }\n async stop() {\n const video = document.getElementById(\"video\");\n if (video) {\n video.pause();\n this.stopStream(video.srcObject);\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, reject) => {\n const video = document.getElementById(\"video\");\n if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {\n reject({ message: \"camera is not running\" });\n return;\n }\n // video.width = video.offsetWidth;\n let base64EncodedImage;\n if (video && video.videoWidth > 0 && video.videoHeight > 0) {\n const canvas = document.createElement(\"canvas\");\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 if ((options.format || \"jpeg\") === \"jpeg\") {\n base64EncodedImage = canvas\n .toDataURL(\"image/jpeg\", (options.quality || 85) / 100.0)\n .replace(\"data:image/jpeg;base64,\", \"\");\n }\n else {\n base64EncodedImage = canvas\n .toDataURL(\"image/png\")\n .replace(\"data:image/png;base64,\", \"\");\n }\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async stopRecordVideo() {\n throw new Error(\"stopRecordVideo not supported under the web platform\");\n }\n async startRecordVideo(_options) {\n throw new Error(\"startRecordVideo not supported under the web platform\");\n }\n async getSupportedFlashModes() {\n throw new Error(\"getSupportedFlashModes not supported under the web platform\");\n }\n async getHorizontalFov() {\n throw new Error(\"getHorizontalFov 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}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,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,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cA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(
|
|
4
|
+
const CameraPreview = core.registerPlugin("CameraPreview", {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
class CameraPreviewWeb extends core.WebPlugin {
|
|
9
9
|
constructor() {
|
|
10
10
|
super({
|
|
11
|
-
name:
|
|
12
|
-
platforms: [
|
|
11
|
+
name: "CameraPreview",
|
|
12
|
+
platforms: ["web"],
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
async start(options) {
|
|
@@ -26,25 +26,25 @@ var capacitorApp = (function (exports, core) {
|
|
|
26
26
|
.catch((error) => {
|
|
27
27
|
Promise.reject(error);
|
|
28
28
|
});
|
|
29
|
-
const video = document.getElementById(
|
|
29
|
+
const video = document.getElementById("video");
|
|
30
30
|
const parent = document.getElementById(options.parent);
|
|
31
31
|
if (!video) {
|
|
32
|
-
const videoElement = document.createElement(
|
|
33
|
-
videoElement.id =
|
|
34
|
-
videoElement.setAttribute(
|
|
32
|
+
const videoElement = document.createElement("video");
|
|
33
|
+
videoElement.id = "video";
|
|
34
|
+
videoElement.setAttribute("class", options.className || "");
|
|
35
35
|
// Don't flip video feed if camera is rear facing
|
|
36
|
-
if (options.position !==
|
|
37
|
-
videoElement.setAttribute(
|
|
36
|
+
if (options.position !== "rear") {
|
|
37
|
+
videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);");
|
|
38
38
|
}
|
|
39
39
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
40
|
-
const isSafari = userAgent.includes(
|
|
40
|
+
const isSafari = userAgent.includes("safari") && !userAgent.includes("chrome");
|
|
41
41
|
// Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
|
|
42
42
|
// Without these attributes videoElement.play() will throw a NotAllowedError
|
|
43
43
|
// https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
|
|
44
44
|
if (isSafari) {
|
|
45
|
-
videoElement.setAttribute(
|
|
46
|
-
videoElement.setAttribute(
|
|
47
|
-
videoElement.setAttribute(
|
|
45
|
+
videoElement.setAttribute("autoplay", "true");
|
|
46
|
+
videoElement.setAttribute("muted", "true");
|
|
47
|
+
videoElement.setAttribute("playsinline", "true");
|
|
48
48
|
}
|
|
49
49
|
parent.appendChild(videoElement);
|
|
50
50
|
if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
|
|
@@ -54,8 +54,9 @@ var capacitorApp = (function (exports, core) {
|
|
|
54
54
|
height: { ideal: options.height },
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
|
-
if (options.position ===
|
|
58
|
-
constraints.video.facingMode =
|
|
57
|
+
if (options.position === "rear") {
|
|
58
|
+
constraints.video.facingMode =
|
|
59
|
+
"environment";
|
|
59
60
|
this.isBackCamera = true;
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
@@ -63,7 +64,7 @@ var capacitorApp = (function (exports, core) {
|
|
|
63
64
|
}
|
|
64
65
|
const self = this;
|
|
65
66
|
await navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
|
66
|
-
if (document.getElementById(
|
|
67
|
+
if (document.getElementById("video")) {
|
|
67
68
|
//video.src = window.URL.createObjectURL(stream);
|
|
68
69
|
videoElement.srcObject = stream;
|
|
69
70
|
videoElement.play();
|
|
@@ -71,7 +72,7 @@ var capacitorApp = (function (exports, core) {
|
|
|
71
72
|
}
|
|
72
73
|
else {
|
|
73
74
|
self.stopStream(stream);
|
|
74
|
-
Promise.reject({ message:
|
|
75
|
+
Promise.reject({ message: "camera already stopped" });
|
|
75
76
|
}
|
|
76
77
|
}, (err) => {
|
|
77
78
|
Promise.reject(err);
|
|
@@ -79,7 +80,7 @@ var capacitorApp = (function (exports, core) {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
|
-
Promise.reject({ message:
|
|
83
|
+
Promise.reject({ message: "camera already started" });
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
stopStream(stream) {
|
|
@@ -91,7 +92,7 @@ var capacitorApp = (function (exports, core) {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
async stop() {
|
|
94
|
-
const video = document.getElementById(
|
|
95
|
+
const video = document.getElementById("video");
|
|
95
96
|
if (video) {
|
|
96
97
|
video.pause();
|
|
97
98
|
this.stopStream(video.srcObject);
|
|
@@ -100,16 +101,16 @@ var capacitorApp = (function (exports, core) {
|
|
|
100
101
|
}
|
|
101
102
|
async capture(options) {
|
|
102
103
|
return new Promise((resolve, reject) => {
|
|
103
|
-
const video = document.getElementById(
|
|
104
|
+
const video = document.getElementById("video");
|
|
104
105
|
if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
|
|
105
|
-
reject({ message:
|
|
106
|
+
reject({ message: "camera is not running" });
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
// video.width = video.offsetWidth;
|
|
109
110
|
let base64EncodedImage;
|
|
110
111
|
if (video && video.videoWidth > 0 && video.videoHeight > 0) {
|
|
111
|
-
const canvas = document.createElement(
|
|
112
|
-
const context = canvas.getContext(
|
|
112
|
+
const canvas = document.createElement("canvas");
|
|
113
|
+
const context = canvas.getContext("2d");
|
|
113
114
|
canvas.width = video.videoWidth;
|
|
114
115
|
canvas.height = video.videoHeight;
|
|
115
116
|
// flip horizontally back camera isn't used
|
|
@@ -118,13 +119,15 @@ var capacitorApp = (function (exports, core) {
|
|
|
118
119
|
context.scale(-1, 1);
|
|
119
120
|
}
|
|
120
121
|
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
|
121
|
-
if ((options.format ||
|
|
122
|
+
if ((options.format || "jpeg") === "jpeg") {
|
|
122
123
|
base64EncodedImage = canvas
|
|
123
|
-
.toDataURL(
|
|
124
|
-
.replace(
|
|
124
|
+
.toDataURL("image/jpeg", (options.quality || 85) / 100.0)
|
|
125
|
+
.replace("data:image/jpeg;base64,", "");
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
|
-
base64EncodedImage = canvas
|
|
128
|
+
base64EncodedImage = canvas
|
|
129
|
+
.toDataURL("image/png")
|
|
130
|
+
.replace("data:image/png;base64,", "");
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
resolve({
|
|
@@ -136,27 +139,27 @@ var capacitorApp = (function (exports, core) {
|
|
|
136
139
|
return this.capture(_options);
|
|
137
140
|
}
|
|
138
141
|
async stopRecordVideo() {
|
|
139
|
-
throw new Error(
|
|
142
|
+
throw new Error("stopRecordVideo not supported under the web platform");
|
|
140
143
|
}
|
|
141
144
|
async startRecordVideo(_options) {
|
|
142
|
-
throw new Error(
|
|
145
|
+
throw new Error("startRecordVideo not supported under the web platform");
|
|
143
146
|
}
|
|
144
147
|
async getSupportedFlashModes() {
|
|
145
|
-
throw new Error(
|
|
148
|
+
throw new Error("getSupportedFlashModes not supported under the web platform");
|
|
146
149
|
}
|
|
147
150
|
async getHorizontalFov() {
|
|
148
|
-
throw new Error(
|
|
151
|
+
throw new Error("getHorizontalFov not supported under the web platform");
|
|
149
152
|
}
|
|
150
153
|
async setFlashMode(_options) {
|
|
151
|
-
throw new Error(
|
|
154
|
+
throw new Error("setFlashMode not supported under the web platform" + _options);
|
|
152
155
|
}
|
|
153
156
|
async flip() {
|
|
154
|
-
throw new Error(
|
|
157
|
+
throw new Error("flip not supported under the web platform");
|
|
155
158
|
}
|
|
156
159
|
async setOpacity(_options) {
|
|
157
|
-
const video = document.getElementById(
|
|
158
|
-
if (!!video && !!_options[
|
|
159
|
-
video.style.setProperty(
|
|
160
|
+
const video = document.getElementById("video");
|
|
161
|
+
if (!!video && !!_options["opacity"]) {
|
|
162
|
+
video.style.setProperty("opacity", _options["opacity"].toString());
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
}
|