vexflow 5.2.0 → 5.4.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 (189) hide show
  1. package/README.md +2 -0
  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 +6502 -1708
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +5622 -1618
  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 +10 -3
  13. package/build/esm/src/alternatingtremolo.js +68 -0
  14. package/build/esm/src/annotation.js +19 -3
  15. package/build/esm/src/articulation.js +28 -6
  16. package/build/esm/src/beam.js +171 -28
  17. package/build/esm/src/bend.js +79 -23
  18. package/build/esm/src/clef.js +3 -0
  19. package/build/esm/src/continuouslayout.js +681 -0
  20. package/build/esm/src/continuousspan.js +159 -0
  21. package/build/esm/src/curve.js +48 -55
  22. package/build/esm/src/dot.js +13 -4
  23. package/build/esm/src/easyscore/composition.js +52 -2
  24. package/build/esm/src/easyscore/policies.js +39 -8
  25. package/build/esm/src/element.js +4 -0
  26. package/build/esm/src/engravinggeometry.js +157 -0
  27. package/build/esm/src/engravingprofile.js +44 -0
  28. package/build/esm/src/factory.js +31 -11
  29. package/build/esm/src/font.js +9 -1
  30. package/build/esm/src/formatter.js +9 -1
  31. package/build/esm/src/fretdiagram.js +77 -0
  32. package/build/esm/src/gracenote.js +43 -38
  33. package/build/esm/src/gracenotegroup.js +53 -56
  34. package/build/esm/src/guitargesture.js +33 -0
  35. package/build/esm/src/guitarmodifiers.js +26 -0
  36. package/build/esm/src/index.js +10 -0
  37. package/build/esm/src/instrumentprofile.js +123 -0
  38. package/build/esm/src/keysignature.js +24 -2
  39. package/build/esm/src/modifiercontext.js +11 -0
  40. package/build/esm/src/notationspelling.js +73 -0
  41. package/build/esm/src/note.js +3 -0
  42. package/build/esm/src/notehead.js +11 -6
  43. package/build/esm/src/ornament.js +43 -18
  44. package/build/esm/src/pagebreaks.js +58 -0
  45. package/build/esm/src/pedalmarking.js +39 -17
  46. package/build/esm/src/phraselayout.js +503 -0
  47. package/build/esm/src/phraseribbon.js +28 -0
  48. package/build/esm/src/proportionalformatter.js +54 -6
  49. package/build/esm/src/publication.js +402 -0
  50. package/build/esm/src/publicationview.js +114 -0
  51. package/build/esm/src/scorenavigation.js +172 -0
  52. package/build/esm/src/sheet.js +14 -2
  53. package/build/esm/src/stave.js +33 -16
  54. package/build/esm/src/stavebarline.js +5 -7
  55. package/build/esm/src/staveconnector.js +1 -0
  56. package/build/esm/src/stavehairpin.js +53 -27
  57. package/build/esm/src/stavenote.js +134 -116
  58. package/build/esm/src/stavetie.js +66 -9
  59. package/build/esm/src/stem.js +26 -11
  60. package/build/esm/src/strokes.js +4 -0
  61. package/build/esm/src/system.js +19 -4
  62. package/build/esm/src/systembreaks.js +42 -0
  63. package/build/esm/src/tabnote.js +6 -1
  64. package/build/esm/src/textbracket.js +24 -5
  65. package/build/esm/src/tickcontext.js +19 -0
  66. package/build/esm/src/timesignature.js +20 -6
  67. package/build/esm/src/tuplet.js +58 -17
  68. package/build/esm/src/version.js +3 -3
  69. package/build/esm/src/vexflow.js +20 -0
  70. package/build/esm/src/voice.js +7 -3
  71. package/build/esm/tests/bend_tests.js +14 -1
  72. package/build/esm/tests/curve_tests.js +14 -4
  73. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  74. package/build/esm/tests/demos/drums.js +54 -0
  75. package/build/esm/tests/demos/electric.js +63 -0
  76. package/build/esm/tests/demos/greensleeves.js +90 -0
  77. package/build/esm/tests/demos/joy.js +61 -0
  78. package/build/esm/tests/demos/kesh.js +80 -0
  79. package/build/esm/tests/demos/prelude.js +59 -0
  80. package/build/esm/tests/demos/quartertones.js +50 -0
  81. package/build/esm/tests/demos/saints.js +65 -0
  82. package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
  83. package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
  84. package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
  85. package/build/esm/tests/engraving/publication-studies.mjs +87 -0
  86. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  87. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  88. package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
  89. package/build/esm/tests/engraving/studies.mjs +367 -0
  90. package/build/esm/tests/formatter_tests.js +10 -1
  91. package/build/esm/tests/index.js +1 -0
  92. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  93. package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
  94. package/build/esm/tests/node/easyscore-tests.mjs +71 -0
  95. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  96. package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
  97. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  98. package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
  99. package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
  100. package/build/esm/tests/node/publication-tests.mjs +219 -0
  101. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  102. package/build/esm/tests/threevoice_tests.js +11 -1
  103. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  104. package/build/esm/tools/audit-dependencies.mjs +61 -0
  105. package/build/esm/tools/easyscore-structure.mjs +1 -1
  106. package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
  107. package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
  108. package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
  109. package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
  110. package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
  111. package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
  112. package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
  113. package/build/esm/tools/score-fixtures.mjs +23 -6
  114. package/build/types/src/accidental.d.ts +4 -0
  115. package/build/types/src/alternatingtremolo.d.ts +13 -0
  116. package/build/types/src/annotation.d.ts +9 -0
  117. package/build/types/src/articulation.d.ts +9 -1
  118. package/build/types/src/beam.d.ts +16 -0
  119. package/build/types/src/bend.d.ts +8 -0
  120. package/build/types/src/clef.d.ts +3 -0
  121. package/build/types/src/continuouslayout.d.ts +103 -0
  122. package/build/types/src/continuousspan.d.ts +60 -0
  123. package/build/types/src/curve.d.ts +20 -0
  124. package/build/types/src/dot.d.ts +5 -0
  125. package/build/types/src/easyscore/composition.d.ts +27 -0
  126. package/build/types/src/easyscore/policies.d.ts +1 -1
  127. package/build/types/src/element.d.ts +2 -0
  128. package/build/types/src/engravinggeometry.d.ts +31 -0
  129. package/build/types/src/engravingprofile.d.ts +20 -0
  130. package/build/types/src/factory.d.ts +6 -1
  131. package/build/types/src/formatter.d.ts +3 -3
  132. package/build/types/src/fretdiagram.d.ts +23 -0
  133. package/build/types/src/gracenote.d.ts +7 -0
  134. package/build/types/src/gracenotegroup.d.ts +7 -2
  135. package/build/types/src/guitargesture.d.ts +26 -0
  136. package/build/types/src/guitarmodifiers.d.ts +3 -0
  137. package/build/types/src/index.d.ts +12 -0
  138. package/build/types/src/instrumentprofile.d.ts +124 -0
  139. package/build/types/src/keysignature.d.ts +9 -0
  140. package/build/types/src/modifiercontext.d.ts +4 -0
  141. package/build/types/src/notationspelling.d.ts +25 -0
  142. package/build/types/src/note.d.ts +15 -0
  143. package/build/types/src/notehead.d.ts +5 -0
  144. package/build/types/src/ornament.d.ts +10 -1
  145. package/build/types/src/pagebreaks.d.ts +26 -0
  146. package/build/types/src/pedalmarking.d.ts +9 -0
  147. package/build/types/src/phraselayout.d.ts +87 -0
  148. package/build/types/src/phraseribbon.d.ts +7 -0
  149. package/build/types/src/proportionalformatter.d.ts +11 -2
  150. package/build/types/src/publication.d.ts +61 -0
  151. package/build/types/src/publicationview.d.ts +27 -0
  152. package/build/types/src/scorenavigation.d.ts +33 -0
  153. package/build/types/src/sheet.d.ts +5 -0
  154. package/build/types/src/stave.d.ts +13 -0
  155. package/build/types/src/stavehairpin.d.ts +18 -0
  156. package/build/types/src/stavenote.d.ts +20 -2
  157. package/build/types/src/stavetie.d.ts +9 -0
  158. package/build/types/src/stem.d.ts +10 -1
  159. package/build/types/src/system.d.ts +8 -1
  160. package/build/types/src/systembreaks.d.ts +9 -0
  161. package/build/types/src/textbracket.d.ts +7 -0
  162. package/build/types/src/tickcontext.d.ts +5 -0
  163. package/build/types/src/timesignature.d.ts +6 -0
  164. package/build/types/src/tuplet.d.ts +5 -48
  165. package/build/types/src/vexflow.d.ts +20 -0
  166. package/build/types/src/voice.d.ts +2 -0
  167. package/changelog/CHANGELOG.md +25 -0
  168. package/package.json +15 -3
  169. package/tests/all.html +277 -0
  170. package/tests/demo_petzold_tests.ts +435 -0
  171. package/tests/demos/drums.ts +55 -0
  172. package/tests/demos/drums.webp +0 -0
  173. package/tests/demos/electric.ts +70 -0
  174. package/tests/demos/electric.webp +0 -0
  175. package/tests/demos/greensleeves.ts +97 -0
  176. package/tests/demos/greensleeves.webp +0 -0
  177. package/tests/demos/joy.ts +65 -0
  178. package/tests/demos/joy.webp +0 -0
  179. package/tests/demos/kesh.ts +86 -0
  180. package/tests/demos/kesh.webp +0 -0
  181. package/tests/demos/prelude.ts +65 -0
  182. package/tests/demos/prelude.webp +0 -0
  183. package/tests/demos/quartertones.ts +51 -0
  184. package/tests/demos/quartertones.webp +0 -0
  185. package/tests/demos/saints.ts +70 -0
  186. package/tests/demos/saints.webp +0 -0
  187. package/tests/flow.html +550 -239
  188. package/tests/fonts.css +493 -0
  189. package/tests/minuet.webp +0 -0
