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