vexflow 5.5.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 (92) 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 +692 -309
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +551 -253
  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 +6 -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/publicationview.js +3 -2
  25. package/build/esm/src/stave.js +4 -2
  26. package/build/esm/src/stavenote.js +56 -13
  27. package/build/esm/src/stavesection.js +15 -10
  28. package/build/esm/src/stavetie.js +3 -2
  29. package/build/esm/src/strokes.js +1 -1
  30. package/build/esm/src/svgcontext.js +11 -3
  31. package/build/esm/src/tabnote.js +6 -8
  32. package/build/esm/src/tabtie.js +3 -0
  33. package/build/esm/src/version.js +3 -3
  34. package/build/esm/tests/chordsymbol_tests.js +4 -1
  35. package/build/esm/tests/demo_repertoire_tests.js +1 -1
  36. package/build/esm/tests/demos/electric.js +1 -3
  37. package/build/esm/tests/demos/greensleeves.js +1 -2
  38. package/build/esm/tests/demos/kesh.js +2 -3
  39. package/build/esm/tests/demos/saints.js +17 -5
  40. package/build/esm/tests/engraving/continuous-studies.mjs +24 -0
  41. package/build/esm/tests/engraving/publication-studies.mjs +30 -0
  42. package/build/esm/tests/font_tests.js +8 -0
  43. package/build/esm/tests/gracetabnote_tests.js +19 -3
  44. package/build/esm/tests/node/chord-kerning-tests.mjs +2 -2
  45. package/build/esm/tests/node/continuous-score-tests.mjs +157 -2
  46. package/build/esm/tests/node/easyscore-tests.mjs +38 -0
  47. package/build/esm/tests/node/engraving-layout-tests.mjs +33 -0
  48. package/build/esm/tests/node/instrument-profile-tests.mjs +40 -0
  49. package/build/esm/tests/node/local-engraving-tests.mjs +58 -0
  50. package/build/esm/tests/node/metrics-tests.mjs +2 -0
  51. package/build/esm/tests/node/phrase-layout-tests.mjs +58 -5
  52. package/build/esm/tests/node/publication-tests.mjs +146 -4
  53. package/build/esm/tests/node/svg-export-tests.mjs +50 -21
  54. package/build/esm/tests/scores/electric.js +3 -4
  55. package/build/esm/tests/scores/kesh.js +1 -1
  56. package/build/esm/tests/scores/saints.js +10 -8
  57. package/build/esm/tests/scores/sumer.js +3 -1
  58. package/build/esm/tests/tabnote_tests.js +43 -0
  59. package/build/esm/tests/vexflow_test_helpers.js +1 -0
  60. package/build/esm/tools/explorer/catalog/expression.mjs +16 -6
  61. package/build/esm/tools/explorer/catalog/guitar.mjs +2 -2
  62. package/build/types/src/continuouslayout.d.ts +4 -0
  63. package/build/types/src/continuousspan.d.ts +8 -2
  64. package/build/types/src/easyscore/composition.d.ts +19 -0
  65. package/build/types/src/fretdiagram.d.ts +2 -0
  66. package/build/types/src/instrumentprofile.d.ts +4 -0
  67. package/build/types/src/note.d.ts +2 -0
  68. package/build/types/src/notehead.d.ts +2 -0
  69. package/build/types/src/stave.d.ts +4 -2
  70. package/build/types/src/stavenote.d.ts +10 -0
  71. package/build/types/src/stavesection.d.ts +3 -0
  72. package/build/types/src/svgcontext.d.ts +2 -0
  73. package/build/types/src/typeguard.d.ts +1 -0
  74. package/changelog/CHANGELOG.md +8 -0
  75. package/package.json +1 -1
  76. package/tests/demos/electric.ts +1 -3
  77. package/tests/demos/electric.webp +0 -0
  78. package/tests/demos/greensleeves.ts +1 -3
  79. package/tests/demos/greensleeves.webp +0 -0
  80. package/tests/demos/kesh.ts +2 -4
  81. package/tests/demos/kesh.webp +0 -0
  82. package/tests/demos/saints.ts +20 -7
  83. package/tests/demos/saints.webp +0 -0
  84. package/tests/scores/electric.js +6 -4
  85. package/tests/scores/electric.webp +0 -0
  86. package/tests/scores/falseta.webp +0 -0
  87. package/tests/scores/kesh.js +1 -2
  88. package/tests/scores/kesh.webp +0 -0
  89. package/tests/scores/saints.js +11 -8
  90. package/tests/scores/saints.webp +0 -0
  91. package/tests/scores/sumer.js +8 -3
  92. package/tests/scores/sumer.webp +0 -0
