vexflow 5.0.0-alpha.2 → 5.0.0-alpha.3

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 (112) 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 +4 -4
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +4 -4
  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/version.js +3 -3
  12. package/package.json +1 -3
  13. package/entry/vexflow-bravura.ts +0 -25
  14. package/entry/vexflow-core.ts +0 -16
  15. package/entry/vexflow-debug-with-tests.ts +0 -64
  16. package/entry/vexflow-debug.ts +0 -54
  17. package/entry/vexflow.ts +0 -47
  18. package/src/accidental.ts +0 -570
  19. package/src/annotation.ts +0 -294
  20. package/src/articulation.ts +0 -383
  21. package/src/barnote.ts +0 -95
  22. package/src/beam.ts +0 -999
  23. package/src/bend.ts +0 -268
  24. package/src/boundingbox.ts +0 -108
  25. package/src/canvascontext.ts +0 -348
  26. package/src/chordsymbol.ts +0 -473
  27. package/src/clef.ts +0 -164
  28. package/src/clefnote.ts +0 -50
  29. package/src/crescendo.ts +0 -132
  30. package/src/curve.ts +0 -195
  31. package/src/dot.ts +0 -171
  32. package/src/easyscore.ts +0 -538
  33. package/src/element.ts +0 -692
  34. package/src/factory.ts +0 -694
  35. package/src/font.ts +0 -343
  36. package/src/fonts/academico.ts +0 -2
  37. package/src/fonts/academicobold.ts +0 -2
  38. package/src/fonts/bravura.ts +0 -2
  39. package/src/fonts/gonville.ts +0 -2
  40. package/src/fonts/petaluma.ts +0 -2
  41. package/src/fonts/petalumascript.ts +0 -2
  42. package/src/formatter.ts +0 -1107
  43. package/src/fraction.ts +0 -245
  44. package/src/frethandfinger.ts +0 -180
  45. package/src/ghostnote.ts +0 -75
  46. package/src/glyphnote.ts +0 -68
  47. package/src/glyphs.ts +0 -5880
  48. package/src/gracenote.ts +0 -146
  49. package/src/gracenotegroup.ts +0 -194
  50. package/src/gracetabnote.ts +0 -30
  51. package/src/index.ts +0 -90
  52. package/src/keymanager.ts +0 -153
  53. package/src/keysignature.ts +0 -272
  54. package/src/keysignote.ts +0 -46
  55. package/src/metrics.ts +0 -222
  56. package/src/modifier.ts +0 -216
  57. package/src/modifiercontext.ts +0 -177
  58. package/src/multimeasurerest.ts +0 -229
  59. package/src/music.ts +0 -443
  60. package/src/note.ts +0 -690
  61. package/src/notehead.ts +0 -158
  62. package/src/notesubgroup.ts +0 -88
  63. package/src/ornament.ts +0 -301
  64. package/src/parenthesis.ts +0 -89
  65. package/src/parser.ts +0 -263
  66. package/src/pedalmarking.ts +0 -273
  67. package/src/registry.ts +0 -146
  68. package/src/rendercontext.ts +0 -98
  69. package/src/renderer.ts +0 -166
  70. package/src/repeatnote.ts +0 -25
  71. package/src/stave.ts +0 -885
  72. package/src/stavebarline.ts +0 -231
  73. package/src/staveconnector.ts +0 -281
  74. package/src/stavehairpin.ts +0 -209
  75. package/src/staveline.ts +0 -343
  76. package/src/stavemodifier.ts +0 -93
  77. package/src/stavenote.ts +0 -1230
  78. package/src/staverepetition.ts +0 -148
  79. package/src/stavesection.ts +0 -54
  80. package/src/stavetempo.ts +0 -162
  81. package/src/stavetext.ts +0 -69
  82. package/src/stavetie.ts +0 -235
  83. package/src/stavevolta.ts +0 -66
  84. package/src/stem.ts +0 -225
  85. package/src/stemmablenote.ts +0 -248
  86. package/src/stringnumber.ts +0 -286
  87. package/src/strokes.ts +0 -214
  88. package/src/svgcontext.ts +0 -639
  89. package/src/system.ts +0 -327
  90. package/src/tables.ts +0 -796
  91. package/src/tabnote.ts +0 -449
  92. package/src/tabslide.ts +0 -115
  93. package/src/tabstave.ts +0 -31
  94. package/src/tabtie.ts +0 -44
  95. package/src/textbracket.ts +0 -231
  96. package/src/textdynamics.ts +0 -101
  97. package/src/textnote.ts +0 -175
  98. package/src/tickable.ts +0 -374
  99. package/src/tickcontext.ts +0 -280
  100. package/src/timesignature.ts +0 -229
  101. package/src/timesignote.ts +0 -45
  102. package/src/tremolo.ts +0 -51
  103. package/src/tuning.ts +0 -90
  104. package/src/tuplet.ts +0 -349
  105. package/src/typeguard.ts +0 -136
  106. package/src/util.ts +0 -169
  107. package/src/version.ts +0 -4
  108. package/src/vexflow.ts +0 -378
  109. package/src/vibrato.ts +0 -99
  110. package/src/vibratobracket.ts +0 -81
  111. package/src/voice.ts +0 -302
  112. 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
- }