vexflow 5.1.1 → 5.2.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 (96) hide show
  1. package/README.md +8 -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 +2916 -484
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +2761 -451
  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/accidental.js +3 -0
  13. package/build/esm/src/articulation.js +27 -14
  14. package/build/esm/src/beam.js +12 -2
  15. package/build/esm/src/chordkerning.js +98 -0
  16. package/build/esm/src/chordsymbol.js +108 -27
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/clefnote.js +5 -1
  19. package/build/esm/src/dot.js +1 -1
  20. package/build/esm/src/easyscore/composition.js +297 -0
  21. package/build/esm/src/easyscore/elementindex.js +81 -0
  22. package/build/esm/src/easyscore/elements.js +324 -0
  23. package/build/esm/src/easyscore/policies.js +69 -0
  24. package/build/esm/src/easyscore/rhythm.js +42 -0
  25. package/build/esm/src/easyscore.js +448 -26
  26. package/build/esm/src/element.js +13 -2
  27. package/build/esm/src/factory.js +256 -60
  28. package/build/esm/src/formatter.js +32 -4
  29. package/build/esm/src/keysignature.js +9 -1
  30. package/build/esm/src/keysignote.js +2 -2
  31. package/build/esm/src/note.js +5 -0
  32. package/build/esm/src/parenthesis.js +1 -1
  33. package/build/esm/src/parser.js +6 -1
  34. package/build/esm/src/proportionalformatter.js +186 -0
  35. package/build/esm/src/registry.js +27 -0
  36. package/build/esm/src/sheet.js +20 -3
  37. package/build/esm/src/stave.js +9 -2
  38. package/build/esm/src/stavenote.js +12 -12
  39. package/build/esm/src/stemmablenote.js +6 -1
  40. package/build/esm/src/tickable.js +5 -0
  41. package/build/esm/src/tuplet.js +3 -2
  42. package/build/esm/src/version.js +3 -3
  43. package/build/esm/src/vexflow.js +2 -1
  44. package/build/esm/tests/beam_tests.js +35 -0
  45. package/build/esm/tests/easyscore_tests.js +40 -0
  46. package/build/esm/tests/easyscore_types.js +65 -0
  47. package/build/esm/tests/formatter_tests.js +41 -0
  48. package/build/esm/tests/node/chord-kerning-tests.mjs +173 -0
  49. package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
  50. package/build/esm/tests/node/easyscore-tests.mjs +953 -0
  51. package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -0
  52. package/build/esm/tests/node/tool-security-tests.mjs +85 -0
  53. package/build/esm/tools/easyscore-api-audit.mjs +58 -0
  54. package/build/esm/tools/easyscore-composition.mjs +62 -0
  55. package/build/esm/tools/easyscore-example.mjs +16 -0
  56. package/build/esm/tools/easyscore-families.mjs +61 -0
  57. package/build/esm/tools/easyscore-references-example.mjs +26 -0
  58. package/build/esm/tools/easyscore-rhythm.mjs +58 -0
  59. package/build/esm/tools/easyscore-structure.mjs +88 -0
  60. package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
  61. package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
  62. package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
  63. package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
  64. package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
  65. package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
  66. package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
  67. package/build/esm/tools/explorer/catalog.mjs +14 -0
  68. package/build/types/src/accidental.d.ts +2 -0
  69. package/build/types/src/articulation.d.ts +6 -0
  70. package/build/types/src/beam.d.ts +2 -0
  71. package/build/types/src/chordkerning.d.ts +42 -0
  72. package/build/types/src/chordsymbol.d.ts +19 -0
  73. package/build/types/src/clef.d.ts +2 -0
  74. package/build/types/src/easyscore/composition.d.ts +107 -0
  75. package/build/types/src/easyscore/elementindex.d.ts +30 -0
  76. package/build/types/src/easyscore/elements.d.ts +156 -0
  77. package/build/types/src/easyscore/policies.d.ts +12 -0
  78. package/build/types/src/easyscore/rhythm.d.ts +9 -0
  79. package/build/types/src/easyscore.d.ts +153 -11
  80. package/build/types/src/element.d.ts +5 -1
  81. package/build/types/src/factory.d.ts +91 -8
  82. package/build/types/src/formatter.d.ts +7 -1
  83. package/build/types/src/keysignature.d.ts +3 -0
  84. package/build/types/src/keysignote.d.ts +1 -1
  85. package/build/types/src/note.d.ts +2 -0
  86. package/build/types/src/parser.d.ts +5 -0
  87. package/build/types/src/proportionalformatter.d.ts +30 -0
  88. package/build/types/src/registry.d.ts +4 -0
  89. package/build/types/src/stave.d.ts +2 -0
  90. package/build/types/src/stavenote.d.ts +1 -1
  91. package/build/types/src/stemmablenote.d.ts +6 -1
  92. package/build/types/src/tickable.d.ts +2 -0
  93. package/build/types/src/vexflow.d.ts +2 -1
  94. package/changelog/CHANGELOG.md +57 -0
  95. package/package.json +19 -7
  96. package/tests/flow.html +10 -3
