@shopify/react-native-skia 0.1.136 → 0.1.139
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -47
- package/android/build.gradle +1 -2
- package/cpp/api/JsiSkApi.h +0 -4
- package/cpp/api/JsiSkFont.h +0 -19
- package/cpp/api/JsiSkMatrix.h +12 -0
- package/cpp/api/JsiSkTypeface.h +1 -29
- package/lib/commonjs/mock/index.js +0 -4
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +5 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +1 -1
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
- package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Text.js +4 -6
- package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
- package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
- package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -27
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/renderer/processors/Transform.js +8 -15
- package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
- package/lib/commonjs/skia/core/Data.js +3 -1
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Image.js +4 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.js +3 -1
- package/lib/commonjs/skia/core/SVG.js.map +1 -1
- package/lib/commonjs/skia/core/Typeface.js +4 -1
- package/lib/commonjs/skia/core/Typeface.js.map +1 -1
- package/lib/commonjs/skia/core/index.js +0 -26
- package/lib/commonjs/skia/core/index.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.js +18 -3
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/index.js +0 -13
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +67 -57
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js +29 -0
- package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/WithSkiaWeb.js +39 -0
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/index.js +22 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -4
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +5 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Group.js +1 -1
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/text/Glyphs.js +4 -5
- package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/module/renderer/components/text/Text.js +4 -5
- package/lib/module/renderer/components/text/Text.js.map +1 -1
- package/lib/module/renderer/components/text/TextPath.js +3 -3
- package/lib/module/renderer/components/text/TextPath.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +0 -23
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/renderer/processors/Transform.js +8 -15
- package/lib/module/renderer/processors/Transform.js.map +1 -1
- package/lib/module/skia/core/Data.js +3 -1
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Image.js +2 -1
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/core/SVG.js +2 -1
- package/lib/module/skia/core/SVG.js.map +1 -1
- package/lib/module/skia/core/Typeface.js +2 -1
- package/lib/module/skia/core/Typeface.js.map +1 -1
- package/lib/module/skia/core/index.js +0 -2
- package/lib/module/skia/core/index.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/types/Matrix.js +12 -2
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +0 -6
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.js +4 -0
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -2
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +0 -4
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +67 -58
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +16 -0
- package/lib/module/web/LoadSkiaWeb.js.map +1 -0
- package/lib/module/web/WithSkiaWeb.js +23 -0
- package/lib/module/web/WithSkiaWeb.js.map +1 -0
- package/lib/module/web/index.js +2 -9
- package/lib/module/web/index.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
- package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
- package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
- package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
- package/lib/typescript/src/skia/core/index.d.ts +0 -2
- package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
- package/lib/typescript/src/skia/types/Matrix.d.ts +6 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
- package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +1 -4
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
- package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +9 -11
- package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
- package/lib/typescript/src/web/WithSkiaWeb.d.ts +12 -0
- package/lib/typescript/src/web/index.d.ts +2 -5
- package/package.json +5 -1
- package/scripts/setup-canvaskit.js +74 -0
- package/src/mock/index.ts +0 -4
- package/src/renderer/Canvas.tsx +5 -8
- package/src/renderer/DrawingContext.ts +1 -2
- package/src/renderer/components/Group.tsx +1 -1
- package/src/renderer/components/text/Glyphs.tsx +2 -6
- package/src/renderer/components/text/Text.tsx +2 -3
- package/src/renderer/components/text/TextPath.tsx +2 -3
- package/src/renderer/processors/Font.ts +2 -25
- package/src/renderer/processors/Transform.ts +7 -10
- package/src/skia/core/Data.ts +3 -1
- package/src/skia/core/Image.ts +3 -1
- package/src/skia/core/SVG.ts +3 -1
- package/src/skia/core/Typeface.ts +4 -6
- package/src/skia/core/index.ts +0 -2
- package/src/skia/types/Font/Font.ts +0 -13
- package/src/skia/types/Matrix.ts +19 -3
- package/src/skia/types/Skia.ts +0 -2
- package/src/skia/types/Typeface/Typeface.ts +1 -4
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkFont.ts +0 -9
- package/src/skia/web/JsiSkMatrix.ts +4 -0
- package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
- package/src/skia/web/JsiSkia.ts +0 -2
- package/src/values/hooks/useComputedValue.ts +0 -5
- package/src/views/SkiaView.web.tsx +55 -70
- package/src/web/LoadSkiaWeb.tsx +24 -0
- package/src/web/WithSkiaWeb.tsx +37 -0
- package/src/web/index.ts +2 -15
- package/cpp/api/JsiSkFontMgr.h +0 -84
- package/cpp/api/JsiSkFontMgrFactory.h +0 -48
- package/lib/commonjs/skia/core/Paint.js +0 -28
- package/lib/commonjs/skia/core/Paint.js.map +0 -1
- package/lib/commonjs/skia/core/Path.js +0 -72
- package/lib/commonjs/skia/core/Path.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
- package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/module/skia/core/Paint.js +0 -17
- package/lib/module/skia/core/Paint.js.map +0 -1
- package/lib/module/skia/core/Path.js +0 -53
- package/lib/module/skia/core/Path.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/module/skia/types/FontMgr/index.js +0 -3
- package/lib/module/skia/types/FontMgr/index.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
- package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
- package/lib/typescript/src/skia/core/Path.d.ts +0 -21
- package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
- package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
- package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
- package/src/skia/core/Paint.ts +0 -22
- package/src/skia/core/Path.ts +0 -60
- package/src/skia/types/FontMgr/FontMgr.ts +0 -24
- package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
- package/src/skia/types/FontMgr/index.ts +0 -2
- package/src/skia/web/JsiSkFontMgr.ts +0 -38
- package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
package/README.md
CHANGED
@@ -1,52 +1,9 @@
|
|
1
1
|
# React Native Skia
|
2
2
|
|
3
|
-
|
4
|
-
Skia serves as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Mozilla Firefox, Firefox OS, and many other products.
|
3
|
+
High-performance 2d Graphics for React Native using Skia
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
```sh
|
9
|
-
yarn add @shopify/react-native-skia
|
10
|
-
```
|
11
|
-
|
12
|
-
Or using npm:
|
13
|
-
|
14
|
-
```sh
|
15
|
-
npm install @shopify/react-native-skia
|
16
|
-
```
|
17
|
-
|
18
|
-
## iOS
|
19
|
-
|
20
|
-
Run `pod install` on the `ios/` directory.
|
21
|
-
|
22
|
-
## Android
|
23
|
-
|
24
|
-
> **Version compatibility**: `react-native@>=0.66` is required.
|
25
|
-
|
26
|
-
Currently, you will need Android NDK to be installed.
|
27
|
-
If you have Android Studio installed, make sure `$ANDROID_NDK` is available.
|
28
|
-
`ANDROID_NDK=/Users/username/Library/Android/sdk/ndk-bundle` for instance.
|
5
|
+
<img width="400" alt="skia" src="https://user-images.githubusercontent.com/306134/146549218-b7959ad9-0107-4c1c-b439-b96c780f5230.png">
|
29
6
|
|
30
|
-
|
31
|
-
|
32
|
-
And then the _SDK Location_ section. It will show you the NDK path, or the option to download it if you don't have it installed.
|
33
|
-
|
34
|
-
### Proguard
|
35
|
-
|
36
|
-
If you're using Proguard, make sure to add the following rule:
|
37
|
-
|
38
|
-
```
|
39
|
-
-keep class com.shopify.reactnative.skia.** { *; }
|
40
|
-
```
|
41
|
-
|
42
|
-
## Playground
|
43
|
-
|
44
|
-
We have an example project you can play with [here](https://github.com/Shopify/react-native-skia/tree/main/example).
|
45
|
-
|
46
|
-
```sh
|
47
|
-
yarn
|
48
|
-
cd package && yarn && cd ..
|
49
|
-
cd example && yarn && yarn start
|
50
|
-
```
|
7
|
+
Checkout the full documentation [here](https://shopify.github.io/react-native-skia).
|
51
8
|
|
52
|
-
|
9
|
+
Documentation on the library development is available [here](https://github.com/Shopify/react-native-skia#library-development).
|
package/android/build.gradle
CHANGED
package/cpp/api/JsiSkApi.h
CHANGED
@@ -33,7 +33,6 @@
|
|
33
33
|
#include "JsiSkVertices.h"
|
34
34
|
#include "JsiSkTypefaceFactory.h"
|
35
35
|
#include "JsiSkDataFactory.h"
|
36
|
-
#include "JsiSkFontMgrFactory.h"
|
37
36
|
#include "JsiSkSurfaceFactory.h"
|
38
37
|
#include "JsiSkTextBlobFactory.h"
|
39
38
|
#include "JsiSkContourMeasureIter.h"
|
@@ -72,9 +71,6 @@ namespace RNSkia
|
|
72
71
|
installFunction("PictureRecorder", JsiSkPictureRecorder::createCtor(context));
|
73
72
|
installFunction("Color", JsiSkColor::createCtor());
|
74
73
|
|
75
|
-
// Static members
|
76
|
-
installReadonlyProperty("FontMgr",
|
77
|
-
std::make_shared<JsiSkFontMgrFactory>(context));
|
78
74
|
installReadonlyProperty("SVG",
|
79
75
|
std::make_shared<JsiSkSVGFactory>(context));
|
80
76
|
installReadonlyProperty("Image",
|
package/cpp/api/JsiSkFont.h
CHANGED
@@ -38,24 +38,6 @@ namespace RNSkia
|
|
38
38
|
return jsi::String::createFromUtf8(runtime, "Font");
|
39
39
|
}
|
40
40
|
|
41
|
-
JSI_HOST_FUNCTION(measureText)
|
42
|
-
{
|
43
|
-
RNSkLogger::warnToJavascriptConsole(runtime, "measureText() is deprecated. Clients should use 'Font.getGlyphWidths' instead (the latter does no shaping)");
|
44
|
-
auto textVal = arguments[0].asString(runtime).utf8(runtime);
|
45
|
-
auto text = textVal.c_str();
|
46
|
-
SkRect rect;
|
47
|
-
std::shared_ptr<SkPaint> paint = nullptr;
|
48
|
-
// Check if a paint argument was provided
|
49
|
-
if (count == 2)
|
50
|
-
{
|
51
|
-
paint = JsiSkPaint::fromValue(runtime, arguments[1]);
|
52
|
-
}
|
53
|
-
getObject()->measureText(text, strlen(text), SkTextEncoding::kUTF8, &rect,
|
54
|
-
paint.get());
|
55
|
-
rect.setXYWH(0, 0, rect.width(), rect.height());
|
56
|
-
return JsiSkRect::toValue(runtime, getContext(), std::move(rect));
|
57
|
-
}
|
58
|
-
|
59
41
|
JSI_HOST_FUNCTION(getGlyphWidths)
|
60
42
|
{
|
61
43
|
auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
|
@@ -279,7 +261,6 @@ namespace RNSkia
|
|
279
261
|
|
280
262
|
JSI_EXPORT_FUNCTIONS(
|
281
263
|
JSI_EXPORT_FUNC(JsiSkFont, getSize),
|
282
|
-
JSI_EXPORT_FUNC(JsiSkFont, measureText),
|
283
264
|
JSI_EXPORT_FUNC(JsiSkFont, getMetrics),
|
284
265
|
JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs),
|
285
266
|
JSI_EXPORT_FUNC(JsiSkFont, getGlyphIntercepts),
|
package/cpp/api/JsiSkMatrix.h
CHANGED
@@ -46,6 +46,10 @@ public:
|
|
46
46
|
);
|
47
47
|
}
|
48
48
|
|
49
|
+
JSI_PROPERTY_GET(__typename__) {
|
50
|
+
return jsi::String::createFromUtf8(runtime, "Matrix");
|
51
|
+
}
|
52
|
+
|
49
53
|
JSI_HOST_FUNCTION(concat) {
|
50
54
|
auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]);
|
51
55
|
getObject()->preConcat(*m3);
|
@@ -78,6 +82,13 @@ public:
|
|
78
82
|
getObject()->preRotate(SkRadiansToDegrees(a));
|
79
83
|
return jsi::Value::undefined();
|
80
84
|
}
|
85
|
+
|
86
|
+
JSI_HOST_FUNCTION(identity) {
|
87
|
+
getObject()->setIdentity();
|
88
|
+
return jsi::Value::undefined();
|
89
|
+
}
|
90
|
+
|
91
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMatrix, __typename__))
|
81
92
|
|
82
93
|
JSI_EXPORT_FUNCTIONS(
|
83
94
|
JSI_EXPORT_FUNC(JsiSkMatrix, concat),
|
@@ -85,6 +96,7 @@ public:
|
|
85
96
|
JSI_EXPORT_FUNC(JsiSkMatrix, scale),
|
86
97
|
JSI_EXPORT_FUNC(JsiSkMatrix, skew),
|
87
98
|
JSI_EXPORT_FUNC(JsiSkMatrix, rotate),
|
99
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, identity),
|
88
100
|
)
|
89
101
|
|
90
102
|
/**
|
package/cpp/api/JsiSkTypeface.h
CHANGED
@@ -22,24 +22,12 @@ using namespace facebook;
|
|
22
22
|
|
23
23
|
class JsiSkTypeface : public JsiSkWrappingSkPtrHostObject<SkTypeface> {
|
24
24
|
public:
|
25
|
-
JSI_PROPERTY_GET(bold) {
|
26
|
-
RNSkLogger::warnToJavascriptConsole(runtime, "Typeface.bold is deprecated and will be removed in a future release.");
|
27
|
-
return jsi::Value(getObject()->isBold());
|
28
|
-
}
|
29
|
-
|
30
|
-
JSI_PROPERTY_GET(italic) {
|
31
|
-
RNSkLogger::warnToJavascriptConsole(runtime, "Typeface.italic is deprecated and will be removed in a future release.");
|
32
|
-
return jsi::Value(getObject()->isItalic());
|
33
|
-
}
|
34
|
-
|
35
25
|
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
36
26
|
JSI_PROPERTY_GET(__typename__) {
|
37
27
|
return jsi::String::createFromUtf8(runtime, "Typeface");
|
38
28
|
}
|
39
29
|
|
40
|
-
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface,
|
41
|
-
JSI_EXPORT_PROP_GET(JsiSkTypeface, italic),
|
42
|
-
JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__))
|
30
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__))
|
43
31
|
|
44
32
|
JsiSkTypeface(std::shared_ptr<RNSkPlatformContext> context,
|
45
33
|
sk_sp<SkTypeface> typeface)
|
@@ -64,22 +52,6 @@ public:
|
|
64
52
|
return jsi::Object::createFromHostObject(
|
65
53
|
runtime, std::make_shared<JsiSkTypeface>(std::move(context), std::move(tf)));
|
66
54
|
}
|
67
|
-
|
68
|
-
private:
|
69
|
-
static SkFontStyle getFontStyleFromNumber(int fontStyle) {
|
70
|
-
switch (fontStyle) {
|
71
|
-
case 0:
|
72
|
-
return SkFontStyle::Normal();
|
73
|
-
case 1:
|
74
|
-
return SkFontStyle::Bold();
|
75
|
-
case 2:
|
76
|
-
return SkFontStyle::Italic();
|
77
|
-
case 3:
|
78
|
-
return SkFontStyle::BoldItalic();
|
79
|
-
default:
|
80
|
-
return SkFontStyle::Normal();
|
81
|
-
};
|
82
|
-
}
|
83
55
|
};
|
84
56
|
|
85
57
|
} // namespace RNSkia
|
@@ -70,12 +70,8 @@ const Mock = {
|
|
70
70
|
useFont: Noop,
|
71
71
|
useTypeface: Noop,
|
72
72
|
useImage: Noop,
|
73
|
-
usePath: Noop,
|
74
73
|
useSVG: Noop,
|
75
|
-
useTextPath: Noop,
|
76
|
-
usePaint: Noop,
|
77
74
|
usePicture: Noop,
|
78
|
-
useSvgPath: Noop,
|
79
75
|
// 3. Point/Rect/Transform utilities
|
80
76
|
vec,
|
81
77
|
rect: (x, y, width, height) => ({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useDataCollection","useRawData","useData","useFont","useTypeface","useImage","
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useDataCollection","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","useSharedValueEffect","Values","ValuesHooks","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","ShaderLib","createDrawing","createDeclaration"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAjBA;AAmBA,MAAMA,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEO,MAAMC,IAAa,GAAG,IAAIP,IAAJ,EAAtB;;;AAEA,MAAMQ,GAAG,GAAG,CAACC,CAAD,EAAaC,CAAb;AAAA;;AAAA,SAA6B;AAAED,IAAAA,CAAC,EAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAO,CAAV;AAAaC,IAAAA,CAAC,UAAEA,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A1DD;AA2DJC,EAAAA,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;AA4DJK,EAAAA,SAAS,EAATA,oBA5DI;AA6DJC,EAAAA,aAAa,EAAE7D,IA7DX;AA8DJ8D,EAAAA,iBAAiB,EAAE9D;AA9Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useDataCollection: Noop,\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
|
@@ -48,17 +48,13 @@ const render = (element, root, container) => {
|
|
48
48
|
const useCanvasRef = () => (0, _react.useRef)(null);
|
49
49
|
|
50
50
|
exports.useCanvasRef = useCanvasRef;
|
51
|
-
|
52
|
-
const defaultFontMgr = _Skia.Skia.FontMgr.RefDefault();
|
53
|
-
|
54
51
|
const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
55
52
|
let {
|
56
53
|
children,
|
57
54
|
style,
|
58
55
|
debug,
|
59
56
|
mode,
|
60
|
-
onTouch
|
61
|
-
fontMgr
|
57
|
+
onTouch
|
62
58
|
} = _ref;
|
63
59
|
const size = (0, _useValue.useValue)({
|
64
60
|
width: 0,
|
@@ -111,16 +107,17 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
|
111
107
|
opacity: 1,
|
112
108
|
ref,
|
113
109
|
center: _Skia.Skia.Point(width / 2, height / 2),
|
114
|
-
fontMgr: fontMgr !== null && fontMgr !== void 0 ? fontMgr : defaultFontMgr,
|
115
110
|
Skia: _Skia.Skia
|
116
111
|
};
|
117
112
|
container.draw(ctx);
|
118
113
|
}, [tick, onTouch]);
|
119
114
|
(0, _react.useEffect)(() => {
|
120
115
|
return () => {
|
121
|
-
|
116
|
+
skiaReconciler.updateContainer(null, root, null, () => {
|
117
|
+
container.depMgr.unsubscribe();
|
118
|
+
});
|
122
119
|
};
|
123
|
-
}, [container]);
|
120
|
+
}, [container, root]);
|
124
121
|
return /*#__PURE__*/_react.default.createElement(_views.SkiaView, {
|
125
122
|
ref: ref,
|
126
123
|
style: style,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Canvas.tsx"],"names":["skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","
|
1
|
+
{"version":3,"sources":["Canvas.tsx"],"names":["skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","Canvas","forwardedRef","children","style","debug","mode","onTouch","size","width","height","canvasCtx","Skia","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","Container","DependencyManager","createContainer","onDraw","canvas","info","timestamp","touches","current","paint","Paint","ctx","opacity","center","Point","draw","unsubscribe","refs","targetRef","React","useRef","useEffect","forEach"],"mappings":";;;;;;;AAAA;;AAgBA;;AAEA;;AAEA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;;;;;;;AAH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cU,SAAS,CAACV,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACS,IAAD,CAVH;;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport { SkiaView, useDrawCallback } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport { Skia } from \"../skia/Skia\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n\n container.depMgr.subscribe();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaView>(null);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaView> {\n ref?: RefObject<SkiaView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch }, forwardedRef) => {\n const size = useValue({ width: 0, height: 0 });\n const canvasCtx = useMemo(() => ({ Skia, size }), [size]);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [tick, setTick] = useState(0);\n const redraw = useCallback(() => setTick((t) => t + 1), []);\n\n const container = useMemo(\n () => new Container(new DependencyManager(ref), redraw),\n [redraw, ref]\n );\n\n const root = useMemo(\n () => skiaReconciler.createContainer(container, 0, false, null),\n [container]\n );\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={canvasCtx}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container, canvasCtx]);\n\n // Draw callback\n const onDraw = useDrawCallback(\n (canvas, info) => {\n // TODO: if tree is empty (count === 1) maybe we should not render?\n const { width, height, timestamp } = info;\n if (onTouch) {\n onTouch(info.touches);\n }\n if (\n width !== canvasCtx.size.current.width ||\n height !== canvasCtx.size.current.height\n ) {\n canvasCtx.size.current = { width, height };\n }\n const paint = Skia.Paint();\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: Skia.Point(width / 2, height / 2),\n Skia,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.unsubscribe();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaView\n ref={ref}\n style={style}\n onDraw={onDraw}\n mode={mode}\n debug={debug}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"]}
|
@@ -55,7 +55,7 @@ const onDraw = (0, _nodes.createDrawing)((ctx, _ref, node) => {
|
|
55
55
|
canvas.save();
|
56
56
|
}
|
57
57
|
|
58
|
-
(0, _processors.processCanvasTransform)(
|
58
|
+
(0, _processors.processCanvasTransform)(canvas, groupProps);
|
59
59
|
|
60
60
|
if (clip) {
|
61
61
|
const op = invertClip ? _types.ClipOp.Difference : _types.ClipOp.Intersect;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","isDeclarationNode","map","child","draw","drawings","DrawingNode","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAWA;;AACA;;;;;;AAEA,MAAMA,SAAS,GAAIC,GAAD,IAChB,kBAAkBA,GAAlB,IAAyBA,GAAG,CAACC,YAAJ,KAAqB,OADhD;;AASA,MAAMC,MAAM,GAAG,0BACb,CAACC,GAAD,QAAkDC,IAAlD,KAA2D;AAAA,MAArD;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA,UAAf;AAA2B,OAAGC;AAA9B,GAAqD;AACzD,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,OAAV;AAAmBC,IAAAA;AAAnB,MAA4BR,GAAlC;AACA,QAAMS,YAAY,GAAGR,IAAI,CAACS,QAAL,CAClBC,MADkB,CACXC,8BADW,EAElBC,GAFkB,CAEbC,KAAD,IAAWA,KAAK,CAACC,IAAN,CAAWf,GAAX,CAFG,CAArB;AAIA,QAAMgB,QAAQ,GAAGf,IAAI,CAACS,QAAL,CAAcC,MAAd,CACdG,KAAD,IAAWA,KAAK,YAAYG,kBADb,CAAjB;AAGA,QAAMC,KAAK,GAAG,8BACZlB,GAAG,CAACQ,IADQ,EAEZR,GAAG,CAACkB,KAAJ,CAAUC,IAAV,EAFY,EAGZZ,OAHY,EAIZF,UAJY,EAKZI,YALY,CAAd;AAOA,QAAMW,YAAY,GAAG,CAAC,CAACf,UAAU,CAACgB,SAAb,IAA0B,CAAC,CAAChB,UAAU,CAACiB,MAA5D;AACA,QAAMC,OAAO,GAAG,CAAC,CAACpB,IAAlB;AACA,QAAMqB,UAAU,GAAGJ,YAAY,IAAIG,OAAhB,IAA2B,CAAC,CAACrB,KAAhD;;AACA,MAAIsB,UAAJ,EAAgB;AACd,QAAItB,KAAJ,EAAW;AACT,UAAI,OAAOA,KAAP,KAAiB,SAArB,EAAgC;AAC9BI,QAAAA,MAAM,CAACmB,SAAP;AACD,OAFD,MAEO,IAAI7B,SAAS,CAACM,KAAD,CAAb,EAAsB;AAC3BI,QAAAA,MAAM,CAACmB,SAAP,CAAiBvB,KAAjB;AACD,OAFM,MAEA;AAAA;;AACLI,QAAAA,MAAM,CAACmB,SAAP,mBAAiBvB,KAAK,CAACwB,OAAvB,2DAAkCC,SAAlC;AACD;AACF,KARD,MAQO;AACLrB,MAAAA,MAAM,CAACsB,IAAP;AACD;;AACD,
|
1
|
+
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","isDeclarationNode","map","child","draw","drawings","DrawingNode","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAWA;;AACA;;;;;;AAEA,MAAMA,SAAS,GAAIC,GAAD,IAChB,kBAAkBA,GAAlB,IAAyBA,GAAG,CAACC,YAAJ,KAAqB,OADhD;;AASA,MAAMC,MAAM,GAAG,0BACb,CAACC,GAAD,QAAkDC,IAAlD,KAA2D;AAAA,MAArD;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA,UAAf;AAA2B,OAAGC;AAA9B,GAAqD;AACzD,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,OAAV;AAAmBC,IAAAA;AAAnB,MAA4BR,GAAlC;AACA,QAAMS,YAAY,GAAGR,IAAI,CAACS,QAAL,CAClBC,MADkB,CACXC,8BADW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ADL;AAEEkB,IAAAA,KAFF;AAGEX,IAAAA,OAAO,EAAEF,UAAU,CAACE,OAAX,GAAqBF,UAAU,CAACE,OAAX,GAAqBA,OAA1C,GAAoDA;AAH/D,GADF,EAMES,QANF;;AAQA,MAAIQ,UAAJ,EAAgB;AACdlB,IAAAA,MAAM,CAAC4B,OAAP;AACD;AACF,CAjDY,CAAf;;AAoDO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAW,IAAA,MAAM,EAAErC;AAAnB,KAA+BqC,KAA/B;AAAsC,IAAA,cAAc;AAApD,KAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\nimport type { RefObject } from \"react\";\n\nimport type { SkPaint } from \"../../skia/types\";\nimport { ClipOp } from \"../../skia/types\";\nimport {\n processCanvasTransform,\n processPaint,\n processClip,\n} from \"../processors\";\nimport type {\n CustomPaintProps,\n TransformProps,\n AnimatedProps,\n ClipDef,\n} from \"../processors\";\nimport { createDrawing, DrawingNode } from \"../nodes\";\nimport { isDeclarationNode } from \"../nodes/Declaration\";\n\nconst isSkPaint = (obj: RefObject<SkPaint> | SkPaint): obj is SkPaint =>\n \"__typename__\" in obj && obj.__typename__ === \"Paint\";\n\nexport interface GroupProps extends CustomPaintProps, TransformProps {\n clip?: ClipDef;\n invertClip?: boolean;\n layer?: RefObject<SkPaint> | SkPaint | boolean;\n}\n\nconst onDraw = createDrawing<GroupProps>(\n (ctx, { layer, clip, invertClip, ...groupProps }, node) => {\n const { canvas, opacity, Skia } = ctx;\n const declarations = node.children\n .filter(isDeclarationNode)\n .map((child) => child.draw(ctx));\n\n const drawings = node.children.filter(\n (child) => child instanceof DrawingNode\n );\n const paint = processPaint(\n ctx.Skia,\n ctx.paint.copy(),\n opacity,\n groupProps,\n declarations\n );\n const hasTransform = !!groupProps.transform || !!groupProps.matrix;\n const hasClip = !!clip;\n const shouldSave = hasTransform || hasClip || !!layer;\n if (shouldSave) {\n if (layer) {\n if (typeof layer === \"boolean\") {\n canvas.saveLayer();\n } else if (isSkPaint(layer)) {\n canvas.saveLayer(layer);\n } else {\n canvas.saveLayer(layer.current ?? undefined);\n }\n } else {\n canvas.save();\n }\n processCanvasTransform(canvas, groupProps);\n if (clip) {\n const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;\n processClip(Skia, canvas, clip, op);\n }\n }\n node.visit(\n {\n ...ctx,\n paint,\n opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,\n },\n drawings\n );\n if (shouldSave) {\n canvas.restore();\n }\n }\n);\n\nexport const Group = (props: AnimatedProps<GroupProps>) => {\n return <skDrawing onDraw={onDraw} {...props} skipProcessing />;\n};\n"]}
|
@@ -9,8 +9,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
10
10
|
var _Drawing = require("../../nodes/Drawing");
|
11
11
|
|
12
|
-
var _Font = require("../../processors/Font");
|
13
|
-
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
13
|
|
16
14
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -18,9 +16,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
18
16
|
const onDraw = (0, _Drawing.createDrawing)((_ref, _ref2) => {
|
19
17
|
let {
|
20
18
|
canvas,
|
21
|
-
paint
|
22
|
-
fontMgr,
|
23
|
-
Skia
|
19
|
+
paint
|
24
20
|
} = _ref;
|
25
21
|
let {
|
26
22
|
glyphs: rawGlyphs,
|
@@ -28,7 +24,9 @@ const onDraw = (0, _Drawing.createDrawing)((_ref, _ref2) => {
|
|
28
24
|
y,
|
29
25
|
...fontDef
|
30
26
|
} = _ref2;
|
31
|
-
const
|
27
|
+
const {
|
28
|
+
font
|
29
|
+
} = fontDef;
|
32
30
|
const {
|
33
31
|
glyphs,
|
34
32
|
positions
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Glyphs.tsx"],"names":["onDraw","canvas","paint","
|
1
|
+
{"version":3,"sources":["Glyphs.tsx"],"names":["onDraw","canvas","paint","glyphs","rawGlyphs","x","y","fontDef","font","positions","reduce","acc","glyph","id","pos","push","drawGlyphs","Glyphs","props","defaultProps"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;AAqBA,MAAMA,MAAM,GAAG,4BACb,iBAAgE;AAAA,MAA/D;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA+D;AAAA,MAA5C;AAAEC,IAAAA,MAAM,EAAEC,SAAV;AAAqBC,IAAAA,CAArB;AAAwBC,IAAAA,CAAxB;AAA2B,OAAGC;AAA9B,GAA4C;AAC9D,QAAM;AAAEC,IAAAA;AAAF,MAAWD,OAAjB;AACA,QAAM;AAAEJ,IAAAA,MAAF;AAAUM,IAAAA;AAAV,MAAwBL,SAAS,CAACM,MAAV,CAC5B,CAACC,GAAD,EAAMC,KAAN,KAAgB;AACd,UAAM;AAAEC,MAAAA,EAAF;AAAMC,MAAAA;AAAN,QAAcF,KAApB;AACAD,IAAAA,GAAG,CAACR,MAAJ,CAAWY,IAAX,CAAgBF,EAAhB;AACAF,IAAAA,GAAG,CAACF,SAAJ,CAAcM,IAAd,CAAmBD,GAAnB;AACA,WAAOH,GAAP;AACD,GAN2B,EAO5B;AAAER,IAAAA,MAAM,EAAE,EAAV;AAAcM,IAAAA,SAAS,EAAE;AAAzB,GAP4B,CAA9B;AASAR,EAAAA,MAAM,CAACe,UAAP,CAAkBb,MAAlB,EAA0BM,SAA1B,EAAqCJ,CAArC,EAAwCC,CAAxC,EAA2CE,IAA3C,EAAiDN,KAAjD;AACD,CAbY,CAAf;;AAgBO,MAAMe,MAAM,GAAIC,KAAD,IAAuC;AAC3D,sBAAO;AAAW,IAAA,MAAM,EAAElB;AAAnB,KAA+BkB,KAA/B,EAAP;AACD,CAFM;;;AAIPD,MAAM,CAACE,YAAP,GAAsB;AACpBd,EAAAA,CAAC,EAAE,CADiB;AAEpBC,EAAAA,CAAC,EAAE;AAFiB,CAAtB","sourcesContent":["import React from \"react\";\n\nimport type { CustomPaintProps, AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\nimport type { SkPoint } from \"../../../skia/types\";\nimport type { FontDef } from \"../../processors/Font\";\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport type GlyphsProps = CustomPaintProps &\n FontDef & {\n x: number;\n y: number;\n glyphs: Glyph[];\n };\n\ninterface ProcessedGlyphs {\n glyphs: number[];\n positions: SkPoint[];\n}\n\nconst onDraw = createDrawing<GlyphsProps>(\n ({ canvas, paint }, { glyphs: rawGlyphs, x, y, ...fontDef }) => {\n const { font } = fontDef;\n const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(\n (acc, glyph) => {\n const { id, pos } = glyph;\n acc.glyphs.push(id);\n acc.positions.push(pos);\n return acc;\n },\n { glyphs: [], positions: [] }\n );\n canvas.drawGlyphs(glyphs, positions, x, y, font, paint);\n }\n);\n\nexport const Glyphs = (props: AnimatedProps<GlyphsProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nGlyphs.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
|
@@ -9,8 +9,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
10
10
|
var _Drawing = require("../../nodes/Drawing");
|
11
11
|
|
12
|
-
var _processors = require("../../processors");
|
13
|
-
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
13
|
|
16
14
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -18,9 +16,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
18
16
|
const onDraw = (0, _Drawing.createDrawing)((_ref, _ref2) => {
|
19
17
|
let {
|
20
18
|
canvas,
|
21
|
-
paint
|
22
|
-
fontMgr,
|
23
|
-
Skia
|
19
|
+
paint
|
24
20
|
} = _ref;
|
25
21
|
let {
|
26
22
|
text,
|
@@ -28,7 +24,9 @@ const onDraw = (0, _Drawing.createDrawing)((_ref, _ref2) => {
|
|
28
24
|
y,
|
29
25
|
...fontDef
|
30
26
|
} = _ref2;
|
31
|
-
const
|
27
|
+
const {
|
28
|
+
font
|
29
|
+
} = fontDef;
|
32
30
|
canvas.drawText(text, x, y, paint, font);
|
33
31
|
});
|
34
32
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Text.tsx"],"names":["onDraw","canvas","paint","
|
1
|
+
{"version":3,"sources":["Text.tsx"],"names":["onDraw","canvas","paint","text","x","y","fontDef","font","drawText","Text","props","defaultProps"],"mappings":";;;;;;;AAAA;;AAOA;;;;;;AASA,MAAMA,MAAM,GAAG,4BACb,iBAAmD;AAAA,MAAlD;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAkD;AAAA,MAA/B;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,CAAR;AAAWC,IAAAA,CAAX;AAAc,OAAGC;AAAjB,GAA+B;AACjD,QAAM;AAAEC,IAAAA;AAAF,MAAWD,OAAjB;AACAL,EAAAA,MAAM,CAACO,QAAP,CAAgBL,IAAhB,EAAsBC,CAAtB,EAAyBC,CAAzB,EAA4BH,KAA5B,EAAmCK,IAAnC;AACD,CAJY,CAAf;;AAOO,MAAME,IAAI,GAAIC,KAAD,IAAqC;AACvD,sBAAO;AAAW,IAAA,MAAM,EAAEV;AAAnB,KAA+BU,KAA/B,EAAP;AACD,CAFM;;;AAIPD,IAAI,CAACE,YAAL,GAAoB;AAClBP,EAAAA,CAAC,EAAE,CADe;AAElBC,EAAAA,CAAC,EAAE;AAFe,CAApB","sourcesContent":["import React from \"react\";\n\nimport type {\n CustomPaintProps,\n AnimatedProps,\n FontDef,\n} from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\n\ntype TextProps = CustomPaintProps &\n FontDef & {\n text: string;\n x: number;\n y: number;\n };\n\nconst onDraw = createDrawing<TextProps>(\n ({ canvas, paint }, { text, x, y, ...fontDef }) => {\n const { font } = fontDef;\n canvas.drawText(text, x, y, paint, font);\n }\n);\n\nexport const Text = (props: AnimatedProps<TextProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nText.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
|
@@ -9,8 +9,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
10
10
|
var _nodes = require("../../nodes");
|
11
11
|
|
12
|
-
var _Font = require("../../processors/Font");
|
13
|
-
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
13
|
|
16
14
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -19,7 +17,6 @@ const onDraw = (0, _nodes.createDrawing)((_ref, _ref2) => {
|
|
19
17
|
let {
|
20
18
|
canvas,
|
21
19
|
paint,
|
22
|
-
fontMgr,
|
23
20
|
Skia
|
24
21
|
} = _ref;
|
25
22
|
let {
|
@@ -34,7 +31,9 @@ const onDraw = (0, _nodes.createDrawing)((_ref, _ref2) => {
|
|
34
31
|
throw new Error("Invalid path: " + pathDef);
|
35
32
|
}
|
36
33
|
|
37
|
-
const
|
34
|
+
const {
|
35
|
+
font
|
36
|
+
} = fontDef;
|
38
37
|
const ids = font.getGlyphIDs(text);
|
39
38
|
const widths = font.getGlyphWidths(ids, paint);
|
40
39
|
const rsx = [];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["TextPath.tsx"],"names":["onDraw","canvas","paint","
|
1
|
+
{"version":3,"sources":["TextPath.tsx"],"names":["onDraw","canvas","paint","Skia","text","initialOffset","path","pathDef","fontDef","Path","MakeFromSVGString","Error","font","ids","getGlyphIDs","widths","getGlyphWidths","rsx","meas","ContourMeasureIter","cont","next","dist","i","length","width","substring","px","py","tx","ty","getPosTan","adjustedX","adjustedY","push","RSXform","blob","TextBlob","MakeFromRSXform","drawTextBlob","TextPath","props","defaultProps"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;AAWA,MAAMA,MAAM,GAAG,0BACb,iBAGK;AAAA,MAFH;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA;AAAjB,GAEG;AAAA,MADH;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,aAAR;AAAuBC,IAAAA,IAAI,EAAEC,OAA7B;AAAsC,OAAGC;AAAzC,GACG;AACH,QAAMF,IAAI,GACR,OAAOC,OAAP,KAAmB,QAAnB,GACIJ,IAAI,CAACM,IAAL,CAAUC,iBAAV,CAA4BH,OAA5B,CADJ,GAEIA,OAHN;;AAIA,MAAID,IAAI,KAAK,IAAb,EAAmB;AACjB,UAAM,IAAIK,KAAJ,CAAU,mBAAmBJ,OAA7B,CAAN;AACD;;AACD,QAAM;AAAEK,IAAAA;AAAF,MAAWJ,OAAjB;AACA,QAAMK,GAAG,GAAGD,IAAI,CAACE,WAAL,CAAiBV,IAAjB,CAAZ;AACA,QAAMW,MAAM,GAAGH,IAAI,CAACI,cAAL,CAAoBH,GAApB,EAAyBX,KAAzB,CAAf;AACA,QAAMe,GAAgB,GAAG,EAAzB;AACA,QAAMC,IAAI,GAAGf,IAAI,CAACgB,kBAAL,CAAwBb,IAAxB,EAA8B,KAA9B,EAAqC,CAArC,CAAb;AACA,MAAIc,IAAI,GAAGF,IAAI,CAACG,IAAL,EAAX;AACA,MAAIC,IAAI,GAAGjB,aAAX;;AACA,OAAK,IAAIkB,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGnB,IAAI,CAACoB,MAAT,IAAmBJ,IAAnC,EAAy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;AACD,CAFM;;;AAIPD,QAAQ,CAACE,YAAT,GAAwB;AACtBrC,EAAAA,aAAa,EAAE;AADO,CAAxB","sourcesContent":["import React from \"react\";\n\nimport type { CustomPaintProps, AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes\";\nimport type { SkPath, SkRSXform } from \"../../../skia/types\";\nimport type { FontDef } from \"../../processors/Font\";\n\nexport type TextPathProps = CustomPaintProps &\n FontDef & {\n text: string;\n path: SkPath | string;\n initialOffset: number;\n };\n\nconst onDraw = createDrawing<TextPathProps>(\n (\n { canvas, paint, Skia },\n { text, initialOffset, path: pathDef, ...fontDef }\n ) => {\n const path =\n typeof pathDef === \"string\"\n ? Skia.Path.MakeFromSVGString(pathDef)\n : pathDef;\n if (path === null) {\n throw new Error(\"Invalid path: \" + pathDef);\n }\n const { font } = fontDef;\n const ids = font.getGlyphIDs(text);\n const widths = font.getGlyphWidths(ids, paint);\n const rsx: SkRSXform[] = [];\n const meas = Skia.ContourMeasureIter(path, false, 1);\n let cont = meas.next();\n let dist = initialOffset;\n for (let i = 0; i < text.length && cont; i++) {\n const width = widths[i];\n dist += width / 2;\n if (dist > cont.length()) {\n // jump to next contour\n cont = meas.next();\n if (!cont) {\n // We have come to the end of the path - terminate the string\n // right here.\n text = text.substring(0, i);\n break;\n }\n dist = width / 2;\n }\n // Gives us the (x, y) coordinates as well as the cos/sin of the tangent\n // line at that position.\n const { px, py, tx, ty } = cont.getPosTan(dist);\n const adjustedX = px - (width / 2) * tx;\n const adjustedY = py - (width / 2) * ty;\n rsx.push(Skia.RSXform(tx, ty, adjustedX, adjustedY));\n dist += width / 2;\n }\n const blob = Skia.TextBlob.MakeFromRSXform(text, rsx, font);\n canvas.drawTextBlob(blob, 0, 0, paint);\n }\n);\n\nexport const TextPath = (props: AnimatedProps<TextPathProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nTextPath.defaultProps = {\n initialOffset: 0,\n};\n"]}
|
@@ -3,37 +3,11 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.isFont = void 0;
|
7
7
|
|
8
8
|
const isFont = fontDef => // We have an issue to check property existence on JSI backed instances
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
10
|
fontDef.font !== undefined;
|
11
11
|
|
12
12
|
exports.isFont = isFont;
|
13
|
-
|
14
|
-
const processFont = (Skia, fontMgr, fontDef) => {
|
15
|
-
let selectedFont;
|
16
|
-
|
17
|
-
if (isFont(fontDef)) {
|
18
|
-
selectedFont = fontDef.font;
|
19
|
-
} else {
|
20
|
-
console.warn( // eslint-disable-next-line max-len
|
21
|
-
"Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts");
|
22
|
-
const {
|
23
|
-
familyName,
|
24
|
-
size
|
25
|
-
} = fontDef;
|
26
|
-
const typeface = fontMgr.matchFamilyStyle(familyName);
|
27
|
-
|
28
|
-
if (typeface === null) {
|
29
|
-
throw new Error(`No typeface found for ${familyName}`);
|
30
|
-
}
|
31
|
-
|
32
|
-
selectedFont = Skia.Font(typeface, size);
|
33
|
-
}
|
34
|
-
|
35
|
-
return selectedFont;
|
36
|
-
};
|
37
|
-
|
38
|
-
exports.processFont = processFont;
|
39
13
|
//# sourceMappingURL=Font.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Font.ts"],"names":["isFont","fontDef","font","undefined"
|
1
|
+
{"version":3,"sources":["Font.ts"],"names":["isFont","fontDef","font","undefined"],"mappings":";;;;;;;AAIO,MAAMA,MAAM,GAAIC,OAAD,IACpB;AACA;AACCA,OAAD,CAAiBC,IAAjB,KAA0BC,SAHrB","sourcesContent":["import type { SkFont } from \"../../skia/types\";\n\nexport type FontDef = { font: SkFont };\n\nexport const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (fontDef as any).font !== undefined;\n"]}
|
@@ -7,40 +7,33 @@ exports.transformOrigin = exports.processCanvasTransform = exports.localMatrix =
|
|
7
7
|
|
8
8
|
var _types = require("../../skia/types");
|
9
9
|
|
10
|
-
const processCanvasTransform = (
|
11
|
-
let {
|
12
|
-
canvas,
|
13
|
-
Skia
|
14
|
-
} = _ref;
|
10
|
+
const processCanvasTransform = (canvas, _ref) => {
|
15
11
|
let {
|
16
12
|
transform,
|
17
13
|
origin,
|
18
14
|
matrix
|
19
|
-
} =
|
15
|
+
} = _ref;
|
20
16
|
|
21
17
|
if (matrix) {
|
22
18
|
if (origin) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
m3.translate(-origin.x, -origin.y);
|
27
|
-
canvas.concat(m3);
|
19
|
+
canvas.translate(origin.x, origin.y);
|
20
|
+
canvas.concat(matrix);
|
21
|
+
canvas.translate(-origin.x, -origin.y);
|
28
22
|
} else {
|
29
23
|
canvas.concat(matrix);
|
30
24
|
}
|
31
25
|
} else if (transform) {
|
32
|
-
|
33
|
-
canvas.concat(m3);
|
26
|
+
(0, _types.processTransform)(canvas, origin ? transformOrigin(origin, transform) : transform);
|
34
27
|
}
|
35
28
|
};
|
36
29
|
|
37
30
|
exports.processCanvasTransform = processCanvasTransform;
|
38
31
|
|
39
|
-
const localMatrix = (m,
|
32
|
+
const localMatrix = (m, _ref2) => {
|
40
33
|
let {
|
41
34
|
transform,
|
42
35
|
origin
|
43
|
-
} =
|
36
|
+
} = _ref2;
|
44
37
|
|
45
38
|
if (transform) {
|
46
39
|
return (0, _types.processTransform)(m, origin ? transformOrigin(origin, transform) : transform);
|