chordsheetjs 5.1.3 → 5.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.
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
commit d7b54993c4ea66c07a35bd36690482ab620f836e
|
|
2
|
+
Author: Martijn Versluis <martijnversluis@users.noreply.github.com>
|
|
3
|
+
Date: Sun Jan 30 16:35:24 2022 +0100
|
|
4
|
+
|
|
5
|
+
Do not rely on contructor name
|
|
6
|
+
|
|
7
|
+
Due to build tools scrambling constructor names, we can not rely on those
|
|
8
|
+
for type checking. Thus we have to use `instanceof`. This change removes
|
|
9
|
+
usages of `constructor.name` and solves the cyclic dependency by moving around
|
|
10
|
+
some functions.
|
|
11
|
+
|
|
12
|
+
Resolves #421
|
|
13
|
+
|
|
14
|
+
diff --git a/src/formatter/html_div_formatter.js b/src/formatter/html_div_formatter.js
|
|
15
|
+
index f92f532..b1de230 100644
|
|
16
|
+
--- a/src/formatter/html_div_formatter.js
|
|
17
|
+
+++ b/src/formatter/html_div_formatter.js
|
|
18
|
+
@@ -1,6 +1,6 @@
|
|
19
|
+
import Handlebars from 'handlebars';
|
|
20
|
+
|
|
21
|
+
-import '../handlebars_helpers';
|
|
22
|
+
+import '../template_helpers';
|
|
23
|
+
import HtmlFormatter from './html_formatter';
|
|
24
|
+
import './templates/html_div_formatter';
|
|
25
|
+
import { scopeCss } from '../utilities';
|
|
26
|
+
diff --git a/src/formatter/html_table_formatter.js b/src/formatter/html_table_formatter.js
|
|
27
|
+
index 4883fef..7d7e8ea 100644
|
|
28
|
+
--- a/src/formatter/html_table_formatter.js
|
|
29
|
+
+++ b/src/formatter/html_table_formatter.js
|
|
30
|
+
@@ -1,6 +1,6 @@
|
|
31
|
+
import Handlebars from 'handlebars';
|
|
32
|
+
|
|
33
|
+
-import '../handlebars_helpers';
|
|
34
|
+
+import '../template_helpers';
|
|
35
|
+
import HtmlFormatter from './html_formatter';
|
|
36
|
+
import './templates/html_table_formatter';
|
|
37
|
+
import { scopeCss } from '../utilities';
|
|
38
|
+
diff --git a/src/formatter/text_formatter.js b/src/formatter/text_formatter.js
|
|
39
|
+
index 61385f1..81fe226 100644
|
|
40
|
+
--- a/src/formatter/text_formatter.js
|
|
41
|
+
+++ b/src/formatter/text_formatter.js
|
|
42
|
+
@@ -1,10 +1,10 @@
|
|
43
|
+
import ChordLyricsPair from '../chord_sheet/chord_lyrics_pair';
|
|
44
|
+
import Tag from '../chord_sheet/tag';
|
|
45
|
+
import { renderChord } from '../helpers';
|
|
46
|
+
+import { hasTextContents } from '../template_helpers';
|
|
47
|
+
|
|
48
|
+
import {
|
|
49
|
+
hasChordContents,
|
|
50
|
+
- hasTextContents,
|
|
51
|
+
padLeft,
|
|
52
|
+
} from '../utilities';
|
|
53
|
+
|
|
54
|
+
diff --git a/src/handlebars_helpers.js b/src/template_helpers.js
|
|
55
|
+
similarity index 87%
|
|
56
|
+
rename from src/handlebars_helpers.js
|
|
57
|
+
rename to src/template_helpers.js
|
|
58
|
+
index 0e5ff98..b330f87 100644
|
|
59
|
+
--- a/src/handlebars_helpers.js
|
|
60
|
+
+++ b/src/template_helpers.js
|
|
61
|
+
@@ -7,12 +7,20 @@ import { renderChord } from './helpers';
|
|
62
|
+
|
|
63
|
+
import {
|
|
64
|
+
hasChordContents,
|
|
65
|
+
- hasTextContents,
|
|
66
|
+
isEvaluatable,
|
|
67
|
+
} from './utilities';
|
|
68
|
+
|
|
69
|
+
const lineHasContents = (line) => line.items.some((item) => item.isRenderable());
|
|
70
|
+
|
|
71
|
+
+/* eslint import/prefer-default-export: 0 */
|
|
72
|
+
+export const hasTextContents = (line) => (
|
|
73
|
+
+ line.items.some((item) => (
|
|
74
|
+
+ (item instanceof ChordLyricsPair && item.lyrics)
|
|
75
|
+
+ || (item instanceof Tag && item.isRenderable())
|
|
76
|
+
+ || isEvaluatable(item)
|
|
77
|
+
+ ))
|
|
78
|
+
+);
|
|
79
|
+
+
|
|
80
|
+
HandleBars.registerHelper('isChordLyricsPair', (item) => item instanceof ChordLyricsPair);
|
|
81
|
+
|
|
82
|
+
HandleBars.registerHelper('isTag', (item) => item instanceof Tag);
|
|
83
|
+
diff --git a/src/utilities.js b/src/utilities.js
|
|
84
|
+
index 03c69cc..503c811 100644
|
|
85
|
+
--- a/src/utilities.js
|
|
86
|
+
+++ b/src/utilities.js
|
|
87
|
+
@@ -8,18 +8,6 @@ export const hasChordContents = (line) => line.items.some((item) => !!item.chord
|
|
88
|
+
|
|
89
|
+
export const isEvaluatable = (item) => typeof item.evaluate === 'function';
|
|
90
|
+
|
|
91
|
+
-function isInstanceOf(object, constructorName) {
|
|
92
|
+
- return object?.constructor?.name === constructorName;
|
|
93
|
+
-}
|
|
94
|
+
-
|
|
95
|
+
-export const hasTextContents = (line) => (
|
|
96
|
+
- line.items.some((item) => (
|
|
97
|
+
- (isInstanceOf(item, 'ChordLyricsPair') && item.lyrics)
|
|
98
|
+
- || (isInstanceOf(item, 'Tag') && item.isRenderable())
|
|
99
|
+
- || isEvaluatable(item)
|
|
100
|
+
- ))
|
|
101
|
+
-);
|
|
102
|
+
-
|
|
103
|
+
export const padLeft = (str, length) => {
|
|
104
|
+
let paddedString = str;
|
|
105
|
+
for (let l = str.length; l < length; l += 1, paddedString += ' ');
|
|
@@ -529,7 +529,7 @@ function peg$parse(input, options) {
|
|
|
529
529
|
}
|
|
530
530
|
|
|
531
531
|
function peg$parseLine() {
|
|
532
|
-
var s0, s1, s2, s3, s4;
|
|
532
|
+
var s0, s1, s2, s3, s4, s5, s6;
|
|
533
533
|
s0 = peg$currPos;
|
|
534
534
|
s1 = peg$parseLyrics();
|
|
535
535
|
|
|
@@ -561,9 +561,22 @@ function peg$parse(input, options) {
|
|
|
561
561
|
}
|
|
562
562
|
|
|
563
563
|
if (s4 !== peg$FAILED) {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
564
|
+
s5 = [];
|
|
565
|
+
s6 = peg$parseSpace();
|
|
566
|
+
|
|
567
|
+
while (s6 !== peg$FAILED) {
|
|
568
|
+
s5.push(s6);
|
|
569
|
+
s6 = peg$parseSpace();
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (s5 !== peg$FAILED) {
|
|
573
|
+
peg$savedPos = s0;
|
|
574
|
+
s1 = peg$c2(s1, s2, s3, s4);
|
|
575
|
+
s0 = s1;
|
|
576
|
+
} else {
|
|
577
|
+
peg$currPos = s0;
|
|
578
|
+
s0 = peg$FAILED;
|
|
579
|
+
}
|
|
567
580
|
} else {
|
|
568
581
|
peg$currPos = s0;
|
|
569
582
|
s0 = peg$FAILED;
|
|
@@ -1714,13 +1727,9 @@ function peg$parse(input, options) {
|
|
|
1714
1727
|
s0 = [];
|
|
1715
1728
|
s1 = peg$parseTagValueChar();
|
|
1716
1729
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
s1 = peg$parseTagValueChar();
|
|
1721
|
-
}
|
|
1722
|
-
} else {
|
|
1723
|
-
s0 = peg$FAILED;
|
|
1730
|
+
while (s1 !== peg$FAILED) {
|
|
1731
|
+
s0.push(s1);
|
|
1732
|
+
s1 = peg$parseTagValueChar();
|
|
1724
1733
|
}
|
|
1725
1734
|
|
|
1726
1735
|
return s0;
|