@@ -151,6 +151,13 @@ export class KeySignature extends StaveModifier {
151
151
  this.format();
152
152
  return this.width;
153
153
  }
154
+ setClef(clef) {
155
+ if (clef !== undefined)
156
+ Tables.clefProperties(clef);
157
+ this.clefOverride = clef;
158
+ this.formatted = false;
159
+ return this;
160
+ }
154
161
  setKeySig(keySpec, cancelKeySpec, alterKeySpec) {
155
162
  this.formatted = false;
156
163
  this.keySpec = keySpec;
@@ -172,6 +179,7 @@ export class KeySignature extends StaveModifier {
172
179
  }
173
180
  }
174
181
  format() {
182
+ var _a;
175
183
  let stave = this.getStave();
176
184
  if (!stave) {
177
185
  stave = new Stave(0, 0, 100);
@@ -190,7 +198,7 @@ export class KeySignature extends StaveModifier {
190
198
  this.convertToAlterAccList(this.alterKeySpec);
191
199
  }
192
200
  if (this.accList.length > 0) {
193
- const clef = (this.position === StaveModifierPosition.END ? stave.getEndClef() : stave.getClef()) || stave.getClef();
201
+ const clef = (_a = this.clefOverride) !== null && _a !== void 0 ? _a : ((this.position === StaveModifierPosition.END ? stave.getEndClef() : stave.getClef()) || stave.getClef());
194
202
  if (cancelAccList) {
195
203
  this.convertAccLines(clef, cancelAccList.type, cancelAccList.accList);
196
204
  }
@@ -4,9 +4,9 @@ export class KeySigNote extends Note {
4
4
  static get CATEGORY() {
5
5
  return "KeySigNote";
6
6
  }
7
- constructor(keySpec, cancelKeySpec, alterKeySpec) {
7
+ constructor(keySpec, cancelKeySpec, alterKeySpec, clef) {
8
8
  super({ duration: 'b' });
9
- this.keySignature = new KeySignature(keySpec, cancelKeySpec, alterKeySpec);
9
+ this.keySignature = new KeySignature(keySpec, cancelKeySpec, alterKeySpec).setClef(clef);
10
10
  this.ignoreTicks = true;
11
11
  }
12
12
  addToModifierContext(mc) {
@@ -176,6 +176,11 @@ export class Note extends Tickable {
176
176
  getStave() {
177
177
  return this.stave;
178
178
  }
179
+ clearStave() {
180
+ this.stave = undefined;
181
+ this.preFormatted = false;
182
+ return this;
183
+ }
179
184
  checkStave() {
180
185
  return defined(this.stave, 'NoStave', 'No stave attached to instance.');
181
186
  }
@@ -48,7 +48,7 @@ export class Parenthesis extends Modifier {
48
48
  }
49
49
  setNote(note) {
50
50
  this.note = note;
51
- this.setFont(note.getFont());
51
+ this.setFont(note.fontInfo);
52
52
  return this;
53
53
  }
54
54
  draw() {
@@ -18,6 +18,7 @@ function flattenMatches(r) {
18
18
  }
19
19
  export class Parser {
20
20
  constructor(grammar) {
21
+ this.furthestErrorPos = NO_ERROR_POS;
21
22
  this.grammar = grammar;
22
23
  this.line = '';
23
24
  this.pos = 0;
@@ -27,8 +28,10 @@ export class Parser {
27
28
  this.line = line;
28
29
  this.pos = 0;
29
30
  this.errorPos = NO_ERROR_POS;
31
+ this.furthestErrorPos = NO_ERROR_POS;
30
32
  const result = this.expect(this.grammar.begin());
31
33
  result.errorPos = this.errorPos;
34
+ result.furthestErrorPos = result.success ? NO_ERROR_POS : this.furthestErrorPos;
32
35
  return result;
33
36
  }
34
37
  matchFail(returnPos) {
@@ -52,6 +55,7 @@ export class Parser {
52
55
  };
53
56
  }
54
57
  else {
58
+ this.furthestErrorPos = Math.max(this.furthestErrorPos, this.pos);
55
59
  return { success: false, pos: this.pos };
56
60
  }
57
61
  }
@@ -127,6 +131,7 @@ export class Parser {
127
131
  if (!ruleFunc) {
128
132
  throw new RuntimeError('Invalid rule function');
129
133
  }
134
+ const start = this.pos;
130
135
  let result;
131
136
  const rule = ruleFunc.bind(this.grammar)();
132
137
  if (rule.token) {
@@ -156,7 +161,7 @@ export class Parser {
156
161
  result.results.forEach((r) => matches.push(flattenMatches(r)));
157
162
  }
158
163
  if (rule.run && result.success) {
159
- rule.run({ matches });
164
+ rule.run({ matches, start, end: this.pos });
160
165
  }
161
166
  return result;
162
167
  }
@@ -0,0 +1,186 @@
1
+ import { Fraction } from './fraction.js';
2
+ import { TickContext } from './tickcontext.js';
3
+ import { RuntimeError } from './util.js';
4
+ const PADDING = 2;
5
+ const EPSILON = 1e-7;
6
+ function required(value) {
7
+ return (Math.ceil(value * 100) / 100).toFixed(2);
8
+ }
9
+ export class ProportionalFormatter {
10
+ constructor(voices, resolutionMultiplier) {
11
+ var _a;
12
+ var _b;
13
+ this.origin = 0;
14
+ this.tail = PADDING;
15
+ this.minimumScale = 0;
16
+ this.centeredWidth = 0;
17
+ const resolution = voices[0].getActualResolution() / voices[0].getResolutionMultiplier();
18
+ this.quarterTicks = resolution / 4;
19
+ let durationTicks = voices[0].getTotalTicks().value();
20
+ for (const voice of voices) {
21
+ if (voice.getActualResolution() / voice.getResolutionMultiplier() !== resolution) {
22
+ throw new RuntimeError('BadArgument', 'Proportional voices must use the same tick resolution.');
23
+ }
24
+ durationTicks = Math.max(durationTicks, voice.getTicksUsed().value());
25
+ for (const note of voice.getTickables()) {
26
+ if (note.shouldIgnoreTicks())
27
+ continue;
28
+ const ticks = note.getTicks();
29
+ if (ticks.value() <= 0)
30
+ throw new RuntimeError('BadArgument', 'Rhythmic durations must be positive.');
31
+ resolutionMultiplier = Fraction.LCM(resolutionMultiplier, ticks.denominator);
32
+ }
33
+ }
34
+ if (!Number.isSafeInteger(resolutionMultiplier) || resolutionMultiplier <= 0) {
35
+ throw new RuntimeError('BadArgument', 'Proportional timeline exceeds the supported rational tick range.');
36
+ }
37
+ this.duration = durationTicks / this.quarterTicks;
38
+ const byTick = new Map();
39
+ for (const [voiceIndex, voice] of voices.entries()) {
40
+ const elapsed = new Fraction(0, resolutionMultiplier);
41
+ for (const note of voice.getTickables()) {
42
+ const tick = elapsed.numerator;
43
+ if (!Number.isSafeInteger(tick)) {
44
+ throw new RuntimeError('BadArgument', 'Proportional timeline exceeds the supported rational tick range.');
45
+ }
46
+ let anchor = byTick.get(tick);
47
+ if (!anchor) {
48
+ anchor = { tick, context: new TickContext({ tickID: tick }), prefixes: [], extents: new Map() };
49
+ byTick.set(tick, anchor);
50
+ }
51
+ if (note.shouldIgnoreTicks()) {
52
+ const prefix = ((_a = (_b = anchor.prefixes)[voiceIndex]) !== null && _a !== void 0 ? _a : (_b[voiceIndex] = { contexts: [] }));
53
+ prefix.contexts.push(new TickContext({ tickID: tick }).addTickable(note, voiceIndex));
54
+ }
55
+ else {
56
+ anchor.context.addTickable(note, voiceIndex);
57
+ elapsed.add(note.getTicks());
58
+ }
59
+ }
60
+ }
61
+ this.anchors = [...byTick.values()].sort((a, b) => a.tick - b.tick);
62
+ const map = {};
63
+ const array = [];
64
+ for (const anchor of this.anchors) {
65
+ map[anchor.tick] = anchor.context;
66
+ anchor.prefixes.forEach((prefix) => array.push(...prefix.contexts));
67
+ array.push(anchor.context);
68
+ }
69
+ array.forEach((context) => (context.tContexts = array));
70
+ this.contexts = { map, array, list: this.anchors.map((anchor) => anchor.tick), resolutionMultiplier };
71
+ }
72
+ quarters(anchor) {
73
+ return anchor.tick / this.contexts.resolutionMultiplier / this.quarterTicks;
74
+ }
75
+ measure() {
76
+ var _a, _b, _c, _d;
77
+ this.origin = PADDING;
78
+ this.tail = PADDING;
79
+ this.minimumScale = 0;
80
+ this.centeredWidth = 0;
81
+ for (const anchor of this.anchors) {
82
+ anchor.extents.clear();
83
+ anchor.context.preFormat();
84
+ for (const note of anchor.context.getTickables()) {
85
+ const metrics = note.getMetrics();
86
+ const left = metrics.modLeftPx + metrics.leftDisplacedHeadPx;
87
+ const right = metrics.notePx + metrics.modRightPx + metrics.rightDisplacedHeadPx;
88
+ if (note.isCenterAligned()) {
89
+ this.centeredWidth = Math.max(this.centeredWidth, 2 * Math.max(left, right));
90
+ continue;
91
+ }
92
+ const extent = (_a = anchor.extents.get(note.getStave())) !== null && _a !== void 0 ? _a : { left: 0, right: 0 };
93
+ extent.left = Math.max(extent.left, left);
94
+ extent.right = Math.max(extent.right, right);
95
+ anchor.extents.set(note.getStave(), extent);
96
+ }
97
+ const prefixWidths = new Map();
98
+ anchor.prefixes.forEach((prefix) => {
99
+ var _a;
100
+ let width = 0;
101
+ for (const context of prefix.contexts)
102
+ width += context.preFormat().getWidth();
103
+ const stave = prefix.contexts[0].getTickables()[0].getStave();
104
+ prefixWidths.set(stave, Math.max((_a = prefixWidths.get(stave)) !== null && _a !== void 0 ? _a : 0, width));
105
+ });
106
+ for (const [stave, width] of prefixWidths) {
107
+ const extent = (_b = anchor.extents.get(stave)) !== null && _b !== void 0 ? _b : { left: 0, right: 0 };
108
+ extent.left += width;
109
+ anchor.extents.set(stave, extent);
110
+ }
111
+ for (const extent of anchor.extents.values()) {
112
+ if (this.quarters(anchor) === 0)
113
+ this.origin = Math.max(this.origin, extent.left + PADDING);
114
+ if (this.quarters(anchor) === this.duration)
115
+ this.tail = Math.max(this.tail, extent.right + PADDING);
116
+ }
117
+ }
118
+ const previous = new Map();
119
+ for (const anchor of this.anchors) {
120
+ const time = this.quarters(anchor);
121
+ for (const [stave, extent] of anchor.extents) {
122
+ for (const before of (_c = previous.get(stave)) !== null && _c !== void 0 ? _c : []) {
123
+ this.minimumScale = Math.max(this.minimumScale, (before.extent.right + extent.left + PADDING) / (time - before.time));
124
+ }
125
+ if (time > 0)
126
+ this.minimumScale = Math.max(this.minimumScale, (extent.left + PADDING - this.origin) / time);
127
+ if (time < this.duration) {
128
+ this.minimumScale = Math.max(this.minimumScale, (extent.right + PADDING - this.tail) / (this.duration - time));
129
+ }
130
+ const list = (_d = previous.get(stave)) !== null && _d !== void 0 ? _d : [];
131
+ list.push({ time, extent });
132
+ previous.set(stave, list);
133
+ }
134
+ }
135
+ this.minimumScale = Math.max(this.minimumScale, this.centeredWidth / this.duration);
136
+ }
137
+ dimensions(spacing, width) {
138
+ if (!Number.isFinite(width) || width < 0)
139
+ throw new RuntimeError('BadArgument', 'Width must be finite and nonnegative.');
140
+ const requested = spacing.pixelsPerQuarter;
141
+ if (requested !== undefined && (!Number.isFinite(requested) || requested <= 0)) {
142
+ throw new RuntimeError('BadArgument', 'pixelsPerQuarter must be positive and finite.');
143
+ }
144
+ this.measure();
145
+ const minimumWidth = this.origin + this.duration * this.minimumScale + this.tail;
146
+ const scale = requested !== null && requested !== void 0 ? requested : (width > 0 ? (width - this.origin - this.tail) / this.duration : this.minimumScale);
147
+ const neededWidth = this.origin + this.duration * scale + this.tail;
148
+ if (!Number.isFinite(neededWidth) || !Number.isFinite(this.minimumScale)) {
149
+ throw new RuntimeError('BadArgument', 'Proportional dimensions exceed the supported pixel range.');
150
+ }
151
+ if (scale + EPSILON < this.minimumScale || (width > 0 && width + EPSILON < neededWidth)) {
152
+ throw new RuntimeError('InsufficientProportionalSpace', `Proportional spacing requires at least ${required(this.minimumScale)} px/quarter and ` +
153
+ `${required(Math.max(minimumWidth, neededWidth))} px width; received ${scale.toFixed(2)} px/quarter` +
154
+ (width > 0 ? ` and ${width.toFixed(2)} px width.` : '.'));
155
+ }
156
+ return { scale, width: neededWidth };
157
+ }
158
+ minimumWidth(spacing) {
159
+ return this.dimensions(spacing, 0).width;
160
+ }
161
+ format(spacing, width) {
162
+ const dimensions = this.dimensions(spacing, width);
163
+ for (const anchor of this.anchors) {
164
+ const x = this.origin + this.quarters(anchor) * dimensions.scale;
165
+ anchor.context.setX(x);
166
+ anchor.context.getCenterAlignedTickables().forEach((note) => {
167
+ note.setCenterXShift(this.origin + (this.duration * dimensions.scale) / 2 - x);
168
+ });
169
+ anchor.prefixes.forEach((prefix) => {
170
+ const stave = prefix.contexts[0].getTickables()[0].getStave();
171
+ const notes = anchor.context.getTickables().filter((note) => note.getStave() === stave);
172
+ let right = x -
173
+ Math.max(0, ...notes.map((note) => {
174
+ const metrics = note.getMetrics();
175
+ return metrics.modLeftPx + metrics.leftDisplacedHeadPx;
176
+ }));
177
+ for (const context of [...prefix.contexts].reverse()) {
178
+ const metrics = context.getMetrics();
179
+ context.setX(right - PADDING / 2 - metrics.notePx - metrics.totalRightPx);
180
+ right -= context.getWidth();
181
+ }
182
+ });
183
+ }
184
+ return dimensions.width;
185
+ }
186
+ }
@@ -19,7 +19,33 @@ export class Registry {
19
19
  static disableDefaultRegistry() {
20
20
  Registry.defaultRegistry = undefined;
21
21
  }
22
+ transaction(build) {
23
+ const before = new Index();
24
+ for (const name of Object.keys(this.index)) {
25
+ for (const [value, elements] of Object.entries(this.index[name])) {
26
+ before[name][value] = Object.assign(Object.create(null), elements);
27
+ }
28
+ }
29
+ const existing = new Set(Object.values(before.id).flatMap((elements) => Object.values(elements)));
30
+ const created = new Set();
31
+ this.transactions.push(created);
32
+ try {
33
+ return build();
34
+ }
35
+ catch (error) {
36
+ created.forEach((element) => {
37
+ if (!existing.has(element))
38
+ element.onRegister(undefined);
39
+ });
40
+ this.index = before;
41
+ throw error;
42
+ }
43
+ finally {
44
+ this.transactions.pop();
45
+ }
46
+ }
22
47
  constructor() {
48
+ this.transactions = [];
23
49
  this.index = new Index();
24
50
  }
25
51
  clear() {
@@ -53,6 +79,7 @@ export class Registry {
53
79
  if (!id) {
54
80
  throw new RuntimeError("Can't add element without `id` attribute to registry");
55
81
  }
82
+ this.transactions.forEach((transaction) => transaction.add(elem));
56
83
  elem.setAttribute('id', id);
57
84
  this.setIndexValue('id', id, id, elem);
58
85
  this.updateIndex({ id, name: 'type', value: elem.getAttribute('type'), oldValue: undefined });
@@ -1,3 +1,7 @@
1
+ import { ClefNote } from './clefnote.js';
2
+ import { Note } from './note.js';
3
+ import { StaveNote } from './stavenote.js';
4
+ import { StemmableNote } from './stemmablenote.js';
1
5
  import { RuntimeError } from './util.js';
2
6
  export class Sheet {
3
7
  constructor(options) {
@@ -74,9 +78,22 @@ export class Sheet {
74
78
  let bottom = system.getBoundingBox().getH();
75
79
  for (const voice of system.getVoices()) {
76
80
  for (const note of voice.getTickables()) {
77
- const box = note.getBoundingBox();
78
- top = Math.min(top, box.getY());
79
- bottom = Math.max(bottom, box.getY() + box.getH());
81
+ if (note instanceof StaveNote || note instanceof ClefNote) {
82
+ const box = note instanceof StaveNote ? note.getBoundingBox(false) : note.getBoundingBox();
83
+ top = Math.min(top, box.getY());
84
+ bottom = Math.max(bottom, box.getY() + box.getH());
85
+ }
86
+ else if (note instanceof Note) {
87
+ const padding = note.checkStave().getSpacingBetweenLines();
88
+ const ys = note.getYs();
89
+ top = Math.min(top, ...ys.map((y) => y - padding));
90
+ bottom = Math.max(bottom, ...ys.map((y) => y + padding));
91
+ if (note instanceof StemmableNote && note.hasStem()) {
92
+ const { topY, baseY } = note.getStemExtents();
93
+ top = Math.min(top, topY, baseY);
94
+ bottom = Math.max(bottom, topY, baseY);
95
+ }
96
+ }
80
97
  }
81
98
  }
82
99
  return { top, bottom };
@@ -37,6 +37,7 @@ export class Stave extends Element {
37
37
  return Metrics.get('Stave.endPaddingMax');
38
38
  }
39
39
  constructor(x, y, width, options) {
40
+ var _a;
40
41
  super();
41
42
  this.x = x;
42
43
  this.y = y;
@@ -46,9 +47,9 @@ export class Stave extends Element {
46
47
  this.endX = x + width;
47
48
  this.modifiers = [];
48
49
  this.measure = 0;
49
- this.clef = 'treble';
50
+ this.clef = (_a = options === null || options === void 0 ? void 0 : options.clef) !== null && _a !== void 0 ? _a : 'treble';
50
51
  this.endClef = undefined;
51
- this.options = Object.assign({ verticalBarWidth: 10, numLines: 5, leftBar: true, rightBar: true, spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, spaceAboveStaffLn: 4, spaceBelowStaffLn: 4, topTextPosition: 1, bottomTextPosition: 4, lineConfig: [] }, options);
52
+ this.options = Object.assign({ clef: 'treble', verticalBarWidth: 10, numLines: 5, leftBar: true, rightBar: true, spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, spaceAboveStaffLn: 4, spaceBelowStaffLn: 4, topTextPosition: 1, bottomTextPosition: 4, lineConfig: [] }, options);
52
53
  this.bounds = { x: this.x, y: this.y, w: this.width, h: 0 };
53
54
  this.defaultLedgerLineStyle = { lineWidth: 2 };
54
55
  this.resetLines();
@@ -227,6 +228,12 @@ export class Stave extends Element {
227
228
  if (position !== undefined) {
228
229
  modifier.setPosition(position);
229
230
  }
231
+ if (modifier instanceof Clef) {
232
+ if (modifier.getPosition() === StaveModifierPosition.BEGIN)
233
+ this.clef = modifier.getType();
234
+ else if (modifier.getPosition() === StaveModifierPosition.END)
235
+ this.endClef = modifier.getType();
236
+ }
230
237
  modifier.setStave(this);
231
238
  this.formatted = false;
232
239
  this.modifiers.push(modifier);
@@ -157,7 +157,7 @@ export class StaveNote extends StemmableNote {
157
157
  else {
158
158
  if (noteL.stemDirection === 1) {
159
159
  noteL.stemDirection = -1;
160
- noteL.note.setStemDirection(-1);
160
+ noteL.note.setStemDirection(-1, noteL.note.isAutoStem());
161
161
  }
162
162
  }
163
163
  }
@@ -174,11 +174,11 @@ export class StaveNote extends StemmableNote {
174
174
  }
175
175
  else if (noteU.note.hasStem()) {
176
176
  noteU.stemDirection = -noteU.note.getStemDirection();
177
- noteU.note.setStemDirection(noteU.stemDirection);
177
+ noteU.note.setStemDirection(noteU.stemDirection, noteU.note.isAutoStem());
178
178
  }
179
179
  else if (noteL.note.hasStem()) {
180
180
  noteL.stemDirection = -noteL.note.getStemDirection();
181
- noteL.note.setStemDirection(noteL.stemDirection);
181
+ noteL.note.setStemDirection(noteL.stemDirection, noteL.note.isAutoStem());
182
182
  }
183
183
  }
184
184
  }
@@ -199,11 +199,11 @@ export class StaveNote extends StemmableNote {
199
199
  noteM.note.setXShift(xShift);
200
200
  if (noteL.note.hasBeam() === false) {
201
201
  noteL.stemDirection = -1;
202
- noteL.note.setStemDirection(-1);
202
+ noteL.note.setStemDirection(-1, noteL.note.isAutoStem());
203
203
  }
204
204
  if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
205
205
  noteU.stemDirection = 1;
206
- noteU.note.setStemDirection(1);
206
+ noteU.note.setStemDirection(1, noteU.note.isAutoStem());
207
207
  }
208
208
  }
209
209
  state.rightShift += xShift;
@@ -233,11 +233,11 @@ export class StaveNote extends StemmableNote {
233
233
  noteM.note.setXShift(xShift);
234
234
  if (noteL.note.hasBeam() === false) {
235
235
  noteL.stemDirection = -1;
236
- noteL.note.setStemDirection(-1);
236
+ noteL.note.setStemDirection(-1, noteL.note.isAutoStem());
237
237
  }
238
238
  if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
239
239
  noteU.stemDirection = 1;
240
- noteU.note.setStemDirection(1);
240
+ noteU.note.setStemDirection(1, noteU.note.isAutoStem());
241
241
  }
242
242
  }
243
243
  state.rightShift += xShift;
@@ -357,7 +357,7 @@ export class StaveNote extends StemmableNote {
357
357
  return this._noteHeads;
358
358
  }
359
359
  autoStem() {
360
- this.setStemDirection(this.calculateOptimalStemDirection());
360
+ this.setStemDirection(this.calculateOptimalStemDirection(), true);
361
361
  }
362
362
  calculateOptimalStemDirection() {
363
363
  this.minLine = this.sortedKeyProps[0].keyProps.line;
@@ -406,7 +406,7 @@ export class StaveNote extends StemmableNote {
406
406
  });
407
407
  this.sortedKeyProps.sort((a, b) => a.keyProps.line - b.keyProps.line);
408
408
  }
409
- getBoundingBox() {
409
+ getBoundingBox(includeModifiers = true) {
410
410
  const boundingBox = new BoundingBox(this.getAbsoluteX(), this.ys[0], 0, 0);
411
411
  this._noteHeads.forEach((notehead) => {
412
412
  const displacement = notehead.isDisplaced()
@@ -431,9 +431,9 @@ export class StaveNote extends StemmableNote {
431
431
  bbFlag.setY(y + this.flag.getYShift() - this.flag.getTextMetrics().actualBoundingBoxAscent);
432
432
  boundingBox.mergeWith(bbFlag);
433
433
  }
434
- for (let i = 0; i < this.modifiers.length; i++) {
435
- boundingBox.mergeWith(this.modifiers[i].getBoundingBox());
436
- }
434
+ if (includeModifiers)
435
+ for (const modifier of this.modifiers)
436
+ boundingBox.mergeWith(modifier.getBoundingBox());
437
437
  return boundingBox;
438
438
  }
439
439
  getLineNumber(isTopNote) {
@@ -10,6 +10,7 @@ export class StemmableNote extends Note {
10
10
  }
11
11
  constructor(noteStruct) {
12
12
  super(noteStruct);
13
+ this.autoStemEnabled = false;
13
14
  this.flag = new Flag();
14
15
  }
15
16
  getStem() {
@@ -99,13 +100,17 @@ export class StemmableNote extends Note {
99
100
  throw new RuntimeError('NoStem', 'No stem attached to this note.');
100
101
  return this.stemDirection;
101
102
  }
102
- setStemDirection(direction) {
103
+ isAutoStem() {
104
+ return this.autoStemEnabled;
105
+ }
106
+ setStemDirection(direction, autoStem = false) {
103
107
  if (!direction)
104
108
  direction = Stem.UP;
105
109
  if (direction !== Stem.UP && direction !== Stem.DOWN) {
106
110
  throw new RuntimeError('BadArgument', `Invalid stem direction: ${direction}`);
107
111
  }
108
112
  this.stemDirection = direction;
113
+ this.autoStemEnabled = autoStem;
109
114
  this.reset();
110
115
  if (this.hasFlag()) {
111
116
  this.buildFlag();
@@ -80,6 +80,11 @@ export class Tickable extends Element {
80
80
  setVoice(voice) {
81
81
  this.voice = voice;
82
82
  }
83
+ clearVoice() {
84
+ this.voice = undefined;
85
+ this.preFormatted = false;
86
+ return this;
87
+ }
83
88
  getTuplet() {
84
89
  return this.tupletStack.at(-1);
85
90
  }
@@ -20,6 +20,7 @@ export class Tuplet extends Element {
20
20
  return 15;
21
21
  }
22
22
  constructor(notes, options = {}) {
23
+ var _a, _b;
23
24
  super();
24
25
  if (!notes || !notes.length) {
25
26
  throw new RuntimeError('BadArguments', 'No notes provided for tuplet.');
@@ -30,8 +31,8 @@ export class Tuplet extends Element {
30
31
  const bracketed = options.bracketed !== undefined ? options.bracketed : notes.some((note) => !note.hasBeam());
31
32
  const ratioed = options.ratioed !== undefined ? options.ratioed : Math.abs(notesOccupied - numNotes) > 1;
32
33
  const location = options.location || Tuplet.LOCATION_TOP;
33
- const yOffset = options.yOffset || Metrics.get('Tuplet.yOffset');
34
- const textYOffset = options.textYOffset || Metrics.get('Tuplet.textYOffset');
34
+ const yOffset = (_a = options.yOffset) !== null && _a !== void 0 ? _a : Metrics.get('Tuplet.yOffset');
35
+ const textYOffset = (_b = options.textYOffset) !== null && _b !== void 0 ? _b : Metrics.get('Tuplet.textYOffset');
35
36
  const suffix = options.suffix || '';
36
37
  this.options = {
37
38
  bracketed,
@@ -1,3 +1,3 @@
1
- export const VERSION = '5.1.1';
2
- export const ID = '271f9428354588de1f6c83a065428c8a5c442513';
3
- export const DATE = '2026-11-16T03:47:09.194Z';
1
+ export const VERSION = '5.2.0';
2
+ export const ID = '8b18873122b9b765ee130661d77692b3606fbcaf';
3
+ export const DATE = '2026-11-17T02:51:04.170Z';
@@ -21,7 +21,7 @@ import { ClefNote } from './clefnote.js';
21
21
  import { Crescendo } from './crescendo.js';
22
22
  import { Curve, CurvePosition } from './curve.js';
23
23
  import { Dot } from './dot.js';
24
- import { EasyScore } from './easyscore.js';
24
+ import { EasyScore, EasyScoreError } from './easyscore.js';
25
25
  import { Element } from './element.js';
26
26
  import { Factory } from './factory.js';
27
27
  import { Font, FontStyle, FontWeight } from './font.js';
@@ -235,6 +235,7 @@ VexFlow.Crescendo = Crescendo;
235
235
  VexFlow.Curve = Curve;
236
236
  VexFlow.Dot = Dot;
237
237
  VexFlow.EasyScore = EasyScore;
238
+ VexFlow.EasyScoreError = EasyScoreError;
238
239
  VexFlow.Element = Element;
239
240
  VexFlow.Factory = Factory;
240
241
  VexFlow.Font = Font;
@@ -10,6 +10,7 @@ const BeamTests = {
10
10
  run('Sixteenth Beam', sixteenth);
11
11
  run('Slopey Beam', slopey);
12
12
  run('Auto-stemmed Beam', autoStem);
13
+ run('Auto-stemmed tuplets across middle line', autoStemTuplets);
13
14
  run('Mixed Beam 1', mixed);
14
15
  run('Mixed Beam 2', mixed2);
15
16
  run('Mixed Beam 3', mixed3);
@@ -667,3 +668,37 @@ function complexWithArticulation2(options) {
667
668
  }
668
669
  VexFlowTests.register(BeamTests);
669
670
  export { BeamTests };
671
+ function autoStemTuplets(options) {
672
+ const f = VexFlowTests.makeFactory(options, 720, 650);
673
+ const score = f.EasyScore();
674
+ const groups = [];
675
+ const phrases = ['C4/8, D4, E4, F4, G4, A4, B4', 'A5/8, G5, F5, E5, D5, C5, A4'];
676
+ for (const proportional of [false, true]) {
677
+ for (const phrase of phrases) {
678
+ const notes = score.notes(phrase);
679
+ options.assert.equal(new Set(notes.map((note) => note.getStemDirection())).size, 2, 'Fixture crosses stem boundary');
680
+ score.tuplet(notes, { numNotes: 7, notesOccupied: 4, ratioed: true });
681
+ score.beam(notes);
682
+ const system = f.System({
683
+ x: 25,
684
+ y: 30 + groups.length * 155,
685
+ width: 660,
686
+ details: proportional ? { spacing: { mode: 'proportional', pixelsPerQuarter: 200 } } : {},
687
+ });
688
+ system.addStave({ voices: [score.voice(notes, { time: '2/4' })] }).addClef('treble');
689
+ groups.push(notes);
690
+ }
691
+ }
692
+ f.draw({ retain: true });
693
+ const positions = groups.map((notes) => notes.map((note) => note.getAbsoluteX()));
694
+ f.draw({ retain: true });
695
+ groups.forEach((notes, row) => notes.forEach((note, index) => {
696
+ const direction = note.getBeam().getStemDirection();
697
+ options.assert.equal(note.getStemDirection(), direction, 'All stems agree with the beam');
698
+ const head = note.noteHeads[0];
699
+ options.assert.notOk(head.isDisplaced(), 'A single head has no chord displacement');
700
+ const attachment = direction === Stem.UP ? head.getAbsoluteX() + head.getWidth() : head.getAbsoluteX();
701
+ options.assert.ok(Math.abs(note.getStemX() - (attachment - (direction * Stem.WIDTH) / 2)) < 1e-7, 'Stem attaches to correct edge of head');
702
+ options.assert.equal(note.getAbsoluteX(), positions[row][index], 'Redraw preserves rhythmic anchor');
703
+ }));
704
+ }