vexflow 5.4.0 → 5.6.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 (127) 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 +1740 -372
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +565 -258
  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/annotation.js +2 -1
  12. package/build/esm/src/continuouslayout.js +107 -16
  13. package/build/esm/src/continuousspan.js +9 -1
  14. package/build/esm/src/easyscore/composition.js +83 -18
  15. package/build/esm/src/factory.js +2 -9
  16. package/build/esm/src/formatter.js +1 -1
  17. package/build/esm/src/fretdiagram.js +6 -2
  18. package/build/esm/src/gracenotegroup.js +4 -3
  19. package/build/esm/src/guitarmodifiers.js +4 -1
  20. package/build/esm/src/metrics.js +24 -5
  21. package/build/esm/src/note.js +1 -0
  22. package/build/esm/src/notehead.js +21 -10
  23. package/build/esm/src/phraselayout.js +13 -5
  24. package/build/esm/src/publication.js +10 -5
  25. package/build/esm/src/publicationview.js +3 -2
  26. package/build/esm/src/stave.js +4 -2
  27. package/build/esm/src/stavenote.js +56 -13
  28. package/build/esm/src/stavesection.js +15 -10
  29. package/build/esm/src/stavetie.js +3 -2
  30. package/build/esm/src/strokes.js +1 -1
  31. package/build/esm/src/svgcontext.js +11 -3
  32. package/build/esm/src/tabnote.js +6 -8
  33. package/build/esm/src/tabtie.js +3 -0
  34. package/build/esm/src/version.js +3 -3
  35. package/build/esm/tests/chordsymbol_tests.js +4 -1
  36. package/build/esm/tests/demo_petzold_tests.js +26 -14
  37. package/build/esm/tests/demo_repertoire_tests.js +5 -1
  38. package/build/esm/tests/demos/ballade.js +15 -0
  39. package/build/esm/tests/demos/electric.js +1 -3
  40. package/build/esm/tests/demos/fugue.js +19 -0
  41. package/build/esm/tests/demos/greensleeves.js +1 -2
  42. package/build/esm/tests/demos/kesh.js +2 -3
  43. package/build/esm/tests/demos/saints.js +17 -5
  44. package/build/esm/tests/engraving/continuous-studies.mjs +24 -0
  45. package/build/esm/tests/engraving/publication-studies.mjs +30 -0
  46. package/build/esm/tests/font_tests.js +8 -0
  47. package/build/esm/tests/gracenote_tests.js +1 -1
  48. package/build/esm/tests/gracetabnote_tests.js +19 -3
  49. package/build/esm/tests/node/chord-kerning-tests.mjs +2 -2
  50. package/build/esm/tests/node/continuous-score-tests.mjs +157 -2
  51. package/build/esm/tests/node/easyscore-tests.mjs +38 -0
  52. package/build/esm/tests/node/engraving-layout-tests.mjs +33 -0
  53. package/build/esm/tests/node/instrument-profile-tests.mjs +40 -0
  54. package/build/esm/tests/node/local-engraving-tests.mjs +58 -0
  55. package/build/esm/tests/node/metrics-tests.mjs +2 -0
  56. package/build/esm/tests/node/phrase-layout-tests.mjs +58 -5
  57. package/build/esm/tests/node/publication-tests.mjs +158 -2
  58. package/build/esm/tests/node/svg-export-tests.mjs +50 -21
  59. package/build/esm/tests/scores/ballade.js +399 -0
  60. package/build/esm/tests/scores/drums.js +93 -0
  61. package/build/esm/tests/scores/electric.js +83 -0
  62. package/build/esm/tests/scores/falseta.js +46 -0
  63. package/build/esm/tests/scores/fugue.js +366 -0
  64. package/build/esm/tests/scores/guitar.js +32 -0
  65. package/build/esm/tests/scores/kesh.js +146 -0
  66. package/build/esm/tests/scores/prelude.js +84 -0
  67. package/build/esm/tests/scores/quartertones.js +78 -0
  68. package/build/esm/tests/scores/saints.js +70 -0
  69. package/build/esm/tests/scores/sumer.js +126 -0
  70. package/build/esm/tests/scores/viewer.js +162 -0
  71. package/build/esm/tests/tabnote_tests.js +43 -0
  72. package/build/esm/tests/vexflow_test_helpers.js +1 -0
  73. package/build/esm/tools/explorer/catalog/expression.mjs +16 -6
  74. package/build/esm/tools/explorer/catalog/guitar.mjs +2 -2
  75. package/build/types/src/continuouslayout.d.ts +4 -0
  76. package/build/types/src/continuousspan.d.ts +10 -2
  77. package/build/types/src/easyscore/composition.d.ts +19 -0
  78. package/build/types/src/fretdiagram.d.ts +2 -0
  79. package/build/types/src/instrumentprofile.d.ts +4 -0
  80. package/build/types/src/note.d.ts +2 -0
  81. package/build/types/src/notehead.d.ts +2 -0
  82. package/build/types/src/publication.d.ts +3 -1
  83. package/build/types/src/stave.d.ts +4 -2
  84. package/build/types/src/stavenote.d.ts +10 -0
  85. package/build/types/src/stavesection.d.ts +3 -0
  86. package/build/types/src/svgcontext.d.ts +2 -0
  87. package/build/types/src/typeguard.d.ts +1 -0
  88. package/changelog/CHANGELOG.md +16 -0
  89. package/package.json +4 -1
  90. package/tests/all.html +9 -0
  91. package/tests/demo_petzold_tests.ts +30 -16
  92. package/tests/demos/ballade.ts +36 -0
  93. package/tests/demos/ballade.webp +0 -0
  94. package/tests/demos/electric.ts +1 -3
  95. package/tests/demos/electric.webp +0 -0
  96. package/tests/demos/fugue.ts +27 -0
  97. package/tests/demos/fugue.webp +0 -0
  98. package/tests/demos/greensleeves.ts +1 -3
  99. package/tests/demos/greensleeves.webp +0 -0
  100. package/tests/demos/kesh.ts +2 -4
  101. package/tests/demos/kesh.webp +0 -0
  102. package/tests/demos/saints.ts +20 -7
  103. package/tests/demos/saints.webp +0 -0
  104. package/tests/flow.html +165 -52
  105. package/tests/minuet.webp +0 -0
  106. package/tests/scores/ballade.js +445 -0
  107. package/tests/scores/drums.js +101 -0
  108. package/tests/scores/drums.webp +0 -0
  109. package/tests/scores/electric.js +93 -0
  110. package/tests/scores/electric.webp +0 -0
  111. package/tests/scores/falseta.js +53 -0
  112. package/tests/scores/falseta.webp +0 -0
  113. package/tests/scores/fugue.js +433 -0
  114. package/tests/scores/guitar.js +34 -0
  115. package/tests/scores/index.html +48 -0
  116. package/tests/scores/kesh.js +171 -0
  117. package/tests/scores/kesh.webp +0 -0
  118. package/tests/scores/prelude.js +90 -0
  119. package/tests/scores/prelude.webp +0 -0
  120. package/tests/scores/quartertones.js +83 -0
  121. package/tests/scores/quartertones.webp +0 -0
  122. package/tests/scores/saints.js +85 -0
  123. package/tests/scores/saints.webp +0 -0
  124. package/tests/scores/sumer.js +139 -0
  125. package/tests/scores/sumer.webp +0 -0
  126. package/tests/scores/viewer.css +132 -0
  127. package/tests/scores/viewer.js +150 -0
