chordsheetjs 7.3.0 → 7.5.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
@@ -1,6 +1,4 @@
1
- var $988mA$process = require("process");
2
1
  var $988mA$lodashget = require("lodash.get");
3
- var $988mA$handlebars = require("handlebars");
4
2
 
5
3
  function $parcel$defineInteropFlag(a) {
6
4
  Object.defineProperty(a, '__esModule', {value: true, configurable: true});
@@ -1801,7 +1799,12 @@ class $8fcf445ea0999053$var$Note {
1801
1799
  return this._note;
1802
1800
  }
1803
1801
  toString() {
1804
- return `${this.note}`;
1802
+ switch(this.type){
1803
+ case 0, $af8d31735c159a26$export$1321df9b16c30c6a:
1804
+ return `${this.minor ? this.note.toLowerCase() : this.note.toUpperCase()}`;
1805
+ default:
1806
+ return `${this.note}`;
1807
+ }
1805
1808
  }
1806
1809
  set(attributes) {
1807
1810
  return new $8fcf445ea0999053$var$Note({
@@ -1936,7 +1939,6 @@ var $6ebb068142750218$export$2e2bcd8739ae039 = {
1936
1939
  };
1937
1940
 
1938
1941
 
1939
-
1940
1942
  const $21a34a464e7bc609$export$13215d9ce4923f76 = (collection, Klass)=>{
1941
1943
  const newObject = new Klass();
1942
1944
  collection.push(newObject);
@@ -1969,7 +1971,8 @@ function $21a34a464e7bc609$export$b680e6b2c82f8c2f(message) {
1969
1971
  try {
1970
1972
  throw new Error(`DEPRECATION: ${message}`);
1971
1973
  } catch (e) {
1972
- if (typeof $988mA$process === "object" && typeof $988mA$process.emitWarning === "function") $988mA$process.emitWarning(`${message}\n${e.stack}`);
1974
+ const proc = globalThis.process;
1975
+ if (typeof proc === "object" && typeof proc.emitWarning === "function") proc.emitWarning(`${message}\n${e.stack}`);
1973
1976
  else console.warn(`${message}\n${e.stack}`);
1974
1977
  }
1975
1978
  }
@@ -2030,6 +2033,7 @@ class $bff5407e03fdc8ee$var$Key {
2030
2033
  this.note = note instanceof (0, $8fcf445ea0999053$export$2e2bcd8739ae039) ? note : (0, $8fcf445ea0999053$export$2e2bcd8739ae039).parse(note);
2031
2034
  this.modifier = modifier || null;
2032
2035
  this.minor = !!minor || false;
2036
+ if (this.minor) this.note.minor = true;
2033
2037
  }
2034
2038
  isMinor() {
2035
2039
  return this.minor || this.note.isMinor();
@@ -2080,8 +2084,25 @@ class $bff5407e03fdc8ee$var$Key {
2080
2084
  toNumeralString(key = null) {
2081
2085
  return this.toNumeral(key).toString();
2082
2086
  }
2083
- toString() {
2084
- if (this.isChordSymbol()) return `${this.note}${this.modifier || ""}`;
2087
+ toString({ showMinor: showMinor = true } = {}) {
2088
+ switch(this.note.type){
2089
+ case 0, $af8d31735c159a26$export$27c95a7104c1f7aa:
2090
+ return this.formatChordSymbolString(showMinor);
2091
+ case 0, $af8d31735c159a26$export$4d318981b5a83836:
2092
+ return this.formatNumericString(showMinor);
2093
+ case 0, $af8d31735c159a26$export$1321df9b16c30c6a:
2094
+ return this.formatNumeralString();
2095
+ default:
2096
+ throw new Error(`Unexpected note type ${this.note.type}`);
2097
+ }
2098
+ }
2099
+ formatChordSymbolString(showMinor) {
2100
+ return `${this.note}${this.modifier || ""}${this.minor && showMinor ? "m" : ""}`;
2101
+ }
2102
+ formatNumericString(showMinor) {
2103
+ return `${this.modifier || ""}${this.note}${this.minor && showMinor ? "m" : ""}`;
2104
+ }
2105
+ formatNumeralString() {
2085
2106
  return `${this.modifier || ""}${this.note}`;
2086
2107
  }
2087
2108
  transpose(delta) {
@@ -2146,9 +2167,13 @@ class $bff5407e03fdc8ee$var$Key {
2146
2167
  }
2147
2168
  normalizeEnharmonics(key) {
2148
2169
  if (key) {
2149
- const rootKeyString = key.minor ? `${key}m` : key.toString();
2170
+ const rootKeyString = $bff5407e03fdc8ee$var$Key.wrap(key).toString({
2171
+ showMinor: true
2172
+ });
2150
2173
  const enharmonics = (0, $6ebb068142750218$export$2e2bcd8739ae039)[rootKeyString];
2151
- const thisKeyString = this.toString();
2174
+ const thisKeyString = this.toString({
2175
+ showMinor: false
2176
+ });
2152
2177
  if (enharmonics && enharmonics[thisKeyString]) return $bff5407e03fdc8ee$var$Key.parse(enharmonics[thisKeyString]);
2153
2178
  }
2154
2179
  return this.clone();
@@ -3089,7 +3114,7 @@ var $e12151f977ef7bf6$export$2e2bcd8739ae039 = $e12151f977ef7bf6$var$mapping;
3089
3114
 
3090
3115
 
3091
3116
 
3092
- function $26f57998457eb2d4$var$normalizeSuffix(suffix) {
3117
+ function $26f57998457eb2d4$var$normalizeChordSuffix(suffix) {
3093
3118
  if ((0, $e12151f977ef7bf6$export$2e2bcd8739ae039)[suffix] === "[blank]") return null;
3094
3119
  return (0, $e12151f977ef7bf6$export$2e2bcd8739ae039)[suffix] || suffix;
3095
3120
  }
@@ -3136,7 +3161,7 @@ const $26f57998457eb2d4$var$regexes = [
3136
3161
  const keyObj = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(key);
3137
3162
  const rootKey = this.root.toChordSymbol(keyObj).normalizeEnharmonics(keyObj);
3138
3163
  let chordSymbolChord = new $26f57998457eb2d4$var$Chord({
3139
- suffix: $26f57998457eb2d4$var$normalizeSuffix(this.suffix),
3164
+ suffix: $26f57998457eb2d4$var$normalizeChordSuffix(this.suffix),
3140
3165
  root: rootKey,
3141
3166
  bass: this.bass?.toChordSymbol(keyObj).normalizeEnharmonics(rootKey)
3142
3167
  });
@@ -3172,7 +3197,7 @@ const $26f57998457eb2d4$var$regexes = [
3172
3197
  });
3173
3198
  const keyObj = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(key);
3174
3199
  return new $26f57998457eb2d4$var$Chord({
3175
- suffix: $26f57998457eb2d4$var$normalizeSuffix(this.suffix),
3200
+ suffix: $26f57998457eb2d4$var$normalizeChordSuffix(this.suffix),
3176
3201
  root: this.root.toNumeric(keyObj),
3177
3202
  bass: this.bass?.toNumeric(keyObj)
3178
3203
  });
@@ -3190,7 +3215,7 @@ const $26f57998457eb2d4$var$regexes = [
3190
3215
  });
3191
3216
  const keyObj = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(key);
3192
3217
  return new $26f57998457eb2d4$var$Chord({
3193
- suffix: $26f57998457eb2d4$var$normalizeSuffix(this.suffix),
3218
+ suffix: $26f57998457eb2d4$var$normalizeChordSuffix(this.suffix),
3194
3219
  root: this.root.toNumeral(keyObj),
3195
3220
  bass: this.bass?.toNumeral(keyObj)
3196
3221
  });
@@ -3229,7 +3254,9 @@ const $26f57998457eb2d4$var$regexes = [
3229
3254
  * Converts the chord to a string, eg `Esus4/G#` or `1sus4/#3`
3230
3255
  * @returns {string} the chord string
3231
3256
  */ toString() {
3232
- const chordString = this.root.toString() + (this.suffix || "");
3257
+ const chordString = this.root.toString({
3258
+ showMinor: false
3259
+ }) + (this.suffix || "");
3233
3260
  if (this.bass) return `${chordString}/${this.bass.toString()}`;
3234
3261
  return chordString;
3235
3262
  }
@@ -3244,17 +3271,21 @@ const $26f57998457eb2d4$var$regexes = [
3244
3271
  * - 7# becomes 1
3245
3272
  * - 3# becomes 4
3246
3273
  *
3247
- * Besides that it normalizes the suffix. For example, `sus2` becomes `2`, `sus4` becomes `sus`.
3274
+ * Besides that it normalizes the suffix if `normalizeSuffix` is `true`.
3275
+ * For example, `sus2` becomes `2`, `sus4` becomes `sus`.
3248
3276
  * All suffix normalizations can be found in `src/normalize_mappings/suffix-mapping.txt`.
3249
- *
3277
+ * @param {Key|string} [key=null] the key to normalize to
3278
+ * @param {Object} [options={}] options
3279
+ * @param {boolean} [options.normalizeSuffix=true] whether to normalize the chord suffix after transposing
3250
3280
  * @returns {Chord} the normalized chord
3251
- */ normalize(key = null) {
3281
+ */ normalize(key = null, { normalizeSuffix: normalizeSuffix = true } = {}) {
3282
+ const suffix = normalizeSuffix ? $26f57998457eb2d4$var$normalizeChordSuffix(this.suffix) : this.suffix;
3252
3283
  if ((0, $21a34a464e7bc609$export$7ee701e290d9865)(key)) return this.process("normalize").set({
3253
- suffix: (0, $21a34a464e7bc609$export$ed9b06b5ee264ad3)($26f57998457eb2d4$var$normalizeSuffix(this.suffix))
3284
+ suffix: suffix
3254
3285
  });
3255
3286
  return this.set({
3287
+ suffix: suffix,
3256
3288
  root: this.root.normalizeEnharmonics(key),
3257
- suffix: (0, $21a34a464e7bc609$export$ed9b06b5ee264ad3)($26f57998457eb2d4$var$normalizeSuffix(this.suffix)),
3258
3289
  bass: this.bass ? this.bass.normalizeEnharmonics(this.root.toString()) : null
3259
3290
  });
3260
3291
  }
@@ -3286,16 +3317,17 @@ const $26f57998457eb2d4$var$regexes = [
3286
3317
  }
3287
3318
  constructor({ base: base = null , modifier: modifier = null , suffix: suffix = null , bassBase: bassBase = null , bassModifier: bassModifier = null , root: root = null , bass: bass = null , }){
3288
3319
  this.suffix = (0, $21a34a464e7bc609$export$ed9b06b5ee264ad3)(suffix);
3320
+ const isMinor = suffix && suffix[0] === "m" && suffix.substring(0, 3).toLowerCase() !== "maj";
3289
3321
  this.root = root || new (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039)({
3290
3322
  note: base,
3291
3323
  modifier: modifier,
3292
- minor: suffix === "m"
3324
+ minor: isMinor
3293
3325
  });
3294
3326
  if (bass) this.bass = bass;
3295
3327
  else if (bassBase) this.bass = new (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039)({
3296
3328
  note: bassBase,
3297
3329
  modifier: bassModifier,
3298
- minor: suffix === "m"
3330
+ minor: isMinor
3299
3331
  });
3300
3332
  else this.bass = null;
3301
3333
  }
@@ -3375,11 +3407,13 @@ var $26f57998457eb2d4$export$2e2bcd8739ae039 = $26f57998457eb2d4$var$Chord;
3375
3407
  lyrics: lyrics
3376
3408
  });
3377
3409
  }
3378
- transpose(delta, key = null) {
3410
+ transpose(delta, key = null, { normalizeChordSuffix: normalizeChordSuffix = false } = {}) {
3379
3411
  const chordObj = (0, $26f57998457eb2d4$export$2e2bcd8739ae039).parse(this.chords);
3380
3412
  if (chordObj) {
3381
3413
  let transposedChord = chordObj.transpose(delta);
3382
- if (key) transposedChord = transposedChord.normalize(key);
3414
+ if (key) transposedChord = transposedChord.normalize(key, {
3415
+ normalizeSuffix: normalizeChordSuffix
3416
+ });
3383
3417
  return this.set({
3384
3418
  chords: transposedChord.toString()
3385
3419
  });
@@ -4142,8 +4176,10 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4142
4176
  * - transpose the song key in {@link metadata}
4143
4177
  * - update any existing `key` directive
4144
4178
  * @param {number} delta The number of semitones (positive or negative) to transpose with
4179
+ * @param {Object} [options={}] options
4180
+ * @param {boolean} [options.normalizeChordSuffix=false] whether to normalize the chord suffixes after transposing
4145
4181
  * @returns {Song} The transposed song
4146
- */ transpose(delta) {
4182
+ */ transpose(delta, { normalizeChordSuffix: normalizeChordSuffix = false } = {}) {
4147
4183
  const wrappedKey = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(this.key);
4148
4184
  let transposedKey = null;
4149
4185
  let song = this;
@@ -4152,7 +4188,9 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4152
4188
  song = song.setKey(transposedKey);
4153
4189
  }
4154
4190
  return song.mapItems((item)=>{
4155
- if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(delta, transposedKey);
4191
+ if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(delta, transposedKey, {
4192
+ normalizeChordSuffix: normalizeChordSuffix
4193
+ });
4156
4194
  return item;
4157
4195
  });
4158
4196
  }
@@ -4161,18 +4199,26 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4161
4199
  * - transpose all chords, see: {@link Chord#transpose}
4162
4200
  * - transpose the song key in {@link metadata}
4163
4201
  * - update any existing `key` directive
4202
+ * @param {Object} [options={}] options
4203
+ * @param {boolean} [options.normalizeChordSuffix=false] whether to normalize the chord suffixes after transposing
4164
4204
  * @returns {Song} The transposed song
4165
- */ transposeUp() {
4166
- return this.transpose(1);
4205
+ */ transposeUp({ normalizeChordSuffix: normalizeChordSuffix = false } = {}) {
4206
+ return this.transpose(1, {
4207
+ normalizeChordSuffix: normalizeChordSuffix
4208
+ });
4167
4209
  }
4168
4210
  /**
4169
4211
  * Transposes the song down by one semitone. It will:
4170
4212
  * - transpose all chords, see: {@link Chord#transpose}
4171
4213
  * - transpose the song key in {@link metadata}
4172
4214
  * - update any existing `key` directive
4215
+ * @param {Object} [options={}] options
4216
+ * @param {boolean} [options.normalizeChordSuffix=false] whether to normalize the chord suffixes after transposing
4173
4217
  * @returns {Song} The transposed song
4174
- */ transposeDown() {
4175
- return this.transpose(-1);
4218
+ */ transposeDown({ normalizeChordSuffix: normalizeChordSuffix = false } = {}) {
4219
+ return this.transpose(-1, {
4220
+ normalizeChordSuffix: normalizeChordSuffix
4221
+ });
4176
4222
  }
4177
4223
  /**
4178
4224
  * Returns a copy of the song with the key set to the specified key. It changes:
@@ -4927,6 +4973,19 @@ var $525b2331e4b0ed83$export$2e2bcd8739ae039 = $525b2331e4b0ed83$var$TextFormatt
4927
4973
 
4928
4974
 
4929
4975
 
4976
+ /**
4977
+ * Acts as a base class for HTML formatters, taking care of whitelisting prototype property access.
4978
+ */ class $d834af97c9a2e4df$var$HtmlFormatter extends (0, $0055ecb09272ba2d$export$2e2bcd8739ae039) {
4979
+ formatWithTemplate(song, template) {
4980
+ return template({
4981
+ song: song,
4982
+ configuration: this.configuration
4983
+ });
4984
+ }
4985
+ }
4986
+ var $d834af97c9a2e4df$export$2e2bcd8739ae039 = $d834af97c9a2e4df$var$HtmlFormatter;
4987
+
4988
+
4930
4989
 
4931
4990
 
4932
4991
 
@@ -4979,31 +5038,6 @@ var $5381a6b1b90601c7$export$2e2bcd8739ae039 = ({ configuration: configuration ,
4979
5038
 
4980
5039
 
4981
5040
 
4982
-
4983
- /**
4984
- * Acts as a base class for HTML formatters, taking care of whitelisting prototype property access.
4985
- */ class $d834af97c9a2e4df$var$HtmlFormatter extends (0, $0055ecb09272ba2d$export$2e2bcd8739ae039) {
4986
- formatWithTemplate(song, template) {
4987
- return template({
4988
- song: song,
4989
- configuration: this.configuration
4990
- }, {
4991
- allowedProtoProperties: {
4992
- bodyLines: true,
4993
- bodyParagraphs: true,
4994
- subtitle: true,
4995
- title: true,
4996
- value: true,
4997
- key: true
4998
- }
4999
- });
5000
- }
5001
- }
5002
- var $d834af97c9a2e4df$export$2e2bcd8739ae039 = $d834af97c9a2e4df$var$HtmlFormatter;
5003
-
5004
-
5005
-
5006
- const { html_table_formatter: $5b02ea769c63fd56$var$template } = (0, ($parcel$interopDefault($988mA$handlebars))).templates;
5007
5041
  const $5b02ea769c63fd56$export$200cf2de69532aa8 = {
5008
5042
  h1: {
5009
5043
  fontSize: "1.5em"
@@ -5037,7 +5071,7 @@ function $5b02ea769c63fd56$export$aa5b6043dd05348b(scope) {
5037
5071
  * @param {Song} song The song to be formatted
5038
5072
  * @returns {string} The HTML string
5039
5073
  */ format(song) {
5040
- return this.formatWithTemplate(song, $5b02ea769c63fd56$var$template);
5074
+ return this.formatWithTemplate(song, (0, $5381a6b1b90601c7$export$2e2bcd8739ae039));
5041
5075
  }
5042
5076
  /**
5043
5077
  * Generates basic CSS, optionally scoped within the provided selector, to use with output generated by