vextab 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/runtime/auto.mjs +1 -1
- package/dist/runtime/browser.mjs +1 -1
- package/dist/runtime/resolve.mjs +1 -1
- package/dist/runtime/shared/J2THHOG5.mjs +1 -0
- package/dist/runtime/shared/LFV5PYP4.mjs +352 -0
- package/dist/runtime/types/browser.d.ts +1 -0
- package/dist/runtime/types/playback/animation.d.ts +2 -7
- package/dist/runtime/types/playback/ink.d.ts +18 -0
- package/dist/runtime/types/playback/written-overlay.d.ts +14 -0
- package/dist/runtime/types/score/layout-map.d.ts +2 -0
- package/dist/runtime/types/score/layout.d.ts +5 -0
- package/dist/runtime/vextab.js +10 -10
- package/package.json +1 -1
- package/dist/runtime/shared/OKFI2OP5.mjs +0 -1
- package/dist/runtime/shared/OWAKZY4J.mjs +0 -352
package/dist/runtime/vextab.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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. */
|
|
1
|
+
var vextab=(()=>{var Pi=Object.create;var on=Object.defineProperty;var Ti=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var _i=Object.getPrototypeOf,Ai=Object.prototype.hasOwnProperty;var Kn=(o,e)=>()=>{try{return e||o((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},Rr=(o,e)=>{for(var n in e)on(o,n,{get:e[n],enumerable:!0})},Cr=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ni(e))!Ai.call(o,s)&&s!==n&&on(o,s,{get:()=>e[s],enumerable:!(t=Ti(e,s))||t.enumerable});return o};var Se=(o,e,n)=>(n=o!=null?Pi(_i(o)):{},Cr(e||!o||!o.__esModule?on(n,"default",{value:o,enumerable:!0}):n,o)),Ri=o=>Cr(on({},"__esModule",{value:!0}),o);var an=Kn((Ir,Br)=>{(function(o,e){typeof define=="function"&&define.amd?define(function(){return e(o)}):e(o)})(Ir,function(){var o=(function(){var e,n,t,s,r=[],a=r.concat,i=r.filter,l=r.slice,c=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+|!)[^>]*>/,S=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,x=/^(?:body|html)$/i,T=/([A-Z])/g,B=["val","css","html","text","data","width","height","offset"],H=["after","prepend","before","append"],_=c.createElement("table"),M=c.createElement("tr"),V={tr:c.createElement("tbody"),tbody:_,thead:_,tfoot:_,td:M,th:M,"*":c.createElement("div")},j=/complete|loaded|interactive/,q=/^[\w-]*$/,z={},R=z.toString,N={},W,E,A=c.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"},D=Array.isArray||function(d){return d instanceof Array};N.matches=function(d,p){if(!p||!d||d.nodeType!==1)return!1;var w=d.matches||d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.matchesSelector;if(w)return w.call(d,p);var I,U=d.parentNode,G=!U;return G&&(U=A).appendChild(d),I=~N.qsa(U,p).indexOf(d),G&&A.removeChild(d),I};function Y(d){return d==null?String(d):z[R.call(d)]||"object"}function ne(d){return Y(d)=="function"}function se(d){return d!=null&&d==d.window}function re(d){return d!=null&&d.nodeType==d.DOCUMENT_NODE}function le(d){return Y(d)=="object"}function ae(d){return le(d)&&!se(d)&&Object.getPrototypeOf(d)==Object.prototype}function te(d){var p=!!d&&"length"in d&&d.length,w=t.type(d);return w!="function"&&!se(d)&&(w=="array"||p===0||typeof p=="number"&&p>0&&p-1 in d)}function Q(d){return i.call(d,function(p){return p!=null})}function J(d){return d.length>0?t.fn.concat.apply([],d):d}W=function(d){return d.replace(/-+(.)?/g,function(p,w){return w?w.toUpperCase():""})};function ce(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()}E=function(d){return i.call(d,function(p,w){return d.indexOf(p)==w})};function oe(d){return d in f?f[d]:f[d]=new RegExp("(^|\\s)"+d+"(\\s|$)")}function ue(d,p){return typeof p=="number"&&!m[ce(d)]?p+"px":p}function C(d){var p,w;return u[d]||(p=c.createElement(d),c.body.appendChild(p),w=getComputedStyle(p,"").getPropertyValue("display"),p.parentNode.removeChild(p),w=="none"&&(w="block"),u[d]=w),u[d]}function $(d){return"children"in d?l.call(d.children):t.map(d.childNodes,function(p){if(p.nodeType==1)return p})}function Z(d,p){var w,I=d?d.length:0;for(w=0;w<I;w++)this[w]=d[w];this.length=I,this.selector=p||""}N.fragment=function(d,p,w){var I,U,G;return S.test(d)&&(I=t(c.createElement(RegExp.$1))),I||(d.replace&&(d=d.replace(k,"<$1></$2>")),p===e&&(p=h.test(d)&&RegExp.$1),p in V||(p="*"),G=V[p],G.innerHTML=""+d,I=t.each(l.call(G.childNodes),function(){G.removeChild(this)})),ae(w)&&(U=t(I),t.each(w,function(de,fe){B.indexOf(de)>-1?U[de](fe):U.attr(de,fe)})),I},N.Z=function(d,p){return new Z(d,p)},N.isZ=function(d){return d instanceof N.Z},N.init=function(d,p){var w;if(d)if(typeof d=="string")if(d=d.trim(),d[0]=="<"&&h.test(d))w=N.fragment(d,RegExp.$1,p),d=null;else{if(p!==e)return t(p).find(d);w=N.qsa(c,d)}else{if(ne(d))return t(c).ready(d);if(N.isZ(d))return d;if(D(d))w=Q(d);else if(le(d))w=[d],d=null;else if(h.test(d))w=N.fragment(d.trim(),RegExp.$1,p),d=null;else{if(p!==e)return t(p).find(d);w=N.qsa(c,d)}}else return N.Z();return N.Z(w,d)},t=function(d,p){return N.init(d,p)};function O(d,p,w){for(n in p)w&&(ae(p[n])||D(p[n]))?(ae(p[n])&&!ae(d[n])&&(d[n]={}),D(p[n])&&!D(d[n])&&(d[n]=[]),O(d[n],p[n],w)):p[n]!==e&&(d[n]=p[n])}t.extend=function(d){var p,w=l.call(arguments,1);return typeof d=="boolean"&&(p=d,d=w.shift()),w.forEach(function(I){O(d,I,p)}),d},N.qsa=function(d,p){var w,I=p[0]=="#",U=!I&&p[0]==".",G=I||U?p.slice(1):p,de=q.test(G);return d.getElementById&&de&&I?(w=d.getElementById(G))?[w]:[]:d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11?[]:l.call(de&&!I&&d.getElementsByClassName?U?d.getElementsByClassName(G):d.getElementsByTagName(p):d.querySelectorAll(p))};function b(d,p){return p==null?t(d):t(d).filter(p)}t.contains=c.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,w,I){return ne(p)?p.call(d,w,I):p}function y(d,p,w){w==null?d.removeAttribute(p):d.setAttribute(p,w)}function P(d,p){var w=d.className||"",I=w&&w.baseVal!==e;if(p===e)return I?w.baseVal:w;I?w.baseVal=p:d.className=p}function F(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=Y,t.isFunction=ne,t.isWindow=se,t.isArray=D,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),w=typeof d;return d!=null&&w!="boolean"&&(w!="string"||d.length)&&!isNaN(p)&&isFinite(p)||!1},t.inArray=function(d,p,w){return r.indexOf.call(p,d,w)},t.camelCase=W,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 w,I=[],U,G;if(te(d))for(U=0;U<d.length;U++)w=p(d[U],U),w!=null&&I.push(w);else for(G in d)w=p(d[G],G),w!=null&&I.push(w);return J(I)},t.each=function(d,p){var w,I;if(te(d)){for(w=0;w<d.length;w++)if(p.call(d[w],w,d[w])===!1)return d}else for(I in d)if(p.call(d[I],I,d[I])===!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){z["[object "+p+"]"]=p.toLowerCase()}),t.fn={constructor:N.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,w=[];for(d=0;d<arguments.length;d++)p=arguments[d],w[d]=N.isZ(p)?p.toArray():p;return a.apply(N.isZ(this)?this.toArray():this,w)},map:function(d){return t(t.map(this,function(p,w){return d.call(p,w,p)}))},slice:function(){return t(l.apply(this,arguments))},ready:function(d){return j.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(p,w){return d.call(p,w,p)!==!1}),this},filter:function(d){return ne(d)?this.not(this.not(d)):t(i.call(this,function(p){return N.matches(p,d)}))},add:function(d,p){return t(E(this.concat(t(d,p))))},is:function(d){return this.length>0&&N.matches(this[0],d)},not:function(d){var p=[];if(ne(d)&&d.call!==e)this.each(function(I){d.call(this,I)||p.push(this)});else{var w=typeof d=="string"?this.filter(d):te(d)&&ne(d.item)?l.call(d):t(d);this.forEach(function(I){w.indexOf(I)<0&&p.push(I)})}return t(p)},has:function(d){return this.filter(function(){return le(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&&!le(d)?d:t(d)},last:function(){var d=this[this.length-1];return d&&!le(d)?d:t(d)},find:function(d){var p,w=this;return d?typeof d=="object"?p=t(d).filter(function(){var I=this;return r.some.call(w,function(U){return t.contains(U,I)})}):this.length==1?p=t(N.qsa(this[0],d)):p=this.map(function(){return N.qsa(this,d)}):p=t(),p},closest:function(d,p){var w=[],I=typeof d=="object"&&t(d);return this.each(function(U,G){for(;G&&!(I?I.indexOf(G)>=0:N.matches(G,d));)G=G!==p&&!re(G)&&G.parentNode;G&&w.indexOf(G)<0&&w.push(G)}),t(w)},parents:function(d){for(var p=[],w=this;w.length>0;)w=t.map(w,function(I){if((I=I.parentNode)&&!re(I)&&p.indexOf(I)<0)return p.push(I),I});return b(p,d)},parent:function(d){return b(E(this.pluck("parentNode")),d)},children:function(d){return b(this.map(function(){return $(this)}),d)},contents:function(){return this.map(function(){return this.contentDocument||l.call(this.childNodes)})},siblings:function(d){return b(this.map(function(p,w){return i.call($(w.parentNode),function(I){return I!==w})}),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=C(this.nodeName))})},replaceWith:function(d){return this.before(d).remove()},wrap:function(d){var p=ne(d);if(this[0]&&!p)var w=t(d).get(0),I=w.parentNode||this.length>1;return this.each(function(U){t(this).wrapAll(p?d.call(this,U):I?w.cloneNode(!0):w)})},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=ne(d);return this.each(function(w){var I=t(this),U=I.contents(),G=p?d.call(this,w):d;U.length?U.wrapAll(G):I.append(G)})},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 w=this.innerHTML;t(this).empty().append(g(this,d,p,w))}):0 in this?this[0].innerHTML:null},text:function(d){return 0 in arguments?this.each(function(p){var w=g(this,d,p,this.textContent);this.textContent=w==null?"":""+w}):0 in this?this.pluck("textContent").join(""):null},attr:function(d,p){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(I){if(this.nodeType===1)if(le(d))for(n in d)y(this,n,d[n]);else y(this,d,g(this,p,I,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(w){this[d]=g(this,p,w,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 w="data-"+d.replace(T,"-$1").toLowerCase(),I=1 in arguments?this.attr(w,p):this.attr(w);return I!==null?F(I):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(w){var I=t(this),U=g(this,d,w,I.offset()),G=I.offsetParent().offset(),de={top:U.top-G.top,left:U.left-G.left};I.css("position")=="static"&&(de.position="relative"),I.css(de)});if(!this.length)return null;if(c.documentElement!==this[0]&&!t.contains(c.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 w=this[0];if(typeof d=="string")return w?w.style[W(d)]||getComputedStyle(w,"").getPropertyValue(d):void 0;if(D(d)){if(!w)return;var I={},U=getComputedStyle(w,"");return t.each(d,function(de,fe){I[fe]=w.style[W(fe)]||U.getPropertyValue(fe)}),I}}var G="";if(Y(d)=="string")!p&&p!==0?this.each(function(){this.style.removeProperty(ce(d))}):G=ce(d)+":"+ue(d,p);else for(n in d)!d[n]&&d[n]!==0?this.each(function(){this.style.removeProperty(ce(n))}):G+=ce(n)+":"+ue(n,d[n])+";";return this.each(function(){this.style.cssText+=";"+G})},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(P(p))},oe(d)):!1},addClass:function(d){return d?this.each(function(p){if("className"in this){s=[];var w=P(this),I=g(this,d,p,w);I.split(/\s+/g).forEach(function(U){t(this).hasClass(U)||s.push(U)},this),s.length&&P(this,w+(w?" ":"")+s.join(" "))}}):this},removeClass:function(d){return this.each(function(p){if("className"in this){if(d===e)return P(this,"");s=P(this),g(this,d,p,s).split(/\s+/g).forEach(function(w){s=s.replace(oe(w)," ")}),P(this,s.trim())}})},toggleClass:function(d,p){return d?this.each(function(w){var I=t(this),U=g(this,d,w,P(this));U.split(/\s+/g).forEach(function(G){(p===e?!I.hasClass(G):p)?I.addClass(G):I.removeClass(G)})}):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(),w=this.offset(),I=x.test(p[0].nodeName)?{top:0,left:0}:p.offset();return w.top-=parseFloat(t(d).css("margin-top"))||0,w.left-=parseFloat(t(d).css("margin-left"))||0,I.top+=parseFloat(t(p[0]).css("border-top-width"))||0,I.left+=parseFloat(t(p[0]).css("border-left-width"))||0,{top:w.top-I.top,left:w.left-I.left}}},offsetParent:function(){return this.map(function(){for(var d=this.offsetParent||c.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(w){return w[0].toUpperCase()});t.fn[d]=function(w){var I,U=this[0];return w===e?se(U)?U["inner"+p]:re(U)?U.documentElement["scroll"+p]:(I=this.offset())&&I[d]:this.each(function(G){U=t(this),U.css(d,g(this,w,G,U[d]()))})}});function v(d,p){p(d);for(var w=0,I=d.childNodes.length;w<I;w++)v(d.childNodes[w],p)}return H.forEach(function(d,p){var w=p%2;t.fn[d]=function(){var I,U=t.map(arguments,function(fe){var he=[];return I=Y(fe),I=="array"?(fe.forEach(function(pe){if(pe.nodeType!==e)return he.push(pe);if(t.zepto.isZ(pe))return he=he.concat(pe.get());he=he.concat(N.fragment(pe))}),he):I=="object"||fe==null?fe:N.fragment(fe)}),G,de=this.length>1;return U.length<1?this:this.each(function(fe,he){G=w?he:he.parentNode,he=p==0?he.nextSibling:p==1?he.firstChild:p==2?he:null;var pe=t.contains(c.documentElement,G);U.forEach(function(Le){if(de)Le=Le.cloneNode(!0);else if(!G)return t(Le).remove();G.insertBefore(Le,he),pe&&v(Le,function(Ae){if(Ae.nodeName!=null&&Ae.nodeName.toUpperCase()==="SCRIPT"&&(!Ae.type||Ae.type==="text/javascript")&&!Ae.src){var ve=Ae.ownerDocument?Ae.ownerDocument.defaultView:window;ve.eval.call(ve,Ae.innerHTML)}})})})},t.fn[w?d+"To":"insert"+(p?"Before":"After")]=function(I){return t(I)[d](this),this}}),N.Z.prototype=Z.prototype=t.fn,N.uniq=E,N.deserializeValue=F,t.zepto=N,t})();return window.Zepto=o,window.$===void 0&&(window.$=o),Br.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 m(R){return R._zid||(R._zid=n++)}function h(R,N,W,E){if(N=S(N),N.ns)var A=k(N.ns);return(i[m(R)]||[]).filter(function(L){return L&&(!N.e||L.e==N.e)&&(!N.ns||A.test(L.ns))&&(!W||m(L.fn)===m(W))&&(!E||L.sel==E)})}function S(R){var N=(""+R).split(".");return{e:N[0],ns:N.slice(1).sort().join(" ")}}function k(R){return new RegExp("(?:^| )"+R.replace(" "," .* ?")+"(?: |$)")}function x(R,N){return R.del&&!c&&R.e in u||!!N}function T(R){return f[R]||c&&u[R]||R}function B(R,N,W,E,A,L,D){var Y=m(R),ne=i[Y]||(i[Y]=[]);N.split(/\s/).forEach(function(se){if(se=="ready")return e(document).ready(W);var re=S(se);re.fn=W,re.sel=A,re.e in f&&(W=function(ae){var te=ae.relatedTarget;if(!te||te!==this&&!e.contains(this,te))return re.fn.apply(this,arguments)}),re.del=L;var le=L||W;re.proxy=function(ae){if(ae=q(ae),!ae.isImmediatePropagationStopped()){ae.data=E;var te=le.apply(R,ae._args==t?[ae]:[ae].concat(ae._args));return te===!1&&(ae.preventDefault(),ae.stopPropagation()),te}},re.i=ne.length,ne.push(re),"addEventListener"in R&&R.addEventListener(T(re.e),re.proxy,x(re,D))})}function H(R,N,W,E,A){var L=m(R);(N||"").split(/\s/).forEach(function(D){h(R,D,W,E).forEach(function(Y){delete i[L][Y.i],"removeEventListener"in R&&R.removeEventListener(T(Y.e),Y.proxy,x(Y,A))})})}e.event={add:B,remove:H},e.proxy=function(R,N){var W=2 in arguments&&s.call(arguments,2);if(r(R)){var E=function(){return R.apply(N,W?W.concat(s.call(arguments)):arguments)};return E._zid=m(R),E}else{if(a(N))return W?(W.unshift(R[N],R),e.proxy.apply(null,W)):e.proxy(R[N],R);throw new TypeError("expected function")}},e.fn.bind=function(R,N,W){return this.on(R,N,W)},e.fn.unbind=function(R,N){return this.off(R,N)},e.fn.one=function(R,N,W,E){return this.on(R,N,W,E,1)};var _=function(){return!0},M=function(){return!1},V=/^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/,j={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};function q(R,N){return(N||!R.isDefaultPrevented)&&(N||(N=R),e.each(j,function(W,E){var A=N[W];R[W]=function(){return this[E]=_,A&&A.apply(N,arguments)},R[E]=M}),R.timeStamp||(R.timeStamp=Date.now()),(N.defaultPrevented!==t?N.defaultPrevented:"returnValue"in N?N.returnValue===!1:N.getPreventDefault&&N.getPreventDefault())&&(R.isDefaultPrevented=_)),R}function z(R){var N,W={originalEvent:R};for(N in R)!V.test(N)&&R[N]!==t&&(W[N]=R[N]);return q(W,R)}e.fn.delegate=function(R,N,W){return this.on(N,R,W)},e.fn.undelegate=function(R,N,W){return this.off(N,R,W)},e.fn.live=function(R,N){return e(document.body).delegate(this.selector,R,N),this},e.fn.die=function(R,N){return e(document.body).undelegate(this.selector,R,N),this},e.fn.on=function(R,N,W,E,A){var L,D,Y=this;return R&&!a(R)?(e.each(R,function(ne,se){Y.on(ne,N,W,se,A)}),Y):(!a(N)&&!r(E)&&E!==!1&&(E=W,W=N,N=t),(E===t||W===!1)&&(E=W,W=t),E===!1&&(E=M),Y.each(function(ne,se){A&&(L=function(re){return H(se,re.type,E),E.apply(this,arguments)}),N&&(D=function(re){var le,ae=e(re.target).closest(N,se).get(0);if(ae&&ae!==se)return le=e.extend(z(re),{currentTarget:ae,liveFired:se}),(L||E).apply(ae,[le].concat(s.call(arguments,1)))}),B(se,R,E,W,N,D||L)}))},e.fn.off=function(R,N,W){var E=this;return R&&!a(R)?(e.each(R,function(A,L){E.off(A,N,L)}),E):(!a(N)&&!r(W)&&W!==!1&&(W=N,N=t),W===!1&&(W=M),E.each(function(){H(this,R,W,N)}))},e.fn.trigger=function(R,N){return R=a(R)||e.isPlainObject(R)?e.Event(R):q(R),R._args=N,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,N)})},e.fn.triggerHandler=function(R,N){var W,E;return this.each(function(A,L){W=z(a(R)?e.Event(R):R),W._args=N,W.target=L,e.each(h(L,R.type||R),function(D,Y){if(E=Y.proxy(W),W.isImmediatePropagationStopped())return!1})}),E},"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(N){return 0 in arguments?this.bind(R,N):this.trigger(R)}}),e.Event=function(R,N){a(R)||(N=R,R=N.type);var W=document.createEvent(l[R]||"Events"),E=!0;if(N)for(var A in N)A=="bubbles"?E=!!N[A]:W[A]=N[A];return W.initEvent(R,E,!0),q(W)}})(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*$/,m=t.createElement("a");m.href=window.location.href;function h(E,A,L){var D=e.Event(A);return e(E).trigger(D,L),!D.isDefaultPrevented()}function S(E,A,L,D){if(E.global)return h(A||t,L,D)}e.active=0;function k(E){E.global&&e.active++===0&&S(E,null,"ajaxStart")}function x(E){E.global&&!--e.active&&S(E,null,"ajaxStop")}function T(E,A){var L=A.context;if(A.beforeSend.call(L,E,A)===!1||S(A,L,"ajaxBeforeSend",[E,A])===!1)return!1;S(A,L,"ajaxSend",[E,A])}function B(E,A,L,D){var Y=L.context,ne="success";L.success.call(Y,E,ne,A),D&&D.resolveWith(Y,[E,ne,A]),S(L,Y,"ajaxSuccess",[A,L,E]),_(ne,A,L)}function H(E,A,L,D,Y){var ne=D.context;D.error.call(ne,L,A,E),Y&&Y.rejectWith(ne,[L,A,E]),S(D,ne,"ajaxError",[L,D,E||A]),_(A,L,D)}function _(E,A,L){var D=L.context;L.complete.call(D,A,E),S(L,D,"ajaxComplete",[A,L]),x(L)}function M(E,A,L){if(L.dataFilter==V)return E;var D=L.context;return L.dataFilter.call(D,E,A)}function V(){}e.ajaxJSONP=function(E,A){if(!("type"in E))return e.ajax(E);var L=E.jsonpCallback,D=(e.isFunction(L)?L():L)||"Zepto"+n++,Y=t.createElement("script"),ne=window[D],se,re=function(te){e(Y).triggerHandler("error",te||"abort")},le={abort:re},ae;return A&&A.promise(le),e(Y).on("load error",function(te,Q){clearTimeout(ae),e(Y).off().remove(),te.type=="error"||!se?H(null,Q||"error",le,E,A):B(se[0],le,E,A),window[D]=ne,se&&e.isFunction(ne)&&ne(se[0]),ne=se=void 0}),T(le,E)===!1?(re("abort"),le):(window[D]=function(){se=arguments},Y.src=E.url.replace(/\?(.+)=\?/,"?$1="+D),t.head.appendChild(Y),E.timeout>0&&(ae=setTimeout(function(){re("timeout")},E.timeout)),le)},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 j(E){return E&&(E=E.split(";",2)[0]),E&&(E==u?"html":E==c?"json":i.test(E)?"script":l.test(E)&&"xml")||"text"}function q(E,A){return A==""?E:(E+"&"+A).replace(/[&?]{1,2}/,"?")}function z(E){E.processData&&E.data&&e.type(E.data)!="string"&&(E.data=e.param(E.data,E.traditional)),E.data&&(!E.type||E.type.toUpperCase()=="GET"||E.dataType=="jsonp")&&(E.url=q(E.url,E.data),E.data=void 0)}e.ajax=function(E){var A=e.extend({},E||{}),L=e.Deferred&&e.Deferred(),D,Y;for(s in e.ajaxSettings)A[s]===void 0&&(A[s]=e.ajaxSettings[s]);k(A),A.crossDomain||(D=t.createElement("a"),D.href=A.url,D.href=D.href,A.crossDomain=m.protocol+"//"+m.host!=D.protocol+"//"+D.host),A.url||(A.url=window.location.toString()),(Y=A.url.indexOf("#"))>-1&&(A.url=A.url.slice(0,Y)),z(A);var ne=A.dataType,se=/\?.+=\?/.test(A.url);if(se&&(ne="jsonp"),(A.cache===!1||(!E||E.cache!==!0)&&(ne=="script"||ne=="jsonp"))&&(A.url=q(A.url,"_="+Date.now())),ne=="jsonp")return se||(A.url=q(A.url,A.jsonp?A.jsonp+"=?":A.jsonp===!1?"":"callback=?")),e.ajaxJSONP(A,L);var re=A.accepts[ne],le={},ae=function(ue,C){le[ue.toLowerCase()]=[ue,C]},te=/^([\w-]+:)\/\//.test(A.url)?RegExp.$1:window.location.protocol,Q=A.xhr(),J=Q.setRequestHeader,ce;if(L&&L.promise(Q),A.crossDomain||ae("X-Requested-With","XMLHttpRequest"),ae("Accept",re||"*/*"),(re=A.mimeType||re)&&(re.indexOf(",")>-1&&(re=re.split(",",2)[0]),Q.overrideMimeType&&Q.overrideMimeType(re)),(A.contentType||A.contentType!==!1&&A.data&&A.type.toUpperCase()!="GET")&&ae("Content-Type",A.contentType||"application/x-www-form-urlencoded"),A.headers)for(r in A.headers)ae(r,A.headers[r]);if(Q.setRequestHeader=ae,Q.onreadystatechange=function(){if(Q.readyState==4){Q.onreadystatechange=V,clearTimeout(ce);var ue,C=!1;if(Q.status>=200&&Q.status<300||Q.status==304||Q.status==0&&te=="file:"){if(ne=ne||j(A.mimeType||Q.getResponseHeader("content-type")),Q.responseType=="arraybuffer"||Q.responseType=="blob")ue=Q.response;else{ue=Q.responseText;try{ue=M(ue,ne,A),ne=="script"?(0,eval)(ue):ne=="xml"?ue=Q.responseXML:ne=="json"&&(ue=f.test(ue)?null:e.parseJSON(ue))}catch($){C=$}if(C)return H(C,"parsererror",Q,A,L)}B(ue,Q,A,L)}else H(Q.statusText||null,Q.status?"error":"abort",Q,A,L)}},T(Q,A)===!1)return Q.abort(),H(null,"abort",Q,A,L),Q;var oe="async"in A?A.async:!0;if(Q.open(A.type,A.url,oe,A.username,A.password),A.xhrFields)for(r in A.xhrFields)Q[r]=A.xhrFields[r];for(r in le)J.apply(Q,le[r]);return A.timeout>0&&(ce=setTimeout(function(){Q.onreadystatechange=V,Q.abort(),H(null,"timeout",Q,A,L)},A.timeout)),Q.send(A.data?A.data:null),Q};function R(E,A,L,D){return e.isFunction(A)&&(D=L,L=A,A=void 0),e.isFunction(L)||(D=L,L=void 0),{url:E,data:A,success:L,dataType:D}}e.get=function(){return e.ajax(R.apply(null,arguments))},e.post=function(){var E=R.apply(null,arguments);return E.type="POST",e.ajax(E)},e.getJSON=function(){var E=R.apply(null,arguments);return E.dataType="json",e.ajax(E)},e.fn.load=function(E,A,L){if(!this.length)return this;var D=this,Y=E.split(/\s/),ne,se=R(E,A,L),re=se.success;return Y.length>1&&(se.url=Y[0],ne=Y[1]),se.success=function(le){D.html(ne?e("<div>").html(le.replace(a,"")).find(ne):le),re&&re.apply(D,arguments)},e.ajax(se),this};var N=encodeURIComponent;function W(E,A,L,D){var Y,ne=e.isArray(A),se=e.isPlainObject(A);e.each(A,function(re,le){Y=e.type(le),D&&(re=L?D:D+"["+(se||Y=="object"||Y=="array"?re:"")+"]"),!D&&ne?E.add(le.name,le.value):Y=="array"||!L&&Y=="object"?W(E,le,L,re):E.add(re,le)})}e.param=function(E,A){var L=[];return L.add=function(D,Y){e.isFunction(Y)&&(Y=Y()),Y==null&&(Y=""),this.push(N(D)+"="+N(Y))},W(L,E,A),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 Me=Kn((ea,Hr)=>{if(!window.VexFlow)throw new Error("Load vexflow.js before vextab.js.");Hr.exports=window.VexFlow});var Si=Kn(()=>{var ki=document.createElement("style");ki.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(ki)});var $o={};Rr($o,{Artist:()=>Ye,Div:()=>Et,Player:()=>Xe,ScoreError:()=>ee,ScoreV2Error:()=>Je,Vex:()=>X,VexTab:()=>$e,createPerformer:()=>Sr,createSpessaSynthPlayback:()=>qn,createWebAudioPlayback:()=>pt,isPerformerName:()=>wt,parseScore:()=>ot,performerProfiles:()=>Qt,renderConductor:()=>Gn,renderEdition:()=>xi,renderScore:()=>Ut,renderScorePart:()=>Wn,resolvePart:()=>Ei});var Ar={};Rr(Ar,{Artist:()=>Ye,Div:()=>Kt,Flow:()=>Mi,Player:()=>Xe,ScoreError:()=>ee,ScoreV2Error:()=>Je,VexTab:()=>$e,createSpessaSynthPlayback:()=>qn,createWebAudioPlayback:()=>pt,parseScore:()=>ot,renderScore:()=>Ut,renderScorePart:()=>Wn});var Un=Se(an());var _r=Se(an());function Mt(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 Fr(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 Ci(o,e,n,t){let s=new Map,r=new Map;for(let l of o){let{partIndex:c,score:u,local:f,view:m}=l,h=u.measures[e-1],S=f.staves[e-1];S.forEach((k,x)=>s.set(k,{partIndex:c,staffIndex:x,bounds:Fr(k)}));for(let[k,x]of m.staves.entries())for(let T of h.voices)if(!(T.hand&&T.hand!==x))for(let B of T.events){let H=Mt(B.onset),_=f.getNote(m.eventId(x,B.id)),M=r.get(H);if(!M){let q=_.getAbsoluteX()-(_.isCenterAligned()?_.getCenterXShift():0);M={time:H,x:q,events:new Map},r.set(H,M)}let V=s.get(_.getStave())??s.get(S[k]),j=M.events.get(V);j?j.push(B.id):M.events.set(V,[B.id])}}let a=[...r.values()].sort((l,c)=>l.time-c.time),i=[...s.values()];return a.push({time:Mt(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 Vr(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 Or(o,e,n,t,s){return t+(o-e)/(n-e)*(s-t)}function Xt(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 Yt=.5;function Ii(o,e,n){let t=o.anchors;if(e<t[0].x-Yt||e>t[t.length-1].x+Yt)return;let s=o.staves.find(c=>n>=c.bounds.top&&n<=c.bounds.bottom);if(!s)return;let r=Math.min(t.length-1,Vr(t,e,"x")),a=t[r],i=t[r-1],l=i&&e-i.x<a.x-e?i:a;return Math.abs(l.x-e)<=Yt?Xt(o,s,l.time,l.x,l):Xt(o,s,Or(e,i.x,a.x,i.time,a.time),e)}function cn(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 Lr(o,e,n,t,s){let r=o.sheet.getContinuousLayout().rows,a=[],i=r.map(l=>{let c=l.measures.flatMap(u=>o.staves[u-1].map(Fr));return{left:Math.min(...c.map(u=>u.left)),right:Math.max(...c.map(u=>u.right)),top:Math.min(...c.map(u=>u.top)),bottom:Math.max(...c.map(u=>u.bottom))}});return r.forEach((l,c)=>{for(let u of l.measures)a[u-1]=Ci(e,u,c+1,i[c])}),{clientPoint:s,positionAt({partIndex:l,staffIndex:c=0,measure:u,offset:f}){if(!Number.isInteger(u))return;let m=a[u-1],h=m?.staves.find(B=>B.partIndex===l&&B.staffIndex===c),S=Mt(f);if(!h||!Number.isFinite(S)||S<0)return;let k=Vr(m.anchors,S,"time"),x=m.anchors[k];if(!x)return;if(x.time===S)return Xt(m,h,S,x.x,x);let T=m.anchors[k-1];if(T)return Xt(m,h,S,Or(S,T.time,x.time,T.x,x.x))},hitTest({x:l,y:c}){if(!Number.isFinite(l)||!Number.isFinite(c))return;let u=i.findIndex(k=>c>=k.top&&c<=k.bottom&&l>=k.left-Yt&&l<=k.right+Yt);if(u>=0)for(let k of r[u].measures){let x=Ii(a[k-1],l,c);if(x)return x}let f=n.hitTest(l,c);if(!f||f.reference||f.role==="mark")return;let m=a[f.measure-1],h=m.staves[t.findIndex(k=>k.id===f.staff)],S=m.anchors.find(k=>k.events.get(h)?.includes(f.sourceEvent));if(S)return Xt(m,h,S.time,S.x,S)}}}var Ie=Se(an());var We=Se(Me());We.default.Flow||(We.default.Flow=We.default);!We.default.RERR&&We.default.RuntimeError&&(We.default.RERR=We.default.RuntimeError);We.default.BM||(We.default.BM=(o,e)=>e());var X=We.default;var Bi=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 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+`
|
|
364
|
+
`.trim().split(/\s+/));function Fe(o){return Bi.has(o.toLowerCase())||/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(o)}function we(o){return{fillStyle:o,strokeStyle:o}}function ln(o,e){let n=getComputedStyle(e).backgroundColor;n&&!n.startsWith("rgba(")&&!n.includes("/")&&o.setBackgroundFillStyle(n)}var Qe=Se(Me()),Xn="Academico",ze=()=>Qe.default.getTextFonts()[0],bt=()=>Qe.default.getFonts()[0],Pt=()=>ze()==="Petaluma Script"?"normal":"bold";function yt(o,e){if(!o)return e();let n=Qe.default.getFonts(),t=Qe.default.getTextFonts();try{return o==="Petaluma"?Qe.default.setFonts("Petaluma","Petaluma Script"):Qe.default.setFonts("Bravura",Xn),e()}finally{Qe.default.setFonts(...n),Qe.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 un(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 Dr(o,e){un(o,e)}function zr(o,e){let n=[];return un(o,(t,s)=>n.push(e(t,s))),n}function et(o,...e){let n=e.filter(t=>t!=null);return Object.assign(o,...n)}function jr(o){return o?Object.keys(o):[]}function Yn(o,e){return o?Object.prototype.hasOwnProperty.call(o,e):!1}function dn(o,...e){let n={};return e.forEach(t=>{Yn(o,t)&&(n[t]=o[t])}),n}var Te=Se(Me()),fn=class{constructor(e){this.artist=e}prepareStave(e,n){if(!e)return[];let t=X.Flow.Barline.type,s=t.SINGLE,r=n.map(a=>{let i=me(a);return i instanceof X.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 Te.Beam(e.slice(l,c),i===void 0);return u.renderOptions.showStemlets=a["beam-stemlets"]==="true",u}):Te.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 Te.Annotation&&i.getVerticalJustification()===Te.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 Te.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 Te.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 Te.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=(T,B,H)=>T.flatMap((_,M)=>{if(!_.length)return[];_.forEach(j=>j.setStave(B));let V=new Te.Voice(n.meter).setMode(Te.Voice.Mode.SOFT).addTickables(_);return r.push(...this.makeBeams(_,n.voiceSettings[M],n,M,H)),[V]}),i=n.tab,l=n.note,c=a(t,i,!0),u=a(s,l,!1),f=l||i,m=f,S=n.text_voices.filter(T=>T.length).map(T=>{let B=this.alignTextBars(T,s[0]??t[0]??[]);return B.forEach(H=>H.setStave(m)),new Te.Voice(n.meter).setMode(Te.Voice.Mode.SOFT).addTickables(B)}),k=new Te.Formatter,x=[...c,...u,...S];for(let T of[c,u,S])T.length&&k.joinVoices(T);x.length&&k.formatToStave(x,f,{alignRests:u.length>1});for(let T of c)this.alignTopAnnotations(T,i),T.draw(e,i);for(let T of u)T.draw(e,l);for(let T of r)T.setContext(e).draw();for(let T of S)T.draw(e,m);return i&&l&&new X.Flow.StaveConnector(l,i).setType(X.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(we(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 Re=Se(Me());var Fi={left:Re.Modifier.Position.LEFT,right:Re.Modifier.Position.RIGHT,above:Re.Modifier.Position.ABOVE,below:Re.Modifier.Position.BELOW};function Jn(o,e,n=!1,t=!1){let s=!t&&(e===Re.Modifier.Position.LEFT||e===Re.Modifier.Position.RIGHT),r=n?new Re.StringNumber(o):new Re.FretHandFinger(o,{headPlacement:s}).setDrawCircle(t&&/^\d$/.test(o));return r.setPosition(e),r}function Tt(o,e,n,t,s=!1,r=!1){for(let a of n){let i=Fi[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"?Re.Annotation.VerticalJustify.TOP:Re.Annotation.VerticalJustify.BOTTOM;o.addModifier(new Re.Annotation(a.finger).setFont(ze(),11).setVerticalJustification(l),e);continue}o.addModifier(Jn(a.finger,i,a.stringNumber,t),e)}else o.addModifier(new Re.Articulation(a.articulation??"a>").setPosition(i),e)}}function $n(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 Zn(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 Vi(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?Zn(l,!i,s,e):i?n:t}})}function Gr(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=Zn(c.value,!1,n,c.range??e(c._l,c._c))),c.key==="accents"&&(l=Zn(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=Vi(u.suffix.text,u.suffix.range,i,l,n),delete u.suffix)}}var K=function(o,e,n={}){return o.forEach(t=>n[t]=e),n},Wr=[1,6],qr=[1,7],Ur=[1,8],Kr=[1,9],Xr=[1,10],Jt=[5,11,13,14,15,16],lt=[5,11,13,14,15,16,18,20,22],Yr=[2,18],Qn=[1,15],ut=[5,11,13,14,15,16,18,20,22,24],Jr=[1,19],$r=[1,20],Zr=[1,21],Qr=[1,22],es=[1,46],ts=[1,31],ns=[1,35],rs=[1,36],mn=[1,42],ss=[1,45],is=[1,44],tt=[1,60],nt=[1,61],rt=[1,62],Nt=[1,58],_t=[1,53],At=[1,54],Rt=[1,55],Ct=[1,56],It=[1,57],Bt=[1,59],os=[1,47],as=[1,48],cs=[1,49],ls=[1,50],st=[1,63],us=[1,67],ds=[1,68],fs=[5,11,13,14,15,16,18,20,22,28],ge=[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],er=[2,94],tr=[1,80],nr=[1,77],rr=[1,78],sr=[1,79],pn=[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],ir=[1,83],ms=[1,88],ps=[1,89],hs=[1,90],gs=[1,91],Ve=[50,68,70,72,73,74,75,76,77,78,79,80],xt=[32,47,57,58,59,87],Ft=[50,57,68,70,72,73,74,75,76,77,78,79,80,92],bs=[1,113],hn=[34,45],gn=[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],ys=[2,77],xs=[1,120],or=[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],bn=[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],vs=[28,82],ar=[50,57,68,70,72,73,74,75,76,77,78,79,80],Oi=(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+`
|
|
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 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
|
-
`+
|
|
368
|
-
Expecting `+
|
|
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?
|
|
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 cr(){this.yy={}}cr.prototype={Parser:cr,lexer:Oi,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:Wr,13:qr,14:Ur,15:Kr,16:Xr},{1:[3]},{5:[1,11]},{5:[2,3],7:12,8:5,11:Wr,13:qr,14:Ur,15:Kr,16:Xr},K(Jt,[2,4]),K(lt,Yr,{9:13,12:14,24:Qn}),{12:16,24:Qn},K(ut,[2,9]),K(ut,[2,10]),K(ut,[2,11]),K(ut,[2,12]),{1:[2,1]},K(Jt,[2,5]),K(Jt,[2,7],{10:17,17:18,18:Jr,20:$r,22:Zr}),K(lt,[2,19],{24:Qr}),{26:[1,23]},K(Jt,[2,8],{24:Qr}),K(Jt,[2,6],{17:24,18:Jr,20:$r,22:Zr}),K(lt,[2,13]),{19:25,27:[1,26]},{21:27,26:es,29:28,30:29,31:30,32:ts,35:32,36:33,37:34,38:ns,39:rs,40:37,41:38,42:39,43:40,44:mn,46:ss,47:is,48:41,55:43,56:51,57:tt,58:nt,59:rt,60:52,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt,81:os,82:as,84:cs,86:ls,87:st},K(lt,Yr,{12:14,9:64,24:Qn}),{26:[1,65]},{23:66,24:us,25:ds},K(lt,[2,14]),K(lt,[2,15],{28:[1,69]}),K(fs,[2,24]),K(lt,[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:es,32:ts,38:ns,39:rs,44:mn,46:ss,47:is,57:tt,58:nt,59:rt,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt,81:os,82:as,84:cs,86:ls,87:st}),K(ge,[2,26]),K(ge,[2,28]),K(ge,[2,29]),{30:74,31:73,33:71,44:mn,48:41,54:72,55:75,56:51,57:tt,58:nt,59:rt,60:52,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt,87:st},K(ge,[2,31]),K(ge,[2,32]),K(ge,[2,33]),K(ge,[2,34]),K(ge,[2,35]),K(ge,[2,36]),K(ge,[2,37]),K(ge,[2,38]),K(ge,[2,39]),K([50,68,72,73,74,75,76,77],er,{49:76,70:tr,78:nr,79:rr,80:sr}),K(pn,[2,40]),{32:[1,81],47:ir,56:84,57:tt,58:nt,59:rt,60:85,62:82,87:st},{57:ms,63:86,65:87,67:ps,68:hs,69:gs},K(ge,[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]},K(Ve,[2,60]),K(Ve,[2,61],{57:[1,101]}),K(xt,[2,83]),K(xt,[2,84]),K(xt,[2,85]),K(xt,[2,86]),K(xt,[2,87]),K(xt,[2,88]),K(xt,[2,89]),K(Ve,[2,56],{58:[1,102]}),{57:[1,103]},K(Ve,[2,59]),K(Ft,[2,110],{88:104,86:[1,105],90:[1,106],91:[1,107]}),K(lt,[2,17]),{23:108,24:us,25:ds},K(ut,[2,22]),K(ut,[2,20]),K(ut,[2,21]),{27:[1,109]},K(ge,[2,27]),{34:[1,110],45:[1,111]},{34:[1,112],45:bs},K(hn,[2,41]),K(hn,[2,52]),{47:ir,56:84,57:tt,58:nt,59:rt,60:85,62:82,87:st},{50:[1,114],55:115,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt},K(gn,[2,90]),K(gn,[2,91]),K(gn,[2,92]),K(gn,[2,93]),{30:74,48:41,54:116,55:75,56:51,57:tt,58:nt,59:rt,60:52,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt,87:st},K(Ve,[2,63]),{57:ms,63:117,65:87,67:ps,68:hs,69:gs},K(Ve,[2,66]),K(Ve,[2,69],{57:[1,118]}),K(ge,ys,{64:119,70:xs}),K(or,[2,80],{66:121,71:[1,122]}),K(bn,[2,73]),K(bn,[2,74]),K(bn,[2,75]),K(bn,[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]},K(vs,[2,98]),{84:[1,132]},K(ge,[2,101]),{86:[1,133]},{57:[1,134]},{61:[1,135]},K(Ve,[2,58]),K(Ve,[2,57]),K(ar,[2,111],{89:136,92:[1,137]}),K(Ft,[2,105],{86:[1,138]}),K(Ft,[2,107],{90:[1,139]}),K(Ft,[2,109]),K(ut,[2,23]),K(fs,[2,25]),K(ge,[2,30]),{31:140,44:mn},K(ge,er,{49:141,70:tr,78:nr,79:rr,80:sr}),{30:142,48:41,55:75,56:51,57:tt,58:nt,59:rt,60:52,68:Nt,72:_t,73:At,74:Rt,75:Ct,76:It,77:Bt,87:st},{51:143,57:[1,144]},{47:ir,56:84,57:tt,58:nt,59:rt,60:85,62:145,87:st},{34:[1,146],45:bs},{47:ys,64:147,70:xs},{61:[1,148]},K(ge,[2,71]),K(ge,[2,78],{70:[1,149]}),K(or,[2,72]),K(or,[2,81]),K(ge,[2,44]),K(ge,[2,45]),K(ge,[2,47]),K(ge,[2,46]),K(ge,[2,48]),K(ge,[2,95]),{57:[1,150]},K(ge,[2,97]),{24:[1,151]},K(ge,[2,100]),K(ge,[2,102]),{86:[1,152]},{57:[1,153]},K(ar,[2,104]),K(ar,[2,112]),K(Ft,[2,106]),K(Ft,[2,108]),K(hn,[2,42]),K(ge,[2,54]),K(hn,[2,53]),K(pn,[2,51],{52:154,53:[1,155]}),K([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]),K(Ve,[2,64]),K(ge,er,{49:156,70:tr,78:nr,79:rr,80:sr}),{47:[1,157]},{57:[1,158]},K(ge,[2,79]),{81:[1,159]},K(vs,[2,99]),K(ge,[2,103]),K(Ve,[2,62]),K(pn,[2,49]),K(pn,[2,50]),K(ge,[2,55]),{56:160,57:tt,58:nt,59:rt,60:161,87:st},K(Ve,[2,70]),K(ge,[2,96]),K(Ve,[2,65]),K(Ve,[2,67],{57:[1,162]}),{61:[1,163]},{57:[1,164]},K(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:et(me(r[i-4]),{decorator:r[i-3]}),un(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.$=[et(r[i],{articulation:r[i-1],...t.locate?{range:t.locate(this._$)}:{}})];break;case 64:et(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),et(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=z=>{k.length-=2*z,x.length-=z,T.length-=z},l=()=>{let z=c.lex()||1;return typeof z!="number"&&(z=this.symbols_[z]||z),z},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 m=this.table,h={},S=c.yylloc,k=[0],x=[null],T=[S],B=[],H="",_=0,M=0,V=0,j,q;for(;;){let z=k[k.length-1],R;if(this.defaultActions[z]?R=this.defaultActions[z]:((j===null||typeof j>"u")&&(j=l()),R=m[z]&&m[z][j]),!R||!R[0]){let E=function(A){let L=k.length-1,D=0;for(;;){if("2"in m[A])return D;if(A===0||L<2)return!1;L-=2,A=k[L],++D}},N,W="";if(!V){let A=[];for(let L in m[z])L in this.terminals_&&L>2&&A.push("'"+this.terminals_[L]+"'");W=c.showPosition?"Parse error on line "+(_+1)+`:
|
|
367
|
+
`+c.showPosition()+`
|
|
368
|
+
Expecting `+A.join(", ")+", got '"+(this.terminals_[j]||j)+"'":"Parse error on line "+(_+1)+": Unexpected "+(j===1?"end of input":"'"+(this.terminals_[j]||j)+"'"),this.parseError(W,{text:c.match,token:this.terminals_[j]||j,line:c.yylineno,loc:S,expected:A})}if(V===3){if(j===1||q===1)throw new Error(W||"Parsing halted while starting to recover from another error.");M=c.yyleng,H=c.yytext,_=c.yylineno,S=c.yylloc,j=l()}if(N===!1)throw new Error(W||"Parsing halted. No suitable error recovery rule available.");i(N),q=j==2?null:j,j=2,z=k[k.length-1],R=m[z]&&m[z][2],V=3}if(Array.isArray(R[0])&&R.length>1)throw new Error("Parse Error: multiple actions possible at state: "+z+", token: "+j);switch(R[0]){case 1:k.push(j),x.push(c.yytext),T.push(c.yylloc),k.push(R[1]),j=null,q?(j=q,q=null):(M=c.yyleng,H=c.yytext,_=c.yylineno,S=c.yylloc,V>0&&V--);break;case 2:{let N=this.productions_[R[1]][1],W=T[T.length-(N||1)],E=T[T.length-1];h.$=x[x.length-N],h._$={first_line:W.first_line,last_line:E.last_line,first_column:W.first_column,last_column:E.last_column},u&&(h._$.range=[W.range[0],E.range[1]]);let A=this.performAction.call(h,H,M,_,f,R[1],x,T,...e);if(typeof A<"u")return A;N&&i(N),k.push(this.productions_[R[1]][0]),x.push(h.$),T.push(h._$),k.push(m[k[k.length-2]][k[k.length-1]]);break}case 3:return!0}}}};var Li=new cr,ws=Li;var He=Se(Me());var Vt=Se(Me());function Ce(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 ks(o){return o===1?"\xBD":o===2?"full":o+" st"}function Ot(o,e){return"Pre-bend "+ks(o.semitones)+" on string "+e+(o.release?", release":"")}function yn({semitones:o,release:e}){let n=[{type:Vt.Bend.PREBEND,text:ks(o)}];return e&&n.push({type:Vt.Bend.DOWN,text:""}),new Vt.Bend(n)}function xn(o,e,n){let[t,s]=o.getNoteForFret(e,n).split("/");return t.toLowerCase()+"/"+(Number(s)-1)}function Lt(o,e,n,t,s){let r=Vt.default.keyProperties(o.getNoteForFret(t,s));e.reset();let a=e.selectNote(r.key),i=n.getNoteParts(r.key).root,l=n.getNoteParts(a.note).root,c=r.octave;return l==="b"&&i==="c"&&c--,l==="c"&&i==="b"&&c++,[a.note,c,a.accidental??"n"]}function vn(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 vt=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,l=i==="b"||!i&&e<0,c=k=>t[k].num*2+ +(He.default.keySignature(k)[0]?.type==="b"!==l),u=Object.keys(t).filter(k=>/^[A-G][#b]?m?$/.test(k)&&k.endsWith("m")===n.endsWith("m")&&s.getNoteValue(k.replace(/m$/,"").toLowerCase())===a);this.target=u.sort((k,x)=>c(k)-c(x))[0];let f=this.target.replace(/m$/,"").toLowerCase(),m=k=>He.Music.rootIndexes[k[0]],h=k=>He.Music.rootValues[m(k)]+(k[1]==="b"?-1:+(k[1]==="#")),S=(h(r)+e-h(f))/12;this.steps=S*7+m(f)-m(r)}pitch(e,n){return He.NotationSpelling.transpose(e+"/"+n,this.semitones,this.steps)}};function Ss(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 Hi(o,e,n,t){if(o.fret!==void 0){o.fret=Ss(o.fret,e,o,t);let c=Number(o.fret)+n.capo+(o.prebend?.semitones??0),u=n.tuning.getValueForFret(c,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,l]=e.pitch(s.key+(s.accidental||""),r).split("/");o.fret===void 0&&(Number(l)<-2||Number(l)>9||!a&&Ce(i+"/"+l)===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=l:o.string=l}function lr(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 Di(o,e,n){let t=/^(\s*chord\s+)("(?:[^"\\]|\\.)*")(.*)$/.exec(o.params);if(t){o.params=t[1]+JSON.stringify(lr(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:Ss(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 zi(o,e,n,t){let s=0,r=!1,a=e.get(0);for(let i of o.notes??[])try{let l=i.command==="command"&&/^\s*key\s+(\S+)\s*$/.exec(i.params);if(l)(!He.default.hasKeySignature(l[1])||!/^[A-G][#b]?m?$/.test(l[1]))&&t(i,"Invalid key signature"),a=new vt(a.semitones,l[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")Di(i,a,t);else if(i.chord||i.abc||i.fret!==void 0||i.command==="rest"){for(let c of i.chord??[i])Hi(c,a,n,t);r=!0}}catch(l){if(l.code==="syntax")throw l;t(i,l.message)}}function Es(o,e){let n=0,t=!1,s=!1,r,a;for(let i of o){if(i.element==="options"){for(let l of i.params)l.key==="transpose"&&(t&&e(l,"Set transpose before the first stave"),n=Number(l.value),(!/^[+-]?\d+$/.test(l.value)||!Number.isSafeInteger(n)||Math.abs(n)>127)&&e(l,"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 l=i.options?.find(h=>h.key==="key"),c=l?.value??"C";(!/^[A-G][#b]?m?$/.test(c)||!He.default.hasKeySignature(c))&&e(l??i,"Transposition requires a major or minor key");let u=new vt(n,c),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]]),l)l.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||zi(i,a,r,e)}}}var ee=class extends Error{constructor(n,t,s){super(`${t} at line ${s.line} column ${s.column}.`);this.code=n;this.range=s}};function $t(o,e=!1){let n;function t(c){if(!n){n=[0];let u=/\r\n|\r|\n/g;for(;u.exec(o);)n.push(u.lastIndex)}return{start:n[c.first_line-1]+c.first_column,end:n[c.last_line-1]+c.last_column,line:c.first_line,column:c.first_column}}if(!o?.trim())throw new ee("syntax","No code",{start:0,end:0,line:1,column:0});function s(c,u){let[f,m,h]=c.split("z").map(Number);if(!Number.isSafeInteger(f)||!Number.isSafeInteger(m)||m<=f)throw new ee("syntax","A pre-bend must start above the fretted pitch",t(u));if(h!==void 0&&h!==f)throw new ee("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(ws);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(...c){return a=i.apply(this,c),a},r.parseError=(c,u)=>{throw new ee("syntax",`Unexpected text '${u.text}'`,t(a.yylloc))};let l=r.parse(o.replace(/\r\n?/g,`
|
|
369
|
+
`));if(l?.some(c=>c.element==="options"&&c.params.some(u=>u.key==="transpose"))){if(!e)return $t(o,!0);Es(l,(c,u)=>{throw new ee("syntax",u,c.range)})}return l&&Gr(l,(c,u)=>t({first_line:c,last_line:c,first_column:u,last_column:u+1}),(c,u)=>{throw new ee("syntax",c,u)}),l}function ur(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 ee("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 ee("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 ee("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 m=c;m<=u;m++){let h=f.find(k=>k.first===m&&a(k)<=u);if(!h){if(i.length>=16384)throw new ee("measure","Performed repeat exceeds 16384 bar visits",o.measures[m-1].range);i.push(m);continue}let S=f.filter(k=>k!==h);for(let k=0;k<(h.count??Math.max(2,h.endings.length));k++){l(m,h.bodyEnd,S);let x=h.endings[k];x&&l(x.first,x.last,S)}m=a(h)}}return l(1,n.length,t),i}function Ms(o,e){let n=new Map,t=new Map;for(let s of o){let r=ur(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 ee("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=Ce(l+"/"+(Number(a)+Math.floor(i/7)));return c===void 0?e:Math.max(0,Math.min(127,c+e-Ce(o)))}function Ts(o,e,n,t=.25){if(!o.notes.length)return[o];let s=o.notes[0],r=e.heads.find(u=>u.sounding&&Ce(u.sounding)===s.pitch);if(!r)return[o];let a=[],i=o.time,l=o.duration;function c(u,f,m){let h=m/u.length;u.forEach((S,k)=>a.push({...o,time:f+k*h,duration:h,notes:(Array.isArray(S)?S:[S]).map(x=>({pitch:x,duration:h,velocity:s.velocity,...s.fixedVelocity&&{fixedVelocity:!0},program:s.program}))}))}if(e.grace){let u=s.pitch-Ce(r.written),f=e.grace.pitches.map(m=>(Array.isArray(m)?m:[m]).map(h=>Ce(h)+u).filter(h=>h>=0&&h<=127)).filter(m=>m.length);if(f.length){let m=e.grace.side==="before",S=(m&&!e.grace.steal?Math.min(l,...o.notes.map(x=>x.duration)):l)*t,k=m?i:i+l-S;c(f,k,S),l-=S,m&&(i+=S);for(let x of o.notes)m?x.duration=Math.max(0,x.duration-S):x.duration-=Math.min(S,Math.max(0,x.duration-(k-o.time)))}}if(e.ornament){let u=Ps(r.written,s.pitch,1,n),f=Ps(r.written,s.pitch,-1,n),m=s.pitch,S={tr:[m,u,m,u],mordent:[m,u],mordent_inverted:[m,f],turn:[u,m,f],turn_inverted:[f,m,u]}[e.ornament],k=Math.min(l,s.duration)/2;c(S,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 kn=Se(Me());function Ns(o,e,n){let t=Ce(o);if(t===void 0)return;let s={pitch:t,duration:e,velocity:100};return n&&(s.bend=[{time:e,semitones:-n}]),s}function Ee(o,e){let[n,t]=o.split("/").map(Number);return n/t*e}function ji(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=Ns(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 dr=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 Gi(o,e,n){let t=[],s=new Map;for(let S of o.playback?.tempoChanges??[]){let k=s.get(S.bar)??[];k.push({at:Ee(S.at,1),bpm:S.bpm*e/(o.playback.tempo??120)}),s.set(S.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(S=>S.voices.filter(k=>k.hand&&k.events.some(x=>x.dynamic)).map(k=>k.hand)):[]),u=new Map,f=new Set((o.spans??[]).flatMap(S=>S.kind==="crescendo"||S.kind==="diminuendo"?[S.from,S.to]:[])),m=e,h=0;for(let S of o.measures){let k=o.playback?.tempos?.[S.number];k&&(m=k*e/(o.playback.tempo??120)),t.push(m);let x=s.get(S.number);x&&(m=x[x.length-1].bpm);let T=S.voices.flatMap((B,H)=>B.events.map(_=>({attack:_,voice:H,onset:Ee(_.onset,1)}))).sort((B,H)=>B.onset-H.onset||+!!H.attack.dynamic-+!!B.attack.dynamic);for(let{attack:B,voice:H,onset:_}of T){let M=c.size===2?S.voices[H].hand??"":"";u.has(M)||u.set(M,new dr);let V=u.get(M);r.set(B.id,V.attack(h+_,l[B.dynamic],!B.silent&&B.heads.length>0,n&&!f.has(B.id)));let j=i[H]??=[],q={id:B.id,time:h+_,voice:H,explicit:!!B.dynamic,index:j.length};a.set(B.id,q),j.push(q)}h+=Ee(S.span,1)}for(let S of o.spans??[]){if(S.kind!=="crescendo"&&S.kind!=="diminuendo")continue;let k=a.get(S.from),x=a.get(S.to);if(!k||!x||x.time<=k.time)continue;let T=S.kind==="crescendo",B=T&&S.niente?1:r.get(S.from),H=!T&&S.niente?1:x.explicit?r.get(S.to):Math.min(127,Math.max(1,B+(T?24:-24)));for(let _=k.index;_<=x.index;_++){let M=i[k.voice][_];r.set(M.id,Math.round(B+(H-B)*(M.time-k.time)/(x.time-k.time)))}}return{tempi:t,tempoChanges:s,velocities:r}}function Wi(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 m=c+u>>>1;t[m].end<=l?c=m+1:u=m}let f=t[c];if(n&&(f?.start<l||t[c-1]?.end===l)&&(i.holdRelease=!0),f&&f.start<l){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 qi(o,e,n,t,s){let r=t(Ee(o.span,1)),a=e/4,[i,l]=o.state.meter.split("/").map(Number),c=Math.max(0,i/l-Ee(o.span,1))*4,u=Math.abs(c-Math.round(c))>1e-8?c%1*a:0,f=[];if(s!==void 0){let S=Ee(o.span,1),k=0,x=(1-u/a)/4;for(;k<S-1e-12;){let T=Math.min(k+x,S);f.push({end:t(T),...T-k>=.25-1e-12&&{eighth:t(k+.125)}}),k=T,x=.25}}let m=[],h=!1;for(let S of o.voices)for(let k of S.events){let x=t(Ee(k.onset,1)+Ee(k.duration,1));k.heads.some(T=>T.marks?.some(B=>B.articulation?.startsWith("a@")))&&m.push(x),x>=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:m,phraseEnd:h||!!m.length}}function _s(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 m of a.fermatas??[]){let h=r+m;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 As(o,e,n,t=ur(o,!1),s,r){let a=[],i=new Map(o.ties.map(E=>[E.to+":"+E.toHead,E])),l=new Map,c=!!s&&!s.literal,u=!1,{tempi:f,tempoChanges:m,velocities:h}=Gi(o,e,c),S=new Set((o.spans??[]).filter(E=>E.kind==="slur").map(E=>E.to)),k=new Map((o.spans??[]).filter(E=>E.kind==="tremolo").map(E=>[E.from,E])),x=new Map((o.spans??[]).flatMap(E=>E.kind==="glissando"?[[E.to+":"+E.toHead,E]]:[])),T=new Map,B=new Map,H=(o.spans??[]).filter(E=>E.kind==="pedal"),_=new Map(H.map(E=>[E.from,E.to])),M=new Set(H.filter(E=>E.onset).map(E=>E.to)),V=new Map,j=[];function q(E){for(let A of V.values())j.push({start:A,end:E});V.clear()}let z=new Map((o.repeats??[]).flatMap(E=>E.endings.slice(1).map(A=>[A.first,E.bodyEnd]))),R=0,N=0;for(let E of t){let A=o.measures[E-1];if(E!==R+1){if(z.get(E)===R)for(let[te,Q]of l)(Q.barNumber!==R||Math.abs(Q.writtenEnd-N)>1e-8)&&l.delete(te);else l.clear();q(N)}else if(z.has(E)){let te=z.get(E);for(let[Q,J]of l)J.barNumber===te&&l.delete(Q)}R=E;let L=240/f[E-1],D=0,Y=0,ne=L,se=[{start:D,timeAtStart:Y,rate:ne}];for(let te of m.get(E)??[])Y+=(te.at-D)*ne,D=te.at,ne=240/te.bpm,se.push({start:D,timeAtStart:Y,rate:ne});let re=te=>{let Q=0,J=se.length;for(;Q+1<J;){let oe=Q+J>>>1;se[oe].start<=te?Q=oe:J=oe}let ce=se[Q];return ce.timeAtStart+(te-ce.start)*ce.rate},le=A.voices.flatMap(te=>te.events).map(te=>({attack:te,time:N+re(Ee(te.onset,1))}));le.sort((te,Q)=>te.time-Q.time),r&&Ee(A.span,L)>0&&r.push(qi(A,L,S,re,se.length>1?ne/4:void 0));let ae=new Map;for(let{attack:te,time:Q}of le){let J=re(Ee(te.onset,1)+Ee(te.duration,1))-re(Ee(te.onset,1));_.has(te.id)&&V.set(_.get(te.id),Q),V.has(te.id)&&(j.push({start:V.get(te.id),end:M.has(te.id)?Q:Q+J}),V.delete(te.id));let ce=[];if(te.grace||te.ornament){let oe=te.activeKey??A.state.key??"C";B.has(oe)||B.set(oe,new kn.KeyManager(oe));let ue;if(te.grace?.steal){let C=Ee(te.onset,1),$=Ee(te.duration,1),Z=$*Ee(te.grace.steal,1),O=te.grace.side==="before"?C:C+$-Z;ue=(re(O+Z)-re(O))/J}T.set(te.id,{attack:te,key:B.get(oe),graceShare:ue})}te.heads.forEach((oe,ue)=>{let C=oe.sustain?re(Ee(te.onset,1)+Ee(oe.sustain,1))-re(Ee(te.onset,1)):J,$=te.id+":"+ue,Z=i.get($),O=Z&&l.get(Z.from+":"+Z.fromHead);if(O){if(c&&(O.note.holdRelease=!0),O.note.duration=Math.max(O.note.duration,Q+C-O.start),Z.bend){let{semitones:b,hold:g,release:y}=Z.bend;O.note.bend=[...O.note.bend??[],{time:Q-O.start+C*g[0]/g[1],semitones:b},{time:Q-O.start+C*y[0]/y[1],semitones:0}]}l.set($,{...O,barNumber:E,writtenEnd:Q+C})}else{let b=ji(te,oe,C);if(b){let g=x.get($),y=g&&l.get(g.from+":"+g.fromHead);y&&(y.note.bend=[...y.note.bend??[],{time:Q-y.start,semitones:b.pitch-y.note.pitch}]),b.velocity=h.get(te.id),c&&oe.marks&&(oe.marks.some(P=>P.articulation==="a>"||!P.articulation&&!P.finger&&!P.stringNumber)&&(b.velocity=Math.min(127,b.velocity+10)),!b.bend&&!te.grace&&!te.ornament&&oe.marks.some(P=>P.articulation==="a.")&&(b.duration*=.58)),oe.velocity!==void 0&&(b.velocity=oe.velocity,b.fixedVelocity=!0,oe.velocity===0&&(u=!0)),o.program!==void 0&&(b.program=o.program),ce.push(b),l.set($,{note:b,start:Q,barNumber:E,writtenEnd:Q+C})}}}),ae.set(te.id,{time:Q,duration:J,source:te.id,notes:ce,mark:n&&(()=>n(te.id))})}for(let[te,Q]of ae){let J=k.get(te);if(J?.kind!=="tremolo"){a.push(Q);continue}let ce=ae.get(J.to),oe=Q.duration+ce.duration,ue=L/2**(2+J.strokes);for(let C=0;C*ue<oe-1e-9;C++){let $=C%2?ce:Q,Z=Math.min(ue,oe-C*ue);a.push({...$,time:Q.time+C*ue,duration:Z,notes:$.notes.map(O=>({...O,duration:Z}))})}ae.delete(J.to)}N+=re(Ee(A.span,1))}let W=T.size?a.flatMap(E=>{let A=T.get(String(E.source));if(!A)return[E];let L=A.attack.grace,D=A.graceShare??(L&&s?.graceFraction(E.time,E.duration,L.pitches.length,L.slash));return Ts(E,A.attack,A.key,D)}):a;if(u)for(let E of W)E.notes=E.notes.filter(A=>A.velocity!==0);return W.sort((E,A)=>E.time-A.time),q(N),Wi(W,j,c),{events:W,duration:N}}function Rs(o,e){let n=[],t=240/(e*kn.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(),m=f*t,h=[];if(!u.isRest()){let S=it.get(u)??(u.getPlayNote?.()??[]).map(x=>({key:x})),k=new Map;S.forEach((x,T)=>{let B=Ns(x.key,m,x.release);if(!B)return;let H=wn.get(u)?.get(T),_=H&&s.get(H.glyph)?.get(H.index);_&&_.pitch===B.pitch?(_.duration+=m,k.set(T,_)):(h.push(B),k.set(T,B))}),s.set(u,k)}n.push({time:(r+c)*t,duration:m,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 it=new WeakMap,wn=new WeakMap;function Cs(o,e){let n=wn.get(o)?.get(e);return n&&it.get(n.glyph)?.[n.index]}function fr(o,e,n,t){if(!o||!e)return;let s=wn.get(e)??new Map;t.forEach((r,a)=>s.set(r,{glyph:o,index:n[a]})),wn.set(e,s)}var Sn=class{constructor(e){this.artist=e}makeBend(e,n){let t=X.Flow.Bend.UP,s="";if(parseInt(e,10)>parseInt(n,10))t=X.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 l=a.getPositions(),c=n.getPositions();i.forEach((u,f)=>{let m=s[f],h=l[u],S=c[m];this.artist.current_bends[u]||(this.artist.current_bends[u]=[]),this.artist.current_bends[u].push(this.makeBend(h.fret,S.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;Dr(this.artist.current_bends,(t,s)=>{let r=[];t.forEach(l=>r.push(l));let a=X.Flow.Bend.length<=1?new X.Flow.Bend(r):new X.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 X.RERR("ArtistError","Tuplet counts must be positive integers");let a=vn(s,r.meter),i=(l,c,u)=>{let f=l.slice(-t);if(f.length!==t||f.some(h=>h instanceof X.Flow.BarNote))throw new X.RERR("ArtistError","Not enough notes for tuplet in this bar and voice");let m=new X.Flow.Tuplet(f,{numNotes:s,notesOccupied:a});c&&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=X.Flow.Modifier.Position,s=[],r=[];if(n)n[1].split(/-/).forEach(i=>s.push(i.trim()));else return null;let a=()=>new X.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=Jn(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=X.Flow.Stroke.Type;if(!n)return null;switch(n[1]){case"bu":return new X.Flow.Stroke(t.BRUSH_UP);case"bd":return new X.Flow.Stroke(t.BRUSH_DOWN);case"ru":return new X.Flow.Stroke(t.ROLL_UP);case"rd":return new X.Flow.Stroke(t.ROLL_DOWN);case"qu":return new X.Flow.Stroke(t.RASQUEDO_UP);case"qd":return new X.Flow.Stroke(t.RASQUEDO_DOWN);default:throw new X.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=X.Flow.Modifier.Position,a=s==="t"?r.ABOVE:r.BELOW;return new X.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=X.Flow.Annotation.VerticalJustify,i=r==="top"?a.TOP:a.BOTTOM,l=(u,f=i)=>new X.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&&!Fe(u))throw new X.RERR("ArtistError",`Invalid annotation color '${u}'`);if(!f)return null;let m=l(f);return u?m.setStyle(we(u)):m}if(c=e.match(/^\.([^.]*)\.(.*)/),c){let u=i,f=c[1],m=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 m?l(m,u):null}return l(e)}formatOverrideFretText(e){if(!e)return null;let n=X.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],m=(()=>{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}${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 c=parseInt(n.string,10);if(!Number.isNaN(c)){let u=-1;e.positions.forEach((f,m)=>{parseInt(f.str,10)===c&&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 l=0;e.fretElement.forEach(c=>{l=Math.max(l,c.getWidth())}),e.setWidth(l)}addAnnotations(e){let n=me(this.artist.staves),t=n.note_notes,s=n.tab_notes;if(e.length>s.length)throw new X.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 X.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"&&fr(n,t,s,r),e==="t"&&t.addModifier(new X.Flow.Annotation("T").setVerticalJustification(X.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 X.Flow.TabSlide(i)),(e==="h"||e==="p")&&(a=new X.Flow.TabTie(i,e.toUpperCase())),(e==="T"||e==="t")&&(a=new X.Flow.TabTie(i," ")),e==="b"&&this.openBends(n,t,s,r),a){let l=me(this.artist.staves)?.color;l&&a.setStyle(we(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"&&fr(n,t,s,r),["b","s","h","p","t","T"].includes(e)&&(a=new X.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(we(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 X.Flow.TabNote)return e.length-n;if(!(t instanceof X.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 X.Flow.Vibrato),e==="V"&&(r=new X.Flow.Vibrato,typeof r.setHarsh=="function"&&r.setHarsh(!0)),e==="u"&&(r=new X.Flow.Articulation("a|").setPosition(X.Flow.Modifier.Position.BELOW),a=new X.Flow.Articulation("a|").setPosition(X.Flow.Modifier.Position.BELOW)),e==="d"&&(r=new X.Flow.Articulation("am").setPosition(X.Flow.Modifier.Position.BELOW),a=new X.Flow.Articulation("am").setPosition(X.Flow.Modifier.Position.BELOW));let i=me(t);if(i&&r&&i.addModifier(r,0),a){let l=me(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=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 l=e.map((h,S)=>h&&h===i?S:-1).filter(h=>h>=0);if(De(l))return;i==="b"&&(a=!0);let c=this.getPreviousNoteIndex(),u=null,f=null,m=[];if(c===-1)u=null,f=null;else{u=t[c];let h=u.getPositions();f=[];for(let S of l){let k=r.getPositions()[S];if(!k)continue;let x=k.fret==="X"&&i==="T",T=h.findIndex((B,H)=>{if(f.includes(H))return!1;if(x){let _=n.note?s[c].getKeys():u.getPlayNote(),M=n.note?me(s).getKeys():r.getPlayNote();return B.fret==="X"&&_[H]===M[S]}return B.str===k.str});T>=0&&(f.push(T),m.push(S))}}n.tab&&this.addTabArticulation(i,u,r,f||[],m),n.note&&m.length&&this.addStaveArticulation(i,s[c],me(s),f||[],m)}),a||this.closeBends(0)}};var qe=Se(Me());var Is=Se(Me()),dt=new Is.PercussionMap;function En(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 Mn=Se(Me()),Pn=10,Bs=5;function Ht(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 Ui(o,e,n){return{x:o+(n.edge==="in"?-Pn:Pn),y:e+(n.side==="above"?-Bs:Bs)}}var Tn=class extends Mn.Modifier{constructor(n){super();this.slide=n;this.setPosition(n.edge==="in"?Mn.Modifier.Position.LEFT:Mn.Modifier.Position.RIGHT)}static get CATEGORY(){return"OpenSlide"}draw(){let n=this.checkContext(),t=this.checkAttachedNote().getModifierStartXY(this.getPosition(),this.checkIndex()),s=Ui(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 Nn(o,e,n){let t=new Tn(n);o.getModifiers().some(r=>r instanceof Tn&&r.getPosition()===t.getPosition())||(n.edge==="in"?o.setLeftDisplacedHeadPx(o.getLeftDisplacedHeadPx()+Pn+2):o.setRightDisplacedHeadPx(o.getRightDisplacedHeadPx()+Pn+2)),o.addModifier(t,e)}var _n=class{constructor(e){this.signs=new WeakMap;this.artist=e}getNoteForFret(e,n){return Lt(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 X.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 qe.Music().createScaleMap(e.key)))n[a]=i.slice(1)||"n";let t=new qe.WrittenAccidentalState(n),s=new Map;for(let a of e.note_voices){let i=new qe.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 X.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)it.get(l)?.forEach((c,u)=>{if(!c.inherit)return;let f=c.inherit.written[0],m=r.get(c.inherit.written)??n[f],h=Cs(l,u);if(c.key=h?.key??f+(m==="n"?"":m)+c.key.slice(c.key.indexOf("/")),Ce(c.key)===void 0)throw new ee("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 m=t.sign(l,f?"ambiguous":u)!==void 0;for(let{head:h,note:S,index:k}of c)this.updateSign(S,k,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(),l=i.indexOf(t.mark);l>=0&&i.splice(l,1),delete t.mark}a&&!t.mark&&(t.mark=new qe.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 X.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&&Nn(s,i,a),r&&s.addModifier(yn(r),i)}),t.push(s),this.attachDots(s)}attachDots(e){for(let n=0;n<this.artist.current_dots;n++)X.Flow.Dot.buildAndAttach([e],e instanceof X.Flow.TabNote?{index:0}:{all:!0})}setDuration(e,n=!1){let t=/^(\d+|[whq])(s?)(d*)$/i.exec(e.trim());if(!t)throw new X.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 qe.StaveNote(dt.note(e,t));this.attachDots(s),n.note_notes.push(s),n.tab_notes.push(new X.Flow.GhostNote(t)),it.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 qe.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 X.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=[],l=[],c=[],u=[],f=[],m=[],h=0,S=e[0].string,k=0;if(e.forEach(x=>{h+=1,(x.abc||x.string!==S)&&(k=0,S=x.string),r[k]||(r[k]=[],a[k]=[],i[k]=[],l[k]=[],f[k]=[],c[k]=[],u[k]=null);let T=null,B=null,H=null,_=null,M,V,j;if(x.abc){let E=x.octave?x.octave:x.string;[T,B,H]=this.getNoteForABC(x.abc,E);let A=H?H.split("_")[0]:"";if(_=`${T}${A}`,x.abc.transposed&&!H&&!x.fret&&(j={written:T.toLowerCase()+"/"+B,range:x.abc.transposed},_=this.artist.music_api.createScaleMap(s.key)[T.toLowerCase()].replace(/n$/,"")),x.fret&&x.abc.transposed){let[L,D]=this.artist.tuning.getNoteForFret(Number(x.fret)+s.capo,x.string).split("/");V=L+"/"+(Number(D)-1+this.artist.current_octave_shift)}x.fret||(x.fret="X")}else if(x.fret){let E=String(Number(x.fret)+s.capo+(x.prebend?.semitones??0));[T,B,H]=this.getNoteForFret(E,x.string);let[A,L]=this.artist.tuning.getNoteForFret(E,x.string).split("/");_=A,M=Number(L)-1}else throw new X.RERR("ArtistError","No note specified");let q=parseInt(String(B),10)+this.artist.current_octave_shift,z=x.time?{time:x.time,dot:x.dot}:null,R=H?.split("_")[0],N=x.abc&&R&&R!=="n"?T+R:T;r[k].push(`${N}/${B}`);let W=(M??Number(B))+this.artist.current_octave_shift;a[k].push(`${_}/${q}`),i[k].push(V??`${_}/${W}`),l[k].push(R&&/^[a-g]/i.test(T)?{key:`${T[0].toLowerCase()}/${B}`,sign:R,literal:!!x.abc,cautionary:x.abc?x.abc.accidental_type==="c":this.artist.customizations.accidentals==="cautionary"&&R!=="n"}:null),f[k].push({fret:x.fret,str:x.string,prebend:x.prebend,openSlide:x.openSlide,marks:x.marks,inherit:j}),x.articulation?c[k].push(x.articulation):c[k].push(null),m[k]=z,x.decorator&&(u[k]=x.decorator),k+=1}),r.forEach((x,T)=>{if(m[T]&&this.setDuration(m[T].time,m[T].dot),this.addTabNote(f[T],a[T]),s.note&&(this.addStaveNote({spec:x,signs:l[T],play_note:a[T]}),!s.tab)){let H=f[T].filter(_=>_.prebend).map(_=>Ot(_.prebend,_.str));for(let _ of f[T])_.openSlide&&H.push(Ht(_.openSlide,_.str));if(H.length){let _=new X.Flow.Annotation(H.join(" \xB7 "));_.setVerticalJustification(X.Flow.Annotation.VerticalJustify.TOP),me(s.note_notes).addModifier(_,0)}}f[T].forEach((H,_)=>{H.marks&&(s.tab&&Tt(me(s.tab_notes),_,H.marks,!0),s.note&&Tt(me(s.note_notes),_,H.marks,!1))});let B=i[T].map((H,_)=>{let M=f[T][_].prebend;return{key:H,release:M?.release?M.semitones:0,inherit:f[T][_].inherit}});it.set(me(s.tab_notes),B),s.note&&it.set(me(s.note_notes),B),this.artist.addArticulations(c[T]),u[T]&&this.artist.addDecorator(u[T])}),n){let x=[];for(let T=0;T<h;T+=1)x.push(n);this.artist.addArticulations(x)}t&&this.artist.addDecorator(t)}addNote(e){this.addChord([e],null,null)}};var Dt=Se(Me());function mr(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 Dt.Fraction(a,r)),e=s.reduce((a,i)=>a+i,0)+"/"+r}return new Dt.Voice(e),{meter:e,groups:t??Dt.Beam.getDefaultBeamGroups(e)}}var An=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=X.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 X.Flow.BarNote().setType(s);n.tab_notes.push(r),n.note&&n.note_notes.push(new X.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};et(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 X.Flow.Stave(a,this.artist.last_y,Number(this.artist.customizations.width)-20,{leftBar:!1}),t.color&&r.setDefaultLedgerLineStyle(we(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 X.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}=mr(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 Rn=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 X.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 X.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=X.Flow.TextNote.Justification.CENTER;switch(t){case"center":u=X.Flow.TextNote.Justification.CENTER;break;case"left":u=X.Flow.TextNote.Justification.LEFT;break;case"right":u=X.Flow.TextNote.Justification.RIGHT;break;default:u=X.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:l,weight:c}};e.startsWith("#")&&(m.glyph=e.slice(1),m.text="",m.font=null);let h=new X.Flow.TextNote(m).setLine(n).setJustification(u);this.color&&h.setStyle(we(this.color)),me(a).push(h)}};var Ye=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:Xn,font_size:10,font_style:null,bottom_spacing:30,tab_stave_lower_spacing:10,note_stave_lower_spacing:0,scale:1},s&&et(this.options,s),this.renderer=new fn(this),this.articulations=new Sn(this),this.notes=new _n(this),this.stavesBuilder=new An(this),this.text=new Rn(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 X.Flow.Tuning,this.key_manager=new X.Flow.KeyManager("C"),this.music_api=new X.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 X.RERR("ArtistError",s)){this.log("setOptions: ",e);let t=jr(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 X.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 X.Flow.BarNote)throw new X.RERR("ArtistError",`Put !color! after a note or rest at line ${n} column ${t}`);a?.setStyle(we(s[1])),a?.setLedgerLineStyle?.(we(s[1])),i?.setStyle(we(s[1]));break}case"octave-shift":if(s.length!==2||!/^[+-]?\d+$/.test(s[1])||!Number.isSafeInteger(Number(s[1])))throw new X.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 X.RERR("ArtistError",`Invalid command '${s[0]}' at line ${n} column ${t}`)}}};function pr(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 Fs(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,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",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,m=a.id,h=l.name,S=u.mark.range;if(l.span==="hairpin")o.spans.push({kind:u.mark.hairpin,first:f,last:m,range:S,name:h,niente:u.mark.niente});else{if(l.span==="beam"){let k=o.events[u.index].bar!==a.bar;if(pr(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:m,range:S,name:h});continue}}o.spans.push({kind:l.span,first:f,last:m,range:S,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 Ki=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 Zt(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":Ki.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 hr(o){return o==="auto"||o==="mini"||o==="large"}function gr(o){return/^(top|bottom)-(left|center|right)$/.test(o)}function Cn(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(!hr(s))throw new RangeError("Control size must be auto, mini or large");if(!gr(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 Qt={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 wt(o){return Object.prototype.hasOwnProperty.call(Qt,o)}var Oe=Object.freeze({bytes:65536,tokens:8192,depth:24,repetitions:32,events:4096,heads:16,steps:32768,fraction:2147483647}),Xi=Object.freeze({...Oe,bytes:1048576,tokens:131072,events:32768,steps:524288});function Vs(o="default"){if(o==="default")return Oe;if(o==="large")return Xi;throw new RangeError("Expected score capacity default or large")}function Ds(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 m of c.split("-")){let h=f+m.length;s(m+"/"+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 Yi(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 Ds(o,(a,i,l)=>n(a,i,r(l)),t).map(a=>({text:a.text,range:r(a.range)}))}var Os=/^:(w|h|q|1|2|4|8|16|32|64|128|256)(\.{0,2})$/,In=/^[A-G](?:bb|##|b|#|n)?[0-9]$/,Ls=/^(x|0|[1-9]\d?)\/([1-8])$/,Ji=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"]),Hs=["kick","snare","hat"];function $i(o){return o==="guitar"||o==="piano"||o==="drums"||o==="staff"}function zs(o,e,n=Oe){let t=new Set(Hs),s=new Map,r=Ds(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 m(){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 S=new Map,k=[],x={},T,B,H,_=[],M=[],V,j,q;function z(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 P=y[1].split("+").map(Number),F=P.reduce((v,d)=>v+d,0);return(F>32||P.includes(0))&&u("Expected one through 32 beats",b),{value:F+"/"+y[2],...P.length>1&&{sign:b.text},range:g}}function R(b,g){let y=z(g),P=1;if(l()==="at"){c();let F=c();(!/^[1-9]\d{0,3}$/.test(F.text)||Number(F.text)<2)&&u("Expected a bar number starting at 2",F),P=Number(F.text)}b[P]&&u("Meter already declared for bar "+P,g),b[P]=y}function N(){let b=c();return["tr","turn","turn_inverted","mordent","mordent_inverted"].includes(b.text)||u("Unknown ornament",b),b.text}function W(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 E(){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 A(b){let g={range:b.range,settings:{},anchors:[],cues:[]};l()==="part"?(c(),g.part=m()):l()==="conductor"&&(c(),g.conductor=!0),M.some(F=>F.part===g.part&&F.conductor===g.conductor)&&u("Duplicate edition for this target",b);function y(){let F=c();return/^\d{1,3}(?:\.\d{1,3})?$/.test(F.text)||u("Expected millimeters",F),Number(F.text)}function P(){let F=c();return/^[1-9]\d{0,3}$/.test(F.text)||u("Expected a positive measure number",F),Number(F.text)}h(()=>{for(;l()!=="}";){let F=c(),v=F.text;if(Object.prototype.hasOwnProperty.call(g.settings,v)&&u("Duplicate edition setting",F),v==="paper"){let d=c();d.text!=="A4"&&d.text!=="Letter"&&u("Expected A4 or Letter",d),g.settings.paper=d.text}else if(v==="margins")g.settings.margins={top:y(),right:y(),bottom:y(),left:y()};else if(v==="staffSize")g.settings.staffSize=y(),g.settings.staffSize||u("Expected a positive staff size",F);else if(v==="title"||v==="subtitle"||v==="header"||v==="footer")g.settings[v]=E();else if(v==="pageNumbers"||v==="compressRests"){let d=c();d.text!=="on"&&d.text!=="off"&&u("Expected on or off",d),g.settings[v]=d.text==="on"}else if(v==="system"||v==="page"||v==="prefer"||v==="forbid"){f(v==="system"||v==="page"?"at":"after");let d=P();g.anchors.push({field:{system:"systemBreaks",page:"pageBreaks",prefer:"preferredTurns",forbid:"forbiddenTurns"}[v],measure:d,range:[F.range[0],r[a-1].range[1]]})}else if(v==="cue"){g.part||u("Declare a cue in a player edition",F);let d=m();f("at");let p=P(),w=E();w.trim()||u("Expected a cue label",F),g.cues.push({part:d,measure:p,label:w,range:[F.range[0],r[a-1].range[1]]})}else u("Unknown edition setting",F)}}),g.range=[b.range[0],r[a-1].range[1]],M.push(g)}function L(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 P=c();(!/^[+-]?\d{1,3}$/.test(P.text)||Math.abs(Number(P.text))>127)&&u("Expected a sounding interval from -127 to +127 semitones",P),g.sounds=Number(P.text)}else g[y.text]=E()}return g}function D(b){let{name:g,...y}=b;return{...y,...g!==void 0&&{displayName:g}}}function Y(){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=E();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 ne(b,g,y=!1){let P=/^([1-9]\d{0,9})\/([1-9]\d{0,9})$/.exec(g);P||u("Expected a positive fraction",b);let[F,v]=P.slice(1).map(Number);(F>Oe.fraction||v>Oe.fraction)&&u("Timing fraction exceeds precision limit",b),y&&F>=v&&u("Grace share must be smaller than one",b);let d=F,p=v;for(;p;)[d,p]=[p,d%p];return F/d+"/"+v/d}function se(){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 v=m(),d=b.text==="tieStart"&&(l()==="above"||l()==="below")?c().text:void 0;return{kind:b.text,name:v,...d&&{side:d},range:g()}}if(b.text==="velocity"){let v=c();return(!/^(?:0|[1-9]\d{0,2})$/.test(v.text)||Number(v.text)>127)&&u("Expected an integer MIDI velocity from 0 to 127",v),{kind:"velocity",value:Number(v.text),range:g()}}if(b.text==="sustain"){let v=c();return{kind:"sustain",duration:ne(v,v.text),range:g()}}if(["slurStart","slurEnd","beamStart","beamEnd","crescendoStart","diminuendoStart","hairpinEnd"].includes(b.text)){let v=m(),d=b.text.startsWith("slur")?"slur":b.text.startsWith("beam")?"beam":"hairpin",p=b.text.endsWith("Start")?"start":"end",w=b.text==="crescendoStart"?"crescendo":b.text==="diminuendoStart"?"diminuendo":void 0,I=b.text==="slurStart"&&(l()==="above"||l()==="below")?c().text:void 0,U=!!w&&l()==="niente";return U&&c(),{kind:"spanEndpoint",name:v,span:d,edge:p,hairpin:w,side:I,niente:U,range:g()}}if(b.text==="frame"||b.text==="diagram"){f("(");let v=[];for(;l()!==")";){let p=c();(!/^(?:x|\d{1,2})$/.test(p.text)||v.length>=8)&&u("Expected up to eight diagram frets",p),v.push(p.text==="x"?"x":Number(p.text))}c();let d;if(l().startsWith("barre=")){let p=c(),w=/^barre=(\d{1,2})\/([1-8])\.\.([1-8])$/.exec(p.text);w||u("Expected barre=fret/from..to",p),d=[Number(w[1]),Number(w[2]),Number(w[3])]}return{kind:b.text,frets:v,barre:d,range:g()}}if(b.text==="line"){let v=c();return/^-?\d{1,2}(?:\.5)?$/.test(v.text)||u("Expected a staff line",v),{kind:"line",value:Number(v.text),range:g()}}if(b.text==="ink")return{kind:"ink",value:c().text,range:g()};if(b.text==="label"){let v=E(),d=Y();return{kind:"label",text:v,style:d,range:g()}}if(b.text==="tap"||b.text==="vibrato"){let v=b.text==="vibrato"&&l()==="wide";return v&&c(),{kind:b.text,wide:v,range:g()}}if(b.text==="brush"||b.text==="roll"||b.text==="stroke"||b.text==="rasgueado"){let v=c();return v.text!=="up"&&v.text!=="down"&&u("Expected up or down",v),{kind:b.text,direction:v.text,range:g()}}if(b.text==="symbol"){let v=E(),d;return l()==="ink"&&(c(),d=c().text),{kind:"symbol",text:v,ink:d,range:g()}}if(b.text==="write"){let v=c();return In.test(v.text)||u("Expected a written pitch",v),{kind:"write",pitch:v.text,range:g()}}if(["staccato","fermata","articulation"].includes(b.text)){let v=b.text==="articulation"?l().startsWith('"')?E():c().text:b.text==="fermata"?"a@a":"a.",d=l()==="below"?"below":"above";return(l()==="below"||l()==="above")&&c(),{kind:"sign",code:v,position:d,range:g()}}if(b.text==="stem"){let v=c();return v.text!=="up"&&v.text!=="down"&&u("Expected stem up or down",v),{kind:"stem",value:v.text,range:g()}}if(b.text==="dynamic"){let v=c();return/^(ppp|pp|p|mp|mf|f|ff|fff)$/.test(v.text)||u("Expected a dynamic from ppp to fff",v),{kind:"dynamic",value:v.text,range:g()}}if(b.text==="onStaff"){let v=c();return v.text!=="upper"&&v.text!=="lower"&&u("Expected upper or lower",v),{kind:"onStaff",hand:v.text,range:g()}}if(b.text==="sharedStem")return{kind:"sharedStem",name:m(),range:g()};if(b.text==="ornament")return{kind:"ornament",value:N(),range:g()};if(b.text==="pedal"){let v=c();v.text!=="down"&&v.text!=="up"&&u("Expected pedal down or up",v);let d=v.text==="up"&&l()==="onset";return d&&c(),{kind:"pedal",action:v.text,...d&&{onset:d},range:g()}}if(b.text==="ossia"){let v=c();/^:(?:q|8|16|32)$/.test(v.text)||u("Expected an ossia note value such as :8",v);let d=[];for(f("(");l()!==")";){let p=c();(!In.test(p.text)||d.length>=16)&&u("Expected up to 16 ossia notes",p);let w;l()==="["&&(c(),f("ornament"),w=N(),f("]")),d.push({pitch:p.text,ornament:w})}return f(")"),d.length||u("Expected an ossia note",b),{kind:"ossia",duration:v.text.slice(1),notes:d,range:g()}}if(b.text==="grace"){let v=c(),d=[],p=[];v.text!=="before"&&v.text!=="after"&&u("Expected before or after",v);let w=l()==="slashed";w&&c();let I=l().startsWith("steal=")?c():void 0,U=I&&ne(I,I.text.slice(6),!0);for(f("(");l()!==")";){d.length>=16&&u("Expected up to 16 grace attacks");let G=l()==="(";G&&c();let de=[];do{let fe=c(),he=Ls.exec(fe.text);if(de.length>=Oe.heads&&u("Too many grace chord heads",fe),In.test(fe.text)?de.push(fe.text):he&&he[1]!=="x"?de.push({fret:Number(he[1]),string:Number(he[2])}):u("Expected a grace pitch or fret/string",fe),l()==="["){c(),l()!=="finger"&&u("Expected a finger on the grace head");let pe=se();if(pe.kind!=="finger")return u("Expected a grace fingering");p.push({attack:d.length,head:de.length-1,finger:String(pe.value),position:pe.side}),f("]")}}while(G&&l()!==")");G&&f(")"),d.push(G?de:de[0])}return f(")"),d.length||u("Expected a grace pitch",v),{kind:"grace",side:v.text,pitches:d,...U&&{steal:U},...p.length&&{fingerings:p},...w&&{slash:w},range:g()}}if(b.text==="harmony"){let v=function(){let I=c();return/^[A-G](?:b|#)?$/.test(I.text)||u("Expected a chord root or bass pitch",I),I.text},d=v(),p=E(),w;return l()==="bass"&&(c(),w=v()),{kind:"harmony",root:d,quality:p,...w&&{bass:w},range:g()}}if(b.text==="lyric"||b.text==="verse"){let v=b.text==="verse"?m():void 0,d=E(),p;l()==="elide"&&(c(),p=E());let w=l()==="hyphen";w&&c();let I=/^extend=([1-9]\d?)$/.exec(l());return I&&c(),{kind:"lyric",...v&&{verse:v},...p!==void 0&&{elideWith:p},text:d,hyphen:w,extend:I?Number(I[1]):0,range:g()}}if(b.text==="slideIn"||b.text==="slideOut"){let v=c();return v.text!=="above"&&v.text!=="below"?u("Expected above or below",v):{kind:b.text,side:v.text,range:g()}}if(b.text==="gliss"){let v=c();return/^(?:[1-9]|1[0-6])$/.test(v.text)||u("Expected the previous chord head number, 1 through 16",v),{kind:"gliss",fromHead:Number(v.text)-1,range:g()}}if(b.text==="release"||b.text==="bend"){let v=function(G){let de=c(),fe=/^(\w+)=(\d{1,4})(?:\/(\d{1,4}))?$/.exec(de.text);if(!fe||fe[1]!==G)return u("Expected "+G+"=N/D",de);let he=Number(fe[2]),pe=Number(fe[3]??1);return pe<1||he<1||he>pe?u("Bend phase must lie within the note",de):[he,pe]};if(b.text==="release"){let G=v("hold"),de=v("release");return de[0]*G[1]<=G[0]*de[1]&&u("Release must follow the hold",b),{kind:"release",hold:G,release:de,range:g()}}let d=c();/^\+(?:[1-9]\d?(?:\.5)?|0\.5)$/.test(d.text)||u("Expected a positive bend in semitones",d);let p=v("rise"),w=l().startsWith("hold=")?v("hold"):void 0,I=l().startsWith("release=")?v("release"):void 0,U=w??p;return(w&&w[0]*p[1]<p[0]*w[1]||I&&I[0]*U[1]<=U[0]*I[1])&&u("Bend phases must follow musical time",b),{kind:"bend",semitones:Number(d.text),rise:p,hold:w,release:I,range:g()}}if(b.text==="prebend"){let v=c();if(!/^\+[1-9]\d?$/.test(v.text))return u("Expected a positive bend in semitones",v);let d=l()==="release";return d&&c(),{kind:"prebend",semitones:Number(v.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(),P=l(),F=P==="left"||P==="right"||P==="above"||P==="below"?P:void 0;return F&&c(),{kind:b.text,value:/^\d$/.test(y.text)?Number(y.text):y.text,side:F??"left",range:[b.range[0],r[a-1].range[1]]}}let re=new Map;function le(){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];re.has(y)&&u("Duplicate alias "+y,b),Ji.has(y)&&u("Alias would hide the built-in mark "+y,b);let P=r[a],F=E(),v=r,d=a;r=Yi(F,P,e,n),a=0;try{let p=se();l()&&u("Expected one complete note mark"),re.set(y,p)}finally{r=v,a=d}}while(/^[a-z][a-z0-9_]*=$/.test(l())||r[a+1]?.text==="=")}function ae(){let b=re.get(l());return b?{...b,range:c().range}:se()}function te(){if(l()!=="[")return[];c();let b=[ae()];for(;l()===",";)c(),b.push(ae());return f("]"),b}function Q(){let b=c(),g=Ls.exec(b.text);if(g)return{marks:[],fret:g[1]==="x"?"x":Number(g[1]),string:Number(g[2]),range:b.range};if(In.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 J(){let b=r[a],g=l()==="(",y=[];if(g){c();do{y.length===Oe.heads&&u("Too many heads in a chord");let p=Q();for(let w of te()){if(w.kind==="accent"){p.marks.push({kind:"sign",code:"a>",position:"above",range:w.range});continue}if(W(w))return u("Place the attack mark after the closing parenthesis",b);p.marks.push(w)}y.push(p)}while(l()!==")");c()}else y.push(Q());let P=new Set,F=new Set;for(let p of y)"string"in p&&P.has(p.string)&&u("A chord needs distinct strings",b),"drum"in p&&F.has(p.drum)&&u("A chord needs distinct drum instruments",b),"string"in p&&P.add(p.string),"drum"in p&&F.add(p.drum);let v=te(),d=v.filter(p=>!W(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:v.filter(W),range:[b.range[0],r[a-1].range[1]]}}function ce(b,g){let y={w:1,h:2,q:4}[b[1]]??Number(b[1]),P=2**b[2].length;return{range:g,kind:"duration",value:[BigInt(P*2-1),BigInt(y*P)]}}function oe(b=!1){let g=[];for(;l()!=="}"&&!(b&&l()==="text");){let y=r[a];y.text||u("Expected a closing brace");let P,F=Os.exec(y.text);if(F)c(),P=ce(F,y.range);else if(y.text==="meter"){c();let v=z(c());P={kind:"meter",signature:v,range:[y.range[0],v.range[1]]}}else if(y.text==="use"){c();let v=r[a],d=m();S.has(d)||u("Declare pattern "+d+" before using it (including inside patterns)",v),P={range:y.range,kind:"use",name:d}}else if(y.text==="bar"){c();let v=c(),d={double:"double",final:"end",repeatEnd:"repeat-end",repeatBoth:"repeat-both",single:"single"};Object.prototype.hasOwnProperty.call(d,v.text)||u("Unknown closing barline",v),P={kind:"|",closing:d[v.text],range:y.range}}else if(y.text==="repeatStart")c(),P={kind:"repeatStart",range:y.range};else if(y.text==="break")c(),f("system"),P={kind:"break",range:y.range};else if(y.text==="mark")c(),P={kind:"mark",text:E(),range:y.range};else if(y.text==="crescendo"||y.text==="diminuendo"||y.text==="continuousBeam"||y.text==="feather"||y.text==="tremolo"){let v=y.text;c();let d=(v==="crescendo"||v==="diminuendo")&&(l()==="above"||l()==="below")?c().text:void 0,p,w,I;if(v==="tremolo"){let U=c();/^[1-4]$/.test(U.text)||u("Expected one to four tremolo strokes",U),p=Number(U.text)}else if(v==="feather"){let U=c();U.text!=="left"&&U.text!=="right"&&u("Expected left or right",U),w=U.text}else v!=="continuousBeam"&&l()==="niente"&&(c(),I=!0);P={kind:v,strokes:p,feather:w,niente:I,side:d,body:h(oe),range:y.range}}else if(y.text==="fragment"||y.text==="slur"||y.text==="beam"){c();let v=y.text==="slur"&&(l()==="above"||l()==="below")?c().text:void 0;P={kind:y.text,side:v,body:h(oe),range:y.range}}else if(y.text==="palmMute"){c(),f("strings"),f("(");let v=[];for(;l()!==")";){let d=c();(!/^[1-8]$/.test(d.text)||v.includes(Number(d.text)))&&u("Expected distinct string numbers",d),v.push(Number(d.text))}v.length||u("Expected a string number"),c(),P={kind:"palmMute",strings:v,body:h(oe),range:y.range}}else if(y.text==="transpose"||y.text==="octave"){c();let v=c(),d=Number(v.text)*(y.text==="octave"?12:1);(!/^[+-]?\d{1,3}$/.test(v.text)||Math.abs(d)>127)&&u("Invalid transposition interval",v),P={kind:y.text,semitones:d,body:h(oe),range:y.range}}else if(y.text==="volta"||y.text==="repeatCount"){c();let v=c();/^(?:[2-9]|[12]\d|3[0-2])$/.test(v.text)||u("Expected 2 through 32 repeat passes",v);let d=h(oe),p=[];for(let w=1;y.text==="volta"&&w<=Number(v.text);w++)f("ending"),f(String(w)),p.push(h(oe));P={kind:"volta",body:d,endings:p,...y.text==="repeatCount"&&{count:Number(v.text)},range:y.range}}else if(y.text==="times"||y.text==="tuplet"){c();let v=c();if(y.text==="times")(!/^[1-9]\d?$/.test(v.text)||Number(v.text)>Oe.repetitions)&&u("Use a literal repeat count from 1 to "+Oe.repetitions,v),P={range:y.range,kind:"times",count:Number(v.text),body:h(oe)};else{let d=/^([1-9]\d?):([1-9]\d?)$/.exec(v.text);(!d||d.slice(1).some(p=>Number(p)>16))&&u("Use an actual:normal tuplet ratio from 1 to 16 on each side",v),P={range:y.range,kind:"tuplet",scale:[BigInt(d[2]),BigInt(d[1])],body:h(oe)}}}else if(y.text==="rest"||y.text==="skip"||y.text==="slash"||y.text==="|")if(c(),y.text==="|")P={kind:"|",range:y.range};else{let v=te();v.some(d=>!W(d))&&u("This rhythm has no pitched head",y),P={kind:y.text,marks:v,range:y.range}}else{g.push(J());continue}P.range=[y.range[0],r[a-1].range[1]],g.push(P)}return g}function ue(b=!1){if(l()!=="voice"){let P=r[a].range,F=oe(!0);return b&&F.some(v=>v.kind==="attack")&&F.every(v=>["attack","duration","rest","skip","slash"].includes(v.kind))?[{name:"main",range:P,body:[{kind:"fragment",range:[P[0],F[F.length-1].range[1]],body:F}]}]:[{name:"main",range:P,body:F}]}let g=[],y=new Set;for(;l()==="voice";){c();let P=r[a],F=m();y.has(F)&&u("Duplicate voice "+F,P),y.add(F);let v=O("staff",!0);g.push({name:F,range:P.range,settings:v,body:h(oe)})}return g}function C(){let b={};for(;["font","size","style","ink","line","align","spacing"].includes(l());){if(["font","size","style","ink"].includes(l())){Object.assign(b,Y());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 $(){let b=[];for(;l()==="text";){c();let g=r[a].range,y=m();b.some(v=>v.voice.name===y)&&u("Duplicate text lane");let P=C(),F=h(()=>{let v=[],d=P;for(;l()!=="}";){let p=r[a],w=Os.exec(l());if(w)c(),v.push(ce(w,p.range));else if(l()==="|")c(),v.push({kind:"|",range:p.range});else if(l()==="skip")c(),v.push({kind:"skip",range:p.range});else if(["font","size","style","ink","line","align","spacing"].includes(l()))d={...d,...C()};else{let I=l()==="start"||l()==="end"?c().text:void 0,U=l()==="sign",G;U?(c(),G=m()):G=E();let de=[p.range[0],r[a-1].range[1]];I==="start"||I==="end"?v.push({kind:"textBoundary",boundary:{edge:I,text:G,glyph:U,style:d,range:de},range:de}):v.push({kind:"attack",heads:[],marks:[{kind:"text",text:G,glyph:U,style:d,range:de}],range:de})}}return v});b.push({voice:{name:y,range:g,body:F},style:P})}return b}function Z(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",P=g;if(l()==="+"){c(),P=c(),/^\d{1,9}\/[1-9]\d{0,8}$/.test(P.text)||u("Expected an offset in whole notes",P);let[F,v]=P.text.split("/").map(Number),d=F,p=v;for(;p;)[d,p]=[p,d%p];y=F/d+"/"+v/d}return{bar:Number(g.text),at:y,range:[b.range[0],P.range[1]]}}function O(b,g=!1,y=!1){let P={};function F(){f("at");let p=c();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 v(p){if(l()!=="at"){Object.assign(P,p);return}let w=F(),I=P.changes??={};I[w]={...I[w],...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(l());){let p=c(),w=c();if(p.text==="program")(!/^\d{1,3}$/.test(w.text)||Number(w.text)>127)&&u("Expected a MIDI program from 0 to 127",w),P.program=Number(w.text);else if(p.text==="map"){(b!=="drums"||!/^[a-z][a-z0-9_]*$/.test(w.text)||t.has(w.text))&&u("Expected a new percussion ID",w);let I=E();I.trim()||u("Expected a percussion label",w),f("line");let U=c();f("head");let G=c();f("stem");let de=c();f("midi");let fe=c();/^-?\d(?:\.5)?$/.test(U.text)||u("Expected a staff line or space",U),["normal","cross","circle-cross","triangle"].includes(G.text)||u("Unknown percussion head",G),de.text!=="up"&&de.text!=="down"&&u("Expected up or down",de),(!/^\d{1,3}$/.test(fe.text)||Number(fe.text)>127)&&u("Expected a MIDI pitch from 0 to 127",fe),(P.drums??=[]).push({id:w.text,label:I,line:Number(U.text),head:G.text,stem:de.text,midi:Number(fe.text)}),t.add(w.text)}else if(p.text==="meter")R(P.meters??={},w);else if(p.text==="accidentals")w.text!=="standard"&&w.text!=="cautionary"&&u("Expected standard or cautionary",w),P.cautionary=w.text==="cautionary";else if(p.text==="display"){w.text!=="meter"&&u("Expected display meter",w);let I=c();I.text!=="hidden"&&I.text!=="shown"&&u("Expected hidden or shown",I),v({displayMeter:I.text==="shown"})}else if(p.text==="groupBeats"){w.text!=="("&&u("Expected beat groups in parentheses",w);let I=[];for(;l()!==")";){let U=c();(!/^[1-9]\d?$/.test(U.text)||I.length>=32)&&u("Invalid beat group",U),I.push(Number(U.text))}I.length||u("Expected at least one beat group"),c(),P.beatGroups=I}else if(p.text==="ink")v({ink:w.text});else if(p.text==="stem"||p.text==="tabDirection")w.text!=="up"&&w.text!=="down"&&u("Expected up or down",w),P[p.text]=w.text;else if(p.text==="beams"||p.text==="flatBeams"||p.text==="beamRests"||p.text==="tabStems"||p.text==="stemlets"||p.text==="middleRests")w.text!=="on"&&w.text!=="off"&&u("Expected on or off",w),P[p.text==="beams"?"beam":p.text]=w.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(w.text)||u("Expected a key signature",w),l()==="at"||y){let I=l()==="at"?Z(p):{bar:1,at:"0/1",range:p.range};!y&&I.at==="0/1"&&I.bar>1?(P.keys??={})[I.bar]=w.text:(P.staffChanges??=[]).push({...I,key:w.text})}else P.key=w.text;else if(p.text==="sounds")(!/^[+-]?\d{1,3}$/.test(w.text)||Math.abs(Number(w.text))>127)&&u("Invalid sounding interval",w),(P.staffChanges??=[]).push({...Z(p),sounds:Number(w.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(w.text)||u("Unknown clef",w),l()==="at"||y){w.text==="none"&&u("A timed clef must be visible",w);let U=l()==="at"?Z(p):{bar:1,at:"0/1",range:p.range};(P.staffChanges??=[]).push({...U,clef:w.text})}else P.clef=w.text;else if(b!=="guitar")u("This setting needs a guitar part",p);else if(p.text==="view")w.text!=="tab"&&w.text!=="both"&&w.text!=="notation"&&u("Expected tab, notation or both",w),P.view=w.text;else if(p.text==="capo")/^(?:0|[1-9]|1\d|2[0-4])$/.test(w.text)||u("Expected capo fret 0 through 24",w),P.capo=Number(w.text);else if(w.text==="("){let I=[];for(;l()!==")";){let U=c();/^[A-G](?:#|b)?[0-8]$/.test(U.text)||u("Expected an open string pitch such as E4",U),I.length===8&&u("A tuning supports up to eight strings",U),I.push(U.text.slice(0,-1)+"/"+U.text.slice(-1))}I.length<4&&u("A tuning needs at least four strings",w),c(),v({tuning:I.join(",")})}else{let I={standard:"standard",dropD:"dropd",dagdad:"dagdad",eb:"eb",standardBanjo:"standardBanjo"};Object.prototype.hasOwnProperty.call(I,w.text)||u("Unknown guitar tuning",w),v({tuning:I[w.text]})}}return P}for(;l();){let b=c();if(b.text==="meter")k.length&&u("Declare the shared meters before the first part",b),R(x,c());else if(b.text==="pickup"){(j||k.length)&&u("Declare one pickup before the first part",b),q=c();let g=/^([1-9]\d{0,2})\/(1|2|4|8|16|32|64)$/.exec(q.text);g||u("Expected a pickup duration such as 1/8",q),j=[BigInt(g[1]),BigInt(g[2])]}else if(b.text==="edition")A(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 F={};h(()=>{for(;l()!=="}";){let v=c();if(v.text==="align"){F.align&&u("Duplicate score heading alignment",v),f("center"),F.align="center";continue}v.text!=="title"&&v.text!=="dedication"&&v.text!=="tempo"&&v.text!=="composer"&&u("Unknown score heading field",v),F[v.text]!==void 0&&u("Duplicate score heading field",v),F[v.text]=E()}}),V.heading=F;continue}let y=c(),P=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"&&P<=20||g.text==="scale"&&(!P||P>8))&&u("Invalid layout dimension",y),V[g.text]=P}});else if(b.text==="play")(k.length||T)&&u("Set playback once before the first part",b),T={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),T.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 P=Z(g);P.at!=="0/1"?(T.tempoChanges??=[]).push({...P,bpm:Number(y.text)}):(s.has(P.bar)&&u("Duplicate tempo change at this bar",y),s.set(P.bar,P.range),(T.tempos??={})[P.bar]=Number(y.text))}else T.tempo=Number(y.text)}else if(g.text==="controls"||g.text==="controlSize"||g.text==="position"||g.text==="inset"){let y=c(),P=T.controls??={};g.text==="controls"?y.text==="off"||y.text==="hover"||y.text==="always"?P.visibility=y.text:u("Expected controls off, hover or always",y):g.text==="controlSize"?hr(y.text)?P.size=y.text:u("Expected controlSize auto, mini or large",y):g.text==="position"?gr(y.text)?P.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),P.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):T.swing=y.text}else if(g.text==="performer"){let y=c();wt(y.text)?T.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),T.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),H=g.text==="on"}else if(b.text==="alias")k.length&&u("Declare aliases before the first part",b),le();else if(b.text==="pattern"){let g=r[a],y=m();S.has(y)&&u("Duplicate pattern "+y,g),S.set(y,h(oe))}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(m());let P=c();y.length<2&&u("A group needs at least two parts",g),_.push({type:g.text,parts:y,range:[b.range[0],P.range[1]]})}else if($i(b.text)){t=new Set(Hs);let g=r[a],y=l()==="{"?void 0:m();y&&k.some(p=>p.id===y)&&u("Duplicate part ID "+y,g);let P,F=[],v={},d;if(b.text==="piano")h(()=>{P=L(y),v=O("piano");for(let p of["upper","lower"]){let w=f(p),I=r[a],U=l()==="{"?void 0:m();F.some(he=>(he.id??he.name)===(U??p))&&u("Duplicate staff ID "+(U??p),U?I:w);let G,de,fe=h(()=>(G=L(U),de=O("piano",!1,!0),ue()));F.push({...D(G),...de,name:p,range:w.range,voices:fe})}d=$()});else{let p={},w=h(()=>{if(P=L(y),l()==="stave"){c();let G=m();p=h(()=>L(G))}v=O(b.text);let I=b.text==="guitar"&&!v.meters&&!Object.keys(x).length&&!j,U=ue(I);return d=$(),U});F.push({...D(p),name:"main",range:b.range,voices:w})}k.push({...P,...v,...d?.length&&{lanes:d},kind:b.text,range:b.range,staves:F})}else u("Expected a score setting, alias, pattern or part",b)}return k.length||u("Expected a part"),{groups:_,tempoRanges:s,editions:M,patterns:S,parts:k,scoreMeters:x,pickup:j,pickupRange:q?.range,playback:T,measureNumbers:H,layout:V,transpose:B}}var Je=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 en(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 kt=([o,e])=>o+"/"+e;function ft(o){let[e,n]=o.split("/");return[BigInt(e),BigInt(n)]}function Zi(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 js(o,e){let n=Vs(e),t=(E,A,L,D=[])=>{throw new Je(E,A,o,L,D)},{groups:s,tempoRanges:r,editions:a,patterns:i,parts:l,scoreMeters:c,pickup:u,pickupRange:f,playback:m,measureNumbers:h,layout:S,transpose:k}=zs(o,t,n),x=c[1]?.value??"4/4",T=u&&kt(en(...u,t,f,[])),B=[BigInt(1),BigInt(4)],H=[BigInt(0),BigInt(1)],_=0,M=0;function V(E,A){++_>n.steps&&t("work-limit","Phrase expansion exceeds "+n.steps+" work steps",E,A)}function j(E,A,L,D,Y){let ne={name:L.name,...L.settings&&{settings:L.settings},range:L.range,events:[],measures:[],spans:[]},{events:se,measures:re,spans:le}=ne,ae=1,te=0,Q=H,J=!1,ce=0,oe=0,ue=!1,C,$;function Z(g,y,P){let F=kt(Q);Y.bars[ae-1]!==void 0&&Y.bars[ae-1]!==F&&t("alignment","Voices disagree on the length of bar "+ae,g,y),Y.bars[ae-1]=F,re.push({number:ae,start:te,end:se.length,barlineRange:g,trace:y,span:F,fragment:J,newRow:ue,rehearsal:C,closing:P,opening:$}),$=P==="repeat-both"?"repeat-begin":void 0,te=se.length,ae++,Q=H,C=void 0,ue=!1}function O(g,y,P,F,v){++M>n.events&&t("event-limit","Score exceeds "+n.events+" expanded attacks, rests or skips",g.range,v);let d=en(y[0]*F[0],y[1]*F[1],t,g.range,v),p=Zt(g.marks??[]);p&&t("syntax",p.reason,p.range,v);let w=[E.id??D+1,A.id??A.name,L.name,se.length+1].join("."),I=g.kind==="attack"?g.heads.map((U,G)=>{(E.kind==="drums"!="drum"in U||"string"in U&&E.kind!=="guitar")&&t("instrument","This head does not belong to "+E.kind,U.range,v);let de=Zt(U.marks);de&&t("syntax",de.reason,de.range,v);for(let pe of U.marks){if(pe.kind==="sustain"){let[Le,Ae]=ft(pe.duration);Le*d[1]>d[0]*Ae&&t("syntax","Head sustain exceeds this attack; write a separate voice or tie",pe.range,v);let ve=g.marks?.find(Ge=>Ge.kind==="grace");if(ve?.kind==="grace"&&ve.steal&&ve.side==="before"){let[Ge,gt]=ft(ve.steal);Le*d[1]*gt<=d[0]*Ae*Ge&&t("syntax","Before-grace would consume the entire sounding head",ve.range,v)}}["bend","prebend","slideIn","slideOut"].includes(pe.kind)&&(!("fret"in U)||typeof U.fret!="number")&&t("instrument","This technique needs a pitched fret",pe.range,v)}let fe=U.marks.find(pe=>pe.kind==="hammer"||pe.kind==="slide"||pe.kind==="pull");if(!fe||fe.kind!=="hammer"&&fe.kind!=="slide"&&fe.kind!=="pull")return U;let he=Zi(U,se[se.length-1],fe.kind);return he||t("hammer",fe.kind==="hammer"?"Expected a lower fret on this string in the preceding attack":"Expected a compatible preceding fret on this string",fe.range,v),le.push({kind:fe.kind,from:he,to:{event:w,head:G},range:fe.range}),fe.kind==="hammer"?{...U,hammerFrom:he}:U}):[];se.push({id:w,bar:ae,at:kt(Q),duration:kt(d),writtenDuration:kt(y),kind:g.kind,...ce&&{transpose:ce},...oe&&{soundingOctaves:oe},heads:I,marks:g.marks??[],range:g.range,rhythmRange:P,trace:v}),Q=en(Q[0]*d[1]+d[0]*Q[1],Q[1]*d[1],t,g.range,v)}function b(g,y,P,F,v){v.length>Oe.depth&&t("depth-limit","Phrase expansion is too deep",v[v.length-1].range,v);for(let d of g)switch(V(d.range,v),d.kind){case"meter":{Q[0]&&t("alignment","Change meter at the beginning of a bar",d.range,v);let p=Y.meters[ae],w=d.signature;p&&(p.value!==w.value||p.sign!==w.sign)&&t("alignment","Conflicting meters for bar "+ae,w.range,v),Y.meters[ae]??={...w,...v.length&&{trace:v}};break}case"duration":y=d.value,P=d.range;break;case"|":Z(d.range,v,d.closing);break;case"textBoundary":{let p=d.boundary.edge==="start"?"0/1":Y.bars[ae-1];kt(Q)!==p&&t("alignment","Put a text boundary at the indicated bar edge",d.range,v),(ne.boundaries??=[]).push({...d.boundary,bar:ae});break}case"mark":case"break":case"repeatStart":Q[0]&&t("alignment","Place this directive at the beginning of a bar",d.range,v),d.kind==="mark"?C=d.text:d.kind==="repeatStart"?$="repeat-begin":ue=!0;break;case"fragment":{(Q[0]||J)&&t("alignment","Start a fragment at a bar boundary",d.range,v),J=!0;let p=ae;b(d.body,y,P,F,v),(Q[0]||p===ae)&&Z(d.range,v),J=!1;break}case"octave":{let p=oe;oe+=d.semitones/12,b(d.body,y,P,F,v),oe=p;break}case"transpose":{let p=ce;ce+=d.semitones,Math.abs(ce)>127&&t("instrument","Transposition exceeds the MIDI range",d.range,v),b(d.body,y,P,F,v),ce=p;break}case"crescendo":case"diminuendo":case"continuousBeam":case"feather":case"tremolo":{let p=se.length,w=d.kind==="tremolo"?en(F[0],F[1]*BigInt(2),t,d.range,v):F;b(d.body,y,P,w,v);let I=se.slice(p),U=I[0],G=I[I.length-1];I.length<2&&t("syntax","This span needs two endpoints",d.range,v),(d.kind==="feather"||d.kind==="continuousBeam")&&(I.some(de=>!de.heads.length||Number(de.writtenDuration.split("/")[1])<(d.kind==="feather"?16:8))||d.kind==="feather"&&U.bar!==G.bar)&&t("syntax","Invalid pitches or durations for this beam",d.range,v),d.kind==="tremolo"&&(I.length!==2||U.bar!==G.bar||!U.heads.length||!G.heads.length||U.writtenDuration!==G.writtenDuration||!["1/1","1/2","1/4"].includes(U.writtenDuration))&&t("syntax","Tremolo needs two equal whole, half or quarter attacks in one measure",d.range,v),le.push({kind:d.kind,first:U.id,last:G.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,P,F,v);let w=se.slice(p);(!w.length||d.kind!=="palmMute"&&w.length<2)&&t("syntax","This span needs more notes",d.range,v),d.kind==="palmMute"&&E.kind!=="guitar"&&t("instrument","Palm mute needs a guitar",d.range,v),d.kind==="beam"&&pr(se,p,se.length-1,d.range,v,t),le.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,F,[...v,{pattern:d.name,range:d.range}]);break;case"times":for(let p=1;p<=d.count;p++)V(d.range,v),b(d.body,y,P,F,[...v,{iteration:p,range:d.range}]);break;case"volta":{Q[0]&&t("bar-length","Start a repeat at a shared barline",d.range,v);let p=ae;b(d.body,y,P,F,v);let w=ae-1;(Q[0]||w<p)&&t("bar-length","End the repeat body with a full bar",d.range,v);let I=d.endings.map(U=>{let G=ae;return b(U,y,P,F,v),(Q[0]||ae===G)&&t("bar-length","Each ending needs at least one complete bar",d.range,v),{first:G,last:ae-1}});(ne.repeats??=[]).push({first:p,bodyEnd:w,endings:I,...d.count&&{count:d.count},range:d.range});break}case"tuplet":{let p=se.length,w=d.scale[1]+":"+d.scale[0],I=en(F[0]*d.scale[0],F[1]*d.scale[1],t,d.range,v);b(d.body,y,P,I,[...v,{tuplet:w,range:d.range}]),se.length>p&&le.push({kind:"tuplet",ratio:w,first:se[p].id,last:se[se.length-1].id,range:d.range});break}default:O(d,y,P,F,v)}}if(b(L.body,B,void 0,[BigInt(1),BigInt(1)],[]),Q[0]){let g=se[se.length-1];t("bar-length","End the final measure with |",g.range,g.trace)}return Fs(ne,t),re.length||t("bar-length","Expected at least one measure",L.range),Y.voiceLength!==void 0&&Y.voiceLength!==re.length&&t("alignment","Every voice in a part must cover the same number of bars",L.range),Y.voiceLength=re.length,ne}function q(E,A,L){let D,Y=!1,ne=[...A,...L];for(let se=0;se<E.bars.length;se++){let re=se+1;E.meters[re]?(D=E.meters[re],Y=!0):!Y&&c[re]&&(D=c[re]);let le=D?.value??"4/4",ae=ft(le);re===1&&u&&u[0]*ae[1]>=ae[0]*u[1]&&t("syntax","Pickup must be shorter than the opening meter "+le,f);let te=re===1&&u?u:ae,[Q,J]=ft(E.bars[se]);if(Q*te[1]!==te[0]*J){let ce=A.find(oe=>!oe.measures[se].fragment);if(ce){let oe=ce.measures[se];if(Q*te[1]>te[0]*J)for(let ue=oe.start;ue<oe.end;ue++){let C=ce.events[ue],[$,Z]=ft(C.at),[O,b]=ft(C.duration);($*b+O*Z)*te[1]>te[0]*Z*b&&t("bar-length","Attack crosses the end of bar "+re,C.range,C.trace)}t("bar-length","Bar "+re+" contains "+oe.span+" of a whole note, expected "+kt(te),oe.barlineRange,oe.trace)}}for(let ce of ne){let oe=ce.measures[se];oe.meter=le,oe.meterSign=D?.sign,oe.meterRange=D?.range}}}function z(E,A){let L=(D,Y)=>{let[ne,se]=ft(D),[re,le]=ft(Y);return Number(ne*le-re*se)};E.sort((D,Y)=>D.bar-Y.bar||L(D.at,Y.at));for(let D of E)(!A[D.bar-1]||L(D.at,A[D.bar-1])>=0)&&t("alignment","Timed setting lies outside its written measure",D.range)}let R=l.map((E,A)=>{let{lanes:L,...D}=E,Y={bars:[],meters:{...E.meters}},ne=E.staves.map(le=>({...le,voices:le.voices.map(ae=>j(E,le,ae,A,Y))})),se=L?.map(le=>({name:le.voice.name,style:le.style,voice:j(E,{name:"main",range:E.range,voices:[]},{...le.voice,name:"text-"+le.voice.name},A,Y)})),re=Y.bars.length;for(let[le,ae]of Object.entries(Y.meters))Number(le)>re&&t("alignment","Meter change lies beyond this part",ae.range,ae.trace);for(let le of Object.keys(E.changes??{}))Number(le)>re&&t("alignment","Part setting change lies beyond the score",E.range);for(let le of Object.keys(E.keys??{}))Number(le)>re&&t("alignment","Key change lies beyond the score",E.range);for(let le of ne){let ae=[...E.staffChanges??[],...le.staffChanges??[]];if(!ae.length)continue;z(ae,Y.bars);let te=new Set,Q=le.voices.map(J=>new Set(J.events.map(ce=>ce.bar+":"+ce.at)));for(let J of ae){for(let ce of["key","clef","sounds"])if(J[ce]!==void 0){let oe=ce+":"+J.bar+":"+J.at;te.has(oe)&&t("alignment","Duplicate timed "+ce,J.range),te.add(oe)}(J.key||J.clef)&&J.at!=="0/1"&&(Q.some(ce=>!ce.has(J.bar+":"+J.at))||se?.length)&&t("alignment","Inline clef and key changes need a shared music-voice onset without a separate text lane",J.range)}le.staffChanges=ae}return q(Y,ne.flatMap(le=>le.voices),se?.map(le=>le.voice)??[]),{...D,...Object.keys(Y.meters).length&&{meters:Y.meters},measureCount:re,staves:ne,...se&&{text:se}}}),N=Math.max(...R.map(E=>E.measureCount));for(let[E,A]of Object.entries(c))Number(E)>N&&t("alignment","Meter change lies beyond the score",A.range);for(let[E,A]of r)E>N&&t("alignment","Tempo change lies beyond the score",A);if(m?.tempoChanges){let E=R[0].staves[0].voices[0].measures;for(let L of R){let D=L.staves[0].voices[0].measures;z(m.tempoChanges,D.map(ne=>ne.span));let Y=m.tempoChanges[m.tempoChanges.length-1];for(let ne=0;ne<Y.bar-1;ne++)D[ne].span!==E[ne].span&&t("alignment","Share the written bar grid before a global inline tempo",Y.range)}let A=new Set;for(let L of m.tempoChanges){let D=L.bar+":"+L.at;A.has(D)&&t("alignment","Duplicate timed tempo",L.range),A.add(D)}}let W=new Map(R.map((E,A)=>[E.id,A]));for(let E of s){let A=W.get(E.parts[0]);(A===void 0||E.parts.some((L,D)=>W.get(L)!==A+D))&&t("alignment","Group members must be adjacent named parts in score order",E.range)}for(let E of a){let A=R.find(D=>D.id===E.part);E.part&&!A&&t("alignment","Unknown edition part "+E.part,E.range);let L=A?.measureCount??Math.min(...R.map(D=>D.measureCount));for(let D of E.anchors)(D.measure>L||D.field.endsWith("Turns")&&D.measure===L)&&t("alignment","Edition measure or turn outside the music",D.range);for(let D of E.cues){let Y=R.find(ne=>ne.id===D.part);(!Y||D.measure>Y.measureCount||D.measure>L)&&t("alignment","Missing cue instrument or measure",D.range)}}return{language:2,...s.length&&{groups:s},...a.length&&{editions:a},...k&&{transpose:k},...S&&{layout:S},...m&&{playback:m},...h!==void 0&&{measureNumbers:h},source:o,meter:x,meterRange:c[1]?.range,...u&&{pickup:T},measureCount:N,parts:R}}var Ne=Se(Me());var zt=Se(Me());function be(o,e){throw new ee("syntax",e,o)}function br(o,e){try{let n=JSON.parse(o);if(typeof n=="string"&&n.trim()&&!/[\r\n]/.test(n))return n}catch{}be(e,"Expected nonempty text in double quotes")}function Qi(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||be(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)&&be(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"))&&be(t,"A bend needs a pitched fretted attack");try{new zt.FrettedInstrument(n.tuning,n.capo).bentAttack(i,e.base,a)}catch(l){be(t,l.message)}return a}function eo(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)&&be(n,"Frame disagrees with the fretted chord")}e.heads.some(t=>!t.position)&&be(n,"A frame needs an explicit string for each chord member")}function yr(o,e,n,t,s="frame"){let r=/^([x\d,]+)(?:\s+barre=(\d+):(\d+)-(\d+))?$/.exec(o);(!r||!e.chord)&&be(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)&&be(t,"Supply four through eight strings in a diagram"),(s==="frame"&&i!==n.strings||a.some(m=>!/^(x|\d+)$/.test(m)))&&be(t,"Supply one fret or x per string");let l=a.map(m=>m==="x"?"x":Number(m));l.every(m=>m==="x")&&be(t,"A frame needs at least one sounding string"),l.some(m=>m!=="x"&&!Number.isSafeInteger(m))&&be(t,"Invalid frame fret"),s==="frame"&&eo(l,e,t);let c=l.filter(m=>typeof m=="number"&&m>0),u=Math.max(...c)>4?Math.min(...c):1;Math.max(...c)-u>=4&&be(t,"Frame spans more than four frets");let f;if(r[2]){let[m,h,S]=r.slice(2).map(Number);(h<=S||S<1||h>i||m<u||l[i-h]!==m||l[i-S]!==m||l.slice(i-h,i-S+1).some(k=>typeof k!="number"||k<m))&&be(t,"Barre endpoints must stop at the given fret, from lower to higher string"),f={fret:m,from:h,to:S}}return{frets:l,firstFret:u,barre:f}}function to(o,e,n,t){if(o.events.length&&be(t,"Put this command at the start of a bar"),o.boundaryRange??=t,e==="key"){(o.keyChange||!zt.default.hasKeySignature(n))&&be(t,"Expected one key signature per boundary");try{new zt.KeyManager(n)}catch{be(t,"Unsupported key signature")}o.keyChange=n}else if(e==="mark")o.rehearsal&&be(t,"Duplicate rehearsal mark"),o.rehearsal=br(n,t);else{let s=/^([1-9]\d*)\s+bars=([1-9]\d*)$/.exec(n);(!s||o.ending)&&be(t,"Expected one ending NUMBER bars=COUNT"),o.ending={label:s[1]+".",bars:Number(s[2]),range:t}}}var Bn=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||be(t,"Put this command in the first voice"),to(n,s,r,t);return}let a=n.events[n.events.length-1];switch(a||be(t,"Put this command immediately after an attack in this bar"),s){case"color":Fe(r)||be(t,"Expected a CSS color name or hex value"),a.color=r;break;case"bend":a.bend&&be(t,"One timed bend per attack"),a.bend={spec:Qi(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)))&&be(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)))&&be(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)&&be(t,"Put !silent! after a rest"),a.silent=t;break;case"chord":{a.heads.length||be(t,"A chord label needs a note or slash"),a.chord&&be(t,"Duplicate chord label");let i=/^("(?:[^"\\]|\\.)*")(?:\s+color=(\S+))?$/.exec(r);(!i||i[2]&&!Fe(i[2]))&&be(t,'Expected chord "label" with an optional color=NAME or hex value'),a.chord={text:br(i[1],t),...i[2]&&{color:i[2]},range:t};break}case"frame":a.frame&&be(t,"Duplicate chord frame"),a.frame={spec:yr(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)&&be(t,'Expected one lyric "syllable" with an optional - or extend=COUNT on a note'),a.lyric={text:br(i[1],t),hyphen:!!i[2],extend:Number(i[3]??0),range:t};break}default:throw new ee("fixed-layout","Use fixed layout for command "+s,t)}}finish(){this.mute&&be(this.mute.range,"Unclosed palm mute")}};function Fn(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)&&be(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)&&be(c.range,"Hyphen needs a following syllable in this bar and voice"),!c?.crossConnector&&c?.extend&&!a.events[l+c.extend]&&be(c.range,"Lyric extender must end in this bar and voice")})}}function ke(o,e){throw new ee("fixed-layout",`Use fixed layout for ${e}`,o.range)}function ye(o,e){throw new ee("syntax",e,o.range)}function mt(o){return new Ne.Fraction().parse(o).simplify()}function Gs(o,e){return(!/^[1-9]\d*\/[1-9]\d*$/.test(o)||!o.split("/").every(n=>Number.isSafeInteger(Number(n))))&&ye(e,`Invalid span '${o}'`),mt(o).toString()}function tn(o){return["true","false"].includes(o.value)||ye(o,`Expected true or false for ${o.key}`),o.value==="true"}function Us(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 no(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:Us(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)&&ye(s,"A piano uses treble and bass notation staves"),!(e.piano&&s.key==="hand"))switch(s.key){case"color":Fe(s.value)||ye(s,"Expected a CSS color name or hex value"),e.color=s.value;break;case"notation":e.notation=tn(s);break;case"tablature":e.tab=tn(s);break;case"fragment":e.fragment=tn(s);break;case"show-time":n=tn(s),e.timeRange=s.range;break;case"time":(["C","C|"].includes(s.value)||/^(?:\(\d+(?:\+\d+)+\)|\d+(?:\+\d+)+)\/\d+$/.test(s.value))&&ke(s,`printed time signature '${s.value}'`),Gs(s.value,s),e.meter=s.value,t=!0;break;case"pickup":e.pickup=Gs(s.value,s);break;case"key":Ne.default.hasKeySignature(s.value)||ye(s,"Invalid key signature");try{new Ne.KeyManager(s.value)}catch{ke(s,`key signature '${s.value}'`)}e.key=s.value;break;case"tuning":try{new Ne.Tuning(s.value)}catch{ye(s,"Invalid tuning")}e.tuning=s.value;break;case"capo":e.capo=Number(s.value),(!/^\d+$/.test(s.value)||!Number.isSafeInteger(e.capo))&&ye(s,"Expected a nonnegative capo fret");break;case"strings":e.strings=Number(s.value),(!Number.isInteger(e.strings)||e.strings<4||e.strings>8)&&ye(s,"Expected 4\u20138 strings");break;case"clef":s.value==="none"&&ke(s,`clef '${s.value}'`),["treble","bass","tenor","alto","percussion"].includes(s.value)||ye(s,"Invalid clef"),e.clef=s.value;break;case"fingering":case"accents":break;case"voice":break;default:ke(s,`stave option '${s.key}'`)}return e.showTime=n&&t,!e.notation&&!e.tab&&ye(o,"At least one staff must be visible"),e.pickup&&!mt(e.pickup).lessThan(mt(e.meter))&&ye(o,"Pickup must be shorter than the meter"),e}function Ws(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 ro(o,e){for(let n of e.params){switch(n.key){case"tempo":(!Number.isFinite(Number(n.value))||Number(n.value)<=0)&&ye(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":tn(n);break;case"tab-stem-direction":["up","down"].includes(n.value)||ye(n,"Invalid tab stem direction");break;case"beams":n.value==="explicit"&&ke(n,"explicit beam groups"),["auto","off"].includes(n.value)||ye(n,"Invalid beam mode");break;default:ke(n,`option '${n.key}'`)}o[n.key]=n.value}}function so(o){let e=o.time.replace(/s$/,"");try{Ne.default.durationToTicks(e)}catch{ye(o,`Invalid duration '${o.time}'`)}return{base:e,dots:Number(o.dot||0),slash:o.time.endsWith("s"),range:o.range}}function io(o,e,n,t,s,r){e.piano&&(o.fret!==void 0||!o.abc||!/^[A-G]$/.test(o.abc.key))&&ye(o,"Write named pitches such as C/4 on a piano stave"),o.decorator&&ke(o,`decorator '${o.decorator}'`),o.articulation&&!["T","-"].includes(o.articulation)&&ke(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 m=Number(o.fret);(a<1||a>e.strings||!Number.isSafeInteger(m))&&ye(o,"Invalid fret or string");try{c=xn(n,l,a)}catch{ye(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)&&ye(o,"Dead strike needs a physical string");let S;try{S=n.getNoteForFret(e.capo,a).toLowerCase()}catch{ye(o,"String outside the tuning")}return{range:o.range,written:S,sounding:null,position:{str:a,fret:"X"}}}/^[A-G]$/.test(o.abc.key)||ke(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&&ke(o,"a named pitch without an explicit fret on tab"),{range:o.range,written:h,sounding:c??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]=Lt(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 oo(o,e,n){let t=o.drums.map(a=>a.id),s=En(e.clef,e.tab,t,n);s&&ye(o,s);let{keys:r}=dt.note(t,"q");return t.map((a,i)=>({drum:a,range:o.drums[i].range,written:r[i],sounding:null}))}function ao(o,e,n,t,s){let r=new Set;for(let a of n){let i=e.heads[a];i.sounding===null&&ye(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)&&xr(c)===xr(i)))??-1;l<0&&ye(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 co(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)&&ye(e,"Tuplet must fit in this bar and voice");let a=vn(t,n);for(let i of o.events.slice(r))i.duration=mt(i.duration).multiply(a,t).simplify().toString();o.tuplets.push({start:r,count:s,numNotes:t,notesOccupied:a,range:e.range})}function lo(o,e,n,t,s,r,a,i){let l=new Ne.Tuning(e.tuning),c=new Ne.KeyManager(e.key),u=new Ne.Music,f=[],m=Us(o),h=Ws(n,t,m),S=new Bn(e,a,!i);i?.[0].keyChange&&c.setKey(i[0].keyChange);let k;for(let x of o.notes){if(x.time&&(r.rhythm=so(x)),x.command==="command"){S.apply(x,h),h.keyChange&&!h.events.length&&c.setKey(h.keyChange);continue}if(x.command==="bar"){let N={type:x.type,range:x.range};!h.events.length&&f.length&&!h.opening&&ke(x,"consecutive barlines"),!h.events.length&&!f.length&&!["single","repeat-begin"].includes(x.type)&&ke(x,"this opening barline"),h.events.length?(h.closing=N,f.push(h),h=Ws(n,t,m),i?.[f.length]?.keyChange&&c.setKey(i[f.length].keyChange)):h.opening&&ke(x,"consecutive empty barlines"),(!f.length||["repeat-begin","repeat-both"].includes(x.type))&&(h.opening=N);continue}if(x.command==="tuplet"){co(h,x,e.meter);continue}if(["open_beam","close_beam"].includes(x.command)||(x.command&&x.command!=="rest"&&ke(x,x.command),x.command==="rest"&&(x.params.explicit||Number(x.params.position))&&ke(x,"positioned rest"),(x.decorator||x.articulation&&!["T","-"].includes(x.articulation))&&ke(x,`technique '${x.decorator||x.articulation}'`),!x.command&&!x.chord&&!x.drums&&!x.abc&&x.fret===void 0))continue;let T=x.command==="rest"?[]:x.chord??[x];x.chord&&T.some(N=>N.time)&&ke(x,"duration changes inside a chord");let B=x.drums?oo(x,e,r.rhythm.slash):T.map(N=>{let W=io(N,e,l,c,u,r.rhythm.slash);return N.marks&&(W.marks=N.marks),W}),H=B.flatMap(N=>N.position?[N.position.str]:[]);new Set(H).size!==H.length&&ke(x,"a multi-stop chord on one string");let{base:_,dots:M,slash:V}=r.rhythm,j=Ne.default.durationToTicks(_),q=new Ne.Fraction(j,Ne.default.RESOLUTION).multiply(2**(M+1)-1,2**M).simplify().toString(),z={id:"a"+x.range.start,range:x.range,heads:B,base:_,dots:M,rhythmRange:r.rhythm.range,slash:V,duration:q,onset:"0/1"},R=T.flatMap((N,W)=>x.articulation==="T"||N.articulation==="T"?[W]:[]);ao(k,z,R,s,x),h.events.push(z),k=z}S.finish(),!h.events.length&&h.boundaryRange&&ye({range:h.boundaryRange},"Boundary command needs a following measure"),h.events.length?f.push(h):h.opening&&ke({range:h.opening.range},"a barline without a following measure");for(let x of f){let T=new Ne.Fraction(0,1);for(let B of x.events)B.onset=T.simplify().toString(),T.add(mt(B.duration));x.span=T.simplify().toString()}return f}function qs(o,e){let n=o.voices[0]?.bars;if(!n?.length)throw new ee("measure","Empty stave",o.node.range);o.state.piano&&!o.voices.some(s=>s.bars[0]?.hand==="left")&&ye(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 ee("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:mt(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 ee("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 ee("measure","Voice barlines disagree",m)}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 xr(o){return o.written[0]+o.written.slice(o.written.indexOf("/"))}function uo(o,e,n){let t=new Ne.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 m=c.get(f.onset)??[];m.push({event:f,hand:u.hand}),c.set(f.onset,m)}for(let u of[...c.keys()].sort((f,m)=>mt(f).value()-mt(m).value())){let f=new Map;for(let{event:m,hand:h}of c.get(u))s.set(m.id,m.heads),m.heads.forEach((S,k)=>{if(S.sounding===null)return;let x=xr(S),T=(h??"")+x,B=r.get(m.id+"/"+k),H=B&&s.get(B.from)[B.fromHead];if(S.inheritSign){let M=H?.written.split("/")[0]??l.get(T)??i[x[0]].replace(/n$/,"");if(M==="?")throw new ee("syntax","Write the accidental after a conflicting unison",S.range);S.written=M+x.slice(1),S.position||(S.sounding=S.written)}if(n&&Ce(S.sounding)===void 0)throw new ee("syntax","Transposed note is outside the playable MIDI range",S.range);if(H&&H.written!==S.written)throw new ee("syntax","Tied pitches differ",S.range);let _=S.written.split("/")[0];f.set(T,f.has(T)&&f.get(T)!==_?"?":_)});for(let[m,h]of f)l.set(m,h)}}}function fo(o){let e=o.options?.find(n=>n.key==="hand");return o.element==="piano"?(e&&e.value!=="right"&&ye(e,"Start a piano with the right hand, then add voice hand=left"),"right"):((!e||!["right","left"].includes(e.value))&&ye(e??o,"A piano voice needs hand=right or hand=left"),e.value)}function ot(o,e={}){if(e.language===void 0||e.language===2)return js(o,e.capacity);if(e.language!==1)throw new RangeError("Expected VexTab language 1 or 2");let n=$t(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 m=u.params.find(S=>["tempo","instrument","player"].includes(S.key));l&&m&&ye(m,"Set flow playback options before the first stave");let h=u.params.find(S=>S.key==="measure-numbers");l&&h&&ye(h,"Set measure numbering before the first stave"),ro(i,u);continue}if(u.element!=="voice"||!l)l&&qs(l,t),l={node:u,state:no(u),voices:[]};else for(let m of u.options??[])!["voice","fingering","accents"].includes(m.key)&&!(l.state.piano&&m.key==="hand")&&ke(m,`voice option '${m.key}'`);u.text?.length&&ke({range:u.text[0].declaration},"timed text"),u.slurs?.length&&ke(u.slurs[0],"slur");let f=u.options?.find(m=>m.key==="voice")?.value;if(f&&!["top","bottom","new"].includes(f)&&ye(u,"Invalid voice direction"),u.notes?.length){let m=l.state.piano?fo(u):void 0,h=m?{rhythm:{base:"q",dots:0,slash:!1}}:a,S=lo(u,l.state,i,f,s,h,r,l.voices[0]?.bars);if(m)for(let k of S)k.hand=m;l.voices.push({bars:S,node:u})}else(u.element==="voice"||u.element==="piano")&&ye(u,"Empty voice")}l||ye(n[0],"Expected a stave"),qs(l,t),uo(t,s,!!Number(i.transpose)),Fn(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 Vn=class{constructor(e){this.artist=e}newError(e,n){return new X.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"||!Fe(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(!(X.Flow?.hasKeySignature?X.Flow.hasKeySignature(i.value):Yn(X.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{mr(i.value)}catch{throw l(`Invalid time signature: '${i.value}'`)}break;case"tuning":try{new X.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(zr(e.chord,n=>dn(n,"time","dot","fret","prebend","openSlide","marks","abc","octave","string","articulation","decorator")),e.articulation,e.decorator)}parseFret(e){this.artist.addNote(dn(e,"time","dot","fret","prebend","openSlide","marks","string","articulation","decorator"))}parseABC(e){this.artist.addNote(dn(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()>=X.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=En(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(m){throw this.newError(c,`Bad text or duration. Did you forget a comma?${m}`)}};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 mo(o){return typeof o?.addStave=="function"}var $e=class o{constructor(e,n){this.valid=!1;if(mo(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 Vn(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):ot(e,{language:2,capacity:this.capacity});return this.valid=!!n,n}parseFixed(e){let n;try{n=$t(e)}catch(t){throw t instanceof ee?Object.assign(new X.RERR("ParseError",t.message),{range:t.range}):t}return n&&this.compiler.generate(n),n}};function Ue(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 Ks(o,e){let n=e==="right"?"upper":e==="left"?"lower":"main";return{role:n,staff:o.instrument?.staves[n]}}function Xs(o,e,n){let{role:t,staff:s}=Ks(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 po(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 ee("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 ho(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 ee("fixed-layout","Conflicting conductor rehearsal marks",o[r].measures[t].range);s.rehearsal=a.rehearsal}}return s})}function vr(o,e){po(o);function n(i,l){let c=o[i],{role:u,staff:f}=Ks(c,l),m=(c.instrument?.id??i+1)+"."+(f?.id??u);return u==="main"&&c.measures[0].state.tab?m+"."+l:m}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(m=>typeof m=="object"&&"stave"in m&&typeof m.stave=="string"?{...m,stave:n(l,m.stave)}:m)}))}))}))),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(m=>r.get(m)).filter(m=>m!==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:ho(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 Ys(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 nn(o){return[...o.lyric?[o.lyric]:[],...o.verses??[]]}function Js(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 nn(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 ee("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=Se(Me());function wr(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 $s(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 Zs=new WeakMap;function je(o,e=0){if(!Number.isInteger(e)||!o.parts[e])throw new RangeError("No instrument at partIndex "+e);let n=Zs.get(o);n||Zs.set(o,n=new Map);let t=n.get(e);if(t)return t;let s=o.parts[e],r=wr(o.source),a=r(s.range),{id:i,name:l,shortName:c,sounds:u}=s,m=(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"),S=new xe.Music,k=s.key??"C",x=new xe.KeyManager(k),T=new Map,B=s.capo??0,H=s.staves.some(C=>C.voices.some($=>$.events.some(Z=>Z.heads.some(O=>"pitch"in O))));if(H&&(s.view==="tab"||s.view==="both"))throw new ee("measure","A tab view needs a string and fret for every pitch",a);function _(C,$){if(!Fe(C))throw new ee("measure","Expected a CSS color name or hex code",$);return C}let M=s.tuning??"standard",V=s.staves[0].voices[0].measures[0],j=V.meter??o.meter,q=V.meterRange??o.meterRange,z={declaration:a,color:s.ink&&s.ink!=="default"?_(s.ink,a):void 0,timeRange:r(q??s.range),meter:j,showTime:!!q,tab:s.kind==="guitar"&&s.view!=="notation"&&!H,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},R=[],N={...o.groups&&{groups:o.groups},...m&&{instrument:m},source:o.source,measures:R,ties:[],spans:[],playback:o.playback,layout:o.layout,measureNumbers:o.measureNumbers??!1},W=new Map;N.program=s.program;let E=s.drums?.length?new xe.PercussionMap([...xe.PercussionMap.kit,...s.drums]):dt;s.kind==="drums"&&(z.kit=E);let A=new xe.Fraction().parse(j).simplify().toString(),L=new Map;function D(C){if(!C||s.kind==="drums")return;let $=k+"/"+C;return L.has($)||L.set($,new vt(C,k)),L.get($)}function Y(C,$){let Z=r(C.range),O=[],b;if("drum"in C)b={drum:C.drum,midi:s.drums?.find(g=>g.id===C.drum)?.midi,written:E.note([C.drum],"q").keys[0],sounding:null,range:Z};else if("pitch"in C){let g=C.pitch[0].toLowerCase(),y=C.pitch.slice(1,-1);x.reset();let P=y?g+(y==="n"?"":y):x.getAccidental(g).note,F=$?$.pitch(P,Number(C.pitch.slice(-1))):P+"/"+C.pitch.slice(-1);b={written:F,sounding:F,range:Z}}else{if(C.string>z.strings)throw new ee("measure","String outside the tuning",Z);let g={str:C.string,fret:C.fret==="x"?"X":C.fret+($?.semitones??0)};if(typeof g.fret=="number"&&g.fret<0)throw new ee("measure","Transposition puts fret outside the original string",Z);let P=(C.marks.find(p=>p.kind==="prebend")?.semitones??0)+(typeof g.fret=="number"?g.fret:0)+B,F=$?.target??k;T.has(F)||T.set(F,new xe.KeyManager(F));let[v,d]=Lt(h,T.get(F),S,String(P),C.string);b={position:g,written:v+"/"+d,sounding:C.fret==="x"?null:xn(h,P,C.string),range:Z}}s.cautionary&&b.position&&b.written.split("/")[0].length>1&&(b.accidental=b.written.split("/")[0].slice(1),b.cautionary=!0);for(let g of C.marks){if(g.kind==="velocity"&&(b.velocity=g.value),g.kind==="sustain"&&(b.sustain=g.duration),g.kind==="prebend"&&(b.prebend={semitones:g.semitones,release:g.release}),(g.kind==="slideIn"||g.kind==="slideOut")&&(b.openSlide={edge:g.kind==="slideIn"?"in":"out",side:g.side}),g.kind==="write"){if(!b.position)throw new ee("measure","A written-pitch override needs a fretted head",r(g.range));let y=g.pitch[0].toLowerCase(),P=g.pitch.slice(1,-1),F=P?y+(P==="n"?"":P):x.getAccidental(y).note;b.written=$?$.pitch(F,Number(g.pitch.slice(-1))):F+"/"+g.pitch.slice(-1)}g.kind==="gliss"&&(b.glissFrom=g.fromHead),g.kind==="release"&&(b.release=g),g.kind==="sign"&&O.push({articulation:g.code,position:g.position}),(g.kind==="finger"||g.kind==="stringNumber")&&O.push({finger:String(g.value),stringNumber:g.kind==="stringNumber",position:g.side})}for(let g of C.marks)(g.kind==="courtesy"||g.kind==="showSign")&&(b.accidental=b.written.split("/")[0].slice(1)||"n",b.cautionary=g.kind==="courtesy");for(let g of C.marks)(g.kind==="hammer"||g.kind==="pull"||g.kind==="slide")&&(b.connection=g.kind);if("hammerFrom"in C&&C.hammerFrom&&(b.hammer=!0),O.length&&(b.marks=O),b.sounding&&Ce(b.sounding)===void 0)throw new ee("measure","Pitch outside MIDI range",Z);return b}function ne(C,$){let Z=C.pitches.map(g=>(Array.isArray(g)?g:[g]).map(y=>Y({...typeof y=="string"?{pitch:y}:y,marks:[],range:C.range},$))),O=Z.some(g=>g.some(y=>y.position));if(O&&(s.kind!=="guitar"||Z.some(g=>g.some(y=>!y.position))))throw new ee("measure","Write every guitar grace head as a fret/string, or use written pitches throughout",r(C.range));if(!O&&!z.notation)throw new ee("measure","TAB grace notes need explicit fret/string positions",r(C.range));let b=O?Z.map(g=>g.map(y=>y.position)):void 0;if(b?.some(g=>new Set(g.map(y=>y.str)).size!==g.length))throw new ee("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:b,fingerings:C.fingerings,pitches:Z.map((g,y)=>Array.isArray(C.pitches[y])?g.map(P=>P.written):g[0].written)}}function se(C,$){let Z=D((o.transpose??0)+(C.transpose??0));for(let P of[C.marks,...C.heads.map(F=>F.marks)]){let F=Zt(P);if(F)throw new ee("measure",F.reason,r(F.range))}let O=C.heads.map(P=>Y(P,Z)),b=D(($??0)+12*(C.soundingOctaves??0));if($!==void 0||C.soundingOctaves)for(let P of O){if(!P.sounding)continue;let F=$===void 0?P.sounding:P.written,[v,d]=F.split("/");if(P.sounding=b?b.pitch(v,Number(d)):F,Ce(P.sounding)===void 0)throw new ee("measure","Sounding pitch exceeds the MIDI range after the octave or instrument shift",P.range)}if(C.kind==="slash"){if(z.tab)throw new ee("measure","Give a slash a notation-only staff",r(C.range));O.push({written:"b/4",sounding:null,range:r(C.range)})}let g={id:C.id,range:r(C.range),heads:O,slash:C.kind==="slash",onset:C.at,duration:C.duration,...$s(C.writtenDuration)};C.rhythmRange&&(g.rhythmRange=r(C.rhythmRange)),C.kind==="skip"&&(g.silent=g.range),C.heads.forEach((P,F)=>{for(let v of P.marks)if(v.kind==="bend"&&"string"in P){let d=r(v.range),p=O.map(I=>I.position);if(O[F].bend||O[F].prebend||p.some(I=>!I||typeof I.fret!="number"))throw new ee("measure","A bend needs pitched frets and one contour per string",d);let w={string:P.string,semitones:v.semitones,rise:v.rise,release:v.release,hold:v.hold};try{new xe.FrettedInstrument(z.tuning,B).bentAttack(p,g.base,w)}catch(I){throw new ee("measure",I.message,d)}O[F].bend=w,g.bend??={spec:w,range:d}}});for(let P of C.marks){if(P.kind==="slash"){if(!O.length)throw new ee("measure","A slash needs a written head",r(P.range));g.slash=!0}if(P.kind==="lyric"){let F={...P,range:r(P.range)};P.verse?(g.verses??=[]).push(F):g.lyric=F}if(P.kind==="harmony"){let{root:F,bass:v,quality:d}=P;g.harmony=xe.NotationSpelling.transposeChord({root:F,quality:d,bass:v},Z?.semitones??0,Z?.steps??0),g.chord={text:xe.NotationSpelling.chordText(g.harmony),range:r(P.range)}}if(P.kind==="stem"){if(!O.length)throw new ee("measure","A stem needs a written head",r(P.range));g.stem=P.value}if(P.kind==="dynamic"&&(g.dynamic=P.value),(P.kind==="ossia"||P.kind==="ornament"||P.kind==="grace")&&(!O.length||!z.notation&&P.kind!=="grace"||O.some(F=>!!F.drum)))throw new ee("measure","Grace notes, ornaments and ossias need a pitched notation anchor",r(P.range));if(P.kind==="ornament"&&(g.ornament=P.value),P.kind==="onStaff"||P.kind==="sharedStem"){if(!z.piano||P.kind==="sharedStem"&&!O.length)throw new ee("measure","Staff assignments need piano and a shared stem needs pitched notes",r(P.range));P.kind==="onStaff"?g.displayHand=P.hand==="upper"?"right":"left":g.sharedStem=P.name}if(P.kind==="grace"&&(g.grace=ne(P,Z)),P.kind==="ossia"&&(g.ossia={duration:P.duration,notes:P.notes.map(F=>({key:Y({pitch:F.pitch,range:P.range,marks:[]},Z).written,ornament:F.ornament}))}),P.kind==="symbol"&&(g.chord={text:Z?lr(P.text,Z):P.text,color:P.ink&&_(P.ink,r(P.range)),range:r(P.range)}),P.kind==="line"){if(C.kind!=="rest")throw new ee("measure","Only a rest takes a staff line",r(P.range));g.restLine=P.value}if(P.kind==="ink"&&(g.color=_(P.value,r(P.range))),P.kind==="label"){let F=P.style;(g.labels??=[]).push({text:P.text,...F,range:r(P.range),ink:F.ink&&_(F.ink,r(P.range))})}if((P.kind==="tap"||P.kind==="vibrato"||"direction"in P)&&(g.gestures??=[]).push(P),P.kind==="accent"){if(!O.length)throw new ee("measure","Accent needs a head",r(P.range));(O[0].marks??=[]).push({position:"above"})}}let y=C.marks.find(P=>P.kind==="frame"||P.kind==="diagram");if(y?.kind==="frame"||y?.kind==="diagram"){let P=Z?.semitones??0,F=y.frets.map(w=>w==="x"?w:w+P),v=y.barre,d=v&&v[0]+P!==0?" barre="+(v[0]+P)+":"+v[1]+"-"+v[2]:"",p=r(y.range);if(y.kind==="diagram"&&C.kind!=="attack"&&C.kind!=="rest")throw new ee("measure","Anchor the chord diagram to a note or rest",p);g.frame={range:p,spec:yr(F.join(",")+d,g,z,p,y.kind)}}return g}let re=new Map;function le(C){return C.trace.flatMap($=>"pattern"in $?["p"+$.range[0]]:"iteration"in $?["r"+$.range[0]+":"+$.iteration]:[]).join("/")}function ae(C,$,Z){let O=$.find(d=>d.start),b=$.find(d=>!d.start),g=$.find(d=>d!==O&&d!==b);if(g)throw new ee("measure","Duplicate tie endpoint "+C,g.range);if(!O||!b)throw new ee("measure","Unpaired tie "+C,(O??b).range);let y=O.event.heads[O.index],P=b.event.heads[b.index];if(!(O.bar<b.bar||O.bar===b.bar&&new xe.Fraction().parse(O.event.onset).lessThan(new xe.Fraction().parse(b.event.onset)))||y.sounding===null||y.written!==P.written||y.sounding!==P.sounding||y.position?.str!==P.position?.str||O.hand!==b.hand)throw new ee("measure","Named tie needs a later matching head on the same staff",b.range);let v="named-tie-"+C+(Z?"-"+O.event.id:"");N.ties.push({id:v,from:O.event.id,fromHead:O.index,to:b.event.id,toHead:b.index,...O.side&&{side:O.side},range:b.range})}function te(){for(let[C,$]of re){if($.length<=2){ae(C,$,!1);continue}let Z=new Map([["",[]]]),O=b=>b.slice(0,Math.max(0,b.lastIndexOf("/")));for(let b of $){for(let g=b.scope;!Z.has(g);g=O(g))Z.set(g,[]);Z.get(b.scope).push(b)}for(let b of[...Z.keys()].sort((g,y)=>y.length-g.length)){let g=Z.get(b);g.length&&(g.length===1&&b?Z.get(O(b)).push(g[0]):ae(C,g,!0))}}}function Q(C,$,Z,O=[]){let b=[],g={...s,...C.settings},y=0,P=Z==="left"?"bass":s.clef??"treble",F=[],v=0;function d(G){G.key&&(k=G.key,x=new xe.KeyManager(k),z.key=D(o.transpose)?.target??k),G.clef&&(P=G.clef),G.sounds!==void 0&&($=G.sounds)}let p,w;function I(G){for(;v<F.length&&!new xe.Fraction().parse(F[v].at).greaterThan(new xe.Fraction().parse(G.at));)d(F[v++]);let de=se(G,$);O.length&&(de.writtenClef=P,de.activeKey=z.key);for(let he of G.marks){if(he.kind!=="pedal")continue;let pe=r(he.range);if(!z.piano||G.kind==="skip")throw new ee("measure","Place pedal marks on piano notes or rests",pe);if(he.action==="down"){if(w)throw new ee("measure","Lift the pedal before pressing again",pe);w=de}else{if(!w)throw new ee("measure","Pedal up needs an earlier pedal down in this voice",pe);N.spans.push({kind:"pedal",...he.onset&&{onset:!0},from:w.id,to:de.id,id:"pedal-"+w.id,range:pe}),w=void 0}}let fe=new Set;return G.heads.forEach((he,pe)=>{for(let Pe of he.marks){if(Pe.kind!=="tieStart"&&Pe.kind!=="tieEnd")continue;let Be=re.get(Pe.name)??[];Be.length||re.set(Pe.name,Be),Be.push({event:de,index:pe,bar:G.bar,hand:Z,range:r(Pe.range),scope:le(G),side:Pe.side,start:Pe.kind==="tieStart"})}let Le=de.heads[pe].glissFrom;if(Le!==void 0){if(!p?.heads[Le])throw new ee("measure","Missing previous glissando head",de.heads[pe].range);N.spans.push({kind:"glissando",id:"gliss-"+de.id+"-"+pe,from:p.id,fromHead:Le,to:de.id,toHead:pe,range:de.heads[pe].range})}let Ae=he.marks.find(Pe=>Pe.kind==="tie");if(!Ae)return;let ve=r(Ae.range),Ge=de.heads[pe],gt=p?.heads.findIndex((Pe,Be)=>!fe.has(Be)&&Ge.sounding&&Pe.written===Ge.written&&Pe.sounding===Ge.sounding&&Pe.position?.str===Ge.position?.str)??-1;if(gt<0)throw new ee("measure","Tie needs a matching preceding pitch and string",ve);fe.add(gt),N.ties.push({id:"tie-"+de.id+"-"+pe,from:p.id,fromHead:gt,to:de.id,toHead:pe,range:ve})}),p=de,de}k=s.key??"C",x=new xe.KeyManager(k),z.key=D(o.transpose)?.target??k,z.tuning=M,h=new xe.Tuning(M),z.color=s.ink==="default"?void 0:s.ink;let U=s.displayMeter;for(let G of C.measures){s.keys?.[G.number]&&(k=s.keys[G.number],x=new xe.KeyManager(k),z.key=D(o.transpose)?.target??k);let de=r(G.barlineRange),fe=s.changes?.[G.number];if(fe?.tuning){if((xe.Tuning.names[fe.tuning]??fe.tuning).split(",").length!==z.strings)throw new ee("measure","A tuning change must keep the same string count",de);z.tuning=fe.tuning,h=new xe.Tuning(fe.tuning)}fe?.ink&&(z.color=fe.ink==="default"?void 0:_(fe.ink,de)),fe?.displayMeter!==void 0&&(U=fe.displayMeter);let he=G.span??(G.number===1&&o.pickup?o.pickup:A),pe=G.meter??j;for(F=[],v=0;y<O.length&&O[y].bar===G.number;){let Ze=O[y++];Ze.at==="0/1"?d(Ze):F.push(Ze)}let Le=o.transpose?F.map(Ze=>Ze.key?{...Ze,key:new vt(o.transpose,Ze.key).target}:Ze):F,Ae={key:z.key,clef:P,changes:Le},ve={name:C.name,declaration:r(C.range),hand:Z,span:he,events:C.events.slice(G.start,G.end).map(I),tuplets:[],stem:g.stem,beams:g.beam??!0,flatBeams:g.flatBeams,beamRests:g.beamRests??!0,beatGroups:g.beatGroups,stemlets:g.stemlets??!1,middleRests:g.middleRests??!1,tabStems:g.tabStems??!1,rehearsal:G.rehearsal,opening:G.opening?{type:G.opening,range:de}:void 0,closing:G.closing?{type:G.closing,range:de}:void 0,tabDirection:g.tabDirection==="down"?-1:1},Ge=R[G.number-2]?.state,gt=Ge?.meter!==pe||Ge?.meterSign!==G.meterSign,Pe=R[G.number-1]??={number:G.number,range:de,state:{...z,key:Ae.key,fragment:!!G.fragment,meter:pe,meterSign:G.meterSign,timeRange:G.meterRange?r(G.meterRange):z.timeRange,showTime:U!==!1&&(G.number===1?U||z.showTime:gt||fe?.displayMeter===!0)},span:he,newRow:!!G.newRow,voices:[]};for(O.length&&((Pe.staffState??={})[Z??"notation"]=Ae);v<F.length;)d(F[v++]);Pe.newRow||=!!G.newRow;let Be=Pe.voices[0];if(Be){if(ve.rehearsal&&Be.rehearsal&&ve.rehearsal!==Be.rehearsal||ve.opening&&Be.opening&&ve.opening.type!==Be.opening.type||ve.closing&&Be.closing&&ve.closing.type!==Be.closing.type)throw new ee("measure","Voices disagree about a shared bar boundary",de);Be.rehearsal??=ve.rehearsal,Be.opening??=ve.opening,Be.closing??=ve.closing}Pe.voices.push(ve),b.push(ve)}if(w)throw new ee("measure","Missing pedal up",w.range);Js(b,N.spans),ce(C),oe(C,b)}function J(C){let $=new Map,Z=[];for(let O=C.length-1;O>=0;O--){let b=C[O],g=b.first+":"+b.bodyEnd,y=$.get(g)??0;$.set(g,y+1);let P=W.get(g)??[],F=P[y];if(!F)P.push(b),W.set(g,P),Z.push(b);else{if(F.count!==b.count)throw new ee("measure","Voices disagree about the repeat count",r(b.range));if(F.endings.length!==b.endings.length||F.endings.some((v,d)=>v.last!==b.endings[d].last))throw new ee("measure","Voices disagree about repeat endings",r(b.range))}}Z.length&&(N.repeats??=[]).push(...Z.reverse())}function ce(C){if(C.repeats?.length){J(C.repeats);for(let $ of C.repeats){let Z=r($.range),O=$.endings[$.endings.length-1]?.last??$.bodyEnd;if(R.slice($.first-1,O).some(g=>!g.voices[0].events.length))throw new ee("measure","An ending needs sounding or resting measures",Z);let b=R[$.first-1].voices[0];if(b.opening={type:"repeat-begin",range:Z},$.count){let g=R[$.bodyEnd-1].voices[0];g.closing={type:"repeat-end",range:Z};let y=g.events[g.events.length-1],P="\xD7"+$.count;y.labels?.some(F=>F.text===P)||(y.labels??=[]).push({text:P,position:"above",range:Z})}$.endings.forEach((g,y)=>{let P=R[g.last-1].voices[0];y<$.endings.length-1&&(P.closing={type:"repeat-end",range:Z});let F=R[g.first-1].voices[0].events[0].id,v="ending-"+F,d=N.spans.find(p=>p.id===v);if(d){if(d.kind!=="volta"||d.lastBar!==g.last||d.label!==y+1+".")throw new ee("measure","Voices disagree about repeat endings",Z)}else N.spans.push({kind:"volta",id:v,label:y+1+".",firstBar:g.first,lastBar:g.last,from:F,to:P.events[P.events.length-1].id,range:Z})})}}}function oe(C,$){let Z=new Map(C.events.map((O,b)=>[O.id,b]));for(let O of C.spans){let b=r(O.range);if(O.kind==="continuousBeam"||O.kind==="crescendo"||O.kind==="diminuendo"||O.kind==="tremolo"){if(!z.notation)throw new ee("measure","This expression span needs a notation staff",b);if(N.spans.push({kind:O.kind,from:O.first,to:O.last,niente:O.niente,...O.side&&{side:O.side},strokes:O.strokes,range:b,id:O.kind+"-"+O.first+(O.name?"-"+O.name:"")}),O.kind==="tremolo"||O.kind==="continuousBeam"){let g,y=Z.get(O.last);for(let P=Z.get(O.first);P<=y;P++){let F=C.events[P].bar-1,v=$[F],d=v.events[P-C.measures[F].start];if(O.kind==="tremolo")d.tremolo=O.strokes;else{if(d.displayHand&&d.displayHand!==v.hand)throw new ee("measure","A continuous beam must stay on its owning staff",b);let p=d.heads[0]?.drum,w=d.stem??v.stem??(p&&E.instruments.find(I=>I.id===p)?.stem);if(w&&g&&w!==g)throw new ee("measure","Stems in a continuous beam must agree in direction",b);w&&(g=w),d.continuousBeam=!0}}}}else if(O.kind==="slur"||O.kind==="palmMute"){if(O.kind==="palmMute"&&O.strings.some(g=>g>z.strings))throw new ee("measure","Mute outside the instrument tuning",b);N.spans.push({kind:O.kind,from:O.first,to:O.last,side:O.side,strings:O.strings,range:b,id:O.kind+"-"+O.first+(O.name?"-"+O.name:"")})}else if(O.kind==="beam"||O.kind==="feather"){let g=Z.get(O.first),y=Z.get(O.last),P=C.measures[C.events[g].bar-1];($[P.number-1].beamGroups??=[]).push({start:g-P.start,end:y-P.start,feather:O.kind==="feather"?O.feather:void 0,range:b})}else if("to"in O)N.spans.push({kind:O.kind,id:O.kind+"-"+O.to.event+"-"+O.to.head,range:b,from:O.from.event,to:O.to.event,fromHead:O.from.head,toHead:O.to.head});else if(O.kind==="tuplet"){let g=Z.get(O.first),y=Z.get(O.last),[P,F]=O.ratio.split(":").map(Number);for(let v=g;v<=y;){let d=C.measures[C.events[v].bar-1],p=Math.min(d.end,y+1);$[d.number-1].tuplets.push({start:v-d.start,count:p-v,numNotes:P,notesOccupied:F,range:b}),v=p}}}}for(let C of s.staves)for(let $ of C.voices)Q($,C.sounds??s.sounds,C.name==="upper"?"right":C.name==="lower"?"left":void 0,C.staffChanges);te();let ue=new Map(R.flatMap(C=>C.voices.flatMap($=>$.events.map(Z=>[Z.id,Z]))));for(let C of N.ties){let $=ue.get(C.from).heads[C.fromHead],Z=ue.get(C.to).heads[C.toHead];if(Z.release){if(!$.bend||$.bend.release||!Z.position||$.position.str!==Z.position.str)throw new ee("measure","A tied release needs a bent source on the same string",Z.range);$.tiedBendStart=!0,C.bend={semitones:$.bend.semitones,rise:$.bend.rise,hold:Z.release.hold,release:Z.release.release},C.string=Z.position.str}}for(let C of ue.values())for(let[$,Z]of C.heads.entries())if(Z.release&&!N.ties.some(O=>O.to===C.id&&O.toHead===$&&O.bend))throw new ee("measure","A release needs a tied continuation",Z.range);Fn(R,N.spans);for(let[C,$]of(s.text??[]).entries()){let Z={line:-C*2,...$.style};Z.ink&&_(Z.ink,r($.voice.range));for(let O of $.voice.measures){let b=R[O.number-1],g=$.voice.events.slice(O.start,O.end).map(y=>{let P=y.marks.find(F=>F.kind==="text");return{id:y.id,range:r(y.range),...$s(y.writtenDuration),text:P?.text??"",glyph:P?.glyph,style:{...Z,...P?.style}}});for(let y of $.voice.boundaries??[]){if(y.bar!==O.number)continue;let P=y.edge==="start"?g[0]:g[g.length-1];if(!P)throw new ee("measure","A text boundary needs a timed anchor",r(y.range));(P.boundaries??=[]).push({...y,range:r(y.range)})}for(let y of g)y.style.ink&&_(y.style.ink,y.range);(b.text??=[]).push(g)}}return n.set(e,N),N}var go="http://www.w3.org/2000/svg";var bo=0;function Ke(o,e={}){let n=document.createElementNS(go,o);for(let[t,s]of Object.entries(e))n.setAttribute(t,String(s));return n}function On(o,e,n){let t=n-e;if(t<=0)return 0;let s=Math.min(.075,t/2),r=Math.min(.14,t/2);return Math.max(0,Math.min(1,(o-e+s)/s,(n-o)/r))}var jt=class{constructor(){this.layer=Ke("g",{class:"vextab-playback-ink",color:"var(--vextab-playback-tint, #fff600)","pointer-events":"none","aria-hidden":"true"});this.bar=Ke("line",{stroke:"#a8a8a8","stroke-opacity":.55,"stroke-width":3.5,"stroke-linecap":"round"});this.gradient="vextab-glow-"+ ++bo;this.dots=[];let e=Ke("radialGradient",{id:this.gradient});for(let[t,s]of[[0,.5],[.32,.72],[.52,.6],[.76,.22],[1,0]])e.append(Ke("stop",{offset:t,"stop-color":"currentColor","stop-opacity":s}));let n=Ke("defs");n.append(e),this.layer.append(n,this.bar)}drawDot(e,n,t,s){let r=this.dots[e];r||(r={node:Ke("ellipse",{rx:17,ry:13,fill:"url(#"+this.gradient+")",stroke:"none"})},this.dots.push(r)),r.point!==n&&(r.node.parentNode!==s&&s.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}hideUnused(e){for(let n=e;n<this.dots.length;n++){let t=this.dots[n];t.opacity!==0&&t.node.setAttribute("opacity","0"),t.opacity=0}}};var rn=class{constructor(e,n,t,s){this.surface=e;this.music=n;this.follow=s;this.ink=new jt;this.anchors=[];this.pulses=[];this.active=[];this.anchor=0;this.pulse=0;this.frame=0;this.pages=new Map;this.printedRows=new Map;for(let r of n.events){let a=t.get(r.source);if(!a)continue;let{x:i,row:l,heads:c}=a,u=this.anchors[this.anchors.length-1];(!u||Math.abs(u.time-r.time)>1e-6)&&this.anchors.push({time:r.time,x:i,row:l,slope:0,speed:0}),c.length&&this.pulses.push({time:r.time,end:r.time+r.duration,heads:c,row:l})}this.anchors.forEach((r,a)=>{let i=this.anchors[a+1],l=(i?.row===r.row?i.x:r.row.right)-r.x,c=(i?.time??n.duration)-r.time;r.slope=c>0?l/c:0;let u=this.anchors[a-1];r.speed=r.slope,u?.row===r.row&&(r.speed=u.slope*r.slope>0?2/(1/u.slope+1/r.slope):0)})}rowLayer(e){let n=e.printedPage;if(!n)return this.ink.layer.parentNode||this.surface?.append(this.ink.layer),this.ink.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=Ke("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.ink.layer.parentNode||s.append(this.ink.layer)}let r=Ke("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.ink.bar),this.ink.bar.setAttribute("y1",String(e.top)),this.ink.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.ink.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.ink.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=On(e,s.time,s.end);if(r>0)for(let a of s.heads)this.ink.drawDot(t++,a,r,this.rowLayer(s.row))}this.active.length=n,this.ink.hideUnused(t)}stop(){cancelAnimationFrame(this.frame),this.ink.layer.remove();for(let[e,n]of this.pages)n.parentElement?.replaceWith(e)}};var Wt=new WeakMap;function Ln(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 yo(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 Qs(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=Ln(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],m=(it.get(l)??[]).map(h=>/^[a-g]/i.test(h.key));e.set(l,yo(s,f,m))}))}return e}function ei(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 m of i.measures)for(let[h,S]of r.get(m)??[])f??={top:c+S.row.top,bottom:c+S.row.bottom,right:u+S.row.right,printedPage:a.svg,scale:t},s.set(h,{row:f,x:u+S.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,m={x:(f.x+f.w/2)/t,y:(f.y+f.h/2)/t};c.heads.length||(c.x=m.x),c.heads.push(m)}}return s}function at(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 xo(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 vo(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((m,h)=>m+h.duration,0);for(let m=l;m<=c;m++){let h=o[m],S=r+h.duration,k=r,x=0,T=h.quarter-(h.beatOffset??0);for(;r<S-1e-9;){let B=h.beats?.[x++],H=B?k+B.end:Math.min(r+T,S),_=H-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*at(n,s.length);let j=!t&&h.fermatas?.some(E=>E>r-k+1e-9&&E<=H-k+1e-9),q=_*(1-e.rubato*V+e.drift*i+(j?.35:0)),z=h.swingable!==!1&&(B?B.eighth!==void 0:Math.abs(_/h.quarter-1)<1e-6),R=B?.eighth===void 0?.5:(B.eighth-(r-k))/_,N=60/(B?_:h.quarter),W=z?e.swing*Math.max(0,Math.min(.22,.25-(N-60)/750)):0;s.push({start:r,end:H,played:a,length:q,velocity:V*e.swell,swing:W,fullBeat:z,middle:R}),r=H,a+=q,T=h.quarter}r=S}l=c+1}return s}function kr(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 wo(o,e){let n=new Set;for(let t of o)for(let s of[t.time,t.time+t.duration]){let r=kr(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 ko(o,e,n,t){let s=n[n.length-1],r=t.swing||t.pocket?wo(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=kr(n,l),u=n[c],f=Math.max(0,(l-u.start)/(u.end-u.start)),m=u.played+a(c),h=u.played+u.length*(u.middle+(r.has(c)?0:2*(1-u.middle)*u.swing)),S=u.played+u.length+a(c+1);return f<u.middle?m+f/u.middle*(h-m):h+(f-u.middle)/(1-u.middle)*(S-h)}return i}function So(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=at(t,0),i=o.map((f,m)=>{let h=(f.pitch-s)/Math.max(1,r-s),S=t^Math.imul(f.pitch+1,617)^m;return{note:f,finger:S,landing:a*h+at(S,1)}}).sort((f,m)=>f.landing-m.landing),l=Math.min(e,...o.map(f=>f.duration));if(l<=0)return;let c=Math.min(l*.12,n*(.78+.22*at(t,2))),u=Math.min(1,n/.013);i.forEach(({note:f,finger:m},h)=>{let S=h/(i.length-1),k=h>0&&h<i.length-1?.32*at(m,3)/(i.length-1):0,x=c*(S+k),T=f.pitch===r?.042:f.pitch===s?-.012:-.085,B=1+u*(T+.052*at(m,4));f.fixedVelocity||(f.velocity=Math.max(1,Math.min(127,Math.round(f.velocity*B)))),x&&(f.onsetOffset=x);let H=0;!f.holdRelease&&!f.bend&&f.duration<=e+1e-9&&(H=Math.min(n*1.8,f.duration*.09)*Math.max(0,.56+.4*at(m,5)-(f.pitch===r?.23:0))),f.duration-=x+H,x&&f.bend&&(f.bend=f.bend.map(_=>({..._,time:Math.max(0,_.time-x)})))})}function Eo(o,e,n,t,s){let r=ko(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[kr(n,i.time)],m=t.touch*at(s^e+1,Math.round(i.time*1e5)),h=(i.time-f.start)/(f.end-f.start),S=f.fullBeat?t.beatAccent*Math.cos(2*Math.PI*h):0,k=1+(f.velocity+m+S)/100,x=i.notes.map(T=>{let B=i.time+(T.onsetOffset??0),H=r(B),_=M=>r(B+M)-H;return{...T,duration:_(T.duration),...T.onsetOffset&&{onsetOffset:H-c},velocity:T.fixedVelocity?T.velocity:Math.max(1,Math.min(127,Math.round(T.velocity*k))),...T.bend&&{bend:T.bend.map(M=>({...M,time:_(M.time)}))}}});return So(x,u,t.chordSpread??0,s^Math.imul(e+1,65537)^Math.imul(l+1,16777619)),{...i,time:c,duration:u,notes:x}}),duration:r(o.duration)}}function Mo(o){if(typeof o=="string"){if(!wt(o))throw new RangeError("Unknown performer: "+o);return Qt[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 Sr(o="human",e,n){let t=Mo(o),s=n==="off"?{...t,swing:0,pocket:0}:n==="eighths"?{...t,swing:t.swing||1}:t,r=o==="robot"||o===Qt.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*at(a,Math.round(i*1e5)))},perform(i,l=[],c=120){if(r&&!s.swing||!i.length)return i;let u=Math.max(...i.map(m=>m.duration)),f=vo(xo(l,u,c),s,a,r);return f.length?i.map((m,h)=>Eo(m,h,f,s,a)):i}}}function Po(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 ti(o,e,n,t){return e-o>=t-n||o<n?o-n:Math.max(0,e-t)}var Hn=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=Po(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:m,x:h,y:S}of this.ports){let k=m===document.scrollingElement,x=k?void 0:m.getBoundingClientRect(),T=x?x.width/(m.offsetWidth||1):1,B=x?x.height/(m.offsetHeight||1):1;if(!T||!B)continue;let H=window.visualViewport,_=x?x.left+m.clientLeft*T:H?.offsetLeft??0,M=x?x.top+m.clientTop*B:H?.offsetTop??0,V=k?H?.width??m.clientWidth:m.clientWidth*T,j=k?H?.height??m.clientHeight:m.clientHeight*B,q=h?ti(i,l,_+12,_+V-12)/T:0,z=Math.min(68,j*.12),R=S?ti(c,u,M+z,M+j-z)/B:0,N=Math.max(0,Math.min(m.scrollWidth-m.clientWidth,m.scrollLeft+q)),W=Math.max(0,Math.min(m.scrollHeight-m.clientHeight,m.scrollTop+R)),E=N-m.scrollLeft,A=W-m.scrollTop;if(Math.abs(E)>=1||Math.abs(A)>=1){f=!0;let L=D=>Math.sign(D)*Math.min(Math.abs(D),Math.max(1,Math.abs(D)*r));m.scrollBy({left:L(E),top:L(A),behavior:"instant"})}i-=E*T,l-=E*T,c-=A*B,u-=A*B}this.nextCheck=f?t:t+120}};function To(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 ni(o,e,n,t,{size:s,inset:r}){let a=To(o),i=t.querySelector(".vextab-control-panel"),l=window.visualViewport,c=0,u,f=!1;function m(){c=0;let T=e.getBoundingClientRect(),B=n.getBoundingClientRect();if(f&&(!u||T.left!==u.left||T.top!==u.top||T.right!==u.right||T.bottom!==u.bottom)&&h(),u=T,!B.width||!B.height)return;let H=n.offsetWidth/B.width,_=n.offsetHeight/B.height,M=l?.offsetLeft??0,V=l?.offsetTop??0,j=Math.max(T.left,M),q=Math.max(T.top,V),z=l?.width??document.documentElement.clientWidth,R=l?.height??document.documentElement.clientHeight,N=Math.min(T.right,M+z),W=Math.min(T.bottom,V+R),E=T.height>=R*.8||T.width>z+1;for(let{element:Y,x:ne,y:se}of a){let re=Y.getBoundingClientRect(),le=re.width/(Y.offsetWidth||1),ae=re.height/(Y.offsetHeight||1),te=re.left+Y.clientLeft*le,Q=re.top+Y.clientTop*ae;(ne&&T.width>Y.clientWidth*le+1||se&&T.height>Y.clientHeight*ae+1)&&(E=!0),ne&&(j=Math.max(j,te),N=Math.min(N,te+Y.clientWidth*le)),se&&(q=Math.max(q,Q),W=Math.min(W,Q+Y.clientHeight*ae))}if(N<=j||W<=q){t.style.inset="0";return}let A=s==="auto"?E?"large":"mini":s;t.dataset.size!==A&&(t.dataset.size=A);let L=Math.min(r,Math.max(0,((N-j)*H-i.offsetWidth)/2)),D=Math.min(r,Math.max(0,((W-q)*_-i.offsetHeight)/2));t.style.padding=D+"px "+L+"px",t.style.setProperty("--control-y-inset",D+"px"),t.style.inset=[(q-B.top)*_,(B.right-N)*H,(B.bottom-W)*_,(j-B.left)*H].map(Y=>Y+"px").join(" ")}function h(){c||(c=requestAnimationFrame(m))}let S,k=new IntersectionObserver(T=>{if(f=T[T.length-1].isIntersecting,f){if(u=void 0,!S){S=new AbortController;let B={signal:S.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 S?.abort(),S=void 0,t.style.inset="0"},{threshold:[0,.25,.5,.75,1]}),x=new ResizeObserver(h);for(let T of[o,...a.map(B=>B.element)])x.observe(T);return k.observe(e),m(),()=>{S?.abort(),k.disconnect(),x.disconnect(),cancelAnimationFrame(c)}}var ri="http://www.w3.org/2000/svg",si=3e3;function sn(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 Dn=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=sn("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=sn("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 Hn: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(ri,"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(ri,"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=ni(s,e,this.root,this.controls,t)}}reveal(){if(this.hideAt=performance.now()+si,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,si)}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=sn("Adjust tempo","vextab-metronome",()=>r(t.inert)),this.decrease=sn("Decrease tempo","vextab-step",()=>e(Math.max(1,this.tempo-5))),this.decrease.textContent="\u2212";let a=sn("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 ii(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 No(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 zn=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 m=()=>f.currentTime??performance.now()/1e3,h=No(t.events),S=m(),k=-r,x=()=>k+(m()-S)*this.rate,T=0,B=()=>{if(!a.signal.aborted)try{let H=x();for(;T<h.length&&h[T].time<=H;){let M=h[T++];M.mark?.();for(let V of M.notes)M.time+V.duration>H&&f.playNote(_o(V,this.rate))}if(T===h.length&&H>=t.duration){this.stop();return}let _=h[T]?.time??t.duration;this.timer=window.setTimeout(B,Math.max(1,(_-x())/this.rate*1e3))}catch(H){c(H)}};this.retime=H=>{k=x(),S=m(),this.rate=H,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(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 _o(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,m=s.createOscillator(),h=s.createGain();m.type=n>=72&&n<=79?"sine":"triangle",m.frequency.value=440*2**((c.pitch-69)/12),m.detune.setValueAtTime(0,u);for(let S of c.bend??[])m.detune.linearRampToValueAtTime(S.semitones*100,u+S.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),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:l,stop:i,get currentTime(){return s.currentTime}}}return{open:e}}function oi(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 Ao={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 ai(o){let e=/^\d+$/.test(String(o))?Number(o):Ao[o];if(!Number.isInteger(e)||e<0||e>127)throw new RangeError("Invalid instrument: "+o);return e}var Xe=class o{constructor(e,n={}){this.transport=new zn;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,Ue(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){ai(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&&Wt.get(e);this.sharedSurface=!!this.ensemble&&!!s?.ensemble&&this.ensemble.every((S,k)=>s.ensemble[k]===S),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=Cn({...c,...u});(i===!0||l)&&f.visibility==="off"&&(f.visibility="hover");let m=(S,k,x)=>new Dn(S,this.options.overlay_class,k,()=>{this.play().catch(()=>{})},()=>this.stop(),this.options.tempo,T=>this.setTempo(T),f,x);this.overlay=m(a,this.options.show_controls&&i!==!1&&f.visibility!=="off",l);let h=new Set(this.ensemble);for(let S of t){let k=Wt.get(S);k&&h.has(k.score)&&this.companions.push({...k,overlay:m(S,!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=Ms(a,this.options.order==="performed"),l=Sr(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((x,T)=>As(x,n,this.mark,i.get(x),l,l.needsBeatGrid?c[T]:void 0)):[Rs(this.artist,n)],f=l.perform(u,_s(c),n),m=f[0],h=new Map(a.map((x,T)=>[x,f[T]])),S=f.length===1?m:{events:f.flatMap(x=>x.events).sort((x,T)=>x.time-T.time),duration:Math.max(...f.map(x=>x.duration))},k=s??(!this.artist||typeof MIDI>"u"?pt():oi(String(t),r,o.INSTRUMENTS_LOADED,l.literal));if(this.overlay&&!S.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?Qs(this.artist):void 0);x?.size&&this.animations.push(new rn(this.overlay?.surface,this.sharedSurface?S:m,x,(_,M)=>this.overlay?.followSystem(_,M)));for(let _ of this.companions){let M=h.get(_.score);M&&this.animations.push(new rn(_.overlay.surface,M,_.read()))}let T=ai(t),B=[...new Set(S.events.flatMap(_=>_.notes.map(M=>M.program??T)))],H=B.some(_=>_!==T)?ii(k,B):k;await this.transport.play(H,T,S,_=>{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)}};X.Flow.Player||(X.Flow.Player=Xe);function Ro(o,e){let n=0,t=o.length;for(;n<t;){let s=Math.floor((n+t)/2);o[s].end<=e?n=s+1:t=s}return n}function Co(o,e){let n=o[0].measures.map(()=>[]);for(let t of o)for(let s of t.measures)for(let r of s.voices){let a=[];for(let i of r.events){let l=e.get(i.id)?.heads;if(!l?.length)continue;let c=Mt(i.onset);a.push({start:c,end:c+Mt(i.duration),heads:l})}a.length&&n[s.number-1].push(a)}return n}function Io(o,e){let n=parseFloat(o.style.width),t=parseFloat(o.style.height),s=Ke("svg",{viewBox:`0 0 ${n} ${t}`,preserveAspectRatio:"none","aria-hidden":"true"});s.style.cssText="position:absolute;pointer-events:none;background:transparent;",e.append(s);let r="";return{paper:s,align(){let a=o.getBoundingClientRect(),i=e.getBoundingClientRect();if(!i.width||!i.height)return;let l=[100*(a.left-i.left)/i.width,100*(a.top-i.top)/i.height,100*a.width/i.width,100*a.height/i.height],c=l.join(",");c!==r&&(r=c,[s.style.left,s.style.top,s.style.width,s.style.height]=l.map(u=>u+"%"))}}}function ci(o,e,n,t,s){let r=new jt,a=Co(t,s),i=e instanceof HTMLCanvasElement?Io(e,o):void 0,l=i?.paper??e,c=t[0].playback?.tempo??120,u=!1;return{setPosition(f,m=c){if(u)return;if(!Number.isFinite(m)||m<=0)throw new RangeError("Tempo must be positive");let h=n.positionAt(f);if(!h){r.layer.remove();return}i?.align(),r.layer.parentNode||l.append(r.layer),r.bar.setAttribute("transform","translate("+h.x+" 0)"),r.bar.setAttribute("y1",String(h.systemBounds.top)),r.bar.setAttribute("y2",String(h.systemBounds.bottom));let S=240/m,k=.075/S,x=0;for(let T of a[h.measure-1])for(let B=Ro(T,h.offset);B<T.length;B++){let H=T[B];if(H.start>h.offset+k)break;let _=On((h.offset-H.start)*S,0,(H.end-H.start)*S);if(_>0)for(let M of H.heads)r.drawDot(x++,M,_,r.layer)}r.hideUnused(x)},clear(){r.layer.remove()},dispose(){u=!0,r.layer.remove(),i?.paper.remove()}}}function li(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 ht=Se(Me());function di(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 ui(o){return o.boundaries?.some(e=>e.edge==="start"&&e.style.line===o.style.line)}var jn=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?ht.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:bt(),style:"normal",weight:"normal"}},h=t==="beat"&&ui(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 ht.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 ht.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"?ht.TextNote.Justification.RIGHT:i==="left"?ht.TextNote.Justification.LEFT:ht.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 ht.TextNote){if(a=e,a.getDirectionAnchor()==="beat"&&ui(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(we(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 m=f,h=m.getBeam?.();if(!(!h||h.getNotes()[0]!==m||m.getStave()?.getY()!==i.getY()))for(let S of h.getStripBounds())S.x<c.x+c.w&&S.x+S.w>c.x&&(u=Math.max(u,S.y+S.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 St=Se(Me());function fi(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,m,h=0){if(!c)return;let S=c.split(/(\^\{[^{}]+\}|♩|𝅗𝅥)/u).filter(Boolean).map(_=>{let M=_.startsWith("^{")&&_.endsWith("}"),V=M?_.slice(2,-1):_,j=_==="\u2669"?St.default.Glyphs.metNoteQuarterUp:_==="\u{1D15E}"?St.default.Glyphs.metNoteHalfUp:void 0,q=j?bt():ze(),z=j?"normal":Pt(),R=j??V.trim(),N=m*a*(M?.62:1);o.setFont(q,N,z,"normal");let W=j?0:o.measureText("a a").width-o.measureText("aa").width,E=(V.length-V.trimStart().length)*W,A=(V.length-R.length)*W+o.measureText(R).width;return{label:R,family:q,weight:z,fontSize:N,raised:M,leading:E,advance:A}}),k=S.reduce((_,M)=>_+M.advance,0),x=r&&k>t?t/k:1,T=m*a*x,B=n+u*t-k*x*h,H=r?s+i+T*1.3:s-f*a;for(let _ of S)o.setFont(_.family,_.fontSize*x,_.weight,"normal"),o.fillText(_.label,B+_.leading*x,H-(_.raised?T*.5:0)),B+=_.advance*x;r&&(i+=T*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 mi(o,e){let n=new St.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 St.Ornament(s.ornament.replace("_inverted","Inverted")).getText(),m=f?'[stem="down",articulations="'+f+'.above"]':'[stem="down"]';return i+(u===l?"":l)+a+"/"+o.duration+m}).join(", ")}var ie=Se(Me());var pi=Se(Me());function hi(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,m]of c.events.entries()){let h=n(m.id),S=m.chord?[m.chord.text]:[];if(t)for(let k of m.heads)(k.connection||k.hammer)&&e==="tab"&&S.push(k.connection==="pull"?"P":k.connection==="slide"?"Slide":"H"),k.openSlide&&e==="notation"&&S.push(Ht(k.openSlide,k.position.str)),k.prebend&&S.push(Ot(k.prebend,k.position.str));if(s)for(let k of m.gestures??[])"direction"in k?!o.state.piano&&!r&&S.push(k.kind+" "+k.direction):S.push(k.kind==="tap"?"T":k.wide?"Wide vibrato":"Vibrato");m.harmony&&S.length===1?i.push({note:h,harmony:m.harmony}):S.length&&i.push({note:h,text:S.join(" \xB7 ")});for(let k of nn(m)){let{text:x,hyphen:T,extend:B,range:H,verse:_,elideWith:M,crossConnector:V}=k;if(e==="tab")throw new ee("fixed-layout","This lyric needs a notation staff",H);let j=_??"";u.has(j)||u.set(j,[]),u.get(j).push({note:h,text:x,elideWith:M,hyphenAfter:T,extendTo:B?n(V?a.get(H.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 Bo(o){return o.voices.flatMap(e=>e.events.filter(n=>n.frame)).map(e=>({event:e,beat:new pi.Fraction().parse(e.onset).value()})).sort((e,n)=>e.beat-n.beat)}function gi(o,e){return o.measures.flatMap(n=>Bo(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 Fo=0;function Vo(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 ee("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 ee("fixed-layout","A flow score must keep its staff configuration",r.state.declaration);return s}function qt(o,e){return o.state.piano?o.voices.filter(n=>n.hand===e):o.voices}var Er=class{constructor(e){this.revision=e;this.ids=Object.create(null);this.ranges=new Map;this.prefix="vt"+ ++Fo+"-";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 Oo(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:Ht(s.openSlide,s.position.str)}),s.prebend&&t.push({kind:"technique",id:"pre-bend",index:r,label:Ot(s.prebend,s.position.str)}),!s.position&&s.sounding===null&&t.push({kind:"unpitched",id:"slash",label:"Rhythm slash",index:r})}),t}function Lo(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 Ho(o,e,n,t){let s=o.stem,r=s?s==="up"?1:-1:n==="tab"?o.tabDirection:void 0,a=new ie.FrettedInstrument(e.state.tuning,e.state.capo),i=n==="left"?"bass":e.state.clef,l=Lo(o),c,u=o.events.map(h=>{let S=t.project(n,h.id,h.range);h.heads.forEach((q,z)=>t.project(n,h.id+"-head-"+z,q.range));let k=e.state.piano?h.displayHand:void 0,x=l.get(h),T=h.stem==="up"?1:h.stem==="down"?-1:void 0,B={duration:h.base,dots:h.dots,stemDirection:T??x??r,headSource:{event:h.id}};if(h.silent)return{id:S,skip:B};if(!h.heads.length){let q=n==="tab"?5-e.state.strings:0,z=h.restLine===void 0?void 0:h.restLine+q;return{id:S,...k&&{stave:k},note:{...B,keys:["r/4"],clef:"treble",type:"r",restLine:z}}}if(h.heads[0].drum){let q=(e.state.kit??dt).note(h.heads.map(z=>z.drum),h.base,h.stem??s);return{id:S,note:{...q,dots:h.dots,headSource:B.headSource}}}let H=Oo(h,a),_=h.heads.map(q=>q.position?.fret==="X"?q.written+"/X":q.written);if(n==="tab")return{id:S,tab:{...B,keys:_,notation:H,positions:h.heads.map(q=>({...q.position}))},drawStem:o.tabStems&&!["w","1"].includes(h.base)};let M=h.writtenClef??i;if(k&&k!==o.hand){let q=e.staffState?.[k];M=q?.clef??(k==="left"?"bass":"treble");for(let z of q?.changes??[]){if(new ie.Fraction().parse(z.at).greaterThan(new ie.Fraction().parse(h.onset)))break;M=z.clef??M}}let V=h.heads.map((q,z)=>{let R=$n(q.marks,h.heads);return{key:_[z],...R&&{fingering:{finger:R.finger,position:R.position}},...q.accidental&&{accidental:q.cautionary?"cautionary":"force"}}}),j={...B,heads:V,notation:H,clef:M,type:h.slash?"s":"n",autoStem:B.stemDirection===void 0};return h.tremolo&&(c===void 0?(c=B.stemDirection??new ie.StaveNote({...j,autoStem:!0}).getStemDirection(),j.stemDirection=c):(j.stemDirection=c,c=void 0),j.autoStem=!1),{id:S,...k&&{stave:k},note:h.tremolo?ie.AlternatingTremolo.endpoint(j,h.tremolo):j,...h.grace&&{grace:{side:h.grace.side,slur:!0,beam:h.grace.pitches.length>1,notes:h.grace.pitches.map(q=>({keys:Array.isArray(q)?q:[q],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,S)=>{let k=f.get(o.events[S].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 ie.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 Do(o){let e=o.voices[0].closing?.type;if(e==="end")return ie.Barline.type.END;if(e==="double")return ie.Barline.type.DOUBLE}function bi(o,e,n,t=!1){let s=Vo(o,e);if(!s.includes("tab"))for(let M of o.measures)for(let V of M.voices){let j=V.events.find(q=>q.bend)?.bend;if(j)throw new ee("fixed-layout","A timed bend contour needs a tab staff",j.range)}let r=new Er(o.source),a=r.id,i=o.layout?.heading,l=i&&(i.align==="center"||Object.keys(i).length===1)&&!Object.values(i).some(M=>/\^\{/.test(M)),c=gi(o,(M,V,j)=>r.project(s[0],M,V,j)),u=[];if(l)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"?ie.default.Glyphs.metNoteQuarterUp:ie.default.Glyphs.metNoteHalfUp,font:{family:bt(),weight:"normal"}}:V),align:i.align??(M==="title"?"center":M==="composer"?"right":"left"),font:{family:ze(),weight:Pt(),size:M==="title"?32:16}});c.length&&u.push({kind:"diagrams",align:i?.align??"left",diagrams:c.map(M=>M.diagram),font:{family:ze(),size:12}}),o.playback?.swing==="eighths"&&u.push({kind:"text",font:{family:ze(),size:12,weight:Pt()},runs:["Swing ",{notes:["8","8"],beam:!0}," = ",{notes:["q","8"],tuplet:[3,2]}]});let f=new jn,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),S=[],k=new Set(o.measures.flatMap(M=>M.voices.flatMap(V=>V.events.filter(j=>!j.heads.length).map(j=>j.id)))),x=new Map,T=[],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."},...Xs(o,M,M===s[0]),options:M==="tab"?{numLines:o.measures[0].state.strings}:{},measures:o.measures.map(V=>{let j=qt(V,M);if(M!=="tab"&&o.ties.length&&j.filter(N=>N.events.some(W=>W.heads.length)).length>1){for(let N of j)if(N.stem)for(let W of N.events)x.set(W.id,N.stem==="up"?"above":"below")}let q=M===s[0]||V.state.piano,z=M==="tab"?void 0:V.staffState?.[M];return{clef:z?.clef??(M==="tab"?"tab":M==="left"?"bass":V.state.clef),key:z?.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:Do(V),...q&&hi({...V,voices:j},M==="tab"?"tab":"notation",N=>a(M,N),t||!s.includes("tab"),t,h,m),voices:[...j.map((N,W)=>N.events.length?Ho(N,V,M,r):{notes:[{id:a(M,"blank-"+V.number+"-"+W),skip:"w"}]}),...(V.state.piano&&s.length===2?di(V.text??[],M==="left",o.layout?.staffDistance??9):M===s[0]?V.text??[]:[]).flatMap(N=>f.voices(N,V.number,(W,E)=>r.project(M,W,E)))]}})})),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:S,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 j=a(V,M.from);r.ids[j]&&S.push({kind:"tie",id:r.project(V,M.id,M.range),from:j,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 z of s){let R=a(z,M.from),N=a(z,M.to);z!=="tab"&&r.ids[R]&&r.ids[N]&&S.push({kind:"pedal",pedalStyle:"text",id:r.project(z,M.id,M.range),from:R,to:N})}continue}if(M.kind==="lyric"||M.kind==="hyphen"||M.kind==="tremolo")continue;if(M.kind==="continuousBeam"||M.kind==="crescendo"||M.kind==="diminuendo"){for(let z of s){let R=a(z,M.from),N=a(z,M.to);!r.ids[R]||!r.ids[N]||z==="tab"||S.push({kind:M.kind==="continuousBeam"?"beam":M.kind,from:R,to:N,..."niente"in M&&{niente:M.niente},...M.side&&{side:M.side},id:r.project(z,M.id,M.range)})}continue}if("fromHead"in M){for(let z of s){if(z==="tab")continue;let R=a(z,M.from);r.ids[R]&&S.push({kind:M.kind==="glissando"?"glissando":"tie",id:r.project(z,M.id,M.range),from:R,to:a(z,M.to),fromHead:M.fromHead,toHead:M.toHead})}continue}if(M.kind==="slur"){for(let z of s){let R=a(z,M.from);z==="tab"&&(k.has(M.from)||k.has(M.to))||r.ids[R]&&S.push({kind:"slur",side:M.side??(z==="tab"?"below":void 0),id:r.project(z,M.id,M.range),from:R,to:a(z,M.to)})}continue}if(M.kind==="palmMute"&&!s.includes("tab"))throw new ee("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],q={id:r.project(V,M.id,M.range),from:a(V,M.from),to:a(V,M.to)};if(M.kind==="palmMute")S.push({...q,kind:M.kind,strings:M.strings});else if(V==="tab"&&k.has(M.from)!==k.has(M.to)){let z=o.measures[M.firstBar-1].voices.flatMap(E=>E.events),N=o.measures[M.lastBar-1].voices.flatMap(E=>E.events).find(E=>k.has(E.id)===k.has(M.from)),W=z.find(E=>k.has(E.id)===k.has(M.to));N||W?S.push({...q,kind:"volta",text:M.label,from:N?q.from:a(V,W.id),to:N?a(V,N.id):q.to}):T.push(M)}else S.push({...q,kind:M.kind,text:M.label})}let H=[];for(let M of o.measures)for(let V of s)if(V!=="tab")for(let j of qt(M,V))for(let q of j.events){let z=q.ossia;z&&H.push({id:a(V,q.id+"-ossia"),at:a(V,q.id),label:"Ossia.",notes:mi(z,M.state.key??"C"),beam:z.notes.length>1&&z.duration!=="q",scale:.63})}if(B.continuous.ossias=H,s.includes("left")&&s.includes("right")){let M=[];for(let V of o.measures){let j=new Map;for(let q of V.voices)for(let z of q.events)if(z.sharedStem){let R=z.sharedStem+":"+z.onset,N=j.get(R)??{},W=q.hand==="right"?"upper":"lower";if(N[W])throw new ee("measure","Duplicate shared stem endpoint",z.range);N[W]=a(q.hand,z.id),j.set(R,N)}for(let q of j.values()){if(!q.upper||!q.lower)throw new ee("measure","Shared stems need simultaneous notes on both staves",V.range);M.push({id:q.upper+"-shared",upper:q.upper,lower:q.lower})}}B.continuous.splitChords=M}let _={spec:B,nativeHeading:l,frames:c,staves:s,sources:r,eventId:a,mixedEndings:T,textLanes:f,printAnchors:t?new Map:void 0,endingRegions:[]};return B.engraving=Uo(o,_),_}function zo(o,e,n){for(let t of e.labels??[]){let s=new ie.Annotation(t.text).setVerticalJustification(t.position==="below"?ie.Annotation.VerticalJustify.BOTTOM:ie.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(we(t.ink)),o.addModifier(s,0)}for(let t of e.gestures??[])if(t.kind==="tap")n&&o.addModifier(new ie.Annotation("T"),0);else if(t.kind==="vibrato")n&&o.addModifier(new ie.Vibrato().setVibratoWidth(t.wide?28:18),0);else if(t.kind==="stroke")o.addModifier(new ie.Articulation(t.direction==="up"?"a|":"am").setPosition(ie.Modifier.Position.BELOW),0);else if("direction"in t){let s=(t.kind==="rasgueado"?"RASGUEADO":t.kind.toUpperCase())+"_"+t.direction.toUpperCase();o.addModifier(new ie.Stroke(ie.Stroke.Type[s]),0)}}function jo(o,e,n,t,s){if(e.grace?.positions&&o instanceof ie.TabNote){let r=e.grace.positions.map(i=>new ie.GraceTabNote({positions:i,duration:"16"})),a=new ie.GraceNoteGroup(r).setPosition(e.grace.side==="before"?ie.Modifier.Position.LEFT:ie.Modifier.Position.RIGHT);o.addModifier(a,0)}if(e.grace?.fingerings){let r=o.getModifiers().find(a=>a instanceof ie.GraceNoteGroup);for(let{attack:a,head:i,finger:l,position:c}of e.grace.fingerings)r&&Tt(r.getGraceNotes()[a],i,[{finger:l,position:c}],n==="tab",!0,!0)}if(e.ornament&&n!=="tab"&&o.addModifier(new ie.Ornament(e.ornament.replace("_inverted","Inverted")),0),e.dynamic&&(t.hand||s)){let r=[...e.dynamic].map(i=>ie.TextDynamics.GLYPHS[i]).join(""),a=t.hand==="right"&&e.displayHand==="left"?ie.Annotation.VerticalJustify.TOP:ie.Annotation.VerticalJustify.BOTTOM;o.addModifier(new ie.Annotation(r).setFont(bt(),15).setVerticalJustification(a),0)}zo(o,e,n==="tab"),e.color&&(o.setStyle(we(e.color)),o instanceof ie.StaveNote&&o.setLedgerLineStyle(we(e.color))),e.silent&&(o.renderOptions.draw=!1),e.heads.forEach((r,a)=>{if(!r.marks)return;let i=o instanceof ie.StaveNote&&!r.drum?$n(r.marks,e.heads):void 0;Tt(o,a,r.marks.filter(l=>l!==i),n==="tab",!0)}),o instanceof ie.TabNote&&e.heads.forEach((r,a)=>{r.openSlide&&Nn(o,a,r.openSlide),r.prebend&&o.addModifier(yn(r.prebend),a)}),n==="tab"&&!t.tabStems&&!e.heads.length&&(o.renderOptions.draw=!1)}function Go(o,e,n,t){let s=nn(e).sort((a,i)=>(a.verse??"").localeCompare(i.verse??"")),r=0;for(let a of o.getModifiers()){if(!(a instanceof ie.Annotation))continue;let i=e.chord&&a.getText().split(" \xB7 ")[0]===e.chord.text,l=a.phraseManaged&&a.getVerticalJustification()===ie.Annotation.VerticalJustify.BOTTOM&&s[r++],c=i?e.chord.range:l&&l.range;if(!c)continue;i&&e.chord.color&&a.setStyle(we(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 Wo(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(_=>_>=r.firstBar&&_<=r.lastBar);if(!u.length)continue;let f=u[0],m=u[u.length-1],h=i(f),S=i(m);if(!h||!S)continue;let k=h.checkStave(),x=k.getX()+1,T=S.checkStave().getNoteEndX(),B=c.y+k.getY()-n.staves[f-1][0].getY()-15,H={x,y:B,w:T-x,h:14};e.endingRegions.push({id:a,kind:"span",source:r.id,row:l,...H}),s({source:h,bounds:H,draw(_){_.openGroup("tab-ending",a+"-"+l),_.fillRect(x,B,T-x,1),f===r.firstBar&&(_.fillRect(x,B,1,12),_.setFont(ze(),11).fillText(r.label,x+4,B+12)),m===r.lastBar&&_.fillRect(T-1,B,1,12),_.closeGroup()}})}}}function qo(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 ie.StaveNote&&i instanceof ie.StaveNote){let u=new ie.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 ie.TabNote)||!(i instanceof ie.TabNote))continue;let l=Number(i.getPositions()[s.toHead].fret)>Number(a.getPositions()[s.fromHead].fret),c=(u,f)=>{let m={firstNote:u,lastNote:f,firstIndexes:[s.fromHead],lastIndexes:[s.toHead]},h=s.kind==="slide"||s.kind==="glissando"?new ie.TabSlide(m,l?ie.TabSlide.SLIDE_UP:ie.TabSlide.SLIDE_DOWN):u?s.kind==="pull"?ie.TabTie.createPulloff(m):ie.TabTie.createHammeron(m):new ie.TabTie(m);u&&(s.kind==="hammer"||s.kind==="pull")&&h.setFont({...h.fontInfo,family:ze(),weight:Pt()}),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 Uo(o,e){let n=new Map;for(let t of o.measures)for(let s of e.staves)for(let r of qt(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?jo(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=Ln(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 S=h.getAttribute("id"),k=n.get(S),x=h;if(!k){e.textLanes.place(x,s,t);continue}let{measure:T,voice:B,staff:H,event:_}=k;r.set(S,x),e.printAnchors&&x.preFormatted&&a.has(T.number)&&(!e.printAnchors.has(_.id)||H===e.staves[0])&&e.printAnchors.set(_.id,{measure:T.number,x:x.getAbsoluteX(),row:a.get(T.number)}),_.silent&&(x.renderOptions.draw=!1);let M=x.checkStave();if(T.state.hideClef)for(let V of M.getModifiers(void 0,ie.Clef.CATEGORY))V.setText("");if(T.state.color){let V=we(T.state.color);M.setStyle(V),x.getVoice().setStyle(V),x.getBeam()?.setStyle(V)}if(H==="tab"&&!B.tabStems)for(let V of x.getTupletStack())V.setRendered();Go(x,_,e,H)}qo(o,e,r,s),e.mixedEndings.length&&Wo(o,e,t,r,s);let i=r.get(e.eventId(e.staves[0],qt(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=>{fi(f,c,l.x,l.width,c.align==="center"?u-150:u)}})}}}}function Ko(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 Mr=class extends ie.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 m of l.measures)for(let[h,S]of qt(m,u).entries())for(let k of S.events)k.silent&&r.push({id:c.eventId(u,k.id),source:k.id,staff:f.id,measure:m.number,voice:h+1,onset:k.onset,duration:k.duration,label:["Measure "+m.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 ie.Fraction().parse(l.onset).value()-new ie.Fraction().parse(c.onset).value()||i.get(l.staff)-i.get(c.staff)||l.voice-c.voice))}};function Xo(o,e,n){let t=new Map;for(let s of o.sheet.getContinuousLayout().rows){let r=Ln(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,m=n.heads.get(u.id).flatMap(S=>{if(S.role==="mark"||S.reference||typeof S.sourceHead!="number")return[];let k=u.heads[S.sourceHead];if(u.silent||!k||!k.sounding&&k.midi===void 0)return[];let x=S.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 Ut(o,e,n={}){let t=n.part??"score",s="parts"in e?Ue(e,n):0,r="parts"in e?je(e,s):e;return yt(r.layout?.font,()=>yi(o,[Pr(r,t)],t,n,!1,s))}function Gn(o,e,n={}){return yt(e.layout?.font,()=>yi(o,e.parts.map((t,s)=>je(e,s)),"score",n,!0))}function yi(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 l=e.map(J=>bi(J,n,i-20)),c=l.map(J=>J.spec),u=s?vr(e,c):c[0],f=document.createElement("div"),m=t.renderer==="canvas"?f.appendChild(document.createElement("canvas")):void 0,h=m?new ie.CanvasContext(m.getContext("2d")):new ie.SVGContext(f);m?f.style.position="relative":ln(h,o),a.layout?.heading&&!l[0].nativeHeading&&(u.sheet.y+=125),l.some(J=>J.mixedEndings.length)&&(u.sheet.y+=20);let S=new ie.Factory({renderer:{elementId:null,width:i,height:1}}).setContext(h),k=S.EasyScore();if(m){let J=u.engraving.place;u.engraving={...u.engraving,place(ce,oe){let ue=0;for(let C of ce.sheet.getContinuousLayout().detailMarks)ue=Math.max(ue,C.bounds.y+C.bounds.h);J(ce,C=>{ue=Math.max(ue,C.bounds.y+C.bounds.h),oe(C)}),H(ce.sheet,ue)}}}let x=k.compose(u),T=0,B=l.map((J,ce)=>{let oe=l.length===1?x:Ys(x,T,J.staves.length);T+=J.staves.length;let ue=e[ce];return{partIndex:r+ce,score:ue,view:J,local:oe}});function H(J,ce=0){let oe=Math.max(i,...J.getRows().map(ue=>ue.x+ue.width+10));h.resize(oe,Math.ceil(Math.max(J.getHeight(),ce)+20))}let _=[],M=l.flatMap(J=>J.frames.map(ce=>({frame:ce,sources:J.sources})));if(M.length){let J=ie.Registry.getDefaultRegistry(),ce=J??new ie.Registry;J||ie.Registry.enableDefaultRegistry(ce);try{S.draw(),ce.getElementsByType(ie.FretDiagram.CATEGORY).filter(ue=>ue.isRendered()&&ue.getContext()===h).forEach((ue,C)=>{let{frame:$,sources:Z}=M[C],{x:O,y:b,w:g,h:y}=ue.getBoundingBox();Z.ids[ue.getAttribute("id")]=$.source,_.push({id:$.id,source:$.source,kind:"event",x:O,y:b,w:g,h:y})})}finally{J||ie.Registry.disableDefaultRegistry()}}else S.draw();let V=l.flatMap(J=>[...J.textLanes.regions.values()]),j=[...V,..._,...l.flatMap(J=>J.endingRegions)],q=Object.assign(Object.create(null),...l.map(J=>J.sources.ids)),z=B.flatMap(({score:J,view:ce},oe)=>ce.staves.map(ue=>{let C=J.measures[0].state,$=J.instrument?.name??(C.piano?"Piano":C.tab?"Guitar":"Part "+(oe+1)),Z={right:"right hand",left:"left hand",tab:"tablature",notation:"notation"}[ue];return $+", "+Z})),R=s?u.staves.map((J,ce)=>({...J,name:z[ce]})):u.staves,N=new Mr(x,R,q,B),W=new Map(B.flatMap(({score:J,view:ce})=>J.ties.map(oe=>[ce.eventId("tab",oe.id),[]])));for(let J of N.regions)W.get(J.id)?.push(J);let E=[...W.values()].flat(),A=new Set(B.flatMap(({score:J,view:ce})=>[...Ko(J,ce)]));function L(J,ce){let oe=Z=>J>=Z.x&&J<=Z.x+Z.w&&ce>=Z.y&&ce<=Z.y+Z.h,ue=V.find(oe);if(ue)return ue;let C=N.heads.hitTest(J,ce);if(C&&typeof C.sourceHead=="number"&&C.role!=="mark")return{id:C.sourceEvent+"-head-"+C.sourceHead,source:C.sourceEvent,kind:"event",...C.bounds};let $=N.hitTest(J,ce);return $&&!A.has($.id)?$:j.find(oe)}m?(m.setAttribute("role","img"),m.setAttribute("aria-label",N.events.map(J=>J.label).join(". "))):H(x.sheet);let D=a.layout?.scale??1;if(D!==1){let J=m??h.svg;J.style.zoom=String(D),m||(f.style.width=parseFloat(J.style.width)*D+"px")}o.replaceChildren(f);function Y(J,ce,oe){return ne(J+"-head-"+ce,oe)}function ne(J,ce){for(let oe of l){let ue=oe.sources.rangeFor(J,ce);if(ue)return ue}}let se=x.sheet.getContinuousLayout().diagnostics.map(J=>({...J,range:J.source&&ne(J.source,a.source)||a.measures[J.measures[0]-1]?.range}));for(let J of a.measures)if(e.some(ce=>ce.measures[J.number-1].voices.some(oe=>oe.events.some(ue=>ue.chord||ue.lyric))))for(let ce of x.systems[J.number-1].getPhraseLayout().diagnostics){let oe=ce.sources.find(ue=>ne(ue,a.source));se.push({code:ce.code,measures:[J.number],source:oe,range:ne(oe,a.source)??J.range})}let re=m??h.svg,le=cn(re),ae,te=()=>yt(a.layout?.font,()=>Xo(x,B,N));function Q(){return ae??=yt(a.layout?.font,()=>Lr(x,B,N.heads,R,le))}return Wt.set(re,{score:a,ensemble:s?e:void 0,read:te}),{score:a,parts:e,composition:x,navigation:N,hitTest:L,tabRegions:E,extraRegions:j,diagnostics:se,rangeFor:ne,headRangeFor:Y,get layoutMap(){return Q()},createPlaybackOverlay(){return ci(f,re,Q(),e,te())},sourceFor:J=>q[J]}}function Pr(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 ee("measure","A hand part needs a piano score",o.measures[0].range);if(!t&&o.measures[0].state.piano&&n!==void 0)throw new ee("measure","Choose a hand before selecting its voice",o.measures[0].range);let s=new Set,r=o.measures.map(l=>{let c=t?qt(l,t):l.voices;if(n!==void 0){let u=c[n-1];if(!Number.isInteger(n)||!u)throw new ee("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(m=>m.displayHand?{...m,displayHand:void 0}:m):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 Wn(o,e,n,t={}){let{voice:s,partId:r,partIndex:a,...i}=t;return yt(e.layout?.font,()=>"parts"in e?vi(o,e,Ue(e,{partId:r,partIndex:a}),i,n,s):wi(o,[Pr(e,n,s)],[n],i))}function xi(o,e,n="conductor",t={}){return yt(e.layout?.font,()=>vi(o,e,n==="conductor"?n:Ue(e,n),t,"score"))}function vi(o,e,n,t,s,r){let a=n==="conductor",i=li(e,n,t),l=t.regions===void 0?i.cues.map(m=>Ue(e,{partId:m.part})):[],c=a?e.parts.map((m,h)=>h):[...new Set([n,...l])],u=c.map((m,h)=>{let S=je(e,m);return h===0&&!a?Pr(S,s,r):S}),f=u.map((m,h)=>h===0?s:"score");return wi(o,u,f,i.settings,{conductor:a,donors:l.map(m=>c.indexOf(m)),edition:i,document:e})}function wi(o,e,n,t,s){let r=e[0],a=e.map((_,M)=>bi(_,n[M],600,!0)),i=a.length>1?vr(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:l,...c}=t;if(l){let _=new Set([...c.preferredTurns??[],...c.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}=c;if(u?.length){for(let M of i.staves)for(let V of M.measures)for(let j of V.voices)typeof j.notes!="string"&&(j.notes=j.notes.map(q=>typeof q!="object"||!("skip"in q)||typeof q.skip=="string"?q:"B4/"+q.skip.duration+"/g"+".".repeat(q.skip.dots??0)+'[id="'+q.id+'"]'));let _=i.engraving.prepareNote;i.engraving={...i.engraving,prepareNote(M,V,j){_(M,V,j);for(let q of u)q(M,V,j)}}}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((j,q)=>j+q.staves.length,0);return{kind:"cue",staff:i.staves[V].id,label:_.label,measure:_.measure}}));let m=wr(r.source),h;try{h=new ie.Publication(i).render(o,f)}catch(_){throw s?.edition.range&&_.code==="BadPublication"?new ee("fixed-layout",_.message,m(s.edition.range)):_}let S=(s?.conductor?a:a.slice(0,1)).flatMap(_=>_.frames.map(M=>({frame:M,sources:_.sources})));S.length&&h.pages.flatMap(M=>[...M.svg.querySelectorAll(".vf-score-opening .vf-fret-diagram")]).forEach((M,V)=>{let j=M.getAttribute("data-vf-id")?.replace(/^vf-/,"");j&&S[V]&&(S[V].sources.ids[j]=S[V].frame.source)});let k=(_,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(N=>N.field==="forbiddenTurns"&&N.measure===M),j=_.detail.startsWith("cue exceeds")&&s?.edition.cues.find(N=>N.measure===M),q=V||j,z=_.code==="ExcludedAnchor"?_.detail:_.detail.split(" ")[1],R=q?m(q.range):k(z,r.source)||_.code==="TextOverflow"&&s?.edition.range&&m(s.edition.range)||r.measures[M-1]?.range;return{..._,range:R}}),T=new Map,B=s?.conductor?e:[r];for(let _ of B)for(let M of _.measures)for(let V of M.voices)for(let j of V.events)T.set(j.id,j);let H=new Map((s?.conductor?a:a.slice(0,1)).flatMap(_=>[..._.printAnchors]));for(let _ of h.pages)Wt.set(_.svg,{score:r,ensemble:s?.conductor?e:void 0,read:()=>ei(h,T,H,(f.staffSize??7)/40)});return{publication:h,diagnostics:x,score:r,rangeFor:k,headRangeFor:(_,M,V)=>k(_+"-head-"+M,V),sourceFor:_=>a.map(M=>M.sources.sourceFor(_)).find(Boolean)}}Si();function _e(o,e,n){return o.getAttribute(`data-${e}`)||(n?o.getAttribute(`data-${n}`):null)||o.getAttribute(e)}function Yo(o){let e=_e(o,"playback-controls"),n=_e(o,"playback-position"),t=_e(o,"playback-inset"),s=_e(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)),Cn(r),(e==="on"||e==="true")&&!r.visibility&&(r.visibility="hover"),r}function Nr(o,e){let n=_e(o,"layout");return n==="flow"||!n&&/^[ \t]*piano(?:\s|$)/m.test(e)}var Tr=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,Ie.default)(e).text(),(0,Ie.default)(e).empty(),(0,Ie.default)(e).css("position")==="static"&&(0,Ie.default)(e).css("position","relative");let t=(0,Ie.default)(e)[0];this.playbackControls=n.playbackControls??Yo(t),this.enablePlayer=n.player??(this.playbackControls===void 0?void 0:!!this.playbackControls);let s=_e(t,"performer");if(n.performer!==void 0)this.performer=n.performer;else if(s){if(!wt(s))throw new RangeError("Unknown performer: "+s);this.performer=s}this.seed=n.seed;let r=_e(t,"width");this.width=parseInt(r,10)||400,this.scale=parseFloat(_e(t,"scale"))||1,this.rendererBackend=_e(t,"renderer")||"svg";let a=n.language??Number(_e(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??_e(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??_e(t,"part-id")??void 0,this.conductor=(n.view??_e(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||Nr(t,this.code),t.classList.toggle("vextab-flow",this.flow),this.editor=_e(t,"editor")||"",this.show_errors=_e(t,"show-errors")||"",this.editor_width=parseInt(_e(t,"editor-width","editor_width"),10)||this.width,this.editor_height=parseInt(_e(t,"editor-height","editor_height"),10)||200,this.editor==="true"?(this.text_area=(0,Ie.default)('<textarea aria-label="VexTab source"></textarea>').addClass("editor").val(this.code),this.code=this.text_area.val(),this.editor_error=(0,Ie.default)('<div role="status"></div>').addClass("editor-error"),(0,Ie.default)(e).append((0,Ie.default)("<p/>")).append(this.editor_error),(0,Ie.default)(e).append((0,Ie.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,Ie.default)('<div role="status"></div>').addClass("editor-error"),(0,Ie.default)(e).append((0,Ie.default)("<p/>")).append(this.editor_error)),this.flow||(this.artist=new Ye(10,0,this.width,{scale:this.scale}),this.parser=new $e(this.artist,{language:1})),this.autoWidth=this.flow&&_e(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 X.BM("Total render time: ",()=>{this.parse(),this.draw()}),this}reportError(e){this.player?.removeControls(),this.diagnostic=e instanceof Je?{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,Ie.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?Gn(e,n,{width:a,renderer:s}):Ut(e,n,{width:a,part:this.part,renderer:s}),l=e.querySelector("svg, canvas"),c=cn(l);return this.text_area&&l.addEventListener("click",u=>{let f=c(u);if(!f)return;let m=i.hitTest(f.x,f.y);m&&this.selectSource(m.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,je(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 Xe(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,Ie.default)(this.sel)[0];t.insertBefore(n,t.firstChild);try{if(this.flow)this.drawFlow(n);else{let r=e?X.Flow.Renderer.Backends.CANVAS:X.Flow.Renderer.Backends.SVG,a=new X.Flow.Renderer(n,r);if(e||ln(a.getContext(),n),this.enablePlayer!==void 0&&(this.artist.customizations.player=String(this.enablePlayer)),!this.player&&this.artist.customizations.player==="true"&&(this.player=new Xe(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((m,h)=>"Voice "+(h+1)+". "+m.filter(S=>!S.shouldIgnoreTicks()).map(S=>{let k=S.getPositions?.(),x=l.note?.getClef()==="percussion"?S.notation?.filter(H=>H.kind==="unpitched").map(H=>H.label):void 0,T=x?.length?x:k?.map(H=>"string "+H.str+" fret "+H.fret);return(S.isRest()?"rest":(T??S.getKeys()).join(", "))+" ("+S.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?ot(this.code,{capacity:this.capacity}):void 0,this.candidate=this.document?je(this.document,Ue(this.document,{partId:this.partId,partIndex:this.partIndex})):ot(this.code,{language:1})):(this.artist.reset(),this.parser.parse(this.code))}catch(e){this.reportError(e)}return this}parse(){return X.BM("Parse time: ",()=>{this.parseInternal()}),this}draw(){return X.BM("Draw time: ",()=>{this.drawInternal()}),this}},Et=Tr;function Ei(o,e={}){return je(o,Ue(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 qn(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,l="resume"in i?i.resume():Promise.resolve();await Promise.all([l,o.isReady]),a.throwIfAborted();let c=new Set,u=new Set,f;function m(S){o.noteOff(S.channel,S.note.pitch),S.range&&o.pitchWheel(S.channel,8192),c.delete(S)}function h(){window.clearTimeout(f);let S=1/0;for(let k of c){let x=i.currentTime-k.start;if(x>=k.note.duration){m(k);continue}if(k.range){let T=Jo(k.note.bend,x)/k.range;o.pitchWheel(k.channel,Math.max(0,Math.min(16383,Math.round(8192+T*8192)))),S=Math.min(S,.012)}S=Math.min(S,k.note.duration-x)}c.size&&(f=window.setTimeout(h,Math.max(1,S*1e3)))}return{get currentTime(){return i.currentTime},playNote(S){h();let k=Math.ceil(Math.max(0,...(S.bend??[]).map(T=>Math.abs(T.semitones)))),x=n.find(T=>(!t.has(T)||u.has(T))&&![...c].some(B=>B.channel===T&&(k||B.range||B.note.pitch===S.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)),k&&o.pitchWheelRange(x,k),o.noteOn(x,S.pitch,S.velocity),c.add({channel:x,note:S,start:i.currentTime,range:k}),h()},stop(){window.clearTimeout(f);for(let S of c)m(S);for(let S of u)t.delete(S);u.clear()}}}return{open:s}}window.VEXTAB_SEL_V3="div.vextab-auto";(0,_r.default)(()=>{let o=window.VEXTAB_SEL_V3;o&&(0,_r.default)(o).forEach(e=>new Et(e))});var Kt=class o extends Et{static{this.SEL=".vex-tabdiv"}constructor(e,n){let t=(0,Un.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=Nr(t[0],t.text())||"VEXTAB_USE_SVG"in window||"Raphael"in window;t.attr("renderer",s?"svg":"canvas")}super(e,n)}static start(){(0,Un.default)(o.SEL).forEach(e=>new o(e))}},Mi=X.Flow;Mi.TabDiv=Kt;(0,Un.default)(()=>{Kt.SEL&&Kt.start()});window.VexTabDiv=Ar;return Ri($o);})();
|