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.
Files changed (94) hide show
  1. package/README.md +48 -65
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +729 -698
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +553 -614
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow-gonville.js +2 -2
  11. package/build/cjs/vexflow-gonville.js.map +1 -1
  12. package/build/cjs/vexflow-petaluma.js +2 -2
  13. package/build/cjs/vexflow-petaluma.js.map +1 -1
  14. package/build/cjs/vexflow.js +2 -2
  15. package/build/cjs/vexflow.js.map +1 -1
  16. package/build/esm/entry/vexflow-bravura.js +1 -2
  17. package/build/esm/entry/vexflow-core.js +1 -2
  18. package/build/esm/entry/vexflow-debug-with-tests.js +9 -2
  19. package/build/esm/entry/vexflow-debug.js +7 -2
  20. package/build/esm/entry/vexflow-gonville.js +1 -2
  21. package/build/esm/entry/vexflow-petaluma.js +1 -2
  22. package/build/esm/entry/vexflow.js +1 -2
  23. package/build/esm/src/annotation.js +10 -4
  24. package/build/esm/src/beam.js +20 -6
  25. package/build/esm/src/factory.js +6 -1
  26. package/build/esm/src/flow.js +27 -14
  27. package/build/esm/src/font.js +0 -2
  28. package/build/esm/src/formatter.js +21 -4
  29. package/build/esm/src/glyph.js +6 -0
  30. package/build/esm/src/index.js +1 -3
  31. package/build/esm/src/note.js +1 -1
  32. package/build/esm/src/stave.js +2 -2
  33. package/build/esm/src/staveconnector.js +6 -3
  34. package/build/esm/src/staveline.js +2 -5
  35. package/build/esm/src/stavenote.js +19 -6
  36. package/build/esm/src/stavesection.js +9 -6
  37. package/build/esm/src/stavetext.js +3 -3
  38. package/build/esm/src/system.js +1 -8
  39. package/build/esm/src/textnote.js +12 -14
  40. package/build/esm/src/version.js +3 -3
  41. package/build/esm/tests/annotation_tests.js +14 -1
  42. package/build/esm/tests/beam_tests.js +19 -0
  43. package/build/esm/tests/easyscore_tests.js +5 -2
  44. package/build/esm/tests/formatter_tests.js +62 -10
  45. package/build/esm/tests/stave_tests.js +4 -4
  46. package/build/types/entry/vexflow-bravura.d.ts +1 -2
  47. package/build/types/entry/vexflow-core.d.ts +1 -2
  48. package/build/types/entry/vexflow-debug.d.ts +1 -2
  49. package/build/types/entry/vexflow-gonville.d.ts +1 -2
  50. package/build/types/entry/vexflow-petaluma.d.ts +1 -2
  51. package/build/types/entry/vexflow.d.ts +1 -2
  52. package/build/types/src/annotation.d.ts +1 -0
  53. package/build/types/src/beam.d.ts +30 -1
  54. package/build/types/src/easyscore.d.ts +4 -0
  55. package/build/types/src/factory.d.ts +6 -3
  56. package/build/types/src/flow.d.ts +27 -12
  57. package/build/types/src/font.d.ts +0 -1
  58. package/build/types/src/glyph.d.ts +2 -0
  59. package/build/types/src/index.d.ts +1 -3
  60. package/build/types/src/note.d.ts +1 -0
  61. package/build/types/src/stave.d.ts +1 -1
  62. package/build/types/src/staveconnector.d.ts +13 -15
  63. package/build/types/src/staveline.d.ts +2 -5
  64. package/build/types/src/stavesection.d.ts +2 -1
  65. package/build/types/src/system.d.ts +2 -2
  66. package/build/types/src/textnote.d.ts +4 -4
  67. package/entry/vexflow-bravura.ts +3 -3
  68. package/entry/vexflow-core.ts +3 -3
  69. package/entry/vexflow-debug-with-tests.ts +16 -2
  70. package/entry/vexflow-debug.ts +11 -3
  71. package/entry/vexflow-gonville.ts +3 -3
  72. package/entry/vexflow-petaluma.ts +3 -3
  73. package/entry/vexflow.ts +3 -3
  74. package/package.json +3 -1
  75. package/releases/vexflow-debug.js +30441 -0
  76. package/releases/vexflow-min.js +6 -0
  77. package/src/annotation.ts +15 -4
  78. package/src/beam.ts +55 -6
  79. package/src/easyscore.ts +11 -1
  80. package/src/factory.ts +18 -4
  81. package/src/flow.ts +35 -20
  82. package/src/font.ts +0 -4
  83. package/src/formatter.ts +24 -8
  84. package/src/glyph.ts +8 -0
  85. package/src/index.ts +2 -7
  86. package/src/note.ts +2 -1
  87. package/src/stave.ts +2 -2
  88. package/src/staveconnector.ts +43 -9
  89. package/src/staveline.ts +2 -5
  90. package/src/stavenote.ts +20 -10
  91. package/src/stavesection.ts +10 -6
  92. package/src/stavetext.ts +3 -3
  93. package/src/system.ts +3 -9
  94. 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.minLine <= noteL.maxLine + lineSpacing) {
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
- // Shift upper voice rest up
303
- shiftRestVertical(noteU, noteM, 1);
304
- // Shift lower voice rest down
305
- shiftRestVertical(noteL, noteM, -1);
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
- // Shift middle voice rest up
314
- shiftRestVertical(noteM, noteL, 1);
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
- // Shift middle voice rest down
318
- shiftRestVertical(noteM, noteU, -1);
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
  }
@@ -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(2) + this.shift_y;
71
+ const y = stave.getYForTopText(1.5) + this.shift_y;
70
72
  const x = this.x + shift_x;
71
- ctx.beginPath();
72
- ctx.setLineWidth(rectWidth);
73
- ctx.rect(x, y + textMeasurements.y - paddingY, width, height);
74
- ctx.stroke();
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 { Justification, TextNote } from './textnote';
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 === Justification.CENTER) {
97
+ if (this.options.justification === TextJustification.CENTER) {
98
98
  x += stave.getWidth() / 2 - text_width / 2;
99
- } else if (this.options.justification === Justification.RIGHT) {
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: string = 'double'): StaveConnector {
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
- if (this.options.autoWidth) {
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 Justification {
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 get Justification(): typeof Justification {
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: 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 = Justification.LEFT;
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: Justification): this {
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 === Justification.CENTER) {
171
+ if (this.justification === TextJustification.CENTER) {
174
172
  this.leftDisplacedHeadPx = this.width / 2;
175
- } else if (this.justification === Justification.RIGHT) {
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 === Justification.CENTER) {
199
+ if (this.justification === TextJustification.CENTER) {
202
200
  x -= width / 2;
203
- } else if (this.justification === Justification.RIGHT) {
201
+ } else if (this.justification === TextJustification.RIGHT) {
204
202
  x -= width;
205
203
  }
206
204