@fretfall/player 0.4.0 → 0.4.2
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/highway.js +1 -1
- package/package.json +1 -1
package/highway.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lap as Ve}from"./perf.js";import{noteName as Qn}from"./music.js";const Ae=900,_o=84,to=28,eo=2.2,Ho=.9,Fo=2.4,No=a=>_o*(a.drawDistance??1)/(to*(a.noteSpeed??1)),Yo=.34,de=24,vn=1.2,qo=1.25,zo=1.25,gn=5,Pn=1,Go=1.6,Uo=2,pn=.19,no=.12,oo=3,Xo=11,jo=[{time:-1/0,endTime:1/0,fret:1,width:4}],En=[3,5,7,9,12,15,17,19,21,24],Bn=.15,io=.31,so=1.7,ao=1.4,lo=1,ro=1.2,Ko=18,ho=(a,s,h,n,e)=>{const[r,x,d,t]=[Math.min(a,s),Math.max(a,s),Math.min(h,n),Math.max(h,n)],F=Math.min(e,(x-r)/2,(t-d)/2),X=(_t,z,Et)=>{const G=Array.from({length:5},(Ht,yt)=>[_t+Math.cos(Et+yt*Math.PI/8)*F,z+Math.sin(Et+yt*Math.PI/8)*F]);return[G[0],...G,G[4]]};return[...X(x-F,t-F,0),...X(r+F,t-F,Math.PI/2),...X(r+F,d+F,Math.PI),...X(x-F,d+F,1.5*Math.PI)]},Jo=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([s,h])=>[s,-h])],Vo={inline:{label:"6 in line",outline:[[0,1],[.42,1.05],[.73,1.3],[1.01,1.53],[1.46,1.45],[2.73,1.08],[4.38,.62],[5.79,.17],[6.54,-.13],[6.88,-.35],[7.03,-.88],[6.98,-1.56],[6.64,-2.11],[6.14,-2.38],[5.59,-2.34],[5.21,-2.05],[4.99,-1.66],[4.75,-1.39],[4.25,-1.3],[3.5,-1.39],[2.6,-1.6],[1.85,-1.81],[1.18,-1.75],[.83,-1.36],[.47,-1.06],[0,-1]],posts:{from:[1.56,.95],to:[6.01,-.58]},keys:"machine",tree:2.47},fourTwo:{label:"4 + 2",outline:[[0,1],[.48,1.03],[.94,1.35],[1.21,1.72],[1.52,1.72],[2.99,1.31],[4.23,.95],[5.53,.57],[5.92,.28],[6.07,-.36],[6.05,-1.03],[5.79,-1.53],[5.36,-1.67],[4.95,-1.53],[4.68,-1.29],[4.36,-1.19],[4.02,-1.32],[3.67,-1.56],[2.99,-1.67],[2.08,-1.6],[1.4,-1.43],[.94,-1.16],[.48,-1.03],[0,-1]],posts:{from:[1.81,1.08],to:[4.94,-.03],treble:{share:1/3,from:[2.33,-1.03],to:[3.38,-.69]}},keys:"machine"},openBook:{label:"3 + 3 open book",outline:Jo([[0,1],[.48,1.07],[.96,1.33],[1.47,1.53],[3.16,1.67],[4.98,1.76],[6.25,1.8],[6.25,1.8],[6.42,.93],[6.3,0]]),posts:{from:[2.5,1.07],to:[5.1,1.07],treble:{share:1/2}},keys:"tulip",cover:[[.22,0],[.22,.4],[.36,.5],[.78,.4],[1.3,.25],[1.82,.16],[2.13,.1],[2.24,0],[2.13,-.1],[1.82,-.16],[1.3,-.25],[.78,-.4],[.36,-.5],[.22,-.4],[.22,0]],screws:[[.43,0],[1.98,0]]},pointed:{label:"3 + 3 pointed",outline:[[0,1],[.36,1.12],[.75,1.47],[1.07,1.84],[1.38,1.93],[2.29,1.73],[3.26,1.55],[4.36,1.35],[5.45,1.12],[5.75,.95],[5.86,.43],[5.98,-.22],[6.29,-.75],[6.75,-1.22],[6.75,-1.22],[6.17,-1.24],[5.33,-1.3],[4.36,-1.37],[3.26,-1.55],[2.29,-1.73],[1.38,-1.93],[1.07,-1.84],[.75,-1.47],[.36,-1.12],[0,-1]],posts:{from:[2.07,1],to:[4.65,.46],treble:{share:1/2}},keys:"machine",cover:[[.1,.44],[.1,.44],[.59,.4],[1.1,.28],[1.69,0],[1.69,0],[1.1,-.28],[.59,-.4],[.1,-.44],[.1,-.44],[.1,.44]],screws:[]},headless:{label:"Headless",outline:ho(.2,.95,-1.06,1.06,.2),clamps:.58}};function Zo(a,s){const h=s.length,n=mo(a.outline,10);let e=s.map(t=>[a.clamps,t]),r=s.map(()=>1);if(a.posts){const{from:t,to:F,treble:X}=a.posts,_t=X?Math.floor(h*X.share+1e-9):0,z=h-_t,Et=(V,v,pt)=>Mt=>V.map((K,N)=>K+(v[N]-K)*Mt/Math.max(1,pt-1)),G=([V,v])=>[V,-v],Ht=Et(t,F,z),yt=Et(X?.from??G(t),X?.to??G(F),_t);e=s.map((V,v)=>v<z?Ht(v):yt(h-1-v)),r=s.map((V,v)=>v<z?1:-1)}const x=(t,F)=>{let X=null;for(let _t=1;_t<n.length;_t++){const[z,Et]=n[_t-1],[G,Ht]=n[_t];if((z-t)*(G-t)>0||z===G)continue;const yt=Et+(Ht-Et)*(t-z)/(G-z);(X===null||yt*F>X*F)&&(X=yt)}return X??F},d=a.keys?e.map(([t],F)=>({u:t,side:r[F],edge:x(t,r[F])})):[];return{outline:n,ends:e,keys:d}}const fo=new WeakMap,yn=new Map,Qo=(a,s)=>{const h=s.join(),n=fo.get(a);if(n?.key===h)return n.parts;const e=Zo(a,s);return fo.set(a,{key:h,parts:e}),e},co=(a,s)=>(yn.has(a)||(yn.size>500&&yn.clear(),yn.set(a,s())),yn.get(a)),mo=(a,s=8)=>[...a.slice(0,-1).flatMap((h,n)=>{const e=a[Math.max(0,n-1)],r=a[n+1],x=a[Math.min(a.length-1,n+2)];return h[0]===r[0]&&h[1]===r[1]?[h]:Array.from({length:s},(d,t)=>{const F=t/s;return[0,1].map(X=>.5*(2*h[X]+(r[X]-e[X])*F+(2*e[X]-5*h[X]+4*r[X]-x[X])*F*F+(3*h[X]-e[X]-3*r[X]+x[X])*F**3))})}),a.at(-1)],Tn=(a,s)=>{if(!a.startsWith("#"))return a;const h=n=>{const e=parseInt(a.slice(n,n+2),16);return Math.round(s>0?e+(255-e)*s:e*(1+s)).toString(16).padStart(2,"0")};return`#${h(1)}${h(3)}${h(5)}`},wn=new Map,H=(a,s)=>{if(!a.startsWith("#"))return a;const h=a+s;let n=wn.get(h);return n||(wn.size>1e3&&wn.clear(),wn.set(h,n=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${s})`)),n},se=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<s?h=e+1:n=e}return h};function uo(a){if(a.links?.next.length===a.notes.length)return a.links;const s=a.notes.length,h=new Array(s).fill(-1),n=new Array(s).fill(-1),e={};let r=0;for(let x=0;x<s;x++){const{string:d,sustain:t}=a.notes[x];e[d]!==void 0&&([n[x],h[e[d]]]=[e[d],x]),e[d]=x,r=Math.max(r,t)}return a.links={next:h,prev:n,held:r}}const ee=a=>Math.round(a*4)/4,We=32,An=new Map;let go=0;const Kt=(a,s,h)=>{let n=An.get(s);n||An.set(s,n=new Map);let e=n.get(h);if(!e){++go>5e3&&([go,n]=[0,new Map],An.clear(),An.set(s,n)),a.font=s;const r=a.measureText(h);n.set(h,e={width:r.width,middle:(r.actualBoundingBoxAscent-r.actualBoundingBoxDescent)/2,top:r.actualBoundingBoxAscent})}return e},Wn=128,_n=new WeakMap,ti=a=>{if(!_n.has(a)){const s=new OffscreenCanvas(1,Wn),h=s.getContext("2d"),[n,e]=[a.floor0,a.floor1].map(x=>[1,3,5].map(d=>parseInt(x.slice(d,d+2),16))),r=Array.from({length:Wn},(x,d)=>{const t=(d+.5)/Wn;return`rgba(${n.map((F,X)=>Math.round(F+(e[X]-F)*t))}, ${1-t})`});r.forEach((x,d)=>{h.fillStyle=x,h.fillRect(0,Wn-1-d,1,1)}),_n.set(a,{strip:s,near:r[0]})}return _n.get(a)},xn=new Map,po=new WeakMap,xo=(a,s,h)=>{let n=po.get(a);n||po.set(a,n=new Map);let e=n.get(s);if(!e){e=a.createLinearGradient(0,0,0,1);for(const[r,x]of h)e.addColorStop(r,x);n.set(s,e)}return e},$n=new Map,Mo=(a,s,h,n,e)=>{const r=`${s}|${h}|${n}|${e}`;let x=$n.get(r);return x||($n.size>20&&$n.clear(),x=a.createLinearGradient(0,s,0,h),x.addColorStop(0,n),x.addColorStop(1,e),$n.set(r,x)),x},In=(a,s)=>[a[0]-s[0],a[1]-s[1],a[2]-s[2]],Dn=(a,s)=>a[0]*s[0]+a[1]*s[1]+a[2]*s[2],ei=(a,s)=>[a[1]*s[2]-a[2]*s[1],a[2]*s[0]-a[0]*s[2],a[0]*s[1]-a[1]*s[0]],ni=a=>a.map(s=>s/Math.hypot(...a)),oi=(a,s)=>{let h=0;for(const n of a??[]){if(n.time>s)break;h=n.fret}return h},ii=.15,bo=new WeakMap,Hn=a=>{let s=bo.get(a);if(!s){s=[];for(const h of a){const n=s[s.length-1];n&&h.endTime-h.time<ii?n.endTime=h.endTime:s.push({...h})}bo.set(a,s)}return s},kn=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<=s?h=e+1:n=e}return a[Math.max(0,h-1)]},yo=a=>a*a*(3-2*a),si=.3,To=new WeakMap;function ko(a,s){let h=To.get(a);if(h||To.set(a,h={}),!(s in h)){const n=Math.max(a.sustain,.05),r=(a[s]??(s==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([x,d])=>[x*n,d,!1])??[];r.length&&r[0][0]>.001&&(r[0][2]=!0,r.unshift([0,0,!1])),h[s]=r.length?r:null}return h[s]}function So(a,s){if(!a)return 0;let h=a[0][1];for(let n=1;n<a.length&&s>a[n-1][0];n++){const[[e,r],[x,d,t]]=[a[n-1],a[n]],F=Math.min(x-e,si)||1e-6;h=r+(d-r)*yo(Math.min(1,Math.max(0,(s-(t?x-F:e))/F)))}return h}const ai=(a,s)=>So(ko(a,"bendCurve"),s),li=(a,s)=>So(ko(a,"whammy"),s),vo=new WeakMap,rn=a=>{let s=vo.get(a);return s===void 0&&vo.set(a,s=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,h])=>h))),s};function ri(a){if(a.chordSpans)return a.chordSpans;const s=[];for(const h of a.chords){const n=Math.max(h.time+.25,...h.notes.map(r=>a.notes[r].time+a.notes[r].sustain)),e=s.at(-1);e&&h.time-e.end<1&&(h.name?h.name===e.name:h.highDensity)?e.end=Math.max(e.end,n):h.name&&s.push({name:h.name,time:h.time,end:n})}for(const h of a.handShapes??[])h.arpeggio&&h.name&&s.push({name:h.name,time:h.startTime,end:h.endTime});return a.chordSpans=s.sort((h,n)=>h.time-n.time)}function hi(a){if(a.chordRails)return a.chordRails;const s=[],h=n=>Math.max(n.time+.15,...n.notes.map(e=>a.notes[e].time+a.notes[e].sustain));for(let n=0;n<a.chords.length;n++){const e=a.chords[n];if(e.highDensity)continue;let r=h(e),x=n+1;for(;a.chords[x]?.highDensity&&a.chords[x].time-r<1;x++)r=Math.max(r,h(a.chords[x]));r=Math.min(r,a.chords[x]?.time??1/0),r-e.time>.2&&s.push({time:e.time,end:r,frets:e.notes.map(d=>a.notes[d].fret)})}for(const n of a.handShapes??[])n.arpeggio&&s.push({time:n.startTime,end:n.endTime,frets:n.frets,arpeggio:n});return a.chordRails=s}const Po={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},Fn=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),wo=(a,s,h,n)=>{if(a===void 0)return s;const e=a+(s-a)*(1-Math.exp(-h/n));return Math.abs(s-e)<1e-6?s:e};function Ao(a,s,h,n,e){a[s]===void 0&&([a[s],a[s+"Speed"]]=[h,0]);const r=2/n,x=r*e,d=1/(1+x+.48*x*x+.235*x*x*x),t=a[s]-h,F=(a[s+"Speed"]+r*t)*e;a[s+"Speed"]=(a[s+"Speed"]-r*F)*d,a[s]=h+(t+F)*d,Math.abs(a[s]-h)<1e-6&&Math.abs(a[s+"Speed"])<1e-6&&([a[s],a[s+"Speed"]]=[h,0])}function Wo(a,s,h=0){let n=1/0,e=-1/0;for(const x of a)x.endTime<=s||x.time>=s+oo||(n=Math.min(n,x.fret-1),e=Math.max(e,x.fret-1+x.width));if(n===1/0){const x=kn(a,s);[n,e]=[x.fret-1,x.fret-1+x.width]}h&&(n=Math.min(n,h-1));const r=Math.max(Xo,e-n+2)+1;return{lo:n,hi:e,span:r,center:Math.min(25-r/2,Math.max(r/2-1,(n+e)/2))}}function fi(a,s,h,n,e=0){const r=Wo(s,h,e),x=a.target,d=!x||r.lo<x.center-x.span/2||r.hi>x.center+x.span/2,t=x&&x.span-Math.max(r.span,Wo(s,h+oo,e).span)>2;(d||t)&&(a.target=r);const F=Math.min(n-(a.at??n),100);a.at=n,Ao(a,"span",a.target.span,a.target.span>a.span?.8:1.4,F/1e3),Ao(a,"center",a.target.center,1,F/1e3);const X=kn(Hn(s),h);return a.left=wo(a.left,X.fret-1,F,90),a.right=wo(a.right,X.fret-1+X.width,F,90),X}function $o(a,s,h,n,e,r,x,d){a.beginPath(),a.moveTo(s-n,h-r*e),a.lineTo(s,h),a.lineTo(s+n,h-r*e),a.lineWidth=Math.max(3,e*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,e*.65),a.strokeStyle=x,a.stroke(),a.lineWidth=Math.max(.6,e*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Io(a,s,h,n,e){a.beginPath(),a.moveTo(s,h),a.lineTo(n,e),a.stroke()}function Nn(a){const s=devicePixelRatio||1,h=a.clientWidth,n=a.clientHeight;(a.width!==Math.round(h*s)||a.height!==Math.round(n*s))&&(a.width=Math.round(h*s),a.height=Math.round(n*s));const e=a.getContext("2d"),r=n/Ae,x=h/r,d=s*r;return e.setTransform(d,0,0,d,0,0),e.clearRect(0,0,x,Ae),{g:e,W:x,B:d}}function xi(a,s,h,n,e){const{g:r,W:x,B:d}=Nn(a);let t=r;if(!s)return;const F=s.anchors.length?s.anchors:jo,X=oi(s.capos,h),_t=fi(e,F,h,performance.now(),X),z=s.strings,Et=Math.min(.5,5*Yo/Math.max(1,z-1)),G=Et*zo*(n.boardHeight??1),Ht=G*(z-1),yt=o=>(n.stringOrder==="high"?o:z-1-o)*G,V=o=>(o>=z/2?1:-1)*(n.stringOrder==="high"?-1:1),v=to*(n.noteSpeed??1),pt=No(n),Mt=-.22,K=Ht+.22,N=Mt-.06,Tt=pt*v,ut=o=>Math.max(0,o)*v,It=o=>n.str[o%n.str.length],Jt=n.noteLines===0?null:`rgba(255, 255, 255, ${n.noteLines??.5})`,ne=+n.fretNumbers||0,ye=e.span,Ft=[e.center,Et*(z-1)/2,0],oe=(n.viewAngle??30)*Math.PI/180,ge=.6*Math.SQRT2*ye,Ze=[Ft[0],Ht+ge*Math.sin(oe),-ge*Math.cos(oe)],Te=ni(In([Ft[0],0,2.2*ye],Ze)),ke=ei(Te,[1,0,0]),Ne=(n.sideAngle??0)*Math.PI/180,[Se,Ye]=[Math.sin(Ne),Math.cos(Ne)],$e=In(Ze,Ft),C=Dn($e,Te),ft=Dn($e,ke),tt=[-Se,Te[1]*Ye,Te[2]*Ye],Ct=[Ye,Te[1]*Se,Te[2]*Se],Ot=[Ft[0]+ft*ke[0]+C*tt[0],Ft[1]+ft*ke[1]+C*tt[1],ft*ke[2]+C*tt[2]],ae=Math.min(x*.88,Ae*(n.fill?1.3:1.05)),Ie=ae*Dn(In(Ft,Ot),tt)/ye,le=Math.min(qo*(n.fretWidth??1),x*ye/(ae*Math.max(1,ye-2.5)));let re=0,ve=0;const[Vt,Xe,qe]=Ot,[De,hn,Le]=tt,[Ce,fn,Qe]=Ct,[pe,Zt,ze]=ke,A=(o,i,c)=>{const l=o-Vt,f=i-Xe,p=c-qe,T=Ie/Math.max(.05,l*De+f*hn+p*Le);return[x/2+(l*Ce+f*fn+p*Qe)*le*T+re,Ae/2-(l*pe+f*Zt+p*ze)*T+ve,T]},[on,Oe,qt]=A(...Ft);[re,ve]=[x/2-on,Ae*(n.fill?.83:.81)-Oe];const[,cn]=A(e.center-ye/2,N,0),[,Re]=A(e.center+ye/2,N,0),[,he]=A(e.center,N,0);ve-=Math.min(Ae*.08,Math.max(0,cn-he,Re-he)),Ve("setup");const gt=(o,i=!0)=>{t.beginPath();for(let c=0;c<o.length;c++){const[l,f]=A(o[c][0],o[c][1],o[c][2]);c?t.lineTo(l,f):t.moveTo(l,f)}i&&t.closePath()},St=(o,i)=>{gt([o,i],!1),q()},Ee=(o,i,c,l,f)=>{if(n.gem!=="pill")return gt([[o-l,i-f,c],[o+l,i-f,c],[o+l,i+f,c],[o-l,i+f,c]]);const[p,T]=A(o-l,i,c),[E,w]=A(o+l,i,c),[,O]=A(o,i+f,c),[,At]=A(o,i-f,c),rt=Math.atan2(w-T,E-p),at=Math.min(Math.abs(At-O),Math.hypot(E-p,w-T))/2,[U,nt]=[at*Math.cos(rt),at*Math.sin(rt)];t.beginPath(),t.arc(p+U,T+nt,at,rt+Math.PI/2,rt+Math.PI*1.5),t.arc(E-U,w-nt,at,rt-Math.PI/2,rt+Math.PI/2),t.closePath()},Je=(o,i)=>{const c=kn(F,i),l=o.filter(f=>f>0);return[Math.min(c.fret-1,...l.map(f=>f-1))+.05,Math.max(c.fret-1+Math.max(4,c.width),...l)-.05]},M=(o,i,c,l,f)=>{St([o-l,i-f,c],[o+l,i+f,c]),St([o-l,i+f,c],[o+l,i-f,c])},m=n.markings==="white",Y=m?"#ffffff":n.ink,P=(o,i,c,l,f,p,T,E=null)=>{const[w,O]=T?[f*.85,p*.8]:[Math.min(f,.34)*.72,p*.82];E||(t.strokeStyle=H(n.ink,T?.7:.35),t.lineWidth=T?Math.max(3.5,.1*l):Math.max(2.5,.06*l),M(o,i,c,w,O)),t.strokeStyle=E??(T?"#ffffff":H("#ffffff",.42)),t.lineWidth=Math.max(E?2:T?1.8:1.2,(T?.05:.035)*l),M(o,i,c,w,O)};let I=null,y=0;const ct=o=>{o!==I&&(t.font=I=o)},Z={},bt=(o,i,c,l,f,p)=>{const T=Z[f]??=`${f} ${We}px ${n.num}`,E=l/We;return Kt(t,T,o),ct(T),t.textAlign=p,t.setTransform(d*E,0,0,d*E,d*i,d*(c-y)),Kt(t,T,o).middle},Nt=()=>t.setTransform(d,0,0,d,0,-d*y),kt=(o,i,c)=>{t.fillStyle=o,t.setTransform(d,0,0,d*(c-i),0,d*(i-y)),t.fill(),Nt()},Yt=(o,i,c,l,f,p,T=700,E="center",w=!0,O=!1)=>{const[At,rt,at]=A(i,c,l),U=f*(O?at:Math.sqrt(at*qt));if(U<(O?1:8)||At<-60||At>x+60)return;t.textBaseline="alphabetic";const nt=bt(o,At,rt,U,T,E);w&&(t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(o,0,nt)),t.fillStyle=p,t.fillText(o,0,nt),Nt(),t.textBaseline="middle"},Gt=(o,i,c,l,f,p,T=700)=>{const[E,w]=A(i,N,c),[O,At]=A(i+l,N,c),rt=Math.hypot(O-E,At-w),at=rt>.01?Math.max(1,Ko/rt):1,[U,nt]=A(i+l*at,N,c),te=Math.hypot(U-E,nt-w);let Q=f*at,[xt,D]=A(i,N,c+Q),Rt=Math.hypot(xt-E,D-w);for(let Ge=0;Ge<3&&Rt>te*ro;Ge++)Q*=te*ro/Rt,[xt,D]=A(i,N,c+Q),Rt=Math.hypot(xt-E,D-w);const Lt=Math.abs(Math.atan2(xt-E,w-D));if(E<-60||E>x+60||Rt<lo||Lt>ao)return;const Wt=t.globalAlpha;t.globalAlpha=Wt*Math.min(1,(ao-Lt)/.2,(Rt-lo)/3)*Math.max(.45,at**-.5);const an=Z[T]??=`${T} ${We}px ${n.num}`;ct(an),t.textAlign="center",t.textBaseline="alphabetic";const{top:nn}=Kt(t,an,o);t.setTransform(d*(U-E)/We,d*(nt-w)/We,-d*(xt-E)/We,-d*(D-w)/We,d*E,d*(w-y)),t.fillStyle=p,t.fillText(o,0,nn),Nt(),t.globalAlpha=Wt,t.textBaseline="middle"},[,zt]=A(Ft[0],N,0),[,vt]=A(Ft[0],N,Tt),Dt=(o,i,c)=>{const l=`${zt}|${vt}`;(xn.span!==l||xn.size>300)&&(xn.clear(),xn.span=l);const f=`${o}|${i}|${c}`;let p=xn.get(f);return p||(p=t.createLinearGradient(0,zt,0,vt),p.addColorStop(0,H(o,i)),p.addColorStop(1,H(o,c)),xn.set(f,p)),p};let Ut=null;const B=(o,i,c=10,l=!1)=>Ut=o?{color:i,blur:c,faded:l}:null,ot=[[.6,.05],[.35,.13],[.15,.27]],st=[[.4,.3]],Bt=o=>{if(!Ut)return;const{lineWidth:i,globalAlpha:c}=t,l=o?1:Math.min(1,2*i/Ut.blur);t.save(),t.strokeStyle=Ut.faded?Dt(Ut.color,1,.1):Ut.color;for(const[f,p]of Ut.blur>4?ot:st)t.lineWidth=(o?0:i)+2*Ut.blur*f,t.globalAlpha=c*p*l,t.stroke();t.restore()},q=()=>{Bt(!1),t.stroke()},J=()=>{Bt(!0),t.fill()};t.textBaseline="middle",t.lineCap="round",t.lineJoin="round";const{strip:je,near:tn}=ti(n);let[Be,_e]=[-60,de+60];if(Ne){const o=Ft[0]+(1-Dn(In([Ft[0],N,0],Ot),tt))/tt[0];[Be,_e]=tt[0]>0?[Math.max(-60,o),de+60]:[-60,Math.min(de+60,o)]}t.save(),gt([[Be,N,0],[_e,N,0],[_e,N,Tt],[Be,N,Tt]]),t.clip(),Ne&&(t.fillStyle=tn,t.fillRect(0,zt,x,Ae-zt)),t.imageSmoothingEnabled=!1,t.drawImage(je,0,vt,x,zt-vt),t.restore();const fe=(o,i)=>{const[c,l]=A(...o),[f,p]=A(...i);t.moveTo(c,l),t.lineTo(f,p)};t.strokeStyle=Dt(n.lane,.5,.04),t.lineWidth=Ho,t.beginPath();for(let o=0;o<=de;o++)fe([o,N,0],[o,N,Tt]);q();for(const o of[!1,!0]){t.strokeStyle=o?n.measure:n.beat,t.lineWidth=o?1.6:1,t.beginPath();const i=[];for(let c=se(s.beats,h);c<s.beats.length;c++){const l=s.beats[c],f=l.time-h;if(f>pt)break;l.measure>=0===o&&(f>pt-.4?i.push(f):fe([0,N,ut(f)],[de,N,ut(f)]))}q();for(const c of i)t.globalAlpha=(pt-c)/.4,t.beginPath(),fe([0,N,ut(c)],[de,N,ut(c)]),q();t.globalAlpha=1}if(ne)for(let o=se(s.beats,h);o<s.beats.length;o++){const i=s.beats[o],c=i.time-h;if(c>pt)break;if(i.measure<0)continue;const l=kn(Hn(F),i.time),f=ut(c);t.globalAlpha=Math.min(1,(pt-c)/.4);for(const p of En)(p<l.fret||p>=l.fret+l.width)&&Gt(String(p),p-.5,f,io,so,H(n.inlay,ne))}t.globalAlpha=1,(n.guides===!1?[]:Hn(F).filter(o=>o.endTime>h&&o.time<h+pt)).forEach((o,i)=>{const c=ut(Math.max(0,o.time-h)),l=ut(Math.min(pt,o.endTime-h)),f=o.fret-1,p=f+o.width;t.fillStyle=Dt(n.anchorFill,n.anchorOpacity,.02),gt([[f,N,c],[p,N,c],[p,N,l],[f,N,l]]),J(),t.strokeStyle=Dt(n.anchorLane,.55,.04),t.lineWidth=Fo*.6;for(const T of[f,p])St([T,N,c],[T,N,l]);i&&o.time>h&&St([f,N,c],[p,N,c])});const u=new Map,g=o=>{const i=Math.round(o*100);return u.has(i)||u.set(i,{dt:o-h,texts:[],pins:[]}),u.get(i)};for(const o of s.markers??[])o.time>=h&&o.time<=h+pt&&!g(o.time).texts.includes(o.text)&&g(o.time).texts.push(o.text);for(const o of s.hairpins??[])o.time>=h&&o.time<=h+pt&&g(o.time).pins.push(o.kind);const L=Math.min(e.center-(e.span/2+.5)/le,-.5);for(const{dt:o,texts:i,pins:c}of u.values()){const[l,f,p]=A(L,N,ut(o)),T=Math.sqrt(p*qt),E=i.join(" · "),w=.25*T,O=`700 ${We}px ${n.num}`,At=.3*T/We,rt=E?Kt(t,O,E).width*At:0,at=rt+c.length*(.9*T+w);ct(O);let U=Math.max(l-.3*T,16+at);t.globalAlpha=Math.min(1,(pt-o)/.4),E&&(t.save(),t.translate(U,f),t.scale(At,At),t.textAlign="right",t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(E,0,0),t.fillStyle=n.accent,t.fillText(E,0,0),t.restore(),U-=rt+w);for(const nt of c){const te=U-.9*T,Q=.14*T,[xt,D]=nt==="cresc"?[te,U]:[U,te];for(const[Rt,Lt]of[[H(n.ink,.9),Math.max(3.5,.12*T)],[n.text,Math.max(1.5,.05*T)]])t.strokeStyle=Rt,t.lineWidth=Lt,t.beginPath(),t.moveTo(D,f-Q),t.lineTo(xt,f),t.lineTo(D,f+Q),q();U=te-w}}t.globalAlpha=1,Ve("floor");const k=[];for(let o=se(s.notes,h-uo(s).held-.3);o<s.notes.length;o++){const i=s.notes[o];if(i.time>h+pt)break;const c=Math.max(i.sustain,(i.slideTo??i.slideUnpitchTo??null)===null?0:.25,.15);i.time+c>=h-.05&&k.push(i)}const S=o=>o.chord===null||o.chord===void 0?null:s.chords[o.chord],_=o=>S(o)?.fretHandMute||n.repeatMarks==="frame"&&(o.repeat||S(o)?.highDensity),R=o=>{const i=kn(F,o.time),c=o.fret===0;return{a:i,open:c,x:c?i.fret-1+i.width/2:o.fret-.5,y:yt(o.string)}},it=(o,i,c)=>{const l=o.slideSpan??Math.max(o.sustain,.25),f=o.slideTo??o.slideUnpitchTo??null,p=Math.min(1,Math.max(0,c/l));return f===null||o.fret===0?i:i+(f-.5-i)*p*p*p*(p*(p*6-15)+10)},Pt=(o,i)=>(ai(o,i)*V(o.string)+li(o,i))*G*Pn,ht=o=>{const i=h-o.time;return i<0||o.fret===0||!(rn(o)>0)?0:Pt(o,Math.min(i,Math.max(o.sustain,.15)))},et=new Map;for(const o of k){const i=o.time-h,c=Math.max(o.sustain,.15);i>0||-i>c||o.fret===0||!(rn(o)>0)||et.set(o.string,{note:o,x:o.fret-.5,dy:ht(o)})}const xe=(o,i=0,c=!1)=>{const l=et.get(o),f=yt(o)+i,p=c?[[0,f,0]]:[en?[en[o][0],en[o][1]+i,0]:[-.6,f,0],[0,f,0]];if(!l)return gt([...p,[de+.6,f,0]],!1);gt([...p,[l.x,f+l.dy,0],[de+.6,f,0]],!1)},Pe=o=>yt(o.string)+ht(o),ce=Vo[n.headstock],we=(K-Mt)/2,mn=n.stringOrder==="high"?-1:1,ue=([o,i])=>[-o*we/le,Ht/2+i*we*mn,0],wt=o=>(yt(o)-Ht/2)*mn/we,Xt=ce&&Qo(ce,Array.from({length:z},(o,i)=>wt(i))),en=Xt?.ends.map(ue),Qt=(o,i,c=1)=>{o&&(t.fillStyle=o,J()),i&&(t.strokeStyle=i,t.lineWidth=c,q())},sn=(o,i,c)=>{const[l,f]=ue(o),[p,T]=A(l,f,0),[E]=A(l+i*we/le,f,0),[,w]=A(l,f+c*we,0);t.beginPath(),t.ellipse(p,T,Math.abs(E-p),Math.abs(w-T),0,0,Math.PI*2)},dn=(o,i,c,l,f)=>gt(co(`${o},${i},${c},${l},${f}`,()=>ho(o,i,c,l,f)).map(ue)),qn=()=>{for(const{u:c,side:l,edge:f}of Xt.keys){const p=(T,E)=>[f+l*T,f+l*E];ce.keys==="machine"?(dn(c-.15,c+.15,...p(-.12,.08),.03),Qt(H(n.text,.12),H(n.anchorLane,.35)),dn(c-.03,c+.03,...p(.06,.22),0),Qt(H(n.text,.28)),dn(c-.11,c+.11,...p(.2,.68),.1),Qt(H(n.text,.18),H(n.anchorLane,.55))):(dn(c-.035,c+.035,...p(-.05,.22),0),Qt(H(n.text,.28)),sn([c,f+l*.18],.08,.04),Qt(H(n.text,.3)),sn([c,f+l*.4],.14,.2),Qt(H(n.text,.18),H(n.anchorLane,.55)))}gt(Xt.outline.map(ue));const[,o]=A(...ue([0,1.6])),[,i]=A(...ue([0,-1.2]));if(Qt(Mo(t,o,i,n.floor0,n.ink)),t.save(),t.clip(),Qt(null,H(n.text,.07),.3*we*qt),t.restore(),B(!0,n.anchorLane,8),Qt(null,H(n.anchorLane,.6),Math.max(1.5,.03*qt)),B(!1),ce.cover){gt(co(ce.cover,()=>mo(ce.cover)).map(ue)),Qt(H(n.text,.09),H(n.text,.4));for(const c of ce.screws)sn(c,.04,.04),Qt(H(n.nut,.85))}},zn=o=>eo*(.7+.14*(z-1-o)),Ro=()=>{if(e.plate?.key!==Ln||e.plate.t!==n)return e.plate={key:Ln,t:n},qn();const o=e.plate;if(!o.image){const[i,c]=[[],[]];for(const At of[...Xt.outline,...Xt.keys.map(({u:rt,side:at,edge:U})=>[rt,U+at*.8])]){const[rt,at]=A(...ue(At));i.push(rt),c.push(at)}const l=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,f=Math.min(x,Math.max(...i)+24),p=Math.floor(Math.max(0,Math.min(...c)-24)*d)/d,T=Math.min(Ae,Math.max(...c)+24);o.image=new OffscreenCanvas(Math.max(1,Math.ceil((f-l)*d)),Math.max(1,Math.ceil((T-p)*d)));const[E,w,O]=[t,y,I];[t,y,I,o.x,o.y]=[o.image.getContext("2d"),0,null,l,p],t.setTransform(d,0,0,d,-l*d,-p*d),t.lineCap=t.lineJoin="round",qn(),[t,y,I]=[E,w,O]}t.drawImage(o.image,o.x,o.y,o.image.width/d,o.image.height/d)},Gn=()=>{t.fillStyle=n.board,gt([[0,Mt,0],[de+.6,Mt,0],[de+.6,K,0],[0,K,0]]),J(),t.fillStyle=H(n.anchorFill,.16),gt([[e.left,Mt,0],[e.right,Mt,0],[e.right,K,0],[e.left,K,0]]),J(),t.fillStyle=n.inlayDot;const o=l=>(Math.max(0,Math.ceil(l)-1)+.5)*G;t.beginPath();for(const l of En)for(const f of l%12?[o((z-1)/2)]:[o((z-1)/4),Ht-o((z-1)/4)]){const[p,T,E]=A(l-.5,f,0);t.moveTo(p+.1*E,T),t.ellipse(p,T,.1*E,.08*E,0,0,Math.PI*2)}J(),X>0&&(t.fillStyle=H(n.ink,.5),gt([[0,Mt,0],[X-Bn,Mt,0],[X-Bn,K,0],[0,K,0]]),J()),Xt&&Ro();const[,i]=A(Ft[0],K,0),[,c]=A(Ft[0],Mt,0);t.strokeStyle=Mo(t,i,c,H(n.anchorPost,.75),n.post),t.lineWidth=Math.max(1.5,.05*qt),t.beginPath();for(let l=1;l<=de;l++)fe([l,Mt-.04,0],[l,K+.04,0]);q(),t.strokeStyle=n.nut,t.lineWidth=Math.max(3,.12*qt),St([0,Mt-.06,0],[0,K+.06,0]),B(!0,n.anchorPost,12),t.strokeStyle=n.anchorPost,t.lineWidth=Math.max(3,.07*qt);for(const l of[e.left,e.right])St([l,Mt-.14,0],[l,K+.14,0]);B(!1);for(let l=0;l<z;l++){const f=zn(l);B(!0,It(l),3),t.strokeStyle=H(It(l),.9),t.lineWidth=f,xe(l),q(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=Math.max(.6,f*.3),xe(l,.012),q()}if(Xt&&(Xt.ends.forEach(([l,f],p)=>{if(ce.clamps)dn(l-.1,l+.1,f-.1,f+.1,.04),Qt(H(n.text,.22),H(n.text,.45)),sn([l,f],.05,.05),Qt(n.nut);else{sn([l,f],.17,.17),Qt(H(n.ink,.5),H(n.nut,.4)),sn([l,f],.085,.085),Qt(n.nut),sn([l,f],.03,.03),Qt(H(n.ink,.85));const[T,E,w]=A(...en[p]),[O,At]=A(0,yt(p),0),rt=Math.atan2(At-E,O-T);t.beginPath(),t.arc(T,E,.1*we*w,rt-1.3,rt+1.3),Qt(null,It(p),zn(p))}}),ce.tree)){const l=[z-2,z-1].map(f=>{const[p,T]=Xt.ends[f];return wt(f)+(T-wt(f))*ce.tree/p});dn(ce.tree-.05,ce.tree+.05,Math.min(...l)-.08,Math.max(...l)+.08,.04),Qt(H(n.nut,.7),H(n.ink,.6))}for(const l of[!1,!0])for(let f=1;f<=de;f++){const p=f>=_t.fret&&f<_t.fret+_t.width,T=En.includes(f);(p||T)===l&&Yt(String(f),f-.5,Mt-.3,0,p?.3:T?.26:.2,p?n.accent:T?n.inlay:n.numOff,l?800:500,"center",!1)}},Mn=(o,i)=>A(o,i,0).slice(0,2).map(c=>Math.round(c*d*10)).join(":"),Ln=[n.headstock,z,G,mn,x,d,Math.round(le*1e4),Mn(0,Mt),Mn(de,Mt),Mn(0,K),Mn(de,K),Mn(-4,Ht/2)].join(),Sn=!et.size&&[Ln,_t.fret,_t.width,X,Math.round(e.left*1e3),Math.round(e.right*1e3)].join();if(!Sn||e.board?.key!==Sn||e.board.t!==n)e.board=Sn&&{key:Sn,t:n},Gn();else{const o=e.board;if(!o.drawn){const i=[[0,K+.2],[de,K+.2],[0,Mt-.9],[de,Mt-.9]].map(([T,E])=>A(T,E,0)[1]);Xt&&i.push(...[...Xt.outline,...Xt.keys.map(({u:T,side:E,edge:w})=>[T,w+E*.8])].map(T=>A(...ue(T))[1]));const c=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,l=Math.min(Ae,Math.max(...i)+24),[f,p]=[Math.ceil(x*d),Math.max(1,Math.ceil((l-c)*d))];(e.boardImage?.width!==f||e.boardImage.height!==p)&&(e.boardImage=new OffscreenCanvas(f,p)),[t,y,I,o.y,o.drawn]=[e.boardImage.getContext("2d"),c,null,c,!0],t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,f,p),Nt(),t.lineCap=t.lineJoin="round",t.textBaseline="middle",Gn(),[t,y,I]=[r,0,null]}t.drawImage(e.boardImage,0,o.y,e.boardImage.width/d,e.boardImage.height/d)}Ve("board");const Un=(o,i)=>o.letRing&&-i>.25;for(const o of k){const i=o.time-h;if(i>0||-i>Math.max(o.sustain,.15)||o.mute)continue;const c=It(o.string),l=Pe(o);if(B(!Un(o,i),c,10),t.strokeStyle=c,t.lineWidth=eo+3,xe(o.string,0,!0),q(),B(!1),-i<.2){const[f,p,T]=A(R(o).x,l,0);t.save(),t.translate(f,p),t.scale(1,.4);const E=t.createRadialGradient(0,0,0,0,0,.5*T);E.addColorStop(0,H(n.flash,.8*(1+i/.2))),E.addColorStop(1,H(n.flash,0)),t.fillStyle=E,t.beginPath(),t.arc(0,0,.5*T,0,Math.PI*2),J(),t.restore()}}t.strokeStyle=n.anchorLane,t.lineWidth=2.5,B(!0,n.anchorLane,10);for(const o of s.handShapes??[]){if(o.startTime>h||o.endTime<=h||o.endTime-o.startTime<.3||!o.frets.some((l,f)=>l>=0&&f<z))continue;const[i,c]=Je(o.frets.filter((l,f)=>f<z),o.startTime);gt([[i,Mt,0],[c,Mt,0],[c,K,0],[i,K,0]]),q()}if(B(!1),X>0){const o=X-Bn;t.strokeStyle=n.nut,t.lineWidth=Math.max(4,.17*qt),St([o,Mt-.16,0],[o,K+.16,0]),t.strokeStyle=H(n.ink,.45),t.lineWidth=Math.max(1,.05*qt),St([o,Mt-.13,0],[o,K+.13,0])}Ve("strings");for(const o of k){const i=o.time-h,c=ut(i),l=S(o),{a:f,open:p,x:T,y:E}=R(o),w=it(o,T,-i);if(i<-.15||o.tied||Math.abs(A(w,E,c)[0]-x/2)>x/2+200)continue;const O=p?(f.width-.2)/2:.34;t.globalAlpha=i<0?Math.max(0,1+i/.15):Math.min(1,(pt-i)/.4),!l&&Jt&&(t.strokeStyle=Jt,t.lineWidth=2,St([w-O,N,c],[w+O,N,c])),!(p||_(o))&&(t.strokeStyle=H(It(o.string),o.repeat||l?.highDensity?.35:.75),t.lineWidth=1.5,St([w,Math.min(E,Pe(o))-.42*G,c],[w,N,c]))}t.globalAlpha=1;const Eo=(o,i,c)=>{const l=Array.from({length:13},(f,p)=>{const T=p/12;return[o[0]+(i[0]-o[0])*T,o[1]+(i[1]-o[1])*T+Math.sin(Math.PI*T)*c,o[2]+(i[2]-o[2])*T]});gt(l,!1),q()};for(const o of hi(s)){if(o.end<=h||o.time>=h+pt)continue;const[i,c]=Je(o.frets,o.time),l=o.time-h,f=ut(Math.max(l,0)),p=ut(Math.min(o.end-h,pt));t.globalAlpha=Math.min(1,(pt-Math.max(l,0))/.4),B(!o.arpeggio,n.anchorLane,10,!0),t.strokeStyle=Dt(n.anchorLane,1,.2),t.lineWidth=3.5;for(const T of[i,c])St([T,N,f],[T,N,p]);B(!1),o.arpeggio&&l>0&&(t.strokeStyle=H(n.anchorLane,.7),t.lineWidth=1.5,gt([[i,N,f],[i,K,f],[c,K,f],[c,N,f]],!1),q(),o.arpeggio.name&&f>gn&&Yt(o.arpeggio.name,i-.12,K/2,f,.34,n.text,600,"right"))}t.globalAlpha=1;const Cn=(o,i)=>{const c=R(o);return Math.abs(c.x-i)<(c.open?(c.a.width-.2)/2+.1:.45)};for(const[o,i]of k.entries()){const c=i.time-h,l=S(i),f=i.slideTo??i.slideUnpitchTo??null,{a:p,open:T,x:E,y:w}=R(i),O=It(i.string),At=ut(c),rt=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),at=(T?.12:.42)*G*(i.grace?.6:1);c>-.15&&!l?.highDensity&&!i.repeat&&(t.globalAlpha=Math.min(1,(pt-c)/.4),t.strokeStyle=O,t.lineWidth=2,t.setLineDash([4,4]),i.slideIn&&St([E+(i.slideIn==="below"?-1.4:1.4),w-at,Math.max(0,At-1)],[E+(i.slideIn==="below"?-rt:rt),w,At]),i.slideOut&&St([E+(i.slideOut==="up"?rt:-rt),w,At],[E+(i.slideOut==="up"?1.4:-1.4),w-at,At+1]),t.setLineDash([]),t.globalAlpha=1);const U=f===null?i.sustain:Math.max(i.sustain,.25),nt=f!==null||i.bend||i.bendCurve||i.whammy,te=i.tied||typeof i.tieTo=="number";if(U<=.2&&!te||c+U<=0||l&&!nt&&!te||_(i))continue;T&&f&&(t.strokeStyle=O,t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]),Eo([E,w,ut(Math.max(c,0))],[f-.5,w,ut(Math.min(c+U,pt))],G*1.5),t.setLineDash([]));let Q=null;for(let dt=o+1;dt<k.length&&k[dt].time<=i.time+U+.02;dt++){const b=k[dt];if(!(b.time<=i.time+.005)&&(S(b)||b.string===i.string||Cn(b,E))){Q=b;break}}const xt=Math.max(c,0),D=i.bend||i.bendCurve||i.whammy,Rt=f!==null&&i.slideTo===null;let Lt=Math.min(c+U,pt,Q?Q.time-h:1/0);if(Lt<=xt)continue;const Wt=dt=>{const b=dt-c,$=ut(dt),j=i.bend||i.bendCurve||i.whammy,lt=i.vibrato&&!j?Math.sin($/1.6*Math.PI*2)*G*(i.vibratoWide?.45:.25):0,$t=i.tremolo?Math.floor($/.3)%2?.05:-.05:0,Me=Pn+(Go-Pn)*yo(Math.min(1,$/Uo));return[it(i,E,b)+$t,w+lt+Pt(i,b)*Me/Pn,$]},an=Q&&Wt(Lt)[0],nn=Q&&S(Q)?.notes.find(dt=>Cn(s.notes[dt],an)),Ge=typeof nn=="number"?s.notes[nn]:Q;if(Q&&!Q.tied&&(D||Cn(Ge,an))){const dt=R(Ge),b=ut(Ge.time-h),$=dt.open?(dt.a.width-.2)/2:.34,j=A(dt.x,dt.y-(dt.open?.12:.42)*G,b)[1]+3,[lt]=A(dt.x-$,dt.y,b),[$t]=A(dt.x+$,dt.y,b),Me=He=>{const[mt,jt]=A(...Wt(He));return jt<j&&mt>Math.min(lt,$t)-2&&mt<Math.max(lt,$t)+2};if(Me(Lt)&&!Me(xt)){let He=xt,mt=Lt;for(let jt=0;jt<24;jt++)[He,mt]=Me((He+mt)/2)?[He,(He+mt)/2]:[(He+mt)/2,mt];Lt=He}if(Lt<=xt+.001)continue}const ln=f===null&&!D&&!i.vibrato&&!i.tremolo?1:Math.min(400,Math.max(12,Math.ceil((Lt-xt)*v*8))),ie=Array.from({length:ln+1},(dt,b)=>Wt(xt+(Lt-xt)*b/ln));if(T&&!l){t.fillStyle=Dt(O,i.letRing?.14:.26,.03),gt([...ie.map(([dt,b,$])=>[dt-rt,b,$]),...ie.slice().reverse().map(([dt,b,$])=>[dt+rt,b,$])]),J(),B(!i.letRing,O,6,!0),t.strokeStyle=Dt(O,.95,.3),t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]);for(const dt of[-rt,rt])gt(ie.map(([b,$,j])=>[b+dt,$,j]),!1),q();t.setLineDash([]),B(!1)}else if(i.bend||i.bendCurve||i.whammy){const dt=b=>gt([...ie.map(([$,j,lt])=>[$-b,j,lt]),...ie.slice().reverse().map(([$,j,lt])=>[$+b,j,lt])]);dt(pn),t.fillStyle=Dt(O,1,.6),J(),dt(pn*.35),t.fillStyle=Dt(Tn(O,-.22),1,.55),J(),B(!0,O,8,!0),t.strokeStyle=Dt(Tn(O,.6),1,.5),t.lineWidth=2;for(const b of[-pn,pn])gt(ie.map(([$,j,lt])=>[$+b,j,lt]),!1),q();B(!1)}else{B(!i.letRing,O,6,!0);const dt=b=>Rt?pn*Math.min(1,2*(1-b/(ie.length-1))):pn;gt([...ie.map(([b,$,j],lt)=>[b-dt(lt),$,j]),...ie.map(([b,$,j],lt)=>[b+dt(lt),$,j]).reverse()],!1),t.fillStyle=Rt?Dt(O,.9,0):Dt(O,i.letRing?.5:.9,i.letRing?.2:.45),J(),t.strokeStyle=Rt?Dt(Tn(O,.6),.85,0):Dt(Tn(O,.6),1,.5),t.lineWidth=2,t.setLineDash(i.letRing?[7,6]:[]),q(),t.setLineDash([]),B(!1)}}Ve("trails");const Xn=new Set;for(let o=k.length-1;o>=0;o--){const i=k[o],c=i.time-h,l=ut(c),f=S(i),{a:p,open:T,x:E}=R(i),w=it(i,E,-c),O=Pe(i),At=i.mute||f?.fretHandMute,rt=i.palmMute||f?.palmMute,at=It(i.string),U=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),nt=(T?.12:.42)*G*(i.grace?.6:1);if(c<-.15)continue;const te=c<0?Math.max(0,1+c/.15):Math.min(1,(pt-c)/.4);if(t.globalAlpha=te,f&&!Xn.has(i.chord)){Xn.add(i.chord);const[b,$]=Je(f.notes.map(mt=>s.notes[mt].fret),i.time),j=t.globalAlpha,lt=l<gn,$t=lt?.65:f.highDensity&&n.repeatMarks!=="frame"?.18:.5;if(gt([[b,N,l],[$,N,l],[$,K,l],[b,K,l]]),n.frames==="gradient"){const[,mt]=A(b,N,l),[,jt]=A(b,K,l),me=lt?n.anchorLane:n.anchorFill;kt(xo(t,`${me}|${$t}`,[[0,H(me,$t*.6)],[1,H(me,0)]]),mt,jt)}else t.globalAlpha=j*$t,f.highDensity||(t.fillStyle=n.chordFill,J()),t.strokeStyle=lt?n.anchorLane:n.chordBox,t.lineWidth=lt||!f.highDensity?1.5:1.2,B(lt,n.anchorLane,8),q(),B(!1);if(t.globalAlpha=j,t.strokeStyle=Jt,t.lineWidth=2,Jt&&St([b,N,l],[$,N,l]),(f.fretHandMute||f.palmMute)&&n.repeatMarks!=="hide"){const[,,mt]=A((b+$)/2,N,l),jt=(b+$)/2,me=(N+K)/2,Ue=($-b)/2*.78,be=(K-N)/2*.72;t.strokeStyle="rgba(255, 255, 255, 0.28)",t.lineWidth=Math.max(3,.28*mt),t.lineCap="round",M(jt,me,l,Ue,be),t.lineCap="butt"}if(f.accent){const mt=Math.min(.6,($-b)*.22),jt=(K-N)*.35,me=Math.min(1,A(b,K,l)[2]/A(b,K,gn)[2]);t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,3.5*me*(f.accent==="heavy"?1.4:1)),t.lineCap="square",B(!0,"#ffffff",Math.max(2,12*me)),gt([[b,K-jt,l],[b,K,l],[b+mt,K,l]],!1),q(),gt([[$-mt,K,l],[$,K,l],[$,K-jt,l]],!1),q(),B(!1),t.lineCap="round"}if(f.barre&&(!f.highDensity||n.repeatMarks==="grey")){const mt=f.barre.fret-.5;t.strokeStyle=f.highDensity?n.muted:"rgba(255, 255, 255, 0.7)",t.lineWidth=Math.max(3,.1*A(mt,Ht/2,l)[2]);const[jt,me]=[yt(f.barre.from),yt(f.barre.to)].sort((Ue,be)=>Ue-be);St([mt,jt-G*.4,l],[mt,me+G*.4,l]),Yt(f.barre.half?"½B":"B",mt,K+.12,l,.22,f.highDensity?n.muted:n.text)}if(f.strum||f.roll){const mt=b-.25,jt=yt(0)>yt(z-1)?K-.1:N+.15,me=jt>Ht/2?N+.15:K-.1,[Ue,be]=(f.strum??f.roll)==="down"?[jt,me]:[me,jt];t.strokeStyle=n.text,t.lineWidth=2,f.roll?gt(Array.from({length:17},(ui,Zn)=>[mt+Math.sin(Zn/16*Math.PI*6)*.06,Ue+(be-Ue)*Zn/16,l]),!1):gt([[mt,Ue,l],[mt,be,l]],!1),q();const un=be<Ue?.14:-.14;St([mt-.08,be+un,l],[mt,be,l]),St([mt+.08,be+un,l],[mt,be,l])}const Me=s.chords[i.chord-1],He=!Me||i.time-Me.time>1||Me.name!==f.name;l>gn&&f.name&&!f.highDensity&&He&&Yt(f.name,b-.12,K/2,l,.34,n.text,600,"right")}const[Q,xt,D]=A(w,O,l);if(Q<-200||Q>x+200||_(i)){t.globalAlpha=1;continue}const Rt=i.repeat||f?.highDensity;if(Rt){const b=l<gn;t.globalAlpha*=b?.9:.4,t.strokeStyle=at,t.lineWidth=b?2:1.5,B(b,at,8),Ee(w,O,l,U,nt),q(),B(!1),(i.palmMute&&!f?.palmMute||i.mute&&!f?.fretHandMute)&&n.repeatMarks!=="hide"&&P(w,O,l,D,T?.34:U,T?G*.3:nt,rt,n.muted),t.globalAlpha=te}else if(!i.tied){if(!T&&ne){const b=i.harmonic||i.harmonicPinch?`<${i.fret}>`:i.ghost?`(${i.fret})`:String(i.fret),$=i.grace?.7:1;Gt(b,w,l,io*$,so*$,H(at,ne))}if(i.dynamicLabel&&Yt(i.dynamicLabel,w-.6,N,l,.3,n.text,"italic 700","right"),i.ghost&&(t.globalAlpha=te*.5),n.gem==="pill")n.notes3d!==!1&&(Ee(w,O,l+no,U,nt),t.fillStyle=at,J(),t.fillStyle="rgba(255, 255, 255, 0.35)",J()),Ee(w,O,l,U,nt),t.fillStyle=at,J();else{const b=i.harmonic||i.harmonicPinch,$=no;if(!b&&n.notes3d!==!1)for(const[$t,Me]of[[[[w-U,O+nt,l],[w+U,O+nt,l],[w+U,O+nt,l+$],[w-U,O+nt,l+$]],"rgba(255, 255, 255, 0.35)"],[[[w-U,O-nt,l],[w-U,O+nt,l],[w-U,O+nt,l+$],[w-U,O-nt,l+$]],"rgba(0, 0, 0, 0.4)"],[[[w+U,O-nt,l],[w+U,O+nt,l],[w+U,O+nt,l+$],[w+U,O-nt,l+$]],"rgba(0, 0, 0, 0.4)"]])gt($t),t.fillStyle=at,J(),t.fillStyle=Me,J();B(l<gn,at,8),t.fillStyle=at,b?gt([[w,O+nt*1.3,l],[w+U*.8,O,l],[w,O-nt*1.3,l],[w-U*.8,O,l]]):Ee(w,O,l,U,nt),J(),B(!1);const[,j]=A(w,O+nt,l),[,lt]=A(w,O-nt,l);kt(xo(t,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),j,lt),t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=1,q()}if((i.palmMute&&!f?.palmMute||i.mute&&!f?.fretHandMute)&&P(w,O,l,D,T?.34:U,T?G*.3:nt,rt,T&&rt?at:null),!T&&!At&&!rt){const b=i.finger??(f?.fingers?.[i.string]>=0?f.fingers[i.string]:null),$=b!==null?b===0?"T":String(b):"";if($){const j=t.globalAlpha;t.globalAlpha=j*Math.min(1,Math.max(0,(1-c/pt)/.4)),Yt($,w,O,l-.01,G*.62,Y,700,"center",m,!0),t.globalAlpha=j}}}if(Rt&&n.repeatMarks==="hide"){t.globalAlpha=1;continue}const Lt=Rt?n.muted:n.text;if(t.globalAlpha=te*(Rt?.8:1)*Math.min(1,Math.max(0,(1-c/pt)/.15)),i.ghost){const[b]=A(w-U,O,l),[$]=A(w+U,O,l),j=nt*D*1.5;t.strokeStyle=Rt?Lt:at,t.lineWidth=Math.max(1.2,.035*D),t.beginPath(),t.arc(b+j*.35,xt,j,Math.PI*.7,Math.PI*1.3),q(),t.beginPath(),t.arc($-j*.35,xt,j,-Math.PI*.3,Math.PI*.3),q()}if(i.grace&&(t.strokeStyle=Lt,t.lineWidth=Math.max(1,.03*D),Io(t,Q-U*D*le*1.2,xt+nt*D*1.4,Q+U*D*le*1.2,xt-nt*D*1.4)),i.showString){const[b]=A(w-U,O,l),$=.12*D,j=b-$-.06*D;t.strokeStyle=t.fillStyle=Rt?Lt:at,t.lineWidth=Math.max(1,.025*D),t.beginPath(),t.arc(j,xt,$,0,Math.PI*2),q(),bt(String(z-i.string),j,xt,.15*D,700,"center"),t.fillText(String(z-i.string),0,0),Nt()}let Wt=xt-nt*D-.18*D;t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D),t.textAlign="center";const an=(b,$,j)=>{t.beginPath();for(let lt=0;lt<=20;lt++)t[lt?"lineTo":"moveTo"](Q-b+2*b*lt/20,Wt+Math.sin(lt/20*Math.PI*2*j)*$);q()},nn=(b,$,j="700")=>{$*D<2||(bt(b,Q,Wt,$*D,j,"center"),t.fillText(b,0,0),Nt(),Wt-=($+.04)*D)};let Ge=xt-nt*D;const Rn=i.tap&&!i.tapLeft;if((i.hammerOn||i.pullOff)&&!Rn&&!i.tied){const b=i.grace?.6:1,$=.34*D*le*b,j=.72*G*D*b,[lt,$t]=i.hammerOn?[xt+j/2,xt-j/2]:[xt-j/2,xt+j/2];t.beginPath(),t.moveTo(Q-$,$t),t.lineTo(Q+$,$t),t.lineTo(Q,lt),t.closePath(),t.fillStyle=Rt?Lt:"#ffffff",t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(2,.04*D),q(),J(),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}if(Rn&&!i.tied){const b=i.grace?.6:1,$=.28*D*le*b,j=.62*G*D*b,lt=Ge+.15*j,$t=lt-j;t.beginPath(),t.moveTo(Q,lt),t.lineTo(Q+$,$t),t.lineTo(Q,$t+.38*j),t.lineTo(Q-$,$t),t.closePath(),t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(3.5,.1*D),q(),t.fillStyle=Rt?H(Lt,.4):H(Tn(at,.55),.85),J(),t.strokeStyle=Rt?Lt:at,t.lineWidth=Math.max(1.8,.05*D),q(),Ge=$t,Wt=Math.min(Wt,Ge-.14*D),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}const ln=rn(i);if(ln>0){const b=i.bendCurve?.[0]?.[1]>0,$=(i.bendCurve?.length??0)>1&&i.bendCurve.at(-1)[1]<ln,j=Math.min(3,Math.max(1,Math.round(ln*2))),lt=U*D*le*.6,$t=U*D*.3,Me=$t*1.25,He=H(n.ink,.9);let mt=Ge-.04*D;const jt=be=>{for(let un=0;un<j;un++)$o(t,Q,mt-un*Me-(be>0?0:$t),lt,$t,be,Rt?Lt:at,He);mt-=j*Me+.08*D},me=V(i.string);(!b||!$)&&jt(-me),$&&jt(me);const Ue=`${b?"pre ":""}${Fn(ln)}`;t.fillStyle=Lt,bt(Ue,Q+lt+.08*D,(xt-nt*D+mt)/2,.22*D,700,"left"),t.fillText(Ue,0,0),Nt(),t.textAlign="center",Wt=Math.min(Wt,mt-.1*D)}i.staccato&&(t.beginPath(),t.arc(Q,Wt+.04*D,Math.max(1.5,.045*D),0,Math.PI*2),J(),Wt-=.16*D);const ie=!i.tied;ie&&i.accent&&(i.accent==="tenuto"||!f?.accent)&&nn({heavy:"^",tenuto:"–"}[i.accent]??">",.3);const dt=[ie&&i.tapLeft?"m.g.":"",Po[i.harmonicType]??(ie&&i.harmonicPinch?"PH":""),ie&&(i.slap?"slap":i.pop?"pop":""),ie&&i.golpe?`golpe (${i.golpe})`:"",ie&&i.rasgueado?`rasg. ${i.rasgueado}`:"",typeof i.trill=="number"?`tr ${i.trill}`:"",i.ornament??"",i.fade??"",i.whammy?"w/bar":"",i.wah==="open"?"o":i.wah==="closed"?"+":""];for(const b of dt)b&&nn(b,b.length>2?.22:.28);if(ie&&i.rightFinger&&nn(i.rightFinger,.26,"italic 700"),i.pick){const b=.09*D,$=.13*D;t.beginPath(),i.pick==="down"?[[-b,$/2],[-b,-$/2],[b,-$/2],[b,$/2]].forEach(([j,lt],$t)=>t[$t?"lineTo":"moveTo"](Q+j,Wt+lt)):[[-b,-$/2],[0,$/2],[b,-$/2]].forEach(([j,lt],$t)=>t[$t?"lineTo":"moveTo"](Q+j,Wt+lt)),q(),Wt-=.22*D}if(i.fermata&&(t.beginPath(),t.arc(Q,Wt+.06*D,.14*D,Math.PI,0),q(),t.beginPath(),t.arc(Q,Wt+.02*D,Math.max(1.5,.03*D),0,Math.PI*2),J(),Wt-=.24*D),i.tremolo){for(let b=-1;b<=1;b++)Io(t,Q-.12*D,Wt+(b*.08+.05)*D,Q+.12*D,Wt+(b*.08-.05)*D);Wt-=.3*D,an(.14*D,.04*D,1.5),Wt-=.14*D}t.globalAlpha=1}Ve("notes");const jn=new Set;for(const o of k){const i=o.time-h,c=S(o);if(!c?.barre||jn.has(c)||i>.06||i<-Math.max(o.sustain,.12))continue;jn.add(c),t.strokeStyle="rgba(255, 255, 255, 0.85)",t.lineWidth=Math.max(4,.12*qt);const[l,f]=[yt(c.barre.from),yt(c.barre.to)].sort((p,T)=>p-T);St([c.barre.fret-.5,l-G*.45,0],[c.barre.fret-.5,f+G*.45,0])}const Kn=new Set,Jn=new Set;for(const o of k){const i=o.time-h,c=S(o),l=et.get(o.string),f=o.heldFrom??null,p=i<=.06||f!==null&&h>=f-.06,T=(o.slideTo??o.slideUnpitchTo??null)!==null;if(o.mute||i>vn||i<-Math.max(o.sustain,T?.25:.12)||(c?.highDensity||f!==null)&&!p||l&&l.note!==o&&!p||p&&Kn.has(`${o.string}:${o.fret}`))continue;p&&Kn.add(`${o.string}:${o.fret}`),Jn.add(`${o.string}:${o.fret}`);const{a:E,open:w,x:O}=R(o),At=it(o,O,-i),rt=Pe(o),at=It(o.string),U=(w?(E.width-.2)/2:.32)+2/qt,nt=(w?.1:.36)*G+2/qt;if(Ee(At,rt,0,U,nt),p)B(!Un(o,i),at,14),t.fillStyle=at,J(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.7)",t.lineWidth=1.5,q();else{const Q=(1-i/vn)**2;t.globalAlpha=.35*Q,t.fillStyle=at,J(),t.globalAlpha=.25+.75*Q,t.strokeStyle=at,t.lineWidth=2.2,q()}const te=o.finger??(c?.fingers?.[o.string]>=0?c.fingers[o.string]:null);if(!w&&te!==null&&Yt(te===0?"T":String(te),At,rt,0,G*.55,p?Y:n.text,800,"center",!p||m),!w&&rn(o)>0){const Q=V(o.string),xt=o.bendCurve?.[0]?.[1]>0&&o.bendCurve.at(-1)[1]<rn(o),[D,Rt]=A(At,rt+Q*nt,0);$o(t,D,Rt-Q*(xt?.14:.05)*qt,.17*qt*le,.085*qt,(xt?1:-1)*Q,"#ffffff",H(n.ink,.9))}t.globalAlpha=1}for(const o of s.handShapes??[])!o.arpeggio||o.startTime-h>vn||o.endTime<=h||(t.globalAlpha=.3+.5*Math.min(1,1-(o.startTime-h)/vn)**2,o.frets.forEach((i,c)=>{if(i<=0||c>=z||Jn.has(`${c}:${i}`))return;const l=i-.5,f=yt(c),p=o.fingers[c];Ee(l,f,0,.32+2/qt,.36*G+2/qt),t.strokeStyle=It(c),t.lineWidth=2.2,q(),p>=0&&Yt(p===0?"T":String(p),l,f,0,G*.55,n.text,800)}),t.globalAlpha=1);Ve("targets");const Vn=ri(s),On=Vn.findLast(o=>o.time<=h&&h<o.end+.3),Bo=On?null:Vn.find(o=>o.time>h&&o.time-h<1.2),bn=On??Bo;if(bn){const[o,i]=A(e.right+.4,K+.5,0),c=Kt(t,Z[700]??=`700 ${We}px ${n.num}`,bn.name).width*52/We;t.globalAlpha=On?1:Math.max(.35,1-(bn.time-h)/1.2),t.fillStyle=n.text,bt(bn.name,Math.min(o,x-24-c),i,52,700,"left"),t.fillText(bn.name,0,0),Nt(),t.globalAlpha=1}Ve("labels")}const Do=298,ci=240,mi=64,Ke=100,Fe=24,Lo=150;function Co(a,s){if(a.tabPages?.length===s)return a.tabPages.pages;const h=a.notes.at(-1),n=Math.max(h?h.time+h.sustain:0,a.beats.at(-1)?.time??0)+.5;let e=a.beats.filter(d=>d.measure>=0).map(d=>d.time);e.length<2&&(e=Array.from({length:Math.ceil(n/s)+1},(d,t)=>t*s)),e=[Math.min(0,e[0]),...e.filter(d=>d>0),Math.max(n,e.at(-1)+.01)];const r=[];let x=e[0];for(let d=1;d<e.length;d++)e[d]-x>s&&e[d-1]>x&&r.push({start:x,end:x=e[d-1]});r.push({start:x,end:e.at(-1)});for(let d=0;d<r.length-1;d++)r[d].end=r[d+1].start;return a.tabPages={length:s,pages:r},r}const Yn=(a,s)=>a.str[s%a.str.length],Oo=110,di=15.75;function Mi(a,s,h,n,e={}){const{g:r,W:x}=Nn(a);if(!s)return;const d=s.strings,t=di*(n.boardHeight??1),F=t*(d-1),X=(n.tabMarks??"all")==="all",_t=n.paper==="light",z=_t?"#15181f":n.text,Et=_t?"#5c6472":n.muted,G=Fe+46,Ht=x-Fe-16,yt=Ht-G,V=!!n.sheetNotes,v=t*.6,pt=V&&typeof document<"u"&&!!document.fonts?.check(`${4*v}px "Noto Music"`,"𝄠"),Mt=P=>(Math.floor(P/12)-1)*7+[0,0,1,1,2,3,3,4,4,5,5,6][P%12];if(V&&!s.sheetRange){let P=38;for(const I of s.notes)P=Math.max(P,Mt((s.open?.[I.string]??40)+I.fret+12));s.sheetRange={over:Math.max(2,Math.ceil((P-38)/2)+1),under:Math.max(6,Math.floor((30-Mt((s.open?.[0]??40)+12))/2)+2.5)}}const K=V?s.sheetRange.over:0,N=V?s.sheetRange.under:0,Tt=V?v*(K+4+N):0,ut=s.lyrics?.length?t*1.3:0,It=n.tabMarks!=="notes",Jt=44+Tt,ne=t*1.3,ye=Math.max(2,t*.16),Ft=Jt+F+(V?t:ne)+ut+t*2.8,oe=V?s.keys?.findLast(P=>P.time<=h)?.fifths??0:0,ge=oe<0,Ze=`${4*v}px "Noto Music"`,Te={1:["♯",.9],"-1":["♭",.8],0:["♮",.7]},ke=V?v*(.6+2.84+.5+Math.abs(oe)*1.15+1):0,Ne=ge?[0,1,1,2,2,3,4,4,5,5,6,6]:[0,0,1,1,2,3,3,4,4,5,5,6],Se=ge?[0,-1,0,-1,0,0,-1,0,-1,0,-1,0]:[0,1,0,1,0,0,1,0,1,0,1,0],Ye=[0,0,0,0,0,0,0];for(let P=0;P<Math.abs(oe);P++)Ye[(ge?[6,2,5,1,4,0,3]:[3,0,4,1,5,2,6])[P]]=ge?-1:1;const $e=new Path2D,C=[];if(V&&!s.sheetShortest){let P=1/0;const I=s.rhythm??[];for(let y=1;y<I.length;y++)I[y].time-I[y-1].time>.001&&(P=Math.min(P,I[y].time-I[y-1].time));s.sheetShortest=P}const ft=V&&s.sheetShortest<1/0?Math.max(Oo,1.75*v/s.sheetShortest):Oo,tt=Co(s,(yt-ke)/ft),Ct=Math.max(0,tt.findLastIndex(P=>P.start<=h)),Ot=Do,ae=Ae-66,Ie=ae-Ot-22>=2*Ft?1:0;(e.sheetY===void 0||n.sheetScroll!=="manual"&&e.sheetAt!==Ct)&&(e.sheetY=Math.max(0,Ct-Ie)*Ft),e.sheetAt=Ct,e.sheetY=Math.min(Math.max(0,e.sheetY),Math.max(0,tt.length*Ft+22-(ae-Ot)));const le=Ot+22-e.sheetY,re=s.rhythm??[],ve=(d-1)/2;r.save(),r.beginPath(),r.rect(Fe,Ot,x-Fe*2,ae-Ot),r.clip();const Vt=(P,I)=>P+(n.stringOrder==="high"?d-1-I:I)*t,Xe=`700 ${ee(t*.95)}px ${n.num}`,qe=`600 ${ee(10.5)}px ${n.ui}`,De=`700 ${ee(t*.55)}px ${n.num}`,hn=`italic 600 ${ee(11.5)}px ${n.ui}`,Le=new Path2D,Ce=new Path2D,fn=new Path2D,Qe=new Path2D,pe=new Path2D,Zt=new Path2D,ze=new Path2D,A=new Path2D,on=new Path2D,Oe=`600 ${ee(9.5)}px ${n.ui}`,qt=`600 ${ee(12)}px ${n.num}`,cn=P=>P.chord===null||P.chord===void 0?null:s.chords?.[P.chord],Re=P=>P.value>=8?Math.round(Math.log2(P.value))-2:0,he=[],gt=[],St=[],Ee=[],Je=[],M={box:null,x:null},m=new Set((s.markers??[]).filter(P=>P.text.startsWith("repeat")).map(P=>Math.round(P.time*50))),Y=new Map((s.meters??[]).map(P=>[Math.round(P.time*50),P.text]));r.textAlign="center";for(let P=0;P<tt.length;P++){const I=le+P*Ft;if(I+Ft<Ot)continue;if(I>ae)break;const y=tt[P],ct=(yt-ke)/(y.end-y.start),Z=W=>G+ke+(W-y.start)*ct,bt=I+Jt,Nt=bt+F,kt=Nt+5+ne,Yt=bt-v*N,Gt=Yt-4*v,zt=W=>Yt-(W-30)*v/2,vt=V?Gt-v*K:bt;for(let W=0;W<d;W++)Le.moveTo(G,Vt(bt,W)),Le.lineTo(Ht,Vt(bt,W));if(V){for(let g=0;g<5;g++)Le.moveTo(G,Gt+g*v),Le.lineTo(Ht,Gt+g*v);Ce.moveTo(G,Gt),Ce.lineTo(G,Nt);const W=G+v*.6;C.push(["𝄠",W,Yt]);const u=ge?[34,37,33,36,32,35,31]:[38,35,39,36,33,37,34];for(let g=0;g<Math.abs(oe);g++)C.push([Te[ge?-1:1][0],W+v*(2.84+.5+g*(ge?1.05:1.15)),zt(u[g])+v*.52])}if(P===0&&s.open)for(let W=0;W<d;W++)Ee.push([Qn(s.open[W]),G-16,Vt(bt,W)+t*.32,Yn(n,W)]);for(let W=se(s.beats,y.start-.001);W<s.beats.length&&s.beats[W].time<y.end-.001;W++){const u=s.beats[W],g=Z(u.time),L=Math.round(u.time*50);if(u.measure<0){ze.moveTo(g+1.6,vt-11),ze.arc(g,vt-11,1.6,0,Math.PI*2);continue}const k=m.has(L)?fn:Ce;if(k.moveTo(g,bt),k.lineTo(g,Nt),V&&(k.moveTo(g,Gt),k.lineTo(g,Yt)),m.has(L))for(const _ of[ve-.5,ve+.5])ze.moveTo(g+8.6,Vt(bt,0)+_*t),ze.arc(g+7,Vt(bt,0)+_*t,1.6,0,Math.PI*2);he.push([qe,String(u.measure),g+1,vt-8,Et,"left"]);const S=Y.get(L)??(W===0?s.meters?.[0]?.text:null);if(S){const[_,R]=S.split("/"),it=g+12+(m.has(L)?6:0),Pt=`600 ${ee(F*.38)}px ${n.num}`;he.push([Pt,_,it,bt+F*.45,z,"center"],[Pt,R,it,bt+F*.97,z,"center"])}}let Dt=-1/0,Ut=-1/0;for(const W of s.sections??[])if(W.time>=y.start&&W.time<y.end){const u=Z(W.time)+1;he.push([hn,W.name,u,vt-34,z,"left"]),Ut=u+Kt(r,hn,W.name).width+16}for(const W of s.markers??[])if(W.time>=y.start&&W.time<y.end&&!W.text.startsWith("repeat")&&!/^\d+\/\d+$/.test(W.text)){const u=Math.max(Z(W.time)+1,Dt);he.push([qe,W.text,u,vt-21,W.text.startsWith("♩")?n.accent:z,"left"]),Dt=u+Kt(r,qe,W.text).width+10}const B=new Map,ot=new Map,st=new Set,Bt={palm:[],ring:[]};for(let W=se(s.notes,y.start-.001);W<s.notes.length&&s.notes[W].time<y.end-.001;W++){const u=s.notes[W],g=Z(u.time),L=Vt(bt,u.string),k=u.grace?.72:1,S=u.mute?"×":u.harmonic||u.harmonicPinch?`<${u.fret}>`:u.ghost?`(${u.fret})`:String(u.fret),_=st.has(W)?`(${S})`:S,R=Kt(r,Xe,_).width*k,it=g-(B.get(u.string)??-1/0)-2,Pt=Math.min(1,Math.max(.55,2*it/R)),ht=k*Pt<1?`700 ${ee(t*.95*k*Pt)}px ${n.num}`:Xe,et=Kt(r,ht,_).width;B.set(u.string,g+et/2),Qe.rect(g-et/2-2.5,L-t*.5,et+5,t);const xe=u.time<=h&&h<u.time+Math.max(u.sustain,.15);if((xe?St:Je).push([ht,_,g,L+Kt(r,ht,"5").middle,xe?Yn(n,u.string):z]),X&&Pt===1&&it>R/2+12&&!u.mute&&u.fret>0&&u.finger!==null&&u.finger!==void 0&>.push([u.finger===0?"T":String(u.finger),g+et/2+2,L+t*.45]),typeof u.tieTo=="number"&&(st.add(u.tieTo),s.notes[u.tieTo].time<y.end)){const Pe=Z(s.notes[u.tieTo].time);A.moveTo(g+et/2,L+t*.45),A.quadraticCurveTo((g+Pe)/2,L+t*1.2,Pe-et/2,L+t*.45)}if(It){const Pe=u.slideTo??u.slideUnpitchTo??null,ce=Pe!==null?Math.sign(Pe-u.fret)||1:u.slideOut==="up"?1:u.slideOut?-1:0;if(ce&&(A.moveTo(g+et/2+2,L+ce*t*.32),A.lineTo(g+et/2+t*.75,L-ce*t*.32)),u.slideIn){const wt=u.slideIn==="below"?1:-1;A.moveTo(g-et/2-t*.75,L+wt*t*.32),A.lineTo(g-et/2-2,L-wt*t*.32)}const we=ot.get(u.string);if((u.hammerOn||u.pullOff)&&we&&g-we.x<t*8&&(A.moveTo(we.x,L-t*.55),A.quadraticCurveTo((we.x+g)/2,L-t*1.5,g,L-t*.55),he.push([Oe,u.hammerOn?"H":"P",(we.x+g)/2,L-t*1.05,Et,"center"])),u.vibrato)for(let wt=g-et/2;wt<=g+et/2+1;wt+=2)A[wt===g-et/2?"moveTo":"lineTo"](wt,L-t*.62+Math.sin((wt-g)/1.6)*1.4);const mn=rn(u);if(mn>0){const wt=g+et/2+t*.6,Xt=L-t*1.25;A.moveTo(g+et/2+1,L-t*.15),A.quadraticCurveTo(wt,L-t*.5,wt,Xt),A.moveTo(wt-3,Xt+4),A.lineTo(wt,Xt),A.lineTo(wt+3,Xt+4),he.push([Oe,Fn(mn),wt,Xt-3,z,"center"])}const ue=cn(u);for(const[wt,Xt]of[["palm",u.palmMute||ue?.palmMute],["ring",u.letRing]])if(Xt){const en=Bt[wt].at(-1);en&&u.time-en.end<.8?Object.assign(en,{end:u.time,x1:g+et/2}):Bt[wt].push({x0:g-et/2,x1:g+et/2,end:u.time})}if(ue?.name&&ue.notes[0]===W){const wt=s.chords[u.chord-1];(!wt||u.time-wt.time>1||wt.name!==ue.name)&&he.push([qt,ue.name,Math.max(g-et/2,Ut),vt-34,z,"left"])}}ot.set(u.string,{x:g,y:L})}for(const[W,u]of[["palm","P.M."],["ring","let ring"]])for(const g of Bt[W]){const L=Kt(r,Oe,u).width;he.push([Oe,u,g.x0,vt-21,Et,"left"]),g.x1>g.x0+L+8&&(on.moveTo(g.x0+L+4,vt-24),on.lineTo(g.x1,vt-24),A.moveTo(g.x1,vt-27),A.lineTo(g.x1,vt-21))}if(s.lyrics?.length){let W=-1/0;for(let u=se(s.lyrics,y.start-.001);u<s.lyrics.length&&s.lyrics[u].time<y.end-.001;u++){const g=Math.max(Z(s.lyrics[u].time),W);he.push([qe,s.lyrics[u].text,g,Nt+(V?t:ne)+t*1.55,Et,"left"]),W=g+Kt(r,qe,s.lyrics[u].text).width+5}}const q=new Map;if(V){const W=[...Ye];let u=Math.max(0,se(s.beats,y.start)-1);for(let g=se(s.notes,y.start-.001);g<s.notes.length&&s.notes[g].time<y.end-.001;g++){const L=s.notes[g],k=Z(L.time),S=(s.open?.[L.string]??40)+L.fret+12,_=S%12,R=(Math.floor(S/12)-1)*7+Ne[_],it=zt(R),Pt=v*(L.grace?.35:.5);for(;s.beats[u+1]?.time<=L.time+1e-4;)s.beats[++u].measure>=0&&W.splice(0,7,...Ye);const ht=L.time<=h&&h<L.time+Math.max(L.sustain,.15);q.set(g,{x:k,y:it,r:Pt,step:R}),ht?St.push(["head",k,it,Pt,Yn(n,L.string)]):(Zt.moveTo(k+Pt,it),Zt.ellipse(k,it,Pt,Pt*.81,-.35,0,Math.PI*2));for(let et=28;et>=R;et-=2)$e.moveTo(k-v*.9,zt(et)),$e.lineTo(k+v*.9,zt(et));for(let et=40;et<=R;et+=2)$e.moveTo(k-v*.9,zt(et)),$e.lineTo(k+v*.9,zt(et));if(W[Ne[_]]!==Se[_]){W[Ne[_]]=Se[_];const[et,xe]=Te[Se[_]];C.push([et,k-v*(.5+.25+xe+.2),it+v*.52])}}}const J=[];let je=0,tn=-1,Be=Math.max(0,se(s.beats,y.start)-1);const _e=Gt+2*v,fe=()=>{if(!J.length)return;const W=V?J.filter(S=>S.up).length*2>=J.length:!1,u=V&&W?1:-1,g=V?v*.5:ye,L=V?v*.25:ye*.6;let k=kt;if(V){for(const R of J)R.sx=R.x+(W?v*.44:-v*.44),R.sy=W?R.lo:R.hi,R.tip=W?Math.min(R.hi-v*3.5,_e):Math.max(R.lo+v*3.5,_e);const S=J.map(R=>R.sy),_=S.reduce((R,it)=>R+it,0)/S.length;k=J.length===1?J[0].tip+(Re(J[0].r)>2?u*-v*.58:0):W?Math.min(_-v*3.5,Math.min(...J.map(R=>R.hi))-v*2.5):Math.max(_+v*3.5,Math.max(...J.map(R=>R.lo))+v*2.5)}for(const S of J)pe.moveTo(S.sx,S.sy),pe.lineTo(S.sx,k);for(let S=0;J.length>1&&S<je;S++){const _=k+u*S*(g+L)-(u<0?g:0);let R=-1;for(let it=0;it<=J.length;it++){const Pt=it<J.length&&Re(J[it].r)>S;if(Pt&&R<0&&(R=it),Pt||R<0)continue;const ht=J[R].sx-(V?v*.06:0),et=J[it-1].sx+(V?v*.06:0),xe=R===it-1,Pe=V?v*1.1:t*.8;Zt.rect(xe&&R?et-Pe:ht,_,xe?Pe:et-ht,g),R=-1}}if(J.length===1&&Re(J[0].r)){const S=J[0];if(V)C.push(["𝅥"+["𝅮","𝅯","𝅰"][Math.min(3,Re(S.r))-1],S.sx-v*.06,S.sy+v*.54,W?1:-1,S.sy]);else for(let _=0;_<Re(S.r);_++)Zt.rect(S.x,k-_*(g+L)-g,t*.8,g)}J.length=je=0};for(let W=Math.max(0,se(re,y.start)-1);W<re.length;W++){const u=re[W];if(u.time>=y.end-.001)break;if(u.time<y.start-.001)continue;const g=Z(u.time),L=t*1.1/20;for(;s.beats[Be+1]?.time<=u.time+1e-4;)Be++;if((Be!==tn||u.rest)&&fe(),tn=Be,u.rest&&V){if(u.value<=2)Zt.rect(g-v*.6,u.value===1?Gt+v:Gt+v*1.5,v*1.2,v*.5);else{const S=Math.min(3,Math.round(Math.log2(u.value))-2),_=[1.03,1.05,1.32,1.6][S];C.push([["𝄽","𝄾","𝄿","𝅀"][S],g-v*.2-_*v/2,Yt])}continue}if(u.rest){const S=bt+ve*t;if(u.value<=2)Zt.rect(g-6*L,S-(u.value===1?5:0)*L,12*L,5*L);else{if(pe.moveTo(g+(u.value===4?-3:4)*L,S+(u.value===4?-10:-7)*L),u.value>4)pe.lineTo(g-3*L,S+9*L);else for(const[_,R]of[[3,-3],[-3,3],[4,9]])pe.lineTo(g+_*L,S+R*L);for(let _=0;_<Re(u);_++)Zt.moveTo(g+(4-_*1.6)*L,S+(-5+_*5)*L),Zt.arc(g+(2-_*1.6)*L,S+(-5+_*5)*L,2*L,0,Math.PI*2)}continue}let k={r:u,x:g,stems:pe,up:!1,lo:Nt+5,hi:Nt+5,sx:g,sy:Nt+5,tip:kt};if(V){const S=[];for(let ht=se(s.notes,u.time-.001);ht<s.notes.length&&s.notes[ht].time<=u.time+.001;ht++)q.has(ht)&&!s.notes[ht].grace&&S.push(q.get(ht));if(!S.length)continue;const _=S.map(ht=>ht.y),R=Math.max(..._),it=Math.min(..._),Pt=Math.abs(R-_e)>=Math.abs(it-_e);if(k={r:u,x:g,stems:pe,up:Pt,lo:R,hi:it,sx:g+(Pt?v*.44:-v*.44),sy:Pt?R:it,tip:Pt?Math.min(it-v*3.5,_e):Math.max(R+v*3.5,_e)},u.value<=2)for(const ht of S)Qe.moveTo(ht.x+v*.32,ht.y),Qe.ellipse(ht.x,ht.y,v*.32,v*.17,-.6,0,Math.PI*2);for(const ht of S)for(let et=0;et<u.dots;et++){const xe=ht.step%2===0?-v*.5:0;Zt.moveTo(ht.x+v*(1.2+et*.5)+v*.2,ht.y+xe),Zt.arc(ht.x+v*(1.2+et*.5),ht.y+xe,v*.2,0,Math.PI*2)}}else for(let S=0;S<u.dots;S++)Zt.moveTo(g+t*.5+S*t*.4+t*.13,kt-t*.4),Zt.arc(g+t*.5+S*t*.4,kt-t*.4,t*.13,0,Math.PI*2);if(u.value===1){fe();continue}Re(u)?(J.push(k),je=Math.max(je,Re(u))):(fe(),pe.moveTo(k.sx,k.sy),pe.lineTo(k.sx,k.tip))}if(fe(),P===Ct){const W=Math.max(0,se(re,h+1e-4)-1),u=re[W];if(u&&u.time>=y.start-.001&&u.time<y.end){const g=re[W+1]&&re[W+1].time<y.end?re[W+1].time:y.end,L=Z(u.time)-t*(V?1:.75),k=Z(g)-t*(V?.3:.35),S=V?vt-t*.5:bt-t*.7;n.beatBox!==!1&&(M.box=[L,S,Math.max(k-L,t*1.5),Nt+t*.5-S+(V?0:ne*.45+t*.2)])}M.x=[Z(Math.min(h,y.end)),(V?vt:bt)-t*.5,Nt+t*.5]}}if(r.lineCap="butt",r.strokeStyle=H(z,.42),r.lineWidth=V?Math.max(1,v*.13):1,r.stroke(Le),r.strokeStyle=H(z,.7),r.lineWidth=V?Math.max(1.2,v*.16):1.2,r.stroke(Ce),r.lineWidth=V?v*.5:3,r.stroke(fn),r.fillStyle=Et,r.fill(ze),r.strokeStyle=r.fillStyle=z,r.lineWidth=V?Math.max(1,v*.12):Math.max(1.2,t*.09),r.stroke(pe),r.lineWidth=Math.max(1,v*.16),r.stroke($e),r.lineCap="round",r.fill(Zt),r.strokeStyle=z,r.lineWidth=1.1,r.stroke(A),r.setLineDash([4,3]),r.stroke(on),r.setLineDash([]),pt){r.font=Ze,r.textAlign="left",r.textBaseline="alphabetic";for(const[P,I,y,ct,Z]of C)ct===-1?(r.save(),r.translate(I,Z),r.scale(1,-1),r.fillText(P,0,v*.54),r.restore()):r.fillText(P,I,y)}r.globalCompositeOperation="destination-out",r.fill(Qe),r.globalCompositeOperation="source-over";for(const[P,I,y,ct,Z,bt]of he)r.font=P,r.fillStyle=Z,r.textAlign=bt,r.fillText(I,y,ct);r.textAlign="center",r.font=Xe,r.fillStyle=z;for(const[P,I,y,ct]of Je)P!==Xe&&(r.font=P),r.fillText(I,y,ct),P!==Xe&&(r.font=Xe);r.font=De,r.textAlign="left",r.globalAlpha=.7;for(const[P,I,y]of gt)r.fillText(P,I,y);r.globalAlpha=1,r.textAlign="center";for(const[P,I,y,ct,Z]of St)r.fillStyle=r.shadowColor=Z,r.shadowBlur=12,P==="head"?(r.beginPath(),r.ellipse(I,y,ct,ct*.81,-.35,0,Math.PI*2),r.fill()):(r.font=P,r.fillText(I,y,ct));r.shadowBlur=0,r.font=qe;for(const[P,I,y,ct]of Ee)r.fillStyle=ct,r.fillText(P,I,y);if(M.box&&(r.strokeStyle=H(n.accent,.35),r.fillStyle=H(n.accent,.1),r.lineWidth=1,r.beginPath(),r.roundRect(...M.box,4),r.fill(),r.stroke()),M.x){const[P,I,y]=M.x,ct=t*.9;r.strokeStyle=n.accent,r.lineWidth=1.5,r.beginPath(),r.roundRect(P-ct/2,I,ct,y-I,ct/2),r.stroke()}r.restore(),r.globalCompositeOperation="destination-over",r.beginPath(),r.roundRect(Fe,Ot,x-Fe*2,ae-Ot,16),r.fillStyle=_t?"#ffffff":H(n.ink,.72),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle=_t?"#d3d7df":n.chipBorder,r.lineWidth=1,r.stroke(),Ve("sheet")}function bi(a,s,h,n){const{g:e,W:r}=Nn(a);if(!s)return;const x=s.strings,d=Math.min(mi,320/Math.max(1,x-1))*(n.boardHeight??1),t=Do,F=t+d*2.2,X=F+d*(x-1),_t=X+d*1.45,z=F-d*1.55,Et=Math.min(20,d*.32),G=C=>F+(n.stringOrder==="high"?x-1-C:C)*d,Ht=ci*(n.noteSpeed??1),yt=n.tabLayout==="pages",V=(n.tabMarks??"all")==="all",v=n.tabMarks==="notes",pt=Ke+30,Mt=r-Fe-30,K=yt?Math.min(170,(Mt-pt)*.14):0,N=Mt-(yt?K+24:0);let Tt,ut,It,Jt,ne=null;if(yt){const C=Co(s,(N-pt)/Ht),ft=Math.max(0,C.findLastIndex(Ot=>Ot.start<=h)),tt=C[ft],Ct=(N-pt)/(tt.end-tt.start);Tt=Ot=>pt+(Ot-tt.start)*Ct,[It,Jt]=[tt.start,tt.end-.001],ut=Tt(Math.min(Math.max(h,tt.start),tt.end)),C[ft+1]&&(ne={start:C[ft+1].start,scale:Ct})}else ut=Math.max(Ke+Lo+60,r*.2),Tt=C=>ut+(C-h)*Ht,[It,Jt]=[h-(ut-Ke)/Ht,h+(r-ut)/Ht];const ye=C=>n.str[C%n.str.length],Ft=C=>C.chord===null||C.chord===void 0?null:s.chords[C.chord],oe=(C,ft,tt,Ct)=>{e.beginPath(),e.moveTo(C,ft),e.lineTo(tt,Ct),e.stroke()},ge=(C,ft,tt,Ct)=>{const Ot=Math.hypot(tt,Ct),[ae,Ie]=[tt/Ot,Ct/Ot];oe(C,ft,C-6*ae-4*Ie,ft-6*Ie+4*ae),oe(C,ft,C-6*ae+4*Ie,ft-6*Ie-4*ae)},Ze=C=>C>=ut-1?1:.4;e.lineCap="round",e.lineJoin="round",e.textBaseline="alphabetic";const Te=[],ke=C=>{C&&(e.save(),e.beginPath(),e.rect(C[0],0,C[1]-C[0],Ae),e.clip());const ft=`600 ${ee(Math.min(15,d*.26))}px ${n.num}`,tt=`700 ${ee(Math.min(13,d*.22))}px ${n.num}`,Ct=new Map;e.font=ft,e.textAlign="left";const Ot=new Path2D,ae=new Path2D;e.fillStyle=n.muted;for(let M=se(s.beats,It-1);M<s.beats.length;M++){const m=s.beats[M];if(m.time>Jt)break;const Y=Tt(m.time),P=m.measure>=0,I=P?Ot:ae;I.moveTo(Y,F-d*.35),I.lineTo(Y,X+d*.35),P&&(e.fillText(String(m.measure),Y+6,t+d*.3),Ct.set(Math.round(m.time*50),Kt(e,ft,String(m.measure)).width+16))}e.lineWidth=1,e.strokeStyle=H(n.text,.05),e.stroke(ae),e.lineWidth=1.5,e.strokeStyle=H(n.text,.16),e.stroke(Ot),e.fillStyle=n.accent;const Ie=new Map;for(const M of s.markers??[])M.time>=It&&M.time<=Jt&&Ie.set(Math.round(M.time*50),[...Ie.get(Math.round(M.time*50))??[],M.text]);for(const[M,m]of Ie)e.fillText([...new Set(m)].join(" · "),Tt(M/50)+6+(Ct.get(M)??0),t+d*.3);e.strokeStyle=H(n.text,.14),e.beginPath();for(let M=0;M<x;M++)e.moveTo(Ke,G(M)),e.lineTo(r-Fe,G(M));e.stroke();const le=X+d*.92,re=X+d*1.24;if(n.guides!==!1&&!v){e.font=ft,e.fillStyle=e.strokeStyle=n.anchorLane,e.lineWidth=2;let M=-1/0;const m=s.anchors??[];for(let Y=Math.max(1,se(m,It));Y<m.length&&m[Y].time<=Jt;Y++){const P=m[Y],I=Tt(P.time);if(I<M)continue;const y=`fret ${P.fret}`;e.globalAlpha=Ze(I),oe(I,X+d*.6,I,le-2),e.fillText(y,I+5,le),M=I+5+Kt(e,ft,y).width+8}e.globalAlpha=1}e.strokeStyle=n.text,e.lineWidth=1.5;for(const M of v?[]:s.hairpins??[]){if(M.endTime<It||M.time>Jt)continue;const m=Tt(M.time),Y=Math.max(m+30,Tt(M.endTime)),[P,I]=M.kind==="cresc"?[m,Y]:[Y,m];e.globalAlpha=Ze(Y),e.beginPath(),e.moveTo(I,re-11),e.lineTo(P,re-5),e.lineTo(I,re+1),e.stroke()}e.globalAlpha=1;const ve=ee(Math.min(26,d*.42)),Vt=ve*1.3,Xe=ve*.32,qe=n.gem==="pill"?Vt/2:5,De={note:`700 ${ve}px ${n.num}`,grace:`700 ${ee(ve*.72)}px ${n.num}`,finger:`700 ${ee(ve*.5)}px ${n.num}`},hn=n.markings==="white",Le=s.rhythm,Ce=M=>Tt(M.time)+Vt/2;if(Le?.length){const M=new Path2D,m=new Path2D,Y=Math.max(2.5,d*.055),P=Math.max(2,d*.045),I=Math.max(5,d*.13),y=Et/20,ct=B=>B.value>=8?Math.round(Math.log2(B.value))-2:0,Z=(B,ot,st)=>{M.moveTo(B+st,ot),M.arc(B,ot,st,0,Math.PI*2)},bt=(B,ot)=>{if(ot.value<=2)return M.rect(B-7*y,z+Et*(ot.value===1?.3:.62),14*y,5*y);if(m.moveTo(B+(ot.value===4?-3:4)*y,z+(ot.value===4?2:3)*y),ot.value>4)m.lineTo(B-3*y,z+19*y);else for(const[st,Bt]of[[3,9],[-3,15],[4,21]])m.lineTo(B+st*y,z+Bt*y);for(let st=0;st<ct(ot);st++)Z(B+(2-st*1.6)*y,z+(5+st*5)*y,2*y)},Nt=(B,ot)=>{const st=z+Et;ot.value>=4?Z(B,st,Y):(m.moveTo(B+Y,st),m.arc(B,st,Y,0,Math.PI*2)),ot.value>1&&(m.moveTo(B,z),m.lineTo(B,st-Y*.7))},kt=[],Yt=[];let Gt=0,zt=0;const vt=()=>{for(let B=0;B<Gt;B++){let ot=-1;for(let st=0;st<=kt.length;st++){const Bt=st<kt.length&&ct(kt[st])>B;if(Bt&&ot<0&&(ot=st),Bt||ot<0)continue;const q=Ce(kt[ot]);M.rect(ot===st-1&&ot?q-I:q,z+B*P*2,Math.max(Ce(kt[st-1])-q,I),P),ot=-1}}zt&&kt.length>1&&Yt.push([(Ce(kt[0])+Ce(kt.at(-1)))/2,String(zt)]),kt.length=Gt=zt=0};let Dt=-1,Ut=Math.max(0,se(s.beats,It)-1);for(let B=Math.max(0,se(Le,It)-1);B<Le.length;B++){const ot=Le[B],st=Ce(ot);if(ot.time>Jt)break;for(;s.beats[Ut+1]?.time<=ot.time+1e-4;)Ut++;(Ut!==Dt||ot.rest)&&vt(),Dt=Ut,ot.rest?bt(st,ot):(Nt(st,ot),ct(ot)?(kt.push(ot),Gt=Math.max(Gt,ct(ot)),zt||=ot.tuplet):vt());for(let Bt=0;Bt<ot.dots;Bt++)Z(st+Y*(2.2+Bt*1.5),z+Et+Y*.8,Math.max(1.3,Y*.45))}if(vt(),e.fillStyle=e.strokeStyle=n.muted,e.lineWidth=Math.max(1.2,d*.022),e.stroke(m),e.fill(M),Yt.length){e.font=tt,e.textAlign="center";for(const[B,ot]of Yt)e.fillText(ot,B,z-P*2);e.textAlign="left"}}for(const M of v?[]:s.handShapes??[]){if(!M.arpeggio||M.endTime<It||M.startTime>Jt)continue;const m=M.frets.flatMap((I,y)=>I>=0&&y<x?[G(y)]:[]);if(!m.length)continue;const Y=Tt(M.startTime)-12,P=Tt(M.endTime);e.globalAlpha=Ze(P),e.strokeStyle=H(n.text,.4),e.lineWidth=1.5,e.setLineDash([6,5]),e.beginPath(),e.roundRect(Y,Math.min(...m)-Vt/2-6,P-Y,Math.max(...m)-Math.min(...m)+Vt+12,8),e.stroke(),e.setLineDash([]),M.name&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(M.name,Y,F-d*.72))}e.globalAlpha=1;const fn=M=>(M.slideTo??M.slideUnpitchTo??null)!==null||!!M.slideOut,Qe=M=>{const m=Ft(M);return!!m&&!M.repeat&&!m.highDensity&&m.notes.length>1},pe=(M,m)=>v?4:4+(fn(M)?16:0)+(Qe(m)?10:0)+(m.slideIn?18:0)+(m.showString?20:0);let Zt=0,ze=0;const A=(M,m)=>{m(ze-M/2),ze-=M+3},on={"":tt,"italic ":`italic ${tt}`},Oe=(M,m="")=>A(10,Y=>{e.font=on[m],e.fillText(M,Zt,Y+5)}),{next:qt,prev:cn,held:Re}=uo(s),he=new Map,gt=new Set,St=[],Ee=[];for(let M=se(s.notes,It-Re-.5);M<s.notes.length;M++){const m=s.notes[M];if(m.time>Jt)break;if(Tt(m.time+m.sustain)<Ke-40-Vt*4||C&&m.time<It&&Tt(m.time+m.sustain)-2<=Tt(It)&&typeof m.tieTo!="number")continue;const Y=Ft(m),P=m.grace?.72:1,I=Vt*P,y=G(m.string),ct=ye(m.string),Z=Tt(m.time),bt=m.mute||Y?.fretHandMute,Nt=m.palmMute||Y?.palmMute,kt=m.repeat||Y?.highDensity,Yt=bt?"×":m.harmonic||m.harmonicPinch?`<${m.fret}>`:m.ghost?`(${m.fret})`:String(m.fret),Gt=m.finger??(Y?.fingers?.[m.string]>=0?Y.fingers[m.string]:null),zt=!V||bt||m.fret===0||Gt===null?"":Gt===0?"T":String(Gt),vt=m.grace?De.grace:De.note,Dt=Kt(e,vt,Yt).width,Ut=zt?Kt(e,De.finger,zt).width+3:0,B=s.notes[qt[M]],ot=B?Tt(B.time)-pe(m,B):1/0,st=Math.min(Math.max(I,Dt+Ut+Xe*2*P),Math.max(10,ot-Z)),Bt=Math.max(Z+st,Math.min(Tt(m.time+m.sustain)-2,ot)),q=Z+st/2,J=Math.min(1,(st-4)/(Dt+Ut)),je=he.get(m.string)??(cn[M]>=0?{x0:Tt(s.notes[cn[M]].time),w:Vt}:null);if(he.set(m.string,{x0:Z,w:st}),Bt<Ke-40&&typeof m.tieTo!="number")continue;const tn=m.time<=h&&h<m.time+Math.max(m.sustain,.15),Be=(tn||Z>=ut-1?1:.4)*(m.ghost?.55:1);if(e.globalAlpha=Be,Y&&!gt.has(Y)&&!v){gt.add(Y);const fe=Y.notes.map(k=>G(s.notes[k].string)),W=Math.min(...fe)-Vt/2,u=Math.max(...fe)+Vt/2,g=Z-7;if(fe.length>1&&!kt&&(e.strokeStyle=Y.accent?"#ffffff":H(n.text,.7),e.lineWidth=Y.accent==="heavy"?4:Y.accent?3:2,e.beginPath(),e.moveTo(g+4,W),e.lineTo(g,W),e.lineTo(g,u),e.lineTo(g+4,u),e.stroke()),e.font=tt,e.fillStyle=e.strokeStyle=kt?n.muted:n.text,e.lineWidth=1.8,e.textAlign="left",Y.barre&&!kt&&e.fillText(`${Y.barre.half?"½":""}B${Y.barre.fret}`,g,W-5),Y.strum||Y.roll){const k=Y.notes.map(ht=>s.notes[ht].string),S=G(Math.min(...k)),_=G(Math.max(...k)),[R,it]=(Y.strum??Y.roll)==="down"?[S,_]:[_,S],Pt=g-9;e.beginPath();for(let ht=0;ht<=16;ht++)e.lineTo(Pt+(Y.roll?Math.sin(ht/16*Math.PI*6)*2.5:0),R+(it-R)*ht/16);e.stroke(),ge(Pt,it,0,it-R||1)}const L=s.chords[m.chord-1];Y.name&&!kt&&(!L||m.time-L.time>1||L.name!==Y.name)&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(Y.name,Z,F-d*.72))}e.beginPath(),e.roundRect(Z,y-I/2,Bt-Z,I,qe*P),tn&&!kt&&(e.shadowColor=ct,e.shadowBlur=18),kt?(e.strokeStyle=ct,e.lineWidth=2,e.stroke()):m.letRing&&Bt>Z+st+2?(e.fillStyle=H(ct,.3),e.fill(),e.shadowBlur=0,e.strokeStyle=ct,e.lineWidth=2,e.setLineDash([6,5]),oe(Z+st+4,y,Bt-4,y),e.setLineDash([]),e.beginPath(),e.roundRect(Z,y-I/2,st,I,qe*P),e.fillStyle=ct,e.fill()):(e.fillStyle=bt?H(n.text,.22):ct,e.fill()),e.shadowBlur=0,tn&&Te.push({y,c:ct});const _e=kt?ct:bt?n.text:hn?"#ffffff":n.ink;St.push({text:Yt,font:vt,finger:zt,fill:_e,shown:Be,squeeze:J,x:q,y:y+Kt(e,vt,Yt).middle,left:-(Dt+Ut)/2,textWidth:Dt}),v||Ee.push(()=>{e.globalAlpha=Be;const fe=kt?n.muted:n.text;e.strokeStyle=e.fillStyle=fe,e.lineWidth=1.6;const W=m.slideTo??m.slideUnpitchTo??null,u=W===null?m.slideOut==="up"?1:m.slideOut?-1:0:Math.sign(W-m.fret)||1;if(u){const k=m.slideTo===null&&m.slideUnpitchTo!==null&&m.slideUnpitchTo!==void 0;k&&e.setLineDash([3,3]),oe(Bt+4,y+u*I*.3,Bt+14,y-u*I*.3),k&&e.setLineDash([])}if(m.slideIn&&oe(Z-16,y+(m.slideIn==="below"?1:-1)*I*.3,Z-6,y-(m.slideIn==="below"?1:-1)*I*.3),typeof m.tieTo=="number"){const k=Tt(s.notes[m.tieTo].time)+I/2;e.setLineDash([4,3]),e.beginPath(),e.moveTo(q,y+I/2+3),e.quadraticCurveTo((q+k)/2,y+I/2+14,k,y+I/2+3),e.stroke(),e.setLineDash([])}if(m.showString){const k=Z-(Y?26:13);e.beginPath(),e.arc(k,y,8,0,Math.PI*2),e.stroke(),e.font=De.finger,e.textAlign="center",e.fillText(String(x-m.string),k,y+Kt(e,De.finger,"1").middle)}m.dynamicLabel&&(e.font=`italic ${tt}`,e.textAlign="left",e.fillStyle=n.text,e.fillText(m.dynamicLabel,Z,re),e.fillStyle=fe);let g=y-I/2-6;if(m.vibrato){e.beginPath();for(let k=Z+2;k<=Math.max(Bt,Z+24)-2;k+=2)e.lineTo(k,g+Math.sin((k-Z)/3)*(m.vibratoWide?3:1.8));e.stroke(),g-=m.vibratoWide?10:8}if(e.textAlign="center",e.font=tt,(m.hammerOn||m.pullOff)&&je){const k=je.x0+je.w/2,S=(k+q)/2;e.beginPath(),e.moveTo(k,g),e.quadraticCurveTo(S,g-12,q,g),e.stroke(),e.fillText(m.hammerOn?"H":"P",S,g-9),g-=10}const L=rn(m);if(L>0){const k=m.bendCurve?.[0]?.[1]>0,S=(m.bendCurve?.length??0)>1&&m.bendCurve.at(-1)[1]<L,_=Z+st-2,R=y-I/2,it=R-16;e.beginPath(),k?(e.moveTo(_,R),e.lineTo(_,it)):(e.moveTo(_-4,R+2),e.quadraticCurveTo(_+4,R,_+6,it)),e.stroke(),ge(k?_:_+6,it,k?0:.3,-1),S&&(e.beginPath(),e.moveTo(_+12,it),e.quadraticCurveTo(_+16,R-6,_+16,R),e.stroke(),ge(_+16,R,0,1)),e.textAlign="left",e.fillText(`${k?"pre ":""}${Fn(L)}`,_+(S?20:10),it+4),e.textAlign="center"}[Zt,ze]=[q,g],m.tap&&!m.tapLeft&&Oe("T"),m.staccato&&A(4,k=>{e.beginPath(),e.arc(q,k,2,0,Math.PI*2),e.fill()}),m.accent&&(m.accent==="tenuto"||!Y?.accent)&&Oe({heavy:"^",tenuto:"–"}[m.accent]??">"),Nt&&Oe("PM");for(const k of[m.tapLeft?"m.g.":"",Po[m.harmonicType]??(m.harmonicPinch?"PH":""),m.slap?"slap":m.pop?"pop":"",m.golpe?`golpe (${m.golpe})`:"",m.rasgueado?`rasg. ${m.rasgueado}`:"",typeof m.trill=="number"?`tr ${m.trill}`:"",m.ornament??"",m.fade??"",m.whammy?"w/bar":"",m.wah==="open"?"o":m.wah==="closed"?"+":""])k&&Oe(k);m.rightFinger&&Oe(m.rightFinger,"italic "),m.pick&&A(9,k=>{e.beginPath(),m.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([S,_],R)=>e[R?"lineTo":"moveTo"](q+S,k+_)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([S,_],R)=>e[R?"lineTo":"moveTo"](q+S,k+_)),e.stroke()}),m.fermata&&A(9,k=>{e.beginPath(),e.arc(q,k+4,7,Math.PI,0),e.stroke(),e.beginPath(),e.arc(q,k+3,1.5,0,Math.PI*2),e.fill()}),m.tremolo&&A(18,k=>{for(let S=-1;S<=1;S++)oe(q-6,k+S*4+5.5,q+6,k+S*4+.5);e.beginPath();for(let S=0;S<=12;S++)e[S?"lineTo":"moveTo"](q-8+16*S/12,k-7+Math.sin(S/12*Math.PI*2)*2);e.stroke()})})}const Je=(M,m,Y,P)=>{if(e.globalAlpha=M.shown*P,e.fillStyle=M.fill,M.squeeze===1)return e.fillText(m,M.x+M.left+Y,M.y);e.save(),e.translate(M.x,M.y),e.scale(M.squeeze,1),e.fillText(m,M.left+Y,0),e.restore()};e.textAlign="left";for(const M of[De.note,De.grace]){e.font=M;for(const m of St)m.font===M&&Je(m,m.text,0,1)}e.font=De.finger;for(const M of St)M.finger&&Je(M,M.finger,M.textWidth+3,.7);for(const M of Ee)M();e.globalAlpha=1,C&&e.restore()};if(!yt)ke(null);else if(ke([pt-40,N+4]),ne){const C=N+24,ft=ut;Tt=tt=>C+(tt-ne.start)*ne.scale,[It,Jt,ut]=[ne.start,ne.start+K/ne.scale,-1/0],ke([C-8,Mt+4]),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.55)",e.fillRect(C-8,0,Mt+12-(C-8),Ae),e.restore(),e.strokeStyle=H(n.text,.22),e.lineWidth=1.5,e.setLineDash([3,5]),oe(N+12,F-d*.6,N+12,X+d*.6),e.setLineDash([]),ut=ft}e.shadowColor=n.accent,e.shadowBlur=16,e.strokeStyle=n.accent,e.lineWidth=3,oe(ut,F-d*.7,ut,X+d*.7);for(const{y:C,c:ft}of Te)e.shadowColor=ft,e.fillStyle="#ffffff",e.beginPath(),e.arc(ut,C,4,0,Math.PI*2),e.fill();e.shadowBlur=0,e.globalCompositeOperation="destination-out";for(const[C,ft,tt]of yt?[]:[[Ke+10,1,Lo],[r-Fe,-1,80]]){const Ct=e.createLinearGradient(C,0,C+ft*tt,0);Ct.addColorStop(0,"rgba(0, 0, 0, 1)"),Ct.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=Ct,e.fillRect(ft>0?0:C-tt,0,ft>0?C+tt:r-C+tt,Ae)}if(e.globalCompositeOperation="destination-over",e.beginPath(),e.roundRect(Fe,t,r-Fe*2,_t-t,16),e.fillStyle=H(n.ink,.72),e.fill(),e.globalCompositeOperation="source-over",e.strokeStyle=n.chipBorder,e.lineWidth=1,e.stroke(),!s.open)return;const Ne=`700 ${ee(Math.min(14,d*.24))}px ${n.num}`,Se=Math.min(13,d*.22),Ye=(Fe+Ke)/2;e.textAlign="center",e.fillStyle=n.muted,e.font=`700 ${ee(Math.min(12,d*.2))}px ${n.ui}`,e.fillText("TAB",Ye,z+Et*.7);const $e=s.meters?.findLast(C=>C.time<=h)?.text.split("/");if($e){const C=(F+X)/2,ft=`700 ${ee(Math.min(30,d*.52))}px ${n.num}`;e.font=ft,e.fillText($e[0],Ke+20,C-d*.04),e.fillText($e[1],Ke+20,C+d*.56)}e.font=Ne;for(let C=0;C<x;C++){const ft=G(C),tt=ye(C),Ct=Te.some(Ot=>Ot.y===ft);e.fillStyle=Ct?tt:H(tt,.16),e.beginPath(),e.roundRect(Ye-Se*1.2,ft-Se*.95,Se*2.4,Se*1.9,Se*.55),e.fill(),e.fillStyle=Ct?n.ink:tt,e.fillText(Qn(s.open[C]),Ye,ft+Kt(e,Ne,"E").middle)}}export{Vo as HEADSTOCKS,ai as bendAt,xi as drawHighway,Mi as drawSheet,bi as drawTab,Zo as headstockParts,No as lookAhead,fi as moveCamera,ho as rounded,mo as spline};
|
|
1
|
+
import{lap as Ve}from"./perf.js";import{noteName as Qn}from"./music.js";const Ae=900,_o=84,to=28,eo=2.2,Ho=.9,Fo=2.4,No=a=>_o*(a.drawDistance??1)/(to*(a.noteSpeed??1)),Yo=.34,de=24,vn=1.2,qo=1.25,zo=1.25,gn=5,Pn=1,Go=1.6,Uo=2,pn=.19,no=.12,oo=3,Xo=11,jo=[{time:-1/0,endTime:1/0,fret:1,width:4}],En=[3,5,7,9,12,15,17,19,21,24],Bn=.15,io=.31,so=1.7,ao=1.4,lo=1,ro=1.2,Ko=18,ho=(a,s,h,n,e)=>{const[r,x,d,t]=[Math.min(a,s),Math.max(a,s),Math.min(h,n),Math.max(h,n)],F=Math.min(e,(x-r)/2,(t-d)/2),X=(_t,z,Et)=>{const G=Array.from({length:5},(Ht,yt)=>[_t+Math.cos(Et+yt*Math.PI/8)*F,z+Math.sin(Et+yt*Math.PI/8)*F]);return[G[0],...G,G[4]]};return[...X(x-F,t-F,0),...X(r+F,t-F,Math.PI/2),...X(r+F,d+F,Math.PI),...X(x-F,d+F,1.5*Math.PI)]},Jo=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([s,h])=>[s,-h])],Vo={inline:{label:"6 in line",outline:[[0,1],[.42,1.05],[.73,1.3],[1.01,1.53],[1.46,1.45],[2.73,1.08],[4.38,.62],[5.79,.17],[6.54,-.13],[6.88,-.35],[7.03,-.88],[6.98,-1.56],[6.64,-2.11],[6.14,-2.38],[5.59,-2.34],[5.21,-2.05],[4.99,-1.66],[4.75,-1.39],[4.25,-1.3],[3.5,-1.39],[2.6,-1.6],[1.85,-1.81],[1.18,-1.75],[.83,-1.36],[.47,-1.06],[0,-1]],posts:{from:[1.56,.95],to:[6.01,-.58]},keys:"machine",tree:2.47},fourTwo:{label:"4 + 2",outline:[[0,1],[.48,1.03],[.94,1.35],[1.21,1.72],[1.52,1.72],[2.99,1.31],[4.23,.95],[5.53,.57],[5.92,.28],[6.07,-.36],[6.05,-1.03],[5.79,-1.53],[5.36,-1.67],[4.95,-1.53],[4.68,-1.29],[4.36,-1.19],[4.02,-1.32],[3.67,-1.56],[2.99,-1.67],[2.08,-1.6],[1.4,-1.43],[.94,-1.16],[.48,-1.03],[0,-1]],posts:{from:[1.81,1.08],to:[4.94,-.03],treble:{share:1/3,from:[2.33,-1.03],to:[3.38,-.69]}},keys:"machine"},openBook:{label:"3 + 3 open book",outline:Jo([[0,1],[.48,1.07],[.96,1.33],[1.47,1.53],[3.16,1.67],[4.98,1.76],[6.25,1.8],[6.25,1.8],[6.42,.93],[6.3,0]]),posts:{from:[2.5,1.07],to:[5.1,1.07],treble:{share:1/2}},keys:"tulip",cover:[[.22,0],[.22,.4],[.36,.5],[.78,.4],[1.3,.25],[1.82,.16],[2.13,.1],[2.24,0],[2.13,-.1],[1.82,-.16],[1.3,-.25],[.78,-.4],[.36,-.5],[.22,-.4],[.22,0]],screws:[[.43,0],[1.98,0]]},pointed:{label:"3 + 3 pointed",outline:[[0,1],[.36,1.12],[.75,1.47],[1.07,1.84],[1.38,1.93],[2.29,1.73],[3.26,1.55],[4.36,1.35],[5.45,1.12],[5.75,.95],[5.86,.43],[5.98,-.22],[6.29,-.75],[6.75,-1.22],[6.75,-1.22],[6.17,-1.24],[5.33,-1.3],[4.36,-1.37],[3.26,-1.55],[2.29,-1.73],[1.38,-1.93],[1.07,-1.84],[.75,-1.47],[.36,-1.12],[0,-1]],posts:{from:[2.07,1],to:[4.65,.46],treble:{share:1/2}},keys:"machine",cover:[[.1,.44],[.1,.44],[.59,.4],[1.1,.28],[1.69,0],[1.69,0],[1.1,-.28],[.59,-.4],[.1,-.44],[.1,-.44],[.1,.44]],screws:[]},headless:{label:"Headless",outline:ho(.2,.95,-1.06,1.06,.2),clamps:.58}};function Zo(a,s){const h=s.length,n=mo(a.outline,10);let e=s.map(t=>[a.clamps,t]),r=s.map(()=>1);if(a.posts){const{from:t,to:F,treble:X}=a.posts,_t=X?Math.floor(h*X.share+1e-9):0,z=h-_t,Et=(Z,P,pt)=>Mt=>Z.map((K,N)=>K+(P[N]-K)*Mt/Math.max(1,pt-1)),G=([Z,P])=>[Z,-P],Ht=Et(t,F,z),yt=Et(X?.from??G(t),X?.to??G(F),_t);e=s.map((Z,P)=>P<z?Ht(P):yt(h-1-P)),r=s.map((Z,P)=>P<z?1:-1)}const x=(t,F)=>{let X=null;for(let _t=1;_t<n.length;_t++){const[z,Et]=n[_t-1],[G,Ht]=n[_t];if((z-t)*(G-t)>0||z===G)continue;const yt=Et+(Ht-Et)*(t-z)/(G-z);(X===null||yt*F>X*F)&&(X=yt)}return X??F},d=a.keys?e.map(([t],F)=>({u:t,side:r[F],edge:x(t,r[F])})):[];return{outline:n,ends:e,keys:d}}const fo=new WeakMap,yn=new Map,Qo=(a,s)=>{const h=s.join(),n=fo.get(a);if(n?.key===h)return n.parts;const e=Zo(a,s);return fo.set(a,{key:h,parts:e}),e},co=(a,s)=>(yn.has(a)||(yn.size>500&&yn.clear(),yn.set(a,s())),yn.get(a)),mo=(a,s=8)=>[...a.slice(0,-1).flatMap((h,n)=>{const e=a[Math.max(0,n-1)],r=a[n+1],x=a[Math.min(a.length-1,n+2)];return h[0]===r[0]&&h[1]===r[1]?[h]:Array.from({length:s},(d,t)=>{const F=t/s;return[0,1].map(X=>.5*(2*h[X]+(r[X]-e[X])*F+(2*e[X]-5*h[X]+4*r[X]-x[X])*F*F+(3*h[X]-e[X]-3*r[X]+x[X])*F**3))})}),a.at(-1)],Tn=(a,s)=>{if(!a.startsWith("#"))return a;const h=n=>{const e=parseInt(a.slice(n,n+2),16);return Math.round(s>0?e+(255-e)*s:e*(1+s)).toString(16).padStart(2,"0")};return`#${h(1)}${h(3)}${h(5)}`},wn=new Map,H=(a,s)=>{if(!a.startsWith("#"))return a;const h=a+s;let n=wn.get(h);return n||(wn.size>1e3&&wn.clear(),wn.set(h,n=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${s})`)),n},se=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<s?h=e+1:n=e}return h};function uo(a){if(a.links?.next.length===a.notes.length)return a.links;const s=a.notes.length,h=new Array(s).fill(-1),n=new Array(s).fill(-1),e={};let r=0;for(let x=0;x<s;x++){const{string:d,sustain:t}=a.notes[x];e[d]!==void 0&&([n[x],h[e[d]]]=[e[d],x]),e[d]=x,r=Math.max(r,t)}return a.links={next:h,prev:n,held:r}}const ee=a=>Math.round(a*4)/4,We=32,An=new Map;let go=0;const Kt=(a,s,h)=>{let n=An.get(s);n||An.set(s,n=new Map);let e=n.get(h);if(!e){++go>5e3&&([go,n]=[0,new Map],An.clear(),An.set(s,n)),a.font=s;const r=a.measureText(h);n.set(h,e={width:r.width,middle:(r.actualBoundingBoxAscent-r.actualBoundingBoxDescent)/2,top:r.actualBoundingBoxAscent})}return e},Wn=128,_n=new WeakMap,ti=a=>{if(!_n.has(a)){const s=new OffscreenCanvas(1,Wn),h=s.getContext("2d"),[n,e]=[a.floor0,a.floor1].map(x=>[1,3,5].map(d=>parseInt(x.slice(d,d+2),16))),r=Array.from({length:Wn},(x,d)=>{const t=(d+.5)/Wn;return`rgba(${n.map((F,X)=>Math.round(F+(e[X]-F)*t))}, ${1-t})`});r.forEach((x,d)=>{h.fillStyle=x,h.fillRect(0,Wn-1-d,1,1)}),_n.set(a,{strip:s,near:r[0]})}return _n.get(a)},xn=new Map,po=new WeakMap,xo=(a,s,h)=>{let n=po.get(a);n||po.set(a,n=new Map);let e=n.get(s);if(!e){e=a.createLinearGradient(0,0,0,1);for(const[r,x]of h)e.addColorStop(r,x);n.set(s,e)}return e},$n=new Map,Mo=(a,s,h,n,e)=>{const r=`${s}|${h}|${n}|${e}`;let x=$n.get(r);return x||($n.size>20&&$n.clear(),x=a.createLinearGradient(0,s,0,h),x.addColorStop(0,n),x.addColorStop(1,e),$n.set(r,x)),x},In=(a,s)=>[a[0]-s[0],a[1]-s[1],a[2]-s[2]],Dn=(a,s)=>a[0]*s[0]+a[1]*s[1]+a[2]*s[2],ei=(a,s)=>[a[1]*s[2]-a[2]*s[1],a[2]*s[0]-a[0]*s[2],a[0]*s[1]-a[1]*s[0]],ni=a=>a.map(s=>s/Math.hypot(...a)),oi=(a,s)=>{let h=0;for(const n of a??[]){if(n.time>s)break;h=n.fret}return h},ii=.15,bo=new WeakMap,Hn=a=>{let s=bo.get(a);if(!s){s=[];for(const h of a){const n=s[s.length-1];n&&h.endTime-h.time<ii?n.endTime=h.endTime:s.push({...h})}bo.set(a,s)}return s},kn=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<=s?h=e+1:n=e}return a[Math.max(0,h-1)]},yo=a=>a*a*(3-2*a),si=.3,To=new WeakMap;function ko(a,s){let h=To.get(a);if(h||To.set(a,h={}),!(s in h)){const n=Math.max(a.sustain,.05),r=(a[s]??(s==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([x,d])=>[x*n,d,!1])??[];r.length&&r[0][0]>.001&&(r[0][2]=!0,r.unshift([0,0,!1])),h[s]=r.length?r:null}return h[s]}function So(a,s){if(!a)return 0;let h=a[0][1];for(let n=1;n<a.length&&s>a[n-1][0];n++){const[[e,r],[x,d,t]]=[a[n-1],a[n]],F=Math.min(x-e,si)||1e-6;h=r+(d-r)*yo(Math.min(1,Math.max(0,(s-(t?x-F:e))/F)))}return h}const ai=(a,s)=>So(ko(a,"bendCurve"),s),li=(a,s)=>So(ko(a,"whammy"),s),vo=new WeakMap,rn=a=>{let s=vo.get(a);return s===void 0&&vo.set(a,s=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,h])=>h))),s};function ri(a){if(a.chordSpans)return a.chordSpans;const s=[];for(const h of a.chords){const n=Math.max(h.time+.25,...h.notes.map(r=>a.notes[r].time+a.notes[r].sustain)),e=s.at(-1);e&&h.time-e.end<1&&(h.name?h.name===e.name:h.highDensity)?e.end=Math.max(e.end,n):h.name&&s.push({name:h.name,time:h.time,end:n})}for(const h of a.handShapes??[])h.arpeggio&&h.name&&s.push({name:h.name,time:h.startTime,end:h.endTime});return a.chordSpans=s.sort((h,n)=>h.time-n.time)}function hi(a){if(a.chordRails)return a.chordRails;const s=[],h=n=>Math.max(n.time+.15,...n.notes.map(e=>a.notes[e].time+a.notes[e].sustain));for(let n=0;n<a.chords.length;n++){const e=a.chords[n];if(e.highDensity)continue;let r=h(e),x=n+1;for(;a.chords[x]?.highDensity&&a.chords[x].time-r<1;x++)r=Math.max(r,h(a.chords[x]));r=Math.min(r,a.chords[x]?.time??1/0),r-e.time>.2&&s.push({time:e.time,end:r,frets:e.notes.map(d=>a.notes[d].fret)})}for(const n of a.handShapes??[])n.arpeggio&&s.push({time:n.startTime,end:n.endTime,frets:n.frets,arpeggio:n});return a.chordRails=s}const Po={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},Fn=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),wo=(a,s,h,n)=>{if(a===void 0)return s;const e=a+(s-a)*(1-Math.exp(-h/n));return Math.abs(s-e)<1e-6?s:e};function Ao(a,s,h,n,e){a[s]===void 0&&([a[s],a[s+"Speed"]]=[h,0]);const r=2/n,x=r*e,d=1/(1+x+.48*x*x+.235*x*x*x),t=a[s]-h,F=(a[s+"Speed"]+r*t)*e;a[s+"Speed"]=(a[s+"Speed"]-r*F)*d,a[s]=h+(t+F)*d,Math.abs(a[s]-h)<1e-6&&Math.abs(a[s+"Speed"])<1e-6&&([a[s],a[s+"Speed"]]=[h,0])}function Wo(a,s,h=0){let n=1/0,e=-1/0;for(const x of a)x.endTime<=s||x.time>=s+oo||(n=Math.min(n,x.fret-1),e=Math.max(e,x.fret-1+x.width));if(n===1/0){const x=kn(a,s);[n,e]=[x.fret-1,x.fret-1+x.width]}h&&(n=Math.min(n,h-1));const r=Math.max(Xo,e-n+2)+1;return{lo:n,hi:e,span:r,center:Math.min(25-r/2,Math.max(r/2-1,(n+e)/2))}}function fi(a,s,h,n,e=0){const r=Wo(s,h,e),x=a.target,d=!x||r.lo<x.center-x.span/2||r.hi>x.center+x.span/2,t=x&&x.span-Math.max(r.span,Wo(s,h+oo,e).span)>2;(d||t)&&(a.target=r);const F=Math.min(n-(a.at??n),100);a.at=n,Ao(a,"span",a.target.span,a.target.span>a.span?.8:1.4,F/1e3),Ao(a,"center",a.target.center,1,F/1e3);const X=kn(Hn(s),h);return a.left=wo(a.left,X.fret-1,F,90),a.right=wo(a.right,X.fret-1+X.width,F,90),X}function $o(a,s,h,n,e,r,x,d){a.beginPath(),a.moveTo(s-n,h-r*e),a.lineTo(s,h),a.lineTo(s+n,h-r*e),a.lineWidth=Math.max(3,e*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,e*.65),a.strokeStyle=x,a.stroke(),a.lineWidth=Math.max(.6,e*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Io(a,s,h,n,e){a.beginPath(),a.moveTo(s,h),a.lineTo(n,e),a.stroke()}function Nn(a){const s=devicePixelRatio||1,h=a.clientWidth,n=a.clientHeight;(a.width!==Math.round(h*s)||a.height!==Math.round(n*s))&&(a.width=Math.round(h*s),a.height=Math.round(n*s));const e=a.getContext("2d"),r=n/Ae,x=h/r,d=s*r;return e.setTransform(d,0,0,d,0,0),e.clearRect(0,0,x,Ae),{g:e,W:x,B:d}}function xi(a,s,h,n,e){const{g:r,W:x,B:d}=Nn(a);let t=r;if(!s)return;const F=s.anchors.length?s.anchors:jo,X=oi(s.capos,h),_t=fi(e,F,h,performance.now(),X),z=s.strings,Et=Math.min(.5,5*Yo/Math.max(1,z-1)),G=Et*zo*(n.boardHeight??1),Ht=G*(z-1),yt=o=>(n.stringOrder==="high"?o:z-1-o)*G,Z=o=>(o>=z/2?1:-1)*(n.stringOrder==="high"?-1:1),P=to*(n.noteSpeed??1),pt=No(n),Mt=-.22,K=Ht+.22,N=Mt-.06,Tt=pt*P,ut=o=>Math.max(0,o)*P,It=o=>n.str[o%n.str.length],Jt=n.noteLines===0?null:`rgba(255, 255, 255, ${n.noteLines??.5})`,ne=+n.fretNumbers||0,ye=e.span,Ft=[e.center,Et*(z-1)/2,0],oe=(n.viewAngle??30)*Math.PI/180,ge=.6*Math.SQRT2*ye,Ze=[Ft[0],Ht+ge*Math.sin(oe),-ge*Math.cos(oe)],Te=ni(In([Ft[0],0,2.2*ye],Ze)),ke=ei(Te,[1,0,0]),Ne=(n.sideAngle??0)*Math.PI/180,[Se,Ye]=[Math.sin(Ne),Math.cos(Ne)],$e=In(Ze,Ft),O=Dn($e,Te),ft=Dn($e,ke),tt=[-Se,Te[1]*Ye,Te[2]*Ye],Ct=[Ye,Te[1]*Se,Te[2]*Se],Ot=[Ft[0]+ft*ke[0]+O*tt[0],Ft[1]+ft*ke[1]+O*tt[1],ft*ke[2]+O*tt[2]],ae=Math.min(x*.88,Ae*(n.fill?1.3:1.05)),Ie=ae*Dn(In(Ft,Ot),tt)/ye,le=Math.min(qo*(n.fretWidth??1),x*ye/(ae*Math.max(1,ye-2.5)));let re=0,ve=0;const[Vt,Xe,qe]=Ot,[De,hn,Le]=tt,[Ce,fn,Qe]=Ct,[pe,Zt,ze]=ke,A=(o,i,f)=>{const l=o-Vt,c=i-Xe,p=f-qe,T=Ie/Math.max(.05,l*De+c*hn+p*Le);return[x/2+(l*Ce+c*fn+p*Qe)*le*T+re,Ae/2-(l*pe+c*Zt+p*ze)*T+ve,T]},[on,Oe,qt]=A(...Ft);[re,ve]=[x/2-on,Ae*(n.fill?.83:.81)-Oe];const[,cn]=A(e.center-ye/2,N,0),[,Re]=A(e.center+ye/2,N,0),[,he]=A(e.center,N,0);ve-=Math.min(Ae*.08,Math.max(0,cn-he,Re-he)),Ve("setup");const gt=(o,i=!0)=>{t.beginPath();for(let f=0;f<o.length;f++){const[l,c]=A(o[f][0],o[f][1],o[f][2]);f?t.lineTo(l,c):t.moveTo(l,c)}i&&t.closePath()},St=(o,i)=>{gt([o,i],!1),q()},Ee=(o,i,f,l,c)=>{if(n.gem!=="pill")return gt([[o-l,i-c,f],[o+l,i-c,f],[o+l,i+c,f],[o-l,i+c,f]]);const[p,T]=A(o-l,i,f),[E,w]=A(o+l,i,f),[,C]=A(o,i+c,f),[,At]=A(o,i-c,f),it=Math.atan2(w-T,E-p),lt=Math.min(Math.abs(At-C),Math.hypot(E-p,w-T))/2,[U,nt]=[lt*Math.cos(it),lt*Math.sin(it)];t.beginPath(),t.arc(p+U,T+nt,lt,it+Math.PI/2,it+Math.PI*1.5),t.arc(E-U,w-nt,lt,it-Math.PI/2,it+Math.PI/2),t.closePath()},Je=(o,i)=>{const f=kn(F,i),l=o.filter(c=>c>0);return[Math.min(f.fret-1,...l.map(c=>c-1))+.05,Math.max(f.fret-1+Math.max(4,f.width),...l)-.05]},M=(o,i,f,l,c)=>{St([o-l,i-c,f],[o+l,i+c,f]),St([o-l,i+c,f],[o+l,i-c,f])},m=n.markings==="white",Y=m?"#ffffff":n.ink,v=(o,i,f,l,c,p,T,E=null)=>{const[w,C]=T?[c*.85,p*.8]:[Math.min(c,.34)*.72,p*.82];E||(t.strokeStyle=H(n.ink,T?.7:.35),t.lineWidth=T?Math.max(3.5,.1*l):Math.max(2.5,.06*l),M(o,i,f,w,C)),t.strokeStyle=E??(T?"#ffffff":H("#ffffff",.42)),t.lineWidth=Math.max(E?2:T?1.8:1.2,(T?.05:.035)*l),M(o,i,f,w,C)};let I=null,y=0;const ct=o=>{o!==I&&(t.font=I=o)},Q={},bt=(o,i,f,l,c,p)=>{const T=Q[c]??=`${c} ${We}px ${n.num}`,E=l/We;return Kt(t,T,o),ct(T),t.textAlign=p,t.setTransform(d*E,0,0,d*E,d*i,d*(f-y)),Kt(t,T,o).middle},Nt=()=>t.setTransform(d,0,0,d,0,-d*y),kt=(o,i,f)=>{t.fillStyle=o,t.setTransform(d,0,0,d*(f-i),0,d*(i-y)),t.fill(),Nt()},Yt=(o,i,f,l,c,p,T=700,E="center",w=!0,C=!1)=>{const[At,it,lt]=A(i,f,l),U=c*(C?lt:Math.sqrt(lt*qt));if(U<(C?1:8)||At<-60||At>x+60)return;t.textBaseline="alphabetic";const nt=bt(o,At,it,U,T,E);w&&(t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(o,0,nt)),t.fillStyle=p,t.fillText(o,0,nt),Nt(),t.textBaseline="middle"},Gt=(o,i,f,l,c,p,T=700)=>{const[E,w]=A(i,N,f),[C,At]=A(i+l,N,f),it=Math.hypot(C-E,At-w),lt=it>.01?Math.max(1,Ko/it):1,[U,nt]=A(i+l*lt,N,f),te=Math.hypot(U-E,nt-w);let V=c*lt,[xt,D]=A(i,N,f+V),Rt=Math.hypot(xt-E,D-w);for(let Ge=0;Ge<3&&Rt>te*ro;Ge++)V*=te*ro/Rt,[xt,D]=A(i,N,f+V),Rt=Math.hypot(xt-E,D-w);const Lt=Math.abs(Math.atan2(xt-E,w-D));if(E<-60||E>x+60||Rt<lo||Lt>ao)return;const Wt=t.globalAlpha;t.globalAlpha=Wt*Math.min(1,(ao-Lt)/.2,(Rt-lo)/3)*Math.max(.45,lt**-.5);const an=Q[T]??=`${T} ${We}px ${n.num}`;ct(an),t.textAlign="center",t.textBaseline="alphabetic";const{top:nn}=Kt(t,an,o);t.setTransform(d*(U-E)/We,d*(nt-w)/We,-d*(xt-E)/We,-d*(D-w)/We,d*E,d*(w-y)),t.fillStyle=p,t.fillText(o,0,nn),Nt(),t.globalAlpha=Wt,t.textBaseline="middle"},[,zt]=A(Ft[0],N,0),[,vt]=A(Ft[0],N,Tt),Dt=(o,i,f)=>{const l=`${zt}|${vt}`;(xn.span!==l||xn.size>300)&&(xn.clear(),xn.span=l);const c=`${o}|${i}|${f}`;let p=xn.get(c);return p||(p=t.createLinearGradient(0,zt,0,vt),p.addColorStop(0,H(o,i)),p.addColorStop(1,H(o,f)),xn.set(c,p)),p};let Ut=null;const B=(o,i,f=10,l=!1)=>Ut=o?{color:i,blur:f,faded:l}:null,ot=[[.6,.05],[.35,.13],[.15,.27]],at=[[.4,.3]],Bt=o=>{if(!Ut)return;const{lineWidth:i,globalAlpha:f}=t,l=o?1:Math.min(1,2*i/Ut.blur);t.save(),t.strokeStyle=Ut.faded?Dt(Ut.color,1,.1):Ut.color;for(const[c,p]of Ut.blur>4?ot:at)t.lineWidth=(o?0:i)+2*Ut.blur*c,t.globalAlpha=f*p*l,t.stroke();t.restore()},q=()=>{Bt(!1),t.stroke()},J=()=>{Bt(!0),t.fill()};t.textBaseline="middle",t.lineCap="round",t.lineJoin="round";const{strip:je,near:tn}=ti(n);let[Be,_e]=[-60,de+60];if(Ne){const o=Ft[0]+(1-Dn(In([Ft[0],N,0],Ot),tt))/tt[0];[Be,_e]=tt[0]>0?[Math.max(-60,o),de+60]:[-60,Math.min(de+60,o)]}t.save(),gt([[Be,N,0],[_e,N,0],[_e,N,Tt],[Be,N,Tt]]),t.clip(),Ne&&(t.fillStyle=tn,t.fillRect(0,zt,x,Ae-zt)),t.imageSmoothingEnabled=!1,t.drawImage(je,0,vt,x,zt-vt),t.restore();const fe=(o,i)=>{const[f,l]=A(...o),[c,p]=A(...i);t.moveTo(f,l),t.lineTo(c,p)};t.strokeStyle=Dt(n.lane,.5,.04),t.lineWidth=Ho,t.beginPath();for(let o=0;o<=de;o++)fe([o,N,0],[o,N,Tt]);q();for(const o of[!1,!0]){t.strokeStyle=o?n.measure:n.beat,t.lineWidth=o?1.6:1,t.beginPath();const i=[];for(let f=se(s.beats,h);f<s.beats.length;f++){const l=s.beats[f],c=l.time-h;if(c>pt)break;l.measure>=0===o&&(c>pt-.4?i.push(c):fe([0,N,ut(c)],[de,N,ut(c)]))}q();for(const f of i)t.globalAlpha=(pt-f)/.4,t.beginPath(),fe([0,N,ut(f)],[de,N,ut(f)]),q();t.globalAlpha=1}if(ne)for(let o=se(s.beats,h);o<s.beats.length;o++){const i=s.beats[o],f=i.time-h;if(f>pt)break;if(i.measure<0)continue;const l=kn(Hn(F),i.time),c=ut(f);t.globalAlpha=Math.min(1,(pt-f)/.4);for(const p of En)(p<l.fret||p>=l.fret+l.width)&&Gt(String(p),p-.5,c,io,so,H(n.inlay,ne))}t.globalAlpha=1,(n.guides===!1?[]:Hn(F).filter(o=>o.endTime>h&&o.time<h+pt)).forEach((o,i)=>{const f=ut(Math.max(0,o.time-h)),l=ut(Math.min(pt,o.endTime-h)),c=o.fret-1,p=c+o.width;t.fillStyle=Dt(n.anchorFill,n.anchorOpacity,.02),gt([[c,N,f],[p,N,f],[p,N,l],[c,N,l]]),J(),t.strokeStyle=Dt(n.anchorLane,.55,.04),t.lineWidth=Fo*.6;for(const T of[c,p])St([T,N,f],[T,N,l]);i&&o.time>h&&St([c,N,f],[p,N,f])});const u=new Map,g=o=>{const i=Math.round(o*100);return u.has(i)||u.set(i,{dt:o-h,texts:[],pins:[]}),u.get(i)};for(const o of s.markers??[])o.time>=h&&o.time<=h+pt&&!g(o.time).texts.includes(o.text)&&g(o.time).texts.push(o.text);for(const o of s.hairpins??[])o.time>=h&&o.time<=h+pt&&g(o.time).pins.push(o.kind);const L=Math.min(e.center-(e.span/2+.5)/le,-.5);for(const{dt:o,texts:i,pins:f}of u.values()){const[l,c,p]=A(L,N,ut(o)),T=Math.sqrt(p*qt),E=i.join(" · "),w=.25*T,C=`700 ${We}px ${n.num}`,At=.3*T/We,it=E?Kt(t,C,E).width*At:0,lt=it+f.length*(.9*T+w);ct(C);let U=Math.max(l-.3*T,16+lt);t.globalAlpha=Math.min(1,(pt-o)/.4),E&&(t.save(),t.translate(U,c),t.scale(At,At),t.textAlign="right",t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(E,0,0),t.fillStyle=n.accent,t.fillText(E,0,0),t.restore(),U-=it+w);for(const nt of f){const te=U-.9*T,V=.14*T,[xt,D]=nt==="cresc"?[te,U]:[U,te];for(const[Rt,Lt]of[[H(n.ink,.9),Math.max(3.5,.12*T)],[n.text,Math.max(1.5,.05*T)]])t.strokeStyle=Rt,t.lineWidth=Lt,t.beginPath(),t.moveTo(D,c-V),t.lineTo(xt,c),t.lineTo(D,c+V),q();U=te-w}}t.globalAlpha=1,Ve("floor");const S=[];for(let o=se(s.notes,h-uo(s).held-.3);o<s.notes.length;o++){const i=s.notes[o];if(i.time>h+pt)break;const f=Math.max(i.sustain,(i.slideTo??i.slideUnpitchTo??null)===null?0:.25,.15);i.time+f>=h-.05&&S.push(i)}const k=o=>o.chord===null||o.chord===void 0?null:s.chords[o.chord],_=o=>k(o)?.fretHandMute||n.repeatMarks==="frame"&&(o.repeat||k(o)?.highDensity);if(!s.palmRuns){const o={};for(const i of s.notes){const f=i.palmMute||k(i)?.palmMute;i.palmAgain=!!f&&i.time-(o[i.string]??-1/0)<.8,f&&(o[i.string]=i.time)}s.palmRuns=!0}const R=o=>{const i=kn(F,o.time),f=o.fret===0;return{a:i,open:f,x:f?i.fret-1+i.width/2:o.fret-.5,y:yt(o.string)}},st=(o,i,f)=>{const l=o.slideSpan??Math.max(o.sustain,.25),c=o.slideTo??o.slideUnpitchTo??null,p=Math.min(1,Math.max(0,f/l));return c===null||o.fret===0?i:i+(c-.5-i)*p*p*p*(p*(p*6-15)+10)},Pt=(o,i)=>(ai(o,i)*Z(o.string)+li(o,i))*G*Pn,ht=o=>{const i=h-o.time;return i<0||o.fret===0||!(rn(o)>0)?0:Pt(o,Math.min(i,Math.max(o.sustain,.15)))},et=new Map;for(const o of S){const i=o.time-h,f=Math.max(o.sustain,.15);i>0||-i>f||o.fret===0||!(rn(o)>0)||et.set(o.string,{note:o,x:o.fret-.5,dy:ht(o)})}const xe=(o,i=0,f=!1)=>{const l=et.get(o),c=yt(o)+i,p=f?[[0,c,0]]:[en?[en[o][0],en[o][1]+i,0]:[-.6,c,0],[0,c,0]];if(!l)return gt([...p,[de+.6,c,0]],!1);gt([...p,[l.x,c+l.dy,0],[de+.6,c,0]],!1)},Pe=o=>yt(o.string)+ht(o),ce=Vo[n.headstock],we=(K-Mt)/2,mn=n.stringOrder==="high"?-1:1,ue=([o,i])=>[-o*we/le,Ht/2+i*we*mn,0],wt=o=>(yt(o)-Ht/2)*mn/we,Xt=ce&&Qo(ce,Array.from({length:z},(o,i)=>wt(i))),en=Xt?.ends.map(ue),Qt=(o,i,f=1)=>{o&&(t.fillStyle=o,J()),i&&(t.strokeStyle=i,t.lineWidth=f,q())},sn=(o,i,f)=>{const[l,c]=ue(o),[p,T]=A(l,c,0),[E]=A(l+i*we/le,c,0),[,w]=A(l,c+f*we,0);t.beginPath(),t.ellipse(p,T,Math.abs(E-p),Math.abs(w-T),0,0,Math.PI*2)},dn=(o,i,f,l,c)=>gt(co(`${o},${i},${f},${l},${c}`,()=>ho(o,i,f,l,c)).map(ue)),qn=()=>{for(const{u:f,side:l,edge:c}of Xt.keys){const p=(T,E)=>[c+l*T,c+l*E];ce.keys==="machine"?(dn(f-.15,f+.15,...p(-.12,.08),.03),Qt(H(n.text,.12),H(n.anchorLane,.35)),dn(f-.03,f+.03,...p(.06,.22),0),Qt(H(n.text,.28)),dn(f-.11,f+.11,...p(.2,.68),.1),Qt(H(n.text,.18),H(n.anchorLane,.55))):(dn(f-.035,f+.035,...p(-.05,.22),0),Qt(H(n.text,.28)),sn([f,c+l*.18],.08,.04),Qt(H(n.text,.3)),sn([f,c+l*.4],.14,.2),Qt(H(n.text,.18),H(n.anchorLane,.55)))}gt(Xt.outline.map(ue));const[,o]=A(...ue([0,1.6])),[,i]=A(...ue([0,-1.2]));if(Qt(Mo(t,o,i,n.floor0,n.ink)),t.save(),t.clip(),Qt(null,H(n.text,.07),.3*we*qt),t.restore(),B(!0,n.anchorLane,8),Qt(null,H(n.anchorLane,.6),Math.max(1.5,.03*qt)),B(!1),ce.cover){gt(co(ce.cover,()=>mo(ce.cover)).map(ue)),Qt(H(n.text,.09),H(n.text,.4));for(const f of ce.screws)sn(f,.04,.04),Qt(H(n.nut,.85))}},zn=o=>eo*(.7+.14*(z-1-o)),Ro=()=>{if(e.plate?.key!==Ln||e.plate.t!==n)return e.plate={key:Ln,t:n},qn();const o=e.plate;if(!o.image){const[i,f]=[[],[]];for(const At of[...Xt.outline,...Xt.keys.map(({u:it,side:lt,edge:U})=>[it,U+lt*.8])]){const[it,lt]=A(...ue(At));i.push(it),f.push(lt)}const l=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,c=Math.min(x,Math.max(...i)+24),p=Math.floor(Math.max(0,Math.min(...f)-24)*d)/d,T=Math.min(Ae,Math.max(...f)+24);o.image=new OffscreenCanvas(Math.max(1,Math.ceil((c-l)*d)),Math.max(1,Math.ceil((T-p)*d)));const[E,w,C]=[t,y,I];[t,y,I,o.x,o.y]=[o.image.getContext("2d"),0,null,l,p],t.setTransform(d,0,0,d,-l*d,-p*d),t.lineCap=t.lineJoin="round",qn(),[t,y,I]=[E,w,C]}t.drawImage(o.image,o.x,o.y,o.image.width/d,o.image.height/d)},Gn=()=>{t.fillStyle=n.board,gt([[0,Mt,0],[de+.6,Mt,0],[de+.6,K,0],[0,K,0]]),J(),t.fillStyle=H(n.anchorFill,.16),gt([[e.left,Mt,0],[e.right,Mt,0],[e.right,K,0],[e.left,K,0]]),J(),t.fillStyle=n.inlayDot;const o=l=>(Math.max(0,Math.ceil(l)-1)+.5)*G;t.beginPath();for(const l of En)for(const c of l%12?[o((z-1)/2)]:[o((z-1)/4),Ht-o((z-1)/4)]){const[p,T,E]=A(l-.5,c,0);t.moveTo(p+.1*E,T),t.ellipse(p,T,.1*E,.08*E,0,0,Math.PI*2)}J(),X>0&&(t.fillStyle=H(n.ink,.5),gt([[0,Mt,0],[X-Bn,Mt,0],[X-Bn,K,0],[0,K,0]]),J()),Xt&&Ro();const[,i]=A(Ft[0],K,0),[,f]=A(Ft[0],Mt,0);t.strokeStyle=Mo(t,i,f,H(n.anchorPost,.75),n.post),t.lineWidth=Math.max(1.5,.05*qt),t.beginPath();for(let l=1;l<=de;l++)fe([l,Mt-.04,0],[l,K+.04,0]);q(),t.strokeStyle=n.nut,t.lineWidth=Math.max(3,.12*qt),St([0,Mt-.06,0],[0,K+.06,0]),B(!0,n.anchorPost,12),t.strokeStyle=n.anchorPost,t.lineWidth=Math.max(3,.07*qt);for(const l of[e.left,e.right])St([l,Mt-.14,0],[l,K+.14,0]);B(!1);for(let l=0;l<z;l++){const c=zn(l);B(!0,It(l),3),t.strokeStyle=H(It(l),.9),t.lineWidth=c,xe(l),q(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=Math.max(.6,c*.3),xe(l,.012),q()}if(Xt&&(Xt.ends.forEach(([l,c],p)=>{if(ce.clamps)dn(l-.1,l+.1,c-.1,c+.1,.04),Qt(H(n.text,.22),H(n.text,.45)),sn([l,c],.05,.05),Qt(n.nut);else{sn([l,c],.17,.17),Qt(H(n.ink,.5),H(n.nut,.4)),sn([l,c],.085,.085),Qt(n.nut),sn([l,c],.03,.03),Qt(H(n.ink,.85));const[T,E,w]=A(...en[p]),[C,At]=A(0,yt(p),0),it=Math.atan2(At-E,C-T);t.beginPath(),t.arc(T,E,.1*we*w,it-1.3,it+1.3),Qt(null,It(p),zn(p))}}),ce.tree)){const l=[z-2,z-1].map(c=>{const[p,T]=Xt.ends[c];return wt(c)+(T-wt(c))*ce.tree/p});dn(ce.tree-.05,ce.tree+.05,Math.min(...l)-.08,Math.max(...l)+.08,.04),Qt(H(n.nut,.7),H(n.ink,.6))}for(const l of[!1,!0])for(let c=1;c<=de;c++){const p=c>=_t.fret&&c<_t.fret+_t.width,T=En.includes(c);(p||T)===l&&Yt(String(c),c-.5,Mt-.3,0,p?.3:T?.26:.2,p?n.accent:T?n.inlay:n.numOff,l?800:500,"center",!1)}},Mn=(o,i)=>A(o,i,0).slice(0,2).map(f=>Math.round(f*d*10)).join(":"),Ln=[n.headstock,z,G,mn,x,d,Math.round(le*1e4),Mn(0,Mt),Mn(de,Mt),Mn(0,K),Mn(de,K),Mn(-4,Ht/2)].join(),Sn=!et.size&&[Ln,_t.fret,_t.width,X,Math.round(e.left*1e3),Math.round(e.right*1e3)].join();if(!Sn||e.board?.key!==Sn||e.board.t!==n)e.board=Sn&&{key:Sn,t:n},Gn();else{const o=e.board;if(!o.drawn){const i=[[0,K+.2],[de,K+.2],[0,Mt-.9],[de,Mt-.9]].map(([T,E])=>A(T,E,0)[1]);Xt&&i.push(...[...Xt.outline,...Xt.keys.map(({u:T,side:E,edge:w})=>[T,w+E*.8])].map(T=>A(...ue(T))[1]));const f=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,l=Math.min(Ae,Math.max(...i)+24),[c,p]=[Math.ceil(x*d),Math.max(1,Math.ceil((l-f)*d))];(e.boardImage?.width!==c||e.boardImage.height!==p)&&(e.boardImage=new OffscreenCanvas(c,p)),[t,y,I,o.y,o.drawn]=[e.boardImage.getContext("2d"),f,null,f,!0],t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,c,p),Nt(),t.lineCap=t.lineJoin="round",t.textBaseline="middle",Gn(),[t,y,I]=[r,0,null]}t.drawImage(e.boardImage,0,o.y,e.boardImage.width/d,e.boardImage.height/d)}Ve("board");const Un=(o,i)=>o.letRing&&-i>.25;for(const o of S){const i=o.time-h;if(i>0||-i>Math.max(o.sustain,.15)||o.mute)continue;const f=It(o.string),l=Pe(o);if(B(!Un(o,i),f,10),t.strokeStyle=f,t.lineWidth=eo+3,xe(o.string,0,!0),q(),B(!1),-i<.2){const[c,p,T]=A(R(o).x,l,0);t.save(),t.translate(c,p),t.scale(1,.4);const E=t.createRadialGradient(0,0,0,0,0,.5*T);E.addColorStop(0,H(n.flash,.8*(1+i/.2))),E.addColorStop(1,H(n.flash,0)),t.fillStyle=E,t.beginPath(),t.arc(0,0,.5*T,0,Math.PI*2),J(),t.restore()}}t.strokeStyle=n.anchorLane,t.lineWidth=2.5,B(!0,n.anchorLane,10);for(const o of s.handShapes??[]){if(o.startTime>h||o.endTime<=h||o.endTime-o.startTime<.3||!o.frets.some((l,c)=>l>=0&&c<z))continue;const[i,f]=Je(o.frets.filter((l,c)=>c<z),o.startTime);gt([[i,Mt,0],[f,Mt,0],[f,K,0],[i,K,0]]),q()}if(B(!1),X>0){const o=X-Bn;t.strokeStyle=n.nut,t.lineWidth=Math.max(4,.17*qt),St([o,Mt-.16,0],[o,K+.16,0]),t.strokeStyle=H(n.ink,.45),t.lineWidth=Math.max(1,.05*qt),St([o,Mt-.13,0],[o,K+.13,0])}Ve("strings");for(const o of S){const i=o.time-h,f=ut(i),l=k(o),{a:c,open:p,x:T,y:E}=R(o),w=st(o,T,-i);if(i<-.15||o.tied||Math.abs(A(w,E,f)[0]-x/2)>x/2+200)continue;const C=p?(c.width-.2)/2:.34;t.globalAlpha=i<0?Math.max(0,1+i/.15):Math.min(1,(pt-i)/.4),!l&&Jt&&(t.strokeStyle=Jt,t.lineWidth=2,St([w-C,N,f],[w+C,N,f])),!(p||_(o))&&(t.strokeStyle=H(It(o.string),o.repeat||l?.highDensity?.35:.75),t.lineWidth=1.5,St([w,Math.min(E,Pe(o))-.42*G,f],[w,N,f]))}t.globalAlpha=1;const Eo=(o,i,f)=>{const l=Array.from({length:13},(c,p)=>{const T=p/12;return[o[0]+(i[0]-o[0])*T,o[1]+(i[1]-o[1])*T+Math.sin(Math.PI*T)*f,o[2]+(i[2]-o[2])*T]});gt(l,!1),q()};for(const o of hi(s)){if(o.end<=h||o.time>=h+pt)continue;const[i,f]=Je(o.frets,o.time),l=o.time-h,c=ut(Math.max(l,0)),p=ut(Math.min(o.end-h,pt));t.globalAlpha=Math.min(1,(pt-Math.max(l,0))/.4),B(!o.arpeggio,n.anchorLane,10,!0),t.strokeStyle=Dt(n.anchorLane,1,.2),t.lineWidth=3.5;for(const T of[i,f])St([T,N,c],[T,N,p]);B(!1),o.arpeggio&&l>0&&(t.strokeStyle=H(n.anchorLane,.7),t.lineWidth=1.5,gt([[i,N,c],[i,K,c],[f,K,c],[f,N,c]],!1),q(),o.arpeggio.name&&c>gn&&Yt(o.arpeggio.name,i-.12,K/2,c,.34,n.text,600,"right"))}t.globalAlpha=1;const Cn=(o,i)=>{const f=R(o);return Math.abs(f.x-i)<(f.open?(f.a.width-.2)/2+.1:.45)};for(const[o,i]of S.entries()){const f=i.time-h,l=k(i),c=i.slideTo??i.slideUnpitchTo??null,{a:p,open:T,x:E,y:w}=R(i),C=It(i.string),At=ut(f),it=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),lt=(T?.12:.42)*G*(i.grace?.6:1);f>-.15&&!l?.highDensity&&!i.repeat&&(t.globalAlpha=Math.min(1,(pt-f)/.4),t.strokeStyle=C,t.lineWidth=2,t.setLineDash([4,4]),i.slideIn&&St([E+(i.slideIn==="below"?-1.4:1.4),w-lt,Math.max(0,At-1)],[E+(i.slideIn==="below"?-it:it),w,At]),i.slideOut&&St([E+(i.slideOut==="up"?it:-it),w,At],[E+(i.slideOut==="up"?1.4:-1.4),w-lt,At+1]),t.setLineDash([]),t.globalAlpha=1);const U=c===null?i.sustain:Math.max(i.sustain,.25),nt=c!==null||i.bend||i.bendCurve||i.whammy,te=i.tied||typeof i.tieTo=="number";if(U<=.2&&!te||f+U<=0||l&&!nt&&!te||_(i))continue;T&&c&&(t.strokeStyle=C,t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]),Eo([E,w,ut(Math.max(f,0))],[c-.5,w,ut(Math.min(f+U,pt))],G*1.5),t.setLineDash([]));let V=null;for(let dt=o+1;dt<S.length&&S[dt].time<=i.time+U+.02;dt++){const b=S[dt];if(!(b.time<=i.time+.005)&&(k(b)||b.string===i.string||Cn(b,E))){V=b;break}}const xt=Math.max(f,0),D=i.bend||i.bendCurve||i.whammy,Rt=c!==null&&i.slideTo===null;let Lt=Math.min(f+U,pt,V?V.time-h:1/0);if(Lt<=xt)continue;const Wt=dt=>{const b=dt-f,$=ut(dt),j=i.bend||i.bendCurve||i.whammy,rt=i.vibrato&&!j?Math.sin($/1.6*Math.PI*2)*G*(i.vibratoWide?.45:.25):0,$t=i.tremolo?Math.floor($/.3)%2?.05:-.05:0,Me=Pn+(Go-Pn)*yo(Math.min(1,$/Uo));return[st(i,E,b)+$t,w+rt+Pt(i,b)*Me/Pn,$]},an=V&&Wt(Lt)[0],nn=V&&k(V)?.notes.find(dt=>Cn(s.notes[dt],an)),Ge=typeof nn=="number"?s.notes[nn]:V;if(V&&!V.tied&&(D||Cn(Ge,an))){const dt=R(Ge),b=ut(Ge.time-h),$=dt.open?(dt.a.width-.2)/2:.34,j=A(dt.x,dt.y-(dt.open?.12:.42)*G,b)[1]+3,[rt]=A(dt.x-$,dt.y,b),[$t]=A(dt.x+$,dt.y,b),Me=He=>{const[mt,jt]=A(...Wt(He));return jt<j&&mt>Math.min(rt,$t)-2&&mt<Math.max(rt,$t)+2};if(Me(Lt)&&!Me(xt)){let He=xt,mt=Lt;for(let jt=0;jt<24;jt++)[He,mt]=Me((He+mt)/2)?[He,(He+mt)/2]:[(He+mt)/2,mt];Lt=He}if(Lt<=xt+.001)continue}const ln=c===null&&!D&&!i.vibrato&&!i.tremolo?1:Math.min(400,Math.max(12,Math.ceil((Lt-xt)*P*8))),ie=Array.from({length:ln+1},(dt,b)=>Wt(xt+(Lt-xt)*b/ln));if(T&&!l){t.fillStyle=Dt(C,i.letRing?.14:.26,.03),gt([...ie.map(([dt,b,$])=>[dt-it,b,$]),...ie.slice().reverse().map(([dt,b,$])=>[dt+it,b,$])]),J(),B(!i.letRing,C,6,!0),t.strokeStyle=Dt(C,.95,.3),t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]);for(const dt of[-it,it])gt(ie.map(([b,$,j])=>[b+dt,$,j]),!1),q();t.setLineDash([]),B(!1)}else if(i.bend||i.bendCurve||i.whammy){const dt=b=>gt([...ie.map(([$,j,rt])=>[$-b,j,rt]),...ie.slice().reverse().map(([$,j,rt])=>[$+b,j,rt])]);dt(pn),t.fillStyle=Dt(C,1,.6),J(),dt(pn*.35),t.fillStyle=Dt(Tn(C,-.22),1,.55),J(),B(!0,C,8,!0),t.strokeStyle=Dt(Tn(C,.6),1,.5),t.lineWidth=2;for(const b of[-pn,pn])gt(ie.map(([$,j,rt])=>[$+b,j,rt]),!1),q();B(!1)}else{B(!i.letRing,C,6,!0);const dt=b=>Rt?pn*Math.min(1,2*(1-b/(ie.length-1))):pn;gt([...ie.map(([b,$,j],rt)=>[b-dt(rt),$,j]),...ie.map(([b,$,j],rt)=>[b+dt(rt),$,j]).reverse()],!1),t.fillStyle=Rt?Dt(C,.9,0):Dt(C,i.letRing?.5:.9,i.letRing?.2:.45),J(),t.strokeStyle=Rt?Dt(Tn(C,.6),.85,0):Dt(Tn(C,.6),1,.5),t.lineWidth=2,t.setLineDash(i.letRing?[7,6]:[]),q(),t.setLineDash([]),B(!1)}}Ve("trails");const Xn=new Set;for(let o=S.length-1;o>=0;o--){const i=S[o],f=i.time-h,l=ut(f),c=k(i),{a:p,open:T,x:E}=R(i),w=st(i,E,-f),C=Pe(i),At=i.mute||c?.fretHandMute,it=i.palmMute||c?.palmMute,lt=It(i.string),U=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),nt=(T?.12:.42)*G*(i.grace?.6:1);if(f<-.15)continue;const te=f<0?Math.max(0,1+f/.15):Math.min(1,(pt-f)/.4);if(t.globalAlpha=te,c&&!Xn.has(i.chord)){Xn.add(i.chord);const[b,$]=Je(c.notes.map(mt=>s.notes[mt].fret),i.time),j=t.globalAlpha,rt=l<gn,$t=rt?.65:c.highDensity&&n.repeatMarks!=="frame"?.18:.5;if(gt([[b,N,l],[$,N,l],[$,K,l],[b,K,l]]),n.frames==="gradient"){const[,mt]=A(b,N,l),[,jt]=A(b,K,l),me=rt?n.anchorLane:n.anchorFill;kt(xo(t,`${me}|${$t}`,[[0,H(me,$t*.6)],[1,H(me,0)]]),mt,jt)}else t.globalAlpha=j*$t,c.highDensity||(t.fillStyle=n.chordFill,J()),t.strokeStyle=rt?n.anchorLane:n.chordBox,t.lineWidth=rt||!c.highDensity?1.5:1.2,B(rt,n.anchorLane,8),q(),B(!1);if(t.globalAlpha=j,t.strokeStyle=Jt,t.lineWidth=2,Jt&&St([b,N,l],[$,N,l]),c.fretHandMute&&n.repeatMarks!=="hide"){const[,,mt]=A((b+$)/2,N,l),jt=(b+$)/2,me=(N+K)/2,Ue=($-b)/2*.78,be=(K-N)/2*.72;t.strokeStyle="rgba(255, 255, 255, 0.28)",t.lineWidth=Math.max(3,.28*mt),t.lineCap="round",M(jt,me,l,Ue,be),t.lineCap="butt"}if(c.accent){const mt=Math.min(.6,($-b)*.22),jt=(K-N)*.35,me=Math.min(1,A(b,K,l)[2]/A(b,K,gn)[2]);t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,3.5*me*(c.accent==="heavy"?1.4:1)),t.lineCap="square",B(!0,"#ffffff",Math.max(2,12*me)),gt([[b,K-jt,l],[b,K,l],[b+mt,K,l]],!1),q(),gt([[$-mt,K,l],[$,K,l],[$,K-jt,l]],!1),q(),B(!1),t.lineCap="round"}if(c.barre&&(!c.highDensity||n.repeatMarks==="grey")){const mt=c.barre.fret-.5;t.strokeStyle=c.highDensity?n.muted:"rgba(255, 255, 255, 0.7)",t.lineWidth=Math.max(3,.1*A(mt,Ht/2,l)[2]);const[jt,me]=[yt(c.barre.from),yt(c.barre.to)].sort((Ue,be)=>Ue-be);St([mt,jt-G*.4,l],[mt,me+G*.4,l]),Yt(c.barre.half?"½B":"B",mt,K+.12,l,.22,c.highDensity?n.muted:n.text)}if(c.strum||c.roll){const mt=b-.25,jt=yt(0)>yt(z-1)?K-.1:N+.15,me=jt>Ht/2?N+.15:K-.1,[Ue,be]=(c.strum??c.roll)==="down"?[jt,me]:[me,jt];t.strokeStyle=n.text,t.lineWidth=2,c.roll?gt(Array.from({length:17},(ui,Zn)=>[mt+Math.sin(Zn/16*Math.PI*6)*.06,Ue+(be-Ue)*Zn/16,l]),!1):gt([[mt,Ue,l],[mt,be,l]],!1),q();const un=be<Ue?.14:-.14;St([mt-.08,be+un,l],[mt,be,l]),St([mt+.08,be+un,l],[mt,be,l])}const Me=s.chords[i.chord-1],He=!Me||i.time-Me.time>1||Me.name!==c.name;l>gn&&c.name&&!c.highDensity&&He&&Yt(c.name,b-.12,K/2,l,.34,n.text,600,"right")}const[V,xt,D]=A(w,C,l);if(V<-200||V>x+200||_(i)){it&&V>=-200&&V<=x+200&&n.repeatMarks!=="hide"&&v(w,C,l,D,T?(p.width-.2)/2:.34,(T?.12:.42)*G*(i.palmAgain?.5:1),!0,n.muted),t.globalAlpha=1;continue}const Rt=i.repeat||c?.highDensity;if(Rt){const b=l<gn;t.globalAlpha*=b?.9:.4,t.strokeStyle=lt,t.lineWidth=b?2:1.5,B(b,lt,8),Ee(w,C,l,U,nt),q(),B(!1),(it||i.mute&&!c?.fretHandMute)&&n.repeatMarks!=="hide"&&v(w,C,l,D,T?.34:U,(T?G*.3:nt)*(i.palmAgain?.5:1),it,n.muted),t.globalAlpha=te}else if(!i.tied){if(!T&&ne){const b=i.harmonic||i.harmonicPinch?`<${i.fret}>`:i.ghost?`(${i.fret})`:String(i.fret),$=i.grace?.7:1;Gt(b,w,l,io*$,so*$,H(lt,ne))}if(i.dynamicLabel&&Yt(i.dynamicLabel,w-.6,N,l,.3,n.text,"italic 700","right"),i.ghost&&(t.globalAlpha=te*.5),n.gem==="pill")n.notes3d!==!1&&(Ee(w,C,l+no,U,nt),t.fillStyle=lt,J(),t.fillStyle="rgba(255, 255, 255, 0.35)",J()),Ee(w,C,l,U,nt),t.fillStyle=lt,J();else{const b=i.harmonic||i.harmonicPinch,$=no;if(!b&&n.notes3d!==!1)for(const[$t,Me]of[[[[w-U,C+nt,l],[w+U,C+nt,l],[w+U,C+nt,l+$],[w-U,C+nt,l+$]],"rgba(255, 255, 255, 0.35)"],[[[w-U,C-nt,l],[w-U,C+nt,l],[w-U,C+nt,l+$],[w-U,C-nt,l+$]],"rgba(0, 0, 0, 0.4)"],[[[w+U,C-nt,l],[w+U,C+nt,l],[w+U,C+nt,l+$],[w+U,C-nt,l+$]],"rgba(0, 0, 0, 0.4)"]])gt($t),t.fillStyle=lt,J(),t.fillStyle=Me,J();B(l<gn,lt,8),t.fillStyle=lt,b?gt([[w,C+nt*1.3,l],[w+U*.8,C,l],[w,C-nt*1.3,l],[w-U*.8,C,l]]):Ee(w,C,l,U,nt),J(),B(!1);const[,j]=A(w,C+nt,l),[,rt]=A(w,C-nt,l);kt(xo(t,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),j,rt),t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=1,q()}if((it||i.mute&&!c?.fretHandMute)&&v(w,C,l,D,T?.34:U,(T?G*.3:nt)*(i.palmAgain?.5:1),it,T&&it?lt:null),!T&&!At&&!it){const b=i.finger??(c?.fingers?.[i.string]>=0?c.fingers[i.string]:null),$=b!==null?b===0?"T":String(b):"";if($){const j=t.globalAlpha;t.globalAlpha=j*Math.min(1,Math.max(0,(1-f/pt)/.4)),Yt($,w,C,l-.01,G*.62,Y,700,"center",m,!0),t.globalAlpha=j}}}if(Rt&&n.repeatMarks==="hide"){t.globalAlpha=1;continue}const Lt=Rt?n.muted:n.text;if(t.globalAlpha=te*(Rt?.8:1)*Math.min(1,Math.max(0,(1-f/pt)/.15)),i.ghost){const[b]=A(w-U,C,l),[$]=A(w+U,C,l),j=nt*D*1.5;t.strokeStyle=Rt?Lt:lt,t.lineWidth=Math.max(1.2,.035*D),t.beginPath(),t.arc(b+j*.35,xt,j,Math.PI*.7,Math.PI*1.3),q(),t.beginPath(),t.arc($-j*.35,xt,j,-Math.PI*.3,Math.PI*.3),q()}if(i.grace&&(t.strokeStyle=Lt,t.lineWidth=Math.max(1,.03*D),Io(t,V-U*D*le*1.2,xt+nt*D*1.4,V+U*D*le*1.2,xt-nt*D*1.4)),i.showString){const[b]=A(w-U,C,l),$=.12*D,j=b-$-.06*D;t.strokeStyle=t.fillStyle=Rt?Lt:lt,t.lineWidth=Math.max(1,.025*D),t.beginPath(),t.arc(j,xt,$,0,Math.PI*2),q(),bt(String(z-i.string),j,xt,.15*D,700,"center"),t.fillText(String(z-i.string),0,0),Nt()}let Wt=xt-nt*D-.18*D;t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D),t.textAlign="center";const an=(b,$,j)=>{t.beginPath();for(let rt=0;rt<=20;rt++)t[rt?"lineTo":"moveTo"](V-b+2*b*rt/20,Wt+Math.sin(rt/20*Math.PI*2*j)*$);q()},nn=(b,$,j="700")=>{$*D<2||(bt(b,V,Wt,$*D,j,"center"),t.fillText(b,0,0),Nt(),Wt-=($+.04)*D)};let Ge=xt-nt*D;const Rn=i.tap&&!i.tapLeft;if((i.hammerOn||i.pullOff)&&!Rn&&!i.tied){const b=i.grace?.6:1,$=.34*D*le*b,j=.72*G*D*b,[rt,$t]=i.hammerOn?[xt+j/2,xt-j/2]:[xt-j/2,xt+j/2];t.beginPath(),t.moveTo(V-$,$t),t.lineTo(V+$,$t),t.lineTo(V,rt),t.closePath(),t.fillStyle=Rt?Lt:"#ffffff",t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(2,.04*D),q(),J(),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}if(Rn&&!i.tied){const b=i.grace?.6:1,$=.28*D*le*b,j=.62*G*D*b,rt=Ge+.15*j,$t=rt-j;t.beginPath(),t.moveTo(V,rt),t.lineTo(V+$,$t),t.lineTo(V,$t+.38*j),t.lineTo(V-$,$t),t.closePath(),t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(3.5,.1*D),q(),t.fillStyle=Rt?H(Lt,.4):H(Tn(lt,.55),.85),J(),t.strokeStyle=Rt?Lt:lt,t.lineWidth=Math.max(1.8,.05*D),q(),Ge=$t,Wt=Math.min(Wt,Ge-.14*D),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}const ln=rn(i);if(ln>0){const b=i.bendCurve?.[0]?.[1]>0,$=(i.bendCurve?.length??0)>1&&i.bendCurve.at(-1)[1]<ln,j=Math.min(3,Math.max(1,Math.round(ln*2))),rt=U*D*le*.6,$t=U*D*.3,Me=$t*1.25,He=H(n.ink,.9);let mt=Ge-.04*D;const jt=be=>{for(let un=0;un<j;un++)$o(t,V,mt-un*Me-(be>0?0:$t),rt,$t,be,Rt?Lt:lt,He);mt-=j*Me+.08*D},me=Z(i.string);(!b||!$)&&jt(-me),$&&jt(me);const Ue=`${b?"pre ":""}${Fn(ln)}`;t.fillStyle=Lt,bt(Ue,V+rt+.08*D,(xt-nt*D+mt)/2,.22*D,700,"left"),t.fillText(Ue,0,0),Nt(),t.textAlign="center",Wt=Math.min(Wt,mt-.1*D)}i.staccato&&(t.beginPath(),t.arc(V,Wt+.04*D,Math.max(1.5,.045*D),0,Math.PI*2),J(),Wt-=.16*D);const ie=!i.tied;ie&&i.accent&&(i.accent==="tenuto"||!c?.accent)&&nn({heavy:"^",tenuto:"–"}[i.accent]??">",.3);const dt=[ie&&i.tapLeft?"m.g.":"",Po[i.harmonicType]??(ie&&i.harmonicPinch?"PH":""),ie&&(i.slap?"slap":i.pop?"pop":""),ie&&i.golpe?`golpe (${i.golpe})`:"",ie&&i.rasgueado?`rasg. ${i.rasgueado}`:"",typeof i.trill=="number"?`tr ${i.trill}`:"",i.ornament??"",i.fade??"",i.whammy?"w/bar":"",i.wah==="open"?"o":i.wah==="closed"?"+":""];for(const b of dt)b&&nn(b,b.length>2?.22:.28);if(ie&&i.rightFinger&&nn(i.rightFinger,.26,"italic 700"),i.pick){const b=.09*D,$=.13*D;t.beginPath(),i.pick==="down"?[[-b,$/2],[-b,-$/2],[b,-$/2],[b,$/2]].forEach(([j,rt],$t)=>t[$t?"lineTo":"moveTo"](V+j,Wt+rt)):[[-b,-$/2],[0,$/2],[b,-$/2]].forEach(([j,rt],$t)=>t[$t?"lineTo":"moveTo"](V+j,Wt+rt)),q(),Wt-=.22*D}if(i.fermata&&(t.beginPath(),t.arc(V,Wt+.06*D,.14*D,Math.PI,0),q(),t.beginPath(),t.arc(V,Wt+.02*D,Math.max(1.5,.03*D),0,Math.PI*2),J(),Wt-=.24*D),i.tremolo){for(let b=-1;b<=1;b++)Io(t,V-.12*D,Wt+(b*.08+.05)*D,V+.12*D,Wt+(b*.08-.05)*D);Wt-=.3*D,an(.14*D,.04*D,1.5),Wt-=.14*D}t.globalAlpha=1}Ve("notes");const jn=new Set;for(const o of S){const i=o.time-h,f=k(o);if(!f?.barre||jn.has(f)||i>.06||i<-Math.max(o.sustain,.12))continue;jn.add(f),t.strokeStyle="rgba(255, 255, 255, 0.85)",t.lineWidth=Math.max(4,.12*qt);const[l,c]=[yt(f.barre.from),yt(f.barre.to)].sort((p,T)=>p-T);St([f.barre.fret-.5,l-G*.45,0],[f.barre.fret-.5,c+G*.45,0])}const Kn=new Set,Jn=new Set;for(const o of S){const i=o.time-h,f=k(o),l=et.get(o.string),c=o.heldFrom??null,p=i<=.06||c!==null&&h>=c-.06,T=(o.slideTo??o.slideUnpitchTo??null)!==null;if(o.mute||i>vn||i<-Math.max(o.sustain,T?.25:.12)||(f?.highDensity||c!==null)&&!p||l&&l.note!==o&&!p||p&&Kn.has(`${o.string}:${o.fret}`))continue;p&&Kn.add(`${o.string}:${o.fret}`),Jn.add(`${o.string}:${o.fret}`);const{a:E,open:w,x:C}=R(o),At=st(o,C,-i),it=Pe(o),lt=It(o.string),U=(w?(E.width-.2)/2:.32)+2/qt,nt=(w?.1:.36)*G+2/qt;if(Ee(At,it,0,U,nt),p)B(!Un(o,i),lt,14),t.fillStyle=lt,J(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.7)",t.lineWidth=1.5,q();else{const V=(1-i/vn)**2;t.globalAlpha=.35*V,t.fillStyle=lt,J(),t.globalAlpha=.25+.75*V,t.strokeStyle=lt,t.lineWidth=2.2,q()}const te=o.finger??(f?.fingers?.[o.string]>=0?f.fingers[o.string]:null);if(!w&&te!==null&&Yt(te===0?"T":String(te),At,it,0,G*.55,p?Y:n.text,800,"center",!p||m),!w&&rn(o)>0){const V=Z(o.string),xt=o.bendCurve?.[0]?.[1]>0&&o.bendCurve.at(-1)[1]<rn(o),[D,Rt]=A(At,it+V*nt,0);$o(t,D,Rt-V*(xt?.14:.05)*qt,.17*qt*le,.085*qt,(xt?1:-1)*V,"#ffffff",H(n.ink,.9))}t.globalAlpha=1}for(const o of s.handShapes??[])!o.arpeggio||o.startTime-h>vn||o.endTime<=h||(t.globalAlpha=.3+.5*Math.min(1,1-(o.startTime-h)/vn)**2,o.frets.forEach((i,f)=>{if(i<=0||f>=z||Jn.has(`${f}:${i}`))return;const l=i-.5,c=yt(f),p=o.fingers[f];Ee(l,c,0,.32+2/qt,.36*G+2/qt),t.strokeStyle=It(f),t.lineWidth=2.2,q(),p>=0&&Yt(p===0?"T":String(p),l,c,0,G*.55,n.text,800)}),t.globalAlpha=1);Ve("targets");const Vn=ri(s),On=Vn.findLast(o=>o.time<=h&&h<o.end+.3),Bo=On?null:Vn.find(o=>o.time>h&&o.time-h<1.2),bn=On??Bo;if(bn){const[o,i]=A(e.right+.4,K+.5,0),f=Kt(t,Q[700]??=`700 ${We}px ${n.num}`,bn.name).width*52/We;t.globalAlpha=On?1:Math.max(.35,1-(bn.time-h)/1.2),t.fillStyle=n.text,bt(bn.name,Math.min(o,x-24-f),i,52,700,"left"),t.fillText(bn.name,0,0),Nt(),t.globalAlpha=1}Ve("labels")}const Do=298,ci=240,mi=64,Ke=100,Fe=24,Lo=150;function Co(a,s){if(a.tabPages?.length===s)return a.tabPages.pages;const h=a.notes.at(-1),n=Math.max(h?h.time+h.sustain:0,a.beats.at(-1)?.time??0)+.5;let e=a.beats.filter(d=>d.measure>=0).map(d=>d.time);e.length<2&&(e=Array.from({length:Math.ceil(n/s)+1},(d,t)=>t*s)),e=[Math.min(0,e[0]),...e.filter(d=>d>0),Math.max(n,e.at(-1)+.01)];const r=[];let x=e[0];for(let d=1;d<e.length;d++)e[d]-x>s&&e[d-1]>x&&r.push({start:x,end:x=e[d-1]});r.push({start:x,end:e.at(-1)});for(let d=0;d<r.length-1;d++)r[d].end=r[d+1].start;return a.tabPages={length:s,pages:r},r}const Yn=(a,s)=>a.str[s%a.str.length],Oo=110,di=15.75;function Mi(a,s,h,n,e={}){const{g:r,W:x}=Nn(a);if(!s)return;const d=s.strings,t=di*(n.boardHeight??1),F=t*(d-1),X=(n.tabMarks??"all")==="all",_t=n.paper==="light",z=_t?"#15181f":n.text,Et=_t?"#5c6472":n.muted,G=Fe+46,Ht=x-Fe-16,yt=Ht-G,Z=!!n.sheetNotes,P=t*.6,pt=Z&&typeof document<"u"&&!!document.fonts?.check(`${4*P}px "Noto Music"`,"𝄠"),Mt=v=>(Math.floor(v/12)-1)*7+[0,0,1,1,2,3,3,4,4,5,5,6][v%12];if(Z&&!s.sheetRange){let v=38;for(const I of s.notes)v=Math.max(v,Mt((s.open?.[I.string]??40)+I.fret+12));s.sheetRange={over:Math.max(2,Math.ceil((v-38)/2)+1),under:Math.max(6,Math.floor((30-Mt((s.open?.[0]??40)+12))/2)+2.5)}}const K=Z?s.sheetRange.over:0,N=Z?s.sheetRange.under:0,Tt=Z?P*(K+4+N):0,ut=s.lyrics?.length?t*1.3:0,It=n.tabMarks!=="notes",Jt=44+Tt,ne=t*1.3,ye=Math.max(2,t*.16),Ft=Jt+F+(Z?t:ne)+ut+t*2.8,oe=Z?s.keys?.findLast(v=>v.time<=h)?.fifths??0:0,ge=oe<0,Ze=`${4*P}px "Noto Music"`,Te={1:["♯",.9],"-1":["♭",.8],0:["♮",.7]},ke=Z?P*(.6+2.84+.5+Math.abs(oe)*1.15+1):0,Ne=ge?[0,1,1,2,2,3,4,4,5,5,6,6]:[0,0,1,1,2,3,3,4,4,5,5,6],Se=ge?[0,-1,0,-1,0,0,-1,0,-1,0,-1,0]:[0,1,0,1,0,0,1,0,1,0,1,0],Ye=[0,0,0,0,0,0,0];for(let v=0;v<Math.abs(oe);v++)Ye[(ge?[6,2,5,1,4,0,3]:[3,0,4,1,5,2,6])[v]]=ge?-1:1;const $e=new Path2D,O=[];if(Z&&!s.sheetShortest){let v=1/0;const I=s.rhythm??[];for(let y=1;y<I.length;y++)I[y].time-I[y-1].time>.001&&(v=Math.min(v,I[y].time-I[y-1].time));s.sheetShortest=v}const ft=Z&&s.sheetShortest<1/0?Math.max(Oo,1.75*P/s.sheetShortest):Oo,tt=Co(s,(yt-ke)/ft),Ct=Math.max(0,tt.findLastIndex(v=>v.start<=h)),Ot=Do,ae=Ae-66,Ie=ae-Ot-22>=2*Ft?1:0;(e.sheetY===void 0||n.sheetScroll!=="manual"&&e.sheetAt!==Ct)&&(e.sheetY=Math.max(0,Ct-Ie)*Ft),e.sheetAt=Ct,e.sheetY=Math.min(Math.max(0,e.sheetY),Math.max(0,tt.length*Ft+22-(ae-Ot)));const le=Ot+22-e.sheetY,re=s.rhythm??[],ve=(d-1)/2;r.save(),r.beginPath(),r.rect(Fe,Ot,x-Fe*2,ae-Ot),r.clip();const Vt=(v,I)=>v+(n.stringOrder==="high"?d-1-I:I)*t,Xe=`700 ${ee(t*.95)}px ${n.num}`,qe=`600 ${ee(10.5)}px ${n.ui}`,De=`700 ${ee(t*.55)}px ${n.num}`,hn=`italic 600 ${ee(11.5)}px ${n.ui}`,Le=new Path2D,Ce=new Path2D,fn=new Path2D,Qe=new Path2D,pe=new Path2D,Zt=new Path2D,ze=new Path2D,A=new Path2D,on=new Path2D,Oe=`600 ${ee(9.5)}px ${n.ui}`,qt=`600 ${ee(12)}px ${n.num}`,cn=v=>v.chord===null||v.chord===void 0?null:s.chords?.[v.chord],Re=v=>v.value>=8?Math.round(Math.log2(v.value))-2:0,he=[],gt=[],St=[],Ee=[],Je=[],M={box:null,x:null},m=new Set((s.markers??[]).filter(v=>v.text.startsWith("repeat")).map(v=>Math.round(v.time*50))),Y=new Map((s.meters??[]).map(v=>[Math.round(v.time*50),v.text]));r.textAlign="center";for(let v=0;v<tt.length;v++){const I=le+v*Ft;if(I+Ft<Ot)continue;if(I>ae)break;const y=tt[v],ct=(yt-ke)/(y.end-y.start),Q=W=>G+ke+(W-y.start)*ct,bt=I+Jt,Nt=bt+F,kt=Nt+5+ne,Yt=bt-P*N,Gt=Yt-4*P,zt=W=>Yt-(W-30)*P/2,vt=Z?Gt-P*K:bt;for(let W=0;W<d;W++)Le.moveTo(G,Vt(bt,W)),Le.lineTo(Ht,Vt(bt,W));if(Z){for(let g=0;g<5;g++)Le.moveTo(G,Gt+g*P),Le.lineTo(Ht,Gt+g*P);Ce.moveTo(G,Gt),Ce.lineTo(G,Nt);const W=G+P*.6;O.push(["𝄠",W,Yt]);const u=ge?[34,37,33,36,32,35,31]:[38,35,39,36,33,37,34];for(let g=0;g<Math.abs(oe);g++)O.push([Te[ge?-1:1][0],W+P*(2.84+.5+g*(ge?1.05:1.15)),zt(u[g])+P*.52])}if(v===0&&s.open)for(let W=0;W<d;W++)Ee.push([Qn(s.open[W]),G-16,Vt(bt,W)+t*.32,Yn(n,W)]);for(let W=se(s.beats,y.start-.001);W<s.beats.length&&s.beats[W].time<y.end-.001;W++){const u=s.beats[W],g=Q(u.time),L=Math.round(u.time*50);if(u.measure<0){ze.moveTo(g+1.6,vt-11),ze.arc(g,vt-11,1.6,0,Math.PI*2);continue}const S=m.has(L)?fn:Ce;if(S.moveTo(g,bt),S.lineTo(g,Nt),Z&&(S.moveTo(g,Gt),S.lineTo(g,Yt)),m.has(L))for(const _ of[ve-.5,ve+.5])ze.moveTo(g+8.6,Vt(bt,0)+_*t),ze.arc(g+7,Vt(bt,0)+_*t,1.6,0,Math.PI*2);he.push([qe,String(u.measure),g+1,vt-8,Et,"left"]);const k=Y.get(L)??(W===0?s.meters?.[0]?.text:null);if(k){const[_,R]=k.split("/"),st=g+12+(m.has(L)?6:0),Pt=`600 ${ee(F*.38)}px ${n.num}`;he.push([Pt,_,st,bt+F*.45,z,"center"],[Pt,R,st,bt+F*.97,z,"center"])}}let Dt=-1/0,Ut=-1/0;for(const W of s.sections??[])if(W.time>=y.start&&W.time<y.end){const u=Q(W.time)+1;he.push([hn,W.name,u,vt-34,z,"left"]),Ut=u+Kt(r,hn,W.name).width+16}for(const W of s.markers??[])if(W.time>=y.start&&W.time<y.end&&!W.text.startsWith("repeat")&&!/^\d+\/\d+$/.test(W.text)){const u=Math.max(Q(W.time)+1,Dt);he.push([qe,W.text,u,vt-21,W.text.startsWith("♩")?n.accent:z,"left"]),Dt=u+Kt(r,qe,W.text).width+10}const B=new Map,ot=new Map,at=new Set,Bt={palm:[],ring:[]};for(let W=se(s.notes,y.start-.001);W<s.notes.length&&s.notes[W].time<y.end-.001;W++){const u=s.notes[W],g=Q(u.time),L=Vt(bt,u.string),S=u.grace?.72:1,k=u.mute?"×":u.harmonic||u.harmonicPinch?`<${u.fret}>`:u.ghost?`(${u.fret})`:String(u.fret),_=at.has(W)?`(${k})`:k,R=Kt(r,Xe,_).width*S,st=g-(B.get(u.string)??-1/0)-2,Pt=Math.min(1,Math.max(.55,2*st/R)),ht=S*Pt<1?`700 ${ee(t*.95*S*Pt)}px ${n.num}`:Xe,et=Kt(r,ht,_).width;B.set(u.string,g+et/2),Qe.rect(g-et/2-2.5,L-t*.5,et+5,t);const xe=u.time<=h&&h<u.time+Math.max(u.sustain,.15);if((xe?St:Je).push([ht,_,g,L+Kt(r,ht,"5").middle,xe?Yn(n,u.string):z]),X&&Pt===1&&st>R/2+12&&!u.mute&&u.fret>0&&u.finger!==null&&u.finger!==void 0&>.push([u.finger===0?"T":String(u.finger),g+et/2+2,L+t*.45]),typeof u.tieTo=="number"&&(at.add(u.tieTo),s.notes[u.tieTo].time<y.end)){const Pe=Q(s.notes[u.tieTo].time);A.moveTo(g+et/2,L+t*.45),A.quadraticCurveTo((g+Pe)/2,L+t*1.2,Pe-et/2,L+t*.45)}if(It){const Pe=u.slideTo??u.slideUnpitchTo??null,ce=Pe!==null?Math.sign(Pe-u.fret)||1:u.slideOut==="up"?1:u.slideOut?-1:0;if(ce&&(A.moveTo(g+et/2+2,L+ce*t*.32),A.lineTo(g+et/2+t*.75,L-ce*t*.32)),u.slideIn){const wt=u.slideIn==="below"?1:-1;A.moveTo(g-et/2-t*.75,L+wt*t*.32),A.lineTo(g-et/2-2,L-wt*t*.32)}const we=ot.get(u.string);if((u.hammerOn||u.pullOff)&&we&&g-we.x<t*8&&(A.moveTo(we.x,L-t*.55),A.quadraticCurveTo((we.x+g)/2,L-t*1.5,g,L-t*.55),he.push([Oe,u.hammerOn?"H":"P",(we.x+g)/2,L-t*1.05,Et,"center"])),u.vibrato)for(let wt=g-et/2;wt<=g+et/2+1;wt+=2)A[wt===g-et/2?"moveTo":"lineTo"](wt,L-t*.62+Math.sin((wt-g)/1.6)*1.4);const mn=rn(u);if(mn>0){const wt=g+et/2+t*.6,Xt=L-t*1.25;A.moveTo(g+et/2+1,L-t*.15),A.quadraticCurveTo(wt,L-t*.5,wt,Xt),A.moveTo(wt-3,Xt+4),A.lineTo(wt,Xt),A.lineTo(wt+3,Xt+4),he.push([Oe,Fn(mn),wt,Xt-3,z,"center"])}const ue=cn(u);for(const[wt,Xt]of[["palm",u.palmMute||ue?.palmMute],["ring",u.letRing]])if(Xt){const en=Bt[wt].at(-1);en&&u.time-en.end<.8?Object.assign(en,{end:u.time,x1:g+et/2}):Bt[wt].push({x0:g-et/2,x1:g+et/2,end:u.time})}if(ue?.name&&ue.notes[0]===W){const wt=s.chords[u.chord-1];(!wt||u.time-wt.time>1||wt.name!==ue.name)&&he.push([qt,ue.name,Math.max(g-et/2,Ut),vt-34,z,"left"])}}ot.set(u.string,{x:g,y:L})}for(const[W,u]of[["palm","P.M."],["ring","let ring"]])for(const g of Bt[W]){const L=Kt(r,Oe,u).width;he.push([Oe,u,g.x0,vt-21,Et,"left"]),g.x1>g.x0+L+8&&(on.moveTo(g.x0+L+4,vt-24),on.lineTo(g.x1,vt-24),A.moveTo(g.x1,vt-27),A.lineTo(g.x1,vt-21))}if(s.lyrics?.length){let W=-1/0;for(let u=se(s.lyrics,y.start-.001);u<s.lyrics.length&&s.lyrics[u].time<y.end-.001;u++){const g=Math.max(Q(s.lyrics[u].time),W);he.push([qe,s.lyrics[u].text,g,Nt+(Z?t:ne)+t*1.55,Et,"left"]),W=g+Kt(r,qe,s.lyrics[u].text).width+5}}const q=new Map;if(Z){const W=[...Ye];let u=Math.max(0,se(s.beats,y.start)-1);for(let g=se(s.notes,y.start-.001);g<s.notes.length&&s.notes[g].time<y.end-.001;g++){const L=s.notes[g],S=Q(L.time),k=(s.open?.[L.string]??40)+L.fret+12,_=k%12,R=(Math.floor(k/12)-1)*7+Ne[_],st=zt(R),Pt=P*(L.grace?.35:.5);for(;s.beats[u+1]?.time<=L.time+1e-4;)s.beats[++u].measure>=0&&W.splice(0,7,...Ye);const ht=L.time<=h&&h<L.time+Math.max(L.sustain,.15);q.set(g,{x:S,y:st,r:Pt,step:R}),ht?St.push(["head",S,st,Pt,Yn(n,L.string)]):(Zt.moveTo(S+Pt,st),Zt.ellipse(S,st,Pt,Pt*.81,-.35,0,Math.PI*2));for(let et=28;et>=R;et-=2)$e.moveTo(S-P*.9,zt(et)),$e.lineTo(S+P*.9,zt(et));for(let et=40;et<=R;et+=2)$e.moveTo(S-P*.9,zt(et)),$e.lineTo(S+P*.9,zt(et));if(W[Ne[_]]!==Se[_]){W[Ne[_]]=Se[_];const[et,xe]=Te[Se[_]];O.push([et,S-P*(.5+.25+xe+.2),st+P*.52])}}}const J=[];let je=0,tn=-1,Be=Math.max(0,se(s.beats,y.start)-1);const _e=Gt+2*P,fe=()=>{if(!J.length)return;const W=Z?J.filter(k=>k.up).length*2>=J.length:!1,u=Z&&W?1:-1,g=Z?P*.5:ye,L=Z?P*.25:ye*.6;let S=kt;if(Z){for(const R of J)R.sx=R.x+(W?P*.44:-P*.44),R.sy=W?R.lo:R.hi,R.tip=W?Math.min(R.hi-P*3.5,_e):Math.max(R.lo+P*3.5,_e);const k=J.map(R=>R.sy),_=k.reduce((R,st)=>R+st,0)/k.length;S=J.length===1?J[0].tip+(Re(J[0].r)>2?u*-P*.58:0):W?Math.min(_-P*3.5,Math.min(...J.map(R=>R.hi))-P*2.5):Math.max(_+P*3.5,Math.max(...J.map(R=>R.lo))+P*2.5)}for(const k of J)pe.moveTo(k.sx,k.sy),pe.lineTo(k.sx,S);for(let k=0;J.length>1&&k<je;k++){const _=S+u*k*(g+L)-(u<0?g:0);let R=-1;for(let st=0;st<=J.length;st++){const Pt=st<J.length&&Re(J[st].r)>k;if(Pt&&R<0&&(R=st),Pt||R<0)continue;const ht=J[R].sx-(Z?P*.06:0),et=J[st-1].sx+(Z?P*.06:0),xe=R===st-1,Pe=Z?P*1.1:t*.8;Zt.rect(xe&&R?et-Pe:ht,_,xe?Pe:et-ht,g),R=-1}}if(J.length===1&&Re(J[0].r)){const k=J[0];if(Z)O.push(["𝅥"+["𝅮","𝅯","𝅰"][Math.min(3,Re(k.r))-1],k.sx-P*.06,k.sy+P*.54,W?1:-1,k.sy]);else for(let _=0;_<Re(k.r);_++)Zt.rect(k.x,S-_*(g+L)-g,t*.8,g)}J.length=je=0};for(let W=Math.max(0,se(re,y.start)-1);W<re.length;W++){const u=re[W];if(u.time>=y.end-.001)break;if(u.time<y.start-.001)continue;const g=Q(u.time),L=t*1.1/20;for(;s.beats[Be+1]?.time<=u.time+1e-4;)Be++;if((Be!==tn||u.rest)&&fe(),tn=Be,u.rest&&Z){if(u.value<=2)Zt.rect(g-P*.6,u.value===1?Gt+P:Gt+P*1.5,P*1.2,P*.5);else{const k=Math.min(3,Math.round(Math.log2(u.value))-2),_=[1.03,1.05,1.32,1.6][k];O.push([["𝄽","𝄾","𝄿","𝅀"][k],g-P*.2-_*P/2,Yt])}continue}if(u.rest){const k=bt+ve*t;if(u.value<=2)Zt.rect(g-6*L,k-(u.value===1?5:0)*L,12*L,5*L);else{if(pe.moveTo(g+(u.value===4?-3:4)*L,k+(u.value===4?-10:-7)*L),u.value>4)pe.lineTo(g-3*L,k+9*L);else for(const[_,R]of[[3,-3],[-3,3],[4,9]])pe.lineTo(g+_*L,k+R*L);for(let _=0;_<Re(u);_++)Zt.moveTo(g+(4-_*1.6)*L,k+(-5+_*5)*L),Zt.arc(g+(2-_*1.6)*L,k+(-5+_*5)*L,2*L,0,Math.PI*2)}continue}let S={r:u,x:g,stems:pe,up:!1,lo:Nt+5,hi:Nt+5,sx:g,sy:Nt+5,tip:kt};if(Z){const k=[];for(let ht=se(s.notes,u.time-.001);ht<s.notes.length&&s.notes[ht].time<=u.time+.001;ht++)q.has(ht)&&!s.notes[ht].grace&&k.push(q.get(ht));if(!k.length)continue;const _=k.map(ht=>ht.y),R=Math.max(..._),st=Math.min(..._),Pt=Math.abs(R-_e)>=Math.abs(st-_e);if(S={r:u,x:g,stems:pe,up:Pt,lo:R,hi:st,sx:g+(Pt?P*.44:-P*.44),sy:Pt?R:st,tip:Pt?Math.min(st-P*3.5,_e):Math.max(R+P*3.5,_e)},u.value<=2)for(const ht of k)Qe.moveTo(ht.x+P*.32,ht.y),Qe.ellipse(ht.x,ht.y,P*.32,P*.17,-.6,0,Math.PI*2);for(const ht of k)for(let et=0;et<u.dots;et++){const xe=ht.step%2===0?-P*.5:0;Zt.moveTo(ht.x+P*(1.2+et*.5)+P*.2,ht.y+xe),Zt.arc(ht.x+P*(1.2+et*.5),ht.y+xe,P*.2,0,Math.PI*2)}}else for(let k=0;k<u.dots;k++)Zt.moveTo(g+t*.5+k*t*.4+t*.13,kt-t*.4),Zt.arc(g+t*.5+k*t*.4,kt-t*.4,t*.13,0,Math.PI*2);if(u.value===1){fe();continue}Re(u)?(J.push(S),je=Math.max(je,Re(u))):(fe(),pe.moveTo(S.sx,S.sy),pe.lineTo(S.sx,S.tip))}if(fe(),v===Ct){const W=Math.max(0,se(re,h+1e-4)-1),u=re[W];if(u&&u.time>=y.start-.001&&u.time<y.end){const g=re[W+1]&&re[W+1].time<y.end?re[W+1].time:y.end,L=Q(u.time)-t*(Z?1:.75),S=Q(g)-t*(Z?.3:.35),k=Z?vt-t*.5:bt-t*.7;n.beatBox!==!1&&(M.box=[L,k,Math.max(S-L,t*1.5),Nt+t*.5-k+(Z?0:ne*.45+t*.2)])}M.x=[Q(Math.min(h,y.end)),(Z?vt:bt)-t*.5,Nt+t*.5]}}if(r.lineCap="butt",r.strokeStyle=H(z,.42),r.lineWidth=Z?Math.max(1,P*.13):1,r.stroke(Le),r.strokeStyle=H(z,.7),r.lineWidth=Z?Math.max(1.2,P*.16):1.2,r.stroke(Ce),r.lineWidth=Z?P*.5:3,r.stroke(fn),r.fillStyle=Et,r.fill(ze),r.strokeStyle=r.fillStyle=z,r.lineWidth=Z?Math.max(1,P*.12):Math.max(1.2,t*.09),r.stroke(pe),r.lineWidth=Math.max(1,P*.16),r.stroke($e),r.lineCap="round",r.fill(Zt),r.strokeStyle=z,r.lineWidth=1.1,r.stroke(A),r.setLineDash([4,3]),r.stroke(on),r.setLineDash([]),pt){r.font=Ze,r.textAlign="left",r.textBaseline="alphabetic";for(const[v,I,y,ct,Q]of O)ct===-1?(r.save(),r.translate(I,Q),r.scale(1,-1),r.fillText(v,0,P*.54),r.restore()):r.fillText(v,I,y)}r.globalCompositeOperation="destination-out",r.fill(Qe),r.globalCompositeOperation="source-over";for(const[v,I,y,ct,Q,bt]of he)r.font=v,r.fillStyle=Q,r.textAlign=bt,r.fillText(I,y,ct);r.textAlign="center",r.font=Xe,r.fillStyle=z;for(const[v,I,y,ct]of Je)v!==Xe&&(r.font=v),r.fillText(I,y,ct),v!==Xe&&(r.font=Xe);r.font=De,r.textAlign="left",r.globalAlpha=.7;for(const[v,I,y]of gt)r.fillText(v,I,y);r.globalAlpha=1,r.textAlign="center";for(const[v,I,y,ct,Q]of St)r.fillStyle=r.shadowColor=Q,r.shadowBlur=12,v==="head"?(r.beginPath(),r.ellipse(I,y,ct,ct*.81,-.35,0,Math.PI*2),r.fill()):(r.font=v,r.fillText(I,y,ct));r.shadowBlur=0,r.font=qe;for(const[v,I,y,ct]of Ee)r.fillStyle=ct,r.fillText(v,I,y);if(M.box&&(r.strokeStyle=H(n.accent,.35),r.fillStyle=H(n.accent,.1),r.lineWidth=1,r.beginPath(),r.roundRect(...M.box,4),r.fill(),r.stroke()),M.x){const[v,I,y]=M.x,ct=t*.9;r.strokeStyle=n.accent,r.lineWidth=1.5,r.beginPath(),r.roundRect(v-ct/2,I,ct,y-I,ct/2),r.stroke()}r.restore(),r.globalCompositeOperation="destination-over",r.beginPath(),r.roundRect(Fe,Ot,x-Fe*2,ae-Ot,16),r.fillStyle=_t?"#ffffff":H(n.ink,.72),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle=_t?"#d3d7df":n.chipBorder,r.lineWidth=1,r.stroke(),Ve("sheet")}function bi(a,s,h,n){const{g:e,W:r}=Nn(a);if(!s)return;const x=s.strings,d=Math.min(mi,320/Math.max(1,x-1))*(n.boardHeight??1),t=Do,F=t+d*2.2,X=F+d*(x-1),_t=X+d*1.45,z=F-d*1.55,Et=Math.min(20,d*.32),G=O=>F+(n.stringOrder==="high"?x-1-O:O)*d,Ht=ci*(n.noteSpeed??1),yt=n.tabLayout==="pages",Z=(n.tabMarks??"all")==="all",P=n.tabMarks==="notes",pt=Ke+30,Mt=r-Fe-30,K=yt?Math.min(170,(Mt-pt)*.14):0,N=Mt-(yt?K+24:0);let Tt,ut,It,Jt,ne=null;if(yt){const O=Co(s,(N-pt)/Ht),ft=Math.max(0,O.findLastIndex(Ot=>Ot.start<=h)),tt=O[ft],Ct=(N-pt)/(tt.end-tt.start);Tt=Ot=>pt+(Ot-tt.start)*Ct,[It,Jt]=[tt.start,tt.end-.001],ut=Tt(Math.min(Math.max(h,tt.start),tt.end)),O[ft+1]&&(ne={start:O[ft+1].start,scale:Ct})}else ut=Math.max(Ke+Lo+60,r*.2),Tt=O=>ut+(O-h)*Ht,[It,Jt]=[h-(ut-Ke)/Ht,h+(r-ut)/Ht];const ye=O=>n.str[O%n.str.length],Ft=O=>O.chord===null||O.chord===void 0?null:s.chords[O.chord],oe=(O,ft,tt,Ct)=>{e.beginPath(),e.moveTo(O,ft),e.lineTo(tt,Ct),e.stroke()},ge=(O,ft,tt,Ct)=>{const Ot=Math.hypot(tt,Ct),[ae,Ie]=[tt/Ot,Ct/Ot];oe(O,ft,O-6*ae-4*Ie,ft-6*Ie+4*ae),oe(O,ft,O-6*ae+4*Ie,ft-6*Ie-4*ae)},Ze=O=>O>=ut-1?1:.4;e.lineCap="round",e.lineJoin="round",e.textBaseline="alphabetic";const Te=[],ke=O=>{O&&(e.save(),e.beginPath(),e.rect(O[0],0,O[1]-O[0],Ae),e.clip());const ft=`600 ${ee(Math.min(15,d*.26))}px ${n.num}`,tt=`700 ${ee(Math.min(13,d*.22))}px ${n.num}`,Ct=new Map;e.font=ft,e.textAlign="left";const Ot=new Path2D,ae=new Path2D;e.fillStyle=n.muted;for(let M=se(s.beats,It-1);M<s.beats.length;M++){const m=s.beats[M];if(m.time>Jt)break;const Y=Tt(m.time),v=m.measure>=0,I=v?Ot:ae;I.moveTo(Y,F-d*.35),I.lineTo(Y,X+d*.35),v&&(e.fillText(String(m.measure),Y+6,t+d*.3),Ct.set(Math.round(m.time*50),Kt(e,ft,String(m.measure)).width+16))}e.lineWidth=1,e.strokeStyle=H(n.text,.05),e.stroke(ae),e.lineWidth=1.5,e.strokeStyle=H(n.text,.16),e.stroke(Ot),e.fillStyle=n.accent;const Ie=new Map;for(const M of s.markers??[])M.time>=It&&M.time<=Jt&&Ie.set(Math.round(M.time*50),[...Ie.get(Math.round(M.time*50))??[],M.text]);for(const[M,m]of Ie)e.fillText([...new Set(m)].join(" · "),Tt(M/50)+6+(Ct.get(M)??0),t+d*.3);e.strokeStyle=H(n.text,.14),e.beginPath();for(let M=0;M<x;M++)e.moveTo(Ke,G(M)),e.lineTo(r-Fe,G(M));e.stroke();const le=X+d*.92,re=X+d*1.24;if(n.guides!==!1&&!P){e.font=ft,e.fillStyle=e.strokeStyle=n.anchorLane,e.lineWidth=2;let M=-1/0;const m=s.anchors??[];for(let Y=Math.max(1,se(m,It));Y<m.length&&m[Y].time<=Jt;Y++){const v=m[Y],I=Tt(v.time);if(I<M)continue;const y=`fret ${v.fret}`;e.globalAlpha=Ze(I),oe(I,X+d*.6,I,le-2),e.fillText(y,I+5,le),M=I+5+Kt(e,ft,y).width+8}e.globalAlpha=1}e.strokeStyle=n.text,e.lineWidth=1.5;for(const M of P?[]:s.hairpins??[]){if(M.endTime<It||M.time>Jt)continue;const m=Tt(M.time),Y=Math.max(m+30,Tt(M.endTime)),[v,I]=M.kind==="cresc"?[m,Y]:[Y,m];e.globalAlpha=Ze(Y),e.beginPath(),e.moveTo(I,re-11),e.lineTo(v,re-5),e.lineTo(I,re+1),e.stroke()}e.globalAlpha=1;const ve=ee(Math.min(26,d*.42)),Vt=ve*1.3,Xe=ve*.32,qe=n.gem==="pill"?Vt/2:5,De={note:`700 ${ve}px ${n.num}`,grace:`700 ${ee(ve*.72)}px ${n.num}`,finger:`700 ${ee(ve*.5)}px ${n.num}`},hn=n.markings==="white",Le=s.rhythm,Ce=M=>Tt(M.time)+Vt/2;if(Le?.length){const M=new Path2D,m=new Path2D,Y=Math.max(2.5,d*.055),v=Math.max(2,d*.045),I=Math.max(5,d*.13),y=Et/20,ct=B=>B.value>=8?Math.round(Math.log2(B.value))-2:0,Q=(B,ot,at)=>{M.moveTo(B+at,ot),M.arc(B,ot,at,0,Math.PI*2)},bt=(B,ot)=>{if(ot.value<=2)return M.rect(B-7*y,z+Et*(ot.value===1?.3:.62),14*y,5*y);if(m.moveTo(B+(ot.value===4?-3:4)*y,z+(ot.value===4?2:3)*y),ot.value>4)m.lineTo(B-3*y,z+19*y);else for(const[at,Bt]of[[3,9],[-3,15],[4,21]])m.lineTo(B+at*y,z+Bt*y);for(let at=0;at<ct(ot);at++)Q(B+(2-at*1.6)*y,z+(5+at*5)*y,2*y)},Nt=(B,ot)=>{const at=z+Et;ot.value>=4?Q(B,at,Y):(m.moveTo(B+Y,at),m.arc(B,at,Y,0,Math.PI*2)),ot.value>1&&(m.moveTo(B,z),m.lineTo(B,at-Y*.7))},kt=[],Yt=[];let Gt=0,zt=0;const vt=()=>{for(let B=0;B<Gt;B++){let ot=-1;for(let at=0;at<=kt.length;at++){const Bt=at<kt.length&&ct(kt[at])>B;if(Bt&&ot<0&&(ot=at),Bt||ot<0)continue;const q=Ce(kt[ot]);M.rect(ot===at-1&&ot?q-I:q,z+B*v*2,Math.max(Ce(kt[at-1])-q,I),v),ot=-1}}zt&&kt.length>1&&Yt.push([(Ce(kt[0])+Ce(kt.at(-1)))/2,String(zt)]),kt.length=Gt=zt=0};let Dt=-1,Ut=Math.max(0,se(s.beats,It)-1);for(let B=Math.max(0,se(Le,It)-1);B<Le.length;B++){const ot=Le[B],at=Ce(ot);if(ot.time>Jt)break;for(;s.beats[Ut+1]?.time<=ot.time+1e-4;)Ut++;(Ut!==Dt||ot.rest)&&vt(),Dt=Ut,ot.rest?bt(at,ot):(Nt(at,ot),ct(ot)?(kt.push(ot),Gt=Math.max(Gt,ct(ot)),zt||=ot.tuplet):vt());for(let Bt=0;Bt<ot.dots;Bt++)Q(at+Y*(2.2+Bt*1.5),z+Et+Y*.8,Math.max(1.3,Y*.45))}if(vt(),e.fillStyle=e.strokeStyle=n.muted,e.lineWidth=Math.max(1.2,d*.022),e.stroke(m),e.fill(M),Yt.length){e.font=tt,e.textAlign="center";for(const[B,ot]of Yt)e.fillText(ot,B,z-v*2);e.textAlign="left"}}for(const M of P?[]:s.handShapes??[]){if(!M.arpeggio||M.endTime<It||M.startTime>Jt)continue;const m=M.frets.flatMap((I,y)=>I>=0&&y<x?[G(y)]:[]);if(!m.length)continue;const Y=Tt(M.startTime)-12,v=Tt(M.endTime);e.globalAlpha=Ze(v),e.strokeStyle=H(n.text,.4),e.lineWidth=1.5,e.setLineDash([6,5]),e.beginPath(),e.roundRect(Y,Math.min(...m)-Vt/2-6,v-Y,Math.max(...m)-Math.min(...m)+Vt+12,8),e.stroke(),e.setLineDash([]),M.name&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(M.name,Y,F-d*.72))}e.globalAlpha=1;const fn=M=>(M.slideTo??M.slideUnpitchTo??null)!==null||!!M.slideOut,Qe=M=>{const m=Ft(M);return!!m&&!M.repeat&&!m.highDensity&&m.notes.length>1},pe=(M,m)=>P?4:4+(fn(M)?16:0)+(Qe(m)?10:0)+(m.slideIn?18:0)+(m.showString?20:0);let Zt=0,ze=0;const A=(M,m)=>{m(ze-M/2),ze-=M+3},on={"":tt,"italic ":`italic ${tt}`},Oe=(M,m="")=>A(10,Y=>{e.font=on[m],e.fillText(M,Zt,Y+5)}),{next:qt,prev:cn,held:Re}=uo(s),he=new Map,gt=new Set,St=[],Ee=[];for(let M=se(s.notes,It-Re-.5);M<s.notes.length;M++){const m=s.notes[M];if(m.time>Jt)break;if(Tt(m.time+m.sustain)<Ke-40-Vt*4||O&&m.time<It&&Tt(m.time+m.sustain)-2<=Tt(It)&&typeof m.tieTo!="number")continue;const Y=Ft(m),v=m.grace?.72:1,I=Vt*v,y=G(m.string),ct=ye(m.string),Q=Tt(m.time),bt=m.mute||Y?.fretHandMute,Nt=m.palmMute||Y?.palmMute,kt=m.repeat||Y?.highDensity,Yt=bt?"×":m.harmonic||m.harmonicPinch?`<${m.fret}>`:m.ghost?`(${m.fret})`:String(m.fret),Gt=m.finger??(Y?.fingers?.[m.string]>=0?Y.fingers[m.string]:null),zt=!Z||bt||m.fret===0||Gt===null?"":Gt===0?"T":String(Gt),vt=m.grace?De.grace:De.note,Dt=Kt(e,vt,Yt).width,Ut=zt?Kt(e,De.finger,zt).width+3:0,B=s.notes[qt[M]],ot=B?Tt(B.time)-pe(m,B):1/0,at=Math.min(Math.max(I,Dt+Ut+Xe*2*v),Math.max(10,ot-Q)),Bt=Math.max(Q+at,Math.min(Tt(m.time+m.sustain)-2,ot)),q=Q+at/2,J=Math.min(1,(at-4)/(Dt+Ut)),je=he.get(m.string)??(cn[M]>=0?{x0:Tt(s.notes[cn[M]].time),w:Vt}:null);if(he.set(m.string,{x0:Q,w:at}),Bt<Ke-40&&typeof m.tieTo!="number")continue;const tn=m.time<=h&&h<m.time+Math.max(m.sustain,.15),Be=(tn||Q>=ut-1?1:.4)*(m.ghost?.55:1);if(e.globalAlpha=Be,Y&&!gt.has(Y)&&!P){gt.add(Y);const fe=Y.notes.map(S=>G(s.notes[S].string)),W=Math.min(...fe)-Vt/2,u=Math.max(...fe)+Vt/2,g=Q-7;if(fe.length>1&&!kt&&(e.strokeStyle=Y.accent?"#ffffff":H(n.text,.7),e.lineWidth=Y.accent==="heavy"?4:Y.accent?3:2,e.beginPath(),e.moveTo(g+4,W),e.lineTo(g,W),e.lineTo(g,u),e.lineTo(g+4,u),e.stroke()),e.font=tt,e.fillStyle=e.strokeStyle=kt?n.muted:n.text,e.lineWidth=1.8,e.textAlign="left",Y.barre&&!kt&&e.fillText(`${Y.barre.half?"½":""}B${Y.barre.fret}`,g,W-5),Y.strum||Y.roll){const S=Y.notes.map(ht=>s.notes[ht].string),k=G(Math.min(...S)),_=G(Math.max(...S)),[R,st]=(Y.strum??Y.roll)==="down"?[k,_]:[_,k],Pt=g-9;e.beginPath();for(let ht=0;ht<=16;ht++)e.lineTo(Pt+(Y.roll?Math.sin(ht/16*Math.PI*6)*2.5:0),R+(st-R)*ht/16);e.stroke(),ge(Pt,st,0,st-R||1)}const L=s.chords[m.chord-1];Y.name&&!kt&&(!L||m.time-L.time>1||L.name!==Y.name)&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(Y.name,Q,F-d*.72))}e.beginPath(),e.roundRect(Q,y-I/2,Bt-Q,I,qe*v),tn&&!kt&&(e.shadowColor=ct,e.shadowBlur=18),kt?(e.strokeStyle=ct,e.lineWidth=2,e.stroke()):m.letRing&&Bt>Q+at+2?(e.fillStyle=H(ct,.3),e.fill(),e.shadowBlur=0,e.strokeStyle=ct,e.lineWidth=2,e.setLineDash([6,5]),oe(Q+at+4,y,Bt-4,y),e.setLineDash([]),e.beginPath(),e.roundRect(Q,y-I/2,at,I,qe*v),e.fillStyle=ct,e.fill()):(e.fillStyle=bt?H(n.text,.22):ct,e.fill()),e.shadowBlur=0,tn&&Te.push({y,c:ct});const _e=kt?ct:bt?n.text:hn?"#ffffff":n.ink;St.push({text:Yt,font:vt,finger:zt,fill:_e,shown:Be,squeeze:J,x:q,y:y+Kt(e,vt,Yt).middle,left:-(Dt+Ut)/2,textWidth:Dt}),P||Ee.push(()=>{e.globalAlpha=Be;const fe=kt?n.muted:n.text;e.strokeStyle=e.fillStyle=fe,e.lineWidth=1.6;const W=m.slideTo??m.slideUnpitchTo??null,u=W===null?m.slideOut==="up"?1:m.slideOut?-1:0:Math.sign(W-m.fret)||1;if(u){const S=m.slideTo===null&&m.slideUnpitchTo!==null&&m.slideUnpitchTo!==void 0;S&&e.setLineDash([3,3]),oe(Bt+4,y+u*I*.3,Bt+14,y-u*I*.3),S&&e.setLineDash([])}if(m.slideIn&&oe(Q-16,y+(m.slideIn==="below"?1:-1)*I*.3,Q-6,y-(m.slideIn==="below"?1:-1)*I*.3),typeof m.tieTo=="number"){const S=Tt(s.notes[m.tieTo].time)+I/2;e.setLineDash([4,3]),e.beginPath(),e.moveTo(q,y+I/2+3),e.quadraticCurveTo((q+S)/2,y+I/2+14,S,y+I/2+3),e.stroke(),e.setLineDash([])}if(m.showString){const S=Q-(Y?26:13);e.beginPath(),e.arc(S,y,8,0,Math.PI*2),e.stroke(),e.font=De.finger,e.textAlign="center",e.fillText(String(x-m.string),S,y+Kt(e,De.finger,"1").middle)}m.dynamicLabel&&(e.font=`italic ${tt}`,e.textAlign="left",e.fillStyle=n.text,e.fillText(m.dynamicLabel,Q,re),e.fillStyle=fe);let g=y-I/2-6;if(m.vibrato){e.beginPath();for(let S=Q+2;S<=Math.max(Bt,Q+24)-2;S+=2)e.lineTo(S,g+Math.sin((S-Q)/3)*(m.vibratoWide?3:1.8));e.stroke(),g-=m.vibratoWide?10:8}if(e.textAlign="center",e.font=tt,(m.hammerOn||m.pullOff)&&je){const S=je.x0+je.w/2,k=(S+q)/2;e.beginPath(),e.moveTo(S,g),e.quadraticCurveTo(k,g-12,q,g),e.stroke(),e.fillText(m.hammerOn?"H":"P",k,g-9),g-=10}const L=rn(m);if(L>0){const S=m.bendCurve?.[0]?.[1]>0,k=(m.bendCurve?.length??0)>1&&m.bendCurve.at(-1)[1]<L,_=Q+at-2,R=y-I/2,st=R-16;e.beginPath(),S?(e.moveTo(_,R),e.lineTo(_,st)):(e.moveTo(_-4,R+2),e.quadraticCurveTo(_+4,R,_+6,st)),e.stroke(),ge(S?_:_+6,st,S?0:.3,-1),k&&(e.beginPath(),e.moveTo(_+12,st),e.quadraticCurveTo(_+16,R-6,_+16,R),e.stroke(),ge(_+16,R,0,1)),e.textAlign="left",e.fillText(`${S?"pre ":""}${Fn(L)}`,_+(k?20:10),st+4),e.textAlign="center"}[Zt,ze]=[q,g],m.tap&&!m.tapLeft&&Oe("T"),m.staccato&&A(4,S=>{e.beginPath(),e.arc(q,S,2,0,Math.PI*2),e.fill()}),m.accent&&(m.accent==="tenuto"||!Y?.accent)&&Oe({heavy:"^",tenuto:"–"}[m.accent]??">"),Nt&&Oe("PM");for(const S of[m.tapLeft?"m.g.":"",Po[m.harmonicType]??(m.harmonicPinch?"PH":""),m.slap?"slap":m.pop?"pop":"",m.golpe?`golpe (${m.golpe})`:"",m.rasgueado?`rasg. ${m.rasgueado}`:"",typeof m.trill=="number"?`tr ${m.trill}`:"",m.ornament??"",m.fade??"",m.whammy?"w/bar":"",m.wah==="open"?"o":m.wah==="closed"?"+":""])S&&Oe(S);m.rightFinger&&Oe(m.rightFinger,"italic "),m.pick&&A(9,S=>{e.beginPath(),m.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([k,_],R)=>e[R?"lineTo":"moveTo"](q+k,S+_)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([k,_],R)=>e[R?"lineTo":"moveTo"](q+k,S+_)),e.stroke()}),m.fermata&&A(9,S=>{e.beginPath(),e.arc(q,S+4,7,Math.PI,0),e.stroke(),e.beginPath(),e.arc(q,S+3,1.5,0,Math.PI*2),e.fill()}),m.tremolo&&A(18,S=>{for(let k=-1;k<=1;k++)oe(q-6,S+k*4+5.5,q+6,S+k*4+.5);e.beginPath();for(let k=0;k<=12;k++)e[k?"lineTo":"moveTo"](q-8+16*k/12,S-7+Math.sin(k/12*Math.PI*2)*2);e.stroke()})})}const Je=(M,m,Y,v)=>{if(e.globalAlpha=M.shown*v,e.fillStyle=M.fill,M.squeeze===1)return e.fillText(m,M.x+M.left+Y,M.y);e.save(),e.translate(M.x,M.y),e.scale(M.squeeze,1),e.fillText(m,M.left+Y,0),e.restore()};e.textAlign="left";for(const M of[De.note,De.grace]){e.font=M;for(const m of St)m.font===M&&Je(m,m.text,0,1)}e.font=De.finger;for(const M of St)M.finger&&Je(M,M.finger,M.textWidth+3,.7);for(const M of Ee)M();e.globalAlpha=1,O&&e.restore()};if(!yt)ke(null);else if(ke([pt-40,N+4]),ne){const O=N+24,ft=ut;Tt=tt=>O+(tt-ne.start)*ne.scale,[It,Jt,ut]=[ne.start,ne.start+K/ne.scale,-1/0],ke([O-8,Mt+4]),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.55)",e.fillRect(O-8,0,Mt+12-(O-8),Ae),e.restore(),e.strokeStyle=H(n.text,.22),e.lineWidth=1.5,e.setLineDash([3,5]),oe(N+12,F-d*.6,N+12,X+d*.6),e.setLineDash([]),ut=ft}e.shadowColor=n.accent,e.shadowBlur=16,e.strokeStyle=n.accent,e.lineWidth=3,oe(ut,F-d*.7,ut,X+d*.7);for(const{y:O,c:ft}of Te)e.shadowColor=ft,e.fillStyle="#ffffff",e.beginPath(),e.arc(ut,O,4,0,Math.PI*2),e.fill();e.shadowBlur=0,e.globalCompositeOperation="destination-out";for(const[O,ft,tt]of yt?[]:[[Ke+10,1,Lo],[r-Fe,-1,80]]){const Ct=e.createLinearGradient(O,0,O+ft*tt,0);Ct.addColorStop(0,"rgba(0, 0, 0, 1)"),Ct.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=Ct,e.fillRect(ft>0?0:O-tt,0,ft>0?O+tt:r-O+tt,Ae)}if(e.globalCompositeOperation="destination-over",e.beginPath(),e.roundRect(Fe,t,r-Fe*2,_t-t,16),e.fillStyle=H(n.ink,.72),e.fill(),e.globalCompositeOperation="source-over",e.strokeStyle=n.chipBorder,e.lineWidth=1,e.stroke(),!s.open)return;const Ne=`700 ${ee(Math.min(14,d*.24))}px ${n.num}`,Se=Math.min(13,d*.22),Ye=(Fe+Ke)/2;e.textAlign="center",e.fillStyle=n.muted,e.font=`700 ${ee(Math.min(12,d*.2))}px ${n.ui}`,e.fillText("TAB",Ye,z+Et*.7);const $e=s.meters?.findLast(O=>O.time<=h)?.text.split("/");if($e){const O=(F+X)/2,ft=`700 ${ee(Math.min(30,d*.52))}px ${n.num}`;e.font=ft,e.fillText($e[0],Ke+20,O-d*.04),e.fillText($e[1],Ke+20,O+d*.56)}e.font=Ne;for(let O=0;O<x;O++){const ft=G(O),tt=ye(O),Ct=Te.some(Ot=>Ot.y===ft);e.fillStyle=Ct?tt:H(tt,.16),e.beginPath(),e.roundRect(Ye-Se*1.2,ft-Se*.95,Se*2.4,Se*1.9,Se*.55),e.fill(),e.fillStyle=Ct?n.ink:tt,e.fillText(Qn(s.open[O]),Ye,ft+Kt(e,Ne,"E").middle)}}export{Vo as HEADSTOCKS,ai as bendAt,xi as drawHighway,Mi as drawSheet,bi as drawTab,Zo as headstockParts,No as lookAhead,fi as moveCamera,ho as rounded,mo as spline};
|
package/package.json
CHANGED