pwa-camera.cjs.entry.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const index = require('./index-d7f36e37.js');
  4. /**
  5. * MediaStream ImageCapture polyfill
  6. *
  7. * @license
  8. * Copyright 2018 Google Inc.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. let ImageCapture = window.ImageCapture;
  23. if (typeof ImageCapture === 'undefined') {
  24. ImageCapture = class {
  25. /**
  26. * TODO https://www.w3.org/TR/image-capture/#constructors
  27. *
  28. * @param {MediaStreamTrack} videoStreamTrack - A MediaStreamTrack of the 'video' kind
  29. */
  30. constructor(videoStreamTrack) {
  31. if (videoStreamTrack.kind !== 'video')
  32. throw new DOMException('NotSupportedError');
  33. this._videoStreamTrack = videoStreamTrack;
  34. if (!('readyState' in this._videoStreamTrack)) {
  35. // Polyfill for Firefox
  36. this._videoStreamTrack.readyState = 'live';
  37. }
  38. // MediaStream constructor not available until Chrome 55 - https://www.chromestatus.com/feature/5912172546752512
  39. this._previewStream = new MediaStream([videoStreamTrack]);
  40. this.videoElement = document.createElement('video');
  41. this.videoElementPlaying = new Promise(resolve => {
  42. this.videoElement.addEventListener('playing', resolve);
  43. });
  44. if (HTMLMediaElement) {
  45. this.videoElement.srcObject = this._previewStream; // Safari 11 doesn't allow use of createObjectURL for MediaStream
  46. }
  47. else {
  48. this.videoElement.src = URL.createObjectURL(this._previewStream);
  49. }
  50. this.videoElement.muted = true;
  51. this.videoElement.setAttribute('playsinline', ''); // Required by Safari on iOS 11. See https://webkit.org/blog/6784
  52. this.videoElement.play();
  53. this.canvasElement = document.createElement('canvas');
  54. // TODO Firefox has https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
  55. this.canvas2dContext = this.canvasElement.getContext('2d');
  56. }
  57. /**
  58. * https://w3c.github.io/mediacapture-image/index.html#dom-imagecapture-videostreamtrack
  59. * @return {MediaStreamTrack} The MediaStreamTrack passed into the constructor
  60. */
  61. get videoStreamTrack() {
  62. return this._videoStreamTrack;
  63. }
  64. /**
  65. * Implements https://www.w3.org/TR/image-capture/#dom-imagecapture-getphotocapabilities
  66. * @return {Promise<PhotoCapabilities>} Fulfilled promise with
  67. * [PhotoCapabilities](https://www.w3.org/TR/image-capture/#idl-def-photocapabilities)
  68. * object on success, rejected promise on failure
  69. */
  70. getPhotoCapabilities() {
  71. return new Promise(function executorGPC(resolve, reject) {
  72. // TODO see https://github.com/w3c/mediacapture-image/issues/97
  73. const MediaSettingsRange = {
  74. current: 0, min: 0, max: 0,
  75. };
  76. resolve({
  77. exposureCompensation: MediaSettingsRange,
  78. exposureMode: 'none',
  79. fillLightMode: ['none'],
  80. focusMode: 'none',
  81. imageHeight: MediaSettingsRange,
  82. imageWidth: MediaSettingsRange,
  83. iso: MediaSettingsRange,
  84. redEyeReduction: false,
  85. whiteBalanceMode: 'none',
  86. zoom: MediaSettingsRange,
  87. });
  88. reject(new DOMException('OperationError'));
  89. });
  90. }
  91. /**
  92. * Implements https://www.w3.org/TR/image-capture/#dom-imagecapture-setoptions
  93. * @param {Object} photoSettings - Photo settings dictionary, https://www.w3.org/TR/image-capture/#idl-def-photosettings
  94. * @return {Promise<void>} Fulfilled promise on success, rejected promise on failure
  95. */
  96. setOptions(_photoSettings = {}) {
  97. return new Promise(function executorSO(_resolve, _reject) {
  98. // TODO
  99. });
  100. }
  101. /**
  102. * TODO
  103. * Implements https://www.w3.org/TR/image-capture/#dom-imagecapture-takephoto
  104. * @return {Promise<Blob>} Fulfilled promise with [Blob](https://www.w3.org/TR/FileAPI/#blob)
  105. * argument on success; rejected promise on failure
  106. */
  107. takePhoto() {
  108. const self = this;
  109. return new Promise(function executorTP(resolve, reject) {
  110. // `If the readyState of the MediaStreamTrack provided in the constructor is not live,
  111. // return a promise rejected with a new DOMException whose name is "InvalidStateError".`
  112. if (self._videoStreamTrack.readyState !== 'live') {
  113. return reject(new DOMException('InvalidStateError'));
  114. }
  115. self.videoElementPlaying.then(() => {
  116. try {
  117. self.canvasElement.width = self.videoElement.videoWidth;
  118. self.canvasElement.height = self.videoElement.videoHeight;
  119. self.canvas2dContext.drawImage(self.videoElement, 0, 0);
  120. self.canvasElement.toBlob(resolve);
  121. }
  122. catch (error) {
  123. reject(new DOMException('UnknownError'));
  124. }
  125. });
  126. });
  127. }
  128. /**
  129. * Implements https://www.w3.org/TR/image-capture/#dom-imagecapture-grabframe
  130. * @return {Promise<ImageBitmap>} Fulfilled promise with
  131. * [ImageBitmap](https://www.w3.org/TR/html51/webappapis.html#webappapis-images)
  132. * argument on success; rejected promise on failure
  133. */
  134. grabFrame() {
  135. const self = this;
  136. return new Promise(function executorGF(resolve, reject) {
  137. // `If the readyState of the MediaStreamTrack provided in the constructor is not live,
  138. // return a promise rejected with a new DOMException whose name is "InvalidStateError".`
  139. if (self._videoStreamTrack.readyState !== 'live') {
  140. return reject(new DOMException('InvalidStateError'));
  141. }
  142. self.videoElementPlaying.then(() => {
  143. try {
  144. self.canvasElement.width = self.videoElement.videoWidth;
  145. self.canvasElement.height = self.videoElement.videoHeight;
  146. self.canvas2dContext.drawImage(self.videoElement, 0, 0);
  147. // TODO polyfill https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmapFactories/createImageBitmap for IE
  148. resolve(window.createImageBitmap(self.canvasElement));
  149. }
  150. catch (error) {
  151. reject(new DOMException('UnknownError'));
  152. }
  153. });
  154. });
  155. }
  156. };
  157. }
  158. window.ImageCapture = ImageCapture;
  159. const cameraCss = ":host{--header-height:4em;--footer-height:9em;--header-height-landscape:3em;--footer-height-landscape:6em;--shutter-size:6em;--icon-size-header:1.5em;--icon-size-footer:2.5em;--margin-size-header:1.5em;--margin-size-footer:2.0em;font-family:-apple-system, BlinkMacSystemFont,\n “Segoe UI”, “Roboto”, “Droid Sans”, “Helvetica Neue”, sans-serif;display:block;width:100%;height:100%}.items{-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;width:100%;height:100%;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}.items .item{-ms-flex:1;flex:1;text-align:center}.items .item:first-child{text-align:left}.items .item:last-child{text-align:right}.camera-wrapper{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;width:100%;height:100%}.camera-header{color:white;background-color:black;height:var(--header-height)}.camera-header .items{padding:var(--margin-size-header)}.camera-footer{position:relative;color:white;background-color:black;height:var(--footer-height)}.camera-footer .items{padding:var(--margin-size-footer)}@media (max-height: 375px){.camera-header{--header-height:var(--header-height-landscape)}.camera-footer{--footer-height:var(--footer-height-landscape)}.camera-footer .shutter{--shutter-size:4em}}.camera-video{position:relative;-ms-flex:1;flex:1;overflow:hidden;background-color:black}video{width:100%;height:100%;max-height:100%;min-height:100%;-o-object-fit:cover;object-fit:cover;background-color:black}.pick-image{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;position:absolute;left:var(--margin-size-footer);top:0;height:100%;width:var(--icon-size-footer);color:white}.pick-image input{visibility:hidden}.pick-image svg{cursor:pointer;fill:white;width:var(--icon-size-footer);height:var(--icon-size-footer)}.shutter{position:absolute;left:50%;top:50%;width:var(--shutter-size);height:var(--shutter-size);margin-top:calc(var(--shutter-size) / -2);margin-left:calc(var(--shutter-size) / -2);border-radius:100%;background-color:#c6cdd8;padding:12px;-webkit-box-sizing:border-box;box-sizing:border-box}.shutter:active .shutter-button{background-color:#9da9bb}.shutter-button{background-color:white;border-radius:100%;width:100%;height:100%}.rotate{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;position:absolute;right:var(--margin-size-footer);top:0;height:100%;width:var(--icon-size-footer);color:white}.rotate img{width:var(--icon-size-footer);height:var(--icon-size-footer)}.shutter-overlay{z-index:5;position:absolute;width:100%;height:100%;background-color:black}.error{width:100%;height:100%;color:white;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center}.no-device{background-color:black;-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;color:white}.no-device label{cursor:pointer;background:#fff;border-radius:6px;padding:6px 8px;color:black}.no-device input{visibility:hidden;height:0;margin-top:16px}.accept{background-color:black;-ms-flex:1;flex:1;overflow:hidden}.accept .accept-image{width:100%;height:100%;max-height:100%;background-position:center center;background-size:cover;background-repeat:no-repeat}.close img{cursor:pointer;width:var(--icon-size-header);height:var(--icon-size-header)}.flash img{width:var(--icon-size-header);height:var(--icon-size-header)}.accept-use img{width:var(--icon-size-footer);height:var(--icon-size-footer)}.accept-cancel img{width:var(--icon-size-footer);height:var(--icon-size-footer)}.offscreen-image-render{top:0;left:0;visibility:hidden;pointer-events:none;width:100%;height:100%}";
  160. const CameraPWA = class {
  161. constructor(hostRef) {
  162. index.registerInstance(this, hostRef);
  163. // Whether the device has multiple cameras (front/back)
  164. this.hasMultipleCameras = false;
  165. // Whether the device has flash support
  166. this.hasFlash = false;
  167. // Flash modes for camera
  168. this.flashModes = [];
  169. // Current flash mode
  170. this.flashMode = 'off';
  171. this.handlePickFile = (_e) => {
  172. };
  173. this.handleShutterClick = (_e) => {
  174. console.debug('shutter click');
  175. this.capture();
  176. };
  177. this.handleRotateClick = (_e) => {
  178. this.rotate();
  179. };
  180. this.handleClose = (_e) => {
  181. this.handlePhoto && this.handlePhoto(null);
  182. };
  183. this.handleFlashClick = (_e) => {
  184. this.cycleFlash();
  185. };
  186. this.handleCancelPhoto = (_e) => {
  187. const track = this.stream && this.stream.getTracks()[0];
  188. let c = track && track.getConstraints();
  189. this.photo = null;
  190. this.photoSrc = null;
  191. if (c) {
  192. this.initCamera({
  193. video: {
  194. facingMode: c.facingMode
  195. }
  196. });
  197. }
  198. else {
  199. this.initCamera();
  200. }
  201. };
  202. this.handleAcceptPhoto = (_e) => {
  203. this.handlePhoto && this.handlePhoto(this.photo);
  204. };
  205. this.handleFileInputChange = async (e) => {
  206. const input = e.target;
  207. const file = input.files[0];
  208. try {
  209. const orientation = await this.getOrientation(file);
  210. console.debug('Got orientation', orientation);
  211. this.photoOrientation = orientation;
  212. }
  213. catch (e) {
  214. }
  215. this.handlePhoto && this.handlePhoto(file);
  216. };
  217. this.handleVideoMetadata = (e) => {
  218. console.debug('Video metadata', e);
  219. };
  220. this.facingMode = 'user';
  221. this.handlePhoto = undefined;
  222. this.hidePicker = false;
  223. this.handleNoDeviceError = undefined;
  224. this.noDevicesText = 'No camera found';
  225. this.noDevicesButtonText = 'Choose image';
  226. this.photo = undefined;
  227. this.photoSrc = undefined;
  228. this.showShutterOverlay = false;
  229. this.flashIndex = 0;
  230. this.hasCamera = null;
  231. this.rotation = 0;
  232. this.deviceError = null;
  233. }
  234. async componentDidLoad() {
  235. this.defaultConstraints = {
  236. video: {
  237. facingMode: this.facingMode
  238. }
  239. };
  240. // Figure out how many cameras we have
  241. await this.queryDevices();
  242. // Initialize the camera
  243. await this.initCamera();
  244. }
  245. disconnectedCallback() {
  246. this.stopStream();
  247. this.photoSrc && URL.revokeObjectURL(this.photoSrc);
  248. }
  249. hasImageCapture() {
  250. return 'ImageCapture' in window;
  251. }
  252. /**
  253. * Query the list of connected devices and figure out how many video inputs we have.
  254. */
  255. async queryDevices() {
  256. try {
  257. const devices = await navigator.mediaDevices.enumerateDevices();
  258. const videoDevices = devices.filter(d => d.kind == 'videoinput');
  259. this.hasCamera = !!videoDevices.length;
  260. this.hasMultipleCameras = videoDevices.length > 1;
  261. }
  262. catch (e) {
  263. this.deviceError = e;
  264. }
  265. }
  266. async initCamera(constraints) {
  267. if (!constraints) {
  268. constraints = this.defaultConstraints;
  269. }
  270. try {
  271. const stream = await navigator.mediaDevices.getUserMedia(Object.assign({ video: true, audio: false }, constraints));
  272. this.initStream(stream);
  273. }
  274. catch (e) {
  275. this.deviceError = e;
  276. this.handleNoDeviceError && this.handleNoDeviceError(e);
  277. }
  278. }
  279. async initStream(stream) {
  280. this.stream = stream;
  281. this.videoElement.srcObject = stream;
  282. if (this.hasImageCapture()) {
  283. this.imageCapture = new window.ImageCapture(stream.getVideoTracks()[0]);
  284. await this.initPhotoCapabilities(this.imageCapture);
  285. }
  286. else {
  287. this.deviceError = 'No image capture';
  288. this.handleNoDeviceError && this.handleNoDeviceError();
  289. }
  290. // Always re-render
  291. index.forceUpdate(this.el);
  292. }
  293. async initPhotoCapabilities(imageCapture) {
  294. const c = await imageCapture.getPhotoCapabilities();
  295. if (c.fillLightMode && c.fillLightMode.length > 1) {
  296. this.flashModes = c.fillLightMode.map(m => m);
  297. // Try to recall the current flash mode
  298. if (this.flashMode) {
  299. this.flashMode = this.flashModes[this.flashModes.indexOf(this.flashMode)] || 'off';
  300. this.flashIndex = this.flashModes.indexOf(this.flashMode) || 0;
  301. }
  302. else {
  303. this.flashIndex = 0;
  304. }
  305. }
  306. }
  307. stopStream() {
  308. if (this.videoElement) {
  309. this.videoElement.srcObject = null;
  310. }
  311. this.stream && this.stream.getTracks().forEach(track => track.stop());
  312. }
  313. async capture() {
  314. if (this.hasImageCapture()) {
  315. try {
  316. const photo = await this.imageCapture.takePhoto({
  317. fillLightMode: this.flashModes.length > 1 ? this.flashMode : undefined
  318. });
  319. await this.flashScreen();
  320. this.promptAccept(photo);
  321. }
  322. catch (e) {
  323. console.error('Unable to take photo!', e);
  324. }
  325. }
  326. this.stopStream();
  327. }
  328. async promptAccept(photo) {
  329. this.photo = photo;
  330. const orientation = await this.getOrientation(photo);
  331. console.debug('Got orientation', orientation);
  332. this.photoOrientation = orientation;
  333. if (orientation) {
  334. switch (orientation) {
  335. case 1:
  336. case 2:
  337. this.rotation = 0;
  338. break;
  339. case 3:
  340. case 4:
  341. this.rotation = 180;
  342. break;
  343. case 5:
  344. case 6:
  345. this.rotation = 90;
  346. break;
  347. case 7:
  348. case 8:
  349. this.rotation = 270;
  350. break;
  351. }
  352. }
  353. this.photoSrc = URL.createObjectURL(photo);
  354. }
  355. getOrientation(file) {
  356. return new Promise(resolve => {
  357. const reader = new FileReader();
  358. reader.onload = (event) => {
  359. const view = new DataView(event.target.result);
  360. if (view.getUint16(0, false) !== 0xFFD8) {
  361. return resolve(-2);
  362. }
  363. const length = view.byteLength;
  364. let offset = 2;
  365. while (offset < length) {
  366. const marker = view.getUint16(offset, false);
  367. offset += 2;
  368. if (marker === 0xFFE1) {
  369. if (view.getUint32(offset += 2, false) !== 0x45786966) {
  370. return resolve(-1);
  371. }
  372. const little = view.getUint16(offset += 6, false) === 0x4949;
  373. offset += view.getUint32(offset + 4, little);
  374. const tags = view.getUint16(offset, little);
  375. offset += 2;
  376. for (let i = 0; i < tags; i++) {
  377. if (view.getUint16(offset + (i * 12), little) === 0x0112) {
  378. return resolve(view.getUint16(offset + (i * 12) + 8, little));
  379. }
  380. }
  381. }
  382. else if ((marker & 0xFF00) !== 0xFF00) {
  383. break;
  384. }
  385. else {
  386. offset += view.getUint16(offset, false);
  387. }
  388. }
  389. return resolve(-1);
  390. };
  391. reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
  392. });
  393. }
  394. rotate() {
  395. this.stopStream();
  396. const track = this.stream && this.stream.getTracks()[0];
  397. if (!track) {
  398. return;
  399. }
  400. let c = track.getConstraints();
  401. let facingMode = c.facingMode;
  402. if (!facingMode) {
  403. let c = track.getCapabilities();
  404. if (c.facingMode) {
  405. facingMode = c.facingMode[0];
  406. }
  407. }
  408. if (facingMode === 'environment') {
  409. this.initCamera({
  410. video: {
  411. facingMode: 'user'
  412. }
  413. });
  414. }
  415. else {
  416. this.initCamera({
  417. video: {
  418. facingMode: 'environment'
  419. }
  420. });
  421. }
  422. }
  423. setFlashMode(mode) {
  424. console.debug('New flash mode: ', mode);
  425. this.flashMode = mode;
  426. }
  427. cycleFlash() {
  428. if (this.flashModes.length > 0) {
  429. this.flashIndex = (this.flashIndex + 1) % this.flashModes.length;
  430. this.setFlashMode(this.flashModes[this.flashIndex]);
  431. }
  432. }
  433. async flashScreen() {
  434. return new Promise((resolve, _reject) => {
  435. this.showShutterOverlay = true;
  436. setTimeout(() => {
  437. this.showShutterOverlay = false;
  438. resolve();
  439. }, 100);
  440. });
  441. }
  442. iconExit() {
  443. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' enable-background='new 0 0 512 512' xml:space='preserve'%3E%3Cg id='Icon_5_'%3E%3Cg%3E%3Cpath fill='%23FFFFFF' d='M402.2,134L378,109.8c-1.6-1.6-4.1-1.6-5.7,0L258.8,223.4c-1.6,1.6-4.1,1.6-5.7,0L139.6,109.8 c-1.6-1.6-4.1-1.6-5.7,0L109.8,134c-1.6,1.6-1.6,4.1,0,5.7l113.5,113.5c1.6,1.6,1.6,4.1,0,5.7L109.8,372.4c-1.6,1.6-1.6,4.1,0,5.7 l24.1,24.1c1.6,1.6,4.1,1.6,5.7,0l113.5-113.5c1.6-1.6,4.1-1.6,5.7,0l113.5,113.5c1.6,1.6,4.1,1.6,5.7,0l24.1-24.1 c1.6-1.6,1.6-4.1,0-5.7L288.6,258.8c-1.6-1.6-1.6-4.1,0-5.7l113.5-113.5C403.7,138.1,403.7,135.5,402.2,134z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E`;
  444. }
  445. iconPhotos() {
  446. return (index.h("svg", { xmlns: 'http://www.w3.org/2000/svg', width: '512', height: '512', viewBox: '0 0 512 512' }, index.h("path", { d: 'M450.29,112H142c-34,0-62,27.51-62,61.33V418.67C80,452.49,108,480,142,480H450c34,0,62-26.18,62-60V173.33C512,139.51,484.32,112,450.29,112Zm-77.15,61.34a46,46,0,1,1-46.28,46A46.19,46.19,0,0,1,373.14,173.33Zm-231.55,276c-17,0-29.86-13.75-29.86-30.66V353.85l90.46-80.79a46.54,46.54,0,0,1,63.44,1.83L328.27,337l-113,112.33ZM480,418.67a30.67,30.67,0,0,1-30.71,30.66H259L376.08,333a46.24,46.24,0,0,1,59.44-.16L480,370.59Z' }), index.h("path", { d: 'M384,32H64A64,64,0,0,0,0,96V352a64.11,64.11,0,0,0,48,62V152a72,72,0,0,1,72-72H446A64.11,64.11,0,0,0,384,32Z' })));
  447. }
  448. iconConfirm() {
  449. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' enable-background='new 0 0 512 512' xml:space='preserve'%3E%3Ccircle fill='%232CD865' cx='256' cy='256' r='256'/%3E%3Cg id='Icon_1_'%3E%3Cg%3E%3Cg%3E%3Cpath fill='%23FFFFFF' d='M208,301.4l-55.4-55.5c-1.5-1.5-4-1.6-5.6-0.1l-23.4,22.3c-1.6,1.6-1.7,4.1-0.1,5.7l81.6,81.4 c3.1,3.1,8.2,3.1,11.3,0l171.8-171.7c1.6-1.6,1.6-4.2-0.1-5.7l-23.4-22.3c-1.6-1.5-4.1-1.5-5.6,0.1L213.7,301.4 C212.1,303,209.6,303,208,301.4z'/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E`;
  450. }
  451. iconReverseCamera() {
  452. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' enable-background='new 0 0 512 512' xml:space='preserve'%3E%3Cg%3E%3Cpath fill='%23FFFFFF' d='M352,0H160C72,0,0,72,0,160v192c0,88,72,160,160,160h192c88,0,160-72,160-160V160C512,72,440,0,352,0z M356.7,365.8l-3.7,3.3c-27,23.2-61.4,35.9-96.8,35.9c-72.4,0-135.8-54.7-147-125.6c-0.3-1.9-2-3.3-3.9-3.3H64 c-3.3,0-5.2-3.8-3.2-6.4l61.1-81.4c1.6-2.1,4.7-2.1,6.4-0.1l63.3,81.4c2,2.6,0.2,6.5-3.2,6.5h-40.6c-2.5,0-4.5,2.4-3.9,4.8 c11.5,51.5,59.2,90.6,112.4,90.6c26.4,0,51.8-9.7,73.7-27.9l3.1-2.5c1.6-1.3,3.9-1.1,5.3,0.3l18.5,18.6 C358.5,361.6,358.4,364.3,356.7,365.8z M451.4,245.6l-61,83.5c-1.6,2.2-4.8,2.2-6.4,0.1l-63.3-83.3c-2-2.6-0.1-6.4,3.2-6.4h40.8 c2.5,0,4.4-2.3,3.9-4.8c-5.1-24.2-17.8-46.5-36.5-63.7c-21.2-19.4-48.2-30.1-76-30.1c-26.5,0-52.6,9.7-73.7,27.3l-3.1,2.5 c-1.6,1.3-3.9,1.2-5.4-0.3l-18.5-18.5c-1.6-1.6-1.5-4.3,0.2-5.9l3.5-3.1c27-23.2,61.4-35.9,96.8-35.9c38,0,73.9,13.7,101.2,38.7 c23.2,21.1,40.3,55.2,45.7,90.1c0.3,1.9,1.9,3.4,3.9,3.4h41.3C451.4,239.2,453.3,243,451.4,245.6z'/%3E%3C/g%3E%3C/svg%3E`;
  453. }
  454. iconRetake() {
  455. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' enable-background='new 0 0 512 512' xml:space='preserve'%3E%3Ccircle fill='%23727A87' cx='256' cy='256' r='256'/%3E%3Cg id='Icon_5_'%3E%3Cg%3E%3Cpath fill='%23FFFFFF' d='M394.2,142L370,117.8c-1.6-1.6-4.1-1.6-5.7,0L258.8,223.4c-1.6,1.6-4.1,1.6-5.7,0L147.6,117.8 c-1.6-1.6-4.1-1.6-5.7,0L117.8,142c-1.6,1.6-1.6,4.1,0,5.7l105.5,105.5c1.6,1.6,1.6,4.1,0,5.7L117.8,364.4c-1.6,1.6-1.6,4.1,0,5.7 l24.1,24.1c1.6,1.6,4.1,1.6,5.7,0l105.5-105.5c1.6-1.6,4.1-1.6,5.7,0l105.5,105.5c1.6,1.6,4.1,1.6,5.7,0l24.1-24.1 c1.6-1.6,1.6-4.1,0-5.7L288.6,258.8c-1.6-1.6-1.6-4.1,0-5.7l105.5-105.5C395.7,146.1,395.7,143.5,394.2,142z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E`;
  456. }
  457. iconFlashOff() {
  458. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' style='enable-background:new 0 0 512 512;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M498,483.7L42.3,28L14,56.4l149.8,149.8L91,293.8c-2.5,3-0.1,7.2,3.9,7.2h143.9c1.6,0,2.7,1.3,2.4,2.7 L197.6,507c-1,4.4,5.8,6.9,8.9,3.2l118.6-142.8L469.6,512L498,483.7z'/%3E%3Cpath class='st0' d='M449,218.2c2.5-3,0.1-7.2-3.9-7.2H301.2c-1.6,0-2.7-1.3-2.4-2.7L342.4,5c1-4.4-5.8-6.9-8.9-3.2L214.9,144.6 l161.3,161.3L449,218.2z'/%3E%3C/g%3E%3C/svg%3E`;
  459. }
  460. iconFlashOn() {
  461. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' style='enable-background:new 0 0 512 512;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Cpath class='st0' d='M287.2,211c-1.6,0-2.7-1.3-2.4-2.7L328.4,5c1-4.4-5.8-6.9-8.9-3.2L77,293.8c-2.5,3-0.1,7.2,3.9,7.2h143.9 c1.6,0,2.7,1.3,2.4,2.7L183.6,507c-1,4.4,5.8,6.9,8.9,3.2l242.5-292c2.5-3,0.1-7.2-3.9-7.2L287.2,211L287.2,211z'/%3E%3C/svg%3E`;
  462. }
  463. iconFlashAuto() {
  464. return `data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' style='enable-background:new 0 0 512 512;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Cpath class='st0' d='M287.2,211c-1.6,0-2.7-1.3-2.4-2.7L328.4,5c1-4.4-5.8-6.9-8.9-3.2L77,293.8c-2.5,3-0.1,7.2,3.9,7.2h143.9 c1.6,0,2.7,1.3,2.4,2.7L183.6,507c-1,4.4,5.8,6.9,8.9,3.2l242.5-292c2.5-3,0.1-7.2-3.9-7.2L287.2,211L287.2,211z'/%3E%3Cg%3E%3Cpath class='st0' d='M321.3,186l74-186H438l74,186h-43.5l-11.9-32.5h-80.9l-12,32.5H321.3z M415.8,47.9l-27.2,70.7h54.9l-27.2-70.7 H415.8z'/%3E%3C/g%3E%3C/svg%3E`;
  465. }
  466. render() {
  467. // const acceptStyles = { transform: `rotate(${-this.rotation}deg)` };
  468. const acceptStyles = {};
  469. return (index.h("div", { class: "camera-wrapper" }, index.h("div", { class: "camera-header" }, index.h("section", { class: "items" }, index.h("div", { class: "item close", onClick: e => this.handleClose(e) }, index.h("img", { src: this.iconExit() })), index.h("div", { class: "item flash", onClick: e => this.handleFlashClick(e) }, this.flashModes.length > 0 && (index.h("div", null, this.flashMode == 'off' ? index.h("img", { src: this.iconFlashOff() }) : '', this.flashMode == 'auto' ? index.h("img", { src: this.iconFlashAuto() }) : '', this.flashMode == 'flash' ? index.h("img", { src: this.iconFlashOn() }) : ''))))), (this.hasCamera === false || !!this.deviceError) && (index.h("div", { class: "no-device" }, index.h("h2", null, this.noDevicesText), index.h("label", { htmlFor: "_pwa-elements-camera-input" }, this.noDevicesButtonText), index.h("input", { type: "file", id: "_pwa-elements-camera-input", onChange: this.handleFileInputChange, accept: "image/*", class: "select-file-button" }))), this.photoSrc ? (index.h("div", { class: "accept" }, index.h("div", { class: "accept-image", style: Object.assign({ backgroundImage: `url(${this.photoSrc})` }, acceptStyles) }))) : (index.h("div", { class: "camera-video" }, this.showShutterOverlay && (index.h("div", { class: "shutter-overlay" })), this.hasImageCapture() ? (index.h("video", { ref: (el) => this.videoElement = el, onLoadedMetaData: this.handleVideoMetadata, autoplay: true, playsinline: true })) : (index.h("canvas", { ref: (el) => this.canvasElement = el, width: "100%", height: "100%" })), index.h("canvas", { class: "offscreen-image-render", ref: e => this.offscreenCanvas = e, width: "100%", height: "100%" }))), this.hasCamera && (index.h("div", { class: "camera-footer" }, !this.photo ? ([
  470. !this.hidePicker && (index.h("div", { class: "pick-image", onClick: this.handlePickFile }, index.h("label", { htmlFor: "_pwa-elements-file-pick" }, this.iconPhotos()), index.h("input", { type: "file", id: "_pwa-elements-file-pick", onChange: this.handleFileInputChange, accept: "image/*", class: "pick-image-button" }))),
  471. index.h("div", { class: "shutter", onClick: this.handleShutterClick }, index.h("div", { class: "shutter-button" })),
  472. index.h("div", { class: "rotate", onClick: this.handleRotateClick }, index.h("img", { src: this.iconReverseCamera() })),
  473. ]) : (index.h("section", { class: "items" }, index.h("div", { class: "item accept-cancel", onClick: e => this.handleCancelPhoto(e) }, index.h("img", { src: this.iconRetake() })), index.h("div", { class: "item accept-use", onClick: e => this.handleAcceptPhoto(e) }, index.h("img", { src: this.iconConfirm() }))))))));
  474. }
  475. static get assetsDirs() { return ["icons"]; }
  476. get el() { return index.getElement(this); }
  477. };
  478. CameraPWA.style = cameraCss;
  479. exports.pwa_camera = CameraPWA;