chordsheetjs 6.0.0 → 6.2.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/README.md +477 -539
- package/lib/bundle.js +15353 -0
- package/lib/index.js +6253 -216
- package/lib/index.js.map +1 -0
- package/lib/main.d.ts +1062 -0
- package/lib/main.d.ts.map +1 -0
- package/package.json +50 -23
- package/d7b54993c4ea66c07a35bd36690482ab620f836e.patch +0 -105
- package/lib/chord.js +0 -496
- package/lib/chord_sheet/chord_lyrics_pair.js +0 -75
- package/lib/chord_sheet/chord_pro/composite.js +0 -54
- package/lib/chord_sheet/chord_pro/evaluation_error.js +0 -58
- package/lib/chord_sheet/chord_pro/literal.js +0 -42
- package/lib/chord_sheet/chord_pro/ternary.js +0 -126
- package/lib/chord_sheet/comment.js +0 -55
- package/lib/chord_sheet/line.js +0 -185
- package/lib/chord_sheet/metadata.js +0 -202
- package/lib/chord_sheet/paragraph.js +0 -88
- package/lib/chord_sheet/song.js +0 -353
- package/lib/chord_sheet/tag.js +0 -345
- package/lib/chord_sheet_serializer.js +0 -278
- package/lib/constants.js +0 -54
- package/lib/formatter/chord_pro_formatter.js +0 -184
- package/lib/formatter/html_div_formatter.js +0 -130
- package/lib/formatter/html_formatter.js +0 -44
- package/lib/formatter/html_table_formatter.js +0 -154
- package/lib/formatter/templates/html_div_formatter.js +0 -544
- package/lib/formatter/templates/html_table_formatter.js +0 -731
- package/lib/formatter/text_formatter.js +0 -184
- package/lib/helpers.js +0 -32
- package/lib/key.js +0 -386
- package/lib/normalize_mappings/enharmonic-normalize.js +0 -124
- package/lib/normalize_mappings/generate-suffix-normalize-mapping.js +0 -36
- package/lib/normalize_mappings/suffix-normalize-mapping.js +0 -914
- package/lib/note.js +0 -264
- package/lib/parser/chord_pro_parser.js +0 -64
- package/lib/parser/chord_pro_peg_parser.js +0 -2069
- package/lib/parser/chord_sheet_parser.js +0 -175
- package/lib/parser/parser_warning.js +0 -62
- package/lib/parser/ultimate_guitar_parser.js +0 -154
- package/lib/template_helpers.js +0 -98
- package/lib/utilities.js +0 -110
package/lib/chord_sheet/song.js
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _line = _interopRequireDefault(require("./line"));
|
|
11
|
-
|
|
12
|
-
var _paragraph = _interopRequireDefault(require("./paragraph"));
|
|
13
|
-
|
|
14
|
-
var _utilities = require("../utilities");
|
|
15
|
-
|
|
16
|
-
var _metadata = _interopRequireDefault(require("./metadata"));
|
|
17
|
-
|
|
18
|
-
var _parser_warning = _interopRequireDefault(require("../parser/parser_warning"));
|
|
19
|
-
|
|
20
|
-
var _constants = require("../constants");
|
|
21
|
-
|
|
22
|
-
var _tag = _interopRequireWildcard(require("./tag"));
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
-
|
|
30
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
31
|
-
|
|
32
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
33
|
-
|
|
34
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
35
|
-
|
|
36
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
37
|
-
|
|
38
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
39
|
-
|
|
40
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
41
|
-
|
|
42
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
43
|
-
|
|
44
|
-
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); } }
|
|
45
|
-
|
|
46
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Represents a song in a chord sheet. Currently a chord sheet can only have one song.
|
|
50
|
-
*/
|
|
51
|
-
var Song = /*#__PURE__*/function () {
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new {Song} instance
|
|
54
|
-
* @param metadata {Object|Metadata} predefined metadata
|
|
55
|
-
*/
|
|
56
|
-
function Song() {
|
|
57
|
-
var metadata = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
58
|
-
|
|
59
|
-
_classCallCheck(this, Song);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The {@link Line} items of which the song consists
|
|
63
|
-
* @member
|
|
64
|
-
* @type {Array<Line>}
|
|
65
|
-
*/
|
|
66
|
-
this.lines = [];
|
|
67
|
-
/**
|
|
68
|
-
* The {@link Paragraph} items of which the song consists
|
|
69
|
-
* @member
|
|
70
|
-
* @type {Paragraph[]}
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
this.paragraphs = [];
|
|
74
|
-
/**
|
|
75
|
-
* The song's metadata. When there is only one value for an entry, the value is a string. Else, the value is
|
|
76
|
-
* an array containing all unique values for the entry.
|
|
77
|
-
* @type {Metadata}
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
this.metadata = new _metadata["default"](metadata);
|
|
81
|
-
this.currentLine = null;
|
|
82
|
-
this.currentParagraph = null;
|
|
83
|
-
this.warnings = [];
|
|
84
|
-
this.sectionType = _constants.NONE;
|
|
85
|
-
this.currentKey = null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_createClass(Song, [{
|
|
89
|
-
key: "previousLine",
|
|
90
|
-
get: function get() {
|
|
91
|
-
var count = this.lines.length;
|
|
92
|
-
|
|
93
|
-
if (count >= 2) {
|
|
94
|
-
return this.lines[count - 2];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns the song lines, skipping the leading empty lines (empty as in not rendering any content). This is useful
|
|
101
|
-
* if you want to skip the "header lines": the lines that only contain meta data.
|
|
102
|
-
* @returns {Line[]} The song body lines
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
}, {
|
|
106
|
-
key: "bodyLines",
|
|
107
|
-
get: function get() {
|
|
108
|
-
return this.selectRenderableItems('_bodyLines', 'lines');
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns the song paragraphs, skipping the paragraphs that only contain empty lines
|
|
112
|
-
* (empty as in not rendering any content)
|
|
113
|
-
* @see {@link bodyLines}
|
|
114
|
-
* @returns {Paragraph[]}
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
}, {
|
|
118
|
-
key: "bodyParagraphs",
|
|
119
|
-
get: function get() {
|
|
120
|
-
return this.selectRenderableItems('_bodyParagraphs', 'paragraphs');
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "selectRenderableItems",
|
|
124
|
-
value: function selectRenderableItems(targetProp, sourceProp) {
|
|
125
|
-
if (this[targetProp] === undefined) {
|
|
126
|
-
this[targetProp] = _toConsumableArray(this[sourceProp]);
|
|
127
|
-
var collection = this[targetProp];
|
|
128
|
-
|
|
129
|
-
while (collection.length > 0 && !collection[0].hasRenderableItems()) {
|
|
130
|
-
this[targetProp].shift();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return this[targetProp];
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
|
-
key: "chords",
|
|
138
|
-
value: function chords(chr) {
|
|
139
|
-
this.currentLine.chords(chr);
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "lyrics",
|
|
143
|
-
value: function lyrics(chr) {
|
|
144
|
-
this.ensureLine();
|
|
145
|
-
this.currentLine.lyrics(chr);
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "addLine",
|
|
149
|
-
value: function addLine() {
|
|
150
|
-
this.ensureParagraph();
|
|
151
|
-
this.flushLine();
|
|
152
|
-
this.currentLine = (0, _utilities.pushNew)(this.lines, _line["default"]);
|
|
153
|
-
this.setCurrentLineType(this.sectionType);
|
|
154
|
-
this.currentLine.key = this.currentKey;
|
|
155
|
-
return this.currentLine;
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "setCurrentLineType",
|
|
159
|
-
value: function setCurrentLineType(sectionType) {
|
|
160
|
-
this.currentLine.type = sectionType;
|
|
161
|
-
}
|
|
162
|
-
}, {
|
|
163
|
-
key: "flushLine",
|
|
164
|
-
value: function flushLine() {
|
|
165
|
-
if (this.currentLine !== null) {
|
|
166
|
-
if (this.currentLine.isEmpty()) {
|
|
167
|
-
this.addParagraph();
|
|
168
|
-
} else if (this.currentLine.hasRenderableItems()) {
|
|
169
|
-
this.currentParagraph.addLine(this.currentLine);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "finish",
|
|
175
|
-
value: function finish() {
|
|
176
|
-
this.flushLine();
|
|
177
|
-
}
|
|
178
|
-
}, {
|
|
179
|
-
key: "addChordLyricsPair",
|
|
180
|
-
value: function addChordLyricsPair() {
|
|
181
|
-
var chords = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
182
|
-
var lyrics = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
183
|
-
this.ensureLine();
|
|
184
|
-
return this.currentLine.addChordLyricsPair(chords, lyrics);
|
|
185
|
-
}
|
|
186
|
-
}, {
|
|
187
|
-
key: "ensureLine",
|
|
188
|
-
value: function ensureLine() {
|
|
189
|
-
if (this.currentLine === null) {
|
|
190
|
-
this.addLine();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}, {
|
|
194
|
-
key: "addParagraph",
|
|
195
|
-
value: function addParagraph() {
|
|
196
|
-
this.currentParagraph = (0, _utilities.pushNew)(this.paragraphs, _paragraph["default"]);
|
|
197
|
-
return this.currentParagraph;
|
|
198
|
-
}
|
|
199
|
-
}, {
|
|
200
|
-
key: "ensureParagraph",
|
|
201
|
-
value: function ensureParagraph() {
|
|
202
|
-
if (this.currentParagraph === null) {
|
|
203
|
-
this.addParagraph();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
key: "addTag",
|
|
208
|
-
value: function addTag(tagContents) {
|
|
209
|
-
var tag = _tag["default"].parse(tagContents);
|
|
210
|
-
|
|
211
|
-
if (tag.isMetaTag()) {
|
|
212
|
-
this.setMetaData(tag.name, tag.value);
|
|
213
|
-
} else if (tag.name === _tag.TRANSPOSE) {
|
|
214
|
-
this.currentKey = tag.value;
|
|
215
|
-
} else {
|
|
216
|
-
this.setSectionTypeFromTag(tag);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
this.ensureLine();
|
|
220
|
-
this.currentLine.addTag(tag);
|
|
221
|
-
return tag;
|
|
222
|
-
}
|
|
223
|
-
}, {
|
|
224
|
-
key: "setSectionTypeFromTag",
|
|
225
|
-
value: function setSectionTypeFromTag(tag) {
|
|
226
|
-
switch (tag.name) {
|
|
227
|
-
case _tag.START_OF_CHORUS:
|
|
228
|
-
this.startSection(_constants.CHORUS, tag);
|
|
229
|
-
break;
|
|
230
|
-
|
|
231
|
-
case _tag.END_OF_CHORUS:
|
|
232
|
-
this.endSection(_constants.CHORUS, tag);
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
case _tag.START_OF_TAB:
|
|
236
|
-
this.startSection(_constants.TAB, tag);
|
|
237
|
-
break;
|
|
238
|
-
|
|
239
|
-
case _tag.END_OF_TAB:
|
|
240
|
-
this.endSection(_constants.TAB, tag);
|
|
241
|
-
break;
|
|
242
|
-
|
|
243
|
-
case _tag.START_OF_VERSE:
|
|
244
|
-
this.startSection(_constants.VERSE, tag);
|
|
245
|
-
break;
|
|
246
|
-
|
|
247
|
-
case _tag.END_OF_VERSE:
|
|
248
|
-
this.endSection(_constants.VERSE, tag);
|
|
249
|
-
break;
|
|
250
|
-
|
|
251
|
-
default:
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}, {
|
|
256
|
-
key: "startSection",
|
|
257
|
-
value: function startSection(sectionType, tag) {
|
|
258
|
-
this.checkCurrentSectionType(_constants.NONE, tag);
|
|
259
|
-
this.sectionType = sectionType;
|
|
260
|
-
this.setCurrentLineType(sectionType);
|
|
261
|
-
}
|
|
262
|
-
}, {
|
|
263
|
-
key: "endSection",
|
|
264
|
-
value: function endSection(sectionType, tag) {
|
|
265
|
-
this.checkCurrentSectionType(sectionType, tag);
|
|
266
|
-
this.sectionType = _constants.NONE;
|
|
267
|
-
}
|
|
268
|
-
}, {
|
|
269
|
-
key: "checkCurrentSectionType",
|
|
270
|
-
value: function checkCurrentSectionType(sectionType, tag) {
|
|
271
|
-
if (this.sectionType !== sectionType) {
|
|
272
|
-
this.addWarning("Unexpected tag {".concat(tag.originalName, ", current section is: ").concat(this.sectionType), tag);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}, {
|
|
276
|
-
key: "addWarning",
|
|
277
|
-
value: function addWarning(message, _ref) {
|
|
278
|
-
var line = _ref.line,
|
|
279
|
-
column = _ref.column;
|
|
280
|
-
var warning = new _parser_warning["default"](message, line, column);
|
|
281
|
-
this.warnings.push(warning);
|
|
282
|
-
}
|
|
283
|
-
}, {
|
|
284
|
-
key: "addComment",
|
|
285
|
-
value: function addComment(comment) {
|
|
286
|
-
this.ensureLine();
|
|
287
|
-
this.currentLine.addComment(comment);
|
|
288
|
-
}
|
|
289
|
-
}, {
|
|
290
|
-
key: "addItem",
|
|
291
|
-
value: function addItem(item) {
|
|
292
|
-
if (item instanceof _tag["default"]) {
|
|
293
|
-
this.addTag(item);
|
|
294
|
-
} else {
|
|
295
|
-
this.ensureLine();
|
|
296
|
-
this.currentLine.addItem(item);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Returns a deep clone of the song
|
|
301
|
-
* @returns {Song} The cloned song
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
}, {
|
|
305
|
-
key: "clone",
|
|
306
|
-
value: function clone() {
|
|
307
|
-
var clonedSong = new Song();
|
|
308
|
-
clonedSong.lines = this.lines.map(function (line) {
|
|
309
|
-
return line.clone();
|
|
310
|
-
});
|
|
311
|
-
clonedSong.metadata = this.metadata.clone();
|
|
312
|
-
return clonedSong;
|
|
313
|
-
}
|
|
314
|
-
}, {
|
|
315
|
-
key: "setMetaData",
|
|
316
|
-
value: function setMetaData(name, value) {
|
|
317
|
-
this.metadata.add(name, value);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* The song's metadata. Please use {@link metadata} instead.
|
|
321
|
-
* @deprecated
|
|
322
|
-
* @returns {@link Metadata} The metadata
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
}, {
|
|
326
|
-
key: "metaData",
|
|
327
|
-
get: function get() {
|
|
328
|
-
(0, _utilities.deprecate)('metaData has been deprecated, please use metadata instead (notice the lowercase "d")');
|
|
329
|
-
return this.metadata;
|
|
330
|
-
}
|
|
331
|
-
}, {
|
|
332
|
-
key: "getMetaData",
|
|
333
|
-
value: function getMetaData(name) {
|
|
334
|
-
return this.metadata[name] || null;
|
|
335
|
-
}
|
|
336
|
-
}]);
|
|
337
|
-
|
|
338
|
-
return Song;
|
|
339
|
-
}();
|
|
340
|
-
|
|
341
|
-
var defineProperty = Object.defineProperty;
|
|
342
|
-
var songPrototype = Song.prototype;
|
|
343
|
-
|
|
344
|
-
_tag.META_TAGS.forEach(function (tagName) {
|
|
345
|
-
defineProperty(songPrototype, tagName, {
|
|
346
|
-
get: function get() {
|
|
347
|
-
return this.getMetaData(tagName);
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
var _default = Song;
|
|
353
|
-
exports["default"] = _default;
|
package/lib/chord_sheet/tag.js
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
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
|
-
exports.isReadonlyTag = isReadonlyTag;
|
|
8
|
-
|
|
9
|
-
var _ALIASES;
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Album meta directive. See https://www.chordpro.org/chordpro/directives-album/
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
var ALBUM = 'album';
|
|
24
|
-
/**
|
|
25
|
-
* Artist meta directive. See https://www.chordpro.org/chordpro/directives-artist/
|
|
26
|
-
* @type {string}
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
exports.ALBUM = ALBUM;
|
|
30
|
-
var ARTIST = 'artist';
|
|
31
|
-
/**
|
|
32
|
-
* Capo meta directive. See https://www.chordpro.org/chordpro/directives-capo/
|
|
33
|
-
* @type {string}
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
exports.ARTIST = ARTIST;
|
|
37
|
-
var CAPO = 'capo';
|
|
38
|
-
/**
|
|
39
|
-
* Comment directive. See https://www.chordpro.org/chordpro/directives-comment/
|
|
40
|
-
* @type {string}
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
exports.CAPO = CAPO;
|
|
44
|
-
var COMMENT = 'comment';
|
|
45
|
-
/**
|
|
46
|
-
* Composer meta directive. See https://www.chordpro.org/chordpro/directives-composer/
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
exports.COMMENT = COMMENT;
|
|
51
|
-
var COMPOSER = 'composer';
|
|
52
|
-
/**
|
|
53
|
-
* Copyright meta directive. See https://www.chordpro.org/chordpro/directives-copyright/
|
|
54
|
-
* @type {string}
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
exports.COMPOSER = COMPOSER;
|
|
58
|
-
var COPYRIGHT = 'copyright';
|
|
59
|
-
/**
|
|
60
|
-
* Duration meta directive. See https://www.chordpro.org/chordpro/directives-duration/
|
|
61
|
-
* @type {string}
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
exports.COPYRIGHT = COPYRIGHT;
|
|
65
|
-
var DURATION = 'duration';
|
|
66
|
-
/**
|
|
67
|
-
* End of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
|
|
68
|
-
* @type {string}
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
exports.DURATION = DURATION;
|
|
72
|
-
var END_OF_CHORUS = 'end_of_chorus';
|
|
73
|
-
/**
|
|
74
|
-
* End of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
|
|
75
|
-
* @type {string}
|
|
76
|
-
*/
|
|
77
|
-
|
|
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;
|
|
86
|
-
var END_OF_VERSE = 'end_of_verse';
|
|
87
|
-
/**
|
|
88
|
-
* Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
|
|
89
|
-
* @type {string}
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
exports.END_OF_VERSE = END_OF_VERSE;
|
|
93
|
-
var KEY = 'key';
|
|
94
|
-
/**
|
|
95
|
-
* Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
|
|
96
|
-
* @type {string}
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
exports.KEY = KEY;
|
|
100
|
-
var _KEY = '_key';
|
|
101
|
-
/**
|
|
102
|
-
* Lyricist meta directive. See https://www.chordpro.org/chordpro/directives-lyricist/
|
|
103
|
-
* @type {string}
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
exports._KEY = _KEY;
|
|
107
|
-
var LYRICIST = 'lyricist';
|
|
108
|
-
/**
|
|
109
|
-
* Start of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
|
|
110
|
-
* @type {string}
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
exports.LYRICIST = LYRICIST;
|
|
114
|
-
var START_OF_CHORUS = 'start_of_chorus';
|
|
115
|
-
/**
|
|
116
|
-
* Start of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
|
|
117
|
-
* @type {string}
|
|
118
|
-
*/
|
|
119
|
-
|
|
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;
|
|
128
|
-
var START_OF_VERSE = 'start_of_verse';
|
|
129
|
-
/**
|
|
130
|
-
* Subtitle meta directive. See https://www.chordpro.org/chordpro/directives-subtitle/
|
|
131
|
-
* @type {string}
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
exports.START_OF_VERSE = START_OF_VERSE;
|
|
135
|
-
var SUBTITLE = 'subtitle';
|
|
136
|
-
/**
|
|
137
|
-
* Tempo meta directive. See https://www.chordpro.org/chordpro/directives-tempo/
|
|
138
|
-
* @type {string}
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
exports.SUBTITLE = SUBTITLE;
|
|
142
|
-
var TEMPO = 'tempo';
|
|
143
|
-
/**
|
|
144
|
-
* Time meta directive. See https://www.chordpro.org/chordpro/directives-time/
|
|
145
|
-
* @type {string}
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
|
-
exports.TEMPO = TEMPO;
|
|
149
|
-
var TIME = 'time';
|
|
150
|
-
/**
|
|
151
|
-
* Title meta directive. See https://www.chordpro.org/chordpro/directives-title/
|
|
152
|
-
* @type {string}
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
exports.TIME = TIME;
|
|
156
|
-
var TITLE = 'title';
|
|
157
|
-
/**
|
|
158
|
-
* Transpose meta directive. See: https://www.chordpro.org/chordpro/directives-transpose/
|
|
159
|
-
* @type {string}
|
|
160
|
-
*/
|
|
161
|
-
|
|
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;
|
|
170
|
-
var YEAR = 'year';
|
|
171
|
-
exports.YEAR = YEAR;
|
|
172
|
-
var TITLE_SHORT = 't';
|
|
173
|
-
var SUBTITLE_SHORT = 'st';
|
|
174
|
-
var COMMENT_SHORT = 'c';
|
|
175
|
-
var START_OF_CHORUS_SHORT = 'soc';
|
|
176
|
-
var END_OF_CHORUS_SHORT = 'eoc';
|
|
177
|
-
var START_OF_TAB_SHORT = 'sot';
|
|
178
|
-
var END_OF_TAB_SHORT = 'eot';
|
|
179
|
-
var RENDERABLE_TAGS = [COMMENT];
|
|
180
|
-
var META_TAGS = [ALBUM, ARTIST, CAPO, COMPOSER, COPYRIGHT, DURATION, KEY, LYRICIST, TEMPO, TIME, TITLE, SUBTITLE, YEAR];
|
|
181
|
-
exports.META_TAGS = META_TAGS;
|
|
182
|
-
var READ_ONLY_TAGS = [_KEY];
|
|
183
|
-
exports.READ_ONLY_TAGS = READ_ONLY_TAGS;
|
|
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);
|
|
185
|
-
var META_TAG_REGEX = /^meta:\s*([^:\s]+)(\s*(.+))?$/;
|
|
186
|
-
var TAG_REGEX = /^([^:\s]+)(:?\s*(.+))?$/;
|
|
187
|
-
var CUSTOM_META_TAG_NAME_REGEX = /^x_(.+)$/;
|
|
188
|
-
|
|
189
|
-
function isReadonlyTag(tagName) {
|
|
190
|
-
return READ_ONLY_TAGS.includes(tagName);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
var translateTagNameAlias = function translateTagNameAlias(name) {
|
|
194
|
-
if (!name) {
|
|
195
|
-
return name;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
var sanitizedName = name.trim();
|
|
199
|
-
|
|
200
|
-
if (sanitizedName in ALIASES) {
|
|
201
|
-
return ALIASES[sanitizedName];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return sanitizedName;
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Represents a tag/directive. See https://www.chordpro.org/chordpro/chordpro-directives/
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var Tag = /*#__PURE__*/function () {
|
|
212
|
-
function Tag(name, value) {
|
|
213
|
-
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
214
|
-
_ref$line = _ref.line,
|
|
215
|
-
line = _ref$line === void 0 ? null : _ref$line,
|
|
216
|
-
_ref$column = _ref.column,
|
|
217
|
-
column = _ref$column === void 0 ? null : _ref$column,
|
|
218
|
-
_ref$offset = _ref.offset,
|
|
219
|
-
offset = _ref$offset === void 0 ? null : _ref$offset;
|
|
220
|
-
|
|
221
|
-
_classCallCheck(this, Tag);
|
|
222
|
-
|
|
223
|
-
this.name = name;
|
|
224
|
-
this.value = value;
|
|
225
|
-
this.line = line;
|
|
226
|
-
this.column = column;
|
|
227
|
-
this.offset = offset;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
_createClass(Tag, [{
|
|
231
|
-
key: "name",
|
|
232
|
-
get:
|
|
233
|
-
/**
|
|
234
|
-
* The tag full name. When the original tag used the short name, `name` will return the full name.
|
|
235
|
-
* @member
|
|
236
|
-
* @type {string}
|
|
237
|
-
*/
|
|
238
|
-
function get() {
|
|
239
|
-
return this._name.trim();
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* The original tag name that was used to construct the tag.
|
|
243
|
-
* @member
|
|
244
|
-
* @type {string}
|
|
245
|
-
*/
|
|
246
|
-
,
|
|
247
|
-
set: function set(name) {
|
|
248
|
-
this._name = translateTagNameAlias(name);
|
|
249
|
-
this._originalName = name;
|
|
250
|
-
}
|
|
251
|
-
}, {
|
|
252
|
-
key: "originalName",
|
|
253
|
-
get: function get() {
|
|
254
|
-
return this._originalName.trim();
|
|
255
|
-
}
|
|
256
|
-
}, {
|
|
257
|
-
key: "value",
|
|
258
|
-
get:
|
|
259
|
-
/**
|
|
260
|
-
* The tag value
|
|
261
|
-
* @member
|
|
262
|
-
* @type {string|null}
|
|
263
|
-
*/
|
|
264
|
-
function get() {
|
|
265
|
-
if (this._value) {
|
|
266
|
-
return this._value.trim();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return this._value || null;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Checks whether the tag value is a non-empty string.
|
|
273
|
-
* @returns {boolean}
|
|
274
|
-
*/
|
|
275
|
-
,
|
|
276
|
-
set: function set(value) {
|
|
277
|
-
this._value = value;
|
|
278
|
-
}
|
|
279
|
-
}, {
|
|
280
|
-
key: "hasValue",
|
|
281
|
-
value: function hasValue() {
|
|
282
|
-
return this.value !== null && this.value.trim().length > 0;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Checks whether the tag is usually rendered inline. It currently only applies to comment tags.
|
|
286
|
-
* @returns {boolean}
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
|
-
}, {
|
|
290
|
-
key: "isRenderable",
|
|
291
|
-
value: function isRenderable() {
|
|
292
|
-
return RENDERABLE_TAGS.indexOf(this.name) !== -1;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Checks whether the tag is either a standard meta tag or a custom meta directive (`{x_some_name}`)
|
|
296
|
-
* @returns {boolean}
|
|
297
|
-
*/
|
|
298
|
-
|
|
299
|
-
}, {
|
|
300
|
-
key: "isMetaTag",
|
|
301
|
-
value: function isMetaTag() {
|
|
302
|
-
return CUSTOM_META_TAG_NAME_REGEX.test(this.name) || META_TAGS.indexOf(this.name) !== -1;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Returns a clone of the tag.
|
|
306
|
-
* @returns {Tag} The cloned tag
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
|
-
}, {
|
|
310
|
-
key: "clone",
|
|
311
|
-
value: function clone() {
|
|
312
|
-
return new Tag(this.name, this.value);
|
|
313
|
-
}
|
|
314
|
-
}, {
|
|
315
|
-
key: "toString",
|
|
316
|
-
value: function toString() {
|
|
317
|
-
return "Tag(name=".concat(this.name, ", value=").concat(this.name, ")");
|
|
318
|
-
}
|
|
319
|
-
}], [{
|
|
320
|
-
key: "parse",
|
|
321
|
-
value: function parse(tag) {
|
|
322
|
-
if (tag instanceof Tag) {
|
|
323
|
-
return tag;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return this.parseWithRegex(tag, META_TAG_REGEX) || this.parseWithRegex(tag, TAG_REGEX);
|
|
327
|
-
}
|
|
328
|
-
}, {
|
|
329
|
-
key: "parseWithRegex",
|
|
330
|
-
value: function parseWithRegex(tag, regex) {
|
|
331
|
-
var matches = tag.match(regex);
|
|
332
|
-
|
|
333
|
-
if (matches !== null) {
|
|
334
|
-
return new Tag(matches[1], matches[3] || null);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
}]);
|
|
340
|
-
|
|
341
|
-
return Tag;
|
|
342
|
-
}();
|
|
343
|
-
|
|
344
|
-
var _default = Tag;
|
|
345
|
-
exports["default"] = _default;
|