@@ -1,5 +1,6 @@
1
1
  import { BoundingBox } from './boundingbox.js';
2
2
  import { Glyphs } from './glyphs.js';
3
+ import { attachGuitarGestures } from './guitarmodifiers.js';
3
4
  import { Metrics } from './metrics.js';
4
5
  import { Modifier } from './modifier.js';
5
6
  import { Note } from './note.js';
@@ -77,41 +78,37 @@ export class StaveNote extends StemmableNote {
77
78
  note: notes[i],
78
79
  });
79
80
  }
80
- let voices = 0;
81
- let noteU = undefined;
82
- let noteM = undefined;
83
- let noteL = undefined;
84
- const draw = [false, false, false];
85
- for (let i = 0; i < notesList.length; i++) {
86
- draw[i] = notesList[i].note.renderOptions.draw !== false;
87
- }
88
- if (draw[0] && draw[1] && draw[2]) {
89
- voices = 3;
90
- noteU = notesList[0];
91
- noteM = notesList[1];
92
- noteL = notesList[2];
93
- }
94
- else if (draw[0] && draw[1]) {
95
- voices = 2;
96
- noteU = notesList[0];
97
- noteL = notesList[1];
98
- }
99
- else if (draw[0] && draw[2]) {
100
- voices = 2;
101
- noteU = notesList[0];
102
- noteL = notesList[2];
103
- }
104
- else if (draw[1] && draw[2]) {
105
- voices = 2;
106
- noteU = notesList[1];
107
- noteL = notesList[2];
108
- }
109
- else {
81
+ const visible = notesList.filter((item) => item.note.renderOptions.draw !== false);
82
+ if (visible.length < 2)
83
+ return true;
84
+ if (visible.length > 3) {
85
+ const columns = [];
86
+ for (const item of visible.sort((a, b) => b.maxLine - a.maxLine || b.line - a.line)) {
87
+ let column = columns.find((entry) => item.maxLine + 0.5 < entry.bottom);
88
+ if (!column) {
89
+ column = { bottom: item.minLine, width: 0, members: [] };
90
+ columns.push(column);
91
+ }
92
+ column.bottom = item.minLine;
93
+ column.width = Math.max(column.width, item.voiceShift);
94
+ column.members.push(item);
95
+ }
96
+ let x = 0;
97
+ for (const column of columns) {
98
+ for (const item of column.members)
99
+ item.note.setXShift(x);
100
+ if (column !== columns[columns.length - 1])
101
+ x += column.width + 2;
102
+ }
103
+ state.rightShift += x;
110
104
  return true;
111
105
  }
106
+ const voices = visible.length;
107
+ let noteU = visible[0];
108
+ let noteL = visible[voices - 1];
109
+ const noteM = voices === 3 ? visible[1] : undefined;
112
110
  if (voices === 2 && noteU.stemDirection === -1 && noteL.stemDirection === 1) {
113
- noteU = notesList[1];
114
- noteL = notesList[0];
111
+ [noteU, noteL] = [noteL, noteU];
115
112
  }
116
113
  const voiceXShift = Math.max(noteU.voiceShift, noteL.voiceShift);
117
114
  let xShift = 0;
@@ -250,19 +247,24 @@ export class StaveNote extends StemmableNote {
250
247
  return true;
251
248
  }
252
249
  constructor(noteStruct) {
253
- var _a, _b, _c;
250
+ var _a, _b, _c, _d, _e;
254
251
  super(noteStruct);
255
252
  this.minLine = 0;
256
253
  this.maxLine = 0;
254
+ this.useDefaultHeadX = false;
255
+ this.extraHeadColumns = 0;
257
256
  this.sortedKeyProps = [];
257
+ this.engraving = noteStruct.engraving;
258
+ const musicFont = (_a = noteStruct.musicFont) !== null && _a !== void 0 ? _a : (_b = this.engraving) === null || _b === void 0 ? void 0 : _b.musicFont;
259
+ if (musicFont)
260
+ this.setFont(Object.assign(Object.assign({}, this.fontInfo), { family: musicFont }));
258
261
  this.ledgerLineStyle = {};
259
- this.clef = (_a = noteStruct.clef) !== null && _a !== void 0 ? _a : 'treble';
260
- this.octaveShift = (_b = noteStruct.octaveShift) !== null && _b !== void 0 ? _b : 0;
262
+ this.clef = (_c = noteStruct.clef) !== null && _c !== void 0 ? _c : 'treble';
263
+ this.octaveShift = (_d = noteStruct.octaveShift) !== null && _d !== void 0 ? _d : 0;
261
264
  this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
262
265
  defined(this.glyphProps, 'BadArguments', `No glyph found for duration '${this.duration}' and type '${this.noteType}'`);
263
266
  this.displaced = false;
264
267
  this.dotShiftY = 0;
265
- this.useDefaultHeadX = false;
266
268
  this._noteHeads = [];
267
269
  this.modifiers = [];
268
270
  this.renderOptions = Object.assign(Object.assign({}, this.renderOptions), { strokePx: noteStruct.strokePx || StaveNote.LEDGER_LINE_OFFSET });
@@ -272,8 +274,10 @@ export class StaveNote extends StemmableNote {
272
274
  this.autoStem();
273
275
  }
274
276
  else {
275
- this.setStemDirection((_c = noteStruct.stemDirection) !== null && _c !== void 0 ? _c : Stem.UP);
277
+ this.setStemDirection((_e = noteStruct.stemDirection) !== null && _e !== void 0 ? _e : Stem.UP);
276
278
  }
279
+ if (this.notation.length)
280
+ attachGuitarGestures(this);
277
281
  }
278
282
  reset() {
279
283
  super.reset();
@@ -309,9 +313,8 @@ export class StaveNote extends StemmableNote {
309
313
  this._noteHeads = [];
310
314
  const stemDirection = this.getStemDirection();
311
315
  const keys = this.getKeys();
312
- let lastLine = undefined;
313
- let lineDiff = undefined;
314
- let displaced = false;
316
+ const lastLineInColumn = [];
317
+ this.extraHeadColumns = 0;
315
318
  let start;
316
319
  let end;
317
320
  let step;
@@ -328,24 +331,17 @@ export class StaveNote extends StemmableNote {
328
331
  for (let i = start; i !== end; i += step) {
329
332
  const noteProps = this.sortedKeyProps[i].keyProps;
330
333
  const line = noteProps.line;
331
- if (lastLine === undefined) {
332
- lastLine = line;
333
- }
334
- else {
335
- lineDiff = Math.abs(lastLine - line);
336
- if (lineDiff === 0 || lineDiff === 0.5) {
337
- displaced = !displaced;
338
- }
339
- else {
340
- displaced = false;
341
- this.useDefaultHeadX = true;
342
- }
343
- }
344
- lastLine = line;
334
+ let column = lastLineInColumn.findIndex((previous) => Math.abs(previous - line) >= 1);
335
+ if (i !== start && Math.abs(this.sortedKeyProps[i - step].keyProps.line - line) >= 1)
336
+ this.useDefaultHeadX = true;
337
+ if (column < 0)
338
+ column = lastLineInColumn.length;
339
+ lastLineInColumn[column] = line;
340
+ this.extraHeadColumns = Math.max(this.extraHeadColumns, column);
345
341
  const notehead = new NoteHead({
346
342
  duration: this.duration,
347
343
  noteType: this.noteType,
348
- displaced,
344
+ displacementColumn: column,
349
345
  stemDirection,
350
346
  customGlyphCode: noteProps.code,
351
347
  line: noteProps.line,
@@ -369,7 +365,6 @@ export class StaveNote extends StemmableNote {
369
365
  }
370
366
  calculateKeyProps() {
371
367
  var _a;
372
- let lastLine;
373
368
  for (let i = 0; i < this.keys.length; ++i) {
374
369
  const key = this.keys[i];
375
370
  const options = { octaveShift: (_a = this.octaveShift) !== null && _a !== void 0 ? _a : 0, duration: this.duration };
@@ -385,33 +380,44 @@ export class StaveNote extends StemmableNote {
385
380
  props.line = 3;
386
381
  }
387
382
  }
388
- const line = props.line;
389
- if (lastLine === undefined) {
390
- lastLine = line;
391
- }
392
- else {
393
- if (Math.abs(lastLine - line) < 1) {
394
- this.displaced = true;
395
- props.displaced = true;
396
- if (this.keyProps.length > 0) {
397
- this.keyProps[i - 1].displaced = true;
398
- }
399
- }
400
- }
401
- lastLine = line;
402
383
  this.keyProps.push(props);
403
384
  }
404
385
  this.keyProps.forEach((keyProps, index) => {
405
386
  this.sortedKeyProps.push({ keyProps, index });
406
387
  });
407
388
  this.sortedKeyProps.sort((a, b) => a.keyProps.line - b.keyProps.line);
389
+ for (let i = 1; i < this.sortedKeyProps.length; i++) {
390
+ const lower = this.sortedKeyProps[i - 1].keyProps;
391
+ const upper = this.sortedKeyProps[i].keyProps;
392
+ if (upper.line - lower.line < 1) {
393
+ this.displaced = true;
394
+ lower.displaced = upper.displaced = true;
395
+ }
396
+ }
397
+ }
398
+ getHeadInk() {
399
+ return this._noteHeads.map((head) => {
400
+ const displacement = head.getDisplacementX();
401
+ return head.getTextInk(this.getNoteHeadBeginX() + displacement, head.getY());
402
+ });
403
+ }
404
+ getFlagInk() {
405
+ if (!this.shouldDrawFlag())
406
+ return;
407
+ const { x, y } = this.getFlagPosition();
408
+ return this.flag.getTextInk(x, y);
409
+ }
410
+ getStemSegment() {
411
+ var _a;
412
+ if (!((_a = this.stem) === null || _a === void 0 ? void 0 : _a.isVisible()) || (!this.hasStem() && !this.beam))
413
+ return;
414
+ const adjustment = this.shouldDrawFlag() ? Metrics.get('Stem.heightAdjustmentForFlag', -3) : undefined;
415
+ return this.checkStem().getSegment(this.getStemX(), adjustment);
408
416
  }
409
417
  getBoundingBox(includeModifiers = true) {
410
418
  const boundingBox = new BoundingBox(this.getAbsoluteX(), this.ys[0], 0, 0);
411
419
  this._noteHeads.forEach((notehead) => {
412
- const displacement = notehead.isDisplaced()
413
- ? (notehead.getWidth() - Stem.WIDTH / 2) * this.getStemDirection()
414
- : 0;
420
+ const displacement = notehead.getDisplacementX();
415
421
  const box = notehead.getBoundingBox();
416
422
  box.setX(this.getNoteHeadBeginX() + displacement + notehead.getXShift());
417
423
  boundingBox.mergeWith(box);
@@ -468,10 +474,21 @@ export class StaveNote extends StemmableNote {
468
474
  return super.hasFlag() && !this.isRest();
469
475
  }
470
476
  getStemX() {
477
+ var _a;
471
478
  if (this.noteType === 'r') {
472
479
  return this.getCenterGlyphX();
473
480
  }
474
481
  else {
482
+ 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);
491
+ }
475
492
  return super.getStemX() + (this.stemDirection ? Stem.WIDTH / (2 * -this.stemDirection) : 0);
476
493
  }
477
494
  }
@@ -620,11 +637,12 @@ export class StaveNote extends StemmableNote {
620
637
  return this.keyProps[index].line;
621
638
  }
622
639
  getVoiceShiftWidth() {
623
- return this.getGlyphWidth() * (this.displaced ? 2 : 1);
640
+ return this.getGlyphWidth() * (this.displaced ? 1 + Math.max(1, this.extraHeadColumns) : 1);
624
641
  }
625
642
  calcNoteDisplacements() {
626
- this.setLeftDisplacedHeadPx(this.displaced && this.stemDirection === Stem.DOWN ? this.getGlyphWidth() : 0);
627
- this.setRightDisplacedHeadPx(!this.hasFlag() && this.displaced && this.stemDirection === Stem.UP ? this.getGlyphWidth() : 0);
643
+ const extra = this.getVoiceShiftWidth() - this.getGlyphWidth();
644
+ this.setLeftDisplacedHeadPx(this.stemDirection === Stem.DOWN ? extra : 0);
645
+ this.setRightDisplacedHeadPx(this.stemDirection === Stem.UP ? Math.max(0, extra - (this.hasFlag() ? this.getGlyphWidth() : 0)) : 0);
628
646
  }
629
647
  preFormat() {
630
648
  if (this.preFormatted)
@@ -650,7 +668,10 @@ export class StaveNote extends StemmableNote {
650
668
  this._noteHeads.forEach((nh) => {
651
669
  const offset = Tables.noteHeadStemYOffsets[nh.text];
652
670
  const anchor = offset ? offset[anchorKey] : 0;
653
- const y = nh.getY() - anchor * Tables.STAVE_LINE_DISTANCE;
671
+ const fontAnchor = this.engraving && this.engraving.musicFont === nh.fontInfo.family
672
+ ? this.engraving.stemAnchor(nh.text, anchorKey)
673
+ : undefined;
674
+ const y = nh.getY() - (fontAnchor ? (fontAnchor[1] * nh.fontSizeInPixels) / 4 : anchor * Tables.STAVE_LINE_DISTANCE);
654
675
  yTop = Math.min(y, yTop);
655
676
  yBottom = Math.max(y, yBottom);
656
677
  });
@@ -660,7 +681,7 @@ export class StaveNote extends StemmableNote {
660
681
  }
661
682
  return { yTop, yBottom };
662
683
  }
663
- getNoteHeadBounds() {
684
+ getNoteHeadBounds(layoutX = false) {
664
685
  let yTop = +Infinity;
665
686
  let yBottom = -Infinity;
666
687
  let nonDisplacedX;
@@ -677,10 +698,10 @@ export class StaveNote extends StemmableNote {
677
698
  yTop = Math.min(y, yTop);
678
699
  yBottom = Math.max(y, yBottom);
679
700
  if (displacedX === undefined && notehead.isDisplaced()) {
680
- displacedX = notehead.getAbsoluteX();
701
+ displacedX = layoutX ? this.getNoteHeadBeginX() + notehead.getDisplacementX() : notehead.getAbsoluteX();
681
702
  }
682
703
  if (nonDisplacedX === undefined && !notehead.isDisplaced()) {
683
- nonDisplacedX = notehead.getAbsoluteX();
704
+ nonDisplacedX = layoutX ? this.getNoteHeadBeginX() : notehead.getAbsoluteX();
684
705
  }
685
706
  highestLine = Math.max(line, highestLine);
686
707
  lowestLine = Math.min(line, lowestLine);
@@ -716,47 +737,42 @@ export class StaveNote extends StemmableNote {
716
737
  get noteHeads() {
717
738
  return this._noteHeads.slice();
718
739
  }
719
- drawLedgerLines() {
740
+ getLedgerLines() {
741
+ const lines = [];
720
742
  const stave = this.checkStave();
721
- const { renderOptions: { strokePx }, } = this;
722
- const ctx = this.checkContext();
723
- const width = this.getGlyphWidth() + strokePx * 2;
724
- const doubleWidth = 2 * (this.getGlyphWidth() + strokePx) - Stem.WIDTH / 2;
743
+ const { strokePx } = this.renderOptions;
725
744
  if (this.isRest())
745
+ return lines;
746
+ const { highestLine, lowestLine } = this.getNoteHeadBounds(true);
747
+ const addLedger = (line, heads) => {
748
+ if (!heads.length)
749
+ return;
750
+ const left = Math.min(...heads.map((head) => head.getDisplacementX()));
751
+ const right = Math.max(...heads.map((head) => head.getDisplacementX() + head.getWidth()));
752
+ lines.push({
753
+ x: this.getNoteHeadBeginX() + left - strokePx,
754
+ y: stave.getYForNote(line),
755
+ width: right - left + 2 * strokePx,
756
+ });
757
+ };
758
+ for (let line = 6; line <= highestLine; ++line)
759
+ addLedger(line, this._noteHeads.filter((head) => head.getLine() >= line));
760
+ for (let line = 0; line >= lowestLine; --line)
761
+ addLedger(line, this._noteHeads.filter((head) => head.getLine() <= line));
762
+ return lines;
763
+ }
764
+ drawLedgerLines() {
765
+ const lines = this.getLedgerLines();
766
+ if (!lines.length)
726
767
  return;
727
- if (!ctx) {
728
- throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
729
- }
730
- const { highestLine, lowestLine, highestDisplacedLine, highestNonDisplacedLine, lowestDisplacedLine, lowestNonDisplacedLine, displacedX, nonDisplacedX, } = this.getNoteHeadBounds();
731
- if (highestLine < 6 && lowestLine > 0)
732
- return;
733
- const minX = Math.min(displacedX !== null && displacedX !== void 0 ? displacedX : 0, nonDisplacedX !== null && nonDisplacedX !== void 0 ? nonDisplacedX : 0);
734
- const drawLedgerLine = (y, normal, displaced) => {
735
- let x;
736
- if (displaced && normal)
737
- x = minX - strokePx;
738
- else if (normal)
739
- x = (nonDisplacedX !== null && nonDisplacedX !== void 0 ? nonDisplacedX : 0) - strokePx;
740
- else
741
- x = (displacedX !== null && displacedX !== void 0 ? displacedX : 0) - strokePx;
742
- const ledgerWidth = normal && displaced ? doubleWidth : width;
768
+ const ctx = this.checkContext();
769
+ ctx.save();
770
+ this.applyStyle(ctx, Object.assign(Object.assign({}, this.checkStave().getDefaultLedgerLineStyle()), this.getLedgerLineStyle()));
771
+ for (const { x, y, width } of lines) {
743
772
  ctx.beginPath();
744
773
  ctx.moveTo(x, y);
745
- ctx.lineTo(x + ledgerWidth, y);
774
+ ctx.lineTo(x + width, y);
746
775
  ctx.stroke();
747
- };
748
- const style = Object.assign(Object.assign({}, stave.getDefaultLedgerLineStyle()), this.getLedgerLineStyle());
749
- ctx.save();
750
- this.applyStyle(ctx, style);
751
- for (let line = 6; line <= highestLine; ++line) {
752
- const normal = nonDisplacedX !== undefined && line <= highestNonDisplacedLine;
753
- const displaced = highestDisplacedLine !== undefined && line <= highestDisplacedLine;
754
- drawLedgerLine(stave.getYForNote(line), normal, displaced);
755
- }
756
- for (let line = 0; line >= lowestLine; --line) {
757
- const normal = nonDisplacedX !== undefined && line >= lowestNonDisplacedLine;
758
- const displaced = lowestDisplacedLine !== undefined && line >= lowestDisplacedLine;
759
- drawLedgerLine(stave.getYForNote(line), normal, displaced);
760
776
  }
761
777
  ctx.restore();
762
778
  }
@@ -859,7 +875,9 @@ export class StaveNote extends StemmableNote {
859
875
  }
860
876
  L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
861
877
  const clsAttribute = this.getAttribute('class');
862
- ctx.openGroup('stavenote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
878
+ const group = ctx.openGroup('stavenote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
879
+ if (this.notation.length)
880
+ group === null || group === void 0 ? void 0 : group.setAttribute('aria-label', this.notation.map((entry) => entry.label).join(', '));
863
881
  this.drawLedgerLines();
864
882
  if (shouldRenderStem)
865
883
  this.drawStem();
@@ -1,4 +1,6 @@
1
+ import { BoundingBox } from './boundingbox.js';
1
2
  import { Element } from './element.js';
3
+ import { ribbonParts } from './phraseribbon.js';
2
4
  import { RuntimeError } from './util.js';
3
5
  export class StaveTie extends Element {
4
6
  static get CATEGORY() {
@@ -6,6 +8,7 @@ export class StaveTie extends Element {
6
8
  }
7
9
  constructor(notes, text = '') {
8
10
  super();
11
+ this.layoutRise = 0;
9
12
  this.setNotes(notes);
10
13
  this.text = text;
11
14
  this.renderOptions = {
@@ -58,11 +61,10 @@ export class StaveTie extends Element {
58
61
  isPartial() {
59
62
  return !this.notes.firstNote || !this.notes.lastNote;
60
63
  }
61
- renderTie(params) {
64
+ *tieCurves(params) {
62
65
  if (params.firstYs.length === 0 || params.lastYs.length === 0) {
63
66
  throw new RuntimeError('BadArguments', 'No Y-values to render');
64
67
  }
65
- const ctx = this.checkContext();
66
68
  let cp1 = this.renderOptions.cp1;
67
69
  let cp2 = this.renderOptions.cp2;
68
70
  if (Math.abs(params.lastX - params.firstX) < this.renderOptions.shortTieCutoff) {
@@ -74,8 +76,6 @@ export class StaveTie extends Element {
74
76
  const yShift = this.renderOptions.yShift * params.direction;
75
77
  const firstIndexes = this.notes.firstIndexes;
76
78
  const lastIndexes = this.notes.lastIndexes;
77
- const clsAttribute = this.getAttribute('class');
78
- ctx.openGroup('stavetie' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
79
79
  for (let i = 0; i < firstIndexes.length; ++i) {
80
80
  const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
81
81
  const firstY = params.firstYs[firstIndexes[i]] + yShift;
@@ -83,12 +83,69 @@ export class StaveTie extends Element {
83
83
  if (isNaN(firstY) || isNaN(lastY)) {
84
84
  throw new RuntimeError('BadArguments', 'Bad indexes for tie rendering.');
85
85
  }
86
- const topControlPointY = (firstY + lastY) / 2 + cp1 * params.direction;
87
- const bottomControlPointY = (firstY + lastY) / 2 + cp2 * params.direction;
86
+ const topControlPointY = (firstY + lastY) / 2 + (cp1 + this.layoutRise) * params.direction;
87
+ const bottomControlPointY = (firstY + lastY) / 2 + (cp2 + this.layoutRise) * params.direction;
88
+ yield {
89
+ x1: params.firstX + firstXShift,
90
+ x2: params.lastX + lastXShift,
91
+ firstY,
92
+ lastY,
93
+ cpX,
94
+ topControlPointY,
95
+ bottomControlPointY,
96
+ };
97
+ }
98
+ }
99
+ setLayoutRise(rise) {
100
+ this.layoutRise = rise;
101
+ }
102
+ hasManualControls() {
103
+ const { cp1, cp2, cp1Short, cp2Short } = this.renderOptions;
104
+ return cp1 !== 8 || cp2 !== 12 || cp1Short !== 2 || cp2Short !== 8;
105
+ }
106
+ getRouteParts() {
107
+ this.synchronizeIndexes();
108
+ const ribbons = this.tieCurves({
109
+ firstX: this.getFirstX(),
110
+ lastX: this.getLastX(),
111
+ firstYs: this.getFirstYs(),
112
+ lastYs: this.getLastYs(),
113
+ direction: this.getDirection(),
114
+ });
115
+ const parts = [];
116
+ for (const r of ribbons) {
117
+ const start = { x: r.x1, y: r.firstY }, end = { x: r.x2, y: r.lastY };
118
+ parts.push(...ribbonParts([start, { x: r.cpX, y: r.topControlPointY }, end], [start, { x: r.cpX, y: r.bottomControlPointY }, end]));
119
+ }
120
+ return parts;
121
+ }
122
+ getRibbonBounds() {
123
+ this.synchronizeIndexes();
124
+ const curves = this.tieCurves({
125
+ firstX: this.getFirstX(),
126
+ lastX: this.getLastX(),
127
+ firstYs: this.getFirstYs(),
128
+ lastYs: this.getLastYs(),
129
+ direction: this.getDirection(),
130
+ });
131
+ let box;
132
+ for (const { x1, x2, firstY, lastY, topControlPointY, bottomControlPointY } of curves) {
133
+ const top = Math.min(firstY, lastY, topControlPointY, bottomControlPointY);
134
+ const bottom = Math.max(firstY, lastY, topControlPointY, bottomControlPointY);
135
+ const part = new BoundingBox(Math.min(x1, x2), top, Math.abs(x2 - x1), bottom - top);
136
+ box = box ? box.mergeWith(part) : part;
137
+ }
138
+ return box !== null && box !== void 0 ? box : new BoundingBox(this.getFirstX(), this.getFirstYs()[0], 0, 0);
139
+ }
140
+ renderTie(params) {
141
+ const ctx = this.checkContext();
142
+ const clsAttribute = this.getAttribute('class');
143
+ ctx.openGroup('stavetie' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
144
+ for (const { x1, x2, firstY, lastY, cpX, topControlPointY, bottomControlPointY } of this.tieCurves(params)) {
88
145
  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);
146
+ ctx.moveTo(x1, firstY);
147
+ ctx.quadraticCurveTo(cpX, topControlPointY, x2, lastY);
148
+ ctx.quadraticCurveTo(cpX, bottomControlPointY, x1, firstY);
92
149
  ctx.closePath();
93
150
  ctx.fill();
94
151
  }
@@ -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
  }
@@ -81,6 +81,10 @@ export class Stroke extends Modifier {
81
81
  }
82
82
  }
83
83
  }
84
+ if (this.noteEnd) {
85
+ topY = Math.min(topY, ...this.noteEnd.getYs());
86
+ botY = Math.max(botY, ...this.noteEnd.getYs());
87
+ }
84
88
  let arrow = '';
85
89
  let arrowY = 0;
86
90
  let textY = 0;
@@ -2,6 +2,7 @@ import { BoundingBox } from './boundingbox.js';
2
2
  import { Element } from './element.js';
3
3
  import { Formatter } from './formatter.js';
4
4
  import { Note } from './note.js';
5
+ import { PhraseLayout } from './phraselayout.js';
5
6
  import { Stave } from './stave.js';
6
7
  import { RuntimeError } from './util.js';
7
8
  export class System extends Element {
@@ -103,7 +104,13 @@ export class System extends Element {
103
104
  this.partVoices.push(voice);
104
105
  });
105
106
  }
106
- format() {
107
+ getPhraseLayout() {
108
+ var _a;
109
+ return ((_a = this.phrase) !== null && _a !== void 0 ? _a : (this.phrase = new PhraseLayout()));
110
+ }
111
+ format(row) {
112
+ var _a, _b, _c, _d;
113
+ (_a = this.phrase) === null || _a === void 0 ? void 0 : _a.resetPlacement();
107
114
  const optionsDetails = this.options.details;
108
115
  let justifyWidth = 0;
109
116
  const formatter = new Formatter(optionsDetails);
@@ -113,6 +120,8 @@ export class System extends Element {
113
120
  const debugNoteMetricsYs = [];
114
121
  this.partStaves.forEach((part, index) => {
115
122
  y = y + part.space(this.partStaveInfos[index].spaceAbove);
123
+ if (row === null || row === void 0 ? void 0 : row.staffOffsets)
124
+ y = this.options.y + row.staffOffsets[index];
116
125
  part.setY(y);
117
126
  y = y + part.space(this.partStaveInfos[index].spaceBelow);
118
127
  y = y + part.space(this.options.spaceBetweenStaves);
@@ -133,7 +142,7 @@ export class System extends Element {
133
142
  this.partStaves.forEach((part) => part.setNoteStartX(startX));
134
143
  if (this.options.autoWidth && this.partVoices.length > 0) {
135
144
  justifyWidth = formatter.preCalculateMinTotalWidth(this.partVoices);
136
- this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x);
145
+ this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x) + ((_b = row === null || row === void 0 ? void 0 : row.endPadding) !== null && _b !== void 0 ? _b : 0);
137
146
  this.partStaves.forEach((part) => {
138
147
  part.setWidth(this.options.width);
139
148
  });
@@ -144,6 +153,8 @@ export class System extends Element {
144
153
  : this.options.width - (startX - this.options.x) - Stave.defaultPadding;
145
154
  }
146
155
  if (this.partVoices.length > 0) {
156
+ if (!this.options.autoWidth)
157
+ justifyWidth -= (_c = row === null || row === void 0 ? void 0 : row.endPadding) !== null && _c !== void 0 ? _c : 0;
147
158
  formatter.format(this.partVoices, this.options.noJustification ? 0 : justifyWidth, this.options.formatOptions);
148
159
  }
149
160
  formatter.postFormat();
@@ -154,17 +165,21 @@ export class System extends Element {
154
165
  this.debugNoteMetricsYs = debugNoteMetricsYs;
155
166
  this.lastY = y;
156
167
  Stave.formatBegModifiers(this.partStaves);
168
+ (_d = this.phrase) === null || _d === void 0 ? void 0 : _d.format(this.partStaves, this.partVoices);
157
169
  }
158
170
  getBoundingBox() {
159
- var _a;
160
- return new BoundingBox(this.options.x, this.options.y, this.options.width, ((_a = this.lastY) !== null && _a !== void 0 ? _a : 0) - this.options.y);
171
+ var _a, _b;
172
+ const box = new BoundingBox(this.options.x, this.options.y, this.options.width, ((_a = this.lastY) !== null && _a !== void 0 ? _a : 0) - this.options.y);
173
+ return ((_b = this.phrase) === null || _b === void 0 ? void 0 : _b.bounds) ? box.mergeWith(this.phrase.bounds) : box;
161
174
  }
162
175
  draw() {
176
+ var _a;
163
177
  const ctx = this.checkContext();
164
178
  if (!this.formatter || !this.startX || !this.lastY || !this.debugNoteMetricsYs) {
165
179
  throw new RuntimeError('NoFormatter', 'format() must be called before draw()');
166
180
  }
167
181
  this.setRendered();
182
+ (_a = this.phrase) === null || _a === void 0 ? void 0 : _a.draw(ctx);
168
183
  if (this.options.debugFormatter) {
169
184
  Formatter.plotDebugging(ctx, this.formatter, this.startX, this.options.y, this.lastY);
170
185
  }