vexflow 5.0.0-alpha.3 → 5.0.0-beta.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 (152) hide show
  1. package/README.md +6 -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 +2066 -1877
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +1052 -993
  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 +22 -28
  13. package/build/esm/src/annotation.js +0 -2
  14. package/build/esm/src/barnote.js +3 -3
  15. package/build/esm/src/beam.js +26 -46
  16. package/build/esm/src/bend.js +11 -3
  17. package/build/esm/src/chordsymbol.js +0 -4
  18. package/build/esm/src/clef.js +0 -2
  19. package/build/esm/src/clefnote.js +6 -1
  20. package/build/esm/src/curve.js +8 -5
  21. package/build/esm/src/element.js +94 -118
  22. package/build/esm/src/factory.js +4 -4
  23. package/build/esm/src/flag.js +20 -0
  24. package/build/esm/src/fonts/gonville.js +1 -1
  25. package/build/esm/src/formatter.js +13 -21
  26. package/build/esm/src/fraction.js +15 -22
  27. package/build/esm/src/glyphnote.js +3 -4
  28. package/build/esm/src/gracenote.js +0 -2
  29. package/build/esm/src/gracenotegroup.js +17 -8
  30. package/build/esm/src/index.js +1 -0
  31. package/build/esm/src/keysignature.js +38 -31
  32. package/build/esm/src/keysignote.js +1 -1
  33. package/build/esm/src/metrics.js +58 -7
  34. package/build/esm/src/modifier.js +10 -23
  35. package/build/esm/src/multimeasurerest.js +16 -25
  36. package/build/esm/src/note.js +7 -0
  37. package/build/esm/src/notehead.js +6 -1
  38. package/build/esm/src/ornament.js +0 -2
  39. package/build/esm/src/pedalmarking.js +33 -41
  40. package/build/esm/src/registry.js +5 -19
  41. package/build/esm/src/stave.js +11 -19
  42. package/build/esm/src/stavebarline.js +2 -3
  43. package/build/esm/src/stavehairpin.js +1 -1
  44. package/build/esm/src/staveline.js +0 -4
  45. package/build/esm/src/stavemodifier.js +0 -2
  46. package/build/esm/src/stavenote.js +42 -68
  47. package/build/esm/src/staverepetition.js +3 -2
  48. package/build/esm/src/stavesection.js +13 -15
  49. package/build/esm/src/stavetempo.js +7 -13
  50. package/build/esm/src/stavetext.js +2 -2
  51. package/build/esm/src/stavetie.js +82 -40
  52. package/build/esm/src/stavevolta.js +3 -2
  53. package/build/esm/src/stem.js +0 -4
  54. package/build/esm/src/stemmablenote.js +5 -6
  55. package/build/esm/src/stringnumber.js +0 -2
  56. package/build/esm/src/svgcontext.js +5 -13
  57. package/build/esm/src/tabnote.js +2 -8
  58. package/build/esm/src/textbracket.js +0 -3
  59. package/build/esm/src/textnote.js +0 -2
  60. package/build/esm/src/tickable.js +13 -26
  61. package/build/esm/src/tickcontext.js +20 -2
  62. package/build/esm/src/timesignature.js +2 -4
  63. package/build/esm/src/timesignote.js +2 -0
  64. package/build/esm/src/tuplet.js +37 -30
  65. package/build/esm/src/version.js +3 -3
  66. package/build/esm/src/vexflow.js +6 -2
  67. package/build/esm/src/vibrato.js +6 -1
  68. package/build/esm/tests/accidental_tests.js +30 -17
  69. package/build/esm/tests/annotation_tests.js +12 -12
  70. package/build/esm/tests/articulation_tests.js +13 -13
  71. package/build/esm/tests/auto_beam_formatting_tests.js +33 -33
  72. package/build/esm/tests/beam_tests.js +1 -1
  73. package/build/esm/tests/bend_tests.js +7 -7
  74. package/build/esm/tests/chordsymbol_tests.js +8 -8
  75. package/build/esm/tests/clef_tests.js +5 -1
  76. package/build/esm/tests/curve_tests.js +34 -0
  77. package/build/esm/tests/{bach_tests.js → demo_petzold_tests.js} +7 -7
  78. package/build/esm/tests/dot_tests.js +4 -4
  79. package/build/esm/tests/formatter_tests.js +25 -25
  80. package/build/esm/tests/glyphnote_tests.js +6 -0
  81. package/build/esm/tests/gracenote_tests.js +2 -1
  82. package/build/esm/tests/gracetabnote_tests.js +1 -1
  83. package/build/esm/tests/index.js +1 -1
  84. package/build/esm/tests/key_clef_tests.js +6 -6
  85. package/build/esm/tests/keysignature_tests.js +20 -17
  86. package/build/esm/tests/notehead_tests.js +10 -7
  87. package/build/esm/tests/offscreencanvas_tests.js +1 -1
  88. package/build/esm/tests/ornament_tests.js +8 -8
  89. package/build/esm/tests/pedalmarking_tests.js +27 -0
  90. package/build/esm/tests/percussion_tests.js +6 -3
  91. package/build/esm/tests/renderer_tests.js +1 -1
  92. package/build/esm/tests/rests_tests.js +26 -26
  93. package/build/esm/tests/rhythm_tests.js +15 -15
  94. package/build/esm/tests/stave_tests.js +44 -43
  95. package/build/esm/tests/staveconnector_tests.js +73 -73
  96. package/build/esm/tests/stavehairpin_tests.js +1 -1
  97. package/build/esm/tests/stavemodifier_tests.js +3 -3
  98. package/build/esm/tests/stavenote_tests.js +29 -29
  99. package/build/esm/tests/stavetie_tests.js +29 -0
  100. package/build/esm/tests/stringnumber_tests.js +1 -1
  101. package/build/esm/tests/strokes_tests.js +1 -1
  102. package/build/esm/tests/style_tests.js +1 -1
  103. package/build/esm/tests/tabnote_tests.js +7 -7
  104. package/build/esm/tests/tabslide_tests.js +6 -6
  105. package/build/esm/tests/tabstave_tests.js +2 -1
  106. package/build/esm/tests/tabtie_tests.js +8 -8
  107. package/build/esm/tests/textnote_tests.js +1 -1
  108. package/build/esm/tests/threevoice_tests.js +2 -2
  109. package/build/esm/tests/timesignature_tests.js +23 -13
  110. package/build/esm/tests/vexflow_test_helpers.js +25 -39
  111. package/build/esm/tests/vibrato_tests.js +3 -3
  112. package/build/esm/tests/voice_tests.js +1 -1
  113. package/build/types/src/accidental.d.ts +19 -1
  114. package/build/types/src/annotation.d.ts +1 -1
  115. package/build/types/src/beam.d.ts +12 -1
  116. package/build/types/src/bend.d.ts +6 -0
  117. package/build/types/src/clefnote.d.ts +2 -0
  118. package/build/types/src/curve.d.ts +5 -4
  119. package/build/types/src/element.d.ts +23 -14
  120. package/build/types/src/factory.d.ts +2 -2
  121. package/build/types/src/flag.d.ts +12 -0
  122. package/build/types/src/fonts/gonville.d.ts +1 -1
  123. package/build/types/src/formatter.d.ts +5 -3
  124. package/build/types/src/fraction.d.ts +12 -7
  125. package/build/types/src/frethandfinger.d.ts +1 -1
  126. package/build/types/src/index.d.ts +1 -0
  127. package/build/types/src/keysignature.d.ts +7 -7
  128. package/build/types/src/metrics.d.ts +5 -0
  129. package/build/types/src/modifier.d.ts +3 -2
  130. package/build/types/src/multimeasurerest.d.ts +4 -1
  131. package/build/types/src/note.d.ts +2 -0
  132. package/build/types/src/pedalmarking.d.ts +2 -2
  133. package/build/types/src/registry.d.ts +1 -1
  134. package/build/types/src/stave.d.ts +1 -3
  135. package/build/types/src/stavebarline.d.ts +1 -1
  136. package/build/types/src/staveline.d.ts +1 -1
  137. package/build/types/src/stavemodifier.d.ts +0 -1
  138. package/build/types/src/stavenote.d.ts +2 -1
  139. package/build/types/src/staverepetition.d.ts +1 -1
  140. package/build/types/src/stavesection.d.ts +3 -4
  141. package/build/types/src/stavetempo.d.ts +4 -5
  142. package/build/types/src/stavetext.d.ts +1 -2
  143. package/build/types/src/stavetie.d.ts +39 -2
  144. package/build/types/src/stavevolta.d.ts +1 -2
  145. package/build/types/src/stemmablenote.d.ts +2 -3
  146. package/build/types/src/svgcontext.d.ts +1 -1
  147. package/build/types/src/tickable.d.ts +2 -1
  148. package/build/types/src/tickcontext.d.ts +30 -0
  149. package/build/types/src/tuplet.d.ts +2 -12
  150. package/build/types/src/typeguard.d.ts +1 -0
  151. package/package.json +33 -29
  152. package/tests/flow.html +2 -2
