@rr0/ufoathome 0.175.0 → 0.176.0
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/dist-embed-interview/rr0-interview.mjs +9 -6
- package/dist-embed-scene/{BeamEditor-lqfhEk0b.js → BeamEditor-zq64GorX.js} +1 -1
- package/dist-embed-scene/{LanternEditor-B70H4IHX.js → LanternEditor-2q5seAWj.js} +1 -1
- package/dist-embed-scene/{LaunchEditor-DnOCC18Z.js → LaunchEditor-Cupksu8A.js} +1 -1
- package/dist-embed-scene/{ParameterForm-B4kpfmg7.js → ParameterForm-BMIW4Gkh.js} +5 -5
- package/dist-embed-scene/{ReentryEditor-CAoYGTuQ.js → ReentryEditor-DJO_M-8-.js} +1 -1
- package/{dist-embed-sighting/TimelineTracks-Cl54dXfV.js → dist-embed-scene/TimelineTracks-B-bXAaF7.js} +1 -1
- package/dist-embed-scene/rr0-scene.mjs +229 -203
- package/dist-embed-sighting/{AdsbLolArchiveProvider-CcD8HBKE.js → AdsbLolArchiveProvider-DK4qEYPv.js} +1 -1
- package/dist-embed-sighting/{BallesterGuaspAssessor-C3AZoSYJ.js → BallesterGuaspAssessor-FGskpWWG.js} +1 -1
- package/dist-embed-sighting/{BeamEditor-DhVematZ.js → BeamEditor-BglkfKa6.js} +1 -1
- package/dist-embed-sighting/{BeamSystem-B4to8Pi-.js → BeamSystem-DDtPjozC.js} +1 -1
- package/dist-embed-sighting/CaseMessages_en-DEyvxYxv.js +1 -0
- package/dist-embed-sighting/CaseMessages_es-DDsQ93tK.js +1 -0
- package/dist-embed-sighting/CaseMessages_fr-DoHbDEkG.js +1 -0
- package/dist-embed-sighting/CaseMessages_it-CF8sKknV.js +1 -0
- package/dist-embed-sighting/{ContrailSystem-DOuG7PiJ.js → ContrailSystem-DXV0DnrQ.js} +1 -1
- package/dist-embed-sighting/{Flightradar24Provider-Dpx8D7Mq.js → Flightradar24Provider-Ch4GdVJG.js} +1 -1
- package/dist-embed-sighting/GLTFLoader-BDyucwJ-.js +1 -0
- package/dist-embed-sighting/HeadlightSystem-DGUfgm2c.js +34 -0
- package/dist-embed-sighting/HynekAssessor-Cb8mZ9Ib.js +1 -0
- package/dist-embed-sighting/InterviewElement-Byb_sxbO.js +38 -0
- package/dist-embed-sighting/InterviewMessages_en-BNau2xU8.js +1 -0
- package/dist-embed-sighting/InterviewMessages_es-ypa0EDh9.js +1 -0
- package/dist-embed-sighting/InterviewMessages_fr-OCQdwn9j.js +1 -0
- package/dist-embed-sighting/InterviewMessages_it-awuOqf5v.js +1 -0
- package/dist-embed-sighting/{LanternEditor-DV_09Orv.js → LanternEditor-CaZ1JhZS.js} +1 -1
- package/dist-embed-sighting/{LaserBeam-DWr9CljY.js → LaserBeam-DkKFSSp_.js} +1 -1
- package/dist-embed-sighting/LaunchEditor-QRG2uHH8.js +22 -0
- package/dist-embed-sighting/LaunchPlume-DBINBQgQ.js +1 -0
- package/dist-embed-sighting/{LaunchSimulation-CUoqmEUv.js → LaunchSimulation-DUvH6_BB.js} +1 -1
- package/dist-embed-sighting/{ModuleSession-C0IGrROR.js → ModuleSession-GzfQ8_LE.js} +3 -3
- package/dist-embed-sighting/ModuleThree-tnKi-oul.js +1 -0
- package/dist-embed-sighting/{NearestApproach-Dm99M0L8.js → NearestApproach-BeKwz4vK.js} +1 -1
- package/dist-embed-sighting/{ParameterForm-DHI22UeD.js → ParameterForm-DW6cQmYI.js} +12 -15
- package/dist-embed-sighting/{PoherAssessor-BUqWHdc2.js → PoherAssessor-JLqDISRf.js} +1 -1
- package/dist-embed-sighting/{RailwaySystem-Bb0sdKJq.js → RailwaySystem-BfTJvmf3.js} +1 -1
- package/dist-embed-sighting/{ReentryEditor-MvS7QLW_.js → ReentryEditor-BHgPXlx3.js} +6 -6
- package/dist-embed-sighting/ReentrySimulation-C3BR2hs3.js +1 -0
- package/dist-embed-sighting/{ReferenceSystem-CK13CXoG.js → ReferenceSystem-B5diz1Lt.js} +1 -1
- package/dist-embed-sighting/{RoadMarkings-DiBAmqci.js → RoadMarkings-Dv3xdtFG.js} +1 -1
- package/dist-embed-sighting/{SceneNames_en-Cy3_acfm.js → SceneNames_en-BbQ55UYu.js} +1 -1
- package/dist-embed-sighting/{SceneNames_es-VxS6QttN.js → SceneNames_es-DsJpGSDK.js} +1 -1
- package/dist-embed-sighting/{SceneNames_fr-Dg8Zgkb7.js → SceneNames_fr-CKr5m8QL.js} +1 -1
- package/dist-embed-sighting/{SceneNames_it-Cf-I4HxZ.js → SceneNames_it-qSw1j95v.js} +1 -1
- package/dist-embed-sighting/{SightingMessages_en-BjIUyT4W.js → SightingMessages_en-DuokT218.js} +1 -1
- package/dist-embed-sighting/{SightingMessages_es-TueslN1u.js → SightingMessages_es-JO8WQ1_V.js} +1 -1
- package/dist-embed-sighting/{SightingMessages_fr-Dfp6mAcU.js → SightingMessages_fr-3C2RZVNA.js} +1 -1
- package/dist-embed-sighting/{SightingMessages_it-C0VvJY01.js → SightingMessages_it-BEMBUACg.js} +1 -1
- package/{dist-embed-scene/TimelineTracks-BMdiUSuh.js → dist-embed-sighting/TimelineTracks-XzShW15O.js} +2 -2
- package/dist-embed-sighting/{TraceSystem-Br5X73bm.js → TraceSystem-XybhI4uJ.js} +2 -2
- package/dist-embed-sighting/UfoMessages_en-CoSqGYwb.js +1 -0
- package/dist-embed-sighting/{WaterSystem-B1eVrX5D.js → WaterSystem-CcLIPQfy.js} +1 -1
- package/dist-embed-sighting/rr0-sighting.mjs +459 -337
- package/dist-embed-sighting/{trafficRuntime-eDpxCSB0.js → trafficRuntime-BAuwwA-Z.js} +1 -1
- package/dist-embed-sighting-editor/{InterviewEditorElement-HpLlL2F7.js → InterviewEditorElement-BesUoWBH.js} +15 -12
- package/dist-embed-sighting-editor/rr0-sighting-editor.mjs +128 -102
- package/package.json +1 -1
- package/dist-embed-sighting/GLTFLoader-BbUDci9q.js +0 -1
- package/dist-embed-sighting/HeadlightSystem-B2L7iVgs.js +0 -34
- package/dist-embed-sighting/HynekAssessor-BNn-J5RL.js +0 -1
- package/dist-embed-sighting/LaunchEditor-CB_nUoqA.js +0 -22
- package/dist-embed-sighting/LaunchPlume-C83k71p6.js +0 -1
- package/dist-embed-sighting/ModuleThree-CIiYBmMI.js +0 -1
- package/dist-embed-sighting/ReentrySimulation-DniDRt4s.js +0 -1
- package/dist-embed-sighting/UfoMessages_en-Bau9u8Mz.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as gt,L as At,T as W,R as L,a as F,M as Q,D as K,r as Et,l as Y,O as tt}from"./rr0-sighting.mjs";import{C as et}from"./ContrailGrowth-DwHS8If9.js";class A{static OCTAVES=[63,125,250,500,1e3,2e3,4e3,8e3];static STANDARD={temperatureC:15,relativeHumidity:.7,pressureKPa:101.325};static REFERENCE_PRESSURE_KPA=101.325;static REFERENCE_TEMPERATURE_K=293.15;static TRIPLE_POINT_K=273.16;static speedOfSound(t){return 20.0468*Math.sqrt(t+273.15)}static absorptionDbPerKm(t,e=A.STANDARD){const a=e.temperatureC+273.15,n=A.REFERENCE_TEMPERATURE_K,s=e.pressureKPa/A.REFERENCE_PRESSURE_KPA,c=10**(-6.8346*(A.TRIPLE_POINT_K/a)**1.261+4.6151),i=e.relativeHumidity*100*c/s,r=s*(24+40400*i*(.02+i)/(.391+i)),l=s*(a/n)**-.5*(9+280*i*Math.exp(-4.17*((a/n)**(-1/3)-1))),o=t*t;return 8.686*o*(184e-13*(1/s)*Math.sqrt(a/n)+(a/n)**-2.5*(.01275*Math.exp(-2239.1/a)/(r+o/r)+.1068*Math.exp(-3352/a)/(l+o/l)))*1e3}static aWeightingDb(t){const e=t*t,a=12194**2*e*e/((e+20.6**2)*Math.sqrt((e+107.7**2)*(e+737.9**2))*(e+12194**2));return 20*Math.log10(a)+2}static sumDb(t){return 10*Math.log10(t.reduce((e,a)=>e+10**(a/10),0))}}const Mt=.25,at=.4,nt=6,z=12,bt=3,st=.2,ft=.2,Dt=24,St=3,Rt=12,it=1,It=.7,Ot=1.5,Tt=.8,Bt=1.3,rt=.9,ot=5,_t=25,vt=.5,Nt=.12,ct=[.13,.31],Ct=.16,wt=1.6,yt=3.6,lt=1.1,kt=.3,Pt=1e3,ut=.7;class J{context;noiseBuffer;roughBuffers=new Map;voices=new Map;bus;reverb;reverbOut;level=1;master;paused=!0;requested=[];headingDeg=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("AircraftAudio: Web Audio unavailable, aircraft stay silent:",t);return}}gt.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t,e=0){this.requested=t,this.headingDeg=e,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);this.context?.close(),this.context=void 0,this.master=void 0,this.bus=void 0}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested,a=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])a.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n);this.retarget(t,s,n)}}build(t,e){const a=t.createGain();a.gain.value=0;let n;const s=this.busOf(t);typeof t.createStereoPanner=="function"?(n=t.createStereoPanner(),a.connect(n).connect(s)):a.connect(s);const c=t.createGain(),i=e.character?.modulationDepth??0;c.gain.value=1-i/2;const r=t.createOscillator();r.type="sine";const l=t.createGain();l.gain.value=i/2,r.connect(l).connect(c.gain),c.connect(a);const o=t.createBufferSource();o.buffer=this.noise(t),o.loop=!0,o.loopStart=Math.random()*nt*.5;const d=[],u=[],h=[];for(const T of A.OCTAVES){const B=t.createBiquadFilter();B.type="bandpass",B.frequency.value=T,B.Q.value=it;const N=t.createBiquadFilter();N.type="bandpass",N.frequency.value=T,N.Q.value=it;const P=t.createGain();P.gain.value=0,o.connect(B).connect(N).connect(P).connect(c),d.push(B),u.push(N),h.push(P)}const p=[];for(const[T,B]of[[e.character?.toneHz,e.character?.toneShare],[e.character?.humHz,e.character?.humShare]])if(T!==void 0)for(let N=1;N<=St;N++){const P=t.createOscillator();P.type="sine",P.frequency.value=T*N;const q=t.createGain();q.gain.value=0,P.connect(q).connect(a),p.push({oscillator:P,gain:q,harmonic:N,baseHz:T,share:B??0})}const m=t.createGain();m.gain.value=0,m.connect(a.gain);const M=ct.map(T=>{const B=t.createOscillator();return B.type="sine",B.frequency.value=T,B.connect(m),B}),f=t.createGain();f.gain.value=e.character?.roughness??st;const I=t.createBufferSource();I.buffer=this.roughTable(t,bt),I.loop=!0,I.loopStart=Math.random()*z*.5,I.connect(f).connect(c.gain);const S=t.createGain();S.gain.value=(e.character?.roughness??st)*ft;const b=t.createBufferSource();b.buffer=this.roughTable(t,Dt),b.loop=!0,b.loopStart=Math.random()*z*.5,b.connect(S).connect(c.gain);let _;const j=this.busOf(t)&&this.reverb;j&&(_=t.createGain(),_.gain.value=0,a.connect(_).connect(j));const $=[o,I,b,r,...p.map(T=>T.oscillator),...M];for(const T of $)T.start();const x={nodes:[a,c,l,f,S,m,...p.map(T=>T.gain),...d,...u,...h,..._?[_]:[],...n?[n]:[],...$],sources:$,filters:d,seconds:u,gains:h,tones:p,lfo:r,lfoDepth:l,wander:M,wanderDepth:m,roughDepth:f,crackleDepth:S,beat:c,output:a,panner:n,send:_};return this.voices.set(e.id,x),x}retarget(t,e,a){const n=t.currentTime,s=(p,m)=>p.setTargetAtTime(m,n,Mt),c=Math.min(Ot,Math.max(It,a.dopplerRatio)),i=Math.min(Bt,Math.max(Tt,Math.sqrt(a.dopplerRatio))),r=t.sampleRate*.45,l=a.bandAmplitudes.map((p,m)=>p*J.unweighting(A.OCTAVES[m])),o=Math.sqrt(l.reduce((p,m)=>p+m*m,0)),d=Math.min(1,Math.max(0,(a.distanceKm-ot)/(_t-ot)));A.OCTAVES.forEach((p,m)=>{s(e.filters[m].frequency,Math.min(r,p*i)),s(e.seconds[m].frequency,Math.min(r,p*i)),s(e.gains[m].gain,l[m]*Math.sqrt(Pt/p))});const u=a.character;for(const{oscillator:p,gain:m,harmonic:M,baseHz:f,share:I}of e.tones){const S=f*M;s(p.frequency,S*c);const b=S*c;s(m.gain,b<r?I*Ct*l[J.bandOf(b)]/M:0)}u?.modulationHz!==void 0&&s(e.lfo.frequency,u.modulationHz*c);const h=o>0?ut*(1-Math.exp(-o/ut))/o:1;if(s(e.output.gain,h*(1-kt*d)),s(e.wanderDepth.gain,h*Nt*d/ct.length),e.send&&s(e.send.gain,wt*d),e.panner){const p=(a.azimuthDeg-this.headingDeg)*Math.PI/180,m=a.inside?0:Math.max(-rt,Math.min(rt,Math.sin(p)))*(1-vt*d);s(e.panner.pan,m)}}static unweighting(t){return 10**(Math.min(Rt,Math.max(0,-A.aWeightingDb(t)))/20)}static bandOf(t){let e=0;return A.OCTAVES.forEach((a,n)=>{Math.abs(Math.log(t/a))<Math.abs(Math.log(t/A.OCTAVES[e]))&&(e=n)}),e}roughTable(t,e){const a=this.roughBuffers.get(e);if(a)return a;const n=Math.floor(t.sampleRate*z),s=t.createBuffer(1,n,t.sampleRate),c=s.getChannelData(0),i=Array.from({length:z*e},()=>(Math.random()*2-1)**3),r=t.sampleRate/e;for(let l=0;l<c.length;l++){const o=l/r,d=Math.floor(o),u=o-d,h=u*u*(3-2*u);c[l]=i[d%i.length]*(1-h)+i[(d+1)%i.length]*h}return this.roughBuffers.set(e,s),s}roomImpulse(t){const e=Math.floor(t.sampleRate*yt),a=t.createBuffer(2,e,t.sampleRate);for(let n=0;n<2;n++){const s=a.getChannelData(n);let c=0;for(let i=0;i<e;i++){const r=i/t.sampleRate,l=.6*Math.exp(-r/(lt*2))+.04;c+=l*(Math.random()*2-1-c),s[i]=c*Math.exp(-r/lt)}}return a}busOf(t){if(this.bus)return this.bus;const e=t.createGain();if(e.gain.value=this.level,e.connect(t.destination),this.master=e,typeof t.createConvolver=="function"){const a=t.createConvolver();a.buffer=this.roomImpulse(t);const n=t.createGain();n.gain.value=.9,a.connect(n),this.reverb=a,this.reverbOut=n}if(typeof t.createDynamicsCompressor=="function"){const a=t.createDynamicsCompressor();a.threshold.value=-6,a.knee.value=3,a.ratio.value=4,a.attack.value=.005,a.release.value=.25,a.connect(e),this.bus=a}else this.bus=e;return this.reverbOut?.connect(this.bus),this.bus}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const a=this.context;a&&(e.output.gain.setTargetAtTime(0,a.currentTime,at/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},at*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*nt,t.sampleRate),a=e.getChannelData(0);for(let n=0;n<a.length;n++)a[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class v{static BASE_DB_A=30;static WIND_DB_A=[[0,10],[1,28],[2,36],[3,40],[5,46],[8,52],[12,58],[20,66]];static RAIN_DB_A=[[0,0],[.1,42],[.3,50],[.6,58],[1,65]];static BED_RMS=.2;static MINIMUM_REFERENCE=.008;static WIND_BED_MIN_MS=1;static WIND_BED_FULL_MS=20;static dbA(t){const e=[v.BASE_DB_A,v.along(v.WIND_DB_A,t.windSpeed)];return(t.precipitationType==="rain"||t.precipitationType==="hail")&&e.push(v.along(v.RAIN_DB_A,t.precipitationIntensity)),10*Math.log10(e.filter(a=>a>0).reduce((a,n)=>a+10**(n/10),0))}static bedVolume(t){const e=t.windSpeed>v.WIND_BED_MIN_MS?Math.min(t.windSpeed/v.WIND_BED_FULL_MS,1):0,a=t.precipitationType==="hail"?Math.min(1,t.precipitationIntensity*1.3+.2):t.precipitationType==="rain"?t.precipitationIntensity:0;return Math.hypot(e,a)}static referenceAmplitude(t){return Math.max(v.BED_RMS*v.bedVolume(t),v.MINIMUM_REFERENCE)}static along(t,e){if(e<=t[0][0])return t[0][1];for(let a=1;a<t.length;a++)if(e<=t[a][0]){const[n,s]=t[a-1],[c,i]=t[a];return s+(i-s)*(e-n)/(c-n)}return t[t.length-1][1]}}class k{static TYPES={A318:["Airbus A318","airliner-narrow",34.1,31.4],A319:["Airbus A319","airliner-narrow",34.1,33.8],A320:["Airbus A320","airliner-narrow",34.1,37.6],A321:["Airbus A321","airliner-narrow",34.1,44.5],A19N:["Airbus A319neo","airliner-narrow",35.8,33.8],A20N:["Airbus A320neo","airliner-narrow",35.8,37.6],A21N:["Airbus A321neo","airliner-narrow",35.8,44.5],B737:["Boeing 737-700","airliner-narrow",34.3,33.6],B738:["Boeing 737-800","airliner-narrow",35.8,39.5],B739:["Boeing 737-900","airliner-narrow",35.8,42.1],B38M:["Boeing 737 MAX 8","airliner-narrow",35.9,39.5],B39M:["Boeing 737 MAX 9","airliner-narrow",35.9,42.2],B752:["Boeing 757-200","airliner-narrow",38,47.3],B753:["Boeing 757-300","airliner-narrow",38,54.4],B762:["Boeing 767-200","airliner-wide",47.6,48.5],B763:["Boeing 767-300","airliner-wide",47.6,54.9],B764:["Boeing 767-400","airliner-wide",51.9,61.4],B772:["Boeing 777-200","airliner-wide",60.9,63.7],B77L:["Boeing 777-200LR","airliner-wide",64.8,63.7],B77W:["Boeing 777-300ER","airliner-wide",64.8,73.9],B788:["Boeing 787-8","airliner-wide",60.1,56.7],B789:["Boeing 787-9","airliner-wide",60.1,62.8],B78X:["Boeing 787-10","airliner-wide",60.1,68.3],B744:["Boeing 747-400","airliner-wide",64.4,70.7],B748:["Boeing 747-8","airliner-wide",68.4,76.3],A306:["Airbus A300-600","airliner-wide",44.8,54.1],A310:["Airbus A310","airliner-wide",43.9,46.7],A332:["Airbus A330-200","airliner-wide",60.3,58.8],A333:["Airbus A330-300","airliner-wide",60.3,63.7],A338:["Airbus A330-800","airliner-wide",64,58.8],A339:["Airbus A330-900","airliner-wide",64,63.7],A343:["Airbus A340-300","airliner-wide",60.3,63.7],A346:["Airbus A340-600","airliner-wide",63.5,75.4],A359:["Airbus A350-900","airliner-wide",64.8,66.8],A35K:["Airbus A350-1000","airliner-wide",64.8,73.8],A388:["Airbus A380-800","airliner-wide",79.8,72.7],E170:["Embraer 170","regional-jet",26,29.9],E75L:["Embraer 175","regional-jet",26,31.7],E75S:["Embraer 175","regional-jet",26,31.7],E190:["Embraer 190","regional-jet",28.7,36.2],E195:["Embraer 195","regional-jet",28.7,38.7],E290:["Embraer 190-E2","regional-jet",33.7,36.2],E295:["Embraer 195-E2","regional-jet",33.7,41.5],CRJ2:["Bombardier CRJ200","regional-jet",21.2,26.8],CRJ7:["Bombardier CRJ700","regional-jet",23.2,32.3],CRJ9:["Bombardier CRJ900","regional-jet",24.9,36.2],CRJX:["Bombardier CRJ1000","regional-jet",26.2,39.1],AT72:["ATR 72","regional-turboprop",27.1,27.2],AT76:["ATR 72-600","regional-turboprop",27.1,27.2],AT45:["ATR 42","regional-turboprop",24.6,22.7],DH8D:["Dash 8 Q400","regional-turboprop",28.4,32.8],DH8C:["Dash 8-300","regional-turboprop",27.4,25.7],SF34:["Saab 340","regional-turboprop",21.4,19.7],B190:["Beechcraft 1900","regional-turboprop",17.7,17.6],C25A:["Cessna CitationJet CJ2","business-jet",14.3,14.4],C56X:["Cessna Citation Excel","business-jet",17.2,16],C68A:["Cessna Citation Latitude","business-jet",22,18.9],C550:["Cessna Citation II","business-jet",15.8,14.4],E55P:["Embraer Phenom 300","business-jet",15.9,15.6],E50P:["Embraer Phenom 100","business-jet",12.3,12.8],GLF5:["Gulfstream G550","business-jet",28.5,29.4],FA7X:["Dassault Falcon 7X","business-jet",26.2,23.4],CL60:["Bombardier Challenger 600","business-jet",19.6,20.9],LJ45:["Learjet 45","business-jet",14.6,17.7],H25B:["Hawker 800","business-jet",15.7,15.6],C172:["Cessna 172","light-piston",11,8.3],C152:["Cessna 152","light-piston",10.2,7.3],C182:["Cessna 182","light-piston",10.9,8.8],P28A:["Piper Cherokee","light-piston",10.7,7.2],PA34:["Piper Seneca","light-piston",11.8,8.7],SR20:["Cirrus SR20","light-piston",10.9,7.9],SR22:["Cirrus SR22","light-piston",11.7,7.9],S22T:["Cirrus SR22T","light-piston",11.7,7.9],DA40:["Diamond DA40","light-piston",11.6,8.1],DA42:["Diamond DA42","light-piston",13.4,8.6],BE20:["Beechcraft King Air 200","turboprop-light",16.6,13.3],BE58:["Beechcraft Baron","light-piston",11.5,9.1],C208:["Cessna Caravan","turboprop-light",15.9,11.5],PC12:["Pilatus PC-12","turboprop-light",16.3,14.4],TBM9:["Daher TBM 900","turboprop-light",12.8,10.7],EC35:["Airbus H135","helicopter-light",10.2,12.1],EC45:["Airbus H145","helicopter-medium",11,13.6],AS50:["Airbus H125","helicopter-light",10.7,12.9],EC30:["Airbus H130","helicopter-light",10.7,12.6],B407:["Bell 407","helicopter-light",10.7,12.7],B06:["Bell 206","helicopter-light",10.2,12],B429:["Bell 429","helicopter-medium",10.9,13],B505:["Bell 505","helicopter-light",10.4,11.9],R44:["Robinson R44","helicopter-light",10.1,11.7],R22:["Robinson R22","helicopter-light",7.7,8.8],A109:["Agusta A109","helicopter-medium",11,13],A139:["Leonardo AW139","helicopter-medium",13.8,16.7],S92:["Sikorsky S-92","helicopter-heavy",17.2,20.9],H60:["Sikorsky UH-60 Black Hawk","helicopter-heavy",16.4,19.8],T38:["Northrop T-38 Talon","military-jet",7.7,14.1],HAWK:["BAE Hawk","military-jet",9.4,11.9],GLID:["Glider","glider",17,7],BALL:["Balloon","balloon",15,20],ULAC:["Ultralight","ultralight",9.5,6],C42:["Ikarus C42","ultralight",9.4,6.3],DRON:["Drone","unmanned",1,.6]};static CATEGORIES={A1:["Light aircraft","light-piston",11,8.3],A2:["Small aircraft","business-jet",15,15],A3:["Large aircraft","airliner-narrow",34.1,37.6],A4:["High-vortex large aircraft","airliner-narrow",38,47.3],A5:["Heavy aircraft","airliner-wide",60.3,63.7],A6:["High-performance aircraft","military-jet",8,14],A7:["Rotorcraft","helicopter-medium",10.7,12.7],B1:["Glider","glider",17,7],B2:["Lighter-than-air","balloon",15,20],B4:["Ultralight","ultralight",9.5,6],B6:["Unmanned aircraft","unmanned",1.5,1]};static GENERIC={name:"Airliner",kind:"airliner-narrow",spanM:34.1,lengthM:37.6,basis:"nothing"};static of(t){const e=t?.type?.toUpperCase(),a=e?k.TYPES[e]:void 0;if(a)return{code:e,name:a[0],kind:a[1],spanM:a[2],lengthM:a[3],basis:"type"};const n=t?.category?k.CATEGORIES[t.category]:void 0;return n?{name:n[0],kind:n[1],spanM:n[2],lengthM:n[3],basis:"category"}:{...k.GENERIC}}static isHelicopter(t){return t.kind.startsWith("helicopter")}}class O{static DUSK_SUN_ELEVATION_DEG=-.83;static ALWAYS=new Set(["airliner-narrow","airliner-wide","regional-turboprop","regional-jet","business-jet"]);static NONE=new Set(["glider","balloon"]);static BRIGHTNESS={"light-piston":[.5,.2,.5],"turboprop-light":[.7,.4,.8],ultralight:[.4,.2,.4],unmanned:[0,.05,0],"helicopter-light":[1,1,1],"helicopter-medium":[1,1,1],"helicopter-heavy":[1,1,1],"military-jet":[1,1,1]};static LANDING_LIGHTS_BELOW_FT=1e4;static LANDING_INTENSITY=600;static LANDING_BEAM_DEG=10;static LANDING_COLOR="#fff1dc";static LANDING_BRIGHTNESS={"airliner-narrow":1,"airliner-wide":1,"regional-jet":.6,"regional-turboprop":.6,"business-jet":.4,"turboprop-light":.2,"light-piston":.1,ultralight:.05,"helicopter-light":.1,"helicopter-medium":.2,"helicopter-heavy":.2};static lampsOn(t,e){if(O.NONE.has(t))return{navigation:!1,beacon:!1,strobes:!1};if(O.ALWAYS.has(t))return{navigation:!0,beacon:!0,strobes:!0};const a=e<O.DUSK_SUN_ELEVATION_DEG;return t==="unmanned"?{navigation:!1,beacon:!1,strobes:a}:{navigation:a,beacon:a,strobes:a}}static lights(t,e){const a=O.lampsOn(t.kind,e),n=t.kind.startsWith("helicopter"),s=At.find(h=>h.id===(n?"helicopter":"airliner")).create(),[c,i]=n?[5,7]:[17,18],r=t.spanM/2/c,l=t.lengthM/2/i,[o,d,u]=O.BRIGHTNESS[t.kind]??[1,1,1];return s.filter(h=>h.id.startsWith("nav")?a.navigation:h.id.startsWith("strobe")?a.strobes:h.id.startsWith("beacon")?a.beacon:!0).filter(h=>!(h.id.startsWith("beacon")&&!a.beacon)).map(h=>{const p=h.id.startsWith("nav")?o:h.id.startsWith("strobe")?d:u;return{...h,offsetM:{x:h.offsetM.x*r,y:h.offsetM.y,z:h.offsetM.z*l},intensity:(h.intensity??1)*p}}).filter(h=>(h.intensity??1)>0)}static landingLights(t,e,a){const n=O.LANDING_BRIGHTNESS[t.kind]??0;if(n===0||!O.lampsOn(t.kind,e).navigation)return[];const s=o=>o<O.LANDING_LIGHTS_BELOW_FT;if(!a.some(o=>s(o.altitudeFt)))return[];const c=O.LANDING_INTENSITY*n,i=a.flatMap((o,d)=>d>0&&s(o.altitudeFt)!==s(a[d-1].altitudeFt)?[{t:o.t,intensity:s(o.altitudeFt)?c:0}]:[]),r=t.spanM/34,l=t.lengthM/36;return[-1,1].map(o=>({id:o<0?"landing-left":"landing-right",offsetM:{x:o*5*r,y:-1,z:3*l},color:O.LANDING_COLOR,intensity:s(a[0].altitudeFt)?c:0,pattern:{kind:"steady"},beamDeg:O.LANDING_BEAM_DEG,keyframes:i}))}static bodyColor(t){return t.kind==="military-jet"?"#8a8e94":t.kind.startsWith("helicopter")?"#c8ccd1":t.kind==="unmanned"?"#2c2e33":"#dde0e4"}}class U{static FAMILIES={"amvlab-a320":["A318","A319","A320","A321","A19N","A20N","A21N"],"amvlab-b737":["B732","B733","B734","B735","B736","B737","B738","B739","B37M","B38M","B39M","B3XM"],"amvlab-a350":["A359","A35K"],"amvlab-a380":["A388"],"amvlab-b787":["B788","B789","B78X"]};static BY_TYPE=new Map(Object.entries(U.FAMILIES).flatMap(([t,e])=>e.map(a=>[a,t])));static idOf(t){return t?U.BY_TYPE.get(t.toUpperCase()):void 0}}class R{static ID_PREFIX=W.ID_PREFIX;static MAX_OBJECTS=40;static FT_TO_M=.3048;static DEG=Math.PI/180;static from(t,e,a,n=R.MAX_OBJECTS,s={}){return new Ht(t,e,a,n,s).build()}static idOf(t,e){return W.idOf(t,e)}static keyOf(t){return W.keyOf(t)}static HEIGHT_OVER_LENGTH=.29;static sizeOf(t){return{widthM:t.spanM,lengthM:t.lengthM,heightM:t.lengthM*R.HEIGHT_OVER_LENGTH}}static offsetOf(t,e){const a=L.seenFrom(t,{lat:e.lat,lng:e.lng,heightM:e.altitudeFt*R.FT_TO_M}),n=a.distanceKm*1e3,s=n*Math.cos(a.altitudeDeg*R.DEG);return{eastM:s*Math.sin(a.azimuthDeg*R.DEG),northM:s*Math.cos(a.azimuthDeg*R.DEG),upM:n*Math.sin(a.altitudeDeg*R.DEG),altitudeDeg:a.altitudeDeg,distanceKm:a.distanceKm}}static segments(t){const e=[];let a=[];for(const n of t.points){const s=a[a.length-1];s&&n.t-s.t>F.MAX_GAP_S*1e3&&(e.push(a),a=[]),a.push(n)}return e.push(a),e.filter(n=>n.length>=2)}static bearingDeg(t,e){return(Math.atan2(e.eastM-t.eastM,e.northM-t.northM)/R.DEG+360)%360}}class Ht{constructor(t,e,a,n,s){this.tracks=t,this.observer=e,this.startMs=a,this.maxObjects=n,this.options=s}build(){const t=[];for(const a of this.tracks){const n=R.keyOf(a),s=this.options.models?.get(n)??k.of(void 0);R.segments(a).forEach((c,i)=>{const r=c.map(h=>({point:h,at:R.offsetOf(this.observer,h)}));if(!r.some(h=>h.at.altitudeDeg>=0))return;const l=r.map((h,p)=>({t:h.point.t-this.startMs,eastM:h.at.eastM,northM:h.at.northM,altitudeM:h.at.upM,headingDeg:h.point.trackDeg??(p+1<r.length?R.bearingDeg(h.at,r[p+1].at):R.bearingDeg(r[p-1].at,h.at))})),o=R.idOf(a,i),d=r[Math.floor(r.length/2)].point,u=this.options.sunElevationAt?.(d)??90;t.push({object:{id:o,kind:"aircraft",eastM:l[0].eastM,northM:l[0].northM,headingDeg:l[0].headingDeg,sizeM:R.sizeOf(s),model:U.idOf(s.code)?{id:U.idOf(s.code)}:void 0,color:O.bodyColor(s),lights:[...O.lights(s,u),...O.landingLights(s,u,c.map(h=>({t:h.t-this.startMs,altitudeFt:h.altitudeFt})))],track:l},presence:{fromMs:l[0].t,untilMs:l[l.length-1].t},flight:{icao:a.icao,nonIcao:a.nonIcao,points:c},closestKm:Math.min(...r.map(h=>h.at.distanceKm))})})}t.sort((a,n)=>a.closestKm-n.closestKm);const e=t.slice(0,this.maxObjects);return{objects:e.map(a=>a.object),presence:new Map(e.map(a=>[a.object.id,a.presence])),flights:new Map(e.map(a=>[a.object.id,a.flight])),total:t.length,shown:e.length}}}const mt=[{id:"turbofan-narrow-body",name:"Turbofan airliner, narrow-body",kinds:["airliner-narrow"],totalDbA:148,shapeDb:[-32,-17,-9,-6,-5,-7,-12,-22],character:{toneHz:1800,toneShare:.3,humHz:90,humShare:.7}},{id:"turbofan-wide-body",name:"Turbofan airliner, wide-body",kinds:["airliner-wide"],totalDbA:151,shapeDb:[-28,-14,-7,-4,-3,-6,-12,-22],character:{toneHz:1200,toneShare:.3,humHz:70,humShare:.7}},{id:"regional-jet",name:"Regional jet",kinds:["regional-jet"],totalDbA:144,shapeDb:[-32,-17,-9,-5,-4,-6,-11,-21],character:{toneHz:1900,toneShare:.3,humHz:95,humShare:.7}},{id:"business-jet",name:"Business jet",kinds:["business-jet"],totalDbA:141,shapeDb:[-30,-15,-8,-4,-3,-4,-9,-19],character:{toneHz:2500,toneShare:.25,humHz:110,humShare:.7}},{id:"turboprop",name:"Turboprop",kinds:["regional-turboprop","turboprop-light"],totalDbA:138,shapeDb:[-14,-9,-8,-6,-8,-13,-20,-28],character:{toneHz:80,toneShare:.5}},{id:"light-piston",name:"Light piston aircraft",kinds:["light-piston"],totalDbA:130,shapeDb:[-18,-9,-5,-4,-8,-14,-22,-30],character:{toneHz:80,toneShare:.4}},{id:"ultralight",name:"Ultralight",kinds:["ultralight"],totalDbA:124,shapeDb:[-16,-8,-5,-4,-9,-15,-23,-31],character:{toneHz:140,toneShare:.4}},{id:"helicopter-light",name:"Light helicopter",kinds:["helicopter-light"],totalDbA:134,shapeDb:[-15,-8,-4,-3,-6,-10,-16,-24],character:{modulationHz:20,modulationDepth:.5}},{id:"helicopter-medium",name:"Medium helicopter",kinds:["helicopter-medium"],totalDbA:138,shapeDb:[-14,-7,-4,-3,-6,-10,-16,-24],character:{modulationHz:22,modulationDepth:.5}},{id:"helicopter-heavy",name:"Heavy helicopter",kinds:["helicopter-heavy"],totalDbA:144,shapeDb:[-12,-6,-4,-4,-7,-11,-17,-25],character:{modulationHz:17,modulationDepth:.5}},{id:"military-jet",name:"Military jet",kinds:["military-jet"],totalDbA:152,shapeDb:[-26,-12,-6,-3,-2,-3,-7,-15]},{id:"glider",name:"Glider",kinds:["glider"],totalDbA:85,shapeDb:[-30,-22,-15,-10,-8,-8,-14,-22]},{id:"balloon",name:"Hot-air balloon",kinds:["balloon"],totalDbA:100,shapeDb:[-25,-15,-9,-5,-3,-6,-12,-20]},{id:"unmanned",name:"Unmanned aircraft",kinds:["unmanned"],totalDbA:88,shapeDb:[-40,-30,-20,-12,-6,-3,-3,-8],character:{toneHz:450,toneShare:1}}],ht=mt.map(w=>({id:w.id,name:w.name,soundPowerA:w.shapeDb.map(t=>t+w.totalDbA-A.sumDb(w.shapeDb)),character:w.character}));class g{static DEFAULT_AMBIENT_DB_A=35;static DETECTION_MARGIN_DB=3;static AMBIENT_SHAPE_DB=[-12,-7,-5,-5,-7,-11,-17,-25];static HEARING_FLOOR_DB_A=0;static ITERATIONS=30;static CONVERGED_MS=.5;static VELOCITY_STEP_MS=500;static noiseOfKind(t){const e=mt.find(a=>a.kinds.includes(t));return ht.find(a=>a.id===(e?.id??"turbofan-narrow-body"))}static bandsAt(t,e,a=A.STANDARD){const n=20*Math.log10(Math.max(e*1e3,1))+11;return A.OCTAVES.map((s,c)=>t.soundPowerA[c]-n-A.absorptionDbPerKm(s,a)*e)}static couldBeHeard(t,e,a=g.DEFAULT_AMBIENT_DB_A,n=A.STANDARD){const s=g.ambientBands(a);return g.bandsAt(t,e,n).some((c,i)=>c>=Math.max(s[i]+g.DETECTION_MARGIN_DB,g.HEARING_FLOOR_DB_A))}static ambientBands(t){const e=g.AMBIENT_SHAPE_DB,a=A.sumDb(e);return e.map(n=>t+n-a)}static heardAt(t,e,a,n={}){const s=n.air??A.STANDARD,c=A.speedOfSound(s.temperatureC),i=t.points[t.points.length-1]?.t;if(i===void 0)return;let r=Math.min(a,i),l=F.positionAt(t,r);if(!l)return;let o=L.seenFrom(e,l.geo);for(let b=0;b<g.ITERATIONS;b++){const _=a-o.distanceKm*1e3*1e3/c,j=Math.abs(_-r);if(r=_,l=F.positionAt(t,r),!l)return;if(o=L.seenFrom(e,l.geo),j<g.CONVERGED_MS)break}const d=F.positionAt(t,a),u=d?L.seenFrom(e,d.geo):o,h=n.noise??ht[0],p=n.ambientDbA??g.DEFAULT_AMBIENT_DB_A,m=g.ambientBands(p),M=g.bandsAt(h,o.distanceKm,s),f=M.map((b,_)=>b>=Math.max(m[_]+g.DETECTION_MARGIN_DB,g.HEARING_FLOOR_DB_A)),I=M.indexOf(Math.max(...M)),S=f.lastIndexOf(!0);return{track:t,audible:f.some(Boolean),levelDbA:A.sumDb(M),bandsDbA:M,ambientDbA:p,delayS:(a-r)/1e3,emittedAtMs:r,sound:o,seen:u,lagDeg:g.angleBetween(o,u),dopplerRatio:g.doppler(t,e,r,c),dominantHz:A.OCTAVES[I],cutoffHz:S<0?void 0:A.OCTAVES[S]}}static profile(t,e,a,n,s=2e3,c={}){const i=[];let r,l,o=a;for(let d=a;d<=n;d+=s){const u=g.heardAt(t,e,d,c);u&&(!l||u.levelDbA>l.levelDbA)&&(l=u,o=d),u?.audible?r?r.untilMs=d:i.push(r={fromMs:d,untilMs:d}):r=void 0}return{track:t,audible:i,peakDbA:l?.levelDbA??-1/0,peakAtMs:o,peakDelayS:l?.delayS??0}}static angleBetween(t,e){const a=o=>{const d=o.altitudeDeg*Math.PI/180,u=o.azimuthDeg*Math.PI/180;return[Math.cos(d)*Math.sin(u),Math.cos(d)*Math.cos(u),Math.sin(d)]},[n,s,c]=a(t),[i,r,l]=a(e);return Math.acos(Math.min(1,Math.max(-1,n*i+s*r+c*l)))*180/Math.PI}static doppler(t,e,a,n){const s=g.VELOCITY_STEP_MS,c=F.positionAt(t,a-s),i=F.positionAt(t,a+s);if(!c||!i)return 1;const r=L.seenFrom(e,c.geo).distanceKm*1e3,l=L.seenFrom(e,i.geo).distanceKm*1e3;return 1/(1-(r-l)/(2*s/1e3)/n)}}class Kt{static at(t,e,a,n,s={}){const c=F.seenFrom(t,a,n);if(!c)return;const i=k.of(e),r=g.heardAt(t,a,n,{noise:g.noiseOfKind(i.kind),...s});return{hex:`${t.nonIcao?"~":""}${t.icao.toString(16).padStart(6,"0")}`,registration:e?.registration,typeCode:i.code??e?.type,name:i.basis==="nothing"?void 0:i.name,kind:i.kind,basis:i.basis,military:e?.military===!0,restricted:e?.restricted===!0,altitudeFt:c.altitudeFt,groundSpeedKt:c.groundSpeedKt,trackDeg:c.trackDeg,sky:c.sky,angularRateDegPerS:c.angularRateDegPerS,hearing:r&&{audible:r.audible,levelDbA:r.levelDbA,ambientDbA:r.ambientDbA,delayS:r.delayS,lagDeg:r.lagDeg,dopplerRatio:r.dopplerRatio,cutoffHz:r.cutoffHz,dominantHz:r.dominantHz}}}}class D{static REFERENCE_AMPLITUDE=.02;static MASKING_RANGE_DB=6;static KNEE_DB=20;static COMPRESSION_RATIO=1.5;static EXPANSION_RATIO=1.8;static DEFAULT_MAX_VOICES=4;static candidates(t,e,a,n,s={}){const c=new Set;for(const[i,r]of t){const l=g.noiseOfKind(k.of(e.get(a(r))).kind);let o=1/0;for(const d of r.points)o=Math.min(o,L.seenFrom(n,{lat:d.lat,lng:d.lng,heightM:d.altitudeFt*.3048}).distanceKm);g.couldBeHeard(l,o,s.ambientDbA,s.air)&&c.add(i)}return c}static voices(t,e,a,n,s,c,i={}){const r=[];for(const l of t){const o=e.get(l);if(!o||i.only?.(l)===!1)continue;const d=i.kindOf?.(l)??k.of(a.get(n(o))).kind,u=i.noiseOf?.(l)??g.noiseOfKind(d),h=g.heardAt(o,s,c,{...i,noise:u});if(!h?.audible)continue;const p=i.throughDb,m=p?h.bandsDbA.map((M,f)=>M-(p[f]??0)):h.bandsDbA;p&&!D.noticed(m,h.ambientDbA)||r.push({id:l,kind:d,bandAmplitudes:D.bandAmplitudes(m,h.ambientDbA,i.referenceAmplitude),levelDbA:p?A.sumDb(m):h.levelDbA,distanceKm:h.sound.distanceKm,dopplerRatio:h.dopplerRatio,azimuthDeg:h.sound.azimuthDeg,elevationDeg:h.sound.altitudeDeg,character:u.character})}return r.sort((l,o)=>o.levelDbA-l.levelDbA).slice(0,i.maxVoices??D.DEFAULT_MAX_VOICES)}static noticed(t,e){const a=g.ambientBands(e);return t.some((n,s)=>n>=a[s]+g.DETECTION_MARGIN_DB)}static bandAmplitudes(t,e,a=D.REFERENCE_AMPLITUDE){const n=g.ambientBands(e),s=g.DETECTION_MARGIN_DB,c=A.sumDb(t),i=c-e,r=i>=D.KNEE_DB?D.KNEE_DB+(i-D.KNEE_DB)/D.COMPRESSION_RATIO:D.KNEE_DB-(D.KNEE_DB-i)*D.EXPANSION_RATIO,l=a*10**(r/20);return t.map((o,d)=>{const u=Math.min(1,Math.max(0,(o-n[d]-s+D.MASKING_RANGE_DB)/(2*D.MASKING_RANGE_DB)));return u*u*(3-2*u)*l*10**((o-c)/20)})}static BANDS_HZ=A.OCTAVES}class V{static RUMBLE_BELOW_HZ=500;static DULL_BELOW_HZ=2e3;static PITCH_NOTICED=.03;static text(t,e,a,n){const s=(u,h=0)=>u.toLocaleString(n,{maximumFractionDigits:h}),c=(u,h)=>u.replace(/\{(\w+)\}/g,(p,m)=>h[m]??`{${m}}`),i=[],r=[t.registration,t.name].filter(Boolean).join(" · ");i.push(r||c(e.unnamed,{hex:t.hex}));const l=[c(e.altitude,{value:s(Math.round(t.altitudeFt/100)*100)}),t.groundSpeedKt===void 0?void 0:c(e.speed,{value:s(Math.round(t.groundSpeedKt))}),t.trackDeg===void 0?void 0:c(e.heading,{value:s(Math.round(t.trackDeg))})].filter(Boolean);i.push(l.join(" · ")),i.push(c(e.position,{distance:s(t.sky.distanceKm,t.sky.distanceKm<10?1:0),elevation:s(Math.round(t.sky.altitudeDeg)),bearing:a(t.sky.azimuthDeg)}));const o=t.hearing;if(!o)i.push(e.soundUnknown);else if(!o.audible)i.push(c(e.inaudible,{level:s(Math.round(o.levelDbA)),ambient:s(Math.round(o.ambientDbA))}));else{const u=o.cutoffHz??0,h=u<=V.RUMBLE_BELOW_HZ?e.rumble:u<=V.DULL_BELOW_HZ?e.muffled:e.broad,p=o.dopplerRatio-1,m=Math.abs(p)<V.PITCH_NOTICED?"":c(p>0?e.pitchHigher:e.pitchLower,{percent:s(Math.round(Math.abs(p)*100))});i.push(c(e.heard,{level:s(Math.round(o.levelDbA)),delay:s(Math.round(o.delayS)),lag:s(Math.round(o.lagDeg)),character:c(h,{cutoff:s(u)}),pitch:m}))}t.contrail&&i.push(c(t.contrail.persistent?e.contrailPersistent:e.contrailShort,{rhi:s(Math.round(t.contrail.iceRelativeHumidity*100))}));const d=[t.military?e.military:void 0,t.restricted?e.restricted:void 0].filter(Boolean);return d.length>0&&i.push(d.join(" · ")),i.push(e.candidate),i.join(`
|
|
1
|
+
import{A as gt,L as At,T as W,R as L,c as F,M as Q,D as K,r as Et,l as Y,O as tt}from"./rr0-sighting.mjs";import{C as et}from"./ContrailGrowth-DwHS8If9.js";class A{static OCTAVES=[63,125,250,500,1e3,2e3,4e3,8e3];static STANDARD={temperatureC:15,relativeHumidity:.7,pressureKPa:101.325};static REFERENCE_PRESSURE_KPA=101.325;static REFERENCE_TEMPERATURE_K=293.15;static TRIPLE_POINT_K=273.16;static speedOfSound(t){return 20.0468*Math.sqrt(t+273.15)}static absorptionDbPerKm(t,e=A.STANDARD){const a=e.temperatureC+273.15,n=A.REFERENCE_TEMPERATURE_K,s=e.pressureKPa/A.REFERENCE_PRESSURE_KPA,c=10**(-6.8346*(A.TRIPLE_POINT_K/a)**1.261+4.6151),i=e.relativeHumidity*100*c/s,r=s*(24+40400*i*(.02+i)/(.391+i)),l=s*(a/n)**-.5*(9+280*i*Math.exp(-4.17*((a/n)**(-1/3)-1))),o=t*t;return 8.686*o*(184e-13*(1/s)*Math.sqrt(a/n)+(a/n)**-2.5*(.01275*Math.exp(-2239.1/a)/(r+o/r)+.1068*Math.exp(-3352/a)/(l+o/l)))*1e3}static aWeightingDb(t){const e=t*t,a=12194**2*e*e/((e+20.6**2)*Math.sqrt((e+107.7**2)*(e+737.9**2))*(e+12194**2));return 20*Math.log10(a)+2}static sumDb(t){return 10*Math.log10(t.reduce((e,a)=>e+10**(a/10),0))}}const Mt=.25,at=.4,nt=6,z=12,bt=3,st=.2,ft=.2,Dt=24,St=3,Rt=12,it=1,It=.7,Ot=1.5,Tt=.8,Bt=1.3,rt=.9,ot=5,_t=25,vt=.5,Nt=.12,ct=[.13,.31],Ct=.16,wt=1.6,yt=3.6,lt=1.1,kt=.3,Pt=1e3,ut=.7;class J{context;noiseBuffer;roughBuffers=new Map;voices=new Map;bus;reverb;reverbOut;level=1;master;paused=!0;requested=[];headingDeg=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("AircraftAudio: Web Audio unavailable, aircraft stay silent:",t);return}}gt.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t,e=0){this.requested=t,this.headingDeg=e,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);this.context?.close(),this.context=void 0,this.master=void 0,this.bus=void 0}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested,a=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])a.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n);this.retarget(t,s,n)}}build(t,e){const a=t.createGain();a.gain.value=0;let n;const s=this.busOf(t);typeof t.createStereoPanner=="function"?(n=t.createStereoPanner(),a.connect(n).connect(s)):a.connect(s);const c=t.createGain(),i=e.character?.modulationDepth??0;c.gain.value=1-i/2;const r=t.createOscillator();r.type="sine";const l=t.createGain();l.gain.value=i/2,r.connect(l).connect(c.gain),c.connect(a);const o=t.createBufferSource();o.buffer=this.noise(t),o.loop=!0,o.loopStart=Math.random()*nt*.5;const d=[],u=[],h=[];for(const T of A.OCTAVES){const B=t.createBiquadFilter();B.type="bandpass",B.frequency.value=T,B.Q.value=it;const N=t.createBiquadFilter();N.type="bandpass",N.frequency.value=T,N.Q.value=it;const P=t.createGain();P.gain.value=0,o.connect(B).connect(N).connect(P).connect(c),d.push(B),u.push(N),h.push(P)}const p=[];for(const[T,B]of[[e.character?.toneHz,e.character?.toneShare],[e.character?.humHz,e.character?.humShare]])if(T!==void 0)for(let N=1;N<=St;N++){const P=t.createOscillator();P.type="sine",P.frequency.value=T*N;const q=t.createGain();q.gain.value=0,P.connect(q).connect(a),p.push({oscillator:P,gain:q,harmonic:N,baseHz:T,share:B??0})}const m=t.createGain();m.gain.value=0,m.connect(a.gain);const M=ct.map(T=>{const B=t.createOscillator();return B.type="sine",B.frequency.value=T,B.connect(m),B}),f=t.createGain();f.gain.value=e.character?.roughness??st;const I=t.createBufferSource();I.buffer=this.roughTable(t,bt),I.loop=!0,I.loopStart=Math.random()*z*.5,I.connect(f).connect(c.gain);const S=t.createGain();S.gain.value=(e.character?.roughness??st)*ft;const b=t.createBufferSource();b.buffer=this.roughTable(t,Dt),b.loop=!0,b.loopStart=Math.random()*z*.5,b.connect(S).connect(c.gain);let _;const j=this.busOf(t)&&this.reverb;j&&(_=t.createGain(),_.gain.value=0,a.connect(_).connect(j));const $=[o,I,b,r,...p.map(T=>T.oscillator),...M];for(const T of $)T.start();const x={nodes:[a,c,l,f,S,m,...p.map(T=>T.gain),...d,...u,...h,..._?[_]:[],...n?[n]:[],...$],sources:$,filters:d,seconds:u,gains:h,tones:p,lfo:r,lfoDepth:l,wander:M,wanderDepth:m,roughDepth:f,crackleDepth:S,beat:c,output:a,panner:n,send:_};return this.voices.set(e.id,x),x}retarget(t,e,a){const n=t.currentTime,s=(p,m)=>p.setTargetAtTime(m,n,Mt),c=Math.min(Ot,Math.max(It,a.dopplerRatio)),i=Math.min(Bt,Math.max(Tt,Math.sqrt(a.dopplerRatio))),r=t.sampleRate*.45,l=a.bandAmplitudes.map((p,m)=>p*J.unweighting(A.OCTAVES[m])),o=Math.sqrt(l.reduce((p,m)=>p+m*m,0)),d=Math.min(1,Math.max(0,(a.distanceKm-ot)/(_t-ot)));A.OCTAVES.forEach((p,m)=>{s(e.filters[m].frequency,Math.min(r,p*i)),s(e.seconds[m].frequency,Math.min(r,p*i)),s(e.gains[m].gain,l[m]*Math.sqrt(Pt/p))});const u=a.character;for(const{oscillator:p,gain:m,harmonic:M,baseHz:f,share:I}of e.tones){const S=f*M;s(p.frequency,S*c);const b=S*c;s(m.gain,b<r?I*Ct*l[J.bandOf(b)]/M:0)}u?.modulationHz!==void 0&&s(e.lfo.frequency,u.modulationHz*c);const h=o>0?ut*(1-Math.exp(-o/ut))/o:1;if(s(e.output.gain,h*(1-kt*d)),s(e.wanderDepth.gain,h*Nt*d/ct.length),e.send&&s(e.send.gain,wt*d),e.panner){const p=(a.azimuthDeg-this.headingDeg)*Math.PI/180,m=a.inside?0:Math.max(-rt,Math.min(rt,Math.sin(p)))*(1-vt*d);s(e.panner.pan,m)}}static unweighting(t){return 10**(Math.min(Rt,Math.max(0,-A.aWeightingDb(t)))/20)}static bandOf(t){let e=0;return A.OCTAVES.forEach((a,n)=>{Math.abs(Math.log(t/a))<Math.abs(Math.log(t/A.OCTAVES[e]))&&(e=n)}),e}roughTable(t,e){const a=this.roughBuffers.get(e);if(a)return a;const n=Math.floor(t.sampleRate*z),s=t.createBuffer(1,n,t.sampleRate),c=s.getChannelData(0),i=Array.from({length:z*e},()=>(Math.random()*2-1)**3),r=t.sampleRate/e;for(let l=0;l<c.length;l++){const o=l/r,d=Math.floor(o),u=o-d,h=u*u*(3-2*u);c[l]=i[d%i.length]*(1-h)+i[(d+1)%i.length]*h}return this.roughBuffers.set(e,s),s}roomImpulse(t){const e=Math.floor(t.sampleRate*yt),a=t.createBuffer(2,e,t.sampleRate);for(let n=0;n<2;n++){const s=a.getChannelData(n);let c=0;for(let i=0;i<e;i++){const r=i/t.sampleRate,l=.6*Math.exp(-r/(lt*2))+.04;c+=l*(Math.random()*2-1-c),s[i]=c*Math.exp(-r/lt)}}return a}busOf(t){if(this.bus)return this.bus;const e=t.createGain();if(e.gain.value=this.level,e.connect(t.destination),this.master=e,typeof t.createConvolver=="function"){const a=t.createConvolver();a.buffer=this.roomImpulse(t);const n=t.createGain();n.gain.value=.9,a.connect(n),this.reverb=a,this.reverbOut=n}if(typeof t.createDynamicsCompressor=="function"){const a=t.createDynamicsCompressor();a.threshold.value=-6,a.knee.value=3,a.ratio.value=4,a.attack.value=.005,a.release.value=.25,a.connect(e),this.bus=a}else this.bus=e;return this.reverbOut?.connect(this.bus),this.bus}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const a=this.context;a&&(e.output.gain.setTargetAtTime(0,a.currentTime,at/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},at*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*nt,t.sampleRate),a=e.getChannelData(0);for(let n=0;n<a.length;n++)a[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class v{static BASE_DB_A=30;static WIND_DB_A=[[0,10],[1,28],[2,36],[3,40],[5,46],[8,52],[12,58],[20,66]];static RAIN_DB_A=[[0,0],[.1,42],[.3,50],[.6,58],[1,65]];static BED_RMS=.2;static MINIMUM_REFERENCE=.008;static WIND_BED_MIN_MS=1;static WIND_BED_FULL_MS=20;static dbA(t){const e=[v.BASE_DB_A,v.along(v.WIND_DB_A,t.windSpeed)];return(t.precipitationType==="rain"||t.precipitationType==="hail")&&e.push(v.along(v.RAIN_DB_A,t.precipitationIntensity)),10*Math.log10(e.filter(a=>a>0).reduce((a,n)=>a+10**(n/10),0))}static bedVolume(t){const e=t.windSpeed>v.WIND_BED_MIN_MS?Math.min(t.windSpeed/v.WIND_BED_FULL_MS,1):0,a=t.precipitationType==="hail"?Math.min(1,t.precipitationIntensity*1.3+.2):t.precipitationType==="rain"?t.precipitationIntensity:0;return Math.hypot(e,a)}static referenceAmplitude(t){return Math.max(v.BED_RMS*v.bedVolume(t),v.MINIMUM_REFERENCE)}static along(t,e){if(e<=t[0][0])return t[0][1];for(let a=1;a<t.length;a++)if(e<=t[a][0]){const[n,s]=t[a-1],[c,i]=t[a];return s+(i-s)*(e-n)/(c-n)}return t[t.length-1][1]}}class k{static TYPES={A318:["Airbus A318","airliner-narrow",34.1,31.4],A319:["Airbus A319","airliner-narrow",34.1,33.8],A320:["Airbus A320","airliner-narrow",34.1,37.6],A321:["Airbus A321","airliner-narrow",34.1,44.5],A19N:["Airbus A319neo","airliner-narrow",35.8,33.8],A20N:["Airbus A320neo","airliner-narrow",35.8,37.6],A21N:["Airbus A321neo","airliner-narrow",35.8,44.5],B737:["Boeing 737-700","airliner-narrow",34.3,33.6],B738:["Boeing 737-800","airliner-narrow",35.8,39.5],B739:["Boeing 737-900","airliner-narrow",35.8,42.1],B38M:["Boeing 737 MAX 8","airliner-narrow",35.9,39.5],B39M:["Boeing 737 MAX 9","airliner-narrow",35.9,42.2],B752:["Boeing 757-200","airliner-narrow",38,47.3],B753:["Boeing 757-300","airliner-narrow",38,54.4],B762:["Boeing 767-200","airliner-wide",47.6,48.5],B763:["Boeing 767-300","airliner-wide",47.6,54.9],B764:["Boeing 767-400","airliner-wide",51.9,61.4],B772:["Boeing 777-200","airliner-wide",60.9,63.7],B77L:["Boeing 777-200LR","airliner-wide",64.8,63.7],B77W:["Boeing 777-300ER","airliner-wide",64.8,73.9],B788:["Boeing 787-8","airliner-wide",60.1,56.7],B789:["Boeing 787-9","airliner-wide",60.1,62.8],B78X:["Boeing 787-10","airliner-wide",60.1,68.3],B744:["Boeing 747-400","airliner-wide",64.4,70.7],B748:["Boeing 747-8","airliner-wide",68.4,76.3],A306:["Airbus A300-600","airliner-wide",44.8,54.1],A310:["Airbus A310","airliner-wide",43.9,46.7],A332:["Airbus A330-200","airliner-wide",60.3,58.8],A333:["Airbus A330-300","airliner-wide",60.3,63.7],A338:["Airbus A330-800","airliner-wide",64,58.8],A339:["Airbus A330-900","airliner-wide",64,63.7],A343:["Airbus A340-300","airliner-wide",60.3,63.7],A346:["Airbus A340-600","airliner-wide",63.5,75.4],A359:["Airbus A350-900","airliner-wide",64.8,66.8],A35K:["Airbus A350-1000","airliner-wide",64.8,73.8],A388:["Airbus A380-800","airliner-wide",79.8,72.7],E170:["Embraer 170","regional-jet",26,29.9],E75L:["Embraer 175","regional-jet",26,31.7],E75S:["Embraer 175","regional-jet",26,31.7],E190:["Embraer 190","regional-jet",28.7,36.2],E195:["Embraer 195","regional-jet",28.7,38.7],E290:["Embraer 190-E2","regional-jet",33.7,36.2],E295:["Embraer 195-E2","regional-jet",33.7,41.5],CRJ2:["Bombardier CRJ200","regional-jet",21.2,26.8],CRJ7:["Bombardier CRJ700","regional-jet",23.2,32.3],CRJ9:["Bombardier CRJ900","regional-jet",24.9,36.2],CRJX:["Bombardier CRJ1000","regional-jet",26.2,39.1],AT72:["ATR 72","regional-turboprop",27.1,27.2],AT76:["ATR 72-600","regional-turboprop",27.1,27.2],AT45:["ATR 42","regional-turboprop",24.6,22.7],DH8D:["Dash 8 Q400","regional-turboprop",28.4,32.8],DH8C:["Dash 8-300","regional-turboprop",27.4,25.7],SF34:["Saab 340","regional-turboprop",21.4,19.7],B190:["Beechcraft 1900","regional-turboprop",17.7,17.6],C25A:["Cessna CitationJet CJ2","business-jet",14.3,14.4],C56X:["Cessna Citation Excel","business-jet",17.2,16],C68A:["Cessna Citation Latitude","business-jet",22,18.9],C550:["Cessna Citation II","business-jet",15.8,14.4],E55P:["Embraer Phenom 300","business-jet",15.9,15.6],E50P:["Embraer Phenom 100","business-jet",12.3,12.8],GLF5:["Gulfstream G550","business-jet",28.5,29.4],FA7X:["Dassault Falcon 7X","business-jet",26.2,23.4],CL60:["Bombardier Challenger 600","business-jet",19.6,20.9],LJ45:["Learjet 45","business-jet",14.6,17.7],H25B:["Hawker 800","business-jet",15.7,15.6],C172:["Cessna 172","light-piston",11,8.3],C152:["Cessna 152","light-piston",10.2,7.3],C182:["Cessna 182","light-piston",10.9,8.8],P28A:["Piper Cherokee","light-piston",10.7,7.2],PA34:["Piper Seneca","light-piston",11.8,8.7],SR20:["Cirrus SR20","light-piston",10.9,7.9],SR22:["Cirrus SR22","light-piston",11.7,7.9],S22T:["Cirrus SR22T","light-piston",11.7,7.9],DA40:["Diamond DA40","light-piston",11.6,8.1],DA42:["Diamond DA42","light-piston",13.4,8.6],BE20:["Beechcraft King Air 200","turboprop-light",16.6,13.3],BE58:["Beechcraft Baron","light-piston",11.5,9.1],C208:["Cessna Caravan","turboprop-light",15.9,11.5],PC12:["Pilatus PC-12","turboprop-light",16.3,14.4],TBM9:["Daher TBM 900","turboprop-light",12.8,10.7],EC35:["Airbus H135","helicopter-light",10.2,12.1],EC45:["Airbus H145","helicopter-medium",11,13.6],AS50:["Airbus H125","helicopter-light",10.7,12.9],EC30:["Airbus H130","helicopter-light",10.7,12.6],B407:["Bell 407","helicopter-light",10.7,12.7],B06:["Bell 206","helicopter-light",10.2,12],B429:["Bell 429","helicopter-medium",10.9,13],B505:["Bell 505","helicopter-light",10.4,11.9],R44:["Robinson R44","helicopter-light",10.1,11.7],R22:["Robinson R22","helicopter-light",7.7,8.8],A109:["Agusta A109","helicopter-medium",11,13],A139:["Leonardo AW139","helicopter-medium",13.8,16.7],S92:["Sikorsky S-92","helicopter-heavy",17.2,20.9],H60:["Sikorsky UH-60 Black Hawk","helicopter-heavy",16.4,19.8],T38:["Northrop T-38 Talon","military-jet",7.7,14.1],HAWK:["BAE Hawk","military-jet",9.4,11.9],GLID:["Glider","glider",17,7],BALL:["Balloon","balloon",15,20],ULAC:["Ultralight","ultralight",9.5,6],C42:["Ikarus C42","ultralight",9.4,6.3],DRON:["Drone","unmanned",1,.6]};static CATEGORIES={A1:["Light aircraft","light-piston",11,8.3],A2:["Small aircraft","business-jet",15,15],A3:["Large aircraft","airliner-narrow",34.1,37.6],A4:["High-vortex large aircraft","airliner-narrow",38,47.3],A5:["Heavy aircraft","airliner-wide",60.3,63.7],A6:["High-performance aircraft","military-jet",8,14],A7:["Rotorcraft","helicopter-medium",10.7,12.7],B1:["Glider","glider",17,7],B2:["Lighter-than-air","balloon",15,20],B4:["Ultralight","ultralight",9.5,6],B6:["Unmanned aircraft","unmanned",1.5,1]};static GENERIC={name:"Airliner",kind:"airliner-narrow",spanM:34.1,lengthM:37.6,basis:"nothing"};static of(t){const e=t?.type?.toUpperCase(),a=e?k.TYPES[e]:void 0;if(a)return{code:e,name:a[0],kind:a[1],spanM:a[2],lengthM:a[3],basis:"type"};const n=t?.category?k.CATEGORIES[t.category]:void 0;return n?{name:n[0],kind:n[1],spanM:n[2],lengthM:n[3],basis:"category"}:{...k.GENERIC}}static isHelicopter(t){return t.kind.startsWith("helicopter")}}class O{static DUSK_SUN_ELEVATION_DEG=-.83;static ALWAYS=new Set(["airliner-narrow","airliner-wide","regional-turboprop","regional-jet","business-jet"]);static NONE=new Set(["glider","balloon"]);static BRIGHTNESS={"light-piston":[.5,.2,.5],"turboprop-light":[.7,.4,.8],ultralight:[.4,.2,.4],unmanned:[0,.05,0],"helicopter-light":[1,1,1],"helicopter-medium":[1,1,1],"helicopter-heavy":[1,1,1],"military-jet":[1,1,1]};static LANDING_LIGHTS_BELOW_FT=1e4;static LANDING_INTENSITY=600;static LANDING_BEAM_DEG=10;static LANDING_COLOR="#fff1dc";static LANDING_BRIGHTNESS={"airliner-narrow":1,"airliner-wide":1,"regional-jet":.6,"regional-turboprop":.6,"business-jet":.4,"turboprop-light":.2,"light-piston":.1,ultralight:.05,"helicopter-light":.1,"helicopter-medium":.2,"helicopter-heavy":.2};static lampsOn(t,e){if(O.NONE.has(t))return{navigation:!1,beacon:!1,strobes:!1};if(O.ALWAYS.has(t))return{navigation:!0,beacon:!0,strobes:!0};const a=e<O.DUSK_SUN_ELEVATION_DEG;return t==="unmanned"?{navigation:!1,beacon:!1,strobes:a}:{navigation:a,beacon:a,strobes:a}}static lights(t,e){const a=O.lampsOn(t.kind,e),n=t.kind.startsWith("helicopter"),s=At.find(h=>h.id===(n?"helicopter":"airliner")).create(),[c,i]=n?[5,7]:[17,18],r=t.spanM/2/c,l=t.lengthM/2/i,[o,d,u]=O.BRIGHTNESS[t.kind]??[1,1,1];return s.filter(h=>h.id.startsWith("nav")?a.navigation:h.id.startsWith("strobe")?a.strobes:h.id.startsWith("beacon")?a.beacon:!0).filter(h=>!(h.id.startsWith("beacon")&&!a.beacon)).map(h=>{const p=h.id.startsWith("nav")?o:h.id.startsWith("strobe")?d:u;return{...h,offsetM:{x:h.offsetM.x*r,y:h.offsetM.y,z:h.offsetM.z*l},intensity:(h.intensity??1)*p}}).filter(h=>(h.intensity??1)>0)}static landingLights(t,e,a){const n=O.LANDING_BRIGHTNESS[t.kind]??0;if(n===0||!O.lampsOn(t.kind,e).navigation)return[];const s=o=>o<O.LANDING_LIGHTS_BELOW_FT;if(!a.some(o=>s(o.altitudeFt)))return[];const c=O.LANDING_INTENSITY*n,i=a.flatMap((o,d)=>d>0&&s(o.altitudeFt)!==s(a[d-1].altitudeFt)?[{t:o.t,intensity:s(o.altitudeFt)?c:0}]:[]),r=t.spanM/34,l=t.lengthM/36;return[-1,1].map(o=>({id:o<0?"landing-left":"landing-right",offsetM:{x:o*5*r,y:-1,z:3*l},color:O.LANDING_COLOR,intensity:s(a[0].altitudeFt)?c:0,pattern:{kind:"steady"},beamDeg:O.LANDING_BEAM_DEG,keyframes:i}))}static bodyColor(t){return t.kind==="military-jet"?"#8a8e94":t.kind.startsWith("helicopter")?"#c8ccd1":t.kind==="unmanned"?"#2c2e33":"#dde0e4"}}class U{static FAMILIES={"amvlab-a320":["A318","A319","A320","A321","A19N","A20N","A21N"],"amvlab-b737":["B732","B733","B734","B735","B736","B737","B738","B739","B37M","B38M","B39M","B3XM"],"amvlab-a350":["A359","A35K"],"amvlab-a380":["A388"],"amvlab-b787":["B788","B789","B78X"]};static BY_TYPE=new Map(Object.entries(U.FAMILIES).flatMap(([t,e])=>e.map(a=>[a,t])));static idOf(t){return t?U.BY_TYPE.get(t.toUpperCase()):void 0}}class R{static ID_PREFIX=W.ID_PREFIX;static MAX_OBJECTS=40;static FT_TO_M=.3048;static DEG=Math.PI/180;static from(t,e,a,n=R.MAX_OBJECTS,s={}){return new Ht(t,e,a,n,s).build()}static idOf(t,e){return W.idOf(t,e)}static keyOf(t){return W.keyOf(t)}static HEIGHT_OVER_LENGTH=.29;static sizeOf(t){return{widthM:t.spanM,lengthM:t.lengthM,heightM:t.lengthM*R.HEIGHT_OVER_LENGTH}}static offsetOf(t,e){const a=L.seenFrom(t,{lat:e.lat,lng:e.lng,heightM:e.altitudeFt*R.FT_TO_M}),n=a.distanceKm*1e3,s=n*Math.cos(a.altitudeDeg*R.DEG);return{eastM:s*Math.sin(a.azimuthDeg*R.DEG),northM:s*Math.cos(a.azimuthDeg*R.DEG),upM:n*Math.sin(a.altitudeDeg*R.DEG),altitudeDeg:a.altitudeDeg,distanceKm:a.distanceKm}}static segments(t){const e=[];let a=[];for(const n of t.points){const s=a[a.length-1];s&&n.t-s.t>F.MAX_GAP_S*1e3&&(e.push(a),a=[]),a.push(n)}return e.push(a),e.filter(n=>n.length>=2)}static bearingDeg(t,e){return(Math.atan2(e.eastM-t.eastM,e.northM-t.northM)/R.DEG+360)%360}}class Ht{constructor(t,e,a,n,s){this.tracks=t,this.observer=e,this.startMs=a,this.maxObjects=n,this.options=s}build(){const t=[];for(const a of this.tracks){const n=R.keyOf(a),s=this.options.models?.get(n)??k.of(void 0);R.segments(a).forEach((c,i)=>{const r=c.map(h=>({point:h,at:R.offsetOf(this.observer,h)}));if(!r.some(h=>h.at.altitudeDeg>=0))return;const l=r.map((h,p)=>({t:h.point.t-this.startMs,eastM:h.at.eastM,northM:h.at.northM,altitudeM:h.at.upM,headingDeg:h.point.trackDeg??(p+1<r.length?R.bearingDeg(h.at,r[p+1].at):R.bearingDeg(r[p-1].at,h.at))})),o=R.idOf(a,i),d=r[Math.floor(r.length/2)].point,u=this.options.sunElevationAt?.(d)??90;t.push({object:{id:o,kind:"aircraft",eastM:l[0].eastM,northM:l[0].northM,headingDeg:l[0].headingDeg,sizeM:R.sizeOf(s),model:U.idOf(s.code)?{id:U.idOf(s.code)}:void 0,color:O.bodyColor(s),lights:[...O.lights(s,u),...O.landingLights(s,u,c.map(h=>({t:h.t-this.startMs,altitudeFt:h.altitudeFt})))],track:l},presence:{fromMs:l[0].t,untilMs:l[l.length-1].t},flight:{icao:a.icao,nonIcao:a.nonIcao,points:c},closestKm:Math.min(...r.map(h=>h.at.distanceKm))})})}t.sort((a,n)=>a.closestKm-n.closestKm);const e=t.slice(0,this.maxObjects);return{objects:e.map(a=>a.object),presence:new Map(e.map(a=>[a.object.id,a.presence])),flights:new Map(e.map(a=>[a.object.id,a.flight])),total:t.length,shown:e.length}}}const mt=[{id:"turbofan-narrow-body",name:"Turbofan airliner, narrow-body",kinds:["airliner-narrow"],totalDbA:148,shapeDb:[-32,-17,-9,-6,-5,-7,-12,-22],character:{toneHz:1800,toneShare:.3,humHz:90,humShare:.7}},{id:"turbofan-wide-body",name:"Turbofan airliner, wide-body",kinds:["airliner-wide"],totalDbA:151,shapeDb:[-28,-14,-7,-4,-3,-6,-12,-22],character:{toneHz:1200,toneShare:.3,humHz:70,humShare:.7}},{id:"regional-jet",name:"Regional jet",kinds:["regional-jet"],totalDbA:144,shapeDb:[-32,-17,-9,-5,-4,-6,-11,-21],character:{toneHz:1900,toneShare:.3,humHz:95,humShare:.7}},{id:"business-jet",name:"Business jet",kinds:["business-jet"],totalDbA:141,shapeDb:[-30,-15,-8,-4,-3,-4,-9,-19],character:{toneHz:2500,toneShare:.25,humHz:110,humShare:.7}},{id:"turboprop",name:"Turboprop",kinds:["regional-turboprop","turboprop-light"],totalDbA:138,shapeDb:[-14,-9,-8,-6,-8,-13,-20,-28],character:{toneHz:80,toneShare:.5}},{id:"light-piston",name:"Light piston aircraft",kinds:["light-piston"],totalDbA:130,shapeDb:[-18,-9,-5,-4,-8,-14,-22,-30],character:{toneHz:80,toneShare:.4}},{id:"ultralight",name:"Ultralight",kinds:["ultralight"],totalDbA:124,shapeDb:[-16,-8,-5,-4,-9,-15,-23,-31],character:{toneHz:140,toneShare:.4}},{id:"helicopter-light",name:"Light helicopter",kinds:["helicopter-light"],totalDbA:134,shapeDb:[-15,-8,-4,-3,-6,-10,-16,-24],character:{modulationHz:20,modulationDepth:.5}},{id:"helicopter-medium",name:"Medium helicopter",kinds:["helicopter-medium"],totalDbA:138,shapeDb:[-14,-7,-4,-3,-6,-10,-16,-24],character:{modulationHz:22,modulationDepth:.5}},{id:"helicopter-heavy",name:"Heavy helicopter",kinds:["helicopter-heavy"],totalDbA:144,shapeDb:[-12,-6,-4,-4,-7,-11,-17,-25],character:{modulationHz:17,modulationDepth:.5}},{id:"military-jet",name:"Military jet",kinds:["military-jet"],totalDbA:152,shapeDb:[-26,-12,-6,-3,-2,-3,-7,-15]},{id:"glider",name:"Glider",kinds:["glider"],totalDbA:85,shapeDb:[-30,-22,-15,-10,-8,-8,-14,-22]},{id:"balloon",name:"Hot-air balloon",kinds:["balloon"],totalDbA:100,shapeDb:[-25,-15,-9,-5,-3,-6,-12,-20]},{id:"unmanned",name:"Unmanned aircraft",kinds:["unmanned"],totalDbA:88,shapeDb:[-40,-30,-20,-12,-6,-3,-3,-8],character:{toneHz:450,toneShare:1}}],ht=mt.map(w=>({id:w.id,name:w.name,soundPowerA:w.shapeDb.map(t=>t+w.totalDbA-A.sumDb(w.shapeDb)),character:w.character}));class g{static DEFAULT_AMBIENT_DB_A=35;static DETECTION_MARGIN_DB=3;static AMBIENT_SHAPE_DB=[-12,-7,-5,-5,-7,-11,-17,-25];static HEARING_FLOOR_DB_A=0;static ITERATIONS=30;static CONVERGED_MS=.5;static VELOCITY_STEP_MS=500;static noiseOfKind(t){const e=mt.find(a=>a.kinds.includes(t));return ht.find(a=>a.id===(e?.id??"turbofan-narrow-body"))}static bandsAt(t,e,a=A.STANDARD){const n=20*Math.log10(Math.max(e*1e3,1))+11;return A.OCTAVES.map((s,c)=>t.soundPowerA[c]-n-A.absorptionDbPerKm(s,a)*e)}static couldBeHeard(t,e,a=g.DEFAULT_AMBIENT_DB_A,n=A.STANDARD){const s=g.ambientBands(a);return g.bandsAt(t,e,n).some((c,i)=>c>=Math.max(s[i]+g.DETECTION_MARGIN_DB,g.HEARING_FLOOR_DB_A))}static ambientBands(t){const e=g.AMBIENT_SHAPE_DB,a=A.sumDb(e);return e.map(n=>t+n-a)}static heardAt(t,e,a,n={}){const s=n.air??A.STANDARD,c=A.speedOfSound(s.temperatureC),i=t.points[t.points.length-1]?.t;if(i===void 0)return;let r=Math.min(a,i),l=F.positionAt(t,r);if(!l)return;let o=L.seenFrom(e,l.geo);for(let b=0;b<g.ITERATIONS;b++){const _=a-o.distanceKm*1e3*1e3/c,j=Math.abs(_-r);if(r=_,l=F.positionAt(t,r),!l)return;if(o=L.seenFrom(e,l.geo),j<g.CONVERGED_MS)break}const d=F.positionAt(t,a),u=d?L.seenFrom(e,d.geo):o,h=n.noise??ht[0],p=n.ambientDbA??g.DEFAULT_AMBIENT_DB_A,m=g.ambientBands(p),M=g.bandsAt(h,o.distanceKm,s),f=M.map((b,_)=>b>=Math.max(m[_]+g.DETECTION_MARGIN_DB,g.HEARING_FLOOR_DB_A)),I=M.indexOf(Math.max(...M)),S=f.lastIndexOf(!0);return{track:t,audible:f.some(Boolean),levelDbA:A.sumDb(M),bandsDbA:M,ambientDbA:p,delayS:(a-r)/1e3,emittedAtMs:r,sound:o,seen:u,lagDeg:g.angleBetween(o,u),dopplerRatio:g.doppler(t,e,r,c),dominantHz:A.OCTAVES[I],cutoffHz:S<0?void 0:A.OCTAVES[S]}}static profile(t,e,a,n,s=2e3,c={}){const i=[];let r,l,o=a;for(let d=a;d<=n;d+=s){const u=g.heardAt(t,e,d,c);u&&(!l||u.levelDbA>l.levelDbA)&&(l=u,o=d),u?.audible?r?r.untilMs=d:i.push(r={fromMs:d,untilMs:d}):r=void 0}return{track:t,audible:i,peakDbA:l?.levelDbA??-1/0,peakAtMs:o,peakDelayS:l?.delayS??0}}static angleBetween(t,e){const a=o=>{const d=o.altitudeDeg*Math.PI/180,u=o.azimuthDeg*Math.PI/180;return[Math.cos(d)*Math.sin(u),Math.cos(d)*Math.cos(u),Math.sin(d)]},[n,s,c]=a(t),[i,r,l]=a(e);return Math.acos(Math.min(1,Math.max(-1,n*i+s*r+c*l)))*180/Math.PI}static doppler(t,e,a,n){const s=g.VELOCITY_STEP_MS,c=F.positionAt(t,a-s),i=F.positionAt(t,a+s);if(!c||!i)return 1;const r=L.seenFrom(e,c.geo).distanceKm*1e3,l=L.seenFrom(e,i.geo).distanceKm*1e3;return 1/(1-(r-l)/(2*s/1e3)/n)}}class Kt{static at(t,e,a,n,s={}){const c=F.seenFrom(t,a,n);if(!c)return;const i=k.of(e),r=g.heardAt(t,a,n,{noise:g.noiseOfKind(i.kind),...s});return{hex:`${t.nonIcao?"~":""}${t.icao.toString(16).padStart(6,"0")}`,registration:e?.registration,typeCode:i.code??e?.type,name:i.basis==="nothing"?void 0:i.name,kind:i.kind,basis:i.basis,military:e?.military===!0,restricted:e?.restricted===!0,altitudeFt:c.altitudeFt,groundSpeedKt:c.groundSpeedKt,trackDeg:c.trackDeg,sky:c.sky,angularRateDegPerS:c.angularRateDegPerS,hearing:r&&{audible:r.audible,levelDbA:r.levelDbA,ambientDbA:r.ambientDbA,delayS:r.delayS,lagDeg:r.lagDeg,dopplerRatio:r.dopplerRatio,cutoffHz:r.cutoffHz,dominantHz:r.dominantHz}}}}class D{static REFERENCE_AMPLITUDE=.02;static MASKING_RANGE_DB=6;static KNEE_DB=20;static COMPRESSION_RATIO=1.5;static EXPANSION_RATIO=1.8;static DEFAULT_MAX_VOICES=4;static candidates(t,e,a,n,s={}){const c=new Set;for(const[i,r]of t){const l=g.noiseOfKind(k.of(e.get(a(r))).kind);let o=1/0;for(const d of r.points)o=Math.min(o,L.seenFrom(n,{lat:d.lat,lng:d.lng,heightM:d.altitudeFt*.3048}).distanceKm);g.couldBeHeard(l,o,s.ambientDbA,s.air)&&c.add(i)}return c}static voices(t,e,a,n,s,c,i={}){const r=[];for(const l of t){const o=e.get(l);if(!o||i.only?.(l)===!1)continue;const d=i.kindOf?.(l)??k.of(a.get(n(o))).kind,u=i.noiseOf?.(l)??g.noiseOfKind(d),h=g.heardAt(o,s,c,{...i,noise:u});if(!h?.audible)continue;const p=i.throughDb,m=p?h.bandsDbA.map((M,f)=>M-(p[f]??0)):h.bandsDbA;p&&!D.noticed(m,h.ambientDbA)||r.push({id:l,kind:d,bandAmplitudes:D.bandAmplitudes(m,h.ambientDbA,i.referenceAmplitude),levelDbA:p?A.sumDb(m):h.levelDbA,distanceKm:h.sound.distanceKm,dopplerRatio:h.dopplerRatio,azimuthDeg:h.sound.azimuthDeg,elevationDeg:h.sound.altitudeDeg,character:u.character})}return r.sort((l,o)=>o.levelDbA-l.levelDbA).slice(0,i.maxVoices??D.DEFAULT_MAX_VOICES)}static noticed(t,e){const a=g.ambientBands(e);return t.some((n,s)=>n>=a[s]+g.DETECTION_MARGIN_DB)}static bandAmplitudes(t,e,a=D.REFERENCE_AMPLITUDE){const n=g.ambientBands(e),s=g.DETECTION_MARGIN_DB,c=A.sumDb(t),i=c-e,r=i>=D.KNEE_DB?D.KNEE_DB+(i-D.KNEE_DB)/D.COMPRESSION_RATIO:D.KNEE_DB-(D.KNEE_DB-i)*D.EXPANSION_RATIO,l=a*10**(r/20);return t.map((o,d)=>{const u=Math.min(1,Math.max(0,(o-n[d]-s+D.MASKING_RANGE_DB)/(2*D.MASKING_RANGE_DB)));return u*u*(3-2*u)*l*10**((o-c)/20)})}static BANDS_HZ=A.OCTAVES}class V{static RUMBLE_BELOW_HZ=500;static DULL_BELOW_HZ=2e3;static PITCH_NOTICED=.03;static text(t,e,a,n){const s=(u,h=0)=>u.toLocaleString(n,{maximumFractionDigits:h}),c=(u,h)=>u.replace(/\{(\w+)\}/g,(p,m)=>h[m]??`{${m}}`),i=[],r=[t.registration,t.name].filter(Boolean).join(" · ");i.push(r||c(e.unnamed,{hex:t.hex}));const l=[c(e.altitude,{value:s(Math.round(t.altitudeFt/100)*100)}),t.groundSpeedKt===void 0?void 0:c(e.speed,{value:s(Math.round(t.groundSpeedKt))}),t.trackDeg===void 0?void 0:c(e.heading,{value:s(Math.round(t.trackDeg))})].filter(Boolean);i.push(l.join(" · ")),i.push(c(e.position,{distance:s(t.sky.distanceKm,t.sky.distanceKm<10?1:0),elevation:s(Math.round(t.sky.altitudeDeg)),bearing:a(t.sky.azimuthDeg)}));const o=t.hearing;if(!o)i.push(e.soundUnknown);else if(!o.audible)i.push(c(e.inaudible,{level:s(Math.round(o.levelDbA)),ambient:s(Math.round(o.ambientDbA))}));else{const u=o.cutoffHz??0,h=u<=V.RUMBLE_BELOW_HZ?e.rumble:u<=V.DULL_BELOW_HZ?e.muffled:e.broad,p=o.dopplerRatio-1,m=Math.abs(p)<V.PITCH_NOTICED?"":c(p>0?e.pitchHigher:e.pitchLower,{percent:s(Math.round(Math.abs(p)*100))});i.push(c(e.heard,{level:s(Math.round(o.levelDbA)),delay:s(Math.round(o.delayS)),lag:s(Math.round(o.lagDeg)),character:c(h,{cutoff:s(u)}),pitch:m}))}t.contrail&&i.push(c(t.contrail.persistent?e.contrailPersistent:e.contrailShort,{rhi:s(Math.round(t.contrail.iceRelativeHumidity*100))}));const d=[t.military?e.military:void 0,t.restricted?e.restricted:void 0].filter(Boolean);return d.length>0&&i.push(d.join(" · ")),i.push(e.candidate),i.join(`
|
|
2
2
|
`)}}class Z{static EFFICIENCY={"airliner-narrow":.34,"airliner-wide":.38,"regional-jet":.32,"business-jet":.3,"military-jet":.22,unknown:.34};static efficiencyOf(t){return Z.EFFICIENCY[t]}}class E{static EMISSION_INDEX_WATER=1.25;static COMBUSTION_HEAT=432e5;static AIR_HEAT_CAPACITY=1004;static MOLAR_MASS_RATIO=.622;static FT_TO_M=.3048;static TROPOPAUSE_M=11e3;static TROPOPAUSE_HPA=226.32;static ISOTHERMAL_SCALE_HEIGHT_M=6341.62;static pressureAtAltitudeFt(t){const e=t*E.FT_TO_M;return e<=E.TROPOPAUSE_M?1013.25*(1-225577e-10*e)**5.25588:E.TROPOPAUSE_HPA*Math.exp(-(e-E.TROPOPAUSE_M)/E.ISOTHERMAL_SCALE_HEIGHT_M)}static saturationOverWaterPa(t){const e=t+273.15;return Math.exp(54.842763-6763.22/e-4.21*Math.log(e)+367e-6*e+Math.tanh(.0415*(e-218.8))*(53.878-1331.22/e-9.44523*Math.log(e)+.014025*e))}static saturationOverIcePa(t){const e=t+273.15;return Math.exp(9.550426-5723.265/e+3.53068*Math.log(e)-.00728332*e)}static iceRelativeHumidity(t,e){return e*E.saturationOverWaterPa(t)/E.saturationOverIcePa(t)}static mixingSlope(t,e){return E.EMISSION_INDEX_WATER*E.AIR_HEAT_CAPACITY*t*100/(E.MOLAR_MASS_RATIO*E.COMBUSTION_HEAT*(1-e))}static criticalTemperatureC(t,e){const a=Math.log(E.mixingSlope(t,e)-.053);return-46.46+9.43*a+.72*a*a}static requiredHumidity(t,e,a){const n=E.criticalTemperatureC(t,e);return(E.mixingSlope(t,e)*(a-n)+E.saturationOverWaterPa(n))/E.saturationOverWaterPa(a)}static evaluate(t,e){const a=E.criticalTemperatureC(t.pressureHpa,e),n=E.requiredHumidity(t.pressureHpa,e,t.temperatureC),s=E.iceRelativeHumidity(t.temperatureC,t.relativeHumidity),c=t.temperatureC<a&&t.relativeHumidity>=n;return{forms:c,persistent:c&&s>=1,criticalTemperatureC:a,requiredHumidity:n,iceRelativeHumidity:s}}}class y{static HOLD_MS=36e5;static DEG=Math.PI/180;static GAS_CONSTANT_OVER_GRAVITY=287.05/9.80665;static at(t,e,a){if(t.length===0)return;const n=t[0],s=t[t.length-1];if(e<n.t-y.HOLD_MS||e>s.t+y.HOLD_MS)return;const c=t.findIndex(h=>h.t>e),i=c===0?t[0]:t[(c===-1?t.length:c)-1],r=c===-1||c===0?i:t[c],l=y.atLevel(i,a),o=y.atLevel(r,a);if(!l||!o)return;const d=r.t>i.t?Math.min(1,Math.max(0,(e-i.t)/(r.t-i.t))):0,u=(h,p)=>h+(p-h)*d;return{pressureHpa:a,temperatureC:u(l.temperatureC,o.temperatureC),relativeHumidity:u(l.relativeHumidity,o.relativeHumidity),driftEastMs:u(l.driftEastMs,o.driftEastMs),driftNorthMs:u(l.driftNorthMs,o.driftNorthMs),shearPerS:u(l.shearPerS,o.shearPerS)}}static atLevel(t,e){const a=t.levels;for(let n=0;n+1<a.length;n++){const s=a[n],c=a[n+1];if(e>s.pressureHpa||e<c.pressureHpa)continue;const i=(Math.log(s.pressureHpa)-Math.log(e))/(Math.log(s.pressureHpa)-Math.log(c.pressureHpa)),r=(h,p)=>h+(p-h)*i,l=h=>{const p=h.windFromDeg*y.DEG;return{east:-h.windSpeedMs*Math.sin(p),north:-h.windSpeedMs*Math.cos(p)}},o=l(s),d=l(c),u=y.GAS_CONSTANT_OVER_GRAVITY*((s.temperatureC+c.temperatureC)/2+273.15)*Math.log(s.pressureHpa/c.pressureHpa);return{pressureHpa:e,temperatureC:r(s.temperatureC,c.temperatureC),relativeHumidity:r(s.relativeHumidity,c.relativeHumidity),driftEastMs:r(o.east,d.east),driftNorthMs:r(o.north,d.north),shearPerS:Math.hypot(d.east-o.east,d.north-o.north)/u}}}}class H{static MIN_ALTITUDE_FT=2e4;static DENSE_MS=3e5;static SPARSE_STEP_MS=6e4;static SATURATION_HORIZON_MS=3*36e5;static SATURATION_STEP_MS=6e5;static PRESSURE_STEP_HPA=5;static plan(t,e,a,n){if(a.length===0)return[];const s=[],c=new Map,i=(r,l,o)=>{const d=Math.round(l/H.PRESSURE_STEP_HPA)*H.PRESSURE_STEP_HPA,u=H.SATURATION_STEP_MS,h=Math.floor(r/u)*u,p=`${d}|${h}`,m=c.get(p);if(m!==void 0)return m+(h-r)/1e3;let M=1/0;for(let f=u;f<=H.SATURATION_HORIZON_MS;f+=u){const I=y.at(a,h+f,d);if(!I)break;if(E.evaluate(I,o).iceRelativeHumidity<1){M=f/1e3;break}}return c.set(p,M),M+(h-r)/1e3};for(const r of t.objects){const l=t.flights.get(r.id),o=r.track;if(!l||!o||o.length!==l.points.length)continue;const d=e?.get(W.keyOf(l))??k.of(void 0),u=Z.efficiencyOf(d.kind);if(u===void 0)continue;const h=[];let p=-1/0;o.forEach((m,M)=>{if(m.t<-H.DENSE_MS&&M+1<o.length&&m.t-p<H.SPARSE_STEP_MS)return;p=m.t;const f=l.points[M],I=E.pressureAtAltitudeFt(f.altitudeFt),S=y.at(a,n+m.t,I),b=S&&E.evaluate(S,u);h.push({tMs:m.t,eastM:m.eastM,northM:m.northM,upM:m.altitudeM??0,forms:b?.forms??!1,persistent:b?.persistent??!1,lifetimeS:b?et.lifetimeS(b.iceRelativeHumidity):0,driftEastMs:S?.driftEastMs??0,driftNorthMs:S?.driftNorthMs??0,shearPerS:S?.shearPerS??et.TYPICAL_SHEAR_PER_S,iceRelativeHumidity:b?.iceRelativeHumidity??0,saturatedForS:b?.persistent?i(n+m.t,I,u):0})}),h.some((m,M)=>m.forms&&h[M+1]?.forms)&&s.push({id:r.id,spanM:d.spanM,points:h})}return s}}const dt=[500,400,300,250,200,150],Lt=["temperature","relative_humidity","wind_speed","wind_direction"],Ft="2022-01-01",pt=.25;class Gt{fetchImpl;baseUrl;cache=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.baseUrl=t.baseUrl??"https://historical-forecast-api.open-meteo.com/v1/forecast"}between(t,e,a){const n=new Date(e).toISOString().slice(0,10);if(n<Ft)return Promise.resolve({status:"outside"});const s=new Date(a).toISOString().slice(0,10),i=`${`${Math.round(t.lat/pt)},${Math.round(t.lng/pt)}`}|${n}|${s}`;let r=this.cache.get(i);return r||(r=this.read(t,n,s),this.cache.set(i,r),r.then(l=>{l.status==="failed"&&this.cache.delete(i)})),r}async read(t,e,a){const n=dt.flatMap(i=>Lt.map(r=>`${r}_${i}hPa`)),s=new URLSearchParams({latitude:String(t.lat),longitude:String(t.lng),start_date:e,end_date:a,hourly:n.join(","),wind_speed_unit:"ms",timezone:"UTC"}),c=`${this.baseUrl}?${s}`;try{const i=await this.fetchImpl(c);if(!i.ok)return{status:"failed"};const r=await i.json();return this.decode(r,{id:"open-meteo-forecast",name:"Open-Meteo (historical forecast)",url:c})}catch{return{status:"failed"}}}decode(t,e){const a=t.hourly;if(!a?.time)return{status:"outside"};const n=[];return a.time.forEach((s,c)=>{const i=[];for(const r of dt){const l=p=>a[`${p}_${r}hPa`]?.[c],o=l("temperature"),d=l("relative_humidity"),u=l("wind_speed"),h=l("wind_direction");if([o,d,u,h].some(p=>p==null))return;i.push({pressureHpa:r,temperatureC:o,relativeHumidity:d/100,windSpeedMs:u,windFromDeg:h})}n.push({t:Date.parse(`${s}Z`),levels:i})}),n.length>0?{status:"found",samples:n,source:e}:{status:"outside"}}}const zt=Q.point("upperAir").provide(Q.BUILT_IN,[{id:"open-meteo-forecast",name:"Open-Meteo (historical forecast)",credit:"Weather data by Open-Meteo.com, CC BY 4.0",creditUrl:"https://open-meteo.com/en/docs/historical-forecast-api",create:()=>new Gt}]);class C{static DEFAULT_KIND=K.DEFAULT_KIND;static STEP_MS=1e3;static LEAD_MS=12e4;static FT_PER_M=1/.3048;static ID_PREFIX="decor:";tracks=new Map;static kindOf(t,e){return K.kindOf(t,e)}static flies(t){return K.flies(t)}voices(t,e,a,n={},s=()=>{}){const c=t.event.place?.[0];if(!c)return[];const i=new Map,r=new Map,l=Math.max(t.observerTrack.duration,(t.event.durationSeconds??0)*1e3);for(const o of t.decor){const d=K.kindOf(o,s(o));if(!d)continue;const u=`${C.ID_PREFIX}${o.id}`;i.set(u,this.trackOf(o,u,c,l)),r.set(u,d)}for(const o of this.tracks.keys())i.has(o)||this.tracks.delete(o);return i.size===0?[]:D.voices(new Set(i.keys()),i,new Map,o=>String(o.icao),a,e,{...n,kindOf:o=>r.get(o)})}trackOf(t,e,a,n){const s=JSON.stringify([t.track,t.eastM,t.northM,t.headingDeg,a.lat,a.lng,n]),c=this.tracks.get(e);if(c?.key===s)return c.track;const i=[];for(let u=0;u<=n;u+=C.STEP_MS)i.push(C.pointAt(t,u,a));(i.length===0||i[i.length-1].t<n)&&i.push(C.pointAt(t,n,a));const r=i[0],l=i[1]??r,o=u=>(l[u]-r[u])/(l.t-r.t||1);for(let u=C.STEP_MS*10;u<=C.LEAD_MS;u+=C.STEP_MS*10)i.unshift({t:-u,lat:r.lat-o("lat")*u,lng:r.lng-o("lng")*u,altitudeFt:Math.max(0,r.altitudeFt-o("altitudeFt")*u)});const d={icao:C.hash(e),nonIcao:!0,points:i};return this.tracks.set(e,{key:s,track:d}),d}static pointAt(t,e,a){const n=Et(t,e),s=Y(n.eastM,-n.northM,a.lat,a.lng);return{t:e,lat:s.lat,lng:s.lng,altitudeFt:n.altitudeM*C.FT_PER_M}}static hash(t){let e=0;for(let a=0;a<t.length;a++)e=e*31+t.charCodeAt(a)>>>0;return e}}class X{static CABIN_DB_A={"airliner-wide":76,"airliner-narrow":78,"regional-jet":78,"business-jet":82,"regional-turboprop":84,"turboprop-light":88,"light-piston":92,"military-jet":95,ultralight:95,"helicopter-light":95,"helicopter-medium":96,"helicopter-heavy":98,glider:70,balloon:60};static DEFAULT_DB_A=78;static voice(t,e={}){const a=tt.aircraftOf(t);if(!a)return;const n=g.noiseOfKind(a),s=tt.insulationDb(t),c=n.soundPowerA.map((o,d)=>o-s[d]),i=A.sumDb(c),r=X.levelDbA(a,t?.noise),l=c.map(o=>o-i+r);return{id:"observer:cabin",kind:a,bandAmplitudes:D.bandAmplitudes(l,e.ambientDbA??0,e.referenceAmplitude),levelDbA:r,inside:!0,distanceKm:0,dopplerRatio:1,azimuthDeg:0,elevationDeg:0,character:n.character}}static levelDbA(t,e){return(X.CABIN_DB_A[t]??X.DEFAULT_DB_A)+20*Math.log10(Math.max(e??1,.01))}}class G{static STEP_MS=250;static FT_PER_M=1/.3048;static ID_PREFIX="body:";tracks=new Map;static noiseOf(t){const e=g.noiseOfKind(t.kind),a=t.quieterDb??0;return a===0?e:{...e,id:`${e.id}-${a}dB`,soundPowerA:e.soundPowerA.map(n=>n-a)}}voices(t,e,a,n,s,c,i={}){const r=new Map,l=new Map,o=new Map;for(const u of t){if(!u.sound)continue;const h=`${G.ID_PREFIX}${u.id}`,p=this.trackOf(u,h,e,n,c);p&&(r.set(h,p),l.set(h,u.sound.kind),o.set(h,G.noiseOf(u.sound)))}for(const u of this.tracks.keys())r.has(u)||this.tracks.delete(u);if(r.size===0)return[];const d=Y(a.eastM,-a.northM,n.lat,n.lng);return D.voices(new Set(r.keys()),r,new Map,u=>String(u.icao),{lat:d.lat,lng:d.lng,heightM:a.upM},s,{...i,kindOf:u=>l.get(u),noiseOf:u=>o.get(u)})}trackOf(t,e,a,n,s){const c=`${n.lat},${n.lng},${s}`,i=this.tracks.get(e);if(i&&i.body===t&&i.origin===c)return i.track;const r=[];for(let o=-12e4;o<=s;o+=G.STEP_MS){const d=a(t,o);if(!d)continue;const u=Y(d.eastM,-d.northM,n.lat,n.lng);r.push({t:o,lat:u.lat,lng:u.lng,altitudeFt:d.upM*G.FT_PER_M})}if(r.length<2)return;const l={icao:G.hash(e),nonIcao:!0,points:r};return this.tracks.set(e,{body:t,origin:c,track:l}),l}static hash(t){let e=0;for(let a=0;a<t.length;a++)e=e*31+t.charCodeAt(a)>>>0;return e}}export{J as AircraftAudio,H as AircraftContrails,k as AircraftModels,v as AmbientNoise,G as BodyHearing,X as CabinHearing,C as DecorAircraftHearing,R as TrafficDecor,Kt as TrafficInfos,D as TrafficSound,V as TrafficTooltip,zt as UPPER_AIR_SOURCES};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SightingFileEditor-CASP3L_i.js","./index-DSNA74v6.js","./sightingSchema-DbcXsOHL.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{S
|
|
2
|
+
import{S,a as T,H as M,s as j,U as I,I as P,b as W,P as z,c as y,W as N,r as D,d as J,E as L,e as H,A as B,f as E,M as q,_ as C,l as V}from"./rr0-sighting-editor.mjs";import{InterviewMedia as A}from"./InterviewMedia-CvAxC62V.js";import{InterviewFile as f}from"./interviewJson-DXD8FSBX.js";const $="rr0-interview",G=`
|
|
3
3
|
rr0-interview { display: block; --rr0-interview-line: color-mix(in srgb, currentColor 35%, transparent); }
|
|
4
4
|
rr0-interview [hidden] { display: none !important; }
|
|
5
5
|
rr0-interview .rr0-interview-status { font-size: .85em; opacity: .85; margin: 0 0 .5em; }
|
|
@@ -11,6 +11,9 @@ rr0-interview .intervention { margin: 0 0 .4em; border-left: 3px solid var(--spe
|
|
|
11
11
|
rr0-interview .intervention:hover { background: color-mix(in srgb, var(--speaker) 7%, transparent); }
|
|
12
12
|
rr0-interview .turn { position: relative; padding: .2em .5em; }
|
|
13
13
|
rr0-interview .turn.flash { background: color-mix(in srgb, #fc3 28%, transparent); }
|
|
14
|
+
/* The passage the replay is inside stays lit while it is there, instead of a flash that is over before anyone looks. Nothing marks the
|
|
15
|
+
passages that are merely tied to a moment: each already carries its timecode, which says it (dicté). */
|
|
16
|
+
rr0-interview .turn.synced { background: color-mix(in srgb, #fc3 12%, transparent); }
|
|
14
17
|
rr0-interview .turn .who { font-size: .85em; font-weight: 600; color: var(--speaker); overflow-wrap: anywhere; }
|
|
15
18
|
rr0-interview .turn.is-redacted .who, rr0-interview .turn.goes-on .who { display: none; }
|
|
16
19
|
rr0-interview .turn .said, rr0-interview .turn .redacted { margin: 0; padding: 0; text-indent: 0; white-space: pre-wrap; }
|
|
@@ -26,7 +29,7 @@ rr0-interview .turn .refs { display: flex; flex-wrap: wrap; gap: .25em; }
|
|
|
26
29
|
rr0-interview .turn .ref { font: inherit; font-size: .8em; cursor: pointer; border: 1px solid var(--rr0-interview-line); border-radius: 999px; background: transparent; color: inherit;
|
|
27
30
|
padding: 0 .35em; font-variant-numeric: tabular-nums; white-space: nowrap; display: inline-flex; align-items: center; gap: .15em; }
|
|
28
31
|
rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
29
|
-
`;class O extends HTMLElement{messages;said=new
|
|
32
|
+
`;class O extends HTMLElement{messages;said=new S(["en"]);localeToken=0;loadToken=0;json;loading;base;status=document.createElement("p");turns=document.createElement("div");blocks=new Map;lastRevealed;syncedIndex;constructor(){super(),this.status.className="rr0-interview-status",this.status.setAttribute("role","status"),this.turns.className="rr0-interview-turns"}static get observedAttributes(){return["src"]}attributeChangedCallback(e,t,s){e==="src"&&s!==t&&this.isConnected&&this.load()}connectedCallback(){O.styleRoot(this.getRootNode()),this.contains(this.turns)||this.replaceChildren(this.status,this.turns),this.loadLocale(),this.hasAttribute("src")&&this.json===void 0&&this.loading!==this.getAttribute("src")&&this.load()}get interview(){return this.json}set interview(e){this.loadToken++,this.json=e,this.draw()}set documentUrl(e){this.base=e}static styleRoot(e){const t=e instanceof ShadowRoot?e:document.head;if(t.querySelector("style[data-rr0-interview]"))return;const s=document.createElement("style");s.dataset.rr0Interview="",s.textContent=G,t.append(s)}async load(){const e=this.getAttribute("src"),t=++this.loadToken;if(this.loading=e??void 0,!e)return;const s=new URL(e,location.href).href;let r;try{r=f.read(await T.json(s))}catch{r=void 0}t===this.loadToken&&(this.base=s,this.json=r,this.draw())}async loadLocale(){const e=++this.localeToken,t=M.preferencesFor(this),s=j(t,I),r=await P.load(s);e===this.localeToken&&(this.said=new S(t),this.messages=r,this.draw())}speakerName(e,t){const s=f.speakerName(e,t),r=e.speakers?.[t]?.role;return s===r&&r in this.messages.roles?this.messages.roles[r]:s}seek(e,t){const s=this.json,r=t?f.said(t):void 0,i={sighting:e.sighting??f.sightingsOf(s)[0],at:e.at,...r?{quote:r}:{}};this.dispatchEvent(new CustomEvent(W,{bubbles:!0,composed:!0,detail:i}));const a=this.getAttribute("player");if(!a)return;const l=this.getRootNode().getElementById?.(a);typeof l?.seekTo=="function"&&(l.scrollIntoView?.({block:"center",behavior:"smooth"}),l.seekTo(i.at,i.sighting))}gap(e,t){const s=document.createElement(t),r=document.createElement("span");r.className="bar";const i=`${this.messages.redacted}${this.messages.colon}${this.said.read(e)??""}`;return r.dataset.tip=i,r.tabIndex=0,r.setAttribute("role","img"),r.setAttribute("aria-label",i),s.append(r),s}saidNodes(e){if(!/[<&]/.test(e))return[document.createTextNode(e)];const t=document.createElement("template");t.innerHTML=e;for(const s of t.content.querySelectorAll("*")){if(["SCRIPT","STYLE","IFRAME","OBJECT","EMBED"].includes(s.tagName)){s.remove();continue}for(const r of[...s.attributes])if(/^on/i.test(r.name)||/^\s*javascript:/i.test(r.value))s.removeAttribute(r.name);else if(["href","src"].includes(r.name))try{r.value=new URL(r.value,this.base??location.href).href}catch{}}return[...t.content.childNodes]}draw(){if(!this.messages)return;const e=this.messages,t=this.json;this.blocks.clear();const s=Array.isArray(t?.segments)?t.segments:[];if(!t||s.length===0){this.status.hidden=!0;const d=document.createElement("p");d.textContent=e.exchangesEmpty,this.turns.replaceChildren(d);return}const r=t.speakers??{},i=Object.keys(r);if(t.proofreading){const d=i.filter(h=>!["approved","covered"].includes(t.proofreading?.[h]?.status??""));this.status.textContent=d.length===0?e.proofreadAll:e.proofreadPending.replace("{names}",d.map(h=>this.speakerName(t,h)).join(", ")),this.status.hidden=!1}else this.status.hidden=!0;const a=[];let n,l=!1,c,o;s.forEach((d,h)=>{const u=d.redacted?JSON.stringify(d.redacted.reason):void 0;if(u!==void 0&&c?.reason===u){this.blocks.set(h,c.block),d.speaker!==o&&(o=void 0);return}const p=document.createElement("div");p.className="turn",p.dataset.segment=String(h);const b=document.createElement("div");b.className="who";const x=document.createElement("span");if(x.textContent=d.redacted?"":this.speakerName(t,d.speaker),d.start!==void 0&&(p.dataset.time=f.clock(d.start,!0)),o!==d.speaker&&(n=document.createElement("div"),n.className="intervention",n.style.setProperty("--speaker-hue",String((Math.max(0,i.indexOf(d.speaker))*67+210)%360)),a.push(n),l=!1),d.redacted||(l&&p.classList.add("goes-on"),l=!0),n.append(p),o=d.speaker,b.append(x),d.redacted){p.classList.add("is-redacted");const v=this.gap(d.redacted.reason,"p");v.className="redacted",c={block:p,reason:u},p.append(b,v)}else{const v=document.createElement("p");if(v.className="said",d.parts){let k="";for(const w of d.parts){const R="redacted"in w?"▮":f.plain(w.text);/[\p{L}\p{N}.,;:!?)»”…▮]$/u.test(k)&&/^[\p{L}\p{N}(«“▮]/u.test(R)&&v.append(" "),"redacted"in w?v.append(this.gap(w.redacted.reason,"span")):v.append(...this.saidNodes(w.text)),k=R}}else v.append(...this.saidNodes(d.text??""));c=void 0,p.append(b,v)}if(d.refs?.length){const v=document.createElement("div");v.className="refs";for(const k of d.refs){const w=document.createElement("button");w.type="button",w.className="ref",w.innerHTML=z.PLAY,w.append(f.clock(k.at,!0)),w.addEventListener("click",()=>this.seek(k,d)),v.append(w)}p.append(v)}this.blocks.set(h,p)}),this.turns.replaceChildren(...a)}revealAt(e,t){const s=this.json;if(!s)return;const r=f.sightingsOf(s)[0];let i;if(s.segments?.forEach((a,n)=>{for(const l of a.refs??[]){const c=l.sighting??r;t!==void 0&&c!==void 0&&c!==t||l.at>e+.001||(!i||l.at>i.at)&&(i={index:n,at:l.at})}}),!!i)return i.index!==this.lastRevealed&&(this.lastRevealed=i.index,this.revealSegment(i.index)),this.markSynced(i.index),i.index}momentsCited(e){const t=this.json;if(!t)return[];const s=f.sightingsOf(t)[0],r=[];for(const i of t.segments??[])for(const a of i.refs??[]){const n=a.sighting??s;e!==void 0&&n!==void 0&&n!==e||r.push({at:a.at,quote:f.said(i)??""})}return r.sort((i,a)=>i.at-a.at)}markSynced(e){e!==this.syncedIndex&&(this.syncedIndex!==void 0&&this.blocks.get(this.syncedIndex)?.classList.remove("synced"),this.syncedIndex=e,this.blocks.get(e)?.classList.add("synced"))}revealSegment(e){const t=this.blocks.get(e);t&&(t.scrollIntoView?.({block:"center"}),t.classList.add("flash"),window.setTimeout(()=>t.classList.remove("flash"),1600))}}function Y(){customElements.get($)||customElements.define($,O)}class g{static partsOf(e){return e.parts?e.parts:e.redacted?[]:[{text:e.text??""}]}static shownRanges(e){const t=[];let s="",r=0;return e.forEach((i,a)=>{const n="redacted"in i?"▮":f.plain(i.text);/[\p{L}\p{N}.,;:!?)»”…▮]$/u.test(s)&&/^[\p{L}\p{N}(«“▮]/u.test(n)&&(r+=1);const l="redacted"in i?0:n.length;t.push({part:a,from:r,to:r+l}),r+=l,s=n}),t}static words(e){return e.trim()===""?0:e.trim().split(/\s+/u).length}static redact(e,t,s,r){const i=[...g.partsOf(e)],a=g.shownRanges(i).find(x=>!("redacted"in i[x.part])&&t>=x.from&&s<=x.to);if(!a)return;const n=f.plain(i[a.part].text),l=/[\p{L}\p{N}'’-]/u;let c=t-a.from,o=s-a.from;for(;c>0&&l.test(n[c-1])&&l.test(n[c]);)c--;for(;o<n.length&&l.test(n[o])&&l.test(n[o-1]);)o++;const d=n.slice(c,o);if(d.trim()==="")return;const h=n.slice(0,c).trimEnd(),u=n.slice(o).trimStart(),p=[...h!==""?[{text:h}]:[],{redacted:{reason:r,words:g.words(d)}},...u!==""?[{text:u}]:[]],b=i.slice(0,a.part).filter(x=>"redacted"in x).length;return i.splice(a.part,1,...p),g.setParts(e,i),{text:d.trim(),nth:b}}static redactWhole(e,t){const s=JSON.stringify({text:e.text,parts:e.parts}),r=g.partsOf(e).reduce((i,a)=>i+("redacted"in a?a.redacted.words??0:g.words(f.plain(a.text))),0);if(delete e.text,delete e.parts,e.redacted={reason:t,...r>0?{words:r}:{}},e.refs)for(const i of e.refs)delete i.range;return s}static restoreWhole(e,t){const{text:s,parts:r}=JSON.parse(t);delete e.redacted,r?e.parts=r:e.text=s??""}static restorePart(e,t,s){const r=[...g.partsOf(e)];let i=-1;const a=r.findIndex(n=>"redacted"in n&&++i===t);a!==-1&&(r.splice(a,1,{text:s}),g.setParts(e,r))}static raw(e,t=()=>{}){let s=-1,r="",i="";for(const a of g.partsOf(e)){const n="redacted"in a?`⟦${t(++s)??"…"}⟧`:a.text;r!==""&&!/\s$/u.test(i)&&!/^\s/u.test(n)&&(r+=" "),r+=n,i=n}return r}static fromRaw(e,t,s){const r=g.partsOf(e).filter(l=>"redacted"in l),i=[],a=new Map;let n=-1;return t.split(/⟦([^⟧]*)⟧/u).forEach((l,c)=>{if(c%2===0){l.trim()!==""&&i.push({text:l.trim()});return}n++;const o=l.trim();o===""||o==="…"||o==="..."?i.push({redacted:r[n]?.redacted??{reason:s}}):(i.push({redacted:{reason:s,words:g.words(o)}}),a.set(n,o))}),delete e.redacted,g.setParts(e,i),a}static setParts(e,t){const s=[];for(const r of t){const i=s[s.length-1],a=!("redacted"in r)&&/^[,.;:!?)»”…]/u.test(r.text)?"":" ";i&&!("redacted"in i)&&!("redacted"in r)?s[s.length-1]={text:`${i.text}${a}${r.text}`.replace(/\s+/gu," ").trim()}:s.push(r)}if(s.some(r=>"redacted"in r)){if(e.parts=s,delete e.text,e.refs)for(const r of e.refs)delete r.range}else e.text=s.map(r=>r.text).join(" "),delete e.parts}}class U{constructor(e,t,s){this.host=t,this.messages=s,e.classList.add("player"),e.innerHTML=`<div class="player-video" hidden></div>
|
|
30
33
|
<div class="player-bar">
|
|
31
34
|
<button type="button" class="icon-btn player-play" disabled>${y.PLAY}</button>
|
|
32
35
|
<span class="player-time">0:00</span>
|
|
@@ -35,7 +38,7 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
|
35
38
|
<button type="button" class="pill-btn player-recordings"></button>
|
|
36
39
|
</div>
|
|
37
40
|
<p class="player-empty"></p>
|
|
38
|
-
<dialog class="recordings-window"><h3></h3><div class="recording-rows"></div><button type="button" class="pill-btn recording-add">${y.PLUS}<span></span></button></dialog>`,this.play=e.querySelector(".player-play"),this.time=e.querySelector(".player-time"),this.end=e.querySelector(".player-end"),this.track=e.querySelector(".speaker-track"),this.video=e.querySelector(".player-video"),this.empty=e.querySelector(".player-empty"),this.open=e.querySelector(".player-recordings"),this.window=e.querySelector(".recordings-window"),this.play.addEventListener("click",()=>{this.media&&(this.media.paused?this.media.play().catch(()=>{}):this.media.pause())}),this.track.addEventListener("pointerdown",
|
|
41
|
+
<dialog class="recordings-window"><h3></h3><div class="recording-rows"></div><button type="button" class="pill-btn recording-add">${y.PLUS}<span></span></button></dialog>`,this.play=e.querySelector(".player-play"),this.time=e.querySelector(".player-time"),this.end=e.querySelector(".player-end"),this.track=e.querySelector(".speaker-track"),this.video=e.querySelector(".player-video"),this.empty=e.querySelector(".player-empty"),this.open=e.querySelector(".player-recordings"),this.window=e.querySelector(".recordings-window"),this.play.addEventListener("click",()=>{this.media&&(this.media.paused?this.media.play().catch(()=>{}):this.media.pause())}),this.track.addEventListener("pointerdown",r=>{const i=this.track.getBoundingClientRect();i.width>0&&this.seek((r.clientX-i.left)/i.width*this.duration)}),this.track.addEventListener("keydown",r=>{(r.key==="ArrowRight"||r.key==="ArrowLeft")&&this.seek(this.now+(r.key==="ArrowRight"?5:-5))}),this.open.addEventListener("click",()=>this.showWindow()),e.querySelector(".recording-add").addEventListener("click",()=>this.edit(r=>r.push({kind:"audio",src:""}))),N.dialog(this.window,s.close,()=>this.window.close())}static CSS=`
|
|
39
42
|
.player { margin: 0 0 4px; border-radius: 12px; }
|
|
40
43
|
.player-video { aspect-ratio: 16 / 9; margin-bottom: 8px; border-radius: 10px; overflow: hidden; background: #0b1020; }
|
|
41
44
|
.player-video video { width: 100%; height: 100%; display: block; }
|
|
@@ -59,7 +62,7 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
|
59
62
|
.recording-file { display: flex; gap: 6px; }
|
|
60
63
|
.recording-status { grid-column: 1 / -1; margin: -4px 0 0; font-size: 12px; color: var(--ink-faint); }
|
|
61
64
|
.recording-status.error { color: var(--error); }
|
|
62
|
-
`;json;base;media;mediaFor="";picked=new Map;messages;play;time;end;track;video;empty;open;window;setMessages(e){this.messages=e,this.render()}show(e,t){this.json=e,this.base=t,this.render()}get now(){return this.media?Math.max(0,this.media.currentTime-(this.recordings[0]?.offset??0)):this.position}seek(e){this.position=Math.min(this.duration,Math.max(0,e)),this.media&&(this.media.currentTime=this.position+(this.recordings[0]?.offset??0)),this.placeHead(),this.host.timeChanged(this.position)}position=0;get recordings(){return Array.isArray(this.json?.recordings)?this.json.recordings:[]}get duration(){const e=this.media&&Number.isFinite(this.media.duration)?this.media.duration-(this.recordings[0]?.offset??0):0,t=Math.max(0,...(this.json?.segments??[]).map(
|
|
65
|
+
`;json;base;media;mediaFor="";picked=new Map;messages;play;time;end;track;video;empty;open;window;setMessages(e){this.messages=e,this.render()}show(e,t){this.json=e,this.base=t,this.render()}get now(){return this.media?Math.max(0,this.media.currentTime-(this.recordings[0]?.offset??0)):this.position}seek(e){this.position=Math.min(this.duration,Math.max(0,e)),this.media&&(this.media.currentTime=this.position+(this.recordings[0]?.offset??0)),this.placeHead(),this.host.timeChanged(this.position)}position=0;get recordings(){return Array.isArray(this.json?.recordings)?this.json.recordings:[]}get duration(){const e=this.media&&Number.isFinite(this.media.duration)?this.media.duration-(this.recordings[0]?.offset??0):0,t=Math.max(0,...(this.json?.segments??[]).map(s=>s.end??s.start??0));return Math.max(1,e,t)}render(){const e=this.messages,t=this.recordings;this.open.innerHTML='<svg class="icon" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M6 12V3.5l7-1.5V10.5"/><circle cx="4.5" cy="12" r="1.5"/><circle cx="11.5" cy="10.5" r="1.5"/></svg>',this.open.append(e.recordings.replace("{n}",String(t.length))),this.empty.textContent=t.length===0?e.noRecording:"",this.empty.hidden=t.length>0,this.play.title=e.play,this.play.setAttribute("aria-label",e.play),this.track.setAttribute("aria-label",e.recordingsTitle),this.ensureMedia(),this.drawTrack(),this.window.open&&this.drawRows()}ensureMedia(){const e=this.recordings[0],t=e?`${e.kind}|${e.src}`:"";if(t===this.mediaFor||(this.mediaFor=t,this.media?.pause(),this.media=void 0,this.video.replaceChildren(),this.video.hidden=!0,this.play.disabled=!0,!e||e.src===""))return;const s=document.createElement(e.kind==="video"?"video":"audio");s.preload="metadata",s.src=this.urlOf(e.src),s.addEventListener("loadedmetadata",()=>this.drawTrack()),s.addEventListener("timeupdate",()=>{this.placeHead(),this.host.timeChanged(this.now)});const r=()=>{const i=!s.paused;this.play.innerHTML=i?y.PAUSE:y.PLAY;const a=i?this.messages.pause:this.messages.play;this.play.title=a,this.play.setAttribute("aria-label",a)};s.addEventListener("play",r),s.addEventListener("pause",r),e.kind==="video"&&(this.video.append(s),this.video.hidden=!1),this.media=s,this.play.disabled=!1}urlOf(e){const t=this.picked.get(e);if(t)return t;try{return new URL(e,this.base??location.href).href}catch{return e}}drawTrack(){const e=this.json,t=this.duration,s=(e?.segments??[]).filter(i=>i.start!==void 0);this.track.replaceChildren(...s.map(i=>{const a=document.createElement("span"),n=e?.speakers?.[i.speaker]?.role;a.className=i.redacted?"seg redacted":"seg",a.dataset.role=n==="witness"||n==="interviewer"?n:"other";const l=i.start??0,c=i.end??l+1;return a.style.left=`${l/t*100}%`,a.style.width=`${Math.max(.3,(c-l)/t*100)}%`,a}));const r=document.createElement("span");r.className="head",this.track.append(r),this.track.setAttribute("aria-valuemax",String(Math.round(t))),this.end.textContent=f.clock(t),this.placeHead()}placeHead(){const e=this.now,t=this.track.querySelector(".head");t&&(t.style.left=`${Math.min(e,this.duration)/this.duration*100}%`),this.time.textContent=f.clock(Math.floor(e)),this.track.setAttribute("aria-valuenow",String(Math.round(e)))}showWindow(){this.drawRows(),typeof this.window.showModal=="function"?this.window.showModal():this.window.setAttribute("open","")}drawRows(){const e=this.messages;this.window.querySelector("h3").textContent=e.recordingsTitle,this.window.querySelector(".recording-add span").textContent=e.recordingAdd,N.dialog(this.window,e.close,()=>this.window.close()),this.window.querySelector(".recording-rows").replaceChildren(...this.recordings.map((s,r)=>{const i=document.createElement("div");i.className="recording-row";const a=document.createElement("select");a.append(new Option(e.recordingAudio,"audio"),new Option(e.recordingVideo,"video")),a.value=s.kind,a.addEventListener("change",()=>this.edit(p=>{p[r].kind=a.value}));const n=document.createElement("input");n.type="text",n.value=s.src,n.placeholder="interview.mp3",n.addEventListener("change",()=>this.edit(p=>{p[r].src=n.value.trim()}));const l=document.createElement("input");l.type="file",l.accept="audio/*,video/*",l.hidden=!0,l.addEventListener("change",()=>{const p=l.files?.[0];p&&(this.picked.set(p.name,URL.createObjectURL(p)),this.edit(b=>{b[r].src=p.name,p.type.startsWith("video/")&&(b[r].kind="video")}))});const c=document.createElement("button");c.type="button",c.className="icon-btn",c.title=e.recordingFile,c.setAttribute("aria-label",e.recordingFile),c.innerHTML='<svg class="icon" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 4.5h4l1.5 1.5h5.5v6.5h-11z"/></svg>',c.addEventListener("click",()=>l.click());const o=document.createElement("span");o.className="recording-file",o.append(n,c,l);const d=document.createElement("input");d.type="number",d.step="0.1",d.value=s.offset!==void 0?String(s.offset):"",d.placeholder="0",d.addEventListener("change",()=>this.edit(p=>{const b=Number(d.value);d.value.trim()===""||!Number.isFinite(b)||b===0?delete p[r].offset:p[r].offset=b}));const h=document.createElement("button");h.type="button",h.className="icon-btn",h.innerHTML=y.TRASH,h.title=e.recordingRemove,h.setAttribute("aria-label",e.recordingRemove),h.addEventListener("click",()=>this.edit(p=>{p.splice(r,1)}));const u=document.createElement("p");return u.className="recording-status",this.check(s,u),i.append(this.labelled(e.recordingKind,a),this.labelled(e.recordingFile,o),this.labelled(e.recordingOffset,d,"s"),h,u),i}))}labelled(e,t,s){const r=document.createElement("label"),i=document.createElement("span");return i.textContent=e,r.append(i,t),s&&r.append(` ${s}`),r}check(e,t){if(e.src==="")return;const s=document.createElement(e.kind==="video"?"video":"audio");s.preload="metadata",s.addEventListener("loadedmetadata",()=>{t.textContent=f.clock(Math.round(s.duration)),t.classList.remove("error")}),s.addEventListener("error",()=>{t.textContent=this.messages.loadFailed,t.classList.add("error")}),s.src=this.urlOf(e.src)}edit(e){const t=structuredClone(this.recordings);e(t),this.host.recordingsChanged(t)}}const F="rr0-interview-editor",K=`
|
|
63
66
|
<style>
|
|
64
67
|
:host { display: block; }
|
|
65
68
|
/* The colours of the transcript's text editor (see SightingFileEditor): a key, a string, a number or a word, and a mistake. Dark mode redefines them. */
|
|
@@ -93,19 +96,19 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
|
93
96
|
fieldset.witnesses legend { float: left; padding: 0; margin-right: .4em; }
|
|
94
97
|
#exchanges { --rr0-interview-max-height: 32em; --rr0-interview-overflow: auto; }
|
|
95
98
|
.file-note { margin: .3em 0; }
|
|
96
|
-
${
|
|
99
|
+
${q.rules([".file-note"])}
|
|
97
100
|
.file-editor { min-height: 18em; margin-top: .5em; }
|
|
98
101
|
/* ---- The design handoff's look (design_handoff_editeurs_ufoathome, §2 and §5) ---- */
|
|
99
102
|
:host {
|
|
100
|
-
${
|
|
103
|
+
${L.TOKENS}
|
|
101
104
|
--rr0-field-radius: 8px;
|
|
102
105
|
--rr0-input-font-size: 15px;
|
|
103
106
|
container-type: inline-size;
|
|
104
107
|
font: 400 15px/1.5 var(--sans);
|
|
105
108
|
color: var(--ink);
|
|
106
109
|
}
|
|
107
|
-
${
|
|
108
|
-
${
|
|
110
|
+
${L.HEAD}
|
|
111
|
+
${L.fields(".interview-app")}
|
|
109
112
|
.recordings-window :is(button, input, select) { font: inherit; }
|
|
110
113
|
.recordings-window .pill-btn { min-height: 36px; }
|
|
111
114
|
/* Its parts, underlined, as the case's are. */
|
|
@@ -140,8 +143,8 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
|
140
143
|
#exchanges .rr0-interview-status { padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--ink-dim); font-size: 13px; }
|
|
141
144
|
#group-transcript > .row { margin-bottom: 12px; }
|
|
142
145
|
@container (max-width: 640px) { #exchanges { --rr0-interview-max-height: 440px; } }
|
|
143
|
-
${
|
|
144
|
-
${
|
|
146
|
+
${U.CSS}
|
|
147
|
+
${H.CSS}
|
|
145
148
|
${N.CSS}
|
|
146
149
|
${B.CSS}
|
|
147
150
|
${y.CSS}
|
|
@@ -227,5 +230,5 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
|
|
|
227
230
|
<div id="file-editor" class="file-editor"></div>
|
|
228
231
|
</section>
|
|
229
232
|
</div>
|
|
230
|
-
`;class m extends HTMLElement{shadow=this.attachShadow({mode:"open"});get importInput(){return this.shadow.getElementById("import")}messages;said=new L(["en"]);language="en";localeToken=0;current;options=[];group="summary";base;text;fileEditor;fileEditorLoading;shownFor;ready=Promise.resolve();player;drawn;takenOut=new Map;constructor(){super(),this.shadow.innerHTML=K,customElements.upgrade(this.shadow),this.importInput.build();for(const e of["title","time","by","url","summary","witness","medium"])this.shadow.getElementById(e).addEventListener(e==="witness"||e==="medium"?"change":"input",()=>this.write(e));for(const e of this.shadow.querySelectorAll("#tabs .group-tab"))e.addEventListener("click",()=>this.openGroup(m.GROUPS[e.getAttribute("aria-controls")]??"summary"));this.shadow.getElementById("url").addEventListener("change",()=>{this.shownFor=void 0,this.text===void 0&&this.group==="file"&&this.showTranscript()}),this.importInput.addEventListener("filepick",e=>{const t=e.detail;t.file?this.importFromFile(t.file):this.importFromUrl(t.url)}),this.shadow.getElementById("save").addEventListener("click",()=>this.save()),this.shadow.getElementById("redact-selection").addEventListener("click",()=>void this.redactSelection()),this.shadow.getElementById("exchanges").addEventListener("click",e=>{const t=e.target.closest(".bar[data-restorable]");t&&this.restore(t.dataset.restorable)})}static GROUPS={"group-summary":"summary","group-exchanges":"exchanges","group-transcript":"file"};static get observedAttributes(){return["readonly"]}attributeChangedCallback(){this.applyReadonly()}connectedCallback(){this.ready=this.loadLocale()}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.releaseFileEditor()})}releaseFileEditor(){this.fileEditor&&(this.text=this.fileEditor.text,this.fileEditor.destroy(),this.fileEditor=void 0,this.fileEditorLoading=void 0,this.shownFor=void 0)}get event(){return this.current}set event(e){e!==this.current&&(this.shownFor=void 0),this.current=e,this.render(),this.takenOut.clear(),this.group==="file"&&this.showTranscript(),queueMicrotask(()=>{this.current===e&&this.showExchanges()})}set witnesses(e){this.options=e,this.render()}set documentUrl(e){this.base=e}get transcriptText(){return this.text}set transcriptText(e){this.text=e,this.shownFor=void 0}field(e){return this.shadow.getElementById(e)}async loadLocale(){const e=++this.localeToken,t=M.preferencesFor(this),r=P(t,j),s=await H.load(r);e===this.localeToken&&(this.language=r,this.said=new L(t),this.messages=s,this.player||(this.player=new q(this.shadow.getElementById("player"),{timeChanged:i=>this.markCurrentTurn(i),recordingsChanged:i=>void this.editTranscript(a=>{i.length===0?delete a.recordings:a.recordings=i})},s),this.render()),this.render())}applyReadonly(){const e=this.hasAttribute("readonly");for(const t of["title","time","by","url","summary"])this.field(t).readOnly=e;for(const t of this.shadow.querySelectorAll("#witness input"))t.disabled=e;this.field("medium").disabled=e,this.importInput.disabled=e}static byText(e){return(e??[]).map(t=>"people"in t?t.people:"org"in t?t.org:t.title??"").filter(t=>t!=="").join(", ")}render(){const e=this.messages;if(!e)return;const t=(o,d)=>{this.shadow.getElementById(o).textContent=d};t("label-summary-group",e.summaryTab),t("label-file-group",e.fileTab),t("label-exchanges-group",e.exchangesTab),t("label-title",e.title),t("label-witness",e.witness),t("label-medium",e.medium),t("label-time",e.time),t("label-by",e.by),t("label-summary",e.summary),t("label-url",e.transcript),I.say(this.shadow.getElementById("label-import-file"),e.importFile,e.importFileHint),t("redact-selection",e.redactSelection),this.player?.setMessages(e),this.importInput.messages=e,t("save",e.saveButton),this.field("url").title=e.transcriptHint,this.field("by").title=e.byHint;const r=this.current,s=this.shadow.activeElement,i=(o,d)=>{this.field(o)!==s&&(this.field(o).value=d)};i("title",this.said.read(r?.title)??""),i("time",r?.time??""),i("by",m.byText(r?.by)),i("url",r?.url??""),i("summary",this.said.read(r?.summary)??"");const a=[r?.interviewOf].flat().filter(o=>typeof o=="string"),n=this.shadow.getElementById("witness"),l=[...this.options,...a.filter(o=>!this.options.some(d=>d.id===o)).map(o=>({id:o,label:o}))];n.replaceChildren(n.querySelector("legend"),...l.map(o=>{const d=document.createElement("label"),h=document.createElement("input");return h.type="checkbox",h.value=o.id,h.checked=a.includes(o.id),d.append(h,o.label),d}));const c=this.shadow.getElementById("medium");if(c.replaceChildren(...A.ALL.map(o=>new Option(A.label(o,this.language),o))),r?.medium!==void 0&&!A.ALL.includes(r.medium)&&c.append(new Option(String(r.medium),String(r.medium))),r?.medium===void 0){const o=new Option(e.witnessNone,"");o.disabled=!0,o.hidden=!0,c.prepend(o)}c.value=r?.medium??"",this.applyReadonly()}write(e){const t=this.current;if(!t)return;const r=e==="witness"?"":this.field(e).value;switch(e){case"title":{const s=this.said.write(t.title,r,this.language);s===void 0?delete t.title:t.title=s;break}case"summary":{const s=this.said.write(t.summary,r,this.language);s===void 0?delete t.summary:t.summary=s;break}case"time":r.trim()===""?delete t.time:t.time=r.trim();break;case"url":r.trim()===""?delete t.url:t.url=r.trim();break;case"by":{const s=r.split(",").map(i=>i.trim()).filter(i=>i!=="");s.length===0?delete t.by:t.by=s.map(i=>({people:i}));break}case"witness":{const s=[...this.shadow.querySelectorAll("#witness input:checked")].map(i=>i.value);if(s.length===0){this.render();return}t.interviewOf=s.length===1?s[0]:s;break}case"medium":r===""?delete t.medium:t.medium=r;break}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:e,event:t}})),e==="medium"&&this.render(),e!=="url"&&this.syncFileFromEvent()}openGroup(e){this.group=e;const t={summary:"group-summary",exchanges:"group-exchanges",file:"group-transcript"};for(const r of this.shadow.querySelectorAll("#tabs .group-tab"))r.setAttribute("aria-expanded",String(r.getAttribute("aria-controls")===t[e]));for(const[r,s]of Object.entries(t))this.shadow.getElementById(s).hidden=r!==e;e==="file"&&this.showTranscript(),e==="exchanges"&&this.showExchanges()}exchangesToken=0;async transcriptJson(e){try{const t=this.fileEditor?.text??this.text;if(t!==void 0)return g.read(JSON.parse(t));const r=this.transcriptUrl(e);if(r!==void 0)return g.read(await T.json(r))}catch{}}async showExchanges(){const e=this.current;if(!e)return;const t=++this.exchangesToken,r=await this.transcriptJson(e);await this.ready,!(t!==this.exchangesToken||this.current!==e)&&this.drawExchanges(r)}drawExchanges(e){const t=this.shadow.getElementById("exchanges");t.documentUrl=this.current?this.transcriptUrl(this.current):void 0,t.interview=e,this.drawn=e,this.player?.show(e,this.current?this.transcriptUrl(this.current):void 0),this.renderReview(e),this.decorateExchanges(e)}async editTranscript(e){const t=this.current;if(!t||this.hasAttribute("readonly"))return;const r=await this.transcriptJson(t)??JSON.parse(this.template(t));Array.isArray(r.segments)||(r.segments=[]),e(r);const s=m.pretty(m.withEventFields(r,t));this.fileEditor?.replaceText(s,!1),this.onEdited(s)}get redactReason(){return this.said.write(void 0,this.messages.redactReason,this.language)??this.messages.redactReason}speakerLabel(e,t){const r=g.speakerName(e,t),s=e.speakers?.[t]?.role;return r===s&&s in this.messages.roles?this.messages.roles[s]:r}renderReview(e){const t=this.shadow.getElementById("review"),r=Object.keys(e?.speakers??{});if(t.hidden=!e||r.length===0,!e||r.length===0)return;const s=l=>["approved","covered"].includes(e.proofreading?.[l]?.status??""),i=r.filter(l=>!s(l)),a=document.createElement("span");a.textContent=i.length===0?this.messages.proofreadAll:this.messages.proofreadPending.replace("{names}",i.map(l=>this.speakerLabel(e,l)).join(", ")),t.toggleAttribute("data-done",i.length===0);const n=document.createElement("span");n.className="review-boxes";for(const l of r){const c=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=s(l),o.disabled=this.hasAttribute("readonly"),o.addEventListener("change",()=>void this.editTranscript(d=>{d.proofreading??={},o.checked?d.proofreading[l]={status:"approved",date:new Date().toISOString().slice(0,10)}:d.proofreading[l]={status:"pending"}})),c.append(o,this.messages.reviewedBy.replace("{name}",this.speakerLabel(e,l))),n.append(c)}t.replaceChildren(a,n)}momentsOf(e,t){const r=e.speakers?.[t]?.of??g.sightingsOf(e)[0];return this.options.find(s=>s.id===r)?.moments??this.options.flatMap(s=>s.moments??[])}decorateExchanges(e){if(!e)return;const t=this.messages,r=this.hasAttribute("readonly");for(const s of this.shadow.querySelectorAll("#exchanges .turn[data-segment]")){const i=Number(s.dataset.segment),a=e.segments[i];if(!a)continue;if(a.start!==void 0){const c=document.createElement("button");c.type="button",c.className="turn-time",c.textContent=g.clock(a.start),c.addEventListener("click",()=>this.player?.seek(a.start)),s.prepend(c)}const n=a.redacted?[a.redacted]:f.partsOf(a).flatMap(c=>"redacted"in c?[c.redacted]:[]);s.querySelectorAll(".bar").forEach((c,o)=>{const d=n[o]?.words;c.textContent=d!==void 0?t.redactedWords.replace("{n}",String(d)):t.redacted,c.classList.add("redacted-label");const h=a.redacted?`${i}:all`:`${i}:${o}`;this.takenOut.has(h)&&(c.dataset.restorable=h)});const l=this.momentsOf(e,a.speaker);s.querySelectorAll(".ref").forEach((c,o)=>{const d=a.refs?.[o];if(!d)return;const h=l.find(p=>Math.abs(p.at-d.at)<.05);if(h){const p=document.createElement("span");p.className="moment-letter",p.textContent=h.label.slice(0,2),c.replaceChildren(p,t.momentLabel.replace("{k}",h.label).replace("{text}",h.note??g.clock(d.at)))}if(r)return;const u=document.createElement("button");u.type="button",u.className="ref-unlink",u.textContent="×",u.title=t.unlinkMoment,u.setAttribute("aria-label",t.unlinkMoment),u.addEventListener("click",()=>void this.editTranscript(p=>{p.segments[i].refs?.splice(o,1),p.segments[i].refs?.length===0&&delete p.segments[i].refs})),c.after(u)}),r||s.append(this.turnTools(e,i,a,l))}}turnTools(e,t,r,s){const i=this.messages,a=document.createElement("div");a.className="turn-tools";const n=(o,d)=>{const h=document.createElement("button");return h.type="button",h.textContent=o,h.addEventListener("click",d),h};if(e.speakers?.[r.speaker]?.role==="witness"&&!r.redacted){const o=n(i.linkMoment,()=>{});a.append(o),new B(o,`moment-menu-${t}`,h=>void this.editTranscript(u=>{const p=u.segments[t].refs??[];p.some(b=>Math.abs(b.at-Number(h))<.05)||p.push({at:Number(h)}),u.segments[t].refs=p}),h=>`moment-${t}-${h}`).setKinds(s.length>0?s.map(h=>({value:String(h.at),label:i.momentLabel.replace("{k}",h.label).replace("{text}",h.note??g.clock(h.at))})):[{value:"",label:i.noMoments,disabledReason:i.noMoments}])}r.redacted||a.append(n(i.editTurn,()=>this.editTurn(t)));const l=this.takenOut.has(`${t}:all`)||[...this.takenOut.keys()].some(o=>o.startsWith(`${t}:`));if(r.redacted||r.parts&&l){const o=n(i.restoreAll,()=>void this.restoreAll(t));o.disabled=!l,a.append(o)}else a.append(n(i.redactAll,()=>void this.editTranscript(o=>{this.forget(t),this.takenOut.set(`${t}:all`,f.redactWhole(o.segments[t],this.redactReason))})));const c=n("",()=>void this.editTranscript(o=>{o.segments.splice(t,1),this.shiftTakenOut(t)}));return c.className="icon-btn",c.innerHTML=y.TRASH,c.title=i.deleteTurn,c.setAttribute("aria-label",i.deleteTurn),a.append(c),a}async redactSelection(){const e=this.messages,t=this.shadow.getElementById("redact-note"),r=(h,u=!1)=>{t.textContent=h,t.classList.toggle("error",u)},s=this.shadow.getSelection?.()??document.getSelection(),i=s&&s.rangeCount>0?s.getRangeAt(0):void 0;if(!i||i.collapsed){r(e.selectionNone);return}const a=h=>h instanceof Element?h:h.parentElement,n=a(i.startContainer)?.closest(".said");if(!n||a(i.endContainer)?.closest(".said")!==n||a(i.startContainer)?.closest(".bar")||a(i.endContainer)?.closest(".bar")){r(e.selectionOnePassage,!0);return}const l=Number(n.closest(".turn").dataset.segment),c=m.offsetIn(n,i.startContainer,i.startOffset),o=m.offsetIn(n,i.endContainer,i.endOffset);let d=!1;await this.editTranscript(h=>{const u=f.redact(h.segments[l],Math.min(c,o),Math.max(c,o),this.redactReason);u&&(d=!0,this.shiftParts(l,u.nth),this.takenOut.set(`${l}:${u.nth}`,u.text))}),s?.removeAllRanges(),r(d?"":e.selectionOnePassage,!d)}static offsetIn(e,t,r){let s=0;const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:a=>a.parentElement?.closest(".bar")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let a=i.nextNode();a;a=i.nextNode()){if(a===t)return s+r;if(t.contains(a)&&t!==a){const l=[...t.childNodes].slice(0,r);return s+l.reduce((c,o)=>c+(o instanceof Element&&o.closest(".bar")?0:(o.textContent??"").length),0)}s+=(a.textContent??"").length}return s}async restore(e){const t=this.takenOut.get(e);if(t===void 0)return;const[r,s]=e.split(":"),i=Number(r);await this.editTranscript(a=>{s==="all"?f.restoreWhole(a.segments[i],t):(f.restorePart(a.segments[i],Number(s),t),this.shiftParts(i,Number(s),-1)),this.takenOut.delete(e)})}async restoreAll(e){if(this.takenOut.has(`${e}:all`)){await this.restore(`${e}:all`);return}const t=[...this.takenOut.keys()].filter(r=>r.startsWith(`${e}:`)).map(r=>Number(r.split(":")[1])).sort((r,s)=>s-r);for(const r of t)await this.restore(`${e}:${r}`)}editTurn(e){const r=this.drawn?.segments[e],s=this.shadow.querySelector(`#exchanges .turn[data-segment="${e}"] .said`);if(!r||!s)return;const i=this.messages,a=document.createElement("div");a.className="turn-edit";const n=document.createElement("textarea");n.value=f.raw(r,h=>this.takenOut.get(`${e}:${h}`));const l=document.createElement("span");l.className="hint",l.textContent=i.turnEditHint;const c=document.createElement("div");c.className="buttons";const o=document.createElement("button");o.type="button",o.className="pill-btn primary",o.textContent=i.saveTurn,o.addEventListener("click",()=>void this.editTranscript(h=>{const u=f.fromRaw(h.segments[e],n.value,this.redactReason);this.forget(e);for(const[p,b]of u)this.takenOut.set(`${e}:${p}`,b)}));const d=document.createElement("button");d.type="button",d.className="pill-btn",d.textContent=i.cancelTurn,d.addEventListener("click",()=>this.drawExchanges(this.drawn)),c.append(o,d),a.append(n,l,c),s.replaceWith(a),n.focus()}forget(e){for(const t of[...this.takenOut.keys()])t.startsWith(`${e}:`)&&this.takenOut.delete(t)}shiftParts(e,t,r=1){const s=[...this.takenOut].filter(([i])=>i.startsWith(`${e}:`)&&i!==`${e}:all`&&Number(i.split(":")[1])>=t+(r<0?1:0));for(const[i]of s)this.takenOut.delete(i);for(const[i,a]of s)this.takenOut.set(`${e}:${Number(i.split(":")[1])+r}`,a)}shiftTakenOut(e){const t=[...this.takenOut];this.takenOut.clear();for(const[r,s]of t){const[i,a]=r.split(":"),n=Number(i);n<e?this.takenOut.set(r,s):n>e&&this.takenOut.set(`${n-1}:${a}`,s)}}markCurrentTurn(e){const t=this.drawn?.segments??[];let r=-1;t.forEach((a,n)=>{a.start!==void 0&&a.start<=e&&(r=n)});for(const a of this.shadow.querySelectorAll("#exchanges .turn.current"))a.classList.remove("current");const s=this.shadow.querySelector(`#exchanges .turn[data-segment="${r}"]`);if(!s)return;s.classList.add("current");const i=s.closest(".rr0-interview-turns");i&&(s.offsetTop<i.scrollTop||s.offsetTop>i.scrollTop+i.clientHeight-s.offsetHeight)&&i.scrollTo({top:s.offsetTop-i.clientHeight/3,behavior:"smooth"})}async revealSegment(e){this.openGroup("exchanges"),await this.showExchanges(),this.shadow.getElementById("exchanges").revealSegment(e)}note(e,t="info"){U.show(this.shadow.getElementById("file-note"),e,t)}transcriptUrl(e){return e.url?new URL(e.url,this.base??location.href).href:void 0}static pretty(e){return JSON.stringify(e,null,2)+`
|
|
231
|
-
`}static SHARED=["title","time","medium","by","interviewOf","summary"];static ORDER=["version","id","language","title","time","medium","by","interviewOf","summary","speakers","transcription","proofreading","anonymization","recordings","segments"];static ordered(e){const t={};for(const
|
|
233
|
+
`;class m extends HTMLElement{shadow=this.attachShadow({mode:"open"});get importInput(){return this.shadow.getElementById("import")}messages;said=new S(["en"]);language="en";localeToken=0;current;options=[];group="summary";base;text;fileEditor;fileEditorLoading;shownFor;ready=Promise.resolve();player;drawn;takenOut=new Map;constructor(){super(),this.shadow.innerHTML=K,customElements.upgrade(this.shadow),this.importInput.build();for(const e of["title","time","by","url","summary","witness","medium"])this.shadow.getElementById(e).addEventListener(e==="witness"||e==="medium"?"change":"input",()=>this.write(e));for(const e of this.shadow.querySelectorAll("#tabs .group-tab"))e.addEventListener("click",()=>this.openGroup(m.GROUPS[e.getAttribute("aria-controls")]??"summary"));this.shadow.getElementById("url").addEventListener("change",()=>{this.shownFor=void 0,this.text===void 0&&this.group==="file"&&this.showTranscript()}),this.importInput.addEventListener("filepick",e=>{const t=e.detail;t.file?this.importFromFile(t.file):this.importFromUrl(t.url)}),this.shadow.getElementById("save").addEventListener("click",()=>this.save()),this.shadow.getElementById("redact-selection").addEventListener("click",()=>void this.redactSelection()),this.shadow.getElementById("exchanges").addEventListener("click",e=>{const t=e.target.closest(".bar[data-restorable]");t&&this.restore(t.dataset.restorable)})}static GROUPS={"group-summary":"summary","group-exchanges":"exchanges","group-transcript":"file"};static get observedAttributes(){return["readonly"]}attributeChangedCallback(){this.applyReadonly()}connectedCallback(){this.ready=this.loadLocale()}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.releaseFileEditor()})}releaseFileEditor(){this.fileEditor&&(this.text=this.fileEditor.text,this.fileEditor.destroy(),this.fileEditor=void 0,this.fileEditorLoading=void 0,this.shownFor=void 0)}get event(){return this.current}set event(e){e!==this.current&&(this.shownFor=void 0),this.current=e,this.render(),this.takenOut.clear(),this.group==="file"&&this.showTranscript(),queueMicrotask(()=>{this.current===e&&this.showExchanges()})}set witnesses(e){this.options=e,this.render()}set documentUrl(e){this.base=e}get transcriptText(){return this.text}set transcriptText(e){this.text=e,this.shownFor=void 0}field(e){return this.shadow.getElementById(e)}async loadLocale(){const e=++this.localeToken,t=M.preferencesFor(this),s=j(t,I),r=await P.load(s);e===this.localeToken&&(this.language=s,this.said=new S(t),this.messages=r,this.player||(this.player=new U(this.shadow.getElementById("player"),{timeChanged:i=>this.markCurrentTurn(i),recordingsChanged:i=>void this.editTranscript(a=>{i.length===0?delete a.recordings:a.recordings=i})},r),this.render()),this.render())}applyReadonly(){const e=this.hasAttribute("readonly");for(const t of["title","time","by","url","summary"])this.field(t).readOnly=e;for(const t of this.shadow.querySelectorAll("#witness input"))t.disabled=e;this.field("medium").disabled=e,this.importInput.disabled=e}static byText(e){return(e??[]).map(t=>"people"in t?t.people:"org"in t?t.org:t.title??"").filter(t=>t!=="").join(", ")}render(){const e=this.messages;if(!e)return;const t=(o,d)=>{this.shadow.getElementById(o).textContent=d};t("label-summary-group",e.summaryTab),t("label-file-group",e.fileTab),t("label-exchanges-group",e.exchangesTab),t("label-title",e.title),t("label-witness",e.witness),t("label-medium",e.medium),t("label-time",e.time),t("label-by",e.by),t("label-summary",e.summary),t("label-url",e.transcript),H.say(this.shadow.getElementById("label-import-file"),e.importFile,e.importFileHint),t("redact-selection",e.redactSelection),this.player?.setMessages(e),this.importInput.messages=e,t("save",e.saveButton),this.field("url").title=e.transcriptHint,this.field("by").title=e.byHint;const s=this.current,r=this.shadow.activeElement,i=(o,d)=>{this.field(o)!==r&&(this.field(o).value=d)};i("title",this.said.read(s?.title)??""),i("time",s?.time??""),i("by",m.byText(s?.by)),i("url",s?.url??""),i("summary",this.said.read(s?.summary)??"");const a=[s?.interviewOf].flat().filter(o=>typeof o=="string"),n=this.shadow.getElementById("witness"),l=[...this.options,...a.filter(o=>!this.options.some(d=>d.id===o)).map(o=>({id:o,label:o}))];n.replaceChildren(n.querySelector("legend"),...l.map(o=>{const d=document.createElement("label"),h=document.createElement("input");return h.type="checkbox",h.value=o.id,h.checked=a.includes(o.id),d.append(h,o.label),d}));const c=this.shadow.getElementById("medium");if(c.replaceChildren(...A.ALL.map(o=>new Option(A.label(o,this.language),o))),s?.medium!==void 0&&!A.ALL.includes(s.medium)&&c.append(new Option(String(s.medium),String(s.medium))),s?.medium===void 0){const o=new Option(e.witnessNone,"");o.disabled=!0,o.hidden=!0,c.prepend(o)}c.value=s?.medium??"",this.applyReadonly()}write(e){const t=this.current;if(!t)return;const s=e==="witness"?"":this.field(e).value;switch(e){case"title":{const r=this.said.write(t.title,s,this.language);r===void 0?delete t.title:t.title=r;break}case"summary":{const r=this.said.write(t.summary,s,this.language);r===void 0?delete t.summary:t.summary=r;break}case"time":s.trim()===""?delete t.time:t.time=s.trim();break;case"url":s.trim()===""?delete t.url:t.url=s.trim();break;case"by":{const r=s.split(",").map(i=>i.trim()).filter(i=>i!=="");r.length===0?delete t.by:t.by=r.map(i=>({people:i}));break}case"witness":{const r=[...this.shadow.querySelectorAll("#witness input:checked")].map(i=>i.value);if(r.length===0){this.render();return}t.interviewOf=r.length===1?r[0]:r;break}case"medium":s===""?delete t.medium:t.medium=s;break}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:e,event:t}})),e==="medium"&&this.render(),e!=="url"&&this.syncFileFromEvent()}openGroup(e){this.group=e;const t={summary:"group-summary",exchanges:"group-exchanges",file:"group-transcript"};for(const s of this.shadow.querySelectorAll("#tabs .group-tab"))s.setAttribute("aria-expanded",String(s.getAttribute("aria-controls")===t[e]));for(const[s,r]of Object.entries(t))this.shadow.getElementById(r).hidden=s!==e;e==="file"&&this.showTranscript(),e==="exchanges"&&this.showExchanges()}exchangesToken=0;async transcriptJson(e){try{const t=this.fileEditor?.text??this.text;if(t!==void 0)return f.read(JSON.parse(t));const s=this.transcriptUrl(e);if(s!==void 0)return f.read(await T.json(s))}catch{}}async showExchanges(){const e=this.current;if(!e)return;const t=++this.exchangesToken,s=await this.transcriptJson(e);await this.ready,!(t!==this.exchangesToken||this.current!==e)&&this.drawExchanges(s)}drawExchanges(e){const t=this.shadow.getElementById("exchanges");t.documentUrl=this.current?this.transcriptUrl(this.current):void 0,t.interview=e,this.drawn=e,this.player?.show(e,this.current?this.transcriptUrl(this.current):void 0),this.renderReview(e),this.decorateExchanges(e)}async editTranscript(e){const t=this.current;if(!t||this.hasAttribute("readonly"))return;const s=await this.transcriptJson(t)??JSON.parse(this.template(t));Array.isArray(s.segments)||(s.segments=[]),e(s);const r=m.pretty(m.withEventFields(s,t));this.fileEditor?.replaceText(r,!1),this.onEdited(r)}get redactReason(){return this.said.write(void 0,this.messages.redactReason,this.language)??this.messages.redactReason}speakerLabel(e,t){const s=f.speakerName(e,t),r=e.speakers?.[t]?.role;return s===r&&r in this.messages.roles?this.messages.roles[r]:s}renderReview(e){const t=this.shadow.getElementById("review"),s=Object.keys(e?.speakers??{});if(t.hidden=!e||s.length===0,!e||s.length===0)return;const r=l=>["approved","covered"].includes(e.proofreading?.[l]?.status??""),i=s.filter(l=>!r(l)),a=document.createElement("span");a.textContent=i.length===0?this.messages.proofreadAll:this.messages.proofreadPending.replace("{names}",i.map(l=>this.speakerLabel(e,l)).join(", ")),t.toggleAttribute("data-done",i.length===0);const n=document.createElement("span");n.className="review-boxes";for(const l of s){const c=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=r(l),o.disabled=this.hasAttribute("readonly"),o.addEventListener("change",()=>void this.editTranscript(d=>{d.proofreading??={},o.checked?d.proofreading[l]={status:"approved",date:new Date().toISOString().slice(0,10)}:d.proofreading[l]={status:"pending"}})),c.append(o,this.messages.reviewedBy.replace("{name}",this.speakerLabel(e,l))),n.append(c)}t.replaceChildren(a,n)}momentsOf(e,t){const s=e.speakers?.[t]?.of??f.sightingsOf(e)[0];return this.options.find(r=>r.id===s)?.moments??this.options.flatMap(r=>r.moments??[])}decorateExchanges(e){if(!e)return;const t=this.messages,s=this.hasAttribute("readonly");for(const r of this.shadow.querySelectorAll("#exchanges .turn[data-segment]")){const i=Number(r.dataset.segment),a=e.segments[i];if(!a)continue;if(a.start!==void 0){const c=document.createElement("button");c.type="button",c.className="turn-time",c.textContent=f.clock(a.start),c.addEventListener("click",()=>this.player?.seek(a.start)),r.prepend(c)}const n=a.redacted?[a.redacted]:g.partsOf(a).flatMap(c=>"redacted"in c?[c.redacted]:[]);r.querySelectorAll(".bar").forEach((c,o)=>{const d=n[o]?.words;c.textContent=d!==void 0?t.redactedWords.replace("{n}",String(d)):t.redacted,c.classList.add("redacted-label");const h=a.redacted?`${i}:all`:`${i}:${o}`;this.takenOut.has(h)&&(c.dataset.restorable=h)});const l=this.momentsOf(e,a.speaker);r.querySelectorAll(".ref").forEach((c,o)=>{const d=a.refs?.[o];if(!d)return;const h=l.find(p=>Math.abs(p.at-d.at)<.05);if(h){const p=document.createElement("span");p.className="moment-letter",p.textContent=h.label.slice(0,2),c.replaceChildren(p,t.momentLabel.replace("{k}",h.label).replace("{text}",h.note??f.clock(d.at)))}if(s)return;const u=document.createElement("button");u.type="button",u.className="ref-unlink",u.textContent="×",u.title=t.unlinkMoment,u.setAttribute("aria-label",t.unlinkMoment),u.addEventListener("click",()=>void this.editTranscript(p=>{p.segments[i].refs?.splice(o,1),p.segments[i].refs?.length===0&&delete p.segments[i].refs})),c.after(u)}),s||r.append(this.turnTools(e,i,a,l))}}turnTools(e,t,s,r){const i=this.messages,a=document.createElement("div");a.className="turn-tools";const n=(o,d)=>{const h=document.createElement("button");return h.type="button",h.textContent=o,h.addEventListener("click",d),h};if(e.speakers?.[s.speaker]?.role==="witness"&&!s.redacted){const o=n(i.linkMoment,()=>{});a.append(o),new B(o,`moment-menu-${t}`,h=>void this.editTranscript(u=>{const p=u.segments[t].refs??[];p.some(b=>Math.abs(b.at-Number(h))<.05)||p.push({at:Number(h)}),u.segments[t].refs=p}),h=>`moment-${t}-${h}`).setKinds(r.length>0?r.map(h=>({value:String(h.at),label:i.momentLabel.replace("{k}",h.label).replace("{text}",h.note??f.clock(h.at))})):[{value:"",label:i.noMoments,disabledReason:i.noMoments}])}s.redacted||a.append(n(i.editTurn,()=>this.editTurn(t)));const l=this.takenOut.has(`${t}:all`)||[...this.takenOut.keys()].some(o=>o.startsWith(`${t}:`));if(s.redacted||s.parts&&l){const o=n(i.restoreAll,()=>void this.restoreAll(t));o.disabled=!l,a.append(o)}else a.append(n(i.redactAll,()=>void this.editTranscript(o=>{this.forget(t),this.takenOut.set(`${t}:all`,g.redactWhole(o.segments[t],this.redactReason))})));const c=n("",()=>void this.editTranscript(o=>{o.segments.splice(t,1),this.shiftTakenOut(t)}));return c.className="icon-btn",c.innerHTML=y.TRASH,c.title=i.deleteTurn,c.setAttribute("aria-label",i.deleteTurn),a.append(c),a}async redactSelection(){const e=this.messages,t=this.shadow.getElementById("redact-note"),s=(h,u=!1)=>{t.textContent=h,t.classList.toggle("error",u)},r=this.shadow.getSelection?.()??document.getSelection(),i=r&&r.rangeCount>0?r.getRangeAt(0):void 0;if(!i||i.collapsed){s(e.selectionNone);return}const a=h=>h instanceof Element?h:h.parentElement,n=a(i.startContainer)?.closest(".said");if(!n||a(i.endContainer)?.closest(".said")!==n||a(i.startContainer)?.closest(".bar")||a(i.endContainer)?.closest(".bar")){s(e.selectionOnePassage,!0);return}const l=Number(n.closest(".turn").dataset.segment),c=m.offsetIn(n,i.startContainer,i.startOffset),o=m.offsetIn(n,i.endContainer,i.endOffset);let d=!1;await this.editTranscript(h=>{const u=g.redact(h.segments[l],Math.min(c,o),Math.max(c,o),this.redactReason);u&&(d=!0,this.shiftParts(l,u.nth),this.takenOut.set(`${l}:${u.nth}`,u.text))}),r?.removeAllRanges(),s(d?"":e.selectionOnePassage,!d)}static offsetIn(e,t,s){let r=0;const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:a=>a.parentElement?.closest(".bar")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let a=i.nextNode();a;a=i.nextNode()){if(a===t)return r+s;if(t.contains(a)&&t!==a){const l=[...t.childNodes].slice(0,s);return r+l.reduce((c,o)=>c+(o instanceof Element&&o.closest(".bar")?0:(o.textContent??"").length),0)}r+=(a.textContent??"").length}return r}async restore(e){const t=this.takenOut.get(e);if(t===void 0)return;const[s,r]=e.split(":"),i=Number(s);await this.editTranscript(a=>{r==="all"?g.restoreWhole(a.segments[i],t):(g.restorePart(a.segments[i],Number(r),t),this.shiftParts(i,Number(r),-1)),this.takenOut.delete(e)})}async restoreAll(e){if(this.takenOut.has(`${e}:all`)){await this.restore(`${e}:all`);return}const t=[...this.takenOut.keys()].filter(s=>s.startsWith(`${e}:`)).map(s=>Number(s.split(":")[1])).sort((s,r)=>r-s);for(const s of t)await this.restore(`${e}:${s}`)}editTurn(e){const s=this.drawn?.segments[e],r=this.shadow.querySelector(`#exchanges .turn[data-segment="${e}"] .said`);if(!s||!r)return;const i=this.messages,a=document.createElement("div");a.className="turn-edit";const n=document.createElement("textarea");n.value=g.raw(s,h=>this.takenOut.get(`${e}:${h}`));const l=document.createElement("span");l.className="hint",l.textContent=i.turnEditHint;const c=document.createElement("div");c.className="buttons";const o=document.createElement("button");o.type="button",o.className="pill-btn primary",o.textContent=i.saveTurn,o.addEventListener("click",()=>void this.editTranscript(h=>{const u=g.fromRaw(h.segments[e],n.value,this.redactReason);this.forget(e);for(const[p,b]of u)this.takenOut.set(`${e}:${p}`,b)}));const d=document.createElement("button");d.type="button",d.className="pill-btn",d.textContent=i.cancelTurn,d.addEventListener("click",()=>this.drawExchanges(this.drawn)),c.append(o,d),a.append(n,l,c),r.replaceWith(a),n.focus()}forget(e){for(const t of[...this.takenOut.keys()])t.startsWith(`${e}:`)&&this.takenOut.delete(t)}shiftParts(e,t,s=1){const r=[...this.takenOut].filter(([i])=>i.startsWith(`${e}:`)&&i!==`${e}:all`&&Number(i.split(":")[1])>=t+(s<0?1:0));for(const[i]of r)this.takenOut.delete(i);for(const[i,a]of r)this.takenOut.set(`${e}:${Number(i.split(":")[1])+s}`,a)}shiftTakenOut(e){const t=[...this.takenOut];this.takenOut.clear();for(const[s,r]of t){const[i,a]=s.split(":"),n=Number(i);n<e?this.takenOut.set(s,r):n>e&&this.takenOut.set(`${n-1}:${a}`,r)}}markCurrentTurn(e){const t=this.drawn?.segments??[];let s=-1;t.forEach((a,n)=>{a.start!==void 0&&a.start<=e&&(s=n)});for(const a of this.shadow.querySelectorAll("#exchanges .turn.current"))a.classList.remove("current");const r=this.shadow.querySelector(`#exchanges .turn[data-segment="${s}"]`);if(!r)return;r.classList.add("current");const i=r.closest(".rr0-interview-turns");i&&(r.offsetTop<i.scrollTop||r.offsetTop>i.scrollTop+i.clientHeight-r.offsetHeight)&&i.scrollTo({top:r.offsetTop-i.clientHeight/3,behavior:"smooth"})}async revealSegment(e){this.openGroup("exchanges"),await this.showExchanges(),this.shadow.getElementById("exchanges").revealSegment(e)}note(e,t="info"){q.show(this.shadow.getElementById("file-note"),e,t)}transcriptUrl(e){return e.url?new URL(e.url,this.base??location.href).href:void 0}static pretty(e){return JSON.stringify(e,null,2)+`
|
|
234
|
+
`}static SHARED=["title","time","medium","by","interviewOf","summary"];static ORDER=["version","id","language","title","time","medium","by","interviewOf","summary","speakers","transcription","proofreading","anonymization","recordings","segments"];static ordered(e){const t={};for(const s of m.ORDER)s in e&&(t[s]=e[s]);for(const s of Object.keys(e))s in t||(t[s]=e[s]);return t}static witnessesOf(e){return[e].flat().filter(t=>typeof t=="string")}static withEventFields(e,t){const s={...e};for(const i of m.SHARED)t[i]===void 0?delete s[i]:s[i]=structuredClone(t[i]);const r=s.speakers;if(typeof r=="object"&&r!==null){const i={...r},a=(n,l,c)=>{c.forEach((o,d)=>{const h=d===0?n:`${n}${d+1}`;i[h]?i[h]={...i[h],[l]:o}:d>0&&(i[h]={role:n,[l]:o})})};a("interviewer","by",t.by??[]),a("witness","of",m.witnessesOf(t.interviewOf)),s.speakers=i}return m.ordered(s)}applyFileToEvent(e,t){const s=this.current;if(!s)return!1;const r=JSON.stringify(m.SHARED.map(n=>s[n])),i=n=>typeof n=="string"||typeof n=="object"&&n!==null&&!Array.isArray(n),a={title:i,summary:i,time:n=>typeof n=="string",medium:n=>typeof n=="string",by:n=>Array.isArray(n),interviewOf:n=>typeof n=="string"||Array.isArray(n)};for(const n of m.SHARED){const l=e[n];l!==void 0&&a[n](l)?s[n]=structuredClone(l):t&&delete s[n]}return JSON.stringify(m.SHARED.map(n=>s[n]))!==r}syncFileFromEvent(){const e=this.current,t=this.fileEditor?.text??this.text;if(!e||t===void 0)return;let s;try{s=JSON.parse(t)}catch{return}if(typeof s!="object"||s===null||Array.isArray(s))return;const r=m.pretty(m.withEventFields(s,e));r!==t&&(this.text=r,this.fileEditor?.replaceText(r,!1),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:e,text:r}})))}template(e){return m.pretty(m.withEventFields({version:1,language:this.language,speakers:{interviewer:{role:"interviewer"},witness:{role:"witness"}},segments:[]},e))}loadFileEditor(e){return this.fileEditorLoading??=(async()=>{try{const[{SightingFileEditor:t},{default:s},r]=await Promise.all([C(()=>import("./SightingFileEditor-CASP3L_i.js"),__vite__mapDeps([0,1,2]),import.meta.url),C(()=>import("./interviewSchema-Dk0AWHwc.js"),[],import.meta.url),V(this.language)]);return this.fileEditor=new t(this.shadow.getElementById("file-editor"),e,i=>this.onEdited(i),this.messages.editorLabel,{baseline:e,phrases:r.fileSearchPhrases,schema:s}),this.fileEditor}catch(t){throw this.fileEditorLoading=void 0,t}})(),this.fileEditorLoading}async showTranscript(){const e=this.current;if(!e||this.shownFor===e)return;this.note(this.messages.loading);let t=this.text;if(t===void 0){const s=this.transcriptUrl(e);if(s!==void 0)try{const r=await T.json(s);this.current===e&&typeof r=="object"&&r!==null&&!Array.isArray(r)?(this.applyFileToEvent(r,!1)&&this.fileChangedEvent(),t=m.pretty(m.withEventFields(r,e))):t=m.pretty(r)}catch{this.note(this.messages.loadFailed,"error")}t??=this.template(e)}if(this.current===e)try{const s=await this.loadFileEditor(t);if(this.current!==e)return;s.replaceText(t,!1),this.shownFor=e,this.text!==void 0||this.transcriptUrl(e)===void 0?this.note(void 0):this.shadow.getElementById("file-note").textContent===this.messages.loading&&this.note(void 0)}catch{this.note(this.messages.loadFailed,"error")}}onEdited(e){this.text=e;let t,s=!0;try{t=JSON.parse(e)}catch{s=!1}this.note(s?void 0:this.messages.invalid,"error");const r=this.current;if(s&&r&&typeof t=="object"&&t!==null&&!Array.isArray(t)&&this.applyFileToEvent(t,!0)&&this.fileChangedEvent(),r&&!r.url&&e.trim()!==""){const i=r.id??"1";r.url=`${i.startsWith("interview")?i:`interview-${i}`}.json`,this.field("url").value=r.url,this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"url",event:r}}))}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:r,text:e}})),this.showExchanges()}fileChangedEvent(){this.render(),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"file",event:this.current}}))}async take(e){if(typeof e!="object"||e===null||!Array.isArray(e.segments)){this.note(this.messages.notATranscript,"error");return}const t=this.current;t&&this.applyFileToEvent(e,!1)&&this.fileChangedEvent();const s=m.pretty(t?m.withEventFields(e,t):e);await this.loadFileEditor(s).then(r=>r.replaceText(s,!1),()=>{}),this.shownFor=this.current,this.note(void 0),this.onEdited(s)}async importFromFile(e){try{const t=await e.text();let s;try{s=JSON.parse(t)}catch{s=void 0}if(typeof s!="object"||s===null){const{InterviewImport:r}=await C(async()=>{const{InterviewImport:l}=await import("./interviewImport-C-TiARLK.js");return{InterviewImport:l}},[],import.meta.url),i=this.current,a=[i?.interviewOf].flat().filter(l=>typeof l=="string"),n=r.parse(t,{by:(i?.by??[]).map(l=>m.byText([l])).filter(l=>l!==""),witnesses:this.options.filter(l=>a.length===0||a.includes(l.id))});s=n&&{...n,transcription:{note:`Imported from ${e.name}: who speaks and when are as the file gave them, to be checked.`}}}s===void 0?this.note(this.messages.notATranscript,"error"):await this.take(s)}catch{this.note(this.messages.loadFailed,"error")}}async importFromUrl(e){try{await this.take(await T.json(new URL(e,this.base??location.href).href))}catch{this.note(this.messages.loadFailed,"error")}}save(){const e=this.fileEditor?.text??this.text;if(e===void 0)return;const t=(this.current?.url??"").split("/").pop()||`${this.current?.id??"interview"}.json`,s=URL.createObjectURL(new Blob([e],{type:"application/json"})),r=document.createElement("a");r.href=s,r.download=t,r.click(),URL.revokeObjectURL(s)}}function ee(){Y(),D(),customElements.get(F)||customElements.define(F,m)}export{E as INTERVIEW_CHANGE_EVENT,F as INTERVIEW_EDITOR_ELEMENT_NAME,W as INTERVIEW_SEEK_EVENT,m as InterviewEditorElement,ee as register};
|