vexflow-native 2.0.0 → 2.0.2

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 (27) hide show
  1. package/lib/module/base/VexflowRecordingReplay.js +118 -78
  2. package/lib/module/base/VexflowRecordingReplay.js.map +1 -1
  3. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +14 -5
  4. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
  5. package/lib/module/renderer/ScoreRenderer/utils.js +31 -12
  6. package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
  7. package/lib/module/renderer/layout.js +10 -0
  8. package/lib/module/renderer/layout.js.map +1 -1
  9. package/lib/module/renderer/useScoreRecording.js +50 -17
  10. package/lib/module/renderer/useScoreRecording.js.map +1 -1
  11. package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -1
  12. package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
  13. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +2 -2
  14. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
  15. package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +12 -7
  16. package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
  17. package/lib/typescript/src/renderer/layout.d.ts +7 -0
  18. package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
  19. package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/src/base/VexflowRecordingReplay.ts +193 -141
  22. package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +2 -2
  23. package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +18 -5
  24. package/src/renderer/ScoreRenderer/types.ts +2 -2
  25. package/src/renderer/ScoreRenderer/utils.ts +41 -18
  26. package/src/renderer/layout.ts +15 -0
  27. package/src/renderer/useScoreRecording.ts +71 -19
@@ -6,8 +6,10 @@ import {
6
6
  StrokeCap,
7
7
  type SkCanvas,
8
8
  type SkColor,
9
+ type SkImageFilter,
9
10
  type SkPaint,
10
11
  type SkPathBuilder,
12
+ type SkPathEffect,
11
13
  type SkTypefaceFontProvider,
12
14
  } from 'react-native-skia';
13
15
 
@@ -18,7 +20,6 @@ import type {
18
20
  VexflowRecordingLineCap,
19
21
  VexflowRecordingPaint,
20
22
  VexflowRecordingPathCommand,
21
- VexflowRecordingRect,
22
23
  VexflowStyleOverride,
23
24
  } from './VexflowRecordingTypes';
24
25
 
@@ -35,15 +36,27 @@ function shadowBlurToSigma(shadowBlur: number): number {
35
36
  }
36
37
 
37
38
  /**
38
- * Per-replay `css color -> SkColor` cache: a recording uses a handful of
39
- * distinct colors but references them thousands of times.
39
+ * Skia objects one replay call allocates once and reuses across its commands.
40
+ * A recording uses a handful of distinct colors, glows and dashes but
41
+ * references them thousands of times, so each is created on first use and
42
+ * cached by value. Everything here is disposed when the replay ends: under
43
+ * NativeState only GC would free it otherwise.
40
44
  */
