vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +528 -492
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +460 -452
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/accidental.js +22 -28
  12. package/build/esm/src/beam.js +24 -42
  13. package/build/esm/src/clefnote.js +6 -1
  14. package/build/esm/src/element.js +83 -101
  15. package/build/esm/src/fonts/gonville.js +1 -1
  16. package/build/esm/src/formatter.js +9 -17
  17. package/build/esm/src/fraction.js +15 -22
  18. package/build/esm/src/glyphnote.js +3 -2
  19. package/build/esm/src/metrics.js +3 -0
  20. package/build/esm/src/modifier.js +6 -21
  21. package/build/esm/src/multimeasurerest.js +16 -25
  22. package/build/esm/src/note.js +7 -0
  23. package/build/esm/src/registry.js +5 -19
  24. package/build/esm/src/stave.js +4 -6
  25. package/build/esm/src/stavenote.js +26 -40
  26. package/build/esm/src/stavetempo.js +4 -11
  27. package/build/esm/src/stavetie.js +82 -36
  28. package/build/esm/src/svgcontext.js +5 -12
  29. package/build/esm/src/tickable.js +13 -26
  30. package/build/esm/src/tickcontext.js +20 -2
  31. package/build/esm/src/version.js +3 -3
  32. package/build/esm/src/vibrato.js +6 -1
  33. package/build/esm/tests/clef_tests.js +5 -1
  34. package/build/esm/tests/glyphnote_tests.js +6 -0
  35. package/build/esm/tests/stavetie_tests.js +29 -0
  36. package/build/esm/tests/tabstave_tests.js +1 -0
  37. package/build/esm/tests/vexflow_test_helpers.js +25 -39
  38. package/build/types/src/accidental.d.ts +19 -1
  39. package/build/types/src/annotation.d.ts +1 -1
  40. package/build/types/src/beam.d.ts +12 -1
  41. package/build/types/src/clefnote.d.ts +2 -0
  42. package/build/types/src/element.d.ts +13 -3
  43. package/build/types/src/fonts/gonville.d.ts +1 -1
  44. package/build/types/src/formatter.d.ts +5 -3
  45. package/build/types/src/fraction.d.ts +12 -7
  46. package/build/types/src/modifier.d.ts +2 -1
  47. package/build/types/src/multimeasurerest.d.ts +4 -1
  48. package/build/types/src/note.d.ts +2 -0
  49. package/build/types/src/registry.d.ts +1 -1
  50. package/build/types/src/stavenote.d.ts +2 -1
  51. package/build/types/src/stavetempo.d.ts +3 -3
  52. package/build/types/src/stavetie.d.ts +39 -2
  53. package/build/types/src/svgcontext.d.ts +1 -1
  54. package/build/types/src/tickable.d.ts +2 -1
  55. package/build/types/src/tickcontext.d.ts +30 -0
  56. package/package.json +2 -4
  57. package/tests/flow.html +2 -2
  58. package/entry/vexflow-bravura.ts +0 -25
  59. package/entry/vexflow-core.ts +0 -16
  60. package/entry/vexflow-debug-with-tests.ts +0 -64
  61. package/entry/vexflow-debug.ts +0 -54
  62. package/entry/vexflow.ts +0 -47
  63. package/src/accidental.ts +0 -570
  64. package/src/annotation.ts +0 -294
  65. package/src/articulation.ts +0 -383
  66. package/src/barnote.ts +0 -95
  67. package/src/beam.ts +0 -999
  68. package/src/bend.ts +0 -268
  69. package/src/boundingbox.ts +0 -108
  70. package/src/canvascontext.ts +0 -348
  71. package/src/chordsymbol.ts +0 -473
  72. package/src/clef.ts +0 -164
  73. package/src/clefnote.ts +0 -50
  74. package/src/crescendo.ts +0 -132
  75. package/src/curve.ts +0 -195
  76. package/src/dot.ts +0 -171
  77. package/src/easyscore.ts +0 -538
  78. package/src/element.ts +0 -692
  79. package/src/factory.ts +0 -694
  80. package/src/font.ts +0 -343
  81. package/src/fonts/academico.ts +0 -2
  82. package/src/fonts/academicobold.ts +0 -2
  83. package/src/fonts/bravura.ts +0 -2
  84. package/src/fonts/gonville.ts +0 -2
  85. package/src/fonts/petaluma.ts +0 -2
  86. package/src/fonts/petalumascript.ts +0 -2
  87. package/src/formatter.ts +0 -1107
  88. package/src/fraction.ts +0 -245
  89. package/src/frethandfinger.ts +0 -180
  90. package/src/ghostnote.ts +0 -75
  91. package/src/glyphnote.ts +0 -68
  92. package/src/glyphs.ts +0 -5880
  93. package/src/gracenote.ts +0 -146
  94. package/src/gracenotegroup.ts +0 -194
  95. package/src/gracetabnote.ts +0 -30
  96. package/src/index.ts +0 -90
  97. package/src/keymanager.ts +0 -153
  98. package/src/keysignature.ts +0 -272
  99. package/src/keysignote.ts +0 -46
  100. package/src/metrics.ts +0 -222
  101. package/src/modifier.ts +0 -216
  102. package/src/modifiercontext.ts +0 -177
  103. package/src/multimeasurerest.ts +0 -229
  104. package/src/music.ts +0 -443
  105. package/src/note.ts +0 -690
  106. package/src/notehead.ts +0 -158
  107. package/src/notesubgroup.ts +0 -88
  108. package/src/ornament.ts +0 -301
  109. package/src/parenthesis.ts +0 -89
  110. package/src/parser.ts +0 -263
  111. package/src/pedalmarking.ts +0 -273
  112. package/src/registry.ts +0 -146
  113. package/src/rendercontext.ts +0 -98
  114. package/src/renderer.ts +0 -166
  115. package/src/repeatnote.ts +0 -25
  116. package/src/stave.ts +0 -885
  117. package/src/stavebarline.ts +0 -231
  118. package/src/staveconnector.ts +0 -281
  119. package/src/stavehairpin.ts +0 -209
  120. package/src/staveline.ts +0 -343
  121. package/src/stavemodifier.ts +0 -93
  122. package/src/stavenote.ts +0 -1230
  123. package/src/staverepetition.ts +0 -148
  124. package/src/stavesection.ts +0 -54
  125. package/src/stavetempo.ts +0 -162
  126. package/src/stavetext.ts +0 -69
  127. package/src/stavetie.ts +0 -235
  128. package/src/stavevolta.ts +0 -66
  129. package/src/stem.ts +0 -225
  130. package/src/stemmablenote.ts +0 -248
  131. package/src/stringnumber.ts +0 -286
  132. package/src/strokes.ts +0 -214
  133. package/src/svgcontext.ts +0 -639
  134. package/src/system.ts +0 -327
  135. package/src/tables.ts +0 -796
  136. package/src/tabnote.ts +0 -449
  137. package/src/tabslide.ts +0 -115
  138. package/src/tabstave.ts +0 -31
  139. package/src/tabtie.ts +0 -44
  140. package/src/textbracket.ts +0 -231
  141. package/src/textdynamics.ts +0 -101
  142. package/src/textnote.ts +0 -175
  143. package/src/tickable.ts +0 -374
  144. package/src/tickcontext.ts +0 -280
  145. package/src/timesignature.ts +0 -229
  146. package/src/timesignote.ts +0 -45
  147. package/src/tremolo.ts +0 -51
  148. package/src/tuning.ts +0 -90
  149. package/src/tuplet.ts +0 -349
  150. package/src/typeguard.ts +0 -136
  151. package/src/util.ts +0 -169
  152. package/src/version.ts +0 -4
  153. package/src/vexflow.ts +0 -378
  154. package/src/vibrato.ts +0 -99
  155. package/src/vibratobracket.ts +0 -81
  156. package/src/voice.ts +0 -302
  157. package/src/web.ts +0 -35
