@mcqj/vexflow 0.0.1-alpha.8 → 0.0.1-alpha.9
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 +1 -1
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +1 -1
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +54 -7
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +23 -7
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +1 -1
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/formatter.js +26 -2
- package/build/esm/src/version.js +2 -2
- package/build/esm/tests/formatter_tests.js +26 -0
- package/build/playwright-artifacts/.last-run.json +4 -0
- package/build/playwright-report/index.html +49 -0
- package/build/types/src/formatter.d.ts +3 -1
- package/package.json +10 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! VexFlow 0.0.1-alpha.8 2026-11-
|
|
1
|
+
/*! VexFlow 0.0.1-alpha.8 2026-11-23T01:19:49.490Z beeb3933573a1cbf00a85d294d8524fabba6f406
|
|
2
2
|
Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/vexflow/blob/main/AUTHORS.md). */
|
|
3
3
|
(function(global, factory) {
|
|
4
4
|
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define([], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.VexFlow = factory());
|
|
@@ -14395,6 +14395,7 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
14395
14395
|
const contexts = this.tickContexts;
|
|
14396
14396
|
if (!contexts) throw new RuntimeError("NoTickContexts", "preFormat requires TickContexts");
|
|
14397
14397
|
const { spacingList: contextList, map: contextMap } = contexts;
|
|
14398
|
+
this.justifyWidth = justifyWidth;
|
|
14398
14399
|
this.lossHistory = [];
|
|
14399
14400
|
if (voicesParam && stave) voicesParam.forEach((voice) => voice.setStave(stave).preFormat());
|
|
14400
14401
|
let x = 0;
|
|
@@ -14533,7 +14534,6 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
14533
14534
|
actualWidth = shiftToIdealDistances(calculateIdealDistances(targetWidth));
|
|
14534
14535
|
iterations--;
|
|
14535
14536
|
}
|
|
14536
|
-
this.justifyWidth = justifyWidth;
|
|
14537
14537
|
this.positionDependentContexts();
|
|
14538
14538
|
return this.evaluate();
|
|
14539
14539
|
}
|
|
@@ -14543,13 +14543,21 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
14543
14543
|
* Dependent voices follow the layout of the other voices, so their contexts
|
|
14544
14544
|
* are not part of the spacing list. Instead, place each one between the
|
|
14545
14545
|
* surrounding spacing contexts, interpolating by tick. Contexts before the
|
|
14546
|
-
* first
|
|
14546
|
+
* first spacing context are aligned with it, and trailing contexts are
|
|
14547
|
+
* interpolated across the final note's remaining duration toward the end of
|
|
14548
|
+
* the justified layout.
|
|
14547
14549
|
*/
|
|
14548
14550
|
positionDependentContexts() {
|
|
14549
14551
|
const contexts = this.tickContexts;
|
|
14550
14552
|
if (!contexts) return;
|
|
14551
14553
|
const { spacingList, dependentList, map } = contexts;
|
|
14552
14554
|
if (spacingList.length === 0 || dependentList.length === 0) return;
|
|
14555
|
+
const firstSpacingContext = map[spacingList[0]];
|
|
14556
|
+
const lastSpacingTick = spacingList[spacingList.length - 1];
|
|
14557
|
+
const lastSpacingContext = map[lastSpacingTick];
|
|
14558
|
+
const finalTick = lastSpacingTick + lastSpacingContext.getMaxTicks().value();
|
|
14559
|
+
const centerX = this.justifyWidth > 0 ? (this.justifyWidth - lastSpacingContext.getMetrics().notePx - lastSpacingContext.getMetrics().totalRightPx - firstSpacingContext.getMetrics().totalLeftPx) / 2 : void 0;
|
|
14560
|
+
const endX = this.justifyWidth > 0 ? this.justifyWidth : void 0;
|
|
14553
14561
|
let nextIndex = 0;
|
|
14554
14562
|
dependentList.forEach((tick) => {
|
|
14555
14563
|
while (nextIndex < spacingList.length && spacingList[nextIndex] < tick) nextIndex++;
|
|
@@ -14562,8 +14570,16 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
14562
14570
|
const nextX = map[nextTick].getX();
|
|
14563
14571
|
const ratio = (tick - prevTick) / (nextTick - prevTick);
|
|
14564
14572
|
context.setX(prevX + (nextX - prevX) * ratio);
|
|
14565
|
-
} else if (prevTick !== void 0)
|
|
14566
|
-
|
|
14573
|
+
} else if (prevTick !== void 0) {
|
|
14574
|
+
const prevX = map[prevTick].getX();
|
|
14575
|
+
if (endX !== void 0 && finalTick > prevTick) {
|
|
14576
|
+
const ratio = Math.min(1, (tick - prevTick) / (finalTick - prevTick));
|
|
14577
|
+
context.setX(prevX + (endX - prevX) * ratio);
|
|
14578
|
+
} else context.setX(prevX);
|
|
14579
|
+
} else if (nextTick !== void 0) context.setX(map[nextTick].getX());
|
|
14580
|
+
if (centerX !== void 0) context.getCenterAlignedTickables().forEach((tickable) => {
|
|
14581
|
+
tickable.setCenterXShift(centerX - context.getX());
|
|
14582
|
+
});
|
|
14567
14583
|
});
|
|
14568
14584
|
}
|
|
14569
14585
|
/** Calculate the total cost of this formatting decision. */
|
|
@@ -18703,8 +18719,8 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
18703
18719
|
};
|
|
18704
18720
|
// src/version.ts
|
|
18705
18721
|
var VERSION = "0.0.1-alpha.8";
|
|
18706
|
-
var ID = "
|
|
18707
|
-
var DATE = "2026-11-
|
|
18722
|
+
var ID = "beeb3933573a1cbf00a85d294d8524fabba6f406";
|
|
18723
|
+
var DATE = "2026-11-23T01:19:49.490Z";
|
|
18708
18724
|
// src/vexflow.ts
|
|
18709
18725
|
var VexFlow = class {
|
|
18710
18726
|
static {
|
|
@@ -27455,6 +27471,7 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
27455
27471
|
VexFlowTests.test("Inline clef and time signatures preserve note spacing", inlineSpacersPreserveNoteSpacing);
|
|
27456
27472
|
VexFlowTests.test("Dependent voices do not affect music layout", dependentVoicesDoNotAffectMusicLayout);
|
|
27457
27473
|
VexFlowTests.test("Off-grid dependent voices do not affect music layout", dependentOffGridVoicesDoNotAffectMusicLayout);
|
|
27474
|
+
VexFlowTests.test("Off-grid dependent voices honor center alignment", dependentOffGridVoicesCenterAlign);
|
|
27458
27475
|
run("Proportional Formatting - No Tuning", proportional, {
|
|
27459
27476
|
debug: true,
|
|
27460
27477
|
iterations: 0
|
|
@@ -27594,6 +27611,36 @@ Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/
|
|
|
27594
27611
|
musicNotes.forEach((note, index) => assert.strictEqual(note.getX(), baselineNotes[index].getX()));
|
|
27595
27612
|
assert.ok(lyricNotes[1].getX() > musicNotes[0].getX());
|
|
27596
27613
|
assert.ok(lyricNotes[1].getX() < musicNotes[1].getX());
|
|
27614
|
+
const lastMusicX = musicNotes[3].getX();
|
|
27615
|
+
const trailingLyricX = lyricNotes[13].getX();
|
|
27616
|
+
const lastLyricX = lyricNotes[15].getX();
|
|
27617
|
+
assert.ok(trailingLyricX > lastMusicX, "First trailing lyric should follow the final music onset.");
|
|
27618
|
+
assert.ok(lastLyricX > trailingLyricX, "Trailing lyrics should not overlap.");
|
|
27619
|
+
assert.ok(lastLyricX < 500, "Trailing lyrics should stay within the justified width.");
|
|
27620
|
+
}
|
|
27621
|
+
function dependentOffGridVoicesCenterAlign(assert) {
|
|
27622
|
+
const musicNotes = Array.from({ length: 4 }, () => new StaveNote({
|
|
27623
|
+
keys: ["c/4"],
|
|
27624
|
+
duration: "4"
|
|
27625
|
+
}));
|
|
27626
|
+
const musicVoice = new Voice("4/4").addTickables(musicNotes);
|
|
27627
|
+
const centered = new TextNote({
|
|
27628
|
+
text: "x",
|
|
27629
|
+
duration: "16",
|
|
27630
|
+
alignCenter: true
|
|
27631
|
+
});
|
|
27632
|
+
const lyricNotes = Array.from({ length: 16 }, (_, i) => i === 5 ? centered : new GhostNote({ duration: "16" }));
|
|
27633
|
+
const lyricVoice = new Voice("4/4").setMode(Voice.Mode.SOFT).setDependent(true).addTickables(lyricNotes);
|
|
27634
|
+
const formatter = new Formatter().joinVoices([musicVoice, lyricVoice]);
|
|
27635
|
+
formatter.format([musicVoice, lyricVoice], 500);
|
|
27636
|
+
const tickContexts = formatter.getTickContexts();
|
|
27637
|
+
assert.ok(tickContexts);
|
|
27638
|
+
if (!tickContexts) return;
|
|
27639
|
+
const firstContext = tickContexts.map[tickContexts.spacingList[0]];
|
|
27640
|
+
const lastContext = tickContexts.map[tickContexts.spacingList[tickContexts.spacingList.length - 1]];
|
|
27641
|
+
const expectedCenterXShift = (500 - lastContext.getMetrics().notePx - lastContext.getMetrics().totalRightPx - firstContext.getMetrics().totalLeftPx) / 2 - centered.getTickContext().getX();
|
|
27642
|
+
assert.ok(expectedCenterXShift !== 0);
|
|
27643
|
+
assert.ok(Math.abs(centered.getCenterXShift() - expectedCenterXShift) < 1e-9, "Center-aligned dependent tickables should use the same justified center as spacing tickables.");
|
|
27597
27644
|
}
|
|
27598
27645
|
function getResolutionMultiplier(assert) {
|
|
27599
27646
|
const [voice1, voice2] = getTestVoices();
|