vexflow 5.1.2 → 5.3.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 (162) hide show
  1. package/README.md +7 -6
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +5325 -1730
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +4228 -1545
  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 +13 -3
  13. package/build/esm/src/articulation.js +51 -20
  14. package/build/esm/src/beam.js +170 -30
  15. package/build/esm/src/bend.js +24 -19
  16. package/build/esm/src/clef.js +3 -0
  17. package/build/esm/src/clefnote.js +5 -1
  18. package/build/esm/src/curve.js +27 -53
  19. package/build/esm/src/dot.js +14 -5
  20. package/build/esm/src/easyscore/composition.js +336 -0
  21. package/build/esm/src/easyscore/elementindex.js +81 -0
  22. package/build/esm/src/easyscore/elements.js +324 -0
  23. package/build/esm/src/easyscore/policies.js +97 -0
  24. package/build/esm/src/easyscore/rhythm.js +42 -0
  25. package/build/esm/src/easyscore.js +448 -26
  26. package/build/esm/src/element.js +17 -2
  27. package/build/esm/src/engravinggeometry.js +150 -0
  28. package/build/esm/src/engravingprofile.js +44 -0
  29. package/build/esm/src/factory.js +268 -64
  30. package/build/esm/src/formatter.js +40 -4
  31. package/build/esm/src/gracenote.js +43 -38
  32. package/build/esm/src/gracenotegroup.js +53 -56
  33. package/build/esm/src/index.js +2 -0
  34. package/build/esm/src/keysignature.js +10 -2
  35. package/build/esm/src/keysignote.js +2 -2
  36. package/build/esm/src/modifiercontext.js +11 -0
  37. package/build/esm/src/note.js +5 -0
  38. package/build/esm/src/notehead.js +11 -6
  39. package/build/esm/src/ornament.js +38 -18
  40. package/build/esm/src/parenthesis.js +1 -1
  41. package/build/esm/src/parser.js +6 -1
  42. package/build/esm/src/proportionalformatter.js +234 -0
  43. package/build/esm/src/registry.js +27 -0
  44. package/build/esm/src/sheet.js +20 -3
  45. package/build/esm/src/stave.js +9 -2
  46. package/build/esm/src/stavenote.js +140 -127
  47. package/build/esm/src/stavetie.js +39 -7
  48. package/build/esm/src/stem.js +26 -11
  49. package/build/esm/src/stemmablenote.js +6 -1
  50. package/build/esm/src/tickable.js +5 -0
  51. package/build/esm/src/tickcontext.js +19 -0
  52. package/build/esm/src/timesignature.js +5 -0
  53. package/build/esm/src/tuplet.js +60 -19
  54. package/build/esm/src/version.js +3 -3
  55. package/build/esm/src/vexflow.js +6 -1
  56. package/build/esm/tests/beam_tests.js +35 -0
  57. package/build/esm/tests/bend_tests.js +14 -1
  58. package/build/esm/tests/curve_tests.js +14 -4
  59. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  60. package/build/esm/tests/demos/drums.js +54 -0
  61. package/build/esm/tests/demos/electric.js +63 -0
  62. package/build/esm/tests/demos/greensleeves.js +90 -0
  63. package/build/esm/tests/demos/joy.js +61 -0
  64. package/build/esm/tests/demos/kesh.js +80 -0
  65. package/build/esm/tests/demos/prelude.js +59 -0
  66. package/build/esm/tests/demos/quartertones.js +50 -0
  67. package/build/esm/tests/demos/saints.js +65 -0
  68. package/build/esm/tests/easyscore_tests.js +40 -0
  69. package/build/esm/tests/easyscore_types.js +65 -0
  70. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  71. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  72. package/build/esm/tests/engraving/studies.mjs +279 -0
  73. package/build/esm/tests/formatter_tests.js +51 -1
  74. package/build/esm/tests/index.js +1 -0
  75. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  76. package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
  77. package/build/esm/tests/node/easyscore-tests.mjs +1024 -0
  78. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  79. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  80. package/build/esm/tests/node/proportional-spacing-tests.mjs +278 -0
  81. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  82. package/build/esm/tests/threevoice_tests.js +11 -1
  83. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  84. package/build/esm/tools/audit-dependencies.mjs +61 -0
  85. package/build/esm/tools/easyscore-api-audit.mjs +58 -0
  86. package/build/esm/tools/easyscore-composition.mjs +62 -0
  87. package/build/esm/tools/easyscore-example.mjs +16 -0
  88. package/build/esm/tools/easyscore-families.mjs +61 -0
  89. package/build/esm/tools/easyscore-references-example.mjs +26 -0
  90. package/build/esm/tools/easyscore-rhythm.mjs +58 -0
  91. package/build/esm/tools/easyscore-structure.mjs +88 -0
  92. package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
  93. package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
  94. package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
  95. package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
  96. package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
  97. package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
  98. package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
  99. package/build/esm/tools/explorer/catalog.mjs +14 -0
  100. package/build/esm/tools/score-fixtures.mjs +23 -6
  101. package/build/types/src/accidental.d.ts +6 -0
  102. package/build/types/src/articulation.d.ts +12 -1
  103. package/build/types/src/beam.d.ts +16 -0
  104. package/build/types/src/clef.d.ts +2 -0
  105. package/build/types/src/curve.d.ts +9 -0
  106. package/build/types/src/dot.d.ts +5 -0
  107. package/build/types/src/easyscore/composition.d.ts +126 -0
  108. package/build/types/src/easyscore/elementindex.d.ts +30 -0
  109. package/build/types/src/easyscore/elements.d.ts +156 -0
  110. package/build/types/src/easyscore/policies.d.ts +12 -0
  111. package/build/types/src/easyscore/rhythm.d.ts +9 -0
  112. package/build/types/src/easyscore.d.ts +153 -11
  113. package/build/types/src/element.d.ts +7 -1
  114. package/build/types/src/engravinggeometry.d.ts +31 -0
  115. package/build/types/src/engravingprofile.d.ts +20 -0
  116. package/build/types/src/factory.d.ts +97 -9
  117. package/build/types/src/formatter.d.ts +7 -1
  118. package/build/types/src/gracenote.d.ts +7 -0
  119. package/build/types/src/gracenotegroup.d.ts +7 -2
  120. package/build/types/src/index.d.ts +2 -0
  121. package/build/types/src/keysignature.d.ts +3 -0
  122. package/build/types/src/keysignote.d.ts +1 -1
  123. package/build/types/src/modifiercontext.d.ts +4 -0
  124. package/build/types/src/note.d.ts +2 -0
  125. package/build/types/src/notehead.d.ts +5 -0
  126. package/build/types/src/ornament.d.ts +7 -0
  127. package/build/types/src/parser.d.ts +5 -0
  128. package/build/types/src/proportionalformatter.d.ts +39 -0
  129. package/build/types/src/registry.d.ts +4 -0
  130. package/build/types/src/stave.d.ts +2 -0
  131. package/build/types/src/stavenote.d.ts +21 -3
  132. package/build/types/src/stavetie.d.ts +4 -0
  133. package/build/types/src/stem.d.ts +10 -1
  134. package/build/types/src/stemmablenote.d.ts +6 -1
  135. package/build/types/src/tickable.d.ts +2 -0
  136. package/build/types/src/tickcontext.d.ts +5 -0
  137. package/build/types/src/timesignature.d.ts +2 -0
  138. package/build/types/src/tuplet.d.ts +5 -48
  139. package/build/types/src/vexflow.d.ts +6 -1
  140. package/changelog/CHANGELOG.md +52 -0
  141. package/package.json +13 -3
  142. package/tests/all.html +277 -0
  143. package/tests/demo_petzold_tests.ts +435 -0
  144. package/tests/demos/drums.ts +55 -0
  145. package/tests/demos/drums.webp +0 -0
  146. package/tests/demos/electric.ts +70 -0
  147. package/tests/demos/electric.webp +0 -0
  148. package/tests/demos/greensleeves.ts +97 -0
  149. package/tests/demos/greensleeves.webp +0 -0
  150. package/tests/demos/joy.ts +65 -0
  151. package/tests/demos/joy.webp +0 -0
  152. package/tests/demos/kesh.ts +86 -0
  153. package/tests/demos/kesh.webp +0 -0
  154. package/tests/demos/prelude.ts +65 -0
  155. package/tests/demos/prelude.webp +0 -0
  156. package/tests/demos/quartertones.ts +51 -0
  157. package/tests/demos/quartertones.webp +0 -0
  158. package/tests/demos/saints.ts +70 -0
  159. package/tests/demos/saints.webp +0 -0
  160. package/tests/flow.html +550 -239
  161. package/tests/fonts.css +493 -0
  162. package/tests/minuet.webp +0 -0
