1import{b2 as A,b5 as u,b1 as O}from"./index-DLyyNZmW.js";import"./vendor-BgKbKc7J.js";import"./signalr-BrM92d4O.js";import"./utils-Dt19vo1Q.js";import"./dnd-DrUs3kaJ.js";var m;(function(n){n.Prompt="PROMPT",n.Camera="CAMERA",n.Photos="PHOTOS"})(m||(m={}));var p;(function(n){n.Rear="REAR",n.Front="FRONT"})(p||(p={}));var L;(function(n){n.Uri="uri",n.Base64="base64",n.DataUrl="dataUrl"})(L||(L={}));var g;(function(n){n[n.Photo=0]="Photo",n[n.Video=1]="Video"})(g||(g={}));var f;(function(n){n[n.Photo=0]="Photo",n[n.Video=1]="Video",n[n.All=2]="All"})(f||(f={}));var _;(function(n){n[n.JPEG=0]="JPEG",n[n.PNG=1]="PNG"})(_||(_={}));var F;(function(n){n.CameraPermissionDenied="OS-PLUG-CAMR-0003",n.GalleryPermissionDenied="OS-PLUG-CAMR-0005",n.NoCameraAvailable="OS-PLUG-CAMR-0007",n.TakePhotoCancelled="OS-PLUG-CAMR-0006",n.TakePhotoFailed="OS-PLUG-CAMR-0010",n.TakePhotoInvalidArguments="OS-PLUG-CAMR-0014",n.InvalidImageData="OS-PLUG-CAMR-0008",n.EditPhotoFailed="OS-PLUG-CAMR-0009",n.EditPhotoCancelled="OS-PLUG-CAMR-0013",n.EditPhotoEmptyUri="OS-PLUG-CAMR-0024",n.ImageNotFound="OS-PLUG-CAMR-0011",n.ProcessImageFailed="OS-PLUG-CAMR-0012",n.ChooseMediaFailed="OS-PLUG-CAMR-0018",n.ChooseMediaCancelled="OS-PLUG-CAMR-0020",n.MediaPathError="OS-PLUG-CAMR-0021",n.FetchImageFromUriFailed="OS-PLUG-CAMR-0028",n.RecordVideoFailed="OS-PLUG-CAMR-0016",n.RecordVideoCancelled="OS-PLUG-CAMR-0017",n.VideoNotFound="OS-PLUG-CAMR-0025",n.PlayVideoFailed="OS-PLUG-CAMR-0023",n.EncodeResultFailed="OS-PLUG-CAMR-0019",n.FileNotFound="OS-PLUG-CAMR-0027",n.InvalidArgument="OS-PLUG-CAMR-0031",n.GeneralError="OS-PLUG-CAMR-0026"})(F||(F={}));class I extends A{async takePhoto(e){return new Promise(async(i,t)=>{e.webUseInput?this.takePhotoCameraInputExperience(e,i,t):this.takePhotoCameraExperience(e,i,t)})}async recordVideo(e){throw this.unimplemented("recordVideo is not implemented on Web.")}async playVideo(e){throw this.unimplemented("playVideo is not implemented on Web.")}async chooseFromGallery(e){return new Promise(async(i,t)=>{this.galleryInputExperience(e,i,t)})}async editPhoto(e){throw this.unimplemented("editPhoto is not implemented on Web.")}async editURIPhoto(e){throw this.unimplemented("editURIPhoto is not implemented on Web.")}async getPhoto(e){return new Promise(async(i,t)=>{if(e.webUseInput||e.source===m.Photos)this.fileInputExperience(e,i,t);else if(e.source===m.Prompt){let a=document.querySelector("pwa-action-sheet");a||(a=document.createElement("pwa-action-sheet"),document.body.appendChild(a)),a.header=e.promptLabelHeader||"Photo",a.cancelable=!1,a.options=[{title:e.promptLabelPhoto||"From Photos"},{title:e.promptLabelPicture||"Take Picture"}],a.addEventListener("onSelection",async o=>{o.detail===0?this.fileInputExperience(e,i,t):this.cameraExperience(e,i,t)})}else this.cameraExperience(e,i,t)})}async pickImages(e){return new Promise(async(i,t)=>{this.multipleFileInputExperience(i,t)})}async cameraExperience(e,i,t){await this._setupPWACameraModal(e.direction,a=>this._getCameraPhoto(a,e),()=>this.fileInputExperience(e,i,t),i,t)}fileInputExperience(e,i,t){let a=document.querySelector("#_capacitor-camera-input");const o=()=>{var l;(l=a.parentNode)===null||l===void 0||l.removeChild(a)};a||(a=document.createElement("input"),a.id="_capacitor-camera-input",a.type="file",a.hidden=!0,document.body.appendChild(a),a.addEventListener("change",l=>{const s=a.files[0];let r="jpeg";if(s.type==="image/png"?r="png":s.type==="image/gif"&&(r="gif"),e.resultType==="dataUrl"||e.resultType==="base64"){const c=new FileReader;c.addEventListener("load",()=>{if(e.resultType==="dataUrl")i({dataUrl:c.result,format:r});else if(e.resultType==="base64"){const h=c.result.split(",")[1];i({base64String:h,format:r})}o()}),c.readAsDataURL(s)}else i({webPath:URL.createObjectURL(s),format:r}),o()}),a.addEventListener("cancel",l=>{t(new u("User cancelled photos app")),o()})),a.accept="image/*",a.capture=!0,e.source===m.Photos||e.source===m.Prompt?a.removeAttribute("capture"):e.direction===p.Front?a.capture="user":e.direction===p.Rear&&(a.capture="environment"),a.click()}multipleFileInputExperience(e,i){let t=document.querySelector("#_capacitor-camera-in
1put-multiple");const a=()=>{var o;(o=t.parentNode)===null||o===void 0||o.removeChild(t)};t||(t=document.createElement("input"),t.id="_capacitor-camera-input-multiple",t.type="file",t.hidden=!0,t.multiple=!0,document.body.appendChild(t),t.addEventListener("change",o=>{const l=[];for(let s=0;s<t.files.length;s++){const r=t.files[s];let c="jpeg";r.type==="image/png"?c="png":r.type==="image/gif"&&(c="gif"),l.push({webPath:URL.createObjectURL(r),format:c})}e({photos:l}),a()}),t.addEventListener("cancel",o=>{i(new u("User cancelled photos app")),a()})),t.accept="image/*",t.click()}_getCameraPhoto(e,i){return new Promise((t,a)=>{const o=new FileReader,l=this._getFileFormat(e);i.resultType==="uri"?t({webPath:URL.createObjectURL(e),format:l,saved:!1}):(o.readAsDataURL(e),o.onloadend=()=>{const s=o.result;i.resultType==="dataUrl"?t({dataUrl:s,format:l,saved:!1}):t({base64String:s.split(",")[1],format:l,saved:!1})},o.onerror=s=>{a(s)})})}async takePhotoCameraExperience(e,i,t){await this._setupPWACameraModal(e.cameraDirection,a=>{var o;return this._buildPhotoMediaResult(a,(o=e.includeMetadata)!==null&&o!==void 0?o:!1)},()=>this.takePhotoCameraInputExperience(e,i,t),i,t)}takePhotoCameraInputExperience(e,i,t){const a=this._createFileInput("_capacitor-camera-input-takephoto"),o=()=>{var l;(l=a.parentNode)===null||l===void 0||l.removeChild(a)};a.onchange=async l=>{var s;if(!this._validateFileInput(a,t,o))return;const r=a.files[0];i(await this._buildPhotoMediaResult(r,(s=e.includeMetadata)!==null&&s!==void 0?s:!1)),o()},a.oncancel=()=>{t(new u("User cancelled photos app")),o()},a.accept="image/*",e.cameraDirection===p.Front?a.capture="user":a.capture="environment",a.click()}galleryInputExperience(e,i,t){var a,o;const l=this._createFileInput("_capacitor-camera-input-gallery");l.multiple=(a=e.allowMultipleSelection)!==null&&a!==void 0?a:!1;const s=()=>{var c;(c=l.parentNode)===null||c===void 0||c.removeChild(l)};l.onchange=async c=>{var h;if(!this._validateFileInput(l,t,s))return;const v=[];for(let w=0;w<l.files.length;w++){const d=l.files[w];if(d.type.startsWith("image/"))v.push(await this._buildPhotoMediaResult(d,(h=e.includeMetadata)!==null&&h!==void 0?h:!1));else if(d.type.startsWith("video/")){const M=this._getFileFormat(d);let y,b,U;try{const P=await this._getVideoMetadata(d);y=P.thumbnail,e.includeMetadata&&(b=P.resolution,U=P.duration)}catch(P){console.warn("Failed to get video metadata:",P)}const R={type:g.Video,thumbnail:y,webPath:URL.createObjectURL(d),saved:!1};e.includeMetadata&&(R.metadata={format:M,resolution:b,size:d.size,creationDate:new Date(d.lastModified).toISOString(),duration:U}),v.push(R)}}i({results:v}),s()},l.oncancel=()=>{t(new u("User cancelled photos app")),s()};const r=(o=e.mediaType)!==null&&o!==void 0?o:f.Photo;r===f.Photo?l.accept="image/*":r===f.Video?l.accept="video/*":l.accept="image/*,video/*",l.click()}_getFileFormat(e){return e.type==="image/png"?"png":e.type==="image/gif"?"gif":e.type.startsWith("video/")?e.type.split("/")[1]:e.type.startsWith("image/")?"jpeg":e.type.split("/")[1]||"jpeg"}async _buildPhotoMediaResult(e,i){const t=this._getFileFormat(e),a=await this._getBase64FromFile(e),o={type:g.Photo,thumbnail:a,webPath:URL.createObjectURL(e),saved:!1};if(i){const l=await this._getImageResolution(e);o.metadata={format:t,resolution:l,size:e.size,creationDate:"lastModified"in e?new Date(e.lastModified).toISOString():new Date().toISOString()}}return o}_validateFileInput(e,i,t){if(!e.files||e.files.length===0){const a=e.multiple?"No files selected":"No file selected";return i(new u(a)),t(),!1}return!0}async _setupPWACameraModal(e,i,t,a,o){if(customElements.get("pwa-camera-modal")){const l=document.createElement("pwa-camera-modal");l.facingMode=e===p.Front?"user":"environment",document.body.appendChild(l);try{await l.componentOnReady(),l.addEventListener("onPhoto",async s=>{const r=s.detail;r===null?o(new u("User cancelled photos app")):r instanceof Error?o(r):a(await i(r)),l.dismiss(),document.body.removeChild(l)}),l.present()}catch{t()}}else console.error("Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements."),t()}_createFileInput(e){let i=document.querySelector(`#${e}`);
1return i||(i=document.createElement("input"),i.id=e,i.type="file",i.hidden=!0,document.body.appendChild(i)),i}async _getImageResolution(e){try{const i=await createImageBitmap(e),t=`${i.width}x${i.height}`;return i.close(),t}catch(i){console.warn("Failed to get image resolution:",i);return}}_getBase64FromFile(e){return new Promise((i,t)=>{const a=new FileReader;a.onloadend=()=>{const l=a.result.split(",")[1];i(l)},a.onerror=o=>{t(o)},a.readAsDataURL(e)})}_getVideoMetadata(e){return new Promise(i=>{const t=document.createElement("video");t.preload="metadata",t.muted=!0,t.onloadedmetadata=()=>{const a=Math.min(1,t.duration*.1);t.currentTime=a},t.onseeked=()=>{const a={resolution:`${t.videoWidth}x${t.videoHeight}`,duration:t.duration};try{const o=document.createElement("canvas");o.width=t.videoWidth,o.height=t.videoHeight;const l=o.getContext("2d");l&&(l.drawImage(t,0,0,o.width,o.height),a.thumbnail=o.toDataURL("image/jpeg",.8).split(",")[1])}catch(o){console.warn("Failed to generate video thumbnail:",o)}URL.revokeObjectURL(t.src),i(a)},t.onerror=()=>{URL.revokeObjectURL(t.src),i({})},t.src=URL.createObjectURL(e)})}async checkPermissions(){if(typeof navigator>"u"||!navigator.permissions)throw this.unavailable("Permissions API not available in this browser");try{return{camera:(await window.navigator.permissions.query({name:"camera"})).state,photos:"granted"}}catch{throw this.unavailable("Camera permissions are not available in this browser")}}async requestPermissions(){throw this.unimplemented("Not implemented on web.")}async pickLimitedLibraryPhotos(){throw this.unavailable("Not implemented on web.")}async getLimitedLibraryPhotos(){throw this.unavailable("Not implemented on web.")}}const N=O("Camera",{web:()=>new I});export{N as Camera,p as CameraDirection,F as CameraErrorCode,L as CameraResultType,m as CameraSource,_ as EncodingType,g as MediaType,f as MediaTypeSelection};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.