@shopify/react-native-skia 0.1.165 → 0.1.166

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +16 -5
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +34 -0
  3. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +2 -47
  4. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawViewManager.java +2 -44
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +2 -47
  6. package/cpp/rnskia/dom/base/DerivedNodeProp.h +4 -4
  7. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -4
  8. package/cpp/rnskia/dom/nodes/JsiPathNode.h +12 -5
  9. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +17 -7
  10. package/cpp/rnskia/dom/props/ClipProp.h +6 -6
  11. package/cpp/rnskia/dom/props/ImageProps.h +3 -1
  12. package/cpp/rnskia/dom/props/PaintProps.h +0 -16
  13. package/cpp/rnskia/dom/props/VerticesProps.h +2 -2
  14. package/lib/commonjs/dom/nodes/drawings/Box.js +1 -1
  15. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  16. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
  17. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  18. package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -2
  19. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  20. package/lib/commonjs/skia/types/Shader/Shader.js +26 -27
  21. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  22. package/lib/module/dom/nodes/drawings/Box.js +1 -1
  23. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  24. package/lib/module/dom/nodes/paint/ImageFilters.js +1 -1
  25. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  26. package/lib/module/dom/nodes/paint/Shaders.js +5 -4
  27. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  28. package/lib/module/skia/types/Shader/Shader.js +26 -27
  29. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  30. package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -2
  31. package/package.json +1 -1
  32. package/src/dom/nodes/drawings/Box.ts +1 -1
  33. package/src/dom/nodes/paint/ImageFilters.ts +1 -1
  34. package/src/dom/nodes/paint/Shaders.ts +5 -5
  35. package/src/skia/types/Shader/Shader.ts +30 -38
@@ -7,25 +7,36 @@ import android.view.Surface;
7
7
  import android.view.TextureView;
8
8
 
9
9
  import com.facebook.jni.annotations.DoNotStrip;
10
+ import com.facebook.react.uimanager.PointerEvents;
11
+ import com.facebook.react.views.view.ReactViewGroup;
10
12
 
