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
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
var Literal = /*#__PURE__*/function () {
|
|
15
|
-
function Literal(expression) {
|
|
16
|
-
_classCallCheck(this, Literal);
|
|
17
|
-
|
|
18
|
-
this.string = expression;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_createClass(Literal, [{
|
|
22
|
-
key: "evaluate",
|
|
23
|
-
value: function evaluate() {
|
|
24
|
-
return this.string;
|
|
25
|
-
}
|
|
26
|
-
}, {
|
|
27
|
-
key: "isRenderable",
|
|
28
|
-
value: function isRenderable() {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
key: "clone",
|
|
33
|
-
value: function clone() {
|
|
34
|
-
return new Literal(this.string);
|
|
35
|
-
}
|
|
36
|
-
}]);
|
|
37
|
-
|
|
38
|
-
return Literal;
|
|
39
|
-
}();
|
|
40
|
-
|
|
41
|
-
var _default = Literal;
|
|
42
|
-
exports["default"] = _default;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _evaluation_error = _interopRequireDefault(require("./evaluation_error"));
|
|
9
|
-
|
|
10
|
-
var _utilities = require("../../utilities");
|
|
11
|
-
|
|
12
|
-
var _composite = _interopRequireDefault(require("./composite"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
|
|
16
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
-
|
|
18
|
-
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
|
-
|
|
20
|
-
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
|
-
|
|
22
|
-
var Ternary = /*#__PURE__*/function () {
|
|
23
|
-
function Ternary() {
|
|
24
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
25
|
-
_ref$variable = _ref.variable,
|
|
26
|
-
variable = _ref$variable === void 0 ? null : _ref$variable,
|
|
27
|
-
_ref$valueTest = _ref.valueTest,
|
|
28
|
-
valueTest = _ref$valueTest === void 0 ? null : _ref$valueTest,
|
|
29
|
-
_ref$trueExpression = _ref.trueExpression,
|
|
30
|
-
trueExpression = _ref$trueExpression === void 0 ? null : _ref$trueExpression,
|
|
31
|
-
_ref$falseExpression = _ref.falseExpression,
|
|
32
|
-
falseExpression = _ref$falseExpression === void 0 ? null : _ref$falseExpression,
|
|
33
|
-
_ref$line = _ref.line,
|
|
34
|
-
line = _ref$line === void 0 ? null : _ref$line,
|
|
35
|
-
_ref$column = _ref.column,
|
|
36
|
-
column = _ref$column === void 0 ? null : _ref$column,
|
|
37
|
-
_ref$offset = _ref.offset,
|
|
38
|
-
offset = _ref$offset === void 0 ? null : _ref$offset;
|
|
39
|
-
|
|
40
|
-
_classCallCheck(this, Ternary);
|
|
41
|
-
|
|
42
|
-
this.variable = (0, _utilities.presence)(variable);
|
|
43
|
-
this.valueTest = valueTest;
|
|
44
|
-
this.trueExpression = trueExpression;
|
|
45
|
-
this.falseExpression = falseExpression;
|
|
46
|
-
this.line = line;
|
|
47
|
-
this.column = column;
|
|
48
|
-
this.offset = offset;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Evaluate the meta expression
|
|
52
|
-
* @param {Metadata} metadata The metadata object to use for evaluating the expression
|
|
53
|
-
* @returns {string} The evaluated expression
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
_createClass(Ternary, [{
|
|
58
|
-
key: "evaluate",
|
|
59
|
-
value: function evaluate(metadata) {
|
|
60
|
-
var upperContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
61
|
-
|
|
62
|
-
if (this.variable) {
|
|
63
|
-
return this.evaluateWithVariable(metadata);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!upperContext) {
|
|
67
|
-
throw new _evaluation_error["default"]('Unexpected empty expression', this.line, this.column, this.offset);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return metadata.get(upperContext);
|
|
71
|
-
}
|
|
72
|
-
}, {
|
|
73
|
-
key: "evaluateWithVariable",
|
|
74
|
-
value: function evaluateWithVariable(metadata) {
|
|
75
|
-
var value = metadata.get(this.variable);
|
|
76
|
-
|
|
77
|
-
if ((0, _utilities.isPresent)(value) && (!this.valueTest || value === this.valueTest)) {
|
|
78
|
-
return this.evaluateForTruthyValue(metadata, value);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (this.falseExpression) {
|
|
82
|
-
return new _composite["default"](this.falseExpression, this.variable).evaluate(metadata);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return '';
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "evaluateForTruthyValue",
|
|
89
|
-
value: function evaluateForTruthyValue(metadata, value) {
|
|
90
|
-
if (this.trueExpression) {
|
|
91
|
-
return new _composite["default"](this.trueExpression, this.variable).evaluate(metadata);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "isRenderable",
|
|
98
|
-
value: function isRenderable() {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
key: "clone",
|
|
103
|
-
value: function clone() {
|
|
104
|
-
var _this$trueExpression, _this$falseExpression;
|
|
105
|
-
|
|
106
|
-
return new Ternary({
|
|
107
|
-
variable: this.variable,
|
|
108
|
-
valueTest: this.valueTest,
|
|
109
|
-
trueExpression: (_this$trueExpression = this.trueExpression) === null || _this$trueExpression === void 0 ? void 0 : _this$trueExpression.map(function (part) {
|
|
110
|
-
return part.clone();
|
|
111
|
-
}),
|
|
112
|
-
falseExpression: (_this$falseExpression = this.falseExpression) === null || _this$falseExpression === void 0 ? void 0 : _this$falseExpression.map(function (part) {
|
|
113
|
-
return part.clone();
|
|
114
|
-
}),
|
|
115
|
-
line: this.line,
|
|
116
|
-
column: this.column,
|
|
117
|
-
offset: this.offset
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}]);
|
|
121
|
-
|
|
122
|
-
return Ternary;
|
|
123
|
-
}();
|
|
124
|
-
|
|
125
|
-
var _default = Ternary;
|
|
126
|
-
exports["default"] = _default;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Represents a comment. See https://www.chordpro.org/chordpro/chordpro-file-format-specification/#overview
|
|
16
|
-
*/
|
|
17
|
-
var Comment = /*#__PURE__*/function () {
|
|
18
|
-
function Comment(content) {
|
|
19
|
-
_classCallCheck(this, Comment);
|
|
20
|
-
|
|
21
|
-
this.content = content;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Indicates whether a Comment should be visible in a formatted chord sheet (except for ChordPro sheets)
|
|
25
|
-
* @returns {boolean}
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_createClass(Comment, [{
|
|
30
|
-
key: "isRenderable",
|
|
31
|
-
value: function isRenderable() {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns a deep copy of the Comment, useful when programmatically transforming a song
|
|
36
|
-
* @returns {Comment}
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
}, {
|
|
40
|
-
key: "clone",
|
|
41
|
-
value: function clone() {
|
|
42
|
-
return new Comment(this.content);
|
|
43
|
-
}
|
|
44
|
-
}, {
|
|
45
|
-
key: "toString",
|
|
46
|
-
value: function toString() {
|
|
47
|
-
return "Comment(content=".concat(this.content, ")");
|
|
48
|
-
}
|
|
49
|
-
}]);
|
|
50
|
-
|
|
51
|
-
return Comment;
|
|
52
|
-
}();
|
|
53
|
-
|
|
54
|
-
var _default = Comment;
|
|
55
|
-
exports["default"] = _default;
|
package/lib/chord_sheet/line.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _chord_lyrics_pair = _interopRequireDefault(require("./chord_lyrics_pair"));
|
|
9
|
-
|
|
10
|
-
var _tag = _interopRequireDefault(require("./tag"));
|
|
11
|
-
|
|
12
|
-
var _comment = _interopRequireDefault(require("./comment"));
|
|
13
|
-
|
|
14
|
-
var _constants = require("../constants");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
|
|
18
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Represents a line in a chord sheet, consisting of items of type ChordLyricsPair or Tag
|
|
26
|
-
*/
|
|
27
|
-
var Line = /*#__PURE__*/function () {
|
|
28
|
-
function Line() {
|
|
29
|
-
_classCallCheck(this, Line);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The items ({@link ChordLyricsPair} or {@link Tag} or {@link Comment}) of which the line consists
|
|
33
|
-
* @member
|
|
34
|
-
* @type {Array.<(ChordLyricsPair|Tag|Comment)>}
|
|
35
|
-
*/
|
|
36
|
-
this.items = [];
|
|
37
|
-
/**
|
|
38
|
-
* The line type, This is set by the ChordProParser when it read tags like {start_of_chorus} or {start_of_verse}
|
|
39
|
-
* Values can be {@link VERSE}, {@link CHORUS} or {@link NONE}
|
|
40
|
-
* @member
|
|
41
|
-
* @type {string}
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
this.type = _constants.NONE;
|
|
45
|
-
this.currentChordLyricsPair = null;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Indicates whether the line contains any items
|
|
49
|
-
* @returns {boolean}
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
_createClass(Line, [{
|
|
54
|
-
key: "isEmpty",
|
|
55
|
-
value: function isEmpty() {
|
|
56
|
-
return this.items.length === 0;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Adds an item ({@link ChordLyricsPair} or {@link Tag}) to the line
|
|
60
|
-
* @param {ChordLyricsPair|Tag} item The item to be added
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
}, {
|
|
64
|
-
key: "addItem",
|
|
65
|
-
value: function addItem(item) {
|
|
66
|
-
if (item instanceof _tag["default"]) {
|
|
67
|
-
this.addTag(item);
|
|
68
|
-
} else if (item instanceof _chord_lyrics_pair["default"]) {
|
|
69
|
-
this.addChordLyricsPair(item);
|
|
70
|
-
} else if (item instanceof _comment["default"]) {
|
|
71
|
-
this.addComment(item);
|
|
72
|
-
} else {
|
|
73
|
-
this.items.push(item);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Indicates whether the line contains items that are renderable
|
|
78
|
-
* @returns {boolean}
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
}, {
|
|
82
|
-
key: "hasRenderableItems",
|
|
83
|
-
value: function hasRenderableItems() {
|
|
84
|
-
return this.items.some(function (item) {
|
|
85
|
-
return item.isRenderable();
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Returns a deep copy of the line and all of its items
|
|
90
|
-
* @returns {Line}
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
}, {
|
|
94
|
-
key: "clone",
|
|
95
|
-
value: function clone() {
|
|
96
|
-
var clonedLine = new Line();
|
|
97
|
-
clonedLine.items = this.items.map(function (item) {
|
|
98
|
-
return item.clone();
|
|
99
|
-
});
|
|
100
|
-
clonedLine.type = this.type;
|
|
101
|
-
return clonedLine;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Indicates whether the line type is {@link VERSE}
|
|
105
|
-
* @returns {boolean}
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
}, {
|
|
109
|
-
key: "isVerse",
|
|
110
|
-
value: function isVerse() {
|
|
111
|
-
return this.type === _constants.VERSE;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Indicates whether the line type is {@link CHORUS}
|
|
115
|
-
* @returns {boolean}
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
}, {
|
|
119
|
-
key: "isChorus",
|
|
120
|
-
value: function isChorus() {
|
|
121
|
-
return this.type === _constants.CHORUS;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Indicates whether the line contains items that are renderable. Please use {@link hasRenderableItems}
|
|
125
|
-
* @deprecated
|
|
126
|
-
* @returns {boolean}
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
}, {
|
|
130
|
-
key: "hasContent",
|
|
131
|
-
value: function hasContent() {
|
|
132
|
-
return this.hasRenderableItems();
|
|
133
|
-
}
|
|
134
|
-
}, {
|
|
135
|
-
key: "addChordLyricsPair",
|
|
136
|
-
value: function addChordLyricsPair(chords, lyrics) {
|
|
137
|
-
if (chords instanceof _chord_lyrics_pair["default"]) {
|
|
138
|
-
this.currentChordLyricsPair = chords;
|
|
139
|
-
} else {
|
|
140
|
-
this.currentChordLyricsPair = new _chord_lyrics_pair["default"](chords, lyrics);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.items.push(this.currentChordLyricsPair);
|
|
144
|
-
return this.currentChordLyricsPair;
|
|
145
|
-
}
|
|
146
|
-
}, {
|
|
147
|
-
key: "ensureChordLyricsPair",
|
|
148
|
-
value: function ensureChordLyricsPair() {
|
|
149
|
-
if (!this.currentChordLyricsPair) {
|
|
150
|
-
this.addChordLyricsPair();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: "chords",
|
|
155
|
-
value: function chords(chr) {
|
|
156
|
-
this.ensureChordLyricsPair();
|
|
157
|
-
this.currentChordLyricsPair.chords += chr;
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "lyrics",
|
|
161
|
-
value: function lyrics(chr) {
|
|
162
|
-
this.ensureChordLyricsPair();
|
|
163
|
-
this.currentChordLyricsPair.lyrics += chr;
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
key: "addTag",
|
|
167
|
-
value: function addTag(name, value) {
|
|
168
|
-
var tag = name instanceof _tag["default"] ? name : new _tag["default"](name, value);
|
|
169
|
-
this.items.push(tag);
|
|
170
|
-
return tag;
|
|
171
|
-
}
|
|
172
|
-
}, {
|
|
173
|
-
key: "addComment",
|
|
174
|
-
value: function addComment(content) {
|
|
175
|
-
var comment = content instanceof _comment["default"] ? content : new _comment["default"](content);
|
|
176
|
-
this.items.push(comment);
|
|
177
|
-
return comment;
|
|
178
|
-
}
|
|
179
|
-
}]);
|
|
180
|
-
|
|
181
|
-
return Line;
|
|
182
|
-
}();
|
|
183
|
-
|
|
184
|
-
var _default = Line;
|
|
185
|
-
exports["default"] = _default;
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _tag = require("./tag");
|
|
9
|
-
|
|
10
|
-
var _chord = _interopRequireDefault(require("../chord"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
-
|
|
16
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
-
|
|
18
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
20
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
-
|
|
24
|
-
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."); }
|
|
25
|
-
|
|
26
|
-
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); }
|
|
27
|
-
|
|
28
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
29
|
-
|
|
30
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
31
|
-
|
|
32
|
-
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; }
|
|
33
|
-
|
|
34
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
35
|
-
|
|
36
|
-
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); } }
|
|
37
|
-
|
|
38
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
39
|
-
|
|
40
|
-
function appendValue(array, key, value) {
|
|
41
|
-
if (!array.includes(value)) {
|
|
42
|
-
array.push(value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Stores song metadata. Properties can be accessed using the get() method:
|
|
47
|
-
*
|
|
48
|
-
* const metadata = new Metadata({ author: 'John' });
|
|
49
|
-
* metadata.get('author') // => 'John'
|
|
50
|
-
*
|
|
51
|
-
* See {@link Metadata#get}
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var Metadata = /*#__PURE__*/function () {
|
|
56
|
-
function Metadata() {
|
|
57
|
-
var _this = this;
|
|
58
|
-
|
|
59
|
-
var metadata = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
60
|
-
|
|
61
|
-
_classCallCheck(this, Metadata);
|
|
62
|
-
|
|
63
|
-
Object.keys(metadata).filter(function (key) {
|
|
64
|
-
return !(0, _tag.isReadonlyTag)(key);
|
|
65
|
-
}).forEach(function (key) {
|
|
66
|
-
var value = metadata[key];
|
|
67
|
-
|
|
68
|
-
if (value instanceof Array) {
|
|
69
|
-
_this[key] = _toConsumableArray(value);
|
|
70
|
-
} else {
|
|
71
|
-
_this[key] = value;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_createClass(Metadata, [{
|
|
77
|
-
key: "add",
|
|
78
|
-
value: function add(key, value) {
|
|
79
|
-
if ((0, _tag.isReadonlyTag)(key)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!(key in this)) {
|
|
84
|
-
this[key] = value;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var currentValue = this[key];
|
|
89
|
-
|
|
90
|
-
if (currentValue === value) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (currentValue instanceof Array) {
|
|
95
|
-
appendValue(currentValue, key, value);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this[key] = [currentValue, value];
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Reads a metadata value by key. This method supports simple value lookup, as fetching single array values.
|
|
103
|
-
*
|
|
104
|
-
* This method deprecates direct property access, eg: metadata['author']
|
|
105
|
-
*
|
|
106
|
-
* Examples:
|
|
107
|
-
*
|
|
108
|
-
* const metadata = new Metadata({ lyricist: 'Pete', author: ['John', 'Mary'] });
|
|
109
|
-
* metadata.get('lyricist') // => 'Pete'
|
|
110
|
-
* metadata.get('author') // => ['John', 'Mary']
|
|
111
|
-
* metadata.get('author.1') // => 'John'
|
|
112
|
-
* metadata.get('author.2') // => 'Mary'
|
|
113
|
-
*
|
|
114
|
-
* Using a negative index will start counting at the end of the list:
|
|
115
|
-
*
|
|
116
|
-
* const metadata = new Metadata({ lyricist: 'Pete', author: ['John', 'Mary'] });
|
|
117
|
-
* metadata.get('author.-1') // => 'Mary'
|
|
118
|
-
* metadata.get('author.-2') // => 'John'
|
|
119
|
-
*
|
|
120
|
-
* @param prop the property name
|
|
121
|
-
* @returns {Array<String>|String} the metadata value(s). If there is only one value, it will return a String,
|
|
122
|
-
* else it returns an array of strings.
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
key: "get",
|
|
127
|
-
value: function get(prop) {
|
|
128
|
-
if (prop === _tag._KEY) {
|
|
129
|
-
return this.calculateKeyFromCapo();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (prop in this) {
|
|
133
|
-
return this[prop];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return this.getArrayItem(prop);
|
|
137
|
-
}
|
|
138
|
-
}, {
|
|
139
|
-
key: "parseArrayKey",
|
|
140
|
-
value: function parseArrayKey(prop) {
|
|
141
|
-
var match = prop.match(/(.+)\.(-?\d+)$/);
|
|
142
|
-
|
|
143
|
-
if (!match) {
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
var key = match[1];
|
|
148
|
-
var index = parseInt(match[2], 10);
|
|
149
|
-
return [key, index];
|
|
150
|
-
}
|
|
151
|
-
}, {
|
|
152
|
-
key: "getArrayItem",
|
|
153
|
-
value: function getArrayItem(prop) {
|
|
154
|
-
var _this$parseArrayKey = this.parseArrayKey(prop),
|
|
155
|
-
_this$parseArrayKey2 = _slicedToArray(_this$parseArrayKey, 2),
|
|
156
|
-
key = _this$parseArrayKey2[0],
|
|
157
|
-
index = _this$parseArrayKey2[1];
|
|
158
|
-
|
|
159
|
-
if (!(key && index)) {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var arrayValue = this[key] || [];
|
|
164
|
-
var itemIndex = index;
|
|
165
|
-
|
|
166
|
-
if (itemIndex < 0) {
|
|
167
|
-
itemIndex = arrayValue.length + itemIndex;
|
|
168
|
-
} else if (itemIndex > 0) {
|
|
169
|
-
itemIndex -= 1;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return arrayValue[itemIndex];
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns a deep clone of this Metadata object
|
|
176
|
-
* @returns {Metadata} the cloned Metadata object
|
|
177
|
-
*/
|
|
178
|
-
|
|
179
|
-
}, {
|
|
180
|
-
key: "clone",
|
|
181
|
-
value: function clone() {
|
|
182
|
-
return new Metadata(this);
|
|
183
|
-
}
|
|
184
|
-
}, {
|
|
185
|
-
key: "calculateKeyFromCapo",
|
|
186
|
-
value: function calculateKeyFromCapo() {
|
|
187
|
-
var capo = this.get(_tag.CAPO);
|
|
188
|
-
var key = this.get(_tag.KEY);
|
|
189
|
-
|
|
190
|
-
if (capo && key) {
|
|
191
|
-
return _chord["default"].parse(key).transpose(parseInt(capo, 10)).toString();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return undefined;
|
|
195
|
-
}
|
|
196
|
-
}]);
|
|
197
|
-
|
|
198
|
-
return Metadata;
|
|
199
|
-
}();
|
|
200
|
-
|
|
201
|
-
var _default = Metadata;
|
|
202
|
-
exports["default"] = _default;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _constants = require("../constants");
|
|
9
|
-
|
|
10
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
-
|
|
12
|
-
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."); }
|
|
13
|
-
|
|
14
|
-
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); }
|
|
15
|
-
|
|
16
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
17
|
-
|
|
18
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Represents a paragraph of lines in a chord sheet
|
|
30
|
-
*/
|
|
31
|
-
var Paragraph = /*#__PURE__*/function () {
|
|
32
|
-
function Paragraph() {
|
|
33
|
-
_classCallCheck(this, Paragraph);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The {@link Line} items of which the paragraph consists
|
|
37
|
-
* @member
|
|
38
|
-
* @type {Array<Line>}
|
|
39
|
-
*/
|
|
40
|
-
this.lines = [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_createClass(Paragraph, [{
|
|
44
|
-
key: "addLine",
|
|
45
|
-
value: function addLine(line) {
|
|
46
|
-
this.lines.push(line);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Tries to determine the common type for all lines. If the types for all lines are equal, it returns that type.
|
|
50
|
-
* If not, it returns {@link INDETERMINATE}
|
|
51
|
-
* @returns {string}
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
}, {
|
|
55
|
-
key: "type",
|
|
56
|
-
get: function get() {
|
|
57
|
-
var types = this.lines.map(function (line) {
|
|
58
|
-
return line.type;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
var uniqueTypes = _toConsumableArray(new Set(types));
|
|
62
|
-
|
|
63
|
-
if (uniqueTypes.length === 1) {
|
|
64
|
-
return uniqueTypes[0];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return _constants.INDETERMINATE;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Indicates whether the paragraph contains lines with renderable items.
|
|
71
|
-
* @see {@link Line.hasRenderableItems}
|
|
72
|
-
* @returns {boolean}
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
}, {
|
|
76
|
-
key: "hasRenderableItems",
|
|
77
|
-
value: function hasRenderableItems() {
|
|
78
|
-
return this.lines.some(function (line) {
|
|
79
|
-
return line.hasRenderableItems();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}]);
|
|
83
|
-
|
|
84
|
-
return Paragraph;
|
|
85
|
-
}();
|
|
86
|
-
|
|
87
|
-
var _default = Paragraph;
|
|
88
|
-
exports["default"] = _default;
|