vexflow 5.0.0-alpha.4 → 5.0.0-beta.0

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 (122) hide show
  1. package/README.md +6 -6
  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 +1546 -1393
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +600 -549
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/annotation.js +0 -2
  13. package/build/esm/src/barnote.js +3 -3
  14. package/build/esm/src/beam.js +2 -4
  15. package/build/esm/src/bend.js +11 -3
  16. package/build/esm/src/chordsymbol.js +0 -4
  17. package/build/esm/src/clef.js +0 -2
  18. package/build/esm/src/curve.js +8 -5
  19. package/build/esm/src/element.js +11 -17
  20. package/build/esm/src/factory.js +4 -4
  21. package/build/esm/src/flag.js +20 -0
  22. package/build/esm/src/formatter.js +4 -4
  23. package/build/esm/src/glyphnote.js +0 -2
  24. package/build/esm/src/gracenote.js +0 -2
  25. package/build/esm/src/gracenotegroup.js +17 -8
  26. package/build/esm/src/index.js +1 -0
  27. package/build/esm/src/keysignature.js +38 -31
  28. package/build/esm/src/keysignote.js +1 -1
  29. package/build/esm/src/metrics.js +55 -7
  30. package/build/esm/src/modifier.js +4 -2
  31. package/build/esm/src/notehead.js +6 -1
  32. package/build/esm/src/ornament.js +0 -2
  33. package/build/esm/src/pedalmarking.js +33 -41
  34. package/build/esm/src/stave.js +10 -16
  35. package/build/esm/src/stavebarline.js +2 -3
  36. package/build/esm/src/stavehairpin.js +1 -1
  37. package/build/esm/src/staveline.js +0 -4
  38. package/build/esm/src/stavemodifier.js +0 -2
  39. package/build/esm/src/stavenote.js +16 -28
  40. package/build/esm/src/staverepetition.js +3 -2
  41. package/build/esm/src/stavesection.js +13 -15
  42. package/build/esm/src/stavetempo.js +3 -2
  43. package/build/esm/src/stavetext.js +2 -2
  44. package/build/esm/src/stavetie.js +0 -4
  45. package/build/esm/src/stavevolta.js +3 -2
  46. package/build/esm/src/stem.js +0 -4
  47. package/build/esm/src/stemmablenote.js +5 -6
  48. package/build/esm/src/stringnumber.js +0 -2
  49. package/build/esm/src/svgcontext.js +0 -1
  50. package/build/esm/src/tabnote.js +2 -8
  51. package/build/esm/src/textbracket.js +0 -3
  52. package/build/esm/src/textnote.js +0 -2
  53. package/build/esm/src/timesignature.js +2 -4
  54. package/build/esm/src/timesignote.js +2 -0
  55. package/build/esm/src/tuplet.js +37 -30
  56. package/build/esm/src/version.js +3 -3
  57. package/build/esm/src/vexflow.js +6 -2
  58. package/build/esm/tests/accidental_tests.js +30 -17
  59. package/build/esm/tests/annotation_tests.js +12 -12
  60. package/build/esm/tests/articulation_tests.js +13 -13
  61. package/build/esm/tests/auto_beam_formatting_tests.js +33 -33
  62. package/build/esm/tests/beam_tests.js +1 -1
  63. package/build/esm/tests/bend_tests.js +7 -7
  64. package/build/esm/tests/chordsymbol_tests.js +8 -8
  65. package/build/esm/tests/curve_tests.js +34 -0
  66. package/build/esm/tests/{bach_tests.js → demo_petzold_tests.js} +7 -7
  67. package/build/esm/tests/dot_tests.js +4 -4
  68. package/build/esm/tests/formatter_tests.js +25 -25
  69. package/build/esm/tests/gracenote_tests.js +2 -1
  70. package/build/esm/tests/gracetabnote_tests.js +1 -1
  71. package/build/esm/tests/index.js +1 -1
  72. package/build/esm/tests/key_clef_tests.js +6 -6
  73. package/build/esm/tests/keysignature_tests.js +20 -17
  74. package/build/esm/tests/notehead_tests.js +10 -7
  75. package/build/esm/tests/offscreencanvas_tests.js +1 -1
  76. package/build/esm/tests/ornament_tests.js +8 -8
  77. package/build/esm/tests/pedalmarking_tests.js +27 -0
  78. package/build/esm/tests/percussion_tests.js +6 -3
  79. package/build/esm/tests/renderer_tests.js +1 -1
  80. package/build/esm/tests/rests_tests.js +26 -26
  81. package/build/esm/tests/rhythm_tests.js +15 -15
  82. package/build/esm/tests/stave_tests.js +44 -43
  83. package/build/esm/tests/staveconnector_tests.js +73 -73
  84. package/build/esm/tests/stavehairpin_tests.js +1 -1
  85. package/build/esm/tests/stavemodifier_tests.js +3 -3
  86. package/build/esm/tests/stavenote_tests.js +29 -29
  87. package/build/esm/tests/stringnumber_tests.js +1 -1
  88. package/build/esm/tests/strokes_tests.js +1 -1
  89. package/build/esm/tests/style_tests.js +1 -1
  90. package/build/esm/tests/tabnote_tests.js +7 -7
  91. package/build/esm/tests/tabslide_tests.js +6 -6
  92. package/build/esm/tests/tabstave_tests.js +1 -1
  93. package/build/esm/tests/tabtie_tests.js +8 -8
  94. package/build/esm/tests/textnote_tests.js +1 -1
  95. package/build/esm/tests/threevoice_tests.js +2 -2
  96. package/build/esm/tests/timesignature_tests.js +23 -13
  97. package/build/esm/tests/vibrato_tests.js +3 -3
  98. package/build/esm/tests/voice_tests.js +1 -1
  99. package/build/types/src/bend.d.ts +6 -0
  100. package/build/types/src/curve.d.ts +5 -4
  101. package/build/types/src/element.d.ts +10 -11
  102. package/build/types/src/factory.d.ts +2 -2
  103. package/build/types/src/flag.d.ts +12 -0
  104. package/build/types/src/frethandfinger.d.ts +1 -1
  105. package/build/types/src/index.d.ts +1 -0
  106. package/build/types/src/keysignature.d.ts +7 -7
  107. package/build/types/src/metrics.d.ts +5 -0
  108. package/build/types/src/modifier.d.ts +1 -1
  109. package/build/types/src/pedalmarking.d.ts +2 -2
  110. package/build/types/src/stave.d.ts +1 -3
  111. package/build/types/src/stavebarline.d.ts +1 -1
  112. package/build/types/src/staveline.d.ts +1 -1
  113. package/build/types/src/stavemodifier.d.ts +0 -1
  114. package/build/types/src/staverepetition.d.ts +1 -1
  115. package/build/types/src/stavesection.d.ts +3 -4
  116. package/build/types/src/stavetempo.d.ts +1 -2
  117. package/build/types/src/stavetext.d.ts +1 -2
  118. package/build/types/src/stavevolta.d.ts +1 -2
  119. package/build/types/src/stemmablenote.d.ts +2 -3
  120. package/build/types/src/tuplet.d.ts +2 -12
  121. package/build/types/src/typeguard.d.ts +1 -0
  122. package/package.json +32 -28
