vexflow 5.0.0-beta.1 → 5.1.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/LICENSE +3 -3
  2. package/README.md +32 -50
  3. package/build/cjs/vexflow-bravura.js +2 -2
  4. package/build/cjs/vexflow-bravura.js.map +1 -1
  5. package/build/cjs/vexflow-core.js +2 -2
  6. package/build/cjs/vexflow-core.js.map +1 -1
  7. package/build/cjs/vexflow-debug-with-tests.js +3685 -1386
  8. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  9. package/build/cjs/vexflow-debug.js +2443 -980
  10. package/build/cjs/vexflow-debug.js.map +1 -1
  11. package/build/cjs/vexflow.js +2 -2
  12. package/build/cjs/vexflow.js.map +1 -1
  13. package/build/esm/src/accidental.js +1 -0
  14. package/build/esm/src/annotation.js +31 -8
  15. package/build/esm/src/beam.js +4 -2
  16. package/build/esm/src/chordsymbol.js +3 -1
  17. package/build/esm/src/clef.js +3 -1
  18. package/build/esm/src/curve.js +68 -11
  19. package/build/esm/src/easyscore.js +40 -1
  20. package/build/esm/src/element.js +42 -9
  21. package/build/esm/src/factory.js +46 -9
  22. package/build/esm/src/flag.js +3 -1
  23. package/build/esm/src/font.js +17 -0
  24. package/build/esm/src/formatter.js +34 -36
  25. package/build/esm/src/fraction.js +4 -1
  26. package/build/esm/src/glyphnote.js +3 -1
  27. package/build/esm/src/gracenotegroup.js +18 -1
  28. package/build/esm/src/index.js +2 -0
  29. package/build/esm/src/keysignature.js +3 -1
  30. package/build/esm/src/metrics.js +55 -1
  31. package/build/esm/src/modifiercontext.js +15 -1
  32. package/build/esm/src/note.js +2 -2
  33. package/build/esm/src/notehead.js +3 -1
  34. package/build/esm/src/ornament.js +3 -1
  35. package/build/esm/src/pedalmarking.js +44 -5
  36. package/build/esm/src/registry.js +16 -6
  37. package/build/esm/src/rendercontext.js +10 -0
  38. package/build/esm/src/sheet.js +117 -0
  39. package/build/esm/src/stave.js +13 -8
  40. package/build/esm/src/stavebarline.js +53 -1
  41. package/build/esm/src/staveline.js +2 -0
  42. package/build/esm/src/stavenote.js +54 -19
  43. package/build/esm/src/stavetie.js +3 -1
  44. package/build/esm/src/stem.js +2 -1
  45. package/build/esm/src/stemmablenote.js +9 -0
  46. package/build/esm/src/stringnumber.js +0 -1
  47. package/build/esm/src/strokes.js +10 -0
  48. package/build/esm/src/svgcontext.js +14 -4
  49. package/build/esm/src/svgexport.js +68 -0
  50. package/build/esm/src/system.js +14 -0
  51. package/build/esm/src/tables.js +69 -37
  52. package/build/esm/src/tabnote.js +20 -1
  53. package/build/esm/src/textbracket.js +5 -4
  54. package/build/esm/src/textdynamics.js +5 -0
  55. package/build/esm/src/textnote.js +3 -3
  56. package/build/esm/src/tickable.js +56 -22
  57. package/build/esm/src/timesignature.js +30 -9
  58. package/build/esm/src/timesignote.js +3 -1
  59. package/build/esm/src/tuning.js +2 -2
  60. package/build/esm/src/tuplet.js +79 -29
  61. package/build/esm/src/util.js +1 -0
  62. package/build/esm/src/version.js +3 -3
  63. package/build/esm/src/vexflow.js +14 -2
  64. package/build/esm/src/voice.js +44 -8
  65. package/build/esm/tests/accidental_tests.js +52 -0
  66. package/build/esm/tests/annotation_tests.js +38 -0
  67. package/build/esm/tests/articulation_tests.js +34 -0
  68. package/build/esm/tests/beam_tests.js +17 -0
  69. package/build/esm/tests/curve_tests.js +81 -0
  70. package/build/esm/tests/font_tests.js +32 -1
  71. package/build/esm/tests/formatter_tests.js +58 -23
  72. package/build/esm/tests/gracenote_tests.js +58 -0
  73. package/build/esm/tests/gracetabnote_tests.js +40 -0
  74. package/build/esm/tests/keysignature_tests.js +14 -3
  75. package/build/esm/tests/node/package-input-tests.mjs +149 -0
  76. package/build/esm/tests/node/render-metrics-tests.mjs +78 -0
  77. package/build/esm/tests/node/rendering-tests.mjs +75 -0
  78. package/build/esm/tests/node/sheet-tests.mjs +202 -0
  79. package/build/esm/tests/node/svg-export-tests.mjs +182 -0
  80. package/build/esm/tests/pedalmarking_tests.js +25 -0
  81. package/build/esm/tests/rests_tests.js +6 -0
  82. package/build/esm/tests/stave_tests.js +6 -3
  83. package/build/esm/tests/stavenote_tests.js +100 -55
  84. package/build/esm/tests/strokes_tests.js +19 -5
  85. package/build/esm/tests/timesignature_tests.js +19 -0
  86. package/build/esm/tests/tuplet_tests.js +273 -12
  87. package/build/esm/tests/unison_tests.js +13 -13
  88. package/build/esm/tests/voice_tests.js +34 -0
  89. package/build/esm/tools/render-metrics.mjs +49 -0
  90. package/build/esm/tools/score-fixtures.mjs +94 -0
  91. package/build/esm/tools/sheet-fixture.mjs +90 -0
  92. package/build/esm/tools/visual-regression.mjs +106 -0
  93. package/build/types/src/annotation.d.ts +17 -1
  94. package/build/types/src/curve.d.ts +24 -7
  95. package/build/types/src/easyscore.d.ts +8 -0
  96. package/build/types/src/element.d.ts +5 -0
  97. package/build/types/src/factory.d.ts +18 -1
  98. package/build/types/src/font.d.ts +2 -0
  99. package/build/types/src/formatter.d.ts +23 -14
  100. package/build/types/src/gracenotegroup.d.ts +5 -0
  101. package/build/types/src/index.d.ts +2 -0
  102. package/build/types/src/metrics.d.ts +2 -0
  103. package/build/types/src/modifiercontext.d.ts +4 -0
  104. package/build/types/src/pedalmarking.d.ts +4 -1
  105. package/build/types/src/registry.d.ts +2 -0
  106. package/build/types/src/rendercontext.d.ts +12 -0
  107. package/build/types/src/sheet.d.ts +49 -0
  108. package/build/types/src/stave.d.ts +4 -4
  109. package/build/types/src/stavebarline.d.ts +10 -0
  110. package/build/types/src/stavenote.d.ts +11 -0
  111. package/build/types/src/strokes.d.ts +4 -0
  112. package/build/types/src/svgcontext.d.ts +5 -0
  113. package/build/types/src/svgexport.d.ts +22 -0
  114. package/build/types/src/system.d.ts +4 -0
  115. package/build/types/src/tables.d.ts +9 -0
  116. package/build/types/src/tabnote.d.ts +4 -0
  117. package/build/types/src/textbracket.d.ts +1 -1
  118. package/build/types/src/textdynamics.d.ts +3 -0
  119. package/build/types/src/tickable.d.ts +27 -10
  120. package/build/types/src/timesignature.d.ts +4 -0
  121. package/build/types/src/tuplet.d.ts +8 -0
  122. package/build/types/src/util.d.ts +1 -0
  123. package/build/types/src/vexflow.d.ts +8 -1
  124. package/build/types/src/voice.d.ts +6 -0
  125. package/changelog/CHANGELOG.md +94 -0
  126. package/package.json +42 -26
  127. package/tests/flow.html +15 -7
