chordsheetjs 15.5.2 → 15.5.3-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/bundle.js CHANGED
@@ -8676,7 +8676,10 @@ Or set the song key before changing key:
8676
8676
  const eagerChord = this.notation && chordString ? (0, $177a605b8569b31c$export$2e2bcd8739ae039).parse(chordString, {
8677
8677
  notation: this.notation
8678
8678
  }) : null;
8679
- return new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(eagerChord ? eagerChord.toString() : chordString, lyrics, annotation, eagerChord, isRhythmSymbol || false);
8679
+ return new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(eagerChord ? eagerChord.toString() : chordString, lyrics, annotation, eagerChord, isRhythmSymbol || this.isRhythmSymbol(chordString));
8680
+ }
8681
+ isRhythmSymbol(chordString) {
8682
+ return chordString === "|" || chordString === "/";
8680
8683
  }
8681
8684
  parseTag(astComponent) {
8682
8685
  const { name, value, location: { offset = null, line = null, column = null } = {}, chordDefinition, attributes, selector, isNegated } = astComponent;
@@ -28448,7 +28451,7 @@ ${template}
28448
28451
  const renderedChords = this.renderChordText(chords, line);
28449
28452
  const measurements = this.calculateMeasurements(renderedChords, lyrics, nextItem, lyricsOnly);
28450
28453
  return {
28451
- item: new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, lyrics),
28454
+ item: new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, lyrics, splitItem.annotation, null, splitItem.isRhythmSymbol),
28452
28455
  width: measurements.totalWidth,
28453
28456
  chordHeight: measurements.chordHeight
28454
28457
  };
@@ -28560,11 +28563,7 @@ ${template}
28560
28563
  const firstLyrics = splitLines[0];
28561
28564
  const secondLyrics = splitLines.slice(1).join(" ");
28562
28565
  return [
28563
- {
28564
- item: new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(item.item.chords, firstLyrics),
28565
- width: this.measurer.measureTextWidth(firstLyrics, lyricsFont),
28566
- chordHeight: item.chordHeight
28567
- },
28566
+ this.createSplitMeasuredItem(item, firstLyrics, item.item.chords, item.item.isRhythmSymbol),
28568
28567
  {
28569
28568
  item: new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)("", secondLyrics),
28570
28569
  width: this.measurer.measureTextWidth(secondLyrics, lyricsFont),
@@ -28572,6 +28571,14 @@ ${template}
28572
28571
  }
28573
28572
  ];
28574
28573
  }
28574
+ createSplitMeasuredItem(originalItem, lyrics, chords, isRhythmSymbol) {
28575
+ const annotation = originalItem.item instanceof (0, $551a223fc13b5c10$export$2e2bcd8739ae039) ? originalItem.item.annotation : null;
28576
+ return {
28577
+ item: new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, lyrics, annotation, null, isRhythmSymbol),
28578
+ width: this.measurer.measureTextWidth(lyrics, this.config.fonts.lyrics),
28579
+ chordHeight: originalItem.chordHeight
28580
+ };
28581
+ }
28575
28582
  /**
28576
28583
  * Removes hyphens from lyrics for lyrics-only mode
28577
28584
  */
@@ -28599,11 +28606,11 @@ ${template}
28599
28606
  items.push(new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)("", adjustedFragment, ""));
28600
28607
  }
28601
28608
  }
28602
- if (index === 0 && lyricFragments.length === 1) items.push(new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, fragment, annotation));
28609
+ if (index === 0 && lyricFragments.length === 1) items.push(new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, fragment, annotation, null, pair.isRhythmSymbol));
28603
28610
  else if (index === 0 && lyricFragments.length > 1) {
28604
28611
  let commaAdjustedFragment = fragment;
28605
28612
  commaAdjustedFragment += ",";
28606
- items.push(new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, commaAdjustedFragment, annotation));
28613
+ items.push(new (0, $551a223fc13b5c10$export$2e2bcd8739ae039)(chords, commaAdjustedFragment, annotation, null, pair.isRhythmSymbol));
28607
28614
  }
28608
28615
  });
28609
28616
  return items;
@@ -28745,7 +28752,7 @@ ${template}
28745
28752
  this.layoutFactory.createLineLayout(items, line)
28746
28753
  ];
28747
28754
  if (softBreakIndices.length === 0) return this.handleNoSoftBreaks(items, availableWidth, line);
28748
- const { firstChunk, secondChunk } = this.splitAtBestSoftBreak(items, softBreakIndices, totalWidth);
28755
+ const { firstChunk, secondChunk } = this.splitAtBestSoftBreak(items, softBreakIndices, totalWidth, availableWidth);
28749
28756
  if (firstChunk.length === 0) return this.breakContent(secondChunk, availableWidth, line);
