@parent-tobias/chord-component 1.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/LICENSE +21 -0
- package/README.md +359 -0
- package/dist/chord-data-service.js +190 -0
- package/dist/chord-diagram.js +181 -0
- package/dist/chord-editor.js +691 -0
- package/dist/chord-list.js +119 -0
- package/dist/default-chords.js +322 -0
- package/dist/index.js +26 -0
- package/dist/indexed-db-service.js +228 -0
- package/dist/music-utils.js +128 -0
- package/dist/node_modules/@lit/reactive-element/css-tag.js +42 -0
- package/dist/node_modules/@lit/reactive-element/decorators/base.js +9 -0
- package/dist/node_modules/@lit/reactive-element/decorators/custom-element.js +13 -0
- package/dist/node_modules/@lit/reactive-element/decorators/property.js +37 -0
- package/dist/node_modules/@lit/reactive-element/decorators/query.js +20 -0
- package/dist/node_modules/@lit/reactive-element/decorators/state.js +12 -0
- package/dist/node_modules/@lit/reactive-element/reactive-element.js +251 -0
- package/package.json +83 -0
- package/src/chord-data-service.ts +275 -0
- package/src/chord-diagram.ts +255 -0
- package/src/chord-editor.ts +919 -0
- package/src/chord-list.ts +145 -0
- package/src/default-chords.ts +333 -0
- package/src/index.ts +7 -0
- package/src/indexed-db-service.ts +356 -0
- package/src/music-utils.ts +216 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { css as b, LitElement as x, html as n } from "lit";
|
|
2
|
+
import { customElement as w } from "./node_modules/@lit/reactive-element/decorators/custom-element.js";
|
|
3
|
+
import { property as v } from "./node_modules/@lit/reactive-element/decorators/property.js";
|
|
4
|
+
import { state as g } from "./node_modules/@lit/reactive-element/decorators/state.js";
|
|
5
|
+
import { query as C } from "./node_modules/@lit/reactive-element/decorators/query.js";
|
|
6
|
+
import { SVGuitarChord as D } from "svguitar";
|
|
7
|
+
import { instruments as E, chordToNotes as $, chordOnInstrument as j } from "./music-utils.js";
|
|
8
|
+
import { chordDataService as F } from "./chord-data-service.js";
|
|
9
|
+
var O = Object.defineProperty, L = Object.getOwnPropertyDescriptor, d = (r, c, a, o) => {
|
|
10
|
+
for (var i = o > 1 ? void 0 : o ? L(c, a) : c, h = r.length - 1, s; h >= 0; h--)
|
|
11
|
+
(s = r[h]) && (i = (o ? s(c, a, i) : s(i)) || i);
|
|
12
|
+
return o && i && O(c, a, i), i;
|
|
13
|
+
};
|
|
14
|
+
let e = class extends x {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments), this.instrument = "Standard Ukulele", this.chord = "", this.chordData = {}, this.isLoading = !1, this.loadError = null;
|
|
17
|
+
}
|
|
18
|
+
async connectedCallback() {
|
|
19
|
+
super.connectedCallback(), await this.loadChordData();
|
|
20
|
+
}
|
|
21
|
+
async updated(r) {
|
|
22
|
+
super.updated(r), r.has("instrument") && await this.loadChordData();
|
|
23
|
+
}
|
|
24
|
+
async loadChordData() {
|
|
25
|
+
this.isLoading = !0, this.loadError = null;
|
|
26
|
+
try {
|
|
27
|
+
const r = await F.getChordData(this.instrument);
|
|
28
|
+
this.chordData = r.data;
|
|
29
|
+
} catch (r) {
|
|
30
|
+
console.error("Failed to load chord data:", r), this.loadError = "Failed to load chord data", this.chordData = {};
|
|
31
|
+
} finally {
|
|
32
|
+
this.isLoading = !1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
render() {
|
|
36
|
+
if (this.isLoading)
|
|
37
|
+
return n`
|
|
38
|
+
<div class='chord'>
|
|
39
|
+
<div style="color: #90cdf4; font-size: 0.8rem; text-align: center; padding: 0.5rem;">
|
|
40
|
+
Loading...
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
`;
|
|
44
|
+
if (this.loadError)
|
|
45
|
+
return n`
|
|
46
|
+
<div class='chord'>
|
|
47
|
+
<div class='error'>${this.loadError}</div>
|
|
48
|
+
</div>
|
|
49
|
+
`;
|
|
50
|
+
if (!this.chord)
|
|
51
|
+
return n`
|
|
52
|
+
<div class='chord'>
|
|
53
|
+
<div class='error'>No chord specified</div>
|
|
54
|
+
</div>
|
|
55
|
+
`;
|
|
56
|
+
const r = E.find(({ name: t }) => t === this.instrument);
|
|
57
|
+
if (!r)
|
|
58
|
+
return n`
|
|
59
|
+
<div class='chord'>
|
|
60
|
+
<span>${this.chord.replace(/(maj)$/, "")}</span>
|
|
61
|
+
<div class='error'>Unknown instrument: ${this.instrument}</div>
|
|
62
|
+
</div>
|
|
63
|
+
`;
|
|
64
|
+
const c = j(r), a = $(this.chord);
|
|
65
|
+
if (!a || !a.notes || a.notes.length === 0)
|
|
66
|
+
return n`
|
|
67
|
+
<div class='chord'>
|
|
68
|
+
<span>${this.chord.replace(/(maj)$/, "")}</span>
|
|
69
|
+
<div class='error'>Unknown chord: ${this.chord}</div>
|
|
70
|
+
</div>
|
|
71
|
+
`;
|
|
72
|
+
const o = this.chordData[this.chord] ? this.chordData[this.chord] : {
|
|
73
|
+
barres: [],
|
|
74
|
+
fingers: c(a) || []
|
|
75
|
+
}, i = o.fingers.map(
|
|
76
|
+
([, t]) => typeof t == "number" ? t : 1 / 0
|
|
77
|
+
), h = o.barres.map((t) => typeof t.fret == "number" ? t.fret : 0), s = [...i, ...h], y = s.length > 0 ? Math.min(...s.filter((t) => t > 0)) : 1, l = s.length > 0 ? Math.max(...s, 0) : 4;
|
|
78
|
+
let m = 1;
|
|
79
|
+
l > 4 && (m = Math.max(1, y));
|
|
80
|
+
let p, f;
|
|
81
|
+
m > 1 || l > 4 ? (p = Math.max(l - m + 1, 4), f = m) : (p = Math.max(l, 4), f = 1);
|
|
82
|
+
const u = document.createElement("div");
|
|
83
|
+
try {
|
|
84
|
+
return new D(u).configure({
|
|
85
|
+
strings: r.strings.length,
|
|
86
|
+
frets: p,
|
|
87
|
+
position: f,
|
|
88
|
+
tuning: [...r.strings]
|
|
89
|
+
}).chord({
|
|
90
|
+
fingers: o.fingers,
|
|
91
|
+
barres: o.barres
|
|
92
|
+
}).draw(), n`
|
|
93
|
+
<div class='chord'>
|
|
94
|
+
<span>${this.chord.replace(/(maj)$/, "")}</span>
|
|
95
|
+
<div class='diagram'>${u.firstChild}</div>
|
|
96
|
+
</div>
|
|
97
|
+
`;
|
|
98
|
+
} catch (t) {
|
|
99
|
+
return console.error("Error generating chord diagram:", t), n`
|
|
100
|
+
<div class='chord'>
|
|
101
|
+
<span>${this.chord.replace(/(maj)$/, "")}</span>
|
|
102
|
+
<div class='error'>Error generating diagram</div>
|
|
103
|
+
</div>
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
e.styles = b`
|
|
109
|
+
:host {
|
|
110
|
+
display: block;
|
|
111
|
+
width: 100%;
|
|
112
|
+
min-width: 100px;
|
|
113
|
+
max-width: 150px;
|
|
114
|
+
border: 1px solid #4a5568;
|
|
115
|
+
border-radius: 4px;
|
|
116
|
+
background: #2d3748;
|
|
117
|
+
padding: 0.5rem;
|
|
118
|
+
box-sizing: border-box;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.chord {
|
|
122
|
+
display: flex;
|
|
123
|
+
flex-direction: column;
|
|
124
|
+
align-items: center;
|
|
125
|
+
width: 100%;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.chord span {
|
|
129
|
+
color: #f8f8f8;
|
|
130
|
+
font-size: 0.9rem;
|
|
131
|
+
font-weight: 500;
|
|
132
|
+
margin-bottom: 0.25rem;
|
|
133
|
+
text-align: center;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.diagram {
|
|
137
|
+
width: 100%;
|
|
138
|
+
display: flex;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.diagram :global(svg) {
|
|
143
|
+
max-width: 100%;
|
|
144
|
+
height: auto;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.error {
|
|
148
|
+
color: #fc8181;
|
|
149
|
+
font-size: 0.8rem;
|
|
150
|
+
text-align: center;
|
|
151
|
+
padding: 0.5rem;
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
154
|
+
d([
|
|
155
|
+
v({
|
|
156
|
+
type: String
|
|
157
|
+
})
|
|
158
|
+
], e.prototype, "instrument", 2);
|
|
159
|
+
d([
|
|
160
|
+
v({
|
|
161
|
+
type: String
|
|
162
|
+
})
|
|
163
|
+
], e.prototype, "chord", 2);
|
|
164
|
+
d([
|
|
165
|
+
C(".diagram")
|
|
166
|
+
], e.prototype, "container", 2);
|
|
167
|
+
d([
|
|
168
|
+
g()
|
|
169
|
+
], e.prototype, "chordData", 2);
|
|
170
|
+
d([
|
|
171
|
+
g()
|
|
172
|
+
], e.prototype, "isLoading", 2);
|
|
173
|
+
d([
|
|
174
|
+
g()
|
|
175
|
+
], e.prototype, "loadError", 2);
|
|
176
|
+
e = d([
|
|
177
|
+
w("chord-diagram")
|
|
178
|
+
], e);
|
|
179
|
+
export {
|
|
180
|
+
e as ChordDiagram
|
|
181
|
+
};
|