@livetiles/reach-components-react 0.5.0-preview.1004 → 0.5.0-preview.1007

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/web.esm.js ADDED
@@ -0,0 +1 @@
1
+ import{ac as e,ad as t,ae as a,af as r}from"./index.esm2.js";import"react/jsx-runtime";import"events";import"react";import"office-ui-fabric-react";import"react-router-dom";import"react-is";import"styled-components";import"react-dom";import"office-ui-fabric-core/dist/css/fabric.css";import"office-ui-fabric-react/lib/common/DirectionalHint";import"react-dom/server";class i extends e{async getPhoto(e){return new Promise((async(a,r)=>{if(e.webUseInput||e.source===t.Photos)this.fileInputExperience(e,a);else if(e.source===t.Prompt){let t=document.querySelector("pwa-action-sheet");t||(t=document.createElement("pwa-action-sheet"),document.body.appendChild(t)),t.header=e.promptLabelHeader||"Photo",t.cancelable=!1,t.options=[{title:e.promptLabelPhoto||"From Photos"},{title:e.promptLabelPicture||"Take Picture"}],t.addEventListener("onSelection",(async t=>{0===t.detail?this.fileInputExperience(e,a):this.cameraExperience(e,a,r)}))}else this.cameraExperience(e,a,r)}))}async pickImages(e){return new Promise((async e=>{this.multipleFileInputExperience(e)}))}async cameraExperience(e,t,i){if(customElements.get("pwa-camera-modal")){const o=document.createElement("pwa-camera-modal");o.facingMode=e.direction===a.Front?"user":"environment",document.body.appendChild(o);try{await o.componentOnReady(),o.addEventListener("onPhoto",(async a=>{const n=a.detail;null===n?i(new r("User cancelled photos app")):n instanceof Error?i(n):t(await this._getCameraPhoto(n,e)),o.dismiss(),document.body.removeChild(o)})),o.present()}catch(a){this.fileInputExperience(e,t)}}else console.error("Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements."),this.fileInputExperience(e,t)}fileInputExperience(e,r){let i=document.querySelector("#_capacitor-camera-input");const o=()=>{var e;null===(e=i.parentNode)||void 0===e||e.removeChild(i)};i||(i=document.createElement("input"),i.id="_capacitor-camera-input",i.type="file",i.hidden=!0,document.body.appendChild(i),i.addEventListener("change",(t=>{const a=i.files[0];let n="jpeg";if("image/png"===a.type?n="png":"image/gif"===a.type&&(n="gif"),"dataUrl"===e.resultType||"base64"===e.resultType){const t=new FileReader;t.addEventListener("load",(()=>{if("dataUrl"===e.resultType)r({dataUrl:t.result,format:n});else if("base64"===e.resultType){const e=t.result.split(",")[1];r({base64String:e,format:n})}o()})),t.readAsDataURL(a)}else r({webPath:URL.createObjectURL(a),format:n}),o()}))),i.accept="image/*",i.capture=!0,e.source===t.Photos||e.source===t.Prompt?i.removeAttribute("capture"):e.direction===a.Front?i.capture="user":e.direction===a.Rear&&(i.capture="environment"),i.click()}multipleFileInputExperience(e){let t=document.querySelector("#_capacitor-camera-input-multiple");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",(a=>{const r=[];for(let e=0;e<t.files.length;e++){const a=t.files[e];let i="jpeg";"image/png"===a.type?i="png":"image/gif"===a.type&&(i="gif"),r.push({webPath:URL.createObjectURL(a),format:i})}var i;e({photos:r}),null===(i=t.parentNode)||void 0===i||i.removeChild(t)}))),t.accept="image/*",t.click()}_getCameraPhoto(e,t){return new Promise(((a,r)=>{const i=new FileReader,o=e.type.split("/")[1];"uri"===t.resultType?a({webPath:URL.createObjectURL(e),format:o,saved:!1}):(i.readAsDataURL(e),i.onloadend=()=>{const e=i.result;"dataUrl"===t.resultType?a({dataUrl:e,format:o,saved:!1}):a({base64String:e.split(",")[1],format:o,saved:!1})},i.onerror=e=>{r(e)})}))}async checkPermissions(){if("undefined"==typeof navigator||!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(e){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 o=new i;export{o as Camera,i as CameraWeb};