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/easyscore.ts DELETED
@@ -1,538 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Accidental } from './accidental';
5
- import { Articulation } from './articulation';
6
- import { PartialBeamDirection } from './beam';
7
- import { Dot } from './dot';
8
- import { Factory } from './factory';
9
- import { FretHandFinger } from './frethandfinger';
10
- import { Music } from './music';
11
- import { Note } from './note';
12
- import { Grammar, Match, Parser, Result, Rule, RuleFunction } from './parser';
13
- import { RenderContext } from './rendercontext';
14
- import { Stem } from './stem';
15
- import { StemmableNote } from './stemmablenote';
16
- import { TupletOptions } from './tuplet';
17
- import { defined, log, RuntimeError } from './util';
18
- import { Voice } from './voice';
19
-
20
- // To enable logging for this class. Set `VexFlow.EasyScore.DEBUG` to `true`.
21
- // eslint-disable-next-line
22
- function L(...args: any[]): void {
23
- if (EasyScore.DEBUG) log('VexFlow.EasyScore', args);
24
- }
25
-
26
- // eslint-disable-next-line
27
- export type CommitHook = (obj: any, note: StemmableNote, builder: Builder) => void;
28
-
29
- export class EasyScoreGrammar implements Grammar {
30
- builder: Builder;
31
-
32
- constructor(builder: Builder) {
33
- this.builder = builder;
34
- }
35
-
36
- begin(): RuleFunction {
37
- return this.LINE;
38
- }
39
-
40
- LINE(): Rule {
41
- return {
42
- expect: [this.PIECE, this.PIECES, this.EOL],
43
- };
44
- }
45
- PIECE(): Rule {
46
- return {
47
- expect: [this.CHORDORNOTE, this.PARAMS],
48
- run: () => this.builder.commitPiece(),
49
- };
50
- }
51
- PIECES(): Rule {
52
- return {
53
- expect: [this.COMMA, this.PIECE],
54
- zeroOrMore: true,
55
- };
56
- }
57
- PARAMS(): Rule {
58
- return {
59
- expect: [this.DURATION, this.TYPE, this.DOTS, this.OPTS],
60
- };
61
- }
62
- CHORDORNOTE(): Rule {
63
- return {
64
- expect: [this.CHORD, this.SINGLENOTE],
65
- or: true,
66
- };
67
- }
68
- CHORD(): Rule {
69
- return {
70
- expect: [this.LPAREN, this.NOTES, this.RPAREN],
71
- // eslint-disable-next-line
72
- run: (state) => this.builder.addChord(state!.matches[1] as Match[]),
73
- };
74
- }
75
- NOTES(): Rule {
76
- return {
77
- expect: [this.NOTE],
78
- oneOrMore: true,
79
- };
80
- }
81
- NOTE(): Rule {
82
- return {
83
- expect: [this.NOTENAME, this.ACCIDENTAL, this.OCTAVE],
84
- };
85
- }
86
- SINGLENOTE(): Rule {
87
- return {
88
- expect: [this.NOTENAME, this.ACCIDENTAL, this.OCTAVE],
89
- run: (state) => {
90
- // eslint-disable-next-line
91
- const s = state!;
92
- this.builder.addSingleNote(s.matches[0] as string, s.matches[1] as string, s.matches[2] as string);
93
- },
94
- };
95
- }
96
- ACCIDENTAL(): Rule {
97
- return {
98
- expect: [this.MICROTONES, this.ACCIDENTALS],
99
- maybe: true,
100
- or: true,
101
- };
102
- }
103
- DOTS(): Rule {
104
- return {
105
- expect: [this.DOT],
106
- zeroOrMore: true,
107
- // eslint-disable-next-line
108
- run: (state) => this.builder.setNoteDots(state!.matches),
109
- };
110
- }
111
- TYPE(): Rule {
112
- return {
113
- expect: [this.SLASH, this.MAYBESLASH, this.TYPES],
114
- maybe: true,
115
- // eslint-disable-next-line
116
- run: (state) => this.builder.setNoteType(state!.matches[2] as string),
117
- };
118
- }
119
- DURATION(): Rule {
120
- return {
121
- expect: [this.SLASH, this.DURATIONS],
122
- maybe: true,
123
- // eslint-disable-next-line
124
- run: (state) => this.builder.setNoteDuration(state!.matches[1] as string),
125
- };
126
- }
127
- OPTS(): Rule {
128
- return {
129
- expect: [this.LBRACKET, this.KEYVAL, this.KEYVALS, this.RBRACKET],
130
- maybe: true,
131
- };
132
- }
133
- KEYVALS(): Rule {
134
- return {
135
- expect: [this.COMMA, this.KEYVAL],
136
- zeroOrMore: true,
137
- };
138
- }
139
- KEYVAL(): Rule {
140
- const unquote = (str: string) => str.slice(1, -1);
141
-
142
- return {
143
- expect: [this.KEY, this.EQUALS, this.VAL],
144
- // eslint-disable-next-line
145
- run: (state) => this.builder.addNoteOption(state!.matches[0] as string, unquote(state!.matches[2] as string)),
146
- };
147
- }
148
- VAL(): Rule {
149
- return {
150
- expect: [this.SVAL, this.DVAL],
151
- or: true,
152
- };
153
- }
154
-
155
- KEY(): Rule {
156
- return { token: '[a-zA-Z][a-zA-Z0-9]*' };
157
- }
158
- DVAL(): Rule {
159
- return { token: '["][^"]*["]' };
160
- }
161
- SVAL(): Rule {
162
- return { token: "['][^']*[']" };
163
- }
164
- NOTENAME(): Rule {
165
- return { token: '[a-gA-G]' };
166
- }
167
- OCTAVE(): Rule {
168
- return { token: '[0-9]+' };
169
- }
170
- ACCIDENTALS(): Rule {
171
- return { token: 'bb|b|##|#|n' };
172
- }
173
- MICROTONES(): Rule {
174
- return { token: 'bbs|bss|bs|db|d|\\+\\+-|\\+-|\\+\\+|\\+|k|o' };
175
- }
176
- DURATIONS(): Rule {
177
- return { token: '[0-9whq]+' };
178
- }
179
- TYPES(): Rule {
180
- return { token: '[rRsSmMhHgG]' };
181
- }
182
- LPAREN(): Rule {
183
- return { token: '[(]' };
184
- }
185
- RPAREN(): Rule {
186
- return { token: '[)]' };
187
- }
188
- COMMA(): Rule {
189
- return { token: '[,]' };
190
- }
191
- DOT(): Rule {
192
- return { token: '[.]' };
193
- }
194
- SLASH(): Rule {
195
- return { token: '[/]' };
196
- }
197
- MAYBESLASH(): Rule {
198
- return { token: '[/]?' };
199
- }
200
- EQUALS(): Rule {
201
- return { token: '[=]' };
202
- }
203
- LBRACKET(): Rule {
204
- return { token: '\\[' };
205
- }
206
- RBRACKET(): Rule {
207
- return { token: '\\]' };
208
- }
209
- EOL(): Rule {
210
- return { token: '$' };
211
- }
212
- }
213
-
214
- export interface NotePiece {
215
- key: string;
216
- accid?: string | null;
217
- octave?: string;
218
- }
219
-
220
- export class Piece {
221
- chord: NotePiece[] = [];
222
- duration: string;
223
- dots: number = 0;
224
- type?: string;
225
- options: { [x: string]: string } = {};
226
- constructor(duration: string) {
227
- this.duration = duration;
228
- }
229
- }
230
-
231
- export interface BuilderElements {
232
- notes: StemmableNote[];
233
- accidentals: (Accidental | undefined)[][];
234
- }
235
-
236
- // Extending Record<string, any> allows arbitrary properties via Builder.reset() & EasyScore.parse().
237
- // eslint-disable-next-line
238
- export interface BuilderOptions extends Record<string, any> {
239
- stem?: string;
240
- clef?: string;
241
- }
242
-
243
- export class Builder {
244
- factory: Factory;
245
- // Initialized by the constructor via this.reset().
246
- elements!: BuilderElements;
247
- // Initialized by the constructor via this.reset().
248
- options!: BuilderOptions;
249
- // Initialized by the constructor via this.resetPiece().
250
- piece!: Piece;
251
- commitHooks: CommitHook[] = [];
252
- rollingDuration!: string;
253
-
254
- constructor(factory: Factory) {
255
- this.factory = factory;
256
- this.reset();
257
- }
258
-
259
- reset(options?: BuilderOptions): void {
260
- this.options = {
261
- stem: 'auto',
262
- clef: 'treble',
263
- ...options,
264
- };
265
- this.elements = { notes: [], accidentals: [] };
266
- this.rollingDuration = '8';
267
- this.resetPiece();
268
- }
269
-
270
- getFactory(): Factory {
271
- return this.factory;
272
- }
273
-
274
- getElements(): BuilderElements {
275
- return this.elements;
276
- }
277
-
278
- addCommitHook(commitHook: CommitHook): void {
279
- this.commitHooks.push(commitHook);
280
- }
281
-
282
- resetPiece(): void {
283
- L('resetPiece');
284
- this.piece = new Piece(this.rollingDuration);
285
- }
286
-
287
- setNoteDots(dots: Match[]): void {
288
- L('setNoteDots:', dots);
289
- if (dots) this.piece.dots = dots.length;
290
- }
291
-
292
- setNoteDuration(duration?: string): void {
293
- L('setNoteDuration:', duration);
294
- this.rollingDuration = this.piece.duration = duration || this.rollingDuration;
295
- }
296
-
297
- setNoteType(type?: string): void {
298
- L('setNoteType:', type);
299
- if (type) this.piece.type = type;
300
- }
301
-
302
- addNoteOption(key: string, value: string): void {
303
- L('addNoteOption: key:', key, 'value:', value);
304
- this.piece.options[key] = value;
305
- }
306
-
307
- addNote(key?: string, accid?: string | null, octave?: string): void {
308
- L('addNote:', key, accid, octave);
309
- this.piece.chord.push({
310
- key: key as string,
311
- accid,
312
- octave,
313
- });
314
- }
315
-
316
- addSingleNote(key: string, accid?: string | null, octave?: string): void {
317
- L('addSingleNote:', key, accid, octave);
318
- this.addNote(key, accid, octave);
319
- }
320
-
321
- // notes is an array with 3 entries
322
- addChord(notes: Match[]): void {
323
- L('startChord');
324
- if (typeof notes[0] !== 'object') {
325
- this.addSingleNote(notes[0]);
326
- } else {
327
- notes.forEach((n) => {
328
- if (n) this.addNote(...(n as string[])); // n => [string, string | null, string]
329
- });
330
- }
331
- L('endChord');
332
- }
333
-
334
- commitPiece(): void {
335
- L('commitPiece');
336
- const { factory } = this;
337
-
338
- if (!factory) return;
339
-
340
- const options = { ...this.options, ...this.piece.options };
341
-
342
- // reset() sets this.options.stem & this.options.clef but we check to make sure nothing has changed.
343
- // e.g., auto | up | down
344
- const stem = defined(options.stem, 'BadArguments', 'options.stem is not defined').toLowerCase();
345
- // e.g., treble | bass
346
- const clef = defined(options.clef, 'BadArguments', 'options.clef is not defined').toLowerCase();
347
-
348
- const { chord, duration, dots, type } = this.piece;
349
-
350
- // Create a string[] that will be assigned to the .keys property of the StaveNote.
351
- // Each string in the array represents a note pitch and is of the form: {NoteName}{Accidental}/{Octave}
352
- // Only standard accidentals are included in the .keys property. Microtonal accidentals are not included.
353
- const standardAccidentals = Music.accidentals;
354
- const keys = chord.map(
355
- (notePiece) =>
356
- notePiece.key +
357
- (standardAccidentals.includes(notePiece.accid ?? '') ? notePiece.accid : '') +
358
- '/' +
359
- notePiece.octave
360
- );
361
- const autoStem = stem === 'auto'; // StaveNoteStruct expects the underscore & lowercase.
362
-
363
- // Build a GhostNote or StaveNote using the information we gathered.
364
- const note =
365
- type?.toLowerCase() === 'g'
366
- ? factory.GhostNote({ duration, dots })
367
- : factory.StaveNote({ keys, duration, dots, type, clef, autoStem });
368
- if (!autoStem) note.setStemDirection(stem === 'up' ? Stem.UP : Stem.DOWN);
369
-
370
- // Attach accidentals.
371
- const accidentals: (Accidental | undefined)[] = [];
372
- chord.forEach((notePiece: NotePiece, index: number) => {
373
- const accid = notePiece.accid;
374
- if (typeof accid === 'string') {
375
- const accidental = factory.Accidental({ type: accid });
376
- note.addModifier(accidental, index);
377
- accidentals.push(accidental);
378
- } else {
379
- accidentals.push(undefined);
380
- }
381
- });
382
-
383
- // Attach dots.
384
- for (let i = 0; i < dots; i++) Dot.buildAndAttach([note], { all: true });
385
-
386
- this.commitHooks.forEach((commitHook) => commitHook(options, note, this));
387
-
388
- this.elements.notes.push(note);
389
- this.elements.accidentals.push(accidentals);
390
- this.resetPiece();
391
- }
392
- }
393
-
394
- export interface EasyScoreOptions {
395
- factory?: Factory;
396
- builder?: Builder;
397
- commitHooks?: CommitHook[];
398
- throwOnError?: boolean;
399
- }
400
-
401
- // Extending Record<string, any> allows arbitrary properties via set(defaults).
402
- // eslint-disable-next-line
403
- export interface EasyScoreDefaults extends Record<string, any> {
404
- clef?: string;
405
- time?: string;
406
- stem?: string;
407
- }
408
-
409
- /**
410
- * Commit hook used by EasyScore.setOptions().
411
- */
412
- function setId(options: { id?: string }, note: StemmableNote) {
413
- if (options.id === undefined) return;
414
- note.setAttribute('id', options.id);
415
- }
416
-
417
- // Used by setClass() below.
418
- const commaSeparatedRegex = /\s*,\s*/;
419
-
420
- /**
421
- * Commit hook used by EasyScore.setOptions().
422
- */
423
- function setClass(options: { class?: string }, note: StemmableNote) {
424
- if (options.class === undefined) return;
425
- options.class.split(commaSeparatedRegex).forEach((className: string) => note.addClass(className));
426
- }
427
-
428
- /**
429
- * EasyScore implements a parser for a simple language to generate VexFlow objects.
430
- */
431
- export class EasyScore {
432
- static DEBUG: boolean = false;
433
-
434
- defaults: EasyScoreDefaults = {
435
- clef: 'treble',
436
- time: '4/4',
437
- stem: 'auto',
438
- };
439
-
440
- // options, factory, builder, grammar, and parser are all
441
- // initialized by the constructor via this.setOptions().
442
- options!: EasyScoreOptions;
443
- factory!: Factory;
444
- builder!: Builder;
445
- grammar!: EasyScoreGrammar;
446
- parser!: Parser;
447
-
448
- constructor(options: EasyScoreOptions = {}) {
449
- this.setOptions(options);
450
- }
451
-
452
- /**
453
- * Set the score defaults.
454
- * clef must be set appropriately to avoid errors when adding Staves.
455
- * @param defaults.clef default clef ( treble | bass ...) see {@link Clef.types}
456
- * @param defaults.time default time signature ( 4/4 | 9/8 ...)
457
- * @param defaults.stem default stem arrangement (auto | up | down)
458
- * @returns this
459
- */
460
- set(defaults: EasyScoreDefaults): this {
461
- this.defaults = { ...this.defaults, ...defaults };
462
- return this;
463
- }
464
-
465
- /**
466
- * @param options.factory is required.
467
- * @returns this
468
- */
469
- setOptions(options: EasyScoreOptions): this {
470
- // eslint-disable-next-line
471
- const factory = options.factory!; // ! operator, because options.factory was set in Factory.EasyScore().
472
- const builder = options.builder ?? new Builder(factory);
473
-
474
- this.options = {
475
- commitHooks: [setId, setClass, Articulation.easyScoreHook, FretHandFinger.easyScoreHook],
476
- throwOnError: false,
477
- ...options,
478
- factory,
479
- builder,
480
- };
481
-
482
- this.factory = factory;
483
- this.builder = builder;
484
- this.grammar = new EasyScoreGrammar(this.builder);
485
- this.parser = new Parser(this.grammar);
486
- this.options.commitHooks?.forEach((commitHook) => this.addCommitHook(commitHook));
487
- return this;
488
- }
489
-
490
- setContext(context: RenderContext): this {
491
- this.factory.setContext(context);
492
- return this;
493
- }
494
-
495
- parse(line: string, options: BuilderOptions = {}): Result {
496
- this.builder.reset(options);
497
- const result = this.parser.parse(line);
498
- if (!result.success && this.options.throwOnError) {
499
- L(result);
500
- throw new RuntimeError('Error parsing line: ' + line);
501
- }
502
- return result;
503
- }
504
-
505
- beam(
506
- notes: StemmableNote[],
507
- options?: {
508
- autoStem?: boolean;
509
- secondaryBeamBreaks?: number[];
510
- partialBeamDirections?: {
511
- [noteIndex: number]: PartialBeamDirection;
512
- };
513
- }
514
- ): StemmableNote[] {
515
- this.factory.Beam({ notes, options });
516
- return notes;
517
- }
518
-
519
- tuplet(notes: StemmableNote[], options?: TupletOptions): StemmableNote[] {
520
- this.factory.Tuplet({ notes, options });
521
- return notes;
522
- }
523
-
524
- notes(line: string, options: BuilderOptions = {}): StemmableNote[] {
525
- options = { clef: this.defaults.clef, stem: this.defaults.stem, ...options };
526
- this.parse(line, options);
527
- return this.builder.getElements().notes;
528
- }
529
-
530
- voice(notes: Note[], options: { time?: string; options?: { softmaxFactor: number } } = {}): Voice {
531
- options = { time: this.defaults.time, ...options };
532
- return this.factory.Voice(options).addTickables(notes);
533
- }
534
-
535
- addCommitHook(commitHook: CommitHook): void {
536
- this.builder.addCommitHook(commitHook);
537
- }
538
- }