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

2 lines
19 KiB
JavaScript

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