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/tuplet.ts DELETED
@@ -1,349 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
-
3
- /**
4
- * ## Description
5
- *
6
- * Create a new tuplet from the specified notes. The notes must
7
- * be part of the same voice. If they are of different rhythmic
8
- * values, then options.numNotes must be set.
9
- *
10
- * @constructor
11
- * @param {Array.<VexFlow.StaveNote>} A set of notes: staveNotes,
12
- * notes, etc... any class that inherits stemmableNote at some
13
- * point in its prototype chain.
14
- * @param options: object {
15
- *
16
- * numNotes: fit this many notes into...
17
- * notesOccupied: ...the space of this many notes
18
- *
19
- * Together, these two properties make up the tuplet ratio
20
- * in the form of numNotes : notesOccupied.
21
- * numNotes defaults to the number of notes passed in, so
22
- * it is important that if you omit this property, all of
23
- * the notes passed should be of the same note value.
24
- * notesOccupied defaults to 2 -- so you should almost
25
- * certainly pass this parameter for anything other than
26
- * a basic triplet.
27
- *
28
- * location:
29
- * default 1, which is above the notes: ┌─── 3 ───┐
30
- * -1 is below the notes └─── 3 ───┘
31
- *
32
- * bracketed: boolean, draw a bracket around the tuplet number
33
- * when true: ┌─── 3 ───┐ when false: 3
34
- * defaults to true if notes are not beamed, false otherwise
35
- *
36
- * ratioed: boolean
37
- * when true: ┌─── 7:8 ───┐, when false: ┌─── 7 ───┐
38
- * defaults to true if the difference between numNotes and
39
- * notesOccupied is greater than 1.
40
- *
41
- * yOffset: int, default 0
42
- * manually offset a tuplet, for instance to avoid collisions
43
- * with articulations, etc...
44
- * }
45
- */
46
-
47
- import { Element } from './element';
48
- import { Formatter } from './formatter';
49
- import { Glyphs } from './glyphs';
50
- import { Note } from './note';
51
- import { Stem } from './stem';
52
- import { StemmableNote } from './stemmablenote';
53
- import { Tables } from './tables';
54
- import { Category } from './typeguard';
55
- import { RuntimeError } from './util';
56
-
57
- export interface TupletOptions {
58
- bracketed?: boolean;
59
- location?: number;
60
- notesOccupied?: number;
61
- numNotes?: number;
62
- ratioed?: boolean;
63
- yOffset?: number;
64
- }
65
-
66
- export interface TupletMetrics {
67
- noteHeadOffset: number;
68
- stemOffset: number;
69
- bottomLine: number;
70
- topModifierOffset: number;
71
- }
72
-
73
- export const enum TupletLocation {
74
- BOTTOM = -1,
75
- TOP = +1,
76
- }
77
-
78
- export class Tuplet extends Element {
79
- static get CATEGORY(): string {
80
- return Category.Tuplet;
81
- }
82
-
83
- notes: Note[];
84
-
85
- protected options: TupletOptions;
86
- protected numNotes: number;
87
-
88
- protected bracketed: boolean;
89
- protected textElement: Element;
90
- // location is initialized by the constructor via setTupletLocation(...).
91
- protected location!: number;
92
-
93
- protected notesOccupied: number;
94
- protected ratioed: boolean;
95
-
96
- static get LOCATION_TOP(): number {
97
- return TupletLocation.TOP;
98
- }
99
- static get LOCATION_BOTTOM(): number {
100
- return TupletLocation.BOTTOM;
101
- }
102
- static get NESTING_OFFSET(): number {
103
- return 15;
104
- }
105
-
106
- constructor(notes: Note[], options: TupletOptions = {}) {
107
- super();
108
-
109
- if (!notes || !notes.length) {
110
- throw new RuntimeError('BadArguments', 'No notes provided for tuplet.');
111
- }
112
-
113
- this.options = options;
114
- this.notes = notes;
115
- this.numNotes = this.options.numNotes !== undefined ? this.options.numNotes : notes.length;
116
-
117
- this.notesOccupied = this.options.notesOccupied || 2;
118
- if (this.options.bracketed !== undefined) {
119
- this.bracketed = this.options.bracketed;
120
- } else {
121
- this.bracketed = notes.some((note) => !note.hasBeam());
122
- }
123
-
124
- this.ratioed =
125
- this.options.ratioed !== undefined ? this.options.ratioed : Math.abs(this.notesOccupied - this.numNotes) > 1;
126
- this.textElement = new Element('Tuplet');
127
-
128
- this.setTupletLocation(this.options.location || Tuplet.LOCATION_TOP);
129
-
130
- Formatter.AlignRestsToNotes(notes, true, true);
131
- this.resolveGlyphs();
132
- this.attach();
133
- }
134
-
135
- attach(): void {
136
- for (let i = 0; i < this.notes.length; i++) {
137
- const note = this.notes[i];
138
- note.setTuplet(this);
139
- }
140
- }
141
-
142
- detach(): void {
143
- for (let i = 0; i < this.notes.length; i++) {
144
- const note = this.notes[i];
145
- note.resetTuplet(this);
146
- }
147
- }
148
-
149
- /**
150
- * Set whether or not the bracket is drawn.
151
- */
152
- setBracketed(bracketed: boolean): this {
153
- this.bracketed = !!bracketed;
154
- return this;
155
- }
156
-
157
- /**
158
- * Set whether or not the ratio is shown.
159
- */
160
- setRatioed(ratioed: boolean): this {
161
- this.ratioed = !!ratioed;
162
- return this;
163
- }
164
-
165
- /**
166
- * Set the tuplet indicator to be displayed either on the top or bottom of the stave.
167
- */
168
- setTupletLocation(location: number): this {
169
- if (location !== Tuplet.LOCATION_TOP && location !== Tuplet.LOCATION_BOTTOM) {
170
- // eslint-disable-next-line
171
- console.warn(`Invalid tuplet location [${location}]. Using Tuplet.LOCATION_TOP.`);
172
- location = Tuplet.LOCATION_TOP;
173
- }
174
-
175
- this.location = location;
176
- return this;
177
- }
178
-
179
- getNotes(): Note[] {
180
- return this.notes;
181
- }
182
-
183
- getNoteCount(): number {
184
- return this.numNotes;
185
- }
186
-
187
- getNotesOccupied(): number {
188
- return this.notesOccupied;
189
- }
190
-
191
- setNotesOccupied(notes: number): void {
192
- this.detach();
193
- this.notesOccupied = notes;
194
- this.resolveGlyphs();
195
- this.attach();
196
- }
197
-
198
- resolveGlyphs(): void {
199
- let numerator = '';
200
- let denominator = '';
201
- let n = this.numNotes;
202
- while (n >= 1) {
203
- numerator = String.fromCharCode(0xe880 /* tuplet0 */ + (n % 10)) + numerator;
204
- n = Math.floor(n / 10);
205
- }
206
- if (this.ratioed) {
207
- n = this.notesOccupied;
208
- while (n >= 1) {
209
- denominator = String.fromCharCode(0xe880 /* tuplet0 */ + (n % 10)) + denominator;
210
- n = Math.floor(n / 10);
211
- }
212
- denominator = Glyphs.tupletColon + denominator;
213
- }
214
- this.textElement.setText(numerator + denominator);
215
- }
216
-
217
- // determine how many tuplets are nested within this tuplet
218
- // on the same side (above/below), to calculate a y
219
- // offset for this tuplet:
220
- getNestedTupletCount(): number {
221
- const location = this.location;
222
- const firstNote = this.notes[0];
223
- let maxTupletCount = countTuplets(firstNote, location);
224
- let minTupletCount = countTuplets(firstNote, location);
225
-
226
- // Count the tuplets that are on the same side (above/below)
227
- // as this tuplet:
228
- function countTuplets(note: Note, location: number) {
229
- return note.getTupletStack().filter((tuplet) => tuplet.location === location).length;
230
- }
231
-
232
- this.notes.forEach((note) => {
233
- const tupletCount = countTuplets(note, location);
234
- maxTupletCount = tupletCount > maxTupletCount ? tupletCount : maxTupletCount;
235
- minTupletCount = tupletCount < minTupletCount ? tupletCount : minTupletCount;
236
- });
237
-
238
- return maxTupletCount - minTupletCount;
239
- }
240
-
241
- // determine the y position of the tuplet:
242
- getYPosition(): number {
243
- // offset the tuplet for any nested tuplets between
244
- // it and the notes:
245
- const nestedTupletYOffset = this.getNestedTupletCount() * Tuplet.NESTING_OFFSET * -this.location;
246
-
247
- // offset the tuplet for any manual yOffset:
248
- const yOffset = this.options.yOffset ?? 0;
249
-
250
- // now iterate through the notes and find our highest
251
- // or lowest locations, to form a base yPosition
252
- const firstNote = this.notes[0];
253
- let yPosition;
254
- if (this.location === Tuplet.LOCATION_TOP) {
255
- yPosition = firstNote.checkStave().getYForLine(0) - 1.5 * Tables.STAVE_LINE_DISTANCE;
256
-
257
- // check modifiers above note to see if they will collide with tuplet beam
258
- for (let i = 0; i < this.notes.length; ++i) {
259
- const note = this.notes[i];
260
- let modLines = 0;
261
- const mc = note.getModifierContext();
262
- if (mc) {
263
- modLines = Math.max(modLines, mc.getState().topTextLine);
264
- }
265
- const modY = note.getYForTopText(modLines) - 2 * Tables.STAVE_LINE_DISTANCE;
266
- if (note.hasStem() || note.isRest()) {
267
- const topY =
268
- note.getStemDirection() === Stem.UP
269
- ? note.getStemExtents().topY - Tables.STAVE_LINE_DISTANCE
270
- : note.getStemExtents().baseY - 2 * Tables.STAVE_LINE_DISTANCE;
271
- yPosition = Math.min(topY, yPosition);
272
- if (modLines > 0) {
273
- yPosition = Math.min(modY, yPosition);
274
- }
275
- }
276
- }
277
- } else {
278
- let lineCheck = 4; // tuplet default on line 4
279
- // check modifiers below note to see if they will collide with tuplet beam
280
- this.notes.forEach((nn) => {
281
- const mc = nn.getModifierContext();
282
- if (mc) {
283
- lineCheck = Math.max(lineCheck, mc.getState().textLine + 1);
284
- }
285
- });
286
- yPosition = firstNote.checkStave().getYForLine(lineCheck) + 2 * Tables.STAVE_LINE_DISTANCE;
287
-
288
- for (let i = 0; i < this.notes.length; ++i) {
289
- if (this.notes[i].hasStem() || this.notes[i].isRest()) {
290
- const bottomY =
291
- this.notes[i].getStemDirection() === Stem.UP
292
- ? this.notes[i].getStemExtents().baseY + 2 * Tables.STAVE_LINE_DISTANCE
293
- : this.notes[i].getStemExtents().topY + Tables.STAVE_LINE_DISTANCE;
294
- if (bottomY > yPosition) {
295
- yPosition = bottomY;
296
- }
297
- }
298
- }
299
- }
300
-
301
- return yPosition + nestedTupletYOffset + yOffset;
302
- }
303
-
304
- draw(): void {
305
- const ctx = this.checkContext();
306
- let xPos = 0;
307
- let yPos = 0;
308
- this.setRendered();
309
-
310
- // determine x value of left bound of tuplet
311
- const firstNote = this.notes[0] as StemmableNote;
312
- const lastNote = this.notes[this.notes.length - 1] as StemmableNote;
313
-
314
- if (!this.bracketed) {
315
- xPos = firstNote.getStemX();
316
- this.width = lastNote.getStemX() - xPos;
317
- } else {
318
- xPos = firstNote.getTieLeftX() - 5;
319
- this.width = lastNote.getTieRightX() - xPos + 5;
320
- }
321
-
322
- // determine y value for tuplet
323
- yPos = this.getYPosition();
324
-
325
- const notationCenterX = xPos + this.width / 2;
326
- const notationStartX = notationCenterX - this.textElement.getWidth() / 2;
327
-
328
- // draw bracket if the tuplet is not beamed
329
- if (this.bracketed) {
330
- const lineWidth = this.width / 2 - this.textElement.getWidth() / 2 - 5;
331
-
332
- // only draw the bracket if it has positive length
333
- if (lineWidth > 0) {
334
- ctx.fillRect(xPos, yPos, lineWidth, 1);
335
- ctx.fillRect(xPos + this.width / 2 + this.textElement.getWidth() / 2 + 5, yPos, lineWidth, 1);
336
- ctx.fillRect(xPos, yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0), 1, this.location * 10);
337
- ctx.fillRect(
338
- xPos + this.width,
339
- yPos + (this.location === Tuplet.LOCATION_BOTTOM ? 1 : 0),
340
- 1,
341
- this.location * 10
342
- );
343
- }
344
- }
345
-
346
- // draw text
347
- this.textElement.renderText(ctx, notationStartX, yPos + this.textElement.getHeight() / 2);
348
- }
349
- }
package/src/typeguard.ts DELETED
@@ -1,136 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Ron B. Yeh
3
- // MIT License
4
-
5
- import { Accidental } from './accidental';
6
- import { Annotation } from './annotation';
7
- import { Dot } from './dot';
8
- import { GraceNote } from './gracenote';
9
- import { GraceNoteGroup } from './gracenotegroup';
10
- import { Note } from './note';
11
- import { RenderContext } from './rendercontext';
12
- import { Barline } from './stavebarline';
13
- import { StaveNote } from './stavenote';
14
- import { StemmableNote } from './stemmablenote';
15
- import { TabNote } from './tabnote';
16
-
17
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
-
19
- /**
20
- * Use instead of `instanceof` as a more flexible type guard.
21
- * @param obj check if this object's CATEGORY matches the provided category.
22
- * @param category a string representing a category of VexFlow objects.
23
- * @param checkAncestors defaults to `true`, so we walk up the prototype chain to look for a matching `CATEGORY`.
24
- * If `false`, we do not check the superclass or other ancestors.
25
- * @returns true if `obj` has a static `CATEGORY` property that matches `category`.
26
- */
27
- export function isCategory<T>(obj: any, category: string, checkAncestors: boolean = true): obj is T {
28
- // obj is undefined, a number, a primitive string, or null.
29
- if (typeof obj !== 'object' || obj === null) {
30
- return false;
31
- }
32
-
33
- // `obj.constructor` is a reference to the constructor function that created the `obj` instance.
34
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor
35
- let constructorFcn = obj.constructor;
36
-
37
- // Check if the object's static .CATEGORY matches the provided category.
38
-
39
- if (checkAncestors) {
40
- // Walk up the prototype chain to look for a matching obj.constructor.CATEGORY.
41
- while (obj !== null) {
42
- constructorFcn = obj.constructor;
43
- if ('CATEGORY' in constructorFcn && constructorFcn.CATEGORY === category) {
44
- return true;
45
- }
46
- obj = Object.getPrototypeOf(obj);
47
- }
48
- return false;
49
- } else {
50
- // Do not walk up the prototype chain. Just check this particular object's static .CATEGORY string.
51
- return 'CATEGORY' in constructorFcn && constructorFcn.CATEGORY === category;
52
- }
53
- }
54
-
55
- export const isAccidental = (obj: unknown): obj is Accidental => isCategory(obj, Category.Accidental);
56
- export const isAnnotation = (obj: unknown): obj is Annotation => isCategory(obj, Category.Annotation);
57
- export const isBarline = (obj: unknown): obj is Barline => isCategory(obj, Category.Barline);
58
- export const isDot = (obj: unknown): obj is Dot => isCategory(obj, Category.Dot);
59
- export const isGraceNote = (obj: unknown): obj is GraceNote => isCategory(obj, Category.GraceNote);
60
- export const isGraceNoteGroup = (obj: unknown): obj is GraceNoteGroup => isCategory(obj, Category.GraceNoteGroup);
61
- export const isNote = (obj: unknown): obj is Note => isCategory(obj, Category.Note);
62
- export const isRenderContext = (obj: unknown): obj is RenderContext => isCategory(obj, Category.RenderContext);
63
- export const isStaveNote = (obj: unknown): obj is StaveNote => isCategory(obj, Category.StaveNote);
64
- export const isStemmableNote = (obj: unknown): obj is StemmableNote => isCategory(obj, Category.StemmableNote);
65
- export const isTabNote = (obj: unknown): obj is TabNote => isCategory(obj, Category.TabNote);
66
-
67
- // 'const' enums are erased by the TypeScript compiler. The string values are inlined at all the use sites.
68
- // See: https://www.typescriptlang.org/docs/handbook/enums.html#const-enums
69
- export const enum Category {
70
- Accidental = 'Accidental',
71
- Annotation = 'Annotation',
72
- Articulation = 'Articulation',
73
- Barline = 'Barline',
74
- BarNote = 'BarNote',
75
- Beam = 'Beam',
76
- Bend = 'Bend',
77
- ChordSymbol = 'ChordSymbol',
78
- Clef = 'Clef',
79
- ClefNote = 'ClefNote',
80
- Crescendo = 'Crescendo',
81
- Curve = 'Curve',
82
- Dot = 'Dot',
83
- Element = 'Element',
84
- Fraction = 'Fraction',
85
- FretHandFinger = 'FretHandFinger',
86
- GhostNote = 'GhostNote',
87
- Glyph = 'Glyph',
88
- GlyphNote = 'GlyphNote',
89
- GraceNote = 'GraceNote',
90
- GraceNoteGroup = 'GraceNoteGroup',
91
- GraceTabNote = 'GraceTabNote',
92
- KeySignature = 'KeySignature',
93
- KeySigNote = 'KeySigNote',
94
- Modifier = 'Modifier',
95
- MultiMeasureRest = 'MultiMeasureRest',
96
- Note = 'Note',
97
- NoteHead = 'NoteHead',
98
- NoteSubGroup = 'NoteSubGroup',
99
- Ornament = 'Ornament',
100
- Parenthesis = 'Parenthesis',
101
- PedalMarking = 'PedalMarking',
102
- RenderContext = 'RenderContext',
103
- RepeatNote = 'RepeatNote',
104
- Repetition = 'Repetition',
105
- Stave = 'Stave',
106
- StaveConnector = 'StaveConnector',
107
- StaveHairpin = 'StaveHairpin',
108
- StaveLine = 'StaveLine',
109
- StaveModifier = 'StaveModifier',
110
- StaveNote = 'StaveNote',
111
- StaveSection = 'StaveSection',
112
- StaveTempo = 'StaveTempo',
113
- StaveText = 'StaveText',
114
- StaveTie = 'StaveTie',
115
- Stem = 'Stem',
116
- StemmableNote = 'StemmableNote',
117
- StringNumber = 'StringNumber',
118
- Stroke = 'Stroke',
119
- System = 'System',
120
- TabNote = 'TabNote',
121
- TabSlide = 'TabSlide',
122
- TabStave = 'TabStave',
123
- TabTie = 'TabTie',
124
- TextBracket = 'TextBracket',
125
- TextDynamics = 'TextDynamics',
126
- TextNote = 'TextNote',
127
- Tickable = 'Tickable',
128
- TimeSignature = 'TimeSignature',
129
- TimeSigNote = 'TimeSigNote',
130
- Tremolo = 'Tremolo',
131
- Tuplet = 'Tuplet',
132
- Vibrato = 'Vibrato',
133
- VibratoBracket = 'VibratoBracket',
134
- Voice = 'Voice',
135
- Volta = 'Volta',
136
- }
package/src/util.ts DELETED
@@ -1,169 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- // Note: Keep this module free of imports to reduce the chance of circular dependencies.
5
-
6
- /** `RuntimeError` will be thrown by VexFlow classes in case of error. */
7
- export class RuntimeError extends Error {
8
- code: string;
9
- constructor(code: string, message: string = '') {
10
- super('[RuntimeError] ' + code + ': ' + message);
11
- this.code = code;
12
- }
13
- }
14
-
15
- /** VexFlow can be used outside of the browser (e.g., Node) where `window` may not be defined. */
16
- // eslint-disable-next-line
17
- export function globalObject(): typeof globalThis & any {
18
- if (typeof globalThis !== 'undefined') {
19
- return globalThis;
20
- }
21
- if (typeof self !== 'undefined') {
22
- return self;
23
- }
24
- if (typeof window !== 'undefined') {
25
- return window;
26
- }
27
- if (typeof global !== 'undefined') {
28
- return global;
29
- }
30
- return Function('return this')();
31
- }
32
-
33
- /**
34
- * Check that `x` is of type `T` and not `undefined`.
35
- * If `x` is `undefined`, throw a RuntimeError with the optionally provided error code and message.
36
- */
37
- export function defined<T>(x?: T, code: string = 'undefined', message: string = ''): T {
38
- if (x === undefined) {
39
- throw new RuntimeError(code, message);
40
- }
41
- return x;
42
- }
43
-
44
- /** Default log function sends all arguments to console. */
45
- // eslint-disable-next-line
46
- export function log(block: string, ...args: any[]): void {
47
- if (!args) return;
48
- const line = Array.prototype.slice.call(args).join(' ');
49
- globalObject().console.log(block + ': ' + line);
50
- }
51
-
52
- /** Dump warning to console. */
53
- // eslint-disable-next-line
54
- export function warn(...args: any[]): void {
55
- const line = args.join(' ');
56
- const err = new Error();
57
- globalObject().console.log('Warning: ', line, err.stack);
58
- }
59
-
60
- /** Round number to nearest fractional value (`.5`, `.25`, etc.) */
61
- function roundN(x: number, n: number): number {
62
- return x % n >= n / 2 ? parseInt(`${x / n}`, 10) * n + n : parseInt(`${x / n}`, 10) * n;
63
- }
64
-
65
- /** Locate the mid point between stave lines. Returns a fractional line if a space. */
66
- export function midLine(a: number, b: number): number {
67
- let midLine = b + (a - b) / 2;
68
- if (midLine % 2 > 0) {
69
- midLine = roundN(midLine * 10, 5) / 10;
70
- }
71
- return midLine;
72
- }
73
-
74
- /**
75
- * Used by various classes (e.g., SVGContext) to provide a
76
- * unique prefix to element names (or other keys in shared namespaces).
77
- */
78
- export function prefix(text: string): string {
79
- return `vf-${text}`;
80
- }
81
-
82
- /**
83
- * @param s
84
- * @returns `s` with the first letter capitalized.
85
- */
86
- export function upperFirst(s: string = ''): string {
87
- return s.charAt(0).toUpperCase() + s.slice(1);
88
- }
89
-
90
- /**
91
- * Convert an arbitrary angle in radians to the equivalent one in the range [0, pi).
92
- */
93
- export function normalizeAngle(a: number): number {
94
- a = a % (2 * Math.PI);
95
- if (a < 0) {
96
- a += 2 * Math.PI;
97
- }
98
- return a;
99
- }
100
-
101
- /**
102
- * Return the sum of an array of numbers.
103
- */
104
- export function sumArray(arr: number[]): number {
105
- return arr.reduce((a, b) => a + b, 0);
106
- }
107
-
108
- //////////////////////////////////////////////////////////////////////////////////////////////////
109
- // Moved from vex.ts to util.ts.
110
-
111
- /**
112
- * Take `arr` and return a new array consisting of the sorted, unique'd,
113
- * contents of arr. Does not modify `arr`.
114
- */
115
- // eslint-disable-next-line
116
- /*
117
- static sortAndUnique(arr: any[], cmp: any, eq: any): any[] {
118
- if (arr.length > 1) {
119
- const newArr = [];
120
- let last;
121
- arr.sort(cmp);
122
-
123
- for (let i = 0; i < arr.length; ++i) {
124
- if (i === 0 || !eq(arr[i], last)) {
125
- newArr.push(arr[i]);
126
- }
127
- last = arr[i];
128
- }
129
-
130
- return newArr;
131
- } else {
132
- return [].concat(arr); //
133
- }
134
- }
135
- */
136
-
137
- // Get the 2D Canvas context from DOM element with id `canvasId`.
138
- /*
139
- static getCanvasContext(canvasId: string): RenderingContext {
140
- if (!canvasId) {
141
- throw new RuntimeError('BadArgument', 'Invalid canvas selector: ' + canvasId);
142
- }
143
-
144
- const canvas = document.getElementById(canvasId) as HTMLCanvasElement;
145
- if (!(canvas && canvas.getContext)) {
146
- throw new RuntimeError('UnsupportedBrowserError', 'This browser does not support HTML5 Canvas');
147
- }
148
-
149
- return canvas.getContext('2d') as RenderingContext;
150
- }
151
- */
152
-
153
- /** Benchmark. Run function `f` once and report time elapsed shifted by `s` milliseconds. */
154
- /*
155
- static benchmark(s: any, f: any): void {
156
- const startTime = new Date().getTime();
157
- f();
158
- const elapsed = new Date().getTime() - startTime;
159
- log(s, elapsed + 'ms');
160
- }
161
- */
162
-
163
- // Get stack trace.
164
- /*
165
- static stackTrace(): string | undefined {
166
- const err = new Error();
167
- return err.stack;
168
- }
169
- */
package/src/version.ts DELETED
@@ -1,4 +0,0 @@
1
- // Gruntfile.js uses string-replace-loader to replace these values during build time.
2
- export const VERSION: string = '__VF_VERSION__';
3
- export const ID: string = '__VF_GIT_COMMIT_ID__';
4
- export const DATE: string = '__VF_BUILD_DATE__';