vector-score 1.0.3 → 1.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.
package/README.md CHANGED
@@ -3,42 +3,51 @@
3
3
  # Vector Score
4
4
  ![NPM Version](https://img.shields.io/npm/v/vector-score)
5
5
  [![Bundlephobia](https://img.shields.io/bundlephobia/minzip/vector-score)](https://bundlephobia.com/package/vector-score)
6
+ ![NPM Downloads](https://img.shields.io/npm/d18m/vector-score)
6
7
 
7
- A lightweight, SVG-based TypeScript library for rendering musical staves, notes, and rhythm patterns in the browser.
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
+
10
+ <br/>
8
11
 
9
12
  ## Features
10
13
 
11
- * **Multiple Staff Types**: Supports Treble, Bass, Alto, and Grand staves (MusicStaff and ScrollingStaff).
12
- * [**Music Staff**](#Standard-Music-Staff):Standard music staff for notation.
13
- * [**Rhythm Staff**](#Rhythm-Staff): Dedicated staff for rhythm exercises with customizable time signatures and bar handling.
14
- * [**Scrolling Staff**](#Scrolling-Staff) Staff made to allow for 'endless' style of notes.
15
- * **SVG Rendering**: Scalable Vector graphics suitable for any screen size.
16
- * **Flexible Note Input**: Simple string-based syntax for defining notes.
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**](#Standard-Music-Staff)
17
19
 
18
- ## Installation
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)
19
25
 
20
- ```bash
21
- npm i vector-score
22
- ````
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)
23
29
 
24
- ## Development
30
+ <br />
25
31
 
26
- To start the development server with a playground:
32
+ ## Notes
33
+
34
+ * Main targeting class for css is 'vs-svg-renderer-parent'
35
+ * Could be useful if needing to add in specific colors or styling to any SVG element rendered.
27
36
 
28
- ```bash
29
- npm run dev
30
- ```
31
37
 
32
- To build the library for production:
38
+ <br />
39
+
40
+ ## Installation
33
41
 
34
42
  ```bash
35
- npm run build
43
+ npm i vector-score
36
44
  ```
37
45
 
46
+ <br />
47
+
38
48
  ## Usage
39
49
 
40
50
  ### 1. Setup HTML
41
-
42
51
  Create a container element in your HTML where the staff will be rendered.
43
52
 
44
53
  ```html
@@ -46,8 +55,7 @@ Create a container element in your HTML where the staff will be rendered.
46
55
  ```
47
56
 
48
57
  ### 2. Import and Initialize
49
-
50
- ### Standard Music Staff
58
+ Import desired class (MusicStaff, GuitarChord, etc.). Declare variable with reference to container element. Pass in options for specific class (options are typed).
51
59
 
52
60
  ```typescript
53
61
  import { MusicStaff } from 'vector-score';
@@ -58,7 +66,8 @@ const staff = new MusicStaff(container, {
58
66
  staffType: 'treble', // 'treble', 'bass', 'alto', or 'grand'
59
67
  width: 400,
60
68
  scale: 1.2,
61
- spaceBelow: 1
69
+ spaceBelow: 1,
70
+ keySignature: "Bb"
62
71
  });
63
72
 
64
73
  // Draw a C Minor scale (quarter notes)
@@ -71,10 +80,17 @@ staff.drawChord(['C4w', 'E4w', 'G4w']);
71
80
  // Evenly space all notes on the staff
72
81
  staff.justifyNotes();
73
82
  ```
74
- #### Resulting Staff
83
+
84
+ ### Resulting Staff
75
85
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/MusicStaffTrebleResult.svg)
76
86
 
77
- ### Grand Staff
87
+ <br/>
88
+
89
+ ## Grand Staff
90
+
91
+ See [**Note String Syntax**](#Note-String-Syntax) to see how to write notes on music staff (i.e. ['G4q', 'E4h', 'C4w', "A3h", "F3h"] )
92
+
93
+ See [**MusicStaffOptions**](#MusicStaffOptions) to see how configuration options during class instantiation.
78
94
 
79
95
  ```typescript
80
96
  import { MusicStaff } from 'vector-score';
@@ -91,10 +107,51 @@ grandStaff.drawNote(['G4q', 'E4h', 'C4w', "A3h", "F3h"]);
91
107
 
92
108
  grandStaff.drawChord(["G3w", "C4w", "E4w"]);
93
109
  ```
94
- #### Resulting Staff
110
+ ### Resulting Staff
95
111
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/MusicStaffGrandResult.svg)
96
112
 
97
- ### Rhythm Staff
113
+ <br/>
114
+
115
+ ## Guitar Chords
116
+
117
+ 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"`).
118
+
119
+ See [**GuitarChordOptions**](#GuitarChordOptions) to see how configuration options during class instantiation.
120
+
121
+ ```typescript
122
+ import { GuitarChord } from 'vector-score';
123
+
124
+ const grandStaff = new GuitarChord(container, {
125
+ fretCount: 5,
126
+ stringCount: 6,
127
+ stringLabels: ["E", "A", "D", "G", "B", "E"],
128
+ width: 300,
129
+ scale: 1,
130
+ color: "var(--font-color)",
131
+ backgroundColor: "var(--bg-color)"
132
+ });
133
+
134
+ // C chord
135
+ guitarChordsSection.addChord("x32010", "032010", {
136
+ label: "C",
137
+ });
138
+
139
+ // Bbmaj7 Barre Chord (Automatically calculates the starting fret and barre positioning)
140
+ const frets = "x13231";
141
+ const fingers = "013241";
142
+ const barres = guitarChordsSection.determineBarreOptions(frets, fingers, [1]);
143
+
144
+ guitarChordsSection.addChord(frets, fingers, {
145
+ label: "Bbmaj7",
146
+ barres: barres
147
+ });
148
+ ```
149
+ ### Result
150
+ ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/GuitarChordsResult.svg)
151
+
152
+ <br />
153
+
154
+ ## Rhythm Staff
98
155
 
99
156
  ```typescript
100
157
  import { RhythmStaff } from 'vector-score';
@@ -120,10 +177,12 @@ rhythm.drawNote(['q', 'q']);
120
177
  // Increment the UI to show the first beat in the bar
121
178
  rhythm.incrementCurrentBeatUI();
122
179
  ```
123
- #### Resulting Staff
180
+ ### Resulting Staff
124
181
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/RhythmStaffResult.svg)
125
182
 
126
- ### Scrolling Staff
183
+ <br />
184
+
185
+ ## Scrolling Staff
127
186
 
128
187
  ```typescript
129
188
  import { ScrollingStaff } from 'vector-score';
@@ -163,9 +222,11 @@ scrollingStaff.queueNotes([
163
222
 
164
223
  // The button event listener calls 'advanceNotes()' to move the notes over, one step at a time.
165
224
  ```
166
- #### Resulting Staff
225
+ ### Resulting Staff
167
226
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/ScrollingStaffResult.webp)
168
227
 
228
+ <br />
229
+
169
230
  ## Note String Syntax
170
231
 
171
232
  Notes are defined using a specific string format parsed by the library:
@@ -186,6 +247,35 @@ Notes are defined using a specific string format parsed by the library:
186
247
  * `F#5q`: F Sharp, Octave 5, Quarter note
187
248
  * `Bb3e`: B Flat, Octave 3, Eighth note
188
249
 
250
+ <br />
251
+
252
+ ## Guitar String Syntax
253
+
254
+ 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).
255
+
256
+ ### Frets String format: `[xX\da-zA-Z]+`
257
+ * `x` or `X`: Muted string.
258
+ * `0`: Open string.
259
+ * `1-9`: Fretted at the specified fret.
260
+ * `a-z` / `A-Z`: Base-36 alphanumeric encoding for double-digit frets (e.g., `a` = 10, `b` = 11, `c` = 12).
261
+
262
+ ### Fingers String format: `[\d]+`
263
+ * `0`: No finger labeled.
264
+ * `1-9`: Finger number to display on the dot.
265
+
266
+ **Example:**
267
+ * `guitarChordsSection.addChord("x32010", "032010")`: Displays an open C major chord.
268
+ * The lowest string is muted (`x`) and has no finger label (`0`).
269
+ * The A string is played at the 3rd fret (`3`) with the 3rd finger (`3`).
270
+ * *Note: The `startFret` option is now automatically calculated based on the lowest fretted note if left undefined.*
271
+
272
+ ### Barre Lines
273
+ Barre lines can be added dynamically using the built-in helper method, `determineBarreOptions(frets, fingers, barreFrets)`.
274
+ * Pass in your fret string, finger string, and an array of the target frets you wish to barre.
275
+ * 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.
276
+
277
+ <br />
278
+
189
279
  ## API Reference
190
280
 
191
281
  ### MusicStaff Class
@@ -200,6 +290,22 @@ Notes are defined using a specific string format parsed by the library:
200
290
  | `changeChordByIndex(notes: string[], index: number)` | Replaces a chord at a specific index with a new chord. |
201
291
  | `destroy()` | Destroys internal arrays and elements |
202
292
 
293
+ <br/>
294
+
295
+ ### GuitarChord Class
296
+
297
+ | Method | Description |
298
+ | :--- | :--- |
299
+ | `addChord(frets: string, fingers: string, options?: GuitarChordDrawOptions)` | Draws notes on the diagram using string configurations. Options include manual `startFret`, `label`, and `barres`. |
300
+ | `modifyChordByIndex(frets: string, fingers: string, chordIndex: number, options?: GuitarChordDrawOptions)` | Modifies the chord at the specified index with new definitions and options. |
301
+ | `determineBarreOptions(frets: string, fingers: string, barreFrets: number[])` | Automatically calculates barre line dimensions based on fingering and returns `GuitarBarreDef[]` to be used in chord options. |
302
+ | `removeChordByIndex(chordIndex: number)` | Removes the chord diagram at the specified index and recalculates layout. |
303
+ | `clearAllChords()` | Removes all chords in the container. |
304
+ | `destroy()` | Destroys internal arrays and elements. |
305
+
306
+
307
+ <br/>
308
+
203
309
  ### RhythmStaff Class
204
310
 
205
311
  | Method | Description |
@@ -212,6 +318,8 @@ Notes are defined using a specific string format parsed by the library:
212
318
  | `resetCurrentBeatUI()` | Must be called if current beat goes over the total beats in the bar to reset its state |
213
319
  | `destroy()` | Destroys internal arrays and elements |
214
320
 
321
+ <br/>
322
+
215
323
  ### ScrollingStaff Class
216
324
 
217
325
  | Method | Description |
@@ -221,18 +329,30 @@ Notes are defined using a specific string format parsed by the library:
221
329
  | `clearAllNote()` | Clears all notes on the staff |
222
330
  | `destroy()` | Destroys internal arrays and elements |
223
331
 
332
+ <br />
333
+
224
334
  ## Configuration Options
225
335
 
226
336
  ### MusicStaffOptions
227
337
  * `width`: Total width of the SVG in pixels.
228
338
  * `scale`: Zoom factor (default: 1).
229
- * `noteStartX`: Position where notes start to draw.
230
339
  * `staffType`: `'treble' | 'bass' | 'alto' | 'grand'`.
340
+ * `keySignature`: Change key signature to display on the staff.
231
341
  * `spaceAbove`: Padding units above the staff (in staff line spaces).
232
342
  * `spaceBelow`: Padding units below the staff (in staff line spaces).
343
+ * `noteStartX`: Position where notes start to draw.
233
344
  * `staffColor`: CSS color string for lines and notes.
234
345
  * `staffBackgroundColor`: CSS color string for background.
235
346
 
347
+ ### GuitarChordOptions
348
+ * `stringCount`: Amount of strings to show in diagram, default is 6.
349
+ * `fretCount`: Amount of frets to show in diagram, default is 5.
350
+ * `stringLabels`: Labels to show under each string in each chord diagram. Provided string values will display in order of strings in this array value.
351
+ * `width`: Total width of the SVG in pixels.
352
+ * `scale`: Zoom factor (default: 1).
353
+ * `color`: CSS color string for lines and notes.
354
+ * `backgroundColor`: CSS color string for background.
355
+
236
356
  ### RhythmStaffOptions
237
357
  * `topNumber`: The top number of the time signature (e.g., 4 for 4/4 time).
238
358
  * `barsCount`: Number of measures to draw.
@@ -0,0 +1,106 @@
1
+ import { GuitarBarreDef, GuitarChordDrawOptions } from '../types';
2
+ export type GuitarChordOptions = {
3
+ width?: number;
4
+ scale?: number;
5
+ stringCount?: number;
6
+ fretCount?: number;
7
+ stringLabels?: string[];
8
+ color?: string;
9
+ backgroundColor?: string;
10
+ };
11
+ export default class GuitarChord {
12
+ private svgRendererInstance;
13
+ private options;
14
+ private chordEntries;
15
+ private cursorX;
16
+ private cursorY;
17
+ private readonly diagramWidth;
18
+ private readonly diagramHeight;
19
+ private readonly gridTopY;
20
+ private readonly rowHeight;
21
+ /**
22
+ * Creates an instance of a GuitarChord diagram renderer.
23
+ *
24
+ * @param rootElementCtx - The element (div) reference that the chord diagram(s) will be appended to.
25
+ * @param options - Optional configuration. Can adjust total width, scale, string/fret count, and coloring.
26
+ * All config options are in the type GuitarChordOptions.
27
+ */
28
+ constructor(rootElementCtx: HTMLElement, options?: GuitarChordOptions);
29
+ private drawStringDots;
30
+ private drawStringLabels;
31
+ private drawBarre;
32
+ private renderChordDiagram;
33
+ private relayoutChords;
34
+ /**
35
+ * Adds a new chord diagram. Diagrams are placed left-to-right in the order added, wrapping to a
36
+ * new row automatically once the configured width is exceeded.
37
+ *
38
+ * @param frets - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
39
+ * * `x` - muted string
40
+ * * `0` - open string
41
+ * * `1...n` - fretted at the given absolute fret number (e.g. `3`)
42
+ * @param fingers - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
43
+ * * `0` - No finger labeled
44
+ * * `1...n` - Finger labeled as number provided
45
+ *
46
+ * @param options - Optional per-chord settings: `startFret` (default `1`, for diagrams higher up the neck)
47
+ * and `label` (a chord name drawn above the diagram).
48
+ *
49
+ * @returns The index of the newly added chord, for later use with the CRUD-by-index methods.
50
+ *
51
+ * @throws {Error} If fret or finger's string length doesn't match the configured string count.
52
+ *
53
+ * @example
54
+ * // Draw an open C major chord
55
+ * guitarChord.addChord("x32010", "032010", { label: "C" });
56
+ */
57
+ addChord(frets: string, fingers: string, options?: GuitarChordDrawOptions): number;
58
+ /**
59
+ * Replaces the chord diagram at the specified index with a new one, in place.
60
+ *
61
+ * @param frets - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
62
+ * * `x` - muted string
63
+ * * `0` - open string
64
+ * * `1...n` - fretted at the given absolute fret number (e.g. `3`)
65
+ * @param fingers - A string, with each value being ordered low-to-high (e.g. first position in string 0 is the low E string)
66
+ * * `0` - No finger labeled
67
+ * * `1...n` - Finger labeled as number provided
68
+ *
69
+ * @param chordIndex - The index of the chord to replace (as returned by addChord).
70
+ *
71
+ * @param options - Optional per-chord settings, see addChord.
72
+ *
73
+ * @returns void
74
+ *
75
+ * @throws {Error} If the index is out of bounds, or if chordDef is invalid (see addChord).
76
+ *
77
+ * @example
78
+ * // Change chord at index 0 to a D major chord
79
+ * guitarChord.modifyChordByIndex("xx0232", "000132", 0, { label: "D" });
80
+ *
81
+ */
82
+ modifyChordByIndex(frets: string, fingers: string, chordIndex: number, options?: GuitarChordDrawOptions): void;
83
+ /**
84
+ * Removes the chord diagram at the specified index. Remaining chords are re-flowed to close the gap.
85
+ * @param chordIndex - The index of the chord to remove.
86
+ * @returns void
87
+ * @throws {Error} If the index is out of bounds.
88
+ */
89
+ removeChordByIndex(chordIndex: number): void;
90
+ /**
91
+ * Removes all chord diagrams and resets internal positioning.
92
+ * @returns void
93
+ */
94
+ clearAllChords(): void;
95
+ /**
96
+ * * Used to automatically determine options for creating barre lines.
97
+ * * The returned value then can be used in addChord and modifyChord methods.
98
+ * @returns GuitarBarreDef[]
99
+ */
100
+ determineBarreOptions(frets: string, fingers: string, barreFrets: number[]): GuitarBarreDef[];
101
+ /**
102
+ * Removes the root svg element and cleans up arrays.
103
+ * @returns void
104
+ */
105
+ destroy(): void;
106
+ }
@@ -4,6 +4,7 @@ export type MusicStaffOptions = {
4
4
  scale?: number;
5
5
  noteStartX?: number;
6
6
  staffType?: StaffTypes;
7
+ keySignature?: string;
7
8
  spaceAbove?: number;
8
9
  spaceBelow?: number;
9
10
  staffColor?: string;
@@ -24,6 +25,7 @@ export default class MusicStaff {
24
25
  * @param options - Optional configuration settings. Can adjust staff type (treble, bass, alto, grand), width, scale, spaces above/below, etc. All config options are in the type MusicStaffOptions
25
26
  */
26
27
  constructor(rootElementCtx: HTMLElement, options?: MusicStaffOptions);
28
+ private createKeySignature;
27
29
  /**
28
30
  * Draws a note on the staff.
29
31
  * @param notes - A single string OR array of note strings in the format `[Root][Accidental?][Octave][Duration?]`.
@@ -17,6 +17,18 @@ type DrawRectOptions = {
17
17
  x?: number;
18
18
  y?: number;
19
19
  fill?: string;
20
+ rx?: number;
21
+ };
22
+ type DrawCircleOptions = {
23
+ filled?: boolean;
24
+ fill?: string;
25
+ strokeWidth?: number;
26
+ };
27
+ type DrawTextOptions = {
28
+ fontSize?: number;
29
+ anchor?: "start" | "middle" | "end";
30
+ fill?: string;
31
+ fontWeight?: string;
20
32
  };
21
33
  export default class SVGRenderer {
22
34
  private rootElementRef;
@@ -35,6 +47,7 @@ export default class SVGRenderer {
35
47
  commitElementsToDOM(elements: SVGElement[] | SVGElement, parent?: HTMLElement | SVGElement): void;
36
48
  getLayerByName(name: LayerNames): SVGGElement;
37
49
  addTotalRootSvgHeight(amount: number): void;
50
+ setTotalRootSvgHeight(amount: number): void;
38
51
  addTotalRootSvgYOffset(amount: number): void;
39
52
  applySizingToRootSvg(): void;
40
53
  get rootSvgElement(): SVGElement;
@@ -42,6 +55,8 @@ export default class SVGRenderer {
42
55
  drawLine(x1: number, y1: number, x2: number, y2: number, parent: SVGElement): void;
43
56
  drawRect(width: number, height: number, parent: SVGElement, options?: DrawRectOptions): SVGRectElement;
44
57
  drawGlyph(glyphName: GlyphNames, parent: SVGElement, options?: DrawGlyphOptions): void;
58
+ drawCircle(cx: number, cy: number, radius: number, parent: SVGElement, options?: DrawCircleOptions): SVGCircleElement;
59
+ drawText(text: string, x: number, y: number, parent: SVGElement, options?: DrawTextOptions): SVGTextElement;
45
60
  destroy(): void;
46
61
  }
47
62
  export {};
@@ -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 = 40;
29
+ export declare const GUITAR_DIAGRAM_V_SPACING = 16;
30
+ export declare const GUITAR_DIAGRAM_BOTTOM_PADDING = 1;
31
+ export declare const GUITAR_NUT_THICKNESS = 4;
32
+ export declare const GUITAR_NUT_X_OFFSET = 1;
33
+ export declare const GUITAR_NUT_SPACE_ABOVE: number;
34
+ export declare const GUITAR_LABEL_FONT_SIZE = 16;
35
+ export declare const GUITAR_FINGER_FONT_SIZE = 14;
36
+ export declare const GUITAR_FRET_LABEL_FONT_SIZE = 14;
37
+ export declare const GUITAR_LABEL_HEIGHT = 16;
38
+ export declare const GUITAR_FRET_LABEL_OFFSET_X: number;
@@ -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[];
@@ -0,0 +1,9 @@
1
+ import { default as SVGRenderer } from '../classes/SVGRenderer';
2
+ import { StaffStrategy } from '../strategies/StrategyInterface';
3
+ import { AccidentalType, KeySignatureDef, NoteNames, StaffTypes } from '../types';
4
+ export declare const KEY_SIGNATURE_START_X = 40;
5
+ export declare const KEY_SIGNATURE_ORDER: Record<AccidentalType, NoteNames[]>;
6
+ export declare const KEY_SIGNATURES: Record<string, KeySignatureDef>;
7
+ export declare const KEY_SIG_OCTAVES: Record<StaffTypes, Record<AccidentalType, number[]>>;
8
+ export declare function parseKeySignature(key: string): KeySignatureDef;
9
+ export declare function drawKeySignature(svgRenderer: SVGRenderer, strategy: StaffStrategy, key: string, startX: number): number;
@@ -4,6 +4,5 @@ export declare function parseNoteString(noteString: string): NoteObj;
4
4
  export declare function parseDurationNoteString(note: string): Durations;
5
5
  export declare function parseRestString(rest: string): Durations;
6
6
  export declare function getGlyphNameByClef(clef: string): GlyphNames;
7
- export declare function getNoteSpacingFromReference(referenceNote: NoteObj, targetNote: NoteObj): number;
8
7
  export declare function noteToAbsoluteSemitone(note: NoteObj): number;
9
- export declare function getNameOctaveIdx(name: string, octave: number): number;
8
+ export declare function getNoteSpacingFromReference(referenceNote: Pick<NoteObj, "name" | "octave">, targetNote: Pick<NoteObj, "name" | "octave">): number;
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';
@@ -1,14 +1,16 @@
1
1
  import { default as SVGRenderer } from '../classes/SVGRenderer';
2
- import { NoteObj, StaffTypes } from '../types';
2
+ import { AccidentalType, NoteObj, StaffTypes } from '../types';
3
3
  import { LedgerLineEntry, StaffStrategy } from './StrategyInterface';
4
4
  export default class GrandStaffStrategy implements StaffStrategy {
5
5
  private params;
6
6
  private rendererRef;
7
7
  private width;
8
+ private trebleStaffHeight;
8
9
  constructor(rendererRef: SVGRenderer, staffType: StaffTypes);
9
10
  private drawStaffLines;
10
11
  drawStaff: (width: number) => void;
11
12
  shouldNoteFlip(noteYPos: number): boolean;
12
13
  getLedgerLinesX(note: Omit<NoteObj, "accidental">, yPos: number): LedgerLineEntry[];
13
14
  calculateNoteYPos: (note: Omit<NoteObj, "accidental">) => number;
15
+ getKeySignatureYPositions(type: AccidentalType, count: number): number[][];
14
16
  }
@@ -1,5 +1,5 @@
1
1
  import { default as SVGRenderer } from '../classes/SVGRenderer';
2
- import { NoteObj, StaffTypes } from '../types';
2
+ import { AccidentalType, NoteObj, StaffTypes } from '../types';
3
3
  import { LedgerLineEntry, StaffStrategy } from './StrategyInterface';
4
4
  export default class SingleStaffStrategy implements StaffStrategy {
5
5
  private params;
@@ -9,4 +9,5 @@ export default class SingleStaffStrategy implements StaffStrategy {
9
9
  shouldNoteFlip(noteYPos: number): boolean;
10
10
  getLedgerLinesX(note: Omit<NoteObj, "accidental">, yPos: number): LedgerLineEntry[];
11
11
  calculateNoteYPos: (note: Omit<NoteObj, "accidental">) => number;
12
+ getKeySignatureYPositions(type: AccidentalType, count: number): number[][];
12
13
  }
@@ -1,9 +1,10 @@
1
- import { NoteObj, StaffTypes } from '../types';
1
+ import { AccidentalType, NoteObj, StaffTypes } from '../types';
2
2
  export interface StaffStrategy {
3
3
  drawStaff(width: number): void;
4
4
  calculateNoteYPos(note: Omit<NoteObj, "accidental">): number;
5
5
  getLedgerLinesX(note: Omit<NoteObj, "accidental">, yPos: number): LedgerLineEntry[];
6
6
  shouldNoteFlip(noteYPos: number): boolean;
7
+ getKeySignatureYPositions(type: AccidentalType, count: number): number[][];
7
8
  }
8
9
  export type StaffParams = {
9
10
  staffType: StaffTypes;
package/dist/types.d.ts CHANGED
@@ -9,3 +9,23 @@ export type NoteNames = 'C' | 'D' | 'E' | 'F' | 'G' | 'A' | 'B';
9
9
  export type Durations = 'w' | 'h' | 'q' | 'e' | 's';
10
10
  export type Accidentals = '#' | 'b' | '##' | 'bb' | 'n';
11
11
  export type DurationsBeatValues = 4 | 2 | 1 | 0.5;
12
+ export type AccidentalType = "sharp" | "flat";
13
+ export type KeySignatureDef = {
14
+ type: AccidentalType;
15
+ count: number;
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
+ };