vexflow-native 2.4.0 → 2.5.0

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 (160) hide show
  1. package/README.md +7 -1
  2. package/lib/module/base/FontManager.js +41 -27
  3. package/lib/module/base/FontManager.js.map +1 -1
  4. package/lib/module/base/VexflowCanvas.js +8 -6
  5. package/lib/module/base/VexflowCanvas.js.map +1 -1
  6. package/lib/module/base/VexflowRecordingClone.js +83 -0
  7. package/lib/module/base/VexflowRecordingClone.js.map +1 -0
  8. package/lib/module/base/VexflowRecordingContext.js +1 -80
  9. package/lib/module/base/VexflowRecordingContext.js.map +1 -1
  10. package/lib/module/base/builtInTextFont.js +21 -0
  11. package/lib/module/base/builtInTextFont.js.map +1 -0
  12. package/lib/module/base/cssFontShorthand.js +34 -0
  13. package/lib/module/base/cssFontShorthand.js.map +1 -0
  14. package/lib/module/base/fonts/OFL.txt +93 -0
  15. package/lib/module/base/fonts/academico.js +12 -0
  16. package/lib/module/base/fonts/academico.js.map +1 -0
  17. package/lib/module/base/pictureRetirement.js +70 -0
  18. package/lib/module/base/pictureRetirement.js.map +1 -0
  19. package/lib/module/base/setupVexflowReactNative.js +1 -36
  20. package/lib/module/base/setupVexflowReactNative.js.map +1 -1
  21. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +22 -119
  22. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
  23. package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js +129 -0
  24. package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js.map +1 -0
  25. package/lib/module/musicxml/MusicXmlParser/PartParser.js +8 -1
  26. package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -1
  27. package/lib/module/musicxml/MusicXmlParser/Spanners.js +8 -5
  28. package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -1
  29. package/lib/module/musicxml/MusicXmlParser/mappers.js +83 -3
  30. package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
  31. package/lib/module/renderer/Layout/DocumentLayout.js +13 -4
  32. package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
  33. package/lib/module/renderer/Layout/VerticalSpacing.js +37 -7
  34. package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -1
  35. package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js +80 -46
  36. package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js.map +1 -1
  37. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +10 -22
  38. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
  39. package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +18 -8
  40. package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -1
  41. package/lib/module/renderer/ScoreRenderer/utils.js +42 -88
  42. package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
  43. package/lib/module/renderer/constants.js +1 -1
  44. package/lib/module/renderer/layout.js +7 -3
  45. package/lib/module/renderer/layout.js.map +1 -1
  46. package/lib/module/renderer/lyrics.js +127 -0
  47. package/lib/module/renderer/lyrics.js.map +1 -0
  48. package/lib/module/renderer/measure.js +11 -9
  49. package/lib/module/renderer/measure.js.map +1 -1
  50. package/lib/module/renderer/measureBounds.js +5 -0
  51. package/lib/module/renderer/measureBounds.js.map +1 -1
  52. package/lib/module/renderer/measureModifiers.js +24 -6
  53. package/lib/module/renderer/measureModifiers.js.map +1 -1
  54. package/lib/module/renderer/noteModifiers.js +5 -13
  55. package/lib/module/renderer/noteModifiers.js.map +1 -1
  56. package/lib/module/renderer/{fixedNoteSpacing.js → noteSpacing.js} +46 -10
  57. package/lib/module/renderer/noteSpacing.js.map +1 -0
  58. package/lib/module/renderer/render.js +37 -20
  59. package/lib/module/renderer/render.js.map +1 -1
  60. package/lib/typescript/src/base/FontManager.d.ts +12 -7
  61. package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
  62. package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -1
  63. package/lib/typescript/src/base/VexflowRecordingClone.d.ts +8 -0
  64. package/lib/typescript/src/base/VexflowRecordingClone.d.ts.map +1 -0
  65. package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
  66. package/lib/typescript/src/base/builtInTextFont.d.ts +6 -0
  67. package/lib/typescript/src/base/builtInTextFont.d.ts.map +1 -0
  68. package/lib/typescript/src/base/cssFontShorthand.d.ts +3 -0
  69. package/lib/typescript/src/base/cssFontShorthand.d.ts.map +1 -0
  70. package/lib/typescript/src/base/fonts/academico.d.ts +5 -0
  71. package/lib/typescript/src/base/fonts/academico.d.ts.map +1 -0
  72. package/lib/typescript/src/base/pictureRetirement.d.ts +26 -0
  73. package/lib/typescript/src/base/pictureRetirement.d.ts.map +1 -0
  74. package/lib/typescript/src/base/setupVexflowReactNative.d.ts +0 -8
  75. package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -1
  76. package/lib/typescript/src/base/types.d.ts.map +1 -1
  77. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +4 -1
  78. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -1
  79. package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -1
  80. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlNotes.d.ts +13 -0
  81. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlNotes.d.ts.map +1 -0
  82. package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -1
  83. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +6 -0
  84. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -1
  85. package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +7 -1
  86. package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
  87. package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
  88. package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +6 -0
  89. package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -1
  90. package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts +1 -1
  91. package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts.map +1 -1
  92. package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
  93. package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +1 -0
  94. package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -1
  95. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +14 -11
  96. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
  97. package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +8 -27
  98. package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
  99. package/lib/typescript/src/renderer/layout.d.ts +4 -1
  100. package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
  101. package/lib/typescript/src/renderer/lyrics.d.ts +42 -0
  102. package/lib/typescript/src/renderer/lyrics.d.ts.map +1 -0
  103. package/lib/typescript/src/renderer/measure.d.ts +2 -2
  104. package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
  105. package/lib/typescript/src/renderer/measureBounds.d.ts +3 -0
  106. package/lib/typescript/src/renderer/measureBounds.d.ts.map +1 -1
  107. package/lib/typescript/src/renderer/measureModifiers.d.ts +14 -4
  108. package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
  109. package/lib/typescript/src/renderer/noteModifiers.d.ts +2 -1
  110. package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -1
  111. package/lib/typescript/src/renderer/{fixedNoteSpacing.d.ts → noteSpacing.d.ts} +9 -1
  112. package/lib/typescript/src/renderer/noteSpacing.d.ts.map +1 -0
  113. package/lib/typescript/src/renderer/render.d.ts.map +1 -1
  114. package/lib/typescript/src/renderer/types.d.ts +17 -7
  115. package/lib/typescript/src/renderer/types.d.ts.map +1 -1
  116. package/lib/typescript/src/state/types.d.ts +8 -2
  117. package/lib/typescript/src/state/types.d.ts.map +1 -1
  118. package/package.json +34 -26
  119. package/src/base/FontManager.ts +50 -31
  120. package/src/base/VexflowCanvas.tsx +10 -10
  121. package/src/base/VexflowRecordingClone.ts +89 -0
  122. package/src/base/VexflowRecordingContext.ts +8 -81
  123. package/src/base/builtInTextFont.ts +25 -0
  124. package/src/base/cssFontShorthand.ts +45 -0
  125. package/src/base/fonts/OFL.txt +93 -0
  126. package/src/base/fonts/academico.ts +10 -0
  127. package/src/base/pictureRetirement.ts +74 -0
  128. package/src/base/setupVexflowReactNative.ts +1 -49
  129. package/src/base/types.ts +0 -3
  130. package/src/musicxml/MusicXmlParser/InternalTypes.ts +5 -0
  131. package/src/musicxml/MusicXmlParser/MeasureParser.ts +31 -182
  132. package/src/musicxml/MusicXmlParser/MusicXmlNotes.ts +198 -0
  133. package/src/musicxml/MusicXmlParser/PartParser.ts +10 -3
  134. package/src/musicxml/MusicXmlParser/Spanners.ts +11 -8
  135. package/src/musicxml/MusicXmlParser/mappers.ts +55 -6
  136. package/src/renderer/Layout/DocumentLayout.ts +12 -3
  137. package/src/renderer/Layout/VerticalSpacing.ts +46 -13
  138. package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +127 -66
  139. package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +8 -23
  140. package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +16 -2
  141. package/src/renderer/ScoreRenderer/types.ts +14 -12
  142. package/src/renderer/ScoreRenderer/utils.ts +54 -125
  143. package/src/renderer/constants.ts +1 -1
  144. package/src/renderer/layout.ts +15 -4
  145. package/src/renderer/lyrics.ts +163 -0
  146. package/src/renderer/measure.tsx +16 -9
  147. package/src/renderer/measureBounds.ts +10 -0
  148. package/src/renderer/measureModifiers.ts +27 -7
  149. package/src/renderer/noteModifiers.ts +8 -9
  150. package/src/renderer/{fixedNoteSpacing.ts → noteSpacing.ts} +60 -9
  151. package/src/renderer/render.tsx +51 -25
  152. package/src/renderer/types.ts +17 -7
  153. package/src/state/types.ts +8 -2
  154. package/lib/module/renderer/fixedNoteSpacing.js.map +0 -1
  155. package/lib/module/utils.js +0 -44
  156. package/lib/module/utils.js.map +0 -1
  157. package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts.map +0 -1
  158. package/lib/typescript/src/utils.d.ts +0 -1
  159. package/lib/typescript/src/utils.d.ts.map +0 -1
  160. package/src/utils.tsx +0 -42
