vexflow 5.1.2 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +5325 -1730
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4228 -1545
- 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 +13 -3
- package/build/esm/src/articulation.js +51 -20
- package/build/esm/src/beam.js +170 -30
- package/build/esm/src/bend.js +24 -19
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/clefnote.js +5 -1
- package/build/esm/src/curve.js +27 -53
- package/build/esm/src/dot.js +14 -5
- package/build/esm/src/easyscore/composition.js +336 -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 +97 -0
- package/build/esm/src/easyscore/rhythm.js +42 -0
- package/build/esm/src/easyscore.js +448 -26
- package/build/esm/src/element.js +17 -2
- package/build/esm/src/engravinggeometry.js +150 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +268 -64
- package/build/esm/src/formatter.js +40 -4
- 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 +10 -2
- package/build/esm/src/keysignote.js +2 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/note.js +5 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +38 -18
- package/build/esm/src/parenthesis.js +1 -1
- package/build/esm/src/parser.js +6 -1
- package/build/esm/src/proportionalformatter.js +234 -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 +140 -127
- package/build/esm/src/stavetie.js +39 -7
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/stemmablenote.js +6 -1
- package/build/esm/src/tickable.js +5 -0
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +5 -0
- package/build/esm/src/tuplet.js +60 -19
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +6 -1
- package/build/esm/tests/beam_tests.js +35 -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/easyscore_tests.js +40 -0
- package/build/esm/tests/easyscore_types.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 +51 -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-rendering-tests.mjs +332 -0
- package/build/esm/tests/node/easyscore-tests.mjs +1024 -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 +278 -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-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/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +6 -0
- package/build/types/src/articulation.d.ts +12 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/clef.d.ts +2 -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 +126 -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 +7 -1
- 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 +97 -9
- package/build/types/src/formatter.d.ts +7 -1
- 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/keysignature.d.ts +3 -0
- package/build/types/src/keysignote.d.ts +1 -1
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +7 -0
- package/build/types/src/parser.d.ts +5 -0
- package/build/types/src/proportionalformatter.d.ts +39 -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 +21 -3
- package/build/types/src/stavetie.d.ts +4 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/stemmablenote.d.ts +6 -1
- package/build/types/src/tickable.d.ts +2 -0
- 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 +6 -1
- package/changelog/CHANGELOG.md +52 -0
- package/package.json +13 -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,150 @@
|
|
|
1
|
+
import { Accidental } from './accidental.js';
|
|
2
|
+
import { Annotation } from './annotation.js';
|
|
3
|
+
import { Articulation } from './articulation.js';
|
|
4
|
+
import { Beam } from './beam.js';
|
|
5
|
+
import { BoundingBox } from './boundingbox.js';
|
|
6
|
+
import { Curve } from './curve.js';
|
|
7
|
+
import { Dot } from './dot.js';
|
|
8
|
+
import { GraceNote } from './gracenote.js';
|
|
9
|
+
import { GraceNoteGroup } from './gracenotegroup.js';
|
|
10
|
+
import { Ornament } from './ornament.js';
|
|
11
|
+
import { StaveNote } from './stavenote.js';
|
|
12
|
+
import { StaveTie } from './stavetie.js';
|
|
13
|
+
import { Stem } from './stem.js';
|
|
14
|
+
import { Tuplet } from './tuplet.js';
|
|
15
|
+
import { RuntimeError } from './util.js';
|
|
16
|
+
function inflate(box, amount) {
|
|
17
|
+
return new BoundingBox(box.x - amount, box.y - amount, box.w + 2 * amount, box.h + 2 * amount);
|
|
18
|
+
}
|
|
19
|
+
function rectangle(x1, y1, x2, y2) {
|
|
20
|
+
return new BoundingBox(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1));
|
|
21
|
+
}
|
|
22
|
+
function noteShape(note) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
if (note.renderOptions.draw === false)
|
|
25
|
+
return { parts: [], anchors: {} };
|
|
26
|
+
(_a = note.getBeam()) === null || _a === void 0 ? void 0 : _a.postFormat();
|
|
27
|
+
const parts = note.getHeadInk();
|
|
28
|
+
const anchors = {};
|
|
29
|
+
parts.forEach((box, i) => {
|
|
30
|
+
anchors[`head${i}`] = { x: box.x + box.w / 2, y: note.getYs()[i] };
|
|
31
|
+
});
|
|
32
|
+
const segment = note.getStemSegment();
|
|
33
|
+
if (segment) {
|
|
34
|
+
const { x, baseY, tipY } = segment;
|
|
35
|
+
parts.push(new BoundingBox(x - Stem.WIDTH / 2, Math.min(baseY, tipY), Stem.WIDTH, Math.abs(tipY - baseY)));
|
|
36
|
+
anchors.stemBase = { x, y: baseY };
|
|
37
|
+
anchors.stemTip = { x, y: tipY };
|
|
38
|
+
}
|
|
39
|
+
const flag = note.getFlagInk();
|
|
40
|
+
if (flag)
|
|
41
|
+
parts.push(flag);
|
|
42
|
+
const lineWidth = (_c = (_b = note.getLedgerLineStyle().lineWidth) !== null && _b !== void 0 ? _b : note.checkStave().getDefaultLedgerLineStyle().lineWidth) !== null && _c !== void 0 ? _c : 1;
|
|
43
|
+
for (const { x, y, width } of note.getLedgerLines())
|
|
44
|
+
parts.push(new BoundingBox(x, y - lineWidth / 2, width, lineWidth));
|
|
45
|
+
if (note instanceof GraceNote) {
|
|
46
|
+
const slash = note.getSlash();
|
|
47
|
+
if (slash)
|
|
48
|
+
parts.push(inflate(rectangle(slash.x1, slash.y1, slash.x2, slash.y2), note.getFontScale() / 2));
|
|
49
|
+
}
|
|
50
|
+
return { parts, anchors };
|
|
51
|
+
}
|
|
52
|
+
export function measureEngraving(element, options = {}) {
|
|
53
|
+
var _a;
|
|
54
|
+
const diagnostics = [];
|
|
55
|
+
const report = (owner, code) => {
|
|
56
|
+
diagnostics.push({
|
|
57
|
+
code,
|
|
58
|
+
phase: 'measure',
|
|
59
|
+
severity: code === 'LayoutOverflow' ? 'warning' : 'error',
|
|
60
|
+
sourceId: owner.getAttribute('id'),
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
function collect(owner) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const shape = { parts: [], anchors: {} };
|
|
66
|
+
const children = (elements) => {
|
|
67
|
+
for (const child of elements)
|
|
68
|
+
shape.parts.push(...collect(child).parts);
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
const kind = Object.getPrototypeOf(owner).constructor;
|
|
72
|
+
const custom = (_a = options.extension) === null || _a === void 0 ? void 0 : _a.call(options, owner);
|
|
73
|
+
if (custom)
|
|
74
|
+
Object.assign(shape, custom);
|
|
75
|
+
else if (kind === StaveNote || kind === GraceNote) {
|
|
76
|
+
const note = owner;
|
|
77
|
+
Object.assign(shape, noteShape(note));
|
|
78
|
+
if (note.renderOptions.draw !== false)
|
|
79
|
+
children(note.getModifiers());
|
|
80
|
+
}
|
|
81
|
+
else if (kind === GraceNoteGroup)
|
|
82
|
+
children(owner.getLayoutElements());
|
|
83
|
+
else if (kind === Articulation) {
|
|
84
|
+
const box = owner.getInkBounds();
|
|
85
|
+
shape.parts.push(box);
|
|
86
|
+
shape.anchors.center = { x: box.x + box.w / 2, y: box.y + box.h / 2 };
|
|
87
|
+
}
|
|
88
|
+
else if (kind === Accidental || kind === Dot) {
|
|
89
|
+
shape.parts.push(owner.getInkBounds());
|
|
90
|
+
}
|
|
91
|
+
else if (kind === Tuplet || kind === Ornament) {
|
|
92
|
+
shape.parts.push(owner.getBoundingBox());
|
|
93
|
+
}
|
|
94
|
+
else if (kind === Beam) {
|
|
95
|
+
const beam = owner;
|
|
96
|
+
shape.parts.push(beam.getBoundingBox());
|
|
97
|
+
for (const [i, note] of beam.getNotes().entries())
|
|
98
|
+
shape.anchors[`stem${i}`] = { x: note.getStemX(), y: note.getStemExtents().topY };
|
|
99
|
+
}
|
|
100
|
+
else if (kind === Curve) {
|
|
101
|
+
const curve = owner;
|
|
102
|
+
shape.parts.push(inflate(curve.getBoundingBox(), ((_b = curve.getStyle().lineWidth) !== null && _b !== void 0 ? _b : 1) / 2));
|
|
103
|
+
shape.anchors = curve.getAnchors();
|
|
104
|
+
}
|
|
105
|
+
else if (kind === Annotation) {
|
|
106
|
+
const mark = owner;
|
|
107
|
+
const { x } = mark.computeX();
|
|
108
|
+
const { y } = mark.computeY();
|
|
109
|
+
shape.parts.push(mark.getTextInk(x, y));
|
|
110
|
+
shape.anchors.baseline = { x: x + mark.getXShift(), y: y + mark.getYShift() };
|
|
111
|
+
}
|
|
112
|
+
else if (kind === StaveTie && !owner.text)
|
|
113
|
+
shape.parts.push(owner.getRibbonBounds());
|
|
114
|
+
else
|
|
115
|
+
report(owner, 'UnsupportedGeometry');
|
|
116
|
+
const finiteBox = (b) => [b.x, b.y, b.w, b.h].every(Number.isFinite) && b.w >= 0 && b.h >= 0;
|
|
117
|
+
if (!shape.parts.every(finiteBox) ||
|
|
118
|
+
!Object.values(shape.anchors).every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))) {
|
|
119
|
+
report(owner, 'InvalidGeometry');
|
|
120
|
+
return { parts: [], anchors: {} };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (!(error instanceof RuntimeError))
|
|
125
|
+
throw error;
|
|
126
|
+
report(owner, 'UnformattedGeometry');
|
|
127
|
+
}
|
|
128
|
+
return shape;
|
|
129
|
+
}
|
|
130
|
+
const shape = collect(element);
|
|
131
|
+
const padding = (_a = options.paddingPx) !== null && _a !== void 0 ? _a : 0;
|
|
132
|
+
if (!Number.isFinite(padding) || padding < 0)
|
|
133
|
+
throw new RangeError('Expected finite nonnegative layout padding.');
|
|
134
|
+
let ink;
|
|
135
|
+
for (const part of shape.parts) {
|
|
136
|
+
const box = new BoundingBox(part.x, part.y, part.w, part.h);
|
|
137
|
+
ink = ink ? ink.mergeWith(box) : box;
|
|
138
|
+
}
|
|
139
|
+
const layout = ink && inflate(ink, padding);
|
|
140
|
+
if (ink && element instanceof GraceNoteGroup) {
|
|
141
|
+
shape.anchors.left = { x: ink.x, y: element.checkAttachedNote().getYs()[element.checkIndex()] };
|
|
142
|
+
shape.anchors.right = { x: ink.x + ink.w, y: shape.anchors.left.y };
|
|
143
|
+
}
|
|
144
|
+
const v = options.viewport;
|
|
145
|
+
if (v &&
|
|
146
|
+
layout &&
|
|
147
|
+
(layout.x < v.x || layout.y < v.y || layout.x + layout.w > v.x + v.w || layout.y + layout.h > v.y + v.h))
|
|
148
|
+
report(element, 'LayoutOverflow');
|
|
149
|
+
return Object.assign(Object.assign({}, shape), { ink, layout, diagnostics });
|
|
150
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
function record(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' ? value : {};
|
|
4
|
+
}
|
|
5
|
+
function distance(value, fallback, allowZero = false) {
|
|
6
|
+
return typeof value === 'number' && Number.isFinite(value) && (allowZero ? value >= 0 : value > 0) && value <= 16
|
|
7
|
+
? value
|
|
8
|
+
: fallback;
|
|
9
|
+
}
|
|
10
|
+
function readAnchor(value) {
|
|
11
|
+
if (!Array.isArray(value) || value.length !== 2 || !value.every((v) => Number.isFinite(v) && Math.abs(v) <= 16))
|
|
12
|
+
return;
|
|
13
|
+
return Object.freeze([value[0], value[1]]);
|
|
14
|
+
}
|
|
15
|
+
export class EngravingProfile {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!options.musicFont.trim())
|
|
19
|
+
throw new RangeError('Expected a music font family.');
|
|
20
|
+
this.musicFont = options.musicFont;
|
|
21
|
+
const supplied = record(options.metadata);
|
|
22
|
+
const metadata = supplied.fontName === this.musicFont ? supplied : {};
|
|
23
|
+
this.beamThickness = (_a = options.beamThickness) !== null && _a !== void 0 ? _a : distance(record(metadata.engravingDefaults).beamThickness, 0.5);
|
|
24
|
+
this.clearance = (_b = options.clearance) !== null && _b !== void 0 ? _b : 0.25;
|
|
25
|
+
if (!Number.isFinite(distance(this.beamThickness, NaN)) || !Number.isFinite(distance(this.clearance, NaN, true)))
|
|
26
|
+
throw new RangeError('Invalid engraving distance in staff spaces.');
|
|
27
|
+
const anchors = {};
|
|
28
|
+
for (const [name, fields] of Object.entries(record(metadata.glyphsWithAnchors))) {
|
|
29
|
+
if (!Object.prototype.hasOwnProperty.call(Glyphs, name))
|
|
30
|
+
continue;
|
|
31
|
+
const glyph = Glyphs[name];
|
|
32
|
+
anchors[glyph] = Object.freeze({
|
|
33
|
+
up: readAnchor(record(fields).stemUpSE),
|
|
34
|
+
down: readAnchor(record(fields).stemDownNW),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
this.anchors = Object.freeze(anchors);
|
|
38
|
+
Object.freeze(this);
|
|
39
|
+
}
|
|
40
|
+
stemAnchor(glyph, direction) {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.anchors[glyph]) === null || _a === void 0 ? void 0 : _a[direction];
|
|
43
|
+
}
|
|
44
|
+
}
|