@shopify/react-native-skia 0.1.116 → 0.1.120

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. package/cpp/api/JsiSkApi.h +13 -9
  2. package/cpp/api/JsiSkCanvas.h +9 -1
  3. package/cpp/api/JsiSkPicture.h +71 -0
  4. package/cpp/api/JsiSkPictureFactory.h +50 -0
  5. package/cpp/api/JsiSkPictureRecorder.h +53 -0
  6. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +3 -6
  7. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +2 -4
  8. package/ios/RNSkia-iOS/SkiaDrawView.mm +3 -2
  9. package/lib/commonjs/renderer/Canvas.js +22 -36
  10. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  11. package/lib/commonjs/renderer/HostConfig.js +3 -25
  12. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  13. package/lib/commonjs/renderer/components/{Defs.js → Drawing.js} +13 -12
  14. package/lib/commonjs/renderer/components/Drawing.js.map +1 -0
  15. package/lib/commonjs/renderer/components/Group.js +7 -4
  16. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  17. package/lib/commonjs/renderer/components/Paint.js +1 -21
  18. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  19. package/lib/commonjs/renderer/components/Picture.js +35 -0
  20. package/lib/commonjs/renderer/components/Picture.js.map +1 -0
  21. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +5 -34
  22. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  23. package/lib/commonjs/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +19 -8
  24. package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -0
  25. package/lib/commonjs/renderer/components/imageFilters/index.js +4 -17
  26. package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
  27. package/lib/commonjs/renderer/components/index.js +17 -4
  28. package/lib/commonjs/renderer/components/index.js.map +1 -1
  29. package/lib/commonjs/renderer/components/maskFilters/Blur.js +1 -1
  30. package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
  31. package/lib/commonjs/renderer/components/shapes/Box.js +126 -0
  32. package/lib/commonjs/renderer/components/shapes/Box.js.map +1 -0
  33. package/lib/commonjs/renderer/components/shapes/index.js +13 -0
  34. package/lib/commonjs/renderer/components/shapes/index.js.map +1 -1
  35. package/lib/commonjs/renderer/index.js +13 -0
  36. package/lib/commonjs/renderer/index.js.map +1 -1
  37. package/lib/commonjs/renderer/nodes/Declaration.js +12 -1
  38. package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
  39. package/lib/commonjs/renderer/nodes/Drawing.js +9 -24
  40. package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
  41. package/lib/commonjs/renderer/nodes/Node.js +9 -16
  42. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  43. package/lib/commonjs/renderer/processors/Paint.js +24 -26
  44. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  45. package/lib/commonjs/renderer/processors/math/Math.js +19 -1
  46. package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
  47. package/lib/commonjs/renderer/processors/math/Matrix3.js +11 -5
  48. package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
  49. package/lib/commonjs/renderer/typeddash.js +26 -2
  50. package/lib/commonjs/renderer/typeddash.js.map +1 -1
  51. package/lib/commonjs/renderer/useContextBridge.js +35 -0
  52. package/lib/commonjs/renderer/useContextBridge.js.map +1 -0
  53. package/lib/commonjs/skia/Canvas.js.map +1 -1
  54. package/lib/commonjs/skia/Picture/Picture.js +6 -0
  55. package/lib/commonjs/skia/Picture/Picture.js.map +1 -0
  56. package/lib/commonjs/skia/Picture/PictureFactory.js +6 -0
  57. package/lib/commonjs/skia/Picture/PictureFactory.js.map +1 -0
  58. package/lib/commonjs/skia/Picture/PictureRecorder.js +6 -0
  59. package/lib/commonjs/skia/Picture/PictureRecorder.js.map +1 -0
  60. package/lib/commonjs/skia/Picture/index.js +58 -0
  61. package/lib/commonjs/skia/Picture/index.js.map +1 -0
  62. package/lib/commonjs/skia/Picture/usePicture.js +30 -0
  63. package/lib/commonjs/skia/Picture/usePicture.js.map +1 -0
  64. package/lib/commonjs/skia/Skia.js +2 -0
  65. package/lib/commonjs/skia/Skia.js.map +1 -1
  66. package/lib/commonjs/skia/index.js +14 -0
  67. package/lib/commonjs/skia/index.js.map +1 -1
  68. package/lib/commonjs/values/hooks/useDerivedValue.js +2 -2
  69. package/lib/commonjs/values/hooks/useDerivedValue.js.map +1 -1
  70. package/lib/commonjs/views/SkiaView.js +6 -5
  71. package/lib/commonjs/views/SkiaView.js.map +1 -1
  72. package/lib/commonjs/views/types.js.map +1 -1
  73. package/lib/module/renderer/Canvas.js +20 -32
  74. package/lib/module/renderer/Canvas.js.map +1 -1
  75. package/lib/module/renderer/HostConfig.js +2 -24
  76. package/lib/module/renderer/HostConfig.js.map +1 -1
  77. package/lib/module/renderer/components/Drawing.js +17 -0
  78. package/lib/module/renderer/components/Drawing.js.map +1 -0
  79. package/lib/module/renderer/components/Group.js +8 -6
  80. package/lib/module/renderer/components/Group.js.map +1 -1
  81. package/lib/module/renderer/components/Paint.js +2 -22
  82. package/lib/module/renderer/components/Paint.js.map +1 -1
  83. package/lib/module/renderer/components/Picture.js +21 -0
  84. package/lib/module/renderer/components/Picture.js.map +1 -0
  85. package/lib/module/renderer/components/imageFilters/InnerShadow.js +4 -26
  86. package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  87. package/lib/module/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +16 -6
  88. package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -0
  89. package/lib/module/renderer/components/imageFilters/index.js +1 -2
  90. package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
  91. package/lib/module/renderer/components/index.js +2 -1
  92. package/lib/module/renderer/components/index.js.map +1 -1
  93. package/lib/module/renderer/components/maskFilters/Blur.js +1 -1
  94. package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
  95. package/lib/module/renderer/components/shapes/Box.js +102 -0
  96. package/lib/module/renderer/components/shapes/Box.js.map +1 -0
  97. package/lib/module/renderer/components/shapes/index.js +1 -0
  98. package/lib/module/renderer/components/shapes/index.js.map +1 -1
  99. package/lib/module/renderer/index.js +1 -0
  100. package/lib/module/renderer/index.js.map +1 -1
  101. package/lib/module/renderer/nodes/Declaration.js +4 -0
  102. package/lib/module/renderer/nodes/Declaration.js.map +1 -1
  103. package/lib/module/renderer/nodes/Drawing.js +8 -21
  104. package/lib/module/renderer/nodes/Drawing.js.map +1 -1
  105. package/lib/module/renderer/nodes/Node.js +9 -15
  106. package/lib/module/renderer/nodes/Node.js.map +1 -1
  107. package/lib/module/renderer/processors/Paint.js +22 -21
  108. package/lib/module/renderer/processors/Paint.js.map +1 -1
  109. package/lib/module/renderer/processors/math/Math.js +15 -0
  110. package/lib/module/renderer/processors/math/Math.js.map +1 -1
  111. package/lib/module/renderer/processors/math/Matrix3.js +6 -2
  112. package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
  113. package/lib/module/renderer/typeddash.js +21 -0
  114. package/lib/module/renderer/typeddash.js.map +1 -1
  115. package/lib/module/renderer/useContextBridge.js +21 -0
  116. package/lib/module/renderer/useContextBridge.js.map +1 -0
  117. package/lib/module/skia/Canvas.js.map +1 -1
  118. package/lib/module/skia/Picture/Picture.js +2 -0
  119. package/lib/module/skia/Picture/Picture.js.map +1 -0
  120. package/lib/module/skia/Picture/PictureFactory.js +2 -0
  121. package/lib/module/skia/Picture/PictureFactory.js.map +1 -0
  122. package/lib/module/skia/Picture/PictureRecorder.js +2 -0
  123. package/lib/module/skia/Picture/PictureRecorder.js.map +1 -0
  124. package/lib/module/skia/Picture/index.js +5 -0
  125. package/lib/module/skia/Picture/index.js.map +1 -0
  126. package/lib/module/skia/Picture/usePicture.js +19 -0
  127. package/lib/module/skia/Picture/usePicture.js.map +1 -0
  128. package/lib/module/skia/Skia.js +2 -0
  129. package/lib/module/skia/Skia.js.map +1 -1
  130. package/lib/module/skia/index.js +1 -0
  131. package/lib/module/skia/index.js.map +1 -1
  132. package/lib/module/values/hooks/useDerivedValue.js +1 -1
  133. package/lib/module/values/hooks/useDerivedValue.js.map +1 -1
  134. package/lib/module/views/SkiaView.js +6 -5
  135. package/lib/module/views/SkiaView.js.map +1 -1
  136. package/lib/module/views/types.js.map +1 -1
  137. package/lib/typescript/src/renderer/Canvas.d.ts +5 -10
  138. package/lib/typescript/src/renderer/components/Drawing.d.ts +7 -0
  139. package/lib/typescript/src/renderer/components/Picture.d.ts +6 -0
  140. package/lib/typescript/src/renderer/components/imageFilters/InnerShadow.d.ts +3 -12
  141. package/lib/typescript/src/renderer/components/imageFilters/{DropShadow.d.ts → Shadow.d.ts} +3 -2
  142. package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -2
  143. package/lib/typescript/src/renderer/components/index.d.ts +2 -1
  144. package/lib/typescript/src/renderer/components/shapes/Box.d.ts +23 -0
  145. package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
  146. package/lib/typescript/src/renderer/index.d.ts +1 -0
  147. package/lib/typescript/src/renderer/nodes/Declaration.d.ts +3 -0
  148. package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
  149. package/lib/typescript/src/renderer/nodes/Node.d.ts +2 -2
  150. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -2
  151. package/lib/typescript/src/renderer/processors/math/Math.d.ts +14 -0
  152. package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -0
  153. package/lib/typescript/src/renderer/typeddash.d.ts +1 -0
  154. package/lib/typescript/src/renderer/useContextBridge.d.ts +5 -0
  155. package/lib/typescript/src/skia/Canvas.d.ts +6 -0
  156. package/lib/typescript/src/skia/Picture/Picture.d.ts +26 -0
  157. package/lib/typescript/src/skia/Picture/PictureFactory.d.ts +8 -0
  158. package/lib/typescript/src/skia/Picture/PictureRecorder.d.ts +15 -0
  159. package/lib/typescript/src/skia/Picture/index.d.ts +4 -0
  160. package/lib/typescript/src/skia/Picture/usePicture.d.ts +11 -0
  161. package/lib/typescript/src/skia/Skia.d.ts +5 -0
  162. package/lib/typescript/src/skia/index.d.ts +1 -0
  163. package/lib/typescript/src/views/SkiaView.d.ts +25 -1
  164. package/lib/typescript/src/views/types.d.ts +0 -24
  165. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  166. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  167. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  168. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  169. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  170. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  171. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  172. package/package.json +1 -1
  173. package/src/renderer/Canvas.tsx +14 -30
  174. package/src/renderer/HostConfig.ts +2 -20
  175. package/src/renderer/components/Drawing.tsx +16 -0
  176. package/src/renderer/components/Group.tsx +25 -15
  177. package/src/renderer/components/Paint.tsx +5 -35
  178. package/src/renderer/components/Picture.tsx +17 -0
  179. package/src/renderer/components/imageFilters/InnerShadow.tsx +33 -47
  180. package/src/renderer/components/imageFilters/Shadow.tsx +39 -0
  181. package/src/renderer/components/imageFilters/index.ts +1 -2
  182. package/src/renderer/components/index.ts +2 -1
  183. package/src/renderer/components/maskFilters/Blur.tsx +1 -1
  184. package/src/renderer/components/shapes/Box.tsx +98 -0
  185. package/src/renderer/components/shapes/index.ts +1 -0
  186. package/src/renderer/index.ts +1 -0
  187. package/src/renderer/nodes/Declaration.tsx +14 -0
  188. package/src/renderer/nodes/Drawing.tsx +16 -26
  189. package/src/renderer/nodes/Node.ts +9 -12
  190. package/src/renderer/processors/Paint.ts +34 -31
  191. package/src/renderer/processors/math/Math.ts +16 -0
  192. package/src/renderer/processors/math/Matrix3.ts +35 -31
  193. package/src/renderer/typeddash.ts +18 -0
  194. package/src/renderer/useContextBridge.tsx +21 -0
  195. package/src/skia/Canvas.ts +7 -0
  196. package/src/skia/Picture/Picture.ts +34 -0
  197. package/src/skia/Picture/PictureFactory.ts +9 -0
  198. package/src/skia/Picture/PictureRecorder.ts +18 -0
  199. package/src/skia/Picture/index.ts +4 -0
  200. package/src/skia/Picture/usePicture.ts +28 -0
  201. package/src/skia/Skia.ts +5 -0
  202. package/src/skia/index.ts +1 -0
  203. package/src/values/hooks/useDerivedValue.ts +1 -1
  204. package/src/views/SkiaView.tsx +27 -3
  205. package/src/views/types.ts +0 -25
  206. package/lib/commonjs/renderer/components/Defs.js.map +0 -1
  207. package/lib/commonjs/renderer/components/imageFilters/DropShadow.js.map +0 -1
  208. package/lib/module/renderer/components/Defs.js +0 -16
  209. package/lib/module/renderer/components/Defs.js.map +0 -1
  210. package/lib/module/renderer/components/imageFilters/DropShadow.js.map +0 -1
  211. package/lib/typescript/src/renderer/components/Defs.d.ts +0 -5
  212. package/src/renderer/components/Defs.tsx +0 -19
  213. package/src/renderer/components/imageFilters/DropShadow.tsx +0 -31