41
- type SkColorCache = Record<string, SkColor>;
42
-
43
- function getCachedColor(color: string, cache: SkColorCache): SkColor {
45
+ type ReplayPool = {
46
+ colors: Record<string, SkColor>;
47
+ glows: Record<string, SkImageFilter>;
48
+ dashes: Record<string, SkPathEffect>;
49
+ fillPaint: SkPaint;
50
+ strokePaint: SkPaint;
51
+ /** Created on the first `clearRect`; most recordings never clear a rect. */
52
+ clearPaint: SkPaint | null;
53
+ pathBuilder: SkPathBuilder;
54
+ };
55
+
56
+ function getCachedColor(color: string, pool: ReplayPool): SkColor {
44
57
  'worklet';
45
58
 
46
- return (cache[color] ??= Skia.Color(color));
59
+ return (pool.colors[color] ??= Skia.Color(color));
47
60
  }
48
61
 
49
62
  /**
@@ -55,7 +68,7 @@ function getCachedColor(color: string, cache: SkColorCache): SkColor {
55
68
  function applyGlow(
56
69
  skPaint: SkPaint,
57
70
  paint: VexflowRecordingPaint,
58
- colorCache: SkColorCache
71
+ pool: ReplayPool
59
72
  ) {
60
73
  'worklet';
61
74
 
@@ -67,22 +80,34 @@ function applyGlow(
67
80
  }
68
81
 
69
82
  const sigma = shadowBlurToSigma(paint.shadowBlur ?? 0);
83
+ const key = `${paint.shadowColor}|${sigma}`;
70
84
 
71
85
  skPaint.setImageFilter(
72
- Skia.ImageFilter.MakeDropShadow(
86
+ (pool.glows[key] ??= Skia.ImageFilter.MakeDropShadow(
73
87
  0,
74
88
  0,
75
89
  sigma,
76
90
  sigma,
77
- getCachedColor(paint.shadowColor, colorCache)
78
- )
91
+ getCachedColor(paint.shadowColor, pool)
92
+ ))
79
93
  );
80
94
  }
81
95
 
82
- function toSkiaRect(rect: VexflowRecordingRect) {
96
+ function applyDash(
97
+ skPaint: SkPaint,
98
+ lineDash: number[] | undefined,
99
+ pool: ReplayPool
100
+ ) {
83
101
  'worklet';
84
102
 
85
- return Skia.XYWHRect(rect.x, rect.y, rect.width, rect.height);
103
+ if (lineDash == null || lineDash.length === 0) {
104
+ skPaint.setPathEffect(null);
105
+ return;
106
+ }
107
+
108
+ skPaint.setPathEffect(
109
+ (pool.dashes[lineDash.join(',')] ??= Skia.PathEffect.MakeDash(lineDash))
110
+ );
86
111
  }
87
112
 
88
113
  function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
@@ -106,67 +131,86 @@ function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
106
131
  * state (glow filter, dash effect) is explicitly reset on every configure so
107
132
  * nothing bleeds between commands.
108
133
  */
109
- function createPooledFillPaint(): SkPaint {
134
+ function createReplayPool(): ReplayPool {
110
135
  'worklet';
111
136
 
112
- const skPaint = Skia.Paint();
113
- skPaint.setStyle(PaintStyle.Fill);
114
- skPaint.setAntiAlias(true);
137
+ const fillPaint = Skia.Paint();
138
+ fillPaint.setStyle(PaintStyle.Fill);
139
+ fillPaint.setAntiAlias(true);
115
140
 
116
- return skPaint;
141
+ const strokePaint = Skia.Paint();
142
+ strokePaint.setStyle(PaintStyle.Stroke);
143
+ strokePaint.setAntiAlias(true);
144
+
145
+ return {
146
+ colors: {},
147
+ glows: {},
148
+ dashes: {},
149
+ fillPaint,
150
+ strokePaint,
151
+ clearPaint: null,
152
+ pathBuilder: Skia.PathBuilder.Make(),
153
+ };
117
154
  }
118
155
 
119
- function createPooledStrokePaint(): SkPaint {
156
+ /**
157
+ * Paints keep their own reference to an image filter / path effect, and a
158
+ * recorded picture copies the paint state it drew with, so disposing the JS
159
+ * handles here never invalidates what was drawn.
160
+ */
161
+ function disposeReplayPool(pool: ReplayPool) {
120
162
  'worklet';
121
163
 
122
- const skPaint = Skia.Paint();
123
- skPaint.setStyle(PaintStyle.Stroke);
124
- skPaint.setAntiAlias(true);
125
-
126
- return skPaint;
164
+ for (const key in pool.glows) {
165
+ pool.glows[key]!.dispose();
166
+ }
167
+ for (const key in pool.dashes) {
168
+ pool.dashes[key]!.dispose();
169
+ }
170
+ pool.fillPaint.dispose();
171
+ pool.strokePaint.dispose();
172
+ pool.clearPaint?.dispose();
173
+ pool.pathBuilder.dispose();
127
174
  }
128
175
 
129
176
  function configureFillPaint(
130
- skPaint: SkPaint,
131
177
  paint: VexflowRecordingPaint,
132
- colorCache: SkColorCache
178
+ pool: ReplayPool
133
179
  ): SkPaint {
134
180
  'worklet';
135
181
 
136
- skPaint.setColor(getCachedColor(paint.color, colorCache));
137
- applyGlow(skPaint, paint, colorCache);
182
+ const skPaint = pool.fillPaint;
183
+ skPaint.setColor(getCachedColor(paint.color, pool));
184
+ applyGlow(skPaint, paint, pool);
138
185
 
139
186
  return skPaint;
140
187
  }
141
188
 
142
189
  function configureStrokePaint(
143
- skPaint: SkPaint,
144
190
  paint: VexflowRecordingPaint,
145
- colorCache: SkColorCache
191
+ pool: ReplayPool
146
192
  ): SkPaint {
147
193
  'worklet';
148
194
 
149
- skPaint.setColor(getCachedColor(paint.color, colorCache));
195
+ const skPaint = pool.strokePaint;
196
+ skPaint.setColor(getCachedColor(paint.color, pool));
150
197
  skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
151
198
  skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
152
- applyGlow(skPaint, paint, colorCache);
153
-
154
- if (paint.lineDash != null && paint.lineDash.length > 0) {
155
- skPaint.setPathEffect(Skia.PathEffect.MakeDash(paint.lineDash));
156
- } else {
157
- skPaint.setPathEffect(null);
158
- }
199
+ applyGlow(skPaint, paint, pool);
200
+ applyDash(skPaint, paint.lineDash, pool);
159
201
 
160
202
  return skPaint;
161
203
  }
162
204
 
163
- function createClearPaint(): SkPaint {
205
+ function getClearPaint(pool: ReplayPool): SkPaint {
164
206
  'worklet';
165
207
 
166
- const clearPaint = Skia.Paint();
167
- clearPaint.setBlendMode(BlendMode.Clear);
208
+ if (pool.clearPaint == null) {
209
+ pool.clearPaint = Skia.Paint();
210
+ pool.clearPaint.setBlendMode(BlendMode.Clear);
211
+ }
168
212
 
169
- return clearPaint;
213
+ return pool.clearPaint;
170
214
  }
171
215
 
172
216
  type PaintKind = 'fill' | 'stroke';
@@ -261,14 +305,10 @@ function applyPathCommand(
261
305
  builder.quadTo(command.cpx, command.cpy, command.x, command.y);
262
306
  break;
263
307
  case 'addRect':
264
- builder.addRect(toSkiaRect(command.rect));
308
+ builder.addRect(command.rect);
265
309
  break;
266
310
  case 'addArc':
267
- builder.addArc(
268
- toSkiaRect(command.rect),
269
- command.startDegrees,
270
- command.sweepDegrees
271
- );
311
+ builder.addArc(command.rect, command.startDegrees, command.sweepDegrees);
272
312
  break;
273
313
  case 'close':
274
314
  builder.close();
@@ -278,16 +318,26 @@ function applyPathCommand(
278
318
  }
279
319
  }
280
320
 
281
- function buildPath(path: readonly VexflowRecordingPathCommand[]) {
321
+ /**
322
+ * Build the recorded path in the pooled builder (`detach` hands over the path
323
+ * and resets the builder for the next command), draw it, and free it at once:
324
+ * the canvas copies the path at the draw call.
325
+ */
326
+ function drawRecordedPath(
327
+ canvas: SkCanvas,
328
+ path: readonly VexflowRecordingPathCommand[],
329
+ skPaint: SkPaint,
330
+ builder: SkPathBuilder
331
+ ) {
282
332
  'worklet';
283
333
 
284
- const builder = Skia.PathBuilder.Make();
285
-
286
334
  for (const command of path) {
287
335
  applyPathCommand(builder, command);
288
336
  }
289
337
 
290
- return builder.build();
338
+ const skPath = builder.detach();
339
+ canvas.drawPath(skPath, skPaint);
340
+ skPath.dispose();
291
341
  }
292
342
 
293
343
  export function renderVexflowRecordingCommands(
@@ -314,98 +364,100 @@ export function renderVexflowRecordingCommands(
314
364
 
315
365
  const fontManager =
316
366
  replayFontManager ?? new FontManager(fontProvider, defaultFont);
317
- const colorCache: SkColorCache = {};
318
- const fillPaint = createPooledFillPaint();
319
- const strokePaint = createPooledStrokePaint();
320
-
321
- for (const command of commands) {
322
- switch (command.type) {
323
- case 'clear':
324
- canvas.clear(getCachedColor(command.color, colorCache));
325
- break;
326
- case 'save':
327
- canvas.save();
328
- break;
329
- case 'restore':
330
- canvas.restore();
331
- break;
332
- case 'scale':
333
- canvas.scale(command.x, command.y);
334
- break;
335
- case 'translate':
336
- canvas.translate(command.x, command.y);
337
- break;
338
- case 'clipRect':
339
- canvas.clipRect(toSkiaRect(command.rect), ClipOp.Intersect, true);
340
- break;
341
- case 'fillRect':
342
- canvas.drawRect(
343
- toSkiaRect(command.rect),
344
- configureFillPaint(
345
- fillPaint,
346
- resolveStyle(
347
- command.paint,
348
- command.groupId,
349
- 'fill',
350
- styleOverrides
351
- ),
352
- colorCache
353
- )
354
- );
355
- break;
356
- case 'clearRect':
357
- canvas.drawRect(toSkiaRect(command.rect), createClearPaint());
358
- break;
359
- case 'fillPath':
360
- canvas.drawPath(
361
- buildPath(command.path),
362
- configureFillPaint(
363
- fillPaint,
364
- resolveStyle(
365
- command.paint,
366
- command.groupId,
367
- 'fill',
368
- styleOverrides
367
+ const pool = createReplayPool();
368
+
369
+ try {
370
+ for (const command of commands) {
371
+ switch (command.type) {
372
+ case 'clear':
373
+ canvas.clear(getCachedColor(command.color, pool));
374
+ break;
375
+ case 'save':
376
+ canvas.save();
377
+ break;
378
+ case 'restore':
379
+ canvas.restore();
380
+ break;
381
+ case 'scale':
382
+ canvas.scale(command.x, command.y);
383
+ break;
384
+ case 'translate':
385
+ canvas.translate(command.x, command.y);
386
+ break;
387
+ case 'clipRect':
388
+ canvas.clipRect(command.rect, ClipOp.Intersect, true);
389
+ break;
390
+ case 'fillRect':
391
+ canvas.drawRect(
392
+ command.rect,
393
+ configureFillPaint(
394
+ resolveStyle(
395
+ command.paint,
396
+ command.groupId,
397
+ 'fill',
398
+ styleOverrides
399
+ ),
400
+ pool
401
+ )
402
+ );
403
+ break;
404
+ case 'clearRect':
405
+ canvas.drawRect(command.rect, getClearPaint(pool));
406
+ break;
407
+ case 'fillPath':
408
+ drawRecordedPath(
409
+ canvas,
410
+ command.path,
411
+ configureFillPaint(
412
+ resolveStyle(
413
+ command.paint,
414
+ command.groupId,
415
+ 'fill',
416
+ styleOverrides
417
+ ),
418
+ pool
369
419
  ),
370
- colorCache
371
- )
372
- );
373
- break;
374
- case 'strokePath':
375
- canvas.drawPath(
376
- buildPath(command.path),
377
- configureStrokePaint(
378
- strokePaint,
379
- resolveStyle(
380
- command.paint,
381
- command.groupId,
382
- 'stroke',
383
- styleOverrides
420
+ pool.pathBuilder
421
+ );
422
+ break;
423
+ case 'strokePath':
424
+ drawRecordedPath(
425
+ canvas,
426
+ command.path,
427
+ configureStrokePaint(
428
+ resolveStyle(
429
+ command.paint,
430
+ command.groupId,
431
+ 'stroke',
432
+ styleOverrides
433
+ ),
434
+ pool
384
435
  ),
385
- colorCache
386
- )
387
- );
388
- break;
389
- case 'fillText':
390
- canvas.drawText(
391
- command.text,
392
- command.x,
393
- command.y,
394
- configureFillPaint(
395
- fillPaint,
396
- resolveStyle(
397
- command.paint,
398
- command.groupId,
399
- 'fill',
400
- styleOverrides
436
+ pool.pathBuilder
437
+ );
438
+ break;
439
+ case 'fillText':
440
+ canvas.drawText(
441
+ command.text,
442
+ command.x,
443
+ command.y,
444
+ configureFillPaint(
445
+ resolveStyle(
446
+ command.paint,
447
+ command.groupId,
448
+ 'fill',
449
+ styleOverrides
450
+ ),
451
+ pool
401
452
  ),
402
- colorCache
403
- ),
404
- createFont(fontManager, command.font)
405
- );
406
- break;
407
- default:
408
- assertNever(command);
453
+ createFont(fontManager, command.font)
454
+ );
455
+ break;
456
+ default:
457
+ assertNever(command);
458
+ }
409
459
  }
460
+ } finally {
461
+ disposeReplayPool(pool);
410
462
  }
411
463
  }
@@ -6,9 +6,9 @@ import { scheduleOnUI } from 'react-native-worklets';
6
6
  import type { VexflowRecordingCommand } from '../../base';
7
7
  import { isVexflowNativeDebugEnabled } from '../../shared/debug';
8
8
  import type {
9
- OverlayDisposalState,
10
9
  OverlayFontManagerSlot,
11
10
  OverlayProfileState,
11
+ PictureDisposalState,
12
12
  ScoreOverlayPictureProps,
13
13
  } from './types';
14
14
  import {
@@ -43,7 +43,7 @@ export default function ScoreOverlayPicture({
43
43
  const fontManagerSlot = useSharedValue<OverlayFontManagerSlot>({
44
44
  manager: null,
45
45
  });
46
- const disposal = useSharedValue<OverlayDisposalState>({
46
+ const disposal = useSharedValue<PictureDisposalState>({
47
47
  prev: null,
48
48
  pending: [],
49
49
  });
@@ -18,9 +18,12 @@ import ScoreOverlayPicture from './ScoreOverlayPicture';
18
18
  import ScorePlayhead, { resolvePlayheadStyle } from './ScorePlayhead';
19
19
  import ScoreScrollbar from './ScoreScrollbar';
20
20
  import { getMaxScroll, getScrollAxis, useScoreScroll } from './useScoreScroll';
21
+ import type { PictureDisposalState } from './types';
21
22
  import {
22
23
  createPictureTransform,
23
24
  createScorePicture,
25
+ disposeRetiredPictures,
26
+ retirePicture,
24
27
  withDefaultOptions,
25
28
  } from './utils';
26
29
 
@@ -201,14 +204,24 @@ const ScoreRenderer: React.FC<ScoreRendererProps> = ({
201
204
  replayFontManager,
202
205
  ]);
203
206
 
204
- useEffect(() => {
205
- if (!picture) {
206
- return;
207
- }
207
+ const pictureDisposalRef = useRef<PictureDisposalState>({
208
+ prev: null,
209
+ pending: [],
210
+ });
208
211
 
209
- return () => picture.dispose();
212
+ useEffect(() => {
213
+ retirePicture(pictureDisposalRef.current, picture ?? null);
210
214
  }, [picture]);
211
215
 
216
+ useEffect(() => {
217
+ const disposal = pictureDisposalRef.current;
218
+
219
+ // Cleanup also runs when effects are torn down without unmounting
220
+ // (a hidden <Activity>, StrictMode), after which the memoized picture is
221
+ // drawn again — so the current picture is left to the GC.
222
+ return () => disposeRetiredPictures(disposal);
223
+ }, []);
224
+
212
225
  const onReadyRef = useRef(onReady);
213
226
 
214
227
  useEffect(() => {
@@ -39,8 +39,8 @@ export interface ScoreOverlayPictureProps {
39
39
  itemStyleOverrides: NonNullable<ScoreRendererProps['itemStyleOverrides']>;
40
40
  }
41
41
 
42
- export interface OverlayDisposalState {
43
- /** The last real (non-empty) overlay picture the mapper returned. */
42
+ export interface PictureDisposalState {
43
+ /** The current picture; null while none is shown (or the shared blank one). */
44
44
  prev: SkPicture | null;
45
45
  /** Superseded pictures awaiting disposal, oldest first. */
46
46
  pending: SkPicture[];
@@ -20,9 +20,9 @@ import type {
20
20
  import { createVisibleViewport } from '../viewport';
21
21
  import type {
22
22
  CreateScorePictureParams,
23
- OverlayDisposalState,
24
23
  OverlayFontManagerSlot,
25
24
  OverlayProfileState,
25
+ PictureDisposalState,
26
26
  } from './types';
27
27
 
28
28
  // The reanimated plugin rewrites 'worklet' function declarations into
@@ -185,26 +185,22 @@ export function getEmptyOverlayPicture(): SkPicture {
185
185
  }
186
186
 
187
187
  /**
188
- * Two-generation deferred disposal: the retiring picture may still be
189
- * referenced by the committed Picture node or a frame in flight, so only
190
- * pictures two supersessions old are disposed. The shared blank picture never
191
- * enters the ring (`next === null` marks an empty frame).
188
+ * Two-generation deferred disposal: react-native-skia commits the Canvas tree
189
+ * asynchronously, so a retiring picture may still be referenced by the
190
+ * committed Picture node or a commit in flight. Only pictures two
191
+ * supersessions old are disposed. `next === null` marks a frame without an
192
+ * owned picture (none, or the shared blank one), which never enters the ring.
192
193
  */
193
- export function retireOverlayPicture(
194
- disposal: SharedValue<OverlayDisposalState>,
194
+ export function retirePicture(
195
+ state: PictureDisposalState,
195
196
  next: SkPicture | null
196
197
  ) {
197
198
  'worklet';
198
199
 
199
- if (typeof _WORKLET === 'undefined' || !_WORKLET) {
200
- // The mapper's seed run happens on JS against a copy of the state; writes
201
- // here would never be seen by the UI runtime, so skip tracking entirely
202
- // (leaks at most one picture per mapper re-creation).
200
+ if (state.prev === next) {
203
201
  return;
204
202
  }
205
203
 
206
- const state = disposal.value;
207
-
208
204
  if (state.prev != null) {
209
205
  state.pending.push(state.prev);
210
206
 
@@ -216,22 +212,49 @@ export function retireOverlayPicture(
216
212
  state.prev = next;
217
213
  }
218
214
 
219
- export function disposeOverlayPictures(
220
- disposal: SharedValue<OverlayDisposalState>
221
- ) {
215
+ /** Disposes the superseded pictures only; the current one stays alive. */
216
+ export function disposeRetiredPictures(state: PictureDisposalState) {
222
217
  'worklet';
223
218
 
224
- const state = disposal.value;
225
-
226
219
  for (const pending of state.pending) {
227
220
  pending.dispose();
228
221
  }
229
222
  state.pending.length = 0;
223
+ }
224
+
225
+ export function disposePictures(state: PictureDisposalState) {
226
+ 'worklet';
227
+
228
+ disposeRetiredPictures(state);
230
229
 
231
230
  state.prev?.dispose();
232
231
  state.prev = null;
233
232
  }
234
233
 
234
+ export function retireOverlayPicture(
235
+ disposal: SharedValue<PictureDisposalState>,
236
+ next: SkPicture | null
237
+ ) {
238
+ 'worklet';
239
+
240
+ if (typeof _WORKLET === 'undefined' || !_WORKLET) {
241
+ // The mapper's seed run happens on JS against a copy of the state; writes
242
+ // here would never be seen by the UI runtime, so skip tracking entirely
243
+ // (leaks at most one picture per mapper re-creation).
244
+ return;
245
+ }
246
+
247
+ retirePicture(disposal.value, next);
248
+ }
249
+
250
+ export function disposeOverlayPictures(
251
+ disposal: SharedValue<PictureDisposalState>
252
+ ) {
253
+ 'worklet';
254
+
255
+ disposePictures(disposal.value);
256
+ }
257
+
235
258
  /** Throttled (≤1/s) UI-thread record timing; debug flag only. */
236
259
  export function logOverlayProfile(
237
260
  profile: SharedValue<OverlayProfileState>,
@@ -144,6 +144,21 @@ export function layoutScore(
144
144
  };
145
145
  }
146
146
 
147
+ /**
148
+ * Whether `layoutScore` reads `viewport.height` for this score. Only the
149
+ * infinite score centers on it; document layouts use it solely for the
150
+ * content size of a score with no measures. Callers can skip a re-layout on
151
+ * height-only viewport changes when this is false.
152
+ */
153
+ export function layoutUsesViewportHeight(
154
+ rendererType: RendererType,
155
+ measuredScore: MeasuredScore
156
+ ): boolean {
157
+ return (
158
+ rendererType === 'infiniteScore' || measuredScore.measures.length === 0
159
+ );
160
+ }
161
+
147
162
  function buildGroupLayoutContext(
148
163
  score: Score,
149
164
  measuredScore: MeasuredScore