chordsheetjs 10.2.0 → 10.3.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/index.js CHANGED
@@ -11804,14 +11804,23 @@ var $c6abce5a8855cc55$export$2e2bcd8739ae039 = $c6abce5a8855cc55$var$enharmonics
11804
11804
  transpose(delta, key = null, { normalizeChordSuffix: normalizeChordSuffix } = {
11805
11805
  normalizeChordSuffix: false
11806
11806
  }) {
11807
- const chordObj = (0, $177a605b8569b31c$export$2e2bcd8739ae039).parse(this.chords.trim());
11808
- if (chordObj) {
11809
- let transposedChord = chordObj.transpose(delta);
11810
- if (key) transposedChord = transposedChord.normalize(key, {
11807
+ return this.changeChord((chord)=>{
11808
+ const transposedChord = chord.transpose(delta);
11809
+ if (key) return transposedChord.normalize(key, {
11811
11810
  normalizeSuffix: normalizeChordSuffix
11812
11811
  });
11812
+ return transposedChord;
11813
+ });
11814
+ }
11815
+ useModifier(modifier) {
11816
+ return this.changeChord((chord)=>chord.useModifier(modifier));
11817
+ }
11818
+ changeChord(func) {
11819
+ const chordObj = (0, $177a605b8569b31c$export$2e2bcd8739ae039).parse(this.chords.trim());
11820
+ if (chordObj) {
11821
+ const changedChord = func(chordObj);
11813
11822
  return this.set({
11814
- chords: transposedChord.toString()
11823
+ chords: changedChord.toString()
11815
11824
  });
11816
11825
  }
11817
11826
  return this.clone();
@@ -14263,7 +14272,8 @@ function $51ced2cf8b50f946$export$bb6f5ab929ea49e7(lyrics) {
14263
14272
  }
14264
14273
  function $51ced2cf8b50f946$export$54f22f5279737844(chords, lyrics) {
14265
14274
  const pairs = $51ced2cf8b50f946$export$bb6f5ab929ea49e7(lyrics || "");
14266
- let [first, ...rest] = pairs;
14275
+ const [_first, ...rest] = pairs;
14276
+ let first = pairs[0];
14267
14277
  let addedLeadingChord = null;
14268
14278
  if (chords !== "") {
14269
14279
  if (!first || first.type === "softLineBreak") addedLeadingChord = {
@@ -27987,10 +27997,24 @@ const $c53141c05fae8382$var$END_TAG_TO_SECTION_TYPE = {
27987
27997
  * @param {string} newKey The new key.
27988
27998
  * @returns {Song} The changed song
27989
27999
  */ changeKey(newKey) {
27990
- const delta = this.getTransposeDistance(newKey);
27991
- return this.transpose(delta);
28000
+ const currentKey = this.requireCurrentKey();
28001
+ const targetKey = (0, $c2d6ab25ad00308f$export$2e2bcd8739ae039).wrapOrFail(newKey);
28002
+ const delta = currentKey.distanceTo(targetKey);
28003
+ const transposedSong = this.transpose(delta);
28004
+ if (targetKey.modifier) return transposedSong.useModifier(targetKey.modifier);
28005
+ return transposedSong;
28006
+ }
28007
+ /**
28008
+ * Returns a copy of the song with all chords changed to the specified modifier.
28009
+ * @param {Modifier} modifier the new modifier
28010
+ * @returns {Song} the changed song
28011
+ */ useModifier(modifier) {
28012
+ return this.mapItems((item)=>{
28013
+ if (item instanceof (0, $551a223fc13b5c10$export$2e2bcd8739ae039)) return item.useModifier(modifier);
28014
+ return item;
28015
+ });
27992
28016
  }
27993
- getTransposeDistance(newKey) {
28017
+ requireCurrentKey() {
27994
28018
  const wrappedKey = (0, $c2d6ab25ad00308f$export$2e2bcd8739ae039).wrap(this.key);
27995
28019
  if (!wrappedKey) throw new Error(`
27996
28020
  Cannot change song key, the original key is unknown.
@@ -28000,7 +28024,7 @@ Either ensure a key directive is present in the song (when using chordpro):
28000
28024
 
28001
28025
  Or set the song key before changing key:
28002
28026
  \`song.setKey('C');\``.substring(1));
28003
- return wrappedKey.distanceTo(newKey);
28027
+ return wrappedKey;
28004
28028
  }
28005
28029
  /**
28006
28030
  * Returns a copy of the song with the directive value set to the specified value.
@@ -29087,7 +29111,7 @@ function $7270482b3072811c$var$applySoftLineBreaks(line) {
29087
29111
  }
29088
29112
  function $7270482b3072811c$var$chordProperties(chord) {
29089
29113
  // Disable no-unused-vars until destructuredObjectIgnorePattern is available
29090
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
29114
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29091
29115
  const { type: _type, ...properties } = chord;
29092
29116
  return properties;
29093
29117
  }