@@ -139,6 +139,14 @@ function textFontDefaults(assert) {
139
139
  const previous = MetricsDefaults.Annotation.fontFamily;
140
140
  try {
141
141
  VexFlow.setFonts('Bravura', 'Academico');
142
+ const note = new VexFlow.TabNote({ positions: [{ str: 1, fret: 5 }], duration: 'q' });
143
+ const ends = { firstNote: note, lastNote: note };
144
+ assert.equal(new VexFlow.ChordSymbol().fontSizeInPoints, 14);
145
+ assert.equal(Metrics.getFontInfo('Annotation.lyric').size, 12);
146
+ assert.equal(new VexFlow.TabTie(ends, 'H').fontInfo.family.split(',')[0], 'Arial');
147
+ assert.equal(new VexFlow.StaveTie(ends, 'H').fontInfo.family.split(',')[0], 'Academico');
148
+ assert.equal(new VexFlow.TabTie(ends, 'hold').fontInfo.family.split(',')[0], 'Academico');
149
+ assert.equal(new Bend([{ type: Bend.UP, text: 'full' }]).fontInfo.family.split(',')[0], 'Academico');
142
150
  const annotation = new VexFlow.Annotation('Sing with gentle voices');
143
151
  const ctx = document.createElement('canvas').getContext('2d');
144
152
  ctx.font = Font.toCSSString(annotation.fontInfo);
@@ -5,6 +5,7 @@ import { Formatter } from '../src/formatter.js';
5
5
  import { GraceNoteGroup } from '../src/gracenotegroup.js';
6
6
  import { GraceTabNote } from '../src/gracetabnote.js';
7
7
  import { Metrics, MetricsDefaults } from '../src/metrics.js';
8
+ import { ModifierPosition } from '../src/modifier.js';
8
9
  import { TabNote } from '../src/tabnote.js';
9
10
  import { TabStave } from '../src/tabstave.js';
10
11
  import { Voice } from '../src/voice.js';
@@ -13,6 +14,7 @@ const GraceTabNoteTests = {
13
14
  QUnit.module('Grace Tab Notes');
14
15
  QUnit.test('fretSizing', fretSizing);
15
16
  const run = VexFlowTests.runTests;
17
+ run('Grace frets beside a two-digit host', graceClearance, undefined, ['Bravura']);
16
18
  run('Grace Tab Note Simple', simple);
17
19
  run('Grace Tab Note Slurred', slurred);
18
20
  },
@@ -24,6 +26,19 @@ function setupContext(opts, ctxBuilder) {
24
26
  const stave = new TabStave(10, 10, 350).addTabGlyph().setContext(context).drawWithStyle();
25
27
  return { context, stave };
26
28
  }
29
+ function graceClearance(options, contextBuilder) {
30
+ const { context, stave } = setupContext(options, contextBuilder);
31
+ const positions = [{ str: 2, fret: 12 }];
32
+ const host = new TabNote({ positions, duration: 'w' });
33
+ const before = new GraceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '8' });
34
+ const after = new GraceTabNote({ positions, duration: '8' });
35
+ host.addModifier(new GraceNoteGroup([before]));
36
+ host.addModifier(new GraceNoteGroup([after]).setPosition(ModifierPosition.RIGHT));
37
+ Formatter.FormatAndDraw(context, stave, [host]);
38
+ const hostHalfWidth = TabNote.tabToElement('12').getWidth() / 2;
39
+ options.assert.ok(before.getAbsoluteX() + before.getWidth() / 2 + 2 <= host.getAbsoluteX() - hostHalfWidth);
40
+ options.assert.ok(after.getAbsoluteX() - after.getWidth() / 2 - 2 >= host.getAbsoluteX() + hostHalfWidth);
41
+ }
27
42
  function simple(options, contextBuilder) {
28
43
  const { context, stave } = setupContext(options, contextBuilder);
29
44
  const note0 = tabNote({ positions: [{ str: 4, fret: 6 }], duration: '4' });
@@ -104,13 +119,14 @@ function fretSizing(assert) {
104
119
  }
105
120
  }
106
121
  note.setFontSize(7).setGhost(true);
107
- assert.equal(Font.convertSizeToPointValue(note.getFrets()[0].fontInfo.size), 7);
122
+ assert.equal(note.getFrets()[0].fontSizeInPoints, 7);
108
123
  note.setGhost(false).setFontSize();
109
- assert.equal(Font.convertSizeToPointValue(note.getFrets()[0].fontInfo.size), 6);
124
+ const normalSize = Font.convertSizeToPointValue(Metrics.getFontInfo('TabNote.text').size);
125
+ assert.ok(Math.abs(note.getFrets()[0].fontSizeInPoints - normalSize * scale) < 0.001);
110
126
  MetricsDefaults.GraceTabNote.fontScale = 1 / 3;
111
127
  Metrics.clear('GraceTabNote');
112
128
  const small = new InspectableGraceTabNote({ positions: [{ str: 2, fret: 12 }], duration: '8' });
113
- assert.equal(Font.convertSizeToPointValue(small.getFrets()[0].fontInfo.size), 3);
129
+ assert.ok(Math.abs(small.getFrets()[0].fontSizeInPoints - normalSize / 3) < 0.001);
114
130
  }
