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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
export type Id = string;
|
|
2
|
+
export type Clef = 'treble' | 'bass' | 'alto' | 'tenor' | 'soprano' | 'mezzo-soprano' | 'baritone-c' | 'baritone-f' | 'subbass' | 'french' | 'percussion' | 'tab';
|
|
3
|
+
export type Step = 'C' | 'D' | 'E' | 'F' | 'G' | 'A' | 'B';
|
|
4
|
+
export type Accidental = 'bb' | 'b' | 'n' | '#' | '##' | 'x' | 'quarter-flat' | 'quarter-sharp';
|
|
5
|
+
export type NoteLength = 'long' | 'breve' | 'w' | 'h' | 'q' | '8' | '16' | '32' | '64' | '128';
|
|
6
|
+
export type StemDirection = 'up' | 'down' | 'auto';
|
|
7
|
+
export type Barline = 'single' | 'double' | 'end' | 'repeat-begin' | 'repeat-end' | 'final';
|
|
8
|
+
export type Articulation = 'staccato' | 'tenuto' | 'accent' | 'marcato' | 'staccatissimo' | 'fermata';
|
|
9
|
+
export type Dynamic = 'ppp' | 'pp' | 'p' | 'mp' | 'mf' | 'f' | 'ff' | 'fff' | 'sfz';
|
|
10
|
+
export type KeyMode = 'major' | 'minor' | 'dorian' | 'phrygian' | 'lydian' | 'mixolydian' | 'locrian';
|
|
11
|
+
export type VoiceTimingMode = 'strict' | 'soft' | 'free';
|
|
12
|
+
export type StaffGroupRole = 'grandStaff' | 'choir' | 'section' | 'custom';
|
|
13
|
+
export type StaffGroupSymbol = 'brace' | 'bracket' | 'line';
|
|
14
|
+
export interface Fraction {
|
|
15
|
+
num: number;
|
|
16
|
+
den: number;
|
|
17
|
+
}
|
|
18
|
+
export interface Pitch {
|
|
19
|
+
step: Step;
|
|
20
|
+
octave: number;
|
|
21
|
+
accidental?: Accidental;
|
|
22
|
+
}
|
|
23
|
+
export interface DurationValue {
|
|
24
|
+
length: NoteLength;
|
|
25
|
+
dots?: 0 | 1 | 2 | 3;
|
|
26
|
+
}
|
|
27
|
+
export interface KeySignature {
|
|
28
|
+
tonic: Step;
|
|
29
|
+
accidental?: 'b' | '#';
|
|
30
|
+
mode?: KeyMode;
|
|
31
|
+
}
|
|
32
|
+
export interface Meter {
|
|
33
|
+
beats: number;
|
|
34
|
+
beatUnit: number;
|
|
35
|
+
beamGroups?: Fraction[];
|
|
36
|
+
}
|
|
37
|
+
export interface Tempo {
|
|
38
|
+
bpm: number;
|
|
39
|
+
beatUnit?: DurationValue;
|
|
40
|
+
text?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface Note {
|
|
43
|
+
id: Id;
|
|
44
|
+
type: 'note';
|
|
45
|
+
pitch: Pitch;
|
|
46
|
+
duration: DurationValue;
|
|
47
|
+
voiceId: Id;
|
|
48
|
+
targetStaffId?: Id;
|
|
49
|
+
stemDirection?: StemDirection;
|
|
50
|
+
}
|
|
51
|
+
export interface Rest {
|
|
52
|
+
id: Id;
|
|
53
|
+
type: 'rest';
|
|
54
|
+
duration: DurationValue;
|
|
55
|
+
voiceId: Id;
|
|
56
|
+
targetStaffId?: Id;
|
|
57
|
+
kind?: 'visible' | 'spacer' | 'hidden';
|
|
58
|
+
staffLine?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface Chord {
|
|
61
|
+
id: Id;
|
|
62
|
+
type: 'chord';
|
|
63
|
+
pitches: Pitch[];
|
|
64
|
+
duration: DurationValue;
|
|
65
|
+
voiceId: Id;
|
|
66
|
+
targetStaffId?: Id;
|
|
67
|
+
stemDirection?: StemDirection;
|
|
68
|
+
}
|
|
69
|
+
export type VoiceItem = Note | Rest | Chord;
|
|
70
|
+
export interface Voice {
|
|
71
|
+
id: Id;
|
|
72
|
+
name?: string;
|
|
73
|
+
index: number;
|
|
74
|
+
timingMode?: VoiceTimingMode;
|
|
75
|
+
items: VoiceItem[];
|
|
76
|
+
}
|
|
77
|
+
export interface MeasureState {
|
|
78
|
+
clef?: Clef;
|
|
79
|
+
meter?: Meter;
|
|
80
|
+
keySignature?: KeySignature;
|
|
81
|
+
tempo?: Tempo;
|
|
82
|
+
}
|
|
83
|
+
export interface MeasureLeftModifiers {
|
|
84
|
+
showClef?: boolean;
|
|
85
|
+
showMeter?: boolean;
|
|
86
|
+
showKeySignature?: boolean;
|
|
87
|
+
startBarline?: Barline;
|
|
88
|
+
}
|
|
89
|
+
export interface MeasureRightModifiers {
|
|
90
|
+
endBarline?: Barline;
|
|
91
|
+
}
|
|
92
|
+
export interface TextDirection {
|
|
93
|
+
id: Id;
|
|
94
|
+
type: 'text';
|
|
95
|
+
text: string;
|
|
96
|
+
placement?: 'above' | 'below';
|
|
97
|
+
}
|
|
98
|
+
export interface TempoDirection {
|
|
99
|
+
id: Id;
|
|
100
|
+
type: 'tempo';
|
|
101
|
+
tempo: Tempo;
|
|
102
|
+
placement?: 'above' | 'below';
|
|
103
|
+
}
|
|
104
|
+
export type Direction = TextDirection | TempoDirection;
|
|
105
|
+
export interface Measure {
|
|
106
|
+
id: Id;
|
|
107
|
+
number: number;
|
|
108
|
+
state?: MeasureState;
|
|
109
|
+
leftModifiers?: MeasureLeftModifiers;
|
|
110
|
+
rightModifiers?: MeasureRightModifiers;
|
|
111
|
+
directions?: Direction[];
|
|
112
|
+
voices: Voice[];
|
|
113
|
+
}
|
|
114
|
+
export interface Staff {
|
|
115
|
+
id: Id;
|
|
116
|
+
name?: string;
|
|
117
|
+
shortName?: string;
|
|
118
|
+
order: number;
|
|
119
|
+
defaultClef: Clef;
|
|
120
|
+
transposition?: number;
|
|
121
|
+
measures: Measure[];
|
|
122
|
+
}
|
|
123
|
+
export interface StaffGroup {
|
|
124
|
+
id: Id;
|
|
125
|
+
staffIds?: Id[];
|
|
126
|
+
role: StaffGroupRole;
|
|
127
|
+
symbol?: StaffGroupSymbol;
|
|
128
|
+
}
|
|
129
|
+
export interface ScoreMetadata {
|
|
130
|
+
title?: string;
|
|
131
|
+
subtitle?: string;
|
|
132
|
+
composer?: string;
|
|
133
|
+
lyricist?: string;
|
|
134
|
+
arranger?: string;
|
|
135
|
+
copyright?: string;
|
|
136
|
+
}
|
|
137
|
+
export interface ScoreDefaults {
|
|
138
|
+
meter: Meter;
|
|
139
|
+
keySignature?: KeySignature;
|
|
140
|
+
tempo?: Tempo;
|
|
141
|
+
}
|
|
142
|
+
export interface AttachmentBase {
|
|
143
|
+
id: Id;
|
|
144
|
+
ownerId: Id;
|
|
145
|
+
}
|
|
146
|
+
export interface ArticulationAttachment extends AttachmentBase {
|
|
147
|
+
type: 'articulation';
|
|
148
|
+
articulation: Articulation;
|
|
149
|
+
}
|
|
150
|
+
export interface DynamicAttachment extends AttachmentBase {
|
|
151
|
+
type: 'dynamic';
|
|
152
|
+
dynamic: Dynamic;
|
|
153
|
+
placement?: 'above' | 'below';
|
|
154
|
+
}
|
|
155
|
+
export interface LyricAttachment extends AttachmentBase {
|
|
156
|
+
type: 'lyric';
|
|
157
|
+
text: string;
|
|
158
|
+
verse?: number;
|
|
159
|
+
}
|
|
160
|
+
export type NoteAttachment = ArticulationAttachment | DynamicAttachment | LyricAttachment;
|
|
161
|
+
export interface Tie {
|
|
162
|
+
id: Id;
|
|
163
|
+
fromNoteId: Id;
|
|
164
|
+
toNoteId: Id;
|
|
165
|
+
}
|
|
166
|
+
export interface Slur {
|
|
167
|
+
id: Id;
|
|
168
|
+
fromNoteId: Id;
|
|
169
|
+
toNoteId: Id;
|
|
170
|
+
}
|
|
171
|
+
export interface TupletGroup {
|
|
172
|
+
id: Id;
|
|
173
|
+
voiceId: Id;
|
|
174
|
+
itemIds: Id[];
|
|
175
|
+
ratio: Fraction;
|
|
176
|
+
bracketed?: boolean;
|
|
177
|
+
placement?: 'above' | 'below';
|
|
178
|
+
}
|
|
179
|
+
export interface Score {
|
|
180
|
+
id: Id;
|
|
181
|
+
metadata?: ScoreMetadata;
|
|
182
|
+
defaults: ScoreDefaults;
|
|
183
|
+
staves: Staff[];
|
|
184
|
+
staffGroups?: StaffGroup[];
|
|
185
|
+
attachments?: NoteAttachment[];
|
|
186
|
+
ties?: Tie[];
|
|
187
|
+
slurs?: Slur[];
|
|
188
|
+
tuplets?: TupletGroup[];
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/state/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,MAAM,MAAM,IAAI,GACZ,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,eAAe,GACf,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GA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|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import { type SkFont } from '@shopify/react-native-skia';
|
|
2
|
-
import { type ParsedCssFont } from './types';
|
|
3
|
-
export declare function getAdvanceWidth(font: SkFont, text: string): number;
|
|
4
|
-
export declare function toPxFontSize(size: number | string | undefined): number;
|
|
5
|
-
export declare function parseCssFontShorthand(cssFont: string): ParsedCssFont;
|
|
6
|
-
export declare function createFont(size: number, familyName?: string, bravuraFont?: SkFont | null): SkFont;
|
|
7
1
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.tsx"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "React native backend for rendering music notation using @shopify/react-native-skiaact-native-skia",
|
|
5
|
-
"main": "./lib/module/index.js",
|
|
6
|
-
"types": "./lib/typescript/src/index.d.ts",
|
|
5
|
+
"main": "./lib/module/base/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/base/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"source": "./src/index.
|
|
10
|
-
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
-
"default": "./lib/module/index.js"
|
|
9
|
+
"source": "./src/base/index.ts",
|
|
10
|
+
"types": "./lib/typescript/src/base/index.d.ts",
|
|
11
|
+
"default": "./lib/module/base/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./state": {
|
|
14
|
+
"source": "./src/state/index.ts",
|
|
15
|
+
"types": "./lib/typescript/src/state/index.d.ts",
|
|
16
|
+
"default": "./lib/module/state/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./renderer": {
|
|
19
|
+
"source": "./src/renderer/index.ts",
|
|
20
|
+
"types": "./lib/typescript/src/renderer/index.d.ts",
|
|
21
|
+
"default": "./lib/module/renderer/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./musicxml": {
|
|
24
|
+
"source": "./src/musicxml/index.ts",
|
|
25
|
+
"types": "./lib/typescript/src/musicxml/index.d.ts",
|
|
26
|
+
"default": "./lib/module/musicxml/index.js"
|
|
12
27
|
},
|
|
13
28
|
"./package.json": "./package.json"
|
|
14
29
|
},
|
|
15
30
|
"files": [
|
|
16
31
|
"src",
|
|
17
32
|
"lib",
|
|
18
|
-
"android",
|
|
19
|
-
"ios",
|
|
20
|
-
"cpp",
|
|
21
|
-
"*.podspec",
|
|
22
33
|
"react-native.config.js",
|
|
23
34
|
"!ios/build",
|
|
24
35
|
"!android/build",
|
|
@@ -35,8 +46,11 @@
|
|
|
35
46
|
"example": "yarn workspace vexflow-native-example",
|
|
36
47
|
"clean": "del-cli lib",
|
|
37
48
|
"prepare": "bob build",
|
|
49
|
+
"postinstall": "yarn workspace vexflow-native-example apply-patches",
|
|
38
50
|
"typecheck": "tsc",
|
|
39
|
-
"lint": "eslint
|
|
51
|
+
"lint": "eslint src example --ext .js,.ts,.tsx",
|
|
52
|
+
"lint:fix": "yarn lint --fix",
|
|
53
|
+
"format": "prettier --write README.md package.json \"src/**/*.{ts,tsx}\"",
|
|
40
54
|
"test": "jest",
|
|
41
55
|
"release": "release-it --only-version"
|
|
42
56
|
},
|
|
@@ -66,7 +80,7 @@
|
|
|
66
80
|
"@react-native/babel-preset": "0.83.0",
|
|
67
81
|
"@react-native/eslint-config": "0.83.0",
|
|
68
82
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
69
|
-
"@shopify/react-native-skia": "
|
|
83
|
+
"@shopify/react-native-skia": "2.6.2",
|
|
70
84
|
"@types/jest": "^29.5.14",
|
|
71
85
|
"@types/react": "^19.1.12",
|
|
72
86
|
"commitlint": "^19.8.1",
|
|
@@ -80,6 +94,9 @@
|
|
|
80
94
|
"react": "19.1.0",
|
|
81
95
|
"react-native": "0.81.5",
|
|
82
96
|
"react-native-builder-bob": "^0.40.18",
|
|
97
|
+
"react-native-gesture-handler": "^2.30.0",
|
|
98
|
+
"react-native-reanimated": "^4.2.2",
|
|
99
|
+
"react-native-worklets": "^0.7.4",
|
|
83
100
|
"release-it": "^19.0.4",
|
|
84
101
|
"turbo": "^2.5.6",
|
|
85
102
|
"typescript": "^5.9.2",
|
|
@@ -89,6 +106,9 @@
|
|
|
89
106
|
"@shopify/react-native-skia": "*",
|
|
90
107
|
"react": "*",
|
|
91
108
|
"react-native": "*",
|
|
109
|
+
"react-native-gesture-handler": "*",
|
|
110
|
+
"react-native-reanimated": "*",
|
|
111
|
+
"react-native-worklets": "*",
|
|
92
112
|
"vexflow": "*"
|
|
93
113
|
},
|
|
94
114
|
"workspaces": [
|
|
@@ -124,7 +144,12 @@
|
|
|
124
144
|
"preset": "react-native",
|
|
125
145
|
"modulePathIgnorePatterns": [
|
|
126
146
|
"<rootDir>/example/node_modules",
|
|
127
|
-
"<rootDir>/lib/"
|
|
147
|
+
"<rootDir>/lib/",
|
|
148
|
+
"<rootDir>/prev-implementation/"
|
|
149
|
+
],
|
|
150
|
+
"testPathIgnorePatterns": [
|
|
151
|
+
"<rootDir>/example/",
|
|
152
|
+
"<rootDir>/prev-implementation/"
|
|
128
153
|
]
|
|
129
154
|
},
|
|
130
155
|
"commitlint": {
|
|
@@ -161,5 +186,8 @@
|
|
|
161
186
|
"release-it"
|
|
162
187
|
],
|
|
163
188
|
"version": "0.57.2"
|
|
189
|
+
},
|
|
190
|
+
"dependencies": {
|
|
191
|
+
"fast-xml-parser": "^5.7.3"
|
|
164
192
|
}
|
|
165
193
|
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { FontInfo } from 'vexflow';
|
|
2
|
+
import {
|
|
3
|
+
FontWeight,
|
|
4
|
+
FontSlant,
|
|
5
|
+
FontWidth,
|
|
6
|
+
Skia,
|
|
7
|
+
} from '@shopify/react-native-skia';
|
|
8
|
+
import type {
|
|
9
|
+
SkFont,
|
|
10
|
+
SkTypefaceFontProvider,
|
|
11
|
+
} from '@shopify/react-native-skia';
|
|
12
|
+
|
|
13
|
+
// import Logger, { LogCategory } from '../shared/Logger';
|
|
14
|
+
|
|
15
|
+
// const Log = Logger.extend(LogCategory.FontManager);
|
|
16
|
+
|
|
17
|
+
interface ResolvedFont {
|
|
18
|
+
family: string;
|
|
19
|
+
size: number;
|
|
20
|
+
weight: FontWeight;
|
|
21
|
+
slant: FontSlant;
|
|
22
|
+
width: FontWidth;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const PT_TO_PX = 4 / 3; // 1pt = 1.333px
|
|
26
|
+
|
|
27
|
+
function parseSize(size?: string | number): number {
|
|
28
|
+
'worklet';
|
|
29
|
+
|
|
30
|
+
if (typeof size === 'number') {
|
|
31
|
+
return size;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof size === 'string') {
|
|
35
|
+
const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt|em|%)?$/);
|
|
36
|
+
|
|
37
|
+
if (match) {
|
|
38
|
+
const value = parseFloat(match?.[1] || '30');
|
|
39
|
+
const unit = match[2] || 'pt';
|
|
40
|
+
|
|
41
|
+
switch (unit) {
|
|
42
|
+
case 'px':
|
|
43
|
+
return value * 0.75; // 1px = 0.75pt
|
|
44
|
+
case 'em':
|
|
45
|
+
return value * 12; // Assuming 1em = 16px = 12pt
|
|
46
|
+
case '%':
|
|
47
|
+
return value * 0.12; // Assuming 100% = 12pt
|
|
48
|
+
case 'pt':
|
|
49
|
+
default:
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return 30; // Default font size in pixels
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseWeight(weight?: string | number): FontWeight {
|
|
59
|
+
'worklet';
|
|
60
|
+
|
|
61
|
+
const weightStr = String(weight || 'normal').toLowerCase();
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
{
|
|
65
|
+
'normal': FontWeight.Normal,
|
|
66
|
+
'bold': FontWeight.Bold,
|
|
67
|
+
'100': FontWeight.Thin,
|
|
68
|
+
'200': FontWeight.ExtraLight,
|
|
69
|
+
'300': FontWeight.Light,
|
|
70
|
+
'400': FontWeight.Normal,
|
|
71
|
+
'500': FontWeight.Medium,
|
|
72
|
+
'600': FontWeight.SemiBold,
|
|
73
|
+
'700': FontWeight.Bold,
|
|
74
|
+
'800': FontWeight.ExtraBold,
|
|
75
|
+
'900': FontWeight.Black,
|
|
76
|
+
}[weightStr] || FontWeight.Normal
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseSlant(style?: string): FontSlant {
|
|
81
|
+
'worklet';
|
|
82
|
+
|
|
83
|
+
const styleStr = String(style || 'normal').toLowerCase();
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
{
|
|
87
|
+
normal: FontSlant.Upright,
|
|
88
|
+
italic: FontSlant.Italic,
|
|
89
|
+
oblique: FontSlant.Oblique,
|
|
90
|
+
}[styleStr] || FontSlant.Upright
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default class FontManager {
|
|
95
|
+
__workletClass = true;
|
|
96
|
+
|
|
97
|
+
private fontProvider: SkTypefaceFontProvider;
|
|
98
|
+
private defaultFontName: string;
|
|
99
|
+
|
|
100
|
+
constructor(fontProvider: SkTypefaceFontProvider, defaultFontName: string) {
|
|
101
|
+
this.fontProvider = fontProvider;
|
|
102
|
+
this.defaultFontName = defaultFontName;
|
|
103
|
+
|
|
104
|
+
const families: string[] = [];
|
|
105
|
+
|
|
106
|
+
for (let i = 0; i < fontProvider.countFamilies(); i++) {
|
|
107
|
+
families.push(fontProvider.getFamilyName(i));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!families.includes(defaultFontName)) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Default font "${defaultFontName}" is not available in the font provider. Available fonts: ${families.join(
|
|
113
|
+
', '
|
|
114
|
+
)}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private isFamilyAvailable(family: string): boolean {
|
|
120
|
+
for (let i = 0; i < this.fontProvider.countFamilies(); i++) {
|
|
121
|
+
if (
|
|
122
|
+
this.fontProvider.getFamilyName(i).toLowerCase() ===
|
|
123
|
+
family.toLowerCase()
|
|
124
|
+
) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private getFamiliesFromFont(font: string | FontInfo): string[] {
|
|
133
|
+
if (typeof font === 'string') {
|
|
134
|
+
return font.split(',').map((f) => f.trim());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (font as FontInfo).family
|
|
138
|
+
? (font as FontInfo).family!.split(',').map((f) => f.trim())
|
|
139
|
+
: [];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private matchFontFamilyName(font: string | FontInfo): string {
|
|
143
|
+
if (!font) {
|
|
144
|
+
return this.defaultFontName;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const families = this.getFamiliesFromFont(font);
|
|
148
|
+
|
|
149
|
+
for (const family of families) {
|
|
150
|
+
if (this.isFamilyAvailable(family)) {
|
|
151
|
+
return family;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return this.defaultFontName;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
resolveFontDescriptor(
|
|
159
|
+
font?: string | FontInfo,
|
|
160
|
+
size?: string | number,
|
|
161
|
+
weight?: string | number,
|
|
162
|
+
style?: string
|
|
163
|
+
): ResolvedFont {
|
|
164
|
+
return {
|
|
165
|
+
family: this.matchFontFamilyName(font || ''),
|
|
166
|
+
size: parseSize(
|
|
167
|
+
typeof font === 'string' ? size : (font as FontInfo).size || size
|
|
168
|
+
),
|
|
169
|
+
weight: parseWeight(weight),
|
|
170
|
+
slant: parseSlant(style),
|
|
171
|
+
width: FontWidth.Normal,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
createSkFont(
|
|
176
|
+
font?: string | FontInfo,
|
|
177
|
+
size?: string | number,
|
|
178
|
+
weight?: string | number,
|
|
179
|
+
style?: string
|
|
180
|
+
): SkFont {
|
|
181
|
+
const {
|
|
182
|
+
family,
|
|
183
|
+
size: resolvedSize,
|
|
184
|
+
weight: resolvedWeight,
|
|
185
|
+
slant,
|
|
186
|
+
} = this.resolveFontDescriptor(font, size, weight, style);
|
|
187
|
+
|
|
188
|
+
const typeface = this.fontProvider.matchFamilyStyle(family, {
|
|
189
|
+
weight: resolvedWeight,
|
|
190
|
+
slant,
|
|
191
|
+
width: FontWidth.Normal,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
if (!typeface) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`Failed to create SkFont. No matching typeface found for family "${family}" with weight "${resolvedWeight}" and slant "${slant}".`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Log.log(
|
|
201
|
+
// `Created SkFont with family "${family}", size ${resolvedSize}px, weight ${resolvedWeight}, slant ${slant}.`
|
|
202
|
+
// );
|
|
203
|
+
|
|
204
|
+
return Skia.Font(typeface, resolvedSize * PT_TO_PX); // Convert from points to pixels
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SkFont } from '@shopify/react-native-skia';
|
|
2
|
+
import { Font } from 'vexflow';
|
|
3
|
+
import type VexflowRecordingContext from './VexflowRecordingContext';
|
|
4
|
+
|
|
5
|
+
class TextMeasureContext {
|
|
6
|
+
__workletClass = true;
|
|
7
|
+
|
|
8
|
+
private context: VexflowRecordingContext;
|
|
9
|
+
private currentFont = '';
|
|
10
|
+
|
|
11
|
+
constructor(context: VexflowRecordingContext) {
|
|
12
|
+
this.context = context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
measureText(text: string) {
|
|
16
|
+
const currentFont = this.context.getCurrentSkFont();
|
|
17
|
+
const rect = currentFont.measureText(text);
|
|
18
|
+
|
|
19
|
+
const width = getAdvanceWidth(currentFont, text);
|
|
20
|
+
const ascent = Math.max(0, -rect.y);
|
|
21
|
+
const descent = Math.max(0, rect.y + rect.height);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
width,
|
|
25
|
+
actualBoundingBoxAscent: ascent,
|
|
26
|
+
actualBoundingBoxDescent: descent,
|
|
27
|
+
fontBoundingBoxAscent: ascent,
|
|
28
|
+
fontBoundingBoxDescent: descent,
|
|
29
|
+
actualBoundingBoxLeft: rect.x,
|
|
30
|
+
actualBoundingBoxRight: rect.x + rect.width,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get() {
|
|
35
|
+
return this.currentFont;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set(value: string) {
|
|
39
|
+
this.currentFont = value;
|
|
40
|
+
this.context.setFont(Font.fromCSSString(value));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get font() {
|
|
44
|
+
return this.get();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set font(value: string) {
|
|
48
|
+
this.set(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default TextMeasureContext;
|
|
53
|
+
|
|
54
|
+
function getAdvanceWidth(font: SkFont, text: string): number {
|
|
55
|
+
const glyphs = font.getGlyphIDs(text);
|
|
56
|
+
const widths = font.getGlyphWidths(glyphs);
|
|
57
|
+
|
|
58
|
+
return widths.reduce((sum, width) => sum + width, 0);
|
|
59
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Canvas,
|
|
3
|
+
Picture,
|
|
4
|
+
Skia,
|
|
5
|
+
useCanvasRef,
|
|
6
|
+
useCanvasSize,
|
|
7
|
+
} from '@shopify/react-native-skia';
|
|
8
|
+
import React, { useMemo } from 'react';
|
|
9
|
+
import { StyleSheet } from 'react-native';
|
|
10
|
+
|
|
11
|
+
import type { VexflowCanvasProps } from './types';
|
|
12
|
+
import VexflowRecordingContext from './VexflowRecordingContext';
|
|
13
|
+
import { renderVexflowRecordingCommands } from './VexflowRecordingReplay';
|
|
14
|
+
|
|
15
|
+
const VexflowCanvas: React.FC<VexflowCanvasProps> = (props) => {
|
|
16
|
+
const {
|
|
17
|
+
onDraw,
|
|
18
|
+
fontManager,
|
|
19
|
+
defaultFont,
|
|
20
|
+
// width: propWidth,
|
|
21
|
+
// height: propHeight,
|
|
22
|
+
// colorScheme = 'light',
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
const canvasRef = useCanvasRef();
|
|
26
|
+
const { size: canvasSize } = useCanvasSize(canvasRef);
|
|
27
|
+
|
|
28
|
+
const picture = useMemo(() => {
|
|
29
|
+
const recorder = Skia.PictureRecorder();
|
|
30
|
+
const canvas = recorder.beginRecording(
|
|
31
|
+
Skia.XYWHRect(0, 0, canvasSize.width, canvasSize.height)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const ctx = new VexflowRecordingContext(fontManager, defaultFont);
|
|
35
|
+
|
|
36
|
+
onDraw({ ctx, width: canvasSize.width, height: canvasSize.height });
|
|
37
|
+
renderVexflowRecordingCommands(
|
|
38
|
+
canvas,
|
|
39
|
+
ctx.finish(),
|
|
40
|
+
fontManager,
|
|
41
|
+
defaultFont
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return recorder.finishRecordingAsPicture();
|
|
45
|
+
}, [onDraw, canvasSize, fontManager, defaultFont]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Canvas style={styles.canvas} ref={canvasRef}>
|
|
49
|
+
<Picture picture={picture} />
|
|
50
|
+
</Canvas>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default VexflowCanvas;
|
|
55
|
+
|
|
56
|
+
const styles = StyleSheet.create({
|
|
57
|
+
canvas: {
|
|
58
|
+
flex: 1, // TMP?
|
|
59
|
+
},
|
|
60
|
+
});
|