@@ -25,6 +25,7 @@ import type {
25
25
  Pitch,
26
26
  } from '../state';
27
27
  import { renderOptions } from './constants';
28
+ import { Lyric, verseOf } from './lyrics';
28
29
  import { durationToVF, pitchToVFKey } from './vfKeys';
29
30
 
30
31
  /**
@@ -65,8 +66,6 @@ const DYNAMIC_FONT_SIZE = 30;
65
66
 
66
67
  const ANNOTATION_FONT = { size: 10, weight: 'bold' };
67
68
 
68
- const LYRIC_FONT = { size: 10, weight: 'normal' };
69
-
70
69
  const DIRECTION_FONT = { size: 11, weight: 'bold' };
71
70
 
72
71
  /** `GhostNote`s have no glyphs, so their element box is the origin. */
@@ -141,13 +140,14 @@ function verticalJustification(placement: 'above' | 'below') {
141
140
  }
142
141
 
143
142
  function byVerse(left: LyricAttachment, right: LyricAttachment) {
144
- return (left.verse ?? -Infinity) - (right.verse ?? -Infinity);
143
+ return verseOf(left) - verseOf(right);
145
144
  }
146
145
 
147
146
  /**
148
147
  * Attaches the owner's marks to a VexFlow note in a fixed order regardless of
149
148
  * the attachments' order: articulations, annotations, dynamics, lyrics (by
150
- * verse), grace notes. Same-side marks stack outward in that order.
149
+ * verse), grace notes. Same-side marks stack outward in that order, except
150
+ * lyrics, which sit on their staff's verse lines (`lyrics.ts`).
151
151
  */
