vexflow 5.2.0 → 5.3.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 (114) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +2759 -1382
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +1814 -1227
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/accidental.js +10 -3
  12. package/build/esm/src/articulation.js +24 -6
  13. package/build/esm/src/beam.js +158 -28
  14. package/build/esm/src/bend.js +24 -19
  15. package/build/esm/src/curve.js +27 -53
  16. package/build/esm/src/dot.js +13 -4
  17. package/build/esm/src/easyscore/composition.js +40 -1
  18. package/build/esm/src/easyscore/policies.js +34 -6
  19. package/build/esm/src/element.js +4 -0
  20. package/build/esm/src/engravinggeometry.js +150 -0
  21. package/build/esm/src/engravingprofile.js +44 -0
  22. package/build/esm/src/factory.js +15 -7
  23. package/build/esm/src/formatter.js +9 -1
  24. package/build/esm/src/gracenote.js +43 -38
  25. package/build/esm/src/gracenotegroup.js +53 -56
  26. package/build/esm/src/index.js +2 -0
  27. package/build/esm/src/keysignature.js +1 -1
  28. package/build/esm/src/modifiercontext.js +11 -0
  29. package/build/esm/src/notehead.js +11 -6
  30. package/build/esm/src/ornament.js +38 -18
  31. package/build/esm/src/proportionalformatter.js +54 -6
  32. package/build/esm/src/stavenote.js +128 -115
  33. package/build/esm/src/stavetie.js +39 -7
  34. package/build/esm/src/stem.js +26 -11
  35. package/build/esm/src/tickcontext.js +19 -0
  36. package/build/esm/src/timesignature.js +5 -0
  37. package/build/esm/src/tuplet.js +57 -17
  38. package/build/esm/src/version.js +3 -3
  39. package/build/esm/src/vexflow.js +4 -0
  40. package/build/esm/tests/bend_tests.js +14 -1
  41. package/build/esm/tests/curve_tests.js +14 -4
  42. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  43. package/build/esm/tests/demos/drums.js +54 -0
  44. package/build/esm/tests/demos/electric.js +63 -0
  45. package/build/esm/tests/demos/greensleeves.js +90 -0
  46. package/build/esm/tests/demos/joy.js +61 -0
  47. package/build/esm/tests/demos/kesh.js +80 -0
  48. package/build/esm/tests/demos/prelude.js +59 -0
  49. package/build/esm/tests/demos/quartertones.js +50 -0
  50. package/build/esm/tests/demos/saints.js +65 -0
  51. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  52. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  53. package/build/esm/tests/engraving/studies.mjs +279 -0
  54. package/build/esm/tests/formatter_tests.js +10 -1
  55. package/build/esm/tests/index.js +1 -0
  56. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  57. package/build/esm/tests/node/easyscore-tests.mjs +71 -0
  58. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  59. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  60. package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
  61. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  62. package/build/esm/tests/threevoice_tests.js +11 -1
  63. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  64. package/build/esm/tools/audit-dependencies.mjs +61 -0
  65. package/build/esm/tools/score-fixtures.mjs +23 -6
  66. package/build/types/src/accidental.d.ts +4 -0
  67. package/build/types/src/articulation.d.ts +6 -1
  68. package/build/types/src/beam.d.ts +14 -0
  69. package/build/types/src/curve.d.ts +9 -0
  70. package/build/types/src/dot.d.ts +5 -0
  71. package/build/types/src/easyscore/composition.d.ts +19 -0
  72. package/build/types/src/easyscore/policies.d.ts +1 -1
  73. package/build/types/src/element.d.ts +2 -0
  74. package/build/types/src/engravinggeometry.d.ts +31 -0
  75. package/build/types/src/engravingprofile.d.ts +20 -0
  76. package/build/types/src/factory.d.ts +6 -1
  77. package/build/types/src/formatter.d.ts +3 -3
  78. package/build/types/src/gracenote.d.ts +7 -0
  79. package/build/types/src/gracenotegroup.d.ts +7 -2
  80. package/build/types/src/index.d.ts +2 -0
  81. package/build/types/src/modifiercontext.d.ts +4 -0
  82. package/build/types/src/notehead.d.ts +5 -0
  83. package/build/types/src/ornament.d.ts +7 -0
  84. package/build/types/src/proportionalformatter.d.ts +11 -2
  85. package/build/types/src/stavenote.d.ts +20 -2
  86. package/build/types/src/stavetie.d.ts +4 -0
  87. package/build/types/src/stem.d.ts +10 -1
  88. package/build/types/src/tickcontext.d.ts +5 -0
  89. package/build/types/src/timesignature.d.ts +2 -0
  90. package/build/types/src/tuplet.d.ts +5 -48
  91. package/build/types/src/vexflow.d.ts +4 -0
  92. package/changelog/CHANGELOG.md +17 -0
  93. package/package.json +7 -2
  94. package/tests/all.html +277 -0
  95. package/tests/demo_petzold_tests.ts +435 -0
  96. package/tests/demos/drums.ts +55 -0
  97. package/tests/demos/drums.webp +0 -0
  98. package/tests/demos/electric.ts +70 -0
  99. package/tests/demos/electric.webp +0 -0
  100. package/tests/demos/greensleeves.ts +97 -0
  101. package/tests/demos/greensleeves.webp +0 -0
  102. package/tests/demos/joy.ts +65 -0
  103. package/tests/demos/joy.webp +0 -0
  104. package/tests/demos/kesh.ts +86 -0
  105. package/tests/demos/kesh.webp +0 -0
  106. package/tests/demos/prelude.ts +65 -0
  107. package/tests/demos/prelude.webp +0 -0
  108. package/tests/demos/quartertones.ts +51 -0
  109. package/tests/demos/quartertones.webp +0 -0
  110. package/tests/demos/saints.ts +70 -0
  111. package/tests/demos/saints.webp +0 -0
  112. package/tests/flow.html +550 -239
  113. package/tests/fonts.css +493 -0
  114. package/tests/minuet.webp +0 -0
