vector-score 1.1.0 → 1.2.1
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 +159 -40
- package/dist/classes/GuitarChord.d.ts +108 -0
- package/dist/classes/SVGRenderer.d.ts +19 -0
- package/dist/constants.d.ts +19 -0
- package/dist/helpers/guitarHelpers.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/types.d.ts +15 -0
- package/dist/vector-score.js +488 -161
- package/dist/vector-score.umd.cjs +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -5,41 +5,33 @@
|
|
|
5
5
|
[](https://bundlephobia.com/package/vector-score)
|
|
6
6
|

|
|
7
7
|
|
|
8
|
-
A lightweight, SVG-based TypeScript library for rendering musical
|
|
8
|
+
A lightweight, SVG-based TypeScript library for rendering simple musical notation, rhythm staves, and guitar chords. Designed for simple displaying musical information for musical oriented web applications.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* **Multiple Staff Types**: Supports Treble, Bass, Alto, and Grand staves (MusicStaff and ScrollingStaff).
|
|
13
|
-
* [**Music Staff**](#Standard-Music-Staff):Standard music staff for notation.
|
|
14
|
-
* [**Rhythm Staff**](#Rhythm-Staff): Dedicated staff for rhythm exercises with customizable time signatures and bar handling.
|
|
15
|
-
* [**Scrolling Staff**](#Scrolling-Staff) Staff made to allow for 'endless' style of notes.
|
|
16
|
-
* **SVG Rendering**: Scalable Vector graphics suitable for any screen size.
|
|
17
|
-
* **Flexible Note Input**: Simple string-based syntax for defining notes.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm i vector-score
|
|
23
|
-
````
|
|
10
|
+
<br/>
|
|
24
11
|
|
|
25
|
-
##
|
|
12
|
+
## Features
|
|
26
13
|
|
|
27
|
-
|
|
14
|
+
### Rendering Standard Musical Notation
|
|
15
|
+
* Supports grand, treble, bass, and alto clefs.
|
|
16
|
+
* Easy to add notes and provides justifying alignment functions.
|
|
17
|
+
* Simple single line staff for display chords, notes, or scales.
|
|
18
|
+
* [**Go to Music Staffs**](#Grand-Staff)
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
### Render and Display Guitar Chords
|
|
21
|
+
* Write explicitly which string, fret, and optionally finger to display on the diagram.
|
|
22
|
+
* Supports explicity barre chords.
|
|
23
|
+
* Label each string below diagram, useful for showing tuning of chord.
|
|
24
|
+
* [**Go to Guitar Chords**](#Guitar-Chords)
|
|
32
25
|
|
|
33
|
-
|
|
26
|
+
### Extra Classes
|
|
27
|
+
* Dedicated staff for rhythm exercises with customizable time signatures and bar handling. [**Go to Rhythm Staff**](#Rhythm-Staff)
|
|
28
|
+
* Staff made to allow for 'endless' style of notes. [**Go to Scrolling Staff**](#Scrolling-Staff)
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
npm run build
|
|
37
|
-
```
|
|
30
|
+
<br />
|
|
38
31
|
|
|
39
32
|
## Usage
|
|
40
33
|
|
|
41
34
|
### 1. Setup HTML
|
|
42
|
-
|
|
43
35
|
Create a container element in your HTML where the staff will be rendered.
|
|
44
36
|
|
|
45
37
|
```html
|
|
@@ -47,8 +39,7 @@ Create a container element in your HTML where the staff will be rendered.
|
|
|
47
39
|
```
|
|
48
40
|
|
|
49
41
|
### 2. Import and Initialize
|
|
50
|
-
|
|
51
|
-
### Standard Music Staff
|
|
42
|
+
Import desired class (MusicStaff, GuitarChord, etc.). Declare variable with reference to container element. Pass in options for specific class (options are typed).
|
|
52
43
|
|
|
53
44
|
```typescript
|
|
54
45
|
import { MusicStaff } from 'vector-score';
|
|
@@ -64,19 +55,43 @@ const staff = new MusicStaff(container, {
|
|
|
64
55
|
});
|
|
65
56
|
|
|
66
57
|
// Draw a C Minor scale (quarter notes)
|
|
67
|
-
// Format: NoteName + Accidental(optional) + Octave + Duration
|
|
68
58
|
staff.drawNote(['C4q', 'D4q', 'Eb4q', 'F4q', 'G4q', 'Ab4q', 'Bb4q', 'C5q']);
|
|
69
|
-
|
|
70
|
-
// Draw a C Chord
|
|
71
|
-
staff.drawChord(['C4w', 'E4w', 'G4w']);
|
|
72
|
-
|
|
73
|
-
// Evenly space all notes on the staff
|
|
74
59
|
staff.justifyNotes();
|
|
75
60
|
```
|
|
76
|
-
|
|
61
|
+
|
|
62
|
+
### Resulting Staff
|
|
77
63
|

|
|
78
64
|
|
|
79
|
-
|
|
65
|
+
<br/>
|
|
66
|
+
|
|
67
|
+
## Notes
|
|
68
|
+
|
|
69
|
+
### CSS Classes
|
|
70
|
+
Listed below will be all the specific classes that can be targeted to change their repsective elements styling. All elements that are designed to be targeted with classes are prefixed with `vs-`.
|
|
71
|
+
|
|
72
|
+
* `svg.vs-svg-renderer-root`: The actual svg element.
|
|
73
|
+
* `g.vs-svg-renderer-parent`: The main group element.
|
|
74
|
+
* `text.vs-guitar-text-base && text.vs-guitar-text-small`: The \<text\> elements for the labels on the guitar chord diagram.
|
|
75
|
+
* `circle.vs-guitar-fret-dot`: The element for the guitar fret dots.
|
|
76
|
+
* `rect.vs-guitar-barre`: The element for the guitar barre lines.
|
|
77
|
+
* `g.vs-scrolling-notes-layer > g.vs-note-wrapper`: Targeting the scrolling staff's notes, which a transition property can be added for smooth animation.
|
|
78
|
+
|
|
79
|
+
Example
|
|
80
|
+
|
|
81
|
+
```css
|
|
82
|
+
/* Target and change the fret dot colors */
|
|
83
|
+
.vs-guitar-fret-dot {
|
|
84
|
+
fill: oklch(67% 0.05 240.864);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
<br />
|
|
89
|
+
|
|
90
|
+
## Grand Staff
|
|
91
|
+
|
|
92
|
+
See [**Note String Syntax**](#Note-String-Syntax) to see how to write notes on music staff (i.e. ['G4q', 'E4h', 'C4w', "A3h", "F3h"] )
|
|
93
|
+
|
|
94
|
+
See [**MusicStaffOptions**](#MusicStaffOptions) to see how configuration options during class instantiation.
|
|
80
95
|
|
|
81
96
|
```typescript
|
|
82
97
|
import { MusicStaff } from 'vector-score';
|
|
@@ -93,10 +108,51 @@ grandStaff.drawNote(['G4q', 'E4h', 'C4w', "A3h", "F3h"]);
|
|
|
93
108
|
|
|
94
109
|
grandStaff.drawChord(["G3w", "C4w", "E4w"]);
|
|
95
110
|
```
|
|
96
|
-
|
|
111
|
+
### Resulting Staff
|
|
97
112
|

|
|
98
113
|
|
|
99
|
-
|
|
114
|
+
<br/>
|
|
115
|
+
|
|
116
|
+
## Guitar Chords
|
|
117
|
+
|
|
118
|
+
See [**Guitar String Syntax**](#Guitar-String-Syntax) to see how to write **frets**, **fingers**, and **barre lines** on Guitar Chord diagrams (i.e., `"x32010"`, `"032010"`).
|
|
119
|
+
|
|
120
|
+
See [**GuitarChordOptions**](#GuitarChordOptions) to see how configuration options during class instantiation.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { GuitarChord } from 'vector-score';
|
|
124
|
+
|
|
125
|
+
const grandStaff = new GuitarChord(container, {
|
|
126
|
+
fretCount: 5,
|
|
127
|
+
stringCount: 6,
|
|
128
|
+
stringLabels: ["E", "A", "D", "G", "B", "E"],
|
|
129
|
+
inlineChordsAmount: 2, // Choose how many chords are in a single line
|
|
130
|
+
scale: 1,
|
|
131
|
+
color: "var(--font-color)",
|
|
132
|
+
backgroundColor: "white"
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// C chord
|
|
136
|
+
guitarChordsSection.addChord("x32010", "032010", {
|
|
137
|
+
label: "C",
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Bbmaj7 Barre Chord (Automatically calculates the starting fret and barre positioning)
|
|
141
|
+
const frets = "687766";
|
|
142
|
+
const fingers = "142311";
|
|
143
|
+
const barres = guitarChordsSection.determineBarreOptions(frets, fingers, [6]);
|
|
144
|
+
|
|
145
|
+
guitarChordsSection.addChord(frets, fingers, {
|
|
146
|
+
label: "Bbmaj7",
|
|
147
|
+
barres: barres
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
### Result
|
|
151
|
+

|
|
152
|
+
|
|
153
|
+
<br />
|
|
154
|
+
|
|
155
|
+
## Rhythm Staff
|
|
100
156
|
|
|
101
157
|
```typescript
|
|
102
158
|
import { RhythmStaff } from 'vector-score';
|
|
@@ -122,10 +178,12 @@ rhythm.drawNote(['q', 'q']);
|
|
|
122
178
|
// Increment the UI to show the first beat in the bar
|
|
123
179
|
rhythm.incrementCurrentBeatUI();
|
|
124
180
|
```
|
|
125
|
-
|
|
181
|
+
### Resulting Staff
|
|
126
182
|

|
|
127
183
|
|
|
128
|
-
|
|
184
|
+
<br />
|
|
185
|
+
|
|
186
|
+
## Scrolling Staff
|
|
129
187
|
|
|
130
188
|
```typescript
|
|
131
189
|
import { ScrollingStaff } from 'vector-score';
|
|
@@ -165,9 +223,11 @@ scrollingStaff.queueNotes([
|
|
|
165
223
|
|
|
166
224
|
// The button event listener calls 'advanceNotes()' to move the notes over, one step at a time.
|
|
167
225
|
```
|
|
168
|
-
|
|
226
|
+
### Resulting Staff
|
|
169
227
|

|
|
170
228
|
|
|
229
|
+
<br />
|
|
230
|
+
|
|
171
231
|
## Note String Syntax
|
|
172
232
|
|
|
173
233
|
Notes are defined using a specific string format parsed by the library:
|
|
@@ -188,6 +248,35 @@ Notes are defined using a specific string format parsed by the library:
|
|
|
188
248
|
* `F#5q`: F Sharp, Octave 5, Quarter note
|
|
189
249
|
* `Bb3e`: B Flat, Octave 3, Eighth note
|
|
190
250
|
|
|
251
|
+
<br />
|
|
252
|
+
|
|
253
|
+
## Guitar String Syntax
|
|
254
|
+
|
|
255
|
+
Chords are defined using two continuous strings: one for **frets** and one for **fingers**. The length of both strings must match the configured string count of the diagram (default is 6). Notes are written in ***string order***, with the first character representing the lowest string (e.g., low E in standard tuning).
|
|
256
|
+
|
|
257
|
+
### Frets String format: `[xX\da-zA-Z]+`
|
|
258
|
+
* `x` or `X`: Muted string.
|
|
259
|
+
* `0`: Open string.
|
|
260
|
+
* `1-9`: Fretted at the specified fret.
|
|
261
|
+
* `a-z` / `A-Z`: Base-36 alphanumeric encoding for double-digit frets (e.g., `a` = 10, `b` = 11, `c` = 12).
|
|
262
|
+
|
|
263
|
+
### Fingers String format: `[\d]+`
|
|
264
|
+
* `0`: No finger labeled.
|
|
265
|
+
* `1-9`: Finger number to display on the dot.
|
|
266
|
+
|
|
267
|
+
**Example:**
|
|
268
|
+
* `guitarChordsSection.addChord("x32010", "032010")`: Displays an open C major chord.
|
|
269
|
+
* The lowest string is muted (`x`) and has no finger label (`0`).
|
|
270
|
+
* The A string is played at the 3rd fret (`3`) with the 3rd finger (`3`).
|
|
271
|
+
* *Note: The `startFret` option is now automatically calculated based on the lowest fretted note if left undefined.*
|
|
272
|
+
|
|
273
|
+
### Barre Lines
|
|
274
|
+
Barre lines can be added dynamically using the built-in helper method, `determineBarreOptions(frets, fingers, barreFrets)`.
|
|
275
|
+
* Pass in your fret string, finger string, and an array of the target frets you wish to barre.
|
|
276
|
+
* The method will automatically calculate the stretch (`fromString` to `toString`) based on the matching finger numbers and return a definition array to pass directly into your `addChord` options.
|
|
277
|
+
|
|
278
|
+
<br />
|
|
279
|
+
|
|
191
280
|
## API Reference
|
|
192
281
|
|
|
193
282
|
### MusicStaff Class
|
|
@@ -202,6 +291,22 @@ Notes are defined using a specific string format parsed by the library:
|
|
|
202
291
|
| `changeChordByIndex(notes: string[], index: number)` | Replaces a chord at a specific index with a new chord. |
|
|
203
292
|
| `destroy()` | Destroys internal arrays and elements |
|
|
204
293
|
|
|
294
|
+
<br/>
|
|
295
|
+
|
|
296
|
+
### GuitarChord Class
|
|
297
|
+
|
|
298
|
+
| Method | Description |
|
|
299
|
+
| :--- | :--- |
|
|
300
|
+
| `addChord(frets: string, fingers: string, options?: GuitarChordDrawOptions)` | Draws notes on the diagram using string configurations. Options include manual `startFret`, `label`, and `barres`. |
|
|
301
|
+
| `modifyChordByIndex(frets: string, fingers: string, chordIndex: number, options?: GuitarChordDrawOptions)` | Modifies the chord at the specified index with new definitions and options. |
|
|
302
|
+
| `determineBarreOptions(frets: string, fingers: string, barreFrets: number[])` | Automatically calculates barre line dimensions based on fingering and returns `GuitarBarreDef[]` to be used in chord options. |
|
|
303
|
+
| `removeChordByIndex(chordIndex: number)` | Removes the chord diagram at the specified index and recalculates layout. |
|
|
304
|
+
| `clearAllChords()` | Removes all chords in the container. |
|
|
305
|
+
| `destroy()` | Destroys internal arrays and elements. |
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
<br/>
|
|
309
|
+
|
|
205
310
|
### RhythmStaff Class
|
|
206
311
|
|
|
207
312
|
| Method | Description |
|
|
@@ -214,6 +319,8 @@ Notes are defined using a specific string format parsed by the library:
|
|
|
214
319
|
| `resetCurrentBeatUI()` | Must be called if current beat goes over the total beats in the bar to reset its state |
|
|
215
320
|
| `destroy()` | Destroys internal arrays and elements |
|
|
216
321
|
|
|
322
|
+
<br/>
|
|
323
|
+
|
|
217
324
|
### ScrollingStaff Class
|
|
218
325
|
|
|
219
326
|
| Method | Description |
|
|
@@ -223,6 +330,8 @@ Notes are defined using a specific string format parsed by the library:
|
|
|
223
330
|
| `clearAllNote()` | Clears all notes on the staff |
|
|
224
331
|
| `destroy()` | Destroys internal arrays and elements |
|
|
225
332
|
|
|
333
|
+
<br />
|
|
334
|
+
|
|
226
335
|
## Configuration Options
|
|
227
336
|
|
|
228
337
|
### MusicStaffOptions
|
|
@@ -236,6 +345,16 @@ Notes are defined using a specific string format parsed by the library:
|
|
|
236
345
|
* `staffColor`: CSS color string for lines and notes.
|
|
237
346
|
* `staffBackgroundColor`: CSS color string for background.
|
|
238
347
|
|
|
348
|
+
### GuitarChordOptions
|
|
349
|
+
* `stringCount`: Amount of strings to show in diagram, default is 6.
|
|
350
|
+
* `fretCount`: Amount of frets to show in diagram, default is 5.
|
|
351
|
+
* `stringLabels`: Labels to show under each string in each chord diagram. Provided string values will display in order of strings in this array value.
|
|
352
|
+
* `inlineChordsAmount`: Max amount of chords to display on a single line (default: 2).
|
|
353
|
+
* `scale`: Zoom factor (default: 1).
|
|
354
|
+
* `color`: CSS color string for lines and notes.
|
|
355
|
+
* `backgroundColor`: CSS color string for background.
|
|
356
|
+
* `width`: Total width of the SVG in pixels, overrides inlineChordAmount auto width calculation (default: undefined).
|
|
357
|
+
|
|
239
358
|
### RhythmStaffOptions
|
|
240
359
|
* `topNumber`: The top number of the time signature (e.g., 4 for 4/4 time).
|
|
241
360
|
* `barsCount`: Number of measures to draw.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { GuitarBarreDef, GuitarChordDrawOptions } from '../types';
|
|
2
|
+
export type GuitarChordOptions = {
|
|
3
|
+
width?: number;
|
|
4
|
+
inlineChordsAmount?: number;
|
|
5
|
+
scale?: number;
|
|
6
|
+
stringCount?: number;
|
|
7
|
+
fretCount?: number;
|
|
8
|
+
stringLabels?: string[];
|
|
9
|
+
color?: string;
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
};
|
|
12
|
+
export default class GuitarChord {
|
|
13
|
+
private svgRendererInstance;
|
|
14
|
+
private options;
|
|
15
|
+
private chordEntries;
|
|
16
|
+
private cursorX;
|
|
17
|
+
private cursorY;
|
|
18
|
+
private readonly diagramWidth;
|
|
19
|
+
private readonly diagramHeight;
|
|
20
|
+
private readonly gridTopY;
|
|
21
|
+
private readonly rowHeight;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of a GuitarChord diagram renderer.
|
|
24
|
+
*
|
|
25
|
+
* @param rootElementCtx - The element (div) reference that the chord diagram(s) will be appended to.
|
|
26
|
+
* @param options - Optional configuration. Can adjust total width, scale, string/fret count, and coloring.
|
|
27
|
+
* All config options are in the type GuitarChordOptions.
|
|
28
|
+
*/
|
|
29
|
+
constructor(rootElementCtx: HTMLElement, options?: GuitarChordOptions);
|
|
30
|
+
private getDotsToHide;
|
|
31
|
+
private drawFretDots;
|
|
32
|
+
private drawStringLabels;
|
|
33
|
+
private drawBarre;
|
|
34
|
+
private renderChordDiagram;
|
|
35
|
+
private relayoutChords;
|
|
36
|
+
/**
|
|
37
|
+
* Adds a new chord diagram. Diagrams are placed left-to-right in the order added, wrapping to a
|
|
38
|
+
* new row automatically once the configured width is exceeded.
|
|
39
|
+
*
|
|
40
|
+
* @param frets - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
|
|
41
|
+
* * `x` - muted string
|
|
42
|
+
* * `0` - open string
|
|
43
|
+
* * `1...n` - fretted at the given absolute fret number (e.g. `3`)
|
|
44
|
+
* @param fingers - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
|
|
45
|
+
* * `0` - No finger labeled
|
|
46
|
+
* * `1...n` - Finger labeled as number provided
|
|
47
|
+
*
|
|
48
|
+
* @param options - Optional per-chord settings: `startFret` (default `1`, for diagrams higher up the neck)
|
|
49
|
+
* and `label` (a chord name drawn above the diagram).
|
|
50
|
+
*
|
|
51
|
+
* @returns The index of the newly added chord, for later use with the CRUD-by-index methods.
|
|
52
|
+
*
|
|
53
|
+
* @throws {Error} If fret or finger's string length doesn't match the configured string count.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Draw an open C major chord
|
|
57
|
+
* guitarChord.addChord("x32010", "032010", { label: "C" });
|
|
58
|
+
*/
|
|
59
|
+
addChord(frets: string, fingers: string, options?: GuitarChordDrawOptions): number;
|
|
60
|
+
/**
|
|
61
|
+
* Replaces the chord diagram at the specified index with a new one, in place.
|
|
62
|
+
*
|
|
63
|
+
* @param frets - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
|
|
64
|
+
* * `x` - muted string
|
|
65
|
+
* * `0` - open string
|
|
66
|
+
* * `1...n` - fretted at the given absolute fret number (e.g. `3`)
|
|
67
|
+
* @param fingers - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
|
|
68
|
+
* * `0` - No finger labeled
|
|
69
|
+
* * `1...n` - Finger labeled as number provided
|
|
70
|
+
*
|
|
71
|
+
* @param chordIndex - The index of the chord to replace (as returned by addChord).
|
|
72
|
+
*
|
|
73
|
+
* @param options - Optional per-chord settings, see addChord.
|
|
74
|
+
*
|
|
75
|
+
* @returns void
|
|
76
|
+
*
|
|
77
|
+
* @throws {Error} If the index is out of bounds, or if chordDef is invalid (see addChord).
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // Change chord at index 0 to a D major chord
|
|
81
|
+
* guitarChord.modifyChordByIndex("xx0232", "000132", 0, { label: "D" });
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
modifyChordByIndex(frets: string, fingers: string, chordIndex: number, options?: GuitarChordDrawOptions): void;
|
|
85
|
+
/**
|
|
86
|
+
* Removes the chord diagram at the specified index. Remaining chords are re-flowed to close the gap.
|
|
87
|
+
* @param chordIndex - The index of the chord to remove.
|
|
88
|
+
* @returns void
|
|
89
|
+
* @throws {Error} If the index is out of bounds.
|
|
90
|
+
*/
|
|
91
|
+
removeChordByIndex(chordIndex: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Removes all chord diagrams and resets internal positioning.
|
|
94
|
+
* @returns void
|
|
95
|
+
*/
|
|
96
|
+
clearAllChords(): void;
|
|
97
|
+
/**
|
|
98
|
+
* * Used to automatically determine options for creating barre lines.
|
|
99
|
+
* * The returned value then can be used in addChord and modifyChord methods.
|
|
100
|
+
* @returns GuitarBarreDef[]
|
|
101
|
+
*/
|
|
102
|
+
determineBarreOptions(frets: string, fingers: string, barreFrets: number[]): GuitarBarreDef[];
|
|
103
|
+
/**
|
|
104
|
+
* Removes the root svg element and cleans up arrays.
|
|
105
|
+
* @returns void
|
|
106
|
+
*/
|
|
107
|
+
destroy(): void;
|
|
108
|
+
}
|
|
@@ -17,6 +17,21 @@ type DrawRectOptions = {
|
|
|
17
17
|
x?: number;
|
|
18
18
|
y?: number;
|
|
19
19
|
fill?: string;
|
|
20
|
+
rx?: number;
|
|
21
|
+
classes?: string | string[];
|
|
22
|
+
};
|
|
23
|
+
type DrawCircleOptions = {
|
|
24
|
+
filled?: boolean;
|
|
25
|
+
fill?: string;
|
|
26
|
+
strokeWidth?: number;
|
|
27
|
+
classes?: string | string[];
|
|
28
|
+
};
|
|
29
|
+
type DrawTextOptions = {
|
|
30
|
+
fontSize?: number;
|
|
31
|
+
anchor?: "start" | "middle" | "end";
|
|
32
|
+
fill?: string;
|
|
33
|
+
fontWeight?: string;
|
|
34
|
+
classes?: string | string[];
|
|
20
35
|
};
|
|
21
36
|
export default class SVGRenderer {
|
|
22
37
|
private rootElementRef;
|
|
@@ -31,10 +46,12 @@ export default class SVGRenderer {
|
|
|
31
46
|
private totalHeight;
|
|
32
47
|
constructor(rootElementCtx: HTMLElement, options: SVGRendererOptions);
|
|
33
48
|
private makeGlyphDefs;
|
|
49
|
+
private addNamespacedClassesToElement;
|
|
34
50
|
createGroup(className?: string): SVGGElement;
|
|
35
51
|
commitElementsToDOM(elements: SVGElement[] | SVGElement, parent?: HTMLElement | SVGElement): void;
|
|
36
52
|
getLayerByName(name: LayerNames): SVGGElement;
|
|
37
53
|
addTotalRootSvgHeight(amount: number): void;
|
|
54
|
+
setTotalRootSvgHeight(amount: number): void;
|
|
38
55
|
addTotalRootSvgYOffset(amount: number): void;
|
|
39
56
|
applySizingToRootSvg(): void;
|
|
40
57
|
get rootSvgElement(): SVGElement;
|
|
@@ -42,6 +59,8 @@ export default class SVGRenderer {
|
|
|
42
59
|
drawLine(x1: number, y1: number, x2: number, y2: number, parent: SVGElement): void;
|
|
43
60
|
drawRect(width: number, height: number, parent: SVGElement, options?: DrawRectOptions): SVGRectElement;
|
|
44
61
|
drawGlyph(glyphName: GlyphNames, parent: SVGElement, options?: DrawGlyphOptions): void;
|
|
62
|
+
drawCircle(cx: number, cy: number, radius: number, parent: SVGElement, options?: DrawCircleOptions): SVGCircleElement;
|
|
63
|
+
drawText(text: string, x: number, y: number, parent: SVGElement, options?: DrawTextOptions): SVGTextElement;
|
|
45
64
|
destroy(): void;
|
|
46
65
|
}
|
|
47
66
|
export {};
|
package/dist/constants.d.ts
CHANGED
|
@@ -17,3 +17,22 @@ export declare const HALF_NOTE_LEDGER_LINE_WIDTH = 12.5;
|
|
|
17
17
|
export declare const CHORD_MAX_CONSECUTIVE_ACCIDENTALS = 3;
|
|
18
18
|
export declare const staffParams: Record<StaffTypes, StaffParams>;
|
|
19
19
|
export declare const durationBeatValueMap: Record<Durations, number>;
|
|
20
|
+
export declare const GUITAR_STRING_COUNT_DEFAULT = 6;
|
|
21
|
+
export declare const GUITAR_FRET_COUNT_DEFAULT = 5;
|
|
22
|
+
export declare const GUITAR_STRING_SPACING = 22;
|
|
23
|
+
export declare const GUITAR_FRET_SPACING = 30;
|
|
24
|
+
export declare const GUITAR_DOT_RADIUS = 10;
|
|
25
|
+
export declare const GUITAR_MARKER_RADIUS = 6;
|
|
26
|
+
export declare const GUITAR_STRING_LABEL_OFFSET = 4;
|
|
27
|
+
export declare const GUITAR_STRING_LABEL_HEIGHT: number;
|
|
28
|
+
export declare const GUITAR_DIAGRAM_H_SPACING = 51;
|
|
29
|
+
export declare const GUITAR_DIAGRAM_V_SPACING = 12;
|
|
30
|
+
export declare const GUITAR_DIAGRAM_TOP_PADDING = 4;
|
|
31
|
+
export declare const GUITAR_DIAGRAM_BOTTOM_PADDING = 1;
|
|
32
|
+
export declare const GUITAR_NUT_THICKNESS = 4;
|
|
33
|
+
export declare const GUITAR_NUT_X_OFFSET = 1;
|
|
34
|
+
export declare const GUITAR_NUT_SPACE_ABOVE: number;
|
|
35
|
+
export declare const GUITAR_FONT_BASE = 16;
|
|
36
|
+
export declare const GUITAR_FONT_SMALL = 12;
|
|
37
|
+
export declare const GUITAR_LABEL_HEIGHT = 16;
|
|
38
|
+
export declare const GUITAR_FRET_LABEL_OFFSET_X = 2;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GuitarStringState } from '../types';
|
|
2
|
+
export declare function createStateStrings(frets: string[], fingers: string[]): GuitarStringState[];
|
|
3
|
+
export declare function calculateStartFret(fretParts: string[], fretCount: number): number;
|
|
4
|
+
export declare function parseFretsEntry(frets: string): string[];
|
|
5
|
+
export declare function parseFingersEntry(fingers: string): string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { default as MusicStaff } from './classes/MusicStaff';
|
|
2
2
|
export { default as RhythmStaff } from './classes/RhythmStaff';
|
|
3
3
|
export { default as ScrollingStaff } from './classes/ScrollingStaff';
|
|
4
|
+
export { default as GuitarChord } from './classes/GuitarChord';
|
|
4
5
|
export type { MusicStaffOptions } from './classes/MusicStaff';
|
|
5
6
|
export type { RhythmStaffOptions } from './classes/RhythmStaff';
|
|
6
7
|
export type { ScrollingStaffOptions } from './classes/ScrollingStaff';
|
|
8
|
+
export type { GuitarChordOptions } from './classes/GuitarChord';
|
|
7
9
|
export type { StaffTypes } from './types';
|
|
10
|
+
export type { GuitarChordDrawOptions, GuitarBarreDef } from './types';
|
package/dist/types.d.ts
CHANGED
|
@@ -14,3 +14,18 @@ export type KeySignatureDef = {
|
|
|
14
14
|
type: AccidentalType;
|
|
15
15
|
count: number;
|
|
16
16
|
};
|
|
17
|
+
export type GuitarStringState = {
|
|
18
|
+
fret: string;
|
|
19
|
+
finger: string;
|
|
20
|
+
};
|
|
21
|
+
export type GuitarBarreDef = {
|
|
22
|
+
fret: number;
|
|
23
|
+
fromString: number;
|
|
24
|
+
toString: number;
|
|
25
|
+
finger?: number;
|
|
26
|
+
};
|
|
27
|
+
export type GuitarChordDrawOptions = {
|
|
28
|
+
startFret?: number;
|
|
29
|
+
label?: string;
|
|
30
|
+
barres?: GuitarBarreDef[];
|
|
31
|
+
};
|