{"version":3,"sources":["webpack:///./node_modules/@capacitor/camera/dist/esm/web.js"],"names":["CameraWeb","options","Promise","async","resolve","reject","webUseInput","source","Photos","this","fileInputExperience","Prompt","actionSheet","document","querySelector","createElement","body","appendChild","header","promptLabelHeader","cancelable","title","promptLabelPhoto","promptLabelPicture","addEventListener","e","selection","detail","cameraExperience","_options","multipleFileInputExperience","customElements","get","cameraModal","facingMode","direction","Front","componentOnReady","photo","Error","_getCameraPhoto","dismiss","removeChild","present","console","error","input","cleanup","_a","parentNode","id","type","hidden","_e","file","files","format","resultType","reader","FileReader","dataUrl","result","b64","split","base64String","readAsDataURL","webPath","URL","createObjectURL","accept","capture","removeAttribute","Rear","click","multiple","photos","i","length","push","saved","onloadend","r","onerror","navigator","permissions","unavailable","permission","window","query","name","camera","state","unimplemented","Camera"],"mappings":"gHAAA,oHAEO,MAAMA,UAAkB,OAC3B,eAAeC,GAEX,OAAO,IAAIC,QAAQC,MAAOC,EAASC,KAC/B,GAAIJ,EAAQK,aAAeL,EAAQM,SAAW,OAAaC,OACvDC,KAAKC,oBAAoBT,EAASG,QAEjC,GAAIH,EAAQM,SAAW,OAAaI,OAAQ,CAC7C,IAAIC,EAAcC,SAASC,cAAc,oBACpCF,IACDA,EAAcC,SAASE,cAAc,oBACrCF,SAASG,KAAKC,YAAYL,IAE9BA,EAAYM,OAASjB,EAAQkB,mBAAqB,QAClDP,EAAYQ,YAAa,EACzBR,EAAYX,QAAU,CAClB,CAAEoB,MAAOpB,EAAQqB,kBAAoB,eACrC,CAAED,MAAOpB,EAAQsB,oBAAsB,iBAE3CX,EAAYY,iBAAiB,cAAerB,MAAOsB,IAC/C,MAAMC,EAAYD,EAAEE,OACF,IAAdD,EACAjB,KAAKC,oBAAoBT,EAASG,GAGlCK,KAAKmB,iBAAiB3B,EAASG,EAASC,UAKhDI,KAAKmB,iBAAiB3B,EAASG,EAASC,KAIpD,iBAAiBwB,GAEb,OAAO,IAAI3B,QAAQC,MAAOC,IACtBK,KAAKqB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WACbH,EAASlB,EAAMa,KAAKY,MAAM,KAAK,GACV,QAAvB9D,EAAQwD,WACRrD,EAAQ,CACJ8D,QAASC,IAAIC,gBAAgB9B,GAC7BkB,OAAQA,EACRuB,OAAO,KAIXrB,EAAOO,cAAc3B,GACrBoB,EAAOsB,UAAY,KACf,MAAMC,EAAIvB,EAAOG,OACU,YAAvB5D,EAAQwD,WACRrD,EAAQ,CACJwD,QAASqB,EACTzB,OAAQA,EACRuB,OAAO,IAIX3E,EAAQ,CACJ4D,aAAciB,EAAElB,MAAM,KAAK,GAC3BP,OAAQA,EACRuB,OAAO,KAInBrB,EAAOwB,QAAUzD,IACbpB,EAAOoB,OAKvB,yBACI,GAAyB,qBAAd0D,YAA8BA,UAAUC,YAC/C,MAAM3E,KAAK4E,YAAY,iDAE3B,IAII,MAAMC,QAAmBC,OAAOJ,UAAUC,YAAYI,MAAM,CACxDC,KAAM,WAEV,MAAO,CACHC,OAAQJ,EAAWK,MACnBhB,OAAQ,WAGhB,MAAO3B,GACH,MAAMvC,KAAK4E,YAAY,yDAG/B,2BACI,MAAM5E,KAAKmF,cAAc,2BAE7B,iCACI,MAAMnF,KAAK4E,YAAY,2BAE3B,gCACI,MAAM5E,KAAK4E,YAAY,4BAG/B,MAAMQ,EAAS,IAAI7F","file":"js/chunk-2d216786.a7e28752.js","sourcesContent":["import { WebPlugin, CapacitorException } from '@capacitor/core';\nimport { CameraSource, CameraDirection } from './definitions';\nexport class CameraWeb extends WebPlugin {\n async getPhoto(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n if (options.webUseInput || options.source === CameraSource.Photos) {\n this.fileInputExperience(options, resolve);\n }\n else if (options.source === CameraSource.Prompt) {\n let actionSheet = document.querySelector('pwa-action-sheet');\n if (!actionSheet) {\n actionSheet = document.createElement('pwa-action-sheet');\n document.body.appendChild(actionSheet);\n }\n actionSheet.header = options.promptLabelHeader || 'Photo';\n actionSheet.cancelable = false;\n actionSheet.options = [\n { title: options.promptLabelPhoto || 'From Photos' },\n { title: options.promptLabelPicture || 'Take Picture' },\n ];\n actionSheet.addEventListener('onSelection', async (e) => {\n const selection = e.detail;\n if (selection === 0) {\n this.fileInputExperience(options, resolve);\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n async pickImages(_options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n this.multipleFileInputExperience(resolve);\n });\n }\n async cameraExperience(options, resolve, reject) {\n if (customElements.get('pwa-camera-modal')) {\n const cameraModal = document.createElement('pwa-camera-modal');\n cameraModal.facingMode =\n options.direction === CameraDirection.Front ? 'user' : 'environment';\n document.body.appendChild(cameraModal);\n try {\n await cameraModal.componentOnReady();\n cameraModal.addEventListener('onPhoto', async (e) => {\n const photo = e.detail;\n if (photo === null) {\n reject(new CapacitorException('User cancelled photos app'));\n }\n else if (photo instanceof Error) {\n reject(photo);\n }\n else {\n resolve(await this._getCameraPhoto(photo, options));\n }\n cameraModal.dismiss();\n document.body.removeChild(cameraModal);\n });\n cameraModal.present();\n }\n catch (e) {\n this.fileInputExperience(options, resolve);\n }\n }\n else {\n console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements.`);\n this.fileInputExperience(options, resolve);\n }\n }\n fileInputExperience(options, resolve) {\n let input = document.querySelector('#_capacitor-camera-input');\n const cleanup = () => {\n var _a;\n (_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);\n };\n if (!input) {\n input = document.createElement('input');\n input.id = '_capacitor-camera-input';\n input.type = 'file';\n input.hidden = true;\n document.body.appendChild(input);\n input.addEventListener('change', (_e) => {\n const file = input.files[0];\n let format = 'jpeg';\n if (file.type === 'image/png') {\n format = 'png';\n }\n else if (file.type === 'image/gif') {\n format = 'gif';\n }\n if (options.resultType === 'dataUrl' ||\n options.resultType === 'base64') {\n const reader = new FileReader();\n reader.addEventListener('load', () => {\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: reader.result,\n format,\n });\n }\n else if (options.resultType === 'base64') {\n const b64 = reader.result.split(',')[1];\n resolve({\n base64String: b64,\n format,\n });\n }\n cleanup();\n });\n reader.readAsDataURL(file);\n }\n else {\n resolve({\n webPath: URL.createObjectURL(file),\n format: format,\n });\n cleanup();\n }\n });\n }\n input.accept = 'image/*';\n input.capture = true;\n if (options.source === CameraSource.Photos ||\n options.source === CameraSource.Prompt) {\n input.removeAttribute('capture');\n }\n else if (options.direction === CameraDirection.Front) {\n input.capture = 'user';\n }\n else if (options.direction === CameraDirection.Rear) {\n input.capture = 'environment';\n }\n input.click();\n }\n multipleFileInputExperience(resolve) {\n let input = document.querySelector('#_capacitor-camera-input-multiple');\n const cleanup = () => {\n var _a;\n (_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);\n };\n if (!input) {\n input = document.createElement('input');\n input.id = '_capacitor-camera-input-multiple';\n input.type = 'file';\n input.hidden = true;\n input.multiple = true;\n document.body.appendChild(input);\n input.addEventListener('change', (_e) => {\n const photos = [];\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < input.files.length; i++) {\n const file = input.files[i];\n let format = 'jpeg';\n if (file.type === 'image/png') {\n format = 'png';\n }\n else if (file.type === 'image/gif') {\n format = 'gif';\n }\n photos.push({\n webPath: URL.createObjectURL(file),\n format: format,\n });\n }\n resolve({ photos });\n cleanup();\n });\n }\n input.accept = 'image/*';\n input.click();\n }\n _getCameraPhoto(photo, options) {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n const format = photo.type.split('/')[1];\n if (options.resultType === 'uri') {\n resolve({\n webPath: URL.createObjectURL(photo),\n format: format,\n saved: false,\n });\n }\n else {\n reader.readAsDataURL(photo);\n reader.onloadend = () => {\n const r = reader.result;\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: r,\n format: format,\n saved: false,\n });\n }\n else {\n resolve({\n base64String: r.split(',')[1],\n format: format,\n saved: false,\n });\n }\n };\n reader.onerror = e => {\n reject(e);\n };\n }\n });\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n try {\n // https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query\n // the specific permissions that are supported varies among browsers that implement the\n // permissions API, so we need a try/catch in case 'camera' is invalid\n const permission = await window.navigator.permissions.query({\n name: 'camera',\n });\n return {\n camera: permission.state,\n photos: 'granted',\n };\n }\n catch (_a) {\n throw this.unavailable('Camera permissions are not available in this browser');\n }\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n async pickLimitedLibraryPhotos() {\n throw this.unavailable('Not implemented on web.');\n }\n async getLimitedLibraryPhotos() {\n throw this.unavailable('Not implemented on web.');\n }\n}\nconst Camera = new CameraWeb();\nexport { Camera };\n//# sourceMappingURL=web.js.map"],"sourceRoot":""}