chordsheetjs 5.0.0 → 5.1.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.
@@ -9,17 +9,17 @@ exports["default"] = void 0;
9
9
 
10
10
  var _line = _interopRequireDefault(require("./line"));
11
11
 
12
- var _tag = _interopRequireWildcard(require("./tag"));
13
-
14
12
  var _paragraph = _interopRequireDefault(require("./paragraph"));
15
13
 
16
14
  var _utilities = require("../utilities");
17
15
 
18
16
  var _metadata = _interopRequireDefault(require("./metadata"));
19
17
 
18
+ var _parser_warning = _interopRequireDefault(require("../parser/parser_warning"));
19
+
20
20
  var _constants = require("../constants");
21
21
 
22
- var _parser_warning = _interopRequireDefault(require("../parser/parser_warning"));
22
+ var _tag = _interopRequireWildcard(require("./tag"));
23
23
 
24
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
25
 
@@ -82,6 +82,7 @@ var Song = /*#__PURE__*/function () {
82
82
  this.currentParagraph = null;
83
83
  this.warnings = [];
84
84
  this.sectionType = _constants.NONE;
85
+ this.currentKey = null;
85
86
  }
86
87
 
87
88
  _createClass(Song, [{
@@ -150,6 +151,7 @@ var Song = /*#__PURE__*/function () {
150
151
  this.flushLine();
151
152
  this.currentLine = (0, _utilities.pushNew)(this.lines, _line["default"]);
152
153
  this.setCurrentLineType(this.sectionType);
154
+ this.currentLine.key = this.currentKey;
153
155
  return this.currentLine;
154
156
  }
155
157
  }, {
@@ -208,6 +210,8 @@ var Song = /*#__PURE__*/function () {
208
210
 
209
211
  if (tag.isMetaTag()) {
210
212
  this.setMetaData(tag.name, tag.value);
213
+ } else if (tag.name === _tag.TRANSPOSE) {
214
+ this.currentKey = tag.value;
211
215
  } else {
212
216
  this.setSectionTypeFromTag(tag);
213
217
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports._KEY = exports.YEAR = exports.TITLE = exports.TIME = exports.TEMPO = exports.SUBTITLE = exports.START_OF_VERSE = exports.START_OF_TAB = exports.START_OF_CHORUS = exports.READ_ONLY_TAGS = exports.META_TAGS = exports.LYRICIST = exports.KEY = exports.END_OF_VERSE = exports.END_OF_TAB = exports.END_OF_CHORUS = exports.DURATION = exports.COPYRIGHT = exports.COMPOSER = exports.COMMENT = exports.CAPO = exports.ARTIST = exports.ALBUM = void 0;
6
+ exports["default"] = exports._KEY = exports.YEAR = exports.TRANSPOSE = exports.TITLE = exports.TIME = exports.TEMPO = exports.SUBTITLE = exports.START_OF_VERSE = exports.START_OF_TAB = exports.START_OF_CHORUS = exports.READ_ONLY_TAGS = exports.META_TAGS = exports.LYRICIST = exports.KEY = exports.END_OF_VERSE = exports.END_OF_TAB = exports.END_OF_CHORUS = exports.DURATION = exports.COPYRIGHT = exports.COMPOSER = exports.COMMENT = exports.CAPO = exports.ARTIST = exports.ALBUM = void 0;
7
7
  exports.isReadonlyTag = isReadonlyTag;
8
8
 
9
9
  var _ALIASES;
@@ -155,11 +155,18 @@ var TIME = 'time';
155
155
  exports.TIME = TIME;
156
156
  var TITLE = 'title';
157
157
  /**
158
- * Year meta directive. See https://www.chordpro.org/chordpro/directives-year/
158
+ * Transpose meta directive. See: https://www.chordpro.org/chordpro/directives-transpose/
159
159
  * @type {string}
160
160
  */
161
161
 
162
162
  exports.TITLE = TITLE;
163
+ var TRANSPOSE = 'transpose';
164
+ /**
165
+ * Year meta directive. See https://www.chordpro.org/chordpro/directives-year/
166
+ * @type {string}
167
+ */
168
+
169
+ exports.TRANSPOSE = TRANSPOSE;
163
170
  var YEAR = 'year';
164
171
  exports.YEAR = YEAR;
165
172
  var TITLE_SHORT = 't';
@@ -30,7 +30,8 @@ var HtmlFormatter = /*#__PURE__*/function () {
30
30
  bodyParagraphs: true,
31
31
  subtitle: true,
32
32
  title: true,
33
- value: true
33
+ value: true,
34
+ key: true
34
35
  }
35
36
  });
36
37
  }
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
3
  var Handlebars = require("handlebars");
6
4
 
7
5
  var template = Handlebars.template,
8
6
  templates = Handlebars.templates = Handlebars.templates || {};
9
7
  templates['html_div_formatter'] = template({
10
- "1": function _(container, depth0, helpers, partials, data, blockParams, depths) {
8
+ "1": function _(container, depth0, helpers, partials, data, blockParams) {
11
9
  var stack1,
12
10
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
13
11
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
@@ -21,7 +19,7 @@ templates['html_div_formatter'] = template({
21
19
  return ((stack1 = lookupProperty(helpers, "if").call(alias1, depth0 != null ? lookupProperty(depth0, "title") : depth0, {
22
20
  "name": "if",
23
21
  "hash": {},
24
- "fn": container.program(2, data, 0, blockParams, depths),
22
+ "fn": container.program(2, data, 0, blockParams),
25
23
  "inverse": container.noop,
26
24
  "data": data,
27
25
  "blockParams": blockParams,
@@ -38,7 +36,7 @@ templates['html_div_formatter'] = template({
38
36
  })) != null ? stack1 : "") + ((stack1 = lookupProperty(helpers, "if").call(alias1, depth0 != null ? lookupProperty(depth0, "subtitle") : depth0, {
39
37
  "name": "if",
40
38
  "hash": {},
41
- "fn": container.program(4, data, 0, blockParams, depths),
39
+ "fn": container.program(4, data, 0, blockParams),
42
40
  "inverse": container.noop,
43
41
  "data": data,
44
42
  "blockParams": blockParams,
@@ -55,7 +53,7 @@ templates['html_div_formatter'] = template({
55
53
  })) != null ? stack1 : "") + "<div class=\"chord-sheet\">" + ((stack1 = lookupProperty(helpers, "each").call(alias1, depth0 != null ? lookupProperty(depth0, "bodyParagraphs") : depth0, {
56
54
  "name": "each",
57
55
  "hash": {},
58
- "fn": container.program(6, data, 1, blockParams, depths),
56
+ "fn": container.program(6, data, 1, blockParams),
59
57
  "inverse": container.noop,
60
58
  "data": data,
61
59
  "blockParams": blockParams,
@@ -123,7 +121,7 @@ templates['html_div_formatter'] = template({
123
121
  }
124
122
  }) : helper)) + "</h2>";
125
123
  },
126
- "6": function _(container, depth0, helpers, partials, data, blockParams, depths) {
124
+ "6": function _(container, depth0, helpers, partials, data, blockParams) {
127
125
  var stack1,
128
126
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
129
127
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
@@ -152,7 +150,7 @@ templates['html_div_formatter'] = template({
152
150
  })) + "\">" + ((stack1 = lookupProperty(helpers, "each").call(alias1, depth0 != null ? lookupProperty(depth0, "lines") : depth0, {
153
151
  "name": "each",
154
152
  "hash": {},
155
- "fn": container.program(7, data, 1, blockParams, depths),
153
+ "fn": container.program(7, data, 1, blockParams),
156
154
  "inverse": container.noop,
157
155
  "data": data,
158
156
  "blockParams": blockParams,
@@ -168,7 +166,7 @@ templates['html_div_formatter'] = template({
168
166
  }
169
167
  })) != null ? stack1 : "") + "</div>";
170
168
  },
171
- "7": function _(container, depth0, helpers, partials, data, blockParams, depths) {
169
+ "7": function _(container, depth0, helpers, partials, data, blockParams) {
172
170
  var stack1,
173
171
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
174
172
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
@@ -197,7 +195,7 @@ templates['html_div_formatter'] = template({
197
195
  }), {
198
196
  "name": "if",
199
197
  "hash": {},
200
- "fn": container.program(8, data, 0, blockParams, depths),
198
+ "fn": container.program(8, data, 0, blockParams),
201
199
  "inverse": container.noop,
202
200
  "data": data,
203
201
  "blockParams": blockParams,
@@ -213,7 +211,7 @@ templates['html_div_formatter'] = template({
213
211
  }
214
212
  })) != null ? stack1 : "";
215
213
  },
216
- "8": function _(container, depth0, helpers, partials, data, blockParams, depths) {
214
+ "8": function _(container, depth0, helpers, partials, data, blockParams) {
217
215
  var stack1,
218
216
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
219
217
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
@@ -242,7 +240,7 @@ templates['html_div_formatter'] = template({
242
240
  })) + "\">" + ((stack1 = lookupProperty(helpers, "each").call(alias1, depth0 != null ? lookupProperty(depth0, "items") : depth0, {
243
241
  "name": "each",
244
242
  "hash": {},
245
- "fn": container.program(9, data, 1, blockParams, depths),
243
+ "fn": container.program(9, data, 1, blockParams),
246
244
  "inverse": container.noop,
247
245
  "data": data,
248
246
  "blockParams": blockParams,
@@ -258,7 +256,7 @@ templates['html_div_formatter'] = template({
258
256
  }
259
257
  })) != null ? stack1 : "") + "</div>";
260
258
  },
261
- "9": function _(container, depth0, helpers, partials, data, blockParams, depths) {
259
+ "9": function _(container, depth0, helpers, partials, data, blockParams) {
262
260
  var stack1,
263
261
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
264
262
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
@@ -287,7 +285,7 @@ templates['html_div_formatter'] = template({
287
285
  }), {
288
286
  "name": "if",
289
287
  "hash": {},
290
- "fn": container.program(10, data, 0, blockParams, depths),
288
+ "fn": container.program(10, data, 0, blockParams),
291
289
  "inverse": container.noop,
292
290
  "data": data,
293
291
  "blockParams": blockParams,
@@ -319,7 +317,7 @@ templates['html_div_formatter'] = template({
319
317
  }), {
320
318
  "name": "if",
321
319
  "hash": {},
322
- "fn": container.program(12, data, 0, blockParams, depths),
320
+ "fn": container.program(12, data, 0, blockParams),
323
321
  "inverse": container.noop,
324
322
  "data": data,
325
323
  "blockParams": blockParams,
@@ -351,7 +349,7 @@ templates['html_div_formatter'] = template({
351
349
  }), {
352
350
  "name": "if",
353
351
  "hash": {},
354
- "fn": container.program(15, data, 0, blockParams, depths),
352
+ "fn": container.program(15, data, 0, blockParams),
355
353
  "inverse": container.noop,
356
354
  "data": data,
357
355
  "blockParams": blockParams,
@@ -367,12 +365,12 @@ templates['html_div_formatter'] = template({
367
365
  }
368
366
  })) != null ? stack1 : "");
369
367
  },
370
- "10": function _(container, depth0, helpers, partials, data) {
371
- var helper,
368
+ "10": function _(container, depth0, helpers, partials, data, blockParams) {
369
+ var stack1,
370
+ helper,
372
371
  alias1 = depth0 != null ? depth0 : container.nullContext || {},
373
372
  alias2 = container.hooks.helperMissing,
374
- alias3 = "function",
375
- alias4 = container.escapeExpression,
373
+ alias3 = container.escapeExpression,
376
374
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
377
375
  if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
378
376
  return parent[propertyName];
@@ -381,10 +379,11 @@ templates['html_div_formatter'] = template({
381
379
  return undefined;
382
380
  };
383
381
 
384
- return "<div class=\"column\"><div class=\"chord\">" + alias4((helper = (helper = lookupProperty(helpers, "chords") || (depth0 != null ? lookupProperty(depth0, "chords") : depth0)) != null ? helper : alias2, _typeof(helper) === alias3 ? helper.call(alias1, {
385
- "name": "chords",
382
+ return "<div class=\"column\"><div class=\"chord\">" + alias3((lookupProperty(helpers, "renderChord") || depth0 && lookupProperty(depth0, "renderChord") || alias2).call(alias1, depth0 != null ? lookupProperty(depth0, "chords") : depth0, (stack1 = blockParams[3][0]) != null ? lookupProperty(stack1, "key") : stack1, (stack1 = (stack1 = data && lookupProperty(data, "root")) && lookupProperty(stack1, "song")) && lookupProperty(stack1, "key"), {
383
+ "name": "renderChord",
386
384
  "hash": {},
387
385
  "data": data,
386
+ "blockParams": blockParams,
388
387
  "loc": {
389
388
  "start": {
390
389
  "line": 18,
@@ -392,21 +391,22 @@ templates['html_div_formatter'] = template({
392
391
  },
393
392
  "end": {
394
393
  "line": 18,
395
- "column": 67
394
+ "column": 103
396
395
  }
397
396
  }
398
- }) : helper)) + "</div><div class=\"lyrics\">" + alias4((helper = (helper = lookupProperty(helpers, "lyrics") || (depth0 != null ? lookupProperty(depth0, "lyrics") : depth0)) != null ? helper : alias2, _typeof(helper) === alias3 ? helper.call(alias1, {
397
+ })) + "</div><div class=\"lyrics\">" + alias3((helper = (helper = lookupProperty(helpers, "lyrics") || (depth0 != null ? lookupProperty(depth0, "lyrics") : depth0)) != null ? helper : alias2, typeof helper === "function" ? helper.call(alias1, {
399
398
  "name": "lyrics",
400
399
  "hash": {},
401
400
  "data": data,
401
+ "blockParams": blockParams,
402
402
  "loc": {
403
403
  "start": {
404
404
  "line": 18,
405
- "column": 93
405
+ "column": 129
406
406
  },
407
407
  "end": {
408
408
  "line": 18,
409
- "column": 103
409
+ "column": 139
410
410
  }
411
411
  }
412
412
  }) : helper)) + "</div></div>";
@@ -482,7 +482,7 @@ templates['html_div_formatter'] = template({
482
482
  }
483
483
  }) : helper)) + "</div>";
484
484
  },
485
- "15": function _(container, depth0, helpers, partials, data, blockParams, depths) {
485
+ "15": function _(container, depth0, helpers, partials, data, blockParams) {
486
486
  var stack1,
487
487
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
488
488
  if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
@@ -492,7 +492,7 @@ templates['html_div_formatter'] = template({
492
492
  return undefined;
493
493
  };
494
494
 
495
- return "<div class=\"column\"><div class=\"chord\"></div><div class=\"lyrics\">" + container.escapeExpression((lookupProperty(helpers, "evaluate") || depth0 && lookupProperty(depth0, "evaluate") || container.hooks.helperMissing).call(depth0 != null ? depth0 : container.nullContext || {}, blockParams[1][0], (stack1 = depths[4] != null ? lookupProperty(depths[4], "song") : depths[4]) != null ? lookupProperty(stack1, "metadata") : stack1, {
495
+ return "<div class=\"column\"><div class=\"chord\"></div><div class=\"lyrics\">" + container.escapeExpression((lookupProperty(helpers, "evaluate") || depth0 && lookupProperty(depth0, "evaluate") || container.hooks.helperMissing).call(depth0 != null ? depth0 : container.nullContext || {}, blockParams[1][0], (stack1 = (stack1 = data && lookupProperty(data, "root")) && lookupProperty(stack1, "song")) && lookupProperty(stack1, "metadata"), {
496
496
  "name": "evaluate",
497
497
  "hash": {},
498
498
  "data": data,
@@ -504,13 +504,13 @@ templates['html_div_formatter'] = template({
504
504
  },
505
505
  "end": {
506
506
  "line": 28,
507
- "column": 126
507
+ "column": 120
508
508
  }
509
509
  }
510
510
  })) + "</div></div>";
511
511
  },
512
512
  "compiler": [8, ">= 4.3.0"],
513
- "main": function main(container, depth0, helpers, partials, data, blockParams, depths) {
513
+ "main": function main(container, depth0, helpers, partials, data, blockParams) {
514
514
  var stack1,
515
515
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
516
516
  if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
@@ -523,7 +523,7 @@ templates['html_div_formatter'] = template({
523
523
  return (stack1 = lookupProperty(helpers, "with").call(depth0 != null ? depth0 : container.nullContext || {}, depth0 != null ? lookupProperty(depth0, "song") : depth0, {
524
524
  "name": "with",
525
525
  "hash": {},
526
- "fn": container.program(1, data, 0, blockParams, depths),
526
+ "fn": container.program(1, data, 0, blockParams),
527
527
  "inverse": container.noop,
528
528
  "data": data,
529
529
  "blockParams": blockParams,
@@ -540,6 +540,5 @@ templates['html_div_formatter'] = template({
540
540
  })) != null ? stack1 : "";
541
541
  },
542
542
  "useData": true,
543
- "useDepths": true,
544
543
  "useBlockParams": true
545
544
  });
@@ -406,8 +406,8 @@ templates['html_table_formatter'] = template({
406
406
  }
407
407
  })) != null ? stack1 : "";
408
408
  },
409
- "12": function _(container, depth0, helpers, partials, data) {
410
- var helper,
409
+ "12": function _(container, depth0, helpers, partials, data, blockParams) {
410
+ var stack1,
411
411
  lookupProperty = container.lookupProperty || function (parent, propertyName) {
412
412
  if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
413
413
  return parent[propertyName];
@@ -416,10 +416,11 @@ templates['html_table_formatter'] = template({
416
416
  return undefined;
417
417
  };
418
418
 
419
- return "<td class=\"chord\">" + container.escapeExpression((helper = (helper = lookupProperty(helpers, "chords") || (depth0 != null ? lookupProperty(depth0, "chords") : depth0)) != null ? helper : container.hooks.helperMissing, typeof helper === "function" ? helper.call(depth0 != null ? depth0 : container.nullContext || {}, {
420
- "name": "chords",
419
+ return "<td class=\"chord\">" + container.escapeExpression((lookupProperty(helpers, "renderChord") || depth0 && lookupProperty(depth0, "renderChord") || container.hooks.helperMissing).call(depth0 != null ? depth0 : container.nullContext || {}, depth0 != null ? lookupProperty(depth0, "chords") : depth0, (stack1 = blockParams[4][0]) != null ? lookupProperty(stack1, "key") : stack1, (stack1 = (stack1 = data && lookupProperty(data, "root")) && lookupProperty(stack1, "song")) && lookupProperty(stack1, "key"), {
420
+ "name": "renderChord",
421
421
  "hash": {},
422
422
  "data": data,
423
+ "blockParams": blockParams,
423
424
  "loc": {
424
425
  "start": {
425
426
  "line": 21,
@@ -427,10 +428,10 @@ templates['html_table_formatter'] = template({
427
428
  },
428
429
  "end": {
429
430
  "line": 21,
430
- "column": 52
431
+ "column": 88
431
432
  }
432
433
  }
433
- }) : helper)) + "</td>";
434
+ })) + "</td>";
434
435
  },
435
436
  "14": function _(container, depth0, helpers, partials, data, blockParams, depths) {
436
437
  var stack1,
@@ -9,6 +9,8 @@ var _chord_lyrics_pair = _interopRequireDefault(require("../chord_sheet/chord_ly
9
9
 
10
10
  var _tag = _interopRequireDefault(require("../chord_sheet/tag"));
11
11
 
12
+ var _helpers = require("../helpers");
13
+
12
14
  var _utilities = require("../utilities");
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -36,23 +38,26 @@ var TextFormatter = /*#__PURE__*/function () {
36
38
  * @returns {string} the chord sheet
37
39
  */
38
40
  function format(song) {
39
- return [this.formatHeader(song), this.formatParagraphs(song)].join('');
41
+ this.song = song;
42
+ return [this.formatHeader(), this.formatParagraphs()].join('');
40
43
  }
41
44
  }, {
42
45
  key: "formatHeader",
43
- value: function formatHeader(song) {
44
- var title = song.title,
45
- subtitle = song.subtitle;
46
+ value: function formatHeader() {
47
+ var _this$song = this.song,
48
+ title = _this$song.title,
49
+ subtitle = _this$song.subtitle;
46
50
  var separator = title || subtitle ? '\n' : '';
47
51
  return [this.formatTitle(title), this.formatSubTitle(subtitle), separator].join('');
48
52
  }
49
53
  }, {
50
54
  key: "formatParagraphs",
51
- value: function formatParagraphs(song) {
55
+ value: function formatParagraphs() {
52
56
  var _this = this;
53
57
 
54
- var bodyParagraphs = song.bodyParagraphs,
55
- metadata = song.metadata;
58
+ var _this$song2 = this.song,
59
+ bodyParagraphs = _this$song2.bodyParagraphs,
60
+ metadata = _this$song2.metadata;
56
61
  return bodyParagraphs.map(function (paragraph) {
57
62
  return _this.formatParagraph(paragraph, metadata);
58
63
  }).join('\n\n');
@@ -107,9 +112,9 @@ var TextFormatter = /*#__PURE__*/function () {
107
112
  }
108
113
  }, {
109
114
  key: "chordLyricsPairLength",
110
- value: function chordLyricsPairLength(chordLyricsPair) {
111
- var chords = chordLyricsPair.chords,
112
- lyrics = chordLyricsPair.lyrics;
115
+ value: function chordLyricsPairLength(chordLyricsPair, line) {
116
+ var chords = (0, _helpers.renderChord)(chordLyricsPair.chords, line.key, this.song.key);
117
+ var lyrics = chordLyricsPair.lyrics;
113
118
  var chordsLength = (chords || '').length;
114
119
  var lyricsLength = (lyrics || '').length;
115
120
 
@@ -121,13 +126,14 @@ var TextFormatter = /*#__PURE__*/function () {
121
126
  }
122
127
  }, {
123
128
  key: "formatItemTop",
124
- value: function formatItemTop(item) {
129
+ value: function formatItemTop(item, metadata, line) {
125
130
  if (item instanceof _tag["default"] && item.isRenderable()) {
126
131
  return (0, _utilities.padLeft)('', item.value);
127
132
  }
128
133
 
129
134
  if (item instanceof _chord_lyrics_pair["default"]) {
130
- return (0, _utilities.padLeft)(item.chords || '', this.chordLyricsPairLength(item));
135
+ var chords = (0, _helpers.renderChord)(item.chords, line.key, this.song.key);
136
+ return (0, _utilities.padLeft)(chords, this.chordLyricsPairLength(item, line));
131
137
  }
132
138
 
133
139
  return '';
@@ -147,18 +153,18 @@ var TextFormatter = /*#__PURE__*/function () {
147
153
  var _this3 = this;
148
154
 
149
155
  return line.items.map(function (item) {
150
- return formatter.call(_this3, item, metadata);
156
+ return formatter.call(_this3, item, metadata, line);
151
157
  }).join('');
152
158
  }
153
159
  }, {
154
160
  key: "formatItemBottom",
155
- value: function formatItemBottom(item, metadata) {
161
+ value: function formatItemBottom(item, metadata, line) {
156
162
  if (item instanceof _tag["default"] && item.isRenderable()) {
157
163
  return item.value;
158
164
  }
159
165
 
160
166
  if (item instanceof _chord_lyrics_pair["default"]) {
161
- return (0, _utilities.padLeft)(item.lyrics, this.chordLyricsPairLength(item));
167
+ return (0, _utilities.padLeft)(item.lyrics, this.chordLyricsPairLength(item, line));
162
168
  }
163
169
 
164
170
  if (typeof item.evaluate === 'function') {
@@ -8,6 +8,8 @@ var _tag = _interopRequireDefault(require("./chord_sheet/tag"));
8
8
 
9
9
  var _constants = require("./constants");
10
10
 
11
+ var _helpers = require("./helpers");
12
+
11
13
  var _utilities = require("./utilities");
12
14
 
13
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -76,4 +78,6 @@ _handlebars["default"].registerHelper('evaluate', function (item, metadata) {
76
78
  }
77
79
 
78
80
  return item.evaluate(metadata);
79
- });
81
+ });
82
+
83
+ _handlebars["default"].registerHelper('renderChord', _helpers.renderChord);
package/lib/helpers.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renderChord = renderChord;
7
+
8
+ var _chord = _interopRequireDefault(require("./chord"));
9
+
10
+ var _utilities = require("./utilities");
11
+
12
+ var _key = _interopRequireDefault(require("./key"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ function transposeDistance(lineKey, songKey) {
17
+ if (/^\d+$/.test(lineKey)) {
18
+ return parseInt(lineKey, 10);
19
+ }
20
+
21
+ return _key["default"].distance(songKey, lineKey);
22
+ }
23
+ /* eslint import/prefer-default-export: 0 */
24
+
25
+
26
+ function renderChord(chord, lineKey, songKey) {
27
+ if ((0, _utilities.presence)(chord) && (0, _utilities.presence)(lineKey) && (0, _utilities.presence)(songKey)) {
28
+ return _chord["default"].parse(chord).transpose(transposeDistance(lineKey, songKey)).useModifier(lineKey.modifier).toString();
29
+ }
30
+
31
+ return chord;
32
+ }
package/lib/key.js CHANGED
@@ -72,6 +72,20 @@ var Key = /*#__PURE__*/function () {
72
72
  }
73
73
 
74
74
  _createClass(Key, [{
75
+ key: "distanceTo",
76
+ value: function distanceTo(otherKey) {
77
+ var otherKeyObj = Key.wrap(otherKey);
78
+ var key = this.useModifier(otherKeyObj.modifier);
79
+ var delta = 0;
80
+
81
+ while (!key.equals(otherKeyObj) && delta < 20) {
82
+ key = key.transposeUp().useModifier(otherKeyObj.modifier);
83
+ delta += 1;
84
+ }
85
+
86
+ return delta;
87
+ }
88
+ }, {
75
89
  key: "clone",
76
90
  value: function clone() {
77
91
  return _classPrivateMethodGet(this, _set, _set2).call(this, {});
@@ -276,6 +290,11 @@ var Key = /*#__PURE__*/function () {
276
290
 
277
291
  return this.parse(keyStringOrObject);
278
292
  }
293
+ }, {
294
+ key: "distance",
295
+ value: function distance(oneKey, otherKey) {
296
+ return this.wrap(oneKey).distanceTo(otherKey);
297
+ }
279
298
  }]);
280
299
 
281
300
  return Key;
package/lib/utilities.js CHANGED
@@ -9,12 +9,6 @@ exports.isEmptyString = isEmptyString;
9
9
  exports.pushNew = exports.presence = exports.padLeft = exports.isPresent = exports.isEvaluatable = void 0;
10
10
  exports.scopeCss = scopeCss;
11
11
 
12
- var _chord_lyrics_pair = _interopRequireDefault(require("./chord_sheet/chord_lyrics_pair"));
13
-
14
- var _tag = _interopRequireDefault(require("./chord_sheet/tag"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
-
18
12
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19
13
 
20
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -39,7 +33,7 @@ exports.pushNew = pushNew;
39
33
 
40
34
  var hasChordContents = function hasChordContents(line) {
41
35
  return line.items.some(function (item) {
42
- return item instanceof _chord_lyrics_pair["default"] && item.chords;
36
+ return !!item.chords;
43
37
  });
44
38
  };
45
39
 
@@ -51,9 +45,15 @@ var isEvaluatable = function isEvaluatable(item) {
51
45
 
52
46
  exports.isEvaluatable = isEvaluatable;
53
47
 
48
+ function isInstanceOf(object, constructorName) {
49
+ var _object$constructor;
50
+
51
+ return (object === null || object === void 0 ? void 0 : (_object$constructor = object.constructor) === null || _object$constructor === void 0 ? void 0 : _object$constructor.name) === constructorName;
52
+ }
53
+
54
54
  var hasTextContents = function hasTextContents(line) {
55
55
  return line.items.some(function (item) {
56
- return item instanceof _chord_lyrics_pair["default"] && item.lyrics || item instanceof _tag["default"] && item.isRenderable() || isEvaluatable(item);
56
+ return isInstanceOf(item, 'ChordLyricsPair') && item.lyrics || isInstanceOf(item, 'Tag') && item.isRenderable() || isEvaluatable(item);
57
57
  });
58
58
  };
59
59
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "chordsheetjs",
3
3
  "author": "Martijn Versluis",
4
- "version": "5.0.0",
4
+ "version": "5.1.2",
5
5
  "description": "A JavaScript library for parsing and formatting chord sheets",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -15,16 +15,17 @@
15
15
  "devDependencies": {
16
16
  "@babel/cli": "^7.10.1",
17
17
  "@babel/core": "^7.10.2",
18
+ "@babel/eslint-parser": "^7.16.3",
18
19
  "@babel/plugin-transform-runtime": "^7.10.1",
19
20
  "@babel/preset-env": "^7.10.2",
20
- "babel-eslint": "^10.1.0",
21
21
  "babel-plugin-handlebars-inline-precompile": "^2.1.1",
22
- "eslint": "^7.2.0",
22
+ "eslint": "^8.3.0",
23
23
  "eslint-config-airbnb-base": "^15.0.0",
24
24
  "eslint-plugin-import": "^2.21.2",
25
25
  "jest": "^27.0.1",
26
26
  "jsdoc-to-markdown": "^7.1.0",
27
- "pegjs": "^0.10.0"
27
+ "pegjs": "^0.10.0",
28
+ "print": "^1.2.0"
28
29
  },
29
30
  "scripts": {
30
31
  "jest": "jest",