vexflow-native 2.1.0 → 2.2.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 (57) hide show
  1. package/README.md +1 -1
  2. package/lib/module/renderer/Layout/DocumentLayout.js +36 -32
  3. package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
  4. package/lib/module/renderer/Layout/LayoutMetrics.js +7 -1
  5. package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -1
  6. package/lib/module/renderer/constants.js +4 -1
  7. package/lib/module/renderer/constants.js.map +1 -1
  8. package/lib/module/renderer/engraveScore.js +202 -0
  9. package/lib/module/renderer/engraveScore.js.map +1 -0
  10. package/lib/module/renderer/index.js +1 -0
  11. package/lib/module/renderer/index.js.map +1 -1
  12. package/lib/module/renderer/layout.js +4 -1
  13. package/lib/module/renderer/layout.js.map +1 -1
  14. package/lib/module/renderer/measure.js +12 -3
  15. package/lib/module/renderer/measure.js.map +1 -1
  16. package/lib/module/renderer/measureModifiers.js +5 -4
  17. package/lib/module/renderer/measureModifiers.js.map +1 -1
  18. package/lib/module/renderer/render.js +2 -1
  19. package/lib/module/renderer/render.js.map +1 -1
  20. package/lib/module/renderer/systemExtents.js +104 -0
  21. package/lib/module/renderer/systemExtents.js.map +1 -0
  22. package/lib/module/renderer/useScoreRecording.js +19 -109
  23. package/lib/module/renderer/useScoreRecording.js.map +1 -1
  24. package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
  25. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +2 -2
  26. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -1
  27. package/lib/typescript/src/renderer/constants.d.ts.map +1 -1
  28. package/lib/typescript/src/renderer/engraveScore.d.ts +101 -0
  29. package/lib/typescript/src/renderer/engraveScore.d.ts.map +1 -0
  30. package/lib/typescript/src/renderer/index.d.ts +1 -0
  31. package/lib/typescript/src/renderer/index.d.ts.map +1 -1
  32. package/lib/typescript/src/renderer/layout.d.ts +1 -0
  33. package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
  34. package/lib/typescript/src/renderer/measure.d.ts +5 -0
  35. package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
  36. package/lib/typescript/src/renderer/measureModifiers.d.ts +4 -3
  37. package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
  38. package/lib/typescript/src/renderer/render.d.ts.map +1 -1
  39. package/lib/typescript/src/renderer/systemExtents.d.ts +15 -0
  40. package/lib/typescript/src/renderer/systemExtents.d.ts.map +1 -0
  41. package/lib/typescript/src/renderer/types.d.ts +25 -0
  42. package/lib/typescript/src/renderer/types.d.ts.map +1 -1
  43. package/lib/typescript/src/renderer/useScoreRecording.d.ts +3 -20
  44. package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/renderer/Layout/DocumentLayout.ts +65 -33
  47. package/src/renderer/Layout/LayoutMetrics.ts +9 -2
  48. package/src/renderer/constants.ts +3 -0
  49. package/src/renderer/engraveScore.ts +338 -0
  50. package/src/renderer/index.ts +6 -0
  51. package/src/renderer/layout.ts +5 -2
  52. package/src/renderer/measure.tsx +27 -3
  53. package/src/renderer/measureModifiers.ts +7 -4
  54. package/src/renderer/render.tsx +7 -1
  55. package/src/renderer/systemExtents.ts +134 -0
  56. package/src/renderer/types.ts +25 -0
  57. package/src/renderer/useScoreRecording.ts +27 -176
