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
@@ -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 _StaveNote_noteHeads, _StaveNote_sortedKeyProps;
13
1
  import { BoundingBox } from './boundingbox.js';
14
2
  import { Glyphs } from './glyphs.js';
15
3
  import { Metrics } from './metrics.js';
@@ -54,7 +42,7 @@ export class StaveNote extends StemmableNote {
54
42
  return false;
55
43
  const notesList = [];
56
44
  for (let i = 0; i < notes.length; i++) {
57
- const props = __classPrivateFieldGet(notes[i], _StaveNote_sortedKeyProps, "f");
45
+ const props = notes[i].sortedKeyProps;
58
46
  const line = props[0].keyProps.line;
59
47
  let minL = props[props.length - 1].keyProps.line;
60
48
  const stemDirection = notes[i].getStemDirection();
@@ -64,10 +52,10 @@ export class StaveNote extends StemmableNote {
64
52
  if (notes[i].isRest()) {
65
53
  maxL =
66
54
  line +
67
- Math.ceil(__classPrivateFieldGet(notes[i], _StaveNote_noteHeads, "f")[0].getTextMetrics().actualBoundingBoxAscent / Tables.STAVE_LINE_DISTANCE);
55
+ Math.ceil(notes[i]._noteHeads[0].getTextMetrics().actualBoundingBoxAscent / Tables.STAVE_LINE_DISTANCE);
68
56
  minL =
69
57
  line -
70
- Math.ceil(__classPrivateFieldGet(notes[i], _StaveNote_noteHeads, "f")[0].getTextMetrics().actualBoundingBoxDescent / Tables.STAVE_LINE_DISTANCE);
58
+ Math.ceil(notes[i]._noteHeads[0].getTextMetrics().actualBoundingBoxDescent / Tables.STAVE_LINE_DISTANCE);
71
59
  }
72
60
  else {
73
61
  maxL =
@@ -140,8 +128,8 @@ export class StaveNote extends StemmableNote {
140
128
  else {
141
129
  const lineDiff = Math.abs(noteU.line - noteL.line);
142
130
  if (noteU.note.hasStem() && noteL.note.hasStem()) {
143
- const noteUHead = __classPrivateFieldGet(noteU.note, _StaveNote_sortedKeyProps, "f")[0].keyProps.code;
144
- const noteLHead = __classPrivateFieldGet(noteL.note, _StaveNote_sortedKeyProps, "f")[__classPrivateFieldGet(noteL.note, _StaveNote_sortedKeyProps, "f").length - 1].keyProps.code;
131
+ const noteUHead = noteU.note.sortedKeyProps[0].keyProps.code;
132
+ const noteLHead = noteL.note.sortedKeyProps[noteL.note.sortedKeyProps.length - 1].keyProps.code;
145
133
  if (!Tables.UNISON ||
146
134
  noteUHead !== noteLHead ||
147
135
  noteU.note.getModifiers().filter((item) => item.getCategory() === "Dot" && item.getIndex() === 0)
@@ -264,8 +252,7 @@ export class StaveNote extends StemmableNote {
264
252
  super(noteStruct);
265
253
  this.minLine = 0;
266
254
  this.maxLine = 0;
267
- _StaveNote_noteHeads.set(this, void 0);
268
- _StaveNote_sortedKeyProps.set(this, []);
255
+ this.sortedKeyProps = [];
269
256
  this.ledgerLineStyle = {};
270
257
  this.clef = (_a = noteStruct.clef) !== null && _a !== void 0 ? _a : 'treble';
271
258
  this.octaveShift = (_b = noteStruct.octaveShift) !== null && _b !== void 0 ? _b : 0;
@@ -274,7 +261,7 @@ export class StaveNote extends StemmableNote {
274
261
  this.displaced = false;
275
262
  this.dotShiftY = 0;
276
263
  this.useDefaultHeadX = false;
277
- __classPrivateFieldSet(this, _StaveNote_noteHeads, [], "f");
264
+ this._noteHeads = [];
278
265
  this.modifiers = [];
279
266
  this.renderOptions = Object.assign(Object.assign({}, this.renderOptions), { strokePx: noteStruct.strokePx || StaveNote.LEDGER_LINE_OFFSET });
280
267
  this.calculateKeyProps();
@@ -290,9 +277,9 @@ export class StaveNote extends StemmableNote {
290
277
  }
291
278
  reset() {
292
279
  super.reset();
293
- const noteHeadStyles = __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").map((noteHead) => noteHead.getStyle());
280
+ const noteHeadStyles = this._noteHeads.map((noteHead) => noteHead.getStyle());
294
281
  this.buildNoteHeads();
295
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").forEach((noteHead, index) => {
282
+ this._noteHeads.forEach((noteHead, index) => {
296
283
  const noteHeadStyle = noteHeadStyles[index];
297
284
  if (noteHeadStyle)
298
285
  noteHead.setStyle(noteHeadStyle);
@@ -313,11 +300,11 @@ export class StaveNote extends StemmableNote {
313
300
  return this;
314
301
  }
315
302
  buildStem() {
316
- this.setStem(new Stem({ hide: !!this.isRest() }));
303
+ this.setStem(new Stem({ hide: this.isRest() }));
317
304
  return this;
318
305
  }
319
306
  buildNoteHeads() {
320
- __classPrivateFieldSet(this, _StaveNote_noteHeads, [], "f");
307
+ this._noteHeads = [];
321
308
  const stemDirection = this.getStemDirection();
322
309
  const keys = this.getKeys();
323
310
  let lastLine = undefined;
@@ -337,7 +324,7 @@ export class StaveNote extends StemmableNote {
337
324
  step = -1;
338
325
  }
339
326
  for (let i = start; i !== end; i += step) {
340
- const noteProps = __classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f")[i].keyProps;
327
+ const noteProps = this.sortedKeyProps[i].keyProps;
341
328
  const line = noteProps.line;
342
329
  if (lastLine === undefined) {
343
330
  lastLine = line;
@@ -362,17 +349,17 @@ export class StaveNote extends StemmableNote {
362
349
  line: noteProps.line,
363
350
  });
364
351
  notehead.fontInfo = this.fontInfo;
365
- this.addChildElement(notehead);
366
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f")[__classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f")[i].index] = notehead;
352
+ this.addChild(notehead);
353
+ this._noteHeads[this.sortedKeyProps[i].index] = notehead;
367
354
  }
368
- return __classPrivateFieldGet(this, _StaveNote_noteHeads, "f");
355
+ return this._noteHeads;
369
356
  }
370
357
  autoStem() {
371
358
  this.setStemDirection(this.calculateOptimalStemDirection());
372
359
  }
373
360
  calculateOptimalStemDirection() {
374
- this.minLine = __classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f")[0].keyProps.line;
375
- this.maxLine = __classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f")[this.keyProps.length - 1].keyProps.line;
361
+ this.minLine = this.sortedKeyProps[0].keyProps.line;
362
+ this.maxLine = this.sortedKeyProps[this.keyProps.length - 1].keyProps.line;
376
363
  const MIDDLE_LINE = 3;
377
364
  const decider = (this.minLine + this.maxLine) / 2;
378
365
  const stemDirection = decider < MIDDLE_LINE ? Stem.UP : Stem.DOWN;
@@ -401,7 +388,7 @@ export class StaveNote extends StemmableNote {
401
388
  lastLine = line;
402
389
  }
403
390
  else {
404
- if (Math.abs(lastLine - line) === 0.5) {
391
+ if (Math.abs(lastLine - line) < 1) {
405
392
  this.displaced = true;
406
393
  props.displaced = true;
407
394
  if (this.keyProps.length > 0) {
@@ -413,27 +400,26 @@ export class StaveNote extends StemmableNote {
413
400
  this.keyProps.push(props);
414
401
  }
415
402
  this.keyProps.forEach((keyProps, index) => {
416
- __classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f").push({ keyProps, index });
403
+ this.sortedKeyProps.push({ keyProps, index });
417
404
  });
418
- __classPrivateFieldGet(this, _StaveNote_sortedKeyProps, "f").sort((a, b) => a.keyProps.line - b.keyProps.line);
405
+ this.sortedKeyProps.sort((a, b) => a.keyProps.line - b.keyProps.line);
419
406
  }
420
407
  getBoundingBox() {
421
408
  const boundingBox = new BoundingBox(this.getAbsoluteX(), this.ys[0], 0, 0);
422
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").forEach((notehead) => {
409
+ this._noteHeads.forEach((notehead) => {
423
410
  boundingBox.mergeWith(notehead.getBoundingBox());
424
411
  });
425
412
  const { yTop, yBottom } = this.getNoteHeadBounds();
426
- const noteStemHeight = this.stem.getHeight();
427
- const flagX = this.getStemX() - Tables.STEM_WIDTH / 2;
428
- const flagY = this.getStemDirection() === Stem.DOWN
429
- ? yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
430
- : yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
431
413
  if (!this.isRest() && this.hasStem()) {
432
- boundingBox.mergeWith(new BoundingBox(this.getAbsoluteX(), flagY, 0, 0));
414
+ const noteStemHeight = this.stem.getHeight();
415
+ const stemY = this.getStemDirection() === Stem.DOWN
416
+ ? yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
417
+ : yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
418
+ boundingBox.mergeWith(new BoundingBox(this.getAbsoluteX(), stemY, 0, 0));
433
419
  }
434
420
  if (this.hasFlag()) {
435
421
  const bbFlag = this.flag.getBoundingBox();
436
- boundingBox.mergeWith(bbFlag.move(flagX, flagY));
422
+ boundingBox.mergeWith(bbFlag);
437
423
  }
438
424
  for (let i = 0; i < this.modifiers.length; i++) {
439
425
  boundingBox.mergeWith(this.modifiers[i].getBoundingBox());
@@ -489,7 +475,7 @@ export class StaveNote extends StemmableNote {
489
475
  }
490
476
  setStave(stave) {
491
477
  super.setStave(stave);
492
- const ys = __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").map((notehead) => {
478
+ const ys = this._noteHeads.map((notehead) => {
493
479
  notehead.setStave(stave);
494
480
  return notehead.getY();
495
481
  });
@@ -553,7 +539,7 @@ export class StaveNote extends StemmableNote {
553
539
  x = this.getGlyphWidth() / 2;
554
540
  }
555
541
  let restShift = 0;
556
- switch (__classPrivateFieldGet(this, _StaveNote_noteHeads, "f")[index].getText()) {
542
+ switch (this._noteHeads[index].getText()) {
557
543
  case Glyphs.restDoubleWhole:
558
544
  case Glyphs.restWhole:
559
545
  restShift += 0.5;
@@ -597,16 +583,16 @@ export class StaveNote extends StemmableNote {
597
583
  return this.ledgerLineStyle;
598
584
  }
599
585
  setFlagStyle(style) {
600
- this.flagStyle = style;
586
+ this.flag.setStyle(style);
601
587
  }
602
588
  getFlagStyle() {
603
- return this.flagStyle;
589
+ return this.flag.getStyle();
604
590
  }
605
591
  getGlyphWidth() {
606
592
  return this.noteHeads[0].getWidth();
607
593
  }
608
594
  setKeyStyle(index, style) {
609
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f")[index].setStyle(style);
595
+ this._noteHeads[index].setStyle(style);
610
596
  return this;
611
597
  }
612
598
  setKeyLine(index, line) {
@@ -652,7 +638,7 @@ export class StaveNote extends StemmableNote {
652
638
  let lowestDisplacedLine;
653
639
  let highestNonDisplacedLine = highestLine;
654
640
  let lowestNonDisplacedLine = lowestLine;
655
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").forEach((notehead) => {
641
+ this._noteHeads.forEach((notehead) => {
656
642
  const line = notehead.getLine();
657
643
  const y = notehead.getY();
658
644
  yTop = Math.min(y, yTop);
@@ -695,7 +681,7 @@ export class StaveNote extends StemmableNote {
695
681
  return xBegin + this.getGlyphWidth();
696
682
  }
697
683
  get noteHeads() {
698
- return __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").slice();
684
+ return this._noteHeads.slice();
699
685
  }
700
686
  drawLedgerLines() {
701
687
  const stave = this.checkStave();
@@ -727,6 +713,7 @@ export class StaveNote extends StemmableNote {
727
713
  ctx.stroke();
728
714
  };
729
715
  const style = Object.assign(Object.assign({}, stave.getDefaultLedgerLineStyle()), this.getLedgerLineStyle());
716
+ ctx.save();
730
717
  this.applyStyle(ctx, style);
731
718
  for (let line = 6; line <= highestLine; ++line) {
732
719
  const normal = nonDisplacedX !== undefined && line <= highestNonDisplacedLine;
@@ -738,20 +725,17 @@ export class StaveNote extends StemmableNote {
738
725
  const displaced = lowestDisplacedLine !== undefined && line >= lowestDisplacedLine;
739
726
  drawLedgerLine(stave.getYForNote(line), normal, displaced);
740
727
  }
741
- this.restoreStyle(ctx, style);
728
+ ctx.restore();
742
729
  }
743
730
  drawModifiers(noteheadParam) {
744
731
  const ctx = this.checkContext();
745
732
  for (let i = 0; i < this.modifiers.length; i++) {
746
733
  const modifier = this.modifiers[i];
747
734
  const index = modifier.checkIndex();
748
- const notehead = __classPrivateFieldGet(this, _StaveNote_noteHeads, "f")[index];
735
+ const notehead = this._noteHeads[index];
749
736
  if (notehead === noteheadParam) {
750
- const noteheadStyle = notehead.getStyle();
751
- notehead.applyStyle(ctx, noteheadStyle);
752
737
  modifier.setContext(ctx);
753
738
  modifier.drawWithStyle();
754
- notehead.restoreStyle(ctx, noteheadStyle);
755
739
  }
756
740
  }
757
741
  }
@@ -775,20 +759,13 @@ export class StaveNote extends StemmableNote {
775
759
  yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
776
760
  :
777
761
  yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
778
- this.applyStyle(ctx, this.flagStyle);
779
- this.flag.renderText(ctx, flagX, flagY);
780
- this.restoreStyle(ctx, this.flagStyle);
762
+ this.flag.setContext(ctx).setX(flagX).setY(flagY).drawWithStyle();
781
763
  }
782
764
  }
783
765
  drawNoteHeads() {
784
766
  const ctx = this.checkContext();
785
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").forEach((notehead) => {
786
- notehead.applyStyle(ctx);
787
- ctx.openGroup('notehead', notehead.getAttribute('id'));
788
- notehead.setContext(ctx).draw();
789
- this.drawModifiers(notehead);
790
- ctx.closeGroup();
791
- notehead.restoreStyle(ctx);
767
+ this._noteHeads.forEach((notehead) => {
768
+ notehead.setContext(ctx).drawWithStyle();
792
769
  });
793
770
  }
794
771
  drawStem(stemOptions) {
@@ -800,7 +777,7 @@ export class StaveNote extends StemmableNote {
800
777
  this.stem.adjustHeightForFlag();
801
778
  }
802
779
  if (this.stem) {
803
- this.stem.setContext(ctx).draw();
780
+ this.stem.setContext(ctx).drawWithStyle();
804
781
  }
805
782
  }
806
783
  getStemExtension() {
@@ -840,13 +817,12 @@ export class StaveNote extends StemmableNote {
840
817
  const ctx = this.checkContext();
841
818
  const xBegin = this.getNoteHeadBeginX();
842
819
  const shouldRenderStem = this.hasStem() && !this.beam;
843
- __classPrivateFieldGet(this, _StaveNote_noteHeads, "f").forEach((notehead) => notehead.setX(xBegin));
820
+ this._noteHeads.forEach((notehead) => notehead.setX(xBegin));
844
821
  if (this.stem) {
845
822
  const stemX = this.getStemX();
846
823
  this.stem.setNoteHeadXBounds(stemX, stemX);
847
824
  }
848
825
  L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
849
- this.applyStyle();
850
826
  ctx.openGroup('stavenote', this.getAttribute('id'));
851
827
  this.drawLedgerLines();
852
828
  if (shouldRenderStem)
@@ -856,9 +832,7 @@ export class StaveNote extends StemmableNote {
856
832
  const bb = this.getBoundingBox();
857
833
  ctx.pointerRect(bb.getX(), bb.getY(), bb.getW(), bb.getH());
858
834
  ctx.closeGroup();
859
- this.restoreStyle();
860
835
  this.setRendered();
861
836
  }
862
837
  }
863
- _StaveNote_noteHeads = new WeakMap(), _StaveNote_sortedKeyProps = new WeakMap();
864
838
  StaveNote.DEBUG = false;
@@ -20,7 +20,9 @@ export class Repetition extends StaveModifier {
20
20
  this.yShift = y;
21
21
  return this;
22
22
  }
23
- draw(stave, x) {
23
+ draw() {
24
+ const stave = this.checkStave();
25
+ const x = stave.getModifierXShift(this.getPosition());
24
26
  this.setRendered();
25
27
  switch (this.symbolType) {
26
28
  case Repetition.type.CODA_RIGHT:
@@ -62,7 +64,6 @@ export class Repetition extends StaveModifier {
62
64
  default:
63
65
  break;
64
66
  }
65
- return this;
66
67
  }
67
68
  drawCodaFixed(stave, x) {
68
69
  const y = stave.getYForTopText(stave.getNumLines());
@@ -1,38 +1,36 @@
1
+ import { Metrics } from './metrics.js';
1
2
  import { StaveModifier } from './stavemodifier.js';
2
3
  export class StaveSection extends StaveModifier {
3
4
  static get CATEGORY() {
4
5
  return "StaveSection";
5
6
  }
6
- constructor(section, x, yShift, drawRect = true) {
7
+ constructor(section, x = 0, yShift = 0, drawRect = true) {
7
8
  super();
8
- this.setStaveSection(section);
9
+ this.setText(section);
9
10
  this.x = x;
10
11
  this.yShift = yShift;
11
12
  this.drawRect = drawRect;
13
+ this.padding = Metrics.get('StaveSection.padding');
12
14
  }
13
- setStaveSection(section) {
14
- this.text = section;
15
+ setDrawRect(drawRect) {
16
+ this.drawRect = drawRect;
15
17
  return this;
16
18
  }
17
- draw(stave, xShift) {
18
- const borderWidth = 2;
19
- const padding = 2;
19
+ draw() {
20
+ const stave = this.checkStave();
20
21
  const ctx = stave.checkContext();
21
22
  this.setRendered();
22
- ctx.save();
23
- ctx.setLineWidth(borderWidth);
23
+ this.x = stave.getX() + stave.getModifierXShift(this.getPosition());
24
24
  const headroom = -1 * this.textMetrics.actualBoundingBoxDescent;
25
- const width = this.width + 2 * padding;
26
- const height = this.height + 2 * padding;
25
+ const width = this.width + 2 * this.padding;
26
+ const height = this.height + 2 * this.padding;
27
27
  const y = stave.getYForTopText(1.5) + this.yShift;
28
- const x = this.x + xShift;
28
+ const x = this.x + this.xShift;
29
29
  if (this.drawRect) {
30
30
  ctx.beginPath();
31
31
  ctx.rect(x, y - height + headroom, width, height);
32
32
  ctx.stroke();
33
33
  }
34
- this.renderText(ctx, xShift + padding, y - padding);
35
- ctx.restore();
36
- return this;
34
+ this.renderText(ctx, this.xShift + this.padding, y - this.padding);
37
35
  }
38
36
  }
@@ -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 _StaveTempo_durationToCode;
7
1
  import { Element } from './element.js';
8
2
  import { Glyphs } from './glyphs.js';
9
3
  import { Metrics } from './metrics.js';
@@ -14,7 +8,7 @@ export class StaveTempo extends StaveModifier {
14
8
  }
15
9
  constructor(tempo, x, shiftY) {
16
10
  super();
17
- _StaveTempo_durationToCode.set(this, {
11
+ this.durationToCode = {
18
12
  '1/4': Glyphs.metNoteDoubleWholeSquare,
19
13
  long: Glyphs.metNoteDoubleWholeSquare,
20
14
  '1/2': Glyphs.metNoteDoubleWhole,
@@ -44,7 +38,7 @@ export class StaveTempo extends StaveModifier {
44
38
  '512th': Glyphs.metNote512thUp,
45
39
  1024: Glyphs.metNote1024thUp,
46
40
  '1024th': Glyphs.metNote1024thUp,
47
- });
41
+ };
48
42
  this.tempo = tempo;
49
43
  this.position = StaveModifierPosition.ABOVE;
50
44
  this.x = x;
@@ -55,7 +49,9 @@ export class StaveTempo extends StaveModifier {
55
49
  this.tempo = tempo;
56
50
  return this;
57
51
  }
58
- draw(stave, shiftX) {
52
+ draw() {
53
+ const stave = this.checkStave();
54
+ const shiftX = stave.getModifierXShift(this.getPosition());
59
55
  const ctx = stave.checkContext();
60
56
  this.setRendered();
61
57
  const { name, duration, dots, bpm, duration2, dots2, parenthesis } = this.tempo;
@@ -75,7 +71,7 @@ export class StaveTempo extends StaveModifier {
75
71
  x += elText.getWidth() + 3;
76
72
  }
77
73
  if (duration) {
78
- el.setText(__classPrivateFieldGet(this, _StaveTempo_durationToCode, "f")[duration]);
74
+ el.setText(this.durationToCode[duration]);
79
75
  el.renderText(ctx, x + this.xShift, y + this.yShift);
80
76
  x += el.getWidth() + 3;
81
77
  if (dots) {
@@ -89,7 +85,7 @@ export class StaveTempo extends StaveModifier {
89
85
  elText.renderText(ctx, x + this.xShift, y + this.yShift);
90
86
  x += elText.getWidth() + 3;
91
87
  if (duration2) {
92
- el.setText(__classPrivateFieldGet(this, _StaveTempo_durationToCode, "f")[duration2]);
88
+ el.setText(this.durationToCode[duration2]);
93
89
  el.renderText(ctx, x + this.xShift, y + this.yShift);
94
90
  x += el.getWidth() + 3;
95
91
  if (dots2) {
@@ -110,7 +106,5 @@ export class StaveTempo extends StaveModifier {
110
106
  elText.renderText(ctx, x + this.xShift, y + this.yShift);
111
107
  }
112
108
  }
113
- return this;
114
109
  }
115
110
  }
116
- _StaveTempo_durationToCode = new WeakMap();
@@ -14,7 +14,8 @@ export class StaveText extends StaveModifier {
14
14
  this.position = position;
15
15
  this.justification = (_c = options.justification) !== null && _c !== void 0 ? _c : TextNote.Justification.CENTER;
16
16
  }
17
- draw(stave) {
17
+ draw() {
18
+ const stave = this.checkStave();
18
19
  const ctx = stave.checkContext();
19
20
  this.setRendered();
20
21
  let x;
@@ -50,6 +51,5 @@ export class StaveText extends StaveModifier {
50
51
  throw new RuntimeError('InvalidPosition', 'Value Must be in Modifier.Position.');
51
52
  }
52
53
  this.renderText(ctx, x, y + 4);
53
- return this;
54
54
  }
55
55
  }
@@ -11,6 +11,9 @@ export class StaveTie extends Element {
11
11
  this.renderOptions = {
12
12
  cp1: 8,
13
13
  cp2: 12,
14
+ shortTieCutoff: 10,
15
+ cp1Short: 2,
16
+ cp2Short: 8,
14
17
  textShiftX: 0,
15
18
  firstXShift: 0,
16
19
  lastXShift: 0,
@@ -18,6 +21,20 @@ export class StaveTie extends Element {
18
21
  tieSpacing: 0,
19
22
  };
20
23
  }
24
+ getDirection() {
25
+ if (this.direction !== undefined && this.direction !== null) {
26
+ return this.direction;
27
+ }
28
+ else if (this.notes.lastNote) {
29
+ return this.notes.lastNote.getStemDirection();
30
+ }
31
+ else if (this.notes.firstNote) {
32
+ return this.notes.firstNote.getStemDirection();
33
+ }
34
+ else {
35
+ return 0;
36
+ }
37
+ }
21
38
  setDirection(direction) {
22
39
  this.direction = direction;
23
40
  return this;
@@ -48,16 +65,15 @@ export class StaveTie extends Element {
48
65
  const ctx = this.checkContext();
49
66
  let cp1 = this.renderOptions.cp1;
50
67
  let cp2 = this.renderOptions.cp2;
51
- if (Math.abs(params.lastX - params.firstX) < 10) {
52
- cp1 = 2;
53
- cp2 = 8;
68
+ if (Math.abs(params.lastX - params.firstX) < this.renderOptions.shortTieCutoff) {
69
+ cp1 = this.renderOptions.cp1Short;
70
+ cp2 = this.renderOptions.cp2Short;
54
71
  }
55
72
  const firstXShift = this.renderOptions.firstXShift;
56
73
  const lastXShift = this.renderOptions.lastXShift;
57
74
  const yShift = this.renderOptions.yShift * params.direction;
58
75
  const firstIndexes = this.notes.firstIndexes;
59
76
  const lastIndexes = this.notes.lastIndexes;
60
- this.applyStyle();
61
77
  ctx.openGroup('stavetie', this.getAttribute('id'));
62
78
  for (let i = 0; i < firstIndexes.length; ++i) {
63
79
  const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
@@ -76,7 +92,6 @@ export class StaveTie extends Element {
76
92
  ctx.fill();
77
93
  }
78
94
  ctx.closeGroup();
79
- this.restoreStyle();
80
95
  }
81
96
  renderTieText(firstX, lastX) {
82
97
  var _a, _b, _c;
@@ -85,56 +100,83 @@ export class StaveTie extends Element {
85
100
  centerX -= ctx.measureText(this.text).width / 2;
86
101
  const stave = (_b = (_a = this.notes.firstNote) === null || _a === void 0 ? void 0 : _a.checkStave()) !== null && _b !== void 0 ? _b : (_c = this.notes.lastNote) === null || _c === void 0 ? void 0 : _c.checkStave();
87
102
  if (stave) {
88
- ctx.save();
89
103
  ctx.setFont(this.fontInfo);
90
104
  ctx.fillText(this.text, centerX + this.renderOptions.textShiftX, stave.getYForTopText() - 1);
91
- ctx.restore();
92
105
  }
93
106
  }
94
107
  getNotes() {
95
108
  return this.notes;
96
109
  }
97
- draw() {
98
- this.checkContext();
99
- this.setRendered();
100
- const firstNote = this.notes.firstNote;
101
- const lastNote = this.notes.lastNote;
102
- let firstX = 0;
103
- let lastX = 0;
104
- let firstYs = [0];
105
- let lastYs = [0];
106
- let stemDirection = 0;
107
- if (firstNote) {
108
- firstX = firstNote.getTieRightX() + this.renderOptions.tieSpacing;
109
- stemDirection = firstNote.getStemDirection();
110
- firstYs = firstNote.getYs();
111
- }
112
- else if (lastNote) {
113
- const stave = lastNote.checkStave();
114
- firstX = stave.getTieStartX();
115
- firstYs = lastNote.getYs();
116
- this.notes.firstIndexes = this.notes.lastIndexes;
110
+ getFirstX() {
111
+ if (this.notes.firstNote) {
112
+ return this.notes.firstNote.getTieRightX() + this.renderOptions.tieSpacing;
113
+ }
114
+ else if (this.notes.lastNote) {
115
+ return this.notes.lastNote.checkStave().getTieStartX();
116
+ }
117
+ else {
118
+ return 0;
119
+ }
120
+ }
121
+ getLastX() {
122
+ if (this.notes.lastNote) {
123
+ return this.notes.lastNote.getTieLeftX() + this.renderOptions.tieSpacing;
124
+ }
125
+ else if (this.notes.firstNote) {
126
+ return this.notes.firstNote.checkStave().getTieEndX();
127
+ }
128
+ else {
129
+ return 0;
117
130
  }
118
- if (lastNote) {
119
- lastX = lastNote.getTieLeftX() + this.renderOptions.tieSpacing;
120
- stemDirection = lastNote.getStemDirection();
121
- lastYs = lastNote.getYs();
131
+ }
132
+ getFirstYs() {
133
+ if (this.notes.firstNote) {
134
+ return this.notes.firstNote.getYs();
135
+ }
136
+ else if (this.notes.lastNote) {
137
+ return this.notes.lastNote.getYs();
138
+ }
139
+ else {
140
+ return [0];
141
+ }
142
+ }
143
+ getLastYs() {
144
+ if (this.notes.lastNote) {
145
+ return this.notes.lastNote.getYs();
146
+ }
147
+ else if (this.notes.firstNote) {
148
+ return this.notes.firstNote.getYs();
122
149
  }
123
- else if (firstNote) {
124
- const stave = firstNote.checkStave();
125
- lastX = stave.getTieEndX();
126
- lastYs = firstNote.getYs();
150
+ else {
151
+ return [0];
152
+ }
153
+ }
154
+ synchronizeIndexes() {
155
+ if (this.notes.firstNote && this.notes.lastNote) {
156
+ return;
157
+ }
158
+ else if (!this.notes.firstNote && !this.notes.lastNote) {
159
+ return;
160
+ }
161
+ else if (this.notes.firstNote) {
127
162
  this.notes.lastIndexes = this.notes.firstIndexes;
128
163
  }
129
- if (this.direction) {
130
- stemDirection = this.direction;
164
+ else {
165
+ this.notes.firstIndexes = this.notes.lastIndexes;
131
166
  }
167
+ }
168
+ draw() {
169
+ this.checkContext();
170
+ this.setRendered();
171
+ this.synchronizeIndexes();
172
+ const firstX = this.getFirstX();
173
+ const lastX = this.getLastX();
132
174
  this.renderTie({
133
175
  firstX,
134
176
  lastX,
135
- firstYs,
136
- lastYs,
137
- direction: stemDirection,
177
+ firstYs: this.getFirstYs(),
178
+ lastYs: this.getLastYs(),
179
+ direction: this.getDirection(),
138
180
  });
139
181
  this.renderTieText(firstX, lastX);
140
182
  return true;
@@ -21,7 +21,9 @@ export class Volta extends StaveModifier {
21
21
  this.yShift = yShift;
22
22
  this.text = label;
23
23
  }
24
- draw(stave, x) {
24
+ draw() {
25
+ const stave = this.checkStave();
26
+ const x = stave.getModifierXShift(this.getPosition());
25
27
  const ctx = stave.checkContext();
26
28
  this.setRendered();
27
29
  let width = stave.getWidth() - x;
@@ -47,6 +49,5 @@ export class Volta extends StaveModifier {
47
49
  this.renderText(ctx, x + 5, topY - this.yShift + 15);
48
50
  }
49
51
  ctx.fillRect(this.x + x, topY, width, 1);
50
- return this;
51
52
  }
52
53
  }