vexflow 5.2.0 → 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.
- 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 +2759 -1382
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +1814 -1227
- 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/articulation.js +24 -6
- package/build/esm/src/beam.js +158 -28
- package/build/esm/src/bend.js +24 -19
- package/build/esm/src/curve.js +27 -53
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +40 -1
- package/build/esm/src/easyscore/policies.js +34 -6
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +150 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +15 -7
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/index.js +2 -0
- package/build/esm/src/keysignature.js +1 -1
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +38 -18
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/stavenote.js +128 -115
- package/build/esm/src/stavetie.js +39 -7
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +5 -0
- package/build/esm/src/tuplet.js +57 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +4 -0
- 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/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/studies.mjs +279 -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/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -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/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/articulation.d.ts +6 -1
- package/build/types/src/beam.d.ts +14 -0
- package/build/types/src/curve.d.ts +9 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +19 -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/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/index.d.ts +2 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +4 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +2 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +4 -0
- package/changelog/CHANGELOG.md +17 -0
- package/package.json +7 -2
- 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,262 @@
|
|
|
1
|
+
const durations = new Map([
|
|
2
|
+
['1/1', 'w'],
|
|
3
|
+
['1/2', 'h'],
|
|
4
|
+
['1/4', 'q'],
|
|
5
|
+
['1/8', '8'],
|
|
6
|
+
['1/16', '16'],
|
|
7
|
+
]);
|
|
8
|
+
const fractions = new Map([...durations].map(([a, b]) => [b, a]));
|
|
9
|
+
function fail(code, sourceId, phase) {
|
|
10
|
+
const diagnostic = { code, sourceId, severity: 'error', phase };
|
|
11
|
+
throw Object.assign(new Error(`${code} at ${sourceId}`), { diagnostic });
|
|
12
|
+
}
|
|
13
|
+
function ticks(at, owner, phase) {
|
|
14
|
+
const match = /^(0|[1-9]\d*)\/(1|2|4|8|16)$/.exec(at);
|
|
15
|
+
if (!match || +match[1] > +match[2])
|
|
16
|
+
fail('UnsupportedTime', owner, phase);
|
|
17
|
+
const value = (+match[1] * 16) / +match[2];
|
|
18
|
+
if (at !== rational(value))
|
|
19
|
+
fail('UnsupportedTime', owner, phase);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function rational(t) {
|
|
23
|
+
if (!t)
|
|
24
|
+
return '0/1';
|
|
25
|
+
for (const denominator of [1, 2, 4, 8, 16]) {
|
|
26
|
+
if (Number.isInteger((t * denominator) / 16))
|
|
27
|
+
return `${(t * denominator) / 16}/${denominator}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function fields(object, names, id, phase) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
if (!object ||
|
|
33
|
+
Object.getPrototypeOf(object) !== Object.prototype ||
|
|
34
|
+
Object.keys(object).some((k) => !names.includes(k)))
|
|
35
|
+
fail('UnsupportedInput', (_c = (_b = (_a = object === null || object === void 0 ? void 0 : object.getAttribute) === null || _a === void 0 ? void 0 : _a.call(object, 'id')) !== null && _b !== void 0 ? _b : object === null || object === void 0 ? void 0 : object.id) !== null && _c !== void 0 ? _c : id, phase);
|
|
36
|
+
}
|
|
37
|
+
function validate(score, phase) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const ids = new Set();
|
|
40
|
+
const events = new Set();
|
|
41
|
+
const claim = (id) => {
|
|
42
|
+
if (typeof id !== 'string' || !id || ids.has(id))
|
|
43
|
+
fail('InvalidId', id, phase);
|
|
44
|
+
ids.add(id);
|
|
45
|
+
};
|
|
46
|
+
fields(score, ['staves', 'measures', 'marks'], 'score', phase);
|
|
47
|
+
if (![score.staves, score.measures, score.marks].every(Array.isArray))
|
|
48
|
+
fail('UnsupportedInput', 'score', phase);
|
|
49
|
+
if (!score.staves.length || !score.measures.length)
|
|
50
|
+
fail('EmptyScore', 'score', phase);
|
|
51
|
+
for (const staff of score.staves) {
|
|
52
|
+
fields(staff, ['id', 'voice', 'clef', 'key', 'time'], (_a = staff === null || staff === void 0 ? void 0 : staff.id) !== null && _a !== void 0 ? _a : 'staff', phase);
|
|
53
|
+
claim(staff.id);
|
|
54
|
+
claim(staff.voice);
|
|
55
|
+
if (!['treble', 'bass'].includes(staff.clef) || !['C', 'G'].includes(staff.key) || staff.time !== '4/4')
|
|
56
|
+
fail('UnsupportedContext', staff.id, phase);
|
|
57
|
+
}
|
|
58
|
+
for (const bar of score.measures) {
|
|
59
|
+
fields(bar, ['id', 'key', 'voices'], (_b = bar === null || bar === void 0 ? void 0 : bar.id) !== null && _b !== void 0 ? _b : 'measure', phase);
|
|
60
|
+
claim(bar.id);
|
|
61
|
+
if (bar.key !== undefined && !['C', 'G'].includes(bar.key))
|
|
62
|
+
fail('UnsupportedContext', bar.id, phase);
|
|
63
|
+
fields(bar.voices, score.staves.map((s) => s.voice), bar.id, phase);
|
|
64
|
+
for (const staff of score.staves) {
|
|
65
|
+
let t = 0;
|
|
66
|
+
if (!Array.isArray(bar.voices[staff.voice]))
|
|
67
|
+
fail('MissingVoice', bar.id, phase);
|
|
68
|
+
for (const event of bar.voices[staff.voice]) {
|
|
69
|
+
fields(event, ['id', 'pitch', 'at', 'duration'], bar.id, phase);
|
|
70
|
+
claim(event.id);
|
|
71
|
+
events.add(event.id);
|
|
72
|
+
if (!durations.has(event.duration) ||
|
|
73
|
+
ticks(event.at, event.id, phase) !== t ||
|
|
74
|
+
!/^[a-g](#|b)?\/[0-9]$/.test(event.pitch))
|
|
75
|
+
fail('UnsupportedEvent', event.id, phase);
|
|
76
|
+
t += ticks(event.duration, event.id, phase);
|
|
77
|
+
}
|
|
78
|
+
if (t !== 16)
|
|
79
|
+
fail('IncompleteMeasure', bar.id, phase);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const barIndex = (id, owner) => {
|
|
83
|
+
const index = score.measures.findIndex((b) => b.id === id);
|
|
84
|
+
if (index < 0)
|
|
85
|
+
fail('DanglingAnchor', owner, phase);
|
|
86
|
+
return index;
|
|
87
|
+
};
|
|
88
|
+
for (const mark of score.marks) {
|
|
89
|
+
claim(mark === null || mark === void 0 ? void 0 : mark.id);
|
|
90
|
+
if (mark.kind === 'dynamic') {
|
|
91
|
+
fields(mark, ['id', 'kind', 'event', 'text', 'offset'], mark.id, phase);
|
|
92
|
+
if (!events.has(mark.event))
|
|
93
|
+
fail('DanglingAnchor', mark.id, phase);
|
|
94
|
+
if (!Number.isFinite(mark.offset) || mark.text !== 'p')
|
|
95
|
+
fail('UnsupportedMark', mark.id, phase);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!score.staves.some((s) => s.id === mark.staff))
|
|
99
|
+
fail('DanglingAnchor', mark.id, phase);
|
|
100
|
+
if (mark.kind === 'rehearsal') {
|
|
101
|
+
fields(mark, ['id', 'kind', 'measure', 'staff', 'text'], mark.id, phase);
|
|
102
|
+
barIndex(mark.measure, mark.id);
|
|
103
|
+
if (typeof mark.text !== 'string')
|
|
104
|
+
fail('UnsupportedMark', mark.id, phase);
|
|
105
|
+
}
|
|
106
|
+
else if (mark.kind === 'pedal') {
|
|
107
|
+
fields(mark, ['id', 'kind', 'staff', 'start', 'end'], mark.id, phase);
|
|
108
|
+
const positions = [mark.start, mark.end].map((anchor, i) => {
|
|
109
|
+
fields(anchor, ['measure', 'at', 'continuation'], mark.id, phase);
|
|
110
|
+
const bar = barIndex(anchor.measure, mark.id);
|
|
111
|
+
const at = ticks(anchor.at, mark.id, phase);
|
|
112
|
+
if (anchor.continuation !== undefined &&
|
|
113
|
+
(anchor.continuation !== true || (i ? bar !== score.measures.length - 1 || at !== 16 : bar !== 0 || at !== 0)))
|
|
114
|
+
fail('InvalidContinuation', mark.id, phase);
|
|
115
|
+
return bar * 16 + at;
|
|
116
|
+
});
|
|
117
|
+
if (positions[0] >= positions[1])
|
|
118
|
+
fail('InvalidSpan', mark.id, phase);
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
fail('UnsupportedMark', mark.id, phase);
|
|
122
|
+
}
|
|
123
|
+
return score;
|
|
124
|
+
}
|
|
125
|
+
export function compositionInput(score) {
|
|
126
|
+
return {
|
|
127
|
+
staves: score.staves.map((staff) => ({
|
|
128
|
+
id: staff.id,
|
|
129
|
+
clef: staff.clef,
|
|
130
|
+
key: staff.key,
|
|
131
|
+
time: staff.time,
|
|
132
|
+
measures: score.measures.map((bar) => (Object.assign(Object.assign({}, (bar.key && { key: bar.key })), { voices: [
|
|
133
|
+
{
|
|
134
|
+
notes: bar.voices[staff.voice].map((e) => ({
|
|
135
|
+
id: e.id,
|
|
136
|
+
note: { clef: staff.clef, keys: [e.pitch], duration: durations.get(e.duration) },
|
|
137
|
+
})),
|
|
138
|
+
},
|
|
139
|
+
] }))),
|
|
140
|
+
})),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export function saveScore(score, format) {
|
|
144
|
+
validate(score, 'encode');
|
|
145
|
+
if (format === 'logical')
|
|
146
|
+
return JSON.stringify({ format, version: 1, score });
|
|
147
|
+
if (format !== 'easyscore')
|
|
148
|
+
fail('UnsupportedFormat', 'score', 'encode');
|
|
149
|
+
return JSON.stringify({
|
|
150
|
+
format,
|
|
151
|
+
version: 1,
|
|
152
|
+
composition: compositionInput(score),
|
|
153
|
+
measureIds: score.measures.map((b) => b.id),
|
|
154
|
+
voiceIds: score.staves.map((s) => s.voice),
|
|
155
|
+
marks: score.marks,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export function loadScore(text) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
let file;
|
|
161
|
+
try {
|
|
162
|
+
file = JSON.parse(text);
|
|
163
|
+
}
|
|
164
|
+
catch (_c) {
|
|
165
|
+
fail('InvalidDocument', 'score', 'decode');
|
|
166
|
+
}
|
|
167
|
+
if ((file === null || file === void 0 ? void 0 : file.version) !== 1)
|
|
168
|
+
fail('UnsupportedVersion', 'score', 'decode');
|
|
169
|
+
if (file.format === 'logical') {
|
|
170
|
+
fields(file, ['format', 'version', 'score'], 'score', 'decode');
|
|
171
|
+
return validate(file.score, 'decode');
|
|
172
|
+
}
|
|
173
|
+
if (file.format !== 'easyscore')
|
|
174
|
+
fail('UnsupportedFormat', 'score', 'decode');
|
|
175
|
+
fields(file, ['format', 'version', 'composition', 'measureIds', 'voiceIds', 'marks'], 'score', 'decode');
|
|
176
|
+
if (![(_a = file.composition) === null || _a === void 0 ? void 0 : _a.staves, file.measureIds, file.voiceIds, file.marks].every(Array.isArray) ||
|
|
177
|
+
!file.composition.staves.length ||
|
|
178
|
+
file.composition.staves.length !== file.voiceIds.length)
|
|
179
|
+
fail('InvalidDocument', 'score', 'decode');
|
|
180
|
+
for (const staff of file.composition.staves) {
|
|
181
|
+
if (!Array.isArray(staff === null || staff === void 0 ? void 0 : staff.measures) || staff.measures.length !== file.measureIds.length)
|
|
182
|
+
fail('InvalidDocument', (_b = staff === null || staff === void 0 ? void 0 : staff.id) !== null && _b !== void 0 ? _b : 'staff', 'decode');
|
|
183
|
+
}
|
|
184
|
+
const staves = file.composition.staves.map(({ id, clef, key, time }, i) => ({
|
|
185
|
+
id,
|
|
186
|
+
clef,
|
|
187
|
+
key,
|
|
188
|
+
time,
|
|
189
|
+
voice: file.voiceIds[i],
|
|
190
|
+
}));
|
|
191
|
+
const measures = file.measureIds.map((id, i) => {
|
|
192
|
+
var _a, _b;
|
|
193
|
+
const voices = Object.create(null);
|
|
194
|
+
const key = (_a = file.composition.staves[0].measures[i]) === null || _a === void 0 ? void 0 : _a.key;
|
|
195
|
+
for (const [j, staff] of file.composition.staves.entries()) {
|
|
196
|
+
const bar = staff.measures[i];
|
|
197
|
+
if (!bar ||
|
|
198
|
+
bar.key !== key ||
|
|
199
|
+
!Array.isArray(bar.voices) ||
|
|
200
|
+
bar.voices.length !== 1 ||
|
|
201
|
+
!Array.isArray((_b = bar.voices[0]) === null || _b === void 0 ? void 0 : _b.notes))
|
|
202
|
+
fail('UnsupportedContext', id, 'decode');
|
|
203
|
+
let t = 0;
|
|
204
|
+
voices[staves[j].voice] = bar.voices[0].notes.map((item) => {
|
|
205
|
+
const { id, note } = item !== null && item !== void 0 ? item : {};
|
|
206
|
+
if (!Array.isArray(note === null || note === void 0 ? void 0 : note.keys) || note.keys.length !== 1 || !fractions.has(note.duration))
|
|
207
|
+
fail('UnsupportedEvent', id, 'decode');
|
|
208
|
+
const event = { id, pitch: note.keys[0], duration: fractions.get(note.duration), at: rational(t) };
|
|
209
|
+
t += ticks(event.duration, id, 'decode');
|
|
210
|
+
return event;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return Object.assign(Object.assign({ id }, (key && { key })), { voices: Object.assign({}, voices) });
|
|
214
|
+
});
|
|
215
|
+
const score = validate({ staves, measures, marks: file.marks }, 'decode');
|
|
216
|
+
const reconstructed = compositionInput(score);
|
|
217
|
+
const canonical = (value) => Array.isArray(value)
|
|
218
|
+
? value.map(canonical)
|
|
219
|
+
: value && typeof value === 'object'
|
|
220
|
+
? Object.fromEntries(Object.keys(value)
|
|
221
|
+
.sort()
|
|
222
|
+
.map((k) => [k, canonical(value[k])]))
|
|
223
|
+
: value;
|
|
224
|
+
if (JSON.stringify(canonical(reconstructed)) !== JSON.stringify(canonical(file.composition)))
|
|
225
|
+
fail('UnsupportedInput', 'composition', 'decode');
|
|
226
|
+
return score;
|
|
227
|
+
}
|
|
228
|
+
export function excerpt(score, firstId, lastId = firstId) {
|
|
229
|
+
validate(score, 'excerpt');
|
|
230
|
+
const index = (id) => score.measures.findIndex((b) => b.id === id);
|
|
231
|
+
const first = index(firstId), last = index(lastId);
|
|
232
|
+
if (first < 0 || last < first)
|
|
233
|
+
fail('InvalidRange', firstId, 'excerpt');
|
|
234
|
+
const measures = structuredClone(score.measures.slice(first, last + 1));
|
|
235
|
+
const events = new Set(measures.flatMap((b) => Object.values(b.voices)
|
|
236
|
+
.flat()
|
|
237
|
+
.map((e) => e.id)));
|
|
238
|
+
const staves = score.staves.map((staff) => {
|
|
239
|
+
var _a;
|
|
240
|
+
let key = staff.key;
|
|
241
|
+
for (const bar of score.measures.slice(0, first + 1))
|
|
242
|
+
key = (_a = bar.key) !== null && _a !== void 0 ? _a : key;
|
|
243
|
+
return Object.assign(Object.assign({}, staff), { key });
|
|
244
|
+
});
|
|
245
|
+
const marks = [];
|
|
246
|
+
for (const mark of structuredClone(score.marks)) {
|
|
247
|
+
if (mark.kind === 'dynamic' && events.has(mark.event))
|
|
248
|
+
marks.push(mark);
|
|
249
|
+
if (mark.kind === 'rehearsal' && index(mark.measure) >= first && index(mark.measure) <= last)
|
|
250
|
+
marks.push(mark);
|
|
251
|
+
if (mark.kind !== 'pedal' || index(mark.end.measure) < first || index(mark.start.measure) > last)
|
|
252
|
+
continue;
|
|
253
|
+
if (index(mark.start.measure) < first)
|
|
254
|
+
mark.start = { measure: firstId, at: '0/1', continuation: true };
|
|
255
|
+
if (index(mark.end.measure) > last)
|
|
256
|
+
mark.end = { measure: lastId, at: '1/1', continuation: true };
|
|
257
|
+
if (mark.start.measure !== mark.end.measure ||
|
|
258
|
+
ticks(mark.start.at, mark.id, 'excerpt') < ticks(mark.end.at, mark.id, 'excerpt'))
|
|
259
|
+
marks.push(mark);
|
|
260
|
+
}
|
|
261
|
+
return validate({ staves, measures, marks }, 'excerpt');
|
|
262
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
export function registerStudies() {
|
|
2
|
+
const VF = globalThis.VexFlow;
|
|
3
|
+
QUnit.module('M0 studies');
|
|
4
|
+
function chord(options, input, clef, signs) {
|
|
5
|
+
const factory = VF.Test.makeFactory(options, 220, 150);
|
|
6
|
+
const score = factory.EasyScore();
|
|
7
|
+
const notes = score.notes(input, { clef });
|
|
8
|
+
factory
|
|
9
|
+
.System({ width: 195 })
|
|
10
|
+
.addStave({ voices: [score.voice(notes, { mode: 'soft' })] })
|
|
11
|
+
.addClef(clef);
|
|
12
|
+
factory.draw();
|
|
13
|
+
const note = notes[0];
|
|
14
|
+
const actual = note
|
|
15
|
+
.getModifiers()
|
|
16
|
+
.filter((mark) => mark instanceof VF.Accidental)
|
|
17
|
+
.map((mark) => mark.type);
|
|
18
|
+
options.assert.deepEqual(actual, signs, 'Explicit accidental sequence');
|
|
19
|
+
options.assert.equal(note.noteHeads.length, note.getKeys().length, 'Every pitch has a head');
|
|
20
|
+
const root = document.getElementById(options.elementId);
|
|
21
|
+
const boxes = [...root.querySelectorAll('.vf-stavenote text')].map((glyph) => {
|
|
22
|
+
const { x, y, width, height } = glyph.getBBox();
|
|
23
|
+
return { glyph: glyph.textContent.codePointAt(0).toString(16), x, y, width, height };
|
|
24
|
+
});
|
|
25
|
+
const headGlyphs = new Set(note.noteHeads.map((head) => head.getText().codePointAt(0).toString(16)));
|
|
26
|
+
const heads = boxes.filter((box) => headGlyphs.has(box.glyph));
|
|
27
|
+
const headPositions = new Set(heads.map((head) => head.x));
|
|
28
|
+
options.assert.equal(heads.length, note.getKeys().length, 'Every pitch draws its head glyph');
|
|
29
|
+
const quality = headPositions.size === heads.length ? 'Distinct head positions' : 'Coincident head positions';
|
|
30
|
+
root.dataset.measurement = JSON.stringify({ actual, boxes, quality });
|
|
31
|
+
}
|
|
32
|
+
VF.Test.runTests('Altered whole-note unison', (o) => chord(o, '(B4 B#4)/w', 'treble', ['#']));
|
|
33
|
+
VF.Test.runTests('Natural and flat in bass clef', (o) => chord(o, '(Bn3 Bb3)/w', 'bass', ['n', 'b']));
|
|
34
|
+
VF.Test.runTests('Three spellings on one line', (o) => chord(o, '(D#5 Dn5 Db5)/q', 'treble', ['#', 'n', 'b']));
|
|
35
|
+
VF.Test.runTests('Mixed subdivisions after a triplet', (options) => {
|
|
36
|
+
const factory = VF.Test.makeFactory(options, 480, 160);
|
|
37
|
+
const score = factory.EasyScore();
|
|
38
|
+
const notes = score.notes('C5/q, D5/q, E5/q, F5/8, G5/16, A5/16, B5/q');
|
|
39
|
+
score.tuplet(notes.slice(0, 3));
|
|
40
|
+
const beams = VF.Beam.generateBeams(notes);
|
|
41
|
+
factory
|
|
42
|
+
.System({ width: 450 })
|
|
43
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
44
|
+
.addClef('treble');
|
|
45
|
+
factory.draw();
|
|
46
|
+
for (const beam of beams)
|
|
47
|
+
beam.setContext(factory.getContext()).draw();
|
|
48
|
+
const groups = beams.map((beam) => beam.getNotes().map((note) => notes.indexOf(note)));
|
|
49
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ groups, expected: [[3, 4, 5]] });
|
|
50
|
+
options.assert.deepEqual(groups, [[3, 4, 5]], 'The three short notes form one beat');
|
|
51
|
+
options.assert.equal(notes.length, 7, 'Seven attacks fill one strict 4/4 measure');
|
|
52
|
+
});
|
|
53
|
+
VF.Test.runTests('Repeated contour at two widths', (options) => {
|
|
54
|
+
const factory = VF.Test.makeFactory(options, 560, 260);
|
|
55
|
+
const score = factory.EasyScore();
|
|
56
|
+
const beams = [];
|
|
57
|
+
for (const [width, y] of [
|
|
58
|
+
[300, 15],
|
|
59
|
+
[500, 140],
|
|
60
|
+
]) {
|
|
61
|
+
const notes = score.notes('A4/8, B4, C4, D4, G4, A4, B4, C4', { stem: 'up' });
|
|
62
|
+
factory
|
|
63
|
+
.System({ width, y })
|
|
64
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
65
|
+
.addClef('treble');
|
|
66
|
+
for (const start of [0, 4])
|
|
67
|
+
beams.push(factory.Beam({ notes: notes.slice(start, start + 4) }));
|
|
68
|
+
}
|
|
69
|
+
factory.draw();
|
|
70
|
+
const slopes = beams.map((beam) => beam.slope);
|
|
71
|
+
options.assert.ok(slopes.every(Number.isFinite), 'Finite screen-coordinate slopes');
|
|
72
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ slopes });
|
|
73
|
+
});
|
|
74
|
+
VF.Test.runTests('Lyric after a skipped attack', (options) => {
|
|
75
|
+
const factory = VF.Test.makeFactory(options, 360, 160);
|
|
76
|
+
const score = factory.EasyScore();
|
|
77
|
+
const notes = score.notes('G4/q, A4/q, C5/h');
|
|
78
|
+
for (const [i, word] of [
|
|
79
|
+
[0, 'sum'],
|
|
80
|
+
[2, 'mer'],
|
|
81
|
+
]) {
|
|
82
|
+
notes[i].addModifier(new VF.Annotation(word).setTextBaseline(125), 0);
|
|
83
|
+
}
|
|
84
|
+
factory
|
|
85
|
+
.System({ width: 335 })
|
|
86
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
87
|
+
.addClef('treble');
|
|
88
|
+
factory.draw();
|
|
89
|
+
const root = document.getElementById(options.elementId);
|
|
90
|
+
const lyrics = [...root.querySelectorAll('text')].filter((el) => ['sum', 'mer'].includes(el.textContent));
|
|
91
|
+
options.assert.deepEqual(lyrics.map((el) => el.textContent), ['sum', 'mer'], 'Syllables stay in event order');
|
|
92
|
+
options.assert.deepEqual(lyrics.map((el) => Number(el.getAttribute('y'))), [125, 125], 'Authored common baseline');
|
|
93
|
+
root.dataset.measurement = JSON.stringify({
|
|
94
|
+
lyrics: lyrics.map((el) => {
|
|
95
|
+
const { x, y, width, height } = el.getBBox();
|
|
96
|
+
return { id: el.textContent, group: 'verse', x, y, width, height };
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
VF.Test.runTests('Two head shapes at one onset', (options) => {
|
|
101
|
+
const factory = VF.Test.makeFactory(options, 230, 150);
|
|
102
|
+
const score = factory.EasyScore();
|
|
103
|
+
const note = score.make.note({ keys: ['f/4', 'g/5/x2'], duration: 'w' });
|
|
104
|
+
factory
|
|
105
|
+
.System({ width: 210 })
|
|
106
|
+
.addStave({ voices: [score.voice([note])] })
|
|
107
|
+
.addClef('percussion');
|
|
108
|
+
factory.draw();
|
|
109
|
+
options.assert.equal(new Set(note.noteHeads.map((head) => head.getText())).size, 2, 'Distinct typed head glyphs');
|
|
110
|
+
options.assert.notOk(score.parseNotation('(F4 G5/m)/8, G5/m').success, 'The legacy compact spelling is rejected');
|
|
111
|
+
const foreign = VF.EasyScore.create({ renderer: { elementId: null } }).notes('C4/w')[0];
|
|
112
|
+
options.assert.throws(() => score.make.curve({ from: note, to: foreign }), /owner|factory|belong/i, 'A span cannot resolve an endpoint in another score');
|
|
113
|
+
const signs = score.notes('C#4/q, Cb4/q').map((n) => n.getModifiers()[0].type);
|
|
114
|
+
options.assert.deepEqual(signs, ['#', 'b'], 'Spelled probe preserves the requested accidental sequence');
|
|
115
|
+
options.assert.notDeepEqual(signs, ['#', '#'], 'Substituting sharp for flat is detected');
|
|
116
|
+
});
|
|
117
|
+
VF.Test.runTests('Horizontal beams inside the staff', (options) => {
|
|
118
|
+
const factory = VF.Test.makeFactory(options, 380, 145);
|
|
119
|
+
const score = factory.EasyScore();
|
|
120
|
+
const notes = score.notes('C4/8, C4, D4, D4, E4, E4, F4, F4', { stem: 'up' });
|
|
121
|
+
const stave = factory
|
|
122
|
+
.System({ width: 350 })
|
|
123
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
124
|
+
.addClef('treble');
|
|
125
|
+
const beams = [0, 2, 4, 6].map((first) => factory.Beam({ notes: notes.slice(first, first + 2) }));
|
|
126
|
+
factory.draw();
|
|
127
|
+
const lines = [0, 1, 2, 3, 4].map((i) => stave.getYForLine(i));
|
|
128
|
+
const tips = beams.map((beam) => beam.getNotes()[0].getStemExtents().topY);
|
|
129
|
+
options.assert.ok(beams.every((beam) => Math.abs(beam.slope) < 1e-6), 'Repeated pitches have horizontal beams');
|
|
130
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ lines, tips });
|
|
131
|
+
});
|
|
132
|
+
QUnit.module('M1 studies');
|
|
133
|
+
VF.Test.runTests('Notehead between beamed attacks', (options) => {
|
|
134
|
+
const factory = VF.Test.makeFactory(options, 400, 140);
|
|
135
|
+
const score = factory.EasyScore();
|
|
136
|
+
const notes = score.notes('C4/8, C4/8', { stem: 'up' });
|
|
137
|
+
const other = factory.StaveNote({ keys: ['c/5'], duration: '16', stemDirection: 1 });
|
|
138
|
+
const voices = [notes, [factory.GhostNote('16'), other, factory.GhostNote('8')]];
|
|
139
|
+
const beam = factory.Beam({ notes });
|
|
140
|
+
factory
|
|
141
|
+
.System({ x: 10, y: 0, width: 370 })
|
|
142
|
+
.addStave({ voices: voices.map((v) => score.voice(v, { mode: 'soft' })) });
|
|
143
|
+
factory.draw();
|
|
144
|
+
const headBottom = other.getYs()[0] + other.noteHeads[0].getTextMetrics().actualBoundingBoxDescent;
|
|
145
|
+
const clearancePx = beam.getBeamYToDraw() - headBottom;
|
|
146
|
+
options.assert.ok(Number.isFinite(clearancePx), 'Measured clearance from head to horizontal beam');
|
|
147
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ clearancePx });
|
|
148
|
+
});
|
|
149
|
+
VF.Test.runTests('Sloped beam after narrowing a retained system', (options) => {
|
|
150
|
+
const factory = VF.Test.makeFactory(options, 540, 140);
|
|
151
|
+
const score = factory.EasyScore();
|
|
152
|
+
const notes = score.notes('A4/8, B4, C4, D4', { stem: 'up' });
|
|
153
|
+
const beam = factory.Beam({ notes });
|
|
154
|
+
const system = factory.System({ x: 10, y: 0, width: 520 });
|
|
155
|
+
system.addStave({ voices: [score.voice(notes, { mode: 'soft' })] });
|
|
156
|
+
factory.draw({ retain: true });
|
|
157
|
+
factory.getContext().clear();
|
|
158
|
+
system.setWidth(300);
|
|
159
|
+
factory.draw({ retain: true });
|
|
160
|
+
const stemTipErrorsPx = notes.map((note) => {
|
|
161
|
+
const beamY = beam.getBeamYToDraw() + beam.slope * (note.getStemX() - notes[0].getStemX());
|
|
162
|
+
return note.getStemExtents().topY - beamY;
|
|
163
|
+
});
|
|
164
|
+
options.assert.ok(stemTipErrorsPx.every(Number.isFinite), 'Measured each stem tip against the refitted line');
|
|
165
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ stemTipErrorsPx });
|
|
166
|
+
});
|
|
167
|
+
QUnit.module('M2 studies');
|
|
168
|
+
VF.Test.runTests('Four close voices and an unequal onset', (options) => {
|
|
169
|
+
const factory = VF.Test.makeFactory(options, 420, 155);
|
|
170
|
+
const score = factory.EasyScore();
|
|
171
|
+
const voices = ['F5/q, G5/q', 'E5/8, C5/8, D5/q', 'D5/q, E5/q', 'C5/q, B4/q'].map((input, i) => score.voice(score.notes(input, { stem: i % 2 ? 'down' : 'up' }), { mode: 'soft' }));
|
|
172
|
+
factory.System({ width: 390 }).addStave({ voices }).addClef('treble');
|
|
173
|
+
factory.draw();
|
|
174
|
+
const x = voices.map((v) => v.getTickables()[0].getNoteHeadBeginX());
|
|
175
|
+
options.assert.ok(x.every(Number.isFinite), 'Every voice has a head position');
|
|
176
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ x });
|
|
177
|
+
});
|
|
178
|
+
VF.Test.runTests('Beam contour and staff contact', (options) => {
|
|
179
|
+
const factory = VF.Test.makeFactory(options, 550, 265);
|
|
180
|
+
const score = factory.EasyScore();
|
|
181
|
+
const beams = [];
|
|
182
|
+
for (const [width, y] of [
|
|
183
|
+
[300, 10],
|
|
184
|
+
[520, 135],
|
|
185
|
+
]) {
|
|
186
|
+
const notes = score.notes('G4/8, A4, B4, C4, E4, E4, F4, F4', { stem: 'up' });
|
|
187
|
+
factory
|
|
188
|
+
.System({ width, y })
|
|
189
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
190
|
+
.addClef('treble');
|
|
191
|
+
for (const group of [notes.slice(0, 4), notes.slice(4, 6), notes.slice(6)]) {
|
|
192
|
+
const beam = factory.Beam({ notes: group });
|
|
193
|
+
beam.renderOptions.contourSlope = true;
|
|
194
|
+
beams.push(beam);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
factory.draw();
|
|
198
|
+
const slopes = beams.map((beam) => beam.slope);
|
|
199
|
+
options.assert.ok(slopes.every(Number.isFinite), 'Every beam has a finite slope');
|
|
200
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({ slopes });
|
|
201
|
+
});
|
|
202
|
+
VF.Test.runTests('Long fall and delayed turn after redraw', (options) => {
|
|
203
|
+
const factory = VF.Test.makeFactory(options, 440, 175);
|
|
204
|
+
const score = factory.EasyScore();
|
|
205
|
+
const notes = score.notes('G4/q, A4/q, B4/h');
|
|
206
|
+
notes[0].addModifier(new VF.Ornament('fallLong'), 0);
|
|
207
|
+
notes[1].addModifier(new VF.Ornament('turn').setDelayed(true).setUpperAccidental('#'), 0);
|
|
208
|
+
const system = factory.System({ width: 410, y: 20 });
|
|
209
|
+
system.addStave({ voices: [score.voice(notes)] }).addClef('treble');
|
|
210
|
+
factory.draw({ retain: true });
|
|
211
|
+
factory.getContext().clear();
|
|
212
|
+
system.setWidth(320);
|
|
213
|
+
factory.draw({ retain: true });
|
|
214
|
+
options.assert.ok(notes.every((n) => n.isRendered()), 'Retained notes rendered');
|
|
215
|
+
});
|
|
216
|
+
VF.Test.runTests('Grace groups on both sides of a host', (options) => {
|
|
217
|
+
const f = VF.Test.makeFactory(options, 515, 135), es = f.EasyScore();
|
|
218
|
+
const notes = es.notes('E5/q, F5/q, G5/h');
|
|
219
|
+
for (const [side, keys] of [
|
|
220
|
+
[VF.Modifier.Position.LEFT, ['d/5']],
|
|
221
|
+
[VF.Modifier.Position.RIGHT, ['g/5', 'f/5']],
|
|
222
|
+
]) {
|
|
223
|
+
const group = f
|
|
224
|
+
.GraceNoteGroup({
|
|
225
|
+
notes: keys.map((key) => f.GraceNote({ keys: [key], duration: '16', slash: true })),
|
|
226
|
+
slur: true,
|
|
227
|
+
})
|
|
228
|
+
.setPosition(side);
|
|
229
|
+
if (keys.length > 1)
|
|
230
|
+
group.beamNotes();
|
|
231
|
+
notes[0].addModifier(group, 0);
|
|
232
|
+
}
|
|
233
|
+
f.System({ width: 490 })
|
|
234
|
+
.addStave({ voices: [es.voice(notes)] })
|
|
235
|
+
.addClef('treble');
|
|
236
|
+
f.draw();
|
|
237
|
+
options.assert.equal(notes[0].getModifiers().length, 2, 'Both grace groups remain attached to the first note');
|
|
238
|
+
});
|
|
239
|
+
VF.Test.runTests('Tuplet over a turn with auxiliary signs', (options) => {
|
|
240
|
+
const f = VF.Test.makeFactory(options, 515, 170), es = f.EasyScore();
|
|
241
|
+
const notes = es.notes('G4/8, A4/8, B4/8, C5/q');
|
|
242
|
+
notes[1].addModifier(new VF.Ornament('turn').setPosition(VF.Modifier.Position.ABOVE).setUpperAccidental('#').setLowerAccidental('b'), 0);
|
|
243
|
+
const tuplet = f.Tuplet({ notes: notes.slice(0, 3), options: { bracketed: true } });
|
|
244
|
+
f.System({ width: 490, y: 60 })
|
|
245
|
+
.addStave({ voices: [es.voice(notes, { mode: 'soft' })] })
|
|
246
|
+
.addClef('treble');
|
|
247
|
+
f.draw();
|
|
248
|
+
options.assert.ok(Number.isFinite(tuplet.getYPosition()), 'Bracket has a resolved staff position');
|
|
249
|
+
});
|
|
250
|
+
VF.Test.runTests('Measured spacing with a short final attack', (options) => {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
const f = VF.Test.makeFactory(options, 515, 160), es = f.EasyScore();
|
|
253
|
+
const notes = es.notes('E4/h, A4/q, F#4/8, G4/16, A4/32, B4/64, C5/64');
|
|
254
|
+
const group = f
|
|
255
|
+
.GraceNoteGroup({ notes: ['f/4', 'g/4'].map((key) => f.GraceNote({ keys: [key], duration: '16' })) })
|
|
256
|
+
.beamNotes();
|
|
257
|
+
notes[1].addModifier(group, 0);
|
|
258
|
+
notes[2].addModifier(new VF.ChordSymbol().addText('Dmaj7'), 0);
|
|
259
|
+
const details = { spacing: { mode: 'optical' } };
|
|
260
|
+
try {
|
|
261
|
+
new VF.Formatter(details);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (error.code !== 'BadArgument')
|
|
265
|
+
throw error;
|
|
266
|
+
delete details.spacing;
|
|
267
|
+
}
|
|
268
|
+
f.System({ width: 490, y: 20, details })
|
|
269
|
+
.addStave({ voices: [es.voice(notes)] })
|
|
270
|
+
.addClef('treble');
|
|
271
|
+
f.draw();
|
|
272
|
+
const x = notes.map((n) => n.getNoteHeadBeginX());
|
|
273
|
+
options.assert.ok(x.every((value, i) => !i || value > x[i - 1]), 'Each successive attack advances');
|
|
274
|
+
document.getElementById(options.elementId).dataset.measurement = JSON.stringify({
|
|
275
|
+
mode: (_b = (_a = details.spacing) === null || _a === void 0 ? void 0 : _a.mode) !== null && _b !== void 0 ? _b : 'default',
|
|
276
|
+
x,
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
@@ -395,7 +395,16 @@ function alignedMixedElements(options) {
|
|
|
395
395
|
stave2.setContext(context).drawWithStyle();
|
|
396
396
|
tuplet.setContext(context).drawWithStyle();
|
|
397
397
|
tuplet2.setContext(context).drawWithStyle();
|
|
398
|
-
|
|
398
|
+
const outerText = (note) => note
|
|
399
|
+
.getModifiers()
|
|
400
|
+
.find((m) => m.getText() === 'ttt')
|
|
401
|
+
.getBoundingBox();
|
|
402
|
+
const below = outerText(notes[0]);
|
|
403
|
+
const lowerGap = tuplet.getYPosition() - (below.getY() + below.getH());
|
|
404
|
+
const upperGap = outerText(notes2[1]).getY() - tuplet2.getYPosition();
|
|
405
|
+
const space = stave.getSpacingBetweenLines();
|
|
406
|
+
options.assert.ok(lowerGap >= space && lowerGap < 2 * space, 'Lower bracket clears the text');
|
|
407
|
+
options.assert.ok(Math.abs(upperGap - lowerGap) <= space / 2, 'Both brackets have comparable clearance');
|
|
399
408
|
}
|
|
400
409
|
function justifyStaveNotes(options) {
|
|
401
410
|
const f = VexFlowTests.makeFactory(options, 520, 280);
|
package/build/esm/tests/index.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { isExcepted } from '../../tools/audit-dependencies.mjs';
|
|
4
|
+
function fixture() {
|
|
5
|
+
const report = {
|
|
6
|
+
auditReportVersion: 2,
|
|
7
|
+
metadata: { vulnerabilities: { total: 2 } },
|
|
8
|
+
vulnerabilities: {
|
|
9
|
+
tool: { nodes: ['node_modules/tool'], via: ['picomatch'] },
|
|
10
|
+
picomatch: {
|
|
11
|
+
nodes: ['node_modules/picomatch'],
|
|
12
|
+
via: [{ url: 'https://github.com/advisories/GHSA-fc5q-39xc-vjpf' }],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const packages = {
|
|
17
|
+
'node_modules/tool': { dev: true },
|
|
18
|
+
'node_modules/picomatch': { dev: true, version: '4.0.5' },
|
|
19
|
+
};
|
|
20
|
+
return { report, packages };
|
|
21
|
+
}
|
|
22
|
+
const reviewDate = Date.UTC(2026, 10, 18);
|
|
23
|
+
test('accepts the reviewed advisory and its inherited findings only during the review period', () => {
|
|
24
|
+
const { report, packages } = fixture();
|
|
25
|
+
assert.ok(isExcepted(report, packages, reviewDate));
|
|
26
|
+
assert.equal(isExcepted(report, packages, Date.UTC(2026, 11, 18)), false);
|
|
27
|
+
});
|
|
28
|
+
test('rejects changes in scope, new advisories, and incomplete audit results', () => {
|
|
29
|
+
for (const change of [
|
|
30
|
+
({ packages }) => delete packages['node_modules/picomatch'].dev,
|
|
31
|
+
({ packages }) => (packages['node_modules/picomatch'].version = '4.0.6'),
|
|
32
|
+
({ report }) => (report.vulnerabilities.picomatch.fixAvailable = true),
|
|
33
|
+
({ report }) => report.vulnerabilities.picomatch.via.push({ url: 'another advisory' }),
|
|
34
|
+
({ report }) => report.vulnerabilities.tool.via.push({ url: 'another advisory' }),
|
|
35
|
+
({ report }) => (report.vulnerabilities.tool.via = ['missing']),
|
|
36
|
+
({ report }) => (report.error = { summary: 'audit unavailable' }),
|
|
37
|
+
]) {
|
|
38
|
+
const data = fixture();
|
|
39
|
+
change(data);
|
|
40
|
+
assert.equal(isExcepted(data.report, data.packages, reviewDate), false);
|
|
41
|
+
}
|
|
42
|
+
});
|