@@ -0,0 +1,15 @@
1
+ import type { VexflowRecordingCommand } from '../base';
2
+ import type FontManager from '../base/FontManager';
3
+ interface VerticalBand {
4
+ y: number;
5
+ height: number;
6
+ }
7
+ /**
8
+ * Grows each band to cover everything the recording draws for it. A command
9
+ * belongs to the band its vertical centre is in, or else the nearest one.
10
+ * Curve control points count as drawn, so a band can come out slightly taller
11
+ * than its ink, never shorter.
12
+ */
13
+ export declare function coverDrawnExtents<Band extends VerticalBand>(bands: readonly Band[], commands: readonly VexflowRecordingCommand[], fontManager: FontManager): Band[];
14
+ export {};
15
+ //# sourceMappingURL=systemExtents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"systemExtents.d.ts","sourceRoot":"","sources":["../../../../src/renderer/systemExtents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AAQnD,UAAU,YAAY;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,YAAY,EACzD,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,WAAW,EAAE,WAAW,GACvB,IAAI,EAAE,CAqBR"}
@@ -129,6 +129,31 @@ export interface ScoreSpacing {
129
129
  * rows of two renderers laid out side by side stay aligned. Default false.
130
130
  */
131
131
  uniformSystemPitch: boolean;
132
+ /**
133
+ * `document` only: indent of the first system of each staff group, in
134
+ * content units (before `render.scale`). That system starts later and is
135
+ * narrower by the same amount. Default 0.
136
+ */
137
+ firstSystemIndent: number;
138
+ /**
139
+ * Vertical gap between systems in content units, clamped to >= 0. With
140
+ * `uniformSystemPitch` the pitch is the shared system height plus this gap.
141
+ * Undefined or non-finite = the built-in `max(82, staffGap / 8)`.
142
+ */
143
+ systemGap?: number;
144
+ /**
145
+ * `document` only: `justify` stretches the last system of each staff group
146
+ * to the full width like every other system; `natural` keeps its intrinsic
147
+ * width (a one-system score counts as its own last system). `documentEven`
148
+ * never stretches a partial last system. Default `justify`.
149
+ */
150
+ lastSystemFill: 'justify' | 'natural';
151
+ /**
152
+ * Draw the clef on the first measure of every system instead of the first
153
+ * measure of the score only; line breaking reserves its width. A measure
154
+ * with `leftModifiers.showClef: false` still hides it. Default false.
155
+ */
156
+ clefOnEachSystem: boolean;
132
157
  }
