@fretfall/player 0.1.0 → 0.2.1

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/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  An arcade-style note highway for Guitar Pro and MusicXML tabs, in the browser.
4
4
 
5
- [![CI](https://github.com/FinalAngel/fretfall-player/actions/workflows/ci.yml/badge.svg)](https://github.com/FinalAngel/fretfall-player/actions/workflows/ci.yml)
6
- [![Performance](https://github.com/FinalAngel/fretfall-player/actions/workflows/perf.yml/badge.svg)](https://github.com/FinalAngel/fretfall-player/actions/workflows/perf.yml)
5
+ [![CI](https://github.com/fretfall/player/actions/workflows/ci.yml/badge.svg)](https://github.com/fretfall/player/actions/workflows/ci.yml)
6
+ [![Performance](https://github.com/fretfall/player/actions/workflows/perf.yml/badge.svg)](https://github.com/fretfall/player/actions/workflows/perf.yml)
7
7
  [![npm](https://img.shields.io/npm/v/@fretfall/player?color=c8f04a&labelColor=0e1014)](https://www.npmjs.com/package/@fretfall/player)
8
8
  [![license](https://img.shields.io/npm/l/@fretfall/player?color=c8f04a&labelColor=0e1014)](LICENSE)
9
9
 
10
+ [**Try it**](https://fretfall.github.io/player/) — the demo is the published package with a front door of its own, served from GitHub Pages.
11
+
12
+ ![Notes falling down the 3D fretboard: the hand position lit on the neck, chord names beside the shapes, fingering on each note, and fret numbers painted along the highway](docs/screenshot.webp)
13
+
10
14
  Open a tab and play along: the notes fall down a 3D fretboard, with hand positions and fingering worked out for you. Add the
11
15
  band's recording and the player lines the tab up with it on its own.
12
16
 
@@ -26,7 +30,8 @@ Any static file server works. Tabs are read and played by [alphaTab](https://www
26
30
 
27
31
  ## Build on it
28
32
 
29
- Serve the package's files and add your own page around it. The player exposes `window.fretfall` once it dispatches
33
+ Serve the package's files and add your own page around it. The player starts with no song of its own — the page around it
34
+ opens the first one, as the demo's front door does with its demo tab. The player exposes `window.fretfall` once it dispatches
30
35
  `fretfall:ready`:
31
36
 
32
37
  ```js
@@ -40,7 +45,7 @@ fretfall.part = 1;
40
45
  | Member | |
41
46
  |:--|:--|
42
47
  | `open(files, options)` / `pick()` | Open songs, or show the file dialog |
43
- | `playing`, `time`, `length` | Where playback is, in seconds |
48
+ | `playing`, `time`, `length` | Where playback is, in seconds. `playing` is settable: it waits for the synth's instruments |
44
49
  | `parts`, `part` | The song's parts, and the one shown (settable) |
45
50
  | `addFormat({ name, extensions, open })` | Read another file type: `open(file)` resolves to `{ song, audio }` |
46
51
  | `closeSheets()` | Close Settings and the notation sheet |
@@ -55,18 +60,42 @@ Keys: <kbd>Space</kbd> play · <kbd>L</kbd> loop · <kbd>O</kbd> open · <kbd>D<
55
60
 
56
61
  ```sh
57
62
  npm ci
63
+ npm start # the demo on http://localhost:4410, rebuilt from src/ on every request
58
64
  npm test # node --test
59
65
  npm run lint # oxlint: correctness and performance rules
60
- npm run build # dist/, the published package
66
+ npm run build # dist/, the published package (DEMO=1: with the demo's front door, as github.io serves it)
61
67
  npm run bench # frame time, draw calls, sync and size of dist/
62
68
  ```
63
69
 
70
+ `src/` is the player's modules, `demo/` the page they ship with, and the demo's front door and tab. The build flattens both
71
+ into `dist/`, which is what npm publishes and what the demo serves — so the page next to the modules, as a page built on the
72
+ player has it. The front door, between `<!-- demo -->` and `<!-- /demo -->` in the page, stays out of the package.
73
+
64
74
  No pull request may make the player slower or bigger. CI builds it and the base branch, benchmarks both in turns on the same
65
75
  runner, and fails on more than 10% frame or sync time, 5% draw calls or 1% gzipped size. A regression taken on purpose
66
76
  passes with the `perf-ok` label.
67
77
 
68
78
  Releases: bump `version`, publish a GitHub release tagged `v<version>`, and CI publishes to npm with provenance.
69
79
 
80
+ ## Contributing
81
+
82
+ Help is welcome — a bug report with a tab that reproduces it is as useful as a patch.
83
+
84
+ - **Something broken?** [Open an issue](https://github.com/fretfall/player/issues/new/choose). Say which file, which browser,
85
+ and what you expected; attach the tab if you can share it.
86
+ - **An idea, or not sure it belongs?** Open an issue before you build it. The player stays small on purpose, and it is easier
87
+ to say "yes, but over here" before the work than after.
88
+ - **Small and obvious?** A typo, a clear fix — just send the pull request.
89
+
90
+ Then: fork, branch off `main`, and before you push run `npm run lint && npm test && npm run build`, which is what CI runs.
91
+ Add or extend a `*.test.mjs` next to the module you touched — plain `node:assert`, no framework — and keep the diff to the
92
+ change you are making. Commit subjects read as [Conventional Commits](https://www.conventionalcommits.org) (`fix:`, `feat:`,
93
+ `docs:`, `chore:`, `refactor:`), because the release notes are written from them.
94
+
95
+ Two house rules, both enforced by CI: the player has **no runtime dependencies** and **no framework** — plain ES modules and
96
+ the platform — and **no pull request may make it slower or bigger** (see the budgets above). Match the style of the file you
97
+ are in rather than any style guide; there is no formatter, and a reformatted file makes a review impossible.
98
+
70
99
  ## License
71
100
 
72
101
  [MIT](LICENSE)
package/highway.js CHANGED
@@ -1 +1 @@
1
- import{lap as fe}from"./perf.js";import{noteName as bi}from"./music.js";const Ft=900,yi=84,Yn=28,qn=2.2,Si=.9,ki=2.4,Ti=a=>yi*(a.drawDistance??1)/(Yn*(a.noteSpeed??1)),Pi=.34,Lt=24,an=1.2,Ai=1.25,wi=1.25,Ce=5,sn=1,vi=1.6,Wi=2,ln=.19,Xn=.12,Un=3,$i=11,Ii=[{time:-1/0,endTime:1/0,fret:1,width:4}],jn=[3,5,7,9,12,15,17,19,21,24],Jn=(a,l,h,o,t)=>{const[m,M,d,e]=[Math.min(a,l),Math.max(a,l),Math.min(h,o),Math.max(h,o)],$=Math.min(t,(M-m)/2,(e-d)/2),_=(U,ct,R)=>{const ot=Array.from({length:5},(lt,vt)=>[U+Math.cos(R+vt*Math.PI/8)*$,ct+Math.sin(R+vt*Math.PI/8)*$]);return[ot[0],...ot,ot[4]]};return[..._(M-$,e-$,0),..._(m+$,e-$,Math.PI/2),..._(m+$,d+$,Math.PI),..._(M-$,d+$,1.5*Math.PI)]},Li=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([l,h])=>[l,-h])],Di={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:Li([[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:Jn(.2,.95,-1.06,1.06,.2),clamps:.58}};function Ci(a,l){const h=l.length,o=Qn(a.outline,10);let t=l.map(e=>[a.clamps,e]),m=l.map(()=>1);if(a.posts){const{from:e,to:$,treble:_}=a.posts,U=_?Math.floor(h*_.share+1e-9):0,ct=h-U,R=(Q,G,A)=>P=>Q.map((Mt,tt)=>Mt+(G[tt]-Mt)*P/Math.max(1,A-1)),ot=([Q,G])=>[Q,-G],lt=R(e,$,ct),vt=R(_?.from??ot(e),_?.to??ot($),U);t=l.map((Q,G)=>G<ct?lt(G):vt(h-1-G)),m=l.map((Q,G)=>G<ct?1:-1)}const M=(e,$)=>{let _=null;for(let U=1;U<o.length;U++){const[ct,R]=o[U-1],[ot,lt]=o[U];if((ct-e)*(ot-e)>0||ct===ot)continue;const vt=R+(lt-R)*(e-ct)/(ot-ct);(_===null||vt*$>_*$)&&(_=vt)}return _??$},d=a.keys?t.map(([e],$)=>({u:e,side:m[$],edge:M(e,m[$])})):[];return{outline:o,ends:t,keys:d}}const Kn=new WeakMap,ze=new Map,Ri=(a,l)=>{const h=l.join(),o=Kn.get(a);if(o?.key===h)return o.parts;const t=Ci(a,l);return Kn.set(a,{key:h,parts:t}),t},Vn=(a,l)=>(ze.has(a)||(ze.size>500&&ze.clear(),ze.set(a,l())),ze.get(a)),Qn=(a,l=8)=>[...a.slice(0,-1).flatMap((h,o)=>{const t=a[Math.max(0,o-1)],m=a[o+1],M=a[Math.min(a.length-1,o+2)];return h[0]===m[0]&&h[1]===m[1]?[h]:Array.from({length:l},(d,e)=>{const $=e/l;return[0,1].map(_=>.5*(2*h[_]+(m[_]-t[_])*$+(2*t[_]-5*h[_]+4*m[_]-M[_])*$*$+(3*h[_]-t[_]-3*m[_]+M[_])*$**3))})}),a.at(-1)],Wn=(a,l)=>{if(!a.startsWith("#"))return a;const h=o=>{const t=parseInt(a.slice(o,o+2),16);return Math.round(l>0?t+(255-t)*l:t*(1+l)).toString(16).padStart(2,"0")};return`#${h(1)}${h(3)}${h(5)}`},rn=new Map,L=(a,l)=>{if(!a.startsWith("#"))return a;const h=a+l;let o=rn.get(h);return o||(rn.size>1e3&&rn.clear(),rn.set(h,o=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${l})`)),o},Ge=(a,l)=>{let h=0,o=a.length;for(;h<o;){const t=h+o>>1;a[t].time<l?h=t+1:o=t}return h};function Zn(a){if(a.links?.next.length===a.notes.length)return a.links;const l=a.notes.length,h=new Array(l).fill(-1),o=new Array(l).fill(-1),t={};let m=0;for(let M=0;M<l;M++){const{string:d,sustain:e}=a.notes[M];t[d]!==void 0&&([o[M],h[t[d]]]=[t[d],M]),t[d]=M,m=Math.max(m,e)}return a.links={next:h,prev:o,held:m}}const ce=a=>Math.round(a*4)/4,de=32,hn=new Map;let ti=0;const jt=(a,l,h)=>{let o=hn.get(l);o||hn.set(l,o=new Map);let t=o.get(h);if(!t){++ti>5e3&&([ti,o]=[0,new Map],hn.clear(),hn.set(l,o)),a.font=l;const m=a.measureText(h);o.set(h,t={width:m.width,middle:(m.actualBoundingBoxAscent-m.actualBoundingBoxDescent)/2})}return t},fn=128,$n=new WeakMap,Ei=a=>{if(!$n.has(a)){const l=new OffscreenCanvas(1,fn),h=l.getContext("2d"),[o,t]=[a.floor0,a.floor1].map(M=>[1,3,5].map(d=>parseInt(M.slice(d,d+2),16))),m=Array.from({length:fn},(M,d)=>{const e=(d+.5)/fn;return`rgba(${o.map(($,_)=>Math.round($+(t[_]-$)*e))}, ${1-e})`});m.forEach((M,d)=>{h.fillStyle=M,h.fillRect(0,fn-1-d,1,1)}),$n.set(a,{strip:l,near:m[0]})}return $n.get(a)},Re=new Map,ei=new WeakMap,ni=(a,l,h)=>{let o=ei.get(a);o||ei.set(a,o=new Map);let t=o.get(l);if(!t){t=a.createLinearGradient(0,0,0,1);for(const[m,M]of h)t.addColorStop(m,M);o.set(l,t)}return t},cn=new Map,ii=(a,l,h,o,t)=>{const m=`${l}|${h}|${o}|${t}`;let M=cn.get(m);return M||(cn.size>20&&cn.clear(),M=a.createLinearGradient(0,l,0,h),M.addColorStop(0,o),M.addColorStop(1,t),cn.set(m,M)),M},dn=(a,l)=>[a[0]-l[0],a[1]-l[1],a[2]-l[2]],mn=(a,l)=>a[0]*l[0]+a[1]*l[1]+a[2]*l[2],Oi=(a,l)=>[a[1]*l[2]-a[2]*l[1],a[2]*l[0]-a[0]*l[2],a[0]*l[1]-a[1]*l[0]],Bi=a=>a.map(l=>l/Math.hypot(...a)),gn=(a,l)=>{let h=0,o=a.length;for(;h<o;){const t=h+o>>1;a[t].time<=l?h=t+1:o=t}return a[Math.max(0,h-1)]},oi=a=>a*a*(3-2*a),_i=.3,ai=new WeakMap;function si(a,l){let h=ai.get(a);if(h||ai.set(a,h={}),!(l in h)){const o=Math.max(a.sustain,.05),m=(a[l]??(l==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([M,d])=>[M*o,d,!1])??[];m.length&&m[0][0]>.001&&(m[0][2]=!0,m.unshift([0,0,!1])),h[l]=m.length?m:null}return h[l]}function li(a,l){if(!a)return 0;let h=a[0][1];for(let o=1;o<a.length&&l>a[o-1][0];o++){const[[t,m],[M,d,e]]=[a[o-1],a[o]],$=Math.min(M-t,_i)||1e-6;h=m+(d-m)*oi(Math.min(1,Math.max(0,(l-(e?M-$:t))/$)))}return h}const Hi=(a,l)=>li(si(a,"bendCurve"),l),Fi=(a,l)=>Hi(a,l)+li(si(a,"whammy"),l),ri=new WeakMap,Ee=a=>{let l=ri.get(a);return l===void 0&&ri.set(a,l=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,h])=>h))),l};function Ni(a){if(a.chordSpans)return a.chordSpans;const l=[];for(const h of a.chords){const o=Math.max(h.time+.25,...h.notes.map(m=>a.notes[m].time+a.notes[m].sustain)),t=l.at(-1);t&&h.time-t.end<1&&(h.name?h.name===t.name:h.highDensity)?t.end=Math.max(t.end,o):h.name&&l.push({name:h.name,time:h.time,end:o})}for(const h of a.handShapes??[])h.arpeggio&&h.name&&l.push({name:h.name,time:h.startTime,end:h.endTime});return a.chordSpans=l.sort((h,o)=>h.time-o.time)}function zi(a){if(a.chordRails)return a.chordRails;const l=[],h=o=>Math.max(o.time+.15,...o.notes.map(t=>a.notes[t].time+a.notes[t].sustain));for(let o=0;o<a.chords.length;o++){const t=a.chords[o];if(t.highDensity)continue;let m=h(t),M=o+1;for(;a.chords[M]?.highDensity&&a.chords[M].time-m<1;M++)m=Math.max(m,h(a.chords[M]));m=Math.min(m,a.chords[M]?.time??1/0),m-t.time>.2&&l.push({time:t.time,end:m,frets:t.notes.map(d=>a.notes[d].fret)})}for(const o of a.handShapes??[])o.arpeggio&&l.push({time:o.startTime,end:o.endTime,frets:o.frets,arpeggio:o});return a.chordRails=l}const hi={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},fi=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),ci=(a,l,h,o)=>{if(a===void 0)return l;const t=a+(l-a)*(1-Math.exp(-h/o));return Math.abs(l-t)<1e-6?l:t};function di(a,l,h,o,t){a[l]===void 0&&([a[l],a[l+"Speed"]]=[h,0]);const m=2/o,M=m*t,d=1/(1+M+.48*M*M+.235*M*M*M),e=a[l]-h,$=(a[l+"Speed"]+m*e)*t;a[l+"Speed"]=(a[l+"Speed"]-m*$)*d,a[l]=h+(e+$)*d,Math.abs(a[l]-h)<1e-6&&Math.abs(a[l+"Speed"])<1e-6&&([a[l],a[l+"Speed"]]=[h,0])}function mi(a,l){let h=1/0,o=-1/0;for(const m of a)m.endTime<=l||m.time>=l+Un||(h=Math.min(h,m.fret-1),o=Math.max(o,m.fret-1+m.width));if(h===1/0){const m=gn(a,l);[h,o]=[m.fret-1,m.fret-1+m.width]}const t=Math.max($i,o-h+2)+1;return{lo:h,hi:o,span:t,center:Math.min(25-t/2,Math.max(t/2-1,(h+o)/2))}}function Gi(a,l,h,o){const t=mi(l,h),m=a.target,M=!m||t.lo<m.center-m.span/2||t.hi>m.center+m.span/2,d=m&&m.span-Math.max(t.span,mi(l,h+Un).span)>2;(M||d)&&(a.target=t);const e=Math.min(o-(a.at??o),100);a.at=o,di(a,"span",a.target.span,a.target.span>a.span?.8:1.4,e/1e3),di(a,"center",a.target.center,1,e/1e3);const $=gn(l,h);return a.left=ci(a.left,$.fret-1,e,90),a.right=ci(a.right,$.fret-1+$.width,e,90),$}function gi(a,l,h,o,t,m,M,d){a.beginPath(),a.moveTo(l-o,h-m*t),a.lineTo(l,h),a.lineTo(l+o,h-m*t),a.lineWidth=Math.max(3,t*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,t*.65),a.strokeStyle=M,a.stroke(),a.lineWidth=Math.max(.6,t*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Ye(a,l,h,o,t){a.beginPath(),a.moveTo(l,h),a.lineTo(o,t),a.stroke()}function pi(a){const l=devicePixelRatio||1,h=a.clientWidth,o=a.clientHeight;(a.width!==Math.round(h*l)||a.height!==Math.round(o*l))&&(a.width=Math.round(h*l),a.height=Math.round(o*l));const t=a.getContext("2d"),m=o/Ft,M=h/m,d=l*m;return t.setTransform(d,0,0,d,0,0),t.clearRect(0,0,M,Ft),{g:t,W:M,B:d}}function Ki(a,l,h,o,t){const{g:m,W:M,B:d}=pi(a);let e=m;if(!l)return;const $=l.anchors.length?l.anchors:Ii,_=Gi(t,$,h,performance.now()),U=l.strings,ct=Math.min(.5,5*Pi/Math.max(1,U-1)),R=ct*wi*(o.boardHeight??1),ot=R*(U-1),lt=i=>(o.stringOrder==="high"?i:U-1-i)*R,vt=Yn*(o.noteSpeed??1),Q=Ti(o),G=-.22,A=ot+.22,P=G-.06,Mt=Q*vt,tt=i=>Math.max(0,i)*vt,Tt=i=>o.str[i%o.str.length],ge=o.noteLines===0?null:`rgba(255, 255, 255, ${o.noteLines??.5})`,Jt=t.span,rt=[t.center,ct*(U-1)/2,0],Pe=(o.viewAngle??30)*Math.PI/180,Ae=.6*Math.SQRT2*Jt,Be=[rt[0],ot+Ae*Math.sin(Pe),-Ae*Math.cos(Pe)],Kt=Bi(dn([rt[0],0,2.2*Jt],Be)),se=Oi(Kt,[1,0,0]),we=(o.sideAngle??0)*Math.PI/180,[W,K]=[Math.sin(we),Math.cos(we)],j=dn(Be,rt),St=mn(j,Kt),Et=mn(j,se),Wt=[-W,Kt[1]*K,Kt[2]*K],Vt=[K,Kt[1]*W,Kt[2]*W],ve=[rt[0]+Et*se[0]+St*Wt[0],rt[1]+Et*se[1]+St*Wt[1],Et*se[2]+St*Wt[2]],pe=Math.min(M*.88,Ft*(o.fill?1.3:1.05)),ue=pe*mn(dn(rt,ve),Wt)/Jt,pt=Math.min(Ai*(o.fretWidth??1),M*Jt/(pe*Math.max(1,Jt-2.5)));let qe=0,We=0;const[Qt,pn,un]=ve,[Mn,xn,Xe]=Wt,[_e,Me,bn]=Vt,[xe,yn,Ue]=se,D=(i,n,c)=>{const s=i-Qt,r=n-pn,p=c-un,u=ue/Math.max(.05,s*Mn+r*xn+p*Xe);return[M/2+(s*_e+r*Me+p*bn)*pt*u+qe,Ft/2-(s*xe+r*yn+p*Ue)*u+We,u]},[je,Je,xt]=D(...rt);[qe,We]=[M/2-je,Ft*(o.fill?.83:.81)-Je];const[,Ke]=D(t.center-Jt/2,P,0),[,Ve]=D(t.center+Jt/2,P,0),[,x]=D(t.center,P,0);We-=Math.min(Ft*.08,Math.max(0,Ke-x,Ve-x)),fe("setup");const f=(i,n=!0)=>{e.beginPath();for(let c=0;c<i.length;c++){const[s,r]=D(i[c][0],i[c][1],i[c][2]);c?e.lineTo(s,r):e.moveTo(s,r)}n&&e.closePath()},S=(i,n)=>{f([i,n],!1),N()},nt=(i,n,c,s,r)=>{if(o.gem!=="pill")return f([[i-s,n-r,c],[i+s,n-r,c],[i+s,n+r,c],[i-s,n+r,c]]);const[p,u]=D(i-s,n,c),[v,b]=D(i+s,n,c),[,k]=D(i,n+r,c),[,J]=D(i,n-r,c),H=Math.atan2(b-u,v-p),F=Math.min(Math.abs(J-k),Math.hypot(v-p,b-u))/2,[I,B]=[F*Math.cos(H),F*Math.sin(H)];e.beginPath(),e.arc(p+I,u+B,F,H+Math.PI/2,H+Math.PI*1.5),e.arc(v-I,b-B,F,H-Math.PI/2,H+Math.PI/2),e.closePath()},Y=(i,n)=>{const c=gn($,n),s=i.filter(r=>r>0);return[Math.min(c.fret-1,...s.map(r=>r-1))+.05,Math.max(c.fret-1+Math.max(4,c.width),...s)-.05]},et=(i,n,c,s,r)=>{S([i-s,n-r,c],[i+s,n+r,c]),S([i-s,n+r,c],[i+s,n-r,c])},Ot=o.markings==="white",ht=Ot?"#ffffff":o.ink,be=(i,n,c,s,r,p,u,v=null)=>{const[b,k]=u?[r*.85,p*.8]:[Math.min(r,.34)*.4,p*.55],J=u&&!Ot&&!v;v||(e.strokeStyle=L(o.ink,J?.85:.7),e.lineWidth=J?Math.max(2,.06*s):Math.max(3.5,.1*s),et(i,n,c,b,k)),!J&&(e.strokeStyle=v??"#ffffff",e.lineWidth=Math.max(v?2:1.8,.05*s),et(i,n,c,b,k))};let ee=null,Pt=0;const $e=i=>{i!==ee&&(e.font=ee=i)},Ie={},ne=(i,n,c,s,r,p)=>{const u=Ie[r]??=`${r} ${de}px ${o.num}`,v=s/de;return jt(e,u,i),$e(u),e.textAlign=p,e.setTransform(d*v,0,0,d*v,d*n,d*(c-Pt)),jt(e,u,i).middle},qt=()=>e.setTransform(d,0,0,d,0,-d*Pt),ye=(i,n,c)=>{e.fillStyle=i,e.setTransform(d,0,0,d*(c-n),0,d*(n-Pt)),e.fill(),qt()},Dt=(i,n,c,s,r,p,u=700,v="center",b=!0,k=!1)=>{const[J,H,F]=D(n,c,s),I=r*(k?F:Math.sqrt(F*xt));if(I<(k?1:8)||J<-60||J>M+60)return;e.textBaseline="alphabetic";const B=ne(i,J,H,I,u,v);b&&(e.lineWidth=de*.2,e.strokeStyle=L(o.ink,.9),e.strokeText(i,0,B)),e.fillStyle=p,e.fillText(i,0,B),qt(),e.textBaseline="middle"},[,ie]=D(rt[0],P,0),[,Se]=D(rt[0],P,Mt),gt=(i,n,c)=>{const s=`${ie}|${Se}`;(Re.span!==s||Re.size>300)&&(Re.clear(),Re.span=s);const r=`${i}|${n}|${c}`;let p=Re.get(r);return p||(p=e.createLinearGradient(0,ie,0,Se),p.addColorStop(0,L(i,n)),p.addColorStop(1,L(i,c)),Re.set(r,p)),p};let $t=null;const E=(i,n,c=10,s=!1)=>$t=i?{color:n,blur:c,faded:s}:null,Sn=[[.6,.05],[.35,.13],[.15,.27]],He=[[.4,.3]],Le=i=>{if(!$t)return;const{lineWidth:n,globalAlpha:c}=e,s=i?1:Math.min(1,2*n/$t.blur);e.save(),e.strokeStyle=$t.faded?gt($t.color,1,.1):$t.color;for(const[r,p]of $t.blur>4?Sn:He)e.lineWidth=(i?0:n)+2*$t.blur*r,e.globalAlpha=c*p*s,e.stroke();e.restore()},N=()=>{Le(!1),e.stroke()},at=()=>{Le(!0),e.fill()};e.textBaseline="middle",e.lineCap="round",e.lineJoin="round";const{strip:le,near:re}=Ei(o);let[Zt,bt]=[-60,Lt+60];if(we){const i=rt[0]+(1-mn(dn([rt[0],P,0],ve),Wt))/Wt[0];[Zt,bt]=Wt[0]>0?[Math.max(-60,i),Lt+60]:[-60,Math.min(Lt+60,i)]}e.save(),f([[Zt,P,0],[bt,P,0],[bt,P,Mt],[Zt,P,Mt]]),e.clip(),we&&(e.fillStyle=re,e.fillRect(0,ie,M,Ft-ie)),e.imageSmoothingEnabled=!1,e.drawImage(le,0,Se,M,ie-Se),e.restore();const Xt=(i,n)=>{const[c,s]=D(...i),[r,p]=D(...n);e.moveTo(c,s),e.lineTo(r,p)};e.strokeStyle=gt(o.lane,.5,.04),e.lineWidth=Si,e.beginPath();for(let i=0;i<=Lt;i++)Xt([i,P,0],[i,P,Mt]);N();for(const i of[!1,!0]){e.strokeStyle=i?o.measure:o.beat,e.lineWidth=i?1.6:1,e.beginPath();for(let n=Ge(l.beats,h);n<l.beats.length;n++){const c=l.beats[n],s=c.time-h;if(s>Q)break;c.measure>=0===i&&Xt([0,P,tt(s)],[Lt,P,tt(s)])}N()}(o.guides===!1?[]:$.filter(i=>i.endTime>h&&i.time<h+Q)).forEach((i,n)=>{const c=tt(Math.max(0,i.time-h)),s=tt(Math.min(Q,i.endTime-h)),r=i.fret-1,p=r+i.width;e.fillStyle=gt(o.anchorFill,o.anchorOpacity,.02),f([[r,P,c],[p,P,c],[p,P,s],[r,P,s]]),at(),e.strokeStyle=gt(o.anchorLane,.55,.04),e.lineWidth=ki*.6;for(const u of[r,p])S([u,P,c],[u,P,s]);n&&i.time>h&&S([r,P,c],[p,P,c]),n&&i.time>h+.3&&Dt(String(i.fret),r-.2,P,c,.3,o.anchorLane,700,"right")});const dt=new Map,ft=i=>{const n=Math.round(i*100);return dt.has(n)||dt.set(n,{dt:i-h,texts:[],pins:[]}),dt.get(n)};for(const i of l.markers??[])i.time>=h&&i.time<=h+Q&&!ft(i.time).texts.includes(i.text)&&ft(i.time).texts.push(i.text);for(const i of l.hairpins??[])i.time>=h&&i.time<=h+Q&&ft(i.time).pins.push(i.kind);const At=Math.min(t.center-(t.span/2+.5)/pt,-.5);for(const{dt:i,texts:n,pins:c}of dt.values()){const[s,r,p]=D(At,P,tt(i)),u=Math.sqrt(p*xt),v=n.join(" · "),b=.25*u,k=`700 ${de}px ${o.num}`,J=.3*u/de,H=v?jt(e,k,v).width*J:0,F=H+c.length*(.9*u+b);$e(k);let I=Math.max(s-.3*u,16+F);e.globalAlpha=Math.min(1,(Q-i)/.4),v&&(e.save(),e.translate(I,r),e.scale(J,J),e.textAlign="right",e.lineWidth=de*.2,e.strokeStyle=L(o.ink,.9),e.strokeText(v,0,0),e.fillStyle=o.accent,e.fillText(v,0,0),e.restore(),I-=H+b);for(const B of c){const yt=I-.9*u,ut=.14*u,[X,st]=B==="cresc"?[yt,I]:[I,yt];for(const[y,It]of[[L(o.ink,.9),Math.max(3.5,.12*u)],[o.text,Math.max(1.5,.05*u)]])e.strokeStyle=y,e.lineWidth=It,e.beginPath(),e.moveTo(st,r-ut),e.lineTo(X,r),e.lineTo(st,r+ut),N();I=yt-b}}e.globalAlpha=1,fe("floor");const mt=[];for(let i=Ge(l.notes,h-Zn(l).held-.3);i<l.notes.length;i++){const n=l.notes[i];if(n.time>h+Q)break;const c=Math.max(n.sustain,(n.slideTo??n.slideUnpitchTo??null)===null?0:.25,.15);n.time+c>=h-.05&&mt.push(n)}const Ut=i=>i.chord===null||i.chord===void 0?null:l.chords[i.chord],te=i=>o.repeatMarks==="frame"&&(i.repeat||Ut(i)?.highDensity),he=i=>{const n=gn($,i.time),c=i.fret===0;return{a:n,open:c,x:c?n.fret-1+n.width/2:i.fret-.5,y:lt(i.string)}},Qe=(i,n,c)=>{const s=i.slideTo??i.slideUnpitchTo??null,r=Math.min(1,Math.max(0,c/Math.max(i.sustain,.25)));return s===null||i.fret===0?n:n+(s-.5-n)*r*r*(3-2*r)},In=(i,n)=>Fi(i,n)*R*sn,Ln=i=>{const n=h-i.time;return n<0||i.fret===0||!(Ee(i)>0)?0:In(i,Math.min(n,Math.max(i.sustain,.15)))},Ze=new Map;for(const i of mt){const n=i.time-h,c=Math.max(i.sustain,.15);n>0||-n>c||i.fret===0||!(Ee(i)>0)||Ze.set(i.string,{note:i,x:i.fret-.5,dy:Ln(i)})}const kn=(i,n=0,c=!1)=>{const s=Ze.get(i),r=lt(i)+n,p=c?[[0,r,0]]:[en?[en[i][0],en[i][1]+n,0]:[-.6,r,0],[0,r,0]];if(!s)return f([...p,[Lt+.6,r,0]],!1);f([...p,[s.x,r+s.dy,0],[Lt+.6,r,0]],!1)},tn=i=>lt(i.string)+Ln(i),Nt=Di[o.headstock],ke=(A-G)/2,Tn=o.stringOrder==="high"?-1:1,oe=([i,n])=>[-i*ke/pt,ot/2+n*ke*Tn,0],Pn=i=>(lt(i)-ot/2)*Tn/ke,zt=Nt&&Ri(Nt,Array.from({length:U},(i,n)=>Pn(n))),en=zt?.ends.map(oe),kt=(i,n,c=1)=>{i&&(e.fillStyle=i,at()),n&&(e.strokeStyle=n,e.lineWidth=c,N())},Te=(i,n,c)=>{const[s,r]=oe(i),[p,u]=D(s,r,0),[v]=D(s+n*ke/pt,r,0),[,b]=D(s,r+c*ke,0);e.beginPath(),e.ellipse(p,u,Math.abs(v-p),Math.abs(b-u),0,0,Math.PI*2)},De=(i,n,c,s,r)=>f(Vn(`${i},${n},${c},${s},${r}`,()=>Jn(i,n,c,s,r)).map(oe)),Dn=()=>{for(const{u:c,side:s,edge:r}of zt.keys){const p=(u,v)=>[r+s*u,r+s*v];Nt.keys==="machine"?(De(c-.15,c+.15,...p(-.12,.08),.03),kt(L(o.text,.12),L(o.anchorLane,.35)),De(c-.03,c+.03,...p(.06,.22),0),kt(L(o.text,.28)),De(c-.11,c+.11,...p(.2,.68),.1),kt(L(o.text,.18),L(o.anchorLane,.55))):(De(c-.035,c+.035,...p(-.05,.22),0),kt(L(o.text,.28)),Te([c,r+s*.18],.08,.04),kt(L(o.text,.3)),Te([c,r+s*.4],.14,.2),kt(L(o.text,.18),L(o.anchorLane,.55)))}f(zt.outline.map(oe));const[,i]=D(...oe([0,1.6])),[,n]=D(...oe([0,-1.2]));if(kt(ii(e,i,n,o.floor0,o.ink)),e.save(),e.clip(),kt(null,L(o.text,.07),.3*ke*xt),e.restore(),E(!0,o.anchorLane,8),kt(null,L(o.anchorLane,.6),Math.max(1.5,.03*xt)),E(!1),Nt.cover){f(Vn(Nt.cover,()=>Qn(Nt.cover)).map(oe)),kt(L(o.text,.09),L(o.text,.4));for(const c of Nt.screws)Te(c,.04,.04),kt(L(o.nut,.85))}},Cn=i=>qn*(.7+.14*(U-1-i)),Mi=()=>{if(t.plate?.key!==An||t.plate.t!==o)return t.plate={key:An,t:o},Dn();const i=t.plate;if(!i.image){const[n,c]=[[],[]];for(const J of[...zt.outline,...zt.keys.map(({u:H,side:F,edge:I})=>[H,I+F*.8])]){const[H,F]=D(...oe(J));n.push(H),c.push(F)}const s=Math.floor(Math.max(0,Math.min(...n)-24)*d)/d,r=Math.min(M,Math.max(...n)+24),p=Math.floor(Math.max(0,Math.min(...c)-24)*d)/d,u=Math.min(Ft,Math.max(...c)+24);i.image=new OffscreenCanvas(Math.max(1,Math.ceil((r-s)*d)),Math.max(1,Math.ceil((u-p)*d)));const[v,b,k]=[e,Pt,ee];[e,Pt,ee,i.x,i.y]=[i.image.getContext("2d"),0,null,s,p],e.setTransform(d,0,0,d,-s*d,-p*d),e.lineCap=e.lineJoin="round",Dn(),[e,Pt,ee]=[v,b,k]}e.drawImage(i.image,i.x,i.y,i.image.width/d,i.image.height/d)},Rn=()=>{e.fillStyle=o.board,f([[0,G,0],[Lt+.6,G,0],[Lt+.6,A,0],[0,A,0]]),at(),e.fillStyle=L(o.anchorFill,.16),f([[t.left,G,0],[t.right,G,0],[t.right,A,0],[t.left,A,0]]),at(),e.fillStyle=o.inlayDot;const i=s=>(Math.max(0,Math.ceil(s)-1)+.5)*R;e.beginPath();for(const s of jn)for(const r of s%12?[i((U-1)/2)]:[i((U-1)/4),ot-i((U-1)/4)]){const[p,u,v]=D(s-.5,r,0);e.moveTo(p+.1*v,u),e.ellipse(p,u,.1*v,.08*v,0,0,Math.PI*2)}at(),zt&&Mi();const[,n]=D(rt[0],A,0),[,c]=D(rt[0],G,0);e.strokeStyle=ii(e,n,c,L(o.anchorPost,.75),o.post),e.lineWidth=Math.max(1.5,.05*xt),e.beginPath();for(let s=1;s<=Lt;s++)Xt([s,G-.04,0],[s,A+.04,0]);N(),e.strokeStyle=o.nut,e.lineWidth=Math.max(3,.12*xt),S([0,G-.06,0],[0,A+.06,0]),E(!0,o.anchorPost,12),e.strokeStyle=o.anchorPost,e.lineWidth=Math.max(3,.07*xt);for(const s of[t.left,t.right])S([s,G-.14,0],[s,A+.14,0]);E(!1);for(let s=0;s<U;s++){const r=Cn(s);E(!0,Tt(s),3),e.strokeStyle=L(Tt(s),.9),e.lineWidth=r,kn(s),N(),E(!1),e.strokeStyle="rgba(255, 255, 255, 0.25)",e.lineWidth=Math.max(.6,r*.3),kn(s,.012),N()}if(zt&&(zt.ends.forEach(([s,r],p)=>{if(Nt.clamps)De(s-.1,s+.1,r-.1,r+.1,.04),kt(L(o.text,.22),L(o.text,.45)),Te([s,r],.05,.05),kt(o.nut);else{Te([s,r],.17,.17),kt(L(o.ink,.5),L(o.nut,.4)),Te([s,r],.085,.085),kt(o.nut),Te([s,r],.03,.03),kt(L(o.ink,.85));const[u,v,b]=D(...en[p]),[k,J]=D(0,lt(p),0),H=Math.atan2(J-v,k-u);e.beginPath(),e.arc(u,v,.1*ke*b,H-1.3,H+1.3),kt(null,Tt(p),Cn(p))}}),Nt.tree)){const s=[U-2,U-1].map(r=>{const[p,u]=zt.ends[r];return Pn(r)+(u-Pn(r))*Nt.tree/p});De(Nt.tree-.05,Nt.tree+.05,Math.min(...s)-.08,Math.max(...s)+.08,.04),kt(L(o.nut,.7),L(o.ink,.6))}for(const s of[!1,!0])for(let r=1;r<=Lt;r++){const p=r>=_.fret&&r<_.fret+_.width,u=jn.includes(r);(p||u)===s&&Dt(String(r),r-.5,G-.3,0,p?.3:u?.26:.2,p?o.accent:u?o.inlay:o.numOff,s?800:500,"center",!1)}},Fe=(i,n)=>D(i,n,0).slice(0,2).map(c=>Math.round(c*d*10)).join(":"),An=[o.headstock,U,R,Tn,M,d,Math.round(pt*1e4),Fe(0,G),Fe(Lt,G),Fe(0,A),Fe(Lt,A),Fe(-4,ot/2)].join(),nn=!Ze.size&&[An,_.fret,_.width,Math.round(t.left*1e3),Math.round(t.right*1e3)].join();if(!nn||t.board?.key!==nn||t.board.t!==o)t.board=nn&&{key:nn,t:o},Rn();else{const i=t.board;if(!i.drawn){const n=[[0,A+.2],[Lt,A+.2],[0,G-.9],[Lt,G-.9]].map(([u,v])=>D(u,v,0)[1]);zt&&n.push(...[...zt.outline,...zt.keys.map(({u,side:v,edge:b})=>[u,b+v*.8])].map(u=>D(...oe(u))[1]));const c=Math.floor(Math.max(0,Math.min(...n)-24)*d)/d,s=Math.min(Ft,Math.max(...n)+24),[r,p]=[Math.ceil(M*d),Math.max(1,Math.ceil((s-c)*d))];(t.boardImage?.width!==r||t.boardImage.height!==p)&&(t.boardImage=new OffscreenCanvas(r,p)),[e,Pt,ee,i.y,i.drawn]=[t.boardImage.getContext("2d"),c,null,c,!0],e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,r,p),qt(),e.lineCap=e.lineJoin="round",e.textBaseline="middle",Rn(),[e,Pt,ee]=[m,0,null]}e.drawImage(t.boardImage,0,i.y,t.boardImage.width/d,t.boardImage.height/d)}fe("board");const En=(i,n)=>i.letRing&&-n>.25;for(const i of mt){const n=i.time-h;if(n>0||-n>Math.max(i.sustain,.15)||i.mute)continue;const c=Tt(i.string),s=tn(i);if(E(!En(i,n),c,10),e.strokeStyle=c,e.lineWidth=qn+3,kn(i.string,0,!0),N(),E(!1),-n<.2){const[r,p,u]=D(he(i).x,s,0);e.save(),e.translate(r,p),e.scale(1,.4);const v=e.createRadialGradient(0,0,0,0,0,.5*u);v.addColorStop(0,L(o.flash,.8*(1+n/.2))),v.addColorStop(1,L(o.flash,0)),e.fillStyle=v,e.beginPath(),e.arc(0,0,.5*u,0,Math.PI*2),at(),e.restore()}}e.strokeStyle=o.anchorLane,e.lineWidth=2.5,E(!0,o.anchorLane,10);for(const i of l.handShapes??[]){if(i.startTime>h||i.endTime<=h||i.endTime-i.startTime<.3||!i.frets.some((s,r)=>s>=0&&r<U))continue;const[n,c]=Y(i.frets.filter((s,r)=>r<U),i.startTime);f([[n,G,0],[c,G,0],[c,A,0],[n,A,0]]),N()}E(!1),fe("strings");for(const i of mt){const n=i.time-h,c=tt(n),s=Ut(i),{a:r,open:p,x:u,y:v}=he(i),b=Qe(i,u,-n);if(n<-.15||Math.abs(D(b,v,c)[0]-M/2)>M/2+200)continue;const k=p?(r.width-.2)/2:.34;e.globalAlpha=n<0?Math.max(0,1+n/.15):Math.min(1,(Q-n)/.4),!s&&ge&&(e.strokeStyle=ge,e.lineWidth=2,S([b-k,P,c],[b+k,P,c])),!(p||te(i))&&(e.strokeStyle=L(Tt(i.string),i.repeat||s?.highDensity?.35:.75),e.lineWidth=1.5,S([b,Math.min(v,tn(i))-.42*R,c],[b,P,c]))}e.globalAlpha=1;const On=(i,n,c)=>{const s=Array.from({length:13},(r,p)=>{const u=p/12;return[i[0]+(n[0]-i[0])*u,i[1]+(n[1]-i[1])*u+Math.sin(Math.PI*u)*c,i[2]+(n[2]-i[2])*u]});f(s,!1),N()};for(const i of zi(l)){if(i.end<=h||i.time>=h+Q)continue;const[n,c]=Y(i.frets,i.time),s=i.time-h,r=tt(Math.max(s,0)),p=tt(Math.min(i.end-h,Q));e.globalAlpha=Math.min(1,(Q-Math.max(s,0))/.4),E(!i.arpeggio,o.anchorLane,10,!0),e.strokeStyle=gt(o.anchorLane,1,.2),e.lineWidth=3.5;for(const u of[n,c])S([u,P,r],[u,P,p]);E(!1),i.arpeggio&&s>0&&(e.strokeStyle=L(o.anchorLane,.7),e.lineWidth=1.5,f([[n,P,r],[n,A,r],[c,A,r],[c,P,r]],!1),N(),i.arpeggio.name&&r>Ce&&Dt(i.arpeggio.name,n-.12,A/2,r,.34,o.text,600,"right"))}e.globalAlpha=1;const wn=(i,n)=>{const c=he(i);return Math.abs(c.x-n)<(c.open?(c.a.width-.2)/2+.1:.45)};for(const[i,n]of mt.entries()){const c=n.time-h,s=Ut(n),r=n.slideTo??n.slideUnpitchTo??null,{a:p,open:u,x:v,y:b}=he(n),k=Tt(n.string),J=tt(c),H=(u?(p.width-.2)/2:.34)*(n.grace?.6:1),F=(u?.12:.42)*R*(n.grace?.6:1);if(c>-.15&&!s?.highDensity&&!n.repeat){if(e.globalAlpha=Math.min(1,(Q-c)/.4),e.strokeStyle=k,e.lineWidth=2,e.setLineDash([4,4]),n.slideIn&&S([v+(n.slideIn==="below"?-1.4:1.4),b-F,Math.max(0,J-1)],[v+(n.slideIn==="below"?-H:H),b,J]),n.slideOut&&S([v+(n.slideOut==="up"?H:-H),b,J],[v+(n.slideOut==="up"?1.4:-1.4),b-F,J+1]),e.setLineDash([]),typeof n.tieTo=="number"){const C=l.notes[n.tieTo],z=he(C);e.setLineDash([5,4]),On([v,b+F,J],[z.x,z.y+F,tt(C.time-h)],R*.9),e.setLineDash([])}e.globalAlpha=1}const I=r===null?n.sustain:Math.max(n.sustain,.25),B=r!==null||n.bend||n.bendCurve||n.whammy;if(I<=.2||c+I<=0||s&&!B||te(n))continue;u&&r&&(e.strokeStyle=k,e.lineWidth=2.5,e.setLineDash(n.letRing?[7,6]:[]),On([v,b,tt(Math.max(c,0))],[r-.5,b,tt(Math.min(c+I,Q))],R*1.5),e.setLineDash([]));let yt=null;for(let C=i+1;C<mt.length&&mt[C].time<=n.time+I+.02;C++){const z=mt[C];if(!(z.time<=n.time+.005)&&(Ut(z)||z.string===n.string||wn(z,v))){yt=z;break}}const ut=Math.max(c,0),X=n.bend||n.bendCurve||n.whammy;let st=Math.min(c+I,Q,yt?yt.time-h:1/0);if(st<=ut)continue;const y=C=>{const z=C-c,g=tt(C),T=n.bend||n.bendCurve||n.whammy,w=n.vibrato&&!T?Math.sin(g/1.6*Math.PI*2)*R*(n.vibratoWide?.45:.25):0,it=n.tremolo?Math.floor(g/.3)%2?.05:-.05:0,q=sn+(vi-sn)*oi(Math.min(1,g/Wi));return[Qe(n,v,z)+it,b+w+In(n,z)*q/sn,g]},It=yt&&y(st)[0],Ct=yt&&Ut(yt)?.notes.find(C=>wn(l.notes[C],It)),Z=typeof Ct=="number"?l.notes[Ct]:yt;if(yt&&(X||wn(Z,It))){const C=he(Z),z=tt(Z.time-h),g=C.open?(C.a.width-.2)/2:.34,T=D(C.x,C.y-(C.open?.12:.42)*R,z)[1]+3,[w]=D(C.x-g,C.y,z),[it]=D(C.x+g,C.y,z),q=wt=>{const[Yt,V]=D(...y(wt));return V<T&&Yt>Math.min(w,it)-2&&Yt<Math.max(w,it)+2};if(q(st)&&!q(ut)){let wt=ut,Yt=st;for(let V=0;V<24;V++)[wt,Yt]=q((wt+Yt)/2)?[wt,(wt+Yt)/2]:[(wt+Yt)/2,Yt];st=wt}if(st<=ut+.001)continue}const Bt=r===null&&!X&&!n.vibrato&&!n.tremolo?1:Math.min(400,Math.max(12,Math.ceil((st-ut)*vt*8))),Gt=Array.from({length:Bt+1},(C,z)=>y(ut+(st-ut)*z/Bt));if(u&&!s){e.fillStyle=gt(k,n.letRing?.14:.26,.03),f([...Gt.map(([C,z,g])=>[C-H,z,g]),...Gt.slice().reverse().map(([C,z,g])=>[C+H,z,g])]),at(),E(!n.letRing,k,6,!0),e.strokeStyle=gt(k,.95,.3),e.lineWidth=2.5,e.setLineDash(n.letRing?[7,6]:[]);for(const C of[-H,H])f(Gt.map(([z,g,T])=>[z+C,g,T]),!1),N();e.setLineDash([]),E(!1)}else if(n.bend||n.bendCurve||n.whammy){const C=z=>f([...Gt.map(([g,T,w])=>[g-z,T,w]),...Gt.slice().reverse().map(([g,T,w])=>[g+z,T,w])]);C(ln),e.fillStyle=gt(k,1,.6),at(),C(ln*.35),e.fillStyle=gt(Wn(k,-.22),1,.55),at(),E(!0,k,8,!0),e.strokeStyle=gt(Wn(k,.6),1,.5),e.lineWidth=2;for(const z of[-ln,ln])f(Gt.map(([g,T,w])=>[g+z,T,w]),!1),N();E(!1)}else E(!n.letRing,k,6,!0),e.fillStyle=gt(k,n.letRing?.4:.75,n.letRing?.15:.3),f([...Gt.map(([C,z,g])=>[C-.09,z,g]),...Gt.slice().reverse().map(([C,z,g])=>[C+.09,z,g])]),at(),E(!1);if((n.letRing||r!==null||!X&&(n.vibrato||n.tremolo))&&(e.strokeStyle=gt(n.letRing?k:"#ffffff",.75,.3),e.lineWidth=n.letRing?2:1.5,e.setLineDash(n.letRing?[7,6]:[]),f(Gt,!1),N(),e.setLineDash([])),r!==null&&st>=Math.min(c+I,Q)-.001){const[C,z,g]=y(c+I);e.strokeStyle=k,e.lineWidth=2,e.setLineDash(n.slideTo===null?[5,4]:[]),u?nt(r-.5,z,g,.34,.42*R):nt(C,z,g,H,F),N(),e.setLineDash([])}}fe("trails");const Bn=new Set;for(let i=mt.length-1;i>=0;i--){const n=mt[i],c=n.time-h,s=tt(c),r=Ut(n),{a:p,open:u,x:v}=he(n),b=Qe(n,v,-c),k=tn(n),J=n.mute||r?.fretHandMute,H=n.palmMute||r?.palmMute,F=Tt(n.string),I=(u?(p.width-.2)/2:.34)*(n.grace?.6:1),B=(u?.12:.42)*R*(n.grace?.6:1),yt=n.slideTo??n.slideUnpitchTo??null;if(c<-.15)continue;const ut=c<0?Math.max(0,1+c/.15):Math.min(1,(Q-c)/.4);if(e.globalAlpha=ut,r&&!Bn.has(n.chord)){Bn.add(n.chord);const[g,T]=Y(r.notes.map(V=>l.notes[V].fret),n.time),w=e.globalAlpha,it=s<Ce,q=it?.65:r.highDensity&&o.repeatMarks!=="frame"?.18:.5;if(f([[g,P,s],[T,P,s],[T,A,s],[g,A,s]]),o.frames==="gradient"){const[,V]=D(g,P,s),[,_t]=D(g,A,s),Rt=it?o.anchorLane:o.anchorFill;ye(ni(e,`${Rt}|${q}`,[[0,L(Rt,q*.6)],[1,L(Rt,0)]]),V,_t)}else e.globalAlpha=w*q,r.highDensity||(e.fillStyle=o.chordFill,at()),e.strokeStyle=it?o.anchorLane:o.chordBox,e.lineWidth=it||!r.highDensity?1.5:1.2,E(it,o.anchorLane,8),N(),E(!1);if(e.globalAlpha=w,e.strokeStyle=ge,e.lineWidth=2,ge&&S([g,P,s],[T,P,s]),r.highDensity&&(r.palmMute||r.fretHandMute)&&(e.strokeStyle=r.palmMute?o.muted:"#ffffff",et((g+T)/2,P+R*.4,s,r.palmMute?.22:.12,R*(r.palmMute?.35:.22))),r.accent){const V=Math.min(.6,(T-g)*.22),_t=(A-P)*.35,Rt=Math.min(1,D(g,A,s)[2]/D(g,A,Ce)[2]);e.strokeStyle="#ffffff",e.lineWidth=Math.max(1,3.5*Rt*(r.accent==="heavy"?1.4:1)),e.lineCap="square",E(!0,"#ffffff",Math.max(2,12*Rt)),f([[g,A-_t,s],[g,A,s],[g+V,A,s]],!1),N(),f([[T-V,A,s],[T,A,s],[T,A-_t,s]],!1),N(),E(!1),e.lineCap="round"}if(r.barre&&(!r.highDensity||o.repeatMarks==="grey")){const V=r.barre.fret-.5;e.strokeStyle=r.highDensity?o.muted:"rgba(255, 255, 255, 0.7)",e.lineWidth=Math.max(3,.1*D(V,ot/2,s)[2]);const[_t,Rt]=[lt(r.barre.from),lt(r.barre.to)].sort((ae,Ht)=>ae-Ht);S([V,_t-R*.4,s],[V,Rt+R*.4,s]),Dt(r.barre.half?"½B":"B",V,A+.12,s,.22,r.highDensity?o.muted:o.text)}if(r.strum||r.roll){const V=g-.25,_t=lt(0)>lt(U-1)?A-.1:P+.15,Rt=_t>ot/2?P+.15:A-.1,[ae,Ht]=(r.strum??r.roll)==="down"?[_t,Rt]:[Rt,_t];e.strokeStyle=o.text,e.lineWidth=2,r.roll?f(Array.from({length:17},(Ui,Gn)=>[V+Math.sin(Gn/16*Math.PI*6)*.06,ae+(Ht-ae)*Gn/16,s]),!1):f([[V,ae,s],[V,Ht,s]],!1),N();const zn=Ht<ae?.14:-.14;S([V-.08,Ht+zn,s],[V,Ht,s]),S([V+.08,Ht+zn,s],[V,Ht,s])}const wt=l.chords[n.chord-1],Yt=!wt||n.time-wt.time>1||wt.name!==r.name;s>Ce&&r.name&&!r.highDensity&&Yt&&Dt(r.name,g-.12,A/2,s,.34,o.text,600,"right")}const[X,st,y]=D(b,k,s);if(X<-200||X>M+200||te(n)){e.globalAlpha=1;continue}const It=n.repeat||r?.highDensity;if(It){const g=s<Ce;e.globalAlpha*=g?.9:.4,e.strokeStyle=F,e.lineWidth=g?2:1.5,E(g,F,8),nt(b,k,s,I,B),N(),E(!1),(J||H)&&o.repeatMarks!=="hide"&&be(b,k,s,y,u?.34:I,u?R*.3:B,H,o.muted),e.globalAlpha=ut}else{if(!u&&s>1.75&&o.fretNumbers){const g=n.harmonic||n.harmonicPinch?`<${n.fret}>`:n.ghost?`(${n.fret})`:String(n.fret);Dt(g,b,P,s-.55,n.grace?.18:.26,F)}if(n.dynamicLabel&&Dt(n.dynamicLabel,b-.6,P,s,.3,o.text,"italic 700","right"),n.ghost&&(e.globalAlpha=ut*.5),o.gem==="pill")o.notes3d!==!1&&(nt(b,k,s+Xn,I,B),e.fillStyle=F,at(),e.fillStyle="rgba(255, 255, 255, 0.35)",at()),nt(b,k,s,I,B),e.fillStyle=F,at();else{const g=n.harmonic||n.harmonicPinch,T=Xn;if(!g&&o.notes3d!==!1)for(const[q,wt]of[[[[b-I,k+B,s],[b+I,k+B,s],[b+I,k+B,s+T],[b-I,k+B,s+T]],"rgba(255, 255, 255, 0.35)"],[[[b-I,k-B,s],[b-I,k+B,s],[b-I,k+B,s+T],[b-I,k-B,s+T]],"rgba(0, 0, 0, 0.4)"],[[[b+I,k-B,s],[b+I,k+B,s],[b+I,k+B,s+T],[b+I,k-B,s+T]],"rgba(0, 0, 0, 0.4)"]])f(q),e.fillStyle=F,at(),e.fillStyle=wt,at();E(s<Ce,F,8),e.fillStyle=F,g?f([[b,k+B*1.3,s],[b+I*.8,k,s],[b,k-B*1.3,s],[b-I*.8,k,s]]):nt(b,k,s,I,B),at(),E(!1);const[,w]=D(b,k+B,s),[,it]=D(b,k-B,s);ye(ni(e,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),w,it),e.strokeStyle="rgba(255, 255, 255, 0.6)",e.lineWidth=1,N()}if((J||H)&&be(b,k,s,y,u?.34:I,u?R*.3:B,H,u&&H?F:null),!u&&!J&&!H){const g=n.finger??(r?.fingers?.[n.string]>=0?r.fingers[n.string]:null),T=g!==null?g===0?"T":String(g):"";if(T){const w=e.globalAlpha;e.globalAlpha=w*Math.min(1,Math.max(0,(1-c/Q)/.4)),Dt(T,b,k,s-.01,R*.62,ht,700,"center",Ot,!0),e.globalAlpha=w}}}if(It&&o.repeatMarks==="hide"){e.globalAlpha=1;continue}const Ct=It?o.muted:o.text;if(e.globalAlpha=ut*(It?.8:1)*Math.min(1,Math.max(0,(1-c/Q)/.15)),n.ghost){const[g]=D(b-I,k,s),[T]=D(b+I,k,s),w=B*y*1.5;e.strokeStyle=It?Ct:F,e.lineWidth=Math.max(1.2,.035*y),e.beginPath(),e.arc(g+w*.35,st,w,Math.PI*.7,Math.PI*1.3),N(),e.beginPath(),e.arc(T-w*.35,st,w,-Math.PI*.3,Math.PI*.3),N()}if(n.grace&&(e.strokeStyle=Ct,e.lineWidth=Math.max(1,.03*y),Ye(e,X-I*y*pt*1.2,st+B*y*1.4,X+I*y*pt*1.2,st-B*y*1.4)),n.showString){const[g]=D(b-I,k,s),T=.12*y,w=g-T-.06*y;e.strokeStyle=e.fillStyle=It?Ct:F,e.lineWidth=Math.max(1,.025*y),e.beginPath(),e.arc(w,st,T,0,Math.PI*2),N(),ne(String(U-n.string),w,st,.15*y,700,"center"),e.fillText(String(U-n.string),0,0),qt()}let Z=st-B*y-.18*y;e.strokeStyle=e.fillStyle=Ct,e.lineWidth=Math.max(1.2,.04*y),e.textAlign="center";const on=(g,T,w="700")=>{T*y<2||(ne(g,X,Z,T*y,w,"center"),e.fillText(g,0,0),qt(),Z-=(T+.04)*y)};let Bt=st-B*y;const Gt=n.tap&&!n.tapLeft;if((n.hammerOn||n.pullOff)&&!Gt){const g=n.grace?.6:1,T=.2*y*pt*g,w=.38*R*y*g,[it,q]=n.hammerOn?[Bt+.4*w,Bt-.6*w]:[Bt-.6*w,Bt+.4*w];e.beginPath(),e.moveTo(X-T,q),e.lineTo(X+T,q),e.lineTo(X,it),e.closePath(),e.fillStyle=It?Ct:"#ffffff",e.strokeStyle=L(o.ink,.9),e.lineWidth=Math.max(1.5,.03*y),N(),at(),Bt-=.6*w,Z=Math.min(Z,Bt-.14*y),e.strokeStyle=e.fillStyle=Ct,e.lineWidth=Math.max(1.2,.04*y)}if(Gt){const g=n.grace?.6:1,T=.28*y*pt*g,w=.62*R*y*g,it=Bt+.15*w,q=it-w;e.beginPath(),e.moveTo(X,it),e.lineTo(X+T,q),e.lineTo(X,q+.38*w),e.lineTo(X-T,q),e.closePath(),e.strokeStyle=L(o.ink,.9),e.lineWidth=Math.max(3.5,.1*y),N(),e.fillStyle=It?L(Ct,.4):L(Wn(F,.55),.85),at(),e.strokeStyle=It?Ct:F,e.lineWidth=Math.max(1.8,.05*y),N(),Bt=q,Z=Math.min(Z,Bt-.14*y),e.strokeStyle=e.fillStyle=Ct,e.lineWidth=Math.max(1.2,.04*y)}const C=Ee(n);if(C>0){const g=n.bendCurve?.[0]?.[1]>0,T=(n.bendCurve?.length??0)>1&&n.bendCurve.at(-1)[1]<C,w=Math.min(3,Math.max(1,Math.round(C*2))),it=I*y*pt*.6,q=I*y*.3,wt=q*1.25,Yt=L(o.ink,.9);let V=Bt-.04*y;const _t=ae=>{for(let Ht=0;Ht<w;Ht++)gi(e,X,V-Ht*wt-(ae>0?0:q),it,q,ae,It?Ct:F,Yt);V-=w*wt+.08*y};(!g||!T)&&_t(-1),T&&_t(1);const Rt=`${g?"pre ":""}${fi(C)}`;e.fillStyle=Ct,ne(Rt,X+it+.08*y,(st-B*y+V)/2,.22*y,700,"left"),e.fillText(Rt,0,0),qt(),e.textAlign="center",Z=Math.min(Z,V-.1*y)}n.staccato&&(e.beginPath(),e.arc(X,Z+.04*y,Math.max(1.5,.045*y),0,Math.PI*2),at(),Z-=.16*y),n.accent&&(n.accent==="tenuto"||!r?.accent)&&on({heavy:"^",tenuto:"–"}[n.accent]??">",.3);const z=[n.tapLeft?"m.g.":"",hi[n.harmonicType]??(n.harmonicPinch?"PH":""),n.slap?"slap":n.pop?"pop":"",n.golpe?`golpe (${n.golpe})`:"",n.rasgueado?`rasg. ${n.rasgueado}`:"",typeof n.trill=="number"?`tr ${n.trill}`:"",n.ornament??"",n.fade??"",n.whammy?"w/bar":"",n.wah==="open"?"o":n.wah==="closed"?"+":""];for(const g of z)g&&on(g,g.length>2?.22:.28);if(n.rightFinger&&on(n.rightFinger,.26,"italic 700"),n.vibrato){const g=.24*y,T=(n.vibratoWide?.07:.035)*y;e.beginPath();for(let w=0;w<=20;w++)e[w?"lineTo":"moveTo"](X-g+2*g*w/20,Z+Math.sin(w/20*Math.PI*4)*T);N(),Z-=(.16+(n.vibratoWide?.06:0))*y}if(n.pick){const g=.09*y,T=.13*y;e.beginPath(),n.pick==="down"?[[-g,T/2],[-g,-T/2],[g,-T/2],[g,T/2]].forEach(([w,it],q)=>e[q?"lineTo":"moveTo"](X+w,Z+it)):[[-g,-T/2],[0,T/2],[g,-T/2]].forEach(([w,it],q)=>e[q?"lineTo":"moveTo"](X+w,Z+it)),N(),Z-=.22*y}if(n.fermata&&(e.beginPath(),e.arc(X,Z+.06*y,.14*y,Math.PI,0),N(),e.beginPath(),e.arc(X,Z+.02*y,Math.max(1.5,.03*y),0,Math.PI*2),at(),Z-=.24*y),n.tremolo){for(let g=-1;g<=1;g++)Ye(e,X-.12*y,Z+(g*.08+.05)*y,X+.12*y,Z+(g*.08-.05)*y);Z-=.34*y}if(yt!==null&&!u){const g=Math.sign(yt-n.fret)||1,T=X-g*.16*y,w=X+g*.16*y,it=Z+.07*y,q=Z-.09*y;Ye(e,T,it,w,q),Ye(e,w,q,w-g*.1*y,q),Ye(e,w,q,w,q+.1*y),Z-=.3*y}e.globalAlpha=1}fe("notes");const _n=new Set;for(const i of mt){const n=i.time-h,c=Ut(i);if(!c?.barre||_n.has(c)||n>.06||n<-Math.max(i.sustain,.12))continue;_n.add(c),e.strokeStyle="rgba(255, 255, 255, 0.85)",e.lineWidth=Math.max(4,.12*xt);const[s,r]=[lt(c.barre.from),lt(c.barre.to)].sort((p,u)=>p-u);S([c.barre.fret-.5,s-R*.45,0],[c.barre.fret-.5,r+R*.45,0])}const Hn=new Set,Fn=new Set;for(const i of mt){const n=i.time-h,c=Ut(i),s=Ze.get(i.string),r=i.heldFrom??null,p=n<=.06||r!==null&&h>=r-.06,u=(i.slideTo??i.slideUnpitchTo??null)!==null;if(i.mute||n>an||n<-Math.max(i.sustain,u?.25:.12)||(c?.highDensity||r!==null)&&!p||s&&s.note!==i&&!p||p&&Hn.has(`${i.string}:${i.fret}`))continue;p&&Hn.add(`${i.string}:${i.fret}`),Fn.add(`${i.string}:${i.fret}`);const{a:v,open:b,x:k}=he(i),J=Qe(i,k,-n),H=tn(i),F=Tt(i.string),I=(b?(v.width-.2)/2:.32)+2/xt,B=(b?.1:.36)*R+2/xt;if(nt(J,H,0,I,B),p)E(!En(i,n),F,14),e.fillStyle=F,at(),E(!1),e.strokeStyle="rgba(255, 255, 255, 0.7)",e.lineWidth=1.5,N();else{const ut=(1-n/an)**2;e.globalAlpha=.35*ut,e.fillStyle=F,at(),e.globalAlpha=.25+.75*ut,e.strokeStyle=F,e.lineWidth=2.2,N()}const yt=i.finger??(c?.fingers?.[i.string]>=0?c.fingers[i.string]:null);if(!b&&yt!==null&&Dt(yt===0?"T":String(yt),J,H,0,R*.55,p?ht:o.text,800,"center",!p||Ot),!b&&Ee(i)>0){const[ut,X]=D(J,H+B,0),st=i.bendCurve?.[0]?.[1]>0&&i.bendCurve.at(-1)[1]<Ee(i);gi(e,ut,X-(st?.14:.05)*xt,.17*xt*pt,.085*xt,st?1:-1,"#ffffff",L(o.ink,.9))}e.globalAlpha=1}for(const i of l.handShapes??[])!i.arpeggio||i.startTime-h>an||i.endTime<=h||(e.globalAlpha=.3+.5*Math.min(1,1-(i.startTime-h)/an)**2,i.frets.forEach((n,c)=>{if(n<=0||c>=U||Fn.has(`${c}:${n}`))return;const s=n-.5,r=lt(c),p=i.fingers[c];nt(s,r,0,.32+2/xt,.36*R+2/xt),e.strokeStyle=Tt(c),e.lineWidth=2.2,N(),p>=0&&Dt(p===0?"T":String(p),s,r,0,R*.55,o.text,800)}),e.globalAlpha=1);fe("targets");const Nn=Ni(l),vn=Nn.findLast(i=>i.time<=h&&h<i.end+.3),xi=vn?null:Nn.find(i=>i.time>h&&i.time-h<1.2),Ne=vn??xi;if(Ne){const[i,n]=D(t.right+.4,A+.5,0),c=jt(e,Ie[700]??=`700 ${de}px ${o.num}`,Ne.name).width*52/de;e.globalAlpha=vn?1:Math.max(.35,1-(Ne.time-h)/1.2),e.fillStyle=o.text,ne(Ne.name,Math.min(i,M-24-c),n,52,700,"left"),e.fillText(Ne.name,0,0),qt(),e.globalAlpha=1}fe("labels")}const Yi=240,qi=64,me=100,Oe=24,ui=150;function Xi(a,l){if(a.tabPages?.length===l)return a.tabPages.pages;const h=a.notes.at(-1),o=Math.max(h?h.time+h.sustain:0,a.beats.at(-1)?.time??0)+.5;let t=a.beats.filter(d=>d.measure>=0).map(d=>d.time);t.length<2&&(t=Array.from({length:Math.ceil(o/l)+1},(d,e)=>e*l)),t=[Math.min(0,t[0]),...t.filter(d=>d>0),Math.max(o,t.at(-1)+.01)];const m=[];let M=t[0];for(let d=1;d<t.length;d++)t[d]-M>l&&t[d-1]>M&&m.push({start:M,end:M=t[d-1]});m.push({start:M,end:t.at(-1)});for(let d=0;d<m.length-1;d++)m[d].end=m[d+1].start;return a.tabPages={length:l,pages:m},m}function Vi(a,l,h,o){const{g:t,W:m}=pi(a);if(!l)return;const M=l.strings,d=Math.min(qi,320/Math.max(1,M-1))*(o.boardHeight??1),e=Ft*.62-d*(M-1)/2,$=e+d*(M-1),_=e-d*1.65,U=$+d*1.45,ct=W=>e+(o.stringOrder==="high"?M-1-W:W)*d,R=Yi*(o.noteSpeed??1),ot=o.tabLayout==="pages",lt=me+30,vt=m-Oe-30,Q=ot?Math.min(170,(vt-lt)*.14):0,G=vt-(ot?Q+24:0);let A,P,Mt,tt,Tt=null;if(ot){const W=Xi(l,(G-lt)/R),K=Math.max(0,W.findLastIndex(Et=>Et.start<=h)),j=W[K],St=(G-lt)/(j.end-j.start);A=Et=>lt+(Et-j.start)*St,[Mt,tt]=[j.start,j.end-.001],P=A(Math.min(Math.max(h,j.start),j.end)),W[K+1]&&(Tt={start:W[K+1].start,scale:St})}else P=Math.max(me+ui+60,m*.2),A=W=>P+(W-h)*R,[Mt,tt]=[h-(P-me)/R,h+(m-P)/R];const ge=W=>o.str[W%o.str.length],Jt=W=>W.chord===null||W.chord===void 0?null:l.chords[W.chord],rt=(W,K,j,St)=>{t.beginPath(),t.moveTo(W,K),t.lineTo(j,St),t.stroke()},Pe=(W,K,j,St)=>{const Et=Math.hypot(j,St),[Wt,Vt]=[j/Et,St/Et];rt(W,K,W-6*Wt-4*Vt,K-6*Vt+4*Wt),rt(W,K,W-6*Wt+4*Vt,K-6*Vt-4*Wt)},Ae=W=>W>=P-1?1:.4;t.lineCap="round",t.lineJoin="round",t.textBaseline="alphabetic";const Be=[],Kt=W=>{W&&(t.save(),t.beginPath(),t.rect(W[0],0,W[1]-W[0],Ft),t.clip());const K=`600 ${ce(Math.min(15,d*.26))}px ${o.num}`,j=`700 ${ce(Math.min(13,d*.22))}px ${o.num}`,St=new Map;t.font=K,t.textAlign="left";const Et=new Path2D,Wt=new Path2D;t.fillStyle=o.muted;for(let x=Ge(l.beats,Mt-1);x<l.beats.length;x++){const f=l.beats[x];if(f.time>tt)break;const S=A(f.time),nt=f.measure>=0,Y=nt?Et:Wt;Y.moveTo(S,e-d*.35),Y.lineTo(S,$+d*.35),nt&&(t.fillText(String(f.measure),S+6,_+d*.36),St.set(Math.round(f.time*50),jt(t,K,String(f.measure)).width+16))}t.lineWidth=1,t.strokeStyle=L(o.text,.05),t.stroke(Wt),t.lineWidth=1.5,t.strokeStyle=L(o.text,.16),t.stroke(Et),t.fillStyle=o.accent;const Vt=new Map;for(const x of l.markers??[])x.time>=Mt&&x.time<=tt&&Vt.set(Math.round(x.time*50),[...Vt.get(Math.round(x.time*50))??[],x.text]);for(const[x,f]of Vt)t.fillText([...new Set(f)].join(" · "),A(x/50)+6+(St.get(x)??0),_+d*.36);t.strokeStyle=L(o.text,.14),t.beginPath();for(let x=0;x<M;x++)t.moveTo(me,ct(x)),t.lineTo(m-Oe,ct(x));t.stroke();const ve=$+d*.92,pe=$+d*1.24;if(o.guides!==!1){t.font=K,t.fillStyle=t.strokeStyle=o.anchorLane,t.lineWidth=2;let x=-1/0;const f=l.anchors??[];for(let S=Math.max(1,Ge(f,Mt));S<f.length&&f[S].time<=tt;S++){const nt=f[S],Y=A(nt.time);if(Y<x)continue;const et=`fret ${nt.fret}`;t.globalAlpha=Ae(Y),rt(Y,$+d*.6,Y,ve-2),t.fillText(et,Y+5,ve),x=Y+5+jt(t,K,et).width+8}t.globalAlpha=1}t.strokeStyle=o.text,t.lineWidth=1.5;for(const x of l.hairpins??[]){if(x.endTime<Mt||x.time>tt)continue;const f=A(x.time),S=Math.max(f+30,A(x.endTime)),[nt,Y]=x.kind==="cresc"?[f,S]:[S,f];t.globalAlpha=Ae(S),t.beginPath(),t.moveTo(Y,pe-11),t.lineTo(nt,pe-5),t.lineTo(Y,pe+1),t.stroke()}t.globalAlpha=1;const ue=ce(Math.min(26,d*.42)),pt=ue*1.3,qe=ue*.32,We=o.gem==="pill"?pt/2:5,Qt={note:`700 ${ue}px ${o.num}`,grace:`700 ${ce(ue*.72)}px ${o.num}`,finger:`700 ${ce(ue*.5)}px ${o.num}`},pn=o.markings==="white";for(const x of l.handShapes??[]){if(!x.arpeggio||x.endTime<Mt||x.startTime>tt)continue;const f=x.frets.flatMap((Y,et)=>Y>=0&&et<M?[ct(et)]:[]);if(!f.length)continue;const S=A(x.startTime)-12,nt=A(x.endTime);t.globalAlpha=Ae(nt),t.strokeStyle=L(o.text,.4),t.lineWidth=1.5,t.setLineDash([6,5]),t.beginPath(),t.roundRect(S,Math.min(...f)-pt/2-6,nt-S,Math.max(...f)-Math.min(...f)+pt+12,8),t.stroke(),t.setLineDash([]),x.name&&(t.font=`700 ${ce(Math.min(24,d*.4))}px ${o.num}`,t.fillStyle=o.text,t.fillText(x.name,S,e-d*.72))}t.globalAlpha=1;const un=x=>(x.slideTo??x.slideUnpitchTo??null)!==null||!!x.slideOut,Mn=x=>{const f=Jt(x);return!!f&&!x.repeat&&!f.highDensity&&f.notes.length>1},xn=(x,f)=>4+(un(x)?16:0)+(Mn(f)?10:0)+(f.slideIn?18:0)+(f.showString?20:0);let Xe=0,_e=0;const Me=(x,f)=>{f(_e-x/2),_e-=x+3},bn={"":j,"italic ":`italic ${j}`},xe=(x,f="")=>Me(10,S=>{t.font=bn[f],t.fillText(x,Xe,S+5)}),{next:yn,prev:Ue,held:D}=Zn(l),je=new Map,Je=new Set,xt=[],Ke=[];for(let x=Ge(l.notes,Mt-D-.5);x<l.notes.length;x++){const f=l.notes[x];if(f.time>tt)break;if(A(f.time+f.sustain)<me-40-pt*4||W&&f.time<Mt&&A(f.time+f.sustain)-2<=A(Mt)&&typeof f.tieTo!="number")continue;const S=Jt(f),nt=f.grace?.72:1,Y=pt*nt,et=ct(f.string),Ot=ge(f.string),ht=A(f.time),be=f.mute||S?.fretHandMute,ee=f.palmMute||S?.palmMute,Pt=f.repeat||S?.highDensity,$e=be?"×":f.harmonic||f.harmonicPinch?`<${f.fret}>`:f.ghost?`(${f.fret})`:String(f.fret),Ie=f.finger??(S?.fingers?.[f.string]>=0?S.fingers[f.string]:null),ne=be||f.fret===0||Ie===null?"":Ie===0?"T":String(Ie),qt=f.grace?Qt.grace:Qt.note,ye=jt(t,qt,$e).width,Dt=ne?jt(t,Qt.finger,ne).width+3:0,ie=l.notes[yn[x]],Se=ie?A(ie.time)-xn(f,ie):1/0,gt=Math.min(Math.max(Y,ye+Dt+qe*2*nt),Math.max(10,Se-ht)),$t=Math.max(ht+gt,Math.min(A(f.time+f.sustain)-2,Se)),E=ht+gt/2,Sn=Math.min(1,(gt-4)/(ye+Dt)),He=je.get(f.string)??(Ue[x]>=0?{x0:A(l.notes[Ue[x]].time),w:pt}:null);if(je.set(f.string,{x0:ht,w:gt}),$t<me-40&&typeof f.tieTo!="number")continue;const Le=f.time<=h&&h<f.time+Math.max(f.sustain,.15),N=(Le||ht>=P-1?1:.4)*(f.ghost?.55:1);if(t.globalAlpha=N,S&&!Je.has(S)){Je.add(S);const le=S.notes.map(O=>ct(l.notes[O].string)),re=Math.min(...le)-pt/2,Zt=Math.max(...le)+pt/2,bt=ht-7;if(le.length>1&&!Pt&&(t.strokeStyle=S.accent?"#ffffff":L(o.text,.7),t.lineWidth=S.accent==="heavy"?4:S.accent?3:2,t.beginPath(),t.moveTo(bt+4,re),t.lineTo(bt,re),t.lineTo(bt,Zt),t.lineTo(bt+4,Zt),t.stroke()),t.font=j,t.fillStyle=t.strokeStyle=Pt?o.muted:o.text,t.lineWidth=1.8,t.textAlign="left",S.barre&&!Pt&&t.fillText(`${S.barre.half?"½":""}B${S.barre.fret}`,bt,re-5),S.strum||S.roll){const O=S.notes.map(te=>l.notes[te].string),dt=ct(Math.min(...O)),ft=ct(Math.max(...O)),[At,mt]=(S.strum??S.roll)==="down"?[dt,ft]:[ft,dt],Ut=bt-9;t.beginPath();for(let te=0;te<=16;te++)t.lineTo(Ut+(S.roll?Math.sin(te/16*Math.PI*6)*2.5:0),At+(mt-At)*te/16);t.stroke(),Pe(Ut,mt,0,mt-At||1)}const Xt=l.chords[f.chord-1];S.name&&!Pt&&(!Xt||f.time-Xt.time>1||Xt.name!==S.name)&&(t.font=`700 ${ce(Math.min(24,d*.4))}px ${o.num}`,t.fillStyle=o.text,t.fillText(S.name,ht,e-d*.72))}t.beginPath(),t.roundRect(ht,et-Y/2,$t-ht,Y,We*nt),Le&&!Pt&&(t.shadowColor=Ot,t.shadowBlur=18),Pt?(t.strokeStyle=Ot,t.lineWidth=2,t.stroke()):f.letRing&&$t>ht+gt+2?(t.fillStyle=L(Ot,.3),t.fill(),t.shadowBlur=0,t.strokeStyle=Ot,t.lineWidth=2,t.setLineDash([6,5]),rt(ht+gt+4,et,$t-4,et),t.setLineDash([]),t.beginPath(),t.roundRect(ht,et-Y/2,gt,Y,We*nt),t.fillStyle=Ot,t.fill()):(t.fillStyle=be?L(o.text,.22):Ot,t.fill()),t.shadowBlur=0,Le&&Be.push({y:et,c:Ot});const at=Pt?Ot:be?o.text:pn?"#ffffff":o.ink;xt.push({text:$e,font:qt,finger:ne,fill:at,shown:N,squeeze:Sn,x:E,y:et+jt(t,qt,$e).middle,left:-(ye+Dt)/2,textWidth:ye}),Ke.push(()=>{t.globalAlpha=N;const le=Pt?o.muted:o.text;t.strokeStyle=t.fillStyle=le,t.lineWidth=1.6;const re=f.slideTo??f.slideUnpitchTo??null,Zt=re===null?f.slideOut==="up"?1:f.slideOut?-1:0:Math.sign(re-f.fret)||1;if(Zt){const O=f.slideTo===null&&f.slideUnpitchTo!==null&&f.slideUnpitchTo!==void 0;O&&t.setLineDash([3,3]),rt($t+4,et+Zt*Y*.3,$t+14,et-Zt*Y*.3),O&&t.setLineDash([])}if(f.slideIn&&rt(ht-16,et+(f.slideIn==="below"?1:-1)*Y*.3,ht-6,et-(f.slideIn==="below"?1:-1)*Y*.3),typeof f.tieTo=="number"){const O=A(l.notes[f.tieTo].time)+Y/2;t.setLineDash([4,3]),t.beginPath(),t.moveTo(E,et+Y/2+3),t.quadraticCurveTo((E+O)/2,et+Y/2+14,O,et+Y/2+3),t.stroke(),t.setLineDash([])}if(f.showString){const O=ht-(S?26:13);t.beginPath(),t.arc(O,et,8,0,Math.PI*2),t.stroke(),t.font=Qt.finger,t.textAlign="center",t.fillText(String(M-f.string),O,et+jt(t,Qt.finger,"1").middle)}f.dynamicLabel&&(t.font=`italic ${j}`,t.textAlign="left",t.fillStyle=o.text,t.fillText(f.dynamicLabel,ht,pe),t.fillStyle=le);let bt=et-Y/2-6;if(f.vibrato){t.beginPath();for(let O=ht+2;O<=Math.max($t,ht+24)-2;O+=2)t.lineTo(O,bt+Math.sin((O-ht)/3)*(f.vibratoWide?3:1.8));t.stroke(),bt-=f.vibratoWide?10:8}if(t.textAlign="center",t.font=j,(f.hammerOn||f.pullOff)&&He){const O=He.x0+He.w/2,dt=(O+E)/2;t.beginPath(),t.moveTo(O,bt),t.quadraticCurveTo(dt,bt-12,E,bt),t.stroke(),t.fillText(f.hammerOn?"H":"P",dt,bt-9),bt-=10}const Xt=Ee(f);if(Xt>0){const O=f.bendCurve?.[0]?.[1]>0,dt=(f.bendCurve?.length??0)>1&&f.bendCurve.at(-1)[1]<Xt,ft=ht+gt-2,At=et-Y/2,mt=At-16;t.beginPath(),O?(t.moveTo(ft,At),t.lineTo(ft,mt)):(t.moveTo(ft-4,At+2),t.quadraticCurveTo(ft+4,At,ft+6,mt)),t.stroke(),Pe(O?ft:ft+6,mt,O?0:.3,-1),dt&&(t.beginPath(),t.moveTo(ft+12,mt),t.quadraticCurveTo(ft+16,At-6,ft+16,At),t.stroke(),Pe(ft+16,At,0,1)),t.textAlign="left",t.fillText(`${O?"pre ":""}${fi(Xt)}`,ft+(dt?20:10),mt+4),t.textAlign="center"}[Xe,_e]=[E,bt],f.tap&&!f.tapLeft&&xe("T"),f.staccato&&Me(4,O=>{t.beginPath(),t.arc(E,O,2,0,Math.PI*2),t.fill()}),f.accent&&(f.accent==="tenuto"||!S?.accent)&&xe({heavy:"^",tenuto:"–"}[f.accent]??">"),ee&&xe("PM");for(const O of[f.tapLeft?"m.g.":"",hi[f.harmonicType]??(f.harmonicPinch?"PH":""),f.slap?"slap":f.pop?"pop":"",f.golpe?`golpe (${f.golpe})`:"",f.rasgueado?`rasg. ${f.rasgueado}`:"",typeof f.trill=="number"?`tr ${f.trill}`:"",f.ornament??"",f.fade??"",f.whammy?"w/bar":"",f.wah==="open"?"o":f.wah==="closed"?"+":""])O&&xe(O);f.rightFinger&&xe(f.rightFinger,"italic "),f.pick&&Me(9,O=>{t.beginPath(),f.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([dt,ft],At)=>t[At?"lineTo":"moveTo"](E+dt,O+ft)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([dt,ft],At)=>t[At?"lineTo":"moveTo"](E+dt,O+ft)),t.stroke()}),f.fermata&&Me(9,O=>{t.beginPath(),t.arc(E,O+4,7,Math.PI,0),t.stroke(),t.beginPath(),t.arc(E,O+3,1.5,0,Math.PI*2),t.fill()}),f.tremolo&&Me(12,O=>{for(let dt=-1;dt<=1;dt++)rt(E-6,O+dt*4+2.5,E+6,O+dt*4-2.5)})})}const Ve=(x,f,S,nt)=>{if(t.globalAlpha=x.shown*nt,t.fillStyle=x.fill,x.squeeze===1)return t.fillText(f,x.x+x.left+S,x.y);t.save(),t.translate(x.x,x.y),t.scale(x.squeeze,1),t.fillText(f,x.left+S,0),t.restore()};t.textAlign="left";for(const x of[Qt.note,Qt.grace]){t.font=x;for(const f of xt)f.font===x&&Ve(f,f.text,0,1)}t.font=Qt.finger;for(const x of xt)x.finger&&Ve(x,x.finger,x.textWidth+3,.7);for(const x of Ke)x();t.globalAlpha=1,W&&t.restore()};if(!ot)Kt(null);else if(Kt([lt-40,G+4]),Tt){const W=G+24,K=P;A=j=>W+(j-Tt.start)*Tt.scale,[Mt,tt,P]=[Tt.start,Tt.start+Q/Tt.scale,-1/0],Kt([W-8,vt+4]),t.save(),t.globalCompositeOperation="destination-out",t.fillStyle="rgba(0, 0, 0, 0.55)",t.fillRect(W-8,0,vt+12-(W-8),Ft),t.restore(),t.strokeStyle=L(o.text,.22),t.lineWidth=1.5,t.setLineDash([3,5]),rt(G+12,e-d*.6,G+12,$+d*.6),t.setLineDash([]),P=K}t.shadowColor=o.accent,t.shadowBlur=16,t.strokeStyle=o.accent,t.lineWidth=3,rt(P,e-d*.7,P,$+d*.7);for(const{y:W,c:K}of Be)t.shadowColor=K,t.fillStyle="#ffffff",t.beginPath(),t.arc(P,W,4,0,Math.PI*2),t.fill();t.shadowBlur=0,t.globalCompositeOperation="destination-out";for(const[W,K,j]of ot?[]:[[me+10,1,ui],[m-Oe,-1,80]]){const St=t.createLinearGradient(W,0,W+K*j,0);St.addColorStop(0,"rgba(0, 0, 0, 1)"),St.addColorStop(1,"rgba(0, 0, 0, 0)"),t.fillStyle=St,t.fillRect(K>0?0:W-j,0,K>0?W+j:m-W+j,Ft)}t.globalCompositeOperation="destination-over",t.beginPath(),t.roundRect(Oe,_,m-Oe*2,U-_,16),t.fillStyle=L(o.ink,.72),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle=o.chipBorder,t.lineWidth=1,t.stroke();const se=`700 ${ce(Math.min(14,d*.24))}px ${o.num}`,we=Math.min(13,d*.22);t.font=se,t.textAlign="center";for(let W=0;W<M&&l.open;W++){const K=(Oe+me)/2,j=ct(W);t.strokeStyle=t.fillStyle=ge(W),t.lineWidth=1.8,t.beginPath(),t.arc(K,j,we,0,Math.PI*2),t.stroke(),t.fillText(bi(l.open[W]),K,j+jt(t,se,"E").middle)}}export{Di as HEADSTOCKS,Hi as bendAt,Ki as drawHighway,Vi as drawTab,Ci as headstockParts,Ti as lookAhead,Gi as moveCamera,Jn as rounded,Qn as spline};
1
+ import{lap as ue}from"./perf.js";import{noteName as $i}from"./music.js";const Ot=900,Li=84,Jn=28,Vn=2.2,Di=.9,Ci=2.4,Ri=a=>Li*(a.drawDistance??1)/(Jn*(a.noteSpeed??1)),_i=.34,$t=24,fn=1.2,Ei=1.25,Oi=1.25,Re=5,cn=1,Bi=1.6,Hi=2,dn=.19,Zn=.12,Qn=3,Ni=11,Fi=[{time:-1/0,endTime:1/0,fret:1,width:4}],Cn=[3,5,7,9,12,15,17,19,21,24],Rn=.15,ti=.31,ei=1.7,ni=1.4,ii=1,oi=1.2,zi=.75,ai=(a,l,f,o,e)=>{const[M,m,d,t]=[Math.min(a,l),Math.max(a,l),Math.min(f,o),Math.max(f,o)],L=Math.min(e,(m-M)/2,(t-d)/2),R=(Tt,U,wt)=>{const _=Array.from({length:5},(xt,st)=>[Tt+Math.cos(wt+st*Math.PI/8)*L,U+Math.sin(wt+st*Math.PI/8)*L]);return[_[0],..._,_[4]]};return[...R(m-L,t-L,0),...R(M+L,t-L,Math.PI/2),...R(M+L,d+L,Math.PI),...R(m-L,d+L,1.5*Math.PI)]},Gi=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([l,f])=>[l,-f])],Ui={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:Gi([[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:ai(.2,.95,-1.06,1.06,.2),clamps:.58}};function Yi(a,l){const f=l.length,o=ri(a.outline,10);let e=l.map(t=>[a.clamps,t]),M=l.map(()=>1);if(a.posts){const{from:t,to:L,treble:R}=a.posts,Tt=R?Math.floor(f*R.share+1e-9):0,U=f-Tt,wt=(Ht,dt,E)=>j=>Ht.map(($,P)=>$+(dt[P]-$)*j/Math.max(1,E-1)),_=([Ht,dt])=>[Ht,-dt],xt=wt(t,L,U),st=wt(R?.from??_(t),R?.to??_(L),Tt);e=l.map((Ht,dt)=>dt<U?xt(dt):st(f-1-dt)),M=l.map((Ht,dt)=>dt<U?1:-1)}const m=(t,L)=>{let R=null;for(let Tt=1;Tt<o.length;Tt++){const[U,wt]=o[Tt-1],[_,xt]=o[Tt];if((U-t)*(_-t)>0||U===_)continue;const st=wt+(xt-wt)*(t-U)/(_-U);(R===null||st*L>R*L)&&(R=st)}return R??L},d=a.keys?e.map(([t],L)=>({u:t,side:M[L],edge:m(t,M[L])})):[];return{outline:o,ends:e,keys:d}}const si=new WeakMap,Ye=new Map,qi=(a,l)=>{const f=l.join(),o=si.get(a);if(o?.key===f)return o.parts;const e=Yi(a,l);return si.set(a,{key:f,parts:e}),e},li=(a,l)=>(Ye.has(a)||(Ye.size>500&&Ye.clear(),Ye.set(a,l())),Ye.get(a)),ri=(a,l=8)=>[...a.slice(0,-1).flatMap((f,o)=>{const e=a[Math.max(0,o-1)],M=a[o+1],m=a[Math.min(a.length-1,o+2)];return f[0]===M[0]&&f[1]===M[1]?[f]:Array.from({length:l},(d,t)=>{const L=t/l;return[0,1].map(R=>.5*(2*f[R]+(M[R]-e[R])*L+(2*e[R]-5*f[R]+4*M[R]-m[R])*L*L+(3*f[R]-e[R]-3*M[R]+m[R])*L**3))})}),a.at(-1)],_n=(a,l)=>{if(!a.startsWith("#"))return a;const f=o=>{const e=parseInt(a.slice(o,o+2),16);return Math.round(l>0?e+(255-e)*l:e*(1+l)).toString(16).padStart(2,"0")};return`#${f(1)}${f(3)}${f(5)}`},mn=new Map,I=(a,l)=>{if(!a.startsWith("#"))return a;const f=a+l;let o=mn.get(f);return o||(mn.size>1e3&&mn.clear(),mn.set(f,o=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${l})`)),o},_e=(a,l)=>{let f=0,o=a.length;for(;f<o;){const e=f+o>>1;a[e].time<l?f=e+1:o=e}return f};function hi(a){if(a.links?.next.length===a.notes.length)return a.links;const l=a.notes.length,f=new Array(l).fill(-1),o=new Array(l).fill(-1),e={};let M=0;for(let m=0;m<l;m++){const{string:d,sustain:t}=a.notes[m];e[d]!==void 0&&([o[m],f[e[d]]]=[e[d],m]),e[d]=m,M=Math.max(M,t)}return a.links={next:f,prev:o,held:M}}const Me=a=>Math.round(a*4)/4,Bt=32,gn=new Map;let fi=0;const Jt=(a,l,f)=>{let o=gn.get(l);o||gn.set(l,o=new Map);let e=o.get(f);if(!e){++fi>5e3&&([fi,o]=[0,new Map],gn.clear(),gn.set(l,o)),a.font=l;const M=a.measureText(f);o.set(f,e={width:M.width,middle:(M.actualBoundingBoxAscent-M.actualBoundingBoxDescent)/2})}return e},pn=128,En=new WeakMap,Xi=a=>{if(!En.has(a)){const l=new OffscreenCanvas(1,pn),f=l.getContext("2d"),[o,e]=[a.floor0,a.floor1].map(m=>[1,3,5].map(d=>parseInt(m.slice(d,d+2),16))),M=Array.from({length:pn},(m,d)=>{const t=(d+.5)/pn;return`rgba(${o.map((L,R)=>Math.round(L+(e[R]-L)*t))}, ${1-t})`});M.forEach((m,d)=>{f.fillStyle=m,f.fillRect(0,pn-1-d,1,1)}),En.set(a,{strip:l,near:M[0]})}return En.get(a)},Ee=new Map,ci=new WeakMap,di=(a,l,f)=>{let o=ci.get(a);o||ci.set(a,o=new Map);let e=o.get(l);if(!e){e=a.createLinearGradient(0,0,0,1);for(const[M,m]of f)e.addColorStop(M,m);o.set(l,e)}return e},un=new Map,mi=(a,l,f,o,e)=>{const M=`${l}|${f}|${o}|${e}`;let m=un.get(M);return m||(un.size>20&&un.clear(),m=a.createLinearGradient(0,l,0,f),m.addColorStop(0,o),m.addColorStop(1,e),un.set(M,m)),m},Mn=(a,l)=>[a[0]-l[0],a[1]-l[1],a[2]-l[2]],xn=(a,l)=>a[0]*l[0]+a[1]*l[1]+a[2]*l[2],ji=(a,l)=>[a[1]*l[2]-a[2]*l[1],a[2]*l[0]-a[0]*l[2],a[0]*l[1]-a[1]*l[0]],Ki=a=>a.map(l=>l/Math.hypot(...a)),Ji=(a,l)=>{let f=0;for(const o of a??[]){if(o.time>l)break;f=o.fret}return f},qe=(a,l)=>{let f=0,o=a.length;for(;f<o;){const e=f+o>>1;a[e].time<=l?f=e+1:o=e}return a[Math.max(0,f-1)]},gi=a=>a*a*(3-2*a),Vi=.3,pi=new WeakMap;function ui(a,l){let f=pi.get(a);if(f||pi.set(a,f={}),!(l in f)){const o=Math.max(a.sustain,.05),M=(a[l]??(l==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([m,d])=>[m*o,d,!1])??[];M.length&&M[0][0]>.001&&(M[0][2]=!0,M.unshift([0,0,!1])),f[l]=M.length?M:null}return f[l]}function Mi(a,l){if(!a)return 0;let f=a[0][1];for(let o=1;o<a.length&&l>a[o-1][0];o++){const[[e,M],[m,d,t]]=[a[o-1],a[o]],L=Math.min(m-e,Vi)||1e-6;f=M+(d-M)*gi(Math.min(1,Math.max(0,(l-(t?m-L:e))/L)))}return f}const Zi=(a,l)=>Mi(ui(a,"bendCurve"),l),Qi=(a,l)=>Mi(ui(a,"whammy"),l),xi=new WeakMap,Oe=a=>{let l=xi.get(a);return l===void 0&&xi.set(a,l=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,f])=>f))),l};function to(a){if(a.chordSpans)return a.chordSpans;const l=[];for(const f of a.chords){const o=Math.max(f.time+.25,...f.notes.map(M=>a.notes[M].time+a.notes[M].sustain)),e=l.at(-1);e&&f.time-e.end<1&&(f.name?f.name===e.name:f.highDensity)?e.end=Math.max(e.end,o):f.name&&l.push({name:f.name,time:f.time,end:o})}for(const f of a.handShapes??[])f.arpeggio&&f.name&&l.push({name:f.name,time:f.startTime,end:f.endTime});return a.chordSpans=l.sort((f,o)=>f.time-o.time)}function eo(a){if(a.chordRails)return a.chordRails;const l=[],f=o=>Math.max(o.time+.15,...o.notes.map(e=>a.notes[e].time+a.notes[e].sustain));for(let o=0;o<a.chords.length;o++){const e=a.chords[o];if(e.highDensity)continue;let M=f(e),m=o+1;for(;a.chords[m]?.highDensity&&a.chords[m].time-M<1;m++)M=Math.max(M,f(a.chords[m]));M=Math.min(M,a.chords[m]?.time??1/0),M-e.time>.2&&l.push({time:e.time,end:M,frets:e.notes.map(d=>a.notes[d].fret)})}for(const o of a.handShapes??[])o.arpeggio&&l.push({time:o.startTime,end:o.endTime,frets:o.frets,arpeggio:o});return a.chordRails=l}const bi={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},yi=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),Si=(a,l,f,o)=>{if(a===void 0)return l;const e=a+(l-a)*(1-Math.exp(-f/o));return Math.abs(l-e)<1e-6?l:e};function ki(a,l,f,o,e){a[l]===void 0&&([a[l],a[l+"Speed"]]=[f,0]);const M=2/o,m=M*e,d=1/(1+m+.48*m*m+.235*m*m*m),t=a[l]-f,L=(a[l+"Speed"]+M*t)*e;a[l+"Speed"]=(a[l+"Speed"]-M*L)*d,a[l]=f+(t+L)*d,Math.abs(a[l]-f)<1e-6&&Math.abs(a[l+"Speed"])<1e-6&&([a[l],a[l+"Speed"]]=[f,0])}function Ti(a,l,f=0){let o=1/0,e=-1/0;for(const m of a)m.endTime<=l||m.time>=l+Qn||(o=Math.min(o,m.fret-1),e=Math.max(e,m.fret-1+m.width));if(o===1/0){const m=qe(a,l);[o,e]=[m.fret-1,m.fret-1+m.width]}f&&(o=Math.min(o,f-1));const M=Math.max(Ni,e-o+2)+1;return{lo:o,hi:e,span:M,center:Math.min(25-M/2,Math.max(M/2-1,(o+e)/2))}}function no(a,l,f,o,e=0){const M=Ti(l,f,e),m=a.target,d=!m||M.lo<m.center-m.span/2||M.hi>m.center+m.span/2,t=m&&m.span-Math.max(M.span,Ti(l,f+Qn,e).span)>2;(d||t)&&(a.target=M);const L=Math.min(o-(a.at??o),100);a.at=o,ki(a,"span",a.target.span,a.target.span>a.span?.8:1.4,L/1e3),ki(a,"center",a.target.center,1,L/1e3);const R=qe(l,f);return a.left=Si(a.left,R.fret-1,L,90),a.right=Si(a.right,R.fret-1+R.width,L,90),R}function Pi(a,l,f,o,e,M,m,d){a.beginPath(),a.moveTo(l-o,f-M*e),a.lineTo(l,f),a.lineTo(l+o,f-M*e),a.lineWidth=Math.max(3,e*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,e*.65),a.strokeStyle=m,a.stroke(),a.lineWidth=Math.max(.6,e*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Xe(a,l,f,o,e){a.beginPath(),a.moveTo(l,f),a.lineTo(o,e),a.stroke()}function Ai(a){const l=devicePixelRatio||1,f=a.clientWidth,o=a.clientHeight;(a.width!==Math.round(f*l)||a.height!==Math.round(o*l))&&(a.width=Math.round(f*l),a.height=Math.round(o*l));const e=a.getContext("2d"),M=o/Ot,m=f/M,d=l*M;return e.setTransform(d,0,0,d,0,0),e.clearRect(0,0,m,Ot),{g:e,W:m,B:d}}function ho(a,l,f,o,e){const{g:M,W:m,B:d}=Ai(a);let t=M;if(!l)return;const L=l.anchors.length?l.anchors:Fi,R=Ji(l.capos,f),Tt=no(e,L,f,performance.now(),R),U=l.strings,wt=Math.min(.5,5*_i/Math.max(1,U-1)),_=wt*Oi*(o.boardHeight??1),xt=_*(U-1),st=n=>(o.stringOrder==="high"?n:U-1-n)*_,Ht=n=>(n>=U/2?1:-1)*(o.stringOrder==="high"?-1:1),dt=Jn*(o.noteSpeed??1),E=Ri(o),j=-.22,$=xt+.22,P=j-.06,Nt=E*dt,ct=n=>Math.max(0,n)*dt,Ft=n=>o.str[n%o.str.length],Lt=o.noteLines===0?null:`rgba(255, 255, 255, ${o.noteLines??.5})`,he=+o.fretNumbers||0,Vt=e.span,vt=[e.center,wt*(U-1)/2,0],we=(o.viewAngle??30)*Math.PI/180,He=.6*Math.SQRT2*Vt,je=[vt[0],xt+He*Math.sin(we),-He*Math.cos(we)],w=Ki(Mn([vt[0],0,2.2*Vt],je)),Q=ji(w,[1,0,0]),V=(o.sideAngle??0)*Math.PI/180,[bt,Ct]=[Math.sin(V),Math.cos(V)],te=Mn(je,vt),zt=xn(te,w),ve=xn(te,Q),Rt=[-bt,w[1]*Ct,w[2]*Ct],be=[Ct,w[1]*bt,w[2]*bt],Gt=[vt[0]+ve*Q[0]+zt*Rt[0],vt[1]+ve*Q[1]+zt*Rt[1],ve*Q[2]+zt*Rt[2]],Ke=Math.min(m*.88,Ot*(o.fill?1.3:1.05)),Je=Ke*xn(Mn(vt,Gt),Rt)/Vt,mt=Math.min(Ei*(o.fretWidth??1),m*Vt/(Ke*Math.max(1,Vt-2.5)));let Ve=0,Ne=0;const[bn,yn,Ze]=Gt,[Fe,ye,Sn]=Rt,[Se,kn,Qe]=be,[Tn,tn,en]=Q,v=(n,i,h)=>{const s=n-bn,r=i-yn,g=h-Ze,u=Je/Math.max(.05,s*Fe+r*ye+g*Sn);return[m/2+(s*Se+r*kn+g*Qe)*mt*u+Ve,Ot/2-(s*Tn+r*tn+g*en)*u+Ne,u]},[nn,on,p]=v(...vt);[Ve,Ne]=[m/2-nn,Ot*(o.fill?.83:.81)-on];const[,c]=v(e.center-Vt/2,P,0),[,D]=v(e.center+Vt/2,P,0),[,gt]=v(e.center,P,0);Ne-=Math.min(Ot*.08,Math.max(0,c-gt,D-gt)),ue("setup");const A=(n,i=!0)=>{t.beginPath();for(let h=0;h<n.length;h++){const[s,r]=v(n[h][0],n[h][1],n[h][2]);h?t.lineTo(s,r):t.moveTo(s,r)}i&&t.closePath()},H=(n,i)=>{A([n,i],!1),N()},Pt=(n,i,h,s,r)=>{if(o.gem!=="pill")return A([[n-s,i-r,h],[n+s,i-r,h],[n+s,i+r,h],[n-s,i+r,h]]);const[g,u]=v(n-s,i,h),[S,x]=v(n+s,i,h),[,k]=v(n,i+r,h),[,J]=v(n,i-r,h),F=Math.atan2(x-u,S-g),z=Math.min(Math.abs(J-k),Math.hypot(S-g,x-u))/2,[W,O]=[z*Math.cos(F),z*Math.sin(F)];t.beginPath(),t.arc(g+W,u+O,z,F+Math.PI/2,F+Math.PI*1.5),t.arc(S-W,x-O,z,F-Math.PI/2,F+Math.PI/2),t.closePath()},rt=(n,i)=>{const h=qe(L,i),s=n.filter(r=>r>0);return[Math.min(h.fret-1,...s.map(r=>r-1))+.05,Math.max(h.fret-1+Math.max(4,h.width),...s)-.05]},fe=(n,i,h,s,r)=>{H([n-s,i-r,h],[n+s,i+r,h]),H([n-s,i+r,h],[n+s,i-r,h])},We=o.markings==="white",Zt=We?"#ffffff":o.ink,Ie=(n,i,h,s,r,g,u,S=null)=>{const[x,k]=u?[r*.85,g*.8]:[Math.min(r,.34)*.4,g*.55],J=u&&!We&&!S;S||(t.strokeStyle=I(o.ink,J?.85:.7),t.lineWidth=J?Math.max(2,.06*s):Math.max(3.5,.1*s),fe(n,i,h,x,k)),!J&&(t.strokeStyle=S??"#ffffff",t.lineWidth=Math.max(S?2:1.8,.05*s),fe(n,i,h,x,k))};let Qt=null,_t=0;const ke=n=>{n!==Qt&&(t.font=Qt=n)},ce={},oe=(n,i,h,s,r,g)=>{const u=ce[r]??=`${r} ${Bt}px ${o.num}`,S=s/Bt;return Jt(t,u,n),ke(u),t.textAlign=g,t.setTransform(d*S,0,0,d*S,d*i,d*(h-_t)),Jt(t,u,n).middle},Ut=()=>t.setTransform(d,0,0,d,0,-d*_t),ze=(n,i,h)=>{t.fillStyle=n,t.setTransform(d,0,0,d*(h-i),0,d*(i-_t)),t.fill(),Ut()},yt=(n,i,h,s,r,g,u=700,S="center",x=!0,k=!1)=>{const[J,F,z]=v(i,h,s),W=r*(k?z:Math.sqrt(z*p));if(W<(k?1:8)||J<-60||J>m+60)return;t.textBaseline="alphabetic";const O=oe(n,J,F,W,u,S);x&&(t.lineWidth=Bt*.2,t.strokeStyle=I(o.ink,.9),t.strokeText(n,0,O)),t.fillStyle=g,t.fillText(n,0,O),Ut(),t.textBaseline="middle"},ee=(n,i,h,s,r,g,u=700)=>{const[S,x,k]=v(i,P,h),J=(p/k)**zi,[F,z]=v(i+s*J,P,h),W=Math.hypot(F-S,z-x);let O=r*J,[lt,nt]=v(i,P,h+O),X=Math.hypot(lt-S,nt-x);for(let et=0;et<3&&X>W*oi;et++)O*=W*oi/X,[lt,nt]=v(i,P,h+O),X=Math.hypot(lt-S,nt-x);const at=Math.abs(Math.atan2(lt-S,x-nt));if(S<-60||S>m+60||X<ii||at>ni)return;const b=t.globalAlpha;t.globalAlpha=b*Math.min(1,(ni-at)/.2,(X-ii)/3);const kt=ce[u]??=`${u} ${Bt}px ${o.num}`;ke(kt),t.textAlign="center",t.textBaseline="alphabetic";const{middle:It}=Jt(t,kt,n);t.setTransform(d*(F-S)/Bt,d*(z-x)/Bt,-d*(lt-S)/Bt,-d*(nt-x)/Bt,d*S,d*(x-_t)),t.fillStyle=g,t.fillText(n,0,It),Ut(),t.globalAlpha=b,t.textBaseline="middle"},[,pt]=v(vt[0],P,0),[,$e]=v(vt[0],P,Nt),Wt=(n,i,h)=>{const s=`${pt}|${$e}`;(Ee.span!==s||Ee.size>300)&&(Ee.clear(),Ee.span=s);const r=`${n}|${i}|${h}`;let g=Ee.get(r);return g||(g=t.createLinearGradient(0,pt,0,$e),g.addColorStop(0,I(n,i)),g.addColorStop(1,I(n,h)),Ee.set(r,g)),g};let Yt=null;const tt=(n,i,h=10,s=!1)=>Yt=n?{color:i,blur:h,faded:s}:null,Pn=[[.6,.05],[.35,.13],[.15,.27]],de=[[.4,.3]],ae=n=>{if(!Yt)return;const{lineWidth:i,globalAlpha:h}=t,s=n?1:Math.min(1,2*i/Yt.blur);t.save(),t.strokeStyle=Yt.faded?Wt(Yt.color,1,.1):Yt.color;for(const[r,g]of Yt.blur>4?Pn:de)t.lineWidth=(n?0:i)+2*Yt.blur*r,t.globalAlpha=h*g*s,t.stroke();t.restore()},N=()=>{ae(!1),t.stroke()},Y=()=>{ae(!0),t.fill()};t.textBaseline="middle",t.lineCap="round",t.lineJoin="round";const{strip:se,near:B}=Xi(o);let[ot,ft]=[-60,$t+60];if(V){const n=vt[0]+(1-xn(Mn([vt[0],P,0],Gt),Rt))/Rt[0];[ot,ft]=Rt[0]>0?[Math.max(-60,n),$t+60]:[-60,Math.min($t+60,n)]}t.save(),A([[ot,P,0],[ft,P,0],[ft,P,Nt],[ot,P,Nt]]),t.clip(),V&&(t.fillStyle=B,t.fillRect(0,pt,m,Ot-pt)),t.imageSmoothingEnabled=!1,t.drawImage(se,0,$e,m,pt-$e),t.restore();const ut=(n,i)=>{const[h,s]=v(...n),[r,g]=v(...i);t.moveTo(h,s),t.lineTo(r,g)};t.strokeStyle=Wt(o.lane,.5,.04),t.lineWidth=Di,t.beginPath();for(let n=0;n<=$t;n++)ut([n,P,0],[n,P,Nt]);N();for(const n of[!1,!0]){t.strokeStyle=n?o.measure:o.beat,t.lineWidth=n?1.6:1,t.beginPath();const i=[];for(let h=_e(l.beats,f);h<l.beats.length;h++){const s=l.beats[h],r=s.time-f;if(r>E)break;s.measure>=0===n&&(r>E-.4?i.push(r):ut([0,P,ct(r)],[$t,P,ct(r)]))}N();for(const h of i)t.globalAlpha=(E-h)/.4,t.beginPath(),ut([0,P,ct(h)],[$t,P,ct(h)]),N();t.globalAlpha=1}if(he)for(let n=_e(l.beats,f);n<l.beats.length;n++){const i=l.beats[n],h=i.time-f;if(h>E)break;if(i.measure<0)continue;const s=qe(L,i.time),r=ct(h);t.globalAlpha=Math.min(1,(E-h)/.4);for(const g of Cn)(g<s.fret||g>=s.fret+s.width)&&ee(String(g),g-.5,r,ti,ei,I(o.inlay,he))}t.globalAlpha=1,(o.guides===!1?[]:L.filter(n=>n.endTime>f&&n.time<f+E)).forEach((n,i)=>{const h=ct(Math.max(0,n.time-f)),s=ct(Math.min(E,n.endTime-f)),r=n.fret-1,g=r+n.width;t.fillStyle=Wt(o.anchorFill,o.anchorOpacity,.02),A([[r,P,h],[g,P,h],[g,P,s],[r,P,s]]),Y(),t.strokeStyle=Wt(o.anchorLane,.55,.04),t.lineWidth=Ci*.6;for(const u of[r,g])H([u,P,h],[u,P,s]);i&&n.time>f&&H([r,P,h],[g,P,h]),i&&n.time>f+.3&&yt(String(n.fret),r-.2,P,h,.3,o.anchorLane,700,"right")});const Te=new Map,ie=n=>{const i=Math.round(n*100);return Te.has(i)||Te.set(i,{dt:n-f,texts:[],pins:[]}),Te.get(i)};for(const n of l.markers??[])n.time>=f&&n.time<=f+E&&!ie(n.time).texts.includes(n.text)&&ie(n.time).texts.push(n.text);for(const n of l.hairpins??[])n.time>=f&&n.time<=f+E&&ie(n.time).pins.push(n.kind);const vi=Math.min(e.center-(e.span/2+.5)/mt,-.5);for(const{dt:n,texts:i,pins:h}of Te.values()){const[s,r,g]=v(vi,P,ct(n)),u=Math.sqrt(g*p),S=i.join(" · "),x=.25*u,k=`700 ${Bt}px ${o.num}`,J=.3*u/Bt,F=S?Jt(t,k,S).width*J:0,z=F+h.length*(.9*u+x);ke(k);let W=Math.max(s-.3*u,16+z);t.globalAlpha=Math.min(1,(E-n)/.4),S&&(t.save(),t.translate(W,r),t.scale(J,J),t.textAlign="right",t.lineWidth=Bt*.2,t.strokeStyle=I(o.ink,.9),t.strokeText(S,0,0),t.fillStyle=o.accent,t.fillText(S,0,0),t.restore(),W-=F+x);for(const O of h){const lt=W-.9*u,nt=.14*u,[X,at]=O==="cresc"?[lt,W]:[W,lt];for(const[b,kt]of[[I(o.ink,.9),Math.max(3.5,.12*u)],[o.text,Math.max(1.5,.05*u)]])t.strokeStyle=b,t.lineWidth=kt,t.beginPath(),t.moveTo(at,r-nt),t.lineTo(X,r),t.lineTo(at,r+nt),N();W=lt-x}}t.globalAlpha=1,ue("floor");const qt=[];for(let n=_e(l.notes,f-hi(l).held-.3);n<l.notes.length;n++){const i=l.notes[n];if(i.time>f+E)break;const h=Math.max(i.sustain,(i.slideTo??i.slideUnpitchTo??null)===null?0:.25,.15);i.time+h>=f-.05&&qt.push(i)}const me=n=>n.chord===null||n.chord===void 0?null:l.chords[n.chord],An=n=>o.repeatMarks==="frame"&&(n.repeat||me(n)?.highDensity),ge=n=>{const i=qe(L,n.time),h=n.fret===0;return{a:i,open:h,x:h?i.fret-1+i.width/2:n.fret-.5,y:st(n.string)}},an=(n,i,h)=>{const s=n.slideTo??n.slideUnpitchTo??null,r=Math.min(1,Math.max(0,h/Math.max(n.sustain,.25)));return s===null||n.fret===0?i:i+(s-.5-i)*r*r*(3-2*r)},On=(n,i)=>(Zi(n,i)*Ht(n.string)+Qi(n,i))*_*cn,Bn=n=>{const i=f-n.time;return i<0||n.fret===0||!(Oe(n)>0)?0:On(n,Math.min(i,Math.max(n.sustain,.15)))},sn=new Map;for(const n of qt){const i=n.time-f,h=Math.max(n.sustain,.15);i>0||-i>h||n.fret===0||!(Oe(n)>0)||sn.set(n.string,{note:n,x:n.fret-.5,dy:Bn(n)})}const wn=(n,i=0,h=!1)=>{const s=sn.get(n),r=st(n)+i,g=h?[[0,r,0]]:[rn?[rn[n][0],rn[n][1]+i,0]:[-.6,r,0],[0,r,0]];if(!s)return A([...g,[$t+.6,r,0]],!1);A([...g,[s.x,r+s.dy,0],[$t+.6,r,0]],!1)},ln=n=>st(n.string)+Bn(n),Xt=Ui[o.headstock],Pe=($-j)/2,vn=o.stringOrder==="high"?-1:1,le=([n,i])=>[-n*Pe/mt,xt/2+i*Pe*vn,0],Wn=n=>(st(n)-xt/2)*vn/Pe,jt=Xt&&qi(Xt,Array.from({length:U},(n,i)=>Wn(i))),rn=jt?.ends.map(le),St=(n,i,h=1)=>{n&&(t.fillStyle=n,Y()),i&&(t.strokeStyle=i,t.lineWidth=h,N())},Ae=(n,i,h)=>{const[s,r]=le(n),[g,u]=v(s,r,0),[S]=v(s+i*Pe/mt,r,0),[,x]=v(s,r+h*Pe,0);t.beginPath(),t.ellipse(g,u,Math.abs(S-g),Math.abs(x-u),0,0,Math.PI*2)},Le=(n,i,h,s,r)=>A(li(`${n},${i},${h},${s},${r}`,()=>ai(n,i,h,s,r)).map(le)),Hn=()=>{for(const{u:h,side:s,edge:r}of jt.keys){const g=(u,S)=>[r+s*u,r+s*S];Xt.keys==="machine"?(Le(h-.15,h+.15,...g(-.12,.08),.03),St(I(o.text,.12),I(o.anchorLane,.35)),Le(h-.03,h+.03,...g(.06,.22),0),St(I(o.text,.28)),Le(h-.11,h+.11,...g(.2,.68),.1),St(I(o.text,.18),I(o.anchorLane,.55))):(Le(h-.035,h+.035,...g(-.05,.22),0),St(I(o.text,.28)),Ae([h,r+s*.18],.08,.04),St(I(o.text,.3)),Ae([h,r+s*.4],.14,.2),St(I(o.text,.18),I(o.anchorLane,.55)))}A(jt.outline.map(le));const[,n]=v(...le([0,1.6])),[,i]=v(...le([0,-1.2]));if(St(mi(t,n,i,o.floor0,o.ink)),t.save(),t.clip(),St(null,I(o.text,.07),.3*Pe*p),t.restore(),tt(!0,o.anchorLane,8),St(null,I(o.anchorLane,.6),Math.max(1.5,.03*p)),tt(!1),Xt.cover){A(li(Xt.cover,()=>ri(Xt.cover)).map(le)),St(I(o.text,.09),I(o.text,.4));for(const h of Xt.screws)Ae(h,.04,.04),St(I(o.nut,.85))}},Nn=n=>Vn*(.7+.14*(U-1-n)),Wi=()=>{if(e.plate?.key!==In||e.plate.t!==o)return e.plate={key:In,t:o},Hn();const n=e.plate;if(!n.image){const[i,h]=[[],[]];for(const J of[...jt.outline,...jt.keys.map(({u:F,side:z,edge:W})=>[F,W+z*.8])]){const[F,z]=v(...le(J));i.push(F),h.push(z)}const s=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,r=Math.min(m,Math.max(...i)+24),g=Math.floor(Math.max(0,Math.min(...h)-24)*d)/d,u=Math.min(Ot,Math.max(...h)+24);n.image=new OffscreenCanvas(Math.max(1,Math.ceil((r-s)*d)),Math.max(1,Math.ceil((u-g)*d)));const[S,x,k]=[t,_t,Qt];[t,_t,Qt,n.x,n.y]=[n.image.getContext("2d"),0,null,s,g],t.setTransform(d,0,0,d,-s*d,-g*d),t.lineCap=t.lineJoin="round",Hn(),[t,_t,Qt]=[S,x,k]}t.drawImage(n.image,n.x,n.y,n.image.width/d,n.image.height/d)},Fn=()=>{t.fillStyle=o.board,A([[0,j,0],[$t+.6,j,0],[$t+.6,$,0],[0,$,0]]),Y(),t.fillStyle=I(o.anchorFill,.16),A([[e.left,j,0],[e.right,j,0],[e.right,$,0],[e.left,$,0]]),Y(),t.fillStyle=o.inlayDot;const n=s=>(Math.max(0,Math.ceil(s)-1)+.5)*_;t.beginPath();for(const s of Cn)for(const r of s%12?[n((U-1)/2)]:[n((U-1)/4),xt-n((U-1)/4)]){const[g,u,S]=v(s-.5,r,0);t.moveTo(g+.1*S,u),t.ellipse(g,u,.1*S,.08*S,0,0,Math.PI*2)}Y(),R>0&&(t.fillStyle=I(o.ink,.5),A([[0,j,0],[R-Rn,j,0],[R-Rn,$,0],[0,$,0]]),Y()),jt&&Wi();const[,i]=v(vt[0],$,0),[,h]=v(vt[0],j,0);t.strokeStyle=mi(t,i,h,I(o.anchorPost,.75),o.post),t.lineWidth=Math.max(1.5,.05*p),t.beginPath();for(let s=1;s<=$t;s++)ut([s,j-.04,0],[s,$+.04,0]);N(),t.strokeStyle=o.nut,t.lineWidth=Math.max(3,.12*p),H([0,j-.06,0],[0,$+.06,0]),tt(!0,o.anchorPost,12),t.strokeStyle=o.anchorPost,t.lineWidth=Math.max(3,.07*p);for(const s of[e.left,e.right])H([s,j-.14,0],[s,$+.14,0]);tt(!1);for(let s=0;s<U;s++){const r=Nn(s);tt(!0,Ft(s),3),t.strokeStyle=I(Ft(s),.9),t.lineWidth=r,wn(s),N(),tt(!1),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=Math.max(.6,r*.3),wn(s,.012),N()}if(jt&&(jt.ends.forEach(([s,r],g)=>{if(Xt.clamps)Le(s-.1,s+.1,r-.1,r+.1,.04),St(I(o.text,.22),I(o.text,.45)),Ae([s,r],.05,.05),St(o.nut);else{Ae([s,r],.17,.17),St(I(o.ink,.5),I(o.nut,.4)),Ae([s,r],.085,.085),St(o.nut),Ae([s,r],.03,.03),St(I(o.ink,.85));const[u,S,x]=v(...rn[g]),[k,J]=v(0,st(g),0),F=Math.atan2(J-S,k-u);t.beginPath(),t.arc(u,S,.1*Pe*x,F-1.3,F+1.3),St(null,Ft(g),Nn(g))}}),Xt.tree)){const s=[U-2,U-1].map(r=>{const[g,u]=jt.ends[r];return Wn(r)+(u-Wn(r))*Xt.tree/g});Le(Xt.tree-.05,Xt.tree+.05,Math.min(...s)-.08,Math.max(...s)+.08,.04),St(I(o.nut,.7),I(o.ink,.6))}for(const s of[!1,!0])for(let r=1;r<=$t;r++){const g=r>=Tt.fret&&r<Tt.fret+Tt.width,u=Cn.includes(r);(g||u)===s&&yt(String(r),r-.5,j-.3,0,g?.3:u?.26:.2,g?o.accent:u?o.inlay:o.numOff,s?800:500,"center",!1)}},Ge=(n,i)=>v(n,i,0).slice(0,2).map(h=>Math.round(h*d*10)).join(":"),In=[o.headstock,U,_,vn,m,d,Math.round(mt*1e4),Ge(0,j),Ge($t,j),Ge(0,$),Ge($t,$),Ge(-4,xt/2)].join(),hn=!sn.size&&[In,Tt.fret,Tt.width,R,Math.round(e.left*1e3),Math.round(e.right*1e3)].join();if(!hn||e.board?.key!==hn||e.board.t!==o)e.board=hn&&{key:hn,t:o},Fn();else{const n=e.board;if(!n.drawn){const i=[[0,$+.2],[$t,$+.2],[0,j-.9],[$t,j-.9]].map(([u,S])=>v(u,S,0)[1]);jt&&i.push(...[...jt.outline,...jt.keys.map(({u,side:S,edge:x})=>[u,x+S*.8])].map(u=>v(...le(u))[1]));const h=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,s=Math.min(Ot,Math.max(...i)+24),[r,g]=[Math.ceil(m*d),Math.max(1,Math.ceil((s-h)*d))];(e.boardImage?.width!==r||e.boardImage.height!==g)&&(e.boardImage=new OffscreenCanvas(r,g)),[t,_t,Qt,n.y,n.drawn]=[e.boardImage.getContext("2d"),h,null,h,!0],t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,r,g),Ut(),t.lineCap=t.lineJoin="round",t.textBaseline="middle",Fn(),[t,_t,Qt]=[M,0,null]}t.drawImage(e.boardImage,0,n.y,e.boardImage.width/d,e.boardImage.height/d)}ue("board");const zn=(n,i)=>n.letRing&&-i>.25;for(const n of qt){const i=n.time-f;if(i>0||-i>Math.max(n.sustain,.15)||n.mute)continue;const h=Ft(n.string),s=ln(n);if(tt(!zn(n,i),h,10),t.strokeStyle=h,t.lineWidth=Vn+3,wn(n.string,0,!0),N(),tt(!1),-i<.2){const[r,g,u]=v(ge(n).x,s,0);t.save(),t.translate(r,g),t.scale(1,.4);const S=t.createRadialGradient(0,0,0,0,0,.5*u);S.addColorStop(0,I(o.flash,.8*(1+i/.2))),S.addColorStop(1,I(o.flash,0)),t.fillStyle=S,t.beginPath(),t.arc(0,0,.5*u,0,Math.PI*2),Y(),t.restore()}}t.strokeStyle=o.anchorLane,t.lineWidth=2.5,tt(!0,o.anchorLane,10);for(const n of l.handShapes??[]){if(n.startTime>f||n.endTime<=f||n.endTime-n.startTime<.3||!n.frets.some((s,r)=>s>=0&&r<U))continue;const[i,h]=rt(n.frets.filter((s,r)=>r<U),n.startTime);A([[i,j,0],[h,j,0],[h,$,0],[i,$,0]]),N()}if(tt(!1),R>0){const n=R-Rn;t.strokeStyle=o.nut,t.lineWidth=Math.max(4,.17*p),H([n,j-.16,0],[n,$+.16,0]),t.strokeStyle=I(o.ink,.45),t.lineWidth=Math.max(1,.05*p),H([n,j-.13,0],[n,$+.13,0])}ue("strings");for(const n of qt){const i=n.time-f,h=ct(i),s=me(n),{a:r,open:g,x:u,y:S}=ge(n),x=an(n,u,-i);if(i<-.15||Math.abs(v(x,S,h)[0]-m/2)>m/2+200)continue;const k=g?(r.width-.2)/2:.34;t.globalAlpha=i<0?Math.max(0,1+i/.15):Math.min(1,(E-i)/.4),!s&&Lt&&(t.strokeStyle=Lt,t.lineWidth=2,H([x-k,P,h],[x+k,P,h])),!(g||An(n))&&(t.strokeStyle=I(Ft(n.string),n.repeat||s?.highDensity?.35:.75),t.lineWidth=1.5,H([x,Math.min(S,ln(n))-.42*_,h],[x,P,h]))}t.globalAlpha=1;const Gn=(n,i,h)=>{const s=Array.from({length:13},(r,g)=>{const u=g/12;return[n[0]+(i[0]-n[0])*u,n[1]+(i[1]-n[1])*u+Math.sin(Math.PI*u)*h,n[2]+(i[2]-n[2])*u]});A(s,!1),N()};for(const n of eo(l)){if(n.end<=f||n.time>=f+E)continue;const[i,h]=rt(n.frets,n.time),s=n.time-f,r=ct(Math.max(s,0)),g=ct(Math.min(n.end-f,E));t.globalAlpha=Math.min(1,(E-Math.max(s,0))/.4),tt(!n.arpeggio,o.anchorLane,10,!0),t.strokeStyle=Wt(o.anchorLane,1,.2),t.lineWidth=3.5;for(const u of[i,h])H([u,P,r],[u,P,g]);tt(!1),n.arpeggio&&s>0&&(t.strokeStyle=I(o.anchorLane,.7),t.lineWidth=1.5,A([[i,P,r],[i,$,r],[h,$,r],[h,P,r]],!1),N(),n.arpeggio.name&&r>Re&&yt(n.arpeggio.name,i-.12,$/2,r,.34,o.text,600,"right"))}t.globalAlpha=1;const $n=(n,i)=>{const h=ge(n);return Math.abs(h.x-i)<(h.open?(h.a.width-.2)/2+.1:.45)};for(const[n,i]of qt.entries()){const h=i.time-f,s=me(i),r=i.slideTo??i.slideUnpitchTo??null,{a:g,open:u,x:S,y:x}=ge(i),k=Ft(i.string),J=ct(h),F=(u?(g.width-.2)/2:.34)*(i.grace?.6:1),z=(u?.12:.42)*_*(i.grace?.6:1);if(h>-.15&&!s?.highDensity&&!i.repeat){if(t.globalAlpha=Math.min(1,(E-h)/.4),t.strokeStyle=k,t.lineWidth=2,t.setLineDash([4,4]),i.slideIn&&H([S+(i.slideIn==="below"?-1.4:1.4),x-z,Math.max(0,J-1)],[S+(i.slideIn==="below"?-F:F),x,J]),i.slideOut&&H([S+(i.slideOut==="up"?F:-F),x,J],[S+(i.slideOut==="up"?1.4:-1.4),x-z,J+1]),t.setLineDash([]),typeof i.tieTo=="number"){const G=l.notes[i.tieTo],q=ge(G);t.setLineDash([5,4]),Gn([S,x+z,J],[q.x,q.y+z,ct(G.time-f)],_*.9),t.setLineDash([])}t.globalAlpha=1}const W=r===null?i.sustain:Math.max(i.sustain,.25),O=r!==null||i.bend||i.bendCurve||i.whammy;if(W<=.2||h+W<=0||s&&!O||An(i))continue;u&&r&&(t.strokeStyle=k,t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]),Gn([S,x,ct(Math.max(h,0))],[r-.5,x,ct(Math.min(h+W,E))],_*1.5),t.setLineDash([]));let lt=null;for(let G=n+1;G<qt.length&&qt[G].time<=i.time+W+.02;G++){const q=qt[G];if(!(q.time<=i.time+.005)&&(me(q)||q.string===i.string||$n(q,S))){lt=q;break}}const nt=Math.max(h,0),X=i.bend||i.bendCurve||i.whammy;let at=Math.min(h+W,E,lt?lt.time-f:1/0);if(at<=nt)continue;const b=G=>{const q=G-h,it=ct(G),y=i.bend||i.bendCurve||i.whammy,T=i.vibrato&&!y?Math.sin(it/1.6*Math.PI*2)*_*(i.vibratoWide?.45:.25):0,C=i.tremolo?Math.floor(it/.3)%2?.05:-.05:0,Z=cn+(Bi-cn)*gi(Math.min(1,it/Hi));return[an(i,S,q)+C,x+T+On(i,q)*Z/cn,it]},kt=lt&&b(at)[0],It=lt&&me(lt)?.notes.find(G=>$n(l.notes[G],kt)),et=typeof It=="number"?l.notes[It]:lt;if(lt&&(X||$n(et,kt))){const G=ge(et),q=ct(et.time-f),it=G.open?(G.a.width-.2)/2:.34,y=v(G.x,G.y-(G.open?.12:.42)*_,q)[1]+3,[T]=v(G.x-it,G.y,q),[C]=v(G.x+it,G.y,q),Z=K=>{const[At,pe]=v(...b(K));return pe<y&&At>Math.min(T,C)-2&&At<Math.max(T,C)+2};if(Z(at)&&!Z(nt)){let K=nt,At=at;for(let pe=0;pe<24;pe++)[K,At]=Z((K+At)/2)?[K,(K+At)/2]:[(K+At)/2,At];at=K}if(at<=nt+.001)continue}const De=r===null&&!X&&!i.vibrato&&!i.tremolo?1:Math.min(400,Math.max(12,Math.ceil((at-nt)*dt*8))),Mt=Array.from({length:De+1},(G,q)=>b(nt+(at-nt)*q/De));if(u&&!s){t.fillStyle=Wt(k,i.letRing?.14:.26,.03),A([...Mt.map(([G,q,it])=>[G-F,q,it]),...Mt.slice().reverse().map(([G,q,it])=>[G+F,q,it])]),Y(),tt(!i.letRing,k,6,!0),t.strokeStyle=Wt(k,.95,.3),t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]);for(const G of[-F,F])A(Mt.map(([q,it,y])=>[q+G,it,y]),!1),N();t.setLineDash([]),tt(!1)}else if(i.bend||i.bendCurve||i.whammy){const G=q=>A([...Mt.map(([it,y,T])=>[it-q,y,T]),...Mt.slice().reverse().map(([it,y,T])=>[it+q,y,T])]);G(dn),t.fillStyle=Wt(k,1,.6),Y(),G(dn*.35),t.fillStyle=Wt(_n(k,-.22),1,.55),Y(),tt(!0,k,8,!0),t.strokeStyle=Wt(_n(k,.6),1,.5),t.lineWidth=2;for(const q of[-dn,dn])A(Mt.map(([it,y,T])=>[it+q,y,T]),!1),N();tt(!1)}else tt(!i.letRing,k,6,!0),t.fillStyle=Wt(k,i.letRing?.4:.75,i.letRing?.15:.3),A([...Mt.map(([G,q,it])=>[G-.09,q,it]),...Mt.slice().reverse().map(([G,q,it])=>[G+.09,q,it])]),Y(),tt(!1);if((i.letRing||r!==null||!X&&(i.vibrato||i.tremolo))&&(t.strokeStyle=Wt(i.letRing?k:"#ffffff",.75,.3),t.lineWidth=i.letRing?2:1.5,t.setLineDash(i.letRing?[7,6]:[]),A(Mt,!1),N(),t.setLineDash([])),r!==null&&at>=Math.min(h+W,E)-.001){const[G,q,it]=b(h+W);t.strokeStyle=k,t.lineWidth=2,t.setLineDash(i.slideTo===null?[5,4]:[]),u?Pt(r-.5,q,it,.34,.42*_):Pt(G,q,it,F,z),N(),t.setLineDash([])}}ue("trails");const Un=new Set;for(let n=qt.length-1;n>=0;n--){const i=qt[n],h=i.time-f,s=ct(h),r=me(i),{a:g,open:u,x:S}=ge(i),x=an(i,S,-h),k=ln(i),J=i.mute||r?.fretHandMute,F=i.palmMute||r?.palmMute,z=Ft(i.string),W=(u?(g.width-.2)/2:.34)*(i.grace?.6:1),O=(u?.12:.42)*_*(i.grace?.6:1),lt=i.slideTo??i.slideUnpitchTo??null;if(h<-.15)continue;const nt=h<0?Math.max(0,1+h/.15):Math.min(1,(E-h)/.4);if(t.globalAlpha=nt,r&&!Un.has(i.chord)){Un.add(i.chord);const[y,T]=rt(r.notes.map(ht=>l.notes[ht].fret),i.time),C=t.globalAlpha,Z=s<Re,K=Z?.65:r.highDensity&&o.repeatMarks!=="frame"?.18:.5;if(A([[y,P,s],[T,P,s],[T,$,s],[y,$,s]]),o.frames==="gradient"){const[,ht]=v(y,P,s),[,Et]=v(y,$,s),Dt=Z?o.anchorLane:o.anchorFill;ze(di(t,`${Dt}|${K}`,[[0,I(Dt,K*.6)],[1,I(Dt,0)]]),ht,Et)}else t.globalAlpha=C*K,r.highDensity||(t.fillStyle=o.chordFill,Y()),t.strokeStyle=Z?o.anchorLane:o.chordBox,t.lineWidth=Z||!r.highDensity?1.5:1.2,tt(Z,o.anchorLane,8),N(),tt(!1);if(t.globalAlpha=C,t.strokeStyle=Lt,t.lineWidth=2,Lt&&H([y,P,s],[T,P,s]),r.highDensity&&(r.palmMute||r.fretHandMute)&&(t.strokeStyle=r.palmMute?o.muted:"#ffffff",fe((y+T)/2,P+_*.4,s,r.palmMute?.22:.12,_*(r.palmMute?.35:.22))),r.accent){const ht=Math.min(.6,(T-y)*.22),Et=($-P)*.35,Dt=Math.min(1,v(y,$,s)[2]/v(y,$,Re)[2]);t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,3.5*Dt*(r.accent==="heavy"?1.4:1)),t.lineCap="square",tt(!0,"#ffffff",Math.max(2,12*Dt)),A([[y,$-Et,s],[y,$,s],[y+ht,$,s]],!1),N(),A([[T-ht,$,s],[T,$,s],[T,$-Et,s]],!1),N(),tt(!1),t.lineCap="round"}if(r.barre&&(!r.highDensity||o.repeatMarks==="grey")){const ht=r.barre.fret-.5;t.strokeStyle=r.highDensity?o.muted:"rgba(255, 255, 255, 0.7)",t.lineWidth=Math.max(3,.1*v(ht,xt/2,s)[2]);const[Et,Dt]=[st(r.barre.from),st(r.barre.to)].sort((re,Kt)=>re-Kt);H([ht,Et-_*.4,s],[ht,Dt+_*.4,s]),yt(r.barre.half?"½B":"B",ht,$+.12,s,.22,r.highDensity?o.muted:o.text)}if(r.strum||r.roll){const ht=y-.25,Et=st(0)>st(U-1)?$-.1:P+.15,Dt=Et>xt/2?P+.15:$-.1,[re,Kt]=(r.strum??r.roll)==="down"?[Et,Dt]:[Dt,Et];t.strokeStyle=o.text,t.lineWidth=2,r.roll?A(Array.from({length:17},(so,Kn)=>[ht+Math.sin(Kn/16*Math.PI*6)*.06,re+(Kt-re)*Kn/16,s]),!1):A([[ht,re,s],[ht,Kt,s]],!1),N();const Ce=Kt<re?.14:-.14;H([ht-.08,Kt+Ce,s],[ht,Kt,s]),H([ht+.08,Kt+Ce,s],[ht,Kt,s])}const At=l.chords[i.chord-1],pe=!At||i.time-At.time>1||At.name!==r.name;s>Re&&r.name&&!r.highDensity&&pe&&yt(r.name,y-.12,$/2,s,.34,o.text,600,"right")}const[X,at,b]=v(x,k,s);if(X<-200||X>m+200||An(i)){t.globalAlpha=1;continue}const kt=i.repeat||r?.highDensity;if(kt){const y=s<Re;t.globalAlpha*=y?.9:.4,t.strokeStyle=z,t.lineWidth=y?2:1.5,tt(y,z,8),Pt(x,k,s,W,O),N(),tt(!1),(J||F)&&o.repeatMarks!=="hide"&&Ie(x,k,s,b,u?.34:W,u?_*.3:O,F,o.muted),t.globalAlpha=nt}else{if(!u&&he){const y=i.harmonic||i.harmonicPinch?`<${i.fret}>`:i.ghost?`(${i.fret})`:String(i.fret),T=i.grace?.7:1;ee(y,x,Math.max(.35,s-.55),ti*T,ei*T,I(z,he))}if(i.dynamicLabel&&yt(i.dynamicLabel,x-.6,P,s,.3,o.text,"italic 700","right"),i.ghost&&(t.globalAlpha=nt*.5),o.gem==="pill")o.notes3d!==!1&&(Pt(x,k,s+Zn,W,O),t.fillStyle=z,Y(),t.fillStyle="rgba(255, 255, 255, 0.35)",Y()),Pt(x,k,s,W,O),t.fillStyle=z,Y();else{const y=i.harmonic||i.harmonicPinch,T=Zn;if(!y&&o.notes3d!==!1)for(const[K,At]of[[[[x-W,k+O,s],[x+W,k+O,s],[x+W,k+O,s+T],[x-W,k+O,s+T]],"rgba(255, 255, 255, 0.35)"],[[[x-W,k-O,s],[x-W,k+O,s],[x-W,k+O,s+T],[x-W,k-O,s+T]],"rgba(0, 0, 0, 0.4)"],[[[x+W,k-O,s],[x+W,k+O,s],[x+W,k+O,s+T],[x+W,k-O,s+T]],"rgba(0, 0, 0, 0.4)"]])A(K),t.fillStyle=z,Y(),t.fillStyle=At,Y();tt(s<Re,z,8),t.fillStyle=z,y?A([[x,k+O*1.3,s],[x+W*.8,k,s],[x,k-O*1.3,s],[x-W*.8,k,s]]):Pt(x,k,s,W,O),Y(),tt(!1);const[,C]=v(x,k+O,s),[,Z]=v(x,k-O,s);ze(di(t,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),C,Z),t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=1,N()}if((J||F)&&Ie(x,k,s,b,u?.34:W,u?_*.3:O,F,u&&F?z:null),!u&&!J&&!F){const y=i.finger??(r?.fingers?.[i.string]>=0?r.fingers[i.string]:null),T=y!==null?y===0?"T":String(y):"";if(T){const C=t.globalAlpha;t.globalAlpha=C*Math.min(1,Math.max(0,(1-h/E)/.4)),yt(T,x,k,s-.01,_*.62,Zt,700,"center",We,!0),t.globalAlpha=C}}}if(kt&&o.repeatMarks==="hide"){t.globalAlpha=1;continue}const It=kt?o.muted:o.text;if(t.globalAlpha=nt*(kt?.8:1)*Math.min(1,Math.max(0,(1-h/E)/.15)),i.ghost){const[y]=v(x-W,k,s),[T]=v(x+W,k,s),C=O*b*1.5;t.strokeStyle=kt?It:z,t.lineWidth=Math.max(1.2,.035*b),t.beginPath(),t.arc(y+C*.35,at,C,Math.PI*.7,Math.PI*1.3),N(),t.beginPath(),t.arc(T-C*.35,at,C,-Math.PI*.3,Math.PI*.3),N()}if(i.grace&&(t.strokeStyle=It,t.lineWidth=Math.max(1,.03*b),Xe(t,X-W*b*mt*1.2,at+O*b*1.4,X+W*b*mt*1.2,at-O*b*1.4)),i.showString){const[y]=v(x-W,k,s),T=.12*b,C=y-T-.06*b;t.strokeStyle=t.fillStyle=kt?It:z,t.lineWidth=Math.max(1,.025*b),t.beginPath(),t.arc(C,at,T,0,Math.PI*2),N(),oe(String(U-i.string),C,at,.15*b,700,"center"),t.fillText(String(U-i.string),0,0),Ut()}let et=at-O*b-.18*b;t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b),t.textAlign="center";const Dn=(y,T,C)=>{t.beginPath();for(let Z=0;Z<=20;Z++)t[Z?"lineTo":"moveTo"](X-y+2*y*Z/20,et+Math.sin(Z/20*Math.PI*2*C)*T);N()},De=(y,T,C="700")=>{T*b<2||(oe(y,X,et,T*b,C,"center"),t.fillText(y,0,0),Ut(),et-=(T+.04)*b)};let Mt=at-O*b;const G=i.tap&&!i.tapLeft;if((i.hammerOn||i.pullOff)&&!G){const y=i.grace?.6:1,T=.2*b*mt*y,C=.38*_*b*y,[Z,K]=i.hammerOn?[Mt+.4*C,Mt-.6*C]:[Mt-.6*C,Mt+.4*C];t.beginPath(),t.moveTo(X-T,K),t.lineTo(X+T,K),t.lineTo(X,Z),t.closePath(),t.fillStyle=kt?It:"#ffffff",t.strokeStyle=I(o.ink,.9),t.lineWidth=Math.max(1.5,.03*b),N(),Y(),Mt-=.6*C,et=Math.min(et,Mt-.14*b),t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b)}if(G){const y=i.grace?.6:1,T=.28*b*mt*y,C=.62*_*b*y,Z=Mt+.15*C,K=Z-C;t.beginPath(),t.moveTo(X,Z),t.lineTo(X+T,K),t.lineTo(X,K+.38*C),t.lineTo(X-T,K),t.closePath(),t.strokeStyle=I(o.ink,.9),t.lineWidth=Math.max(3.5,.1*b),N(),t.fillStyle=kt?I(It,.4):I(_n(z,.55),.85),Y(),t.strokeStyle=kt?It:z,t.lineWidth=Math.max(1.8,.05*b),N(),Mt=K,et=Math.min(et,Mt-.14*b),t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b)}const q=Oe(i);if(q>0){const y=i.bendCurve?.[0]?.[1]>0,T=(i.bendCurve?.length??0)>1&&i.bendCurve.at(-1)[1]<q,C=Math.min(3,Math.max(1,Math.round(q*2))),Z=W*b*mt*.6,K=W*b*.3,At=K*1.25,pe=I(o.ink,.9);let ht=Mt-.04*b;const Et=Kt=>{for(let Ce=0;Ce<C;Ce++)Pi(t,X,ht-Ce*At-(Kt>0?0:K),Z,K,Kt,kt?It:z,pe);ht-=C*At+.08*b},Dt=Ht(i.string);(!y||!T)&&Et(-Dt),T&&Et(Dt);const re=`${y?"pre ":""}${yi(q)}`;t.fillStyle=It,oe(re,X+Z+.08*b,(at-O*b+ht)/2,.22*b,700,"left"),t.fillText(re,0,0),Ut(),t.textAlign="center",et=Math.min(et,ht-.1*b)}i.staccato&&(t.beginPath(),t.arc(X,et+.04*b,Math.max(1.5,.045*b),0,Math.PI*2),Y(),et-=.16*b),i.accent&&(i.accent==="tenuto"||!r?.accent)&&De({heavy:"^",tenuto:"–"}[i.accent]??">",.3);const it=[i.tapLeft?"m.g.":"",bi[i.harmonicType]??(i.harmonicPinch?"PH":""),i.slap?"slap":i.pop?"pop":"",i.golpe?`golpe (${i.golpe})`:"",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 y of it)y&&De(y,y.length>2?.22:.28);if(i.rightFinger&&De(i.rightFinger,.26,"italic 700"),i.vibrato&&(Dn(.24*b,(i.vibratoWide?.07:.035)*b,2),et-=(.16+(i.vibratoWide?.06:0))*b),i.pick){const y=.09*b,T=.13*b;t.beginPath(),i.pick==="down"?[[-y,T/2],[-y,-T/2],[y,-T/2],[y,T/2]].forEach(([C,Z],K)=>t[K?"lineTo":"moveTo"](X+C,et+Z)):[[-y,-T/2],[0,T/2],[y,-T/2]].forEach(([C,Z],K)=>t[K?"lineTo":"moveTo"](X+C,et+Z)),N(),et-=.22*b}if(i.fermata&&(t.beginPath(),t.arc(X,et+.06*b,.14*b,Math.PI,0),N(),t.beginPath(),t.arc(X,et+.02*b,Math.max(1.5,.03*b),0,Math.PI*2),Y(),et-=.24*b),i.tremolo){for(let y=-1;y<=1;y++)Xe(t,X-.12*b,et+(y*.08+.05)*b,X+.12*b,et+(y*.08-.05)*b);et-=.3*b,Dn(.14*b,.04*b,1.5),et-=.14*b}if(lt!==null&&!u){const y=Math.sign(lt-i.fret)||1,T=X-y*.16*b,C=X+y*.16*b,Z=et+.07*b,K=et-.09*b;Xe(t,T,Z,C,K),Xe(t,C,K,C-y*.1*b,K),Xe(t,C,K,C,K+.1*b),et-=.3*b}t.globalAlpha=1}ue("notes");const Yn=new Set;for(const n of qt){const i=n.time-f,h=me(n);if(!h?.barre||Yn.has(h)||i>.06||i<-Math.max(n.sustain,.12))continue;Yn.add(h),t.strokeStyle="rgba(255, 255, 255, 0.85)",t.lineWidth=Math.max(4,.12*p);const[s,r]=[st(h.barre.from),st(h.barre.to)].sort((g,u)=>g-u);H([h.barre.fret-.5,s-_*.45,0],[h.barre.fret-.5,r+_*.45,0])}const qn=new Set,Xn=new Set;for(const n of qt){const i=n.time-f,h=me(n),s=sn.get(n.string),r=n.heldFrom??null,g=i<=.06||r!==null&&f>=r-.06,u=(n.slideTo??n.slideUnpitchTo??null)!==null;if(n.mute||i>fn||i<-Math.max(n.sustain,u?.25:.12)||(h?.highDensity||r!==null)&&!g||s&&s.note!==n&&!g||g&&qn.has(`${n.string}:${n.fret}`))continue;g&&qn.add(`${n.string}:${n.fret}`),Xn.add(`${n.string}:${n.fret}`);const{a:S,open:x,x:k}=ge(n),J=an(n,k,-i),F=ln(n),z=Ft(n.string),W=(x?(S.width-.2)/2:.32)+2/p,O=(x?.1:.36)*_+2/p;if(Pt(J,F,0,W,O),g)tt(!zn(n,i),z,14),t.fillStyle=z,Y(),tt(!1),t.strokeStyle="rgba(255, 255, 255, 0.7)",t.lineWidth=1.5,N();else{const nt=(1-i/fn)**2;t.globalAlpha=.35*nt,t.fillStyle=z,Y(),t.globalAlpha=.25+.75*nt,t.strokeStyle=z,t.lineWidth=2.2,N()}const lt=n.finger??(h?.fingers?.[n.string]>=0?h.fingers[n.string]:null);if(!x&&lt!==null&&yt(lt===0?"T":String(lt),J,F,0,_*.55,g?Zt:o.text,800,"center",!g||We),!x&&Oe(n)>0){const nt=Ht(n.string),X=n.bendCurve?.[0]?.[1]>0&&n.bendCurve.at(-1)[1]<Oe(n),[at,b]=v(J,F+nt*O,0);Pi(t,at,b-nt*(X?.14:.05)*p,.17*p*mt,.085*p,(X?1:-1)*nt,"#ffffff",I(o.ink,.9))}t.globalAlpha=1}for(const n of l.handShapes??[])!n.arpeggio||n.startTime-f>fn||n.endTime<=f||(t.globalAlpha=.3+.5*Math.min(1,1-(n.startTime-f)/fn)**2,n.frets.forEach((i,h)=>{if(i<=0||h>=U||Xn.has(`${h}:${i}`))return;const s=i-.5,r=st(h),g=n.fingers[h];Pt(s,r,0,.32+2/p,.36*_+2/p),t.strokeStyle=Ft(h),t.lineWidth=2.2,N(),g>=0&&yt(g===0?"T":String(g),s,r,0,_*.55,o.text,800)}),t.globalAlpha=1);ue("targets");const jn=to(l),Ln=jn.findLast(n=>n.time<=f&&f<n.end+.3),Ii=Ln?null:jn.find(n=>n.time>f&&n.time-f<1.2),Ue=Ln??Ii;if(Ue){const[n,i]=v(e.right+.4,$+.5,0),h=Jt(t,ce[700]??=`700 ${Bt}px ${o.num}`,Ue.name).width*52/Bt;t.globalAlpha=Ln?1:Math.max(.35,1-(Ue.time-f)/1.2),t.fillStyle=o.text,oe(Ue.name,Math.min(n,m-24-h),i,52,700,"left"),t.fillText(Ue.name,0,0),Ut(),t.globalAlpha=1}ue("labels")}const io=240,oo=64,xe=100,Be=24,wi=150;function ao(a,l){if(a.tabPages?.length===l)return a.tabPages.pages;const f=a.notes.at(-1),o=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(o/l)+1},(d,t)=>t*l)),e=[Math.min(0,e[0]),...e.filter(d=>d>0),Math.max(o,e.at(-1)+.01)];const M=[];let m=e[0];for(let d=1;d<e.length;d++)e[d]-m>l&&e[d-1]>m&&M.push({start:m,end:m=e[d-1]});M.push({start:m,end:e.at(-1)});for(let d=0;d<M.length-1;d++)M[d].end=M[d+1].start;return a.tabPages={length:l,pages:M},M}function fo(a,l,f,o){const{g:e,W:M}=Ai(a);if(!l)return;const m=l.strings,d=Math.min(oo,320/Math.max(1,m-1))*(o.boardHeight??1),t=Ot*.62-d*(m-1)/2,L=t+d*(m-1),R=t-d*1.65,Tt=L+d*1.45,U=w=>t+(o.stringOrder==="high"?m-1-w:w)*d,wt=io*(o.noteSpeed??1),_=o.tabLayout==="pages",xt=xe+30,st=M-Be-30,Ht=_?Math.min(170,(st-xt)*.14):0,dt=st-(_?Ht+24:0);let E,j,$,P,Nt=null;if(_){const w=ao(l,(dt-xt)/wt),Q=Math.max(0,w.findLastIndex(Ct=>Ct.start<=f)),V=w[Q],bt=(dt-xt)/(V.end-V.start);E=Ct=>xt+(Ct-V.start)*bt,[$,P]=[V.start,V.end-.001],j=E(Math.min(Math.max(f,V.start),V.end)),w[Q+1]&&(Nt={start:w[Q+1].start,scale:bt})}else j=Math.max(xe+wi+60,M*.2),E=w=>j+(w-f)*wt,[$,P]=[f-(j-xe)/wt,f+(M-j)/wt];const ct=w=>o.str[w%o.str.length],Ft=w=>w.chord===null||w.chord===void 0?null:l.chords[w.chord],Lt=(w,Q,V,bt)=>{e.beginPath(),e.moveTo(w,Q),e.lineTo(V,bt),e.stroke()},he=(w,Q,V,bt)=>{const Ct=Math.hypot(V,bt),[te,zt]=[V/Ct,bt/Ct];Lt(w,Q,w-6*te-4*zt,Q-6*zt+4*te),Lt(w,Q,w-6*te+4*zt,Q-6*zt-4*te)},Vt=w=>w>=j-1?1:.4;e.lineCap="round",e.lineJoin="round",e.textBaseline="alphabetic";const vt=[],we=w=>{w&&(e.save(),e.beginPath(),e.rect(w[0],0,w[1]-w[0],Ot),e.clip());const Q=`600 ${Me(Math.min(15,d*.26))}px ${o.num}`,V=`700 ${Me(Math.min(13,d*.22))}px ${o.num}`,bt=new Map;e.font=Q,e.textAlign="left";const Ct=new Path2D,te=new Path2D;e.fillStyle=o.muted;for(let p=_e(l.beats,$-1);p<l.beats.length;p++){const c=l.beats[p];if(c.time>P)break;const D=E(c.time),gt=c.measure>=0,A=gt?Ct:te;A.moveTo(D,t-d*.35),A.lineTo(D,L+d*.35),gt&&(e.fillText(String(c.measure),D+6,R+d*.36),bt.set(Math.round(c.time*50),Jt(e,Q,String(c.measure)).width+16))}e.lineWidth=1,e.strokeStyle=I(o.text,.05),e.stroke(te),e.lineWidth=1.5,e.strokeStyle=I(o.text,.16),e.stroke(Ct),e.fillStyle=o.accent;const zt=new Map;for(const p of l.markers??[])p.time>=$&&p.time<=P&&zt.set(Math.round(p.time*50),[...zt.get(Math.round(p.time*50))??[],p.text]);for(const[p,c]of zt)e.fillText([...new Set(c)].join(" · "),E(p/50)+6+(bt.get(p)??0),R+d*.36);e.strokeStyle=I(o.text,.14),e.beginPath();for(let p=0;p<m;p++)e.moveTo(xe,U(p)),e.lineTo(M-Be,U(p));e.stroke();const ve=L+d*.92,Rt=L+d*1.24;if(o.guides!==!1){e.font=Q,e.fillStyle=e.strokeStyle=o.anchorLane,e.lineWidth=2;let p=-1/0;const c=l.anchors??[];for(let D=Math.max(1,_e(c,$));D<c.length&&c[D].time<=P;D++){const gt=c[D],A=E(gt.time);if(A<p)continue;const H=`fret ${gt.fret}`;e.globalAlpha=Vt(A),Lt(A,L+d*.6,A,ve-2),e.fillText(H,A+5,ve),p=A+5+Jt(e,Q,H).width+8}e.globalAlpha=1}e.strokeStyle=o.text,e.lineWidth=1.5;for(const p of l.hairpins??[]){if(p.endTime<$||p.time>P)continue;const c=E(p.time),D=Math.max(c+30,E(p.endTime)),[gt,A]=p.kind==="cresc"?[c,D]:[D,c];e.globalAlpha=Vt(D),e.beginPath(),e.moveTo(A,Rt-11),e.lineTo(gt,Rt-5),e.lineTo(A,Rt+1),e.stroke()}e.globalAlpha=1;const be=Me(Math.min(26,d*.42)),Gt=be*1.3,Ke=be*.32,Je=o.gem==="pill"?Gt/2:5,mt={note:`700 ${be}px ${o.num}`,grace:`700 ${Me(be*.72)}px ${o.num}`,finger:`700 ${Me(be*.5)}px ${o.num}`},Ve=o.markings==="white";for(const p of l.handShapes??[]){if(!p.arpeggio||p.endTime<$||p.startTime>P)continue;const c=p.frets.flatMap((A,H)=>A>=0&&H<m?[U(H)]:[]);if(!c.length)continue;const D=E(p.startTime)-12,gt=E(p.endTime);e.globalAlpha=Vt(gt),e.strokeStyle=I(o.text,.4),e.lineWidth=1.5,e.setLineDash([6,5]),e.beginPath(),e.roundRect(D,Math.min(...c)-Gt/2-6,gt-D,Math.max(...c)-Math.min(...c)+Gt+12,8),e.stroke(),e.setLineDash([]),p.name&&(e.font=`700 ${Me(Math.min(24,d*.4))}px ${o.num}`,e.fillStyle=o.text,e.fillText(p.name,D,t-d*.72))}e.globalAlpha=1;const Ne=p=>(p.slideTo??p.slideUnpitchTo??null)!==null||!!p.slideOut,bn=p=>{const c=Ft(p);return!!c&&!p.repeat&&!c.highDensity&&c.notes.length>1},yn=(p,c)=>4+(Ne(p)?16:0)+(bn(c)?10:0)+(c.slideIn?18:0)+(c.showString?20:0);let Ze=0,Fe=0;const ye=(p,c)=>{c(Fe-p/2),Fe-=p+3},Sn={"":V,"italic ":`italic ${V}`},Se=(p,c="")=>ye(10,D=>{e.font=Sn[c],e.fillText(p,Ze,D+5)}),{next:kn,prev:Qe,held:Tn}=hi(l),tn=new Map,en=new Set,v=[],nn=[];for(let p=_e(l.notes,$-Tn-.5);p<l.notes.length;p++){const c=l.notes[p];if(c.time>P)break;if(E(c.time+c.sustain)<xe-40-Gt*4||w&&c.time<$&&E(c.time+c.sustain)-2<=E($)&&typeof c.tieTo!="number")continue;const D=Ft(c),gt=c.grace?.72:1,A=Gt*gt,H=U(c.string),Pt=ct(c.string),rt=E(c.time),fe=c.mute||D?.fretHandMute,We=c.palmMute||D?.palmMute,Zt=c.repeat||D?.highDensity,Ie=fe?"×":c.harmonic||c.harmonicPinch?`<${c.fret}>`:c.ghost?`(${c.fret})`:String(c.fret),Qt=c.finger??(D?.fingers?.[c.string]>=0?D.fingers[c.string]:null),_t=fe||c.fret===0||Qt===null?"":Qt===0?"T":String(Qt),ke=c.grace?mt.grace:mt.note,ce=Jt(e,ke,Ie).width,oe=_t?Jt(e,mt.finger,_t).width+3:0,Ut=l.notes[kn[p]],ze=Ut?E(Ut.time)-yn(c,Ut):1/0,yt=Math.min(Math.max(A,ce+oe+Ke*2*gt),Math.max(10,ze-rt)),ee=Math.max(rt+yt,Math.min(E(c.time+c.sustain)-2,ze)),pt=rt+yt/2,$e=Math.min(1,(yt-4)/(ce+oe)),Wt=tn.get(c.string)??(Qe[p]>=0?{x0:E(l.notes[Qe[p]].time),w:Gt}:null);if(tn.set(c.string,{x0:rt,w:yt}),ee<xe-40&&typeof c.tieTo!="number")continue;const Yt=c.time<=f&&f<c.time+Math.max(c.sustain,.15),tt=(Yt||rt>=j-1?1:.4)*(c.ghost?.55:1);if(e.globalAlpha=tt,D&&!en.has(D)){en.add(D);const de=D.notes.map(B=>U(l.notes[B].string)),ae=Math.min(...de)-Gt/2,N=Math.max(...de)+Gt/2,Y=rt-7;if(de.length>1&&!Zt&&(e.strokeStyle=D.accent?"#ffffff":I(o.text,.7),e.lineWidth=D.accent==="heavy"?4:D.accent?3:2,e.beginPath(),e.moveTo(Y+4,ae),e.lineTo(Y,ae),e.lineTo(Y,N),e.lineTo(Y+4,N),e.stroke()),e.font=V,e.fillStyle=e.strokeStyle=Zt?o.muted:o.text,e.lineWidth=1.8,e.textAlign="left",D.barre&&!Zt&&e.fillText(`${D.barre.half?"½":""}B${D.barre.fret}`,Y,ae-5),D.strum||D.roll){const B=D.notes.map(ie=>l.notes[ie].string),ot=U(Math.min(...B)),ft=U(Math.max(...B)),[ut,ne]=(D.strum??D.roll)==="down"?[ot,ft]:[ft,ot],Te=Y-9;e.beginPath();for(let ie=0;ie<=16;ie++)e.lineTo(Te+(D.roll?Math.sin(ie/16*Math.PI*6)*2.5:0),ut+(ne-ut)*ie/16);e.stroke(),he(Te,ne,0,ne-ut||1)}const se=l.chords[c.chord-1];D.name&&!Zt&&(!se||c.time-se.time>1||se.name!==D.name)&&(e.font=`700 ${Me(Math.min(24,d*.4))}px ${o.num}`,e.fillStyle=o.text,e.fillText(D.name,rt,t-d*.72))}e.beginPath(),e.roundRect(rt,H-A/2,ee-rt,A,Je*gt),Yt&&!Zt&&(e.shadowColor=Pt,e.shadowBlur=18),Zt?(e.strokeStyle=Pt,e.lineWidth=2,e.stroke()):c.letRing&&ee>rt+yt+2?(e.fillStyle=I(Pt,.3),e.fill(),e.shadowBlur=0,e.strokeStyle=Pt,e.lineWidth=2,e.setLineDash([6,5]),Lt(rt+yt+4,H,ee-4,H),e.setLineDash([]),e.beginPath(),e.roundRect(rt,H-A/2,yt,A,Je*gt),e.fillStyle=Pt,e.fill()):(e.fillStyle=fe?I(o.text,.22):Pt,e.fill()),e.shadowBlur=0,Yt&&vt.push({y:H,c:Pt});const Pn=Zt?Pt:fe?o.text:Ve?"#ffffff":o.ink;v.push({text:Ie,font:ke,finger:_t,fill:Pn,shown:tt,squeeze:$e,x:pt,y:H+Jt(e,ke,Ie).middle,left:-(ce+oe)/2,textWidth:ce}),nn.push(()=>{e.globalAlpha=tt;const de=Zt?o.muted:o.text;e.strokeStyle=e.fillStyle=de,e.lineWidth=1.6;const ae=c.slideTo??c.slideUnpitchTo??null,N=ae===null?c.slideOut==="up"?1:c.slideOut?-1:0:Math.sign(ae-c.fret)||1;if(N){const B=c.slideTo===null&&c.slideUnpitchTo!==null&&c.slideUnpitchTo!==void 0;B&&e.setLineDash([3,3]),Lt(ee+4,H+N*A*.3,ee+14,H-N*A*.3),B&&e.setLineDash([])}if(c.slideIn&&Lt(rt-16,H+(c.slideIn==="below"?1:-1)*A*.3,rt-6,H-(c.slideIn==="below"?1:-1)*A*.3),typeof c.tieTo=="number"){const B=E(l.notes[c.tieTo].time)+A/2;e.setLineDash([4,3]),e.beginPath(),e.moveTo(pt,H+A/2+3),e.quadraticCurveTo((pt+B)/2,H+A/2+14,B,H+A/2+3),e.stroke(),e.setLineDash([])}if(c.showString){const B=rt-(D?26:13);e.beginPath(),e.arc(B,H,8,0,Math.PI*2),e.stroke(),e.font=mt.finger,e.textAlign="center",e.fillText(String(m-c.string),B,H+Jt(e,mt.finger,"1").middle)}c.dynamicLabel&&(e.font=`italic ${V}`,e.textAlign="left",e.fillStyle=o.text,e.fillText(c.dynamicLabel,rt,Rt),e.fillStyle=de);let Y=H-A/2-6;if(c.vibrato){e.beginPath();for(let B=rt+2;B<=Math.max(ee,rt+24)-2;B+=2)e.lineTo(B,Y+Math.sin((B-rt)/3)*(c.vibratoWide?3:1.8));e.stroke(),Y-=c.vibratoWide?10:8}if(e.textAlign="center",e.font=V,(c.hammerOn||c.pullOff)&&Wt){const B=Wt.x0+Wt.w/2,ot=(B+pt)/2;e.beginPath(),e.moveTo(B,Y),e.quadraticCurveTo(ot,Y-12,pt,Y),e.stroke(),e.fillText(c.hammerOn?"H":"P",ot,Y-9),Y-=10}const se=Oe(c);if(se>0){const B=c.bendCurve?.[0]?.[1]>0,ot=(c.bendCurve?.length??0)>1&&c.bendCurve.at(-1)[1]<se,ft=rt+yt-2,ut=H-A/2,ne=ut-16;e.beginPath(),B?(e.moveTo(ft,ut),e.lineTo(ft,ne)):(e.moveTo(ft-4,ut+2),e.quadraticCurveTo(ft+4,ut,ft+6,ne)),e.stroke(),he(B?ft:ft+6,ne,B?0:.3,-1),ot&&(e.beginPath(),e.moveTo(ft+12,ne),e.quadraticCurveTo(ft+16,ut-6,ft+16,ut),e.stroke(),he(ft+16,ut,0,1)),e.textAlign="left",e.fillText(`${B?"pre ":""}${yi(se)}`,ft+(ot?20:10),ne+4),e.textAlign="center"}[Ze,Fe]=[pt,Y],c.tap&&!c.tapLeft&&Se("T"),c.staccato&&ye(4,B=>{e.beginPath(),e.arc(pt,B,2,0,Math.PI*2),e.fill()}),c.accent&&(c.accent==="tenuto"||!D?.accent)&&Se({heavy:"^",tenuto:"–"}[c.accent]??">"),We&&Se("PM");for(const B of[c.tapLeft?"m.g.":"",bi[c.harmonicType]??(c.harmonicPinch?"PH":""),c.slap?"slap":c.pop?"pop":"",c.golpe?`golpe (${c.golpe})`:"",c.rasgueado?`rasg. ${c.rasgueado}`:"",typeof c.trill=="number"?`tr ${c.trill}`:"",c.ornament??"",c.fade??"",c.whammy?"w/bar":"",c.wah==="open"?"o":c.wah==="closed"?"+":""])B&&Se(B);c.rightFinger&&Se(c.rightFinger,"italic "),c.pick&&ye(9,B=>{e.beginPath(),c.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([ot,ft],ut)=>e[ut?"lineTo":"moveTo"](pt+ot,B+ft)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([ot,ft],ut)=>e[ut?"lineTo":"moveTo"](pt+ot,B+ft)),e.stroke()}),c.fermata&&ye(9,B=>{e.beginPath(),e.arc(pt,B+4,7,Math.PI,0),e.stroke(),e.beginPath(),e.arc(pt,B+3,1.5,0,Math.PI*2),e.fill()}),c.tremolo&&ye(18,B=>{for(let ot=-1;ot<=1;ot++)Lt(pt-6,B+ot*4+5.5,pt+6,B+ot*4+.5);e.beginPath();for(let ot=0;ot<=12;ot++)e[ot?"lineTo":"moveTo"](pt-8+16*ot/12,B-7+Math.sin(ot/12*Math.PI*2)*2);e.stroke()})})}const on=(p,c,D,gt)=>{if(e.globalAlpha=p.shown*gt,e.fillStyle=p.fill,p.squeeze===1)return e.fillText(c,p.x+p.left+D,p.y);e.save(),e.translate(p.x,p.y),e.scale(p.squeeze,1),e.fillText(c,p.left+D,0),e.restore()};e.textAlign="left";for(const p of[mt.note,mt.grace]){e.font=p;for(const c of v)c.font===p&&on(c,c.text,0,1)}e.font=mt.finger;for(const p of v)p.finger&&on(p,p.finger,p.textWidth+3,.7);for(const p of nn)p();e.globalAlpha=1,w&&e.restore()};if(!_)we(null);else if(we([xt-40,dt+4]),Nt){const w=dt+24,Q=j;E=V=>w+(V-Nt.start)*Nt.scale,[$,P,j]=[Nt.start,Nt.start+Ht/Nt.scale,-1/0],we([w-8,st+4]),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.55)",e.fillRect(w-8,0,st+12-(w-8),Ot),e.restore(),e.strokeStyle=I(o.text,.22),e.lineWidth=1.5,e.setLineDash([3,5]),Lt(dt+12,t-d*.6,dt+12,L+d*.6),e.setLineDash([]),j=Q}e.shadowColor=o.accent,e.shadowBlur=16,e.strokeStyle=o.accent,e.lineWidth=3,Lt(j,t-d*.7,j,L+d*.7);for(const{y:w,c:Q}of vt)e.shadowColor=Q,e.fillStyle="#ffffff",e.beginPath(),e.arc(j,w,4,0,Math.PI*2),e.fill();e.shadowBlur=0,e.globalCompositeOperation="destination-out";for(const[w,Q,V]of _?[]:[[xe+10,1,wi],[M-Be,-1,80]]){const bt=e.createLinearGradient(w,0,w+Q*V,0);bt.addColorStop(0,"rgba(0, 0, 0, 1)"),bt.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=bt,e.fillRect(Q>0?0:w-V,0,Q>0?w+V:M-w+V,Ot)}e.globalCompositeOperation="destination-over",e.beginPath(),e.roundRect(Be,R,M-Be*2,Tt-R,16),e.fillStyle=I(o.ink,.72),e.fill(),e.globalCompositeOperation="source-over",e.strokeStyle=o.chipBorder,e.lineWidth=1,e.stroke();const He=`700 ${Me(Math.min(14,d*.24))}px ${o.num}`,je=Math.min(13,d*.22);e.font=He,e.textAlign="center";for(let w=0;w<m&&l.open;w++){const Q=(Be+xe)/2,V=U(w);e.strokeStyle=e.fillStyle=ct(w),e.lineWidth=1.8,e.beginPath(),e.arc(Q,V,je,0,Math.PI*2),e.stroke(),e.fillText($i(l.open[w]),Q,V+Jt(e,He,"E").middle)}}export{Ui as HEADSTOCKS,Zi as bendAt,ho as drawHighway,fo as drawTab,Yi as headstockParts,Ri as lookAhead,no as moveCamera,ai as rounded,ri as spline};