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/annotation.ts CHANGED
@@ -69,6 +69,12 @@ export class Annotation extends Modifier {
69
69
  centerStem: AnnotationVerticalJustify.CENTER_STEM,
70
70
  };
71
71
 
72
+ // Use the same padding for annotations as note head so the
73
+ // words don't run into each other.
74
+ static get minAnnotationPadding(): number {
75
+ const musicFont = Tables.currentMusicFont();
76
+ return musicFont.lookupMetric('glyphs.noteHead.minPadding');
77
+ }
72
78
  /** Arrange annotations within a `ModifierContext` */
73
79
  static format(annotations: Annotation[], state: ModifierContextState): boolean {
74
80
  if (!annotations || annotations.length === 0) return false;
@@ -89,12 +95,12 @@ export class Annotation extends Modifier {
89
95
  const textWidth = textFormatter.getWidthForTextInPx(annotation.text);
90
96
  if (annotation.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
91
97
  maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
92
- leftWidth = Math.max(leftWidth, textWidth);
98
+ leftWidth = Math.max(leftWidth, textWidth) + Annotation.minAnnotationPadding;
93
99
  } else if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
94
100
  maxRightGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
95
101
  rightWidth = Math.max(rightWidth, textWidth);
96
102
  } else {
97
- leftWidth = Math.max(leftWidth, textWidth / 2);
103
+ leftWidth = Math.max(leftWidth, textWidth / 2) + Annotation.minAnnotationPadding;
98
104
  rightWidth = Math.max(rightWidth, textWidth / 2);
99
105
  maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
100
106
  maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
@@ -167,8 +173,8 @@ export class Annotation extends Modifier {
167
173
  Math.max(rightWidth - state.right_shift, 0)
168
174
  );
169
175
  const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.left_shift, 0));
170
- state.left_shift += leftOverlap / 2;
171
- state.right_shift += rightOverlap / 2;
176
+ state.left_shift += leftOverlap;
177
+ state.right_shift += rightOverlap;
172
178
  return true;
173
179
  }
174
180
 
@@ -231,6 +237,10 @@ export class Annotation extends Modifier {
231
237
 
232
238
  // We're changing context parameters. Save current state.
233
239
  ctx.save();
240
+ // Apply style might not save context, if this.style is undefined, so we
241
+ // still need to save context state just before this, since we will be
242
+ // changing ctx parameters below.
243
+ this.applyStyle();
234
244
  const classString = Object.keys(this.getAttribute('classes')).join(' ');
235
245
  ctx.openGroup(classString, this.getAttribute('id'));
236
246
  ctx.setFont(this.textFont);
@@ -290,6 +300,7 @@ export class Annotation extends Modifier {
290
300
  L('Rendering annotation: ', this.text, x, y);
291
301
  ctx.fillText(this.text, x, y);
292
302
  ctx.closeGroup();
303
+ this.restoreStyle();
293
304
  ctx.restore();
294
305
  }
295
306
  }
package/src/beam.ts CHANGED
@@ -37,9 +37,11 @@ function getStemSlope(firstNote: StemmableNote, lastNote: StemmableNote) {
37
37
  return (lastStemTipY - firstStemTipY) / (lastStemX - firstStemX);
38
38
  }
39
39
 
40
- const BEAM_LEFT = 'L';
41
- const BEAM_RIGHT = 'R';
42
- const BEAM_BOTH = 'B';
40
+ export const BEAM_LEFT = 'L';
41
+ export const BEAM_RIGHT = 'R';
42
+ export const BEAM_BOTH = 'B';
43
+
44
+ export type PartialBeamDirection = typeof BEAM_LEFT | typeof BEAM_RIGHT | typeof BEAM_BOTH;
43
45
 
44
46
  /** `Beams` span over a set of `StemmableNotes`. */
