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
package/src/VexflowCanvas.tsx
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Canvas,
|
|
3
|
-
Picture,
|
|
4
|
-
Skia,
|
|
5
|
-
useFont,
|
|
6
|
-
type SkFont,
|
|
7
|
-
type SkPicture,
|
|
8
|
-
} from '@shopify/react-native-skia';
|
|
9
|
-
import { useMemo } from 'react';
|
|
10
|
-
import { Element } from 'vexflow';
|
|
11
|
-
import { Text, useWindowDimensions } from 'react-native';
|
|
12
|
-
|
|
13
|
-
import SkiaVexflowContext from './SkiaVexflowContext';
|
|
14
|
-
import { VEXFLOW_SCORE_COLORS } from './constants';
|
|
15
|
-
import { createFont, getAdvanceWidth, parseCssFontShorthand } from './utils';
|
|
16
|
-
|
|
17
|
-
const CANVAS_HEIGHT = 180;
|
|
18
|
-
|
|
19
|
-
export type VexflowCanvasDrawArgs = {
|
|
20
|
-
ctx: SkiaVexflowContext;
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type VexflowCanvasProps = {
|
|
26
|
-
onDraw: (args: VexflowCanvasDrawArgs) => void;
|
|
27
|
-
width?: number;
|
|
28
|
-
height?: number;
|
|
29
|
-
colorScheme?: 'light' | 'dark';
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function createTextMeasurementCanvas(bravuraFont: SkFont | null) {
|
|
33
|
-
let currentFont = createFont(12, 'Bravura', bravuraFont);
|
|
34
|
-
|
|
35
|
-
const measureContext = {
|
|
36
|
-
measureText: (text: string) => {
|
|
37
|
-
const rect = currentFont.measureText(text);
|
|
38
|
-
const width = getAdvanceWidth(currentFont, text);
|
|
39
|
-
const ascent = Math.max(0, -rect.y);
|
|
40
|
-
const descent = Math.max(0, rect.y + rect.height);
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
width,
|
|
44
|
-
actualBoundingBoxAscent: ascent,
|
|
45
|
-
actualBoundingBoxDescent: descent,
|
|
46
|
-
fontBoundingBoxAscent: ascent,
|
|
47
|
-
fontBoundingBoxDescent: descent,
|
|
48
|
-
actualBoundingBoxLeft: rect.x,
|
|
49
|
-
actualBoundingBoxRight: rect.x + rect.width,
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
Object.defineProperty(measureContext, 'font', {
|
|
55
|
-
get() {
|
|
56
|
-
return '';
|
|
57
|
-
},
|
|
58
|
-
set(value: string) {
|
|
59
|
-
try {
|
|
60
|
-
const parsed = parseCssFontShorthand(value);
|
|
61
|
-
currentFont = createFont(parsed.sizePx, parsed.family, bravuraFont);
|
|
62
|
-
} catch {
|
|
63
|
-
currentFont = createFont(12, 'Bravura', bravuraFont);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
getContext: (type: string) =>
|
|
70
|
-
type === '2d' ? (measureContext as any) : null,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function createVexflowPicture(
|
|
75
|
-
width: number,
|
|
76
|
-
height: number,
|
|
77
|
-
onDraw: (args: VexflowCanvasDrawArgs) => void,
|
|
78
|
-
bravuraFont: SkFont | null,
|
|
79
|
-
scoreColors: {
|
|
80
|
-
fill: string;
|
|
81
|
-
stroke: string;
|
|
82
|
-
}
|
|
83
|
-
): SkPicture {
|
|
84
|
-
const recorder = Skia.PictureRecorder();
|
|
85
|
-
const canvas = recorder.beginRecording(Skia.XYWHRect(0, 0, width, height));
|
|
86
|
-
|
|
87
|
-
const ctx = new SkiaVexflowContext(canvas, bravuraFont, {
|
|
88
|
-
defaultFillStyle: scoreColors.fill,
|
|
89
|
-
defaultStrokeStyle: scoreColors.stroke,
|
|
90
|
-
});
|
|
91
|
-
onDraw({ ctx, width, height });
|
|
92
|
-
|
|
93
|
-
return recorder.finishRecordingAsPicture();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default function VexflowCanvas({
|
|
97
|
-
onDraw,
|
|
98
|
-
width,
|
|
99
|
-
height = CANVAS_HEIGHT,
|
|
100
|
-
colorScheme = 'light',
|
|
101
|
-
}: VexflowCanvasProps) {
|
|
102
|
-
const { width: windowWidth } = useWindowDimensions();
|
|
103
|
-
const scoreColors =
|
|
104
|
-
colorScheme === 'dark'
|
|
105
|
-
? VEXFLOW_SCORE_COLORS.dark
|
|
106
|
-
: VEXFLOW_SCORE_COLORS.light;
|
|
107
|
-
|
|
108
|
-
const canvasWidth = width ?? Math.max(300, Math.floor(windowWidth) - 32);
|
|
109
|
-
const bravuraFont = useFont(require('@assets/fonts/Bravura.otf'), 30);
|
|
110
|
-
|
|
111
|
-
const pictureInfo = useMemo(() => {
|
|
112
|
-
if (!bravuraFont) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
Element.setTextMeasurementCanvas(
|
|
117
|
-
createTextMeasurementCanvas(bravuraFont) as unknown as HTMLCanvasElement
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const picture = createVexflowPicture(
|
|
121
|
-
canvasWidth,
|
|
122
|
-
height,
|
|
123
|
-
onDraw,
|
|
124
|
-
bravuraFont,
|
|
125
|
-
scoreColors
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return { picture, width: canvasWidth, height };
|
|
129
|
-
}, [bravuraFont, canvasWidth, height, onDraw, scoreColors]);
|
|
130
|
-
|
|
131
|
-
if (!pictureInfo) {
|
|
132
|
-
return <Text>Loading Bravura font...</Text>;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<Canvas style={{ width: pictureInfo.width, height: pictureInfo.height }}>
|
|
137
|
-
<Picture picture={pictureInfo.picture} />
|
|
138
|
-
</Canvas>
|
|
139
|
-
);
|
|
140
|
-
}
|
package/src/colorUtils.test.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
|
|
3
|
-
import { resolveScoreColor } from './colorUtils';
|
|
4
|
-
|
|
5
|
-
describe('resolveScoreColor', () => {
|
|
6
|
-
it('maps black tokens to active theme score color', () => {
|
|
7
|
-
const themeColor = '#F9FAFB';
|
|
8
|
-
|
|
9
|
-
expect(resolveScoreColor('black', themeColor)).toBe(themeColor);
|
|
10
|
-
expect(resolveScoreColor('#000', themeColor)).toBe(themeColor);
|
|
11
|
-
expect(resolveScoreColor('#000000', themeColor)).toBe(themeColor);
|
|
12
|
-
expect(resolveScoreColor('rgb(0, 0, 0)', themeColor)).toBe(themeColor);
|
|
13
|
-
expect(resolveScoreColor('rgba(0, 0, 0, 1)', themeColor)).toBe(themeColor);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('maps VexFlow default ledger line tokens to active theme score color', () => {
|
|
17
|
-
const themeColor = '#F9FAFB';
|
|
18
|
-
|
|
19
|
-
expect(resolveScoreColor('#444', themeColor)).toBe(themeColor);
|
|
20
|
-
expect(resolveScoreColor('#444444', themeColor)).toBe(themeColor);
|
|
21
|
-
expect(resolveScoreColor('rgb(68, 68, 68)', themeColor)).toBe(themeColor);
|
|
22
|
-
expect(resolveScoreColor('rgba(68, 68, 68, 1)', themeColor)).toBe(
|
|
23
|
-
themeColor
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('maps VexFlow default tab stave and bend tokens to active theme score color', () => {
|
|
28
|
-
const themeColor = '#F9FAFB';
|
|
29
|
-
|
|
30
|
-
expect(resolveScoreColor('#777', themeColor)).toBe(themeColor);
|
|
31
|
-
expect(resolveScoreColor('#777777', themeColor)).toBe(themeColor);
|
|
32
|
-
expect(resolveScoreColor('rgb(119, 119, 119)', themeColor)).toBe(
|
|
33
|
-
themeColor
|
|
34
|
-
);
|
|
35
|
-
expect(resolveScoreColor('rgba(119, 119, 119, 1)', themeColor)).toBe(
|
|
36
|
-
themeColor
|
|
37
|
-
);
|
|
38
|
-
expect(resolveScoreColor('#999', themeColor)).toBe(themeColor);
|
|
39
|
-
expect(resolveScoreColor('#999999', themeColor)).toBe(themeColor);
|
|
40
|
-
expect(resolveScoreColor('rgb(153, 153, 153)', themeColor)).toBe(
|
|
41
|
-
themeColor
|
|
42
|
-
);
|
|
43
|
-
expect(resolveScoreColor('rgba(153, 153, 153, 1)', themeColor)).toBe(
|
|
44
|
-
themeColor
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('preserves non-black custom colors', () => {
|
|
49
|
-
const themeColor = '#F9FAFB';
|
|
50
|
-
expect(resolveScoreColor('#ef4444', themeColor)).toBe('#ef4444');
|
|
51
|
-
});
|
|
52
|
-
});
|
package/src/colorUtils.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const SCORE_THEME_HEX_TOKENS = new Set([
|
|
2
|
-
'#000',
|
|
3
|
-
'#000000',
|
|
4
|
-
'#444',
|
|
5
|
-
'#444444',
|
|
6
|
-
'#777',
|
|
7
|
-
'#777777',
|
|
8
|
-
'#999',
|
|
9
|
-
'#999999',
|
|
10
|
-
]);
|
|
11
|
-
const BLACK_KEYWORD = 'black';
|
|
12
|
-
const BLACK_RGB_REGEX = /^rgb\(0,0,0\)$/;
|
|
13
|
-
const BLACK_RGBA_REGEX = /^rgba\(0,0,0,(1|1\.0+|0?\.\d+)\)$/;
|
|
14
|
-
const LEDGER_RGB_REGEX = /^rgb\(68,68,68\)$/;
|
|
15
|
-
const LEDGER_RGBA_REGEX = /^rgba\(68,68,68,(1|1\.0+|0?\.\d+)\)$/;
|
|
16
|
-
const BEND_RGB_REGEX = /^rgb\(119,119,119\)$/;
|
|
17
|
-
const BEND_RGBA_REGEX = /^rgba\(119,119,119,(1|1\.0+|0?\.\d+)\)$/;
|
|
18
|
-
const TAB_STAVE_RGB_REGEX = /^rgb\(153,153,153\)$/;
|
|
19
|
-
const TAB_STAVE_RGBA_REGEX = /^rgba\(153,153,153,(1|1\.0+|0?\.\d+)\)$/;
|
|
20
|
-
|
|
21
|
-
function normalizeColorToken(style: string): string {
|
|
22
|
-
return style.trim().toLowerCase().replace(/\s+/g, '');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isBlackColorToken(style: string): boolean {
|
|
26
|
-
const normalized = normalizeColorToken(style);
|
|
27
|
-
|
|
28
|
-
if (SCORE_THEME_HEX_TOKENS.has(normalized) || normalized === BLACK_KEYWORD) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
BLACK_RGB_REGEX.test(normalized) ||
|
|
34
|
-
BLACK_RGBA_REGEX.test(normalized) ||
|
|
35
|
-
LEDGER_RGB_REGEX.test(normalized) ||
|
|
36
|
-
LEDGER_RGBA_REGEX.test(normalized) ||
|
|
37
|
-
BEND_RGB_REGEX.test(normalized) ||
|
|
38
|
-
BEND_RGBA_REGEX.test(normalized) ||
|
|
39
|
-
TAB_STAVE_RGB_REGEX.test(normalized) ||
|
|
40
|
-
TAB_STAVE_RGBA_REGEX.test(normalized)
|
|
41
|
-
) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Replaces VexFlow default black values with the active score theme color.
|
|
49
|
-
export function resolveScoreColor(style: string, themeColor: string): string {
|
|
50
|
-
if (isBlackColorToken(style)) {
|
|
51
|
-
return themeColor;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return style;
|
|
55
|
-
}
|
package/src/constants.tsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type SkFont, StrokeCap, StrokeJoin } from '@shopify/react-native-skia';
|
|
2
|
-
import { type LineCap, type LineJoin } from './types';
|
|
3
|
-
|
|
4
|
-
export const PT_TO_PX = 4 / 3;
|
|
5
|
-
|
|
6
|
-
export const VEXFLOW_SCORE_COLORS = {
|
|
7
|
-
light: {
|
|
8
|
-
fill: '#111827',
|
|
9
|
-
stroke: '#111827',
|
|
10
|
-
},
|
|
11
|
-
dark: {
|
|
12
|
-
fill: '#F9FAFB',
|
|
13
|
-
stroke: '#F9FAFB',
|
|
14
|
-
},
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
export const DEFAULT_FILL_STYLE = VEXFLOW_SCORE_COLORS.light.fill;
|
|
18
|
-
export const DEFAULT_STROKE_STYLE = VEXFLOW_SCORE_COLORS.light.stroke;
|
|
19
|
-
export const DEFAULT_LINE_WIDTH = 1;
|
|
20
|
-
export const DEFAULT_FONT = '12px Bravura';
|
|
21
|
-
|
|
22
|
-
export const LINE_CAP_MAP: Record<LineCap, StrokeCap> = {
|
|
23
|
-
butt: StrokeCap.Butt,
|
|
24
|
-
round: StrokeCap.Round,
|
|
25
|
-
square: StrokeCap.Square,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const LINE_JOIN_MAP: Record<LineJoin, StrokeJoin> = {
|
|
29
|
-
miter: StrokeJoin.Miter,
|
|
30
|
-
round: StrokeJoin.Round,
|
|
31
|
-
bevel: StrokeJoin.Bevel,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const fontCache = new Map<string, SkFont>();
|
package/src/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './constants';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export * from './utils';
|
|
4
|
-
|
|
5
|
-
export { default as SkiaVexflowContext } from './SkiaVexflowContext';
|
|
6
|
-
export { default as VexflowCanvas } from './VexflowCanvas';
|
|
7
|
-
|
|
8
|
-
export type { VexflowCanvasDrawArgs } from './VexflowCanvas';
|