vexflow-native 0.1.0 → 1.0.1
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 +286 -11
- 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 +425 -0
- package/lib/module/base/VexflowRecordingContext.js.map +1 -0
- package/lib/module/base/VexflowRecordingReplay.js +140 -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 +8 -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 +232 -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 +163 -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 +74 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +4 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts +94 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts.map +1 -0
- package/lib/typescript/src/base/index.d.ts +6 -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 +14 -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 +51 -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 -13
- 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 +495 -0
- package/src/base/VexflowRecordingReplay.ts +211 -0
- package/src/base/VexflowRecordingTypes.ts +117 -0
- package/src/base/index.ts +6 -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 +310 -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 +281 -0
- package/src/renderer/scoreParsing.tsx +352 -0
- package/src/renderer/types.ts +60 -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 -101
- 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 -15
- 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 -140
- 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,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BlendMode,
|
|
3
|
+
ClipOp,
|
|
4
|
+
PaintStyle,
|
|
5
|
+
Skia,
|
|
6
|
+
StrokeCap,
|
|
7
|
+
type SkCanvas,
|
|
8
|
+
type SkPaint,
|
|
9
|
+
type SkPathBuilder,
|
|
10
|
+
type SkTypefaceFontProvider,
|
|
11
|
+
} from '@shopify/react-native-skia';
|
|
12
|
+
|
|
13
|
+
import FontManager from './FontManager';
|
|
14
|
+
import type {
|
|
15
|
+
VexflowRecordingCommand,
|
|
16
|
+
VexflowRecordingFont,
|
|
17
|
+
VexflowRecordingLineCap,
|
|
18
|
+
VexflowRecordingPaint,
|
|
19
|
+
VexflowRecordingPathCommand,
|
|
20
|
+
VexflowRecordingRect,
|
|
21
|
+
} from './VexflowRecordingTypes';
|
|
22
|
+
|
|
23
|
+
function toSkiaRect(rect: VexflowRecordingRect) {
|
|
24
|
+
'worklet';
|
|
25
|
+
|
|
26
|
+
return Skia.XYWHRect(rect.x, rect.y, rect.width, rect.height);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
30
|
+
'worklet';
|
|
31
|
+
|
|
32
|
+
switch (cap) {
|
|
33
|
+
case 'round':
|
|
34
|
+
return StrokeCap.Round;
|
|
35
|
+
case 'square':
|
|
36
|
+
return StrokeCap.Square;
|
|
37
|
+
case 'butt':
|
|
38
|
+
default:
|
|
39
|
+
return StrokeCap.Butt;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createFillPaint(paint: VexflowRecordingPaint): SkPaint {
|
|
44
|
+
'worklet';
|
|
45
|
+
|
|
46
|
+
const skPaint = Skia.Paint();
|
|
47
|
+
skPaint.setStyle(PaintStyle.Fill);
|
|
48
|
+
skPaint.setAntiAlias(true);
|
|
49
|
+
skPaint.setColor(Skia.Color(paint.color));
|
|
50
|
+
|
|
51
|
+
return skPaint;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createStrokePaint(paint: VexflowRecordingPaint): SkPaint {
|
|
55
|
+
'worklet';
|
|
56
|
+
|
|
57
|
+
const skPaint = Skia.Paint();
|
|
58
|
+
skPaint.setStyle(PaintStyle.Stroke);
|
|
59
|
+
skPaint.setAntiAlias(true);
|
|
60
|
+
skPaint.setColor(Skia.Color(paint.color));
|
|
61
|
+
skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
|
|
62
|
+
skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
|
|
63
|
+
|
|
64
|
+
return skPaint;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createClearPaint(): SkPaint {
|
|
68
|
+
'worklet';
|
|
69
|
+
|
|
70
|
+
const clearPaint = Skia.Paint();
|
|
71
|
+
clearPaint.setBlendMode(BlendMode.Clear);
|
|
72
|
+
|
|
73
|
+
return clearPaint;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function createFont(fontManager: FontManager, font: VexflowRecordingFont) {
|
|
77
|
+
'worklet';
|
|
78
|
+
|
|
79
|
+
return fontManager.createSkFont(
|
|
80
|
+
font.font,
|
|
81
|
+
font.size,
|
|
82
|
+
font.weight,
|
|
83
|
+
font.style
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function assertNever(value: never): never {
|
|
88
|
+
throw new Error(`Unexpected Vexflow recording command: ${String(value)}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function applyPathCommand(
|
|
92
|
+
builder: SkPathBuilder,
|
|
93
|
+
command: VexflowRecordingPathCommand
|
|
94
|
+
) {
|
|
95
|
+
'worklet';
|
|
96
|
+
|
|
97
|
+
switch (command.type) {
|
|
98
|
+
case 'moveTo':
|
|
99
|
+
builder.moveTo(command.x, command.y);
|
|
100
|
+
break;
|
|
101
|
+
case 'lineTo':
|
|
102
|
+
builder.lineTo(command.x, command.y);
|
|
103
|
+
break;
|
|
104
|
+
case 'cubicTo':
|
|
105
|
+
builder.cubicTo(
|
|
106
|
+
command.cp1x,
|
|
107
|
+
command.cp1y,
|
|
108
|
+
command.cp2x,
|
|
109
|
+
command.cp2y,
|
|
110
|
+
command.x,
|
|
111
|
+
command.y
|
|
112
|
+
);
|
|
113
|
+
break;
|
|
114
|
+
case 'quadTo':
|
|
115
|
+
builder.quadTo(command.cpx, command.cpy, command.x, command.y);
|
|
116
|
+
break;
|
|
117
|
+
case 'addRect':
|
|
118
|
+
builder.addRect(toSkiaRect(command.rect));
|
|
119
|
+
break;
|
|
120
|
+
case 'addArc':
|
|
121
|
+
builder.addArc(
|
|
122
|
+
toSkiaRect(command.rect),
|
|
123
|
+
command.startDegrees,
|
|
124
|
+
command.sweepDegrees
|
|
125
|
+
);
|
|
126
|
+
break;
|
|
127
|
+
case 'close':
|
|
128
|
+
builder.close();
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
assertNever(command);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function buildPath(path: readonly VexflowRecordingPathCommand[]) {
|
|
136
|
+
'worklet';
|
|
137
|
+
|
|
138
|
+
const builder = Skia.PathBuilder.Make();
|
|
139
|
+
|
|
140
|
+
for (const command of path) {
|
|
141
|
+
applyPathCommand(builder, command);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return builder.build();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function renderVexflowRecordingCommands(
|
|
148
|
+
canvas: SkCanvas,
|
|
149
|
+
commands: readonly VexflowRecordingCommand[],
|
|
150
|
+
fontProvider: SkTypefaceFontProvider,
|
|
151
|
+
defaultFont: string
|
|
152
|
+
) {
|
|
153
|
+
'worklet';
|
|
154
|
+
|
|
155
|
+
const fontManager = new FontManager(fontProvider, defaultFont);
|
|
156
|
+
|
|
157
|
+
for (const command of commands) {
|
|
158
|
+
switch (command.type) {
|
|
159
|
+
case 'clear':
|
|
160
|
+
canvas.clear(Skia.Color(command.color));
|
|
161
|
+
break;
|
|
162
|
+
case 'save':
|
|
163
|
+
canvas.save();
|
|
164
|
+
break;
|
|
165
|
+
case 'restore':
|
|
166
|
+
canvas.restore();
|
|
167
|
+
break;
|
|
168
|
+
case 'scale':
|
|
169
|
+
canvas.scale(command.x, command.y);
|
|
170
|
+
break;
|
|
171
|
+
case 'translate':
|
|
172
|
+
canvas.translate(command.x, command.y);
|
|
173
|
+
break;
|
|
174
|
+
case 'clipRect':
|
|
175
|
+
canvas.clipRect(toSkiaRect(command.rect), ClipOp.Intersect, true);
|
|
176
|
+
break;
|
|
177
|
+
case 'fillRect':
|
|
178
|
+
canvas.drawRect(
|
|
179
|
+
toSkiaRect(command.rect),
|
|
180
|
+
createFillPaint(command.paint)
|
|
181
|
+
);
|
|
182
|
+
break;
|
|
183
|
+
case 'clearRect':
|
|
184
|
+
canvas.drawRect(toSkiaRect(command.rect), createClearPaint());
|
|
185
|
+
break;
|
|
186
|
+
case 'fillPath':
|
|
187
|
+
canvas.drawPath(
|
|
188
|
+
buildPath(command.path),
|
|
189
|
+
createFillPaint(command.paint)
|
|
190
|
+
);
|
|
191
|
+
break;
|
|
192
|
+
case 'strokePath':
|
|
193
|
+
canvas.drawPath(
|
|
194
|
+
buildPath(command.path),
|
|
195
|
+
createStrokePaint(command.paint)
|
|
196
|
+
);
|
|
197
|
+
break;
|
|
198
|
+
case 'fillText':
|
|
199
|
+
canvas.drawText(
|
|
200
|
+
command.text,
|
|
201
|
+
command.x,
|
|
202
|
+
command.y,
|
|
203
|
+
createFillPaint(command.paint),
|
|
204
|
+
createFont(fontManager, command.font)
|
|
205
|
+
);
|
|
206
|
+
break;
|
|
207
|
+
default:
|
|
208
|
+
assertNever(command);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { FontInfo } from 'vexflow';
|
|
2
|
+
|
|
3
|
+
export type VexflowRecordingLineCap = 'butt' | 'round' | 'square';
|
|
4
|
+
|
|
5
|
+
export interface VexflowRecordingRect {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface VexflowRecordingPaint {
|
|
13
|
+
color: string;
|
|
14
|
+
strokeCap?: VexflowRecordingLineCap;
|
|
15
|
+
strokeWidth?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface VexflowRecordingFont {
|
|
19
|
+
font?: string | FontInfo;
|
|
20
|
+
size?: string | number;
|
|
21
|
+
weight?: string | number;
|
|
22
|
+
style?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type VexflowRecordingPathCommand =
|
|
26
|
+
| {
|
|
27
|
+
type: 'moveTo';
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
type: 'lineTo';
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
type: 'cubicTo';
|
|
38
|
+
cp1x: number;
|
|
39
|
+
cp1y: number;
|
|
40
|
+
cp2x: number;
|
|
41
|
+
cp2y: number;
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
type: 'quadTo';
|
|
47
|
+
cpx: number;
|
|
48
|
+
cpy: number;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
}
|
|
52
|
+
| {
|
|
53
|
+
type: 'addRect';
|
|
54
|
+
rect: VexflowRecordingRect;
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
type: 'addArc';
|
|
58
|
+
rect: VexflowRecordingRect;
|
|
59
|
+
startDegrees: number;
|
|
60
|
+
sweepDegrees: number;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
type: 'close';
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type VexflowRecordingCommand =
|
|
67
|
+
| {
|
|
68
|
+
type: 'clear';
|
|
69
|
+
color: string;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
type: 'save';
|
|
73
|
+
}
|
|
74
|
+
| {
|
|
75
|
+
type: 'restore';
|
|
76
|
+
}
|
|
77
|
+
| {
|
|
78
|
+
type: 'scale';
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: 'translate';
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
type: 'clipRect';
|
|
89
|
+
rect: VexflowRecordingRect;
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
type: 'fillRect';
|
|
93
|
+
rect: VexflowRecordingRect;
|
|
94
|
+
paint: VexflowRecordingPaint;
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
type: 'clearRect';
|
|
98
|
+
rect: VexflowRecordingRect;
|
|
99
|
+
}
|
|
100
|
+
| {
|
|
101
|
+
type: 'fillPath';
|
|
102
|
+
path: VexflowRecordingPathCommand[];
|
|
103
|
+
paint: VexflowRecordingPaint;
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
type: 'strokePath';
|
|
107
|
+
path: VexflowRecordingPathCommand[];
|
|
108
|
+
paint: VexflowRecordingPaint;
|
|
109
|
+
}
|
|
110
|
+
| {
|
|
111
|
+
type: 'fillText';
|
|
112
|
+
text: string;
|
|
113
|
+
x: number;
|
|
114
|
+
y: number;
|
|
115
|
+
paint: VexflowRecordingPaint;
|
|
116
|
+
font: VexflowRecordingFont;
|
|
117
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Element, Font } from 'vexflow';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import type { FontInfo } from 'vexflow';
|
|
4
|
+
|
|
5
|
+
const FONT_SIZE_PATTERN =
|
|
6
|
+
/(\d+(?:\.\d+)?(?:px|pt|em|rem|%|in|mm|cm)?)(?:\/[^\s]+)?/i;
|
|
7
|
+
const FONT_STYLE_PATTERN = /\b(italic|oblique|normal)\b/i;
|
|
8
|
+
const FONT_WEIGHT_PATTERN = /\b(bold|bolder|lighter|normal|[1-9]00)\b/i;
|
|
9
|
+
|
|
10
|
+
const originalFromCSSString = Font.fromCSSString.bind(Font);
|
|
11
|
+
|
|
12
|
+
let fallbackInstalled = false;
|
|
13
|
+
let textMeasurementCanvasInstalled = false;
|
|
14
|
+
|
|
15
|
+
const emptyTextMetrics = {
|
|
16
|
+
width: 0,
|
|
17
|
+
actualBoundingBoxAscent: 0,
|
|
18
|
+
actualBoundingBoxDescent: 0,
|
|
19
|
+
actualBoundingBoxLeft: 0,
|
|
20
|
+
actualBoundingBoxRight: 0,
|
|
21
|
+
fontBoundingBoxAscent: 0,
|
|
22
|
+
fontBoundingBoxDescent: 0,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const emptyTextMeasurementContext = {
|
|
26
|
+
measureText: () => emptyTextMetrics,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function installVexflowReactNativeFallbacks(): void {
|
|
30
|
+
'worklet';
|
|
31
|
+
|
|
32
|
+
if (fallbackInstalled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ('document' in globalThis) {
|
|
41
|
+
fallbackInstalled = true;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Font.fromCSSString = ((cssFontShorthand: string) =>
|
|
46
|
+
parseCssFontShorthand(cssFontShorthand)) as typeof Font.fromCSSString;
|
|
47
|
+
|
|
48
|
+
fallbackInstalled = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function ensureVexflowTextMeasurementCanvas(): void {
|
|
52
|
+
'worklet';
|
|
53
|
+
|
|
54
|
+
if (textMeasurementCanvasInstalled) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const existingCanvas = Element.getTextMeasurementCanvas();
|
|
59
|
+
const existingContext = existingCanvas?.getContext(
|
|
60
|
+
'2d' as unknown as 'webgpu'
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (existingContext) {
|
|
64
|
+
textMeasurementCanvasInstalled = true;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ('document' in globalThis) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Element.setTextMeasurementCanvas({
|
|
73
|
+
getContext: (type: string) => {
|
|
74
|
+
if (type === '2d') {
|
|
75
|
+
return emptyTextMeasurementContext;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return null;
|
|
79
|
+
},
|
|
80
|
+
} as unknown as HTMLCanvasElement);
|
|
81
|
+
textMeasurementCanvasInstalled = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseCssFontShorthand(cssFontShorthand: string): Required<FontInfo> {
|
|
85
|
+
const source = cssFontShorthand.trim();
|
|
86
|
+
|
|
87
|
+
if (source.length === 0) {
|
|
88
|
+
return emptyFontInfo();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const sizeMatch = source.match(FONT_SIZE_PATTERN);
|
|
92
|
+
|
|
93
|
+
if (!sizeMatch || sizeMatch.index === undefined) {
|
|
94
|
+
return emptyFontInfo();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const prefix = source.slice(0, sizeMatch.index).trim();
|
|
98
|
+
const family = source.slice(sizeMatch.index + sizeMatch[0].length).trim();
|
|
99
|
+
const style =
|
|
100
|
+
prefix.match(FONT_STYLE_PATTERN)?.[1]?.toLowerCase() ?? 'normal';
|
|
101
|
+
const weight =
|
|
102
|
+
prefix.match(FONT_WEIGHT_PATTERN)?.[1]?.toLowerCase() ?? 'normal';
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
family,
|
|
106
|
+
size: sizeMatch[1] ?? '',
|
|
107
|
+
weight,
|
|
108
|
+
style,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function emptyFontInfo(): Required<FontInfo> {
|
|
113
|
+
return {
|
|
114
|
+
family: '',
|
|
115
|
+
size: '',
|
|
116
|
+
weight: '',
|
|
117
|
+
style: '',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const __test__ = {
|
|
122
|
+
originalFromCSSString,
|
|
123
|
+
parseCssFontShorthand,
|
|
124
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SkTypefaceFontProvider } from '@shopify/react-native-skia';
|
|
2
|
+
import type VexflowRecordingContext from './VexflowRecordingContext';
|
|
3
|
+
|
|
4
|
+
export interface OnDrawParams {
|
|
5
|
+
ctx: VexflowRecordingContext;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface VexflowCanvasProps {
|
|
11
|
+
onDraw: (params: OnDrawParams) => void;
|
|
12
|
+
fontManager: SkTypefaceFontProvider;
|
|
13
|
+
defaultFont: string;
|
|
14
|
+
// width?: number;
|
|
15
|
+
// height?: number;
|
|
16
|
+
// colorScheme?: 'light' | 'dark';
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Basic color name support (limited to a few common colors for now)
|
|
2
|
+
const colorMap: Record<string, string> = {
|
|
3
|
+
black: '#000000',
|
|
4
|
+
white: '#FFFFFF',
|
|
5
|
+
red: '#FF0000',
|
|
6
|
+
green: '#00FF00',
|
|
7
|
+
blue: '#0000FF',
|
|
8
|
+
// Add more colors as needed
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function parseStyleToColor(style: string): string {
|
|
12
|
+
if (
|
|
13
|
+
style.startsWith('#') ||
|
|
14
|
+
style.startsWith('rgb') ||
|
|
15
|
+
style.startsWith('hsl')
|
|
16
|
+
) {
|
|
17
|
+
return style;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return colorMap[style.toLowerCase()] || '#000000'; // Default to black if unknown
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Dynamic,
|
|
3
|
+
Measure,
|
|
4
|
+
NoteAttachment,
|
|
5
|
+
ScoreDefaults,
|
|
6
|
+
Slur,
|
|
7
|
+
Staff,
|
|
8
|
+
Tie,
|
|
9
|
+
TupletGroup,
|
|
10
|
+
} from '../../state';
|
|
11
|
+
|
|
12
|
+
export type PartInfo = {
|
|
13
|
+
id: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type StaffBuild = {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
order: number;
|
|
21
|
+
defaultClef?: Staff['defaultClef'];
|
|
22
|
+
measures: Measure[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type ActiveSpanner = {
|
|
26
|
+
itemId: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type ParserState = {
|
|
30
|
+
scoreId: string;
|
|
31
|
+
divisions: number;
|
|
32
|
+
defaults: ScoreDefaults;
|
|
33
|
+
attachments: NoteAttachment[];
|
|
34
|
+
ties: Tie[];
|
|
35
|
+
slurs: Slur[];
|
|
36
|
+
tuplets: TupletGroup[];
|
|
37
|
+
pendingDynamics: Map<string, Dynamic[]>;
|
|
38
|
+
activeTies: Map<string, ActiveSpanner>;
|
|
39
|
+
activeSlurs: Map<string, ActiveSpanner>;
|
|
40
|
+
activeTuplets: Map<string, TupletGroup>;
|
|
41
|
+
};
|