vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4

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 (157) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +528 -492
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +460 -452
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/accidental.js +22 -28
  12. package/build/esm/src/beam.js +24 -42
  13. package/build/esm/src/clefnote.js +6 -1
  14. package/build/esm/src/element.js +83 -101
  15. package/build/esm/src/fonts/gonville.js +1 -1
  16. package/build/esm/src/formatter.js +9 -17
  17. package/build/esm/src/fraction.js +15 -22
  18. package/build/esm/src/glyphnote.js +3 -2
  19. package/build/esm/src/metrics.js +3 -0
  20. package/build/esm/src/modifier.js +6 -21
  21. package/build/esm/src/multimeasurerest.js +16 -25
  22. package/build/esm/src/note.js +7 -0
  23. package/build/esm/src/registry.js +5 -19
  24. package/build/esm/src/stave.js +4 -6
  25. package/build/esm/src/stavenote.js +26 -40
  26. package/build/esm/src/stavetempo.js +4 -11
  27. package/build/esm/src/stavetie.js +82 -36
  28. package/build/esm/src/svgcontext.js +5 -12
  29. package/build/esm/src/tickable.js +13 -26
  30. package/build/esm/src/tickcontext.js +20 -2
  31. package/build/esm/src/version.js +3 -3
  32. package/build/esm/src/vibrato.js +6 -1
  33. package/build/esm/tests/clef_tests.js +5 -1
  34. package/build/esm/tests/glyphnote_tests.js +6 -0
  35. package/build/esm/tests/stavetie_tests.js +29 -0
  36. package/build/esm/tests/tabstave_tests.js +1 -0
  37. package/build/esm/tests/vexflow_test_helpers.js +25 -39
  38. package/build/types/src/accidental.d.ts +19 -1
  39. package/build/types/src/annotation.d.ts +1 -1
  40. package/build/types/src/beam.d.ts +12 -1
  41. package/build/types/src/clefnote.d.ts +2 -0
  42. package/build/types/src/element.d.ts +13 -3
  43. package/build/types/src/fonts/gonville.d.ts +1 -1
  44. package/build/types/src/formatter.d.ts +5 -3
  45. package/build/types/src/fraction.d.ts +12 -7
  46. package/build/types/src/modifier.d.ts +2 -1
  47. package/build/types/src/multimeasurerest.d.ts +4 -1
  48. package/build/types/src/note.d.ts +2 -0
  49. package/build/types/src/registry.d.ts +1 -1
  50. package/build/types/src/stavenote.d.ts +2 -1
  51. package/build/types/src/stavetempo.d.ts +3 -3
  52. package/build/types/src/stavetie.d.ts +39 -2
  53. package/build/types/src/svgcontext.d.ts +1 -1
  54. package/build/types/src/tickable.d.ts +2 -1
  55. package/build/types/src/tickcontext.d.ts +30 -0
  56. package/package.json +2 -4
  57. package/tests/flow.html +2 -2
  58. package/entry/vexflow-bravura.ts +0 -25
  59. package/entry/vexflow-core.ts +0 -16
  60. package/entry/vexflow-debug-with-tests.ts +0 -64
  61. package/entry/vexflow-debug.ts +0 -54
  62. package/entry/vexflow.ts +0 -47
  63. package/src/accidental.ts +0 -570
  64. package/src/annotation.ts +0 -294
  65. package/src/articulation.ts +0 -383
  66. package/src/barnote.ts +0 -95
  67. package/src/beam.ts +0 -999
  68. package/src/bend.ts +0 -268
  69. package/src/boundingbox.ts +0 -108
  70. package/src/canvascontext.ts +0 -348
  71. package/src/chordsymbol.ts +0 -473
  72. package/src/clef.ts +0 -164
  73. package/src/clefnote.ts +0 -50
  74. package/src/crescendo.ts +0 -132
  75. package/src/curve.ts +0 -195
  76. package/src/dot.ts +0 -171
  77. package/src/easyscore.ts +0 -538
  78. package/src/element.ts +0 -692
  79. package/src/factory.ts +0 -694
  80. package/src/font.ts +0 -343
  81. package/src/fonts/academico.ts +0 -2
  82. package/src/fonts/academicobold.ts +0 -2
  83. package/src/fonts/bravura.ts +0 -2
  84. package/src/fonts/gonville.ts +0 -2
  85. package/src/fonts/petaluma.ts +0 -2
  86. package/src/fonts/petalumascript.ts +0 -2
  87. package/src/formatter.ts +0 -1107
  88. package/src/fraction.ts +0 -245
  89. package/src/frethandfinger.ts +0 -180
  90. package/src/ghostnote.ts +0 -75
  91. package/src/glyphnote.ts +0 -68
  92. package/src/glyphs.ts +0 -5880
  93. package/src/gracenote.ts +0 -146
  94. package/src/gracenotegroup.ts +0 -194
  95. package/src/gracetabnote.ts +0 -30
  96. package/src/index.ts +0 -90
  97. package/src/keymanager.ts +0 -153
  98. package/src/keysignature.ts +0 -272
  99. package/src/keysignote.ts +0 -46
  100. package/src/metrics.ts +0 -222
  101. package/src/modifier.ts +0 -216
  102. package/src/modifiercontext.ts +0 -177
  103. package/src/multimeasurerest.ts +0 -229
  104. package/src/music.ts +0 -443
  105. package/src/note.ts +0 -690
  106. package/src/notehead.ts +0 -158
  107. package/src/notesubgroup.ts +0 -88
  108. package/src/ornament.ts +0 -301
  109. package/src/parenthesis.ts +0 -89
  110. package/src/parser.ts +0 -263
  111. package/src/pedalmarking.ts +0 -273
  112. package/src/registry.ts +0 -146
  113. package/src/rendercontext.ts +0 -98
  114. package/src/renderer.ts +0 -166
  115. package/src/repeatnote.ts +0 -25
  116. package/src/stave.ts +0 -885
  117. package/src/stavebarline.ts +0 -231
  118. package/src/staveconnector.ts +0 -281
  119. package/src/stavehairpin.ts +0 -209
  120. package/src/staveline.ts +0 -343
  121. package/src/stavemodifier.ts +0 -93
  122. package/src/stavenote.ts +0 -1230
  123. package/src/staverepetition.ts +0 -148
  124. package/src/stavesection.ts +0 -54
  125. package/src/stavetempo.ts +0 -162
  126. package/src/stavetext.ts +0 -69
  127. package/src/stavetie.ts +0 -235
  128. package/src/stavevolta.ts +0 -66
  129. package/src/stem.ts +0 -225
  130. package/src/stemmablenote.ts +0 -248
  131. package/src/stringnumber.ts +0 -286
  132. package/src/strokes.ts +0 -214
  133. package/src/svgcontext.ts +0 -639
  134. package/src/system.ts +0 -327
  135. package/src/tables.ts +0 -796
  136. package/src/tabnote.ts +0 -449
  137. package/src/tabslide.ts +0 -115
  138. package/src/tabstave.ts +0 -31
  139. package/src/tabtie.ts +0 -44
  140. package/src/textbracket.ts +0 -231
  141. package/src/textdynamics.ts +0 -101
  142. package/src/textnote.ts +0 -175
  143. package/src/tickable.ts +0 -374
  144. package/src/tickcontext.ts +0 -280
  145. package/src/timesignature.ts +0 -229
  146. package/src/timesignote.ts +0 -45
  147. package/src/tremolo.ts +0 -51
  148. package/src/tuning.ts +0 -90
  149. package/src/tuplet.ts +0 -349
  150. package/src/typeguard.ts +0 -136
  151. package/src/util.ts +0 -169
  152. package/src/version.ts +0 -4
  153. package/src/vexflow.ts +0 -378
  154. package/src/vibrato.ts +0 -99
  155. package/src/vibratobracket.ts +0 -81
  156. package/src/voice.ts +0 -302
  157. package/src/web.ts +0 -35
