Rapport-Mobileapp/dist/assets/web-AScraMDr.js

8 lines
15 KiB
JavaScript

import{a as le,_ as ge,f as me,b as Re,g as we,W as ye}from"./index-CQwTocWK.js";const F={RECORDING:"RECORDING",PAUSED:"PAUSED",NONE:"NONE"};var re;(function(o){o.Documents="DOCUMENTS",o.Data="DATA",o.Library="LIBRARY",o.Cache="CACHE",o.External="EXTERNAL",o.ExternalStorage="EXTERNAL_STORAGE",o.ExternalCache="EXTERNAL_CACHE",o.LibraryNoCloud="LIBRARY_NO_CLOUD",o.Temporary="TEMPORARY"})(re||(re={}));var te;(function(o){o.UTF8="utf8",o.ASCII="ascii",o.UTF16="utf16"})(te||(te={}));const k=le("Filesystem",{web:()=>ge(()=>import("./web-PsETgseH.js"),__vite__mapDeps([0,1,2])).then(o=>new o.FilesystemWeb)});me();const Ee=le("BlobWriter");function _e(o){return window.btoa(Array.from(new Uint8Array(o)).map(function(i){return String.fromCharCode(i)}).join(""))}function be({path:o,directory:i,blob:s,recursive:p}){return k.writeFile({directory:i,path:o,recursive:p,data:""}).then(function(){return new Promise(function(d,l){function c(u){l(u.target.error)}const h=window.indexedDB.open("Disc");h.onerror=c,h.onsuccess=function(){const m=h.result.transaction("FileStorage","readwrite");m.onerror=c;const v=m.objectStore("FileStorage"),g=`/${i}/${o.replace(/^\//,"")}`,_=v.get(g);_.onsuccess=function(){_.result.size=s.size,_.result.content=s;const P=v.put(_.result);P.onsuccess=function(){d(void 0)}}}})})}function ne({path:o,directory:i,blob:s,recursive:p}){return k.writeFile({directory:i,path:o,recursive:p,data:""}).then(function d(){if(s.size===0)return Promise.resolve();const l=3*128*1024,c=s.slice(0,l);return s=s.slice(l),new Response(c).arrayBuffer().then(function(u){return k.appendFile({directory:i,path:o,data:_e(u)})}).then(d)})}function Se(o){const{path:i,directory:s,blob:p,fast_mode:d=!1,recursive:l,on_fallback:c}=o;return!p||!Number.isSafeInteger(p.size)||typeof p.type!="string"?Promise.reject(new Error("Not a Blob.")):Re.getPlatform()==="web"?d?be(o):ne(o):Promise.all([Ee.get_config(),k.getUri({path:i,directory:s})]).then(function([h,u]){const m=u.uri.replace("file://","");return(window.CapacitorWebFetch||window.fetch)(h.base_url+m+(l?"?recursive=true":""),{headers:{authorization:h.auth_token},method:"put",body:p}).then(function(g){if(g.status!==204)throw new Error("Bad HTTP status: "+g.status);return u.uri})}).catch(function(u){return c!==void 0&&c(u),ne(o)})}const Pe=Object.freeze(Se);var fe={};function Te(o){return o&&o.__esModule?o:{default:o}}var Oe=Te,W={exports:{}},oe;function Ne(){return oe||(oe=1,function(o){var i=function(s){var p=Object.prototype,d=p.hasOwnProperty,l=Object.defineProperty||function(r,e,t){r[e]=t.value},c,h=typeof Symbol=="function"?Symbol:{},u=h.iterator||"@@iterator",m=h.asyncIterator||"@@asyncIterator",v=h.toStringTag||"@@toStringTag";function g(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{g({},"")}catch{g=function(e,t,a){return e[t]=a}}function _(r,e,t,a){var n=e&&e.prototype instanceof U?e:U,f=Object.create(n.prototype),R=new Y(a||[]);return l(f,"_invoke",{value:pe(r,t,R)}),f}s.wrap=_;function P(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(a){return{type:"throw",arg:a}}}var Q="suspendedStart",he="suspendedYield",J="executing",I="completed",b={};function U(){}function C(){}function O(){}var B={};g(B,u,function(){return this});var j=Object.getPrototypeOf,G=j&&j(j($([])));G&&G!==p&&d.call(G,u)&&(B=G);var D=O.prototype=U.prototype=Object.create(B);C.prototype=O,l(D,"constructor",{value:O,configurable:!0}),l(O,"constructor",{value:C,configurable:!0}),C.displayName=g(O,v,"GeneratorFunction");function K(r){["next","throw","return"].forEach(function(e){g(r,e,function(t){return this._invoke(e,t)})})}s.isGeneratorFunction=function(r){var e=typeof r=="function"&&r.constructor;return e?e===C||(e.displayName||e.name)==="GeneratorFunction":!1},s.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,O):(r.__proto__=O,g(r,v,"GeneratorFunction")),r.prototype=Object.create(D),r},s.awrap=function(r){return{__await:r}};function M(r,e){function t(f,R,w,E){var y=P(r[f],r,R);if(y.type==="throw")E(y.arg);else{var z=y.arg,L=z.value;return L&&typeof L=="object"&&d.call(L,"__await")?e.resolve(L.__await).then(function(N){t("next",N,w,E)},function(N){t("throw",N,w,E)}):e.resolve(L).then(function(N){z.value=N,w(z)},function(N){return t("throw",N,w,E)})}}var a;function n(f,R){function w(){return new e(function(E,y){t(f,R,E,y)})}return a=a?a.then(w,w):w()}l(this,"_invoke",{value:n})}K(M.prototype),g(M.prototype,m,function(){return this}),s.AsyncIterator=M,s.async=function(r,e,t,a,n){n===void 0&&(n=Promise);var f=new M(_(r,e,t,a),n);return s.isGeneratorFunction(e)?f:f.next().then(function(R){return R.done?R.value:f.next()})};function pe(r,e,t){var a=Q;return function(f,R){if(a===J)throw new Error("Generator is already running");if(a===I){if(f==="throw")throw R;return ee()}for(t.method=f,t.arg=R;;){var w=t.delegate;if(w){var E=Z(w,t);if(E){if(E===b)continue;return E}}if(t.method==="next")t.sent=t._sent=t.arg;else if(t.method==="throw"){if(a===Q)throw a=I,t.arg;t.dispatchException(t.arg)}else t.method==="return"&&t.abrupt("return",t.arg);a=J;var y=P(r,e,t);if(y.type==="normal"){if(a=t.done?I:he,y.arg===b)continue;return{value:y.arg,done:t.done}}else y.type==="throw"&&(a=I,t.method="throw",t.arg=y.arg)}}}function Z(r,e){var t=e.method,a=r.iterator[t];if(a===c)return e.delegate=null,t==="throw"&&r.iterator.return&&(e.method="return",e.arg=c,Z(r,e),e.method==="throw")||t!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+t+"' method")),b;var n=P(a,r.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,b;var f=n.arg;if(!f)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,b;if(f.done)e[r.resultName]=f.value,e.next=r.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return f;return e.delegate=null,b}K(D),g(D,v,"Generator"),g(D,u,function(){return this}),g(D,"toString",function(){return"[object Generator]"});function ve(r){var e={tryLoc:r[0]};1 in r&&(e.catchLoc=r[1]),2 in r&&(e.finallyLoc=r[2],e.afterLoc=r[3]),this.tryEntries.push(e)}function q(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function Y(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(ve,this),this.reset(!0)}s.keys=function(r){var e=Object(r),t=[];for(var a in e)t.push(a);return t.reverse(),function n(){for(;t.length;){var f=t.pop();if(f in e)return n.value=f,n.done=!1,n}return n.done=!0,n}};function $(r){if(r){var e=r[u];if(e)return e.call(r);if(typeof r.next=="function")return r;if(!isNaN(r.length)){var t=-1,a=function n(){for(;++t<r.length;)if(d.call(r,t))return n.value=r[t],n.done=!1,n;return n.value=c,n.done=!0,n};return a.next=a}}return{next:ee}}s.values=$;function ee(){return{value:c,done:!0}}return Y.prototype={constructor:Y,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(q),!r)for(var e in this)e.charAt(0)==="t"&&d.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var r=this.tryEntries[0],e=r.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function t(E,y){return f.type="throw",f.arg=r,e.next=E,y&&(e.method="next",e.arg=c),!!y}for(var a=this.tryEntries.length-1;a>=0;--a){var n=this.tryEntries[a],f=n.completion;if(n.tryLoc==="root")return t("end");if(n.tryLoc<=this.prev){var R=d.call(n,"catchLoc"),w=d.call(n,"finallyLoc");if(R&&w){if(this.prev<n.catchLoc)return t(n.catchLoc,!0);if(this.prev<n.finallyLoc)return t(n.finallyLoc)}else if(R){if(this.prev<n.catchLoc)return t(n.catchLoc,!0)}else if(w){if(this.prev<n.finallyLoc)return t(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(r,e){for(var t=this.tryEntries.length-1;t>=0;--t){var a=this.tryEntries[t];if(a.tryLoc<=this.prev&&d.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var n=a;break}}n&&(r==="break"||r==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var f=n?n.completion:{};return f.type=r,f.arg=e,n?(this.method="next",this.next=n.finallyLoc,b):this.complete(f)},complete:function(r,e){if(r.type==="throw")throw r.arg;return r.type==="break"||r.type==="continue"?this.next=r.arg:r.type==="return"?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):r.type==="normal"&&e&&(this.next=e),b},finish:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===r)return this.complete(t.completion,t.afterLoc),q(t),b}},catch:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===r){var a=t.completion;if(a.type==="throw"){var n=a.arg;q(t)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:$(r),resultName:e,nextLoc:t},this.method==="next"&&(this.arg=c),b}},s}(o.exports);try{regeneratorRuntime=i}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}}(W)),W.exports}var H,ie;function De(){return ie||(ie=1,H=Ne()),H}var V,ae;function Le(){if(ae)return V;ae=1;function o(s,p,d,l,c,h,u){try{var m=s[h](u),v=m.value}catch(g){d(g);return}m.done?p(v):Promise.resolve(v).then(l,c)}function i(s){return function(){var p=this,d=arguments;return new Promise(function(l,c){var h=s.apply(p,d);function u(v){o(h,l,c,u,m,"next",v)}function m(v){o(h,l,c,u,m,"throw",v)}u(void 0)})}}return V=i,V}(function(o){var i=Oe;Object.defineProperty(o,"__esModule",{value:!0}),o.default=d;var s=i(De()),p=i(Le());function d(c){return l.apply(this,arguments)}function l(){return(l=(0,p.default)(s.default.mark(function c(h){var u,m;return s.default.wrap(function(v){for(;;)switch(v.prev=v.next){case 0:return u=document.createElement("video"),m=new Promise(function(g,_){u.addEventListener("loadedmetadata",function(){u.duration===1/0?(u.currentTime=Number.MAX_SAFE_INTEGER,u.ontimeupdate=function(){u.ontimeupdate=null,g(u.duration),u.currentTime=0}):g(u.duration)}),u.onerror=function(P){return _(P.target.error)}}),u.src=typeof h=="string"||h instanceof String?h:window.URL.createObjectURL(h),v.abrupt("return",m);case 4:case"end":return v.stop()}},c)}))).apply(this,arguments)}})(fe);const Ae=we(fe),T=()=>({value:!0}),A=()=>({value:!1}),Ie=()=>new Error("MISSING_PERMISSION"),Ce=()=>new Error("ALREADY_RECORDING"),Ge=()=>new Error("DEVICE_CANNOT_VOICE_RECORD"),se=()=>new Error("FAILED_TO_RECORD"),Me=()=>new Error("EMPTY_RECORDING"),X=()=>new Error("RECORDING_HAS_NOT_STARTED"),ue=()=>new Error("FAILED_TO_FETCH_RECORDING"),x=()=>new Error("COULD_NOT_QUERY_PERMISSION_STATUS"),ce={"audio/aac":".aac","audio/mp4":".mp3","audio/webm;codecs=opus":".ogg","audio/webm":".ogg","audio/ogg;codecs=opus":".ogg"},de=()=>new Promise(()=>{});class S{constructor(){this.mediaRecorder=null,this.chunks=[],this.pendingResult=de()}static async canDeviceVoiceRecord(){var i;return((i=navigator==null?void 0:navigator.mediaDevices)===null||i===void 0?void 0:i.getUserMedia)==null||S.getSupportedMimeType()==null?A():T()}async startRecording(i){if(this.mediaRecorder!=null)throw Ce();if(!(await S.canDeviceVoiceRecord()).value)throw Ge();if(!(await S.hasAudioRecordingPermission().catch(()=>T())).value)throw Ie();return navigator.mediaDevices.getUserMedia({audio:!0}).then(d=>this.onSuccessfullyStartedRecording(d,i)).catch(this.onFailedToStartRecording.bind(this))}async stopRecording(){if(this.mediaRecorder==null)throw X();try{return this.mediaRecorder.stop(),this.mediaRecorder.stream.getTracks().forEach(i=>i.stop()),this.pendingResult}catch{throw ue()}finally{this.prepareInstanceForNextOperation()}}static async hasAudioRecordingPermission(){return navigator.permissions.query==null?navigator.mediaDevices==null?Promise.reject(x()):navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>T()).catch(()=>{throw x()}):navigator.permissions.query({name:"microphone"}).then(i=>({value:i.state==="granted"})).catch(()=>{throw x()})}static async requestAudioRecordingPermission(){return(await S.hasAudioRecordingPermission().catch(()=>A())).value?T():navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>T()).catch(()=>A())}pauseRecording(){if(this.mediaRecorder==null)throw X();return this.mediaRecorder.state==="recording"?(this.mediaRecorder.pause(),Promise.resolve(T())):Promise.resolve(A())}resumeRecording(){if(this.mediaRecorder==null)throw X();return this.mediaRecorder.state==="paused"?(this.mediaRecorder.resume(),Promise.resolve(T())):Promise.resolve(A())}getCurrentStatus(){return this.mediaRecorder==null?Promise.resolve({status:F.NONE}):this.mediaRecorder.state==="recording"?Promise.resolve({status:F.RECORDING}):this.mediaRecorder.state==="paused"?Promise.resolve({status:F.PAUSED}):Promise.resolve({status:F.NONE})}static getSupportedMimeType(){if((MediaRecorder==null?void 0:MediaRecorder.isTypeSupported)==null)return null;const i=Object.keys(ce).find(s=>MediaRecorder.isTypeSupported(s));return i??null}onSuccessfullyStartedRecording(i,s){return this.pendingResult=new Promise((p,d)=>{this.mediaRecorder=new MediaRecorder(i),this.mediaRecorder.onerror=()=>{this.prepareInstanceForNextOperation(),d(se())},this.mediaRecorder.onstop=async()=>{var l,c,h;const u=S.getSupportedMimeType();if(u==null){this.prepareInstanceForNextOperation(),d(ue());return}const m=new Blob(this.chunks,{type:u});if(m.size<=0){this.prepareInstanceForNextOperation(),d(Me());return}let v,g;s!=null?(v=`${(h=(c=(l=s.subDirectory)===null||l===void 0?void 0:l.match(/^\/?(.+[^/])\/?$/))===null||c===void 0?void 0:c[1])!==null&&h!==void 0?h:""}/recording-${new Date().getTime()}${ce[u]}`,await Pe({blob:m,directory:s.directory,fast_mode:!0,path:v,recursive:!0})):g=await S.blobToBase64(m);const _=await Ae(m);this.prepareInstanceForNextOperation(),p({value:{recordDataBase64:g,mimeType:u,msDuration:_*1e3,path:v}})},this.mediaRecorder.ondataavailable=l=>this.chunks.push(l.data),this.mediaRecorder.start()}),T()}onFailedToStartRecording(){throw this.prepareInstanceForNextOperation(),se()}static blobToBase64(i){return new Promise(s=>{const p=new FileReader;p.onloadend=()=>{const d=String(p.result),l=d.split("base64,"),c=l.length>1?l[1]:d;s(c.trim())},p.readAsDataURL(i)})}prepareInstanceForNextOperation(){if(this.mediaRecorder!=null&&this.mediaRecorder.state==="recording")try{this.mediaRecorder.stop()}catch(i){console.warn("While trying to stop a media recorder, an error was thrown",i)}this.pendingResult=de(),this.mediaRecorder=null,this.chunks=[]}}class Fe extends ye{constructor(){super(...arguments),this.voiceRecorderInstance=new S}canDeviceVoiceRecord(){return S.canDeviceVoiceRecord()}hasAudioRecordingPermission(){return S.hasAudioRecordingPermission()}requestAudioRecordingPermission(){return S.requestAudioRecordingPermission()}startRecording(i){return this.voiceRecorderInstance.startRecording(i)}stopRecording(){return this.voiceRecorderInstance.stopRecording()}pauseRecording(){return this.voiceRecorderInstance.pauseRecording()}resumeRecording(){return this.voiceRecorderInstance.resumeRecording()}getCurrentStatus(){return this.voiceRecorderInstance.getCurrentStatus()}}const Ue=Object.freeze(Object.defineProperty({__proto__:null,VoiceRecorderWeb:Fe},Symbol.toStringTag,{value:"Module"}));export{te as E,Ue as w};
function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = ["assets/web-PsETgseH.js","assets/index-CQwTocWK.js","assets/index-Br6gItOh.css"]
}
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
}