@shopify/react-native-skia 0.1.176 → 0.1.180

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. package/android/CMakeLists.txt +2 -0
  2. package/cpp/jsi/JsiHostObject.cpp +13 -7
  3. package/cpp/jsi/JsiHostObject.h +3 -1
  4. package/cpp/jsi/RuntimeAwareCache.cpp +9 -0
  5. package/cpp/jsi/RuntimeAwareCache.h +101 -0
  6. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +57 -0
  7. package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
  8. package/cpp/rnskia/RNSkManager.cpp +4 -0
  9. package/cpp/rnskia/RNSkView.h +5 -3
  10. package/cpp/rnskia/dom/base/JsiDomNode.h +22 -2
  11. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +10 -9
  12. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +10 -2
  13. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  14. package/lib/commonjs/external/reanimated/index.d.ts +1 -0
  15. package/lib/commonjs/external/reanimated/index.js +13 -0
  16. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  17. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +8 -0
  18. package/lib/commonjs/external/reanimated/moduleWrapper.js +68 -0
  19. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -0
  20. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +5 -0
  21. package/lib/commonjs/external/reanimated/renderHelpers.js +81 -0
  22. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -0
  23. package/lib/commonjs/external/reanimated/useSharedValueEffect.d.ts +2 -5
  24. package/lib/commonjs/external/reanimated/useSharedValueEffect.js +10 -25
  25. package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +1 -1
  26. package/lib/commonjs/headless/index.d.ts +3 -0
  27. package/lib/commonjs/headless/index.js +57 -0
  28. package/lib/commonjs/headless/index.js.map +1 -0
  29. package/lib/commonjs/mock/index.d.ts +1 -2
  30. package/lib/commonjs/mock/index.js +0 -4
  31. package/lib/commonjs/mock/index.js.map +1 -1
  32. package/lib/commonjs/renderer/Canvas.js +7 -1
  33. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  34. package/lib/commonjs/renderer/Container.d.ts +2 -1
  35. package/lib/commonjs/renderer/Container.js +2 -0
  36. package/lib/commonjs/renderer/Container.js.map +1 -1
  37. package/lib/commonjs/renderer/HostConfig.js +6 -4
  38. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  39. package/lib/commonjs/renderer/Reconciler.d.ts +1 -1
  40. package/lib/commonjs/renderer/Reconciler.js +2 -1
  41. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  42. package/lib/commonjs/renderer/processors/Animations/Animations.d.ts +4 -1
  43. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  44. package/lib/module/dom/nodes/paint/ImageFilters.js +10 -2
  45. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  46. package/lib/module/external/reanimated/index.d.ts +1 -0
  47. package/lib/module/external/reanimated/index.js +1 -0
  48. package/lib/module/external/reanimated/index.js.map +1 -1
  49. package/lib/module/external/reanimated/moduleWrapper.d.ts +8 -0
  50. package/lib/module/external/reanimated/moduleWrapper.js +50 -0
  51. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -0
  52. package/lib/module/external/reanimated/renderHelpers.d.ts +5 -0
  53. package/lib/module/external/reanimated/renderHelpers.js +72 -0
  54. package/lib/module/external/reanimated/renderHelpers.js.map +1 -0
  55. package/lib/module/external/reanimated/useSharedValueEffect.d.ts +2 -5
  56. package/lib/module/external/reanimated/useSharedValueEffect.js +7 -22
  57. package/lib/module/external/reanimated/useSharedValueEffect.js.map +1 -1
  58. package/lib/module/headless/index.d.ts +3 -0
  59. package/lib/module/headless/index.js +29 -0
  60. package/lib/module/headless/index.js.map +1 -0
  61. package/lib/module/mock/index.d.ts +1 -2
  62. package/lib/module/mock/index.js +0 -3
  63. package/lib/module/mock/index.js.map +1 -1
  64. package/lib/module/renderer/Canvas.js +7 -1
  65. package/lib/module/renderer/Canvas.js.map +1 -1
  66. package/lib/module/renderer/Container.d.ts +2 -1
  67. package/lib/module/renderer/Container.js +2 -0
  68. package/lib/module/renderer/Container.js.map +1 -1
  69. package/lib/module/renderer/HostConfig.js +5 -4
  70. package/lib/module/renderer/HostConfig.js.map +1 -1
  71. package/lib/module/renderer/Reconciler.d.ts +1 -1
  72. package/lib/module/renderer/Reconciler.js +2 -1
  73. package/lib/module/renderer/Reconciler.js.map +1 -1
  74. package/lib/module/renderer/processors/Animations/Animations.d.ts +4 -1
  75. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  76. package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
  77. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +8 -0
  78. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +5 -0
  79. package/lib/typescript/src/external/reanimated/useSharedValueEffect.d.ts +2 -5
  80. package/lib/typescript/src/headless/index.d.ts +3 -0
  81. package/lib/typescript/src/mock/index.d.ts +1 -2
  82. package/lib/typescript/src/renderer/Container.d.ts +2 -1
  83. package/lib/typescript/src/renderer/Reconciler.d.ts +1 -1
  84. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +4 -1
  85. package/package.json +1 -1
  86. package/src/dom/nodes/paint/ImageFilters.ts +8 -2
  87. package/src/external/reanimated/index.ts +1 -0
  88. package/src/external/reanimated/moduleWrapper.ts +60 -0
  89. package/src/external/reanimated/renderHelpers.ts +70 -0
  90. package/src/external/reanimated/useSharedValueEffect.ts +17 -23
  91. package/src/headless/index.ts +31 -0
  92. package/src/mock/index.ts +0 -5
  93. package/src/renderer/Canvas.tsx +6 -2
  94. package/src/renderer/Container.tsx +2 -1
  95. package/src/renderer/HostConfig.ts +8 -2
  96. package/src/renderer/Reconciler.tsx +3 -2
  97. package/src/renderer/processors/Animations/Animations.ts +9 -1
