vexflow 4.0.1 → 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 (38) hide show
  1. package/README.md +2 -2
  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 +91 -19
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +37 -16
  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/src/beam.js +2 -0
  17. package/build/esm/src/stave.js +2 -2
  18. package/build/esm/src/staveconnector.js +6 -3
  19. package/build/esm/src/stavenote.js +9 -1
  20. package/build/esm/src/stavesection.js +9 -6
  21. package/build/esm/src/version.js +3 -3
  22. package/build/esm/tests/formatter_tests.js +53 -2
  23. package/build/esm/tests/stave_tests.js +1 -1
  24. package/build/types/src/factory.d.ts +2 -2
  25. package/build/types/src/stave.d.ts +1 -1
  26. package/build/types/src/staveconnector.d.ts +13 -15
  27. package/build/types/src/stavesection.d.ts +2 -1
  28. package/build/types/src/system.d.ts +2 -2
  29. package/package.json +3 -1
  30. package/releases/vexflow-debug.js +30441 -0
  31. package/releases/vexflow-min.js +6 -0
  32. package/src/beam.ts +2 -0
  33. package/src/factory.ts +2 -2
  34. package/src/stave.ts +2 -2
  35. package/src/staveconnector.ts +43 -9
  36. package/src/stavenote.ts +7 -1
  37. package/src/stavesection.ts +10 -6
  38. package/src/system.ts +2 -2