11
- public abstract class SkiaBaseView extends TextureView implements TextureView.SurfaceTextureListener {
13
+ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView.SurfaceTextureListener {
12
14
 
13
15
  @DoNotStrip
14
16
  private Surface mSurface;
17
+ private TextureView mTexture;
15
18
 
16
19
  public SkiaBaseView(Context context) {
17
20
  super(context);
18
- setSurfaceTextureListener(this);
19
- setOpaque(false);
21
+ mTexture = new TextureView(context);
22
+ mTexture.setSurfaceTextureListener(this);
23
+ mTexture.setOpaque(false);
24
+ addView(mTexture);
20
25
  }
21
26
 
22
27
  @Override
23
- public void setBackgroundColor(int color) {
24
- // Texture view does not support setting the background color.
28
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
29
+ super.onLayout(changed, left, top, right, bottom);
30
+ mTexture.layout(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
25
31
  }
26
32
 
27
33
  @Override
28
34
  public boolean onTouchEvent(MotionEvent ev) {
35
+ // We do not accept the touch event if this view is not supposed to receive it.
36
+ if (!PointerEvents.canBeTouchTarget(getPointerEvents())) {
37
+ return false;
38
+ }
39
+
29
40
  // https://developer.android.com/training/gestures/multi
30
41
  int action = ev.getActionMasked();
31
42
 
@@ -0,0 +1,34 @@
1
+ package com.shopify.reactnative.skia;
2
+
3
+ import com.facebook.react.uimanager.annotations.ReactProp;
4
+ import com.facebook.react.views.view.ReactViewGroup;
5
+ import com.facebook.react.views.view.ReactViewManager;
6
+
7
+ import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
9
+
10
+ public abstract class SkiaBaseViewManager extends ReactViewManager {
11
+
12
+ @Override
13
+ public void setNativeId(@NonNull ReactViewGroup view, @Nullable String nativeId) {
14
+ super.setNativeId(view, nativeId);
15
+ int nativeIdResolved = Integer.parseInt(nativeId);
16
+ ((SkiaBaseView)view).registerView(nativeIdResolved);
17
+ }
18
+
19
+ @ReactProp(name = "mode")
20
+ public void setMode(ReactViewGroup view, String mode) {
21
+ ((SkiaBaseView)view).setMode(mode);
22
+ }
23
+
24
+ @ReactProp(name = "debug")
25
+ public void setDebug(ReactViewGroup view, boolean show) {
26
+ ((SkiaBaseView)view).setDebugMode(show);
27
+ }
28
+
29
+ @Override
30
+ public void onDropViewInstance(@NonNull ReactViewGroup view) {
31
+ super.onDropViewInstance(view);
32
+ ((SkiaBaseView)view).unregisterView();
33
+ }
34
+ }
@@ -1,17 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.bridge.ReactContext;
4
- import com.facebook.react.uimanager.BaseViewManager;
5
- import com.facebook.react.uimanager.LayoutShadowNode;
6
3
  import com.facebook.react.uimanager.ThemedReactContext;
7
- import com.facebook.react.uimanager.annotations.ReactProp;
8
-
9
4
  import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
-
12
- import java.util.HashMap;
13
5
 
14
- public class SkiaDomViewManager extends BaseViewManager<SkiaDomView, LayoutShadowNode> {
6
+ public class SkiaDomViewManager extends SkiaBaseViewManager {
15
7
 
16
8
  @NonNull
17
9
  @Override
@@ -19,46 +11,9 @@ public class SkiaDomViewManager extends BaseViewManager<SkiaDomView, LayoutShado
19
11
  return "SkiaDomView";
20
12
  }
21
13
 
22
- @Override
23
- public LayoutShadowNode createShadowNodeInstance() {
24
- return new LayoutShadowNode();
25
- }
26
-
27
- @Override
28
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
29
- return LayoutShadowNode.class;
30
- }
31
-
32
- @Override
33
- public void updateExtraData(SkiaDomView root, Object extraData) {
34
- }
35
-
36
- @Override
37
- public void setNativeId(@NonNull SkiaDomView view, @Nullable String nativeId) {
38
- super.setNativeId(view, nativeId);
39
- int nativeIdResolved = Integer.parseInt(nativeId);
40
- view.registerView(nativeIdResolved);
41
- }
42
-
43
- @ReactProp(name = "mode")
44
- public void setMode(SkiaDomView view, String mode) {
45
- view.setMode(mode);
46
- }
47
-
48
- @ReactProp(name = "debug")
49
- public void setDebug(SkiaDomView view, boolean show) {
50
- view.setDebugMode(show);
51
- }
52
-
53
- @Override
54
- public void onDropViewInstance(@NonNull SkiaDomView view) {
55
- super.onDropViewInstance(view);
56
- view.unregisterView();
57
- }
58
-
59
14
  @NonNull
60
15
  @Override
61
- protected SkiaDomView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaDomView createViewInstance(@NonNull ThemedReactContext reactContext) {
62
17
  return new SkiaDomView(reactContext);
63
18
  }
64
19
  }
@@ -1,14 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.uimanager.BaseViewManager;
4
- import com.facebook.react.uimanager.LayoutShadowNode;
5
3
  import com.facebook.react.uimanager.ThemedReactContext;
6
- import com.facebook.react.uimanager.annotations.ReactProp;
7
-
8
4
  import androidx.annotation.NonNull;
9
- import androidx.annotation.Nullable;
10
5
 
11
- public class SkiaDrawViewManager extends BaseViewManager<SkiaDrawView, LayoutShadowNode> {
6
+ public class SkiaDrawViewManager extends SkiaBaseViewManager {
12
7
 
13
8
  @NonNull
14
9
  @Override
@@ -16,46 +11,9 @@ public class SkiaDrawViewManager extends BaseViewManager<SkiaDrawView, LayoutSha
16
11
  return "SkiaDrawView";
17
12
  }
18
13
 
19
- @Override
20
- public LayoutShadowNode createShadowNodeInstance() {
21
- return new LayoutShadowNode();
22
- }
23
-
24
- @Override
25
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
26
- return LayoutShadowNode.class;
27
- }
28
-
29
- @Override
30
- public void updateExtraData(SkiaDrawView root, Object extraData) {
31
- }
32
-
33
- @Override
34
- public void setNativeId(@NonNull SkiaDrawView view, @Nullable String nativeId) {
35
- super.setNativeId(view, nativeId);
36
- int nativeIdResolved = Integer.parseInt(nativeId);
37
- view.registerView(nativeIdResolved);
38
- }
39
-
40
- @ReactProp(name = "mode")
41
- public void setMode(SkiaDrawView view, String mode) {
42
- view.setMode(mode);
43
- }
44
-
45
- @ReactProp(name = "debug")
46
- public void setDebug(SkiaDrawView view, boolean show) {
47
- view.setDebugMode(show);
48
- }
49
-
50
- @Override
51
- public void onDropViewInstance(@NonNull SkiaDrawView view) {
52
- super.onDropViewInstance(view);
53
- view.unregisterView();
54
- }
55
-
56
14
  @NonNull
57
15
  @Override
58
- protected SkiaDrawView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaDrawView createViewInstance(@NonNull ThemedReactContext reactContext) {
59
17
  return new SkiaDrawView(reactContext);
60
18
  }
61
19
  }
@@ -1,17 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.bridge.ReactContext;
4
- import com.facebook.react.uimanager.BaseViewManager;
5
- import com.facebook.react.uimanager.LayoutShadowNode;
6
3
  import com.facebook.react.uimanager.ThemedReactContext;
7
- import com.facebook.react.uimanager.annotations.ReactProp;
8
-
9
4
  import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
-
12
- import java.util.HashMap;
13
5
 
14
- public class SkiaPictureViewManager extends BaseViewManager<SkiaPictureView, LayoutShadowNode> {
6
+ public class SkiaPictureViewManager extends SkiaBaseViewManager {
15
7
 
16
8
  @NonNull
17
9
  @Override
@@ -19,46 +11,9 @@ public class SkiaPictureViewManager extends BaseViewManager<SkiaPictureView, Lay
19
11
  return "SkiaPictureView";
20
12
  }
21
13
 
22
- @Override
23
- public LayoutShadowNode createShadowNodeInstance() {
24
- return new LayoutShadowNode();
25
- }
26
-
27
- @Override
28
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
29
- return LayoutShadowNode.class;
30
- }
31
-
32
- @Override
33
- public void updateExtraData(SkiaPictureView root, Object extraData) {
34
- }
35
-
36
- @Override
37
- public void setNativeId(@NonNull SkiaPictureView view, @Nullable String nativeId) {
38
- super.setNativeId(view, nativeId);
39
- int nativeIdResolved = Integer.parseInt(nativeId);
40
- view.registerView(nativeIdResolved);
41
- }
42
-
43
- @ReactProp(name = "mode")
44
- public void setMode(SkiaPictureView view, String mode) {
45
- view.setMode(mode);
46
- }
47
-
48
- @ReactProp(name = "debug")
49
- public void setDebug(SkiaPictureView view, boolean show) {
50
- view.setDebugMode(show);
51
- }
52
-
53
- @Override
54
- public void onDropViewInstance(@NonNull SkiaPictureView view) {
55
- super.onDropViewInstance(view);
56
- view.unregisterView();
57
- }
58
-
59
14
  @NonNull
60
15
  @Override
61
- protected SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
62
17
  return new SkiaPictureView(reactContext);
63
18
  }
64
19
  }