@@ -49,6 +49,8 @@ add_library(
49
49
 
50
50
  "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp"
51
51
  "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiValue.cpp"
52
+ "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeLifecycleMonitor.cpp"
53
+ "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeAwareCache.cpp"
52
54
 
53
55
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp"
54
56
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkJsView.cpp"
@@ -55,12 +55,18 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
55
55
  const jsi::PropNameID &name) {
56
56
  auto nameStr = name.utf8(runtime);
57
57
 
58
- // Do the happy-paths first
58
+ // Happy path - cached host functions are cheapest to look up
59
+ const JsiFunctionMap &funcs = getExportedFunctionMap();
60
+ auto func = funcs.find(nameStr);
59
61
 
60
62
  // Check function cache
61
- auto cachedFunc = _hostFunctionCache.find(nameStr);
62
- if (cachedFunc != _hostFunctionCache.end()) {
63
- return cachedFunc->second.asFunction(runtime);
63
+ if (func != funcs.end()) {
64
+ std::map<std::string, jsi::Function> &runtimeCache =
65
+ _hostFunctionCache.get(runtime);
66
+ auto cachedFunc = runtimeCache.find(nameStr);
67
+ if (cachedFunc != runtimeCache.end()) {
68
+ return cachedFunc->second.asFunction(runtime);
69
+ }
64
70
  }
65
71
 
66
72
  // Check the static getters map
@@ -72,9 +78,9 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
72
78
  }
73
79
 
74
80
  // Check the static function map
75
- const JsiFunctionMap &funcs = getExportedFunctionMap();
76
- auto func = funcs.find(nameStr);
77
81
  if (func != funcs.end()) {
82
+
83
+ // Create dispatcher
78
84
  auto dispatcher =
79
85
  std::bind(func->second, reinterpret_cast<JsiHostObject *>(this),
80
86
  std::placeholders::_1, std::placeholders::_2,
@@ -82,7 +88,7 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
82
88
 
83
89
  // Add to cache - it is important to cache the results from the
84
90
  // createFromHostFunction function which takes some time.
85
- return _hostFunctionCache
91
+ return _hostFunctionCache.get(runtime)
86
92
  .emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name,
87
93
  0, dispatcher))
88
94
  .first->second.asFunction(runtime);
@@ -9,6 +9,8 @@
9
9
  #include <unordered_map>
10
10
  #include <vector>
11
11
 
12
+ #include "RuntimeAwareCache.h"
13
+
12
14
  #define STR_CAT_NX(A, B) A##B
13
15
  #define STR_CAT(A, B) STR_CAT_NX(A, B)
14
16
  #define STR_GET get_
@@ -363,6 +365,6 @@ private:
363
365
  std::unordered_map<std::string, jsi::HostFunctionType> _funcMap;
364
366
  std::unordered_map<std::string, JsPropertyType> _propMap;
365
367
 
366
- std::map<std::string, jsi::Function> _hostFunctionCache;
368
+ RuntimeAwareCache<std::map<std::string, jsi::Function>> _hostFunctionCache;
367
369
  };
368
370
  } // namespace RNJsi