@@ -0,0 +1,202 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import assert from 'node:assert/strict';
22
+ import test from 'node:test';
23
+ import { fileURLToPath } from 'node:url';
24
+ import puppeteer from 'puppeteer';
25
+ import { analyzeLayout } from '../../tools/render-metrics.mjs';
26
+ import { renderSheetStudy } from '../../tools/sheet-fixture.mjs';
27
+ const root = fileURLToPath(new URL('../../', import.meta.url));
28
+ test('responsive sheets and themes on Canvas and SVG', (t) => __awaiter(void 0, void 0, void 0, function* () {
29
+ const browser = yield puppeteer.launch({
30
+ headless: true,
31
+ args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : [],
32
+ });
33
+ try {
34
+ const page = yield browser.newPage();
35
+ yield page.setContent('<div id="score"></div>');
36
+ yield page.addScriptTag({ path: `${root}build/cjs/vexflow-debug.js` });
37
+ yield page.evaluate(() => __awaiter(void 0, void 0, void 0, function* () {
38
+ yield document.fonts.ready;
39
+ }));
40
+ for (const font of ['Bravura', 'Petaluma']) {
41
+ for (const backend of ['svg', 'canvas']) {
42
+ yield t.test(`${font} ${backend}: resize, bounds, colors`, () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const result = yield page.evaluate(renderSheetStudy, { font, backend, widths: [320, 680] });
44
+ const [wide, narrow, restored] = result.snapshots;
45
+ assert.deepEqual(restored, wide, 'wide/narrow/wide reflow is deterministic');
46
+ assert.ok(narrow.rows.length > wide.rows.length, 'narrow viewport wraps more rows');
47
+ for (const snapshot of result.snapshots) {
48
+ const metrics = analyzeLayout(snapshot.boxes, { width: snapshot.width + 40, height: snapshot.height + 40 });
49
+ assert.deepEqual(metrics.invalid, []);
50
+ assert.deepEqual(metrics.collisions, [], 'curated voices and measures do not overlap');
51
+ const reportedOverflow = snapshot.rows.some((row) => row.overflow > 0);
52
+ if (!reportedOverflow)
53
+ assert.deepEqual(metrics.overflow, []);
54
+ }
55
+ if (backend === 'svg') {
56
+ assert.equal(result.cssWidth, '720px');
57
+ const colors = result.colors.flatMap((item) => [item.fill, item.stroke]);
58
+ assert.ok(colors.includes('rgb(231, 237, 245)'), 'theme reaches marks');
59
+ assert.ok(colors.includes('rgb(237, 155, 64)'), 'explicit highlight survives');
60
+ assert.ok(!colors.includes('rgb(0, 0, 0)'), 'no hard-coded black marks');
61
+ }
62
+ else {
63
+ const pixels = yield page.evaluate(() => {
64
+ const canvas = document.querySelector('canvas');
65
+ const data = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data;
66
+ let theme = 0, highlight = 0, black = 0;
67
+ for (let i = 0; i < data.length; i += 4) {
68
+ if (data[i + 3] < 250)
69
+ continue;
70
+ if (data[i] === 231 && data[i + 1] === 237 && data[i + 2] === 245)
71
+ theme++;
72
+ if (data[i] === 237 && data[i + 1] === 155 && data[i + 2] === 64)
73
+ highlight++;
74
+ if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0)
75
+ black++;
76
+ }
77
+ return { theme, highlight, black };
78
+ });
79
+ assert.ok(pixels.theme > 100);
80
+ assert.ok(pixels.highlight > 10);
81
+ assert.equal(pixels.black, 0);
82
+ }
83
+ }));
84
+ }
85
+ }
86
+ yield t.test('theme changes preserve local styles and repeated tuplet draws', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ for (const backend of ['svg', 'canvas']) {
88
+ const result = yield page.evaluate((backend) => {
89
+ const VF = VexFlow;
90
+ const host = document.getElementById('score');
91
+ host.replaceChildren();
92
+ const target = backend === 'canvas' ? host.appendChild(document.createElement('canvas')) : host;
93
+ target.id = backend === 'canvas' ? 'score-canvas' : 'score';
94
+ const f = new VF.Factory({ renderer: { elementId: target.id, width: 600, height: 300 } });
95
+ const score = f.EasyScore();
96
+ const notes = score.notes('C5/8, D5, E5, F5/q, G5, A5');
97
+ f.Tuplet({ notes: notes.slice(0, 3), options: { suffix: VF.Glyphs.metNoteQuarterUp } });
98
+ f.System({ width: 560, y: 50 })
99
+ .addStave({ voices: [score.voice(notes)] })
100
+ .addClef('treble');
101
+ const bracket = f.TextBracket({
102
+ from: notes[3],
103
+ to: notes[5],
104
+ text: '8',
105
+ options: { superscript: 'va', position: 'top' },
106
+ });
107
+ const pedal = f.PedalMarking({ notes: [notes[0], notes[5]] });
108
+ for (const element of [bracket, pedal]) {
109
+ element.renderOptions.color = '#ff0000';
110
+ element.setStyle({ fillStyle: '#00aa00', strokeStyle: '#00aa00' });
111
+ }
112
+ const frames = [];
113
+ for (const color of ['#112233', '#ddeeff', '#112233']) {
114
+ f.setStyle({ fillStyle: color, strokeStyle: color });
115
+ f.getContext().clear();
116
+ f.draw({ retain: true });
117
+ frames.push(backend === 'canvas'
118
+ ? target.toDataURL()
119
+ : [...host.querySelectorAll('path,text,rect')].map((node) => {
120
+ const style = getComputedStyle(node);
121
+ return {
122
+ text: node.textContent,
123
+ x: node.getAttribute('x'),
124
+ y: node.getAttribute('y'),
125
+ d: node.getAttribute('d'),
126
+ fill: style.fill,
127
+ stroke: style.stroke,
128
+ };
129
+ }));
130
+ }
131
+ const defaults = f.getContext().getDefaultStyle();
132
+ f.reset();
133
+ return { frames, defaults, voices: f.getVoices().length };
134
+ }, backend);
135
+ assert.deepEqual(result.frames[0], result.frames[2], `${backend}: redraw returns identical output`);
136
+ assert.notDeepEqual(result.frames[0], result.frames[1], `${backend}: changing theme changes output`);
137
+ assert.deepEqual(result.defaults, {}, 'drawing restores context defaults');
138
+ assert.equal(result.voices, 0, 'reset releases retained score');
139
+ if (backend === 'svg') {
140
+ const colors = result.frames[0].flatMap((item) => [item.fill, item.stroke]);
141
+ assert.ok(colors.includes('rgb(0, 170, 0)'), 'explicit bracket and pedal color renders');
142
+ assert.ok(!colors.includes('rgb(255, 0, 0)'), 'explicit styles override legacy colors');
143
+ }
144
+ }
145
+ }));
146
+ yield t.test('empty and oversized sheets, parser boundaries, and ownership', () => __awaiter(void 0, void 0, void 0, function* () {
147
+ const result = yield page.evaluate(() => {
148
+ const VF = VexFlow;
149
+ const f = new VF.Factory({ renderer: { elementId: 'score', width: 600, height: 400 } });
150
+ const empty = f.Sheet({ width: 50 }).format().getRows();
151
+ const score = f.EasyScore();
152
+ const measures = score.measures('C4/h[id="a|b"], E4, |, G4, C5');
153
+ const durations = measures.map((notes) => notes.map((note) => note.getDuration()));
154
+ const invalid = ['', 'C4/w || C4/w', '| C4/w', 'C4/w | rubbish'].map((line) => {
155
+ try {
156
+ score.measures(line);
157
+ return false;
158
+ }
159
+ catch (_a) {
160
+ return true;
161
+ }
162
+ });
163
+ const sheet = f.Sheet({ width: 50 });
164
+ const system = sheet.addSystem();
165
+ system.addStave({ voices: [score.voice(measures[0])] }).addClef('treble');
166
+ sheet.format();
167
+ const rows = sheet.getRows().map((_a) => {
168
+ var { systems } = _a, row = __rest(_a, ["systems"]);
169
+ return row;
170
+ });
171
+ let builds = 0;
172
+ class CountedNote extends VF.StaveNote {
173
+ buildNoteHeads() {
174
+ builds++;
175
+ return super.buildNoteHeads();
176
+ }
177
+ count() {
178
+ return this.children.length;
179
+ }
180
+ }
181
+ const note = new CountedNote({ keys: ['c/4', 'e/4'], duration: '8' });
182
+ const initialBuilds = builds;
183
+ const initialChildren = note.count();
184
+ for (let i = 0; i < 20; i++)
185
+ note.setStemDirection(i % 2 ? 1 : -1);
186
+ return { empty, durations, invalid, rows, initialBuilds, initialChildren, finalChildren: note.count() };
187
+ });
188
+ assert.deepEqual(result.empty, []);
189
+ assert.deepEqual(result.durations, [
190
+ ['h', 'h'],
191
+ ['h', 'h'],
192
+ ]);
193
+ assert.ok(result.invalid.every(Boolean));
194
+ assert.ok(result.rows[0].overflow > 0);
195
+ assert.equal(result.initialBuilds, 1);
196
+ assert.equal(result.finalChildren, result.initialChildren);
197
+ }));
198
+ }
199
+ finally {
200
+ yield browser.close();
201
+ }
202
+ }));
@@ -0,0 +1,182 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import assert from 'node:assert/strict';
11
+ import { spawnSync } from 'node:child_process';
12
+ import { mkdirSync, readdirSync, readFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import test from 'node:test';
15
+ import { fileURLToPath } from 'node:url';
16
+ import puppeteer from 'puppeteer';
17
+ const root = fileURLToPath(new URL('../../', import.meta.url));
18
+ test('portable SVG paths retain score geometry and render with fonts and styles blocked', () => __awaiter(void 0, void 0, void 0, function* () {
19
+ const browser = yield puppeteer.launch({
20
+ headless: true,
21
+ args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : [],
22
+ });
23
+ try {
24
+ const page = yield browser.newPage();
25
+ yield page.setViewport({ width: 640, height: 300, deviceScaleFactor: 1 });
26
+ yield page.setContent('<div id="score"></div>');
27
+ yield page.addScriptTag({ path: join(root, 'build/cjs/vexflow-debug.js') });
28
+ yield page.addScriptTag({ path: join(root, 'node_modules/opentype.js/dist/opentype.js') });
29
+ const faces = [
30
+ ['Bravura', 'bravura/bravura.otf'],
31
+ ['Academico', 'academico/academico.otf'],
32
+ ['Academico', 'academico/academico-bold.otf', 'bold'],
33
+ ['Petaluma', 'petaluma/petaluma.otf'],
34
+ ['Petaluma Script', 'petalumascript/petalumascript.otf'],
35
+ ].map(([family, file, weight]) => ({
36
+ family,
37
+ weight,
38
+ data: readFileSync(join(root, 'node_modules/@vexflow-fonts', file)).toString('base64'),
39
+ }));
40
+ yield page.evaluate((faces) => __awaiter(void 0, void 0, void 0, function* () {
41
+ window.outlineFonts = [];
42
+ for (const { family, weight, data } of faces) {
43
+ const bytes = Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
44
+ const face = new FontFace(family, bytes, { weight: weight !== null && weight !== void 0 ? weight : 'normal' });
45
+ document.fonts.add(yield face.load());
46
+ window.outlineFonts.push({ family, weight, font: opentype.parse(bytes.buffer) });
47
+ }
48
+ yield document.fonts.ready;
49
+ }), faces);
50
+ const checks = yield page.evaluate(() => {
51
+ const container = document.createElement('div');
52
+ const context = new VexFlow.SVGContext(container);
53
+ context.resize(200, 100);
54
+ context.openGroup('styled').setAttribute('transform', 'translate(4 5)');
55
+ context.setFont('Academico', '12pt', 'bold').setFillStyle('#cf2300').fillText('AV', 10, 30);
56
+ context.closeGroup();
57
+ context.setFont('Bravura,Academico', '16px').fillText('\uE050Hello', 5, 60);
58
+ const before = context.toSVG();
59
+ let missingError = false;
60
+ try {
61
+ context.toSVG([]);
62
+ }
63
+ catch (error) {
64
+ missingError = /MissingFont/.test(error.message);
65
+ }
66
+ const exported = new DOMParser().parseFromString(context.toSVG(window.outlineFonts), 'image/svg+xml');
67
+ const paths = exported.querySelectorAll('path');
68
+ const bold = window.outlineFonts.find((face) => face.weight === 'bold').font;
69
+ const regular = window.outlineFonts.find((face) => face.family === 'Academico' && !face.weight).font;
70
+ const music = window.outlineFonts[0].font;
71
+ const expectedMixed = music.getPath('\uE050', 5, 60, 16).toPathData(5) +
72
+ regular.getPath('Hello', 5 + music.getAdvanceWidth('\uE050', 16), 60, 16).toPathData(5);
73
+ context.setFont('Academico', '12pt', 'normal', 'italic').fillText('italic', 5, 80);
74
+ let italicError = false;
75
+ try {
76
+ context.toSVG(window.outlineFonts);
77
+ }
78
+ catch (error) {
79
+ italicError = /MissingFont/.test(error.message);
80
+ }
81
+ return {
82
+ exact: paths[0].getAttribute('d') === bold.getPath('AV', 10, 30, 16).toPathData(5),
83
+ mixed: paths[1].getAttribute('d') === expectedMixed,
84
+ color: paths[0].getAttribute('fill'),
85
+ transform: paths[0].parentElement.getAttribute('transform'),
86
+ original: before.includes('<text') && context.svg.querySelectorAll('text').length === 3,
87
+ noText: !exported.querySelector('text'),
88
+ missingError,
89
+ italicError,
90
+ };
91
+ });
92
+ assert.deepEqual(checks, {
93
+ exact: true,
94
+ mixed: true,
95
+ color: '#cf2300',
96
+ transform: 'translate(4 5)',
97
+ original: true,
98
+ noText: true,
99
+ missingError: true,
100
+ italicError: true,
101
+ });
102
+ for (const [name, music, text] of [
103
+ ['bravura', 'Bravura', 'Academico'],
104
+ ['petaluma', 'Petaluma', 'Petaluma Script'],
105
+ ]) {
106
+ const drawings = yield page.evaluate(({ music, text }) => {
107
+ document.querySelector('#score').replaceChildren();
108
+ 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);
121
+ context.setFont(`${text},Academico`, '14pt').fillText('Andante — AV', 20, 28);
122
+ context.setFont(`${text},Academico`, '12pt').fillText('Sing clearly', 200, 195);
123
+ const before = context.toSVG();
124
+ 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
+ const clone = new DOMParser().parseFromString(after, 'image/svg+xml').documentElement;
130
+ return { before, after, glyphs: originalBounds.length, paths: clone.querySelectorAll('path').length };
131
+ }, { music, text });
132
+ assert.ok(drawings.glyphs > 10);
133
+ assert.ok(drawings.paths >= drawings.glyphs);
134
+ assert.doesNotMatch(drawings.after, /<text\b|@font-face|<use\b/);
135
+ const viewer = yield browser.newPage();
136
+ yield viewer.setViewport({ width: 640, height: 300, deviceScaleFactor: 1 });
137
+ const failures = [];
138
+ viewer.on('request', (request) => failures.push(request.url()));
139
+ const csp = "<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; font-src 'none'; style-src 'none'; img-src data:\">";
140
+ for (const state of ['before', 'after']) {
141
+ yield viewer.setContent(csp + drawings[state]);
142
+ assert.equal(yield viewer.evaluate(() => document.fonts.size), 0);
143
+ if (state === 'after') {
144
+ const geometry = yield viewer.$eval('svg', (svg) => {
145
+ const box = svg.getBBox();
146
+ return { width: box.width, height: box.height, text: svg.querySelectorAll('text').length };
147
+ });
148
+ assert.equal(geometry.text, 0);
149
+ assert.ok(geometry.width > 500 && geometry.height > 100);
150
+ }
151
+ }
152
+ yield viewer.setContent(csp +
153
+ `<img width="620" height="240" src="data:image/svg+xml;base64,${Buffer.from(drawings.after).toString('base64')}">`);
154
+ yield viewer.waitForFunction(() => document.querySelector('img').complete);
155
+ assert.ok(yield viewer.$eval('img', (img) => img.naturalWidth > 0));
156
+ assert.ok(failures.every((url) => url.startsWith('data:')), 'no font or network requests');
157
+ yield viewer.close();
158
+ }
159
+ yield page.close();
160
+ }
161
+ finally {
162
+ yield browser.close();
163
+ }
164
+ }));
165
+ test('image generator embeds the local music fonts in saved SVGs', () => {
166
+ const directory = join(root, 'build/svg-generator-check');
167
+ mkdirSync(directory, { recursive: true });
168
+ const result = spawnSync(process.execPath, ['tools/generate_images_pptr.js', 'build', directory, '--module=Clef'], {
169
+ cwd: root,
170
+ timeout: 30000,
171
+ encoding: 'utf8',
172
+ });
173
+ assert.ifError(result.error);
174
+ assert.equal(result.status, 0, result.stdout + result.stderr);
175
+ const files = readdirSync(directory);
176
+ const svgs = files.filter((name) => name.endsWith('.svg'));
177
+ assert.ok(svgs.length >= 3, 'representative SVGs generated');
178
+ for (const name of svgs) {
179
+ assert.match(readFileSync(join(directory, name), 'utf8'), /data:font\/woff2;base64,/);
180
+ assert.ok(files.includes(name + '.png'), 'SVG rasterization succeeded');
181
+ }
182
+ });
@@ -1,7 +1,10 @@
1
+ import { VexFlow } from '../src/vexflow.js';
1
2
  import { VexFlowTests } from './vexflow_test_helpers.js';
