chordsheetjs 15.5.2-canary.0 → 15.5.2

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 CHANGED
@@ -29716,7 +29716,7 @@ ${template}
29716
29716
  }
29717
29717
  };
29718
29718
  var $a5a21ced491ea51f$export$2e2bcd8739ae039 = $a5a21ced491ea51f$var$UltimateGuitarParser;
29719
- var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.5.2-canary.0";
29719
+ var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.5.2";
29720
29720
  var $2a7926da41d163b3$export$191a710ad3c9a989 = {
29721
29721
  configure: $181068e44290b873$export$8d21e34596265fa2,
29722
29722
  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
- : ${n.message}`,{cause:n})}}calculateX(r,e=0,n=0){switch(r){case"center":return this.backend.pageSize.width/2-e/2+n;case"right":return this.backend.pageSize.width-this.context.margins.right-e+n;default:return typeof r=="number"?this.context.margins.left+r+n:this.context.margins.left+n}}getAvailableWidth(){return this.backend.pageSize.width-this.context.margins.left-this.context.margins.right}},Zj=Lf,Ff=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(n=>{this.renderLines(n)}),e.addSpacing&&(this.y+=this.getParagraphSpacing())})}renderLines(r){r.forEach(e=>{this.renderLineLayout(e)})}renderLineLayout(r){let{items:e,lineHeight:n,line:l}=r;if(this.hasColumnBreak(r)){this.moveToNextColumn();return}this.y+n>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+=n,this.x=this.getColumnStartX()}hasColumnBreak(r){let{items:e}=r;return e.length===1&&e[0].item instanceof X&&Qf(e[0].item)}renderItem(r,e,n,l,u,d,x){r instanceof J?this.renderChordLyricsPair(r,e,n,l,u,d):r instanceof X?r.isSectionDelimiter()?this.addSectionLabel(r.label,n,x):ls(r)&&this.addComment(r.value,n,x):r instanceof pe&&this.addTextElement(r.content,n,u,"lyrics")}renderChordLyricsPair(r,e,n,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,n,D,"chord")}M&&M.trim()!==""&&this.addTextElement(M,n,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 n=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 n&&l?(u=e,d=u+this.getMaxChordHeight(r)+x):n&&!l?u=e:!n&&l&&(d=e),{chordsYOffset:u,lyricsYOffset:d}}getMaxChordHeight(r){return r.reduce((e,{chordHeight:n})=>Math.max(e,n||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,n,l){let u=this.getFontForType(l),{width:d,height:x}=this.measureText(r,u);this.elements.push({x:e,y:n,width:d,height:x,content:r,type:l,style:u,page:this.currentPage,column:this.currentColumn})}addSectionLabel(r,e,n){this.addTextElement(r,e,n,"sectionLabel")}addComment(r,e,n){this.addTextElement(r,e,n,"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(),n=this.getColumnSpacing();return r+(this.currentColumn-1)*(e+n)}getColumnBottomY(){return this.getPageHeight()-this.getBottomMargin()-this.getFooterHeight()}getColumnWidth(){let r=this.getPageWidth()-this.getLeftMargin()-this.getRightMargin(),e=this.getColumnCount(),n=this.getColumnSpacing();return(r-(e-1)*n)/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}},Jj=Ff,Ef=class extends Jj{constructor(r,e,n){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=n,this.styler=new qj({cssClassPrefix:n.cssClassPrefix,cssClasses:n.cssClasses}),!e)throw new Error("Container element is required");this.doc=new Yj(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((n,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 n=this.createLayoutBackend(r,e);return new Zj(n,{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:(n,l,u)=>this.renderHtmlText(n,l,u),getTextWidth:(n,l)=>this.doc.getTextWidth(n,l),splitTextToSize:(n,l,u)=>this.doc.splitTextToSize(n,l,u),setFontStyle:n=>{this.currentLayoutFontStyle=n},setTextItem:n=>{this.currentLayoutTextItem=n},addElement:(n,l,u)=>this.doc.addElement(n,l,u),addImage:(n,l,u,d,x,M)=>this.renderHtmlImage(n,u,d,x,M),line:(n,l,u,d)=>this.renderHtmlLine(n,l,u,d),setLineStyle:n=>{this.currentLineStyle=n},resetDash:()=>{}}}renderHtmlText(r,e,n){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,n)}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,n,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,n)}renderHtmlLine(r,e,n,l){let u=document.createElement("div");u.className=`${this.styler.prefix}line`;let d=this.currentLineStyle;u.style.width=`${n-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,n)=>{this.renderParagraph(e,n,r)})}renderParagraph(r,e,n){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<n.length-1&&(this.y+=this.getParagraphSpacing()),this.x=this.getColumnStartX(),this.elements=u}groupElementsByPageAndColumn(r){let e={};return r.forEach(n=>{let l=`${n.page}-${n.column}`;e[l]||(e[l]=[]),e[l].push(n)}),e}renderLineItems(r){let e={column:this.currentColumn,page:this.currentPage};r.forEach(n=>{e=this.renderSingleLine(n,e)})}renderSingleLine(r,e){if(this.hasColumnBreak(r))return this.moveToNextColumn(),this.getCurrentContext();let n=this.handleColumnOverflow(r.lineHeight,e);return this.renderLineContent(r,n),n}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:n,lineHeight:l,line:u}=r,d=this.y,{chordsYOffset:x,lyricsYOffset:M}=this.calculateChordLyricYOffsets(n,d),D=this.x;n.forEach(w=>{this.renderMeasuredItem(w,D,d,x,M,n,u,e),D+=w.width}),this.y+=l,this.x=this.getColumnStartX()}renderMeasuredItem(r,e,n,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,n,M):D instanceof pe&&(this.addTextElement(D.content,e,u,"lyrics"),this.updatePosition(M.column,M.page))}renderChordLyricsPairItem(r,e,n,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(n,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,n,l){let u=r.attributes.__titleSeparator==="true";r.isSectionDelimiter()?(this.addSectionLabel(r.label,e,n,{noUnderline:u}),this.updatePosition(l.column,l.page)):ls(r)&&(this.addComment(r.value,e,n,{noUnderline:u}),this.updatePosition(l.column,l.page))}updatePosition(r,e){let n=this.elements[this.elements.length-1];n.column=r,n.page=e}addSectionLabel(r,e,n,l={}){this.addTextElementWithOptions(r,e,n,"sectionLabel",l)}addComment(r,e,n,l={}){this.addTextElementWithOptions(r,e,n,"comment",l)}addTextElementWithOptions(r,e,n,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:n,width:x,height:M,content:r,type:l,style:D,page:this.currentPage,column:this.currentColumn})}measureText(r,e){let{w:n,h:l}=this.doc.getTextDimensions(r,e);return{width:n,height:l}}calculateChordBaseline(r,e,n){let l=this.getFontConfiguration("chord"),{height:u}=this.measureText(n,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 n=this.getElementsForPage(e);n.length>0&&(this.doc.setPage(e),n.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,n=Number.MAX_VALUE,l=Number.MIN_VALUE,u=Number.MIN_VALUE;return r.forEach(d=>{e=Math.min(e,d.x),n=Math.min(n,d.y),l=Math.max(l,d.x+d.width),u=Math.max(u,d.y+d.height)}),{minX:e,minY:n,maxX:l,maxY:u}}createParagraphDiv(r,e){let n=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:`${n}px`,height:`${l}px`}),u}createElementGroupDiv(r,e,n,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=n,u}renderElementGroup(r,e,n,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}-${n}`,`${x}${l.sectionType}`]);r.forEach(D=>{this.renderElement(D,d,M)}),this.doc.addElement(M,d.minX,d.minY)}renderElement(r,e,n){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),n.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:n}=this.styler;e.className=`${n}element ${n}${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:n,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d}=this.configuration.layout.sections.global;return new Uj(r,e,this.configuration.layout,{columnCount:n,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d})}generateDimensionCacheKey(){let{width:r,height:e}=this.doc.pageSize,{layout:n}=this.configuration,{global:l}=n.sections;return[r,e,n.global.margins.left,n.global.margins.right,n.global.margins.top,n.global.margins.bottom,n.header?.height||0,l.columnCount,l.columnSpacing,l.minColumnWidth||0,l.maxColumnWidth||0].join("-")}getExtraMetadata(r,e){let n={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);n.capoKey=T7(u)[d]}return n}},Qj=Ef,Df=class{constructor(r,e,n){this.measurer=r,this.config=e,this.song=n}measureLineItems(r,e=!1){let n=[];for(let l=0;l<r.items.length;l+=1){let u=r.items[l],d=r.items[l+1]??null;if(Zs(u)){let x=this.processChordLyricsPair(u,d,r,e);n.push(...x)}else if(_7(u))n.push(this.processSoftLineBreak(u));else if(Js(u)){let x=this.processTag(u);n.push(...x)}else n.push({item:null,width:0})}return n}processChordLyricsPair(r,e,n,l=!1){let u=this.handleLyricsOnlyMode(r,e,l);if(u)return u;let d=this.splitChordLyricsPair(r,l);return this.processSplitItems(d,e,n,l)}handleLyricsOnlyMode(r,e,n){if(!n)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||!Zs(r))return;let n=r,l=n.lyrics||"";(l.startsWith(" -")||l.startsWith("-"))&&(e(),n.lyrics=this.removeHyphens(l))}processSplitItems(r,e,n,l){return r.map(u=>this.processSingleSplitItem(u,e,n,l)).filter(u=>u!==null)}processSingleSplitItem(r,e,n,l){return r instanceof pe?this.processSoftLineBreak(r):r instanceof J?this.measureChordLyricsPair(r,e,n,l):null}measureChordLyricsPair(r,e,n,l){let{chords:u,lyrics:d}=this.getAdjustedChordsAndLyrics(r,l);if(l&&d==="")return{item:null,width:0};let x=this.renderChordText(u,n),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,n,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,n,l);return{totalWidth:Math.max(D,M),chordHeight:r?this.measurer.measureTextHeight(r,u):0}}getAdjustedChordWidth(r,e,n,l,u){let d=l&&Zs(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(n+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 n=ls(r)?this.config.fonts.comment:this.config.fonts.sectionLabel,l=this.config.width,u=r.label||r.value||"";this.measurer.splitTextToSize(u,l,n).forEach(x=>{let M=this.measurer.measureTextWidth(x,n);e.push(this.createMeasuredTagItem(r,x,M))})}else e.push({item:r,width:0});return e}createMeasuredTagItem(r,e,n){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:n}}splitMeasuredItem(r,e){if(!(r.item instanceof J)||!r.item.lyrics)return[r,null];let{lyrics:n}=r.item,l=this.config.fonts.lyrics,u=this.measurer.splitTextToSize(n,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:n,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(n,M,u));else if(D===0&&d.length>1){let w=M;w+=",",x.push(new J(n,w,u))}}),x}findNextItemWithLyrics(r,e,n){return[...r,...e.slice(n)].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)}},wf=class{constructor(r){this.config=r}createLineLayout(r,e){let n=this.analyzeLineContent(r),l=this.determineLineType(n),u=Math.max(...r.map(x=>x.chordHeight||0)),d=this.calculateLineHeight(n,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:n,fontConfig:l}=this.getBaseHeightAndFont(r,e),u=l?.lineHeight||1;return n*u}getBaseHeightAndFont(r,e){let n=this.config.linePadding;if(r.hasChords&&r.hasLyrics){let l=this.config.fonts.lyrics;return n+=e+this.config.chordLyricSpacing+l.size,{baseHeight:n,fontConfig:l}}return r.hasChords?{baseHeight:n+e,fontConfig:null}:r.hasLyrics?this.addFontHeight(n,this.config.fonts.lyrics):r.hasComments?this.addFontHeight(n,this.config.fonts.comment):r.hasSectionLabel?this.addFontHeight(n,this.config.fonts.sectionLabel):{baseHeight:n,fontConfig:null}}addFontHeight(r,e){return{baseHeight:r+e.size,fontConfig:e}}createColumnBreakLayout(){return{type:"Tag",line:new ws,items:[{item:new X("column_break"),width:0}],lineHeight:0}}},Gf=class{constructor(r,e){this.itemProcessor=r,this.layoutFactory=e}breakLineIntoLayouts(r,e,n=!1){let l=this.itemProcessor.measureLineItems(r,n),u=this.consolidateConsecutiveSoftBreaks(l);return this.breakContent(u,e,r)}breakContent(r,e,n){if(r.length===0)return[];let{totalWidth:l,softBreakIndices:u}=this.analyzeContent(r);if(this.shouldReturnSingleLayout(l,e))return[this.layoutFactory.createLineLayout(r,n)];if(u.length===0)return this.handleNoSoftBreaks(r,e,n);let{firstChunk:d,secondChunk:x}=this.splitAtBestSoftBreak(r,u,l);return d.length===0?this.breakContent(x,e,n):[this.layoutFactory.createLineLayout(d,n),...this.breakContent(x,e,n)]}handleNoSoftBreaks(r,e,n){let l=this.findBreakIndex(r,e);if(l===-1)return[this.layoutFactory.createLineLayout(r,n)];if(l===0)return this.handleOversizedFirstItem(r,e,n);let u=r.slice(0,l),d=r.slice(l);return this.removeTrailingComma(u),[this.layoutFactory.createLineLayout(u,n),...this.breakContent(d,e,n)]}consolidateConsecutiveSoftBreaks(r){let e=[];for(let n=0;n<r.length;n+=1){let l=r[n];e.push(l),l.item instanceof pe&&(n=this.skipConsecutiveSoftBreaks(r,n))}return e}skipConsecutiveSoftBreaks(r,e){let n=e;for(;n+1<r.length&&r[n+1].item instanceof pe;)n+=1;return n}findBreakIndex(r,e){let n=0;for(let l=0;l<r.length;l+=1){if(n+r[l].width>e)return l;n+=r[l].width}return-1}handleOversizedFirstItem(r,e,n){let[l,u]=this.itemProcessor.splitMeasuredItem(r[0],e),d=u?[u,...r.slice(1)]:r.slice(1);return[this.layoutFactory.createLineLayout([l],n),...this.breakContent(d,e,n)]}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,n){let l=n/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 n=0;for(let l=0;l<e&&l<r.length;l+=1)n+=r[l].width;return n}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 n=r.item,l=this.measureChordAndLyricWidths(n),u=this.adjustChordWidth(n,l,e);return Math.max(u,l.lyricsWidth)}measureChordAndLyricWidths(r){let e=this.itemProcessor.config.fonts.chord,n=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,n):0;return{chordWidth:l,lyricsWidth:u}}adjustChordWidth(r,e,n){if(this.shouldSkipChordSpacing(e.chordWidth,n))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,n){let l=this.itemProcessor.findNextItemWithLyrics(r,e,n);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 ws,items:[{item:new X("column_break"),width:0}],lineHeight:0}}function eP(i){return i.reduce((r,e)=>{let n=e.reduce((l,u)=>l+u.lineHeight,0);return r+n},0)}function sP(i){return i.length===1&&i[0].items.length===1&&i[0].items[0].item instanceof X&&Qf(i[0].items[0].item)}var Tf=class{constructor(r){this.chordLyricLineCount=r,this.totalChordLyricPairLines=r}splitParagraph(r,e,n,l){let u=this.flattenLineLayouts(r),d=this.trySplitParagraph(r,u,e,l);return d||(e!==n?[[ni()],...r]:r)}trySplitParagraph(r,e,n,l){let u=this.findAcceptableSplits(e),d=this.selectSplit(u,n,l);return d?this.buildSplitResult(r,d.index):null}selectSplit(r,e,n){for(let l=r.length-1;l>=0;l-=1){let u=r[l];if(e+u.heightFirstPart<=n)return u}return null}buildSplitResult(r,e){let{firstPart:n,secondPart:l}=this.partitionLineLayouts(r,e);return[...n,[ni()],...l]}flattenLineLayouts(r){let e=[];return r.forEach(n=>{n.forEach(l=>{e.push(l)})}),e}findAcceptableSplits(r){let e=0,n=0;return r.slice(0,-1).reduce((l,u,d)=>{e+=u.lineHeight,n+=u.type==="ChordLyricsPair"?1:0;let x=this.totalChordLyricPairLines-n;return n>=2&&x>=2&&l.push({index:d+1,heightFirstPart:e}),l},[])}partitionLineLayouts(r,e){let n=r.reduce((l,u)=>this.partitionReducer(l,u,e),{firstPart:[],secondPart:[],processed:0});return{firstPart:n.firstPart,secondPart:n.secondPart}}partitionReducer(r,e,n){let l=e.length,u=r.processed+l<=n,d=r.processed>=n;if(u)r.firstPart.push(e);else if(d)r.secondPart.push(e);else{let x=n-r.processed;r.firstPart.push(e.slice(0,x)),r.secondPart.push(e.slice(x))}return r.processed+=l,r}},Mf=class{splitParagraph(r,e,n,l){if(r.length===0)return[];let{splitIndex:u,heightFirstPart:d}=this.findSplitMetadata(r);return u===null?this.prependColumnBreakIfNeeded(r,e,n):e+d<=l?this.buildSplitResult(r,u):this.prependColumnBreakIfNeeded(r,e,n)}findSplitMetadata(r){let e=0,n=0;for(let l=0;l<r.length;l+=1){let{height:u,chordCount:d}=this.summarizeLineLayout(r[l]);if(e+=d,n+=u,e>=2)return{splitIndex:l+1,heightFirstPart:n}}return{splitIndex:null,heightFirstPart:n}}summarizeLineLayout(r){return r.reduce((e,n)=>({height:e.height+n.lineHeight,chordCount:e.chordCount+(n.type==="ChordLyricsPair"?1:0)}),{height:0,chordCount:0})}buildSplitResult(r,e){let n=r.slice(0,e),l=r.slice(e);return n.concat([[ni()]]).concat(l)}prependColumnBreakIfNeeded(r,e,n){return e===n?r:[[ni()]].concat(r)}},vf=class{splitParagraph(r,e,n,l){let u=[];return e!==n&&u.push([ni()]),u.concat(r)}},jf=class{splitParagraph(r,e,n,l,u){return this.createStrategy(u).splitParagraph(r,e,n,l)}createStrategy(r){return r<=3?new vf:r===4?new Mf:new Tf(r)}},Pf=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}},tP=Pf,ci=class{constructor(r,e,n){this.song=r,this.measurer=e,this.config=n,this.sectionCache=new Map,this.processRepeatedSections(),this.itemProcessor=new Df(this.measurer,this.config,this.song),this.layoutFactory=new wf(n),this.lineBreaker=new Gf(this.itemProcessor,this.layoutFactory),this.paragraphSplitter=new jf}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||!Js(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:n}=this.song.clone();n.forEach((l,u)=>{this.processParagraph({paragraph:l,index:u,processedParagraphs:r,skipIndices:e,bodyParagraphs:n})}),this.song.renderParagraphs=r,this.sectionCache.clear()}processParagraph(r){let{paragraph:e,index:n,skipIndices:l,processedParagraphs:u}=r;if(this.shouldSkipParagraphIndex(n,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 n=this.cloneParagraph(e.paragraph);if(this.cacheFirstOccurrence(r,n,e.processedParagraphs))return;let l=this.sectionCache.get(r);l&&this.handleRepeatedSection({cachedParagraph:l,currentParagraph:n,processedParagraphs:e.processedParagraphs,skipIndices:e.skipIndices,startIndex:e.index,bodyParagraphs:e.bodyParagraphs})}cacheFirstOccurrence(r,e,n){return this.sectionCache.has(r)?!1:(this.sectionCache.set(r,e),n.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:n,startIndex:l,bodyParagraphs:u}=r,d=[this.createTitleOnlyParagraph(e)];for(let x=l+1;x<u.length;x+=1){let M=u[x];if(!n.has(x))if(this.shouldIncludeTitle(M))d.push(this.createTitleOnlyParagraph(M)),n.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:n,processedParagraphs:l}=r,u=new Et;this.buildFullModeLines(n,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 n=r.lines[0],l=n.items[0];return l&&Js(l)?[n.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 n=e.lines[0];return r.slice(1).forEach(l=>{if(l.lines.length===0)return;let u=l.lines[0];this.addTitleSeparator(n),u.items.forEach(d=>{n.items.push(this.cloneItem(d))})}),e}addTitleSeparator(r){r.items.push(...this.buildTitleSeparatorItems())}buildTitleSeparatorItems(){return[new pe(" "),new tP,new pe(" ")]}createTitleOnlyParagraph(r){let e=new Et;if(r.lines.length===0)return e;let n=r.lines[0],l=new ws({type:n.type,items:[]});return n.items.forEach(u=>{Js(u)&&l.addItem(this.cloneItem(u))}),l.items.length===0&&(l.items=[...n.items.map(u=>this.cloneItem(u))]),e.addLine(l),e}cloneParagraph(r){let e=new Et;return r.lines.forEach(n=>e.addLine(n.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(n=>{e=this.processParagraphLayout(n,r,e)}),r}processParagraphLayout(r,e,n){let l=this.computeParagraphLayout(r,this.config.columnWidth,this.config.displayLyricsOnly),u=this.computeLineTypeCounts(l);if(this.shouldSkipParagraphLayout(u))return n;let d=this.adjustParagraphLayouts(l,n,u.chordLyricLineCount),x=this.calculateNextSimulationState(d,n);return this.addParagraphLayout(e,r,d),x}computeLineTypeCounts(r){let e=0,n=0;return r.forEach(l=>{l.forEach(u=>{u.type==="ChordLyricsPair"?e+=1:(u.type==="Comment"||u.type==="SectionLabel")&&(n+=1)})}),{chordLyricLineCount:e,nonLyricLineCount:n}}shouldSkipParagraphLayout(r){return!!this.config.displayLyricsOnly&&r.nonLyricLineCount===1&&r.chordLyricLineCount===0}adjustParagraphLayouts(r,e,n){let l=eP(r);return e.currentY+l<=this.config.columnBottomY?r:this.paragraphSplitter.splitParagraph(r,e.currentY,this.config.minY,this.config.columnBottomY,n)}calculateNextSimulationState(r,e){let{currentY:n,currentColumn:l}=e;return r.forEach(u=>{if(sP(u))l+=1,l>(this.config.columnCount||1)&&(l=1),n=this.config.minY;else{let d=u.reduce((x,M)=>x+M.lineHeight,0);n+=d}}),n+=this.config.paragraphSpacing,{currentY:n,currentColumn:l}}addParagraphLayout(r,e,n){r.push({units:n,addSpacing:!0,sectionType:e.type})}computeParagraphLayout(r,e,n=!1){let l=[];return r.lines.forEach(u=>{if(dr(u)){let d=this.lineBreaker.breakLineIntoLayouts(u,e,n);l.push(d)}}),l}},Bf=class extends Vj{constructor(r){super(),this.song=new Gs,this.renderer=null,this.container=r}getDefaultConfiguration(){return E7()}format(r){for(this.song=r;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.renderer=new Qj(r,this.container,this.configuration),this.renderer.initialize();let n=this.createLayoutEngine().computeParagraphLayouts();this.renderer.render(n)}createLayoutEngine(){if(!this.renderer)throw new Error("Renderer not initialized");let r=this.renderer.getDocumentMetadata(),{dimensions:e}=r,n={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,n)}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)}},Y7=Bf,k5=/^\[(Verse.*)]/i,O5=/^\[(Chorus.*)]/i,W5=/^\[(Bridge.*)]/i,H5=/^\[(Intro|Outro|Instrumental|Interlude|Solo|Pre-Chorus)( \d+)?]/i,rP=/^(\w+):\s*(.+)$/,K5=/^\[([^\]]+)]/,V5=/\s+(x\d+)\s*$/i,U5=/^\s*(((?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?([^/\s]*)(\/(?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?)?)(\s|$)+)+(\s|$)+/,Y5={[Qs]:bn,[Fs]:bi,[ur]:un,[Gt]:ii},Na={[Qs]:Of,[Fs]:mn,[ur]:kf,[Gt]:Ka},If=class extends Zf{constructor({preserveWhitespace:r=!0}={}){super({preserveWhitespace:r},!1),this.currentSectionType=null,this.pendingRepeatNotation=null}parseLine(r){this.isSectionEnd()&&this.endSection();let{cleanLine:e,repeatNotation:n}=this.extractRepeatNotation(r);this.pendingRepeatNotation=n,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=U5.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 k5.test(r)||O5.test(r)||W5.test(r)||H5.test(r)||K5.test(r)||U5.test(r)||r.trim().length===0}parseChordsOnly(r){this.parseLyricsWithChords(r,""),this.applyRepeatNotation()}parseLyricsWithChords(r,e){let n=this.processCharacters(r,e);if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.lyrics+=e.substring(n),this.chordLyricsPair.chords=this.chordLyricsPair.chords.trim(),this.chordLyricsPair.lyrics&&(this.chordLyricsPair.lyrics=this.chordLyricsPair.lyrics.trim()),this.applyRepeatNotation()}processCharacters(r,e){let n=P7(e),l=-1;for(let u=0,d=r.length;u<d;u+=1)this.addCharacter(r[u],r[u+1]),l=this.mapLyricsCharacter(n,u,e,l),this.processingText=!/\s/.test(r[u]);return l>=0?l+1:0}addCharacter(r,e){let n=/\s/.test(r);if(n||this.ensureChordLyricsPairInitialized(),!n||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(V5);return e?{cleanLine:r.replace(V5,""),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(rP);if(!e)return!1;let n=e[1].toLowerCase();if(!Xa.includes(n))return!1;let l=n===br?this.extractCapoValue(e[2]):e[2].trim();return this.startNewLine(),this.songBuilder.addTag(new X(n,l)),!0}extractCapoValue(r){let[,e]=r.match(/^(\d+)/)||[];return e||r.trim()}parseVerseDirective(r){let e=r.match(k5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(Qs,n),!0}parseChorusDirective(r){let e=r.match(O5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(Fs,n),!0}parseBridgeDirective(r){let e=r.match(W5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(ur,n),!0}parsePartDirective(r){let e=r.match(H5);if(!e)return!1;this.startNewLine();let n=e[1]+(e[2]||"");return this.startSection(Gt,n),!0}parseMetadata(r){let e=r.match(K5);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(ln,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 Na&&this.startNewLine(),this.endSection({addNewLine:!1})}startSection(r,e){this.currentSectionType&&this.endSection(),this.currentSectionType=r,this.songBuilder.setCurrentProperties(r),r in Y5&&this.songBuilder.addTag(new X(Y5[r],e))}endSection({addNewLine:r=!0}={}){this.currentSectionType!==null&&this.currentSectionType in Na&&(this.songLine&&this.songLine.isEmpty()?this.songLine.addTag(new X(Na[this.currentSectionType])):this.songBuilder.addLine().addTag(new X(Na[this.currentSectionType])),r&&this.startNewLine()),this.songBuilder.setCurrentProperties(Es),this.currentSectionType=null}startNewLine(){this.songLine=this.songBuilder.addLine()}},q7=If,X7="15.5.2-canary.0",iP={configure:Lj,getDefaultConfig:gr,getHTMLDefaultConfig:F7,getMeasuredHtmlDefaultConfig:E7,getPDFDefaultConfig:Pv,mergeConfigs:Dt},Z7=iP,aP={getCapos:T7,getKeys:Xv},J7=aP,nP={},cP={CHORUS:Fs,Chord:Ds,ChordDefinition:on,ChordLyricsPair:J,ChordProFormatter:D7,MeasuredHtmlFormatter:Y7,ChordProParser:Xf,ChordSheetParser:Zf,ChordSheetSerializer:gn,ChordsOverWordsFormatter:W7,ChordsOverWordsParser:K7,Comment:Xs,Composite:en,HtmlDivFormatter:V7,HtmlTableFormatter:U7,INDETERMINATE:rn,Line:ws,Literal:ke,Metadata:or,NONE:Es,Paragraph:Et,PART:Gt,SoftLineBreak:pe,Song:Gs,TAB:fi,TEXTBLOCK:oi,Tag:X,Ternary:fr,TextFormatter:so,UltimateGuitarParser:q7,VERSE:Qs,BaseMeasurer:lr,DomMeasurer:mr,CanvasMeasurer:tn,LayoutEngine:ci,formatterConfiguration:Z7,keyHelpers:J7,version:X7,templateHelpers:{isEvaluatable:ui,isChordLyricsPair:Zs,lineHasContents:dr,isTag:Js,isComment:ls,isImage:dn,stripHTML:pn,each:Ls,when:fe,hasTextContents:gi,lineClasses:xn,paragraphClasses:yn,evaluate:hi,fontStyleTag:ze,renderChord:et,hasChordContents:Rf,pangoToHtml:hn,stripPangoMarkup:wt}};lM(H.exports,nP)});return fP();})();
230
+ : ${n.message}`,{cause:n})}}calculateX(r,e=0,n=0){switch(r){case"center":return this.backend.pageSize.width/2-e/2+n;case"right":return this.backend.pageSize.width-this.context.margins.right-e+n;default:return typeof r=="number"?this.context.margins.left+r+n:this.context.margins.left+n}}getAvailableWidth(){return this.backend.pageSize.width-this.context.margins.left-this.context.margins.right}},Zj=Lf,Ff=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(n=>{this.renderLines(n)}),e.addSpacing&&(this.y+=this.getParagraphSpacing())})}renderLines(r){r.forEach(e=>{this.renderLineLayout(e)})}renderLineLayout(r){let{items:e,lineHeight:n,line:l}=r;if(this.hasColumnBreak(r)){this.moveToNextColumn();return}this.y+n>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+=n,this.x=this.getColumnStartX()}hasColumnBreak(r){let{items:e}=r;return e.length===1&&e[0].item instanceof X&&Qf(e[0].item)}renderItem(r,e,n,l,u,d,x){r instanceof J?this.renderChordLyricsPair(r,e,n,l,u,d):r instanceof X?r.isSectionDelimiter()?this.addSectionLabel(r.label,n,x):ls(r)&&this.addComment(r.value,n,x):r instanceof pe&&this.addTextElement(r.content,n,u,"lyrics")}renderChordLyricsPair(r,e,n,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,n,D,"chord")}M&&M.trim()!==""&&this.addTextElement(M,n,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 n=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 n&&l?(u=e,d=u+this.getMaxChordHeight(r)+x):n&&!l?u=e:!n&&l&&(d=e),{chordsYOffset:u,lyricsYOffset:d}}getMaxChordHeight(r){return r.reduce((e,{chordHeight:n})=>Math.max(e,n||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,n,l){let u=this.getFontForType(l),{width:d,height:x}=this.measureText(r,u);this.elements.push({x:e,y:n,width:d,height:x,content:r,type:l,style:u,page:this.currentPage,column:this.currentColumn})}addSectionLabel(r,e,n){this.addTextElement(r,e,n,"sectionLabel")}addComment(r,e,n){this.addTextElement(r,e,n,"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(),n=this.getColumnSpacing();return r+(this.currentColumn-1)*(e+n)}getColumnBottomY(){return this.getPageHeight()-this.getBottomMargin()-this.getFooterHeight()}getColumnWidth(){let r=this.getPageWidth()-this.getLeftMargin()-this.getRightMargin(),e=this.getColumnCount(),n=this.getColumnSpacing();return(r-(e-1)*n)/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}},Jj=Ff,Ef=class extends Jj{constructor(r,e,n){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=n,this.styler=new qj({cssClassPrefix:n.cssClassPrefix,cssClasses:n.cssClasses}),!e)throw new Error("Container element is required");this.doc=new Yj(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((n,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 n=this.createLayoutBackend(r,e);return new Zj(n,{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:(n,l,u)=>this.renderHtmlText(n,l,u),getTextWidth:(n,l)=>this.doc.getTextWidth(n,l),splitTextToSize:(n,l,u)=>this.doc.splitTextToSize(n,l,u),setFontStyle:n=>{this.currentLayoutFontStyle=n},setTextItem:n=>{this.currentLayoutTextItem=n},addElement:(n,l,u)=>this.doc.addElement(n,l,u),addImage:(n,l,u,d,x,M)=>this.renderHtmlImage(n,u,d,x,M),line:(n,l,u,d)=>this.renderHtmlLine(n,l,u,d),setLineStyle:n=>{this.currentLineStyle=n},resetDash:()=>{}}}renderHtmlText(r,e,n){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,n)}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,n,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,n)}renderHtmlLine(r,e,n,l){let u=document.createElement("div");u.className=`${this.styler.prefix}line`;let d=this.currentLineStyle;u.style.width=`${n-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,n)=>{this.renderParagraph(e,n,r)})}renderParagraph(r,e,n){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<n.length-1&&(this.y+=this.getParagraphSpacing()),this.x=this.getColumnStartX(),this.elements=u}groupElementsByPageAndColumn(r){let e={};return r.forEach(n=>{let l=`${n.page}-${n.column}`;e[l]||(e[l]=[]),e[l].push(n)}),e}renderLineItems(r){let e={column:this.currentColumn,page:this.currentPage};r.forEach(n=>{e=this.renderSingleLine(n,e)})}renderSingleLine(r,e){if(this.hasColumnBreak(r))return this.moveToNextColumn(),this.getCurrentContext();let n=this.handleColumnOverflow(r.lineHeight,e);return this.renderLineContent(r,n),n}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:n,lineHeight:l,line:u}=r,d=this.y,{chordsYOffset:x,lyricsYOffset:M}=this.calculateChordLyricYOffsets(n,d),D=this.x;n.forEach(w=>{this.renderMeasuredItem(w,D,d,x,M,n,u,e),D+=w.width}),this.y+=l,this.x=this.getColumnStartX()}renderMeasuredItem(r,e,n,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,n,M):D instanceof pe&&(this.addTextElement(D.content,e,u,"lyrics"),this.updatePosition(M.column,M.page))}renderChordLyricsPairItem(r,e,n,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(n,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,n,l){let u=r.attributes.__titleSeparator==="true";r.isSectionDelimiter()?(this.addSectionLabel(r.label,e,n,{noUnderline:u}),this.updatePosition(l.column,l.page)):ls(r)&&(this.addComment(r.value,e,n,{noUnderline:u}),this.updatePosition(l.column,l.page))}updatePosition(r,e){let n=this.elements[this.elements.length-1];n.column=r,n.page=e}addSectionLabel(r,e,n,l={}){this.addTextElementWithOptions(r,e,n,"sectionLabel",l)}addComment(r,e,n,l={}){this.addTextElementWithOptions(r,e,n,"comment",l)}addTextElementWithOptions(r,e,n,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:n,width:x,height:M,content:r,type:l,style:D,page:this.currentPage,column:this.currentColumn})}measureText(r,e){let{w:n,h:l}=this.doc.getTextDimensions(r,e);return{width:n,height:l}}calculateChordBaseline(r,e,n){let l=this.getFontConfiguration("chord"),{height:u}=this.measureText(n,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 n=this.getElementsForPage(e);n.length>0&&(this.doc.setPage(e),n.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,n=Number.MAX_VALUE,l=Number.MIN_VALUE,u=Number.MIN_VALUE;return r.forEach(d=>{e=Math.min(e,d.x),n=Math.min(n,d.y),l=Math.max(l,d.x+d.width),u=Math.max(u,d.y+d.height)}),{minX:e,minY:n,maxX:l,maxY:u}}createParagraphDiv(r,e){let n=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:`${n}px`,height:`${l}px`}),u}createElementGroupDiv(r,e,n,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=n,u}renderElementGroup(r,e,n,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}-${n}`,`${x}${l.sectionType}`]);r.forEach(D=>{this.renderElement(D,d,M)}),this.doc.addElement(M,d.minX,d.minY)}renderElement(r,e,n){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),n.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:n}=this.styler;e.className=`${n}element ${n}${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:n,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d}=this.configuration.layout.sections.global;return new Uj(r,e,this.configuration.layout,{columnCount:n,columnSpacing:l,minColumnWidth:u,maxColumnWidth:d})}generateDimensionCacheKey(){let{width:r,height:e}=this.doc.pageSize,{layout:n}=this.configuration,{global:l}=n.sections;return[r,e,n.global.margins.left,n.global.margins.right,n.global.margins.top,n.global.margins.bottom,n.header?.height||0,l.columnCount,l.columnSpacing,l.minColumnWidth||0,l.maxColumnWidth||0].join("-")}getExtraMetadata(r,e){let n={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);n.capoKey=T7(u)[d]}return n}},Qj=Ef,Df=class{constructor(r,e,n){this.measurer=r,this.config=e,this.song=n}measureLineItems(r,e=!1){let n=[];for(let l=0;l<r.items.length;l+=1){let u=r.items[l],d=r.items[l+1]??null;if(Zs(u)){let x=this.processChordLyricsPair(u,d,r,e);n.push(...x)}else if(_7(u))n.push(this.processSoftLineBreak(u));else if(Js(u)){let x=this.processTag(u);n.push(...x)}else n.push({item:null,width:0})}return n}processChordLyricsPair(r,e,n,l=!1){let u=this.handleLyricsOnlyMode(r,e,l);if(u)return u;let d=this.splitChordLyricsPair(r,l);return this.processSplitItems(d,e,n,l)}handleLyricsOnlyMode(r,e,n){if(!n)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||!Zs(r))return;let n=r,l=n.lyrics||"";(l.startsWith(" -")||l.startsWith("-"))&&(e(),n.lyrics=this.removeHyphens(l))}processSplitItems(r,e,n,l){return r.map(u=>this.processSingleSplitItem(u,e,n,l)).filter(u=>u!==null)}processSingleSplitItem(r,e,n,l){return r instanceof pe?this.processSoftLineBreak(r):r instanceof J?this.measureChordLyricsPair(r,e,n,l):null}measureChordLyricsPair(r,e,n,l){let{chords:u,lyrics:d}=this.getAdjustedChordsAndLyrics(r,l);if(l&&d==="")return{item:null,width:0};let x=this.renderChordText(u,n),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,n,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,n,l);return{totalWidth:Math.max(D,M),chordHeight:r?this.measurer.measureTextHeight(r,u):0}}getAdjustedChordWidth(r,e,n,l,u){let d=l&&Zs(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(n+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 n=ls(r)?this.config.fonts.comment:this.config.fonts.sectionLabel,l=this.config.width,u=r.label||r.value||"";this.measurer.splitTextToSize(u,l,n).forEach(x=>{let M=this.measurer.measureTextWidth(x,n);e.push(this.createMeasuredTagItem(r,x,M))})}else e.push({item:r,width:0});return e}createMeasuredTagItem(r,e,n){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:n}}splitMeasuredItem(r,e){if(!(r.item instanceof J)||!r.item.lyrics)return[r,null];let{lyrics:n}=r.item,l=this.config.fonts.lyrics,u=this.measurer.splitTextToSize(n,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:n,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(n,M,u));else if(D===0&&d.length>1){let w=M;w+=",",x.push(new J(n,w,u))}}),x}findNextItemWithLyrics(r,e,n){return[...r,...e.slice(n)].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)}},wf=class{constructor(r){this.config=r}createLineLayout(r,e){let n=this.analyzeLineContent(r),l=this.determineLineType(n),u=Math.max(...r.map(x=>x.chordHeight||0)),d=this.calculateLineHeight(n,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:n,fontConfig:l}=this.getBaseHeightAndFont(r,e),u=l?.lineHeight||1;return n*u}getBaseHeightAndFont(r,e){let n=this.config.linePadding;if(r.hasChords&&r.hasLyrics){let l=this.config.fonts.lyrics;return n+=e+this.config.chordLyricSpacing+l.size,{baseHeight:n,fontConfig:l}}return r.hasChords?{baseHeight:n+e,fontConfig:null}:r.hasLyrics?this.addFontHeight(n,this.config.fonts.lyrics):r.hasComments?this.addFontHeight(n,this.config.fonts.comment):r.hasSectionLabel?this.addFontHeight(n,this.config.fonts.sectionLabel):{baseHeight:n,fontConfig:null}}addFontHeight(r,e){return{baseHeight:r+e.size,fontConfig:e}}createColumnBreakLayout(){return{type:"Tag",line:new ws,items:[{item:new X("column_break"),width:0}],lineHeight:0}}},Gf=class{constructor(r,e){this.itemProcessor=r,this.layoutFactory=e}breakLineIntoLayouts(r,e,n=!1){let l=this.itemProcessor.measureLineItems(r,n),u=this.consolidateConsecutiveSoftBreaks(l);return this.breakContent(u,e,r)}breakContent(r,e,n){if(r.length===0)return[];let{totalWidth:l,softBreakIndices:u}=this.analyzeContent(r);if(this.shouldReturnSingleLayout(l,e))return[this.layoutFactory.createLineLayout(r,n)];if(u.length===0)return this.handleNoSoftBreaks(r,e,n);let{firstChunk:d,secondChunk:x}=this.splitAtBestSoftBreak(r,u,l);return d.length===0?this.breakContent(x,e,n):[this.layoutFactory.createLineLayout(d,n),...this.breakContent(x,e,n)]}handleNoSoftBreaks(r,e,n){let l=this.findBreakIndex(r,e);if(l===-1)return[this.layoutFactory.createLineLayout(r,n)];if(l===0)return this.handleOversizedFirstItem(r,e,n);let u=r.slice(0,l),d=r.slice(l);return this.removeTrailingComma(u),[this.layoutFactory.createLineLayout(u,n),...this.breakContent(d,e,n)]}consolidateConsecutiveSoftBreaks(r){let e=[];for(let n=0;n<r.length;n+=1){let l=r[n];e.push(l),l.item instanceof pe&&(n=this.skipConsecutiveSoftBreaks(r,n))}return e}skipConsecutiveSoftBreaks(r,e){let n=e;for(;n+1<r.length&&r[n+1].item instanceof pe;)n+=1;return n}findBreakIndex(r,e){let n=0;for(let l=0;l<r.length;l+=1){if(n+r[l].width>e)return l;n+=r[l].width}return-1}handleOversizedFirstItem(r,e,n){let[l,u]=this.itemProcessor.splitMeasuredItem(r[0],e),d=u?[u,...r.slice(1)]:r.slice(1);return[this.layoutFactory.createLineLayout([l],n),...this.breakContent(d,e,n)]}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,n){let l=n/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 n=0;for(let l=0;l<e&&l<r.length;l+=1)n+=r[l].width;return n}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 n=r.item,l=this.measureChordAndLyricWidths(n),u=this.adjustChordWidth(n,l,e);return Math.max(u,l.lyricsWidth)}measureChordAndLyricWidths(r){let e=this.itemProcessor.config.fonts.chord,n=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,n):0;return{chordWidth:l,lyricsWidth:u}}adjustChordWidth(r,e,n){if(this.shouldSkipChordSpacing(e.chordWidth,n))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,n){let l=this.itemProcessor.findNextItemWithLyrics(r,e,n);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 ws,items:[{item:new X("column_break"),width:0}],lineHeight:0}}function eP(i){return i.reduce((r,e)=>{let n=e.reduce((l,u)=>l+u.lineHeight,0);return r+n},0)}function sP(i){return i.length===1&&i[0].items.length===1&&i[0].items[0].item instanceof X&&Qf(i[0].items[0].item)}var Tf=class{constructor(r){this.chordLyricLineCount=r,this.totalChordLyricPairLines=r}splitParagraph(r,e,n,l){let u=this.flattenLineLayouts(r),d=this.trySplitParagraph(r,u,e,l);return d||(e!==n?[[ni()],...r]:r)}trySplitParagraph(r,e,n,l){let u=this.findAcceptableSplits(e),d=this.selectSplit(u,n,l);return d?this.buildSplitResult(r,d.index):null}selectSplit(r,e,n){for(let l=r.length-1;l>=0;l-=1){let u=r[l];if(e+u.heightFirstPart<=n)return u}return null}buildSplitResult(r,e){let{firstPart:n,secondPart:l}=this.partitionLineLayouts(r,e);return[...n,[ni()],...l]}flattenLineLayouts(r){let e=[];return r.forEach(n=>{n.forEach(l=>{e.push(l)})}),e}findAcceptableSplits(r){let e=0,n=0;return r.slice(0,-1).reduce((l,u,d)=>{e+=u.lineHeight,n+=u.type==="ChordLyricsPair"?1:0;let x=this.totalChordLyricPairLines-n;return n>=2&&x>=2&&l.push({index:d+1,heightFirstPart:e}),l},[])}partitionLineLayouts(r,e){let n=r.reduce((l,u)=>this.partitionReducer(l,u,e),{firstPart:[],secondPart:[],processed:0});return{firstPart:n.firstPart,secondPart:n.secondPart}}partitionReducer(r,e,n){let l=e.length,u=r.processed+l<=n,d=r.processed>=n;if(u)r.firstPart.push(e);else if(d)r.secondPart.push(e);else{let x=n-r.processed;r.firstPart.push(e.slice(0,x)),r.secondPart.push(e.slice(x))}return r.processed+=l,r}},Mf=class{splitParagraph(r,e,n,l){if(r.length===0)return[];let{splitIndex:u,heightFirstPart:d}=this.findSplitMetadata(r);return u===null?this.prependColumnBreakIfNeeded(r,e,n):e+d<=l?this.buildSplitResult(r,u):this.prependColumnBreakIfNeeded(r,e,n)}findSplitMetadata(r){let e=0,n=0;for(let l=0;l<r.length;l+=1){let{height:u,chordCount:d}=this.summarizeLineLayout(r[l]);if(e+=d,n+=u,e>=2)return{splitIndex:l+1,heightFirstPart:n}}return{splitIndex:null,heightFirstPart:n}}summarizeLineLayout(r){return r.reduce((e,n)=>({height:e.height+n.lineHeight,chordCount:e.chordCount+(n.type==="ChordLyricsPair"?1:0)}),{height:0,chordCount:0})}buildSplitResult(r,e){let n=r.slice(0,e),l=r.slice(e);return n.concat([[ni()]]).concat(l)}prependColumnBreakIfNeeded(r,e,n){return e===n?r:[[ni()]].concat(r)}},vf=class{splitParagraph(r,e,n,l){let u=[];return e!==n&&u.push([ni()]),u.concat(r)}},jf=class{splitParagraph(r,e,n,l,u){return this.createStrategy(u).splitParagraph(r,e,n,l)}createStrategy(r){return r<=3?new vf:r===4?new Mf:new Tf(r)}},Pf=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}},tP=Pf,ci=class{constructor(r,e,n){this.song=r,this.measurer=e,this.config=n,this.sectionCache=new Map,this.processRepeatedSections(),this.itemProcessor=new Df(this.measurer,this.config,this.song),this.layoutFactory=new wf(n),this.lineBreaker=new Gf(this.itemProcessor,this.layoutFactory),this.paragraphSplitter=new jf}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||!Js(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:n}=this.song.clone();n.forEach((l,u)=>{this.processParagraph({paragraph:l,index:u,processedParagraphs:r,skipIndices:e,bodyParagraphs:n})}),this.song.renderParagraphs=r,this.sectionCache.clear()}processParagraph(r){let{paragraph:e,index:n,skipIndices:l,processedParagraphs:u}=r;if(this.shouldSkipParagraphIndex(n,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 n=this.cloneParagraph(e.paragraph);if(this.cacheFirstOccurrence(r,n,e.processedParagraphs))return;let l=this.sectionCache.get(r);l&&this.handleRepeatedSection({cachedParagraph:l,currentParagraph:n,processedParagraphs:e.processedParagraphs,skipIndices:e.skipIndices,startIndex:e.index,bodyParagraphs:e.bodyParagraphs})}cacheFirstOccurrence(r,e,n){return this.sectionCache.has(r)?!1:(this.sectionCache.set(r,e),n.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:n,startIndex:l,bodyParagraphs:u}=r,d=[this.createTitleOnlyParagraph(e)];for(let x=l+1;x<u.length;x+=1){let M=u[x];if(!n.has(x))if(this.shouldIncludeTitle(M))d.push(this.createTitleOnlyParagraph(M)),n.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:n,processedParagraphs:l}=r,u=new Et;this.buildFullModeLines(n,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 n=r.lines[0],l=n.items[0];return l&&Js(l)?[n.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 n=e.lines[0];return r.slice(1).forEach(l=>{if(l.lines.length===0)return;let u=l.lines[0];this.addTitleSeparator(n),u.items.forEach(d=>{n.items.push(this.cloneItem(d))})}),e}addTitleSeparator(r){r.items.push(...this.buildTitleSeparatorItems())}buildTitleSeparatorItems(){return[new pe(" "),new tP,new pe(" ")]}createTitleOnlyParagraph(r){let e=new Et;if(r.lines.length===0)return e;let n=r.lines[0],l=new ws({type:n.type,items:[]});return n.items.forEach(u=>{Js(u)&&l.addItem(this.cloneItem(u))}),l.items.length===0&&(l.items=[...n.items.map(u=>this.cloneItem(u))]),e.addLine(l),e}cloneParagraph(r){let e=new Et;return r.lines.forEach(n=>e.addLine(n.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(n=>{e=this.processParagraphLayout(n,r,e)}),r}processParagraphLayout(r,e,n){let l=this.computeParagraphLayout(r,this.config.columnWidth,this.config.displayLyricsOnly),u=this.computeLineTypeCounts(l);if(this.shouldSkipParagraphLayout(u))return n;let d=this.adjustParagraphLayouts(l,n,u.chordLyricLineCount),x=this.calculateNextSimulationState(d,n);return this.addParagraphLayout(e,r,d),x}computeLineTypeCounts(r){let e=0,n=0;return r.forEach(l=>{l.forEach(u=>{u.type==="ChordLyricsPair"?e+=1:(u.type==="Comment"||u.type==="SectionLabel")&&(n+=1)})}),{chordLyricLineCount:e,nonLyricLineCount:n}}shouldSkipParagraphLayout(r){return!!this.config.displayLyricsOnly&&r.nonLyricLineCount===1&&r.chordLyricLineCount===0}adjustParagraphLayouts(r,e,n){let l=eP(r);return e.currentY+l<=this.config.columnBottomY?r:this.paragraphSplitter.splitParagraph(r,e.currentY,this.config.minY,this.config.columnBottomY,n)}calculateNextSimulationState(r,e){let{currentY:n,currentColumn:l}=e;return r.forEach(u=>{if(sP(u))l+=1,l>(this.config.columnCount||1)&&(l=1),n=this.config.minY;else{let d=u.reduce((x,M)=>x+M.lineHeight,0);n+=d}}),n+=this.config.paragraphSpacing,{currentY:n,currentColumn:l}}addParagraphLayout(r,e,n){r.push({units:n,addSpacing:!0,sectionType:e.type})}computeParagraphLayout(r,e,n=!1){let l=[];return r.lines.forEach(u=>{if(dr(u)){let d=this.lineBreaker.breakLineIntoLayouts(u,e,n);l.push(d)}}),l}},Bf=class extends Vj{constructor(r){super(),this.song=new Gs,this.renderer=null,this.container=r}getDefaultConfiguration(){return E7()}format(r){for(this.song=r;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.renderer=new Qj(r,this.container,this.configuration),this.renderer.initialize();let n=this.createLayoutEngine().computeParagraphLayouts();this.renderer.render(n)}createLayoutEngine(){if(!this.renderer)throw new Error("Renderer not initialized");let r=this.renderer.getDocumentMetadata(),{dimensions:e}=r,n={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,n)}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)}},Y7=Bf,k5=/^\[(Verse.*)]/i,O5=/^\[(Chorus.*)]/i,W5=/^\[(Bridge.*)]/i,H5=/^\[(Intro|Outro|Instrumental|Interlude|Solo|Pre-Chorus)( \d+)?]/i,rP=/^(\w+):\s*(.+)$/,K5=/^\[([^\]]+)]/,V5=/\s+(x\d+)\s*$/i,U5=/^\s*(((?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?([^/\s]*)(\/(?:[A-G]|Do|Re|Mi|Fa|Sol|La|Si)(#|b)?)?)(\s|$)+)+(\s|$)+/,Y5={[Qs]:bn,[Fs]:bi,[ur]:un,[Gt]:ii},Na={[Qs]:Of,[Fs]:mn,[ur]:kf,[Gt]:Ka},If=class extends Zf{constructor({preserveWhitespace:r=!0}={}){super({preserveWhitespace:r},!1),this.currentSectionType=null,this.pendingRepeatNotation=null}parseLine(r){this.isSectionEnd()&&this.endSection();let{cleanLine:e,repeatNotation:n}=this.extractRepeatNotation(r);this.pendingRepeatNotation=n,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=U5.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 k5.test(r)||O5.test(r)||W5.test(r)||H5.test(r)||K5.test(r)||U5.test(r)||r.trim().length===0}parseChordsOnly(r){this.parseLyricsWithChords(r,""),this.applyRepeatNotation()}parseLyricsWithChords(r,e){let n=this.processCharacters(r,e);if(!this.chordLyricsPair)throw new Error("Expected this.chordLyricsPair to be present");this.chordLyricsPair.lyrics+=e.substring(n),this.chordLyricsPair.chords=this.chordLyricsPair.chords.trim(),this.chordLyricsPair.lyrics&&(this.chordLyricsPair.lyrics=this.chordLyricsPair.lyrics.trim()),this.applyRepeatNotation()}processCharacters(r,e){let n=P7(e),l=-1;for(let u=0,d=r.length;u<d;u+=1)this.addCharacter(r[u],r[u+1]),l=this.mapLyricsCharacter(n,u,e,l),this.processingText=!/\s/.test(r[u]);return l>=0?l+1:0}addCharacter(r,e){let n=/\s/.test(r);if(n||this.ensureChordLyricsPairInitialized(),!n||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(V5);return e?{cleanLine:r.replace(V5,""),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(rP);if(!e)return!1;let n=e[1].toLowerCase();if(!Xa.includes(n))return!1;let l=n===br?this.extractCapoValue(e[2]):e[2].trim();return this.startNewLine(),this.songBuilder.addTag(new X(n,l)),!0}extractCapoValue(r){let[,e]=r.match(/^(\d+)/)||[];return e||r.trim()}parseVerseDirective(r){let e=r.match(k5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(Qs,n),!0}parseChorusDirective(r){let e=r.match(O5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(Fs,n),!0}parseBridgeDirective(r){let e=r.match(W5);if(!e)return!1;this.startNewLine();let n=e[1];return this.startSection(ur,n),!0}parsePartDirective(r){let e=r.match(H5);if(!e)return!1;this.startNewLine();let n=e[1]+(e[2]||"");return this.startSection(Gt,n),!0}parseMetadata(r){let e=r.match(K5);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(ln,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 Na&&this.startNewLine(),this.endSection({addNewLine:!1})}startSection(r,e){this.currentSectionType&&this.endSection(),this.currentSectionType=r,this.songBuilder.setCurrentProperties(r),r in Y5&&this.songBuilder.addTag(new X(Y5[r],e))}endSection({addNewLine:r=!0}={}){this.currentSectionType!==null&&this.currentSectionType in Na&&(this.songLine&&this.songLine.isEmpty()?this.songLine.addTag(new X(Na[this.currentSectionType])):this.songBuilder.addLine().addTag(new X(Na[this.currentSectionType])),r&&this.startNewLine()),this.songBuilder.setCurrentProperties(Es),this.currentSectionType=null}startNewLine(){this.songLine=this.songBuilder.addLine()}},q7=If,X7="15.5.2",iP={configure:Lj,getDefaultConfig:gr,getHTMLDefaultConfig:F7,getMeasuredHtmlDefaultConfig:E7,getPDFDefaultConfig:Pv,mergeConfigs:Dt},Z7=iP,aP={getCapos:T7,getKeys:Xv},J7=aP,nP={},cP={CHORUS:Fs,Chord:Ds,ChordDefinition:on,ChordLyricsPair:J,ChordProFormatter:D7,MeasuredHtmlFormatter:Y7,ChordProParser:Xf,ChordSheetParser:Zf,ChordSheetSerializer:gn,ChordsOverWordsFormatter:W7,ChordsOverWordsParser:K7,Comment:Xs,Composite:en,HtmlDivFormatter:V7,HtmlTableFormatter:U7,INDETERMINATE:rn,Line:ws,Literal:ke,Metadata:or,NONE:Es,Paragraph:Et,PART:Gt,SoftLineBreak:pe,Song:Gs,TAB:fi,TEXTBLOCK:oi,Tag:X,Ternary:fr,TextFormatter:so,UltimateGuitarParser:q7,VERSE:Qs,BaseMeasurer:lr,DomMeasurer:mr,CanvasMeasurer:tn,LayoutEngine:ci,formatterConfiguration:Z7,keyHelpers:J7,version:X7,templateHelpers:{isEvaluatable:ui,isChordLyricsPair:Zs,lineHasContents:dr,isTag:Js,isComment:ls,isImage:dn,stripHTML:pn,each:Ls,when:fe,hasTextContents:gi,lineClasses:xn,paragraphClasses:yn,evaluate:hi,fontStyleTag:ze,renderChord:et,hasChordContents:Rf,pangoToHtml:hn,stripPangoMarkup:wt}};lM(H.exports,nP)});return fP();})();
package/lib/index.js CHANGED
@@ -30282,7 +30282,7 @@ const $a5a21ced491ea51f$var$endSectionTags = {
30282
30282
  var $a5a21ced491ea51f$export$2e2bcd8739ae039 = $a5a21ced491ea51f$var$UltimateGuitarParser;
30283
30283
 
30284
30284
 
30285
- var $ae92e002ce14f11a$export$2e2bcd8739ae039 = '15.5.2-canary.0';
30285
+ var $ae92e002ce14f11a$export$2e2bcd8739ae039 = '15.5.2';
30286
30286
 
30287
30287
 
30288
30288