vexflow-native 1.9.0 → 2.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 +42 -2
- package/lib/module/base/FontManager.js +3 -5
- package/lib/module/base/FontManager.js.map +1 -1
- package/lib/module/base/VexflowCanvas.js +1 -1
- package/lib/module/base/VexflowCanvas.js.map +1 -1
- package/lib/module/base/VexflowRecordingContext.js.map +1 -1
- package/lib/module/base/VexflowRecordingReplay.js +119 -79
- package/lib/module/base/VexflowRecordingReplay.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js +4 -3
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScorePlayhead.js +1 -1
- package/lib/module/renderer/ScoreRenderer/ScorePlayhead.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
- package/lib/module/renderer/layout.js +10 -0
- package/lib/module/renderer/layout.js.map +1 -1
- package/lib/module/renderer/useScoreRecording.js +50 -17
- package/lib/module/renderer/useScoreRecording.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +2 -2
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts +1 -1
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +1 -1
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -1
- package/lib/typescript/src/base/types.d.ts +1 -1
- package/lib/typescript/src/base/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScorePlayhead.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScorePlayhead.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
- package/lib/typescript/src/renderer/layout.d.ts +7 -0
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/types.d.ts +1 -1
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
- package/package.json +20 -16
- package/src/base/FontManager.ts +4 -11
- package/src/base/TextMeasureContext.ts +1 -1
- package/src/base/VexflowCanvas.tsx +1 -1
- package/src/base/VexflowRecordingContext.ts +1 -4
- package/src/base/VexflowRecordingReplay.ts +194 -142
- package/src/base/types.ts +1 -1
- package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +4 -7
- package/src/renderer/ScoreRenderer/ScorePlayhead.tsx +1 -1
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +1 -7
- package/src/renderer/ScoreRenderer/types.ts +1 -4
- package/src/renderer/ScoreRenderer/utils.ts +1 -1
- package/src/renderer/layout.ts +15 -0
- package/src/renderer/types.ts +1 -1
- package/src/renderer/useScoreRecording.ts +72 -20
- package/lib/module/musicxml/testfiles/lg-8102429.xml +0 -79620
- package/src/musicxml/testfiles/lg-8102429.xml +0 -79620
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow-native",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "React
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "React Native backend for rendering music notation using react-native-skia",
|
|
5
5
|
"main": "./lib/module/base/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/base/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"@eslint/compat": "^1.3.2",
|
|
83
83
|
"@eslint/eslintrc": "^3.3.1",
|
|
84
84
|
"@eslint/js": "^9.35.0",
|
|
85
|
-
"@react-native/babel-preset": "0.
|
|
86
|
-
"@react-native/eslint-config": "0.
|
|
85
|
+
"@react-native/babel-preset": "0.86.3",
|
|
86
|
+
"@react-native/eslint-config": "0.86.3",
|
|
87
|
+
"@react-native/jest-preset": "0.86.3",
|
|
87
88
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
88
|
-
"@shopify/react-native-skia": "2.6.2",
|
|
89
89
|
"@types/jest": "^29.5.14",
|
|
90
|
-
"@types/react": "
|
|
90
|
+
"@types/react": "~19.2.2",
|
|
91
91
|
"commitlint": "^19.8.1",
|
|
92
92
|
"del-cli": "^6.0.0",
|
|
93
93
|
"eslint": "^9.35.0",
|
|
@@ -96,12 +96,13 @@
|
|
|
96
96
|
"jest": "^29.7.0",
|
|
97
97
|
"lefthook": "^2.0.3",
|
|
98
98
|
"prettier": "^2.8.8",
|
|
99
|
-
"react": "19.
|
|
100
|
-
"react-native": "0.
|
|
99
|
+
"react": "19.2.3",
|
|
100
|
+
"react-native": "0.86.3",
|
|
101
101
|
"react-native-builder-bob": "^0.40.18",
|
|
102
|
-
"react-native-gesture-handler": "
|
|
103
|
-
"react-native-reanimated": "
|
|
104
|
-
"react-native-
|
|
102
|
+
"react-native-gesture-handler": "~2.32.0",
|
|
103
|
+
"react-native-reanimated": "4.5.1",
|
|
104
|
+
"react-native-skia": "3.0.3",
|
|
105
|
+
"react-native-worklets": "0.10.1",
|
|
105
106
|
"release-it": "^19.0.4",
|
|
106
107
|
"turbo": "^2.5.6",
|
|
107
108
|
"typedoc": "0.28.20",
|
|
@@ -109,12 +110,12 @@
|
|
|
109
110
|
"vexflow": "^5.0.0"
|
|
110
111
|
},
|
|
111
112
|
"peerDependencies": {
|
|
112
|
-
"@shopify/react-native-skia": "*",
|
|
113
113
|
"react": "*",
|
|
114
114
|
"react-native": "*",
|
|
115
115
|
"react-native-gesture-handler": "*",
|
|
116
|
-
"react-native-reanimated": "
|
|
117
|
-
"react-native-
|
|
116
|
+
"react-native-reanimated": ">=4.0.0",
|
|
117
|
+
"react-native-skia": ">=3.0.0",
|
|
118
|
+
"react-native-worklets": ">=0.7.0",
|
|
118
119
|
"vexflow": "*"
|
|
119
120
|
},
|
|
120
121
|
"workspaces": [
|
|
@@ -147,17 +148,20 @@
|
|
|
147
148
|
"useTabs": false
|
|
148
149
|
},
|
|
149
150
|
"jest": {
|
|
150
|
-
"preset": "react-native",
|
|
151
|
+
"preset": "@react-native/jest-preset",
|
|
151
152
|
"testMatch": [
|
|
152
153
|
"**/__tests__/**/*.test.[jt]s?(x)"
|
|
153
154
|
],
|
|
155
|
+
"moduleNameMapper": {
|
|
156
|
+
"^react-native-skia$": "<rootDir>/src/__tests__/skiaMock"
|
|
157
|
+
},
|
|
154
158
|
"modulePathIgnorePatterns": [
|
|
155
159
|
"<rootDir>/example/node_modules",
|
|
156
160
|
"<rootDir>/lib/",
|
|
157
161
|
"<rootDir>/prev-implementation/"
|
|
158
162
|
],
|
|
159
163
|
"testPathIgnorePatterns": [
|
|
160
|
-
"<rootDir>/example/",
|
|
164
|
+
"<rootDir>/example/(?!src/benchmark/)",
|
|
161
165
|
"<rootDir>/prev-implementation/"
|
|
162
166
|
]
|
|
163
167
|
},
|
package/src/base/FontManager.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type { FontInfo } from 'vexflow';
|
|
2
|
-
import {
|
|
3
|
-
FontWeight,
|
|
4
|
-
FontSlant,
|
|
5
|
-
FontWidth,
|
|
6
|
-
Skia,
|
|
7
|
-
} from '@shopify/react-native-skia';
|
|
2
|
+
import { FontWeight, FontSlant, FontWidth, Skia } from 'react-native-skia';
|
|
8
3
|
import type {
|
|
9
4
|
SkFont,
|
|
10
5
|
SkFontMgr,
|
|
11
6
|
SkTypeface,
|
|
12
7
|
SkTypefaceFontProvider,
|
|
13
|
-
} from '
|
|
8
|
+
} from 'react-native-skia';
|
|
14
9
|
|
|
15
10
|
// import Logger, { LogCategory } from '../shared/Logger';
|
|
16
11
|
|
|
@@ -99,10 +94,8 @@ export default class FontManager {
|
|
|
99
94
|
private fontProvider: SkTypefaceFontProvider;
|
|
100
95
|
private defaultFontName: string;
|
|
101
96
|
private familiesLower: string[];
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
// Skia host objects, which are shareable across reanimated runtimes (the
|
|
105
|
-
// provider itself already crosses the same way).
|
|
97
|
+
// Instances never cross runtimes; each runtime builds its own, so these
|
|
98
|
+
// caches are runtime-local.
|
|
106
99
|
private familyMatchCache: Record<string, string> = {};
|
|
107
100
|
private skFontCache: Record<string, SkFont> = {};
|
|
108
101
|
private systemFontMgr: SkFontMgr | null | undefined;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SkFont,
|
|
3
|
-
type SkTypefaceFontProvider,
|
|
4
|
-
} from '@shopify/react-native-skia';
|
|
1
|
+
import { type SkFont, type SkTypefaceFontProvider } from 'react-native-skia';
|
|
5
2
|
import { Platform } from 'react-native';
|
|
6
3
|
import { Element, RenderContext as VexflowRenderContext } from 'vexflow';
|
|
7
4
|
import type { FontInfo } from 'vexflow';
|
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
StrokeCap,
|
|
7
7
|
type SkCanvas,
|
|
8
8
|
type SkColor,
|
|
9
|
+
type SkImageFilter,
|
|
9
10
|
type SkPaint,
|
|
10
11
|
type SkPathBuilder,
|
|
12
|
+
type SkPathEffect,
|
|
11
13
|
type SkTypefaceFontProvider,
|
|
12
|
-
} from '
|
|
14
|
+
} from 'react-native-skia';
|
|
13
15
|
|
|
14
16
|
import FontManager from './FontManager';
|
|
15
17
|
import type {
|
|
@@ -18,7 +20,6 @@ import type {
|
|
|
18
20
|
VexflowRecordingLineCap,
|
|
19
21
|
VexflowRecordingPaint,
|
|
20
22
|
VexflowRecordingPathCommand,
|
|
21
|
-
VexflowRecordingRect,
|
|
22
23
|
VexflowStyleOverride,
|
|
23
24
|
} from './VexflowRecordingTypes';
|
|
24
25
|
|
|
@@ -35,15 +36,27 @@ function shadowBlurToSigma(shadowBlur: number): number {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
* distinct colors
|
|
39
|
+
* Skia objects one replay call allocates once and reuses across its commands.
|
|
40
|
+
* A recording uses a handful of distinct colors, glows and dashes but
|
|
41
|
+
* references them thousands of times, so each is created on first use and
|
|
42
|
+
* cached by value. Everything here is disposed when the replay ends: under
|
|
43
|
+
* NativeState only GC would free it otherwise.
|
|
40
44
|
*/
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
type ReplayPool = {
|
|
46
|
+
colors: Record<string, SkColor>;
|
|
47
|
+
glows: Record<string, SkImageFilter>;
|
|
48
|
+
dashes: Record<string, SkPathEffect>;
|
|
49
|
+
fillPaint: SkPaint;
|
|
50
|
+
strokePaint: SkPaint;
|
|
51
|
+
/** Created on the first `clearRect`; most recordings never clear a rect. */
|
|
52
|
+
clearPaint: SkPaint | null;
|
|
53
|
+
pathBuilder: SkPathBuilder;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function getCachedColor(color: string, pool: ReplayPool): SkColor {
|
|
44
57
|
'worklet';
|
|
45
58
|
|
|
46
|
-
return (
|
|
59
|
+
return (pool.colors[color] ??= Skia.Color(color));
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
/**
|
|
@@ -55,7 +68,7 @@ function getCachedColor(color: string, cache: SkColorCache): SkColor {
|
|
|
55
68
|
function applyGlow(
|
|
56
69
|
skPaint: SkPaint,
|
|
57
70
|
paint: VexflowRecordingPaint,
|
|
58
|
-
|
|
71
|
+
pool: ReplayPool
|
|
59
72
|
) {
|
|
60
73
|
'worklet';
|
|
61
74
|
|
|
@@ -67,22 +80,34 @@ function applyGlow(
|
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
const sigma = shadowBlurToSigma(paint.shadowBlur ?? 0);
|
|
83
|
+
const key = `${paint.shadowColor}|${sigma}`;
|
|
70
84
|
|
|
71
85
|
skPaint.setImageFilter(
|
|
72
|
-
Skia.ImageFilter.MakeDropShadow(
|
|
86
|
+
(pool.glows[key] ??= Skia.ImageFilter.MakeDropShadow(
|
|
73
87
|
0,
|
|
74
88
|
0,
|
|
75
89
|
sigma,
|
|
76
90
|
sigma,
|
|
77
|
-
getCachedColor(paint.shadowColor,
|
|
78
|
-
)
|
|
91
|
+
getCachedColor(paint.shadowColor, pool)
|
|
92
|
+
))
|
|
79
93
|
);
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
function
|
|
96
|
+
function applyDash(
|
|
97
|
+
skPaint: SkPaint,
|
|
98
|
+
lineDash: number[] | undefined,
|
|
99
|
+
pool: ReplayPool
|
|
100
|
+
) {
|
|
83
101
|
'worklet';
|
|
84
102
|
|
|
85
|
-
|
|
103
|
+
if (lineDash == null || lineDash.length === 0) {
|
|
104
|
+
skPaint.setPathEffect(null);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
skPaint.setPathEffect(
|
|
109
|
+
(pool.dashes[lineDash.join(',')] ??= Skia.PathEffect.MakeDash(lineDash))
|
|
110
|
+
);
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
@@ -106,67 +131,86 @@ function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
|
106
131
|
* state (glow filter, dash effect) is explicitly reset on every configure so
|
|
107
132
|
* nothing bleeds between commands.
|
|
108
133
|
*/
|
|
109
|
-
function
|
|
134
|
+
function createReplayPool(): ReplayPool {
|
|
110
135
|
'worklet';
|
|
111
136
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
const fillPaint = Skia.Paint();
|
|
138
|
+
fillPaint.setStyle(PaintStyle.Fill);
|
|
139
|
+
fillPaint.setAntiAlias(true);
|
|
115
140
|
|
|
116
|
-
|
|
141
|
+
const strokePaint = Skia.Paint();
|
|
142
|
+
strokePaint.setStyle(PaintStyle.Stroke);
|
|
143
|
+
strokePaint.setAntiAlias(true);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
colors: {},
|
|
147
|
+
glows: {},
|
|
148
|
+
dashes: {},
|
|
149
|
+
fillPaint,
|
|
150
|
+
strokePaint,
|
|
151
|
+
clearPaint: null,
|
|
152
|
+
pathBuilder: Skia.PathBuilder.Make(),
|
|
153
|
+
};
|
|
117
154
|
}
|
|
118
155
|
|
|
119
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Paints keep their own reference to an image filter / path effect, and a
|
|
158
|
+
* recorded picture copies the paint state it drew with, so disposing the JS
|
|
159
|
+
* handles here never invalidates what was drawn.
|
|
160
|
+
*/
|
|
161
|
+
function disposeReplayPool(pool: ReplayPool) {
|
|
120
162
|
'worklet';
|
|
121
163
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
164
|
+
for (const key in pool.glows) {
|
|
165
|
+
pool.glows[key]!.dispose();
|
|
166
|
+
}
|
|
167
|
+
for (const key in pool.dashes) {
|
|
168
|
+
pool.dashes[key]!.dispose();
|
|
169
|
+
}
|
|
170
|
+
pool.fillPaint.dispose();
|
|
171
|
+
pool.strokePaint.dispose();
|
|
172
|
+
pool.clearPaint?.dispose();
|
|
173
|
+
pool.pathBuilder.dispose();
|
|
127
174
|
}
|
|
128
175
|
|
|
129
176
|
function configureFillPaint(
|
|
130
|
-
skPaint: SkPaint,
|
|
131
177
|
paint: VexflowRecordingPaint,
|
|
132
|
-
|
|
178
|
+
pool: ReplayPool
|
|
133
179
|
): SkPaint {
|
|
134
180
|
'worklet';
|
|
135
181
|
|
|
136
|
-
skPaint.
|
|
137
|
-
|
|
182
|
+
const skPaint = pool.fillPaint;
|
|
183
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
184
|
+
applyGlow(skPaint, paint, pool);
|
|
138
185
|
|
|
139
186
|
return skPaint;
|
|
140
187
|
}
|
|
141
188
|
|
|
142
189
|
function configureStrokePaint(
|
|
143
|
-
skPaint: SkPaint,
|
|
144
190
|
paint: VexflowRecordingPaint,
|
|
145
|
-
|
|
191
|
+
pool: ReplayPool
|
|
146
192
|
): SkPaint {
|
|
147
193
|
'worklet';
|
|
148
194
|
|
|
149
|
-
skPaint.
|
|
195
|
+
const skPaint = pool.strokePaint;
|
|
196
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
150
197
|
skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
|
|
151
198
|
skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
|
|
152
|
-
applyGlow(skPaint, paint,
|
|
153
|
-
|
|
154
|
-
if (paint.lineDash != null && paint.lineDash.length > 0) {
|
|
155
|
-
skPaint.setPathEffect(Skia.PathEffect.MakeDash(paint.lineDash));
|
|
156
|
-
} else {
|
|
157
|
-
skPaint.setPathEffect(null);
|
|
158
|
-
}
|
|
199
|
+
applyGlow(skPaint, paint, pool);
|
|
200
|
+
applyDash(skPaint, paint.lineDash, pool);
|
|
159
201
|
|
|
160
202
|
return skPaint;
|
|
161
203
|
}
|
|
162
204
|
|
|
163
|
-
function
|
|
205
|
+
function getClearPaint(pool: ReplayPool): SkPaint {
|
|
164
206
|
'worklet';
|
|
165
207
|
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
if (pool.clearPaint == null) {
|
|
209
|
+
pool.clearPaint = Skia.Paint();
|
|
210
|
+
pool.clearPaint.setBlendMode(BlendMode.Clear);
|
|
211
|
+
}
|
|
168
212
|
|
|
169
|
-
return clearPaint;
|
|
213
|
+
return pool.clearPaint;
|
|
170
214
|
}
|
|
171
215
|
|
|
172
216
|
type PaintKind = 'fill' | 'stroke';
|
|
@@ -261,14 +305,10 @@ function applyPathCommand(
|
|
|
261
305
|
builder.quadTo(command.cpx, command.cpy, command.x, command.y);
|
|
262
306
|
break;
|
|
263
307
|
case 'addRect':
|
|
264
|
-
builder.addRect(
|
|
308
|
+
builder.addRect(command.rect);
|
|
265
309
|
break;
|
|
266
310
|
case 'addArc':
|
|
267
|
-
builder.addArc(
|
|
268
|
-
toSkiaRect(command.rect),
|
|
269
|
-
command.startDegrees,
|
|
270
|
-
command.sweepDegrees
|
|
271
|
-
);
|
|
311
|
+
builder.addArc(command.rect, command.startDegrees, command.sweepDegrees);
|
|
272
312
|
break;
|
|
273
313
|
case 'close':
|
|
274
314
|
builder.close();
|
|
@@ -278,16 +318,26 @@ function applyPathCommand(
|
|
|
278
318
|
}
|
|
279
319
|
}
|
|
280
320
|
|
|
281
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Build the recorded path in the pooled builder (`detach` hands over the path
|
|
323
|
+
* and resets the builder for the next command), draw it, and free it at once:
|
|
324
|
+
* the canvas copies the path at the draw call.
|
|
325
|
+
*/
|
|
326
|
+
function drawRecordedPath(
|
|
327
|
+
canvas: SkCanvas,
|
|
328
|
+
path: readonly VexflowRecordingPathCommand[],
|
|
329
|
+
skPaint: SkPaint,
|
|
330
|
+
builder: SkPathBuilder
|
|
331
|
+
) {
|
|
282
332
|
'worklet';
|
|
283
333
|
|
|
284
|
-
const builder = Skia.PathBuilder.Make();
|
|
285
|
-
|
|
286
334
|
for (const command of path) {
|
|
287
335
|
applyPathCommand(builder, command);
|
|
288
336
|
}
|
|
289
337
|
|
|
290
|
-
|
|
338
|
+
const skPath = builder.detach();
|
|
339
|
+
canvas.drawPath(skPath, skPaint);
|
|
340
|
+
skPath.dispose();
|
|
291
341
|
}
|
|
292
342
|
|
|
293
343
|
export function renderVexflowRecordingCommands(
|
|
@@ -314,98 +364,100 @@ export function renderVexflowRecordingCommands(
|
|
|
314
364
|
|
|
315
365
|
const fontManager =
|
|
316
366
|
replayFontManager ?? new FontManager(fontProvider, defaultFont);
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
)
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
const pool = createReplayPool();
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
for (const command of commands) {
|
|
371
|
+
switch (command.type) {
|
|
372
|
+
case 'clear':
|
|
373
|
+
canvas.clear(getCachedColor(command.color, pool));
|
|
374
|
+
break;
|
|
375
|
+
case 'save':
|
|
376
|
+
canvas.save();
|
|
377
|
+
break;
|
|
378
|
+
case 'restore':
|
|
379
|
+
canvas.restore();
|
|
380
|
+
break;
|
|
381
|
+
case 'scale':
|
|
382
|
+
canvas.scale(command.x, command.y);
|
|
383
|
+
break;
|
|
384
|
+
case 'translate':
|
|
385
|
+
canvas.translate(command.x, command.y);
|
|
386
|
+
break;
|
|
387
|
+
case 'clipRect':
|
|
388
|
+
canvas.clipRect(command.rect, ClipOp.Intersect, true);
|
|
389
|
+
break;
|
|
390
|
+
case 'fillRect':
|
|
391
|
+
canvas.drawRect(
|
|
392
|
+
command.rect,
|
|
393
|
+
configureFillPaint(
|
|
394
|
+
resolveStyle(
|
|
395
|
+
command.paint,
|
|
396
|
+
command.groupId,
|
|
397
|
+
'fill',
|
|
398
|
+
styleOverrides
|
|
399
|
+
),
|
|
400
|
+
pool
|
|
401
|
+
)
|
|
402
|
+
);
|
|
403
|
+
break;
|
|
404
|
+
case 'clearRect':
|
|
405
|
+
canvas.drawRect(command.rect, getClearPaint(pool));
|
|
406
|
+
break;
|
|
407
|
+
case 'fillPath':
|
|
408
|
+
drawRecordedPath(
|
|
409
|
+
canvas,
|
|
410
|
+
command.path,
|
|
411
|
+
configureFillPaint(
|
|
412
|
+
resolveStyle(
|
|
413
|
+
command.paint,
|
|
414
|
+
command.groupId,
|
|
415
|
+
'fill',
|
|
416
|
+
styleOverrides
|
|
417
|
+
),
|
|
418
|
+
pool
|
|
369
419
|
),
|
|
370
|
-
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
420
|
+
pool.pathBuilder
|
|
421
|
+
);
|
|
422
|
+
break;
|
|
423
|
+
case 'strokePath':
|
|
424
|
+
drawRecordedPath(
|
|
425
|
+
canvas,
|
|
426
|
+
command.path,
|
|
427
|
+
configureStrokePaint(
|
|
428
|
+
resolveStyle(
|
|
429
|
+
command.paint,
|
|
430
|
+
command.groupId,
|
|
431
|
+
'stroke',
|
|
432
|
+
styleOverrides
|
|
433
|
+
),
|
|
434
|
+
pool
|
|
384
435
|
),
|
|
385
|
-
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
436
|
+
pool.pathBuilder
|
|
437
|
+
);
|
|
438
|
+
break;
|
|
439
|
+
case 'fillText':
|
|
440
|
+
canvas.drawText(
|
|
441
|
+
command.text,
|
|
442
|
+
command.x,
|
|
443
|
+
command.y,
|
|
444
|
+
configureFillPaint(
|
|
445
|
+
resolveStyle(
|
|
446
|
+
command.paint,
|
|
447
|
+
command.groupId,
|
|
448
|
+
'fill',
|
|
449
|
+
styleOverrides
|
|
450
|
+
),
|
|
451
|
+
pool
|
|
401
452
|
),
|
|
402
|
-
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
assertNever(command);
|
|
453
|
+
createFont(fontManager, command.font)
|
|
454
|
+
);
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
assertNever(command);
|
|
458
|
+
}
|
|
409
459
|
}
|
|
460
|
+
} finally {
|
|
461
|
+
disposeReplayPool(pool);
|
|
410
462
|
}
|
|
411
463
|
}
|
package/src/base/types.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react';
|
|
2
|
-
import { Picture, type SkPicture } from '
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useDerivedValue,
|
|
6
|
-
useSharedValue,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import { Picture, type SkPicture } from 'react-native-skia';
|
|
3
|
+
import { useDerivedValue, useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { scheduleOnUI } from 'react-native-worklets';
|
|
8
5
|
|
|
9
6
|
import type { VexflowRecordingCommand } from '../../base';
|
|
10
7
|
import { isVexflowNativeDebugEnabled } from '../../shared/debug';
|
|
@@ -110,7 +107,7 @@ export default function ScoreOverlayPicture({
|
|
|
110
107
|
|
|
111
108
|
useEffect(() => {
|
|
112
109
|
return () => {
|
|
113
|
-
|
|
110
|
+
scheduleOnUI(disposeOverlayPictures, disposal);
|
|
114
111
|
};
|
|
115
112
|
}, [disposal]);
|
|
116
113
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { RoundedRect, Skia, type SkRRect } from '
|
|
2
|
+
import { RoundedRect, Skia, type SkRRect } from 'react-native-skia';
|
|
3
3
|
import { useDerivedValue, type SharedValue } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
import type {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
Canvas,
|
|
5
|
-
Group,
|
|
6
|
-
Picture,
|
|
7
|
-
Skia,
|
|
8
|
-
useCanvasRef,
|
|
9
|
-
} from '@shopify/react-native-skia';
|
|
3
|
+
import { Canvas, Group, Picture, Skia, useCanvasRef } from 'react-native-skia';
|
|
10
4
|
import { StyleSheet, View, type LayoutChangeEvent } from 'react-native';
|
|
11
5
|
import { GestureDetector } from 'react-native-gesture-handler';
|
|
12
6
|
import { useDerivedValue } from 'react-native-reanimated';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SkPicture,
|
|
3
|
-
SkTypefaceFontProvider,
|
|
4
|
-
} from '@shopify/react-native-skia';
|
|
1
|
+
import type { SkPicture, SkTypefaceFontProvider } from 'react-native-skia';
|
|
5
2
|
import type { GestureType } from 'react-native-gesture-handler';
|
|
6
3
|
import type { SharedValue } from 'react-native-reanimated';
|
|
7
4
|
|