@@ -120,8 +120,6 @@ export class Stem extends Element {
120
120
  const stemHeight = this.getHeight();
121
121
  L('Rendering stem - ', 'Top Y: ', this.yTop, 'Bottom Y: ', this.yBottom);
122
122
  const stemletYOffset = this.isStemlet ? stemHeight - this.stemletHeight * this.stemDirection : 0;
123
- ctx.save();
124
- this.applyStyle();
125
123
  ctx.openGroup('stem', this.getAttribute('id'));
126
124
  ctx.beginPath();
127
125
  ctx.setLineWidth(Stem.WIDTH);
@@ -129,8 +127,6 @@ export class Stem extends Element {
129
127
  ctx.lineTo(stemX, stemY - stemHeight - this.renderHeightAdjustment * stemDirection);
130
128
  ctx.stroke();
131
129
  ctx.closeGroup();
132
- this.restoreStyle();
133
- ctx.restore();
134
130
  }
135
131
  }
136
132
  Stem.DEBUG = false;
@@ -1,4 +1,4 @@
1
- import { Element } from './element.js';
1
+ import { Flag } from './flag.js';
2
2
  import { Glyphs } from './glyphs.js';
3
3
  import { Note } from './note.js';
4
4
  import { Stem } from './stem.js';
@@ -10,8 +10,7 @@ export class StemmableNote extends Note {
10
10
  }
