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/voice.ts DELETED
@@ -1,302 +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 { Fraction } from './fraction';
7
- import { RenderContext } from './rendercontext';
8
- import { Stave } from './stave';
9
- import { Tables } from './tables';
10
- import { Tickable } from './tickable';
11
- import { Category } from './typeguard';
12
- import { defined, RuntimeError, sumArray } from './util';
13
-
14
- export interface VoiceTime {
15
- numBeats: number;
16
- beatValue: number;
17
- /** Defaults to `VexFlow.RESOLUTION` if not provided. */
18
- resolution?: number;
19
- }
20
-
21
- export enum VoiceMode {
22
- STRICT = 1,
23
- SOFT = 2,
24
- FULL = 3,
25
- }
26
-
27
- /**
28
- * `Voice` is mainly a container object to group `Tickables` for formatting.
29
- */
30
- export class Voice extends Element {
31
- static get CATEGORY(): string {
32
- return Category.Voice;
33
- }
34
-
35
- /**
36
- * Modes allow the addition of ticks in three different ways:
37
- * - STRICT: This is the default. Ticks must fill the voice.
38
- * - SOFT: Ticks can be added without restrictions.
39
- * - FULL: Ticks do not need to fill the voice, but can't exceed the maximum tick length.
40
- */
41
- static get Mode(): typeof VoiceMode {
42
- return VoiceMode;
43
- }
44
-
45
- protected resolutionMultiplier: number = 1;
46
- protected smallestTickCount: Fraction;
47
- protected stave?: Stave;
48
- protected mode: VoiceMode = VoiceMode.STRICT;
49
- protected expTicksUsed?: number;
50
- protected preFormatted: boolean = false;
51
- protected options: { softmaxFactor: number };
52
-
53
- protected readonly totalTicks: Fraction;
54
- protected readonly ticksUsed: Fraction = new Fraction(0, 1);
55
- protected readonly largestTickWidth: number = 0;
56
- protected readonly tickables: Tickable[] = [];
57
- protected readonly time: Required<VoiceTime>;
58
-
59
- constructor(time?: VoiceTime | string) {
60
- super();
61
-
62
- this.options = {
63
- softmaxFactor: Tables.SOFTMAX_FACTOR,
64
- };
65
-
66
- // Convert the `time` string into a VoiceTime object if necessary.
67
- let voiceTime: VoiceTime | undefined;
68
- if (typeof time === 'string') {
69
- // Time signature shortcut: "4/4", "3/8", etc.
70
- const match = time.match(/(\d+)\/(\d+)/);
71
- if (match) {
72
- voiceTime = {
73
- numBeats: parseInt(match[1]),
74
- beatValue: parseInt(match[2]),
75
- };
76
- }
77
- } else {
78
- voiceTime = time;
79
- }
80
-
81
- // Default time signature is 4/4.
82
- this.time = {
83
- numBeats: 4,
84
- beatValue: 4,
85
- resolution: Tables.RESOLUTION,
86
- ...voiceTime,
87
- };
88
-
89
- // Recalculate total ticks.
90
- this.totalTicks = new Fraction(this.time.numBeats * (this.time.resolution / this.time.beatValue), 1);
91
- // until tickables are added, the smallestTickCount is the same as the stated totalTicks duration.
92
- this.smallestTickCount = this.totalTicks.clone();
93
- }
94
-
95
- /** Get the total ticks in the voice. */
96
- getTotalTicks(): Fraction {
97
- return this.totalTicks;
98
- }
99
-
100
- /** Get the total ticks used in the voice by all the tickables. */
101
- getTicksUsed(): Fraction {
102
- return this.ticksUsed;
103
- }
104
-
105
- /** Get the largest width of all the tickables. */
106
- getLargestTickWidth(): number {
107
- return this.largestTickWidth;
108
- }
109
-
110
- /** Get the tick count for the shortest tickable */
111
- getSmallestTickCount(): Fraction {
112
- return this.smallestTickCount;
113
- }
114
-
115
- /** Get the tickables in the voice. */
116
- getTickables(): Tickable[] {
117
- return this.tickables;
118
- }
119
-
120
- /** Get the voice mode (Voice.Mode.SOFT, STRICT, or FULL) */
121
- getMode(): number {
122
- return this.mode;
123
- }
124
-
125
- /**
126
- * Set the voice mode.
127
- * @param mode value from `VoiceMode` or Voice.Mode
128
- */
129
- setMode(mode: number): this {
130
- this.mode = mode;
131
- return this;
132
- }
133
-
134
- /** Get the resolution multiplier for the voice. */
135
- getResolutionMultiplier(): number {
136
- return this.resolutionMultiplier;
137
- }
138
-
139
- /** Get the actual tick resolution for the voice. */
140
- getActualResolution(): number {
141
- return this.resolutionMultiplier * this.time.resolution;
142
- }
143
-
144
- /** Set the voice's stave. */
145
- setStave(stave: Stave): this {
146
- this.stave = stave;
147
- return this;
148
- }
149
-
150
- getStave(): Stave | undefined {
151
- return this.stave;
152
- }
153
-
154
- /** Get the bounding box for the voice. */
155
- getBoundingBox(): BoundingBox {
156
- const boundingBox = this.tickables[0].getBoundingBox();
157
- for (let i = 1; i < this.tickables.length; ++i) {
158
- const tickable = this.tickables[i];
159
- if (!tickable.getStave() && this.stave) tickable.setStave(this.stave);
160
- const bb = tickable.getBoundingBox();
161
- boundingBox.mergeWith(bb);
162
- }
163
- return boundingBox;
164
- }
165
-
166
- /** Set the voice mode to strict or soft. */
167
- setStrict(strict: boolean): this {
168
- this.mode = strict ? VoiceMode.STRICT : VoiceMode.SOFT;
169
- return this;
170
- }
171
-
172
- /** Determine if the voice is complete according to the voice mode. */
173
- isComplete(): boolean {
174
- if (this.mode === VoiceMode.STRICT || this.mode === VoiceMode.FULL) {
175
- return this.ticksUsed.equals(this.totalTicks);
176
- } else {
177
- return true;
178
- }
179
- }
180
-
181
- /**
182
- * We use softmax to layout the tickables proportional to the exponent of
183
- * their duration. The softmax factor is used to determine the 'linearness' of
184
- * the layout.
185
- *
186
- * The softmax of all the tickables in this voice should sum to 1.
187
- */
188
- setSoftmaxFactor(factor: number): this {
189
- this.options.softmaxFactor = factor;
190
- this.expTicksUsed = 0; // reset
191
- return this;
192
- }
193
-
194
- /**
195
- * Calculate the sum of the exponents of all the ticks in this voice to use
196
- * as the denominator of softmax. (It is not the sum of the softmax(t) over all tickables)
197
- *
198
- * Note that the "exp" of "expTicksUsed" stands for "expontential" ticks used,
199
- * not "expected" ticks used.
200
- */
201
- protected reCalculateExpTicksUsed(): number {
202
- const totalTicks = this.ticksUsed.value();
203
- const exp = (tickable: Tickable) => Math.pow(this.options.softmaxFactor, tickable.getTicks().value() / totalTicks);
204
- this.expTicksUsed = sumArray(this.tickables.map(exp));
205
- return this.expTicksUsed;
206
- }
207
-
208
- /** Get the softmax-scaled value of a tick duration. 'tickValue' is a number. */
209
- softmax(tickValue: number): number {
210
- if (!this.expTicksUsed) {
211
- this.expTicksUsed = this.reCalculateExpTicksUsed();
212
- }
213
-
214
- const totalTicks = this.ticksUsed.value();
215
- const exp = (v: number) => Math.pow(this.options.softmaxFactor, v / totalTicks);
216
- const sm = exp(tickValue) / this.expTicksUsed;
217
- return sm;
218
- }
219
-
220
- /** Add a tickable to the voice. */
221
- addTickable(tickable: Tickable): this {
222
- if (!tickable.shouldIgnoreTicks()) {
223
- const ticks = tickable.getTicks();
224
-
225
- // Update the total ticks for this line.
226
- this.ticksUsed.add(ticks);
227
- this.expTicksUsed = 0; // reset
228
-
229
- if (
230
- (this.mode === VoiceMode.STRICT || this.mode === VoiceMode.FULL) &&
231
- this.ticksUsed.greaterThan(this.totalTicks)
232
- ) {
233
- this.ticksUsed.subtract(ticks);
234
- throw new RuntimeError('BadArgument', 'Too many ticks.');
235
- }
236
-
237
- // Track the smallest tickable for formatting.
238
- if (ticks.lessThan(this.smallestTickCount)) {
239
- this.smallestTickCount = ticks.clone();
240
- }
241
-
242
- this.resolutionMultiplier = this.ticksUsed.denominator;
243
-
244
- // Expand total ticks using denominator from ticks used.
245
- this.totalTicks.add(0, this.ticksUsed.denominator);
246
- }
247
-
248
- // Add the tickable to the line.
249
- this.tickables.push(tickable);
250
- tickable.setVoice(this);
251
- return this;
252
- }
253
-
254
- /** Add an array of tickables to the voice. */
255
- addTickables(tickables: Tickable[]): this {
256
- for (let i = 0; i < tickables.length; ++i) {
257
- this.addTickable(tickables[i]);
258
- }
259
- return this;
260
- }
261
-
262
- /** Preformat the voice by applying the voice's stave to each note. */
263
- preFormat(): this {
264
- if (this.preFormatted) return this;
265
- const stave = this.checkStave();
266
- this.tickables.forEach((tickable) => {
267
- if (!tickable.getStave()) {
268
- tickable.setStave(stave);
269
- }
270
- });
271
- this.preFormatted = true;
272
- return this;
273
- }
274
-
275
- checkStave(): Stave {
276
- return defined(this.stave, 'NoStave', 'No stave attached to instance.');
277
- }
278
-
279
- /**
280
- * Render the voice onto the canvas `context` and an optional `stave`.
281
- * If `stave` is omitted, it is expected that the notes have staves
282
- * already set.
283
- *
284
- * This method also calculates the voice's boundingBox while drawing
285
- * the notes. Note the similarities with this.getBoundingBox().
286
- */
287
- draw(context: RenderContext = this.checkContext(), stave?: Stave): void {
288
- stave = stave ?? this.stave;
289
- this.setRendered();
290
- for (let i = 0; i < this.tickables.length; ++i) {
291
- const tickable = this.tickables[i];
292
- // Set the stave if provided.
293
- if (stave) {
294
- tickable.setStave(stave);
295
- }
296
- defined(tickable.getStave(), 'MissingStave', 'The voice cannot draw tickables without staves.');
297
-
298
- tickable.setContext(context);
299
- tickable.drawWithStyle();
300
- }
301
- }
302
- }
package/src/web.ts DELETED
@@ -1,35 +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
- // Utilities for working with Web APIs.
6
- // See: https://developer.mozilla.org/en-US/docs/Web/API
7
-
8
- import { globalObject } from './util';
9
-
10
- // eslint-disable-next-line
11
- export function isHTMLCanvas(element: any): element is HTMLCanvasElement {
12
- if (!element) return false;
13
-
14
- const global = globalObject();
15
- return (
16
- // It's either an instance of the HTMLCanvasElement class,
17
- (typeof global.HTMLCanvasElement === 'function' && element instanceof global.HTMLCanvasElement) ||
18
- // OR it's pretending to be a <canvas> element. Good enough!
19
- // Do not rely on .tagName, because node-canvas doesn't provide a tagName.
20
- (typeof element.getContext === 'function' && typeof element.toDataURL === 'function')
21
- );
22
- }
23
-
24
- // eslint-disable-next-line
25
- export function isHTMLDiv(element: any): element is HTMLDivElement {
26
- if (!element) return false;
27
-
28
- const global = globalObject();
29
- return (
30
- // It's either an instance of the HTMLDivElement class.
31
- (typeof global.HTMLDivElement === 'function' && element instanceof global.HTMLDivElement) ||
32
- // OR it's pretending to be a <div>. See: svgcontext.ts.
33
- (typeof element.appendChild === 'function' && typeof element.style === 'object')
34
- );
35
- }