@@ -0,0 +1,9 @@
1
+ #pragma once
2
+
3
+ #include "RuntimeAwareCache.h"
4
+
5
+ namespace RNJsi {
6
+
7
+ jsi::Runtime *BaseRuntimeAwareCache::_mainRuntime = nullptr;
8
+
9
+ } // namespace RNJsi
@@ -0,0 +1,101 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+
5
+ #include <memory>
6
+ #include <unordered_map>
7
+ #include <utility>
8
+
9
+ #include "RuntimeLifecycleMonitor.h"
10
+
11
+ namespace RNJsi {
12
+
13
+ namespace jsi = facebook::jsi;
14
+
15
+ class BaseRuntimeAwareCache {
16
+ public:
17
+ static void setMainJsRuntime(jsi::Runtime *rt) { _mainRuntime = rt; }
18
+
19
+ protected:
20
+ static jsi::Runtime *getMainJsRuntime() {
21
+ assert(_mainRuntime != nullptr &&
22
+ "Expected main Javascript runtime to be set in the "
23
+ "BaseRuntimeAwareCache class.");
24
+
25
+ return _mainRuntime;
26
+ }
27
+
28
+ private:
29
+ static jsi::Runtime *_mainRuntime;
30
+ };
31
+
32
+ /**
33
+ * Provides a way to keep data specific to a jsi::Runtime instance that gets
34
+ * cleaned up when that runtime is destroyed. This is necessary because JSI does
35
+ * not allow for its associated objects to be retained past the runtime
36
+ * lifetime. If an object (e.g. jsi::Values or jsi::Function instances) is kept
37
+ * after the runtime is torn down, its destructor (once it is destroyed
38
+ * eventually) will result in a crash (JSI objects keep a pointer to memory
39
+ * managed by the runtime, accessing that portion of the memory after runtime is
40
+ * deleted is the root cause of that crash).
41
+ *
42
+ * In order to provide an efficient implementation that does not add an overhead
43
+ * for the cases when only a single runtiome is used, which is the primary
44
+ * usecase, the following assumption has been made: Only for secondary runtimes
45
+ * we track destruction and clean up the store associated with that runtime. For
46
+ * the first runtime we assume that the object holding the store is destroyed
47
+ * prior to the destruction of that runtime.
48
+ *
49
+ * The above assumption makes it work without any overhead when only single
50
+ * runtime is in use. Specifically, we don't perform any additional operations
51
+ * related to tracking runtime lifecycle when only a single runtime is used.
52
+ */
53
+ template <typename T>
54
+ class RuntimeAwareCache : public BaseRuntimeAwareCache,
55
+ public RuntimeLifecycleListener {
56
+
57
+ public:
58
+ void onRuntimeDestroyed(jsi::Runtime *rt) override {
59
+ if (getMainJsRuntime() != rt) {
60
+ // We are removing a secondary runtime
61
+ _secondaryRuntimeCaches.erase(rt);
62
+ }
63
+ }
64
+
65
+ ~RuntimeAwareCache() {
66
+ for (auto &cache : _secondaryRuntimeCaches) {
67
+ RuntimeLifecycleMonitor::removeListener(
68
+ *static_cast<jsi::Runtime *>(cache.first), this);
69
+ }
70
+ }
71
+
72
+ T &get(jsi::Runtime &rt) {
73
+ // We check if we're accessing the main runtime - this is the happy path
74
+ // to avoid us having to lookup by runtime for caches that only has a single
75
+ // runtime
76
+ if (getMainJsRuntime() == &rt) {
77
+ return _primaryCache;
78
+ } else {
79
+ if (_secondaryRuntimeCaches.count(&rt) == 0) {
80
+ // we only add listener when the secondary runtime is used, this assumes
81
+ // that the secondary runtime is terminated first. This lets us avoid
82
+ // additional complexity for the majority of cases when objects are not
83
+ // shared between runtimes. Otherwise we'd have to register all objecrts
84
+ // with the RuntimeMonitor as opposed to only registering ones that are
85
+ // used in secondary runtime. Note that we can't register listener here
86
+ // with the primary runtime as it may run on a separate thread.
87
+ RuntimeLifecycleMonitor::addListener(rt, this);
88
+
89
+ T cache;
90
+ _secondaryRuntimeCaches.emplace(&rt, std::move(cache));
91
+ }
92
+ }
93
+ return _secondaryRuntimeCaches.at(&rt);
94
+ }
95
+
96
+ private:
97
+ std::unordered_map<void *, T> _secondaryRuntimeCaches;
98
+ T _primaryCache;
99
+ };
100
+
101
+ } // namespace RNJsi
@@ -0,0 +1,57 @@
1
+ #include "RuntimeLifecycleMonitor.h"
2
+
3
+ #include <unordered_map>
4
+ #include <unordered_set>
5
+ #include <utility>
6
+
7
+ namespace RNJsi {
8
+
9
+ static std::unordered_map<jsi::Runtime *,
10
+ std::unordered_set<RuntimeLifecycleListener *>>
11
+ listeners;
12
+
13
+ struct RuntimeLifecycleMonitorObject : public jsi::HostObject {
14
+ jsi::Runtime *_rt;
15
+ explicit RuntimeLifecycleMonitorObject(jsi::Runtime *rt) : _rt(rt) {}
16
+ ~RuntimeLifecycleMonitorObject() {
17
+ auto listenersSet = listeners.find(_rt);
18
+ if (listenersSet != listeners.end()) {
19
+ for (auto listener : listenersSet->second) {
20
+ listener->onRuntimeDestroyed(_rt);
21
+ }
22
+ listeners.erase(listenersSet);
23
+ }
24
+ }
25
+ };
26
+
27
+ void RuntimeLifecycleMonitor::addListener(jsi::Runtime &rt,
28
+ RuntimeLifecycleListener *listener) {
29
+ auto listenersSet = listeners.find(&rt);
30
+ if (listenersSet == listeners.end()) {
31
+ // We install a global host object in the provided runtime, this way we can
32
+ // use that host object destructor to get notified when the runtime is being
33
+ // terminated. We use a unique name for the object as it gets saved with the
34
+ // runtime's global object.
35
+ rt.global().setProperty(
36
+ rt, "__rnskia_rt_lifecycle_monitor",
37
+ jsi::Object::createFromHostObject(
38
+ rt, std::make_shared<RuntimeLifecycleMonitorObject>(&rt)));
39
+ std::unordered_set<RuntimeLifecycleListener *> newSet;
40
+ newSet.insert(listener);
41
+ listeners.emplace(&rt, std::move(newSet));
42
+ } else {
43
+ listenersSet->second.insert(listener);
44
+ }
45
+ }
46
+
47
+ void RuntimeLifecycleMonitor::removeListener(
48
+ jsi::Runtime &rt, RuntimeLifecycleListener *listener) {
49
+ auto listenersSet = listeners.find(&rt);
50
+ if (listenersSet == listeners.end()) {
51
+ // nothing to do here
52
+ } else {
53
+ listenersSet->second.erase(listener);
54
+ }
55
+ }
56
+
57
+ } // namespace RNJsi
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+
5
+ #include <memory>
6
+
7
+ namespace RNJsi {
8
+
9
+ namespace jsi = facebook::jsi;
10
+
11
+ /**
12
+ * Listener interface that allows for getting notified when a jsi::Runtime
13
+ * instance is destroyed.
14
+ */
15
+ struct RuntimeLifecycleListener {
16
+ virtual ~RuntimeLifecycleListener() {}
17
+ virtual void onRuntimeDestroyed(jsi::Runtime *) = 0;
18
+ };
19
+
20
+ /**
21
+ * This class provides an API via static methods for registering and
22
+ * unregistering runtime lifecycle listeners. The listeners can be used to
23
+ * cleanup any data that references a given jsi::Runtime instance before it gets
24
+ * destroyed.
25
+ */
26
+ struct RuntimeLifecycleMonitor {
27
+ static void addListener(jsi::Runtime &rt, RuntimeLifecycleListener *listener);
28
+ static void removeListener(jsi::Runtime &rt,
29
+ RuntimeLifecycleListener *listener);
30
+ };
31
+
32
+ } // namespace RNJsi
@@ -11,6 +11,7 @@
11
11
  #include <RNSkView.h>