@@ -1,229 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- // Implements time signatures glyphs for staffs
5
- // See tables.js for the internal time signatures
6
- // representation
7
-
8
- import { Element } from './element';
9
- import { Glyphs } from './glyphs';
10
- import { RenderContext } from './rendercontext';
11
- import { Stave } from './stave';
12
- import { StaveModifier, StaveModifierPosition } from './stavemodifier';
13
- import { Category } from './typeguard';
14
- import { RuntimeError } from './util';
15
-
16
- export interface TimeSignatureInfo {
17
- glyph: string;
18
- line: number;
19
- num: boolean;
20
- }
21
-
22
- const assertIsValidTimeSig = (timeSpec: string) => {
23
- const numbers = timeSpec.split('/');
24
-
25
- numbers.forEach((number) => {
26
- // Characters consisting in number 0..9, '+', '-', '(' or ')'
27
- if (/^[0-9+\-()]+$/.test(number) === false) {
28
- throw new RuntimeError('BadTimeSignature', `Invalid time spec: ${timeSpec}. Must contain valid signatures.`);
29
- }
30
- });
31
- };
32
-
33
- /**
34
- * A TimeSignature is a StaveModifier that can make its appropriate Glyphs directly from
35
- * a provided "timeSpec" such as "4/4", "C|" (cut time), or even something more advanced
36
- * such as "3/4(6/8)" or "2/4+5/8".
37
- */
38
- export class TimeSignature extends StaveModifier {
39
- static get CATEGORY(): string {
40
- return Category.TimeSignature;
41
- }
42
-
43
- bottomLine: number; // bottomLine and topLine are used to calculate the position of the
44
- topLine: number; // top row of digits in a numeric TimeSignature.
45
-
46
- protected timeSpec: string = '4/4';
47
- protected line: number = 0;
48
- protected topText: Element;
49
- protected botText: Element;
50
- protected isNumeric: boolean = true;
51
- protected validateArgs: boolean;
52
- protected topStartX: number = 0;
53
- protected botStartX: number = 0;
54
- protected lineShift: number = 0;
55
-
56
- constructor(timeSpec: string = '4/4', customPadding = 15, validateArgs = true) {
57
- super();
58
- this.topText = new Element();
59
- this.botText = new Element();
60
- this.validateArgs = validateArgs;
61
-
62
- const padding = customPadding;
63
-
64
- this.topLine = 1;
65
- this.bottomLine = 3;
66
- this.setPosition(StaveModifierPosition.BEGIN);
67
- this.setTimeSig(timeSpec);
68
- this.setPadding(padding);
69
- }
70
-
71
- static getTimeSigCode(key: string, smallSig = false): string {
72
- let code: string = Glyphs.null;
73
- switch (key) {
74
- case 'C':
75
- code = Glyphs.timeSigCommon;
76
- break;
77
- case 'C|':
78
- code = Glyphs.timeSigCutCommon;
79
- break;
80
- case '+':
81
- code = smallSig ? Glyphs.timeSigPlusSmall : Glyphs.timeSigPlus;
82
- break;
83
- case '-':
84
- code = Glyphs.timeSigMinus;
85
- break;
86
- case '(':
87
- code = smallSig ? Glyphs.timeSigParensLeftSmall : Glyphs.timeSigParensLeft;
88
- break;
89
- case ')':
90
- code = smallSig ? Glyphs.timeSigParensRightSmall : Glyphs.timeSigParensRight;
91
- break;
92
- default:
93
- code = String.fromCodePoint(0xe080 + Number(key[0])) /* timeSigN = Glyphs.timeSig0 + N */;
94
- break;
95
- }
96
- return code;
97
- }
98
-
99
- /**
100
- * Returns a new TimeSignatureGlyph (a Glyph subclass that knows how to draw both
101
- * top and bottom digits along with plus signs etc.)
102
- */
103
- makeTimeSignatureGlyph(topDigits: string, botDigits: string): void {
104
- // note that 'code' is ignored by TimeSignatureGlyph when rendering.
105
- let txt = '';
106
- let topWidth = 0;
107
- let height = 0;
108
- for (let i = 0; i < topDigits.length; ++i) {
109
- const code = TimeSignature.getTimeSigCode(topDigits[i], botDigits.length > 0);
110
- txt += code;
111
- }
112
- this.topText.setText(txt);
113
- topWidth = this.topText.getWidth();
114
- height = this.topText.getHeight();
115
-
116
- let botWidth = 0;
117
- txt = '';
118
- for (let i = 0; i < botDigits.length; ++i) {
119
- const code = TimeSignature.getTimeSigCode(botDigits[i], true);
120
- txt += code;
121
- }
122
- this.botText.setText(txt);
123
- botWidth = this.botText.getWidth();
124
- height = Math.max(height, this.botText.getHeight());
125
-
126
- // If the height of the digits is more than three staff spaces (30), shift half a line line
127
- // in order to center the digits on lines 1.5 and 4.5 rather than 2 and 4.
128
- this.lineShift = height > 30 ? 0.5 : 0;
129
-
130
- this.width = Math.max(topWidth, botWidth);
131
- this.topStartX = (this.width - topWidth) / 2.0;
132
- this.botStartX = (this.width - botWidth) / 2.0;
133
- }
134
-
135
- /**
136
- * Set a new time signature specification without changing customPadding, etc.
137
- *
138
- * The getter for this is `getTimeSpec` not `getTimeSig`.
139
- */
140
- setTimeSig(timeSpec: string): this {
141
- this.timeSpec = timeSpec;
142
- if (timeSpec === 'C' || timeSpec === 'C|') {
143
- const code = TimeSignature.getTimeSigCode(timeSpec);
144
- this.line = 2;
145
- this.text = code;
146
- this.isNumeric = false;
147
- } else {
148
- if (this.validateArgs) {
149
- assertIsValidTimeSig(timeSpec);
150
- }
151
- const parts = timeSpec.split('/');
152
- this.line = 0;
153
- this.isNumeric = true;
154
- this.makeTimeSignatureGlyph(parts[0] ?? '', parts[1] ?? '');
155
- }
156
- return this;
157
- }
158
-
159
- /**
160
- * Return the timeSpec (such as '4/4' or 'C|' or even '2/4+3/8') of the TimeSignature
161
- */
162
- getTimeSpec(): string {
163
- return this.timeSpec;
164
- }
165
-
166
- /**
167
- * Return the staff line that the TimeSignature sits on. Generally 0 for numerator/
168
- * denominator time signatures such as 3/4 and 2 for cut/common.
169
- */
170
- getLine(): number {
171
- return this.line;
172
- }
173
-
174
- /**
175
- * Set the line number that the TimeSignature sits on. Half-values are acceptable
176
- * for spaces, etc. Can be altered, for instance, for signatures that sit above the
177
- * staff in large orchestral scores.
178
- */
179
- setLine(line: number) {
180
- this.line = line;
181
- }
182
-
183
- /**
184
- * Return a boolean on whether this TimeSignature is drawn with one or more numbers
185
- * (such as 4/4) or not (as in cut time).
186
- */
187
- getIsNumeric(): boolean {
188
- return this.isNumeric;
189
- }
190
-
191
- /**
192
- * Set whether this TimeSignature is drawn with one or more numbers.
193
- */
194
- setIsNumeric(isNumeric: boolean) {
195
- this.isNumeric = isNumeric;
196
- }
197
-
198
- /**
199
- * Draw the time signature on a Stave using its RenderContext. Both setStave
200
- * and setContext must already be run.
201
- */
202
- draw(): void {
203
- const stave = this.checkStave();
204
- const ctx = stave.checkContext();
205
- this.setRendered();
206
- this.drawAt(ctx, stave, this.x);
207
- }
208
-
209
- drawAt(ctx: RenderContext, stave: Stave, x: number): void {
210
- this.setRendered();
211
-
212
- this.applyStyle(ctx);
213
- ctx.openGroup('timesignature', this.getAttribute('id'));
214
- if (this.isNumeric) {
215
- let startX = x + this.topStartX;
216
- let y = 0;
217
- if (this.botText.getText().length > 0) y = stave.getYForLine(this.topLine - this.lineShift);
218
- else y = (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
219
- this.topText.renderText(ctx, startX, y);
220
- startX = x + this.botStartX;
221
- y = stave.getYForLine(this.bottomLine + this.lineShift);
222
- this.botText.renderText(ctx, startX, y);
223
- } else {
224
- this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
225
- }
226
- ctx.closeGroup();
227
- this.restoreStyle(ctx);
228
- }
229
- }
@@ -1,45 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Taehoon Moon 2014
3
-
4
- import { ModifierContext } from './modifiercontext';
5
- import { Note } from './note';
6
- import { TimeSignature } from './timesignature';
7
- import { Category } from './typeguard';
8
-
9
- export class TimeSigNote extends Note {
10
- static get CATEGORY(): string {
11
- return Category.TimeSigNote;
12
- }
13
-
14
- protected timeSig: TimeSignature;
15
-
16
- constructor(timeSpec: string, customPadding?: number) {
17
- super({ duration: 'b' });
18
-
19
- this.timeSig = new TimeSignature(timeSpec, customPadding);
20
- this.setWidth(this.timeSig.getWidth());
21
-
22
- // Note properties
23
- this.ignoreTicks = true;
24
- }
25
-
26
- /* Overridden to ignore */
27
- // eslint-disable-next-line
28
- addToModifierContext(mc: ModifierContext): this {
29
- // DO NOTHING.
30
- return this;
31
- }
32
-
33
- preFormat(): this {
34
- this.preFormatted = true;
35
- return this;
36
- }
37
-
38
- draw(): void {
39
- const stave = this.checkStave();
40
- const ctx = this.checkContext();
41
- this.setRendered();
42
-
43
- this.timeSig.drawAt(ctx, stave, this.getAbsoluteX());
44
- }
45
- }
package/src/tremolo.ts DELETED
@@ -1,51 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Mike Corrigan <corrigan@gmail.com>
3
- // MIT License
4
-
5
- import { Glyphs } from './glyphs';
6
- import { Metrics } from './metrics';
7
- import { Modifier } from './modifier';
8
- import { Stem } from './stem';
9
- import { Category } from './typeguard';
10
-
11
- /** Tremolo implements tremolo notation. */
12
- export class Tremolo extends Modifier {
13
- static get CATEGORY(): string {
14
- return Category.Tremolo;
15
- }
16
-
17
- protected readonly num: number;
18
-
19
- /**
20
- * @param num number of bars
21
- */
22
- constructor(num: number) {
23
- super();
24
-
25
- this.num = num;
26
- this.position = Modifier.Position.CENTER;
27
- this.text = Glyphs.tremolo1;
28
- }
29
-
30
- /** Draw the tremolo on the rendering context. */
31
- draw(): void {
32
- const ctx = this.checkContext();
33
- const note = this.checkAttachedNote();
34
- this.setRendered();
35
-
36
- const stemDirection = note.getStemDirection();
37
- const scale = note.getFontScale();
38
- const ySpacing = Metrics.get(`Tremolo.spacing`) * stemDirection * scale;
39
-
40
- const x =
41
- note.getAbsoluteX() + (stemDirection === Stem.UP ? note.getGlyphWidth() - Stem.WIDTH / 2 : Stem.WIDTH / 2);
42
- let y = note.getStemExtents().topY + (this.num <= 3 ? ySpacing : 0);
43
-
44
- this.fontInfo.size = Metrics.get(`Tremolo.fontSize`) * scale;
45
-
46
- for (let i = 0; i < this.num; ++i) {
47
- this.renderText(ctx, x, y);
48
- y += ySpacing;
49
- }
50
- }
51
- }
package/src/tuning.ts DELETED
@@ -1,90 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Tables } from './tables';
5
- import { RuntimeError } from './util';
6
-
7
- /** `Tuning` implements varies types of tunings for tablature. */
8
- export class Tuning {
9
- protected tuningValues: number[] = [];
10
-
11
- static get names(): Record<string, string> {
12
- return {
13
- standard: 'E/5,B/4,G/4,D/4,A/3,E/3',
14
- dagdad: 'D/5,A/4,G/4,D/4,A/3,D/3',
15
- dropd: 'E/5,B/4,G/4,D/4,A/3,D/3',
16
- eb: 'Eb/5,Bb/4,Gb/4,Db/4,Ab/3,Db/3',
17
- standardBanjo: 'D/5,B/4,G/4,D/4,G/5',
18
- };
19
- }
20
-
21
- /**
22
- * Constructor.
23
- * @param tuningString tuning name (eg. 'dagdad') or comma separated note strings
24
- */
25
- constructor(tuningString = 'E/5,B/4,G/4,D/4,A/3,E/3,B/2,E/2') {
26
- // Default to standard tuning.
27
- this.setTuning(tuningString);
28
- }
29
-
30
- /** Return the note number associated to the note string. */
31
- noteToInteger(noteString: string): number {
32
- return Tables.keyProperties(noteString).intValue ?? -1;
33
- }
34
-
35
- /**
36
- * Set tuning identified by tuning name (eg. 'dagdad')
37
- * @param tuningString tuning name (eg. 'dagdad') or comma separated note strings
38
- */
39
- setTuning(tuningString: string): void {
40
- if (Tuning.names[tuningString]) {
41
- tuningString = Tuning.names[tuningString];
42
- }
43
-
44
- this.tuningValues = [];
45
-
46
- const keys = tuningString.split(/\s*,\s*/);
47
- if (keys.length === 0) {
48
- throw new RuntimeError('BadArguments', `Invalid tuning string: ${tuningString}`);
49
- }
50
-
51
- for (let i = 0; i < keys.length; ++i) {
52
- this.tuningValues[i] = this.noteToInteger(keys[i]);
53
- }
54
- }
55
-
56
- /** Return the note number associated with a tablature string. */
57
- getValueForString(stringNum: string | number): number {
58
- const s = Number(stringNum);
59
- if (s < 1 || s > this.tuningValues.length) {
60
- throw new RuntimeError(
61
- 'BadArguments',
62
- `String number must be between 1 and ${this.tuningValues.length}:${stringNum}`
63
- );
64
- }
65
-
66
- return this.tuningValues[s - 1];
67
- }
68
-
69
- /** Return the note number associated with a tablature string and fret. */
70
- getValueForFret(fretNum: string | number, stringNum: string | number): number {
71
- const stringValue = this.getValueForString(stringNum);
72
- const f = Number(fretNum);
73
-
74
- if (f < 0) {
75
- throw new RuntimeError('BadArguments', `Fret number must be 0 or higher: ${fretNum}`);
76
- }
77
-
78
- return stringValue + f;
79
- }
80
-
81
- /** Return the note string associated with tablature string and fret. */
82
- getNoteForFret(fretNum: string | number, stringNum: string | number): string {
83
- const noteValue = this.getValueForFret(fretNum, stringNum);
84
-
85
- const octave = Math.floor(noteValue / 12);
86
- const value = noteValue % 12;
87
-
88
- return `${Tables.integerToNote(value)}/${octave}`;
89
- }
90
- }