vexflow 5.2.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +6502 -1708
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +5622 -1618
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +10 -3
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +28 -6
- package/build/esm/src/beam.js +171 -28
- package/build/esm/src/bend.js +79 -23
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +48 -55
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +52 -2
- package/build/esm/src/easyscore/policies.js +39 -8
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +157 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +31 -11
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +10 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +24 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +43 -18
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +134 -116
- package/build/esm/src/stavetie.js +66 -9
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +20 -6
- package/build/esm/src/tuplet.js +58 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +20 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +367 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +9 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +20 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +27 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +12 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +10 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +9 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +6 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +20 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +25 -0
- package/package.json +15 -3
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -0,0 +1,282 @@
|
|
|
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 test from 'node:test';
|
|
12
|
+
import { readFile } from 'node:fs/promises';
|
|
13
|
+
import puppeteer from 'puppeteer';
|
|
14
|
+
import { createCanvas, registerFont } from 'canvas';
|
|
15
|
+
import { makeContinuousStudy } from '../engraving/continuous-studies.mjs';
|
|
16
|
+
const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
17
|
+
for (const family of ['Bravura', 'Academico']) {
|
|
18
|
+
const name = family.toLowerCase();
|
|
19
|
+
registerFont(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.otf', import.meta.url).pathname, {
|
|
20
|
+
family,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
|
|
24
|
+
function factory() {
|
|
25
|
+
const canvas = createCanvas(960, 1100), ctx = canvas.getContext('2d');
|
|
26
|
+
const f = new VF.Factory({ renderer: { elementId: null, width: 960, height: 1100 } }).setContext(new VF.CanvasContext(ctx));
|
|
27
|
+
return { f, ctx, canvas };
|
|
28
|
+
}
|
|
29
|
+
function scene(kind, width, mode) {
|
|
30
|
+
const { f, ctx, canvas } = factory(), c = makeContinuousStudy(VF, f, kind, width, mode), l = c.sheet.getContinuousLayout();
|
|
31
|
+
const frame = (w) => {
|
|
32
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
33
|
+
c.sheet.setWidth(w);
|
|
34
|
+
f.draw({ retain: true });
|
|
35
|
+
return {
|
|
36
|
+
rows: l.rows.map((r) => ({ m: r.measures, v: r.visibleStaves, w: r.width, h: r.height, rest: r.restGroups })),
|
|
37
|
+
fragments: structuredClone(l.fragments),
|
|
38
|
+
diagnostics: structuredClone(l.diagnostics),
|
|
39
|
+
pixels: canvas.toBuffer(),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
return { f, c, l, frame };
|
|
43
|
+
}
|
|
44
|
+
test('vocal phrase retains IDs; three fragments reunite at the original width with identical pixels', () => {
|
|
45
|
+
const { c, l, frame } = scene('choir', 740), head = c.getNote('v00');
|
|
46
|
+
const wide = frame(740);
|
|
47
|
+
assert.equal(wide.rows.length, 1);
|
|
48
|
+
const narrow = frame(260);
|
|
49
|
+
assert.deepEqual(narrow.rows.map((r) => r.m), [
|
|
50
|
+
[1, 2],
|
|
51
|
+
[3, 4],
|
|
52
|
+
[5, 6],
|
|
53
|
+
]);
|
|
54
|
+
for (const id of ['sung-word', 'phrase'])
|
|
55
|
+
assert.deepEqual(l.fragments.filter((f) => f.id === id).map((f) => f.part), ['first', 'middle', 'last']);
|
|
56
|
+
const endSigns = c.staves[1][0].getModifiers(VF.StaveModifier.Position.END, VF.KeySignature.CATEGORY);
|
|
57
|
+
assert.equal(endSigns.length, 1);
|
|
58
|
+
assert.deepEqual(narrow.diagnostics, []);
|
|
59
|
+
assert.equal(head, c.getNote('v00'));
|
|
60
|
+
assert.deepEqual(frame(740), wide);
|
|
61
|
+
assert.equal(c.staves[1][0].getModifiers(VF.StaveModifier.Position.END, VF.KeySignature.CATEGORY).length, 0);
|
|
62
|
+
});
|
|
63
|
+
test('balanced width avoids the greedy last-measure row on the same seven measures', () => {
|
|
64
|
+
const greedy = scene('breaks', 415, 'greedy').frame(415), balanced = scene('breaks', 415, 'balanced').frame(415);
|
|
65
|
+
assert.deepEqual(greedy.rows.map((r) => r.m.length), [6, 1]);
|
|
66
|
+
assert.deepEqual(balanced.rows.map((r) => r.m.length), [3, 4]);
|
|
67
|
+
assert.deepEqual(balanced.rows.flatMap((r) => r.m), greedy.rows.flatMap((r) => r.m));
|
|
68
|
+
});
|
|
69
|
+
test('grand-staff drawing preserves cross-staff stem joins and wedge aperture across redraw', () => {
|
|
70
|
+
const { c, frame } = scene('keyboard', 490);
|
|
71
|
+
const wide = frame(490), n = c.getNote('cross'), staff = c.staves[0][1], beam = n.getBeam();
|
|
72
|
+
assert.equal(n.getStave(), staff);
|
|
73
|
+
assert.ok(beam.getStripBounds().every((b) => Number.isFinite(b.y)));
|
|
74
|
+
const parts = wide.fragments.filter((f) => f.kind === 'crescendo');
|
|
75
|
+
assert.deepEqual(parts.map((f) => f.part), ['first', 'last']);
|
|
76
|
+
assert.equal(parts[0].progress[1], parts[1].progress[0]);
|
|
77
|
+
assert.equal(parts[0].progress[0], 0);
|
|
78
|
+
assert.equal(parts[1].progress[1], 1);
|
|
79
|
+
assert.deepEqual(c.staves[0].map((s) => s.getY()), c.staves[1].map((s) => s.getY()));
|
|
80
|
+
frame(300);
|
|
81
|
+
assert.deepEqual(frame(490), wide);
|
|
82
|
+
assert.equal(n.getStave(), staff);
|
|
83
|
+
});
|
|
84
|
+
test('silent staves return with their names and a compressed run retains its measure identities', () => {
|
|
85
|
+
const { c, frame } = scene('ensemble', 430);
|
|
86
|
+
const { rows, diagnostics } = frame(430);
|
|
87
|
+
assert.deepEqual(diagnostics, []);
|
|
88
|
+
assert.deepEqual(rows.map((r) => r.v), [['fl'], ['fl', 'vc']]);
|
|
89
|
+
assert.deepEqual(rows[0].rest, [[2, 3, 4]]);
|
|
90
|
+
assert.equal(c.notes.length, 6);
|
|
91
|
+
assert.ok(c.notes[2][1][0][0].isRest());
|
|
92
|
+
assert.equal(c.staves[4][1].getModifiers()[0].getType(), VF.Barline.type.REPEAT_BEGIN);
|
|
93
|
+
assert.equal(c.staves[5][0].getModifiers()[1].getType(), VF.Barline.type.REPEAT_END);
|
|
94
|
+
});
|
|
95
|
+
function spec(count, continuous, notes = (i) => [{ id: 'n' + i, note: { keys: ['c/5'], duration: 'w' } }]) {
|
|
96
|
+
return {
|
|
97
|
+
staves: [{ id: 'staff', measures: Array.from({ length: count }, (_, i) => ({ voices: [{ notes: notes(i) }] })) }],
|
|
98
|
+
continuous,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
test('hard keeps overflow together and forced breaks win over spare space', () => {
|
|
102
|
+
const { f } = factory();
|
|
103
|
+
const c = f.EasyScore().compose(spec(4, {
|
|
104
|
+
boundaries: [
|
|
105
|
+
{ measure: 2, breakBefore: 'keep' },
|
|
106
|
+
{ measure: 3, breakBefore: 'force' },
|
|
107
|
+
{ measure: 4, breakBefore: 'keep' },
|
|
108
|
+
],
|
|
109
|
+
}));
|
|
110
|
+
const l = c.sheet.getContinuousLayout();
|
|
111
|
+
c.sheet.setWidth(12).format();
|
|
112
|
+
assert.deepEqual(l.rows.map((r) => r.measures), [
|
|
113
|
+
[1, 2],
|
|
114
|
+
[3, 4],
|
|
115
|
+
]);
|
|
116
|
+
assert.deepEqual(l.diagnostics.map((d) => d.code), ['RowOverflow', 'RowOverflow']);
|
|
117
|
+
assert.ok(l.rows.every((r) => r.overflow > 0));
|
|
118
|
+
c.sheet.setWidth(800).format();
|
|
119
|
+
assert.deepEqual(l.rows.map((r) => r.measures), [
|
|
120
|
+
[1, 2],
|
|
121
|
+
[3, 4],
|
|
122
|
+
]);
|
|
123
|
+
assert.deepEqual(l.diagnostics, []);
|
|
124
|
+
});
|
|
125
|
+
test('span families retain the source anchors and continuous parameter at first, middle and final fragments', () => {
|
|
126
|
+
for (const kind of [
|
|
127
|
+
'tie',
|
|
128
|
+
'slur',
|
|
129
|
+
'crescendo',
|
|
130
|
+
'diminuendo',
|
|
131
|
+
'pedal',
|
|
132
|
+
'lyric',
|
|
133
|
+
'hyphen',
|
|
134
|
+
'volta',
|
|
135
|
+
'ottava',
|
|
136
|
+
'trill',
|
|
137
|
+
'tuplet',
|
|
138
|
+
]) {
|
|
139
|
+
const { f } = factory(), c = f.EasyScore().compose(spec(3, {
|
|
140
|
+
spans: [{ id: 's', kind, from: 'n0', to: 'n2' }],
|
|
141
|
+
boundaries: [
|
|
142
|
+
{ measure: 2, breakBefore: 'force' },
|
|
143
|
+
{ measure: 3, breakBefore: 'force' },
|
|
144
|
+
],
|
|
145
|
+
}));
|
|
146
|
+
f.draw({ retain: true });
|
|
147
|
+
const l = c.sheet.getContinuousLayout(), fs = l.fragments;
|
|
148
|
+
assert.deepEqual(l.diagnostics, [], kind);
|
|
149
|
+
assert.deepEqual(fs.map((f) => f.part), ['first', 'middle', 'last'], kind);
|
|
150
|
+
assert.ok(fs.every((f) => f.id === 's' && f.x1 < f.x2 && Number.isFinite(f.y1 + f.y2)));
|
|
151
|
+
for (let i = 1; i < fs.length; i++)
|
|
152
|
+
assert.equal(fs[i - 1].progress[1], fs[i].progress[0]);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
test('boundary key, clef and meter move together; explicit signs survive and returned tied accidentals reflow', () => {
|
|
156
|
+
const { f } = factory(), es = f.EasyScore();
|
|
157
|
+
const s = spec(2, { spans: [{ id: 'tie', kind: 'tie', from: 'n0', to: 'n1' }] }, (i) => [
|
|
158
|
+
{ id: 'n' + i, note: { keys: ['f#/4'], duration: 'w' } },
|
|
159
|
+
]);
|
|
160
|
+
s.accidentals = 'key-aware';
|
|
161
|
+
const c = es.compose(s), n = c.getNote('n1'), l = c.sheet.getContinuousLayout();
|
|
162
|
+
const mods = () => n.getModifiers().filter((m) => m instanceof VF.Accidental);
|
|
163
|
+
c.sheet.setWidth(680).format();
|
|
164
|
+
assert.equal(mods().length, 0);
|
|
165
|
+
c.sheet.setWidth(128).format();
|
|
166
|
+
assert.equal(l.rows.length, 2);
|
|
167
|
+
assert.equal(mods().length, 1);
|
|
168
|
+
const explicit = f.Accidental({ type: 'n' }).setAsCautionary();
|
|
169
|
+
n.addModifier(explicit, 0);
|
|
170
|
+
c.sheet.setWidth(680).format();
|
|
171
|
+
assert.deepEqual(mods(), [explicit]);
|
|
172
|
+
const other = factory().f.EasyScore();
|
|
173
|
+
const boundary = spec(2, {});
|
|
174
|
+
boundary.staves[0].measures[0].key = 'D';
|
|
175
|
+
Object.assign(boundary.staves[0].measures[1], { key: 'F', clef: 'bass', time: '2/2' });
|
|
176
|
+
const b = other.compose(boundary);
|
|
177
|
+
b.sheet.setWidth(145).format();
|
|
178
|
+
const signs = (pos) => b.staves[0][0].getModifiers(pos).map((m) => m.getCategory());
|
|
179
|
+
for (const cat of [VF.Clef.CATEGORY, VF.KeySignature.CATEGORY, VF.TimeSignature.CATEGORY])
|
|
180
|
+
assert.ok(signs(VF.StaveModifier.Position.END).includes(cat), cat);
|
|
181
|
+
b.sheet.setWidth(800).format();
|
|
182
|
+
assert.deepEqual(signs(VF.StaveModifier.Position.END), [VF.Barline.CATEGORY]);
|
|
183
|
+
});
|
|
184
|
+
test('structural marks interrupt rest compression; navigation targets and span heads validate atomically', () => {
|
|
185
|
+
const { f } = factory(), es = f.EasyScore(), rest = () => [{ note: { keys: ['b/4'], duration: 'wr' } }];
|
|
186
|
+
const c = es.compose(spec(7, {
|
|
187
|
+
compressRests: true,
|
|
188
|
+
boundaries: [
|
|
189
|
+
{ measure: 4, navigation: { kind: 'segno', id: 'sign' } },
|
|
190
|
+
{ measure: 7, navigation: { kind: 'dalSegno', target: 'sign' } },
|
|
191
|
+
],
|
|
192
|
+
}, rest));
|
|
193
|
+
c.sheet.setWidth(850).format();
|
|
194
|
+
assert.deepEqual(c.sheet.getContinuousLayout().rows.flatMap((r) => r.restGroups), [
|
|
195
|
+
[2, 3],
|
|
196
|
+
[5, 6],
|
|
197
|
+
]);
|
|
198
|
+
for (const config of [
|
|
199
|
+
{ spans: [{ id: 's', kind: 'tie', from: 'n0', to: 'n1', toHead: 5 }] },
|
|
200
|
+
{ boundaries: [{ measure: 1, navigation: { kind: 'toCoda', target: 'missing' } }] },
|
|
201
|
+
{ boundaries: [{ measure: 3 }] },
|
|
202
|
+
]) {
|
|
203
|
+
const fresh = factory().f.EasyScore();
|
|
204
|
+
assert.throws(() => fresh.compose(spec(2, config)));
|
|
205
|
+
assert.equal(fresh.getElement('n0'), undefined);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
test('the shared stem and arpeggio follow the two native heads at each width', () => {
|
|
209
|
+
const { c, frame } = scene('chord', 375);
|
|
210
|
+
const wide = frame(375);
|
|
211
|
+
assert.deepEqual(wide.diagnostics, []);
|
|
212
|
+
const top = c.getNote('rh00'), bottom = c.getNote('lh00'), stroke = top.getModifiers().find((m) => m instanceof VF.Stroke);
|
|
213
|
+
assert.equal(top.getStemX(), bottom.getStemX());
|
|
214
|
+
const ink = stroke.getBoundingBox();
|
|
215
|
+
assert.ok(ink.y <= top.getYs()[0] && ink.y + ink.h >= bottom.getYs()[0]);
|
|
216
|
+
frame(160);
|
|
217
|
+
assert.deepEqual(frame(375), wide);
|
|
218
|
+
});
|
|
219
|
+
test('instrument changes survive hiding and reflow and the new full name reserves row-start width', () => {
|
|
220
|
+
const s = spec(3, { boundaries: [{ measure: 2, breakBefore: 'force' }] });
|
|
221
|
+
s.staves[0].name = 'Flute';
|
|
222
|
+
s.staves[0].shortName = 'Fl.';
|
|
223
|
+
s.staves[0].measures[1].instrument = { name: 'Bass clarinet in B-flat', shortName: 'B. cl.' };
|
|
224
|
+
const c = factory().f.EasyScore().compose(s);
|
|
225
|
+
c.sheet.setWidth(165).format();
|
|
226
|
+
assert.ok(c.staves[1][0].getX() > c.staves[0][0].getX() + 30);
|
|
227
|
+
assert.ok(c.staves[2][0].getX() < c.staves[1][0].getX());
|
|
228
|
+
});
|
|
229
|
+
test('choir, piano and ensemble reflow in browser SVG and Canvas with two font pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
231
|
+
try {
|
|
232
|
+
const page = yield browser.newPage();
|
|
233
|
+
yield page.setContent('<body></body>');
|
|
234
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
235
|
+
yield page.addScriptTag({ content: 'window.makeContinuousStudy=' + makeContinuousStudy.toString() });
|
|
236
|
+
for (const family of ['Bravura', 'Academico', 'Petaluma', 'Petaluma Script']) {
|
|
237
|
+
const name = family.toLowerCase().replaceAll(' ', '');
|
|
238
|
+
const data = yield readFile(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.woff2', import.meta.url));
|
|
239
|
+
yield page.evaluate((family, data) => __awaiter(void 0, void 0, void 0, function* () { return document.fonts.add(yield new FontFace(family, 'url(data:font/woff2;base64,' + data + ')').load()); }), family, data.toString('base64'));
|
|
240
|
+
}
|
|
241
|
+
for (const backend of ['svg', 'canvas'])
|
|
242
|
+
for (const kind of ['choir', 'keyboard', 'ensemble'])
|
|
243
|
+
for (const family of ['Bravura', 'Petaluma']) {
|
|
244
|
+
const output = yield page.evaluate(({ backend, kind, family }) => {
|
|
245
|
+
const VF = window.VexFlow;
|
|
246
|
+
VF.setFonts(family, family === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
247
|
+
const target = document.createElement(backend === 'svg' ? 'div' : 'canvas');
|
|
248
|
+
target.id = 'study';
|
|
249
|
+
document.body.replaceChildren(target);
|
|
250
|
+
const f = new VF.Factory({ renderer: { elementId: 'study', width: 850, height: 1200 } });
|
|
251
|
+
const c = window.makeContinuousStudy(VF, f, kind, 740), layout = c.sheet.getContinuousLayout();
|
|
252
|
+
return [740, 270, 740].map((w) => {
|
|
253
|
+
f.getContext().clear();
|
|
254
|
+
c.sheet.setWidth(w);
|
|
255
|
+
f.draw({ retain: true });
|
|
256
|
+
const geometry = layout.rows.map((r) => [r.measures, r.visibleStaves, r.height, r.width]);
|
|
257
|
+
const drawn = backend === 'svg'
|
|
258
|
+
? target.querySelectorAll('path,text').length > 0
|
|
259
|
+
: target
|
|
260
|
+
.getContext('2d')
|
|
261
|
+
.getImageData(0, 0, 850, 1200)
|
|
262
|
+
.data.some((v, i) => i % 4 === 3 && v > 0);
|
|
263
|
+
return {
|
|
264
|
+
geometry,
|
|
265
|
+
fragments: structuredClone(layout.fragments),
|
|
266
|
+
diagnostics: structuredClone(layout.diagnostics),
|
|
267
|
+
drawn,
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
}, { backend, kind, family });
|
|
271
|
+
assert.deepEqual(output[0], output[2], backend + ' ' + kind + ' ' + family);
|
|
272
|
+
assert.notDeepEqual(output[0].geometry, output[1].geometry);
|
|
273
|
+
for (const frame of output) {
|
|
274
|
+
assert.ok(frame.drawn);
|
|
275
|
+
assert.deepEqual(frame.diagnostics, [], backend + ' ' + kind + ' ' + family);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
yield browser.close();
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
@@ -951,3 +951,74 @@ test('typed grace notes retain explicit stem direction over automatic defaults',
|
|
|
951
951
|
assert.equal(grace.getStemDirection(), -1);
|
|
952
952
|
assert.equal(grace.isAutoStem(), false);
|
|
953
953
|
});
|
|
954
|
+
test('grace order is explicit and simultaneous signs are independent of voice insertion', () => {
|
|
955
|
+
const marks = (note) => note
|
|
956
|
+
.getModifiers()
|
|
957
|
+
.filter((m) => m instanceof VF.Accidental)
|
|
958
|
+
.map((m) => m.type);
|
|
959
|
+
const voice = (side, pitches) => ({
|
|
960
|
+
notes: [
|
|
961
|
+
{
|
|
962
|
+
note: { keys: ['f#/4'], duration: 'h' },
|
|
963
|
+
grace: { side, notes: pitches.map((key) => ({ keys: [key], duration: '16' })) },
|
|
964
|
+
},
|
|
965
|
+
'F4/h',
|
|
966
|
+
],
|
|
967
|
+
});
|
|
968
|
+
function arrays(voices, graceAccidentals) {
|
|
969
|
+
const result = create().compose({
|
|
970
|
+
accidentals: 'key-aware',
|
|
971
|
+
graceAccidentals,
|
|
972
|
+
staves: [{ id: 'a', measures: [{ voices }] }],
|
|
973
|
+
});
|
|
974
|
+
return result.notes[0][0].map(([host, last]) => {
|
|
975
|
+
const grace = host.getModifiers().find((m) => m instanceof VF.GraceNoteGroup);
|
|
976
|
+
return [grace.getGraceNotes().map(marks), marks(host), marks(last)];
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
const early = voice('before', ['f/4', 'f#/4']);
|
|
980
|
+
const conflict = voice('before', ['fb/4']);
|
|
981
|
+
const expected = [
|
|
982
|
+
[[[], ['#']], ['#'], ['n']],
|
|
983
|
+
[[['b']], ['#'], ['n']],
|
|
984
|
+
];
|
|
985
|
+
assert.deepEqual(arrays([early, conflict], 'ordered'), expected);
|
|
986
|
+
assert.deepEqual(arrays([conflict, early], 'ordered'), expected.toReversed());
|
|
987
|
+
assert.deepEqual(arrays([early], 'explicit'), [[[[], []], ['#'], ['n']]]);
|
|
988
|
+
assert.deepEqual(arrays([voice('after', ['f/4', 'f#/4'])], 'ordered'), [[[['n'], ['#']], ['#'], ['n']]]);
|
|
989
|
+
});
|
|
990
|
+
test('explicit grace cautionaries survive ordered generation and suppress redundant host signs', () => {
|
|
991
|
+
const result = create().compose({
|
|
992
|
+
accidentals: 'key-aware',
|
|
993
|
+
graceAccidentals: 'ordered',
|
|
994
|
+
staves: [
|
|
995
|
+
{
|
|
996
|
+
id: 'a',
|
|
997
|
+
measures: [
|
|
998
|
+
{
|
|
999
|
+
voices: [
|
|
1000
|
+
{
|
|
1001
|
+
notes: [
|
|
1002
|
+
{
|
|
1003
|
+
note: { keys: ['f#/4'], duration: 'w' },
|
|
1004
|
+
grace: {
|
|
1005
|
+
side: 'before',
|
|
1006
|
+
notes: [
|
|
1007
|
+
{ keys: ['f#/4'], duration: '8', accidentals: [{ index: 0, type: '#', cautionary: true }] },
|
|
1008
|
+
],
|
|
1009
|
+
},
|
|
1010
|
+
},
|
|
1011
|
+
],
|
|
1012
|
+
},
|
|
1013
|
+
],
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
},
|
|
1017
|
+
],
|
|
1018
|
+
});
|
|
1019
|
+
const [host] = result.notes[0][0][0];
|
|
1020
|
+
const [group] = host.getModifiers();
|
|
1021
|
+
assert.equal(host.getModifiers().length, 1);
|
|
1022
|
+
const marks = group.getGraceNotes()[0].getModifiers();
|
|
1023
|
+
assert.deepEqual(marks.map((m) => [m.type, m.isCautionary()]), [['#', true]]);
|
|
1024
|
+
});
|