12
12
 
13
13
  #include <JsiDomApi.h>
14
+ #include <RuntimeAwareCache.h>
14
15
 
15
16
  namespace RNSkia {
16
17
  namespace jsi = facebook::jsi;
@@ -23,6 +24,9 @@ RNSkManager::RNSkManager(
23
24
  _platformContext(platformContext),
24
25
  _viewApi(std::make_shared<RNSkJsiViewApi>(platformContext)) {
25
26
 
27
+ // Register main runtime
28
+ BaseRuntimeAwareCache::setMainJsRuntime(_jsRuntime);
29
+
26
30
  // Install bindings
27
31
  installBindings();
28
32
  }
@@ -88,10 +88,11 @@ protected:
88
88
 
89
89
  class RNSkImageCanvasProvider : public RNSkCanvasProvider {
90
90
  public:
91
- RNSkImageCanvasProvider(std::function<void()> requestRedraw, float width,
91
+ RNSkImageCanvasProvider(std::shared_ptr<RNSkPlatformContext> context,
92
+ std::function<void()> requestRedraw, float width,
92
93
  float height)
93
94
  : RNSkCanvasProvider(requestRedraw), _width(width), _height(height) {
94
- _surface = SkSurface::MakeRasterN32Premul(_width, _height);
95
+ _surface = context->makeOffscreenSurface(_width, _height);
95
96
  }
96
97
 
97
98
  /**
@@ -261,8 +262,9 @@ public:
261
262
  Renders the view into an SkImage instead of the screen.
262
263
  */
263
264
  sk_sp<SkImage> makeImageSnapshot(std::shared_ptr<SkRect> bounds) {
265
+
264
266
  auto provider = std::make_shared<RNSkImageCanvasProvider>(
265
- std::bind(&RNSkView::requestRedraw, this),
267
+ getPlatformContext(), std::bind(&RNSkView::requestRedraw, this),
266
268
  _canvasProvider->getScaledWidth(), _canvasProvider->getScaledHeight());
267
269
 
268
270
  _renderer->renderImmediate(provider);
@@ -73,9 +73,29 @@ public:
73
73
  }
74
74
 
75
75
  /**
76
- Empty setProp implementation - compatibility with JS node
76
+ Updates the selected property value
77
77
  */
78
- JSI_HOST_FUNCTION(setProp) { return jsi::Value::undefined(); }
78
+ JSI_HOST_FUNCTION(setProp) {
79
+ if (_propsContainer == nullptr) {
80
+ // TODO: we ignore individual properties updates if the initial properties
81
+ // hasn't been defined. It is likely an error if we reach this branch and
82
+ // perhaps should throw an exception but platformContext isn't available
83
+ // here.
84
+ return jsi::Value::undefined();
85
+ }
86
+ auto propName = arguments[0].asString(runtime).utf8(runtime);
87
+ const jsi::Value &propValue = arguments[1];
88
+
89
+ auto mappedProps = _propsContainer->getMappedProperties();
90
+ auto propMapIt = mappedProps.find(JsiPropId::get(propName));
91
+ if (propMapIt != mappedProps.end()) {
92
+ for (auto &prop : propMapIt->second) {
93
+ prop->updateValue(runtime, propValue);
94
+ }
95
+ }
96
+
97
+ return jsi::Value::undefined();
98
+ }
79
99
 
80
100
  /**
81
101
  JS Function to be called when the node is no longer part of the reconciler
@@ -158,20 +158,21 @@ public:
158
158
  : JsiBaseImageFilterNode(context, "skDisplacementMapImageFilter") {}
159
159
 
160
160
  void decorate(DeclarationContext *context) override {
161
-
161
+ decorateChildren(context);
162
162
  auto channelX =
163
163
  getColorChannelFromStringValue(_channelXProp->value().getAsString());
164
164
  auto channelY =
165
165
  getColorChannelFromStringValue(_channelYProp->value().getAsString());
166
166
  auto scale = _scaleProp->value().getAsNumber();
167
-
168
- auto displacement = context->getImageFilters()->pop();
169
-
170
- auto color = context->getImageFilters()->pop();
171
-
172
- composeAndPush(context, SkImageFilters::DisplacementMap(
173
- channelX, channelY, scale, displacement,
174
- color ? color : nullptr));
167
+ auto shader = context->getShaders()->pop();
168
+ if (!shader) {
169
+ throw std::runtime_error("DisplacementMap expects a shader as child");
170
+ }
171
+ auto map = SkImageFilters::Shader(shader);
172
+ auto input = context->getImageFilters()->pop();
173
+ auto imgf = SkImageFilters::DisplacementMap(channelX, channelY, scale, map,
174
+ input ? input : nullptr);
175
+ context->getImageFilters()->push(imgf);
175
176
  }
176
177
 
177
178
  protected:
@@ -83,13 +83,21 @@ class DisplacementMapImageFilterNode extends ImageFilterDeclaration {
83
83
  }
84
84
 
85
85
  decorate(ctx) {
86
+ this.decorateChildren(ctx);
86
87
  const {
87
88
  channelX,
88
89
  channelY,
89
90
  scale
90
91
  } = this.props;
91
- const imgf = this.Skia.ImageFilter.MakeDisplacementMap(_types.ColorChannel[(0, _datatypes.enumKey)(channelX)], _types.ColorChannel[(0, _datatypes.enumKey)(channelY)], scale, ctx.imageFilters.pop(), this.input(ctx));
92
- this.composeAndPush(ctx, imgf);
92
+ const shader = ctx.shaders.pop();
93
+
94
+ if (!shader) {
95
+ throw new Error("DisplacementMap expects a shader as child");
96
+ }
97
+
98
+ const map = this.Skia.ImageFilter.MakeShader(shader, null);
99
+ const imgf = this.Skia.ImageFilter.MakeDisplacementMap(_types.ColorChannel[(0, _datatypes.enumKey)(channelX)], _types.ColorChannel[(0, _datatypes.enumKey)(channelY)], scale, map, this.input(ctx));
100
+ ctx.imageFilters.push(imgf);
93
101
  }
94
102
 
95
103
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","BlendMode","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","TileMode","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","JsiDeclarationNode","constructor","ctx","type","props","DeclarationType","imageFilters","pop","composeAndPush","imgf1","save","decorateChildren","imgf2","popAllAsOne","cf","colorFilters","restore","imgf","push","OffsetImageFilterNode","NodeType","OffsetImageFilter","decorate","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","MakeDisplacementMap","ColorChannel","enumKey","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","processRadius","DropShadowImageFilterNode","DropShadowImageFilter","cl","inner","Color","factory","bind","MakeDropShadowOnly","MakeDropShadow","MorphologyOperator","MorphologyImageFilterNode","MorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","BlendImageFilterNode","BlendImageFilter","a","b","Error","RuntimeShaderImageFilterNode","RuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","processUniforms","MakeRuntimeShader"],"sources":["ImageFilters.ts"],"sourcesContent":["import type { SkImageFilter, SkColor, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n DeclarationContext,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport { processRadius, enumKey } from \"../datatypes\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n null\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nexport abstract class ImageFilterDeclaration<P> extends JsiDeclarationNode<P> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n protected input(ctx: DeclarationContext) {\n return ctx.imageFilters.pop() ?? null;\n }\n\n protected composeAndPush(ctx: DeclarationContext, imgf1: SkImageFilter) {\n ctx.save();\n this.decorateChildren(ctx);\n let imgf2 = ctx.imageFilters.popAllAsOne();\n const cf = ctx.colorFilters.popAllAsOne();\n ctx.restore();\n if (cf) {\n imgf2 = this.Skia.ImageFilter.MakeCompose(\n imgf2 ?? null,\n this.Skia.ImageFilter.MakeColorFilter(cf, null)\n );\n }\n const imgf = imgf2\n ? this.Skia.ImageFilter.MakeCompose(imgf1, imgf2)\n : imgf1;\n ctx.imageFilters.push(imgf);\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n this.decorateChildren(ctx);\n const { x, y } = this.props;\n const imgf = this.Skia.ImageFilter.MakeOffset(x, y, null);\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { channelX, channelY, scale } = this.props;\n const imgf = this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n ctx.imageFilters.pop()!,\n this.input(ctx)\n );\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n const imgf = this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.input(ctx)\n );\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.DropShadowImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, this.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? this.Skia.ImageFilter.MakeDropShadowOnly.bind(this.Skia.ImageFilter)\n : this.Skia.ImageFilter.MakeDropShadow.bind(this.Skia.ImageFilter);\n }\n const imgf = factory(dx, dy, blur, blur, color, this.input(ctx));\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nexport class MorphologyImageFilterNode extends ImageFilterDeclaration<MorphologyImageFilterProps> {\n constructor(ctx: NodeContext, props: MorphologyImageFilterProps) {\n super(ctx, NodeType.MorphologyImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n let imgf;\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n imgf = this.Skia.ImageFilter.MakeErode(r.x, r.y, this.input(ctx));\n } else {\n imgf = this.Skia.ImageFilter.MakeDilate(r.x, r.y, this.input(ctx));\n }\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { mode } = this.props;\n const a = ctx.imageFilters.pop();\n const b = ctx.imageFilters.pop();\n if (!a || !b) {\n throw new Error(\"BlendImageFilter requires two image filters\");\n }\n const imgf = this.Skia.ImageFilter.MakeBlend(mode, a, b);\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const imgf = this.Skia.ImageFilter.MakeRuntimeShader(\n rtb,\n null,\n this.input(ctx)\n );\n this.composeAndPush(ctx, imgf);\n }\n}\n"],"mappings":";;;;;;;AACA;;AAgBA;;AACA;;AAEA;;AAEA,MAAMA,KAAK,GAAGC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAd;;AAEA,MAAMC,eAAe,GAAG,CACtBC,IADsB,EAEtBC,UAFsB,EAGtBC,EAHsB,EAItBC,EAJsB,EAKtBC,MALsB,EAMtBC,MANsB,EAOtBC,KAPsB,EAQtBC,KARsB,KASnB;EACH,MAAMC,aAAa,GAAGR,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CACpBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCiB,gBAAA,CAAUC,GAA5C,CADoB,EAEpB,IAFoB,CAAtB;EAIA,MAAMC,WAAW,GAAGf,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CAClBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCiB,gBAAA,CAAUG,KAA5C,CADkB,EAElB,IAFkB,CAApB;EAIA,MAAMC,EAAE,GAAGjB,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CACTV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BN,KAA3B,EAAkCO,gBAAA,CAAUK,MAA5C,CADS,EAET,IAFS,CAAX;EAIA,MAAMC,EAAE,GAAGnB,IAAI,CAACS,WAAL,CAAiBW,UAAjB,CAA4BlB,EAA5B,EAAgCC,EAAhC,EAAoCc,EAApC,CAAX;EACA,MAAMI,EAAE,GAAGrB,IAAI,CAACS,WAAL,CAAiBa,QAAjB,CAA0BlB,MAA1B,EAAkCC,MAAlC,EAA0CkB,eAAA,CAASC,KAAnD,EAA0DL,EAA1D,CAAX;EACA,MAA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AAG,KAAK/F,IAAL,CAAUgG,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZ,IAAAG,sBAAA,EAAgBJ,MAAhB,EAAwBC,QAAxB,EAAkCC,GAAlC;IACD;;IACD,MAAMjD,IAAI,GAAG,KAAK9C,IAAL,CAAUS,WAAV,CAAsByF,iBAAtB,CACXH,GADW,EAEX,IAFW,EAGX,KAAKxF,KAAL,CAAWwB,GAAX,CAHW,CAAb;IAKA,KAAKM,cAAL,CAAoBN,GAApB,EAAyBe,IAAzB;EACD;;AAjBqG"}
1
+ {"version":3,"names":["Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","BlendMode","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","TileMode","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","JsiDeclarationNode","constructor","ctx","type","props","DeclarationType","imageFilters","pop","composeAndPush","imgf1","save","decorateChildren","imgf2","popAllAsOne","cf","colorFilters","restore","imgf","push","OffsetImageFilterNode","NodeType","OffsetImageFilter","decorate","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","shader","shaders","Error","map","MakeShader","MakeDisplacementMap","ColorChannel","enumKey","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","processRadius","DropShadowImageFilterNode","DropShadowImageFilter","cl","inner","Color","factory","bind","MakeDropShadowOnly","MakeDropShadow","MorphologyOperator","MorphologyImageFilterNode","MorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","BlendImageFilterNode","BlendImageFilter","a","b","RuntimeShaderImageFilterNode","RuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","processUniforms","MakeRuntimeShader"],"sources":["ImageFilters.ts"],"sourcesContent":["import type { SkImageFilter, SkColor, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n DeclarationContext,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport { processRadius, enumKey } from \"../datatypes\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n null\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nexport abstract class ImageFilterDeclaration<P> extends JsiDeclarationNode<P> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n protected input(ctx: DeclarationContext) {\n return ctx.imageFilters.pop() ?? null;\n }\n\n protected composeAndPush(ctx: DeclarationContext, imgf1: SkImageFilter) {\n ctx.save();\n this.decorateChildren(ctx);\n let imgf2 = ctx.imageFilters.popAllAsOne();\n const cf = ctx.colorFilters.popAllAsOne();\n ctx.restore();\n if (cf) {\n imgf2 = this.Skia.ImageFilter.MakeCompose(\n imgf2 ?? null,\n this.Skia.ImageFilter.MakeColorFilter(cf, null)\n );\n }\n const imgf = imgf2\n ? this.Skia.ImageFilter.MakeCompose(imgf1, imgf2)\n : imgf1;\n ctx.imageFilters.push(imgf);\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n this.decorateChildren(ctx);\n const { x, y } = this.props;\n const imgf = this.Skia.ImageFilter.MakeOffset(x, y, null);\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n this.decorateChildren(ctx);\n const { channelX, channelY, scale } = this.props;\n const shader = ctx.shaders.pop();\n if (!shader) {\n throw new Error(\"DisplacementMap expects a shader as child\");\n }\n const map = this.Skia.ImageFilter.MakeShader(shader, null);\n const imgf = this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n map,\n this.input(ctx)\n );\n ctx.imageFilters.push(imgf);\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n const imgf = this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.input(ctx)\n );\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.DropShadowImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, this.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? this.Skia.ImageFilter.MakeDropShadowOnly.bind(this.Skia.ImageFilter)\n : this.Skia.ImageFilter.MakeDropShadow.bind(this.Skia.ImageFilter);\n }\n const imgf = factory(dx, dy, blur, blur, color, this.input(ctx));\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nexport class MorphologyImageFilterNode extends ImageFilterDeclaration<MorphologyImageFilterProps> {\n constructor(ctx: NodeContext, props: MorphologyImageFilterProps) {\n super(ctx, NodeType.MorphologyImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n let imgf;\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n imgf = this.Skia.ImageFilter.MakeErode(r.x, r.y, this.input(ctx));\n } else {\n imgf = this.Skia.ImageFilter.MakeDilate(r.x, r.y, this.input(ctx));\n }\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { mode } = this.props;\n const a = ctx.imageFilters.pop();\n const b = ctx.imageFilters.pop();\n if (!a || !b) {\n throw new Error(\"BlendImageFilter requires two image filters\");\n }\n const imgf = this.Skia.ImageFilter.MakeBlend(mode, a, b);\n this.composeAndPush(ctx, imgf);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n decorate(ctx: DeclarationContext) {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const imgf = this.Skia.ImageFilter.MakeRuntimeShader(\n rtb,\n null,\n this.input(ctx)\n );\n this.composeAndPush(ctx, imgf);\n }\n}\n"],"mappings":";;;;;;;AACA;;AAgBA;;AACA;;AAEA;;AAEA,MAAMA,KAAK,GAAGC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAd;;AAEA,MAAMC,eAAe,GAAG,CACtBC,IADsB,EAEtBC,UAFsB,EAGtBC,EAHsB,EAItBC,EAJsB,EAKtBC,MALsB,EAMtBC,MANsB,EAOtBC,KAPsB,EAQtBC,KARsB,KASnB;EACH,MAAMC,aAAa,GAAGR,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CACpBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCiB,gBAAA,CAAUC,GAA5C,CADoB,EAEpB,IAFoB,CAAtB;EAIA,MAAMC,WAAW,GAAGf,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CAClBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCiB,gBAAA,CAAUG,KAA5C,CADkB,EAElB,IAFkB,CAApB;EAIA,MAAMC,EAAE,GAAGjB,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CACTV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BN,KAA3B,EAAkCO,gBAAA,CAAUK,MAA5C,CADS,EAET,IAFS,CAAX;EAIA,MAAM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M,IAAIjC,KAAJ,CAAU,6CAAV,CAAN;IACD;;IACD,MAAMf,IAAI,GAAG,KAAK9C,IAAL,CAAUS,WAAV,CAAsBG,SAAtB,CAAgCyD,IAAhC,EAAsCwB,CAAtC,EAAyCC,CAAzC,CAAb;IACA,KAAKzD,cAAL,CAAoBN,GAApB,EAAyBe,IAAzB;EACD;;AAdqF;;;;AAiBjF,MAAMiD,4BAAN,SAA2CnE,sBAA3C,CAAiG;EACtGE,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAyD;IAClE,MAAMF,GAAN,EAAWkB,gBAAA,CAAS+C,wBAApB,EAA8C/D,KAA9C;EACD;;EAEDkB,QAAQ,CAACpB,GAAD,EAA0B;IAChC,MAAM;MAAEkE,MAAF;MAAUC;IAAV,IAAuB,KAAKjE,KAAlC;IACA,MAAMkE,GAAG,GAAG,KAAKnG,IAAL,CAAUoG,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZ,IAAAG,sBAAA,EAAgBJ,MAAhB,EAAwBC,QAAxB,EAAkCC,GAAlC;IACD;;IACD,MAAMrD,IAAI,GAAG,KAAK9C,IAAL,CAAUS,WAAV,CAAsB6F,iBAAtB,CACXH,GADW,EAEX,IAFW,EAGX,KAAK5F,KAAL,CAAWwB,GAAX,CAHW,CAAb;IAKA,KAAKM,cAAL,CAAoBN,GAApB,EAAyBe,IAAzB;EACD;;AAjBqG"}
@@ -1 +1,2 @@
1
1
  export * from "./useSharedValueEffect";
2
+ export * from "./renderHelpers";
@@ -16,4 +16,17 @@ Object.keys(_useSharedValueEffect).forEach(function (key) {
16
16
  }
17
17
  });
18
18
  });
19
+
20
+ var _renderHelpers = require("./renderHelpers");
21
+
22
+ Object.keys(_renderHelpers).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _renderHelpers[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _renderHelpers[key];
29
+ }
30
+ });
31
+ });
19
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useSharedValueEffect\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useSharedValueEffect\";\nexport * from \"./renderHelpers\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,8 @@
1
+ import type { SharedValueType } from "../../renderer/processors/Animations";
2
+ export declare const HAS_REANIMATED2: boolean;
3
+ export declare const HAS_REANIMATED3: boolean;
4
+ export declare const useSharedValue: any;
5
+ export declare const startMapper: any;
6
+ export declare const stopMapper: any;
7
+ export declare const runOnJS: any;
8
+ export declare const isSharedValue: <T>(value: unknown) => value is SharedValueType<T>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSharedValue = exports.stopMapper = exports.startMapper = exports.runOnJS = exports.isSharedValue = exports.HAS_REANIMATED3 = exports.HAS_REANIMATED2 = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _Reanimated, _Reanimated2, _Reanimated3, _Reanimated4;
11
+
12
+ // This one is needed for the deprecated useSharedValue function
13
+ // We can remove it once we remove the deprecation
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ let Reanimated2; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+
17
+ let Reanimated3;
18
+ let reanimatedVersion;
19
+
20
+ try {
21
+ Reanimated2 = require("react-native-reanimated");
22
+ reanimatedVersion = // eslint-disable-next-line import/extensions
23
+ require("react-native-reanimated/package.json").version;
24
+
25
+ if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
26
+ Reanimated3 = Reanimated2;
27
+ }
28
+ } catch (e) {}
29
+
30
+ const HAS_REANIMATED2 = !!Reanimated2;
31
+ exports.HAS_REANIMATED2 = HAS_REANIMATED2;
32
+ const HAS_REANIMATED3 = !!Reanimated3;
33
+ exports.HAS_REANIMATED3 = HAS_REANIMATED3;
34
+
35
+ function throwOnMissingReanimated2() {
36
+ if (!HAS_REANIMATED2) {
37
+ throw new Error("Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
38
+ react-naitve-skia's integration layer API.");
39
+ }
40
+ }
41
+
42
+ function throwOnMissingReanimated3() {
43
+ if (!HAS_REANIMATED3) {
44
+ throw new Error(`Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`);
45
+ }
46
+
47
+ throwOnMissingReanimated2();
48
+ }
49
+
50
+ const useSharedValue = ((_Reanimated = Reanimated2) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) || (value => (0, _react.useMemo)(() => ({
51
+ value
52
+ }), [value]));
53
+
54
+ exports.useSharedValue = useSharedValue;
55
+ const startMapper = ((_Reanimated2 = Reanimated2) === null || _Reanimated2 === void 0 ? void 0 : _Reanimated2.startMapper) || throwOnMissingReanimated2;
56
+ exports.startMapper = startMapper;
57
+ const stopMapper = ((_Reanimated3 = Reanimated2) === null || _Reanimated3 === void 0 ? void 0 : _Reanimated3.stopMapper) || throwOnMissingReanimated2;
58
+ exports.stopMapper = stopMapper;
59
+ const runOnJS = ((_Reanimated4 = Reanimated2) === null || _Reanimated4 === void 0 ? void 0 : _Reanimated4.runOnJS) || throwOnMissingReanimated2;
60
+ exports.runOnJS = runOnJS;
61
+
62
+ const isSharedValue = value => {
63
+ throwOnMissingReanimated3();
64
+ return !!value && Reanimated3.isSharedValue(value);
65
+ };
66
+
67
+ exports.isSharedValue = isSharedValue;
68
+ //# sourceMappingURL=moduleWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Reanimated2","Reanimated3","reanimatedVersion","require","version","includes","e","HAS_REANIMATED2","HAS_REANIMATED3","throwOnMissingReanimated2","Error","throwOnMissingReanimated3","useSharedValue","value","useMemo","startMapper","stopMapper","runOnJS","isSharedValue"],"sources":["moduleWrapper.ts"],"sourcesContent":["import { useMemo } from \"react\";\n\nimport type { SharedValueType } from \"../../renderer/processors/Animations\";\n\n// This one is needed for the deprecated useSharedValue function\n// We can remove it once we remove the deprecation\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Reanimated2: any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Reanimated3: any;\nlet reanimatedVersion: string;\n\ntry {\n Reanimated2 = require(\"react-native-reanimated\");\n reanimatedVersion =\n // eslint-disable-next-line import/extensions\n require(\"react-native-reanimated/package.json\").version;\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n Reanimated3 = Reanimated2;\n }\n} catch (e) {}\n\nexport const HAS_REANIMATED2 = !!Reanimated2;\nexport const HAS_REANIMATED3 = !!Reanimated3;\n\nfunction throwOnMissingReanimated2() {\n if (!HAS_REANIMATED2) {\n throw new Error(\n \"Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \\\n react-naitve-skia's integration layer API.\"\n );\n }\n}\n\nfunction throwOnMissingReanimated3() {\n if (!HAS_REANIMATED3) {\n throw new Error(\n `Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`\n );\n }\n throwOnMissingReanimated2();\n}\n\nexport const useSharedValue =\n Reanimated2?.useSharedValue ||\n ((value: number) => useMemo(() => ({ value }), [value]));\n\nexport const startMapper =\n Reanimated2?.startMapper || throwOnMissingReanimated2;\nexport const stopMapper = Reanimated2?.stopMapper || throwOnMissingReanimated2;\nexport const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated2;\nexport const isSharedValue = <T>(\n value: unknown\n): value is SharedValueType<T> => {\n throwOnMissingReanimated3();\n return !!value && Reanimated3.isSharedValue(value);\n};\n"],"mappings":";;;;;;;AAAA;;;;AAIA;AACA;AACA;AACA,IAAIA,WAAJ,C,CACA;;AACA,IAAIC,WAAJ;AACA,IAAIC,iBAAJ;;AAEA,IAAI;EACFF,WAAW,GAAGG,OAAO,CAAC,yBAAD,CAArB;EACAD,iBAAiB,GACf;EACAC,OAAO,CAAC,sCAAD,CAAP,CAAgDC,OAFlD;;EAGA,IACEF,iBAAiB,KAChBA,iBAAiB,IAAI,OAArB,IAAgCA,iBAAiB,CAACG,QAAlB,CAA2B,QAA3B,CADhB,CADnB,EAGE;IACAJ,WAAW,GAAGD,WAAd;EACD;AACF,CAXD,CAWE,OAAOM,CAAP,EAAU,CAAE;;AAEP,MAAMC,eAAe,GAAG,CAAC,CAACP,WAA1B;;AACA,MAAMQ,eAAe,GAAG,CAAC,CAACP,WAA1B;;;AAEP,SAASQ,yBAAT,GAAqC;EACnC,IAAI,CAACF,eAAL,EAAsB;IACpB,MAAM,IAAIG,KAAJ,CACJ;AACN,iDAFU,CAAN;EAID;AACF;;AAED,SAASC,yBAAT,GAAqC;EACnC,IAAI,CAACH,eAAL,EAAsB;IACpB,MAAM,IAAIE,KAAJ,CACH,sBAAqBR,iBAAkB,sDADpC,CAAN;EAGD;;EACDO,yBAAyB;AAC1B;;AAEM,MAAMG,cAAc,GACzB,gBAAAZ,WAAW,UAAX,kDAAaY,cAAb,MACEC,KAAD,IAAmB,IAAAC,cAAA,EAAQ,OAAO;EAAED;AAAF,CAAP,CAAR,EAA2B,CAACA,KAAD,CAA3B,CADpB,CADK;;;AAIA,MAAME,WAAW,GACtB,iBAAAf,WAAW,UAAX,oDAAae,WAAb,KAA4BN,yBADvB;;AAEA,MAAMO,UAAU,GAAG,iBAAAhB,WAAW,UAAX,oDAAagB,UAAb,KAA2BP,yBAA9C;;AACA,MAAMQ,OAAO,GAAG,iBAAAjB,WAAW,UAAX,oDAAaiB,OAAb,KAAwBR,yBAAxC;;;AACA,MAAMS,aAAa,GACxBL,KAD2B,IAEK;EAChCF,yBAAyB;EACzB,OAAO,CAAC,CAACE,KAAF,IAAWZ,WAAW,CAACiB,aAAZ,CAA0BL,KAA1B,CAAlB;AACD,CALM"}
@@ -0,0 +1,5 @@
1
+ import type { Container } from "../../renderer/Container";
2
+ import type { AnimatedProps } from "../../renderer/processors";
3
+ import type { Node } from "../../dom/types";
4
+ export declare function extractReanimatedProps(props: AnimatedProps<any>): AnimatedProps<any, never>[];
5
+ export declare function bindReanimatedProps(container: Container, node: Node<any>, reanimatedProps: AnimatedProps<any>): void;