115
131
  finally {
116
132
  MetricsDefaults.GraceTabNote.fontScale = scale;
@@ -17,7 +17,7 @@ const sup = { symbolModifier: ChordSymbol.symbolModifiers.SUPERSCRIPT };
17
17
  const sub = { symbolModifier: ChordSymbol.symbolModifiers.SUBSCRIPT };
18
18
  const state = () => ({ leftShift: 0, rightShift: 0, topTextLine: 0, textLine: 0 });
19
19
  const close = (a, b, tolerance = 0.04) => assert.ok(Math.abs(a - b) < tolerance, `${a} ≈ ${b}`);
20
- function chord(mode = 'auto', family = 'Academico,Bravura', size = 12) {
20
+ function chord(mode = 'auto', family = 'Academico,Bravura', size = VF.Metrics.getFontInfo('ChordSymbol').size) {
21
21
  const symbol = new ChordSymbol().setFont(family, size).setKerning(mode);
22
22
  new StaveNote({ keys: ['c/5'], duration: 'q' }).addModifier(symbol, 0);
23
23
  return symbol;
@@ -123,7 +123,7 @@ test('custom profiles are isolated and shift the following advance as well as in
123
123
  musicFont: 'Bravura',
124
124
  pairs: [{ left: 'A', right: Glyphs.csymDiminished, position: 'superscript', adjustmentEm: 0 }],
125
125
  };
126
- const make = () => diminished(chord()).addText('7');
126
+ const make = () => diminished(chord('auto', 'Academico,Bravura', 12)).addText('7');
127
127
  const base = format(make().setKerningProfile(profile));
128
128
  profile.pairs[0].adjustmentEm = -0.1;
129
129
  const adjusted = format(make().setKerningProfile(profile));
@@ -12,7 +12,7 @@ import test from 'node:test';
12
12
  import { readFile } from 'node:fs/promises';
13
13
  import puppeteer from 'puppeteer';
14
14
  import { createCanvas, registerFont } from 'canvas';
15
- import { makeContinuousStudy } from '../engraving/continuous-studies.mjs';
15
+ import { makeContinuousStudy, tabEndingStudy } from '../engraving/continuous-studies.mjs';
16
16
  const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
17
17
  for (const family of ['Bravura', 'Academico']) {
18
18
  const name = family.toLowerCase();
@@ -98,6 +98,24 @@ function spec(count, continuous, notes = (i) => [{ id: 'n' + i, note: { keys: ['
98
98
  continuous,
99
99
  };
100
100
  }
101
+ test('a lyric extender resolves a unique word on its source note during formatting', () => {
102
+ const span = { id: 'hold', kind: 'lyric', from: 'n0', to: 'n1', syllableId: 'word' };
103
+ const compose = (config) => factory()
104
+ .f.EasyScore()
105
+ .compose(spec(2, { spans: [config] }));
106
+ for (const invalid of [{ text: 'duplicate' }, { kind: 'tie' }, { syllableId: '' }]) {
107
+ assert.throws(() => compose(Object.assign(Object.assign({}, span), invalid)), /anchored lyric extender/);
108
+ }
109
+ const c = compose(span);
110
+ const format = () => c.sheet.setWidth(600).format();
111
+ assert.throws(format, /Expected one lyric annotation/);
112
+ const source = c.getNote('n0');
113
+ const word = () => new VF.Annotation('word').setAttribute('id', 'word');
114
+ source.addModifier(word());
115
+ format();
116
+ source.addModifier(word());
117
+ assert.throws(format, /Expected one lyric annotation/);
118
+ });
101
119
  test('hard keeps overflow together and forced breaks win over spare space', () => {
102
120
  const { f } = factory();
103
121
  const c = f.EasyScore().compose(spec(4, {
@@ -152,6 +170,48 @@ test('span families retain the source anchors and continuous parameter at first,
152
170
  assert.equal(fs[i - 1].progress[1], fs[i].progress[0]);
153
171
  }
154
172
  });
173
+ test('tab ties stay on the selected string through reflow and leave a visible incoming curve', () => {
174
+ for (const selectors of [{ string: 2 }, { fromHead: 1 }, { toHead: 0 }, { fromHead: 1, toHead: 0 }, {}]) {
175
+ const source = tabEndingStudy();
176
+ const tie = source.continuous.spans[0];
177
+ delete tie.fromHead;
178
+ Object.assign(tie, selectors);
179
+ const string = Object.keys(selectors).length ? 2 : 1;
180
+ const { f } = factory();
181
+ const score = f.EasyScore().compose(source);
182
+ const layout = score.sheet.getContinuousLayout();
183
+ function frame(width) {
184
+ score.sheet.setWidth(width);
185
+ f.draw({ retain: true });
186
+ assert.deepEqual(layout.diagnostics, []);
187
+ return structuredClone(layout.fragments);
188
+ }
189
+ const wide = frame(420);
190
+ assert.deepEqual(wide.map((f) => f.part), ['single', 'single']);
191
+ const narrow = frame(122);
192
+ for (const kind of ['tie', 'volta'])
193
+ assert.deepEqual(narrow.filter((f) => f.kind === kind).map((f) => f.part), ['first', 'last']);
194
+ for (const f of narrow.filter((f) => f.kind === 'tie')) {
195
+ const stave = score.staves[f.row][0];
196
+ assert.deepEqual(f.strings, [string]);
197
+ assert.ok(f.x2 - f.x1 >= stave.space(1), 'visible tie on each side of the break');
198
+ const line = stave.getYForLine(string - 1);
199
+ assert.ok(f.y1 < line && f.y1 > line - stave.space(0.5));
200
+ assert.equal(f.y1, f.y2);
201
+ }
202
+ assert.deepEqual(frame(420), wide);
203
+ }
204
+ });
205
+ test('tab ties reject unmatched strings, frets and invalid chord positions before drawing', () => {
206
+ for (const selectors of [{ string: 7 }, { string: 3 }, { fromHead: -1 }, { toHead: 2 }, { fromHead: 1, toHead: 1 }]) {
207
+ const source = tabEndingStudy();
208
+ Object.assign(source.continuous.spans[0], selectors);
209
+ assert.throws(() => factory().f.EasyScore().compose(source), /tab tie/i);
210
+ }
211
+ const source = tabEndingStudy();
212
+ source.staves[0].measures[1].voices[0].notes[0].tab.positions[0] = { str: 2, fret: 11 };
213
+ assert.throws(() => factory().f.EasyScore().compose(source), /same string and fret/);
214
+ });
155
215
  test('boundary key, clef and meter move together; explicit signs survive and returned tied accidentals reflow', () => {
156
216
  const { f } = factory(), es = f.EasyScore();
157
217
  const s = spec(2, { spans: [{ id: 'tie', kind: 'tie', from: 'n0', to: 'n1' }] }, (i) => [
@@ -181,6 +241,25 @@ test('boundary key, clef and meter move together; explicit signs survive and ret
181
241
  b.sheet.setWidth(800).format();
182
242
  assert.deepEqual(signs(VF.StaveModifier.Position.END), [VF.Barline.CATEGORY]);
183
243
  });
244
+ test('an authored rest remains visible on a silent staff and breaks a compressed rest run', () => {
245
+ const measures = Array.from({ length: 3 }, (_, i) => ({
246
+ voices: [{ notes: [{ note: Object.assign({ keys: ['r/4'], duration: 'wr' }, (i === 1 && { restLine: 0 })) }] }],
247
+ }));
248
+ const source = { staves: [{ id: 'rest', measures }], continuous: { compressRests: true, hideEmptyStaves: true } };
249
+ const { f } = factory();
250
+ const score = f.EasyScore().compose(source);
251
+ score.sheet.format();
252
+ assert.deepEqual(score.sheet.getContinuousLayout().rows.flatMap((row) => row.restGroups), []);
253
+ const melody = spec(3, {}).staves[0];
254
+ const duet = factory()
255
+ .f.EasyScore()
256
+ .compose(Object.assign(Object.assign({}, source), { staves: [melody, ...source.staves] }));
257
+ duet.sheet.format();
258
+ assert.ok(duet.sheet
259
+ .getContinuousLayout()
260
+ .rows.find((row) => row.measures.includes(2))
261
+ .visibleStaves.includes('rest'));
262
+ });
184
263
  test('structural marks interrupt rest compression; navigation targets and span heads validate atomically', () => {
185
264
  const { f } = factory(), es = f.EasyScore(), rest = () => [{ note: { keys: ['b/4'], duration: 'wr' } }];
186
265
  const c = es.compose(spec(7, {
@@ -226,7 +305,58 @@ test('instrument changes survive hiding and reflow and the new full name reserve
226
305
  assert.ok(c.staves[1][0].getX() > c.staves[0][0].getX() + 30);
227
306
  assert.ok(c.staves[2][0].getX() < c.staves[1][0].getX());
228
307
  });
229
- test('choir, piano and ensemble reflow in browser SVG and Canvas with two font pairs', () => __awaiter(void 0, void 0, void 0, function* () {
308
+ function renderSaints({ backend, space }) {
309
+ const VF = window.VexFlow;
310
+ VF.setFonts('Petaluma', 'Academico');
311
+ const target = document.createElement(backend === 'svg' ? 'div' : 'canvas');
312
+ target.id = 'saints';
313
+ document.body.replaceChildren(target);
314
+ const score = VF.EasyScore.create({ renderer: { elementId: target.id, width: 1100, height: 1800 } });
315
+ const edition = window.FeaturedScores.saints.create(VF, score, 'Reharmonized');
316
+ edition.spec.staves[0].options = { spacingBetweenLinesPx: space };
317
+ edition.spec.sheet = { width: 1000, x: 16, y: 42, rowGap: 26, measurePadding: 18 };
318
+ const music = score.compose(edition.spec);
319
+ edition.decorate(music);
320
+ const ctx = score.factory.getContext();
321
+ const drawText = ctx.fillText.bind(ctx);
322
+ let painted = [];
323
+ ctx.fillText = (text, x, y) => {
324
+ if (text === 'in')
325
+ painted.push(y);
326
+ return drawText(text, x, y);
327
+ };
328
+ return [1000, 356, 1000].map((width) => {
329
+ music.sheet.setWidth(width).format();
330
+ const { rows, fragments, diagnostics } = music.sheet.getContinuousLayout();
331
+ const words = music.notes.flat(3).flatMap((n) => n.getModifiers().filter((a) => a.phraseManaged));
332
+ const expected = words.filter((a) => a.text === 'in').map((a) => a.computeY().y);
333
+ const baselines = words.map((a) => a.computeY().y - a.checkAttachedNote().checkStave().getYForLine(0));
334
+ const extenders = fragments
335
+ .filter((f) => f.kind === 'lyric')
336
+ .map((f) => {
337
+ const spec = edition.spec.continuous.spans.find((s) => s.id === f.id);
338
+ const word = music
339
+ .getNote(spec.from)
340
+ .getModifiers()
341
+ .find((a) => a.getAttribute('id') === spec.syllableId);
342
+ const ink = word.getTextInk(word.computeX().x, word.computeY().y);
343
+ const staff = music.staves[rows[f.row].measures[0] - 1][0];
344
+ return { part: f.part, y: f.y1 - staff.getYForLine(0), gap: f.x1 - (ink.x + ink.w), length: f.x2 - f.x1 };
345
+ });
346
+ ctx.clear();
347
+ painted = [];
348
+ score.draw({ retain: true });
349
+ return {
350
+ bars: rows.map((r) => r.measures),
351
+ baselines,
352
+ extenders,
353
+ expected,
354
+ painted,
355
+ diagnostics: structuredClone(diagnostics),
356
+ };
357
+ });
358
+ }
359
+ test('Saints, choir, piano and ensemble reflow in browser SVG and Canvas with two font pairs', () => __awaiter(void 0, void 0, void 0, function* () {
230
360
  const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
231
361
  try {
232
362
  const page = yield browser.newPage();
@@ -238,6 +368,31 @@ test('choir, piano and ensemble reflow in browser SVG and Canvas with two font p
238
368
  const data = yield readFile(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.woff2', import.meta.url));
239
369
  yield page.evaluate((family, data) => __awaiter(void 0, void 0, void 0, function* () { return document.fonts.add(yield new FontFace(family, 'url(data:font/woff2;base64,' + data + ')').load()); }), family, data.toString('base64'));
240
370
  }
371
+ yield page.evaluate(() => {
372
+ window.FeaturedScores = {};
373
+ });
374
+ yield page.addScriptTag({ path: new URL('../scores/saints.js', import.meta.url).pathname });
375
+ for (const backend of ['svg', 'canvas']) {
376
+ for (const space of [9, 10]) {
377
+ const frames = yield page.evaluate(renderSaints, { backend, space });
378
+ assert.deepEqual(frames[2], frames[0], 'returning to page width restores all verse geometry');
379
+ assert.ok(frames[1].bars.length > frames[0].bars.length);
380
+ assert.ok(frames[1].extenders.some((f) => f.part === 'last'), 'a held syllable crosses a system break');
381
+ for (const frame of frames) {
382
+ assert.deepEqual(frame.diagnostics, []);
383
+ assert.equal(frame.expected.length, 4);
384
+ assert.deepEqual(frame.painted, frame.expected, 'each syllable is drawn once at its measured baseline');
385
+ for (const y of frame.baselines)
386
+ assert.ok(Math.abs(y - 7.5 * space) < 0.01);
387
+ for (const line of frame.extenders) {
388
+ assert.ok(Math.abs(line.y - 7.5 * space) < 0.01);
389
+ assert.ok(line.length > 0);
390
+ if (line.part === 'first' || line.part === 'single')
391
+ assert.ok(Math.abs(line.gap - 0.35 * space) < 0.01);
392
+ }
393
+ }
394
+ }
395
+ }
241
396
  for (const backend of ['svg', 'canvas'])
242
397
  for (const kind of ['choir', 'keyboard', 'ensemble'])
243
398
  for (const family of ['Bravura', 'Petaluma']) {
@@ -801,6 +801,44 @@ test('composition failures roll back IDs and queues and enforce shared staff sta
801
801
  const result = score.compose({ staves: [{ id: 'a', measures: [{ voices: [{ notes: [native] }] }] }] });
802
802
  assert.equal(result.notes[0][0][0][0], native);
803
803
  });
804
+ test('hidden meter changes stay silent at courtesy breaks and can be revealed in the following bar', () => {
805
+ const score = create().compose({
806
+ staves: [
807
+ {
808
+ id: 'melody',
809
+ time: '2/4',
810
+ measures: [
811
+ { voices: [{ notes: 'C4/h' }] },
812
+ { time: '6/8', showTimeSignature: false, voices: [{ notes: 'D4/q., G4/q.' }] },
813
+ { showTimeSignature: true, voices: [{ notes: 'F4/q., D4/q.' }] },
814
+ ],
815
+ },
816
+ ],
817
+ continuous: { boundaries: [{ measure: 2, breakBefore: 'force' }] },
818
+ });
819
+ score.sheet.format();
820
+ assert.deepEqual(score.staves.map(([s]) => s.getModifiers().filter((m) => m instanceof VF.TimeSignature).length), [1, 0, 1]);
821
+ });
822
+ test('invalid lead-mark anchors restore a caller-owned note and its original modifiers', () => {
823
+ const score = create();
824
+ const note = score.make.note({ keys: ['c/4'], duration: 'w' }).setAttribute('id', 'owned');
825
+ const existing = score.make.annotation({ text: 'dolce' });
826
+ score.attach(note, existing);
827
+ assert.throws(() => score.compose({
828
+ staves: [
829
+ {
830
+ id: 'melody',
831
+ measures: [
832
+ { voices: [{ notes: [note] }], chords: [{ note: 'owned', text: 'C' }] },
833
+ { voices: [{ notes: 'D4/w' }], verses: [[{ note: 'owned', text: 'wrong bar' }]] },
834
+ ],
835
+ },
836
+ ],
837
+ }), /another staff or measure/);
838
+ assert.deepEqual(note.getModifiers(), [existing]);
839
+ assert.equal(note.getStave(), undefined);
840
+ assert.throws(() => note.getVoice(), /No voice/i);
841
+ });
804
842
  test('key-aware composition preserves literal pitches and explicit marks across rational onsets and key changes', () => {
805
843
  const marks = (note) => note
806
844
  .getModifiers()
@@ -108,6 +108,39 @@ test('two live scores independently consume glyph metrics, anchors and beam poli
108
108
  }
109
109
  assert.throws(() => profile('Bravura', { beamThickness: NaN }), RangeError);
110
110
  });
111
+ test('default Bravura slash stems meet the published glyph anchors at normal and grace sizes', () => {
112
+ const reference = profile('Bravura');
113
+ const { f } = factory();
114
+ for (const make of [f.StaveNote.bind(f), f.GraceNote.bind(f)])
115
+ for (const duration of ['q', '8', 'h'])
116
+ for (const direction of [VF.Stem.UP, VF.Stem.DOWN]) {
117
+ const note = make({ keys: ['b/4'], duration, type: 's', stemDirection: direction });
118
+ const stave = f.Stave({ x: 10, y: 60, width: 240 });
119
+ VF.Formatter.FormatAndDraw(f.getContext(), stave, [note]);
120
+ const head = note.noteHeads[0];
121
+ const [x, y] = reference.stemAnchor(head.text, direction === VF.Stem.UP ? 'up' : 'down');
122
+ const space = head.fontSizeInPixels / 4;
123
+ const stem = note.getStem().getSegment();
124
+ assert.equal(stem.x, note.getNoteHeadBeginX() + head.getXShift() + x * space - (direction * VF.Stem.WIDTH) / 2);
125
+ assert.equal(stem.baseY, head.getY() - y * space);
126
+ }
127
+ });
128
+ test('slash anchors follow the note font and respect explicit metadata', () => {
129
+ const { f } = factory();
130
+ const custom = new VF.EngravingProfile({
131
+ musicFont: 'Bravura',
132
+ metadata: { fontName: 'Bravura', glyphsWithAnchors: { noteheadSlashVerticalEnds: { stemUpSE: [1.25, 0.4] } } },
133
+ });
134
+ for (const [options, expectedY] of [
135
+ [{ engraving: custom }, 0.4],
136
+ [{ musicFont: 'Petaluma, Bravura' }, 0],
137
+ ]) {
138
+ const note = f.StaveNote(Object.assign({ keys: ['b/4'], duration: 'q', type: 's', stemDirection: VF.Stem.UP }, options));
139
+ VF.Formatter.FormatAndDraw(f.getContext(), f.Stave({ x: 10, y: 60, width: 240 }), [note]);
140
+ const head = note.noteHeads[0];
141
+ assert.equal(note.getStem().getSegment().baseY, head.getY() - (expectedY * head.fontSizeInPixels) / 4);
142
+ }
143
+ });
111
144
  test('beam clears a head whose attack falls strictly between its stems', () => {
112
145
  const build = (peerKey) => {
113
146
  const { f } = factory();
@@ -30,6 +30,46 @@ test('instrument studies and score construction', (t) => __awaiter(void 0, void
30
30
  return makeStudy(VF, f, kind);
31
31
  };
32
32
  }));
33
+ yield t.test('fret position labels follow score and diagram fonts on SVG and Canvas', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const labels = yield page.evaluate(() => {
35
+ const VF = VexFlow;
36
+ const spec = { firstFret: 7, frets: ['x', 7, 9, 9, 8, 7] };
37
+ const result = [];
38
+ for (const backend of ['svg', 'canvas']) {
39
+ const host = document.createElement('div');
40
+ const canvas = document.createElement('canvas').getContext('2d');
41
+ const ctx = backend === 'svg' ? new VF.SVGContext(host) : new VF.CanvasContext(canvas);
42
+ const fillText = canvas.fillText.bind(canvas);
43
+ canvas.fillText = (text, x, y) => {
44
+ result.push([text, canvas.font]);
45
+ fillText(text, x, y);
46
+ };
47
+ for (const [family, override] of [
48
+ ['Academico', false],
49
+ ['serif', false],
50
+ ['serif', true],
51
+ ]) {
52
+ VF.setTextFonts(family);
53
+ const diagram = new VF.FretDiagram(spec).setContext(ctx);
54
+ if (override)
55
+ diagram.setFont('monospace', 11, 'bold');
56
+ diagram.draw();
57
+ if (backend === 'svg') {
58
+ const label = [...host.querySelectorAll('text')].at(-1);
59
+ result.push([label.textContent, label.getAttribute('font-family')]);
60
+ }
61
+ }
62
+ }
63
+ VF.setFonts('Bravura', 'Academico');
64
+ return result;
65
+ });
66
+ for (let i = 0; i < labels.length; i++) {
67
+ assert.equal(labels[i][0], '7');
68
+ assert.match(labels[i][1], [/Academico/, /serif/, /monospace/][i % 3]);
69
+ }
70
+ assert.equal(labels.length, 6);
71
+ assert.match(labels[5][1], /bold/);
72
+ }));
33
73
  yield t.test('percussion keeps mixed head identities and stems in native notes, compositions and exported parts', () => __awaiter(void 0, void 0, void 0, function* () {
34
74
  const result = yield page.evaluate(() => {
35
75
  const VF = VexFlow, kit = new VF.PercussionMap();
@@ -80,6 +80,54 @@ function renderMatrix({ family, textFamily, backend, metadata }) {
80
80
  .data.some((v, i, data) => i % 4 === 3 && v > 128 && data[i - 1] < 64);
81
81
  return { before, after, rows, sizes, pixels, drawnLabel };
82
82
  }
83
+ function labelGeometry(backend) {
84
+ const VF = window.VexFlow;
85
+ VF.setFonts('Bravura', 'Academico');
86
+ const target = document.createElement(backend === 'SVG' ? 'div' : 'canvas');
87
+ document.body.replaceChildren(target);
88
+ const ctx = new VF.Renderer(target, VF.Renderer.Backends[backend]).resize(400, 200).getContext();
89
+ const stave = new VF.Stave(20, 80, 350).setContext(ctx);
90
+ const note = new VF.StaveNote({ keys: ['c/4'], duration: 'q' }).setStave(stave);
91
+ const label = stave.setSection('Bridge', 0).getModifiers().at(-1);
92
+ const measurements = [];
93
+ let frame, painted;
94
+ const rect = ctx.rect.bind(ctx), fillText = ctx.fillText.bind(ctx);
95
+ ctx.rect = (x, y, w, h) => {
96
+ frame = { x, y, w, h };
97
+ return rect(x, y, w, h);
98
+ };
99
+ ctx.fillText = (text, x, y) => {
100
+ painted = { x, y, width: ctx.measureText(text).width };
101
+ return fillText(text, x, y);
102
+ };
103
+ for (const [dx, dy] of [
104
+ [0, 0],
105
+ [17, -9],
106
+ ]) {
107
+ label.setXShift(dx).setYShift(dy);
108
+ const before = label.getBoundingBox();
109
+ label.draw();
110
+ const m = label.getTextMetrics();
111
+ const gaps = [
112
+ painted.x - m.actualBoundingBoxLeft - frame.x,
113
+ frame.x + frame.w - painted.x - m.actualBoundingBoxRight,
114
+ painted.y - m.actualBoundingBoxAscent - frame.y,
115
+ frame.y + frame.h - painted.y - m.actualBoundingBoxDescent,
116
+ ];
117
+ measurements.push({ x: painted.x, y: painted.y, gaps, frame, before: Object.assign({}, before) });
118
+ }
119
+ const centers = [];
120
+ for (const Tie of [VF.StaveTie, VF.TabTie]) {
121
+ const tie = new Tie({ firstNote: note }, 'H').setContext(ctx);
122
+ for (const size of [8, 32]) {
123
+ ctx.setFont('monospace', size);
124
+ const previous = ctx.getFont();
125
+ tie.renderTieText(30, 140);
126
+ centers.push({ x: painted.x + painted.width / 2, restored: previous === ctx.getFont() });
127
+ }
128
+ }
129
+ return { measurements, centers };
130
+ }
83
131
  test('Bravura, Petaluma and metadata-free Leland render local parts at normal, cue and grace sizes', () => __awaiter(void 0, void 0, void 0, function* () {
84
132
  const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
85
133
  try {
@@ -95,6 +143,16 @@ test('Bravura, Petaluma and metadata-free Leland render local parts at normal, c
95
143
  document.fonts.add(yield face.load());
96
144
  }), family, bytes.toString('base64'));
97
145
  }
146
+ for (const backend of ['SVG', 'CANVAS']) {
147
+ const { measurements: [original, shifted], centers, } = yield page.evaluate(labelGeometry, backend);
148
+ assert.equal(shifted.x - original.x, 17);
149
+ assert.equal(shifted.y - original.y, -9);
150
+ for (const { gaps, frame, before } of [original, shifted]) {
151
+ assert.deepEqual(before, frame);
152
+ assert.ok(gaps[0] > 0 && gaps.every((gap) => Math.abs(gap - gaps[0]) < 0.01), 'equal ink padding on every edge');
153
+ }
154
+ assert.ok(centers.every((c) => c.restored && Math.abs(c.x - 85) < 0.01), 'tie text uses its own drawing font');
155
+ }
98
156
  for (const [family, textFamily] of [
99
157
  ['Bravura', 'Academico'],
100
158
  ['Petaluma', 'Petaluma Script'],
@@ -152,11 +152,13 @@ test('category font/style caches refresh after edits to defaults', () => {
152
152
  MetricsDefaults[key] = { fontSize: 12, fillStyle: '#123456' };
153
153
  Metrics.clear(key);
154
154
  assert.equal(Metrics.getFontInfo(key).size, 12);
155
+ assert.equal(Metrics.getFontInfo(key + '.child').size, 12);
155
156
  assert.equal(Metrics.getStyle(key).fillStyle, '#123456');
156
157
  MetricsDefaults[key].fontSize = 24;
157
158
  MetricsDefaults[key].fillStyle = '#abcdef';
158
159
  Metrics.clear(key);
159
160
  assert.equal(Metrics.getFontInfo(key).size, 24);
161
+ assert.equal(Metrics.getFontInfo(key + '.child').size, 24);
160
162
  assert.equal(Metrics.getStyle(key).fillStyle, '#abcdef');
161
163
  }
162
164
  finally {
@@ -159,6 +159,56 @@ test('nested quadratic and cubic routes preserve tied chord indices, manual cont
159
159
  system.format();
160
160
  assert.ok(layout.diagnostics.some((d) => d.code === 'CrossingSpans' && d.sources.includes(cross.getAttribute('id'))));
161
161
  });
162
+ test('authored whole and half rests retain their supporting line across staves and formatting passes', () => {
163
+ for (const lines of [4, 5]) {
164
+ const f = factory();
165
+ const stave = f.Stave({ options: { numLines: lines } });
166
+ for (const [duration, plain, ledger] of [
167
+ ['hr', VF.VexFlow.Glyphs.restHalf, VF.VexFlow.Glyphs.restHalfLegerLine],
168
+ ['wr', VF.VexFlow.Glyphs.restWhole, VF.VexFlow.Glyphs.restWholeLegerLine],
169
+ ]) {
170
+ const bottom = 6 - lines;
171
+ for (const line of [bottom - 1, bottom, 3, 5, 6]) {
172
+ const rest = f.StaveNote({ keys: ['r/4'], duration, restLine: line });
173
+ const other = f.StaveNote({ keys: ['b/4'], duration: 'w', stemDirection: VF.Stem.DOWN });
174
+ const voices = [rest, other].map((n) => f.Voice().setMode(VF.Voice.Mode.SOFT).addTickable(n));
175
+ for (let pass = 0; pass < 2; pass++) {
176
+ new VF.Formatter().joinVoices(voices).formatToStave(voices, stave, { alignRests: true });
177
+ for (const voice of voices)
178
+ voice.draw(f.getContext(), stave);
179
+ const [head] = rest.noteHeads;
180
+ assert.equal(rest.getKeyLine(0), line);
181
+ assert.equal(head.getY(), stave.getYForNote(line));
182
+ assert.equal(head.getText(), line < bottom || line > 5 ? ledger : plain);
183
+ }
184
+ }
185
+ }
186
+ }
187
+ const rest = new VF.StaveNote({ keys: ['r/4'], duration: 'wr', restLine: 1 });
188
+ rest.setStave(new VF.Stave(0, 0, 100, { numLines: 4 }));
189
+ assert.equal(rest.noteHeads[0].text, VF.VexFlow.Glyphs.restWholeLegerLine);
190
+ rest.setStave(new VF.Stave(0, 0, 100));
191
+ assert.equal(rest.noteHeads[0].text, VF.VexFlow.Glyphs.restWhole);
192
+ });
193
+ test('automatic rests clear a fixed rest and resume alignment after releasing a pin', () => {
194
+ const f = factory();
195
+ const next = f.StaveNote({ keys: ['d/5'], duration: 'q' });
196
+ const fixed = f.StaveNote({ keys: ['r/4'], duration: 'qr', restLine: 3 });
197
+ VF.Formatter.AlignRestsToNotes([fixed, next], true);
198
+ assert.equal(fixed.getKeyLine(0), 3);
199
+ const auto = f.StaveNote({ keys: ['r/4'], duration: 'qr' });
200
+ const stave = f.Stave();
201
+ const voices = [fixed, auto].map((n) => f.Voice().setMode(VF.Voice.Mode.SOFT).addTickable(n));
202
+ new VF.Formatter().joinVoices(voices).formatToStave(voices, stave);
203
+ assert.equal(fixed.getKeyLine(0), 3);
204
+ assert.notEqual(auto.getKeyLine(0), 3);
205
+ assert.notEqual(auto.renderOptions.draw, false);
206
+ fixed.setRestLine(0).setRestLine(undefined);
207
+ VF.Formatter.AlignRestsToNotes([fixed, next], true);
208
+ assert.equal(fixed.getKeyLine(0), next.getLineForRest());
209
+ assert.throws(() => next.setRestLine(1), /rest/i);
210
+ assert.throws(() => auto.setRestLine(NaN), /finite/);
211
+ });
162
212
  test('a rest clears ink anchored at an earlier attack and reports a collision when pinned', () => {
163
213
  function restCase(pin) {
164
214
  const { f, system, staff, layout, notes } = score('G4/q, B4/q/r, G4/q');
@@ -169,19 +219,22 @@ test('a rest clears ink anchored at an earlier attack and reports a collision wh
169
219
  obstruction.setXShift(a.x - b.x).setTextBaseline(obstruction.computeY().y + b.y - a.y);
170
220
  assert.ok(rest.isRest());
171
221
  const original = rest.getKeyLine(0);
172
- if (pin)
222
+ if (pin === 'phrase')
173
223
  layout.pin(rest);
224
+ if (pin === 'rest')
225
+ rest.setRestLine(original);
174
226
  system.format();
175
- assert.equal(intersects(measured(rest).ink, measured(obstruction).ink), pin);
176
- assert.equal(rest.getKeyLine(0) === original, pin);
177
- assert.equal(layout.diagnostics.some((d) => d.code === 'PinnedCollision'), pin);
227
+ assert.equal(intersects(measured(rest).ink, measured(obstruction).ink), Boolean(pin));
228
+ assert.equal(rest.getKeyLine(0) === original, Boolean(pin));
229
+ assert.equal(layout.diagnostics.some((d) => d.code === 'PinnedCollision'), Boolean(pin));
178
230
  const line = rest.getKeyLine(0);
179
231
  system.format();
180
232
  assert.equal(rest.getKeyLine(0), line);
181
233
  assert.equal(host.getStave(), staff);
182
234
  }
183
235
  restCase(false);
184
- restCase(true);
236
+ restCase('phrase');
237
+ restCase('rest');
185
238
  });
186
239
  test('staff separation refits cross-staff beams to the visible stem tips after resizing', () => {
187
240
  const { f, system, staff, layout, notes } = score('G4/8, C5/8, G4/q');