vector-score 1.2.1 → 1.3.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
@@ -1,4 +1,6 @@
1
- ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/vector-score-icon.svg)
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/vector-score-icon.svg" alt="Vector Score Logo" />
3
+ </p>
2
4
 
3
5
  # Vector Score
4
6
  ![NPM Version](https://img.shields.io/npm/v/vector-score)
@@ -7,7 +9,8 @@
7
9
 
8
10
  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
11
 
10
- <br/>
12
+ [**See CSS class styling guide**](#Notes)
13
+
11
14
 
12
15
  ## Features
13
16
 
@@ -27,7 +30,6 @@ A lightweight, SVG-based TypeScript library for rendering simple musical notatio
27
30
  * Dedicated staff for rhythm exercises with customizable time signatures and bar handling. [**Go to Rhythm Staff**](#Rhythm-Staff)
28
31
  * Staff made to allow for 'endless' style of notes. [**Go to Scrolling Staff**](#Scrolling-Staff)
29
32
 
30
- <br />
31
33
 
32
34
  ## Usage
33
35
 
@@ -51,7 +53,7 @@ const staff = new MusicStaff(container, {
51
53
  width: 400,
52
54
  scale: 1.2,
53
55
  spaceBelow: 1,
54
- keySignature: "Bb"
56
+ keySignature: "Bb",
55
57
  });
56
58
 
57
59
  // Draw a C Minor scale (quarter notes)
@@ -59,33 +61,88 @@ staff.drawNote(['C4q', 'D4q', 'Eb4q', 'F4q', 'G4q', 'Ab4q', 'Bb4q', 'C5q']);
59
61
  staff.justifyNotes();
60
62
  ```
61
63
 
62
- ### Resulting Staff
63
- ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/MusicStaffTrebleResult.svg)
64
-
65
- <br/>
66
64
 
67
65
  ## Notes
68
66
 
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
67
+ ### CSS Classes & Theming
68
+ The GuitarChord diagram uses CSS classes for styling. All elements that can be targeted for theming are prefixed with `.vs-`.
69
+
70
+ #### General SVG Classes
71
+ * `svg.vs-svg-renderer-root`: The root SVG element.
72
+ * `g.vs-svg-renderer-parent`: The main parent group element containing all drawn elements.
73
+
74
+ #### Staff Theming
75
+ * `.vs-staff-layer`: The layer containing the staff lines, clef, and time signature.
76
+ * `.vs-notes-layer`: The layer containing all notes, chords, stems, and rests.
77
+ * `.vs-ui-layer`: Contains UI elements like the RhythmStaff beat tracker.
78
+ * `vs-rhythm-current-beat`: Targets the highlighting rectangle for the current beat in the RhythmStaff. Also possible to add in transition animation on `x` property.
79
+
80
+ #### Guitar Chord Theming
81
+ The `GuitarChord` class is entirely styled via CSS. Here are the specific layout targets:
82
+ * **Text & Labels:**
83
+ * `.vs-guitar-text`: Base class for all text elements in the diagram.
84
+ * `.vs-guitar-diagram-label`: The chord name label above the diagram.
85
+ * `.vs-guitar-fret-label`: The fret number indicator (e.g., "5fr").
86
+ * `.vs-guitar-fret-text`: The finger numbers inside the dots and barres.
87
+ * **Grid Lines:**
88
+ * `.vs-guitar-group-fret-lines`: The horizontal fret lines and the top nut.
89
+ * `.vs-guitar-group-string-lines`: The vertical string lines.
90
+ * **Dots & Markers:**
91
+ * `.vs-guitar-fret-muted`: The 'X' markers for muted strings above the nut.
92
+ * `.vs-guitar-fret-open`: The 'O' outline markers for open strings above the nut.
93
+ * `.vs-guitar-fret-dot`: The parent group for fretted dots.
94
+ * `.vs-guitar-fret-circle`: The actual SVG circle shape for a fretted note.
95
+ * **Barres:**
96
+ * `.vs-guitar-group-barre`: The group containing the elements for the barre line.
97
+ * `.vs-guitar-barre`: The rectangle element spanning across strings for barre chords.
98
+
99
+ #### Scrolling Staff Theming
100
+ * `g.vs-scrolling-notes-layer > g`: Targets the scrolling staff's notes, where a transition property can be added for smooth animation.
101
+
102
+
103
+ **Example: Custom Staff Theme Implementation**
104
+ ```css
105
+ /* Adds background color to root SVG element */
106
+ svg.vs-svg-renderer-root {
107
+ background-color: white;
108
+ }
109
+
110
+ /* Set base staff color */
111
+ .vs-staff-layer,
112
+ .vs-notes-layer {
113
+ color: #d4d4d8;
114
+ }
115
+
116
+ /* Animate current beat rect UI */
117
+ .vs-rhythm-current-beat {
118
+ transition: x 0.2s ease-in
119
+ }
120
+ ```
80
121
 
122
+ **Example: Custom Guitar Chord Theme Implementation**
81
123
  ```css
82
- /* Target and change the fret dot colors */
83
- .vs-guitar-fret-dot {
84
- fill: oklch(67% 0.05 240.864);
124
+ /* Set base grid colors */
125
+ .vs-guitar-group-fret-lines,
126
+ .vs-guitar-group-string-lines {
127
+ color: #d4d4d8;
85
128
  }
86
- ```
87
129
 
88
- <br />
130
+ /* Format the text labels */
131
+ .vs-guitar-text { fill: #1a1827; }
132
+ .vs-guitar-fret-text { fill: #ffffff; }
133
+
134
+ /* Style the open/muted markers */
135
+ .vs-guitar-fret-muted { color: #dc2626; }
136
+ .vs-guitar-fret-open { color: #3b82f6; }
137
+
138
+ /* Apply alternating fret dot colors */
139
+ .vs-guitar-fret-dot { color: oklch(50% 0.05 220); }
140
+
141
+ .vs-guitar-fret-dot:nth-child(odd of .vs-guitar-fret-dot) { color: oklch(60% 0.25 200); }
142
+
143
+ /* Style the barre */
144
+ .vs-guitar-barre { fill: #1e40af; }
145
+ ```
89
146
 
90
147
  ## Grand Staff
91
148
 
@@ -111,7 +168,6 @@ grandStaff.drawChord(["G3w", "C4w", "E4w"]);
111
168
  ### Resulting Staff
112
169
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/MusicStaffGrandResult.svg)
113
170
 
114
- <br/>
115
171
 
116
172
  ## Guitar Chords
117
173
 
@@ -125,11 +181,10 @@ import { GuitarChord } from 'vector-score';
125
181
  const grandStaff = new GuitarChord(container, {
126
182
  fretCount: 5,
127
183
  stringCount: 6,
128
- stringLabels: ["E", "A", "D", "G", "B", "E"],
129
- inlineChordsAmount: 2, // Choose how many chords are in a single line
184
+ stringLabels: ["E", "A", "D", "G", "B", "E"], // Labels under each string, in order
185
+ inlineChordsAmount: 4, // Choose how many chords are in a single line
186
+ centerChords: true, // Centers the diagrams inside their rows
130
187
  scale: 1,
131
- color: "var(--font-color)",
132
- backgroundColor: "white"
133
188
  });
134
189
 
135
190
  // C chord
@@ -150,7 +205,6 @@ guitarChordsSection.addChord(frets, fingers, {
150
205
  ### Result
151
206
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/GuitarChordsResult.svg)
152
207
 
153
- <br />
154
208
 
155
209
  ## Rhythm Staff
156
210
 
@@ -181,7 +235,6 @@ rhythm.incrementCurrentBeatUI();
181
235
  ### Resulting Staff
182
236
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/RhythmStaffResult.svg)
183
237
 
184
- <br />
185
238
 
186
239
  ## Scrolling Staff
187
240
 
@@ -226,7 +279,6 @@ scrollingStaff.queueNotes([
226
279
  ### Resulting Staff
227
280
  ![Alt Text](https://raw.githubusercontent.com/DrakeB1234/VectorScore/master/public/ScrollingStaffResult.webp)
228
281
 
229
- <br />
230
282
 
231
283
  ## Note String Syntax
232
284
 
@@ -248,7 +300,6 @@ Notes are defined using a specific string format parsed by the library:
248
300
  * `F#5q`: F Sharp, Octave 5, Quarter note
249
301
  * `Bb3e`: B Flat, Octave 3, Eighth note
250
302
 
251
- <br />
252
303
 
253
304
  ## Guitar String Syntax
254
305
 
@@ -275,7 +326,6 @@ Barre lines can be added dynamically using the built-in helper method, `determin
275
326
  * Pass in your fret string, finger string, and an array of the target frets you wish to barre.
276
327
  * 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
328
 
278
- <br />
279
329
 
280
330
  ## API Reference
281
331
 
@@ -291,7 +341,6 @@ Barre lines can be added dynamically using the built-in helper method, `determin
291
341
  | `changeChordByIndex(notes: string[], index: number)` | Replaces a chord at a specific index with a new chord. |
292
342
  | `destroy()` | Destroys internal arrays and elements |
293
343
 
294
- <br/>
295
344
 
296
345
  ### GuitarChord Class
297
346
 
@@ -305,7 +354,6 @@ Barre lines can be added dynamically using the built-in helper method, `determin
305
354
  | `destroy()` | Destroys internal arrays and elements. |
306
355
 
307
356
 
308
- <br/>
309
357
 
310
358
  ### RhythmStaff Class
311
359
 
@@ -319,7 +367,6 @@ Barre lines can be added dynamically using the built-in helper method, `determin
319
367
  | `resetCurrentBeatUI()` | Must be called if current beat goes over the total beats in the bar to reset its state |
320
368
  | `destroy()` | Destroys internal arrays and elements |
321
369
 
322
- <br/>
323
370
 
324
371
  ### ScrollingStaff Class
325
372
 
@@ -330,7 +377,6 @@ Barre lines can be added dynamically using the built-in helper method, `determin
330
377
  | `clearAllNote()` | Clears all notes on the staff |
331
378
  | `destroy()` | Destroys internal arrays and elements |
332
379
 
333
- <br />
334
380
 
335
381
  ## Configuration Options
336
382
 
@@ -342,18 +388,18 @@ Barre lines can be added dynamically using the built-in helper method, `determin
342
388
  * `spaceAbove`: Padding units above the staff (in staff line spaces).
343
389
  * `spaceBelow`: Padding units below the staff (in staff line spaces).
344
390
  * `noteStartX`: Position where notes start to draw.
345
- * `staffColor`: CSS color string for lines and notes.
346
- * `staffBackgroundColor`: CSS color string for background.
391
+ * `svgAutoFill`: Sets inline styles on root SVG element to allow for screen scaling (default: true).
392
+
347
393
 
348
394
  ### GuitarChordOptions
349
395
  * `stringCount`: Amount of strings to show in diagram, default is 6.
350
396
  * `fretCount`: Amount of frets to show in diagram, default is 5.
351
397
  * `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
398
  * `inlineChordsAmount`: Max amount of chords to display on a single line (default: 2).
399
+ * `centerChords`: Boolean to center the chord diagrams on their respective rows (default: true).
353
400
  * `scale`: Zoom factor (default: 1).
354
- * `color`: CSS color string for lines and notes.
355
- * `backgroundColor`: CSS color string for background.
356
401
  * `width`: Total width of the SVG in pixels, overrides inlineChordAmount auto width calculation (default: undefined).
402
+ * `svgAutoFill`: Sets inline styles on root SVG element to allow for screen scaling (default: true).
357
403
 
358
404
  ### RhythmStaffOptions
359
405
  * `topNumber`: The top number of the time signature (e.g., 4 for 4/4 time).
@@ -369,6 +415,7 @@ Barre lines can be added dynamically using the built-in helper method, `determin
369
415
  * `staffColor`: CSS color string for lines and notes.
370
416
  * `staffBackgroundColor`: CSS color string for background.
371
417
  * `currentBeatUIColor`: CSS color string for current beat UI indicator.
418
+ * `svgAutoFill`: Sets inline styles on root SVG element to allow for screen scaling (default: true).
372
419
 
373
420
  ### ScrollingStaffOptions
374
421
  * `width`: Total width of the SVG in pixels.
@@ -380,3 +427,4 @@ Barre lines can be added dynamically using the built-in helper method, `determin
380
427
  * `staffColor`: CSS color string for lines and notes.
381
428
  * `staffBackgroundColor`: CSS color string for background.
382
429
  * `onNotesOut`: Callback function for when there are no more notes on the staff to advance.
430
+ * `svgAutoFill`: Sets inline styles on root SVG element to allow for screen scaling (default: true).
@@ -2,12 +2,12 @@ import { GuitarBarreDef, GuitarChordDrawOptions } from '../types';
2
2
  export type GuitarChordOptions = {
3
3
  width?: number;
4
4
  inlineChordsAmount?: number;
5
+ centerChords?: boolean;
5
6
  scale?: number;
6
7
  stringCount?: number;
7
8
  fretCount?: number;
8
9
  stringLabels?: string[];
9
- color?: string;
10
- backgroundColor?: string;
10
+ svgAutoFill?: boolean;
11
11
  };
12
12
  export default class GuitarChord {
13
13
  private svgRendererInstance;
@@ -7,8 +7,7 @@ export type MusicStaffOptions = {
7
7
  keySignature?: string;
8
8
  spaceAbove?: number;
9
9
  spaceBelow?: number;
10
- staffColor?: string;
11
- staffBackgroundColor?: string;
10
+ svgAutoFill?: boolean;
12
11
  };
13
12
  export default class MusicStaff {
14
13
  private svgRendererInstance;
@@ -5,9 +5,7 @@ export type RhythmStaffOptions = {
5
5
  barsCount?: number;
6
6
  spaceAbove?: number;
7
7
  spaceBelow?: number;
8
- staffColor?: string;
9
- staffBackgroundColor?: string;
10
- currentBeatUIColor?: string;
8
+ svgAutoFill?: boolean;
11
9
  };
12
10
  export default class RhythmStaff {
13
11
  private rendererInstance;
@@ -4,15 +4,17 @@ type SVGRendererOptions = {
4
4
  width: number;
5
5
  height: number;
6
6
  scale: number;
7
- staffColor: string;
8
- staffBackgroundColor: string;
9
7
  useGlyphs: GlyphNames[];
8
+ svgAutoFill: boolean;
10
9
  };
11
- type LayerNames = 'staff' | 'notes' | 'ui';
12
10
  type DrawGlyphOptions = {
13
11
  yOffset?: number;
14
12
  xOffset?: number;
15
13
  };
14
+ type DrawLineOptions = {
15
+ strokeWidth?: number;
16
+ classes?: string | string[];
17
+ };
16
18
  type DrawRectOptions = {
17
19
  x?: number;
18
20
  y?: number;
@@ -29,6 +31,7 @@ type DrawCircleOptions = {
29
31
  type DrawTextOptions = {
30
32
  fontSize?: number;
31
33
  anchor?: "start" | "middle" | "end";
34
+ baseline?: "central";
32
35
  fill?: string;
33
36
  fontWeight?: string;
34
37
  classes?: string | string[];
@@ -37,9 +40,7 @@ export default class SVGRenderer {
37
40
  private rootElementRef;
38
41
  private svgElementRef;
39
42
  private parentGroupContainer;
40
- private musicStaffLayer;
41
- private musicNotesLayer;
42
- private musicUILayer;
43
+ private layers;
43
44
  private width;
44
45
  private scale;
45
46
  private totalYOffset;
@@ -47,16 +48,25 @@ export default class SVGRenderer {
47
48
  constructor(rootElementCtx: HTMLElement, options: SVGRendererOptions);
48
49
  private makeGlyphDefs;
49
50
  private addNamespacedClassesToElement;
51
+ /**
52
+ * Creates a layer that is appended to parent element.
53
+ * layerName arg is the key that is appended to the internal list of layers, which
54
+ * can be used in method getLayer() arg. Best to call on construction.
55
+ *
56
+ * @param {string} layerName
57
+ * @returns {SVGGElement}
58
+ */
59
+ createLayer(layerName: string): SVGGElement;
60
+ getLayer(layerName: string): SVGGElement | null;
50
61
  createGroup(className?: string): SVGGElement;
51
62
  commitElementsToDOM(elements: SVGElement[] | SVGElement, parent?: HTMLElement | SVGElement): void;
52
- getLayerByName(name: LayerNames): SVGGElement;
53
63
  addTotalRootSvgHeight(amount: number): void;
54
64
  setTotalRootSvgHeight(amount: number): void;
55
65
  addTotalRootSvgYOffset(amount: number): void;
56
66
  applySizingToRootSvg(): void;
57
67
  get rootSvgElement(): SVGElement;
58
68
  get parentGroupElement(): SVGElement;
59
- drawLine(x1: number, y1: number, x2: number, y2: number, parent: SVGElement): void;
69
+ drawLine(x1: number, y1: number, x2: number, y2: number, parent: SVGElement, options?: DrawLineOptions): void;
60
70
  drawRect(width: number, height: number, parent: SVGElement, options?: DrawRectOptions): SVGRectElement;
61
71
  drawGlyph(glyphName: GlyphNames, parent: SVGElement, options?: DrawGlyphOptions): void;
62
72
  drawCircle(cx: number, cy: number, radius: number, parent: SVGElement, options?: DrawCircleOptions): SVGCircleElement;
@@ -6,8 +6,7 @@ export type ScrollingStaffOptions = {
6
6
  staffType?: StaffTypes;
7
7
  spaceAbove?: number;
8
8
  spaceBelow?: number;
9
- staffColor?: string;
10
- staffBackgroundColor?: string;
9
+ svgAutoFill?: boolean;
11
10
  onNotesOut?: () => void;
12
11
  };
13
12
  export type NoteSequence = (string | string[])[];