@@ -1,38 +1,36 @@
1
+ import { Metrics } from './metrics.js';
1
2
  import { StaveModifier } from './stavemodifier.js';
2
3
  export class StaveSection extends StaveModifier {
3
4
  static get CATEGORY() {
4
5
  return "StaveSection";
5
6
  }
6
- constructor(section, x, yShift, drawRect = true) {
7
+ constructor(section, x = 0, yShift = 0, drawRect = true) {
7
8
  super();
8
- this.setStaveSection(section);
9
+ this.setText(section);
9
10
  this.x = x;
10
11
  this.yShift = yShift;
11
12
  this.drawRect = drawRect;
13
+ this.padding = Metrics.get('StaveSection.padding');
12
14
  }
13
- setStaveSection(section) {
14
- this.text = section;
15
+ setDrawRect(drawRect) {
16
+ this.drawRect = drawRect;
15
17
  return this;
16
18
  }
17
- draw(stave, xShift) {
18
- const borderWidth = 2;
19
- const padding = 2;
19
+ draw() {
20
+ const stave = this.checkStave();
20
21
  const ctx = stave.checkContext();
21
22
  this.setRendered();
22
- ctx.save();
23
- ctx.setLineWidth(borderWidth);
23
+ this.x = stave.getX() + stave.getModifierXShift(this.getPosition());
24
24
  const headroom = -1 * this.textMetrics.actualBoundingBoxDescent;
25
- const width = this.width + 2 * padding;
26
- const height = this.height + 2 * padding;
25
+ const width = this.width + 2 * this.padding;
26
+ const height = this.height + 2 * this.padding;
27
27
  const y = stave.getYForTopText(1.5) + this.yShift;
28
- const x = this.x + xShift;
28
+ const x = this.x + this.xShift;
29
29
  if (this.drawRect) {
30
30
  ctx.beginPath();
31
31
  ctx.rect(x, y - height + headroom, width, height);
32
32
  ctx.stroke();
33
33
  }
34
- this.renderText(ctx, xShift + padding, y - padding);
35
- ctx.restore();
36
- return this;
34
+ this.renderText(ctx, this.xShift + this.padding, y - this.padding);
37
35
  }
38
36
  }
@@ -49,7 +49,9 @@ export class StaveTempo extends StaveModifier {
49
49
  this.tempo = tempo;
50
50
  return this;
51
51
  }
52
- draw(stave, shiftX) {
52
+ draw() {
53
+ const stave = this.checkStave();
54
+ const shiftX = stave.getModifierXShift(this.getPosition());
53
55
  const ctx = stave.checkContext();
54
56
  this.setRendered();
55
57
  const { name, duration, dots, bpm, duration2, dots2, parenthesis } = this.tempo;
@@ -104,6 +106,5 @@ export class StaveTempo extends StaveModifier {
104
106
  elText.renderText(ctx, x + this.xShift, y + this.yShift);
105
107
  }
106
108
  }
107
- return this;
108
109
  }
109
110
  }
@@ -14,7 +14,8 @@ export class StaveText extends StaveModifier {
14
14
  this.position = position;
15
15
  this.justification = (_c = options.justification) !== null && _c !== void 0 ? _c : TextNote.Justification.CENTER;
16
16
  }
17
- draw(stave) {
17
+ draw() {
18
+ const stave = this.checkStave();
18
19
  const ctx = stave.checkContext();
19
20
  this.setRendered();
20
21
  let x;
@@ -50,6 +51,5 @@ export class StaveText extends StaveModifier {
50
51
  throw new RuntimeError('InvalidPosition', 'Value Must be in Modifier.Position.');
51
52
  }
52
53
  this.renderText(ctx, x, y + 4);
53
- return this;
54
54
  }
55
55
  }
@@ -74,7 +74,6 @@ export class StaveTie extends Element {
74
74
  const yShift = this.renderOptions.yShift * params.direction;
75
75
  const firstIndexes = this.notes.firstIndexes;
76
76
  const lastIndexes = this.notes.lastIndexes;
77
- this.applyStyle();
78
77
  ctx.openGroup('stavetie', this.getAttribute('id'));
79
78
  for (let i = 0; i < firstIndexes.length; ++i) {
80
79
  const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
@@ -93,7 +92,6 @@ export class StaveTie extends Element {
93
92
  ctx.fill();
94
93
  }
95
94
  ctx.closeGroup();
96
- this.restoreStyle();
97
95
  }
98
96
  renderTieText(firstX, lastX) {
99
97
  var _a, _b, _c;
@@ -102,10 +100,8 @@ export class StaveTie extends Element {
102
100
  centerX -= ctx.measureText(this.text).width / 2;
103
101
  const stave = (_b = (_a = this.notes.firstNote) === null || _a === void 0 ? void 0 : _a.checkStave()) !== null && _b !== void 0 ? _b : (_c = this.notes.lastNote) === null || _c === void 0 ? void 0 : _c.checkStave();
104
102
  if (stave) {
105
- ctx.save();
106
103
  ctx.setFont(this.fontInfo);
107
104
  ctx.fillText(this.text, centerX + this.renderOptions.textShiftX, stave.getYForTopText() - 1);
108
- ctx.restore();
109
105
  }
110
106
  }
111
107
  getNotes() {
@@ -21,7 +21,9 @@ export class Volta extends StaveModifier {
21
21
  this.yShift = yShift;
22
22
  this.text = label;
23
23
  }
24
- draw(stave, x) {
24
+ draw() {
25
+ const stave = this.checkStave();
26
+ const x = stave.getModifierXShift(this.getPosition());
25
27
  const ctx = stave.checkContext();
26
28
  this.setRendered();
27
29
  let width = stave.getWidth() - x;
@@ -47,6 +49,5 @@ export class Volta extends StaveModifier {
47
49
  this.renderText(ctx, x + 5, topY - this.yShift + 15);
48
50
  }
49
51
  ctx.fillRect(this.x + x, topY, width, 1);
50
- return this;
51
52
  }
52
53
  }
@@ -120,8 +120,6 @@ export class Stem extends Element {
120
120
  const stemHeight = this.getHeight();
121
121
  L('Rendering stem - ', 'Top Y: ', this.yTop, 'Bottom Y: ', this.yBottom);
122
122
  const stemletYOffset = this.isStemlet ? stemHeight - this.stemletHeight * this.stemDirection : 0;
123
- ctx.save();
124
- this.applyStyle();
125
123
  ctx.openGroup('stem', this.getAttribute('id'));
126
124
  ctx.beginPath();
127
125
  ctx.setLineWidth(Stem.WIDTH);
@@ -129,8 +127,6 @@ export class Stem extends Element {
129
127
  ctx.lineTo(stemX, stemY - stemHeight - this.renderHeightAdjustment * stemDirection);
130
128
  ctx.stroke();
131
129
  ctx.closeGroup();
132
- this.restoreStyle();
133
- ctx.restore();
134
130
  }
135
131
  }
136
132
  Stem.DEBUG = false;
@@ -1,4 +1,4 @@
1
- import { Element } from './element.js';
1
+ import { Flag } from './flag.js';
2
2
  import { Glyphs } from './glyphs.js';
3
3
  import { Note } from './note.js';
4
4
  import { Stem } from './stem.js';
@@ -10,8 +10,7 @@ export class StemmableNote extends Note {
10
10
  }
11
11
  constructor(noteStruct) {
12
12
  super(noteStruct);
13
- this.flag = new Element();
14
- this.flagStyle = {};
13
+ this.flag = new Flag();
15
14
  }
16
15
  getStem() {
17
16
  return this.stem;
@@ -24,7 +23,7 @@ export class StemmableNote extends Note {
24
23
  }
25
24
  setStem(stem) {
26
25
  this.stem = stem;
27
- this.addChildElement(stem);
26
+ this.addChild(stem);
28
27
  return this;
29
28
  }
30
29
  buildStem() {
@@ -38,7 +37,7 @@ export class StemmableNote extends Note {
38
37
  if (this.hasFlag()) {
39
38
  const flagCode = this.getStemDirection() === Stem.DOWN
40
39
  ? String.fromCodePoint(((_b = (_a = glyphProps.codeFlagUp) === null || _a === void 0 ? void 0 : _a.codePointAt(0)) !== null && _b !== void 0 ? _b : -1) + 1)
41
- : (_c = glyphProps.codeFlagUp) !== null && _c !== void 0 ? _c : Glyphs.null;
40
+ : ((_c = glyphProps.codeFlagUp) !== null && _c !== void 0 ? _c : Glyphs.null);
42
41
  this.flag.setText(flagCode);
43
42
  this.flag.fontInfo = this.fontInfo;
44
43
  }
@@ -180,6 +179,6 @@ export class StemmableNote extends Note {
180
179
  this.checkContext();
181
180
  this.setRendered();
182
181
  this.setStem(new Stem(stemOptions));
183
- (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setContext(this.getContext()).draw();
182
+ (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setContext(this.getContext()).drawWithStyle();
184
183
  }
185
184
  }
@@ -186,7 +186,6 @@ export class StringNumber extends Modifier {
186
186
  default:
187
187
  throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid`);
188
188
  }
189
- ctx.save();
190
189
  if (this.drawCircle) {
191
190
  ctx.beginPath();
192
191
  ctx.arc(dotX, dotY, this.radius, 0, Math.PI * 2, false);
@@ -225,6 +224,5 @@ export class StringNumber extends Modifier {
225
224
  break;
226
225
  }
227
226
  }
228
- ctx.restore();
229
227
  }
230
228
  }
@@ -177,7 +177,6 @@ export class SVGContext extends RenderContext {
177
177
  while (this.svg.lastChild) {
178
178
  this.svg.removeChild(this.svg.lastChild);
179
179
  }
180
- this.scale(this.state.scaleX, this.state.scaleY);
181
180
  }
182
181
  rect(x, y, width, height, attributes) {
183
182
  if (height < 0) {
@@ -207,9 +207,7 @@ export class TabNote extends StemmableNote {
207
207
  this.getStemY() - this.checkStem().getHeight() - this.getStemExtension()
208
208
  :
209
209
  this.getStemY() - this.checkStem().getHeight() + this.getStemExtension();
210
- this.applyStyle(context, this.flagStyle);
211
- this.flag.renderText(context, flagX, flagY);
212
- this.restoreStyle(context, this.flagStyle);
210
+ this.flag.setContext(context).setX(flagX).setY(flagY).drawWithStyle();
213
211
  }
214
212
  }
215
213
  drawModifiers() {
@@ -232,7 +230,6 @@ export class TabNote extends StemmableNote {
232
230
  const stringsUsed = this.positions.map((position) => Number(position.str));
233
231
  const unusedStrings = getUnusedStringGroups(numLines, stringsUsed);
234
232
  const stemLines = getPartialStemLines(stemY, unusedStrings, this.checkStave(), this.getStemDirection());
235
- ctx.save();
236
233
  ctx.setLineWidth(Stem.WIDTH);
237
234
  stemLines.forEach((bounds) => {
238
235
  if (bounds.length === 0)
@@ -243,7 +240,6 @@ export class TabNote extends StemmableNote {
243
240
  ctx.stroke();
244
241
  ctx.closePath();
245
242
  });
246
- ctx.restore();
247
243
  }
248
244
  }
249
245
  drawPositions() {
@@ -265,18 +261,16 @@ export class TabNote extends StemmableNote {
265
261
  }
266
262
  this.setRendered();
267
263
  const renderStem = this.beam === undefined && this.renderOptions.drawStem;
268
- this.applyStyle();
269
264
  ctx.openGroup('tabnote', this.getAttribute('id'));
270
265
  this.drawPositions();
271
266
  this.drawStemThrough();
272
267
  if (this.stem && renderStem) {
273
268
  const stemX = this.getStemX();
274
269
  this.stem.setNoteHeadXBounds(stemX, stemX);
275
- this.stem.setContext(ctx).draw();
270
+ this.stem.setContext(ctx).drawWithStyle();
276
271
  }
277
272
  this.drawFlag();
278
273
  this.drawModifiers();
279
274
  ctx.closeGroup();
280
- this.restoreStyle();
281
275
  }
282
276
  }
@@ -86,8 +86,6 @@ export class TextBracket extends Element {
86
86
  const stop = { x: this.stop.getAbsoluteX(), y };
87
87
  L('Rendering TextBracket: start:', start, 'stop:', stop, 'y:', y);
88
88
  const bracketHeight = this.renderOptions.bracketHeight * this.position;
89
- ctx.save();
90
- this.applyStyle(ctx);
91
89
  this.textElement.renderText(ctx, start.x, start.y);
92
90
  const mainWidth = this.textElement.getWidth();
93
91
  const mainHeight = this.textElement.getHeight();
@@ -125,7 +123,6 @@ export class TextBracket extends Element {
125
123
  ctx.stroke();
126
124
  ctx.closePath();
127
125
  }
128
- ctx.restore();
129
126
  }
130
127
  }
131
128
  TextBracket.DEBUG = false;
@@ -103,7 +103,6 @@ export class TextNote extends Note {
103
103
  x -= width;
104
104
  }
105
105
  const y = stave.getYForLine(this.line + -3);
106
- this.applyStyle(ctx);
107
106
  this.renderText(ctx, x, y);
108
107
  const height = this.getHeight();
109
108
  if (this.superscript) {
@@ -112,7 +111,6 @@ export class TextNote extends Note {
112
111
  if (this.subscript) {
113
112
  this.subscript.renderText(ctx, x + this.width + 2, y + height / 2.2 - 1);
114
113
  }
115
- this.restoreStyle(ctx);
116
114
  }
117
115
  }
118
116
  TextNote.Justification = TextJustification;
@@ -123,12 +123,12 @@ export class TimeSignature extends StaveModifier {
123
123
  const stave = this.checkStave();
124
124
  const ctx = stave.checkContext();
125
125
  this.setRendered();
126
+ ctx.openGroup('timesignature', this.getAttribute('id'));
126
127
  this.drawAt(ctx, stave, this.x);
128
+ ctx.closeGroup();
127
129
  }
128
130
  drawAt(ctx, stave, x) {
129
131
  this.setRendered();
130
- this.applyStyle(ctx);
131
- ctx.openGroup('timesignature', this.getAttribute('id'));
132
132
  if (this.isNumeric) {
133
133
  let startX = x + this.topStartX;
134
134
  let y = 0;
@@ -144,7 +144,5 @@ export class TimeSignature extends StaveModifier {
144
144
  else {
145
145
  this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
146
146
  }
147
- ctx.closeGroup();
148
- this.restoreStyle(ctx);
149
147
  }
150
148
  }
@@ -21,6 +21,8 @@ export class TimeSigNote extends Note {
21
21
  const stave = this.checkStave();
22
22
  const ctx = this.checkContext();
23
23
  this.setRendered();
24
+ ctx.openGroup('timesignote', this.getAttribute('id'));
24
25
  this.timeSig.drawAt(ctx, stave, this.getAbsoluteX());
26
+ ctx.closeGroup();
25
27
  }
26
28
  }
@@ -1,6 +1,7 @@
1
1
  import { Element } from './element.js';
2
2
  import { Formatter } from './formatter.js';
3
3
  import { Glyphs } from './glyphs.js';
4
+ import { Metrics } from './metrics.js';
4
5
  import { Stem } from './stem.js';
5
6
  import { Tables } from './tables.js';
6
7
  import { RuntimeError } from './util.js';
@@ -22,20 +23,25 @@ export class Tuplet extends Element {
22
23
  if (!notes || !notes.length) {
23
24
  throw new RuntimeError('BadArguments', 'No notes provided for tuplet.');
24
25
  }
25
- this.options = options;
26
26
  this.notes = notes;
27
- this.numNotes = this.options.numNotes !== undefined ? this.options.numNotes : notes.length;
28
- this.notesOccupied = this.options.notesOccupied || 2;
29
- if (this.options.bracketed !== undefined) {
30
- this.bracketed = this.options.bracketed;
31
- }
32
- else {
33
- this.bracketed = notes.some((note) => !note.hasBeam());
34
- }
35
- this.ratioed =
36
- this.options.ratioed !== undefined ? this.options.ratioed : Math.abs(this.notesOccupied - this.numNotes) > 1;
27
+ const numNotes = options.numNotes !== undefined ? options.numNotes : notes.length;
28
+ const notesOccupied = options.notesOccupied || 2;
29
+ const bracketed = options.bracketed !== undefined ? options.bracketed : notes.some((note) => !note.hasBeam());
30
+ const ratioed = options.ratioed !== undefined ? options.ratioed : Math.abs(notesOccupied - numNotes) > 1;
31
+ const location = options.location || Tuplet.LOCATION_TOP;
32
+ const yOffset = options.yOffset || Metrics.get('Tuplet.yOffset');
33
+ const textYOffset = options.textYOffset || Metrics.get('Tuplet.textYOffset');
34
+ this.options = {
35
+ bracketed,
36
+ location,
37
+ notesOccupied,
38
+ numNotes,
39
+ ratioed,
40
+ yOffset,
41
+ textYOffset,
42
+ };
37
43
  this.textElement = new Element('Tuplet');
38
- this.setTupletLocation(this.options.location || Tuplet.LOCATION_TOP);
44
+ this.setTupletLocation(location || Tuplet.LOCATION_TOP);
39
45
  Formatter.AlignRestsToNotes(notes, true, true);
40
46
  this.resolveGlyphs();
41
47
  this.attach();
@@ -53,11 +59,11 @@ export class Tuplet extends Element {
53
59
  }
54
60
  }
55
61
  setBracketed(bracketed) {
56
- this.bracketed = !!bracketed;
62
+ this.options.bracketed = bracketed;
57
63
  return this;
58
64
  }
59
65
  setRatioed(ratioed) {
60
- this.ratioed = !!ratioed;
66
+ this.options.ratioed = ratioed;
61
67
  return this;
62
68
  }
63
69
  setTupletLocation(location) {
@@ -65,34 +71,34 @@ export class Tuplet extends Element {
65
71
  console.warn(`Invalid tuplet location [${location}]. Using Tuplet.LOCATION_TOP.`);
66
72
  location = Tuplet.LOCATION_TOP;
67
73
  }
68
- this.location = location;
74
+ this.options.location = location;
69
75
  return this;
70
76
  }
71
77
  getNotes() {
72
78
  return this.notes;
73
79
  }
74
80
  getNoteCount() {
75
- return this.numNotes;
81
+ return this.options.numNotes;
76
82
  }
77
83
  getNotesOccupied() {
78
- return this.notesOccupied;
84
+ return this.options.notesOccupied;
79
85
  }
80
86
  setNotesOccupied(notes) {
81
87
  this.detach();
82
- this.notesOccupied = notes;
88
+ this.options.notesOccupied = notes;
83
89
  this.resolveGlyphs();
84
90
  this.attach();
85
91
  }
86
92
  resolveGlyphs() {
87
93
  let numerator = '';
88
94
  let denominator = '';
89
- let n = this.numNotes;
95
+ let n = this.options.numNotes;
90
96
  while (n >= 1) {
91
97
  numerator = String.fromCharCode(0xe880 + (n % 10)) + numerator;
92
98
  n = Math.floor(n / 10);
93
99
  }
94
- if (this.ratioed) {
95
- n = this.notesOccupied;
100
+ if (this.options.ratioed) {
101
+ n = this.options.notesOccupied;
96
102
  while (n >= 1) {
97
103
  denominator = String.fromCharCode(0xe880 + (n % 10)) + denominator;
98
104
  n = Math.floor(n / 10);
@@ -102,12 +108,12 @@ export class Tuplet extends Element {
102
108
  this.textElement.setText(numerator + denominator);
103
109
  }
104
110
  getNestedTupletCount() {
105
- const location = this.location;
111
+ const { location } = this.options;
106
112
  const firstNote = this.notes[0];
107
113
  let maxTupletCount = countTuplets(firstNote, location);
108
114
  let minTupletCount = countTuplets(firstNote, location);
109
115
  function countTuplets(note, location) {
110
- return note.getTupletStack().filter((tuplet) => tuplet.location === location).length;
116
+ return note.getTupletStack().filter((tuplet) => tuplet.options.location === location).length;
111
117
  }
112
118
  this.notes.forEach((note) => {
113
119
  const tupletCount = countTuplets(note, location);
@@ -118,11 +124,11 @@ export class Tuplet extends Element {
118
124
  }
119
125
  getYPosition() {
120
126
  var _a;
121
- const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.location;
127
+ const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.options.location;
122
128
  const yOffset = (_a = this.options.yOffset) !== null && _a !== void 0 ? _a : 0;
123
129
  const firstNote = this.notes[0];
124
130
  let yPosition;
125
- if (this.location === Tuplet.LOCATION_TOP) {
131
+ if (this.options.location === Tuplet.LOCATION_TOP) {
126
132
  yPosition = firstNote.checkStave().getYForLine(0) - 1.5 * Tables.STAVE_LINE_DISTANCE;
127
133
  for (let i = 0; i < this.notes.length; ++i) {
128
134
  const note = this.notes[i];
@@ -166,13 +172,14 @@ export class Tuplet extends Element {
166
172
  return yPosition + nestedTupletYOffset + yOffset;
167
173
  }
168
174
  draw() {
175
+ const { location, bracketed, textYOffset } = this.options;
169
176
  const ctx = this.checkContext();
170
177
  let xPos = 0;
171
178
  let yPos = 0;
172
179
  this.setRendered();
173
180
  const firstNote = this.notes[0];
174
181
  const lastNote = this.notes[this.notes.length - 1];
175
- if (!this.bracketed) {
182
+ if (!bracketed) {
176
183
  xPos = firstNote.getStemX();
177
184
  this.width = lastNote.getStemX() - xPos;
178
185
  }
@@ -183,15 +190,15 @@ export class Tuplet extends Element {
183
190
  yPos = this.getYPosition();
184
191
  const notationCenterX = xPos + this.width / 2;
185
192
  const notationStartX = notationCenterX - this.textElement.getWidth() / 2;
186
- if (this.bracketed) {
193
+ if (bracketed) {
187
194
  const lineWidth = this.width / 2 - this.textElement.getWidth() / 2 - 5;
188
195
  if (lineWidth > 0) {
189
196
  ctx.fillRect(xPos, yPos, lineWidth, 1);
190
197
  ctx.fillRect(xPos + this.width / 2 + this.textElement.getWidth() / 2 + 5, yPos, lineWidth, 1);
191
- ctx.fillRect(xPos, yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, this.location * 10);
192
- ctx.fillRect(xPos + this.width, yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, this.location * 10);
198
+ ctx.fillRect(xPos, yPos + (location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, location * 10);
199
+ ctx.fillRect(xPos + this.width, yPos + (location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, location * 10);
193
200
  }
194
201
  }
195
- this.textElement.renderText(ctx, notationStartX, yPos + this.textElement.getHeight() / 2);
202
+ this.textElement.renderText(ctx, notationStartX, yPos + this.textElement.getHeight() / 2 + (location === Tuplet.LOCATION_TOP ? -1 : 1) * textYOffset);
196
203
  }
197
204
  }
@@ -1,3 +1,3 @@
1
- export const VERSION = '5.0.0-alpha.4';
2
- export const ID = 'b71510759a0805f5a61170a47ec293256833eb35';
3
- export const DATE = '2024-06-24T05:25:46.334Z';
1
+ export const VERSION = '5.0.0-beta.0';
2
+ export const ID = '2daeb4def8b685227f2a3c924177b40ddcc5bda3';
3
+ export const DATE = '2024-09-12T19:16:57.446Z';
@@ -104,6 +104,7 @@ export class VexFlow {
104
104
  }
105
105
  static setFonts(...fontNames) {
106
106
  MetricsDefaults.fontFamily = fontNames.join(',');
107
+ Metrics.clear();
107
108
  }
108
109
  static getFonts() {
109
110
  return Metrics.get('fontFamily').split(',');
@@ -157,10 +158,13 @@ export class VexFlow {
157
158
  Tables.STAVE_LINE_DISTANCE = value;
158
159
  }
159
160
  static get STAVE_LINE_THICKNESS() {
160
- return Tables.STAVE_LINE_THICKNESS;
161
+ return MetricsDefaults.Stave.lineWidth;
161
162
  }
162
163
  static set STAVE_LINE_THICKNESS(value) {
163
- Tables.STAVE_LINE_THICKNESS = value;
164
+ MetricsDefaults.Stave.lineWidth = value;
165
+ MetricsDefaults.TabStave.lineWidth = value;
166
+ Metrics.clear('Stave');
167
+ Metrics.clear('TabStave');
164
168
  }
165
169
  static get STEM_HEIGHT() {
166
170
  return Tables.STEM_HEIGHT;
@@ -126,9 +126,11 @@ function formatAccidentalSpaces(options) {
126
126
  duration: '8d',
127
127
  }).addModifier(new Accidental('##'), 0),
128
128
  new StaveNote({
129
- keys: ['b/4'],
129
+ keys: ['Bb/4', 'Bn/4'],
130
130
  duration: '16',
131
- }).addModifier(new Accidental('b'), 0),
131
+ })
132
+ .addModifier(new Accidental('b'), 0)
133
+ .addModifier(new Accidental('n'), 0),
132
134
  new StaveNote({
133
135
  keys: ['f/3'],
134
136
  duration: '8',
@@ -166,9 +168,11 @@ function formatAccidentalSpaces(options) {
166
168
  duration: '16',
167
169
  }),
168
170
  new StaveNote({
169
- keys: ['d/4'],
171
+ keys: ['Db/4', 'Dn/4'],
170
172
  duration: 'q',
171
- }),
173
+ })
174
+ .addModifier(new Accidental('b'), 0)
175
+ .addModifier(new Accidental('n'), 0),
172
176
  ];
173
177
  Dot.buildAndAttach([notes[0]], { all: true });
174
178
  const beams = Beam.generateBeams(notes);
@@ -180,10 +184,10 @@ function formatAccidentalSpaces(options) {
180
184
  const formatter = new Formatter({ softmaxFactor }).joinVoices([voice]);
181
185
  const width = formatter.preCalculateMinTotalWidth([voice]);
182
186
  const stave = new Stave(10, 40, width + 20);
183
- stave.setContext(context).draw();
187
+ stave.setContext(context).drawWithStyle();
184
188
  formatter.format([voice], width);
185
189
  voice.draw(context, stave);
186
- beams.forEach((b) => b.setContext(context).draw());
190
+ beams.forEach((b) => b.setContext(context).drawWithStyle());
187
191
  notes.forEach((note) => Note.plotMetrics(context, note, 30));
188
192
  VexFlowTests.plotLegendForNoteWidth(context, 300, 150);
189
193
  options.assert.ok(true);
@@ -270,7 +274,15 @@ function genAccidentals() {
270
274
  accs.push(String.fromCodePoint(u));
271
275
  }
272
276
  for (let u = 0xe310; u <= 0xe335; u++) {
273
- accs.push(String.fromCodePoint(u));
277
+ switch (u) {
278
+ case 0xe31a:
279
+ case 0xe31b:
280
+ case 0xe31e:
281
+ case 0xe31f:
282
+ break;
283
+ default:
284
+ accs.push(String.fromCodePoint(u));
285
+ }
274
286
  }
275
287
  for (let u = 0xe340; u <= 0xe367; u++) {
276
288
  accs.push(String.fromCodePoint(u));
@@ -309,21 +321,22 @@ function genAccidentals() {
309
321
  }
310
322
  const accidentals = genAccidentals();
311
323
  function cautionary(options) {
312
- const staveCount = 21;
324
+ const staveCount = 20;
325
+ const notesPerStave = 22;
313
326
  const scale = 0.85;
314
- const staveWidth = 840;
327
+ const staveWidth = 900;
328
+ const staveHeight = 75;
315
329
  let i = 0;
316
330
  let j = 0;
317
- const f = VexFlowTests.makeFactory(options, staveWidth + 10, 175 * staveCount + 10);
331
+ const f = VexFlowTests.makeFactory(options, staveWidth + 10, staveHeight * staveCount + 10);
318
332
  f.getContext().scale(scale, scale);
319
333
  const accids = Object.values(accidentals).filter((accid) => accid !== '{' && accid !== '}');
320
- const mod = Math.round(accids.length / staveCount);
321
334
  for (i = 0; i < staveCount; ++i) {
322
- const stave = f.Stave({ x: 0, y: 10 + 100 * i, width: staveWidth / scale });
335
+ const stave = f.Stave({ x: 0, y: 10 + (staveHeight / scale) * i, width: staveWidth / scale });
323
336
  const score = f.EasyScore();
324
337
  const rowMap = [];
325
- for (j = 0; j < mod && j + i * staveCount < accids.length; ++j) {
326
- rowMap.push(accids[j + i * staveCount]);
338
+ for (j = 0; j < notesPerStave && j + i * notesPerStave < accids.length; ++j) {
339
+ rowMap.push(accids[j + i * notesPerStave]);
327
340
  }
328
341
  const notes = rowMap.map((accidType) => f
329
342
  .StaveNote({ keys: ['a/4'], duration: '4', stemDirection: Stem.UP })
@@ -435,8 +448,8 @@ function multiVoice(options) {
435
448
  note1.addToModifierContext(modifierContext);
436
449
  note2.addToModifierContext(modifierContext);
437
450
  new TickContext().addTickable(note1).addTickable(note2).preFormat().setX(x);
438
- note1.setContext(ctx).draw();
439
- note2.setContext(ctx).draw();
451
+ note1.setContext(ctx).drawWithStyle();
452
+ note2.setContext(ctx).drawWithStyle();
440
453
  Note.plotMetrics(ctx, note1, 180);
441
454
  Note.plotMetrics(ctx, note2, 15);
442
455
  }
@@ -444,7 +457,7 @@ function multiVoice(options) {
444
457
  const accid = makeNewAccid(f);
445
458
  const stave = f.Stave({ x: 10, y: 45, width: 420 });
446
459
  const ctx = f.getContext();
447
- stave.draw();
460
+ stave.drawWithStyle();
448
461
  let note1 = f
449
462
  .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: '2', stemDirection: -1 })
450
463
  .addModifier(accid('b'), 0)