@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.
@@ -0,0 +1,145 @@
1
+ import { LitElement, css, html, type PropertyValues } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import './chord-diagram.js';
4
+
5
+ /**
6
+ * A web component that displays a list of chord diagrams for a specific instrument.
7
+ *
8
+ * @element chord-list
9
+ *
10
+ * @attr {string} instrument - The instrument to display chords for (default: 'Standard Ukulele')
11
+ * @attr {string|string[]} chords - JSON string or array of chord names to display
12
+ *
13
+ * @example
14
+ * ```html
15
+ * <chord-list instrument="Standard Ukulele" chords='["C", "F", "G", "Am"]'></chord-list>
16
+ * <chord-list instrument="Standard Guitar" chords='["E", "A", "D"]'></chord-list>
17
+ * ```
18
+ */
19
+ @customElement('chord-list')
20
+ export class ChordList extends LitElement {
21
+
22
+ /**
23
+ * The instrument to display chords for
24
+ */
25
+ @property({
26
+ type: String
27
+ })
28
+ instrument = 'Standard Ukulele';
29
+
30
+ /**
31
+ * The chord names to display - can be a JSON string or array
32
+ */
33
+ @property()
34
+ chords: string | string[] = '[]';
35
+
36
+ /**
37
+ * Parsed chord names from the chords property
38
+ */
39
+ private get parsedChords(): string[] {
40
+ try {
41
+ if (Array.isArray(this.chords)) {
42
+ return this.chords;
43
+ }
44
+ if (typeof this.chords === 'string') {
45
+ return JSON.parse(this.chords);
46
+ }
47
+ return [];
48
+ } catch {
49
+ return [];
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Number of chords in the list (reactive state)
55
+ */
56
+ @state()
57
+ numChords = 0;
58
+
59
+ static styles = css`
60
+ :host {
61
+ display: block;
62
+ width: 100%;
63
+ height: fit-content;
64
+ container-type: inline-size;
65
+ }
66
+
67
+ header {
68
+ margin-bottom: 0.5rem;
69
+ }
70
+
71
+ header h3 {
72
+ margin: 0;
73
+ font-size: 1rem;
74
+ color: #f8f8f8;
75
+ font-weight: 600;
76
+ }
77
+
78
+ .list {
79
+ display: grid;
80
+ grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
81
+ gap: 0.5rem;
82
+ align-items: start;
83
+ }
84
+
85
+ .empty-state {
86
+ color: #a0aec0;
87
+ font-size: 0.9rem;
88
+ text-align: center;
89
+ padding: 1rem;
90
+ font-style: italic;
91
+ }
92
+
93
+ /* Responsive adjustments for different container widths */
94
+ @container (max-width: 400px) {
95
+ .list {
96
+ grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
97
+ gap: 0.3rem;
98
+ }
99
+ }
100
+
101
+ @container (min-width: 600px) {
102
+ .list {
103
+ grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
104
+ }
105
+ }
106
+
107
+ @container (min-width: 800px) {
108
+ .list {
109
+ grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
110
+ }
111
+ }
112
+ `
113
+
114
+ updated(changedProperties: PropertyValues<this>) {
115
+ if (changedProperties.has("chords")) {
116
+ this.numChords = this.parsedChords.length;
117
+ }
118
+ }
119
+
120
+ render() {
121
+ const chordNames = this.parsedChords;
122
+
123
+ if (chordNames.length === 0) {
124
+ return html`
125
+ <header>
126
+ <h3>${this.instrument}</h3>
127
+ </header>
128
+ <div class='empty-state'>
129
+ No chords to display
130
+ </div>
131
+ `;
132
+ }
133
+
134
+ return html`
135
+ <header>
136
+ <h3>${this.instrument} (${this.numChords} chord${this.numChords !== 1 ? 's' : ''})</h3>
137
+ </header>
138
+ <div class='list'>
139
+ ${chordNames.map((chord) =>
140
+ html`<chord-diagram chord=${chord} instrument='${this.instrument}'></chord-diagram>`
141
+ )}
142
+ </div>
143
+ `;
144
+ }
145
+ }
@@ -0,0 +1,333 @@
1
+ import type { Finger, Barre } from 'svguitar';
2
+
3
+ interface Dictionary<T> {
4
+ [key: string]: T
5
+ }
6
+
7
+ export type InstrumentDefault = {
8
+ barres: Barre[]
9
+ fingers: Finger[]
10
+ position?: number // Starting fret position (1 = first fret, etc.)
11
+ }
12
+
13
+ type Instrument = Dictionary<InstrumentDefault>
14
+
15
+ export const systemDefaultChords: Dictionary<Instrument> = {
16
+ "Standard Ukulele": {
17
+ "Cm": {
18
+ "barres": [],
19
+ "fingers": [
20
+ [3,3],
21
+ [2,3],
22
+ [1,3]
23
+ ]
24
+ },
25
+ "Cm7": {
26
+ "barres": [{
27
+ "fromString": 4,
28
+ "toString": 1,
29
+ "fret": 3,
30
+ "text": "1"
31
+ }],
32
+ "fingers": []
33
+ },
34
+ "Cdim": {
35
+ "barres": [],
36
+ "fingers": [
37
+ [4,2],
38
+ [3,3],
39
+ [2,2],
40
+ [1,3]
41
+ ]
42
+ },
43
+ "C": {
44
+ "barres": [],
45
+ "fingers": [
46
+ [4,0],
47
+ [3,0],
48
+ [2,0],
49
+ [1,3]
50
+ ]
51
+ },
52
+ "C7": {
53
+ "barres": [],
54
+ "fingers": [
55
+ [4,0],
56
+ [3,0],
57
+ [2,0],
58
+ [1,1]
59
+ ]
60
+ },
61
+ "Cmaj7": {
62
+ "barres": [],
63
+ "fingers": [
64
+ [4,0],
65
+ [3,0],
66
+ [2,0],
67
+ [1,2]
68
+ ]
69
+ },
70
+ "Dm": {
71
+ "barres": [],
72
+ "fingers": [
73
+ [4,2],
74
+ [3,2],
75
+ [2,1],
76
+ [1,0]
77
+ ]
78
+ },
79
+ "Dm7": {
80
+ "barres": [],
81
+ "fingers": [
82
+ [4,2],
83
+ [3,2],
84
+ [2,1],
85
+ [1,3]
86
+ ]
87
+ },
88
+ "D": {
89
+ "barres": [],
90
+ "fingers": [
91
+ [4,2],
92
+ [3,2],
93
+ [2,2],
94
+ [1,0]
95
+ ]
96
+ },
97
+ "D7": {
98
+ "barres": [],
99
+ "fingers": [
100
+ [4,2],
101
+ [3,2],
102
+ [2,2],
103
+ [1,3]
104
+ ]
105
+ },
106
+ "Em": {
107
+ "barres": [],
108
+ "fingers": [
109
+ [4,0],
110
+ [3,4],
111
+ [2,3],
112
+ [1,2]
113
+ ]
114
+ },
115
+ "E": {
116
+ "barres": [],
117
+ "fingers": [
118
+ [4,4],
119
+ [3,4],
120
+ [2,4],
121
+ [1,2]
122
+ ]
123
+ },
124
+ "E7": {
125
+ "barres": [],
126
+ "fingers": [
127
+ [4,2],
128
+ [3,4],
129
+ [2,4],
130
+ [1,2]
131
+ ]
132
+ },
133
+ "F": {
134
+ "barres": [],
135
+ "fingers": [
136
+ [4,2],
137
+ [3,0],
138
+ [2,1],
139
+ [1,0]
140
+ ]
141
+ },
142
+ "F7": {
143
+ "barres": [],
144
+ "fingers": [
145
+ [4,2],
146
+ [3,3],
147
+ [2,1],
148
+ [1,3]
149
+ ]
150
+ },
151
+ "Fm": {
152
+ "barres": [],
153
+ "fingers": [
154
+ [4,1],
155
+ [3,0],
156
+ [2,1],
157
+ [1,3]
158
+ ]
159
+ },
160
+ "G": {
161
+ "barres": [],
162
+ "fingers": [
163
+ [4,0],
164
+ [3,2],
165
+ [2,3],
166
+ [1,2]
167
+ ]
168
+ },
169
+ "G7": {
170
+ "barres": [],
171
+ "fingers": [
172
+ [4,0],
173
+ [3,2],
174
+ [2,1],
175
+ [1,2]
176
+ ]
177
+ },
178
+ "Gm": {
179
+ "barres": [],
180
+ "fingers": [
181
+ [4,0],
182
+ [3,2],
183
+ [2,3],
184
+ [1,1]
185
+ ]
186
+ },
187
+ "Am": {
188
+ "barres": [],
189
+ "fingers": [
190
+ [4,2],
191
+ [3,0],
192
+ [2,0],
193
+ [1,0]
194
+ ]
195
+ },
196
+ "A": {
197
+ "barres": [],
198
+ "fingers": [
199
+ [4,2],
200
+ [3,1],
201
+ [2,0],
202
+ [1,0]
203
+ ]
204
+ },
205
+ "A7": {
206
+ "barres": [],
207
+ "fingers": [
208
+ [4,0],
209
+ [3,1],
210
+ [2,0],
211
+ [1,0]
212
+ ]
213
+ },
214
+ "Bm": {
215
+ "barres": [],
216
+ "fingers": [
217
+ [4,4],
218
+ [3,2],
219
+ [2,2],
220
+ [1,2]
221
+ ]
222
+ },
223
+ "B": {
224
+ "barres": [],
225
+ "fingers": [
226
+ [4,4],
227
+ [3,3],
228
+ [2,2],
229
+ [1,2]
230
+ ]
231
+ },
232
+ "B7": {
233
+ "barres": [],
234
+ "fingers": [
235
+ [4,2],
236
+ [3,3],
237
+ [2,2],
238
+ [1,2]
239
+ ]
240
+ }
241
+ },
242
+ "Standard Guitar": {
243
+ "C": {
244
+ "barres": [],
245
+ "fingers": [
246
+ [5,3],
247
+ [4,2],
248
+ [2,1]
249
+ ]
250
+ },
251
+ "Cm": {
252
+ "barres": [{
253
+ "fromString": 5,
254
+ "toString": 1,
255
+ "fret": 3,
256
+ "text": "1"
257
+ }],
258
+ "fingers": [
259
+ [4,5],
260
+ [3,5],
261
+ [2,4]
262
+ ]
263
+ },
264
+ "D": {
265
+ "barres": [],
266
+ "fingers": [
267
+ [4,2],
268
+ [3,3],
269
+ [1,2]
270
+ ]
271
+ },
272
+ "Dm": {
273
+ "barres": [],
274
+ "fingers": [
275
+ [4,2],
276
+ [3,3],
277
+ [1,1]
278
+ ]
279
+ },
280
+ "E": {
281
+ "barres": [],
282
+ "fingers": [
283
+ [5,2],
284
+ [4,2],
285
+ [3,1]
286
+ ]
287
+ },
288
+ "Em": {
289
+ "barres": [],
290
+ "fingers": [
291
+ [5,2],
292
+ [4,2]
293
+ ]
294
+ },
295
+ "F": {
296
+ "barres": [{
297
+ "fromString": 6,
298
+ "toString": 1,
299
+ "fret": 1,
300
+ "text": "1"
301
+ }],
302
+ "fingers": [
303
+ [5,3],
304
+ [4,3],
305
+ [3,2]
306
+ ]
307
+ },
308
+ "G": {
309
+ "barres": [],
310
+ "fingers": [
311
+ [6,3],
312
+ [1,3],
313
+ [5,2]
314
+ ]
315
+ },
316
+ "A": {
317
+ "barres": [],
318
+ "fingers": [
319
+ [4,2],
320
+ [3,2],
321
+ [2,2]
322
+ ]
323
+ },
324
+ "Am": {
325
+ "barres": [],
326
+ "fingers": [
327
+ [4,2],
328
+ [3,2],
329
+ [2,1]
330
+ ]
331
+ }
332
+ }
333
+ };
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { ChordDiagram } from './chord-diagram.js';
2
+ export { ChordList } from './chord-list.js';
3
+ export { ChordEditor } from './chord-editor.js';
4
+ export * from './music-utils.js';
5
+ export * from './default-chords.js';
6
+ export { chordDataService } from './chord-data-service.js';
7
+ export { indexedDBService } from './indexed-db-service.js';