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.
Files changed (162) hide show
  1. package/README.md +7 -6
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +5325 -1730
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +4228 -1545
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/accidental.js +13 -3
  13. package/build/esm/src/articulation.js +51 -20
  14. package/build/esm/src/beam.js +170 -30
  15. package/build/esm/src/bend.js +24 -19
  16. package/build/esm/src/clef.js +3 -0
  17. package/build/esm/src/clefnote.js +5 -1
  18. package/build/esm/src/curve.js +27 -53
  19. package/build/esm/src/dot.js +14 -5
  20. package/build/esm/src/easyscore/composition.js +336 -0
  21. package/build/esm/src/easyscore/elementindex.js +81 -0
  22. package/build/esm/src/easyscore/elements.js +324 -0
  23. package/build/esm/src/easyscore/policies.js +97 -0
  24. package/build/esm/src/easyscore/rhythm.js +42 -0
  25. package/build/esm/src/easyscore.js +448 -26
  26. package/build/esm/src/element.js +17 -2
  27. package/build/esm/src/engravinggeometry.js +150 -0
  28. package/build/esm/src/engravingprofile.js +44 -0
  29. package/build/esm/src/factory.js +268 -64
  30. package/build/esm/src/formatter.js +40 -4
  31. package/build/esm/src/gracenote.js +43 -38
  32. package/build/esm/src/gracenotegroup.js +53 -56
  33. package/build/esm/src/index.js +2 -0
  34. package/build/esm/src/keysignature.js +10 -2
  35. package/build/esm/src/keysignote.js +2 -2
  36. package/build/esm/src/modifiercontext.js +11 -0
  37. package/build/esm/src/note.js +5 -0
  38. package/build/esm/src/notehead.js +11 -6
  39. package/build/esm/src/ornament.js +38 -18
  40. package/build/esm/src/parenthesis.js +1 -1
  41. package/build/esm/src/parser.js +6 -1
  42. package/build/esm/src/proportionalformatter.js +234 -0
  43. package/build/esm/src/registry.js +27 -0
  44. package/build/esm/src/sheet.js +20 -3
  45. package/build/esm/src/stave.js +9 -2
  46. package/build/esm/src/stavenote.js +140 -127
  47. package/build/esm/src/stavetie.js +39 -7
  48. package/build/esm/src/stem.js +26 -11
  49. package/build/esm/src/stemmablenote.js +6 -1
  50. package/build/esm/src/tickable.js +5 -0
  51. package/build/esm/src/tickcontext.js +19 -0
  52. package/build/esm/src/timesignature.js +5 -0
  53. package/build/esm/src/tuplet.js +60 -19
  54. package/build/esm/src/version.js +3 -3
  55. package/build/esm/src/vexflow.js +6 -1
  56. package/build/esm/tests/beam_tests.js +35 -0
  57. package/build/esm/tests/bend_tests.js +14 -1
  58. package/build/esm/tests/curve_tests.js +14 -4
  59. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  60. package/build/esm/tests/demos/drums.js +54 -0
  61. package/build/esm/tests/demos/electric.js +63 -0
  62. package/build/esm/tests/demos/greensleeves.js +90 -0
  63. package/build/esm/tests/demos/joy.js +61 -0
  64. package/build/esm/tests/demos/kesh.js +80 -0
  65. package/build/esm/tests/demos/prelude.js +59 -0
  66. package/build/esm/tests/demos/quartertones.js +50 -0
  67. package/build/esm/tests/demos/saints.js +65 -0
  68. package/build/esm/tests/easyscore_tests.js +40 -0
  69. package/build/esm/tests/easyscore_types.js +65 -0
  70. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  71. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  72. package/build/esm/tests/engraving/studies.mjs +279 -0
  73. package/build/esm/tests/formatter_tests.js +51 -1
  74. package/build/esm/tests/index.js +1 -0
  75. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  76. package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
  77. package/build/esm/tests/node/easyscore-tests.mjs +1024 -0
  78. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  79. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  80. package/build/esm/tests/node/proportional-spacing-tests.mjs +278 -0
  81. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  82. package/build/esm/tests/threevoice_tests.js +11 -1
  83. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  84. package/build/esm/tools/audit-dependencies.mjs +61 -0
  85. package/build/esm/tools/easyscore-api-audit.mjs +58 -0
  86. package/build/esm/tools/easyscore-composition.mjs +62 -0
  87. package/build/esm/tools/easyscore-example.mjs +16 -0
  88. package/build/esm/tools/easyscore-families.mjs +61 -0
  89. package/build/esm/tools/easyscore-references-example.mjs +26 -0
  90. package/build/esm/tools/easyscore-rhythm.mjs +58 -0
  91. package/build/esm/tools/easyscore-structure.mjs +88 -0
  92. package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
  93. package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
  94. package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
  95. package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
  96. package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
  97. package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
  98. package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
  99. package/build/esm/tools/explorer/catalog.mjs +14 -0
  100. package/build/esm/tools/score-fixtures.mjs +23 -6
  101. package/build/types/src/accidental.d.ts +6 -0
  102. package/build/types/src/articulation.d.ts +12 -1
  103. package/build/types/src/beam.d.ts +16 -0
  104. package/build/types/src/clef.d.ts +2 -0
  105. package/build/types/src/curve.d.ts +9 -0
  106. package/build/types/src/dot.d.ts +5 -0
  107. package/build/types/src/easyscore/composition.d.ts +126 -0
  108. package/build/types/src/easyscore/elementindex.d.ts +30 -0
  109. package/build/types/src/easyscore/elements.d.ts +156 -0
  110. package/build/types/src/easyscore/policies.d.ts +12 -0
  111. package/build/types/src/easyscore/rhythm.d.ts +9 -0
  112. package/build/types/src/easyscore.d.ts +153 -11
  113. package/build/types/src/element.d.ts +7 -1
  114. package/build/types/src/engravinggeometry.d.ts +31 -0
  115. package/build/types/src/engravingprofile.d.ts +20 -0
  116. package/build/types/src/factory.d.ts +97 -9
  117. package/build/types/src/formatter.d.ts +7 -1
  118. package/build/types/src/gracenote.d.ts +7 -0
  119. package/build/types/src/gracenotegroup.d.ts +7 -2
  120. package/build/types/src/index.d.ts +2 -0
  121. package/build/types/src/keysignature.d.ts +3 -0
  122. package/build/types/src/keysignote.d.ts +1 -1
  123. package/build/types/src/modifiercontext.d.ts +4 -0
  124. package/build/types/src/note.d.ts +2 -0
  125. package/build/types/src/notehead.d.ts +5 -0
  126. package/build/types/src/ornament.d.ts +7 -0
  127. package/build/types/src/parser.d.ts +5 -0
  128. package/build/types/src/proportionalformatter.d.ts +39 -0
  129. package/build/types/src/registry.d.ts +4 -0
  130. package/build/types/src/stave.d.ts +2 -0
  131. package/build/types/src/stavenote.d.ts +21 -3
  132. package/build/types/src/stavetie.d.ts +4 -0
  133. package/build/types/src/stem.d.ts +10 -1
  134. package/build/types/src/stemmablenote.d.ts +6 -1
  135. package/build/types/src/tickable.d.ts +2 -0
  136. package/build/types/src/tickcontext.d.ts +5 -0
  137. package/build/types/src/timesignature.d.ts +2 -0
  138. package/build/types/src/tuplet.d.ts +5 -48
  139. package/build/types/src/vexflow.d.ts +6 -1
  140. package/changelog/CHANGELOG.md +52 -0
  141. package/package.json +13 -3
  142. package/tests/all.html +277 -0
  143. package/tests/demo_petzold_tests.ts +435 -0
  144. package/tests/demos/drums.ts +55 -0
  145. package/tests/demos/drums.webp +0 -0
  146. package/tests/demos/electric.ts +70 -0
  147. package/tests/demos/electric.webp +0 -0
  148. package/tests/demos/greensleeves.ts +97 -0
  149. package/tests/demos/greensleeves.webp +0 -0
  150. package/tests/demos/joy.ts +65 -0
  151. package/tests/demos/joy.webp +0 -0
  152. package/tests/demos/kesh.ts +86 -0
  153. package/tests/demos/kesh.webp +0 -0
  154. package/tests/demos/prelude.ts +65 -0
  155. package/tests/demos/prelude.webp +0 -0
  156. package/tests/demos/quartertones.ts +51 -0
  157. package/tests/demos/quartertones.webp +0 -0
  158. package/tests/demos/saints.ts +70 -0
  159. package/tests/demos/saints.webp +0 -0
  160. package/tests/flow.html +550 -239
  161. package/tests/fonts.css +493 -0
  162. 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
+ }