@@ -1,3 +1,4 @@
1
+ import { BoundingBox } from './boundingbox.js';
1
2
  import { Element } from './element.js';
2
3
  import { RuntimeError } from './util.js';
3
4
  export class StaveTie extends Element {
@@ -58,11 +59,10 @@ export class StaveTie extends Element {
58
59
  isPartial() {
59
60
  return !this.notes.firstNote || !this.notes.lastNote;
60
61
  }
61
- renderTie(params) {
62
+ *tieCurves(params) {
62
63
  if (params.firstYs.length === 0 || params.lastYs.length === 0) {
63
64
  throw new RuntimeError('BadArguments', 'No Y-values to render');
64
65
  }
65
- const ctx = this.checkContext();
66
66
  let cp1 = this.renderOptions.cp1;
67
67
  let cp2 = this.renderOptions.cp2;
68
68
  if (Math.abs(params.lastX - params.firstX) < this.renderOptions.shortTieCutoff) {
@@ -74,8 +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
- const clsAttribute = this.getAttribute('class');
78
- ctx.openGroup('stavetie' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
79
77
  for (let i = 0; i < firstIndexes.length; ++i) {
80
78
  const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
81
79
  const firstY = params.firstYs[firstIndexes[i]] + yShift;
@@ -85,10 +83,44 @@ export class StaveTie extends Element {
85
83
  }
86
84
  const topControlPointY = (firstY + lastY) / 2 + cp1 * params.direction;
87
85
  const bottomControlPointY = (firstY + lastY) / 2 + cp2 * params.direction;
86
+ yield {
87
+ x1: params.firstX + firstXShift,
88
+ x2: params.lastX + lastXShift,
89
+ firstY,
90
+ lastY,
91
+ cpX,
92
+ topControlPointY,
93
+ bottomControlPointY,
94
+ };
95
+ }
96
+ }
97
+ getRibbonBounds() {
98
+ this.synchronizeIndexes();
99
+ const curves = this.tieCurves({
100
+ firstX: this.getFirstX(),
101
+ lastX: this.getLastX(),
102
+ firstYs: this.getFirstYs(),
103
+ lastYs: this.getLastYs(),
104
+ direction: this.getDirection(),
105
+ });
106
+ let box;
107
+ for (const { x1, x2, firstY, lastY, topControlPointY, bottomControlPointY } of curves) {
108
+ const top = Math.min(firstY, lastY, topControlPointY, bottomControlPointY);
109
+ const bottom = Math.max(firstY, lastY, topControlPointY, bottomControlPointY);
110
+ const part = new BoundingBox(Math.min(x1, x2), top, Math.abs(x2 - x1), bottom - top);
111
+ box = box ? box.mergeWith(part) : part;
112
+ }
113
+ return box !== null && box !== void 0 ? box : new BoundingBox(this.getFirstX(), this.getFirstYs()[0], 0, 0);
114
+ }
115
+ renderTie(params) {
116
+ const ctx = this.checkContext();
117
+ const clsAttribute = this.getAttribute('class');
118
+ ctx.openGroup('stavetie' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
119
+ for (const { x1, x2, firstY, lastY, cpX, topControlPointY, bottomControlPointY } of this.tieCurves(params)) {
88
120
  ctx.beginPath();
89
- ctx.moveTo(params.firstX + firstXShift, firstY);
90
- ctx.quadraticCurveTo(cpX, topControlPointY, params.lastX + lastXShift, lastY);
91
- ctx.quadraticCurveTo(cpX, bottomControlPointY, params.firstX + firstXShift, firstY);
121
+ ctx.moveTo(x1, firstY);
122
+ ctx.quadraticCurveTo(cpX, topControlPointY, x2, lastY);
123
+ ctx.quadraticCurveTo(cpX, bottomControlPointY, x1, firstY);
92
124
  ctx.closePath();
93
125
  ctx.fill();
94
126
  }
@@ -1,7 +1,8 @@
1
+ import { BoundingBox } from './boundingbox.js';
1
2
  import { Element } from './element.js';
2
3
  import { Metrics } from './metrics.js';
3
4
  import { Tables } from './tables.js';
4
- import { log, RuntimeError } from './util.js';
5
+ import { log } from './util.js';
5
6
  function L(...args) {
6
7
  if (Stem.DEBUG)
7
8
  log('VexFlow.Stem', args);
@@ -71,9 +72,6 @@ export class Stem extends Element {
71
72
  const unsignedHeight = this.yBottom - this.yTop + (Stem.HEIGHT - yOffset + this.stemExtension);
72
73
  return unsignedHeight * this.stemDirection;
73
74
  }
74
- getBoundingBox() {
75
- throw new RuntimeError('NotImplemented', 'getBoundingBox() not implemented.');
76
- }
77
75
  getExtents() {
78
76
  const isStemUp = this.stemDirection === Stem.UP;
79
77
  const ys = [this.yTop, this.yBottom];
@@ -83,6 +81,9 @@ export class Stem extends Element {
83
81
  const stemTipY = innerMostNoteheadY + stemHeight * -this.stemDirection;
84
82
  return { topY: stemTipY, baseY: outerMostNoteheadY };
85
83
  }
84
+ isVisible() {
85
+ return !this.hide;
86
+ }
86
87
  setVisibility(isVisible) {
87
88
  this.hide = !isVisible;
88
89
  return this;
@@ -98,11 +99,7 @@ export class Stem extends Element {
98
99
  adjustHeightForBeam() {
99
100
  this.renderHeightAdjustment = -Stem.WIDTH / 2;
100
101
  }
101
- draw() {
102
- this.setRendered();
103
- if (this.hide)
104
- return;
105
- const ctx = this.checkContext();
102
+ getSegment(x, adjustment = this.renderHeightAdjustment) {
106
103
  let stemX;
107
104
  let stemY;
108
105
  const stemDirection = this.stemDirection;
@@ -120,12 +117,30 @@ export class Stem extends Element {
120
117
  const stemHeight = this.getHeight();
121
118
  L('Rendering stem - ', 'Top Y: ', this.yTop, 'Bottom Y: ', this.yBottom);
122
119
  const stemletYOffset = this.isStemlet ? stemHeight - this.stemletHeight * this.stemDirection : 0;
120
+ return {
121
+ x: x !== null && x !== void 0 ? x : stemX,
122
+ baseY: stemY - stemletYOffset + yBaseOffset,
123
+ tipY: stemY - stemHeight - adjustment * stemDirection,
124
+ };
125
+ }
126
+ getBoundingBox() {
127
+ const { x, baseY, tipY } = this.getSegment();
128
+ if (this.hide)
129
+ return new BoundingBox(x, baseY, 0, 0);
130
+ return new BoundingBox(x - Stem.WIDTH / 2, Math.min(baseY, tipY), Stem.WIDTH, Math.abs(baseY - tipY));
131
+ }
132
+ draw() {
133
+ this.setRendered();
134
+ if (this.hide)
135
+ return;
136
+ const ctx = this.checkContext();
137
+ const { x, baseY, tipY } = this.getSegment();
123
138
  const clsAttribute = this.getAttribute('class');
124
139
  ctx.openGroup('stem' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
125
140
  ctx.beginPath();
126
141
  ctx.setLineWidth(Stem.WIDTH);
127
- ctx.moveTo(stemX, stemY - stemletYOffset + yBaseOffset);
128
- ctx.lineTo(stemX, stemY - stemHeight - this.renderHeightAdjustment * stemDirection);
142
+ ctx.moveTo(x, baseY);
143
+ ctx.lineTo(x, tipY);
129
144
  ctx.stroke();
130
145
  ctx.closeGroup();
131
146
  }
@@ -1,6 +1,25 @@
1
1
  import { Fraction } from './fraction.js';
2
2
  import { RuntimeError, sumArray } from './util.js';
3
3
  export class TickContext {
4
+ static linkTimeline(contexts) {
5
+ contexts.forEach((context, i) => {
6
+ context.nextAttack = contexts[i + 1];
7
+ });
8
+ }
9
+ *through(last) {
10
+ if (this.tickID > last.tickID)
11
+ return;
12
+ yield this;
13
+ if (this === last)
14
+ return;
15
+ let context = this.nextAttack;
16
+ while (context && context.tickID <= last.tickID) {
17
+ yield context;
18
+ if (context === last)
19
+ return;
20
+ context = context.nextAttack;
21
+ }
22
+ }
4
23
  static getNextContext(tContext) {
5
24
  const contexts = tContext.tContexts;
6
25
  const index = contexts.indexOf(tContext);
@@ -34,6 +34,11 @@ export class TimeSignature extends StaveModifier {
34
34
  this.setTimeSig(timeSpec);
35
35
  this.setPadding(padding);
36
36
  }
37
+ setMusicFont(family) {
38
+ for (const element of [this, this.topText, this.botText])
39
+ element.setFont(Object.assign(Object.assign({}, element.fontInfo), { family }));
40
+ return this.setTimeSig(this.timeSpec);
41
+ }
37
42
  static getTimeSigCode(key, smallSig = false) {
38
43
  let code = Glyphs.null;
39
44
  switch (key) {
@@ -1,10 +1,15 @@
1
+ import { Annotation } from './annotation.js';
2
+ import { Articulation } from './articulation.js';
1
3
  import { BoundingBox } from './boundingbox.js';
2
4
  import { Element } from './element.js';
3
5
  import { Formatter } from './formatter.js';
4
6
  import { Glyphs } from './glyphs.js';
5
7
  import { Metrics } from './metrics.js';
8
+ import { Modifier } from './modifier.js';
9
+ import { Ornament } from './ornament.js';
6
10
  import { Stem } from './stem.js';
7
11
  import { Tables } from './tables.js';
12
+ import { isAnnotation } from './typeguard.js';
8
13
  import { RuntimeError } from './util.js';
9
14
  export class Tuplet extends Element {
10
15
  static get CATEGORY() {
@@ -34,7 +39,11 @@ export class Tuplet extends Element {
34
39
  const yOffset = (_a = options.yOffset) !== null && _a !== void 0 ? _a : Metrics.get('Tuplet.yOffset');
35
40
  const textYOffset = (_b = options.textYOffset) !== null && _b !== void 0 ? _b : Metrics.get('Tuplet.textYOffset');
36
41
  const suffix = options.suffix || '';
42
+ if (options.displayRatio &&
43
+ (options.displayRatio.length !== 2 || !options.displayRatio.every((n) => Number.isSafeInteger(n) && n > 0)))
44
+ throw new RuntimeError('BadArguments', 'Tuplet display ratio requires two positive integers.');
37
45
  this.options = {
46
+ displayRatio: options.displayRatio && [...options.displayRatio],
38
47
  bracketed,
39
48
  location,
40
49
  notesOccupied,
@@ -71,6 +80,7 @@ export class Tuplet extends Element {
71
80
  }
72
81
  setRatioed(ratioed) {
73
82
  this.options.ratioed = ratioed;
83
+ this.resolveGlyphs();
74
84
  return this;
75
85
  }
76
86
  setTupletLocation(location) {
@@ -97,15 +107,16 @@ export class Tuplet extends Element {
97
107
  this.attach();
98
108
  }
99
109
  resolveGlyphs() {
110
+ var _a, _b, _c, _d;
100
111
  let numerator = '';
101
112
  let denominator = '';
102
- let n = this.options.numNotes;
113
+ let n = (_b = (_a = this.options.displayRatio) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : this.options.numNotes;
103
114
  while (n >= 1) {
104
115
  numerator = String.fromCharCode(0xe880 + (n % 10)) + numerator;
105
116
  n = Math.floor(n / 10);
106
117
  }
107
118
  if (this.options.ratioed) {
108
- n = this.options.notesOccupied;
119
+ n = (_d = (_c = this.options.displayRatio) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : this.options.notesOccupied;
109
120
  while (n >= 1) {
110
121
  denominator = String.fromCharCode(0xe880 + (n % 10)) + denominator;
111
122
  n = Math.floor(n / 10);
@@ -132,7 +143,7 @@ export class Tuplet extends Element {
132
143
  return maxOffset;
133
144
  }
134
145
  getYPosition() {
135
- var _a;
146
+ var _a, _b, _c;
136
147
  const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.options.location;
137
148
  const yOffset = (_a = this.options.yOffset) !== null && _a !== void 0 ? _a : 0;
138
149
  const firstNote = this.notes[0];
@@ -144,7 +155,7 @@ export class Tuplet extends Element {
144
155
  let modLines = 0;
145
156
  const mc = note.getModifierContext();
146
157
  if (mc) {
147
- modLines = Math.max(modLines, mc.getState().topTextLine);
158
+ modLines = mc.getUnmeasuredTextLines(true);
148
159
  }
149
160
  const modY = note.getYForTopText(modLines) - 2 * Tables.STAVE_LINE_DISTANCE;
150
161
  if (note.hasStem() || note.isRest()) {
@@ -163,7 +174,7 @@ export class Tuplet extends Element {
163
174
  this.notes.forEach((nn) => {
164
175
  const mc = nn.getModifierContext();
165
176
  if (mc) {
166
- lineCheck = Math.max(lineCheck, mc.getState().textLine + 1);
177
+ lineCheck = Math.max(lineCheck, mc.getUnmeasuredTextLines(false) + 1);
167
178
  }
168
179
  });
169
180
  yPosition = firstNote.checkStave().getYForLine(lineCheck) + 2 * Tables.STAVE_LINE_DISTANCE;
@@ -178,16 +189,44 @@ export class Tuplet extends Element {
178
189
  }
179
190
  }
180
191
  }
192
+ const above = this.options.location === Tuplet.LOCATION_TOP;
193
+ const side = above ? Annotation.VerticalJustify.TOP : Annotation.VerticalJustify.BOTTOM;
194
+ const hook = this.options.bracketed ? Metrics.get('Tuplet.bracket.legLength') : this.textElement.getHeight() / 2;
195
+ const padding = hook + firstNote.checkStave().getSpacingBetweenLines() / 4;
196
+ for (const note of this.notes) {
197
+ for (const mark of note.getModifiers()) {
198
+ if (mark.getPosition() !== (above ? Modifier.Position.ABOVE : Modifier.Position.BELOW))
199
+ continue;
200
+ const box = mark instanceof Articulation
201
+ ? mark.getInkBounds()
202
+ : mark instanceof Ornament
203
+ ? mark.getBoundingBox()
204
+ : undefined;
205
+ if (box)
206
+ yPosition = above ? Math.min(yPosition, box.y - padding) : Math.max(yPosition, box.y + box.h + padding);
207
+ }
208
+ const annotations = (_c = (_b = note.getModifierContext()) === null || _b === void 0 ? void 0 : _b.getMembers("Annotation")) !== null && _c !== void 0 ? _c : [];
209
+ for (const mark of annotations) {
210
+ if (!isAnnotation(mark) ||
211
+ mark.getVerticalJustification() !== side ||
212
+ mark.checkAttachedNote().getStave() !== note.getStave())
213
+ continue;
214
+ const baseline = mark.computeY().y + mark.getYShift();
215
+ const ink = mark.getTextMetrics();
216
+ yPosition = above
217
+ ? Math.min(yPosition, baseline - ink.actualBoundingBoxAscent - padding)
218
+ : Math.max(yPosition, baseline + ink.actualBoundingBoxDescent + padding);
219
+ }
220
+ }
181
221
  return yPosition + nestedTupletYOffset + yOffset;
182
222
  }
183
- draw() {
223
+ positionElements() {
184
224
  const { location, bracketed, textYOffset, suffix } = this.options;
185
225
  const bracketPadding = Metrics.get('Tuplet.bracket.padding');
186
226
  const bracketThickness = Metrics.get('Tuplet.bracket.lineWidth');
187
227
  const bracketLegLength = Metrics.get('Tuplet.bracket.legLength');
188
228
  const extraSpacing = Metrics.get('Tuplet.suffix.extraSpacing');
189
229
  const suffixOffsetY = Metrics.get('Tuplet.suffix.suffixOffsetY');
190
- const ctx = this.checkContext();
191
230
  let xPos = 0;
192
231
  let yPos = 0;
193
232
  const firstNote = this.notes[0];
@@ -217,6 +256,15 @@ export class Tuplet extends Element {
217
256
  const notationCenterX = xPos + bodyWidth / 2;
218
257
  const notationStartX = notationCenterX - totalTextWidth / 2;
219
258
  const commonTextY = yPos + this.textElement.getHeight() / 2 + (location === Tuplet.LOCATION_TOP ? -1 : 1) * textYOffset;
259
+ this.textElement.setX(notationStartX).setY(commonTextY);
260
+ if (suffix)
261
+ this.suffixElement.setX(notationStartX + ratioWidth + extraSpacing).setY(commonTextY + suffixOffsetY);
262
+ return { xPos, yPos, bodyWidth, totalTextWidth, bracketPadding, bracketThickness, bracketLegLength };
263
+ }
264
+ draw() {
265
+ const { location, bracketed, suffix } = this.options;
266
+ const { xPos, yPos, bodyWidth, totalTextWidth, bracketPadding, bracketThickness, bracketLegLength } = this.positionElements();
267
+ const ctx = this.checkContext();
220
268
  const clsAttribute = this.getAttribute('class');
221
269
  ctx.openGroup('tuplet' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
222
270
  if (bracketed) {
@@ -229,23 +277,15 @@ export class Tuplet extends Element {
229
277
  ctx.fillRect(xPos + bodyWidth, yPos + (isTupletBottom ? 1 : 0), bracketThickness, location * bracketLegLength);
230
278
  }
231
279
  }
232
- let currentX = notationStartX;
233
- this.textElement.setX(currentX);
234
- this.textElement.setY(commonTextY);
235
280
  this.textElement.renderText(ctx, 0, 0);
236
- currentX += ratioWidth + extraSpacing;
237
- if (suffix) {
238
- const suffixY = commonTextY + suffixOffsetY;
239
- this.suffixElement.setX(currentX);
240
- this.suffixElement.setY(suffixY);
281
+ if (suffix)
241
282
  this.suffixElement.renderText(ctx, 0, 0);
242
- currentX += noteWidth;
243
- }
244
283
  this.drawPointerRect();
245
284
  ctx.closeGroup();
246
285
  this.setRendered();
247
286
  }
248
287
  getBoundingBox() {
288
+ this.positionElements();
249
289
  const { bracketed, suffix } = this.options;
250
290
  const ratioBounding = this.textElement.getBoundingBox();
251
291
  const suffixBounding = this.suffixElement.getBoundingBox();
@@ -1,3 +1,3 @@
1
- export const VERSION = '5.2.0';
2
- export const ID = '8b18873122b9b765ee130661d77692b3606fbcaf';
3
- export const DATE = '2026-11-17T02:51:04.170Z';
1
+ export const VERSION = '5.3.0';
2
+ export const ID = '18f11424bdf291599683d063b18ded0dc840f0e0';
3
+ export const DATE = '2026-11-18T16:43:59.349Z';
@@ -23,6 +23,8 @@ import { Curve, CurvePosition } from './curve.js';
23
23
  import { Dot } from './dot.js';
24
24
  import { EasyScore, EasyScoreError } from './easyscore.js';
25
25
  import { Element } from './element.js';
26
+ import { measureEngraving } from './engravinggeometry.js';
27
+ import { EngravingProfile } from './engravingprofile.js';
26
28
  import { Factory } from './factory.js';
27
29
  import { Font, FontStyle, FontWeight } from './font.js';
28
30
  import { Formatter } from './formatter.js';
@@ -219,6 +221,8 @@ VexFlow.BUILD = {
219
221
  DATE: DATE,
220
222
  INFO: '',
221
223
  };
224
+ VexFlow.measureEngraving = measureEngraving;
225
+ VexFlow.EngravingProfile = EngravingProfile;
222
226
  VexFlow.Accidental = Accidental;
223
227
  VexFlow.Annotation = Annotation;
224
228
  VexFlow.Articulation = Articulation;
@@ -146,7 +146,20 @@ function reverseBends(options, contextBuilder) {
146
146
  .addTickable(note)
147
147
  .preFormat()
148
148
  .setX(75 * i);
149
- note.setStave(stave).setContext(ctx).drawWithStyle();
149
+ const arrowXs = [];
150
+ const quadratic = ctx.quadraticCurveTo.bind(ctx);
151
+ ctx.quadraticCurveTo = (cx, cy, x, y) => {
152
+ arrowXs.push(x);
153
+ return quadratic(cx, cy, x, y);
154
+ };
155
+ try {
156
+ note.setStave(stave).setContext(ctx).drawWithStyle();
157
+ }
158
+ finally {
159
+ ctx.quadraticCurveTo = quadratic;
160
+ }
161
+ if (i < 2)
162
+ options.assert.ok(arrowXs[0] > arrowXs[1], 'Lower string uses the outer curve');
150
163
  Note.plotMetrics(ctx, note, 140);
151
164
  options.assert.ok(true, 'Bend ' + i);
152
165
  }
@@ -22,11 +22,12 @@ function createTest(noteGroup1, noteGroup2, setupCurves) {
22
22
  score.beam(score.notes(...noteGroup1)),
23
23
  score.beam(score.notes(...noteGroup2)),
24
24
  ].reduce(concat);
25
- setupCurves(factory, staveNotes);
25
+ const check = setupCurves(factory, staveNotes);
26
26
  const voices = [score.voice(staveNotes, { time: '4/4' })];
27
27
  factory.Formatter().joinVoices(voices).formatToStave(voices, stave);
28
28
  factory.draw();
29
- options.assert.ok('Simple Curve');
29
+ check === null || check === void 0 ? void 0 : check(options.assert);
30
+ options.assert.ok(true, 'Curve renders');
30
31
  };
31
32
  }
32
33
  const simple = createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8, f5, d5, g5', { stem: 'down' }], (f, notes) => {
@@ -59,16 +60,20 @@ const openingDirUp = createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8, f5
59
60
  openingDirection: 'up',
60
61
  },
61
62
  });
62
- f.Curve({
63
+ const lower = f.Curve({
63
64
  from: notes[4],
64
65
  to: notes[7],
65
66
  options: {
66
67
  openingDirection: 'up',
67
68
  },
68
69
  });
70
+ return (assert) => {
71
+ const tips = [notes[4], notes[7]].map((note) => note.getStemExtents().topY);
72
+ assert.ok(lower.getBoundingBox().getY() > Math.min(...tips), 'Opening-up slur clears the down-stem beam');
73
+ };
69
74
  });
70
75
  const openingDirDown = createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8, f5, d5, g5', { stem: 'down' }], (f, notes) => {
71
- f.Curve({
76
+ const upper = f.Curve({
72
77
  from: notes[0],
73
78
  to: notes[3],
74
79
  options: {
@@ -82,6 +87,11 @@ const openingDirDown = createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8,
82
87
  openingDirection: 'down',
83
88
  },
84
89
  });
90
+ return (assert) => {
91
+ const tips = [notes[0], notes[3]].map((note) => note.getStemExtents().topY);
92
+ const bounds = upper.getBoundingBox();
93
+ assert.ok(bounds.getY() + bounds.getH() < Math.max(...tips), 'Opening-down slur clears the up-stem beam');
94
+ };
85
95
  });
86
96
  const rounded = createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], (f, notes) => {
87
97
  f.Curve({
@@ -0,0 +1,27 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { drums } from './demos/drums.js';
3
+ import { electric } from './demos/electric.js';
4
+ import { greensleeves } from './demos/greensleeves.js';
5
+ import { joy } from './demos/joy.js';
6
+ import { kesh } from './demos/kesh.js';
7
+ import { prelude } from './demos/prelude.js';
8
+ import { quartertones } from './demos/quartertones.js';
9
+ import { saints } from './demos/saints.js';
10
+ const repertoire = [
11
+ { title: 'When the Saints Go Marching In', render: saints, fonts: ['Petaluma'] },
12
+ { title: 'Greensleeves', render: greensleeves },
13
+ { title: 'Prelude in C major', render: prelude },
14
+ { title: 'The Kesh Jig', render: kesh },
15
+ { title: 'Ode to Joy', render: joy },
16
+ { title: 'High Wire', render: electric },
17
+ { title: 'Pocket Change', render: drums },
18
+ { title: 'Narrow Steps', render: quartertones },
19
+ ];
20
+ for (const piece of repertoire) {
21
+ VexFlowTests.register({
22
+ Start() {
23
+ QUnit.module('Demo - ' + piece.title);
24
+ VexFlowTests.runTests(piece.title, piece.render, undefined, piece.fonts);
25
+ },
26
+ });
27
+ }
@@ -0,0 +1,54 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, Modifier, Stem } from '../../src/index.js';
3
+ export function drums(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 350);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ const hat = 'g/5/x2';
7
+ const snare = 'c/5';
8
+ const hand = (...keys) => score.make.note({ keys, duration: '8', stemDirection: Stem.UP });
9
+ const kicks = [
10
+ 'F4/q, D4/q/r, F4/8, F4, D4/q/r',
11
+ 'F4/q., F4/8, F4/q, D4/q/r',
12
+ 'F4/q, D4/q/r, F4/8, F4, D4/q/r',
13
+ 'F4/q, D4/q/r, F4/q, F4',
14
+ ];
15
+ kicks.forEach((kick, i) => {
16
+ const fill = i === 3;
17
+ const hands = [hand(hat), hand(hat), hand(snare, hat), hand(hat)];
18
+ hands[2].addModifier(score.make.articulation({ type: 'accent', position: 'above' }));
19
+ score.beam(hands.slice());
20
+ if (fill) {
21
+ for (const run of [
22
+ [snare, snare, 'e/5'],
23
+ ['d/5', 'a/4', 'a/4'],
24
+ ]) {
25
+ const triplet = run.map((drum) => hand(drum));
26
+ score.beam(triplet);
27
+ score.make.tuplet({ notes: triplet, options: { numNotes: 3, notesOccupied: 2 } });
28
+ hands.push(...triplet);
29
+ }
30
+ }
31
+ else {
32
+ const answer = [hand(hat), hand(snare, hat), hand(snare, hat), hand(hat)];
33
+ answer[1].addModifier(score.make.parenthesis(Modifier.Position.LEFT), 0);
34
+ answer[1].addModifier(score.make.parenthesis(Modifier.Position.RIGHT), 0);
35
+ answer[2].addModifier(score.make.articulation({ type: 'accent', position: 'above' }));
36
+ score.beam(answer);
37
+ hands.push(...answer);
38
+ }
39
+ const feet = score.notes(kick, { stem: 'down' });
40
+ if (i === 0 || i === 2)
41
+ score.beam(feet.slice(2, 4));
42
+ const stave = f
43
+ .System({ x: 16 + (i % 2) * 432, y: 56 + Math.floor(i / 2) * 148, width: 432 })
44
+ .addStave({ voices: [score.voice(hands), score.voice(feet)] });
45
+ if (i % 2 === 0)
46
+ stave.addClef('percussion');
47
+ if (i === 0)
48
+ stave.addTimeSignature('4/4').setTempo({ name: 'In the pocket', duration: 'q', bpm: 92 }, -43);
49
+ if (fill)
50
+ stave.setEndBarType(BarlineType.REPEAT_END);
51
+ });
52
+ f.draw();
53
+ options.assert.ok(true, 'Independent kick and hands finish together after the triplet fill');
54
+ }
@@ -0,0 +1,63 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, Bend, Stem } from '../../src/index.js';
3
+ export function electric(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 380);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ const makeNote = (duration, ...frets) => score.make.tabNote({ duration, stemDirection: Stem.DOWN, positions: frets.map(([str, fret]) => ({ str, fret })) }, true);
7
+ const bars = [
8
+ [
9
+ makeNote('q', [6, 5], [5, 7], [4, 7]),
10
+ makeNote('8', [3, 5]),
11
+ makeNote('8', [3, 7]),
12
+ makeNote('q', [2, 5]),
13
+ makeNote('q', [2, 8]),
14
+ ],
15
+ [makeNote('h', [3, 7]), makeNote('8', [3, 5]), makeNote('8', [3, 7]), makeNote('q', [4, 7])],
16
+ [5, 8, 12, 8, 5, 8, 12, 8].map((fret) => makeNote('8', [1, fret])),
17
+ [makeNote('q', [1, 5]), makeNote('8', [2, 8]), makeNote('8', [2, 5]), makeNote('h', [4, 7], [3, 9], [2, 10])],
18
+ ];
19
+ bars.forEach((notes, i) => {
20
+ const x = 16 + (i % 2) * 432;
21
+ const y = 35 + Math.floor(i / 2) * 176;
22
+ const stave = score.make.tabStave({ x, y, width: 432 });
23
+ if (i % 2 === 0)
24
+ stave.addClef('tab');
25
+ if (i === 0)
26
+ stave.addTimeSignature('4/4').setTempo({ duration: 'q', bpm: 96 }, -8);
27
+ if (i === 3)
28
+ stave.setEndBarType(BarlineType.END);
29
+ const legato = (start, label) => score.make
30
+ .tabTie({ firstNote: notes[start], lastNote: notes[start + 1] }, label)
31
+ .setFont('Arial, Helvetica, sans-serif', 9, 'bold');
32
+ if (i === 0) {
33
+ score.beam(notes.slice(1, 3));
34
+ legato(1, 'H');
35
+ notes[4].addModifier(score.make.vibrato().setVibratoWidth(30));
36
+ }
37
+ else if (i === 1) {
38
+ notes[0].addModifier(score.make.bend([
39
+ { type: Bend.UP, text: 'Full' },
40
+ { type: Bend.DOWN, text: '' },
41
+ ]));
42
+ score.beam(notes.slice(1, 3));
43
+ score.make.tabSlide({ firstNote: notes[1], lastNote: notes[2] });
44
+ }
45
+ else if (i === 2) {
46
+ score.beam(notes.slice(0, 4));
47
+ score.beam(notes.slice(4));
48
+ for (const start of [0, 4]) {
49
+ legato(start, 'H');
50
+ legato(start + 1, 'T');
51
+ legato(start + 2, 'P');
52
+ }
53
+ legato(3, 'P');
54
+ }
55
+ else {
56
+ score.beam(notes.slice(1, 3));
57
+ legato(1, 'P');
58
+ }
59
+ f.System({ x, y, width: 432 }).addStave({ stave, voices: [score.voice(notes)] });
60
+ });
61
+ f.draw();
62
+ options.assert.ok(true, 'Four bars of rhythmic tab with native guitar techniques');
63
+ }