@shopify/react-native-skia 0.1.116 → 0.1.118
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkApi.h +13 -9
- package/cpp/api/JsiSkCanvas.h +9 -1
- package/cpp/api/JsiSkPicture.h +71 -0
- package/cpp/api/JsiSkPictureFactory.h +50 -0
- package/cpp/api/JsiSkPictureRecorder.h +53 -0
- package/lib/commonjs/renderer/Canvas.js +22 -36
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +2 -24
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/renderer/components/Drawing.js +31 -0
- package/lib/commonjs/renderer/components/Drawing.js.map +1 -0
- package/lib/commonjs/renderer/components/Group.js +1 -1
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Picture.js +35 -0
- package/lib/commonjs/renderer/components/Picture.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +5 -34
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/commonjs/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +19 -8
- package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/index.js +4 -17
- package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/commonjs/renderer/components/index.js +26 -0
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Box.js +126 -0
- package/lib/commonjs/renderer/components/shapes/Box.js.map +1 -0
- package/lib/commonjs/renderer/components/shapes/index.js +13 -0
- package/lib/commonjs/renderer/components/shapes/index.js.map +1 -1
- package/lib/commonjs/renderer/index.js +13 -0
- package/lib/commonjs/renderer/index.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Declaration.js +8 -1
- package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Drawing.js +5 -8
- package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Math.js +19 -1
- package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Matrix3.js +11 -5
- package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/commonjs/renderer/typeddash.js +26 -2
- package/lib/commonjs/renderer/typeddash.js.map +1 -1
- package/lib/commonjs/renderer/useContextBridge.js +35 -0
- package/lib/commonjs/renderer/useContextBridge.js.map +1 -0
- package/lib/commonjs/skia/Canvas.js.map +1 -1
- package/lib/commonjs/skia/Picture/Picture.js +6 -0
- package/lib/commonjs/skia/Picture/Picture.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js +6 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js +6 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/commonjs/skia/Picture/index.js +58 -0
- package/lib/commonjs/skia/Picture/index.js.map +1 -0
- package/lib/commonjs/skia/Picture/usePicture.js +30 -0
- package/lib/commonjs/skia/Picture/usePicture.js.map +1 -0
- package/lib/commonjs/skia/Skia.js +2 -0
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/commonjs/skia/index.js +14 -0
- package/lib/commonjs/skia/index.js.map +1 -1
- package/lib/commonjs/values/hooks/useDerivedValue.js +2 -2
- package/lib/commonjs/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -5
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.js +20 -32
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +1 -23
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/renderer/components/Drawing.js +17 -0
- package/lib/module/renderer/components/Drawing.js.map +1 -0
- package/lib/module/renderer/components/Group.js +1 -1
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Picture.js +21 -0
- package/lib/module/renderer/components/Picture.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/InnerShadow.js +4 -26
- package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/module/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +16 -6
- package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/index.js +1 -2
- package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/module/renderer/components/index.js +2 -0
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/module/renderer/components/shapes/Box.js +102 -0
- package/lib/module/renderer/components/shapes/Box.js.map +1 -0
- package/lib/module/renderer/components/shapes/index.js +1 -0
- package/lib/module/renderer/components/shapes/index.js.map +1 -1
- package/lib/module/renderer/index.js +1 -0
- package/lib/module/renderer/index.js.map +1 -1
- package/lib/module/renderer/nodes/Declaration.js +3 -0
- package/lib/module/renderer/nodes/Declaration.js.map +1 -1
- package/lib/module/renderer/nodes/Drawing.js +3 -4
- package/lib/module/renderer/nodes/Drawing.js.map +1 -1
- package/lib/module/renderer/processors/math/Math.js +15 -0
- package/lib/module/renderer/processors/math/Math.js.map +1 -1
- package/lib/module/renderer/processors/math/Matrix3.js +6 -2
- package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/module/renderer/typeddash.js +21 -0
- package/lib/module/renderer/typeddash.js.map +1 -1
- package/lib/module/renderer/useContextBridge.js +21 -0
- package/lib/module/renderer/useContextBridge.js.map +1 -0
- package/lib/module/skia/Canvas.js.map +1 -1
- package/lib/module/skia/Picture/Picture.js +2 -0
- package/lib/module/skia/Picture/Picture.js.map +1 -0
- package/lib/module/skia/Picture/PictureFactory.js +2 -0
- package/lib/module/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/module/skia/Picture/PictureRecorder.js +2 -0
- package/lib/module/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/module/skia/Picture/index.js +5 -0
- package/lib/module/skia/Picture/index.js.map +1 -0
- package/lib/module/skia/Picture/usePicture.js +19 -0
- package/lib/module/skia/Picture/usePicture.js.map +1 -0
- package/lib/module/skia/Skia.js +2 -0
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/module/skia/index.js +1 -0
- package/lib/module/skia/index.js.map +1 -1
- package/lib/module/values/hooks/useDerivedValue.js +1 -1
- package/lib/module/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/module/views/SkiaView.js +6 -5
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +5 -10
- package/lib/typescript/src/renderer/components/Drawing.d.ts +7 -0
- package/lib/typescript/src/renderer/components/Picture.d.ts +6 -0
- package/lib/typescript/src/renderer/components/imageFilters/InnerShadow.d.ts +3 -12
- package/lib/typescript/src/renderer/components/imageFilters/{DropShadow.d.ts → Shadow.d.ts} +3 -2
- package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -2
- package/lib/typescript/src/renderer/components/index.d.ts +2 -0
- package/lib/typescript/src/renderer/components/shapes/Box.d.ts +23 -0
- package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
- package/lib/typescript/src/renderer/index.d.ts +1 -0
- package/lib/typescript/src/renderer/nodes/Declaration.d.ts +2 -0
- package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
- package/lib/typescript/src/renderer/processors/math/Math.d.ts +14 -0
- package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -0
- package/lib/typescript/src/renderer/typeddash.d.ts +1 -0
- package/lib/typescript/src/renderer/useContextBridge.d.ts +5 -0
- package/lib/typescript/src/skia/Canvas.d.ts +6 -0
- package/lib/typescript/src/skia/Picture/Picture.d.ts +26 -0
- package/lib/typescript/src/skia/Picture/PictureFactory.d.ts +8 -0
- package/lib/typescript/src/skia/Picture/PictureRecorder.d.ts +15 -0
- package/lib/typescript/src/skia/Picture/index.d.ts +4 -0
- package/lib/typescript/src/skia/Picture/usePicture.d.ts +11 -0
- package/lib/typescript/src/skia/Skia.d.ts +5 -0
- package/lib/typescript/src/skia/index.d.ts +1 -0
- package/lib/typescript/src/views/SkiaView.d.ts +25 -1
- package/lib/typescript/src/views/types.d.ts +0 -24
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +14 -30
- package/src/renderer/HostConfig.ts +1 -19
- package/src/renderer/components/Drawing.tsx +16 -0
- package/src/renderer/components/Group.tsx +1 -1
- package/src/renderer/components/Picture.tsx +17 -0
- package/src/renderer/components/imageFilters/InnerShadow.tsx +33 -47
- package/src/renderer/components/imageFilters/Shadow.tsx +39 -0
- package/src/renderer/components/imageFilters/index.ts +1 -2
- package/src/renderer/components/index.ts +2 -0
- package/src/renderer/components/maskFilters/Blur.tsx +1 -1
- package/src/renderer/components/shapes/Box.tsx +98 -0
- package/src/renderer/components/shapes/index.ts +1 -0
- package/src/renderer/index.ts +1 -0
- package/src/renderer/nodes/Declaration.tsx +10 -0
- package/src/renderer/nodes/Drawing.tsx +6 -6
- package/src/renderer/processors/math/Math.ts +16 -0
- package/src/renderer/processors/math/Matrix3.ts +35 -31
- package/src/renderer/typeddash.ts +18 -0
- package/src/renderer/useContextBridge.tsx +21 -0
- package/src/skia/Canvas.ts +7 -0
- package/src/skia/Picture/Picture.ts +34 -0
- package/src/skia/Picture/PictureFactory.ts +9 -0
- package/src/skia/Picture/PictureRecorder.ts +18 -0
- package/src/skia/Picture/index.ts +4 -0
- package/src/skia/Picture/usePicture.ts +28 -0
- package/src/skia/Skia.ts +5 -0
- package/src/skia/index.ts +1 -0
- package/src/values/hooks/useDerivedValue.ts +1 -1
- package/src/views/SkiaView.tsx +27 -3
- package/src/views/types.ts +0 -25
- package/lib/commonjs/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/lib/module/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/src/renderer/components/imageFilters/DropShadow.tsx +0 -31
package/cpp/api/JsiSkApi.h
CHANGED
@@ -37,6 +37,8 @@
|
|
37
37
|
#include "JsiSkSurfaceFactory.h"
|
38
38
|
#include "JsiSkTextBlobFactory.h"
|
39
39
|
#include "JsiSkContourMeasureIter.h"
|
40
|
+
#include "JsiSkPictureRecorder.h"
|
41
|
+
#include "JsiSkPictureFactory.h"
|
40
42
|
|
41
43
|
namespace RNSkia
|
42
44
|
{
|
@@ -55,15 +57,16 @@ namespace RNSkia
|
|
55
57
|
: JsiSkHostObject(context)
|
56
58
|
{
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
installFunction("Font", JsiSkFont::createCtor(context));
|
61
|
+
installFunction("Paint", JsiSkPaint::createCtor(context));
|
62
|
+
installFunction("RSXform", JsiSkRSXform::createCtor(context));
|
63
|
+
installFunction("Matrix", JsiSkMatrix::createCtor(context));
|
64
|
+
installFunction("XYWHRect", JsiSkRect::createCtor(context));
|
65
|
+
installFunction("RRectXY", JsiSkRRect::createCtor(context));
|
66
|
+
installFunction("Point", JsiSkPoint::createCtor(context));
|
67
|
+
installFunction("ContourMeasureIter", JsiSkContourMeasureIter::createCtor(context));
|
68
|
+
installFunction("MakeVertices", JsiSkVertices::createCtor(context));
|
69
|
+
installFunction("PictureRecorder", JsiSkPictureRecorder::createCtor(context));
|
67
70
|
|
68
71
|
// Static members
|
69
72
|
installReadonlyProperty("FontMgr",
|
@@ -92,6 +95,7 @@ namespace RNSkia
|
|
92
95
|
std::make_shared<JsiSkShaderFactory>(context));
|
93
96
|
installReadonlyProperty("TextBlob", std::make_shared<JsiSkTextBlobFactory>(context));
|
94
97
|
installReadonlyProperty("Surface", std::make_shared<JsiSkSurfaceFactory>(context));
|
98
|
+
installReadonlyProperty("Picture", std::make_shared<JsiSkPictureFactory>(context));
|
95
99
|
};
|
96
100
|
};
|
97
101
|
} // namespace RNSkia
|
package/cpp/api/JsiSkCanvas.h
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
#include "JsiSkSVG.h"
|
16
16
|
#include "JsiSkVertices.h"
|
17
17
|
#include "JsiSkTextBlob.h"
|
18
|
+
#include "JsiSkPicture.h"
|
18
19
|
|
19
20
|
#include <jsi/jsi.h>
|
20
21
|
|
@@ -476,6 +477,12 @@ public:
|
|
476
477
|
_canvas->concat(*matrix.get());
|
477
478
|
return jsi::Value::undefined();
|
478
479
|
}
|
480
|
+
|
481
|
+
JSI_HOST_FUNCTION(drawPicture) {
|
482
|
+
auto picture = JsiSkPicture::fromValue(runtime, arguments[0]);
|
483
|
+
_canvas->drawPicture(picture);
|
484
|
+
return jsi::Value::undefined();
|
485
|
+
}
|
479
486
|
|
480
487
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkCanvas, drawPaint),
|
481
488
|
JSI_EXPORT_FUNC(JsiSkCanvas, drawLine),
|
@@ -514,7 +521,8 @@ public:
|
|
514
521
|
JSI_EXPORT_FUNC(JsiSkCanvas, skew),
|
515
522
|
JSI_EXPORT_FUNC(JsiSkCanvas, drawColor),
|
516
523
|
JSI_EXPORT_FUNC(JsiSkCanvas, clear),
|
517
|
-
JSI_EXPORT_FUNC(JsiSkCanvas, concat)
|
524
|
+
JSI_EXPORT_FUNC(JsiSkCanvas, concat),
|
525
|
+
JSI_EXPORT_FUNC(JsiSkCanvas, drawPicture))
|
518
526
|
|
519
527
|
JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context)
|
520
528
|
: JsiSkHostObject(std::move(context)) {}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
#pragma once
|
3
|
+
|
4
|
+
#include "JsiSkHostObjects.h"
|
5
|
+
#include <JsiSkData.h>
|
6
|
+
#include <JsiSkShader.h>
|
7
|
+
|
8
|
+
#pragma clang diagnostic push
|
9
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
10
|
+
|
11
|
+
#include <SkPicture.h>
|
12
|
+
|
13
|
+
#pragma clang diagnostic pop
|
14
|
+
|
15
|
+
namespace RNSkia {
|
16
|
+
|
17
|
+
using namespace facebook;
|
18
|
+
|
19
|
+
class JsiSkPicture : public JsiSkWrappingSkPtrHostObject<SkPicture> {
|
20
|
+
public:
|
21
|
+
|
22
|
+
JsiSkPicture(std::shared_ptr<RNSkPlatformContext> context, const sk_sp<SkPicture> picture)
|
23
|
+
: JsiSkWrappingSkPtrHostObject<SkPicture>(context, picture) {};
|
24
|
+
|
25
|
+
JSI_HOST_FUNCTION(makeShader) {
|
26
|
+
auto tmx = (SkTileMode)arguments[0].asNumber();
|
27
|
+
auto tmy = (SkTileMode)arguments[1].asNumber();
|
28
|
+
auto fm = (SkFilterMode)arguments[2].asNumber();
|
29
|
+
auto m = count > 3 && !arguments[3].isUndefined() ?
|
30
|
+
JsiSkMatrix::fromValue(runtime, arguments[3]).get() : nullptr;
|
31
|
+
|
32
|
+
auto tr = count > 4 && !arguments[4].isUndefined() ?
|
33
|
+
JsiSkRect::fromValue(runtime, arguments[4]).get() : nullptr;
|
34
|
+
|
35
|
+
// Create shader
|
36
|
+
auto shader = getObject()->makeShader(tmx, tmy, fm, m, tr);
|
37
|
+
return jsi::Object::createFromHostObject(
|
38
|
+
runtime, std::make_shared<JsiSkShader>(getContext(), shader));
|
39
|
+
}
|
40
|
+
|
41
|
+
JSI_HOST_FUNCTION(serialize) {
|
42
|
+
auto data = getObject()->serialize();
|
43
|
+
auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array");
|
44
|
+
size_t size = data->size();
|
45
|
+
|
46
|
+
jsi::Object array = arrayCtor.callAsConstructor(runtime, static_cast<double>(size)).getObject(runtime);
|
47
|
+
jsi::ArrayBuffer buffer = array
|
48
|
+
.getProperty(runtime, jsi::PropNameID::forAscii(runtime, "buffer"))
|
49
|
+
.asObject(runtime)
|
50
|
+
.getArrayBuffer(runtime);
|
51
|
+
|
52
|
+
auto bfrPtr = reinterpret_cast<uint8_t *>(buffer.data(runtime));
|
53
|
+
memcpy(bfrPtr, data->bytes(), size);
|
54
|
+
return array;
|
55
|
+
}
|
56
|
+
|
57
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPicture, makeShader),
|
58
|
+
JSI_EXPORT_FUNC(JsiSkPicture, serialize))
|
59
|
+
|
60
|
+
/**
|
61
|
+
Returns the underlying object from a host object of this type
|
62
|
+
*/
|
63
|
+
static sk_sp<SkPicture> fromValue(jsi::Runtime &runtime,
|
64
|
+
const jsi::Value &obj) {
|
65
|
+
return obj.asObject(runtime)
|
66
|
+
.asHostObject<JsiSkPicture>(runtime)
|
67
|
+
.get()
|
68
|
+
->getObject();
|
69
|
+
}
|
70
|
+
};
|
71
|
+
} // namespace RNSkia
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
#pragma once
|
3
|
+
|
4
|
+
#include "JsiSkColorFilter.h"
|
5
|
+
#include "JsiSkHostObjects.h"
|
6
|
+
#include "JsiSkData.h"
|
7
|
+
#include "JsiSkPicture.h"
|
8
|
+
|
9
|
+
#pragma clang diagnostic push
|
10
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
11
|
+
|
12
|
+
#include <SkPicture.h>
|
13
|
+
#include <SkData.h>
|
14
|
+
|
15
|
+
#pragma clang diagnostic pop
|
16
|
+
|
17
|
+
namespace RNSkia {
|
18
|
+
|
19
|
+
using namespace facebook;
|
20
|
+
|
21
|
+
class JsiSkPictureFactory : public JsiSkHostObject {
|
22
|
+
public:
|
23
|
+
JSI_HOST_FUNCTION(MakePicture) {
|
24
|
+
if(!arguments[0].isObject()) {
|
25
|
+
jsi::detail::throwJSError(runtime, "Expected arraybuffer as first parameter");
|
26
|
+
}
|
27
|
+
auto array = arguments[0].asObject(runtime);
|
28
|
+
jsi::ArrayBuffer buffer = array
|
29
|
+
.getProperty(runtime, jsi::PropNameID::forAscii(runtime, "buffer"))
|
30
|
+
.asObject(runtime)
|
31
|
+
.getArrayBuffer(runtime);
|
32
|
+
|
33
|
+
sk_sp<SkData> data = SkData::MakeWithCopy(buffer.data(runtime), buffer.size(runtime));
|
34
|
+
auto picture = SkPicture::MakeFromData(data.get());
|
35
|
+
if(picture != nullptr) {
|
36
|
+
return jsi::Object::createFromHostObject(
|
37
|
+
runtime,
|
38
|
+
std::make_shared<JsiSkPicture>(getContext(), picture));
|
39
|
+
} else {
|
40
|
+
return jsi::Value::undefined();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPictureFactory, MakePicture))
|
45
|
+
|
46
|
+
JsiSkPictureFactory(std::shared_ptr<RNSkPlatformContext> context)
|
47
|
+
: JsiSkHostObject(context) {}
|
48
|
+
};
|
49
|
+
|
50
|
+
} // namespace RNSkia
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
#pragma once
|
3
|
+
|
4
|
+
#include "JsiSkHostObjects.h"
|
5
|
+
#include "JsiSkRect.h"
|
6
|
+
#include "JsiSkPicture.h"
|
7
|
+
#include "JsiSkCanvas.h"
|
8
|
+
|
9
|
+
#pragma clang diagnostic push
|
10
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
11
|
+
|
12
|
+
#include <SkPictureRecorder.h>
|
13
|
+
#include <SkBBHFactory.h>
|
14
|
+
|
15
|
+
#pragma clang diagnostic pop
|
16
|
+
|
17
|
+
namespace RNSkia {
|
18
|
+
|
19
|
+
using namespace facebook;
|
20
|
+
|
21
|
+
class JsiSkPictureRecorder : public JsiSkWrappingSharedPtrHostObject<SkPictureRecorder> {
|
22
|
+
public:
|
23
|
+
|
24
|
+
JsiSkPictureRecorder(std::shared_ptr<RNSkPlatformContext> context)
|
25
|
+
: JsiSkWrappingSharedPtrHostObject<SkPictureRecorder>(
|
26
|
+
context, std::make_shared<SkPictureRecorder>()){};
|
27
|
+
|
28
|
+
JSI_HOST_FUNCTION(beginRecording) {
|
29
|
+
auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
|
30
|
+
SkRTreeFactory factory;
|
31
|
+
auto canvas = getObject()->beginRecording(*rect, &factory);
|
32
|
+
return jsi::Object::createFromHostObject(
|
33
|
+
runtime, std::make_shared<JsiSkCanvas>(getContext(), canvas));
|
34
|
+
}
|
35
|
+
|
36
|
+
JSI_HOST_FUNCTION(finishRecordingAsPicture) {
|
37
|
+
auto picture = getObject()->finishRecordingAsPicture();
|
38
|
+
return jsi::Object::createFromHostObject(
|
39
|
+
runtime, std::make_shared<JsiSkPicture>(getContext(), picture));
|
40
|
+
}
|
41
|
+
|
42
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPictureRecorder, beginRecording),
|
43
|
+
JSI_EXPORT_FUNC(JsiSkPictureRecorder, finishRecordingAsPicture))
|
44
|
+
|
45
|
+
static const jsi::HostFunctionType
|
46
|
+
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
47
|
+
return JSI_HOST_FUNCTION_LAMBDA {
|
48
|
+
return jsi::Object::createFromHostObject(
|
49
|
+
runtime, std::make_shared<JsiSkPictureRecorder>(context));
|
50
|
+
};
|
51
|
+
}
|
52
|
+
};
|
53
|
+
} // namespace RNSkia
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.useCanvasSize = exports.useCanvasRef = exports.skiaReconciler = exports.Canvas = void 0;
|
7
7
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
9
9
|
|
@@ -13,6 +13,8 @@ var _views = require("../views");
|
|
13
13
|
|
14
14
|
var _skia = require("../skia");
|
15
15
|
|
16
|
+
var _useValue = require("../values/hooks/useValue");
|
17
|
+
|
16
18
|
var _HostConfig = require("./HostConfig");
|
17
19
|
|
18
20
|
var _processors = require("./processors");
|
@@ -28,31 +30,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
28
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
29
31
|
|
30
32
|
// import { debugTree } from "./nodes";
|
31
|
-
// useContextBridge() is taken from https://github.com/pmndrs/drei#usecontextbridge
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
33
|
-
const useContextBridge = function () {
|
34
|
-
for (var _len = arguments.length, contexts = new Array(_len), _key = 0; _key < _len; _key++) {
|
35
|
-
contexts[_key] = arguments[_key];
|
36
|
-
}
|
37
|
-
|
38
|
-
const values = // eslint-disable-next-line react-hooks/rules-of-hooks
|
39
|
-
contexts.map(context => (0, _react.useContext)(context));
|
40
|
-
return (0, _react.useMemo)(() => _ref => {
|
41
|
-
let {
|
42
|
-
children
|
43
|
-
} = _ref;
|
44
|
-
return contexts.reduceRight((acc, Context, i) => /*#__PURE__*/_react.default.createElement(Context.Provider, {
|
45
|
-
value: values[i],
|
46
|
-
children: acc
|
47
|
-
}), children);
|
48
|
-
}, [contexts, values]);
|
49
|
-
};
|
50
|
-
|
51
|
-
exports.useContextBridge = useContextBridge;
|
52
|
-
|
53
33
|
const CanvasContext = /*#__PURE__*/_react.default.createContext(null);
|
54
34
|
|
55
|
-
const
|
35
|
+
const useCanvasSize = () => {
|
56
36
|
const canvas = (0, _react.useContext)(CanvasContext);
|
57
37
|
|
58
38
|
if (!canvas) {
|
@@ -62,7 +42,7 @@ const useCanvas = () => {
|
|
62
42
|
return canvas;
|
63
43
|
};
|
64
44
|
|
65
|
-
exports.
|
45
|
+
exports.useCanvasSize = useCanvasSize;
|
66
46
|
const skiaReconciler = (0, _reactReconciler.default)(_HostConfig.skHostConfig);
|
67
47
|
exports.skiaReconciler = skiaReconciler;
|
68
48
|
skiaReconciler.injectIntoDevTools({
|
@@ -84,7 +64,7 @@ exports.useCanvasRef = useCanvasRef;
|
|
84
64
|
|
85
65
|
const defaultFontMgr = _skia.Skia.FontMgr.RefDefault();
|
86
66
|
|
87
|
-
const Canvas = /*#__PURE__*/(0, _react.forwardRef)((
|
67
|
+
const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
88
68
|
let {
|
89
69
|
children,
|
90
70
|
style,
|
@@ -92,23 +72,23 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref2, forwardedRef) => {
|
|
92
72
|
mode,
|
93
73
|
onTouch,
|
94
74
|
fontMgr
|
95
|
-
} =
|
75
|
+
} = _ref;
|
76
|
+
const canvasCtx = (0, _useValue.useValue)({
|
77
|
+
width: 0,
|
78
|
+
height: 0
|
79
|
+
});
|
96
80
|
const innerRef = useCanvasRef();
|
97
81
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
98
82
|
const [tick, setTick] = (0, _react.useState)(0);
|
99
83
|
const redraw = (0, _react.useCallback)(() => setTick(t => t + 1), []);
|
100
84
|
const container = (0, _react.useMemo)(() => new _nodes.Container(new _DependencyManager.DependencyManager(ref), redraw), [redraw, ref]);
|
101
|
-
const canvasCtx = (0, _react.useRef)({
|
102
|
-
width: 0,
|
103
|
-
height: 0
|
104
|
-
});
|
105
85
|
const root = (0, _react.useMemo)(() => skiaReconciler.createContainer(container, 0, false, null), [container]); // Render effect
|
106
86
|
|
107
87
|
(0, _react.useEffect)(() => {
|
108
88
|
render( /*#__PURE__*/_react.default.createElement(CanvasContext.Provider, {
|
109
|
-
value: canvasCtx
|
89
|
+
value: canvasCtx
|
110
90
|
}, children), root, container);
|
111
|
-
}, [children, root, redraw, container]); // Draw callback
|
91
|
+
}, [children, root, redraw, container, canvasCtx]); // Draw callback
|
112
92
|
|
113
93
|
const onDraw = (0, _views.useDrawCallback)((canvas, info) => {
|
114
94
|
// TODO: if tree is empty (count === 1) maybe we should not render?
|
@@ -122,6 +102,13 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref2, forwardedRef) => {
|
|
122
102
|
onTouch(info.touches);
|
123
103
|
}
|
124
104
|
|
105
|
+
if (width !== canvasCtx.current.width || height !== canvasCtx.current.height) {
|
106
|
+
canvasCtx.current = {
|
107
|
+
width,
|
108
|
+
height
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
125
112
|
const paint = _skia.Skia.Paint();
|
126
113
|
|
127
114
|
paint.setAntiAlias(true);
|
@@ -136,7 +123,6 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref2, forwardedRef) => {
|
|
136
123
|
center: (0, _processors.vec)(width / 2, height / 2),
|
137
124
|
fontMgr: fontMgr !== null && fontMgr !== void 0 ? fontMgr : defaultFontMgr
|
138
125
|
};
|
139
|
-
canvasCtx.current = ctx;
|
140
126
|
container.draw(ctx);
|
141
127
|
}, [tick, onTouch]);
|
142
128
|
(0, _react.useEffect)(() => {
|
@@ -163,8 +149,8 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref2, forwardedRef) => {
|
|
163
149
|
exports.Canvas = Canvas;
|
164
150
|
|
165
151
|
const useCombinedRefs = function () {
|
166
|
-
for (var
|
167
|
-
refs[
|
152
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
153
|
+
refs[_key] = arguments[_key];
|
168
154
|
}
|
169
155
|
|
170
156
|
const targetRef = _react.default.useRef(null);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Canvas.tsx"],"names":["
|
1
|
+
{"version":3,"sources":["Canvas.tsx"],"names":["CanvasContext","React","createContext","useCanvasSize","canvas","Error","skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","defaultFontMgr","Skia","FontMgr","RefDefault","Canvas","forwardedRef","children","style","debug","mode","onTouch","fontMgr","canvasCtx","width","height","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","Container","DependencyManager","createContainer","onDraw","info","timestamp","touches","current","paint","Paint","setAntiAlias","ctx","opacity","center","draw","unsubscribe","refs","targetRef","useRef","useEffect","forEach"],"mappings":";;;;;;;AAAA;;AAiBA;;AAEA;;AAEA;;AAEA;;AAGA;;AAEA;;AACA;;AACA;;;;;;;;AAHA;AAKA,MAAMA,aAAa,gBAAGC,eAAMC,aAAN,CAGX,IAHW,CAAtB;;AAKO,MAAMC,aAAa,GAAG,MAAM;AACjC,QAAMC,MAAM,GAAG,uBAAWJ,aAAX,CAAf;;AACA,MAAI,CAACI,MAAL,EAAa;AACX,UAAM,IAAIC,KAAJ,CAAU,iCAAV,CAAN;AACD;;AACD,SAAOD,MAAP;AACD,CANM;;;AA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useState,\n useCallback,\n useMemo,\n useContext,\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 { Skia } from \"../skia\";\nimport type { FontMgr } from \"../skia/FontMgr/FontMgr\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport type { SkiaReadonlyValue } from \"../values/types\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { vec } from \"./processors\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\n\nconst CanvasContext = React.createContext<SkiaReadonlyValue<{\n width: number;\n height: number;\n}> | null>(null);\n\nexport const useCanvasSize = () => {\n const canvas = useContext(CanvasContext);\n if (!canvas) {\n throw new Error(\"Canvas context is not available\");\n }\n return canvas;\n};\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 fontMgr?: FontMgr;\n}\n\nconst defaultFontMgr = Skia.FontMgr.RefDefault();\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch, fontMgr }, forwardedRef) => {\n const canvasCtx = useValue({ width: 0, height: 0 });\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 <CanvasContext.Provider value={canvasCtx}>\n {children}\n </CanvasContext.Provider>,\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.current.width ||\n height !== canvasCtx.current.height\n ) {\n canvasCtx.current = { width, height };\n }\n const paint = Skia.Paint();\n paint.setAntiAlias(true);\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: vec(width / 2, height / 2),\n fontMgr: fontMgr ?? defaultFontMgr,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n container.depMgr.unsubscribe();\n };\n }, [container]);\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"]}
|
@@ -20,28 +20,6 @@ const debug = function () {
|
|
20
20
|
|
21
21
|
exports.debug = debug;
|
22
22
|
|
23
|
-
// Shallow eq on props (without children)
|
24
|
-
const shallowEq = (p1, p2) => {
|
25
|
-
const keys1 = (0, _typeddash.mapKeys)(p1);
|
26
|
-
const keys2 = (0, _typeddash.mapKeys)(p2);
|
27
|
-
|
28
|
-
if (keys1.length !== keys2.length) {
|
29
|
-
return false;
|
30
|
-
}
|
31
|
-
|
32
|
-
for (const key of keys1) {
|
33
|
-
if (key === "children") {
|
34
|
-
continue;
|
35
|
-
}
|
36
|
-
|
37
|
-
if (p1[key] !== p2[key]) {
|
38
|
-
return false;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
return true;
|
43
|
-
};
|
44
|
-
|
45
23
|
const allChildrenAreMemoized = node => {
|
46
24
|
if (!node.memoizable) {
|
47
25
|
return false;
|
@@ -225,7 +203,7 @@ const skHostConfig = {
|
|
225
203
|
|
226
204
|
prepareUpdate: (instance, type, oldProps, newProps, _rootContainerInstance, _hostContext) => {
|
227
205
|
debug("prepareUpdate");
|
228
|
-
const propsAreEqual = shallowEq(oldProps, newProps);
|
206
|
+
const propsAreEqual = (0, _typeddash.shallowEq)(oldProps, newProps);
|
229
207
|
|
230
208
|
if (propsAreEqual && !instance.memoizable) {
|
231
209
|
return null;
|
@@ -238,7 +216,7 @@ const skHostConfig = {
|
|
238
216
|
commitUpdate(instance, _updatePayload, type, prevProps, nextProps, _internalHandle) {
|
239
217
|
debug("commitUpdate: ", type);
|
240
218
|
|
241
|
-
if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {
|
219
|
+
if ((0, _typeddash.shallowEq)(prevProps, nextProps) && allChildrenAreMemoized(instance)) {
|
242
220
|
return;
|
243
221
|
}
|
244
222
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","shallowEq","p1","p2","keys1","keys2","length","key","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unSubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","DrawingNode","Declaration","onDeclare","DeclarationNode","skHostConfig","now","performance","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP;AACA,MAAMC,SAAS,GAAG,CAAkBC,EAAlB,EAAyBC,EAAzB,KAA4C;AAC5D,QAAMC,KAAK,GAAG,wBAAQF,EAAR,CAAd;AACA,QAAMG,KAAK,GAAG,wBAAQF,EAAR,CAAd;;AACA,MAAIC,KAAK,CAACE,MAAN,KAAiBD,KAAK,CAACC,MAA3B,EAAmC;AACjC,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,GAAX,IAAkBH,KAAlB,EAAyB;AACvB,QAAIG,GAAG,KAAK,UAAZ,EAAwB;AACtB;AACD;;AACD,QAAIL,EAAE,CAACK,GAAD,CAAF,KAAYJ,EAAE,CAACI,GAAD,CAAlB,EAAyB;AACvB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAA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;AAC7BjC,IAAAA,KAAK,CAAC,gBAAD,CAAL;AACAiC,IAAAA,SAAS,CAACnB,QAAV,CAAmBW,MAAnB,CAA0B,CAA1B;AACD,GAlJyC;AAoJ1CuE,EAAAA,kBAAkB,EAAE,MAAM;AACxBhG,IAAAA,KAAK,CAAC,oBAAD,CAAL;AACD,GAtJyC;AAwJ1CiG,EAAAA,WAAW,EAAE,CAAChF,MAAD,EAASJ,KAAT,KAAmB;AAC9BS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA1JyC;AA4J1CqF,EAAAA,wBAAwB,EAAE,CAACjF,MAAD,EAASJ,KAAT,KAAmB;AAC3CS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA9JyC;AAgK1CsF,EAAAA,uBAAuB,EAAE,CAAClF,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AAClDD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD,GAlKyC;AAoK1CD,EAAAA,YAAY,EAAE,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS, performance*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, mapKeys } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\n// Shallow eq on props (without children)\nconst shallowEq = <P extends Props>(p1: P, p2: P): boolean => {\n const keys1 = mapKeys(p1);\n const keys2 = mapKeys(p2);\n if (keys1.length !== keys2.length) {\n return false;\n }\n for (const key of keys1) {\n if (key === \"children\") {\n continue;\n }\n if (p1[key] !== p2[key]) {\n return false;\n }\n }\n return true;\n};\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unSubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: performance.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
1
|
+
{"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unSubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","p1","DrawingNode","Declaration","onDeclare","p2","DeclarationNode","skHostConfig","now","performance","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MAAI,CAACA,IAAI,CAACC,UAAV,EAAsB;AACpB,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACG,QAAzB,EAAmC;AACjC,QAAI,CAACD,KAAK,CAACE,QAAX,EAAqB;AACnB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAVD;;AAYA,MAAMC,qBAAqB,GAAIC,MAAD,IAAkB;AAC9C,MAAIA,MAAM,CAACL,UAAX,EAAu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J,KAAT,KAAmB;AAC3CS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA9JyC;AAgK1CwF,EAAAA,uBAAuB,EAAE,CAACpF,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AAClDD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD,GAlKyC;AAoK1CD,EAAAA,YAAY,EAAE,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS, performance*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unSubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: performance.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Drawing = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
|
10
|
+
var _Drawing = require("../nodes/Drawing");
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
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); }
|
15
|
+
|
16
|
+
const onDraw = (0, _Drawing.createDrawing)((ctx, _ref) => {
|
17
|
+
let {
|
18
|
+
drawing
|
19
|
+
} = _ref;
|
20
|
+
drawing(ctx);
|
21
|
+
});
|
22
|
+
|
23
|
+
const Drawing = props => {
|
24
|
+
return /*#__PURE__*/_react.default.createElement("skDrawing", _extends({
|
25
|
+
onDraw: onDraw,
|
26
|
+
skipProcessing: true
|
27
|
+
}, props));
|
28
|
+
};
|
29
|
+
|
30
|
+
exports.Drawing = Drawing;
|
31
|
+
//# sourceMappingURL=Drawing.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["Drawing.tsx"],"names":["onDraw","ctx","drawing","Drawing","props"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;AAMA,MAAMA,MAAM,GAAG,4BAA4B,CAACC,GAAD,WAAsB;AAAA,MAAhB;AAAEC,IAAAA;AAAF,GAAgB;AAC/DA,EAAAA,OAAO,CAACD,GAAD,CAAP;AACD,CAFc,CAAf;;AAIO,MAAME,OAAO,GAAIC,KAAD,IAAyB;AAC9C,sBAAO;AAAW,IAAA,MAAM,EAAEJ,MAAnB;AAA2B,IAAA,cAAc;AAAzC,KAA8CI,KAA9C,EAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport { createDrawing } from \"../nodes/Drawing\";\n\ninterface DrawingProps {\n drawing: (ctx: DrawingContext) => void;\n}\n\nconst onDraw = createDrawing<DrawingProps>((ctx, { drawing }) => {\n drawing(ctx);\n});\n\nexport const Drawing = (props: DrawingProps) => {\n return <skDrawing onDraw={onDraw} skipProcessing {...props} />;\n};\n"]}
|
@@ -34,7 +34,7 @@ const onDraw = (0, _nodes.createDrawing)((ctx, _ref, node) => {
|
|
34
34
|
(0, _processors.processPaint)(paint, opacity, groupProps);
|
35
35
|
const hasTransform = !!groupProps.transform || !!groupProps.matrix;
|
36
36
|
const hasClip = !!clip;
|
37
|
-
const shouldSave = hasTransform || hasClip;
|
37
|
+
const shouldSave = hasTransform || hasClip || !!layer;
|
38
38
|
|
39
39
|
if (shouldSave) {
|
40
40
|
if (layer) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","paint","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAYA;;;;;;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;AAAV,MAAsBP,GAA5B;AACA,QAAMQ,KAAK,GAAG,6BAAYR,GAAG,CAACQ,KAAhB,EAAuBH,UAAvB,CAAd;AACA,gCAAaG,KAAb,EAAoBD,OAApB,EAA6BF,UAA7B;AACA,QAAMI,YAAY,GAAG,CAAC,CAACJ,UAAU,CAACK,SAAb,IAA0B,CAAC,CAACL,UAAU,CAACM,MAA5D;AACA,QAAMC,OAAO,GAAG,CAAC,CAACT,IAAlB;AACA,QAAMU,UAAU,GAAGJ,YAAY,IAAIG,
|
1
|
+
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","paint","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAYA;;;;;;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,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1C,GAAoDA;AAHpD,GAAX;;AAKA,MAAIM,UAAJ,EAAgB;AACdP,IAAAA,MAAM,CAACiB,OAAP;AACD;AACF,CAlCY,CAAf;;AAqCO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAW,IAAA,MAAM,EAAE1B;AAAnB,KAA+B0B,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\";\nimport { ClipOp } from \"../../skia\";\nimport {\n processTransform,\n selectPaint,\n processPaint,\n processClip,\n} from \"../processors\";\nimport type {\n CustomPaintProps,\n TransformProps,\n AnimatedProps,\n ClipDef,\n} from \"../processors\";\nimport { createDrawing } from \"../nodes\";\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 } = ctx;\n const paint = selectPaint(ctx.paint, groupProps);\n processPaint(paint, opacity, groupProps);\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 processTransform(ctx, groupProps);\n if (clip) {\n const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;\n processClip(canvas, clip, op);\n }\n }\n node.visit({\n ...ctx,\n paint,\n opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,\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"]}
|