chordsheetjs 6.3.0 → 7.0.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 +41 -6
- package/lib/bundle.js +51 -15
- package/lib/index.html +40 -0
- package/lib/index.js +51 -15
- package/lib/index.js.map +1 -1
- package/lib/main.d.ts +24 -4
- package/lib/main.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -636,8 +636,10 @@ If not, it returns [INDETERMINATE](#INDETERMINATE)</p>
|
|
|
636
636
|
* [.paragraphs](#Song+paragraphs) : [<code>Array.<Paragraph></code>](#Paragraph)
|
|
637
637
|
* ~~[.metaData](#Song+metaData) ⇒~~
|
|
638
638
|
* [.clone()](#Song+clone) ⇒ [<code>Song</code>](#Song)
|
|
639
|
-
* [.setCapo(capo)](#Song+setCapo) ⇒ [<code>Song</code>](#Song)
|
|
640
639
|
* [.setKey(key)](#Song+setKey) ⇒ [<code>Song</code>](#Song)
|
|
640
|
+
* [.setCapo(capo)](#Song+setCapo) ⇒ [<code>Song</code>](#Song)
|
|
641
|
+
* [.changeKey(newKey)](#Song+changeKey) ⇒ [<code>Song</code>](#Song)
|
|
642
|
+
* [.changeMetadata(name, value)](#Song+changeMetadata)
|
|
641
643
|
* [.mapItems(func)](#Song+mapItems) ⇒ [<code>Song</code>](#Song)
|
|
642
644
|
* [.mapLines(func)](#Song+mapLines) ⇒ [<code>Song</code>](#Song)
|
|
643
645
|
|
|
@@ -689,13 +691,29 @@ if you want to skip the "header lines": the lines that only contain me
|
|
|
689
691
|
|
|
690
692
|
**Kind**: instance method of [<code>Song</code>](#Song)
|
|
691
693
|
**Returns**: [<code>Song</code>](#Song) - <p>The cloned song</p>
|
|
694
|
+
<a name="Song+setKey"></a>
|
|
695
|
+
|
|
696
|
+
### song.setKey(key) ⇒ [<code>Song</code>](#Song)
|
|
697
|
+
<p>Returns a copy of the song with the key value set to the specified key. It changes:</p>
|
|
698
|
+
<ul>
|
|
699
|
+
<li>the value for <code>key</code> in the <code>metadata</code> set</li>
|
|
700
|
+
<li>any existing <code>key</code> directive</li>
|
|
701
|
+
</ul>
|
|
702
|
+
|
|
703
|
+
**Kind**: instance method of [<code>Song</code>](#Song)
|
|
704
|
+
**Returns**: [<code>Song</code>](#Song) - <p>The changed song</p>
|
|
705
|
+
|
|
706
|
+
| Param | Type | Description |
|
|
707
|
+
| --- | --- | --- |
|
|
708
|
+
| key | <code>number</code> \| <code>null</code> | <p>the key. Passing <code>null</code> will:</p> <ul> <li>remove the current key from <code>metadata</code></li> <li>remove any <code>key</code> directive</li> </ul> |
|
|
709
|
+
|
|
692
710
|
<a name="Song+setCapo"></a>
|
|
693
711
|
|
|
694
712
|
### song.setCapo(capo) ⇒ [<code>Song</code>](#Song)
|
|
695
|
-
<p>Returns a copy of the song with the
|
|
713
|
+
<p>Returns a copy of the song with the key value set to the specified capo. It changes:</p>
|
|
696
714
|
<ul>
|
|
697
715
|
<li>the value for <code>capo</code> in the <code>metadata</code> set</li>
|
|
698
|
-
<li>any existing <code>capo</code> directive
|
|
716
|
+
<li>any existing <code>capo</code> directive</li>
|
|
699
717
|
</ul>
|
|
700
718
|
|
|
701
719
|
**Kind**: instance method of [<code>Song</code>](#Song)
|
|
@@ -705,9 +723,9 @@ if you want to skip the "header lines": the lines that only contain me
|
|
|
705
723
|
| --- | --- | --- |
|
|
706
724
|
| capo | <code>number</code> \| <code>null</code> | <p>the capo. Passing <code>null</code> will:</p> <ul> <li>remove the current key from <code>metadata</code></li> <li>remove any <code>capo</code> directive</li> </ul> |
|
|
707
725
|
|
|
708
|
-
<a name="Song+
|
|
726
|
+
<a name="Song+changeKey"></a>
|
|
709
727
|
|
|
710
|
-
### song.
|
|
728
|
+
### song.changeKey(newKey) ⇒ [<code>Song</code>](#Song)
|
|
711
729
|
<p>Returns a copy of the song with the key set to the specified key. It changes:</p>
|
|
712
730
|
<ul>
|
|
713
731
|
<li>the value for <code>key</code> in the <code>metadata</code> set</li>
|
|
@@ -720,7 +738,24 @@ if you want to skip the "header lines": the lines that only contain me
|
|
|
720
738
|
|
|
721
739
|
| Param | Type | Description |
|
|
722
740
|
| --- | --- | --- |
|
|
723
|
-
|
|
|
741
|
+
| newKey | <code>string</code> | <p>The new key.</p> |
|
|
742
|
+
|
|
743
|
+
<a name="Song+changeMetadata"></a>
|
|
744
|
+
|
|
745
|
+
### song.changeMetadata(name, value)
|
|
746
|
+
<p>Returns a copy of the song with the directive value set to the specified value.</p>
|
|
747
|
+
<ul>
|
|
748
|
+
<li>when there is a matching directive in the song, it will update the directive</li>
|
|
749
|
+
<li>when there is no matching directive, it will be inserted
|
|
750
|
+
If <code>value</code> is <code>null</code> it will act as a delete, any directive matching <code>name</code> will be removed.</li>
|
|
751
|
+
</ul>
|
|
752
|
+
|
|
753
|
+
**Kind**: instance method of [<code>Song</code>](#Song)
|
|
754
|
+
|
|
755
|
+
| Param | Type | Description |
|
|
756
|
+
| --- | --- | --- |
|
|
757
|
+
| name | <code>string</code> | <p>The directive name</p> |
|
|
758
|
+
| value | <code>string</code> \| <code>null</code> | <p>The value to set, or <code>null</code> to remove the directive</p> |
|
|
724
759
|
|
|
725
760
|
<a name="Song+mapItems"></a>
|
|
726
761
|
|
package/lib/bundle.js
CHANGED
|
@@ -1994,6 +1994,7 @@ function $21a34a464e7bc609$export$78d1711480f95c3e(string) {
|
|
|
1994
1994
|
return string === null || string === undefined || string === '';
|
|
1995
1995
|
}
|
|
1996
1996
|
function $21a34a464e7bc609$export$595e981f61839426(string, constructor, regexes) {
|
|
1997
|
+
if ($21a34a464e7bc609$export$78d1711480f95c3e(string)) return null;
|
|
1997
1998
|
for(let i = 0, count = regexes.length; i < count; i += 1){
|
|
1998
1999
|
const match = string.match(regexes[i]);
|
|
1999
2000
|
if (match) return new constructor(match.groups);
|
|
@@ -4129,43 +4130,78 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
|
|
|
4129
4130
|
return this.metadata[name] || null;
|
|
4130
4131
|
}
|
|
4131
4132
|
/**
|
|
4132
|
-
* Returns a copy of the song with the
|
|
4133
|
+
* Returns a copy of the song with the key value set to the specified key. It changes:
|
|
4134
|
+
* - the value for `key` in the `metadata` set
|
|
4135
|
+
* - any existing `key` directive
|
|
4136
|
+
* @param {number|null} key the key. Passing `null` will:
|
|
4137
|
+
* - remove the current key from `metadata`
|
|
4138
|
+
* - remove any `key` directive
|
|
4139
|
+
* @returns {Song} The changed song
|
|
4140
|
+
*/ setKey(key) {
|
|
4141
|
+
return this.changeMetadata($5e9ede69210ec54a$export$7167c830cefcb6b5, key);
|
|
4142
|
+
}
|
|
4143
|
+
/**
|
|
4144
|
+
* Returns a copy of the song with the key value set to the specified capo. It changes:
|
|
4133
4145
|
* - the value for `capo` in the `metadata` set
|
|
4134
|
-
* - any existing `capo` directive
|
|
4146
|
+
* - any existing `capo` directive
|
|
4135
4147
|
* @param {number|null} capo the capo. Passing `null` will:
|
|
4136
4148
|
* - remove the current key from `metadata`
|
|
4137
4149
|
* - remove any `capo` directive
|
|
4138
4150
|
* @returns {Song} The changed song
|
|
4139
4151
|
*/ setCapo(capo) {
|
|
4140
|
-
|
|
4141
|
-
|
|
4152
|
+
return this.changeMetadata($5e9ede69210ec54a$export$866f445d49bad88e, capo);
|
|
4153
|
+
}
|
|
4154
|
+
setDirective(name, value) {
|
|
4155
|
+
if (value === null) return this.removeItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === name
|
|
4142
4156
|
);
|
|
4143
|
-
|
|
4157
|
+
return this.updateItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === name
|
|
4144
4158
|
, (item)=>item.set({
|
|
4145
|
-
value:
|
|
4159
|
+
value: value
|
|
4146
4160
|
})
|
|
4147
|
-
, (song)=>song.insertDirective(
|
|
4161
|
+
, (song)=>song.insertDirective(name, value)
|
|
4148
4162
|
);
|
|
4149
|
-
updatedSong.metadata.set('capo', capo);
|
|
4150
|
-
return updatedSong;
|
|
4151
4163
|
}
|
|
4152
4164
|
/**
|
|
4153
4165
|
* Returns a copy of the song with the key set to the specified key. It changes:
|
|
4154
4166
|
* - the value for `key` in the `metadata` set
|
|
4155
4167
|
* - any existing `key` directive
|
|
4156
4168
|
* - all chords, those are transposed according to the distance between the current and the new key
|
|
4157
|
-
* @param {string}
|
|
4169
|
+
* @param {string} newKey The new key.
|
|
4158
4170
|
* @returns {Song} The changed song
|
|
4159
|
-
*/
|
|
4160
|
-
const transpose =
|
|
4171
|
+
*/ changeKey(newKey) {
|
|
4172
|
+
const transpose = this.getTransposeDistance(newKey);
|
|
4161
4173
|
const updatedSong = this.mapItems((item)=>{
|
|
4162
4174
|
if (item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === $5e9ede69210ec54a$export$7167c830cefcb6b5) return item.set({
|
|
4163
|
-
value:
|
|
4175
|
+
value: newKey
|
|
4164
4176
|
});
|
|
4165
|
-
if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose,
|
|
4177
|
+
if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose, newKey);
|
|
4166
4178
|
return item;
|
|
4167
4179
|
});
|
|
4168
|
-
updatedSong.metadata.set('key',
|
|
4180
|
+
updatedSong.metadata.set('key', newKey);
|
|
4181
|
+
return updatedSong;
|
|
4182
|
+
}
|
|
4183
|
+
getTransposeDistance(newKey) {
|
|
4184
|
+
const wrappedKey = $bff5407e03fdc8ee$export$2e2bcd8739ae039.wrap(this.key);
|
|
4185
|
+
if (!wrappedKey) throw new Error(`
|
|
4186
|
+
Cannot change song key, the original key is unknown.
|
|
4187
|
+
|
|
4188
|
+
Either ensure a key directive is present in the song (when using chordpro):
|
|
4189
|
+
\`{key: C}\`
|
|
4190
|
+
|
|
4191
|
+
Or set the song key before changing key:
|
|
4192
|
+
\`song.setKey('C');\``.substring(1));
|
|
4193
|
+
return wrappedKey.distanceTo(newKey);
|
|
4194
|
+
}
|
|
4195
|
+
/**
|
|
4196
|
+
* Returns a copy of the song with the directive value set to the specified value.
|
|
4197
|
+
* - when there is a matching directive in the song, it will update the directive
|
|
4198
|
+
* - when there is no matching directive, it will be inserted
|
|
4199
|
+
* If `value` is `null` it will act as a delete, any directive matching `name` will be removed.
|
|
4200
|
+
* @param {string} name The directive name
|
|
4201
|
+
* @param {string | null} value The value to set, or `null` to remove the directive
|
|
4202
|
+
*/ changeMetadata(name, value) {
|
|
4203
|
+
const updatedSong = this.setDirective(name, value);
|
|
4204
|
+
updatedSong.metadata.set(name, value);
|
|
4169
4205
|
return updatedSong;
|
|
4170
4206
|
}
|
|
4171
4207
|
insertDirective(name, value, { after: after = null } = {}) {
|
package/lib/index.html
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<script src="bundle.js"></script>
|
|
4
|
+
</head>
|
|
5
|
+
<body>
|
|
6
|
+
<script type="text/plain" id="chordSheet">
|
|
7
|
+
{title: Let it be}
|
|
8
|
+
{subtitle: ChordSheetJS example version}
|
|
9
|
+
{composer: John Lennon}
|
|
10
|
+
{composer: Paul McCartney}
|
|
11
|
+
{Chorus}
|
|
12
|
+
|
|
13
|
+
Written by: %{composer}
|
|
14
|
+
|
|
15
|
+
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be
|
|
16
|
+
[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm] [C]
|
|
17
|
+
</script>
|
|
18
|
+
<style>
|
|
19
|
+
body {
|
|
20
|
+
font-family: sans-serif;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
<script>
|
|
24
|
+
const {
|
|
25
|
+
ChordProParser,
|
|
26
|
+
HtmlDivFormatter,
|
|
27
|
+
} = ChordSheetJS;
|
|
28
|
+
|
|
29
|
+
const parser = new ChordProParser();
|
|
30
|
+
const chordpro = document.getElementById("chordSheet").innerText;
|
|
31
|
+
const song = parser.parse(chordpro);
|
|
32
|
+
const formatter = new HtmlDivFormatter();
|
|
33
|
+
const disp = formatter.format(song);
|
|
34
|
+
const css = HtmlDivFormatter.cssString('.chordSheetViewer');
|
|
35
|
+
|
|
36
|
+
document.write(`<style>${css}</style>`);
|
|
37
|
+
document.write(`<div class="chordSheetViewer">${disp}</div>`);
|
|
38
|
+
</script>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
package/lib/index.js
CHANGED
|
@@ -1993,6 +1993,7 @@ function $21a34a464e7bc609$export$78d1711480f95c3e(string) {
|
|
|
1993
1993
|
return string === null || string === undefined || string === '';
|
|
1994
1994
|
}
|
|
1995
1995
|
function $21a34a464e7bc609$export$595e981f61839426(string, constructor, regexes) {
|
|
1996
|
+
if ($21a34a464e7bc609$export$78d1711480f95c3e(string)) return null;
|
|
1996
1997
|
for(let i = 0, count = regexes.length; i < count; i += 1){
|
|
1997
1998
|
const match = string.match(regexes[i]);
|
|
1998
1999
|
if (match) return new constructor(match.groups);
|
|
@@ -4128,43 +4129,78 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
|
|
|
4128
4129
|
return this.metadata[name] || null;
|
|
4129
4130
|
}
|
|
4130
4131
|
/**
|
|
4131
|
-
* Returns a copy of the song with the
|
|
4132
|
+
* Returns a copy of the song with the key value set to the specified key. It changes:
|
|
4133
|
+
* - the value for `key` in the `metadata` set
|
|
4134
|
+
* - any existing `key` directive
|
|
4135
|
+
* @param {number|null} key the key. Passing `null` will:
|
|
4136
|
+
* - remove the current key from `metadata`
|
|
4137
|
+
* - remove any `key` directive
|
|
4138
|
+
* @returns {Song} The changed song
|
|
4139
|
+
*/ setKey(key) {
|
|
4140
|
+
return this.changeMetadata($5e9ede69210ec54a$export$7167c830cefcb6b5, key);
|
|
4141
|
+
}
|
|
4142
|
+
/**
|
|
4143
|
+
* Returns a copy of the song with the key value set to the specified capo. It changes:
|
|
4132
4144
|
* - the value for `capo` in the `metadata` set
|
|
4133
|
-
* - any existing `capo` directive
|
|
4145
|
+
* - any existing `capo` directive
|
|
4134
4146
|
* @param {number|null} capo the capo. Passing `null` will:
|
|
4135
4147
|
* - remove the current key from `metadata`
|
|
4136
4148
|
* - remove any `capo` directive
|
|
4137
4149
|
* @returns {Song} The changed song
|
|
4138
4150
|
*/ setCapo(capo) {
|
|
4139
|
-
|
|
4140
|
-
|
|
4151
|
+
return this.changeMetadata($5e9ede69210ec54a$export$866f445d49bad88e, capo);
|
|
4152
|
+
}
|
|
4153
|
+
setDirective(name, value) {
|
|
4154
|
+
if (value === null) return this.removeItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === name
|
|
4141
4155
|
);
|
|
4142
|
-
|
|
4156
|
+
return this.updateItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === name
|
|
4143
4157
|
, (item)=>item.set({
|
|
4144
|
-
value:
|
|
4158
|
+
value: value
|
|
4145
4159
|
})
|
|
4146
|
-
, (song)=>song.insertDirective(
|
|
4160
|
+
, (song)=>song.insertDirective(name, value)
|
|
4147
4161
|
);
|
|
4148
|
-
updatedSong.metadata.set('capo', capo);
|
|
4149
|
-
return updatedSong;
|
|
4150
4162
|
}
|
|
4151
4163
|
/**
|
|
4152
4164
|
* Returns a copy of the song with the key set to the specified key. It changes:
|
|
4153
4165
|
* - the value for `key` in the `metadata` set
|
|
4154
4166
|
* - any existing `key` directive
|
|
4155
4167
|
* - all chords, those are transposed according to the distance between the current and the new key
|
|
4156
|
-
* @param {string}
|
|
4168
|
+
* @param {string} newKey The new key.
|
|
4157
4169
|
* @returns {Song} The changed song
|
|
4158
|
-
*/
|
|
4159
|
-
const transpose =
|
|
4170
|
+
*/ changeKey(newKey) {
|
|
4171
|
+
const transpose = this.getTransposeDistance(newKey);
|
|
4160
4172
|
const updatedSong = this.mapItems((item)=>{
|
|
4161
4173
|
if (item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === $5e9ede69210ec54a$export$7167c830cefcb6b5) return item.set({
|
|
4162
|
-
value:
|
|
4174
|
+
value: newKey
|
|
4163
4175
|
});
|
|
4164
|
-
if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose,
|
|
4176
|
+
if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose, newKey);
|
|
4165
4177
|
return item;
|
|
4166
4178
|
});
|
|
4167
|
-
updatedSong.metadata.set('key',
|
|
4179
|
+
updatedSong.metadata.set('key', newKey);
|
|
4180
|
+
return updatedSong;
|
|
4181
|
+
}
|
|
4182
|
+
getTransposeDistance(newKey) {
|
|
4183
|
+
const wrappedKey = $bff5407e03fdc8ee$export$2e2bcd8739ae039.wrap(this.key);
|
|
4184
|
+
if (!wrappedKey) throw new Error(`
|
|
4185
|
+
Cannot change song key, the original key is unknown.
|
|
4186
|
+
|
|
4187
|
+
Either ensure a key directive is present in the song (when using chordpro):
|
|
4188
|
+
\`{key: C}\`
|
|
4189
|
+
|
|
4190
|
+
Or set the song key before changing key:
|
|
4191
|
+
\`song.setKey('C');\``.substring(1));
|
|
4192
|
+
return wrappedKey.distanceTo(newKey);
|
|
4193
|
+
}
|
|
4194
|
+
/**
|
|
4195
|
+
* Returns a copy of the song with the directive value set to the specified value.
|
|
4196
|
+
* - when there is a matching directive in the song, it will update the directive
|
|
4197
|
+
* - when there is no matching directive, it will be inserted
|
|
4198
|
+
* If `value` is `null` it will act as a delete, any directive matching `name` will be removed.
|
|
4199
|
+
* @param {string} name The directive name
|
|
4200
|
+
* @param {string | null} value The value to set, or `null` to remove the directive
|
|
4201
|
+
*/ changeMetadata(name, value) {
|
|
4202
|
+
const updatedSong = this.setDirective(name, value);
|
|
4203
|
+
updatedSong.metadata.set(name, value);
|
|
4168
4204
|
return updatedSong;
|
|
4169
4205
|
}
|
|
4170
4206
|
insertDirective(name, value, { after: after = null } = {}) {
|