chordsheetjs 4.9.0 → 5.1.3

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.
Files changed (39) hide show
  1. package/README.md +164 -138
  2. package/lib/chord.js +341 -35
  3. package/lib/chord_sheet/chord_lyrics_pair.js +1 -1
  4. package/lib/chord_sheet/chord_pro/composite.js +1 -1
  5. package/lib/chord_sheet/chord_pro/evaluation_error.js +7 -3
  6. package/lib/chord_sheet/chord_pro/literal.js +1 -1
  7. package/lib/chord_sheet/chord_pro/ternary.js +1 -1
  8. package/lib/chord_sheet/comment.js +1 -1
  9. package/lib/chord_sheet/line.js +1 -1
  10. package/lib/chord_sheet/metadata.js +4 -4
  11. package/lib/chord_sheet/paragraph.js +1 -1
  12. package/lib/chord_sheet/song.js +17 -5
  13. package/lib/chord_sheet/tag.js +29 -6
  14. package/lib/chord_sheet_serializer.js +1 -1
  15. package/lib/constants.js +14 -2
  16. package/lib/formatter/chord_pro_formatter.js +1 -1
  17. package/lib/formatter/html_div_formatter.js +4 -4
  18. package/lib/formatter/html_formatter.js +3 -2
  19. package/lib/formatter/html_table_formatter.js +4 -4
  20. package/lib/formatter/templates/html_div_formatter.js +31 -32
  21. package/lib/formatter/templates/html_table_formatter.js +7 -6
  22. package/lib/formatter/text_formatter.js +25 -17
  23. package/lib/helpers.js +32 -0
  24. package/lib/index.js +33 -10
  25. package/lib/key.js +311 -0
  26. package/lib/note.js +132 -0
  27. package/lib/parser/chord_pro_parser.js +1 -1
  28. package/lib/parser/chord_pro_peg_parser.js +2 -2
  29. package/lib/parser/chord_sheet_parser.js +1 -1
  30. package/lib/parser/parser_warning.js +1 -1
  31. package/lib/parser/ultimate_guitar_parser.js +4 -4
  32. package/lib/{handlebars_helpers.js → template_helpers.js} +21 -2
  33. package/lib/utilities.js +22 -23
  34. package/package.json +7 -6
  35. package/lib/chord_helpers.js +0 -222
  36. package/lib/chord_symbol.js +0 -139
  37. package/lib/numeric_chord.js +0 -138
  38. package/lib/parse_chord.js +0 -74
  39. package/lib/to_chord_symbol.js +0 -93
@@ -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_CHORUS = exports.READ_ONLY_TAGS = exports.META_TAGS = exports.LYRICIST = exports.KEY = exports.END_OF_VERSE = 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;
@@ -12,7 +12,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
12
12
 
13
13
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
14
14
 
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
16
 
17
17
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
18
 
@@ -71,11 +71,18 @@ var DURATION = 'duration';
71
71
  exports.DURATION = DURATION;
72
72
  var END_OF_CHORUS = 'end_of_chorus';
73
73
  /**
74
- * End of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
74
+ * End of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
75
75
  * @type {string}
76
76
  */
77
77
 
78
78
  exports.END_OF_CHORUS = END_OF_CHORUS;
79
+ var END_OF_TAB = 'end_of_tab';
80
+ /**
81
+ * End of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
82
+ * @type {string}
83
+ */
84
+
85
+ exports.END_OF_TAB = END_OF_TAB;
79
86
  var END_OF_VERSE = 'end_of_verse';
80
87
  /**
81
88
  * Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
@@ -106,11 +113,18 @@ var LYRICIST = 'lyricist';
106
113
  exports.LYRICIST = LYRICIST;
107
114
  var START_OF_CHORUS = 'start_of_chorus';
108
115
  /**
109
- * Start of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
116
+ * Start of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
110
117
  * @type {string}
111
118
  */
112
119
 
113
120
  exports.START_OF_CHORUS = START_OF_CHORUS;
121
+ var START_OF_TAB = 'start_of_tab';
122
+ /**
123
+ * Start of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
124
+ * @type {string}
125
+ */
126
+
127
+ exports.START_OF_TAB = START_OF_TAB;
114
128
  var START_OF_VERSE = 'start_of_verse';
115
129
  /**
116
130
  * Subtitle meta directive. See https://www.chordpro.org/chordpro/directives-subtitle/
@@ -141,11 +155,18 @@ var TIME = 'time';
141
155
  exports.TIME = TIME;
142
156
  var TITLE = 'title';
143
157
  /**
144
- * Year meta directive. See https://www.chordpro.org/chordpro/directives-year/
158
+ * Transpose meta directive. See: https://www.chordpro.org/chordpro/directives-transpose/
145
159
  * @type {string}
146
160
  */
147
161
 
148
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;
149
170
  var YEAR = 'year';
150
171
  exports.YEAR = YEAR;
151
172
  var TITLE_SHORT = 't';
@@ -153,12 +174,14 @@ var SUBTITLE_SHORT = 'st';
153
174
  var COMMENT_SHORT = 'c';
