vexflow 4.0.1-beta.2 → 4.0.2
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 +48 -65
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +729 -698
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +553 -614
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow-gonville.js +2 -2
- package/build/cjs/vexflow-gonville.js.map +1 -1
- package/build/cjs/vexflow-petaluma.js +2 -2
- package/build/cjs/vexflow-petaluma.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/entry/vexflow-bravura.js +1 -2
- package/build/esm/entry/vexflow-core.js +1 -2
- package/build/esm/entry/vexflow-debug-with-tests.js +9 -2
- package/build/esm/entry/vexflow-debug.js +7 -2
- package/build/esm/entry/vexflow-gonville.js +1 -2
- package/build/esm/entry/vexflow-petaluma.js +1 -2
- package/build/esm/entry/vexflow.js +1 -2
- package/build/esm/src/annotation.js +10 -4
- package/build/esm/src/beam.js +20 -6
- package/build/esm/src/factory.js +6 -1
- package/build/esm/src/flow.js +27 -14
- package/build/esm/src/font.js +0 -2
- package/build/esm/src/formatter.js +21 -4
- package/build/esm/src/glyph.js +6 -0
- package/build/esm/src/index.js +1 -3
- package/build/esm/src/note.js +1 -1
- package/build/esm/src/stave.js +2 -2
- package/build/esm/src/staveconnector.js +6 -3
- package/build/esm/src/staveline.js +2 -5
- package/build/esm/src/stavenote.js +19 -6
- package/build/esm/src/stavesection.js +9 -6
- package/build/esm/src/stavetext.js +3 -3
- package/build/esm/src/system.js +1 -8
- package/build/esm/src/textnote.js +12 -14
- package/build/esm/src/version.js +3 -3
- package/build/esm/tests/annotation_tests.js +14 -1
- package/build/esm/tests/beam_tests.js +19 -0
- package/build/esm/tests/easyscore_tests.js +5 -2
- package/build/esm/tests/formatter_tests.js +62 -10
- package/build/esm/tests/stave_tests.js +4 -4
- package/build/types/entry/vexflow-bravura.d.ts +1 -2
- package/build/types/entry/vexflow-core.d.ts +1 -2
- package/build/types/entry/vexflow-debug.d.ts +1 -2
- package/build/types/entry/vexflow-gonville.d.ts +1 -2
- package/build/types/entry/vexflow-petaluma.d.ts +1 -2
- package/build/types/entry/vexflow.d.ts +1 -2
- package/build/types/src/annotation.d.ts +1 -0
- package/build/types/src/beam.d.ts +30 -1
- package/build/types/src/easyscore.d.ts +4 -0
- package/build/types/src/factory.d.ts +6 -3
- package/build/types/src/flow.d.ts +27 -12
- package/build/types/src/font.d.ts +0 -1
- package/build/types/src/glyph.d.ts +2 -0
- package/build/types/src/index.d.ts +1 -3
- package/build/types/src/note.d.ts +1 -0
- package/build/types/src/stave.d.ts +1 -1
- package/build/types/src/staveconnector.d.ts +13 -15
- package/build/types/src/staveline.d.ts +2 -5
- package/build/types/src/stavesection.d.ts +2 -1
- package/build/types/src/system.d.ts +2 -2
- package/build/types/src/textnote.d.ts +4 -4
- package/entry/vexflow-bravura.ts +3 -3
- package/entry/vexflow-core.ts +3 -3
- package/entry/vexflow-debug-with-tests.ts +16 -2
- package/entry/vexflow-debug.ts +11 -3
- package/entry/vexflow-gonville.ts +3 -3
- package/entry/vexflow-petaluma.ts +3 -3
- package/entry/vexflow.ts +3 -3
- package/package.json +3 -1
- package/releases/vexflow-debug.js +30441 -0
- package/releases/vexflow-min.js +6 -0
- package/src/annotation.ts +15 -4
- package/src/beam.ts +55 -6
- package/src/easyscore.ts +11 -1
- package/src/factory.ts +18 -4
- package/src/flow.ts +35 -20
- package/src/font.ts +0 -4
- package/src/formatter.ts +24 -8
- package/src/glyph.ts +8 -0
- package/src/index.ts +2 -7
- package/src/note.ts +2 -1
- package/src/stave.ts +2 -2
- package/src/staveconnector.ts +43 -9
- package/src/staveline.ts +2 -5
- package/src/stavenote.ts +20 -10
- package/src/stavesection.ts +10 -6
- package/src/stavetext.ts +3 -3
- package/src/system.ts +3 -9
- package/src/textnote.ts +9 -11
package/src/stavenote.ts
CHANGED
|
@@ -184,7 +184,9 @@ export class StaveNote extends StemmableNote {
|
|
|
184
184
|
if (voices === 2) {
|
|
185
185
|
const lineSpacing =
|
|
186
186
|
noteU.note.hasStem() && noteL.note.hasStem() && noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
|
|
187
|
-
if (noteU.
|
|
187
|
+
if (noteL.isrest && noteU.isrest && noteU.note.duration === noteL.note.duration) {
|
|
188
|
+
noteL.note.render_options.draw = false;
|
|
189
|
+
} else if (noteU.minLine <= noteL.maxLine + lineSpacing) {
|
|
188
190
|
if (noteU.isrest) {
|
|
189
191
|
// shift rest up
|
|
190
192
|
shiftRestVertical(noteU, noteL, 1);
|
|
@@ -248,7 +250,7 @@ export class StaveNote extends StemmableNote {
|
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
252
|
} //Very close whole notes
|
|
251
|
-
} else {
|
|
253
|
+
} else if (lineDiff < 1) {
|
|
252
254
|
xShift = voiceXShift + 2;
|
|
253
255
|
if (noteU.stemDirection === noteL.stemDirection) {
|
|
254
256
|
// upper voice is middle voice, so shift it right
|
|
@@ -257,6 +259,12 @@ export class StaveNote extends StemmableNote {
|
|
|
257
259
|
// shift lower voice right
|
|
258
260
|
noteL.note.setXShift(xShift);
|
|
259
261
|
}
|
|
262
|
+
} else if (noteU.note.hasStem()) {
|
|
263
|
+
noteU.stemDirection = -noteU.note.getStemDirection();
|
|
264
|
+
noteU.note.setStemDirection(noteU.stemDirection);
|
|
265
|
+
} else if (noteL.note.hasStem()) {
|
|
266
|
+
noteL.stemDirection = -noteL.note.getStemDirection();
|
|
267
|
+
noteL.note.setStemDirection(noteL.stemDirection);
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
270
|
}
|
|
@@ -299,10 +307,10 @@ export class StaveNote extends StemmableNote {
|
|
|
299
307
|
|
|
300
308
|
// Special case 2 :: all voices are rests
|
|
301
309
|
if (noteU.isrest && noteM.isrest && noteL.isrest) {
|
|
302
|
-
//
|
|
303
|
-
|
|
304
|
-
//
|
|
305
|
-
|
|
310
|
+
// Hide upper voice rest
|
|
311
|
+
noteU.note.render_options.draw = false;
|
|
312
|
+
// Hide lower voice rest
|
|
313
|
+
noteL.note.render_options.draw = false;
|
|
306
314
|
// format complete
|
|
307
315
|
state.right_shift += xShift;
|
|
308
316
|
return true;
|
|
@@ -310,12 +318,12 @@ export class StaveNote extends StemmableNote {
|
|
|
310
318
|
|
|
311
319
|
// Test if any other rests can be repositioned
|
|
312
320
|
if (noteM.isrest && noteU.isrest && noteM.minLine <= noteL.maxLine) {
|
|
313
|
-
//
|
|
314
|
-
|
|
321
|
+
// Hide middle voice rest
|
|
322
|
+
noteM.note.render_options.draw = false;
|
|
315
323
|
}
|
|
316
324
|
if (noteM.isrest && noteL.isrest && noteU.minLine <= noteM.maxLine) {
|
|
317
|
-
//
|
|
318
|
-
|
|
325
|
+
// Hide middle voice rest
|
|
326
|
+
noteM.note.render_options.draw = false;
|
|
319
327
|
}
|
|
320
328
|
if (noteU.isrest && noteU.minLine <= noteM.maxLine) {
|
|
321
329
|
// shift upper voice rest up;
|
|
@@ -1206,6 +1214,8 @@ export class StaveNote extends StemmableNote {
|
|
|
1206
1214
|
|
|
1207
1215
|
// Draws all the `StaveNote` parts. This is the main drawing method.
|
|
1208
1216
|
draw(): void {
|
|
1217
|
+
if (this.render_options.draw === false) return;
|
|
1218
|
+
|
|
1209
1219
|
if (this.ys.length === 0) {
|
|
1210
1220
|
throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
|
|
1211
1221
|
}
|
package/src/stavesection.ts
CHANGED
|
@@ -21,8 +21,9 @@ export class StaveSection extends StaveModifier {
|
|
|
21
21
|
protected section: string;
|
|
22
22
|
protected shift_x: number;
|
|
23
23
|
protected shift_y: number;
|
|
24
|
+
protected drawRect: boolean;
|
|
24
25
|
|
|
25
|
-
constructor(section: string, x: number, shift_y: number) {
|
|
26
|
+
constructor(section: string, x: number, shift_y: number, drawRect = true) {
|
|
26
27
|
super();
|
|
27
28
|
|
|
28
29
|
this.setWidth(16);
|
|
@@ -30,6 +31,7 @@ export class StaveSection extends StaveModifier {
|
|
|
30
31
|
this.x = x;
|
|
31
32
|
this.shift_x = 0;
|
|
32
33
|
this.shift_y = shift_y;
|
|
34
|
+
this.drawRect = drawRect;
|
|
33
35
|
this.resetFont();
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -66,12 +68,14 @@ export class StaveSection extends StaveModifier {
|
|
|
66
68
|
const height = textHeight + 2 * paddingY; // add top & bottom padding
|
|
67
69
|
|
|
68
70
|
// Seems to be a good default y
|
|
69
|
-
const y = stave.getYForTopText(
|
|
71
|
+
const y = stave.getYForTopText(1.5) + this.shift_y;
|
|
70
72
|
const x = this.x + shift_x;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
if (this.drawRect) {
|
|
74
|
+
ctx.beginPath();
|
|
75
|
+
ctx.setLineWidth(rectWidth);
|
|
76
|
+
ctx.rect(x, y + textMeasurements.y - paddingY, width, height);
|
|
77
|
+
ctx.stroke();
|
|
78
|
+
}
|
|
75
79
|
ctx.fillText(this.section, x + paddingX, y);
|
|
76
80
|
ctx.restore();
|
|
77
81
|
return this;
|
package/src/stavetext.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Font, FontInfo, FontStyle, FontWeight } from './font';
|
|
5
5
|
import { Stave } from './stave';
|
|
6
6
|
import { StaveModifier, StaveModifierPosition } from './stavemodifier';
|
|
7
|
-
import {
|
|
7
|
+
import { TextJustification, TextNote } from './textnote';
|
|
8
8
|
import { Category } from './typeguard';
|
|
9
9
|
import { RuntimeError } from './util';
|
|
10
10
|
|
|
@@ -94,9 +94,9 @@ export class StaveText extends StaveModifier {
|
|
|
94
94
|
case StaveModifierPosition.ABOVE:
|
|
95
95
|
case StaveModifierPosition.BELOW:
|
|
96
96
|
x = stave.getX() + this.options.shift_x;
|
|
97
|
-
if (this.options.justification ===
|
|
97
|
+
if (this.options.justification === TextJustification.CENTER) {
|
|
98
98
|
x += stave.getWidth() / 2 - text_width / 2;
|
|
99
|
-
} else if (this.options.justification ===
|
|
99
|
+
} else if (this.options.justification === TextJustification.RIGHT) {
|
|
100
100
|
x += stave.getWidth() - text_width;
|
|
101
101
|
}
|
|
102
102
|
|
package/src/system.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { FormatParams, Formatter, FormatterOptions } from './formatter';
|
|
|
8
8
|
import { Note } from './note';
|
|
9
9
|
import { RenderContext } from './rendercontext';
|
|
10
10
|
import { Stave, StaveOptions } from './stave';
|
|
11
|
-
import { StaveConnector } from './staveconnector';
|
|
11
|
+
import { StaveConnector, StaveConnectorType } from './staveconnector';
|
|
12
12
|
import { Category } from './typeguard';
|
|
13
13
|
import { RuntimeError } from './util';
|
|
14
14
|
import { Voice } from './voice';
|
|
@@ -121,7 +121,7 @@ export class System extends Element {
|
|
|
121
121
|
* Add connector between staves.
|
|
122
122
|
* @param type see {@link StaveConnector.typeString}
|
|
123
123
|
*/
|
|
124
|
-
addConnector(type:
|
|
124
|
+
addConnector(type: StaveConnectorType = 'double'): StaveConnector {
|
|
125
125
|
this.connector = this.factory.StaveConnector({
|
|
126
126
|
top_stave: this.parts[0].stave,
|
|
127
127
|
bottom_stave: this.parts[this.parts.length - 1].stave,
|
|
@@ -191,13 +191,7 @@ export class System extends Element {
|
|
|
191
191
|
this.parts.forEach((part) => {
|
|
192
192
|
y = y + part.stave.space(part.spaceAbove);
|
|
193
193
|
part.stave.setY(y);
|
|
194
|
-
|
|
195
|
-
part.voices.forEach((voice) => {
|
|
196
|
-
formatter.joinVoices([voice]);
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
formatter.joinVoices(part.voices);
|
|
200
|
-
}
|
|
194
|
+
formatter.joinVoices(part.voices);
|
|
201
195
|
y = y + part.stave.space(part.spaceBelow);
|
|
202
196
|
y = y + part.stave.space(this.options.spaceBetweenStaves);
|
|
203
197
|
if (part.debugNoteMetrics) {
|
package/src/textnote.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Note, NoteStruct } from './note';
|
|
|
7
7
|
import { Category } from './typeguard';
|
|
8
8
|
import { RuntimeError } from './util';
|
|
9
9
|
|
|
10
|
-
export enum
|
|
10
|
+
export enum TextJustification {
|
|
11
11
|
LEFT = 1,
|
|
12
12
|
CENTER = 2,
|
|
13
13
|
RIGHT = 3,
|
|
@@ -41,9 +41,7 @@ export class TextNote extends Note {
|
|
|
41
41
|
style: FontStyle.NORMAL,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
static
|
|
45
|
-
return Justification;
|
|
46
|
-
}
|
|
44
|
+
static readonly Justification = TextJustification;
|
|
47
45
|
|
|
48
46
|
/** Glyph data. */
|
|
49
47
|
static get GLYPHS(): Record<string, { code: string }> {
|
|
@@ -112,7 +110,7 @@ export class TextNote extends Note {
|
|
|
112
110
|
protected superscript?: string;
|
|
113
111
|
protected subscript?: string;
|
|
114
112
|
protected smooth: boolean;
|
|
115
|
-
protected justification:
|
|
113
|
+
protected justification: TextJustification;
|
|
116
114
|
protected line: number;
|
|
117
115
|
|
|
118
116
|
constructor(noteStruct: TextNoteStruct) {
|
|
@@ -125,7 +123,7 @@ export class TextNote extends Note {
|
|
|
125
123
|
this.line = noteStruct.line || 0;
|
|
126
124
|
this.smooth = noteStruct.smooth || false;
|
|
127
125
|
this.ignore_ticks = noteStruct.ignore_ticks || false;
|
|
128
|
-
this.justification =
|
|
126
|
+
this.justification = TextJustification.LEFT;
|
|
129
127
|
|
|
130
128
|
// Determine and set initial note width. Note that the text width is
|
|
131
129
|
// an approximation and isn't very accurate. The only way to accurately
|
|
@@ -142,7 +140,7 @@ export class TextNote extends Note {
|
|
|
142
140
|
}
|
|
143
141
|
|
|
144
142
|
/** Set the horizontal justification of the TextNote. */
|
|
145
|
-
setJustification(just:
|
|
143
|
+
setJustification(just: TextJustification): this {
|
|
146
144
|
this.justification = just;
|
|
147
145
|
return this;
|
|
148
146
|
}
|
|
@@ -170,9 +168,9 @@ export class TextNote extends Note {
|
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
|
|
173
|
-
if (this.justification ===
|
|
171
|
+
if (this.justification === TextJustification.CENTER) {
|
|
174
172
|
this.leftDisplacedHeadPx = this.width / 2;
|
|
175
|
-
} else if (this.justification ===
|
|
173
|
+
} else if (this.justification === TextJustification.RIGHT) {
|
|
176
174
|
this.leftDisplacedHeadPx = this.width;
|
|
177
175
|
}
|
|
178
176
|
|
|
@@ -198,9 +196,9 @@ export class TextNote extends Note {
|
|
|
198
196
|
// Align based on tick-context width.
|
|
199
197
|
const width = this.getWidth();
|
|
200
198
|
|
|
201
|
-
if (this.justification ===
|
|
199
|
+
if (this.justification === TextJustification.CENTER) {
|
|
202
200
|
x -= width / 2;
|
|
203
|
-
} else if (this.justification ===
|
|
201
|
+
} else if (this.justification === TextJustification.RIGHT) {
|
|
204
202
|
x -= width;
|
|
205
203
|
}
|
|
206
204
|
|