@@ -116,7 +116,7 @@ public:
116
116
  /**
117
117
  Returns the derived value
118
118
  */
119
- std::shared_ptr<T> getDerivedValue() { return _derivedValue; }
119
+ std::shared_ptr<const T> getDerivedValue() { return _derivedValue; }
120
120
 
121
121
  /**
122
122
  Returns true if is optional and one of the child props has a value, or all
@@ -128,7 +128,7 @@ protected:
128
128
  /**
129
129
  Set derived value from sub classes
130
130
  */
131
- void setDerivedValue(std::shared_ptr<T> value) {
131
+ void setDerivedValue(std::shared_ptr<const T> value) {
132
132
  setIsChanged(_derivedValue != value);
133
133
  _derivedValue = value;
134
134
  }
@@ -138,11 +138,11 @@ protected:
138
138
  */
139
139
  void setDerivedValue(const T &&value) {
140
140
  setIsChanged(true);
141
- _derivedValue = std::make_shared<T>(std::move(value));
141
+ _derivedValue = std::make_shared<const T>(std::move(value));
142
142
  }
143
143
 
144
144
  private:
145
- std::shared_ptr<T> _derivedValue;
145
+ std::shared_ptr<const T> _derivedValue;
146
146
  };
147
147
 
148
148
  /**
@@ -81,8 +81,8 @@ protected:
81
81
  }
82
82
 
83
83
  private:
84
- SkRRect inflate(const SkRRect &box, SkScalar dx, SkScalar dy, size_t tx = 0,
85
- size_t ty = 0) {
84
+ SkRRect inflate(const SkRRect &box, SkScalar dx, SkScalar dy, SkScalar tx = 0,
85
+ SkScalar ty = 0) {
86
86
  return SkRRect::MakeRectXY(
87
87
  SkRect::MakeXYWH(box.rect().x() - dx + tx, box.rect().y() - dy + ty,
88
88
  box.rect().width() + 2 * dx,
@@ -90,8 +90,8 @@ private:
90
90
  box.getSimpleRadii().x() + dx, box.getSimpleRadii().y() + dy);
91
91
  }
92
92
 
93
- SkRRect deflate(const SkRRect &box, SkScalar dx, SkScalar dy, size_t tx = 0,
94
- size_t ty = 0) {
93
+ SkRRect deflate(const SkRRect &box, SkScalar dx, SkScalar dy, SkScalar tx = 0,
94
+ SkScalar ty = 0) {
95
95
  return inflate(box, -dx, -dy, tx, ty);
96
96
  }
97
97
 
@@ -59,20 +59,22 @@ protected:
59
59
  ", end: " + std::to_string(_endProp->value().getAsNumber()));
60
60
  }
61
61
  filteredPath.swap(filteredPath);
62
- _path = std::make_shared<SkPath>(filteredPath);
62
+ _path = std::make_shared<const SkPath>(filteredPath);
63
63
  } else if (hasStartOffset || hasEndOffset) {
64
64
  throw std::runtime_error(
65
65
  "Failed trimming path with parameters start: " +
66
66
  std::to_string(_startProp->value().getAsNumber()) +
67
67
  ", end: " + std::to_string(_endProp->value().getAsNumber()));
68
68
  } else {
69
- _path = std::make_shared<SkPath>(filteredPath);
69
+ _path = std::make_shared<const SkPath>(filteredPath);
70
70
  }
71
71
 
72
72
  // Set fill style
73
73
  if (_fillTypeProp->isSet()) {
74
74
  auto fillType = _fillTypeProp->value().getAsString();
75
- _path->setFillType(getFillTypeFromStringValue(fillType));
75
+ auto p = std::make_shared<SkPath>(*_path.get());
76
+ p->setFillType(getFillTypeFromStringValue(fillType));
77
+ _path = std::const_pointer_cast<const SkPath>(p);
76
78
  }
77
79
 
78
80
  // do we have a special paint here?
@@ -105,9 +107,14 @@ protected:
105
107
  precision = opts.getValue(PropNamePrecision).getAsNumber();
106
108
  }
107
109
 
108
- if (!strokePaint.getFillPath(*_path.get(), _path.get(), nullptr,
110
+ // _path is const so we can't mutate it directly, let's replace the
111
+ // path like this:
112
+ auto p = std::make_shared<SkPath>(*_path.get());
113
+ if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr,
109
114
  precision)) {
110
115
  _path = nullptr;
116
+ } else {
117
+ _path = std::const_pointer_cast<const SkPath>(p);
111
118
  }
112
119
  }
113
120
 
@@ -157,7 +164,7 @@ private:
157
164
  NodeProp *_fillTypeProp;
158
165
  NodeProp *_strokeOptsProp;
159
166
 
160
- std::shared_ptr<SkPath> _path;
167
+ std::shared_ptr<const SkPath> _path;
161
168
  };
162
169
 
163
170
  class StrokeOptsProps : public BaseDerivedProp {
@@ -121,8 +121,16 @@ protected:
121
121
  if (rect != nullptr && lm != nullptr) {
122
122
  auto rc = _imageProps->getDerivedValue();
123
123
  auto m3 = _imageProps->rect2rect(rc->src, rc->dst);
124
- lm->preTranslate(m3.x(), m3.y());
125
- lm->preScale(m3.width(), m3.height());
124
+ if (_transformProp->isChanged()) {
125
+ // To modify the matrix we need to copy it since we're not allowed to
126
+ // modify values contained in properties - this would have caused the
127
+ // matrix to be translated and scaled more and more for each render
128
+ // even thought the matrix prop did not change.
129
+ _matrix.reset();
130
+ _matrix.preConcat(*lm);
131
+ _matrix.preTranslate(m3.x(), m3.y());
132
+ _matrix.preScale(m3.width(), m3.height());
133
+ }
126
134
  }
127
135
 
128
136
  setShader(
@@ -133,7 +141,7 @@ protected:
133
141
  _filterModeProp->value().getAsString()),
134
142
  getMipmapModeFromString(
135
143
  _mipmapModeProp->value().getAsString())),
136
- lm));
144
+ &_matrix));
137
145
  }
138
146
  }
139
147
 
@@ -185,6 +193,8 @@ private:
185
193
  "\" is not a valid Mipmap Mode.");
186
194
  }
187
195
 
196
+ SkMatrix _matrix;
197
+
188
198
  TileModeProp *_txProp;
189
199
  TileModeProp *_tyProp;
190
200
  NodeProp *_filterModeProp;
@@ -328,12 +338,12 @@ protected:
328
338
  }
329
339
  }
330
340
 
331
- SkColor *_colors;
332
- SkTileMode _mode;
341
+ const SkColor *_colors;
333
342
  double _flags;
334
- SkScalar *_positions;
335
- SkMatrix *_matrix;
336
343
  int _colorCount;
344
+ SkTileMode _mode;
345
+ const SkScalar *_positions;
346
+ const SkMatrix *_matrix;
337
347
 
338
348
  private:
339
349
  TransformsProps *_transformsProps;
@@ -45,18 +45,18 @@ public:
45
45
  return _pathProp->isSet() || _rectProp->isSet() || _rrectProp->isSet();
46
46
  }
47
47
 
48
- SkPath *getPath() { return _path.get(); }
49
- SkRect *getRect() { return _rect.get(); }
50
- SkRRect *getRRect() { return _rrect.get(); }
48
+ const SkPath *getPath() { return _path.get(); }
49
+ const SkRect *getRect() { return _rect.get(); }
50
+ const SkRRect *getRRect() { return _rrect.get(); }
51
51
 
52
52
  private:
53
53
  PathProp *_pathProp;
54
54
  RectProp *_rectProp;
55
55
  RRectProp *_rrectProp;
56
56
 
57
- std::shared_ptr<SkPath> _path;
58
- std::shared_ptr<SkRect> _rect;
59
- std::shared_ptr<SkRRect> _rrect;
57
+ std::shared_ptr<const SkPath> _path;
58
+ std::shared_ptr<const SkRect> _rect;
59
+ std::shared_ptr<const SkRRect> _rrect;
60
60
  };
61
61
 
62
62
  } // namespace RNSkia
@@ -74,7 +74,9 @@ public:
74
74
  }
75
75
 
76
76
  sk_sp<SkImage> getImage() { return _imageProp->getDerivedValue(); }
77
- std::shared_ptr<SkRect> getRect() { return _rectProp->getDerivedValue(); }
77
+ std::shared_ptr<const SkRect> getRect() {
78
+ return _rectProp->getDerivedValue();
79
+ }
78
80
 
79
81
  SkRect rect2rect(SkRect src, SkRect dst) {
80
82
  auto scaleX = dst.width() / src.width();
@@ -19,8 +19,6 @@
19
19
 
20
20
  namespace RNSkia {
21
21
 
22
- static PropId PropNameCurrent = JsiPropId::get("current");
23
-
24
22
  class PaintProp : public DerivedProp<SkPaint> {
25
23
  public:
26
24
  explicit PaintProp(PropId name) : DerivedProp<SkPaint>() {
@@ -40,20 +38,6 @@ public:
40
38
  throw std::runtime_error("Expected SkPaint object, got unknown "
41
39
  "object when reading paint property.");
42
40
  }
43
- } else if (_paintProp->value().getType() == PropType::Object) {
44
- // We have a JS object - is it a ref?
45
- auto ref = _paintProp->value().getValue(PropNameCurrent);
46
- if (ref.getType() == PropType::HostObject) {
47
- auto ptr = ref.getAs<JsiSkPaint>();
48
- if (ptr != nullptr) {
49
- // Update the local paint for the current context
50
- setDerivedValue(ptr->getObject());
51
- } else {
52
- throw std::runtime_error(
53
- "Expected reference to a SkPaint object, got unknown object "
54
- "when reading paint property.");
55
- }
56
- }
57
41
  } else {
58
42
  setDerivedValue(nullptr);
59
43
  }
@@ -40,9 +40,9 @@ public:
40
40
  bool hasColors() { return _colorsProp->isSet(); }
41
41
 
42
42
  void updateDerivedValue() override {
43
- SkVertices::VertexMode *vertextMode =
43
+ const SkVertices::VertexMode *vertextMode =
44
44
  _vertexModeProp->getDerivedValue().get();
45
- std::vector<SkColor> *colors = _colorsProp->getDerivedValue().get();
45
+ const std::vector<SkColor> *colors = _colorsProp->getDerivedValue().get();
46
46
  auto vertices = _verticesProp->getDerivedValue();
47
47
  auto textures = _texturesProp->getDerivedValue();
48
48
  auto indices = _indicesProp->getDerivedValue();
@@ -27,7 +27,7 @@ const deflate = function (Skia, box, dx, dy) {
27
27
 
28
28
  class BoxShadowNode extends _Node.JsiDeclarationNode {
29
29
  constructor(ctx, props) {
30
- super(ctx, _types2.DeclarationType.Unknown, _types2.NodeType.Box, props);
30
+ super(ctx, _types2.DeclarationType.Unknown, _types2.NodeType.BoxShadow, props);
31
31
  }
32
32
 
33
33
  materialize() {
@@ -1 +1 @@
1
- {"version":3,"names":["inflate","Skia","box","dx","dy","tx","ty","RRectXY","XYWHRect","rect","x","y","width","height","rx","ry","deflate","BoxShadowNode","JsiDeclarationNode","constructor","ctx","props","DeclarationType","Unknown","NodeType","Box","materialize","BoxNode","JsiRenderNode","renderNode","canvas","paint","defaultBox","opacity","getAlphaf","isRRect","shadows","_children","map","node","filter","n","shadow","inner","color","blur","spread","lPaint","Paint","setColor","Color","setAlphaf","setMaskFilter","MaskFilter","MakeBlur","BlurStyle","Normal","drawRRect","delta","Point","Math","abs","save","clipRRect","ClipOp","Intersect","outer","drawDRRect","restore"],"sources":["Box.ts"],"sourcesContent":["import type { SkRRect, Skia } from \"../../../skia/types\";\nimport { BlurStyle, ClipOp, isRRect } from \"../../../skia/types\";\nimport type { DrawingContext } from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport type { BoxShadowProps, BoxProps } from \"../../types/Drawings\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport { JsiRenderNode } from \"../RenderNode\";\n\nconst inflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) =>\n Skia.RRectXY(\n Skia.XYWHRect(\n box.rect.x - dx + tx,\n box.rect.y - dy + ty,\n box.rect.width + 2 * dx,\n box.rect.height + 2 * dy\n ),\n box.rx + dx,\n box.ry + dy\n );\n\nconst deflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) => inflate(Skia, box, -dx, -dy, tx, ty);\n\nexport class BoxShadowNode extends JsiDeclarationNode<\n BoxShadowProps,\n BoxShadowProps\n> {\n constructor(ctx: NodeContext, props: BoxShadowProps) {\n super(ctx, DeclarationType.Unknown, NodeType.Box, props);\n }\n\n materialize() {\n return this.props;\n }\n}\n\nexport class BoxNode extends JsiRenderNode<BoxProps> {\n constructor(ctx: NodeContext, props: BoxProps) {\n super(ctx, NodeType.Box, props);\n }\n\n renderNode({ canvas, paint }: DrawingContext) {\n const { box: defaultBox } = this.props;\n const opacity = paint.getAlphaf();\n const box = isRRect(defaultBox)\n ? defaultBox\n : this.Skia.RRectXY(defaultBox, 0, 0);\n const shadows = this._children\n .map((node) => {\n if (node instanceof BoxShadowNode) {\n return node.materialize();\n }\n return null;\n })\n .filter((n): n is BoxShadowProps => n !== null);\n shadows\n .filter((shadow) => !shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n canvas.drawRRect(\n inflate(this.Skia, box, spread, spread, dx, dy),\n lPaint\n );\n });\n\n canvas.drawRRect(box, paint);\n\n shadows\n .filter((shadow) => shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const delta = this.Skia.Point(10 + Math.abs(dx), 10 + Math.abs(dy));\n canvas.save();\n canvas.clipRRect(box, ClipOp.Intersect, false);\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n const inner = deflate(this.Skia, box, spread, spread, dx, dy);\n const outer = inflate(this.Skia, box, delta.x, delta.y);\n canvas.drawDRRect(outer, inner, lPaint);\n canvas.restore();\n });\n }\n}\n"],"mappings":";;;;;;;AACA;;AAEA;;AAGA;;AACA;;AAEA,MAAMA,OAAO,GAAG,UACdC,IADc,EAEdC,GAFc,EAGdC,EAHc,EAIdC,EAJc;EAAA,IAKdC,EALc,uEAKT,CALS;EAAA,I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BD,KAAlB,EAAyBvB,KAAzB,EAAgCI,MAAhC;MACAjB,MAAM,CAACsC,OAAP;IACD,CAlBH;EAmBD;;AAxDkD"}
1
+ {"version":3,"names":["inflate","Skia","box","dx","dy","tx","ty","RRectXY","XYWHRect","rect","x","y","width","height","rx","ry","deflate","BoxShadowNode","JsiDeclarationNode","constructor","ctx","props","DeclarationType","Unknown","NodeType","BoxShadow","materialize","BoxNode","JsiRenderNode","Box","renderNode","canvas","paint","defaultBox","opacity","getAlphaf","isRRect","shadows","_children","map","node","filter","n","shadow","inner","color","blur","spread","lPaint","Paint","setColor","Color","setAlphaf","setMaskFilter","MaskFilter","MakeBlur","BlurStyle","Normal","drawRRect","delta","Point","Math","abs","save","clipRRect","ClipOp","Intersect","outer","drawDRRect","restore"],"sources":["Box.ts"],"sourcesContent":["import type { SkRRect, Skia } from \"../../../skia/types\";\nimport { BlurStyle, ClipOp, isRRect } from \"../../../skia/types\";\nimport type { DrawingContext } from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport type { BoxShadowProps, BoxProps } from \"../../types/Drawings\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport { JsiRenderNode } from \"../RenderNode\";\n\nconst inflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) =>\n Skia.RRectXY(\n Skia.XYWHRect(\n box.rect.x - dx + tx,\n box.rect.y - dy + ty,\n box.rect.width + 2 * dx,\n box.rect.height + 2 * dy\n ),\n box.rx + dx,\n box.ry + dy\n );\n\nconst deflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) => inflate(Skia, box, -dx, -dy, tx, ty);\n\nexport class BoxShadowNode extends JsiDeclarationNode<\n BoxShadowProps,\n BoxShadowProps\n> {\n constructor(ctx: NodeContext, props: BoxShadowProps) {\n super(ctx, DeclarationType.Unknown, NodeType.BoxShadow, props);\n }\n\n materialize() {\n return this.props;\n }\n}\n\nexport class BoxNode extends JsiRenderNode<BoxProps> {\n constructor(ctx: NodeContext, props: BoxProps) {\n super(ctx, NodeType.Box, props);\n }\n\n renderNode({ canvas, paint }: DrawingContext) {\n const { box: defaultBox } = this.props;\n const opacity = paint.getAlphaf();\n const box = isRRect(defaultBox)\n ? defaultBox\n : this.Skia.RRectXY(defaultBox, 0, 0);\n const shadows = this._children\n .map((node) => {\n if (node instanceof BoxShadowNode) {\n return node.materialize();\n }\n return null;\n })\n .filter((n): n is BoxShadowProps => n !== null);\n shadows\n .filter((shadow) => !shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n canvas.drawRRect(\n inflate(this.Skia, box, spread, spread, dx, dy),\n lPaint\n );\n });\n\n canvas.drawRRect(box, paint);\n\n shadows\n .filter((shadow) => shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const delta = this.Skia.Point(10 + Math.abs(dx), 10 + Math.abs(dy));\n canvas.save();\n canvas.clipRRect(box, ClipOp.Intersect, false);\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n const inner = deflate(this.Skia, box, spread, spread, dx, dy);\n const outer = inflate(this.Skia, box, delta.x, delta.y);\n canvas.drawDRRect(outer, inner, lPaint);\n canvas.restore();\n });\n }\n}\n"],"mappings":";;;;;;;AACA;;AAEA;;AAGA;;AACA;;AAEA,MAAMA,OAAO,GAAG,UACdC,IADc,EAEdC,GAFc,EAGdC,EAHc,EAIdC,EA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C,CAArB;MACAoB,MAAM,CAACqC,UAAP,CAAkBD,KAAlB,EAAyBvB,KAAzB,EAAgCI,MAAhC;MACAjB,MAAM,CAACsC,OAAP;IACD,CAlBH;EAmBD;;AAxDkD"}
@@ -122,7 +122,7 @@ exports.BlurImageFilterNode = BlurImageFilterNode;
122
122
 
123
123
  class DropShadowImageFilterNode extends ImageFilterDeclaration {
124
124
  constructor(ctx, props) {
125
- super(ctx, _types2.NodeType.BlurImageFilter, props);
125
+ super(ctx, _types2.NodeType.DropShadowImageFilter, props);
126
126
  }
127
127
 
128
128
  materialize() {
@@ -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","getOptionalChildInstance","index","child","_children","getMandatoryChildInstance","isImageFilter","materialize","isShader","MakeShader","declarationType","Error","OffsetImageFilterNode","NodeType","OffsetImageFilter","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","MakeDisplacementMap","ColorChannel","enumKey","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","processRadius","DropShadowImageFilterNode","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 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<\n P,\n Nullable extends null | never = never\n> extends JsiDeclarationNode<P, SkImageFilter, Nullable> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n getOptionalChildInstance(index: number) {\n const child = this._children[index];\n if (!child) {\n return null;\n }\n return this.getMandatoryChildInstance(index);\n }\n\n getMandatoryChildInstance(index: number) {\n const child = this._children[index];\n if (child instanceof JsiDeclarationNode) {\n if (child.isImageFilter()) {\n return child.materialize();\n } else if (child.isShader()) {\n return this.Skia.ImageFilter.MakeShader(child.materialize(), null);\n } else if (child.declarationType === DeclarationType.ColorFilter) {\n return this.Skia.ImageFilter.MakeColorFilter(child.materialize(), null);\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n materialize() {\n const { x, y } = this.props;\n return this.Skia.ImageFilter.MakeOffset(\n x,\n y,\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n materialize() {\n const { channelX, channelY, scale } = this.props;\n return this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n this.getMandatoryChildInstance(0),\n this.getOptionalChildInstance(1)\n );\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n return this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n const input = this.getOptionalChildInstance(0);\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 return factory(dx, dy, blur, blur, color, input);\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 materialize() {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n const input = this.getOptionalChildInstance(0);\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n return this.Skia.ImageFilter.MakeErode(r.x, r.y, input);\n }\n return this.Skia.ImageFilter.MakeDilate(r.x, r.y, input);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n materialize() {\n const { mode } = this.props;\n const a = this.getMandatoryChildInstance(0);\n const b = this.getMandatoryChildInstance(1);\n return this.Skia.ImageFilter.MakeBlend(mode, a, b);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n materialize() {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const input = this.getOptionalChildInstance(0);\n return this.Skia.ImageFilter.MakeRuntimeShader(rtb, null, input);\n }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ACC,GAAD,EAAmBE,KAAnB,EAAiD;IAC1D,MAAMF,GAAN,EAAWgB,gBAAA,CAASoC,gBAApB,EAAsClD,KAAtC;EACD;;EAEDQ,WAAW,GAAG;IACZ,MAAM;MAAEoB;IAAF,IAAW,KAAK5B,KAAtB;IACA,MAAMmD,CAAC,GAAG,KAAK7C,yBAAL,CAA+B,CAA/B,CAAV;IACA,MAAM8C,CAAC,GAAG,KAAK9C,yBAAL,CAA+B,CAA/B,CAAV;IACA,OAAO,KAAKvC,IAAL,CAAUS,WAAV,CAAsBG,SAAtB,CAAgCiD,IAAhC,EAAsCuB,CAAtC,EAAyCC,CAAzC,CAAP;EACD;;AAVqF;;;;AAajF,MAAMC,4BAAN,SAA2C1D,sBAA3C,CAAiG;EACtGE,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAyD;IAClE,MAAMF,GAAN,EAAWgB,gBAAA,CAASwC,wBAApB,EAA8CtD,KAA9C;EACD;;EAEDQ,WAAW,GAAG;IACZ,MAAM;MAAE+C,MAAF;MAAUC;IAAV,IAAuB,KAAKxD,KAAlC;IACA,MAAMyD,GAAG,GAAG,KAAK1F,IAAL,CAAU2F,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZ,IAAAG,sBAAA,EAAgBJ,MAAhB,EAAwBC,QAAxB,EAAkCC,GAAlC;IACD;;IACD,MAAMnF,KAAK,GAAG,KAAK4B,wBAAL,CAA8B,CAA9B,CAAd;IACA,OAAO,KAAKnC,IAAL,CAAUS,WAAV,CAAsBoF,iBAAtB,CAAwCH,GAAxC,EAA6C,IAA7C,EAAmDnF,KAAnD,CAAP;EACD;;AAbqG"}
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","getOptionalChildInstance","index","child","_children","getMandatoryChildInstance","isImageFilter","materialize","isShader","MakeShader","declarationType","Error","OffsetImageFilterNode","NodeType","OffsetImageFilter","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","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 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<\n P,\n Nullable extends null | never = never\n> extends JsiDeclarationNode<P, SkImageFilter, Nullable> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n getOptionalChildInstance(index: number) {\n const child = this._children[index];\n if (!child) {\n return null;\n }\n return this.getMandatoryChildInstance(index);\n }\n\n getMandatoryChildInstance(index: number) {\n const child = this._children[index];\n if (child instanceof JsiDeclarationNode) {\n if (child.isImageFilter()) {\n return child.materialize();\n } else if (child.isShader()) {\n return this.Skia.ImageFilter.MakeShader(child.materialize(), null);\n } else if (child.declarationType === DeclarationType.ColorFilter) {\n return this.Skia.ImageFilter.MakeColorFilter(child.materialize(), null);\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n materialize() {\n const { x, y } = this.props;\n return this.Skia.ImageFilter.MakeOffset(\n x,\n y,\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n materialize() {\n const { channelX, channelY, scale } = this.props;\n return this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n this.getMandatoryChildInstance(0),\n this.getOptionalChildInstance(1)\n );\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n return this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.DropShadowImageFilter, props);\n }\n\n materialize() {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n const input = this.getOptionalChildInstance(0);\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 return factory(dx, dy, blur, blur, color, input);\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 materialize() {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n const input = this.getOptionalChildInstance(0);\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n return this.Skia.ImageFilter.MakeErode(r.x, r.y, input);\n }\n return this.Skia.ImageFilter.MakeDilate(r.x, r.y, input);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n materialize() {\n const { mode } = this.props;\n const a = this.getMandatoryChildInstance(0);\n const b = this.getMandatoryChildInstance(1);\n return this.Skia.ImageFilter.MakeBlend(mode, a, b);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n materialize() {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const input = this.getOptionalChildInstance(0);\n return this.Skia.ImageFilter.MakeRuntimeShader(rtb, null, input);\n }\n}\n"],"mappings":";;;;;;;AACA;;AAeA;;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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