vexflow-native 0.2.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 +265 -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 +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 -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
package/README.md
CHANGED
|
@@ -1,77 +1,305 @@
|
|
|
1
1
|
# vexflow-native
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## What This Library Provides
|
|
6
|
-
|
|
7
|
-
- `VexflowCanvas`: React component that creates a Skia canvas and gives you a VexFlow-compatible render context.
|
|
8
|
-
- `SkiaVexflowContext`: low-level context implementation (you usually do not need to use it directly).
|
|
3
|
+
React Native Skia bridge for rendering VexFlow music notation.
|
|
9
4
|
|
|
10
5
|
## Installation
|
|
11
6
|
|
|
12
7
|
Install the library and its peer dependencies:
|
|
13
8
|
|
|
14
9
|
```sh
|
|
15
|
-
npm install vexflow-native vexflow @shopify/react-native-skia
|
|
10
|
+
npm install vexflow-native react react-native vexflow @shopify/react-native-skia react-native-gesture-handler react-native-reanimated react-native-worklets
|
|
16
11
|
```
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
`ScoreRenderer` uses gesture handling and Reanimated worklets for scrolling, so
|
|
14
|
+
configure `react-native-gesture-handler`, `react-native-reanimated`, and
|
|
15
|
+
`react-native-worklets` as required by your React Native app.
|
|
16
|
+
|
|
17
|
+
## Entrypoints
|
|
18
|
+
|
|
19
|
+
- `vexflow-native` exports the low-level `VexflowCanvas` bridge for drawing with
|
|
20
|
+
VexFlow directly.
|
|
21
|
+
- `vexflow-native/renderer` exports `ScoreRenderer`, a React component that
|
|
22
|
+
renders the typed score model.
|
|
23
|
+
- `vexflow-native/state` exports the score state types, including `Score`.
|
|
24
|
+
- `vexflow-native/musicxml` exports `parseMusicXmlToScore` and
|
|
25
|
+
`MusicXmlParseError`.
|
|
26
|
+
|
|
27
|
+
## Fonts
|
|
28
|
+
|
|
29
|
+
Load a notation font with Skia and pass the returned font provider to the
|
|
30
|
+
renderer. The `defaultFont` prop must match one of the font family names passed
|
|
31
|
+
to `useFonts`.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { useFonts } from '@shopify/react-native-skia';
|
|
35
|
+
|
|
36
|
+
import bravuraFont from './assets/fonts/Bravura.otf';
|
|
37
|
+
|
|
38
|
+
const fontManager = useFonts({
|
|
39
|
+
Bravura: [bravuraFont],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!fontManager) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## React Native Skia web patches
|
|
48
|
+
|
|
49
|
+
The example app includes a `patch-package` patch for
|
|
50
|
+
`@shopify/react-native-skia@2.6.2` at
|
|
51
|
+
`example/patches/@shopify+react-native-skia+2.6.2.patch`. The repository root
|
|
52
|
+
applies it after install with:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
yarn workspace vexflow-native-example apply-patches
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The patch is needed by the web example with this Skia version. It:
|
|
59
|
+
|
|
60
|
+
- lets Skia web resolve string asset sources;
|
|
61
|
+
- forwards `JsiSkTypefaceFontProvider.matchFamilyStyle` to CanvasKit so fonts
|
|
62
|
+
registered with `useFonts` can be matched by family name;
|
|
63
|
+
- keeps a small diagnostic log in the web font manager patch.
|
|
64
|
+
|
|
65
|
+
Native iOS and Android usage does not need this example patch. If your own app
|
|
66
|
+
targets React Native Web with `@shopify/react-native-skia@2.6.2` and hits font
|
|
67
|
+
matching or asset source issues, apply an equivalent patch in your app with
|
|
68
|
+
`patch-package`. Re-check the patch when upgrading Skia, because it is tied to
|
|
69
|
+
that package version and may become unnecessary after upstream changes.
|
|
70
|
+
|
|
71
|
+
## Render MusicXML
|
|
72
|
+
|
|
73
|
+
Convert a MusicXML string into a `Score`, then render it with `ScoreRenderer`.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import React, { useMemo } from 'react';
|
|
77
|
+
import { View } from 'react-native';
|
|
78
|
+
import { useFonts } from '@shopify/react-native-skia';
|
|
79
|
+
import { ScoreRenderer } from 'vexflow-native/renderer';
|
|
80
|
+
import {
|
|
81
|
+
MusicXmlParseError,
|
|
82
|
+
parseMusicXmlToScore,
|
|
83
|
+
} from 'vexflow-native/musicxml';
|
|
84
|
+
|
|
85
|
+
import bravuraFont from './assets/fonts/Bravura.otf';
|
|
86
|
+
|
|
87
|
+
type MusicXmlScoreProps = {
|
|
88
|
+
xml: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export function MusicXmlScore({ xml }: MusicXmlScoreProps) {
|
|
92
|
+
const fontManager = useFonts({
|
|
93
|
+
Bravura: [bravuraFont],
|
|
94
|
+
});
|
|
95
|
+
const score = useMemo(
|
|
96
|
+
() => parseMusicXmlToScore(xml, { scoreId: 'imported-score' }),
|
|
97
|
+
[xml]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (!fontManager) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<View style={{ flex: 1 }}>
|
|
106
|
+
<ScoreRenderer
|
|
107
|
+
score={score}
|
|
108
|
+
defaultFont="Bravura"
|
|
109
|
+
fontManager={fontManager}
|
|
110
|
+
/>
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
parseMusicXmlToScore('<score-timewise />');
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error instanceof MusicXmlParseError) {
|
|
119
|
+
// The current parser targets score-partwise MusicXML.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The MusicXML parser currently targets `score-partwise` documents. `score-timewise`
|
|
125
|
+
input throws `MusicXmlParseError`.
|
|
126
|
+
|
|
127
|
+
## Render a Plain Score Object
|
|
128
|
+
|
|
129
|
+
Use `ScoreRenderer` directly when you already have score state or want to build
|
|
130
|
+
it yourself.
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import React from 'react';
|
|
134
|
+
import { View } from 'react-native';
|
|
135
|
+
import { useFonts } from '@shopify/react-native-skia';
|
|
136
|
+
import { ScoreRenderer } from 'vexflow-native/renderer';
|
|
137
|
+
import type { Score } from 'vexflow-native/state';
|
|
138
|
+
|
|
139
|
+
import bravuraFont from './assets/fonts/Bravura.otf';
|
|
140
|
+
|
|
141
|
+
const score: Score = {
|
|
142
|
+
id: 'plain-score',
|
|
143
|
+
defaults: {
|
|
144
|
+
meter: {
|
|
145
|
+
beats: 4,
|
|
146
|
+
beatUnit: 4,
|
|
147
|
+
},
|
|
148
|
+
keySignature: {
|
|
149
|
+
tonic: 'C',
|
|
150
|
+
mode: 'major',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
staves: [
|
|
154
|
+
{
|
|
155
|
+
id: 'staff-1',
|
|
156
|
+
order: 0,
|
|
157
|
+
defaultClef: 'treble',
|
|
158
|
+
measures: [
|
|
159
|
+
{
|
|
160
|
+
id: 'measure-1',
|
|
161
|
+
number: 1,
|
|
162
|
+
leftModifiers: {
|
|
163
|
+
showClef: true,
|
|
164
|
+
showKeySignature: true,
|
|
165
|
+
showMeter: true,
|
|
166
|
+
},
|
|
167
|
+
voices: [
|
|
168
|
+
{
|
|
169
|
+
id: 'voice-1',
|
|
170
|
+
index: 0,
|
|
171
|
+
items: [
|
|
172
|
+
{
|
|
173
|
+
id: 'note-1',
|
|
174
|
+
type: 'note',
|
|
175
|
+
pitch: { step: 'C', octave: 4 },
|
|
176
|
+
duration: { length: 'q' },
|
|
177
|
+
voiceId: 'voice-1',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: 'note-2',
|
|
181
|
+
type: 'note',
|
|
182
|
+
pitch: { step: 'D', octave: 4 },
|
|
183
|
+
duration: { length: 'q' },
|
|
184
|
+
voiceId: 'voice-1',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'note-3',
|
|
188
|
+
type: 'note',
|
|
189
|
+
pitch: { step: 'E', octave: 4 },
|
|
190
|
+
duration: { length: 'q' },
|
|
191
|
+
voiceId: 'voice-1',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: 'note-4',
|
|
195
|
+
type: 'note',
|
|
196
|
+
pitch: { step: 'F', octave: 4 },
|
|
197
|
+
duration: { length: 'q' },
|
|
198
|
+
voiceId: 'voice-1',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export function PlainScore() {
|
|
210
|
+
const fontManager = useFonts({
|
|
211
|
+
Bravura: [bravuraFont],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (!fontManager) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<View style={{ flex: 1 }}>
|
|
220
|
+
<ScoreRenderer
|
|
221
|
+
score={score}
|
|
222
|
+
defaultFont="Bravura"
|
|
223
|
+
fontManager={fontManager}
|
|
224
|
+
rendererType="document"
|
|
225
|
+
/>
|
|
226
|
+
</View>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
`rendererType` is optional. The default is `document`; use `documentEven` for
|
|
232
|
+
even measure widths across document systems, or `infiniteScore` for a horizontal
|
|
233
|
+
single-system layout.
|
|
234
|
+
|
|
235
|
+
## Draw Directly with VexFlow
|
|
236
|
+
|
|
237
|
+
Use `VexflowCanvas` when you want direct VexFlow control instead of the typed
|
|
238
|
+
score model.
|
|
19
239
|
|
|
20
240
|
```tsx
|
|
21
241
|
import React, { useCallback } from 'react';
|
|
22
242
|
import { View } from 'react-native';
|
|
243
|
+
import { useFonts } from '@shopify/react-native-skia';
|
|
23
244
|
import { Formatter, Stave, StaveNote, Voice } from 'vexflow';
|
|
24
|
-
import { VexflowCanvas, type
|
|
245
|
+
import { VexflowCanvas, type OnDrawParams } from 'vexflow-native';
|
|
246
|
+
|
|
247
|
+
import bravuraFont from './assets/fonts/Bravura.otf';
|
|
25
248
|
|
|
26
|
-
export
|
|
27
|
-
const
|
|
249
|
+
export function DirectVexFlow() {
|
|
250
|
+
const fontManager = useFonts({
|
|
251
|
+
Bravura: [bravuraFont],
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const onDraw = useCallback(({ ctx }: OnDrawParams) => {
|
|
255
|
+
const stave = new Stave(10, 40, 400);
|
|
28
256
|
|
|
29
|
-
const onDraw = useCallback(({ ctx, width }: VexflowCanvasDrawArgs) => {
|
|
30
|
-
const stave = new Stave(10, 40, width - 20);
|
|
31
257
|
stave.addClef('treble').addTimeSignature('4/4');
|
|
32
|
-
stave.setContext(ctx).draw();
|
|
33
258
|
|
|
34
259
|
const notes = [
|
|
35
|
-
new StaveNote({
|
|
36
|
-
new StaveNote({
|
|
37
|
-
new StaveNote({
|
|
38
|
-
new StaveNote({
|
|
260
|
+
new StaveNote({ keys: ['c/4'], duration: 'q' }),
|
|
261
|
+
new StaveNote({ keys: ['d/4'], duration: 'q' }),
|
|
262
|
+
new StaveNote({ keys: ['e/4'], duration: 'q' }),
|
|
263
|
+
new StaveNote({ keys: ['f/4'], duration: 'q' }),
|
|
39
264
|
];
|
|
40
265
|
|
|
41
|
-
const voice = new Voice({
|
|
266
|
+
const voice = new Voice({ numBeats: 4, beatValue: 4 });
|
|
42
267
|
voice.addTickables(notes);
|
|
43
268
|
|
|
44
|
-
new Formatter().joinVoices([voice]).
|
|
269
|
+
new Formatter().joinVoices([voice]).formatToStave([voice], stave);
|
|
270
|
+
|
|
271
|
+
stave.setContext(ctx).draw();
|
|
45
272
|
voice.draw(ctx, stave);
|
|
46
273
|
}, []);
|
|
47
274
|
|
|
275
|
+
if (!fontManager) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
48
279
|
return (
|
|
49
|
-
<View style={{
|
|
280
|
+
<View style={{ flex: 1 }}>
|
|
50
281
|
<VexflowCanvas
|
|
51
282
|
onDraw={onDraw}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
colorScheme="light"
|
|
283
|
+
fontManager={fontManager}
|
|
284
|
+
defaultFont="Bravura"
|
|
55
285
|
/>
|
|
56
286
|
</View>
|
|
57
287
|
);
|
|
58
288
|
}
|
|
59
289
|
```
|
|
60
290
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
`VexflowCanvas` props:
|
|
64
|
-
|
|
65
|
-
- `onDraw: ({ ctx, width, height }) => void` (required)
|
|
66
|
-
- `font: require('.../Bravura.otf')` (required)
|
|
67
|
-
- `width?: number` (defaults to window width with internal margin)
|
|
68
|
-
- `height?: number` (default: `180`)
|
|
69
|
-
- `colorScheme?: 'light' | 'dark'` (default: `'light'`)
|
|
70
|
-
|
|
71
|
-
## Notes
|
|
291
|
+
## ScoreRenderer props
|
|
72
292
|
|
|
73
|
-
- `
|
|
74
|
-
-
|
|
293
|
+
- `score`: typed score state to render.
|
|
294
|
+
- `defaultFont`: font family name used as the default VexFlow font.
|
|
295
|
+
- `fontManager`: Skia font provider returned by `useFonts`.
|
|
296
|
+
- `colorScheme`: optional foreground, background, and ledger line colors.
|
|
297
|
+
- `rendererType`: `document`, `documentEven`, or `infiniteScore`.
|
|
298
|
+
- `options`: optional renderer settings grouped by `insets`, `spacing`, and
|
|
299
|
+
`render`.
|
|
300
|
+
- `scrollEnabled`: enables or disables pan scrolling. Defaults to `true`.
|
|
301
|
+
- `showScrollbars`: shows scrollbars when the score overflows. Defaults to
|
|
302
|
+
`true`.
|
|
75
303
|
|
|
76
304
|
## Contributing
|
|
77
305
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { FontWeight, FontSlant, FontWidth, Skia } from '@shopify/react-native-skia';
|
|
4
|
+
|
|
5
|
+
// import Logger, { LogCategory } from '../shared/Logger';
|
|
6
|
+
|
|
7
|
+
// const Log = Logger.extend(LogCategory.FontManager);
|
|
8
|
+
|
|
9
|
+
const PT_TO_PX = 4 / 3; // 1pt = 1.333px
|
|
10
|
+
|
|
11
|
+
function parseSize(size) {
|
|
12
|
+
'worklet';
|
|
13
|
+
|
|
14
|
+
if (typeof size === 'number') {
|
|
15
|
+
return size;
|
|
16
|
+
}
|
|
17
|
+
if (typeof size === 'string') {
|
|
18
|
+
const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt|em|%)?$/);
|
|
19
|
+
if (match) {
|
|
20
|
+
const value = parseFloat(match?.[1] || '30');
|
|
21
|
+
const unit = match[2] || 'pt';
|
|
22
|
+
switch (unit) {
|
|
23
|
+
case 'px':
|
|
24
|
+
return value * 0.75;
|
|
25
|
+
// 1px = 0.75pt
|
|
26
|
+
case 'em':
|
|
27
|
+
return value * 12;
|
|
28
|
+
// Assuming 1em = 16px = 12pt
|
|
29
|
+
case '%':
|
|
30
|
+
return value * 0.12;
|
|
31
|
+
// Assuming 100% = 12pt
|
|
32
|
+
case 'pt':
|
|
33
|
+
default:
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return 30; // Default font size in pixels
|
|
39
|
+
}
|
|
40
|
+
function parseWeight(weight) {
|
|
41
|
+
'worklet';
|
|
42
|
+
|
|
43
|
+
const weightStr = String(weight || 'normal').toLowerCase();
|
|
44
|
+
return {
|
|
45
|
+
'normal': FontWeight.Normal,
|
|
46
|
+
'bold': FontWeight.Bold,
|
|
47
|
+
'100': FontWeight.Thin,
|
|
48
|
+
'200': FontWeight.ExtraLight,
|
|
49
|
+
'300': FontWeight.Light,
|
|
50
|
+
'400': FontWeight.Normal,
|
|
51
|
+
'500': FontWeight.Medium,
|
|
52
|
+
'600': FontWeight.SemiBold,
|
|
53
|
+
'700': FontWeight.Bold,
|
|
54
|
+
'800': FontWeight.ExtraBold,
|
|
55
|
+
'900': FontWeight.Black
|
|
56
|
+
}[weightStr] || FontWeight.Normal;
|
|
57
|
+
}
|
|
58
|
+
function parseSlant(style) {
|
|
59
|
+
'worklet';
|
|
60
|
+
|
|
61
|
+
const styleStr = String(style || 'normal').toLowerCase();
|
|
62
|
+
return {
|
|
63
|
+
normal: FontSlant.Upright,
|
|
64
|
+
italic: FontSlant.Italic,
|
|
65
|
+
oblique: FontSlant.Oblique
|
|
66
|
+
}[styleStr] || FontSlant.Upright;
|
|
67
|
+
}
|
|
68
|
+
export default class FontManager {
|
|
69
|
+
__workletClass = true;
|
|
70
|
+
constructor(fontProvider, defaultFontName) {
|
|
71
|
+
this.fontProvider = fontProvider;
|
|
72
|
+
this.defaultFontName = defaultFontName;
|
|
73
|
+
const families = [];
|
|
74
|
+
for (let i = 0; i < fontProvider.countFamilies(); i++) {
|
|
75
|
+
families.push(fontProvider.getFamilyName(i));
|
|
76
|
+
}
|
|
77
|
+
if (!families.includes(defaultFontName)) {
|
|
78
|
+
throw new Error(`Default font "${defaultFontName}" is not available in the font provider. Available fonts: ${families.join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
isFamilyAvailable(family) {
|
|
82
|
+
for (let i = 0; i < this.fontProvider.countFamilies(); i++) {
|
|
83
|
+
if (this.fontProvider.getFamilyName(i).toLowerCase() === family.toLowerCase()) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
getFamiliesFromFont(font) {
|
|
90
|
+
if (typeof font === 'string') {
|
|
91
|
+
return font.split(',').map(f => f.trim());
|
|
92
|
+
}
|
|
93
|
+
return font.family ? font.family.split(',').map(f => f.trim()) : [];
|
|
94
|
+
}
|
|
95
|
+
matchFontFamilyName(font) {
|
|
96
|
+
if (!font) {
|
|
97
|
+
return this.defaultFontName;
|
|
98
|
+
}
|
|
99
|
+
const families = this.getFamiliesFromFont(font);
|
|
100
|
+
for (const family of families) {
|
|
101
|
+
if (this.isFamilyAvailable(family)) {
|
|
102
|
+
return family;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return this.defaultFontName;
|
|
106
|
+
}
|
|
107
|
+
resolveFontDescriptor(font, size, weight, style) {
|
|
108
|
+
return {
|
|
109
|
+
family: this.matchFontFamilyName(font || ''),
|
|
110
|
+
size: parseSize(typeof font === 'string' ? size : font.size || size),
|
|
111
|
+
weight: parseWeight(weight),
|
|
112
|
+
slant: parseSlant(style),
|
|
113
|
+
width: FontWidth.Normal
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
createSkFont(font, size, weight, style) {
|
|
117
|
+
const {
|
|
118
|
+
family,
|
|
119
|
+
size: resolvedSize,
|
|
120
|
+
weight: resolvedWeight,
|
|
121
|
+
slant
|
|
122
|
+
} = this.resolveFontDescriptor(font, size, weight, style);
|
|
123
|
+
const typeface = this.fontProvider.matchFamilyStyle(family, {
|
|
124
|
+
weight: resolvedWeight,
|
|
125
|
+
slant,
|
|
126
|
+
width: FontWidth.Normal
|
|
127
|
+
});
|
|
128
|
+
if (!typeface) {
|
|
129
|
+
throw new Error(`Failed to create SkFont. No matching typeface found for family "${family}" with weight "${resolvedWeight}" and slant "${slant}".`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Log.log(
|
|
133
|
+
// `Created SkFont with family "${family}", size ${resolvedSize}px, weight ${resolvedWeight}, slant ${slant}.`
|
|
134
|
+
// );
|
|
135
|
+
|
|
136
|
+
return Skia.Font(typeface, resolvedSize * PT_TO_PX); // Convert from points to pixels
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=FontManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FontWeight","FontSlant","FontWidth","Skia","PT_TO_PX","parseSize","size","match","trim","value","parseFloat","unit","parseWeight","weight","weightStr","String","toLowerCase","Normal","Bold","Thin","ExtraLight","Light","Medium","SemiBold","ExtraBold","Black","parseSlant","style","styleStr","normal","Upright","italic","Italic","oblique","Oblique","FontManager","__workletClass","constructor","fontProvider","defaultFontName","families","i","countFamilies","push","getFamilyName","includes","Error","join","isFamilyAvailable","family","getFamiliesFromFont","font","split","map","f","matchFontFamilyName","resolveFontDescriptor","slant","width","createSkFont","resolvedSize","resolvedWeight","typeface","matchFamilyStyle","Font"],"sourceRoot":"../../../src","sources":["base/FontManager.ts"],"mappings":";;AACA,SACEA,UAAU,EACVC,SAAS,EACTC,SAAS,EACTC,IAAI,QACC,4BAA4B;;AAMnC;;AAEA;;AAUA,MAAMC,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;;AAExB,SAASC,SAASA,CAACC,IAAsB,EAAU;EACjD,SAAS;;EAET,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI;EACb;EAEA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC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AM;MACN3C,IAAI,EAAEsD,YAAY;MAClB/C,MAAM,EAAEgD,cAAc;MACtBJ;IACF,CAAC,GAAG,IAAI,CAACD,qBAAqB,CAACL,IAAI,EAAE7C,IAAI,EAAEO,MAAM,EAAEc,KAAK,CAAC;IAEzD,MAAMmC,QAAQ,GAAG,IAAI,CAACxB,YAAY,CAACyB,gBAAgB,CAACd,MAAM,EAAE;MAC1DpC,MAAM,EAAEgD,cAAc;MACtBJ,KAAK;MACLC,KAAK,EAAExD,SAAS,CAACe;IACnB,CAAC,CAAC;IAEF,IAAI,CAAC6C,QAAQ,EAAE;MACb,MAAM,IAAIhB,KAAK,CACb,mEAAmEG,MAAM,kBAAkBY,cAAc,gBAAgBJ,KAAK,IAChI,CAAC;IACH;;IAEA;IACA;IACA;;IAEA,OAAOtD,IAAI,CAAC6D,IAAI,CAACF,QAAQ,EAAEF,YAAY,GAAGxD,QAAQ,CAAC,CAAC,CAAC;EACvD;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Font } from 'vexflow';
|
|
4
|
+
class TextMeasureContext {
|
|
5
|
+
__workletClass = true;
|
|
6
|
+
currentFont = '';
|
|
7
|
+
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
measureText(text) {
|
|
11
|
+
const currentFont = this.context.getCurrentSkFont();
|
|
12
|
+
const rect = currentFont.measureText(text);
|
|
13
|
+
const width = getAdvanceWidth(currentFont, text);
|
|
14
|
+
const ascent = Math.max(0, -rect.y);
|
|
15
|
+
const descent = Math.max(0, rect.y + rect.height);
|
|
16
|
+
return {
|
|
17
|
+
width,
|
|
18
|
+
actualBoundingBoxAscent: ascent,
|
|
19
|
+
actualBoundingBoxDescent: descent,
|
|
20
|
+
fontBoundingBoxAscent: ascent,
|
|
21
|
+
fontBoundingBoxDescent: descent,
|
|
22
|
+
actualBoundingBoxLeft: rect.x,
|
|
23
|
+
actualBoundingBoxRight: rect.x + rect.width
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
get() {
|
|
27
|
+
return this.currentFont;
|
|
28
|
+
}
|
|
29
|
+
set(value) {
|
|
30
|
+
this.currentFont = value;
|
|
31
|
+
this.context.setFont(Font.fromCSSString(value));
|
|
32
|
+
}
|
|
33
|
+
get font() {
|
|
34
|
+
return this.get();
|
|
35
|
+
}
|
|
36
|
+
set font(value) {
|
|
37
|
+
this.set(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default TextMeasureContext;
|
|
41
|
+
function getAdvanceWidth(font, text) {
|
|
42
|
+
const glyphs = font.getGlyphIDs(text);
|
|
43
|
+
const widths = font.getGlyphWidths(glyphs);
|
|
44
|
+
return widths.reduce((sum, width) => sum + width, 0);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=TextMeasureContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Font","TextMeasureContext","__workletClass","currentFont","constructor","context","measureText","text","getCurrentSkFont","rect","width","getAdvanceWidth","ascent","Math","max","y","descent","height","actualBoundingBoxAscent","actualBoundingBoxDescent","fontBoundingBoxAscent","fontBoundingBoxDescent","actualBoundingBoxLeft","x","actualBoundingBoxRight","get","set","value","setFont","fromCSSString","font","glyphs","getGlyphIDs","widths","getGlyphWidths","reduce","sum"],"sourceRoot":"../../../src","sources":["base/TextMeasureContext.ts"],"mappings":";;AACA,SAASA,IAAI,QAAQ,SAAS;AAG9B,MAAMC,kBAAkB,CAAC;EACvBC,cAAc,GAAG,IAAI;EAGbC,WAAW,GAAG,EAAE;EAExBC,WAAWA,CAACC,OAAgC,EAAE;IAC5C,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;EAEAC,WAAWA,CAACC,IAAY,EAAE;IACxB,MAAMJ,WAAW,GAAG,IAAI,CAACE,OAAO,CAACG,gBAAgB,CAAC,CAAC;IACnD,MAAMC,IAAI,GAAGN,WAAW,CAACG,WAAW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AAK0B,GAAG,GAAG1B,KAAK,EAAE,CAAC,CAAC;AACtD","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Canvas, Picture, Skia, useCanvasRef, useCanvasSize } from '@shopify/react-native-skia';
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
|
+
import { StyleSheet } from 'react-native';
|
|
6
|
+
import VexflowRecordingContext from "./VexflowRecordingContext.js";
|
|
7
|
+
import { renderVexflowRecordingCommands } from "./VexflowRecordingReplay.js";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
const VexflowCanvas = props => {
|
|
10
|
+
const {
|
|
11
|
+
onDraw,
|
|
12
|
+
fontManager,
|
|
13
|
+
defaultFont
|
|
14
|
+
// width: propWidth,
|
|
15
|
+
// height: propHeight,
|
|
16
|
+
// colorScheme = 'light',
|
|
17
|
+
} = props;
|
|
18
|
+
const canvasRef = useCanvasRef();
|
|
19
|
+
const {
|
|
20
|
+
size: canvasSize
|
|
21
|
+
} = useCanvasSize(canvasRef);
|
|
22
|
+
const picture = useMemo(() => {
|
|
23
|
+
const recorder = Skia.PictureRecorder();
|
|
24
|
+
const canvas = recorder.beginRecording(Skia.XYWHRect(0, 0, canvasSize.width, canvasSize.height));
|
|
25
|
+
const ctx = new VexflowRecordingContext(fontManager, defaultFont);
|
|
26
|
+
onDraw({
|
|
27
|
+
ctx,
|
|
28
|
+
width: canvasSize.width,
|
|
29
|
+
height: canvasSize.height
|
|
30
|
+
});
|
|
31
|
+
renderVexflowRecordingCommands(canvas, ctx.finish(), fontManager, defaultFont);
|
|
32
|
+
return recorder.finishRecordingAsPicture();
|
|
33
|
+
}, [onDraw, canvasSize, fontManager, defaultFont]);
|
|
34
|
+
return /*#__PURE__*/_jsx(Canvas, {
|
|
35
|
+
style: styles.canvas,
|
|
36
|
+
ref: canvasRef,
|
|
37
|
+
children: /*#__PURE__*/_jsx(Picture, {
|
|
38
|
+
picture: picture
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export default VexflowCanvas;
|
|
43
|
+
const styles = StyleSheet.create({
|
|
44
|
+
canvas: {
|
|
45
|
+
flex: 1 // TMP?
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=VexflowCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Canvas","Picture","Skia","useCanvasRef","useCanvasSize","React","useMemo","StyleSheet","VexflowRecordingContext","renderVexflowRecordingCommands","jsx","_jsx","VexflowCanvas","props","onDraw","fontManager","defaultFont","canvasRef","size","canvasSize","picture","recorder","PictureRecorder","canvas","beginRecording","XYWHRect","width","height","ctx","finish","finishRecordingAsPicture","style","styles","ref","children","create","flex"],"sourceRoot":"../../../src","sources":["base/VexflowCanvas.tsx"],"mappings":";;AAAA,SACEA,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,YAAY,EACZC,aAAa,QACR,4BAA4B;AACnC,OAAOC,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,UAAU,QAAQ,cAAc;AAGzC,OAAOC,uBAAuB,MAAM,8BAA2B;AAC/D,SAASC,8BAA8B,QAAQ,6BAA0B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE1E,MAAMC,aAA2C,GAAIC,KAAK,IAAK;EAC7D,MAAM;IACJC,MAAM;IACNC,WAAW;IACXC;IACA;IACA;IACA;EACF,CAAC,GAAGH,KAAK;EAET,MAAMI,SAAS,GAAGd,YAAY,CAAC,CAAC;EAChC,MAAM;IAAEe,IAAI,EAAEC;EAAW,CAAC,GAAGf,aAAa,CAACa,SAAS,CAAC;EAErD,MAAMG,OAAO,GAAGd,OAAO,CAAC,MAAM;IAC5B,MAAMe,QAAQ,GAAGnB,IAAI,CAACoB,eAAe,CAAC,CAAC;IACvC,MAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAc,CACpCtB,IAAI,CAACuB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAEN,UAAU,CAACO,KAAK,EAAEP,UAAU,CAACQ,MAAM,CACzD,CAAC;IAED,MAAMC,GAAG,GAAG,IAAIpB,uBAAuB,CAACO,WAAW,EAAEC,WAAW,CAAC;IAEjEF,MAAM,CAAC;MAAEc,GAAG;MAAEF,KAAK,EAAEP,UAAU,CAACO,KAAK;MAAEC,MAAM,EAAER,UAAU,CAACQ;IAAO,CAAC,CAAC;IACnElB,8BAA8B,CAC5Bc,MAAM,EACNK,GAAG,CAACC,MAAM,CAAC,CAAC,EACZd,WAAW,EACXC,WACF,CAAC;IAED,OAAOK,QAAQ,CAACS,wBAAwB,CAAC,CAAC;EAC5C,CAAC,EAAE,CAAChB,MAAM,EAAEK,UAAU,EAAEJ,WAAW,EAAEC,WAAW,CAAC,CAAC;EAElD,oBACEL,IAAA,CAACX,MAAM;IAAC+B,KAAK,EAAEC,MAAM,CAACT,MAAO;IAACU,GAAG,EAAEhB,SAAU;IAAAiB,QAAA,eAC3CvB,IAAA,CAACV,OAAO;MAACmB,OAAO,EAAEA;IAAQ,CAAE;EAAC,CACvB,CAAC;AAEb,CAAC;AAED,eAAeR,aAAa;AAE5B,MAAMoB,MAAM,GAAGzB,UAAU,CAAC4B,MAAM,CAAC;EAC/BZ,MAAM,EAAE;IACNa,IAAI,EAAE,CAAC,CAAE;EACX;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { parseStyleToColor } from "./utils.js";
|
|
4
|
+
const FOREGROUND_COLOR_ALIASES = new Set(['black', '#000', '#000000']);
|
|
5
|
+
const LEDGER_LINE_COLOR_ALIASES = new Set(['#444', '#444444']);
|
|
6
|
+
export function resolveVexflowColor(style, colorScheme) {
|
|
7
|
+
const normalizedStyle = style.trim().toLowerCase();
|
|
8
|
+
if (colorScheme?.foreground && FOREGROUND_COLOR_ALIASES.has(normalizedStyle)) {
|
|
9
|
+
return parseStyleToColor(colorScheme.foreground);
|
|
10
|
+
}
|
|
11
|
+
if (LEDGER_LINE_COLOR_ALIASES.has(normalizedStyle)) {
|
|
12
|
+
return parseStyleToColor(colorScheme?.ledgerLine ?? colorScheme?.foreground ?? style);
|
|
13
|
+
}
|
|
14
|
+
return parseStyleToColor(style);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=VexflowColorScheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parseStyleToColor","FOREGROUND_COLOR_ALIASES","Set","LEDGER_LINE_COLOR_ALIASES","resolveVexflowColor","style","colorScheme","normalizedStyle","trim","toLowerCase","foreground","has","ledgerLine"],"sourceRoot":"../../../src","sources":["base/VexflowColorScheme.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,YAAS;AAQ3C,MAAMC,wBAAwB,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACtE,MAAMC,yBAAyB,GAAG,IAAID,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9D,OAAO,SAASE,mBAAmBA,CACjCC,KAAa,EACbC,WAAgC,EACxB;EACR,MAAMC,eAAe,GAAGF,KAAK,CAACG,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC;EAElD,IACEH,WAAW,EAAEI,UAAU,IACvBT,wBAAwB,CAACU,GAAG,CAACJ,eAAe,CAAC,EAC7C;IACA,OAAOP,iBAAiB,CAACM,WAAW,CAACI,UAAU,CAAC;EAClD;EAEA,IAAIP,yBAAyB,CAACQ,GAAG,CAACJ,eAAe,CAAC,EAAE;IAClD,OAAOP,iBAAiB,CACtBM,WAAW,EAAEM,UAAU,IAAIN,WAAW,EAAEI,UAAU,IAAIL,KACxD,CAAC;EACH;EAEA,OAAOL,iBAAiB,CAACK,KAAK,CAAC;AACjC","ignoreList":[]}
|