28750
28757
  const firstLayout = this.layoutFactory.createLineLayout(firstChunk, line);
28751
28758
  return [
@@ -28762,8 +28769,9 @@ ${template}
28762
28769
  this.layoutFactory.createLineLayout(items, line)
28763
28770
  ];
28764
28771
  if (breakIndex === 0) return this.handleOversizedFirstItem(items, availableWidth, line);
28765
- const firstChunk = items.slice(0, breakIndex);
28766
- const secondChunk = items.slice(breakIndex);
28772
+ let firstChunk = items.slice(0, breakIndex);
28773
+ let secondChunk = items.slice(breakIndex);
28774
+ ({ firstChunk, secondChunk } = this.avoidLeadingRhythmSymbol(firstChunk, secondChunk, availableWidth));
28767
28775
  this.removeTrailingComma(firstChunk);
28768
28776
  return [
28769
28777
  this.layoutFactory.createLineLayout(firstChunk, line),
@@ -28822,26 +28830,112 @@ ${template}
28822
28830
  shouldReturnSingleLayout(totalWidth, availableWidth) {
28823
28831
  return totalWidth <= availableWidth;
28824
28832
  }
28825
- splitAtBestSoftBreak(items, softBreakIndices, totalWidth) {
28833
+ splitAtBestSoftBreak(items, softBreakIndices, totalWidth, availableWidth) {
28834
+ const bestBreak = this.findBestSoftBreak(items, softBreakIndices, totalWidth);
28835
+ let firstChunk = items.slice(0, bestBreak.index);
28836
+ let secondChunk = items.slice(bestBreak.index + 1);
28837
+ ({ firstChunk, secondChunk } = this.avoidLeadingRhythmSymbol(firstChunk, secondChunk, availableWidth));
28838
+ this.removeTrailingComma(firstChunk);
28839
+ this.capitalizeNextItem(secondChunk, secondChunk, 0);
28840
+ return {
28841
+ firstChunk,
28842
+ secondChunk
28843
+ };
28844
+ }
28845
+ findBestSoftBreak(items, softBreakIndices, totalWidth) {
28826
28846
  const targetWidth = totalWidth / 2;
28827
28847
  const breakOptions = softBreakIndices.map((idx) => ({
28828
28848
  index: idx,
28829
28849
  widthUpToBreak: this.getWidthUpToIndex(items, idx)
28830
28850
  }));
28831
- const bestBreak = breakOptions.reduce((best, current) => {
28832
- const currentDistance = Math.abs(current.widthUpToBreak - targetWidth);
28833
- const bestDistance = Math.abs(best.widthUpToBreak - targetWidth);
28834
- if (currentDistance === bestDistance) return current.index > best.index ? current : best;
28835
- return currentDistance < bestDistance ? current : best;
28836
- });
28837
- const firstChunk = items.slice(0, bestBreak.index);
28838
- const secondChunk = items.slice(bestBreak.index + 1);
28839
- this.removeTrailingComma(firstChunk);
28840
- this.capitalizeNextItem(secondChunk, secondChunk, 0);
28841
- return {
28851
+ return breakOptions.reduce((best, current) => this.selectBetterSoftBreak(best, current, targetWidth));
28852
+ }
28853
+ selectBetterSoftBreak(best, current, targetWidth) {
28854
+ const currentDistance = Math.abs(current.widthUpToBreak - targetWidth);
28855
+ const bestDistance = Math.abs(best.widthUpToBreak - targetWidth);
28856
+ if (currentDistance === bestDistance) return current.index > best.index ? current : best;
28857
+ return currentDistance < bestDistance ? current : best;
28858
+ }
28859
+ /**
28860
+ * Avoid wrapping a line so that the next visual line starts with a rhythm symbol.
28861
+ *
28862
+ * Prefer keeping the leading rhythm symbol(s) with the previous line, but only
28863
+ * when the previous line still fits. If they do not fit, break earlier by
28864
+ * moving the nearest preceding non-rhythm chord to the next line. Width checks
28865
+ * are recalculated in the final line context so trailing chord-spacing is not
28866
+ * counted for a line-ending rhythm symbol such as `|`.
28867
+ */
28868
+ avoidLeadingRhythmSymbol(firstChunk, secondChunk, availableWidth) {
28869
+ if (!this.shouldAvoidLeadingRhythmSymbol(secondChunk)) return {
28870
+ firstChunk,
28871
+ secondChunk
28872
+ };
28873
+ return this.tryMoveLeadingRhythmSymbolsToFirstChunk(firstChunk, secondChunk, availableWidth) || this.movePrecedingChordToSecondChunk(firstChunk, secondChunk);
28874
+ }
28875
+ shouldAvoidLeadingRhythmSymbol(secondChunk) {
28876
+ const leadingRhythmSymbolCount = this.countLeadingRhythmSymbols(secondChunk);
28877
+ return this.startsWithRhythmSymbol(secondChunk) && this.hasChordAfterLeadingRhythmSymbols(secondChunk, leadingRhythmSymbolCount);
28878
+ }
28879
+ tryMoveLeadingRhythmSymbolsToFirstChunk(firstChunk, secondChunk, availableWidth) {
28880
+ const leadingRhythmSymbolCount = this.countLeadingRhythmSymbols(secondChunk);
28881
+ const laterFirstChunk = [
28882
+ ...firstChunk,
28883
+ ...secondChunk.slice(0, leadingRhythmSymbolCount)
28884
+ ];
28885
+ const laterSecondChunk = secondChunk.slice(leadingRhythmSymbolCount);
28886
+ if (this.calculateLineContextWidth(laterFirstChunk) <= availableWidth) return {
28887
+ firstChunk: laterFirstChunk,
28888
+ secondChunk: laterSecondChunk
28889
+ };
28890
+ return null;
28891
+ }
28892
+ movePrecedingChordToSecondChunk(firstChunk, secondChunk) {
28893
+ const precedingChordIndex = this.findLastNonRhythmChordIndex(firstChunk);
28894
+ if (precedingChordIndex <= 0) return {
28842
28895
  firstChunk,
28843
28896
  secondChunk
28844
28897
  };
28898
+ return {
28899
+ firstChunk: firstChunk.slice(0, precedingChordIndex),
28900
+ secondChunk: [
28901
+ ...firstChunk.slice(precedingChordIndex),
28902
+ ...secondChunk
28903
+ ]
28904
+ };
28905
+ }
28906
+ startsWithRhythmSymbol(items) {
28907
+ return this.isRhythmSymbolItem(items[0]);
28908
+ }
28909
+ countLeadingRhythmSymbols(items) {
28910
+ let count = 0;
28911
+ while (count < items.length && this.isRhythmSymbolItem(items[count])) count += 1;
28912
+ return count;
28913
+ }
28914
+ hasChordAfterLeadingRhythmSymbols(items, leadingRhythmSymbolCount) {
28915
+ return this.isNonRhythmChordItem(items[leadingRhythmSymbolCount]);
28916
+ }
28917
+ findLastNonRhythmChordIndex(items) {
28918
+ for (let index = items.length - 1; index >= 0; index -= 1) {
28919
+ if (this.isNonRhythmChordItem(items[index])) return index;
28920
+ }
28921
+ return -1;
28922
+ }
28923
+ isRhythmSymbolItem(item) {
28924
+ return item?.item instanceof (0, $551a223fc13b5c10$export$2e2bcd8739ae039) && item.item.isRhythmSymbol;
28925
+ }
28926
+ isNonRhythmChordItem(item) {
28927
+ return item?.item instanceof (0, $551a223fc13b5c10$export$2e2bcd8739ae039) && !item.item.isRhythmSymbol && (item.item.chords || "").trim() !== "";
28928
+ }
28929
+ calculateLineContextWidth(items) {
28930
+ return items.reduce((width, item, index) => {
28931
+ const nextItem = items[index + 1] || null;
28932
+ return width + this.recalculateWidthForLineContext(item, nextItem);
28933
+ }, 0);
28934
+ }
28935
+ recalculateWidthForLineContext(item, nextItem) {
28936
+ if (item.item instanceof (0, $551a223fc13b5c10$export$2e2bcd8739ae039)) return this.recalculateChordLyricWidth(item, nextItem);
28937
+ if (!nextItem && item.item instanceof (0, $4b6dd3e4b817bd81$export$2e2bcd8739ae039)) return 0;
28938
+ return item.width;
28845
28939
  }
28846
28940
  removeTrailingComma(items) {
28847
28941
  const lastItem = items[items.length - 1];
@@ -29716,7 +29810,7 @@ ${template}
29716
29810
  }
29717
29811
  };
29718
29812
  var $a5a21ced491ea51f$export$2e2bcd8739ae039 = $a5a21ced491ea51f$var$UltimateGuitarParser;
29719
- var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.5.2";
29813
+ var $ae92e002ce14f11a$export$2e2bcd8739ae039 = "15.5.3-canary.0";
29720
29814
  var $2a7926da41d163b3$export$191a710ad3c9a989 = {
29721
29815
  configure: $181068e44290b873$export$8d21e34596265fa2,
29722
29816
  getDefaultConfig: $fe1d3ba9df1ecad5$export$ed30944e0fe6ae5c,