11
11
  constructor(noteStruct) {
12
12
  super(noteStruct);
13
- this.flag = new Element();
14
- this.flagStyle = {};
13
+ this.flag = new Flag();
15
14
  }
16
15
  getStem() {
17
16
  return this.stem;
@@ -24,7 +23,7 @@ export class StemmableNote extends Note {
24
23
  }
25
24
  setStem(stem) {
26
25
  this.stem = stem;
27
- this.addChildElement(stem);
26
+ this.addChild(stem);
28
27
  return this;
29
28
  }
30
29
  buildStem() {
@@ -38,7 +37,7 @@ export class StemmableNote extends Note {
38
37
  if (this.hasFlag()) {
39
38
  const flagCode = this.getStemDirection() === Stem.DOWN
40
39
  ? String.fromCodePoint(((_b = (_a = glyphProps.codeFlagUp) === null || _a === void 0 ? void 0 : _a.codePointAt(0)) !== null && _b !== void 0 ? _b : -1) + 1)
41
- : (_c = glyphProps.codeFlagUp) !== null && _c !== void 0 ? _c : Glyphs.null;
40
+ : ((_c = glyphProps.codeFlagUp) !== null && _c !== void 0 ? _c : Glyphs.null);
42
41
  this.flag.setText(flagCode);
43
42
  this.flag.fontInfo = this.fontInfo;
44
43
  }
@@ -180,6 +179,6 @@ export class StemmableNote extends Note {
180
179
  this.checkContext();
181
180
  this.setRendered();
182
181
  this.setStem(new Stem(stemOptions));
183
- (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setContext(this.getContext()).draw();
182
+ (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setContext(this.getContext()).drawWithStyle();
184
183
  }
185
184
  }
@@ -186,7 +186,6 @@ export class StringNumber extends Modifier {
186
186
  default:
187
187
  throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid`);
188
188
  }
189
- ctx.save();
190
189
  if (this.drawCircle) {
191
190
  ctx.beginPath();
192
191
  ctx.arc(dotX, dotY, this.radius, 0, Math.PI * 2, false);
@@ -225,6 +224,5 @@ export class StringNumber extends Modifier {
225
224
  break;
226
225
  }
227
226
  }
228
- ctx.restore();
229
227
  }
230
228
  }
@@ -1,9 +1,3 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _SVGContext_instances, _SVGContext_getShadowStyle;
7
1
  import { Element } from './element.js';
8
2
  import { Font, FontStyle, FontWeight } from './font.js';
9
3
  import { Metrics } from './metrics.js';
@@ -37,7 +31,6 @@ const TWO_PI = 2 * Math.PI;
37
31
  export class SVGContext extends RenderContext {
38
32
  constructor(element) {
39
33
  super();
40
- _SVGContext_instances.add(this);
41
34
  this.width = 0;
42
35
  this.height = 0;
43
36
  this.precision = 1;
@@ -184,7 +177,6 @@ export class SVGContext extends RenderContext {
184
177
  while (this.svg.lastChild) {
185
178
  this.svg.removeChild(this.svg.lastChild);
186
179
  }
187
- this.scale(this.state.scaleX, this.state.scaleY);
188
180
  }
189
181
  rect(x, y, width, height, attributes) {
190
182
  if (height < 0) {
@@ -308,6 +300,9 @@ export class SVGContext extends RenderContext {
308
300
  this.path += 'Z';
309
301
  return this;
310
302
  }
303
+ getShadowStyle() {
304
+ return `filter: drop-shadow(0 0 ${this.attributes.shadowBlur / 1.5}px ${this.attributes.shadowColor})`;
305
+ }
311
306
  fill(attributes) {
312
307
  const path = this.create('path');
313
308
  if (typeof attributes === 'undefined') {
@@ -315,7 +310,7 @@ export class SVGContext extends RenderContext {
315
310
  }
316
311
  attributes.d = this.path;
317
312
  if (this.attributes.shadowBlur > 0) {
318
- attributes.style = __classPrivateFieldGet(this, _SVGContext_instances, "m", _SVGContext_getShadowStyle).call(this);
313
+ attributes.style = this.getShadowStyle();
319
314
  }
320
315
  this.applyAttributes(path, attributes);
321
316
  this.add(path);
@@ -325,7 +320,7 @@ export class SVGContext extends RenderContext {
325
320
  const path = this.create('path');
326
321
  const attributes = Object.assign(Object.assign({}, this.attributes), { fill: 'none', d: this.path });
327
322
  if (this.attributes.shadowBlur > 0) {
328
- attributes.style = __classPrivateFieldGet(this, _SVGContext_instances, "m", _SVGContext_getShadowStyle).call(this);
323
+ attributes.style = this.getShadowStyle();
329
324
  }
330
325
  this.applyAttributes(path, attributes);
331
326
  this.add(path);
@@ -396,7 +391,4 @@ export class SVGContext extends RenderContext {
396
391
  return this.fontCSSString;
397
392
  }
398
393
  }
399
- _SVGContext_instances = new WeakSet(), _SVGContext_getShadowStyle = function _SVGContext_getShadowStyle() {
400
- return `filter: drop-shadow(0 0 ${this.attributes.shadowBlur / 1.5}px ${this.attributes.shadowColor})`;
401
- };
402
394
  SVGContext.measureTextElement = new Element();
@@ -207,9 +207,7 @@ export class TabNote extends StemmableNote {
207
207
  this.getStemY() - this.checkStem().getHeight() - this.getStemExtension()
208
208
  :
209
209
  this.getStemY() - this.checkStem().getHeight() + this.getStemExtension();
210
- this.applyStyle(context, this.flagStyle);
211
- this.flag.renderText(context, flagX, flagY);
212
- this.restoreStyle(context, this.flagStyle);
210
+ this.flag.setContext(context).setX(flagX).setY(flagY).drawWithStyle();
213
211
  }
214
212
  }
215
213
  drawModifiers() {
@@ -232,7 +230,6 @@ export class TabNote extends StemmableNote {
232
230
  const stringsUsed = this.positions.map((position) => Number(position.str));
233
231
  const unusedStrings = getUnusedStringGroups(numLines, stringsUsed);
234
232
  const stemLines = getPartialStemLines(stemY, unusedStrings, this.checkStave(), this.getStemDirection());
235
- ctx.save();
236
233
  ctx.setLineWidth(Stem.WIDTH);
237
234
  stemLines.forEach((bounds) => {
238
235
  if (bounds.length === 0)
@@ -243,7 +240,6 @@ export class TabNote extends StemmableNote {
243
240
  ctx.stroke();
244
241
  ctx.closePath();
245
242
  });
246
- ctx.restore();
247
243
  }
248
244
  }
249
245
  drawPositions() {
@@ -265,18 +261,16 @@ export class TabNote extends StemmableNote {
265
261
  }
266
262
  this.setRendered();
267
263
  const renderStem = this.beam === undefined && this.renderOptions.drawStem;
268
- this.applyStyle();
269
264
  ctx.openGroup('tabnote', this.getAttribute('id'));
270
265
  this.drawPositions();
271
266
  this.drawStemThrough();
272
267
  if (this.stem && renderStem) {
273
268
  const stemX = this.getStemX();
274
269
  this.stem.setNoteHeadXBounds(stemX, stemX);
275
- this.stem.setContext(ctx).draw();
270
+ this.stem.setContext(ctx).drawWithStyle();
276
271
  }
277
272
  this.drawFlag();
278
273
  this.drawModifiers();
279
274
  ctx.closeGroup();
280
- this.restoreStyle();
281
275
  }
282
276
  }
@@ -86,8 +86,6 @@ export class TextBracket extends Element {
86
86
  const stop = { x: this.stop.getAbsoluteX(), y };
87
87
  L('Rendering TextBracket: start:', start, 'stop:', stop, 'y:', y);
88
88
  const bracketHeight = this.renderOptions.bracketHeight * this.position;
89
- ctx.save();
90
- this.applyStyle(ctx);
91
89
  this.textElement.renderText(ctx, start.x, start.y);
92
90
  const mainWidth = this.textElement.getWidth();
93
91
  const mainHeight = this.textElement.getHeight();
@@ -125,7 +123,6 @@ export class TextBracket extends Element {
125
123
  ctx.stroke();
126
124
  ctx.closePath();
127
125
  }
128
- ctx.restore();
129
126
  }
130
127
  }
131
128
  TextBracket.DEBUG = false;
@@ -103,7 +103,6 @@ export class TextNote extends Note {
103
103
  x -= width;
104
104
  }
105
105
  const y = stave.getYForLine(this.line + -3);
106
- this.applyStyle(ctx);
107
106
  this.renderText(ctx, x, y);
108
107
  const height = this.getHeight();
109
108
  if (this.superscript) {
@@ -112,7 +111,6 @@ export class TextNote extends Note {
112
111
  if (this.subscript) {
113
112
  this.subscript.renderText(ctx, x + this.width + 2, y + height / 2.2 - 1);
114
113
  }
115
- this.restoreStyle(ctx);
116
114
  }
117
115
  }
118
116
  TextNote.Justification = TextJustification;
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _Tickable_preFormatted, _Tickable_postFormatted;
13
1
  import { Element } from './element.js';
14
2
  import { Fraction } from './fraction.js';
15
3
  import { Tables } from './tables.js';
@@ -20,8 +8,8 @@ export class Tickable extends Element {
20
8
  }
21
9
  constructor() {
22
10
  super();
23
- _Tickable_preFormatted.set(this, false);
24
- _Tickable_postFormatted.set(this, false);
11
+ this._preFormatted = false;
12
+ this._postFormatted = false;
25
13
  this.ticks = new Fraction(0, 1);
26
14
  this.intrinsicTicks = 0;
27
15
  this.tickMultiplier = new Fraction(1, 1);
@@ -55,7 +43,7 @@ export class Tickable extends Element {
55
43
  return this;
56
44
  }
57
45
  getWidth() {
58
- if (!__classPrivateFieldGet(this, _Tickable_preFormatted, "f")) {
46
+ if (!this._preFormatted) {
59
47
  throw new RuntimeError('UnformattedNote', "Can't call GetWidth on an unformatted note.");
60
48
  }
61
49
  return this.width + (this.modifierContext ? this.modifierContext.getWidth() : 0);
@@ -133,12 +121,12 @@ export class Tickable extends Element {
133
121
  this.modifierContext.addMember(this.modifiers[i]);
134
122
  }
135
123
  this.modifierContext.addMember(this);
136
- __classPrivateFieldSet(this, _Tickable_preFormatted, false, "f");
124
+ this._preFormatted = false;
137
125
  return this;
138
126
  }
139
127
  addModifier(modifier, index = 0) {
140
128
  this.modifiers.push(modifier);
141
- __classPrivateFieldSet(this, _Tickable_preFormatted, false, "f");
129
+ this._preFormatted = false;
142
130
  return this;
143
131
  }
144
132
  getModifiers() {
@@ -146,13 +134,13 @@ export class Tickable extends Element {
146
134
  }
147
135
  setTickContext(tc) {
148
136
  this.tickContext = tc;
149
- __classPrivateFieldSet(this, _Tickable_preFormatted, false, "f");
137
+ this._preFormatted = false;
150
138
  }
151
139
  checkTickContext(message = 'Tickable has no tick context.') {
152
140
  return defined(this.tickContext, 'NoTickContext', message);
153
141
  }
154
142
  preFormat() {
155
- if (__classPrivateFieldGet(this, _Tickable_preFormatted, "f"))
143
+ if (this._preFormatted)
156
144
  return;
157
145
  this.width = 0;
158
146
  if (this.modifierContext) {
@@ -161,22 +149,22 @@ export class Tickable extends Element {
161
149
  }
162
150
  }
163
151
  set preFormatted(value) {
164
- __classPrivateFieldSet(this, _Tickable_preFormatted, value, "f");
152
+ this._preFormatted = value;
165
153
  }
166
154
  get preFormatted() {
167
- return __classPrivateFieldGet(this, _Tickable_preFormatted, "f");
155
+ return this._preFormatted;
168
156
  }
169
157
  postFormat() {
170
- if (__classPrivateFieldGet(this, _Tickable_postFormatted, "f"))
158
+ if (this._postFormatted)
171
159
  return this;
172
- __classPrivateFieldSet(this, _Tickable_postFormatted, true, "f");
160
+ this._postFormatted = true;
173
161
  return this;
174
162
  }
175
163
  set postFormatted(value) {
176
- __classPrivateFieldSet(this, _Tickable_postFormatted, value, "f");
164
+ this._postFormatted = value;
177
165
  }
178
166
  get postFormatted() {
179
- return __classPrivateFieldGet(this, _Tickable_postFormatted, "f");
167
+ return this._postFormatted;
180
168
  }
181
169
  getIntrinsicTicks() {
182
170
  return this.intrinsicTicks;
@@ -212,4 +200,3 @@ export class Tickable extends Element {
212
200
  return defined(this.modifierContext, 'NoModifierContext', 'No modifier context attached to this tickable.');
213
201
  }
214
202
  }
215
- _Tickable_preFormatted = new WeakMap(), _Tickable_postFormatted = new WeakMap();
@@ -1,5 +1,5 @@
1
1
  import { Fraction } from './fraction.js';
2
- import { RuntimeError } from './util.js';
2
+ import { RuntimeError, sumArray } from './util.js';
3
3
  export class TickContext {
4
4
  static getNextContext(tContext) {
5
5
  const contexts = tContext.tContexts;
@@ -8,9 +8,10 @@ export class TickContext {
8
8
  return contexts[index + 1];
9
9
  }
10
10
  constructor(options) {
11
+ var _a;
11
12
  this.preFormatted = false;
12
13
  this.postFormatted = false;
13
- this.tickID = options && options.tickID ? options.tickID : 0;
14
+ this.tickID = (_a = options === null || options === void 0 ? void 0 : options.tickID) !== null && _a !== void 0 ? _a : 0;
14
15
  this.currentTick = new Fraction(0, 1);
15
16
  this.maxTicks = new Fraction(0, 1);
16
17
  this.maxTickable = undefined;
@@ -168,4 +169,21 @@ export class TickContext {
168
169
  getFormatterMetrics() {
169
170
  return this.formatterMetrics;
170
171
  }
172
+ move(shift, prev, next) {
173
+ this.setX(this.getX() + shift);
174
+ this.getFormatterMetrics().freedom.left += shift;
175
+ this.getFormatterMetrics().freedom.right -= shift;
176
+ if (prev)
177
+ prev.getFormatterMetrics().freedom.right += shift;
178
+ if (next)
179
+ next.getFormatterMetrics().freedom.left -= shift;
180
+ }
181
+ getDeviationCost() {
182
+ return sumArray(this.tickables.map((t) => t.getFormatterMetrics().space.deviation));
183
+ }
184
+ getAverageDeviationCost() {
185
+ if (!this.tickables.length)
186
+ return 0;
187
+ return this.getDeviationCost() / this.tickables.length;
188
+ }
171
189
  }
@@ -123,12 +123,12 @@ export class TimeSignature extends StaveModifier {
123
123
  const stave = this.checkStave();
124
124
  const ctx = stave.checkContext();
125
125
  this.setRendered();
126
+ ctx.openGroup('timesignature', this.getAttribute('id'));
126
127
  this.drawAt(ctx, stave, this.x);
128
+ ctx.closeGroup();
127
129
  }
128
130
  drawAt(ctx, stave, x) {
129
131
  this.setRendered();
130
- this.applyStyle(ctx);
131
- ctx.openGroup('timesignature', this.getAttribute('id'));
132
132
  if (this.isNumeric) {
133
133
  let startX = x + this.topStartX;
134
134
  let y = 0;
@@ -144,7 +144,5 @@ export class TimeSignature extends StaveModifier {
144
144
  else {
145
145
  this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
146
146
  }
147
- ctx.closeGroup();
148
- this.restoreStyle(ctx);
149
147
  }
150
148
  }
@@ -21,6 +21,8 @@ export class TimeSigNote extends Note {
21
21
  const stave = this.checkStave();
22
22
  const ctx = this.checkContext();
23
23
  this.setRendered();
24
+ ctx.openGroup('timesignote', this.getAttribute('id'));
24
25
  this.timeSig.drawAt(ctx, stave, this.getAbsoluteX());
26
+ ctx.closeGroup();
25
27
  }
26
28
  }
@@ -1,6 +1,7 @@
1
1
  import { Element } from './element.js';
2
2
  import { Formatter } from './formatter.js';
3
3
  import { Glyphs } from './glyphs.js';
4
+ import { Metrics } from './metrics.js';
4
5
  import { Stem } from './stem.js';
5
6
  import { Tables } from './tables.js';
6
7
  import { RuntimeError } from './util.js';
@@ -22,20 +23,25 @@ export class Tuplet extends Element {
22
23
  if (!notes || !notes.length) {
23
24
  throw new RuntimeError('BadArguments', 'No notes provided for tuplet.');
24
25
  }
25
- this.options = options;
26
26
  this.notes = notes;
27
- this.numNotes = this.options.numNotes !== undefined ? this.options.numNotes : notes.length;
28
- this.notesOccupied = this.options.notesOccupied || 2;
29
- if (this.options.bracketed !== undefined) {
30
- this.bracketed = this.options.bracketed;
31
- }
32
- else {
33
- this.bracketed = notes.some((note) => !note.hasBeam());
34
- }
35
- this.ratioed =
36
- this.options.ratioed !== undefined ? this.options.ratioed : Math.abs(this.notesOccupied - this.numNotes) > 1;
27
+ const numNotes = options.numNotes !== undefined ? options.numNotes : notes.length;
28
+ const notesOccupied = options.notesOccupied || 2;
29
+ const bracketed = options.bracketed !== undefined ? options.bracketed : notes.some((note) => !note.hasBeam());
30
+ const ratioed = options.ratioed !== undefined ? options.ratioed : Math.abs(notesOccupied - numNotes) > 1;
31
+ const location = options.location || Tuplet.LOCATION_TOP;
32
+ const yOffset = options.yOffset || Metrics.get('Tuplet.yOffset');
33
+ const textYOffset = options.textYOffset || Metrics.get('Tuplet.textYOffset');
34
+ this.options = {
35
+ bracketed,
36
+ location,
37
+ notesOccupied,
38
+ numNotes,
39
+ ratioed,
40
+ yOffset,
41
+ textYOffset,
42
+ };
37
43
  this.textElement = new Element('Tuplet');
38
- this.setTupletLocation(this.options.location || Tuplet.LOCATION_TOP);
44
+ this.setTupletLocation(location || Tuplet.LOCATION_TOP);
39
45
  Formatter.AlignRestsToNotes(notes, true, true);
40
46
  this.resolveGlyphs();
41
47
  this.attach();
@@ -53,11 +59,11 @@ export class Tuplet extends Element {
53
59
  }
54
60
  }
55
61
  setBracketed(bracketed) {
56
- this.bracketed = !!bracketed;
62
+ this.options.bracketed = bracketed;
57
63
  return this;
58
64
  }
59
65
  setRatioed(ratioed) {
60
- this.ratioed = !!ratioed;
66
+ this.options.ratioed = ratioed;
61
67
  return this;
62
68
  }
63
69
  setTupletLocation(location) {
@@ -65,34 +71,34 @@ export class Tuplet extends Element {
65
71
  console.warn(`Invalid tuplet location [${location}]. Using Tuplet.LOCATION_TOP.`);
66
72
  location = Tuplet.LOCATION_TOP;
67
73
  }
68
- this.location = location;
74
+ this.options.location = location;
69
75
  return this;
70
76
  }
71
77
  getNotes() {
72
78
  return this.notes;
73
79
  }
74
80
  getNoteCount() {
75
- return this.numNotes;
81
+ return this.options.numNotes;
76
82
  }
77
83
  getNotesOccupied() {
78
- return this.notesOccupied;
84
+ return this.options.notesOccupied;
79
85
  }
80
86
  setNotesOccupied(notes) {
81
87
  this.detach();
82
- this.notesOccupied = notes;
88
+ this.options.notesOccupied = notes;
83
89
  this.resolveGlyphs();
84
90
  this.attach();
85
91
  }
86
92
  resolveGlyphs() {
87
93
  let numerator = '';
88
94
  let denominator = '';
89
- let n = this.numNotes;
95
+ let n = this.options.numNotes;
90
96
  while (n >= 1) {
91
97
  numerator = String.fromCharCode(0xe880 + (n % 10)) + numerator;
92
98
  n = Math.floor(n / 10);
93
99
  }
94
- if (this.ratioed) {
95
- n = this.notesOccupied;
100
+ if (this.options.ratioed) {
101
+ n = this.options.notesOccupied;
96
102
  while (n >= 1) {
97
103
  denominator = String.fromCharCode(0xe880 + (n % 10)) + denominator;
98
104
  n = Math.floor(n / 10);
@@ -102,12 +108,12 @@ export class Tuplet extends Element {
102
108
  this.textElement.setText(numerator + denominator);
103
109
  }
104
110
  getNestedTupletCount() {
105
- const location = this.location;
111
+ const { location } = this.options;
106
112
  const firstNote = this.notes[0];
107
113
  let maxTupletCount = countTuplets(firstNote, location);
108
114
  let minTupletCount = countTuplets(firstNote, location);
109
115
  function countTuplets(note, location) {
110
- return note.getTupletStack().filter((tuplet) => tuplet.location === location).length;
116
+ return note.getTupletStack().filter((tuplet) => tuplet.options.location === location).length;
111
117
  }
112
118
  this.notes.forEach((note) => {
113
119
  const tupletCount = countTuplets(note, location);
@@ -118,11 +124,11 @@ export class Tuplet extends Element {
118
124
  }
119
125
  getYPosition() {
120
126
  var _a;
121
- const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.location;
127
+ const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.options.location;
122
128
  const yOffset = (_a = this.options.yOffset) !== null && _a !== void 0 ? _a : 0;
123
129
  const firstNote = this.notes[0];
124
130
  let yPosition;
125
- if (this.location === Tuplet.LOCATION_TOP) {
131
+ if (this.options.location === Tuplet.LOCATION_TOP) {
126
132
  yPosition = firstNote.checkStave().getYForLine(0) - 1.5 * Tables.STAVE_LINE_DISTANCE;
127
133
  for (let i = 0; i < this.notes.length; ++i) {
128
134
  const note = this.notes[i];
@@ -166,13 +172,14 @@ export class Tuplet extends Element {
166
172
  return yPosition + nestedTupletYOffset + yOffset;
167
173
  }
168
174
  draw() {
175
+ const { location, bracketed, textYOffset } = this.options;
169
176
  const ctx = this.checkContext();
170
177
  let xPos = 0;
171
178
  let yPos = 0;
172
179
  this.setRendered();
173
180
  const firstNote = this.notes[0];
174
181
  const lastNote = this.notes[this.notes.length - 1];
175
- if (!this.bracketed) {
182
+ if (!bracketed) {
176
183
  xPos = firstNote.getStemX();
177
184
  this.width = lastNote.getStemX() - xPos;
178
185
  }
@@ -183,15 +190,15 @@ export class Tuplet extends Element {
183
190
  yPos = this.getYPosition();
184
191
  const notationCenterX = xPos + this.width / 2;
185
192
  const notationStartX = notationCenterX - this.textElement.getWidth() / 2;
186
- if (this.bracketed) {
193
+ if (bracketed) {
187
194
  const lineWidth = this.width / 2 - this.textElement.getWidth() / 2 - 5;
188
195
  if (lineWidth > 0) {
189
196
  ctx.fillRect(xPos, yPos, lineWidth, 1);
190
197
  ctx.fillRect(xPos + this.width / 2 + this.textElement.getWidth() / 2 + 5, yPos, lineWidth, 1);
191
- ctx.fillRect(xPos, yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, this.location * 10);
192
- ctx.fillRect(xPos + this.width, yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, this.location * 10);
198
+ ctx.fillRect(xPos, yPos + (location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, location * 10);
199
+ ctx.fillRect(xPos + this.width, yPos + (location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, location * 10);
193
200
  }
194
201
  }
195
- this.textElement.renderText(ctx, notationStartX, yPos + this.textElement.getHeight() / 2);
202
+ this.textElement.renderText(ctx, notationStartX, yPos + this.textElement.getHeight() / 2 + (location === Tuplet.LOCATION_TOP ? -1 : 1) * textYOffset);
196
203
  }
197
204
  }
@@ -1,3 +1,3 @@
1
- export const VERSION = '5.0.0-alpha.3';
2
- export const ID = '34a251a7bd087f8a341d61837db71c38def9f70d';
3
- export const DATE = '2024-03-10T22:53:53.018Z';
1
+ export const VERSION = '5.0.0-beta.0';
2
+ export const ID = '2daeb4def8b685227f2a3c924177b40ddcc5bda3';
3
+ export const DATE = '2024-09-12T19:16:57.446Z';
@@ -104,6 +104,7 @@ export class VexFlow {
104
104
  }
105
105
  static setFonts(...fontNames) {
106
106
  MetricsDefaults.fontFamily = fontNames.join(',');
107
+ Metrics.clear();
107
108
  }
108
109
  static getFonts() {
109
110
  return Metrics.get('fontFamily').split(',');
@@ -157,10 +158,13 @@ export class VexFlow {
157
158
  Tables.STAVE_LINE_DISTANCE = value;
158
159
  }
159
160
  static get STAVE_LINE_THICKNESS() {
160
- return Tables.STAVE_LINE_THICKNESS;
161
+ return MetricsDefaults.Stave.lineWidth;
161
162
  }
162
163
  static set STAVE_LINE_THICKNESS(value) {
163
- Tables.STAVE_LINE_THICKNESS = value;
164
+ MetricsDefaults.Stave.lineWidth = value;
165
+ MetricsDefaults.TabStave.lineWidth = value;
166
+ Metrics.clear('Stave');
167
+ Metrics.clear('TabStave');
164
168
  }
165
169
  static get STEM_HEIGHT() {
166
170
  return Tables.STEM_HEIGHT;
@@ -1,6 +1,7 @@
1
1
  import { Bend } from './bend.js';
2
2
  import { Modifier } from './modifier.js';
3
3
  import { Tables } from './tables.js';
4
+ import { RuntimeError } from './util.js';
4
5
  export class Vibrato extends Modifier {
5
6
  static get CATEGORY() {
6
7
  return "Vibrato";
@@ -41,7 +42,11 @@ export class Vibrato extends Modifier {
41
42
  setVibratoWidth(width) {
42
43
  this.renderOptions.width = width;
43
44
  this.text = String.fromCodePoint(this.renderOptions.code);
44
- const items = Math.round(this.renderOptions.width / this.getWidth());
45
+ const myWidth = this.getWidth();
46
+ if (!myWidth) {
47
+ throw new RuntimeError('Cannot set vibrato width if width is 0');
48
+ }
49
+ const items = Math.round(this.renderOptions.width / myWidth);
45
50
  for (let i = 1; i < items; i++) {
46
51
  this.text += String.fromCodePoint(this.renderOptions.code);
47
52
  }