3
+ import { StaveNote } from '../src/stavenote.js';
2
4
  const PedalMarkingTests = {
3
5
  Start() {
4
6
  QUnit.module('PedalMarking');
7
+ QUnit.test('annotationClearance', annotationClearance);
5
8
  const run = VexFlowTests.runTests;
6
9
  run('Simple Pedal 1', simple1);
7
10
  run('Simple Pedal 1b', simple1b);
@@ -89,3 +92,25 @@ const customTest2 = createTest((factory, notes0, notes1) => {
89
92
  });
90
93
  VexFlowTests.register(PedalMarkingTests);
91
94
  export { PedalMarkingTests };
95
+ function annotationClearance(assert) {
96
+ const V = VexFlow;
97
+ const stave = new V.Stave(20, 60, 600);
98
+ const notes = Array.from({ length: 4 }, () => new StaveNote({ keys: ['c/4'], duration: 'q' }).setStave(stave));
99
+ const annotations = ['pedal', 'change', 'gypsy', 'mark'].map((text, i) => {
100
+ const annotation = new V.Annotation(text).setVerticalJustification('bottom').setFontSize(20);
101
+ notes[i].addModifier(annotation, 0);
102
+ return annotation;
103
+ });
104
+ const voice = new V.Voice('4/4').addTickables(notes);
105
+ new V.Formatter().joinVoices([voice]).formatToStave([voice], stave);
106
+ for (const type of ['bracket', 'mixed']) {
107
+ const pedal = new V.PedalMarking([notes[0], notes[1], notes[1], notes[3]]).setType(type);
108
+ if (type === 'mixed')
109
+ pedal.setCustomText('Ped.');
110
+ const bottom = Math.max(...annotations.map((a) => a.computeY().y + a.getTextMetrics().actualBoundingBoxDescent));
111
+ assert.ok(pedal.getYForStave(stave) - pedal.renderOptions.bracketHeight >= bottom + 4);
112
+ annotations[2].setTextBaseline(300);
113
+ assert.ok(pedal.getYForStave(stave) >= 314, 'Explicit baselines are respected');
114
+ annotations[2].setTextBaseline();
115
+ }
116
+ }
@@ -32,6 +32,9 @@ function setupContext(options, contextBuilder, width = 350, height = 150) {
32
32
  function basic(options, contextBuilder) {
33
33
  const { context, stave } = setupContext(options, contextBuilder, 700);
34
34
  const notes = [
35
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: 'mr' }),
36
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: 'lr' }),
37
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '1/2r' }),
35
38
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: 'wr' }),
36
39
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: 'hr' }),
37
40
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '4r' }),
@@ -40,6 +43,9 @@ function basic(options, contextBuilder) {
40
43
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '32r' }),
41
44
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '64r' }),
42
45
  new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '128r' }),