@@ -1,3 +1,4 @@
1
+ import { Glyphs } from './glyphs.js';
1
2
  import { Note } from './note.js';
2
3
  import { Stem } from './stem.js';
3
4
  import { defined, log, RuntimeError } from './util.js';
@@ -14,8 +15,8 @@ export class NoteHead extends Note {
14
15
  super(noteStruct);
15
16
  this.customGlyph = false;
16
17
  this.ledger = {
17
- '\ue4e3': '\ue4f4',
18
- '\ue4e4': '\ue4f5',
18
+ [Glyphs.restWhole]: Glyphs.restWholeLegerLine,
19
+ [Glyphs.restHalf]: Glyphs.restHalfLegerLine,
19
20
  };
20
21
  this.index = noteStruct.index;
21
22
  this.x = noteStruct.x || 0;
@@ -30,18 +31,24 @@ export class NoteHead extends Note {
30
31
  this.line = noteStruct.line || 0;
31
32
  this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
32
33
  defined(this.glyphProps, 'BadArguments', `No glyph found for duration '${this.duration}' and type '${this.noteType}'`);
33
- if ((this.line > 5 || this.line < 0) && this.ledger[this.glyphProps.codeHead]) {
34
- this.glyphProps.codeHead = this.ledger[this.glyphProps.codeHead];
35
- }
36
- this.text = this.glyphProps.codeHead;
37
- if (noteStruct.customGlyphCode) {
38
- this.customGlyph = true;
39
- this.text = noteStruct.customGlyphCode;
40
- }
34
+ this.text = noteStruct.customGlyphCode || this.glyphProps.codeHead;
35
+ this.customGlyph = !!noteStruct.customGlyphCode;
36
+ this.updateRestGlyph();
41
37
  this.setStyle((_b = noteStruct.style) !== null && _b !== void 0 ? _b : {});
42
38
  this.slashed = noteStruct.slashed || false;
43
39
  this.renderOptions = Object.assign({}, this.renderOptions);
44
40
  }
41
+ updateRestGlyph() {
42
+ var _a, _b;
43
+ const plain = this.glyphProps.codeHead;
44
+ const ledger = this.ledger[plain];
45
+ if (!ledger || (this.text !== plain && this.text !== ledger))
46
+ return;
47
+ const bottomLine = 6 - ((_b = (_a = this.stave) === null || _a === void 0 ? void 0 : _a.getNumLines()) !== null && _b !== void 0 ? _b : 5);
48
+ const glyph = this.line > 5 || this.line < bottomLine ? ledger : plain;
49
+ if (this.text !== glyph)
50
+ this.setText(glyph);
51
+ }
45
52
  getWidth() {
46
53
  return this.width;
47
54
  }
@@ -53,6 +60,9 @@ export class NoteHead extends Note {
53
60
  }
54
61
  setLine(line) {
55
62
  this.line = line;
63
+ if (this.stave)
64
+ return this.setStave(this.stave);
65
+ this.updateRestGlyph();
56
66
  return this;
57
67
  }
58
68
  getAbsoluteX() {
@@ -65,6 +75,7 @@ export class NoteHead extends Note {
65
75
  setStave(stave) {
66
76
  const line = this.getLine();
67
77
  this.stave = stave;
78
+ this.updateRestGlyph();
68
79
  if (this.stave) {
69
80
  this.setY(this.stave.getYForNote(line));
70
81
  this.setContext(this.stave.getContext());
@@ -5,6 +5,7 @@ import { Clef } from './clef.js';
5
5
  import { measureEngraving } from './engravinggeometry.js';
6
6
  import { GhostNote } from './ghostnote.js';
7
7
  import { KeySignature } from './keysignature.js';
8
+ import { Metrics } from './metrics.js';
8
9
  import { Modifier } from './modifier.js';
9
10
  import { Ornament } from './ornament.js';
10
11
  import { Barline } from './stavebarline.js';
@@ -82,6 +83,7 @@ export class PhraseLayout {
82
83
  const marks = syllables.map((s, i) => {
83
84
  var _a;
84
85
  return new Annotation(s.text)
86
+ .setFont(Metrics.getFontInfo('Annotation.lyric'))
85
87
  .setVerticalJustification(options.side === 'above' ? 'top' : 'bottom')
86
88
  .setConnectorPadding(s.hyphenAfter || ((_a = syllables[i - 1]) === null || _a === void 0 ? void 0 : _a.hyphenAfter) ? stave.space(0.4) : 0);
87
89
  });
@@ -96,9 +98,10 @@ export class PhraseLayout {
96
98
  mark.setLayoutBaseline(undefined);
97
99
  for (const route of this.routes)
98
100
  route.setLayoutRise(0);
99
- for (const [note, line] of this.restLines)
100
- if (note.getKeyLine(0) === line.after)
101
+ for (const [note, line] of this.restLines) {
102
+ if (note.restLine === undefined && note.getKeyLine(0) === line.after)
101
103
  note.setKeyLine(0, line.before);
104
+ }
102
105
  this.restLines.clear();
103
106
  }
104
107
  report(code, ...owners) {
@@ -186,7 +189,11 @@ export class PhraseLayout {
186
189
  if (!tuplets.has(owner))
187
190
  this.measure(owner, stave);
188
191
  for (const n of rests)
189
- this.placeRest(n);
192
+ if (n.restLine !== undefined)
193
+ this.placeRest(n);
194
+ for (const n of rests)
195
+ if (n.restLine === undefined)
196
+ this.placeRest(n);
190
197
  for (const m of marks)
191
198
  this.placeAttachment(m);
192
199
  for (const t of tuplets)
@@ -208,7 +215,8 @@ export class PhraseLayout {
208
215
  this.report('UnsupportedGeometry', note);
209
216
  let parts = original.parts;
210
217
  const hits = this.hits(parts, stave, gap);
211
- if (hits.length && !this.pins.has(note)) {
218
+ const pinned = note.restLine !== undefined || this.pins.has(note);
219
+ if (hits.length && !pinned) {
212
220
  const sign = note.getStemDirection();
213
221
  for (const step of [1, -1, 2, -2, 3, -3, 4, -4]) {
214
222
  const delta = step * sign;
@@ -225,7 +233,7 @@ export class PhraseLayout {
225
233
  }
226
234
  const remaining = this.hits(parts, stave, gap);
227
235
  if (remaining.length)
228
- this.report(this.pins.has(note) ? 'PinnedCollision' : 'UnresolvedCollision', note, remaining[0].owner);
236
+ this.report(pinned ? 'PinnedCollision' : 'UnresolvedCollision', note, remaining[0].owner);
229
237
  this.addParts(note, stave, parts);
230
238
  }
231
239
  placeAttachment(mark) {
@@ -33,10 +33,13 @@ function dimensions(o) {
33
33
  invalidPage('Margins consume the paper.');
34
34
  return Object.assign(Object.assign({}, size), { margin, musicWidth: width, scale: staff / (4 * Tables.STAVE_LINE_DISTANCE), gap, extra });
35
35
  }
36
- function compose(host, spec) {
36
+ function compose(host, spec, hooks = []) {
37
37
  const ctx = new SVGContext(host);
38
38
  const factory = new Factory({ renderer: { elementId: null, width: 1, height: 1 } }).setContext(ctx);
39
- const score = factory.EasyScore().compose(spec);
39
+ const easyScore = factory.EasyScore();
40
+ for (const hook of hooks)
41
+ easyScore.addCommitHook(hook);
42
+ const score = easyScore.compose(spec);
40
43
  return { ctx, factory, score };
41
44
  }
42
45
  function musicGroup(svg) {
@@ -48,6 +51,8 @@ function musicGroup(svg) {
48
51
  }
49
52
  function inkBox(el, context) {
50
53
  var _a, _b;
54
+ if (el.getAttribute('opacity') === '0')
55
+ return;
51
56
  let box;
52
57
  if (el.tagName === 'g') {
53
58
  const children = Array.from(el.children).flatMap((c) => { var _a; return (_a = inkBox(c, context)) !== null && _a !== void 0 ? _a : []; });
@@ -189,7 +194,7 @@ function addInsets(host, spec, o, score, rows, diagnostics) {
189
194
  sheet: { x: 0, y: 0, width: stave.getWidth() / scale, measurePadding: 4 },
190
195
  continuous: {},
191
196
  };
192
- const inset = compose(host, insetSpec);
197
+ const inset = compose(host, insetSpec, o.noteHooks);
193
198
  inset.factory.draw();
194
199
  row.references.push(Object.assign(Object.assign({}, r), { events: semanticEvents(inset.score, insetSpec, 1).map((e) => (Object.assign(Object.assign({}, e), { measure: r.measure }))) }));
195
200
  const g = musicGroup(inset.ctx.svg);
@@ -357,11 +362,11 @@ export class Publication {
357
362
  (((_a = this.source.spans) === null || _a === void 0 ? void 0 : _a.length) ||
358
363
  ((_c = (_b = this.source.continuous) === null || _b === void 0 ? void 0 : _b.spans) === null || _c === void 0 ? void 0 : _c.length) ||
359
364
  ((_e = (_d = this.source.continuous) === null || _d === void 0 ? void 0 : _d.splitChords) === null || _e === void 0 ? void 0 : _e.length))
360
- ? compose(host, this.source).score
365
+ ? compose(host, this.source, options.noteHooks).score
361
366
  : undefined;
362
367
  const width = size.musicWidth / size.scale - 2;
363
368
  const spec = projectScore(this.source, options, width, ref, (id, measures) => diagnostics.push({ code: 'ExcludedAnchor', measures, detail: id }));
364
- const { ctx, factory, score } = compose(host, spec);
369
+ const { ctx, factory, score } = compose(host, spec, options.noteHooks);
365
370
  factory.draw();
366
371
  const layout = score.sheet.getContinuousLayout();
367
372
  for (const d of layout.diagnostics)
@@ -94,12 +94,13 @@ function homeStaff(staff, selected) {
94
94
  }) }))) }))) });
95
95
  }
96
96
  export function insetStaff(staff, measure) {
97
- var _a, _b, _c;
98
- const state = { clef: staff.clef, key: staff.key, time: staff.time };
97
+ var _a, _b, _c, _d;
98
+ const state = { clef: staff.clef, key: staff.key, time: staff.time, showTimeSignature: staff.showTimeSignature };
99
99
  for (const m of staff.measures.slice(0, measure - 1)) {
100
100
  state.clef = (_a = m.clef) !== null && _a !== void 0 ? _a : state.clef;
101
101
  state.key = (_b = m.key) !== null && _b !== void 0 ? _b : state.key;
102
102
  state.time = (_c = m.time) !== null && _c !== void 0 ? _c : state.time;
103
+ state.showTimeSignature = (_d = m.showTimeSignature) !== null && _d !== void 0 ? _d : state.showTimeSignature;
103
104
  for (const v of m.voices.slice(0, 1))
104
105
  if (typeof v.notes !== 'string')
105
106
  for (const item of v.notes)
@@ -30,7 +30,8 @@ export class Stave extends Element {
30
30
  static get CATEGORY() {
31
31
  return "Stave";
32
32
  }
33
- setBoundaryModifiers(modifiers) {
33
+ setBoundaryModifiers(modifiers, notePadding = 0) {
34
+ this.boundaryNotePadding = notePadding;
34
35
  this.boundaryModifiers = modifiers;
35
36
  for (const mark of modifiers)
36
37
  mark.setStave(this);
@@ -46,6 +47,7 @@ export class Stave extends Element {
46
47
  var _a;
47
48
  super();
48
49
  this.boundaryModifiers = [];
50
+ this.boundaryNotePadding = 0;
49
51
  this.x = x;
50
52
  this.y = y;
51
53
  this.width = width;
@@ -429,7 +431,7 @@ export class Stave extends Element {
429
431
  if (padding + width === 0)
430
432
  offset--;
431
433
  }
432
- this.startX = x;
434
+ this.startX = x + this.boundaryNotePadding;
433
435
  x = this.x + this.width;
434
436
  const widths = {
435
437
  left: 0,
@@ -9,6 +9,10 @@ import { Stem } from './stem.js';
9
9
  import { StemmableNote } from './stemmablenote.js';
10
10
  import { Tables } from './tables.js';
11
11
  import { defined, log, midLine, RuntimeError } from './util.js';
12
+ const bravuraSlashAnchors = {
13
+ [Glyphs.noteheadSlashVerticalEnds]: { up: [1.46, 0.656], down: [0, -0.664] },
14
+ [Glyphs.noteheadSlashWhiteHalf]: { up: [3.12, 1], down: [0, -1] },
15
+ };
12
16
  function L(...args) {
13
17
  if (StaveNote.DEBUG)
14
18
  log('VexFlow.StaveNote', args);
@@ -81,7 +85,18 @@ export class StaveNote extends StemmableNote {
81
85
  const visible = notesList.filter((item) => item.note.renderOptions.draw !== false);
82
86
  if (visible.length < 2)
83
87
  return true;
84
- if (visible.length > 3) {
88
+ const positioned = visible.some(({ note }) => note.restLine !== undefined);
89
+ if (positioned && visible.length <= 3) {
90
+ for (const rest of visible.filter((v) => v.isrest && v.note.restLine === undefined)) {
91
+ const direction = rest.note.getStemDirection();
92
+ const peers = visible.filter((v) => v !== rest).sort((a, b) => direction * (a.minLine - b.minLine));
93
+ for (const peer of peers) {
94
+ if (rest.minLine <= peer.maxLine && peer.minLine <= rest.maxLine)
95
+ shiftRestVertical(rest, peer, direction);
96
+ }
97
+ }
98
+ }
99
+ if (visible.length > 3 || positioned) {
85
100
  const columns = [];
86
101
  for (const item of visible.sort((a, b) => b.maxLine - a.maxLine || b.line - a.line)) {
87
102
  let column = columns.find((entry) => item.maxLine + 0.5 < entry.bottom);
@@ -276,6 +291,8 @@ export class StaveNote extends StemmableNote {
276
291
  else {
277
292
  this.setStemDirection((_e = noteStruct.stemDirection) !== null && _e !== void 0 ? _e : Stem.UP);
278
293
  }
294
+ if (noteStruct.restLine !== undefined)
295
+ this.setRestLine(noteStruct.restLine);
279
296
  if (this.notation.length)
280
297
  attachGuitarGestures(this);
281
298
  }
@@ -473,21 +490,31 @@ export class StaveNote extends StemmableNote {
473
490
  hasFlag() {
474
491
  return super.hasFlag() && !this.isRest();
475
492
  }
476
- getStemX() {
493
+ stemAnchor(head, direction) {
477
494
  var _a;
495
+ const family = head.fontInfo.family;
496
+ if (((_a = this.engraving) === null || _a === void 0 ? void 0 : _a.musicFont) === family) {
497
+ const anchor = this.engraving.stemAnchor(head.text, direction);
498
+ if (anchor)
499
+ return anchor;
500
+ }
501
+ const slash = bravuraSlashAnchors[head.text];
502
+ if (slash && /^\s*(?:Bravura|"Bravura"|'Bravura')\s*(?:,|$)/i.test(family))
503
+ return slash[direction];
504
+ }
505
+ getStemX() {
478
506
  if (this.noteType === 'r') {
479
507
  return this.getCenterGlyphX();
480
508
  }
481
509
  else {
482
510
  const up = this.stemDirection === Stem.UP;
483
- const head = this.engraving && this._noteHeads.find((h) => !h.isDisplaced());
484
- if (head && ((_a = this.engraving) === null || _a === void 0 ? void 0 : _a.musicFont) === head.fontInfo.family) {
485
- const anchor = this.engraving.stemAnchor(head.text, up ? 'up' : 'down');
486
- if (anchor)
487
- return (this.getNoteHeadBeginX() +
488
- head.getXShift() +
489
- (anchor[0] * head.fontSizeInPixels) / 4 +
490
- ((up ? -1 : 1) * Stem.WIDTH) / 2);
511
+ const head = this._noteHeads.find((h) => !h.isDisplaced());
512
+ const anchor = head && this.stemAnchor(head, up ? 'up' : 'down');
513
+ if (head && anchor) {
514
+ return (this.getNoteHeadBeginX() +
515
+ head.getXShift() +
516
+ (anchor[0] * head.fontSizeInPixels) / 4 +
517
+ ((up ? -1 : 1) * Stem.WIDTH) / 2);
491
518
  }
492
519
  return super.getStemX() + (this.stemDirection ? Stem.WIDTH / (2 * -this.stemDirection) : 0);
493
520
  }
@@ -628,6 +655,24 @@ export class StaveNote extends StemmableNote {
628
655
  this._noteHeads[index].setStyle(style);
629
656
  return this;
630
657
  }
658
+ get restLine() {
659
+ return this.lineBeforeRestPin === undefined ? undefined : this.getKeyLine(0);
660
+ }
661
+ setRestLine(line) {
662
+ var _a;
663
+ if (!this.isRest() || (line !== undefined && !Number.isFinite(line)))
664
+ throw new RuntimeError('BadArguments', 'Rest positioning requires a rest and a finite line.');
665
+ if (line !== undefined) {
666
+ (_a = this.lineBeforeRestPin) !== null && _a !== void 0 ? _a : (this.lineBeforeRestPin = this.getKeyLine(0));
667
+ return this.setKeyLine(0, line);
668
+ }
669
+ if (this.lineBeforeRestPin !== undefined) {
670
+ const previous = this.lineBeforeRestPin;
671
+ this.lineBeforeRestPin = undefined;
672
+ this.setKeyLine(0, previous);
673
+ }
674
+ return this;
675
+ }
631
676
  setKeyLine(index, line) {
632
677
  this.keyProps[index].line = line;
633
678
  this.reset();
@@ -668,9 +713,7 @@ export class StaveNote extends StemmableNote {
668
713
  this._noteHeads.forEach((nh) => {
669
714
  const offset = Tables.noteHeadStemYOffsets[nh.text];
670
715
  const anchor = offset ? offset[anchorKey] : 0;
671
- const fontAnchor = this.engraving && this.engraving.musicFont === nh.fontInfo.family
672
- ? this.engraving.stemAnchor(nh.text, anchorKey)
673
- : undefined;
716
+ const fontAnchor = this.stemAnchor(nh, anchorKey);
674
717
  const y = nh.getY() - (fontAnchor ? (fontAnchor[1] * nh.fontSizeInPixels) / 4 : anchor * Tables.STAVE_LINE_DISTANCE);
675
718
  yTop = Math.min(y, yTop);
676
719
  yBottom = Math.max(y, yBottom);
@@ -1,3 +1,4 @@
1
+ import { BoundingBox } from './boundingbox.js';
1
2
  import { Metrics } from './metrics.js';
2
3
  import { StaveModifier } from './stavemodifier.js';
3
4
  export class StaveSection extends StaveModifier {
@@ -16,21 +17,25 @@ export class StaveSection extends StaveModifier {
16
17
  this.drawRect = drawRect;
17
18
  return this;
18
19
  }
20
+ getBoundingBox() {
21
+ if (this.stave) {
22
+ this.x = this.stave.getX() + this.stave.getModifierXShift(this.getPosition()) + this.padding;
23
+ this.y = this.stave.getYForTopText(1.5) - this.padding;
24
+ }
25
+ const ink = this.getTextInk(this.x, this.y);
26
+ if (!this.drawRect)
27
+ return ink;
28
+ return new BoundingBox(ink.x - this.padding, ink.y - this.padding, ink.w + 2 * this.padding, ink.h + 2 * this.padding);
29
+ }
19
30
  draw() {
20
- const stave = this.checkStave();
21
- const ctx = stave.checkContext();
31
+ const ctx = this.checkStave().checkContext();
32
+ const bounds = this.getBoundingBox();
22
33
  this.setRendered();
23
- this.x = stave.getX() + stave.getModifierXShift(this.getPosition());
24
- const headroom = -1 * this.textMetrics.actualBoundingBoxDescent;
25
- const width = this.width + 2 * this.padding;
26
- const height = this.height + 2 * this.padding;
27
- const y = stave.getYForTopText(1.5) + this.yShift;
28
- const x = this.x + this.xShift;
29
34
  if (this.drawRect) {
30
35
  ctx.beginPath();
31
- ctx.rect(x, y - height + headroom, width, height);
36
+ ctx.rect(bounds.x, bounds.y, bounds.w, bounds.h);
32
37
  ctx.stroke();
33
38
  }
34
- this.renderText(ctx, this.xShift + this.padding, y - this.padding);
39
+ this.renderText(ctx, 0, 0);
35
40
  }
36
41
  }
@@ -155,12 +155,13 @@ export class StaveTie extends Element {
155
155
  renderTieText(firstX, lastX) {
156
156
  var _a, _b, _c;
157
157
  const ctx = this.checkContext();
158
- let centerX = (firstX + lastX) / 2;
159
- centerX -= ctx.measureText(this.text).width / 2;
160
158
  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();
161
159
  if (stave) {
160
+ ctx.save();
162
161
  ctx.setFont(this.fontInfo);
162
+ const centerX = (firstX + lastX - ctx.measureText(this.text).width) / 2;
163
163
  ctx.fillText(this.text, centerX + this.renderOptions.textShiftX, stave.getYForTopText() - 1);
164
+ ctx.restore();
164
165
  }
165
166
  }
166
167
  getNotes() {
@@ -66,7 +66,7 @@ export class Stroke extends Modifier {
66
66
  let yPositions = note.getYs();
67
67
  let topY = start.y;
68
68
  let botY = start.y;
69
- const x = start.x - 5;
69
+ const x = start.x - 5 - (isTabNote(note) ? Metrics.get('NoteHead.minPadding') : 0);
70
70
  const lineSpace = note.checkStave().getSpacingBetweenLines();
71
71
  const notes = this.checkModifierContext().getMembers(note.getCategory());
72
72
  for (let i = 0; i < notes.length; i++) {
@@ -358,17 +358,25 @@ export class SVGContext extends RenderContext {
358
358
  }
359
359
  save() {
360
360
  this.stateStack.push({
361
+ font: this.fontCSSString,
361
362
  state: structuredClone(this.state),
362
363
  attributes: structuredClone(this.attributes),
363
364
  });
364
365
  return this;
365
366
  }
366
367
  restore() {
368
+ var _a;
367
369
  const savedState = this.stateStack.pop();
368
370
  if (savedState) {
369
- const state = savedState;
370
- this.state = structuredClone(state.state);
371
- this.attributes = structuredClone(state.attributes);
371
+ this.state = structuredClone(savedState.state);
372
+ this.attributes = structuredClone(savedState.attributes);
373
+ this.fontCSSString =
374
+ (_a = savedState.font) !== null && _a !== void 0 ? _a : Font.toCSSString({
375
+ family: this.attributes['font-family'],
376
+ size: this.attributes['font-size'],
377
+ weight: this.attributes['font-weight'],
378
+ style: this.attributes['font-style'],
379
+ });
372
380
  }
373
381
  return this;
374
382
  }
@@ -155,6 +155,8 @@ export class TabNote extends StemmableNote {
155
155
  this.fretElement.push(el);
156
156
  this.width = Math.max(el.getWidth(), this.width);
157
157
  }
158
+ this.setLeftDisplacedHeadPx(this.width / 2);
159
+ this.setRightDisplacedHeadPx(this.width / 2);
158
160
  }
159
161
  setStave(stave) {
160
162
  super.setStave(stave);
@@ -177,19 +179,15 @@ export class TabNote extends StemmableNote {
177
179
  if (this.ys.length === 0) {
178
180
  throw new RuntimeError('NoYValues', 'No Y-Values calculated for this note.');
179
181
  }
180
- let x = 0;
182
+ let x = this.getAbsoluteX();
181
183
  if (position === Modifier.Position.LEFT) {
182
- x = -1 * 2;
184
+ x = this.getTieLeftX();
183
185
  }
184
186
  else if (position === Modifier.Position.RIGHT) {
185
- x = this.width + 2;
186
- }
187
- else if (position === Modifier.Position.BELOW || position === Modifier.Position.ABOVE) {
188
- const noteGlyphWidth = this.width;
189
- x = noteGlyphWidth / 2;
187
+ x = this.getTieRightX();
190
188
  }
191
189
  return {
192
- x: this.getAbsoluteX() + x,
190
+ x,
193
191
  y: this.ys[index],
194
192
  };
195
193
  }
@@ -1,3 +1,4 @@
1
+ import { Metrics } from './metrics.js';
1
2
  import { StaveTie } from './stavetie.js';
2
3
  export class TabTie extends StaveTie {
3
4
  static get CATEGORY() {
@@ -11,6 +12,8 @@ export class TabTie extends StaveTie {
11
12
  }
12
13
  constructor(notes, text) {
13
14
  super(notes, text);
15
+ if (text && /^[a-z]$/i.test(text))
16
+ this.setFont(Metrics.getFontInfo('TabTie.techniqueLetter'));
14
17
  this.renderOptions.cp1 = 9;
15
18
  this.renderOptions.cp2 = 11;
16
19
  this.renderOptions.yShift = 3;
@@ -1,3 +1,3 @@
1
- export const VERSION = '5.4.0';
2
- export const ID = '30054199edf019f97dcea2f2939430198f387f49';
3
- export const DATE = '2026-11-19T00:43:30.372Z';
1
+ export const VERSION = '5.6.0';
2
+ export const ID = '39cf287f300f0ef6bd9b63cbf1d01ef0bbbd1c10';
3
+ export const DATE = '2026-11-19T20:58:10.569Z';
@@ -377,7 +377,8 @@ function doubleBottom(options) {
377
377
  options.assert.ok(true, '2 Bottom Chord Symbol');
378
378
  }
379
379
  function wide(options) {
380
- const f = VexFlowTests.makeFactory(options, 300 * 1.5, 680);
380
+ const pageWidth = 370;
381
+ const f = VexFlowTests.makeFactory(options, pageWidth * 1.5, 680);
381
382
  const ctx = f.getContext();
382
383
  ctx.scale(1.5, 1.5);
383
384
  function draw(chord1, chord2, y) {
@@ -387,6 +388,8 @@ function wide(options) {
387
388
  note(f, ['c/4', 'e/4', 'B/4'], 'h', chord2),
388
389
  ];
389
390
  Formatter.FormatAndDraw(ctx, stave, notes);
391
+ const last = chord2.getBoundingBox();
392
+ options.assert.ok(last.x + last.w < pageWidth, 'The final chord and its extension fit on the page');
390
393
  }
391
394
  let chord1 = f.ChordSymbol().addText('FrogToad7').setHorizontal('left').addGlyphOrText('(#11b9)', superscript);
392
395
  let chord2 = f.ChordSymbol({ hJustify: 'left' }).addText('CToShiningC').addGlyphSuperscript('majorSeventh');
@@ -1,5 +1,5 @@
1
1
  import { concat, VexFlowTests } from './vexflow_test_helpers.js';
2
- import { BarlineType, Registry } from '../src/index.js';
2
+ import { BarlineType, Registry, StaveHairpin } from '../src/index.js';
3
3
  const DemoPetzoldTests = {
4
4
  Start() {
5
5
  QUnit.module('Demo - Petzold');
@@ -34,15 +34,16 @@ function minuetInG(options) {
34
34
  .addClef('treble')
35
35
  .addKeySignature('G')
36
36
  .addTimeSignature('3/4')
37
- .setTempo({ name: 'Allegretto', duration: 'h', dots: 1, bpm: 66 }, -30);
37
+ .setTempo({ name: 'Allegretto', duration: 'q', bpm: 132 }, -30);
38
38
  system
39
- .addStave({ voices: [voice(notes('(G3 B3 D4)/h, A3/q', { clef: 'bass' }))] })
39
+ .addStave({ voices: [voice(notes('(G3 B3 D4)/h[id="ped1"], A3/q[id="lift1"]', { clef: 'bass' }))] })
40
40
  .addClef('bass')
41
41
  .addKeySignature('G')
42
42
  .addTimeSignature('3/4');
43
43
  system.addConnector('brace');
44
44
  system.addConnector('singleRight');
45
45
  system.addConnector('singleLeft');
46
+ f.PedalMarking({ notes: [id('ped1'), id('lift1')] });
46
47
  id('m1a').addModifier(f.Fingering({ number: '5' }), 0);
47
48
  system = appendSystem(150);
48
49
  system.addStave({ voices: [voice(notes('D5/q[id="m2a"], G4[id="m2b"], G4[id="m2c"]'))] });
@@ -63,8 +64,11 @@ function minuetInG(options) {
63
64
  });
64
65
  system = appendSystem(150);
65
66
  system.addStave({
66
- voices: [voice([notes('E5/q[id="m3a"]'), beam(notes('C5/8, D5, E5, F5', { stem: 'down' }))].reduce(concat))],
67
+ voices: [
68
+ voice([notes('E5/q[id="m3a"]'), beam(notes('C5/8[id="m3cut"], D5, E5, F5', { stem: 'down' }))].reduce(concat)),
69
+ ],
67
70
  });
71
+ id('m3cut').addModifier(f.Ornament('mordent'));
68
72
  id('m3a').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
69
73
  system.addStave({ voices: [voice(notes('C4/h.', { clef: 'bass' }))] });
70
74
  system.addConnector('singleRight');
@@ -80,8 +84,8 @@ function minuetInG(options) {
80
84
  to: id('m4a'),
81
85
  options: {
82
86
  cps: [
83
- { x: 0, y: 20 },
84
- { x: 0, y: 20 },
87
+ { x: 0, y: 39 },
88
+ { x: 0, y: 39 },
85
89
  ],
86
90
  },
87
91
  });
@@ -117,6 +121,7 @@ function minuetInG(options) {
117
121
  system
118
122
  .addStave({
119
123
  voices: [
124
+ voice([f.TextDynamics({ text: 'mf', duration: 'h', dots: 1, line: 10 })]),
120
125
  voice([notes('F4/q[id="m7a"]'), beam(notes('G4/8[id="m7b"], A4, B4, G4', { stem: 'up' }))].reduce(concat)),
121
126
  ],
122
127
  })
@@ -129,11 +134,12 @@ function minuetInG(options) {
129
134
  system.addConnector('brace');
130
135
  system.addConnector('singleRight');
131
136
  system.addConnector('singleLeft');
137
+ id('m7a').addModifier(f.Articulation({ type: 'a-', position: 'above' }));
132
138
  id('m7a').addModifier(f.Fingering({ number: '2', position: 'below' }), 0);
133
139
  id('m7b').addModifier(f.Fingering({ number: '1' }), 0);
134
140
  id('m7c').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
135
141
  system = appendSystem(180);
136
- const grace = f.GraceNote({ keys: ['d/3'], clef: 'bass', duration: '4', slash: false });
142
+ const grace = f.GraceNote({ keys: ['b/4'], duration: '8', slash: true });
137
143
  system.addStave({ voices: [voice(notes('A4/h.[id="m8c"]'))] });
138
144
  system.addStave({
139
145
  voices: [
@@ -144,7 +150,7 @@ function minuetInG(options) {
144
150
  });
145
151
  system.addConnector('singleRight');
146
152
  id('m8b').addModifier(f.Fingering({ number: '1', position: 'above' }), 0);
147
- id('m8c').addModifier(f.GraceNoteGroup({ notes: [grace] }), 0);
153
+ id('m8c').addModifier(f.GraceNoteGroup({ notes: [grace], slur: true }), 0);
148
154
  f.Curve({
149
155
  from: id('m7a'),
150
156
  to: id('m8c'),
@@ -158,10 +164,10 @@ function minuetInG(options) {
158
164
  positionEnd: 'nearTop',
159
165
  },
160
166
  });
161
- f.StaveTie({ from: grace, to: id('m8c') });
162
167
  system = appendSystem(180);
163
168
  system.addStave({
164
169
  voices: [
170
+ voice([f.TextDynamics({ text: 'pp', duration: 'h', dots: 1, line: 9 })]),
165
171
  score
166
172
  .set({ clef: 'treble' })
167
173
  .voice([notes('D5/q[id="m9a"]'), beam(notes('G4/8, A4, B4, C5', { stem: 'up' }))].reduce(concat)),
@@ -190,8 +196,11 @@ function minuetInG(options) {
190
196
  });
191
197
  system = appendSystem(150);
192
198
  system.addStave({
193
- voices: [voice([notes('E5/q[id="m11a"]'), beam(notes('C5/8, D5, E5, F5', { stem: 'down' }))].reduce(concat))],
199
+ voices: [
200
+ voice([notes('E5/q[id="m11a"]'), beam(notes('C5/8[id="m11cut"], D5, E5, F5', { stem: 'down' }))].reduce(concat)),
201
+ ],
194
202
  });
203
+ id('m11cut').addModifier(f.Ornament('mordent'));
195
204
  id('m11a').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
196
205
  system.addStave({ voices: [voice(notes('C4/h.', { clef: 'bass' }))] });
197
206
  system.addConnector('singleRight');
@@ -215,8 +224,8 @@ function minuetInG(options) {
215
224
  to: id('m12a'),
216
225
  options: {
217
226
  cps: [
218
- { x: 0, y: 20 },
219
- { x: 0, y: 20 },
227
+ { x: 0, y: 39 },
228
+ { x: 0, y: 39 },
220
229
  ],
221
230
  },
222
231
  });
@@ -248,7 +257,7 @@ function minuetInG(options) {
248
257
  voices: [
249
258
  score
250
259
  .set({ clef: 'treble' })
251
- .voice([notes('B4/q'), beam(notes('C5/8, b4, a4, g4', { stem: 'up' }))].reduce(concat)),
260
+ .voice([notes('B4/q'), beam(notes('C5/8, b4, a4, g4[id="m14end"]', { stem: 'up' }))].reduce(concat)),
252
261
  ],
253
262
  });
254
263
  system.addStave({ voices: [voice(notes('g3/h[id="m14a"], b3/q[id="m14b"]', { clef: 'bass' }))] });
@@ -274,7 +283,7 @@ function minuetInG(options) {
274
283
  })
275
284
  .setEndBarType(BarlineType.REPEAT_END);
276
285
  system
277
- .addStave({ voices: [voice(notes('g3/h[id="m16b"], g2/q', { clef: 'bass' }))] })
286
+ .addStave({ voices: [voice(notes('g3/h[id="m16b"], g2/q[id="lift16"]', { clef: 'bass' }))] })
278
287
  .setEndBarType(BarlineType.REPEAT_END);
279
288
  system.addConnector('boldDoubleRight');
280
289
  id('m16a').addModifier(f.Fingering({ number: '1' }), 0);
@@ -327,6 +336,9 @@ function minuetInG(options) {
327
336
  ],
328
337
  },
329
338
  });
339
+ f.StaveHairpin({ from: id('m5a'), to: id('m6a'), type: StaveHairpin.type.CRESC });
340
+ f.StaveHairpin({ from: id('m13a'), to: id('m14end'), type: StaveHairpin.type.DECRESC });
341
+ f.PedalMarking({ notes: [id('m16b'), id('lift16')] });
330
342
  f.draw();
331
343
  Registry.disableDefaultRegistry();
332
344
  options.assert.ok(true, 'Petzold Minuet in G');