@@ -0,0 +1,278 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { createCanvas, registerFont } from 'canvas';
4
+ import { JSDOM } from 'jsdom';
5
+ const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
6
+ for (const [family, file] of [
7
+ ['Bravura', 'bravura/bravura'],
8
+ ['Academico', 'academico/academico'],
9
+ ]) {
10
+ registerFont(new URL(`../../node_modules/@vexflow-fonts/${file}.otf`, import.meta.url).pathname, { family });
11
+ }
12
+ VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
13
+ const documentFixture = new JSDOM('<div></div>');
14
+ globalThis.document = documentFixture.window.document;
15
+ test.after(() => {
16
+ delete globalThis.document;
17
+ documentFixture.window.close();
18
+ });
19
+ const { Formatter, Voice, Stave, StaveNote, Tuplet, ClefNote, Accidental, Dot, GraceNote, GraceNoteGroup } = VF;
20
+ const rhythm = ['16', '16', '16', '16', '8', '8', 'q', 'q'];
21
+ const close = (actual, expected) => assert.ok(Math.abs(actual - expected) < 1e-7, `${actual} ≈ ${expected}`);
22
+ function voice(durations = rhythm, meter = '4/4', stave = new Stave(10, 50, 900)) {
23
+ const notes = durations.map((duration) => new StaveNote({ keys: ['c/5'], duration }).setStave(stave));
24
+ VF.Beam.generateBeams(notes);
25
+ return new Voice(meter).setMode(Voice.Mode.SOFT).addTickables(notes).setMode(Voice.Mode.STRICT);
26
+ }
27
+ const proportional = (pixelsPerQuarter) => new Formatter({ spacing: { mode: 'proportional', pixelsPerQuarter } });
28
+ const positions = (voice) => voice
29
+ .getTickables()
30
+ .filter((n) => !n.shouldIgnoreTicks())
31
+ .map((n) => n.getTickContext().getX());
32
+ function onsets(v, expected) {
33
+ const x = positions(v);
34
+ expected.forEach((offset, i) => close(x[i] - x[0], offset));
35
+ }
36
+ test('mixed durations retain exact scale, final duration, trailing space, and tuning invariance', () => {
37
+ const v = voice();
38
+ const f = proportional(100).joinVoices([v]).format([v], 800);
39
+ onsets(v, [0, 25, 50, 75, 100, 150, 200, 300]);
40
+ close(f.getMinTotalWidth(), 404);
41
+ const before = positions(v);
42
+ for (let i = 0; i < 10; i++)
43
+ f.tune();
44
+ assert.deepEqual(positions(v), before);
45
+ f.format([v], 500);
46
+ assert.deepEqual(positions(v), before);
47
+ });
48
+ test('omitted scale fits the full measure; omitted width uses measured minimum', () => {
49
+ const v = voice();
50
+ const f = proportional().joinVoices([v]).format([v], 504);
51
+ onsets(v, [0, 31.25, 62.5, 93.75, 125, 187.5, 250, 375]);
52
+ const minimum = f.preCalculateMinTotalWidth([v]);
53
+ f.format([v], minimum);
54
+ const expected = positions(v);
55
+ f.format([v]);
56
+ assert.deepEqual(positions(v), expected);
57
+ });
58
+ test('7/8 and dotted rhythms retain duration ratios', () => {
59
+ const v = voice(Array(7).fill('8'), '7/8');
60
+ proportional(100).joinVoices([v]).format([v]);
61
+ onsets(v, [0, 50, 100, 150, 200, 250, 300]);
62
+ const dotted = voice(['qd', '8', 'h']);
63
+ Dot.buildAndAttach([dotted.getTickables()[0]]);
64
+ proportional(100).joinVoices([dotted]).format([dotted]);
65
+ onsets(dotted, [0, 150, 200]);
66
+ });
67
+ test('shared onsets align in multiple voices on the same stave', () => {
68
+ const stave = new Stave(10, 50, 900);
69
+ const upper = voice(rhythm, '4/4', stave);
70
+ const lower = voice(['q', 'q', 'q', 'q'], '4/4', stave);
71
+ lower.getTickables().forEach((note) => note.setStemDirection(-1));
72
+ const f = proportional(140).joinVoices([upper, lower]).format([upper, lower]);
73
+ [0, 4, 6, 7].forEach((index, beat) => close(positions(upper)[index], positions(lower)[beat]));
74
+ assert.ok(f.getMinTotalWidth() >= 560);
75
+ });
76
+ test('triplets and septuplets on separate staves share rational endpoints without false collisions', () => {
77
+ const first = voice([...Array(3).fill('8'), 'q', 'h']);
78
+ const second = voice([...Array(7).fill('8'), 'h']);
79
+ new Tuplet(first.getTickables().slice(0, 3), { numNotes: 3, notesOccupied: 2 });
80
+ new Tuplet(second.getTickables().slice(0, 7), { numNotes: 7, notesOccupied: 4 });
81
+ const f = proportional(140).joinVoices([first, second]).format([first, second]);
82
+ onsets(first, [0, 140 / 3, 280 / 3, 140, 280]);
83
+ onsets(second, [...Array.from({ length: 7 }, (_, i) => (i * 280) / 7), 280]);
84
+ close(positions(first)[4], positions(second)[7]);
85
+ assert.equal(f.getTickContexts().resolutionMultiplier % 21, 0);
86
+ });
87
+ test('inline clefs and trailing barlines occupy space without consuming time', () => {
88
+ const stave = new Stave(10, 50, 900);
89
+ const notes = voice(['q', 'q', 'q', 'q'], '4/4', stave).getTickables();
90
+ const clefs = [new ClefNote('bass', 'small'), new ClefNote('treble', 'small')].map((c) => c.setStave(stave));
91
+ const end = new VF.BarNote().setStave(stave);
92
+ const v = new Voice('4/4').addTickables([notes[0], ...clefs, ...notes.slice(1), end]);
93
+ const f = proportional(130).joinVoices([v]).format([v]);
94
+ onsets(v, [0, 130, 260, 390]);
95
+ assert.ok(clefs[0].getAbsoluteX() < clefs[1].getAbsoluteX());
96
+ assert.ok(clefs[1].getAbsoluteX() + clefs[1].getWidth() <= notes[1].getAbsoluteX());
97
+ close(end.getTickContext().getX() - positions(v)[0], 520 - 1 - end.getTickContext().getMetrics().notePx);
98
+ const before = v.getTickables().map((n) => n.getAbsoluteX());
99
+ f.format([v]);
100
+ assert.deepEqual(v.getTickables().map((n) => n.getAbsoluteX()), before);
101
+ });
102
+ test('grace groups and accidentals reserve space before the first rhythmic anchor', () => {
103
+ const v = voice(['q', 'q', 'q', 'q']);
104
+ const first = v.getTickables()[0];
105
+ first.addModifier(new Accidental('##'), 0);
106
+ first.addModifier(new GraceNoteGroup([new GraceNote({ keys: ['d/5'], duration: '8' })]), 0);
107
+ const f = proportional(150).joinVoices([v]).format([v]);
108
+ onsets(v, [0, 150, 300, 450]);
109
+ assert.ok(positions(v)[0] > 20);
110
+ assert.ok(f.getMinTotalWidth() > 620);
111
+ });
112
+ test('crowded chords and insufficient stave width fail with actionable dimensions', () => {
113
+ const v = voice();
114
+ v.getTickables()[1].addModifier(new Accidental('##'), 0);
115
+ assert.throws(() => proportional(10).joinVoices([v]).format([v]), /InsufficientProportionalSpace.*px\/quarter.*px width/);
116
+ const f = proportional(200).joinVoices([v]);
117
+ assert.throws(() => f.format([v], 100), /InsufficientProportionalSpace/);
118
+ f.format([v], 1000);
119
+ onsets(v, [0, 50, 100, 150, 200, 300, 400, 600]);
120
+ });
121
+ test('partial voices keep the declared span and SOFT overflow extends it', () => {
122
+ const partial = new Voice('4/4').setMode(Voice.Mode.SOFT).addTickables(voice(['q'], '1/4').getTickables());
123
+ const f = proportional(100).joinVoices([partial]).format([partial]);
124
+ close(f.getMinTotalWidth(), 404);
125
+ const overflow = new Voice('4/4')
126
+ .setMode(Voice.Mode.SOFT)
127
+ .addTickables(voice(Array(5).fill('q'), '5/4').getTickables());
128
+ const g = proportional(100).joinVoices([overflow]).format([overflow]);
129
+ close(g.getMinTotalWidth(), 504);
130
+ });
131
+ test('invalid scales and widths are rejected, and default spacing remains available', () => {
132
+ for (const scale of [0, -1, NaN, Infinity]) {
133
+ const v = voice();
134
+ assert.throws(() => proportional(scale).joinVoices([v]).format([v]), /pixelsPerQuarter/);
135
+ }
136
+ for (const width of [-1, Infinity, NaN]) {
137
+ const v = voice();
138
+ assert.throws(() => proportional(100).joinVoices([v]).format([v], width), /Width must/);
139
+ }
140
+ const v = voice();
141
+ new Formatter().joinVoices([v]).format([v], 500);
142
+ assert.notEqual(positions(v)[4] - positions(v)[0], positions(v)[6] - positions(v)[4]);
143
+ });
144
+ test('centered whole-measure rests retain centering', () => {
145
+ const v = voice(['wr']);
146
+ v.getTickables()[0].setCenterAlignment(true);
147
+ proportional(100).joinVoices([v]).format([v], 800);
148
+ close(v.getTickables()[0].getCenterXShift(), 200);
149
+ });
150
+ test('System autoWidth and tuning preserve fixed spacing on Canvas and SVG', () => {
151
+ const dom = new JSDOM('<div id="score"></div>');
152
+ const oldDocument = globalThis.document;
153
+ globalThis.document = dom.window.document;
154
+ try {
155
+ for (const backend of [VF.Renderer.Backends.CANVAS, VF.Renderer.Backends.SVG]) {
156
+ const host = document.getElementById('score');
157
+ host.replaceChildren();
158
+ const target = backend === VF.Renderer.Backends.CANVAS ? host.appendChild(document.createElement('canvas')) : host;
159
+ target.id = 'target';
160
+ const factory = new VF.Factory({ renderer: { elementId: target, backend, width: 900, height: 300 } });
161
+ const notes = factory.EasyScore().notes('C5/16, D5, E5, F5, G5/8, A5, B5/q, C6');
162
+ const v = factory.Voice().addTickables(notes);
163
+ const system = factory.System({
164
+ details: { spacing: { mode: 'proportional', pixelsPerQuarter: 120 } },
165
+ formatIterations: 5,
166
+ });
167
+ system.addStave({ voices: [v] }).addClef('treble');
168
+ factory.draw({ retain: true });
169
+ onsets(v, [0, 30, 60, 90, 120, 180, 240, 360]);
170
+ assert.ok(system.getWidth() > 480);
171
+ const before = positions(v);
172
+ factory.draw({ retain: true });
173
+ assert.deepEqual(positions(v), before);
174
+ target.id = 'score';
175
+ }
176
+ }
177
+ finally {
178
+ globalThis.document = oldDocument;
179
+ dom.window.close();
180
+ }
181
+ });
182
+ test('dense chord bounds remain separated at the automatic minimum width', () => {
183
+ const stave = new Stave(10, 50, 900);
184
+ const notes = Array.from({ length: 8 }, () => new StaveNote({ keys: ['c/5', 'd/5', 'e/5'], duration: '8' }).setStave(stave));
185
+ notes.forEach((note) => note.addModifier(new Accidental('##'), 0).addModifier(new Accidental('b'), 1));
186
+ VF.Beam.generateBeams(notes);
187
+ const v = new Voice('4/4').addTickables(notes);
188
+ const f = proportional().joinVoices([v]).format([v]);
189
+ for (let i = 1; i < notes.length; i++) {
190
+ const previous = notes[i - 1].getMetrics();
191
+ const current = notes[i].getMetrics();
192
+ const right = notes[i - 1].getTickContext().getX() + previous.notePx + previous.modRightPx + previous.rightDisplacedHeadPx;
193
+ const left = notes[i].getTickContext().getX() - current.modLeftPx - current.leftDisplacedHeadPx;
194
+ assert.ok(left - right >= 2 - 1e-7);
195
+ }
196
+ const scale = positions(v)[1] - positions(v)[0];
197
+ onsets(v, notes.map((_, i) => scale * i));
198
+ assert.ok(Number.isFinite(f.getMinTotalWidth()));
199
+ });
200
+ test('staves supplied during format also apply to inline prefixes', () => {
201
+ const notes = ['q', 'q', 'q', 'q'].map((duration) => new StaveNote({ keys: ['c/5'], duration }));
202
+ const clef = new ClefNote('bass', 'small');
203
+ const v = new Voice('4/4').addTickables([clef, ...notes]);
204
+ const stave = new Stave(10, 50, 900);
205
+ proportional(120).joinVoices([v]).format([v], 600, { stave });
206
+ onsets(v, [0, 120, 240, 360]);
207
+ assert.ok(clef.getAbsoluteX() + clef.getWidth() <= notes[0].getAbsoluteX());
208
+ });
209
+ test('unsupported numeric ranges fail before producing infinite coordinates', () => {
210
+ assert.throws(() => proportional().preCalculateMinTotalWidth([]), /No voices/);
211
+ assert.throws(() => proportional().format([]), /No voices/);
212
+ const v = voice();
213
+ assert.throws(() => proportional(Number.MAX_VALUE).joinVoices([v]).format([v]), /pixel range/);
214
+ });
215
+ test('optical spacing fits measured obstacles, then stretches rhythmic intervals without moving clefs into notes', () => {
216
+ const stave = new Stave(10, 50, 900);
217
+ const notes = ['q', 'q', '8', '16', '32', '64'].map((duration) => new StaveNote({ keys: ['c/5'], duration }).setStave(stave));
218
+ notes[0].addModifier(new VF.Annotation('crescendo'), 0);
219
+ notes[1].addModifier(new GraceNoteGroup(['d/5', 'e/5', 'f/5'].map((key) => new GraceNote({ keys: [key], duration: '16' }))), 0);
220
+ notes[2].addModifier(new VF.ChordSymbol().addText('Cmaj7/G'), 0);
221
+ notes[3].addModifier(new Accidental('##'), 0);
222
+ const clef = new ClefNote('bass', 'small').setStave(stave);
223
+ const v = new Voice('4/4').setStrict(false).addTickables([notes[0], clef, ...notes.slice(1)]);
224
+ const f = new Formatter({ spacing: { mode: 'optical' } }).joinVoices([v]);
225
+ const minimum = f.preCalculateMinTotalWidth([v]);
226
+ assert.throws(() => f.format([v], minimum - 1), /InsufficientOpticalSpace.*px width/);
227
+ f.format([v], minimum);
228
+ const tight = positions(v);
229
+ for (let i = 1; i < notes.length; ++i) {
230
+ const prev = notes[i - 1].getMetrics(), curr = notes[i].getMetrics();
231
+ assert.ok(tight[i] - curr.modLeftPx - curr.leftDisplacedHeadPx >=
232
+ tight[i - 1] + prev.notePx + prev.rightDisplacedHeadPx + prev.modRightPx + 2 - 1e-7);
233
+ }
234
+ assert.ok(clef.getAbsoluteX() + clef.getWidth() <= notes[1].getAbsoluteX());
235
+ f.format([v], minimum + 200);
236
+ const loose = positions(v);
237
+ const extra = (i) => loose[i] - loose[i - 1] - (tight[i] - tight[i - 1]);
238
+ close(extra(3) / extra(4), Math.sqrt(2));
239
+ f.tune();
240
+ assert.deepEqual(positions(v), loose);
241
+ });
242
+ test('nested 5:4 and 3:2 tuplets preserve every exact onset through reformat', () => {
243
+ const stave = new Stave(10, 50, 900);
244
+ const notes = Array.from({ length: 5 }, () => new StaveNote({ keys: ['c/5'], duration: '8' }).setStave(stave));
245
+ new Tuplet(notes, { numNotes: 5, notesOccupied: 4 });
246
+ new Tuplet(notes.slice(1, 4), { numNotes: 3, notesOccupied: 2 });
247
+ const v = new Voice('4/4').setStrict(false).addTickables(notes);
248
+ const f = proportional(200).joinVoices([v]).format([v]);
249
+ const expected = [0, 6, 10, 14, 18];
250
+ const elapsed = new VF.Fraction(0, 1);
251
+ for (const [i, n] of notes.entries()) {
252
+ assert.ok(elapsed.equals(new VF.Fraction(expected[i] * 4096, 15)));
253
+ elapsed.add(n.getTicks());
254
+ }
255
+ assert.ok(elapsed.equals(new VF.Fraction(24 * 4096, 15)));
256
+ onsets(v, expected.map((value) => (value * 200) / 15));
257
+ f.format([v], 1600);
258
+ onsets(v, expected.map((value) => (value * 200) / 15));
259
+ });
260
+ test('optical and exact policies expose different minima for a very short final attack', () => {
261
+ const makeVoice = () => voice(['h', 'q', '8', '16', '32', '64', '64']);
262
+ const run = (spacing) => {
263
+ const v = makeVoice();
264
+ const f = new Formatter(spacing ? { spacing } : {}).joinVoices([v]);
265
+ const minimum = f.preCalculateMinTotalWidth([v]);
266
+ f.format([v], minimum);
267
+ assert.ok(positions(v).every(Number.isFinite));
268
+ return minimum;
269
+ };
270
+ const optical = run({ mode: 'optical' });
271
+ const exact = run({ mode: 'proportional' });
272
+ const legacy = run();
273
+ assert.ok(optical < exact);
274
+ assert.ok(legacy > 0);
275
+ const constrained = new Formatter({ spacing: { mode: 'proportional' } });
276
+ const v = makeVoice();
277
+ assert.throws(() => constrained.joinVoices([v]).format([v], optical), /InsufficientProportionalSpace/);
278
+ });
@@ -14,7 +14,7 @@ import { join } from 'node:path';
14
14
  import test from 'node:test';