package/src/system.ts DELETED
@@ -1,327 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { BoundingBox } from './boundingbox';
5
- import { Element } from './element';
6
- import { Factory } from './factory';
7
- import { FormatParams, Formatter, FormatterOptions } from './formatter';
8
- import { Note } from './note';
9
- import { RenderContext } from './rendercontext';
10
- import { Stave, StaveOptions } from './stave';
11
- import { StaveConnector, StaveConnectorType } from './staveconnector';
12
- import { Category } from './typeguard';
13
- import { RuntimeError } from './util';
14
- import { Voice } from './voice';
15
-
16
- export interface SystemFormatterOptions extends FormatterOptions {
17
- alpha?: number;
18
- }
19
-
20
- export interface SystemStave {
21
- voices: Voice[];
22
- stave?: Stave;
23
- noJustification?: boolean;
24
- options?: StaveOptions;
25
- spaceAbove?: number;
26
- spaceBelow?: number;
27
- debugNoteMetrics?: boolean;
28
- }
29
-
30
- interface StaveInfo {
31
- noJustification: boolean;
32
- options: StaveOptions;
33
- spaceAbove: number;
34
- spaceBelow: number;
35
- debugNoteMetrics: boolean;
36
- }
37
-
38
- /**
39
- * Formatting for systems created/drawn from factory:
40
- *
41
- * If width is provided, the system will use the specified width.
42
- *
43
- * If noJustification flag is 'true', there is no justification between voices
44
- * Otherwise, autoWidth defaults to true.
45
- *
46
- * If autowidth is true, the system uses format.preCalculateMinWidth
47
- * for the width of all voices, and default stave padding
48
- */
49
- export interface SystemOptions {
50
- factory?: Factory;
51
- noPadding?: boolean;
52
- debugFormatter?: boolean;
53
- spaceBetweenStaves?: number;
54
- formatIterations?: number;
55
- autoWidth?: boolean;
56
- x?: number;
57
- width?: number;
58
- y?: number;
59
- details?: SystemFormatterOptions;
60
- formatOptions?: FormatParams;
61
- noJustification?: boolean;
62
- }
63
-
64
- /**
65
- * System implements a musical system, which is a collection of staves,
66
- * each which can have one or more voices. All voices across all staves in
67
- * the system are formatted together.
68
- */
69
- export class System extends Element {
70
- static get CATEGORY(): string {
71
- return Category.System;
72
- }
73
-
74
- protected options!: Required<SystemOptions>;
75
- protected factory!: Factory;
76
- protected formatter?: Formatter;
77
- protected startX?: number;
78
- protected lastY?: number;
79
- protected partStaves: Stave[];
80
- protected partStaveInfos: StaveInfo[];
81
- protected partVoices: Voice[];
82
- protected connector?: StaveConnector;
83
- protected debugNoteMetricsYs?: { y: number; stave: Stave }[];
84
-
85
- constructor(params: SystemOptions = {}) {
86
- super();
87
- this.setOptions(params);
88
- this.partStaves = [];
89
- this.partStaveInfos = [];
90
- this.partVoices = [];
91
- }
92
-
93
- /** Set formatting options. */
94
- setOptions(options: SystemOptions = {}): void {
95
- if (!options.factory) {
96
- throw new RuntimeError('NoFactory', 'System.setOptions(options) requires a factory.');
97
- }
98
- this.factory = options.factory;
99
- this.options = {
100
- factory: this.factory,
101
- x: 10,
102
- y: 10,
103
- width: 500,
104
- spaceBetweenStaves: 12, // stave spaces
105
- autoWidth: false,
106
- noJustification: false,
107
- debugFormatter: false,
108
- formatIterations: 0, // number of formatter tuning steps
109
- noPadding: false,
110
- ...options,
111
- details: {
112
- alpha: 0.5, // formatter tuner learning/shifting rate
113
- ...options.details,
114
- },
115
- formatOptions: {
116
- ...options.formatOptions,
117
- },
118
- };
119
-
120
- if (this.options.noJustification === false && typeof options.width === 'undefined') {
121
- this.options.autoWidth = true;
122
- }
123
- }
124
-
125
- /** Get origin X. */
126
- getX(): number {
127
- return this.options.x;
128
- }
129
-
130
- /** Set origin X. */
131
- setX(x: number): this {
132
- this.options.x = x;
133
- this.partStaves.forEach((s) => {
134
- s.setX(x);
135
- });
136
- return this;
137
- }
138
-
139
- /** Get origin y. */
140
- getY(): number {
141
- return this.options.y;
142
- }
143
-
144
- /** Set origin y. */
145
- setY(y: number): this {
146
- this.options.y = y;
147
- this.partStaves.forEach((s) => {
148
- s.setY(y);
149
- });
150
- return this;
151
- }
152
-
153
- /** Get associated staves. */
154
- getStaves(): Stave[] {
155
- return this.partStaves;
156
- }
157
-
158
- /** Get associated voices. */
159
- getVoices(): Voice[] {
160
- return this.partVoices;
161
- }
162
-
163
- /** Set associated context. */
164
- setContext(context: RenderContext): this {
165
- super.setContext(context);
166
- this.factory.setContext(context);
167
- return this;
168
- }
169
-
170
- /**
171
- * Add connector between staves.
172
- * @param type see {@link StaveConnector.typeString}
173
- */
174
- addConnector(type: StaveConnectorType = 'double'): StaveConnector {
175
- this.connector = this.factory.StaveConnector({
176
- topStave: this.partStaves[0],
177
- bottomStave: this.partStaves[this.partStaves.length - 1],
178
- type,
179
- });
180
- return this.connector;
181
- }
182
-
183
- /**
184
- * Add a stave to the system.
185
- *
186
- * Example (one voice):
187
- *
188
- * `system.addStave({voices: [score.voice(score.notes('C#5/q, B4, A4, G#4'))]});`
189
- *
190
- * Example (two voices):
191
- *
192
- * `system.addStave({voices: [`
193
- * `score.voice(score.notes('C#5/q, B4, A4, G#4', {stem: 'up'})),`
194
- * `score.voice(score.notes('C#4/h, C#4', {stem: 'down'}))`
195
- * `]});`
196
- */
197
- addStave(params: SystemStave): Stave {
198
- const staveOptions: StaveOptions = { leftBar: false, ...params.options };
199
-
200
- const stave =
201
- params.stave ??
202
- this.factory.Stave({ x: this.options.x, y: this.options.y, width: this.options.width, options: staveOptions });
203
-
204
- const p = {
205
- spaceAbove: 0, // stave spaces
206
- spaceBelow: 0, // stave spaces
207
- debugNoteMetrics: false,
208
- noJustification: false,
209
- ...params,
210
- options: staveOptions, // this needs to go after ...params, so we can override the options field.
211
- };
212
-
213
- const ctx = this.getContext();
214
- p.voices.forEach((voice) => {
215
- voice
216
- .setContext(ctx)
217
- .setStave(stave)
218
- .getTickables()
219
- .forEach((tickable) => tickable.setStave(stave));
220
- this.partVoices.push(voice);
221
- });
222
-
223
- this.partStaves.push(stave);
224
- this.partStaveInfos.push(p);
225
- return stave;
226
- }
227
-
228
- /**
229
- * Add voices to the system with stave already assigned.
230
- */
231
- addVoices(voices: Voice[]) {
232
- const ctx = this.getContext();
233
- voices.forEach((voice) => {
234
- voice.setContext(ctx);
235
- this.partVoices.push(voice);
236
- });
237
- }
238
-
239
- /** Format the system. */
240
- format(): void {
241
- const optionsDetails = this.options.details;
242
- let justifyWidth = 0;
243
- const formatter = new Formatter(optionsDetails);
244
- this.formatter = formatter;
245
-
246
- let y = this.options.y;
247
- let startX = 0;
248
- const debugNoteMetricsYs: { y: number; stave: Stave }[] = [];
249
-
250
- this.partStaves.forEach((part, index) => {
251
- y = y + part.space(this.partStaveInfos[index].spaceAbove);
252
- part.setY(y);
253
- y = y + part.space(this.partStaveInfos[index].spaceBelow);
254
- y = y + part.space(this.options.spaceBetweenStaves);
255
- if (this.partStaveInfos[index].debugNoteMetrics) {
256
- debugNoteMetricsYs.push({ y, stave: part });
257
- y += 15;
258
- }
259
- startX = Math.max(startX, part.getNoteStartX());
260
- });
261
-
262
- // Re-assign Stave to update y position
263
- this.partVoices.forEach((voice) => {
264
- voice.getTickables().forEach((tickable) => {
265
- const stave = tickable.getStave();
266
- if (stave) tickable.setStave(stave);
267
- });
268
- });
269
-
270
- // Join the voices
271
- formatter.joinVoices(this.partVoices);
272
-
273
- // Update the start position of all staves.
274
- this.partStaves.forEach((part) => part.setNoteStartX(startX));
275
- if (this.options.autoWidth && this.partVoices.length > 0) {
276
- justifyWidth = formatter.preCalculateMinTotalWidth(this.partVoices);
277
- this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x);
278
- this.partStaves.forEach((part) => {
279
- part.setWidth(this.options.width);
280
- });
281
- } else {
282
- justifyWidth = this.options.noPadding
283
- ? this.options.width - (startX - this.options.x)
284
- : this.options.width - (startX - this.options.x) - Stave.defaultPadding;
285
- }
286
- if (this.partVoices.length > 0) {
287
- formatter.format(this.partVoices, this.options.noJustification ? 0 : justifyWidth, this.options.formatOptions);
288
- }
289
- formatter.postFormat();
290
-
291
- for (let i = 0; i < this.options.formatIterations; i++) {
292
- formatter.tune(optionsDetails);
293
- }
294
-
295
- this.startX = startX;
296
- this.debugNoteMetricsYs = debugNoteMetricsYs;
297
- this.lastY = y;
298
- Stave.formatBegModifiers(this.partStaves);
299
- }
300
-
301
- /** Get the boundingBox. */
302
- getBoundingBox(): BoundingBox {
303
- return new BoundingBox(this.options.x, this.options.y, this.options.width, (this.lastY ?? 0) - this.options.y);
304
- }
305
-
306
- /** Render the system. */
307
- draw(): void {
308
- // Render debugging information, if requested.
309
- const ctx = this.checkContext();
310
- if (!this.formatter || !this.startX || !this.lastY || !this.debugNoteMetricsYs) {
311
- throw new RuntimeError('NoFormatter', 'format() must be called before draw()');
312
- }
313
- this.setRendered();
314
-
315
- if (this.options.debugFormatter) {
316
- Formatter.plotDebugging(ctx, this.formatter, this.startX, this.options.y, this.lastY);
317
- }
318
-
319
- this.debugNoteMetricsYs.forEach((d) => {
320
- this.partVoices.forEach((voice) => {
321
- voice.getTickables().forEach((tickable) => {
322
- if (tickable.getStave() === d.stave) Note.plotMetrics(ctx, tickable, d.y);
323
- });
324
- });
325
- });
326
- }
327
- }