jianpurender 1.1.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jianpurender.js +1 -1
- package/es5/jianpu_svg_render.d.ts +1 -0
- package/es6/index.js +1 -1
- package/es6/jianpu_svg_render.d.ts +1 -0
- package/es6/jianpu_svg_render.js +1 -1
- package/es6/lib.js +1 -1
- package/node/index.js +1 -1
- package/node/jianpu_svg_render.d.ts +1 -0
- package/node/jianpu_svg_render.js +1 -1
- package/node/lib.js +1 -1
- package/package.json +9 -2
package/dist/jianpurender.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var t,e={75:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DURATION_LINE_SCALES=e.SMALL_FONT_SIZE_MULTIPLIER=e.FONT_SIZE_MULTIPLIER=e.AUGMENTATION_SPACING_FACTOR=e.ACCIDENTAL_SPACING_FACTOR=e.AUGMENTATION_DASH_FACTOR=e.DOT_SIZE_FACTOR=e.OCTAVE_DOT_OFFSET_FACTOR=e.UNDERLINE_SPACING_FACTOR=e.COMPACT_SPACING_FACTOR=e.LINE_STROKE_WIDTH=void 0,e.LINE_STROKE_WIDTH=1,e.COMPACT_SPACING_FACTOR=1.5,e.UNDERLINE_SPACING_FACTOR=.2,e.OCTAVE_DOT_OFFSET_FACTOR=1,e.DOT_SIZE_FACTOR=.1,e.AUGMENTATION_DASH_FACTOR=.8,e.ACCIDENTAL_SPACING_FACTOR=.1,e.AUGMENTATION_SPACING_FACTOR=.2,e.FONT_SIZE_MULTIPLIER=1.2,e.SMALL_FONT_SIZE_MULTIPLIER=.75,e.DURATION_LINE_SCALES=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},88:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuSVGRender=e.ScrollType=void 0;var n,r=i(75),a=i(811),s=i(388),o=i(567),h=i(186),u=i(214);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(e.ScrollType=n={}));var l=function(){function t(t,e,i){var a,s,u,l,c,d,g,m,f,p,S,T=this;this.handleScrollEvent=function(t){T.lastKnownScrollLeft=T.parentElement.scrollLeft,T.isScrolling||window.requestAnimationFrame((function(){T.updateOverlaySignaturesForScroll(T.lastKnownScrollLeft),T.isScrolling=!1})),T.isScrolling=!0},this.jianpuInfo=t,this.div=i,this.config={noteHeight:null!==(a=e.noteHeight)&&void 0!==a?a:20,noteSpacingFactor:null!==(s=e.noteSpacingFactor)&&void 0!==s?s:r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:null!==(u=e.pixelsPerTimeStep)&&void 0!==u?u:0,noteColor:null!==(l=e.noteColor)&&void 0!==l?l:"black",activeNoteColor:null!==(c=e.activeNoteColor)&&void 0!==c?c:"red",defaultKey:null!==(d=e.defaultKey)&&void 0!==d?d:0,scrollType:null!==(g=e.scrollType)&&void 0!==g?g:n.PAGE,fontFamily:null!==(m=e.fontFamily)&&void 0!==m?m:"sans-serif",width:null!==(f=e.width)&&void 0!==f?f:0,height:null!==(p=e.height)&&void 0!==p?p:0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(S=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==S?S:o.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}return t.prototype.clear=function(){for(var t;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(a.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,a.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(a.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,a.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,a.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,a.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(t=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==t?t:o.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()},t.prototype.updateLayout=function(t){this.width=null!=t?t:this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);var e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width","".concat(this.width)),this.mainSVG.setAttribute("height","".concat(this.height)),this.mainG.setAttribute("transform","translate(0, ".concat(this.yBaseline+e,")")),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height","".concat(this.height)),this.overlayG.setAttribute("transform","translate(0, ".concat(this.yBaseline,")"))},t.prototype.redraw=function(t,e){var i=this,r=-1,s=this.config.pixelsPerTimeStep<=0;if(t){var o="".concat(t.start,"-").concat(t.pitch);if(this.playingNotes.forEach((function(t,e){if(e!==o){var n=i.mainSVG.querySelector('g[data-id="'.concat(e,'"]'));n&&(0,a.resetElementHighlight)(n,i.config.noteColor),i.playingNotes.delete(e)}})),!this.playingNotes.has(o)){var h=this.mainSVG.querySelector('g[data-id="'.concat(o,'"]'));if(h){(0,a.highlightElement)(h,this.config.activeNoteColor),this.playingNotes.set(o,t);var u=h.getBoundingClientRect(),l=this.mainSVG.getBoundingClientRect();r=u.left-l.left+this.parentElement.scrollLeft;var c=h.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||c)&&this.scrollIntoViewIfNeeded(r)}}if(!s&&this.signaturesBlinking){var d=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>d&&(this.signaturesBlinking=!1,(0,a.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);var g=this.width,m=this.width,f=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,p=0,S=new Map;this.jianpuModel.jianpuBlockMap.forEach((function(t,e){if(e>=i.lastRenderedQ-1e-9){g=s?m:i.jianpuModel.measuresInfo.quartersToTime(e,e)*i.config.pixelsPerTimeStep;var n=i.drawJianpuBlock(t,g,S);s?m+=n:m=Math.max(m,g+n);var r=i.mainSVG.querySelector('g[data-block-start="'.concat(t.start,'"]'));if(r)try{var a=r.getBBox(),o=a.y,h=a.y+a.height;p=Math.min(p,o),f=Math.max(f,h)}catch(t){}i.lastRenderedQ=e+t.length}})),this.height=Math.max(this.height,f-p+this.config.noteHeight),this.updateLayout(m)}return r},t.prototype.drawJianpuBlock=function(t,e,i){var n=0,o=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),u=(0,a.createSVGGroupChild)(this.musicG,"block-".concat(t.start));if(u.setAttribute("data-block-start","".concat(t.start)),h&&t.start>1e-6){var l=e-(o?.6*this.estimatedNoteWidth:4),c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE);(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)}var m=this.updateCurrentKey(t.start),f=this.updateCurrentTimeSignature(t.start),p=0;if((m||f)&&t.start>1e-6){var S=e+n;p=this.drawSignatures(this.signaturesG,S,m,f),o&&(n+=p+.2*this.estimatedNoteWidth)}var T=e+n,v=0;if(t.notes.length>0?v=this.drawNotes(t,T,i,u):t.length>1e-6&&(v=this.drawRest(t,T,u)),o){n+=v;var A=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?A*=1:t.length<.0625?A*=.05:t.length<.125?A*=.1:t.length<.25?A*=.2:t.length<.5?A*=.4:t.length<1&&(A*=.5),n+=A}else n=Math.max(p,v);return this.jianpuModel.isLastMeasureAtQ(t.start+t.length)&&(l=e+n,c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE),(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)),n},t.prototype.drawNotes=function(t,e,i,n){var o=this,h=e,u=e,l=.1*this.estimatedNoteWidth,c="".concat(this.numberFontSize,"px"),d="".concat(this.smallFontSize,"px"),g=t.durationLines,m=void 0===g?0:g,f=t.augmentationDots,p=void 0===f?0:f,S=t.augmentationDash,T=void 0!==S&&S;return t.notes.forEach((function(e){var g,f,S,v="".concat(e.start,"-").concat(e.pitch),A=(0,a.createSVGGroupChild)(n,v);t.isMeasureBeginning()&&A.setAttribute("data-is-measure-start","true");var E=h,_=E;if(0!==e.accidental){var I=s.ACCIDENTAL_TEXT[e.accidental];(0,a.drawSVGText)(A,I,E+l,0,d,"normal","end","text-top",o.config.noteColor)}var N=0;if(T){var y=o.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,M=y/50,C=(0,a.drawSVGPath)(A,s.augmentationDashPath,E,0,M,1);(0,a.setStroke)(C,o.config.noteColor,r.LINE_STROKE_WIDTH),_=E+(N=y)}else{var L="".concat(e.jianpuNumber);_=E+(N=(0,a.drawSVGText)(A,L,E,0,c,"normal","start","middle",o.config.noteColor).getBBox().width)}if(0!==e.octaveDot&&!1===T)for(var b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),O=E+N/2,R=2.8*H,G=o.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR,D=0;D<Math.abs(e.octaveDot);D++){var P=(e.octaveDot>0?-G:.6*G)-D*R*(e.octaveDot>0?1:-1);(0,a.drawSVGPath)(A,s.dotPath,O,P,b,b)}if(m>0)for(var w=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,F=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,k=N/s.PATH_SCALE*(null!==(g=r.DURATION_LINE_SCALES.get(m))&&void 0!==g?g:1),V=0;V<m;V++){var x=w+V*F,B=(0,a.drawSVGPath)(A,s.underlinePath,E,x,k,1);(0,a.setStroke)(B,o.config.noteColor,r.LINE_STROKE_WIDTH)}var U=_+l;if(p>0){var H;for(b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),D=0;D<p;D++)(0,a.drawSVGPath)(A,s.dotPath,U,0,b,b),U+=H+l;_=U+l}var j=_;if(e.tiedTo&&!T)i.set(e,{g:A,xNoteRight:j,yNoteBaseline:0});else if(e.tiedFrom){for(var Q=e.tiedFrom;Q.tiedFrom;)Q=Q.tiedFrom;var J=i.get(Q);if(J){var K=1*J.xNoteRight,W=(T?E-2.2*o.estimatedNoteWidth:E-l)-K,q=1.2*-o.config.noteHeight,Z=W/s.PATH_SCALE*1.3,z=o.config.noteHeight/s.PATH_SCALE*1.6;W>1&&(0,a.drawSVGPath)(J.g,s.tiePath,K-(null!==(S=null===(f=J.g.getCTM())||void 0===f?void 0:f.e)&&void 0!==S?S:0),q,Z,z);for(var X=Q;X&&X!==e;){i.delete(X);var Y=X.tiedTo;Y&&(X=Y)}}else console.warn("Missing linked SVG details for first tied note:",Q)}u=Math.max(u,_)})),u-e},t.prototype.drawRest=function(t,e,i){var n,o="".concat(this.numberFontSize,"px"),h=.1*this.estimatedNoteWidth,u=t.durationLines,l=void 0===u?0:u,c=t.augmentationDots,d=void 0===c?0:c,g=e,m=g,f=(0,a.drawSVGText)(i,"0",g,0,o,"normal","start","middle",this.config.noteColor).getBBox().width;if(m=g+f,l>0)for(var p=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,S=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,T=f/s.PATH_SCALE*(null!==(n=r.DURATION_LINE_SCALES.get(l))&&void 0!==n?n:1),v=0;v<l;v++){var A=p+v*S,E=(0,a.drawSVGPath)(i,s.underlinePath,g,A,T,1);(0,a.setStroke)(E,this.config.noteColor,r.LINE_STROKE_WIDTH)}var _=m+h;if(d>0){for(var I=this.config.noteHeight*r.DOT_SIZE_FACTOR,N=I/(.15*s.PATH_SCALE),y=0;y<d;y++)(0,a.drawSVGPath)(i,s.dotPath,_,0,N,N),_+=I+h;m=_+h}return m-e},t.prototype.drawSignatures=function(t,e,i,n){var r,s=e,o=.3*this.estimatedNoteWidth,h="".concat(this.smallFontSize,"px"),l="".concat(this.numberFontSize,"px");if(i){var c=null!==(r=u.PITCH_CLASS_NAMES[this.currentKey%12])&&void 0!==r?r:"C",d="1=".concat(c);s+=(0,a.drawSVGText)(t,d,s,0,l,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(n){var g="".concat(this.currentTimeSignature.numerator,"/").concat(this.currentTimeSignature.denominator);s+=(0,a.drawSVGText)(t,g,s,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+o}var m=s-e;try{var f=t.getBBox(),p=f.y,S=f.y+f.height,T=Math.max(this.yBaseline+S,this.yBaseline-p)+.5*this.config.noteHeight;this.height=Math.max(this.height,T)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,a.setBlinkAnimation)(this.overlayG,!0)),m},t.prototype.updateCurrentKey=function(t){var e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)},t.prototype.updateCurrentTimeSignature=function(t){var e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=e,0))},t.prototype.scrollIntoViewIfNeeded=function(t){var e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft,r=i;this.config.scrollType===n.PAGE?t<i+20?r=t-20:t>i+e-20&&(r=t-e+20):r=t-.5*e,r=Math.max(0,Math.min(r,this.parentElement.scrollWidth-e)),Math.abs(r-i)>1&&(this.parentElement.scrollTo({left:r,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(r))},t.prototype.updateOverlaySignaturesForScroll=function(t){var e,i=this.pixelsToTime(t),n=this.jianpuModel.measuresInfo.keySignatureAtQ(i),r=null!==(e=this.jianpuModel.measuresInfo.timeSignatureAtQ(i))&&void 0!==e?e:this.currentTimeSignature,s=!1;if(n!==this.currentKey&&(this.currentKey=n,s=!0),r.numerator===this.currentTimeSignature.numerator&&r.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=r,s=!0),s){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,a.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,a.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}},t.prototype.pixelsToTime=function(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)},t}();e.JianpuSVGRender=l},186:function(t,e,i){var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuModel=void 0,e.mapMidiToJianpu=u;var r=i(567),a=i(980),s=i(826),o=i(214),h=function(){function t(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}return t.prototype.isLastMeasureAtQ=function(t){return t>=this.lastQ-1e-6},t.prototype.getTotalDuration=function(){return this.lastQ},t.prototype.update=function(t,e){var i=this;this.jianpuInfo=t,t.notes.sort((function(t,e){return t.start-e.start})),this.lastQ=0,t.notes.forEach((function(t){i.lastQ=Math.max(i.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[r.DEFAULT_TEMPO],t.tempos.sort((function(t,e){return t.start-e.start})),t.tempos[0].start>1e-6&&t.tempos.unshift(n(n({},r.DEFAULT_TEMPO),{start:0}));var s=void 0!==e?{start:0,key:e}:n({},r.DEFAULT_KEY_SIGNATURE);t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[s],t.keySignatures.sort((function(t,e){return t.start-e.start})),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift(n(n({},s),{start:0})),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[r.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort((function(t,e){return t.start-e.start})),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift(n(n({},r.DEFAULT_TIME_SIGNATURE),{start:0})),this.measuresInfo=new a.MeasuresInfo(t,this.lastQ),this.infoToBlocks()},t.prototype.infoToBlocks=function(){var t=this,e=new Map,i=0;if(this.jianpuInfo.notes.forEach((function(n){var r=n.start,a=t.measuresInfo.measureNumberAtQ(r);if(r>i+1e-6){var o=i,h=r-o,u=t.measuresInfo.measureNumberAtQ(o),l=new s.JianpuBlock(o,h,[],u);e.set(o,l)}var c=t.measuresInfo.keySignatureAtQ(r),d=t.createJianpuNote(n,c),g=e.get(r);g||(g=new s.JianpuBlock(r,0,[],a),e.set(r,g)),g.addNote(d),i=Math.max(i,r+g.length)})),this.lastQ>i+1e-6){var n=i,r=this.lastQ-n;if(r>1e-6){var a=this.measuresInfo.measureNumberAtQ(n),o=new s.JianpuBlock(n,r,[],a);e.set(n,o)}}this.jianpuBlockMap=new Map;var h=Array.from(e.keys()).sort((function(t,e){return t-e})),u=[];h.forEach((function(t){u.push(e.get(t))}));for(var l=new Set;u.length>0;){var c=u.shift();l.has(c.start)&&this.jianpuBlockMap.has(c.start);var d=c.splitToBeat(this.measuresInfo);if(d)c.mergeToMap(this.jianpuBlockMap),l.add(c.start),u.unshift(d);else{var g=c,m=null;do{m=g.splitToStandardSymbol(this.measuresInfo),g.mergeToMap(this.jianpuBlockMap),l.add(g.start),m&&(g=m)}while(m)}}this.jianpuBlockMap.forEach((function(e){e.calculateRenderProperties(t.measuresInfo)}))},t.prototype.createJianpuNote=function(t,e){var i=u(t.pitch,e);return n(n({},t),{jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental})},t}();function u(t,e){var i=e%12,n=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(n-=12);var r=(t-(n+12*Math.round((t-n)/12))+12)%12,a=o.MAJOR_SCALE_INTERVALS[r],s=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],s=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],s=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],s=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],s=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],s=2;break;default:console.warn("Unexpected chromatic interval ".concat(r," in mapMidiToJianpu. Defaulting to sharp of lower valid degree."));var h=(r-1+12)%12,u=(r+1+12)%12,l=o.MAJOR_SCALE_INTERVALS[h],c=o.MAJOR_SCALE_INTERVALS[u];void 0!==l?(a=l,s=1):void 0!==c?(a=c,s=2):(a=1,s=1,console.error("Could not determine Jianpu number components for MIDI ".concat(t,", interval ").concat(r," from tonic in key ").concat(e,".")))}void 0===a&&(console.error("Jianpu number became undefined for MIDI ".concat(t," (interval ").concat(r,", key ").concat(e,") after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.")),a=1,s=1)}return{jianpuNumber:a,octaveDot:Math.floor((t-n)/12),accidental:s}}e.JianpuModel=h},214:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MIDDLE_C_MIDI=e.MAJOR_SCALE_INTERVALS=e.PITCH_CLASS_NAMES=e.MAX_QUARTER_DIVISION=e.MIN_RESOLUTION=void 0,e.MIN_RESOLUTION=.0625,e.MAX_QUARTER_DIVISION=240,e.PITCH_CLASS_NAMES=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],e.MAJOR_SCALE_INTERVALS={0:1,2:2,4:3,5:4,7:5,9:6,11:7},e.MIDDLE_C_MIDI=60},229:function(t,e,i){var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(e,i);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,r)}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),r=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||n(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(i(88),e),r(i(186),e),r(i(826),e),r(i(567),e)},388:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.dotPath=e.tiePath=e.augmentationDashPath=e.underlinePath=e.barPath=e.ACCIDENTAL_TEXT=e.ACCIDENTAL_PATHS=e.PATH_SCALE=void 0,e.PATH_SCALE=100,e.ACCIDENTAL_PATHS=[null,"m 30,15 h 40 m -35,20 h 40 M 50,0 v 50 M 70,5 v 50","m 45,5 v 40 c 0,15 20,15 20,0 V 20 C 65,5 45,5 45,5 Z","M 45,5 v 45 M 65,0 v 45 H 45 m 20,10 H 45"],e.ACCIDENTAL_TEXT=["","#","b"],e.barPath="m 0,-50 v 100",e.underlinePath="m 0,0 h 100",e.augmentationDashPath="m 0,0 h 50",e.tiePath="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",e.dotPath="M 0 0 a 15 15 0 1 0 0.0001 0 z"},567:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_TIME_SIGNATURE=e.DEFAULT_KEY_SIGNATURE=e.DEFAULT_TEMPO=void 0,e.getMeasureLength=function(t){return t.numerator*(4/t.denominator)},e.DEFAULT_TEMPO={start:0,qpm:60},e.DEFAULT_KEY_SIGNATURE={start:0,key:0},e.DEFAULT_TIME_SIGNATURE={start:0,numerator:4,denominator:4}},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SVGNS=void 0,e.drawSVGPath=function(t,i,n,r,a,s,o){void 0===o&&(o=1);var h=document.createElementNS(e.SVGNS,"path");return h.setAttributeNS(null,"d",i),h.setAttributeNS(null,"transform","translate(".concat(n,", ").concat(r,") scale(").concat(a,", ").concat(s,")")),o<1&&h.setAttributeNS(null,"opacity","".concat(o)),t.appendChild(h),h},e.drawSVGText=function(t,i,n,r,a,s,o,h,u,l){void 0===s&&(s="normal"),void 0===o&&(o="middle"),void 0===h&&(h="middle"),void 0===u&&(u="currentColor"),void 0===l&&(l=1);var c=document.createElementNS(e.SVGNS,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",a),c.setAttributeNS(null,"font-weight",s),c.setAttributeNS(null,"x","".concat(n)),c.setAttributeNS(null,"y","".concat(r)),c.setAttributeNS(null,"text-anchor",o),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==u&&c.setAttributeNS(null,"fill",u),l<1&&c.setAttributeNS(null,"opacity","".concat(l));var d=document.createTextNode(i);return c.appendChild(d),t.appendChild(c),c},e.createSVGGroupChild=function(t,i){var n=document.createElementNS(e.SVGNS,"g");return i&&n.setAttribute("data-id",i),t.appendChild(n),n},e.setBlinkAnimation=function(t,i,n){void 0===i&&(i=!0),void 0===n&&(n="1s");var r=t.querySelector('animate[attributeName="opacity"]');return i?r?(r.setAttributeNS(null,"repeatCount","indefinite"),r.beginElement()):((r=document.createElementNS(e.SVGNS,"animate")).setAttributeNS(null,"attributeName","opacity"),r.setAttributeNS(null,"values","1;0.2;1"),r.setAttributeNS(null,"keyTimes","0;0.5;1"),r.setAttributeNS(null,"dur",n),r.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(r)):(r&&(r.endElement(),r.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t},e.setFill=function(t,e){t.setAttributeNS(null,"fill",e)},e.setStroke=function(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width","".concat(i))},e.highlightElement=function(t,e){var i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((function(t){i.push(t)})),i.forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t},e.resetElementHighlight=function(t,e){t.querySelectorAll("text, path").forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))},e.SVGNS="http://www.w3.org/2000/svg"},826:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuBlock=void 0,e.splitJianpuNote=a;var n=i(214);function r(t){return Math.abs(t)<1e-6}function a(t,e){var i=t.start+t.length;if(e<=t.start||e>=i||r(i-e))return null;var n=i-e;t.length=e-t.start;var a={start:e,length:n,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(a.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=a),t.tiedTo=a,a}var s=function(){function t(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=[]),void 0===n&&(n=1),this.start=t,this.length=e,this.notes=i,this.measureNumber=n}return t.prototype.addNote=function(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!r(this.start-t.start))return console.warn("JianpuBlock: Attempted to add note at ".concat(t.start," to block starting at ").concat(this.start,". Ignoring.")),!1;for(var e=!1,i=!1,n=0;n<this.notes.length;n++)if(this.notes[n].pitch===t.pitch){i=!0,t.length<this.notes[n].length&&(this.notes[n].tiedFrom&&(t.tiedFrom=this.notes[n].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[n].tiedTo&&(t.tiedTo=this.notes[n].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[n]=t,e=!0);break}i||this.notes.push(t);for(var a=1/0,s=0,o=this.notes;s<o.length;s++){var h=o[s];a=Math.min(a,h.length)}return this.length=a,!i||e},t.prototype.split=function(e,i){var n=this.start+this.length;if(e<=this.start||e>=n||r(n-e))return null;for(var s=n-e,o=e-this.start,h=new t(e,s,[],i.measureNumberAtQ(e)),u=[],l=0,c=this.notes;l<c.length;l++){var d=c[l],g=d.start+d.length;if(g>e+1e-6){var m=a(d,e);m?u.push(m):console.warn("Split failed for note, unexpected state.")}else r(g-e)}return u.forEach((function(t){return h.addNote(t)})),this.length=o,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h},t.prototype.splitToBeat=function(t){var e=t.timeSignatureAtQ(this.start);if(!e)return null;var i=t.measureLengthAtQ(this.start),n=t.measureNumberAtQ(this.start),a=this.start-(n-Math.floor(n))*i,s=this.start-a,o=4/e.denominator,h=s/o;this.beatBegin=r(h-Math.round(h));var u=a+(Math.floor(h+1e-6)+1)*o,l=a+i,c=this.start+this.length,d=null;u<c-1e-6&&u>this.start+1e-6&&(d=u),l<c-1e-6&&l>this.start+1e-6&&(null===d||l<d)&&(d=l);var g=null;if(null!==d)(g=this.split(d,t))&&(this.beatEnd=!0);else{var m=(s+this.length)/o;this.beatEnd=r(m-Math.round(m)),this.beatEnd||(this.beatEnd=r(c-l))}return this.isTieStart=this.notes.some((function(t){return t.tiedFrom})),this.isTieEnd=this.notes.some((function(t){return t.tiedTo})),g&&(g.isTieStart=g.notes.some((function(t){return t.tiedFrom})),g.isTieEnd=g.notes.some((function(t){return t.tiedTo})),this.notes.some((function(t){return t.tiedTo&&t.start+t.length>d}))&&delete this.isTieEnd),g},t.prototype.calculateRenderProperties=function(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;var e=this.length;if(!(r(e)||e<0)){if(t.allowDottedRests||this.notes.length>0){if(r(e-1.5))return void(this.augmentationDots=1);if(r(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(r(e-.375))return this.durationLines=2,void(this.augmentationDots=1);r(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){var i=this.notes[0],n=t.timeSignatureAtQ(this.start);if(!n)return;var a=Math.max(4/n.denominator,1);if(!(this.measureNumber%1<=1e-6)&&i.tiedFrom&&r(i.tiedFrom.length-a)&&i.tiedFrom.pitch===i.pitch&&i.length>=1){var s=!0;if(i.tiedTo){var o=i.start+i.length;s=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(o))&&i.tiedTo.length>=1}s&&(this.augmentationDash=!0)}}}},t.prototype.splitToStandardSymbol=function(t){var e=this.length;if(r(e)||e<n.MIN_RESOLUTION-1e-6)return null;var i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));for(var a=0,s=0,o=i;s<o.length;s++){var h=o[s];if(e>=h-1e-6){a=h;break}}r(a)&&e<(a=n.MIN_RESOLUTION)-1e-6&&e>1e-6&&console.warn("Block length ".concat(e," is too small, rendering as ").concat(a));var u=null;return e>a+1e-6?(u=this.split(this.start+a,t),this.length!==a&&(console.warn("Adjusting block length after split from ".concat(this.length," to ").concat(a)),this.length=a)):this.length=a,u},t.prototype.mergeToMap=function(t){var e=t.get(this.start);e?(this.notes.forEach((function(t){return e.addNote(t)})),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)},t.prototype.isMeasureBeginning=function(){return r(this.measureNumber-Math.floor(this.measureNumber))},t}();e.JianpuBlock=s},980:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MeasuresInfo=void 0;var n=i(567),r=i(214),a=function(){function t(t,e){this.allowDottedRests=!0,this.measuresInfo=[];for(var i=0,a=0,s=0,o=t.tempos[0],h=t.keySignatures[0],u=t.timeSignatures[0],l=1,c=(0,n.getMeasureLength)(u),d=u.start,g=r.MIN_RESOLUTION,m=0;m<e;m+=g){var f={start:m,measureNumber:l+(m-d)/c,measureLength:c,tempo:o,keySignature:h,timeSignature:u};i<t.tempos.length&&Math.abs(t.tempos[i].start-m)<g/2&&(o=t.tempos[i++],f.tempo=o,f.tempoChange=!0),a<t.keySignatures.length&&Math.abs(t.keySignatures[a].start-m)<g/2&&(h=t.keySignatures[a++],f.keySignature=h,f.keyChange=!0),s<t.timeSignatures.length&&Math.abs(t.timeSignatures[s].start-m)<g/2&&(l+=(t.timeSignatures[s].start-d)/c,l=Math.round(1e3*l)/1e3,u=t.timeSignatures[s++],f.timeSignature=u,c=(0,n.getMeasureLength)(u),f.measureLength=c,f.measureNumber=l,f.timeChange=!0,d=f.start),this.measuresInfo.push(f)}}return t.prototype.findIndex=function(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/r.MIN_RESOLUTION)))},t.prototype.measureNumberAtQ=function(t){if(0===this.measuresInfo.length)return 1;var e=this.findIndex(t),i=this.measuresInfo[e],n=(t-i.start)/i.measureLength;return i.measureNumber+n+1e-9},t.prototype.measureLengthAtQ=function(t){if(0===this.measuresInfo.length)return(0,n.getMeasureLength)(n.DEFAULT_TIME_SIGNATURE);var e=this.findIndex(t);return this.measuresInfo[e].measureLength},t.prototype.tempoAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TEMPO.qpm;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.tempoChange&&s?a.tempo.qpm:-1},t.prototype.keySignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_KEY_SIGNATURE.key;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.keyChange&&s?a.keySignature.key:-1},t.prototype.timeSignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TIME_SIGNATURE;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.timeChange&&s?a.timeSignature:null},t.prototype.quartersToTime=function(t,e){var i=this.tempoAtQ(e);return i<=0?0:t/i*60},t.prototype.timeToQuarters=function(t,e){var i=this.tempoAtQ(e);if(i<=0)return 0;var n=t*i/60;return Math.round(n*r.MAX_QUARTER_DIVISION)/r.MAX_QUARTER_DIVISION},t.prototype.isBeatStart=function(t){if(0===this.measuresInfo.length)return!1;var e=this.findIndex(t),i=this.measuresInfo[e],n=i.timeSignature,a=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/n.denominator);return Math.abs(a-Math.round(a))<r.MIN_RESOLUTION/2},t}();e.MeasuresInfo=a}},i={};t=function t(n){var r=i[n];if(void 0!==r)return r.exports;var a=i[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(229),window.jr=t})();
|
|
1
|
+
(()=>{"use strict";var t,e={75:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DURATION_LINE_SCALES=e.SMALL_FONT_SIZE_MULTIPLIER=e.FONT_SIZE_MULTIPLIER=e.AUGMENTATION_SPACING_FACTOR=e.ACCIDENTAL_SPACING_FACTOR=e.AUGMENTATION_DASH_FACTOR=e.DOT_SIZE_FACTOR=e.OCTAVE_DOT_OFFSET_FACTOR=e.UNDERLINE_SPACING_FACTOR=e.COMPACT_SPACING_FACTOR=e.LINE_STROKE_WIDTH=void 0,e.LINE_STROKE_WIDTH=1,e.COMPACT_SPACING_FACTOR=1.5,e.UNDERLINE_SPACING_FACTOR=.2,e.OCTAVE_DOT_OFFSET_FACTOR=1,e.DOT_SIZE_FACTOR=.1,e.AUGMENTATION_DASH_FACTOR=.8,e.ACCIDENTAL_SPACING_FACTOR=.1,e.AUGMENTATION_SPACING_FACTOR=.2,e.FONT_SIZE_MULTIPLIER=1.2,e.SMALL_FONT_SIZE_MULTIPLIER=.75,e.DURATION_LINE_SCALES=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},88:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuSVGRender=e.ScrollType=void 0;var n,r=i(75),a=i(811),s=i(388),o=i(567),h=i(186),u=i(214);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(e.ScrollType=n={}));var l=function(){function t(t,e,i){var a,s,u,l,c,d,g,m,f,p,S,T=this;this.handleScrollEvent=function(t){T.lastKnownScrollLeft=T.parentElement.scrollLeft,T.isScrolling||window.requestAnimationFrame((function(){T.updateOverlaySignaturesForScroll(T.lastKnownScrollLeft),T.isScrolling=!1})),T.isScrolling=!0},this.jianpuInfo=t,this.div=i,this.config={noteHeight:null!==(a=e.noteHeight)&&void 0!==a?a:20,noteSpacingFactor:null!==(s=e.noteSpacingFactor)&&void 0!==s?s:r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:null!==(u=e.pixelsPerTimeStep)&&void 0!==u?u:0,noteColor:this.parseColorString(null!==(l=e.noteColor)&&void 0!==l?l:"black"),activeNoteColor:this.parseColorString(null!==(c=e.activeNoteColor)&&void 0!==c?c:"red"),defaultKey:null!==(d=e.defaultKey)&&void 0!==d?d:0,scrollType:null!==(g=e.scrollType)&&void 0!==g?g:n.PAGE,fontFamily:null!==(m=e.fontFamily)&&void 0!==m?m:"sans-serif",width:null!==(f=e.width)&&void 0!==f?f:0,height:null!==(p=e.height)&&void 0!==p?p:0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(S=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==S?S:o.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}return t.prototype.parseColorString=function(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?"rgb(".concat(t,")"):t},t.prototype.clear=function(){for(var t;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(a.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,a.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(a.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,a.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,a.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,a.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(t=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==t?t:o.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()},t.prototype.updateLayout=function(t){this.width=null!=t?t:this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);var e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width","".concat(this.width)),this.mainSVG.setAttribute("height","".concat(this.height)),this.mainG.setAttribute("transform","translate(0, ".concat(this.yBaseline+e,")")),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height","".concat(this.height)),this.overlayG.setAttribute("transform","translate(0, ".concat(this.yBaseline,")"))},t.prototype.redraw=function(t,e){var i=this,r=-1,s=this.config.pixelsPerTimeStep<=0;if(t){var o="".concat(t.start,"-").concat(t.pitch);if(this.playingNotes.forEach((function(t,e){if(e!==o){var n=i.mainSVG.querySelector('g[data-id="'.concat(e,'"]'));n&&(0,a.resetElementHighlight)(n,i.config.noteColor),i.playingNotes.delete(e)}})),!this.playingNotes.has(o)){var h=this.mainSVG.querySelector('g[data-id="'.concat(o,'"]'));if(h){(0,a.highlightElement)(h,this.config.activeNoteColor),this.playingNotes.set(o,t);var u=h.getBoundingClientRect(),l=this.mainSVG.getBoundingClientRect();r=u.left-l.left+this.parentElement.scrollLeft;var c=h.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||c)&&this.scrollIntoViewIfNeeded(r)}}if(!s&&this.signaturesBlinking){var d=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>d&&(this.signaturesBlinking=!1,(0,a.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);var g=this.width,m=this.width,f=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,p=0,S=new Map;this.jianpuModel.jianpuBlockMap.forEach((function(t,e){if(e>=i.lastRenderedQ-1e-9){g=s?m:i.jianpuModel.measuresInfo.quartersToTime(e,e)*i.config.pixelsPerTimeStep;var n=i.drawJianpuBlock(t,g,S);s?m+=n:m=Math.max(m,g+n);var r=i.mainSVG.querySelector('g[data-block-start="'.concat(t.start,'"]'));if(r)try{var a=r.getBBox(),o=a.y,h=a.y+a.height;p=Math.min(p,o),f=Math.max(f,h)}catch(t){}i.lastRenderedQ=e+t.length}})),this.height=Math.max(this.height,f-p+this.config.noteHeight),this.updateLayout(m)}return r},t.prototype.drawJianpuBlock=function(t,e,i){var n=0,o=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),u=(0,a.createSVGGroupChild)(this.musicG,"block-".concat(t.start));if(u.setAttribute("data-block-start","".concat(t.start)),h&&t.start>1e-6){var l=e-(o?.6*this.estimatedNoteWidth:4),c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE);(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)}var m=this.updateCurrentKey(t.start),f=this.updateCurrentTimeSignature(t.start),p=0;if((m||f)&&t.start>1e-6){var S=e+n;p=this.drawSignatures(this.signaturesG,S,m,f),o&&(n+=p+.2*this.estimatedNoteWidth)}var T=e+n,v=0;if(t.notes.length>0?v=this.drawNotes(t,T,i,u):t.length>1e-6&&(v=this.drawRest(t,T,u)),o){n+=v;var A=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?A*=1:t.length<.0625?A*=.05:t.length<.125?A*=.1:t.length<.25?A*=.2:t.length<.5?A*=.4:t.length<1&&(A*=.5),n+=A}else n=Math.max(p,v);return this.jianpuModel.isLastMeasureAtQ(t.start+t.length)&&(l=e+n,c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE),(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)),n},t.prototype.drawNotes=function(t,e,i,n){var o=this,h=e,u=e,l=.1*this.estimatedNoteWidth,c="".concat(this.numberFontSize,"px"),d="".concat(this.smallFontSize,"px"),g=t.durationLines,m=void 0===g?0:g,f=t.augmentationDots,p=void 0===f?0:f,S=t.augmentationDash,T=void 0!==S&&S;return t.notes.forEach((function(e){var g,f,S,v="".concat(e.start,"-").concat(e.pitch),A=(0,a.createSVGGroupChild)(n,v);t.isMeasureBeginning()&&A.setAttribute("data-is-measure-start","true");var E=h,_=E;if(0!==e.accidental){var I=s.ACCIDENTAL_TEXT[e.accidental];(0,a.drawSVGText)(A,I,E+l,0,d,"normal","end","text-top",o.config.noteColor)}var N=0;if(T){var y=o.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,M=y/50,C=(0,a.drawSVGPath)(A,s.augmentationDashPath,E,0,M,1);(0,a.setStroke)(C,o.config.noteColor,r.LINE_STROKE_WIDTH),_=E+(N=y)}else{var L="".concat(e.jianpuNumber);_=E+(N=(0,a.drawSVGText)(A,L,E,0,c,"normal","start","middle",o.config.noteColor).getBBox().width)}if(0!==e.octaveDot&&!1===T)for(var b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),O=E+N/2,R=2.8*H,G=o.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR,D=0;D<Math.abs(e.octaveDot);D++){var P=(e.octaveDot>0?-G:.6*G)-D*R*(e.octaveDot>0?1:-1);(0,a.drawSVGPath)(A,s.dotPath,O,P,b,b)}if(m>0)for(var w=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,F=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,k=N/s.PATH_SCALE*(null!==(g=r.DURATION_LINE_SCALES.get(m))&&void 0!==g?g:1),V=0;V<m;V++){var x=w+V*F,B=(0,a.drawSVGPath)(A,s.underlinePath,E,x,k,1);(0,a.setStroke)(B,o.config.noteColor,r.LINE_STROKE_WIDTH)}var U=_+l;if(p>0){var H;for(b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),D=0;D<p;D++)(0,a.drawSVGPath)(A,s.dotPath,U,0,b,b),U+=H+l;_=U+l}var j=_;if(e.tiedTo&&!T)i.set(e,{g:A,xNoteRight:j,yNoteBaseline:0});else if(e.tiedFrom){for(var Q=e.tiedFrom;Q.tiedFrom;)Q=Q.tiedFrom;var J=i.get(Q);if(J){var K=1*J.xNoteRight,W=(T?E-2.2*o.estimatedNoteWidth:E-l)-K,q=1.2*-o.config.noteHeight,Z=W/s.PATH_SCALE*1.3,z=o.config.noteHeight/s.PATH_SCALE*1.6;W>1&&(0,a.drawSVGPath)(J.g,s.tiePath,K-(null!==(S=null===(f=J.g.getCTM())||void 0===f?void 0:f.e)&&void 0!==S?S:0),q,Z,z);for(var X=Q;X&&X!==e;){i.delete(X);var Y=X.tiedTo;Y&&(X=Y)}}else console.warn("Missing linked SVG details for first tied note:",Q)}u=Math.max(u,_)})),u-e},t.prototype.drawRest=function(t,e,i){var n,o="".concat(this.numberFontSize,"px"),h=.1*this.estimatedNoteWidth,u=t.durationLines,l=void 0===u?0:u,c=t.augmentationDots,d=void 0===c?0:c,g=e,m=g,f=(0,a.drawSVGText)(i,"0",g,0,o,"normal","start","middle",this.config.noteColor).getBBox().width;if(m=g+f,l>0)for(var p=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,S=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,T=f/s.PATH_SCALE*(null!==(n=r.DURATION_LINE_SCALES.get(l))&&void 0!==n?n:1),v=0;v<l;v++){var A=p+v*S,E=(0,a.drawSVGPath)(i,s.underlinePath,g,A,T,1);(0,a.setStroke)(E,this.config.noteColor,r.LINE_STROKE_WIDTH)}var _=m+h;if(d>0){for(var I=this.config.noteHeight*r.DOT_SIZE_FACTOR,N=I/(.15*s.PATH_SCALE),y=0;y<d;y++)(0,a.drawSVGPath)(i,s.dotPath,_,0,N,N),_+=I+h;m=_+h}return m-e},t.prototype.drawSignatures=function(t,e,i,n){var r,s=e,o=.3*this.estimatedNoteWidth,h="".concat(this.smallFontSize,"px"),l="".concat(this.numberFontSize,"px");if(i){var c=null!==(r=u.PITCH_CLASS_NAMES[this.currentKey%12])&&void 0!==r?r:"C",d="1=".concat(c);s+=(0,a.drawSVGText)(t,d,s,0,l,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(n){var g="".concat(this.currentTimeSignature.numerator,"/").concat(this.currentTimeSignature.denominator);s+=(0,a.drawSVGText)(t,g,s,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+o}var m=s-e;try{var f=t.getBBox(),p=f.y,S=f.y+f.height,T=Math.max(this.yBaseline+S,this.yBaseline-p)+.5*this.config.noteHeight;this.height=Math.max(this.height,T)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,a.setBlinkAnimation)(this.overlayG,!0)),m},t.prototype.updateCurrentKey=function(t){var e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)},t.prototype.updateCurrentTimeSignature=function(t){var e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=e,0))},t.prototype.scrollIntoViewIfNeeded=function(t){var e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft,r=i;this.config.scrollType===n.PAGE?t<i+20?r=t-20:t>i+e-20&&(r=t-e+20):r=t-.5*e,r=Math.max(0,Math.min(r,this.parentElement.scrollWidth-e)),Math.abs(r-i)>1&&(this.parentElement.scrollTo({left:r,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(r))},t.prototype.updateOverlaySignaturesForScroll=function(t){var e,i=this.pixelsToTime(t),n=this.jianpuModel.measuresInfo.keySignatureAtQ(i),r=null!==(e=this.jianpuModel.measuresInfo.timeSignatureAtQ(i))&&void 0!==e?e:this.currentTimeSignature,s=!1;if(n!==this.currentKey&&(this.currentKey=n,s=!0),r.numerator===this.currentTimeSignature.numerator&&r.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=r,s=!0),s){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,a.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,a.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}},t.prototype.pixelsToTime=function(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)},t}();e.JianpuSVGRender=l},186:function(t,e,i){var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuModel=void 0,e.mapMidiToJianpu=u;var r=i(567),a=i(980),s=i(826),o=i(214),h=function(){function t(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}return t.prototype.isLastMeasureAtQ=function(t){return t>=this.lastQ-1e-6},t.prototype.getTotalDuration=function(){return this.lastQ},t.prototype.update=function(t,e){var i=this;this.jianpuInfo=t,t.notes.sort((function(t,e){return t.start-e.start})),this.lastQ=0,t.notes.forEach((function(t){i.lastQ=Math.max(i.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[r.DEFAULT_TEMPO],t.tempos.sort((function(t,e){return t.start-e.start})),t.tempos[0].start>1e-6&&t.tempos.unshift(n(n({},r.DEFAULT_TEMPO),{start:0}));var s=void 0!==e?{start:0,key:e}:n({},r.DEFAULT_KEY_SIGNATURE);t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[s],t.keySignatures.sort((function(t,e){return t.start-e.start})),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift(n(n({},s),{start:0})),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[r.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort((function(t,e){return t.start-e.start})),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift(n(n({},r.DEFAULT_TIME_SIGNATURE),{start:0})),this.measuresInfo=new a.MeasuresInfo(t,this.lastQ),this.infoToBlocks()},t.prototype.infoToBlocks=function(){var t=this,e=new Map,i=0;if(this.jianpuInfo.notes.forEach((function(n){var r=n.start,a=t.measuresInfo.measureNumberAtQ(r);if(r>i+1e-6){var o=i,h=r-o,u=t.measuresInfo.measureNumberAtQ(o),l=new s.JianpuBlock(o,h,[],u);e.set(o,l)}var c=t.measuresInfo.keySignatureAtQ(r),d=t.createJianpuNote(n,c),g=e.get(r);g||(g=new s.JianpuBlock(r,0,[],a),e.set(r,g)),g.addNote(d),i=Math.max(i,r+g.length)})),this.lastQ>i+1e-6){var n=i,r=this.lastQ-n;if(r>1e-6){var a=this.measuresInfo.measureNumberAtQ(n),o=new s.JianpuBlock(n,r,[],a);e.set(n,o)}}this.jianpuBlockMap=new Map;var h=Array.from(e.keys()).sort((function(t,e){return t-e})),u=[];h.forEach((function(t){u.push(e.get(t))}));for(var l=new Set;u.length>0;){var c=u.shift();l.has(c.start)&&this.jianpuBlockMap.has(c.start);var d=c.splitToBeat(this.measuresInfo);if(d)c.mergeToMap(this.jianpuBlockMap),l.add(c.start),u.unshift(d);else{var g=c,m=null;do{m=g.splitToStandardSymbol(this.measuresInfo),g.mergeToMap(this.jianpuBlockMap),l.add(g.start),m&&(g=m)}while(m)}}this.jianpuBlockMap.forEach((function(e){e.calculateRenderProperties(t.measuresInfo)}))},t.prototype.createJianpuNote=function(t,e){var i=u(t.pitch,e);return n(n({},t),{jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental})},t}();function u(t,e){var i=e%12,n=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(n-=12);var r=(t-(n+12*Math.round((t-n)/12))+12)%12,a=o.MAJOR_SCALE_INTERVALS[r],s=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],s=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],s=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],s=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],s=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],s=2;break;default:console.warn("Unexpected chromatic interval ".concat(r," in mapMidiToJianpu. Defaulting to sharp of lower valid degree."));var h=(r-1+12)%12,u=(r+1+12)%12,l=o.MAJOR_SCALE_INTERVALS[h],c=o.MAJOR_SCALE_INTERVALS[u];void 0!==l?(a=l,s=1):void 0!==c?(a=c,s=2):(a=1,s=1,console.error("Could not determine Jianpu number components for MIDI ".concat(t,", interval ").concat(r," from tonic in key ").concat(e,".")))}void 0===a&&(console.error("Jianpu number became undefined for MIDI ".concat(t," (interval ").concat(r,", key ").concat(e,") after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.")),a=1,s=1)}return{jianpuNumber:a,octaveDot:Math.floor((t-n)/12),accidental:s}}e.JianpuModel=h},214:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MIDDLE_C_MIDI=e.MAJOR_SCALE_INTERVALS=e.PITCH_CLASS_NAMES=e.MAX_QUARTER_DIVISION=e.MIN_RESOLUTION=void 0,e.MIN_RESOLUTION=.0625,e.MAX_QUARTER_DIVISION=240,e.PITCH_CLASS_NAMES=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],e.MAJOR_SCALE_INTERVALS={0:1,2:2,4:3,5:4,7:5,9:6,11:7},e.MIDDLE_C_MIDI=60},229:function(t,e,i){var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(e,i);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,r)}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),r=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||n(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(i(88),e),r(i(186),e),r(i(826),e),r(i(567),e)},388:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.dotPath=e.tiePath=e.augmentationDashPath=e.underlinePath=e.barPath=e.ACCIDENTAL_TEXT=e.ACCIDENTAL_PATHS=e.PATH_SCALE=void 0,e.PATH_SCALE=100,e.ACCIDENTAL_PATHS=[null,"m 30,15 h 40 m -35,20 h 40 M 50,0 v 50 M 70,5 v 50","m 45,5 v 40 c 0,15 20,15 20,0 V 20 C 65,5 45,5 45,5 Z","M 45,5 v 45 M 65,0 v 45 H 45 m 20,10 H 45"],e.ACCIDENTAL_TEXT=["","#","b"],e.barPath="m 0,-50 v 100",e.underlinePath="m 0,0 h 100",e.augmentationDashPath="m 0,0 h 50",e.tiePath="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",e.dotPath="M 0 0 a 15 15 0 1 0 0.0001 0 z"},567:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_TIME_SIGNATURE=e.DEFAULT_KEY_SIGNATURE=e.DEFAULT_TEMPO=void 0,e.getMeasureLength=function(t){return t.numerator*(4/t.denominator)},e.DEFAULT_TEMPO={start:0,qpm:60},e.DEFAULT_KEY_SIGNATURE={start:0,key:0},e.DEFAULT_TIME_SIGNATURE={start:0,numerator:4,denominator:4}},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SVGNS=void 0,e.drawSVGPath=function(t,i,n,r,a,s,o){void 0===o&&(o=1);var h=document.createElementNS(e.SVGNS,"path");return h.setAttributeNS(null,"d",i),h.setAttributeNS(null,"transform","translate(".concat(n,", ").concat(r,") scale(").concat(a,", ").concat(s,")")),o<1&&h.setAttributeNS(null,"opacity","".concat(o)),t.appendChild(h),h},e.drawSVGText=function(t,i,n,r,a,s,o,h,u,l){void 0===s&&(s="normal"),void 0===o&&(o="middle"),void 0===h&&(h="middle"),void 0===u&&(u="currentColor"),void 0===l&&(l=1);var c=document.createElementNS(e.SVGNS,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",a),c.setAttributeNS(null,"font-weight",s),c.setAttributeNS(null,"x","".concat(n)),c.setAttributeNS(null,"y","".concat(r)),c.setAttributeNS(null,"text-anchor",o),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==u&&c.setAttributeNS(null,"fill",u),l<1&&c.setAttributeNS(null,"opacity","".concat(l));var d=document.createTextNode(i);return c.appendChild(d),t.appendChild(c),c},e.createSVGGroupChild=function(t,i){var n=document.createElementNS(e.SVGNS,"g");return i&&n.setAttribute("data-id",i),t.appendChild(n),n},e.setBlinkAnimation=function(t,i,n){void 0===i&&(i=!0),void 0===n&&(n="1s");var r=t.querySelector('animate[attributeName="opacity"]');return i?r?(r.setAttributeNS(null,"repeatCount","indefinite"),r.beginElement()):((r=document.createElementNS(e.SVGNS,"animate")).setAttributeNS(null,"attributeName","opacity"),r.setAttributeNS(null,"values","1;0.2;1"),r.setAttributeNS(null,"keyTimes","0;0.5;1"),r.setAttributeNS(null,"dur",n),r.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(r)):(r&&(r.endElement(),r.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t},e.setFill=function(t,e){t.setAttributeNS(null,"fill",e)},e.setStroke=function(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width","".concat(i))},e.highlightElement=function(t,e){var i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((function(t){i.push(t)})),i.forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t},e.resetElementHighlight=function(t,e){t.querySelectorAll("text, path").forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))},e.SVGNS="http://www.w3.org/2000/svg"},826:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuBlock=void 0,e.splitJianpuNote=a;var n=i(214);function r(t){return Math.abs(t)<1e-6}function a(t,e){var i=t.start+t.length;if(e<=t.start||e>=i||r(i-e))return null;var n=i-e;t.length=e-t.start;var a={start:e,length:n,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(a.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=a),t.tiedTo=a,a}var s=function(){function t(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=[]),void 0===n&&(n=1),this.start=t,this.length=e,this.notes=i,this.measureNumber=n}return t.prototype.addNote=function(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!r(this.start-t.start))return console.warn("JianpuBlock: Attempted to add note at ".concat(t.start," to block starting at ").concat(this.start,". Ignoring.")),!1;for(var e=!1,i=!1,n=0;n<this.notes.length;n++)if(this.notes[n].pitch===t.pitch){i=!0,t.length<this.notes[n].length&&(this.notes[n].tiedFrom&&(t.tiedFrom=this.notes[n].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[n].tiedTo&&(t.tiedTo=this.notes[n].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[n]=t,e=!0);break}i||this.notes.push(t);for(var a=1/0,s=0,o=this.notes;s<o.length;s++){var h=o[s];a=Math.min(a,h.length)}return this.length=a,!i||e},t.prototype.split=function(e,i){var n=this.start+this.length;if(e<=this.start||e>=n||r(n-e))return null;for(var s=n-e,o=e-this.start,h=new t(e,s,[],i.measureNumberAtQ(e)),u=[],l=0,c=this.notes;l<c.length;l++){var d=c[l],g=d.start+d.length;if(g>e+1e-6){var m=a(d,e);m?u.push(m):console.warn("Split failed for note, unexpected state.")}else r(g-e)}return u.forEach((function(t){return h.addNote(t)})),this.length=o,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h},t.prototype.splitToBeat=function(t){var e=t.timeSignatureAtQ(this.start);if(!e)return null;var i=t.measureLengthAtQ(this.start),n=t.measureNumberAtQ(this.start),a=this.start-(n-Math.floor(n))*i,s=this.start-a,o=4/e.denominator,h=s/o;this.beatBegin=r(h-Math.round(h));var u=a+(Math.floor(h+1e-6)+1)*o,l=a+i,c=this.start+this.length,d=null;u<c-1e-6&&u>this.start+1e-6&&(d=u),l<c-1e-6&&l>this.start+1e-6&&(null===d||l<d)&&(d=l);var g=null;if(null!==d)(g=this.split(d,t))&&(this.beatEnd=!0);else{var m=(s+this.length)/o;this.beatEnd=r(m-Math.round(m)),this.beatEnd||(this.beatEnd=r(c-l))}return this.isTieStart=this.notes.some((function(t){return t.tiedFrom})),this.isTieEnd=this.notes.some((function(t){return t.tiedTo})),g&&(g.isTieStart=g.notes.some((function(t){return t.tiedFrom})),g.isTieEnd=g.notes.some((function(t){return t.tiedTo})),this.notes.some((function(t){return t.tiedTo&&t.start+t.length>d}))&&delete this.isTieEnd),g},t.prototype.calculateRenderProperties=function(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;var e=this.length;if(!(r(e)||e<0)){if(t.allowDottedRests||this.notes.length>0){if(r(e-1.5))return void(this.augmentationDots=1);if(r(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(r(e-.375))return this.durationLines=2,void(this.augmentationDots=1);r(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){var i=this.notes[0],n=t.timeSignatureAtQ(this.start);if(!n)return;var a=Math.max(4/n.denominator,1);if(!(this.measureNumber%1<=1e-6)&&i.tiedFrom&&r(i.tiedFrom.length-a)&&i.tiedFrom.pitch===i.pitch&&i.length>=1){var s=!0;if(i.tiedTo){var o=i.start+i.length;s=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(o))&&i.tiedTo.length>=1}s&&(this.augmentationDash=!0)}}}},t.prototype.splitToStandardSymbol=function(t){var e=this.length;if(r(e)||e<n.MIN_RESOLUTION-1e-6)return null;var i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));for(var a=0,s=0,o=i;s<o.length;s++){var h=o[s];if(e>=h-1e-6){a=h;break}}r(a)&&e<(a=n.MIN_RESOLUTION)-1e-6&&e>1e-6&&console.warn("Block length ".concat(e," is too small, rendering as ").concat(a));var u=null;return e>a+1e-6?(u=this.split(this.start+a,t),this.length!==a&&(console.warn("Adjusting block length after split from ".concat(this.length," to ").concat(a)),this.length=a)):this.length=a,u},t.prototype.mergeToMap=function(t){var e=t.get(this.start);e?(this.notes.forEach((function(t){return e.addNote(t)})),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)},t.prototype.isMeasureBeginning=function(){return r(this.measureNumber-Math.floor(this.measureNumber))},t}();e.JianpuBlock=s},980:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MeasuresInfo=void 0;var n=i(567),r=i(214),a=function(){function t(t,e){this.allowDottedRests=!0,this.measuresInfo=[];for(var i=0,a=0,s=0,o=t.tempos[0],h=t.keySignatures[0],u=t.timeSignatures[0],l=1,c=(0,n.getMeasureLength)(u),d=u.start,g=r.MIN_RESOLUTION,m=0;m<e;m+=g){var f={start:m,measureNumber:l+(m-d)/c,measureLength:c,tempo:o,keySignature:h,timeSignature:u};i<t.tempos.length&&Math.abs(t.tempos[i].start-m)<g/2&&(o=t.tempos[i++],f.tempo=o,f.tempoChange=!0),a<t.keySignatures.length&&Math.abs(t.keySignatures[a].start-m)<g/2&&(h=t.keySignatures[a++],f.keySignature=h,f.keyChange=!0),s<t.timeSignatures.length&&Math.abs(t.timeSignatures[s].start-m)<g/2&&(l+=(t.timeSignatures[s].start-d)/c,l=Math.round(1e3*l)/1e3,u=t.timeSignatures[s++],f.timeSignature=u,c=(0,n.getMeasureLength)(u),f.measureLength=c,f.measureNumber=l,f.timeChange=!0,d=f.start),this.measuresInfo.push(f)}}return t.prototype.findIndex=function(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/r.MIN_RESOLUTION)))},t.prototype.measureNumberAtQ=function(t){if(0===this.measuresInfo.length)return 1;var e=this.findIndex(t),i=this.measuresInfo[e],n=(t-i.start)/i.measureLength;return i.measureNumber+n+1e-9},t.prototype.measureLengthAtQ=function(t){if(0===this.measuresInfo.length)return(0,n.getMeasureLength)(n.DEFAULT_TIME_SIGNATURE);var e=this.findIndex(t);return this.measuresInfo[e].measureLength},t.prototype.tempoAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TEMPO.qpm;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.tempoChange&&s?a.tempo.qpm:-1},t.prototype.keySignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_KEY_SIGNATURE.key;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.keyChange&&s?a.keySignature.key:-1},t.prototype.timeSignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TIME_SIGNATURE;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.timeChange&&s?a.timeSignature:null},t.prototype.quartersToTime=function(t,e){var i=this.tempoAtQ(e);return i<=0?0:t/i*60},t.prototype.timeToQuarters=function(t,e){var i=this.tempoAtQ(e);if(i<=0)return 0;var n=t*i/60;return Math.round(n*r.MAX_QUARTER_DIVISION)/r.MAX_QUARTER_DIVISION},t.prototype.isBeatStart=function(t){if(0===this.measuresInfo.length)return!1;var e=this.findIndex(t),i=this.measuresInfo[e],n=i.timeSignature,a=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/n.denominator);return Math.abs(a-Math.round(a))<r.MIN_RESOLUTION/2},t}();e.MeasuresInfo=a}},i={};t=function t(n){var r=i[n];if(void 0!==r)return r.exports;var a=i[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(229),window.jr=t})();
|
|
@@ -42,6 +42,7 @@ export declare class JianpuSVGRender {
|
|
|
42
42
|
private numberFontSize;
|
|
43
43
|
private smallFontSize;
|
|
44
44
|
private yBaseline;
|
|
45
|
+
private parseColorString;
|
|
45
46
|
constructor(score: JianpuInfo, config: JianpuSVGRenderConfig, div: HTMLDivElement);
|
|
46
47
|
clear(): void;
|
|
47
48
|
private updateLayout;
|
package/es6/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.index=e():t.index=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{DEFAULT_KEY_SIGNATURE:()=>a.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>a.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>a.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>o.JianpuBlock,JianpuModel:()=>r.JianpuModel,JianpuSVGRender:()=>n.JianpuSVGRender,ScrollType:()=>n.ScrollType,getMeasureLength:()=>a.getMeasureLength,mapMidiToJianpu:()=>r.mapMidiToJianpu,splitJianpuNote:()=>o.splitJianpuNote});var n=i(313),r=i(849),o=i(765),a=i(830);return s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.index=e():t.index=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{DEFAULT_KEY_SIGNATURE:()=>a.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>a.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>a.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>o.JianpuBlock,JianpuModel:()=>r.JianpuModel,JianpuSVGRender:()=>n.JianpuSVGRender,ScrollType:()=>n.ScrollType,getMeasureLength:()=>a.getMeasureLength,mapMidiToJianpu:()=>r.mapMidiToJianpu,splitJianpuNote:()=>o.splitJianpuNote});var n=i(313),r=i(849),o=i(765),a=i(830);return s})()));
|
|
@@ -42,6 +42,7 @@ export declare class JianpuSVGRender {
|
|
|
42
42
|
private numberFontSize;
|
|
43
43
|
private smallFontSize;
|
|
44
44
|
private yBaseline;
|
|
45
|
+
private parseColorString;
|
|
45
46
|
constructor(score: JianpuInfo, config: JianpuSVGRenderConfig, div: HTMLDivElement);
|
|
46
47
|
clear(): void;
|
|
47
48
|
private updateLayout;
|
package/es6/jianpu_svg_render.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jianpu_svg_render=e():t.jianpu_svg_render=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=function(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=Math.round((t-s)/12),r=(t-(s+12*n)+12)%12;let a=o.MAJOR_SCALE_INTERVALS[r],h=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],h=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],h=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],h=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],h=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],h=2;break;default:{console.warn(`Unexpected chromatic interval ${r} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(r-1+12)%12,s=(r+1+12)%12,n=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==n?(a=n,h=1):void 0!==l?(a=l,h=2):(a=1,h=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${r} from tonic in key ${e}.`));break}}void 0===a&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${r}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),a=1,h=1)}const l=Math.floor((t-s)/12);return{jianpuNumber:a,octaveDot:l,accidental:h}}(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{JianpuSVGRender:()=>c,ScrollType:()=>n});var n,r=i(240),o=i(134),a=i(961),h=i(830),l=i(849),u=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(n={}));class c{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??n.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new l.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(o.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,o.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(o.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,o.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,o.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,o.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const s=this.config.pixelsPerTimeStep<=0;if(t){const r=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==r){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,o.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(r)){const s=this.mainSVG.querySelector(`g[data-id="${r}"]`);if(s){(0,o.highlightElement)(s,this.config.activeNoteColor),this.playingNotes.set(r,t);const a=s.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=s.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!s&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,o.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,n=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=s?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);s?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,s=t.y+t.height;n=Math.min(n,e),i=Math.max(i,s)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-n+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const n=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,o.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(n?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),n&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),n){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let n=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,f=(0,o.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&f.setAttribute("data-is-measure-start","true");let p=n,T=p;if(0!==e.accidental){const t=a.ACCIDENTAL_TEXT[e.accidental];(0,o.drawSVGText)(f,t,p+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,o.drawSVGPath)(f,a.augmentationDashPath,p,0,e,1);(0,o.setStroke)(i,this.config.noteColor,r.LINE_STROKE_WIDTH),A=t,T=p+A}else{const t=`${e.jianpuNumber}`;A=(0,o.drawSVGText)(f,t,p,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=p+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,i=t/(.15*a.PATH_SCALE),s=p+A/2,n=2.8*t,h=this.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const r=(e.octaveDot>0?-h:.6*h)-t*n*(e.octaveDot>0?1:-1);(0,o.drawSVGPath)(f,a.dotPath,s,r,i,i)}}if(d>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,i=A/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const n=t+s*e,h=(0,o.drawSVGPath)(f,a.underlinePath,p,n,i,1);(0,o.setStroke)(h,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let i=0;i<m;i++)(0,o.drawSVGPath)(f,a.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:f,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,r=(g?p-2.2*this.estimatedNoteWidth:p-l)-n,h=1.2*-this.config.noteHeight,u=r/a.PATH_SCALE*1.3,c=this.config.noteHeight/a.PATH_SCALE*1.6;r>1&&(0,o.drawSVGPath)(s.g,a.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,n=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,o.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,s=d/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(h)??1);for(let n=0;n<h;n++){const h=t+n*e,l=(0,o.drawSVGPath)(i,a.underlinePath,u,h,s,1);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let m=c+n;if(l>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let s=0;s<l;s++)(0,o.drawSVGPath)(i,a.dotPath,m,0,e,e),m+=t+n;c=m+n}return c-e}drawSignatures(t,e,i,s){let n=e;const r=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${u.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,o.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*r}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,o.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+r}const l=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,o.setBlinkAnimation)(this.overlayG,!0)),l}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let s=i;if(this.config.scrollType===n.PAGE){const n=20;t<i+n?s=t-n:t>i+e-n&&(s=t-e+n)}else{s=t-.5*e}s=Math.max(0,Math.min(s,this.parentElement.scrollWidth-e)),Math.abs(s-i)>1&&(this.parentElement.scrollTo({left:s,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(s))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,o.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,o.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}return s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jianpu_svg_render=e():t.jianpu_svg_render=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=function(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=Math.round((t-s)/12),r=(t-(s+12*n)+12)%12;let a=o.MAJOR_SCALE_INTERVALS[r],h=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],h=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],h=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],h=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],h=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],h=2;break;default:{console.warn(`Unexpected chromatic interval ${r} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(r-1+12)%12,s=(r+1+12)%12,n=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==n?(a=n,h=1):void 0!==l?(a=l,h=2):(a=1,h=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${r} from tonic in key ${e}.`));break}}void 0===a&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${r}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),a=1,h=1)}const l=Math.floor((t-s)/12);return{jianpuNumber:a,octaveDot:l,accidental:h}}(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{JianpuSVGRender:()=>c,ScrollType:()=>n});var n,r=i(240),o=i(134),a=i(961),h=i(830),l=i(849),u=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(n={}));class c{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??n.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new l.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(o.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,o.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(o.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,o.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,o.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,o.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const s=this.config.pixelsPerTimeStep<=0;if(t){const r=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==r){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,o.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(r)){const s=this.mainSVG.querySelector(`g[data-id="${r}"]`);if(s){(0,o.highlightElement)(s,this.config.activeNoteColor),this.playingNotes.set(r,t);const a=s.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=s.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!s&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,o.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,n=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=s?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);s?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,s=t.y+t.height;n=Math.min(n,e),i=Math.max(i,s)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-n+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const n=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,o.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(n?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),n&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),n){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let n=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,f=(0,o.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&f.setAttribute("data-is-measure-start","true");let p=n,T=p;if(0!==e.accidental){const t=a.ACCIDENTAL_TEXT[e.accidental];(0,o.drawSVGText)(f,t,p+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,o.drawSVGPath)(f,a.augmentationDashPath,p,0,e,1);(0,o.setStroke)(i,this.config.noteColor,r.LINE_STROKE_WIDTH),A=t,T=p+A}else{const t=`${e.jianpuNumber}`;A=(0,o.drawSVGText)(f,t,p,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=p+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,i=t/(.15*a.PATH_SCALE),s=p+A/2,n=2.8*t,h=this.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const r=(e.octaveDot>0?-h:.6*h)-t*n*(e.octaveDot>0?1:-1);(0,o.drawSVGPath)(f,a.dotPath,s,r,i,i)}}if(d>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,i=A/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const n=t+s*e,h=(0,o.drawSVGPath)(f,a.underlinePath,p,n,i,1);(0,o.setStroke)(h,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let i=0;i<m;i++)(0,o.drawSVGPath)(f,a.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:f,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,r=(g?p-2.2*this.estimatedNoteWidth:p-l)-n,h=1.2*-this.config.noteHeight,u=r/a.PATH_SCALE*1.3,c=this.config.noteHeight/a.PATH_SCALE*1.6;r>1&&(0,o.drawSVGPath)(s.g,a.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,n=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,o.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,s=d/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(h)??1);for(let n=0;n<h;n++){const h=t+n*e,l=(0,o.drawSVGPath)(i,a.underlinePath,u,h,s,1);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let m=c+n;if(l>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let s=0;s<l;s++)(0,o.drawSVGPath)(i,a.dotPath,m,0,e,e),m+=t+n;c=m+n}return c-e}drawSignatures(t,e,i,s){let n=e;const r=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${u.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,o.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*r}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,o.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+r}const l=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,o.setBlinkAnimation)(this.overlayG,!0)),l}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let s=i;if(this.config.scrollType===n.PAGE){const n=20;t<i+n?s=t-n:t>i+e-n&&(s=t-e+n)}else{s=t-.5*e}s=Math.max(0,Math.min(s,this.parentElement.scrollWidth-e)),Math.abs(s-i)>1&&(this.parentElement.scrollTo({left:s,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(s))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,o.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,o.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}return s})()));
|
package/es6/lib.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.lib=e():t.lib=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},644:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_KEY_SIGNATURE:()=>o.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>o.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>o.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>r.JianpuBlock,JianpuModel:()=>n.JianpuModel,JianpuSVGRender:()=>s.JianpuSVGRender,ScrollType:()=>s.ScrollType,getMeasureLength:()=>o.getMeasureLength,mapMidiToJianpu:()=>n.mapMidiToJianpu,splitJianpuNote:()=>r.splitJianpuNote});var s=i(313),n=i(849),r=i(765),o=i(830)},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s);var n=i(644);return window.jr=n,s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.lib=e():t.lib=e()}(self,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},644:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_KEY_SIGNATURE:()=>o.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>o.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>o.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>r.JianpuBlock,JianpuModel:()=>n.JianpuModel,JianpuSVGRender:()=>s.JianpuSVGRender,ScrollType:()=>s.ScrollType,getMeasureLength:()=>o.getMeasureLength,mapMidiToJianpu:()=>n.mapMidiToJianpu,splitJianpuNote:()=>r.splitJianpuNote});var s=i(313),n=i(849),r=i(765),o=i(830)},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s);var n=i(644);return window.jr=n,s})()));
|
package/node/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{DEFAULT_KEY_SIGNATURE:()=>a.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>a.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>a.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>o.JianpuBlock,JianpuModel:()=>r.JianpuModel,JianpuSVGRender:()=>n.JianpuSVGRender,ScrollType:()=>n.ScrollType,getMeasureLength:()=>a.getMeasureLength,mapMidiToJianpu:()=>r.mapMidiToJianpu,splitJianpuNote:()=>o.splitJianpuNote});var n=i(313),r=i(849),o=i(765),a=i(830);return s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{DEFAULT_KEY_SIGNATURE:()=>a.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>a.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>a.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>o.JianpuBlock,JianpuModel:()=>r.JianpuModel,JianpuSVGRender:()=>n.JianpuSVGRender,ScrollType:()=>n.ScrollType,getMeasureLength:()=>a.getMeasureLength,mapMidiToJianpu:()=>r.mapMidiToJianpu,splitJianpuNote:()=>o.splitJianpuNote});var n=i(313),r=i(849),o=i(765),a=i(830);return s})()));
|
|
@@ -42,6 +42,7 @@ export declare class JianpuSVGRender {
|
|
|
42
42
|
private numberFontSize;
|
|
43
43
|
private smallFontSize;
|
|
44
44
|
private yBaseline;
|
|
45
|
+
private parseColorString;
|
|
45
46
|
constructor(score: JianpuInfo, config: JianpuSVGRenderConfig, div: HTMLDivElement);
|
|
46
47
|
clear(): void;
|
|
47
48
|
private updateLayout;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=function(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=Math.round((t-s)/12),r=(t-(s+12*n)+12)%12;let a=o.MAJOR_SCALE_INTERVALS[r],h=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],h=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],h=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],h=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],h=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],h=2;break;default:{console.warn(`Unexpected chromatic interval ${r} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(r-1+12)%12,s=(r+1+12)%12,n=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==n?(a=n,h=1):void 0!==l?(a=l,h=2):(a=1,h=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${r} from tonic in key ${e}.`));break}}void 0===a&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${r}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),a=1,h=1)}const l=Math.floor((t-s)/12);return{jianpuNumber:a,octaveDot:l,accidental:h}}(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{JianpuSVGRender:()=>c,ScrollType:()=>n});var n,r=i(240),o=i(134),a=i(961),h=i(830),l=i(849),u=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(n={}));class c{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??n.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new l.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(o.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,o.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(o.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,o.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,o.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,o.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const s=this.config.pixelsPerTimeStep<=0;if(t){const r=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==r){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,o.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(r)){const s=this.mainSVG.querySelector(`g[data-id="${r}"]`);if(s){(0,o.highlightElement)(s,this.config.activeNoteColor),this.playingNotes.set(r,t);const a=s.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=s.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!s&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,o.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,n=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=s?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);s?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,s=t.y+t.height;n=Math.min(n,e),i=Math.max(i,s)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-n+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const n=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,o.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(n?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),n&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),n){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let n=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,f=(0,o.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&f.setAttribute("data-is-measure-start","true");let p=n,T=p;if(0!==e.accidental){const t=a.ACCIDENTAL_TEXT[e.accidental];(0,o.drawSVGText)(f,t,p+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,o.drawSVGPath)(f,a.augmentationDashPath,p,0,e,1);(0,o.setStroke)(i,this.config.noteColor,r.LINE_STROKE_WIDTH),A=t,T=p+A}else{const t=`${e.jianpuNumber}`;A=(0,o.drawSVGText)(f,t,p,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=p+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,i=t/(.15*a.PATH_SCALE),s=p+A/2,n=2.8*t,h=this.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const r=(e.octaveDot>0?-h:.6*h)-t*n*(e.octaveDot>0?1:-1);(0,o.drawSVGPath)(f,a.dotPath,s,r,i,i)}}if(d>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,i=A/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const n=t+s*e,h=(0,o.drawSVGPath)(f,a.underlinePath,p,n,i,1);(0,o.setStroke)(h,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let i=0;i<m;i++)(0,o.drawSVGPath)(f,a.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:f,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,r=(g?p-2.2*this.estimatedNoteWidth:p-l)-n,h=1.2*-this.config.noteHeight,u=r/a.PATH_SCALE*1.3,c=this.config.noteHeight/a.PATH_SCALE*1.6;r>1&&(0,o.drawSVGPath)(s.g,a.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,n=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,o.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,s=d/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(h)??1);for(let n=0;n<h;n++){const h=t+n*e,l=(0,o.drawSVGPath)(i,a.underlinePath,u,h,s,1);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let m=c+n;if(l>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let s=0;s<l;s++)(0,o.drawSVGPath)(i,a.dotPath,m,0,e,e),m+=t+n;c=m+n}return c-e}drawSignatures(t,e,i,s){let n=e;const r=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${u.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,o.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*r}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,o.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+r}const l=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,o.setBlinkAnimation)(this.overlayG,!0)),l}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let s=i;if(this.config.scrollType===n.PAGE){const n=20;t<i+n?s=t-n:t>i+e-n&&(s=t-e+n)}else{s=t-.5*e}s=Math.max(0,Math.min(s,this.parentElement.scrollWidth-e)),Math.abs(s-i)>1&&(this.parentElement.scrollTo({left:s,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(s))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,o.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,o.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}return s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=function(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=Math.round((t-s)/12),r=(t-(s+12*n)+12)%12;let a=o.MAJOR_SCALE_INTERVALS[r],h=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],h=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],h=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],h=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],h=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],h=2;break;default:{console.warn(`Unexpected chromatic interval ${r} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(r-1+12)%12,s=(r+1+12)%12,n=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==n?(a=n,h=1):void 0!==l?(a=l,h=2):(a=1,h=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${r} from tonic in key ${e}.`));break}}void 0===a&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${r}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),a=1,h=1)}const l=Math.floor((t-s)/12);return{jianpuNumber:a,octaveDot:l,accidental:h}}(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{JianpuSVGRender:()=>c,ScrollType:()=>n});var n,r=i(240),o=i(134),a=i(961),h=i(830),l=i(849),u=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(n={}));class c{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??n.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new l.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(o.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,o.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(o.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,o.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,o.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,o.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??h.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const s=this.config.pixelsPerTimeStep<=0;if(t){const r=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==r){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,o.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(r)){const s=this.mainSVG.querySelector(`g[data-id="${r}"]`);if(s){(0,o.highlightElement)(s,this.config.activeNoteColor),this.playingNotes.set(r,t);const a=s.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=s.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!s&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,o.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,n=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=s?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);s?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,s=t.y+t.height;n=Math.min(n,e),i=Math.max(i,s)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-n+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const n=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,o.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(n?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),n&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),n){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,o.drawSVGPath)(this.musicG,a.barPath,t,h,1,i/a.PATH_SCALE);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH),n&&(s+=r.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let n=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,f=(0,o.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&f.setAttribute("data-is-measure-start","true");let p=n,T=p;if(0!==e.accidental){const t=a.ACCIDENTAL_TEXT[e.accidental];(0,o.drawSVGText)(f,t,p+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,o.drawSVGPath)(f,a.augmentationDashPath,p,0,e,1);(0,o.setStroke)(i,this.config.noteColor,r.LINE_STROKE_WIDTH),A=t,T=p+A}else{const t=`${e.jianpuNumber}`;A=(0,o.drawSVGText)(f,t,p,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=p+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,i=t/(.15*a.PATH_SCALE),s=p+A/2,n=2.8*t,h=this.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const r=(e.octaveDot>0?-h:.6*h)-t*n*(e.octaveDot>0?1:-1);(0,o.drawSVGPath)(f,a.dotPath,s,r,i,i)}}if(d>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,i=A/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const n=t+s*e,h=(0,o.drawSVGPath)(f,a.underlinePath,p,n,i,1);(0,o.setStroke)(h,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let i=0;i<m;i++)(0,o.drawSVGPath)(f,a.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:f,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,r=(g?p-2.2*this.estimatedNoteWidth:p-l)-n,h=1.2*-this.config.noteHeight,u=r/a.PATH_SCALE*1.3,c=this.config.noteHeight/a.PATH_SCALE*1.6;r>1&&(0,o.drawSVGPath)(s.g,a.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,n=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,o.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,s=d/a.PATH_SCALE*(r.DURATION_LINE_SCALES.get(h)??1);for(let n=0;n<h;n++){const h=t+n*e,l=(0,o.drawSVGPath)(i,a.underlinePath,u,h,s,1);(0,o.setStroke)(l,this.config.noteColor,r.LINE_STROKE_WIDTH)}}let m=c+n;if(l>0){const t=this.config.noteHeight*r.DOT_SIZE_FACTOR,e=t/(.15*a.PATH_SCALE);for(let s=0;s<l;s++)(0,o.drawSVGPath)(i,a.dotPath,m,0,e,e),m+=t+n;c=m+n}return c-e}drawSignatures(t,e,i,s){let n=e;const r=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${u.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,o.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*r}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,o.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+r}const l=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,o.setBlinkAnimation)(this.overlayG,!0)),l}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let s=i;if(this.config.scrollType===n.PAGE){const n=20;t<i+n?s=t-n:t>i+e-n&&(s=t-e+n)}else{s=t-.5*e}s=Math.max(0,Math.min(s,this.parentElement.scrollWidth-e)),Math.abs(s-i)>1&&(this.parentElement.scrollTo({left:s,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(s))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,o.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,o.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}return s})()));
|
package/node/lib.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:e.noteColor??"black",activeNoteColor:e.activeNoteColor??"red",defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},644:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_KEY_SIGNATURE:()=>o.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>o.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>o.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>r.JianpuBlock,JianpuModel:()=>n.JianpuModel,JianpuSVGRender:()=>s.JianpuSVGRender,ScrollType:()=>s.ScrollType,getMeasureLength:()=>o.getMeasureLength,mapMidiToJianpu:()=>n.mapMidiToJianpu,splitJianpuNote:()=>r.splitJianpuNote});var s=i(313),n=i(849),r=i(765),o=i(830)},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s);var n=i(644);return window.jr=n,s})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mm=e():t.mm=e()}(global,(()=>(()=>{"use strict";var t={134:(t,e,i)=>{i.d(e,{SVGNS:()=>s,createSVGGroupChild:()=>o,drawSVGPath:()=>n,drawSVGText:()=>r,highlightElement:()=>l,resetElementHighlight:()=>u,setBlinkAnimation:()=>a,setStroke:()=>h});const s="http://www.w3.org/2000/svg";function n(t,e,i,n,r,o,a=1){const h=document.createElementNS(s,"path");return h.setAttributeNS(null,"d",e),h.setAttributeNS(null,"transform",`translate(${i}, ${n}) scale(${r}, ${o})`),a<1&&h.setAttributeNS(null,"opacity",`${a}`),t.appendChild(h),h}function r(t,e,i,n,r,o="normal",a="middle",h="middle",l="currentColor",u=1){const c=document.createElementNS(s,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",r),c.setAttributeNS(null,"font-weight",o),c.setAttributeNS(null,"x",`${i}`),c.setAttributeNS(null,"y",`${n}`),c.setAttributeNS(null,"text-anchor",a),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==l&&c.setAttributeNS(null,"fill",l),u<1&&c.setAttributeNS(null,"opacity",`${u}`);const d=document.createTextNode(e);return c.appendChild(d),t.appendChild(c),c}function o(t,e){const i=document.createElementNS(s,"g");return e&&i.setAttribute("data-id",e),t.appendChild(i),i}function a(t,e=!0,i="1s"){let n=t.querySelector('animate[attributeName="opacity"]');return e?n?(n.setAttributeNS(null,"repeatCount","indefinite"),n.beginElement()):(n=document.createElementNS(s,"animate"),n.setAttributeNS(null,"attributeName","opacity"),n.setAttributeNS(null,"values","1;0.2;1"),n.setAttributeNS(null,"keyTimes","0;0.5;1"),n.setAttributeNS(null,"dur",i),n.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(n)):(n&&(n.endElement(),n.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t}function h(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width",`${i}`)}function l(t,e){const i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((t=>{i.push(t)})),i.forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t}function u(t,e){t.querySelectorAll("text, path").forEach((t=>{"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))}},240:(t,e,i)=>{i.d(e,{AUGMENTATION_DASH_FACTOR:()=>h,COMPACT_SPACING_FACTOR:()=>n,DOT_SIZE_FACTOR:()=>a,DURATION_LINE_SCALES:()=>c,FONT_SIZE_MULTIPLIER:()=>l,LINE_STROKE_WIDTH:()=>s,OCTAVE_DOT_OFFSET_FACTOR:()=>o,SMALL_FONT_SIZE_MULTIPLIER:()=>u,UNDERLINE_SPACING_FACTOR:()=>r});const s=1,n=1.5,r=.2,o=1,a=.1,h=.8,l=1.2,u=.75,c=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},313:(t,e,i)=>{i.d(e,{JianpuSVGRender:()=>u,ScrollType:()=>s});var s,n=i(240),r=i(134),o=i(961),a=i(830),h=i(849),l=i(559);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(s||(s={}));class u{jianpuInfo;jianpuModel;config;height;width;parentElement;div;mainSVG;mainG;musicG;signaturesG;overlaySVG;overlayG;signaturesBlinking;lastKnownScrollLeft;isScrolling;currentKey;currentTimeSignature;playingNotes;lastRenderedQ;estimatedNoteWidth;numberFontSize;smallFontSize;yBaseline;parseColorString(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?`rgb(${t})`:t}constructor(t,e,i){this.jianpuInfo=t,this.div=i;this.config={noteHeight:e.noteHeight??20,noteSpacingFactor:e.noteSpacingFactor??n.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:e.pixelsPerTimeStep??0,noteColor:this.parseColorString(e.noteColor??"black"),activeNoteColor:this.parseColorString(e.activeNoteColor??"red"),defaultKey:e.defaultKey??0,scrollType:e.scrollType??s.PAGE,fontFamily:e.fontFamily??"sans-serif",width:e.width??0,height:e.height??0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*n.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*n.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(r.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,r.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(r.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,r.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,r.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,r.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=this.jianpuModel.measuresInfo.timeSignatureAtQ(0)??a.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()}updateLayout(t){this.width=t??this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);const e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width",`${this.width}`),this.mainSVG.setAttribute("height",`${this.height}`),this.mainG.setAttribute("transform",`translate(0, ${this.yBaseline+e})`),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height",`${this.height}`),this.overlayG.setAttribute("transform",`translate(0, ${this.yBaseline})`)}redraw(t,e){let i=-1;const n=this.config.pixelsPerTimeStep<=0;if(t){const o=`${t.start}-${t.pitch}`;if(this.playingNotes.forEach(((t,e)=>{if(e!==o){const t=this.mainSVG.querySelector(`g[data-id="${e}"]`);t&&(0,r.resetElementHighlight)(t,this.config.noteColor),this.playingNotes.delete(e)}})),!this.playingNotes.has(o)){const n=this.mainSVG.querySelector(`g[data-id="${o}"]`);if(n){(0,r.highlightElement)(n,this.config.activeNoteColor),this.playingNotes.set(o,t);const a=n.getBoundingClientRect(),h=this.mainSVG.getBoundingClientRect();i=a.left-h.left+this.parentElement.scrollLeft;const l=n.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==s.BAR||l)&&this.scrollIntoViewIfNeeded(i)}}if(!n&&this.signaturesBlinking){const e=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>e&&(this.signaturesBlinking=!1,(0,r.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);let t=this.width,e=this.width,i=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,s=0;const r=new Map;this.jianpuModel.jianpuBlockMap.forEach(((o,a)=>{if(a>=this.lastRenderedQ-1e-9){t=n?e:this.jianpuModel.measuresInfo.quartersToTime(a,a)*this.config.pixelsPerTimeStep;const h=this.drawJianpuBlock(o,t,r);n?e+=h:e=Math.max(e,t+h);const l=this.mainSVG.querySelector(`g[data-block-start="${o.start}"]`);if(l)try{const t=l.getBBox(),e=t.y,n=t.y+t.height;s=Math.min(s,e),i=Math.max(i,n)}catch(t){}this.lastRenderedQ=a+o.length}})),this.height=Math.max(this.height,i-s+this.config.noteHeight),this.updateLayout(e)}return i}drawJianpuBlock(t,e,i){let s=0;const a=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),l=(0,r.createSVGGroupChild)(this.musicG,`block-${t.start}`);if(l.setAttribute("data-block-start",`${t.start}`),h&&t.start>1e-6){const t=e-(a?.6*this.estimatedNoteWidth:4),i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}const u=this.updateCurrentKey(t.start),c=this.updateCurrentTimeSignature(t.start);let d=0;if((u||c)&&t.start>1e-6){const t=e+s;d=this.drawSignatures(this.signaturesG,t,u,c),a&&(s+=d+.2*this.estimatedNoteWidth)}const m=e+s;let g=0;if(t.notes.length>0?g=this.drawNotes(t,m,i,l):t.length>1e-6&&(g=this.drawRest(t,m,l)),a){s+=g;let e=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?e*=1:t.length<.0625?e*=.05:t.length<.125?e*=.1:t.length<.25?e*=.2:t.length<.5?e*=.4:t.length<1&&(e*=.5),s+=e}else s=Math.max(d,g);if(this.jianpuModel.isLastMeasureAtQ(t.start+t.length)){const t=e+s,i=2*this.config.noteHeight,h=0,l=(0,r.drawSVGPath)(this.musicG,o.barPath,t,h,1,i/o.PATH_SCALE);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH),a&&(s+=n.LINE_STROKE_WIDTH)}return s}drawNotes(t,e,i,s){let a=e,h=e;const l=.1*this.estimatedNoteWidth,u=`${this.numberFontSize}px`,c=`${this.smallFontSize}px`,{durationLines:d=0,augmentationDots:m=0,augmentationDash:g=!1}=t;return t.notes.forEach((e=>{const S=`${e.start}-${e.pitch}`,p=(0,r.createSVGGroupChild)(s,S);t.isMeasureBeginning()&&p.setAttribute("data-is-measure-start","true");let f=a,T=f;if(0!==e.accidental){const t=o.ACCIDENTAL_TEXT[e.accidental];(0,r.drawSVGText)(p,t,f+l,0,c,"normal","end","text-top",this.config.noteColor)}let A=0;if(g){const t=this.config.noteHeight*n.AUGMENTATION_DASH_FACTOR,e=t/50,i=(0,r.drawSVGPath)(p,o.augmentationDashPath,f,0,e,1);(0,r.setStroke)(i,this.config.noteColor,n.LINE_STROKE_WIDTH),A=t,T=f+A}else{const t=`${e.jianpuNumber}`;A=(0,r.drawSVGText)(p,t,f,0,u,"normal","start","middle",this.config.noteColor).getBBox().width,T=f+A}if(0!==e.octaveDot&&!1===g){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,i=t/(.15*o.PATH_SCALE),s=f+A/2,a=2.8*t,h=this.config.noteHeight*n.OCTAVE_DOT_OFFSET_FACTOR;for(let t=0;t<Math.abs(e.octaveDot);t++){const n=(e.octaveDot>0?-h:.6*h)-t*a*(e.octaveDot>0?1:-1);(0,r.drawSVGPath)(p,o.dotPath,s,n,i,i)}}if(d>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,i=A/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(d)??1);for(let s=0;s<d;s++){const a=t+s*e,h=(0,r.drawSVGPath)(p,o.underlinePath,f,a,i,1);(0,r.setStroke)(h,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let E=T+l;if(m>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let i=0;i<m;i++)(0,r.drawSVGPath)(p,o.dotPath,E,0,e,e),E+=t+l;T=E+l}const I=T;if(e.tiedTo&&!g)i.set(e,{g:p,xNoteRight:I,yNoteBaseline:0});else if(e.tiedFrom){let t=e.tiedFrom;for(;t.tiedFrom;)t=t.tiedFrom;const s=i.get(t);if(s){const n=1*s.xNoteRight,a=(g?f-2.2*this.estimatedNoteWidth:f-l)-n,h=1.2*-this.config.noteHeight,u=a/o.PATH_SCALE*1.3,c=this.config.noteHeight/o.PATH_SCALE*1.6;a>1&&(0,r.drawSVGPath)(s.g,o.tiePath,n-(s.g.getCTM()?.e??0),h,u,c);let d=t;for(;d&&d!==e;){i.delete(d);const t=d.tiedTo;t&&(d=t)}}else console.warn("Missing linked SVG details for first tied note:",t)}h=Math.max(h,T)})),h-e}drawRest(t,e,i){const s=`${this.numberFontSize}px`,a=.1*this.estimatedNoteWidth,{durationLines:h=0,augmentationDots:l=0}=t;let u=e,c=u;const d=(0,r.drawSVGText)(i,"0",u,0,s,"normal","start","middle",this.config.noteColor).getBBox().width;if(c=u+d,h>0){const t=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR*2.5,e=this.config.noteHeight*n.UNDERLINE_SPACING_FACTOR,s=d/o.PATH_SCALE*(n.DURATION_LINE_SCALES.get(h)??1);for(let a=0;a<h;a++){const h=t+a*e,l=(0,r.drawSVGPath)(i,o.underlinePath,u,h,s,1);(0,r.setStroke)(l,this.config.noteColor,n.LINE_STROKE_WIDTH)}}let m=c+a;if(l>0){const t=this.config.noteHeight*n.DOT_SIZE_FACTOR,e=t/(.15*o.PATH_SCALE);for(let s=0;s<l;s++)(0,r.drawSVGPath)(i,o.dotPath,m,0,e,e),m+=t+a;c=m+a}return c-e}drawSignatures(t,e,i,s){let n=e;const o=.3*this.estimatedNoteWidth,a=`${this.smallFontSize}px`,h=`${this.numberFontSize}px`;if(i){const e=`1=${l.PITCH_CLASS_NAMES[this.currentKey%12]??"C"}`;n+=(0,r.drawSVGText)(t,e,n,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(s){const e=`${this.currentTimeSignature.numerator}/${this.currentTimeSignature.denominator}`;n+=(0,r.drawSVGText)(t,e,n,0,a,"normal","start","middle",this.config.noteColor).getBBox().width+o}const u=n-e;try{const e=t.getBBox(),i=e.y,s=e.y+e.height,n=Math.max(this.yBaseline+s,this.yBaseline-i)+.5*this.config.noteHeight;this.height=Math.max(this.height,n)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,r.setBlinkAnimation)(this.overlayG,!0)),u}updateCurrentKey(t){const e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)}updateCurrentTimeSignature(t){const e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator)&&(this.currentTimeSignature=e,!0)}handleScrollEvent=t=>{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.isScrolling||window.requestAnimationFrame((()=>{this.updateOverlaySignaturesForScroll(this.lastKnownScrollLeft),this.isScrolling=!1})),this.isScrolling=!0};scrollIntoViewIfNeeded(t){const e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft;let n=i;if(this.config.scrollType===s.PAGE){const s=20;t<i+s?n=t-s:t>i+e-s&&(n=t-e+s)}else{n=t-.5*e}n=Math.max(0,Math.min(n,this.parentElement.scrollWidth-e)),Math.abs(n-i)>1&&(this.parentElement.scrollTo({left:n,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(n))}updateOverlaySignaturesForScroll(t){const e=this.pixelsToTime(t),i=this.jianpuModel.measuresInfo.keySignatureAtQ(e),s=this.jianpuModel.measuresInfo.timeSignatureAtQ(e)??this.currentTimeSignature;let n=!1;if(i!==this.currentKey&&(this.currentKey=i,n=!0),s.numerator===this.currentTimeSignature.numerator&&s.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=s,n=!0),n){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,r.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,r.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}}pixelsToTime(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)}}},559:(t,e,i)=>{i.d(e,{MAJOR_SCALE_INTERVALS:()=>o,MAX_QUARTER_DIVISION:()=>n,MIDDLE_C_MIDI:()=>a,MIN_RESOLUTION:()=>s,PITCH_CLASS_NAMES:()=>r});const s=.0625,n=240,r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],o={0:1,2:2,4:3,5:4,7:5,9:6,11:7},a=60},644:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_KEY_SIGNATURE:()=>o.DEFAULT_KEY_SIGNATURE,DEFAULT_TEMPO:()=>o.DEFAULT_TEMPO,DEFAULT_TIME_SIGNATURE:()=>o.DEFAULT_TIME_SIGNATURE,JianpuBlock:()=>r.JianpuBlock,JianpuModel:()=>n.JianpuModel,JianpuSVGRender:()=>s.JianpuSVGRender,ScrollType:()=>s.ScrollType,getMeasureLength:()=>o.getMeasureLength,mapMidiToJianpu:()=>n.mapMidiToJianpu,splitJianpuNote:()=>r.splitJianpuNote});var s=i(313),n=i(849),r=i(765),o=i(830)},765:(t,e,i)=>{i.d(e,{JianpuBlock:()=>o,splitJianpuNote:()=>r});var s=i(559);function n(t){return Math.abs(t)<1e-6}function r(t,e){const i=t.start+t.length;if(e<=t.start||e>=i||n(i-e))return null;const s=i-e;t.length=e-t.start;const r={start:e,length:s,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(r.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=r),t.tiedTo=r,r}class o{start;length;notes;measureNumber;durationLines;augmentationDots;augmentationDash;beatBegin;beatEnd;isTieStart;isTieEnd;constructor(t=0,e=0,i=[],s=1){this.start=t,this.length=e,this.notes=i,this.measureNumber=s}addNote(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!n(this.start-t.start))return console.warn(`JianpuBlock: Attempted to add note at ${t.start} to block starting at ${this.start}. Ignoring.`),!1;let e=!1,i=!1;for(let s=0;s<this.notes.length;s++)if(this.notes[s].pitch===t.pitch){i=!0,t.length<this.notes[s].length&&(this.notes[s].tiedFrom&&(t.tiedFrom=this.notes[s].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[s].tiedTo&&(t.tiedTo=this.notes[s].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[s]=t,e=!0);break}i||this.notes.push(t);let s=1/0;for(const t of this.notes)s=Math.min(s,t.length);return this.length=s,!i||e}split(t,e){const i=this.start+this.length;if(t<=this.start||t>=i||n(i-t))return null;const s=i-t,a=t-this.start,h=new o(t,s,[],e.measureNumberAtQ(t)),l=[];for(const e of this.notes){const i=e.start+e.length;if(i>t+1e-6){const i=r(e,t);i?l.push(i):console.warn("Split failed for note, unexpected state.")}else n(i-t)}return l.forEach((t=>h.addNote(t))),this.length=a,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h}splitToBeat(t){const e=t.timeSignatureAtQ(this.start);if(!e)return null;const i=t.measureLengthAtQ(this.start),s=t.measureNumberAtQ(this.start),r=this.start-(s-Math.floor(s))*i,o=this.start-r,a=4/e.denominator,h=o/a;this.beatBegin=n(h-Math.round(h));const l=r+(Math.floor(h+1e-6)+1)*a,u=r+i,c=this.start+this.length;let d=null;l<c-1e-6&&l>this.start+1e-6&&(d=l),u<c-1e-6&&u>this.start+1e-6&&(null===d||u<d)&&(d=u);let m=null;if(null!==d)m=this.split(d,t),m&&(this.beatEnd=!0);else{const t=(o+this.length)/a;this.beatEnd=n(t-Math.round(t)),this.beatEnd||(this.beatEnd=n(c-u))}return this.isTieStart=this.notes.some((t=>t.tiedFrom)),this.isTieEnd=this.notes.some((t=>t.tiedTo)),m&&(m.isTieStart=m.notes.some((t=>t.tiedFrom)),m.isTieEnd=m.notes.some((t=>t.tiedTo)),this.notes.some((t=>t.tiedTo&&t.start+t.length>d))&&delete this.isTieEnd),m}calculateRenderProperties(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;const e=this.length;if(n(e)||e<0)return;if(t.allowDottedRests||this.notes.length>0){if(n(e-1.5))return void(this.augmentationDots=1);if(n(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(n(e-.375))return this.durationLines=2,void(this.augmentationDots=1);n(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){const e=this.notes[0],i=t.timeSignatureAtQ(this.start);if(!i)return;const s=Math.max(4/i.denominator,1);if(!(this.measureNumber%1<=1e-6)&&e.tiedFrom&&n(e.tiedFrom.length-s)&&e.tiedFrom.pitch===e.pitch&&e.length>=1){let i=!0;if(e.tiedTo){const s=e.start+e.length;i=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(s))&&e.tiedTo.length>=1}i&&(this.augmentationDash=!0)}}}splitToStandardSymbol(t){const e=this.length;if(n(e)||e<s.MIN_RESOLUTION-1e-6)return null;const i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));let r=0;for(const t of i)if(e>=t-1e-6){r=t;break}n(r)&&(r=s.MIN_RESOLUTION,e<r-1e-6&&e>1e-6&&console.warn(`Block length ${e} is too small, rendering as ${r}`));let o=null;return e>r+1e-6?(o=this.split(this.start+r,t),this.length!==r&&(console.warn(`Adjusting block length after split from ${this.length} to ${r}`),this.length=r)):this.length=r,o}mergeToMap(t){const e=t.get(this.start);e?(this.notes.forEach((t=>e.addNote(t))),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)}isMeasureBeginning(){return n(this.measureNumber-Math.floor(this.measureNumber))}}},775:(t,e,i)=>{i.d(e,{MeasuresInfo:()=>r});var s=i(830),n=i(559);class r{measuresInfo;allowDottedRests=!0;constructor(t,e){this.measuresInfo=[];let i=0,r=0,o=0,a=t.tempos[0],h=t.keySignatures[0],l=t.timeSignatures[0],u=1,c=(0,s.getMeasureLength)(l),d=l.start;const m=n.MIN_RESOLUTION;for(let n=0;n<e;n+=m){const e={start:n,measureNumber:u+(n-d)/c,measureLength:c,tempo:a,keySignature:h,timeSignature:l};if(i<t.tempos.length&&Math.abs(t.tempos[i].start-n)<m/2&&(a=t.tempos[i++],e.tempo=a,e.tempoChange=!0),r<t.keySignatures.length&&Math.abs(t.keySignatures[r].start-n)<m/2&&(h=t.keySignatures[r++],e.keySignature=h,e.keyChange=!0),o<t.timeSignatures.length&&Math.abs(t.timeSignatures[o].start-n)<m/2){u+=(t.timeSignatures[o].start-d)/c,u=Math.round(1e3*u)/1e3,l=t.timeSignatures[o++],e.timeSignature=l,c=(0,s.getMeasureLength)(l),e.measureLength=c,e.measureNumber=u,e.timeChange=!0,d=e.start}this.measuresInfo.push(e)}}findIndex(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/n.MIN_RESOLUTION)))}measureNumberAtQ(t){if(0===this.measuresInfo.length)return 1;const e=this.findIndex(t),i=this.measuresInfo[e],s=(t-i.start)/i.measureLength;return i.measureNumber+s+1e-9}measureLengthAtQ(t){if(0===this.measuresInfo.length)return(0,s.getMeasureLength)(s.DEFAULT_TIME_SIGNATURE);const e=this.findIndex(t);return this.measuresInfo[e].measureLength}tempoAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TEMPO.qpm;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.tempoChange&&o?r.tempo.qpm:-1}keySignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_KEY_SIGNATURE.key;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.keyChange&&o?r.keySignature.key:-1}timeSignatureAtQ(t,e=!1){if(0===this.measuresInfo.length)return s.DEFAULT_TIME_SIGNATURE;const i=this.findIndex(t),r=this.measuresInfo[i],o=Math.abs(r.start-t)<n.MIN_RESOLUTION/2;return!e||r.timeChange&&o?r.timeSignature:null}quartersToTime(t,e){const i=this.tempoAtQ(e);return i<=0?0:t/i*60}timeToQuarters(t,e){const i=this.tempoAtQ(e);if(i<=0)return 0;const s=t*i/60;return Math.round(s*n.MAX_QUARTER_DIVISION)/n.MAX_QUARTER_DIVISION}isBeatStart(t){if(0===this.measuresInfo.length)return!1;const e=this.findIndex(t),i=this.measuresInfo[e],s=i.timeSignature,r=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/s.denominator);return Math.abs(r-Math.round(r))<n.MIN_RESOLUTION/2}}},830:(t,e,i)=>{i.d(e,{DEFAULT_KEY_SIGNATURE:()=>n,DEFAULT_TEMPO:()=>s,DEFAULT_TIME_SIGNATURE:()=>r,getMeasureLength:()=>o});const s={start:0,qpm:60},n={start:0,key:0},r={start:0,numerator:4,denominator:4};function o(t){return t.numerator*(4/t.denominator)}},849:(t,e,i)=>{i.d(e,{JianpuModel:()=>a,mapMidiToJianpu:()=>h});var s=i(830),n=i(775),r=i(765),o=i(559);class a{jianpuInfo;measuresInfo;jianpuBlockMap;lastQ;constructor(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}isLastMeasureAtQ(t){return t>=this.lastQ-1e-6}getTotalDuration(){return this.lastQ}update(t,e){this.jianpuInfo=t,t.notes.sort(((t,e)=>t.start-e.start)),this.lastQ=0,t.notes.forEach((t=>{this.lastQ=Math.max(this.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[s.DEFAULT_TEMPO],t.tempos.sort(((t,e)=>t.start-e.start)),t.tempos[0].start>1e-6&&t.tempos.unshift({...s.DEFAULT_TEMPO,start:0});const i=void 0!==e?{start:0,key:e}:{...s.DEFAULT_KEY_SIGNATURE};t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[i],t.keySignatures.sort(((t,e)=>t.start-e.start)),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift({...i,start:0}),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[s.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort(((t,e)=>t.start-e.start)),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift({...s.DEFAULT_TIME_SIGNATURE,start:0}),this.measuresInfo=new n.MeasuresInfo(t,this.lastQ),this.infoToBlocks()}infoToBlocks(){const t=new Map;let e=0;if(this.jianpuInfo.notes.forEach((i=>{const s=i.start,n=this.measuresInfo.measureNumberAtQ(s);if(s>e+1e-6){const i=e,n=s-i,o=this.measuresInfo.measureNumberAtQ(i),a=new r.JianpuBlock(i,n,[],o);t.set(i,a)}const o=this.measuresInfo.keySignatureAtQ(s),a=this.createJianpuNote(i,o);let h=t.get(s);h||(h=new r.JianpuBlock(s,0,[],n),t.set(s,h)),h.addNote(a),e=Math.max(e,s+h.length)})),this.lastQ>e+1e-6){const i=e,s=this.lastQ-i;if(s>1e-6){const e=this.measuresInfo.measureNumberAtQ(i),n=new r.JianpuBlock(i,s,[],e);t.set(i,n)}}this.jianpuBlockMap=new Map;const i=Array.from(t.keys()).sort(((t,e)=>t-e));let s=[];i.forEach((e=>{s.push(t.get(e))}));const n=new Set;for(;s.length>0;){let t=s.shift();n.has(t.start)&&this.jianpuBlockMap.has(t.start);let e=t.splitToBeat(this.measuresInfo);if(e){t.mergeToMap(this.jianpuBlockMap),n.add(t.start),s.unshift(e);continue}let i=t,r=null;do{r=i.splitToStandardSymbol(this.measuresInfo),i.mergeToMap(this.jianpuBlockMap),n.add(i.start),r&&(i=r)}while(r)}this.jianpuBlockMap.forEach((t=>{t.calculateRenderProperties(this.measuresInfo)}))}createJianpuNote(t,e){const i=h(t.pitch,e);return{...t,jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental}}}function h(t,e){const i=e%12;let s=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(s-=12);const n=(t-(s+12*Math.round((t-s)/12))+12)%12;let r=o.MAJOR_SCALE_INTERVALS[n],a=0;if(void 0===r){switch(n){case 1:r=o.MAJOR_SCALE_INTERVALS[0],a=1;break;case 3:r=o.MAJOR_SCALE_INTERVALS[4],a=2;break;case 6:r=o.MAJOR_SCALE_INTERVALS[5],a=1;break;case 8:r=o.MAJOR_SCALE_INTERVALS[9],a=2;break;case 10:r=o.MAJOR_SCALE_INTERVALS[11],a=2;break;default:{console.warn(`Unexpected chromatic interval ${n} in mapMidiToJianpu. Defaulting to sharp of lower valid degree.`);const i=(n-1+12)%12,s=(n+1+12)%12,h=o.MAJOR_SCALE_INTERVALS[i],l=o.MAJOR_SCALE_INTERVALS[s];void 0!==h?(r=h,a=1):void 0!==l?(r=l,a=2):(r=1,a=1,console.error(`Could not determine Jianpu number components for MIDI ${t}, interval ${n} from tonic in key ${e}.`));break}}void 0===r&&(console.error(`Jianpu number became undefined for MIDI ${t} (interval ${n}, key ${e}) after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.`),r=1,a=1)}return{jianpuNumber:r,octaveDot:Math.floor((t-s)/12),accidental:a}}},961:(t,e,i)=>{i.d(e,{ACCIDENTAL_TEXT:()=>n,PATH_SCALE:()=>s,augmentationDashPath:()=>a,barPath:()=>r,dotPath:()=>l,tiePath:()=>h,underlinePath:()=>o});const s=100,n=["","#","b"],r="m 0,-50 v 100",o="m 0,0 h 100",a="m 0,0 h 50",h="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",l="M 0 0 a 15 15 0 1 0 0.0001 0 z"}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s);var n=i(644);return window.jr=n,s})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jianpurender",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Render music score using SVG on browsers.",
|
|
5
5
|
"main": "node/index.js",
|
|
6
6
|
"module": "es6/index.js",
|
|
@@ -54,5 +54,12 @@
|
|
|
54
54
|
"repository": {
|
|
55
55
|
"type": "git",
|
|
56
56
|
"url": "https://github.com/flufy3d/jianpurender.git"
|
|
57
|
-
}
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"jianpu",
|
|
60
|
+
"music",
|
|
61
|
+
"notation",
|
|
62
|
+
"music-score",
|
|
63
|
+
"typescript"
|
|
64
|
+
]
|
|
58
65
|
}
|