chordsheetjs 15.3.0 → 15.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundle.js +4 -1
- package/lib/bundle.min.js +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/main.d.ts +4 -1
- package/lib/main.d.ts.map +1 -1
- package/lib/module.js +4 -1
- package/lib/module.js.map +1 -1
- package/lib/pdf/index.js +4 -1
- package/lib/pdf/index.js.map +1 -1
- package/lib/pdf/main.d.ts +3 -0
- package/lib/pdf/main.d.ts.map +1 -1
- package/lib/pdf/module.js +4 -1
- package/lib/pdf/module.js.map +1 -1
- package/package.json +1 -1
package/lib/bundle.js
CHANGED
|
@@ -6279,6 +6279,9 @@ ${error.stack}`);
|
|
|
6279
6279
|
* @param {boolean} [configuration.useUnicodeModifiers=false] Whether or not to use unicode flat and sharp
|
|
6280
6280
|
* symbols.
|
|
6281
6281
|
* @param {boolean} [configuration.normalizeChords=true] Whether or not to automatically normalize chords
|
|
6282
|
+
* @param {boolean} [configuration.normalizeChordSuffix=true] Whether to normalize chord suffixes (e.g.
|
|
6283
|
+
* `sus2` to `2`, `maj7` to `ma7`). Only takes effect when `normalizeChords` is `true`. Defaults to `false`
|
|
6284
|
+
* for {@link ChordProFormatter} so ChordPro round-trips preserve the user's suffix variant.
|
|
6282
6285
|
*/
|
|
6283
6286
|
constructor(configuration = {}) {
|
|
6284
6287
|
const defaultConfig = this.getDefaultConfiguration();
|
|
@@ -29615,7 +29618,7 @@ ${template}
|
|
|
29615
29618
|
}
|
|
29616
29619
|
};
|
|
29617
29620
|
var $a5a21ced491ea51f$export$2e2bcd8739ae039 = $a5a21ced491ea51f$var$UltimateGuitarParser;
|
|
29618
|
-
var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.3.
|
|
29621
|
+
var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.3.1";
|
|
29619
29622
|
var $2a7926da41d163b3$export$191a710ad3c9a989 = {
|
|
29620
29623
|
configure: $181068e44290b873$export$8d21e34596265fa2,
|
|
29621
29624
|
getDefaultConfig: $fe1d3ba9df1ecad5$export$ed30944e0fe6ae5c,
|
package/lib/bundle.min.js
CHANGED
|
@@ -227,4 +227,4 @@ Or set the song key before changing key:
|
|
|
227
227
|
|
|
228
228
|
${r}
|
|
229
229
|
|
|
230
|
-
: ${a.message}`,{cause:a})}}calculateX(r,e=0,a=0){switch(r){case"center":return this.backend.pageSize.width/2-e/2+a;case"right":return this.backend.pageSize.width-this.context.margins.right-e+a;default:return typeof r=="number"?this.context.margins.left+r+a:this.context.margins.left+a}}getAvailableWidth(){return this.backend.pageSize.width-this.context.margins.left-this.context.margins.right}},Nj=Cf,Af=class{constructor(r){this.startTime=0,this.renderTime=0,this.x=0,this.y=0,this.currentColumn=1,this.elements=[],this.currentPage=1,this.song=r,this.startTime=performance.now()}initialize(){this.x=this.getMinX(),this.y=this.getMinY(),this.currentColumn=1,this.currentPage=1,this.elements=[],this.initializeBackend()}render(r,e){this.initialize(),this.renderParagraphs(r),this.renderChordDiagrams(),this.renderHeadersAndFooters(),this.finalizeRendering(),this.recordRenderingTime()}getContentBottomY(){return this.getColumnBottomY()}getRenderTime(){return this.renderTime}renderParagraphs(r){r.forEach(e=>{e.units.forEach(a=>{this.renderLines(a)}),e.addSpacing&&(this.y+=this.getParagraphSpacing())})}renderLines(r){r.forEach(e=>{this.renderLineLayout(e)})}renderLineLayout(r){let{items:e,lineHeight:a,line:l}=r;if(this.hasColumnBreak(r)){this.moveToNextColumn();return}this.y+a>this.getColumnBottomY()&&this.moveToNextColumn();let u=this.y,{chordsYOffset:d,lyricsYOffset:x}=this.calculateChordLyricYOffsets(e,u),M=this.x;e.forEach(D=>{let{item:w,width:R}=D;this.renderItem(w,l,M,d,x,e,u),M+=R}),this.y+=a,this.x=this.getColumnStartX()}hasColumnBreak(r){let{items:e}=r;return e.length===1&&e[0].item instanceof X&&Xf(e[0].item)}renderItem(r,e,a,l,u,d,x){r instanceof J?this.renderChordLyricsPair(r,e,a,l,u,d):r instanceof X?r.isSectionDelimiter()?this.addSectionLabel(r.label,a,x):ls(r)&&this.addComment(r.value,a,x):r instanceof pe&&this.addTextElement(r.content,a,u,"lyrics")}renderChordLyricsPair(r,e,a,l,u,d){let{chords:x}=r,{lyrics:M}=r;if(x&&(x=this.processChords(x,e)),!this.isLyricsOnly()&&x){let D=this.calculateChordBaseline(l,d,x);this.addTextElement(x,a,D,"chord")}M&&M.trim()!==""&&this.addTextElement(M,a,u,"lyrics")}moveToNextColumn(){this.currentColumn+=1,this.currentColumn>this.getColumnCount()&&(this.startNewPage(),this.currentColumn=1),this.x=this.getColumnStartX(),this.y=this.getMinY()}startNewPage(){this.currentPage+=1,this.createNewPage()}calculateChordLyricYOffsets(r,e){let a=r.some(({item:M})=>M instanceof J&&M.chords),l=r.some(({item:M})=>M instanceof J&&M.hasLyrics()),u=e,d=e,x=this.getChordLyricSpacing();return a&&l?(u=e,d=u+this.getMaxChordHeight(r)+x):a&&!l?u=e:!a&&l&&(d=e),{chordsYOffset:u,lyricsYOffset:d}}getMaxChordHeight(r){return r.reduce((e,{chordHeight:a})=>Math.max(e,a||0),0)}processChords(r,e){return et(r,e,this.song,{renderKey:null,useUnicodeModifier:this.useUnicodeModifiers(),normalizeChords:this.normalizeChords(),decapo:this.getConfiguration().decapo})}addTextElement(r,e,a,l){let u=this.getFontForType(l),{width:d,height:x}=this.measureText(r,u);this.elements.push({x:e,y:a,width:d,height:x,content:r,type:l,style:u,page:this.currentPage,column:this.currentColumn})}addSectionLabel(r,e,a){this.addTextElement(r,e,a,"sectionLabel")}addComment(r,e,a){this.addTextElement(r,e,a,"comment")}getFontForType(r){switch(r){case"chord":return this.getFontConfiguration("chord");case"lyrics":return this.getFontConfiguration("text");case"sectionLabel":return this.getFontConfiguration("sectionLabel");case"comment":return this.getFontConfiguration("comment");default:return this.getFontConfiguration("text")}}getTotalPages(){return this.currentPage}getColumnStartX(){let r=this.getLeftMargin(),e=this.getColumnWidth(),a=this.getColumnSpacing();return r+(this.currentColumn-1)*(e+a)}getColumnBottomY(){return this.getPageHeight()-this.getBottomMargin()-this.getFooterHeight()}getColumnWidth(){let r=this.getPageWidth()-this.getLeftMargin()-this.getRightMargin(),e=this.getColumnCount(),a=this.getColumnSpacing();return(r-(e-1)*a)/e}getMinX(){return this.getLeftMargin()}getMinY(){return this.getTopMargin()+this.getHeaderHeight()}recordRenderingTime(){let r=performance.now();this.renderTime=(r-this.startTime)/1e3}getElementsForPage(r){return this.elements.filter(e=>e.page===r)}getLayout(){return this.getConfiguration().layout}getHeaderConfig(){return this.getLayout().header}getFooterConfig(){return this.getLayout().footer}getPageWidth(){return this.getDocPageSize().width}getPageHeight(){return this.getDocPageSize().height}getLeftMargin(){return this.dimensions.margins.left}getRightMargin(){return this.dimensions.margins.right}getTopMargin(){return this.dimensions.margins.top}getBottomMargin(){return this.dimensions.margins.bottom}getHeaderHeight(){return this.getHeaderConfig()?.height??0}getFooterHeight(){return this.getFooterConfig()?.height??0}getColumnCount(){return this.dimensions.effectiveColumnCount}getSectionsConfig(){let{sections:r}=this.getLayout();if(!r)throw new Error("Configuration must include sections");return r}getColumnSpacing(){return this.getSectionsConfig().global.columnSpacing}getChordLyricSpacing(){return this.getSectionsConfig().global.chordLyricSpacing}getParagraphSpacing(){return this.getSectionsConfig().global.paragraphSpacing||0}useUnicodeModifiers(){return this.getConfiguration().useUnicodeModifiers}normalizeChords(){return this.getConfiguration().normalizeChords}isLyricsOnly(){return!!this.getSectionsConfig()?.base?.display?.lyricsOnly}},Rj=Af,Sf=class extends Rj{constructor(r,e,a){if(super(r),this.currentLayoutFontStyle=null,this.currentLayoutSection=null,this.currentLayoutTextItem=null,this.currentLineStyle=null,this._dimensions=null,this._dimensionCacheKey=null,this.container=e,this.configuration=a,this.styler=new Bj({cssClassPrefix:a.cssClassPrefix,cssClasses:a.cssClasses}),!e)throw new Error("Container element is required");this.doc=new Pj(e,{width:this.configuration.pageSize.width,height:this.configuration.pageSize.height})}getFontConfiguration(r){return this.configuration.fonts[r]}getDocumentMetadata(){return{pageWidth:this.getPageWidth(),pageHeight:this.getPageHeight(),marginLeft:this.getLeftMargin(),marginRight:this.getRightMargin(),marginTop:this.getTopMargin(),marginBottom:this.getBottomMargin(),columnWidth:this.getColumnWidth(),columnCount:this.getColumnCount(),currentPage:this.doc.currentPage,totalPages:this.doc.totalPages,renderTime:this.renderTime,dimensions:this.dimensions}}getDoc(){return this.doc}getHTML(){return this.container}dispose(){this.doc&&this.doc.dispose()}initializeBackend(){if(this.configuration.additionalCss){let r=document.createElement("style");r.textContent=this.configuration.additionalCss,document.head.appendChild(r)}}createNewPage(){this.doc.newPage()}renderChordDiagrams(){console.log("Chord diagram rendering is stubbed out")}renderHeadersAndFooters(){let r=this.getHeaderConfig(),e=this.getFooterConfig();r&&this.renderLayoutForEachPage(r,"header"),e&&this.renderLayoutForEachPage(e,"footer"),this.resetLayoutRenderingState()}renderLayoutForEachPage(r,e){this.doc.eachPage((a,l)=>{this.currentLayoutSection=e,this.resetLayoutRenderingState(e),this.createLayoutRenderer(l+1,this.doc.totalPages).renderLayout(r,e)})}resetLayoutRenderingState(r=null){this.currentLayoutSection=r,this.currentLayoutFontStyle=null,this.currentLayoutTextItem=null,this.currentLineStyle=null}createLayoutRenderer(r,e){let a=this.createLayoutBackend(r,e);return new Nj(a,{metadata:this.song.metadata,margins:this.dimensions.margins,extraMetadata:this.getExtraMetadata(r,e)})}createLayoutBackend(r,e){return{pageSize:this.doc.pageSize,currentPage:r,totalPages:e,text:(a,l,u)=>this.renderHtmlText(a,l,u),getTextWidth:(a,l)=>this.doc.getTextWidth(a,l),splitTextToSize:(a,l,u)=>this.doc.splitTextToSize(a,l,u),setFontStyle:a=>{this.currentLayoutFontStyle=a},setTextItem:a=>{this.currentLayoutTextItem=a},addElement:(a,l,u)=>this.doc.addElement(a,l,u),addImage:(a,l,u,d,x,M)=>this.renderHtmlImage(a,u,d,x,M),line:(a,l,u,d)=>this.renderHtmlLine(a,l,u,d),setLineStyle:a=>{this.currentLineStyle=a},resetDash:()=>{}}}renderHtmlText(r,e,a){let l=document.createElement("div");l.className=`${this.styler.prefix}header-text`,this.applyLayoutTextClasses(l),l.textContent=r,this.applyLayoutTextStyles(l),this.doc.addElement(l,e,a)}applyLayoutTextClasses(r){let e=this.currentLayoutSection?this.styler.getCustomClass(this.currentLayoutSection):void 0;e&&r.classList.add(e),this.currentLayoutTextItem?.cssClass&&r.classList.add(this.currentLayoutTextItem.cssClass)}applyLayoutTextStyles(r){this.currentLayoutTextItem?.elementStyle&&Object.assign(r.style,this.currentLayoutTextItem.elementStyle),this.currentLayoutFontStyle&&this.styler.applyFontStyle(r,this.currentLayoutFontStyle)}renderHtmlImage(r,e,a,l,u){let d=document.createElement("img");d.className=`${this.styler.prefix}image`,d.src=r,d.style.width=`${l}px`,d.style.height=`${u}px`,this.doc.addElement(d,e,a)}renderHtmlLine(r,e,a,l){let u=document.createElement("div");u.className=`${this.styler.prefix}line`;let d=this.currentLineStyle;u.style.width=`${a-r}px`,u.style.height="0",u.style.borderBottomWidth=`${d?.width??1}px`,u.style.borderBottomStyle=d?.dash?.length?"dashed":"solid",u.style.borderBottomColor=d?.color??"#000000",this.doc.addElement(u,r,e)}renderParagraphs(r){r.forEach((e,a)=>{this.renderParagraph(e,a,r)})}renderParagraph(r,e,a){let l=[],u=this.elements;this.elements=l,r.units.forEach(x=>{this.renderLineItems(x)});let d=this.groupElementsByPageAndColumn(l);Object.values(d).forEach((x,M)=>{this.renderElementGroup(x,e,M,r)}),r.addSpacing&&e<a.length-1&&(this.y+=this.getParagraphSpacing()),this.x=this.getColumnStartX(),this.elements=u}groupElementsByPageAndColumn(r){let e={};return r.forEach(a=>{let l=`${a.page}-${a.column}`;e[l]||(e[l]=[]),e[l].push(a)}),e}renderLineItems(r){let e={column:this.currentColumn,page:this.currentPage};r.forEach(a=>{e=this.renderSingleLine(a,e)})}renderSingleLine(r,e){if(this.hasColumnBreak(r))return this.moveToNextColumn(),this.getCurrentContext();let a=this.handleColumnOverflow(r.lineHeight,e);return this.renderLineContent(r,a),a}getCurrentContext(){return{column:this.currentColumn,page:this.currentPage}}handleColumnOverflow(r,e){return this.y+r>this.getColumnBottomY()?(this.moveToNextColumn(),this.getCurrentContext()):e}renderLineContent(r,e){let{items:a,lineHeight:l,line:u}=r,d=this.y,{chordsYOffset:x,lyricsYOffset:M}=this.calculateChordLyricYOffsets(a,d),D=this.x;a.forEach(w=>{this.renderMeasuredItem(w,D,d,x,M,a,u,e),D+=w.width}),this.y+=l,this.x=this.getColumnStartX()}renderMeasuredItem(r,e,a,l,u,d,x,M){let{item:D}=r;D instanceof J?this.renderChordLyricsPairItem(D,e,l,u,d,x,M):D instanceof X?this.renderTagItem(D,e,a,M):D instanceof pe&&(this.addTextElement(D.content,e,u,"lyrics"),this.updatePosition(M.column,M.page))}renderChordLyricsPairItem(r,e,a,l,u,d,x){let{chords:M}=r,{lyrics:D}=r;if(M&&(M=this.processChords(M,d)),!this.isLyricsOnly()&&M){let w=this.calculateChordBaseline(a,u,M);this.addTextElement(M,e,w,"chord"),this.updatePosition(x.column,x.page)}D&&D.trim()!==""&&(this.addTextElement(D,e,l,"lyrics"),this.updatePosition(x.column,x.page))}renderTagItem(r,e,a,l){let u=r.attributes.__titleSeparator==="true";r.isSectionDelimiter()?(this.addSectionLabel(r.label,e,a,{noUnderline:u}),this.updatePosition(l.column,l.page)):ls(r)&&(this.addComment(r.value,e,a,{noUnderline:u}),this.updatePosition(l.column,l.page))}updatePosition(r,e){let a=this.elements[this.elements.length-1];a.column=r,a.page=e}addSectionLabel(r,e,a,l={}){this.addTextElementWithOptions(r,e,a,"sectionLabel",l)}addComment(r,e,a,l={}){this.addTextElementWithOptions(r,e,a,"comment",l)}addTextElementWithOptions(r,e,a,l,u={}){let d=this.getFontForType(l),{width:x,height:M}=this.measureText(r,d),D=u.noUnderline?{...d,underline:!1}:d;this.elements.push({x:e,y:a,width:x,height:M,content:r,type:l,style:D,page:this.currentPage,column:this.currentColumn})}measureText(r,e){let{w:a,h:l}=this.doc.getTextDimensions(r,e);return{width:a,height:l}}calculateChordBaseline(r,e,a){let l=this.getFontConfiguration("chord"),{height:u}=this.measureText(a,l);return r+this.getMaxChordHeight(e)-u}finalizeRendering(){let r=Math.max(this.currentPage,this.doc.totalPages);for(;this.doc.totalPages<r;)this.doc.createPage();for(let e=1;e<=r;e+=1){let a=this.getElementsForPage(e);a.length>0&&(this.doc.setPage(e),a.forEach(l=>{this.drawElement(l)}))}}getConfiguration(){return this.configuration}get dimensions(){let r=this.generateDimensionCacheKey();return(this._dimensionCacheKey!==r||this._dimensions===null)&&(this._dimensions=this.buildDimensions(),this._dimensionCacheKey=r),this._dimensions}getDocPageSize(){return this.doc.pageSize}calculateBounds(r){let e=Number.MAX_VALUE,a=Number.MAX_VALUE,l=Number.MIN_VALUE,u=Number.MIN_VALUE;return r.forEach(d=>{e=Math.min(e,d.x),a=Math.min(a,d.y),l=Math.max(l,d.x+d.width),u=Math.max(u,d.y+d.height)}),{minX:e,minY:a,maxX:l,maxY:u}}createParagraphDiv(r,e){let a=r.maxX-r.minX,l=r.maxY-r.minY,u=document.createElement("div");return u.className=this.styler.createClassName(...e),Object.assign(u.style,{position:"absolute",left:`${r.minX}px`,top:`${r.minY}px`,width:`${a}px`,height:`${l}px`}),u}createElementGroupDiv(r,e,a,l){let u=document.createElement("div");return u.className=this.styler.createClassName(...l),Object.assign(u.style,{position:"absolute",left:`${r}px`,top:`${e}px`}),u.textContent=a,u}renderElementGroup(r,e,a,l){let{page:u}=r[0];this.doc.setPage(u);let d=this.calculateBounds(r),{prefix:x}=this.styler,M=this.createParagraphDiv(d,[`${x}paragraph`,`paragraph-${e}-${a}`,`${x}${l.sectionType}`]);r.forEach(D=>{this.renderElement(D,d,M)}),this.doc.addElement(M,d.minX,d.minY)}renderElement(r,e,a){let{prefix:l}=this.styler,u=this.createElementGroupDiv(r.x-e.minX,r.y-e.minY,r.content,[`${l}element ${l}${r.type}`,this.styler.getCustomClass(r.type)]);this.styler.applyElementStyle(u,r),a.appendChild(u)}drawElement(r){switch(r.type){case"chord":case"lyrics":case"sectionLabel":case"comment":this.drawTextElement(r);break;default:console.warn(`Unknown element type: ${r.type}`);break}}drawTextElement(r){let e=document.createElement("div"),{prefix:a}=this.styler;e.className=`${a}element ${a}${r.type}`;let l=this.styler.getCustomClass(r.type);l&&e.classList.add(l),e.textContent=r.content,r.style&&this.styler.applyElementStyle(e,r),this.doc.addElement(e,r.x,r.y)}buildDimensions(){let{width:r,height:e}=this.doc.pageSize,{columnCount:a,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d}=this.configuration.layout.sections.global;return new jj(r,e,this.configuration.layout,{columnCount:a,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d})}generateDimensionCacheKey(){let{width:r,height:e}=this.doc.pageSize,{layout:a}=this.configuration,{global:l}=a.sections;return[r,e,a.global.margins.left,a.global.margins.right,a.global.margins.top,a.global.margins.bottom,a.header?.height||0,l.columnCount,l.columnSpacing,l.minColumnWidth||0,l.maxColumnWidth||0].join("-")}getExtraMetadata(r,e){let a={page:r.toString(),pages:e.toString(),renderTime:this.renderTime.toString()},l=this.song.metadata.getSingle("capo"),u=this.song.metadata.getSingle("key");if(l&&u){let d=parseInt(l,10);a.capoKey=x7(u)[d]}return a}},zj=Sf,Lf=class{constructor(r,e,a){this.measurer=r,this.config=e,this.song=a}measureLineItems(r,e=!1){let a=[];for(let l=0;l<r.items.length;l+=1){let u=r.items[l],d=r.items[l+1]??null;if(Xs(u)){let x=this.processChordLyricsPair(u,d,r,e);a.push(...x)}else if(G7(u))a.push(this.processSoftLineBreak(u));else if(Zs(u)){let x=this.processTag(u);a.push(...x)}else a.push({item:null,width:0})}return a}processChordLyricsPair(r,e,a,l=!1){let u=this.handleLyricsOnlyMode(r,e,l);if(u)return u;let d=this.splitChordLyricsPair(r,l);return this.processSplitItems(d,e,a,l)}handleLyricsOnlyMode(r,e,a){if(!a)return null;let l=this.removeHyphens(r.lyrics||"");return this.cleanNextItemHyphens(e,()=>{l=l.trimEnd()}),l===""?[{item:null,width:0}]:null}cleanNextItemHyphens(r,e){if(!r||!Xs(r))return;let a=r,l=a.lyrics||"";(l.startsWith(" -")||l.startsWith("-"))&&(e(),a.lyrics=this.removeHyphens(l))}processSplitItems(r,e,a,l){return r.map(u=>this.processSingleSplitItem(u,e,a,l)).filter(u=>u!==null)}processSingleSplitItem(r,e,a,l){return r instanceof pe?this.processSoftLineBreak(r):r instanceof J?this.measureChordLyricsPair(r,e,a,l):null}measureChordLyricsPair(r,e,a,l){let{chords:u,lyrics:d}=this.getAdjustedChordsAndLyrics(r,l);if(l&&d==="")return{item:null,width:0};let x=this.renderChordText(u,a),M=this.calculateMeasurements(x,d,e,l);return{item:new J(u,d),width:M.totalWidth,chordHeight:M.chordHeight}}getAdjustedChordsAndLyrics(r,e){return e?{chords:"",lyrics:this.removeHyphens(r.lyrics||"")}:{chords:r.chords||"",lyrics:r.lyrics||""}}renderChordText(r,e){return et(r,e,this.song,{renderKey:null,useUnicodeModifier:this.config.useUnicodeModifiers,normalizeChords:this.config.normalizeChords,normalizeChordSuffix:this.config.normalizeChordSuffix,decapo:this.config.decapo})}calculateMeasurements(r,e,a,l){let u=this.config.fonts.chord,d=this.config.fonts.lyrics,x=r?this.measurer.measureTextWidth(r,u):0,M=e?this.measurer.measureTextWidth(e,d):0,D=this.getAdjustedChordWidth(x,M,r,a,l);return{totalWidth:Math.max(D,M),chordHeight:r?this.measurer.measureTextHeight(r,u):0}}getAdjustedChordWidth(r,e,a,l,u){let d=l&&Xs(l)&&l.chords?.trim()!=="",x=this.getSpaceWidth(this.config.fonts.lyrics);if(!u&&d&&r>=e-x){let D=this.getChordSpacingAsSpaces();return this.measurer.measureTextWidth(a+D,this.config.fonts.chord)}return r}processSoftLineBreak(r){let e=this.measurer.measureTextWidth(r.content,this.config.fonts.lyrics);return{item:r,width:e}}processTag(r){let e=[];if(ls(r)||r.isSectionDelimiter()){let a=ls(r)?this.config.fonts.comment:this.config.fonts.sectionLabel,l=this.config.width,u=r.label||r.value||"";this.measurer.splitTextToSize(u,l,a).forEach(x=>{let M=this.measurer.measureTextWidth(x,a);e.push(this.createMeasuredTagItem(r,x,M))})}else e.push({item:r,width:0});return e}createMeasuredTagItem(r,e,a){let l=new X(r.name,e);return r.attributes.__titleSeparator==="true"&&(l._value=" > ",l.attributes.__titleSeparator="true",Object.defineProperty(l,"value",{configurable:!0,get:()=>" > ",set:u=>{l._value=u}})),{item:l,width:a}}splitMeasuredItem(r,e){if(!(r.item instanceof J)||!r.item.lyrics)return[r,null];let{lyrics:a}=r.item,l=this.config.fonts.lyrics,u=this.measurer.splitTextToSize(a,e,l);if(u.length===1)return[r,null];let d=u[0],x=u.slice(1).join(" ");return[{item:new J(r.item.chords,d),width:this.measurer.measureTextWidth(d,l),chordHeight:r.chordHeight},{item:new J("",x),width:this.measurer.measureTextWidth(x,l),chordHeight:0}]}removeHyphens(r){let e=r.replace(/\b(\w+)\s*-\s*(\w+)\b/g,"$1$2");return e=e.replace(/(?:\b(\w+)\s*-\s*$)|(?:-\s*$)|(?:\s+-\s+$)/g,"$1"),/^\s*-\s*$/.test(e)?"":e}splitChordLyricsPair(r,e=!1){let{chords:a,lyrics:l,annotation:u}=r;if(!l||l.trim()==="")return[r];let d=l.split(/,\s*/),x=[];return d.forEach((M,D)=>{if(D>0&&D!==0&&(x.push(new pe(" ")),M.trim()!=="")){let w=e?M.trimStart():M;x.push(new J("",w,""))}if(D===0&&d.length===1)x.push(new J(a,M,u));else if(D===0&&d.length>1){let w=M;w+=",",x.push(new J(a,w,u))}}),x}findNextItemWithLyrics(r,e,a){return[...r,...e.slice(a)].find(u=>u.item instanceof J&&u.item.lyrics?.trim())||null}capitalizeFirstWord(r){return r.replace(/^\s*\w/,e=>e.toUpperCase())}getSpaceWidth(r){return this.measurer.measureTextWidth(" ",r)}getChordSpacingAsSpaces(){return" ".repeat(this.config.chordSpacing)}},Ff=class{constructor(r){this.config=r}createLineLayout(r,e){let a=this.analyzeLineContent(r),l=this.determineLineType(a),u=Math.max(...r.map(x=>x.chordHeight||0)),d=this.calculateLineHeight(a,u);return{type:l,items:r,lineHeight:d,line:e}}analyzeLineContent(r){return{hasChords:r.some(e=>e.item instanceof J&&e.item.chords),hasLyrics:r.some(e=>e.item instanceof J&&e.item.lyrics?.trim()),hasComments:r.some(e=>e.item instanceof X&&ls(e.item)),hasSectionLabel:r.some(e=>e.item instanceof X&&e.item.isSectionDelimiter()),hasTag:r.some(e=>e.item instanceof X)}}determineLineType(r){return r.hasChords||r.hasLyrics?"ChordLyricsPair":r.hasComments?"Comment":r.hasSectionLabel?"SectionLabel":r.hasTag?"Tag":"Empty"}calculateLineHeight(r,e){let{baseHeight:a,fontConfig:l}=this.getBaseHeightAndFont(r,e),u=l?.lineHeight||1;return a*u}getBaseHeightAndFont(r,e){let a=this.config.linePadding;if(r.hasChords&&r.hasLyrics){let l=this.config.fonts.lyrics;return a+=e+this.config.chordLyricSpacing+l.size,{baseHeight:a,fontConfig:l}}return r.hasChords?{baseHeight:a+e,fontConfig:null}:r.hasLyrics?this.addFontHeight(a,this.config.fonts.lyrics):r.hasComments?this.addFontHeight(a,this.config.fonts.comment):r.hasSectionLabel?this.addFontHeight(a,this.config.fonts.sectionLabel):{baseHeight:a,fontConfig:null}}addFontHeight(r,e){return{baseHeight:r+e.size,fontConfig:e}}createColumnBreakLayout(){return{type:"Tag",line:new Ds,items:[{item:new X("column_break"),width:0}],lineHeight:0}}},Ef=class{constructor(r,e){this.itemProcessor=r,this.layoutFactory=e}breakLineIntoLayouts(r,e,a=!1){let l=this.itemProcessor.measureLineItems(r,a),u=this.consolidateConsecutiveSoftBreaks(l);return this.breakContent(u,e,r)}breakContent(r,e,a){if(r.length===0)return[];let{totalWidth:l,softBreakIndices:u}=this.analyzeContent(r);if(this.shouldReturnSingleLayout(l,e))return[this.layoutFactory.createLineLayout(r,a)];if(u.length===0)return this.handleNoSoftBreaks(r,e,a);let{firstChunk:d,secondChunk:x}=this.splitAtBestSoftBreak(r,u,l);return d.length===0?this.breakContent(x,e,a):[this.layoutFactory.createLineLayout(d,a),...this.breakContent(x,e,a)]}handleNoSoftBreaks(r,e,a){let l=this.findBreakIndex(r,e);if(l===-1)return[this.layoutFactory.createLineLayout(r,a)];if(l===0)return this.handleOversizedFirstItem(r,e,a);let u=r.slice(0,l),d=r.slice(l);return this.removeTrailingComma(u),[this.layoutFactory.createLineLayout(u,a),...this.breakContent(d,e,a)]}consolidateConsecutiveSoftBreaks(r){let e=[];for(let a=0;a<r.length;a+=1){let l=r[a];e.push(l),l.item instanceof pe&&(a=this.skipConsecutiveSoftBreaks(r,a))}return e}skipConsecutiveSoftBreaks(r,e){let a=e;for(;a+1<r.length&&r[a+1].item instanceof pe;)a+=1;return a}findBreakIndex(r,e){let a=0;for(let l=0;l<r.length;l+=1){if(a+r[l].width>e)return l;a+=r[l].width}return-1}handleOversizedFirstItem(r,e,a){let[l,u]=this.itemProcessor.splitMeasuredItem(r[0],e),d=u?[u,...r.slice(1)]:r.slice(1);return[this.layoutFactory.createLineLayout([l],a),...this.breakContent(d,e,a)]}analyzeContent(r){let e=[];return{totalWidth:r.reduce((l,u,d)=>(u.item instanceof pe&&e.push(d),l+u.width),0),softBreakIndices:e}}shouldReturnSingleLayout(r,e){return r<=e}splitAtBestSoftBreak(r,e,a){let l=a/2,d=e.map(D=>({index:D,widthUpToBreak:this.getWidthUpToIndex(r,D)})).reduce((D,w)=>{let R=Math.abs(w.widthUpToBreak-l),k=Math.abs(D.widthUpToBreak-l);return R===k?w.index>D.index?w:D:R<k?w:D}),x=r.slice(0,d.index),M=r.slice(d.index+1);return this.removeTrailingComma(x),this.capitalizeNextItem(M,M,0),{firstChunk:x,secondChunk:M}}removeTrailingComma(r){let e=r[r.length-1];e?.item instanceof J&&e.item.lyrics?.endsWith(",")&&(e.item.lyrics=e.item.lyrics.slice(0,-1)||"",e.width=this.remeasureLyrics(e))}getWidthUpToIndex(r,e){let a=0;for(let l=0;l<e&&l<r.length;l+=1)a+=r[l].width;return a}remeasureLyrics(r){return r.item instanceof J?this.itemProcessor.measurer.measureTextWidth(r.item.lyrics||"",this.itemProcessor.config.fonts.lyrics):r.width}recalculateChordLyricWidth(r,e=null){if(!(r.item instanceof J))return r.width;let a=r.item,l=this.measureChordAndLyricWidths(a),u=this.adjustChordWidth(a,l,e);return Math.max(u,l.lyricsWidth)}measureChordAndLyricWidths(r){let e=this.itemProcessor.config.fonts.chord,a=this.itemProcessor.config.fonts.lyrics,l=r.chords?this.itemProcessor.measurer.measureTextWidth(r.chords,e):0,u=r.lyrics?this.itemProcessor.measurer.measureTextWidth(r.lyrics,a):0;return{chordWidth:l,lyricsWidth:u}}adjustChordWidth(r,e,a){if(this.shouldSkipChordSpacing(e.chordWidth,a))return e.chordWidth;let l=this.itemProcessor.config.fonts.lyrics,u=this.itemProcessor.measurer.measureTextWidth(" ",l);if(e.chordWidth<e.lyricsWidth-u)return e.chordWidth;let d=this.itemProcessor.config.fonts.chord,x=" ".repeat(this.itemProcessor.config.chordSpacing),M=`${r.chords||""}${x}`;return this.itemProcessor.measurer.measureTextWidth(M,d)}shouldSkipChordSpacing(r,e){return this.itemProcessor.config.displayLyricsOnly||r===0||!e||!(e.item instanceof J)?!0:(e.item.chords||"").trim()===""}capitalizeNextItem(r,e,a){let l=this.itemProcessor.findNextItemWithLyrics(r,e,a);if(l&&l.item instanceof J){let u=l.item.lyrics??"";l.item.lyrics=this.itemProcessor.capitalizeFirstWord(u);let d=e.indexOf(l),x=d>=0&&d<e.length-1?e[d+1]:null;l.width=this.recalculateChordLyricWidth(l,x)}}};function ni(){return{type:"Tag",line:new Ds,items:[{item:new X("column_break"),width:0}],lineHeight:0}}function _j(i){return i.reduce((r,e)=>{let a=e.reduce((l,u)=>l+u.lineHeight,0);return r+a},0)}function kj(i){return i.length===1&&i[0].items.length===1&&i[0].items[0].item instanceof X&&Xf(i[0].items[0].item)}var Df=class{constructor(r){this.chordLyricLineCount=r,this.totalChordLyricPairLines=r}splitParagraph(r,e,a,l){let u=this.flattenLineLayouts(r),d=this.trySplitParagraph(r,u,e,l);return d||(e!==a?[[ni()],...r]:r)}trySplitParagraph(r,e,a,l){let u=this.findAcceptableSplits(e),d=this.selectSplit(u,a,l);return d?this.buildSplitResult(r,d.index):null}selectSplit(r,e,a){for(let l=r.length-1;l>=0;l-=1){let u=r[l];if(e+u.heightFirstPart<=a)return u}return null}buildSplitResult(r,e){let{firstPart:a,secondPart:l}=this.partitionLineLayouts(r,e);return[...a,[ni()],...l]}flattenLineLayouts(r){let e=[];return r.forEach(a=>{a.forEach(l=>{e.push(l)})}),e}findAcceptableSplits(r){let e=0,a=0;return r.slice(0,-1).reduce((l,u,d)=>{e+=u.lineHeight,a+=u.type==="ChordLyricsPair"?1:0;let x=this.totalChordLyricPairLines-a;return a>=2&&x>=2&&l.push({index:d+1,heightFirstPart:e}),l},[])}partitionLineLayouts(r,e){let a=r.reduce((l,u)=>this.partitionReducer(l,u,e),{firstPart:[],secondPart:[],processed:0});return{firstPart:a.firstPart,secondPart:a.secondPart}}partitionReducer(r,e,a){let l=e.length,u=r.processed+l<=a,d=r.processed>=a;if(u)r.firstPart.push(e);else if(d)r.secondPart.push(e);else{let x=a-r.processed;r.firstPart.push(e.slice(0,x)),r.secondPart.push(e.slice(x))}return r.processed+=l,r}},wf=class{splitParagraph(r,e,a,l){if(r.length===0)return[];let{splitIndex:u,heightFirstPart:d}=this.findSplitMetadata(r);return u===null?this.prependColumnBreakIfNeeded(r,e,a):e+d<=l?this.buildSplitResult(r,u):this.prependColumnBreakIfNeeded(r,e,a)}findSplitMetadata(r){let e=0,a=0;for(let l=0;l<r.length;l+=1){let{height:u,chordCount:d}=this.summarizeLineLayout(r[l]);if(e+=d,a+=u,e>=2)return{splitIndex:l+1,heightFirstPart:a}}return{splitIndex:null,heightFirstPart:a}}summarizeLineLayout(r){return r.reduce((e,a)=>({height:e.height+a.lineHeight,chordCount:e.chordCount+(a.type==="ChordLyricsPair"?1:0)}),{height:0,chordCount:0})}buildSplitResult(r,e){let a=r.slice(0,e),l=r.slice(e);return a.concat([[ni()]]).concat(l)}prependColumnBreakIfNeeded(r,e,a){return e===a?r:[[ni()]].concat(r)}},Gf=class{splitParagraph(r,e,a,l){let u=[];return e!==a&&u.push([ni()]),u.concat(r)}},Tf=class{splitParagraph(r,e,a,l,u){return this.createStrategy(u).splitParagraph(r,e,a,l)}createStrategy(r){return r<=3?new Gf:r===4?new wf:new Df(r)}},Mf=class i extends X{constructor(){super("comment"," > "),this.attributes.__titleSeparator="true"}get value(){return" > "}set value(r){super.value=r}clone(){let r=new i;return r.attributes={...this.attributes},r.selector=this.selector,r.isNegated=this.isNegated,r}},Oj=Mf,ci=class{constructor(r,e,a){this.song=r,this.measurer=e,this.config=a,this.sectionCache=new Map,this.processRepeatedSections(),this.itemProcessor=new Lf(this.measurer,this.config,this.song),this.layoutFactory=new Ff(a),this.lineBreaker=new Ef(this.itemProcessor,this.layoutFactory),this.paragraphSplitter=new Tf}normalizeSectionLabel(r){return r?r.replace(/\s*\([^)]*(?:x|\d+|repeat|rep)\s*[^)]*\)\s*$/i,"").trim().toLowerCase().replace(/\s+/g,"_"):null}getSectionCacheKey(r){let e=null;return r.label?e=r.label:r.lines.length>0&&(e=this.extractLabelFromFirstItem(r.lines[0].items[0])),this.normalizeSectionLabel(e)??null}extractLabelFromFirstItem(r){if(!r||!Zs(r))return null;let e=r;return!ls(e)&&!e.isSectionDelimiter()?null:e.label||e.value||null}processRepeatedSections(){if(!this.config.repeatedSections)return;this.sectionCache.clear();let r=[],e=new Set,{bodyParagraphs:a}=this.song.clone();a.forEach((l,u)=>{this.processParagraph({paragraph:l,index:u,processedParagraphs:r,skipIndices:e,bodyParagraphs:a})}),this.song.renderParagraphs=r,this.sectionCache.clear()}processParagraph(r){let{paragraph:e,index:a,skipIndices:l,processedParagraphs:u}=r;if(this.shouldSkipParagraphIndex(a,l))return;let d=this.getSectionCacheKey(e);if(!d){this.addUncachedParagraph(u,e);return}this.handleParagraphWithCacheKey(d,r)}shouldSkipParagraphIndex(r,e){return e.has(r)}addUncachedParagraph(r,e){r.push(this.cloneParagraph(e))}handleParagraphWithCacheKey(r,e){let a=this.cloneParagraph(e.paragraph);if(this.cacheFirstOccurrence(r,a,e.processedParagraphs))return;let l=this.sectionCache.get(r);l&&this.handleRepeatedSection({cachedParagraph:l,currentParagraph:a,processedParagraphs:e.processedParagraphs,skipIndices:e.skipIndices,startIndex:e.index,bodyParagraphs:e.bodyParagraphs})}cacheFirstOccurrence(r,e,a){return this.sectionCache.has(r)?!1:(this.sectionCache.set(r,e),a.push(e),!0)}handleRepeatedSection(r){switch(this.config.repeatedSections){case"hide":return;case"title_only":this.handleTitleOnlyMode(r);return;case"lyrics_only":r.processedParagraphs.push(r.currentParagraph);return;case"full":this.handleFullMode(r);return;default:r.processedParagraphs.push(r.currentParagraph)}}handleTitleOnlyMode(r){let e=this.collectTitleParagraphs(r);r.processedParagraphs.push(this.resolveTitleOnlyParagraph(e))}collectTitleParagraphs(r){let{currentParagraph:e,skipIndices:a,startIndex:l,bodyParagraphs:u}=r,d=[this.createTitleOnlyParagraph(e)];for(let x=l+1;x<u.length;x+=1){let M=u[x];if(!a.has(x))if(this.shouldIncludeTitle(M))d.push(this.createTitleOnlyParagraph(M)),a.add(x);else break}return d}shouldIncludeTitle(r){let e=this.getSectionCacheKey(r);return!!(e&&this.sectionCache.has(e))}resolveTitleOnlyParagraph(r){return r.length===1?r[0]:this.consolidateTitles(r)}handleFullMode(r){let{cachedParagraph:e,currentParagraph:a,processedParagraphs:l}=r,u=new Et;this.buildFullModeLines(a,e).forEach(d=>{u.addLine(d)}),l.push(u)}buildFullModeLines(r,e){if(r.lines.length===0)return e.lines.map(u=>u.clone());let a=r.lines[0],l=a.items[0];return l&&Zs(l)?[a.clone(),...e.lines.slice(1).map(u=>u.clone())]:[...r.lines.map(u=>u.clone()),...e.lines.slice(1).map(u=>u.clone())]}consolidateTitles(r){let e=this.cloneParagraph(r[0]);if(e.lines.length===0)return e;let a=e.lines[0];return r.slice(1).forEach(l=>{if(l.lines.length===0)return;let u=l.lines[0];this.addTitleSeparator(a),u.items.forEach(d=>{a.items.push(this.cloneItem(d))})}),e}addTitleSeparator(r){r.items.push(...this.buildTitleSeparatorItems())}buildTitleSeparatorItems(){return[new pe(" "),new Oj,new pe(" ")]}createTitleOnlyParagraph(r){let e=new Et;if(r.lines.length===0)return e;let a=r.lines[0],l=new Ds({type:a.type,items:[]});return a.items.forEach(u=>{Zs(u)&&l.addItem(this.cloneItem(u))}),l.items.length===0&&(l.items=[...a.items.map(u=>this.cloneItem(u))]),e.addLine(l),e}cloneParagraph(r){let e=new Et;return r.lines.forEach(a=>e.addLine(a.clone())),e}cloneItem(r){return r instanceof pe?new pe(r.content):typeof r.clone=="function"?r.clone():r}computeParagraphLayouts(){let r=[],e={currentY:this.config.minY,currentColumn:1};return this.song.renderParagraphs.forEach(a=>{e=this.processParagraphLayout(a,r,e)}),r}processParagraphLayout(r,e,a){let l=this.computeParagraphLayout(r,this.config.columnWidth,this.config.displayLyricsOnly),u=this.computeLineTypeCounts(l);if(this.shouldSkipParagraphLayout(u))return a;let d=this.adjustParagraphLayouts(l,a,u.chordLyricLineCount),x=this.calculateNextSimulationState(d,a);return this.addParagraphLayout(e,r,d),x}computeLineTypeCounts(r){let e=0,a=0;return r.forEach(l=>{l.forEach(u=>{u.type==="ChordLyricsPair"?e+=1:(u.type==="Comment"||u.type==="SectionLabel")&&(a+=1)})}),{chordLyricLineCount:e,nonLyricLineCount:a}}shouldSkipParagraphLayout(r){return!!this.config.displayLyricsOnly&&r.nonLyricLineCount===1&&r.chordLyricLineCount===0}adjustParagraphLayouts(r,e,a){let l=_j(r);return e.currentY+l<=this.config.columnBottomY?r:this.paragraphSplitter.splitParagraph(r,e.currentY,this.config.minY,this.config.columnBottomY,a)}calculateNextSimulationState(r,e){let{currentY:a,currentColumn:l}=e;return r.forEach(u=>{if(kj(u))l+=1,l>(this.config.columnCount||1)&&(l=1),a=this.config.minY;else{let d=u.reduce((x,M)=>x+M.lineHeight,0);a+=d}}),a+=this.config.paragraphSpacing,{currentY:a,currentColumn:l}}addParagraphLayout(r,e,a){r.push({units:a,addSpacing:!0,sectionType:e.type})}computeParagraphLayout(r,e,a=!1){let l=[];return r.lines.forEach(u=>{if(dr(u)){let d=this.lineBreaker.breakLineIntoLayouts(u,e,a);l.push(d)}}),l}},vf=class extends vj{constructor(r){super(),this.song=new ws,this.renderer=null,this.container=r}getDefaultConfiguration(){return h7()}format(r){for(this.song=r;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.renderer=new zj(r,this.container,this.configuration),this.renderer.initialize();let a=this.createLayoutEngine().computeParagraphLayouts();this.renderer.render(a)}createLayoutEngine(){if(!this.renderer)throw new Error("Renderer not initialized");let r=this.renderer.getDocumentMetadata(),{dimensions:e}=r,a={width:e.columnWidth,fonts:{chord:this.configuration.fonts.chord,lyrics:this.configuration.fonts.text,comment:this.configuration.fonts.comment,sectionLabel:this.configuration.fonts.sectionLabel},chordSpacing:this.configuration.layout.sections.global.chordSpacing,chordLyricSpacing:this.configuration.layout.sections.global.chordLyricSpacing,linePadding:this.configuration.layout.sections.global.linePadding,useUnicodeModifiers:this.configuration.useUnicodeModifiers,normalizeChords:this.configuration.normalizeChords,normalizeChordSuffix:this.configuration.normalizeChordSuffix,minY:e.minY,columnWidth:e.columnWidth,columnCount:this.configuration.layout.sections.global.columnCount,columnSpacing:this.configuration.layout.sections.global.columnSpacing,minColumnWidth:this.configuration.layout.sections.global.minColumnWidth,maxColumnWidth:this.configuration.layout.sections.global.maxColumnWidth,paragraphSpacing:this.configuration.layout.sections.global.paragraphSpacing||0,columnBottomY:this.renderer.getContentBottomY(),displayLyricsOnly:!!this.configuration.layout.sections?.base?.display?.lyricsOnly,decapo:this.configuration.decapo,repeatedSections:this.configuration.layout.sections?.base?.display?.repeatedSections};return new ci(this.song,new mr,a)}getHTML(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.getHTML()}getHTMLString(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.getHTML().outerHTML}dispose(){this.renderer&&(this.renderer.dispose(),this.renderer=null)}},N7=vf,I5=/^\[(Verse.*)]/i,N5=/^\[(Chorus.*)]/i,R5=/^\[(Bridge.*)]/i,z5=/^\[(Intro|Outro|Instrumental|Interlude|Solo|Pre-Chorus)( \d+)?]/i,Wj=/^(\w+):\s*(.+)$/,_5=/^\[([^\]]+)]/,k5=/\s+(x\d+)\s*$/i,O5=/^\s*(((?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?([^/\s]*)(\/(?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?)?)(\s|$)+)+(\s|$)+/,W5={[Qs]:an,[Fs]:mi,[ur]:rn,[Gt]:ii},Ba={[Qs]:zf,[Fs]:tn,[ur]:Rf,[Gt]:_a},jf=class extends Yf{constructor({preserveWhitespace:r=!0}={}){super({preserveWhitespace:r},!1),this.currentSectionType=null,this.pendingRepeatNotation=null}parseLine(r){this.isSectionEnd()&&this.endSection();let{cleanLine:e,repeatNotation:a}=this.extractRepeatNotation(r);this.pendingRepeatNotation=a,this.parseVerseDirective(e)||this.parseChorusDirective(e)||this.parseBridgeDirective(e)||this.parsePartDirective(e)||this.parseUGMetadata(e)||this.parseMetadata(e)||this.parseRegularLine(e)}parseRegularLine(r){this.songLine=this.songBuilder.addLine(),r.trim().length===0?this.chordLyricsPair=null:this.parseNonEmptyLine(r)}parseNonEmptyLine(r){if(!this.songLine)throw new Error("Expected this.songLine to be present");this.chordLyricsPair=this.songLine.addChordLyricsPair();let e=O5.test(r);e&&this.hasNextLine()?this.parseChordLineWithNextLine(r):e?this.parseChordsOnly(r):this.chordLyricsPair.lyrics=`${r}`}parseChordLineWithNextLine(r){let e=this.readLine();this.isNonLyricsLine(e)?(this.parseChordsOnly(r),this.unreadLine()):this.parseLyricsWithChords(r,e)}unreadLine(){this.currentLine-=1}isNonLyricsLine(r){return I5.test(r)||N5.test(r)||R5.test(r)||z5.test(r)||_5.test(r)||O5.test(r)||r.trim().length===0}parseChordsOnly(r){this.parseLyricsWithChords(r,""),this.applyRepeatNotation()}parseLyricsWithChords(r,e){let a=this.processCharacters(r,e);if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.lyrics+=e.substring(a),this.chordLyricsPair.chords=this.chordLyricsPair.chords.trim(),this.chordLyricsPair.lyrics&&(this.chordLyricsPair.lyrics=this.chordLyricsPair.lyrics.trim()),this.applyRepeatNotation()}processCharacters(r,e){let a=S7(e),l=-1;for(let u=0,d=r.length;u<d;u+=1)this.addCharacter(r[u],r[u+1]),l=this.mapLyricsCharacter(a,u,e,l),this.processingText=!/\s/.test(r[u]);return l>=0?l+1:0}addCharacter(r,e){let a=/\s/.test(r);if(a||this.ensureChordLyricsPairInitialized(),!a||this.shouldAddCharacterToChords(e)){if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.chords+=r}}shouldAddCharacterToChords(r){return!!(r&&/\s/.test(r)&&this.preserveWhitespace)}ensureChordLyricsPairInitialized(){if(!this.processingText){if(!this.songLine)throw new Error("Expected this.songLine to be present");this.chordLyricsPair=this.songLine.addChordLyricsPair(),this.processingText=!0}}extractRepeatNotation(r){let e=r.match(k5);return e?{cleanLine:r.replace(k5,""),repeatNotation:e[1]}:{cleanLine:r,repeatNotation:null}}applyRepeatNotation(){if(!this.pendingRepeatNotation||!this.songLine)return;let r=this.songLine.items[this.songLine.items.length-1];r&&"lyrics"in r&&(r.lyrics=(r.lyrics||"")+this.pendingRepeatNotation),this.pendingRepeatNotation=null}parseUGMetadata(r){let e=r.match(Wj);if(!e)return!1;let a=e[1].toLowerCase();if(!Ka.includes(a))return!1;let l=a===br?this.extractCapoValue(e[2]):e[2].trim();return this.startNewLine(),this.songBuilder.addTag(new X(a,l)),!0}extractCapoValue(r){let[,e]=r.match(/^(\d+)/)||[];return e||r.trim()}parseVerseDirective(r){let e=r.match(I5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(Qs,a),!0}parseChorusDirective(r){let e=r.match(N5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(Fs,a),!0}parseBridgeDirective(r){let e=r.match(R5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(ur,a),!0}parsePartDirective(r){let e=r.match(z5);if(!e)return!1;this.startNewLine();let a=e[1]+(e[2]||"");return this.startSection(Gt,a),!0}parseMetadata(r){let e=r.match(_5);if(!e)return!1;if(this.startNewLine(),this.endSection(),!this.songLine)throw new Error("Expected this.songLine to be present");return this.songLine.addTag(new X(sn,e[1])),!0}isSectionEnd(){return this.songLine!==null&&this.songLine.isEmpty()&&this.songBuilder.previousLine!==null&&!this.songBuilder.previousLine.isEmpty()}endOfSong(){super.endOfSong(),this.currentSectionType!==null&&this.currentSectionType in Ba&&this.startNewLine(),this.endSection({addNewLine:!1})}startSection(r,e){this.currentSectionType&&this.endSection(),this.currentSectionType=r,this.songBuilder.setCurrentProperties(r),r in W5&&this.songBuilder.addTag(new X(W5[r],e))}endSection({addNewLine:r=!0}={}){this.currentSectionType!==null&&this.currentSectionType in Ba&&(this.songLine&&this.songLine.isEmpty()?this.songLine.addTag(new X(Ba[this.currentSectionType])):this.songBuilder.addLine().addTag(new X(Ba[this.currentSectionType])),r&&this.startNewLine()),this.songBuilder.setCurrentProperties(Es),this.currentSectionType=null}startNewLine(){this.songLine=this.songBuilder.addLine()}},R7=jf,z7="15.3.0",Hj={configure:lj,getDefaultConfig:gr,getHTMLDefaultConfig:g7,getMeasuredHtmlDefaultConfig:h7,getPDFDefaultConfig:yv,mergeConfigs:Dt},_7=Hj,Kj={getCapos:x7,getKeys:Iv},k7=Kj,Vj={},Uj={CHORUS:Fs,Chord:Js,ChordDefinition:en,ChordLyricsPair:J,ChordProFormatter:d7,MeasuredHtmlFormatter:N7,ChordProParser:Uf,ChordSheetParser:Yf,ChordSheetSerializer:nn,ChordsOverWordsFormatter:v7,ChordsOverWordsParser:P7,Comment:qs,Composite:Va,HtmlDivFormatter:B7,HtmlTableFormatter:I7,INDETERMINATE:qa,Line:Ds,Literal:_e,Metadata:or,NONE:Es,Paragraph:Et,PART:Gt,SoftLineBreak:pe,Song:ws,TAB:fi,TEXTBLOCK:oi,Tag:X,Ternary:fr,TextFormatter:Jf,UltimateGuitarParser:R7,VERSE:Qs,BaseMeasurer:lr,DomMeasurer:mr,CanvasMeasurer:Ya,LayoutEngine:ci,formatterConfiguration:_7,keyHelpers:k7,version:z7,templateHelpers:{isEvaluatable:li,isChordLyricsPair:Xs,lineHasContents:dr,isTag:Zs,isComment:ls,isImage:fn,stripHTML:on,each:Ls,when:fe,hasTextContents:ui,lineClasses:mn,paragraphClasses:un,evaluate:bi,fontStyleTag:Re,renderChord:et,hasChordContents:Bf,pangoToHtml:cn,stripPangoMarkup:wt}};QT(H.exports,Vj)});return Yj();})();
|
|
230
|
+
: ${a.message}`,{cause:a})}}calculateX(r,e=0,a=0){switch(r){case"center":return this.backend.pageSize.width/2-e/2+a;case"right":return this.backend.pageSize.width-this.context.margins.right-e+a;default:return typeof r=="number"?this.context.margins.left+r+a:this.context.margins.left+a}}getAvailableWidth(){return this.backend.pageSize.width-this.context.margins.left-this.context.margins.right}},Nj=Cf,Af=class{constructor(r){this.startTime=0,this.renderTime=0,this.x=0,this.y=0,this.currentColumn=1,this.elements=[],this.currentPage=1,this.song=r,this.startTime=performance.now()}initialize(){this.x=this.getMinX(),this.y=this.getMinY(),this.currentColumn=1,this.currentPage=1,this.elements=[],this.initializeBackend()}render(r,e){this.initialize(),this.renderParagraphs(r),this.renderChordDiagrams(),this.renderHeadersAndFooters(),this.finalizeRendering(),this.recordRenderingTime()}getContentBottomY(){return this.getColumnBottomY()}getRenderTime(){return this.renderTime}renderParagraphs(r){r.forEach(e=>{e.units.forEach(a=>{this.renderLines(a)}),e.addSpacing&&(this.y+=this.getParagraphSpacing())})}renderLines(r){r.forEach(e=>{this.renderLineLayout(e)})}renderLineLayout(r){let{items:e,lineHeight:a,line:l}=r;if(this.hasColumnBreak(r)){this.moveToNextColumn();return}this.y+a>this.getColumnBottomY()&&this.moveToNextColumn();let u=this.y,{chordsYOffset:d,lyricsYOffset:x}=this.calculateChordLyricYOffsets(e,u),M=this.x;e.forEach(D=>{let{item:w,width:R}=D;this.renderItem(w,l,M,d,x,e,u),M+=R}),this.y+=a,this.x=this.getColumnStartX()}hasColumnBreak(r){let{items:e}=r;return e.length===1&&e[0].item instanceof X&&Xf(e[0].item)}renderItem(r,e,a,l,u,d,x){r instanceof J?this.renderChordLyricsPair(r,e,a,l,u,d):r instanceof X?r.isSectionDelimiter()?this.addSectionLabel(r.label,a,x):ls(r)&&this.addComment(r.value,a,x):r instanceof pe&&this.addTextElement(r.content,a,u,"lyrics")}renderChordLyricsPair(r,e,a,l,u,d){let{chords:x}=r,{lyrics:M}=r;if(x&&(x=this.processChords(x,e)),!this.isLyricsOnly()&&x){let D=this.calculateChordBaseline(l,d,x);this.addTextElement(x,a,D,"chord")}M&&M.trim()!==""&&this.addTextElement(M,a,u,"lyrics")}moveToNextColumn(){this.currentColumn+=1,this.currentColumn>this.getColumnCount()&&(this.startNewPage(),this.currentColumn=1),this.x=this.getColumnStartX(),this.y=this.getMinY()}startNewPage(){this.currentPage+=1,this.createNewPage()}calculateChordLyricYOffsets(r,e){let a=r.some(({item:M})=>M instanceof J&&M.chords),l=r.some(({item:M})=>M instanceof J&&M.hasLyrics()),u=e,d=e,x=this.getChordLyricSpacing();return a&&l?(u=e,d=u+this.getMaxChordHeight(r)+x):a&&!l?u=e:!a&&l&&(d=e),{chordsYOffset:u,lyricsYOffset:d}}getMaxChordHeight(r){return r.reduce((e,{chordHeight:a})=>Math.max(e,a||0),0)}processChords(r,e){return et(r,e,this.song,{renderKey:null,useUnicodeModifier:this.useUnicodeModifiers(),normalizeChords:this.normalizeChords(),decapo:this.getConfiguration().decapo})}addTextElement(r,e,a,l){let u=this.getFontForType(l),{width:d,height:x}=this.measureText(r,u);this.elements.push({x:e,y:a,width:d,height:x,content:r,type:l,style:u,page:this.currentPage,column:this.currentColumn})}addSectionLabel(r,e,a){this.addTextElement(r,e,a,"sectionLabel")}addComment(r,e,a){this.addTextElement(r,e,a,"comment")}getFontForType(r){switch(r){case"chord":return this.getFontConfiguration("chord");case"lyrics":return this.getFontConfiguration("text");case"sectionLabel":return this.getFontConfiguration("sectionLabel");case"comment":return this.getFontConfiguration("comment");default:return this.getFontConfiguration("text")}}getTotalPages(){return this.currentPage}getColumnStartX(){let r=this.getLeftMargin(),e=this.getColumnWidth(),a=this.getColumnSpacing();return r+(this.currentColumn-1)*(e+a)}getColumnBottomY(){return this.getPageHeight()-this.getBottomMargin()-this.getFooterHeight()}getColumnWidth(){let r=this.getPageWidth()-this.getLeftMargin()-this.getRightMargin(),e=this.getColumnCount(),a=this.getColumnSpacing();return(r-(e-1)*a)/e}getMinX(){return this.getLeftMargin()}getMinY(){return this.getTopMargin()+this.getHeaderHeight()}recordRenderingTime(){let r=performance.now();this.renderTime=(r-this.startTime)/1e3}getElementsForPage(r){return this.elements.filter(e=>e.page===r)}getLayout(){return this.getConfiguration().layout}getHeaderConfig(){return this.getLayout().header}getFooterConfig(){return this.getLayout().footer}getPageWidth(){return this.getDocPageSize().width}getPageHeight(){return this.getDocPageSize().height}getLeftMargin(){return this.dimensions.margins.left}getRightMargin(){return this.dimensions.margins.right}getTopMargin(){return this.dimensions.margins.top}getBottomMargin(){return this.dimensions.margins.bottom}getHeaderHeight(){return this.getHeaderConfig()?.height??0}getFooterHeight(){return this.getFooterConfig()?.height??0}getColumnCount(){return this.dimensions.effectiveColumnCount}getSectionsConfig(){let{sections:r}=this.getLayout();if(!r)throw new Error("Configuration must include sections");return r}getColumnSpacing(){return this.getSectionsConfig().global.columnSpacing}getChordLyricSpacing(){return this.getSectionsConfig().global.chordLyricSpacing}getParagraphSpacing(){return this.getSectionsConfig().global.paragraphSpacing||0}useUnicodeModifiers(){return this.getConfiguration().useUnicodeModifiers}normalizeChords(){return this.getConfiguration().normalizeChords}isLyricsOnly(){return!!this.getSectionsConfig()?.base?.display?.lyricsOnly}},Rj=Af,Sf=class extends Rj{constructor(r,e,a){if(super(r),this.currentLayoutFontStyle=null,this.currentLayoutSection=null,this.currentLayoutTextItem=null,this.currentLineStyle=null,this._dimensions=null,this._dimensionCacheKey=null,this.container=e,this.configuration=a,this.styler=new Bj({cssClassPrefix:a.cssClassPrefix,cssClasses:a.cssClasses}),!e)throw new Error("Container element is required");this.doc=new Pj(e,{width:this.configuration.pageSize.width,height:this.configuration.pageSize.height})}getFontConfiguration(r){return this.configuration.fonts[r]}getDocumentMetadata(){return{pageWidth:this.getPageWidth(),pageHeight:this.getPageHeight(),marginLeft:this.getLeftMargin(),marginRight:this.getRightMargin(),marginTop:this.getTopMargin(),marginBottom:this.getBottomMargin(),columnWidth:this.getColumnWidth(),columnCount:this.getColumnCount(),currentPage:this.doc.currentPage,totalPages:this.doc.totalPages,renderTime:this.renderTime,dimensions:this.dimensions}}getDoc(){return this.doc}getHTML(){return this.container}dispose(){this.doc&&this.doc.dispose()}initializeBackend(){if(this.configuration.additionalCss){let r=document.createElement("style");r.textContent=this.configuration.additionalCss,document.head.appendChild(r)}}createNewPage(){this.doc.newPage()}renderChordDiagrams(){console.log("Chord diagram rendering is stubbed out")}renderHeadersAndFooters(){let r=this.getHeaderConfig(),e=this.getFooterConfig();r&&this.renderLayoutForEachPage(r,"header"),e&&this.renderLayoutForEachPage(e,"footer"),this.resetLayoutRenderingState()}renderLayoutForEachPage(r,e){this.doc.eachPage((a,l)=>{this.currentLayoutSection=e,this.resetLayoutRenderingState(e),this.createLayoutRenderer(l+1,this.doc.totalPages).renderLayout(r,e)})}resetLayoutRenderingState(r=null){this.currentLayoutSection=r,this.currentLayoutFontStyle=null,this.currentLayoutTextItem=null,this.currentLineStyle=null}createLayoutRenderer(r,e){let a=this.createLayoutBackend(r,e);return new Nj(a,{metadata:this.song.metadata,margins:this.dimensions.margins,extraMetadata:this.getExtraMetadata(r,e)})}createLayoutBackend(r,e){return{pageSize:this.doc.pageSize,currentPage:r,totalPages:e,text:(a,l,u)=>this.renderHtmlText(a,l,u),getTextWidth:(a,l)=>this.doc.getTextWidth(a,l),splitTextToSize:(a,l,u)=>this.doc.splitTextToSize(a,l,u),setFontStyle:a=>{this.currentLayoutFontStyle=a},setTextItem:a=>{this.currentLayoutTextItem=a},addElement:(a,l,u)=>this.doc.addElement(a,l,u),addImage:(a,l,u,d,x,M)=>this.renderHtmlImage(a,u,d,x,M),line:(a,l,u,d)=>this.renderHtmlLine(a,l,u,d),setLineStyle:a=>{this.currentLineStyle=a},resetDash:()=>{}}}renderHtmlText(r,e,a){let l=document.createElement("div");l.className=`${this.styler.prefix}header-text`,this.applyLayoutTextClasses(l),l.textContent=r,this.applyLayoutTextStyles(l),this.doc.addElement(l,e,a)}applyLayoutTextClasses(r){let e=this.currentLayoutSection?this.styler.getCustomClass(this.currentLayoutSection):void 0;e&&r.classList.add(e),this.currentLayoutTextItem?.cssClass&&r.classList.add(this.currentLayoutTextItem.cssClass)}applyLayoutTextStyles(r){this.currentLayoutTextItem?.elementStyle&&Object.assign(r.style,this.currentLayoutTextItem.elementStyle),this.currentLayoutFontStyle&&this.styler.applyFontStyle(r,this.currentLayoutFontStyle)}renderHtmlImage(r,e,a,l,u){let d=document.createElement("img");d.className=`${this.styler.prefix}image`,d.src=r,d.style.width=`${l}px`,d.style.height=`${u}px`,this.doc.addElement(d,e,a)}renderHtmlLine(r,e,a,l){let u=document.createElement("div");u.className=`${this.styler.prefix}line`;let d=this.currentLineStyle;u.style.width=`${a-r}px`,u.style.height="0",u.style.borderBottomWidth=`${d?.width??1}px`,u.style.borderBottomStyle=d?.dash?.length?"dashed":"solid",u.style.borderBottomColor=d?.color??"#000000",this.doc.addElement(u,r,e)}renderParagraphs(r){r.forEach((e,a)=>{this.renderParagraph(e,a,r)})}renderParagraph(r,e,a){let l=[],u=this.elements;this.elements=l,r.units.forEach(x=>{this.renderLineItems(x)});let d=this.groupElementsByPageAndColumn(l);Object.values(d).forEach((x,M)=>{this.renderElementGroup(x,e,M,r)}),r.addSpacing&&e<a.length-1&&(this.y+=this.getParagraphSpacing()),this.x=this.getColumnStartX(),this.elements=u}groupElementsByPageAndColumn(r){let e={};return r.forEach(a=>{let l=`${a.page}-${a.column}`;e[l]||(e[l]=[]),e[l].push(a)}),e}renderLineItems(r){let e={column:this.currentColumn,page:this.currentPage};r.forEach(a=>{e=this.renderSingleLine(a,e)})}renderSingleLine(r,e){if(this.hasColumnBreak(r))return this.moveToNextColumn(),this.getCurrentContext();let a=this.handleColumnOverflow(r.lineHeight,e);return this.renderLineContent(r,a),a}getCurrentContext(){return{column:this.currentColumn,page:this.currentPage}}handleColumnOverflow(r,e){return this.y+r>this.getColumnBottomY()?(this.moveToNextColumn(),this.getCurrentContext()):e}renderLineContent(r,e){let{items:a,lineHeight:l,line:u}=r,d=this.y,{chordsYOffset:x,lyricsYOffset:M}=this.calculateChordLyricYOffsets(a,d),D=this.x;a.forEach(w=>{this.renderMeasuredItem(w,D,d,x,M,a,u,e),D+=w.width}),this.y+=l,this.x=this.getColumnStartX()}renderMeasuredItem(r,e,a,l,u,d,x,M){let{item:D}=r;D instanceof J?this.renderChordLyricsPairItem(D,e,l,u,d,x,M):D instanceof X?this.renderTagItem(D,e,a,M):D instanceof pe&&(this.addTextElement(D.content,e,u,"lyrics"),this.updatePosition(M.column,M.page))}renderChordLyricsPairItem(r,e,a,l,u,d,x){let{chords:M}=r,{lyrics:D}=r;if(M&&(M=this.processChords(M,d)),!this.isLyricsOnly()&&M){let w=this.calculateChordBaseline(a,u,M);this.addTextElement(M,e,w,"chord"),this.updatePosition(x.column,x.page)}D&&D.trim()!==""&&(this.addTextElement(D,e,l,"lyrics"),this.updatePosition(x.column,x.page))}renderTagItem(r,e,a,l){let u=r.attributes.__titleSeparator==="true";r.isSectionDelimiter()?(this.addSectionLabel(r.label,e,a,{noUnderline:u}),this.updatePosition(l.column,l.page)):ls(r)&&(this.addComment(r.value,e,a,{noUnderline:u}),this.updatePosition(l.column,l.page))}updatePosition(r,e){let a=this.elements[this.elements.length-1];a.column=r,a.page=e}addSectionLabel(r,e,a,l={}){this.addTextElementWithOptions(r,e,a,"sectionLabel",l)}addComment(r,e,a,l={}){this.addTextElementWithOptions(r,e,a,"comment",l)}addTextElementWithOptions(r,e,a,l,u={}){let d=this.getFontForType(l),{width:x,height:M}=this.measureText(r,d),D=u.noUnderline?{...d,underline:!1}:d;this.elements.push({x:e,y:a,width:x,height:M,content:r,type:l,style:D,page:this.currentPage,column:this.currentColumn})}measureText(r,e){let{w:a,h:l}=this.doc.getTextDimensions(r,e);return{width:a,height:l}}calculateChordBaseline(r,e,a){let l=this.getFontConfiguration("chord"),{height:u}=this.measureText(a,l);return r+this.getMaxChordHeight(e)-u}finalizeRendering(){let r=Math.max(this.currentPage,this.doc.totalPages);for(;this.doc.totalPages<r;)this.doc.createPage();for(let e=1;e<=r;e+=1){let a=this.getElementsForPage(e);a.length>0&&(this.doc.setPage(e),a.forEach(l=>{this.drawElement(l)}))}}getConfiguration(){return this.configuration}get dimensions(){let r=this.generateDimensionCacheKey();return(this._dimensionCacheKey!==r||this._dimensions===null)&&(this._dimensions=this.buildDimensions(),this._dimensionCacheKey=r),this._dimensions}getDocPageSize(){return this.doc.pageSize}calculateBounds(r){let e=Number.MAX_VALUE,a=Number.MAX_VALUE,l=Number.MIN_VALUE,u=Number.MIN_VALUE;return r.forEach(d=>{e=Math.min(e,d.x),a=Math.min(a,d.y),l=Math.max(l,d.x+d.width),u=Math.max(u,d.y+d.height)}),{minX:e,minY:a,maxX:l,maxY:u}}createParagraphDiv(r,e){let a=r.maxX-r.minX,l=r.maxY-r.minY,u=document.createElement("div");return u.className=this.styler.createClassName(...e),Object.assign(u.style,{position:"absolute",left:`${r.minX}px`,top:`${r.minY}px`,width:`${a}px`,height:`${l}px`}),u}createElementGroupDiv(r,e,a,l){let u=document.createElement("div");return u.className=this.styler.createClassName(...l),Object.assign(u.style,{position:"absolute",left:`${r}px`,top:`${e}px`}),u.textContent=a,u}renderElementGroup(r,e,a,l){let{page:u}=r[0];this.doc.setPage(u);let d=this.calculateBounds(r),{prefix:x}=this.styler,M=this.createParagraphDiv(d,[`${x}paragraph`,`paragraph-${e}-${a}`,`${x}${l.sectionType}`]);r.forEach(D=>{this.renderElement(D,d,M)}),this.doc.addElement(M,d.minX,d.minY)}renderElement(r,e,a){let{prefix:l}=this.styler,u=this.createElementGroupDiv(r.x-e.minX,r.y-e.minY,r.content,[`${l}element ${l}${r.type}`,this.styler.getCustomClass(r.type)]);this.styler.applyElementStyle(u,r),a.appendChild(u)}drawElement(r){switch(r.type){case"chord":case"lyrics":case"sectionLabel":case"comment":this.drawTextElement(r);break;default:console.warn(`Unknown element type: ${r.type}`);break}}drawTextElement(r){let e=document.createElement("div"),{prefix:a}=this.styler;e.className=`${a}element ${a}${r.type}`;let l=this.styler.getCustomClass(r.type);l&&e.classList.add(l),e.textContent=r.content,r.style&&this.styler.applyElementStyle(e,r),this.doc.addElement(e,r.x,r.y)}buildDimensions(){let{width:r,height:e}=this.doc.pageSize,{columnCount:a,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d}=this.configuration.layout.sections.global;return new jj(r,e,this.configuration.layout,{columnCount:a,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d})}generateDimensionCacheKey(){let{width:r,height:e}=this.doc.pageSize,{layout:a}=this.configuration,{global:l}=a.sections;return[r,e,a.global.margins.left,a.global.margins.right,a.global.margins.top,a.global.margins.bottom,a.header?.height||0,l.columnCount,l.columnSpacing,l.minColumnWidth||0,l.maxColumnWidth||0].join("-")}getExtraMetadata(r,e){let a={page:r.toString(),pages:e.toString(),renderTime:this.renderTime.toString()},l=this.song.metadata.getSingle("capo"),u=this.song.metadata.getSingle("key");if(l&&u){let d=parseInt(l,10);a.capoKey=x7(u)[d]}return a}},zj=Sf,Lf=class{constructor(r,e,a){this.measurer=r,this.config=e,this.song=a}measureLineItems(r,e=!1){let a=[];for(let l=0;l<r.items.length;l+=1){let u=r.items[l],d=r.items[l+1]??null;if(Xs(u)){let x=this.processChordLyricsPair(u,d,r,e);a.push(...x)}else if(G7(u))a.push(this.processSoftLineBreak(u));else if(Zs(u)){let x=this.processTag(u);a.push(...x)}else a.push({item:null,width:0})}return a}processChordLyricsPair(r,e,a,l=!1){let u=this.handleLyricsOnlyMode(r,e,l);if(u)return u;let d=this.splitChordLyricsPair(r,l);return this.processSplitItems(d,e,a,l)}handleLyricsOnlyMode(r,e,a){if(!a)return null;let l=this.removeHyphens(r.lyrics||"");return this.cleanNextItemHyphens(e,()=>{l=l.trimEnd()}),l===""?[{item:null,width:0}]:null}cleanNextItemHyphens(r,e){if(!r||!Xs(r))return;let a=r,l=a.lyrics||"";(l.startsWith(" -")||l.startsWith("-"))&&(e(),a.lyrics=this.removeHyphens(l))}processSplitItems(r,e,a,l){return r.map(u=>this.processSingleSplitItem(u,e,a,l)).filter(u=>u!==null)}processSingleSplitItem(r,e,a,l){return r instanceof pe?this.processSoftLineBreak(r):r instanceof J?this.measureChordLyricsPair(r,e,a,l):null}measureChordLyricsPair(r,e,a,l){let{chords:u,lyrics:d}=this.getAdjustedChordsAndLyrics(r,l);if(l&&d==="")return{item:null,width:0};let x=this.renderChordText(u,a),M=this.calculateMeasurements(x,d,e,l);return{item:new J(u,d),width:M.totalWidth,chordHeight:M.chordHeight}}getAdjustedChordsAndLyrics(r,e){return e?{chords:"",lyrics:this.removeHyphens(r.lyrics||"")}:{chords:r.chords||"",lyrics:r.lyrics||""}}renderChordText(r,e){return et(r,e,this.song,{renderKey:null,useUnicodeModifier:this.config.useUnicodeModifiers,normalizeChords:this.config.normalizeChords,normalizeChordSuffix:this.config.normalizeChordSuffix,decapo:this.config.decapo})}calculateMeasurements(r,e,a,l){let u=this.config.fonts.chord,d=this.config.fonts.lyrics,x=r?this.measurer.measureTextWidth(r,u):0,M=e?this.measurer.measureTextWidth(e,d):0,D=this.getAdjustedChordWidth(x,M,r,a,l);return{totalWidth:Math.max(D,M),chordHeight:r?this.measurer.measureTextHeight(r,u):0}}getAdjustedChordWidth(r,e,a,l,u){let d=l&&Xs(l)&&l.chords?.trim()!=="",x=this.getSpaceWidth(this.config.fonts.lyrics);if(!u&&d&&r>=e-x){let D=this.getChordSpacingAsSpaces();return this.measurer.measureTextWidth(a+D,this.config.fonts.chord)}return r}processSoftLineBreak(r){let e=this.measurer.measureTextWidth(r.content,this.config.fonts.lyrics);return{item:r,width:e}}processTag(r){let e=[];if(ls(r)||r.isSectionDelimiter()){let a=ls(r)?this.config.fonts.comment:this.config.fonts.sectionLabel,l=this.config.width,u=r.label||r.value||"";this.measurer.splitTextToSize(u,l,a).forEach(x=>{let M=this.measurer.measureTextWidth(x,a);e.push(this.createMeasuredTagItem(r,x,M))})}else e.push({item:r,width:0});return e}createMeasuredTagItem(r,e,a){let l=new X(r.name,e);return r.attributes.__titleSeparator==="true"&&(l._value=" > ",l.attributes.__titleSeparator="true",Object.defineProperty(l,"value",{configurable:!0,get:()=>" > ",set:u=>{l._value=u}})),{item:l,width:a}}splitMeasuredItem(r,e){if(!(r.item instanceof J)||!r.item.lyrics)return[r,null];let{lyrics:a}=r.item,l=this.config.fonts.lyrics,u=this.measurer.splitTextToSize(a,e,l);if(u.length===1)return[r,null];let d=u[0],x=u.slice(1).join(" ");return[{item:new J(r.item.chords,d),width:this.measurer.measureTextWidth(d,l),chordHeight:r.chordHeight},{item:new J("",x),width:this.measurer.measureTextWidth(x,l),chordHeight:0}]}removeHyphens(r){let e=r.replace(/\b(\w+)\s*-\s*(\w+)\b/g,"$1$2");return e=e.replace(/(?:\b(\w+)\s*-\s*$)|(?:-\s*$)|(?:\s+-\s+$)/g,"$1"),/^\s*-\s*$/.test(e)?"":e}splitChordLyricsPair(r,e=!1){let{chords:a,lyrics:l,annotation:u}=r;if(!l||l.trim()==="")return[r];let d=l.split(/,\s*/),x=[];return d.forEach((M,D)=>{if(D>0&&D!==0&&(x.push(new pe(" ")),M.trim()!=="")){let w=e?M.trimStart():M;x.push(new J("",w,""))}if(D===0&&d.length===1)x.push(new J(a,M,u));else if(D===0&&d.length>1){let w=M;w+=",",x.push(new J(a,w,u))}}),x}findNextItemWithLyrics(r,e,a){return[...r,...e.slice(a)].find(u=>u.item instanceof J&&u.item.lyrics?.trim())||null}capitalizeFirstWord(r){return r.replace(/^\s*\w/,e=>e.toUpperCase())}getSpaceWidth(r){return this.measurer.measureTextWidth(" ",r)}getChordSpacingAsSpaces(){return" ".repeat(this.config.chordSpacing)}},Ff=class{constructor(r){this.config=r}createLineLayout(r,e){let a=this.analyzeLineContent(r),l=this.determineLineType(a),u=Math.max(...r.map(x=>x.chordHeight||0)),d=this.calculateLineHeight(a,u);return{type:l,items:r,lineHeight:d,line:e}}analyzeLineContent(r){return{hasChords:r.some(e=>e.item instanceof J&&e.item.chords),hasLyrics:r.some(e=>e.item instanceof J&&e.item.lyrics?.trim()),hasComments:r.some(e=>e.item instanceof X&&ls(e.item)),hasSectionLabel:r.some(e=>e.item instanceof X&&e.item.isSectionDelimiter()),hasTag:r.some(e=>e.item instanceof X)}}determineLineType(r){return r.hasChords||r.hasLyrics?"ChordLyricsPair":r.hasComments?"Comment":r.hasSectionLabel?"SectionLabel":r.hasTag?"Tag":"Empty"}calculateLineHeight(r,e){let{baseHeight:a,fontConfig:l}=this.getBaseHeightAndFont(r,e),u=l?.lineHeight||1;return a*u}getBaseHeightAndFont(r,e){let a=this.config.linePadding;if(r.hasChords&&r.hasLyrics){let l=this.config.fonts.lyrics;return a+=e+this.config.chordLyricSpacing+l.size,{baseHeight:a,fontConfig:l}}return r.hasChords?{baseHeight:a+e,fontConfig:null}:r.hasLyrics?this.addFontHeight(a,this.config.fonts.lyrics):r.hasComments?this.addFontHeight(a,this.config.fonts.comment):r.hasSectionLabel?this.addFontHeight(a,this.config.fonts.sectionLabel):{baseHeight:a,fontConfig:null}}addFontHeight(r,e){return{baseHeight:r+e.size,fontConfig:e}}createColumnBreakLayout(){return{type:"Tag",line:new Ds,items:[{item:new X("column_break"),width:0}],lineHeight:0}}},Ef=class{constructor(r,e){this.itemProcessor=r,this.layoutFactory=e}breakLineIntoLayouts(r,e,a=!1){let l=this.itemProcessor.measureLineItems(r,a),u=this.consolidateConsecutiveSoftBreaks(l);return this.breakContent(u,e,r)}breakContent(r,e,a){if(r.length===0)return[];let{totalWidth:l,softBreakIndices:u}=this.analyzeContent(r);if(this.shouldReturnSingleLayout(l,e))return[this.layoutFactory.createLineLayout(r,a)];if(u.length===0)return this.handleNoSoftBreaks(r,e,a);let{firstChunk:d,secondChunk:x}=this.splitAtBestSoftBreak(r,u,l);return d.length===0?this.breakContent(x,e,a):[this.layoutFactory.createLineLayout(d,a),...this.breakContent(x,e,a)]}handleNoSoftBreaks(r,e,a){let l=this.findBreakIndex(r,e);if(l===-1)return[this.layoutFactory.createLineLayout(r,a)];if(l===0)return this.handleOversizedFirstItem(r,e,a);let u=r.slice(0,l),d=r.slice(l);return this.removeTrailingComma(u),[this.layoutFactory.createLineLayout(u,a),...this.breakContent(d,e,a)]}consolidateConsecutiveSoftBreaks(r){let e=[];for(let a=0;a<r.length;a+=1){let l=r[a];e.push(l),l.item instanceof pe&&(a=this.skipConsecutiveSoftBreaks(r,a))}return e}skipConsecutiveSoftBreaks(r,e){let a=e;for(;a+1<r.length&&r[a+1].item instanceof pe;)a+=1;return a}findBreakIndex(r,e){let a=0;for(let l=0;l<r.length;l+=1){if(a+r[l].width>e)return l;a+=r[l].width}return-1}handleOversizedFirstItem(r,e,a){let[l,u]=this.itemProcessor.splitMeasuredItem(r[0],e),d=u?[u,...r.slice(1)]:r.slice(1);return[this.layoutFactory.createLineLayout([l],a),...this.breakContent(d,e,a)]}analyzeContent(r){let e=[];return{totalWidth:r.reduce((l,u,d)=>(u.item instanceof pe&&e.push(d),l+u.width),0),softBreakIndices:e}}shouldReturnSingleLayout(r,e){return r<=e}splitAtBestSoftBreak(r,e,a){let l=a/2,d=e.map(D=>({index:D,widthUpToBreak:this.getWidthUpToIndex(r,D)})).reduce((D,w)=>{let R=Math.abs(w.widthUpToBreak-l),k=Math.abs(D.widthUpToBreak-l);return R===k?w.index>D.index?w:D:R<k?w:D}),x=r.slice(0,d.index),M=r.slice(d.index+1);return this.removeTrailingComma(x),this.capitalizeNextItem(M,M,0),{firstChunk:x,secondChunk:M}}removeTrailingComma(r){let e=r[r.length-1];e?.item instanceof J&&e.item.lyrics?.endsWith(",")&&(e.item.lyrics=e.item.lyrics.slice(0,-1)||"",e.width=this.remeasureLyrics(e))}getWidthUpToIndex(r,e){let a=0;for(let l=0;l<e&&l<r.length;l+=1)a+=r[l].width;return a}remeasureLyrics(r){return r.item instanceof J?this.itemProcessor.measurer.measureTextWidth(r.item.lyrics||"",this.itemProcessor.config.fonts.lyrics):r.width}recalculateChordLyricWidth(r,e=null){if(!(r.item instanceof J))return r.width;let a=r.item,l=this.measureChordAndLyricWidths(a),u=this.adjustChordWidth(a,l,e);return Math.max(u,l.lyricsWidth)}measureChordAndLyricWidths(r){let e=this.itemProcessor.config.fonts.chord,a=this.itemProcessor.config.fonts.lyrics,l=r.chords?this.itemProcessor.measurer.measureTextWidth(r.chords,e):0,u=r.lyrics?this.itemProcessor.measurer.measureTextWidth(r.lyrics,a):0;return{chordWidth:l,lyricsWidth:u}}adjustChordWidth(r,e,a){if(this.shouldSkipChordSpacing(e.chordWidth,a))return e.chordWidth;let l=this.itemProcessor.config.fonts.lyrics,u=this.itemProcessor.measurer.measureTextWidth(" ",l);if(e.chordWidth<e.lyricsWidth-u)return e.chordWidth;let d=this.itemProcessor.config.fonts.chord,x=" ".repeat(this.itemProcessor.config.chordSpacing),M=`${r.chords||""}${x}`;return this.itemProcessor.measurer.measureTextWidth(M,d)}shouldSkipChordSpacing(r,e){return this.itemProcessor.config.displayLyricsOnly||r===0||!e||!(e.item instanceof J)?!0:(e.item.chords||"").trim()===""}capitalizeNextItem(r,e,a){let l=this.itemProcessor.findNextItemWithLyrics(r,e,a);if(l&&l.item instanceof J){let u=l.item.lyrics??"";l.item.lyrics=this.itemProcessor.capitalizeFirstWord(u);let d=e.indexOf(l),x=d>=0&&d<e.length-1?e[d+1]:null;l.width=this.recalculateChordLyricWidth(l,x)}}};function ni(){return{type:"Tag",line:new Ds,items:[{item:new X("column_break"),width:0}],lineHeight:0}}function _j(i){return i.reduce((r,e)=>{let a=e.reduce((l,u)=>l+u.lineHeight,0);return r+a},0)}function kj(i){return i.length===1&&i[0].items.length===1&&i[0].items[0].item instanceof X&&Xf(i[0].items[0].item)}var Df=class{constructor(r){this.chordLyricLineCount=r,this.totalChordLyricPairLines=r}splitParagraph(r,e,a,l){let u=this.flattenLineLayouts(r),d=this.trySplitParagraph(r,u,e,l);return d||(e!==a?[[ni()],...r]:r)}trySplitParagraph(r,e,a,l){let u=this.findAcceptableSplits(e),d=this.selectSplit(u,a,l);return d?this.buildSplitResult(r,d.index):null}selectSplit(r,e,a){for(let l=r.length-1;l>=0;l-=1){let u=r[l];if(e+u.heightFirstPart<=a)return u}return null}buildSplitResult(r,e){let{firstPart:a,secondPart:l}=this.partitionLineLayouts(r,e);return[...a,[ni()],...l]}flattenLineLayouts(r){let e=[];return r.forEach(a=>{a.forEach(l=>{e.push(l)})}),e}findAcceptableSplits(r){let e=0,a=0;return r.slice(0,-1).reduce((l,u,d)=>{e+=u.lineHeight,a+=u.type==="ChordLyricsPair"?1:0;let x=this.totalChordLyricPairLines-a;return a>=2&&x>=2&&l.push({index:d+1,heightFirstPart:e}),l},[])}partitionLineLayouts(r,e){let a=r.reduce((l,u)=>this.partitionReducer(l,u,e),{firstPart:[],secondPart:[],processed:0});return{firstPart:a.firstPart,secondPart:a.secondPart}}partitionReducer(r,e,a){let l=e.length,u=r.processed+l<=a,d=r.processed>=a;if(u)r.firstPart.push(e);else if(d)r.secondPart.push(e);else{let x=a-r.processed;r.firstPart.push(e.slice(0,x)),r.secondPart.push(e.slice(x))}return r.processed+=l,r}},wf=class{splitParagraph(r,e,a,l){if(r.length===0)return[];let{splitIndex:u,heightFirstPart:d}=this.findSplitMetadata(r);return u===null?this.prependColumnBreakIfNeeded(r,e,a):e+d<=l?this.buildSplitResult(r,u):this.prependColumnBreakIfNeeded(r,e,a)}findSplitMetadata(r){let e=0,a=0;for(let l=0;l<r.length;l+=1){let{height:u,chordCount:d}=this.summarizeLineLayout(r[l]);if(e+=d,a+=u,e>=2)return{splitIndex:l+1,heightFirstPart:a}}return{splitIndex:null,heightFirstPart:a}}summarizeLineLayout(r){return r.reduce((e,a)=>({height:e.height+a.lineHeight,chordCount:e.chordCount+(a.type==="ChordLyricsPair"?1:0)}),{height:0,chordCount:0})}buildSplitResult(r,e){let a=r.slice(0,e),l=r.slice(e);return a.concat([[ni()]]).concat(l)}prependColumnBreakIfNeeded(r,e,a){return e===a?r:[[ni()]].concat(r)}},Gf=class{splitParagraph(r,e,a,l){let u=[];return e!==a&&u.push([ni()]),u.concat(r)}},Tf=class{splitParagraph(r,e,a,l,u){return this.createStrategy(u).splitParagraph(r,e,a,l)}createStrategy(r){return r<=3?new Gf:r===4?new wf:new Df(r)}},Mf=class i extends X{constructor(){super("comment"," > "),this.attributes.__titleSeparator="true"}get value(){return" > "}set value(r){super.value=r}clone(){let r=new i;return r.attributes={...this.attributes},r.selector=this.selector,r.isNegated=this.isNegated,r}},Oj=Mf,ci=class{constructor(r,e,a){this.song=r,this.measurer=e,this.config=a,this.sectionCache=new Map,this.processRepeatedSections(),this.itemProcessor=new Lf(this.measurer,this.config,this.song),this.layoutFactory=new Ff(a),this.lineBreaker=new Ef(this.itemProcessor,this.layoutFactory),this.paragraphSplitter=new Tf}normalizeSectionLabel(r){return r?r.replace(/\s*\([^)]*(?:x|\d+|repeat|rep)\s*[^)]*\)\s*$/i,"").trim().toLowerCase().replace(/\s+/g,"_"):null}getSectionCacheKey(r){let e=null;return r.label?e=r.label:r.lines.length>0&&(e=this.extractLabelFromFirstItem(r.lines[0].items[0])),this.normalizeSectionLabel(e)??null}extractLabelFromFirstItem(r){if(!r||!Zs(r))return null;let e=r;return!ls(e)&&!e.isSectionDelimiter()?null:e.label||e.value||null}processRepeatedSections(){if(!this.config.repeatedSections)return;this.sectionCache.clear();let r=[],e=new Set,{bodyParagraphs:a}=this.song.clone();a.forEach((l,u)=>{this.processParagraph({paragraph:l,index:u,processedParagraphs:r,skipIndices:e,bodyParagraphs:a})}),this.song.renderParagraphs=r,this.sectionCache.clear()}processParagraph(r){let{paragraph:e,index:a,skipIndices:l,processedParagraphs:u}=r;if(this.shouldSkipParagraphIndex(a,l))return;let d=this.getSectionCacheKey(e);if(!d){this.addUncachedParagraph(u,e);return}this.handleParagraphWithCacheKey(d,r)}shouldSkipParagraphIndex(r,e){return e.has(r)}addUncachedParagraph(r,e){r.push(this.cloneParagraph(e))}handleParagraphWithCacheKey(r,e){let a=this.cloneParagraph(e.paragraph);if(this.cacheFirstOccurrence(r,a,e.processedParagraphs))return;let l=this.sectionCache.get(r);l&&this.handleRepeatedSection({cachedParagraph:l,currentParagraph:a,processedParagraphs:e.processedParagraphs,skipIndices:e.skipIndices,startIndex:e.index,bodyParagraphs:e.bodyParagraphs})}cacheFirstOccurrence(r,e,a){return this.sectionCache.has(r)?!1:(this.sectionCache.set(r,e),a.push(e),!0)}handleRepeatedSection(r){switch(this.config.repeatedSections){case"hide":return;case"title_only":this.handleTitleOnlyMode(r);return;case"lyrics_only":r.processedParagraphs.push(r.currentParagraph);return;case"full":this.handleFullMode(r);return;default:r.processedParagraphs.push(r.currentParagraph)}}handleTitleOnlyMode(r){let e=this.collectTitleParagraphs(r);r.processedParagraphs.push(this.resolveTitleOnlyParagraph(e))}collectTitleParagraphs(r){let{currentParagraph:e,skipIndices:a,startIndex:l,bodyParagraphs:u}=r,d=[this.createTitleOnlyParagraph(e)];for(let x=l+1;x<u.length;x+=1){let M=u[x];if(!a.has(x))if(this.shouldIncludeTitle(M))d.push(this.createTitleOnlyParagraph(M)),a.add(x);else break}return d}shouldIncludeTitle(r){let e=this.getSectionCacheKey(r);return!!(e&&this.sectionCache.has(e))}resolveTitleOnlyParagraph(r){return r.length===1?r[0]:this.consolidateTitles(r)}handleFullMode(r){let{cachedParagraph:e,currentParagraph:a,processedParagraphs:l}=r,u=new Et;this.buildFullModeLines(a,e).forEach(d=>{u.addLine(d)}),l.push(u)}buildFullModeLines(r,e){if(r.lines.length===0)return e.lines.map(u=>u.clone());let a=r.lines[0],l=a.items[0];return l&&Zs(l)?[a.clone(),...e.lines.slice(1).map(u=>u.clone())]:[...r.lines.map(u=>u.clone()),...e.lines.slice(1).map(u=>u.clone())]}consolidateTitles(r){let e=this.cloneParagraph(r[0]);if(e.lines.length===0)return e;let a=e.lines[0];return r.slice(1).forEach(l=>{if(l.lines.length===0)return;let u=l.lines[0];this.addTitleSeparator(a),u.items.forEach(d=>{a.items.push(this.cloneItem(d))})}),e}addTitleSeparator(r){r.items.push(...this.buildTitleSeparatorItems())}buildTitleSeparatorItems(){return[new pe(" "),new Oj,new pe(" ")]}createTitleOnlyParagraph(r){let e=new Et;if(r.lines.length===0)return e;let a=r.lines[0],l=new Ds({type:a.type,items:[]});return a.items.forEach(u=>{Zs(u)&&l.addItem(this.cloneItem(u))}),l.items.length===0&&(l.items=[...a.items.map(u=>this.cloneItem(u))]),e.addLine(l),e}cloneParagraph(r){let e=new Et;return r.lines.forEach(a=>e.addLine(a.clone())),e}cloneItem(r){return r instanceof pe?new pe(r.content):typeof r.clone=="function"?r.clone():r}computeParagraphLayouts(){let r=[],e={currentY:this.config.minY,currentColumn:1};return this.song.renderParagraphs.forEach(a=>{e=this.processParagraphLayout(a,r,e)}),r}processParagraphLayout(r,e,a){let l=this.computeParagraphLayout(r,this.config.columnWidth,this.config.displayLyricsOnly),u=this.computeLineTypeCounts(l);if(this.shouldSkipParagraphLayout(u))return a;let d=this.adjustParagraphLayouts(l,a,u.chordLyricLineCount),x=this.calculateNextSimulationState(d,a);return this.addParagraphLayout(e,r,d),x}computeLineTypeCounts(r){let e=0,a=0;return r.forEach(l=>{l.forEach(u=>{u.type==="ChordLyricsPair"?e+=1:(u.type==="Comment"||u.type==="SectionLabel")&&(a+=1)})}),{chordLyricLineCount:e,nonLyricLineCount:a}}shouldSkipParagraphLayout(r){return!!this.config.displayLyricsOnly&&r.nonLyricLineCount===1&&r.chordLyricLineCount===0}adjustParagraphLayouts(r,e,a){let l=_j(r);return e.currentY+l<=this.config.columnBottomY?r:this.paragraphSplitter.splitParagraph(r,e.currentY,this.config.minY,this.config.columnBottomY,a)}calculateNextSimulationState(r,e){let{currentY:a,currentColumn:l}=e;return r.forEach(u=>{if(kj(u))l+=1,l>(this.config.columnCount||1)&&(l=1),a=this.config.minY;else{let d=u.reduce((x,M)=>x+M.lineHeight,0);a+=d}}),a+=this.config.paragraphSpacing,{currentY:a,currentColumn:l}}addParagraphLayout(r,e,a){r.push({units:a,addSpacing:!0,sectionType:e.type})}computeParagraphLayout(r,e,a=!1){let l=[];return r.lines.forEach(u=>{if(dr(u)){let d=this.lineBreaker.breakLineIntoLayouts(u,e,a);l.push(d)}}),l}},vf=class extends vj{constructor(r){super(),this.song=new ws,this.renderer=null,this.container=r}getDefaultConfiguration(){return h7()}format(r){for(this.song=r;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.renderer=new zj(r,this.container,this.configuration),this.renderer.initialize();let a=this.createLayoutEngine().computeParagraphLayouts();this.renderer.render(a)}createLayoutEngine(){if(!this.renderer)throw new Error("Renderer not initialized");let r=this.renderer.getDocumentMetadata(),{dimensions:e}=r,a={width:e.columnWidth,fonts:{chord:this.configuration.fonts.chord,lyrics:this.configuration.fonts.text,comment:this.configuration.fonts.comment,sectionLabel:this.configuration.fonts.sectionLabel},chordSpacing:this.configuration.layout.sections.global.chordSpacing,chordLyricSpacing:this.configuration.layout.sections.global.chordLyricSpacing,linePadding:this.configuration.layout.sections.global.linePadding,useUnicodeModifiers:this.configuration.useUnicodeModifiers,normalizeChords:this.configuration.normalizeChords,normalizeChordSuffix:this.configuration.normalizeChordSuffix,minY:e.minY,columnWidth:e.columnWidth,columnCount:this.configuration.layout.sections.global.columnCount,columnSpacing:this.configuration.layout.sections.global.columnSpacing,minColumnWidth:this.configuration.layout.sections.global.minColumnWidth,maxColumnWidth:this.configuration.layout.sections.global.maxColumnWidth,paragraphSpacing:this.configuration.layout.sections.global.paragraphSpacing||0,columnBottomY:this.renderer.getContentBottomY(),displayLyricsOnly:!!this.configuration.layout.sections?.base?.display?.lyricsOnly,decapo:this.configuration.decapo,repeatedSections:this.configuration.layout.sections?.base?.display?.repeatedSections};return new ci(this.song,new mr,a)}getHTML(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.getHTML()}getHTMLString(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.getHTML().outerHTML}dispose(){this.renderer&&(this.renderer.dispose(),this.renderer=null)}},N7=vf,I5=/^\[(Verse.*)]/i,N5=/^\[(Chorus.*)]/i,R5=/^\[(Bridge.*)]/i,z5=/^\[(Intro|Outro|Instrumental|Interlude|Solo|Pre-Chorus)( \d+)?]/i,Wj=/^(\w+):\s*(.+)$/,_5=/^\[([^\]]+)]/,k5=/\s+(x\d+)\s*$/i,O5=/^\s*(((?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?([^/\s]*)(\/(?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?)?)(\s|$)+)+(\s|$)+/,W5={[Qs]:an,[Fs]:mi,[ur]:rn,[Gt]:ii},Ba={[Qs]:zf,[Fs]:tn,[ur]:Rf,[Gt]:_a},jf=class extends Yf{constructor({preserveWhitespace:r=!0}={}){super({preserveWhitespace:r},!1),this.currentSectionType=null,this.pendingRepeatNotation=null}parseLine(r){this.isSectionEnd()&&this.endSection();let{cleanLine:e,repeatNotation:a}=this.extractRepeatNotation(r);this.pendingRepeatNotation=a,this.parseVerseDirective(e)||this.parseChorusDirective(e)||this.parseBridgeDirective(e)||this.parsePartDirective(e)||this.parseUGMetadata(e)||this.parseMetadata(e)||this.parseRegularLine(e)}parseRegularLine(r){this.songLine=this.songBuilder.addLine(),r.trim().length===0?this.chordLyricsPair=null:this.parseNonEmptyLine(r)}parseNonEmptyLine(r){if(!this.songLine)throw new Error("Expected this.songLine to be present");this.chordLyricsPair=this.songLine.addChordLyricsPair();let e=O5.test(r);e&&this.hasNextLine()?this.parseChordLineWithNextLine(r):e?this.parseChordsOnly(r):this.chordLyricsPair.lyrics=`${r}`}parseChordLineWithNextLine(r){let e=this.readLine();this.isNonLyricsLine(e)?(this.parseChordsOnly(r),this.unreadLine()):this.parseLyricsWithChords(r,e)}unreadLine(){this.currentLine-=1}isNonLyricsLine(r){return I5.test(r)||N5.test(r)||R5.test(r)||z5.test(r)||_5.test(r)||O5.test(r)||r.trim().length===0}parseChordsOnly(r){this.parseLyricsWithChords(r,""),this.applyRepeatNotation()}parseLyricsWithChords(r,e){let a=this.processCharacters(r,e);if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.lyrics+=e.substring(a),this.chordLyricsPair.chords=this.chordLyricsPair.chords.trim(),this.chordLyricsPair.lyrics&&(this.chordLyricsPair.lyrics=this.chordLyricsPair.lyrics.trim()),this.applyRepeatNotation()}processCharacters(r,e){let a=S7(e),l=-1;for(let u=0,d=r.length;u<d;u+=1)this.addCharacter(r[u],r[u+1]),l=this.mapLyricsCharacter(a,u,e,l),this.processingText=!/\s/.test(r[u]);return l>=0?l+1:0}addCharacter(r,e){let a=/\s/.test(r);if(a||this.ensureChordLyricsPairInitialized(),!a||this.shouldAddCharacterToChords(e)){if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.chords+=r}}shouldAddCharacterToChords(r){return!!(r&&/\s/.test(r)&&this.preserveWhitespace)}ensureChordLyricsPairInitialized(){if(!this.processingText){if(!this.songLine)throw new Error("Expected this.songLine to be present");this.chordLyricsPair=this.songLine.addChordLyricsPair(),this.processingText=!0}}extractRepeatNotation(r){let e=r.match(k5);return e?{cleanLine:r.replace(k5,""),repeatNotation:e[1]}:{cleanLine:r,repeatNotation:null}}applyRepeatNotation(){if(!this.pendingRepeatNotation||!this.songLine)return;let r=this.songLine.items[this.songLine.items.length-1];r&&"lyrics"in r&&(r.lyrics=(r.lyrics||"")+this.pendingRepeatNotation),this.pendingRepeatNotation=null}parseUGMetadata(r){let e=r.match(Wj);if(!e)return!1;let a=e[1].toLowerCase();if(!Ka.includes(a))return!1;let l=a===br?this.extractCapoValue(e[2]):e[2].trim();return this.startNewLine(),this.songBuilder.addTag(new X(a,l)),!0}extractCapoValue(r){let[,e]=r.match(/^(\d+)/)||[];return e||r.trim()}parseVerseDirective(r){let e=r.match(I5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(Qs,a),!0}parseChorusDirective(r){let e=r.match(N5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(Fs,a),!0}parseBridgeDirective(r){let e=r.match(R5);if(!e)return!1;this.startNewLine();let a=e[1];return this.startSection(ur,a),!0}parsePartDirective(r){let e=r.match(z5);if(!e)return!1;this.startNewLine();let a=e[1]+(e[2]||"");return this.startSection(Gt,a),!0}parseMetadata(r){let e=r.match(_5);if(!e)return!1;if(this.startNewLine(),this.endSection(),!this.songLine)throw new Error("Expected this.songLine to be present");return this.songLine.addTag(new X(sn,e[1])),!0}isSectionEnd(){return this.songLine!==null&&this.songLine.isEmpty()&&this.songBuilder.previousLine!==null&&!this.songBuilder.previousLine.isEmpty()}endOfSong(){super.endOfSong(),this.currentSectionType!==null&&this.currentSectionType in Ba&&this.startNewLine(),this.endSection({addNewLine:!1})}startSection(r,e){this.currentSectionType&&this.endSection(),this.currentSectionType=r,this.songBuilder.setCurrentProperties(r),r in W5&&this.songBuilder.addTag(new X(W5[r],e))}endSection({addNewLine:r=!0}={}){this.currentSectionType!==null&&this.currentSectionType in Ba&&(this.songLine&&this.songLine.isEmpty()?this.songLine.addTag(new X(Ba[this.currentSectionType])):this.songBuilder.addLine().addTag(new X(Ba[this.currentSectionType])),r&&this.startNewLine()),this.songBuilder.setCurrentProperties(Es),this.currentSectionType=null}startNewLine(){this.songLine=this.songBuilder.addLine()}},R7=jf,z7="15.3.1",Hj={configure:lj,getDefaultConfig:gr,getHTMLDefaultConfig:g7,getMeasuredHtmlDefaultConfig:h7,getPDFDefaultConfig:yv,mergeConfigs:Dt},_7=Hj,Kj={getCapos:x7,getKeys:Iv},k7=Kj,Vj={},Uj={CHORUS:Fs,Chord:Js,ChordDefinition:en,ChordLyricsPair:J,ChordProFormatter:d7,MeasuredHtmlFormatter:N7,ChordProParser:Uf,ChordSheetParser:Yf,ChordSheetSerializer:nn,ChordsOverWordsFormatter:v7,ChordsOverWordsParser:P7,Comment:qs,Composite:Va,HtmlDivFormatter:B7,HtmlTableFormatter:I7,INDETERMINATE:qa,Line:Ds,Literal:_e,Metadata:or,NONE:Es,Paragraph:Et,PART:Gt,SoftLineBreak:pe,Song:ws,TAB:fi,TEXTBLOCK:oi,Tag:X,Ternary:fr,TextFormatter:Jf,UltimateGuitarParser:R7,VERSE:Qs,BaseMeasurer:lr,DomMeasurer:mr,CanvasMeasurer:Ya,LayoutEngine:ci,formatterConfiguration:_7,keyHelpers:k7,version:z7,templateHelpers:{isEvaluatable:li,isChordLyricsPair:Xs,lineHasContents:dr,isTag:Zs,isComment:ls,isImage:fn,stripHTML:on,each:Ls,when:fe,hasTextContents:ui,lineClasses:mn,paragraphClasses:un,evaluate:bi,fontStyleTag:Re,renderChord:et,hasChordContents:Bf,pangoToHtml:cn,stripPangoMarkup:wt}};QT(H.exports,Vj)});return Yj();})();
|
package/lib/index.js
CHANGED
|
@@ -6374,6 +6374,9 @@ const $fe1d3ba9df1ecad5$export$693785c2cb536a68 = (formatterType, specificDefaul
|
|
|
6374
6374
|
* @param {boolean} [configuration.useUnicodeModifiers=false] Whether or not to use unicode flat and sharp
|
|
6375
6375
|
* symbols.
|
|
6376
6376
|
* @param {boolean} [configuration.normalizeChords=true] Whether or not to automatically normalize chords
|
|
6377
|
+
* @param {boolean} [configuration.normalizeChordSuffix=true] Whether to normalize chord suffixes (e.g.
|
|
6378
|
+
* `sus2` to `2`, `maj7` to `ma7`). Only takes effect when `normalizeChords` is `true`. Defaults to `false`
|
|
6379
|
+
* for {@link ChordProFormatter} so ChordPro round-trips preserve the user's suffix variant.
|
|
6377
6380
|
*/ constructor(configuration = {}){
|
|
6378
6381
|
const defaultConfig = this.getDefaultConfiguration();
|
|
6379
6382
|
this.configuration = (0, $28a2fcb6fb95a147$export$5d86b86a654a7039)(defaultConfig, configuration);
|
|
@@ -30175,7 +30178,7 @@ const $a5a21ced491ea51f$var$endSectionTags = {
|
|
|
30175
30178
|
var $a5a21ced491ea51f$export$2e2bcd8739ae039 = $a5a21ced491ea51f$var$UltimateGuitarParser;
|
|
30176
30179
|
|
|
30177
30180
|
|
|
30178
|
-
var $ae92e002ce14f11a$export$2e2bcd8739ae039 = '15.3.
|
|
30181
|
+
var $ae92e002ce14f11a$export$2e2bcd8739ae039 = '15.3.1';
|
|
30179
30182
|
|
|
30180
30183
|
|
|
30181
30184
|
|