46
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '256r' }),
47
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '512r' }),
48
+ new StaveNote({ keys: ['b/4'], stemDirection: 1, duration: '1024r' }),
43
49
  ];
44
50
  Dot.buildAndAttach(notes, { all: true });
45
51
  Formatter.FormatAndDraw(context, stave, notes);
@@ -6,7 +6,7 @@ import { Formatter } from '../src/formatter.js';
6
6
  import { KeySignature } from '../src/keysignature.js';
7
7
  import { Modifier } from '../src/modifier.js';
8
8
  import { Stave } from '../src/stave.js';
9
- import { Barline, BarlineType } from '../src/stavebarline.js';
9
+ import { Barline, BarlineType, RepeatBracketType } from '../src/stavebarline.js';
10
10
  import { StaveNote } from '../src/stavenote.js';
11
11
  import { Repetition } from '../src/staverepetition.js';
12
12
  import { StaveSection } from '../src/stavesection.js';
@@ -193,13 +193,14 @@ function drawEndModifiers(options, contextBuilder) {
193
193
  const blockHeight = 80;
194
194
  let x = 10;
195
195
  let y = 0;
196
+ let bracketType = RepeatBracketType.NONE;
196
197
  const ctx = contextBuilder(options.elementId, 800, 700);
197
198
  function drawStavesInTwoLines(endBarLine) {
198
199
  function drawStave(x, y, width, begMods, endMods) {
199
200
  const staveBar = new Stave(x, y, width - 10);
200
201
  if (begMods) {
201
202
  if (begMods.barLine !== undefined) {
202
- staveBar.setBegBarType(begMods.barLine);
203
+ staveBar.setBegBarType(begMods.barLine, bracketType);
203
204
  }
204
205
  if (begMods.clef !== undefined) {
205
206
  staveBar.addClef(begMods.clef);
@@ -213,7 +214,7 @@ function drawEndModifiers(options, contextBuilder) {
213
214
  }
214
215
  if (endMods) {
215
216
  if (endMods.barLine !== undefined) {
216
- staveBar.setEndBarType(endMods.barLine);
217
+ staveBar.setEndBarType(endMods.barLine, bracketType);
217
218
  }
218
219
  if (endMods.clef !== undefined) {
219
220
  staveBar.addEndClef(endMods.clef);
@@ -257,9 +258,11 @@ function drawEndModifiers(options, contextBuilder) {
257
258
  drawStavesInTwoLines(BarlineType.DOUBLE);
258
259
  y += blockHeight + 10;
259
260
  x = 10;
261
+ bracketType = RepeatBracketType.STRAIGHT;
260
262
  drawStavesInTwoLines(BarlineType.REPEAT_END);
261
263
  y += blockHeight + 10;
262
264
  x = 10;
265
+ bracketType = RepeatBracketType.CURVED;
263
266
  drawStavesInTwoLines(BarlineType.REPEAT_BOTH);
264
267
  }
265
268
  function drawStaveRepetition(options, contextBuilder) {