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/factory.ts DELETED
@@ -1,694 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
- // @author Mohit Cheppudira
4
- // MIT License
5
-
6
- import { Accidental } from './accidental';
7
- import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation';
8
- import { Articulation } from './articulation';
9
- import { BarNote } from './barnote';
10
- import { Beam, PartialBeamDirection } from './beam';
11
- import { ChordSymbol } from './chordsymbol';
12
- import { ClefNote } from './clefnote';
13
- import { Curve, CurveOptions } from './curve';
14
- import { EasyScore, EasyScoreOptions } from './easyscore';
15
- import { Element } from './element';
16
- import { FontInfo } from './font';
17
- import { Formatter, FormatterOptions } from './formatter';
18
- import { FretHandFinger } from './frethandfinger';
19
- import { GhostNote } from './ghostnote';
20
- import { GlyphNote, GlyphNoteOptions } from './glyphnote';
21
- import { GraceNote, GraceNoteStruct } from './gracenote';
22
- import { GraceNoteGroup } from './gracenotegroup';
23
- import { KeySigNote } from './keysignote';
24
- import { ModifierContext } from './modifiercontext';
25
- import { MultiMeasureRest, MultimeasureRestRenderOptions } from './multimeasurerest';
26
- import { Note, NoteStruct } from './note';
27
- import { NoteSubGroup } from './notesubgroup';
28
- import { Ornament } from './ornament';
29
- import { PedalMarking } from './pedalmarking';
30
- import { RenderContext } from './rendercontext';
31
- import { Renderer } from './renderer';
32
- import { RepeatNote } from './repeatnote';
33
- import { Stave, StaveOptions } from './stave';
34
- import { BarlineType } from './stavebarline';
35
- import { StaveConnector, StaveConnectorType } from './staveconnector';
36
- import { StaveLine } from './staveline';
37
- import { StaveNote, StaveNoteStruct } from './stavenote';
38
- import { StaveTie } from './stavetie';
39
- import { StemmableNote } from './stemmablenote';
40
- import { StringNumber } from './stringnumber';
41
- import { System, SystemOptions } from './system';
42
- import { TabNote, TabNoteStruct } from './tabnote';
43
- import { TabStave } from './tabstave';
44
- import { TextBracket } from './textbracket';
45
- import { TextDynamics } from './textdynamics';
46
- import { TextNote, TextNoteStruct } from './textnote';
47
- import { TickContext } from './tickcontext';
48
- import { TimeSigNote } from './timesignote';
49
- import { Tuplet, TupletOptions } from './tuplet';
50
- import { defined, log, RuntimeError } from './util';
51
- import { VibratoBracket } from './vibratobracket';
52
- import { Voice, VoiceTime } from './voice';
53
- import { isHTMLCanvas } from './web';
54
-
55
- export interface FactoryOptions {
56
- stave?: {
57
- space: number;
58
- };
59
- renderer?: {
60
- elementId: string | null;
61
- backend?: number;
62
- width: number;
63
- height: number;
64
- background?: string;
65
- };
66
- }
67
-
68
- // eslint-disable-next-line
69
- function L(...args: any[]) {
70
- if (Factory.DEBUG) log('VexFlow.Factory', args);
71
- }
72
-
73
- /**
74
- * Factory implements a high level API around VexFlow.
75
- */
76
- export class Factory {
77
- /** To enable logging for this class. Set `VexFlow.Factory.DEBUG` to `true`. */
78
- static DEBUG: boolean = false;
79
-
80
- /**
81
- * Static simplified function to access constructor without providing FactoryOptions
82
- *
83
- * Example:
84
- *
85
- * Create an SVG renderer and attach it to the DIV element named "boo" to render using <page-width> 1200 and <page-height> 600
86
- *
87
- * `const vf: Factory = VexFlow.Factory.newFromElementId('boo', 1200, 600 );`
88
- */
89
- static newFromElementId(elementId: string | null, width = 500, height = 200): Factory {
90
- return new Factory({ renderer: { elementId, width, height } });
91
- }
92
-
93
- protected options: Required<FactoryOptions>;
94
-
95
- protected stave?: Stave;
96
- protected context!: RenderContext;
97
- protected staves!: Stave[];
98
- protected voices!: Voice[];
99
- protected renderQ!: Element[];
100
- protected systems!: System[];
101
-
102
- /**
103
- * Example:
104
- *
105
- * Create an SVG renderer and attach it to the DIV element named "boo" to render using <page-width> 1200 and <page-height> 600
106
- *
107
- * `const vf: Factory = new VexFlow.Factory({renderer: { elementId: 'boo', width: 1200, height: 600 }});`
108
- */
109
- constructor(options: FactoryOptions = {}) {
110
- L('New factory: ', options);
111
- this.options = {
112
- stave: {
113
- space: 10,
114
- },
115
- renderer: {
116
- elementId: '',
117
- width: 500,
118
- height: 200,
119
- background: '#FFF',
120
- },
121
- };
122
-
123
- this.setOptions(options);
124
- }
125
-
126
- reset(): void {
127
- this.renderQ = [];
128
- this.systems = [];
129
- this.staves = [];
130
- this.voices = [];
131
- this.stave = undefined; // current stave
132
- }
133
-
134
- setOptions(options?: FactoryOptions): void {
135
- this.options = { ...this.options, ...options };
136
- this.initRenderer();
137
- this.reset();
138
- }
139
-
140
- initRenderer(): void {
141
- const { elementId, width, height, background } = this.options.renderer;
142
- if (elementId === null) {
143
- return;
144
- }
145
-
146
- if (elementId === '') {
147
- L(this);
148
- throw new RuntimeError('renderer.elementId not set in FactoryOptions');
149
- }
150
-
151
- let backend = this.options.renderer.backend;
152
- if (backend === undefined) {
153
- const elem = document.getElementById(elementId);
154
- // We use a custom type check here, because node-canvas mimics canvas,
155
- // but is not an instance of window.HTMLCanvasElement.
156
- // In fact, `window` might be undefined here.
157
- // See: https://www.npmjs.com/package/canvas
158
- if (isHTMLCanvas(elem)) {
159
- backend = Renderer.Backends.CANVAS;
160
- } else {
161
- backend = Renderer.Backends.SVG;
162
- }
163
- }
164
-
165
- this.context = Renderer.buildContext(elementId, backend, width, height, background);
166
- }
167
-
168
- getContext(): RenderContext {
169
- return this.context;
170
- }
171
-
172
- setContext(context: RenderContext): this {
173
- this.context = context;
174
- return this;
175
- }
176
-
177
- getStave(): Stave | undefined {
178
- return this.stave;
179
- }
180
-
181
- getVoices(): Voice[] {
182
- return this.voices;
183
- }
184
-
185
- /** Return pixels from current stave spacing. */
186
-
187
- Stave(params?: { x?: number; y?: number; width?: number; options?: StaveOptions }): Stave {
188
- const staveSpace = this.options.stave.space;
189
- const p = {
190
- x: 0,
191
- y: 0,
192
- width: this.options.renderer.width - staveSpace * 1.0,
193
- options: { spacingBetweenLinesPx: staveSpace * 1.0 },
194
- ...params,
195
- };
196
-
197
- const stave: Stave = new Stave(p.x, p.y, p.width, p.options);
198
- this.staves.push(stave);
199
- stave.setContext(this.context);
200
- this.stave = stave;
201
- return stave;
202
- }
203
-
204
- TabStave(params?: { x?: number; y?: number; width?: number; options?: StaveOptions }): TabStave {
205
- const staveSpace = this.options.stave.space;
206
- const p = {
207
- x: 0,
208
- y: 0,
209
- width: this.options.renderer.width - staveSpace * 1.0,
210
- options: { spacingBetweenLinesPx: staveSpace * 1.3 },
211
- ...params,
212
- };
213
-
214
- const stave = new TabStave(p.x, p.y, p.width, p.options);
215
- this.staves.push(stave);
216
- stave.setContext(this.context);
217
- this.stave = stave;
218
- return stave;
219
- }
220
-
221
- StaveNote(noteStruct: StaveNoteStruct): StaveNote {
222
- const note = new StaveNote(noteStruct);
223
- if (this.stave) note.setStave(this.stave);
224
- note.setContext(this.context);
225
- this.renderQ.push(note);
226
- return note;
227
- }
228
-
229
- GlyphNote(glyph: string, noteStruct: NoteStruct, options?: GlyphNoteOptions): GlyphNote {
230
- const note = new GlyphNote(glyph, noteStruct, options);
231
- if (this.stave) note.setStave(this.stave);
232
- note.setContext(this.context);
233
- this.renderQ.push(note);
234
- return note;
235
- }
236
-
237
- RepeatNote(type: string, noteStruct?: NoteStruct, options?: GlyphNoteOptions): RepeatNote {
238
- const note = new RepeatNote(type, noteStruct, options);
239
- if (this.stave) note.setStave(this.stave);
240
- note.setContext(this.context);
241
- this.renderQ.push(note);
242
- return note;
243
- }
244
-
245
- GhostNote(noteStruct: string | NoteStruct): GhostNote {
246
- const ghostNote = new GhostNote(noteStruct);
247
- if (this.stave) ghostNote.setStave(this.stave);
248
- ghostNote.setContext(this.context);
249
- this.renderQ.push(ghostNote);
250
- return ghostNote;
251
- }
252
-
253
- TextNote(noteStruct: TextNoteStruct): TextNote {
254
- const textNote = new TextNote(noteStruct);
255
- if (this.stave) textNote.setStave(this.stave);
256
- textNote.setContext(this.context);
257
- this.renderQ.push(textNote);
258
- return textNote;
259
- }
260
-
261
- BarNote(params: { type?: BarlineType | string } = {}): BarNote {
262
- const barNote = new BarNote(params.type);
263
- if (this.stave) barNote.setStave(this.stave);
264
- barNote.setContext(this.context);
265
- this.renderQ.push(barNote);
266
- return barNote;
267
- }
268
-
269
- ClefNote(params?: { type?: string; options?: { size?: string; annotation?: string } }): ClefNote {
270
- const p = {
271
- type: 'treble',
272
- options: {
273
- size: 'default',
274
- annotation: undefined,
275
- },
276
- ...params,
277
- };
278
-
279
- const clefNote = new ClefNote(p.type, p.options.size, p.options.annotation);
280
- if (this.stave) clefNote.setStave(this.stave);
281
- clefNote.setContext(this.context);
282
- this.renderQ.push(clefNote);
283
- return clefNote;
284
- }
285
-
286
- TimeSigNote(params?: { time?: string }): TimeSigNote {
287
- const p = {
288
- time: '4/4',
289
- ...params,
290
- };
291
-
292
- const timeSigNote = new TimeSigNote(p.time);
293
- if (this.stave) timeSigNote.setStave(this.stave);
294
- timeSigNote.setContext(this.context);
295
- this.renderQ.push(timeSigNote);
296
- return timeSigNote;
297
- }
298
-
299
- KeySigNote(params: { key: string; cancelKey?: string; alterKey?: string[] }): KeySigNote {
300
- const keySigNote = new KeySigNote(params.key, params.cancelKey, params.alterKey);
301
- if (this.stave) keySigNote.setStave(this.stave);
302
- keySigNote.setContext(this.context);
303
- this.renderQ.push(keySigNote);
304
- return keySigNote;
305
- }
306
-
307
- TabNote(noteStruct: TabNoteStruct): TabNote {
308
- const note = new TabNote(noteStruct);
309
- if (this.stave) note.setStave(this.stave);
310
- note.setContext(this.context);
311
- this.renderQ.push(note);
312
- return note;
313
- }
314
-
315
- GraceNote(noteStruct: GraceNoteStruct): GraceNote {
316
- const note = new GraceNote(noteStruct);
317
- if (this.stave) note.setStave(this.stave);
318
- note.setContext(this.context);
319
- return note;
320
- }
321
-
322
- GraceNoteGroup(params: { notes: StemmableNote[]; slur?: boolean }): GraceNoteGroup {
323
- const group = new GraceNoteGroup(params.notes, params.slur);
324
- group.setContext(this.context);
325
- return group;
326
- }
327
-
328
- Accidental(params: { type: string }): Accidental {
329
- const accid = new Accidental(params.type);
330
- accid.setContext(this.context);
331
- return accid;
332
- }
333
-
334
- Annotation(params?: {
335
- text?: string;
336
- hJustify?: string | AnnotationHorizontalJustify;
337
- vJustify?: string | AnnotationVerticalJustify;
338
- font?: FontInfo;
339
- }): Annotation {
340
- const p = {
341
- text: 'p',
342
- hJustify: AnnotationHorizontalJustify.CENTER,
343
- vJustify: AnnotationVerticalJustify.BOTTOM,
344
- ...params,
345
- };
346
-
347
- const annotation = new Annotation(p.text);
348
- annotation.setJustification(p.hJustify);
349
- annotation.setVerticalJustification(p.vJustify);
350
- annotation.setFont(p.font);
351
- annotation.setContext(this.context);
352
- return annotation;
353
- }
354
-
355
- ChordSymbol(params?: {
356
- vJustify?: string;
357
- hJustify?: string;
358
- fontFamily?: string;
359
- fontSize?: number;
360
- fontWeight?: string;
361
- }): ChordSymbol {
362
- const p = {
363
- vJustify: 'top',
364
- hJustify: 'center',
365
- ...params,
366
- };
367
-
368
- const chordSymbol = new ChordSymbol();
369
- chordSymbol.setHorizontal(p.hJustify);
370
- chordSymbol.setVertical(p.vJustify);
371
- // There is a default font based on the engraving font. Only set then
372
- // font if it is specific, else use the default
373
- if (typeof p.fontFamily === 'string' && typeof p.fontSize === 'number') {
374
- if (typeof p.fontWeight === 'string') chordSymbol.setFont(p.fontFamily, p.fontSize, p.fontWeight);
375
- else chordSymbol.setFont(p.fontFamily, p.fontSize, '');
376
- } else if (typeof p.fontSize === 'number') {
377
- chordSymbol.setFontSize(p.fontSize);
378
- }
379
- chordSymbol.setContext(this.context);
380
- return chordSymbol;
381
- }
382
-
383
- Articulation(params?: { betweenLines?: boolean; type?: string; position?: string | number }): Articulation {
384
- const articulation = new Articulation(params?.type ?? 'a.');
385
-
386
- if (params?.position !== undefined) articulation.setPosition(params.position);
387
- if (params?.betweenLines !== undefined) articulation.setBetweenLines(params.betweenLines);
388
- articulation.setContext(this.context);
389
- return articulation;
390
- }
391
-
392
- Ornament(
393
- type: string,
394
- params?: { position?: string | number; upperAccidental?: string; lowerAccidental?: string; delayed?: boolean }
395
- ) {
396
- const options = {
397
- type,
398
- accidental: '',
399
- ...params,
400
- };
401
- const ornament = new Ornament(type);
402
- if (params?.position !== undefined) {
403
- ornament.setPosition(params.position);
404
- }
405
- if (options.upperAccidental) {
406
- ornament.setUpperAccidental(options.upperAccidental);
407
- }
408
- if (options.lowerAccidental) {
409
- ornament.setLowerAccidental(options.lowerAccidental);
410
- }
411
- if (typeof options.delayed !== 'undefined') {
412
- ornament.setDelayed(options.delayed);
413
- }
414
- ornament.setContext(this.context);
415
- return ornament;
416
- }
417
-
418
- TextDynamics(params?: { text?: string; duration?: string; dots?: number; line?: number }): TextDynamics {
419
- const p = {
420
- text: 'p',
421
- duration: 'q',
422
- dots: 0,
423
- line: 0,
424
- ...params,
425
- };
426
-
427
- const text = new TextDynamics({
428
- text: p.text,
429
- line: p.line,
430
- duration: p.duration,
431
- dots: p.dots,
432
- });
433
-
434
- if (this.stave) text.setStave(this.stave);
435
- text.setContext(this.context);
436
- this.renderQ.push(text);
437
- return text;
438
- }
439
-
440
- Fingering(params: { number?: string; position?: string }): FretHandFinger {
441
- const p = {
442
- number: '0',
443
- position: 'left',
444
- ...params,
445
- };
446
-
447
- const fingering = new FretHandFinger(p.number);
448
- fingering.setPosition(p.position);
449
- fingering.setContext(this.context);
450
- return fingering;
451
- }
452
-
453
- StringNumber(params: { number: string; position: string }, drawCircle = true): StringNumber {
454
- const stringNumber = new StringNumber(params.number);
455
- stringNumber.setPosition(params.position);
456
- stringNumber.setContext(this.context);
457
- stringNumber.setDrawCircle(drawCircle);
458
- return stringNumber;
459
- }
460
-
461
- TickContext(): TickContext {
462
- return new TickContext();
463
- }
464
-
465
- ModifierContext(): ModifierContext {
466
- return new ModifierContext();
467
- }
468
-
469
- MultiMeasureRest(params: MultimeasureRestRenderOptions): MultiMeasureRest {
470
- const numMeasures = defined(params.numberOfMeasures, 'NoNumberOfMeasures');
471
- const multiMeasureRest = new MultiMeasureRest(numMeasures, params);
472
- multiMeasureRest.setContext(this.context);
473
- this.renderQ.push(multiMeasureRest);
474
- return multiMeasureRest;
475
- }
476
-
477
- Voice(params?: { time?: VoiceTime | string }): Voice {
478
- const p = {
479
- time: '4/4',
480
- ...params,
481
- };
482
- const voice = new Voice(p.time);
483
- this.voices.push(voice);
484
- return voice;
485
- }
486
-
487
- StaveConnector(params: { topStave: Stave; bottomStave: Stave; type: StaveConnectorType }): StaveConnector {
488
- const connector = new StaveConnector(params.topStave, params.bottomStave);
489
- connector.setType(params.type).setContext(this.context);
490
- this.renderQ.push(connector);
491
- return connector;
492
- }
493
-
494
- Formatter(options?: FormatterOptions): Formatter {
495
- return new Formatter(options);
496
- }
497
-
498
- Tuplet(params?: { notes?: Note[]; options?: TupletOptions }): Tuplet {
499
- const p = {
500
- notes: [],
501
- options: {},
502
- ...params,
503
- };
504
-
505
- const tuplet = new Tuplet(p.notes, p.options).setContext(this.context);
506
- this.renderQ.push(tuplet);
507
- return tuplet;
508
- }
509
-
510
- Beam(params: {
511
- notes: StemmableNote[];
512
- options?: {
513
- autoStem?: boolean;
514
- secondaryBeamBreaks?: number[];
515
- partialBeamDirections?: {
516
- [noteIndex: number]: PartialBeamDirection;
517
- };
518
- };
519
- }): Beam {
520
- const beam = new Beam(params.notes, params.options?.autoStem).setContext(this.context);
521
- beam.breakSecondaryAt(params.options?.secondaryBeamBreaks ?? []);
522
- if (params.options?.partialBeamDirections) {
523
- Object.entries(params.options?.partialBeamDirections).forEach(([noteIndex, direction]) => {
524
- beam.setPartialBeamSideAt(Number(noteIndex), direction);
525
- });
526
- }
527
- this.renderQ.push(beam);
528
- return beam;
529
- }
530
-
531
- Curve(params: { from: Note; to: Note; options: CurveOptions }): Curve {
532
- const curve = new Curve(params.from, params.to, params.options).setContext(this.context);
533
- this.renderQ.push(curve);
534
- return curve;
535
- }
536
-
537
- StaveTie(params: {
538
- from?: Note | null;
539
- to?: Note | null;
540
- firstIndexes?: number[];
541
- lastIndexes?: number[];
542
- text?: string;
543
- options?: { direction?: number };
544
- }): StaveTie {
545
- const tie = new StaveTie(
546
- {
547
- firstNote: params.from,
548
- lastNote: params.to,
549
- firstIndexes: params.firstIndexes,
550
- lastIndexes: params.lastIndexes,
551
- },
552
- params.text
553
- );
554
-
555
- if (params.options?.direction) tie.setDirection(params.options.direction);
556
- tie.setContext(this.context);
557
- this.renderQ.push(tie);
558
- return tie;
559
- }
560
-
561
- StaveLine(params: {
562
- from: StaveNote;
563
- to: StaveNote;
564
- firstIndexes: number[];
565
- lastIndexes: number[];
566
- options?: { text?: string; font?: FontInfo };
567
- }): StaveLine {
568
- const line = new StaveLine({
569
- firstNote: params.from,
570
- lastNote: params.to,
571
- firstIndexes: params.firstIndexes,
572
- lastIndexes: params.lastIndexes,
573
- });
574
-
575
- if (params.options?.text) line.setText(params.options.text);
576
- if (params.options?.font) line.setFont(params.options.font);
577
-
578
- line.setContext(this.context);
579
- this.renderQ.push(line);
580
- return line;
581
- }
582
-
583
- VibratoBracket(params: {
584
- from: Note | null;
585
- to: Note | null;
586
- options: {
587
- code?: number;
588
- line?: number;
589
- };
590
- }): VibratoBracket {
591
- const vibratoBracket = new VibratoBracket({
592
- start: params.from,
593
- stop: params.to,
594
- });
595
-
596
- if (params.options.line) vibratoBracket.setLine(params.options.line);
597
- if (params.options.code) vibratoBracket.setVibratoCode(params.options.code);
598
-
599
- vibratoBracket.setContext(this.context);
600
- this.renderQ.push(vibratoBracket);
601
-
602
- return vibratoBracket;
603
- }
604
-
605
- TextBracket(params: {
606
- from: Note;
607
- to: Note;
608
- text: string;
609
- options: {
610
- superscript: string;
611
- position: string;
612
- line?: number;
613
- font?: FontInfo;
614
- };
615
- }): TextBracket {
616
- const textBracket = new TextBracket({
617
- start: params.from,
618
- stop: params.to,
619
- text: params.text,
620
- superscript: params.options.superscript,
621
- position: params.options.position,
622
- });
623
-
624
- if (params.options.line) textBracket.setLine(params.options.line);
625
- if (params.options.font) textBracket.setFont(params.options.font);
626
-
627
- textBracket.setContext(this.context);
628
- this.renderQ.push(textBracket);
629
- return textBracket;
630
- }
631
-
632
- System(params: SystemOptions = {}): System {
633
- params.factory = this;
634
- const system = new System(params).setContext(this.context);
635
- this.systems.push(system);
636
- return system;
637
- }
638
-
639
- /**
640
- * Creates EasyScore. Normally the first step after constructing a Factory. For example:
641
- * ```
642
- * const vf: Factory = new VexFlow.Factory({renderer: { elementId: 'boo', width: 1200, height: 600 }});
643
- * const score: EasyScore = vf.EasyScore();
644
- * ```
645
- * @param options.factory optional instance of Factory
646
- * @param options.builder instance of Builder
647
- * @param options.commitHooks function to call after a note element is created
648
- * @param options.throwOnError throw error in case of parsing error
649
- */
650
- EasyScore(options: EasyScoreOptions = {}): EasyScore {
651
- options.factory = this;
652
- return new EasyScore(options);
653
- }
654
-
655
- PedalMarking(params?: { notes?: StaveNote[]; options?: { style: string } }): PedalMarking {
656
- const p = {
657
- notes: [],
658
- options: {
659
- style: 'mixed',
660
- },
661
- ...params,
662
- };
663
-
664
- const pedal = new PedalMarking(p.notes);
665
- pedal.setType(PedalMarking.typeString[p.options.style]);
666
- pedal.setContext(this.context);
667
- this.renderQ.push(pedal);
668
- return pedal;
669
- }
670
-
671
- NoteSubGroup(params?: { notes?: Note[] }): NoteSubGroup {
672
- const p = {
673
- notes: [],
674
- ...params,
675
- };
676
-
677
- const group = new NoteSubGroup(p.notes);
678
- group.setContext(this.context);
679
- return group;
680
- }
681
-
682
- /** Render the score. */
683
- draw(): void {
684
- const ctx = this.context;
685
- this.systems.forEach((s) => s.setContext(ctx).format());
686
- this.staves.forEach((s) => s.setContext(ctx).draw());
687
- this.voices.forEach((v) => v.setContext(ctx).draw());
688
- this.renderQ.forEach((e) => {
689
- if (!e.isRendered()) e.setContext(ctx).draw();
690
- });
691
- this.systems.forEach((s) => s.setContext(ctx).draw());
692
- this.reset();
693
- }
694
- }