152
152
  export function applyNoteModifiers(
153
153
  note: StaveNote,
@@ -203,11 +203,10 @@ export function applyNoteModifiers(
203
203
  )
204
204
  .sort(byVerse)
205
205
  .forEach((attachment) => {
206
- const lyric = new VFAnnotation(attachment.text);
207
-
208
- lyric.setFont({ family: textFontFamily, ...LYRIC_FONT });
209
- lyric.setVerticalJustification(AnnotationVerticalJustify.BOTTOM);
210
- note.addModifier(lyric, 0);
206
+ note.addModifier(
207
+ new Lyric(attachment.text, verseOf(attachment), textFontFamily),
208
+ 0
209
+ );
211
210
  });
212
211
 
213
212
  for (const attachment of attachments) {
@@ -45,22 +45,16 @@ export function applyFixedNoteSpacing(
45
45
  const multiplier = contexts.resolutionMultiplier || 1;
46
46
  const lastTick = lastTickKey / multiplier;
47
47
 
48
- // Tick context x is relative to noteStartX + the stave's left note padding
49
- // (see Tickable.getAbsoluteX), so the usable span ends at noteEndX. The
50
- // padding is derived from Stave statics because the `Metrics` module is not
51
- // re-exported by every vexflow build.
52
- const stavePadding = Stave.defaultPadding - Stave.rightPadding;
53
- const noteAreaWidth =
54
- stave.getNoteEndX() - stave.getNoteStartX() - stavePadding;
48
+ const areaWidth = noteAreaWidth(stave);
55
49
  const firstLeft = contexts.map[contexts.list[0]!]!.getMetrics().totalLeftPx;
56
- let span = noteAreaWidth - firstLeft;
50
+ let span = areaWidth - firstLeft;
57
51
 
58
52
  const lastContext = contexts.map[lastTickKey]!;
59
53
  const lastOverflow =
60
54
  firstLeft +
61
55
  (lastTick / totalTicks) * span +
62
56
  lastContext.getWidth() -
63
- noteAreaWidth;
57
+ areaWidth;
64
58
 
65
59
  if (lastOverflow > 0) {
66
60
  span -= (lastOverflow * totalTicks) / lastTick;
@@ -76,3 +70,60 @@ export function applyFixedNoteSpacing(
76
70
  );
77
71
  }
78
72
  }
73
+
74
+ /**
75
+ * Compresses the tick contexts linearly, anchored at the first one, when
76
+ * VexFlow's minimum widths run any of them past the note area. The anchor
77
+ * keeps a centre-aligned rest's centre shift valid; beams post-format after
78
+ * this, so they and modifiers follow the final positions. Returns the
79
+ * applied factor, 1 when nothing moved.
80
+ */
81
+ export function squeezeNoteSpacing(formatter: Formatter, stave: Stave) {
82
+ const contexts = formatter.getTickContexts();
83
+
84
+ if (!contexts) {
85
+ return 1;
86
+ }
87
+
88
+ const areaWidth = noteAreaWidth(stave);
89
+ const firstX = contexts.map[contexts.list[0]!]?.getX() ?? 0;
90
+ let scale = 1;
91
+
92
+ for (const tickKey of contexts.list) {
93
+ const context = contexts.map[tickKey]!;
94
+ const offset = context.getX() - firstX;
95
+
96
+ if (offset > 0) {
97
+ scale = Math.min(
98
+ scale,
99
+ (areaWidth - context.getWidth() - firstX) / offset
100
+ );
101
+ }
102
+ }
103
+
104
+ if (scale >= 1 || !(scale > 0)) {
105
+ return 1;
106
+ }
107
+
108
+ for (const tickKey of contexts.list) {
109
+ const context = contexts.map[tickKey]!;
110
+
111
+ context.setX(firstX + (context.getX() - firstX) * scale);
112
+ }
113
+
114
+ return scale;
115
+ }
116
+
117
+ /**
118
+ * Width a tick context x may span: x is relative to noteStartX + the stave's
119
+ * left note padding (see Tickable.getAbsoluteX), so the area ends at
120
+ * noteEndX. The padding is derived from Stave statics because the `Metrics`
121
+ * module is not re-exported by every vexflow build.
122
+ */
123
+ function noteAreaWidth(stave: Stave) {
124
+ return (
125
+ stave.getNoteEndX() -
126
+ stave.getNoteStartX() -
127
+ (Stave.defaultPadding - Stave.rightPadding)
128
+ );
129
+ }
@@ -15,13 +15,16 @@ import type {
15
15
  ScoreLayoutPlan,
16
16
  } from './layout';
17
17
  import {
18
+ alignNoteStarts,
18
19
  applyMeasureModifiers,
20
+ getFormatReferenceStave,
19
21
  resolveMeasureModifiers,
20
22
  } from './measureModifiers';
21
23
  import { indexAttachmentsByOwner, makeVFVoice } from './scoreParsing';
22
- import { applyFixedNoteSpacing } from './fixedNoteSpacing';
23
24
  import { itemLayoutOf } from './itemLayout';
25
+ import { placeLyrics } from './lyrics';
24
26
  import { hasNoteHeads } from './noteModifiers';
27
+ import { applyFixedNoteSpacing, squeezeNoteSpacing } from './noteSpacing';
25
28
  import { applyStaffLines, visibleLineYs } from './stave';
26
29
  import { drawTempoMarks } from './tempoMark';
27
30
  import type { ScoreItemHooks, ScoreItemsLayout, ScoreOptions } from './types';
@@ -161,6 +164,7 @@ function renderMeasure(
161
164
  }));
