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/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
- }