package/src/beam.ts CHANGED
@@ -898,6 +898,8 @@ export class Beam extends Element {
898
898
  this.notes.forEach((note) => {
899
899
  const stem = note.getStem();
900
900
  if (stem) {
901
+ const stem_x = note.getStemX();
902
+ stem.setNoteHeadXBounds(stem_x, stem_x);
901
903
  ctx.openGroup('stem', note.getAttribute('id') + '-stem');
902
904
  stem.setContext(ctx).draw();
903
905
  ctx.closeGroup();
package/src/factory.ts CHANGED
@@ -31,7 +31,7 @@ import { Renderer } from './renderer';
31
31
  import { RepeatNote } from './repeatnote';
32
32
  import { Stave, StaveOptions } from './stave';
33
33
  import { BarlineType } from './stavebarline';
34
- import { StaveConnector } from './staveconnector';
34
+ import { StaveConnector, StaveConnectorType } from './staveconnector';
35
35
  import { StaveLine } from './staveline';
36
36
  import { StaveNote, StaveNoteStruct } from './stavenote';
37
37
  import { StaveTie } from './stavetie';
@@ -471,7 +471,7 @@ export class Factory {
471
471
  return voice;
472
472
  }
473
473
 
474
- StaveConnector(params: { top_stave: Stave; bottom_stave: Stave; type: string }): StaveConnector {
474
+ StaveConnector(params: { top_stave: Stave; bottom_stave: Stave; type: StaveConnectorType }): StaveConnector {
475
475
  const connector = new StaveConnector(params.top_stave, params.bottom_stave);
476
476
  connector.setType(params.type).setContext(this.context);
477
477
  this.renderQ.push(connector);
package/src/stave.ts CHANGED
@@ -306,8 +306,8 @@ export class Stave extends Element {
306
306
  }
307
307
 
308
308
  // Section functions
309
- setSection(section: string, y: number, xOffset = 0, fontSize?: number) {
310
- const staveSection = new StaveSection(section, this.x + xOffset, y);
309
+ setSection(section: string, y: number, xOffset = 0, fontSize?: number, drawRect = true) {
310
+ const staveSection = new StaveSection(section, this.x + xOffset, y, drawRect);
311
311
  if (fontSize) staveSection.setFontSize(fontSize);
312
312
  this.modifiers.push(staveSection);
313
313
  return this;
@@ -30,6 +30,30 @@ function drawBoldDoubleLine(ctx: RenderContext, type: number, topX: number, topY
30
30
  ctx.fillRect(topX - thickLineOffset, topY, variableWidth, botY - topY);
31
31
  }
32
32
 
33
+ /**
34
+ * see {@link StaveConnector.type} & {@link StaveConnector.typeString}
35
+ */
36
+ export type StaveConnectorType =
37
+ | 'singleRight'
38
+ | 'singleLeft'
39
+ | 'single'
40
+ | 'double'
41
+ | 'brace'
42
+ | 'bracket'
43
+ | 'boldDoubleLeft'
44
+ | 'boldDoubleRight'
45
+ | 'thinDouble'
46
+ | 'none'
47
+ | 0
48
+ | 1
49
+ | 2
50
+ | 3
51
+ | 4
52
+ | 5
53
+ | 6
54
+ | 7
55
+ | 8;
56
+
33
57
  /** StaveConnector implements the connector lines between staves of a system. */
34
58
  export class StaveConnector extends Element {
35
59
  static get CATEGORY(): string {
@@ -48,7 +72,7 @@ export class StaveConnector extends Element {
48
72
  * with older versions of vexflow which didn't have right sided
49
73
  * stave connectors.
50
74
  */
51
- static readonly type = {
75
+ static readonly type: Record<string, Exclude<StaveConnectorType, string>> = {
52
76
  SINGLE_RIGHT: 0,
53
77
  SINGLE_LEFT: 1,
54
78
  SINGLE: 1,
@@ -59,7 +83,7 @@ export class StaveConnector extends Element {
59
83
  BOLD_DOUBLE_RIGHT: 6,
60
84
  THIN_DOUBLE: 7,
61
85
  NONE: 8,
62
- };
86
+ } as const;
63
87
 
64
88
  /**
65
89
  * Connector type:
@@ -74,7 +98,7 @@ export class StaveConnector extends Element {
74
98
  * * "thinDouble"
75
99
  * * "none"
76
100
  */
77
- static readonly typeString: Record<string, number> = {
101
+ static readonly typeString: Record<Exclude<StaveConnectorType, number>, Exclude<StaveConnectorType, string>> = {
78
102
  singleRight: StaveConnector.type.SINGLE_RIGHT,
79
103
  singleLeft: StaveConnector.type.SINGLE_LEFT,
80
104
  single: StaveConnector.type.SINGLE,
@@ -85,7 +109,7 @@ export class StaveConnector extends Element {
85
109
  boldDoubleRight: StaveConnector.type.BOLD_DOUBLE_RIGHT,
86
110
  thinDouble: StaveConnector.type.THIN_DOUBLE,
87
111
  none: StaveConnector.type.NONE,
88
- };
112
+ } as const;
89
113
 
90
114
  protected width: number;
91
115
  protected texts: {
@@ -93,7 +117,7 @@ export class StaveConnector extends Element {
93
117
  options: { shift_x: number; shift_y: number };
94
118
  }[];
95
119
 
96
- protected type: number;
120
+ protected type: typeof StaveConnector['type'][keyof typeof StaveConnector['type']];
97
121
 
98
122
  readonly top_stave: Stave;
99
123
  readonly bottom_stave: Stave;
@@ -121,15 +145,25 @@ export class StaveConnector extends Element {
121
145
  * Set type.
122
146
  * @param type see {@link StaveConnector.type} & {@link StaveConnector.typeString}
123
147
  */
124
- setType(type: number | string): this {
125
- type = typeof type === 'string' ? StaveConnector.typeString[type] : type;
148
+ setType(type: StaveConnectorType): this {
149
+ const newType = typeof type === 'string' ? StaveConnector.typeString[type] : type;
126
150
 
127
- if (type >= StaveConnector.type.SINGLE_RIGHT && type <= StaveConnector.type.NONE) {
128
- this.type = type;
151
+ // Be certain that the type is a valid type:
152
+ if (Object.values(StaveConnector.type).includes(newType)) {
153
+ this.type = newType;
129
154
  }
155
+
130
156
  return this;
131
157
  }
132
158
 
159
+ /**
160
+ * Get type.
161
+ * @returns number {@link StaveConnector.type}
162
+ */
163
+ getType(): number {
164
+ return this.type;
165
+ }
166
+
133
167
  /** Set optional associated Text. */
134
168
  setText(text: string, options: { shift_x?: number; shift_y?: number } = {}): this {
135
169
  this.texts.push({
package/src/stavenote.ts CHANGED
@@ -250,7 +250,7 @@ export class StaveNote extends StemmableNote {
250
250
  }
251
251
  }
252
252
  } //Very close whole notes
253
- } else {
253
+ } else if (lineDiff < 1) {
254
254
  xShift = voiceXShift + 2;
255
255
  if (noteU.stemDirection === noteL.stemDirection) {
256
256
  // upper voice is middle voice, so shift it right
@@ -259,6 +259,12 @@ export class StaveNote extends StemmableNote {
259
259
  // shift lower voice right
260
260
  noteL.note.setXShift(xShift);
261
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);
262
268
  }
263
269
  }
264
270
  }
@@ -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/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,