vexflow 5.3.0 → 5.4.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 (115) hide show
  1. package/README.md +2 -0
  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 +4189 -772
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +4323 -906
  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/alternatingtremolo.js +68 -0
  13. package/build/esm/src/annotation.js +19 -3
  14. package/build/esm/src/articulation.js +5 -1
  15. package/build/esm/src/beam.js +13 -0
  16. package/build/esm/src/bend.js +57 -6
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/continuouslayout.js +681 -0
  19. package/build/esm/src/continuousspan.js +159 -0
  20. package/build/esm/src/curve.js +21 -2
  21. package/build/esm/src/easyscore/composition.js +13 -2
  22. package/build/esm/src/easyscore/policies.js +6 -3
  23. package/build/esm/src/engravinggeometry.js +8 -1
  24. package/build/esm/src/factory.js +16 -4
  25. package/build/esm/src/font.js +9 -1
  26. package/build/esm/src/fretdiagram.js +77 -0
  27. package/build/esm/src/guitargesture.js +33 -0
  28. package/build/esm/src/guitarmodifiers.js +26 -0
  29. package/build/esm/src/index.js +8 -0
  30. package/build/esm/src/instrumentprofile.js +123 -0
  31. package/build/esm/src/keysignature.js +23 -1
  32. package/build/esm/src/notationspelling.js +73 -0
  33. package/build/esm/src/note.js +3 -0
  34. package/build/esm/src/ornament.js +5 -0
  35. package/build/esm/src/pagebreaks.js +58 -0
  36. package/build/esm/src/pedalmarking.js +39 -17
  37. package/build/esm/src/phraselayout.js +503 -0
  38. package/build/esm/src/phraseribbon.js +28 -0
  39. package/build/esm/src/publication.js +402 -0
  40. package/build/esm/src/publicationview.js +114 -0
  41. package/build/esm/src/scorenavigation.js +172 -0
  42. package/build/esm/src/sheet.js +14 -2
  43. package/build/esm/src/stave.js +33 -16
  44. package/build/esm/src/stavebarline.js +5 -7
  45. package/build/esm/src/staveconnector.js +1 -0
  46. package/build/esm/src/stavehairpin.js +53 -27
  47. package/build/esm/src/stavenote.js +6 -1
  48. package/build/esm/src/stavetie.js +27 -2
  49. package/build/esm/src/strokes.js +4 -0
  50. package/build/esm/src/system.js +19 -4
  51. package/build/esm/src/systembreaks.js +42 -0
  52. package/build/esm/src/tabnote.js +6 -1
  53. package/build/esm/src/textbracket.js +24 -5
  54. package/build/esm/src/timesignature.js +15 -6
  55. package/build/esm/src/tuplet.js +1 -0
  56. package/build/esm/src/version.js +3 -3
  57. package/build/esm/src/vexflow.js +16 -0
  58. package/build/esm/src/voice.js +7 -3
  59. package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
  60. package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
  61. package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
  62. package/build/esm/tests/engraving/publication-studies.mjs +87 -0
  63. package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
  64. package/build/esm/tests/engraving/studies.mjs +88 -0
  65. package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
  66. package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
  67. package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
  68. package/build/esm/tests/node/publication-tests.mjs +219 -0
  69. package/build/esm/tools/easyscore-structure.mjs +1 -1
  70. package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
  71. package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
  72. package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
  73. package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
  74. package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
  75. package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
  76. package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
  77. package/build/types/src/alternatingtremolo.d.ts +13 -0
  78. package/build/types/src/annotation.d.ts +9 -0
  79. package/build/types/src/articulation.d.ts +3 -0
  80. package/build/types/src/beam.d.ts +2 -0
  81. package/build/types/src/bend.d.ts +8 -0
  82. package/build/types/src/clef.d.ts +3 -0
  83. package/build/types/src/continuouslayout.d.ts +103 -0
  84. package/build/types/src/continuousspan.d.ts +60 -0
  85. package/build/types/src/curve.d.ts +11 -0
  86. package/build/types/src/easyscore/composition.d.ts +8 -0
  87. package/build/types/src/easyscore/policies.d.ts +1 -1
  88. package/build/types/src/fretdiagram.d.ts +23 -0
  89. package/build/types/src/guitargesture.d.ts +26 -0
  90. package/build/types/src/guitarmodifiers.d.ts +3 -0
  91. package/build/types/src/index.d.ts +10 -0
  92. package/build/types/src/instrumentprofile.d.ts +124 -0
  93. package/build/types/src/keysignature.d.ts +9 -0
  94. package/build/types/src/notationspelling.d.ts +25 -0
  95. package/build/types/src/note.d.ts +15 -0
  96. package/build/types/src/ornament.d.ts +3 -1
  97. package/build/types/src/pagebreaks.d.ts +26 -0
  98. package/build/types/src/pedalmarking.d.ts +9 -0
  99. package/build/types/src/phraselayout.d.ts +87 -0
  100. package/build/types/src/phraseribbon.d.ts +7 -0
  101. package/build/types/src/publication.d.ts +61 -0
  102. package/build/types/src/publicationview.d.ts +27 -0
  103. package/build/types/src/scorenavigation.d.ts +33 -0
  104. package/build/types/src/sheet.d.ts +5 -0
  105. package/build/types/src/stave.d.ts +13 -0
  106. package/build/types/src/stavehairpin.d.ts +18 -0
  107. package/build/types/src/stavetie.d.ts +5 -0
  108. package/build/types/src/system.d.ts +8 -1
  109. package/build/types/src/systembreaks.d.ts +9 -0
  110. package/build/types/src/textbracket.d.ts +7 -0
  111. package/build/types/src/timesignature.d.ts +4 -0
  112. package/build/types/src/vexflow.d.ts +16 -0
  113. package/build/types/src/voice.d.ts +2 -0
  114. package/changelog/CHANGELOG.md +8 -0
  115. package/package.json +9 -2
