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
package/src/staveline.ts DELETED
@@ -1,343 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- //
5
- // This file implements `StaveLine` which are simply lines that connect
6
- // two notes. This object is highly configurable, see the `renderOptions`.
7
- // A simple line is often used for notating glissando articulations, but you
8
- // can format a `StaveLine` with arrows or colors for more pedagogical
9
- // purposes, such as diagrams.
10
-
11
- import { Element } from './element';
12
- import { RenderContext } from './rendercontext';
13
- import { StaveNote } from './stavenote';
14
- import { Tables } from './tables';
15
- import { TextJustification } from './textnote';
16
- import { Category } from './typeguard';
17
- import { RuntimeError } from './util';
18
-
19
- export interface StaveLineNotes {
20
- firstNote: StaveNote;
21
- firstIndexes: number[];
22
- lastNote: StaveNote;
23
- lastIndexes: number[];
24
- }
25
-
26
- // Attribution: Arrow rendering implementations based off of
27
- // Patrick Horgan's article, "Drawing lines and arcs with
28
- // arrow heads on HTML5 Canvas"
29
- //
30
- // Draw an arrow head that connects between 3 coordinates.
31
- function drawArrowHead(
32
- ctx: RenderContext,
33
- x0: number,
34
- y0: number,
35
- x1: number,
36
- y1: number,
37
- x2: number,
38
- y2: number
39
- ): void {
40
- // all cases do this.
41
- ctx.beginPath();
42
- ctx.moveTo(x0, y0);
43
- ctx.lineTo(x1, y1);
44
- ctx.lineTo(x2, y2);
45
- ctx.lineTo(x0, y0);
46
- ctx.closePath();
47
-
48
- ctx.fill();
49
- }
50
-
51
- export class StaveLine extends Element {
52
- static get CATEGORY(): string {
53
- return Category.StaveLine;
54
- }
55
-
56
- // Text Positioning
57
- static readonly TextVerticalPosition = {
58
- TOP: 1,
59
- BOTTOM: 2,
60
- };
61
-
62
- static readonly TextJustification = TextJustification;
63
-
64
- public renderOptions: {
65
- paddingLeft: number;
66
- paddingRight: number;
67
- lineWidth: number;
68
- lineDash?: number[];
69
- roundedEnd: boolean;
70
- color?: string;
71
- drawStartArrow: boolean;
72
- drawEndArrow: boolean;
73
- arrowheadLength: number;
74
- arrowheadAngle: number;
75
- textPositionVertical: number;
76
- textJustification: number;
77
- };
78
-
79
- // These five instance variables are all initialized by the constructor via this.setNotes(notes).
80
- protected notes!: StaveLineNotes;
81
- protected firstNote!: StaveNote;
82
- protected firstIndexes!: number[];
83
- protected lastNote!: StaveNote;
84
- protected lastIndexes!: number[];
85
-
86
- // Initialize the StaveLine with the given `notes`.
87
- //
88
- // `notes` is a struct that has:
89
- //
90
- // ```
91
- // {
92
- // firstNote: Note,
93
- // lastNote: Note,
94
- // firstIndexes: [n1, n2, n3],
95
- // lastIndexes: [n1, n2, n3]
96
- // }
97
- // ```
98
- constructor(notes: StaveLineNotes) {
99
- super();
100
-
101
- this.setNotes(notes);
102
-
103
- this.text = '';
104
-
105
- this.renderOptions = {
106
- // Space to add to the left or the right
107
- paddingLeft: 4,
108
- paddingRight: 3,
109
-
110
- // The width of the line in pixels
111
- lineWidth: 1,
112
- // An array of line/space lengths. (TODO/QUESTION: Is this supported in SVG?).
113
- lineDash: undefined,
114
- // Can draw rounded line end, instead of a square. (TODO/QUESTION: Is this supported in SVG?).
115
- roundedEnd: true,
116
- // The color of the line and arrowheads
117
- color: undefined,
118
-
119
- // Flags to draw arrows on each end of the line
120
- drawStartArrow: false,
121
- drawEndArrow: false,
122
-
123
- // The length of the arrowhead sides
124
- arrowheadLength: 10,
125
- // The angle of the arrowhead
126
- arrowheadAngle: Math.PI / 8,
127
-
128
- // The position of the text
129
- textPositionVertical: StaveLine.TextVerticalPosition.TOP,
130
- textJustification: StaveLine.TextJustification.CENTER,
131
- };
132
- }
133
-
134
- // The the annotation for the `StaveLine`
135
- setText(text: string): this {
136
- this.text = text;
137
- return this;
138
- }
139
-
140
- // Set the notes for the `StaveLine`
141
- setNotes(notes: StaveLineNotes): this {
142
- if (!notes.firstNote && !notes.lastNote) {
143
- throw new RuntimeError('BadArguments', 'Notes needs to have either firstNote or lastNote set.');
144
- }
145
-
146
- if (!notes.firstIndexes) notes.firstIndexes = [0];
147
- if (!notes.lastIndexes) notes.lastIndexes = [0];
148
-
149
- if (notes.firstIndexes.length !== notes.lastIndexes.length) {
150
- throw new RuntimeError('BadArguments', 'Connected notes must have same number of indexes.');
151
- }
152
-
153
- this.notes = notes;
154
- this.firstNote = notes.firstNote;
155
- this.firstIndexes = notes.firstIndexes;
156
- this.lastNote = notes.lastNote;
157
- this.lastIndexes = notes.lastIndexes;
158
- return this;
159
- }
160
-
161
- // Apply the style of the `StaveLine` to the context
162
- applyLineStyle(): void {
163
- const ctx = this.checkContext();
164
- const renderOptions = this.renderOptions;
165
-
166
- if (renderOptions.lineDash) {
167
- ctx.setLineDash(renderOptions.lineDash);
168
- }
169
-
170
- if (renderOptions.lineWidth) {
171
- ctx.setLineWidth(renderOptions.lineWidth);
172
- }
173
-
174
- if (renderOptions.roundedEnd) {
175
- ctx.setLineCap('round');
176
- } else {
177
- ctx.setLineCap('square');
178
- }
179
- }
180
-
181
- // Helper function to draw a line with arrow heads
182
- protected drawArrowLine(ctx: RenderContext, pt1: { x: number; y: number }, pt2: { x: number; y: number }): void {
183
- const bothArrows = this.renderOptions.drawStartArrow && this.renderOptions.drawEndArrow;
184
-
185
- const x1 = pt1.x;
186
- const y1 = pt1.y;
187
- const x2 = pt2.x;
188
- const y2 = pt2.y;
189
-
190
- // For ends with arrow we actually want to stop before we get to the arrow
191
- // so that wide lines won't put a flat end on the arrow.
192
- const distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
193
- const ratio = (distance - this.renderOptions.arrowheadLength / 3) / distance;
194
- let endX;
195
- let endY;
196
- let startX;
197
- let startY;
198
- if (this.renderOptions.drawEndArrow || bothArrows) {
199
- endX = Math.round(x1 + (x2 - x1) * ratio);
200
- endY = Math.round(y1 + (y2 - y1) * ratio);
201
- } else {
202
- endX = x2;
203
- endY = y2;
204
- }
205
-
206
- if (this.renderOptions.drawStartArrow || bothArrows) {
207
- startX = x1 + (x2 - x1) * (1 - ratio);
208
- startY = y1 + (y2 - y1) * (1 - ratio);
209
- } else {
210
- startX = x1;
211
- startY = y1;
212
- }
213
-
214
- if (this.renderOptions.color) {
215
- ctx.setStrokeStyle(this.renderOptions.color);
216
- ctx.setFillStyle(this.renderOptions.color);
217
- }
218
-
219
- // Draw the shaft of the arrow
220
- ctx.beginPath();
221
- ctx.moveTo(startX, startY);
222
- ctx.lineTo(endX, endY);
223
- ctx.stroke();
224
- ctx.closePath();
225
-
226
- // calculate the angle of the line
227
- const lineAngle = Math.atan2(y2 - y1, x2 - x1);
228
- // h is the line length of a side of the arrow head
229
- const h = Math.abs(this.renderOptions.arrowheadLength / Math.cos(this.renderOptions.arrowheadAngle));
230
-
231
- let angle1;
232
- let angle2;
233
- let topX;
234
- let topY;
235
- let bottomX;
236
- let bottomY;
237
-
238
- if (this.renderOptions.drawEndArrow || bothArrows) {
239
- angle1 = lineAngle + Math.PI + this.renderOptions.arrowheadAngle;
240
- topX = x2 + Math.cos(angle1) * h;
241
- topY = y2 + Math.sin(angle1) * h;
242
-
243
- angle2 = lineAngle + Math.PI - this.renderOptions.arrowheadAngle;
244
- bottomX = x2 + Math.cos(angle2) * h;
245
- bottomY = y2 + Math.sin(angle2) * h;
246
-
247
- drawArrowHead(ctx, topX, topY, x2, y2, bottomX, bottomY);
248
- }
249
-
250
- if (this.renderOptions.drawStartArrow || bothArrows) {
251
- angle1 = lineAngle + this.renderOptions.arrowheadAngle;
252
- topX = x1 + Math.cos(angle1) * h;
253
- topY = y1 + Math.sin(angle1) * h;
254
-
255
- angle2 = lineAngle - this.renderOptions.arrowheadAngle;
256
- bottomX = x1 + Math.cos(angle2) * h;
257
- bottomY = y1 + Math.sin(angle2) * h;
258
-
259
- drawArrowHead(ctx, topX, topY, x1, y1, bottomX, bottomY);
260
- }
261
- }
262
-
263
- // Renders the `StaveLine` on the context
264
- draw(): this {
265
- const ctx = this.checkContext();
266
- this.setRendered();
267
-
268
- const firstNote = this.firstNote;
269
- const lastNote = this.lastNote;
270
- const renderOptions = this.renderOptions;
271
-
272
- ctx.save();
273
- this.applyLineStyle();
274
-
275
- // Cycle through each set of indexes and draw lines
276
- let startPosition = { x: 0, y: 0 };
277
- let endPosition = { x: 0, y: 0 };
278
- this.firstIndexes.forEach((firstIndex, i) => {
279
- const lastIndex = this.lastIndexes[i];
280
-
281
- // Get initial coordinates for the start/end of the line
282
- startPosition = firstNote.getModifierStartXY(2, firstIndex);
283
- endPosition = lastNote.getModifierStartXY(1, lastIndex);
284
- const upwardsSlope = startPosition.y > endPosition.y;
285
-
286
- // Adjust `x` coordinates for modifiers
287
- startPosition.x += firstNote.getMetrics().modRightPx + renderOptions.paddingLeft;
288
- endPosition.x -= lastNote.getMetrics().modLeftPx + renderOptions.paddingRight;
289
-
290
- // Adjust first `x` coordinates for displacements
291
- const noteheadWidth = firstNote.getGlyphWidth();
292
- const firstDisplaced = firstNote.getKeyProps()[firstIndex].displaced;
293
- if (firstDisplaced && firstNote.getStemDirection() === 1) {
294
- startPosition.x += noteheadWidth + renderOptions.paddingLeft;
295
- }
296
-
297
- // Adjust last `x` coordinates for displacements
298
- const lastDisplaced = lastNote.getKeyProps()[lastIndex].displaced;
299
- if (lastDisplaced && lastNote.getStemDirection() === -1) {
300
- endPosition.x -= noteheadWidth + renderOptions.paddingRight;
301
- }
302
-
303
- // Adjust y position better if it's not coming from the center of the note
304
- startPosition.y += upwardsSlope ? -3 : 1;
305
- endPosition.y += upwardsSlope ? 2 : 0;
306
-
307
- this.drawArrowLine(ctx, startPosition, endPosition);
308
- });
309
-
310
- ctx.restore();
311
-
312
- // Determine the x coordinate where to start the text
313
- const textWidth = this.width;
314
- const justification = renderOptions.textJustification;
315
- let x = 0;
316
- if (justification === StaveLine.TextJustification.LEFT) {
317
- x = startPosition.x;
318
- } else if (justification === StaveLine.TextJustification.CENTER) {
319
- const deltaX = endPosition.x - startPosition.x;
320
- const centerX = deltaX / 2 + startPosition.x;
321
- x = centerX - textWidth / 2;
322
- } else if (justification === StaveLine.TextJustification.RIGHT) {
323
- x = endPosition.x - textWidth;
324
- }
325
-
326
- // Determine the y value to start the text
327
- let y = 0;
328
- const verticalPosition = renderOptions.textPositionVertical;
329
- if (verticalPosition === StaveLine.TextVerticalPosition.TOP) {
330
- y = firstNote.checkStave().getYForTopText();
331
- } else if (verticalPosition === StaveLine.TextVerticalPosition.BOTTOM) {
332
- y = firstNote.checkStave().getYForBottomText(Tables.TEXT_HEIGHT_OFFSET_HACK);
333
- }
334
-
335
- // Draw the text
336
- const color = renderOptions.color;
337
- this.applyStyle(ctx, { fillStyle: color, strokeStyle: color });
338
- this.renderText(ctx, x, y);
339
- this.restoreStyle(ctx);
340
-
341
- return this;
342
- }
343
- }
@@ -1,93 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- // A base class for stave modifiers (e.g. clefs, key signatures)
5
-
6
- import { Element } from './element';
7
- import { Stave } from './stave';
8
- import { Category } from './typeguard';
9
- import { defined } from './util';
10
-
11
- export interface LayoutMetrics {
12
- xMin: number;
13
- xMax: number;
14
- paddingLeft: number;
15
- paddingRight: number;
16
- }
17
-
18
- export enum StaveModifierPosition {
19
- CENTER = 0,
20
- LEFT = 1,
21
- RIGHT = 2,
22
- ABOVE = 3,
23
- BELOW = 4,
24
- BEGIN = 5,
25
- END = 6,
26
- }
27
-
28
- export class StaveModifier extends Element {
29
- static get CATEGORY(): string {
30
- return Category.StaveModifier;
31
- }
32
-
33
- static get Position(): typeof StaveModifierPosition {
34
- return StaveModifierPosition;
35
- }
36
-
37
- protected padding: number;
38
- protected position: StaveModifierPosition;
39
- protected stave?: Stave;
40
- protected layoutMetrics?: LayoutMetrics;
41
-
42
- constructor() {
43
- super();
44
-
45
- this.padding = 10;
46
- this.position = StaveModifierPosition.ABOVE;
47
- }
48
-
49
- getPosition(): number {
50
- return this.position;
51
- }
52
-
53
- setPosition(position: number): this {
54
- this.position = position;
55
- return this;
56
- }
57
-
58
- getStave(): Stave | undefined {
59
- return this.stave;
60
- }
61
-
62
- checkStave(): Stave {
63
- return defined(this.stave, 'NoStave', 'No stave attached to instance.');
64
- }
65
-
66
- setStave(stave: Stave): this {
67
- this.stave = stave;
68
- return this;
69
- }
70
-
71
- getPadding(index: number): number {
72
- return index !== undefined && index < 2 ? 0 : this.padding;
73
- }
74
-
75
- setPadding(padding: number): this {
76
- this.padding = padding;
77
- return this;
78
- }
79
-
80
- setLayoutMetrics(layoutMetrics: LayoutMetrics): this {
81
- this.layoutMetrics = layoutMetrics;
82
- return this;
83
- }
84
-
85
- getLayoutMetrics(): LayoutMetrics | undefined {
86
- return this.layoutMetrics;
87
- }
88
-
89
- // eslint-disable-next-line
90
- draw(...args: any[]): void {
91
- // DO NOTHING.
92
- }
93
- }