vexflow 5.1.2 → 5.2.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 +7 -6
- 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 +2633 -415
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +2478 -382
- 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 +3 -0
- package/build/esm/src/articulation.js +27 -14
- package/build/esm/src/beam.js +12 -2
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/clefnote.js +5 -1
- package/build/esm/src/dot.js +1 -1
- package/build/esm/src/easyscore/composition.js +297 -0
- package/build/esm/src/easyscore/elementindex.js +81 -0
- package/build/esm/src/easyscore/elements.js +324 -0
- package/build/esm/src/easyscore/policies.js +69 -0
- package/build/esm/src/easyscore/rhythm.js +42 -0
- package/build/esm/src/easyscore.js +448 -26
- package/build/esm/src/element.js +13 -2
- package/build/esm/src/factory.js +256 -60
- package/build/esm/src/formatter.js +32 -4
- package/build/esm/src/keysignature.js +9 -1
- package/build/esm/src/keysignote.js +2 -2
- package/build/esm/src/note.js +5 -0
- package/build/esm/src/parenthesis.js +1 -1
- package/build/esm/src/parser.js +6 -1
- package/build/esm/src/proportionalformatter.js +186 -0
- package/build/esm/src/registry.js +27 -0
- package/build/esm/src/sheet.js +20 -3
- package/build/esm/src/stave.js +9 -2
- package/build/esm/src/stavenote.js +12 -12
- package/build/esm/src/stemmablenote.js +6 -1
- package/build/esm/src/tickable.js +5 -0
- package/build/esm/src/tuplet.js +3 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +2 -1
- package/build/esm/tests/beam_tests.js +35 -0
- package/build/esm/tests/easyscore_tests.js +40 -0
- package/build/esm/tests/easyscore_types.js +65 -0
- package/build/esm/tests/formatter_tests.js +41 -0
- package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
- package/build/esm/tests/node/easyscore-tests.mjs +953 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -0
- package/build/esm/tools/easyscore-api-audit.mjs +58 -0
- package/build/esm/tools/easyscore-composition.mjs +62 -0
- package/build/esm/tools/easyscore-example.mjs +16 -0
- package/build/esm/tools/easyscore-families.mjs +61 -0
- package/build/esm/tools/easyscore-references-example.mjs +26 -0
- package/build/esm/tools/easyscore-rhythm.mjs +58 -0
- package/build/esm/tools/easyscore-structure.mjs +88 -0
- package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
- package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
- package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
- package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
- package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
- package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
- package/build/esm/tools/explorer/catalog.mjs +14 -0
- package/build/types/src/accidental.d.ts +2 -0
- package/build/types/src/articulation.d.ts +6 -0
- package/build/types/src/beam.d.ts +2 -0
- package/build/types/src/clef.d.ts +2 -0
- package/build/types/src/easyscore/composition.d.ts +107 -0
- package/build/types/src/easyscore/elementindex.d.ts +30 -0
- package/build/types/src/easyscore/elements.d.ts +156 -0
- package/build/types/src/easyscore/policies.d.ts +12 -0
- package/build/types/src/easyscore/rhythm.d.ts +9 -0
- package/build/types/src/easyscore.d.ts +153 -11
- package/build/types/src/element.d.ts +5 -1
- package/build/types/src/factory.d.ts +91 -8
- package/build/types/src/formatter.d.ts +7 -1
- package/build/types/src/keysignature.d.ts +3 -0
- package/build/types/src/keysignote.d.ts +1 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/parser.d.ts +5 -0
- package/build/types/src/proportionalformatter.d.ts +30 -0
- package/build/types/src/registry.d.ts +4 -0
- package/build/types/src/stave.d.ts +2 -0
- package/build/types/src/stavenote.d.ts +1 -1
- package/build/types/src/stemmablenote.d.ts +6 -1
- package/build/types/src/tickable.d.ts +2 -0
- package/build/types/src/vexflow.d.ts +2 -1
- package/changelog/CHANGELOG.md +35 -0
- package/package.json +7 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
2
2
|
import { Articulation } from '../src/articulation.js';
|
|
3
3
|
import { EasyScore } from '../src/easyscore.js';
|
|
4
|
+
import { Factory } from '../src/factory.js';
|
|
4
5
|
import { FretHandFinger } from '../src/frethandfinger.js';
|
|
5
6
|
import { Modifier } from '../src/modifier.js';
|
|
6
7
|
import { Parenthesis } from '../src/parenthesis.js';
|
|
@@ -17,6 +18,7 @@ const EasyScoreTests = {
|
|
|
17
18
|
QUnit.test('Dots', dots);
|
|
18
19
|
QUnit.test('Types', types);
|
|
19
20
|
QUnit.test('Options', options);
|
|
21
|
+
QUnit.test('Automatic beam stem policy', beamStemPolicy);
|
|
20
22
|
const run = VexFlowTests.runTests;
|
|
21
23
|
run('Draw Basic', drawBasicTest);
|
|
22
24
|
run('Draw Different KeySignature', drawDiffKeysig);
|
|
@@ -486,3 +488,41 @@ function keys(options) {
|
|
|
486
488
|
}
|
|
487
489
|
VexFlowTests.register(EasyScoreTests);
|
|
488
490
|
export { EasyScoreTests };
|
|
491
|
+
function beamStemPolicy(assert) {
|
|
492
|
+
const factory = new Factory({ renderer: { elementId: null, width: 500, height: 200 } });
|
|
493
|
+
const score = factory.EasyScore();
|
|
494
|
+
const phrase = 'C4/8, D4, E4, F4, G4, A4, B4';
|
|
495
|
+
const directions = (notes) => notes.map((note) => note.getStemDirection());
|
|
496
|
+
const automatic = score.notes(phrase);
|
|
497
|
+
assert.equal(new Set(directions(automatic)).size, 2, 'Unbeamed phrase crosses stem boundary');
|
|
498
|
+
score.beam(automatic);
|
|
499
|
+
assert.ok(automatic.every((note) => note.getStemDirection() === Stem.UP), 'Group chooses up stems');
|
|
500
|
+
assert.ok(automatic.every((note) => note.isAutoStem()), 'Beaming retains automatic policy');
|
|
501
|
+
const extended = [...automatic, ...score.notes('C6/8, C6, C6, C6, C6, C6, C6, C6')];
|
|
502
|
+
score.beam(extended);
|
|
503
|
+
assert.ok(extended.every((note) => note.getStemDirection() === Stem.DOWN), 'Regrouping recalculates direction');
|
|
504
|
+
const explicit = score.notes(phrase, { stem: 'down' });
|
|
505
|
+
score.beam(explicit);
|
|
506
|
+
assert.ok(explicit.every((note) => note.getStemDirection() === Stem.DOWN && !note.isAutoStem()), 'Explicit voice stays down');
|
|
507
|
+
score.beam(explicit, { autoStem: true });
|
|
508
|
+
assert.ok(explicit.every((note) => note.getStemDirection() === Stem.UP), 'Explicit beam override selects group direction');
|
|
509
|
+
const pinned = score.notes('C4/8, D4[stem="down"], E4');
|
|
510
|
+
score.beam(pinned);
|
|
511
|
+
assert.deepEqual(directions(pinned), [Stem.DOWN, Stem.DOWN, Stem.DOWN], 'Automatic stems follow one explicit pitch');
|
|
512
|
+
assert.notOk(pinned[1].isAutoStem(), 'Per-note override stays explicit');
|
|
513
|
+
const manual = score.notes('C4/8, D4, E4');
|
|
514
|
+
manual[0].setStemDirection(Stem.DOWN);
|
|
515
|
+
score.beam(manual);
|
|
516
|
+
assert.deepEqual(directions(manual), [Stem.DOWN, Stem.DOWN, Stem.DOWN], 'Setter opts out of automatic direction');
|
|
517
|
+
const mixed = score.notes('C4/8[stem="up"], B4[stem="down"], D4');
|
|
518
|
+
const before = directions(mixed);
|
|
519
|
+
score.beam(mixed);
|
|
520
|
+
assert.deepEqual(directions(mixed), before, 'Conflicting explicit directions remain mixed');
|
|
521
|
+
const preserved = score.notes(phrase);
|
|
522
|
+
const individual = directions(preserved);
|
|
523
|
+
score.beam(preserved, { autoStem: false });
|
|
524
|
+
assert.deepEqual(directions(preserved), individual, 'Explicit false preserves per-note automatic directions');
|
|
525
|
+
const lowLevel = score.notes(phrase);
|
|
526
|
+
factory.Beam({ notes: lowLevel });
|
|
527
|
+
assert.deepEqual(directions(lowLevel), individual, 'Factory keeps its low-level direction-preserving default');
|
|
528
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { Annotation, EasyScore, Fraction } from '../src/index.js';
|
|
11
|
+
export function easyScoreTypes() {
|
|
12
|
+
const score = EasyScore.create({ renderer: { elementId: 'score', width: 500, height: 240 } });
|
|
13
|
+
score.autoBeam(score.notes('C4/8, D4'), { groups: [new Fraction(2, 8)], autoStem: false });
|
|
14
|
+
score.make.tuplet({ notes: score.notes('C4/8, D4, E4'), options: { numNotes: 3, notesOccupied: 2 } });
|
|
15
|
+
score.make.hairpin({ type: 1 });
|
|
16
|
+
const composed = score.compose({
|
|
17
|
+
staves: [
|
|
18
|
+
{ id: 'staff', measures: [{ voices: [{ notes: [{ note: { keys: ['c/4'], duration: 'w' }, id: 'whole' }] }] }] },
|
|
19
|
+
],
|
|
20
|
+
spans: [{ kind: 'tie', from: 'whole' }],
|
|
21
|
+
});
|
|
22
|
+
composed.sheet.setWidth(400);
|
|
23
|
+
score.withDefaults({ clef: 'bass' }, (s) => s.notes('C3/w'));
|
|
24
|
+
score.compose({ staves: [], accidentals: 'automatic' });
|
|
25
|
+
score.withDefaults({}, () => __awaiter(this, void 0, void 0, function* () { return 1; }));
|
|
26
|
+
const tab = score.make.tabNote({ positions: [{ str: 2, fret: 'X' }], duration: 'q' }, true);
|
|
27
|
+
score.make.tabTie({ firstNote: tab }, 'H');
|
|
28
|
+
score.make.tabTie({ firstNote: score.make.note({ keys: ['c/4'], duration: 'q' }) });
|
|
29
|
+
score.attachToStave(score.make.tabStave(), score.make.clef('tab'));
|
|
30
|
+
score.make.tabNote({ positions: [{ str: 'one', fret: 3 }], duration: 'q' });
|
|
31
|
+
score.attach(tab, score.make.clef('tab'));
|
|
32
|
+
const nativeNote = score.make.note({ keys: ['c/4/x'], duration: 'q', autoStem: true });
|
|
33
|
+
score.sequence(['C4/q', nativeNote, { keys: ['d/4'], duration: 'q' }]);
|
|
34
|
+
score.make.graceNoteGroup({ notes: [score.make.graceNote({ keys: ['d/4'], duration: '16', slash: true })] });
|
|
35
|
+
score.make.articulation({ type: 'fermata' }).setBetweenLines(false);
|
|
36
|
+
score.make.ornament('tr', { upperAccidental: '#' });
|
|
37
|
+
score.make.tremolo(3);
|
|
38
|
+
score.make.note({ keys: ['c/4'] });
|
|
39
|
+
score.make.tremolo('three');
|
|
40
|
+
const notes = score.notes('C4/h, C4', { octaveShift: 1, durationOverride: new Fraction(1, 2) });
|
|
41
|
+
const annotation = score.make.annotation({ text: 'dolce' });
|
|
42
|
+
score.attach(notes[0], annotation);
|
|
43
|
+
const tie = score.make.tie({ from: notes[0], to: notes[1] });
|
|
44
|
+
tie.setDirection(1);
|
|
45
|
+
const adopted = score.adopt(new Annotation('extension'), 'modifier');
|
|
46
|
+
const resolved = score.getElement(adopted.getAttribute('id'));
|
|
47
|
+
const named = score.getNote(notes[0].getAttribute('id'));
|
|
48
|
+
const source = score.getSource(named);
|
|
49
|
+
if (resolved && source)
|
|
50
|
+
EasyScore.getSource(resolved);
|
|
51
|
+
score.make.tie({ from: named });
|
|
52
|
+
score.adopt(annotation, 'automatic');
|
|
53
|
+
score.make.tie({ from: score.getElement('note') });
|
|
54
|
+
const voice = score.voice(notes, { time: { numBeats: 4, beatValue: 4 }, mode: 'soft', softmaxFactor: 1 });
|
|
55
|
+
const system = score.system();
|
|
56
|
+
score.sheet({ width: 600 }).addSystem();
|
|
57
|
+
const built = score.build((builder) => builder.make.annotation({ text: 'batch' }));
|
|
58
|
+
built.setText('native');
|
|
59
|
+
score.build(() => __awaiter(this, void 0, void 0, function* () { return 1; }));
|
|
60
|
+
system.addStave({ voices: [voice] });
|
|
61
|
+
score.notes('C4/q', { octaveShift: 'one' });
|
|
62
|
+
score.voice(notes, { mode: 'relaxed' });
|
|
63
|
+
score.make.annotation({ text: 123 });
|
|
64
|
+
score.make.tie({ from: annotation });
|
|
65
|
+
}
|
|
@@ -64,6 +64,7 @@ const FormatterTests = {
|
|
|
64
64
|
run('Notes with Tab', notesWithTab);
|
|
65
65
|
run('Multiple Staves - Justified', multiStaves, { debug: true });
|
|
66
66
|
run('Softmax', softMax);
|
|
67
|
+
run('Strict proportional spacing', strictProportionalSpacing);
|
|
67
68
|
run('Mixtime', mixTime);
|
|
68
69
|
run('Tight', tightNotes1);
|
|
69
70
|
run('Tight 2', tightNotes2);
|
|
@@ -757,3 +758,43 @@ function annotations(options) {
|
|
|
757
758
|
}
|
|
758
759
|
VexFlowTests.register(FormatterTests);
|
|
759
760
|
export { FormatterTests };
|
|
761
|
+
function strictProportionalSpacing(options) {
|
|
762
|
+
const f = VexFlowTests.makeFactory(options, 850, 540);
|
|
763
|
+
const score = f.EasyScore();
|
|
764
|
+
const notes = score.notes('C5/16, D5, E5, F5, G5/8, A5, B5/q, C6', { stem: 'up' });
|
|
765
|
+
score.beam(notes.slice(0, 4));
|
|
766
|
+
score.beam(notes.slice(4, 6));
|
|
767
|
+
const quarters = score.notes('C4/q, E4, G4, E4', { stem: 'down' });
|
|
768
|
+
const system = f.System({
|
|
769
|
+
x: 25,
|
|
770
|
+
y: 40,
|
|
771
|
+
autoWidth: true,
|
|
772
|
+
formatIterations: 4,
|
|
773
|
+
details: { spacing: { mode: 'proportional', pixelsPerQuarter: 140 } },
|
|
774
|
+
});
|
|
775
|
+
system.addStave({ voices: [score.voice(notes), score.voice(quarters)] }).addClef('treble');
|
|
776
|
+
const thirds = score.notes('C5/8, D5, E5, F5/q, G5/h');
|
|
777
|
+
const sevenths = score.notes('C4/8, D4, E4, F4, G4, A4, B4, C5/h');
|
|
778
|
+
score.tuplet(thirds.slice(0, 3), { numNotes: 3, notesOccupied: 2 });
|
|
779
|
+
score.tuplet(sevenths.slice(0, 7), { numNotes: 7, notesOccupied: 4 });
|
|
780
|
+
score.beam(thirds.slice(0, 3));
|
|
781
|
+
score.beam(sevenths.slice(0, 7));
|
|
782
|
+
system.addStave({ voices: [score.voice(thirds)] }).addClef('treble');
|
|
783
|
+
system.addStave({ voices: [score.voice(sevenths)] }).addClef('treble');
|
|
784
|
+
f.draw();
|
|
785
|
+
const close = (a, b, label) => options.assert.ok(Math.abs(a - b) < 1e-7, label);
|
|
786
|
+
const origin = notes[0].getAbsoluteX();
|
|
787
|
+
[0, 35, 70, 105, 140, 210, 280, 420].forEach((offset, i) => close(notes[i].getAbsoluteX(), origin + offset, 'Fixed onset'));
|
|
788
|
+
quarters.forEach((note, i) => close(note.getAbsoluteX(), origin + i * 140, 'Voices align'));
|
|
789
|
+
close(thirds[4].getAbsoluteX(), sevenths[7].getAbsoluteX(), 'Rational endpoints align');
|
|
790
|
+
sevenths.slice(0, 7).forEach((note) => {
|
|
791
|
+
options.assert.equal(note.getStemDirection(), note.getBeam().getStemDirection(), 'Tuplet stem agrees with beam');
|
|
792
|
+
});
|
|
793
|
+
const ctx = f.getContext();
|
|
794
|
+
ctx.save().setStrokeStyle('#b6c4c0').setLineWidth(0.5);
|
|
795
|
+
for (let beat = 0; beat <= 4; beat++) {
|
|
796
|
+
const x = origin + beat * 140;
|
|
797
|
+
ctx.beginPath().moveTo(x, 55).lineTo(x, 505).stroke();
|
|
798
|
+
}
|
|
799
|
+
ctx.restore();
|
|
800
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
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 { readFileSync } from 'node:fs';
|
|
12
|
+
import test from 'node:test';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import puppeteer from 'puppeteer';
|
|
15
|
+
import { createEasyScoreExample } from '../../tools/easyscore-example.mjs';
|
|
16
|
+
import { createEasyScoreReferencesExample } from '../../tools/easyscore-references-example.mjs';
|
|
17
|
+
const root = fileURLToPath(new URL('../../', import.meta.url));
|
|
18
|
+
const guide = readFileSync(`${root}docs/easyscore.md`, 'utf8').match(/```js\n([\s\S]*?)```/)[1];
|
|
19
|
+
test('first EasyScore example matches native rendering', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
21
|
+
try {
|
|
22
|
+
const page = yield browser.newPage();
|
|
23
|
+
yield page.setViewport({ width: 500, height: 240, deviceScaleFactor: 1 });
|
|
24
|
+
yield page.setContent('<style>body { margin: 0; background: white; }</style><div id="host"></div>');
|
|
25
|
+
yield page.addScriptTag({ path: `${root}build/cjs/vexflow-debug.js` });
|
|
26
|
+
yield page.evaluate(`window.createEasyScoreExample = ${createEasyScoreExample.toString()}`);
|
|
27
|
+
yield page.evaluate((source) => {
|
|
28
|
+
window.createGuideExample = new Function('VF', source + '\nreturn { score, notes, annotation, tie, voice, system };');
|
|
29
|
+
}, guide);
|
|
30
|
+
for (const font of ['Bravura', 'Petaluma']) {
|
|
31
|
+
for (const backend of ['svg', 'canvas']) {
|
|
32
|
+
yield t.test(`${font} ${backend}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const frames = [];
|
|
34
|
+
const metrics = [];
|
|
35
|
+
for (const native of ['native', 'shared', 'guide']) {
|
|
36
|
+
metrics.push(yield page.evaluate((_a) => __awaiter(void 0, [_a], void 0, function* ({ font, backend, native }) {
|
|
37
|
+
const VF = VexFlow;
|
|
38
|
+
VF.setFonts(font, font === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
39
|
+
yield document.fonts.ready;
|
|
40
|
+
const host = document.getElementById('host');
|
|
41
|
+
host.replaceChildren();
|
|
42
|
+
const target = host.appendChild(document.createElement(backend === 'canvas' ? 'canvas' : 'div'));
|
|
43
|
+
target.id = 'score';
|
|
44
|
+
const renderer = { elementId: 'score', width: 500, height: 240 };
|
|
45
|
+
let example;
|
|
46
|
+
if (native === 'native') {
|
|
47
|
+
const factory = new VF.Factory({ renderer });
|
|
48
|
+
factory.setStyle({ fillStyle: '#24312c', strokeStyle: '#24312c' });
|
|
49
|
+
const notes = [
|
|
50
|
+
['c/4', 'e/4', 'g/4'],
|
|
51
|
+
['c/4', 'f/4', 'a/4'],
|
|
52
|
+
].map((keys) => factory.StaveNote({ keys, duration: 'h', clef: 'treble', autoStem: true }));
|
|
53
|
+
const annotation = factory.Annotation({ text: 'dolce', vJustify: 'top' });
|
|
54
|
+
notes[0].addModifier(annotation, 0);
|
|
55
|
+
const tie = factory.StaveTie({ from: notes[0], to: notes[1], firstIndexes: [0], lastIndexes: [0] });
|
|
56
|
+
const voice = factory.Voice({ time: '4/4' }).addTickables(notes);
|
|
57
|
+
const system = factory.System({ x: 20, y: 70, width: 460 });
|
|
58
|
+
system
|
|
59
|
+
.addStave({ voices: [voice] })
|
|
60
|
+
.addClef('treble')
|
|
61
|
+
.addTimeSignature('4/4');
|
|
62
|
+
factory.draw({ retain: true });
|
|
63
|
+
example = { notes, annotation, tie, voice, system };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
example =
|
|
67
|
+
native === 'shared' ? window.createEasyScoreExample(VF, renderer) : window.createGuideExample(VF);
|
|
68
|
+
window.example = example;
|
|
69
|
+
try {
|
|
70
|
+
example.score.notes('C4/q, invalid');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!(error instanceof VF.EasyScoreError))
|
|
74
|
+
throw new Error('Browser error class is not exported');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return example.notes.map((note) => ({
|
|
78
|
+
x: note.getAbsoluteX(),
|
|
79
|
+
ys: note.getYs(),
|
|
80
|
+
stem: note.getStemDirection(),
|
|
81
|
+
ticks: note.getTicks().value(),
|
|
82
|
+
bounds: Object.assign({}, note.getBoundingBox()),
|
|
83
|
+
}));
|
|
84
|
+
}), { font, backend, native }));
|
|
85
|
+
frames.push(yield page.screenshot({ omitBackground: false }));
|
|
86
|
+
}
|
|
87
|
+
assert.deepEqual(metrics[1], metrics[0], 'native and EasyScore geometry match');
|
|
88
|
+
assert.deepEqual(metrics[2], metrics[0], 'guide geometry matches');
|
|
89
|
+
assert.deepEqual(frames[2], frames[0], 'the actual guide snippet matches native pixels');
|
|
90
|
+
assert.deepEqual(frames[1], frames[0], 'native and EasyScore pixels match on the same renderer');
|
|
91
|
+
const draws = yield page.evaluate(() => {
|
|
92
|
+
const { score, annotation, tie } = window.example;
|
|
93
|
+
const counts = { annotation: 0, tie: 0 };
|
|
94
|
+
for (const [name, element] of [
|
|
95
|
+
['annotation', annotation],
|
|
96
|
+
['tie', tie],
|
|
97
|
+
]) {
|
|
98
|
+
const draw = element.draw.bind(element);
|
|
99
|
+
element.draw = () => {
|
|
100
|
+
counts[name]++;
|
|
101
|
+
return draw();
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
for (const ink of ['#b74632', '#24312c']) {
|
|
105
|
+
score.factory.getContext().clear();
|
|
106
|
+
score.setStyle({ fillStyle: ink, strokeStyle: ink }).draw({ retain: true });
|
|
107
|
+
}
|
|
108
|
+
return counts;
|
|
109
|
+
});
|
|
110
|
+
assert.deepEqual(draws, { annotation: 2, tie: 2 }, 'one drawing owner per element on retained redraw');
|
|
111
|
+
assert.deepEqual(yield page.screenshot({ omitBackground: false }), frames[1], 'theme round trip preserves output');
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
yield browser.close();
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
test('adopted native notation matches rendering and retained redraw lifecycle', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
122
|
+
try {
|
|
123
|
+
const page = yield browser.newPage();
|
|
124
|
+
yield page.setViewport({ width: 500, height: 240, deviceScaleFactor: 1 });
|
|
125
|
+
yield page.setContent('<style>body { margin: 0; background: white; }</style><div id="host"></div>');
|
|
126
|
+
yield page.addScriptTag({ path: `${root}build/cjs/vexflow-debug.js` });
|
|
127
|
+
yield page.evaluate(`window.createReferenceExample = ${createEasyScoreReferencesExample.toString()}`);
|
|
128
|
+
for (const font of ['Bravura', 'Petaluma']) {
|
|
129
|
+
for (const backend of ['svg', 'canvas']) {
|
|
130
|
+
yield t.test(`${font} ${backend}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const frames = [];
|
|
132
|
+
for (const native of [true, false]) {
|
|
133
|
+
yield page.evaluate((_a) => __awaiter(void 0, [_a], void 0, function* ({ font, backend, native }) {
|
|
134
|
+
const VF = VexFlow;
|
|
135
|
+
VF.setFonts(font, font === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
136
|
+
yield document.fonts.ready;
|
|
137
|
+
const host = document.getElementById('host');
|
|
138
|
+
host.replaceChildren();
|
|
139
|
+
const target = host.appendChild(document.createElement(backend === 'canvas' ? 'canvas' : 'div'));
|
|
140
|
+
target.id = 'score';
|
|
141
|
+
const renderer = { elementId: 'score', width: 500, height: 240 };
|
|
142
|
+
if (!native) {
|
|
143
|
+
window.example = window.createReferenceExample(VF, renderer);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const factory = new VF.Factory({ renderer });
|
|
147
|
+
factory.setStyle({ fillStyle: '#24312c', strokeStyle: '#24312c' });
|
|
148
|
+
const notes = [
|
|
149
|
+
factory.StaveNote({ keys: ['c/4'], duration: 'h', autoStem: true }),
|
|
150
|
+
factory.StaveNote({ keys: ['c/4'], duration: 'q', autoStem: true }),
|
|
151
|
+
factory.StaveNote({ keys: ['e/4'], duration: 'q', autoStem: true }),
|
|
152
|
+
];
|
|
153
|
+
notes[0].addModifier(factory.Annotation({ text: 'dolce', vJustify: 'top' }), 0);
|
|
154
|
+
factory.StaveTie({ from: notes[0], to: notes[1] });
|
|
155
|
+
factory.Curve({ from: notes[1], to: notes[2] });
|
|
156
|
+
const voice = factory.Voice({ time: '4/4' }).addTickables(notes);
|
|
157
|
+
factory
|
|
158
|
+
.System({ x: 20, y: 70, width: 460 })
|
|
159
|
+
.addStave({ voices: [voice] })
|
|
160
|
+
.addClef('treble')
|
|
161
|
+
.addTimeSignature('4/4');
|
|
162
|
+
factory.draw({ retain: true });
|
|
163
|
+
}), { font, backend, native });
|
|
164
|
+
frames.push(yield page.screenshot({ omitBackground: false }));
|
|
165
|
+
}
|
|
166
|
+
assert.deepEqual(frames[1], frames[0], 'native extensions preserve rendered pixels');
|
|
167
|
+
const counts = yield page.evaluate(() => {
|
|
168
|
+
const { score, notes, label, tie, curve } = window.example;
|
|
169
|
+
const calls = { label: 0, tie: 0, curve: 0, native: 0 };
|
|
170
|
+
for (const [key, element] of [
|
|
171
|
+
['label', label],
|
|
172
|
+
['tie', tie],
|
|
173
|
+
['curve', curve],
|
|
174
|
+
['native', notes[2]],
|
|
175
|
+
]) {
|
|
176
|
+
const draw = element.draw.bind(element);
|
|
177
|
+
element.draw = () => {
|
|
178
|
+
calls[key]++;
|
|
179
|
+
return draw();
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
score.adopt(curve, 'drawable');
|
|
183
|
+
score.adopt(notes[2], 'note');
|
|
184
|
+
score.adopt(label, 'modifier');
|
|
185
|
+
score.attach(notes[0], label);
|
|
186
|
+
score.factory.getContext().clear();
|
|
187
|
+
score.draw({ retain: true });
|
|
188
|
+
if (score.getNote('start') !== notes[0] || !score.getSource(notes[0]))
|
|
189
|
+
throw new Error('Lost references');
|
|
190
|
+
return calls;
|
|
191
|
+
});
|
|
192
|
+
assert.deepEqual(counts, { label: 1, tie: 1, curve: 1, native: 1 });
|
|
193
|
+
assert.deepEqual(yield page.screenshot({ omitBackground: false }), frames[1], 'retained redraw is identical');
|
|
194
|
+
assert.deepEqual(yield page.evaluate(() => {
|
|
195
|
+
const { score, notes } = window.example;
|
|
196
|
+
score.factory.getContext().clear();
|
|
197
|
+
score.draw();
|
|
198
|
+
const found = score.getNote('start') === notes[0];
|
|
199
|
+
score.reset();
|
|
200
|
+
return {
|
|
201
|
+
found,
|
|
202
|
+
missing: score.getElement('start') === undefined,
|
|
203
|
+
cleared: VexFlow.EasyScore.getSource(notes[0]) === undefined,
|
|
204
|
+
};
|
|
205
|
+
}), { found: true, missing: true, cleared: true });
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
yield browser.close();
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
test('EasyScore notation families draw once and redraw identically on both backends', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
|
+
const { renderEasyScoreFamilies } = yield import('../../tools/easyscore-families.mjs');
|
|
216
|
+
const { renderEasyScoreStructure } = yield import('../../tools/easyscore-structure.mjs');
|
|
217
|
+
const { renderEasyScoreRhythm } = yield import('../../tools/easyscore-rhythm.mjs');
|
|
218
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
219
|
+
try {
|
|
220
|
+
const page = yield browser.newPage();
|
|
221
|
+
yield page.setViewport({ width: 640, height: 240, deviceScaleFactor: 1 });
|
|
222
|
+
yield page.setContent('<style>body{margin:0;background:white}</style><div id="host"></div>');
|
|
223
|
+
yield page.addScriptTag({ path: `${root}build/cjs/vexflow-debug.js` });
|
|
224
|
+
yield page.evaluate(`window.renderFamilies = ${renderEasyScoreFamilies.toString()}; window.renderRhythm = ${renderEasyScoreRhythm.toString()}; window.renderStructure = ${renderEasyScoreStructure.toString()}`);
|
|
225
|
+
for (const font of ['Bravura', 'Petaluma'])
|
|
226
|
+
for (const backend of ['svg', 'canvas']) {
|
|
227
|
+
for (const kind of [
|
|
228
|
+
'modifiers',
|
|
229
|
+
'accidentals',
|
|
230
|
+
'text',
|
|
231
|
+
'grace',
|
|
232
|
+
'percussion',
|
|
233
|
+
'sequence',
|
|
234
|
+
'odd-meter',
|
|
235
|
+
'tuplets',
|
|
236
|
+
'ties',
|
|
237
|
+
'curves',
|
|
238
|
+
'hairpins',
|
|
239
|
+
'lines',
|
|
240
|
+
'brackets',
|
|
241
|
+
'pedal',
|
|
242
|
+
'partial-spans',
|
|
243
|
+
'dynamics',
|
|
244
|
+
'tab',
|
|
245
|
+
'grace-tab',
|
|
246
|
+
'rest',
|
|
247
|
+
'inline',
|
|
248
|
+
'repeat',
|
|
249
|
+
'labels',
|
|
250
|
+
'endings',
|
|
251
|
+
'connector',
|
|
252
|
+
]) {
|
|
253
|
+
yield t.test(`${font} ${backend} ${kind}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
254
|
+
yield page.evaluate((_a) => __awaiter(void 0, [_a], void 0, function* ({ font, backend, kind }) {
|
|
255
|
+
const VF = VexFlow;
|
|
256
|
+
VF.setFonts(font, font === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
257
|
+
yield document.fonts.ready;
|
|
258
|
+
const host = document.getElementById('host');
|
|
259
|
+
host.replaceChildren();
|
|
260
|
+
const target = host.appendChild(document.createElement(backend === 'canvas' ? 'canvas' : 'div'));
|
|
261
|
+
target.id = 'score';
|
|
262
|
+
const render = ['modifiers', 'accidentals', 'text', 'grace', 'percussion', 'sequence'].includes(kind)
|
|
263
|
+
? window.renderFamilies
|
|
264
|
+
: ['tab', 'grace-tab', 'rest', 'inline', 'repeat', 'labels', 'endings', 'connector'].includes(kind)
|
|
265
|
+
? window.renderStructure
|
|
266
|
+
: window.renderRhythm;
|
|
267
|
+
window.example = render(VF, { elementId: 'score', width: 640, height: 240 }, kind);
|
|
268
|
+
}), { font, backend, kind });
|
|
269
|
+
const original = yield page.screenshot({ omitBackground: false });
|
|
270
|
+
const counts = yield page.evaluate(() => {
|
|
271
|
+
const { score, notes, marks } = window.example;
|
|
272
|
+
const elements = [...notes, ...marks, ...marks.flatMap((mark) => { var _a, _b; return (_b = (_a = mark.getGraceNotes) === null || _a === void 0 ? void 0 : _a.call(mark)) !== null && _b !== void 0 ? _b : []; })];
|
|
273
|
+
const counts = elements.map(() => 0);
|
|
274
|
+
elements.forEach((element, index) => {
|
|
275
|
+
const draw = element.draw.bind(element);
|
|
276
|
+
element.draw = () => {
|
|
277
|
+
counts[index]++;
|
|
278
|
+
return draw();
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
score.factory.getContext().clear();
|
|
282
|
+
score.draw({ retain: true });
|
|
283
|
+
return counts;
|
|
284
|
+
});
|
|
285
|
+
assert.ok(counts.every((count) => count === 1), `one drawing owner: ${counts}`);
|
|
286
|
+
assert.deepEqual(yield page.screenshot({ omitBackground: false }), original);
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
yield browser.close();
|
|
293
|
+
}
|
|
294
|
+
}));
|
|
295
|
+
test('structured composition reflows wide narrow wide with stable native geometry', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
|
+
const { renderEasyScoreComposition } = yield import('../../tools/easyscore-composition.mjs');
|
|
297
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
298
|
+
try {
|
|
299
|
+
const page = yield browser.newPage();
|
|
300
|
+
yield page.setViewport({ width: 1000, height: 1400, deviceScaleFactor: 1 });
|
|
301
|
+
yield page.setContent('<style>body{margin:0;background:white}</style><div id="host"></div>');
|
|
302
|
+
yield page.addScriptTag({ path: `${root}build/cjs/vexflow-debug.js` });
|
|
303
|
+
yield page.evaluate(`window.renderComposition = ${renderEasyScoreComposition.toString()}`);
|
|
304
|
+
for (const font of ['Bravura', 'Petaluma'])
|
|
305
|
+
for (const backend of ['svg', 'canvas'])
|
|
306
|
+
for (const spacing of ['engraving', 'proportional']) {
|
|
307
|
+
yield t.test(`${font} ${backend} ${spacing}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
308
|
+
const initial = yield page.evaluate((_a) => __awaiter(void 0, [_a], void 0, function* ({ font, backend, spacing }) {
|
|
309
|
+
const VF = VexFlow;
|
|
310
|
+
VF.setFonts(font, font === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
311
|
+
yield document.fonts.ready;
|
|
312
|
+
const host = document.getElementById('host');
|
|
313
|
+
host.replaceChildren();
|
|
314
|
+
const target = host.appendChild(document.createElement(backend === 'canvas' ? 'canvas' : 'div'));
|
|
315
|
+
target.id = 'score';
|
|
316
|
+
window.example = window.renderComposition(VF, { elementId: 'score', width: 1000, height: 600 }, spacing);
|
|
317
|
+
return window.example.redraw(1000);
|
|
318
|
+
}), { font, backend, spacing });
|
|
319
|
+
const original = yield page.screenshot({ omitBackground: false });
|
|
320
|
+
const narrow = yield page.evaluate(() => window.example.redraw(350));
|
|
321
|
+
assert.ok(narrow.length > initial.length, 'narrow width wraps more rows');
|
|
322
|
+
assert.ok(narrow.every((row) => Number.isFinite(row.width) && row.height > 0 && row.overflow >= 0));
|
|
323
|
+
const wide = yield page.evaluate(() => window.example.redraw(1000));
|
|
324
|
+
assert.deepEqual(wide, initial, 'native row geometry returns exactly');
|
|
325
|
+
assert.deepEqual(yield page.screenshot({ omitBackground: false }), original, 'wide redraw is identical');
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
finally {
|
|
330
|
+
yield browser.close();
|
|
331
|
+
}
|
|
332
|
+
}));
|