vextab 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/runtime/auto.mjs +1 -1
- package/dist/runtime/browser.mjs +1 -1
- package/dist/runtime/parse.mjs +1 -1
- package/dist/runtime/resolve.mjs +1 -0
- package/dist/runtime/shared/OKFI2OP5.mjs +1 -0
- package/dist/runtime/shared/OWAKZY4J.mjs +352 -0
- package/dist/runtime/shared/SGMFW7I5.mjs +2 -0
- package/dist/runtime/shared/TH2FBVEP.mjs +20 -0
- package/dist/runtime/types/browser.d.ts +2 -0
- package/dist/runtime/types/playback/decorations.d.ts +1 -1
- package/dist/runtime/types/score/commands.d.ts +1 -1
- package/dist/runtime/types/score/drums.d.ts +1 -1
- package/dist/runtime/types/score/layout-map.d.ts +61 -0
- package/dist/runtime/types/score/layout.d.ts +4 -0
- package/dist/runtime/types/score/model.d.ts +2 -0
- package/dist/runtime/types/score/music.d.ts +1 -1
- package/dist/runtime/types/score/resolve.d.ts +7 -0
- package/dist/runtime/vextab.js +10 -10
- package/package.json +5 -1
- package/dist/runtime/shared/PRHM4TS2.mjs +0 -21
- package/dist/runtime/shared/TVARZYJR.mjs +0 -352
package/dist/runtime/vextab.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var vextab=(()=>{var di=Object.create;var Zt=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var mi=Object.getPrototypeOf,hi=Object.prototype.hasOwnProperty;var Ln=(o,e)=>()=>{try{return e||o((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},kr=(o,e)=>{for(var n in e)Zt(o,n,{get:e[n],enumerable:!0})},Sr=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pi(e))!hi.call(o,s)&&s!==n&&Zt(o,s,{get:()=>e[s],enumerable:!(t=fi(e,s))||t.enumerable});return o};var Ee=(o,e,n)=>(n=o!=null?di(mi(o)):{},Sr(e||!o||!o.__esModule?Zt(n,"default",{value:o,enumerable:!0}):n,o)),gi=o=>Sr(Zt({},"__esModule",{value:!0}),o);var Qt=Ln((Er,Tr)=>{(function(o,e){typeof define=="function"&&define.amd?define(function(){return e(o)}):e(o)})(Er,function(){var o=(function(){var e,n,t,s,r=[],a=r.concat,i=r.filter,l=r.slice,c=window.document,u={},f={},p={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},h=/^\s*<(\w+|!)[^>]*>/,E=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,S=/^(?:body|html)$/i,P=/([A-Z])/g,B=["val","css","html","text","data","width","height","offset"],j=["after","prepend","before","append"],A=c.createElement("table"),T=c.createElement("tr"),V={tr:c.createElement("tbody"),tbody:A,thead:A,tfoot:A,td:T,th:T,"*":c.createElement("div")},U=/complete|loaded|interactive/,Y=/^[\w-]*$/,G={},R=G.toString,M={},q,v,_=c.createElement("div"),O={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},W=Array.isArray||function(d){return d instanceof Array};M.matches=function(d,m){if(!m||!d||d.nodeType!==1)return!1;var w=d.matches||d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.matchesSelector;if(w)return w.call(d,m);var N,z=d.parentNode,ie=!z;return ie&&(z=_).appendChild(d),N=~M.qsa(z,m).indexOf(d),ie&&_.removeChild(d),N};function J(d){return d==null?String(d):G[R.call(d)]||"object"}function ae(d){return J(d)=="function"}function L(d){return d!=null&&d==d.window}function X(d){return d!=null&&d.nodeType==d.DOCUMENT_NODE}function se(d){return J(d)=="object"}function ee(d){return se(d)&&!L(d)&&Object.getPrototypeOf(d)==Object.prototype}function Q(d){var m=!!d&&"length"in d&&d.length,w=t.type(d);return w!="function"&&!L(d)&&(w=="array"||m===0||typeof m=="number"&&m>0&&m-1 in d)}function te(d){return i.call(d,function(m){return m!=null})}function de(d){return d.length>0?t.fn.concat.apply([],d):d}q=function(d){return d.replace(/-+(.)?/g,function(m,w){return w?w.toUpperCase():""})};function pe(d){return d.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}v=function(d){return i.call(d,function(m,w){return d.indexOf(m)==w})};function C(d){return d in f?f[d]:f[d]=new RegExp("(^|\\s)"+d+"(\\s|$)")}function K(d,m){return typeof m=="number"&&!p[pe(d)]?m+"px":m}function ne(d){var m,w;return u[d]||(m=c.createElement(d),c.body.appendChild(m),w=getComputedStyle(m,"").getPropertyValue("display"),m.parentNode.removeChild(m),w=="none"&&(w="block"),u[d]=w),u[d]}function H(d){return"children"in d?l.call(d.children):t.map(d.childNodes,function(m){if(m.nodeType==1)return m})}function re(d,m){var w,N=d?d.length:0;for(w=0;w<N;w++)this[w]=d[w];this.length=N,this.selector=m||""}M.fragment=function(d,m,w){var N,z,ie;return E.test(d)&&(N=t(c.createElement(RegExp.$1))),N||(d.replace&&(d=d.replace(k,"<$1></$2>")),m===e&&(m=h.test(d)&&RegExp.$1),m in V||(m="*"),ie=V[m],ie.innerHTML=""+d,N=t.each(l.call(ie.childNodes),function(){ie.removeChild(this)})),ee(w)&&(z=t(N),t.each(w,function(ue,le){B.indexOf(ue)>-1?z[ue](le):z.attr(ue,le)})),N},M.Z=function(d,m){return new re(d,m)},M.isZ=function(d){return d instanceof M.Z},M.init=function(d,m){var w;if(d)if(typeof d=="string")if(d=d.trim(),d[0]=="<"&&h.test(d))w=M.fragment(d,RegExp.$1,m),d=null;else{if(m!==e)return t(m).find(d);w=M.qsa(c,d)}else{if(ae(d))return t(c).ready(d);if(M.isZ(d))return d;if(W(d))w=te(d);else if(se(d))w=[d],d=null;else if(h.test(d))w=M.fragment(d.trim(),RegExp.$1,m),d=null;else{if(m!==e)return t(m).find(d);w=M.qsa(c,d)}}else return M.Z();return M.Z(w,d)},t=function(d,m){return M.init(d,m)};function F(d,m,w){for(n in m)w&&(ee(m[n])||W(m[n]))?(ee(m[n])&&!ee(d[n])&&(d[n]={}),W(m[n])&&!W(d[n])&&(d[n]=[]),F(d[n],m[n],w)):m[n]!==e&&(d[n]=m[n])}t.extend=function(d){var m,w=l.call(arguments,1);return typeof d=="boolean"&&(m=d,d=w.shift()),w.forEach(function(N){F(d,N,m)}),d},M.qsa=function(d,m){var w,N=m[0]=="#",z=!N&&m[0]==".",ie=N||z?m.slice(1):m,ue=Y.test(ie);return d.getElementById&&ue&&N?(w=d.getElementById(ie))?[w]:[]:d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11?[]:l.call(ue&&!N&&d.getElementsByClassName?z?d.getElementsByClassName(ie):d.getElementsByTagName(m):d.querySelectorAll(m))};function b(d,m){return m==null?t(d):t(d).filter(m)}t.contains=c.documentElement.contains?function(d,m){return d!==m&&d.contains(m)}:function(d,m){for(;m&&(m=m.parentNode);)if(m===d)return!0;return!1};function g(d,m,w,N){return ae(m)?m.call(d,w,N):m}function y(d,m,w){w==null?d.removeAttribute(m):d.setAttribute(m,w)}function I(d,m){var w=d.className||"",N=w&&w.baseVal!==e;if(m===e)return N?w.baseVal:w;N?w.baseVal=m:d.className=m}function D(d){try{return d&&(d=="true"||(d=="false"?!1:d=="null"?null:+d+""==d?+d:/^[\[\{]/.test(d)?t.parseJSON(d):d))}catch{return d}}t.type=J,t.isFunction=ae,t.isWindow=L,t.isArray=W,t.isPlainObject=ee,t.isEmptyObject=function(d){var m;for(m in d)return!1;return!0},t.isNumeric=function(d){var m=Number(d),w=typeof d;return d!=null&&w!="boolean"&&(w!="string"||d.length)&&!isNaN(m)&&isFinite(m)||!1},t.inArray=function(d,m,w){return r.indexOf.call(m,d,w)},t.camelCase=q,t.trim=function(d){return d==null?"":String.prototype.trim.call(d)},t.uuid=0,t.support={},t.expr={},t.noop=function(){},t.map=function(d,m){var w,N=[],z,ie;if(Q(d))for(z=0;z<d.length;z++)w=m(d[z],z),w!=null&&N.push(w);else for(ie in d)w=m(d[ie],ie),w!=null&&N.push(w);return de(N)},t.each=function(d,m){var w,N;if(Q(d)){for(w=0;w<d.length;w++)if(m.call(d[w],w,d[w])===!1)return d}else for(N in d)if(m.call(d[N],N,d[N])===!1)return d;return d},t.grep=function(d,m){return i.call(d,m)},window.JSON&&(t.parseJSON=JSON.parse),t.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(d,m){G["[object "+m+"]"]=m.toLowerCase()}),t.fn={constructor:M.Z,length:0,forEach:r.forEach,reduce:r.reduce,push:r.push,sort:r.sort,splice:r.splice,indexOf:r.indexOf,concat:function(){var d,m,w=[];for(d=0;d<arguments.length;d++)m=arguments[d],w[d]=M.isZ(m)?m.toArray():m;return a.apply(M.isZ(this)?this.toArray():this,w)},map:function(d){return t(t.map(this,function(m,w){return d.call(m,w,m)}))},slice:function(){return t(l.apply(this,arguments))},ready:function(d){return U.test(c.readyState)&&c.body?d(t):c.addEventListener("DOMContentLoaded",function(){d(t)},!1),this},get:function(d){return d===e?l.call(this):this[d>=0?d:d+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode!=null&&this.parentNode.removeChild(this)})},each:function(d){return r.every.call(this,function(m,w){return d.call(m,w,m)!==!1}),this},filter:function(d){return ae(d)?this.not(this.not(d)):t(i.call(this,function(m){return M.matches(m,d)}))},add:function(d,m){return t(v(this.concat(t(d,m))))},is:function(d){return this.length>0&&M.matches(this[0],d)},not:function(d){var m=[];if(ae(d)&&d.call!==e)this.each(function(N){d.call(this,N)||m.push(this)});else{var w=typeof d=="string"?this.filter(d):Q(d)&&ae(d.item)?l.call(d):t(d);this.forEach(function(N){w.indexOf(N)<0&&m.push(N)})}return t(m)},has:function(d){return this.filter(function(){return se(d)?t.contains(this,d):t(this).find(d).size()})},eq:function(d){return d===-1?this.slice(d):this.slice(d,+d+1)},first:function(){var d=this[0];return d&&!se(d)?d:t(d)},last:function(){var d=this[this.length-1];return d&&!se(d)?d:t(d)},find:function(d){var m,w=this;return d?typeof d=="object"?m=t(d).filter(function(){var N=this;return r.some.call(w,function(z){return t.contains(z,N)})}):this.length==1?m=t(M.qsa(this[0],d)):m=this.map(function(){return M.qsa(this,d)}):m=t(),m},closest:function(d,m){var w=[],N=typeof d=="object"&&t(d);return this.each(function(z,ie){for(;ie&&!(N?N.indexOf(ie)>=0:M.matches(ie,d));)ie=ie!==m&&!X(ie)&&ie.parentNode;ie&&w.indexOf(ie)<0&&w.push(ie)}),t(w)},parents:function(d){for(var m=[],w=this;w.length>0;)w=t.map(w,function(N){if((N=N.parentNode)&&!X(N)&&m.indexOf(N)<0)return m.push(N),N});return b(m,d)},parent:function(d){return b(v(this.pluck("parentNode")),d)},children:function(d){return b(this.map(function(){return H(this)}),d)},contents:function(){return this.map(function(){return this.contentDocument||l.call(this.childNodes)})},siblings:function(d){return b(this.map(function(m,w){return i.call(H(w.parentNode),function(N){return N!==w})}),d)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(d){return t.map(this,function(m){return m[d]})},show:function(){return this.each(function(){this.style.display=="none"&&(this.style.display=""),getComputedStyle(this,"").getPropertyValue("display")=="none"&&(this.style.display=ne(this.nodeName))})},replaceWith:function(d){return this.before(d).remove()},wrap:function(d){var m=ae(d);if(this[0]&&!m)var w=t(d).get(0),N=w.parentNode||this.length>1;return this.each(function(z){t(this).wrapAll(m?d.call(this,z):N?w.cloneNode(!0):w)})},wrapAll:function(d){if(this[0]){t(this[0]).before(d=t(d));for(var m;(m=d.children()).length;)d=m.first();t(d).append(this)}return this},wrapInner:function(d){var m=ae(d);return this.each(function(w){var N=t(this),z=N.contents(),ie=m?d.call(this,w):d;z.length?z.wrapAll(ie):N.append(ie)})},unwrap:function(){return this.parent().each(function(){t(this).replaceWith(t(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(d){return this.each(function(){var m=t(this);(d===e?m.css("display")=="none":d)?m.show():m.hide()})},prev:function(d){return t(this.pluck("previousElementSibling")).filter(d||"*")},next:function(d){return t(this.pluck("nextElementSibling")).filter(d||"*")},html:function(d){return 0 in arguments?this.each(function(m){var w=this.innerHTML;t(this).empty().append(g(this,d,m,w))}):0 in this?this[0].innerHTML:null},text:function(d){return 0 in arguments?this.each(function(m){var w=g(this,d,m,this.textContent);this.textContent=w==null?"":""+w}):0 in this?this.pluck("textContent").join(""):null},attr:function(d,m){var w;return typeof d=="string"&&!(1 in arguments)?0 in this&&this[0].nodeType==1&&(w=this[0].getAttribute(d))!=null?w:e:this.each(function(N){if(this.nodeType===1)if(se(d))for(n in d)y(this,n,d[n]);else y(this,d,g(this,m,N,this.getAttribute(d)))})},removeAttr:function(d){return this.each(function(){this.nodeType===1&&d.split(" ").forEach(function(m){y(this,m)},this)})},prop:function(d,m){return d=O[d]||d,1 in arguments?this.each(function(w){this[d]=g(this,m,w,this[d])}):this[0]&&this[0][d]},removeProp:function(d){return d=O[d]||d,this.each(function(){delete this[d]})},data:function(d,m){var w="data-"+d.replace(P,"-$1").toLowerCase(),N=1 in arguments?this.attr(w,m):this.attr(w);return N!==null?D(N):e},val:function(d){return 0 in arguments?(d==null&&(d=""),this.each(function(m){this.value=g(this,d,m,this.value)})):this[0]&&(this[0].multiple?t(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value)},offset:function(d){if(d)return this.each(function(w){var N=t(this),z=g(this,d,w,N.offset()),ie=N.offsetParent().offset(),ue={top:z.top-ie.top,left:z.left-ie.left};N.css("position")=="static"&&(ue.position="relative"),N.css(ue)});if(!this.length)return null;if(c.documentElement!==this[0]&&!t.contains(c.documentElement,this[0]))return{top:0,left:0};var m=this[0].getBoundingClientRect();return{left:m.left+window.pageXOffset,top:m.top+window.pageYOffset,width:Math.round(m.width),height:Math.round(m.height)}},css:function(d,m){if(arguments.length<2){var w=this[0];if(typeof d=="string")return w?w.style[q(d)]||getComputedStyle(w,"").getPropertyValue(d):void 0;if(W(d)){if(!w)return;var N={},z=getComputedStyle(w,"");return t.each(d,function(ue,le){N[le]=w.style[q(le)]||z.getPropertyValue(le)}),N}}var ie="";if(J(d)=="string")!m&&m!==0?this.each(function(){this.style.removeProperty(pe(d))}):ie=pe(d)+":"+K(d,m);else for(n in d)!d[n]&&d[n]!==0?this.each(function(){this.style.removeProperty(pe(n))}):ie+=pe(n)+":"+K(n,d[n])+";";return this.each(function(){this.style.cssText+=";"+ie})},index:function(d){return d?this.indexOf(t(d)[0]):this.parent().children().indexOf(this[0])},hasClass:function(d){return d?r.some.call(this,function(m){return this.test(I(m))},C(d)):!1},addClass:function(d){return d?this.each(function(m){if("className"in this){s=[];var w=I(this),N=g(this,d,m,w);N.split(/\s+/g).forEach(function(z){t(this).hasClass(z)||s.push(z)},this),s.length&&I(this,w+(w?" ":"")+s.join(" "))}}):this},removeClass:function(d){return this.each(function(m){if("className"in this){if(d===e)return I(this,"");s=I(this),g(this,d,m,s).split(/\s+/g).forEach(function(w){s=s.replace(C(w)," ")}),I(this,s.trim())}})},toggleClass:function(d,m){return d?this.each(function(w){var N=t(this),z=g(this,d,w,I(this));z.split(/\s+/g).forEach(function(ie){(m===e?!N.hasClass(ie):m)?N.addClass(ie):N.removeClass(ie)})}):this},scrollTop:function(d){if(this.length){var m="scrollTop"in this[0];return d===e?m?this[0].scrollTop:this[0].pageYOffset:this.each(m?function(){this.scrollTop=d}:function(){this.scrollTo(this.scrollX,d)})}},scrollLeft:function(d){if(this.length){var m="scrollLeft"in this[0];return d===e?m?this[0].scrollLeft:this[0].pageXOffset:this.each(m?function(){this.scrollLeft=d}:function(){this.scrollTo(d,this.scrollY)})}},position:function(){if(this.length){var d=this[0],m=this.offsetParent(),w=this.offset(),N=S.test(m[0].nodeName)?{top:0,left:0}:m.offset();return w.top-=parseFloat(t(d).css("margin-top"))||0,w.left-=parseFloat(t(d).css("margin-left"))||0,N.top+=parseFloat(t(m[0]).css("border-top-width"))||0,N.left+=parseFloat(t(m[0]).css("border-left-width"))||0,{top:w.top-N.top,left:w.left-N.left}}},offsetParent:function(){return this.map(function(){for(var d=this.offsetParent||c.body;d&&!S.test(d.nodeName)&&t(d).css("position")=="static";)d=d.offsetParent;return d})}},t.fn.detach=t.fn.remove,["width","height"].forEach(function(d){var m=d.replace(/./,function(w){return w[0].toUpperCase()});t.fn[d]=function(w){var N,z=this[0];return w===e?L(z)?z["inner"+m]:X(z)?z.documentElement["scroll"+m]:(N=this.offset())&&N[d]:this.each(function(ie){z=t(this),z.css(d,g(this,w,ie,z[d]()))})}});function x(d,m){m(d);for(var w=0,N=d.childNodes.length;w<N;w++)x(d.childNodes[w],m)}return j.forEach(function(d,m){var w=m%2;t.fn[d]=function(){var N,z=t.map(arguments,function(le){var me=[];return N=J(le),N=="array"?(le.forEach(function(ye){if(ye.nodeType!==e)return me.push(ye);if(t.zepto.isZ(ye))return me=me.concat(ye.get());me=me.concat(M.fragment(ye))}),me):N=="object"||le==null?le:M.fragment(le)}),ie,ue=this.length>1;return z.length<1?this:this.each(function(le,me){ie=w?me:me.parentNode,me=m==0?me.nextSibling:m==1?me.firstChild:m==2?me:null;var ye=t.contains(c.documentElement,ie);z.forEach(function(ve){if(ue)ve=ve.cloneNode(!0);else if(!ie)return t(ve).remove();ie.insertBefore(ve,me),ye&&x(ve,function(Me){if(Me.nodeName!=null&&Me.nodeName.toUpperCase()==="SCRIPT"&&(!Me.type||Me.type==="text/javascript")&&!Me.src){var Le=Me.ownerDocument?Me.ownerDocument.defaultView:window;Le.eval.call(Le,Me.innerHTML)}})})})},t.fn[w?d+"To":"insert"+(m?"Before":"After")]=function(N){return t(N)[d](this),this}}),M.Z.prototype=re.prototype=t.fn,M.uniq=v,M.deserializeValue=D,t.zepto=M,t})();return window.Zepto=o,window.$===void 0&&(window.$=o),Tr.exports=o,(function(e){var n=1,t,s=Array.prototype.slice,r=e.isFunction,a=function(R){return typeof R=="string"},i={},l={},c="onfocusin"in window,u={focus:"focusin",blur:"focusout"},f={mouseenter:"mouseover",mouseleave:"mouseout"};l.click=l.mousedown=l.mouseup=l.mousemove="MouseEvents";function p(R){return R._zid||(R._zid=n++)}function h(R,M,q,v){if(M=E(M),M.ns)var _=k(M.ns);return(i[p(R)]||[]).filter(function(O){return O&&(!M.e||O.e==M.e)&&(!M.ns||_.test(O.ns))&&(!q||p(O.fn)===p(q))&&(!v||O.sel==v)})}function E(R){var M=(""+R).split(".");return{e:M[0],ns:M.slice(1).sort().join(" ")}}function k(R){return new RegExp("(?:^| )"+R.replace(" "," .* ?")+"(?: |$)")}function S(R,M){return R.del&&!c&&R.e in u||!!M}function P(R){return f[R]||c&&u[R]||R}function B(R,M,q,v,_,O,W){var J=p(R),ae=i[J]||(i[J]=[]);M.split(/\s/).forEach(function(L){if(L=="ready")return e(document).ready(q);var X=E(L);X.fn=q,X.sel=_,X.e in f&&(q=function(ee){var Q=ee.relatedTarget;if(!Q||Q!==this&&!e.contains(this,Q))return X.fn.apply(this,arguments)}),X.del=O;var se=O||q;X.proxy=function(ee){if(ee=Y(ee),!ee.isImmediatePropagationStopped()){ee.data=v;var Q=se.apply(R,ee._args==t?[ee]:[ee].concat(ee._args));return Q===!1&&(ee.preventDefault(),ee.stopPropagation()),Q}},X.i=ae.length,ae.push(X),"addEventListener"in R&&R.addEventListener(P(X.e),X.proxy,S(X,W))})}function j(R,M,q,v,_){var O=p(R);(M||"").split(/\s/).forEach(function(W){h(R,W,q,v).forEach(function(J){delete i[O][J.i],"removeEventListener"in R&&R.removeEventListener(P(J.e),J.proxy,S(J,_))})})}e.event={add:B,remove:j},e.proxy=function(R,M){var q=2 in arguments&&s.call(arguments,2);if(r(R)){var v=function(){return R.apply(M,q?q.concat(s.call(arguments)):arguments)};return v._zid=p(R),v}else{if(a(M))return q?(q.unshift(R[M],R),e.proxy.apply(null,q)):e.proxy(R[M],R);throw new TypeError("expected function")}},e.fn.bind=function(R,M,q){return this.on(R,M,q)},e.fn.unbind=function(R,M){return this.off(R,M)},e.fn.one=function(R,M,q,v){return this.on(R,M,q,v,1)};var A=function(){return!0},T=function(){return!1},V=/^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/,U={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};function Y(R,M){return(M||!R.isDefaultPrevented)&&(M||(M=R),e.each(U,function(q,v){var _=M[q];R[q]=function(){return this[v]=A,_&&_.apply(M,arguments)},R[v]=T}),R.timeStamp||(R.timeStamp=Date.now()),(M.defaultPrevented!==t?M.defaultPrevented:"returnValue"in M?M.returnValue===!1:M.getPreventDefault&&M.getPreventDefault())&&(R.isDefaultPrevented=A)),R}function G(R){var M,q={originalEvent:R};for(M in R)!V.test(M)&&R[M]!==t&&(q[M]=R[M]);return Y(q,R)}e.fn.delegate=function(R,M,q){return this.on(M,R,q)},e.fn.undelegate=function(R,M,q){return this.off(M,R,q)},e.fn.live=function(R,M){return e(document.body).delegate(this.selector,R,M),this},e.fn.die=function(R,M){return e(document.body).undelegate(this.selector,R,M),this},e.fn.on=function(R,M,q,v,_){var O,W,J=this;return R&&!a(R)?(e.each(R,function(ae,L){J.on(ae,M,q,L,_)}),J):(!a(M)&&!r(v)&&v!==!1&&(v=q,q=M,M=t),(v===t||q===!1)&&(v=q,q=t),v===!1&&(v=T),J.each(function(ae,L){_&&(O=function(X){return j(L,X.type,v),v.apply(this,arguments)}),M&&(W=function(X){var se,ee=e(X.target).closest(M,L).get(0);if(ee&&ee!==L)return se=e.extend(G(X),{currentTarget:ee,liveFired:L}),(O||v).apply(ee,[se].concat(s.call(arguments,1)))}),B(L,R,v,q,M,W||O)}))},e.fn.off=function(R,M,q){var v=this;return R&&!a(R)?(e.each(R,function(_,O){v.off(_,M,O)}),v):(!a(M)&&!r(q)&&q!==!1&&(q=M,M=t),q===!1&&(q=T),v.each(function(){j(this,R,q,M)}))},e.fn.trigger=function(R,M){return R=a(R)||e.isPlainObject(R)?e.Event(R):Y(R),R._args=M,this.each(function(){R.type in u&&typeof this[R.type]=="function"?this[R.type]():"dispatchEvent"in this?this.dispatchEvent(R):e(this).triggerHandler(R,M)})},e.fn.triggerHandler=function(R,M){var q,v;return this.each(function(_,O){q=G(a(R)?e.Event(R):R),q._args=M,q.target=O,e.each(h(O,R.type||R),function(W,J){if(v=J.proxy(q),q.isImmediatePropagationStopped())return!1})}),v},"focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(R){e.fn[R]=function(M){return 0 in arguments?this.bind(R,M):this.trigger(R)}}),e.Event=function(R,M){a(R)||(M=R,R=M.type);var q=document.createEvent(l[R]||"Events"),v=!0;if(M)for(var _ in M)_=="bubbles"?v=!!M[_]:q[_]=M[_];return q.initEvent(R,v,!0),Y(q)}})(o),(function(e){var n=+new Date,t=window.document,s,r,a=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,i=/^(?:text|application)\/javascript/i,l=/^(?:text|application)\/xml/i,c="application/json",u="text/html",f=/^\s*$/,p=t.createElement("a");p.href=window.location.href;function h(v,_,O){var W=e.Event(_);return e(v).trigger(W,O),!W.isDefaultPrevented()}function E(v,_,O,W){if(v.global)return h(_||t,O,W)}e.active=0;function k(v){v.global&&e.active++===0&&E(v,null,"ajaxStart")}function S(v){v.global&&!--e.active&&E(v,null,"ajaxStop")}function P(v,_){var O=_.context;if(_.beforeSend.call(O,v,_)===!1||E(_,O,"ajaxBeforeSend",[v,_])===!1)return!1;E(_,O,"ajaxSend",[v,_])}function B(v,_,O,W){var J=O.context,ae="success";O.success.call(J,v,ae,_),W&&W.resolveWith(J,[v,ae,_]),E(O,J,"ajaxSuccess",[_,O,v]),A(ae,_,O)}function j(v,_,O,W,J){var ae=W.context;W.error.call(ae,O,_,v),J&&J.rejectWith(ae,[O,_,v]),E(W,ae,"ajaxError",[O,W,v||_]),A(_,O,W)}function A(v,_,O){var W=O.context;O.complete.call(W,_,v),E(O,W,"ajaxComplete",[_,O]),S(O)}function T(v,_,O){if(O.dataFilter==V)return v;var W=O.context;return O.dataFilter.call(W,v,_)}function V(){}e.ajaxJSONP=function(v,_){if(!("type"in v))return e.ajax(v);var O=v.jsonpCallback,W=(e.isFunction(O)?O():O)||"Zepto"+n++,J=t.createElement("script"),ae=window[W],L,X=function(Q){e(J).triggerHandler("error",Q||"abort")},se={abort:X},ee;return _&&_.promise(se),e(J).on("load error",function(Q,te){clearTimeout(ee),e(J).off().remove(),Q.type=="error"||!L?j(null,te||"error",se,v,_):B(L[0],se,v,_),window[W]=ae,L&&e.isFunction(ae)&&ae(L[0]),ae=L=void 0}),P(se,v)===!1?(X("abort"),se):(window[W]=function(){L=arguments},J.src=v.url.replace(/\?(.+)=\?/,"?$1="+W),t.head.appendChild(J),v.timeout>0&&(ee=setTimeout(function(){X("timeout")},v.timeout)),se)},e.ajaxSettings={type:"GET",beforeSend:V,success:V,error:V,complete:V,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:c,xml:"application/xml, text/xml",html:u,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0,dataFilter:V};function U(v){return v&&(v=v.split(";",2)[0]),v&&(v==u?"html":v==c?"json":i.test(v)?"script":l.test(v)&&"xml")||"text"}function Y(v,_){return _==""?v:(v+"&"+_).replace(/[&?]{1,2}/,"?")}function G(v){v.processData&&v.data&&e.type(v.data)!="string"&&(v.data=e.param(v.data,v.traditional)),v.data&&(!v.type||v.type.toUpperCase()=="GET"||v.dataType=="jsonp")&&(v.url=Y(v.url,v.data),v.data=void 0)}e.ajax=function(v){var _=e.extend({},v||{}),O=e.Deferred&&e.Deferred(),W,J;for(s in e.ajaxSettings)_[s]===void 0&&(_[s]=e.ajaxSettings[s]);k(_),_.crossDomain||(W=t.createElement("a"),W.href=_.url,W.href=W.href,_.crossDomain=p.protocol+"//"+p.host!=W.protocol+"//"+W.host),_.url||(_.url=window.location.toString()),(J=_.url.indexOf("#"))>-1&&(_.url=_.url.slice(0,J)),G(_);var ae=_.dataType,L=/\?.+=\?/.test(_.url);if(L&&(ae="jsonp"),(_.cache===!1||(!v||v.cache!==!0)&&(ae=="script"||ae=="jsonp"))&&(_.url=Y(_.url,"_="+Date.now())),ae=="jsonp")return L||(_.url=Y(_.url,_.jsonp?_.jsonp+"=?":_.jsonp===!1?"":"callback=?")),e.ajaxJSONP(_,O);var X=_.accepts[ae],se={},ee=function(K,ne){se[K.toLowerCase()]=[K,ne]},Q=/^([\w-]+:)\/\//.test(_.url)?RegExp.$1:window.location.protocol,te=_.xhr(),de=te.setRequestHeader,pe;if(O&&O.promise(te),_.crossDomain||ee("X-Requested-With","XMLHttpRequest"),ee("Accept",X||"*/*"),(X=_.mimeType||X)&&(X.indexOf(",")>-1&&(X=X.split(",",2)[0]),te.overrideMimeType&&te.overrideMimeType(X)),(_.contentType||_.contentType!==!1&&_.data&&_.type.toUpperCase()!="GET")&&ee("Content-Type",_.contentType||"application/x-www-form-urlencoded"),_.headers)for(r in _.headers)ee(r,_.headers[r]);if(te.setRequestHeader=ee,te.onreadystatechange=function(){if(te.readyState==4){te.onreadystatechange=V,clearTimeout(pe);var K,ne=!1;if(te.status>=200&&te.status<300||te.status==304||te.status==0&&Q=="file:"){if(ae=ae||U(_.mimeType||te.getResponseHeader("content-type")),te.responseType=="arraybuffer"||te.responseType=="blob")K=te.response;else{K=te.responseText;try{K=T(K,ae,_),ae=="script"?(0,eval)(K):ae=="xml"?K=te.responseXML:ae=="json"&&(K=f.test(K)?null:e.parseJSON(K))}catch(H){ne=H}if(ne)return j(ne,"parsererror",te,_,O)}B(K,te,_,O)}else j(te.statusText||null,te.status?"error":"abort",te,_,O)}},P(te,_)===!1)return te.abort(),j(null,"abort",te,_,O),te;var C="async"in _?_.async:!0;if(te.open(_.type,_.url,C,_.username,_.password),_.xhrFields)for(r in _.xhrFields)te[r]=_.xhrFields[r];for(r in se)de.apply(te,se[r]);return _.timeout>0&&(pe=setTimeout(function(){te.onreadystatechange=V,te.abort(),j(null,"timeout",te,_,O)},_.timeout)),te.send(_.data?_.data:null),te};function R(v,_,O,W){return e.isFunction(_)&&(W=O,O=_,_=void 0),e.isFunction(O)||(W=O,O=void 0),{url:v,data:_,success:O,dataType:W}}e.get=function(){return e.ajax(R.apply(null,arguments))},e.post=function(){var v=R.apply(null,arguments);return v.type="POST",e.ajax(v)},e.getJSON=function(){var v=R.apply(null,arguments);return v.dataType="json",e.ajax(v)},e.fn.load=function(v,_,O){if(!this.length)return this;var W=this,J=v.split(/\s/),ae,L=R(v,_,O),X=L.success;return J.length>1&&(L.url=J[0],ae=J[1]),L.success=function(se){W.html(ae?e("<div>").html(se.replace(a,"")).find(ae):se),X&&X.apply(W,arguments)},e.ajax(L),this};var M=encodeURIComponent;function q(v,_,O,W){var J,ae=e.isArray(_),L=e.isPlainObject(_);e.each(_,function(X,se){J=e.type(se),W&&(X=O?W:W+"["+(L||J=="object"||J=="array"?X:"")+"]"),!W&&ae?v.add(se.name,se.value):J=="array"||!O&&J=="object"?q(v,se,O,X):v.add(X,se)})}e.param=function(v,_){var O=[];return O.add=function(W,J){e.isFunction(J)&&(J=J()),J==null&&(J=""),this.push(M(W)+"="+M(J))},q(O,v,_),O.join("&").replace(/%20/g,"+")}})(o),(function(e){e.fn.serializeArray=function(){var n,t,s=[],r=function(a){if(a.forEach)return a.forEach(r);s.push({name:n,value:a})};return this[0]&&e.each(this[0].elements,function(a,i){t=i.type,n=i.name,n&&i.nodeName.toLowerCase()!="fieldset"&&!i.disabled&&t!="submit"&&t!="reset"&&t!="button"&&t!="file"&&(t!="radio"&&t!="checkbox"||i.checked)&&r(e(i).val())}),s},e.fn.serialize=function(){var n=[];return this.serializeArray().forEach(function(t){n.push(encodeURIComponent(t.name)+"="+encodeURIComponent(t.value))}),n.join("&")},e.fn.submit=function(n){if(0 in arguments)this.bind("submit",n);else if(this.length){var t=e.Event("submit");this.eq(0).trigger(t),t.isDefaultPrevented()||this.get(0).submit()}return this}})(o),(function(){try{getComputedStyle(void 0)}catch{var e=getComputedStyle;window.getComputedStyle=function(t,s){try{return e(t,s)}catch{return null}}}})(),o})});var Pe=Ln((Fo,Mr)=>{if(!window.VexFlow)throw new Error("Load vexflow.js before vextab.js.");Mr.exports=window.VexFlow});var li=Ln(()=>{var ci=document.createElement("style");ci.textContent=`/* Score and editor styles for the browser embed. */
|
|
1
|
+
var vextab=(()=>{var vi=Object.create;var en=Object.defineProperty;var wi=Object.getOwnPropertyDescriptor;var ki=Object.getOwnPropertyNames;var Si=Object.getPrototypeOf,Ei=Object.prototype.hasOwnProperty;var zn=(o,e)=>()=>{try{return e||o((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},Tr=(o,e)=>{for(var n in e)en(o,n,{get:e[n],enumerable:!0})},Pr=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ki(e))!Ei.call(o,s)&&s!==n&&en(o,s,{get:()=>e[s],enumerable:!(t=wi(e,s))||t.enumerable});return o};var Ee=(o,e,n)=>(n=o!=null?vi(Si(o)):{},Pr(e||!o||!o.__esModule?en(n,"default",{value:o,enumerable:!0}):n,o)),Mi=o=>Pr(en({},"__esModule",{value:!0}),o);var tn=zn((Nr,_r)=>{(function(o,e){typeof define=="function"&&define.amd?define(function(){return e(o)}):e(o)})(Nr,function(){var o=(function(){var e,n,t,s,r=[],a=r.concat,i=r.filter,c=r.slice,l=window.document,u={},f={},m={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},h=/^\s*<(\w+|!)[^>]*>/,w=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,x=/^(?:body|html)$/i,P=/([A-Z])/g,B=["val","css","html","text","data","width","height","offset"],D=["after","prepend","before","append"],_=l.createElement("table"),M=l.createElement("tr"),V={tr:l.createElement("tbody"),tbody:_,thead:_,tfoot:_,td:M,th:M,"*":l.createElement("div")},K=/complete|loaded|interactive/,Y=/^[\w-]*$/,W={},C=W.toString,T={},X,S,N=l.createElement("div"),L={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},q=Array.isArray||function(d){return d instanceof Array};T.matches=function(d,p){if(!p||!d||d.nodeType!==1)return!1;var E=d.matches||d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.matchesSelector;if(E)return E.call(d,p);var R,j=d.parentNode,te=!j;return te&&(j=N).appendChild(d),R=~T.qsa(j,p).indexOf(d),te&&N.removeChild(d),R};function Q(d){return d==null?String(d):W[C.call(d)]||"object"}function re(d){return Q(d)=="function"}function se(d){return d!=null&&d==d.window}function ie(d){return d!=null&&d.nodeType==d.DOCUMENT_NODE}function ce(d){return Q(d)=="object"}function ae(d){return ce(d)&&!se(d)&&Object.getPrototypeOf(d)==Object.prototype}function O(d){var p=!!d&&"length"in d&&d.length,E=t.type(d);return E!="function"&&!se(d)&&(E=="array"||p===0||typeof p=="number"&&p>0&&p-1 in d)}function G(d){return i.call(d,function(p){return p!=null})}function ue(d){return d.length>0?t.fn.concat.apply([],d):d}X=function(d){return d.replace(/-+(.)?/g,function(p,E){return E?E.toUpperCase():""})};function le(d){return d.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}S=function(d){return i.call(d,function(p,E){return d.indexOf(p)==E})};function A(d){return d in f?f[d]:f[d]=new RegExp("(^|\\s)"+d+"(\\s|$)")}function U(d,p){return typeof p=="number"&&!m[le(d)]?p+"px":p}function $(d){var p,E;return u[d]||(p=l.createElement(d),l.body.appendChild(p),E=getComputedStyle(p,"").getPropertyValue("display"),p.parentNode.removeChild(p),E=="none"&&(E="block"),u[d]=E),u[d]}function H(d){return"children"in d?c.call(d.children):t.map(d.childNodes,function(p){if(p.nodeType==1)return p})}function ee(d,p){var E,R=d?d.length:0;for(E=0;E<R;E++)this[E]=d[E];this.length=R,this.selector=p||""}T.fragment=function(d,p,E){var R,j,te;return w.test(d)&&(R=t(l.createElement(RegExp.$1))),R||(d.replace&&(d=d.replace(v,"<$1></$2>")),p===e&&(p=h.test(d)&&RegExp.$1),p in V||(p="*"),te=V[p],te.innerHTML=""+d,R=t.each(c.call(te.childNodes),function(){te.removeChild(this)})),ae(E)&&(j=t(R),t.each(E,function(fe,de){B.indexOf(fe)>-1?j[fe](de):j.attr(fe,de)})),R},T.Z=function(d,p){return new ee(d,p)},T.isZ=function(d){return d instanceof T.Z},T.init=function(d,p){var E;if(d)if(typeof d=="string")if(d=d.trim(),d[0]=="<"&&h.test(d))E=T.fragment(d,RegExp.$1,p),d=null;else{if(p!==e)return t(p).find(d);E=T.qsa(l,d)}else{if(re(d))return t(l).ready(d);if(T.isZ(d))return d;if(q(d))E=G(d);else if(ce(d))E=[d],d=null;else if(h.test(d))E=T.fragment(d.trim(),RegExp.$1,p),d=null;else{if(p!==e)return t(p).find(d);E=T.qsa(l,d)}}else return T.Z();return T.Z(E,d)},t=function(d,p){return T.init(d,p)};function F(d,p,E){for(n in p)E&&(ae(p[n])||q(p[n]))?(ae(p[n])&&!ae(d[n])&&(d[n]={}),q(p[n])&&!q(d[n])&&(d[n]=[]),F(d[n],p[n],E)):p[n]!==e&&(d[n]=p[n])}t.extend=function(d){var p,E=c.call(arguments,1);return typeof d=="boolean"&&(p=d,d=E.shift()),E.forEach(function(R){F(d,R,p)}),d},T.qsa=function(d,p){var E,R=p[0]=="#",j=!R&&p[0]==".",te=R||j?p.slice(1):p,fe=Y.test(te);return d.getElementById&&fe&&R?(E=d.getElementById(te))?[E]:[]:d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11?[]:c.call(fe&&!R&&d.getElementsByClassName?j?d.getElementsByClassName(te):d.getElementsByTagName(p):d.querySelectorAll(p))};function b(d,p){return p==null?t(d):t(d).filter(p)}t.contains=l.documentElement.contains?function(d,p){return d!==p&&d.contains(p)}:function(d,p){for(;p&&(p=p.parentNode);)if(p===d)return!0;return!1};function g(d,p,E,R){return re(p)?p.call(d,E,R):p}function y(d,p,E){E==null?d.removeAttribute(p):d.setAttribute(p,E)}function I(d,p){var E=d.className||"",R=E&&E.baseVal!==e;if(p===e)return R?E.baseVal:E;R?E.baseVal=p:d.className=p}function z(d){try{return d&&(d=="true"||(d=="false"?!1:d=="null"?null:+d+""==d?+d:/^[\[\{]/.test(d)?t.parseJSON(d):d))}catch{return d}}t.type=Q,t.isFunction=re,t.isWindow=se,t.isArray=q,t.isPlainObject=ae,t.isEmptyObject=function(d){var p;for(p in d)return!1;return!0},t.isNumeric=function(d){var p=Number(d),E=typeof d;return d!=null&&E!="boolean"&&(E!="string"||d.length)&&!isNaN(p)&&isFinite(p)||!1},t.inArray=function(d,p,E){return r.indexOf.call(p,d,E)},t.camelCase=X,t.trim=function(d){return d==null?"":String.prototype.trim.call(d)},t.uuid=0,t.support={},t.expr={},t.noop=function(){},t.map=function(d,p){var E,R=[],j,te;if(O(d))for(j=0;j<d.length;j++)E=p(d[j],j),E!=null&&R.push(E);else for(te in d)E=p(d[te],te),E!=null&&R.push(E);return ue(R)},t.each=function(d,p){var E,R;if(O(d)){for(E=0;E<d.length;E++)if(p.call(d[E],E,d[E])===!1)return d}else for(R in d)if(p.call(d[R],R,d[R])===!1)return d;return d},t.grep=function(d,p){return i.call(d,p)},window.JSON&&(t.parseJSON=JSON.parse),t.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(d,p){W["[object "+p+"]"]=p.toLowerCase()}),t.fn={constructor:T.Z,length:0,forEach:r.forEach,reduce:r.reduce,push:r.push,sort:r.sort,splice:r.splice,indexOf:r.indexOf,concat:function(){var d,p,E=[];for(d=0;d<arguments.length;d++)p=arguments[d],E[d]=T.isZ(p)?p.toArray():p;return a.apply(T.isZ(this)?this.toArray():this,E)},map:function(d){return t(t.map(this,function(p,E){return d.call(p,E,p)}))},slice:function(){return t(c.apply(this,arguments))},ready:function(d){return K.test(l.readyState)&&l.body?d(t):l.addEventListener("DOMContentLoaded",function(){d(t)},!1),this},get:function(d){return d===e?c.call(this):this[d>=0?d:d+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode!=null&&this.parentNode.removeChild(this)})},each:function(d){return r.every.call(this,function(p,E){return d.call(p,E,p)!==!1}),this},filter:function(d){return re(d)?this.not(this.not(d)):t(i.call(this,function(p){return T.matches(p,d)}))},add:function(d,p){return t(S(this.concat(t(d,p))))},is:function(d){return this.length>0&&T.matches(this[0],d)},not:function(d){var p=[];if(re(d)&&d.call!==e)this.each(function(R){d.call(this,R)||p.push(this)});else{var E=typeof d=="string"?this.filter(d):O(d)&&re(d.item)?c.call(d):t(d);this.forEach(function(R){E.indexOf(R)<0&&p.push(R)})}return t(p)},has:function(d){return this.filter(function(){return ce(d)?t.contains(this,d):t(this).find(d).size()})},eq:function(d){return d===-1?this.slice(d):this.slice(d,+d+1)},first:function(){var d=this[0];return d&&!ce(d)?d:t(d)},last:function(){var d=this[this.length-1];return d&&!ce(d)?d:t(d)},find:function(d){var p,E=this;return d?typeof d=="object"?p=t(d).filter(function(){var R=this;return r.some.call(E,function(j){return t.contains(j,R)})}):this.length==1?p=t(T.qsa(this[0],d)):p=this.map(function(){return T.qsa(this,d)}):p=t(),p},closest:function(d,p){var E=[],R=typeof d=="object"&&t(d);return this.each(function(j,te){for(;te&&!(R?R.indexOf(te)>=0:T.matches(te,d));)te=te!==p&&!ie(te)&&te.parentNode;te&&E.indexOf(te)<0&&E.push(te)}),t(E)},parents:function(d){for(var p=[],E=this;E.length>0;)E=t.map(E,function(R){if((R=R.parentNode)&&!ie(R)&&p.indexOf(R)<0)return p.push(R),R});return b(p,d)},parent:function(d){return b(S(this.pluck("parentNode")),d)},children:function(d){return b(this.map(function(){return H(this)}),d)},contents:function(){return this.map(function(){return this.contentDocument||c.call(this.childNodes)})},siblings:function(d){return b(this.map(function(p,E){return i.call(H(E.parentNode),function(R){return R!==E})}),d)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(d){return t.map(this,function(p){return p[d]})},show:function(){return this.each(function(){this.style.display=="none"&&(this.style.display=""),getComputedStyle(this,"").getPropertyValue("display")=="none"&&(this.style.display=$(this.nodeName))})},replaceWith:function(d){return this.before(d).remove()},wrap:function(d){var p=re(d);if(this[0]&&!p)var E=t(d).get(0),R=E.parentNode||this.length>1;return this.each(function(j){t(this).wrapAll(p?d.call(this,j):R?E.cloneNode(!0):E)})},wrapAll:function(d){if(this[0]){t(this[0]).before(d=t(d));for(var p;(p=d.children()).length;)d=p.first();t(d).append(this)}return this},wrapInner:function(d){var p=re(d);return this.each(function(E){var R=t(this),j=R.contents(),te=p?d.call(this,E):d;j.length?j.wrapAll(te):R.append(te)})},unwrap:function(){return this.parent().each(function(){t(this).replaceWith(t(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(d){return this.each(function(){var p=t(this);(d===e?p.css("display")=="none":d)?p.show():p.hide()})},prev:function(d){return t(this.pluck("previousElementSibling")).filter(d||"*")},next:function(d){return t(this.pluck("nextElementSibling")).filter(d||"*")},html:function(d){return 0 in arguments?this.each(function(p){var E=this.innerHTML;t(this).empty().append(g(this,d,p,E))}):0 in this?this[0].innerHTML:null},text:function(d){return 0 in arguments?this.each(function(p){var E=g(this,d,p,this.textContent);this.textContent=E==null?"":""+E}):0 in this?this.pluck("textContent").join(""):null},attr:function(d,p){var E;return typeof d=="string"&&!(1 in arguments)?0 in this&&this[0].nodeType==1&&(E=this[0].getAttribute(d))!=null?E:e:this.each(function(R){if(this.nodeType===1)if(ce(d))for(n in d)y(this,n,d[n]);else y(this,d,g(this,p,R,this.getAttribute(d)))})},removeAttr:function(d){return this.each(function(){this.nodeType===1&&d.split(" ").forEach(function(p){y(this,p)},this)})},prop:function(d,p){return d=L[d]||d,1 in arguments?this.each(function(E){this[d]=g(this,p,E,this[d])}):this[0]&&this[0][d]},removeProp:function(d){return d=L[d]||d,this.each(function(){delete this[d]})},data:function(d,p){var E="data-"+d.replace(P,"-$1").toLowerCase(),R=1 in arguments?this.attr(E,p):this.attr(E);return R!==null?z(R):e},val:function(d){return 0 in arguments?(d==null&&(d=""),this.each(function(p){this.value=g(this,d,p,this.value)})):this[0]&&(this[0].multiple?t(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value)},offset:function(d){if(d)return this.each(function(E){var R=t(this),j=g(this,d,E,R.offset()),te=R.offsetParent().offset(),fe={top:j.top-te.top,left:j.left-te.left};R.css("position")=="static"&&(fe.position="relative"),R.css(fe)});if(!this.length)return null;if(l.documentElement!==this[0]&&!t.contains(l.documentElement,this[0]))return{top:0,left:0};var p=this[0].getBoundingClientRect();return{left:p.left+window.pageXOffset,top:p.top+window.pageYOffset,width:Math.round(p.width),height:Math.round(p.height)}},css:function(d,p){if(arguments.length<2){var E=this[0];if(typeof d=="string")return E?E.style[X(d)]||getComputedStyle(E,"").getPropertyValue(d):void 0;if(q(d)){if(!E)return;var R={},j=getComputedStyle(E,"");return t.each(d,function(fe,de){R[de]=E.style[X(de)]||j.getPropertyValue(de)}),R}}var te="";if(Q(d)=="string")!p&&p!==0?this.each(function(){this.style.removeProperty(le(d))}):te=le(d)+":"+U(d,p);else for(n in d)!d[n]&&d[n]!==0?this.each(function(){this.style.removeProperty(le(n))}):te+=le(n)+":"+U(n,d[n])+";";return this.each(function(){this.style.cssText+=";"+te})},index:function(d){return d?this.indexOf(t(d)[0]):this.parent().children().indexOf(this[0])},hasClass:function(d){return d?r.some.call(this,function(p){return this.test(I(p))},A(d)):!1},addClass:function(d){return d?this.each(function(p){if("className"in this){s=[];var E=I(this),R=g(this,d,p,E);R.split(/\s+/g).forEach(function(j){t(this).hasClass(j)||s.push(j)},this),s.length&&I(this,E+(E?" ":"")+s.join(" "))}}):this},removeClass:function(d){return this.each(function(p){if("className"in this){if(d===e)return I(this,"");s=I(this),g(this,d,p,s).split(/\s+/g).forEach(function(E){s=s.replace(A(E)," ")}),I(this,s.trim())}})},toggleClass:function(d,p){return d?this.each(function(E){var R=t(this),j=g(this,d,E,I(this));j.split(/\s+/g).forEach(function(te){(p===e?!R.hasClass(te):p)?R.addClass(te):R.removeClass(te)})}):this},scrollTop:function(d){if(this.length){var p="scrollTop"in this[0];return d===e?p?this[0].scrollTop:this[0].pageYOffset:this.each(p?function(){this.scrollTop=d}:function(){this.scrollTo(this.scrollX,d)})}},scrollLeft:function(d){if(this.length){var p="scrollLeft"in this[0];return d===e?p?this[0].scrollLeft:this[0].pageXOffset:this.each(p?function(){this.scrollLeft=d}:function(){this.scrollTo(d,this.scrollY)})}},position:function(){if(this.length){var d=this[0],p=this.offsetParent(),E=this.offset(),R=x.test(p[0].nodeName)?{top:0,left:0}:p.offset();return E.top-=parseFloat(t(d).css("margin-top"))||0,E.left-=parseFloat(t(d).css("margin-left"))||0,R.top+=parseFloat(t(p[0]).css("border-top-width"))||0,R.left+=parseFloat(t(p[0]).css("border-left-width"))||0,{top:E.top-R.top,left:E.left-R.left}}},offsetParent:function(){return this.map(function(){for(var d=this.offsetParent||l.body;d&&!x.test(d.nodeName)&&t(d).css("position")=="static";)d=d.offsetParent;return d})}},t.fn.detach=t.fn.remove,["width","height"].forEach(function(d){var p=d.replace(/./,function(E){return E[0].toUpperCase()});t.fn[d]=function(E){var R,j=this[0];return E===e?se(j)?j["inner"+p]:ie(j)?j.documentElement["scroll"+p]:(R=this.offset())&&R[d]:this.each(function(te){j=t(this),j.css(d,g(this,E,te,j[d]()))})}});function k(d,p){p(d);for(var E=0,R=d.childNodes.length;E<R;E++)k(d.childNodes[E],p)}return D.forEach(function(d,p){var E=p%2;t.fn[d]=function(){var R,j=t.map(arguments,function(de){var pe=[];return R=Q(de),R=="array"?(de.forEach(function(ye){if(ye.nodeType!==e)return pe.push(ye);if(t.zepto.isZ(ye))return pe=pe.concat(ye.get());pe=pe.concat(T.fragment(ye))}),pe):R=="object"||de==null?de:T.fragment(de)}),te,fe=this.length>1;return j.length<1?this:this.each(function(de,pe){te=E?pe:pe.parentNode,pe=p==0?pe.nextSibling:p==1?pe.firstChild:p==2?pe:null;var ye=t.contains(l.documentElement,te);j.forEach(function(ve){if(fe)ve=ve.cloneNode(!0);else if(!te)return t(ve).remove();te.insertBefore(ve,pe),ye&&k(ve,function(Te){if(Te.nodeName!=null&&Te.nodeName.toUpperCase()==="SCRIPT"&&(!Te.type||Te.type==="text/javascript")&&!Te.src){var Le=Te.ownerDocument?Te.ownerDocument.defaultView:window;Le.eval.call(Le,Te.innerHTML)}})})})},t.fn[E?d+"To":"insert"+(p?"Before":"After")]=function(R){return t(R)[d](this),this}}),T.Z.prototype=ee.prototype=t.fn,T.uniq=S,T.deserializeValue=z,t.zepto=T,t})();return window.Zepto=o,window.$===void 0&&(window.$=o),_r.exports=o,(function(e){var n=1,t,s=Array.prototype.slice,r=e.isFunction,a=function(C){return typeof C=="string"},i={},c={},l="onfocusin"in window,u={focus:"focusin",blur:"focusout"},f={mouseenter:"mouseover",mouseleave:"mouseout"};c.click=c.mousedown=c.mouseup=c.mousemove="MouseEvents";function m(C){return C._zid||(C._zid=n++)}function h(C,T,X,S){if(T=w(T),T.ns)var N=v(T.ns);return(i[m(C)]||[]).filter(function(L){return L&&(!T.e||L.e==T.e)&&(!T.ns||N.test(L.ns))&&(!X||m(L.fn)===m(X))&&(!S||L.sel==S)})}function w(C){var T=(""+C).split(".");return{e:T[0],ns:T.slice(1).sort().join(" ")}}function v(C){return new RegExp("(?:^| )"+C.replace(" "," .* ?")+"(?: |$)")}function x(C,T){return C.del&&!l&&C.e in u||!!T}function P(C){return f[C]||l&&u[C]||C}function B(C,T,X,S,N,L,q){var Q=m(C),re=i[Q]||(i[Q]=[]);T.split(/\s/).forEach(function(se){if(se=="ready")return e(document).ready(X);var ie=w(se);ie.fn=X,ie.sel=N,ie.e in f&&(X=function(ae){var O=ae.relatedTarget;if(!O||O!==this&&!e.contains(this,O))return ie.fn.apply(this,arguments)}),ie.del=L;var ce=L||X;ie.proxy=function(ae){if(ae=Y(ae),!ae.isImmediatePropagationStopped()){ae.data=S;var O=ce.apply(C,ae._args==t?[ae]:[ae].concat(ae._args));return O===!1&&(ae.preventDefault(),ae.stopPropagation()),O}},ie.i=re.length,re.push(ie),"addEventListener"in C&&C.addEventListener(P(ie.e),ie.proxy,x(ie,q))})}function D(C,T,X,S,N){var L=m(C);(T||"").split(/\s/).forEach(function(q){h(C,q,X,S).forEach(function(Q){delete i[L][Q.i],"removeEventListener"in C&&C.removeEventListener(P(Q.e),Q.proxy,x(Q,N))})})}e.event={add:B,remove:D},e.proxy=function(C,T){var X=2 in arguments&&s.call(arguments,2);if(r(C)){var S=function(){return C.apply(T,X?X.concat(s.call(arguments)):arguments)};return S._zid=m(C),S}else{if(a(T))return X?(X.unshift(C[T],C),e.proxy.apply(null,X)):e.proxy(C[T],C);throw new TypeError("expected function")}},e.fn.bind=function(C,T,X){return this.on(C,T,X)},e.fn.unbind=function(C,T){return this.off(C,T)},e.fn.one=function(C,T,X,S){return this.on(C,T,X,S,1)};var _=function(){return!0},M=function(){return!1},V=/^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/,K={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};function Y(C,T){return(T||!C.isDefaultPrevented)&&(T||(T=C),e.each(K,function(X,S){var N=T[X];C[X]=function(){return this[S]=_,N&&N.apply(T,arguments)},C[S]=M}),C.timeStamp||(C.timeStamp=Date.now()),(T.defaultPrevented!==t?T.defaultPrevented:"returnValue"in T?T.returnValue===!1:T.getPreventDefault&&T.getPreventDefault())&&(C.isDefaultPrevented=_)),C}function W(C){var T,X={originalEvent:C};for(T in C)!V.test(T)&&C[T]!==t&&(X[T]=C[T]);return Y(X,C)}e.fn.delegate=function(C,T,X){return this.on(T,C,X)},e.fn.undelegate=function(C,T,X){return this.off(T,C,X)},e.fn.live=function(C,T){return e(document.body).delegate(this.selector,C,T),this},e.fn.die=function(C,T){return e(document.body).undelegate(this.selector,C,T),this},e.fn.on=function(C,T,X,S,N){var L,q,Q=this;return C&&!a(C)?(e.each(C,function(re,se){Q.on(re,T,X,se,N)}),Q):(!a(T)&&!r(S)&&S!==!1&&(S=X,X=T,T=t),(S===t||X===!1)&&(S=X,X=t),S===!1&&(S=M),Q.each(function(re,se){N&&(L=function(ie){return D(se,ie.type,S),S.apply(this,arguments)}),T&&(q=function(ie){var ce,ae=e(ie.target).closest(T,se).get(0);if(ae&&ae!==se)return ce=e.extend(W(ie),{currentTarget:ae,liveFired:se}),(L||S).apply(ae,[ce].concat(s.call(arguments,1)))}),B(se,C,S,X,T,q||L)}))},e.fn.off=function(C,T,X){var S=this;return C&&!a(C)?(e.each(C,function(N,L){S.off(N,T,L)}),S):(!a(T)&&!r(X)&&X!==!1&&(X=T,T=t),X===!1&&(X=M),S.each(function(){D(this,C,X,T)}))},e.fn.trigger=function(C,T){return C=a(C)||e.isPlainObject(C)?e.Event(C):Y(C),C._args=T,this.each(function(){C.type in u&&typeof this[C.type]=="function"?this[C.type]():"dispatchEvent"in this?this.dispatchEvent(C):e(this).triggerHandler(C,T)})},e.fn.triggerHandler=function(C,T){var X,S;return this.each(function(N,L){X=W(a(C)?e.Event(C):C),X._args=T,X.target=L,e.each(h(L,C.type||C),function(q,Q){if(S=Q.proxy(X),X.isImmediatePropagationStopped())return!1})}),S},"focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(C){e.fn[C]=function(T){return 0 in arguments?this.bind(C,T):this.trigger(C)}}),e.Event=function(C,T){a(C)||(T=C,C=T.type);var X=document.createEvent(c[C]||"Events"),S=!0;if(T)for(var N in T)N=="bubbles"?S=!!T[N]:X[N]=T[N];return X.initEvent(C,S,!0),Y(X)}})(o),(function(e){var n=+new Date,t=window.document,s,r,a=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,i=/^(?:text|application)\/javascript/i,c=/^(?:text|application)\/xml/i,l="application/json",u="text/html",f=/^\s*$/,m=t.createElement("a");m.href=window.location.href;function h(S,N,L){var q=e.Event(N);return e(S).trigger(q,L),!q.isDefaultPrevented()}function w(S,N,L,q){if(S.global)return h(N||t,L,q)}e.active=0;function v(S){S.global&&e.active++===0&&w(S,null,"ajaxStart")}function x(S){S.global&&!--e.active&&w(S,null,"ajaxStop")}function P(S,N){var L=N.context;if(N.beforeSend.call(L,S,N)===!1||w(N,L,"ajaxBeforeSend",[S,N])===!1)return!1;w(N,L,"ajaxSend",[S,N])}function B(S,N,L,q){var Q=L.context,re="success";L.success.call(Q,S,re,N),q&&q.resolveWith(Q,[S,re,N]),w(L,Q,"ajaxSuccess",[N,L,S]),_(re,N,L)}function D(S,N,L,q,Q){var re=q.context;q.error.call(re,L,N,S),Q&&Q.rejectWith(re,[L,N,S]),w(q,re,"ajaxError",[L,q,S||N]),_(N,L,q)}function _(S,N,L){var q=L.context;L.complete.call(q,N,S),w(L,q,"ajaxComplete",[N,L]),x(L)}function M(S,N,L){if(L.dataFilter==V)return S;var q=L.context;return L.dataFilter.call(q,S,N)}function V(){}e.ajaxJSONP=function(S,N){if(!("type"in S))return e.ajax(S);var L=S.jsonpCallback,q=(e.isFunction(L)?L():L)||"Zepto"+n++,Q=t.createElement("script"),re=window[q],se,ie=function(O){e(Q).triggerHandler("error",O||"abort")},ce={abort:ie},ae;return N&&N.promise(ce),e(Q).on("load error",function(O,G){clearTimeout(ae),e(Q).off().remove(),O.type=="error"||!se?D(null,G||"error",ce,S,N):B(se[0],ce,S,N),window[q]=re,se&&e.isFunction(re)&&re(se[0]),re=se=void 0}),P(ce,S)===!1?(ie("abort"),ce):(window[q]=function(){se=arguments},Q.src=S.url.replace(/\?(.+)=\?/,"?$1="+q),t.head.appendChild(Q),S.timeout>0&&(ae=setTimeout(function(){ie("timeout")},S.timeout)),ce)},e.ajaxSettings={type:"GET",beforeSend:V,success:V,error:V,complete:V,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:l,xml:"application/xml, text/xml",html:u,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0,dataFilter:V};function K(S){return S&&(S=S.split(";",2)[0]),S&&(S==u?"html":S==l?"json":i.test(S)?"script":c.test(S)&&"xml")||"text"}function Y(S,N){return N==""?S:(S+"&"+N).replace(/[&?]{1,2}/,"?")}function W(S){S.processData&&S.data&&e.type(S.data)!="string"&&(S.data=e.param(S.data,S.traditional)),S.data&&(!S.type||S.type.toUpperCase()=="GET"||S.dataType=="jsonp")&&(S.url=Y(S.url,S.data),S.data=void 0)}e.ajax=function(S){var N=e.extend({},S||{}),L=e.Deferred&&e.Deferred(),q,Q;for(s in e.ajaxSettings)N[s]===void 0&&(N[s]=e.ajaxSettings[s]);v(N),N.crossDomain||(q=t.createElement("a"),q.href=N.url,q.href=q.href,N.crossDomain=m.protocol+"//"+m.host!=q.protocol+"//"+q.host),N.url||(N.url=window.location.toString()),(Q=N.url.indexOf("#"))>-1&&(N.url=N.url.slice(0,Q)),W(N);var re=N.dataType,se=/\?.+=\?/.test(N.url);if(se&&(re="jsonp"),(N.cache===!1||(!S||S.cache!==!0)&&(re=="script"||re=="jsonp"))&&(N.url=Y(N.url,"_="+Date.now())),re=="jsonp")return se||(N.url=Y(N.url,N.jsonp?N.jsonp+"=?":N.jsonp===!1?"":"callback=?")),e.ajaxJSONP(N,L);var ie=N.accepts[re],ce={},ae=function(U,$){ce[U.toLowerCase()]=[U,$]},O=/^([\w-]+:)\/\//.test(N.url)?RegExp.$1:window.location.protocol,G=N.xhr(),ue=G.setRequestHeader,le;if(L&&L.promise(G),N.crossDomain||ae("X-Requested-With","XMLHttpRequest"),ae("Accept",ie||"*/*"),(ie=N.mimeType||ie)&&(ie.indexOf(",")>-1&&(ie=ie.split(",",2)[0]),G.overrideMimeType&&G.overrideMimeType(ie)),(N.contentType||N.contentType!==!1&&N.data&&N.type.toUpperCase()!="GET")&&ae("Content-Type",N.contentType||"application/x-www-form-urlencoded"),N.headers)for(r in N.headers)ae(r,N.headers[r]);if(G.setRequestHeader=ae,G.onreadystatechange=function(){if(G.readyState==4){G.onreadystatechange=V,clearTimeout(le);var U,$=!1;if(G.status>=200&&G.status<300||G.status==304||G.status==0&&O=="file:"){if(re=re||K(N.mimeType||G.getResponseHeader("content-type")),G.responseType=="arraybuffer"||G.responseType=="blob")U=G.response;else{U=G.responseText;try{U=M(U,re,N),re=="script"?(0,eval)(U):re=="xml"?U=G.responseXML:re=="json"&&(U=f.test(U)?null:e.parseJSON(U))}catch(H){$=H}if($)return D($,"parsererror",G,N,L)}B(U,G,N,L)}else D(G.statusText||null,G.status?"error":"abort",G,N,L)}},P(G,N)===!1)return G.abort(),D(null,"abort",G,N,L),G;var A="async"in N?N.async:!0;if(G.open(N.type,N.url,A,N.username,N.password),N.xhrFields)for(r in N.xhrFields)G[r]=N.xhrFields[r];for(r in ce)ue.apply(G,ce[r]);return N.timeout>0&&(le=setTimeout(function(){G.onreadystatechange=V,G.abort(),D(null,"timeout",G,N,L)},N.timeout)),G.send(N.data?N.data:null),G};function C(S,N,L,q){return e.isFunction(N)&&(q=L,L=N,N=void 0),e.isFunction(L)||(q=L,L=void 0),{url:S,data:N,success:L,dataType:q}}e.get=function(){return e.ajax(C.apply(null,arguments))},e.post=function(){var S=C.apply(null,arguments);return S.type="POST",e.ajax(S)},e.getJSON=function(){var S=C.apply(null,arguments);return S.dataType="json",e.ajax(S)},e.fn.load=function(S,N,L){if(!this.length)return this;var q=this,Q=S.split(/\s/),re,se=C(S,N,L),ie=se.success;return Q.length>1&&(se.url=Q[0],re=Q[1]),se.success=function(ce){q.html(re?e("<div>").html(ce.replace(a,"")).find(re):ce),ie&&ie.apply(q,arguments)},e.ajax(se),this};var T=encodeURIComponent;function X(S,N,L,q){var Q,re=e.isArray(N),se=e.isPlainObject(N);e.each(N,function(ie,ce){Q=e.type(ce),q&&(ie=L?q:q+"["+(se||Q=="object"||Q=="array"?ie:"")+"]"),!q&&re?S.add(ce.name,ce.value):Q=="array"||!L&&Q=="object"?X(S,ce,L,ie):S.add(ie,ce)})}e.param=function(S,N){var L=[];return L.add=function(q,Q){e.isFunction(Q)&&(Q=Q()),Q==null&&(Q=""),this.push(T(q)+"="+T(Q))},X(L,S,N),L.join("&").replace(/%20/g,"+")}})(o),(function(e){e.fn.serializeArray=function(){var n,t,s=[],r=function(a){if(a.forEach)return a.forEach(r);s.push({name:n,value:a})};return this[0]&&e.each(this[0].elements,function(a,i){t=i.type,n=i.name,n&&i.nodeName.toLowerCase()!="fieldset"&&!i.disabled&&t!="submit"&&t!="reset"&&t!="button"&&t!="file"&&(t!="radio"&&t!="checkbox"||i.checked)&&r(e(i).val())}),s},e.fn.serialize=function(){var n=[];return this.serializeArray().forEach(function(t){n.push(encodeURIComponent(t.name)+"="+encodeURIComponent(t.value))}),n.join("&")},e.fn.submit=function(n){if(0 in arguments)this.bind("submit",n);else if(this.length){var t=e.Event("submit");this.eq(0).trigger(t),t.isDefaultPrevented()||this.get(0).submit()}return this}})(o),(function(){try{getComputedStyle(void 0)}catch{var e=getComputedStyle;window.getComputedStyle=function(t,s){try{return e(t,s)}catch{return null}}}})(),o})});var Pe=zn((Uo,Br)=>{if(!window.VexFlow)throw new Error("Load vexflow.js before vextab.js.");Br.exports=window.VexFlow});var bi=zn(()=>{var gi=document.createElement("style");gi.textContent=`/* Score and editor styles for the browser embed. */
|
|
2
2
|
div.vextab-auto {
|
|
3
3
|
font-family: Academico, Georgia, serif;
|
|
4
4
|
font-size: 18px;
|
|
@@ -347,7 +347,7 @@ div.vextab-auto .title {
|
|
|
347
347
|
@media print {
|
|
348
348
|
.vextab-playback-controls, .vextab-transport, .vextab-playback-ink, .vextab-playback-paper { display: none !important; }
|
|
349
349
|
}
|
|
350
|
-
`;document.head.append(
|
|
350
|
+
`;document.head.append(gi)});var Go={};Tr(Go,{Artist:()=>Ke,Div:()=>kt,Player:()=>Ue,ScoreError:()=>ne,ScoreV2Error:()=>Xe,Vex:()=>Z,VexTab:()=>Ye,createPerformer:()=>yr,createSpessaSynthPlayback:()=>Hn,createWebAudioPlayback:()=>mt,isPerformerName:()=>xt,parseScore:()=>st,performerProfiles:()=>Xt,renderConductor:()=>On,renderEdition:()=>mi,renderScore:()=>zt,renderScorePart:()=>Ln,resolvePart:()=>yi});var Mr={};Tr(Mr,{Artist:()=>Ke,Div:()=>jt,Flow:()=>xi,Player:()=>Ue,ScoreError:()=>ne,ScoreV2Error:()=>Xe,VexTab:()=>Ye,createSpessaSynthPlayback:()=>Hn,createWebAudioPlayback:()=>mt,parseScore:()=>st,renderScore:()=>zt,renderScorePart:()=>Ln});var Dn=Ee(tn());var Er=Ee(tn());function jn(o){if(typeof o=="number")return o;if(!/^\d+\/[1-9]\d*$/.test(o))return NaN;let[e,n]=o.split("/").map(Number);return Number.isSafeInteger(e)&&Number.isSafeInteger(n)?e/n:NaN}function Ar(o){let e=o.getSpacingBetweenLines()/2;return{left:o.getX(),right:o.getX()+o.getWidth(),top:o.getYForLine(0)-e,bottom:o.getYForLine(o.getNumLines()-1)+e}}function Ti(o,e,n,t){let s=new Map,r=new Map;for(let c of o){let{partIndex:l,score:u,local:f,view:m}=c,h=u.measures[e-1],w=f.staves[e-1];w.forEach((v,x)=>s.set(v,{partIndex:l,staffIndex:x,bounds:Ar(v)}));for(let[v,x]of m.staves.entries())for(let P of h.voices)if(!(P.hand&&P.hand!==x))for(let B of P.events){let D=jn(B.onset),_=f.getNote(m.eventId(x,B.id)),M=r.get(D);if(!M){let Y=_.getAbsoluteX()-(_.isCenterAligned()?_.getCenterXShift():0);M={time:D,x:Y,events:new Map},r.set(D,M)}let V=s.get(_.getStave())??s.get(w[v]),K=M.events.get(V);K?K.push(B.id):M.events.set(V,[B.id])}}let a=[...r.values()].sort((c,l)=>c.time-l.time),i=[...s.values()];return a.push({time:jn(o[0].score.measures[e-1].span),x:i[0].bounds.right,events:new Map}),{measure:e,system:n,systemBounds:t,anchors:a,staves:i}}function Rr(o,e,n){let t=0,s=o.length;for(;t<s;){let r=Math.floor((t+s)/2);o[r][n]<e?t=r+1:s=r}return t}function Cr(o,e,n,t,s){return t+(o-e)/(n-e)*(s-t)}function Gt(o,e,n,t,s){let{partIndex:r,staffIndex:a,bounds:i}=e;return{partIndex:r,staffIndex:a,measure:o.measure,offset:n,system:o.system,x:t,staffBounds:i,staffCenterY:(i.top+i.bottom)/2,systemBounds:o.systemBounds,eventIds:s?.events.get(e)??[]}}var Wt=.5;function Pi(o,e,n){let t=o.anchors;if(e<t[0].x-Wt||e>t[t.length-1].x+Wt)return;let s=o.staves.find(l=>n>=l.bounds.top&&n<=l.bounds.bottom);if(!s)return;let r=Math.min(t.length-1,Rr(t,e,"x")),a=t[r],i=t[r-1],c=i&&e-i.x<a.x-e?i:a;return Math.abs(c.x-e)<=Wt?Gt(o,s,c.time,c.x,c):Gt(o,s,Cr(e,i.x,a.x,i.time,a.time),e)}function nn(o){if(o instanceof SVGSVGElement)return({clientX:t,clientY:s})=>{let r=o.getScreenCTM();if(!r)return;let{x:a,y:i}=new DOMPoint(t,s).matrixTransform(r.inverse());if(Number.isFinite(a)&&Number.isFinite(i))return{x:a,y:i}};let e=parseFloat(o.style.width),n=parseFloat(o.style.height);return({clientX:t,clientY:s})=>{let r=o.getBoundingClientRect();if(r.width&&r.height)return{x:(t-r.left)*e/r.width,y:(s-r.top)*n/r.height}}}function Ir(o,e,n,t,s){let r=o.sheet.getContinuousLayout().rows,a=[],i=r.map(c=>{let l=c.measures.flatMap(u=>o.staves[u-1].map(Ar));return{left:Math.min(...l.map(u=>u.left)),right:Math.max(...l.map(u=>u.right)),top:Math.min(...l.map(u=>u.top)),bottom:Math.max(...l.map(u=>u.bottom))}});return r.forEach((c,l)=>{for(let u of c.measures)a[u-1]=Ti(e,u,l+1,i[l])}),{clientPoint:s,positionAt({partIndex:c,staffIndex:l=0,measure:u,offset:f}){if(!Number.isInteger(u))return;let m=a[u-1],h=m?.staves.find(B=>B.partIndex===c&&B.staffIndex===l),w=jn(f);if(!h||!Number.isFinite(w)||w<0)return;let v=Rr(m.anchors,w,"time"),x=m.anchors[v];if(!x)return;if(x.time===w)return Gt(m,h,w,x.x,x);let P=m.anchors[v-1];if(P)return Gt(m,h,w,Cr(w,P.time,x.time,P.x,x.x))},hitTest({x:c,y:l}){if(!Number.isFinite(c)||!Number.isFinite(l))return;let u=i.findIndex(v=>l>=v.top&&l<=v.bottom&&c>=v.left-Wt&&c<=v.right+Wt);if(u>=0)for(let v of r[u].measures){let x=Pi(a[v-1],c,l);if(x)return x}let f=n.hitTest(c,l);if(!f||f.reference||f.role==="mark")return;let m=a[f.measure-1],h=m.staves[t.findIndex(v=>v.id===f.staff)],w=m.anchors.find(v=>v.events.get(h)?.includes(f.sourceEvent));if(w)return Gt(m,h,w.time,w.x,w)}}}var Be=Ee(tn());var Ge=Ee(Pe());Ge.default.Flow||(Ge.default.Flow=Ge.default);!Ge.default.RERR&&Ge.default.RuntimeError&&(Ge.default.RERR=Ge.default.RuntimeError);Ge.default.BM||(Ge.default.BM=(o,e)=>e());var Z=Ge.default;var Ni=new Set(`
|
|
351
351
|
aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood
|
|
352
352
|
cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray
|
|
353
353
|
darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen
|
|
@@ -361,12 +361,12 @@ mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orc
|
|
|
361
361
|
paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown
|
|
362
362
|
royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow
|
|
363
363
|
springgreen steelblue tan teal thistle tomato transparent turquoise violet wheat white whitesmoke yellow yellowgreen
|
|
364
|
-
`.trim().split(/\s+/));function Be(o){return bi.has(o.toLowerCase())||/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(o)}function ke(o){return{fillStyle:o,strokeStyle:o}}function en(o,e){let n=getComputedStyle(e).backgroundColor;n&&!n.startsWith("rgba(")&&!n.includes("/")&&o.setBackgroundFillStyle(n)}var Je=Ee(Pe()),Hn="Academico",ze=()=>Je.default.getTextFonts()[0],ht=()=>Je.default.getFonts()[0],kt=()=>ze()==="Petaluma Script"?"normal":"bold";function St(o,e){if(!o)return e();let n=Je.default.getFonts(),t=Je.default.getTextFonts();try{return o==="Petaluma"?Je.default.setFonts("Petaluma","Petaluma Script"):Je.default.setFonts("Bravura",Hn),e()}finally{Je.default.setFonts(...n),Je.default.setTextFonts(...t)}}function fe(o){if(!(!o||o.length===0))return o[o.length-1]}function De(o){return o==null?!0:Array.isArray(o)||typeof o=="string"?o.length===0:typeof o=="object"?Object.keys(o).length===0:!1}function tn(o,e){if(o){if(Array.isArray(o)){o.forEach((n,t)=>e(n,t));return}Object.keys(o).forEach(n=>e(o[n],n))}}function Pr(o,e){tn(o,e)}function _r(o,e){let n=[];return tn(o,(t,s)=>n.push(e(t,s))),n}function $e(o,...e){let n=e.filter(t=>t!=null);return Object.assign(o,...n)}function Nr(o){return o?Object.keys(o):[]}function Dn(o,e){return o?Object.prototype.hasOwnProperty.call(o,e):!1}function nn(o,...e){let n={};return e.forEach(t=>{Dn(o,t)&&(n[t]=o[t])}),n}var Ne=Ee(Pe()),rn=class{constructor(e){this.artist=e}prepareStave(e,n){if(!e)return[];let t=Z.Flow.Barline.type,s=t.SINGLE,r=n.map(a=>{let i=fe(a);return i instanceof Z.Flow.BarNote&&i.getType()!==t.REPEAT_BEGIN?(s=i.getType(),a.slice(0,-1)):a});return e.setEndBarType(s),r}makeBeams(e,n,t,s,r){let a=n.options;if(r&&a["tab-stems"]!=="true")return[];let i;n.direction==="top"?i=1:n.direction==="bottom"?i=-1:t.voiceSettings.length>1?i=s===0?1:-1:r&&(i=a["tab-stem-direction"]==="down"?-1:1);for(let l of e)i&&l.setStemDirection&&l.setStemDirection(i);return a.beams==="off"?[]:a.beams==="explicit"?n.groups.map(([l,c])=>{let u=new Ne.Beam(e.slice(l,c),i===void 0);return u.renderOptions.showStemlets=a["beam-stemlets"]==="true",u}):Ne.Beam.generateBeams(e,{groups:t.beam_groups,stemDirection:i,beamRests:a["beam-rests"]==="true",showStemlets:a["beam-stemlets"]==="true",beamMiddleOnly:a["beam-middle-only"]==="true"})}alignTopAnnotations(e,n){let t=[];for(let r of e.getTickables())r.getModifiers().filter(i=>i instanceof Ne.Annotation&&i.getVerticalJustification()===Ne.Annotation.VerticalJustify.TOP).forEach((i,l)=>{i.setLayoutBaseline(void 0),(t[l]??=[]).push(i)});let s=n.getYForLine(-1);for(let r of t){for(let a of r)s=Math.min(s,a.computeY().y);for(let a of r)a.setLayoutBaseline(s);s-=Math.max(...r.map(a=>a.computeY().textHeight))}}alignTextBars(e,n){let t=[],s=new Ne.Fraction(0,1);for(let i of n)i.shouldIgnoreTicks()?t.push(s.clone()):s.add(i.getTicks());if(!t.length)return e;let r=[];s=new Ne.Fraction(0,1);let a=0;for(let i of e){for(;a<t.length&&!t[a].greaterThan(s)&&!(t[a++].equals(s)&&i.shouldIgnoreTicks());)r.push(new Ne.TextNote({text:"",duration:"b",ignoreTicks:!0}));r.push(i),i.shouldIgnoreTicks()||s.add(i.getTicks())}return r}formatAndRender(e,n,t,s){let r=[],a=(P,B,j)=>P.flatMap((A,T)=>{if(!A.length)return[];A.forEach(U=>U.setStave(B));let V=new Ne.Voice(n.meter).setMode(Ne.Voice.Mode.SOFT).addTickables(A);return r.push(...this.makeBeams(A,n.voiceSettings[T],n,T,j)),[V]}),i=n.tab,l=n.note,c=a(t,i,!0),u=a(s,l,!1),f=l||i,p=f,E=n.text_voices.filter(P=>P.length).map(P=>{let B=this.alignTextBars(P,s[0]??t[0]??[]);return B.forEach(j=>j.setStave(p)),new Ne.Voice(n.meter).setMode(Ne.Voice.Mode.SOFT).addTickables(B)}),k=new Ne.Formatter,S=[...c,...u,...E];for(let P of[c,u,E])P.length&&k.joinVoices(P);S.length&&k.formatToStave(S,f,{alignRests:u.length>1});for(let P of c)this.alignTopAnnotations(P,i),P.draw(e,i);for(let P of u)P.draw(e,l);for(let P of r)P.setContext(e).draw();for(let P of E)P.draw(e,p);return i&&l&&new Z.Flow.StaveConnector(l,i).setType(Z.Flow.StaveConnector.type.BRACKET).setContext(e).draw(),l?u:c}render(e){let n=this.artist;n.log("Render: ",n.options),n.closeBends(),e.resize(Number(n.customizations.width)*Number(n.customizations.scale),(n.last_y+n.options.bottom_spacing)*Number(n.customizations.scale));let t=e.getContext();t.setViewBox?t.setViewBox(0,0,Number(n.customizations.width),n.last_y+n.options.bottom_spacing):t.scale(Number(n.customizations.scale),Number(n.customizations.scale)),t.clear(),t.setFont(n.options.font_face,n.options.font_size,""),n.renderer_context=t,n.player_voices=[];let s=r=>{r.note&&n.notes.applyAccidentals(r);let a=this.prepareStave(r.tab,r.tab_voices),i=this.prepareStave(r.note,r.note_voices);if(r.tab&&r.note){let c=Math.max(r.tab.getNoteStartX(),r.note.getNoteStartX());r.tab.setNoteStartX(c),r.note.setNoteStartX(c)}r.tab&&r.tab.setContext(t).draw(),r.note&&r.note.setContext(t).draw();let l=this.formatAndRender(t,r,a,i);n.player_voices.push(l)};for(let r of n.staves){if(!r.color){s(r);continue}let a=t.getDefaultStyle();t.save();try{t.setDefaultStyle(ke(r.color)).setStrokeStyle(r.color).setFillStyle(r.color),s(r)}finally{t.setDefaultStyle(a),t.restore()}}n.log("Rendering tab articulations."),n.tab_articulations.forEach(r=>r.setContext(t).drawWithStyle()),n.log("Rendering note articulations."),n.stave_articulations.forEach(r=>r.setContext(t).drawWithStyle()),n.player&&(n.customizations.player==="true"?(n.player.setTempo(parseInt(String(n.customizations.tempo),10)),n.player.setInstrument(String(n.customizations.instrument)),n.player.render()):n.player.removeControls()),n.rendered=!0}};var Ce=Ee(Pe());var yi={left:Ce.Modifier.Position.LEFT,right:Ce.Modifier.Position.RIGHT,above:Ce.Modifier.Position.ABOVE,below:Ce.Modifier.Position.BELOW};function zn(o,e,n=!1,t=!1){let s=!t&&(e===Ce.Modifier.Position.LEFT||e===Ce.Modifier.Position.RIGHT),r=n?new Ce.StringNumber(o):new Ce.FretHandFinger(o,{headPlacement:s}).setDrawCircle(t&&/^\d$/.test(o));return r.setPosition(e),r}function Et(o,e,n,t,s=!1,r=!1){for(let a of n){let i=yi[a.position];if(a.finger!==void 0){if(t&&!s)continue;if((r||/^[pimac]$/.test(a.finger))&&(a.position==="above"||a.position==="below")){let l=a.position==="above"?Ce.Annotation.VerticalJustify.TOP:Ce.Annotation.VerticalJustify.BOTTOM;o.addModifier(new Ce.Annotation(a.finger).setFont(ze(),11).setVerticalJustification(l),e);continue}o.addModifier(zn(a.finger,i,a.stringNumber,t),e)}else o.addModifier(new Ce.Articulation(a.articulation??"a>").setPosition(i),e)}}function jn(o,e){return o?.find(n=>!n.finger||!/^\d$/.test(n.finger)||n.stringNumber?!1:n.position==="left"||n.position==="right"?!0:e.some(t=>t.marks?.some(s=>s!==n&&s.position===n.position&&/^\d$/.test(s.finger??"")&&!s.stringNumber)))}function Gn(o,e,n,t){switch(o){case"a":case"above":case"top":return"above";case"b":case"below":case"bottom":return"below";case"l":case"left":if(!e)return"left";break;case"r":case"right":if(!e)return"right";break}return n(e?"Place an accent above or below":"Place a fingering left, right, above or below",t)}function xi(o,e,n,t,s){return o.slice(1,-1).split(",").map(r=>{let a=/^(?:f([0-5T])|(>))(?::([a-z]+))?$/.exec(r.trim());if(!a)return s("Expected a finger such as f2 or an accent > with optional placement",e);let[,i,,l]=a;return{...i&&{finger:i},position:l?Gn(l,!i,s,e):i?n:t}})}function Ar(o,e,n){let t="left",s="above";for(let r of o){if(r.element==="options")continue;let a=r.element==="voice",i=a?t:"left",l=a?s:"above";for(let c of r.options??[])c.key==="fingering"&&(i=Gn(c.value,!1,n,c.range??e(c._l,c._c))),c.key==="accents"&&(l=Gn(c.value,!0,n,c.range??e(c._l,c._c)));a||(t=i,s=l);for(let c of r.notes??[])for(let u of c.chord??[c])u.suffix&&(u.marks=xi(u.suffix.text,u.suffix.range,i,l,n),delete u.suffix)}}var $=function(o,e,n={}){return o.forEach(t=>n[t]=e),n},Rr=[1,6],Cr=[1,7],Ir=[1,8],Fr=[1,9],Br=[1,10],Gt=[5,11,13,14,15,16],at=[5,11,13,14,15,16,18,20,22],Vr=[2,18],Wn=[1,15],ct=[5,11,13,14,15,16,18,20,22,24],Or=[1,19],Lr=[1,20],Hr=[1,21],Dr=[1,22],zr=[1,46],jr=[1,31],Gr=[1,35],Wr=[1,36],sn=[1,42],qr=[1,45],Ur=[1,44],Ze=[1,60],Qe=[1,61],et=[1,62],Tt=[1,58],Mt=[1,53],Pt=[1,54],_t=[1,55],Nt=[1,56],At=[1,57],Rt=[1,59],Kr=[1,47],Xr=[1,48],Yr=[1,49],Jr=[1,50],tt=[1,63],$r=[1,67],Zr=[1,68],Qr=[5,11,13,14,15,16,18,20,22,28],he=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],qn=[2,94],Un=[1,80],Kn=[1,77],Xn=[1,78],Yn=[1,79],on=[5,11,13,14,15,16,18,20,22,26,32,34,38,39,44,45,46,47,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],Jn=[1,83],es=[1,88],ts=[1,89],ns=[1,90],rs=[1,91],Ve=[50,68,70,72,73,74,75,76,77,78,79,80],gt=[32,47,57,58,59,87],Ct=[50,57,68,70,72,73,74,75,76,77,78,79,80,92],ss=[1,113],an=[34,45],cn=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,50,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],is=[2,77],os=[1,120],$n=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,70,72,73,74,75,76,77,81,82,84,86,87],ln=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,70,71,72,73,74,75,76,77,81,82,84,86,87],as=[28,82],Zn=[50,57,68,70,72,73,74,75,76,77,78,79,80],vi=(function(){return{yy:{},options:{},rules:[/^notes\b/,/^tabstave\b/,/^piano\b/,/^stave\b/,/^voice\b/,/^options\b/,/^text\b/,/^slur\b/,/^["][^"\r\n]*["]/,/^[^\s="][^\s=]*/,/^[$]/,/^[$]/,/^[^,$]+/,/^[!]/,/^[!]/,/^(?:([^!"\r\n]|["]([^"\\\r\n]|\\.)*["])+)/,/^[^!]+/,/^[^,\r\n]+/,/^\//,/^\+/,/^:/,/^=/,/^\(/,/^\)/,/^(?:\[([f]|[>])[^\]/\r\n]*\])/,/^\[/,/^\]/,/^\^/,/^,/,/^(?:\|)/,/^\./,/^#/,/^@/,/^(?:(kick|snare|hat))/,/^[b]/,/^[s]/,/^[h]/,/^[p]/,/^[t]/,/^[T]/,/^[-]/,/^[_]/,/^[v]/,/^[V]/,/^[u]/,/^[d]/,/^[<>]/,/^[0-9]+z[0-9]+(z[0-9]+)?/,/^[0-9]+/,/^[q]/,/^[w]/,/^[h]/,/^[d]/,/^[S]/,/^[A-GXLR]/,/^[n]/,/^[~]/,/^[\r\n]+/,/^[ \t]+/,/^$/,/^./],conditions:{notes:{rules:[10,13,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60],inclusive:!0},text:{rules:[17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,48,49,50,51,52,57,58,59,60],inclusive:!0},slur:{rules:[18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},annotations:{rules:[11,12,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},options:{rules:[8,9,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},command:{rules:[14,15,16,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},INITIAL:{rules:[0,1,2,3,4,5,6,7,9,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0}},performAction(e,n,t,s){let r=s;switch(t){case 0:{return this.begin("notes"),20;break}case 1:{return this.begin("options"),13;break}case 2:{return this.begin("options"),15;break}case 3:{return this.begin("options"),14;break}case 4:{return this.begin("options"),16;break}case 5:{return this.begin("options"),11;break}case 6:{return this.begin("text"),18;break}case 7:{return this.begin("options"),22;break}case 8:return 25;case 9:return 24;case 10:{return this.begin("annotations"),82;break}case 11:{return this.begin("notes"),82;break}case 12:return 24;case 13:{return this.begin("command"),84;break}case 14:{return this.begin("notes"),84;break}case 15:return 85;case 16:return 85;case 17:return 27;case 18:return 50;case 19:return"+";case 20:return 47;case 21:return 26;case 22:return 32;case 23:return 34;case 24:return 53;case 25:return 38;case 26:return 39;case 27:return 81;case 28:return 28;case 29:return 46;case 30:return 45;case 31:return 86;case 32:return 90;case 33:return 44;case 34:return 76;case 35:return 73;case 36:return 68;case 37:return 77;case 38:return 74;case 39:return 75;case 40:return 72;case 41:return 61;case 42:return 78;case 43:return 79;case 44:return 80;case 45:return 70;case 46:return 58;case 47:return 59;case 48:return 57;case 49:return 69;case 50:return 67;case 51:return 68;case 52:return 70;case 53:return 71;case 54:return 87;case 55:return 91;case 56:return 92;case 57:{this.begin("INITIAL");break}case 58:break;case 59:return 5;case 60:return"INVALID"}},setInput(e,n){return this.yy=n||this.yy||{},this._input=e,this._more=!1,this._backtrack=!1,this.done=!1,this.currentCondition="INITIAL",this.conditionStack=["INITIAL"],this.offset=0,this.yytext=this.match="",this.yyleng=0,this.yylineno=0,this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},parseError(e,n){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,n)},input(){let e=this._input[this.offset],n=/\r\n?|\n/g.test(e);return this.offset++,this.yyleng++,this.yytext=this.match=this.yytext+e,n?(this.yylineno++,this.yylloc.last_line++,this.yylloc.last_column=0):this.yylloc.last_column++,e},lineColumnForOffset(e=this.offset,n=this._input,t=1,s=0){let r=/\r\n?|\n/g,a=t,i=s,l=0,c;for(;(c=r.exec(n))!==null;)if(c.index<e)a++,i=0,l=c.index+c[0].length;else{i+=e-l,l=-1;break}return l!==-1&&(i+=e-l),{line:a,column:i}},setMatch(e,n){let t=this._input.slice(e,n),s=e!==this.offset?this.lineColumnForOffset(e):{line:this.yylloc.last_line,column:this.yylloc.last_column},r=e!==n?this.lineColumnForOffset(n-e,t,s.line,s.column):s;this.yytext=this.match=t,this.yyleng=n-e,this.offset=n,this.yylineno=r.line-1,this.yylloc={first_line:s.line,first_column:s.column,last_line:r.line,last_column:r.column}},less(e){let n=this.offset-this.match.length;this.setMatch(n,n+e)},unput(e){let n=this.match.length-e.length;if(!this.match.startsWith(e,n))throw new Error("Lexer#unput() should receive a part of matched text only");this.less(n)},more(){this._more=!0},reject(){throw new Error("reject() is allowed only when options.backtrack_lexer = true")},showPosition(e=this.offset-this.match.length){let n=this._input,t=Math.max(e-20,0),s=Math.min(e+20,n.length),r=(t===0?"":"...")+n.slice(t,e).replace(/\r\n?|\n/g,"\\n"),a=n.slice(e,s).replace(/\r\n?|\n/g,"\\n")+(s===n.length?"":"...");return r+a+`
|
|
364
|
+
`.trim().split(/\s+/));function Fe(o){return Ni.has(o.toLowerCase())||/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(o)}function ke(o){return{fillStyle:o,strokeStyle:o}}function rn(o,e){let n=getComputedStyle(e).backgroundColor;n&&!n.startsWith("rgba(")&&!n.includes("/")&&o.setBackgroundFillStyle(n)}var $e=Ee(Pe()),Gn="Academico",ze=()=>$e.default.getTextFonts()[0],ht=()=>$e.default.getFonts()[0],St=()=>ze()==="Petaluma Script"?"normal":"bold";function gt(o,e){if(!o)return e();let n=$e.default.getFonts(),t=$e.default.getTextFonts();try{return o==="Petaluma"?$e.default.setFonts("Petaluma","Petaluma Script"):$e.default.setFonts("Bravura",Gn),e()}finally{$e.default.setFonts(...n),$e.default.setTextFonts(...t)}}function me(o){if(!(!o||o.length===0))return o[o.length-1]}function De(o){return o==null?!0:Array.isArray(o)||typeof o=="string"?o.length===0:typeof o=="object"?Object.keys(o).length===0:!1}function sn(o,e){if(o){if(Array.isArray(o)){o.forEach((n,t)=>e(n,t));return}Object.keys(o).forEach(n=>e(o[n],n))}}function Fr(o,e){sn(o,e)}function Vr(o,e){let n=[];return sn(o,(t,s)=>n.push(e(t,s))),n}function Ze(o,...e){let n=e.filter(t=>t!=null);return Object.assign(o,...n)}function Or(o){return o?Object.keys(o):[]}function Wn(o,e){return o?Object.prototype.hasOwnProperty.call(o,e):!1}function on(o,...e){let n={};return e.forEach(t=>{Wn(o,t)&&(n[t]=o[t])}),n}var _e=Ee(Pe()),an=class{constructor(e){this.artist=e}prepareStave(e,n){if(!e)return[];let t=Z.Flow.Barline.type,s=t.SINGLE,r=n.map(a=>{let i=me(a);return i instanceof Z.Flow.BarNote&&i.getType()!==t.REPEAT_BEGIN?(s=i.getType(),a.slice(0,-1)):a});return e.setEndBarType(s),r}makeBeams(e,n,t,s,r){let a=n.options;if(r&&a["tab-stems"]!=="true")return[];let i;n.direction==="top"?i=1:n.direction==="bottom"?i=-1:t.voiceSettings.length>1?i=s===0?1:-1:r&&(i=a["tab-stem-direction"]==="down"?-1:1);for(let c of e)i&&c.setStemDirection&&c.setStemDirection(i);return a.beams==="off"?[]:a.beams==="explicit"?n.groups.map(([c,l])=>{let u=new _e.Beam(e.slice(c,l),i===void 0);return u.renderOptions.showStemlets=a["beam-stemlets"]==="true",u}):_e.Beam.generateBeams(e,{groups:t.beam_groups,stemDirection:i,beamRests:a["beam-rests"]==="true",showStemlets:a["beam-stemlets"]==="true",beamMiddleOnly:a["beam-middle-only"]==="true"})}alignTopAnnotations(e,n){let t=[];for(let r of e.getTickables())r.getModifiers().filter(i=>i instanceof _e.Annotation&&i.getVerticalJustification()===_e.Annotation.VerticalJustify.TOP).forEach((i,c)=>{i.setLayoutBaseline(void 0),(t[c]??=[]).push(i)});let s=n.getYForLine(-1);for(let r of t){for(let a of r)s=Math.min(s,a.computeY().y);for(let a of r)a.setLayoutBaseline(s);s-=Math.max(...r.map(a=>a.computeY().textHeight))}}alignTextBars(e,n){let t=[],s=new _e.Fraction(0,1);for(let i of n)i.shouldIgnoreTicks()?t.push(s.clone()):s.add(i.getTicks());if(!t.length)return e;let r=[];s=new _e.Fraction(0,1);let a=0;for(let i of e){for(;a<t.length&&!t[a].greaterThan(s)&&!(t[a++].equals(s)&&i.shouldIgnoreTicks());)r.push(new _e.TextNote({text:"",duration:"b",ignoreTicks:!0}));r.push(i),i.shouldIgnoreTicks()||s.add(i.getTicks())}return r}formatAndRender(e,n,t,s){let r=[],a=(P,B,D)=>P.flatMap((_,M)=>{if(!_.length)return[];_.forEach(K=>K.setStave(B));let V=new _e.Voice(n.meter).setMode(_e.Voice.Mode.SOFT).addTickables(_);return r.push(...this.makeBeams(_,n.voiceSettings[M],n,M,D)),[V]}),i=n.tab,c=n.note,l=a(t,i,!0),u=a(s,c,!1),f=c||i,m=f,w=n.text_voices.filter(P=>P.length).map(P=>{let B=this.alignTextBars(P,s[0]??t[0]??[]);return B.forEach(D=>D.setStave(m)),new _e.Voice(n.meter).setMode(_e.Voice.Mode.SOFT).addTickables(B)}),v=new _e.Formatter,x=[...l,...u,...w];for(let P of[l,u,w])P.length&&v.joinVoices(P);x.length&&v.formatToStave(x,f,{alignRests:u.length>1});for(let P of l)this.alignTopAnnotations(P,i),P.draw(e,i);for(let P of u)P.draw(e,c);for(let P of r)P.setContext(e).draw();for(let P of w)P.draw(e,m);return i&&c&&new Z.Flow.StaveConnector(c,i).setType(Z.Flow.StaveConnector.type.BRACKET).setContext(e).draw(),c?u:l}render(e){let n=this.artist;n.log("Render: ",n.options),n.closeBends(),e.resize(Number(n.customizations.width)*Number(n.customizations.scale),(n.last_y+n.options.bottom_spacing)*Number(n.customizations.scale));let t=e.getContext();t.setViewBox?t.setViewBox(0,0,Number(n.customizations.width),n.last_y+n.options.bottom_spacing):t.scale(Number(n.customizations.scale),Number(n.customizations.scale)),t.clear(),t.setFont(n.options.font_face,n.options.font_size,""),n.renderer_context=t,n.player_voices=[];let s=r=>{r.note&&n.notes.applyAccidentals(r);let a=this.prepareStave(r.tab,r.tab_voices),i=this.prepareStave(r.note,r.note_voices);if(r.tab&&r.note){let l=Math.max(r.tab.getNoteStartX(),r.note.getNoteStartX());r.tab.setNoteStartX(l),r.note.setNoteStartX(l)}r.tab&&r.tab.setContext(t).draw(),r.note&&r.note.setContext(t).draw();let c=this.formatAndRender(t,r,a,i);n.player_voices.push(c)};for(let r of n.staves){if(!r.color){s(r);continue}let a=t.getDefaultStyle();t.save();try{t.setDefaultStyle(ke(r.color)).setStrokeStyle(r.color).setFillStyle(r.color),s(r)}finally{t.setDefaultStyle(a),t.restore()}}n.log("Rendering tab articulations."),n.tab_articulations.forEach(r=>r.setContext(t).drawWithStyle()),n.log("Rendering note articulations."),n.stave_articulations.forEach(r=>r.setContext(t).drawWithStyle()),n.player&&(n.customizations.player==="true"?(n.player.setTempo(parseInt(String(n.customizations.tempo),10)),n.player.setInstrument(String(n.customizations.instrument)),n.player.render()):n.player.removeControls()),n.rendered=!0}};var Ce=Ee(Pe());var _i={left:Ce.Modifier.Position.LEFT,right:Ce.Modifier.Position.RIGHT,above:Ce.Modifier.Position.ABOVE,below:Ce.Modifier.Position.BELOW};function qn(o,e,n=!1,t=!1){let s=!t&&(e===Ce.Modifier.Position.LEFT||e===Ce.Modifier.Position.RIGHT),r=n?new Ce.StringNumber(o):new Ce.FretHandFinger(o,{headPlacement:s}).setDrawCircle(t&&/^\d$/.test(o));return r.setPosition(e),r}function Et(o,e,n,t,s=!1,r=!1){for(let a of n){let i=_i[a.position];if(a.finger!==void 0){if(t&&!s)continue;if((r||/^[pimac]$/.test(a.finger))&&(a.position==="above"||a.position==="below")){let c=a.position==="above"?Ce.Annotation.VerticalJustify.TOP:Ce.Annotation.VerticalJustify.BOTTOM;o.addModifier(new Ce.Annotation(a.finger).setFont(ze(),11).setVerticalJustification(c),e);continue}o.addModifier(qn(a.finger,i,a.stringNumber,t),e)}else o.addModifier(new Ce.Articulation(a.articulation??"a>").setPosition(i),e)}}function Un(o,e){return o?.find(n=>!n.finger||!/^\d$/.test(n.finger)||n.stringNumber?!1:n.position==="left"||n.position==="right"?!0:e.some(t=>t.marks?.some(s=>s!==n&&s.position===n.position&&/^\d$/.test(s.finger??"")&&!s.stringNumber)))}function Kn(o,e,n,t){switch(o){case"a":case"above":case"top":return"above";case"b":case"below":case"bottom":return"below";case"l":case"left":if(!e)return"left";break;case"r":case"right":if(!e)return"right";break}return n(e?"Place an accent above or below":"Place a fingering left, right, above or below",t)}function Ai(o,e,n,t,s){return o.slice(1,-1).split(",").map(r=>{let a=/^(?:f([0-5T])|(>))(?::([a-z]+))?$/.exec(r.trim());if(!a)return s("Expected a finger such as f2 or an accent > with optional placement",e);let[,i,,c]=a;return{...i&&{finger:i},position:c?Kn(c,!i,s,e):i?n:t}})}function Lr(o,e,n){let t="left",s="above";for(let r of o){if(r.element==="options")continue;let a=r.element==="voice",i=a?t:"left",c=a?s:"above";for(let l of r.options??[])l.key==="fingering"&&(i=Kn(l.value,!1,n,l.range??e(l._l,l._c))),l.key==="accents"&&(c=Kn(l.value,!0,n,l.range??e(l._l,l._c)));a||(t=i,s=c);for(let l of r.notes??[])for(let u of l.chord??[l])u.suffix&&(u.marks=Ai(u.suffix.text,u.suffix.range,i,c,n),delete u.suffix)}}var J=function(o,e,n={}){return o.forEach(t=>n[t]=e),n},Hr=[1,6],Dr=[1,7],zr=[1,8],jr=[1,9],Gr=[1,10],qt=[5,11,13,14,15,16],at=[5,11,13,14,15,16,18,20,22],Wr=[2,18],Xn=[1,15],ct=[5,11,13,14,15,16,18,20,22,24],qr=[1,19],Ur=[1,20],Kr=[1,21],Xr=[1,22],Yr=[1,46],Jr=[1,31],$r=[1,35],Zr=[1,36],cn=[1,42],Qr=[1,45],es=[1,44],Qe=[1,60],et=[1,61],tt=[1,62],Mt=[1,58],Tt=[1,53],Pt=[1,54],Nt=[1,55],_t=[1,56],At=[1,57],Rt=[1,59],ts=[1,47],ns=[1,48],rs=[1,49],ss=[1,50],nt=[1,63],is=[1,67],os=[1,68],as=[5,11,13,14,15,16,18,20,22,28],he=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],Yn=[2,94],Jn=[1,80],$n=[1,77],Zn=[1,78],Qn=[1,79],ln=[5,11,13,14,15,16,18,20,22,26,32,34,38,39,44,45,46,47,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],er=[1,83],cs=[1,88],ls=[1,89],us=[1,90],ds=[1,91],Ve=[50,68,70,72,73,74,75,76,77,78,79,80],bt=[32,47,57,58,59,87],Ct=[50,57,68,70,72,73,74,75,76,77,78,79,80,92],fs=[1,113],un=[34,45],dn=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,50,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],ms=[2,77],ps=[1,120],tr=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,70,72,73,74,75,76,77,81,82,84,86,87],fn=[5,11,13,14,15,16,18,20,22,26,32,38,39,44,46,47,57,58,59,68,70,71,72,73,74,75,76,77,81,82,84,86,87],hs=[28,82],nr=[50,57,68,70,72,73,74,75,76,77,78,79,80],Ri=(function(){return{yy:{},options:{},rules:[/^notes\b/,/^tabstave\b/,/^piano\b/,/^stave\b/,/^voice\b/,/^options\b/,/^text\b/,/^slur\b/,/^["][^"\r\n]*["]/,/^[^\s="][^\s=]*/,/^[$]/,/^[$]/,/^[^,$]+/,/^[!]/,/^[!]/,/^(?:([^!"\r\n]|["]([^"\\\r\n]|\\.)*["])+)/,/^[^!]+/,/^[^,\r\n]+/,/^\//,/^\+/,/^:/,/^=/,/^\(/,/^\)/,/^(?:\[([f]|[>])[^\]/\r\n]*\])/,/^\[/,/^\]/,/^\^/,/^,/,/^(?:\|)/,/^\./,/^#/,/^@/,/^(?:(kick|snare|hat))/,/^[b]/,/^[s]/,/^[h]/,/^[p]/,/^[t]/,/^[T]/,/^[-]/,/^[_]/,/^[v]/,/^[V]/,/^[u]/,/^[d]/,/^[<>]/,/^[0-9]+z[0-9]+(z[0-9]+)?/,/^[0-9]+/,/^[q]/,/^[w]/,/^[h]/,/^[d]/,/^[S]/,/^[A-GXLR]/,/^[n]/,/^[~]/,/^[\r\n]+/,/^[ \t]+/,/^$/,/^./],conditions:{notes:{rules:[10,13,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60],inclusive:!0},text:{rules:[17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,48,49,50,51,52,57,58,59,60],inclusive:!0},slur:{rules:[18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},annotations:{rules:[11,12,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},options:{rules:[8,9,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},command:{rules:[14,15,16,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0},INITIAL:{rules:[0,1,2,3,4,5,6,7,9,18,19,20,21,22,23,25,26,27,28,29,30,31,32,57,58,59,60],inclusive:!0}},performAction(e,n,t,s){let r=s;switch(t){case 0:{return this.begin("notes"),20;break}case 1:{return this.begin("options"),13;break}case 2:{return this.begin("options"),15;break}case 3:{return this.begin("options"),14;break}case 4:{return this.begin("options"),16;break}case 5:{return this.begin("options"),11;break}case 6:{return this.begin("text"),18;break}case 7:{return this.begin("options"),22;break}case 8:return 25;case 9:return 24;case 10:{return this.begin("annotations"),82;break}case 11:{return this.begin("notes"),82;break}case 12:return 24;case 13:{return this.begin("command"),84;break}case 14:{return this.begin("notes"),84;break}case 15:return 85;case 16:return 85;case 17:return 27;case 18:return 50;case 19:return"+";case 20:return 47;case 21:return 26;case 22:return 32;case 23:return 34;case 24:return 53;case 25:return 38;case 26:return 39;case 27:return 81;case 28:return 28;case 29:return 46;case 30:return 45;case 31:return 86;case 32:return 90;case 33:return 44;case 34:return 76;case 35:return 73;case 36:return 68;case 37:return 77;case 38:return 74;case 39:return 75;case 40:return 72;case 41:return 61;case 42:return 78;case 43:return 79;case 44:return 80;case 45:return 70;case 46:return 58;case 47:return 59;case 48:return 57;case 49:return 69;case 50:return 67;case 51:return 68;case 52:return 70;case 53:return 71;case 54:return 87;case 55:return 91;case 56:return 92;case 57:{this.begin("INITIAL");break}case 58:break;case 59:return 5;case 60:return"INVALID"}},setInput(e,n){return this.yy=n||this.yy||{},this._input=e,this._more=!1,this._backtrack=!1,this.done=!1,this.currentCondition="INITIAL",this.conditionStack=["INITIAL"],this.offset=0,this.yytext=this.match="",this.yyleng=0,this.yylineno=0,this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},parseError(e,n){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,n)},input(){let e=this._input[this.offset],n=/\r\n?|\n/g.test(e);return this.offset++,this.yyleng++,this.yytext=this.match=this.yytext+e,n?(this.yylineno++,this.yylloc.last_line++,this.yylloc.last_column=0):this.yylloc.last_column++,e},lineColumnForOffset(e=this.offset,n=this._input,t=1,s=0){let r=/\r\n?|\n/g,a=t,i=s,c=0,l;for(;(l=r.exec(n))!==null;)if(l.index<e)a++,i=0,c=l.index+l[0].length;else{i+=e-c,c=-1;break}return c!==-1&&(i+=e-c),{line:a,column:i}},setMatch(e,n){let t=this._input.slice(e,n),s=e!==this.offset?this.lineColumnForOffset(e):{line:this.yylloc.last_line,column:this.yylloc.last_column},r=e!==n?this.lineColumnForOffset(n-e,t,s.line,s.column):s;this.yytext=this.match=t,this.yyleng=n-e,this.offset=n,this.yylineno=r.line-1,this.yylloc={first_line:s.line,first_column:s.column,last_line:r.line,last_column:r.column}},less(e){let n=this.offset-this.match.length;this.setMatch(n,n+e)},unput(e){let n=this.match.length-e.length;if(!this.match.startsWith(e,n))throw new Error("Lexer#unput() should receive a part of matched text only");this.less(n)},more(){this._more=!0},reject(){throw new Error("reject() is allowed only when options.backtrack_lexer = true")},showPosition(e=this.offset-this.match.length){let n=this._input,t=Math.max(e-20,0),s=Math.min(e+20,n.length),r=(t===0?"":"...")+n.slice(t,e).replace(/\r\n?|\n/g,"\\n"),a=n.slice(e,s).replace(/\r\n?|\n/g,"\\n")+(s===n.length?"":"...");return r+a+`
|
|
365
365
|
${"-".repeat(r.length)}^`},test_match(e,n){let t;this._more=!1,this._backtrack=!1,this.setMatch(this.offset,this.offset+e[0].length),this.matches=e;let s=this.performAction.call(this,this.yy,this,n,this.conditionStack[this.conditionStack.length-1]);return!s&&this._backtrack?(Object.assign(this,t),!1):(this.eof()||(this.done=!1),typeof s=="number"&&this.yy.parser?this.yy.parser.terminals_[s]:s||!1)},eof(){return this.offset===this._input.length},next(){if(this.done)return 1;this.eof()&&(this.done=!0),this._more||(this.yytext="",this.match="");let e,n;for(let t of this.conditions[this.currentCondition].rules){let s=this.rules[t],r=this._input.slice(this.offset),a;if(typeof s=="function"){let i=s(r,this.currentCondition);switch(typeof i){case"string":a=[i];break;case"number":a=[r.slice(0,i)];break;default:a=i}}else a=r.match(s);if(a&&(!e||a[0].length>e[0].length)){e=a,n=t;break}}if(e)return this.test_match(e,n);if(this.eof())return 1;this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text.
|
|
366
|
-
`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex(){let e;for(;!e;)e=this.next();return e},begin(e){this.currentCondition=e,this.conditionStack.push(e)},pushState(e){this.begin(e)},popState(){return this.conditionStack.pop(),this.currentCondition=this.conditionStack.length?this.conditionStack[this.conditionStack.length-1]:"INITIAL"},topState(e){return e=this.conditionStack.length-1-Math.abs(e||0),e>=0?this.conditionStack[e]:"INITIAL"},stateStackSize(){return this.conditionStack.length}}})();function Qn(){this.yy={}}Qn.prototype={Parser:Qn,lexer:vi,symbols_:{error:2,e:3,maybe_vextab:4,EOF:5,vextab:6,stave:7,voice:8,maybe_options:9,stave_data:10,OPTIONS:11,options:12,TABSTAVE:13,STAVE:14,PIANO:15,VOICE:16,stave_additions:17,TEXT:18,text:19,NOTES:20,notes:21,SLUR:22,option_value:23,WORD:24,QUOTED_VALUE:25,"=":26,STR:27,",":28,lingo:29,line:30,drum:31,"(":32,drum_hits:33,")":34,chord:35,time:36,bar:37,"[":38,"]":39,tuplets:40,annotations:41,command:42,rest:43,DRUM:44,".":45,"|":46,":":47,frets:48,maybe_decorator:49,"/":50,string:51,maybe_head_marks:52,HEAD_MARKS:53,chord_line:54,articulation:55,fret:56,NUMBER:57,SLIDE_END:58,PREBEND:59,abc:60,_:61,timed_fret:62,time_values:63,maybe_dot:64,time_unit:65,maybe_slash:66,w:67,h:68,q:69,d:70,S:71,"-":72,s:73,t:74,T:75,b:76,p:77,v:78,V:79,u:80,"^":81,$:82,annotation_words:83,"!":84,COMMAND:85,"#":86,ABC:87,abc_accidental:88,accidental_type:89,"@":90,n:91,"~":92,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",11:"OPTIONS",13:"TABSTAVE",14:"STAVE",15:"PIANO",16:"VOICE",18:"TEXT",20:"NOTES",22:"SLUR",24:"WORD",25:"QUOTED_VALUE",26:"=",27:"STR",28:",",32:"(",34:")",38:"[",39:"]",44:"DRUM",45:".",46:"|",47:":",50:"/",53:"HEAD_MARKS",57:"NUMBER",58:"SLIDE_END",59:"PREBEND",61:"_",67:"w",68:"h",69:"q",70:"d",71:"S",72:"-",73:"s",74:"t",75:"T",76:"b",77:"p",78:"v",79:"V",80:"u",81:"^",82:"$",84:"!",85:"COMMAND",86:"#",87:"ABC",90:"@",91:"n",92:"~"},productions_:[0,[3,2],[4,0],[4,1],[6,1],[6,2],[7,3],[7,2],[7,2],[8,1],[8,1],[8,1],[8,1],[10,1],[10,2],[17,2],[17,2],[17,2],[9,0],[9,1],[23,1],[23,1],[12,3],[12,4],[19,1],[19,3],[21,1],[21,2],[29,1],[29,1],[29,3],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[31,1],[33,1],[33,3],[37,1],[37,3],[37,3],[37,3],[37,3],[37,3],[30,5],[52,1],[52,0],[54,1],[54,3],[35,4],[35,5],[56,1],[56,2],[56,2],[56,1],[48,1],[48,1],[48,4],[48,2],[48,4],[62,5],[62,1],[62,5],[62,8],[62,1],[62,4],[36,3],[63,2],[65,1],[65,1],[65,1],[65,1],[64,0],[64,1],[64,2],[66,0],[66,1],[51,1],[55,1],[55,1],[55,1],[55,1],[55,1],[55,1],[55,1],[49,1],[49,1],[49,1],[49,1],[49,0],[40,3],[40,5],[41,3],[83,1],[83,3],[42,3],[43,2],[43,3],[43,4],[60,3],[88,1],[88,2],[88,1],[88,2],[88,1],[88,0],[89,0],[89,1]],table:[{3:1,4:2,5:[2,2],6:3,7:4,8:5,11:Rr,13:Cr,14:Ir,15:Fr,16:Br},{1:[3]},{5:[1,11]},{5:[2,3],7:12,8:5,11:Rr,13:Cr,14:Ir,15:Fr,16:Br},$(Gt,[2,4]),$(at,Vr,{9:13,12:14,24:Wn}),{12:16,24:Wn},$(ct,[2,9]),$(ct,[2,10]),$(ct,[2,11]),$(ct,[2,12]),{1:[2,1]},$(Gt,[2,5]),$(Gt,[2,7],{10:17,17:18,18:Or,20:Lr,22:Hr}),$(at,[2,19],{24:Dr}),{26:[1,23]},$(Gt,[2,8],{24:Dr}),$(Gt,[2,6],{17:24,18:Or,20:Lr,22:Hr}),$(at,[2,13]),{19:25,27:[1,26]},{21:27,26:zr,29:28,30:29,31:30,32:jr,35:32,36:33,37:34,38:Gr,39:Wr,40:37,41:38,42:39,43:40,44:sn,46:qr,47:Ur,48:41,55:43,56:51,57:Ze,58:Qe,59:et,60:52,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt,81:Kr,82:Xr,84:Yr,86:Jr,87:tt},$(at,Vr,{12:14,9:64,24:Wn}),{26:[1,65]},{23:66,24:$r,25:Zr},$(at,[2,14]),$(at,[2,15],{28:[1,69]}),$(Qr,[2,24]),$(at,[2,16],{30:29,31:30,35:32,36:33,37:34,40:37,41:38,42:39,43:40,48:41,55:43,56:51,60:52,29:70,26:zr,32:jr,38:Gr,39:Wr,44:sn,46:qr,47:Ur,57:Ze,58:Qe,59:et,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt,81:Kr,82:Xr,84:Yr,86:Jr,87:tt}),$(he,[2,26]),$(he,[2,28]),$(he,[2,29]),{30:74,31:73,33:71,44:sn,48:41,54:72,55:75,56:51,57:Ze,58:Qe,59:et,60:52,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt,87:tt},$(he,[2,31]),$(he,[2,32]),$(he,[2,33]),$(he,[2,34]),$(he,[2,35]),$(he,[2,36]),$(he,[2,37]),$(he,[2,38]),$(he,[2,39]),$([50,68,72,73,74,75,76,77],qn,{49:76,70:Un,78:Kn,79:Xn,80:Yn}),$(on,[2,40]),{32:[1,81],47:Jn,56:84,57:Ze,58:Qe,59:et,60:85,62:82,87:tt},{57:es,63:86,65:87,67:ts,68:ns,69:rs},$(he,[2,43]),{46:[1,92],47:[1,93]},{57:[1,94]},{24:[1,96],83:95},{85:[1,97]},{57:[1,99],72:[1,100],86:[1,98]},$(Ve,[2,60]),$(Ve,[2,61],{57:[1,101]}),$(gt,[2,83]),$(gt,[2,84]),$(gt,[2,85]),$(gt,[2,86]),$(gt,[2,87]),$(gt,[2,88]),$(gt,[2,89]),$(Ve,[2,56],{58:[1,102]}),{57:[1,103]},$(Ve,[2,59]),$(Ct,[2,110],{88:104,86:[1,105],90:[1,106],91:[1,107]}),$(at,[2,17]),{23:108,24:$r,25:Zr},$(ct,[2,22]),$(ct,[2,20]),$(ct,[2,21]),{27:[1,109]},$(he,[2,27]),{34:[1,110],45:[1,111]},{34:[1,112],45:ss},$(an,[2,41]),$(an,[2,52]),{47:Jn,56:84,57:Ze,58:Qe,59:et,60:85,62:82,87:tt},{50:[1,114],55:115,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt},$(cn,[2,90]),$(cn,[2,91]),$(cn,[2,92]),$(cn,[2,93]),{30:74,48:41,54:116,55:75,56:51,57:Ze,58:Qe,59:et,60:52,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt,87:tt},$(Ve,[2,63]),{57:es,63:117,65:87,67:ts,68:ns,69:rs},$(Ve,[2,66]),$(Ve,[2,69],{57:[1,118]}),$(he,is,{64:119,70:os}),$($n,[2,80],{66:121,71:[1,122]}),$(ln,[2,73]),$(ln,[2,74]),$(ln,[2,75]),$(ln,[2,76]),{26:[1,124],46:[1,123],47:[1,125]},{46:[1,126],47:[1,127]},{28:[1,129],81:[1,128]},{28:[1,131],82:[1,130]},$(as,[2,98]),{84:[1,132]},$(he,[2,101]),{86:[1,133]},{57:[1,134]},{61:[1,135]},$(Ve,[2,58]),$(Ve,[2,57]),$(Zn,[2,111],{89:136,92:[1,137]}),$(Ct,[2,105],{86:[1,138]}),$(Ct,[2,107],{90:[1,139]}),$(Ct,[2,109]),$(ct,[2,23]),$(Qr,[2,25]),$(he,[2,30]),{31:140,44:sn},$(he,qn,{49:141,70:Un,78:Kn,79:Xn,80:Yn}),{30:142,48:41,55:75,56:51,57:Ze,58:Qe,59:et,60:52,68:Tt,72:Mt,73:Pt,74:_t,75:Nt,76:At,77:Rt,87:tt},{51:143,57:[1,144]},{47:Jn,56:84,57:Ze,58:Qe,59:et,60:85,62:145,87:tt},{34:[1,146],45:ss},{47:is,64:147,70:os},{61:[1,148]},$(he,[2,71]),$(he,[2,78],{70:[1,149]}),$($n,[2,72]),$($n,[2,81]),$(he,[2,44]),$(he,[2,45]),$(he,[2,47]),$(he,[2,46]),$(he,[2,48]),$(he,[2,95]),{57:[1,150]},$(he,[2,97]),{24:[1,151]},$(he,[2,100]),$(he,[2,102]),{86:[1,152]},{57:[1,153]},$(Zn,[2,104]),$(Zn,[2,112]),$(Ct,[2,106]),$(Ct,[2,108]),$(an,[2,42]),$(he,[2,54]),$(an,[2,53]),$(on,[2,51],{52:154,53:[1,155]}),$([5,11,13,14,15,16,18,20,22,26,32,34,38,39,44,45,46,47,53,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],[2,82]),$(Ve,[2,64]),$(he,qn,{49:156,70:Un,78:Kn,79:Xn,80:Yn}),{47:[1,157]},{57:[1,158]},$(he,[2,79]),{81:[1,159]},$(as,[2,99]),$(he,[2,103]),$(Ve,[2,62]),$(on,[2,49]),$(on,[2,50]),$(he,[2,55]),{56:160,57:Ze,58:Qe,59:et,60:161,87:tt},$(Ve,[2,70]),$(he,[2,96]),$(Ve,[2,65]),$(Ve,[2,67],{57:[1,162]}),{61:[1,163]},{57:[1,164]},$(Ve,[2,68])],defaultActions:{11:[2,1]},performAction(o,e,n,t,s,r,a){let i=r.length-1;switch(s){case 1:return r[i-1];case 2:case 18:case 51:case 94:this.$=null;break;case 3:case 13:case 19:case 28:case 31:case 32:case 52:case 73:case 74:case 75:case 76:case 82:this.$=r[i];break;case 4:t.locate&&(r[i].range=t.locate(a[i])),this.$=[r[i]];break;case 5:t.locate&&(r[i].range=t.locate(a[i])),this.$=[].concat(r[i-1],r[i]);break;case 6:this.$={element:r[i-2],options:r[i-1],notes:r[i].notes,text:r[i].text,...t.locate?{slurs:r[i].slurs}:{},_l:a[i-2].first_line,_c:a[i-2].first_column};break;case 7:this.$={element:r[i-1],options:r[i],_l:a[i-1].first_line,_c:a[i-1].first_column};break;case 8:this.$={element:"options",params:r[i],_l:a[i-1].first_line,_c:a[i-1].first_column};break;case 14:var l=[].concat(r[i-1].text,r[i].text),c=[].concat(r[i-1].notes,r[i].notes),u=[].concat(r[i-1].slurs,r[i].slurs);this.$={text:l,notes:c,slurs:u};break;case 15:t.locate&&(r[i][0].declaration=t.locate(this._$)),this.$={text:r[i],notes:[],slurs:[]};break;case 16:this.$={notes:r[i],text:[],slurs:[]};break;case 17:this.$={slurs:t.locate?[{range:t.locate(this._$)}]:r[i],notes:[],text:[]};break;case 21:this.$=r[i].slice(1,-1);break;case 22:this.$=[{key:r[i-2],value:r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i-2].first_line,_c:a[i-2].first_column}];break;case 23:this.$=[].concat(r[i-3],[{key:r[i-2],value:r[i],...t.locate?{range:t.locate({...a[i-2],last_line:a[i].last_line,last_column:a[i].last_column})}:{},_l:a[i-2].first_line,_c:a[i-2].first_column}]);break;case 24:this.$=[{text:r[i],...t.locate?{range:t.locate(a[i])}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 25:this.$=[].concat(r[i-2],{text:r[i],...t.locate?{range:t.locate(a[i])}:{},_l:a[i].first_line,_c:a[i].first_column});break;case 26:t.locate&&[].concat(r[i]).forEach(f=>f.range||=t.locate(a[i])),this.$=t.locate?[].concat(r[i]):r[i];break;case 27:t.locate&&[].concat(r[i]).forEach(f=>f.range||=t.locate(a[i])),this.$=[].concat(r[i-1],r[i]);break;case 29:this.$=[{drums:[r[i]],_l:a[i].first_line,_c:a[i].first_column}];break;case 30:this.$=[{drums:r[i-1],_l:a[i-2].first_line,_c:a[i-2].first_column}];break;case 33:this.$=[{command:"bar",type:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 34:this.$=[{command:"open_beam",_l:a[i].first_line,_c:a[i].first_column}];break;case 35:this.$=[{command:"close_beam",_l:a[i].first_line,_c:a[i].first_column}];break;case 36:this.$=[{command:"tuplet",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 37:this.$=[{command:"annotations",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 38:this.$=[{command:"command",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 39:this.$=[{command:"rest",params:r[i]}];break;case 40:this.$={id:r[i],...t.locate?{range:t.locate(a[i])}:{}};break;case 41:case 98:this.$=[r[i]];break;case 42:case 53:case 99:this.$=[].concat(r[i-2],r[i]);break;case 43:this.$="single";break;case 44:this.$="double";break;case 45:this.$="end";break;case 46:this.$="repeat-end";break;case 47:this.$="repeat-begin";break;case 48:this.$="repeat-both";break;case 49:$e(fe(r[i-4]),{decorator:r[i-3]}),tn(r[i-4],function(f){f.string=r[i-1]}),r[i]&&(fe(r[i-4]).suffix=r[i]),t.locate&&(fe(r[i-4]).range.end=t.locate(r[i]?a[i]:a[i-1]).end),this.$=r[i-4];break;case 50:this.$={text:r[i],range:t.markRange(a[i])};break;case 54:this.$=[{chord:r[i-2],decorator:r[i]}];break;case 55:this.$=[{chord:r[i-2],articulation:r[i-4],decorator:r[i]}];break;case 56:this.$={fret:r[i]};break;case 57:this.$={fret:r[i],openSlide:{edge:"in",side:r[i-1]===">"?"above":"below"}};break;case 58:this.$={fret:r[i-1],openSlide:{edge:"out",side:r[i]===">"?"above":"below"}};break;case 59:this.$=t.prebend(r[i],this._$);break;case 60:this.$=[{...r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 61:this.$=[{abc:r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 62:this.$=[{abc:r[i-3],...t.locate?{range:t.locate(this._$)}:{},octave:r[i-2],fret:r[i],_l:a[i-3].first_line,_c:a[i-3].first_column}];break;case 63:this.$=[$e(r[i],{articulation:r[i-1],...t.locate?{range:t.locate(this._$)}:{}})];break;case 64:$e(fe(r[i-3]),{decorator:r[i-2]}),t.locate&&r[i-2]&&(fe(r[i-3]).range.end=t.locate(a[i-2]).end),$e(r[i],{articulation:r[i-1]}),t.locate&&(r[i].range=t.locate({...a[i-1],last_line:a[i].last_line,last_column:a[i].last_column})),r[i-3].push(r[i]),this.$=r[i-3];break;case 65:this.$={time:r[i-3],dot:r[i-2],...r[i],_l:a[i-4].first_line,_c:a[i-4].first_column};break;case 66:this.$={...r[i],_l:a[i].first_line,_c:a[i].first_column};break;case 67:this.$={time:r[i-3],dot:r[i-2],abc:r[i]};break;case 68:this.$={time:r[i-6],dot:r[i-5],abc:r[i-3],octave:r[i-2],fret:r[i]};break;case 69:this.$={abc:r[i],_l:a[i].first_line,_c:a[i].first_column};break;case 70:this.$={abc:r[i-3],octave:r[i-2],fret:r[i],_l:a[i-3].first_line,_c:a[i-3].first_column};break;case 71:this.$={time:r[i-1],dot:r[i]};break;case 72:this.$=r[i-1]+r[i];break;case 77:this.$=!1;break;case 78:this.$=!0;break;case 79:this.$=2;break;case 80:this.$="";break;case 81:case 84:this.$="s";break;case 83:this.$="-";break;case 85:this.$="t";break;case 86:this.$="T";break;case 87:this.$="b";break;case 88:this.$="h";break;case 89:this.$="p";break;case 90:this.$="v";break;case 91:this.$="V";break;case 92:this.$="u";break;case 93:this.$="d";break;case 95:this.$={tuplet:r[i-1]};break;case 96:this.$={tuplet:r[i-3],notes:r[i-1]};break;case 97:case 100:this.$=r[i-1];break;case 101:this.$={position:0};break;case 102:this.$={position:r[i-1],explicit:!0};break;case 103:this.$={position:r[i-1]*-1};break;case 104:this.$={key:r[i-2],accidental:r[i-1],accidental_type:r[i]};break;case 105:this.$="#";break;case 106:this.$="##";break;case 107:this.$="b";break;case 108:this.$="bb";break;case 109:this.$="n";break;case 111:this.$=null;break;case 112:this.$="c";break}},trace(...o){this.DEBUG&&Jison.print(...o)},parseError(o,e){if(e.recoverable)this.trace(o);else{let n=new Error(o);throw n.hash=e,n}},parse(o,...e){let i=G=>{k.length-=2*G,S.length-=G,P.length-=G},l=()=>{let G=c.lex()||1;return typeof G!="number"&&(G=this.symbols_[G]||G),G},c=Object.create(this.lexer),u=c.options&&c.options.ranges,f={...this.yy,parser:this,lexer:c};c.setInput(o,f),typeof f.parseError=="function"&&(this.parseError=f.parseError),typeof c.yylloc>"u"&&(c.yylloc={});let p=this.table,h={},E=c.yylloc,k=[0],S=[null],P=[E],B=[],j="",A=0,T=0,V=0,U,Y;for(;;){let G=k[k.length-1],R;if(this.defaultActions[G]?R=this.defaultActions[G]:((U===null||typeof U>"u")&&(U=l()),R=p[G]&&p[G][U]),!R||!R[0]){let v=function(_){let O=k.length-1,W=0;for(;;){if("2"in p[_])return W;if(_===0||O<2)return!1;O-=2,_=k[O],++W}},M,q="";if(!V){let _=[];for(let O in p[G])O in this.terminals_&&O>2&&_.push("'"+this.terminals_[O]+"'");q=c.showPosition?"Parse error on line "+(A+1)+`:
|
|
367
|
-
`+
|
|
368
|
-
Expecting `+
|
|
369
|
-
`));if(l?.some(c=>c.element==="options"&&c.params.some(u=>u.key==="transpose"))){if(!e)return Wt(o,!0);ds(l,(c,u)=>{throw new oe("syntax",u,c.range)})}return l&&Ar(l,(c,u)=>t({first_line:c,last_line:c,first_column:u,last_column:u+1}),(c,u)=>{throw new oe("syntax",c,u)}),l}function tr(o,e){let n=o.measures.map(c=>c.number);if(!e)return n;let t=[...o.repeats??[]];for(let c of t){if(c.count!==void 0&&(!Number.isInteger(c.count)||c.count<2||c.count>32||c.endings.length))throw new oe("measure","Invalid counted repeat",o.measures[0].range);let u=c.bodyEnd;if(!Number.isInteger(c.first)||!Number.isInteger(u)||c.first<1||u<c.first||u>n.length)throw new oe("measure","Invalid repeat body",o.measures[0].range);for(let f of c.endings){if(f.first!==u+1||!Number.isInteger(f.last)||f.last<f.first||f.last>n.length)throw new oe("measure","Invalid repeat ending",o.measures[c.first-1].range);u=f.last}}let s=[],r=new Set(t.flatMap(c=>c.count?[c.bodyEnd]:c.endings.slice(0,-1).map(u=>u.last)));for(let c of o.measures){let u=c.voices[0];if(["repeat-begin","repeat-both"].includes(u.opening?.type)&&!t.some(f=>f.first===c.number)&&s.push(c.number),["repeat-end","repeat-both"].includes(u.closing?.type)&&!r.has(c.number)){let f=s.pop()??1;t.push({first:f,bodyEnd:c.number,endings:[],range:[c.range.start,c.range.end]})}}let a=c=>c.endings[c.endings.length-1]?.last??c.bodyEnd;t.sort((c,u)=>c.first-u.first||a(u)-a(c));let i=[];function l(c,u,f){for(let p=c;p<=u;p++){let h=f.find(k=>k.first===p&&a(k)<=u);if(!h){if(i.length>=16384)throw new oe("measure","Performed repeat exceeds 16384 bar visits",o.measures[p-1].range);i.push(p);continue}let E=f.filter(k=>k!==h);for(let k=0;k<(h.count??Math.max(2,h.endings.length));k++){l(p,h.bodyEnd,E);let S=h.endings[k];S&&l(S.first,S.last,E)}p=a(h)}}return l(1,n.length,t),i}function fs(o,e){let n=new Map,t=new Map;for(let s of o){let r=tr(s,e);if(n.set(s,r),r.length===s.measures.length)continue;let a=s.measures.map(l=>l.span).join(","),i=t.get(a);if(i&&(i.length!==r.length||i.some((l,c)=>l!==r[c])))throw new oe("measure","Parts disagree about the performed repeat order",s.measures[0].range);t.set(a,r)}if(t.size)for(let s of o){let r=t.get(s.measures.map(a=>a.span).join(","));r&&n.set(s,r)}return n}function ps(o,e,n,t){let s="cdefgab",[r,a]=o.split("/"),i=s.indexOf(r[0])+n,l=t.getAccidental(s[(i+7)%7]).note,c=Ie(l+"/"+(Number(a)+Math.floor(i/7)));return c===void 0?e:Math.max(0,Math.min(127,c+e-Ie(o)))}function ms(o,e,n,t=.25){if(!o.notes.length)return[o];let s=o.notes[0],r=e.heads.find(u=>u.sounding&&Ie(u.sounding)===s.pitch);if(!r)return[o];let a=[],i=o.time,l=o.duration;function c(u,f,p){let h=p/u.length;u.forEach((E,k)=>a.push({...o,time:f+k*h,duration:h,notes:(Array.isArray(E)?E:[E]).map(S=>({pitch:S,duration:h,velocity:s.velocity,...s.fixedVelocity&&{fixedVelocity:!0},program:s.program}))}))}if(e.grace){let u=s.pitch-Ie(r.written),f=e.grace.pitches.map(p=>(Array.isArray(p)?p:[p]).map(h=>Ie(h)+u).filter(h=>h>=0&&h<=127)).filter(p=>p.length);if(f.length){let p=e.grace.side==="before",E=(p&&!e.grace.steal?Math.min(l,...o.notes.map(S=>S.duration)):l)*t,k=p?i:i+l-E;c(f,k,E),l-=E,p&&(i+=E);for(let S of o.notes)p?S.duration=Math.max(0,S.duration-E):S.duration-=Math.min(E,Math.max(0,S.duration-(k-o.time)))}}if(e.ornament){let u=ps(r.written,s.pitch,1,n),f=ps(r.written,s.pitch,-1,n),p=s.pitch,E={tr:[p,u,p,u],mordent:[p,u],mordent_inverted:[p,f],turn:[u,p,f],turn_inverted:[f,p,u]}[e.ornament],k=Math.min(l,s.duration)/2;c(E,i,k),o.notes.length>1&&a.push({...o,time:i,duration:l,notes:o.notes.slice(1)}),s.duration=Math.max(0,s.duration-k),a.push({...o,time:i+k,duration:l-k,notes:[s]})}else a.push({...o,time:i,duration:l});return a}var mn=Ee(Pe());function hs(o,e,n){let t=Ie(o);if(t===void 0)return;let s={pitch:t,duration:e,velocity:100};return n&&(s.bend=[{time:e,semitones:-n}]),s}function Te(o,e){let[n,t]=o.split("/").map(Number);return n/t*e}function Ti(o,e,n){if(e.midi!==void 0&&!o.silent)return{pitch:e.midi,duration:n,velocity:100};if(!e.sounding||o.silent)return;let t=hs(e.sounding,n,e.prebend?.release&&e.prebend.semitones),s=e.bend??o.bend?.spec;if(!t||!s||s.string!==e.position?.str)return t;let r=i=>n*i[0]/i[1],a=[{time:r(s.rise),semitones:s.semitones}];return s.hold&&a.push({time:r(s.hold),semitones:s.semitones}),s.release&&a.push({time:r(s.release),semitones:0}),t.bend=a,t}var nr=class{constructor(){this.from=100;this.target=100;this.start=0;this.hasSounded=!1}at(e){let n=(e-this.start)*4,t=Math.max(0,1-n);return this.target+(this.from-this.target)*t*t}attack(e,n,t,s){if(n!==void 0&&(n!==this.target||!s)){let r=this.at(e);this.from=this.hasSounded&&s?(r+n)/2:n,this.target=n,this.start=e}return t&&(this.hasSounded=!0),Math.round(this.at(e))}};function Mi(o,e,n){let t=[],s=new Map;for(let E of o.playback?.tempoChanges??[]){let k=s.get(E.bar)??[];k.push({at:Te(E.at,1),bpm:E.bpm*e/(o.playback.tempo??120)}),s.set(E.bar,k)}let r=new Map,a=new Map,i=[],l={ppp:28,pp:40,p:52,mp:66,mf:82,f:98,ff:112,fff:124},c=new Set(n&&o.measures[0]?.state.piano?o.measures.flatMap(E=>E.voices.filter(k=>k.hand&&k.events.some(S=>S.dynamic)).map(k=>k.hand)):[]),u=new Map,f=new Set((o.spans??[]).flatMap(E=>E.kind==="crescendo"||E.kind==="diminuendo"?[E.from,E.to]:[])),p=e,h=0;for(let E of o.measures){let k=o.playback?.tempos?.[E.number];k&&(p=k*e/(o.playback.tempo??120)),t.push(p);let S=s.get(E.number);S&&(p=S[S.length-1].bpm);let P=E.voices.flatMap((B,j)=>B.events.map(A=>({attack:A,voice:j,onset:Te(A.onset,1)}))).sort((B,j)=>B.onset-j.onset||+!!j.attack.dynamic-+!!B.attack.dynamic);for(let{attack:B,voice:j,onset:A}of P){let T=c.size===2?E.voices[j].hand??"":"";u.has(T)||u.set(T,new nr);let V=u.get(T);r.set(B.id,V.attack(h+A,l[B.dynamic],!B.silent&&B.heads.length>0,n&&!f.has(B.id)));let U=i[j]??=[],Y={id:B.id,time:h+A,voice:j,explicit:!!B.dynamic,index:U.length};a.set(B.id,Y),U.push(Y)}h+=Te(E.span,1)}for(let E of o.spans??[]){if(E.kind!=="crescendo"&&E.kind!=="diminuendo")continue;let k=a.get(E.from),S=a.get(E.to);if(!k||!S||S.time<=k.time)continue;let P=E.kind==="crescendo",B=P&&E.niente?1:r.get(E.from),j=!P&&E.niente?1:S.explicit?r.get(E.to):Math.min(127,Math.max(1,B+(P?24:-24)));for(let A=k.index;A<=S.index;A++){let T=i[k.voice][A];r.set(T.id,Math.round(B+(j-B)*(T.time-k.time)/(S.time-k.time)))}}return{tempi:t,tempoChanges:s,velocities:r}}function Pi(o,e,n){if(!e.length)return;e.sort((r,a)=>r.start-a.start);let t=[];for(let r of e){let a=t[t.length-1];a&&r.start<a.end?a.end=Math.max(a.end,r.end):t.push(r)}let s=new Map;for(let r=o.length-1;r>=0;r--){let a=o[r];for(let i of a.notes){let l=a.time+i.duration,c=0,u=t.length;for(;c<u;){let p=c+u>>>1;t[p].end<=l?c=p+1:u=p}let f=t[c];if(n&&(f?.start<l||t[c-1]?.end===l)&&(i.holdRelease=!0),f&&f.start<l){let p=Math.min(f.end,s.get(i.pitch)??1/0);i.duration=Math.max(i.duration,p-a.time)}s.set(i.pitch,a.time)}}}function _i(o,e,n,t,s){let r=t(Te(o.span,1)),a=e/4,[i,l]=o.state.meter.split("/").map(Number),c=Math.max(0,i/l-Te(o.span,1))*4,u=Math.abs(c-Math.round(c))>1e-8?c%1*a:0,f=[];if(s!==void 0){let E=Te(o.span,1),k=0,S=(1-u/a)/4;for(;k<E-1e-12;){let P=Math.min(k+S,E);f.push({end:t(P),...P-k>=.25-1e-12&&{eighth:t(k+.125)}}),k=P,S=.25}}let p=[],h=!1;for(let E of o.voices)for(let k of E.events){let S=t(Te(k.onset,1)+Te(k.duration,1));k.heads.some(P=>P.marks?.some(B=>B.articulation?.startsWith("a@")))&&p.push(S),S>=r-1e-8&&n.has(k.id)&&(h=!0)}return{duration:r,quarter:a,beatOffset:u,...s!==void 0&&{beats:f,endingQuarter:s},swingable:l===2||l===4,fermatas:p,phraseEnd:h||!!p.length}}function gs(o){let e=o[0]??[];for(let n of o.slice(1)){let t=0,s=0,r=0;for(let a of n){let i=t,l=s,c=r+a.duration;for(;i<e.length&&l<c-1e-9;){let u=e[i],f=l+u.duration;a.swingable===!1&&(u.swingable=!1),a.phraseEnd&&Math.abs(c-f)<1e-8&&(u.phraseEnd=!0);for(let p of a.fermatas??[]){let h=r+p;h>l+1e-9&&h<=f+1e-9&&(u.fermatas=[...u.fermatas??[],h-l])}if(f>c+1e-9)break;l=f,i++}t=i,s=l,r=c}}return e}function bs(o,e,n,t=tr(o,!1),s,r){let a=[],i=new Map(o.ties.map(v=>[v.to+":"+v.toHead,v])),l=new Map,c=!!s&&!s.literal,u=!1,{tempi:f,tempoChanges:p,velocities:h}=Mi(o,e,c),E=new Set((o.spans??[]).filter(v=>v.kind==="slur").map(v=>v.to)),k=new Map((o.spans??[]).filter(v=>v.kind==="tremolo").map(v=>[v.from,v])),S=new Map((o.spans??[]).flatMap(v=>v.kind==="glissando"?[[v.to+":"+v.toHead,v]]:[])),P=new Map,B=new Map,j=(o.spans??[]).filter(v=>v.kind==="pedal"),A=new Map(j.map(v=>[v.from,v.to])),T=new Set(j.filter(v=>v.onset).map(v=>v.to)),V=new Map,U=[];function Y(v){for(let _ of V.values())U.push({start:_,end:v});V.clear()}let G=new Map((o.repeats??[]).flatMap(v=>v.endings.slice(1).map(_=>[_.first,v.bodyEnd]))),R=0,M=0;for(let v of t){let _=o.measures[v-1];if(v!==R+1){if(G.get(v)===R)for(let[Q,te]of l)(te.barNumber!==R||Math.abs(te.writtenEnd-M)>1e-8)&&l.delete(Q);else l.clear();Y(M)}else if(G.has(v)){let Q=G.get(v);for(let[te,de]of l)de.barNumber===Q&&l.delete(te)}R=v;let O=240/f[v-1],W=0,J=0,ae=O,L=[{start:W,timeAtStart:J,rate:ae}];for(let Q of p.get(v)??[])J+=(Q.at-W)*ae,W=Q.at,ae=240/Q.bpm,L.push({start:W,timeAtStart:J,rate:ae});let X=Q=>{let te=0,de=L.length;for(;te+1<de;){let C=te+de>>>1;L[C].start<=Q?te=C:de=C}let pe=L[te];return pe.timeAtStart+(Q-pe.start)*pe.rate},se=_.voices.flatMap(Q=>Q.events).map(Q=>({attack:Q,time:M+X(Te(Q.onset,1))}));se.sort((Q,te)=>Q.time-te.time),r&&Te(_.span,O)>0&&r.push(_i(_,O,E,X,L.length>1?ae/4:void 0));let ee=new Map;for(let{attack:Q,time:te}of se){let de=X(Te(Q.onset,1)+Te(Q.duration,1))-X(Te(Q.onset,1));A.has(Q.id)&&V.set(A.get(Q.id),te),V.has(Q.id)&&(U.push({start:V.get(Q.id),end:T.has(Q.id)?te:te+de}),V.delete(Q.id));let pe=[];if(Q.grace||Q.ornament){let C=Q.activeKey??_.state.key??"C";B.has(C)||B.set(C,new mn.KeyManager(C));let K;if(Q.grace?.steal){let ne=Te(Q.onset,1),H=Te(Q.duration,1),re=H*Te(Q.grace.steal,1),F=Q.grace.side==="before"?ne:ne+H-re;K=(X(F+re)-X(F))/de}P.set(Q.id,{attack:Q,key:B.get(C),graceShare:K})}Q.heads.forEach((C,K)=>{let ne=C.sustain?X(Te(Q.onset,1)+Te(C.sustain,1))-X(Te(Q.onset,1)):de,H=Q.id+":"+K,re=i.get(H),F=re&&l.get(re.from+":"+re.fromHead);if(F){if(c&&(F.note.holdRelease=!0),F.note.duration=Math.max(F.note.duration,te+ne-F.start),re.bend){let{semitones:b,hold:g,release:y}=re.bend;F.note.bend=[...F.note.bend??[],{time:te-F.start+ne*g[0]/g[1],semitones:b},{time:te-F.start+ne*y[0]/y[1],semitones:0}]}l.set(H,{...F,barNumber:v,writtenEnd:te+ne})}else{let b=Ti(Q,C,ne);if(b){let g=S.get(H),y=g&&l.get(g.from+":"+g.fromHead);y&&(y.note.bend=[...y.note.bend??[],{time:te-y.start,semitones:b.pitch-y.note.pitch}]),b.velocity=h.get(Q.id),c&&C.marks&&(C.marks.some(I=>I.articulation==="a>"||!I.articulation&&!I.finger&&!I.stringNumber)&&(b.velocity=Math.min(127,b.velocity+10)),!b.bend&&!Q.grace&&!Q.ornament&&C.marks.some(I=>I.articulation==="a.")&&(b.duration*=.58)),C.velocity!==void 0&&(b.velocity=C.velocity,b.fixedVelocity=!0,C.velocity===0&&(u=!0)),o.program!==void 0&&(b.program=o.program),pe.push(b),l.set(H,{note:b,start:te,barNumber:v,writtenEnd:te+ne})}}}),ee.set(Q.id,{time:te,duration:de,source:Q.id,notes:pe,mark:n&&(()=>n(Q.id))})}for(let[Q,te]of ee){let de=k.get(Q);if(de?.kind!=="tremolo"){a.push(te);continue}let pe=ee.get(de.to),C=te.duration+pe.duration,K=O/2**(2+de.strokes);for(let ne=0;ne*K<C-1e-9;ne++){let H=ne%2?pe:te,re=Math.min(K,C-ne*K);a.push({...H,time:te.time+ne*K,duration:re,notes:H.notes.map(F=>({...F,duration:re}))})}ee.delete(de.to)}M+=X(Te(_.span,1))}let q=P.size?a.flatMap(v=>{let _=P.get(String(v.source));if(!_)return[v];let O=_.attack.grace,W=_.graceShare??(O&&s?.graceFraction(v.time,v.duration,O.pitches.length,O.slash));return ms(v,_.attack,_.key,W)}):a;if(u)for(let v of q)v.notes=v.notes.filter(_=>_.velocity!==0);return q.sort((v,_)=>v.time-_.time),Y(M),Pi(q,U,c),{events:q,duration:M}}function ys(o,e){let n=[],t=240/(e*mn.default.RESOLUTION),s=new Map,r=0;for(let a of o.getPlayerData().voices){let i=0;for(let l of a){let c=0;for(let u of l.getTickables()){if(u.shouldIgnoreTicks())continue;let f=u.getTicks().value(),p=f*t,h=[];if(!u.isRest()){let E=nt.get(u)??(u.getPlayNote?.()??[]).map(S=>({key:S})),k=new Map;E.forEach((S,P)=>{let B=hs(S.key,p,S.release);if(!B)return;let j=pn.get(u)?.get(P),A=j&&s.get(j.glyph)?.get(j.index);A&&A.pitch===B.pitch?(A.duration+=p,k.set(P,A)):(h.push(B),k.set(P,B))}),s.set(u,k)}n.push({time:(r+c)*t,duration:p,source:u,notes:h}),c+=f}i=Math.max(i,c)}r+=i}return{events:n.sort((a,i)=>a.time-i.time),duration:r*t}}var nt=new WeakMap,pn=new WeakMap;function xs(o,e){let n=pn.get(o)?.get(e);return n&&nt.get(n.glyph)?.[n.index]}function rr(o,e,n,t){if(!o||!e)return;let s=pn.get(e)??new Map;t.forEach((r,a)=>s.set(r,{glyph:o,index:n[a]})),pn.set(e,s)}var hn=class{constructor(e){this.artist=e}makeBend(e,n){let t=Z.Flow.Bend.UP,s="";if(parseInt(e,10)>parseInt(n,10))t=Z.Flow.Bend.DOWN;else switch(Math.abs(parseInt(n,10)-parseInt(e,10))){case 1:s="1/2";break;case 2:s="Full";break;case 3:s="1 1/2";break;default:s=`Bend to ${n}`;break}return{type:t,text:s}}openBends(e,n,t,s){this.artist.log("openBends",e,n,t,s);let r=fe(this.artist.staves).tab_notes,a=e,i=t;De(this.artist.current_bends)?(this.artist.bend_start_index=r.indexOf(e),this.artist.bend_start_strings=t):(a=r[this.artist.bend_start_index],i=this.artist.bend_start_strings);let l=a.getPositions(),c=n.getPositions();i.forEach((u,f)=>{let p=s[f],h=l[u],E=c[p];this.artist.current_bends[u]||(this.artist.current_bends[u]=[]),this.artist.current_bends[u].push(this.makeBend(h.fret,E.fret))})}closeBends(e=1){if(this.artist.bend_start_index==null)return;this.artist.log(`closeBends(${e})`);let n=fe(this.artist.staves).tab_notes;Pr(this.artist.current_bends,(t,s)=>{let r=[];t.forEach(l=>r.push(l));let a=Z.Flow.Bend.length<=1?new Z.Flow.Bend(r):new Z.Flow.Bend(null,null,r),i=parseInt(String(s),10);n[this.artist.bend_start_index].addModifier(a,i)}),n.slice(this.artist.bend_start_index+1,n.length-2+e+1).forEach(t=>t.setGhost(!0)),this.artist.current_bends={},this.artist.bend_start_index=null}makeTuplets(e,n){this.artist.log("makeTuplets",e,n);let t=Number(n??e),s=Number(e),r=fe(this.artist.staves);if(!Number.isSafeInteger(t)||t<1||!Number.isSafeInteger(s)||s<1)throw new Z.RERR("ArtistError","Tuplet counts must be positive integers");let a=fn(s,r.meter),i=(l,c,u)=>{let f=l.slice(-t);if(f.length!==t||f.some(h=>h instanceof Z.Flow.BarNote))throw new Z.RERR("ArtistError","Not enough notes for tuplet in this bar and voice");let p=new Z.Flow.Tuplet(f,{numNotes:s,notesOccupied:a});c&&u.push(p)};r.note&&i(r.note_notes,!0,this.artist.stave_articulations),i(r.tab_notes,!!r.tab&&this.artist.customizations["tab-stems"]==="true",this.artist.tab_articulations)}getFingering(e){return e.match(/^\.fingering\/([^.]+)\./)}makeFingering(e){let n=this.getFingering(e),t=Z.Flow.Modifier.Position,s=[],r=[];if(n)n[1].split(/-/).forEach(i=>s.push(i.trim()));else return null;let a=()=>new Z.RERR("ArtistError",`Bad fingering: ${n[1]}`);return s.forEach(i=>{let l=i.match(/(\d+):([ablr]):([fs]):([^-.]+)/);if(!l)throw a();let c=parseInt(l[1],10)-1,u=t.RIGHT;switch(l[2]){case"l":u=t.LEFT;break;case"r":u=t.RIGHT;break;case"a":u=t.ABOVE;break;case"b":u=t.BELOW;break;default:break}let f=zn(l[4],u,l[3]==="s");r.push({num:c,modifier:f})}),r}getStrokeParts(e){return e.match(/^\.stroke\/([^.]+)\./)}makeStroke(e){let n=this.getStrokeParts(e),t=Z.Flow.Stroke.Type;if(!n)return null;switch(n[1]){case"bu":return new Z.Flow.Stroke(t.BRUSH_UP);case"bd":return new Z.Flow.Stroke(t.BRUSH_DOWN);case"ru":return new Z.Flow.Stroke(t.ROLL_UP);case"rd":return new Z.Flow.Stroke(t.ROLL_DOWN);case"qu":return new Z.Flow.Stroke(t.RASQUEDO_UP);case"qd":return new Z.Flow.Stroke(t.RASQUEDO_DOWN);default:throw new Z.RERR("ArtistError",`Invalid stroke type: ${n[1]}`)}}getScoreArticulationParts(e){return e.match(/^\.(a[^/]*)\/(t|b)[^.]*\./)}makeScoreArticulation(e){let n=this.getScoreArticulationParts(e);if(!n)return null;let t=n[1],s=n[2],r=Z.Flow.Modifier.Position,a=s==="t"?r.ABOVE:r.BELOW;return new Z.Flow.Articulation(t).setPosition(a)}makeAnnotation(e){let n=this.artist.customizations["font-face"],t=this.artist.customizations["font-size"],s=this.artist.customizations["font-style"],r=this.artist.customizations["annotation-position"],a=Z.Flow.Annotation.VerticalJustify,i=r==="top"?a.TOP:a.BOTTOM,l=(u,f=i)=>new Z.Flow.Annotation(u).setFont(n,t,s).setVerticalJustification(f),c=e.match(/^\.([^-]*)-([^-]*)-([^.-]*)(?:-([^.]*))?\.(.*)/);if(c){n=c[1],t=c[2],s=c[3];let[,,,,u,f]=c;if(u!==void 0&&!Be(u))throw new Z.RERR("ArtistError",`Invalid annotation color '${u}'`);if(!f)return null;let p=l(f);return u?p.setStyle(ke(u)):p}if(c=e.match(/^\.([^.]*)\.(.*)/),c){let u=i,f=c[1],p=c[2];switch(f){case"big":s="bold",t="14";break;case"italic":case"italics":s="italic";break;case"medium":t="12";break;case"top":u=a.TOP,this.artist.customizations["annotation-position"]="top";break;case"bottom":u=a.BOTTOM,this.artist.customizations["annotation-position"]="bottom";break;default:break}return p?l(p,u):null}return l(e)}formatOverrideFretText(e){if(!e)return null;let n=Z.Flow?.unicode??{},t=n.sharp??"#",s=n.flat??"b",r=n.natural??"n",a=e.match(/^([A-G])([#@n]{1,2})?(~?)(\d+)?(?:_(\d+)\/(\d+))?$/);if(a&&(a[4]||a[6])){let l=a[1],c=a[2]??"",u=a[4]??"",f=a[6],p=(()=>{switch(c){case"##":return`${t}${t}`;case"#":return t;case"@@":return`${s}${s}`;case"@":return s;case"n":return r;default:return""}})();return{text:`${l}${p}${u}`,string:f}}let i=e.match(/^(\d+)\/(\d+)$/);return i?{text:i[1],string:i[2]}:null}applyFretOverride(e,n){if(!e||!n||!e.fretElement||!e.positions)return;let t=0;if(n.string){let c=parseInt(n.string,10);if(!Number.isNaN(c)){let u=-1;e.positions.forEach((f,p)=>{parseInt(f.str,10)===c&&u<0&&(u=p)}),t=u>=0?u:0}}let s=e.fretElement[t];if(!s)return;s.setText(n.text);let r=this.artist.customizations["font-face"],a=this.artist.customizations["font-size"],i=this.artist.customizations["font-style"];r&&s.setFont(r,a,i);let l=0;e.fretElement.forEach(c=>{l=Math.max(l,c.getWidth())}),e.setWidth(l)}addAnnotations(e){let n=fe(this.artist.staves),t=n.note_notes,s=n.tab_notes;if(e.length>s.length)throw new Z.RERR("ArtistError","More annotations than note elements");n.tab?s.slice(s.length-e.length).forEach((r,a)=>{if(this.getScoreArticulationParts(e[a])){let i=this.makeScoreArticulation(e[a]);r.addModifier(i,0)}else if(this.getStrokeParts(e[a])){let i=this.makeStroke(e[a]);r.addModifier(i,0)}else{let i=e[a],l=this.formatOverrideFretText(i);if(l)this.applyFretOverride(r,l);else{let c=this.makeAnnotation(i);c&&r.addModifier(c,0)}}}):t.slice(t.length-e.length).forEach((r,a)=>{if(!this.getScoreArticulationParts(e[a])){let i=this.makeAnnotation(e[a]);i&&(typeof r.addAnnotation=="function"?r.addAnnotation(0,i):typeof r.addModifier=="function"&&r.addModifier(i,0))}}),n.note&&t.slice(t.length-e.length).forEach((r,a)=>{let i=this.makeScoreArticulation(e[a]);i&&(typeof r.addArticulation=="function"?r.addArticulation(0,i):typeof r.addModifier=="function"&&r.addModifier(i,0));let l=this.makeStroke(e[a]);l&&r.addStroke(0,l);let c=this.makeFingering(e[a]);if(c)try{c.forEach(u=>r.addModifier(u.modifier,u.num))}catch{throw new Z.RERR("ArtistError",`Bad note number in fingering: ${e[a]}`)}})}addTabArticulation(e,n,t,s,r){if(this.artist.log("addTabArticulations: ",e,n,t,s,r),e==="T"&&rr(n,t,s,r),e==="t"&&t.addModifier(new Z.Flow.Annotation("T").setVerticalJustification(Z.Flow.Annotation.VerticalJustify.BOTTOM)),De(s)&&De(r))return;let a=null,i={first_note:n,last_note:t,first_indices:s,last_indices:r,firstNote:n,lastNote:t,firstIndexes:s,lastIndexes:r};if(e==="s"&&(a=new Z.Flow.TabSlide(i)),(e==="h"||e==="p")&&(a=new Z.Flow.TabTie(i,e.toUpperCase())),(e==="T"||e==="t")&&(a=new Z.Flow.TabTie(i," ")),e==="b"&&this.openBends(n,t,s,r),a){let l=fe(this.artist.staves)?.color;l&&a.setStyle(ke(l)),this.artist.tab_articulations.push(a)}}addStaveArticulation(e,n,t,s,r){this.artist.log("addStaveArticulations: ",e,n,t,s,r);let a=null;if(e==="T"&&rr(n,t,s,r),["b","s","h","p","t","T"].includes(e)&&(a=new Z.Flow.StaveTie({first_note:n,last_note:t,first_indices:s,last_indices:r,firstNote:n,lastNote:t,firstIndexes:s,lastIndexes:r})),a){let i=fe(this.artist.staves)?.color;i&&a.setStyle(ke(i)),this.artist.stave_articulations.push(a)}}getPreviousNoteIndex(){let e=fe(this.artist.staves).tab_notes,n=2;for(;n<=e.length;){let t=e[e.length-n];if(t instanceof Z.Flow.TabNote)return e.length-n;if(!(t instanceof Z.Flow.BarNote))break;n+=1}return-1}addDecorator(e){if(this.artist.log("addDecorator: ",e),!e)return;let n=fe(this.artist.staves),t=n.tab_notes,s=n.note_notes,r=null,a=null;e==="v"&&(r=new Z.Flow.Vibrato),e==="V"&&(r=new Z.Flow.Vibrato,typeof r.setHarsh=="function"&&r.setHarsh(!0)),e==="u"&&(r=new Z.Flow.Articulation("a|").setPosition(Z.Flow.Modifier.Position.BELOW),a=new Z.Flow.Articulation("a|").setPosition(Z.Flow.Modifier.Position.BELOW)),e==="d"&&(r=new Z.Flow.Articulation("am").setPosition(Z.Flow.Modifier.Position.BELOW),a=new Z.Flow.Articulation("am").setPosition(Z.Flow.Modifier.Position.BELOW));let i=fe(t);if(i&&r&&i.addModifier(r,0),a){let l=fe(s);l&&(typeof l.addArticulation=="function"?l.addArticulation(0,a):typeof l.addModifier=="function"&&l.addModifier(a,0))}}addArticulations(e){this.artist.log("addArticulations: ",e);let n=fe(this.artist.staves),t=n.tab_notes,s=n.note_notes;if(De(t)||De(e)){this.closeBends(0);return}let r=fe(t),a=!1;["b","s","h","p","t","T","v","V"].forEach(i=>{let l=e.map((h,E)=>h&&h===i?E:-1).filter(h=>h>=0);if(De(l))return;i==="b"&&(a=!0);let c=this.getPreviousNoteIndex(),u=null,f=null,p=[];if(c===-1)u=null,f=null;else{u=t[c];let h=u.getPositions();f=[];for(let E of l){let k=r.getPositions()[E];if(!k)continue;let S=k.fret==="X"&&i==="T",P=h.findIndex((B,j)=>{if(f.includes(j))return!1;if(S){let A=n.note?s[c].getKeys():u.getPlayNote(),T=n.note?fe(s).getKeys():r.getPlayNote();return B.fret==="X"&&A[j]===T[E]}return B.str===k.str});P>=0&&(f.push(P),p.push(E))}}n.tab&&this.addTabArticulation(i,u,r,f||[],p),n.note&&p.length&&this.addStaveArticulation(i,s[c],fe(s),f||[],p)}),a||this.closeBends(0)}};var Ge=Ee(Pe());var vs=Ee(Pe()),lt=new vs.PercussionMap;function gn(o,e,n,t){if(o!=="percussion"||e)return"Use stave clef=percussion for drum hits";if(new Set(n).size!==n.length)return"A drum hit can contain each instrument only once";if(t)return"Use an ordinary duration for drum hits"}var bn=Ee(Pe()),yn=10,ws=5;function Vt(o,e){let n=o.side==="above"?"higher":"lower";return"Slide "+(o.edge==="in"?"in from "+o.side:"out toward a "+n+" fret")+" on string "+e}function Ni(o,e,n){return{x:o+(n.edge==="in"?-yn:yn),y:e+(n.side==="above"?-ws:ws)}}var xn=class extends bn.Modifier{constructor(n){super();this.slide=n;this.setPosition(n.edge==="in"?bn.Modifier.Position.LEFT:bn.Modifier.Position.RIGHT)}static get CATEGORY(){return"OpenSlide"}draw(){let n=this.checkContext(),t=this.checkAttachedNote().getModifierStartXY(this.getPosition(),this.checkIndex()),s=Ni(t.x,t.y,this.slide);n.openGroup("open-slide",this.getAttribute("id")),n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(s.x,s.y),n.stroke(),n.closeGroup(),this.setRendered()}};function vn(o,e,n){let t=new xn(n);o.getModifiers().some(r=>r instanceof xn&&r.getPosition()===t.getPosition())||(n.edge==="in"?o.setLeftDisplacedHeadPx(o.getLeftDisplacedHeadPx()+yn+2):o.setRightDisplacedHeadPx(o.getRightDisplacedHeadPx()+yn+2)),o.addModifier(t,e)}var wn=class{constructor(e){this.signs=new WeakMap;this.artist=e}getNoteForFret(e,n){return Bt(this.artist.tuning,this.artist.key_manager,this.artist.music_api,e,n)}getNoteForABC(e,n){let t=e.key,s=n,r=e.accidental;return e.accidental_type&&(r=`${r||"n"}_${e.accidental_type}`),[t,s,r]}addStaveNote(e){let n={is_rest:!1,play_note:null,...e},t=fe(this.artist.staves).note_notes,s=new Z.Flow.StaveNote({keys:n.spec,duration:this.artist.current_duration,type:this.artist.current_head,clef:this.artist.current_clef,autoStem:!0});this.signs.set(s,n.signs),this.attachDots(s),n.play_note&&s.setPlayNote(n.play_note),t.push(s)}applyAccidentals(e){let n={};for(let[a,i]of Object.entries(new Ge.Music().createScaleMap(e.key)))n[a]=i.slice(1)||"n";let t=new Ge.WrittenAccidentalState(n),s=new Map;for(let a of e.note_voices){let i=new Ge.Fraction(0,1);for(let l of a){let c=i.clone().simplify().toString(),u=s.get(c);u||(u={at:i.clone(),bar:!1,notes:[]},s.set(c,u)),l instanceof Z.Flow.BarNote?u.bar=!0:(this.signs.has(l)&&u.notes.push(l),i.add(l.getTicks()))}}let r=new Map;for(let a of[...s.values()].sort((i,l)=>i.at.value()-l.at.value())){a.bar&&(t.reset(),r.clear());let i=new Map;for(let l of a.notes)nt.get(l)?.forEach((c,u)=>{if(!c.inherit)return;let f=c.inherit.written[0],p=r.get(c.inherit.written)??n[f],h=xs(l,u);if(c.key=h?.key??f+(p==="n"?"":p)+c.key.slice(c.key.indexOf("/")),Ie(c.key)===void 0)throw new oe("syntax","Transposed note is outside the playable MIDI range",c.inherit.range)}),this.signs.get(l).forEach((c,u)=>{if(!c)return;let f=i.get(c.key)??[];f.push({head:c,note:l,index:u}),i.set(c.key,f)});for(let[l,c]of i){let u=c[0].head.sign,f=c.some(h=>h.head.sign!==u);r.set(l,u);let p=t.sign(l,f?"ambiguous":u)!==void 0;for(let{head:h,note:E,index:k}of c)this.updateSign(E,k,h,p||f)}}}updateSign(e,n,t,s){let r=t.cautionary&&(t.literal||!s),a=t.literal||s||r;if(t.mark&&(!a||t.mark.isCautionary()!==r)){let i=e.getModifiers(),l=i.indexOf(t.mark);l>=0&&i.splice(l,1),delete t.mark}a&&!t.mark&&(t.mark=new Ge.Accidental(t.sign),r&&t.mark.setAsCautionary(),e.addModifier(t.mark,n))}addTabNote(e,n=null){let t=fe(this.artist.staves).tab_notes;this.artist.stavesBuilder.reserveTabRhythmSpace();let s=new Z.Flow.TabNote({positions:e.map(({str:r,fret:a})=>({str:r,fret:a})),duration:this.artist.current_duration},this.artist.customizations["tab-stems"]==="true");n&&s.setPlayNote(n),e.forEach(({prebend:r,openSlide:a},i)=>{a&&vn(s,i,a),r&&s.addModifier(un(r),i)}),t.push(s),this.attachDots(s)}attachDots(e){for(let n=0;n<this.artist.current_dots;n++)Z.Flow.Dot.buildAndAttach([e],e instanceof Z.Flow.TabNote?{index:0}:{all:!0})}setDuration(e,n=!1){let t=/^(\d+|[whq])(s?)(d*)$/i.exec(e.trim());if(!t)throw new Z.RERR("ArtistError",`Invalid duration '${e}'`);let s=Number(n)||t[3].length;this.artist.current_dots=s,this.artist.current_head=t[2]?"s":"n",this.artist.current_duration=t[1]+"d".repeat(s)}addDrums(e){let n=fe(this.artist.staves),t=this.artist.current_duration,s=new Ge.StaveNote(lt.note(e,t));this.attachDots(s),n.note_notes.push(s),n.tab_notes.push(new Z.Flow.GhostNote(t)),nt.set(s,[])}addRest(e){this.artist.closeBends();let n=fe(this.artist.staves);this.artist.stavesBuilder.reserveTabRhythmSpace();let t=e.explicit||Number(e.position)!==0,s=r=>{let a=new Ge.StaveNote({keys:["r/4"],duration:this.artist.current_duration,type:"r"});if(a.setStave(r),t){let i=Number(e.position),l=r.getNumLines(),c=6-l,u=2*l-1,f=c+(i-1)/2;i<=0&&(f=c-1+i/2),i>=u&&(f=6+(i-u)/2),a.setRestLine(f)}return this.attachDots(a),a};n.note&&n.note_notes.push(s(n.note)),n.tab_notes.push(n.tab&&this.artist.customizations["tab-stems"]==="true"?s(n.tab):new Z.Flow.GhostNote(this.artist.current_duration))}addChord(e,n,t){if(De(e))return;this.artist.log("addChord: ",e);let s=fe(this.artist.staves),r=[],a=[],i=[],l=[],c=[],u=[],f=[],p=[],h=0,E=e[0].string,k=0;if(e.forEach(S=>{h+=1,(S.abc||S.string!==E)&&(k=0,E=S.string),r[k]||(r[k]=[],a[k]=[],i[k]=[],l[k]=[],f[k]=[],c[k]=[],u[k]=null);let P=null,B=null,j=null,A=null,T,V,U;if(S.abc){let v=S.octave?S.octave:S.string;[P,B,j]=this.getNoteForABC(S.abc,v);let _=j?j.split("_")[0]:"";if(A=`${P}${_}`,S.abc.transposed&&!j&&!S.fret&&(U={written:P.toLowerCase()+"/"+B,range:S.abc.transposed},A=this.artist.music_api.createScaleMap(s.key)[P.toLowerCase()].replace(/n$/,"")),S.fret&&S.abc.transposed){let[O,W]=this.artist.tuning.getNoteForFret(Number(S.fret)+s.capo,S.string).split("/");V=O+"/"+(Number(W)-1+this.artist.current_octave_shift)}S.fret||(S.fret="X")}else if(S.fret){let v=String(Number(S.fret)+s.capo+(S.prebend?.semitones??0));[P,B,j]=this.getNoteForFret(v,S.string);let[_,O]=this.artist.tuning.getNoteForFret(v,S.string).split("/");A=_,T=Number(O)-1}else throw new Z.RERR("ArtistError","No note specified");let Y=parseInt(String(B),10)+this.artist.current_octave_shift,G=S.time?{time:S.time,dot:S.dot}:null,R=j?.split("_")[0],M=S.abc&&R&&R!=="n"?P+R:P;r[k].push(`${M}/${B}`);let q=(T??Number(B))+this.artist.current_octave_shift;a[k].push(`${A}/${Y}`),i[k].push(V??`${A}/${q}`),l[k].push(R&&/^[a-g]/i.test(P)?{key:`${P[0].toLowerCase()}/${B}`,sign:R,literal:!!S.abc,cautionary:S.abc?S.abc.accidental_type==="c":this.artist.customizations.accidentals==="cautionary"&&R!=="n"}:null),f[k].push({fret:S.fret,str:S.string,prebend:S.prebend,openSlide:S.openSlide,marks:S.marks,inherit:U}),S.articulation?c[k].push(S.articulation):c[k].push(null),p[k]=G,S.decorator&&(u[k]=S.decorator),k+=1}),r.forEach((S,P)=>{if(p[P]&&this.setDuration(p[P].time,p[P].dot),this.addTabNote(f[P],a[P]),s.note&&(this.addStaveNote({spec:S,signs:l[P],play_note:a[P]}),!s.tab)){let j=f[P].filter(A=>A.prebend).map(A=>Ft(A.prebend,A.str));for(let A of f[P])A.openSlide&&j.push(Vt(A.openSlide,A.str));if(j.length){let A=new Z.Flow.Annotation(j.join(" \xB7 "));A.setVerticalJustification(Z.Flow.Annotation.VerticalJustify.TOP),fe(s.note_notes).addModifier(A,0)}}f[P].forEach((j,A)=>{j.marks&&(s.tab&&Et(fe(s.tab_notes),A,j.marks,!0),s.note&&Et(fe(s.note_notes),A,j.marks,!1))});let B=i[P].map((j,A)=>{let T=f[P][A].prebend;return{key:j,release:T?.release?T.semitones:0,inherit:f[P][A].inherit}});nt.set(fe(s.tab_notes),B),s.note&&nt.set(fe(s.note_notes),B),this.artist.addArticulations(c[P]),u[P]&&this.artist.addDecorator(u[P])}),n){let S=[];for(let P=0;P<h;P+=1)S.push(n);this.artist.addArticulations(S)}t&&this.artist.addDecorator(t)}addNote(e){this.addChord([e],null,null)}};var Ot=Ee(Pe());function sr(o){let e=o;e==="C"&&(e="4/4"),e==="C|"&&(e="2/2");let n=/^(?:\((\d+(?:\+\d+)+)\)|(\d+(?:\+\d+)+))\/(\d+)$/.exec(e),t;if(n){let s=(n[1]||n[2]).split("+").map(Number),r=Number(n[3]);if(s.includes(0))throw new Error("Empty beat group");t=s.map(a=>new Ot.Fraction(a,r)),e=s.reduce((a,i)=>a+i,0)+"/"+r}return new Ot.Voice(e),{meter:e,groups:t??Ot.Beam.getDefaultBeamGroups(e)}}var kn=class{constructor(e){this.artist=e}addBar(e){this.artist.log("addBar: ",e),this.artist.closeBends(),this.artist.key_manager.reset();let n=fe(this.artist.staves),t=Z.Flow.Barline.type,s=t.SINGLE;switch(e){case"single":s=t.SINGLE;break;case"double":s=t.DOUBLE;break;case"end":s=t.END;break;case"repeat-begin":s=t.REPEAT_BEGIN;break;case"repeat-end":s=t.REPEAT_END;break;case"repeat-both":s=t.REPEAT_BOTH;break;default:s=t.SINGLE;break}let r=new Z.Flow.BarNote().setType(s);n.tab_notes.push(r),n.note&&n.note_notes.push(new Z.Flow.BarNote().setType(s))}reserveTabRhythmSpace(){let e=fe(this.artist.staves);!e.tab||e.tabRhythmSpace||this.artist.customizations["tab-stems"]!=="true"||(e.tabRhythmSpace=(e.note?3:2)*e.tab.getSpacingBetweenLines(),e.tab.setY(e.tab.getY()+e.tabRhythmSpace),this.artist.last_y+=e.tabRhythmSpace)}addVoice(e={}){this.artist.closeBends();let n=fe(this.artist.staves);if(!n){this.addStave("stave",e);return}n.tab_notes.length?(n.tab_notes=[],n.note_notes=[],n.tab_voices.push(n.tab_notes),n.note_voices.push(n.note_notes),n.voiceSettings.push({options:{...this.artist.customizations},direction:e.voice,groups:[]})):Object.assign(fe(n.voiceSettings),{direction:e.voice,options:{...this.artist.customizations}})}addStave(e,n){let t={tuning:"standard",clef:"treble",key:"C",notation:e==="tabstave"?"false":"true",tablature:e==="stave"?"false":"true",strings:6};$e(t,n),this.artist.log("addStave: ",e,t);let s=null,r=null,a=this.artist.x+Number(this.artist.customizations["connector-space"]),i=40;t.notation==="true"&&(r=new Z.Flow.Stave(a,this.artist.last_y,Number(this.artist.customizations.width)-20,{leftBar:!1}),t.color&&r.setDefaultLedgerLineStyle(ke(t.color)),t.clef!=="none"&&r.addClef(t.clef),r.addKeySignature(t.key),t.time&&t["show-time"]!=="false"&&r.addTimeSignature(t.time),this.artist.last_y+=r.getHeight()+this.artist.options.note_stave_lower_spacing+parseInt(String(this.artist.customizations["stave-distance"]),10),i=r.getNoteStartX(),this.artist.current_clef=t.clef==="none"?"treble":t.clef),t.tablature==="true"&&(s=new Z.Flow.TabStave(a,this.artist.last_y,Number(this.artist.customizations.width)-20,{leftBar:!1}).setNumLines(t.strings),t.clef!=="none"&&s.addTabGlyph(),s.setNoteStartX(i),this.artist.last_y+=s.getHeight()+this.artist.options.tab_stave_lower_spacing),this.artist.closeBends();let{meter:l,groups:c}=sr(t.time||"4/4"),u=[],f=[];this.artist.staves.push({tab:s,note:r,tab_voices:[u],note_voices:[f],tab_notes:u,note_notes:f,meter:l,key:t.key,capo:Number(t.capo??0),color:t.color,tabRhythmSpace:0,voiceSettings:[{options:{...this.artist.customizations},direction:t.voice,groups:[]}],text_voices:[],beam_groups:c}),this.artist.tuning.setTuning(t.tuning),this.artist.key_manager.setKey(t.key)}};var Sn=class{constructor(e){this.artist=e}addTextVoice(){this.color=void 0,fe(this.artist.staves).text_voices.push([])}setTextFont(e){if(!e)return;let n=e.match(/^([^-]*)-([^-]*)-([^-]*)(?:-(.*))?$/);if(n){if(n[4]!==void 0&&!Be(n[4]))throw new Z.RERR("ArtistError",`Invalid text color '${n[4]}'`);this.color=n[4],this.artist.customizations["font-face"]=n[1],this.artist.customizations["font-size"]=parseInt(n[2],10),this.artist.customizations["font-style"]=n[3]}}addTextNote(e,n=0,t="center",s=!0,r=!1){let a=fe(this.artist.staves).text_voices;if(De(a))throw new Z.RERR("ArtistError","Can't add text note without text voice");let i=this.artist.customizations["font-face"],l=this.artist.customizations["font-size"],c=this.artist.customizations["font-style"],u=Z.Flow.TextNote.Justification.CENTER;switch(t){case"center":u=Z.Flow.TextNote.Justification.CENTER;break;case"left":u=Z.Flow.TextNote.Justification.LEFT;break;case"right":u=Z.Flow.TextNote.Justification.RIGHT;break;default:u=Z.Flow.TextNote.Justification.CENTER;break}let f=r?"b":this.artist.current_duration,p={text:e,duration:f,smooth:s,ignoreTicks:r,font:{family:i,size:l,weight:c}};e.startsWith("#")&&(p.glyph=e.slice(1),p.text="",p.font=null);let h=new Z.Flow.TextNote(p).setLine(n).setJustification(u);this.color&&h.setStyle(ke(this.color)),fe(a).push(h)}};var qe=class o{constructor(e,n,t,s){this.customizations={};this.staves=[];this.tab_articulations=[];this.stave_articulations=[];this.player_voices=[];this.last_y=0;this.current_duration="q";this.current_dots=0;this.current_head="n";this.current_clef="treble";this.current_bends={};this.current_octave_shift=0;this.bend_start_index=null;this.bend_start_strings=null;this.rendered=!1;this.renderer_context=null;this.player=null;this.x=e,this.y=n,this.width=t,this.options={font_face:Hn,font_size:10,font_style:null,bottom_spacing:30,tab_stave_lower_spacing:10,note_stave_lower_spacing:0,scale:1},s&&$e(this.options,s),this.renderer=new rn(this),this.articulations=new hn(this),this.notes=new wn(this),this.stavesBuilder=new kn(this),this.text=new Sn(this),this.reset()}static{this.DEBUG=!1}static{this.NOLOGO=!0}log(...e){o.DEBUG&&console&&console.log("(Vex.Flow.Artist)",...e)}reset(){this.tuning=new Z.Flow.Tuning,this.key_manager=new Z.Flow.KeyManager("C"),this.music_api=new Z.Flow.Music,this.customizations={"font-size":this.options.font_size,"font-face":this.options.font_face,"font-style":this.options.font_style,"annotation-position":"bottom",scale:this.options.scale,width:this.width,"stave-distance":0,space:0,player:"false",tempo:120,instrument:"acoustic_grand_piano",accidentals:"standard","tab-stems":"false","tab-stem-direction":"up",beams:"auto","beam-rests":"true","beam-stemlets":"true","beam-middle-only":"false","connector-space":5},this.staves=[],this.tab_articulations=[],this.stave_articulations=[],this.player_voices=[],this.last_y=this.y,this.current_duration="q",this.current_dots=0,this.current_head="n",this.current_clef="treble",this.current_bends={},this.current_octave_shift=0,this.bend_start_index=null,this.bend_start_strings=null,this.rendered=!1,this.renderer_context=null}attachPlayer(e){this.player=e}setOptions(e,n=(t,s)=>new Z.RERR("ArtistError",s)){this.log("setOptions: ",e);let t=Nr(this.customizations);if(Object.entries(e).forEach(([s,r])=>{if(!t.includes(s))throw n(s,`Invalid option '${s}'`);if(["width","scale","font-size","tempo","space","stave-distance","connector-space"].includes(s)){let a=Number(r),i=["width","scale","font-size","tempo"].includes(s);if(!Number.isFinite(a)||String(r).trim()===""||i&&a<=0)throw n(s,`Invalid numeric value for '${s}': ${r}`)}if(s==="accidentals"&&!["standard","cautionary"].includes(r))throw n(s,"accidentals must be standard or cautionary");if(s==="beams"&&!["auto","off","explicit"].includes(r))throw n(s,"beams must be auto, explicit or off")}),Object.assign(this.customizations,e),this.rendered&&e.width!==void 0)for(let s of this.staves)s.note?.setWidth(Number(e.width)-20),s.tab?.setWidth(Number(e.width)-20);this.last_y+=Number(e.space??0),e.player==="true"&&(this.last_y+=15)}getPlayerData(){return{voices:this.player_voices,context:this.renderer_context,scale:Number(this.customizations.scale)}}render(e){this.renderer.render(e)}draw(e){this.render(e)}isRendered(){return this.rendered}isLogoHidden(){return!0}setDuration(e,n=!1){this.notes.setDuration(e,n)}addBar(e){this.stavesBuilder.addBar(e)}makeTuplets(e,n){this.articulations.makeTuplets(e,n)}addAnnotations(e){this.articulations.addAnnotations(e)}addArticulations(e){this.articulations.addArticulations(e)}addDecorator(e){this.articulations.addDecorator(e||null)}addRest(e){this.notes.addRest(e)}addChord(e,n,t){this.notes.addChord(e,n||null,t||null)}addNote(e){this.notes.addNote(e)}addTextVoice(){this.text.addTextVoice()}setTextFont(e){this.text.setTextFont(e)}addTextNote(e,n=0,t="center",s=!0,r=!1){this.text.addTextNote(e,n,t,s,r)}addVoice(e){this.stavesBuilder.addVoice(e||{})}addStave(e,n){this.stavesBuilder.addStave(e,n)}openBends(e,n,t,s){this.articulations.openBends(e,n,t,s)}closeBends(e=1){this.articulations.closeBends(e)}runCommand(e,n=0,t=0){this.log("runCommand: ",e);let s=e.split(/\s+/);switch(s[0]){case"color":{if(s.length!==2||!Be(s[1]))throw new Z.RERR("ArtistError",`Expected a CSS color name or hex value at line ${n} column ${t}`);let r=fe(this.staves),a=r&&fe(r.note_notes),i=r&&fe(r.tab_notes);if(!a&&!i||(a||i)instanceof Z.Flow.BarNote)throw new Z.RERR("ArtistError",`Put !color! after a note or rest at line ${n} column ${t}`);a?.setStyle(ke(s[1])),a?.setLedgerLineStyle?.(ke(s[1])),i?.setStyle(ke(s[1]));break}case"octave-shift":if(s.length!==2||!/^[+-]?\d+$/.test(s[1])||!Number.isSafeInteger(Number(s[1])))throw new Z.RERR("ArtistError",`Invalid octave shift at line ${n} column ${t}`);this.current_octave_shift=Number(s[1]),this.log("Octave shift: ",this.current_octave_shift);break;default:throw new Z.RERR("ArtistError",`Invalid command '${s[0]}' at line ${n} column ${t}`)}}};function ir(o,e,n,t,s,r,a=!1){(e>=n||!a&&o[e].bar!==o[n].bar)&&r("syntax","Beam short notes within one bar",t,s);for(let i=e;i<=n;i++){let[l,c]=o[i].writtenDuration.split("/").map(Number);l*4>=c&&r("syntax","Beam short notes with written values shorter than a quarter",t,s),a&&!o[i].heads.length&&r("syntax","A continuous beam requires pitched attacks",t,s)}}function ks(o,e){let n=new Map,t=!1,s;function r(a,i,l,c){if(!s){s=new Uint8Array(o.events.length);let u=new Map(o.events.map((f,p)=>[f.id,p]));for(let f of o.spans)(f.kind==="beam"||f.kind==="feather"||f.kind==="continuousBeam")&&s.fill(1,u.get(f.first),u.get(f.last)+1)}for(let u=a;u<=i;u++)s[u]&&e("syntax","A note may belong to only one beam",l.range,c),s[u]=1}o.events.forEach((a,i)=>{for(let l of a.marks){if(l.kind!=="spanEndpoint")continue;let c=l.span+"-"+l.name;if(l.edge==="start"){n.has(c)&&e("syntax","Duplicate span start "+l.name,l.range,a.trace),l.span==="beam"&&t&&e("syntax","A note may belong to only one beam",l.range,a.trace),n.set(c,{mark:l,index:i}),l.span==="beam"&&(t=!0);continue}let u=n.get(c);(!u||i===u.index)&&e("syntax","Expected an earlier start for "+l.name,l.range,a.trace),n.delete(c);let f=o.events[u.index].id,p=a.id,h=l.name,E=u.mark.range;if(l.span==="hairpin")o.spans.push({kind:u.mark.hairpin,first:f,last:p,range:E,name:h,niente:u.mark.niente});else{if(l.span==="beam"){let k=o.events[u.index].bar!==a.bar;if(ir(o.events,u.index,i,l.range,a.trace,e,k),r(u.index,i,l,a.trace),t=!1,k){o.spans.push({kind:"continuousBeam",first:f,last:p,range:E,name:h});continue}}o.spans.push({kind:l.span,first:f,last:p,range:E,name:h,side:u.mark.side,strings:[]})}}});for(let{mark:a,index:i}of n.values())e("syntax","Missing end for "+a.name,a.range,o.events[i].trace)}var Ai=new Map([...["velocity","sustain","gliss","release","stem","dynamic","sharedStem","onStaff","pedal","ossia","grace","ornament","lyric","symbol","frame","line","ink","write","prebend","bend","text"].map(o=>[o,o]),["diagram","frame"],["slideIn","open slide"],["slideOut","open slide"],["showSign","accidental"],["courtesy","accidental"],["hammer","connection"],["pull","connection"],["slide","connection"]]);function qt(o){if(o.length<2)return;let e=new Set;for(let n of o){let t=n.kind==="pedal"&&"action"in n?"pedal "+n.action:n.kind==="lyric"&&"verse"in n?"verse "+n.verse:n.kind==="harmony"?"symbol":Ai.get(n.kind);if(t){if(e.has(t))return{reason:"Only one "+t+" may be written here",range:n.range};e.add(t)}}}function or(o){return o==="auto"||o==="mini"||o==="large"}function ar(o){return/^(top|bottom)-(left|center|right)$/.test(o)}function En(o={}){let{visibility:e="hover",position:n="bottom-center",inset:t=12,size:s="large"}=o;if(e!=="hover"&&e!=="always"&&e!=="off")throw new RangeError("Control visibility must be off, hover or always");if(!or(s))throw new RangeError("Control size must be auto, mini or large");if(!ar(n))throw new RangeError("Unknown playback control position: "+n);if(!Number.isFinite(t)||t<0)throw new RangeError("Control inset must be a nonnegative number");return{visibility:e,position:n,inset:t,size:s}}var Ut={human:{chordSpread:.008,rubato:.006,drift:.004,swell:1,touch:2,swing:0,beatAccent:.5,pocket:0,grace:.21},bach:{chordSpread:.007,rubato:.021,drift:.014,swell:3,touch:3,swing:0,beatAccent:7,pocket:0,grace:.14},chopin:{chordSpread:.016,rubato:.105,drift:.035,swell:9,touch:5,swing:0,beatAccent:1,pocket:0,grace:.22},ragtime:{chordSpread:.008,rubato:.006,drift:.008,swell:2,touch:3,swing:0,beatAccent:-3,pocket:0,grace:.13},blues:{chordSpread:.014,rubato:.024,drift:.018,swell:4,touch:5,swing:.9,beatAccent:-2,pocket:.055,grace:.16},parker:{chordSpread:.013,rubato:.012,drift:.015,swell:3,touch:5,swing:1,beatAccent:-5,pocket:.032,grace:.11},robot:{chordSpread:0,rubato:0,drift:0,swell:0,touch:0,swing:0,beatAccent:0,pocket:0,grace:.25}};function yt(o){return Object.prototype.hasOwnProperty.call(Ut,o)}var Oe=Object.freeze({bytes:65536,tokens:8192,depth:24,repetitions:32,events:4096,heads:16,steps:32768,fraction:2147483647}),Ri=Object.freeze({...Oe,bytes:1048576,tokens:131072,events:32768,steps:524288});function Ss(o="default"){if(o==="default")return Oe;if(o==="large")return Ri;throw new RangeError("Expected score capacity default or large")}function Ps(o,e,n){(o.length>n.bytes||new TextEncoder().encode(o).length>n.bytes)&&e("source-limit","Score exceeds "+n.bytes/1024+" KiB",[0,0]);let t=[];function s(l,c){t.length===n.tokens&&e("token-limit","Score exceeds "+n.tokens+" input tokens",c),t.push({text:l,range:c})}let r=/[^\r\n]*/y,a=/\/\/[^\r\n]*|"(?:\\.|[^"\\\r\n])*"|"|[{}()[\],|]|(?:\/(?!\/)|[^/"\s{}()[\],|])+/gu,i;for(;i=a.exec(o);){if(i[0].startsWith("//"))continue;let l=i[0];if(l.startsWith("#")&&t[t.length-1]?.text!=="ink"){r.lastIndex=i.index,r.exec(o),a.lastIndex=r.lastIndex;continue}if(/^(?:(?:x|0|[1-9]\d?)-)+(?:x|0|[1-9]\d?)\/[1-8]$/.test(l)){let[c,u]=l.split("/"),f=i.index;for(let p of c.split("-")){let h=f+p.length;s(p+"/"+u,[f,h===i.index+c.length?a.lastIndex:h]),f=h+1}}else s(l,[i.index,a.lastIndex])}return t.push({text:"",range:[o.length,o.length]}),t}function Ci(o,e,n,t){let s=[e.range[0]+1];for(let a=1;a<e.text.length-1;)e.text[a]!=="\\"?a++:a+=e.text[a+1]==="u"?6:2,s.push(e.range[0]+a);let r=([a,i])=>[s[a],s[i]];return Ps(o,(a,i,l)=>n(a,i,r(l)),t).map(a=>({text:a.text,range:r(a.range)}))}var Es=/^:(w|h|q|1|2|4|8|16|32|64|128|256)(\.{0,2})$/,Tn=/^[A-G](?:bb|##|b|#|n)?[0-9]$/,Ts=/^(x|0|[1-9]\d?)\/([1-8])$/,Ii=new Set(["velocity","sustain","hammer","tie","pull","slide","courtesy","slash","accent","frame","diagram","line","ink","label","tap","vibrato","brush","roll","stroke","rasgueado","symbol","write","staccato","fermata","stem","dynamic","harmony","onStaff","sharedStem","pedal","ossia","grace","ornament","verse","gliss","release","articulation","lyric","bend","prebend","finger"]),Ms=["kick","snare","hat"];function Fi(o){return o==="guitar"||o==="piano"||o==="drums"||o==="staff"}function _s(o,e,n=Oe){let t=new Set(Ms),s=new Map,r=Ps(o,e,n),a=0,i=0,l=()=>r[Math.min(a,r.length-1)].text,c=()=>{let b=r[a];return b.text||u("Unexpected end of score",b),a++,b},u=(b,g=r[Math.min(a,r.length-1)])=>e("syntax",b,g.range);function f(b){return l()!==b&&u("Expected "+b),c()}function p(){return/^[a-z][a-z0-9_]*$/.test(l())||u("Expected a lowercase name"),c().text}function h(b){let g=f("{");++i>Oe.depth&&e("depth-limit","Too many nested blocks",g.range);let y=b();return f("}"),i--,y}let E=new Map,k=[],S={},P,B,j,A=[],T=[],V,U,Y;function G(b){let g=b.range;if(b.text==="common")return{value:"4/4",sign:"C",range:g};if(b.text==="cut")return{value:"2/2",sign:"C|",range:g};let y=/^(\d{1,2}(?:\+\d{1,2})*)\/(1|2|4|8|16|32|64)$/.exec(b.text);y||u("Expected a meter such as 4/4",b);let I=y[1].split("+").map(Number),D=I.reduce((x,d)=>x+d,0);return(D>32||I.includes(0))&&u("Expected one through 32 beats",b),{value:D+"/"+y[2],...I.length>1&&{sign:b.text},range:g}}function R(b,g){let y=G(g),I=1;if(l()==="at"){c();let D=c();(!/^[1-9]\d{0,3}$/.test(D.text)||Number(D.text)<2)&&u("Expected a bar number starting at 2",D),I=Number(D.text)}b[I]&&u("Meter already declared for bar "+I,g),b[I]=y}function M(){let b=c();return["tr","turn","turn_inverted","mordent","mordent_inverted"].includes(b.text)||u("Unknown ornament",b),b.text}function q(b){return["spanEndpoint","stem","dynamic","harmony","onStaff","sharedStem","pedal","ossia","grace","ornament","slash","line","accent","symbol","lyric","frame","diagram","ink","label","tap","vibrato","stroke","brush","roll","rasgueado"].includes(b.kind)}function v(){let b=c();if(!b.text.startsWith('"'))return u("Expected quoted text",b);try{return JSON.parse(b.text)}catch{return u("Invalid quoted text",b)}}function _(b){let g={range:b.range,settings:{},anchors:[],cues:[]};l()==="part"?(c(),g.part=p()):l()==="conductor"&&(c(),g.conductor=!0),T.some(D=>D.part===g.part&&D.conductor===g.conductor)&&u("Duplicate edition for this target",b);function y(){let D=c();return/^\d{1,3}(?:\.\d{1,3})?$/.test(D.text)||u("Expected millimeters",D),Number(D.text)}function I(){let D=c();return/^[1-9]\d{0,3}$/.test(D.text)||u("Expected a positive measure number",D),Number(D.text)}h(()=>{for(;l()!=="}";){let D=c(),x=D.text;if(Object.prototype.hasOwnProperty.call(g.settings,x)&&u("Duplicate edition setting",D),x==="paper"){let d=c();d.text!=="A4"&&d.text!=="Letter"&&u("Expected A4 or Letter",d),g.settings.paper=d.text}else if(x==="margins")g.settings.margins={top:y(),right:y(),bottom:y(),left:y()};else if(x==="staffSize")g.settings.staffSize=y(),g.settings.staffSize||u("Expected a positive staff size",D);else if(x==="title"||x==="subtitle"||x==="header"||x==="footer")g.settings[x]=v();else if(x==="pageNumbers"||x==="compressRests"){let d=c();d.text!=="on"&&d.text!=="off"&&u("Expected on or off",d),g.settings[x]=d.text==="on"}else if(x==="system"||x==="page"||x==="prefer"||x==="forbid"){f(x==="system"||x==="page"?"at":"after");let d=I();g.anchors.push({field:{system:"systemBreaks",page:"pageBreaks",prefer:"preferredTurns",forbid:"forbiddenTurns"}[x],measure:d,range:[D.range[0],r[a-1].range[1]]})}else if(x==="cue"){g.part||u("Declare a cue in a player edition",D);let d=p();f("at");let m=I(),w=v();w.trim()||u("Expected a cue label",D),g.cues.push({part:d,measure:m,label:w,range:[D.range[0],r[a-1].range[1]]})}else u("Unknown edition setting",D)}}),g.range=[b.range[0],r[a-1].range[1]],T.push(g)}function O(b){let g=b?{id:b}:{};for(;l()==="name"||l()==="shortName"||l()==="sounds"&&r[a+2]?.text!=="at";){let y=c();if(Object.prototype.hasOwnProperty.call(g,y.text)&&u("Duplicate instrument field",y),y.text==="sounds"){let I=c();(!/^[+-]?\d{1,3}$/.test(I.text)||Math.abs(Number(I.text))>127)&&u("Expected a sounding interval from -127 to +127 semitones",I),g.sounds=Number(I.text)}else g[y.text]=v()}return g}function W(b){let{name:g,...y}=b;return{...y,...g!==void 0&&{displayName:g}}}function J(){let b={};for(;["above","below","font","size","style","ink"].includes(l());){let g=c();if(g.text==="above"||g.text==="below")b.position=g.text;else if(g.text==="font")b.family=v();else{let y=c();g.text==="ink"?b.ink=y.text:g.text==="size"?((!/^\d{1,2}$/.test(y.text)||Number(y.text)<1)&&u("Expected a positive font size",y),b.size=Number(y.text)):(y.text!=="italic"&&y.text!=="normal"&&y.text!=="bold"&&u("Expected a font style",y),b.style=y.text)}}return b}function ae(b,g,y=!1){let I=/^([1-9]\d{0,9})\/([1-9]\d{0,9})$/.exec(g);I||u("Expected a positive fraction",b);let[D,x]=I.slice(1).map(Number);(D>Oe.fraction||x>Oe.fraction)&&u("Timing fraction exceeds precision limit",b),y&&D>=x&&u("Grace share must be smaller than one",b);let d=D,m=x;for(;m;)[d,m]=[m,d%m];return D/d+"/"+x/d}function L(){let b=c();if(b.text==="hammer"||b.text==="tie"||b.text==="pull"||b.text==="slide"||b.text==="courtesy"||b.text==="showSign")return{kind:b.text,range:b.range};let g=()=>[b.range[0],r[a-1].range[1]];if(b.text==="slash")return{kind:"slash",range:b.range};if(b.text==="accent")return l()==="above"||l()==="below"?{kind:"sign",code:"a>",position:c().text,range:g()}:{kind:"accent",range:g()};if(b.text==="tieStart"||b.text==="tieEnd"){let x=p(),d=b.text==="tieStart"&&(l()==="above"||l()==="below")?c().text:void 0;return{kind:b.text,name:x,...d&&{side:d},range:g()}}if(b.text==="velocity"){let x=c();return(!/^(?:0|[1-9]\d{0,2})$/.test(x.text)||Number(x.text)>127)&&u("Expected an integer MIDI velocity from 0 to 127",x),{kind:"velocity",value:Number(x.text),range:g()}}if(b.text==="sustain"){let x=c();return{kind:"sustain",duration:ae(x,x.text),range:g()}}if(["slurStart","slurEnd","beamStart","beamEnd","crescendoStart","diminuendoStart","hairpinEnd"].includes(b.text)){let x=p(),d=b.text.startsWith("slur")?"slur":b.text.startsWith("beam")?"beam":"hairpin",m=b.text.endsWith("Start")?"start":"end",w=b.text==="crescendoStart"?"crescendo":b.text==="diminuendoStart"?"diminuendo":void 0,N=b.text==="slurStart"&&(l()==="above"||l()==="below")?c().text:void 0,z=!!w&&l()==="niente";return z&&c(),{kind:"spanEndpoint",name:x,span:d,edge:m,hairpin:w,side:N,niente:z,range:g()}}if(b.text==="frame"||b.text==="diagram"){f("(");let x=[];for(;l()!==")";){let m=c();(!/^(?:x|\d{1,2})$/.test(m.text)||x.length>=8)&&u("Expected up to eight diagram frets",m),x.push(m.text==="x"?"x":Number(m.text))}c();let d;if(l().startsWith("barre=")){let m=c(),w=/^barre=(\d{1,2})\/([1-8])\.\.([1-8])$/.exec(m.text);w||u("Expected barre=fret/from..to",m),d=[Number(w[1]),Number(w[2]),Number(w[3])]}return{kind:b.text,frets:x,barre:d,range:g()}}if(b.text==="line"){let x=c();return/^-?\d{1,2}(?:\.5)?$/.test(x.text)||u("Expected a staff line",x),{kind:"line",value:Number(x.text),range:g()}}if(b.text==="ink")return{kind:"ink",value:c().text,range:g()};if(b.text==="label"){let x=v(),d=J();return{kind:"label",text:x,style:d,range:g()}}if(b.text==="tap"||b.text==="vibrato"){let x=b.text==="vibrato"&&l()==="wide";return x&&c(),{kind:b.text,wide:x,range:g()}}if(b.text==="brush"||b.text==="roll"||b.text==="stroke"||b.text==="rasgueado"){let x=c();return x.text!=="up"&&x.text!=="down"&&u("Expected up or down",x),{kind:b.text,direction:x.text,range:g()}}if(b.text==="symbol"){let x=v(),d;return l()==="ink"&&(c(),d=c().text),{kind:"symbol",text:x,ink:d,range:g()}}if(b.text==="write"){let x=c();return Tn.test(x.text)||u("Expected a written pitch",x),{kind:"write",pitch:x.text,range:g()}}if(["staccato","fermata","articulation"].includes(b.text)){let x=b.text==="articulation"?l().startsWith('"')?v():c().text:b.text==="fermata"?"a@a":"a.",d=l()==="below"?"below":"above";return(l()==="below"||l()==="above")&&c(),{kind:"sign",code:x,position:d,range:g()}}if(b.text==="stem"){let x=c();return x.text!=="up"&&x.text!=="down"&&u("Expected stem up or down",x),{kind:"stem",value:x.text,range:g()}}if(b.text==="dynamic"){let x=c();return/^(ppp|pp|p|mp|mf|f|ff|fff)$/.test(x.text)||u("Expected a dynamic from ppp to fff",x),{kind:"dynamic",value:x.text,range:g()}}if(b.text==="onStaff"){let x=c();return x.text!=="upper"&&x.text!=="lower"&&u("Expected upper or lower",x),{kind:"onStaff",hand:x.text,range:g()}}if(b.text==="sharedStem")return{kind:"sharedStem",name:p(),range:g()};if(b.text==="ornament")return{kind:"ornament",value:M(),range:g()};if(b.text==="pedal"){let x=c();x.text!=="down"&&x.text!=="up"&&u("Expected pedal down or up",x);let d=x.text==="up"&&l()==="onset";return d&&c(),{kind:"pedal",action:x.text,...d&&{onset:d},range:g()}}if(b.text==="ossia"){let x=c();/^:(?:q|8|16|32)$/.test(x.text)||u("Expected an ossia note value such as :8",x);let d=[];for(f("(");l()!==")";){let m=c();(!Tn.test(m.text)||d.length>=16)&&u("Expected up to 16 ossia notes",m);let w;l()==="["&&(c(),f("ornament"),w=M(),f("]")),d.push({pitch:m.text,ornament:w})}return f(")"),d.length||u("Expected an ossia note",b),{kind:"ossia",duration:x.text.slice(1),notes:d,range:g()}}if(b.text==="grace"){let x=c(),d=[],m=[];x.text!=="before"&&x.text!=="after"&&u("Expected before or after",x);let w=l()==="slashed";w&&c();let N=l().startsWith("steal=")?c():void 0,z=N&&ae(N,N.text.slice(6),!0);for(f("(");l()!==")";){d.length>=16&&u("Expected up to 16 grace attacks");let ie=l()==="(";ie&&c();let ue=[];do{let le=c(),me=Ts.exec(le.text);if(ue.length>=Oe.heads&&u("Too many grace chord heads",le),Tn.test(le.text)?ue.push(le.text):me&&me[1]!=="x"?ue.push({fret:Number(me[1]),string:Number(me[2])}):u("Expected a grace pitch or fret/string",le),l()==="["){c(),l()!=="finger"&&u("Expected a finger on the grace head");let ye=L();if(ye.kind!=="finger")return u("Expected a grace fingering");m.push({attack:d.length,head:ue.length-1,finger:String(ye.value),position:ye.side}),f("]")}}while(ie&&l()!==")");ie&&f(")"),d.push(ie?ue:ue[0])}return f(")"),d.length||u("Expected a grace pitch",x),{kind:"grace",side:x.text,pitches:d,...z&&{steal:z},...m.length&&{fingerings:m},...w&&{slash:w},range:g()}}if(b.text==="harmony"){let x=function(){let N=c();return/^[A-G](?:b|#)?$/.test(N.text)||u("Expected a chord root or bass pitch",N),N.text},d=x(),m=v(),w;return l()==="bass"&&(c(),w=x()),{kind:"harmony",root:d,quality:m,...w&&{bass:w},range:g()}}if(b.text==="lyric"||b.text==="verse"){let x=b.text==="verse"?p():void 0,d=v(),m;l()==="elide"&&(c(),m=v());let w=l()==="hyphen";w&&c();let N=/^extend=([1-9]\d?)$/.exec(l());return N&&c(),{kind:"lyric",...x&&{verse:x},...m!==void 0&&{elideWith:m},text:d,hyphen:w,extend:N?Number(N[1]):0,range:g()}}if(b.text==="slideIn"||b.text==="slideOut"){let x=c();return x.text!=="above"&&x.text!=="below"?u("Expected above or below",x):{kind:b.text,side:x.text,range:g()}}if(b.text==="gliss"){let x=c();return/^(?:[1-9]|1[0-6])$/.test(x.text)||u("Expected the previous chord head number, 1 through 16",x),{kind:"gliss",fromHead:Number(x.text)-1,range:g()}}if(b.text==="release"||b.text==="bend"){let x=function(ie){let ue=c(),le=/^(\w+)=(\d{1,4})(?:\/(\d{1,4}))?$/.exec(ue.text);if(!le||le[1]!==ie)return u("Expected "+ie+"=N/D",ue);let me=Number(le[2]),ye=Number(le[3]??1);return ye<1||me<1||me>ye?u("Bend phase must lie within the note",ue):[me,ye]};if(b.text==="release"){let ie=x("hold"),ue=x("release");return ue[0]*ie[1]<=ie[0]*ue[1]&&u("Release must follow the hold",b),{kind:"release",hold:ie,release:ue,range:g()}}let d=c();/^\+(?:[1-9]\d?(?:\.5)?|0\.5)$/.test(d.text)||u("Expected a positive bend in semitones",d);let m=x("rise"),w=l().startsWith("hold=")?x("hold"):void 0,N=l().startsWith("release=")?x("release"):void 0,z=w??m;return(w&&w[0]*m[1]<m[0]*w[1]||N&&N[0]*z[1]<=z[0]*N[1])&&u("Bend phases must follow musical time",b),{kind:"bend",semitones:Number(d.text),rise:m,hold:w,release:N,range:g()}}if(b.text==="prebend"){let x=c();if(!/^\+[1-9]\d?$/.test(x.text))return u("Expected a positive bend in semitones",x);let d=l()==="release";return d&&c(),{kind:"prebend",semitones:Number(x.text),release:d,range:g()}}if(b.text!=="finger"&&b.text!=="stringNumber")return u("Unknown note mark "+b.text,b);if(b.text==="finger"?!/^[0-5Tpimac]$/.test(l()):!/^[1-8]$/.test(l()))return u("Invalid finger or string number");let y=c(),I=l(),D=I==="left"||I==="right"||I==="above"||I==="below"?I:void 0;return D&&c(),{kind:b.text,value:/^\d$/.test(y.text)?Number(y.text):y.text,side:D??"left",range:[b.range[0],r[a-1].range[1]]}}let X=new Map;function se(){do{let b=c(),g=/^([a-z][a-z0-9_]*)(=?)$/.exec(b.text);g||u("Expected an alias name",b),g[2]||f("=");let y=g[1];X.has(y)&&u("Duplicate alias "+y,b),Ii.has(y)&&u("Alias would hide the built-in mark "+y,b);let I=r[a],D=v(),x=r,d=a;r=Ci(D,I,e,n),a=0;try{let m=L();l()&&u("Expected one complete note mark"),X.set(y,m)}finally{r=x,a=d}}while(/^[a-z][a-z0-9_]*=$/.test(l())||r[a+1]?.text==="=")}function ee(){let b=X.get(l());return b?{...b,range:c().range}:L()}function Q(){if(l()!=="[")return[];c();let b=[ee()];for(;l()===",";)c(),b.push(ee());return f("]"),b}function te(){let b=c(),g=Ts.exec(b.text);if(g)return{marks:[],fret:g[1]==="x"?"x":Number(g[1]),string:Number(g[2]),range:b.range};if(Tn.test(b.text))return{marks:[],pitch:b.text,range:b.range};if(t.has(b.text))return{marks:[],drum:b.text,range:b.range};u("Expected a pitch, fret/string, or drum name",b)}function de(){let b=r[a],g=l()==="(",y=[];if(g){c();do{y.length===Oe.heads&&u("Too many heads in a chord");let m=te();for(let w of Q()){if(w.kind==="accent"){m.marks.push({kind:"sign",code:"a>",position:"above",range:w.range});continue}if(q(w))return u("Place the attack mark after the closing parenthesis",b);m.marks.push(w)}y.push(m)}while(l()!==")");c()}else y.push(te());let I=new Set,D=new Set;for(let m of y)"string"in m&&I.has(m.string)&&u("A chord needs distinct strings",b),"drum"in m&&D.has(m.drum)&&u("A chord needs distinct drum instruments",b),"string"in m&&I.add(m.string),"drum"in m&&D.add(m.drum);let x=Q(),d=x.filter(m=>!q(m));return g&&d.some(m=>m.kind!=="sign")&&u("Place a head mark inside the chord",b),y[0].marks.push(...d),{kind:"attack",heads:y,marks:x.filter(q),range:[b.range[0],r[a-1].range[1]]}}function pe(b,g){let y={w:1,h:2,q:4}[b[1]]??Number(b[1]),I=2**b[2].length;return{range:g,kind:"duration",value:[BigInt(I*2-1),BigInt(y*I)]}}function C(b=!1){let g=[];for(;l()!=="}"&&!(b&&l()==="text");){let y=r[a];y.text||u("Expected a closing brace");let I,D=Es.exec(y.text);if(D)c(),I=pe(D,y.range);else if(y.text==="meter"){c();let x=G(c());I={kind:"meter",signature:x,range:[y.range[0],x.range[1]]}}else if(y.text==="use"){c();let x=r[a],d=p();E.has(d)||u("Declare pattern "+d+" before using it (including inside patterns)",x),I={range:y.range,kind:"use",name:d}}else if(y.text==="bar"){c();let x=c(),d={double:"double",final:"end",repeatEnd:"repeat-end",repeatBoth:"repeat-both",single:"single"};Object.prototype.hasOwnProperty.call(d,x.text)||u("Unknown closing barline",x),I={kind:"|",closing:d[x.text],range:y.range}}else if(y.text==="repeatStart")c(),I={kind:"repeatStart",range:y.range};else if(y.text==="break")c(),f("system"),I={kind:"break",range:y.range};else if(y.text==="mark")c(),I={kind:"mark",text:v(),range:y.range};else if(y.text==="crescendo"||y.text==="diminuendo"||y.text==="continuousBeam"||y.text==="feather"||y.text==="tremolo"){let x=y.text;c();let d=(x==="crescendo"||x==="diminuendo")&&(l()==="above"||l()==="below")?c().text:void 0,m,w,N;if(x==="tremolo"){let z=c();/^[1-4]$/.test(z.text)||u("Expected one to four tremolo strokes",z),m=Number(z.text)}else if(x==="feather"){let z=c();z.text!=="left"&&z.text!=="right"&&u("Expected left or right",z),w=z.text}else x!=="continuousBeam"&&l()==="niente"&&(c(),N=!0);I={kind:x,strokes:m,feather:w,niente:N,side:d,body:h(C),range:y.range}}else if(y.text==="fragment"||y.text==="slur"||y.text==="beam"){c();let x=y.text==="slur"&&(l()==="above"||l()==="below")?c().text:void 0;I={kind:y.text,side:x,body:h(C),range:y.range}}else if(y.text==="palmMute"){c(),f("strings"),f("(");let x=[];for(;l()!==")";){let d=c();(!/^[1-8]$/.test(d.text)||x.includes(Number(d.text)))&&u("Expected distinct string numbers",d),x.push(Number(d.text))}x.length||u("Expected a string number"),c(),I={kind:"palmMute",strings:x,body:h(C),range:y.range}}else if(y.text==="transpose"||y.text==="octave"){c();let x=c(),d=Number(x.text)*(y.text==="octave"?12:1);(!/^[+-]?\d{1,3}$/.test(x.text)||Math.abs(d)>127)&&u("Invalid transposition interval",x),I={kind:y.text,semitones:d,body:h(C),range:y.range}}else if(y.text==="volta"||y.text==="repeatCount"){c();let x=c();/^(?:[2-9]|[12]\d|3[0-2])$/.test(x.text)||u("Expected 2 through 32 repeat passes",x);let d=h(C),m=[];for(let w=1;y.text==="volta"&&w<=Number(x.text);w++)f("ending"),f(String(w)),m.push(h(C));I={kind:"volta",body:d,endings:m,...y.text==="repeatCount"&&{count:Number(x.text)},range:y.range}}else if(y.text==="times"||y.text==="tuplet"){c();let x=c();if(y.text==="times")(!/^[1-9]\d?$/.test(x.text)||Number(x.text)>Oe.repetitions)&&u("Use a literal repeat count from 1 to "+Oe.repetitions,x),I={range:y.range,kind:"times",count:Number(x.text),body:h(C)};else{let d=/^([1-9]\d?):([1-9]\d?)$/.exec(x.text);(!d||d.slice(1).some(m=>Number(m)>16))&&u("Use an actual:normal tuplet ratio from 1 to 16 on each side",x),I={range:y.range,kind:"tuplet",scale:[BigInt(d[2]),BigInt(d[1])],body:h(C)}}}else if(y.text==="rest"||y.text==="skip"||y.text==="slash"||y.text==="|")if(c(),y.text==="|")I={kind:"|",range:y.range};else{let x=Q();x.some(d=>!q(d))&&u("This rhythm has no pitched head",y),I={kind:y.text,marks:x,range:y.range}}else{g.push(de());continue}I.range=[y.range[0],r[a-1].range[1]],g.push(I)}return g}function K(b=!1){if(l()!=="voice"){let I=r[a].range,D=C(!0);return b&&D.some(x=>x.kind==="attack")&&D.every(x=>["attack","duration","rest","skip","slash"].includes(x.kind))?[{name:"main",range:I,body:[{kind:"fragment",range:[I[0],D[D.length-1].range[1]],body:D}]}]:[{name:"main",range:I,body:D}]}let g=[],y=new Set;for(;l()==="voice";){c();let I=r[a],D=p();y.has(D)&&u("Duplicate voice "+D,I),y.add(D);let x=F("staff",!0);g.push({name:D,range:I.range,settings:x,body:h(C)})}return g}function ne(){let b={};for(;["font","size","style","ink","line","align","spacing"].includes(l());){if(["font","size","style","ink"].includes(l())){Object.assign(b,J());continue}let g=c(),y=c();g.text==="line"?(/^-?\d{1,2}$/.test(y.text)||u("Expected a staff line",y),b.line=Number(y.text)):g.text==="align"?(y.text!=="left"&&y.text!=="right"&&y.text!=="center"&&u("Invalid text alignment",y),b.align=y.text):(y.text!=="strict"&&y.text!=="smooth"&&u("Expected strict or smooth spacing",y),b.smooth=y.text==="smooth")}return b}function H(){let b=[];for(;l()==="text";){c();let g=r[a].range,y=p();b.some(x=>x.voice.name===y)&&u("Duplicate text lane");let I=ne(),D=h(()=>{let x=[],d=I;for(;l()!=="}";){let m=r[a],w=Es.exec(l());if(w)c(),x.push(pe(w,m.range));else if(l()==="|")c(),x.push({kind:"|",range:m.range});else if(l()==="skip")c(),x.push({kind:"skip",range:m.range});else if(["font","size","style","ink","line","align","spacing"].includes(l()))d={...d,...ne()};else{let N=l()==="start"||l()==="end"?c().text:void 0,z=l()==="sign",ie;z?(c(),ie=p()):ie=v();let ue=[m.range[0],r[a-1].range[1]];N==="start"||N==="end"?x.push({kind:"textBoundary",boundary:{edge:N,text:ie,glyph:z,style:d,range:ue},range:ue}):x.push({kind:"attack",heads:[],marks:[{kind:"text",text:ie,glyph:z,style:d,range:ue}],range:ue})}}return x});b.push({voice:{name:y,range:g,body:D},style:I})}return b}function re(b){f("at");let g=c();/^[1-9]\d{0,4}$/.test(g.text)||u("Expected a positive written bar number",g);let y="0/1",I=g;if(l()==="+"){c(),I=c(),/^\d{1,9}\/[1-9]\d{0,8}$/.test(I.text)||u("Expected an offset in whole notes",I);let[D,x]=I.text.split("/").map(Number),d=D,m=x;for(;m;)[d,m]=[m,d%m];y=D/d+"/"+x/d}return{bar:Number(g.text),at:y,range:[b.range[0],I.range[1]]}}function F(b,g=!1,y=!1){let I={};function D(){f("at");let m=c();return(!/^[1-9]\d{0,3}$/.test(m.text)||Number(m.text)<2)&&u("Expected a bar number starting at 2",m),Number(m.text)}function x(m){if(l()!=="at"){Object.assign(I,m);return}let w=D(),N=I.changes??={};N[w]={...N[w],...m}}let d=y?["key","clef","sounds"]:g?["stem","beams","flatBeams","beamRests","stemlets","middleRests","tabStems","tabDirection"]:["program","map","meter","key","clef","sounds","view","capo","tuning","ink","stem","beams","flatBeams","beamRests","tabStems","stemlets","middleRests","tabDirection","accidentals","display","groupBeats"];for(;d.includes(l());){let m=c(),w=c();if(m.text==="program")(!/^\d{1,3}$/.test(w.text)||Number(w.text)>127)&&u("Expected a MIDI program from 0 to 127",w),I.program=Number(w.text);else if(m.text==="map"){(b!=="drums"||!/^[a-z][a-z0-9_]*$/.test(w.text)||t.has(w.text))&&u("Expected a new percussion ID",w);let N=v();N.trim()||u("Expected a percussion label",w),f("line");let z=c();f("head");let ie=c();f("stem");let ue=c();f("midi");let le=c();/^-?\d(?:\.5)?$/.test(z.text)||u("Expected a staff line or space",z),["normal","cross","circle-cross","triangle"].includes(ie.text)||u("Unknown percussion head",ie),ue.text!=="up"&&ue.text!=="down"&&u("Expected up or down",ue),(!/^\d{1,3}$/.test(le.text)||Number(le.text)>127)&&u("Expected a MIDI pitch from 0 to 127",le),(I.drums??=[]).push({id:w.text,label:N,line:Number(z.text),head:ie.text,stem:ue.text,midi:Number(le.text)}),t.add(w.text)}else if(m.text==="meter")R(I.meters??={},w);else if(m.text==="accidentals")w.text!=="standard"&&w.text!=="cautionary"&&u("Expected standard or cautionary",w),I.cautionary=w.text==="cautionary";else if(m.text==="display"){w.text!=="meter"&&u("Expected display meter",w);let N=c();N.text!=="hidden"&&N.text!=="shown"&&u("Expected hidden or shown",N),x({displayMeter:N.text==="shown"})}else if(m.text==="groupBeats"){w.text!=="("&&u("Expected beat groups in parentheses",w);let N=[];for(;l()!==")";){let z=c();(!/^[1-9]\d?$/.test(z.text)||N.length>=32)&&u("Invalid beat group",z),N.push(Number(z.text))}N.length||u("Expected at least one beat group"),c(),I.beatGroups=N}else if(m.text==="ink")x({ink:w.text});else if(m.text==="stem"||m.text==="tabDirection")w.text!=="up"&&w.text!=="down"&&u("Expected up or down",w),I[m.text]=w.text;else if(m.text==="beams"||m.text==="flatBeams"||m.text==="beamRests"||m.text==="tabStems"||m.text==="stemlets"||m.text==="middleRests")w.text!=="on"&&w.text!=="off"&&u("Expected on or off",w),I[m.text==="beams"?"beam":m.text]=w.text==="on";else if(m.text==="key")if(/^(?:Cb|Gb|Db|Ab|Eb|Bb|F|C|G|D|A|E|B|F#|C#|Abm|Ebm|Bbm|Fm|Cm|Gm|Dm|Am|Em|Bm|F#m|C#m|G#m|D#m|A#m)$/.test(w.text)||u("Expected a key signature",w),l()==="at"||y){let N=l()==="at"?re(m):{bar:1,at:"0/1",range:m.range};!y&&N.at==="0/1"&&N.bar>1?(I.keys??={})[N.bar]=w.text:(I.staffChanges??=[]).push({...N,key:w.text})}else I.key=w.text;else if(m.text==="sounds")(!/^[+-]?\d{1,3}$/.test(w.text)||Math.abs(Number(w.text))>127)&&u("Invalid sounding interval",w),(I.staffChanges??=[]).push({...re(m),sounds:Number(w.text)});else if(m.text==="clef")if((b==="piano"&&!y||b==="drums")&&u("Declare the clef on a pitched staff",m),["treble","bass","alto","tenor","none","soprano","mezzo-soprano","baritone-c","baritone-f","subbass","french","percussion"].includes(w.text)||u("Unknown clef",w),l()==="at"||y){w.text==="none"&&u("A timed clef must be visible",w);let z=l()==="at"?re(m):{bar:1,at:"0/1",range:m.range};(I.staffChanges??=[]).push({...z,clef:w.text})}else I.clef=w.text;else if(b!=="guitar")u("This setting needs a guitar part",m);else if(m.text==="view")w.text!=="tab"&&w.text!=="both"&&w.text!=="notation"&&u("Expected tab, notation or both",w),I.view=w.text;else if(m.text==="capo")/^(?:0|[1-9]|1\d|2[0-4])$/.test(w.text)||u("Expected capo fret 0 through 24",w),I.capo=Number(w.text);else if(w.text==="("){let N=[];for(;l()!==")";){let z=c();/^[A-G](?:#|b)?[0-8]$/.test(z.text)||u("Expected an open string pitch such as E4",z),N.length===8&&u("A tuning supports up to eight strings",z),N.push(z.text.slice(0,-1)+"/"+z.text.slice(-1))}N.length<4&&u("A tuning needs at least four strings",w),c(),x({tuning:N.join(",")})}else{let N={standard:"standard",dropD:"dropd",dagdad:"dagdad",eb:"eb",standardBanjo:"standardBanjo"};Object.prototype.hasOwnProperty.call(N,w.text)||u("Unknown guitar tuning",w),x({tuning:N[w.text]})}}return I}for(;l();){let b=c();if(b.text==="meter")k.length&&u("Declare the shared meters before the first part",b),R(S,c());else if(b.text==="pickup"){(U||k.length)&&u("Declare one pickup before the first part",b),Y=c();let g=/^([1-9]\d{0,2})\/(1|2|4|8|16|32|64)$/.exec(Y.text);g||u("Expected a pickup duration such as 1/8",Y),U=[BigInt(g[1]),BigInt(g[2])]}else if(b.text==="edition")_(b);else if(b.text==="layout")(V||k.length)&&u("Declare layout once before the first part",b),V={},h(()=>{for(;l()!=="}";){let g=c();if(g.text==="heading"){V.heading&&u("Declare the score heading once",g);let D={};h(()=>{for(;l()!=="}";){let x=c();if(x.text==="align"){D.align&&u("Duplicate score heading alignment",x),f("center"),D.align="center";continue}x.text!=="title"&&x.text!=="dedication"&&x.text!=="tempo"&&x.text!=="composer"&&u("Unknown score heading field",x),D[x.text]!==void 0&&u("Duplicate score heading field",x),D[x.text]=v()}}),V.heading=D;continue}let y=c(),I=Number(y.text);if(g.text==="font"){y.text!=="Petaluma"&&y.text!=="Bravura"&&u("Expected Petaluma or Bravura",y),V.font=y.text;continue}if(g.text==="stemPolicy"){y.text!=="pitch"&&y.text!=="activeVoices"&&u("Expected pitch or activeVoices",y),V.stemPolicy=y.text;continue}if(g.text==="spacing"){y.text!=="optical"&&u("Expected optical spacing",y),V.spacing="optical";continue}g.text!=="width"&&g.text!=="scale"&&g.text!=="rowGap"&&g.text!=="staffDistance"&&g.text!=="firstSystemIndent"&&g.text!=="top"&&u("Unknown score layout setting",g),(!/^\d{1,4}(?:\.\d{1,3})?$/.test(y.text)||g.text==="width"&&I<=20||g.text==="scale"&&(!I||I>8))&&u("Invalid layout dimension",y),V[g.text]=I}});else if(b.text==="play")(k.length||P)&&u("Set playback once before the first part",b),P={enabled:!0},h(()=>{for(;l()!=="}";){let g=c();if(g.text==="enabled"){let y=c();y.text!=="on"&&y.text!=="off"&&u("Expected on or off",y),P.enabled=y.text==="on"}else if(g.text==="tempo"){let y=c();if(/^[1-9]\d{0,2}$/.test(y.text)||u("Expected a positive tempo",y),l()==="at"){let I=re(g);I.at!=="0/1"?(P.tempoChanges??=[]).push({...I,bpm:Number(y.text)}):(s.has(I.bar)&&u("Duplicate tempo change at this bar",y),s.set(I.bar,I.range),(P.tempos??={})[I.bar]=Number(y.text))}else P.tempo=Number(y.text)}else if(g.text==="controls"||g.text==="controlSize"||g.text==="position"||g.text==="inset"){let y=c(),I=P.controls??={};g.text==="controls"?y.text==="off"||y.text==="hover"||y.text==="always"?I.visibility=y.text:u("Expected controls off, hover or always",y):g.text==="controlSize"?or(y.text)?I.size=y.text:u("Expected controlSize auto, mini or large",y):g.text==="position"?ar(y.text)?I.position=y.text:u("Unknown control position",y):(/^\d{1,4}(?:\.\d{1,2})?$/.test(y.text)||u("Expected a nonnegative control inset in pixels",y),I.inset=Number(y.text))}else if(g.text==="swing"){let y=c();y.text!=="eighths"&&y.text!=="off"?u("Expected swing eighths or swing off",y):P.swing=y.text}else if(g.text==="performer"){let y=c();yt(y.text)?P.performer=y.text:u("Unknown performer: "+y.text,y)}else if(g.text==="instrument"){let y=c();!/^[A-Za-z_][A-Za-z0-9_]*$/.test(y.text)&&!/^(?:0|[1-9]\d?|1[01]\d|12[0-7])$/.test(y.text)&&u("Expected an instrument name or MIDI program",y),P.instrument=y.text}else u("Expected a playback setting",g)}});else if(b.text==="transpose"){let g=c();(k.length||B!==void 0)&&u("Declare a single transposition before the first part",g),(!/^[+-]?\d{1,3}$/.test(g.text)||Math.abs(Number(g.text))>127)&&u("Transposition needs an integer from -127 to 127",g),B=Number(g.text)}else if(b.text==="measureNumbers"){let g=c();g.text!=="off"&&g.text!=="on"&&u("Expected on or off",g),j=g.text==="on"}else if(b.text==="alias")k.length&&u("Declare aliases before the first part",b),se();else if(b.text==="pattern"){let g=r[a],y=p();E.has(y)&&u("Duplicate pattern "+y,g),E.set(y,h(C))}else if(b.text==="group"){let g=c();g.text!=="brace"&&g.text!=="bracket"&&u("Expected brace or bracket",g),f("(");let y=[];for(;l()!==")";)y.push(p());let I=c();y.length<2&&u("A group needs at least two parts",g),A.push({type:g.text,parts:y,range:[b.range[0],I.range[1]]})}else if(Fi(b.text)){t=new Set(Ms);let g=r[a],y=l()==="{"?void 0:p();y&&k.some(m=>m.id===y)&&u("Duplicate part ID "+y,g);let I,D=[],x={},d;if(b.text==="piano")h(()=>{I=O(y),x=F("piano");for(let m of["upper","lower"]){let w=f(m),N=r[a],z=l()==="{"?void 0:p();D.some(me=>(me.id??me.name)===(z??m))&&u("Duplicate staff ID "+(z??m),z?N:w);let ie,ue,le=h(()=>(ie=O(z),ue=F("piano",!1,!0),K()));D.push({...W(ie),...ue,name:m,range:w.range,voices:le})}d=H()});else{let m={},w=h(()=>{if(I=O(y),l()==="stave"){c();let ie=p();m=h(()=>O(ie))}x=F(b.text);let N=b.text==="guitar"&&!x.meters&&!Object.keys(S).length&&!U,z=K(N);return d=H(),z});D.push({...W(m),name:"main",range:b.range,voices:w})}k.push({...I,...x,...d?.length&&{lanes:d},kind:b.text,range:b.range,staves:D})}else u("Expected a score setting, alias, pattern or part",b)}return k.length||u("Expected a part"),{groups:A,tempoRanges:s,editions:T,patterns:E,parts:k,scoreMeters:S,pickup:U,pickupRange:Y?.range,playback:P,measureNumbers:j,layout:V,transpose:B}}var Ue=class extends Error{constructor(e,n,t,s,r){let a=t.slice(0,s[0]),i=a.split(/\r\n|\r|\n/).length,l=s[0]-Math.max(a.lastIndexOf(`
|
|
370
|
-
`),a.lastIndexOf("\r"));super(`${e} at ${i}:${l}: ${n}`),this.name="ScoreV2Error",this.code=e,this.range=s,this.trace=r,this.line=i,this.column=l}};function Kt(o,e,n,t,s){let r=o,a=e;for(;a;)[r,a]=[a,r%a];return o/=r,e/=r,(o>Oe.fraction||e>Oe.fraction)&&n("fraction-limit","Written time needs a smaller ratio",t,s),[o,e]}var xt=([o,e])=>o+"/"+e;function ut(o){let[e,n]=o.split("/");return[BigInt(e),BigInt(n)]}function Bi(o,e,n){if(!e||!("fret"in o)||typeof o.fret!="number")return;let t=o.fret,s=e.heads.findIndex(r=>"fret"in r&&r.string===o.string&&typeof r.fret=="number"&&(n==="hammer"?r.fret<t:n==="pull"?r.fret>t:r.fret!==t));if(s>=0)return{event:e.id,head:s}}function Ns(o,e){let n=Ss(e),t=(v,_,O,W=[])=>{throw new Ue(v,_,o,O,W)},{groups:s,tempoRanges:r,editions:a,patterns:i,parts:l,scoreMeters:c,pickup:u,pickupRange:f,playback:p,measureNumbers:h,layout:E,transpose:k}=_s(o,t,n),S=c[1]?.value??"4/4",P=u&&xt(Kt(...u,t,f,[])),B=[BigInt(1),BigInt(4)],j=[BigInt(0),BigInt(1)],A=0,T=0;function V(v,_){++A>n.steps&&t("work-limit","Phrase expansion exceeds "+n.steps+" work steps",v,_)}function U(v,_,O,W,J){let ae={name:O.name,...O.settings&&{settings:O.settings},range:O.range,events:[],measures:[],spans:[]},{events:L,measures:X,spans:se}=ae,ee=1,Q=0,te=j,de=!1,pe=0,C=0,K=!1,ne,H;function re(g,y,I){let D=xt(te);J.bars[ee-1]!==void 0&&J.bars[ee-1]!==D&&t("alignment","Voices disagree on the length of bar "+ee,g,y),J.bars[ee-1]=D,X.push({number:ee,start:Q,end:L.length,barlineRange:g,trace:y,span:D,fragment:de,newRow:K,rehearsal:ne,closing:I,opening:H}),H=I==="repeat-both"?"repeat-begin":void 0,Q=L.length,ee++,te=j,ne=void 0,K=!1}function F(g,y,I,D,x){++T>n.events&&t("event-limit","Score exceeds "+n.events+" expanded attacks, rests or skips",g.range,x);let d=Kt(y[0]*D[0],y[1]*D[1],t,g.range,x),m=qt(g.marks??[]);m&&t("syntax",m.reason,m.range,x);let w=[v.id??W+1,_.id??_.name,O.name,L.length+1].join("."),N=g.kind==="attack"?g.heads.map((z,ie)=>{(v.kind==="drums"!="drum"in z||"string"in z&&v.kind!=="guitar")&&t("instrument","This head does not belong to "+v.kind,z.range,x);let ue=qt(z.marks);ue&&t("syntax",ue.reason,ue.range,x);for(let ye of z.marks){if(ye.kind==="sustain"){let[ve,Me]=ut(ye.duration);ve*d[1]>d[0]*Me&&t("syntax","Head sustain exceeds this attack; write a separate voice or tie",ye.range,x);let Le=g.marks?.find(we=>we.kind==="grace");if(Le?.kind==="grace"&&Le.steal&&Le.side==="before"){let[we,_e]=ut(Le.steal);ve*d[1]*_e<=d[0]*Me*we&&t("syntax","Before-grace would consume the entire sounding head",Le.range,x)}}["bend","prebend","slideIn","slideOut"].includes(ye.kind)&&(!("fret"in z)||typeof z.fret!="number")&&t("instrument","This technique needs a pitched fret",ye.range,x)}let le=z.marks.find(ye=>ye.kind==="hammer"||ye.kind==="slide"||ye.kind==="pull");if(!le||le.kind!=="hammer"&&le.kind!=="slide"&&le.kind!=="pull")return z;let me=Bi(z,L[L.length-1],le.kind);return me||t("hammer",le.kind==="hammer"?"Expected a lower fret on this string in the preceding attack":"Expected a compatible preceding fret on this string",le.range,x),se.push({kind:le.kind,from:me,to:{event:w,head:ie},range:le.range}),le.kind==="hammer"?{...z,hammerFrom:me}:z}):[];L.push({id:w,bar:ee,at:xt(te),duration:xt(d),writtenDuration:xt(y),kind:g.kind,...pe&&{transpose:pe},...C&&{soundingOctaves:C},heads:N,marks:g.marks??[],range:g.range,rhythmRange:I,trace:x}),te=Kt(te[0]*d[1]+d[0]*te[1],te[1]*d[1],t,g.range,x)}function b(g,y,I,D,x){x.length>Oe.depth&&t("depth-limit","Phrase expansion is too deep",x[x.length-1].range,x);for(let d of g)switch(V(d.range,x),d.kind){case"meter":{te[0]&&t("alignment","Change meter at the beginning of a bar",d.range,x);let m=J.meters[ee],w=d.signature;m&&(m.value!==w.value||m.sign!==w.sign)&&t("alignment","Conflicting meters for bar "+ee,w.range,x),J.meters[ee]??={...w,...x.length&&{trace:x}};break}case"duration":y=d.value,I=d.range;break;case"|":re(d.range,x,d.closing);break;case"textBoundary":{let m=d.boundary.edge==="start"?"0/1":J.bars[ee-1];xt(te)!==m&&t("alignment","Put a text boundary at the indicated bar edge",d.range,x),(ae.boundaries??=[]).push({...d.boundary,bar:ee});break}case"mark":case"break":case"repeatStart":te[0]&&t("alignment","Place this directive at the beginning of a bar",d.range,x),d.kind==="mark"?ne=d.text:d.kind==="repeatStart"?H="repeat-begin":K=!0;break;case"fragment":{(te[0]||de)&&t("alignment","Start a fragment at a bar boundary",d.range,x),de=!0;let m=ee;b(d.body,y,I,D,x),(te[0]||m===ee)&&re(d.range,x),de=!1;break}case"octave":{let m=C;C+=d.semitones/12,b(d.body,y,I,D,x),C=m;break}case"transpose":{let m=pe;pe+=d.semitones,Math.abs(pe)>127&&t("instrument","Transposition exceeds the MIDI range",d.range,x),b(d.body,y,I,D,x),pe=m;break}case"crescendo":case"diminuendo":case"continuousBeam":case"feather":case"tremolo":{let m=L.length,w=d.kind==="tremolo"?Kt(D[0],D[1]*BigInt(2),t,d.range,x):D;b(d.body,y,I,w,x);let N=L.slice(m),z=N[0],ie=N[N.length-1];N.length<2&&t("syntax","This span needs two endpoints",d.range,x),(d.kind==="feather"||d.kind==="continuousBeam")&&(N.some(ue=>!ue.heads.length||Number(ue.writtenDuration.split("/")[1])<(d.kind==="feather"?16:8))||d.kind==="feather"&&z.bar!==ie.bar)&&t("syntax","Invalid pitches or durations for this beam",d.range,x),d.kind==="tremolo"&&(N.length!==2||z.bar!==ie.bar||!z.heads.length||!ie.heads.length||z.writtenDuration!==ie.writtenDuration||!["1/1","1/2","1/4"].includes(z.writtenDuration))&&t("syntax","Tremolo needs two equal whole, half or quarter attacks in one measure",d.range,x),se.push({kind:d.kind,first:z.id,last:ie.id,niente:d.niente,...d.side&&{side:d.side},feather:d.feather,strokes:d.strokes,range:d.range});break}case"palmMute":case"slur":case"beam":{let m=L.length;b(d.body,y,I,D,x);let w=L.slice(m);(!w.length||d.kind!=="palmMute"&&w.length<2)&&t("syntax","This span needs more notes",d.range,x),d.kind==="palmMute"&&v.kind!=="guitar"&&t("instrument","Palm mute needs a guitar",d.range,x),d.kind==="beam"&&ir(L,m,L.length-1,d.range,x,t),se.push({kind:d.kind,first:w[0].id,last:w[w.length-1].id,side:d.side,strings:d.strings??[],range:d.range});break}case"use":b(i.get(d.name),B,void 0,D,[...x,{pattern:d.name,range:d.range}]);break;case"times":for(let m=1;m<=d.count;m++)V(d.range,x),b(d.body,y,I,D,[...x,{iteration:m,range:d.range}]);break;case"volta":{te[0]&&t("bar-length","Start a repeat at a shared barline",d.range,x);let m=ee;b(d.body,y,I,D,x);let w=ee-1;(te[0]||w<m)&&t("bar-length","End the repeat body with a full bar",d.range,x);let N=d.endings.map(z=>{let ie=ee;return b(z,y,I,D,x),(te[0]||ee===ie)&&t("bar-length","Each ending needs at least one complete bar",d.range,x),{first:ie,last:ee-1}});(ae.repeats??=[]).push({first:m,bodyEnd:w,endings:N,...d.count&&{count:d.count},range:d.range});break}case"tuplet":{let m=L.length,w=d.scale[1]+":"+d.scale[0],N=Kt(D[0]*d.scale[0],D[1]*d.scale[1],t,d.range,x);b(d.body,y,I,N,[...x,{tuplet:w,range:d.range}]),L.length>m&&se.push({kind:"tuplet",ratio:w,first:L[m].id,last:L[L.length-1].id,range:d.range});break}default:F(d,y,I,D,x)}}if(b(O.body,B,void 0,[BigInt(1),BigInt(1)],[]),te[0]){let g=L[L.length-1];t("bar-length","End the final measure with |",g.range,g.trace)}return ks(ae,t),X.length||t("bar-length","Expected at least one measure",O.range),J.voiceLength!==void 0&&J.voiceLength!==X.length&&t("alignment","Every voice in a part must cover the same number of bars",O.range),J.voiceLength=X.length,ae}function Y(v,_,O){let W,J=!1,ae=[..._,...O];for(let L=0;L<v.bars.length;L++){let X=L+1;v.meters[X]?(W=v.meters[X],J=!0):!J&&c[X]&&(W=c[X]);let se=W?.value??"4/4",ee=ut(se);X===1&&u&&u[0]*ee[1]>=ee[0]*u[1]&&t("syntax","Pickup must be shorter than the opening meter "+se,f);let Q=X===1&&u?u:ee,[te,de]=ut(v.bars[L]);if(te*Q[1]!==Q[0]*de){let pe=_.find(C=>!C.measures[L].fragment);if(pe){let C=pe.measures[L];if(te*Q[1]>Q[0]*de)for(let K=C.start;K<C.end;K++){let ne=pe.events[K],[H,re]=ut(ne.at),[F,b]=ut(ne.duration);(H*b+F*re)*Q[1]>Q[0]*re*b&&t("bar-length","Attack crosses the end of bar "+X,ne.range,ne.trace)}t("bar-length","Bar "+X+" contains "+C.span+" of a whole note, expected "+xt(Q),C.barlineRange,C.trace)}}for(let pe of ae){let C=pe.measures[L];C.meter=se,C.meterSign=W?.sign,C.meterRange=W?.range}}}function G(v,_){let O=(W,J)=>{let[ae,L]=ut(W),[X,se]=ut(J);return Number(ae*se-X*L)};v.sort((W,J)=>W.bar-J.bar||O(W.at,J.at));for(let W of v)(!_[W.bar-1]||O(W.at,_[W.bar-1])>=0)&&t("alignment","Timed setting lies outside its written measure",W.range)}let R=l.map((v,_)=>{let{lanes:O,...W}=v,J={bars:[],meters:{...v.meters}},ae=v.staves.map(se=>({...se,voices:se.voices.map(ee=>U(v,se,ee,_,J))})),L=O?.map(se=>({name:se.voice.name,style:se.style,voice:U(v,{name:"main",range:v.range,voices:[]},{...se.voice,name:"text-"+se.voice.name},_,J)})),X=J.bars.length;for(let[se,ee]of Object.entries(J.meters))Number(se)>X&&t("alignment","Meter change lies beyond this part",ee.range,ee.trace);for(let se of Object.keys(v.changes??{}))Number(se)>X&&t("alignment","Part setting change lies beyond the score",v.range);for(let se of Object.keys(v.keys??{}))Number(se)>X&&t("alignment","Key change lies beyond the score",v.range);for(let se of ae){let ee=[...v.staffChanges??[],...se.staffChanges??[]];if(!ee.length)continue;G(ee,J.bars);let Q=new Set,te=se.voices.map(de=>new Set(de.events.map(pe=>pe.bar+":"+pe.at)));for(let de of ee){for(let pe of["key","clef","sounds"])if(de[pe]!==void 0){let C=pe+":"+de.bar+":"+de.at;Q.has(C)&&t("alignment","Duplicate timed "+pe,de.range),Q.add(C)}(de.key||de.clef)&&de.at!=="0/1"&&(te.some(pe=>!pe.has(de.bar+":"+de.at))||L?.length)&&t("alignment","Inline clef and key changes need a shared music-voice onset without a separate text lane",de.range)}se.staffChanges=ee}return Y(J,ae.flatMap(se=>se.voices),L?.map(se=>se.voice)??[]),{...W,...Object.keys(J.meters).length&&{meters:J.meters},measureCount:X,staves:ae,...L&&{text:L}}}),M=Math.max(...R.map(v=>v.measureCount));for(let[v,_]of Object.entries(c))Number(v)>M&&t("alignment","Meter change lies beyond the score",_.range);for(let[v,_]of r)v>M&&t("alignment","Tempo change lies beyond the score",_);if(p?.tempoChanges){let v=R[0].staves[0].voices[0].measures;for(let O of R){let W=O.staves[0].voices[0].measures;G(p.tempoChanges,W.map(ae=>ae.span));let J=p.tempoChanges[p.tempoChanges.length-1];for(let ae=0;ae<J.bar-1;ae++)W[ae].span!==v[ae].span&&t("alignment","Share the written bar grid before a global inline tempo",J.range)}let _=new Set;for(let O of p.tempoChanges){let W=O.bar+":"+O.at;_.has(W)&&t("alignment","Duplicate timed tempo",O.range),_.add(W)}}let q=new Map(R.map((v,_)=>[v.id,_]));for(let v of s){let _=q.get(v.parts[0]);(_===void 0||v.parts.some((O,W)=>q.get(O)!==_+W))&&t("alignment","Group members must be adjacent named parts in score order",v.range)}for(let v of a){let _=R.find(W=>W.id===v.part);v.part&&!_&&t("alignment","Unknown edition part "+v.part,v.range);let O=_?.measureCount??Math.min(...R.map(W=>W.measureCount));for(let W of v.anchors)(W.measure>O||W.field.endsWith("Turns")&&W.measure===O)&&t("alignment","Edition measure or turn outside the music",W.range);for(let W of v.cues){let J=R.find(ae=>ae.id===W.part);(!J||W.measure>J.measureCount||W.measure>O)&&t("alignment","Missing cue instrument or measure",W.range)}}return{language:2,...s.length&&{groups:s},...a.length&&{editions:a},...k&&{transpose:k},...E&&{layout:E},...p&&{playback:p},...h!==void 0&&{measureNumbers:h},source:o,meter:S,meterRange:c[1]?.range,...u&&{pickup:P},measureCount:M,parts:R}}var Ae=Ee(Pe());var Lt=Ee(Pe());function ge(o,e){throw new oe("syntax",e,o)}function cr(o,e){try{let n=JSON.parse(o);if(typeof n=="string"&&n.trim()&&!/[\r\n]/.test(n))return n}catch{}ge(e,"Expected nonempty text in double quotes")}function Vi(o,e,n,t){let s=/^(\d+)\s+\+(\d+(?:\.\d+)?)\s+rise=(\d+\/\d+)(?:\s+hold=(\d+\/\d+))?(?:\s+release=(\d+\/\d+))?$/.exec(o);s||ge(t,"Expected bend STRING +SEMITONES rise=N/D [hold=N/D] [release=N/D]");function r(l){if(!l)return;let[c,u]=l.split("/").map(Number);return[c,u]}let a={string:+s[1],semitones:+s[2],rise:r(s[3]),hold:r(s[4]),release:r(s[5])};e.heads.some(l=>l.prebend&&l.position.str===a.string)&&ge(t,"This string already has a pre-bend");let i=e.heads.map(l=>l.position);(!i.length||i.some(l=>!l||l.fret==="X"))&&ge(t,"A bend needs a pitched fretted attack");try{new Lt.FrettedInstrument(n.tuning,n.capo).bentAttack(i,e.base,a)}catch(l){ge(t,l.message)}return a}function Oi(o,e,n){for(let[t,s]of o.entries()){let a=e.heads.find(i=>i.position?.str===o.length-t)?.position?.fret;(s==="x"?a!==void 0&&a!=="X":a!==s)&&ge(n,"Frame disagrees with the fretted chord")}e.heads.some(t=>!t.position)&&ge(n,"A frame needs an explicit string for each chord member")}function lr(o,e,n,t,s="frame"){let r=/^([x\d,]+)(?:\s+barre=(\d+):(\d+)-(\d+))?$/.exec(o);(!r||!e.chord)&&ge(t,"A frame follows a chord label and needs low-to-high frets");let a=r[1].split(","),i=a.length;s==="diagram"&&(i<4||i>8)&&ge(t,"Supply four through eight strings in a diagram"),(s==="frame"&&i!==n.strings||a.some(p=>!/^(x|\d+)$/.test(p)))&&ge(t,"Supply one fret or x per string");let l=a.map(p=>p==="x"?"x":Number(p));l.every(p=>p==="x")&&ge(t,"A frame needs at least one sounding string"),l.some(p=>p!=="x"&&!Number.isSafeInteger(p))&&ge(t,"Invalid frame fret"),s==="frame"&&Oi(l,e,t);let c=l.filter(p=>typeof p=="number"&&p>0),u=Math.max(...c)>4?Math.min(...c):1;Math.max(...c)-u>=4&&ge(t,"Frame spans more than four frets");let f;if(r[2]){let[p,h,E]=r.slice(2).map(Number);(h<=E||E<1||h>i||p<u||l[i-h]!==p||l[i-E]!==p||l.slice(i-h,i-E+1).some(k=>typeof k!="number"||k<p))&&ge(t,"Barre endpoints must stop at the given fret, from lower to higher string"),f={fret:p,from:h,to:E}}return{frets:l,firstFret:u,barre:f}}function Li(o,e,n,t){if(o.events.length&&ge(t,"Put this command at the start of a bar"),o.boundaryRange??=t,e==="key"){(o.keyChange||!Lt.default.hasKeySignature(n))&&ge(t,"Expected one key signature per boundary");try{new Lt.KeyManager(n)}catch{ge(t,"Unsupported key signature")}o.keyChange=n}else if(e==="mark")o.rehearsal&&ge(t,"Duplicate rehearsal mark"),o.rehearsal=cr(n,t);else{let s=/^([1-9]\d*)\s+bars=([1-9]\d*)$/.exec(n);(!s||o.ending)&&ge(t,"Expected one ending NUMBER bars=COUNT"),o.ending={label:s[1]+".",bars:Number(s[2]),range:t}}}var Mn=class{constructor(e,n,t){this.state=e;this.spans=n;this.firstVoice=t}apply(e,n){let{range:t}=e,[,s,r=""]=/^(\S+)(?:\s+([\s\S]*))?$/.exec(e.params.trim())??[];if(["key","mark","ending"].includes(s)){this.firstVoice||ge(t,"Put this command in the first voice"),Li(n,s,r,t);return}let a=n.events[n.events.length-1];switch(a||ge(t,"Put this command immediately after an attack in this bar"),s){case"color":Be(r)||ge(t,"Expected a CSS color name or hex value"),a.color=r;break;case"bend":a.bend&&ge(t,"One timed bend per attack"),a.bend={spec:Vi(r,a,this.state,t),range:t};break;case"pm":{let i=r.split(",").map(Number);(this.mute||!/^\d+(,\d+)*$/.test(r)||new Set(i).size!==i.length||i.some(l=>l<1||l>this.state.strings)||!a.heads.some(l=>i.includes(l.position?.str)))&&ge(t,"Start one palm mute on a played target string"),this.mute={event:a,strings:i,range:t};break}case"end-pm":{(r||!this.mute||!a.heads.some(u=>this.mute.strings.includes(u.position?.str)))&&ge(t,"End the open palm mute on a played target string");let{strings:i,event:l,range:c}=this.mute;this.spans.push({kind:"palmMute",id:"pm"+c.start,from:l.id,to:a.id,strings:i,range:c}),this.mute=void 0;break}case"silent":(r||a.heads.length||a.silent)&&ge(t,"Put !silent! after a rest"),a.silent=t;break;case"chord":{a.heads.length||ge(t,"A chord label needs a note or slash"),a.chord&&ge(t,"Duplicate chord label");let i=/^("(?:[^"\\]|\\.)*")(?:\s+color=(\S+))?$/.exec(r);(!i||i[2]&&!Be(i[2]))&&ge(t,'Expected chord "label" with an optional color=NAME or hex value'),a.chord={text:cr(i[1],t),...i[2]&&{color:i[2]},range:t};break}case"frame":a.frame&&ge(t,"Duplicate chord frame"),a.frame={spec:lr(r,a,this.state,t),range:t};break;case"lyric":{let i=/^("(?:[^"\\]|\\.)*")(?:\s+(-)|\s+extend=([1-9]\d*))?$/.exec(r);(!i||a.lyric||!a.heads.length)&&ge(t,'Expected one lyric "syllable" with an optional - or extend=COUNT on a note'),a.lyric={text:cr(i[1],t),hyphen:!!i[2],extend:Number(i[3]??0),range:t};break}default:throw new oe("fixed-layout","Use fixed layout for command "+s,t)}}finish(){this.mute&&ge(this.mute.range,"Unclosed palm mute")}};function Pn(o,e){let n=0;for(let t of o){let s=t.voices[0],r=s.ending;if(r){let a=t.number+r.bars-1,i=o[a-1]?.voices[0].events;(!i||n>=t.number)&&ge(r.range,"Ending overlaps another ending or extends beyond the score"),e.push({kind:"volta",id:"ending"+r.range.start,label:r.label,from:s.events[0].id,to:i[i.length-1].id,firstBar:t.number,lastBar:a,range:r.range}),n=a}for(let a of t.voices)a.events.forEach((i,l)=>{let c=i.lyric;!c?.crossConnector&&c?.hyphen&&!a.events.slice(l+1).some(u=>u.lyric)&&ge(c.range,"Hyphen needs a following syllable in this bar and voice"),!c?.crossConnector&&c?.extend&&!a.events[l+c.extend]&&ge(c.range,"Lyric extender must end in this bar and voice")})}}function Se(o,e){throw new oe("fixed-layout",`Use fixed layout for ${e}`,o.range)}function be(o,e){throw new oe("syntax",e,o.range)}function dt(o){return new Ae.Fraction().parse(o).simplify()}function As(o,e){return(!/^[1-9]\d*\/[1-9]\d*$/.test(o)||!o.split("/").every(n=>Number.isSafeInteger(Number(n))))&&be(e,`Invalid span '${o}'`),dt(o).toString()}function Xt(o){return["true","false"].includes(o.value)||be(o,`Expected true or false for ${o.key}`),o.value==="true"}function Is(o){let e=o.options??[],n=e.length?e[e.length-1].range.end:o.range.start+o.element.length;return{...o.range,end:n}}function Hi(o){let e={tab:o.element==="tabstave",notation:o.element!=="tabstave",capo:0,strings:6,tuning:"standard",key:"C",clef:"treble",meter:"4/4",showTime:!1,fragment:!1,declaration:Is(o),timeRange:{...o.range,end:o.range.start+o.element.length}};o.element==="piano"&&(e.piano=!0);let n=!0,t=!1;for(let s of o.options??[])if(e.piano&&["clef","tuning","capo","strings","tablature","notation"].includes(s.key)&&be(s,"A piano uses treble and bass notation staves"),!(e.piano&&s.key==="hand"))switch(s.key){case"color":Be(s.value)||be(s,"Expected a CSS color name or hex value"),e.color=s.value;break;case"notation":e.notation=Xt(s);break;case"tablature":e.tab=Xt(s);break;case"fragment":e.fragment=Xt(s);break;case"show-time":n=Xt(s),e.timeRange=s.range;break;case"time":(["C","C|"].includes(s.value)||/^(?:\(\d+(?:\+\d+)+\)|\d+(?:\+\d+)+)\/\d+$/.test(s.value))&&Se(s,`printed time signature '${s.value}'`),As(s.value,s),e.meter=s.value,t=!0;break;case"pickup":e.pickup=As(s.value,s);break;case"key":Ae.default.hasKeySignature(s.value)||be(s,"Invalid key signature");try{new Ae.KeyManager(s.value)}catch{Se(s,`key signature '${s.value}'`)}e.key=s.value;break;case"tuning":try{new Ae.Tuning(s.value)}catch{be(s,"Invalid tuning")}e.tuning=s.value;break;case"capo":e.capo=Number(s.value),(!/^\d+$/.test(s.value)||!Number.isSafeInteger(e.capo))&&be(s,"Expected a nonnegative capo fret");break;case"strings":e.strings=Number(s.value),(!Number.isInteger(e.strings)||e.strings<4||e.strings>8)&&be(s,"Expected 4\u20138 strings");break;case"clef":s.value==="none"&&Se(s,`clef '${s.value}'`),["treble","bass","tenor","alto","percussion"].includes(s.value)||be(s,"Invalid clef"),e.clef=s.value;break;case"fingering":case"accents":break;case"voice":break;default:Se(s,`stave option '${s.key}'`)}return e.showTime=n&&t,!e.notation&&!e.tab&&be(o,"At least one staff must be visible"),e.pickup&&!dt(e.pickup).lessThan(dt(e.meter))&&be(o,"Pickup must be shorter than the meter"),e}function Rs(o,e,n){return{declaration:n,events:[],tuplets:[],span:"0/1",beams:o.beams!=="off",stem:e==="top"?"up":e==="bottom"?"down":void 0,tabStems:o["tab-stems"]==="true",tabDirection:o["tab-stem-direction"]==="down"?-1:1,beamRests:o["beam-rests"]!=="false",stemlets:o["beam-stemlets"]!=="false",middleRests:o["beam-middle-only"]==="true"}}function Di(o,e){for(let n of e.params){switch(n.key){case"tempo":(!Number.isFinite(Number(n.value))||Number(n.value)<=0)&&be(n,"Tempo must be positive");break;case"transpose":case"instrument":break;case"player":case"measure-numbers":case"tab-stems":case"beam-rests":case"beam-stemlets":case"beam-middle-only":Xt(n);break;case"tab-stem-direction":["up","down"].includes(n.value)||be(n,"Invalid tab stem direction");break;case"beams":n.value==="explicit"&&Se(n,"explicit beam groups"),["auto","off"].includes(n.value)||be(n,"Invalid beam mode");break;default:Se(n,`option '${n.key}'`)}o[n.key]=n.value}}function zi(o){let e=o.time.replace(/s$/,"");try{Ae.default.durationToTicks(e)}catch{be(o,`Invalid duration '${o.time}'`)}return{base:e,dots:Number(o.dot||0),slash:o.time.endsWith("s"),range:o.range}}function ji(o,e,n,t,s,r){e.piano&&(o.fret!==void 0||!o.abc||!/^[A-G]$/.test(o.abc.key))&&be(o,"Write named pitches such as C/4 on a piano stave"),o.decorator&&Se(o,`decorator '${o.decorator}'`),o.articulation&&!["T","-"].includes(o.articulation)&&Se(o,`technique '${o.articulation}'`);let a=Number(o.string),i,l=Number(o.fret)+e.capo+(o.prebend?.semitones??0),c;if(o.fret!==void 0){let p=Number(o.fret);(a<1||a>e.strings||!Number.isSafeInteger(p))&&be(o,"Invalid fret or string");try{c=dn(n,l,a)}catch{be(o,"String outside the tuning")}i={str:a,fret:p}}if(o.abc){if(o.abc.key==="X"&&!o.abc.accidental&&!o.abc.accidental_type&&o.fret===void 0){if(r&&!e.tab)return{range:o.range,written:"b/4",sounding:null};(a<1||a>e.strings)&&be(o,"Dead strike needs a physical string");let E;try{E=n.getNoteForFret(e.capo,a).toLowerCase()}catch{be(o,"String outside the tuning")}return{range:o.range,written:E,sounding:null,position:{str:a,fret:"X"}}}/^[A-G]$/.test(o.abc.key)||Se(o,`notehead '${o.abc.key}'`);let p=o.abc.accidental,h=o.abc.key.toLowerCase()+(p&&p!=="n"?p:"")+"/"+(o.octave??a);return!i&&e.tab&&Se(o,"a named pitch without an explicit fret on tab"),{range:o.range,written:h,sounding:c??h,position:i,inheritSign:!p&&!o.abc.accidental_type,accidental:p||(o.abc.accidental_type?"n":void 0),cautionary:o.abc.accidental_type==="c"}}let[u,f]=Bt(n,t,s,String(l),a);return{range:o.range,written:u+"/"+f,sounding:c,position:i,...o.prebend&&{prebend:o.prebend},...o.openSlide&&{openSlide:o.openSlide}}}function Gi(o,e,n){let t=o.drums.map(a=>a.id),s=gn(e.clef,e.tab,t,n);s&&be(o,s);let{keys:r}=lt.note(t,"q");return t.map((a,i)=>({drum:a,range:o.drums[i].range,written:r[i],sounding:null}))}function Wi(o,e,n,t,s){let r=new Set;for(let a of n){let i=e.heads[a];i.sounding===null&&be(s,"Only a pitched head can be tied");let l=o?.heads.findIndex((c,u)=>!r.has(u)&&c.position?.str===i.position?.str&&c.position?.fret===i.position?.fret&&(c.written===i.written||(i.inheritSign||c.inheritSign)&&ur(c)===ur(i)))??-1;l<0&&be(s,"Tie needs the same pitch and string on the previous attack"),r.add(l),t.push({id:e.id+"-tie-"+a,from:o.id,to:e.id,fromHead:l,toHead:a,range:s.range})}}function qi(o,e,n){let t=Number(e.params.tuplet),s=Number(e.params.notes??t),r=o.events.length-s;(!Number.isSafeInteger(t)||t<1||!Number.isSafeInteger(s)||s<1||r<0)&&be(e,"Tuplet must fit in this bar and voice");let a=fn(t,n);for(let i of o.events.slice(r))i.duration=dt(i.duration).multiply(a,t).simplify().toString();o.tuplets.push({start:r,count:s,numNotes:t,notesOccupied:a,range:e.range})}function Ui(o,e,n,t,s,r,a,i){let l=new Ae.Tuning(e.tuning),c=new Ae.KeyManager(e.key),u=new Ae.Music,f=[],p=Is(o),h=Rs(n,t,p),E=new Mn(e,a,!i);i?.[0].keyChange&&c.setKey(i[0].keyChange);let k;for(let S of o.notes){if(S.time&&(r.rhythm=zi(S)),S.command==="command"){E.apply(S,h),h.keyChange&&!h.events.length&&c.setKey(h.keyChange);continue}if(S.command==="bar"){let M={type:S.type,range:S.range};!h.events.length&&f.length&&!h.opening&&Se(S,"consecutive barlines"),!h.events.length&&!f.length&&!["single","repeat-begin"].includes(S.type)&&Se(S,"this opening barline"),h.events.length?(h.closing=M,f.push(h),h=Rs(n,t,p),i?.[f.length]?.keyChange&&c.setKey(i[f.length].keyChange)):h.opening&&Se(S,"consecutive empty barlines"),(!f.length||["repeat-begin","repeat-both"].includes(S.type))&&(h.opening=M);continue}if(S.command==="tuplet"){qi(h,S,e.meter);continue}if(["open_beam","close_beam"].includes(S.command)||(S.command&&S.command!=="rest"&&Se(S,S.command),S.command==="rest"&&(S.params.explicit||Number(S.params.position))&&Se(S,"positioned rest"),(S.decorator||S.articulation&&!["T","-"].includes(S.articulation))&&Se(S,`technique '${S.decorator||S.articulation}'`),!S.command&&!S.chord&&!S.drums&&!S.abc&&S.fret===void 0))continue;let P=S.command==="rest"?[]:S.chord??[S];S.chord&&P.some(M=>M.time)&&Se(S,"duration changes inside a chord");let B=S.drums?Gi(S,e,r.rhythm.slash):P.map(M=>{let q=ji(M,e,l,c,u,r.rhythm.slash);return M.marks&&(q.marks=M.marks),q}),j=B.flatMap(M=>M.position?[M.position.str]:[]);new Set(j).size!==j.length&&Se(S,"a multi-stop chord on one string");let{base:A,dots:T,slash:V}=r.rhythm,U=Ae.default.durationToTicks(A),Y=new Ae.Fraction(U,Ae.default.RESOLUTION).multiply(2**(T+1)-1,2**T).simplify().toString(),G={id:"a"+S.range.start,range:S.range,heads:B,base:A,dots:T,rhythmRange:r.rhythm.range,slash:V,duration:Y,onset:"0/1"},R=P.flatMap((M,q)=>S.articulation==="T"||M.articulation==="T"?[q]:[]);Wi(k,G,R,s,S),h.events.push(G),k=G}E.finish(),!h.events.length&&h.boundaryRange&&be({range:h.boundaryRange},"Boundary command needs a following measure"),h.events.length?f.push(h):h.opening&&Se({range:h.opening.range},"a barline without a following measure");for(let S of f){let P=new Ae.Fraction(0,1);for(let B of S.events)B.onset=P.simplify().toString(),P.add(dt(B.duration));S.span=P.simplify().toString()}return f}function Cs(o,e){let n=o.voices[0]?.bars;if(!n?.length)throw new oe("measure","Empty stave",o.node.range);o.state.piano&&!o.voices.some(s=>s.bars[0]?.hand==="left")&&be(o.node,"A piano needs a left hand. Add voice hand=left and write its notes or rests");for(let{bars:s,node:r}of o.voices)if(s.length!==n.length)throw new oe("measure","Voices have different bar counts",r.range);let t=o.state;for(let s=0;s<n.length;s++){n[s].keyChange&&(t={...t,key:n[s].keyChange});let r=o.voices.map(f=>f.bars[s]),i=(s===0?o.state.pickup:void 0)??(o.state.fragment?n[s].span:dt(o.state.meter).toString());for(let f of r){let p=f.closing?.range??f.events[f.events.length-1].range;if(f.span!==i){let h=f!==n[s]?"All voices must fill the same bar":"Declare a pickup or fragment for an intentional partial bar";throw new oe("measure",`Bar ${e.length+1} lasts ${f.span}, expected ${i}. ${h}`,p)}if(f!==n[s]&&((f.closing?.type??"single")!==(n[s].closing?.type??"single")||(f.opening?.type??"single")!==(n[s].opening?.type??"single")))throw new oe("measure","Voice barlines disagree",p)}let l=n[s].events[0],c=n[s].events[n[s].events.length-1],u={...n[s].opening?.range??l.range,end:(n[s].closing?.range??c.range).end};e.push({number:e.length+1,range:u,span:i,state:t,voices:r,newRow:s===0})}}function ur(o){return o.written[0]+o.written.slice(o.written.indexOf("/"))}function Ki(o,e,n){let t=new Ae.Music,s=new Map,r=new Map(e.map(a=>[a.to+"/"+a.toHead,a]));for(let a of o){let i=t.createScaleMap(a.state.key),l=new Map,c=new Map;for(let u of a.voices)for(let f of u.events){let p=c.get(f.onset)??[];p.push({event:f,hand:u.hand}),c.set(f.onset,p)}for(let u of[...c.keys()].sort((f,p)=>dt(f).value()-dt(p).value())){let f=new Map;for(let{event:p,hand:h}of c.get(u))s.set(p.id,p.heads),p.heads.forEach((E,k)=>{if(E.sounding===null)return;let S=ur(E),P=(h??"")+S,B=r.get(p.id+"/"+k),j=B&&s.get(B.from)[B.fromHead];if(E.inheritSign){let T=j?.written.split("/")[0]??l.get(P)??i[S[0]].replace(/n$/,"");if(T==="?")throw new oe("syntax","Write the accidental after a conflicting unison",E.range);E.written=T+S.slice(1),E.position||(E.sounding=E.written)}if(n&&Ie(E.sounding)===void 0)throw new oe("syntax","Transposed note is outside the playable MIDI range",E.range);if(j&&j.written!==E.written)throw new oe("syntax","Tied pitches differ",E.range);let A=E.written.split("/")[0];f.set(P,f.has(P)&&f.get(P)!==A?"?":A)});for(let[p,h]of f)l.set(p,h)}}}function Xi(o){let e=o.options?.find(n=>n.key==="hand");return o.element==="piano"?(e&&e.value!=="right"&&be(e,"Start a piano with the right hand, then add voice hand=left"),"right"):((!e||!["right","left"].includes(e.value))&&be(e??o,"A piano voice needs hand=right or hand=left"),e.value)}function rt(o,e={}){if(e.language===void 0||e.language===2)return Ns(o,e.capacity);if(e.language!==1)throw new RangeError("Expected VexTab language 1 or 2");let n=Wt(o,!0),t=[],s=[],r=[],a={rhythm:{base:"q",dots:0,slash:!1}},i={},l;for(let u of n){if(u.element==="options"){let p=u.params.find(E=>["tempo","instrument","player"].includes(E.key));l&&p&&be(p,"Set flow playback options before the first stave");let h=u.params.find(E=>E.key==="measure-numbers");l&&h&&be(h,"Set measure numbering before the first stave"),Di(i,u);continue}if(u.element!=="voice"||!l)l&&Cs(l,t),l={node:u,state:Hi(u),voices:[]};else for(let p of u.options??[])!["voice","fingering","accents"].includes(p.key)&&!(l.state.piano&&p.key==="hand")&&Se(p,`voice option '${p.key}'`);u.text?.length&&Se({range:u.text[0].declaration},"timed text"),u.slurs?.length&&Se(u.slurs[0],"slur");let f=u.options?.find(p=>p.key==="voice")?.value;if(f&&!["top","bottom","new"].includes(f)&&be(u,"Invalid voice direction"),u.notes?.length){let p=l.state.piano?Xi(u):void 0,h=p?{rhythm:{base:"q",dots:0,slash:!1}}:a,E=Ui(u,l.state,i,f,s,h,r,l.voices[0]?.bars);if(p)for(let k of E)k.hand=p;l.voices.push({bars:E,node:u})}else(u.element==="voice"||u.element==="piano")&&be(u,"Empty voice")}l||be(n[0],"Expected a stave"),Cs(l,t),Ki(t,s,!!Number(i.transpose)),Pn(t,r);let c={source:o,measures:t,ties:s,spans:r,measureNumbers:i["measure-numbers"]==="true"};return(i.player||i.tempo||i.instrument)&&(c.playback={enabled:i.player==="true",tempo:i.tempo?Number(i.tempo):void 0,instrument:i.instrument}),c}var _n=class{constructor(e){this.artist=e}newError(e,n){return new Z.RERR("ParseError",`${n} in line ${e._l} column ${e._c}`)}parseStaveOptions(e,n="voice"){let t={};if(!e)return t;let s=null;e.forEach(i=>{let l=c=>this.newError(i,c);switch(t[i.key]=i.value,i.key){case"fingering":case"accents":break;case"notation":case"tablature":if(s=i,!["true","false"].includes(i.value))throw l(`'${i.key}' must be 'true' or 'false'`);break;case"color":if(n==="voice"||!Be(i.value))throw l("Expected a stave color as a CSS name or hex value");break;case"pickup":if(!/^([1-9]\d*)\/([1-9]\d*)$/.test(i.value))throw l("Expected a pickup span such as 1/4");break;case"fragment":if(!["true","false"].includes(i.value))throw l("fragment must be true or false");break;case"show-time":if(!["true","false"].includes(i.value))throw l("show-time must be true or false");break;case"key":{if(!(Z.Flow?.hasKeySignature?Z.Flow.hasKeySignature(i.value):Dn(Z.Flow?.keySignature?.keySpecs,i.value)))throw l(`Invalid key signature '${i.value}'`);break}case"clef":{let c=["treble","bass","tenor","alto","percussion","none"];if(!c.includes(i.value))throw l(`'clef' must be one of ${c.join(", ")}`);break}case"voice":{let c=["top","bottom","new"];if(!c.includes(i.value))throw l(`'voice' must be one of ${c.join(", ")}`);break}case"time":try{sr(i.value)}catch{throw l(`Invalid time signature: '${i.value}'`)}break;case"tuning":try{new Z.Flow.Tuning(i.value)}catch{throw l(`Invalid tuning: '${i.value}'`)}break;case"capo":if(!/^\d+$/.test(i.value)||!Number.isSafeInteger(Number(i.value)))throw l("Expected a nonnegative capo fret");break;case"strings":{let c=Number(i.value);if(!Number.isInteger(c)||c<4||c>8)throw l(`Invalid number of strings: ${c}`);break}default:throw l(`Invalid option '${i.key}'`)}});let r=t.notation??(n==="tabstave"?"false":"true"),a=t.tablature??(n==="stave"?"false":"true");if(r==="false"&&a==="false")throw this.newError(s,"Both 'notation' and 'tablature' can't be invisible");return t}parseCommand(e){e.command==="bar"&&this.artist.addBar(e.type),e.command==="tuplet"&&this.artist.makeTuplets(e.params.tuplet,e.params.notes),e.command==="annotations"&&this.artist.addAnnotations(e.params),e.command==="rest"&&this.artist.addRest(e.params),e.command==="command"&&this.artist.runCommand(e.params,e._l,e._c)}parseChord(e){this.artist.log("parseChord:",e),this.artist.addChord(_r(e.chord,n=>nn(n,"time","dot","fret","prebend","openSlide","marks","abc","octave","string","articulation","decorator")),e.articulation,e.decorator)}parseFret(e){this.artist.addNote(nn(e,"time","dot","fret","prebend","openSlide","marks","string","articulation","decorator"))}parseABC(e){this.artist.addNote(nn(e,"time","dot","fret","prebend","openSlide","marks","abc","octave","string","articulation","decorator"))}parseStaveElements(e){this.artist.log("parseStaveElements:",e);let n=fe(this.artist.staves),t=fe(n.voiceSettings),s;if(e.forEach(r=>{if(t.options.beams==="explicit"){if(r.command==="open_beam"){if(s)throw this.newError(r,"Nested beam group");s={index:n.tab_notes.length,token:r}}if(r.command==="close_beam"){if(!s)throw this.newError(r,"Missing opening beam bracket");let a=n.tab_notes.slice(s.index);if(a.length<2||a.some(i=>i.getIntrinsicTicks()>=Z.Flow.RESOLUTION/4))throw this.newError(r,"Beams need at least two eighth notes or shorter values");t.groups.push([s.index,n.tab_notes.length]),s=void 0}if(s&&r.command==="bar")throw this.newError(r,"Beam crosses a barline")}if(r.time&&this.artist.setDuration(r.time,r.dot),r.command&&this.parseCommand(r),r.drums){let a=r.drums.map(l=>l.id),i=gn(this.artist.current_clef,!!n.tab,a,this.artist.current_head==="s");if(i)throw this.newError(r,i);this.artist.notes.addDrums(a)}r.chord&&this.parseChord(r),r.abc?this.parseABC(r):r.fret&&this.parseFret(r)}),s)throw this.newError(s.token,"Missing closing beam bracket")}parseStaveText(e){De(e)||this.artist.addTextVoice();let n=0,t="center",s=!0,r=null,a=()=>this.artist.addTextNote("",0,t,!1,!0),i=(l,c)=>{let u=!1,f=l;f[0]==="|"&&(u=!0,f=f.slice(1));try{this.artist.addTextNote(f,n,t,s,u)}catch(p){throw this.newError(c,`Bad text or duration. Did you forget a comma?${p}`)}};e.forEach(l=>{let c=l.text.trim();if(c.match(/\.font=.*/))r=c.slice(6),this.artist.setTextFont(r);else if(c[0]===":")this.artist.setDuration(c.slice(1));else if(c[0]==="."){let u=c.slice(1);switch(u){case"center":case"left":case"right":t=u;break;case"strict":s=!1;break;case"smooth":s=!0;break;case"bar":case"|":a();break;default:if(!/^[+-]?\d+$/.test(u))throw this.newError(l,`Invalid text position '${u}'`);n=Number(u);break}}else c==="|"?a():c.slice(0,2)==="++"?this.artist.addTextVoice():i(c,l)})}generate(e){e.forEach(n=>{switch(n.element){case"piano":throw this.newError(n,'Use layout="flow" or parseScore for a piano grand staff');case"stave":case"tabstave":this.artist.addStave(n.element,this.parseStaveOptions(n.options,n.element)),n.notes&&this.parseStaveElements(n.notes),n.text&&this.parseStaveText(n.text);break;case"voice":this.artist.addVoice(this.parseStaveOptions(n.options,n.element)),n.notes&&this.parseStaveElements(n.notes),n.text&&this.parseStaveText(n.text);break;case"options":{let t={};n.params.forEach(s=>{s.key!=="transpose"&&(t[s.key]=s.value)}),this.artist.setOptions(t,(s,r)=>this.newError(n.params.find(a=>a.key===s),r));break}default:throw this.newError(n,`Invalid keyword '${n.element}'`)}})}};function Yi(o){return typeof o?.addStave=="function"}var Ke=class o{constructor(e,n){this.valid=!1;if(Yi(e)){if(n?.language!==1)throw new TypeError("Use new VexTab(artist, { language: 1 }) for fixed engraving, or new VexTab() and renderScore() for language 2.");this.artist=e,this.compiler=new _n(e)}else{if(n||e?.language===1)throw new TypeError("Language 1 fixed engraving requires new VexTab(artist, { language: 1 }).");if(e?.language!==void 0&&e.language!==2)throw new RangeError("Expected VexTab language 1 or 2");this.capacity=e?.capacity}}static{this.DEBUG=!1}reset(){this.valid=!1}isValid(){return this.valid}getArtist(){return this.artist}parse(e=""){this.reset(),o.DEBUG&&console.log(`(Vex.Flow.VexTab) Parsing:
|
|
371
|
-
`+e);let n=this.compiler?this.parseFixed(e):rt(e,{language:2,capacity:this.capacity});return this.valid=!!n,n}parseFixed(e){let n;try{n=Wt(e)}catch(t){throw t instanceof oe?Object.assign(new Z.RERR("ParseError",t.message),{range:t.range}):t}return n&&this.compiler.generate(n),n}};function st(o,{partId:e,partIndex:n}){if(e===void 0)return n??0;let t=o.parts.findIndex(s=>s.id===e);if(t<0)throw new RangeError("No instrument with part ID "+e);if(n!==void 0&&n!==t)throw new RangeError("partIndex and partId select different instruments");return t}function Fs(o,e){let n=e==="right"?"upper":e==="left"?"lower":"main";return{role:n,staff:o.instrument?.staves[n]}}function Bs(o,e,n){let{role:t,staff:s}=Fs(o,e);if(!n&&t==="main")return{};let r=(l,c)=>[l,c].filter(Boolean).join(" ")||(c===""?"":void 0),a=r(n&&o.instrument?.name,s?.name),i=r(n&&(o.instrument?.shortName??o.instrument?.name),s?.shortName??s?.name);return a===void 0&&i===void 0?{}:{name:a??i,shortName:i??a}}function Ji(o){let e=o[0].measures;for(let[n,t]of o.entries()){let s=t.measures,r=t.instrument?.name??t.instrument?.id??"part "+(n+1);for(let a=0;a<Math.max(e.length,s.length);a++)if(!s[a]||!e[a]||s[a].span!==e[a].span){let i=s[a]??s[s.length-1];throw new oe("fixed-layout","Conductor measures must share a span: "+r+", bar "+(a+1),s[a]&&e[a]&&s[a].state.meter!==e[a].state.meter?i.state.timeRange:i.range)}}}function $i(o,e){return e[0].continuous.boundaries.map((n,t)=>{let s={...n};for(let r=1;r<e.length;r++){let a=e[r].continuous.boundaries[t];if(a.breakBefore&&(s.breakBefore=a.breakBefore),a.repeatStart&&(s.repeatStart=!0),a.repeatEnd&&(s.repeatEnd=!0),a.rehearsal){if(s.rehearsal&&s.rehearsal!==a.rehearsal)throw new oe("fixed-layout","Conflicting conductor rehearsal marks",o[r].measures[t].range);s.rehearsal=a.rehearsal}}return s})}function dr(o,e){Ji(o);function n(i,l){let c=o[i],{role:u,staff:f}=Fs(c,l),p=(c.instrument?.id??i+1)+"."+(f?.id??u);return u==="main"&&c.measures[0].state.tab?p+"."+l:p}let t=e.flatMap((i,l)=>i.staves.map(c=>({...c,id:n(l,c.id),measures:c.measures.map(u=>({...u,voices:u.voices.map(f=>({...f,notes:typeof f.notes=="string"?f.notes:f.notes.map(p=>typeof p=="object"&&"stave"in p&&typeof p.stave=="string"?{...p,stave:n(l,p.stave)}:p)}))}))}))),s=e.flatMap((i,l)=>i.continuous.groups.map(c=>({...c,first:n(l,c.first),last:n(l,c.last)}))),r=new Map(o.map((i,l)=>[i.instrument?.id,l])),a=o[0].groups??[];for(let i of a){let l=i.parts.map(p=>r.get(p)).filter(p=>p!==void 0);if(l.length<2)continue;let c=l[0],u=l[l.length-1],f=e[u].staves;s.push({type:i.type,first:n(c,e[c].staves[0].id),last:n(u,f[f.length-1].id),barlines:!0})}return!a.length&&o.length>1&&s.push({first:t[0].id,last:t[t.length-1].id,type:"bracket",barlines:s.length===0}),{...e[0],staves:t,engraving:{prepareNote(i,l,c){for(let u of e)u.engraving?.prepareNote?.(i,l,c)},place(i,l){for(let c of e)c.engraving?.place?.(i,l)}},continuous:{...e[0].continuous,groups:s,inkBounds:(i,l)=>e.flatMap(c=>c.continuous.inkBounds?.(i,l)??[]),verticalSpacing:e.some(i=>i.continuous.verticalSpacing==="profile")?"profile":e[0].continuous.verticalSpacing,boundaries:$i(o,e),opening:{...e[0].continuous.opening,blocks:[...e[0].continuous.opening?.blocks??[],...e.slice(1).flatMap(i=>(i.continuous.opening?.blocks??[]).filter(l=>l.kind==="diagrams"))]},ossias:e.flatMap(i=>i.continuous.ossias??[]),splitChords:e.flatMap(i=>i.continuous.splitChords??[]),spans:e.flatMap(i=>i.continuous.spans)}}}function Vs(o,e,n){let t=s=>s.map(r=>r.slice(e,e+n));return{...o,staves:t(o.staves),notes:t(o.notes),voices:t(o.voices)}}function Yt(o){return[...o.lyric?[o.lyric]:[],...o.verses??[]]}function Os(o,e){let n=o.flatMap((s,r)=>s.events.map(a=>({event:a,bar:r}))),t=new Map;for(let s=n.length-1;s>=0;s--){let{event:r,bar:a}=n[s];for(let i of Yt(r)){let l=i.verse??"",c=i.hyphen?t.get(l):i.extend?s+i.extend:s;if(!n[c]||!i.text.trim()||i.elideWith!==void 0&&!i.elideWith.trim()||!r.heads.length&&r.silent)throw new oe("measure","Lyric needs a visible note or rest, text and a valid following endpoint",i.range);a!==n[c].bar&&(i.crossConnector=!0,e.push({kind:i.hyphen?"hyphen":"lyric",lane:l,from:r.id,to:n[c].event.id,id:"verse-"+l+"-"+r.id,range:i.range})),t.set(l,s)}}}var xe=Ee(Pe());function fr(o){let e=[0],n=/\r\n|\r|\n/g;for(;n.exec(o);)e.push(n.lastIndex);return([t,s])=>{let r=0,a=e.length;for(;r+1<a;){let i=Math.floor((r+a)/2);e[i]<=t?r=i:a=i}return{start:t,end:s,line:r+1,column:t-e[r]}}}function Ls(o){let[e,n]=o.split("/").map(Number),t=[1,3,7].indexOf(e),s=n/2**t;return{base:{1:"w",2:"h",4:"q"}[s]??String(s),dots:t}}var Hs=new WeakMap;function Xe(o,e=0){if(!Number.isInteger(e)||!o.parts[e])throw new RangeError("No instrument at partIndex "+e);let n=Hs.get(o);n||Hs.set(o,n=new Map);let t=n.get(e);if(t)return t;let s=o.parts[e],r=fr(o.source),a=r(s.range),{id:i,name:l,shortName:c,sounds:u}=s,p=(i!==void 0||l!==void 0||c!==void 0||u!==void 0||s.staves.some(C=>C.id!==void 0||C.displayName!==void 0||C.shortName!==void 0||C.sounds!==void 0))&&{id:i,name:l,shortName:c,sounds:u,staves:Object.fromEntries(s.staves.map(C=>[C.name,{id:C.id,name:C.displayName,shortName:C.shortName,sounds:C.sounds}]))},h=new xe.Tuning(s.tuning??"standard"),E=new xe.Music,k=s.key??"C",S=new xe.KeyManager(k),P=new Map,B=s.capo??0,j=s.staves.some(C=>C.voices.some(K=>K.events.some(ne=>ne.heads.some(H=>"pitch"in H))));if(j&&(s.view==="tab"||s.view==="both"))throw new oe("measure","A tab view needs a string and fret for every pitch",a);function A(C,K){if(!Be(C))throw new oe("measure","Expected a CSS color name or hex code",K);return C}let T=s.tuning??"standard",V=s.staves[0].voices[0].measures[0],U=V.meter??o.meter,Y=V.meterRange??o.meterRange,G={declaration:a,color:s.ink&&s.ink!=="default"?A(s.ink,a):void 0,timeRange:r(Y??s.range),meter:U,showTime:!!Y,tab:s.kind==="guitar"&&s.view!=="notation"&&!j,notation:s.view!=="tab",piano:s.kind==="piano",tuning:T,strings:(xe.Tuning.names[T]??T).split(",").length,capo:B,key:s.key??"C",hideClef:s.clef==="none",clef:s.kind==="drums"?"percussion":s.clef==="none"?"treble":s.clef??"treble",pickup:o.pickup,fragment:!1},R=[],M={...o.groups&&{groups:o.groups},...p&&{instrument:p},source:o.source,measures:R,ties:[],spans:[],playback:o.playback,layout:o.layout,measureNumbers:o.measureNumbers??!1};M.program=s.program;let q=s.drums?.length?new xe.PercussionMap([...xe.PercussionMap.kit,...s.drums]):lt;s.kind==="drums"&&(G.kit=q);let v=new xe.Fraction().parse(U).simplify().toString(),_=new Map;function O(C){if(!C||s.kind==="drums")return;let K=k+"/"+C;return _.has(K)||_.set(K,new bt(C,k)),_.get(K)}function W(C,K){let ne=r(C.range),H=[],re;if("drum"in C)re={drum:C.drum,midi:s.drums?.find(F=>F.id===C.drum)?.midi,written:q.note([C.drum],"q").keys[0],sounding:null,range:ne};else if("pitch"in C){let F=C.pitch[0].toLowerCase(),b=C.pitch.slice(1,-1);S.reset();let g=b?F+(b==="n"?"":b):S.getAccidental(F).note,y=K?K.pitch(g,Number(C.pitch.slice(-1))):g+"/"+C.pitch.slice(-1);re={written:y,sounding:y,range:ne}}else{if(C.string>G.strings)throw new oe("measure","String outside the tuning",ne);let F={str:C.string,fret:C.fret==="x"?"X":C.fret+(K?.semitones??0)};if(typeof F.fret=="number"&&F.fret<0)throw new oe("measure","Transposition puts fret outside the original string",ne);let g=(C.marks.find(x=>x.kind==="prebend")?.semitones??0)+(typeof F.fret=="number"?F.fret:0)+B,y=K?.target??k;P.has(y)||P.set(y,new xe.KeyManager(y));let[I,D]=Bt(h,P.get(y),E,String(g),C.string);re={position:F,written:I+"/"+D,sounding:C.fret==="x"?null:dn(h,g,C.string),range:ne}}s.cautionary&&re.position&&re.written.split("/")[0].length>1&&(re.accidental=re.written.split("/")[0].slice(1),re.cautionary=!0);for(let F of C.marks){if(F.kind==="velocity"&&(re.velocity=F.value),F.kind==="sustain"&&(re.sustain=F.duration),F.kind==="prebend"&&(re.prebend={semitones:F.semitones,release:F.release}),(F.kind==="slideIn"||F.kind==="slideOut")&&(re.openSlide={edge:F.kind==="slideIn"?"in":"out",side:F.side}),F.kind==="write"){if(!re.position)throw new oe("measure","A written-pitch override needs a fretted head",r(F.range));let b=F.pitch[0].toLowerCase(),g=F.pitch.slice(1,-1),y=g?b+(g==="n"?"":g):S.getAccidental(b).note;re.written=K?K.pitch(y,Number(F.pitch.slice(-1))):y+"/"+F.pitch.slice(-1)}F.kind==="gliss"&&(re.glissFrom=F.fromHead),F.kind==="release"&&(re.release=F),F.kind==="sign"&&H.push({articulation:F.code,position:F.position}),(F.kind==="finger"||F.kind==="stringNumber")&&H.push({finger:String(F.value),stringNumber:F.kind==="stringNumber",position:F.side})}for(let F of C.marks)(F.kind==="courtesy"||F.kind==="showSign")&&(re.accidental=re.written.split("/")[0].slice(1)||"n",re.cautionary=F.kind==="courtesy");for(let F of C.marks)(F.kind==="hammer"||F.kind==="pull"||F.kind==="slide")&&(re.connection=F.kind);if("hammerFrom"in C&&C.hammerFrom&&(re.hammer=!0),H.length&&(re.marks=H),re.sounding&&Ie(re.sounding)===void 0)throw new oe("measure","Pitch outside MIDI range",ne);return re}function J(C,K){let ne=C.pitches.map(F=>(Array.isArray(F)?F:[F]).map(b=>W({...typeof b=="string"?{pitch:b}:b,marks:[],range:C.range},K))),H=ne.some(F=>F.some(b=>b.position));if(H&&(s.kind!=="guitar"||ne.some(F=>F.some(b=>!b.position))))throw new oe("measure","Write every guitar grace head as a fret/string, or use written pitches throughout",r(C.range));if(!H&&!G.notation)throw new oe("measure","TAB grace notes need explicit fret/string positions",r(C.range));let re=H?ne.map(F=>F.map(b=>b.position)):void 0;if(re?.some(F=>new Set(F.map(b=>b.str)).size!==F.length))throw new oe("measure","A grace chord may use each string once",r(C.range));return{side:C.side,slash:C.slash,...C.steal&&{steal:C.steal},positions:re,fingerings:C.fingerings,pitches:ne.map((F,b)=>Array.isArray(C.pitches[b])?F.map(g=>g.written):F[0].written)}}function ae(C,K){let ne=O((o.transpose??0)+(C.transpose??0));for(let g of[C.marks,...C.heads.map(y=>y.marks)]){let y=qt(g);if(y)throw new oe("measure",y.reason,r(y.range))}let H=C.heads.map(g=>W(g,ne)),re=O((K??0)+12*(C.soundingOctaves??0));if(K!==void 0||C.soundingOctaves)for(let g of H){if(!g.sounding)continue;let y=K===void 0?g.sounding:g.written,[I,D]=y.split("/");if(g.sounding=re?re.pitch(I,Number(D)):y,Ie(g.sounding)===void 0)throw new oe("measure","Sounding pitch exceeds the MIDI range after the octave or instrument shift",g.range)}if(C.kind==="slash"){if(G.tab)throw new oe("measure","Give a slash a notation-only staff",r(C.range));H.push({written:"b/4",sounding:null,range:r(C.range)})}let F={id:C.id,range:r(C.range),heads:H,slash:C.kind==="slash",onset:C.at,duration:C.duration,...Ls(C.writtenDuration)};C.rhythmRange&&(F.rhythmRange=r(C.rhythmRange)),C.kind==="skip"&&(F.silent=F.range),C.heads.forEach((g,y)=>{for(let I of g.marks)if(I.kind==="bend"&&"string"in g){let D=r(I.range),x=H.map(m=>m.position);if(H[y].bend||H[y].prebend||x.some(m=>!m||typeof m.fret!="number"))throw new oe("measure","A bend needs pitched frets and one contour per string",D);let d={string:g.string,semitones:I.semitones,rise:I.rise,release:I.release,hold:I.hold};try{new xe.FrettedInstrument(G.tuning,B).bentAttack(x,F.base,d)}catch(m){throw new oe("measure",m.message,D)}H[y].bend=d,F.bend??={spec:d,range:D}}});for(let g of C.marks){if(g.kind==="slash"){if(!H.length)throw new oe("measure","A slash needs a written head",r(g.range));F.slash=!0}if(g.kind==="lyric"){let y={...g,range:r(g.range)};g.verse?(F.verses??=[]).push(y):F.lyric=y}if(g.kind==="harmony"){let{root:y,bass:I,quality:D}=g;F.harmony=xe.NotationSpelling.transposeChord({root:y,quality:D,bass:I},ne?.semitones??0,ne?.steps??0),F.chord={text:xe.NotationSpelling.chordText(F.harmony),range:r(g.range)}}if(g.kind==="stem"){if(!H.length)throw new oe("measure","A stem needs a written head",r(g.range));F.stem=g.value}if(g.kind==="dynamic"&&(F.dynamic=g.value),(g.kind==="ossia"||g.kind==="ornament"||g.kind==="grace")&&(!H.length||!G.notation&&g.kind!=="grace"||H.some(y=>!!y.drum)))throw new oe("measure","Grace notes, ornaments and ossias need a pitched notation anchor",r(g.range));if(g.kind==="ornament"&&(F.ornament=g.value),g.kind==="onStaff"||g.kind==="sharedStem"){if(!G.piano||g.kind==="sharedStem"&&!H.length)throw new oe("measure","Staff assignments need piano and a shared stem needs pitched notes",r(g.range));g.kind==="onStaff"?F.displayHand=g.hand==="upper"?"right":"left":F.sharedStem=g.name}if(g.kind==="grace"&&(F.grace=J(g,ne)),g.kind==="ossia"&&(F.ossia={duration:g.duration,notes:g.notes.map(y=>({key:W({pitch:y.pitch,range:g.range,marks:[]},ne).written,ornament:y.ornament}))}),g.kind==="symbol"&&(F.chord={text:ne?er(g.text,ne):g.text,color:g.ink&&A(g.ink,r(g.range)),range:r(g.range)}),g.kind==="line"){if(C.kind!=="rest")throw new oe("measure","Only a rest takes a staff line",r(g.range));F.restLine=g.value}if(g.kind==="ink"&&(F.color=A(g.value,r(g.range))),g.kind==="label"){let y=g.style;(F.labels??=[]).push({text:g.text,...y,range:r(g.range),ink:y.ink&&A(y.ink,r(g.range))})}if((g.kind==="tap"||g.kind==="vibrato"||"direction"in g)&&(F.gestures??=[]).push(g),g.kind==="accent"){if(!H.length)throw new oe("measure","Accent needs a head",r(g.range));(H[0].marks??=[]).push({position:"above"})}}let b=C.marks.find(g=>g.kind==="frame"||g.kind==="diagram");if(b?.kind==="frame"||b?.kind==="diagram"){let g=ne?.semitones??0,y=b.frets.map(d=>d==="x"?d:d+g),I=b.barre,D=I&&I[0]+g!==0?" barre="+(I[0]+g)+":"+I[1]+"-"+I[2]:"",x=r(b.range);if(b.kind==="diagram"&&C.kind!=="attack"&&C.kind!=="rest")throw new oe("measure","Anchor the chord diagram to a note or rest",x);F.frame={range:x,spec:lr(y.join(",")+D,F,G,x,b.kind)}}return F}let L=new Map;function X(C){return C.trace.flatMap(K=>"pattern"in K?["p"+K.range[0]]:"iteration"in K?["r"+K.range[0]+":"+K.iteration]:[]).join("/")}function se(C,K,ne){let H=K.find(D=>D.start),re=K.find(D=>!D.start),F=K.find(D=>D!==H&&D!==re);if(F)throw new oe("measure","Duplicate tie endpoint "+C,F.range);if(!H||!re)throw new oe("measure","Unpaired tie "+C,(H??re).range);let b=H.event.heads[H.index],g=re.event.heads[re.index];if(!(H.bar<re.bar||H.bar===re.bar&&new xe.Fraction().parse(H.event.onset).lessThan(new xe.Fraction().parse(re.event.onset)))||b.sounding===null||b.written!==g.written||b.sounding!==g.sounding||b.position?.str!==g.position?.str||H.hand!==re.hand)throw new oe("measure","Named tie needs a later matching head on the same staff",re.range);let I="named-tie-"+C+(ne?"-"+H.event.id:"");M.ties.push({id:I,from:H.event.id,fromHead:H.index,to:re.event.id,toHead:re.index,...H.side&&{side:H.side},range:re.range})}function ee(){for(let[C,K]of L){if(K.length<=2){se(C,K,!1);continue}let ne=new Map([["",[]]]),H=re=>re.slice(0,Math.max(0,re.lastIndexOf("/")));for(let re of K){for(let F=re.scope;!ne.has(F);F=H(F))ne.set(F,[]);ne.get(re.scope).push(re)}for(let re of[...ne.keys()].sort((F,b)=>b.length-F.length)){let F=ne.get(re);F.length&&(F.length===1&&re?ne.get(H(re)).push(F[0]):se(C,F,!0))}}}function Q(C,K,ne,H=[]){let re=[],F={...s,...C.settings},b=0,g=ne==="left"?"bass":s.clef??"treble",y=[],I=0;function D(N){N.key&&(k=N.key,S=new xe.KeyManager(k),G.key=O(o.transpose)?.target??k),N.clef&&(g=N.clef),N.sounds!==void 0&&(K=N.sounds)}let x,d;function m(N){for(;I<y.length&&!new xe.Fraction().parse(y[I].at).greaterThan(new xe.Fraction().parse(N.at));)D(y[I++]);let z=ae(N,K);H.length&&(z.writtenClef=g,z.activeKey=G.key);for(let ue of N.marks){if(ue.kind!=="pedal")continue;let le=r(ue.range);if(!G.piano||N.kind==="skip")throw new oe("measure","Place pedal marks on piano notes or rests",le);if(ue.action==="down"){if(d)throw new oe("measure","Lift the pedal before pressing again",le);d=z}else{if(!d)throw new oe("measure","Pedal up needs an earlier pedal down in this voice",le);M.spans.push({kind:"pedal",...ue.onset&&{onset:!0},from:d.id,to:z.id,id:"pedal-"+d.id,range:le}),d=void 0}}let ie=new Set;return N.heads.forEach((ue,le)=>{for(let we of ue.marks){if(we.kind!=="tieStart"&&we.kind!=="tieEnd")continue;let _e=L.get(we.name)??[];_e.length||L.set(we.name,_e),_e.push({event:z,index:le,bar:N.bar,hand:ne,range:r(we.range),scope:X(N),side:we.side,start:we.kind==="tieStart"})}let me=z.heads[le].glissFrom;if(me!==void 0){if(!x?.heads[me])throw new oe("measure","Missing previous glissando head",z.heads[le].range);M.spans.push({kind:"glissando",id:"gliss-"+z.id+"-"+le,from:x.id,fromHead:me,to:z.id,toHead:le,range:z.heads[le].range})}let ye=ue.marks.find(we=>we.kind==="tie");if(!ye)return;let ve=r(ye.range),Me=z.heads[le],Le=x?.heads.findIndex((we,_e)=>!ie.has(_e)&&Me.sounding&&we.written===Me.written&&we.sounding===Me.sounding&&we.position?.str===Me.position?.str)??-1;if(Le<0)throw new oe("measure","Tie needs a matching preceding pitch and string",ve);ie.add(Le),M.ties.push({id:"tie-"+z.id+"-"+le,from:x.id,fromHead:Le,to:z.id,toHead:le,range:ve})}),x=z,z}k=s.key??"C",S=new xe.KeyManager(k),G.key=O(o.transpose)?.target??k,G.tuning=T,h=new xe.Tuning(T),G.color=s.ink==="default"?void 0:s.ink;let w=s.displayMeter;for(let N of C.measures){s.keys?.[N.number]&&(k=s.keys[N.number],S=new xe.KeyManager(k),G.key=O(o.transpose)?.target??k);let z=r(N.barlineRange),ie=s.changes?.[N.number];if(ie?.tuning){if((xe.Tuning.names[ie.tuning]??ie.tuning).split(",").length!==G.strings)throw new oe("measure","A tuning change must keep the same string count",z);G.tuning=ie.tuning,h=new xe.Tuning(ie.tuning)}ie?.ink&&(G.color=ie.ink==="default"?void 0:A(ie.ink,z)),ie?.displayMeter!==void 0&&(w=ie.displayMeter);let ue=N.span??(N.number===1&&o.pickup?o.pickup:v),le=N.meter??U;for(y=[],I=0;b<H.length&&H[b].bar===N.number;){let Ye=H[b++];Ye.at==="0/1"?D(Ye):y.push(Ye)}let me=o.transpose?y.map(Ye=>Ye.key?{...Ye,key:new bt(o.transpose,Ye.key).target}:Ye):y,ye={key:G.key,clef:g,changes:me},ve={declaration:r(C.range),hand:ne,span:ue,events:C.events.slice(N.start,N.end).map(m),tuplets:[],stem:F.stem,beams:F.beam??!0,flatBeams:F.flatBeams,beamRests:F.beamRests??!0,beatGroups:F.beatGroups,stemlets:F.stemlets??!1,middleRests:F.middleRests??!1,tabStems:F.tabStems??!1,rehearsal:N.rehearsal,opening:N.opening?{type:N.opening,range:z}:void 0,closing:N.closing?{type:N.closing,range:z}:void 0,tabDirection:F.tabDirection==="down"?-1:1},Me=R[N.number-2]?.state,Le=Me?.meter!==le||Me?.meterSign!==N.meterSign,we=R[N.number-1]??={number:N.number,range:z,state:{...G,key:ye.key,fragment:!!N.fragment,meter:le,meterSign:N.meterSign,timeRange:N.meterRange?r(N.meterRange):G.timeRange,showTime:w!==!1&&(N.number===1?w||G.showTime:Le||ie?.displayMeter===!0)},span:ue,newRow:!!N.newRow,voices:[]};for(H.length&&((we.staffState??={})[ne??"notation"]=ye);I<y.length;)D(y[I++]);we.newRow||=!!N.newRow;let _e=we.voices[0];if(_e){if(ve.rehearsal&&_e.rehearsal&&ve.rehearsal!==_e.rehearsal||ve.opening&&_e.opening&&ve.opening.type!==_e.opening.type||ve.closing&&_e.closing&&ve.closing.type!==_e.closing.type)throw new oe("measure","Voices disagree about a shared bar boundary",z);_e.rehearsal??=ve.rehearsal,_e.opening??=ve.opening,_e.closing??=ve.closing}we.voices.push(ve),re.push(ve)}if(d)throw new oe("measure","Missing pedal up",d.range);Os(re,M.spans),te(C),de(C,re)}function te(C){for(let K of C.repeats??[]){let ne=M.repeats?.find(b=>b.first===K.first&&b.bodyEnd===K.bodyEnd);if(ne&&ne.count!==K.count)throw new oe("measure","Voices disagree about the repeat count",r(K.range));M.repeats?.some(b=>b.first===K.first&&b.bodyEnd===K.bodyEnd&&b.count===K.count&&b.endings.length===K.endings.length&&b.endings.every((g,y)=>g.last===K.endings[y].last))||(M.repeats??=[]).push(K);let H=r(K.range),re=K.endings[K.endings.length-1]?.last??K.bodyEnd;if(R.slice(K.first-1,re).some(b=>!b.voices[0].events.length))throw new oe("measure","An ending needs sounding or resting measures",H);let F=R[K.first-1].voices[0];if(F.opening={type:"repeat-begin",range:H},K.count){let b=R[K.bodyEnd-1].voices[0];b.closing={type:"repeat-end",range:H};let g=b.events[b.events.length-1],y="\xD7"+K.count;g.labels?.some(I=>I.text===y)||(g.labels??=[]).push({text:y,position:"above",range:H})}K.endings.forEach((b,g)=>{let y=R[b.last-1].voices[0];g<K.endings.length-1&&(y.closing={type:"repeat-end",range:H});let I=R[b.first-1].voices[0].events[0].id,D="ending-"+I,x=M.spans.find(d=>d.id===D);if(x){if(x.kind!=="volta"||x.lastBar!==b.last||x.label!==g+1+".")throw new oe("measure","Voices disagree about repeat endings",H)}else M.spans.push({kind:"volta",id:D,label:g+1+".",firstBar:b.first,lastBar:b.last,from:I,to:y.events[y.events.length-1].id,range:H})})}}function de(C,K){let ne=new Map(C.events.map((H,re)=>[H.id,re]));for(let H of C.spans){let re=r(H.range);if(H.kind==="continuousBeam"||H.kind==="crescendo"||H.kind==="diminuendo"||H.kind==="tremolo"){if(!G.notation)throw new oe("measure","This expression span needs a notation staff",re);if(M.spans.push({kind:H.kind,from:H.first,to:H.last,niente:H.niente,...H.side&&{side:H.side},strokes:H.strokes,range:re,id:H.kind+"-"+H.first+(H.name?"-"+H.name:"")}),H.kind==="tremolo"||H.kind==="continuousBeam"){let F,b=ne.get(H.last);for(let g=ne.get(H.first);g<=b;g++){let y=C.events[g].bar-1,I=K[y],D=I.events[g-C.measures[y].start];if(H.kind==="tremolo")D.tremolo=H.strokes;else{if(D.displayHand&&D.displayHand!==I.hand)throw new oe("measure","A continuous beam must stay on its owning staff",re);let x=D.heads[0]?.drum,d=D.stem??I.stem??(x&&q.instruments.find(m=>m.id===x)?.stem);if(d&&F&&d!==F)throw new oe("measure","Stems in a continuous beam must agree in direction",re);d&&(F=d),D.continuousBeam=!0}}}}else if(H.kind==="slur"||H.kind==="palmMute"){if(H.kind==="palmMute"&&H.strings.some(F=>F>G.strings))throw new oe("measure","Mute outside the instrument tuning",re);M.spans.push({kind:H.kind,from:H.first,to:H.last,side:H.side,strings:H.strings,range:re,id:H.kind+"-"+H.first+(H.name?"-"+H.name:"")})}else if(H.kind==="beam"||H.kind==="feather"){let F=ne.get(H.first),b=ne.get(H.last),g=C.measures[C.events[F].bar-1];(K[g.number-1].beamGroups??=[]).push({start:F-g.start,end:b-g.start,feather:H.kind==="feather"?H.feather:void 0,range:re})}else if("to"in H)M.spans.push({kind:H.kind,id:H.kind+"-"+H.to.event+"-"+H.to.head,range:re,from:H.from.event,to:H.to.event,fromHead:H.from.head,toHead:H.to.head});else if(H.kind==="tuplet"){let F=ne.get(H.first),b=ne.get(H.last),[g,y]=H.ratio.split(":").map(Number);for(let I=F;I<=b;){let D=C.measures[C.events[I].bar-1],x=Math.min(D.end,b+1);K[D.number-1].tuplets.push({start:I-D.start,count:x-I,numNotes:g,notesOccupied:y,range:re}),I=x}}}}for(let C of s.staves)for(let K of C.voices)Q(K,C.sounds??s.sounds,C.name==="upper"?"right":C.name==="lower"?"left":void 0,C.staffChanges);ee();let pe=new Map(R.flatMap(C=>C.voices.flatMap(K=>K.events.map(ne=>[ne.id,ne]))));for(let C of M.ties){let K=pe.get(C.from).heads[C.fromHead],ne=pe.get(C.to).heads[C.toHead];if(ne.release){if(!K.bend||K.bend.release||!ne.position||K.position.str!==ne.position.str)throw new oe("measure","A tied release needs a bent source on the same string",ne.range);K.tiedBendStart=!0,C.bend={semitones:K.bend.semitones,rise:K.bend.rise,hold:ne.release.hold,release:ne.release.release},C.string=ne.position.str}}for(let C of pe.values())for(let[K,ne]of C.heads.entries())if(ne.release&&!M.ties.some(H=>H.to===C.id&&H.toHead===K&&H.bend))throw new oe("measure","A release needs a tied continuation",ne.range);Pn(R,M.spans);for(let[C,K]of(s.text??[]).entries()){let ne={line:-C*2,...K.style};ne.ink&&A(ne.ink,r(K.voice.range));for(let H of K.voice.measures){let re=R[H.number-1],F=K.voice.events.slice(H.start,H.end).map(b=>{let g=b.marks.find(y=>y.kind==="text");return{id:b.id,range:r(b.range),...Ls(b.writtenDuration),text:g?.text??"",glyph:g?.glyph,style:{...ne,...g?.style}}});for(let b of K.voice.boundaries??[]){if(b.bar!==H.number)continue;let g=b.edge==="start"?F[0]:F[F.length-1];if(!g)throw new oe("measure","A text boundary needs a timed anchor",r(b.range));(g.boundaries??=[]).push({...b,range:r(b.range)})}for(let b of F)b.style.ink&&A(b.style.ink,b.range);(re.text??=[]).push(F)}}return n.set(e,M),M}var Zi="http://www.w3.org/2000/svg";var Qi=0;function ft(o,e={}){let n=document.createElementNS(Zi,o);for(let[t,s]of Object.entries(e))n.setAttribute(t,String(s));return n}var Jt=class{constructor(e,n,t,s){this.surface=e;this.music=n;this.follow=s;this.layer=ft("g",{class:"vextab-playback-ink","pointer-events":"none","aria-hidden":"true"});this.bar=ft("line",{stroke:"#a8a8a8","stroke-opacity":.55,"stroke-width":3.5,"stroke-linecap":"round"});this.gradient="vextab-glow-"+ ++Qi;this.dots=[];this.anchors=[];this.pulses=[];this.active=[];this.anchor=0;this.pulse=0;this.frame=0;this.pages=new Map;this.printedRows=new Map;let r=ft("radialGradient",{id:this.gradient});for(let[i,l]of[[0,.5],[.32,.72],[.52,.6],[.76,.22],[1,0]])r.append(ft("stop",{offset:i,"stop-color":"currentColor","stop-opacity":l}));let a=ft("defs");a.append(r),this.layer.append(a,this.bar);for(let i of n.events){let l=t.get(i.source);if(!l)continue;let{x:c,row:u,heads:f}=l,p=this.anchors[this.anchors.length-1];(!p||Math.abs(p.time-i.time)>1e-6)&&this.anchors.push({time:i.time,x:c,row:u,slope:0,speed:0}),f.length&&this.pulses.push({time:i.time,end:i.time+i.duration,heads:f,row:u})}this.anchors.forEach((i,l)=>{let c=this.anchors[l+1],u=(c?.row===i.row?c.x:i.row.right)-i.x,f=(c?.time??n.duration)-i.time;i.slope=f>0?u/f:0;let p=this.anchors[l-1];i.speed=i.slope,p?.row===i.row&&(i.speed=p.slope*i.slope>0?2/(1/p.slope+1/i.slope):0)})}rowLayer(e){let n=e.printedPage;if(!n)return this.layer.parentNode||this.surface?.append(this.layer),this.layer;let t=this.printedRows.get(e);if(t)return t;let s=this.pages.get(n);if(!s){let a=document.createElement("div");a.className="vextab-playback-page",n.before(a),s=ft("svg",{"aria-hidden":"true",class:"vextab-playback-paper"});for(let i of["viewBox","width","height","preserveAspectRatio"])n.hasAttribute(i)&&s.setAttribute(i,n.getAttribute(i));s.style.cssText="pointer-events:none;background:transparent;border-color:transparent",a.append(n,s),this.pages.set(n,s),this.layer.parentNode||s.append(this.layer)}let r=ft("g",{transform:"scale("+e.scale+")",class:"vextab-playback-ink","pointer-events":"none"});return s.append(r),this.printedRows.set(e,r),r}moveToRow(e){this.rowLayer(e).prepend(this.bar),this.bar.setAttribute("y1",String(e.top)),this.bar.setAttribute("y2",String(e.bottom)),this.row=e}start(e){if(!this.anchors.length)return;let n=()=>{let t=e();for(;this.anchor+1<this.anchors.length&&this.anchors[this.anchor+1].time<=t;)this.anchor++;let s=this.anchors[this.anchor],r=s.row!==this.row;r&&this.moveToRow(s.row),this.drawBar(t,s,this.anchors[this.anchor+1]),this.follow?.(this.bar,r),this.drawHeads(t),this.frame=requestAnimationFrame(n)};n()}drawBar(e,n,t){let s=t?.row===n.row,r=(s?t.x:n.row.right)-n.x,a=(t?.time??this.music.duration)-n.time,i=a>0?Math.max(0,Math.min(1,(e-n.time)/a)):0,l=s?t.speed:n.slope,c=(1-i)*(n.speed*a-r)+i*(r-l*a),u=n.x+i*r+i*(1-i)*c;this.bar.setAttribute("transform","translate("+u+" 0)")}drawHeads(e){for(;this.pulse<this.pulses.length&&this.pulses[this.pulse].time<=e+.075;)this.active.push(this.pulses[this.pulse++]);let n=0,t=0;for(let s of this.active){if(s.end<=e)continue;this.active[n++]=s;let r=s.end-s.time,a=Math.min(.075,r/2),i=Math.min(.14,r/2),l=Math.min(1,(e-s.time+a)/a,(s.end-e)/i);if(l>0)for(let c of s.heads)this.drawDot(t++,c,l,s.row)}this.active.length=n;for(let s=t;s<this.dots.length;s++){let r=this.dots[s];r.opacity!==0&&r.node.setAttribute("opacity","0"),r.opacity=0}}drawDot(e,n,t,s){let r=this.dots[e];if(r||(r={node:ft("ellipse",{rx:17,ry:13,fill:"url(#"+this.gradient+")",stroke:"none"})},this.dots.push(r)),r.point!==n){let a=this.rowLayer(s);r.node.parentNode!==a&&a.append(r.node),r.node.setAttribute("cx",String(n.x)),r.node.setAttribute("cy",String(n.y)),r.point=n}r.opacity!==t&&r.node.setAttribute("opacity",String(t)),r.opacity=t}stop(){cancelAnimationFrame(this.frame),this.layer.remove();for(let[e,n]of this.pages)n.parentElement?.replaceWith(e)}};var Ht=new WeakMap;function Nn(o){return{top:Math.min(...o.map(e=>e.getYForLine(0)))-7,bottom:Math.max(...o.map(e=>e.getYForLine(e.getNumLines()-1)))+7,right:Math.max(...o.map(e=>e.getNoteEndX()))}}function eo(o,e,n){let t=[],s=e[0].getAbsoluteX();for(let r of e){if(r.isRest()||!n.some(Boolean))continue;let a=r.getYs(),i="getHeadInk"in r?r.getHeadInk():[];for(let l=0;l<a.length;l++){let c=i[l]?i[l].x+i[l].w/2:r.getAbsoluteX();l===0&&r===e[0]&&(s=c),n[l]&&t.push({x:c,y:a[l]})}}return{row:o,x:s,heads:t}}function Ds(o){let e=new Map;for(let n of o.staves){let t=[n.note,n.tab].filter(Boolean);if(!t.length)continue;let s=Nn(t);(n.note?n.note_voices:n.tab_voices).forEach((a,i)=>a.forEach((l,c)=>{if(l.shouldIgnoreTicks())return;let u=n.note&&n.tab&&n.tab_voices[i]?.[c],f=u&&!u.shouldIgnoreTicks()?[l,u]:[l],p=(nt.get(l)??[]).map(h=>/^[a-g]/i.test(h.key));e.set(l,eo(s,f,p))}))}return e}function zs(o,e,n,t){let s=new Map,r=new Map;for(let a of n){let{measure:i}=a[1];r.has(i)||r.set(i,[]),r.get(i).push(a)}for(let a of o.pages){for(let i of a.systems){let l=a.svg.querySelector('[data-system="'+i.measures[0]+'"] > g:last-child'),c=i.y/t+(l?.transform.baseVal[0]?.matrix.f??0),u=i.x/t,f;for(let p of i.measures)for(let[h,E]of r.get(p)??[])f??={top:c+E.row.top,bottom:c+E.row.bottom,right:u+E.row.right,printedPage:a.svg,scale:t},s.set(h,{row:f,x:u+E.x,heads:[]})}for(let i of a.heads.occurrences){if(i.reference||i.role==="mark")continue;let l=e.get(i.sourceEvent),c=s.get(i.sourceEvent);if(!l||!c||typeof i.sourceHead!="number")continue;let u=l.heads[i.sourceHead];if(l.silent||!u||!u.sounding&&u.midi===void 0)continue;let f=i.bounds,p={x:(f.x+f.w/2)/t,y:(f.y+f.h/2)/t};c.heads.length||(c.x=p.x),c.heads.push(p)}}return s}function it(o,e){let n=o^Math.imul(e+1,2654435761),t=0;for(let s=0;s<4;s++){n=n+1831565813|0;let r=Math.imul(n^n>>>15,1|n);r^=r+Math.imul(r^r>>>7,61|r),t+=((r^r>>>14)>>>0)/4294967296}return(t-2)/2}function to(o,e,n){if(!Number.isFinite(n)||n<=0||!Number.isFinite(e)||e<0)throw new RangeError("Invalid playback time or tempo");let t=[...o],s=0,r=0;for(let l of t){if(!(l.duration>0&&Number.isFinite(l.duration)&&l.quarter>0&&Number.isFinite(l.quarter))||!((l.beatOffset??0)>=0&&(l.beatOffset??0)<l.quarter))throw new RangeError("Invalid performance bar");if(s+=l.duration,l.endingQuarter!==void 0&&!(l.endingQuarter>0&&Number.isFinite(l.endingQuarter)))throw new RangeError("Invalid final quarter duration");if(l.beats){let c=0;for(let u of l.beats){if(!(u.end>c&&Number.isFinite(u.end))||u.eighth!==void 0&&!(u.eighth>c&&u.eighth<u.end))throw new RangeError("Invalid written beat grid");c=u.end}if(!l.beats.length||Math.abs(c-l.duration)>1e-9)throw new RangeError("Incomplete written beat grid");r+=l.beats.length}else r+=Math.ceil((l.duration+(l.beatOffset??0))/l.quarter)}let a=t[t.length-1],i=a?.endingQuarter??a?.quarter??60/n;if(r+Math.ceil(Math.max(0,e-s)/i)>1e6)throw new RangeError("Performance exceeds one million beats");for(;s<e-1e-9;){let l=Math.min(4*i,e-s);if(s+l<=s)throw new RangeError("Beat is below clock precision");t.push({quarter:i,duration:l}),s+=l}return t}function no(o,e,n,t){let s=[],r=0,a=0,i=0;for(let l=0;l<o.length;){let c=l;for(;c+1<o.length&&c-l<3&&!o[c].phraseEnd;)c++;let u=r,f=o.slice(l,c+1).reduce((p,h)=>p+h.duration,0);for(let p=l;p<=c;p++){let h=o[p],E=r+h.duration,k=r,S=0,P=h.quarter-(h.beatOffset??0);for(;r<E-1e-9;){let B=h.beats?.[S++],j=B?k+B.end:Math.min(r+P,E),A=j-r;if(A<=0)throw new RangeError("Beat is below clock precision");let T=(r+A/2-u)/f,V=-Math.cos(2*Math.PI*T);i=.55*i+.45*it(n,s.length);let U=!t&&h.fermatas?.some(v=>v>r-k+1e-9&&v<=j-k+1e-9),Y=A*(1-e.rubato*V+e.drift*i+(U?.35:0)),G=h.swingable!==!1&&(B?B.eighth!==void 0:Math.abs(A/h.quarter-1)<1e-6),R=B?.eighth===void 0?.5:(B.eighth-(r-k))/A,M=60/(B?A:h.quarter),q=G?e.swing*Math.max(0,Math.min(.22,.25-(M-60)/750)):0;s.push({start:r,end:j,played:a,length:Y,velocity:V*e.swell,swing:q,fullBeat:G,middle:R}),r=j,a+=Y,P=h.quarter}r=E}l=c+1}return s}function pr(o,e){let n=0,t=o.length-1;for(;n<t;){let s=n+t>>>1;e>=o[s].end-1e-9?n=s+1:t=s}return n}function ro(o,e){let n=new Set;for(let t of o)for(let s of[t.time,t.time+t.duration]){let r=pr(e,s),a=e[r],i=(s-a.start)/(a.end-a.start);i>1e-6&&i<1-1e-6&&Math.abs(i-a.middle)>1e-6&&n.add(r)}return n}function so(o,e,n,t){let s=n[n.length-1],r=t.swing||t.pocket?ro(o.events,n):new Set;function a(l){return e||!l||l===n.length||!n[l].fullBeat||!n[l-1].fullBeat||r.has(l)||r.has(l-1)?0:t.pocket*Math.min(n[l].length,n[l-1].length)}function i(l){if(l>=s.end)return s.played+s.length+(l-s.end);let c=pr(n,l),u=n[c],f=Math.max(0,(l-u.start)/(u.end-u.start)),p=u.played+a(c),h=u.played+u.length*(u.middle+(r.has(c)?0:2*(1-u.middle)*u.swing)),E=u.played+u.length+a(c+1);return f<u.middle?p+f/u.middle*(h-p):h+(f-u.middle)/(1-u.middle)*(E-h)}return i}function io(o,e,n,t){if(o.length<2||!n||o.some(f=>f.onsetOffset))return;let s=Math.min(...o.map(f=>f.pitch)),r=Math.max(...o.map(f=>f.pitch)),a=it(t,0),i=o.map((f,p)=>{let h=(f.pitch-s)/Math.max(1,r-s),E=t^Math.imul(f.pitch+1,617)^p;return{note:f,finger:E,landing:a*h+it(E,1)}}).sort((f,p)=>f.landing-p.landing),l=Math.min(e,...o.map(f=>f.duration));if(l<=0)return;let c=Math.min(l*.12,n*(.78+.22*it(t,2))),u=Math.min(1,n/.013);i.forEach(({note:f,finger:p},h)=>{let E=h/(i.length-1),k=h>0&&h<i.length-1?.32*it(p,3)/(i.length-1):0,S=c*(E+k),P=f.pitch===r?.042:f.pitch===s?-.012:-.085,B=1+u*(P+.052*it(p,4));f.fixedVelocity||(f.velocity=Math.max(1,Math.min(127,Math.round(f.velocity*B)))),S&&(f.onsetOffset=S);let j=0;!f.holdRelease&&!f.bend&&f.duration<=e+1e-9&&(j=Math.min(n*1.8,f.duration*.09)*Math.max(0,.56+.4*it(p,5)-(f.pitch===r?.23:0))),f.duration-=S+j,S&&f.bend&&(f.bend=f.bend.map(A=>({...A,time:Math.max(0,A.time-S)})))})}function oo(o,e,n,t,s){let r=so(o,e,n,t);return{events:o.events.map((i,l)=>{let c=r(i.time),u=r(i.time+i.duration)-c,f=n[pr(n,i.time)],p=t.touch*it(s^e+1,Math.round(i.time*1e5)),h=(i.time-f.start)/(f.end-f.start),E=f.fullBeat?t.beatAccent*Math.cos(2*Math.PI*h):0,k=1+(f.velocity+p+E)/100,S=i.notes.map(P=>{let B=i.time+(P.onsetOffset??0),j=r(B),A=T=>r(B+T)-j;return{...P,duration:A(P.duration),...P.onsetOffset&&{onsetOffset:j-c},velocity:P.fixedVelocity?P.velocity:Math.max(1,Math.min(127,Math.round(P.velocity*k))),...P.bend&&{bend:P.bend.map(T=>({...T,time:A(T.time)}))}}});return io(S,u,t.chordSpread??0,s^Math.imul(e+1,65537)^Math.imul(l+1,16777619)),{...i,time:c,duration:u,notes:S}}),duration:r(o.duration)}}function ao(o){if(typeof o=="string"){if(!yt(o))throw new RangeError("Unknown performer: "+o);return Ut[o]}let e={rubato:[0,.4],drift:[0,.25],swell:[0,32],touch:[0,32],swing:[0,1],beatAccent:[-32,32],pocket:[-.15,.15],grace:[.05,.4],chordSpread:[0,.03]};for(let n of Object.keys(e)){let t=n==="chordSpread"&&o[n]===void 0?0:o[n],[s,r]=e[n];if(!Number.isFinite(t)||t<s||t>r)throw new RangeError("Invalid performer "+n)}return{...o}}function mr(o="human",e,n){let t=ao(o),s=n==="off"?{...t,swing:0,pocket:0}:n==="eighths"?{...t,swing:t.swing||1}:t,r=o==="robot"||o===Ut.robot;if(e!==void 0&&!Number.isSafeInteger(e))throw new RangeError("Expected an integer performer seed");let a=e??(r?0:Math.floor(Math.random()*4294967296));return{literal:r,needsBeatGrid:!r||!!s.swing,graceFraction(i,l,c,u=!1){if(r)return .25;let f=(u?.065:.105)*Math.sqrt(c);return Math.min(s.grace,f/l)*(1+.24*it(a,Math.round(i*1e5)))},perform(i,l=[],c=120){if(r&&!s.swing||!i.length)return i;let u=Math.max(...i.map(p=>p.duration)),f=no(to(l,u,c),s,a,r);return f.length?i.map((p,h)=>oo(p,h,f,s,a)):i}}}function co(o){let e=[];for(let n=o.parentElement;n&&n!==document.scrollingElement;n=n.parentElement){if(!(n instanceof HTMLElement))continue;let t=getComputedStyle(n),s=/^(auto|scroll|overlay)$/.test(t.overflowX),r=/^(auto|scroll|overlay)$/.test(t.overflowY);(s||r)&&e.push({element:n,x:s,y:r})}return e.push({element:document.scrollingElement,x:!0,y:!0}),e}function js(o,e,n,t){return e-o>=t-n||o<n?o-n:Math.max(0,e-t)}var An=class{constructor(){this.ports=[];this.reducedMotion=matchMedia("(prefers-reduced-motion: reduce)");this.lastFrame=0;this.nextCheck=0}update(e,n){let t=performance.now();if(!n&&t<this.nextCheck)return;(n||!this.ports.length)&&(this.ports=co(e));let s=Math.min(40,this.lastFrame?t-this.lastFrame:16),r=this.reducedMotion.matches?1:1-Math.exp(-s/65);this.lastFrame=t;let a=e.getBoundingClientRect(),{left:i,right:l,top:c,bottom:u}=a,f=!1;for(let{element:p,x:h,y:E}of this.ports){let k=p===document.scrollingElement,S=k?void 0:p.getBoundingClientRect(),P=S?S.width/(p.offsetWidth||1):1,B=S?S.height/(p.offsetHeight||1):1;if(!P||!B)continue;let j=window.visualViewport,A=S?S.left+p.clientLeft*P:j?.offsetLeft??0,T=S?S.top+p.clientTop*B:j?.offsetTop??0,V=k?j?.width??p.clientWidth:p.clientWidth*P,U=k?j?.height??p.clientHeight:p.clientHeight*B,Y=h?js(i,l,A+12,A+V-12)/P:0,G=Math.min(68,U*.12),R=E?js(c,u,T+G,T+U-G)/B:0,M=Math.max(0,Math.min(p.scrollWidth-p.clientWidth,p.scrollLeft+Y)),q=Math.max(0,Math.min(p.scrollHeight-p.clientHeight,p.scrollTop+R)),v=M-p.scrollLeft,_=q-p.scrollTop;if(Math.abs(v)>=1||Math.abs(_)>=1){f=!0;let O=W=>Math.sign(W)*Math.min(Math.abs(W),Math.max(1,Math.abs(W)*r));p.scrollBy({left:O(v),top:O(_),behavior:"instant"})}i-=v*P,l-=v*P,c-=_*B,u-=_*B}this.nextCheck=f?t:t+120}};function lo(o){let e=[];for(let n=o.parentElement;n&&n!==document.documentElement;n=n.parentElement){let t=getComputedStyle(n),s=t.overflowX!=="visible",r=t.overflowY!=="visible";(s||r)&&e.push({element:n,x:s,y:r})}return e}function Gs(o,e,n,t,{size:s,inset:r}){let a=lo(o),i=t.querySelector(".vextab-control-panel"),l=window.visualViewport,c=0,u,f=!1;function p(){c=0;let P=e.getBoundingClientRect(),B=n.getBoundingClientRect();if(f&&(!u||P.left!==u.left||P.top!==u.top||P.right!==u.right||P.bottom!==u.bottom)&&h(),u=P,!B.width||!B.height)return;let j=n.offsetWidth/B.width,A=n.offsetHeight/B.height,T=l?.offsetLeft??0,V=l?.offsetTop??0,U=Math.max(P.left,T),Y=Math.max(P.top,V),G=l?.width??document.documentElement.clientWidth,R=l?.height??document.documentElement.clientHeight,M=Math.min(P.right,T+G),q=Math.min(P.bottom,V+R),v=P.height>=R*.8||P.width>G+1;for(let{element:J,x:ae,y:L}of a){let X=J.getBoundingClientRect(),se=X.width/(J.offsetWidth||1),ee=X.height/(J.offsetHeight||1),Q=X.left+J.clientLeft*se,te=X.top+J.clientTop*ee;(ae&&P.width>J.clientWidth*se+1||L&&P.height>J.clientHeight*ee+1)&&(v=!0),ae&&(U=Math.max(U,Q),M=Math.min(M,Q+J.clientWidth*se)),L&&(Y=Math.max(Y,te),q=Math.min(q,te+J.clientHeight*ee))}if(M<=U||q<=Y){t.style.inset="0";return}let _=s==="auto"?v?"large":"mini":s;t.dataset.size!==_&&(t.dataset.size=_);let O=Math.min(r,Math.max(0,((M-U)*j-i.offsetWidth)/2)),W=Math.min(r,Math.max(0,((q-Y)*A-i.offsetHeight)/2));t.style.padding=W+"px "+O+"px",t.style.setProperty("--control-y-inset",W+"px"),t.style.inset=[(Y-B.top)*A,(B.right-M)*j,(B.bottom-q)*A,(U-B.left)*j].map(J=>J+"px").join(" ")}function h(){c||(c=requestAnimationFrame(p))}let E,k=new IntersectionObserver(P=>{if(f=P[P.length-1].isIntersecting,f){if(u=void 0,!E){E=new AbortController;let B={signal:E.signal,passive:!0};document.addEventListener("scroll",h,{...B,capture:!0}),window.addEventListener("resize",h,B),l?.addEventListener("scroll",h,B),l?.addEventListener("resize",h,B)}h()}else E?.abort(),E=void 0,t.style.inset="0"},{threshold:[0,.25,.5,.75,1]}),S=new ResizeObserver(h);for(let P of[o,...a.map(B=>B.element)])S.observe(P);return k.observe(e),p(),()=>{E?.abort(),k.disconnect(),S.disconnect(),cancelAnimationFrame(c)}}var Ws="http://www.w3.org/2000/svg",qs=3e3;function $t(o,e,n){let t=document.createElement("button");return t.type="button",t.className=e,t.setAttribute("aria-label",o),t.title=o,t.onclick=n,t}var Rn=class{constructor(e,n,t,s,r,a,i,l,c){this.root=document.createElement("div");this.status=document.createElement("span");this.listeners=new AbortController;this.hideAt=0;if(this.root.className=`vextab-transport ${n}`,this.controls=document.createElement(c?"span":"div"),this.controls.className=c?"vextab-playback-controls":"vextab-sheet-controls",this.status.setAttribute("role","status"),t)if(this.toggle=$t("Play","vextab-play",()=>this.toggle.classList.contains("vextab-stop")?r():s()),this.setButton(!1),c)this.controls.append(this.toggle);else{let u=document.createElement("div");u.className="vextab-control-panel",u.setAttribute("role","group"),u.setAttribute("aria-label","Playback"),this.scrollButton=$t("Auto-scroll","vextab-auto-scroll",()=>this.setFollowing(!this.follower)),this.setFollowing(l.size!=="mini"),u.append(this.toggle,this.addTempo(i),this.scrollButton),this.controls.append(u),this.controls.dataset.position=l.position,this.controls.dataset.visibility=l.visibility,this.controls.style.setProperty("--control-inset",l.inset+"px")}this.setTempo(a),this.controls.append(this.status),(c??this.root).append(t||c?this.controls:this.status),e instanceof SVGSVGElement&&(this.surface=e),e&&(!c||e instanceof HTMLCanvasElement)&&this.mountSheet(e,t&&!c,l)}setFollowing(e){this.follower=e?new An:void 0,this.scrollButton.setAttribute("aria-pressed",String(e))}followSystem(e,n){this.controls.dataset.size==="large"&&this.follower?.update(e,n)}mountSheet(e,n,t){let s=this.sheet=document.createElement("div");if(s.className="vextab-sheet",e.before(s),s.append(e,this.root),e instanceof HTMLCanvasElement){let r=document.createElementNS(Ws,"svg");r.setAttribute("viewBox",`0 0 ${e.width} ${e.height}`),r.setAttribute("preserveAspectRatio","none"),r.setAttribute("aria-hidden","true"),r.classList.add("vextab-canvas-ink"),this.surface=document.createElementNS(Ws,"g"),this.surface.setAttribute("transform",e.getContext("2d").getTransform().toString()),r.append(this.surface),this.root.prepend(r)}if(n){if(this.controls.addEventListener("click",r=>r.stopPropagation(),{signal:this.listeners.signal}),this.controls.dataset.visibility==="hover"){let r=()=>this.reveal();r();for(let a of["pointerenter","pointermove","pointerdown"])s.addEventListener(a,r,{passive:!0,signal:this.listeners.signal})}this.untrack=Gs(s,e,this.root,this.controls,t)}}reveal(){if(this.hideAt=performance.now()+qs,this.revealTimer!==void 0)return;this.controls.setAttribute("data-visible","");let e=()=>{let n=this.hideAt-performance.now();if(n>0){this.revealTimer=window.setTimeout(e,n);return}this.revealTimer=void 0,this.dismissHoverTempo?.(),this.controls.removeAttribute("data-visible")};this.revealTimer=window.setTimeout(e,qs)}addTempo(e){let n=document.createElement("div");n.className="vextab-tempo";let t=document.createElement("div");t.className="vextab-tempo-stepper";let s=i=>{n.contains(i.target)||r(!1)},r=(i,l=!1)=>{this.dismissHoverTempo=i&&l?()=>{n.querySelector(":focus-visible")||r(!1)}:void 0,i?document.addEventListener("pointerdown",s,{signal:this.listeners.signal}):document.removeEventListener("pointerdown",s),t.inert=!i,this.metronome.setAttribute("aria-expanded",String(i))};this.metronome=$t("Adjust tempo","vextab-metronome",()=>r(t.inert)),this.decrease=$t("Decrease tempo","vextab-step",()=>e(Math.max(1,this.tempo-5))),this.decrease.textContent="\u2212";let a=$t("Increase tempo","vextab-step",()=>e(this.tempo+5));return a.textContent="+",this.readout=document.createElement("span"),this.readout.className="vextab-bpm",this.readout.setAttribute("aria-live","polite"),t.append(this.decrease,this.readout,a),n.append(this.metronome,t),r(!1),n.onpointerenter=i=>{i.pointerType==="mouse"&&t.inert&&r(!0,!0)},n.onpointerleave=i=>{i.pointerType==="mouse"&&!n.querySelector(":focus-visible")&&r(!1)},n.addEventListener("focusout",i=>{n.contains(i.relatedTarget)||r(!1)}),n.onkeydown=i=>{i.key==="Escape"&&(this.metronome.focus(),r(!1))},n}setTempo(e){this.tempo=e,this.readout&&(this.readout.textContent=e+" BPM",this.metronome.setAttribute("aria-description",this.readout.textContent),this.decrease.disabled=e<=1)}setStatus(e){this.status.textContent=e}setPlaying(e){this.root.toggleAttribute("data-playing",e),this.setButton(e),e||(this.marker?.remove(),this.marker=void 0)}setButton(e){if(!this.toggle)return;let n=e?"Stop":"Play";this.controls.classList.contains("vextab-playback-controls")&&(this.toggle.textContent=n),this.toggle.title=n,this.toggle.setAttribute("aria-label",n),this.toggle.className=e?"vextab-stop":"vextab-play"}moveCursor(e,n){this.surface&&(this.marker||(this.marker=document.createElementNS("http://www.w3.org/2000/svg","circle"),this.marker.setAttribute("r","6"),this.marker.classList.add("vextab-playback-marker"),this.marker.setAttribute("fill","currentColor"),this.marker.setAttribute("opacity",".45"),this.marker.setAttribute("pointer-events","none"),this.surface.append(this.marker)),this.marker.setAttribute("cx",String(e)),this.marker.setAttribute("cy",String(n)))}remove(){this.untrack?.(),this.listeners.abort(),window.clearTimeout(this.revealTimer),this.marker?.remove(),this.controls.remove(),this.root.remove(),this.sheet&&this.sheet.replaceWith(...this.sheet.childNodes)}};function Us(o,e){return{async open(n,t){let s=new Map,r=!1;function a(){r=!0,s.forEach(i=>i.stop()),s.clear()}t.addEventListener("abort",a,{once:!0});try{return await Promise.all([...new Set(e)].map(async i=>{let l=await o.open(i,t);r||t.aborted?l.stop():s.set(i,l)})),{get currentTime(){return s.values().next().value?.currentTime},playNote(i){s.get(i.program??n)?.playNote(i)},stop:a}}catch(i){throw a(),i}}}}function uo(o){if(!o.some(n=>n.notes.some(t=>t.onsetOffset)))return o;let e=[];for(let n of o){let t=[];e.push({time:n.time,notes:t,mark:n.mark});for(let s of n.notes){if(!s.onsetOffset){t.push(s);continue}let{onsetOffset:r,...a}=s;e.push({time:n.time+r,notes:[a]})}}return e.sort((n,t)=>n.time-t.time)}var Cn=class{constructor(){this.rate=1}setRate(e){this.retime?this.retime(e):this.rate=e}get active(){return!!this.request}play(e,n,t,s,r=0){this.stop();let a=this.request=new AbortController;return globalThis.addEventListener?.("pagehide",()=>this.stop(),{capture:!0,signal:a.signal}),new Promise((i,l)=>{a.signal.addEventListener("abort",()=>i(),{once:!0});let c=f=>{a.signal.aborted||(l(f),this.stop())},u=f=>{if(a.signal.aborted){f.stop();return}this.session=f;let p=()=>f.currentTime??performance.now()/1e3,h=uo(t.events),E=p(),k=-r,S=()=>k+(p()-E)*this.rate,P=0,B=()=>{if(!a.signal.aborted)try{let j=S();for(;P<h.length&&h[P].time<=j;){let T=h[P++];T.mark?.();for(let V of T.notes)T.time+V.duration>j&&f.playNote(fo(V,this.rate))}if(P===h.length&&j>=t.duration){this.stop();return}let A=h[P]?.time??t.duration;this.timer=window.setTimeout(B,Math.max(1,(A-S())/this.rate*1e3))}catch(j){c(j)}};this.retime=j=>{k=S(),E=p(),this.rate=j,window.clearTimeout(this.timer),B()},s(S),B()};try{let f=e.open(n,a.signal);"playNote"in f?u(f):f.then(u).catch(c)}catch(f){c(f)}})}stop(){this.retime=void 0,this.rate=1,this.request?.abort(),this.request=void 0,window.clearTimeout(this.timer),this.timer=void 0;let e=this.session;this.session=void 0,e?.stop()}};function fo(o,e){return e===1?o:{...o,duration:o.duration/e,bend:o.bend?.map(n=>({...n,time:n.time/e}))}}function pt(o){async function e(n,t){let s=o??new AudioContext,r=new Set,a=!1;function i(){if(!a){a=!0;for(let c of r)c.stop();!o&&s instanceof AudioContext&&s.state!=="closed"&&s.close(),t.removeEventListener("abort",i)}}t.addEventListener("abort",i,{once:!0});try{s instanceof AudioContext&&s.state!=="running"&&await s.resume(),t.throwIfAborted()}catch(c){throw i(),c}function l(c){let u=s.currentTime,f=u+c.duration,p=s.createOscillator(),h=s.createGain();p.type=n>=72&&n<=79?"sine":"triangle",p.frequency.value=440*2**((c.pitch-69)/12),p.detune.setValueAtTime(0,u);for(let E of c.bend??[])p.detune.linearRampToValueAtTime(E.semitones*100,u+E.time);h.gain.setValueAtTime(0,u),h.gain.linearRampToValueAtTime(c.velocity/127*.12,u+Math.min(.006,c.duration/3)),h.gain.exponentialRampToValueAtTime(.001,f),p.connect(h).connect(s.destination),r.add(p),p.onended=()=>{r.delete(p),p.disconnect(),h.disconnect()},p.start(u),p.stop(f)}return{playNote:l,stop:i,get currentTime(){return s.currentTime}}}return{open:e}}function Ks(o,e,n,t=!0){return{open(s,r){function a(){return r.throwIfAborted(),MIDI.programChange(0,s),{playNote(i){MIDI.noteOn(0,i.pitch,t&&!i.fixedVelocity?127:i.velocity,0),MIDI.noteOff(0,i.pitch,i.duration)},stop(){}}}return n[o]?a():new Promise((i,l)=>{MIDI.loadPlugin({instruments:[o],soundfontUrl:e,onerror:l,callback(){n[o]=!0;try{i(a())}catch(c){l(c)}}})})}}}var mo={acoustic_grand_piano:0,acoustic_guitar_nylon:24,acoustic_guitar_steel:25,electric_guitar_jazz:26,distortion_guitar:30,electric_bass_finger:33,electric_bass_pick:34,trumpet:56,brass_section:61,soprano_sax:64,alto_sax:65,tenor_sax:66,baritone_sax:67,flute:73,synth_drum:118};function Xs(o){let e=/^\d+$/.test(String(o))?Number(o):mo[o];if(!Number.isInteger(e)||e<0||e>127)throw new RangeError("Invalid instrument: "+o);return e}var We=class o{constructor(e,n={}){this.transport=new Cn;this.generation=0;this.performanceTempo=120;this.sharedSurface=!1;this.companions=[];this.animations=[];if(this.options={instrument:"acoustic_grand_piano",tempo:120,show_controls:!0,soundfont_url:"/soundfont/",overlay_class:"vextab-player",...n},"parts"in e){let t=e;n.partId===void 0&&n.partIndex===void 0&&t.parts.length>1&&(this.ensemble=t.parts.map((s,r)=>Xe(t,r))),e=Xe(t,st(t,n))}"measures"in e?(this.score=e,this.options.tempo=n.tempo??e.playback?.tempo??120,this.options.instrument=n.instrument??e.playback?.instrument??"acoustic_grand_piano"):this.artist=e,this.setTempo(this.options.tempo),this.setInstrument(this.options.instrument),this.reset()}static{this.DEBUG=!1}static{this.INSTRUMENTS_LOADED={}}setArtist(e){this.dispose(),this.score=void 0,this.ensemble=void 0,this.artist=e,this.reset()}setTempo(e){if(!Number.isFinite(e)||e<=0)throw new RangeError("Tempo must be positive");this.options.tempo=e,this.overlay?.setTempo(e),this.transport.active&&this.transport.setRate(e/this.performanceTempo)}setInstrument(e){Xs(e),this.options.instrument=e,this.stop()}reset(){this.artist?.attachPlayer(this),this.stop()}removeControls(){this.stop(),this.overlay?.remove(),this.overlay=void 0;for(let e of this.companions)e.overlay.remove();this.companions=[]}dispose(){this.removeControls(),this.mark=void 0,this.geometry=void 0,this.artist?.player===this&&this.artist.attachPlayer(null)}render(e,n,t=[]){this.removeControls(),this.mark=n;let s=e&&Ht.get(e);this.sharedSurface=!!this.ensemble&&!!s?.ensemble&&this.ensemble.every((E,k)=>s.ensemble[k]===E),this.geometry=s&&s.score===this.score?s.read:void 0;let r=this.artist?.getPlayerData().context,a=e??r?.canvas??r?.svg,i=this.options.controls,l=i instanceof HTMLElement?i:void 0;if(!a&&!l)throw new Error("Render the score before mounting playback controls");let c=this.score?.playback?.controls,u=typeof i=="object"&&!(i instanceof HTMLElement)?i:void 0,f=En({...c,...u});(i===!0||l)&&f.visibility==="off"&&(f.visibility="hover");let p=(E,k,S)=>new Rn(E,this.options.overlay_class,k,()=>{this.play().catch(()=>{})},()=>this.stop(),this.options.tempo,P=>this.setTempo(P),f,S);this.overlay=p(a,this.options.show_controls&&i!==!1&&f.visibility!=="off",l);let h=new Set(this.ensemble);for(let E of t){let k=Ht.get(E);k&&h.has(k.score)&&this.companions.push({...k,overlay:p(E,!1)})}}moveCursor(e,n){this.overlay?.moveCursor(e,n)}async play(){if(this.transport.active)return;let e=++this.generation,{tempo:n,instrument:t,playback:s,soundfont_url:r}=this.options;this.performanceTempo=n;let a=this.ensemble??(this.score?[this.score]:[]),i=fs(a,this.options.order==="performed"),l=mr(this.options.performer??this.score?.playback?.performer,this.options.seed,this.options.swing??this.score?.playback?.swing),c=a.map(()=>[]),u=a.length?a.map((S,P)=>bs(S,n,this.mark,i.get(S),l,l.needsBeatGrid?c[P]:void 0)):[ys(this.artist,n)],f=l.perform(u,gs(c),n),p=f[0],h=new Map(a.map((S,P)=>[S,f[P]])),E=f.length===1?p:{events:f.flatMap(S=>S.events).sort((S,P)=>S.time-P.time),duration:Math.max(...f.map(S=>S.duration))},k=s??(!this.artist||typeof MIDI>"u"?pt():Ks(String(t),r,o.INSTRUMENTS_LOADED,l.literal));if(this.overlay&&!E.events.some(S=>S.notes.length)){this.overlay?.setStatus("This example has no pitched notes to play.");return}this.overlay?.setPlaying(!0),this.overlay?.setStatus("Loading instruments...");try{let S=this.geometry?.()??(this.artist&&this.overlay?Ds(this.artist):void 0);S?.size&&this.animations.push(new Jt(this.overlay?.surface,this.sharedSurface?E:p,S,(A,T)=>this.overlay?.followSystem(A,T)));for(let A of this.companions){let T=h.get(A.score);T&&this.animations.push(new Jt(A.overlay.surface,T,A.read()))}let P=Xs(t),B=[...new Set(E.events.flatMap(A=>A.notes.map(T=>T.program??P)))],j=B.some(A=>A!==P)?Us(k,B):k;await this.transport.play(j,P,E,A=>{for(let T of this.animations)T.start(A);this.overlay?.setStatus(""),this.overlay?.setPlaying(!0)},this.animations.length?.075:0)}catch(S){throw e===this.generation&&(this.overlay?.setPlaying(!1),this.overlay?.setStatus(S instanceof Error?S.message:String(S))),S}finally{e===this.generation&&(this.stopAnimations(),this.overlay?.setPlaying(!1))}}stopAnimations(){for(let e of this.animations)e.stop();this.animations=[]}stop(){this.generation++,this.transport.stop(),this.stopAnimations(),this.overlay?.setStatus(""),this.overlay?.setPlaying(!1)}};Z.Flow.Player||(Z.Flow.Player=We);function Ys(o,e,n){let t=(o.editions??[]).filter(l=>!l.conductor&&!l.part),s=o.editions?.find(l=>e==="conductor"?l.conductor:l.part&&l.part===o.parts[e].id);s&&t.push(s);let r={},a=[];for(let l of t)Object.assign(r,l.settings),a.push(...l.anchors);for(let l of["systemBreaks","pageBreaks","preferredTurns","forbiddenTurns"])r[l]=a.filter(c=>c.field===l).map(c=>c.measure);let i={...r.margins,...n.margins};return{settings:{...r,...n,margins:i},cues:s?.cues??[],anchors:a,range:(s??t[0])?.range}}var mt=Ee(Pe());function $s(o,e,n){return o.flatMap(t=>{let s=!1,r=t.map(a=>{let i=(u=0)=>u-3>n+4,l=a.text&&i(a.style.line)===e?a.text:"",c=a.boundaries?.filter(u=>i(u.style.line)===e).map(u=>e?{...u,style:{...u.style,line:u.style.line-n}}:u);return(l||c?.length)&&(s=!0),{...a,text:l,boundaries:c,belowBassStaff:e,style:l&&e?{...a.style,line:a.style.line-n}:a.style}});return s?[r]:[]})}function Js(o){return o.boundaries?.some(e=>e.edge==="start"&&e.style.line===o.style.line)}var In=class{constructor(){this.regions=new Map;this.cells=new Map;this.smoothMeasures=new Map;this.smoothNotes=new Map}voices(e,n,t){let r=[{notes:e.map(i=>{let l=t(i.id,i.range);return i.text&&i.style.smooth&&!i.boundaries?.length&&this.smoothMeasures.set(l,n),this.anchor(i,l)})}],a=Math.max(0,...e.map(i=>i.boundaries?.length??0));for(let i=0;i<a;i++)r.push({notes:e.map(l=>{let c=l.boundaries?.[i];if(!c)return{skip:{duration:l.base,dots:l.dots}};let u=l.id+"-at-"+c.range.start;return this.anchor({...l,...c,id:u},t(u,c.range),c.edge)})});return r}anchor(e,n,t="beat"){let s={duration:e.base,dots:e.dots};if(!e.text)return{id:n,skip:s};if(this.cells.set(n,e),e.style.smooth&&t==="beat"&&!e.boundaries?.length)return"B4/"+e.base+"/r"+".".repeat(e.dots)+'[clef="treble",id="'+n+'"]';let{family:r,size:a,style:i,align:l,line:c}=e.style,u=e.glyph?mt.TextNote.GLYPHS[e.text]??e.text:e.text,f={...r&&{family:r},...a&&{size:a},...i==="italic"&&{style:i},...i==="bold"&&{weight:i},...e.glyph&&{family:ht(),style:"normal",weight:"normal"}},h=t==="beat"&&Js(e)?"right":l??"center";return{id:n,direction:{...s,text:u,anchor:t,line:c,align:h,font:f}}}prepare(e,n){let t=this.smoothMeasures.get(e);if(t===void 0||n instanceof mt.TextNote)return;n.renderOptions.draw=!1;let s=this.smoothNotes.get(t);s||this.smoothNotes.set(t,s=new Map),s.set(e,n)}smoothLabel(e,n,t){let{family:s,size:r,style:a,align:i,line:l}=n.style,c=new mt.TextNote({duration:n.base,...n.glyph?{glyph:n.text}:{text:n.text},line:l}).setDirectionAnchor("beat").setAttribute("id",t);return n.glyph?r&&c.setFontSize(r):c.setFont(s??c.fontInfo.family,r??c.fontInfo.size,a==="bold"?"bold":void 0,a==="italic"?"italic":void 0),c.setJustification(i==="right"?mt.TextNote.Justification.RIGHT:i==="left"?mt.TextNote.Justification.LEFT:mt.TextNote.Justification.CENTER),c.setStave(e.checkStave()).setTickContext(e.checkTickContext()),c.preFormat(),c}inkBounds(e,n){let t=[];for(let[s,r]of this.smoothNotes.get(n)??[]){if(r.getStave()!==e)continue;let a=this.cells.get(s),i=this.smoothLabel(r,a,s);this.positionLabel(i,e,a.glyph),t.push(i.getBoundingBox())}return t}positionLabel(e,n,t){if(e.getLine()-3<n.getNumLines())return;e.setYShift(0);let s=t?-e.getTextInk(0,0).y:e.getTextMetrics().fontBoundingBoxAscent;e.setYShift(n.getSpacingBetweenLines()+s)}place(e,n,t){let s=e.getAttribute("id"),r=this.cells.get(s);if(!r)return;let a;if(e instanceof mt.TextNote){if(a=e,a.getDirectionAnchor()==="beat"&&Js(r)){let c=a.getTextMetrics().width;a.setXShift(r.style.align==="right"?0:r.style.align==="left"?c:c/2)}}else{if(!r.style.smooth)return;a=this.smoothLabel(e,r,s)}r.style.ink&&a.setStyle(ke(r.style.ink));let i=e.checkStave();if(this.positionLabel(a,i,r.glyph),r.belowBassStaff){let c=a.getBoundingBox(),u=c.y;for(let f of t.notes.flat(3)){let p=f,h=p.getBeam?.();if(!(!h||h.getNotes()[0]!==p||p.getStave()?.getY()!==i.getY()))for(let E of h.getStripBounds())E.x<c.x+c.w&&E.x+E.w>c.x&&(u=Math.max(u,E.y+E.h+i.space(.4)))}a.setYShift(a.getYShift()+u-c.y)}let l=a.getBoundingBox();this.regions.set(s,{id:s,source:r.id,kind:"event",x:l.x,y:l.y,w:l.w,h:l.h}),a!==e&&n({source:e,bounds:l,draw:c=>a.setContext(c).drawWithStyle()})}};var vt=Ee(Pe());function Zs(o,e,n,t,s){o.save(),o.openGroup("score-heading");let r=e.align==="center",a=Math.min(1,r?Math.max(.75,t/620):t/620),i=0;function l(c,u,f,p,h=0){if(!c)return;let E=c.split(/(\^\{[^{}]+\}|♩|𝅗𝅥)/u).filter(Boolean).map(A=>{let T=A.startsWith("^{")&&A.endsWith("}"),V=T?A.slice(2,-1):A,U=A==="\u2669"?vt.default.Glyphs.metNoteQuarterUp:A==="\u{1D15E}"?vt.default.Glyphs.metNoteHalfUp:void 0,Y=U?ht():ze(),G=U?"normal":kt(),R=U??V.trim(),M=p*a*(T?.62:1);o.setFont(Y,M,G,"normal");let q=U?0:o.measureText("a a").width-o.measureText("aa").width,v=(V.length-V.trimStart().length)*q,_=(V.length-R.length)*q+o.measureText(R).width;return{label:R,family:Y,weight:G,fontSize:M,raised:T,leading:v,advance:_}}),k=E.reduce((A,T)=>A+T.advance,0),S=r&&k>t?t/k:1,P=p*a*S,B=n+u*t-k*S*h,j=r?s+i+P*1.3:s-f*a;for(let A of E)o.setFont(A.family,A.fontSize*S,A.weight,"normal"),o.fillText(A.label,B+A.leading*S,j-(A.raised?P*.5:0)),B+=A.advance*S;r&&(i+=P*1.85)}return r?(l(e.title,.5,0,32,.5),l(e.dedication,.5,0,16,.5),l(e.composer,.5,0,16,.5),l(e.tempo,.5,0,16,.5)):(l(e.title,.5,112,34,.5),l(e.dedication,.045,74,18),l(e.tempo,.17,39,23),l(e.composer,.985,32,19,1)),o.closeGroup(),o.restore(),i}function Qs(o,e){let n=new vt.KeyManager(e),t=new Map;return o.notes.map(s=>{let[r,a]=s.key.split("/"),i=r[0],l=r.slice(1)||"n",c=i+a,u=t.get(c)??n.getAccidental(i).accidental??"n";t.set(c,l);let f=s.ornament&&new vt.Ornament(s.ornament.replace("_inverted","Inverted")).getText(),p=f?'[stem="down",articulations="'+f+'.above"]':'[stem="down"]';return i+(u===l?"":l)+a+"/"+o.duration+p}).join(", ")}var ce=Ee(Pe());var ei=Ee(Pe());function ti(o,e,n,t,s=!1,r=!1,a=new Map){let i=[],l=[];for(let c of o.voices){let u=new Map;for(let[f,p]of c.events.entries()){let h=n(p.id),E=p.chord?[p.chord.text]:[];if(t)for(let k of p.heads)(k.connection||k.hammer)&&e==="tab"&&E.push(k.connection==="pull"?"P":k.connection==="slide"?"Slide":"H"),k.openSlide&&e==="notation"&&E.push(Vt(k.openSlide,k.position.str)),k.prebend&&E.push(Ft(k.prebend,k.position.str));if(s)for(let k of p.gestures??[])"direction"in k?!o.state.piano&&!r&&E.push(k.kind+" "+k.direction):E.push(k.kind==="tap"?"T":k.wide?"Wide vibrato":"Vibrato");p.harmony&&E.length===1?i.push({note:h,harmony:p.harmony}):E.length&&i.push({note:h,text:E.join(" \xB7 ")});for(let k of Yt(p)){let{text:S,hyphen:P,extend:B,range:j,verse:A,elideWith:T,crossConnector:V}=k;if(e==="tab")throw new oe("fixed-layout","This lyric needs a notation staff",j);let U=A??"";u.has(U)||u.set(U,[]),u.get(U).push({note:h,text:S,elideWith:T,hyphenAfter:P,extendTo:B?n(V?a.get(j.start):c.events[f+B].id):void 0})}}for(let f of[...u.keys()].sort())l.push({id:f,syllables:u.get(f)})}return{chords:i,verses:l}}function ho(o){return o.voices.flatMap(e=>e.events.filter(n=>n.frame)).map(e=>({event:e,beat:new ei.Fraction().parse(e.onset).value()})).sort((e,n)=>e.beat-n.beat)}function ni(o,e){return o.measures.flatMap(n=>ho(n).map(({event:t})=>{let{spec:s,range:r}=t.frame,a="frame"+r.start;return{id:e(a,r,t.id),source:a,diagram:{...s,label:t.chord.text}}}))}var go=0;function bo(o,e){let n=o.measures[0].state,s=(n.piano?["right","left"]:["notation","tab"].filter(r=>n[r])).filter(r=>e==="score"||e===r||n.piano&&e==="notation");if(!s.length)throw new oe("fixed-layout",`No ${e} staff in this score`,n.declaration);for(let r of o.measures)if(r.state.piano!==n.piano||["notation","tab"].some(a=>(e==="score"||e===a)&&r.state[a]!==n[a])||s.includes("tab")&&r.state.strings!==n.strings)throw new oe("fixed-layout","A flow score must keep its staff configuration",r.state.declaration);return s}function Dt(o,e){return o.state.piano?o.voices.filter(n=>n.hand===e):o.voices}var hr=class{constructor(e){this.revision=e;this.ids=Object.create(null);this.ranges=new Map;this.prefix="vt"+ ++go+"-";this.id=(e,n)=>this.prefix+e+"-"+n;this.rangeFor=(e,n)=>n===this.revision?this.ranges.get(this.ids[e]??e):void 0;this.sourceFor=e=>this.ids[e]}project(e,n,t,s){let r=this.id(e,s?n+"-"+s:n);return this.ids[r]=n,this.ranges.set(n,t),r}};function yo(o,e){let n=o.heads.flatMap((s,r)=>s.position?[{...s.position,displayKey:s.written,index:r}]:[]),t=[];if(o.bend){let s=n.map(a=>({str:a.str,fret:Number(a.fret)}));t.push(...e.attack(n,o.base).note.notation);let r=o.heads.some(a=>a.bend)?o.heads.flatMap(a=>a.bend&&!a.tiedBendStart?[a.bend]:[]):[o.bend.spec];for(let a of r)t.push(...e.bentAttack(s,o.base,a).note.notation.filter(i=>i.bend))}else if(n.length)for(let s of e.attack(n,o.base).note.notation)t.push({...s,index:n[s.index].index});return o.heads.forEach((s,r)=>{s.openSlide&&t.push({kind:"technique",id:"open-slide",index:r,label:Vt(s.openSlide,s.position.str)}),s.prebend&&t.push({kind:"technique",id:"pre-bend",index:r,label:Ft(s.prebend,s.position.str)}),!s.position&&s.sounding===null&&t.push({kind:"unpitched",id:"slash",label:"Rhythm slash",index:r})}),t}function xo(o){let e=new Map;if(!o.hand)return e;for(let n of o.beamGroups??[]){let t=o.events.slice(n.start,n.end+1),s=t.map(r=>r.displayHand??o.hand);s.some(r=>r!==s[0])&&t.forEach((r,a)=>e.set(r,s[a]==="right"?-1:1))}return e}function vo(o,e,n,t){let s=o.stem,r=s?s==="up"?1:-1:n==="tab"?o.tabDirection:void 0,a=new ce.FrettedInstrument(e.state.tuning,e.state.capo),i=n==="left"?"bass":e.state.clef,l=xo(o),c,u=o.events.map(h=>{let E=t.project(n,h.id,h.range);h.heads.forEach((Y,G)=>t.project(n,h.id+"-head-"+G,Y.range));let k=e.state.piano?h.displayHand:void 0,S=l.get(h),P=h.stem==="up"?1:h.stem==="down"?-1:void 0,B={duration:h.base,dots:h.dots,stemDirection:P??S??r,headSource:{event:h.id}};if(h.silent)return{id:E,skip:B};if(!h.heads.length){let Y=n==="tab"?5-e.state.strings:0,G=h.restLine===void 0?void 0:h.restLine+Y;return{id:E,...k&&{stave:k},note:{...B,keys:["r/4"],clef:"treble",type:"r",restLine:G}}}if(h.heads[0].drum){let Y=(e.state.kit??lt).note(h.heads.map(G=>G.drum),h.base,h.stem??s);return{id:E,note:{...Y,dots:h.dots,headSource:B.headSource}}}let j=yo(h,a),A=h.heads.map(Y=>Y.position?.fret==="X"?Y.written+"/X":Y.written);if(n==="tab")return{id:E,tab:{...B,keys:A,notation:j,positions:h.heads.map(Y=>({...Y.position}))},drawStem:o.tabStems&&!["w","1"].includes(h.base)};let T=h.writtenClef??i;if(k&&k!==o.hand){let Y=e.staffState?.[k];T=Y?.clef??(k==="left"?"bass":"treble");for(let G of Y?.changes??[]){if(new ce.Fraction().parse(G.at).greaterThan(new ce.Fraction().parse(h.onset)))break;T=G.clef??T}}let V=h.heads.map((Y,G)=>{let R=jn(Y.marks,h.heads);return{key:A[G],...R&&{fingering:{finger:R.finger,position:R.position}},...Y.accidental&&{accidental:Y.cautionary?"cautionary":"force"}}}),U={...B,heads:V,notation:j,clef:T,type:h.slash?"s":"n",autoStem:B.stemDirection===void 0};return h.tremolo&&(c===void 0?(c=B.stemDirection??new ce.StaveNote({...U,autoStem:!0}).getStemDirection(),U.stemDirection=c):(U.stemDirection=c,c=void 0),U.autoStem=!1),{id:E,...k&&{stave:k},note:h.tremolo?ce.AlternatingTremolo.endpoint(U,h.tremolo):U,...h.grace&&{grace:{side:h.grace.side,slur:!0,beam:h.grace.pitches.length>1,notes:h.grace.pitches.map(Y=>({keys:Array.isArray(Y)?Y:[Y],duration:h.grace.slash?"8":"16",slash:h.grace.slash,clef:T}))}}}}),f=new Map;if(n!=="tab")for(let h of e.staffState?.[n]?.changes??[])!h.clef&&!h.key||f.set(h.at,{...f.get(h.at),...h.clef&&{clef:h.clef},...h.key&&{key:h.key}});return{notes:f.size?u.flatMap((h,E)=>{let k=f.get(o.events[E].onset);return k?[{change:k},h]:[h]}):u,stem:s??"auto",autoBeam:!o.events.some(h=>h.tremolo)&&o.beams&&(n!=="tab"||o.tabStems)&&{groups:o.beatGroups?.map(h=>new ce.Fraction(h,Number(e.state.meter.split("/")[1]))),stemDirection:o.events.some(h=>h.stem)?void 0:r,flatBeams:o.flatBeams,beamRests:o.beamRests,showStemlets:o.stemlets,beamMiddleOnly:o.middleRests},beams:n==="tab"&&!o.tabStems?[]:o.beamGroups?.map(h=>({start:h.start,count:h.end-h.start+1,flatBeams:o.flatBeams,feathered:h.feather,showStemlets:o.stemlets})),tuplets:o.tuplets.map(h=>({start:h.start,count:h.count,options:{numNotes:h.numNotes,notesOccupied:h.notesOccupied}}))}}function wo(o){let e=o.voices[0].closing?.type;if(e==="end")return ce.Barline.type.END;if(e==="double")return ce.Barline.type.DOUBLE}function ri(o,e,n,t=!1){let s=bo(o,e);if(!s.includes("tab"))for(let T of o.measures)for(let V of T.voices){let U=V.events.find(Y=>Y.bend)?.bend;if(U)throw new oe("fixed-layout","A timed bend contour needs a tab staff",U.range)}let r=new hr(o.source),a=r.id,i=o.layout?.heading,l=i&&(i.align==="center"||Object.keys(i).length===1)&&!Object.values(i).some(T=>/\^\{/.test(T)),c=ni(o,(T,V,U)=>r.project(s[0],T,V,U)),u=[];if(l)for(let T of["title","dedication","composer","tempo"])i[T]&&u.push({kind:"text",runs:i[T].split(/([♩𝅗𝅥])/u).filter(Boolean).map(V=>V==="\u2669"||V==="\u{1D15E}"?{text:V==="\u2669"?ce.default.Glyphs.metNoteQuarterUp:ce.default.Glyphs.metNoteHalfUp,font:{family:ht(),weight:"normal"}}:V),align:i.align??(T==="title"?"center":T==="composer"?"right":"left"),font:{family:ze(),weight:kt(),size:T==="title"?32:16}});c.length&&u.push({kind:"diagrams",align:i?.align??"left",diagrams:c.map(T=>T.diagram),font:{family:ze(),size:12}}),o.playback?.swing==="eighths"&&u.push({kind:"text",font:{family:ze(),size:12,weight:kt()},runs:["Swing ",{notes:["8","8"],beam:!0}," = ",{notes:["q","8"],tuplet:[3,2]}]});let f=new In,p=new Map(o.spans.filter(T=>T.kind==="lyric").map(T=>[T.range.start,T.to])),h=o.measures[0].state.tab&&o.measures.some(T=>T.voices.length>1),E=[],k=new Set(o.measures.flatMap(T=>T.voices.flatMap(V=>V.events.filter(U=>!U.heads.length).map(U=>U.id)))),S=new Map,P=[],B={stemPolicy:o.layout?.stemPolicy==="pitch"?void 0:"active-voices",accidentals:"key-aware",graceAccidentals:"ordered",sheet:{width:n,x:10,y:o.layout?.top??14,rowGap:o.layout?.rowGap??36,...o.layout?.spacing&&{measurePadding:18,measureGap:0}},system:{...o.layout?.spacing&&{details:{spacing:{mode:o.layout.spacing}}},spaceBetweenStaves:o.layout?.staffDistance??9},staves:s.map(T=>({id:T,kind:T==="tab"?"tab":"stave",...T==="right"&&{name:"R.H.",shortName:"R.H."},...T==="left"&&{name:"L.H.",shortName:"L.H."},...Bs(o,T,T===s[0]),options:T==="tab"?{numLines:o.measures[0].state.strings}:{},measures:o.measures.map(V=>{let U=Dt(V,T);if(T!=="tab"&&o.ties.length&&U.filter(M=>M.events.some(q=>q.heads.length)).length>1){for(let M of U)if(M.stem)for(let q of M.events)S.set(q.id,M.stem==="up"?"above":"below")}let Y=T===s[0]||V.state.piano,G=T==="tab"?void 0:V.staffState?.[T];return{clef:G?.clef??(T==="tab"?"tab":T==="left"?"bass":V.state.clef),key:G?.key??V.state.key,time:V.state.meterSign??V.state.meter,span:V.span==="0/1"?"1/1":V.span,showTimeSignature:V.state.showTime&&!(T==="tab"&&s.includes("notation")),endBarline:wo(V),...Y&&ti({...V,voices:U},T==="tab"?"tab":"notation",M=>a(T,M),t||!s.includes("tab"),t,h,p),voices:[...U.map((M,q)=>M.events.length?vo(M,V,T,r):{notes:[{id:a(T,"blank-"+V.number+"-"+q),skip:"w"}]}),...(V.state.piano&&s.length===2?$s(V.text??[],T==="left",o.layout?.staffDistance??9):T===s[0]?V.text??[]:[]).flatMap(M=>f.voices(M,V.number,(q,v)=>r.project(T,q,v)))]}})})),continuous:{inkBounds:(T,V)=>f.inkBounds(T,V),verticalSpacing:o.measures[0].state.piano||s.length>1?"profile":"envelope",textLanes:"system",opening:{indent:o.layout?.firstSystemIndent,blocks:u},courtesy:!1,measureNumbers:o.measureNumbers,spans:E,groups:s.length===2?[{first:s[0],last:s[1],type:o.measures[0].state.piano?"brace":"bracket",barlines:!!o.measures[0].state.piano}]:[],boundaries:o.measures.map(T=>({measure:T.number,rehearsal:T.voices[0].rehearsal,breakBefore:T.newRow&&T.number>1?"force":void 0,repeatStart:["repeat-begin","repeat-both"].includes(T.voices[0].opening?.type),repeatEnd:["repeat-end","repeat-both"].includes(T.voices[0].closing?.type)}))}};for(let T of o.ties)for(let V of s){let U=a(V,T.from);r.ids[U]&&E.push({kind:"tie",id:r.project(V,T.id,T.range),from:U,to:a(V,T.to),side:V==="tab"?void 0:T.side??S.get(T.from)??S.get(T.to),...V==="tab"&&T.bend&&{bend:T.bend,string:T.string},fromHead:T.fromHead,toHead:T.toHead})}for(let T of o.spans??[]){if(T.kind==="pedal"){for(let G of s){let R=a(G,T.from),M=a(G,T.to);G!=="tab"&&r.ids[R]&&r.ids[M]&&E.push({kind:"pedal",pedalStyle:"text",id:r.project(G,T.id,T.range),from:R,to:M})}continue}if(T.kind==="lyric"||T.kind==="hyphen"||T.kind==="tremolo")continue;if(T.kind==="continuousBeam"||T.kind==="crescendo"||T.kind==="diminuendo"){for(let G of s){let R=a(G,T.from),M=a(G,T.to);!r.ids[R]||!r.ids[M]||G==="tab"||E.push({kind:T.kind==="continuousBeam"?"beam":T.kind,from:R,to:M,..."niente"in T&&{niente:T.niente},...T.side&&{side:T.side},id:r.project(G,T.id,T.range)})}continue}if("fromHead"in T){for(let G of s){if(G==="tab")continue;let R=a(G,T.from);r.ids[R]&&E.push({kind:T.kind==="glissando"?"glissando":"tie",id:r.project(G,T.id,T.range),from:R,to:a(G,T.to),fromHead:T.fromHead,toHead:T.toHead})}continue}if(T.kind==="slur"){for(let G of s){let R=a(G,T.from);G==="tab"&&(k.has(T.from)||k.has(T.to))||r.ids[R]&&E.push({kind:"slur",side:T.side??(G==="tab"?"below":void 0),id:r.project(G,T.id,T.range),from:R,to:a(G,T.to)})}continue}if(T.kind==="palmMute"&&!s.includes("tab"))throw new oe("fixed-layout","A string-specific palm mute needs a tab staff",T.range);if(T.kind!=="palmMute"&&T.kind!=="volta")continue;let V=T.kind==="palmMute"?"tab":s[0],Y={id:r.project(V,T.id,T.range),from:a(V,T.from),to:a(V,T.to)};if(T.kind==="palmMute")E.push({...Y,kind:T.kind,strings:T.strings});else if(V==="tab"&&k.has(T.from)!==k.has(T.to)){let G=o.measures[T.firstBar-1].voices.flatMap(v=>v.events),M=o.measures[T.lastBar-1].voices.flatMap(v=>v.events).find(v=>k.has(v.id)===k.has(T.from)),q=G.find(v=>k.has(v.id)===k.has(T.to));M||q?E.push({...Y,kind:"volta",text:T.label,from:M?Y.from:a(V,q.id),to:M?a(V,M.id):Y.to}):P.push(T)}else E.push({...Y,kind:T.kind,text:T.label})}let j=[];for(let T of o.measures)for(let V of s)if(V!=="tab")for(let U of Dt(T,V))for(let Y of U.events){let G=Y.ossia;G&&j.push({id:a(V,Y.id+"-ossia"),at:a(V,Y.id),label:"Ossia.",notes:Qs(G,T.state.key??"C"),beam:G.notes.length>1&&G.duration!=="q",scale:.63})}if(B.continuous.ossias=j,s.includes("left")&&s.includes("right")){let T=[];for(let V of o.measures){let U=new Map;for(let Y of V.voices)for(let G of Y.events)if(G.sharedStem){let R=G.sharedStem+":"+G.onset,M=U.get(R)??{},q=Y.hand==="right"?"upper":"lower";if(M[q])throw new oe("measure","Duplicate shared stem endpoint",G.range);M[q]=a(Y.hand,G.id),U.set(R,M)}for(let Y of U.values()){if(!Y.upper||!Y.lower)throw new oe("measure","Shared stems need simultaneous notes on both staves",V.range);T.push({id:Y.upper+"-shared",upper:Y.upper,lower:Y.lower})}}B.continuous.splitChords=T}let A={spec:B,nativeHeading:l,frames:c,staves:s,sources:r,eventId:a,mixedEndings:P,textLanes:f,printAnchors:t?new Map:void 0,endingRegions:[]};return B.engraving=Po(o,A),A}function ko(o,e,n){for(let t of e.labels??[]){let s=new ce.Annotation(t.text).setVerticalJustification(t.position==="below"?ce.Annotation.VerticalJustify.BOTTOM:ce.Annotation.VerticalJustify.TOP);s.setFont(t.family??ze(),t.size??12,t.style==="bold"?"bold":void 0,t.style==="italic"?"italic":void 0),t.ink&&s.setStyle(ke(t.ink)),o.addModifier(s,0)}for(let t of e.gestures??[])if(t.kind==="tap")n&&o.addModifier(new ce.Annotation("T"),0);else if(t.kind==="vibrato")n&&o.addModifier(new ce.Vibrato().setVibratoWidth(t.wide?28:18),0);else if(t.kind==="stroke")o.addModifier(new ce.Articulation(t.direction==="up"?"a|":"am").setPosition(ce.Modifier.Position.BELOW),0);else if("direction"in t){let s=(t.kind==="rasgueado"?"RASGUEADO":t.kind.toUpperCase())+"_"+t.direction.toUpperCase();o.addModifier(new ce.Stroke(ce.Stroke.Type[s]),0)}}function So(o,e,n,t,s){if(e.grace?.positions&&o instanceof ce.TabNote){let r=e.grace.positions.map(i=>new ce.GraceTabNote({positions:i,duration:"16"})),a=new ce.GraceNoteGroup(r).setPosition(e.grace.side==="before"?ce.Modifier.Position.LEFT:ce.Modifier.Position.RIGHT);o.addModifier(a,0)}if(e.grace?.fingerings){let r=o.getModifiers().find(a=>a instanceof ce.GraceNoteGroup);for(let{attack:a,head:i,finger:l,position:c}of e.grace.fingerings)r&&Et(r.getGraceNotes()[a],i,[{finger:l,position:c}],n==="tab",!0,!0)}if(e.ornament&&n!=="tab"&&o.addModifier(new ce.Ornament(e.ornament.replace("_inverted","Inverted")),0),e.dynamic&&(t.hand||s)){let r=[...e.dynamic].map(i=>ce.TextDynamics.GLYPHS[i]).join(""),a=t.hand==="right"&&e.displayHand==="left"?ce.Annotation.VerticalJustify.TOP:ce.Annotation.VerticalJustify.BOTTOM;o.addModifier(new ce.Annotation(r).setFont(ht(),15).setVerticalJustification(a),0)}ko(o,e,n==="tab"),e.color&&(o.setStyle(ke(e.color)),o instanceof ce.StaveNote&&o.setLedgerLineStyle(ke(e.color))),e.silent&&(o.renderOptions.draw=!1),e.heads.forEach((r,a)=>{if(!r.marks)return;let i=o instanceof ce.StaveNote&&!r.drum?jn(r.marks,e.heads):void 0;Et(o,a,r.marks.filter(l=>l!==i),n==="tab",!0)}),o instanceof ce.TabNote&&e.heads.forEach((r,a)=>{r.openSlide&&vn(o,a,r.openSlide),r.prebend&&o.addModifier(un(r.prebend),a)}),n==="tab"&&!t.tabStems&&!e.heads.length&&(o.renderOptions.draw=!1)}function Eo(o,e,n,t){let s=Yt(e).sort((a,i)=>(a.verse??"").localeCompare(i.verse??"")),r=0;for(let a of o.getModifiers()){if(!(a instanceof ce.Annotation))continue;let i=e.chord&&a.getText().split(" \xB7 ")[0]===e.chord.text,l=a.phraseManaged&&a.getVerticalJustification()===ce.Annotation.VerticalJustify.BOTTOM&&s[r++],c=i?e.chord.range:l&&l.range;if(!c)continue;i&&e.chord.color&&a.setStyle(ke(e.chord.color));let u=(i?"chord":"lyric")+c.start;n.sources.project(t,u,c,e.id),n.sources.ids[a.getAttribute("id")]=u}}function To(o,e,n,t,s){e.endingRegions.length=0;for(let r of e.mixedEndings){if(r.kind!=="volta")continue;let a=e.eventId("tab",r.id),i=l=>t.get(e.eventId("tab",o.measures[l-1].voices[0].events[0]?.id));for(let[l,c]of n.sheet.getContinuousLayout().rows.entries()){let u=c.measures.filter(A=>A>=r.firstBar&&A<=r.lastBar);if(!u.length)continue;let f=u[0],p=u[u.length-1],h=i(f),E=i(p);if(!h||!E)continue;let k=h.checkStave(),S=k.getX()+1,P=E.checkStave().getNoteEndX(),B=c.y+k.getY()-n.staves[f-1][0].getY()-15,j={x:S,y:B,w:P-S,h:14};e.endingRegions.push({id:a,kind:"span",source:r.id,row:l,...j}),s({source:h,bounds:j,draw(A){A.openGroup("tab-ending",a+"-"+l),A.fillRect(S,B,P-S,1),f===r.firstBar&&(A.fillRect(S,B,1,12),A.setFont(ze(),11).fillText(r.label,S+4,B+12)),p===r.lastBar&&A.fillRect(P-1,B,1,12),A.closeGroup()}})}}}function Mo(o,e,n,t){for(let s of o.spans)for(let r of e.staves){let a=n.get(e.eventId(r,s.from)),i=n.get(e.eventId(r,s.to));if(!a||!i)continue;if(s.kind==="tremolo"&&a instanceof ce.StaveNote&&i instanceof ce.StaveNote){let u=new ce.AlternatingTremolo(a,i,s.strokes);t({source:a,bounds:a.getBoundingBox().clone().mergeWith(i.getBoundingBox()),draw:f=>u.setContext(f).draw()})}if(!("fromHead"in s)||!(a instanceof ce.TabNote)||!(i instanceof ce.TabNote))continue;let l=Number(i.getPositions()[s.toHead].fret)>Number(a.getPositions()[s.fromHead].fret),c=(u,f)=>{let p={firstNote:u,lastNote:f,firstIndexes:[s.fromHead],lastIndexes:[s.toHead]},h=s.kind==="slide"||s.kind==="glissando"?new ce.TabSlide(p,l?ce.TabSlide.SLIDE_UP:ce.TabSlide.SLIDE_DOWN):u?s.kind==="pull"?ce.TabTie.createPulloff(p):ce.TabTie.createHammeron(p):new ce.TabTie(p);u&&(s.kind==="hammer"||s.kind==="pull")&&h.setFont({...h.fontInfo,family:ze(),weight:kt()}),t({source:u??f,head:u?s.fromHead:s.toHead,bounds:h.getRibbonBounds(),draw:k=>h.setContext(k).draw()})};a.getStave().getY()===i.getStave().getY()?c(a,i):(c(a),c(void 0,i))}}function Po(o,e){let n=new Map;for(let t of o.measures)for(let s of e.staves)for(let r of Dt(t,s))for(let a of r.events)n.set(e.eventId(s,a.id),{event:a,staff:s,voice:r,measure:t});return{prepareNote(t,s){let r=n.get(t.id);r?So(s,r.event,r.staff,r.voice,r.staff===e.staves[0]):e.textLanes.prepare(t.id,s)},place(t,s){let r=new Map,a=new Map;if(e.printAnchors)for(let u of t.sheet.getContinuousLayout().rows){let f=Nn(u.measures.flatMap(p=>t.staves[p-1]));for(let p of u.measures)a.set(p,f)}for(let u of t.notes)for(let f of u)for(let p of f)for(let h of p){let E=h.getAttribute("id"),k=n.get(E),S=h;if(!k){e.textLanes.place(S,s,t);continue}let{measure:P,voice:B,staff:j,event:A}=k;r.set(E,S),e.printAnchors&&S.preFormatted&&a.has(P.number)&&(!e.printAnchors.has(A.id)||j===e.staves[0])&&e.printAnchors.set(A.id,{measure:P.number,x:S.getAbsoluteX(),row:a.get(P.number)}),A.silent&&(S.renderOptions.draw=!1);let T=S.checkStave();if(P.state.hideClef)for(let V of T.getModifiers(void 0,ce.Clef.CATEGORY))V.setText("");if(P.state.color){let V=ke(P.state.color);T.setStyle(V),S.getVoice().setStyle(V),S.getBeam()?.setStyle(V)}if(j==="tab"&&!B.tabStems)for(let V of S.getTupletStack())V.setRendered();Eo(S,A,e,j)}Mo(o,e,r,s),e.mixedEndings.length&&To(o,e,t,r,s);let i=r.get(e.eventId(e.staves[0],Dt(o.measures[0],e.staves[0])[0]?.events[0]?.id));if(!i)return;let l=t.sheet.getRows()[0],c=!e.nativeHeading&&o.layout?.heading;if(c){let u=i.checkStave().getYForLine(0);s({source:i,bounds:{x:l.x,y:u-150,w:l.width,h:145},draw:f=>{Zs(f,c,l.x,l.width,c.align==="center"?u-150:u)}})}}}}function _o(o,e){let n=new Set(o.measures.flatMap(t=>t.voices.filter(s=>!s.tabStems).flatMap(s=>s.events.filter(r=>!r.heads.length).map(r=>e.eventId("tab",r.id)))));for(let t of o.measures)for(let s of t.voices)for(let r of s.events)if(r.silent)for(let a of e.staves)n.add(e.eventId(a,r.id));return n}var gr=class extends ce.ScoreNavigation{constructor(e,n,t,s){super(e,n,t);let r=[],a=0;for(let{score:l,view:c}of s)for(let u of c.staves){let f=n[a++];for(let p of l.measures)for(let[h,E]of Dt(p,u).entries())for(let k of E.events)k.silent&&r.push({id:c.eventId(u,k.id),source:k.id,staff:f.id,measure:p.number,voice:h+1,onset:k.onset,duration:k.duration,label:["Measure "+p.number,f.name||f.id,"voice "+(h+1),k.duration+" rest"].join(", ")})}let i=new Map(n.map((l,c)=>[l.id,c]));r.length&&(this.events=[...this.events,...r].sort((l,c)=>l.measure-c.measure||new ce.Fraction().parse(l.onset).value()-new ce.Fraction().parse(c.onset).value()||i.get(l.staff)-i.get(c.staff)||l.voice-c.voice))}};function No(o,e,n){let t=new Map;for(let s of o.sheet.getContinuousLayout().rows){let r=Nn(s.measures.flatMap(a=>o.staves[a-1]));for(let{score:a,view:i}of e)for(let l of s.measures)for(let c of a.measures[l-1].voices)for(let u of c.events){let f=c.hand?[c.hand]:i.staves,p=n.heads.get(u.id).flatMap(E=>{if(E.role==="mark"||E.reference||typeof E.sourceHead!="number")return[];let k=u.heads[E.sourceHead];if(u.silent||!k||!k.sounding&&k.midi===void 0)return[];let S=E.bounds;return[{x:S.x+S.w/2,y:S.y+S.h/2}]}),h=p[0]?.x??o.getNote(i.eventId(f[0],u.id)).getAbsoluteX();t.set(u.id,{row:r,x:h,heads:p})}}return t}function zt(o,e,n={}){let t=n.part??"score",s="parts"in e?Xe(e,st(e,n)):e;return St(s.layout?.font,()=>si(o,[br(s,t)],t,n))}function Fn(o,e,n={}){return St(e.layout?.font,()=>si(o,e.parts.map((t,s)=>Xe(e,s)),"score",n,!0))}function si(o,e,n,t,s=!1){let r=e[0],a=t.width??r.layout?.width??(o.clientWidth||640);if(!Number.isFinite(a)||a<=20)throw new RangeError("Score width must exceed 20 pixels");let i=e.map(L=>ri(L,n,a-20)),l=i.map(L=>L.spec),c=s?dr(e,l):l[0],u=document.createElement("div"),f=t.renderer==="canvas"?u.appendChild(document.createElement("canvas")):void 0,p=f?new ce.CanvasContext(f.getContext("2d")):new ce.SVGContext(u);f||en(p,o),r.layout?.heading&&!i[0].nativeHeading&&(c.sheet.y+=125),i.some(L=>L.mixedEndings.length)&&(c.sheet.y+=20);let h=new ce.Factory({renderer:{elementId:null,width:a,height:1}}).setContext(p),E=h.EasyScore();if(f){let L=c.engraving.place;c.engraving={...c.engraving,place(X,se){let ee=0;for(let Q of X.sheet.getContinuousLayout().detailMarks)ee=Math.max(ee,Q.bounds.y+Q.bounds.h);L(X,Q=>{ee=Math.max(ee,Q.bounds.y+Q.bounds.h),se(Q)}),B(X.sheet,ee)}}}let k=E.compose(c),S=0,P=i.map((L,X)=>{let se=i.length===1?k:Vs(k,S,L.staves.length);return S+=L.staves.length,{score:e[X],view:L,local:se}});function B(L,X=0){let se=Math.max(a,...L.getRows().map(ee=>ee.x+ee.width+10));p.resize(se,Math.ceil(Math.max(L.getHeight(),X)+20))}let j=[],A=i.flatMap(L=>L.frames.map(X=>({frame:X,sources:L.sources})));if(A.length){let L=ce.Registry.getDefaultRegistry(),X=L??new ce.Registry;L||ce.Registry.enableDefaultRegistry(X);try{h.draw(),X.getElementsByType(ce.FretDiagram.CATEGORY).filter(ee=>ee.isRendered()&&ee.getContext()===p).forEach((ee,Q)=>{let{frame:te,sources:de}=A[Q],{x:pe,y:C,w:K,h:ne}=ee.getBoundingBox();de.ids[ee.getAttribute("id")]=te.source,j.push({id:te.id,source:te.source,kind:"event",x:pe,y:C,w:K,h:ne})})}finally{L||ce.Registry.disableDefaultRegistry()}}else h.draw();let T=i.flatMap(L=>[...L.textLanes.regions.values()]),V=[...T,...j,...i.flatMap(L=>L.endingRegions)],U=Object.assign(Object.create(null),...i.map(L=>L.sources.ids)),Y=P.flatMap(({score:L,view:X},se)=>X.staves.map(ee=>{let Q=L.measures[0].state,te=L.instrument?.name??(Q.piano?"Piano":Q.tab?"Guitar":"Part "+(se+1)),de={right:"right hand",left:"left hand",tab:"tablature",notation:"notation"}[ee];return te+", "+de})),G=s?c.staves.map((L,X)=>({...L,name:Y[X]})):c.staves,R=new gr(k,G,U,P),M=new Map(P.flatMap(({score:L,view:X})=>L.ties.map(se=>[X.eventId("tab",se.id),[]])));for(let L of R.regions)M.get(L.id)?.push(L);let q=[...M.values()].flat(),v=new Set(P.flatMap(({score:L,view:X})=>[..._o(L,X)]));function _(L,X){let se=de=>L>=de.x&&L<=de.x+de.w&&X>=de.y&&X<=de.y+de.h,ee=T.find(se);if(ee)return ee;let Q=R.heads.hitTest(L,X);if(Q&&typeof Q.sourceHead=="number"&&Q.role!=="mark")return{id:Q.sourceEvent+"-head-"+Q.sourceHead,source:Q.sourceEvent,kind:"event",...Q.bounds};let te=R.hitTest(L,X);return te&&!v.has(te.id)?te:V.find(se)}f?(f.setAttribute("role","img"),f.setAttribute("aria-label",R.events.map(L=>L.label).join(". "))):B(k.sheet);let O=r.layout?.scale??1;if(O!==1){let L=f??p.svg;L.style.zoom=String(O),f||(u.style.width=parseFloat(L.style.width)*O+"px")}o.replaceChildren(u);function W(L,X,se){return J(L+"-head-"+X,se)}function J(L,X){for(let se of i){let ee=se.sources.rangeFor(L,X);if(ee)return ee}}let ae=k.sheet.getContinuousLayout().diagnostics.map(L=>({...L,range:L.source&&J(L.source,r.source)||r.measures[L.measures[0]-1]?.range}));for(let L of r.measures)if(e.some(X=>X.measures[L.number-1].voices.some(se=>se.events.some(ee=>ee.chord||ee.lyric))))for(let X of k.systems[L.number-1].getPhraseLayout().diagnostics){let se=X.sources.find(ee=>J(ee,r.source));ae.push({code:X.code,measures:[L.number],source:se,range:J(se,r.source)??L.range})}return Ht.set(f??p.svg,{score:r,ensemble:s?e:void 0,read:()=>St(r.layout?.font,()=>No(k,P,R))}),{score:r,parts:e,composition:k,navigation:R,hitTest:_,tabRegions:q,extraRegions:V,diagnostics:ae,rangeFor:J,headRangeFor:W,sourceFor:L=>U[L]}}function br(o,e,n){let t=e==="right"||e==="left"?e:void 0;if(!t&&n===void 0)return o;if(t&&!o.measures[0].state.piano)throw new oe("measure","A hand part needs a piano score",o.measures[0].range);if(!t&&o.measures[0].state.piano&&n!==void 0)throw new oe("measure","Choose a hand before selecting its voice",o.measures[0].range);let s=new Set,r=o.measures.map(l=>{let c=t?Dt(l,t):l.voices;if(n!==void 0){let u=c[n-1];if(!Number.isInteger(n)||!u)throw new oe("measure","Missing voice "+n+" in bar "+l.number,l.range);c=[{...u,stem:void 0}]}for(let u of c)for(let f of u.events)s.add(f.id);return{...l,voices:c.map((u,f)=>({...u,rehearsal:f?u.rehearsal:l.voices[0].rehearsal,events:t?u.events.map(p=>p.displayHand?{...p,displayHand:void 0}:p):u.events}))}}),a=o.ties.filter(l=>s.has(l.from)&&s.has(l.to)),i=(o.spans??[]).filter(l=>l.kind==="volta"||s.has(l.from)).map(l=>{if(l.kind!=="volta")return l;let c=r[l.lastBar-1].voices[0].events;return{...l,from:r[l.firstBar-1].voices[0].events[0].id,to:c[c.length-1].id}});return{...o,measures:r,ties:a,spans:i}}function Bn(o,e,n,t={}){let{voice:s,partId:r,partIndex:a,...i}=t;return St(e.layout?.font,()=>"parts"in e?oi(o,e,st(e,{partId:r,partIndex:a}),i,n,s):ai(o,[br(e,n,s)],[n],i))}function ii(o,e,n="conductor",t={}){return St(e.layout?.font,()=>oi(o,e,n==="conductor"?n:st(e,n),t,"score"))}function oi(o,e,n,t,s,r){let a=n==="conductor",i=Ys(e,n,t),l=t.regions===void 0?i.cues.map(p=>st(e,{partId:p.part})):[],c=a?e.parts.map((p,h)=>h):[...new Set([n,...l])],u=c.map((p,h)=>{let E=Xe(e,p);return h===0&&!a?br(E,s,r):E}),f=u.map((p,h)=>h===0?s:"score");return ai(o,u,f,i.settings,{conductor:a,donors:l.map(p=>c.indexOf(p)),edition:i,document:e})}function ai(o,e,n,t,s){let r=e[0],a=e.map((A,T)=>ri(A,n[T],600,!0)),i=a.length>1?dr(e,a.map(A=>A.spec)):a[0].spec;s?.conductor||(i.continuous.boundaries=a[0].spec.continuous.boundaries),s?.conductor||(i.continuous.opening=a[0].spec.continuous.opening);let{compressRests:l,...c}=t;if(l){let A=new Set([...c.preferredTurns??[],...c.forbiddenTurns??[]].map(T=>T+1));i.continuous.compressRests=!0,i.continuous.boundaries=i.continuous.boundaries.flatMap(T=>A.has(T.measure)||r.measures[T.measure-1].state.fragment?[{...T,keepRest:!0}]:T.rehearsal||T.breakBefore||T.repeatStart||T.repeatEnd?[T]:[])}let{noteHooks:u,...f}=c;if(u?.length){for(let T of i.staves)for(let V of T.measures)for(let U of V.voices)typeof U.notes!="string"&&(U.notes=U.notes.map(Y=>typeof Y!="object"||!("skip"in Y)||typeof Y.skip=="string"?Y:"B4/"+Y.skip.duration+"/g"+".".repeat(Y.skip.dots??0)+'[id="'+Y.id+'"]'));let A=i.engraving.prepareNote;i.engraving={...i.engraving,prepareNote(T,V,U){A(T,V,U);for(let Y of u)Y(T,V,U)}}}s&&!s.conductor&&(f.staves=i.staves.slice(0,a[0].staves.length).map(A=>A.id)),s?.donors.length&&(f.regions=s.edition.cues.map((A,T)=>{let V=a.slice(0,s.donors[T]).reduce((U,Y)=>U+Y.staves.length,0);return{kind:"cue",staff:i.staves[V].id,label:A.label,measure:A.measure}}));let p=fr(r.source),h;try{h=new ce.Publication(i).render(o,f)}catch(A){throw s?.edition.range&&A.code==="BadPublication"?new oe("fixed-layout",A.message,p(s.edition.range)):A}let E=(s?.conductor?a:a.slice(0,1)).flatMap(A=>A.frames.map(T=>({frame:T,sources:A.sources})));E.length&&h.pages.flatMap(T=>[...T.svg.querySelectorAll(".vf-score-opening .vf-fret-diagram")]).forEach((T,V)=>{let U=T.getAttribute("data-vf-id")?.replace(/^vf-/,"");U&&E[V]&&(E[V].sources.ids[U]=E[V].frame.source)});let k=(A,T)=>a.map(V=>V.sources.rangeFor(A,T)).find(Boolean),S=h.diagnostics.map(A=>{let T=A.measures[0],V=A.code==="ForbiddenTurn"&&s?.edition.anchors.find(M=>M.field==="forbiddenTurns"&&M.measure===T),U=A.detail.startsWith("cue exceeds")&&s?.edition.cues.find(M=>M.measure===T),Y=V||U,G=A.code==="ExcludedAnchor"?A.detail:A.detail.split(" ")[1],R=Y?p(Y.range):k(G,r.source)||A.code==="TextOverflow"&&s?.edition.range&&p(s.edition.range)||r.measures[T-1]?.range;return{...A,range:R}}),P=new Map,B=s?.conductor?e:[r];for(let A of B)for(let T of A.measures)for(let V of T.voices)for(let U of V.events)P.set(U.id,U);let j=new Map((s?.conductor?a:a.slice(0,1)).flatMap(A=>[...A.printAnchors]));for(let A of h.pages)Ht.set(A.svg,{score:r,ensemble:s?.conductor?e:void 0,read:()=>zs(h,P,j,(f.staffSize??7)/40)});return{publication:h,diagnostics:S,score:r,rangeFor:k,headRangeFor:(A,T,V)=>k(A+"-head-"+T,V),sourceFor:A=>a.map(T=>T.sources.sourceFor(A)).find(Boolean)}}li();function Re(o,e,n){return o.getAttribute(`data-${e}`)||(n?o.getAttribute(`data-${n}`):null)||o.getAttribute(e)}function Ao(o){let e=Re(o,"playback-controls"),n=Re(o,"playback-position"),t=Re(o,"playback-inset"),s=Re(o,"playback-size");if(e===null&&n===null&&t===null&&s===null)return;if(e==="off"||e==="false")return!1;let r={};return e&&e!=="on"&&e!=="true"&&(r.visibility=e),s&&(r.size=s),n&&(r.position=n),t!==null&&(r.inset=Number(t)),En(r),(e==="on"||e==="true")&&!r.visibility&&(r.visibility="hover"),r}function xr(o,e){let n=Re(o,"layout");return n==="flow"||!n&&/^[ \t]*piano(?:\s|$)/m.test(e)}var yr=class{constructor(e,n={}){this.part="score";this.disposed=!1;this.composing=!1;this.surface=null;this.text_area=null;this.editor_error=null;this.timeoutID=null;if(this.order=n.order,this.playback=n.playback??pt(),this.sel=e,!this.sel)throw new Error(`VexTab.Div: invalid selector: ${e}`);this.code=(0,Fe.default)(e).text(),(0,Fe.default)(e).empty(),(0,Fe.default)(e).css("position")==="static"&&(0,Fe.default)(e).css("position","relative");let t=(0,Fe.default)(e)[0];this.playbackControls=n.playbackControls??Ao(t),this.enablePlayer=n.player??(this.playbackControls===void 0?void 0:!!this.playbackControls);let s=Re(t,"performer");if(n.performer!==void 0)this.performer=n.performer;else if(s){if(!yt(s))throw new RangeError("Unknown performer: "+s);this.performer=s}this.seed=n.seed;let r=Re(t,"width");this.width=parseInt(r,10)||400,this.scale=parseFloat(Re(t,"scale"))||1,this.rendererBackend=Re(t,"renderer")||"svg";let a=n.language??Number(Re(t,"language")??2);if(a!==1&&a!==2)throw new RangeError("Expected VexTab language 1 or 2");this.grammar2=a===2;let i=n.capacity??Re(t,"capacity")??"default";if(i!=="default"&&i!=="large")throw new RangeError("Expected score capacity default or large");if(this.capacity=i,this.partIndex=n.partIndex,this.partId=n.partId??Re(t,"part-id")??void 0,this.conductor=(n.view??Re(t,"view"))==="conductor",this.conductor&&(!this.grammar2||this.partIndex!==void 0||this.partId!==void 0))throw new Error("The conductor view requires a complete v2 score");this.flow=this.grammar2||xr(t,this.code),t.classList.toggle("vextab-flow",this.flow),this.editor=Re(t,"editor")||"",this.show_errors=Re(t,"show-errors")||"",this.editor_width=parseInt(Re(t,"editor-width","editor_width"),10)||this.width,this.editor_height=parseInt(Re(t,"editor-height","editor_height"),10)||200,this.editor==="true"?(this.text_area=(0,Fe.default)('<textarea aria-label="VexTab source"></textarea>').addClass("editor").val(this.code),this.code=this.text_area.val(),this.editor_error=(0,Fe.default)('<div role="status"></div>').addClass("editor-error"),(0,Fe.default)(e).append((0,Fe.default)("<p/>")).append(this.editor_error),(0,Fe.default)(e).append((0,Fe.default)("<p/>")).append(this.text_area),this.text_area.width(this.editor_width),this.text_area.height(this.editor_height),this.text_area.on("compositionstart.vextab",()=>{this.composing=!0,window.clearTimeout(this.timeoutID)}),this.text_area.on("compositionend.vextab",()=>{this.composing=!1,this.scheduleEdit()}),this.text_area.on("input.vextab",()=>this.scheduleEdit()),this.text_area.on("keydown.vextab",l=>{!this.composing&&(l.ctrlKey||l.metaKey)&&l.key==="Enter"&&(l.preventDefault(),this.run())})):this.show_errors==="true"&&(this.editor_error=(0,Fe.default)('<div role="status"></div>').addClass("editor-error"),(0,Fe.default)(e).append((0,Fe.default)("<p/>")).append(this.editor_error)),this.flow||(this.artist=new qe(10,0,this.width,{scale:this.scale}),this.parser=new Ke(this.artist,{language:1})),this.autoWidth=this.flow&&Re(t,"layout")!=="fixed"&&(r===null||r==="auto"),this.autoWidth&&t.clientWidth>20&&(this.width=t.clientWidth),this.redraw(),document.fonts.status==="loading"&&document.fonts.ready.then(()=>{this.disposed||this.redraw()}),this.autoWidth&&(this.observer=new ResizeObserver(([l])=>{let c=Math.floor(l.contentRect.width);cancelAnimationFrame(this.resizeFrame),c>20&&c!==this.width&&(this.resizeFrame=requestAnimationFrame(()=>{this.width=c,this.draw()}))}),this.observer.observe(t))}dispose(){this.disposed=!0,this.player?.dispose(),this.observer?.disconnect(),cancelAnimationFrame(this.resizeFrame),window.clearTimeout(this.timeoutID),this.text_area?.off(".vextab")}scheduleEdit(){window.clearTimeout(this.timeoutID),this.player?.removeControls(),this.composing||(this.timeoutID=window.setTimeout(()=>this.run(),250))}run(){return window.clearTimeout(this.timeoutID),this.disposed||this.composing?this:(this.code=this.text_area?.val()??this.code,this.redraw())}getReadingEvents(){return this.getScore()?this.current.layouts.flatMap(e=>e.navigation.events):[]}getDiagnosticRange(){return!this.disposed&&this.code===(this.text_area?.val()??this.code)?this.diagnostic:void 0}selectError(){let e=this.getDiagnosticRange();return!e||!this.text_area?!1:(this.text_area[0].focus(),this.text_area[0].setSelectionRange(e.start,e.end),!0)}getScoreDocument(){return!this.disposed&&this.document?.source===(this.text_area?.val()??this.code)?this.document:void 0}setInstrumentView(e,n="score"){if(!this.grammar2)throw new Error("Instrument selection requires a v2 score");return this.conductor=e==="conductor",this.partIndex=e==="conductor"?void 0:e.partIndex,this.partId=e==="conductor"?void 0:e.partId,this.part=e==="conductor"?"score":n,this.run()}setPart(e){if(!this.flow)throw new Error('setPart requires layout="flow"');return this.part=e,this.draw()}redraw(){return Z.BM("Total render time: ",()=>{this.parse(),this.draw()}),this}reportError(e){this.player?.removeControls(),this.diagnostic=e instanceof Ue?{start:e.range[0],end:e.range[1],line:e.line,column:e.column-1}:e.range,this.surface?.setAttribute("data-preview-stale","true");let n=this.surface?"Showing the last valid score. ":"";this.editor_error?.text(n+e.message),(0,Fe.default)(this.sel)[0].dispatchEvent(new Event("vextab-render"))}getScore(){if(!this.disposed&&this.current&&this.current.score===this.candidate&&!this.surface?.hasAttribute("data-preview-stale")&&this.current.score.source===(this.text_area?.val()??this.code))return this.current.score}setWidth(e){if(!this.flow)throw new Error('setWidth requires layout="flow"');return this.observer?.disconnect(),cancelAnimationFrame(this.resizeFrame),this.autoWidth=!1,this.width=e,this.draw()}selectSource(e,n){let t=this.getScore(),s=t&&t===n&&this.current.layouts.map(a=>a.rangeFor(e,t.source)).find(Boolean);if(!s||!this.text_area)return!1;let r=this.text_area[0];return r.focus(),r.setSelectionRange(s.start,s.end),!0}drawView(e,n,t){let s=this.rendererBackend.toLowerCase()==="canvas"?"canvas":"svg",r=Math.max(21,this.width/(n.layout?.scale??1)),a=this.autoWidth?n.layout?.width??r:this.width,i="parts"in n?Fn(e,n,{width:a,renderer:s}):zt(e,n,{width:a,part:this.part,renderer:s}),l=e.querySelector("svg, canvas");return this.text_area&&l.addEventListener("click",c=>{let u;if(l instanceof SVGSVGElement){let p=l.getScreenCTM();if(!p)return;u=new DOMPoint(c.clientX,c.clientY).matrixTransform(p.inverse())}else{let p=l.getBoundingClientRect();if(!p.width||!p.height)return;u=new DOMPoint((c.clientX-p.left)*l.clientWidth/p.width,(c.clientY-p.top)*l.clientHeight/p.height)}let f=i.hitTest(u.x,u.y);f&&this.selectSource(f.id,t)}),{layout:i,surface:l}}drawFlow(e){if(!this.grammar2&&(this.rendererBackend.toLowerCase()!=="svg"||this.scale!==1))throw new Error("Flow layout requires SVG at scale 1. Use width to reflow.");let n=this.candidate,t=this.document,s=t&&this.part==="score"&&this.partId===void 0&&this.partIndex===void 0&&t.parts.length>1,a=this.conductor&&this.part==="score"?[this.drawView(e,t,n)]:s?t.parts.map((i,l)=>{let c=e.appendChild(document.createElement("div"));return this.drawView(c,Xe(t,l),n)}):[this.drawView(e,n,n)];this.grammar2&&this.scale!==1&&(e.style.zoom=String(this.scale)),this.player?.dispose(),this.player=void 0,(this.enablePlayer??n.playback?.enabled)&&(this.player=new We(s?t:a[0].layout.score,{playback:this.playback,controls:this.playbackControls,performer:this.performer,seed:this.seed,order:this.order})).render(a[0].surface,void 0,a.slice(1).map(l=>l.surface)),this.current={score:n,layouts:a.map(i=>i.layout)}}drawInternal(){if(this.flow?!this.candidate:!this.parser.isValid())return this;let e=this.rendererBackend.toLowerCase()==="canvas",n=document.createElement(e&&!this.flow?"canvas":"div");n.className="vex-canvas";let t=(0,Fe.default)(this.sel)[0];t.insertBefore(n,t.firstChild);try{if(this.flow)this.drawFlow(n);else{let r=e?Z.Flow.Renderer.Backends.CANVAS:Z.Flow.Renderer.Backends.SVG,a=new Z.Flow.Renderer(n,r);if(e||en(a.getContext(),n),this.enablePlayer!==void 0&&(this.artist.customizations.player=String(this.enablePlayer)),!this.player&&this.artist.customizations.player==="true"&&(this.player=new We(this.artist,{playback:this.playback,controls:this.playbackControls,performer:this.performer,seed:this.seed})),this.artist.draw(a),e){let i=this.artist.staves.map((l,c)=>{let f=(l.tab?l.tab_voices:l.note_voices).map((p,h)=>"Voice "+(h+1)+". "+p.filter(E=>!E.shouldIgnoreTicks()).map(E=>{let k=E.getPositions?.(),S=l.note?.getClef()==="percussion"?E.notation?.filter(j=>j.kind==="unpitched").map(j=>j.label):void 0,P=S?.length?S:k?.map(j=>"string "+j.str+" fret "+j.fret);return(E.isRest()?"rest":(P??E.getKeys()).join(", "))+" ("+E.getDuration()+")"}).join(". "));return"Stave "+(c+1)+", meter "+l.meter+". "+f.join(". ")}).join(". ");n.setAttribute("role","img"),n.setAttribute("aria-label",i),n.textContent=i}}this.surface?.remove(),this.surface=n;let s=this.flow?this.current.layouts.flatMap(r=>r.diagnostics):[];this.diagnostic=s[0]?.range,this.editor_error?.text(s.map(r=>{let a=r.range?" (line "+r.range.line+", column "+r.range.column+")":"";return(r.code==="RowOverflow"?"Bar "+r.measures.join(", ")+" exceeds this width":r.code)+a}).join(`
|
|
372
|
-
`)),t.dispatchEvent(new Event("vextab-render"))}catch(s){n.remove(),this.reportError(s)}return this}parseInternal(){try{this.flow?(this.candidate=void 0,this.document=this.grammar2?
|
|
366
|
+
`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex(){let e;for(;!e;)e=this.next();return e},begin(e){this.currentCondition=e,this.conditionStack.push(e)},pushState(e){this.begin(e)},popState(){return this.conditionStack.pop(),this.currentCondition=this.conditionStack.length?this.conditionStack[this.conditionStack.length-1]:"INITIAL"},topState(e){return e=this.conditionStack.length-1-Math.abs(e||0),e>=0?this.conditionStack[e]:"INITIAL"},stateStackSize(){return this.conditionStack.length}}})();function rr(){this.yy={}}rr.prototype={Parser:rr,lexer:Ri,symbols_:{error:2,e:3,maybe_vextab:4,EOF:5,vextab:6,stave:7,voice:8,maybe_options:9,stave_data:10,OPTIONS:11,options:12,TABSTAVE:13,STAVE:14,PIANO:15,VOICE:16,stave_additions:17,TEXT:18,text:19,NOTES:20,notes:21,SLUR:22,option_value:23,WORD:24,QUOTED_VALUE:25,"=":26,STR:27,",":28,lingo:29,line:30,drum:31,"(":32,drum_hits:33,")":34,chord:35,time:36,bar:37,"[":38,"]":39,tuplets:40,annotations:41,command:42,rest:43,DRUM:44,".":45,"|":46,":":47,frets:48,maybe_decorator:49,"/":50,string:51,maybe_head_marks:52,HEAD_MARKS:53,chord_line:54,articulation:55,fret:56,NUMBER:57,SLIDE_END:58,PREBEND:59,abc:60,_:61,timed_fret:62,time_values:63,maybe_dot:64,time_unit:65,maybe_slash:66,w:67,h:68,q:69,d:70,S:71,"-":72,s:73,t:74,T:75,b:76,p:77,v:78,V:79,u:80,"^":81,$:82,annotation_words:83,"!":84,COMMAND:85,"#":86,ABC:87,abc_accidental:88,accidental_type:89,"@":90,n:91,"~":92,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",11:"OPTIONS",13:"TABSTAVE",14:"STAVE",15:"PIANO",16:"VOICE",18:"TEXT",20:"NOTES",22:"SLUR",24:"WORD",25:"QUOTED_VALUE",26:"=",27:"STR",28:",",32:"(",34:")",38:"[",39:"]",44:"DRUM",45:".",46:"|",47:":",50:"/",53:"HEAD_MARKS",57:"NUMBER",58:"SLIDE_END",59:"PREBEND",61:"_",67:"w",68:"h",69:"q",70:"d",71:"S",72:"-",73:"s",74:"t",75:"T",76:"b",77:"p",78:"v",79:"V",80:"u",81:"^",82:"$",84:"!",85:"COMMAND",86:"#",87:"ABC",90:"@",91:"n",92:"~"},productions_:[0,[3,2],[4,0],[4,1],[6,1],[6,2],[7,3],[7,2],[7,2],[8,1],[8,1],[8,1],[8,1],[10,1],[10,2],[17,2],[17,2],[17,2],[9,0],[9,1],[23,1],[23,1],[12,3],[12,4],[19,1],[19,3],[21,1],[21,2],[29,1],[29,1],[29,3],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[29,1],[31,1],[33,1],[33,3],[37,1],[37,3],[37,3],[37,3],[37,3],[37,3],[30,5],[52,1],[52,0],[54,1],[54,3],[35,4],[35,5],[56,1],[56,2],[56,2],[56,1],[48,1],[48,1],[48,4],[48,2],[48,4],[62,5],[62,1],[62,5],[62,8],[62,1],[62,4],[36,3],[63,2],[65,1],[65,1],[65,1],[65,1],[64,0],[64,1],[64,2],[66,0],[66,1],[51,1],[55,1],[55,1],[55,1],[55,1],[55,1],[55,1],[55,1],[49,1],[49,1],[49,1],[49,1],[49,0],[40,3],[40,5],[41,3],[83,1],[83,3],[42,3],[43,2],[43,3],[43,4],[60,3],[88,1],[88,2],[88,1],[88,2],[88,1],[88,0],[89,0],[89,1]],table:[{3:1,4:2,5:[2,2],6:3,7:4,8:5,11:Hr,13:Dr,14:zr,15:jr,16:Gr},{1:[3]},{5:[1,11]},{5:[2,3],7:12,8:5,11:Hr,13:Dr,14:zr,15:jr,16:Gr},J(qt,[2,4]),J(at,Wr,{9:13,12:14,24:Xn}),{12:16,24:Xn},J(ct,[2,9]),J(ct,[2,10]),J(ct,[2,11]),J(ct,[2,12]),{1:[2,1]},J(qt,[2,5]),J(qt,[2,7],{10:17,17:18,18:qr,20:Ur,22:Kr}),J(at,[2,19],{24:Xr}),{26:[1,23]},J(qt,[2,8],{24:Xr}),J(qt,[2,6],{17:24,18:qr,20:Ur,22:Kr}),J(at,[2,13]),{19:25,27:[1,26]},{21:27,26:Yr,29:28,30:29,31:30,32:Jr,35:32,36:33,37:34,38:$r,39:Zr,40:37,41:38,42:39,43:40,44:cn,46:Qr,47:es,48:41,55:43,56:51,57:Qe,58:et,59:tt,60:52,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt,81:ts,82:ns,84:rs,86:ss,87:nt},J(at,Wr,{12:14,9:64,24:Xn}),{26:[1,65]},{23:66,24:is,25:os},J(at,[2,14]),J(at,[2,15],{28:[1,69]}),J(as,[2,24]),J(at,[2,16],{30:29,31:30,35:32,36:33,37:34,40:37,41:38,42:39,43:40,48:41,55:43,56:51,60:52,29:70,26:Yr,32:Jr,38:$r,39:Zr,44:cn,46:Qr,47:es,57:Qe,58:et,59:tt,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt,81:ts,82:ns,84:rs,86:ss,87:nt}),J(he,[2,26]),J(he,[2,28]),J(he,[2,29]),{30:74,31:73,33:71,44:cn,48:41,54:72,55:75,56:51,57:Qe,58:et,59:tt,60:52,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt,87:nt},J(he,[2,31]),J(he,[2,32]),J(he,[2,33]),J(he,[2,34]),J(he,[2,35]),J(he,[2,36]),J(he,[2,37]),J(he,[2,38]),J(he,[2,39]),J([50,68,72,73,74,75,76,77],Yn,{49:76,70:Jn,78:$n,79:Zn,80:Qn}),J(ln,[2,40]),{32:[1,81],47:er,56:84,57:Qe,58:et,59:tt,60:85,62:82,87:nt},{57:cs,63:86,65:87,67:ls,68:us,69:ds},J(he,[2,43]),{46:[1,92],47:[1,93]},{57:[1,94]},{24:[1,96],83:95},{85:[1,97]},{57:[1,99],72:[1,100],86:[1,98]},J(Ve,[2,60]),J(Ve,[2,61],{57:[1,101]}),J(bt,[2,83]),J(bt,[2,84]),J(bt,[2,85]),J(bt,[2,86]),J(bt,[2,87]),J(bt,[2,88]),J(bt,[2,89]),J(Ve,[2,56],{58:[1,102]}),{57:[1,103]},J(Ve,[2,59]),J(Ct,[2,110],{88:104,86:[1,105],90:[1,106],91:[1,107]}),J(at,[2,17]),{23:108,24:is,25:os},J(ct,[2,22]),J(ct,[2,20]),J(ct,[2,21]),{27:[1,109]},J(he,[2,27]),{34:[1,110],45:[1,111]},{34:[1,112],45:fs},J(un,[2,41]),J(un,[2,52]),{47:er,56:84,57:Qe,58:et,59:tt,60:85,62:82,87:nt},{50:[1,114],55:115,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt},J(dn,[2,90]),J(dn,[2,91]),J(dn,[2,92]),J(dn,[2,93]),{30:74,48:41,54:116,55:75,56:51,57:Qe,58:et,59:tt,60:52,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt,87:nt},J(Ve,[2,63]),{57:cs,63:117,65:87,67:ls,68:us,69:ds},J(Ve,[2,66]),J(Ve,[2,69],{57:[1,118]}),J(he,ms,{64:119,70:ps}),J(tr,[2,80],{66:121,71:[1,122]}),J(fn,[2,73]),J(fn,[2,74]),J(fn,[2,75]),J(fn,[2,76]),{26:[1,124],46:[1,123],47:[1,125]},{46:[1,126],47:[1,127]},{28:[1,129],81:[1,128]},{28:[1,131],82:[1,130]},J(hs,[2,98]),{84:[1,132]},J(he,[2,101]),{86:[1,133]},{57:[1,134]},{61:[1,135]},J(Ve,[2,58]),J(Ve,[2,57]),J(nr,[2,111],{89:136,92:[1,137]}),J(Ct,[2,105],{86:[1,138]}),J(Ct,[2,107],{90:[1,139]}),J(Ct,[2,109]),J(ct,[2,23]),J(as,[2,25]),J(he,[2,30]),{31:140,44:cn},J(he,Yn,{49:141,70:Jn,78:$n,79:Zn,80:Qn}),{30:142,48:41,55:75,56:51,57:Qe,58:et,59:tt,60:52,68:Mt,72:Tt,73:Pt,74:Nt,75:_t,76:At,77:Rt,87:nt},{51:143,57:[1,144]},{47:er,56:84,57:Qe,58:et,59:tt,60:85,62:145,87:nt},{34:[1,146],45:fs},{47:ms,64:147,70:ps},{61:[1,148]},J(he,[2,71]),J(he,[2,78],{70:[1,149]}),J(tr,[2,72]),J(tr,[2,81]),J(he,[2,44]),J(he,[2,45]),J(he,[2,47]),J(he,[2,46]),J(he,[2,48]),J(he,[2,95]),{57:[1,150]},J(he,[2,97]),{24:[1,151]},J(he,[2,100]),J(he,[2,102]),{86:[1,152]},{57:[1,153]},J(nr,[2,104]),J(nr,[2,112]),J(Ct,[2,106]),J(Ct,[2,108]),J(un,[2,42]),J(he,[2,54]),J(un,[2,53]),J(ln,[2,51],{52:154,53:[1,155]}),J([5,11,13,14,15,16,18,20,22,26,32,34,38,39,44,45,46,47,53,57,58,59,68,72,73,74,75,76,77,81,82,84,86,87],[2,82]),J(Ve,[2,64]),J(he,Yn,{49:156,70:Jn,78:$n,79:Zn,80:Qn}),{47:[1,157]},{57:[1,158]},J(he,[2,79]),{81:[1,159]},J(hs,[2,99]),J(he,[2,103]),J(Ve,[2,62]),J(ln,[2,49]),J(ln,[2,50]),J(he,[2,55]),{56:160,57:Qe,58:et,59:tt,60:161,87:nt},J(Ve,[2,70]),J(he,[2,96]),J(Ve,[2,65]),J(Ve,[2,67],{57:[1,162]}),{61:[1,163]},{57:[1,164]},J(Ve,[2,68])],defaultActions:{11:[2,1]},performAction(o,e,n,t,s,r,a){let i=r.length-1;switch(s){case 1:return r[i-1];case 2:case 18:case 51:case 94:this.$=null;break;case 3:case 13:case 19:case 28:case 31:case 32:case 52:case 73:case 74:case 75:case 76:case 82:this.$=r[i];break;case 4:t.locate&&(r[i].range=t.locate(a[i])),this.$=[r[i]];break;case 5:t.locate&&(r[i].range=t.locate(a[i])),this.$=[].concat(r[i-1],r[i]);break;case 6:this.$={element:r[i-2],options:r[i-1],notes:r[i].notes,text:r[i].text,...t.locate?{slurs:r[i].slurs}:{},_l:a[i-2].first_line,_c:a[i-2].first_column};break;case 7:this.$={element:r[i-1],options:r[i],_l:a[i-1].first_line,_c:a[i-1].first_column};break;case 8:this.$={element:"options",params:r[i],_l:a[i-1].first_line,_c:a[i-1].first_column};break;case 14:var c=[].concat(r[i-1].text,r[i].text),l=[].concat(r[i-1].notes,r[i].notes),u=[].concat(r[i-1].slurs,r[i].slurs);this.$={text:c,notes:l,slurs:u};break;case 15:t.locate&&(r[i][0].declaration=t.locate(this._$)),this.$={text:r[i],notes:[],slurs:[]};break;case 16:this.$={notes:r[i],text:[],slurs:[]};break;case 17:this.$={slurs:t.locate?[{range:t.locate(this._$)}]:r[i],notes:[],text:[]};break;case 21:this.$=r[i].slice(1,-1);break;case 22:this.$=[{key:r[i-2],value:r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i-2].first_line,_c:a[i-2].first_column}];break;case 23:this.$=[].concat(r[i-3],[{key:r[i-2],value:r[i],...t.locate?{range:t.locate({...a[i-2],last_line:a[i].last_line,last_column:a[i].last_column})}:{},_l:a[i-2].first_line,_c:a[i-2].first_column}]);break;case 24:this.$=[{text:r[i],...t.locate?{range:t.locate(a[i])}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 25:this.$=[].concat(r[i-2],{text:r[i],...t.locate?{range:t.locate(a[i])}:{},_l:a[i].first_line,_c:a[i].first_column});break;case 26:t.locate&&[].concat(r[i]).forEach(f=>f.range||=t.locate(a[i])),this.$=t.locate?[].concat(r[i]):r[i];break;case 27:t.locate&&[].concat(r[i]).forEach(f=>f.range||=t.locate(a[i])),this.$=[].concat(r[i-1],r[i]);break;case 29:this.$=[{drums:[r[i]],_l:a[i].first_line,_c:a[i].first_column}];break;case 30:this.$=[{drums:r[i-1],_l:a[i-2].first_line,_c:a[i-2].first_column}];break;case 33:this.$=[{command:"bar",type:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 34:this.$=[{command:"open_beam",_l:a[i].first_line,_c:a[i].first_column}];break;case 35:this.$=[{command:"close_beam",_l:a[i].first_line,_c:a[i].first_column}];break;case 36:this.$=[{command:"tuplet",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 37:this.$=[{command:"annotations",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 38:this.$=[{command:"command",params:r[i],_l:a[i].first_line,_c:a[i].first_column}];break;case 39:this.$=[{command:"rest",params:r[i]}];break;case 40:this.$={id:r[i],...t.locate?{range:t.locate(a[i])}:{}};break;case 41:case 98:this.$=[r[i]];break;case 42:case 53:case 99:this.$=[].concat(r[i-2],r[i]);break;case 43:this.$="single";break;case 44:this.$="double";break;case 45:this.$="end";break;case 46:this.$="repeat-end";break;case 47:this.$="repeat-begin";break;case 48:this.$="repeat-both";break;case 49:Ze(me(r[i-4]),{decorator:r[i-3]}),sn(r[i-4],function(f){f.string=r[i-1]}),r[i]&&(me(r[i-4]).suffix=r[i]),t.locate&&(me(r[i-4]).range.end=t.locate(r[i]?a[i]:a[i-1]).end),this.$=r[i-4];break;case 50:this.$={text:r[i],range:t.markRange(a[i])};break;case 54:this.$=[{chord:r[i-2],decorator:r[i]}];break;case 55:this.$=[{chord:r[i-2],articulation:r[i-4],decorator:r[i]}];break;case 56:this.$={fret:r[i]};break;case 57:this.$={fret:r[i],openSlide:{edge:"in",side:r[i-1]===">"?"above":"below"}};break;case 58:this.$={fret:r[i-1],openSlide:{edge:"out",side:r[i]===">"?"above":"below"}};break;case 59:this.$=t.prebend(r[i],this._$);break;case 60:this.$=[{...r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 61:this.$=[{abc:r[i],...t.locate?{range:t.locate(this._$)}:{},_l:a[i].first_line,_c:a[i].first_column}];break;case 62:this.$=[{abc:r[i-3],...t.locate?{range:t.locate(this._$)}:{},octave:r[i-2],fret:r[i],_l:a[i-3].first_line,_c:a[i-3].first_column}];break;case 63:this.$=[Ze(r[i],{articulation:r[i-1],...t.locate?{range:t.locate(this._$)}:{}})];break;case 64:Ze(me(r[i-3]),{decorator:r[i-2]}),t.locate&&r[i-2]&&(me(r[i-3]).range.end=t.locate(a[i-2]).end),Ze(r[i],{articulation:r[i-1]}),t.locate&&(r[i].range=t.locate({...a[i-1],last_line:a[i].last_line,last_column:a[i].last_column})),r[i-3].push(r[i]),this.$=r[i-3];break;case 65:this.$={time:r[i-3],dot:r[i-2],...r[i],_l:a[i-4].first_line,_c:a[i-4].first_column};break;case 66:this.$={...r[i],_l:a[i].first_line,_c:a[i].first_column};break;case 67:this.$={time:r[i-3],dot:r[i-2],abc:r[i]};break;case 68:this.$={time:r[i-6],dot:r[i-5],abc:r[i-3],octave:r[i-2],fret:r[i]};break;case 69:this.$={abc:r[i],_l:a[i].first_line,_c:a[i].first_column};break;case 70:this.$={abc:r[i-3],octave:r[i-2],fret:r[i],_l:a[i-3].first_line,_c:a[i-3].first_column};break;case 71:this.$={time:r[i-1],dot:r[i]};break;case 72:this.$=r[i-1]+r[i];break;case 77:this.$=!1;break;case 78:this.$=!0;break;case 79:this.$=2;break;case 80:this.$="";break;case 81:case 84:this.$="s";break;case 83:this.$="-";break;case 85:this.$="t";break;case 86:this.$="T";break;case 87:this.$="b";break;case 88:this.$="h";break;case 89:this.$="p";break;case 90:this.$="v";break;case 91:this.$="V";break;case 92:this.$="u";break;case 93:this.$="d";break;case 95:this.$={tuplet:r[i-1]};break;case 96:this.$={tuplet:r[i-3],notes:r[i-1]};break;case 97:case 100:this.$=r[i-1];break;case 101:this.$={position:0};break;case 102:this.$={position:r[i-1],explicit:!0};break;case 103:this.$={position:r[i-1]*-1};break;case 104:this.$={key:r[i-2],accidental:r[i-1],accidental_type:r[i]};break;case 105:this.$="#";break;case 106:this.$="##";break;case 107:this.$="b";break;case 108:this.$="bb";break;case 109:this.$="n";break;case 111:this.$=null;break;case 112:this.$="c";break}},trace(...o){this.DEBUG&&Jison.print(...o)},parseError(o,e){if(e.recoverable)this.trace(o);else{let n=new Error(o);throw n.hash=e,n}},parse(o,...e){let i=W=>{v.length-=2*W,x.length-=W,P.length-=W},c=()=>{let W=l.lex()||1;return typeof W!="number"&&(W=this.symbols_[W]||W),W},l=Object.create(this.lexer),u=l.options&&l.options.ranges,f={...this.yy,parser:this,lexer:l};l.setInput(o,f),typeof f.parseError=="function"&&(this.parseError=f.parseError),typeof l.yylloc>"u"&&(l.yylloc={});let m=this.table,h={},w=l.yylloc,v=[0],x=[null],P=[w],B=[],D="",_=0,M=0,V=0,K,Y;for(;;){let W=v[v.length-1],C;if(this.defaultActions[W]?C=this.defaultActions[W]:((K===null||typeof K>"u")&&(K=c()),C=m[W]&&m[W][K]),!C||!C[0]){let S=function(N){let L=v.length-1,q=0;for(;;){if("2"in m[N])return q;if(N===0||L<2)return!1;L-=2,N=v[L],++q}},T,X="";if(!V){let N=[];for(let L in m[W])L in this.terminals_&&L>2&&N.push("'"+this.terminals_[L]+"'");X=l.showPosition?"Parse error on line "+(_+1)+`:
|
|
367
|
+
`+l.showPosition()+`
|
|
368
|
+
Expecting `+N.join(", ")+", got '"+(this.terminals_[K]||K)+"'":"Parse error on line "+(_+1)+": Unexpected "+(K===1?"end of input":"'"+(this.terminals_[K]||K)+"'"),this.parseError(X,{text:l.match,token:this.terminals_[K]||K,line:l.yylineno,loc:w,expected:N})}if(V===3){if(K===1||Y===1)throw new Error(X||"Parsing halted while starting to recover from another error.");M=l.yyleng,D=l.yytext,_=l.yylineno,w=l.yylloc,K=c()}if(T===!1)throw new Error(X||"Parsing halted. No suitable error recovery rule available.");i(T),Y=K==2?null:K,K=2,W=v[v.length-1],C=m[W]&&m[W][2],V=3}if(Array.isArray(C[0])&&C.length>1)throw new Error("Parse Error: multiple actions possible at state: "+W+", token: "+K);switch(C[0]){case 1:v.push(K),x.push(l.yytext),P.push(l.yylloc),v.push(C[1]),K=null,Y?(K=Y,Y=null):(M=l.yyleng,D=l.yytext,_=l.yylineno,w=l.yylloc,V>0&&V--);break;case 2:{let T=this.productions_[C[1]][1],X=P[P.length-(T||1)],S=P[P.length-1];h.$=x[x.length-T],h._$={first_line:X.first_line,last_line:S.last_line,first_column:X.first_column,last_column:S.last_column},u&&(h._$.range=[X.range[0],S.range[1]]);let N=this.performAction.call(h,D,M,_,f,C[1],x,P,...e);if(typeof N<"u")return N;T&&i(T),v.push(this.productions_[C[1]][0]),x.push(h.$),P.push(h._$),v.push(m[v[v.length-2]][v[v.length-1]]);break}case 3:return!0}}}};var Ci=new rr,gs=Ci;var He=Ee(Pe());var It=Ee(Pe());function Ie(o){let e=/^([a-g])(bb|##|b|#|n)?\/(-?\d+)$/i.exec(o);if(!e)return;let n={c:0,d:2,e:4,f:5,g:7,a:9,b:11}[e[1].toLowerCase()],t={bb:-2,b:-1,n:0,"":0,"#":1,"##":2}[e[2]??""],s=12*(Number(e[3])+1)+n+t;if(s>=0&&s<=127)return s}function bs(o){return o===1?"\xBD":o===2?"full":o+" st"}function Bt(o,e){return"Pre-bend "+bs(o.semitones)+" on string "+e+(o.release?", release":"")}function mn({semitones:o,release:e}){let n=[{type:It.Bend.PREBEND,text:bs(o)}];return e&&n.push({type:It.Bend.DOWN,text:""}),new It.Bend(n)}function pn(o,e,n){let[t,s]=o.getNoteForFret(e,n).split("/");return t.toLowerCase()+"/"+(Number(s)-1)}function Ft(o,e,n,t,s){let r=It.default.keyProperties(o.getNoteForFret(t,s));e.reset();let a=e.selectNote(r.key),i=n.getNoteParts(r.key).root,c=n.getNoteParts(a.note).root,l=r.octave;return c==="b"&&i==="c"&&l--,c==="c"&&i==="b"&&l++,[a.note,l,a.accidental??"n"]}function hn(o,e){let[n,t]=e.split("/").map(Number);return t>=8&&n>=6&&n%3===0&&(o===2||o===4)?3:Math.max(2,2**Math.floor(Math.log2(o-1)))}var yt=class{constructor(e,n){this.semitones=e;if(e%12===0){this.steps=e/12*7,this.target=n;return}let t=He.default.getKeySignatures(),s=new He.Music,r=n.replace(/m$/,"").toLowerCase(),a=(s.getNoteValue(r)+e%12+12)%12,i=He.default.keySignature(n)[0]?.type,c=i==="b"||!i&&e<0,l=v=>t[v].num*2+ +(He.default.keySignature(v)[0]?.type==="b"!==c),u=Object.keys(t).filter(v=>/^[A-G][#b]?m?$/.test(v)&&v.endsWith("m")===n.endsWith("m")&&s.getNoteValue(v.replace(/m$/,"").toLowerCase())===a);this.target=u.sort((v,x)=>l(v)-l(x))[0];let f=this.target.replace(/m$/,"").toLowerCase(),m=v=>He.Music.rootIndexes[v[0]],h=v=>He.Music.rootValues[m(v)]+(v[1]==="b"?-1:+(v[1]==="#")),w=(h(r)+e-h(f))/12;this.steps=w*7+m(f)-m(r)}pitch(e,n){return He.NotationSpelling.transpose(e+"/"+n,this.semitones,this.steps)}};function ys(o,e,n,t){let s=Number(o)+e.semitones;return(!Number.isSafeInteger(s)||s<0)&&t(n,"Transposition puts fret "+o+" outside the original string"),String(s)}function Ii(o,e,n,t){if(o.fret!==void 0){o.fret=ys(o.fret,e,o,t);let l=Number(o.fret)+n.capo+(o.prebend?.semitones??0),u=n.tuning.getValueForFret(l,o.string);(u<0||u>127)&&t(o,"Transposed fret is outside the playable MIDI range")}let s=o.abc;if(!s||!/^[A-G]$/.test(s.key))return;let r=Number(o.octave??o.string),a=!s.accidental&&!s.accidental_type,[i,c]=e.pitch(s.key+(s.accidental||""),r).split("/");o.fret===void 0&&(Number(c)<-2||Number(c)>9||!a&&Ie(i+"/"+c)===void 0)&&t(o,"Transposed note is outside the playable MIDI range"),s.key=i[0].toUpperCase(),s.transposed=o.range,a||(s.accidental=i.slice(1)||"n"),o.octave!==void 0?o.octave=c:o.string=c}function sr(o,e){let n=/^([A-G][#b]?)([^\s/]*)(?:\/([A-G][#b]?))?$/.exec(o);if(!n||!/^(?:maj|min|dim|aug|sus|add|omit|no|alt|m|M|Δ|ø|°|[0-9#+b(),−-])*$/.test(n[2]))return o;let t=s=>{let r=e.pitch(s,4).split("/")[0];return r[0].toUpperCase()+r.slice(1)};return t(n[1])+n[2]+(n[3]?"/"+t(n[3]):"")}function Bi(o,e,n){let t=/^(\s*chord\s+)("(?:[^"\\]|\\.)*")(.*)$/.exec(o.params);if(t){o.params=t[1]+JSON.stringify(sr(JSON.parse(t[2]),e))+t[3];return}let s=/^(\s*frame\s+)([x\d,]+)(?:\s+barre=(\d+)(:\d+-\d+))?\s*$/.exec(o.params);if(s){let r=i=>i==="x"?i:ys(i,e,o,n),a=s[3]&&r(s[3]);o.params=s[1]+s[2].split(",").map(r).join(",")+(a&&a!=="0"?" barre="+a+s[4]:"")}}function Fi(o,e,n,t){let s=0,r=!1,a=e.get(0);for(let i of o.notes??[])try{let c=i.command==="command"&&/^\s*key\s+(\S+)\s*$/.exec(i.params);if(c)(!He.default.hasKeySignature(c[1])||!/^[A-G][#b]?m?$/.test(c[1]))&&t(i,"Invalid key signature"),a=new yt(a.semitones,c[1]),e.set(s,a),i.params="key "+a.target;else if(i.command==="bar"&&r)s++,a=e.get(s)??a,r=!1;else if(i.command==="command")Bi(i,a,t);else if(i.chord||i.abc||i.fret!==void 0||i.command==="rest"){for(let l of i.chord??[i])Ii(l,a,n,t);r=!0}}catch(c){if(c.code==="syntax")throw c;t(i,c.message)}}function xs(o,e){let n=0,t=!1,s=!1,r,a;for(let i of o){if(i.element==="options"){for(let c of i.params)c.key==="transpose"&&(t&&e(c,"Set transpose before the first stave"),n=Number(c.value),(!/^[+-]?\d+$/.test(c.value)||!Number.isSafeInteger(n)||Math.abs(n)>127)&&e(c,"Transpose needs an integer from -127 to +127 semitones"));continue}if(t=!0,!!n){if(i.element!=="voice"){if(s=i.options?.some(h=>h.key==="clef"&&h.value==="percussion"),s)continue;let c=i.options?.find(h=>h.key==="key"),l=c?.value??"C";(!/^[A-G][#b]?m?$/.test(l)||!He.default.hasKeySignature(l))&&e(c??i,"Transposition requires a major or minor key");let u=new yt(n,l),f=i.options?.find(h=>h.key==="tuning"),m=i.options?.find(h=>h.key==="capo");try{r={tuning:new He.Tuning(f?.value??"standard"),capo:Number(m?.value??0)}}catch{e(f??i,"Invalid tuning")}if(a=new Map([[0,u]]),c)c.value=u.target;else{let h=i.range&&{...i.range,end:i.range.start+i.element.length};(i.options??=[]).unshift({key:"key",value:u.target,range:h,_l:i._l,_c:i._c})}}s||!a||Fi(i,a,r,e)}}}var ne=class extends Error{constructor(n,t,s){super(`${t} at line ${s.line} column ${s.column}.`);this.code=n;this.range=s}};function Ut(o,e=!1){let n;function t(l){if(!n){n=[0];let u=/\r\n|\r|\n/g;for(;u.exec(o);)n.push(u.lastIndex)}return{start:n[l.first_line-1]+l.first_column,end:n[l.last_line-1]+l.last_column,line:l.first_line,column:l.first_column}}if(!o?.trim())throw new ne("syntax","No code",{start:0,end:0,line:1,column:0});function s(l,u){let[f,m,h]=l.split("z").map(Number);if(!Number.isSafeInteger(f)||!Number.isSafeInteger(m)||m<=f)throw new ne("syntax","A pre-bend must start above the fretted pitch",t(u));if(h!==void 0&&h!==f)throw new ne("syntax","Release the pre-bend to its original fret",t(u));return{fret:String(f),prebend:{semitones:m-f,release:h!==void 0}}}let r=Object.create(gs);r.yy={...r.yy,locate:e?t:void 0,markRange:t,prebend:s},r.lexer=Object.create(r.lexer);let a,i=r.lexer.setInput;r.lexer.setInput=function(...l){return a=i.apply(this,l),a},r.parseError=(l,u)=>{throw new ne("syntax",`Unexpected text '${u.text}'`,t(a.yylloc))};let c=r.parse(o.replace(/\r\n?/g,`
|
|
369
|
+
`));if(c?.some(l=>l.element==="options"&&l.params.some(u=>u.key==="transpose"))){if(!e)return Ut(o,!0);xs(c,(l,u)=>{throw new ne("syntax",u,l.range)})}return c&&Lr(c,(l,u)=>t({first_line:l,last_line:l,first_column:u,last_column:u+1}),(l,u)=>{throw new ne("syntax",l,u)}),c}function ir(o,e){let n=o.measures.map(l=>l.number);if(!e)return n;let t=[...o.repeats??[]];for(let l of t){if(l.count!==void 0&&(!Number.isInteger(l.count)||l.count<2||l.count>32||l.endings.length))throw new ne("measure","Invalid counted repeat",o.measures[0].range);let u=l.bodyEnd;if(!Number.isInteger(l.first)||!Number.isInteger(u)||l.first<1||u<l.first||u>n.length)throw new ne("measure","Invalid repeat body",o.measures[0].range);for(let f of l.endings){if(f.first!==u+1||!Number.isInteger(f.last)||f.last<f.first||f.last>n.length)throw new ne("measure","Invalid repeat ending",o.measures[l.first-1].range);u=f.last}}let s=[],r=new Set(t.flatMap(l=>l.count?[l.bodyEnd]:l.endings.slice(0,-1).map(u=>u.last)));for(let l of o.measures){let u=l.voices[0];if(["repeat-begin","repeat-both"].includes(u.opening?.type)&&!t.some(f=>f.first===l.number)&&s.push(l.number),["repeat-end","repeat-both"].includes(u.closing?.type)&&!r.has(l.number)){let f=s.pop()??1;t.push({first:f,bodyEnd:l.number,endings:[],range:[l.range.start,l.range.end]})}}let a=l=>l.endings[l.endings.length-1]?.last??l.bodyEnd;t.sort((l,u)=>l.first-u.first||a(u)-a(l));let i=[];function c(l,u,f){for(let m=l;m<=u;m++){let h=f.find(v=>v.first===m&&a(v)<=u);if(!h){if(i.length>=16384)throw new ne("measure","Performed repeat exceeds 16384 bar visits",o.measures[m-1].range);i.push(m);continue}let w=f.filter(v=>v!==h);for(let v=0;v<(h.count??Math.max(2,h.endings.length));v++){c(m,h.bodyEnd,w);let x=h.endings[v];x&&c(x.first,x.last,w)}m=a(h)}}return c(1,n.length,t),i}function vs(o,e){let n=new Map,t=new Map;for(let s of o){let r=ir(s,e);if(n.set(s,r),r.length===s.measures.length)continue;let a=s.measures.map(c=>c.span).join(","),i=t.get(a);if(i&&(i.length!==r.length||i.some((c,l)=>c!==r[l])))throw new ne("measure","Parts disagree about the performed repeat order",s.measures[0].range);t.set(a,r)}if(t.size)for(let s of o){let r=t.get(s.measures.map(a=>a.span).join(","));r&&n.set(s,r)}return n}function ws(o,e,n,t){let s="cdefgab",[r,a]=o.split("/"),i=s.indexOf(r[0])+n,c=t.getAccidental(s[(i+7)%7]).note,l=Ie(c+"/"+(Number(a)+Math.floor(i/7)));return l===void 0?e:Math.max(0,Math.min(127,l+e-Ie(o)))}function ks(o,e,n,t=.25){if(!o.notes.length)return[o];let s=o.notes[0],r=e.heads.find(u=>u.sounding&&Ie(u.sounding)===s.pitch);if(!r)return[o];let a=[],i=o.time,c=o.duration;function l(u,f,m){let h=m/u.length;u.forEach((w,v)=>a.push({...o,time:f+v*h,duration:h,notes:(Array.isArray(w)?w:[w]).map(x=>({pitch:x,duration:h,velocity:s.velocity,...s.fixedVelocity&&{fixedVelocity:!0},program:s.program}))}))}if(e.grace){let u=s.pitch-Ie(r.written),f=e.grace.pitches.map(m=>(Array.isArray(m)?m:[m]).map(h=>Ie(h)+u).filter(h=>h>=0&&h<=127)).filter(m=>m.length);if(f.length){let m=e.grace.side==="before",w=(m&&!e.grace.steal?Math.min(c,...o.notes.map(x=>x.duration)):c)*t,v=m?i:i+c-w;l(f,v,w),c-=w,m&&(i+=w);for(let x of o.notes)m?x.duration=Math.max(0,x.duration-w):x.duration-=Math.min(w,Math.max(0,x.duration-(v-o.time)))}}if(e.ornament){let u=ws(r.written,s.pitch,1,n),f=ws(r.written,s.pitch,-1,n),m=s.pitch,w={tr:[m,u,m,u],mordent:[m,u],mordent_inverted:[m,f],turn:[u,m,f],turn_inverted:[f,m,u]}[e.ornament],v=Math.min(c,s.duration)/2;l(w,i,v),o.notes.length>1&&a.push({...o,time:i,duration:c,notes:o.notes.slice(1)}),s.duration=Math.max(0,s.duration-v),a.push({...o,time:i+v,duration:c-v,notes:[s]})}else a.push({...o,time:i,duration:c});return a}var bn=Ee(Pe());function Ss(o,e,n){let t=Ie(o);if(t===void 0)return;let s={pitch:t,duration:e,velocity:100};return n&&(s.bend=[{time:e,semitones:-n}]),s}function Me(o,e){let[n,t]=o.split("/").map(Number);return n/t*e}function Vi(o,e,n){if(e.midi!==void 0&&!o.silent)return{pitch:e.midi,duration:n,velocity:100};if(!e.sounding||o.silent)return;let t=Ss(e.sounding,n,e.prebend?.release&&e.prebend.semitones),s=e.bend??o.bend?.spec;if(!t||!s||s.string!==e.position?.str)return t;let r=i=>n*i[0]/i[1],a=[{time:r(s.rise),semitones:s.semitones}];return s.hold&&a.push({time:r(s.hold),semitones:s.semitones}),s.release&&a.push({time:r(s.release),semitones:0}),t.bend=a,t}var or=class{constructor(){this.from=100;this.target=100;this.start=0;this.hasSounded=!1}at(e){let n=(e-this.start)*4,t=Math.max(0,1-n);return this.target+(this.from-this.target)*t*t}attack(e,n,t,s){if(n!==void 0&&(n!==this.target||!s)){let r=this.at(e);this.from=this.hasSounded&&s?(r+n)/2:n,this.target=n,this.start=e}return t&&(this.hasSounded=!0),Math.round(this.at(e))}};function Oi(o,e,n){let t=[],s=new Map;for(let w of o.playback?.tempoChanges??[]){let v=s.get(w.bar)??[];v.push({at:Me(w.at,1),bpm:w.bpm*e/(o.playback.tempo??120)}),s.set(w.bar,v)}let r=new Map,a=new Map,i=[],c={ppp:28,pp:40,p:52,mp:66,mf:82,f:98,ff:112,fff:124},l=new Set(n&&o.measures[0]?.state.piano?o.measures.flatMap(w=>w.voices.filter(v=>v.hand&&v.events.some(x=>x.dynamic)).map(v=>v.hand)):[]),u=new Map,f=new Set((o.spans??[]).flatMap(w=>w.kind==="crescendo"||w.kind==="diminuendo"?[w.from,w.to]:[])),m=e,h=0;for(let w of o.measures){let v=o.playback?.tempos?.[w.number];v&&(m=v*e/(o.playback.tempo??120)),t.push(m);let x=s.get(w.number);x&&(m=x[x.length-1].bpm);let P=w.voices.flatMap((B,D)=>B.events.map(_=>({attack:_,voice:D,onset:Me(_.onset,1)}))).sort((B,D)=>B.onset-D.onset||+!!D.attack.dynamic-+!!B.attack.dynamic);for(let{attack:B,voice:D,onset:_}of P){let M=l.size===2?w.voices[D].hand??"":"";u.has(M)||u.set(M,new or);let V=u.get(M);r.set(B.id,V.attack(h+_,c[B.dynamic],!B.silent&&B.heads.length>0,n&&!f.has(B.id)));let K=i[D]??=[],Y={id:B.id,time:h+_,voice:D,explicit:!!B.dynamic,index:K.length};a.set(B.id,Y),K.push(Y)}h+=Me(w.span,1)}for(let w of o.spans??[]){if(w.kind!=="crescendo"&&w.kind!=="diminuendo")continue;let v=a.get(w.from),x=a.get(w.to);if(!v||!x||x.time<=v.time)continue;let P=w.kind==="crescendo",B=P&&w.niente?1:r.get(w.from),D=!P&&w.niente?1:x.explicit?r.get(w.to):Math.min(127,Math.max(1,B+(P?24:-24)));for(let _=v.index;_<=x.index;_++){let M=i[v.voice][_];r.set(M.id,Math.round(B+(D-B)*(M.time-v.time)/(x.time-v.time)))}}return{tempi:t,tempoChanges:s,velocities:r}}function Li(o,e,n){if(!e.length)return;e.sort((r,a)=>r.start-a.start);let t=[];for(let r of e){let a=t[t.length-1];a&&r.start<a.end?a.end=Math.max(a.end,r.end):t.push(r)}let s=new Map;for(let r=o.length-1;r>=0;r--){let a=o[r];for(let i of a.notes){let c=a.time+i.duration,l=0,u=t.length;for(;l<u;){let m=l+u>>>1;t[m].end<=c?l=m+1:u=m}let f=t[l];if(n&&(f?.start<c||t[l-1]?.end===c)&&(i.holdRelease=!0),f&&f.start<c){let m=Math.min(f.end,s.get(i.pitch)??1/0);i.duration=Math.max(i.duration,m-a.time)}s.set(i.pitch,a.time)}}}function Hi(o,e,n,t,s){let r=t(Me(o.span,1)),a=e/4,[i,c]=o.state.meter.split("/").map(Number),l=Math.max(0,i/c-Me(o.span,1))*4,u=Math.abs(l-Math.round(l))>1e-8?l%1*a:0,f=[];if(s!==void 0){let w=Me(o.span,1),v=0,x=(1-u/a)/4;for(;v<w-1e-12;){let P=Math.min(v+x,w);f.push({end:t(P),...P-v>=.25-1e-12&&{eighth:t(v+.125)}}),v=P,x=.25}}let m=[],h=!1;for(let w of o.voices)for(let v of w.events){let x=t(Me(v.onset,1)+Me(v.duration,1));v.heads.some(P=>P.marks?.some(B=>B.articulation?.startsWith("a@")))&&m.push(x),x>=r-1e-8&&n.has(v.id)&&(h=!0)}return{duration:r,quarter:a,beatOffset:u,...s!==void 0&&{beats:f,endingQuarter:s},swingable:c===2||c===4,fermatas:m,phraseEnd:h||!!m.length}}function Es(o){let e=o[0]??[];for(let n of o.slice(1)){let t=0,s=0,r=0;for(let a of n){let i=t,c=s,l=r+a.duration;for(;i<e.length&&c<l-1e-9;){let u=e[i],f=c+u.duration;a.swingable===!1&&(u.swingable=!1),a.phraseEnd&&Math.abs(l-f)<1e-8&&(u.phraseEnd=!0);for(let m of a.fermatas??[]){let h=r+m;h>c+1e-9&&h<=f+1e-9&&(u.fermatas=[...u.fermatas??[],h-c])}if(f>l+1e-9)break;c=f,i++}t=i,s=c,r=l}}return e}function Ms(o,e,n,t=ir(o,!1),s,r){let a=[],i=new Map(o.ties.map(S=>[S.to+":"+S.toHead,S])),c=new Map,l=!!s&&!s.literal,u=!1,{tempi:f,tempoChanges:m,velocities:h}=Oi(o,e,l),w=new Set((o.spans??[]).filter(S=>S.kind==="slur").map(S=>S.to)),v=new Map((o.spans??[]).filter(S=>S.kind==="tremolo").map(S=>[S.from,S])),x=new Map((o.spans??[]).flatMap(S=>S.kind==="glissando"?[[S.to+":"+S.toHead,S]]:[])),P=new Map,B=new Map,D=(o.spans??[]).filter(S=>S.kind==="pedal"),_=new Map(D.map(S=>[S.from,S.to])),M=new Set(D.filter(S=>S.onset).map(S=>S.to)),V=new Map,K=[];function Y(S){for(let N of V.values())K.push({start:N,end:S});V.clear()}let W=new Map((o.repeats??[]).flatMap(S=>S.endings.slice(1).map(N=>[N.first,S.bodyEnd]))),C=0,T=0;for(let S of t){let N=o.measures[S-1];if(S!==C+1){if(W.get(S)===C)for(let[O,G]of c)(G.barNumber!==C||Math.abs(G.writtenEnd-T)>1e-8)&&c.delete(O);else c.clear();Y(T)}else if(W.has(S)){let O=W.get(S);for(let[G,ue]of c)ue.barNumber===O&&c.delete(G)}C=S;let L=240/f[S-1],q=0,Q=0,re=L,se=[{start:q,timeAtStart:Q,rate:re}];for(let O of m.get(S)??[])Q+=(O.at-q)*re,q=O.at,re=240/O.bpm,se.push({start:q,timeAtStart:Q,rate:re});let ie=O=>{let G=0,ue=se.length;for(;G+1<ue;){let A=G+ue>>>1;se[A].start<=O?G=A:ue=A}let le=se[G];return le.timeAtStart+(O-le.start)*le.rate},ce=N.voices.flatMap(O=>O.events).map(O=>({attack:O,time:T+ie(Me(O.onset,1))}));ce.sort((O,G)=>O.time-G.time),r&&Me(N.span,L)>0&&r.push(Hi(N,L,w,ie,se.length>1?re/4:void 0));let ae=new Map;for(let{attack:O,time:G}of ce){let ue=ie(Me(O.onset,1)+Me(O.duration,1))-ie(Me(O.onset,1));_.has(O.id)&&V.set(_.get(O.id),G),V.has(O.id)&&(K.push({start:V.get(O.id),end:M.has(O.id)?G:G+ue}),V.delete(O.id));let le=[];if(O.grace||O.ornament){let A=O.activeKey??N.state.key??"C";B.has(A)||B.set(A,new bn.KeyManager(A));let U;if(O.grace?.steal){let $=Me(O.onset,1),H=Me(O.duration,1),ee=H*Me(O.grace.steal,1),F=O.grace.side==="before"?$:$+H-ee;U=(ie(F+ee)-ie(F))/ue}P.set(O.id,{attack:O,key:B.get(A),graceShare:U})}O.heads.forEach((A,U)=>{let $=A.sustain?ie(Me(O.onset,1)+Me(A.sustain,1))-ie(Me(O.onset,1)):ue,H=O.id+":"+U,ee=i.get(H),F=ee&&c.get(ee.from+":"+ee.fromHead);if(F){if(l&&(F.note.holdRelease=!0),F.note.duration=Math.max(F.note.duration,G+$-F.start),ee.bend){let{semitones:b,hold:g,release:y}=ee.bend;F.note.bend=[...F.note.bend??[],{time:G-F.start+$*g[0]/g[1],semitones:b},{time:G-F.start+$*y[0]/y[1],semitones:0}]}c.set(H,{...F,barNumber:S,writtenEnd:G+$})}else{let b=Vi(O,A,$);if(b){let g=x.get(H),y=g&&c.get(g.from+":"+g.fromHead);y&&(y.note.bend=[...y.note.bend??[],{time:G-y.start,semitones:b.pitch-y.note.pitch}]),b.velocity=h.get(O.id),l&&A.marks&&(A.marks.some(I=>I.articulation==="a>"||!I.articulation&&!I.finger&&!I.stringNumber)&&(b.velocity=Math.min(127,b.velocity+10)),!b.bend&&!O.grace&&!O.ornament&&A.marks.some(I=>I.articulation==="a.")&&(b.duration*=.58)),A.velocity!==void 0&&(b.velocity=A.velocity,b.fixedVelocity=!0,A.velocity===0&&(u=!0)),o.program!==void 0&&(b.program=o.program),le.push(b),c.set(H,{note:b,start:G,barNumber:S,writtenEnd:G+$})}}}),ae.set(O.id,{time:G,duration:ue,source:O.id,notes:le,mark:n&&(()=>n(O.id))})}for(let[O,G]of ae){let ue=v.get(O);if(ue?.kind!=="tremolo"){a.push(G);continue}let le=ae.get(ue.to),A=G.duration+le.duration,U=L/2**(2+ue.strokes);for(let $=0;$*U<A-1e-9;$++){let H=$%2?le:G,ee=Math.min(U,A-$*U);a.push({...H,time:G.time+$*U,duration:ee,notes:H.notes.map(F=>({...F,duration:ee}))})}ae.delete(ue.to)}T+=ie(Me(N.span,1))}let X=P.size?a.flatMap(S=>{let N=P.get(String(S.source));if(!N)return[S];let L=N.attack.grace,q=N.graceShare??(L&&s?.graceFraction(S.time,S.duration,L.pitches.length,L.slash));return ks(S,N.attack,N.key,q)}):a;if(u)for(let S of X)S.notes=S.notes.filter(N=>N.velocity!==0);return X.sort((S,N)=>S.time-N.time),Y(T),Li(X,K,l),{events:X,duration:T}}function Ts(o,e){let n=[],t=240/(e*bn.default.RESOLUTION),s=new Map,r=0;for(let a of o.getPlayerData().voices){let i=0;for(let c of a){let l=0;for(let u of c.getTickables()){if(u.shouldIgnoreTicks())continue;let f=u.getTicks().value(),m=f*t,h=[];if(!u.isRest()){let w=rt.get(u)??(u.getPlayNote?.()??[]).map(x=>({key:x})),v=new Map;w.forEach((x,P)=>{let B=Ss(x.key,m,x.release);if(!B)return;let D=gn.get(u)?.get(P),_=D&&s.get(D.glyph)?.get(D.index);_&&_.pitch===B.pitch?(_.duration+=m,v.set(P,_)):(h.push(B),v.set(P,B))}),s.set(u,v)}n.push({time:(r+l)*t,duration:m,source:u,notes:h}),l+=f}i=Math.max(i,l)}r+=i}return{events:n.sort((a,i)=>a.time-i.time),duration:r*t}}var rt=new WeakMap,gn=new WeakMap;function Ps(o,e){let n=gn.get(o)?.get(e);return n&&rt.get(n.glyph)?.[n.index]}function ar(o,e,n,t){if(!o||!e)return;let s=gn.get(e)??new Map;t.forEach((r,a)=>s.set(r,{glyph:o,index:n[a]})),gn.set(e,s)}var yn=class{constructor(e){this.artist=e}makeBend(e,n){let t=Z.Flow.Bend.UP,s="";if(parseInt(e,10)>parseInt(n,10))t=Z.Flow.Bend.DOWN;else switch(Math.abs(parseInt(n,10)-parseInt(e,10))){case 1:s="1/2";break;case 2:s="Full";break;case 3:s="1 1/2";break;default:s=`Bend to ${n}`;break}return{type:t,text:s}}openBends(e,n,t,s){this.artist.log("openBends",e,n,t,s);let r=me(this.artist.staves).tab_notes,a=e,i=t;De(this.artist.current_bends)?(this.artist.bend_start_index=r.indexOf(e),this.artist.bend_start_strings=t):(a=r[this.artist.bend_start_index],i=this.artist.bend_start_strings);let c=a.getPositions(),l=n.getPositions();i.forEach((u,f)=>{let m=s[f],h=c[u],w=l[m];this.artist.current_bends[u]||(this.artist.current_bends[u]=[]),this.artist.current_bends[u].push(this.makeBend(h.fret,w.fret))})}closeBends(e=1){if(this.artist.bend_start_index==null)return;this.artist.log(`closeBends(${e})`);let n=me(this.artist.staves).tab_notes;Fr(this.artist.current_bends,(t,s)=>{let r=[];t.forEach(c=>r.push(c));let a=Z.Flow.Bend.length<=1?new Z.Flow.Bend(r):new Z.Flow.Bend(null,null,r),i=parseInt(String(s),10);n[this.artist.bend_start_index].addModifier(a,i)}),n.slice(this.artist.bend_start_index+1,n.length-2+e+1).forEach(t=>t.setGhost(!0)),this.artist.current_bends={},this.artist.bend_start_index=null}makeTuplets(e,n){this.artist.log("makeTuplets",e,n);let t=Number(n??e),s=Number(e),r=me(this.artist.staves);if(!Number.isSafeInteger(t)||t<1||!Number.isSafeInteger(s)||s<1)throw new Z.RERR("ArtistError","Tuplet counts must be positive integers");let a=hn(s,r.meter),i=(c,l,u)=>{let f=c.slice(-t);if(f.length!==t||f.some(h=>h instanceof Z.Flow.BarNote))throw new Z.RERR("ArtistError","Not enough notes for tuplet in this bar and voice");let m=new Z.Flow.Tuplet(f,{numNotes:s,notesOccupied:a});l&&u.push(m)};r.note&&i(r.note_notes,!0,this.artist.stave_articulations),i(r.tab_notes,!!r.tab&&this.artist.customizations["tab-stems"]==="true",this.artist.tab_articulations)}getFingering(e){return e.match(/^\.fingering\/([^.]+)\./)}makeFingering(e){let n=this.getFingering(e),t=Z.Flow.Modifier.Position,s=[],r=[];if(n)n[1].split(/-/).forEach(i=>s.push(i.trim()));else return null;let a=()=>new Z.RERR("ArtistError",`Bad fingering: ${n[1]}`);return s.forEach(i=>{let c=i.match(/(\d+):([ablr]):([fs]):([^-.]+)/);if(!c)throw a();let l=parseInt(c[1],10)-1,u=t.RIGHT;switch(c[2]){case"l":u=t.LEFT;break;case"r":u=t.RIGHT;break;case"a":u=t.ABOVE;break;case"b":u=t.BELOW;break;default:break}let f=qn(c[4],u,c[3]==="s");r.push({num:l,modifier:f})}),r}getStrokeParts(e){return e.match(/^\.stroke\/([^.]+)\./)}makeStroke(e){let n=this.getStrokeParts(e),t=Z.Flow.Stroke.Type;if(!n)return null;switch(n[1]){case"bu":return new Z.Flow.Stroke(t.BRUSH_UP);case"bd":return new Z.Flow.Stroke(t.BRUSH_DOWN);case"ru":return new Z.Flow.Stroke(t.ROLL_UP);case"rd":return new Z.Flow.Stroke(t.ROLL_DOWN);case"qu":return new Z.Flow.Stroke(t.RASQUEDO_UP);case"qd":return new Z.Flow.Stroke(t.RASQUEDO_DOWN);default:throw new Z.RERR("ArtistError",`Invalid stroke type: ${n[1]}`)}}getScoreArticulationParts(e){return e.match(/^\.(a[^/]*)\/(t|b)[^.]*\./)}makeScoreArticulation(e){let n=this.getScoreArticulationParts(e);if(!n)return null;let t=n[1],s=n[2],r=Z.Flow.Modifier.Position,a=s==="t"?r.ABOVE:r.BELOW;return new Z.Flow.Articulation(t).setPosition(a)}makeAnnotation(e){let n=this.artist.customizations["font-face"],t=this.artist.customizations["font-size"],s=this.artist.customizations["font-style"],r=this.artist.customizations["annotation-position"],a=Z.Flow.Annotation.VerticalJustify,i=r==="top"?a.TOP:a.BOTTOM,c=(u,f=i)=>new Z.Flow.Annotation(u).setFont(n,t,s).setVerticalJustification(f),l=e.match(/^\.([^-]*)-([^-]*)-([^.-]*)(?:-([^.]*))?\.(.*)/);if(l){n=l[1],t=l[2],s=l[3];let[,,,,u,f]=l;if(u!==void 0&&!Fe(u))throw new Z.RERR("ArtistError",`Invalid annotation color '${u}'`);if(!f)return null;let m=c(f);return u?m.setStyle(ke(u)):m}if(l=e.match(/^\.([^.]*)\.(.*)/),l){let u=i,f=l[1],m=l[2];switch(f){case"big":s="bold",t="14";break;case"italic":case"italics":s="italic";break;case"medium":t="12";break;case"top":u=a.TOP,this.artist.customizations["annotation-position"]="top";break;case"bottom":u=a.BOTTOM,this.artist.customizations["annotation-position"]="bottom";break;default:break}return m?c(m,u):null}return c(e)}formatOverrideFretText(e){if(!e)return null;let n=Z.Flow?.unicode??{},t=n.sharp??"#",s=n.flat??"b",r=n.natural??"n",a=e.match(/^([A-G])([#@n]{1,2})?(~?)(\d+)?(?:_(\d+)\/(\d+))?$/);if(a&&(a[4]||a[6])){let c=a[1],l=a[2]??"",u=a[4]??"",f=a[6],m=(()=>{switch(l){case"##":return`${t}${t}`;case"#":return t;case"@@":return`${s}${s}`;case"@":return s;case"n":return r;default:return""}})();return{text:`${c}${m}${u}`,string:f}}let i=e.match(/^(\d+)\/(\d+)$/);return i?{text:i[1],string:i[2]}:null}applyFretOverride(e,n){if(!e||!n||!e.fretElement||!e.positions)return;let t=0;if(n.string){let l=parseInt(n.string,10);if(!Number.isNaN(l)){let u=-1;e.positions.forEach((f,m)=>{parseInt(f.str,10)===l&&u<0&&(u=m)}),t=u>=0?u:0}}let s=e.fretElement[t];if(!s)return;s.setText(n.text);let r=this.artist.customizations["font-face"],a=this.artist.customizations["font-size"],i=this.artist.customizations["font-style"];r&&s.setFont(r,a,i);let c=0;e.fretElement.forEach(l=>{c=Math.max(c,l.getWidth())}),e.setWidth(c)}addAnnotations(e){let n=me(this.artist.staves),t=n.note_notes,s=n.tab_notes;if(e.length>s.length)throw new Z.RERR("ArtistError","More annotations than note elements");n.tab?s.slice(s.length-e.length).forEach((r,a)=>{if(this.getScoreArticulationParts(e[a])){let i=this.makeScoreArticulation(e[a]);r.addModifier(i,0)}else if(this.getStrokeParts(e[a])){let i=this.makeStroke(e[a]);r.addModifier(i,0)}else{let i=e[a],c=this.formatOverrideFretText(i);if(c)this.applyFretOverride(r,c);else{let l=this.makeAnnotation(i);l&&r.addModifier(l,0)}}}):t.slice(t.length-e.length).forEach((r,a)=>{if(!this.getScoreArticulationParts(e[a])){let i=this.makeAnnotation(e[a]);i&&(typeof r.addAnnotation=="function"?r.addAnnotation(0,i):typeof r.addModifier=="function"&&r.addModifier(i,0))}}),n.note&&t.slice(t.length-e.length).forEach((r,a)=>{let i=this.makeScoreArticulation(e[a]);i&&(typeof r.addArticulation=="function"?r.addArticulation(0,i):typeof r.addModifier=="function"&&r.addModifier(i,0));let c=this.makeStroke(e[a]);c&&r.addStroke(0,c);let l=this.makeFingering(e[a]);if(l)try{l.forEach(u=>r.addModifier(u.modifier,u.num))}catch{throw new Z.RERR("ArtistError",`Bad note number in fingering: ${e[a]}`)}})}addTabArticulation(e,n,t,s,r){if(this.artist.log("addTabArticulations: ",e,n,t,s,r),e==="T"&&ar(n,t,s,r),e==="t"&&t.addModifier(new Z.Flow.Annotation("T").setVerticalJustification(Z.Flow.Annotation.VerticalJustify.BOTTOM)),De(s)&&De(r))return;let a=null,i={first_note:n,last_note:t,first_indices:s,last_indices:r,firstNote:n,lastNote:t,firstIndexes:s,lastIndexes:r};if(e==="s"&&(a=new Z.Flow.TabSlide(i)),(e==="h"||e==="p")&&(a=new Z.Flow.TabTie(i,e.toUpperCase())),(e==="T"||e==="t")&&(a=new Z.Flow.TabTie(i," ")),e==="b"&&this.openBends(n,t,s,r),a){let c=me(this.artist.staves)?.color;c&&a.setStyle(ke(c)),this.artist.tab_articulations.push(a)}}addStaveArticulation(e,n,t,s,r){this.artist.log("addStaveArticulations: ",e,n,t,s,r);let a=null;if(e==="T"&&ar(n,t,s,r),["b","s","h","p","t","T"].includes(e)&&(a=new Z.Flow.StaveTie({first_note:n,last_note:t,first_indices:s,last_indices:r,firstNote:n,lastNote:t,firstIndexes:s,lastIndexes:r})),a){let i=me(this.artist.staves)?.color;i&&a.setStyle(ke(i)),this.artist.stave_articulations.push(a)}}getPreviousNoteIndex(){let e=me(this.artist.staves).tab_notes,n=2;for(;n<=e.length;){let t=e[e.length-n];if(t instanceof Z.Flow.TabNote)return e.length-n;if(!(t instanceof Z.Flow.BarNote))break;n+=1}return-1}addDecorator(e){if(this.artist.log("addDecorator: ",e),!e)return;let n=me(this.artist.staves),t=n.tab_notes,s=n.note_notes,r=null,a=null;e==="v"&&(r=new Z.Flow.Vibrato),e==="V"&&(r=new Z.Flow.Vibrato,typeof r.setHarsh=="function"&&r.setHarsh(!0)),e==="u"&&(r=new Z.Flow.Articulation("a|").setPosition(Z.Flow.Modifier.Position.BELOW),a=new Z.Flow.Articulation("a|").setPosition(Z.Flow.Modifier.Position.BELOW)),e==="d"&&(r=new Z.Flow.Articulation("am").setPosition(Z.Flow.Modifier.Position.BELOW),a=new Z.Flow.Articulation("am").setPosition(Z.Flow.Modifier.Position.BELOW));let i=me(t);if(i&&r&&i.addModifier(r,0),a){let c=me(s);c&&(typeof c.addArticulation=="function"?c.addArticulation(0,a):typeof c.addModifier=="function"&&c.addModifier(a,0))}}addArticulations(e){this.artist.log("addArticulations: ",e);let n=me(this.artist.staves),t=n.tab_notes,s=n.note_notes;if(De(t)||De(e)){this.closeBends(0);return}let r=me(t),a=!1;["b","s","h","p","t","T","v","V"].forEach(i=>{let c=e.map((h,w)=>h&&h===i?w:-1).filter(h=>h>=0);if(De(c))return;i==="b"&&(a=!0);let l=this.getPreviousNoteIndex(),u=null,f=null,m=[];if(l===-1)u=null,f=null;else{u=t[l];let h=u.getPositions();f=[];for(let w of c){let v=r.getPositions()[w];if(!v)continue;let x=v.fret==="X"&&i==="T",P=h.findIndex((B,D)=>{if(f.includes(D))return!1;if(x){let _=n.note?s[l].getKeys():u.getPlayNote(),M=n.note?me(s).getKeys():r.getPlayNote();return B.fret==="X"&&_[D]===M[w]}return B.str===v.str});P>=0&&(f.push(P),m.push(w))}}n.tab&&this.addTabArticulation(i,u,r,f||[],m),n.note&&m.length&&this.addStaveArticulation(i,s[l],me(s),f||[],m)}),a||this.closeBends(0)}};var We=Ee(Pe());var Ns=Ee(Pe()),lt=new Ns.PercussionMap;function xn(o,e,n,t){if(o!=="percussion"||e)return"Use stave clef=percussion for drum hits";if(new Set(n).size!==n.length)return"A drum hit can contain each instrument only once";if(t)return"Use an ordinary duration for drum hits"}var vn=Ee(Pe()),wn=10,_s=5;function Vt(o,e){let n=o.side==="above"?"higher":"lower";return"Slide "+(o.edge==="in"?"in from "+o.side:"out toward a "+n+" fret")+" on string "+e}function Di(o,e,n){return{x:o+(n.edge==="in"?-wn:wn),y:e+(n.side==="above"?-_s:_s)}}var kn=class extends vn.Modifier{constructor(n){super();this.slide=n;this.setPosition(n.edge==="in"?vn.Modifier.Position.LEFT:vn.Modifier.Position.RIGHT)}static get CATEGORY(){return"OpenSlide"}draw(){let n=this.checkContext(),t=this.checkAttachedNote().getModifierStartXY(this.getPosition(),this.checkIndex()),s=Di(t.x,t.y,this.slide);n.openGroup("open-slide",this.getAttribute("id")),n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(s.x,s.y),n.stroke(),n.closeGroup(),this.setRendered()}};function Sn(o,e,n){let t=new kn(n);o.getModifiers().some(r=>r instanceof kn&&r.getPosition()===t.getPosition())||(n.edge==="in"?o.setLeftDisplacedHeadPx(o.getLeftDisplacedHeadPx()+wn+2):o.setRightDisplacedHeadPx(o.getRightDisplacedHeadPx()+wn+2)),o.addModifier(t,e)}var En=class{constructor(e){this.signs=new WeakMap;this.artist=e}getNoteForFret(e,n){return Ft(this.artist.tuning,this.artist.key_manager,this.artist.music_api,e,n)}getNoteForABC(e,n){let t=e.key,s=n,r=e.accidental;return e.accidental_type&&(r=`${r||"n"}_${e.accidental_type}`),[t,s,r]}addStaveNote(e){let n={is_rest:!1,play_note:null,...e},t=me(this.artist.staves).note_notes,s=new Z.Flow.StaveNote({keys:n.spec,duration:this.artist.current_duration,type:this.artist.current_head,clef:this.artist.current_clef,autoStem:!0});this.signs.set(s,n.signs),this.attachDots(s),n.play_note&&s.setPlayNote(n.play_note),t.push(s)}applyAccidentals(e){let n={};for(let[a,i]of Object.entries(new We.Music().createScaleMap(e.key)))n[a]=i.slice(1)||"n";let t=new We.WrittenAccidentalState(n),s=new Map;for(let a of e.note_voices){let i=new We.Fraction(0,1);for(let c of a){let l=i.clone().simplify().toString(),u=s.get(l);u||(u={at:i.clone(),bar:!1,notes:[]},s.set(l,u)),c instanceof Z.Flow.BarNote?u.bar=!0:(this.signs.has(c)&&u.notes.push(c),i.add(c.getTicks()))}}let r=new Map;for(let a of[...s.values()].sort((i,c)=>i.at.value()-c.at.value())){a.bar&&(t.reset(),r.clear());let i=new Map;for(let c of a.notes)rt.get(c)?.forEach((l,u)=>{if(!l.inherit)return;let f=l.inherit.written[0],m=r.get(l.inherit.written)??n[f],h=Ps(c,u);if(l.key=h?.key??f+(m==="n"?"":m)+l.key.slice(l.key.indexOf("/")),Ie(l.key)===void 0)throw new ne("syntax","Transposed note is outside the playable MIDI range",l.inherit.range)}),this.signs.get(c).forEach((l,u)=>{if(!l)return;let f=i.get(l.key)??[];f.push({head:l,note:c,index:u}),i.set(l.key,f)});for(let[c,l]of i){let u=l[0].head.sign,f=l.some(h=>h.head.sign!==u);r.set(c,u);let m=t.sign(c,f?"ambiguous":u)!==void 0;for(let{head:h,note:w,index:v}of l)this.updateSign(w,v,h,m||f)}}}updateSign(e,n,t,s){let r=t.cautionary&&(t.literal||!s),a=t.literal||s||r;if(t.mark&&(!a||t.mark.isCautionary()!==r)){let i=e.getModifiers(),c=i.indexOf(t.mark);c>=0&&i.splice(c,1),delete t.mark}a&&!t.mark&&(t.mark=new We.Accidental(t.sign),r&&t.mark.setAsCautionary(),e.addModifier(t.mark,n))}addTabNote(e,n=null){let t=me(this.artist.staves).tab_notes;this.artist.stavesBuilder.reserveTabRhythmSpace();let s=new Z.Flow.TabNote({positions:e.map(({str:r,fret:a})=>({str:r,fret:a})),duration:this.artist.current_duration},this.artist.customizations["tab-stems"]==="true");n&&s.setPlayNote(n),e.forEach(({prebend:r,openSlide:a},i)=>{a&&Sn(s,i,a),r&&s.addModifier(mn(r),i)}),t.push(s),this.attachDots(s)}attachDots(e){for(let n=0;n<this.artist.current_dots;n++)Z.Flow.Dot.buildAndAttach([e],e instanceof Z.Flow.TabNote?{index:0}:{all:!0})}setDuration(e,n=!1){let t=/^(\d+|[whq])(s?)(d*)$/i.exec(e.trim());if(!t)throw new Z.RERR("ArtistError",`Invalid duration '${e}'`);let s=Number(n)||t[3].length;this.artist.current_dots=s,this.artist.current_head=t[2]?"s":"n",this.artist.current_duration=t[1]+"d".repeat(s)}addDrums(e){let n=me(this.artist.staves),t=this.artist.current_duration,s=new We.StaveNote(lt.note(e,t));this.attachDots(s),n.note_notes.push(s),n.tab_notes.push(new Z.Flow.GhostNote(t)),rt.set(s,[])}addRest(e){this.artist.closeBends();let n=me(this.artist.staves);this.artist.stavesBuilder.reserveTabRhythmSpace();let t=e.explicit||Number(e.position)!==0,s=r=>{let a=new We.StaveNote({keys:["r/4"],duration:this.artist.current_duration,type:"r"});if(a.setStave(r),t){let i=Number(e.position),c=r.getNumLines(),l=6-c,u=2*c-1,f=l+(i-1)/2;i<=0&&(f=l-1+i/2),i>=u&&(f=6+(i-u)/2),a.setRestLine(f)}return this.attachDots(a),a};n.note&&n.note_notes.push(s(n.note)),n.tab_notes.push(n.tab&&this.artist.customizations["tab-stems"]==="true"?s(n.tab):new Z.Flow.GhostNote(this.artist.current_duration))}addChord(e,n,t){if(De(e))return;this.artist.log("addChord: ",e);let s=me(this.artist.staves),r=[],a=[],i=[],c=[],l=[],u=[],f=[],m=[],h=0,w=e[0].string,v=0;if(e.forEach(x=>{h+=1,(x.abc||x.string!==w)&&(v=0,w=x.string),r[v]||(r[v]=[],a[v]=[],i[v]=[],c[v]=[],f[v]=[],l[v]=[],u[v]=null);let P=null,B=null,D=null,_=null,M,V,K;if(x.abc){let S=x.octave?x.octave:x.string;[P,B,D]=this.getNoteForABC(x.abc,S);let N=D?D.split("_")[0]:"";if(_=`${P}${N}`,x.abc.transposed&&!D&&!x.fret&&(K={written:P.toLowerCase()+"/"+B,range:x.abc.transposed},_=this.artist.music_api.createScaleMap(s.key)[P.toLowerCase()].replace(/n$/,"")),x.fret&&x.abc.transposed){let[L,q]=this.artist.tuning.getNoteForFret(Number(x.fret)+s.capo,x.string).split("/");V=L+"/"+(Number(q)-1+this.artist.current_octave_shift)}x.fret||(x.fret="X")}else if(x.fret){let S=String(Number(x.fret)+s.capo+(x.prebend?.semitones??0));[P,B,D]=this.getNoteForFret(S,x.string);let[N,L]=this.artist.tuning.getNoteForFret(S,x.string).split("/");_=N,M=Number(L)-1}else throw new Z.RERR("ArtistError","No note specified");let Y=parseInt(String(B),10)+this.artist.current_octave_shift,W=x.time?{time:x.time,dot:x.dot}:null,C=D?.split("_")[0],T=x.abc&&C&&C!=="n"?P+C:P;r[v].push(`${T}/${B}`);let X=(M??Number(B))+this.artist.current_octave_shift;a[v].push(`${_}/${Y}`),i[v].push(V??`${_}/${X}`),c[v].push(C&&/^[a-g]/i.test(P)?{key:`${P[0].toLowerCase()}/${B}`,sign:C,literal:!!x.abc,cautionary:x.abc?x.abc.accidental_type==="c":this.artist.customizations.accidentals==="cautionary"&&C!=="n"}:null),f[v].push({fret:x.fret,str:x.string,prebend:x.prebend,openSlide:x.openSlide,marks:x.marks,inherit:K}),x.articulation?l[v].push(x.articulation):l[v].push(null),m[v]=W,x.decorator&&(u[v]=x.decorator),v+=1}),r.forEach((x,P)=>{if(m[P]&&this.setDuration(m[P].time,m[P].dot),this.addTabNote(f[P],a[P]),s.note&&(this.addStaveNote({spec:x,signs:c[P],play_note:a[P]}),!s.tab)){let D=f[P].filter(_=>_.prebend).map(_=>Bt(_.prebend,_.str));for(let _ of f[P])_.openSlide&&D.push(Vt(_.openSlide,_.str));if(D.length){let _=new Z.Flow.Annotation(D.join(" \xB7 "));_.setVerticalJustification(Z.Flow.Annotation.VerticalJustify.TOP),me(s.note_notes).addModifier(_,0)}}f[P].forEach((D,_)=>{D.marks&&(s.tab&&Et(me(s.tab_notes),_,D.marks,!0),s.note&&Et(me(s.note_notes),_,D.marks,!1))});let B=i[P].map((D,_)=>{let M=f[P][_].prebend;return{key:D,release:M?.release?M.semitones:0,inherit:f[P][_].inherit}});rt.set(me(s.tab_notes),B),s.note&&rt.set(me(s.note_notes),B),this.artist.addArticulations(l[P]),u[P]&&this.artist.addDecorator(u[P])}),n){let x=[];for(let P=0;P<h;P+=1)x.push(n);this.artist.addArticulations(x)}t&&this.artist.addDecorator(t)}addNote(e){this.addChord([e],null,null)}};var Ot=Ee(Pe());function cr(o){let e=o;e==="C"&&(e="4/4"),e==="C|"&&(e="2/2");let n=/^(?:\((\d+(?:\+\d+)+)\)|(\d+(?:\+\d+)+))\/(\d+)$/.exec(e),t;if(n){let s=(n[1]||n[2]).split("+").map(Number),r=Number(n[3]);if(s.includes(0))throw new Error("Empty beat group");t=s.map(a=>new Ot.Fraction(a,r)),e=s.reduce((a,i)=>a+i,0)+"/"+r}return new Ot.Voice(e),{meter:e,groups:t??Ot.Beam.getDefaultBeamGroups(e)}}var Mn=class{constructor(e){this.artist=e}addBar(e){this.artist.log("addBar: ",e),this.artist.closeBends(),this.artist.key_manager.reset();let n=me(this.artist.staves),t=Z.Flow.Barline.type,s=t.SINGLE;switch(e){case"single":s=t.SINGLE;break;case"double":s=t.DOUBLE;break;case"end":s=t.END;break;case"repeat-begin":s=t.REPEAT_BEGIN;break;case"repeat-end":s=t.REPEAT_END;break;case"repeat-both":s=t.REPEAT_BOTH;break;default:s=t.SINGLE;break}let r=new Z.Flow.BarNote().setType(s);n.tab_notes.push(r),n.note&&n.note_notes.push(new Z.Flow.BarNote().setType(s))}reserveTabRhythmSpace(){let e=me(this.artist.staves);!e.tab||e.tabRhythmSpace||this.artist.customizations["tab-stems"]!=="true"||(e.tabRhythmSpace=(e.note?3:2)*e.tab.getSpacingBetweenLines(),e.tab.setY(e.tab.getY()+e.tabRhythmSpace),this.artist.last_y+=e.tabRhythmSpace)}addVoice(e={}){this.artist.closeBends();let n=me(this.artist.staves);if(!n){this.addStave("stave",e);return}n.tab_notes.length?(n.tab_notes=[],n.note_notes=[],n.tab_voices.push(n.tab_notes),n.note_voices.push(n.note_notes),n.voiceSettings.push({options:{...this.artist.customizations},direction:e.voice,groups:[]})):Object.assign(me(n.voiceSettings),{direction:e.voice,options:{...this.artist.customizations}})}addStave(e,n){let t={tuning:"standard",clef:"treble",key:"C",notation:e==="tabstave"?"false":"true",tablature:e==="stave"?"false":"true",strings:6};Ze(t,n),this.artist.log("addStave: ",e,t);let s=null,r=null,a=this.artist.x+Number(this.artist.customizations["connector-space"]),i=40;t.notation==="true"&&(r=new Z.Flow.Stave(a,this.artist.last_y,Number(this.artist.customizations.width)-20,{leftBar:!1}),t.color&&r.setDefaultLedgerLineStyle(ke(t.color)),t.clef!=="none"&&r.addClef(t.clef),r.addKeySignature(t.key),t.time&&t["show-time"]!=="false"&&r.addTimeSignature(t.time),this.artist.last_y+=r.getHeight()+this.artist.options.note_stave_lower_spacing+parseInt(String(this.artist.customizations["stave-distance"]),10),i=r.getNoteStartX(),this.artist.current_clef=t.clef==="none"?"treble":t.clef),t.tablature==="true"&&(s=new Z.Flow.TabStave(a,this.artist.last_y,Number(this.artist.customizations.width)-20,{leftBar:!1}).setNumLines(t.strings),t.clef!=="none"&&s.addTabGlyph(),s.setNoteStartX(i),this.artist.last_y+=s.getHeight()+this.artist.options.tab_stave_lower_spacing),this.artist.closeBends();let{meter:c,groups:l}=cr(t.time||"4/4"),u=[],f=[];this.artist.staves.push({tab:s,note:r,tab_voices:[u],note_voices:[f],tab_notes:u,note_notes:f,meter:c,key:t.key,capo:Number(t.capo??0),color:t.color,tabRhythmSpace:0,voiceSettings:[{options:{...this.artist.customizations},direction:t.voice,groups:[]}],text_voices:[],beam_groups:l}),this.artist.tuning.setTuning(t.tuning),this.artist.key_manager.setKey(t.key)}};var Tn=class{constructor(e){this.artist=e}addTextVoice(){this.color=void 0,me(this.artist.staves).text_voices.push([])}setTextFont(e){if(!e)return;let n=e.match(/^([^-]*)-([^-]*)-([^-]*)(?:-(.*))?$/);if(n){if(n[4]!==void 0&&!Fe(n[4]))throw new Z.RERR("ArtistError",`Invalid text color '${n[4]}'`);this.color=n[4],this.artist.customizations["font-face"]=n[1],this.artist.customizations["font-size"]=parseInt(n[2],10),this.artist.customizations["font-style"]=n[3]}}addTextNote(e,n=0,t="center",s=!0,r=!1){let a=me(this.artist.staves).text_voices;if(De(a))throw new Z.RERR("ArtistError","Can't add text note without text voice");let i=this.artist.customizations["font-face"],c=this.artist.customizations["font-size"],l=this.artist.customizations["font-style"],u=Z.Flow.TextNote.Justification.CENTER;switch(t){case"center":u=Z.Flow.TextNote.Justification.CENTER;break;case"left":u=Z.Flow.TextNote.Justification.LEFT;break;case"right":u=Z.Flow.TextNote.Justification.RIGHT;break;default:u=Z.Flow.TextNote.Justification.CENTER;break}let f=r?"b":this.artist.current_duration,m={text:e,duration:f,smooth:s,ignoreTicks:r,font:{family:i,size:c,weight:l}};e.startsWith("#")&&(m.glyph=e.slice(1),m.text="",m.font=null);let h=new Z.Flow.TextNote(m).setLine(n).setJustification(u);this.color&&h.setStyle(ke(this.color)),me(a).push(h)}};var Ke=class o{constructor(e,n,t,s){this.customizations={};this.staves=[];this.tab_articulations=[];this.stave_articulations=[];this.player_voices=[];this.last_y=0;this.current_duration="q";this.current_dots=0;this.current_head="n";this.current_clef="treble";this.current_bends={};this.current_octave_shift=0;this.bend_start_index=null;this.bend_start_strings=null;this.rendered=!1;this.renderer_context=null;this.player=null;this.x=e,this.y=n,this.width=t,this.options={font_face:Gn,font_size:10,font_style:null,bottom_spacing:30,tab_stave_lower_spacing:10,note_stave_lower_spacing:0,scale:1},s&&Ze(this.options,s),this.renderer=new an(this),this.articulations=new yn(this),this.notes=new En(this),this.stavesBuilder=new Mn(this),this.text=new Tn(this),this.reset()}static{this.DEBUG=!1}static{this.NOLOGO=!0}log(...e){o.DEBUG&&console&&console.log("(Vex.Flow.Artist)",...e)}reset(){this.tuning=new Z.Flow.Tuning,this.key_manager=new Z.Flow.KeyManager("C"),this.music_api=new Z.Flow.Music,this.customizations={"font-size":this.options.font_size,"font-face":this.options.font_face,"font-style":this.options.font_style,"annotation-position":"bottom",scale:this.options.scale,width:this.width,"stave-distance":0,space:0,player:"false",tempo:120,instrument:"acoustic_grand_piano",accidentals:"standard","tab-stems":"false","tab-stem-direction":"up",beams:"auto","beam-rests":"true","beam-stemlets":"true","beam-middle-only":"false","connector-space":5},this.staves=[],this.tab_articulations=[],this.stave_articulations=[],this.player_voices=[],this.last_y=this.y,this.current_duration="q",this.current_dots=0,this.current_head="n",this.current_clef="treble",this.current_bends={},this.current_octave_shift=0,this.bend_start_index=null,this.bend_start_strings=null,this.rendered=!1,this.renderer_context=null}attachPlayer(e){this.player=e}setOptions(e,n=(t,s)=>new Z.RERR("ArtistError",s)){this.log("setOptions: ",e);let t=Or(this.customizations);if(Object.entries(e).forEach(([s,r])=>{if(!t.includes(s))throw n(s,`Invalid option '${s}'`);if(["width","scale","font-size","tempo","space","stave-distance","connector-space"].includes(s)){let a=Number(r),i=["width","scale","font-size","tempo"].includes(s);if(!Number.isFinite(a)||String(r).trim()===""||i&&a<=0)throw n(s,`Invalid numeric value for '${s}': ${r}`)}if(s==="accidentals"&&!["standard","cautionary"].includes(r))throw n(s,"accidentals must be standard or cautionary");if(s==="beams"&&!["auto","off","explicit"].includes(r))throw n(s,"beams must be auto, explicit or off")}),Object.assign(this.customizations,e),this.rendered&&e.width!==void 0)for(let s of this.staves)s.note?.setWidth(Number(e.width)-20),s.tab?.setWidth(Number(e.width)-20);this.last_y+=Number(e.space??0),e.player==="true"&&(this.last_y+=15)}getPlayerData(){return{voices:this.player_voices,context:this.renderer_context,scale:Number(this.customizations.scale)}}render(e){this.renderer.render(e)}draw(e){this.render(e)}isRendered(){return this.rendered}isLogoHidden(){return!0}setDuration(e,n=!1){this.notes.setDuration(e,n)}addBar(e){this.stavesBuilder.addBar(e)}makeTuplets(e,n){this.articulations.makeTuplets(e,n)}addAnnotations(e){this.articulations.addAnnotations(e)}addArticulations(e){this.articulations.addArticulations(e)}addDecorator(e){this.articulations.addDecorator(e||null)}addRest(e){this.notes.addRest(e)}addChord(e,n,t){this.notes.addChord(e,n||null,t||null)}addNote(e){this.notes.addNote(e)}addTextVoice(){this.text.addTextVoice()}setTextFont(e){this.text.setTextFont(e)}addTextNote(e,n=0,t="center",s=!0,r=!1){this.text.addTextNote(e,n,t,s,r)}addVoice(e){this.stavesBuilder.addVoice(e||{})}addStave(e,n){this.stavesBuilder.addStave(e,n)}openBends(e,n,t,s){this.articulations.openBends(e,n,t,s)}closeBends(e=1){this.articulations.closeBends(e)}runCommand(e,n=0,t=0){this.log("runCommand: ",e);let s=e.split(/\s+/);switch(s[0]){case"color":{if(s.length!==2||!Fe(s[1]))throw new Z.RERR("ArtistError",`Expected a CSS color name or hex value at line ${n} column ${t}`);let r=me(this.staves),a=r&&me(r.note_notes),i=r&&me(r.tab_notes);if(!a&&!i||(a||i)instanceof Z.Flow.BarNote)throw new Z.RERR("ArtistError",`Put !color! after a note or rest at line ${n} column ${t}`);a?.setStyle(ke(s[1])),a?.setLedgerLineStyle?.(ke(s[1])),i?.setStyle(ke(s[1]));break}case"octave-shift":if(s.length!==2||!/^[+-]?\d+$/.test(s[1])||!Number.isSafeInteger(Number(s[1])))throw new Z.RERR("ArtistError",`Invalid octave shift at line ${n} column ${t}`);this.current_octave_shift=Number(s[1]),this.log("Octave shift: ",this.current_octave_shift);break;default:throw new Z.RERR("ArtistError",`Invalid command '${s[0]}' at line ${n} column ${t}`)}}};function lr(o,e,n,t,s,r,a=!1){(e>=n||!a&&o[e].bar!==o[n].bar)&&r("syntax","Beam short notes within one bar",t,s);for(let i=e;i<=n;i++){let[c,l]=o[i].writtenDuration.split("/").map(Number);c*4>=l&&r("syntax","Beam short notes with written values shorter than a quarter",t,s),a&&!o[i].heads.length&&r("syntax","A continuous beam requires pitched attacks",t,s)}}function As(o,e){let n=new Map,t=!1,s;function r(a,i,c,l){if(!s){s=new Uint8Array(o.events.length);let u=new Map(o.events.map((f,m)=>[f.id,m]));for(let f of o.spans)(f.kind==="beam"||f.kind==="feather"||f.kind==="continuousBeam")&&s.fill(1,u.get(f.first),u.get(f.last)+1)}for(let u=a;u<=i;u++)s[u]&&e("syntax","A note may belong to only one beam",c.range,l),s[u]=1}o.events.forEach((a,i)=>{for(let c of a.marks){if(c.kind!=="spanEndpoint")continue;let l=c.span+"-"+c.name;if(c.edge==="start"){n.has(l)&&e("syntax","Duplicate span start "+c.name,c.range,a.trace),c.span==="beam"&&t&&e("syntax","A note may belong to only one beam",c.range,a.trace),n.set(l,{mark:c,index:i}),c.span==="beam"&&(t=!0);continue}let u=n.get(l);(!u||i===u.index)&&e("syntax","Expected an earlier start for "+c.name,c.range,a.trace),n.delete(l);let f=o.events[u.index].id,m=a.id,h=c.name,w=u.mark.range;if(c.span==="hairpin")o.spans.push({kind:u.mark.hairpin,first:f,last:m,range:w,name:h,niente:u.mark.niente});else{if(c.span==="beam"){let v=o.events[u.index].bar!==a.bar;if(lr(o.events,u.index,i,c.range,a.trace,e,v),r(u.index,i,c,a.trace),t=!1,v){o.spans.push({kind:"continuousBeam",first:f,last:m,range:w,name:h});continue}}o.spans.push({kind:c.span,first:f,last:m,range:w,name:h,side:u.mark.side,strings:[]})}}});for(let{mark:a,index:i}of n.values())e("syntax","Missing end for "+a.name,a.range,o.events[i].trace)}var zi=new Map([...["velocity","sustain","gliss","release","stem","dynamic","sharedStem","onStaff","pedal","ossia","grace","ornament","lyric","symbol","frame","line","ink","write","prebend","bend","text"].map(o=>[o,o]),["diagram","frame"],["slideIn","open slide"],["slideOut","open slide"],["showSign","accidental"],["courtesy","accidental"],["hammer","connection"],["pull","connection"],["slide","connection"]]);function Kt(o){if(o.length<2)return;let e=new Set;for(let n of o){let t=n.kind==="pedal"&&"action"in n?"pedal "+n.action:n.kind==="lyric"&&"verse"in n?"verse "+n.verse:n.kind==="harmony"?"symbol":zi.get(n.kind);if(t){if(e.has(t))return{reason:"Only one "+t+" may be written here",range:n.range};e.add(t)}}}function ur(o){return o==="auto"||o==="mini"||o==="large"}function dr(o){return/^(top|bottom)-(left|center|right)$/.test(o)}function Pn(o={}){let{visibility:e="hover",position:n="bottom-center",inset:t=12,size:s="large"}=o;if(e!=="hover"&&e!=="always"&&e!=="off")throw new RangeError("Control visibility must be off, hover or always");if(!ur(s))throw new RangeError("Control size must be auto, mini or large");if(!dr(n))throw new RangeError("Unknown playback control position: "+n);if(!Number.isFinite(t)||t<0)throw new RangeError("Control inset must be a nonnegative number");return{visibility:e,position:n,inset:t,size:s}}var Xt={human:{chordSpread:.008,rubato:.006,drift:.004,swell:1,touch:2,swing:0,beatAccent:.5,pocket:0,grace:.21},bach:{chordSpread:.007,rubato:.021,drift:.014,swell:3,touch:3,swing:0,beatAccent:7,pocket:0,grace:.14},chopin:{chordSpread:.016,rubato:.105,drift:.035,swell:9,touch:5,swing:0,beatAccent:1,pocket:0,grace:.22},ragtime:{chordSpread:.008,rubato:.006,drift:.008,swell:2,touch:3,swing:0,beatAccent:-3,pocket:0,grace:.13},blues:{chordSpread:.014,rubato:.024,drift:.018,swell:4,touch:5,swing:.9,beatAccent:-2,pocket:.055,grace:.16},parker:{chordSpread:.013,rubato:.012,drift:.015,swell:3,touch:5,swing:1,beatAccent:-5,pocket:.032,grace:.11},robot:{chordSpread:0,rubato:0,drift:0,swell:0,touch:0,swing:0,beatAccent:0,pocket:0,grace:.25}};function xt(o){return Object.prototype.hasOwnProperty.call(Xt,o)}var Oe=Object.freeze({bytes:65536,tokens:8192,depth:24,repetitions:32,events:4096,heads:16,steps:32768,fraction:2147483647}),ji=Object.freeze({...Oe,bytes:1048576,tokens:131072,events:32768,steps:524288});function Rs(o="default"){if(o==="default")return Oe;if(o==="large")return ji;throw new RangeError("Expected score capacity default or large")}function Fs(o,e,n){(o.length>n.bytes||new TextEncoder().encode(o).length>n.bytes)&&e("source-limit","Score exceeds "+n.bytes/1024+" KiB",[0,0]);let t=[];function s(c,l){t.length===n.tokens&&e("token-limit","Score exceeds "+n.tokens+" input tokens",l),t.push({text:c,range:l})}let r=/[^\r\n]*/y,a=/\/\/[^\r\n]*|"(?:\\.|[^"\\\r\n])*"|"|[{}()[\],|]|(?:\/(?!\/)|[^/"\s{}()[\],|])+/gu,i;for(;i=a.exec(o);){if(i[0].startsWith("//"))continue;let c=i[0];if(c.startsWith("#")&&t[t.length-1]?.text!=="ink"){r.lastIndex=i.index,r.exec(o),a.lastIndex=r.lastIndex;continue}if(/^(?:(?:x|0|[1-9]\d?)-)+(?:x|0|[1-9]\d?)\/[1-8]$/.test(c)){let[l,u]=c.split("/"),f=i.index;for(let m of l.split("-")){let h=f+m.length;s(m+"/"+u,[f,h===i.index+l.length?a.lastIndex:h]),f=h+1}}else s(c,[i.index,a.lastIndex])}return t.push({text:"",range:[o.length,o.length]}),t}function Gi(o,e,n,t){let s=[e.range[0]+1];for(let a=1;a<e.text.length-1;)e.text[a]!=="\\"?a++:a+=e.text[a+1]==="u"?6:2,s.push(e.range[0]+a);let r=([a,i])=>[s[a],s[i]];return Fs(o,(a,i,c)=>n(a,i,r(c)),t).map(a=>({text:a.text,range:r(a.range)}))}var Cs=/^:(w|h|q|1|2|4|8|16|32|64|128|256)(\.{0,2})$/,Nn=/^[A-G](?:bb|##|b|#|n)?[0-9]$/,Is=/^(x|0|[1-9]\d?)\/([1-8])$/,Wi=new Set(["velocity","sustain","hammer","tie","pull","slide","courtesy","slash","accent","frame","diagram","line","ink","label","tap","vibrato","brush","roll","stroke","rasgueado","symbol","write","staccato","fermata","stem","dynamic","harmony","onStaff","sharedStem","pedal","ossia","grace","ornament","verse","gliss","release","articulation","lyric","bend","prebend","finger"]),Bs=["kick","snare","hat"];function qi(o){return o==="guitar"||o==="piano"||o==="drums"||o==="staff"}function Vs(o,e,n=Oe){let t=new Set(Bs),s=new Map,r=Fs(o,e,n),a=0,i=0,c=()=>r[Math.min(a,r.length-1)].text,l=()=>{let b=r[a];return b.text||u("Unexpected end of score",b),a++,b},u=(b,g=r[Math.min(a,r.length-1)])=>e("syntax",b,g.range);function f(b){return c()!==b&&u("Expected "+b),l()}function m(){return/^[a-z][a-z0-9_]*$/.test(c())||u("Expected a lowercase name"),l().text}function h(b){let g=f("{");++i>Oe.depth&&e("depth-limit","Too many nested blocks",g.range);let y=b();return f("}"),i--,y}let w=new Map,v=[],x={},P,B,D,_=[],M=[],V,K,Y;function W(b){let g=b.range;if(b.text==="common")return{value:"4/4",sign:"C",range:g};if(b.text==="cut")return{value:"2/2",sign:"C|",range:g};let y=/^(\d{1,2}(?:\+\d{1,2})*)\/(1|2|4|8|16|32|64)$/.exec(b.text);y||u("Expected a meter such as 4/4",b);let I=y[1].split("+").map(Number),z=I.reduce((k,d)=>k+d,0);return(z>32||I.includes(0))&&u("Expected one through 32 beats",b),{value:z+"/"+y[2],...I.length>1&&{sign:b.text},range:g}}function C(b,g){let y=W(g),I=1;if(c()==="at"){l();let z=l();(!/^[1-9]\d{0,3}$/.test(z.text)||Number(z.text)<2)&&u("Expected a bar number starting at 2",z),I=Number(z.text)}b[I]&&u("Meter already declared for bar "+I,g),b[I]=y}function T(){let b=l();return["tr","turn","turn_inverted","mordent","mordent_inverted"].includes(b.text)||u("Unknown ornament",b),b.text}function X(b){return["spanEndpoint","stem","dynamic","harmony","onStaff","sharedStem","pedal","ossia","grace","ornament","slash","line","accent","symbol","lyric","frame","diagram","ink","label","tap","vibrato","stroke","brush","roll","rasgueado"].includes(b.kind)}function S(){let b=l();if(!b.text.startsWith('"'))return u("Expected quoted text",b);try{return JSON.parse(b.text)}catch{return u("Invalid quoted text",b)}}function N(b){let g={range:b.range,settings:{},anchors:[],cues:[]};c()==="part"?(l(),g.part=m()):c()==="conductor"&&(l(),g.conductor=!0),M.some(z=>z.part===g.part&&z.conductor===g.conductor)&&u("Duplicate edition for this target",b);function y(){let z=l();return/^\d{1,3}(?:\.\d{1,3})?$/.test(z.text)||u("Expected millimeters",z),Number(z.text)}function I(){let z=l();return/^[1-9]\d{0,3}$/.test(z.text)||u("Expected a positive measure number",z),Number(z.text)}h(()=>{for(;c()!=="}";){let z=l(),k=z.text;if(Object.prototype.hasOwnProperty.call(g.settings,k)&&u("Duplicate edition setting",z),k==="paper"){let d=l();d.text!=="A4"&&d.text!=="Letter"&&u("Expected A4 or Letter",d),g.settings.paper=d.text}else if(k==="margins")g.settings.margins={top:y(),right:y(),bottom:y(),left:y()};else if(k==="staffSize")g.settings.staffSize=y(),g.settings.staffSize||u("Expected a positive staff size",z);else if(k==="title"||k==="subtitle"||k==="header"||k==="footer")g.settings[k]=S();else if(k==="pageNumbers"||k==="compressRests"){let d=l();d.text!=="on"&&d.text!=="off"&&u("Expected on or off",d),g.settings[k]=d.text==="on"}else if(k==="system"||k==="page"||k==="prefer"||k==="forbid"){f(k==="system"||k==="page"?"at":"after");let d=I();g.anchors.push({field:{system:"systemBreaks",page:"pageBreaks",prefer:"preferredTurns",forbid:"forbiddenTurns"}[k],measure:d,range:[z.range[0],r[a-1].range[1]]})}else if(k==="cue"){g.part||u("Declare a cue in a player edition",z);let d=m();f("at");let p=I(),E=S();E.trim()||u("Expected a cue label",z),g.cues.push({part:d,measure:p,label:E,range:[z.range[0],r[a-1].range[1]]})}else u("Unknown edition setting",z)}}),g.range=[b.range[0],r[a-1].range[1]],M.push(g)}function L(b){let g=b?{id:b}:{};for(;c()==="name"||c()==="shortName"||c()==="sounds"&&r[a+2]?.text!=="at";){let y=l();if(Object.prototype.hasOwnProperty.call(g,y.text)&&u("Duplicate instrument field",y),y.text==="sounds"){let I=l();(!/^[+-]?\d{1,3}$/.test(I.text)||Math.abs(Number(I.text))>127)&&u("Expected a sounding interval from -127 to +127 semitones",I),g.sounds=Number(I.text)}else g[y.text]=S()}return g}function q(b){let{name:g,...y}=b;return{...y,...g!==void 0&&{displayName:g}}}function Q(){let b={};for(;["above","below","font","size","style","ink"].includes(c());){let g=l();if(g.text==="above"||g.text==="below")b.position=g.text;else if(g.text==="font")b.family=S();else{let y=l();g.text==="ink"?b.ink=y.text:g.text==="size"?((!/^\d{1,2}$/.test(y.text)||Number(y.text)<1)&&u("Expected a positive font size",y),b.size=Number(y.text)):(y.text!=="italic"&&y.text!=="normal"&&y.text!=="bold"&&u("Expected a font style",y),b.style=y.text)}}return b}function re(b,g,y=!1){let I=/^([1-9]\d{0,9})\/([1-9]\d{0,9})$/.exec(g);I||u("Expected a positive fraction",b);let[z,k]=I.slice(1).map(Number);(z>Oe.fraction||k>Oe.fraction)&&u("Timing fraction exceeds precision limit",b),y&&z>=k&&u("Grace share must be smaller than one",b);let d=z,p=k;for(;p;)[d,p]=[p,d%p];return z/d+"/"+k/d}function se(){let b=l();if(b.text==="hammer"||b.text==="tie"||b.text==="pull"||b.text==="slide"||b.text==="courtesy"||b.text==="showSign")return{kind:b.text,range:b.range};let g=()=>[b.range[0],r[a-1].range[1]];if(b.text==="slash")return{kind:"slash",range:b.range};if(b.text==="accent")return c()==="above"||c()==="below"?{kind:"sign",code:"a>",position:l().text,range:g()}:{kind:"accent",range:g()};if(b.text==="tieStart"||b.text==="tieEnd"){let k=m(),d=b.text==="tieStart"&&(c()==="above"||c()==="below")?l().text:void 0;return{kind:b.text,name:k,...d&&{side:d},range:g()}}if(b.text==="velocity"){let k=l();return(!/^(?:0|[1-9]\d{0,2})$/.test(k.text)||Number(k.text)>127)&&u("Expected an integer MIDI velocity from 0 to 127",k),{kind:"velocity",value:Number(k.text),range:g()}}if(b.text==="sustain"){let k=l();return{kind:"sustain",duration:re(k,k.text),range:g()}}if(["slurStart","slurEnd","beamStart","beamEnd","crescendoStart","diminuendoStart","hairpinEnd"].includes(b.text)){let k=m(),d=b.text.startsWith("slur")?"slur":b.text.startsWith("beam")?"beam":"hairpin",p=b.text.endsWith("Start")?"start":"end",E=b.text==="crescendoStart"?"crescendo":b.text==="diminuendoStart"?"diminuendo":void 0,R=b.text==="slurStart"&&(c()==="above"||c()==="below")?l().text:void 0,j=!!E&&c()==="niente";return j&&l(),{kind:"spanEndpoint",name:k,span:d,edge:p,hairpin:E,side:R,niente:j,range:g()}}if(b.text==="frame"||b.text==="diagram"){f("(");let k=[];for(;c()!==")";){let p=l();(!/^(?:x|\d{1,2})$/.test(p.text)||k.length>=8)&&u("Expected up to eight diagram frets",p),k.push(p.text==="x"?"x":Number(p.text))}l();let d;if(c().startsWith("barre=")){let p=l(),E=/^barre=(\d{1,2})\/([1-8])\.\.([1-8])$/.exec(p.text);E||u("Expected barre=fret/from..to",p),d=[Number(E[1]),Number(E[2]),Number(E[3])]}return{kind:b.text,frets:k,barre:d,range:g()}}if(b.text==="line"){let k=l();return/^-?\d{1,2}(?:\.5)?$/.test(k.text)||u("Expected a staff line",k),{kind:"line",value:Number(k.text),range:g()}}if(b.text==="ink")return{kind:"ink",value:l().text,range:g()};if(b.text==="label"){let k=S(),d=Q();return{kind:"label",text:k,style:d,range:g()}}if(b.text==="tap"||b.text==="vibrato"){let k=b.text==="vibrato"&&c()==="wide";return k&&l(),{kind:b.text,wide:k,range:g()}}if(b.text==="brush"||b.text==="roll"||b.text==="stroke"||b.text==="rasgueado"){let k=l();return k.text!=="up"&&k.text!=="down"&&u("Expected up or down",k),{kind:b.text,direction:k.text,range:g()}}if(b.text==="symbol"){let k=S(),d;return c()==="ink"&&(l(),d=l().text),{kind:"symbol",text:k,ink:d,range:g()}}if(b.text==="write"){let k=l();return Nn.test(k.text)||u("Expected a written pitch",k),{kind:"write",pitch:k.text,range:g()}}if(["staccato","fermata","articulation"].includes(b.text)){let k=b.text==="articulation"?c().startsWith('"')?S():l().text:b.text==="fermata"?"a@a":"a.",d=c()==="below"?"below":"above";return(c()==="below"||c()==="above")&&l(),{kind:"sign",code:k,position:d,range:g()}}if(b.text==="stem"){let k=l();return k.text!=="up"&&k.text!=="down"&&u("Expected stem up or down",k),{kind:"stem",value:k.text,range:g()}}if(b.text==="dynamic"){let k=l();return/^(ppp|pp|p|mp|mf|f|ff|fff)$/.test(k.text)||u("Expected a dynamic from ppp to fff",k),{kind:"dynamic",value:k.text,range:g()}}if(b.text==="onStaff"){let k=l();return k.text!=="upper"&&k.text!=="lower"&&u("Expected upper or lower",k),{kind:"onStaff",hand:k.text,range:g()}}if(b.text==="sharedStem")return{kind:"sharedStem",name:m(),range:g()};if(b.text==="ornament")return{kind:"ornament",value:T(),range:g()};if(b.text==="pedal"){let k=l();k.text!=="down"&&k.text!=="up"&&u("Expected pedal down or up",k);let d=k.text==="up"&&c()==="onset";return d&&l(),{kind:"pedal",action:k.text,...d&&{onset:d},range:g()}}if(b.text==="ossia"){let k=l();/^:(?:q|8|16|32)$/.test(k.text)||u("Expected an ossia note value such as :8",k);let d=[];for(f("(");c()!==")";){let p=l();(!Nn.test(p.text)||d.length>=16)&&u("Expected up to 16 ossia notes",p);let E;c()==="["&&(l(),f("ornament"),E=T(),f("]")),d.push({pitch:p.text,ornament:E})}return f(")"),d.length||u("Expected an ossia note",b),{kind:"ossia",duration:k.text.slice(1),notes:d,range:g()}}if(b.text==="grace"){let k=l(),d=[],p=[];k.text!=="before"&&k.text!=="after"&&u("Expected before or after",k);let E=c()==="slashed";E&&l();let R=c().startsWith("steal=")?l():void 0,j=R&&re(R,R.text.slice(6),!0);for(f("(");c()!==")";){d.length>=16&&u("Expected up to 16 grace attacks");let te=c()==="(";te&&l();let fe=[];do{let de=l(),pe=Is.exec(de.text);if(fe.length>=Oe.heads&&u("Too many grace chord heads",de),Nn.test(de.text)?fe.push(de.text):pe&&pe[1]!=="x"?fe.push({fret:Number(pe[1]),string:Number(pe[2])}):u("Expected a grace pitch or fret/string",de),c()==="["){l(),c()!=="finger"&&u("Expected a finger on the grace head");let ye=se();if(ye.kind!=="finger")return u("Expected a grace fingering");p.push({attack:d.length,head:fe.length-1,finger:String(ye.value),position:ye.side}),f("]")}}while(te&&c()!==")");te&&f(")"),d.push(te?fe:fe[0])}return f(")"),d.length||u("Expected a grace pitch",k),{kind:"grace",side:k.text,pitches:d,...j&&{steal:j},...p.length&&{fingerings:p},...E&&{slash:E},range:g()}}if(b.text==="harmony"){let k=function(){let R=l();return/^[A-G](?:b|#)?$/.test(R.text)||u("Expected a chord root or bass pitch",R),R.text},d=k(),p=S(),E;return c()==="bass"&&(l(),E=k()),{kind:"harmony",root:d,quality:p,...E&&{bass:E},range:g()}}if(b.text==="lyric"||b.text==="verse"){let k=b.text==="verse"?m():void 0,d=S(),p;c()==="elide"&&(l(),p=S());let E=c()==="hyphen";E&&l();let R=/^extend=([1-9]\d?)$/.exec(c());return R&&l(),{kind:"lyric",...k&&{verse:k},...p!==void 0&&{elideWith:p},text:d,hyphen:E,extend:R?Number(R[1]):0,range:g()}}if(b.text==="slideIn"||b.text==="slideOut"){let k=l();return k.text!=="above"&&k.text!=="below"?u("Expected above or below",k):{kind:b.text,side:k.text,range:g()}}if(b.text==="gliss"){let k=l();return/^(?:[1-9]|1[0-6])$/.test(k.text)||u("Expected the previous chord head number, 1 through 16",k),{kind:"gliss",fromHead:Number(k.text)-1,range:g()}}if(b.text==="release"||b.text==="bend"){let k=function(te){let fe=l(),de=/^(\w+)=(\d{1,4})(?:\/(\d{1,4}))?$/.exec(fe.text);if(!de||de[1]!==te)return u("Expected "+te+"=N/D",fe);let pe=Number(de[2]),ye=Number(de[3]??1);return ye<1||pe<1||pe>ye?u("Bend phase must lie within the note",fe):[pe,ye]};if(b.text==="release"){let te=k("hold"),fe=k("release");return fe[0]*te[1]<=te[0]*fe[1]&&u("Release must follow the hold",b),{kind:"release",hold:te,release:fe,range:g()}}let d=l();/^\+(?:[1-9]\d?(?:\.5)?|0\.5)$/.test(d.text)||u("Expected a positive bend in semitones",d);let p=k("rise"),E=c().startsWith("hold=")?k("hold"):void 0,R=c().startsWith("release=")?k("release"):void 0,j=E??p;return(E&&E[0]*p[1]<p[0]*E[1]||R&&R[0]*j[1]<=j[0]*R[1])&&u("Bend phases must follow musical time",b),{kind:"bend",semitones:Number(d.text),rise:p,hold:E,release:R,range:g()}}if(b.text==="prebend"){let k=l();if(!/^\+[1-9]\d?$/.test(k.text))return u("Expected a positive bend in semitones",k);let d=c()==="release";return d&&l(),{kind:"prebend",semitones:Number(k.text),release:d,range:g()}}if(b.text!=="finger"&&b.text!=="stringNumber")return u("Unknown note mark "+b.text,b);if(b.text==="finger"?!/^[0-5Tpimac]$/.test(c()):!/^[1-8]$/.test(c()))return u("Invalid finger or string number");let y=l(),I=c(),z=I==="left"||I==="right"||I==="above"||I==="below"?I:void 0;return z&&l(),{kind:b.text,value:/^\d$/.test(y.text)?Number(y.text):y.text,side:z??"left",range:[b.range[0],r[a-1].range[1]]}}let ie=new Map;function ce(){do{let b=l(),g=/^([a-z][a-z0-9_]*)(=?)$/.exec(b.text);g||u("Expected an alias name",b),g[2]||f("=");let y=g[1];ie.has(y)&&u("Duplicate alias "+y,b),Wi.has(y)&&u("Alias would hide the built-in mark "+y,b);let I=r[a],z=S(),k=r,d=a;r=Gi(z,I,e,n),a=0;try{let p=se();c()&&u("Expected one complete note mark"),ie.set(y,p)}finally{r=k,a=d}}while(/^[a-z][a-z0-9_]*=$/.test(c())||r[a+1]?.text==="=")}function ae(){let b=ie.get(c());return b?{...b,range:l().range}:se()}function O(){if(c()!=="[")return[];l();let b=[ae()];for(;c()===",";)l(),b.push(ae());return f("]"),b}function G(){let b=l(),g=Is.exec(b.text);if(g)return{marks:[],fret:g[1]==="x"?"x":Number(g[1]),string:Number(g[2]),range:b.range};if(Nn.test(b.text))return{marks:[],pitch:b.text,range:b.range};if(t.has(b.text))return{marks:[],drum:b.text,range:b.range};u("Expected a pitch, fret/string, or drum name",b)}function ue(){let b=r[a],g=c()==="(",y=[];if(g){l();do{y.length===Oe.heads&&u("Too many heads in a chord");let p=G();for(let E of O()){if(E.kind==="accent"){p.marks.push({kind:"sign",code:"a>",position:"above",range:E.range});continue}if(X(E))return u("Place the attack mark after the closing parenthesis",b);p.marks.push(E)}y.push(p)}while(c()!==")");l()}else y.push(G());let I=new Set,z=new Set;for(let p of y)"string"in p&&I.has(p.string)&&u("A chord needs distinct strings",b),"drum"in p&&z.has(p.drum)&&u("A chord needs distinct drum instruments",b),"string"in p&&I.add(p.string),"drum"in p&&z.add(p.drum);let k=O(),d=k.filter(p=>!X(p));return g&&d.some(p=>p.kind!=="sign")&&u("Place a head mark inside the chord",b),y[0].marks.push(...d),{kind:"attack",heads:y,marks:k.filter(X),range:[b.range[0],r[a-1].range[1]]}}function le(b,g){let y={w:1,h:2,q:4}[b[1]]??Number(b[1]),I=2**b[2].length;return{range:g,kind:"duration",value:[BigInt(I*2-1),BigInt(y*I)]}}function A(b=!1){let g=[];for(;c()!=="}"&&!(b&&c()==="text");){let y=r[a];y.text||u("Expected a closing brace");let I,z=Cs.exec(y.text);if(z)l(),I=le(z,y.range);else if(y.text==="meter"){l();let k=W(l());I={kind:"meter",signature:k,range:[y.range[0],k.range[1]]}}else if(y.text==="use"){l();let k=r[a],d=m();w.has(d)||u("Declare pattern "+d+" before using it (including inside patterns)",k),I={range:y.range,kind:"use",name:d}}else if(y.text==="bar"){l();let k=l(),d={double:"double",final:"end",repeatEnd:"repeat-end",repeatBoth:"repeat-both",single:"single"};Object.prototype.hasOwnProperty.call(d,k.text)||u("Unknown closing barline",k),I={kind:"|",closing:d[k.text],range:y.range}}else if(y.text==="repeatStart")l(),I={kind:"repeatStart",range:y.range};else if(y.text==="break")l(),f("system"),I={kind:"break",range:y.range};else if(y.text==="mark")l(),I={kind:"mark",text:S(),range:y.range};else if(y.text==="crescendo"||y.text==="diminuendo"||y.text==="continuousBeam"||y.text==="feather"||y.text==="tremolo"){let k=y.text;l();let d=(k==="crescendo"||k==="diminuendo")&&(c()==="above"||c()==="below")?l().text:void 0,p,E,R;if(k==="tremolo"){let j=l();/^[1-4]$/.test(j.text)||u("Expected one to four tremolo strokes",j),p=Number(j.text)}else if(k==="feather"){let j=l();j.text!=="left"&&j.text!=="right"&&u("Expected left or right",j),E=j.text}else k!=="continuousBeam"&&c()==="niente"&&(l(),R=!0);I={kind:k,strokes:p,feather:E,niente:R,side:d,body:h(A),range:y.range}}else if(y.text==="fragment"||y.text==="slur"||y.text==="beam"){l();let k=y.text==="slur"&&(c()==="above"||c()==="below")?l().text:void 0;I={kind:y.text,side:k,body:h(A),range:y.range}}else if(y.text==="palmMute"){l(),f("strings"),f("(");let k=[];for(;c()!==")";){let d=l();(!/^[1-8]$/.test(d.text)||k.includes(Number(d.text)))&&u("Expected distinct string numbers",d),k.push(Number(d.text))}k.length||u("Expected a string number"),l(),I={kind:"palmMute",strings:k,body:h(A),range:y.range}}else if(y.text==="transpose"||y.text==="octave"){l();let k=l(),d=Number(k.text)*(y.text==="octave"?12:1);(!/^[+-]?\d{1,3}$/.test(k.text)||Math.abs(d)>127)&&u("Invalid transposition interval",k),I={kind:y.text,semitones:d,body:h(A),range:y.range}}else if(y.text==="volta"||y.text==="repeatCount"){l();let k=l();/^(?:[2-9]|[12]\d|3[0-2])$/.test(k.text)||u("Expected 2 through 32 repeat passes",k);let d=h(A),p=[];for(let E=1;y.text==="volta"&&E<=Number(k.text);E++)f("ending"),f(String(E)),p.push(h(A));I={kind:"volta",body:d,endings:p,...y.text==="repeatCount"&&{count:Number(k.text)},range:y.range}}else if(y.text==="times"||y.text==="tuplet"){l();let k=l();if(y.text==="times")(!/^[1-9]\d?$/.test(k.text)||Number(k.text)>Oe.repetitions)&&u("Use a literal repeat count from 1 to "+Oe.repetitions,k),I={range:y.range,kind:"times",count:Number(k.text),body:h(A)};else{let d=/^([1-9]\d?):([1-9]\d?)$/.exec(k.text);(!d||d.slice(1).some(p=>Number(p)>16))&&u("Use an actual:normal tuplet ratio from 1 to 16 on each side",k),I={range:y.range,kind:"tuplet",scale:[BigInt(d[2]),BigInt(d[1])],body:h(A)}}}else if(y.text==="rest"||y.text==="skip"||y.text==="slash"||y.text==="|")if(l(),y.text==="|")I={kind:"|",range:y.range};else{let k=O();k.some(d=>!X(d))&&u("This rhythm has no pitched head",y),I={kind:y.text,marks:k,range:y.range}}else{g.push(ue());continue}I.range=[y.range[0],r[a-1].range[1]],g.push(I)}return g}function U(b=!1){if(c()!=="voice"){let I=r[a].range,z=A(!0);return b&&z.some(k=>k.kind==="attack")&&z.every(k=>["attack","duration","rest","skip","slash"].includes(k.kind))?[{name:"main",range:I,body:[{kind:"fragment",range:[I[0],z[z.length-1].range[1]],body:z}]}]:[{name:"main",range:I,body:z}]}let g=[],y=new Set;for(;c()==="voice";){l();let I=r[a],z=m();y.has(z)&&u("Duplicate voice "+z,I),y.add(z);let k=F("staff",!0);g.push({name:z,range:I.range,settings:k,body:h(A)})}return g}function $(){let b={};for(;["font","size","style","ink","line","align","spacing"].includes(c());){if(["font","size","style","ink"].includes(c())){Object.assign(b,Q());continue}let g=l(),y=l();g.text==="line"?(/^-?\d{1,2}$/.test(y.text)||u("Expected a staff line",y),b.line=Number(y.text)):g.text==="align"?(y.text!=="left"&&y.text!=="right"&&y.text!=="center"&&u("Invalid text alignment",y),b.align=y.text):(y.text!=="strict"&&y.text!=="smooth"&&u("Expected strict or smooth spacing",y),b.smooth=y.text==="smooth")}return b}function H(){let b=[];for(;c()==="text";){l();let g=r[a].range,y=m();b.some(k=>k.voice.name===y)&&u("Duplicate text lane");let I=$(),z=h(()=>{let k=[],d=I;for(;c()!=="}";){let p=r[a],E=Cs.exec(c());if(E)l(),k.push(le(E,p.range));else if(c()==="|")l(),k.push({kind:"|",range:p.range});else if(c()==="skip")l(),k.push({kind:"skip",range:p.range});else if(["font","size","style","ink","line","align","spacing"].includes(c()))d={...d,...$()};else{let R=c()==="start"||c()==="end"?l().text:void 0,j=c()==="sign",te;j?(l(),te=m()):te=S();let fe=[p.range[0],r[a-1].range[1]];R==="start"||R==="end"?k.push({kind:"textBoundary",boundary:{edge:R,text:te,glyph:j,style:d,range:fe},range:fe}):k.push({kind:"attack",heads:[],marks:[{kind:"text",text:te,glyph:j,style:d,range:fe}],range:fe})}}return k});b.push({voice:{name:y,range:g,body:z},style:I})}return b}function ee(b){f("at");let g=l();/^[1-9]\d{0,4}$/.test(g.text)||u("Expected a positive written bar number",g);let y="0/1",I=g;if(c()==="+"){l(),I=l(),/^\d{1,9}\/[1-9]\d{0,8}$/.test(I.text)||u("Expected an offset in whole notes",I);let[z,k]=I.text.split("/").map(Number),d=z,p=k;for(;p;)[d,p]=[p,d%p];y=z/d+"/"+k/d}return{bar:Number(g.text),at:y,range:[b.range[0],I.range[1]]}}function F(b,g=!1,y=!1){let I={};function z(){f("at");let p=l();return(!/^[1-9]\d{0,3}$/.test(p.text)||Number(p.text)<2)&&u("Expected a bar number starting at 2",p),Number(p.text)}function k(p){if(c()!=="at"){Object.assign(I,p);return}let E=z(),R=I.changes??={};R[E]={...R[E],...p}}let d=y?["key","clef","sounds"]:g?["stem","beams","flatBeams","beamRests","stemlets","middleRests","tabStems","tabDirection"]:["program","map","meter","key","clef","sounds","view","capo","tuning","ink","stem","beams","flatBeams","beamRests","tabStems","stemlets","middleRests","tabDirection","accidentals","display","groupBeats"];for(;d.includes(c());){let p=l(),E=l();if(p.text==="program")(!/^\d{1,3}$/.test(E.text)||Number(E.text)>127)&&u("Expected a MIDI program from 0 to 127",E),I.program=Number(E.text);else if(p.text==="map"){(b!=="drums"||!/^[a-z][a-z0-9_]*$/.test(E.text)||t.has(E.text))&&u("Expected a new percussion ID",E);let R=S();R.trim()||u("Expected a percussion label",E),f("line");let j=l();f("head");let te=l();f("stem");let fe=l();f("midi");let de=l();/^-?\d(?:\.5)?$/.test(j.text)||u("Expected a staff line or space",j),["normal","cross","circle-cross","triangle"].includes(te.text)||u("Unknown percussion head",te),fe.text!=="up"&&fe.text!=="down"&&u("Expected up or down",fe),(!/^\d{1,3}$/.test(de.text)||Number(de.text)>127)&&u("Expected a MIDI pitch from 0 to 127",de),(I.drums??=[]).push({id:E.text,label:R,line:Number(j.text),head:te.text,stem:fe.text,midi:Number(de.text)}),t.add(E.text)}else if(p.text==="meter")C(I.meters??={},E);else if(p.text==="accidentals")E.text!=="standard"&&E.text!=="cautionary"&&u("Expected standard or cautionary",E),I.cautionary=E.text==="cautionary";else if(p.text==="display"){E.text!=="meter"&&u("Expected display meter",E);let R=l();R.text!=="hidden"&&R.text!=="shown"&&u("Expected hidden or shown",R),k({displayMeter:R.text==="shown"})}else if(p.text==="groupBeats"){E.text!=="("&&u("Expected beat groups in parentheses",E);let R=[];for(;c()!==")";){let j=l();(!/^[1-9]\d?$/.test(j.text)||R.length>=32)&&u("Invalid beat group",j),R.push(Number(j.text))}R.length||u("Expected at least one beat group"),l(),I.beatGroups=R}else if(p.text==="ink")k({ink:E.text});else if(p.text==="stem"||p.text==="tabDirection")E.text!=="up"&&E.text!=="down"&&u("Expected up or down",E),I[p.text]=E.text;else if(p.text==="beams"||p.text==="flatBeams"||p.text==="beamRests"||p.text==="tabStems"||p.text==="stemlets"||p.text==="middleRests")E.text!=="on"&&E.text!=="off"&&u("Expected on or off",E),I[p.text==="beams"?"beam":p.text]=E.text==="on";else if(p.text==="key")if(/^(?:Cb|Gb|Db|Ab|Eb|Bb|F|C|G|D|A|E|B|F#|C#|Abm|Ebm|Bbm|Fm|Cm|Gm|Dm|Am|Em|Bm|F#m|C#m|G#m|D#m|A#m)$/.test(E.text)||u("Expected a key signature",E),c()==="at"||y){let R=c()==="at"?ee(p):{bar:1,at:"0/1",range:p.range};!y&&R.at==="0/1"&&R.bar>1?(I.keys??={})[R.bar]=E.text:(I.staffChanges??=[]).push({...R,key:E.text})}else I.key=E.text;else if(p.text==="sounds")(!/^[+-]?\d{1,3}$/.test(E.text)||Math.abs(Number(E.text))>127)&&u("Invalid sounding interval",E),(I.staffChanges??=[]).push({...ee(p),sounds:Number(E.text)});else if(p.text==="clef")if((b==="piano"&&!y||b==="drums")&&u("Declare the clef on a pitched staff",p),["treble","bass","alto","tenor","none","soprano","mezzo-soprano","baritone-c","baritone-f","subbass","french","percussion"].includes(E.text)||u("Unknown clef",E),c()==="at"||y){E.text==="none"&&u("A timed clef must be visible",E);let j=c()==="at"?ee(p):{bar:1,at:"0/1",range:p.range};(I.staffChanges??=[]).push({...j,clef:E.text})}else I.clef=E.text;else if(b!=="guitar")u("This setting needs a guitar part",p);else if(p.text==="view")E.text!=="tab"&&E.text!=="both"&&E.text!=="notation"&&u("Expected tab, notation or both",E),I.view=E.text;else if(p.text==="capo")/^(?:0|[1-9]|1\d|2[0-4])$/.test(E.text)||u("Expected capo fret 0 through 24",E),I.capo=Number(E.text);else if(E.text==="("){let R=[];for(;c()!==")";){let j=l();/^[A-G](?:#|b)?[0-8]$/.test(j.text)||u("Expected an open string pitch such as E4",j),R.length===8&&u("A tuning supports up to eight strings",j),R.push(j.text.slice(0,-1)+"/"+j.text.slice(-1))}R.length<4&&u("A tuning needs at least four strings",E),l(),k({tuning:R.join(",")})}else{let R={standard:"standard",dropD:"dropd",dagdad:"dagdad",eb:"eb",standardBanjo:"standardBanjo"};Object.prototype.hasOwnProperty.call(R,E.text)||u("Unknown guitar tuning",E),k({tuning:R[E.text]})}}return I}for(;c();){let b=l();if(b.text==="meter")v.length&&u("Declare the shared meters before the first part",b),C(x,l());else if(b.text==="pickup"){(K||v.length)&&u("Declare one pickup before the first part",b),Y=l();let g=/^([1-9]\d{0,2})\/(1|2|4|8|16|32|64)$/.exec(Y.text);g||u("Expected a pickup duration such as 1/8",Y),K=[BigInt(g[1]),BigInt(g[2])]}else if(b.text==="edition")N(b);else if(b.text==="layout")(V||v.length)&&u("Declare layout once before the first part",b),V={},h(()=>{for(;c()!=="}";){let g=l();if(g.text==="heading"){V.heading&&u("Declare the score heading once",g);let z={};h(()=>{for(;c()!=="}";){let k=l();if(k.text==="align"){z.align&&u("Duplicate score heading alignment",k),f("center"),z.align="center";continue}k.text!=="title"&&k.text!=="dedication"&&k.text!=="tempo"&&k.text!=="composer"&&u("Unknown score heading field",k),z[k.text]!==void 0&&u("Duplicate score heading field",k),z[k.text]=S()}}),V.heading=z;continue}let y=l(),I=Number(y.text);if(g.text==="font"){y.text!=="Petaluma"&&y.text!=="Bravura"&&u("Expected Petaluma or Bravura",y),V.font=y.text;continue}if(g.text==="stemPolicy"){y.text!=="pitch"&&y.text!=="activeVoices"&&u("Expected pitch or activeVoices",y),V.stemPolicy=y.text;continue}if(g.text==="spacing"){y.text!=="optical"&&u("Expected optical spacing",y),V.spacing="optical";continue}g.text!=="width"&&g.text!=="scale"&&g.text!=="rowGap"&&g.text!=="staffDistance"&&g.text!=="firstSystemIndent"&&g.text!=="top"&&u("Unknown score layout setting",g),(!/^\d{1,4}(?:\.\d{1,3})?$/.test(y.text)||g.text==="width"&&I<=20||g.text==="scale"&&(!I||I>8))&&u("Invalid layout dimension",y),V[g.text]=I}});else if(b.text==="play")(v.length||P)&&u("Set playback once before the first part",b),P={enabled:!0},h(()=>{for(;c()!=="}";){let g=l();if(g.text==="enabled"){let y=l();y.text!=="on"&&y.text!=="off"&&u("Expected on or off",y),P.enabled=y.text==="on"}else if(g.text==="tempo"){let y=l();if(/^[1-9]\d{0,2}$/.test(y.text)||u("Expected a positive tempo",y),c()==="at"){let I=ee(g);I.at!=="0/1"?(P.tempoChanges??=[]).push({...I,bpm:Number(y.text)}):(s.has(I.bar)&&u("Duplicate tempo change at this bar",y),s.set(I.bar,I.range),(P.tempos??={})[I.bar]=Number(y.text))}else P.tempo=Number(y.text)}else if(g.text==="controls"||g.text==="controlSize"||g.text==="position"||g.text==="inset"){let y=l(),I=P.controls??={};g.text==="controls"?y.text==="off"||y.text==="hover"||y.text==="always"?I.visibility=y.text:u("Expected controls off, hover or always",y):g.text==="controlSize"?ur(y.text)?I.size=y.text:u("Expected controlSize auto, mini or large",y):g.text==="position"?dr(y.text)?I.position=y.text:u("Unknown control position",y):(/^\d{1,4}(?:\.\d{1,2})?$/.test(y.text)||u("Expected a nonnegative control inset in pixels",y),I.inset=Number(y.text))}else if(g.text==="swing"){let y=l();y.text!=="eighths"&&y.text!=="off"?u("Expected swing eighths or swing off",y):P.swing=y.text}else if(g.text==="performer"){let y=l();xt(y.text)?P.performer=y.text:u("Unknown performer: "+y.text,y)}else if(g.text==="instrument"){let y=l();!/^[A-Za-z_][A-Za-z0-9_]*$/.test(y.text)&&!/^(?:0|[1-9]\d?|1[01]\d|12[0-7])$/.test(y.text)&&u("Expected an instrument name or MIDI program",y),P.instrument=y.text}else u("Expected a playback setting",g)}});else if(b.text==="transpose"){let g=l();(v.length||B!==void 0)&&u("Declare a single transposition before the first part",g),(!/^[+-]?\d{1,3}$/.test(g.text)||Math.abs(Number(g.text))>127)&&u("Transposition needs an integer from -127 to 127",g),B=Number(g.text)}else if(b.text==="measureNumbers"){let g=l();g.text!=="off"&&g.text!=="on"&&u("Expected on or off",g),D=g.text==="on"}else if(b.text==="alias")v.length&&u("Declare aliases before the first part",b),ce();else if(b.text==="pattern"){let g=r[a],y=m();w.has(y)&&u("Duplicate pattern "+y,g),w.set(y,h(A))}else if(b.text==="group"){let g=l();g.text!=="brace"&&g.text!=="bracket"&&u("Expected brace or bracket",g),f("(");let y=[];for(;c()!==")";)y.push(m());let I=l();y.length<2&&u("A group needs at least two parts",g),_.push({type:g.text,parts:y,range:[b.range[0],I.range[1]]})}else if(qi(b.text)){t=new Set(Bs);let g=r[a],y=c()==="{"?void 0:m();y&&v.some(p=>p.id===y)&&u("Duplicate part ID "+y,g);let I,z=[],k={},d;if(b.text==="piano")h(()=>{I=L(y),k=F("piano");for(let p of["upper","lower"]){let E=f(p),R=r[a],j=c()==="{"?void 0:m();z.some(pe=>(pe.id??pe.name)===(j??p))&&u("Duplicate staff ID "+(j??p),j?R:E);let te,fe,de=h(()=>(te=L(j),fe=F("piano",!1,!0),U()));z.push({...q(te),...fe,name:p,range:E.range,voices:de})}d=H()});else{let p={},E=h(()=>{if(I=L(y),c()==="stave"){l();let te=m();p=h(()=>L(te))}k=F(b.text);let R=b.text==="guitar"&&!k.meters&&!Object.keys(x).length&&!K,j=U(R);return d=H(),j});z.push({...q(p),name:"main",range:b.range,voices:E})}v.push({...I,...k,...d?.length&&{lanes:d},kind:b.text,range:b.range,staves:z})}else u("Expected a score setting, alias, pattern or part",b)}return v.length||u("Expected a part"),{groups:_,tempoRanges:s,editions:M,patterns:w,parts:v,scoreMeters:x,pickup:K,pickupRange:Y?.range,playback:P,measureNumbers:D,layout:V,transpose:B}}var Xe=class extends Error{constructor(e,n,t,s,r){let a=t.slice(0,s[0]),i=a.split(/\r\n|\r|\n/).length,c=s[0]-Math.max(a.lastIndexOf(`
|
|
370
|
+
`),a.lastIndexOf("\r"));super(`${e} at ${i}:${c}: ${n}`),this.name="ScoreV2Error",this.code=e,this.range=s,this.trace=r,this.line=i,this.column=c}};function Yt(o,e,n,t,s){let r=o,a=e;for(;a;)[r,a]=[a,r%a];return o/=r,e/=r,(o>Oe.fraction||e>Oe.fraction)&&n("fraction-limit","Written time needs a smaller ratio",t,s),[o,e]}var vt=([o,e])=>o+"/"+e;function ut(o){let[e,n]=o.split("/");return[BigInt(e),BigInt(n)]}function Ui(o,e,n){if(!e||!("fret"in o)||typeof o.fret!="number")return;let t=o.fret,s=e.heads.findIndex(r=>"fret"in r&&r.string===o.string&&typeof r.fret=="number"&&(n==="hammer"?r.fret<t:n==="pull"?r.fret>t:r.fret!==t));if(s>=0)return{event:e.id,head:s}}function Os(o,e){let n=Rs(e),t=(S,N,L,q=[])=>{throw new Xe(S,N,o,L,q)},{groups:s,tempoRanges:r,editions:a,patterns:i,parts:c,scoreMeters:l,pickup:u,pickupRange:f,playback:m,measureNumbers:h,layout:w,transpose:v}=Vs(o,t,n),x=l[1]?.value??"4/4",P=u&&vt(Yt(...u,t,f,[])),B=[BigInt(1),BigInt(4)],D=[BigInt(0),BigInt(1)],_=0,M=0;function V(S,N){++_>n.steps&&t("work-limit","Phrase expansion exceeds "+n.steps+" work steps",S,N)}function K(S,N,L,q,Q){let re={name:L.name,...L.settings&&{settings:L.settings},range:L.range,events:[],measures:[],spans:[]},{events:se,measures:ie,spans:ce}=re,ae=1,O=0,G=D,ue=!1,le=0,A=0,U=!1,$,H;function ee(g,y,I){let z=vt(G);Q.bars[ae-1]!==void 0&&Q.bars[ae-1]!==z&&t("alignment","Voices disagree on the length of bar "+ae,g,y),Q.bars[ae-1]=z,ie.push({number:ae,start:O,end:se.length,barlineRange:g,trace:y,span:z,fragment:ue,newRow:U,rehearsal:$,closing:I,opening:H}),H=I==="repeat-both"?"repeat-begin":void 0,O=se.length,ae++,G=D,$=void 0,U=!1}function F(g,y,I,z,k){++M>n.events&&t("event-limit","Score exceeds "+n.events+" expanded attacks, rests or skips",g.range,k);let d=Yt(y[0]*z[0],y[1]*z[1],t,g.range,k),p=Kt(g.marks??[]);p&&t("syntax",p.reason,p.range,k);let E=[S.id??q+1,N.id??N.name,L.name,se.length+1].join("."),R=g.kind==="attack"?g.heads.map((j,te)=>{(S.kind==="drums"!="drum"in j||"string"in j&&S.kind!=="guitar")&&t("instrument","This head does not belong to "+S.kind,j.range,k);let fe=Kt(j.marks);fe&&t("syntax",fe.reason,fe.range,k);for(let ye of j.marks){if(ye.kind==="sustain"){let[ve,Te]=ut(ye.duration);ve*d[1]>d[0]*Te&&t("syntax","Head sustain exceeds this attack; write a separate voice or tie",ye.range,k);let Le=g.marks?.find(we=>we.kind==="grace");if(Le?.kind==="grace"&&Le.steal&&Le.side==="before"){let[we,Ne]=ut(Le.steal);ve*d[1]*Ne<=d[0]*Te*we&&t("syntax","Before-grace would consume the entire sounding head",Le.range,k)}}["bend","prebend","slideIn","slideOut"].includes(ye.kind)&&(!("fret"in j)||typeof j.fret!="number")&&t("instrument","This technique needs a pitched fret",ye.range,k)}let de=j.marks.find(ye=>ye.kind==="hammer"||ye.kind==="slide"||ye.kind==="pull");if(!de||de.kind!=="hammer"&&de.kind!=="slide"&&de.kind!=="pull")return j;let pe=Ui(j,se[se.length-1],de.kind);return pe||t("hammer",de.kind==="hammer"?"Expected a lower fret on this string in the preceding attack":"Expected a compatible preceding fret on this string",de.range,k),ce.push({kind:de.kind,from:pe,to:{event:E,head:te},range:de.range}),de.kind==="hammer"?{...j,hammerFrom:pe}:j}):[];se.push({id:E,bar:ae,at:vt(G),duration:vt(d),writtenDuration:vt(y),kind:g.kind,...le&&{transpose:le},...A&&{soundingOctaves:A},heads:R,marks:g.marks??[],range:g.range,rhythmRange:I,trace:k}),G=Yt(G[0]*d[1]+d[0]*G[1],G[1]*d[1],t,g.range,k)}function b(g,y,I,z,k){k.length>Oe.depth&&t("depth-limit","Phrase expansion is too deep",k[k.length-1].range,k);for(let d of g)switch(V(d.range,k),d.kind){case"meter":{G[0]&&t("alignment","Change meter at the beginning of a bar",d.range,k);let p=Q.meters[ae],E=d.signature;p&&(p.value!==E.value||p.sign!==E.sign)&&t("alignment","Conflicting meters for bar "+ae,E.range,k),Q.meters[ae]??={...E,...k.length&&{trace:k}};break}case"duration":y=d.value,I=d.range;break;case"|":ee(d.range,k,d.closing);break;case"textBoundary":{let p=d.boundary.edge==="start"?"0/1":Q.bars[ae-1];vt(G)!==p&&t("alignment","Put a text boundary at the indicated bar edge",d.range,k),(re.boundaries??=[]).push({...d.boundary,bar:ae});break}case"mark":case"break":case"repeatStart":G[0]&&t("alignment","Place this directive at the beginning of a bar",d.range,k),d.kind==="mark"?$=d.text:d.kind==="repeatStart"?H="repeat-begin":U=!0;break;case"fragment":{(G[0]||ue)&&t("alignment","Start a fragment at a bar boundary",d.range,k),ue=!0;let p=ae;b(d.body,y,I,z,k),(G[0]||p===ae)&&ee(d.range,k),ue=!1;break}case"octave":{let p=A;A+=d.semitones/12,b(d.body,y,I,z,k),A=p;break}case"transpose":{let p=le;le+=d.semitones,Math.abs(le)>127&&t("instrument","Transposition exceeds the MIDI range",d.range,k),b(d.body,y,I,z,k),le=p;break}case"crescendo":case"diminuendo":case"continuousBeam":case"feather":case"tremolo":{let p=se.length,E=d.kind==="tremolo"?Yt(z[0],z[1]*BigInt(2),t,d.range,k):z;b(d.body,y,I,E,k);let R=se.slice(p),j=R[0],te=R[R.length-1];R.length<2&&t("syntax","This span needs two endpoints",d.range,k),(d.kind==="feather"||d.kind==="continuousBeam")&&(R.some(fe=>!fe.heads.length||Number(fe.writtenDuration.split("/")[1])<(d.kind==="feather"?16:8))||d.kind==="feather"&&j.bar!==te.bar)&&t("syntax","Invalid pitches or durations for this beam",d.range,k),d.kind==="tremolo"&&(R.length!==2||j.bar!==te.bar||!j.heads.length||!te.heads.length||j.writtenDuration!==te.writtenDuration||!["1/1","1/2","1/4"].includes(j.writtenDuration))&&t("syntax","Tremolo needs two equal whole, half or quarter attacks in one measure",d.range,k),ce.push({kind:d.kind,first:j.id,last:te.id,niente:d.niente,...d.side&&{side:d.side},feather:d.feather,strokes:d.strokes,range:d.range});break}case"palmMute":case"slur":case"beam":{let p=se.length;b(d.body,y,I,z,k);let E=se.slice(p);(!E.length||d.kind!=="palmMute"&&E.length<2)&&t("syntax","This span needs more notes",d.range,k),d.kind==="palmMute"&&S.kind!=="guitar"&&t("instrument","Palm mute needs a guitar",d.range,k),d.kind==="beam"&&lr(se,p,se.length-1,d.range,k,t),ce.push({kind:d.kind,first:E[0].id,last:E[E.length-1].id,side:d.side,strings:d.strings??[],range:d.range});break}case"use":b(i.get(d.name),B,void 0,z,[...k,{pattern:d.name,range:d.range}]);break;case"times":for(let p=1;p<=d.count;p++)V(d.range,k),b(d.body,y,I,z,[...k,{iteration:p,range:d.range}]);break;case"volta":{G[0]&&t("bar-length","Start a repeat at a shared barline",d.range,k);let p=ae;b(d.body,y,I,z,k);let E=ae-1;(G[0]||E<p)&&t("bar-length","End the repeat body with a full bar",d.range,k);let R=d.endings.map(j=>{let te=ae;return b(j,y,I,z,k),(G[0]||ae===te)&&t("bar-length","Each ending needs at least one complete bar",d.range,k),{first:te,last:ae-1}});(re.repeats??=[]).push({first:p,bodyEnd:E,endings:R,...d.count&&{count:d.count},range:d.range});break}case"tuplet":{let p=se.length,E=d.scale[1]+":"+d.scale[0],R=Yt(z[0]*d.scale[0],z[1]*d.scale[1],t,d.range,k);b(d.body,y,I,R,[...k,{tuplet:E,range:d.range}]),se.length>p&&ce.push({kind:"tuplet",ratio:E,first:se[p].id,last:se[se.length-1].id,range:d.range});break}default:F(d,y,I,z,k)}}if(b(L.body,B,void 0,[BigInt(1),BigInt(1)],[]),G[0]){let g=se[se.length-1];t("bar-length","End the final measure with |",g.range,g.trace)}return As(re,t),ie.length||t("bar-length","Expected at least one measure",L.range),Q.voiceLength!==void 0&&Q.voiceLength!==ie.length&&t("alignment","Every voice in a part must cover the same number of bars",L.range),Q.voiceLength=ie.length,re}function Y(S,N,L){let q,Q=!1,re=[...N,...L];for(let se=0;se<S.bars.length;se++){let ie=se+1;S.meters[ie]?(q=S.meters[ie],Q=!0):!Q&&l[ie]&&(q=l[ie]);let ce=q?.value??"4/4",ae=ut(ce);ie===1&&u&&u[0]*ae[1]>=ae[0]*u[1]&&t("syntax","Pickup must be shorter than the opening meter "+ce,f);let O=ie===1&&u?u:ae,[G,ue]=ut(S.bars[se]);if(G*O[1]!==O[0]*ue){let le=N.find(A=>!A.measures[se].fragment);if(le){let A=le.measures[se];if(G*O[1]>O[0]*ue)for(let U=A.start;U<A.end;U++){let $=le.events[U],[H,ee]=ut($.at),[F,b]=ut($.duration);(H*b+F*ee)*O[1]>O[0]*ee*b&&t("bar-length","Attack crosses the end of bar "+ie,$.range,$.trace)}t("bar-length","Bar "+ie+" contains "+A.span+" of a whole note, expected "+vt(O),A.barlineRange,A.trace)}}for(let le of re){let A=le.measures[se];A.meter=ce,A.meterSign=q?.sign,A.meterRange=q?.range}}}function W(S,N){let L=(q,Q)=>{let[re,se]=ut(q),[ie,ce]=ut(Q);return Number(re*ce-ie*se)};S.sort((q,Q)=>q.bar-Q.bar||L(q.at,Q.at));for(let q of S)(!N[q.bar-1]||L(q.at,N[q.bar-1])>=0)&&t("alignment","Timed setting lies outside its written measure",q.range)}let C=c.map((S,N)=>{let{lanes:L,...q}=S,Q={bars:[],meters:{...S.meters}},re=S.staves.map(ce=>({...ce,voices:ce.voices.map(ae=>K(S,ce,ae,N,Q))})),se=L?.map(ce=>({name:ce.voice.name,style:ce.style,voice:K(S,{name:"main",range:S.range,voices:[]},{...ce.voice,name:"text-"+ce.voice.name},N,Q)})),ie=Q.bars.length;for(let[ce,ae]of Object.entries(Q.meters))Number(ce)>ie&&t("alignment","Meter change lies beyond this part",ae.range,ae.trace);for(let ce of Object.keys(S.changes??{}))Number(ce)>ie&&t("alignment","Part setting change lies beyond the score",S.range);for(let ce of Object.keys(S.keys??{}))Number(ce)>ie&&t("alignment","Key change lies beyond the score",S.range);for(let ce of re){let ae=[...S.staffChanges??[],...ce.staffChanges??[]];if(!ae.length)continue;W(ae,Q.bars);let O=new Set,G=ce.voices.map(ue=>new Set(ue.events.map(le=>le.bar+":"+le.at)));for(let ue of ae){for(let le of["key","clef","sounds"])if(ue[le]!==void 0){let A=le+":"+ue.bar+":"+ue.at;O.has(A)&&t("alignment","Duplicate timed "+le,ue.range),O.add(A)}(ue.key||ue.clef)&&ue.at!=="0/1"&&(G.some(le=>!le.has(ue.bar+":"+ue.at))||se?.length)&&t("alignment","Inline clef and key changes need a shared music-voice onset without a separate text lane",ue.range)}ce.staffChanges=ae}return Y(Q,re.flatMap(ce=>ce.voices),se?.map(ce=>ce.voice)??[]),{...q,...Object.keys(Q.meters).length&&{meters:Q.meters},measureCount:ie,staves:re,...se&&{text:se}}}),T=Math.max(...C.map(S=>S.measureCount));for(let[S,N]of Object.entries(l))Number(S)>T&&t("alignment","Meter change lies beyond the score",N.range);for(let[S,N]of r)S>T&&t("alignment","Tempo change lies beyond the score",N);if(m?.tempoChanges){let S=C[0].staves[0].voices[0].measures;for(let L of C){let q=L.staves[0].voices[0].measures;W(m.tempoChanges,q.map(re=>re.span));let Q=m.tempoChanges[m.tempoChanges.length-1];for(let re=0;re<Q.bar-1;re++)q[re].span!==S[re].span&&t("alignment","Share the written bar grid before a global inline tempo",Q.range)}let N=new Set;for(let L of m.tempoChanges){let q=L.bar+":"+L.at;N.has(q)&&t("alignment","Duplicate timed tempo",L.range),N.add(q)}}let X=new Map(C.map((S,N)=>[S.id,N]));for(let S of s){let N=X.get(S.parts[0]);(N===void 0||S.parts.some((L,q)=>X.get(L)!==N+q))&&t("alignment","Group members must be adjacent named parts in score order",S.range)}for(let S of a){let N=C.find(q=>q.id===S.part);S.part&&!N&&t("alignment","Unknown edition part "+S.part,S.range);let L=N?.measureCount??Math.min(...C.map(q=>q.measureCount));for(let q of S.anchors)(q.measure>L||q.field.endsWith("Turns")&&q.measure===L)&&t("alignment","Edition measure or turn outside the music",q.range);for(let q of S.cues){let Q=C.find(re=>re.id===q.part);(!Q||q.measure>Q.measureCount||q.measure>L)&&t("alignment","Missing cue instrument or measure",q.range)}}return{language:2,...s.length&&{groups:s},...a.length&&{editions:a},...v&&{transpose:v},...w&&{layout:w},...m&&{playback:m},...h!==void 0&&{measureNumbers:h},source:o,meter:x,meterRange:l[1]?.range,...u&&{pickup:P},measureCount:T,parts:C}}var Ae=Ee(Pe());var Lt=Ee(Pe());function ge(o,e){throw new ne("syntax",e,o)}function fr(o,e){try{let n=JSON.parse(o);if(typeof n=="string"&&n.trim()&&!/[\r\n]/.test(n))return n}catch{}ge(e,"Expected nonempty text in double quotes")}function Ki(o,e,n,t){let s=/^(\d+)\s+\+(\d+(?:\.\d+)?)\s+rise=(\d+\/\d+)(?:\s+hold=(\d+\/\d+))?(?:\s+release=(\d+\/\d+))?$/.exec(o);s||ge(t,"Expected bend STRING +SEMITONES rise=N/D [hold=N/D] [release=N/D]");function r(c){if(!c)return;let[l,u]=c.split("/").map(Number);return[l,u]}let a={string:+s[1],semitones:+s[2],rise:r(s[3]),hold:r(s[4]),release:r(s[5])};e.heads.some(c=>c.prebend&&c.position.str===a.string)&&ge(t,"This string already has a pre-bend");let i=e.heads.map(c=>c.position);(!i.length||i.some(c=>!c||c.fret==="X"))&&ge(t,"A bend needs a pitched fretted attack");try{new Lt.FrettedInstrument(n.tuning,n.capo).bentAttack(i,e.base,a)}catch(c){ge(t,c.message)}return a}function Xi(o,e,n){for(let[t,s]of o.entries()){let a=e.heads.find(i=>i.position?.str===o.length-t)?.position?.fret;(s==="x"?a!==void 0&&a!=="X":a!==s)&&ge(n,"Frame disagrees with the fretted chord")}e.heads.some(t=>!t.position)&&ge(n,"A frame needs an explicit string for each chord member")}function mr(o,e,n,t,s="frame"){let r=/^([x\d,]+)(?:\s+barre=(\d+):(\d+)-(\d+))?$/.exec(o);(!r||!e.chord)&&ge(t,"A frame follows a chord label and needs low-to-high frets");let a=r[1].split(","),i=a.length;s==="diagram"&&(i<4||i>8)&&ge(t,"Supply four through eight strings in a diagram"),(s==="frame"&&i!==n.strings||a.some(m=>!/^(x|\d+)$/.test(m)))&&ge(t,"Supply one fret or x per string");let c=a.map(m=>m==="x"?"x":Number(m));c.every(m=>m==="x")&&ge(t,"A frame needs at least one sounding string"),c.some(m=>m!=="x"&&!Number.isSafeInteger(m))&&ge(t,"Invalid frame fret"),s==="frame"&&Xi(c,e,t);let l=c.filter(m=>typeof m=="number"&&m>0),u=Math.max(...l)>4?Math.min(...l):1;Math.max(...l)-u>=4&&ge(t,"Frame spans more than four frets");let f;if(r[2]){let[m,h,w]=r.slice(2).map(Number);(h<=w||w<1||h>i||m<u||c[i-h]!==m||c[i-w]!==m||c.slice(i-h,i-w+1).some(v=>typeof v!="number"||v<m))&&ge(t,"Barre endpoints must stop at the given fret, from lower to higher string"),f={fret:m,from:h,to:w}}return{frets:c,firstFret:u,barre:f}}function Yi(o,e,n,t){if(o.events.length&&ge(t,"Put this command at the start of a bar"),o.boundaryRange??=t,e==="key"){(o.keyChange||!Lt.default.hasKeySignature(n))&&ge(t,"Expected one key signature per boundary");try{new Lt.KeyManager(n)}catch{ge(t,"Unsupported key signature")}o.keyChange=n}else if(e==="mark")o.rehearsal&&ge(t,"Duplicate rehearsal mark"),o.rehearsal=fr(n,t);else{let s=/^([1-9]\d*)\s+bars=([1-9]\d*)$/.exec(n);(!s||o.ending)&&ge(t,"Expected one ending NUMBER bars=COUNT"),o.ending={label:s[1]+".",bars:Number(s[2]),range:t}}}var _n=class{constructor(e,n,t){this.state=e;this.spans=n;this.firstVoice=t}apply(e,n){let{range:t}=e,[,s,r=""]=/^(\S+)(?:\s+([\s\S]*))?$/.exec(e.params.trim())??[];if(["key","mark","ending"].includes(s)){this.firstVoice||ge(t,"Put this command in the first voice"),Yi(n,s,r,t);return}let a=n.events[n.events.length-1];switch(a||ge(t,"Put this command immediately after an attack in this bar"),s){case"color":Fe(r)||ge(t,"Expected a CSS color name or hex value"),a.color=r;break;case"bend":a.bend&&ge(t,"One timed bend per attack"),a.bend={spec:Ki(r,a,this.state,t),range:t};break;case"pm":{let i=r.split(",").map(Number);(this.mute||!/^\d+(,\d+)*$/.test(r)||new Set(i).size!==i.length||i.some(c=>c<1||c>this.state.strings)||!a.heads.some(c=>i.includes(c.position?.str)))&&ge(t,"Start one palm mute on a played target string"),this.mute={event:a,strings:i,range:t};break}case"end-pm":{(r||!this.mute||!a.heads.some(u=>this.mute.strings.includes(u.position?.str)))&&ge(t,"End the open palm mute on a played target string");let{strings:i,event:c,range:l}=this.mute;this.spans.push({kind:"palmMute",id:"pm"+l.start,from:c.id,to:a.id,strings:i,range:l}),this.mute=void 0;break}case"silent":(r||a.heads.length||a.silent)&&ge(t,"Put !silent! after a rest"),a.silent=t;break;case"chord":{a.heads.length||ge(t,"A chord label needs a note or slash"),a.chord&&ge(t,"Duplicate chord label");let i=/^("(?:[^"\\]|\\.)*")(?:\s+color=(\S+))?$/.exec(r);(!i||i[2]&&!Fe(i[2]))&&ge(t,'Expected chord "label" with an optional color=NAME or hex value'),a.chord={text:fr(i[1],t),...i[2]&&{color:i[2]},range:t};break}case"frame":a.frame&&ge(t,"Duplicate chord frame"),a.frame={spec:mr(r,a,this.state,t),range:t};break;case"lyric":{let i=/^("(?:[^"\\]|\\.)*")(?:\s+(-)|\s+extend=([1-9]\d*))?$/.exec(r);(!i||a.lyric||!a.heads.length)&&ge(t,'Expected one lyric "syllable" with an optional - or extend=COUNT on a note'),a.lyric={text:fr(i[1],t),hyphen:!!i[2],extend:Number(i[3]??0),range:t};break}default:throw new ne("fixed-layout","Use fixed layout for command "+s,t)}}finish(){this.mute&&ge(this.mute.range,"Unclosed palm mute")}};function An(o,e){let n=0;for(let t of o){let s=t.voices[0],r=s.ending;if(r){let a=t.number+r.bars-1,i=o[a-1]?.voices[0].events;(!i||n>=t.number)&&ge(r.range,"Ending overlaps another ending or extends beyond the score"),e.push({kind:"volta",id:"ending"+r.range.start,label:r.label,from:s.events[0].id,to:i[i.length-1].id,firstBar:t.number,lastBar:a,range:r.range}),n=a}for(let a of t.voices)a.events.forEach((i,c)=>{let l=i.lyric;!l?.crossConnector&&l?.hyphen&&!a.events.slice(c+1).some(u=>u.lyric)&&ge(l.range,"Hyphen needs a following syllable in this bar and voice"),!l?.crossConnector&&l?.extend&&!a.events[c+l.extend]&&ge(l.range,"Lyric extender must end in this bar and voice")})}}function Se(o,e){throw new ne("fixed-layout",`Use fixed layout for ${e}`,o.range)}function be(o,e){throw new ne("syntax",e,o.range)}function dt(o){return new Ae.Fraction().parse(o).simplify()}function Ls(o,e){return(!/^[1-9]\d*\/[1-9]\d*$/.test(o)||!o.split("/").every(n=>Number.isSafeInteger(Number(n))))&&be(e,`Invalid span '${o}'`),dt(o).toString()}function Jt(o){return["true","false"].includes(o.value)||be(o,`Expected true or false for ${o.key}`),o.value==="true"}function zs(o){let e=o.options??[],n=e.length?e[e.length-1].range.end:o.range.start+o.element.length;return{...o.range,end:n}}function Ji(o){let e={tab:o.element==="tabstave",notation:o.element!=="tabstave",capo:0,strings:6,tuning:"standard",key:"C",clef:"treble",meter:"4/4",showTime:!1,fragment:!1,declaration:zs(o),timeRange:{...o.range,end:o.range.start+o.element.length}};o.element==="piano"&&(e.piano=!0);let n=!0,t=!1;for(let s of o.options??[])if(e.piano&&["clef","tuning","capo","strings","tablature","notation"].includes(s.key)&&be(s,"A piano uses treble and bass notation staves"),!(e.piano&&s.key==="hand"))switch(s.key){case"color":Fe(s.value)||be(s,"Expected a CSS color name or hex value"),e.color=s.value;break;case"notation":e.notation=Jt(s);break;case"tablature":e.tab=Jt(s);break;case"fragment":e.fragment=Jt(s);break;case"show-time":n=Jt(s),e.timeRange=s.range;break;case"time":(["C","C|"].includes(s.value)||/^(?:\(\d+(?:\+\d+)+\)|\d+(?:\+\d+)+)\/\d+$/.test(s.value))&&Se(s,`printed time signature '${s.value}'`),Ls(s.value,s),e.meter=s.value,t=!0;break;case"pickup":e.pickup=Ls(s.value,s);break;case"key":Ae.default.hasKeySignature(s.value)||be(s,"Invalid key signature");try{new Ae.KeyManager(s.value)}catch{Se(s,`key signature '${s.value}'`)}e.key=s.value;break;case"tuning":try{new Ae.Tuning(s.value)}catch{be(s,"Invalid tuning")}e.tuning=s.value;break;case"capo":e.capo=Number(s.value),(!/^\d+$/.test(s.value)||!Number.isSafeInteger(e.capo))&&be(s,"Expected a nonnegative capo fret");break;case"strings":e.strings=Number(s.value),(!Number.isInteger(e.strings)||e.strings<4||e.strings>8)&&be(s,"Expected 4\u20138 strings");break;case"clef":s.value==="none"&&Se(s,`clef '${s.value}'`),["treble","bass","tenor","alto","percussion"].includes(s.value)||be(s,"Invalid clef"),e.clef=s.value;break;case"fingering":case"accents":break;case"voice":break;default:Se(s,`stave option '${s.key}'`)}return e.showTime=n&&t,!e.notation&&!e.tab&&be(o,"At least one staff must be visible"),e.pickup&&!dt(e.pickup).lessThan(dt(e.meter))&&be(o,"Pickup must be shorter than the meter"),e}function Hs(o,e,n){return{declaration:n,events:[],tuplets:[],span:"0/1",beams:o.beams!=="off",stem:e==="top"?"up":e==="bottom"?"down":void 0,tabStems:o["tab-stems"]==="true",tabDirection:o["tab-stem-direction"]==="down"?-1:1,beamRests:o["beam-rests"]!=="false",stemlets:o["beam-stemlets"]!=="false",middleRests:o["beam-middle-only"]==="true"}}function $i(o,e){for(let n of e.params){switch(n.key){case"tempo":(!Number.isFinite(Number(n.value))||Number(n.value)<=0)&&be(n,"Tempo must be positive");break;case"transpose":case"instrument":break;case"player":case"measure-numbers":case"tab-stems":case"beam-rests":case"beam-stemlets":case"beam-middle-only":Jt(n);break;case"tab-stem-direction":["up","down"].includes(n.value)||be(n,"Invalid tab stem direction");break;case"beams":n.value==="explicit"&&Se(n,"explicit beam groups"),["auto","off"].includes(n.value)||be(n,"Invalid beam mode");break;default:Se(n,`option '${n.key}'`)}o[n.key]=n.value}}function Zi(o){let e=o.time.replace(/s$/,"");try{Ae.default.durationToTicks(e)}catch{be(o,`Invalid duration '${o.time}'`)}return{base:e,dots:Number(o.dot||0),slash:o.time.endsWith("s"),range:o.range}}function Qi(o,e,n,t,s,r){e.piano&&(o.fret!==void 0||!o.abc||!/^[A-G]$/.test(o.abc.key))&&be(o,"Write named pitches such as C/4 on a piano stave"),o.decorator&&Se(o,`decorator '${o.decorator}'`),o.articulation&&!["T","-"].includes(o.articulation)&&Se(o,`technique '${o.articulation}'`);let a=Number(o.string),i,c=Number(o.fret)+e.capo+(o.prebend?.semitones??0),l;if(o.fret!==void 0){let m=Number(o.fret);(a<1||a>e.strings||!Number.isSafeInteger(m))&&be(o,"Invalid fret or string");try{l=pn(n,c,a)}catch{be(o,"String outside the tuning")}i={str:a,fret:m}}if(o.abc){if(o.abc.key==="X"&&!o.abc.accidental&&!o.abc.accidental_type&&o.fret===void 0){if(r&&!e.tab)return{range:o.range,written:"b/4",sounding:null};(a<1||a>e.strings)&&be(o,"Dead strike needs a physical string");let w;try{w=n.getNoteForFret(e.capo,a).toLowerCase()}catch{be(o,"String outside the tuning")}return{range:o.range,written:w,sounding:null,position:{str:a,fret:"X"}}}/^[A-G]$/.test(o.abc.key)||Se(o,`notehead '${o.abc.key}'`);let m=o.abc.accidental,h=o.abc.key.toLowerCase()+(m&&m!=="n"?m:"")+"/"+(o.octave??a);return!i&&e.tab&&Se(o,"a named pitch without an explicit fret on tab"),{range:o.range,written:h,sounding:l??h,position:i,inheritSign:!m&&!o.abc.accidental_type,accidental:m||(o.abc.accidental_type?"n":void 0),cautionary:o.abc.accidental_type==="c"}}let[u,f]=Ft(n,t,s,String(c),a);return{range:o.range,written:u+"/"+f,sounding:l,position:i,...o.prebend&&{prebend:o.prebend},...o.openSlide&&{openSlide:o.openSlide}}}function eo(o,e,n){let t=o.drums.map(a=>a.id),s=xn(e.clef,e.tab,t,n);s&&be(o,s);let{keys:r}=lt.note(t,"q");return t.map((a,i)=>({drum:a,range:o.drums[i].range,written:r[i],sounding:null}))}function to(o,e,n,t,s){let r=new Set;for(let a of n){let i=e.heads[a];i.sounding===null&&be(s,"Only a pitched head can be tied");let c=o?.heads.findIndex((l,u)=>!r.has(u)&&l.position?.str===i.position?.str&&l.position?.fret===i.position?.fret&&(l.written===i.written||(i.inheritSign||l.inheritSign)&&pr(l)===pr(i)))??-1;c<0&&be(s,"Tie needs the same pitch and string on the previous attack"),r.add(c),t.push({id:e.id+"-tie-"+a,from:o.id,to:e.id,fromHead:c,toHead:a,range:s.range})}}function no(o,e,n){let t=Number(e.params.tuplet),s=Number(e.params.notes??t),r=o.events.length-s;(!Number.isSafeInteger(t)||t<1||!Number.isSafeInteger(s)||s<1||r<0)&&be(e,"Tuplet must fit in this bar and voice");let a=hn(t,n);for(let i of o.events.slice(r))i.duration=dt(i.duration).multiply(a,t).simplify().toString();o.tuplets.push({start:r,count:s,numNotes:t,notesOccupied:a,range:e.range})}function ro(o,e,n,t,s,r,a,i){let c=new Ae.Tuning(e.tuning),l=new Ae.KeyManager(e.key),u=new Ae.Music,f=[],m=zs(o),h=Hs(n,t,m),w=new _n(e,a,!i);i?.[0].keyChange&&l.setKey(i[0].keyChange);let v;for(let x of o.notes){if(x.time&&(r.rhythm=Zi(x)),x.command==="command"){w.apply(x,h),h.keyChange&&!h.events.length&&l.setKey(h.keyChange);continue}if(x.command==="bar"){let T={type:x.type,range:x.range};!h.events.length&&f.length&&!h.opening&&Se(x,"consecutive barlines"),!h.events.length&&!f.length&&!["single","repeat-begin"].includes(x.type)&&Se(x,"this opening barline"),h.events.length?(h.closing=T,f.push(h),h=Hs(n,t,m),i?.[f.length]?.keyChange&&l.setKey(i[f.length].keyChange)):h.opening&&Se(x,"consecutive empty barlines"),(!f.length||["repeat-begin","repeat-both"].includes(x.type))&&(h.opening=T);continue}if(x.command==="tuplet"){no(h,x,e.meter);continue}if(["open_beam","close_beam"].includes(x.command)||(x.command&&x.command!=="rest"&&Se(x,x.command),x.command==="rest"&&(x.params.explicit||Number(x.params.position))&&Se(x,"positioned rest"),(x.decorator||x.articulation&&!["T","-"].includes(x.articulation))&&Se(x,`technique '${x.decorator||x.articulation}'`),!x.command&&!x.chord&&!x.drums&&!x.abc&&x.fret===void 0))continue;let P=x.command==="rest"?[]:x.chord??[x];x.chord&&P.some(T=>T.time)&&Se(x,"duration changes inside a chord");let B=x.drums?eo(x,e,r.rhythm.slash):P.map(T=>{let X=Qi(T,e,c,l,u,r.rhythm.slash);return T.marks&&(X.marks=T.marks),X}),D=B.flatMap(T=>T.position?[T.position.str]:[]);new Set(D).size!==D.length&&Se(x,"a multi-stop chord on one string");let{base:_,dots:M,slash:V}=r.rhythm,K=Ae.default.durationToTicks(_),Y=new Ae.Fraction(K,Ae.default.RESOLUTION).multiply(2**(M+1)-1,2**M).simplify().toString(),W={id:"a"+x.range.start,range:x.range,heads:B,base:_,dots:M,rhythmRange:r.rhythm.range,slash:V,duration:Y,onset:"0/1"},C=P.flatMap((T,X)=>x.articulation==="T"||T.articulation==="T"?[X]:[]);to(v,W,C,s,x),h.events.push(W),v=W}w.finish(),!h.events.length&&h.boundaryRange&&be({range:h.boundaryRange},"Boundary command needs a following measure"),h.events.length?f.push(h):h.opening&&Se({range:h.opening.range},"a barline without a following measure");for(let x of f){let P=new Ae.Fraction(0,1);for(let B of x.events)B.onset=P.simplify().toString(),P.add(dt(B.duration));x.span=P.simplify().toString()}return f}function Ds(o,e){let n=o.voices[0]?.bars;if(!n?.length)throw new ne("measure","Empty stave",o.node.range);o.state.piano&&!o.voices.some(s=>s.bars[0]?.hand==="left")&&be(o.node,"A piano needs a left hand. Add voice hand=left and write its notes or rests");for(let{bars:s,node:r}of o.voices)if(s.length!==n.length)throw new ne("measure","Voices have different bar counts",r.range);let t=o.state;for(let s=0;s<n.length;s++){n[s].keyChange&&(t={...t,key:n[s].keyChange});let r=o.voices.map(f=>f.bars[s]),i=(s===0?o.state.pickup:void 0)??(o.state.fragment?n[s].span:dt(o.state.meter).toString());for(let f of r){let m=f.closing?.range??f.events[f.events.length-1].range;if(f.span!==i){let h=f!==n[s]?"All voices must fill the same bar":"Declare a pickup or fragment for an intentional partial bar";throw new ne("measure",`Bar ${e.length+1} lasts ${f.span}, expected ${i}. ${h}`,m)}if(f!==n[s]&&((f.closing?.type??"single")!==(n[s].closing?.type??"single")||(f.opening?.type??"single")!==(n[s].opening?.type??"single")))throw new ne("measure","Voice barlines disagree",m)}let c=n[s].events[0],l=n[s].events[n[s].events.length-1],u={...n[s].opening?.range??c.range,end:(n[s].closing?.range??l.range).end};e.push({number:e.length+1,range:u,span:i,state:t,voices:r,newRow:s===0})}}function pr(o){return o.written[0]+o.written.slice(o.written.indexOf("/"))}function so(o,e,n){let t=new Ae.Music,s=new Map,r=new Map(e.map(a=>[a.to+"/"+a.toHead,a]));for(let a of o){let i=t.createScaleMap(a.state.key),c=new Map,l=new Map;for(let u of a.voices)for(let f of u.events){let m=l.get(f.onset)??[];m.push({event:f,hand:u.hand}),l.set(f.onset,m)}for(let u of[...l.keys()].sort((f,m)=>dt(f).value()-dt(m).value())){let f=new Map;for(let{event:m,hand:h}of l.get(u))s.set(m.id,m.heads),m.heads.forEach((w,v)=>{if(w.sounding===null)return;let x=pr(w),P=(h??"")+x,B=r.get(m.id+"/"+v),D=B&&s.get(B.from)[B.fromHead];if(w.inheritSign){let M=D?.written.split("/")[0]??c.get(P)??i[x[0]].replace(/n$/,"");if(M==="?")throw new ne("syntax","Write the accidental after a conflicting unison",w.range);w.written=M+x.slice(1),w.position||(w.sounding=w.written)}if(n&&Ie(w.sounding)===void 0)throw new ne("syntax","Transposed note is outside the playable MIDI range",w.range);if(D&&D.written!==w.written)throw new ne("syntax","Tied pitches differ",w.range);let _=w.written.split("/")[0];f.set(P,f.has(P)&&f.get(P)!==_?"?":_)});for(let[m,h]of f)c.set(m,h)}}}function io(o){let e=o.options?.find(n=>n.key==="hand");return o.element==="piano"?(e&&e.value!=="right"&&be(e,"Start a piano with the right hand, then add voice hand=left"),"right"):((!e||!["right","left"].includes(e.value))&&be(e??o,"A piano voice needs hand=right or hand=left"),e.value)}function st(o,e={}){if(e.language===void 0||e.language===2)return Os(o,e.capacity);if(e.language!==1)throw new RangeError("Expected VexTab language 1 or 2");let n=Ut(o,!0),t=[],s=[],r=[],a={rhythm:{base:"q",dots:0,slash:!1}},i={},c;for(let u of n){if(u.element==="options"){let m=u.params.find(w=>["tempo","instrument","player"].includes(w.key));c&&m&&be(m,"Set flow playback options before the first stave");let h=u.params.find(w=>w.key==="measure-numbers");c&&h&&be(h,"Set measure numbering before the first stave"),$i(i,u);continue}if(u.element!=="voice"||!c)c&&Ds(c,t),c={node:u,state:Ji(u),voices:[]};else for(let m of u.options??[])!["voice","fingering","accents"].includes(m.key)&&!(c.state.piano&&m.key==="hand")&&Se(m,`voice option '${m.key}'`);u.text?.length&&Se({range:u.text[0].declaration},"timed text"),u.slurs?.length&&Se(u.slurs[0],"slur");let f=u.options?.find(m=>m.key==="voice")?.value;if(f&&!["top","bottom","new"].includes(f)&&be(u,"Invalid voice direction"),u.notes?.length){let m=c.state.piano?io(u):void 0,h=m?{rhythm:{base:"q",dots:0,slash:!1}}:a,w=ro(u,c.state,i,f,s,h,r,c.voices[0]?.bars);if(m)for(let v of w)v.hand=m;c.voices.push({bars:w,node:u})}else(u.element==="voice"||u.element==="piano")&&be(u,"Empty voice")}c||be(n[0],"Expected a stave"),Ds(c,t),so(t,s,!!Number(i.transpose)),An(t,r);let l={source:o,measures:t,ties:s,spans:r,measureNumbers:i["measure-numbers"]==="true"};return(i.player||i.tempo||i.instrument)&&(l.playback={enabled:i.player==="true",tempo:i.tempo?Number(i.tempo):void 0,instrument:i.instrument}),l}var Rn=class{constructor(e){this.artist=e}newError(e,n){return new Z.RERR("ParseError",`${n} in line ${e._l} column ${e._c}`)}parseStaveOptions(e,n="voice"){let t={};if(!e)return t;let s=null;e.forEach(i=>{let c=l=>this.newError(i,l);switch(t[i.key]=i.value,i.key){case"fingering":case"accents":break;case"notation":case"tablature":if(s=i,!["true","false"].includes(i.value))throw c(`'${i.key}' must be 'true' or 'false'`);break;case"color":if(n==="voice"||!Fe(i.value))throw c("Expected a stave color as a CSS name or hex value");break;case"pickup":if(!/^([1-9]\d*)\/([1-9]\d*)$/.test(i.value))throw c("Expected a pickup span such as 1/4");break;case"fragment":if(!["true","false"].includes(i.value))throw c("fragment must be true or false");break;case"show-time":if(!["true","false"].includes(i.value))throw c("show-time must be true or false");break;case"key":{if(!(Z.Flow?.hasKeySignature?Z.Flow.hasKeySignature(i.value):Wn(Z.Flow?.keySignature?.keySpecs,i.value)))throw c(`Invalid key signature '${i.value}'`);break}case"clef":{let l=["treble","bass","tenor","alto","percussion","none"];if(!l.includes(i.value))throw c(`'clef' must be one of ${l.join(", ")}`);break}case"voice":{let l=["top","bottom","new"];if(!l.includes(i.value))throw c(`'voice' must be one of ${l.join(", ")}`);break}case"time":try{cr(i.value)}catch{throw c(`Invalid time signature: '${i.value}'`)}break;case"tuning":try{new Z.Flow.Tuning(i.value)}catch{throw c(`Invalid tuning: '${i.value}'`)}break;case"capo":if(!/^\d+$/.test(i.value)||!Number.isSafeInteger(Number(i.value)))throw c("Expected a nonnegative capo fret");break;case"strings":{let l=Number(i.value);if(!Number.isInteger(l)||l<4||l>8)throw c(`Invalid number of strings: ${l}`);break}default:throw c(`Invalid option '${i.key}'`)}});let r=t.notation??(n==="tabstave"?"false":"true"),a=t.tablature??(n==="stave"?"false":"true");if(r==="false"&&a==="false")throw this.newError(s,"Both 'notation' and 'tablature' can't be invisible");return t}parseCommand(e){e.command==="bar"&&this.artist.addBar(e.type),e.command==="tuplet"&&this.artist.makeTuplets(e.params.tuplet,e.params.notes),e.command==="annotations"&&this.artist.addAnnotations(e.params),e.command==="rest"&&this.artist.addRest(e.params),e.command==="command"&&this.artist.runCommand(e.params,e._l,e._c)}parseChord(e){this.artist.log("parseChord:",e),this.artist.addChord(Vr(e.chord,n=>on(n,"time","dot","fret","prebend","openSlide","marks","abc","octave","string","articulation","decorator")),e.articulation,e.decorator)}parseFret(e){this.artist.addNote(on(e,"time","dot","fret","prebend","openSlide","marks","string","articulation","decorator"))}parseABC(e){this.artist.addNote(on(e,"time","dot","fret","prebend","openSlide","marks","abc","octave","string","articulation","decorator"))}parseStaveElements(e){this.artist.log("parseStaveElements:",e);let n=me(this.artist.staves),t=me(n.voiceSettings),s;if(e.forEach(r=>{if(t.options.beams==="explicit"){if(r.command==="open_beam"){if(s)throw this.newError(r,"Nested beam group");s={index:n.tab_notes.length,token:r}}if(r.command==="close_beam"){if(!s)throw this.newError(r,"Missing opening beam bracket");let a=n.tab_notes.slice(s.index);if(a.length<2||a.some(i=>i.getIntrinsicTicks()>=Z.Flow.RESOLUTION/4))throw this.newError(r,"Beams need at least two eighth notes or shorter values");t.groups.push([s.index,n.tab_notes.length]),s=void 0}if(s&&r.command==="bar")throw this.newError(r,"Beam crosses a barline")}if(r.time&&this.artist.setDuration(r.time,r.dot),r.command&&this.parseCommand(r),r.drums){let a=r.drums.map(c=>c.id),i=xn(this.artist.current_clef,!!n.tab,a,this.artist.current_head==="s");if(i)throw this.newError(r,i);this.artist.notes.addDrums(a)}r.chord&&this.parseChord(r),r.abc?this.parseABC(r):r.fret&&this.parseFret(r)}),s)throw this.newError(s.token,"Missing closing beam bracket")}parseStaveText(e){De(e)||this.artist.addTextVoice();let n=0,t="center",s=!0,r=null,a=()=>this.artist.addTextNote("",0,t,!1,!0),i=(c,l)=>{let u=!1,f=c;f[0]==="|"&&(u=!0,f=f.slice(1));try{this.artist.addTextNote(f,n,t,s,u)}catch(m){throw this.newError(l,`Bad text or duration. Did you forget a comma?${m}`)}};e.forEach(c=>{let l=c.text.trim();if(l.match(/\.font=.*/))r=l.slice(6),this.artist.setTextFont(r);else if(l[0]===":")this.artist.setDuration(l.slice(1));else if(l[0]==="."){let u=l.slice(1);switch(u){case"center":case"left":case"right":t=u;break;case"strict":s=!1;break;case"smooth":s=!0;break;case"bar":case"|":a();break;default:if(!/^[+-]?\d+$/.test(u))throw this.newError(c,`Invalid text position '${u}'`);n=Number(u);break}}else l==="|"?a():l.slice(0,2)==="++"?this.artist.addTextVoice():i(l,c)})}generate(e){e.forEach(n=>{switch(n.element){case"piano":throw this.newError(n,'Use layout="flow" or parseScore for a piano grand staff');case"stave":case"tabstave":this.artist.addStave(n.element,this.parseStaveOptions(n.options,n.element)),n.notes&&this.parseStaveElements(n.notes),n.text&&this.parseStaveText(n.text);break;case"voice":this.artist.addVoice(this.parseStaveOptions(n.options,n.element)),n.notes&&this.parseStaveElements(n.notes),n.text&&this.parseStaveText(n.text);break;case"options":{let t={};n.params.forEach(s=>{s.key!=="transpose"&&(t[s.key]=s.value)}),this.artist.setOptions(t,(s,r)=>this.newError(n.params.find(a=>a.key===s),r));break}default:throw this.newError(n,`Invalid keyword '${n.element}'`)}})}};function oo(o){return typeof o?.addStave=="function"}var Ye=class o{constructor(e,n){this.valid=!1;if(oo(e)){if(n?.language!==1)throw new TypeError("Use new VexTab(artist, { language: 1 }) for fixed engraving, or new VexTab() and renderScore() for language 2.");this.artist=e,this.compiler=new Rn(e)}else{if(n||e?.language===1)throw new TypeError("Language 1 fixed engraving requires new VexTab(artist, { language: 1 }).");if(e?.language!==void 0&&e.language!==2)throw new RangeError("Expected VexTab language 1 or 2");this.capacity=e?.capacity}}static{this.DEBUG=!1}reset(){this.valid=!1}isValid(){return this.valid}getArtist(){return this.artist}parse(e=""){this.reset(),o.DEBUG&&console.log(`(Vex.Flow.VexTab) Parsing:
|
|
371
|
+
`+e);let n=this.compiler?this.parseFixed(e):st(e,{language:2,capacity:this.capacity});return this.valid=!!n,n}parseFixed(e){let n;try{n=Ut(e)}catch(t){throw t instanceof ne?Object.assign(new Z.RERR("ParseError",t.message),{range:t.range}):t}return n&&this.compiler.generate(n),n}};function qe(o,{partId:e,partIndex:n}){if(e===void 0)return n??0;let t=o.parts.findIndex(s=>s.id===e);if(t<0)throw new RangeError("No instrument with part ID "+e);if(n!==void 0&&n!==t)throw new RangeError("partIndex and partId select different instruments");return t}function js(o,e){let n=e==="right"?"upper":e==="left"?"lower":"main";return{role:n,staff:o.instrument?.staves[n]}}function Gs(o,e,n){let{role:t,staff:s}=js(o,e);if(!n&&t==="main")return{};let r=(c,l)=>[c,l].filter(Boolean).join(" ")||(l===""?"":void 0),a=r(n&&o.instrument?.name,s?.name),i=r(n&&(o.instrument?.shortName??o.instrument?.name),s?.shortName??s?.name);return a===void 0&&i===void 0?{}:{name:a??i,shortName:i??a}}function ao(o){let e=o[0].measures;for(let[n,t]of o.entries()){let s=t.measures,r=t.instrument?.name??t.instrument?.id??"part "+(n+1);for(let a=0;a<Math.max(e.length,s.length);a++)if(!s[a]||!e[a]||s[a].span!==e[a].span){let i=s[a]??s[s.length-1];throw new ne("fixed-layout","Conductor measures must share a span: "+r+", bar "+(a+1),s[a]&&e[a]&&s[a].state.meter!==e[a].state.meter?i.state.timeRange:i.range)}}}function co(o,e){return e[0].continuous.boundaries.map((n,t)=>{let s={...n};for(let r=1;r<e.length;r++){let a=e[r].continuous.boundaries[t];if(a.breakBefore&&(s.breakBefore=a.breakBefore),a.repeatStart&&(s.repeatStart=!0),a.repeatEnd&&(s.repeatEnd=!0),a.rehearsal){if(s.rehearsal&&s.rehearsal!==a.rehearsal)throw new ne("fixed-layout","Conflicting conductor rehearsal marks",o[r].measures[t].range);s.rehearsal=a.rehearsal}}return s})}function hr(o,e){ao(o);function n(i,c){let l=o[i],{role:u,staff:f}=js(l,c),m=(l.instrument?.id??i+1)+"."+(f?.id??u);return u==="main"&&l.measures[0].state.tab?m+"."+c:m}let t=e.flatMap((i,c)=>i.staves.map(l=>({...l,id:n(c,l.id),measures:l.measures.map(u=>({...u,voices:u.voices.map(f=>({...f,notes:typeof f.notes=="string"?f.notes:f.notes.map(m=>typeof m=="object"&&"stave"in m&&typeof m.stave=="string"?{...m,stave:n(c,m.stave)}:m)}))}))}))),s=e.flatMap((i,c)=>i.continuous.groups.map(l=>({...l,first:n(c,l.first),last:n(c,l.last)}))),r=new Map(o.map((i,c)=>[i.instrument?.id,c])),a=o[0].groups??[];for(let i of a){let c=i.parts.map(m=>r.get(m)).filter(m=>m!==void 0);if(c.length<2)continue;let l=c[0],u=c[c.length-1],f=e[u].staves;s.push({type:i.type,first:n(l,e[l].staves[0].id),last:n(u,f[f.length-1].id),barlines:!0})}return!a.length&&o.length>1&&s.push({first:t[0].id,last:t[t.length-1].id,type:"bracket",barlines:s.length===0}),{...e[0],staves:t,engraving:{prepareNote(i,c,l){for(let u of e)u.engraving?.prepareNote?.(i,c,l)},place(i,c){for(let l of e)l.engraving?.place?.(i,c)}},continuous:{...e[0].continuous,groups:s,inkBounds:(i,c)=>e.flatMap(l=>l.continuous.inkBounds?.(i,c)??[]),verticalSpacing:e.some(i=>i.continuous.verticalSpacing==="profile")?"profile":e[0].continuous.verticalSpacing,boundaries:co(o,e),opening:{...e[0].continuous.opening,blocks:[...e[0].continuous.opening?.blocks??[],...e.slice(1).flatMap(i=>(i.continuous.opening?.blocks??[]).filter(c=>c.kind==="diagrams"))]},ossias:e.flatMap(i=>i.continuous.ossias??[]),splitChords:e.flatMap(i=>i.continuous.splitChords??[]),spans:e.flatMap(i=>i.continuous.spans)}}}function Ws(o,e,n){let t=s=>s.map(r=>r.slice(e,e+n));return{...o,staves:t(o.staves),notes:t(o.notes),voices:t(o.voices)}}function $t(o){return[...o.lyric?[o.lyric]:[],...o.verses??[]]}function qs(o,e){let n=o.flatMap((s,r)=>s.events.map(a=>({event:a,bar:r}))),t=new Map;for(let s=n.length-1;s>=0;s--){let{event:r,bar:a}=n[s];for(let i of $t(r)){let c=i.verse??"",l=i.hyphen?t.get(c):i.extend?s+i.extend:s;if(!n[l]||!i.text.trim()||i.elideWith!==void 0&&!i.elideWith.trim()||!r.heads.length&&r.silent)throw new ne("measure","Lyric needs a visible note or rest, text and a valid following endpoint",i.range);a!==n[l].bar&&(i.crossConnector=!0,e.push({kind:i.hyphen?"hyphen":"lyric",lane:c,from:r.id,to:n[l].event.id,id:"verse-"+c+"-"+r.id,range:i.range})),t.set(c,s)}}}var xe=Ee(Pe());function gr(o){let e=[0],n=/\r\n|\r|\n/g;for(;n.exec(o);)e.push(n.lastIndex);return([t,s])=>{let r=0,a=e.length;for(;r+1<a;){let i=Math.floor((r+a)/2);e[i]<=t?r=i:a=i}return{start:t,end:s,line:r+1,column:t-e[r]}}}function Us(o){let[e,n]=o.split("/").map(Number),t=[1,3,7].indexOf(e),s=n/2**t;return{base:{1:"w",2:"h",4:"q"}[s]??String(s),dots:t}}var Ks=new WeakMap;function je(o,e=0){if(!Number.isInteger(e)||!o.parts[e])throw new RangeError("No instrument at partIndex "+e);let n=Ks.get(o);n||Ks.set(o,n=new Map);let t=n.get(e);if(t)return t;let s=o.parts[e],r=gr(o.source),a=r(s.range),{id:i,name:c,shortName:l,sounds:u}=s,m=(i!==void 0||c!==void 0||l!==void 0||u!==void 0||s.staves.some(A=>A.id!==void 0||A.displayName!==void 0||A.shortName!==void 0||A.sounds!==void 0))&&{id:i,name:c,shortName:l,sounds:u,staves:Object.fromEntries(s.staves.map(A=>[A.name,{id:A.id,name:A.displayName,shortName:A.shortName,sounds:A.sounds}]))},h=new xe.Tuning(s.tuning??"standard"),w=new xe.Music,v=s.key??"C",x=new xe.KeyManager(v),P=new Map,B=s.capo??0,D=s.staves.some(A=>A.voices.some(U=>U.events.some($=>$.heads.some(H=>"pitch"in H))));if(D&&(s.view==="tab"||s.view==="both"))throw new ne("measure","A tab view needs a string and fret for every pitch",a);function _(A,U){if(!Fe(A))throw new ne("measure","Expected a CSS color name or hex code",U);return A}let M=s.tuning??"standard",V=s.staves[0].voices[0].measures[0],K=V.meter??o.meter,Y=V.meterRange??o.meterRange,W={declaration:a,color:s.ink&&s.ink!=="default"?_(s.ink,a):void 0,timeRange:r(Y??s.range),meter:K,showTime:!!Y,tab:s.kind==="guitar"&&s.view!=="notation"&&!D,notation:s.view!=="tab",piano:s.kind==="piano",tuning:M,strings:(xe.Tuning.names[M]??M).split(",").length,capo:B,key:s.key??"C",hideClef:s.clef==="none",clef:s.kind==="drums"?"percussion":s.clef==="none"?"treble":s.clef??"treble",pickup:o.pickup,fragment:!1},C=[],T={...o.groups&&{groups:o.groups},...m&&{instrument:m},source:o.source,measures:C,ties:[],spans:[],playback:o.playback,layout:o.layout,measureNumbers:o.measureNumbers??!1};T.program=s.program;let X=s.drums?.length?new xe.PercussionMap([...xe.PercussionMap.kit,...s.drums]):lt;s.kind==="drums"&&(W.kit=X);let S=new xe.Fraction().parse(K).simplify().toString(),N=new Map;function L(A){if(!A||s.kind==="drums")return;let U=v+"/"+A;return N.has(U)||N.set(U,new yt(A,v)),N.get(U)}function q(A,U){let $=r(A.range),H=[],ee;if("drum"in A)ee={drum:A.drum,midi:s.drums?.find(F=>F.id===A.drum)?.midi,written:X.note([A.drum],"q").keys[0],sounding:null,range:$};else if("pitch"in A){let F=A.pitch[0].toLowerCase(),b=A.pitch.slice(1,-1);x.reset();let g=b?F+(b==="n"?"":b):x.getAccidental(F).note,y=U?U.pitch(g,Number(A.pitch.slice(-1))):g+"/"+A.pitch.slice(-1);ee={written:y,sounding:y,range:$}}else{if(A.string>W.strings)throw new ne("measure","String outside the tuning",$);let F={str:A.string,fret:A.fret==="x"?"X":A.fret+(U?.semitones??0)};if(typeof F.fret=="number"&&F.fret<0)throw new ne("measure","Transposition puts fret outside the original string",$);let g=(A.marks.find(k=>k.kind==="prebend")?.semitones??0)+(typeof F.fret=="number"?F.fret:0)+B,y=U?.target??v;P.has(y)||P.set(y,new xe.KeyManager(y));let[I,z]=Ft(h,P.get(y),w,String(g),A.string);ee={position:F,written:I+"/"+z,sounding:A.fret==="x"?null:pn(h,g,A.string),range:$}}s.cautionary&&ee.position&&ee.written.split("/")[0].length>1&&(ee.accidental=ee.written.split("/")[0].slice(1),ee.cautionary=!0);for(let F of A.marks){if(F.kind==="velocity"&&(ee.velocity=F.value),F.kind==="sustain"&&(ee.sustain=F.duration),F.kind==="prebend"&&(ee.prebend={semitones:F.semitones,release:F.release}),(F.kind==="slideIn"||F.kind==="slideOut")&&(ee.openSlide={edge:F.kind==="slideIn"?"in":"out",side:F.side}),F.kind==="write"){if(!ee.position)throw new ne("measure","A written-pitch override needs a fretted head",r(F.range));let b=F.pitch[0].toLowerCase(),g=F.pitch.slice(1,-1),y=g?b+(g==="n"?"":g):x.getAccidental(b).note;ee.written=U?U.pitch(y,Number(F.pitch.slice(-1))):y+"/"+F.pitch.slice(-1)}F.kind==="gliss"&&(ee.glissFrom=F.fromHead),F.kind==="release"&&(ee.release=F),F.kind==="sign"&&H.push({articulation:F.code,position:F.position}),(F.kind==="finger"||F.kind==="stringNumber")&&H.push({finger:String(F.value),stringNumber:F.kind==="stringNumber",position:F.side})}for(let F of A.marks)(F.kind==="courtesy"||F.kind==="showSign")&&(ee.accidental=ee.written.split("/")[0].slice(1)||"n",ee.cautionary=F.kind==="courtesy");for(let F of A.marks)(F.kind==="hammer"||F.kind==="pull"||F.kind==="slide")&&(ee.connection=F.kind);if("hammerFrom"in A&&A.hammerFrom&&(ee.hammer=!0),H.length&&(ee.marks=H),ee.sounding&&Ie(ee.sounding)===void 0)throw new ne("measure","Pitch outside MIDI range",$);return ee}function Q(A,U){let $=A.pitches.map(F=>(Array.isArray(F)?F:[F]).map(b=>q({...typeof b=="string"?{pitch:b}:b,marks:[],range:A.range},U))),H=$.some(F=>F.some(b=>b.position));if(H&&(s.kind!=="guitar"||$.some(F=>F.some(b=>!b.position))))throw new ne("measure","Write every guitar grace head as a fret/string, or use written pitches throughout",r(A.range));if(!H&&!W.notation)throw new ne("measure","TAB grace notes need explicit fret/string positions",r(A.range));let ee=H?$.map(F=>F.map(b=>b.position)):void 0;if(ee?.some(F=>new Set(F.map(b=>b.str)).size!==F.length))throw new ne("measure","A grace chord may use each string once",r(A.range));return{side:A.side,slash:A.slash,...A.steal&&{steal:A.steal},positions:ee,fingerings:A.fingerings,pitches:$.map((F,b)=>Array.isArray(A.pitches[b])?F.map(g=>g.written):F[0].written)}}function re(A,U){let $=L((o.transpose??0)+(A.transpose??0));for(let g of[A.marks,...A.heads.map(y=>y.marks)]){let y=Kt(g);if(y)throw new ne("measure",y.reason,r(y.range))}let H=A.heads.map(g=>q(g,$)),ee=L((U??0)+12*(A.soundingOctaves??0));if(U!==void 0||A.soundingOctaves)for(let g of H){if(!g.sounding)continue;let y=U===void 0?g.sounding:g.written,[I,z]=y.split("/");if(g.sounding=ee?ee.pitch(I,Number(z)):y,Ie(g.sounding)===void 0)throw new ne("measure","Sounding pitch exceeds the MIDI range after the octave or instrument shift",g.range)}if(A.kind==="slash"){if(W.tab)throw new ne("measure","Give a slash a notation-only staff",r(A.range));H.push({written:"b/4",sounding:null,range:r(A.range)})}let F={id:A.id,range:r(A.range),heads:H,slash:A.kind==="slash",onset:A.at,duration:A.duration,...Us(A.writtenDuration)};A.rhythmRange&&(F.rhythmRange=r(A.rhythmRange)),A.kind==="skip"&&(F.silent=F.range),A.heads.forEach((g,y)=>{for(let I of g.marks)if(I.kind==="bend"&&"string"in g){let z=r(I.range),k=H.map(p=>p.position);if(H[y].bend||H[y].prebend||k.some(p=>!p||typeof p.fret!="number"))throw new ne("measure","A bend needs pitched frets and one contour per string",z);let d={string:g.string,semitones:I.semitones,rise:I.rise,release:I.release,hold:I.hold};try{new xe.FrettedInstrument(W.tuning,B).bentAttack(k,F.base,d)}catch(p){throw new ne("measure",p.message,z)}H[y].bend=d,F.bend??={spec:d,range:z}}});for(let g of A.marks){if(g.kind==="slash"){if(!H.length)throw new ne("measure","A slash needs a written head",r(g.range));F.slash=!0}if(g.kind==="lyric"){let y={...g,range:r(g.range)};g.verse?(F.verses??=[]).push(y):F.lyric=y}if(g.kind==="harmony"){let{root:y,bass:I,quality:z}=g;F.harmony=xe.NotationSpelling.transposeChord({root:y,quality:z,bass:I},$?.semitones??0,$?.steps??0),F.chord={text:xe.NotationSpelling.chordText(F.harmony),range:r(g.range)}}if(g.kind==="stem"){if(!H.length)throw new ne("measure","A stem needs a written head",r(g.range));F.stem=g.value}if(g.kind==="dynamic"&&(F.dynamic=g.value),(g.kind==="ossia"||g.kind==="ornament"||g.kind==="grace")&&(!H.length||!W.notation&&g.kind!=="grace"||H.some(y=>!!y.drum)))throw new ne("measure","Grace notes, ornaments and ossias need a pitched notation anchor",r(g.range));if(g.kind==="ornament"&&(F.ornament=g.value),g.kind==="onStaff"||g.kind==="sharedStem"){if(!W.piano||g.kind==="sharedStem"&&!H.length)throw new ne("measure","Staff assignments need piano and a shared stem needs pitched notes",r(g.range));g.kind==="onStaff"?F.displayHand=g.hand==="upper"?"right":"left":F.sharedStem=g.name}if(g.kind==="grace"&&(F.grace=Q(g,$)),g.kind==="ossia"&&(F.ossia={duration:g.duration,notes:g.notes.map(y=>({key:q({pitch:y.pitch,range:g.range,marks:[]},$).written,ornament:y.ornament}))}),g.kind==="symbol"&&(F.chord={text:$?sr(g.text,$):g.text,color:g.ink&&_(g.ink,r(g.range)),range:r(g.range)}),g.kind==="line"){if(A.kind!=="rest")throw new ne("measure","Only a rest takes a staff line",r(g.range));F.restLine=g.value}if(g.kind==="ink"&&(F.color=_(g.value,r(g.range))),g.kind==="label"){let y=g.style;(F.labels??=[]).push({text:g.text,...y,range:r(g.range),ink:y.ink&&_(y.ink,r(g.range))})}if((g.kind==="tap"||g.kind==="vibrato"||"direction"in g)&&(F.gestures??=[]).push(g),g.kind==="accent"){if(!H.length)throw new ne("measure","Accent needs a head",r(g.range));(H[0].marks??=[]).push({position:"above"})}}let b=A.marks.find(g=>g.kind==="frame"||g.kind==="diagram");if(b?.kind==="frame"||b?.kind==="diagram"){let g=$?.semitones??0,y=b.frets.map(d=>d==="x"?d:d+g),I=b.barre,z=I&&I[0]+g!==0?" barre="+(I[0]+g)+":"+I[1]+"-"+I[2]:"",k=r(b.range);if(b.kind==="diagram"&&A.kind!=="attack"&&A.kind!=="rest")throw new ne("measure","Anchor the chord diagram to a note or rest",k);F.frame={range:k,spec:mr(y.join(",")+z,F,W,k,b.kind)}}return F}let se=new Map;function ie(A){return A.trace.flatMap(U=>"pattern"in U?["p"+U.range[0]]:"iteration"in U?["r"+U.range[0]+":"+U.iteration]:[]).join("/")}function ce(A,U,$){let H=U.find(z=>z.start),ee=U.find(z=>!z.start),F=U.find(z=>z!==H&&z!==ee);if(F)throw new ne("measure","Duplicate tie endpoint "+A,F.range);if(!H||!ee)throw new ne("measure","Unpaired tie "+A,(H??ee).range);let b=H.event.heads[H.index],g=ee.event.heads[ee.index];if(!(H.bar<ee.bar||H.bar===ee.bar&&new xe.Fraction().parse(H.event.onset).lessThan(new xe.Fraction().parse(ee.event.onset)))||b.sounding===null||b.written!==g.written||b.sounding!==g.sounding||b.position?.str!==g.position?.str||H.hand!==ee.hand)throw new ne("measure","Named tie needs a later matching head on the same staff",ee.range);let I="named-tie-"+A+($?"-"+H.event.id:"");T.ties.push({id:I,from:H.event.id,fromHead:H.index,to:ee.event.id,toHead:ee.index,...H.side&&{side:H.side},range:ee.range})}function ae(){for(let[A,U]of se){if(U.length<=2){ce(A,U,!1);continue}let $=new Map([["",[]]]),H=ee=>ee.slice(0,Math.max(0,ee.lastIndexOf("/")));for(let ee of U){for(let F=ee.scope;!$.has(F);F=H(F))$.set(F,[]);$.get(ee.scope).push(ee)}for(let ee of[...$.keys()].sort((F,b)=>b.length-F.length)){let F=$.get(ee);F.length&&(F.length===1&&ee?$.get(H(ee)).push(F[0]):ce(A,F,!0))}}}function O(A,U,$,H=[]){let ee=[],F={...s,...A.settings},b=0,g=$==="left"?"bass":s.clef??"treble",y=[],I=0;function z(R){R.key&&(v=R.key,x=new xe.KeyManager(v),W.key=L(o.transpose)?.target??v),R.clef&&(g=R.clef),R.sounds!==void 0&&(U=R.sounds)}let k,d;function p(R){for(;I<y.length&&!new xe.Fraction().parse(y[I].at).greaterThan(new xe.Fraction().parse(R.at));)z(y[I++]);let j=re(R,U);H.length&&(j.writtenClef=g,j.activeKey=W.key);for(let fe of R.marks){if(fe.kind!=="pedal")continue;let de=r(fe.range);if(!W.piano||R.kind==="skip")throw new ne("measure","Place pedal marks on piano notes or rests",de);if(fe.action==="down"){if(d)throw new ne("measure","Lift the pedal before pressing again",de);d=j}else{if(!d)throw new ne("measure","Pedal up needs an earlier pedal down in this voice",de);T.spans.push({kind:"pedal",...fe.onset&&{onset:!0},from:d.id,to:j.id,id:"pedal-"+d.id,range:de}),d=void 0}}let te=new Set;return R.heads.forEach((fe,de)=>{for(let we of fe.marks){if(we.kind!=="tieStart"&&we.kind!=="tieEnd")continue;let Ne=se.get(we.name)??[];Ne.length||se.set(we.name,Ne),Ne.push({event:j,index:de,bar:R.bar,hand:$,range:r(we.range),scope:ie(R),side:we.side,start:we.kind==="tieStart"})}let pe=j.heads[de].glissFrom;if(pe!==void 0){if(!k?.heads[pe])throw new ne("measure","Missing previous glissando head",j.heads[de].range);T.spans.push({kind:"glissando",id:"gliss-"+j.id+"-"+de,from:k.id,fromHead:pe,to:j.id,toHead:de,range:j.heads[de].range})}let ye=fe.marks.find(we=>we.kind==="tie");if(!ye)return;let ve=r(ye.range),Te=j.heads[de],Le=k?.heads.findIndex((we,Ne)=>!te.has(Ne)&&Te.sounding&&we.written===Te.written&&we.sounding===Te.sounding&&we.position?.str===Te.position?.str)??-1;if(Le<0)throw new ne("measure","Tie needs a matching preceding pitch and string",ve);te.add(Le),T.ties.push({id:"tie-"+j.id+"-"+de,from:k.id,fromHead:Le,to:j.id,toHead:de,range:ve})}),k=j,j}v=s.key??"C",x=new xe.KeyManager(v),W.key=L(o.transpose)?.target??v,W.tuning=M,h=new xe.Tuning(M),W.color=s.ink==="default"?void 0:s.ink;let E=s.displayMeter;for(let R of A.measures){s.keys?.[R.number]&&(v=s.keys[R.number],x=new xe.KeyManager(v),W.key=L(o.transpose)?.target??v);let j=r(R.barlineRange),te=s.changes?.[R.number];if(te?.tuning){if((xe.Tuning.names[te.tuning]??te.tuning).split(",").length!==W.strings)throw new ne("measure","A tuning change must keep the same string count",j);W.tuning=te.tuning,h=new xe.Tuning(te.tuning)}te?.ink&&(W.color=te.ink==="default"?void 0:_(te.ink,j)),te?.displayMeter!==void 0&&(E=te.displayMeter);let fe=R.span??(R.number===1&&o.pickup?o.pickup:S),de=R.meter??K;for(y=[],I=0;b<H.length&&H[b].bar===R.number;){let Je=H[b++];Je.at==="0/1"?z(Je):y.push(Je)}let pe=o.transpose?y.map(Je=>Je.key?{...Je,key:new yt(o.transpose,Je.key).target}:Je):y,ye={key:W.key,clef:g,changes:pe},ve={name:A.name,declaration:r(A.range),hand:$,span:fe,events:A.events.slice(R.start,R.end).map(p),tuplets:[],stem:F.stem,beams:F.beam??!0,flatBeams:F.flatBeams,beamRests:F.beamRests??!0,beatGroups:F.beatGroups,stemlets:F.stemlets??!1,middleRests:F.middleRests??!1,tabStems:F.tabStems??!1,rehearsal:R.rehearsal,opening:R.opening?{type:R.opening,range:j}:void 0,closing:R.closing?{type:R.closing,range:j}:void 0,tabDirection:F.tabDirection==="down"?-1:1},Te=C[R.number-2]?.state,Le=Te?.meter!==de||Te?.meterSign!==R.meterSign,we=C[R.number-1]??={number:R.number,range:j,state:{...W,key:ye.key,fragment:!!R.fragment,meter:de,meterSign:R.meterSign,timeRange:R.meterRange?r(R.meterRange):W.timeRange,showTime:E!==!1&&(R.number===1?E||W.showTime:Le||te?.displayMeter===!0)},span:fe,newRow:!!R.newRow,voices:[]};for(H.length&&((we.staffState??={})[$??"notation"]=ye);I<y.length;)z(y[I++]);we.newRow||=!!R.newRow;let Ne=we.voices[0];if(Ne){if(ve.rehearsal&&Ne.rehearsal&&ve.rehearsal!==Ne.rehearsal||ve.opening&&Ne.opening&&ve.opening.type!==Ne.opening.type||ve.closing&&Ne.closing&&ve.closing.type!==Ne.closing.type)throw new ne("measure","Voices disagree about a shared bar boundary",j);Ne.rehearsal??=ve.rehearsal,Ne.opening??=ve.opening,Ne.closing??=ve.closing}we.voices.push(ve),ee.push(ve)}if(d)throw new ne("measure","Missing pedal up",d.range);qs(ee,T.spans),G(A),ue(A,ee)}function G(A){for(let U of A.repeats??[]){let $=T.repeats?.find(b=>b.first===U.first&&b.bodyEnd===U.bodyEnd);if($&&$.count!==U.count)throw new ne("measure","Voices disagree about the repeat count",r(U.range));T.repeats?.some(b=>b.first===U.first&&b.bodyEnd===U.bodyEnd&&b.count===U.count&&b.endings.length===U.endings.length&&b.endings.every((g,y)=>g.last===U.endings[y].last))||(T.repeats??=[]).push(U);let H=r(U.range),ee=U.endings[U.endings.length-1]?.last??U.bodyEnd;if(C.slice(U.first-1,ee).some(b=>!b.voices[0].events.length))throw new ne("measure","An ending needs sounding or resting measures",H);let F=C[U.first-1].voices[0];if(F.opening={type:"repeat-begin",range:H},U.count){let b=C[U.bodyEnd-1].voices[0];b.closing={type:"repeat-end",range:H};let g=b.events[b.events.length-1],y="\xD7"+U.count;g.labels?.some(I=>I.text===y)||(g.labels??=[]).push({text:y,position:"above",range:H})}U.endings.forEach((b,g)=>{let y=C[b.last-1].voices[0];g<U.endings.length-1&&(y.closing={type:"repeat-end",range:H});let I=C[b.first-1].voices[0].events[0].id,z="ending-"+I,k=T.spans.find(d=>d.id===z);if(k){if(k.kind!=="volta"||k.lastBar!==b.last||k.label!==g+1+".")throw new ne("measure","Voices disagree about repeat endings",H)}else T.spans.push({kind:"volta",id:z,label:g+1+".",firstBar:b.first,lastBar:b.last,from:I,to:y.events[y.events.length-1].id,range:H})})}}function ue(A,U){let $=new Map(A.events.map((H,ee)=>[H.id,ee]));for(let H of A.spans){let ee=r(H.range);if(H.kind==="continuousBeam"||H.kind==="crescendo"||H.kind==="diminuendo"||H.kind==="tremolo"){if(!W.notation)throw new ne("measure","This expression span needs a notation staff",ee);if(T.spans.push({kind:H.kind,from:H.first,to:H.last,niente:H.niente,...H.side&&{side:H.side},strokes:H.strokes,range:ee,id:H.kind+"-"+H.first+(H.name?"-"+H.name:"")}),H.kind==="tremolo"||H.kind==="continuousBeam"){let F,b=$.get(H.last);for(let g=$.get(H.first);g<=b;g++){let y=A.events[g].bar-1,I=U[y],z=I.events[g-A.measures[y].start];if(H.kind==="tremolo")z.tremolo=H.strokes;else{if(z.displayHand&&z.displayHand!==I.hand)throw new ne("measure","A continuous beam must stay on its owning staff",ee);let k=z.heads[0]?.drum,d=z.stem??I.stem??(k&&X.instruments.find(p=>p.id===k)?.stem);if(d&&F&&d!==F)throw new ne("measure","Stems in a continuous beam must agree in direction",ee);d&&(F=d),z.continuousBeam=!0}}}}else if(H.kind==="slur"||H.kind==="palmMute"){if(H.kind==="palmMute"&&H.strings.some(F=>F>W.strings))throw new ne("measure","Mute outside the instrument tuning",ee);T.spans.push({kind:H.kind,from:H.first,to:H.last,side:H.side,strings:H.strings,range:ee,id:H.kind+"-"+H.first+(H.name?"-"+H.name:"")})}else if(H.kind==="beam"||H.kind==="feather"){let F=$.get(H.first),b=$.get(H.last),g=A.measures[A.events[F].bar-1];(U[g.number-1].beamGroups??=[]).push({start:F-g.start,end:b-g.start,feather:H.kind==="feather"?H.feather:void 0,range:ee})}else if("to"in H)T.spans.push({kind:H.kind,id:H.kind+"-"+H.to.event+"-"+H.to.head,range:ee,from:H.from.event,to:H.to.event,fromHead:H.from.head,toHead:H.to.head});else if(H.kind==="tuplet"){let F=$.get(H.first),b=$.get(H.last),[g,y]=H.ratio.split(":").map(Number);for(let I=F;I<=b;){let z=A.measures[A.events[I].bar-1],k=Math.min(z.end,b+1);U[z.number-1].tuplets.push({start:I-z.start,count:k-I,numNotes:g,notesOccupied:y,range:ee}),I=k}}}}for(let A of s.staves)for(let U of A.voices)O(U,A.sounds??s.sounds,A.name==="upper"?"right":A.name==="lower"?"left":void 0,A.staffChanges);ae();let le=new Map(C.flatMap(A=>A.voices.flatMap(U=>U.events.map($=>[$.id,$]))));for(let A of T.ties){let U=le.get(A.from).heads[A.fromHead],$=le.get(A.to).heads[A.toHead];if($.release){if(!U.bend||U.bend.release||!$.position||U.position.str!==$.position.str)throw new ne("measure","A tied release needs a bent source on the same string",$.range);U.tiedBendStart=!0,A.bend={semitones:U.bend.semitones,rise:U.bend.rise,hold:$.release.hold,release:$.release.release},A.string=$.position.str}}for(let A of le.values())for(let[U,$]of A.heads.entries())if($.release&&!T.ties.some(H=>H.to===A.id&&H.toHead===U&&H.bend))throw new ne("measure","A release needs a tied continuation",$.range);An(C,T.spans);for(let[A,U]of(s.text??[]).entries()){let $={line:-A*2,...U.style};$.ink&&_($.ink,r(U.voice.range));for(let H of U.voice.measures){let ee=C[H.number-1],F=U.voice.events.slice(H.start,H.end).map(b=>{let g=b.marks.find(y=>y.kind==="text");return{id:b.id,range:r(b.range),...Us(b.writtenDuration),text:g?.text??"",glyph:g?.glyph,style:{...$,...g?.style}}});for(let b of U.voice.boundaries??[]){if(b.bar!==H.number)continue;let g=b.edge==="start"?F[0]:F[F.length-1];if(!g)throw new ne("measure","A text boundary needs a timed anchor",r(b.range));(g.boundaries??=[]).push({...b,range:r(b.range)})}for(let b of F)b.style.ink&&_(b.style.ink,b.range);(ee.text??=[]).push(F)}}return n.set(e,T),T}var lo="http://www.w3.org/2000/svg";var uo=0;function ft(o,e={}){let n=document.createElementNS(lo,o);for(let[t,s]of Object.entries(e))n.setAttribute(t,String(s));return n}var Zt=class{constructor(e,n,t,s){this.surface=e;this.music=n;this.follow=s;this.layer=ft("g",{class:"vextab-playback-ink","pointer-events":"none","aria-hidden":"true"});this.bar=ft("line",{stroke:"#a8a8a8","stroke-opacity":.55,"stroke-width":3.5,"stroke-linecap":"round"});this.gradient="vextab-glow-"+ ++uo;this.dots=[];this.anchors=[];this.pulses=[];this.active=[];this.anchor=0;this.pulse=0;this.frame=0;this.pages=new Map;this.printedRows=new Map;let r=ft("radialGradient",{id:this.gradient});for(let[i,c]of[[0,.5],[.32,.72],[.52,.6],[.76,.22],[1,0]])r.append(ft("stop",{offset:i,"stop-color":"currentColor","stop-opacity":c}));let a=ft("defs");a.append(r),this.layer.append(a,this.bar);for(let i of n.events){let c=t.get(i.source);if(!c)continue;let{x:l,row:u,heads:f}=c,m=this.anchors[this.anchors.length-1];(!m||Math.abs(m.time-i.time)>1e-6)&&this.anchors.push({time:i.time,x:l,row:u,slope:0,speed:0}),f.length&&this.pulses.push({time:i.time,end:i.time+i.duration,heads:f,row:u})}this.anchors.forEach((i,c)=>{let l=this.anchors[c+1],u=(l?.row===i.row?l.x:i.row.right)-i.x,f=(l?.time??n.duration)-i.time;i.slope=f>0?u/f:0;let m=this.anchors[c-1];i.speed=i.slope,m?.row===i.row&&(i.speed=m.slope*i.slope>0?2/(1/m.slope+1/i.slope):0)})}rowLayer(e){let n=e.printedPage;if(!n)return this.layer.parentNode||this.surface?.append(this.layer),this.layer;let t=this.printedRows.get(e);if(t)return t;let s=this.pages.get(n);if(!s){let a=document.createElement("div");a.className="vextab-playback-page",n.before(a),s=ft("svg",{"aria-hidden":"true",class:"vextab-playback-paper"});for(let i of["viewBox","width","height","preserveAspectRatio"])n.hasAttribute(i)&&s.setAttribute(i,n.getAttribute(i));s.style.cssText="pointer-events:none;background:transparent;border-color:transparent",a.append(n,s),this.pages.set(n,s),this.layer.parentNode||s.append(this.layer)}let r=ft("g",{transform:"scale("+e.scale+")",class:"vextab-playback-ink","pointer-events":"none"});return s.append(r),this.printedRows.set(e,r),r}moveToRow(e){this.rowLayer(e).prepend(this.bar),this.bar.setAttribute("y1",String(e.top)),this.bar.setAttribute("y2",String(e.bottom)),this.row=e}start(e){if(!this.anchors.length)return;let n=()=>{let t=e();for(;this.anchor+1<this.anchors.length&&this.anchors[this.anchor+1].time<=t;)this.anchor++;let s=this.anchors[this.anchor],r=s.row!==this.row;r&&this.moveToRow(s.row),this.drawBar(t,s,this.anchors[this.anchor+1]),this.follow?.(this.bar,r),this.drawHeads(t),this.frame=requestAnimationFrame(n)};n()}drawBar(e,n,t){let s=t?.row===n.row,r=(s?t.x:n.row.right)-n.x,a=(t?.time??this.music.duration)-n.time,i=a>0?Math.max(0,Math.min(1,(e-n.time)/a)):0,c=s?t.speed:n.slope,l=(1-i)*(n.speed*a-r)+i*(r-c*a),u=n.x+i*r+i*(1-i)*l;this.bar.setAttribute("transform","translate("+u+" 0)")}drawHeads(e){for(;this.pulse<this.pulses.length&&this.pulses[this.pulse].time<=e+.075;)this.active.push(this.pulses[this.pulse++]);let n=0,t=0;for(let s of this.active){if(s.end<=e)continue;this.active[n++]=s;let r=s.end-s.time,a=Math.min(.075,r/2),i=Math.min(.14,r/2),c=Math.min(1,(e-s.time+a)/a,(s.end-e)/i);if(c>0)for(let l of s.heads)this.drawDot(t++,l,c,s.row)}this.active.length=n;for(let s=t;s<this.dots.length;s++){let r=this.dots[s];r.opacity!==0&&r.node.setAttribute("opacity","0"),r.opacity=0}}drawDot(e,n,t,s){let r=this.dots[e];if(r||(r={node:ft("ellipse",{rx:17,ry:13,fill:"url(#"+this.gradient+")",stroke:"none"})},this.dots.push(r)),r.point!==n){let a=this.rowLayer(s);r.node.parentNode!==a&&a.append(r.node),r.node.setAttribute("cx",String(n.x)),r.node.setAttribute("cy",String(n.y)),r.point=n}r.opacity!==t&&r.node.setAttribute("opacity",String(t)),r.opacity=t}stop(){cancelAnimationFrame(this.frame),this.layer.remove();for(let[e,n]of this.pages)n.parentElement?.replaceWith(e)}};var Ht=new WeakMap;function Cn(o){return{top:Math.min(...o.map(e=>e.getYForLine(0)))-7,bottom:Math.max(...o.map(e=>e.getYForLine(e.getNumLines()-1)))+7,right:Math.max(...o.map(e=>e.getNoteEndX()))}}function fo(o,e,n){let t=[],s=e[0].getAbsoluteX();for(let r of e){if(r.isRest()||!n.some(Boolean))continue;let a=r.getYs(),i="getHeadInk"in r?r.getHeadInk():[];for(let c=0;c<a.length;c++){let l=i[c]?i[c].x+i[c].w/2:r.getAbsoluteX();c===0&&r===e[0]&&(s=l),n[c]&&t.push({x:l,y:a[c]})}}return{row:o,x:s,heads:t}}function Xs(o){let e=new Map;for(let n of o.staves){let t=[n.note,n.tab].filter(Boolean);if(!t.length)continue;let s=Cn(t);(n.note?n.note_voices:n.tab_voices).forEach((a,i)=>a.forEach((c,l)=>{if(c.shouldIgnoreTicks())return;let u=n.note&&n.tab&&n.tab_voices[i]?.[l],f=u&&!u.shouldIgnoreTicks()?[c,u]:[c],m=(rt.get(c)??[]).map(h=>/^[a-g]/i.test(h.key));e.set(c,fo(s,f,m))}))}return e}function Ys(o,e,n,t){let s=new Map,r=new Map;for(let a of n){let{measure:i}=a[1];r.has(i)||r.set(i,[]),r.get(i).push(a)}for(let a of o.pages){for(let i of a.systems){let c=a.svg.querySelector('[data-system="'+i.measures[0]+'"] > g:last-child'),l=i.y/t+(c?.transform.baseVal[0]?.matrix.f??0),u=i.x/t,f;for(let m of i.measures)for(let[h,w]of r.get(m)??[])f??={top:l+w.row.top,bottom:l+w.row.bottom,right:u+w.row.right,printedPage:a.svg,scale:t},s.set(h,{row:f,x:u+w.x,heads:[]})}for(let i of a.heads.occurrences){if(i.reference||i.role==="mark")continue;let c=e.get(i.sourceEvent),l=s.get(i.sourceEvent);if(!c||!l||typeof i.sourceHead!="number")continue;let u=c.heads[i.sourceHead];if(c.silent||!u||!u.sounding&&u.midi===void 0)continue;let f=i.bounds,m={x:(f.x+f.w/2)/t,y:(f.y+f.h/2)/t};l.heads.length||(l.x=m.x),l.heads.push(m)}}return s}function it(o,e){let n=o^Math.imul(e+1,2654435761),t=0;for(let s=0;s<4;s++){n=n+1831565813|0;let r=Math.imul(n^n>>>15,1|n);r^=r+Math.imul(r^r>>>7,61|r),t+=((r^r>>>14)>>>0)/4294967296}return(t-2)/2}function mo(o,e,n){if(!Number.isFinite(n)||n<=0||!Number.isFinite(e)||e<0)throw new RangeError("Invalid playback time or tempo");let t=[...o],s=0,r=0;for(let c of t){if(!(c.duration>0&&Number.isFinite(c.duration)&&c.quarter>0&&Number.isFinite(c.quarter))||!((c.beatOffset??0)>=0&&(c.beatOffset??0)<c.quarter))throw new RangeError("Invalid performance bar");if(s+=c.duration,c.endingQuarter!==void 0&&!(c.endingQuarter>0&&Number.isFinite(c.endingQuarter)))throw new RangeError("Invalid final quarter duration");if(c.beats){let l=0;for(let u of c.beats){if(!(u.end>l&&Number.isFinite(u.end))||u.eighth!==void 0&&!(u.eighth>l&&u.eighth<u.end))throw new RangeError("Invalid written beat grid");l=u.end}if(!c.beats.length||Math.abs(l-c.duration)>1e-9)throw new RangeError("Incomplete written beat grid");r+=c.beats.length}else r+=Math.ceil((c.duration+(c.beatOffset??0))/c.quarter)}let a=t[t.length-1],i=a?.endingQuarter??a?.quarter??60/n;if(r+Math.ceil(Math.max(0,e-s)/i)>1e6)throw new RangeError("Performance exceeds one million beats");for(;s<e-1e-9;){let c=Math.min(4*i,e-s);if(s+c<=s)throw new RangeError("Beat is below clock precision");t.push({quarter:i,duration:c}),s+=c}return t}function po(o,e,n,t){let s=[],r=0,a=0,i=0;for(let c=0;c<o.length;){let l=c;for(;l+1<o.length&&l-c<3&&!o[l].phraseEnd;)l++;let u=r,f=o.slice(c,l+1).reduce((m,h)=>m+h.duration,0);for(let m=c;m<=l;m++){let h=o[m],w=r+h.duration,v=r,x=0,P=h.quarter-(h.beatOffset??0);for(;r<w-1e-9;){let B=h.beats?.[x++],D=B?v+B.end:Math.min(r+P,w),_=D-r;if(_<=0)throw new RangeError("Beat is below clock precision");let M=(r+_/2-u)/f,V=-Math.cos(2*Math.PI*M);i=.55*i+.45*it(n,s.length);let K=!t&&h.fermatas?.some(S=>S>r-v+1e-9&&S<=D-v+1e-9),Y=_*(1-e.rubato*V+e.drift*i+(K?.35:0)),W=h.swingable!==!1&&(B?B.eighth!==void 0:Math.abs(_/h.quarter-1)<1e-6),C=B?.eighth===void 0?.5:(B.eighth-(r-v))/_,T=60/(B?_:h.quarter),X=W?e.swing*Math.max(0,Math.min(.22,.25-(T-60)/750)):0;s.push({start:r,end:D,played:a,length:Y,velocity:V*e.swell,swing:X,fullBeat:W,middle:C}),r=D,a+=Y,P=h.quarter}r=w}c=l+1}return s}function br(o,e){let n=0,t=o.length-1;for(;n<t;){let s=n+t>>>1;e>=o[s].end-1e-9?n=s+1:t=s}return n}function ho(o,e){let n=new Set;for(let t of o)for(let s of[t.time,t.time+t.duration]){let r=br(e,s),a=e[r],i=(s-a.start)/(a.end-a.start);i>1e-6&&i<1-1e-6&&Math.abs(i-a.middle)>1e-6&&n.add(r)}return n}function go(o,e,n,t){let s=n[n.length-1],r=t.swing||t.pocket?ho(o.events,n):new Set;function a(c){return e||!c||c===n.length||!n[c].fullBeat||!n[c-1].fullBeat||r.has(c)||r.has(c-1)?0:t.pocket*Math.min(n[c].length,n[c-1].length)}function i(c){if(c>=s.end)return s.played+s.length+(c-s.end);let l=br(n,c),u=n[l],f=Math.max(0,(c-u.start)/(u.end-u.start)),m=u.played+a(l),h=u.played+u.length*(u.middle+(r.has(l)?0:2*(1-u.middle)*u.swing)),w=u.played+u.length+a(l+1);return f<u.middle?m+f/u.middle*(h-m):h+(f-u.middle)/(1-u.middle)*(w-h)}return i}function bo(o,e,n,t){if(o.length<2||!n||o.some(f=>f.onsetOffset))return;let s=Math.min(...o.map(f=>f.pitch)),r=Math.max(...o.map(f=>f.pitch)),a=it(t,0),i=o.map((f,m)=>{let h=(f.pitch-s)/Math.max(1,r-s),w=t^Math.imul(f.pitch+1,617)^m;return{note:f,finger:w,landing:a*h+it(w,1)}}).sort((f,m)=>f.landing-m.landing),c=Math.min(e,...o.map(f=>f.duration));if(c<=0)return;let l=Math.min(c*.12,n*(.78+.22*it(t,2))),u=Math.min(1,n/.013);i.forEach(({note:f,finger:m},h)=>{let w=h/(i.length-1),v=h>0&&h<i.length-1?.32*it(m,3)/(i.length-1):0,x=l*(w+v),P=f.pitch===r?.042:f.pitch===s?-.012:-.085,B=1+u*(P+.052*it(m,4));f.fixedVelocity||(f.velocity=Math.max(1,Math.min(127,Math.round(f.velocity*B)))),x&&(f.onsetOffset=x);let D=0;!f.holdRelease&&!f.bend&&f.duration<=e+1e-9&&(D=Math.min(n*1.8,f.duration*.09)*Math.max(0,.56+.4*it(m,5)-(f.pitch===r?.23:0))),f.duration-=x+D,x&&f.bend&&(f.bend=f.bend.map(_=>({..._,time:Math.max(0,_.time-x)})))})}function yo(o,e,n,t,s){let r=go(o,e,n,t);return{events:o.events.map((i,c)=>{let l=r(i.time),u=r(i.time+i.duration)-l,f=n[br(n,i.time)],m=t.touch*it(s^e+1,Math.round(i.time*1e5)),h=(i.time-f.start)/(f.end-f.start),w=f.fullBeat?t.beatAccent*Math.cos(2*Math.PI*h):0,v=1+(f.velocity+m+w)/100,x=i.notes.map(P=>{let B=i.time+(P.onsetOffset??0),D=r(B),_=M=>r(B+M)-D;return{...P,duration:_(P.duration),...P.onsetOffset&&{onsetOffset:D-l},velocity:P.fixedVelocity?P.velocity:Math.max(1,Math.min(127,Math.round(P.velocity*v))),...P.bend&&{bend:P.bend.map(M=>({...M,time:_(M.time)}))}}});return bo(x,u,t.chordSpread??0,s^Math.imul(e+1,65537)^Math.imul(c+1,16777619)),{...i,time:l,duration:u,notes:x}}),duration:r(o.duration)}}function xo(o){if(typeof o=="string"){if(!xt(o))throw new RangeError("Unknown performer: "+o);return Xt[o]}let e={rubato:[0,.4],drift:[0,.25],swell:[0,32],touch:[0,32],swing:[0,1],beatAccent:[-32,32],pocket:[-.15,.15],grace:[.05,.4],chordSpread:[0,.03]};for(let n of Object.keys(e)){let t=n==="chordSpread"&&o[n]===void 0?0:o[n],[s,r]=e[n];if(!Number.isFinite(t)||t<s||t>r)throw new RangeError("Invalid performer "+n)}return{...o}}function yr(o="human",e,n){let t=xo(o),s=n==="off"?{...t,swing:0,pocket:0}:n==="eighths"?{...t,swing:t.swing||1}:t,r=o==="robot"||o===Xt.robot;if(e!==void 0&&!Number.isSafeInteger(e))throw new RangeError("Expected an integer performer seed");let a=e??(r?0:Math.floor(Math.random()*4294967296));return{literal:r,needsBeatGrid:!r||!!s.swing,graceFraction(i,c,l,u=!1){if(r)return .25;let f=(u?.065:.105)*Math.sqrt(l);return Math.min(s.grace,f/c)*(1+.24*it(a,Math.round(i*1e5)))},perform(i,c=[],l=120){if(r&&!s.swing||!i.length)return i;let u=Math.max(...i.map(m=>m.duration)),f=po(mo(c,u,l),s,a,r);return f.length?i.map((m,h)=>yo(m,h,f,s,a)):i}}}function vo(o){let e=[];for(let n=o.parentElement;n&&n!==document.scrollingElement;n=n.parentElement){if(!(n instanceof HTMLElement))continue;let t=getComputedStyle(n),s=/^(auto|scroll|overlay)$/.test(t.overflowX),r=/^(auto|scroll|overlay)$/.test(t.overflowY);(s||r)&&e.push({element:n,x:s,y:r})}return e.push({element:document.scrollingElement,x:!0,y:!0}),e}function Js(o,e,n,t){return e-o>=t-n||o<n?o-n:Math.max(0,e-t)}var In=class{constructor(){this.ports=[];this.reducedMotion=matchMedia("(prefers-reduced-motion: reduce)");this.lastFrame=0;this.nextCheck=0}update(e,n){let t=performance.now();if(!n&&t<this.nextCheck)return;(n||!this.ports.length)&&(this.ports=vo(e));let s=Math.min(40,this.lastFrame?t-this.lastFrame:16),r=this.reducedMotion.matches?1:1-Math.exp(-s/65);this.lastFrame=t;let a=e.getBoundingClientRect(),{left:i,right:c,top:l,bottom:u}=a,f=!1;for(let{element:m,x:h,y:w}of this.ports){let v=m===document.scrollingElement,x=v?void 0:m.getBoundingClientRect(),P=x?x.width/(m.offsetWidth||1):1,B=x?x.height/(m.offsetHeight||1):1;if(!P||!B)continue;let D=window.visualViewport,_=x?x.left+m.clientLeft*P:D?.offsetLeft??0,M=x?x.top+m.clientTop*B:D?.offsetTop??0,V=v?D?.width??m.clientWidth:m.clientWidth*P,K=v?D?.height??m.clientHeight:m.clientHeight*B,Y=h?Js(i,c,_+12,_+V-12)/P:0,W=Math.min(68,K*.12),C=w?Js(l,u,M+W,M+K-W)/B:0,T=Math.max(0,Math.min(m.scrollWidth-m.clientWidth,m.scrollLeft+Y)),X=Math.max(0,Math.min(m.scrollHeight-m.clientHeight,m.scrollTop+C)),S=T-m.scrollLeft,N=X-m.scrollTop;if(Math.abs(S)>=1||Math.abs(N)>=1){f=!0;let L=q=>Math.sign(q)*Math.min(Math.abs(q),Math.max(1,Math.abs(q)*r));m.scrollBy({left:L(S),top:L(N),behavior:"instant"})}i-=S*P,c-=S*P,l-=N*B,u-=N*B}this.nextCheck=f?t:t+120}};function wo(o){let e=[];for(let n=o.parentElement;n&&n!==document.documentElement;n=n.parentElement){let t=getComputedStyle(n),s=t.overflowX!=="visible",r=t.overflowY!=="visible";(s||r)&&e.push({element:n,x:s,y:r})}return e}function $s(o,e,n,t,{size:s,inset:r}){let a=wo(o),i=t.querySelector(".vextab-control-panel"),c=window.visualViewport,l=0,u,f=!1;function m(){l=0;let P=e.getBoundingClientRect(),B=n.getBoundingClientRect();if(f&&(!u||P.left!==u.left||P.top!==u.top||P.right!==u.right||P.bottom!==u.bottom)&&h(),u=P,!B.width||!B.height)return;let D=n.offsetWidth/B.width,_=n.offsetHeight/B.height,M=c?.offsetLeft??0,V=c?.offsetTop??0,K=Math.max(P.left,M),Y=Math.max(P.top,V),W=c?.width??document.documentElement.clientWidth,C=c?.height??document.documentElement.clientHeight,T=Math.min(P.right,M+W),X=Math.min(P.bottom,V+C),S=P.height>=C*.8||P.width>W+1;for(let{element:Q,x:re,y:se}of a){let ie=Q.getBoundingClientRect(),ce=ie.width/(Q.offsetWidth||1),ae=ie.height/(Q.offsetHeight||1),O=ie.left+Q.clientLeft*ce,G=ie.top+Q.clientTop*ae;(re&&P.width>Q.clientWidth*ce+1||se&&P.height>Q.clientHeight*ae+1)&&(S=!0),re&&(K=Math.max(K,O),T=Math.min(T,O+Q.clientWidth*ce)),se&&(Y=Math.max(Y,G),X=Math.min(X,G+Q.clientHeight*ae))}if(T<=K||X<=Y){t.style.inset="0";return}let N=s==="auto"?S?"large":"mini":s;t.dataset.size!==N&&(t.dataset.size=N);let L=Math.min(r,Math.max(0,((T-K)*D-i.offsetWidth)/2)),q=Math.min(r,Math.max(0,((X-Y)*_-i.offsetHeight)/2));t.style.padding=q+"px "+L+"px",t.style.setProperty("--control-y-inset",q+"px"),t.style.inset=[(Y-B.top)*_,(B.right-T)*D,(B.bottom-X)*_,(K-B.left)*D].map(Q=>Q+"px").join(" ")}function h(){l||(l=requestAnimationFrame(m))}let w,v=new IntersectionObserver(P=>{if(f=P[P.length-1].isIntersecting,f){if(u=void 0,!w){w=new AbortController;let B={signal:w.signal,passive:!0};document.addEventListener("scroll",h,{...B,capture:!0}),window.addEventListener("resize",h,B),c?.addEventListener("scroll",h,B),c?.addEventListener("resize",h,B)}h()}else w?.abort(),w=void 0,t.style.inset="0"},{threshold:[0,.25,.5,.75,1]}),x=new ResizeObserver(h);for(let P of[o,...a.map(B=>B.element)])x.observe(P);return v.observe(e),m(),()=>{w?.abort(),v.disconnect(),x.disconnect(),cancelAnimationFrame(l)}}var Zs="http://www.w3.org/2000/svg",Qs=3e3;function Qt(o,e,n){let t=document.createElement("button");return t.type="button",t.className=e,t.setAttribute("aria-label",o),t.title=o,t.onclick=n,t}var Bn=class{constructor(e,n,t,s,r,a,i,c,l){this.root=document.createElement("div");this.status=document.createElement("span");this.listeners=new AbortController;this.hideAt=0;if(this.root.className=`vextab-transport ${n}`,this.controls=document.createElement(l?"span":"div"),this.controls.className=l?"vextab-playback-controls":"vextab-sheet-controls",this.status.setAttribute("role","status"),t)if(this.toggle=Qt("Play","vextab-play",()=>this.toggle.classList.contains("vextab-stop")?r():s()),this.setButton(!1),l)this.controls.append(this.toggle);else{let u=document.createElement("div");u.className="vextab-control-panel",u.setAttribute("role","group"),u.setAttribute("aria-label","Playback"),this.scrollButton=Qt("Auto-scroll","vextab-auto-scroll",()=>this.setFollowing(!this.follower)),this.setFollowing(c.size!=="mini"),u.append(this.toggle,this.addTempo(i),this.scrollButton),this.controls.append(u),this.controls.dataset.position=c.position,this.controls.dataset.visibility=c.visibility,this.controls.style.setProperty("--control-inset",c.inset+"px")}this.setTempo(a),this.controls.append(this.status),(l??this.root).append(t||l?this.controls:this.status),e instanceof SVGSVGElement&&(this.surface=e),e&&(!l||e instanceof HTMLCanvasElement)&&this.mountSheet(e,t&&!l,c)}setFollowing(e){this.follower=e?new In:void 0,this.scrollButton.setAttribute("aria-pressed",String(e))}followSystem(e,n){this.controls.dataset.size==="large"&&this.follower?.update(e,n)}mountSheet(e,n,t){let s=this.sheet=document.createElement("div");if(s.className="vextab-sheet",e.before(s),s.append(e,this.root),e instanceof HTMLCanvasElement){let r=document.createElementNS(Zs,"svg");r.setAttribute("viewBox",`0 0 ${e.width} ${e.height}`),r.setAttribute("preserveAspectRatio","none"),r.setAttribute("aria-hidden","true"),r.classList.add("vextab-canvas-ink"),this.surface=document.createElementNS(Zs,"g"),this.surface.setAttribute("transform",e.getContext("2d").getTransform().toString()),r.append(this.surface),this.root.prepend(r)}if(n){if(this.controls.addEventListener("click",r=>r.stopPropagation(),{signal:this.listeners.signal}),this.controls.dataset.visibility==="hover"){let r=()=>this.reveal();r();for(let a of["pointerenter","pointermove","pointerdown"])s.addEventListener(a,r,{passive:!0,signal:this.listeners.signal})}this.untrack=$s(s,e,this.root,this.controls,t)}}reveal(){if(this.hideAt=performance.now()+Qs,this.revealTimer!==void 0)return;this.controls.setAttribute("data-visible","");let e=()=>{let n=this.hideAt-performance.now();if(n>0){this.revealTimer=window.setTimeout(e,n);return}this.revealTimer=void 0,this.dismissHoverTempo?.(),this.controls.removeAttribute("data-visible")};this.revealTimer=window.setTimeout(e,Qs)}addTempo(e){let n=document.createElement("div");n.className="vextab-tempo";let t=document.createElement("div");t.className="vextab-tempo-stepper";let s=i=>{n.contains(i.target)||r(!1)},r=(i,c=!1)=>{this.dismissHoverTempo=i&&c?()=>{n.querySelector(":focus-visible")||r(!1)}:void 0,i?document.addEventListener("pointerdown",s,{signal:this.listeners.signal}):document.removeEventListener("pointerdown",s),t.inert=!i,this.metronome.setAttribute("aria-expanded",String(i))};this.metronome=Qt("Adjust tempo","vextab-metronome",()=>r(t.inert)),this.decrease=Qt("Decrease tempo","vextab-step",()=>e(Math.max(1,this.tempo-5))),this.decrease.textContent="\u2212";let a=Qt("Increase tempo","vextab-step",()=>e(this.tempo+5));return a.textContent="+",this.readout=document.createElement("span"),this.readout.className="vextab-bpm",this.readout.setAttribute("aria-live","polite"),t.append(this.decrease,this.readout,a),n.append(this.metronome,t),r(!1),n.onpointerenter=i=>{i.pointerType==="mouse"&&t.inert&&r(!0,!0)},n.onpointerleave=i=>{i.pointerType==="mouse"&&!n.querySelector(":focus-visible")&&r(!1)},n.addEventListener("focusout",i=>{n.contains(i.relatedTarget)||r(!1)}),n.onkeydown=i=>{i.key==="Escape"&&(this.metronome.focus(),r(!1))},n}setTempo(e){this.tempo=e,this.readout&&(this.readout.textContent=e+" BPM",this.metronome.setAttribute("aria-description",this.readout.textContent),this.decrease.disabled=e<=1)}setStatus(e){this.status.textContent=e}setPlaying(e){this.root.toggleAttribute("data-playing",e),this.setButton(e),e||(this.marker?.remove(),this.marker=void 0)}setButton(e){if(!this.toggle)return;let n=e?"Stop":"Play";this.controls.classList.contains("vextab-playback-controls")&&(this.toggle.textContent=n),this.toggle.title=n,this.toggle.setAttribute("aria-label",n),this.toggle.className=e?"vextab-stop":"vextab-play"}moveCursor(e,n){this.surface&&(this.marker||(this.marker=document.createElementNS("http://www.w3.org/2000/svg","circle"),this.marker.setAttribute("r","6"),this.marker.classList.add("vextab-playback-marker"),this.marker.setAttribute("fill","currentColor"),this.marker.setAttribute("opacity",".45"),this.marker.setAttribute("pointer-events","none"),this.surface.append(this.marker)),this.marker.setAttribute("cx",String(e)),this.marker.setAttribute("cy",String(n)))}remove(){this.untrack?.(),this.listeners.abort(),window.clearTimeout(this.revealTimer),this.marker?.remove(),this.controls.remove(),this.root.remove(),this.sheet&&this.sheet.replaceWith(...this.sheet.childNodes)}};function ei(o,e){return{async open(n,t){let s=new Map,r=!1;function a(){r=!0,s.forEach(i=>i.stop()),s.clear()}t.addEventListener("abort",a,{once:!0});try{return await Promise.all([...new Set(e)].map(async i=>{let c=await o.open(i,t);r||t.aborted?c.stop():s.set(i,c)})),{get currentTime(){return s.values().next().value?.currentTime},playNote(i){s.get(i.program??n)?.playNote(i)},stop:a}}catch(i){throw a(),i}}}}function ko(o){if(!o.some(n=>n.notes.some(t=>t.onsetOffset)))return o;let e=[];for(let n of o){let t=[];e.push({time:n.time,notes:t,mark:n.mark});for(let s of n.notes){if(!s.onsetOffset){t.push(s);continue}let{onsetOffset:r,...a}=s;e.push({time:n.time+r,notes:[a]})}}return e.sort((n,t)=>n.time-t.time)}var Fn=class{constructor(){this.rate=1}setRate(e){this.retime?this.retime(e):this.rate=e}get active(){return!!this.request}play(e,n,t,s,r=0){this.stop();let a=this.request=new AbortController;return globalThis.addEventListener?.("pagehide",()=>this.stop(),{capture:!0,signal:a.signal}),new Promise((i,c)=>{a.signal.addEventListener("abort",()=>i(),{once:!0});let l=f=>{a.signal.aborted||(c(f),this.stop())},u=f=>{if(a.signal.aborted){f.stop();return}this.session=f;let m=()=>f.currentTime??performance.now()/1e3,h=ko(t.events),w=m(),v=-r,x=()=>v+(m()-w)*this.rate,P=0,B=()=>{if(!a.signal.aborted)try{let D=x();for(;P<h.length&&h[P].time<=D;){let M=h[P++];M.mark?.();for(let V of M.notes)M.time+V.duration>D&&f.playNote(So(V,this.rate))}if(P===h.length&&D>=t.duration){this.stop();return}let _=h[P]?.time??t.duration;this.timer=window.setTimeout(B,Math.max(1,(_-x())/this.rate*1e3))}catch(D){l(D)}};this.retime=D=>{v=x(),w=m(),this.rate=D,window.clearTimeout(this.timer),B()},s(x),B()};try{let f=e.open(n,a.signal);"playNote"in f?u(f):f.then(u).catch(l)}catch(f){l(f)}})}stop(){this.retime=void 0,this.rate=1,this.request?.abort(),this.request=void 0,window.clearTimeout(this.timer),this.timer=void 0;let e=this.session;this.session=void 0,e?.stop()}};function So(o,e){return e===1?o:{...o,duration:o.duration/e,bend:o.bend?.map(n=>({...n,time:n.time/e}))}}function mt(o){async function e(n,t){let s=o??new AudioContext,r=new Set,a=!1;function i(){if(!a){a=!0;for(let l of r)l.stop();!o&&s instanceof AudioContext&&s.state!=="closed"&&s.close(),t.removeEventListener("abort",i)}}t.addEventListener("abort",i,{once:!0});try{s instanceof AudioContext&&s.state!=="running"&&await s.resume(),t.throwIfAborted()}catch(l){throw i(),l}function c(l){let u=s.currentTime,f=u+l.duration,m=s.createOscillator(),h=s.createGain();m.type=n>=72&&n<=79?"sine":"triangle",m.frequency.value=440*2**((l.pitch-69)/12),m.detune.setValueAtTime(0,u);for(let w of l.bend??[])m.detune.linearRampToValueAtTime(w.semitones*100,u+w.time);h.gain.setValueAtTime(0,u),h.gain.linearRampToValueAtTime(l.velocity/127*.12,u+Math.min(.006,l.duration/3)),h.gain.exponentialRampToValueAtTime(.001,f),m.connect(h).connect(s.destination),r.add(m),m.onended=()=>{r.delete(m),m.disconnect(),h.disconnect()},m.start(u),m.stop(f)}return{playNote:c,stop:i,get currentTime(){return s.currentTime}}}return{open:e}}function ti(o,e,n,t=!0){return{open(s,r){function a(){return r.throwIfAborted(),MIDI.programChange(0,s),{playNote(i){MIDI.noteOn(0,i.pitch,t&&!i.fixedVelocity?127:i.velocity,0),MIDI.noteOff(0,i.pitch,i.duration)},stop(){}}}return n[o]?a():new Promise((i,c)=>{MIDI.loadPlugin({instruments:[o],soundfontUrl:e,onerror:c,callback(){n[o]=!0;try{i(a())}catch(l){c(l)}}})})}}}var Mo={acoustic_grand_piano:0,acoustic_guitar_nylon:24,acoustic_guitar_steel:25,electric_guitar_jazz:26,distortion_guitar:30,electric_bass_finger:33,electric_bass_pick:34,trumpet:56,brass_section:61,soprano_sax:64,alto_sax:65,tenor_sax:66,baritone_sax:67,flute:73,synth_drum:118};function ni(o){let e=/^\d+$/.test(String(o))?Number(o):Mo[o];if(!Number.isInteger(e)||e<0||e>127)throw new RangeError("Invalid instrument: "+o);return e}var Ue=class o{constructor(e,n={}){this.transport=new Fn;this.generation=0;this.performanceTempo=120;this.sharedSurface=!1;this.companions=[];this.animations=[];if(this.options={instrument:"acoustic_grand_piano",tempo:120,show_controls:!0,soundfont_url:"/soundfont/",overlay_class:"vextab-player",...n},"parts"in e){let t=e;n.partId===void 0&&n.partIndex===void 0&&t.parts.length>1&&(this.ensemble=t.parts.map((s,r)=>je(t,r))),e=je(t,qe(t,n))}"measures"in e?(this.score=e,this.options.tempo=n.tempo??e.playback?.tempo??120,this.options.instrument=n.instrument??e.playback?.instrument??"acoustic_grand_piano"):this.artist=e,this.setTempo(this.options.tempo),this.setInstrument(this.options.instrument),this.reset()}static{this.DEBUG=!1}static{this.INSTRUMENTS_LOADED={}}setArtist(e){this.dispose(),this.score=void 0,this.ensemble=void 0,this.artist=e,this.reset()}setTempo(e){if(!Number.isFinite(e)||e<=0)throw new RangeError("Tempo must be positive");this.options.tempo=e,this.overlay?.setTempo(e),this.transport.active&&this.transport.setRate(e/this.performanceTempo)}setInstrument(e){ni(e),this.options.instrument=e,this.stop()}reset(){this.artist?.attachPlayer(this),this.stop()}removeControls(){this.stop(),this.overlay?.remove(),this.overlay=void 0;for(let e of this.companions)e.overlay.remove();this.companions=[]}dispose(){this.removeControls(),this.mark=void 0,this.geometry=void 0,this.artist?.player===this&&this.artist.attachPlayer(null)}render(e,n,t=[]){this.removeControls(),this.mark=n;let s=e&&Ht.get(e);this.sharedSurface=!!this.ensemble&&!!s?.ensemble&&this.ensemble.every((w,v)=>s.ensemble[v]===w),this.geometry=s&&s.score===this.score?s.read:void 0;let r=this.artist?.getPlayerData().context,a=e??r?.canvas??r?.svg,i=this.options.controls,c=i instanceof HTMLElement?i:void 0;if(!a&&!c)throw new Error("Render the score before mounting playback controls");let l=this.score?.playback?.controls,u=typeof i=="object"&&!(i instanceof HTMLElement)?i:void 0,f=Pn({...l,...u});(i===!0||c)&&f.visibility==="off"&&(f.visibility="hover");let m=(w,v,x)=>new Bn(w,this.options.overlay_class,v,()=>{this.play().catch(()=>{})},()=>this.stop(),this.options.tempo,P=>this.setTempo(P),f,x);this.overlay=m(a,this.options.show_controls&&i!==!1&&f.visibility!=="off",c);let h=new Set(this.ensemble);for(let w of t){let v=Ht.get(w);v&&h.has(v.score)&&this.companions.push({...v,overlay:m(w,!1)})}}moveCursor(e,n){this.overlay?.moveCursor(e,n)}async play(){if(this.transport.active)return;let e=++this.generation,{tempo:n,instrument:t,playback:s,soundfont_url:r}=this.options;this.performanceTempo=n;let a=this.ensemble??(this.score?[this.score]:[]),i=vs(a,this.options.order==="performed"),c=yr(this.options.performer??this.score?.playback?.performer,this.options.seed,this.options.swing??this.score?.playback?.swing),l=a.map(()=>[]),u=a.length?a.map((x,P)=>Ms(x,n,this.mark,i.get(x),c,c.needsBeatGrid?l[P]:void 0)):[Ts(this.artist,n)],f=c.perform(u,Es(l),n),m=f[0],h=new Map(a.map((x,P)=>[x,f[P]])),w=f.length===1?m:{events:f.flatMap(x=>x.events).sort((x,P)=>x.time-P.time),duration:Math.max(...f.map(x=>x.duration))},v=s??(!this.artist||typeof MIDI>"u"?mt():ti(String(t),r,o.INSTRUMENTS_LOADED,c.literal));if(this.overlay&&!w.events.some(x=>x.notes.length)){this.overlay?.setStatus("This example has no pitched notes to play.");return}this.overlay?.setPlaying(!0),this.overlay?.setStatus("Loading instruments...");try{let x=this.geometry?.()??(this.artist&&this.overlay?Xs(this.artist):void 0);x?.size&&this.animations.push(new Zt(this.overlay?.surface,this.sharedSurface?w:m,x,(_,M)=>this.overlay?.followSystem(_,M)));for(let _ of this.companions){let M=h.get(_.score);M&&this.animations.push(new Zt(_.overlay.surface,M,_.read()))}let P=ni(t),B=[...new Set(w.events.flatMap(_=>_.notes.map(M=>M.program??P)))],D=B.some(_=>_!==P)?ei(v,B):v;await this.transport.play(D,P,w,_=>{for(let M of this.animations)M.start(_);this.overlay?.setStatus(""),this.overlay?.setPlaying(!0)},this.animations.length?.075:0)}catch(x){throw e===this.generation&&(this.overlay?.setPlaying(!1),this.overlay?.setStatus(x instanceof Error?x.message:String(x))),x}finally{e===this.generation&&(this.stopAnimations(),this.overlay?.setPlaying(!1))}}stopAnimations(){for(let e of this.animations)e.stop();this.animations=[]}stop(){this.generation++,this.transport.stop(),this.stopAnimations(),this.overlay?.setStatus(""),this.overlay?.setPlaying(!1)}};Z.Flow.Player||(Z.Flow.Player=Ue);function ri(o,e,n){let t=(o.editions??[]).filter(c=>!c.conductor&&!c.part),s=o.editions?.find(c=>e==="conductor"?c.conductor:c.part&&c.part===o.parts[e].id);s&&t.push(s);let r={},a=[];for(let c of t)Object.assign(r,c.settings),a.push(...c.anchors);for(let c of["systemBreaks","pageBreaks","preferredTurns","forbiddenTurns"])r[c]=a.filter(l=>l.field===c).map(l=>l.measure);let i={...r.margins,...n.margins};return{settings:{...r,...n,margins:i},cues:s?.cues??[],anchors:a,range:(s??t[0])?.range}}var pt=Ee(Pe());function ii(o,e,n){return o.flatMap(t=>{let s=!1,r=t.map(a=>{let i=(u=0)=>u-3>n+4,c=a.text&&i(a.style.line)===e?a.text:"",l=a.boundaries?.filter(u=>i(u.style.line)===e).map(u=>e?{...u,style:{...u.style,line:u.style.line-n}}:u);return(c||l?.length)&&(s=!0),{...a,text:c,boundaries:l,belowBassStaff:e,style:c&&e?{...a.style,line:a.style.line-n}:a.style}});return s?[r]:[]})}function si(o){return o.boundaries?.some(e=>e.edge==="start"&&e.style.line===o.style.line)}var Vn=class{constructor(){this.regions=new Map;this.cells=new Map;this.smoothMeasures=new Map;this.smoothNotes=new Map}voices(e,n,t){let r=[{notes:e.map(i=>{let c=t(i.id,i.range);return i.text&&i.style.smooth&&!i.boundaries?.length&&this.smoothMeasures.set(c,n),this.anchor(i,c)})}],a=Math.max(0,...e.map(i=>i.boundaries?.length??0));for(let i=0;i<a;i++)r.push({notes:e.map(c=>{let l=c.boundaries?.[i];if(!l)return{skip:{duration:c.base,dots:c.dots}};let u=c.id+"-at-"+l.range.start;return this.anchor({...c,...l,id:u},t(u,l.range),l.edge)})});return r}anchor(e,n,t="beat"){let s={duration:e.base,dots:e.dots};if(!e.text)return{id:n,skip:s};if(this.cells.set(n,e),e.style.smooth&&t==="beat"&&!e.boundaries?.length)return"B4/"+e.base+"/r"+".".repeat(e.dots)+'[clef="treble",id="'+n+'"]';let{family:r,size:a,style:i,align:c,line:l}=e.style,u=e.glyph?pt.TextNote.GLYPHS[e.text]??e.text:e.text,f={...r&&{family:r},...a&&{size:a},...i==="italic"&&{style:i},...i==="bold"&&{weight:i},...e.glyph&&{family:ht(),style:"normal",weight:"normal"}},h=t==="beat"&&si(e)?"right":c??"center";return{id:n,direction:{...s,text:u,anchor:t,line:l,align:h,font:f}}}prepare(e,n){let t=this.smoothMeasures.get(e);if(t===void 0||n instanceof pt.TextNote)return;n.renderOptions.draw=!1;let s=this.smoothNotes.get(t);s||this.smoothNotes.set(t,s=new Map),s.set(e,n)}smoothLabel(e,n,t){let{family:s,size:r,style:a,align:i,line:c}=n.style,l=new pt.TextNote({duration:n.base,...n.glyph?{glyph:n.text}:{text:n.text},line:c}).setDirectionAnchor("beat").setAttribute("id",t);return n.glyph?r&&l.setFontSize(r):l.setFont(s??l.fontInfo.family,r??l.fontInfo.size,a==="bold"?"bold":void 0,a==="italic"?"italic":void 0),l.setJustification(i==="right"?pt.TextNote.Justification.RIGHT:i==="left"?pt.TextNote.Justification.LEFT:pt.TextNote.Justification.CENTER),l.setStave(e.checkStave()).setTickContext(e.checkTickContext()),l.preFormat(),l}inkBounds(e,n){let t=[];for(let[s,r]of this.smoothNotes.get(n)??[]){if(r.getStave()!==e)continue;let a=this.cells.get(s),i=this.smoothLabel(r,a,s);this.positionLabel(i,e,a.glyph),t.push(i.getBoundingBox())}return t}positionLabel(e,n,t){if(e.getLine()-3<n.getNumLines())return;e.setYShift(0);let s=t?-e.getTextInk(0,0).y:e.getTextMetrics().fontBoundingBoxAscent;e.setYShift(n.getSpacingBetweenLines()+s)}place(e,n,t){let s=e.getAttribute("id"),r=this.cells.get(s);if(!r)return;let a;if(e instanceof pt.TextNote){if(a=e,a.getDirectionAnchor()==="beat"&&si(r)){let l=a.getTextMetrics().width;a.setXShift(r.style.align==="right"?0:r.style.align==="left"?l:l/2)}}else{if(!r.style.smooth)return;a=this.smoothLabel(e,r,s)}r.style.ink&&a.setStyle(ke(r.style.ink));let i=e.checkStave();if(this.positionLabel(a,i,r.glyph),r.belowBassStaff){let l=a.getBoundingBox(),u=l.y;for(let f of t.notes.flat(3)){let m=f,h=m.getBeam?.();if(!(!h||h.getNotes()[0]!==m||m.getStave()?.getY()!==i.getY()))for(let w of h.getStripBounds())w.x<l.x+l.w&&w.x+w.w>l.x&&(u=Math.max(u,w.y+w.h+i.space(.4)))}a.setYShift(a.getYShift()+u-l.y)}let c=a.getBoundingBox();this.regions.set(s,{id:s,source:r.id,kind:"event",x:c.x,y:c.y,w:c.w,h:c.h}),a!==e&&n({source:e,bounds:c,draw:l=>a.setContext(l).drawWithStyle()})}};var wt=Ee(Pe());function oi(o,e,n,t,s){o.save(),o.openGroup("score-heading");let r=e.align==="center",a=Math.min(1,r?Math.max(.75,t/620):t/620),i=0;function c(l,u,f,m,h=0){if(!l)return;let w=l.split(/(\^\{[^{}]+\}|♩|𝅗𝅥)/u).filter(Boolean).map(_=>{let M=_.startsWith("^{")&&_.endsWith("}"),V=M?_.slice(2,-1):_,K=_==="\u2669"?wt.default.Glyphs.metNoteQuarterUp:_==="\u{1D15E}"?wt.default.Glyphs.metNoteHalfUp:void 0,Y=K?ht():ze(),W=K?"normal":St(),C=K??V.trim(),T=m*a*(M?.62:1);o.setFont(Y,T,W,"normal");let X=K?0:o.measureText("a a").width-o.measureText("aa").width,S=(V.length-V.trimStart().length)*X,N=(V.length-C.length)*X+o.measureText(C).width;return{label:C,family:Y,weight:W,fontSize:T,raised:M,leading:S,advance:N}}),v=w.reduce((_,M)=>_+M.advance,0),x=r&&v>t?t/v:1,P=m*a*x,B=n+u*t-v*x*h,D=r?s+i+P*1.3:s-f*a;for(let _ of w)o.setFont(_.family,_.fontSize*x,_.weight,"normal"),o.fillText(_.label,B+_.leading*x,D-(_.raised?P*.5:0)),B+=_.advance*x;r&&(i+=P*1.85)}return r?(c(e.title,.5,0,32,.5),c(e.dedication,.5,0,16,.5),c(e.composer,.5,0,16,.5),c(e.tempo,.5,0,16,.5)):(c(e.title,.5,112,34,.5),c(e.dedication,.045,74,18),c(e.tempo,.17,39,23),c(e.composer,.985,32,19,1)),o.closeGroup(),o.restore(),i}function ai(o,e){let n=new wt.KeyManager(e),t=new Map;return o.notes.map(s=>{let[r,a]=s.key.split("/"),i=r[0],c=r.slice(1)||"n",l=i+a,u=t.get(l)??n.getAccidental(i).accidental??"n";t.set(l,c);let f=s.ornament&&new wt.Ornament(s.ornament.replace("_inverted","Inverted")).getText(),m=f?'[stem="down",articulations="'+f+'.above"]':'[stem="down"]';return i+(u===c?"":c)+a+"/"+o.duration+m}).join(", ")}var oe=Ee(Pe());var ci=Ee(Pe());function li(o,e,n,t,s=!1,r=!1,a=new Map){let i=[],c=[];for(let l of o.voices){let u=new Map;for(let[f,m]of l.events.entries()){let h=n(m.id),w=m.chord?[m.chord.text]:[];if(t)for(let v of m.heads)(v.connection||v.hammer)&&e==="tab"&&w.push(v.connection==="pull"?"P":v.connection==="slide"?"Slide":"H"),v.openSlide&&e==="notation"&&w.push(Vt(v.openSlide,v.position.str)),v.prebend&&w.push(Bt(v.prebend,v.position.str));if(s)for(let v of m.gestures??[])"direction"in v?!o.state.piano&&!r&&w.push(v.kind+" "+v.direction):w.push(v.kind==="tap"?"T":v.wide?"Wide vibrato":"Vibrato");m.harmony&&w.length===1?i.push({note:h,harmony:m.harmony}):w.length&&i.push({note:h,text:w.join(" \xB7 ")});for(let v of $t(m)){let{text:x,hyphen:P,extend:B,range:D,verse:_,elideWith:M,crossConnector:V}=v;if(e==="tab")throw new ne("fixed-layout","This lyric needs a notation staff",D);let K=_??"";u.has(K)||u.set(K,[]),u.get(K).push({note:h,text:x,elideWith:M,hyphenAfter:P,extendTo:B?n(V?a.get(D.start):l.events[f+B].id):void 0})}}for(let f of[...u.keys()].sort())c.push({id:f,syllables:u.get(f)})}return{chords:i,verses:c}}function To(o){return o.voices.flatMap(e=>e.events.filter(n=>n.frame)).map(e=>({event:e,beat:new ci.Fraction().parse(e.onset).value()})).sort((e,n)=>e.beat-n.beat)}function ui(o,e){return o.measures.flatMap(n=>To(n).map(({event:t})=>{let{spec:s,range:r}=t.frame,a="frame"+r.start;return{id:e(a,r,t.id),source:a,diagram:{...s,label:t.chord.text}}}))}var Po=0;function No(o,e){let n=o.measures[0].state,s=(n.piano?["right","left"]:["notation","tab"].filter(r=>n[r])).filter(r=>e==="score"||e===r||n.piano&&e==="notation");if(!s.length)throw new ne("fixed-layout",`No ${e} staff in this score`,n.declaration);for(let r of o.measures)if(r.state.piano!==n.piano||["notation","tab"].some(a=>(e==="score"||e===a)&&r.state[a]!==n[a])||s.includes("tab")&&r.state.strings!==n.strings)throw new ne("fixed-layout","A flow score must keep its staff configuration",r.state.declaration);return s}function Dt(o,e){return o.state.piano?o.voices.filter(n=>n.hand===e):o.voices}var xr=class{constructor(e){this.revision=e;this.ids=Object.create(null);this.ranges=new Map;this.prefix="vt"+ ++Po+"-";this.id=(e,n)=>this.prefix+e+"-"+n;this.rangeFor=(e,n)=>n===this.revision?this.ranges.get(this.ids[e]??e):void 0;this.sourceFor=e=>this.ids[e]}project(e,n,t,s){let r=this.id(e,s?n+"-"+s:n);return this.ids[r]=n,this.ranges.set(n,t),r}};function _o(o,e){let n=o.heads.flatMap((s,r)=>s.position?[{...s.position,displayKey:s.written,index:r}]:[]),t=[];if(o.bend){let s=n.map(a=>({str:a.str,fret:Number(a.fret)}));t.push(...e.attack(n,o.base).note.notation);let r=o.heads.some(a=>a.bend)?o.heads.flatMap(a=>a.bend&&!a.tiedBendStart?[a.bend]:[]):[o.bend.spec];for(let a of r)t.push(...e.bentAttack(s,o.base,a).note.notation.filter(i=>i.bend))}else if(n.length)for(let s of e.attack(n,o.base).note.notation)t.push({...s,index:n[s.index].index});return o.heads.forEach((s,r)=>{s.openSlide&&t.push({kind:"technique",id:"open-slide",index:r,label:Vt(s.openSlide,s.position.str)}),s.prebend&&t.push({kind:"technique",id:"pre-bend",index:r,label:Bt(s.prebend,s.position.str)}),!s.position&&s.sounding===null&&t.push({kind:"unpitched",id:"slash",label:"Rhythm slash",index:r})}),t}function Ao(o){let e=new Map;if(!o.hand)return e;for(let n of o.beamGroups??[]){let t=o.events.slice(n.start,n.end+1),s=t.map(r=>r.displayHand??o.hand);s.some(r=>r!==s[0])&&t.forEach((r,a)=>e.set(r,s[a]==="right"?-1:1))}return e}function Ro(o,e,n,t){let s=o.stem,r=s?s==="up"?1:-1:n==="tab"?o.tabDirection:void 0,a=new oe.FrettedInstrument(e.state.tuning,e.state.capo),i=n==="left"?"bass":e.state.clef,c=Ao(o),l,u=o.events.map(h=>{let w=t.project(n,h.id,h.range);h.heads.forEach((Y,W)=>t.project(n,h.id+"-head-"+W,Y.range));let v=e.state.piano?h.displayHand:void 0,x=c.get(h),P=h.stem==="up"?1:h.stem==="down"?-1:void 0,B={duration:h.base,dots:h.dots,stemDirection:P??x??r,headSource:{event:h.id}};if(h.silent)return{id:w,skip:B};if(!h.heads.length){let Y=n==="tab"?5-e.state.strings:0,W=h.restLine===void 0?void 0:h.restLine+Y;return{id:w,...v&&{stave:v},note:{...B,keys:["r/4"],clef:"treble",type:"r",restLine:W}}}if(h.heads[0].drum){let Y=(e.state.kit??lt).note(h.heads.map(W=>W.drum),h.base,h.stem??s);return{id:w,note:{...Y,dots:h.dots,headSource:B.headSource}}}let D=_o(h,a),_=h.heads.map(Y=>Y.position?.fret==="X"?Y.written+"/X":Y.written);if(n==="tab")return{id:w,tab:{...B,keys:_,notation:D,positions:h.heads.map(Y=>({...Y.position}))},drawStem:o.tabStems&&!["w","1"].includes(h.base)};let M=h.writtenClef??i;if(v&&v!==o.hand){let Y=e.staffState?.[v];M=Y?.clef??(v==="left"?"bass":"treble");for(let W of Y?.changes??[]){if(new oe.Fraction().parse(W.at).greaterThan(new oe.Fraction().parse(h.onset)))break;M=W.clef??M}}let V=h.heads.map((Y,W)=>{let C=Un(Y.marks,h.heads);return{key:_[W],...C&&{fingering:{finger:C.finger,position:C.position}},...Y.accidental&&{accidental:Y.cautionary?"cautionary":"force"}}}),K={...B,heads:V,notation:D,clef:M,type:h.slash?"s":"n",autoStem:B.stemDirection===void 0};return h.tremolo&&(l===void 0?(l=B.stemDirection??new oe.StaveNote({...K,autoStem:!0}).getStemDirection(),K.stemDirection=l):(K.stemDirection=l,l=void 0),K.autoStem=!1),{id:w,...v&&{stave:v},note:h.tremolo?oe.AlternatingTremolo.endpoint(K,h.tremolo):K,...h.grace&&{grace:{side:h.grace.side,slur:!0,beam:h.grace.pitches.length>1,notes:h.grace.pitches.map(Y=>({keys:Array.isArray(Y)?Y:[Y],duration:h.grace.slash?"8":"16",slash:h.grace.slash,clef:M}))}}}}),f=new Map;if(n!=="tab")for(let h of e.staffState?.[n]?.changes??[])!h.clef&&!h.key||f.set(h.at,{...f.get(h.at),...h.clef&&{clef:h.clef},...h.key&&{key:h.key}});return{notes:f.size?u.flatMap((h,w)=>{let v=f.get(o.events[w].onset);return v?[{change:v},h]:[h]}):u,stem:s??"auto",autoBeam:!o.events.some(h=>h.tremolo)&&o.beams&&(n!=="tab"||o.tabStems)&&{groups:o.beatGroups?.map(h=>new oe.Fraction(h,Number(e.state.meter.split("/")[1]))),stemDirection:o.events.some(h=>h.stem)?void 0:r,flatBeams:o.flatBeams,beamRests:o.beamRests,showStemlets:o.stemlets,beamMiddleOnly:o.middleRests},beams:n==="tab"&&!o.tabStems?[]:o.beamGroups?.map(h=>({start:h.start,count:h.end-h.start+1,flatBeams:o.flatBeams,feathered:h.feather,showStemlets:o.stemlets})),tuplets:o.tuplets.map(h=>({start:h.start,count:h.count,options:{numNotes:h.numNotes,notesOccupied:h.notesOccupied}}))}}function Co(o){let e=o.voices[0].closing?.type;if(e==="end")return oe.Barline.type.END;if(e==="double")return oe.Barline.type.DOUBLE}function di(o,e,n,t=!1){let s=No(o,e);if(!s.includes("tab"))for(let M of o.measures)for(let V of M.voices){let K=V.events.find(Y=>Y.bend)?.bend;if(K)throw new ne("fixed-layout","A timed bend contour needs a tab staff",K.range)}let r=new xr(o.source),a=r.id,i=o.layout?.heading,c=i&&(i.align==="center"||Object.keys(i).length===1)&&!Object.values(i).some(M=>/\^\{/.test(M)),l=ui(o,(M,V,K)=>r.project(s[0],M,V,K)),u=[];if(c)for(let M of["title","dedication","composer","tempo"])i[M]&&u.push({kind:"text",runs:i[M].split(/([♩𝅗𝅥])/u).filter(Boolean).map(V=>V==="\u2669"||V==="\u{1D15E}"?{text:V==="\u2669"?oe.default.Glyphs.metNoteQuarterUp:oe.default.Glyphs.metNoteHalfUp,font:{family:ht(),weight:"normal"}}:V),align:i.align??(M==="title"?"center":M==="composer"?"right":"left"),font:{family:ze(),weight:St(),size:M==="title"?32:16}});l.length&&u.push({kind:"diagrams",align:i?.align??"left",diagrams:l.map(M=>M.diagram),font:{family:ze(),size:12}}),o.playback?.swing==="eighths"&&u.push({kind:"text",font:{family:ze(),size:12,weight:St()},runs:["Swing ",{notes:["8","8"],beam:!0}," = ",{notes:["q","8"],tuplet:[3,2]}]});let f=new Vn,m=new Map(o.spans.filter(M=>M.kind==="lyric").map(M=>[M.range.start,M.to])),h=o.measures[0].state.tab&&o.measures.some(M=>M.voices.length>1),w=[],v=new Set(o.measures.flatMap(M=>M.voices.flatMap(V=>V.events.filter(K=>!K.heads.length).map(K=>K.id)))),x=new Map,P=[],B={stemPolicy:o.layout?.stemPolicy==="pitch"?void 0:"active-voices",accidentals:"key-aware",graceAccidentals:"ordered",sheet:{width:n,x:10,y:o.layout?.top??14,rowGap:o.layout?.rowGap??36,...o.layout?.spacing&&{measurePadding:18,measureGap:0}},system:{...o.layout?.spacing&&{details:{spacing:{mode:o.layout.spacing}}},spaceBetweenStaves:o.layout?.staffDistance??9},staves:s.map(M=>({id:M,kind:M==="tab"?"tab":"stave",...M==="right"&&{name:"R.H.",shortName:"R.H."},...M==="left"&&{name:"L.H.",shortName:"L.H."},...Gs(o,M,M===s[0]),options:M==="tab"?{numLines:o.measures[0].state.strings}:{},measures:o.measures.map(V=>{let K=Dt(V,M);if(M!=="tab"&&o.ties.length&&K.filter(T=>T.events.some(X=>X.heads.length)).length>1){for(let T of K)if(T.stem)for(let X of T.events)x.set(X.id,T.stem==="up"?"above":"below")}let Y=M===s[0]||V.state.piano,W=M==="tab"?void 0:V.staffState?.[M];return{clef:W?.clef??(M==="tab"?"tab":M==="left"?"bass":V.state.clef),key:W?.key??V.state.key,time:V.state.meterSign??V.state.meter,span:V.span==="0/1"?"1/1":V.span,showTimeSignature:V.state.showTime&&!(M==="tab"&&s.includes("notation")),endBarline:Co(V),...Y&&li({...V,voices:K},M==="tab"?"tab":"notation",T=>a(M,T),t||!s.includes("tab"),t,h,m),voices:[...K.map((T,X)=>T.events.length?Ro(T,V,M,r):{notes:[{id:a(M,"blank-"+V.number+"-"+X),skip:"w"}]}),...(V.state.piano&&s.length===2?ii(V.text??[],M==="left",o.layout?.staffDistance??9):M===s[0]?V.text??[]:[]).flatMap(T=>f.voices(T,V.number,(X,S)=>r.project(M,X,S)))]}})})),continuous:{inkBounds:(M,V)=>f.inkBounds(M,V),verticalSpacing:o.measures[0].state.piano||s.length>1?"profile":"envelope",textLanes:"system",opening:{indent:o.layout?.firstSystemIndent,blocks:u},courtesy:!1,measureNumbers:o.measureNumbers,spans:w,groups:s.length===2?[{first:s[0],last:s[1],type:o.measures[0].state.piano?"brace":"bracket",barlines:!!o.measures[0].state.piano}]:[],boundaries:o.measures.map(M=>({measure:M.number,rehearsal:M.voices[0].rehearsal,breakBefore:M.newRow&&M.number>1?"force":void 0,repeatStart:["repeat-begin","repeat-both"].includes(M.voices[0].opening?.type),repeatEnd:["repeat-end","repeat-both"].includes(M.voices[0].closing?.type)}))}};for(let M of o.ties)for(let V of s){let K=a(V,M.from);r.ids[K]&&w.push({kind:"tie",id:r.project(V,M.id,M.range),from:K,to:a(V,M.to),side:V==="tab"?void 0:M.side??x.get(M.from)??x.get(M.to),...V==="tab"&&M.bend&&{bend:M.bend,string:M.string},fromHead:M.fromHead,toHead:M.toHead})}for(let M of o.spans??[]){if(M.kind==="pedal"){for(let W of s){let C=a(W,M.from),T=a(W,M.to);W!=="tab"&&r.ids[C]&&r.ids[T]&&w.push({kind:"pedal",pedalStyle:"text",id:r.project(W,M.id,M.range),from:C,to:T})}continue}if(M.kind==="lyric"||M.kind==="hyphen"||M.kind==="tremolo")continue;if(M.kind==="continuousBeam"||M.kind==="crescendo"||M.kind==="diminuendo"){for(let W of s){let C=a(W,M.from),T=a(W,M.to);!r.ids[C]||!r.ids[T]||W==="tab"||w.push({kind:M.kind==="continuousBeam"?"beam":M.kind,from:C,to:T,..."niente"in M&&{niente:M.niente},...M.side&&{side:M.side},id:r.project(W,M.id,M.range)})}continue}if("fromHead"in M){for(let W of s){if(W==="tab")continue;let C=a(W,M.from);r.ids[C]&&w.push({kind:M.kind==="glissando"?"glissando":"tie",id:r.project(W,M.id,M.range),from:C,to:a(W,M.to),fromHead:M.fromHead,toHead:M.toHead})}continue}if(M.kind==="slur"){for(let W of s){let C=a(W,M.from);W==="tab"&&(v.has(M.from)||v.has(M.to))||r.ids[C]&&w.push({kind:"slur",side:M.side??(W==="tab"?"below":void 0),id:r.project(W,M.id,M.range),from:C,to:a(W,M.to)})}continue}if(M.kind==="palmMute"&&!s.includes("tab"))throw new ne("fixed-layout","A string-specific palm mute needs a tab staff",M.range);if(M.kind!=="palmMute"&&M.kind!=="volta")continue;let V=M.kind==="palmMute"?"tab":s[0],Y={id:r.project(V,M.id,M.range),from:a(V,M.from),to:a(V,M.to)};if(M.kind==="palmMute")w.push({...Y,kind:M.kind,strings:M.strings});else if(V==="tab"&&v.has(M.from)!==v.has(M.to)){let W=o.measures[M.firstBar-1].voices.flatMap(S=>S.events),T=o.measures[M.lastBar-1].voices.flatMap(S=>S.events).find(S=>v.has(S.id)===v.has(M.from)),X=W.find(S=>v.has(S.id)===v.has(M.to));T||X?w.push({...Y,kind:"volta",text:M.label,from:T?Y.from:a(V,X.id),to:T?a(V,T.id):Y.to}):P.push(M)}else w.push({...Y,kind:M.kind,text:M.label})}let D=[];for(let M of o.measures)for(let V of s)if(V!=="tab")for(let K of Dt(M,V))for(let Y of K.events){let W=Y.ossia;W&&D.push({id:a(V,Y.id+"-ossia"),at:a(V,Y.id),label:"Ossia.",notes:ai(W,M.state.key??"C"),beam:W.notes.length>1&&W.duration!=="q",scale:.63})}if(B.continuous.ossias=D,s.includes("left")&&s.includes("right")){let M=[];for(let V of o.measures){let K=new Map;for(let Y of V.voices)for(let W of Y.events)if(W.sharedStem){let C=W.sharedStem+":"+W.onset,T=K.get(C)??{},X=Y.hand==="right"?"upper":"lower";if(T[X])throw new ne("measure","Duplicate shared stem endpoint",W.range);T[X]=a(Y.hand,W.id),K.set(C,T)}for(let Y of K.values()){if(!Y.upper||!Y.lower)throw new ne("measure","Shared stems need simultaneous notes on both staves",V.range);M.push({id:Y.upper+"-shared",upper:Y.upper,lower:Y.lower})}}B.continuous.splitChords=M}let _={spec:B,nativeHeading:c,frames:l,staves:s,sources:r,eventId:a,mixedEndings:P,textLanes:f,printAnchors:t?new Map:void 0,endingRegions:[]};return B.engraving=Lo(o,_),_}function Io(o,e,n){for(let t of e.labels??[]){let s=new oe.Annotation(t.text).setVerticalJustification(t.position==="below"?oe.Annotation.VerticalJustify.BOTTOM:oe.Annotation.VerticalJustify.TOP);s.setFont(t.family??ze(),t.size??12,t.style==="bold"?"bold":void 0,t.style==="italic"?"italic":void 0),t.ink&&s.setStyle(ke(t.ink)),o.addModifier(s,0)}for(let t of e.gestures??[])if(t.kind==="tap")n&&o.addModifier(new oe.Annotation("T"),0);else if(t.kind==="vibrato")n&&o.addModifier(new oe.Vibrato().setVibratoWidth(t.wide?28:18),0);else if(t.kind==="stroke")o.addModifier(new oe.Articulation(t.direction==="up"?"a|":"am").setPosition(oe.Modifier.Position.BELOW),0);else if("direction"in t){let s=(t.kind==="rasgueado"?"RASGUEADO":t.kind.toUpperCase())+"_"+t.direction.toUpperCase();o.addModifier(new oe.Stroke(oe.Stroke.Type[s]),0)}}function Bo(o,e,n,t,s){if(e.grace?.positions&&o instanceof oe.TabNote){let r=e.grace.positions.map(i=>new oe.GraceTabNote({positions:i,duration:"16"})),a=new oe.GraceNoteGroup(r).setPosition(e.grace.side==="before"?oe.Modifier.Position.LEFT:oe.Modifier.Position.RIGHT);o.addModifier(a,0)}if(e.grace?.fingerings){let r=o.getModifiers().find(a=>a instanceof oe.GraceNoteGroup);for(let{attack:a,head:i,finger:c,position:l}of e.grace.fingerings)r&&Et(r.getGraceNotes()[a],i,[{finger:c,position:l}],n==="tab",!0,!0)}if(e.ornament&&n!=="tab"&&o.addModifier(new oe.Ornament(e.ornament.replace("_inverted","Inverted")),0),e.dynamic&&(t.hand||s)){let r=[...e.dynamic].map(i=>oe.TextDynamics.GLYPHS[i]).join(""),a=t.hand==="right"&&e.displayHand==="left"?oe.Annotation.VerticalJustify.TOP:oe.Annotation.VerticalJustify.BOTTOM;o.addModifier(new oe.Annotation(r).setFont(ht(),15).setVerticalJustification(a),0)}Io(o,e,n==="tab"),e.color&&(o.setStyle(ke(e.color)),o instanceof oe.StaveNote&&o.setLedgerLineStyle(ke(e.color))),e.silent&&(o.renderOptions.draw=!1),e.heads.forEach((r,a)=>{if(!r.marks)return;let i=o instanceof oe.StaveNote&&!r.drum?Un(r.marks,e.heads):void 0;Et(o,a,r.marks.filter(c=>c!==i),n==="tab",!0)}),o instanceof oe.TabNote&&e.heads.forEach((r,a)=>{r.openSlide&&Sn(o,a,r.openSlide),r.prebend&&o.addModifier(mn(r.prebend),a)}),n==="tab"&&!t.tabStems&&!e.heads.length&&(o.renderOptions.draw=!1)}function Fo(o,e,n,t){let s=$t(e).sort((a,i)=>(a.verse??"").localeCompare(i.verse??"")),r=0;for(let a of o.getModifiers()){if(!(a instanceof oe.Annotation))continue;let i=e.chord&&a.getText().split(" \xB7 ")[0]===e.chord.text,c=a.phraseManaged&&a.getVerticalJustification()===oe.Annotation.VerticalJustify.BOTTOM&&s[r++],l=i?e.chord.range:c&&c.range;if(!l)continue;i&&e.chord.color&&a.setStyle(ke(e.chord.color));let u=(i?"chord":"lyric")+l.start;n.sources.project(t,u,l,e.id),n.sources.ids[a.getAttribute("id")]=u}}function Vo(o,e,n,t,s){e.endingRegions.length=0;for(let r of e.mixedEndings){if(r.kind!=="volta")continue;let a=e.eventId("tab",r.id),i=c=>t.get(e.eventId("tab",o.measures[c-1].voices[0].events[0]?.id));for(let[c,l]of n.sheet.getContinuousLayout().rows.entries()){let u=l.measures.filter(_=>_>=r.firstBar&&_<=r.lastBar);if(!u.length)continue;let f=u[0],m=u[u.length-1],h=i(f),w=i(m);if(!h||!w)continue;let v=h.checkStave(),x=v.getX()+1,P=w.checkStave().getNoteEndX(),B=l.y+v.getY()-n.staves[f-1][0].getY()-15,D={x,y:B,w:P-x,h:14};e.endingRegions.push({id:a,kind:"span",source:r.id,row:c,...D}),s({source:h,bounds:D,draw(_){_.openGroup("tab-ending",a+"-"+c),_.fillRect(x,B,P-x,1),f===r.firstBar&&(_.fillRect(x,B,1,12),_.setFont(ze(),11).fillText(r.label,x+4,B+12)),m===r.lastBar&&_.fillRect(P-1,B,1,12),_.closeGroup()}})}}}function Oo(o,e,n,t){for(let s of o.spans)for(let r of e.staves){let a=n.get(e.eventId(r,s.from)),i=n.get(e.eventId(r,s.to));if(!a||!i)continue;if(s.kind==="tremolo"&&a instanceof oe.StaveNote&&i instanceof oe.StaveNote){let u=new oe.AlternatingTremolo(a,i,s.strokes);t({source:a,bounds:a.getBoundingBox().clone().mergeWith(i.getBoundingBox()),draw:f=>u.setContext(f).draw()})}if(!("fromHead"in s)||!(a instanceof oe.TabNote)||!(i instanceof oe.TabNote))continue;let c=Number(i.getPositions()[s.toHead].fret)>Number(a.getPositions()[s.fromHead].fret),l=(u,f)=>{let m={firstNote:u,lastNote:f,firstIndexes:[s.fromHead],lastIndexes:[s.toHead]},h=s.kind==="slide"||s.kind==="glissando"?new oe.TabSlide(m,c?oe.TabSlide.SLIDE_UP:oe.TabSlide.SLIDE_DOWN):u?s.kind==="pull"?oe.TabTie.createPulloff(m):oe.TabTie.createHammeron(m):new oe.TabTie(m);u&&(s.kind==="hammer"||s.kind==="pull")&&h.setFont({...h.fontInfo,family:ze(),weight:St()}),t({source:u??f,head:u?s.fromHead:s.toHead,bounds:h.getRibbonBounds(),draw:v=>h.setContext(v).draw()})};a.getStave().getY()===i.getStave().getY()?l(a,i):(l(a),l(void 0,i))}}function Lo(o,e){let n=new Map;for(let t of o.measures)for(let s of e.staves)for(let r of Dt(t,s))for(let a of r.events)n.set(e.eventId(s,a.id),{event:a,staff:s,voice:r,measure:t});return{prepareNote(t,s){let r=n.get(t.id);r?Bo(s,r.event,r.staff,r.voice,r.staff===e.staves[0]):e.textLanes.prepare(t.id,s)},place(t,s){let r=new Map,a=new Map;if(e.printAnchors)for(let u of t.sheet.getContinuousLayout().rows){let f=Cn(u.measures.flatMap(m=>t.staves[m-1]));for(let m of u.measures)a.set(m,f)}for(let u of t.notes)for(let f of u)for(let m of f)for(let h of m){let w=h.getAttribute("id"),v=n.get(w),x=h;if(!v){e.textLanes.place(x,s,t);continue}let{measure:P,voice:B,staff:D,event:_}=v;r.set(w,x),e.printAnchors&&x.preFormatted&&a.has(P.number)&&(!e.printAnchors.has(_.id)||D===e.staves[0])&&e.printAnchors.set(_.id,{measure:P.number,x:x.getAbsoluteX(),row:a.get(P.number)}),_.silent&&(x.renderOptions.draw=!1);let M=x.checkStave();if(P.state.hideClef)for(let V of M.getModifiers(void 0,oe.Clef.CATEGORY))V.setText("");if(P.state.color){let V=ke(P.state.color);M.setStyle(V),x.getVoice().setStyle(V),x.getBeam()?.setStyle(V)}if(D==="tab"&&!B.tabStems)for(let V of x.getTupletStack())V.setRendered();Fo(x,_,e,D)}Oo(o,e,r,s),e.mixedEndings.length&&Vo(o,e,t,r,s);let i=r.get(e.eventId(e.staves[0],Dt(o.measures[0],e.staves[0])[0]?.events[0]?.id));if(!i)return;let c=t.sheet.getRows()[0],l=!e.nativeHeading&&o.layout?.heading;if(l){let u=i.checkStave().getYForLine(0);s({source:i,bounds:{x:c.x,y:u-150,w:c.width,h:145},draw:f=>{oi(f,l,c.x,c.width,l.align==="center"?u-150:u)}})}}}}function Ho(o,e){let n=new Set(o.measures.flatMap(t=>t.voices.filter(s=>!s.tabStems).flatMap(s=>s.events.filter(r=>!r.heads.length).map(r=>e.eventId("tab",r.id)))));for(let t of o.measures)for(let s of t.voices)for(let r of s.events)if(r.silent)for(let a of e.staves)n.add(e.eventId(a,r.id));return n}var vr=class extends oe.ScoreNavigation{constructor(e,n,t,s){super(e,n,t);let r=[],a=0;for(let{score:c,view:l}of s)for(let u of l.staves){let f=n[a++];for(let m of c.measures)for(let[h,w]of Dt(m,u).entries())for(let v of w.events)v.silent&&r.push({id:l.eventId(u,v.id),source:v.id,staff:f.id,measure:m.number,voice:h+1,onset:v.onset,duration:v.duration,label:["Measure "+m.number,f.name||f.id,"voice "+(h+1),v.duration+" rest"].join(", ")})}let i=new Map(n.map((c,l)=>[c.id,l]));r.length&&(this.events=[...this.events,...r].sort((c,l)=>c.measure-l.measure||new oe.Fraction().parse(c.onset).value()-new oe.Fraction().parse(l.onset).value()||i.get(c.staff)-i.get(l.staff)||c.voice-l.voice))}};function Do(o,e,n){let t=new Map;for(let s of o.sheet.getContinuousLayout().rows){let r=Cn(s.measures.flatMap(a=>o.staves[a-1]));for(let{score:a,view:i}of e)for(let c of s.measures)for(let l of a.measures[c-1].voices)for(let u of l.events){let f=l.hand?[l.hand]:i.staves,m=n.heads.get(u.id).flatMap(w=>{if(w.role==="mark"||w.reference||typeof w.sourceHead!="number")return[];let v=u.heads[w.sourceHead];if(u.silent||!v||!v.sounding&&v.midi===void 0)return[];let x=w.bounds;return[{x:x.x+x.w/2,y:x.y+x.h/2}]}),h=m[0]?.x??o.getNote(i.eventId(f[0],u.id)).getAbsoluteX();t.set(u.id,{row:r,x:h,heads:m})}}return t}function zt(o,e,n={}){let t=n.part??"score",s="parts"in e?qe(e,n):0,r="parts"in e?je(e,s):e;return gt(r.layout?.font,()=>fi(o,[wr(r,t)],t,n,!1,s))}function On(o,e,n={}){return gt(e.layout?.font,()=>fi(o,e.parts.map((t,s)=>je(e,s)),"score",n,!0))}function fi(o,e,n,t,s=!1,r=0){let a=e[0],i=t.width??a.layout?.width??(o.clientWidth||640);if(!Number.isFinite(i)||i<=20)throw new RangeError("Score width must exceed 20 pixels");let c=e.map(O=>di(O,n,i-20)),l=c.map(O=>O.spec),u=s?hr(e,l):l[0],f=document.createElement("div"),m=t.renderer==="canvas"?f.appendChild(document.createElement("canvas")):void 0,h=m?new oe.CanvasContext(m.getContext("2d")):new oe.SVGContext(f);m||rn(h,o),a.layout?.heading&&!c[0].nativeHeading&&(u.sheet.y+=125),c.some(O=>O.mixedEndings.length)&&(u.sheet.y+=20);let w=new oe.Factory({renderer:{elementId:null,width:i,height:1}}).setContext(h),v=w.EasyScore();if(m){let O=u.engraving.place;u.engraving={...u.engraving,place(G,ue){let le=0;for(let A of G.sheet.getContinuousLayout().detailMarks)le=Math.max(le,A.bounds.y+A.bounds.h);O(G,A=>{le=Math.max(le,A.bounds.y+A.bounds.h),ue(A)}),D(G.sheet,le)}}}let x=v.compose(u),P=0,B=c.map((O,G)=>{let ue=c.length===1?x:Ws(x,P,O.staves.length);P+=O.staves.length;let le=e[G];return{partIndex:r+G,score:le,view:O,local:ue}});function D(O,G=0){let ue=Math.max(i,...O.getRows().map(le=>le.x+le.width+10));h.resize(ue,Math.ceil(Math.max(O.getHeight(),G)+20))}let _=[],M=c.flatMap(O=>O.frames.map(G=>({frame:G,sources:O.sources})));if(M.length){let O=oe.Registry.getDefaultRegistry(),G=O??new oe.Registry;O||oe.Registry.enableDefaultRegistry(G);try{w.draw(),G.getElementsByType(oe.FretDiagram.CATEGORY).filter(le=>le.isRendered()&&le.getContext()===h).forEach((le,A)=>{let{frame:U,sources:$}=M[A],{x:H,y:ee,w:F,h:b}=le.getBoundingBox();$.ids[le.getAttribute("id")]=U.source,_.push({id:U.id,source:U.source,kind:"event",x:H,y:ee,w:F,h:b})})}finally{O||oe.Registry.disableDefaultRegistry()}}else w.draw();let V=c.flatMap(O=>[...O.textLanes.regions.values()]),K=[...V,..._,...c.flatMap(O=>O.endingRegions)],Y=Object.assign(Object.create(null),...c.map(O=>O.sources.ids)),W=B.flatMap(({score:O,view:G},ue)=>G.staves.map(le=>{let A=O.measures[0].state,U=O.instrument?.name??(A.piano?"Piano":A.tab?"Guitar":"Part "+(ue+1)),$={right:"right hand",left:"left hand",tab:"tablature",notation:"notation"}[le];return U+", "+$})),C=s?u.staves.map((O,G)=>({...O,name:W[G]})):u.staves,T=new vr(x,C,Y,B),X=new Map(B.flatMap(({score:O,view:G})=>O.ties.map(ue=>[G.eventId("tab",ue.id),[]])));for(let O of T.regions)X.get(O.id)?.push(O);let S=[...X.values()].flat(),N=new Set(B.flatMap(({score:O,view:G})=>[...Ho(O,G)]));function L(O,G){let ue=$=>O>=$.x&&O<=$.x+$.w&&G>=$.y&&G<=$.y+$.h,le=V.find(ue);if(le)return le;let A=T.heads.hitTest(O,G);if(A&&typeof A.sourceHead=="number"&&A.role!=="mark")return{id:A.sourceEvent+"-head-"+A.sourceHead,source:A.sourceEvent,kind:"event",...A.bounds};let U=T.hitTest(O,G);return U&&!N.has(U.id)?U:K.find(ue)}m?(m.setAttribute("role","img"),m.setAttribute("aria-label",T.events.map(O=>O.label).join(". "))):D(x.sheet);let q=a.layout?.scale??1;if(q!==1){let O=m??h.svg;O.style.zoom=String(q),m||(f.style.width=parseFloat(O.style.width)*q+"px")}o.replaceChildren(f);function Q(O,G,ue){return re(O+"-head-"+G,ue)}function re(O,G){for(let ue of c){let le=ue.sources.rangeFor(O,G);if(le)return le}}let se=x.sheet.getContinuousLayout().diagnostics.map(O=>({...O,range:O.source&&re(O.source,a.source)||a.measures[O.measures[0]-1]?.range}));for(let O of a.measures)if(e.some(G=>G.measures[O.number-1].voices.some(ue=>ue.events.some(le=>le.chord||le.lyric))))for(let G of x.systems[O.number-1].getPhraseLayout().diagnostics){let ue=G.sources.find(le=>re(le,a.source));se.push({code:G.code,measures:[O.number],source:ue,range:re(ue,a.source)??O.range})}let ie=m??h.svg,ce=nn(ie),ae;return Ht.set(ie,{score:a,ensemble:s?e:void 0,read:()=>gt(a.layout?.font,()=>Do(x,B,T))}),{score:a,parts:e,composition:x,navigation:T,hitTest:L,tabRegions:S,extraRegions:K,diagnostics:se,rangeFor:re,headRangeFor:Q,get layoutMap(){return ae??=gt(a.layout?.font,()=>Ir(x,B,T.heads,C,ce))},sourceFor:O=>Y[O]}}function wr(o,e,n){let t=e==="right"||e==="left"?e:void 0;if(!t&&n===void 0)return o;if(t&&!o.measures[0].state.piano)throw new ne("measure","A hand part needs a piano score",o.measures[0].range);if(!t&&o.measures[0].state.piano&&n!==void 0)throw new ne("measure","Choose a hand before selecting its voice",o.measures[0].range);let s=new Set,r=o.measures.map(c=>{let l=t?Dt(c,t):c.voices;if(n!==void 0){let u=l[n-1];if(!Number.isInteger(n)||!u)throw new ne("measure","Missing voice "+n+" in bar "+c.number,c.range);l=[{...u,stem:void 0}]}for(let u of l)for(let f of u.events)s.add(f.id);return{...c,voices:l.map((u,f)=>({...u,rehearsal:f?u.rehearsal:c.voices[0].rehearsal,events:t?u.events.map(m=>m.displayHand?{...m,displayHand:void 0}:m):u.events}))}}),a=o.ties.filter(c=>s.has(c.from)&&s.has(c.to)),i=(o.spans??[]).filter(c=>c.kind==="volta"||s.has(c.from)).map(c=>{if(c.kind!=="volta")return c;let l=r[c.lastBar-1].voices[0].events;return{...c,from:r[c.firstBar-1].voices[0].events[0].id,to:l[l.length-1].id}});return{...o,measures:r,ties:a,spans:i}}function Ln(o,e,n,t={}){let{voice:s,partId:r,partIndex:a,...i}=t;return gt(e.layout?.font,()=>"parts"in e?pi(o,e,qe(e,{partId:r,partIndex:a}),i,n,s):hi(o,[wr(e,n,s)],[n],i))}function mi(o,e,n="conductor",t={}){return gt(e.layout?.font,()=>pi(o,e,n==="conductor"?n:qe(e,n),t,"score"))}function pi(o,e,n,t,s,r){let a=n==="conductor",i=ri(e,n,t),c=t.regions===void 0?i.cues.map(m=>qe(e,{partId:m.part})):[],l=a?e.parts.map((m,h)=>h):[...new Set([n,...c])],u=l.map((m,h)=>{let w=je(e,m);return h===0&&!a?wr(w,s,r):w}),f=u.map((m,h)=>h===0?s:"score");return hi(o,u,f,i.settings,{conductor:a,donors:c.map(m=>l.indexOf(m)),edition:i,document:e})}function hi(o,e,n,t,s){let r=e[0],a=e.map((_,M)=>di(_,n[M],600,!0)),i=a.length>1?hr(e,a.map(_=>_.spec)):a[0].spec;s?.conductor||(i.continuous.boundaries=a[0].spec.continuous.boundaries),s?.conductor||(i.continuous.opening=a[0].spec.continuous.opening);let{compressRests:c,...l}=t;if(c){let _=new Set([...l.preferredTurns??[],...l.forbiddenTurns??[]].map(M=>M+1));i.continuous.compressRests=!0,i.continuous.boundaries=i.continuous.boundaries.flatMap(M=>_.has(M.measure)||r.measures[M.measure-1].state.fragment?[{...M,keepRest:!0}]:M.rehearsal||M.breakBefore||M.repeatStart||M.repeatEnd?[M]:[])}let{noteHooks:u,...f}=l;if(u?.length){for(let M of i.staves)for(let V of M.measures)for(let K of V.voices)typeof K.notes!="string"&&(K.notes=K.notes.map(Y=>typeof Y!="object"||!("skip"in Y)||typeof Y.skip=="string"?Y:"B4/"+Y.skip.duration+"/g"+".".repeat(Y.skip.dots??0)+'[id="'+Y.id+'"]'));let _=i.engraving.prepareNote;i.engraving={...i.engraving,prepareNote(M,V,K){_(M,V,K);for(let Y of u)Y(M,V,K)}}}s&&!s.conductor&&(f.staves=i.staves.slice(0,a[0].staves.length).map(_=>_.id)),s?.donors.length&&(f.regions=s.edition.cues.map((_,M)=>{let V=a.slice(0,s.donors[M]).reduce((K,Y)=>K+Y.staves.length,0);return{kind:"cue",staff:i.staves[V].id,label:_.label,measure:_.measure}}));let m=gr(r.source),h;try{h=new oe.Publication(i).render(o,f)}catch(_){throw s?.edition.range&&_.code==="BadPublication"?new ne("fixed-layout",_.message,m(s.edition.range)):_}let w=(s?.conductor?a:a.slice(0,1)).flatMap(_=>_.frames.map(M=>({frame:M,sources:_.sources})));w.length&&h.pages.flatMap(M=>[...M.svg.querySelectorAll(".vf-score-opening .vf-fret-diagram")]).forEach((M,V)=>{let K=M.getAttribute("data-vf-id")?.replace(/^vf-/,"");K&&w[V]&&(w[V].sources.ids[K]=w[V].frame.source)});let v=(_,M)=>a.map(V=>V.sources.rangeFor(_,M)).find(Boolean),x=h.diagnostics.map(_=>{let M=_.measures[0],V=_.code==="ForbiddenTurn"&&s?.edition.anchors.find(T=>T.field==="forbiddenTurns"&&T.measure===M),K=_.detail.startsWith("cue exceeds")&&s?.edition.cues.find(T=>T.measure===M),Y=V||K,W=_.code==="ExcludedAnchor"?_.detail:_.detail.split(" ")[1],C=Y?m(Y.range):v(W,r.source)||_.code==="TextOverflow"&&s?.edition.range&&m(s.edition.range)||r.measures[M-1]?.range;return{..._,range:C}}),P=new Map,B=s?.conductor?e:[r];for(let _ of B)for(let M of _.measures)for(let V of M.voices)for(let K of V.events)P.set(K.id,K);let D=new Map((s?.conductor?a:a.slice(0,1)).flatMap(_=>[..._.printAnchors]));for(let _ of h.pages)Ht.set(_.svg,{score:r,ensemble:s?.conductor?e:void 0,read:()=>Ys(h,P,D,(f.staffSize??7)/40)});return{publication:h,diagnostics:x,score:r,rangeFor:v,headRangeFor:(_,M,V)=>v(_+"-head-"+M,V),sourceFor:_=>a.map(M=>M.sources.sourceFor(_)).find(Boolean)}}bi();function Re(o,e,n){return o.getAttribute(`data-${e}`)||(n?o.getAttribute(`data-${n}`):null)||o.getAttribute(e)}function zo(o){let e=Re(o,"playback-controls"),n=Re(o,"playback-position"),t=Re(o,"playback-inset"),s=Re(o,"playback-size");if(e===null&&n===null&&t===null&&s===null)return;if(e==="off"||e==="false")return!1;let r={};return e&&e!=="on"&&e!=="true"&&(r.visibility=e),s&&(r.size=s),n&&(r.position=n),t!==null&&(r.inset=Number(t)),Pn(r),(e==="on"||e==="true")&&!r.visibility&&(r.visibility="hover"),r}function Sr(o,e){let n=Re(o,"layout");return n==="flow"||!n&&/^[ \t]*piano(?:\s|$)/m.test(e)}var kr=class{constructor(e,n={}){this.part="score";this.disposed=!1;this.composing=!1;this.surface=null;this.text_area=null;this.editor_error=null;this.timeoutID=null;if(this.order=n.order,this.playback=n.playback??mt(),this.sel=e,!this.sel)throw new Error(`VexTab.Div: invalid selector: ${e}`);this.code=(0,Be.default)(e).text(),(0,Be.default)(e).empty(),(0,Be.default)(e).css("position")==="static"&&(0,Be.default)(e).css("position","relative");let t=(0,Be.default)(e)[0];this.playbackControls=n.playbackControls??zo(t),this.enablePlayer=n.player??(this.playbackControls===void 0?void 0:!!this.playbackControls);let s=Re(t,"performer");if(n.performer!==void 0)this.performer=n.performer;else if(s){if(!xt(s))throw new RangeError("Unknown performer: "+s);this.performer=s}this.seed=n.seed;let r=Re(t,"width");this.width=parseInt(r,10)||400,this.scale=parseFloat(Re(t,"scale"))||1,this.rendererBackend=Re(t,"renderer")||"svg";let a=n.language??Number(Re(t,"language")??2);if(a!==1&&a!==2)throw new RangeError("Expected VexTab language 1 or 2");this.grammar2=a===2;let i=n.capacity??Re(t,"capacity")??"default";if(i!=="default"&&i!=="large")throw new RangeError("Expected score capacity default or large");if(this.capacity=i,this.partIndex=n.partIndex,this.partId=n.partId??Re(t,"part-id")??void 0,this.conductor=(n.view??Re(t,"view"))==="conductor",this.conductor&&(!this.grammar2||this.partIndex!==void 0||this.partId!==void 0))throw new Error("The conductor view requires a complete v2 score");this.flow=this.grammar2||Sr(t,this.code),t.classList.toggle("vextab-flow",this.flow),this.editor=Re(t,"editor")||"",this.show_errors=Re(t,"show-errors")||"",this.editor_width=parseInt(Re(t,"editor-width","editor_width"),10)||this.width,this.editor_height=parseInt(Re(t,"editor-height","editor_height"),10)||200,this.editor==="true"?(this.text_area=(0,Be.default)('<textarea aria-label="VexTab source"></textarea>').addClass("editor").val(this.code),this.code=this.text_area.val(),this.editor_error=(0,Be.default)('<div role="status"></div>').addClass("editor-error"),(0,Be.default)(e).append((0,Be.default)("<p/>")).append(this.editor_error),(0,Be.default)(e).append((0,Be.default)("<p/>")).append(this.text_area),this.text_area.width(this.editor_width),this.text_area.height(this.editor_height),this.text_area.on("compositionstart.vextab",()=>{this.composing=!0,window.clearTimeout(this.timeoutID)}),this.text_area.on("compositionend.vextab",()=>{this.composing=!1,this.scheduleEdit()}),this.text_area.on("input.vextab",()=>this.scheduleEdit()),this.text_area.on("keydown.vextab",c=>{!this.composing&&(c.ctrlKey||c.metaKey)&&c.key==="Enter"&&(c.preventDefault(),this.run())})):this.show_errors==="true"&&(this.editor_error=(0,Be.default)('<div role="status"></div>').addClass("editor-error"),(0,Be.default)(e).append((0,Be.default)("<p/>")).append(this.editor_error)),this.flow||(this.artist=new Ke(10,0,this.width,{scale:this.scale}),this.parser=new Ye(this.artist,{language:1})),this.autoWidth=this.flow&&Re(t,"layout")!=="fixed"&&(r===null||r==="auto"),this.autoWidth&&t.clientWidth>20&&(this.width=t.clientWidth),this.redraw(),document.fonts.status==="loading"&&document.fonts.ready.then(()=>{this.disposed||this.redraw()}),this.autoWidth&&(this.observer=new ResizeObserver(([c])=>{let l=Math.floor(c.contentRect.width);cancelAnimationFrame(this.resizeFrame),l>20&&l!==this.width&&(this.resizeFrame=requestAnimationFrame(()=>{this.width=l,this.draw()}))}),this.observer.observe(t))}dispose(){this.disposed=!0,this.player?.dispose(),this.observer?.disconnect(),cancelAnimationFrame(this.resizeFrame),window.clearTimeout(this.timeoutID),this.text_area?.off(".vextab")}scheduleEdit(){window.clearTimeout(this.timeoutID),this.player?.removeControls(),this.composing||(this.timeoutID=window.setTimeout(()=>this.run(),250))}run(){return window.clearTimeout(this.timeoutID),this.disposed||this.composing?this:(this.code=this.text_area?.val()??this.code,this.redraw())}getReadingEvents(){return this.getScore()?this.current.layouts.flatMap(e=>e.navigation.events):[]}getDiagnosticRange(){return!this.disposed&&this.code===(this.text_area?.val()??this.code)?this.diagnostic:void 0}selectError(){let e=this.getDiagnosticRange();return!e||!this.text_area?!1:(this.text_area[0].focus(),this.text_area[0].setSelectionRange(e.start,e.end),!0)}getScoreDocument(){return!this.disposed&&this.document?.source===(this.text_area?.val()??this.code)?this.document:void 0}setInstrumentView(e,n="score"){if(!this.grammar2)throw new Error("Instrument selection requires a v2 score");return this.conductor=e==="conductor",this.partIndex=e==="conductor"?void 0:e.partIndex,this.partId=e==="conductor"?void 0:e.partId,this.part=e==="conductor"?"score":n,this.run()}setPart(e){if(!this.flow)throw new Error('setPart requires layout="flow"');return this.part=e,this.draw()}redraw(){return Z.BM("Total render time: ",()=>{this.parse(),this.draw()}),this}reportError(e){this.player?.removeControls(),this.diagnostic=e instanceof Xe?{start:e.range[0],end:e.range[1],line:e.line,column:e.column-1}:e.range,this.surface?.setAttribute("data-preview-stale","true");let n=this.surface?"Showing the last valid score. ":"";this.editor_error?.text(n+e.message),(0,Be.default)(this.sel)[0].dispatchEvent(new Event("vextab-render"))}getScore(){if(!this.disposed&&this.current&&this.current.score===this.candidate&&!this.surface?.hasAttribute("data-preview-stale")&&this.current.score.source===(this.text_area?.val()??this.code))return this.current.score}setWidth(e){if(!this.flow)throw new Error('setWidth requires layout="flow"');return this.observer?.disconnect(),cancelAnimationFrame(this.resizeFrame),this.autoWidth=!1,this.width=e,this.draw()}selectSource(e,n){let t=this.getScore(),s=t&&t===n&&this.current.layouts.map(a=>a.rangeFor(e,t.source)).find(Boolean);if(!s||!this.text_area)return!1;let r=this.text_area[0];return r.focus(),r.setSelectionRange(s.start,s.end),!0}drawView(e,n,t){let s=this.rendererBackend.toLowerCase()==="canvas"?"canvas":"svg",r=Math.max(21,this.width/(n.layout?.scale??1)),a=this.autoWidth?n.layout?.width??r:this.width,i="parts"in n?On(e,n,{width:a,renderer:s}):zt(e,n,{width:a,part:this.part,renderer:s}),c=e.querySelector("svg, canvas"),l=nn(c);return this.text_area&&c.addEventListener("click",u=>{let f=l(u);if(!f)return;let m=i.hitTest(f.x,f.y);m&&this.selectSource(m.id,t)}),{layout:i,surface:c}}drawFlow(e){if(!this.grammar2&&(this.rendererBackend.toLowerCase()!=="svg"||this.scale!==1))throw new Error("Flow layout requires SVG at scale 1. Use width to reflow.");let n=this.candidate,t=this.document,s=t&&this.part==="score"&&this.partId===void 0&&this.partIndex===void 0&&t.parts.length>1,a=this.conductor&&this.part==="score"?[this.drawView(e,t,n)]:s?t.parts.map((i,c)=>{let l=e.appendChild(document.createElement("div"));return this.drawView(l,je(t,c),n)}):[this.drawView(e,n,n)];this.grammar2&&this.scale!==1&&(e.style.zoom=String(this.scale)),this.player?.dispose(),this.player=void 0,(this.enablePlayer??n.playback?.enabled)&&(this.player=new Ue(s?t:a[0].layout.score,{playback:this.playback,controls:this.playbackControls,performer:this.performer,seed:this.seed,order:this.order})).render(a[0].surface,void 0,a.slice(1).map(c=>c.surface)),this.current={score:n,layouts:a.map(i=>i.layout)}}drawInternal(){if(this.flow?!this.candidate:!this.parser.isValid())return this;let e=this.rendererBackend.toLowerCase()==="canvas",n=document.createElement(e&&!this.flow?"canvas":"div");n.className="vex-canvas";let t=(0,Be.default)(this.sel)[0];t.insertBefore(n,t.firstChild);try{if(this.flow)this.drawFlow(n);else{let r=e?Z.Flow.Renderer.Backends.CANVAS:Z.Flow.Renderer.Backends.SVG,a=new Z.Flow.Renderer(n,r);if(e||rn(a.getContext(),n),this.enablePlayer!==void 0&&(this.artist.customizations.player=String(this.enablePlayer)),!this.player&&this.artist.customizations.player==="true"&&(this.player=new Ue(this.artist,{playback:this.playback,controls:this.playbackControls,performer:this.performer,seed:this.seed})),this.artist.draw(a),e){let i=this.artist.staves.map((c,l)=>{let f=(c.tab?c.tab_voices:c.note_voices).map((m,h)=>"Voice "+(h+1)+". "+m.filter(w=>!w.shouldIgnoreTicks()).map(w=>{let v=w.getPositions?.(),x=c.note?.getClef()==="percussion"?w.notation?.filter(D=>D.kind==="unpitched").map(D=>D.label):void 0,P=x?.length?x:v?.map(D=>"string "+D.str+" fret "+D.fret);return(w.isRest()?"rest":(P??w.getKeys()).join(", "))+" ("+w.getDuration()+")"}).join(". "));return"Stave "+(l+1)+", meter "+c.meter+". "+f.join(". ")}).join(". ");n.setAttribute("role","img"),n.setAttribute("aria-label",i),n.textContent=i}}this.surface?.remove(),this.surface=n;let s=this.flow?this.current.layouts.flatMap(r=>r.diagnostics):[];this.diagnostic=s[0]?.range,this.editor_error?.text(s.map(r=>{let a=r.range?" (line "+r.range.line+", column "+r.range.column+")":"";return(r.code==="RowOverflow"?"Bar "+r.measures.join(", ")+" exceeds this width":r.code)+a}).join(`
|
|
372
|
+
`)),t.dispatchEvent(new Event("vextab-render"))}catch(s){n.remove(),this.reportError(s)}return this}parseInternal(){try{this.flow?(this.candidate=void 0,this.document=this.grammar2?st(this.code,{capacity:this.capacity}):void 0,this.candidate=this.document?je(this.document,qe(this.document,{partId:this.partId,partIndex:this.partIndex})):st(this.code,{language:1})):(this.artist.reset(),this.parser.parse(this.code))}catch(e){this.reportError(e)}return this}parse(){return Z.BM("Parse time: ",()=>{this.parseInternal()}),this}draw(){return Z.BM("Draw time: ",()=>{this.drawInternal()}),this}},kt=kr;function yi(o,e={}){return je(o,qe(o,e))}function jo(o,e){let n={time:0,semitones:0};for(let t of o){if(e<t.time)return n.semitones+(t.semitones-n.semitones)*(e-n.time)/(t.time-n.time);n=t}return n.semitones}function Hn(o,e=[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15]){let n=[...new Set(e)];if(!n.length||n.some(r=>!Number.isInteger(r)||r<0||r>15))throw new RangeError("Supply MIDI channels from 0 to 15");let t=new Set;async function s(r,a){let i=o.context,c="resume"in i?i.resume():Promise.resolve();await Promise.all([c,o.isReady]),a.throwIfAborted();let l=new Set,u=new Set,f;function m(w){o.noteOff(w.channel,w.note.pitch),w.range&&o.pitchWheel(w.channel,8192),l.delete(w)}function h(){window.clearTimeout(f);let w=1/0;for(let v of l){let x=i.currentTime-v.start;if(x>=v.note.duration){m(v);continue}if(v.range){let P=jo(v.note.bend,x)/v.range;o.pitchWheel(v.channel,Math.max(0,Math.min(16383,Math.round(8192+P*8192)))),w=Math.min(w,.012)}w=Math.min(w,v.note.duration-x)}l.size&&(f=window.setTimeout(h,Math.max(1,w*1e3)))}return{get currentTime(){return i.currentTime},playNote(w){h();let v=Math.ceil(Math.max(0,...(w.bend??[]).map(P=>Math.abs(P.semitones)))),x=n.find(P=>(!t.has(P)||u.has(P))&&![...l].some(B=>B.channel===P&&(v||B.range||B.note.pitch===w.pitch)));if(x===void 0)throw new Error("Insufficient reserved SpessaSynth channels for this chord");u.has(x)||(o.programChange(x,r),u.add(x),t.add(x)),v&&o.pitchWheelRange(x,v),o.noteOn(x,w.pitch,w.velocity),l.add({channel:x,note:w,start:i.currentTime,range:v}),h()},stop(){window.clearTimeout(f);for(let w of l)m(w);for(let w of u)t.delete(w);u.clear()}}}return{open:s}}window.VEXTAB_SEL_V3="div.vextab-auto";(0,Er.default)(()=>{let o=window.VEXTAB_SEL_V3;o&&(0,Er.default)(o).forEach(e=>new kt(e))});var jt=class o extends kt{static{this.SEL=".vex-tabdiv"}constructor(e,n){let t=(0,Dn.default)(e);for(let s of["width","height"]){let r=t.attr(`editor_${s}`);r&&!t.attr(`editor-${s}`)&&t.attr(`editor-${s}`,r)}if(!t.attr("renderer")){let s=Sr(t[0],t.text())||"VEXTAB_USE_SVG"in window||"Raphael"in window;t.attr("renderer",s?"svg":"canvas")}super(e,n)}static start(){(0,Dn.default)(o.SEL).forEach(e=>new o(e))}},xi=Z.Flow;xi.TabDiv=jt;(0,Dn.default)(()=>{jt.SEL&&jt.start()});window.VexTabDiv=Mr;return Mi(Go);})();
|