const WIG_W=308,WIG_H=240,PAD_L=28,PAD_R=8,PAD_T=8,PAD_B=18,RA_WAVE={base:3,a:3,c:1,x:1.5,v:2};function buildWiggersCurves(e,n=e.HR){const l={LA:new Array(200),LV:new Array(200),AO:new Array(200),VOL:new Array(200),ECG:new Array(200),RA:new Array(200)},y=e.EDV,C=e.ESV,O=y-C,N=e.pv,j=e.ao,s=e.la,t=PHASE_BOUNDS,u=60/n,W=e.murmur&&e.murmur.kind,P=W==="AR",B=!!j.tardus,D=N.edP,I=N.peakP,V=N.endSysP,T=N.minP,c=D-.6*s.a,F=P?.85:.6,z=T+(c-T)*F,h=j.dia,A=j.sys,E=Math.min(V,A-10),Q=E+(P?-8:2),R=t[5],X=t[2],Y=1-R+X,w=g=>{const _=(g>=R?g-R:g+1-R)/Y;return h+(Q-h)*Math.pow(1-Math.min(1,_),1.3)},K=h+(A-h)*.55,q=.12*O,o=W==="MR"?q:0,M=P?q:0,f=atrialKickFraction(e)*O,v=y-o,m=C+M,L=m+(y-f-m)*.85,Z=ecgTiming(e,n);for(let g=0;g<200;g++){const _=g/200,i=getPhaseIndex(_),b=getPhaseLocal(_),a=cosEase(b);let k,J,U,H;if(i===2?U=B?h+(K-h)*a:h+(A-h)*a:i===3?B?U=b<.6?K+(A-K)*Math.sin(Math.PI/2*b/.6):A-(A-E)*cosEase((b-.6)/.4):U=A-(A-E)*a:i===4?U=E-(P?1:3)*Math.sin(Math.PI*b)+(Q-E)*b:U=w(_),i===0?k=c+(D-c)*a:i===1?k=D+(h+1-D)*a:i===2?k=h+1+(I-h-1)*a:i===3?k=I-(I-V)*Math.pow(a,.8):i===4?k=V-(V-T)*a:i===5?k=T+(z-T)*a:k=z+(c-z)*a,i===0)J=s.base+s.a*Math.sin(Math.PI*b);else if(i===1)J=s.base+2*Math.sin(Math.PI*b);else if(i<=4){const G=(_-t[2])/(t[5]-t[2]);J=s.base+s.v*Math.pow(G,1.5)-2*Math.sin(Math.PI*G)*(1-G)}else i===5?J=s.base+s.v-(s.v+1)*a:J=s.base-1+a;const S=RA_WAVE;let $;if(i===0)$=S.base+S.a*Math.sin(Math.PI*b);else if(i===1)$=S.base+S.c*Math.sin(Math.PI*b);else if(i<=4){const G=(_-t[2])/(t[5]-t[2]);$=S.base+S.v*Math.pow(G,1.5)-S.x*Math.sin(Math.PI*G)*(1-G)}else i===5?$=S.base+S.v-(S.v+1)*a:$=S.base-1+a;l.RA[g]=$,i===0?H=y-f+f*a:i===1?H=y-o*a:i===2||i===3?H=v-(v-C)*ejectionFraction(_):i===4?H=C+M*a:i===5?H=m+(L-m)*a:H=L+(y-f-L)*b,l.LA[g]=J,l.LV[g]=k,l.AO[g]=U,l.VOL[g]=H,l.ECG[g]=ecgValue(_,Z)}return l.aoMin=Math.min(...l.AO),l.aoMax=Math.max(...l.AO),l.raMin=Math.min(...l.RA),l.raMax=Math.max(...l.RA),l}function drawWiggers(e,n,r,l,y,C,O="zh"){const N=308*n,j=240*n;e.clearRect(0,0,N,j);const s=28*n,t=300*n,u=8*n,W=222*n,P=t-s,B=W-u,D=B*.5,I=B*.27,V=B*.2,T=u,c=T+D+4*n,F=c+I+4*n;for(let o=0;o<7;o++){const M=s+PHASE_BOUNDS[o]*P,f=s+PHASE_BOUNDS[o+1]*P,v=PHASES[o],m=getPhaseIndex(l)===o,L=C===o;e.fillStyle=v.color,e.globalAlpha=m?.32:L?.22:.1,e.fillRect(M,u,f-M,B),e.globalAlpha=1,e.fillStyle=m?"#16293F":"rgba(34,49,63,0.55)",e.font=`${10*n}px "JetBrains Mono",ui-monospace,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace`,e.textAlign="center",e.fillText((o+1).toString(),(M+f)/2,u+11*n)}e.strokeStyle="rgba(34,49,63,0.10)",e.lineWidth=1*n,e.beginPath(),e.moveTo(s,c),e.lineTo(t,c),e.moveTo(s,F),e.lineTo(t,F),e.stroke();const z=200,h=0,A=o=>T+D-(o-h)/(z-h)*(D-14*n)-2*n;e.fillStyle="rgba(34,49,63,0.55)",e.font=`${9*n}px "JetBrains Mono",ui-monospace,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace`,e.textAlign="right",e.fillText("mmHg",s-4*n,T+12*n),e.strokeStyle="rgba(34,49,63,0.10)",e.beginPath();for(const o of[80,160])e.moveTo(s,A(o)),e.lineTo(t,A(o));e.stroke(),e.fillStyle="rgba(34,49,63,0.45)";for(const o of[80,160])e.fillText(String(o),s-4*n,A(o)+3*n);const E=(o,M,f=1.5)=>{e.strokeStyle=M,e.lineWidth=f*n,e.beginPath();for(let v=0;v<o.length;v++){const m=s+v/(o.length-1)*P,L=A(o[v]);v===0?e.moveTo(m,L):e.lineTo(m,L)}e.stroke()};E(r.AO,"#A23B36",1.6),E(r.LV,"#1E3A5F",1.6),E(r.LA,"#3E6B6E",1.3);const Q=y.EDV+30,R=Math.max(20,y.ESV-30),X=o=>c+I-(o-R)/(Q-R)*(I-6*n)-2*n;e.strokeStyle="#8E8A83",e.lineWidth=1.4*n,e.beginPath();for(let o=0;o<r.VOL.length;o++){const M=s+o/(r.VOL.length-1)*P,f=X(r.VOL[o]);o===0?e.moveTo(M,f):e.lineTo(M,f)}e.stroke(),e.fillStyle="rgba(34,49,63,0.55)",e.textAlign="right",e.fillText(O==="en"?"Vol":"\u5BB9\u79EF",s-4*n,c+10*n);let Y=1.2,w=-.5;for(const o of r.ECG)o>Y&&(Y=o),o<w&&(w=o);Y+=.1,w-=.1;const K=o=>F+V-(o-w)/(Y-w)*(V-4*n)-2*n;e.strokeStyle="#4A7C59",e.lineWidth=1.3*n,e.beginPath();for(let o=0;o<r.ECG.length;o++){const M=s+o/(r.ECG.length-1)*P,f=K(r.ECG[o]);o===0?e.moveTo(M,f):e.lineTo(M,f)}e.stroke(),e.fillStyle="rgba(34,49,63,0.55)",e.textAlign="right",e.fillText(O==="en"?"ECG":"\u5FC3\u7535\u56FE",s-4*n,F+10*n);const q=s+l*P;e.strokeStyle="#B8860B",e.lineWidth=1.5*n,e.shadowColor="#B8860B",e.shadowBlur=6*n,e.beginPath(),e.moveTo(q,u),e.lineTo(q,W),e.stroke(),e.shadowBlur=0,e.fillStyle="rgba(34,49,63,0.45)",e.font=`${8.5*n}px "JetBrains Mono",ui-monospace,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace`,e.textAlign="center",e.fillText("0",s,W+12*n),e.fillText("1",t,W+12*n),e.fillText(O==="en"?"cycle fraction":"\u5468\u671F\u76F8\u4F4D",(s+t)/2,W+12*n)}Object.assign(window,{WIG_W:308,WIG_H:240,PAD_L:28,PAD_R:8,PAD_T:8,PAD_B:18,buildWiggersCurves,drawWiggers});