15
15
  import { fileURLToPath } from 'node:url';
16
16
  import puppeteer from 'puppeteer';
17
- import { renderScore } from '../../tools/score-fixtures.mjs';
17
+ import { renderScore, scoreKinds } from '../../tools/score-fixtures.mjs';
18
18
  const root = fileURLToPath(new URL('../../', import.meta.url));
19
19
  test('jsdom registers fonts, renders PNGs, and exports portable SVG', () => {
20
20
  const directory = join(root, 'build/jsdom-smoke');
@@ -56,14 +56,18 @@ test('score benchmark fixtures render', () => __awaiter(void 0, void 0, void 0,
56
56
  yield page.setContent('<div id="score"></div>');
57
57
  yield page.addScriptTag({ path: join(root, 'build/cjs/vexflow-debug.js') });
58
58
  yield page.evaluate(() => __awaiter(void 0, void 0, void 0, function* () {
59
+ yield Promise.all([...document.fonts].map((face) => face.load()));
59
60
  yield document.fonts.ready;
60
61
  }));
61
- for (const kind of ['chorale', 'piano', 'chamber']) {
62
+ for (const kind of scoreKinds) {
62
63
  const result = yield page.evaluate(renderScore, { kind, systems: 1 });
63
64
  const expected = {
64
65
  chorale: { notes: 48, staves: 8 },
65
66
  piano: { notes: 64, staves: 8 },
66
67
  chamber: { notes: 144, staves: 12 },
68
+ 'lead-sheet': { notes: 32, staves: 4 },
69
+ percussion: { notes: 32, staves: 4 },
70
+ tab: { notes: 32, staves: 4 },
67
71
  }[kind];
68
72
  assert.deepEqual({ notes: result.notes, staves: result.staves }, expected);
69
73
  assert.ok(result.svg.includes('<path'));
@@ -12,7 +12,7 @@ const ThreeVoicesTests = {
12
12
  run('Auto Adjust Rest Positions - Three Voices #2', autoRestThreeVoices2);
13
13
  },
14
14
  };
15
- function createThreeVoicesTest(noteGroup1, noteGroup2, noteGroup3, setup) {
15
+ function createThreeVoicesTest(noteGroup1, noteGroup2, noteGroup3, setup, check) {
16
16
  return (options) => {
17
17
  const factory = VexFlowTests.makeFactory(options, 600, 200);
18
18
  const stave = factory.Stave().addClef('treble').addTimeSignature('4/4');
@@ -30,6 +30,7 @@ function createThreeVoicesTest(noteGroup1, noteGroup2, noteGroup3, setup) {
30
30
  for (let i = 0; i < beams.length; i++) {
31
31
  beams[i].setContext(factory.getContext()).drawWithStyle();
32
32
  }
33
+ check === null || check === void 0 ? void 0 : check(noteGroups, options.assert);
33
34
  options.assert.ok(true);
34
35
  };
35
36
  }
@@ -49,6 +50,15 @@ const threeVoices2 = createThreeVoicesTest(['(a4 e5)/16, e5, e5, e5, e5/8, e5, e
49
50
  .getTickables()[0]
50
51
  .addModifier(f.Fingering({ number: '0', position: 'left' }), 0)
51
52
  .addModifier(f.Fingering({ number: '4', position: 'left' }), 1);
53
+ }, (groups, assert) => {
54
+ const beam = groups[1][0].checkBeam();
55
+ const first = beam.getNotes()[0];
56
+ const lower = groups[2][1];
57
+ const headTop = lower.noteHeads[0].getBoundingBox().getY();
58
+ for (const x of [lower.getNoteHeadBeginX(), lower.getNoteHeadEndX()]) {
59
+ const edge = beam.getSlopeY(x, first.getStemX(), beam.getBeamYToDraw(), beam.slope);
60
+ assert.ok(edge < headTop, `Middle beam edge at ${edge} clears lower head at ${headTop} (x=${x})`);
61
+ }
52
62
  });
53
63
  const threeVoices3 = createThreeVoicesTest(['(g4 e5)/4, e5, (g4 e5)/2', { stem: 'up' }], ['c#5/4, b4/8, b4/8/r, a4/4., g4/8', { stem: 'down' }], ['c4/4, b3, a3, g3', { stem: 'down' }], (f, voices) => {
54
64
  voices[0]
@@ -134,10 +134,10 @@ export class VexFlowTests {
134
134
  static generateTestID(prefix) {
135
135
  return prefix + '_' + VexFlowTests.NEXT_TEST_ID++;
136
136
  }
137
- static runTests(name, testFunc, params) {
138
- VexFlowTests.runCanvasTest(name, testFunc, params);
139
- VexFlowTests.runSVGTest(name, testFunc, params);
140
- VexFlowTests.runNodeTest(name, testFunc, params);
137
+ static runTests(name, testFunc, params, fontStacks) {
138
+ VexFlowTests.runCanvasTest(name, testFunc, params, fontStacks);
139
+ VexFlowTests.runSVGTest(name, testFunc, params, fontStacks);
140
+ VexFlowTests.runNodeTest(name, testFunc, params, fontStacks);
141
141
  }
142
142
  static runTextTests(name, testFunc, params) {
143
143
  VexFlowTests.runCanvasText(name, testFunc, params);
@@ -155,10 +155,13 @@ export class VexFlowTests {
155
155
  const { elementId, backend } = options;
156
156
  return new Factory({ renderer: { elementId, backend, width, height } });
157
157
  }
158
- static runCanvasTest(name, testFunc, params) {
158
+ static runCanvasTest(name, testFunc, params, fontStacks) {
159
159
  if (VexFlowTests.RUN_CANVAS_TESTS) {
160
160
  const helper = null;
161
- VexFlowTests.runWithParams(Object.assign(Object.assign({}, CANVAS_TEST_CONFIG), { name, testFunc, params, helper }));
161
+ VexFlowTests.runWithParams(Object.assign(Object.assign({}, CANVAS_TEST_CONFIG), { fontStacks: fontStacks !== null && fontStacks !== void 0 ? fontStacks : CANVAS_TEST_CONFIG.fontStacks, name,
162
+ testFunc,
163
+ params,
164
+ helper }));
162
165
  }
163
166
  }
164
167
  static runCanvasText(name, testFunc, params) {
@@ -167,10 +170,13 @@ export class VexFlowTests {
167
170
  VexFlowTests.runWithParams(Object.assign(Object.assign({}, CANVAS_TEXT_CONFIG), { name, testFunc, params, helper }));
168
171
  }
169
172
  }
170
- static runSVGTest(name, testFunc, params) {
173
+ static runSVGTest(name, testFunc, params, fontStacks) {
171
174
  if (VexFlowTests.RUN_SVG_TESTS) {
172
175
  const helper = null;
173
- VexFlowTests.runWithParams(Object.assign(Object.assign({}, SVG_TEST_CONFIG), { name, testFunc, params, helper }));
176
+ VexFlowTests.runWithParams(Object.assign(Object.assign({}, SVG_TEST_CONFIG), { fontStacks: fontStacks !== null && fontStacks !== void 0 ? fontStacks : SVG_TEST_CONFIG.fontStacks, name,
177
+ testFunc,
178
+ params,
179
+ helper }));
174
180
  }
175
181
  }
176
182
  static runSVGText(name, testFunc, params) {
@@ -179,10 +185,13 @@ export class VexFlowTests {
179
185
  VexFlowTests.runWithParams(Object.assign(Object.assign({}, SVG_TEXT_CONFIG), { name, testFunc, params, helper }));
180
186
  }
181
187
  }
182
- static runNodeTest(name, testFunc, params) {
188
+ static runNodeTest(name, testFunc, params, fontStacks) {
183
189
  if (VexFlowTests.RUN_NODE_TESTS) {
184
190
  const helper = VexFlowTests.runNodeTestHelper;
185
- VexFlowTests.runWithParams(Object.assign(Object.assign({}, NODE_TEST_CONFIG), { name, testFunc, params, helper }));
191
+ VexFlowTests.runWithParams(Object.assign(Object.assign({}, NODE_TEST_CONFIG), { fontStacks: fontStacks !== null && fontStacks !== void 0 ? fontStacks : NODE_TEST_CONFIG.fontStacks, name,
192
+ testFunc,
193
+ params,
194
+ helper }));
186
195
  }
187
196
  }
188
197
  static runNodeTestHelper(fontName, element) {
@@ -0,0 +1,61 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ const advisory = 'https://github.com/advisories/GHSA-fc5q-39xc-vjpf';
4
+ const reviewedVersions = new Set(['2.3.2', '4.0.5']);
5
+ const expires = Date.parse('2026-12-18T00:00:00Z');
6
+ export function isExcepted(report, packages, now = Date.now()) {
7
+ var _a, _b, _c, _d, _e, _f;
8
+ const findings = Object.entries((_a = report === null || report === void 0 ? void 0 : report.vulnerabilities) !== null && _a !== void 0 ? _a : {});
9
+ if (now >= expires || report.auditReportVersion !== 2 || report.error || !findings.length)
10
+ return false;
11
+ if (((_c = (_b = report.metadata) === null || _b === void 0 ? void 0 : _b.vulnerabilities) === null || _c === void 0 ? void 0 : _c.total) !== findings.length)
12
+ return false;
13
+ const accepted = new Set();
14
+ for (const [name, finding] of findings) {
15
+ if (!((_d = finding.nodes) === null || _d === void 0 ? void 0 : _d.length) || !finding.nodes.every((path) => { var _a; return ((_a = packages[path]) === null || _a === void 0 ? void 0 : _a.dev) === true; }))
16
+ return false;
17
+ if (name === 'picomatch') {
18
+ if (finding.isDirect || finding.fixAvailable === true)
19
+ return false;
20
+ if (!finding.nodes.every((path) => reviewedVersions.has(packages[path].version)))
21
+ return false;
22
+ if (((_e = finding.via) === null || _e === void 0 ? void 0 : _e.length) !== 1 || ((_f = finding.via[0]) === null || _f === void 0 ? void 0 : _f.url) !== advisory)
23
+ return false;
24
+ accepted.add(name);
25
+ }
26
+ }
27
+ let previousSize;
28
+ do {
29
+ previousSize = accepted.size;
30
+ for (const [name, { via }] of findings) {
31
+ if ((via === null || via === void 0 ? void 0 : via.length) && via.every((cause) => accepted.has(cause)))
32
+ accepted.add(name);
33
+ }
34
+ } while (accepted.size > previousSize);
35
+ return accepted.size === findings.length;
36
+ }
37
+ function main() {
38
+ var _a;
39
+ const result = spawnSync(process.execPath, [process.env.npm_execpath, 'audit', '--include=dev', '--audit-level=low', '--json'], {
40
+ encoding: 'utf8',
41
+ stdio: ['ignore', 'pipe', 'inherit'],
42
+ });
43
+ if (result.error)
44
+ throw result.error;
45
+ if (result.status === 0) {
46
+ console.log('npm audit passed.');
47
+ return;
48
+ }
49
+ console.log(result.stdout);
50
+ if (result.status === 1) {
51
+ const report = JSON.parse(result.stdout);
52
+ const lock = JSON.parse(readFileSync(new URL('../package-lock.json', import.meta.url), 'utf8'));
53
+ if (isExcepted(report, lock.packages)) {
54
+ console.log('Accepted the development-only picomatch advisory through 2026-12-17 UTC. See SECURITY.md.');
55
+ return;
56
+ }
57
+ }
58
+ process.exitCode = (_a = result.status) !== null && _a !== void 0 ? _a : 1;
59
+ }
60
+ if (import.meta.main)
61
+ main();
@@ -0,0 +1,58 @@
1
+ import assert from 'node:assert/strict';
2
+ import { readFileSync, writeFileSync } from 'node:fs';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import ts from 'typescript';
5
+ const root = new URL('../', import.meta.url);
6
+ const snapshot = new URL('docs/easyscore-native-api.json', root);
7
+ const text = (node) => node === null || node === void 0 ? void 0 : node.getText().replace(/\s+/g, ' ').trim();
8
+ const has = (node, kind) => { var _a; return (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((modifier) => modifier.kind === kind); };
9
+ export function nativeSurface() {
10
+ const index = readFileSync(new URL('src/index.ts', root), 'utf8');
11
+ const modules = [...index.matchAll(/^export \* from '\.\/([^']+)';/gm)].map((match) => match[1]);
12
+ modules.push('easyscore/elements', 'easyscore/composition', 'easyscore/rhythm');
13
+ return Object.fromEntries(modules.map((module) => {
14
+ var _a, _b, _c;
15
+ const path = new URL(`src/${module}.ts`, root);
16
+ const file = ts.createSourceFile(fileURLToPath(path), readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true);
17
+ const declarations = {};
18
+ for (const node of file.statements) {
19
+ if (!has(node, ts.SyntaxKind.ExportKeyword))
20
+ continue;
21
+ const name = text(node.name);
22
+ if (ts.isInterfaceDeclaration(node)) {
23
+ declarations[name] = { extends: (_b = (_a = node.heritageClauses) === null || _a === void 0 ? void 0 : _a.map(text)) !== null && _b !== void 0 ? _b : [], fields: node.members.map(text) };
24
+ }
25
+ else if (ts.isTypeAliasDeclaration(node) || ts.isEnumDeclaration(node)) {
26
+ declarations[name] = text(node);
27
+ }
28
+ else if (ts.isClassDeclaration(node)) {
29
+ declarations[name] = node.members
30
+ .filter((member) => !has(member, ts.SyntaxKind.PrivateKeyword) && !has(member, ts.SyntaxKind.ProtectedKeyword))
31
+ .map((member) => {
32
+ var _a;
33
+ const name = (_a = text(member.name)) !== null && _a !== void 0 ? _a : 'constructor';
34
+ if (member.parameters)
35
+ return `${name}(${member.parameters.map(text).join(', ')})${member.type ? ': ' + text(member.type) : ''}`;
36
+ return `${name}${member.type ? ': ' + text(member.type) : ''}`;
37
+ });
38
+ }
39
+ else if (ts.isFunctionDeclaration(node)) {
40
+ declarations[name] = `(${node.parameters.map(text).join(', ')})${node.type ? ': ' + text(node.type) : ''}`;
41
+ }
42
+ else if (ts.isVariableStatement(node)) {
43
+ for (const declaration of node.declarationList.declarations)
44
+ declarations[text(declaration.name)] = (_c = text(declaration.type)) !== null && _c !== void 0 ? _c : 'inferred';
45
+ }
46
+ }
47
+ return [module, declarations];
48
+ }));
49
+ }
50
+ export function checkNativeSurface() {
51
+ assert.deepEqual(nativeSurface(), JSON.parse(readFileSync(snapshot, 'utf8')), 'Native API changed. Review EasyScore coverage, then run node tools/easyscore-api-audit.mjs --update.');
52
+ }
53
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
54
+ if (process.argv.includes('--update'))
55
+ writeFileSync(snapshot, JSON.stringify(nativeSurface(), null, 2) + '\n');
56
+ else
57
+ checkNativeSurface();
58
+ }
@@ -0,0 +1,62 @@
1
+ export function renderEasyScoreComposition(VF, renderer, spacing = 'engraving', ink = '#24312c') {
2
+ const score = VF.EasyScore.create({ renderer });
3
+ score.setStyle({ fillStyle: ink, strokeStyle: ink });
4
+ const result = score.compose({
5
+ sheet: { width: renderer.width - 40, x: 20, y: 20, rowGap: 55 },
6
+ system: {
7
+ spaceBetweenStaves: 10,
8
+ details: spacing === 'proportional' ? { spacing: { mode: 'proportional', pixelsPerQuarter: 70 } } : {},
9
+ },
10
+ accidentals: 'key-aware',
11
+ signatures: 'every-measure',
12
+ staves: [
13
+ {
14
+ id: 'right',
15
+ key: 'G',
16
+ measures: [
17
+ { span: '1/4', voices: [{ notes: 'D5/q' }] },
18
+ {
19
+ time: '2/4',
20
+ voices: [
21
+ {
22
+ notes: 'F#5/8[id="start"], E5, D5, C5, B4, A4[id="end"]',
23
+ stem: 'up',
24
+ tuplets: [
25
+ { start: 0, count: 3 },
26
+ { start: 3, count: 3 },
27
+ ],
28
+ autoBeam: true,
29
+ },
30
+ { notes: 'G4/h', stem: 'down' },
31
+ ],
32
+ },
33
+ { time: '3/4', voices: [{ notes: 'F#5/q, F5, F5' }] },
34
+ { time: '4/4', voices: [{ notes: ['F#5/h', { change: { key: 'C', clef: 'bass' } }, 'G3/q, C4'] }] },
35
+ ],
36
+ },
37
+ {
38
+ id: 'left',
39
+ clef: 'bass',
40
+ key: 'G',
41
+ measures: [
42
+ { span: '1/4', voices: [{ notes: 'G2/q' }] },
43
+ { time: '2/4', voices: [{ notes: '(G2 D3)/h' }] },
44
+ { time: '3/4', voices: [{ notes: 'G2/h.' }] },
45
+ { time: '4/4', voices: [{ notes: 'C3/w' }] },
46
+ ],
47
+ },
48
+ ],
49
+ spans: [{ kind: 'curve', from: 'start', to: 'end' }],
50
+ });
51
+ result.systems.forEach((system) => system.addConnector('brace'));
52
+ const redraw = (width) => {
53
+ result.sheet.setWidth(width - 40).format();
54
+ const context = score.factory.getContext();
55
+ context.resize(width, result.sheet.getHeight() + 35);
56
+ context.clear();
57
+ score.draw({ retain: true });
58
+ return result.sheet.getRows().map((row) => ({ width: row.width, height: row.height, overflow: row.overflow }));
59
+ };
60
+ redraw(renderer.width);
61
+ return { score, result, redraw };
62
+ }
@@ -0,0 +1,16 @@
1
+ export function createEasyScoreExample(VF, renderer, ink = '#24312c') {
2
+ const score = VF.EasyScore.create({ renderer });
3
+ score.setStyle({ fillStyle: ink, strokeStyle: ink });
4
+ const notes = score.notes('(C4 E4 G4)/h, (C4 F4 A4)');
5
+ const annotation = score.make.annotation({ text: 'dolce', vJustify: 'top' });
6
+ score.attach(notes[0], annotation, 0);
7
+ const tie = score.make.tie({ from: notes[0], to: notes[1], firstIndexes: [0], lastIndexes: [0] });
8
+ const voice = score.voice(notes, { time: '4/4', mode: 'strict' });
9
+ const system = score.system({ x: 20, y: 70, width: renderer.width - 40 });
10
+ system
11
+ .addStave({ voices: [voice] })
12
+ .addClef('treble')
13
+ .addTimeSignature('4/4');
14
+ score.draw({ retain: true });
15
+ return { score, notes, annotation, tie, voice, system };
16
+ }