vexflow 5.0.0 → 5.1.1
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/LICENSE +3 -3
- package/README.md +46 -53
- 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 +3825 -1396
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +2577 -984
- 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 +1 -0
- package/build/esm/src/annotation.js +31 -8
- package/build/esm/src/beam.js +4 -2
- package/build/esm/src/chordsymbol.js +3 -1
- package/build/esm/src/clef.js +3 -1
- package/build/esm/src/curve.js +68 -11
- package/build/esm/src/easyscore.js +40 -1
- package/build/esm/src/element.js +49 -11
- package/build/esm/src/factory.js +46 -9
- package/build/esm/src/flag.js +3 -1
- package/build/esm/src/font.js +20 -1
- package/build/esm/src/formatter.js +34 -36
- package/build/esm/src/fraction.js +4 -1
- package/build/esm/src/glyphnote.js +3 -1
- package/build/esm/src/gracenotegroup.js +18 -1
- package/build/esm/src/index.js +2 -0
- package/build/esm/src/keysignature.js +3 -1
- package/build/esm/src/metrics.js +58 -3
- package/build/esm/src/modifiercontext.js +15 -1
- package/build/esm/src/note.js +2 -2
- package/build/esm/src/notehead.js +3 -1
- package/build/esm/src/ornament.js +3 -1
- package/build/esm/src/pedalmarking.js +44 -5
- package/build/esm/src/registry.js +16 -6
- package/build/esm/src/rendercontext.js +10 -0
- package/build/esm/src/sheet.js +117 -0
- package/build/esm/src/stave.js +13 -8
- package/build/esm/src/stavebarline.js +53 -1
- package/build/esm/src/staveline.js +2 -0
- package/build/esm/src/stavenote.js +54 -19
- package/build/esm/src/stavetie.js +3 -1
- package/build/esm/src/stem.js +2 -1
- package/build/esm/src/stemmablenote.js +9 -0
- package/build/esm/src/stringnumber.js +0 -1
- package/build/esm/src/strokes.js +10 -0
- package/build/esm/src/svgcontext.js +14 -4
- package/build/esm/src/svgexport.js +68 -0
- package/build/esm/src/system.js +14 -0
- package/build/esm/src/tables.js +69 -37
- package/build/esm/src/tabnote.js +20 -1
- package/build/esm/src/textbracket.js +5 -4
- package/build/esm/src/textdynamics.js +5 -0
- package/build/esm/src/textmetricscache.js +93 -0
- package/build/esm/src/textnote.js +3 -3
- package/build/esm/src/tickable.js +56 -22
- package/build/esm/src/timesignature.js +30 -9
- package/build/esm/src/timesignote.js +3 -1
- package/build/esm/src/tuning.js +2 -2
- package/build/esm/src/tuplet.js +79 -29
- package/build/esm/src/util.js +1 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +14 -2
- package/build/esm/src/voice.js +44 -8
- package/build/esm/tests/accidental_tests.js +52 -0
- package/build/esm/tests/annotation_tests.js +38 -0
- package/build/esm/tests/articulation_tests.js +34 -0
- package/build/esm/tests/beam_tests.js +17 -0
- package/build/esm/tests/curve_tests.js +81 -0
- package/build/esm/tests/font_tests.js +32 -1
- package/build/esm/tests/formatter_tests.js +58 -23
- package/build/esm/tests/gracenote_tests.js +58 -0
- package/build/esm/tests/gracetabnote_tests.js +40 -0
- package/build/esm/tests/keysignature_tests.js +14 -3
- package/build/esm/tests/node/metrics-tests.mjs +278 -0
- package/build/esm/tests/node/package-input-tests.mjs +149 -0
- package/build/esm/tests/node/render-metrics-tests.mjs +78 -0
- package/build/esm/tests/node/rendering-tests.mjs +75 -0
- package/build/esm/tests/node/sheet-tests.mjs +202 -0
- package/build/esm/tests/node/svg-export-tests.mjs +182 -0
- package/build/esm/tests/pedalmarking_tests.js +25 -0
- package/build/esm/tests/rests_tests.js +6 -0
- package/build/esm/tests/stave_tests.js +6 -3
- package/build/esm/tests/stavenote_tests.js +100 -55
- package/build/esm/tests/strokes_tests.js +19 -5
- package/build/esm/tests/timesignature_tests.js +19 -0
- package/build/esm/tests/tuplet_tests.js +273 -12
- package/build/esm/tests/unison_tests.js +13 -13
- package/build/esm/tests/voice_tests.js +34 -0
- package/build/esm/tools/render-metrics.mjs +49 -0
- package/build/esm/tools/score-fixtures.mjs +94 -0
- package/build/esm/tools/sheet-fixture.mjs +90 -0
- package/build/esm/tools/visual-regression.mjs +106 -0
- package/build/types/src/annotation.d.ts +17 -1
- package/build/types/src/curve.d.ts +24 -7
- package/build/types/src/easyscore.d.ts +8 -0
- package/build/types/src/element.d.ts +7 -0
- package/build/types/src/factory.d.ts +18 -1
- package/build/types/src/font.d.ts +2 -0
- package/build/types/src/formatter.d.ts +23 -14
- package/build/types/src/gracenotegroup.d.ts +5 -0
- package/build/types/src/index.d.ts +2 -0
- package/build/types/src/metrics.d.ts +2 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/pedalmarking.d.ts +4 -1
- package/build/types/src/registry.d.ts +2 -0
- package/build/types/src/rendercontext.d.ts +12 -0
- package/build/types/src/sheet.d.ts +49 -0
- package/build/types/src/stave.d.ts +4 -4
- package/build/types/src/stavebarline.d.ts +10 -0
- package/build/types/src/stavenote.d.ts +11 -0
- package/build/types/src/strokes.d.ts +4 -0
- package/build/types/src/svgcontext.d.ts +5 -0
- package/build/types/src/svgexport.d.ts +22 -0
- package/build/types/src/system.d.ts +4 -0
- package/build/types/src/tables.d.ts +9 -0
- package/build/types/src/tabnote.d.ts +4 -0
- package/build/types/src/textbracket.d.ts +1 -1
- package/build/types/src/textdynamics.d.ts +3 -0
- package/build/types/src/textmetricscache.d.ts +21 -0
- package/build/types/src/tickable.d.ts +27 -10
- package/build/types/src/timesignature.d.ts +4 -0
- package/build/types/src/tuplet.d.ts +8 -0
- package/build/types/src/util.d.ts +1 -0
- package/build/types/src/vexflow.d.ts +8 -1
- package/build/types/src/voice.d.ts +6 -0
- package/changelog/CHANGELOG.md +109 -0
- package/package.json +44 -26
- package/tests/flow.html +15 -7
|
@@ -4,7 +4,7 @@ import { Modifier, ModifierPosition } from './modifier.js';
|
|
|
4
4
|
import { Stem } from './stem.js';
|
|
5
5
|
import { Tables } from './tables.js';
|
|
6
6
|
import { isStemmableNote, isTabNote } from './typeguard.js';
|
|
7
|
-
import { log } from './util.js';
|
|
7
|
+
import { log, RuntimeError } from './util.js';
|
|
8
8
|
function L(...args) {
|
|
9
9
|
if (Annotation.DEBUG)
|
|
10
10
|
log('VexFlow.Annotation', args);
|
|
@@ -140,6 +140,9 @@ export class Annotation extends Modifier {
|
|
|
140
140
|
this.verticalJustification = typeof just === 'string' ? Annotation.VerticalJustifyString[just] : just;
|
|
141
141
|
return this;
|
|
142
142
|
}
|
|
143
|
+
getVerticalJustification() {
|
|
144
|
+
return this.verticalJustification;
|
|
145
|
+
}
|
|
143
146
|
getJustification() {
|
|
144
147
|
return this.horizontalJustification;
|
|
145
148
|
}
|
|
@@ -147,17 +150,18 @@ export class Annotation extends Modifier {
|
|
|
147
150
|
this.horizontalJustification = typeof just === 'string' ? Annotation.HorizontalJustifyString[just] : just;
|
|
148
151
|
return this;
|
|
149
152
|
}
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
setTextBaseline(y) {
|
|
154
|
+
if (y !== undefined && !Number.isFinite(y)) {
|
|
155
|
+
throw new RuntimeError('BadArgument', 'Text baseline must be finite.');
|
|
156
|
+
}
|
|
157
|
+
this.textBaseline = y;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
computeX() {
|
|
152
161
|
const note = this.checkAttachedNote();
|
|
153
|
-
const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
|
|
154
162
|
const start = note.getModifierStartXY(ModifierPosition.ABOVE, this.index);
|
|
155
|
-
this.setRendered();
|
|
156
|
-
ctx.openGroup('annotation', this.getAttribute('id'));
|
|
157
163
|
const textWidth = this.getWidth();
|
|
158
|
-
const textHeight = Font.convertSizeToPixelValue(this.fontInfo.size);
|
|
159
164
|
let x;
|
|
160
|
-
let y;
|
|
161
165
|
if (this.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
|
|
162
166
|
x = start.x;
|
|
163
167
|
}
|
|
@@ -170,6 +174,15 @@ export class Annotation extends Modifier {
|
|
|
170
174
|
else {
|
|
171
175
|
x = note.getStemX() - textWidth / 2;
|
|
172
176
|
}
|
|
177
|
+
return { x, textWidth };
|
|
178
|
+
}
|
|
179
|
+
computeY() {
|
|
180
|
+
const textHeight = Font.convertSizeToPixelValue(this.fontInfo.size);
|
|
181
|
+
if (this.textBaseline !== undefined)
|
|
182
|
+
return { y: this.textBaseline, textHeight };
|
|
183
|
+
const note = this.checkAttachedNote();
|
|
184
|
+
const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
|
|
185
|
+
let y;
|
|
173
186
|
let stemExt = {};
|
|
174
187
|
let spacing = 0;
|
|
175
188
|
const hasStem = note.hasStem();
|
|
@@ -203,10 +216,20 @@ export class Annotation extends Modifier {
|
|
|
203
216
|
const extents = note.getStemExtents();
|
|
204
217
|
y = extents.topY + (extents.baseY - extents.topY) / 2 + textHeight / 2;
|
|
205
218
|
}
|
|
219
|
+
return { y, textHeight };
|
|
220
|
+
}
|
|
221
|
+
draw() {
|
|
222
|
+
const ctx = this.checkContext();
|
|
223
|
+
const { x } = this.computeX();
|
|
224
|
+
const { y } = this.computeY();
|
|
225
|
+
this.setRendered();
|
|
226
|
+
const clsAttribute = this.getAttribute('class');
|
|
227
|
+
ctx.openGroup('annotation' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
206
228
|
L('Rendering annotation: ', this.text, x, y);
|
|
207
229
|
this.x = x;
|
|
208
230
|
this.y = y;
|
|
209
231
|
this.renderText(ctx, 0, 0);
|
|
232
|
+
this.drawPointerRect();
|
|
210
233
|
ctx.closeGroup();
|
|
211
234
|
}
|
|
212
235
|
}
|
package/build/esm/src/beam.js
CHANGED
|
@@ -581,7 +581,7 @@ export class Beam extends Element {
|
|
|
581
581
|
}, this);
|
|
582
582
|
}
|
|
583
583
|
drawBeamLines(ctx) {
|
|
584
|
-
const validBeamDurations = ['4', '8', '16', '32', '64'];
|
|
584
|
+
const validBeamDurations = ['4', '8', '16', '32', '64', '128', '256', '512', '1024'];
|
|
585
585
|
const firstNote = this.notes[0];
|
|
586
586
|
let beamY = this.getBeamYToDraw();
|
|
587
587
|
const firstStemX = firstNote.getStemX();
|
|
@@ -634,9 +634,11 @@ export class Beam extends Element {
|
|
|
634
634
|
if (!this.postFormatted) {
|
|
635
635
|
this.postFormat();
|
|
636
636
|
}
|
|
637
|
-
|
|
637
|
+
const clsAttribute = this.getAttribute('class');
|
|
638
|
+
ctx.openGroup('beam' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
638
639
|
this.drawStems(ctx);
|
|
639
640
|
this.drawBeamLines(ctx);
|
|
641
|
+
this.drawPointerRect();
|
|
640
642
|
ctx.closeGroup();
|
|
641
643
|
}
|
|
642
644
|
}
|
|
@@ -229,7 +229,8 @@ export class ChordSymbol extends Modifier {
|
|
|
229
229
|
const ctx = this.checkContext();
|
|
230
230
|
const note = this.checkAttachedNote();
|
|
231
231
|
this.setRendered();
|
|
232
|
-
|
|
232
|
+
const clsAttribute = this.getAttribute('class');
|
|
233
|
+
ctx.openGroup('chordsymbol' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
233
234
|
const start = note.getModifierStartXY(Modifier.Position.ABOVE, this.index);
|
|
234
235
|
ctx.setFont(this.fontInfo);
|
|
235
236
|
let y;
|
|
@@ -273,6 +274,7 @@ export class ChordSymbol extends Modifier {
|
|
|
273
274
|
symbol.setY(y);
|
|
274
275
|
symbol.renderText(ctx, 0, 0);
|
|
275
276
|
});
|
|
277
|
+
this.drawPointerRect();
|
|
276
278
|
ctx.closeGroup();
|
|
277
279
|
}
|
|
278
280
|
getBoundingBox() {
|
package/build/esm/src/clef.js
CHANGED
|
@@ -109,9 +109,11 @@ export class Clef extends StaveModifier {
|
|
|
109
109
|
const stave = this.checkStave();
|
|
110
110
|
const ctx = stave.checkContext();
|
|
111
111
|
this.setRendered();
|
|
112
|
-
|
|
112
|
+
const clsAttribute = this.getAttribute('class');
|
|
113
|
+
ctx.openGroup('clef' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
113
114
|
this.y = stave.getYForLine(this.line);
|
|
114
115
|
this.renderText(ctx, 0, 0);
|
|
116
|
+
this.drawPointerRect();
|
|
115
117
|
ctx.closeGroup();
|
|
116
118
|
}
|
|
117
119
|
}
|
package/build/esm/src/curve.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox.js';
|
|
1
2
|
import { Element } from './element.js';
|
|
2
3
|
import { RuntimeError } from './util.js';
|
|
4
|
+
function bezierExtrema(p0, p1, p2, p3) {
|
|
5
|
+
const values = [p0, p3];
|
|
6
|
+
const a = -p0 + 3 * p1 - 3 * p2 + p3;
|
|
7
|
+
const b = 2 * (p0 - 2 * p1 + p2);
|
|
8
|
+
const c = p1 - p0;
|
|
9
|
+
const ts = [];
|
|
10
|
+
if (Math.abs(a) < 1e-12) {
|
|
11
|
+
if (Math.abs(b) > 1e-12)
|
|
12
|
+
ts.push(-c / b);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const discriminant = b * b - 4 * a * c;
|
|
16
|
+
if (discriminant >= 0) {
|
|
17
|
+
const root = Math.sqrt(discriminant);
|
|
18
|
+
ts.push((-b + root) / (2 * a), (-b - root) / (2 * a));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const t of ts) {
|
|
22
|
+
if (t > 0 && t < 1) {
|
|
23
|
+
const u = 1 - t;
|
|
24
|
+
values.push(u * u * u * p0 + 3 * u * u * t * p1 + 3 * u * t * t * p2 + t * t * t * p3);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return values;
|
|
28
|
+
}
|
|
3
29
|
export var CurvePosition;
|
|
4
30
|
(function (CurvePosition) {
|
|
5
31
|
CurvePosition[CurvePosition["NEAR_HEAD"] = 1] = "NEAR_HEAD";
|
|
@@ -37,9 +63,7 @@ export class Curve extends Element {
|
|
|
37
63
|
isPartial() {
|
|
38
64
|
return !this.from || !this.to;
|
|
39
65
|
}
|
|
40
|
-
|
|
41
|
-
var _a, _b;
|
|
42
|
-
const ctx = this.checkContext();
|
|
66
|
+
getBezierPoints(params) {
|
|
43
67
|
const xShift = this.renderOptions.xShift;
|
|
44
68
|
const yShift = this.renderOptions.yShift * params.direction;
|
|
45
69
|
const firstX = params.firstX + xShift;
|
|
@@ -51,19 +75,34 @@ export class Curve extends Element {
|
|
|
51
75
|
const { x: cp0x, y: cp0y } = cps[0];
|
|
52
76
|
const { x: cp1x, y: cp1y } = cps[1];
|
|
53
77
|
const controlPointSpacing = (lastX - firstX) / (cps.length + 2);
|
|
78
|
+
return {
|
|
79
|
+
first: { x: firstX, y: firstY },
|
|
80
|
+
last: { x: lastX, y: lastY },
|
|
81
|
+
cps: [
|
|
82
|
+
{ x: firstX + controlPointSpacing + cp0x, y: firstY + cp0y * params.direction },
|
|
83
|
+
{ x: lastX - controlPointSpacing + cp1x, y: lastY + cp1y * params.direction },
|
|
84
|
+
],
|
|
85
|
+
thicknessCps: [
|
|
86
|
+
{ x: lastX - controlPointSpacing + cp1x, y: lastY + (cp1y + thickness) * params.direction },
|
|
87
|
+
{ x: firstX + controlPointSpacing + cp0x, y: firstY + (cp0y + thickness) * params.direction },
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
renderCurve(params) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
const ctx = this.checkContext();
|
|
94
|
+
const { first, last, cps, thicknessCps } = this.getBezierPoints(params);
|
|
54
95
|
ctx.beginPath();
|
|
55
|
-
ctx.moveTo(
|
|
56
|
-
ctx.bezierCurveTo(
|
|
96
|
+
ctx.moveTo(first.x, first.y);
|
|
97
|
+
ctx.bezierCurveTo(cps[0].x, cps[0].y, cps[1].x, cps[1].y, last.x, last.y);
|
|
57
98
|
if (!((_a = this.style) === null || _a === void 0 ? void 0 : _a.lineDash))
|
|
58
|
-
ctx.bezierCurveTo(
|
|
99
|
+
ctx.bezierCurveTo(thicknessCps[0].x, thicknessCps[0].y, thicknessCps[1].x, thicknessCps[1].y, first.x, first.y);
|
|
59
100
|
ctx.stroke();
|
|
60
101
|
ctx.closePath();
|
|
61
102
|
if (!((_b = this.style) === null || _b === void 0 ? void 0 : _b.lineDash))
|
|
62
103
|
ctx.fill();
|
|
63
104
|
}
|
|
64
|
-
|
|
65
|
-
this.checkContext();
|
|
66
|
-
this.setRendered();
|
|
105
|
+
getRenderParams() {
|
|
67
106
|
const firstNote = this.from;
|
|
68
107
|
const lastNote = this.to;
|
|
69
108
|
let firstX;
|
|
@@ -114,13 +153,31 @@ export class Curve extends Element {
|
|
|
114
153
|
if (this.renderOptions.openingDirection === 'down') {
|
|
115
154
|
stemDirection = -1;
|
|
116
155
|
}
|
|
117
|
-
|
|
156
|
+
return {
|
|
118
157
|
firstX,
|
|
119
158
|
lastX,
|
|
120
159
|
firstY,
|
|
121
160
|
lastY,
|
|
122
161
|
direction: stemDirection * (this.renderOptions.invert === true ? -1 : 1),
|
|
123
|
-
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
getBoundingBox() {
|
|
165
|
+
var _a;
|
|
166
|
+
const { first, last, cps, thicknessCps } = this.getBezierPoints(this.getRenderParams());
|
|
167
|
+
const xs = bezierExtrema(first.x, cps[0].x, cps[1].x, last.x);
|
|
168
|
+
const ys = bezierExtrema(first.y, cps[0].y, cps[1].y, last.y);
|
|
169
|
+
if (!((_a = this.style) === null || _a === void 0 ? void 0 : _a.lineDash)) {
|
|
170
|
+
xs.push(...bezierExtrema(last.x, thicknessCps[0].x, thicknessCps[1].x, first.x));
|
|
171
|
+
ys.push(...bezierExtrema(last.y, thicknessCps[0].y, thicknessCps[1].y, first.y));
|
|
172
|
+
}
|
|
173
|
+
const minX = Math.min(...xs);
|
|
174
|
+
const minY = Math.min(...ys);
|
|
175
|
+
return new BoundingBox(minX, minY, Math.max(...xs) - minX, Math.max(...ys) - minY);
|
|
176
|
+
}
|
|
177
|
+
draw() {
|
|
178
|
+
this.checkContext();
|
|
179
|
+
this.setRendered();
|
|
180
|
+
this.renderCurve(this.getRenderParams());
|
|
124
181
|
return true;
|
|
125
182
|
}
|
|
126
183
|
}
|
|
@@ -196,9 +196,10 @@ export class Builder {
|
|
|
196
196
|
this.reset();
|
|
197
197
|
}
|
|
198
198
|
reset(options) {
|
|
199
|
+
var _a;
|
|
199
200
|
this.options = Object.assign({ stem: 'auto', clef: 'treble' }, options);
|
|
200
201
|
this.elements = { notes: [], accidentals: [] };
|
|
201
|
-
this.rollingDuration = '8';
|
|
202
|
+
this.rollingDuration = (_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : '8';
|
|
202
203
|
this.resetPiece();
|
|
203
204
|
}
|
|
204
205
|
getFactory() {
|
|
@@ -363,6 +364,44 @@ export class EasyScore {
|
|
|
363
364
|
this.parse(line, options);
|
|
364
365
|
return this.builder.getElements().notes;
|
|
365
366
|
}
|
|
367
|
+
measures(line, options = {}) {
|
|
368
|
+
const parts = [];
|
|
369
|
+
let start = 0;
|
|
370
|
+
let quote = '';
|
|
371
|
+
for (let i = 0; i < line.length; i++) {
|
|
372
|
+
const char = line[i];
|
|
373
|
+
if (quote) {
|
|
374
|
+
if (char === quote)
|
|
375
|
+
quote = '';
|
|
376
|
+
}
|
|
377
|
+
else if (char === '"' || char === "'") {
|
|
378
|
+
quote = char;
|
|
379
|
+
}
|
|
380
|
+
else if (char === '|') {
|
|
381
|
+
parts.push(line.slice(start, i));
|
|
382
|
+
start = i + 1;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
parts.push(line.slice(start));
|
|
386
|
+
const measures = parts.map((part, index) => {
|
|
387
|
+
let text = part.trim();
|
|
388
|
+
if (index > 0)
|
|
389
|
+
text = text.replace(/^,\s*/, '');
|
|
390
|
+
if (index < parts.length - 1)
|
|
391
|
+
text = text.replace(/\s*,$/, '');
|
|
392
|
+
if (!text)
|
|
393
|
+
throw new RuntimeError('BadArguments', 'Empty EasyScore measure. Use an explicit rest.');
|
|
394
|
+
return text;
|
|
395
|
+
});
|
|
396
|
+
let duration = options.duration;
|
|
397
|
+
return measures.map((text) => {
|
|
398
|
+
const result = this.parse(text, Object.assign(Object.assign({ clef: this.defaults.clef, stem: this.defaults.stem }, options), { duration }));
|
|
399
|
+
if (!result.success)
|
|
400
|
+
throw new RuntimeError('BadArguments', `Invalid EasyScore measure: ${text}`);
|
|
401
|
+
duration = this.builder.rollingDuration;
|
|
402
|
+
return this.builder.getElements().notes;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
366
405
|
voice(notes, options = {}) {
|
|
367
406
|
options = Object.assign({ time: this.defaults.time }, options);
|
|
368
407
|
return this.factory.Voice(options).addTickables(notes);
|
package/build/esm/src/element.js
CHANGED
|
@@ -2,6 +2,7 @@ import { BoundingBox } from './boundingbox.js';
|
|
|
2
2
|
import { Font } from './font.js';
|
|
3
3
|
import { Metrics } from './metrics.js';
|
|
4
4
|
import { Registry } from './registry.js';
|
|
5
|
+
import { TextMetricsCache } from './textmetricscache.js';
|
|
5
6
|
import { defined, prefix, RuntimeError } from './util.js';
|
|
6
7
|
export class Element {
|
|
7
8
|
static get CATEGORY() {
|
|
@@ -12,6 +13,10 @@ export class Element {
|
|
|
12
13
|
}
|
|
13
14
|
static setTextMeasurementCanvas(canvas) {
|
|
14
15
|
Element.txtCanvas = canvas;
|
|
16
|
+
Element.clearTextMeasurementCache();
|
|
17
|
+
}
|
|
18
|
+
static clearTextMeasurementCache() {
|
|
19
|
+
TextMetricsCache.clear();
|
|
15
20
|
}
|
|
16
21
|
static getTextMeasurementCanvas() {
|
|
17
22
|
let txtCanvas = Element.txtCanvas;
|
|
@@ -30,6 +35,7 @@ export class Element {
|
|
|
30
35
|
var _a;
|
|
31
36
|
this.children = [];
|
|
32
37
|
this.style = {};
|
|
38
|
+
this.styleExplicit = false;
|
|
33
39
|
this._text = '';
|
|
34
40
|
this.metricsValid = false;
|
|
35
41
|
this._textMetrics = {
|
|
@@ -61,6 +67,7 @@ export class Element {
|
|
|
61
67
|
this._fontInfo = Metrics.getFontInfo(this.attrs.type);
|
|
62
68
|
this.style = Metrics.getStyle(this.attrs.type);
|
|
63
69
|
this.fontScale = Metrics.get(`${this.attrs.type}.fontScale`);
|
|
70
|
+
this.shouldDrawPointerRect = Metrics.get(`${this.attrs.type}.pointerRect`);
|
|
64
71
|
(_a = Registry.getDefaultRegistry()) === null || _a === void 0 ? void 0 : _a.register(this);
|
|
65
72
|
}
|
|
66
73
|
addChild(child) {
|
|
@@ -75,10 +82,12 @@ export class Element {
|
|
|
75
82
|
}
|
|
76
83
|
setStyle(style) {
|
|
77
84
|
this.style = style;
|
|
85
|
+
this.styleExplicit = true;
|
|
78
86
|
return this;
|
|
79
87
|
}
|
|
80
88
|
setGroupStyle(style) {
|
|
81
89
|
this.style = style;
|
|
90
|
+
this.styleExplicit = true;
|
|
82
91
|
this.children.forEach((child) => child.setGroupStyle(style));
|
|
83
92
|
return this;
|
|
84
93
|
}
|
|
@@ -88,26 +97,48 @@ export class Element {
|
|
|
88
97
|
applyStyle(context = this.context, style = this.getStyle()) {
|
|
89
98
|
if (!context)
|
|
90
99
|
return this;
|
|
100
|
+
if (style === this.style && !this.styleExplicit) {
|
|
101
|
+
const defaults = context.getDefaultStyle();
|
|
102
|
+
style = Object.assign({}, style);
|
|
103
|
+
if (defaults.fillStyle !== undefined)
|
|
104
|
+
delete style.fillStyle;
|
|
105
|
+
if (defaults.strokeStyle !== undefined)
|
|
106
|
+
delete style.strokeStyle;
|
|
107
|
+
}
|
|
91
108
|
if (style.shadowColor)
|
|
92
109
|
context.setShadowColor(style.shadowColor);
|
|
93
|
-
if (style.shadowBlur)
|
|
110
|
+
if (style.shadowBlur !== undefined)
|
|
94
111
|
context.setShadowBlur(style.shadowBlur);
|
|
95
112
|
if (style.fillStyle)
|
|
96
113
|
context.setFillStyle(style.fillStyle);
|
|
97
114
|
if (style.strokeStyle)
|
|
98
115
|
context.setStrokeStyle(style.strokeStyle);
|
|
99
|
-
if (style.lineWidth)
|
|
116
|
+
if (style.lineWidth !== undefined)
|
|
100
117
|
context.setLineWidth(style.lineWidth);
|
|
101
|
-
if (style.lineDash)
|
|
102
|
-
context.setLineDash(style.lineDash.split(' ').map(Number));
|
|
118
|
+
if (style.lineDash !== undefined)
|
|
119
|
+
context.setLineDash(style.lineDash ? style.lineDash.split(' ').map(Number) : []);
|
|
103
120
|
return this;
|
|
104
121
|
}
|
|
105
122
|
drawWithStyle() {
|
|
106
123
|
const ctx = this.checkContext();
|
|
124
|
+
const defaults = ctx.getDefaultStyle();
|
|
107
125
|
ctx.save();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
126
|
+
try {
|
|
127
|
+
if (this.styleExplicit) {
|
|
128
|
+
const inherited = Object.assign({}, defaults);
|
|
129
|
+
if (this.style.fillStyle !== undefined)
|
|
130
|
+
inherited.fillStyle = this.style.fillStyle;
|
|
131
|
+
if (this.style.strokeStyle !== undefined)
|
|
132
|
+
inherited.strokeStyle = this.style.strokeStyle;
|
|
133
|
+
ctx.setDefaultStyle(inherited);
|
|
134
|
+
}
|
|
135
|
+
this.applyStyle(ctx);
|
|
136
|
+
this.draw();
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
ctx.setDefaultStyle(defaults);
|
|
140
|
+
ctx.restore();
|
|
141
|
+
}
|
|
111
142
|
return this;
|
|
112
143
|
}
|
|
113
144
|
draw() {
|
|
@@ -189,6 +220,13 @@ export class Element {
|
|
|
189
220
|
getContext() {
|
|
190
221
|
return this.context;
|
|
191
222
|
}
|
|
223
|
+
drawPointerRect() {
|
|
224
|
+
var _a;
|
|
225
|
+
if (this.shouldDrawPointerRect) {
|
|
226
|
+
const bb = this.getBoundingBox();
|
|
227
|
+
(_a = this.context) === null || _a === void 0 ? void 0 : _a.pointerRect(bb.getX(), bb.getY(), bb.getW(), bb.getH());
|
|
228
|
+
}
|
|
229
|
+
}
|
|
192
230
|
setContext(context) {
|
|
193
231
|
this.context = context;
|
|
194
232
|
return this;
|
|
@@ -344,7 +382,7 @@ export class Element {
|
|
|
344
382
|
return this._textMetrics;
|
|
345
383
|
}
|
|
346
384
|
context.font = Font.toCSSString(Font.validate(this.fontInfo));
|
|
347
|
-
this._textMetrics =
|
|
385
|
+
this._textMetrics = Object.assign({}, TextMetricsCache.measure(context, this.text));
|
|
348
386
|
this._height = this._textMetrics.actualBoundingBoxAscent + this._textMetrics.actualBoundingBoxDescent;
|
|
349
387
|
this._width = this._textMetrics.width;
|
|
350
388
|
this.metricsValid = true;
|
|
@@ -358,7 +396,7 @@ export class Element {
|
|
|
358
396
|
return 0;
|
|
359
397
|
}
|
|
360
398
|
context.font = Font.toCSSString(Metrics.getFontInfo(key));
|
|
361
|
-
return
|
|
399
|
+
return TextMetricsCache.measure(context, text).width;
|
|
362
400
|
}
|
|
363
401
|
getTextMetrics() {
|
|
364
402
|
return this.textMetrics;
|
|
@@ -383,13 +421,13 @@ export class Element {
|
|
|
383
421
|
}
|
|
384
422
|
setOriginX(x) {
|
|
385
423
|
const bbox = this.getBoundingBox();
|
|
386
|
-
const originX = Math.abs((bbox.getX() - this.xShift) / bbox.getW());
|
|
424
|
+
const originX = Math.abs((bbox.getX() - this.x - this.xShift) / bbox.getW());
|
|
387
425
|
const xShift = (x - originX) * bbox.getW();
|
|
388
426
|
this.xShift = -xShift;
|
|
389
427
|
}
|
|
390
428
|
setOriginY(y) {
|
|
391
429
|
const bbox = this.getBoundingBox();
|
|
392
|
-
const originY = Math.abs((bbox.getY() - this.yShift) / bbox.getH());
|
|
430
|
+
const originY = Math.abs((bbox.getY() - this.y - this.yShift) / bbox.getH());
|
|
393
431
|
const yShift = (y - originY) * bbox.getH();
|
|
394
432
|
this.yShift = -yShift;
|
|
395
433
|
}
|
package/build/esm/src/factory.js
CHANGED
|
@@ -21,6 +21,7 @@ import { Ornament } from './ornament.js';
|
|
|
21
21
|
import { PedalMarking } from './pedalmarking.js';
|
|
22
22
|
import { Renderer } from './renderer.js';
|
|
23
23
|
import { RepeatNote } from './repeatnote.js';
|
|
24
|
+
import { Sheet } from './sheet.js';
|
|
24
25
|
import { Stave } from './stave.js';
|
|
25
26
|
import { StaveConnector } from './staveconnector.js';
|
|
26
27
|
import { StaveLine } from './staveline.js';
|
|
@@ -49,6 +50,8 @@ export class Factory {
|
|
|
49
50
|
return new Factory({ renderer: { elementId, width, height } });
|
|
50
51
|
}
|
|
51
52
|
constructor(options = {}) {
|
|
53
|
+
this.retained = false;
|
|
54
|
+
this.style = {};
|
|
52
55
|
L('New factory: ', options);
|
|
53
56
|
this.options = {
|
|
54
57
|
stave: {
|
|
@@ -64,6 +67,8 @@ export class Factory {
|
|
|
64
67
|
this.setOptions(options);
|
|
65
68
|
}
|
|
66
69
|
reset() {
|
|
70
|
+
this.sheets = [];
|
|
71
|
+
this.retained = false;
|
|
67
72
|
this.renderQ = [];
|
|
68
73
|
this.systems = [];
|
|
69
74
|
this.staves = [];
|
|
@@ -109,6 +114,15 @@ export class Factory {
|
|
|
109
114
|
getVoices() {
|
|
110
115
|
return this.voices;
|
|
111
116
|
}
|
|
117
|
+
setStyle(style) {
|
|
118
|
+
this.style = Object.assign({}, style);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
Sheet(options = {}) {
|
|
122
|
+
const sheet = new Sheet(Object.assign(Object.assign({}, options), { factory: this }));
|
|
123
|
+
this.sheets.push(sheet);
|
|
124
|
+
return sheet;
|
|
125
|
+
}
|
|
112
126
|
Stave(params) {
|
|
113
127
|
const staveSpace = this.options.stave.space;
|
|
114
128
|
const p = Object.assign({ x: 0, y: 0, width: this.options.renderer.width - staveSpace * 1.0, options: { spacingBetweenLinesPx: staveSpace * 1.0 } }, params);
|
|
@@ -447,17 +461,40 @@ export class Factory {
|
|
|
447
461
|
group.setContext(this.context);
|
|
448
462
|
return group;
|
|
449
463
|
}
|
|
450
|
-
draw() {
|
|
464
|
+
draw(options = {}) {
|
|
465
|
+
var _a;
|
|
451
466
|
const ctx = this.context;
|
|
452
|
-
this.
|
|
453
|
-
this.
|
|
454
|
-
this.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
e.setContext(ctx).drawWithStyle();
|
|
467
|
+
this.sheets.forEach((sheet) => sheet.format());
|
|
468
|
+
const managed = new Set(this.sheets.flatMap((sheet) => sheet.getSystems()));
|
|
469
|
+
this.systems.forEach((s) => {
|
|
470
|
+
if (!managed.has(s))
|
|
471
|
+
s.setContext(ctx).format();
|
|
458
472
|
});
|
|
459
|
-
|
|
460
|
-
|
|
473
|
+
const defaults = ctx.getDefaultStyle();
|
|
474
|
+
ctx.save();
|
|
475
|
+
ctx.setDefaultStyle(this.style);
|
|
476
|
+
if (this.style.fillStyle !== undefined)
|
|
477
|
+
ctx.setFillStyle(this.style.fillStyle);
|
|
478
|
+
if (this.style.strokeStyle !== undefined)
|
|
479
|
+
ctx.setStrokeStyle(this.style.strokeStyle);
|
|
480
|
+
if (this.retained)
|
|
481
|
+
this.renderQ.forEach((element) => element.setRendered(false));
|
|
482
|
+
try {
|
|
483
|
+
this.staves.forEach((s) => s.setContext(ctx).drawWithStyle());
|
|
484
|
+
this.voices.forEach((v) => v.setContext(ctx).drawWithStyle());
|
|
485
|
+
this.renderQ.forEach((e) => {
|
|
486
|
+
if (!e.isRendered())
|
|
487
|
+
e.setContext(ctx).drawWithStyle();
|
|
488
|
+
});
|
|
489
|
+
this.systems.forEach((s) => s.setContext(ctx).drawWithStyle());
|
|
490
|
+
}
|
|
491
|
+
finally {
|
|
492
|
+
ctx.setDefaultStyle(defaults);
|
|
493
|
+
ctx.restore();
|
|
494
|
+
}
|
|
495
|
+
this.retained = (_a = options.retain) !== null && _a !== void 0 ? _a : false;
|
|
496
|
+
if (!options.retain)
|
|
497
|
+
this.reset();
|
|
461
498
|
}
|
|
462
499
|
}
|
|
463
500
|
Factory.DEBUG = false;
|
package/build/esm/src/flag.js
CHANGED
|
@@ -11,9 +11,11 @@ export class Flag extends Element {
|
|
|
11
11
|
draw() {
|
|
12
12
|
const ctx = this.checkContext();
|
|
13
13
|
this.setRendered();
|
|
14
|
-
|
|
14
|
+
const clsAttribute = this.getAttribute('class');
|
|
15
|
+
ctx.openGroup('flag' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
15
16
|
L("Drawing flag '", this.text, "' at", this.x, this.y);
|
|
16
17
|
this.renderText(ctx, 0, 0);
|
|
18
|
+
this.drawPointerRect();
|
|
17
19
|
ctx.closeGroup();
|
|
18
20
|
}
|
|
19
21
|
}
|
package/build/esm/src/font.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Metrics } from './metrics.js';
|
|
11
|
+
import { TextMetricsCache } from './textmetricscache.js';
|
|
11
12
|
export var FontWeight;
|
|
12
13
|
(function (FontWeight) {
|
|
13
14
|
FontWeight["NORMAL"] = "normal";
|
|
@@ -185,7 +186,8 @@ export class Font {
|
|
|
185
186
|
fontFaceSet = self.fonts;
|
|
186
187
|
}
|
|
187
188
|
fontFaceSet === null || fontFaceSet === void 0 ? void 0 : fontFaceSet.add(fontFace);
|
|
188
|
-
|
|
189
|
+
TextMetricsCache.clear();
|
|
190
|
+
return fontFaceLoadPromise.finally(() => TextMetricsCache.clear());
|
|
189
191
|
});
|
|
190
192
|
}
|
|
191
193
|
static getURLForFont(fontName) {
|
|
@@ -196,6 +198,23 @@ export class Font {
|
|
|
196
198
|
return Font.HOST_URL + files[fontName];
|
|
197
199
|
}
|
|
198
200
|
}
|
|
201
|
+
Font.TEXT_FONT_NAMES = [
|
|
202
|
+
'Academico',
|
|
203
|
+
'Edwin',
|
|
204
|
+
'Bravura Text',
|
|
205
|
+
'Finale Ash Text',
|
|
206
|
+
'Finale Broadway Text',
|
|
207
|
+
'Finale Jazz Text',
|
|
208
|
+
'Finale Maestro Text',
|
|
209
|
+
'Gootville Text',
|
|
210
|
+
'Leland Text',
|
|
211
|
+
'MuseJazz Text',
|
|
212
|
+
'Nepomuk',
|
|
213
|
+
'Petaluma Script',
|
|
214
|
+
'Petaluma Text',
|
|
215
|
+
'Roboto Slab',
|
|
216
|
+
'Sebastian Text',
|
|
217
|
+
];
|
|
199
218
|
Font.scaleToPxFrom = {
|
|
200
219
|
pt: 4 / 3,
|
|
201
220
|
px: 1,
|