162
165
  const vfVoices = voiceArtifacts.map(({ vfVoice }) => vfVoice);
163
166
 
167
+ centreMeasureRest(voiceArtifacts);
164
168
  formatter.joinVoices(vfVoices);
165
169
 
166
170
  return {
@@ -193,7 +197,7 @@ function renderMeasure(
193
197
  staff.lines
194
198
  );
195
199
 
196
- applyMeasureModifiers(
200
+ return applyMeasureModifiers(
197
201
  stave,
198
202
  resolveMeasureModifiers(
199
203
  measure,
@@ -202,14 +206,13 @@ function renderMeasure(
202
206
  ),
203
207
  resolvedState
204
208
  );
205
- stave.setContext(ctx).draw();
206
- return stave;
207
209
  });
208
- const renderedStaveByStaffId = new Map(
209
- group.staves.map((staff, staffIndex) => [
210
- staff.id,
211
- renderedStaves[staffIndex],
212
- ])
210
+
211
+ alignNoteStarts(renderedStaves);
212
+ renderedStaves.forEach((stave) => stave.setContext(ctx).draw());
213
+
214
+ const staffIndexById = new Map(
215
+ group.staves.map((staff, staffIndex) => [staff.id, staffIndex])
213
216
  );
214
217
 
215
218
  renderStaffConnectors(ctx, group, renderedStaves, options);
@@ -217,26 +220,31 @@ function renderMeasure(
217
220
  staffRenderArtifacts.forEach(({ voiceArtifacts }) => {
218
221
  voiceArtifacts.forEach(({ items, notes, ownerStaffId }) => {
219
222
  items.forEach((item, index) => {
220
- const targetStave =
221
- renderedStaveByStaffId.get(item.targetStaffId ?? ownerStaffId) ??
222
- renderedStaveByStaffId.get(ownerStaffId);
223
+ const staffIndex =
224
+ staffIndexById.get(item.targetStaffId ?? ownerStaffId) ??
225
+ staffIndexById.get(ownerStaffId);
226
+ const note = notes[index];
223
227
 
224
- if (targetStave) {
225
- notes[index]?.setStave(targetStave);
228
+ if (staffIndex === undefined || !note) {
229
+ return;
226
230
  }
231
+
232
+ note.setStave(renderedStaves[staffIndex]!);
233
+ placeLyrics(note, measurePlan.verseBaselines?.[staffIndex]);
227
234
  });
228
235
  });
229
236
  });
230
237
 
238
+ let noteSpacingScale = 1;
239
+
231
240
  if (allVoices.length > 0) {
232
- // Format against the stave with the narrowest note area, so notes never
233
- // overrun a stave whose clef or time signature pushes its note start
234
- // further right.
235
241
  const referenceStave = getFormatReferenceStave(renderedStaves);
236
242
  formatter.formatToStave(allVoices, referenceStave);
237
243
 
238
- if (options.fixedNoteSpacing && referenceStave) {
244
+ if (options.fixedNoteSpacing) {
239
245
  applyFixedNoteSpacing(formatter, allVoices, referenceStave);
246
+ } else {
247
+ noteSpacingScale = squeezeNoteSpacing(formatter, referenceStave);
240
248
  }
241
249
  }
242
250
 
@@ -272,17 +280,33 @@ function renderMeasure(
272
280
  options.textFontFamily,
273
281
  itemsLayout.tempoMarks
274
282
  );
275
- collectMeasureLayout(itemsLayout, measurePlan, group.staves, renderedStaves);
283
+ collectMeasureLayout(
284
+ itemsLayout,
285
+ measurePlan,
286
+ group.staves,
287
+ renderedStaves,
288
+ noteSpacingScale
289
+ );
276
290
  }
277
291
 
278
292
  /**
279
- * The stave with the narrowest note area — formatting to it keeps notes
280
- * inside every stave of the group.
293
+ * A staff measure whose only visible item is a rest holds a measure rest,
294
+ * engraved centred in the bar. Hidden and spacer rests don't count.
281
295
  */
282
- function getFormatReferenceStave(renderedStaves: Stave[]): Stave {
283
- return renderedStaves.reduce((reference, stave) =>
284
- stave.getNoteStartX() > reference.getNoteStartX() ? stave : reference
296
+ function centreMeasureRest(
297
+ voiceArtifacts: Array<{ items: VoiceItem[]; notes: VFVoiceNote[] }>
298
+ ) {
299
+ const visible = voiceArtifacts.flatMap(({ items, notes }) =>
300
+ items.flatMap((item, index) =>
301
+ item.type !== 'rest' || (item.kind ?? 'visible') === 'visible'
302
+ ? [{ item, note: notes[index]! }]
303
+ : []
304
+ )
285
305
  );
306
+
307
+ if (visible.length === 1 && visible[0]!.item.type === 'rest') {
308
+ visible[0]!.note.setCenterAlignment(true);
309
+ }
286
310
  }
287
311
 
288
312
  /**
@@ -293,7 +317,8 @@ function collectMeasureLayout(
293
317
  itemsLayout: ScoreItemsLayout,
294
318
  measurePlan: MeasureLayoutPlan,
295
319
  staves: GroupLayoutContext['staves'],
296
- renderedStaves: Stave[]
320
+ renderedStaves: Stave[],
321
+ noteSpacingScale: number
297
322
  ) {
298
323
  staves.forEach((staff, staffIndex) => {
299
324
  const stave = renderedStaves[staffIndex];
@@ -316,6 +341,7 @@ function collectMeasureLayout(
316
341
  staveLineTopY: stave.getTopLineTopY(),
317
342
  staveLineBottomY: stave.getBottomLineBottomY(),
318
343
  visibleLineYs: visibleLineYs(stave, staff.lines),
344
+ ...(noteSpacingScale < 1 ? { noteSpacingScale } : {}),
319
345
  });
320
346
  });
321
347
  }
@@ -172,9 +172,11 @@ export interface ScoreSpacing {
172
172
  */
173
173
  lastSystemFill: 'justify' | 'natural';
174
174
  /**
175
- * Draw the clef on the first measure of every system instead of the first
176
- * measure of the score only; line breaking reserves its width. A measure
177
- * with `leftModifiers.showClef: false` still hides it. Default false.
175
+ * Draw the clef and key signature on the first measure of every system, as
176
+ * engraving convention repeats them; line breaking reserves their width.
177
+ * `false` draws them on the first measure of the score only. A measure's
178
+ * explicit `leftModifiers.showClef` / `showKeySignature` still wins.
179
+ * Default true.
178
180
  */
179
181
  clefOnEachSystem: boolean;
180
182
  }
@@ -200,7 +202,9 @@ export interface RenderOptions {
200
202
  /**
201
203
  * Font family list for the text drawn on a score: annotations, lyrics and
202
204
  * text directions. A family the font provider holds is taken from it;
203
- * otherwise the system font manager resolves the list. Default
205
+ * otherwise the system font manager resolves the list. Without system fonts
206
+ * (CanvasKit on the web) a list naming no provider family draws with the
207
+ * built-in Academico face, VexFlow's default text font. Default
204
208
  * `Arial, Helvetica, sans-serif`.
205
209
  */
206
210
  textFontFamily: string;
@@ -256,8 +260,8 @@ export interface ScoreItemBounds {
256
260
 
257
261
  /**
258
262
  * Geometry of one rendered stave of a measure. Entries of the same measure
259
- * share `x`/`width`, but note bounds are per stave — clef and time signature
260
- * can differ between the staves of a group.
263
+ * share `x`/`width` and `staveNoteStartX` (notes of a group start after its
264
+ * widest clef, key and time signature block); `staveNoteEndX` is per stave.
261
265
  */
262
266
  export interface ScoreMeasureItemsLayout {
263
267
  groupId: string;
@@ -268,7 +272,7 @@ export interface ScoreMeasureItemsLayout {
268
272
  x: number;
269
273
  /** Stave width. */
270
274
  width: number;
271
- /** X where notes may start on this stave (after its clef/meter). */
275
+ /** X where notes start, shared by every stave of the measure's group. */
272
276
  staveNoteStartX: number;
273
277
  /** X where the note area of this stave ends. */
274
278
  staveNoteEndX: number;
@@ -288,6 +292,12 @@ export interface ScoreMeasureItemsLayout {
288
292
  * read the drawn line from here. Always emitted by the renderer.
289
293
  */
290
294
  visibleLineYs?: number[];
295
+ /**
296
+ * Factor the measure's note spacing was compressed by to fit its note area;
297
+ * absent when uncompressed. Re-engrave at a smaller `render.scale` to avoid
298
+ * the crowding.
299
+ */
300
+ noteSpacingScale?: number;
291
301
  }
292
302
 
293
303
  /** Geometry of one drawn tempo mark, same space as {@link ScoreItemsLayout}. */
@@ -190,11 +190,17 @@ export interface MeasureState {
190
190
  }
191
191
 
192
192
  export interface MeasureLeftModifiers {
193
- /** undefined = shown on the first measure only; false hides it there too. */
193
+ /**
194
+ * undefined = shown on the first measure and at every system start
195
+ * (`spacing.clefOnEachSystem`); false hides it there too.
196
+ */
194
197
  showClef?: boolean;
195
198
  /** undefined = hidden. */
196
199
  showMeter?: boolean;
197
- /** undefined = hidden; never drawn on a percussion clef. */
200
+ /**
201
+ * undefined = shown where the clef is by default; false hides it there too.
202
+ * Never drawn on a percussion clef.
203
+ */
198
204
  showKeySignature?: boolean;
199
205
  /** undefined = 'single'; only 'single' and 'repeat-begin' render here. */
200
206
  startBarline?: Barline;
@@ -1 +0,0 @@
1
- {"version":3,"names":["Stave","applyFixedNoteSpacing","formatter","voices","stave","contexts","getTickContexts","lastTickKey","list","length","undefined","totalTicks","getTotalTicks","value","multiplier","resolutionMultiplier","lastTick","stavePadding","defaultPadding","rightPadding","noteAreaWidth","getNoteEndX","getNoteStartX","firstLeft","map","getMetrics","totalLeftPx","span","lastContext","lastOverflow","getWidth","tickKey","setX"],"sourceRoot":"../../../src","sources":["renderer/fixedNoteSpacing.ts"],"mappings":";;AAAA,SAASA,KAAK,QAAQ,SAAS;AAG/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,SAAoB,EACpBC,MAAiB,EACjBC,KAAY,EACZ;EACA,MAAMC,QAAQ,GAAGH,SAAS,CAACI,eAAe,CAAC,CAAC;EAC5C,MAAMC,WAAW,GAAGF,QAAQ,EAAEG,IAAI,CAACH,QAAQ,CAACG,IAAI,CAACC,MAAM,GAAG,CAAC,CAAC;EAE5D,IACE,CAACJ,QAAQ,IACTF,MAAM,CAACM,MAAM,KAAK,CAAC,IACnBF,WAAW,KAAKG,SAAS,IACzBH,WAAW,IAAI,CAAC,EAChB;IACA;EACF;EAEA,MAAMI,UAAU,GAAGR,MAAM,CAAC,CAAC,CAAC,EAAES,aAAa,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,IAAI,CAAC;EAE1D,IAAI,EAAEF,UAAU,GAAG,CAAC,CAAC,EAAE;IACrB;EACF;;EAEA;EACA;EACA;EACA;EACA;EACA,MAAMG,UAAU,GAAGT,QAAQ,CAACU,oBAAoB,IAAI,CAAC;EACrD,MAAMC,QAAQ,GAAGT,WAAW,GAAGO,UAAU;;EAEzC;EACA;EACA;EACA;EACA,MAAMG,YAAY,GAAGjB,KAAK,CAACkB,cAAc,GAAGlB,KAAK,CAACmB,YAAY;EAC9D,MAAMC,aAAa,GACjBhB,KAAK,CAACiB,WAAW,CAAC,CAAC,GAAGjB,KAAK,CAACkB,aAAa,CAAC,CAAC,GAAGL,YAAY;EAC5D,MAAMM,SAAS,GAAGlB,QAAQ,CAACmB,GAAG,CAACnB,QAAQ,CAACG,IAAI,CAAC,CAAC,CAAC,CAAE,CAAEiB,UAAU,CAAC,CAAC,CAACC,WAAW;EAC3E,IAAIC,IAAI,GAAGP,aAAa,GAAGG,SAAS;EAEpC,MAAMK,WAAW,GAAGvB,QAAQ,CAACmB,GAAG,CAACjB,WAAW,CAAE;EAC9C,MAAMsB,YAAY,GAChBN,SAAS,GACRP,QAAQ,GAAGL,UAAU,GAAIgB,IAAI,GAC9BC,WAAW,CAACE,QAAQ,CAAC,CAAC,GACtBV,aAAa;EAEf,IAAIS,YAAY,GAAG,CAAC,EAAE;IACpBF,IAAI,IAAKE,YAAY,GAAGlB,UAAU,GAAIK,QAAQ;EAChD;EAEA,IAAI,EAAEW,IAAI,GAAG,CAAC,CAAC,EAAE;IACf;EACF;EAEA,KAAK,MAAMI,OAAO,IAAI1B,QAAQ,CAACG,IAAI,EAAE;IACnCH,QAAQ,CAACmB,GAAG,CAACO,OAAO,CAAC,CAAEC,IAAI,CACzBT,SAAS,GAAIQ,OAAO,GAAGjB,UAAU,GAAGH,UAAU,GAAIgB,IACpD,CAAC;EACH;AACF","ignoreList":[]}
@@ -1,44 +0,0 @@
1
- // import { PT_TO_PX } from './constants';
2
- // import { type ParsedCssFont } from './types';
3
-
4
- // export function toPxFontSize(size: number | string | undefined): number {
5
- // if (size === undefined || size === null) return 12;
6
-
7
- // if (typeof size === 'number' && Number.isFinite(size)) {
8
- // return size * PT_TO_PX;
9
- // }
10
-
11
- // if (typeof size === 'string') {
12
- // const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt)?$/i);
13
-
14
- // if (match) {
15
- // const value = Number.parseFloat(match[1] || '12');
16
- // const unit = match[2]?.toLowerCase();
17
- // if (!unit || unit === 'px') return value;
18
- // return value * PT_TO_PX;
19
- // }
20
- // }
21
-
22
- // return 12;
23
- // }
24
-
25
- // export function parseCssFontShorthand(cssFont: string): ParsedCssFont {
26
- // const sizeMatch = cssFont.match(/(\d+(?:\.\d+)?(?:px|pt))/i);
27
-
28
- // if (!sizeMatch) {
29
- // return { sizePx: 12 };
30
- // }
31
-
32
- // const sizePx = toPxFontSize(sizeMatch[1]);
33
-
34
- // const family = cssFont
35
- // .slice((sizeMatch.index ?? 0) + (sizeMatch[1]?.length || 0))
36
- // .trim();
37
-
38
- // return {
39
- // sizePx,
40
- // family: family || undefined,
41
- // };
42
- // }
43
- "use strict";
44
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["utils.tsx"],"mappings":"AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fixedNoteSpacing.d.ts","sourceRoot":"","sources":["../../../../src/renderer/fixedNoteSpacing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,EAAE,EACjB,KAAK,EAAE,KAAK,QA0Db"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.tsx"],"names":[],"mappings":""}
package/src/utils.tsx DELETED
@@ -1,42 +0,0 @@
1
- // import { PT_TO_PX } from './constants';
2
- // import { type ParsedCssFont } from './types';
3
-
4
- // export function toPxFontSize(size: number | string | undefined): number {
5
- // if (size === undefined || size === null) return 12;
6
-
7
- // if (typeof size === 'number' && Number.isFinite(size)) {
8
- // return size * PT_TO_PX;
9
- // }
10
-
11
- // if (typeof size === 'string') {
12
- // const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt)?$/i);
13
-
14
- // if (match) {
15
- // const value = Number.parseFloat(match[1] || '12');
16
- // const unit = match[2]?.toLowerCase();
17
- // if (!unit || unit === 'px') return value;
18
- // return value * PT_TO_PX;
19
- // }
20
- // }
21
-
22
- // return 12;
23
- // }
24
-
25
- // export function parseCssFontShorthand(cssFont: string): ParsedCssFont {
26
- // const sizeMatch = cssFont.match(/(\d+(?:\.\d+)?(?:px|pt))/i);
27
-
28
- // if (!sizeMatch) {
29
- // return { sizePx: 12 };
30
- // }
31
-
32
- // const sizePx = toPxFontSize(sizeMatch[1]);
33
-
34
- // const family = cssFont
35
- // .slice((sizeMatch.index ?? 0) + (sizeMatch[1]?.length || 0))
36
- // .trim();
37
-
38
- // return {
39
- // sizePx,
40
- // family: family || undefined,
41
- // };
42
- // }