vexflow-native 0.2.0 → 1.1.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.
- package/README.md +267 -37
- package/lib/module/base/FontManager.js +139 -0
- package/lib/module/base/FontManager.js.map +1 -0
- package/lib/module/base/TextMeasureContext.js +46 -0
- package/lib/module/base/TextMeasureContext.js.map +1 -0
- package/lib/module/base/VexflowCanvas.js +48 -0
- package/lib/module/base/VexflowCanvas.js.map +1 -0
- package/lib/module/base/VexflowColorScheme.js +16 -0
- package/lib/module/base/VexflowColorScheme.js.map +1 -0
- package/lib/module/base/VexflowRecordingContext.js +487 -0
- package/lib/module/base/VexflowRecordingContext.js.map +1 -0
- package/lib/module/base/VexflowRecordingReplay.js +214 -0
- package/lib/module/base/VexflowRecordingReplay.js.map +1 -0
- package/lib/module/base/VexflowRecordingTypes.js +4 -0
- package/lib/module/base/VexflowRecordingTypes.js.map +1 -0
- package/lib/module/base/index.js +9 -0
- package/lib/module/base/index.js.map +1 -0
- package/lib/module/base/setupVexflowReactNative.js +96 -0
- package/lib/module/base/setupVexflowReactNative.js.map +1 -0
- package/lib/module/base/types.js +4 -0
- package/lib/module/base/types.js.map +1 -0
- package/lib/module/base/utils.js +18 -0
- package/lib/module/base/utils.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/InternalTypes.js +4 -0
- package/lib/module/musicxml/MusicXmlParser/InternalTypes.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +269 -0
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js +62 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js +124 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js +41 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/Spanners.js +149 -0
- package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/XmlOrder.js +106 -0
- package/lib/module/musicxml/MusicXmlParser/XmlOrder.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/index.js +110 -0
- package/lib/module/musicxml/MusicXmlParser/index.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/mappers.js +312 -0
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/types.js +10 -0
- package/lib/module/musicxml/MusicXmlParser/types.js.map +1 -0
- package/lib/module/musicxml/index.js +4 -0
- package/lib/module/musicxml/index.js.map +1 -0
- package/lib/module/musicxml/testfiles/lg-8102429.xml +79620 -0
- package/lib/module/renderer/Layout/DocumentLayout.js +156 -0
- package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -0
- package/lib/module/renderer/Layout/LayoutMetrics.js +13 -0
- package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -0
- package/lib/module/renderer/Layout/VerticalSpacing.js +69 -0
- package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +277 -0
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +108 -0
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/index.js +7 -0
- package/lib/module/renderer/ScoreRenderer/index.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/types.js +4 -0
- package/lib/module/renderer/ScoreRenderer/types.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/useScoreScroll.js +77 -0
- package/lib/module/renderer/ScoreRenderer/useScoreScroll.js.map +1 -0
- package/lib/module/renderer/colorScheme.js +17 -0
- package/lib/module/renderer/colorScheme.js.map +1 -0
- package/lib/module/renderer/constants.js +18 -0
- package/lib/module/renderer/constants.js.map +1 -0
- package/lib/module/renderer/index.js +6 -0
- package/lib/module/renderer/index.js.map +1 -0
- package/lib/module/renderer/layout.js +153 -0
- package/lib/module/renderer/layout.js.map +1 -0
- package/lib/module/renderer/measure.js +202 -0
- package/lib/module/renderer/measure.js.map +1 -0
- package/lib/module/renderer/render.js +184 -0
- package/lib/module/renderer/render.js.map +1 -0
- package/lib/module/renderer/scoreParsing.js +230 -0
- package/lib/module/renderer/scoreParsing.js.map +1 -0
- package/lib/module/renderer/types.js +4 -0
- package/lib/module/renderer/types.js.map +1 -0
- package/lib/module/renderer/useScoreRecording.js +112 -0
- package/lib/module/renderer/useScoreRecording.js.map +1 -0
- package/lib/module/renderer/viewport.js +26 -0
- package/lib/module/renderer/viewport.js.map +1 -0
- package/lib/module/shared/Logger.js +67 -0
- package/lib/module/shared/Logger.js.map +1 -0
- package/lib/module/state/index.js +4 -0
- package/lib/module/state/index.js.map +1 -0
- package/lib/module/state/types.js +2 -0
- package/lib/module/state/types.js.map +1 -0
- package/lib/module/types.js +7 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +42 -77
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +23 -0
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -0
- package/lib/typescript/src/base/TextMeasureContext.d.ts +22 -0
- package/lib/typescript/src/base/TextMeasureContext.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowCanvas.d.ts +5 -0
- package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowColorScheme.d.ts +7 -0
- package/lib/typescript/src/base/VexflowColorScheme.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts +103 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +12 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts +146 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts.map +1 -0
- package/lib/typescript/src/base/index.d.ts +7 -0
- package/lib/typescript/src/base/index.d.ts.map +1 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts +11 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -0
- package/lib/typescript/src/base/types.d.ts +13 -0
- package/lib/typescript/src/base/types.d.ts.map +1 -0
- package/lib/typescript/src/base/utils.d.ts +2 -0
- package/lib/typescript/src/base/utils.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +30 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts +4 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts +5 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts +6 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts +8 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +4 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts +20 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts +5 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +15 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts +13 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/index.d.ts +2 -0
- package/lib/typescript/src/musicxml/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts +10 -0
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +6 -0
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +9 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts +15 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +24 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts +5 -0
- package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +12 -0
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts +13 -0
- package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts.map +1 -0
- package/lib/typescript/src/renderer/colorScheme.d.ts +9 -0
- package/lib/typescript/src/renderer/colorScheme.d.ts.map +1 -0
- package/lib/typescript/src/renderer/constants.d.ts +5 -0
- package/lib/typescript/src/renderer/constants.d.ts.map +1 -0
- package/lib/typescript/src/renderer/index.d.ts +4 -0
- package/lib/typescript/src/renderer/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/layout.d.ts +56 -0
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -0
- package/lib/typescript/src/renderer/measure.d.ts +23 -0
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -0
- package/lib/typescript/src/renderer/render.d.ts +9 -0
- package/lib/typescript/src/renderer/render.d.ts.map +1 -0
- package/lib/typescript/src/renderer/scoreParsing.d.ts +76 -0
- package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +56 -0
- package/lib/typescript/src/renderer/types.d.ts.map +1 -0
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +21 -0
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -0
- package/lib/typescript/src/renderer/viewport.d.ts +3 -0
- package/lib/typescript/src/renderer/viewport.d.ts.map +1 -0
- package/lib/typescript/src/shared/Logger.d.ts +18 -0
- package/lib/typescript/src/shared/Logger.d.ts.map +1 -0
- package/lib/typescript/src/state/index.d.ts +2 -0
- package/lib/typescript/src/state/index.d.ts.map +1 -0
- package/lib/typescript/src/state/types.d.ts +190 -0
- package/lib/typescript/src/state/types.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +0 -6
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +0 -6
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/package.json +41 -14
- package/src/base/FontManager.ts +206 -0
- package/src/base/TextMeasureContext.ts +59 -0
- package/src/base/VexflowCanvas.tsx +60 -0
- package/src/base/VexflowColorScheme.ts +32 -0
- package/src/base/VexflowRecordingContext.ts +545 -0
- package/src/base/VexflowRecordingReplay.ts +327 -0
- package/src/base/VexflowRecordingTypes.ts +169 -0
- package/src/base/index.ts +7 -0
- package/src/base/setupVexflowReactNative.ts +124 -0
- package/src/base/types.ts +17 -0
- package/src/base/utils.ts +21 -0
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +41 -0
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +469 -0
- package/src/musicxml/MusicXmlParser/MusicXmlDirections.ts +84 -0
- package/src/musicxml/MusicXmlParser/MusicXmlTiming.ts +153 -0
- package/src/musicxml/MusicXmlParser/PartParser.ts +69 -0
- package/src/musicxml/MusicXmlParser/Spanners.ts +215 -0
- package/src/musicxml/MusicXmlParser/XmlOrder.ts +170 -0
- package/src/musicxml/MusicXmlParser/index.ts +144 -0
- package/src/musicxml/MusicXmlParser/mappers.ts +307 -0
- package/src/musicxml/MusicXmlParser/types.ts +24 -0
- package/src/musicxml/index.ts +5 -0
- package/src/musicxml/testfiles/lg-8102429.xml +79620 -0
- package/src/renderer/Layout/DocumentLayout.ts +240 -0
- package/src/renderer/Layout/LayoutMetrics.ts +21 -0
- package/src/renderer/Layout/VerticalSpacing.ts +122 -0
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +384 -0
- package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +231 -0
- package/src/renderer/ScoreRenderer/index.ts +13 -0
- package/src/renderer/ScoreRenderer/types.ts +14 -0
- package/src/renderer/ScoreRenderer/useScoreScroll.ts +146 -0
- package/src/renderer/colorScheme.ts +28 -0
- package/src/renderer/constants.ts +19 -0
- package/src/renderer/index.ts +3 -0
- package/src/renderer/layout.ts +309 -0
- package/src/renderer/measure.tsx +304 -0
- package/src/renderer/render.tsx +308 -0
- package/src/renderer/scoreParsing.tsx +352 -0
- package/src/renderer/types.ts +65 -0
- package/src/renderer/useScoreRecording.ts +177 -0
- package/src/renderer/viewport.ts +45 -0
- package/src/shared/Logger.ts +85 -0
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +295 -0
- package/src/types.ts +6 -6
- package/src/utils.tsx +32 -98
- package/lib/module/SkiaVexflowContext.js +0 -285
- package/lib/module/SkiaVexflowContext.js.map +0 -1
- package/lib/module/VexflowCanvas.js +0 -103
- package/lib/module/VexflowCanvas.js.map +0 -1
- package/lib/module/colorUtils.js +0 -34
- package/lib/module/colorUtils.js.map +0 -1
- package/lib/module/colorUtils.test.js +0 -37
- package/lib/module/colorUtils.test.js.map +0 -1
- package/lib/module/constants.js +0 -30
- package/lib/module/constants.js.map +0 -1
- package/lib/module/index.js +0 -8
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/src/SkiaVexflowContext.d.ts +0 -101
- package/lib/typescript/src/SkiaVexflowContext.d.ts.map +0 -1
- package/lib/typescript/src/VexflowCanvas.d.ts +0 -17
- package/lib/typescript/src/VexflowCanvas.d.ts.map +0 -1
- package/lib/typescript/src/colorUtils.d.ts +0 -2
- package/lib/typescript/src/colorUtils.d.ts.map +0 -1
- package/lib/typescript/src/colorUtils.test.d.ts +0 -2
- package/lib/typescript/src/colorUtils.test.d.ts.map +0 -1
- package/lib/typescript/src/constants.d.ts +0 -21
- package/lib/typescript/src/constants.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -7
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/src/SkiaVexflowContext.ts +0 -462
- package/src/VexflowCanvas.tsx +0 -145
- package/src/colorUtils.test.ts +0 -52
- package/src/colorUtils.ts +0 -55
- package/src/constants.tsx +0 -34
- package/src/index.ts +0 -8
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
3
|
+
import {
|
|
4
|
+
cancelAnimation,
|
|
5
|
+
useAnimatedReaction,
|
|
6
|
+
useDerivedValue,
|
|
7
|
+
useSharedValue,
|
|
8
|
+
withDecay,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
10
|
+
|
|
11
|
+
import type { RendererSize, RendererType } from '../types';
|
|
12
|
+
import type { ScoreScrollState, ScrollAxis } from './types';
|
|
13
|
+
|
|
14
|
+
const EMPTY_SIZE: RendererSize = { width: 0, height: 0 };
|
|
15
|
+
|
|
16
|
+
export function useScoreScroll({
|
|
17
|
+
contentSize,
|
|
18
|
+
rendererType,
|
|
19
|
+
scrollEnabled,
|
|
20
|
+
viewportSize,
|
|
21
|
+
}: {
|
|
22
|
+
contentSize: RendererSize;
|
|
23
|
+
rendererType: RendererType;
|
|
24
|
+
scrollEnabled: boolean;
|
|
25
|
+
viewportSize: RendererSize;
|
|
26
|
+
}): ScoreScrollState {
|
|
27
|
+
const scrollOffset = useSharedValue(0);
|
|
28
|
+
const viewportSizeValue = useSharedValue<RendererSize>(EMPTY_SIZE);
|
|
29
|
+
const contentSizeValue = useSharedValue<RendererSize>(EMPTY_SIZE);
|
|
30
|
+
const panStartOffset = useSharedValue(0);
|
|
31
|
+
const axis = getScrollAxis(rendererType);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
viewportSizeValue.value = viewportSize;
|
|
35
|
+
}, [viewportSize, viewportSizeValue]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
contentSizeValue.value = contentSize;
|
|
39
|
+
}, [contentSize, contentSizeValue]);
|
|
40
|
+
|
|
41
|
+
const maxScrollValue = useDerivedValue(
|
|
42
|
+
() =>
|
|
43
|
+
getMaxScroll(
|
|
44
|
+
rendererType,
|
|
45
|
+
viewportSizeValue.value,
|
|
46
|
+
contentSizeValue.value
|
|
47
|
+
),
|
|
48
|
+
[contentSizeValue, rendererType, viewportSizeValue]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
useAnimatedReaction(
|
|
52
|
+
() => maxScrollValue.value,
|
|
53
|
+
(nextMaxScroll) => {
|
|
54
|
+
const nextOffset = clampOffset(scrollOffset.value, nextMaxScroll);
|
|
55
|
+
|
|
56
|
+
if (nextOffset !== scrollOffset.value) {
|
|
57
|
+
scrollOffset.value = nextOffset;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[maxScrollValue, scrollOffset]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const panGesture = useMemo(
|
|
64
|
+
() =>
|
|
65
|
+
Gesture.Pan()
|
|
66
|
+
.enabled(scrollEnabled)
|
|
67
|
+
.onStart(() => {
|
|
68
|
+
cancelAnimation(scrollOffset);
|
|
69
|
+
panStartOffset.value = scrollOffset.value;
|
|
70
|
+
})
|
|
71
|
+
.onUpdate((event) => {
|
|
72
|
+
const nextMaxScroll = maxScrollValue.value;
|
|
73
|
+
const translation =
|
|
74
|
+
rendererType === 'infiniteScore'
|
|
75
|
+
? event.translationX
|
|
76
|
+
: event.translationY;
|
|
77
|
+
|
|
78
|
+
scrollOffset.value = clampOffset(
|
|
79
|
+
panStartOffset.value - translation,
|
|
80
|
+
nextMaxScroll
|
|
81
|
+
);
|
|
82
|
+
})
|
|
83
|
+
.onEnd((event) => {
|
|
84
|
+
const nextMaxScroll = maxScrollValue.value;
|
|
85
|
+
const velocity =
|
|
86
|
+
rendererType === 'infiniteScore'
|
|
87
|
+
? event.velocityX
|
|
88
|
+
: event.velocityY;
|
|
89
|
+
|
|
90
|
+
scrollOffset.value =
|
|
91
|
+
nextMaxScroll > 0
|
|
92
|
+
? withDecay({
|
|
93
|
+
clamp: [0, nextMaxScroll],
|
|
94
|
+
velocity: -velocity,
|
|
95
|
+
})
|
|
96
|
+
: 0;
|
|
97
|
+
}),
|
|
98
|
+
[maxScrollValue, panStartOffset, rendererType, scrollEnabled, scrollOffset]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
axis,
|
|
103
|
+
contentSize: contentSizeValue,
|
|
104
|
+
panGesture,
|
|
105
|
+
scrollOffset,
|
|
106
|
+
viewportSize: viewportSizeValue,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function getScrollAxis(rendererType: RendererType): ScrollAxis {
|
|
111
|
+
'worklet';
|
|
112
|
+
|
|
113
|
+
return rendererType === 'infiniteScore' ? 'horizontal' : 'vertical';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function getMaxScroll(
|
|
117
|
+
rendererType: RendererType,
|
|
118
|
+
viewportSize: RendererSize,
|
|
119
|
+
contentSize: RendererSize
|
|
120
|
+
): number {
|
|
121
|
+
'worklet';
|
|
122
|
+
|
|
123
|
+
return getScrollAxis(rendererType) === 'horizontal'
|
|
124
|
+
? Math.max(0, contentSize.width - viewportSize.width)
|
|
125
|
+
: Math.max(0, contentSize.height - viewportSize.height);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function clampOffset(offset: number, maxOffset: number): number {
|
|
129
|
+
'worklet';
|
|
130
|
+
|
|
131
|
+
return Math.min(Math.max(offset, 0), maxOffset);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function createClampedScrollOffset(
|
|
135
|
+
scrollOffset: number,
|
|
136
|
+
rendererType: RendererType,
|
|
137
|
+
viewportSize: RendererSize,
|
|
138
|
+
contentSize: RendererSize
|
|
139
|
+
): number {
|
|
140
|
+
'worklet';
|
|
141
|
+
|
|
142
|
+
return clampOffset(
|
|
143
|
+
scrollOffset,
|
|
144
|
+
getMaxScroll(rendererType, viewportSize, contentSize)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { VexflowColorScheme } from '../base/VexflowColorScheme';
|
|
2
|
+
|
|
3
|
+
export type ScoreColorScheme = VexflowColorScheme;
|
|
4
|
+
|
|
5
|
+
export interface ResolvedScoreColorScheme {
|
|
6
|
+
foreground: string;
|
|
7
|
+
background: string;
|
|
8
|
+
ledgerLine?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DEFAULT_SCORE_COLOR_SCHEME: ResolvedScoreColorScheme = {
|
|
12
|
+
foreground: '#000000',
|
|
13
|
+
background: 'transparent',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function resolveScoreColorScheme(
|
|
17
|
+
colorScheme?: ScoreColorScheme
|
|
18
|
+
): ResolvedScoreColorScheme {
|
|
19
|
+
if (!colorScheme) {
|
|
20
|
+
return DEFAULT_SCORE_COLOR_SCHEME;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
foreground: colorScheme.foreground ?? DEFAULT_SCORE_COLOR_SCHEME.foreground,
|
|
25
|
+
background: colorScheme.background ?? DEFAULT_SCORE_COLOR_SCHEME.background,
|
|
26
|
+
ledgerLine: colorScheme.ledgerLine,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ScoreInsets, ScoreSpacing, RenderOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export const insets: ScoreInsets = {
|
|
4
|
+
top: 24,
|
|
5
|
+
right: 24,
|
|
6
|
+
bottom: 24,
|
|
7
|
+
left: 24,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const spacing: ScoreSpacing = {
|
|
11
|
+
staffGap: 96,
|
|
12
|
+
minIntrinsicSizeMultiplier: 2,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const renderOptions: RenderOptions = {
|
|
16
|
+
pixelRatio: 1,
|
|
17
|
+
scale: 1,
|
|
18
|
+
debug: false,
|
|
19
|
+
};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { Score, Staff, StaffGroup } from '../state';
|
|
2
|
+
import {
|
|
3
|
+
getAvailableDocumentWidth,
|
|
4
|
+
getSystemGap,
|
|
5
|
+
} from './Layout/LayoutMetrics';
|
|
6
|
+
import {
|
|
7
|
+
layoutDocumentEvenGroup,
|
|
8
|
+
layoutDocumentGroup,
|
|
9
|
+
resolveDocumentEvenMeasureWidth,
|
|
10
|
+
} from './Layout/DocumentLayout';
|
|
11
|
+
import { resolveSystemVerticalLayout } from './Layout/VerticalSpacing';
|
|
12
|
+
import type { SystemVerticalLayout } from './Layout/VerticalSpacing';
|
|
13
|
+
import {
|
|
14
|
+
buildMeasurementGroups,
|
|
15
|
+
buildResolvedMeasureStates,
|
|
16
|
+
resolveGroupStaves,
|
|
17
|
+
type ResolvedMeasureState,
|
|
18
|
+
} from './scoreParsing';
|
|
19
|
+
import type { MeasuredScore } from './measure';
|
|
20
|
+
import type { StaffVerticalBounds } from './measure';
|
|
21
|
+
import type {
|
|
22
|
+
RendererRect,
|
|
23
|
+
RendererSize,
|
|
24
|
+
RendererType,
|
|
25
|
+
ScoreOptions,
|
|
26
|
+
} from './types';
|
|
27
|
+
|
|
28
|
+
export interface MeasuredGroupMeasure {
|
|
29
|
+
groupId: string;
|
|
30
|
+
measureIndex: number;
|
|
31
|
+
intrinsicWidth: number;
|
|
32
|
+
measureNumbers: number[];
|
|
33
|
+
staffBounds: StaffVerticalBounds[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface GroupLayoutContext {
|
|
37
|
+
groupId: string;
|
|
38
|
+
staffGroup?: StaffGroup;
|
|
39
|
+
staffIds: string[];
|
|
40
|
+
staves: Staff[];
|
|
41
|
+
resolvedStatesByStaff: ResolvedMeasureState[][];
|
|
42
|
+
measures: MeasuredGroupMeasure[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface MeasureLayoutPlan {
|
|
46
|
+
groupId: string;
|
|
47
|
+
measureIndex: number;
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
staffYOffsets: number[];
|
|
53
|
+
systemIndex: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SystemLayoutPlan {
|
|
57
|
+
groupId: string;
|
|
58
|
+
systemIndex: number;
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
staffCount: number;
|
|
64
|
+
staffYOffsets: number[];
|
|
65
|
+
measureIndices: number[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface GroupLayoutResult {
|
|
69
|
+
groupId: string;
|
|
70
|
+
systems: SystemLayoutPlan[];
|
|
71
|
+
measures: MeasureLayoutPlan[];
|
|
72
|
+
nextY: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ScoreLayoutPlan {
|
|
76
|
+
rendererType: RendererType;
|
|
77
|
+
contentSize: RendererSize;
|
|
78
|
+
systems: SystemLayoutPlan[];
|
|
79
|
+
measures: MeasureLayoutPlan[];
|
|
80
|
+
groups: GroupLayoutContext[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function layoutScore(
|
|
84
|
+
score: Score,
|
|
85
|
+
measuredScore: MeasuredScore,
|
|
86
|
+
options: ScoreOptions,
|
|
87
|
+
rendererType: RendererType,
|
|
88
|
+
viewport: RendererRect
|
|
89
|
+
): ScoreLayoutPlan {
|
|
90
|
+
const groups = buildGroupLayoutContext(score, measuredScore);
|
|
91
|
+
const groupResults: GroupLayoutResult[] = [];
|
|
92
|
+
|
|
93
|
+
if (rendererType === 'infiniteScore') {
|
|
94
|
+
for (const group of groups) {
|
|
95
|
+
groupResults.push(layoutInfiniteScoreGroup(group, viewport, options));
|
|
96
|
+
}
|
|
97
|
+
} else if (rendererType === 'documentEven') {
|
|
98
|
+
const availableWidth = getAvailableDocumentWidth(viewport, options);
|
|
99
|
+
const { measuresPerFullLine, equalMeasureWidth } =
|
|
100
|
+
resolveDocumentEvenMeasureWidth(measuredScore, availableWidth);
|
|
101
|
+
let cursorY = viewport.y + options.insets.top;
|
|
102
|
+
|
|
103
|
+
for (const group of groups) {
|
|
104
|
+
const result = layoutDocumentEvenGroup(
|
|
105
|
+
group,
|
|
106
|
+
{ x: viewport.x + options.insets.left, y: cursorY },
|
|
107
|
+
availableWidth,
|
|
108
|
+
equalMeasureWidth,
|
|
109
|
+
measuresPerFullLine,
|
|
110
|
+
options
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
groupResults.push(result);
|
|
114
|
+
cursorY = result.nextY;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
const availableWidth = getAvailableDocumentWidth(viewport, options);
|
|
118
|
+
let cursorY = viewport.y + options.insets.top;
|
|
119
|
+
|
|
120
|
+
for (const group of groups) {
|
|
121
|
+
const result = layoutDocumentGroup(
|
|
122
|
+
group,
|
|
123
|
+
{ x: viewport.x + options.insets.left, y: cursorY },
|
|
124
|
+
availableWidth,
|
|
125
|
+
options
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
groupResults.push(result);
|
|
129
|
+
cursorY = result.nextY;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
rendererType,
|
|
135
|
+
contentSize: measureContentSize(
|
|
136
|
+
groupResults,
|
|
137
|
+
viewport,
|
|
138
|
+
rendererType,
|
|
139
|
+
options
|
|
140
|
+
),
|
|
141
|
+
systems: groupResults.flatMap((group) => group.systems),
|
|
142
|
+
measures: groupResults.flatMap((group) => group.measures),
|
|
143
|
+
groups,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function buildGroupLayoutContext(
|
|
148
|
+
score: Score,
|
|
149
|
+
measuredScore: MeasuredScore
|
|
150
|
+
): GroupLayoutContext[] {
|
|
151
|
+
const groups = buildMeasurementGroups(score);
|
|
152
|
+
|
|
153
|
+
return groups.map((group) => ({
|
|
154
|
+
groupId: group.groupId,
|
|
155
|
+
staffGroup: group.staffGroup,
|
|
156
|
+
staffIds: group.staffIds,
|
|
157
|
+
staves: resolveGroupStaves(score, group),
|
|
158
|
+
resolvedStatesByStaff: resolveGroupStaves(score, group).map((staff) =>
|
|
159
|
+
buildResolvedMeasureStates(score, staff)
|
|
160
|
+
),
|
|
161
|
+
measures: measuredScore.measures
|
|
162
|
+
.filter((measure) => measure.groupId === group.groupId)
|
|
163
|
+
.sort((left, right) => left.measureIndex - right.measureIndex)
|
|
164
|
+
.map((measure) => ({
|
|
165
|
+
groupId: measure.groupId,
|
|
166
|
+
measureIndex: measure.measureIndex,
|
|
167
|
+
intrinsicWidth: measure.intrinsicNoteWidth,
|
|
168
|
+
measureNumbers: measure.measureNumbers,
|
|
169
|
+
staffBounds: measure.staffBounds,
|
|
170
|
+
})),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function layoutInfiniteScoreGroup(
|
|
175
|
+
group: GroupLayoutContext,
|
|
176
|
+
viewport: RendererRect,
|
|
177
|
+
options: ScoreOptions
|
|
178
|
+
): GroupLayoutResult {
|
|
179
|
+
const systems: SystemLayoutPlan[] = [];
|
|
180
|
+
const measures: MeasureLayoutPlan[] = [];
|
|
181
|
+
const verticalLayout = resolveSystemVerticalLayout(
|
|
182
|
+
group.measures,
|
|
183
|
+
group.staves.length,
|
|
184
|
+
options.spacing.staffGap
|
|
185
|
+
);
|
|
186
|
+
const maxIntrinsicWidth = Math.max(
|
|
187
|
+
...group.measures.map((measure) => measure.intrinsicWidth),
|
|
188
|
+
0
|
|
189
|
+
);
|
|
190
|
+
const systemWidth = group.measures.length * maxIntrinsicWidth;
|
|
191
|
+
const origin = {
|
|
192
|
+
x: getInfiniteScoreOriginX(systemWidth, viewport, options),
|
|
193
|
+
y: getInfiniteScoreOriginY(verticalLayout, viewport),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
let cursorX = origin.x;
|
|
197
|
+
|
|
198
|
+
for (const measure of group.measures) {
|
|
199
|
+
const width = Math.max(measure.intrinsicWidth, maxIntrinsicWidth);
|
|
200
|
+
|
|
201
|
+
measures.push({
|
|
202
|
+
groupId: group.groupId,
|
|
203
|
+
measureIndex: measure.measureIndex,
|
|
204
|
+
x: cursorX,
|
|
205
|
+
y: origin.y,
|
|
206
|
+
width,
|
|
207
|
+
height: verticalLayout.height,
|
|
208
|
+
staffYOffsets: verticalLayout.staffYOffsets,
|
|
209
|
+
systemIndex: 0,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
cursorX += width;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
systems.push({
|
|
216
|
+
groupId: group.groupId,
|
|
217
|
+
systemIndex: 0,
|
|
218
|
+
x: origin.x,
|
|
219
|
+
y: origin.y,
|
|
220
|
+
width: cursorX - origin.x,
|
|
221
|
+
height: verticalLayout.height,
|
|
222
|
+
staffCount: group.staves.length,
|
|
223
|
+
staffYOffsets: verticalLayout.staffYOffsets,
|
|
224
|
+
measureIndices: group.measures.map((measure) => measure.measureIndex),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
groupId: group.groupId,
|
|
229
|
+
systems,
|
|
230
|
+
measures,
|
|
231
|
+
nextY:
|
|
232
|
+
origin.y + verticalLayout.height + getSystemGap(options.spacing.staffGap),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function getInfiniteScoreOriginX(
|
|
237
|
+
systemWidth: number,
|
|
238
|
+
viewport: RendererRect,
|
|
239
|
+
options: ScoreOptions
|
|
240
|
+
): number {
|
|
241
|
+
const insetContentWidth =
|
|
242
|
+
systemWidth + options.insets.left + options.insets.right;
|
|
243
|
+
|
|
244
|
+
if (insetContentWidth <= viewport.width) {
|
|
245
|
+
return viewport.x + (viewport.width - systemWidth) / 2;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return viewport.x + options.insets.left;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function getInfiniteScoreOriginY(
|
|
252
|
+
verticalLayout: SystemVerticalLayout,
|
|
253
|
+
viewport: RendererRect
|
|
254
|
+
): number {
|
|
255
|
+
return (
|
|
256
|
+
viewport.y +
|
|
257
|
+
viewport.height / 2 -
|
|
258
|
+
(verticalLayout.visibleTop + verticalLayout.visibleBottom) / 2
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function measureContentSize(
|
|
263
|
+
groupResults: GroupLayoutResult[],
|
|
264
|
+
viewport: RendererRect,
|
|
265
|
+
rendererType: RendererType,
|
|
266
|
+
options: ScoreOptions
|
|
267
|
+
): RendererSize {
|
|
268
|
+
if (
|
|
269
|
+
groupResults.length === 0 ||
|
|
270
|
+
groupResults.every((group) => group.systems.length === 0)
|
|
271
|
+
) {
|
|
272
|
+
return {
|
|
273
|
+
width: viewport.width,
|
|
274
|
+
height: viewport.height,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let maxRight = viewport.x + options.insets.left;
|
|
279
|
+
let maxBottom = viewport.y + options.insets.top;
|
|
280
|
+
|
|
281
|
+
for (const group of groupResults) {
|
|
282
|
+
for (const system of group.systems) {
|
|
283
|
+
maxRight = Math.max(maxRight, system.x + system.width);
|
|
284
|
+
maxBottom = Math.max(maxBottom, system.y + system.height);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const measuredWidth = maxRight + options.insets.right - viewport.x;
|
|
289
|
+
const measuredHeight = maxBottom + options.insets.bottom - viewport.y;
|
|
290
|
+
|
|
291
|
+
if (rendererType === 'documentEven') {
|
|
292
|
+
return {
|
|
293
|
+
width: Math.max(viewport.width, measuredWidth),
|
|
294
|
+
height: measuredHeight,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (rendererType === 'document') {
|
|
299
|
+
return {
|
|
300
|
+
width: measuredWidth,
|
|
301
|
+
height: measuredHeight,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
width: Math.max(viewport.width, measuredWidth),
|
|
307
|
+
height: viewport.height,
|
|
308
|
+
};
|
|
309
|
+
}
|