133
158
  export interface RenderOptions {
134
159
  /** Currently unused — reserved for future raster-density control. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/renderer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,UAAU,GAAG,cAAc,CAAC;AACzE,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC1D,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAE7E;2CAC2C;AAC3C,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,UAAU,CAAC;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AM,EAAE,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACvC,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,WAAW,EAAE,YAAY,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAa,SAAQ,aAAa,EAAE,YAAY;CAAG;AAEpE,MAAM,WAAW,eAAgB,SAAQ,YAAY;CAAG"}
@@ -1,26 +1,9 @@
1
1
  import type { SkTypefaceFontProvider } from 'react-native-skia';
2
- import type { VexflowRecordingCommand } from '../base';
3
- import { type VexflowRecordingGroupIndex } from '../base/VexflowRecordingIndex';
4
2
  import type { Score } from '../state';
5
- import { type ScoreLayoutPlan } from './layout';
6
3
  import type { ResolvedScoreColorScheme } from './colorScheme';
7
- import type { RendererRect, RendererType, ScoreItemHooks, ScoreItemsLayout, ScoreOptions } from './types';
8
- export interface ScoreRecording {
9
- /** Recorded draw commands, content-space coordinates. */
10
- commands: readonly VexflowRecordingCommand[];
11
- /**
12
- * `commands` bucketed by `groupId` so a style-override replay can redraw
13
- * just the overridden items instead of the whole recording.
14
- */
15
- groupIndex: VexflowRecordingGroupIndex;
16
- /**
17
- * Layout plan in content space; multiply its `contentSize` by the render
18
- * scale for the view-space size that drives scrolling.
19
- */
20
- layoutPlan: ScoreLayoutPlan;
21
- /** Emitted geometry, already converted to view space. */
22
- itemsLayout: ScoreItemsLayout;
23
- }
4
+ import { type ScoreRecording } from './engraveScore';
5
+ import type { RendererRect, RendererType, ScoreItemHooks, ScoreOptions } from './types';
6
+ /** Memoised `engraveScore` pipeline for a mounted renderer. */
24
7
  export declare function useScoreRecording({ decorateItem, defaultFont, enabled, fontManager, colorScheme, onDrawItem, options, rendererType, score, viewport, }: ScoreItemHooks & {
25
8
  defaultFont: string;
26
9
  enabled?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useScoreRecording.d.ts","sourceRoot":"","sources":["../../../../src/renderer/useScoreRecording.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,UAAU,CAAC;AAQlB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;IAC7C;;;OAGG;IACH,UAAU,EAAE,0BAA0B,CAAC;IACvC;;;OAGG;IACH,UAAU,EAAE,eAAe,CAAC;IAC5B,yDAAyD;IACzD,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,WAAW,EACX,OAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EACL,QAAQ,GACT,EAAE,cAAc,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,sBAAsB,CAAC;IACpC,WAAW,EAAE,wBAAwB,CAAC;IACtC,OAAO,EAAE,YAAY,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,GAAG,cAAc,CAkHjB"}
1
+ {"version":3,"file":"useScoreRecording.d.ts","sourceRoot":"","sources":["../../../../src/renderer/useScoreRecording.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EAEd,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,WAAW,EACX,OAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EACL,QAAQ,GACT,EAAE,cAAc,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,sBAAsB,CAAC;IACpC,WAAW,EAAE,wBAAwB,CAAC;IACtC,OAAO,EAAE,YAAY,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,GAAG,cAAc,CAmEjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vexflow-native",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "React Native backend for rendering music notation using react-native-skia",
5
5
  "main": "./lib/module/base/index.js",
6
6
  "types": "./lib/typescript/src/base/index.d.ts",
@@ -16,6 +16,8 @@ import {
16
16
  type DocumentLine = {
17
17
  measures: MeasuredGroupMeasure[];
18
18
  intrinsicWidth: number;
19
+ availableWidth: number;
20
+ indent: number;
19
21
  };
20
22
 
21
23
  export function resolveDocumentEvenMeasureWidth(
@@ -34,11 +36,24 @@ export function resolveDocumentEvenMeasureWidth(
34
36
  };
35
37
  }
36
38
 
37
- const measuresPerFullLine = Math.max(
39
+ let measuresPerFullLine = Math.max(
38
40
  1,
39
41
  Math.floor(availableWidth / widestMeasure)
40
42
  );
41
43
 
44
+ // A clef added at a system start has to fit the equal measure width too.
45
+ while (
46
+ measuresPerFullLine > 1 &&
47
+ measuredScore.measures.some(
48
+ (measure) =>
49
+ measure.measureIndex % measuresPerFullLine === 0 &&
50
+ measure.intrinsicNoteWidth + (measure.systemStartClefWidth ?? 0) >
51
+ availableWidth / measuresPerFullLine
52
+ )
53
+ ) {
54
+ measuresPerFullLine -= 1;
55
+ }
56
+
42
57
  return {
43
58
  measuresPerFullLine,
44
59
  equalMeasureWidth: availableWidth / measuresPerFullLine,
@@ -66,7 +81,7 @@ export function layoutDocumentEvenGroup(
66
81
  }
67
82
 
68
83
  let cursorY = origin.y;
69
- const systemGap = getSystemGap(options.spacing.staffGap);
84
+ const systemGap = getSystemGap(options.spacing);
70
85
  const chunks: MeasuredGroupMeasure[][] = [];
71
86
 
72
87
  for (
@@ -158,24 +173,35 @@ export function layoutDocumentGroup(
158
173
  };
159
174
  }
160
175
 
161
- const lines = splitDocumentLines(group.measures, availableWidth);
176
+ const { firstSystemIndent, lastSystemFill } = options.spacing;
177
+ const lines = splitDocumentLines(
178
+ group.measures,
179
+ availableWidth,
180
+ firstSystemIndent
181
+ );
162
182
  let cursorY = origin.y;
163
- const systemGap = getSystemGap(options.spacing.staffGap);
183
+ const systemGap = getSystemGap(options.spacing);
164
184
 
165
185
  for (const [systemIndex, line] of lines.entries()) {
166
- const lineWidth = availableWidth > 0 ? availableWidth : line.intrinsicWidth;
186
+ const fullWidth =
187
+ line.availableWidth > 0 ? line.availableWidth : line.intrinsicWidth;
188
+ const lineWidth =
189
+ lastSystemFill === 'natural' && systemIndex === lines.length - 1
190
+ ? Math.min(fullWidth, line.intrinsicWidth)
191
+ : fullWidth;
167
192
  const stretchRatio = lineWidth / line.intrinsicWidth;
168
193
  const verticalLayout = resolveSystemVerticalLayout(
169
194
  line.measures,
170
195
  group.staves.length,
171
196
  options.spacing.staffGap
172
197
  );
173
- let cursorX = origin.x;
198
+ const systemX = origin.x + line.indent;
199
+ let cursorX = systemX;
174
200
 
175
201
  systems.push({
176
202
  groupId: group.groupId,
177
203
  systemIndex,
178
- x: origin.x,
204
+ x: systemX,
179
205
  y: cursorY,
180
206
  width: lineWidth,
181
207
  height: verticalLayout.height,
@@ -184,8 +210,11 @@ export function layoutDocumentGroup(
184
210
  measureIndices: line.measures.map((measure) => measure.measureIndex),
185
211
  });
186
212
 
187
- for (const measure of line.measures) {
188
- const width = getMeasureLineWidth(measure) * stretchRatio;
213
+ for (const [lineIndex, measure] of line.measures.entries()) {
214
+ const width =
215
+ (lineIndex === 0
216
+ ? getSystemStartWidth(measure)
217
+ : getMeasureLineWidth(measure)) * stretchRatio;
189
218
 
190
219
  measures.push({
191
220
  groupId: group.groupId,
@@ -214,40 +243,39 @@ export function layoutDocumentGroup(
214
243
 
215
244
  function splitDocumentLines(
216
245
  measures: MeasuredGroupMeasure[],
217
- availableWidth: number
246
+ availableWidth: number,
247
+ firstSystemIndent: number
218
248
  ): DocumentLine[] {
219
249
  const lines: DocumentLine[] = [];
220
- let lineMeasures: MeasuredGroupMeasure[] = [];
221
- let lineWidth = 0;
250
+ let line: DocumentLine | undefined;
222
251
 
223
252
  for (const measure of measures) {
224
253
  const measureWidth = getMeasureLineWidth(measure);
225
254
 
226
- if (lineMeasures.length === 0) {
227
- lineMeasures = [measure];
228
- lineWidth = measureWidth;
229
- continue;
230
- }
231
-
232
- if (availableWidth > 0 && lineWidth + measureWidth > availableWidth) {
233
- lines.push({
234
- measures: lineMeasures,
235
- intrinsicWidth: lineWidth,
236
- });
237
- lineMeasures = [measure];
238
- lineWidth = measureWidth;
255
+ if (
256
+ line &&
257
+ !(
258
+ line.availableWidth > 0 &&
259
+ line.intrinsicWidth + measureWidth > line.availableWidth
260
+ )
261
+ ) {
262
+ line.measures.push(measure);
263
+ line.intrinsicWidth += measureWidth;
239
264
  continue;
240
265
  }
241
266
 
242
- lineMeasures.push(measure);
243
- lineWidth += measureWidth;
244
- }
267
+ const indent =
268
+ lines.length === 0 && firstSystemIndent < availableWidth
269
+ ? firstSystemIndent
270
+ : 0;
245
271
 
246
- if (lineMeasures.length > 0) {
247
- lines.push({
248
- measures: lineMeasures,
249
- intrinsicWidth: lineWidth,
250
- });
272
+ line = {
273
+ measures: [measure],
274
+ intrinsicWidth: getSystemStartWidth(measure),
275
+ availableWidth: availableWidth - indent,
276
+ indent,
277
+ };
278
+ lines.push(line);
251
279
  }
252
280
 
253
281
  return lines;
@@ -256,3 +284,7 @@ function splitDocumentLines(
256
284
  function getMeasureLineWidth(measure: MeasuredGroupMeasure): number {
257
285
  return Math.max(measure.intrinsicWidth, 1);
258
286
  }
287
+
288
+ function getSystemStartWidth(measure: MeasuredGroupMeasure): number {
289
+ return getMeasureLineWidth(measure) + (measure.systemStartClefWidth ?? 0);
290
+ }
@@ -1,4 +1,4 @@
1
- import type { RendererRect, ScoreOptions } from '../types';
1
+ import type { RendererRect, ScoreOptions, ScoreSpacing } from '../types';
2
2
 
3
3
  const MIN_SYSTEM_GAP = 82;
4
4
  const SYSTEM_GAP_DIVISOR = 8;
@@ -16,6 +16,13 @@ export function getAvailableDocumentWidth(
16
16
  );
17
17
  }
18
18
 
19
- export function getSystemGap(staffGap: number): number {
19
+ export function getSystemGap({
20
+ staffGap,
21
+ systemGap,
22
+ }: Pick<ScoreSpacing, 'staffGap' | 'systemGap'>): number {
23
+ if (systemGap !== undefined && Number.isFinite(systemGap)) {
24
+ return Math.max(0, systemGap);
25
+ }
26
+
20
27
  return Math.max(MIN_SYSTEM_GAP, staffGap / SYSTEM_GAP_DIVISOR);
21
28
  }
@@ -11,6 +11,9 @@ export const spacing: ScoreSpacing = {
11
11
  staffGap: 96,
12
12
  minIntrinsicSizeMultiplier: 2,
13
13
  uniformSystemPitch: false,
14
+ firstSystemIndent: 0,
15
+ lastSystemFill: 'justify',
16
+ clefOnEachSystem: false,
14
17
  };
15
18
 
16
19
  export const renderOptions: RenderOptions = {
@@ -0,0 +1,338 @@
1
+ import type { SkTypefaceFontProvider } from 'react-native-skia';
2
+
3
+ import type { VexflowRecordingCommand } from '../base';
4
+ import FontManager from '../base/FontManager';
5
+ import VexflowRecordingContext from '../base/VexflowRecordingContext';
6
+ import {
7
+ buildVexflowGroupIndex,
8
+ type VexflowRecordingGroupIndex,
9
+ } from '../base/VexflowRecordingIndex';
10
+ import type { Score } from '../state';
11
+ import { isVexflowNativeDebugEnabled } from '../shared/debug';
12
+ import {
13
+ resolveScoreColorScheme,
14
+ type ResolvedScoreColorScheme,
15
+ type ScoreColorScheme,
16
+ } from './colorScheme';
17
+ import { layoutScore, type ScoreLayoutPlan } from './layout';
18
+ import { measureScore, type MeasuredScore } from './measure';
19
+ import { renderScore } from './render';
20
+ import {
21
+ createContentViewport,
22
+ getRenderScale,
23
+ scaleItemsLayoutToViewSpace,
24
+ } from './scale';
25
+ import { withDefaultOptions } from './ScoreRenderer/utils';
26
+ import { coverDrawnExtents } from './systemExtents';
27
+ import type {
28
+ RendererRect,
29
+ RendererSize,
30
+ RendererType,
31
+ ScoreItemHooks,
32
+ ScoreItemsLayout,
33
+ ScoreOptions,
34
+ ScoreRendererOptions,
35
+ } from './types';
36
+
37
+ export interface EngraveScoreParams extends ScoreItemHooks {
38
+ score: Score;
39
+ defaultFont: string;
40
+ fontManager: SkTypefaceFontProvider;
41
+ colorScheme?: ScoreColorScheme;
42
+ options?: ScoreRendererOptions;
43
+ /** Default `document`. */
44
+ rendererType?: RendererType;
45
+ /** View-space width the score is laid out against. */
46
+ width: number;
47
+ /**
48
+ * View-space height. Only `infiniteScore`, which centers on it, and a
49
+ * score without measures read it. Default 0.
50
+ */
51
+ height?: number;
52
+ }
53
+
54
+ /** One system of an engraving, in content space. */
55
+ export interface ScoreSystemLayout {
56
+ groupId: string;
57
+ /** Index within the staff group. */
58
+ systemIndex: number;
59
+ x: number;
60
+ width: number;
61
+ /**
62
+ * `y`/`height` cover the system's layout band and everything drawn for it
63
+ * (clefs, ledger lines, stems, modifiers, text), so clipping the commands
64
+ * to this band cuts nothing off.
65
+ */
66
+ y: number;
67
+ height: number;
68
+ measureIndices: number[];
69
+ }
70
+
71
+ export interface ScoreEngraving {
72
+ /**
73
+ * Display list in content space (VexFlow units before `render.scale`);
74
+ * replay it with `renderVexflowRecordingCommands`.
75
+ */
76
+ commands: readonly VexflowRecordingCommand[];
77
+ /** Content space; multiply by `render.scale` for view space. */
78
+ contentSize: RendererSize;
79
+ /** Top to bottom per staff group. */
80
+ systems: ScoreSystemLayout[];
81
+ /** View space, the value `ScoreRenderer` passes to `onItemsLayout`. */
82
+ itemsLayout: ScoreItemsLayout;
83
+ }
84
+
85
+ /**
86
+ * Engraves a score to a display list without mounting a view, for print,
87
+ * export or custom drawing. Same pipeline and output as `ScoreRenderer`.
88
+ */
89
+ export function engraveScore({
90
+ score,
91
+ defaultFont,
92
+ fontManager,
93
+ colorScheme,
94
+ options: userOptions = {},
95
+ rendererType = 'document',
96
+ width,
97
+ height = 0,
98
+ decorateItem,
99
+ onDrawItem,
100
+ }: EngraveScoreParams): ScoreEngraving {
101
+ const options = withDefaultOptions(userOptions);
102
+ const { commands, layoutPlan, itemsLayout } = recordScore({
103
+ measurement: measureScoreRecording({
104
+ score,
105
+ options,
106
+ fontManager,
107
+ defaultFont,
108
+ decorateItem,
109
+ }),
110
+ score,
111
+ options,
112
+ rendererType,
113
+ viewport: { x: 0, y: 0, width, height },
114
+ fontManager,
115
+ defaultFont,
116
+ colorScheme: resolveScoreColorScheme(colorScheme),
117
+ decorateItem,
118
+ onDrawItem,
119
+ });
120
+
121
+ return {
122
+ commands,
123
+ contentSize: layoutPlan.contentSize,
124
+ systems: coverDrawnExtents(
125
+ layoutPlan.systems.map(
126
+ (system): ScoreSystemLayout => ({
127
+ groupId: system.groupId,
128
+ systemIndex: system.systemIndex,
129
+ x: system.x,
130
+ width: system.width,
131
+ y: system.y,
132
+ height: system.height,
133
+ measureIndices: system.measureIndices,
134
+ })
135
+ ),
136
+ commands,
137
+ new FontManager(fontManager, defaultFont)
138
+ ),
139
+ itemsLayout,
140
+ };
141
+ }
142
+
143
+ export interface ScoreMeasurement {
144
+ measuredScore: MeasuredScore;
145
+ measureMs: number;
146
+ }
147
+
148
+ export interface ScoreRecording {
149
+ /** Recorded draw commands, content-space coordinates. */
150
+ commands: readonly VexflowRecordingCommand[];
151
+ /**
152
+ * `commands` bucketed by `groupId` so a style-override replay can redraw
153
+ * just the overridden items instead of the whole recording.
154
+ */
155
+ groupIndex: VexflowRecordingGroupIndex;
156
+ /**
157
+ * Layout plan in content space; multiply its `contentSize` by the render
158
+ * scale for the view-space size that drives scrolling.
159
+ */
160
+ layoutPlan: ScoreLayoutPlan;
161
+ /** Emitted geometry, already converted to view space. */
162
+ itemsLayout: ScoreItemsLayout;
163
+ }
164
+
165
+ /**
166
+ * The measuring pass. It does not depend on the viewport and is the most
167
+ * expensive pass, so callers that re-layout cache it apart from
168
+ * {@link recordScore}.
169
+ */
170
+ export function measureScoreRecording({
171
+ score,
172
+ options,
173
+ fontManager,
174
+ defaultFont,
175
+ decorateItem,
176
+ }: Pick<ScoreItemHooks, 'decorateItem'> & {
177
+ score: Score;
178
+ options: ScoreOptions;
179
+ fontManager: SkTypefaceFontProvider;
180
+ defaultFont: string;
181
+ }): ScoreMeasurement {
182
+ const measureStart = nowMs();
183
+ // On native, constructing a context installs it as VexFlow's text
184
+ // measurement canvas, so text is measured with this font setup.
185
+ // eslint-disable-next-line no-new
186
+ new VexflowRecordingContext(fontManager, defaultFont);
187
+ const measuredScore = measureScore(score, options, { decorateItem });
188
+
189
+ return { measuredScore, measureMs: nowMs() - measureStart };
190
+ }
191
+
192
+ /** Layout and render passes; `viewport` is view space. */
193
+ export function recordScore({
194
+ measurement,
195
+ score,
196
+ options,
197
+ rendererType,
198
+ viewport,
199
+ fontManager,
200
+ defaultFont,
201
+ colorScheme,
202
+ decorateItem,
203
+ onDrawItem,
204
+ }: ScoreItemHooks & {
205
+ measurement: ScoreMeasurement;
206
+ score: Score;
207
+ options: ScoreOptions;
208
+ rendererType: RendererType;
209
+ viewport: RendererRect;
210
+ fontManager: SkTypefaceFontProvider;
211
+ defaultFont: string;
212
+ colorScheme: ResolvedScoreColorScheme;
213
+ }): ScoreRecording {
214
+ // Layout and render run in content space against the virtual viewport;
215
+ // see src/renderer/scale.ts.
216
+ const scale = getRenderScale(options);
217
+ const contentViewport = createContentViewport(viewport, scale);
218
+ const ctx = new VexflowRecordingContext(
219
+ fontManager,
220
+ defaultFont,
221
+ colorScheme
222
+ );
223
+
224
+ const layoutStart = nowMs();
225
+ const layoutPlan = layoutScore(
226
+ score,
227
+ measurement.measuredScore,
228
+ options,
229
+ rendererType,
230
+ contentViewport
231
+ );
232
+ const layoutMs = nowMs() - layoutStart;
233
+
234
+ const renderStart = nowMs();
235
+ const itemsLayout = scaleItemsLayoutToViewSpace(
236
+ renderScore(ctx, score, layoutPlan, options, {
237
+ decorateItem,
238
+ onDrawItem,
239
+ }),
240
+ scale
241
+ );
242
+ const renderMs = nowMs() - renderStart;
243
+
244
+ const finishStart = nowMs();
245
+ const commands = ctx.finish();
246
+ const groupIndex = buildVexflowGroupIndex(commands);
247
+ const finishMs = nowMs() - finishStart;
248
+
249
+ logScoreRecordingProfile({
250
+ commandCount: commands.length,
251
+ groupCount: Object.keys(groupIndex).length,
252
+ contentSize: layoutPlan.contentSize,
253
+ finishMs,
254
+ layoutMs,
255
+ measureCount: layoutPlan.measures.length,
256
+ measurement,
257
+ renderMs,
258
+ rendererType,
259
+ scoreId: score.id,
260
+ systemCount: layoutPlan.systems.length,
261
+ viewport,
262
+ });
263
+
264
+ return {
265
+ commands,
266
+ groupIndex,
267
+ layoutPlan,
268
+ itemsLayout,
269
+ };
270
+ }
271
+
272
+ /**
273
+ * Measurements already counted by a profile line. A cached measurement is
274
+ * reported once, by the first recording built on it, so summed profiles
275
+ * count each measure pass once.
276
+ */
277
+ const profiledMeasurements = new WeakSet<ScoreMeasurement>();
278
+
279
+ function logScoreRecordingProfile({
280
+ commandCount,
281
+ groupCount,
282
+ contentSize,
283
+ finishMs,
284
+ layoutMs,
285
+ measureCount,
286
+ measurement,
287
+ renderMs,
288
+ rendererType,
289
+ scoreId,
290
+ systemCount,
291
+ viewport,
292
+ }: {
293
+ commandCount: number;
294
+ groupCount: number;
295
+ contentSize: { height: number; width: number };
296
+ finishMs: number;
297
+ layoutMs: number;
298
+ measureCount: number;
299
+ measurement: ScoreMeasurement;
300
+ renderMs: number;
301
+ rendererType: RendererType;
302
+ scoreId: string;
303
+ systemCount: number;
304
+ viewport: RendererRect;
305
+ }) {
306
+ if (!isVexflowNativeDebugEnabled()) {
307
+ return;
308
+ }
309
+
310
+ const measureMs = profiledMeasurements.has(measurement)
311
+ ? 0
312
+ : measurement.measureMs;
313
+ profiledMeasurements.add(measurement);
314
+
315
+ console.info('[ScoreRenderer] recording profile', {
316
+ scoreId,
317
+ rendererType,
318
+ viewport,
319
+ contentSize,
320
+ measureCount,
321
+ systemCount,
322
+ commandCount,
323
+ groupCount,
324
+ measureMs: roundMs(measureMs),
325
+ layoutMs: roundMs(layoutMs),
326
+ renderMs: roundMs(renderMs),
327
+ finishMs: roundMs(finishMs),
328
+ totalMs: roundMs(measureMs + layoutMs + renderMs + finishMs),
329
+ });
330
+ }
331
+
332
+ function nowMs(): number {
333
+ return globalThis.performance?.now?.() ?? Date.now();
334
+ }
335
+
336
+ function roundMs(value: number): number {
337
+ return Math.round(value * 10) / 10;
338
+ }
@@ -1,4 +1,10 @@
1
1
  export { default as ScoreRenderer } from './ScoreRenderer';
2
+ export {
3
+ engraveScore,
4
+ type EngraveScoreParams,
5
+ type ScoreEngraving,
6
+ type ScoreSystemLayout,
7
+ } from './engraveScore';
2
8
  export * from './colorScheme';
3
9
  export * from './types';
4
10
  export {