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
@@ -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');
@@ -11,7 +11,8 @@ import assert from 'node:assert/strict';
11
11
  import { readFile } from 'node:fs/promises';
12
12
  import { test } from 'node:test';
13
13
  import puppeteer from 'puppeteer';
14
- import { publicationStudy } from '../engraving/publication-studies.mjs';
14
+ import { tabEndingStudy } from '../engraving/continuous-studies.mjs';
15
+ import { leadSheetStudy, publicationStudy } from '../engraving/publication-studies.mjs';
15
16
  test('publication views, pagination and portable printing', (t) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
17
18
  try {
@@ -104,6 +105,161 @@ test('publication views, pagination and portable printing', (t) => __awaiter(voi
104
105
  }
105
106
  }));
106
107
  }
108
+ yield t.test('structured chords and rhythmic tab retain written dots in independent parts', () => __awaiter(void 0, void 0, void 0, function* () {
109
+ const samples = yield page.evaluate(() => {
110
+ const keys = ['c/4', 'e/4'];
111
+ const positions = [
112
+ { str: 1, fret: 12 },
113
+ { str: 2, fret: 10 },
114
+ ];
115
+ const source = {
116
+ staves: ['stave', 'tab'].map((kind) => ({
117
+ id: kind,
118
+ kind,
119
+ time: '13/16',
120
+ measures: [
121
+ {
122
+ voices: [
123
+ {
124
+ notes: [1, 2].map((dots) => (Object.assign({ id: kind + dots }, (kind === 'tab'
125
+ ? { tab: { duration: 'q', positions, dots }, drawStem: true }
126
+ : { note: { duration: 'q', keys, dots } })))),
127
+ },
128
+ ],
129
+ },
130
+ ],
131
+ })),
132
+ };
133
+ const host = document.querySelector('aside');
134
+ host.replaceChildren();
135
+ host.id = 'dot-score';
136
+ const factory = new VexFlow.Factory({ renderer: { elementId: host.id, width: 500, height: 330 } });
137
+ const screen = factory.EasyScore().compose(source);
138
+ factory.draw();
139
+ const countDots = (group) => [...group.querySelectorAll('text')].filter((el) => el.textContent === VexFlow.Glyphs.augmentationDot).length;
140
+ return source.staves.flatMap(({ id }) => {
141
+ const book = new VexFlow.Publication(source).render(document.querySelector('main'), { staves: [id] });
142
+ const svg = book.pages[0].svg;
143
+ const events = JSON.parse(svg.querySelector('metadata').textContent).events;
144
+ return events.map((event) => ({
145
+ id: event.id,
146
+ ticks: screen.getNote(event.id).getTicks().toString(),
147
+ partTicks: event.ticks,
148
+ screenDots: countDots(host.querySelector('#vf-' + event.id)),
149
+ partDots: countDots(svg.querySelector('[data-vf-id="vf-' + event.id + '"]')),
150
+ }));
151
+ });
152
+ });
153
+ assert.deepEqual(samples, [
154
+ { id: 'stave1', ticks: '6144/1', partTicks: '6144/1', screenDots: 2, partDots: 2 },
155
+ { id: 'stave2', ticks: '7168/1', partTicks: '7168/1', screenDots: 4, partDots: 4 },
156
+ { id: 'tab1', ticks: '6144/1', partTicks: '6144/1', screenDots: 1, partDots: 1 },
157
+ { id: 'tab2', ticks: '7168/1', partTicks: '7168/1', screenDots: 2, partDots: 2 },
158
+ ]);
159
+ }));
160
+ yield t.test('an extracted tab part prints the tied string and the ending across its own system break', () => __awaiter(void 0, void 0, void 0, function* () {
161
+ const source = tabEndingStudy();
162
+ source.staves.unshift({
163
+ id: 'melody',
164
+ time: '1/4',
165
+ measures: [1, 2].map(() => ({ voices: [{ notes: 'C4/q' }] })),
166
+ });
167
+ const result = yield page.evaluate((source) => {
168
+ const book = new VexFlow.Publication(source).render(document.querySelector('main'), {
169
+ staves: ['guitar'],
170
+ systemBreaks: [2],
171
+ });
172
+ const svg = book.pages[0].svg;
173
+ const meta = JSON.parse(svg.querySelector('metadata').textContent);
174
+ return {
175
+ diagnostics: book.diagnostics,
176
+ staves: meta.staves,
177
+ spans: meta.spans,
178
+ systems: [...svg.querySelectorAll('[data-system]')].map((g) => ({
179
+ endings: [...g.querySelectorAll('text')].filter((e) => e.textContent === '1.').length,
180
+ curves: [...g.querySelectorAll('path')].filter((e) => /Q/i.test(e.getAttribute('d'))).length,
181
+ })),
182
+ };
183
+ }, source);
184
+ assert.deepEqual(result.diagnostics, []);
185
+ assert.deepEqual(result.staves, ['guitar']);
186
+ assert.deepEqual(result.systems, [
187
+ { endings: 1, curves: 1 },
188
+ { endings: 0, curves: 1 },
189
+ ]);
190
+ assert.deepEqual(result.spans.filter((s) => s.id === 'hold'), [
191
+ { id: 'hold', kind: 'tie', part: 'first', strings: [2], from: 'tab0' },
192
+ { id: 'hold', kind: 'tie', part: 'last', strings: [2], to: 'tab1' },
193
+ ]);
194
+ assert.deepEqual(result.spans.filter((s) => s.id === 'ending').map((s) => s.part), ['first', 'last']);
195
+ }));
196
+ yield t.test('lead sheet marks stay on their notes through reflow and part extraction', () => __awaiter(void 0, void 0, void 0, function* () {
197
+ yield page.addScriptTag({ content: 'window.leadSheetStudy=' + leadSheetStudy });
198
+ const result = yield page.evaluate(() => {
199
+ const source = leadSheetStudy();
200
+ const host = document.querySelector('aside');
201
+ host.replaceChildren();
202
+ host.id = 'lead-score';
203
+ const factory = new VexFlow.Factory({ renderer: { elementId: host.id, width: 800, height: 1200 } });
204
+ const score = factory.EasyScore().compose(source);
205
+ const read = (svg) => {
206
+ const anchor = (id) => svg.querySelector('#vf-' + id + ', [data-vf-id="vf-' + id + '"]');
207
+ const marks = (id) => Array.from(anchor(id).querySelectorAll('.vf-annotation text'), (t) => t.textContent);
208
+ const bars = [...svg.querySelectorAll('.vf-stavebarline')].map((el) => Array.from(el.querySelectorAll('rect[stroke="none"]'), (r) => Number(r.getAttribute('width'))));
209
+ return {
210
+ opening: marks('a0'),
211
+ second: marks('a3'),
212
+ meterSigns: svg.querySelectorAll('.vf-timesignature').length,
213
+ double: bars.filter((w) => w.join() === '1,1').length,
214
+ final: bars.filter((w) => w.join() === '1,3').length,
215
+ beams: svg.querySelectorAll('.vf-beam').length,
216
+ };
217
+ };
218
+ const samples = [760, 270].map((width) => {
219
+ factory.getContext().clear();
220
+ score.sheet.setWidth(width);
221
+ factory.draw({ retain: true });
222
+ return { rows: score.sheet.getRows().length, drawing: read(host) };
223
+ });
224
+ const beamSizes = [...new Set(score.notes[0][0][0].map((n) => n.getBeam()))].map((b) => b.getNotes().length);
225
+ const book = new VexFlow.Publication(source).render(document.querySelector('main'), {
226
+ staves: ['lead'],
227
+ systemBreaks: [2],
228
+ paper: 'A4',
229
+ });
230
+ return { samples, beamSizes, printed: read(book.pages[0].svg), diagnostics: book.diagnostics };
231
+ });
232
+ const drawing = { opening: ['Cmaj7', 'Day'], second: ['light'], meterSigns: 0, double: 1, final: 1, beams: 4 };
233
+ assert.deepEqual(result.samples, [
234
+ { rows: 1, drawing },
235
+ { rows: 2, drawing },
236
+ ]);
237
+ assert.deepEqual(result.beamSizes, [3, 3]);
238
+ assert.deepEqual(result.printed, drawing);
239
+ assert.deepEqual(result.diagnostics, []);
240
+ }));
241
+ yield t.test('a fingering and its transparent hit area stay with the printed note', () => __awaiter(void 0, void 0, void 0, function* () {
242
+ const printed = yield page.evaluate(() => {
243
+ const measures = Array.from({ length: 6 }, (_, i) => ({
244
+ voices: [{ notes: i === 5 ? 'C5/w[id="fingered",fingerings="4.left"]' : 'G4/w' }],
245
+ }));
246
+ const music = { staves: [{ id: 'keyboard', measures }] };
247
+ const book = new VexFlow.Publication(music).render(document.querySelector('main'), {
248
+ systemBreaks: [2, 3, 4, 5, 6],
249
+ });
250
+ const note = book.pages.map((p) => p.svg.querySelector('[data-vf-id="vf-fingered"]')).find(Boolean);
251
+ const digit = Array.from(note.querySelectorAll('text'))
252
+ .find((el) => el.textContent === '4')
253
+ .getBoundingClientRect();
254
+ const head = note.querySelector('.vf-notehead text').getBoundingClientRect();
255
+ return {
256
+ system: note.closest('[data-system]').getAttribute('data-system'),
257
+ clear: digit.right < head.left,
258
+ aligned: digit.top < head.bottom && head.top < digit.bottom,
259
+ };
260
+ });
261
+ assert.deepEqual(printed, { system: '6', clear: true, aligned: true });
262
+ }));
107
263
  yield t.test('pagination reserves running text at the final page scale', () => __awaiter(void 0, void 0, void 0, function* () {
108
264
  const result = yield page.evaluate(() => {
109
265
  const style = document.createElement('style');
@@ -198,7 +354,7 @@ test('publication views, pagination and portable printing', (t) => __awaiter(voi
198
354
  }
199
355
  }));
200
356
  test('equally feasible pages prefer a performing rest and respect a forbidden turn and last-page spacing', () => __awaiter(void 0, void 0, void 0, function* () {
201
- const { paginate } = yield import('../../build/esm/src/pagebreaks.js');
357
+ const { paginate } = yield import(new URL('../../build/esm/src/pagebreaks.js', import.meta.url).href);
202
358
  const rows = Array.from({ length: 5 }, (_, i) => ({ measures: [i + 1], height: 10, restAtEnd: i === 1 }));
203
359
  const rules = {
204
360
  firstHeight: 34,
@@ -99,36 +99,65 @@ test('portable SVG paths retain score geometry and render with fonts and styles
99
99
  missingError: true,
100
100
  italicError: true,
101
101
  });
102
- for (const [name, music, text] of [
103
- ['bravura', 'Bravura', 'Academico'],
104
- ['petaluma', 'Petaluma', 'Petaluma Script'],
102
+ for (const [music, text] of [
103
+ ['Bravura', 'Academico'],
104
+ ['Petaluma', 'Academico'],
105
+ ['Petaluma', 'Petaluma Script'],
105
106
  ]) {
106
107
  const drawings = yield page.evaluate(({ music, text }) => {
107
108
  document.querySelector('#score').replaceChildren();
108
109
  VexFlow.setFonts(music, text);
109
- const renderer = new VexFlow.Renderer(document.querySelector('#score'), VexFlow.Renderer.Backends.SVG);
110
- renderer.resize(620, 240);
111
- const context = renderer.getContext();
112
- const stave = new VexFlow.Stave(15, 35, 580).addClef('treble').addKeySignature('D').addTimeSignature('4/4');
113
- stave.setContext(context).draw();
114
- const notes = [
115
- new VexFlow.StaveNote({ keys: ['c/5', 'e/5', 'g/5'], duration: 'q' }).addModifier(new VexFlow.Accidental('#'), 0),
116
- new VexFlow.StaveNote({ keys: ['b/4'], duration: 'q' }),
117
- new VexFlow.StaveNote({ keys: ['a/4'], duration: 'q' }),
118
- new VexFlow.StaveNote({ keys: ['b/4'], duration: 'qr' }),
119
- ];
120
- VexFlow.Formatter.FormatAndDraw(context, stave, notes);
110
+ const factory = new VexFlow.Factory({ renderer: { elementId: 'score', width: 620, height: 240 } });
111
+ const context = factory.getContext();
112
+ const score = factory.EasyScore();
113
+ const notes = score.notes('(C#5 E5 G5)/q, B4, A4, B4/q/r');
114
+ const system = factory.System({ x: 15, y: 60, width: 580 });
115
+ const stave = system
116
+ .addStave({ voices: [score.voice(notes)] })
117
+ .addClef('treble')
118
+ .addKeySignature('D')
119
+ .addTimeSignature('4/4');
120
+ notes[1].addModifier(factory.ChordSymbol().addText('G').addGlyphOrText('b9', {
121
+ symbolModifier: VexFlow.ChordSymbol.symbolModifiers.SUPERSCRIPT,
122
+ }));
123
+ system.getPhraseLayout().addVerse(stave, [
124
+ { note: notes[0], text: 'Chanté' },
125
+ { note: notes[1], text: 'dolce' },
126
+ ]);
127
+ factory.draw();
121
128
  context.setFont(`${text},Academico`, '14pt').fillText('Andante — AV', 20, 28);
122
- context.setFont(`${text},Academico`, '12pt').fillText('Sing clearly', 200, 195);
123
129
  const before = context.toSVG();
124
130
  const after = context.toSVG(window.outlineFonts);
125
- const originalBounds = Array.from(context.svg.querySelectorAll('text')).map((node) => {
126
- const { x, y, width, height } = node.getBBox();
127
- return { x, y, width, height };
128
- });
129
131
  const clone = new DOMParser().parseFromString(after, 'image/svg+xml').documentElement;
130
- return { before, after, glyphs: originalBounds.length, paths: clone.querySelectorAll('path').length };
132
+ const regularFace = (family) => window.outlineFonts.find((face) => face.family === family && !face.weight).font;
133
+ const letters = regularFace(text);
134
+ const symbols = regularFace(music);
135
+ const verifyRole = (selector, expected) => {
136
+ const live = context.svg.querySelectorAll(selector + ' text');
137
+ const paths = clone.querySelectorAll(selector + ' path');
138
+ return (live.length === expected.length &&
139
+ paths.length === expected.length &&
140
+ expected.every((outline, i) => paths[i].getAttribute('d') ===
141
+ outline(Number(live[i].getAttribute('x')), Number(live[i].getAttribute('y')))));
142
+ };
143
+ const outline = (word, pt) => (x, y) => letters.getPath(word, x, y, VexFlow.Font.convertSizeToPixelValue(pt)).toPathData(5);
144
+ const raisedNinth = (x, y) => {
145
+ const flat = VexFlow.Glyphs.csymAccidentalFlat;
146
+ const size = VexFlow.Font.convertSizeToPixelValue(8.4);
147
+ return (symbols.getPath(flat, x, y, size).toPathData(5) +
148
+ outline('9', 8.4)(x + symbols.getAdvanceWidth(flat, size), y));
149
+ };
150
+ return {
151
+ before,
152
+ after,
153
+ glyphs: context.svg.querySelectorAll('text').length,
154
+ paths: clone.querySelectorAll('path').length,
155
+ chords: verifyRole('.vf-chordsymbol', [outline('G', 14), raisedNinth]),
156
+ lyrics: verifyRole('.vf-annotation', [outline('Chanté', 12), outline('dolce', 12)]),
157
+ };
131
158
  }, { music, text });
159
+ assert.ok(drawings.chords, `chord outlines in ${music} and ${text}`);
160
+ assert.ok(drawings.lyrics, `verse outlines in ${text}`);
132
161
  assert.ok(drawings.glyphs > 10);
133
162
  assert.ok(drawings.paths >= drawings.glyphs);
134
163
  assert.doesNotMatch(drawings.after, /<text\b|@font-face|<use\b/);