@@ -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
- installFunction("Font", JsiSkFont::createCtor(context));
59
- installFunction("Paint", JsiSkPaint::createCtor(context));
60
- installFunction("RSXform", JsiSkRSXform::createCtor(context));
61
- installFunction("Matrix", JsiSkMatrix::createCtor(context));
62
- installFunction("XYWHRect", JsiSkRect::createCtor(context));
63
- installFunction("RRectXY", JsiSkRRect::createCtor(context));
64
- installFunction("Point", JsiSkPoint::createCtor(context));
65
- installFunction("ContourMeasureIter", JsiSkContourMeasureIter::createCtor(context));
66
- installFunction("MakeVertices", JsiSkVertices::createCtor(context));
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
@@ -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
@@ -18,14 +18,13 @@
18
18
 
19
19
  #pragma clang diagnostic pop
20
20
 
21
- @class SkiaDrawView;
22
-
23
21
  class RNSkDrawViewImpl : public RNSkia::RNSkDrawView {
24
22
  public:
25
- RNSkDrawViewImpl(SkiaDrawView *view,
26
- std::shared_ptr<RNSkia::RNSkPlatformContext> context);
23
+ RNSkDrawViewImpl(std::shared_ptr<RNSkia::RNSkPlatformContext> context);
27
24
 
28
25
  void setSize(int width, int height);
26
+
27
+ CALayer* getLayer() { return _layer; };
29
28
 
30
29
  protected:
31
30
  int getWidth() override { return _width * _context->getPixelDensity(); };
@@ -42,8 +41,6 @@ private:
42
41
  int _width = -1;
43
42
  int _height = -1;
44
43
 
45
- SkiaDrawView *_view;
46
-
47
44
  #pragma clang diagnostic push
48
45
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
49
46
  CAMetalLayer *_layer;
@@ -17,8 +17,8 @@ id<MTLCommandQueue> RNSkDrawViewImpl::_commandQueue = id<MTLCommandQueue>(CFReta
17
17
 
18
18
  sk_sp<GrDirectContext> RNSkDrawViewImpl::_skContext = nullptr;
19
19
 
20
- RNSkDrawViewImpl::RNSkDrawViewImpl(SkiaDrawView* view, std::shared_ptr<RNSkia::RNSkPlatformContext> context):
21
- _view(view), _context(context), RNSkia::RNSkDrawView(context) {
20
+ RNSkDrawViewImpl::RNSkDrawViewImpl(std::shared_ptr<RNSkia::RNSkPlatformContext> context):
21
+ _context(context), RNSkia::RNSkDrawView(context) {
22
22
 
23
23
  #pragma clang diagnostic push
24
24
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
@@ -30,8 +30,6 @@ RNSkDrawViewImpl::RNSkDrawViewImpl(SkiaDrawView* view, std::shared_ptr<RNSkia::R
30
30
  _layer.opaque = false;
31
31
  _layer.contentsScale = _context->getPixelDensity();
32
32
  _layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
33
- _layer.frame = _view.bounds;
34
- [_view.layer addSublayer:_layer];
35
33
 
36
34
  setNativeDrawFunc(std::bind(&RNSkDrawViewImpl::drawFrame, this, std::placeholders::_1));
37
35
  }
@@ -56,13 +56,14 @@
56
56
  if(_nativeId != 0 && _manager != nullptr) {
57
57
  _manager->setSkiaDrawView(_nativeId, nullptr);
58
58
  }
59
+ [_impl->getLayer() removeFromSuperlayer];
59
60
  _impl = nullptr;
60
61
  }
61
62
  } else {
62
63
  // Create implementation view when the parent view is set
63
64
  if(_impl == nullptr && _manager != nullptr) {
64
- __weak decltype(self) weakSelf = self;
65
- _impl = std::make_shared<RNSkDrawViewImpl>(weakSelf, _manager->getPlatformContext());
65
+ _impl = std::make_shared<RNSkDrawViewImpl>(_manager->getPlatformContext());
66
+ [self.layer addSublayer:_impl->getLayer()];
66
67
  if(_nativeId != 0) {
67
68
  _manager->setSkiaDrawView(_nativeId, _impl.get());
68
69
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useContextBridge = exports.useCanvasRef = exports.useCanvas = exports.skiaReconciler = exports.Canvas = void 0;
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 useCanvas = () => {
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.useCanvas = useCanvas;
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)((_ref2, forwardedRef) => {
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
- } = _ref2;
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.current
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 _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
167
- refs[_key2] = arguments[_key2];
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":["useContextBridge","contexts","values","map","context","children","reduceRight","acc","Context","i","CanvasContext","React","createContext","useCanvas","canvas","Error","skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","defaultFontMgr","Skia","FontMgr","RefDefault","Canvas","forwardedRef","style","debug","mode","onTouch","fontMgr","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","Container","DependencyManager","canvasCtx","width","height","createContainer","current","onDraw","info","timestamp","touches","paint","Paint","setAntiAlias","ctx","opacity","center","draw","unsubscribe","refs","targetRef","useRef","useEffect","forEach"],"mappings":";;;;;;;AAAA;;AAmBA;;AAEA;;AAEA;;AAGA;;AAEA;;AACA;;AACA;;;;;;;;AAHA;AAKA;AACA;AACO,MAAMA,gBAAgB,GAAG,YAAiC;AAAA,oCAA7BC,QAA6B;AAA7BA,IAAAA,QAA6B;AAAA;;AAC/D,QAAMC,MAAM,GACV;AACAD,EAAAA,QAAQ,CAACE,GAAT,CAAcC,OAAD,IAAa,uBAAWA,OAAX,CAA1B,CAFF;AAGA,SAAO,oBACL,MACE;AAAA,QAAC;AAAEC,MAAAA;AAAF,KAAD;AAAA,WACEJ,QAAQ,CAACK,WAAT,CACE,CAACC,GAAD,EAAMC,OAAN,EAAeC,CAAf,kBACE,6BAAC,OAAD,CAAS,QAAT;AAAkB,MAAA,KAAK,EAAEP,MAAM,CAACO,CAAD,CAA/B;AAAoC,MAAA,QAAQ,EAAEF;AAA9C,MAFJ,EAIEF,QAJF,CADF;AAAA,GAFG,EASL,CAACJ,QAAD,EAAWC,MAAX,CATK,CAAP;AAWD,CAfM;;;;AAsBP,MAAMQ,aAAa,gBAAGC,eAAMC,aAAN,CAA0C,IAA1C,CAAtB;;AAEO,MAAMC,SAAS,GAAG,MAAM;AAC7B,QAAMC,MAAM,GAAG,uBAAWJ,aAAX,CAAf;;AACA,MAAI,CAACI,MAAL,EAAa;AACX,UAAM,IAAIC,KAAJ,CAAU,iCAAV,CAAN;AACD;;AACD,SAAOD,MAAP;AACD,CANM;;;AAQA,MAAME,cAAc,GAAG,8BAAgBC,wBAAhB,CAAvB;;AAEPD,cAAc,CAACE,kBAAf,CAAkC;AAChCC,EAAAA,UAAU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EAuBb,CAAClB,IAAD,EAAOL,OAAP,CAvBa,CAAf;AA0BA,wBAAU,MAAM;AACd,WAAO,MAAM;AACXd,MAAAA,SAAS,CAACE,MAAV,CAAiBuC,WAAjB;AACD,KAFD;AAGD,GAJD,EAIG,CAACzC,SAAD,CAJH;AAMA,sBACE,6BAAC,eAAD;AACE,IAAA,GAAG,EAAEiB,GADP;AAEE,IAAA,KAAK,EAAEN,KAFT;AAGE,IAAA,MAAM,EAAEmB,MAHV;AAIE,IAAA,IAAI,EAAEjB,IAJR;AAKE,IAAA,KAAK,EAAED;AALT,IADF;AASD,CAtEmB,CAAf;AAyEP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMM,eAAe,GAAG,YAEnB;AAAA,qCADAwB,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAGzD,eAAM0D,MAAN,CAAgB,IAAhB,CAAlB;;AACA1D,iBAAM2D,SAAN,CAAgB,MAAM;AACpBH,IAAAA,IAAI,CAACI,OAAL,CAAc7B,GAAD,IAAS;AACpB,UAAIA,GAAJ,EAAS;AACP,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAAC0B,SAAS,CAACd,OAAX,CAAH;AACD,SAFD,MAEO;AACLZ,UAAAA,GAAG,CAACY,OAAJ,GAAcc,SAAS,CAACd,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACa,IAAD,CAVH;;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n useContext,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n Context,\n ReactElement,\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\";\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\n// useContextBridge() is taken from https://github.com/pmndrs/drei#usecontextbridge\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useContextBridge = (...contexts: Context<any>[]) => {\n const values =\n // eslint-disable-next-line react-hooks/rules-of-hooks\n contexts.map((context) => useContext(context));\n return useMemo(\n () =>\n ({ children }: { children: ReactNode }) =>\n contexts.reduceRight(\n (acc, Context, i) => (\n <Context.Provider value={values[i]} children={acc} />\n ),\n children\n ) as ReactElement,\n [contexts, values]\n );\n};\n\ninterface CanvasContext {\n width: number;\n height: number;\n}\n\nconst CanvasContext = React.createContext<CanvasContext | null>(null);\n\nexport const useCanvas = () => {\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 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 canvasCtx = useRef({ width: 0, height: 0 });\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.current}>\n {children}\n </CanvasContext.Provider>,\n root,\n container\n );\n }, [children, root, redraw, container]);\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 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 canvasCtx.current = ctx;\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"]}
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;;;AAQA,MAAME,cAAc,GAAG,8BAAgBC,wBAAhB,CAAvB;;AAEPD,cAAc,CAACE,kBAAf,CAAkC;AAChCC,EAAAA,UAAU,EAAE,CADoB;AAEhCC,EAAAA,OAAO,EAAE,OAFuB;AAGhCC,EAAAA,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;AAC7ET,EAAAA,cAAc,CAACU,eAAf,CAA+BH,OAA/B,EAAwCC,IAAxC,EAA8C,IAA9C,EAAoD,MAAM;AACxD,2BAAU,iBAAV;AAEAC,IAAAA,SAAS,CAACE,MAAV,CAAiBC,SAAjB;AACD,GAJD;AAKD,CAND;;AAQO,MAAMC,YAAY,GAAG,MAAM,mBAAiB,IAAjB,CAA3B;;;;AASP,MAAMC,cAAc,GAAGC,WAAKC,OAAL,CAAaC,UAAb,EAAvB;;AAEO,MAAMC,MAAM,gBAAG,uBACpB,OAAqDC,YAArD,KAAsE;AAAA,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;AASD,CA3EmB,CAAf;AA8EP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMS,eAAe,GAAG,YAEnB;AAAA,oCADAqB,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAG1D,eAAM2D,MAAN,CAAgB,IAAhB,CAAlB;;AACA3D,iBAAM4D,SAAN,CAAgB,MAAM;AACpBH,IAAAA,IAAI,CAACI,OAAL,CAAc1B,GAAD,IAAS;AACpB,UAAIA,GAAJ,EAAS;AACP,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAACuB,SAAS,CAACV,OAAX,CAAH;AACD,SAFD,MAEO;AACLb,UAAAA,GAAG,CAACa,OAAJ,GAAcU,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 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;
@@ -61,7 +39,7 @@ const bustBranchMemoization = parent => {
61
39
  let ancestor = parent;
62
40
 
63
41
  while (ancestor) {
64
- ancestor.memoized = false;
42
+ ancestor.memoized = null;
65
43
  ancestor = ancestor.parent;
66
44
  }
67
45
  }
@@ -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,I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BiB,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":";;;;;;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A,gBAAgB,EAAE,CAChBC,aADgB,EAEhBC,QAFgB,EAGhBC,QAHgB,KAIb,CACH;AACD,GA7IyC;AA+I1CC,EAAAA,cAAc,EAAGhE,SAAD,IAAe;AAC7B1B,IAAAA,KAAK,CAAC,gBAAD,CAAL;AACA0B,IAAAA,SAAS,CAACnB,QAAV,CAAmBW,MAAnB,CAA0B,CAA1B;AACD,GAlJyC;AAoJ1CyE,EAAAA,kBAAkB,EAAE,MAAM;AACxB3F,IAAAA,KAAK,CAAC,oBAAD,CAAL;AACD,GAtJyC;AAwJ1C4F,EAAAA,WAAW,EAAE,CAAClF,MAAD,EAASJ,KAAT,KAAmB;AAC9BS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA1JyC;AA4J1CuF,EAAAA,wBAAwB,EAAE,CAACnF,MAAD,EAASJ,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 = null;\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"]}