chordsheetjs 6.2.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 CHANGED
@@ -1,4 +1,4 @@
1
- # ChordChartJS [![Code Climate](https://codeclimate.com/github/PraiseCharts/ChordChartJS/badges/gpa.svg)](https://codeclimate.com/github/PraiseCharts/ChordChartJS)
1
+ # ChordSheetJS [![Code Climate](https://codeclimate.com/github/martijnversluis/ChordSheetJS/badges/gpa.svg)](https://codeclimate.com/github/martijnversluis/ChordSheetJS)
2
2
 
3
3
  A JavaScript library for parsing and formatting chord sheets
4
4
 
@@ -11,6 +11,8 @@ A JavaScript library for parsing and formatting chord sheets
11
11
 
12
12
  ## Installation
13
13
 
14
+ ### Package managers
15
+
14
16
  `ChordSheetJS` is on npm, to install run:
15
17
 
16
18
  ```bash
@@ -631,10 +633,15 @@ If not, it returns [INDETERMINATE](#INDETERMINATE)</p>
631
633
  * [new Song(metadata)](#new_Song_new)
632
634
  * [.bodyLines](#Song+bodyLines) ⇒ <code>Array.&lt;Line&gt;</code>
633
635
  * [.bodyParagraphs](#Song+bodyParagraphs) ⇒ [<code>Array.&lt;Paragraph&gt;</code>](#Paragraph)
636
+ * [.paragraphs](#Song+paragraphs) : [<code>Array.&lt;Paragraph&gt;</code>](#Paragraph)
634
637
  * ~~[.metaData](#Song+metaData) ⇒~~
635
638
  * [.clone()](#Song+clone) ⇒ [<code>Song</code>](#Song)
636
- * [.setCapo(capo)](#Song+setCapo) ⇒ [<code>Song</code>](#Song)
637
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)
643
+ * [.mapItems(func)](#Song+mapItems) ⇒ [<code>Song</code>](#Song)
644
+ * [.mapLines(func)](#Song+mapLines) ⇒ [<code>Song</code>](#Song)
638
645
 
639
646
  <a name="new_Song_new"></a>
640
647
 
@@ -662,6 +669,12 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
662
669
 
663
670
  **Kind**: instance property of [<code>Song</code>](#Song)
664
671
  **See**: [bodyLines](bodyLines)
672
+ <a name="Song+paragraphs"></a>
673
+
674
+ ### song.paragraphs : [<code>Array.&lt;Paragraph&gt;</code>](#Paragraph)
675
+ <p>The [Paragraph](#Paragraph) items of which the song consists</p>
676
+
677
+ **Kind**: instance property of [<code>Song</code>](#Song)
665
678
  <a name="Song+metaData"></a>
666
679
 
667
680
  ### ~~song.metaData ⇒~~
@@ -678,13 +691,29 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
678
691
 
679
692
  **Kind**: instance method of [<code>Song</code>](#Song)
680
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
+
681
710
  <a name="Song+setCapo"></a>
682
711
 
683
712
  ### song.setCapo(capo) ⇒ [<code>Song</code>](#Song)
684
- <p>Returns a copy of the song with the capo value set to the specified capo. It changes:</p>
713
+ <p>Returns a copy of the song with the key value set to the specified capo. It changes:</p>
685
714
  <ul>
686
715
  <li>the value for <code>capo</code> in the <code>metadata</code> set</li>
687
- <li>any existing <code>capo</code> directive)</li>
716
+ <li>any existing <code>capo</code> directive</li>
688
717
  </ul>
689
718
 
690
719
  **Kind**: instance method of [<code>Song</code>](#Song)
@@ -694,9 +723,9 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
694
723
  | --- | --- | --- |
695
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> |
696
725
 
697
- <a name="Song+setKey"></a>
726
+ <a name="Song+changeKey"></a>
698
727
 
699
- ### song.setKey(key) ⇒ [<code>Song</code>](#Song)
728
+ ### song.changeKey(newKey) ⇒ [<code>Song</code>](#Song)
700
729
  <p>Returns a copy of the song with the key set to the specified key. It changes:</p>
701
730
  <ul>
702
731
  <li>the value for <code>key</code> in the <code>metadata</code> set</li>
@@ -709,8 +738,71 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
709
738
 
710
739
  | Param | Type | Description |
711
740
  | --- | --- | --- |
712
- | key | <code>string</code> | <p>The new key.</p> |
741
+ | newKey | <code>string</code> | <p>The new key.</p> |
742
+
743
+ <a name="Song+changeMetadata"></a>
713
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> |
759
+
760
+ <a name="Song+mapItems"></a>
761
+
762
+ ### song.mapItems(func) ⇒ [<code>Song</code>](#Song)
763
+ <p>Change the song contents inline. Return a new [Item](Item) to replace it. Return <code>null</code> to remove it.</p>
764
+
765
+ **Kind**: instance method of [<code>Song</code>](#Song)
766
+ **Returns**: [<code>Song</code>](#Song) - <p>the changed song</p>
767
+
768
+ | Param | Type | Description |
769
+ | --- | --- | --- |
770
+ | func | <code>MapItemsCallback</code> | <p>the callback function</p> |
771
+
772
+ **Example**
773
+ ```js
774
+ // transpose all chords:
775
+ song.mapItems((item) => {
776
+ if (item instanceof ChordLyricsPair) {
777
+ return item.transpose(2, 'D');
778
+ }
779
+
780
+ return item;
781
+ });
782
+ ```
783
+ <a name="Song+mapLines"></a>
784
+
785
+ ### song.mapLines(func) ⇒ [<code>Song</code>](#Song)
786
+ <p>Change the song contents inline. Return a new [Line](Line) to replace it. Return <code>null</code> to remove it.</p>
787
+
788
+ **Kind**: instance method of [<code>Song</code>](#Song)
789
+ **Returns**: [<code>Song</code>](#Song) - <p>the changed song</p>
790
+
791
+ | Param | Type | Description |
792
+ | --- | --- | --- |
793
+ | func | <code>MapLinesCallback</code> | <p>the callback function</p> |
794
+
795
+ **Example**
796
+ ```js
797
+ // remove lines with only Tags:
798
+ song.mapLines((line) => {
799
+ if (line.items.every(item => item instanceof Tag)) {
800
+ return null;
801
+ }
802
+
803
+ return line;
804
+ });
805
+ ```
714
806
  <a name="Tag"></a>
715
807
 
716
808
  ## Tag
package/lib/bundle.js CHANGED
@@ -1,4 +1,5 @@
1
1
  (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ChordSheetJS = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
+ var $988mA$process = require("process");
2
3
  var $988mA$lodashget = require("lodash.get");
3
4
  var $988mA$handlebars = require("handlebars");
4
5
 
@@ -1944,6 +1945,7 @@ var $6ebb068142750218$export$2e2bcd8739ae039 = {
1944
1945
  };
1945
1946
 
1946
1947
 
1948
+
1947
1949
  const $21a34a464e7bc609$export$13215d9ce4923f76 = (collection, Klass)=>{
1948
1950
  const newObject = new Klass();
1949
1951
  collection.push(newObject);
@@ -1981,11 +1983,10 @@ ${scopedSelector} {
1981
1983
  }).join('\n\n');
1982
1984
  }
1983
1985
  function $21a34a464e7bc609$export$b680e6b2c82f8c2f(message) {
1984
- const { process: process } = this;
1985
1986
  try {
1986
1987
  throw new Error(`DEPRECATION: ${message}`);
1987
1988
  } catch (e) {
1988
- if (typeof process === 'object' && typeof process.emitWarning === 'function') process.emitWarning(`${message}\n${e.stack}`);
1989
+ if (typeof $988mA$process === 'object' && typeof $988mA$process.emitWarning === 'function') $988mA$process.emitWarning(`${message}\n${e.stack}`);
1989
1990
  else console.warn(`${message}\n${e.stack}`);
1990
1991
  }
1991
1992
  }
@@ -1993,6 +1994,7 @@ function $21a34a464e7bc609$export$78d1711480f95c3e(string) {
1993
1994
  return string === null || string === undefined || string === '';
1994
1995
  }
1995
1996
  function $21a34a464e7bc609$export$595e981f61839426(string, constructor, regexes) {
1997
+ if ($21a34a464e7bc609$export$78d1711480f95c3e(string)) return null;
1996
1998
  for(let i = 0, count = regexes.length; i < count; i += 1){
1997
1999
  const match = string.match(regexes[i]);
1998
2000
  if (match) return new constructor(match.groups);
@@ -3387,6 +3389,11 @@ var $26f57998457eb2d4$export$2e2bcd8739ae039 = $26f57998457eb2d4$var$Chord;
3387
3389
  set(properties) {
3388
3390
  return new $d454f4215ba01af2$var$ChordLyricsPair(properties.chords || this.chords, properties.lyrics || this.lyrics);
3389
3391
  }
3392
+ setLyrics(lyrics) {
3393
+ return this.set({
3394
+ lyrics: lyrics
3395
+ });
3396
+ }
3390
3397
  transpose(delta, key) {
3391
3398
  const chordObj = $26f57998457eb2d4$export$2e2bcd8739ae039.parse(this.chords);
3392
3399
  if (chordObj) return this.set({
@@ -3563,6 +3570,11 @@ const $5e9ede69210ec54a$var$translateTagNameAlias = (name)=>{
3563
3570
  set({ value: value }) {
3564
3571
  return new $5e9ede69210ec54a$var$Tag(this._originalName, value);
3565
3572
  }
3573
+ setValue(value) {
3574
+ return this.set({
3575
+ value: value
3576
+ });
3577
+ }
3566
3578
  }
3567
3579
  var $5e9ede69210ec54a$export$2e2bcd8739ae039 = $5e9ede69210ec54a$var$Tag;
3568
3580
 
@@ -3961,12 +3973,7 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
3961
3973
  * The {@link Line} items of which the song consists
3962
3974
  * @member {Line[]}
3963
3975
  */ lines = [];
3964
- /**
3965
- * The {@link Paragraph} items of which the song consists
3966
- * @member {Paragraph[]}
3967
- */ paragraphs = [];
3968
3976
  currentLine = null;
3969
- currentParagraph = null;
3970
3977
  warnings = [];
3971
3978
  sectionType = $af8d31735c159a26$export$c53d0f541b41b88e;
3972
3979
  currentKey = null;
@@ -4015,37 +4022,35 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4015
4022
  this.ensureLine();
4016
4023
  this.currentLine.lyrics(chr);
4017
4024
  }
4018
- addLine() {
4019
- this.ensureParagraph();
4020
- this.flushLine();
4021
- this.currentLine = $21a34a464e7bc609$export$13215d9ce4923f76(this.lines, $bc411321e9739719$export$2e2bcd8739ae039);
4025
+ addLine(line) {
4026
+ this.currentLine = line || $21a34a464e7bc609$export$13215d9ce4923f76(this.lines, $bc411321e9739719$export$2e2bcd8739ae039);
4022
4027
  this.setCurrentLineType(this.sectionType);
4023
4028
  this.currentLine.transposeKey = this.transposeKey ?? this.currentKey;
4024
4029
  this.currentLine.key = this.currentKey || this.metadata.getSingle($5e9ede69210ec54a$export$7167c830cefcb6b5);
4025
4030
  return this.currentLine;
4026
4031
  }
4032
+ /**
4033
+ * The {@link Paragraph} items of which the song consists
4034
+ * @member {Paragraph[]}
4035
+ */ get paragraphs() {
4036
+ let currentParagraph = new $0c3420c6a3e8a9d7$export$2e2bcd8739ae039();
4037
+ const paragraphs = [
4038
+ currentParagraph
4039
+ ];
4040
+ this.lines.forEach((line)=>{
4041
+ if (line.isEmpty()) {
4042
+ currentParagraph = new $0c3420c6a3e8a9d7$export$2e2bcd8739ae039();
4043
+ paragraphs.push(currentParagraph);
4044
+ } else if (line.hasRenderableItems()) currentParagraph.addLine(line);
4045
+ });
4046
+ return paragraphs;
4047
+ }
4027
4048
  setCurrentLineType(sectionType) {
4028
4049
  this.currentLine.type = sectionType;
4029
4050
  }
4030
- flushLine() {
4031
- if (this.currentLine !== null) {
4032
- if (this.currentLine.isEmpty()) this.addParagraph();
4033
- else if (this.currentLine.hasRenderableItems()) this.currentParagraph.addLine(this.currentLine);
4034
- }
4035
- }
4036
- finish() {
4037
- this.flushLine();
4038
- }
4039
4051
  ensureLine() {
4040
4052
  if (this.currentLine === null) this.addLine();
4041
4053
  }
4042
- addParagraph() {
4043
- this.currentParagraph = $21a34a464e7bc609$export$13215d9ce4923f76(this.paragraphs, $0c3420c6a3e8a9d7$export$2e2bcd8739ae039);
4044
- return this.currentParagraph;
4045
- }
4046
- ensureParagraph() {
4047
- if (this.currentParagraph === null) this.addParagraph();
4048
- }
4049
4054
  addTag(tagContents) {
4050
4055
  const tag = $5e9ede69210ec54a$export$2e2bcd8739ae039.parse(tagContents);
4051
4056
  if (tag.isMetaTag()) this.setMetadata(tag.name, tag.value);
@@ -4107,7 +4112,8 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4107
4112
  * Returns a deep clone of the song
4108
4113
  * @returns {Song} The cloned song
4109
4114
  */ clone() {
4110
- return this.mapItems(null);
4115
+ return this.mapItems((item)=>item
4116
+ );
4111
4117
  }
4112
4118
  setMetadata(name, value) {
4113
4119
  this.metadata.add(name, value);
@@ -4124,43 +4130,78 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4124
4130
  return this.metadata[name] || null;
4125
4131
  }
4126
4132
  /**
4127
- * Returns a copy of the song with the capo value set to the specified capo. It changes:
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:
4128
4145
  * - the value for `capo` in the `metadata` set
4129
- * - any existing `capo` directive)
4146
+ * - any existing `capo` directive
4130
4147
  * @param {number|null} capo the capo. Passing `null` will:
4131
4148
  * - remove the current key from `metadata`
4132
4149
  * - remove any `capo` directive
4133
4150
  * @returns {Song} The changed song
4134
4151
  */ setCapo(capo) {
4135
- let updatedSong;
4136
- if (capo === null) updatedSong = this.removeItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === $5e9ede69210ec54a$export$866f445d49bad88e
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
4137
4156
  );
4138
- else updatedSong = this.updateItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === $5e9ede69210ec54a$export$866f445d49bad88e
4157
+ return this.updateItem((item)=>item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === name
4139
4158
  , (item)=>item.set({
4140
- value: capo
4159
+ value: value
4141
4160
  })
4142
- , (song)=>song.insertDirective($5e9ede69210ec54a$export$866f445d49bad88e, capo)
4161
+ , (song)=>song.insertDirective(name, value)
4143
4162
  );
4144
- updatedSong.metadata.set('capo', capo);
4145
- return updatedSong;
4146
4163
  }
4147
4164
  /**
4148
4165
  * Returns a copy of the song with the key set to the specified key. It changes:
4149
4166
  * - the value for `key` in the `metadata` set
4150
4167
  * - any existing `key` directive
4151
4168
  * - all chords, those are transposed according to the distance between the current and the new key
4152
- * @param {string} key The new key.
4169
+ * @param {string} newKey The new key.
4153
4170
  * @returns {Song} The changed song
4154
- */ setKey(key) {
4155
- const transpose = $bff5407e03fdc8ee$export$2e2bcd8739ae039.distance(this.key, key);
4171
+ */ changeKey(newKey) {
4172
+ const transpose = this.getTransposeDistance(newKey);
4156
4173
  const updatedSong = this.mapItems((item)=>{
4157
4174
  if (item instanceof $5e9ede69210ec54a$export$2e2bcd8739ae039 && item.name === $5e9ede69210ec54a$export$7167c830cefcb6b5) return item.set({
4158
- value: key
4175
+ value: newKey
4159
4176
  });
4160
- if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose, key);
4177
+ if (item instanceof $d454f4215ba01af2$export$2e2bcd8739ae039) return item.transpose(transpose, newKey);
4161
4178
  return item;
4162
4179
  });
4163
- updatedSong.metadata.set('key', 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);
4164
4205
  return updatedSong;
4165
4206
  }
4166
4207
  insertDirective(name, value, { after: after = null } = {}) {
@@ -4178,19 +4219,53 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4178
4219
  ];
4179
4220
  return clonedSong;
4180
4221
  }
4181
- mapItems(func) {
4222
+ /**
4223
+ * Change the song contents inline. Return a new {@link Item} to replace it. Return `null` to remove it.
4224
+ * @example
4225
+ * // transpose all chords:
4226
+ * song.mapItems((item) => {
4227
+ * if (item instanceof ChordLyricsPair) {
4228
+ * return item.transpose(2, 'D');
4229
+ * }
4230
+ *
4231
+ * return item;
4232
+ * });
4233
+ * @param {MapItemsCallback} func the callback function
4234
+ * @returns {Song} the changed song
4235
+ */ mapItems(func) {
4182
4236
  const clonedSong = new $6f653df65dfdf4ef$var$Song();
4183
- clonedSong.lines = this.lines.map((line)=>line.mapItems(func)
4184
- );
4185
- clonedSong.metadata = this.metadata.clone();
4237
+ this.lines.forEach((line)=>{
4238
+ clonedSong.addLine();
4239
+ line.items.forEach((item)=>{
4240
+ const changedItem = func(item);
4241
+ if (changedItem) clonedSong.addItem(changedItem);
4242
+ });
4243
+ });
4186
4244
  return clonedSong;
4187
4245
  }
4188
- mapLines(func) {
4246
+ /**
4247
+ * Change the song contents inline. Return a new {@link Line} to replace it. Return `null` to remove it.
4248
+ * @example
4249
+ * // remove lines with only Tags:
4250
+ * song.mapLines((line) => {
4251
+ * if (line.items.every(item => item instanceof Tag)) {
4252
+ * return null;
4253
+ * }
4254
+ *
4255
+ * return line;
4256
+ * });
4257
+ * @param {MapLinesCallback} func the callback function
4258
+ * @returns {Song} the changed song
4259
+ */ mapLines(func) {
4189
4260
  const clonedSong = new $6f653df65dfdf4ef$var$Song();
4190
- clonedSong.lines = this.lines.map((line)=>func(line.clone())
4191
- ).filter((line)=>line
4192
- );
4193
- clonedSong.metadata = this.metadata.clone();
4261
+ this.lines.forEach((line)=>{
4262
+ const changedLine = func(line);
4263
+ if (changedLine) {
4264
+ clonedSong.addLine();
4265
+ changedLine.items.forEach((item)=>clonedSong.addItem(item)
4266
+ );
4267
+ }
4268
+ });
4194
4269
  return clonedSong;
4195
4270
  }
4196
4271
  updateItem(findCallback, updateCallback, notFoundCallback) {
@@ -4393,7 +4468,6 @@ const $1c14afc274b727b7$var$LINE = 'line';
4393
4468
  * @returns {Song} The deserialized song
4394
4469
  */ deserialize(serializedSong) {
4395
4470
  this.parseAstComponent(serializedSong);
4396
- this.song.finish();
4397
4471
  return this.song;
4398
4472
  }
4399
4473
  parseAstComponent(astComponent) {
@@ -4527,7 +4601,6 @@ const $c049675f48c823b2$var$CHORD_LINE_REGEX = /^\s*((([A-G])(#|b)?([^/\s]*)(\/(
4527
4601
  this.parseLine(line);
4528
4602
  }
4529
4603
  this.endOfSong();
4530
- this.song.finish();
4531
4604
  return this.song;
4532
4605
  }
4533
4606
  endOfSong() {}
@@ -6288,7 +6361,7 @@ var $882b6d93070905b3$export$2e2bcd8739ae039 = {
6288
6361
 
6289
6362
 
6290
6363
 
6291
- },{"handlebars":35,"lodash.get":36}],2:[function(require,module,exports){
6364
+ },{"handlebars":35,"lodash.get":36,"process":48}],2:[function(require,module,exports){
6292
6365
 
6293
6366
  },{}],3:[function(require,module,exports){
6294
6367
  'use strict';
@@ -15349,5 +15422,8 @@ exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGene
15349
15422
  exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer;
15350
15423
  exports.SourceNode = require('./lib/source-node').SourceNode;
15351
15424
 
15352
- },{"./lib/source-map-consumer":43,"./lib/source-map-generator":44,"./lib/source-node":45}]},{},[1])(1)
15425
+ },{"./lib/source-map-consumer":43,"./lib/source-map-generator":44,"./lib/source-node":45}],48:[function(require,module,exports){
15426
+ module.exports = {"browser": true}
15427
+
15428
+ },{}]},{},[1])(1)
15353
15429
  });
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>