154
175
  var START_OF_CHORUS_SHORT = 'soc';
155
176
  var END_OF_CHORUS_SHORT = 'eoc';
177
+ var START_OF_TAB_SHORT = 'sot';
178
+ var END_OF_TAB_SHORT = 'eot';
156
179
  var RENDERABLE_TAGS = [COMMENT];
157
180
  var META_TAGS = [ALBUM, ARTIST, CAPO, COMPOSER, COPYRIGHT, DURATION, KEY, LYRICIST, TEMPO, TIME, TITLE, SUBTITLE, YEAR];
158
181
  exports.META_TAGS = META_TAGS;
159
182
  var READ_ONLY_TAGS = [_KEY];
160
183
  exports.READ_ONLY_TAGS = READ_ONLY_TAGS;
161
- var ALIASES = (_ALIASES = {}, _defineProperty(_ALIASES, TITLE_SHORT, TITLE), _defineProperty(_ALIASES, SUBTITLE_SHORT, SUBTITLE), _defineProperty(_ALIASES, COMMENT_SHORT, COMMENT), _defineProperty(_ALIASES, START_OF_CHORUS_SHORT, START_OF_CHORUS), _defineProperty(_ALIASES, END_OF_CHORUS_SHORT, END_OF_CHORUS), _ALIASES);
184
+ var ALIASES = (_ALIASES = {}, _defineProperty(_ALIASES, TITLE_SHORT, TITLE), _defineProperty(_ALIASES, SUBTITLE_SHORT, SUBTITLE), _defineProperty(_ALIASES, COMMENT_SHORT, COMMENT), _defineProperty(_ALIASES, START_OF_CHORUS_SHORT, START_OF_CHORUS), _defineProperty(_ALIASES, END_OF_CHORUS_SHORT, END_OF_CHORUS), _defineProperty(_ALIASES, START_OF_TAB_SHORT, START_OF_TAB), _defineProperty(_ALIASES, END_OF_TAB_SHORT, END_OF_TAB), _ALIASES);
162
185
  var META_TAG_REGEX = /^meta:\s*([^:\s]+)(\s*(.+))?$/;
163
186
  var TAG_REGEX = /^([^:\s]+)(:?\s*(.+))?$/;
164
187
  var CUSTOM_META_TAG_NAME_REGEX = /^x_(.+)$/;
@@ -25,7 +25,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
25
25
 
26
26
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
27
27
 
28
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
29
29
 
30
30
  var CHORD_SHEET = 'chordSheet';
31
31
  var CHORD_LYRICS_PAIR = 'chordLyricsPair';
package/lib/constants.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VERSE = exports.NONE = exports.INDETERMINATE = exports.CHORUS = void 0;
6
+ exports.VERSE = exports.TAB = exports.SYMBOL = exports.NUMERIC = exports.NONE = exports.INDETERMINATE = exports.CHORUS = void 0;
7
7
 
8
8
  /**
9
9
  * Used to mark a paragraph as verse
@@ -35,4 +35,16 @@ var NONE = 'none';
35
35
 
36
36
  exports.NONE = NONE;
37
37
  var INDETERMINATE = 'indeterminate';
38
- exports.INDETERMINATE = INDETERMINATE;
38
+ /**
39
+ * Used to mark a paragraph as tab
40
+ * @constant
41
+ * @type {string}
42
+ */
43
+
44
+ exports.INDETERMINATE = INDETERMINATE;
45
+ var TAB = 'tab';
46
+ exports.TAB = TAB;
47
+ var SYMBOL = 'symbol';
48
+ exports.SYMBOL = SYMBOL;
49
+ var NUMERIC = 'numeric';
50
+ exports.NUMERIC = NUMERIC;
@@ -19,7 +19,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
19
19
 
20
20
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21
21
 
22
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
22
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
23
 
24
24
  var NEW_LINE = '\n';
