Files
FireworksApp/staticfiles/vite/assets/manual-report-DqrR4OFn.js
T
2026-10-14 18:17:27 +02:00

2 lines
19 KiB
JavaScript

const Ee=document.querySelector("#manual-report-form"),u=window.BOOMCAST_I18N||{};function qe(){if(!Ee)return null;const e=document.querySelector("#burst-start"),t=e.closest(".burst-listener"),n=e.closest(".manual-report__supporting"),i=document.querySelector("#burst-state"),m=document.querySelector("#burst-panel"),f=document.querySelector("#burst-heading"),k=document.querySelector("#burst-detail"),S=document.querySelector("#burst-waveform"),N=document.querySelector("#burst-preview"),we=document.querySelector("#burst-resume"),fe=document.querySelector("#burst-discard"),Le=document.querySelector("#burst-stop"),ce=document.querySelector("#burst-error"),A=new Float32Array(300);let v=0,G="off",W,C,X,c,R,E,j,M;function le(){const a=S.getContext("2d");a.clearRect(0,0,S.width,S.height),a.fillStyle="#ffbd62";const l=S.width/A.length,h=Math.max(.003,...A);for(let r=0;r<A.length;r++){const F=A[(v+r)%A.length],y=Math.max(2,Math.min(S.height,F/h*S.height*.8));a.fillRect(r*l,(S.height-y)/2,Math.max(1,l-1),y)}}function ue(){j=null,N.pause(),N.removeAttribute("src"),N.load(),N.hidden=!0,E&&URL.revokeObjectURL(E),E=null}function q(a){G=a,t&&(t.dataset.state=a),n&&(n.dataset.state=a),i&&(i.textContent=a==="listening"?u.listeningNextBang||"Listening for the next bang":a==="tail"?u.soundDetected||"Sound detected":a==="captured"?u.soundCaptured||"Sound captured":u.notListening||"Not listening"),e.hidden=a!=="off",m.hidden=a==="off",we.hidden=fe.hidden=a!=="captured",f.textContent=a==="captured"?u.soundCaptured||"Sound captured":a==="tail"?u.soundDetectedFinishing||"Sound detected — finishing clip…":u.listeningNextSound||"Listening for the next sound…",k.textContent=a==="listening"?u.keepingRecentAudio||"Keeping the most recent ~10 seconds":a==="captured"?u.previewClipOrSend||"Preview the clip or send your report.":""}function Be(a,l){const h=new ArrayBuffer(44+a.length*2),r=new DataView(h),F=(y,D)=>{for(let _=0;_<D.length;_++)r.setUint8(y+_,D.charCodeAt(_))};F(0,"RIFF"),r.setUint32(4,h.byteLength-8,!0),F(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,l,!0),r.setUint32(28,l*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),F(36,"data"),r.setUint32(40,a.length*2,!0);for(let y=0;y<a.length;y++){const D=Math.max(-1,Math.min(1,a[y]));r.setInt16(44+y*2,D<0?D*32768:D*32767,!0)}return new Blob([h],{type:"audio/wav"})}function He(){return`sound-signal-manual-${new Date().toISOString().replace(/[-:]/g,"").slice(0,15)}.wav`}async function ke(){var a;ce.hidden=!0,e.disabled=!0,t&&(t.dataset.state="starting"),n&&(n.dataset.state="starting"),i&&(i.textContent=u.startingMicrophone||"Starting microphone…");try{if(!((a=navigator.mediaDevices)!=null&&a.getUserMedia)||!window.AudioWorkletNode)throw new Error("Microphone listening is unavailable in this browser or connection.");W=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1},video:!1}),C=new AudioContext,await C.audioWorklet.addModule(new URL("data:text/javascript;base64,Y2xhc3MgQnVyc3RMaXN0ZW5lclByb2Nlc3NvciBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICBzdXBlcigpOwogICAgICAgIHRoaXMuc2FtcGxlcyA9IG5ldyBGbG9hdDMyQXJyYXkoTWF0aC5jZWlsKHNhbXBsZVJhdGUgKiAxMCkpOwogICAgICAgIHRoaXMucG9zaXRpb24gPSAwOwogICAgICAgIHRoaXMuY291bnQgPSAwOwogICAgICAgIHRoaXMuaW50ZXJ2YWwgPSAwOwogICAgICAgIHRoaXMuZW5lcmd5ID0gMDsKICAgICAgICB0aGlzLnBlYWsgPSAwOwogICAgICAgIHRoaXMuYmFzZWxpbmUgPSAwLjAxOwogICAgICAgIHRoaXMubGFzdFRyaWdnZXIgPSAtc2FtcGxlUmF0ZSAqIDEwOwogIC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gICAgICAgICAgICAgdGhpcy5zZW5kQ2xpcChNYXRoLm1pbih0aGlzLmNvdW50LCBNYXRoLnJvdW5kKHNhbXBsZVJhdGUgKiAxMCkpKTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodGhpcy5pbnRlcnZhbCA+PSBNYXRoLnJvdW5kKHNhbXBsZVJhdGUgLyAzMCkpIHsKICAgICAgICAgICAgICAgIGNvbnN0IHJtcyA9IE1hdGguc3FydCh0aGlzLmVuZXJneSAvIHRoaXMuaW50ZXJ2YWwpOwogICAgICAgICAgICAgICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsgdHlwZTogImxldmVsIiwgdmFsdWU6IE1hdGgubWF4KHJtcywgdGhpcy5wZWFrICogMC41KSB9KTsKICAgICAgICAgICAgICAgIGlmICh0aGlzLm1vZGUgPT09ICJsaXN0ZW5pbmciICYmIHRoaXMuZnJhbWUgPiBzYW1wbGVSYXRlICYmIHRoaXMuZnJhbWUgLSB0aGlzLmxhc3RUcmlnZ2VyID4gc2FtcGxlUmF0ZSAqIDMKICAgICAgICAgICAgICAgICAgICAmJiBybXMgPiBNYXRoLm1heCgwLjA3NSwgdGhpcy5iYXNlbGluZSAqIDUpICYmIHRoaXMucGVhayA+IDAuMTYpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLm1vZGUgPSAidGFpbCI7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5wb3N0Um9sbCA9IE1hdGgucm91bmQoc2FtcGxlUmF0ZSAqIDIpOwogICAgICAgICAgICAgICAgICAgIHRoaXMubGFzdFRyaWdnZXIgPSB0aGlzLmZyYW1lOwogICAgICAgICAgICAgICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7IHR5cGU6ICJ0cmlnZ2VyIiB9KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5tb2RlID09PSAibGlzdGVuaW5nIikgewogICAgICAgICAgICAgICAgICAgIHRoaXMuYmFzZWxpbmUgPSB0aGlzLmJhc2VsaW5lICogMC45OCArIE1hdGgubWluKHJtcywgdGhpcy5iYXNlbGluZSAqIDIpICogMC4wMjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMuaW50ZXJ2YWwgPSAwOwogICAgICAgICAgICAgICAgdGhpcy5lbmVyZ3kgPSAwOwogICAgICAgICAgICAgICAgdGhpcy5wZWFrID0gMDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoImJ1cnN0LWxpc3RlbmVyIiwgQnVyc3RMaXN0ZW5lclByb2Nlc3Nvcik7Cg==",import.meta.url)),X=C.createMediaStreamSource(W),c=new AudioWorkletNode(C,"burst-listener"),R=C.createGain(),R.gain.value=0,c.port.onmessage=({data:l})=>{if(l.type==="level"&&(G==="listening"||G==="tail"))A[v]=l.value,v=(v+1)%A.length,le();else if(l.type==="trigger"&&G==="listening")q("tail");else if(l.type==="clip"){const h=new File([Be(l.samples,l.sampleRate)],He(),{type:"audio/wav"});M?(M(h),M=null):G==="tail"&&(ue(),j=h,E=URL.createObjectURL(h),N.src=E,N.hidden=!1,q("captured"))}},X.connect(c),c.connect(R).connect(C.destination),await C.resume(),A.fill(0),v=0,le(),q("listening")}catch(l){await $(),t&&(t.dataset.state="error"),n&&(n.dataset.state="error"),i&&(i.textContent=u.microphoneUnavailable||"Microphone unavailable"),ce.textContent=l.name==="NotAllowedError"?u.microphoneDenied||"Microphone permission was denied. Manual reporting is still available.":u.microphoneFailed||"Microphone capture failed.",ce.hidden=!1}finally{e.disabled=!1}}async function $(){M&&(M(null),M=null),ue(),c==null||c.disconnect(),X==null||X.disconnect(),R==null||R.disconnect(),W==null||W.getTracks().forEach(a=>a.stop()),await(C==null?void 0:C.close()),W=C=X=c=R=null,A.fill(0),v=0,q("off")}function de(){ue(),A.fill(0),v=0,le(),c==null||c.port.postMessage("reset"),c&&q("listening")}return e.addEventListener("click",ke),Le.addEventListener("click",$),fe.addEventListener("click",de),we.addEventListener("click",de),window.addEventListener("pagehide",$),document.addEventListener("visibilitychange",()=>{document.hidden&&$()}),{get active(){return G!=="off"},async clipForSubmission(){return j||(G==="off"||!c?null:new Promise(a=>{M=a,c.port.postMessage("snapshot")}))},submissionSucceeded:de}}const o=window.BOOMCAST_I18N||{},p=document.querySelector("#manual-report-form"),U=document.querySelector("#manual-submit"),K=document.querySelector("#manual-submit-label"),I=document.querySelector("#manual-occurrences"),Me=document.querySelector("#manual-decrease"),xe=document.querySelector("#manual-increase"),Fe=document.querySelector("#manual-latitude"),Ye=document.querySelector("#manual-longitude"),te=document.querySelector("#manual-direction-degrees"),ze=document.querySelector("#manual-direction-accuracy"),re=()=>document.querySelector("#manual-capture-direction"),d=()=>document.querySelector("#manual-direction-status"),s=()=>document.querySelector("#manual-direction-panel"),H=document.querySelector("#manual-compass"),ne=document.querySelector("#manual-compass-home"),Y=document.querySelector("#manual-compass-rose"),Ve=document.querySelector("#manual-compass-heading"),ee=document.querySelector("#manual-report-time"),Se=document.querySelector("#report-clock-hours"),ve=document.querySelector("#report-clock-minutes"),oe=document.querySelector("#manual-occurred-at"),Ze=document.querySelector("#report-clock-mode-label"),ge=document.querySelector("#report-clock-date"),Z=document.querySelector("#report-clock-edit"),V=document.querySelector("#report-clock-reset"),he=document.querySelector("#report-clock-editor"),L=document.querySelector("#report-clock-draft"),Ce=document.querySelector("#report-clock-apply"),Ie=document.querySelector("#report-clock-cancel"),O=document.querySelector("#report-clock-error"),b=document.querySelector("#manual-time-approximate");let g="NOW",T=null,J=!1;const Ge=document.querySelector("#manual-burst-status"),Re=document.querySelector("#manual-burst-duration");let B,ae,x=null;const z=qe(),me=e=>Number.isFinite(e),pe=e=>[o.north||"North",o.northeast||"Northeast",o.east||"East",o.southeast||"Southeast",o.south||"South",o.southwest||"Southwest",o.west||"West",o.northwest||"Northwest"][Math.floor((e+22.5)%360/45)],ie=e=>Number(e.toFixed(1)).toString(),se=()=>{var m,f;if(!ee)return;const e=g==="OVERRIDE"?T:new Date;ee.dateTime=e.toISOString();const t=new Intl.DateTimeFormat(document.documentElement.lang||void 0,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e),n=(m=t.find(k=>k.type==="hour"))==null?void 0:m.value,i=(f=t.find(k=>k.type==="minute"))==null?void 0:f.value;!n||!i||!Se||!ve||(Se.textContent=n,ve.textContent=i,ee.setAttribute("aria-label",`${n}:${i}`),ge&&(ge.hidden=g!=="OVERRIDE",g==="OVERRIDE"&&(ge.textContent=new Intl.DateTimeFormat(document.documentElement.lang||void 0,{day:"numeric",month:"long",year:"numeric"}).format(e))))};se();ee&&window.setInterval(se,6e4);const Ke=(K==null?void 0:K.textContent)||"I heard fireworks",be=e=>{const t=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}`},Ne=()=>{O&&(O.hidden=!0,O.textContent="",L.removeAttribute("aria-invalid"))},ye=()=>{he.hidden=!0,Z.setAttribute("aria-expanded","false"),Ne(),Z.focus()};Z==null||Z.addEventListener("click",()=>{L.value=be(g==="OVERRIDE"?T:new Date),b.checked=g==="OVERRIDE"&&J,b.disabled=!1,Ne(),he.hidden=!1,Z.setAttribute("aria-expanded","true"),L.focus()});Ie==null||Ie.addEventListener("click",()=>{b.checked=g==="OVERRIDE"&&J,b.disabled=g==="NOW",ye()});Ce==null||Ce.addEventListener("click",()=>{const e=L.value,t=e?new Date(e):null;if(!t||Number.isNaN(t.getTime())||be(t)!==e||t.getTime()>Date.now()+3e5){O.textContent=!e||!t||Number.isNaN(t.getTime())||be(t)!==e?o.invalidReportTime||"Enter a valid date and time.":o.futureReportTime||"Report time cannot be in the future.",O.hidden=!1,L.setAttribute("aria-invalid","true"),L.focus();return}T=t,J=b.checked,g="OVERRIDE",oe.value=t.toISOString(),Ze.textContent=o.adjusted||"Adjusted",V.hidden=!1,se(),ye()});V==null||V.addEventListener("click",()=>{g="NOW",T=null,J=!1,oe.value="",b.checked=!1,b.disabled=!0,Ze.textContent=o.now||"Now",V.hidden=!0,se(),he.hidden||ye(),Z.focus()});const w=(e,t="")=>{if(p.dataset.state=e,U.disabled=e==="submitting",K&&(K.textContent=e==="submitting"?o.sendingReport||"Sending…":Ke),t){const n=document.querySelector("#manual-submission");n.className="manual-report__submission",n.textContent=t}},We=e=>{const t=e==null?void 0:e.dataset.nextNoteToken,n=document.querySelector("#manual-note-context");!t||!n||n.value===t||(n.value=t,window.htmx&&htmx.ajax("GET","/fireworks/notes/?token="+encodeURIComponent(t),{target:"#live-field-notes",swap:"outerHTML"}))},Xe=(e,t)=>{const n=new DOMParser().parseFromString(e,"text/html").querySelector("#manual-submission");return n?(document.querySelector("#manual-submission").replaceWith(n),t&&We(n),w(t?"submitted":"error"),t):(w("error",o.reportFailed||"Could not send the report. Please try again."),!1)},De=()=>{const e=Number(I.value)>=3;Ge&&(Ge.textContent=e?o.burstEvent||"Burst Event":o.ordinaryReport||"Ordinary report"),Re&&(Re.hidden=!e)},Q=e=>{const t=Number.parseInt(e,10);I.value=String(Math.min(1e3,Math.max(1,Number.isFinite(t)?t:1))),Me.disabled=I.value==="1",xe.disabled=I.value==="1000",De()};Q(I.value);Me.addEventListener("click",()=>Q(Number(I.value)-1));xe.addEventListener("click",()=>Q(Number(I.value)+1));I.addEventListener("change",()=>Q(I.value));I.addEventListener("input",De);const P=()=>{B&&window.removeEventListener("deviceorientation",B),window.clearTimeout(ae),B=null,ae=null,H.hidden=!0,x=null},Oe=e=>{const t=-e;if(x===null)x=t,Y.style.transition="none",Y.style.transform=`rotate(${x}deg)`,Y.offsetWidth,Y.style.transition="";else{const n=(t-x+540)%360-180;x+=n,Y.style.transform=`rotate(${x}deg)`}Ve.textContent=`${ie(e)}° · ${pe(e)}`,H.setAttribute("aria-label",`${o.compassDirection||"Compass direction"} ${ie(e)}° ${pe(e)}`),H.hidden=!1},Ue=(e,t)=>{const n=d();if(n)if(n.classList.toggle("manual-direction-panel__status--accuracy",t!==null),t===null)n.textContent=o.accuracyUnavailable||"Accuracy unavailable";else{const m=document.createElement("span");m.textContent=o.accuracy||"Accuracy";const f=document.createElement("strong");f.textContent=`±${ie(t)}°`,n.replaceChildren(m,f)}const i=re();i&&(i.textContent=o.stopCapture||"Stop measuring direction")},Pe=()=>{d()&&(P(),s()&&(s().dataset.state="measuring"),d().textContent=o.pointPhone||"Point the top of your phone toward the sound — direction will update live.",B=e=>{const t="webkitCompassHeading"in e,n=me(e.webkitCompassHeading)?e.webkitCompassHeading:!t&&e.absolute&&me(e.alpha)?(360-e.alpha)%360:null;if(n===null||n<0||n>=360)return;const i=me(e.webkitCompassAccuracy)&&e.webkitCompassAccuracy>=0?e.webkitCompassAccuracy:null;te.value=n,ze.value=i===null?"":i,Ue(n,i),Oe(n),window.clearTimeout(ae)},window.addEventListener("deviceorientation",B),ae=window.setTimeout(()=>{P();const e=re(),t=d();e&&(e.textContent=o.captureDirection||"Start measuring direction"),t&&(t.textContent=o.compassUnavailable||"Compass unavailable on this device."),s()&&(s().dataset.state="unavailable")},15e3))},Te=async()=>{var e;if(B){P(),re().textContent=o.captureAgain||"Measure again",s()&&(s().dataset.state=te.value?"captured":"ready");return}if((e=d())==null||e.classList.remove("manual-direction-panel__status--accuracy"),!window.isSecureContext){d().textContent=o.secureCompass||"Compass capture requires a secure HTTPS connection.",s()&&(s().dataset.state="unavailable");return}if(typeof window.DeviceOrientationEvent>"u"){d().textContent=o.compassUnavailable||"Compass unavailable on this device.",s()&&(s().dataset.state="unavailable");return}if(typeof DeviceOrientationEvent.requestPermission=="function"){d().textContent=o.compassPermission||"Requesting compass permission…";try{if(await DeviceOrientationEvent.requestPermission(!0)!=="granted"){d()&&(d().textContent=o.compassDenied||"Compass permission denied."),s()&&(s().dataset.state="unavailable");return}}catch{d()&&(d().textContent=o.compassDenied||"Compass permission denied."),s()&&(s().dataset.state="unavailable");return}}Pe()},Ae=async()=>{if(oe&&(oe.value=g==="OVERRIDE"?T.toISOString():""),b&&(b.checked=g==="OVERRIDE"&&J,b.disabled=g==="NOW"),Q(I.value),P(),w("submitting",o.sendingReport||"Sending…"),z!=null&&z.active){try{const e=await z.clipForSubmission(),t=new FormData(p);e&&t.append("audio",e);const n=await fetch(p.action,{method:"POST",body:t,credentials:"same-origin"}),i=await n.text();Xe(i,n.ok)&&z.submissionSucceeded()}catch{w("error",o.reportFailed||"Could not send the report. Please try again.")}return}if(window.htmx)try{htmx.ajax("POST",p.action,{source:p,target:"#manual-submission",swap:"outerHTML"})}catch{w("error",o.reportFailed||"Could not send the report. Please try again.")}else p.submit()};p.addEventListener("click",e=>{e.target.closest("#manual-capture-direction")&&Te(),e.target.closest(".manual-direction-panel__close")&&(P(),ne&&ne.append(H))});document.body.addEventListener("htmx:beforeSwap",e=>{var t;((t=e.detail.target)==null?void 0:t.id)==="manual-direction-panel"&&ne&&ne.append(H)});document.body.addEventListener("htmx:afterSwap",e=>{var n,i;if(((n=e.detail.target)==null?void 0:n.id)!=="manual-direction-panel")return;re()&&((i=s().querySelector(".manual-direction-panel__copy"))==null||i.after(H));const t=document.querySelector("#manual-direction-summary");if(t&&te.value!==""){const m=Number(te.value);t.textContent=`${pe(m)} · ${ie(m)}°`,s().dataset.state="captured"}});U.addEventListener("click",()=>{if(!U.disabled){if(w("submitting",o.requestingLocation||"Requesting your optional location…"),!navigator.geolocation){Ae();return}navigator.geolocation.getCurrentPosition(e=>{Fe.value=e.coords.latitude,Ye.value=e.coords.longitude,Ae()},()=>Ae(),{enableHighAccuracy:!1,maximumAge:3e5,timeout:1e4})}});p.addEventListener("submit",e=>{e.preventDefault(),U.disabled||U.click()});document.body.addEventListener("htmx:afterRequest",e=>{if(e.detail.elt!==p)return;const t=e.detail.xhr;t?t.status>=400?Xe(t.responseText,!1):w("submitted"):w("error",o.reportFailed||"Could not send the report. Please try again.")});document.body.addEventListener("htmx:sendError",e=>{e.detail.elt===p&&w("error",o.reportFailed||"Could not send the report. Please try again.")});document.body.addEventListener("htmx:afterSwap",()=>We(document.querySelector("#manual-submission")));