vector-score 1.2.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 +31 -29
- package/dist/classes/GuitarChord.d.ts +3 -1
- package/dist/classes/SVGRenderer.d.ts +4 -0
- package/dist/constants.d.ts +6 -6
- package/dist/vector-score.js +342 -315
- package/dist/vector-score.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ A lightweight, SVG-based TypeScript library for rendering simple musical notatio
|
|
|
15
15
|
* Supports grand, treble, bass, and alto clefs.
|
|
16
16
|
* Easy to add notes and provides justifying alignment functions.
|
|
17
17
|
* Simple single line staff for display chords, notes, or scales.
|
|
18
|
-
* [**Go to Music Staffs**](#
|
|
18
|
+
* [**Go to Music Staffs**](#Grand-Staff)
|
|
19
19
|
|
|
20
20
|
### Render and Display Guitar Chords
|
|
21
21
|
* Write explicitly which string, fret, and optionally finger to display on the diagram.
|
|
@@ -29,22 +29,6 @@ A lightweight, SVG-based TypeScript library for rendering simple musical notatio
|
|
|
29
29
|
|
|
30
30
|
<br />
|
|
31
31
|
|
|
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.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<br />
|
|
39
|
-
|
|
40
|
-
## Installation
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
npm i vector-score
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
<br />
|
|
47
|
-
|
|
48
32
|
## Usage
|
|
49
33
|
|
|
50
34
|
### 1. Setup HTML
|
|
@@ -71,13 +55,7 @@ const staff = new MusicStaff(container, {
|
|
|
71
55
|
});
|
|
72
56
|
|
|
73
57
|
// Draw a C Minor scale (quarter notes)
|
|
74
|
-
// Format: NoteName + Accidental(optional) + Octave + Duration
|
|
75
58
|
staff.drawNote(['C4q', 'D4q', 'Eb4q', 'F4q', 'G4q', 'Ab4q', 'Bb4q', 'C5q']);
|
|
76
|
-
|
|
77
|
-
// Draw a C Chord
|
|
78
|
-
staff.drawChord(['C4w', 'E4w', 'G4w']);
|
|
79
|
-
|
|
80
|
-
// Evenly space all notes on the staff
|
|
81
59
|
staff.justifyNotes();
|
|
82
60
|
```
|
|
83
61
|
|
|
@@ -86,6 +64,29 @@ staff.justifyNotes();
|
|
|
86
64
|
|
|
87
65
|
<br/>
|
|
88
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
|
+
|
|
89
90
|
## Grand Staff
|
|
90
91
|
|
|
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"] )
|
|
@@ -125,10 +126,10 @@ const grandStaff = new GuitarChord(container, {
|
|
|
125
126
|
fretCount: 5,
|
|
126
127
|
stringCount: 6,
|
|
127
128
|
stringLabels: ["E", "A", "D", "G", "B", "E"],
|
|
128
|
-
|
|
129
|
+
inlineChordsAmount: 2, // Choose how many chords are in a single line
|
|
129
130
|
scale: 1,
|
|
130
131
|
color: "var(--font-color)",
|
|
131
|
-
backgroundColor: "
|
|
132
|
+
backgroundColor: "white"
|
|
132
133
|
});
|
|
133
134
|
|
|
134
135
|
// C chord
|
|
@@ -137,9 +138,9 @@ guitarChordsSection.addChord("x32010", "032010", {
|
|
|
137
138
|
});
|
|
138
139
|
|
|
139
140
|
// Bbmaj7 Barre Chord (Automatically calculates the starting fret and barre positioning)
|
|
140
|
-
const frets = "
|
|
141
|
-
const fingers = "
|
|
142
|
-
const barres = guitarChordsSection.determineBarreOptions(frets, fingers, [
|
|
141
|
+
const frets = "687766";
|
|
142
|
+
const fingers = "142311";
|
|
143
|
+
const barres = guitarChordsSection.determineBarreOptions(frets, fingers, [6]);
|
|
143
144
|
|
|
144
145
|
guitarChordsSection.addChord(frets, fingers, {
|
|
145
146
|
label: "Bbmaj7",
|
|
@@ -348,10 +349,11 @@ Barre lines can be added dynamically using the built-in helper method, `determin
|
|
|
348
349
|
* `stringCount`: Amount of strings to show in diagram, default is 6.
|
|
349
350
|
* `fretCount`: Amount of frets to show in diagram, default is 5.
|
|
350
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.
|
|
351
|
-
* `
|
|
352
|
+
* `inlineChordsAmount`: Max amount of chords to display on a single line (default: 2).
|
|
352
353
|
* `scale`: Zoom factor (default: 1).
|
|
353
354
|
* `color`: CSS color string for lines and notes.
|
|
354
355
|
* `backgroundColor`: CSS color string for background.
|
|
356
|
+
* `width`: Total width of the SVG in pixels, overrides inlineChordAmount auto width calculation (default: undefined).
|
|
355
357
|
|
|
356
358
|
### RhythmStaffOptions
|
|
357
359
|
* `topNumber`: The top number of the time signature (e.g., 4 for 4/4 time).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GuitarBarreDef, GuitarChordDrawOptions } from '../types';
|
|
2
2
|
export type GuitarChordOptions = {
|
|
3
3
|
width?: number;
|
|
4
|
+
inlineChordsAmount?: number;
|
|
4
5
|
scale?: number;
|
|
5
6
|
stringCount?: number;
|
|
6
7
|
fretCount?: number;
|
|
@@ -26,7 +27,8 @@ export default class GuitarChord {
|
|
|
26
27
|
* All config options are in the type GuitarChordOptions.
|
|
27
28
|
*/
|
|
28
29
|
constructor(rootElementCtx: HTMLElement, options?: GuitarChordOptions);
|
|
29
|
-
private
|
|
30
|
+
private getDotsToHide;
|
|
31
|
+
private drawFretDots;
|
|
30
32
|
private drawStringLabels;
|
|
31
33
|
private drawBarre;
|
|
32
34
|
private renderChordDiagram;
|
|
@@ -18,17 +18,20 @@ type DrawRectOptions = {
|
|
|
18
18
|
y?: number;
|
|
19
19
|
fill?: string;
|
|
20
20
|
rx?: number;
|
|
21
|
+
classes?: string | string[];
|
|
21
22
|
};
|
|
22
23
|
type DrawCircleOptions = {
|
|
23
24
|
filled?: boolean;
|
|
24
25
|
fill?: string;
|
|
25
26
|
strokeWidth?: number;
|
|
27
|
+
classes?: string | string[];
|
|
26
28
|
};
|
|
27
29
|
type DrawTextOptions = {
|
|
28
30
|
fontSize?: number;
|
|
29
31
|
anchor?: "start" | "middle" | "end";
|
|
30
32
|
fill?: string;
|
|
31
33
|
fontWeight?: string;
|
|
34
|
+
classes?: string | string[];
|
|
32
35
|
};
|
|
33
36
|
export default class SVGRenderer {
|
|
34
37
|
private rootElementRef;
|
|
@@ -43,6 +46,7 @@ export default class SVGRenderer {
|
|
|
43
46
|
private totalHeight;
|
|
44
47
|
constructor(rootElementCtx: HTMLElement, options: SVGRendererOptions);
|
|
45
48
|
private makeGlyphDefs;
|
|
49
|
+
private addNamespacedClassesToElement;
|
|
46
50
|
createGroup(className?: string): SVGGElement;
|
|
47
51
|
commitElementsToDOM(elements: SVGElement[] | SVGElement, parent?: HTMLElement | SVGElement): void;
|
|
48
52
|
getLayerByName(name: LayerNames): SVGGElement;
|
package/dist/constants.d.ts
CHANGED
|
@@ -25,14 +25,14 @@ export declare const GUITAR_DOT_RADIUS = 10;
|
|
|
25
25
|
export declare const GUITAR_MARKER_RADIUS = 6;
|
|
26
26
|
export declare const GUITAR_STRING_LABEL_OFFSET = 4;
|
|
27
27
|
export declare const GUITAR_STRING_LABEL_HEIGHT: number;
|
|
28
|
-
export declare const GUITAR_DIAGRAM_H_SPACING =
|
|
29
|
-
export declare const GUITAR_DIAGRAM_V_SPACING =
|
|
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;
|
|
30
31
|
export declare const GUITAR_DIAGRAM_BOTTOM_PADDING = 1;
|
|
31
32
|
export declare const GUITAR_NUT_THICKNESS = 4;
|
|
32
33
|
export declare const GUITAR_NUT_X_OFFSET = 1;
|
|
33
34
|
export declare const GUITAR_NUT_SPACE_ABOVE: number;
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const GUITAR_FRET_LABEL_FONT_SIZE = 14;
|
|
35
|
+
export declare const GUITAR_FONT_BASE = 16;
|
|
36
|
+
export declare const GUITAR_FONT_SMALL = 12;
|
|
37
37
|
export declare const GUITAR_LABEL_HEIGHT = 16;
|
|
38
|
-
export declare const GUITAR_FRET_LABEL_OFFSET_X
|
|
38
|
+
export declare const GUITAR_FRET_LABEL_OFFSET_X = 2;
|