@shopify/react-native-skia 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +10 -4
- package/android/cpp/rnskia-android/OpenGLContext.h +29 -3
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +9 -2
- package/android/cpp/rnskia-android/gl/Context.h +3 -0
- package/android/cpp/rnskia-android/gl/Surface.h +1 -1
- package/cpp/api/JsiSkParagraph.h +114 -0
- package/cpp/api/JsiSkiaContext.h +4 -0
- package/cpp/rnskia/RNSkView.h +6 -0
- package/lib/commonjs/Platform/Platform.js +5 -2
- package/lib/commonjs/Platform/Platform.js.map +1 -1
- package/lib/commonjs/Platform/Platform.web.js +8 -7
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.js +11 -2
- package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/commonjs/skia/core/Font.d.ts +21 -6
- package/lib/commonjs/skia/core/Font.js +24 -4
- package/lib/commonjs/skia/core/Font.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.web.js +4 -5
- package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
- package/lib/commonjs/skia/types/Data/Data.d.ts +5 -4
- package/lib/commonjs/skia/types/Data/Data.js +7 -1
- package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
- package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/commonjs/skia/web/Host.js +7 -0
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +43 -2
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +5 -0
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.js +6 -0
- package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.js +34 -3
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js +66 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js +26 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/Player.js +1 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +12 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +1 -0
- package/lib/commonjs/sksg/StaticContainer.js +27 -1
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/module/Platform/Platform.js +6 -3
- package/lib/module/Platform/Platform.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +9 -8
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/external/reanimated/useVideoLoading.js +12 -2
- package/lib/module/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/module/skia/core/Font.d.ts +21 -6
- package/lib/module/skia/core/Font.js +26 -5
- package/lib/module/skia/core/Font.js.map +1 -1
- package/lib/module/skia/core/SVG.web.js +4 -5
- package/lib/module/skia/core/SVG.web.js.map +1 -1
- package/lib/module/skia/types/Data/Data.d.ts +5 -4
- package/lib/module/skia/types/Data/Data.js +5 -0
- package/lib/module/skia/types/Data/Data.js.map +1 -1
- package/lib/module/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/module/skia/web/Host.js +7 -0
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/module/skia/web/JsiSkFont.js +44 -3
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +5 -0
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/module/skia/web/JsiSkParagraph.js +7 -1
- package/lib/module/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/module/sksg/Container.web.js +35 -4
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/module/sksg/Recorder/FrameScope.js +59 -0
- package/lib/module/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/module/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js +19 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/module/sksg/Recorder/Player.js +1 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/module/sksg/Recorder/Recorder.js +10 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +1 -0
- package/lib/module/sksg/StaticContainer.js +28 -2
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/types/Data/Data.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +2 -2
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.d.ts +17 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +13 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Data/Data.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/typescript/lib/module/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +2 -2
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.native.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/src/skia/core/Font.d.ts +21 -6
- package/lib/typescript/src/skia/types/Data/Data.d.ts +5 -4
- package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/typescript/src/sksg/StaticContainer.d.ts +1 -0
- package/package.json +8 -2
- package/react-native-skia.podspec +18 -10
- package/src/Platform/Platform.ts +6 -7
- package/src/Platform/Platform.web.tsx +9 -8
- package/src/external/reanimated/useVideoLoading.ts +12 -2
- package/src/skia/core/Font.ts +34 -13
- package/src/skia/core/SVG.web.ts +5 -14
- package/src/skia/types/Data/Data.ts +14 -4
- package/src/skia/types/Paragraph/Paragraph.ts +67 -0
- package/src/skia/web/Host.ts +7 -0
- package/src/skia/web/JsiSkFont.ts +48 -4
- package/src/skia/web/JsiSkPaint.ts +5 -0
- package/src/skia/web/JsiSkParagraph.ts +9 -1
- package/src/sksg/Container.web.ts +31 -4
- package/src/sksg/Recorder/DrawingContext.ts +19 -6
- package/src/sksg/Recorder/FrameScope.native.ts +21 -0
- package/src/sksg/Recorder/FrameScope.ts +69 -0
- package/src/sksg/Recorder/Player.ts +1 -2
- package/src/sksg/Recorder/Recorder.ts +15 -1
- package/src/sksg/Recorder/commands/Drawing.ts +3 -3
- package/src/sksg/Recorder/commands/Shaders.ts +22 -16
- package/src/sksg/StaticContainer.ts +29 -2
package/android/build.gradle
CHANGED
|
@@ -74,12 +74,18 @@ static def resolveNodePackage(packageName, baseDir) {
|
|
|
74
74
|
return proc.text.trim()
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// Graphite is detected via a marker file created by install-skia-graphite
|
|
78
|
-
//
|
|
79
|
-
// binaries live in the react-native-skia-android npm package
|
|
77
|
+
// Graphite is detected via a marker file (created by install-skia-graphite for
|
|
78
|
+
// in-repo development, or shipped in the npm tarball for next-channel releases).
|
|
79
|
+
// The prebuilt binaries live in the react-native-skia-android npm package for the
|
|
80
|
+
// default (Ganesh) build and in react-native-skia-graphite-android for Graphite.
|
|
81
|
+
// In-repo Graphite development downloads them directly into libs/android instead,
|
|
82
|
+
// which takes precedence over the npm package when present.
|
|
80
83
|
def useGraphite = file("${projectDir}/../libs/.graphite").exists()
|
|
84
|
+
def localGraphiteLibs = file("${projectDir}/../libs/android")
|
|
81
85
|
def skiaLibsPath = useGraphite
|
|
82
|
-
?
|
|
86
|
+
? (localGraphiteLibs.exists()
|
|
87
|
+
? "${projectDir}/../libs/android"
|
|
88
|
+
: "${resolveNodePackage('react-native-skia-graphite-android', projectDir)}/libs")
|
|
83
89
|
: "${resolveNodePackage('react-native-skia-android', projectDir)}/libs"
|
|
84
90
|
|
|
85
91
|
logger.warn("react-native-skia: SK_GRAPHITE: ${useGraphite}")
|
|
@@ -42,6 +42,11 @@ private:
|
|
|
42
42
|
_glConfig = _glDisplay->chooseConfig();
|
|
43
43
|
_glContext = _glDisplay->makeContext(_glConfig, nullptr);
|
|
44
44
|
_glSurface = _glDisplay->makePixelBufferSurface(_glConfig, 1, 1);
|
|
45
|
+
if (_glContext == nullptr || _glSurface == nullptr) {
|
|
46
|
+
RNSkLogger::logToConsole(
|
|
47
|
+
"Couldn't create the shared OpenGL context or surface");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
45
50
|
_glContext->makeCurrent(_glSurface.get());
|
|
46
51
|
}
|
|
47
52
|
};
|
|
@@ -60,6 +65,10 @@ public:
|
|
|
60
65
|
|
|
61
66
|
sk_sp<SkSurface> MakeOffscreen(int width, int height,
|
|
62
67
|
bool useP3ColorSpace = false) {
|
|
68
|
+
if (_directContext == nullptr) {
|
|
69
|
+
return nullptr;
|
|
70
|
+
}
|
|
71
|
+
|
|
63
72
|
auto colorType = kRGBA_8888_SkColorType;
|
|
64
73
|
|
|
65
74
|
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
|
@@ -110,6 +119,9 @@ public:
|
|
|
110
119
|
sk_sp<SkImage> MakeImageFromBuffer(void *buffer,
|
|
111
120
|
bool requireKnownFormat = false) {
|
|
112
121
|
#if __ANDROID_API__ >= 26
|
|
122
|
+
if (_directContext == nullptr) {
|
|
123
|
+
return nullptr;
|
|
124
|
+
}
|
|
113
125
|
const AHardwareBuffer *hardwareBuffer =
|
|
114
126
|
static_cast<AHardwareBuffer *>(buffer);
|
|
115
127
|
DeleteImageProc deleteImageProc = nullptr;
|
|
@@ -181,6 +193,11 @@ public:
|
|
|
181
193
|
// TODO: remove width, height
|
|
182
194
|
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window,
|
|
183
195
|
bool highBitDepth = false) {
|
|
196
|
+
if (_directContext == nullptr) {
|
|
197
|
+
RNSkLogger::logToConsole(
|
|
198
|
+
"The OpenGL context is invalid, the surface will not be rendered");
|
|
199
|
+
return nullptr;
|
|
200
|
+
}
|
|
184
201
|
auto display = OpenGLSharedContext::getInstance().getDisplay();
|
|
185
202
|
if (highBitDepth) {
|
|
186
203
|
// A 10-bit window surface would require the shared EGL context to be
|
|
@@ -196,7 +213,11 @@ public:
|
|
|
196
213
|
}
|
|
197
214
|
|
|
198
215
|
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
|
199
|
-
void makeCurrent() {
|
|
216
|
+
void makeCurrent() {
|
|
217
|
+
if (_glContext != nullptr) {
|
|
218
|
+
_glContext->makeCurrent(_glSurface.get());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
200
221
|
|
|
201
222
|
private:
|
|
202
223
|
std::unique_ptr<gl::Context> _glContext;
|
|
@@ -209,12 +230,17 @@ private:
|
|
|
209
230
|
auto glConfig = OpenGLSharedContext::getInstance().getConfig();
|
|
210
231
|
_glContext = display->makeContext(glConfig, sharedContext);
|
|
211
232
|
_glSurface = display->makePixelBufferSurface(glConfig, 1, 1);
|
|
212
|
-
_glContext
|
|
233
|
+
if (_glContext == nullptr || _glSurface == nullptr ||
|
|
234
|
+
!_glContext->makeCurrent(_glSurface.get())) {
|
|
235
|
+
RNSkLogger::logToConsole(
|
|
236
|
+
"Couldn't create the OpenGL context, Skia rendering is disabled");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
213
239
|
auto backendInterface = GrGLMakeNativeInterface();
|
|
214
240
|
_directContext = GrDirectContexts::MakeGL(backendInterface);
|
|
215
241
|
|
|
216
242
|
if (_directContext == nullptr) {
|
|
217
|
-
|
|
243
|
+
RNSkLogger::logToConsole("GrDirectContexts::MakeGL failed");
|
|
218
244
|
}
|
|
219
245
|
}
|
|
220
246
|
};
|
|
@@ -16,7 +16,12 @@ namespace RNSkia {
|
|
|
16
16
|
|
|
17
17
|
sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
18
18
|
if (_skSurface == nullptr) {
|
|
19
|
-
_glContext->makeCurrent(_glSurface.get())
|
|
19
|
+
if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
|
|
20
|
+
RNSkLogger::logToConsole(
|
|
21
|
+
"Couldn't create the EGL window surface, the surface will not be "
|
|
22
|
+
"rendered");
|
|
23
|
+
return nullptr;
|
|
24
|
+
}
|
|
20
25
|
GLint stencil;
|
|
21
26
|
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
|
22
27
|
|
|
@@ -52,7 +57,9 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
void OpenGLWindowContext::present() {
|
|
55
|
-
_glContext->makeCurrent(_glSurface.get())
|
|
60
|
+
if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
56
63
|
_directContext->flushAndSubmit();
|
|
57
64
|
_glSurface->present();
|
|
58
65
|
}
|
|
@@ -26,6 +26,9 @@ public:
|
|
|
26
26
|
if (_context == EGL_NO_CONTEXT) {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
|
+
if (surface == nullptr || !surface->isValid()) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
29
32
|
const auto result =
|
|
30
33
|
eglMakeCurrentIfNecessary(_display, surface->getHandle(),
|
|
31
34
|
surface->getHandle(), _context) == EGL_TRUE;
|
package/cpp/api/JsiSkParagraph.h
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#include <jsi/jsi.h>
|
|
9
9
|
|
|
10
10
|
#include "JsiSkCanvas.h"
|
|
11
|
+
#include "JsiSkFont.h"
|
|
11
12
|
#include "JsiSkHostObjects.h"
|
|
12
13
|
#include "JsiSkPath.h"
|
|
13
14
|
#include "JsiSkRect.h"
|
|
@@ -141,6 +142,117 @@ public:
|
|
|
141
142
|
return returnValue;
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
JSI_HOST_FUNCTION(getPath) {
|
|
146
|
+
auto lineNumber =
|
|
147
|
+
static_cast<int>(getArgumentAsNumber(runtime, arguments, count, 0));
|
|
148
|
+
auto paragraph = getObject();
|
|
149
|
+
// Paragraph::getPath does not bounds-check the line number.
|
|
150
|
+
if (lineNumber < 0 ||
|
|
151
|
+
static_cast<size_t>(lineNumber) >= paragraph->lineNumber()) {
|
|
152
|
+
return jsi::Value::null();
|
|
153
|
+
}
|
|
154
|
+
// Paragraph::getPath resets its path builder after every visual run, so
|
|
155
|
+
// for lines shaped as multiple runs (e.g. through font fallback) it only
|
|
156
|
+
// returns the glyphs of the last run. Build the path from the per-glyph
|
|
157
|
+
// data exposed by extendedVisit instead.
|
|
158
|
+
SkPathBuilder builder;
|
|
159
|
+
paragraph->extendedVisit(
|
|
160
|
+
[lineNumber, &builder](
|
|
161
|
+
int visitedLine, const para::Paragraph::ExtendedVisitorInfo *info) {
|
|
162
|
+
if (visitedLine != lineNumber || info == nullptr) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
struct Rec {
|
|
166
|
+
SkPathBuilder *builder;
|
|
167
|
+
SkPoint origin;
|
|
168
|
+
const SkPoint *pos;
|
|
169
|
+
} rec = {&builder, info->origin, info->positions};
|
|
170
|
+
info->font.getPaths(
|
|
171
|
+
{info->glyphs, static_cast<size_t>(info->count)},
|
|
172
|
+
[](const SkPath *src, const SkMatrix &mx, void *ctx) {
|
|
173
|
+
auto *rec = static_cast<Rec *>(ctx);
|
|
174
|
+
if (src != nullptr) {
|
|
175
|
+
SkMatrix total = mx;
|
|
176
|
+
total.postTranslate(rec->origin.fX + rec->pos->fX,
|
|
177
|
+
rec->origin.fY + rec->pos->fY);
|
|
178
|
+
rec->builder->addPath(*src, total);
|
|
179
|
+
}
|
|
180
|
+
rec->pos += 1;
|
|
181
|
+
},
|
|
182
|
+
&rec);
|
|
183
|
+
});
|
|
184
|
+
SkPath path = builder.detach();
|
|
185
|
+
auto hostObjectInstance =
|
|
186
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(path));
|
|
187
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
188
|
+
runtime, hostObjectInstance, getContext());
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
JSI_HOST_FUNCTION(extendedVisit) {
|
|
192
|
+
auto visitorObject = getArgumentAsFunction(runtime, arguments, count, 0);
|
|
193
|
+
auto visitor = visitorObject.asFunction(runtime);
|
|
194
|
+
auto context = getContext();
|
|
195
|
+
getObject()->extendedVisit(
|
|
196
|
+
[&runtime, &visitor, &context](
|
|
197
|
+
int lineNumber, const para::Paragraph::ExtendedVisitorInfo *info) {
|
|
198
|
+
if (info == nullptr) {
|
|
199
|
+
// Signals the end of the line
|
|
200
|
+
visitor.call(runtime, static_cast<double>(lineNumber),
|
|
201
|
+
jsi::Value::null());
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
auto value = jsi::Object(runtime);
|
|
205
|
+
|
|
206
|
+
auto fontInstance = std::make_shared<JsiSkFont>(context, info->font);
|
|
207
|
+
value.setProperty(runtime, "font",
|
|
208
|
+
JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
209
|
+
runtime, fontInstance, context));
|
|
210
|
+
|
|
211
|
+
auto origin = jsi::Object(runtime);
|
|
212
|
+
origin.setProperty(runtime, "x",
|
|
213
|
+
static_cast<double>(info->origin.x()));
|
|
214
|
+
origin.setProperty(runtime, "y",
|
|
215
|
+
static_cast<double>(info->origin.y()));
|
|
216
|
+
value.setProperty(runtime, "origin", origin);
|
|
217
|
+
|
|
218
|
+
auto advance = jsi::Object(runtime);
|
|
219
|
+
advance.setProperty(runtime, "width",
|
|
220
|
+
static_cast<double>(info->advance.width()));
|
|
221
|
+
advance.setProperty(runtime, "height",
|
|
222
|
+
static_cast<double>(info->advance.height()));
|
|
223
|
+
value.setProperty(runtime, "advance", advance);
|
|
224
|
+
|
|
225
|
+
auto size = info->count;
|
|
226
|
+
auto glyphs = jsi::Array(runtime, size);
|
|
227
|
+
auto positions = jsi::Array(runtime, size);
|
|
228
|
+
auto bounds = jsi::Array(runtime, size);
|
|
229
|
+
auto utf8Starts = jsi::Array(runtime, size);
|
|
230
|
+
for (int i = 0; i < size; ++i) {
|
|
231
|
+
glyphs.setValueAtIndex(runtime, i,
|
|
232
|
+
static_cast<double>(info->glyphs[i]));
|
|
233
|
+
auto position = jsi::Object(runtime);
|
|
234
|
+
position.setProperty(runtime, "x",
|
|
235
|
+
static_cast<double>(info->positions[i].x()));
|
|
236
|
+
position.setProperty(runtime, "y",
|
|
237
|
+
static_cast<double>(info->positions[i].y()));
|
|
238
|
+
positions.setValueAtIndex(runtime, i, position);
|
|
239
|
+
bounds.setValueAtIndex(
|
|
240
|
+
runtime, i,
|
|
241
|
+
JsiSkRect::toValue(runtime, context, info->bounds[i]));
|
|
242
|
+
utf8Starts.setValueAtIndex(
|
|
243
|
+
runtime, i, static_cast<double>(info->utf8Starts[i]));
|
|
244
|
+
}
|
|
245
|
+
value.setProperty(runtime, "glyphs", glyphs);
|
|
246
|
+
value.setProperty(runtime, "positions", positions);
|
|
247
|
+
value.setProperty(runtime, "bounds", bounds);
|
|
248
|
+
value.setProperty(runtime, "utf8Starts", utf8Starts);
|
|
249
|
+
value.setProperty(runtime, "flags", static_cast<double>(info->flags));
|
|
250
|
+
|
|
251
|
+
visitor.call(runtime, static_cast<double>(lineNumber), value);
|
|
252
|
+
});
|
|
253
|
+
return jsi::Value::undefined();
|
|
254
|
+
}
|
|
255
|
+
|
|
144
256
|
JSI_HOST_FUNCTION(getRectsForPlaceholders) {
|
|
145
257
|
std::vector<para::TextBox> placeholderInfos =
|
|
146
258
|
getObject()->getRectsForPlaceholders();
|
|
@@ -169,6 +281,8 @@ public:
|
|
|
169
281
|
getGlyphPositionAtCoordinate),
|
|
170
282
|
JSI_EXPORT_FUNC(JsiSkParagraph, getRectsForRange),
|
|
171
283
|
JSI_EXPORT_FUNC(JsiSkParagraph, getLineMetrics),
|
|
284
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getPath),
|
|
285
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, extendedVisit),
|
|
172
286
|
JSI_EXPORT_FUNC(JsiSkParagraph, dispose))
|
|
173
287
|
|
|
174
288
|
size_t getMemoryPressure() const override { return 1024 * 1024; }
|
package/cpp/api/JsiSkiaContext.h
CHANGED
|
@@ -79,6 +79,10 @@ public:
|
|
|
79
79
|
}
|
|
80
80
|
auto result =
|
|
81
81
|
context->makeContextFromNativeSurface(surface, width, height);
|
|
82
|
+
if (result == nullptr) {
|
|
83
|
+
throw std::runtime_error(
|
|
84
|
+
"Couldn't create a Skia context from the native surface");
|
|
85
|
+
}
|
|
82
86
|
// Return the newly constructed object
|
|
83
87
|
auto hostObjectInstance =
|
|
84
88
|
std::make_shared<JsiSkiaContext>(context, std::move(result));
|
package/cpp/rnskia/RNSkView.h
CHANGED
|
@@ -84,6 +84,9 @@ public:
|
|
|
84
84
|
Returns a snapshot of the current surface/canvas
|
|
85
85
|
*/
|
|
86
86
|
sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
|
|
87
|
+
if (_surface == nullptr) {
|
|
88
|
+
return nullptr;
|
|
89
|
+
}
|
|
87
90
|
sk_sp<SkImage> image;
|
|
88
91
|
if (bounds != nullptr) {
|
|
89
92
|
SkIRect b =
|
|
@@ -120,6 +123,9 @@ public:
|
|
|
120
123
|
Render to a canvas
|
|
121
124
|
*/
|
|
122
125
|
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override {
|
|
126
|
+
if (_surface == nullptr) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
123
129
|
cb(_surface->getCanvas());
|
|
124
130
|
return true;
|
|
125
131
|
};
|
|
@@ -10,8 +10,11 @@ const Platform = exports.Platform = {
|
|
|
10
10
|
OS: _reactNative.Platform.OS,
|
|
11
11
|
PixelRatio: _reactNative.PixelRatio.get(),
|
|
12
12
|
resolveAsset: source => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const asset = (0, _types.unwrapModule)(source);
|
|
14
|
+
if (typeof asset === "string") {
|
|
15
|
+
return asset;
|
|
16
|
+
}
|
|
17
|
+
return (0, _types.isRNModule)(asset) ? _reactNative.Image.resolveAssetSource(asset).uri : asset.uri;
|
|
15
18
|
},
|
|
16
19
|
findNodeHandle: _reactNative.findNodeHandle,
|
|
17
20
|
View: _reactNative.View
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_types","Platform","exports","OS","RNPlatform","PixelRatio","get","resolveAsset","source","isRNModule","Image","resolveAssetSource","uri","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_types","Platform","exports","OS","RNPlatform","PixelRatio","get","resolveAsset","source","asset","unwrapModule","isRNModule","Image","resolveAssetSource","uri","findNodeHandle","View"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n Platform as RNPlatform,\n findNodeHandle,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule, unwrapModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n resolveAsset: (source: DataModule) => {\n const asset = unwrapModule(source);\n if (typeof asset === \"string\") {\n return asset;\n }\n return isRNModule(asset) ? Image.resolveAssetSource(asset).uri : asset.uri;\n },\n findNodeHandle,\n View,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAIO,MAAME,QAAmB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACjCE,EAAE,EAAEC,qBAAU,CAACD,EAAE;EACjBE,UAAU,EAAEA,uBAAU,CAACC,GAAG,CAAC,CAAC;EAC5BC,YAAY,EAAGC,MAAkB,IAAK;IACpC,MAAMC,KAAK,GAAG,IAAAC,mBAAY,EAACF,MAAM,CAAC;IAClC,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAOA,KAAK;IACd;IACA,OAAO,IAAAE,iBAAU,EAACF,KAAK,CAAC,GAAGG,kBAAK,CAACC,kBAAkB,CAACJ,KAAK,CAAC,CAACK,GAAG,GAAGL,KAAK,CAACK,GAAG;EAC5E,CAAC;EACDC,cAAc,EAAdA,2BAAc;EACdC,IAAI,EAAJA;AACF,CAAC","ignoreList":[]}
|
|
@@ -44,8 +44,12 @@ const Platform = exports.Platform = {
|
|
|
44
44
|
PixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
|
|
45
45
|
// window is not defined on node
|
|
46
46
|
resolveAsset: source => {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const asset = (0, _types.unwrapModule)(source);
|
|
48
|
+
if (typeof asset === "string") {
|
|
49
|
+
return asset;
|
|
50
|
+
}
|
|
51
|
+
if ((0, _types.isRNModule)(asset)) {
|
|
52
|
+
if (typeof require === "function") {
|
|
49
53
|
const {
|
|
50
54
|
getAssetByID
|
|
51
55
|
} = require("react-native/Libraries/Image/AssetRegistry");
|
|
@@ -53,16 +57,13 @@ const Platform = exports.Platform = {
|
|
|
53
57
|
httpServerLocation,
|
|
54
58
|
name,
|
|
55
59
|
type
|
|
56
|
-
} = getAssetByID(
|
|
60
|
+
} = getAssetByID(asset);
|
|
57
61
|
const uri = `${httpServerLocation}/${name}.${type}`;
|
|
58
62
|
return uri;
|
|
59
63
|
}
|
|
60
64
|
throw new Error("Asset source is a number - this is not supported on the web");
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
return source.uri;
|
|
64
|
-
}
|
|
65
|
-
return source.default;
|
|
66
|
+
return asset.uri;
|
|
66
67
|
},
|
|
67
68
|
findNodeHandle: () => {
|
|
68
69
|
throw new Error("findNodeHandle is not supported on the web");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_types","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","View","children","style","rawStyle","useMemo","cssStyles","alignItems","backgroundColor","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","textDecoration","zIndex","createElement","Platform","exports","OS","PixelRatio","window","devicePixelRatio","resolveAsset","source","isRNModule","getAssetByID","httpServerLocation","name","type","uri","Error","findNodeHandle"],"sources":["Platform.web.tsx"],"sourcesContent":["import type { CSSProperties } from \"react\";\nimport React, { useMemo } from \"react\";\nimport type { ViewComponent, ViewProps } from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\n// Layout is observed by the views themselves (see SkiaPictureView.web.tsx):\n// this shim only reproduces react-native-web's default View styling.\nconst View = (({ children, style: rawStyle }: ViewProps) => {\n const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);\n const cssStyles = useMemo(() => {\n return {\n alignItems: \"stretch\" as const,\n backgroundColor: \"transparent\" as const,\n border: \"0 solid black\" as const,\n boxSizing: \"border-box\" as const,\n display: \"flex\" as const,\n flexBasis: \"auto\" as const,\n flexDirection: \"column\" as const,\n flexShrink: 0,\n listStyle: \"none\" as const,\n margin: 0,\n minHeight: 0,\n minWidth: 0,\n padding: 0,\n position: \"relative\" as const,\n textDecoration: \"none\" as const,\n zIndex: 0,\n ...style,\n };\n }, [style]);\n\n return <div style={cssStyles}>{children}</div>;\n}) as unknown as typeof ViewComponent;\n\nexport const Platform: IPlatform = {\n OS: \"web\",\n PixelRatio: typeof window !== \"undefined\" ? window.devicePixelRatio : 1, // window is not defined on node\n resolveAsset: (source: DataModule) => {\n
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_types","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","View","children","style","rawStyle","useMemo","cssStyles","alignItems","backgroundColor","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","textDecoration","zIndex","createElement","Platform","exports","OS","PixelRatio","window","devicePixelRatio","resolveAsset","source","asset","unwrapModule","isRNModule","getAssetByID","httpServerLocation","name","type","uri","Error","findNodeHandle"],"sources":["Platform.web.tsx"],"sourcesContent":["import type { CSSProperties } from \"react\";\nimport React, { useMemo } from \"react\";\nimport type { ViewComponent, ViewProps } from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule, unwrapModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\n// Layout is observed by the views themselves (see SkiaPictureView.web.tsx):\n// this shim only reproduces react-native-web's default View styling.\nconst View = (({ children, style: rawStyle }: ViewProps) => {\n const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);\n const cssStyles = useMemo(() => {\n return {\n alignItems: \"stretch\" as const,\n backgroundColor: \"transparent\" as const,\n border: \"0 solid black\" as const,\n boxSizing: \"border-box\" as const,\n display: \"flex\" as const,\n flexBasis: \"auto\" as const,\n flexDirection: \"column\" as const,\n flexShrink: 0,\n listStyle: \"none\" as const,\n margin: 0,\n minHeight: 0,\n minWidth: 0,\n padding: 0,\n position: \"relative\" as const,\n textDecoration: \"none\" as const,\n zIndex: 0,\n ...style,\n };\n }, [style]);\n\n return <div style={cssStyles}>{children}</div>;\n}) as unknown as typeof ViewComponent;\n\nexport const Platform: IPlatform = {\n OS: \"web\",\n PixelRatio: typeof window !== \"undefined\" ? window.devicePixelRatio : 1, // window is not defined on node\n resolveAsset: (source: DataModule) => {\n const asset = unwrapModule(source);\n if (typeof asset === \"string\") {\n return asset;\n }\n if (isRNModule(asset)) {\n if (typeof require === \"function\") {\n const {\n getAssetByID,\n } = require(\"react-native/Libraries/Image/AssetRegistry\");\n const { httpServerLocation, name, type } = getAssetByID(asset);\n const uri = `${httpServerLocation}/${name}.${type}`;\n return uri;\n }\n throw new Error(\n \"Asset source is a number - this is not supported on the web\"\n );\n }\n return asset.uri;\n },\n findNodeHandle: () => {\n throw new Error(\"findNodeHandle is not supported on the web\");\n },\n View,\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAAyD,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA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AAe;MAC/BC,MAAM,EAAE,CAAC;MACT,GAAGnB;IACL,CAAC;EACH,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,oBAAOzB,MAAA,CAAAc,OAAA,CAAA+B,aAAA;IAAKpB,KAAK,EAAEG;EAAU,GAAEJ,QAAc,CAAC;AAChD,CAAqC;AAE9B,MAAMsB,QAAmB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACjCE,EAAE,EAAE,KAAK;EACTC,UAAU,EAAE,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,CAACC,gBAAgB,GAAG,CAAC;EAAE;EACzEC,YAAY,EAAGC,MAAkB,IAAK;IACpC,MAAMC,KAAK,GAAG,IAAAC,mBAAY,EAACF,MAAM,CAAC;IAClC,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAOA,KAAK;IACd;IACA,IAAI,IAAAE,iBAAU,EAACF,KAAK,CAAC,EAAE;MACrB,IAAI,OAAOpD,OAAO,KAAK,UAAU,EAAE;QACjC,MAAM;UACJuD;QACF,CAAC,GAAGvD,OAAO,CAAC,4CAA4C,CAAC;QACzD,MAAM;UAAEwD,kBAAkB;UAAEC,IAAI;UAAEC;QAAK,CAAC,GAAGH,YAAY,CAACH,KAAK,CAAC;QAC9D,MAAMO,GAAG,GAAG,GAAGH,kBAAkB,IAAIC,IAAI,IAAIC,IAAI,EAAE;QACnD,OAAOC,GAAG;MACZ;MACA,MAAM,IAAIC,KAAK,CACb,6DACF,CAAC;IACH;IACA,OAAOR,KAAK,CAACO,GAAG;EAClB,CAAC;EACDE,cAAc,EAAEA,CAAA,KAAM;IACpB,MAAM,IAAID,KAAK,CAAC,4CAA4C,CAAC;EAC/D,CAAC;EACDvC;AACF,CAAC","ignoreList":[]}
|
|
@@ -8,7 +8,16 @@ var _react = require("react");
|
|
|
8
8
|
var _skia = require("../../skia");
|
|
9
9
|
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
|
|
11
|
+
// Created lazily: accessing the proxy at module scope would require
|
|
12
|
+
// react-native-reanimated as soon as the package is imported, and would spawn
|
|
13
|
+
// the runtime even for apps that never load a video.
|
|
14
|
+
let runtime;
|
|
15
|
+
const getRuntime = () => {
|
|
16
|
+
if (runtime === undefined) {
|
|
17
|
+
runtime = _ReanimatedProxy.default.createWorkletRuntime("video-metadata-runtime");
|
|
18
|
+
}
|
|
19
|
+
return runtime;
|
|
20
|
+
};
|
|
12
21
|
const useVideoLoading = source => {
|
|
13
22
|
const {
|
|
14
23
|
runOnJS
|
|
@@ -22,7 +31,7 @@ const useVideoLoading = source => {
|
|
|
22
31
|
}, [runOnJS]);
|
|
23
32
|
(0, _react.useEffect)(() => {
|
|
24
33
|
if (source) {
|
|
25
|
-
_ReanimatedProxy.default.runOnRuntime(
|
|
34
|
+
_ReanimatedProxy.default.runOnRuntime(getRuntime(), cb)(source);
|
|
26
35
|
}
|
|
27
36
|
}, [cb, source]);
|
|
28
37
|
return video;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_skia","_ReanimatedProxy","_interopRequireDefault","e","__esModule","default","runtime","Rea","createWorkletRuntime","useVideoLoading","source","runOnJS","video","setVideo","useState","cb","useCallback","src","vid","Skia","Video","useEffect","runOnRuntime","exports"],"sources":["useVideoLoading.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\n\nimport type { Video } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst runtime = Rea.createWorkletRuntime(\"video-metadata-runtime\");\n\ntype VideoSource = string | null;\n\nexport const useVideoLoading = (source: VideoSource) => {\n const { runOnJS } = Rea;\n const [video, setVideo] = useState<Video | null>(null);\n const cb = useCallback(\n (src: string) => {\n \"worklet\";\n const vid = Skia.Video(src) as Video;\n runOnJS(setVideo)(vid);\n },\n [runOnJS]\n );\n useEffect(() => {\n if (source) {\n Rea.runOnRuntime(
|
|
1
|
+
{"version":3,"names":["_react","require","_skia","_ReanimatedProxy","_interopRequireDefault","e","__esModule","default","runtime","getRuntime","undefined","Rea","createWorkletRuntime","useVideoLoading","source","runOnJS","video","setVideo","useState","cb","useCallback","src","vid","Skia","Video","useEffect","runOnRuntime","exports"],"sources":["useVideoLoading.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport type { WorkletRuntime } from \"react-native-reanimated\";\n\nimport type { Video } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\nimport Rea from \"./ReanimatedProxy\";\n\n// Created lazily: accessing the proxy at module scope would require\n// react-native-reanimated as soon as the package is imported, and would spawn\n// the runtime even for apps that never load a video.\nlet runtime: WorkletRuntime | undefined;\nconst getRuntime = () => {\n if (runtime === undefined) {\n runtime = Rea.createWorkletRuntime(\"video-metadata-runtime\");\n }\n return runtime;\n};\n\ntype VideoSource = string | null;\n\nexport const useVideoLoading = (source: VideoSource) => {\n const { runOnJS } = Rea;\n const [video, setVideo] = useState<Video | null>(null);\n const cb = useCallback(\n (src: string) => {\n \"worklet\";\n const vid = Skia.Video(src) as Video;\n runOnJS(setVideo)(vid);\n },\n [runOnJS]\n );\n useEffect(() => {\n if (source) {\n Rea.runOnRuntime(getRuntime(), cb)(source);\n }\n }, [cb, source]);\n return video;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoC,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEpC;AACA;AACA;AACA,IAAIG,OAAmC;AACvC,MAAMC,UAAU,GAAGA,CAAA,KAAM;EACvB,IAAID,OAAO,KAAKE,SAAS,EAAE;IACzBF,OAAO,GAAGG,wBAAG,CAACC,oBAAoB,CAAC,wBAAwB,CAAC;EAC9D;EACA,OAAOJ,OAAO;AAChB,CAAC;AAIM,MAAMK,eAAe,GAAIC,MAAmB,IAAK;EACtD,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,wBAAG;EACvB,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAe,IAAI,CAAC;EACtD,MAAMC,EAAE,GAAG,IAAAC,kBAAW,EACnBC,GAAW,IAAK;IACf,SAAS;;IACT,MAAMC,GAAG,GAAGC,UAAI,CAACC,KAAK,CAACH,GAAG,CAAU;IACpCN,OAAO,CAACE,QAAQ,CAAC,CAACK,GAAG,CAAC;EACxB,CAAC,EACD,CAACP,OAAO,CACV,CAAC;EACD,IAAAU,gBAAS,EAAC,MAAM;IACd,IAAIX,MAAM,EAAE;MACVH,wBAAG,CAACe,YAAY,CAACjB,UAAU,CAAC,CAAC,EAAEU,EAAE,CAAC,CAACL,MAAM,CAAC;IAC5C;EACF,CAAC,EAAE,CAACK,EAAE,EAAEL,MAAM,CAAC,CAAC;EAChB,OAAOE,KAAK;AACd,CAAC;AAACW,OAAA,CAAAd,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
|
+
import { FontSlant, FontWeight } from "../types";
|
|
1
2
|
import type { DataModule, DataSourceParam, SkFontMgr } from "../types";
|
|
2
3
|
import type { SkTypefaceFontProvider } from "../types/Paragraph/TypefaceFontProvider";
|
|
3
4
|
/**
|
|
4
5
|
* Returns a Skia Font object
|
|
5
6
|
* */
|
|
6
7
|
export declare const useFont: (font: DataSourceParam, size?: number, onError?: (err: Error) => void) => import("../types").SkFont | null;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React Native style font slant, as found in the `fontStyle` property of
|
|
10
|
+
* `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.
|
|
11
|
+
*/
|
|
12
|
+
export type RNFontSlant = "normal" | "italic" | "oblique" | FontSlant;
|
|
13
|
+
/**
|
|
14
|
+
* React Native style font weight, as found in the `fontWeight` property of
|
|
15
|
+
* `TextStyle`. Numeric weights such as the {@link FontWeight} enum values
|
|
16
|
+
* used by the Paragraph API are accepted as well.
|
|
17
|
+
*/
|
|
18
|
+
export type RNFontWeight = "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | FontWeight;
|
|
19
|
+
/**
|
|
20
|
+
* Font style accepted by {@link matchFont}.
|
|
21
|
+
* `fontStyle` and `fontWeight` accept both the React Native string values
|
|
22
|
+
* and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same
|
|
23
|
+
* values can be shared with the Paragraph API.
|
|
24
|
+
*/
|
|
25
|
+
export interface RNFontStyle {
|
|
10
26
|
fontFamily: string;
|
|
11
27
|
fontSize: number;
|
|
12
|
-
fontStyle:
|
|
13
|
-
fontWeight:
|
|
28
|
+
fontStyle: RNFontSlant;
|
|
29
|
+
fontWeight: RNFontWeight;
|
|
14
30
|
}
|
|
15
31
|
export declare const matchFont: (inputStyle?: Partial<RNFontStyle>, fontMgr?: SkFontMgr) => import("../types").SkFont;
|
|
16
32
|
export declare const listFontFamilies: (fontMgr?: SkFontMgr) => string[];
|
|
17
33
|
export declare const useFonts: (sources: Record<string, DataModule[]>) => SkTypefaceFontProvider | null;
|
|
18
|
-
export {};
|
|
@@ -26,6 +26,24 @@ const useFont = (font, size = defaultFontSize, onError) => {
|
|
|
26
26
|
}
|
|
27
27
|
}, [size, typeface]);
|
|
28
28
|
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* React Native style font slant, as found in the `fontStyle` property of
|
|
32
|
+
* `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* React Native style font weight, as found in the `fontWeight` property of
|
|
37
|
+
* `TextStyle`. Numeric weights such as the {@link FontWeight} enum values
|
|
38
|
+
* used by the Paragraph API are accepted as well.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Font style accepted by {@link matchFont}.
|
|
43
|
+
* `fontStyle` and `fontWeight` accept both the React Native string values
|
|
44
|
+
* and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same
|
|
45
|
+
* values can be shared with the Paragraph API.
|
|
46
|
+
*/
|
|
29
47
|
exports.useFont = useFont;
|
|
30
48
|
const defaultFontStyle = {
|
|
31
49
|
fontFamily: "System",
|
|
@@ -34,7 +52,9 @@ const defaultFontStyle = {
|
|
|
34
52
|
fontWeight: "normal"
|
|
35
53
|
};
|
|
36
54
|
const slant = s => {
|
|
37
|
-
if (s === "
|
|
55
|
+
if (typeof s === "number") {
|
|
56
|
+
return s;
|
|
57
|
+
} else if (s === "italic") {
|
|
38
58
|
return _types.FontSlant.Italic;
|
|
39
59
|
} else if (s === "oblique") {
|
|
40
60
|
return _types.FontSlant.Oblique;
|
|
@@ -45,11 +65,11 @@ const slant = s => {
|
|
|
45
65
|
const weight = fontWeight => {
|
|
46
66
|
switch (fontWeight) {
|
|
47
67
|
case "normal":
|
|
48
|
-
return
|
|
68
|
+
return _types.FontWeight.Normal;
|
|
49
69
|
case "bold":
|
|
50
|
-
return
|
|
70
|
+
return _types.FontWeight.Bold;
|
|
51
71
|
default:
|
|
52
|
-
return parseInt(fontWeight, 10);
|
|
72
|
+
return typeof fontWeight === "number" ? fontWeight : parseInt(fontWeight, 10);
|
|
53
73
|
}
|
|
54
74
|
};
|
|
55
75
|
const matchFont = (inputStyle = {}, fontMgr = _Skia.Skia.FontMgr.System()) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_Skia","_types","_Platform","_Typeface","defaultFontSize","useFont","font","size","onError","typeface","useTypeface","useMemo","Skia","Font","exports","defaultFontStyle","fontFamily","fontSize","fontStyle","fontWeight","slant","s","FontSlant","Italic","Oblique","Upright","weight","parseInt","matchFont","inputStyle","fontMgr","FontMgr","System","style","width","matchFamilyStyle","listFontFamilies","families","Set","i","countFamilies","add","getFamilyName","Array","from","loadTypefaces","typefacesToLoad","promises","Object","keys","flatMap","familyName","map","typefaceToLoad","Data","fromURI","Platform","resolveAsset","then","data","tf","Typeface","MakeFreeTypeFaceFromData","Error","Promise","all","useFonts","sources","setFontMgr","useState","useEffect","result","fMgr","TypefaceFontProvider","Make","forEach","registerFont"],"sources":["Font.ts"],"sourcesContent":["/*global SkiaApi*/\nimport { useEffect, useMemo, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport { FontSlant } from \"../types\";\nimport type { DataModule, DataSourceParam, SkFontMgr } from \"../types\";\nimport { Platform } from \"../../Platform\";\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\n\nimport { useTypeface } from \"./Typeface\";\n\nconst defaultFontSize = 14;\n\n/**\n * Returns a Skia Font object\n * */\nexport const useFont = (\n font: DataSourceParam,\n size = defaultFontSize,\n onError?: (err: Error) => void\n) => {\n const typeface = useTypeface(font, onError);\n return useMemo(() => {\n if (typeface) {\n return Skia.Font(typeface, size);\n } else {\n return null;\n }\n }, [size, typeface]);\n};\n\
|
|
1
|
+
{"version":3,"names":["_react","require","_Skia","_types","_Platform","_Typeface","defaultFontSize","useFont","font","size","onError","typeface","useTypeface","useMemo","Skia","Font","exports","defaultFontStyle","fontFamily","fontSize","fontStyle","fontWeight","slant","s","FontSlant","Italic","Oblique","Upright","weight","FontWeight","Normal","Bold","parseInt","matchFont","inputStyle","fontMgr","FontMgr","System","style","width","matchFamilyStyle","listFontFamilies","families","Set","i","countFamilies","add","getFamilyName","Array","from","loadTypefaces","typefacesToLoad","promises","Object","keys","flatMap","familyName","map","typefaceToLoad","Data","fromURI","Platform","resolveAsset","then","data","tf","Typeface","MakeFreeTypeFaceFromData","Error","Promise","all","useFonts","sources","setFontMgr","useState","useEffect","result","fMgr","TypefaceFontProvider","Make","forEach","registerFont"],"sources":["Font.ts"],"sourcesContent":["/*global SkiaApi*/\nimport { useEffect, useMemo, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport { FontSlant, FontWeight } from \"../types\";\nimport type { DataModule, DataSourceParam, SkFontMgr } from \"../types\";\nimport { Platform } from \"../../Platform\";\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\n\nimport { useTypeface } from \"./Typeface\";\n\nconst defaultFontSize = 14;\n\n/**\n * Returns a Skia Font object\n * */\nexport const useFont = (\n font: DataSourceParam,\n size = defaultFontSize,\n onError?: (err: Error) => void\n) => {\n const typeface = useTypeface(font, onError);\n return useMemo(() => {\n if (typeface) {\n return Skia.Font(typeface, size);\n } else {\n return null;\n }\n }, [size, typeface]);\n};\n\n/**\n * React Native style font slant, as found in the `fontStyle` property of\n * `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.\n */\nexport type RNFontSlant = \"normal\" | \"italic\" | \"oblique\" | FontSlant;\n\n/**\n * React Native style font weight, as found in the `fontWeight` property of\n * `TextStyle`. Numeric weights such as the {@link FontWeight} enum values\n * used by the Paragraph API are accepted as well.\n */\nexport type RNFontWeight =\n | \"normal\"\n | \"bold\"\n | \"100\"\n | \"200\"\n | \"300\"\n | \"400\"\n | \"500\"\n | \"600\"\n | \"700\"\n | \"800\"\n | \"900\"\n | FontWeight;\n\n/**\n * Font style accepted by {@link matchFont}.\n * `fontStyle` and `fontWeight` accept both the React Native string values\n * and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same\n * values can be shared with the Paragraph API.\n */\nexport interface RNFontStyle {\n fontFamily: string;\n fontSize: number;\n fontStyle: RNFontSlant;\n fontWeight: RNFontWeight;\n}\n\nconst defaultFontStyle: RNFontStyle = {\n fontFamily: \"System\",\n fontSize: defaultFontSize,\n fontStyle: \"normal\",\n fontWeight: \"normal\",\n};\n\nconst slant = (s: RNFontSlant): FontSlant => {\n if (typeof s === \"number\") {\n return s;\n } else if (s === \"italic\") {\n return FontSlant.Italic;\n } else if (s === \"oblique\") {\n return FontSlant.Oblique;\n } else {\n return FontSlant.Upright;\n }\n};\n\nconst weight = (fontWeight: RNFontWeight): FontWeight => {\n switch (fontWeight) {\n case \"normal\":\n return FontWeight.Normal;\n case \"bold\":\n return FontWeight.Bold;\n default:\n return typeof fontWeight === \"number\"\n ? fontWeight\n : (parseInt(fontWeight, 10) as FontWeight);\n }\n};\n\nexport const matchFont = (\n inputStyle: Partial<RNFontStyle> = {},\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const fontStyle = {\n ...defaultFontStyle,\n ...inputStyle,\n };\n const style = {\n weight: weight(fontStyle.fontWeight),\n width: 5,\n slant: slant(fontStyle.fontStyle),\n };\n const typeface = fontMgr.matchFamilyStyle(fontStyle.fontFamily, style);\n return Skia.Font(typeface, fontStyle.fontSize);\n};\n\nexport const listFontFamilies = (\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const families = new Set<string>();\n for (let i = 0; i < fontMgr.countFamilies(); i++) {\n families.add(fontMgr.getFamilyName(i));\n }\n return Array.from(families);\n};\n\nconst loadTypefaces = (typefacesToLoad: Record<string, DataModule[]>) => {\n const promises = Object.keys(typefacesToLoad).flatMap((familyName) => {\n return typefacesToLoad[familyName].map((typefaceToLoad) => {\n return Skia.Data.fromURI(Platform.resolveAsset(typefaceToLoad)).then(\n (data) => {\n const tf = Skia.Typeface.MakeFreeTypeFaceFromData(data);\n if (tf === null) {\n throw new Error(`Couldn't create typeface for ${familyName}`);\n }\n return [familyName, tf] as const;\n }\n );\n });\n });\n return Promise.all(promises);\n};\n\nexport const useFonts = (sources: Record<string, DataModule[]>) => {\n const [fontMgr, setFontMgr] = useState<null | SkTypefaceFontProvider>(null);\n\n useEffect(() => {\n loadTypefaces(sources).then((result) => {\n const fMgr = Skia.TypefaceFontProvider.Make();\n result.forEach(([familyName, typeface]) => {\n fMgr.registerFont(typeface, familyName);\n });\n setFontMgr(fMgr);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return fontMgr;\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,CAACI,IAAI,CAAC;IAClB,CAAC,CAAC;IACF;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO1C,OAAO;AAChB,CAAC;AAACnB,OAAA,CAAAuD,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useSVG = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _Skia = require("../Skia");
|
|
9
|
+
var _Platform = require("../../Platform");
|
|
9
10
|
const useSVG = (source, onError) => {
|
|
10
11
|
const [svg, setSVG] = (0, _react.useState)(null);
|
|
11
12
|
if (source === null || source === undefined) {
|
|
@@ -16,12 +17,10 @@ const useSVG = (source, onError) => {
|
|
|
16
17
|
let src;
|
|
17
18
|
if (typeof source === "string") {
|
|
18
19
|
src = source;
|
|
19
|
-
} else if (
|
|
20
|
-
|
|
21
|
-
} else if (typeof source === "object" && "uri" in source) {
|
|
22
|
-
src = source.uri;
|
|
20
|
+
} else if (source instanceof Uint8Array) {
|
|
21
|
+
throw new Error(`Invalid svg data source. Make sure that the source resolves to a string. Got: ${source}`);
|
|
23
22
|
} else {
|
|
24
|
-
|
|
23
|
+
src = _Platform.Platform.resolveAsset(source);
|
|
25
24
|
}
|
|
26
25
|
const result = await fetch(src);
|
|
27
26
|
const svgStr = await result.text();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_Skia","useSVG","source","onError","svg","setSVG","useState","undefined","Error","useEffect","src","
|
|
1
|
+
{"version":3,"names":["_react","require","_Skia","_Platform","useSVG","source","onError","svg","setSVG","useState","undefined","Error","useEffect","src","Uint8Array","Platform","resolveAsset","result","fetch","svgStr","text","newSvg","Skia","SVG","MakeFromString","exports"],"sources":["SVG.web.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { DataSourceParam, SkSVG } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nexport const useSVG = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => {\n const [svg, setSVG] = useState<SkSVG | null>(null);\n if (source === null || source === undefined) {\n throw new Error(`Invalid svg data source. Got: ${source}`);\n }\n useEffect(() => {\n (async () => {\n let src: string;\n if (typeof source === \"string\") {\n src = source;\n } else if (source instanceof Uint8Array) {\n throw new Error(\n `Invalid svg data source. Make sure that the source resolves to a string. Got: ${source}`\n );\n } else {\n src = Platform.resolveAsset(source);\n }\n const result = await fetch(src);\n const svgStr = await result.text();\n const newSvg = Skia.SVG.MakeFromString(svgStr);\n setSVG(newSvg);\n if (newSvg === null && onError !== undefined) {\n onError(new Error(\"Failed to create SVG from source.\"));\n }\n })();\n }, [onError, source]);\n return svg;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAEO,MAAMG,MAAM,GAAGA,CACpBC,MAAuB,EACvBC,OAA8B,KAC3B;EACH,MAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAG,IAAAC,eAAQ,EAAe,IAAI,CAAC;EAClD,IAAIJ,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKK,SAAS,EAAE;IAC3C,MAAM,IAAIC,KAAK,CAAC,iCAAiCN,MAAM,EAAE,CAAC;EAC5D;EACA,IAAAO,gBAAS,EAAC,MAAM;IACd,CAAC,YAAY;MACX,IAAIC,GAAW;MACf,IAAI,OAAOR,MAAM,KAAK,QAAQ,EAAE;QAC9BQ,GAAG,GAAGR,MAAM;MACd,CAAC,MAAM,IAAIA,MAAM,YAAYS,UAAU,EAAE;QACvC,MAAM,IAAIH,KAAK,CACb,iFAAiFN,MAAM,EACzF,CAAC;MACH,CAAC,MAAM;QACLQ,GAAG,GAAGE,kBAAQ,CAACC,YAAY,CAACX,MAAM,CAAC;MACrC;MACA,MAAMY,MAAM,GAAG,MAAMC,KAAK,CAACL,GAAG,CAAC;MAC/B,M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