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,327 @@
|
|
|
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
|
+
VexflowStyleOverride,
|
|
22
|
+
} from './VexflowRecordingTypes';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Map a CSS `shadowBlur` (a blur radius in px) to a Gaussian sigma for Skia's
|
|
26
|
+
* drop-shadow filter. Canvas measures shadow blur as a radius; Skia's filter is
|
|
27
|
+
* parameterised by sigma. `radius / 2` is the conventional approximation used
|
|
28
|
+
* across Skia-backed canvas shims and gives a visually matching glow.
|
|
29
|
+
*/
|
|
30
|
+
function shadowBlurToSigma(shadowBlur: number): number {
|
|
31
|
+
'worklet';
|
|
32
|
+
|
|
33
|
+
return shadowBlur / 2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Apply the recorded glow (CSS shadow) to a Skia paint as a drop-shadow image
|
|
38
|
+
* filter. `dx = dy = 0` turns the drop shadow into a symmetric glow centred on
|
|
39
|
+
* the ink; `MakeDropShadow` (not `…Only`) keeps the source content, so the note
|
|
40
|
+
* still draws on top of its halo. No-op unless a `shadowColor` resolved.
|
|
41
|
+
*/
|
|
42
|
+
function applyGlow(skPaint: SkPaint, paint: VexflowRecordingPaint) {
|
|
43
|
+
'worklet';
|
|
44
|
+
|
|
45
|
+
if (paint.shadowColor == null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sigma = shadowBlurToSigma(paint.shadowBlur ?? 0);
|
|
50
|
+
|
|
51
|
+
skPaint.setImageFilter(
|
|
52
|
+
Skia.ImageFilter.MakeDropShadow(
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
sigma,
|
|
56
|
+
sigma,
|
|
57
|
+
Skia.Color(paint.shadowColor)
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function toSkiaRect(rect: VexflowRecordingRect) {
|
|
63
|
+
'worklet';
|
|
64
|
+
|
|
65
|
+
return Skia.XYWHRect(rect.x, rect.y, rect.width, rect.height);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
69
|
+
'worklet';
|
|
70
|
+
|
|
71
|
+
switch (cap) {
|
|
72
|
+
case 'round':
|
|
73
|
+
return StrokeCap.Round;
|
|
74
|
+
case 'square':
|
|
75
|
+
return StrokeCap.Square;
|
|
76
|
+
case 'butt':
|
|
77
|
+
default:
|
|
78
|
+
return StrokeCap.Butt;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createFillPaint(paint: VexflowRecordingPaint): SkPaint {
|
|
83
|
+
'worklet';
|
|
84
|
+
|
|
85
|
+
const skPaint = Skia.Paint();
|
|
86
|
+
skPaint.setStyle(PaintStyle.Fill);
|
|
87
|
+
skPaint.setAntiAlias(true);
|
|
88
|
+
skPaint.setColor(Skia.Color(paint.color));
|
|
89
|
+
applyGlow(skPaint, paint);
|
|
90
|
+
|
|
91
|
+
return skPaint;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function createStrokePaint(paint: VexflowRecordingPaint): SkPaint {
|
|
95
|
+
'worklet';
|
|
96
|
+
|
|
97
|
+
const skPaint = Skia.Paint();
|
|
98
|
+
skPaint.setStyle(PaintStyle.Stroke);
|
|
99
|
+
skPaint.setAntiAlias(true);
|
|
100
|
+
skPaint.setColor(Skia.Color(paint.color));
|
|
101
|
+
skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
|
|
102
|
+
skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
|
|
103
|
+
applyGlow(skPaint, paint);
|
|
104
|
+
|
|
105
|
+
if (paint.lineDash != null && paint.lineDash.length > 0) {
|
|
106
|
+
skPaint.setPathEffect(Skia.PathEffect.MakeDash(paint.lineDash));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return skPaint;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function createClearPaint(): SkPaint {
|
|
113
|
+
'worklet';
|
|
114
|
+
|
|
115
|
+
const clearPaint = Skia.Paint();
|
|
116
|
+
clearPaint.setBlendMode(BlendMode.Clear);
|
|
117
|
+
|
|
118
|
+
return clearPaint;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type PaintKind = 'fill' | 'stroke';
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Resolve a recorded paint against an optional per-group style override map
|
|
125
|
+
* (`groupId -> VexflowStyleOverride`), merging the override OVER the recorded
|
|
126
|
+
* paint. Returns the original paint object (referentially) when no override
|
|
127
|
+
* applies, so untagged chrome (staff lines, clefs, …) is never restyled and a
|
|
128
|
+
* replay with no `styleOverrides` is byte-identical to a faithful replay.
|
|
129
|
+
*
|
|
130
|
+
* `kind` disambiguates which colour field wins: a fill command reads
|
|
131
|
+
* `fillColor ?? color`, a stroke command reads `strokeColor ?? color`, each
|
|
132
|
+
* falling back to the recorded colour. Glow (shadow) is applied to both kinds so
|
|
133
|
+
* the whole note glows; dash is stroke-only. This is the seam that lets a single
|
|
134
|
+
* recording be replayed many times in different styles (e.g. per-frame from a
|
|
135
|
+
* shared value) without re-recording.
|
|
136
|
+
*/
|
|
137
|
+
function resolveStyle(
|
|
138
|
+
paint: VexflowRecordingPaint,
|
|
139
|
+
groupId: string | undefined,
|
|
140
|
+
kind: PaintKind,
|
|
141
|
+
styleOverrides?: Record<string, VexflowStyleOverride>
|
|
142
|
+
): VexflowRecordingPaint {
|
|
143
|
+
'worklet';
|
|
144
|
+
|
|
145
|
+
if (styleOverrides == null || groupId == null) {
|
|
146
|
+
return paint;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const override = styleOverrides[groupId];
|
|
150
|
+
|
|
151
|
+
if (override == null) {
|
|
152
|
+
return paint;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const color =
|
|
156
|
+
kind === 'fill'
|
|
157
|
+
? override.fillColor ?? override.color ?? paint.color
|
|
158
|
+
: override.strokeColor ?? override.color ?? paint.color;
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...paint,
|
|
162
|
+
color,
|
|
163
|
+
shadowColor: override.shadowColor ?? paint.shadowColor,
|
|
164
|
+
shadowBlur: override.shadowBlur ?? paint.shadowBlur,
|
|
165
|
+
// Dash is stroke-only; ignore any override.lineDash on fill commands.
|
|
166
|
+
lineDash:
|
|
167
|
+
kind === 'stroke' ? override.lineDash ?? paint.lineDash : paint.lineDash,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createFont(fontManager: FontManager, font: VexflowRecordingFont) {
|
|
172
|
+
'worklet';
|
|
173
|
+
|
|
174
|
+
return fontManager.createSkFont(
|
|
175
|
+
font.font,
|
|
176
|
+
font.size,
|
|
177
|
+
font.weight,
|
|
178
|
+
font.style
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function assertNever(value: never): never {
|
|
183
|
+
throw new Error(`Unexpected Vexflow recording command: ${String(value)}`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function applyPathCommand(
|
|
187
|
+
builder: SkPathBuilder,
|
|
188
|
+
command: VexflowRecordingPathCommand
|
|
189
|
+
) {
|
|
190
|
+
'worklet';
|
|
191
|
+
|
|
192
|
+
switch (command.type) {
|
|
193
|
+
case 'moveTo':
|
|
194
|
+
builder.moveTo(command.x, command.y);
|
|
195
|
+
break;
|
|
196
|
+
case 'lineTo':
|
|
197
|
+
builder.lineTo(command.x, command.y);
|
|
198
|
+
break;
|
|
199
|
+
case 'cubicTo':
|
|
200
|
+
builder.cubicTo(
|
|
201
|
+
command.cp1x,
|
|
202
|
+
command.cp1y,
|
|
203
|
+
command.cp2x,
|
|
204
|
+
command.cp2y,
|
|
205
|
+
command.x,
|
|
206
|
+
command.y
|
|
207
|
+
);
|
|
208
|
+
break;
|
|
209
|
+
case 'quadTo':
|
|
210
|
+
builder.quadTo(command.cpx, command.cpy, command.x, command.y);
|
|
211
|
+
break;
|
|
212
|
+
case 'addRect':
|
|
213
|
+
builder.addRect(toSkiaRect(command.rect));
|
|
214
|
+
break;
|
|
215
|
+
case 'addArc':
|
|
216
|
+
builder.addArc(
|
|
217
|
+
toSkiaRect(command.rect),
|
|
218
|
+
command.startDegrees,
|
|
219
|
+
command.sweepDegrees
|
|
220
|
+
);
|
|
221
|
+
break;
|
|
222
|
+
case 'close':
|
|
223
|
+
builder.close();
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
assertNever(command);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function buildPath(path: readonly VexflowRecordingPathCommand[]) {
|
|
231
|
+
'worklet';
|
|
232
|
+
|
|
233
|
+
const builder = Skia.PathBuilder.Make();
|
|
234
|
+
|
|
235
|
+
for (const command of path) {
|
|
236
|
+
applyPathCommand(builder, command);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return builder.build();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function renderVexflowRecordingCommands(
|
|
243
|
+
canvas: SkCanvas,
|
|
244
|
+
commands: readonly VexflowRecordingCommand[],
|
|
245
|
+
fontProvider: SkTypefaceFontProvider,
|
|
246
|
+
defaultFont: string,
|
|
247
|
+
/**
|
|
248
|
+
* Optional `groupId -> VexflowStyleOverride` map. Commands tagged (via
|
|
249
|
+
* `beginColorGroup`/`endColorGroup`) with a `groupId` present here are drawn
|
|
250
|
+
* with the override merged over their recorded paint — separate fill/stroke
|
|
251
|
+
* colours, a glow (shadow), and a stroke dash are all expressible. Omit for a
|
|
252
|
+
* byte-identical replay of the recorded style.
|
|
253
|
+
*/
|
|
254
|
+
styleOverrides?: Record<string, VexflowStyleOverride>
|
|
255
|
+
) {
|
|
256
|
+
'worklet';
|
|
257
|
+
|
|
258
|
+
const fontManager = new FontManager(fontProvider, defaultFont);
|
|
259
|
+
|
|
260
|
+
for (const command of commands) {
|
|
261
|
+
switch (command.type) {
|
|
262
|
+
case 'clear':
|
|
263
|
+
canvas.clear(Skia.Color(command.color));
|
|
264
|
+
break;
|
|
265
|
+
case 'save':
|
|
266
|
+
canvas.save();
|
|
267
|
+
break;
|
|
268
|
+
case 'restore':
|
|
269
|
+
canvas.restore();
|
|
270
|
+
break;
|
|
271
|
+
case 'scale':
|
|
272
|
+
canvas.scale(command.x, command.y);
|
|
273
|
+
break;
|
|
274
|
+
case 'translate':
|
|
275
|
+
canvas.translate(command.x, command.y);
|
|
276
|
+
break;
|
|
277
|
+
case 'clipRect':
|
|
278
|
+
canvas.clipRect(toSkiaRect(command.rect), ClipOp.Intersect, true);
|
|
279
|
+
break;
|
|
280
|
+
case 'fillRect':
|
|
281
|
+
canvas.drawRect(
|
|
282
|
+
toSkiaRect(command.rect),
|
|
283
|
+
createFillPaint(
|
|
284
|
+
resolveStyle(command.paint, command.groupId, 'fill', styleOverrides)
|
|
285
|
+
)
|
|
286
|
+
);
|
|
287
|
+
break;
|
|
288
|
+
case 'clearRect':
|
|
289
|
+
canvas.drawRect(toSkiaRect(command.rect), createClearPaint());
|
|
290
|
+
break;
|
|
291
|
+
case 'fillPath':
|
|
292
|
+
canvas.drawPath(
|
|
293
|
+
buildPath(command.path),
|
|
294
|
+
createFillPaint(
|
|
295
|
+
resolveStyle(command.paint, command.groupId, 'fill', styleOverrides)
|
|
296
|
+
)
|
|
297
|
+
);
|
|
298
|
+
break;
|
|
299
|
+
case 'strokePath':
|
|
300
|
+
canvas.drawPath(
|
|
301
|
+
buildPath(command.path),
|
|
302
|
+
createStrokePaint(
|
|
303
|
+
resolveStyle(
|
|
304
|
+
command.paint,
|
|
305
|
+
command.groupId,
|
|
306
|
+
'stroke',
|
|
307
|
+
styleOverrides
|
|
308
|
+
)
|
|
309
|
+
)
|
|
310
|
+
);
|
|
311
|
+
break;
|
|
312
|
+
case 'fillText':
|
|
313
|
+
canvas.drawText(
|
|
314
|
+
command.text,
|
|
315
|
+
command.x,
|
|
316
|
+
command.y,
|
|
317
|
+
createFillPaint(
|
|
318
|
+
resolveStyle(command.paint, command.groupId, 'fill', styleOverrides)
|
|
319
|
+
),
|
|
320
|
+
createFont(fontManager, command.font)
|
|
321
|
+
);
|
|
322
|
+
break;
|
|
323
|
+
default:
|
|
324
|
+
assertNever(command);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
* Glow/shadow colour (CSS `shadowColor`). Recorded from
|
|
18
|
+
* `VexflowRecordingContext.setShadowColor`. Replayed in Skia as a drop-shadow
|
|
19
|
+
* image filter with `dx = dy = 0` (a glow around the ink), and overridable per
|
|
20
|
+
* group via `VexflowStyleOverride.shadowColor`.
|
|
21
|
+
*/
|
|
22
|
+
shadowColor?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Glow/shadow blur radius in px (CSS `shadowBlur`). Recorded from
|
|
25
|
+
* `VexflowRecordingContext.setShadowBlur`. Mapped to a Gaussian sigma of
|
|
26
|
+
* `shadowBlur / 2` at replay. Only takes effect when `shadowColor` is set.
|
|
27
|
+
*/
|
|
28
|
+
shadowBlur?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Dash pattern (CSS `setLineDash`), stroke only. Recorded from
|
|
31
|
+
* `VexflowRecordingContext.setLineDash`. Replayed as a Skia dash path effect
|
|
32
|
+
* and overridable per group via `VexflowStyleOverride.lineDash`.
|
|
33
|
+
*/
|
|
34
|
+
lineDash?: number[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A granular, disambiguated style override applied to every command sharing a
|
|
39
|
+
* `groupId` at replay (see `renderVexflowRecordingCommands`'s `styleOverrides`).
|
|
40
|
+
*
|
|
41
|
+
* Each field is merged OVER the recorded paint, so any field left undefined
|
|
42
|
+
* falls back to whatever was recorded. An override is resolved per command
|
|
43
|
+
* against the paint that command uses (fill vs stroke), which is why fill and
|
|
44
|
+
* stroke colours are separable here — the consumer can, e.g., fill a notehead
|
|
45
|
+
* green while stroking its stem red.
|
|
46
|
+
*/
|
|
47
|
+
export interface VexflowStyleOverride {
|
|
48
|
+
/** Fill paint colour (noteheads, rests, glyphs, filled shapes). */
|
|
49
|
+
fillColor?: string;
|
|
50
|
+
/** Stroke paint colour (stems, ledger lines, beam edges). */
|
|
51
|
+
strokeColor?: string;
|
|
52
|
+
/** Shorthand applied to both fill and stroke (lower precedence than the two above). */
|
|
53
|
+
color?: string;
|
|
54
|
+
/** Glow colour (CSS `shadowColor`), applied to both fill and stroke so the whole note glows. */
|
|
55
|
+
shadowColor?: string;
|
|
56
|
+
/** Glow blur radius in px (CSS `shadowBlur`). Only takes effect when a `shadowColor` resolves. */
|
|
57
|
+
shadowBlur?: number;
|
|
58
|
+
/** Dash pattern (stroke only). */
|
|
59
|
+
lineDash?: number[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface VexflowRecordingFont {
|
|
63
|
+
font?: string | FontInfo;
|
|
64
|
+
size?: string | number;
|
|
65
|
+
weight?: string | number;
|
|
66
|
+
style?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type VexflowRecordingPathCommand =
|
|
70
|
+
| {
|
|
71
|
+
type: 'moveTo';
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}
|
|
75
|
+
| {
|
|
76
|
+
type: 'lineTo';
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
}
|
|
80
|
+
| {
|
|
81
|
+
type: 'cubicTo';
|
|
82
|
+
cp1x: number;
|
|
83
|
+
cp1y: number;
|
|
84
|
+
cp2x: number;
|
|
85
|
+
cp2y: number;
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
}
|
|
89
|
+
| {
|
|
90
|
+
type: 'quadTo';
|
|
91
|
+
cpx: number;
|
|
92
|
+
cpy: number;
|
|
93
|
+
x: number;
|
|
94
|
+
y: number;
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
type: 'addRect';
|
|
98
|
+
rect: VexflowRecordingRect;
|
|
99
|
+
}
|
|
100
|
+
| {
|
|
101
|
+
type: 'addArc';
|
|
102
|
+
rect: VexflowRecordingRect;
|
|
103
|
+
startDegrees: number;
|
|
104
|
+
sweepDegrees: number;
|
|
105
|
+
}
|
|
106
|
+
| {
|
|
107
|
+
type: 'close';
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A recorded draw command. `groupId` (optional) is stamped by
|
|
112
|
+
* `beginColorGroup`/`endColorGroup` on the recording context: a replay can then
|
|
113
|
+
* recolor every command sharing a `groupId` from a `groupId -> color` override
|
|
114
|
+
* map without re-recording. Untagged commands (staff lines, clefs, …) are never
|
|
115
|
+
* overridden.
|
|
116
|
+
*/
|
|
117
|
+
export type VexflowRecordingCommand = { groupId?: string } & (
|
|
118
|
+
| {
|
|
119
|
+
type: 'clear';
|
|
120
|
+
color: string;
|
|
121
|
+
}
|
|
122
|
+
| {
|
|
123
|
+
type: 'save';
|
|
124
|
+
}
|
|
125
|
+
| {
|
|
126
|
+
type: 'restore';
|
|
127
|
+
}
|
|
128
|
+
| {
|
|
129
|
+
type: 'scale';
|
|
130
|
+
x: number;
|
|
131
|
+
y: number;
|
|
132
|
+
}
|
|
133
|
+
| {
|
|
134
|
+
type: 'translate';
|
|
135
|
+
x: number;
|
|
136
|
+
y: number;
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
type: 'clipRect';
|
|
140
|
+
rect: VexflowRecordingRect;
|
|
141
|
+
}
|
|
142
|
+
| {
|
|
143
|
+
type: 'fillRect';
|
|
144
|
+
rect: VexflowRecordingRect;
|
|
145
|
+
paint: VexflowRecordingPaint;
|
|
146
|
+
}
|
|
147
|
+
| {
|
|
148
|
+
type: 'clearRect';
|
|
149
|
+
rect: VexflowRecordingRect;
|
|
150
|
+
}
|
|
151
|
+
| {
|
|
152
|
+
type: 'fillPath';
|
|
153
|
+
path: VexflowRecordingPathCommand[];
|
|
154
|
+
paint: VexflowRecordingPaint;
|
|
155
|
+
}
|
|
156
|
+
| {
|
|
157
|
+
type: 'strokePath';
|
|
158
|
+
path: VexflowRecordingPathCommand[];
|
|
159
|
+
paint: VexflowRecordingPaint;
|
|
160
|
+
}
|
|
161
|
+
| {
|
|
162
|
+
type: 'fillText';
|
|
163
|
+
text: string;
|
|
164
|
+
x: number;
|
|
165
|
+
y: number;
|
|
166
|
+
paint: VexflowRecordingPaint;
|
|
167
|
+
font: VexflowRecordingFont;
|
|
168
|
+
}
|
|
169
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as VexflowCanvas } from './VexflowCanvas';
|
|
2
|
+
export { default as VexflowRecordingContext } from './VexflowRecordingContext';
|
|
3
|
+
export { renderVexflowRecordingCommands } from './VexflowRecordingReplay';
|
|
4
|
+
|
|
5
|
+
export * from './VexflowColorScheme';
|
|
6
|
+
export * from './VexflowRecordingTypes';
|
|
7
|
+
export * from './types';
|
|
@@ -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
|
+
};
|