45
47
  export class Beam extends Element {
@@ -74,6 +76,15 @@ export class Beam extends Element {
74
76
  private beam_count: number;
75
77
  private unbeamable?: boolean;
76
78
 
79
+ /**
80
+ * Overrides to default beam directions for secondary-level beams that do not
81
+ * connect to any other note. See further explanation at
82
+ * `setPartialBeamSideAt`
83
+ */
84
+ private forcedPartialDirections: {
85
+ [noteIndex: number]: PartialBeamDirection;
86
+ } = {};
87
+
77
88
  /** Get the direction of the beam */
78
89
  getStemDirection(): number {
79
90
  return this.stem_direction;
@@ -527,6 +538,33 @@ export class Beam extends Element {
527
538
  return this;
528
539
  }
529
540
 
541
+ /**
542
+ * Forces the direction of a partial beam (a secondary-level beam that exists
543
+ * on one note only of the beam group). This is useful in rhythms such as 6/8
544
+ * eighth-sixteenth-eighth-sixteenth, where the direction of the beam on the
545
+ * first sixteenth note can help imply whether the rhythm is to be felt as
546
+ * three groups of eighth notes (typical) or as two groups of three-sixteenths
547
+ * (less common):
548
+ * ```
549
+ * ┌───┬──┬──┐ ┌──┬──┬──┐
550
+ * │ ├─ │ ─┤ vs │ ─┤ │ ─┤
551
+ * │ │ │ │ │ │ │ │
552
+ * ```
553
+ */
554
+ setPartialBeamSideAt(noteIndex: number, side: PartialBeamDirection) {
555
+ this.forcedPartialDirections[noteIndex] = side;
556
+ return this;
557
+ }
558
+
559
+ /**
560
+ * Restore the default direction of a partial beam (a secondary-level beam
561
+ * that does not connect to any other notes).
562
+ */
563
+ unsetPartialBeamSideAt(noteIndex: number) {
564
+ delete this.forcedPartialDirections[noteIndex];
565
+ return this;
566
+ }
567
+
530
568
  /** Return the y coordinate for linear function. */
531
569
  getSlopeY(x: number, first_x_px: number, first_y_px: number, slope: number): number {
532
570
  return first_y_px + (x - first_x_px) * slope;
@@ -712,11 +750,20 @@ export class Beam extends Element {
712
750
  }
713
751
 
714
752
  /** Return upper level beam direction. */
715
- lookupBeamDirection(duration: string, prev_tick: number, tick: number, next_tick: number): string {
753
+ lookupBeamDirection(
754
+ duration: string,
755
+ prev_tick: number,
756
+ tick: number,
757
+ next_tick: number,
758
+ noteIndex: number
759
+ ): PartialBeamDirection {
716
760
  if (duration === '4') {
717
761
  return BEAM_LEFT;
718
762
  }
719
763
 
764
+ const forcedBeamDirection = this.forcedPartialDirections[noteIndex];
765
+ if (forcedBeamDirection) return forcedBeamDirection;
766
+
720
767
  const lookup_duration = `${Tables.durationToNumber(duration) / 2}`;
721
768
  const prev_note_gets_beam = prev_tick < Tables.durationToTicks(lookup_duration);
722
769
  const next_note_gets_beam = next_tick < Tables.durationToTicks(lookup_duration);
@@ -730,7 +777,7 @@ export class Beam extends Element {
730
777
  return BEAM_RIGHT;
731
778
  }
732
779
 
733
- return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick);
780
+ return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick, noteIndex);
734
781
  }
735
782
 
736
783
  /** Get the x coordinates for the beam lines of specific `duration`. */
@@ -803,7 +850,7 @@ export class Beam extends Element {
803
850
  const prev_tick = prev_note.getIntrinsicTicks();
804
851
  const next_tick = next_note.getIntrinsicTicks();
805
852
  const tick = note.getIntrinsicTicks();
806
- const beam_direction = this.lookupBeamDirection(duration, prev_tick, tick, next_tick);
853
+ const beam_direction = this.lookupBeamDirection(duration, prev_tick, tick, next_tick, i);
807
854
 
808
855
  if ([BEAM_LEFT, BEAM_BOTH].includes(beam_direction)) {
809
856
  current_beam.end = current_beam.start - partial_beam_length;
@@ -851,6 +898,8 @@ export class Beam extends Element {
851
898
  this.notes.forEach((note) => {
852
899
  const stem = note.getStem();
853
900
  if (stem) {
901
+ const stem_x = note.getStemX();
902
+ stem.setNoteHeadXBounds(stem_x, stem_x);
854
903
  ctx.openGroup('stem', note.getAttribute('id') + '-stem');
855
904
  stem.setContext(ctx).draw();
856
905
  ctx.closeGroup();
package/src/easyscore.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { Accidental } from './accidental';
5
5
  import { Articulation } from './articulation';
6
+ import { PartialBeamDirection } from './beam';
6
7
  import { Dot } from './dot';
7
8
  import { Factory } from './factory';
8
9
  import { FretHandFinger } from './frethandfinger';
@@ -501,7 +502,16 @@ export class EasyScore {
501
502
  return result;
502
503
  }
503
504
 
504
- beam(notes: StemmableNote[], options?: { autoStem?: boolean; secondaryBeamBreaks?: number[] }): StemmableNote[] {
505
+ beam(
506
+ notes: StemmableNote[],
507
+ options?: {
508
+ autoStem?: boolean;
509
+ secondaryBeamBreaks?: number[];
510
+ partialBeamDirections?: {
511
+ [noteIndex: number]: PartialBeamDirection;
512
+ };
513
+ }
514
+ ): StemmableNote[] {
505
515
  this.factory.Beam({ notes, options });
506
516
  return notes;
507
517
  }
package/src/factory.ts CHANGED
@@ -6,7 +6,7 @@ import { Accidental } from './accidental';
6
6
  import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation';
7
7
  import { Articulation } from './articulation';
8
8
  import { BarNote } from './barnote';
9
- import { Beam } from './beam';
9
+ import { Beam, PartialBeamDirection } from './beam';
10
10
  import { ChordSymbol } from './chordsymbol';
11
11
  import { ClefNote } from './clefnote';
12
12
  import { Curve, CurveOptions } from './curve';
@@ -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);
@@ -494,9 +494,23 @@ export class Factory {
494
494
  return tuplet;
495
495
  }
496
496
 
497
- Beam(params: { notes: StemmableNote[]; options?: { autoStem?: boolean; secondaryBeamBreaks?: number[] } }): Beam {
497
+ Beam(params: {
498
+ notes: StemmableNote[];
499
+ options?: {
500
+ autoStem?: boolean;
501
+ secondaryBeamBreaks?: number[];
502
+ partialBeamDirections?: {
503
+ [noteIndex: number]: PartialBeamDirection;
504
+ };
505
+ };
506
+ }): Beam {
498
507
  const beam = new Beam(params.notes, params.options?.autoStem).setContext(this.context);
499
508
  beam.breakSecondaryAt(params.options?.secondaryBeamBreaks ?? []);
509
+ if (params.options?.partialBeamDirections) {
510
+ Object.entries(params.options?.partialBeamDirections).forEach(([noteIndex, direction]) => {
511
+ beam.setPartialBeamSideAt(Number(noteIndex), direction);
512
+ });
513
+ }
500
514
  this.renderQ.push(beam);
501
515
  return beam;
502
516
  }
package/src/flow.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Accidental } from './accidental';
2
- import { Annotation } from './annotation';
2
+ import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation';
3
3
  import { Articulation } from './articulation';
4
4
  import { BarNote } from './barnote';
5
5
  import { Beam } from './beam';
@@ -7,16 +7,22 @@ import { Bend } from './bend';
7
7
  import { BoundingBox } from './boundingbox';
8
8
  import { BoundingBoxComputation } from './boundingboxcomputation';
9
9
  import { CanvasContext } from './canvascontext';
10
- import { ChordSymbol } from './chordsymbol';
10
+ import {
11
+ ChordSymbol,
12
+ ChordSymbolHorizontalJustify,
13
+ ChordSymbolVerticalJustify,
14
+ SymbolModifiers,
15
+ SymbolTypes,
16
+ } from './chordsymbol';
11
17
  import { Clef } from './clef';
12
18
  import { ClefNote } from './clefnote';
13
19
  import { Crescendo } from './crescendo';
14
- import { Curve } from './curve';
20
+ import { Curve, CurvePosition } from './curve';
15
21
  import { Dot } from './dot';
16
22
  import { EasyScore } from './easyscore';
17
23
  import { Element } from './element';
18
24
  import { Factory } from './factory';
19
- import { Font, FontModule } from './font';
25
+ import { Font, FontModule, FontStyle, FontWeight } from './font';
20
26
  import { Formatter } from './formatter';
21
27
  import { Fraction } from './fraction';
22
28
  import { FretHandFinger } from './frethandfinger';
@@ -42,20 +48,20 @@ import { Parser } from './parser';
42
48
  import { PedalMarking } from './pedalmarking';
43
49
  import { Registry } from './registry';
44
50
  import { RenderContext } from './rendercontext';
45
- import { Renderer } from './renderer';
51
+ import { Renderer, RendererBackends, RendererLineEndType } from './renderer';
46
52
  import { RepeatNote } from './repeatnote';
47
53
  import { Stave } from './stave';
48
54
  import { Barline, BarlineType } from './stavebarline';
49
55
  import { StaveConnector } from './staveconnector';
50
56
  import { StaveHairpin } from './stavehairpin';
51
57
  import { StaveLine } from './staveline';
52
- import { StaveModifier } from './stavemodifier';
58
+ import { StaveModifier, StaveModifierPosition } from './stavemodifier';
53
59
  import { StaveNote } from './stavenote';
54
60
  import { Repetition } from './staverepetition';
55
61
  import { StaveTempo } from './stavetempo';
56
62
  import { StaveText } from './stavetext';
57
63
  import { StaveTie } from './stavetie';
58
- import { Volta } from './stavevolta';
64
+ import { Volta, VoltaType } from './stavevolta';
59
65
  import { Stem } from './stem';
60
66
  import { StringNumber } from './stringnumber';
61
67
  import { Stroke } from './strokes';
@@ -66,10 +72,10 @@ import { TabNote } from './tabnote';
66
72
  import { TabSlide } from './tabslide';
67
73
  import { TabStave } from './tabstave';
68
74
  import { TabTie } from './tabtie';
69
- import { TextBracket } from './textbracket';
75
+ import { TextBracket, TextBracketPosition } from './textbracket';
70
76
  import { TextDynamics } from './textdynamics';
71
77
  import { TextFormatter } from './textformatter';
72
- import { TextNote } from './textnote';
78
+ import { TextJustification, TextNote } from './textnote';
73
79
  import { TickContext } from './tickcontext';
74
80
  import { TimeSignature } from './timesignature';
75
81
  import { TimeSigNote } from './timesignote';
@@ -79,7 +85,7 @@ import { Tuplet } from './tuplet';
79
85
  import { DATE, ID, VERSION } from './version';
80
86
  import { Vibrato } from './vibrato';
81
87
  import { VibratoBracket } from './vibratobracket';
82
- import { Voice } from './voice';
88
+ import { Voice, VoiceMode } from './voice';
83
89
 
84
90
  export class Flow {
85
91
  static get BUILD() {
@@ -112,13 +118,6 @@ export class Flow {
112
118
  static EasyScore = EasyScore;
113
119
  static Element = Element;
114
120
  static Factory = Factory;
115
- static get Flow() {
116
- // This (circular reference) provides a handy shortcut for importing VexFlow via `require()`.
117
- // For example:
118
- // const Vex = require('vexflow');
119
- // const { Flow, Stave, StaveNote, Formatter, Renderer } = Vex.Flow;
120
- return Flow;
121
- }
122
121
  static Font = Font;
123
122
  static Formatter = Formatter;
124
123
  static Fraction = Fraction;
@@ -181,10 +180,26 @@ export class Flow {
181
180
  static Voice = Voice;
182
181
  static Volta = Volta;
183
182
 
184
- // enums need to be exported too!
185
- static BarlineType = BarlineType;
183
+ // Exported Enums.
184
+ // Sorted by the module / file they are exported from.
185
+ static AnnotationHorizontalJustify = AnnotationHorizontalJustify;
186
+ static AnnotationVerticalJustify = AnnotationVerticalJustify;
187
+ static ChordSymbolHorizontalJustify = ChordSymbolHorizontalJustify;
188
+ static ChordSymbolVerticalJustify = ChordSymbolVerticalJustify;
189
+ static SymbolTypes = SymbolTypes;
190
+ static SymbolModifiers = SymbolModifiers;
191
+ static CurvePosition = CurvePosition;
192
+ static FontWeight = FontWeight;
193
+ static FontStyle = FontStyle;
186
194
  static ModifierPosition = ModifierPosition;
187
- // ... more to come ...
195
+ static RendererBackends = RendererBackends;
196
+ static RendererLineEndType = RendererLineEndType;
197
+ static BarlineType = BarlineType;
198
+ static StaveModifierPosition = StaveModifierPosition;
199
+ static VoltaType = VoltaType;
200
+ static TextBracketPosition = TextBracketPosition;
201
+ static TextJustification = TextJustification;
202
+ static VoiceMode = VoiceMode;
188
203
 
189
204
  /**
190
205
  * Examples:
package/src/font.ts CHANGED
@@ -366,10 +366,6 @@ export class Font {
366
366
  }
367
367
  }
368
368
 
369
- static loadTextFonts(): void {
370
- //
371
- }
372
-
373
369
  /**
374
370
  * @param fontName
375
371
  * @param data optionally set the Font object's `.data` property.
package/src/formatter.ts CHANGED
@@ -771,12 +771,13 @@ export class Formatter {
771
771
  const musicFont = Tables.currentMusicFont();
772
772
  const configMinPadding = musicFont.lookupMetric('stave.endPaddingMin');
773
773
  const configMaxPadding = musicFont.lookupMetric('stave.endPaddingMax');
774
+ const leftPadding = musicFont.lookupMetric('stave.padding');
774
775
  let targetWidth = adjustedJustifyWidth;
775
776
  const distances = calculateIdealDistances(targetWidth);
776
777
  let actualWidth = shiftToIdealDistances(distances);
777
- // Calculate right justification by finding max of (configured value, min distance between tickables)
778
- // so measures with lots of white space use it evenly, and crowded measures use at least the configured
779
- // space.
778
+
779
+ // Just one context. Done formatting.
780
+ if (contextList.length === 1) return 0;
780
781
  const calcMinDistance = (targetWidth: number, distances: Distance[]) => {
781
782
  let mdCalc = targetWidth / 2;
782
783
  if (distances.length > 1) {
@@ -788,14 +789,27 @@ export class Formatter {
788
789
  };
789
790
  const minDistance = calcMinDistance(targetWidth, distances);
790
791
 
791
- // Just one context. Done formatting.
792
- if (contextList.length === 1) return 0;
793
-
794
792
  // right justify to either the configured padding, or the min distance between notes, whichever is greatest.
795
793
  // This * 2 keeps the existing formatting unless there is 'a lot' of extra whitespace, which won't break
796
794
  // existing visual regression tests.
797
- const paddingMax = configMaxPadding * 2 < minDistance ? minDistance : configMaxPadding;
798
- const paddingMin = paddingMax - (configMaxPadding - configMinPadding);
795
+ const paddingMaxCalc = (curTargetWidth: number) => {
796
+ let lastTickablePadding = 0;
797
+ const lastTickable = lastContext && lastContext.getMaxTickable();
798
+ if (lastTickable) {
799
+ const voice = lastTickable.getVoice();
800
+ // If the number of actual ticks in the measure <> configured ticks, right-justify
801
+ // because the softmax won't yield the correct value
802
+ if (voice.getTicksUsed().value() > voice.getTotalTicks().value()) {
803
+ return configMaxPadding * 2 < minDistance ? minDistance : configMaxPadding;
804
+ }
805
+ const tickWidth = lastTickable.getWidth();
806
+ lastTickablePadding =
807
+ voice.softmax(lastContext.getMaxTicks().value()) * curTargetWidth - (tickWidth + leftPadding);
808
+ }
809
+ return configMaxPadding * 2 < lastTickablePadding ? lastTickablePadding : configMaxPadding;
810
+ };
811
+ let paddingMax = paddingMaxCalc(targetWidth);
812
+ let paddingMin = paddingMax - (configMaxPadding - configMinPadding);
799
813
  const maxX = adjustedJustifyWidth - paddingMin;
800
814
 
801
815
  let iterations = maxIterations;
@@ -803,6 +817,8 @@ export class Formatter {
803
817
  // without going over
804
818
  while ((actualWidth > maxX && iterations > 0) || (actualWidth + paddingMax < maxX && iterations > 1)) {
805
819
  targetWidth -= actualWidth - maxX;
820
+ paddingMax = paddingMaxCalc(targetWidth);
821
+ paddingMin = paddingMax - (configMaxPadding - configMinPadding);
806
822
  actualWidth = shiftToIdealDistances(calculateIdealDistances(targetWidth));
807
823
  iterations--;
808
824
  }
package/src/glyph.ts CHANGED
@@ -427,11 +427,19 @@ export class Glyph extends Element {
427
427
  return this;
428
428
  }
429
429
 
430
+ getXShift(): number {
431
+ return this.x_shift;
432
+ }
433
+
430
434
  setXShift(x_shift: number): this {
431
435
  this.x_shift = x_shift;
432
436
  return this;
433
437
  }
434
438
 
439
+ getYshift(): number {
440
+ return this.y_shift;
441
+ }
442
+
435
443
  setYShift(y_shift: number): this {
436
444
  this.y_shift = y_shift;
437
445
  return this;
package/src/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  // [VexFlow](https://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
2
2
  // MIT License
3
3
 
4
- import { Vex } from './vex';
5
-
6
4
  export * from './accidental';
7
5
  export * from './annotation';
8
6
  export * from './articulation';
@@ -89,12 +87,9 @@ export * from './tuning';
89
87
  export * from './tuplet';
90
88
  export * from './typeguard';
91
89
  export * from './util';
92
- // Do not export './version'. It is accessible via Vex.Flow.VERSION & Vex.Flow.BUILD.
90
+ // Do not export './version'. It is accessible via Vex.Flow.BUILD.
91
+ export * from './vex';
93
92
  export * from './vibrato';
94
93
  export * from './vibratobracket';
95
94
  export * from './voice';
96
95
  export * from './web';
97
-
98
- // Export Vex as a named export AND as a default export, to support both ways of importing.
99
- export { Vex };
100
- export default Vex;
package/src/note.ts CHANGED
@@ -224,6 +224,7 @@ export abstract class Note extends Tickable {
224
224
  protected stave?: Stave;
225
225
  public render_options: {
226
226
  draw_stem_through_stave?: boolean;
227
+ draw?: boolean;
227
228
  draw_dots?: boolean;
228
229
  draw_stem?: boolean;
229
230
  y_shift: number;
@@ -575,7 +576,7 @@ export abstract class Note extends Tickable {
575
576
 
576
577
  getLeftParenthesisPx(index: number): number {
577
578
  const props = this.getKeyProps()[index];
578
- return props.displaced ? this.getLeftDisplacedHeadPx() : 0;
579
+ return props.displaced ? this.getLeftDisplacedHeadPx() - this.x_shift : -this.x_shift;
579
580
  }
580
581
 
581
582
  getFirstDotPx(): number {
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/staveline.ts CHANGED
@@ -13,6 +13,7 @@ import { FontInfo } from './font';
13
13
  import { RenderContext } from './rendercontext';
14
14
  import { StaveNote } from './stavenote';
15
15
  import { Tables } from './tables';
16
+ import { TextJustification } from './textnote';
16
17
  import { Category } from './typeguard';
17
18
  import { RuntimeError } from './util';
18
19
 
@@ -62,11 +63,7 @@ export class StaveLine extends Element {
62
63
  BOTTOM: 2,
63
64
  };
64
65
 
65
- static readonly TextJustification = {
66
- LEFT: 1,
67
- CENTER: 2,
68
- RIGHT: 3,
69
- };
66
+ static readonly TextJustification = TextJustification;
70
67
 
71
68
  public render_options: {
72
69
  padding_left: number;