@@ -0,0 +1,68 @@
1
+ import { Element } from './element.js';
2
+ import { Fraction } from './fraction.js';
3
+ import { Tables } from './tables.js';
4
+ import { RuntimeError } from './util.js';
5
+ export class AlternatingTremolo extends Element {
6
+ constructor(first, last, strokes) {
7
+ super();
8
+ this.first = first;
9
+ this.last = last;
10
+ this.strokes = strokes;
11
+ if (!Number.isInteger(strokes) || strokes < 1 || strokes > 3)
12
+ throw new RuntimeError('BadArguments', 'Expected one to three tremolo strokes.');
13
+ }
14
+ static endpoint(note, strokes) {
15
+ var _a;
16
+ const denominator = Number(Tables.sanitizeDuration(note.duration));
17
+ if (![2, 4].includes(denominator) ||
18
+ note.dots ||
19
+ note.durationOverride ||
20
+ note.type === 'r' ||
21
+ !Number.isInteger(strokes) ||
22
+ strokes < 1 ||
23
+ strokes > 3)
24
+ throw new RuntimeError('BadArguments', 'Expected an undotted half or quarter tremolo endpoint.');
25
+ return Object.assign(Object.assign({}, note), { durationOverride: new Fraction(1, denominator * 2), notation: [
26
+ ...((_a = note.notation) !== null && _a !== void 0 ? _a : []),
27
+ {
28
+ kind: 'tremolo',
29
+ id: 'alternating-' + strokes,
30
+ label: 'Alternating tremolo, ' + strokes + (strokes === 1 ? ' stroke' : ' strokes'),
31
+ },
32
+ ] });
33
+ }
34
+ draw() {
35
+ const { first, last, strokes } = this;
36
+ const voice = first.getVoice();
37
+ const notes = voice.getTickables();
38
+ if (first.checkStave() !== last.checkStave() ||
39
+ last.getVoice() !== voice ||
40
+ notes[notes.indexOf(first) + 1] !== last ||
41
+ first.getDuration() !== last.getDuration() ||
42
+ first.getStemDirection() !== last.getStemDirection() ||
43
+ ![first, last].every((n) => n.getIntrinsicTicks() === Tables.durationToTicks(n.getDuration()) / 2 &&
44
+ n.notation.some((entry) => entry.kind === 'tremolo' && entry.id === 'alternating-' + strokes)))
45
+ throw new RuntimeError('BadArguments', 'Expected adjacent matching tremolo endpoints with parallel stems on one staff.');
46
+ const ctx = this.checkContext();
47
+ const spacing = first.checkStave().getSpacingBetweenLines();
48
+ const x1 = first.getStemX(), x2 = last.getStemX();
49
+ const inset = Math.min(spacing * 0.4, (x2 - x1) / 5);
50
+ const direction = first.getStemDirection();
51
+ const y1 = first.getStemExtents().topY, y2 = last.getStemExtents().topY;
52
+ const slopeInset = ((y2 - y1) * inset) / (x2 - x1);
53
+ ctx.openGroup('alternating-tremolo', this.getAttribute('id'));
54
+ for (let i = 0; i < strokes; i++) {
55
+ const offset = direction * spacing * (0.2 + i * 0.68);
56
+ const thickness = direction * spacing * 0.42;
57
+ ctx.beginPath();
58
+ ctx.moveTo(x1 + inset, y1 + slopeInset + offset);
59
+ ctx.lineTo(x2 - inset, y2 - slopeInset + offset);
60
+ ctx.lineTo(x2 - inset, y2 - slopeInset + offset + thickness);
61
+ ctx.lineTo(x1 + inset, y1 + slopeInset + offset + thickness);
62
+ ctx.closePath();
63
+ ctx.fill();
64
+ }
65
+ ctx.closeGroup();
66
+ this.setRendered();
67
+ }
68
+ }
@@ -43,7 +43,7 @@ export class Annotation extends Modifier {
43
43
  let verticalSpaceNeeded = textLines;
44
44
  const note = annotation.checkAttachedNote();
45
45
  const glyphWidth = note.getGlyphWidth();
46
- const textWidth = annotation.getWidth();
46
+ const textWidth = annotation.getWidth() + 2 * annotation.connectorPadding;
47
47
  if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
48
48
  maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
49
49
  leftWidth = Math.max(leftWidth, textWidth) + Annotation.minAnnotationPadding;
@@ -132,6 +132,8 @@ export class Annotation extends Modifier {
132
132
  }
133
133
  constructor(text) {
134
134
  super();
135
+ this.phraseManaged = false;
136
+ this.connectorPadding = 0;
135
137
  this.text = text;
136
138
  this.horizontalJustification = AnnotationHorizontalJustify.CENTER;
137
139
  this.verticalJustification = AnnotationVerticalJustify.TOP;
@@ -150,6 +152,18 @@ export class Annotation extends Modifier {
150
152
  this.horizontalJustification = typeof just === 'string' ? Annotation.HorizontalJustifyString[just] : just;
151
153
  return this;
152
154
  }
155
+ setConnectorPadding(px) {
156
+ if (!Number.isFinite(px) || px < 0)
157
+ throw new RangeError('Expected nonnegative connector padding.');
158
+ this.connectorPadding = px;
159
+ return this;
160
+ }
161
+ getTextBaseline() {
162
+ return this.textBaseline;
163
+ }
164
+ setLayoutBaseline(y) {
165
+ this.layoutBaseline = y;
166
+ }
153
167
  setTextBaseline(y) {
154
168
  if (y !== undefined && !Number.isFinite(y)) {
155
169
  throw new RuntimeError('BadArgument', 'Text baseline must be finite.');
@@ -177,9 +191,11 @@ export class Annotation extends Modifier {
177
191
  return { x, textWidth };
178
192
  }
179
193
  computeY() {
194
+ var _a;
180
195
  const textHeight = Font.convertSizeToPixelValue(this.fontInfo.size);
181
- if (this.textBaseline !== undefined)
182
- return { y: this.textBaseline, textHeight };
196
+ const baseline = (_a = this.textBaseline) !== null && _a !== void 0 ? _a : this.layoutBaseline;
197
+ if (baseline !== undefined)
198
+ return { y: baseline, textHeight };
183
199
  const note = this.checkAttachedNote();
184
200
  const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
185
201
  let y;
@@ -226,6 +226,7 @@ export class Articulation extends Modifier {
226
226
  var _a;
227
227
  super();
228
228
  this.heightShift = 0;
229
+ this.layoutShiftY = 0;
229
230
  this.type = type;
230
231
  this.position = ABOVE;
231
232
  if (!Tables.articulationCodes(this.type)) {
@@ -254,6 +255,9 @@ export class Articulation extends Modifier {
254
255
  this.articulation = Object.assign(Object.assign({}, this.articulation), { betweenLines });
255
256
  return this;
256
257
  }
258
+ setLayoutShiftY(y) {
259
+ this.layoutShiftY = y;
260
+ }
257
261
  getPlacement() {
258
262
  const note = this.checkAttachedNote();
259
263
  let centered = false;
@@ -285,7 +289,7 @@ export class Articulation extends Modifier {
285
289
  centered = isWithinLines(snappedLine, position);
286
290
  y += Math.abs(snappedLine - articLine) * staffSpace * offsetDirection;
287
291
  }
288
- return { x, y, centered };
292
+ return { x, y: y + this.layoutShiftY, centered };
289
293
  }
290
294
  getInkBounds() {
291
295
  const { x, y, centered } = this.getPlacement();
@@ -714,6 +714,19 @@ export class Beam extends Element {
714
714
  beamY += thickness * 1.5;
715
715
  }
716
716
  }
717
+ getStripBounds() {
718
+ this.postFormat();
719
+ const parts = [];
720
+ for (const { x1, x2, y1, y2, thickness } of this.getStrips()) {
721
+ const count = Math.min(64, Math.max(1, Math.ceil(Math.abs(y2 - y1) / 2)));
722
+ for (let i = 0; i < count; i++) {
723
+ const x = x1 + ((x2 - x1) * i) / count, y = y1 + ((y2 - y1) * i) / count;
724
+ const dx = (x2 - x1) / count, dy = (y2 - y1) / count;
725
+ parts.push(new BoundingBox(x + Math.min(0, dx), y + Math.min(0, dy) + Math.min(0, thickness), Math.abs(dx), Math.abs(dy) + Math.abs(thickness)));
726
+ }
727
+ }
728
+ return parts;
729
+ }
717
730
  getBoundingBox() {
718
731
  this.postFormat();
719
732
  let box;
@@ -1,4 +1,5 @@
1
1
  import { Element } from './element.js';
2
+ import { bendAmount, copyBend } from './guitargesture.js';
2
3
  import { Metrics } from './metrics.js';
3
4
  import { Modifier } from './modifier.js';
4
5
  import { isTabNote } from './typeguard.js';
@@ -42,6 +43,13 @@ export class Bend extends Modifier {
42
43
  state.topTextLine += 1;
43
44
  return true;
44
45
  }
46
+ static timed(spec) {
47
+ const timing = copyBend(spec);
48
+ const bend = new Bend([{ type: Bend.UP, text: bendAmount(timing) }]);
49
+ bend.timing = timing;
50
+ bend.updateWidth();
51
+ return bend;
52
+ }
45
53
  setStyleLine(style) {
46
54
  this.styleLine = style;
47
55
  return this;
@@ -81,6 +89,10 @@ export class Bend extends Modifier {
81
89
  element.setText(text);
82
90
  return element.getWidth();
83
91
  };
92
+ if (this.timing) {
93
+ this.setWidth(this.xShift + Math.max(48, measureText(bendAmount(this.timing)) + 18));
94
+ return this;
95
+ }
84
96
  let totalWidth = 0;
85
97
  for (let i = 0; i < this.phrase.length; ++i) {
86
98
  const bend = this.phrase[i];
@@ -98,11 +110,14 @@ export class Bend extends Modifier {
98
110
  return this;
99
111
  }
100
112
  draw() {
101
- var _a, _b;
113
+ var _a, _b, _c;
102
114
  const ctx = this.checkContext();
103
115
  const note = this.checkAttachedNote();
116
+ const index = this.checkIndex();
117
+ if (this.timing && (!isTabNote(note) || ((_a = note.getPositions()[index]) === null || _a === void 0 ? void 0 : _a.str) !== this.timing.string))
118
+ throw new RuntimeError('BadArguments', 'Attach the timed bend to its authored TAB string.');
104
119
  this.setRendered();
105
- const start = note.getModifierStartXY(Modifier.Position.RIGHT, this.index);
120
+ const start = note.getModifierStartXY(Modifier.Position.RIGHT, index);
106
121
  start.x += 3;
107
122
  start.y += 0.5;
108
123
  const xShift = this.xShift;
@@ -142,16 +157,39 @@ export class Bend extends Modifier {
142
157
  const renderX = x - ctx.measureText(text).width / 2;
143
158
  ctx.fillText(text, renderX, annotationY);
144
159
  };
160
+ if (this.timing) {
161
+ const { rise, hold, release } = this.timing;
162
+ const left = start.x + xShift;
163
+ const extent = this.getWidth() - xShift;
164
+ const phaseX = ([n, d]) => left + (extent * n) / d;
165
+ const peak = phaseX(rise);
166
+ renderBend(left, start.y, peak - left, bendHeight);
167
+ renderArrowHead(peak, bendHeight, 1);
168
+ renderText(peak, bendAmount(this.timing));
169
+ const held = hold ? phaseX(hold) : peak;
170
+ if (hold) {
171
+ ctx.beginPath();
172
+ ctx.moveTo(peak, bendHeight);
173
+ ctx.lineTo(held, bendHeight);
174
+ ctx.stroke();
175
+ }
176
+ if (release) {
177
+ const end = phaseX(release);
178
+ renderRelease(held, start.y, end - held, bendHeight);
179
+ renderArrowHead(end, start.y, -1);
180
+ }
181
+ return;
182
+ }
145
183
  let lastBend = undefined;
146
184
  let lastBendDrawWidth = 0;
147
185
  let lastDrawnWidth = 0;
148
- if ((_a = this.tap) === null || _a === void 0 ? void 0 : _a.length) {
149
- const tapStart = note.getModifierStartXY(Modifier.Position.CENTER, this.index);
186
+ if ((_b = this.tap) === null || _b === void 0 ? void 0 : _b.length) {
187
+ const tapStart = note.getModifierStartXY(Modifier.Position.CENTER, index);
150
188
  renderText(tapStart.x, this.tap);
151
189
  }
152
190
  for (let i = 0; i < this.phrase.length; ++i) {
153
191
  const bend = this.phrase[i];
154
- const drawWidth = ((_b = bend.drawWidth) !== null && _b !== void 0 ? _b : 0) + (i === 0 ? xShift : 0);
192
+ const drawWidth = ((_c = bend.drawWidth) !== null && _c !== void 0 ? _c : 0) + (i === 0 ? xShift : 0);
155
193
  lastDrawnWidth = drawWidth + lastBendDrawWidth - (i === 1 ? xShift : 0);
156
194
  if (bend.type === Bend.UP) {
157
195
  if (lastBend && lastBend.type === Bend.UP) {
@@ -159,8 +197,19 @@ export class Bend extends Modifier {
159
197
  }
160
198
  renderBend(start.x, start.y, lastDrawnWidth, bendHeight);
161
199
  }
200
+ if (bend.type === Bend.PREBEND || bend.type === Bend.HOLD) {
201
+ this.applyStyle(ctx, this.styleLine);
202
+ ctx.beginPath();
203
+ ctx.moveTo(start.x, bend.type === Bend.PREBEND ? start.y : bendHeight);
204
+ if (bend.type === Bend.PREBEND)
205
+ ctx.lineTo(start.x, bendHeight);
206
+ ctx.lineTo(start.x + lastDrawnWidth, bendHeight);
207
+ ctx.stroke();
208
+ if (bend.type === Bend.PREBEND)
209
+ renderArrowHead(start.x, bendHeight, +1);
210
+ }
162
211
  if (bend.type === Bend.DOWN) {
163
- if (lastBend && lastBend.type === Bend.UP) {
212
+ if (lastBend && [Bend.UP, Bend.PREBEND, Bend.HOLD].includes(lastBend.type)) {
164
213
  renderRelease(start.x, start.y, lastDrawnWidth, bendHeight);
165
214
  }
166
215
  if (lastBend && lastBend.type === Bend.DOWN) {
@@ -189,3 +238,5 @@ export class Bend extends Modifier {
189
238
  }
190
239
  }
191
240
  }
241
+ Bend.PREBEND = 2;
242
+ Bend.HOLD = 3;
@@ -108,6 +108,9 @@ export class Clef extends StaveModifier {
108
108
  this.stave = stave;
109
109
  return this;
110
110
  }
111
+ getInkBounds() {
112
+ return this.getTextInk(this.getX(), this.checkStave().getYForLine(this.line));
113
+ }
111
114
  draw() {
112
115
  const stave = this.checkStave();
113
116
  const ctx = stave.checkContext();