25
25
  /**
@@ -1,6 +1,6 @@
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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -9,7 +9,7 @@ exports["default"] = void 0;
9
9
 
10
10
  var _handlebars = _interopRequireDefault(require("handlebars"));
11
11
 
12
- require("../handlebars_helpers");
12
+ require("../template_helpers");
13
13
 
14
14
  var _html_formatter = _interopRequireDefault(require("./html_formatter"));
15
15
 
@@ -23,9 +23,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
23
23
 
24
24
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
25
25
 
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
27
 
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
28
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
29
 
30
30
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
31
 
@@ -9,7 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
9
9
 
10
10
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
11
 
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
13
 
14
14
  /**
15
15
  * Acts as a base class for HTML formatters, taking care of whitelisting prototype property access.
@@ -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,6 +1,6 @@
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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -10,7 +10,7 @@ exports.scopedCss = scopedCss;
10
10
 
11
11
  var _handlebars = _interopRequireDefault(require("handlebars"));
12
12
 
13
- require("../handlebars_helpers");
13
+ require("../template_helpers");
14
14
 
15
15
  var _html_formatter = _interopRequireDefault(require("./html_formatter"));
16
16
 
@@ -24,9 +24,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
24
24
 
25
25
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
26
26
 
27
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
27
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
28
 
29
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
30
30
 
31
31
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
32
 
@@ -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,10 @@ 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
+
14
+ var _template_helpers = require("../template_helpers");
15
+
12
16
  var _utilities = require("../utilities");
13
17
 
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -17,7 +21,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
17
21
 
18
22
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
19
23
 
20
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
25
 
22
26
  /**
23
27
  * Formats a song into a plain text chord sheet
@@ -36,23 +40,26 @@ var TextFormatter = /*#__PURE__*/function () {
36
40
  * @returns {string} the chord sheet
37
41
  */
38
42
  function format(song) {
39
- return [this.formatHeader(song), this.formatParagraphs(song)].join('');
43
+ this.song = song;
44
+ return [this.formatHeader(), this.formatParagraphs()].join('');
40
45
  }
41
46
  }, {
42
47
  key: "formatHeader",
43
- value: function formatHeader(song) {
44
- var title = song.title,
45
- subtitle = song.subtitle;
48
+ value: function formatHeader() {
49
+ var _this$song = this.song,
50
+ title = _this$song.title,
51
+ subtitle = _this$song.subtitle;
46
52
  var separator = title || subtitle ? '\n' : '';
47
53
  return [this.formatTitle(title), this.formatSubTitle(subtitle), separator].join('');
48
54
  }
49
55
  }, {
50
56
  key: "formatParagraphs",
51
- value: function formatParagraphs(song) {
57
+ value: function formatParagraphs() {
52
58
  var _this = this;
53
59
 
54
- var bodyParagraphs = song.bodyParagraphs,
55
- metadata = song.metadata;
60
+ var _this$song2 = this.song,
61
+ bodyParagraphs = _this$song2.bodyParagraphs,
62
+ metadata = _this$song2.metadata;
56
63
  return bodyParagraphs.map(function (paragraph) {
57
64
  return _this.formatParagraph(paragraph, metadata);
58
65
  }).join('\n\n');
@@ -107,9 +114,9 @@ var TextFormatter = /*#__PURE__*/function () {
107
114
  }
108
115
  }, {
109
116
  key: "chordLyricsPairLength",
110
- value: function chordLyricsPairLength(chordLyricsPair) {
111
- var chords = chordLyricsPair.chords,
112
- lyrics = chordLyricsPair.lyrics;
117
+ value: function chordLyricsPairLength(chordLyricsPair, line) {
118
+ var chords = (0, _helpers.renderChord)(chordLyricsPair.chords, line.key, this.song.key);
119
+ var lyrics = chordLyricsPair.lyrics;
113
120
  var chordsLength = (chords || '').length;
114
121
  var lyricsLength = (lyrics || '').length;
115
122
 
@@ -121,13 +128,14 @@ var TextFormatter = /*#__PURE__*/function () {
121
128
  }
122
129
  }, {
123
130
  key: "formatItemTop",
124
- value: function formatItemTop(item) {
131
+ value: function formatItemTop(item, metadata, line) {
125
132
  if (item instanceof _tag["default"] && item.isRenderable()) {
126
133
  return (0, _utilities.padLeft)('', item.value);
127
134
  }
128
135
 
129
136
  if (item instanceof _chord_lyrics_pair["default"]) {
130
- return (0, _utilities.padLeft)(item.chords || '', this.chordLyricsPairLength(item));
137
+ var chords = (0, _helpers.renderChord)(item.chords, line.key, this.song.key);
138
+ return (0, _utilities.padLeft)(chords, this.chordLyricsPairLength(item, line));
131
139
  }
132
140
 
133
141
  return '';
@@ -135,7 +143,7 @@ var TextFormatter = /*#__PURE__*/function () {
135
143
  }, {
136
144
  key: "formatLineBottom",
137
145
  value: function formatLineBottom(line, metadata) {
138
- if ((0, _utilities.hasTextContents)(line)) {
146
+ if ((0, _template_helpers.hasTextContents)(line)) {
139
147
  return this.formatLineWithFormatter(line, this.formatItemBottom, metadata);
140
148
  }
141
149
 
@@ -147,18 +155,18 @@ var TextFormatter = /*#__PURE__*/function () {
147
155
  var _this3 = this;
148
156
 
149
157
  return line.items.map(function (item) {
150
- return formatter.call(_this3, item, metadata);
158
+ return formatter.call(_this3, item, metadata, line);
151
159
  }).join('');
152
160
  }
153
161
  }, {
154
162
  key: "formatItemBottom",
155
- value: function formatItemBottom(item, metadata) {
163
+ value: function formatItemBottom(item, metadata, line) {
156
164
  if (item instanceof _tag["default"] && item.isRenderable()) {
157
165
  return item.value;
158
166
  }
159
167
 
160
168
  if (item instanceof _chord_lyrics_pair["default"]) {
161
- return (0, _utilities.padLeft)(item.lyrics, this.chordLyricsPairLength(item));
169
+ return (0, _utilities.padLeft)(item.lyrics, this.chordLyricsPairLength(item, line));
162
170
  }
163
171
 
164
172
  if (typeof item.evaluate === 'function') {
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
+ }