@shopify/react-native-skia 0.1.178 → 0.1.181

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/android/build.gradle +6 -1
  2. package/cpp/jsi/RuntimeAwareCache.cpp +0 -2
  3. package/cpp/rnskia/RNSkDomView.cpp +2 -2
  4. package/cpp/rnskia/RNSkPlatformContext.h +2 -2
  5. package/cpp/rnskia/RNSkView.h +5 -3
  6. package/cpp/rnskia/dom/base/JsiDependencyManager.h +10 -6
  7. package/cpp/rnskia/dom/base/JsiDomNode.h +133 -78
  8. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +8 -8
  9. package/cpp/rnskia/dom/base/NodeProp.h +5 -5
  10. package/cpp/rnskia/dom/base/NodePropsContainer.h +7 -1
  11. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +10 -9
  12. package/cpp/rnskia/dom/props/ClipProp.h +13 -20
  13. package/cpp/rnskia/dom/props/PathProp.h +16 -14
  14. package/cpp/rnskia/dom/props/PointProp.h +1 -1
  15. package/cpp/rnskia/dom/props/RRectProp.h +39 -61
  16. package/cpp/rnskia/dom/props/RectProp.h +27 -25
  17. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -2
  18. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +10 -2
  19. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  20. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +2 -2
  21. package/lib/commonjs/external/reanimated/moduleWrapper.js +33 -37
  22. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
  23. package/lib/commonjs/external/reanimated/renderHelpers.js +2 -6
  24. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  25. package/lib/commonjs/external/reanimated/useSharedValueEffect.js +1 -1
  26. package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +1 -1
  27. package/lib/commonjs/views/SkiaBaseWebView.js +5 -1
  28. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  29. package/lib/module/dom/nodes/paint/ImageFilters.js +10 -2
  30. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  31. package/lib/module/external/reanimated/moduleWrapper.d.ts +2 -2
  32. package/lib/module/external/reanimated/moduleWrapper.js +31 -32
  33. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
  34. package/lib/module/external/reanimated/renderHelpers.js +3 -7
  35. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  36. package/lib/module/external/reanimated/useSharedValueEffect.js +2 -2
  37. package/lib/module/external/reanimated/useSharedValueEffect.js.map +1 -1
  38. package/lib/module/views/SkiaBaseWebView.js +5 -1
  39. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  40. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +2 -2
  41. package/package.json +1 -1
  42. package/src/dom/nodes/paint/ImageFilters.ts +8 -2
  43. package/src/external/reanimated/moduleWrapper.ts +36 -38
  44. package/src/external/reanimated/renderHelpers.ts +3 -7
  45. package/src/external/reanimated/useSharedValueEffect.ts +2 -2
  46. package/src/views/SkiaBaseWebView.tsx +5 -0
@@ -33,35 +33,33 @@ public:
33
33
  _prop = defineProperty<NodeProp>(name);
34
34
  }
35
35
 
36
- void updateDerivedValue() override {
37
- if (_prop->isSet()) {
38
- // Check for JsiSkRRect
39
- if (_prop->value().getType() == PropType::HostObject) {
40
- // Try reading as rect
41
- auto rectPtr = std::dynamic_pointer_cast<JsiSkRRect>(
42
- _prop->value().getAsHostObject());
43
- if (rectPtr != nullptr) {
44
- auto rrect = rectPtr->getObject();
45
- setDerivedValue(SkRRect::MakeRectXY(
46
- SkRect::MakeXYWH(rrect->rect().x(), rrect->rect().y(),
47
- rrect->rect().width(), rrect->rect().height()),
48
- rrect->getSimpleRadii().x(), rrect->getSimpleRadii().y()));
49
- }
50
- } else {
51
- if (_prop->isSet() && _prop->value().getType() == PropType::Object) {
52
- auto p = _prop->value();
53
- if (p.hasValue(PropNameX) && p.hasValue(PropNameY) &&
54
- p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight) &&
55
- p.hasValue(PropNameRx) && p.hasValue(PropNameRy)) {
56
- auto x = _prop->value().getValue(PropNameX);
57
- auto y = _prop->value().getValue(PropNameY);
58
- auto width = _prop->value().getValue(PropNameWidth);
59
- auto height = _prop->value().getValue(PropNameHeight);
60
- auto rx = _prop->value().getValue(PropNameRx);
61
- auto ry = _prop->value().getValue(PropNameRy);
36
+ static std::shared_ptr<SkRRect> processRRect(const JsiValue &value) {
37
+ if (value.getType() == PropType::HostObject) {
38
+ // Try reading as rect
39
+ auto rectPtr =
40
+ std::dynamic_pointer_cast<JsiSkRRect>(value.getAsHostObject());
41
+ if (rectPtr != nullptr) {
42
+ auto rrect = rectPtr->getObject();
43
+ return std::make_shared<SkRRect>(
44
+ SkRRect::MakeRectXY(rrect->rect(), rrect->getSimpleRadii().x(),
45
+ rrect->getSimpleRadii().y()));
46
+ }
47
+ } else {
48
+ if (value.getType() == PropType::Object) {
49
+ if (value.hasValue(PropNameRect) && value.hasValue(PropNameRx) &&
50
+ value.hasValue(PropNameRy)) {
51
+ auto rect = value.getValue(PropNameRect);
52
+ if (rect.hasValue(PropNameX) && rect.hasValue(PropNameY) &&
53
+ rect.hasValue(PropNameWidth) && rect.hasValue(PropNameHeight)) {
54
+ auto x = rect.getValue(PropNameX);
55
+ auto y = rect.getValue(PropNameY);
56
+ auto width = rect.getValue(PropNameWidth);
57
+ auto height = rect.getValue(PropNameHeight);
58
+ auto rx = value.getValue(PropNameRx);
59
+ auto ry = value.getValue(PropNameRy);
62
60
 
63
61
  // Update cache from js object value
64
- setDerivedValue(SkRRect::MakeRectXY(
62
+ return std::make_shared<SkRRect>(SkRRect::MakeRectXY(
65
63
  SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(),
66
64
  width.getAsNumber(), height.getAsNumber()),
67
65
  rx.getAsNumber(), ry.getAsNumber()));
@@ -69,6 +67,14 @@ public:
69
67
  }
70
68
  }
71
69
  }
70
+ return nullptr;
71
+ }
72
+
73
+ void updateDerivedValue() override {
74
+ if (_prop->isSet()) {
75
+ auto value = _prop->value();
76
+ setDerivedValue(RRectProp::processRRect(value));
77
+ }
72
78
  }
73
79
 
74
80
  private:
@@ -150,40 +156,12 @@ public:
150
156
  }
151
157
 
152
158
  void updateDerivedValue() override {
153
- if (_boxProp->value().getType() == PropType::HostObject) {
154
- auto rectPtr = std::dynamic_pointer_cast<JsiSkRect>(
155
- _boxProp->value().getAsHostObject());
156
- auto rrectPtr = std::dynamic_pointer_cast<JsiSkRRect>(
157
- _boxProp->value().getAsHostObject());
158
- // 1. box is SkRect
159
- if (rectPtr != nullptr) {
160
- auto rect = rectPtr->getObject();
161
- setDerivedValue(SkRRect::MakeRect(*rect));
162
- // 2. box is SkRRect
163
- } else if (rrectPtr != nullptr) {
164
- setDerivedValue(rrectPtr->getObject());
165
- }
166
- } else if (_boxProp->value().getType() == PropType::Object) {
167
- if (_boxProp->value().hasValue(PropNameRect)) {
168
- // 3. box is { rect: { x, y, width, height }, rx, ry }
169
- auto rectProp = _boxProp->value().getValue(PropNameRect);
170
- auto x = rectProp.getValue(PropNameX).getAsNumber();
171
- auto y = rectProp.getValue(PropNameY).getAsNumber();
172
- auto width = rectProp.getValue(PropNameWidth).getAsNumber();
173
- auto height = rectProp.getValue(PropNameHeight).getAsNumber();
174
- auto rx = _boxProp->value().getValue(PropNameRx).getAsNumber();
175
- auto ry = _boxProp->value().getValue(PropNameRy).getAsNumber();
176
- setDerivedValue(
177
- SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, width, height), rx, ry));
178
- } else {
179
- // 4. box is { x, y, width, height }
180
- auto x = _boxProp->value().getValue(PropNameX).getAsNumber();
181
- auto y = _boxProp->value().getValue(PropNameY).getAsNumber();
182
- auto width = _boxProp->value().getValue(PropNameWidth).getAsNumber();
183
- auto height = _boxProp->value().getValue(PropNameHeight).getAsNumber();
184
- setDerivedValue(
185
- SkRRect::MakeRect(SkRect::MakeXYWH(x, y, width, height)));
186
- }
159
+ auto value = _boxProp->value();
160
+ auto rect = RectProp::processRect(value);
161
+ if (rect) {
162
+ setDerivedValue(SkRRect::MakeRect(*rect));
163
+ } else {
164
+ setDerivedValue(RRectProp::processRRect(value));
187
165
  }
188
166
  }
189
167
 
@@ -31,33 +31,35 @@ public:
31
31
  _prop = defineProperty<NodeProp>(name);
32
32
  }
33
33
 
34
+ static std::shared_ptr<SkRect> processRect(const JsiValue &value) {
35
+ if (value.getType() == PropType::HostObject) {
36
+ auto rectPtr =
37
+ std::dynamic_pointer_cast<JsiSkRect>(value.getAsHostObject());
38
+ if (rectPtr != nullptr) {
39
+ return std::make_shared<SkRect>(SkRect::MakeXYWH(
40
+ rectPtr->getObject()->x(), rectPtr->getObject()->y(),
41
+ rectPtr->getObject()->width(), rectPtr->getObject()->height()));
42
+ }
43
+ } else if (value.getType() == PropType::Object &&
44
+ value.hasValue(PropNameX) && value.hasValue(PropNameY) &&
45
+ value.hasValue(PropNameWidth) &&
46
+ value.hasValue(PropNameHeight)) {
47
+ // Save props for fast access
48
+ auto x = value.getValue(PropNameX);
49
+ auto y = value.getValue(PropNameY);
50
+ auto width = value.getValue(PropNameWidth);
51
+ auto height = value.getValue(PropNameHeight);
52
+ // Update cache from js object value
53
+ return std::make_shared<SkRect>(
54
+ SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(),
55
+ width.getAsNumber(), height.getAsNumber()));
56
+ }
57
+ return nullptr;
58
+ }
59
+
34
60
  void updateDerivedValue() override {
35
61
  if (_prop->isSet()) {
36
- // Check for JsiSkRect
37
- if (_prop->value().getType() == PropType::HostObject) {
38
- auto rectPtr = std::dynamic_pointer_cast<JsiSkRect>(
39
- _prop->value().getAsHostObject());
40
- if (rectPtr != nullptr) {
41
- setDerivedValue(SkRect::MakeXYWH(
42
- rectPtr->getObject()->x(), rectPtr->getObject()->y(),
43
- rectPtr->getObject()->width(), rectPtr->getObject()->height()));
44
- }
45
- } else {
46
- auto p = _prop->value();
47
- if (p.hasValue(PropNameX) && p.hasValue(PropNameY) &&
48
- p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight)) {
49
- // Save props for fast access
50
- auto x = p.getValue(PropNameX);
51
- auto y = p.getValue(PropNameY);
52
- auto width = p.getValue(PropNameWidth);
53
- auto height = p.getValue(PropNameHeight);
54
-
55
- // Update cache from js object value
56
- setDerivedValue(SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(),
57
- width.getAsNumber(),
58
- height.getAsNumber()));
59
- }
60
- }
62
+ setDerivedValue(RectProp::processRect(_prop->value()));
61
63
  }
62
64
  }
63
65
 
@@ -4,7 +4,6 @@
4
4
  #include <thread>
5
5
  #include <utility>
6
6
 
7
- #include <RNSkMeasureTime.h>
8
7
  #include <SkiaMetalRenderer.h>
9
8
 
10
9
  #pragma clang diagnostic push
@@ -20,7 +19,6 @@ void RNSkiOSPlatformContext::performStreamOperation(
20
19
  const std::string &sourceUri,
21
20
  const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) {
22
21
 
23
- RNSkMeasureTime("PlatformContext::performStreamOperation");
24
22
  auto loader = [=]() {
25
23
  NSURL *url = [[NSURL alloc]
26
24
  initWithString:[NSString stringWithUTF8String:sourceUri.c_str()]];
@@ -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,MAAMM,EAAE,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/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,MAAMC,EAAE,G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,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,6 +1,6 @@
1
1
  import type { SharedValueType } from "../../renderer/processors/Animations";
2
- export declare const HAS_REANIMATED: boolean;
3
- export declare function throwOnIncompatibleReanimatedVersion(): void;
2
+ export declare const HAS_REANIMATED2: boolean;
3
+ export declare const HAS_REANIMATED3: boolean;
4
4
  export declare const useSharedValue: any;
5
5
  export declare const startMapper: any;
6
6
  export declare const stopMapper: any;
@@ -3,69 +3,65 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stopMapper = exports.startMapper = exports.runOnJS = exports.isSharedValue = exports.HAS_REANIMATED = void 0;
7
- exports.throwOnIncompatibleReanimatedVersion = throwOnIncompatibleReanimatedVersion;
8
- exports.useSharedValue = void 0;
6
+ exports.useSharedValue = exports.stopMapper = exports.startMapper = exports.runOnJS = exports.isSharedValue = exports.HAS_REANIMATED3 = exports.HAS_REANIMATED2 = void 0;
9
7
 
10
8
  var _react = require("react");
11
9
 
12
10
  var _Reanimated, _Reanimated2, _Reanimated3, _Reanimated4;
13
11
 
12
+ // This one is needed for the deprecated useSharedValue function
13
+ // We can remove it once we remove the deprecation
14
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- let Reanimated;
15
+ let Reanimated2; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
 
17
- try {
18
- Reanimated = require("react-native-reanimated");
19
- } catch (e) {// Ignore
20
- }
21
-
22
- const HAS_REANIMATED = !!Reanimated;
23
- exports.HAS_REANIMATED = HAS_REANIMATED;
17
+ let Reanimated3;
18
+ let reanimatedVersion;
24
19
 
25
- function throwOnMissingReanimated() {
26
- throw new Error("Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
27
- react-naitve-skia's integration layer API.");
28
- }
29
-
30
- let ReanimatedVersionTested = false;
20
+ try {
21
+ Reanimated2 = require("react-native-reanimated");
22
+ reanimatedVersion = // eslint-disable-next-line import/extensions
23
+ require("react-native-reanimated/package.json").version;
31
24
 
32
- function throwOnIncompatibleReanimatedVersion() {
33
- if (ReanimatedVersionTested) {
34
- // we avoid testing version more than once as it won't change and we throw
35
- // an error when version is incompatible
36
- return;
25
+ if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
26
+ Reanimated3 = Reanimated2;
37
27
  }
28
+ } catch (e) {}
38
29
 
39
- ReanimatedVersionTested = true;
40
-
41
- const reanimatedVersion = // eslint-disable-next-line import/extensions
42
- require("react-native-reanimated/package.json").version; // The first compatible version is 3.0.0 but we need to exclude 3.0.0 pre-releases
43
- // as they have limited support for the used API.
30
+ const HAS_REANIMATED2 = !!Reanimated2;
31
+ exports.HAS_REANIMATED2 = HAS_REANIMATED2;
32
+ const HAS_REANIMATED3 = !!Reanimated3;
33
+ exports.HAS_REANIMATED3 = HAS_REANIMATED3;
44
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
+ }
45
41
 
46
- if (!reanimatedVersion || reanimatedVersion < "3.0.0" || reanimatedVersion.includes("3.0.0-")) {
42
+ function throwOnMissingReanimated3() {
43
+ if (!HAS_REANIMATED3) {
47
44
  throw new Error(`Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`);
48
45
  }
46
+
47
+ throwOnMissingReanimated2();
49
48
  }
50
49
 
51
- const useSharedValue = ((_Reanimated = Reanimated) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) || (value => (0, _react.useMemo)(() => ({
50
+ const useSharedValue = ((_Reanimated = Reanimated2) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) || (value => (0, _react.useMemo)(() => ({
52
51
  value
53
52
  }), [value]));
54
53
 
55
54
  exports.useSharedValue = useSharedValue;
56
- const startMapper = ((_Reanimated2 = Reanimated) === null || _Reanimated2 === void 0 ? void 0 : _Reanimated2.startMapper) || throwOnMissingReanimated;
55
+ const startMapper = ((_Reanimated2 = Reanimated2) === null || _Reanimated2 === void 0 ? void 0 : _Reanimated2.startMapper) || throwOnMissingReanimated2;
57
56
  exports.startMapper = startMapper;
58
- const stopMapper = ((_Reanimated3 = Reanimated) === null || _Reanimated3 === void 0 ? void 0 : _Reanimated3.stopMapper) || throwOnMissingReanimated;
57
+ const stopMapper = ((_Reanimated3 = Reanimated2) === null || _Reanimated3 === void 0 ? void 0 : _Reanimated3.stopMapper) || throwOnMissingReanimated2;
59
58
  exports.stopMapper = stopMapper;
60
- const runOnJS = ((_Reanimated4 = Reanimated) === null || _Reanimated4 === void 0 ? void 0 : _Reanimated4.runOnJS) || throwOnMissingReanimated;
59
+ const runOnJS = ((_Reanimated4 = Reanimated2) === null || _Reanimated4 === void 0 ? void 0 : _Reanimated4.runOnJS) || throwOnMissingReanimated2;
61
60
  exports.runOnJS = runOnJS;
62
61
 
63
62
  const isSharedValue = value => {
64
- if (!Reanimated) {
65
- throwOnMissingReanimated();
66
- }
67
-
68
- return !!value && Reanimated.isSharedValue(value);
63
+ throwOnMissingReanimated3();
64
+ return !!value && Reanimated3.isSharedValue(value);
69
65
  };
70
66
 
71
67
  exports.isSharedValue = isSharedValue;
@@ -1 +1 @@
1
- {"version":3,"names":["Reanimated","require","e","HAS_REANIMATED","throwOnMissingReanimated","Error","ReanimatedVersionTested","throwOnIncompatibleReanimatedVersion","reanimatedVersion","version","includes","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// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Reanimated: any;\n\ntry {\n Reanimated = require(\"react-native-reanimated\");\n} catch (e) {\n // Ignore\n}\n\nexport const HAS_REANIMATED = !!Reanimated;\n\nfunction throwOnMissingReanimated() {\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\nlet ReanimatedVersionTested = false;\n\nexport function throwOnIncompatibleReanimatedVersion() {\n if (ReanimatedVersionTested) {\n // we avoid testing version more than once as it won't change and we throw\n // an error when version is incompatible\n return;\n }\n ReanimatedVersionTested = true;\n const reanimatedVersion =\n // eslint-disable-next-line import/extensions\n require(\"react-native-reanimated/package.json\").version;\n // The first compatible version is 3.0.0 but we need to exclude 3.0.0 pre-releases\n // as they have limited support for the used API.\n if (\n !reanimatedVersion ||\n reanimatedVersion < \"3.0.0\" ||\n reanimatedVersion.includes(\"3.0.0-\")\n ) {\n throw new Error(\n `Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`\n );\n }\n}\n\nexport const useSharedValue =\n Reanimated?.useSharedValue ||\n ((value: number) => useMemo(() => ({ value }), [value]));\n\nexport const startMapper = Reanimated?.startMapper || throwOnMissingReanimated;\nexport const stopMapper = Reanimated?.stopMapper || throwOnMissingReanimated;\nexport const runOnJS = Reanimated?.runOnJS || throwOnMissingReanimated;\nexport const isSharedValue = <T>(\n value: unknown\n): value is SharedValueType<T> => {\n if (!Reanimated) {\n throwOnMissingReanimated();\n }\n return !!value && Reanimated.isSharedValue(value);\n};\n"],"mappings":";;;;;;;;;AAAA;;;;AAIA;AACA,IAAIA,UAAJ;;AAEA,IAAI;EACFA,UAAU,GAAGC,OAAO,CAAC,yBAAD,CAApB;AACD,CAFD,CAEE,OAAOC,CAAP,EAAU,CACV;AACD;;AAEM,MAAMC,cAAc,GAAG,CAAC,CAACH,UAAzB;;;AAEP,SAASI,wBAAT,GAAoC;EAClC,MAAM,IAAIC,KAAJ,CACJ;AACJ,+CAFQ,CAAN;AAID;;AAED,IAAIC,uBAAuB,GAAG,KAA9B;;AAEO,SAASC,oCAAT,GAAgD;EACrD,IAAID,uBAAJ,EAA6B;IAC3B;IACA;IACA;EACD;;EACDA,uBAAuB,GAAG,IAA1B;;EACA,MAAME,iBAAiB,GACrB;EACAP,OAAO,CAAC,sCAAD,CAAP,CAAgDQ,OAFlD,CAPqD,CAUrD;EACA;;;EACA,IACE,CAACD,iBAAD,IACAA,iBAAiB,GAAG,OADpB,IAEAA,iBAAiB,CAACE,QAAlB,CAA2B,QAA3B,CAHF,EAIE;IACA,MAAM,IAAIL,KAAJ,CACH,sBAAqBG,iBAAkB,sDADpC,CAAN;EAGD;AACF;;AAEM,MAAMG,cAAc,GACzB,gBAAAX,UAAU,UAAV,kDAAYW,cAAZ,MACEC,KAAD,IAAmB,IAAAC,cAAA,EAAQ,OAAO;EAAED;AAAF,CAAP,CAAR,EAA2B,CAACA,KAAD,CAA3B,CADpB,CADK;;;AAIA,MAAME,WAAW,GAAG,iBAAAd,UAAU,UAAV,oDAAYc,WAAZ,KAA2BV,wBAA/C;;AACA,MAAMW,UAAU,GAAG,iBAAAf,UAAU,UAAV,oDAAYe,UAAZ,KAA0BX,wBAA7C;;AACA,MAAMY,OAAO,GAAG,iBAAAhB,UAAU,UAAV,oDAAYgB,OAAZ,KAAuBZ,wBAAvC;;;AACA,MAAMa,aAAa,GACxBL,KAD2B,IAEK;EAChC,IAAI,CAACZ,UAAL,EAAiB;IACfI,wBAAwB;EACzB;;EACD,OAAO,CAAC,CAACQ,KAAF,IAAWZ,UAAU,CAACiB,aAAX,CAAyBL,KAAzB,CAAlB;AACD,CAPM"}
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"}
@@ -14,7 +14,7 @@ var _moduleWrapper = require("./moduleWrapper");
14
14
  const _bindings = new WeakMap();
15
15
 
16
16
  function extractReanimatedProps(props) {
17
- if (!_moduleWrapper.HAS_REANIMATED) {
17
+ if (!_moduleWrapper.HAS_REANIMATED3) {
18
18
  return [props, {}];
19
19
  }
20
20
 
@@ -40,14 +40,10 @@ function extractReanimatedProps(props) {
40
40
  }
41
41
 
42
42
  function bindReanimatedProps(container, node, reanimatedProps) {
43
- if (!_moduleWrapper.HAS_REANIMATED) {
43
+ if (!_moduleWrapper.HAS_REANIMATED3) {
44
44
  return;
45
45
  }
46
46
 
47
- if (__DEV__) {
48
- (0, _moduleWrapper.throwOnIncompatibleReanimatedVersion)();
49
- }
50
-
51
47
  const sharedValues = Object.values(reanimatedProps);
52
48
 
53
49
  const previousMapperId = _bindings.get(node);
@@ -1 +1 @@
1
- {"version":3,"names":["_bindings","WeakMap","extractReanimatedProps","props","HAS_REANIMATED","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps","container","node","__DEV__","throwOnIncompatibleReanimatedVersion","sharedValues","Object","values","previousMapperId","get","undefined","stopMapper","length","viewId","getNativeId","SkiaViewApi","global","mapperId","startMapper","setProp","requestRedraw","redraw","set"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable reanimated/js-function-in-worklet */\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport {\n startMapper,\n stopMapper,\n isSharedValue,\n throwOnIncompatibleReanimatedVersion,\n HAS_REANIMATED,\n} from \"./moduleWrapper\";\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (!HAS_REANIMATED) {\n return;\n }\n if (__DEV__) {\n throwOnIncompatibleReanimatedVersion();\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = startMapper(() => {\n \"worklet\";\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":";;;;;;;;AAMA;;AANA;;AACA;AAaA,MAAMA,SAAS,GAAG,IAAIC,OAAJ,EAAlB;;AAEO,SAASC,sBAAT,CAAgCC,KAAhC,EAA2D;EAChE,IAAI,CAACC,6BAAL,EAAqB;IACnB,OAAO,CAACD,KAAD,EAAQ,EAAR,CAAP;EACD;;EACD,MAAME,eAAe,GAAG,EAAxB;EACA,MAAMC,UAAU,GAAG,EAAnB;;EACA,KAAK,MAAMC,QAAX,IAAuBJ,KAAvB,EAA8B;IAC5B,IAAII,QAAQ,KAAK,UAAjB,EAA6B;MAC3B;IACD;;IACD,MAAMC,SAAS,GAAGL,KAAK,CAACI,QAAD,CAAvB;;IACA,IAAI,IAAAE,4BAAA,EAAcD,SAAd,CAAJ,EAA8B;MAC5BH,eAAe,CAACE,QAAD,CAAf,GAA4BC,SAA5B;MACAF,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAS,CAACE,KAAjC;IACD,CAHD,MAGO;MACLJ,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAvB;IACD;EACF;;EACD,OAAO,CAACF,UAAD,EAAaD,eAAb,CAAP;AACD;;AAEM,SAASM,mBAAT,CACLC,SADK,EAELC,IAFK,EAGLR,eAHK,EAIL;EACA,IAAI,CAACD,6BAAL,EAAqB;IACnB;EACD;;EACD,IAAIU,OAAJ,EAAa;IACX,IAAAC,mDAAA;EACD;;EACD,MAAMC,YAAY,GAAGC,MAAM,CAACC,MAAP,CAAcb,eAAd,CAArB;;EACA,MAAMc,gBAAgB,GAAGnB,SAAS,CAACoB,GAAV,CAAcP,IAAd,CAAzB;;EACA,IAAIM,gBAAgB,KAAKE,SAAzB,EAAoC;IAClC,IAAAC,yBAAA,EAAWH,gBAAX;EACD;;EACD,IAAIH,YAAY,CAACO,MAAb,GAAsB,CAA1B,EAA6B;IAC3B,MAAMC,MAAM,GAAGZ,SAAS,CAACa,WAAV,EAAf;IACA,MAAM;MAAEC;IAAF,IAAkBC,MAAxB;IACA,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,EAAY,MAAM;MACjC;;MACA,KAAK,MAAMtB,QAAX,IAAuBF,eAAvB,EAAwC;QACtCQ,IAAI,IAAIA,IAAI,CAACiB,OAAL,CAAavB,QAAb,EAAuBF,eAAe,CAACE,QAAD,CAAf,CAA0BG,KAAjD,CAAR;MACD,CAJgC,CAKjC;MACA;MACA;MACA;;;MACA,IAAIgB,WAAJ,EAAiB;QACfA,WAAW,CAACK,aAAZ,CAA0BP,MAA1B;MACD,CAFD,MAEO;QACLZ,SAAS,CAACoB,MAAV;MACD;IACF,CAdgB,EAcdhB,YAdc,CAAjB;;IAeAhB,SAAS,CAACiC,GAAV,CAAcpB,IAAd,EAAoBe,QAApB;EACD;AACF"}
1
+ {"version":3,"names":["_bindings","WeakMap","extractReanimatedProps","props","HAS_REANIMATED3","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps","container","node","sharedValues","Object","values","previousMapperId","get","undefined","stopMapper","length","viewId","getNativeId","SkiaViewApi","global","mapperId","startMapper","setProp","requestRedraw","redraw","set"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable reanimated/js-function-in-worklet */\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport {\n startMapper,\n stopMapper,\n isSharedValue,\n HAS_REANIMATED3,\n} from \"./moduleWrapper\";\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED3) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (!HAS_REANIMATED3) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = startMapper(() => {\n \"worklet\";\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":";;;;;;;;AAMA;;AANA;;AACA;AAYA,MAAMA,SAAS,GAAG,IAAIC,OAAJ,EAAlB;;AAEO,SAASC,sBAAT,CAAgCC,KAAhC,EAA2D;EAChE,IAAI,CAACC,8BAAL,EAAsB;IACpB,OAAO,CAACD,KAAD,EAAQ,EAAR,CAAP;EACD;;EACD,MAAME,eAAe,GAAG,EAAxB;EACA,MAAMC,UAAU,GAAG,EAAnB;;EACA,KAAK,MAAMC,QAAX,IAAuBJ,KAAvB,EAA8B;IAC5B,IAAII,QAAQ,KAAK,UAAjB,EAA6B;MAC3B;IACD;;IACD,MAAMC,SAAS,GAAGL,KAAK,CAACI,QAAD,CAAvB;;IACA,IAAI,IAAAE,4BAAA,EAAcD,SAAd,CAAJ,EAA8B;MAC5BH,eAAe,CAACE,QAAD,CAAf,GAA4BC,SAA5B;MACAF,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAS,CAACE,KAAjC;IACD,CAHD,MAGO;MACLJ,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAvB;IACD;EACF;;EACD,OAAO,CAACF,UAAD,EAAaD,eAAb,CAAP;AACD;;AAEM,SAASM,mBAAT,CACLC,SADK,EAELC,IAFK,EAGLR,eAHK,EAIL;EACA,IAAI,CAACD,8BAAL,EAAsB;IACpB;EACD;;EACD,MAAMU,YAAY,GAAGC,MAAM,CAACC,MAAP,CAAcX,eAAd,CAArB;;EACA,MAAMY,gBAAgB,GAAGjB,SAAS,CAACkB,GAAV,CAAcL,IAAd,CAAzB;;EACA,IAAII,gBAAgB,KAAKE,SAAzB,EAAoC;IAClC,IAAAC,yBAAA,EAAWH,gBAAX;EACD;;EACD,IAAIH,YAAY,CAACO,MAAb,GAAsB,CAA1B,EAA6B;IAC3B,MAAMC,MAAM,GAAGV,SAAS,CAACW,WAAV,EAAf;IACA,MAAM;MAAEC;IAAF,IAAkBC,MAAxB;IACA,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,EAAY,MAAM;MACjC;;MACA,KAAK,MAAMpB,QAAX,IAAuBF,eAAvB,EAAwC;QACtCQ,IAAI,IAAIA,IAAI,CAACe,OAAL,CAAarB,QAAb,EAAuBF,eAAe,CAACE,QAAD,CAAf,CAA0BG,KAAjD,CAAR;MACD,CAJgC,CAKjC;MACA;MACA;MACA;;;MACA,IAAIc,WAAJ,EAAiB;QACfA,WAAW,CAACK,aAAZ,CAA0BP,MAA1B;MACD,CAFD,MAEO;QACLV,SAAS,CAACkB,MAAV;MACD;IACF,CAdgB,EAcdhB,YAdc,CAAjB;;IAeAd,SAAS,CAAC+B,GAAV,CAAclB,IAAd,EAAoBa,QAApB;EACD;AACF"}
@@ -24,7 +24,7 @@ const useSharedValueEffect = function (cb, value) {
24
24
  Learn more at https://shopify.github.io/react-native-skia/.`);
25
25
  const input = (0, _moduleWrapper.useSharedValue)(0);
26
26
  (0, _react.useEffect)(() => {
27
- if (!_moduleWrapper.HAS_REANIMATED) {
27
+ if (!_moduleWrapper.HAS_REANIMATED2) {
28
28
  console.warn("Reanimated was not found and the useSharedValueEffect hook will have no effect.");
29
29
  } else {
30
30
  // Start a mapper in Reanimated
@@ -1 +1 @@
1
- {"version":3,"names":["useSharedValueEffect","cb","value","values","console","warn","input","useSharedValue","useEffect","HAS_REANIMATED","mapperId","startMapper","runOnJS","stopMapper","undefined"],"sources":["useSharedValueEffect.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport type { SharedValueType } from \"../../renderer/processors/Animations\";\n\nimport {\n HAS_REANIMATED,\n useSharedValue,\n runOnJS,\n startMapper,\n stopMapper,\n} from \"./moduleWrapper\";\n\n/**\n * Connects a shared value from reanimated to a SkiaView or Canvas\n * so whenever the shared value changes the SkiaView will redraw.\n * @param cb Callback that will be called whenever the shared value changes.\n * @param values One or more shared values to listen for.\n */\nexport const useSharedValueEffect = <T = number>(\n cb: () => void,\n value: SharedValueType<T>,\n ...values: SharedValueType<T>[]\n) => {\n console.warn(\n `useSharedValueEffect() is now deprecated, you can use Reanimated values directly.\nLearn more at https://shopify.github.io/react-native-skia/.`\n );\n const input = useSharedValue(0);\n\n useEffect(() => {\n if (!HAS_REANIMATED) {\n console.warn(\n \"Reanimated was not found and the useSharedValueEffect hook will have no effect.\"\n );\n } else {\n // Start a mapper in Reanimated\n const mapperId = startMapper(\n () => {\n \"worklet\";\n runOnJS(cb)();\n },\n [value, ...values],\n [input]\n );\n // Return unregistering the mapper\n return () => {\n if (stopMapper && mapperId !== undefined) {\n stopMapper(mapperId);\n }\n };\n }\n return () => {};\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [input, value, ...values]);\n};\n"],"mappings":";;;;;;;AAAA;;AAIA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAG,UAClCC,EADkC,EAElCC,KAFkC,EAI/B;EAAA,kCADAC,MACA;IADAA,MACA;EAAA;;EACHC,OAAO,CAACC,IAAR,CACG;AACL,4DAFE;EAIA,MAAMC,KAAK,GAAG,IAAAC,6BAAA,EAAe,CAAf,CAAd;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,IAAI,CAACC,6BAAL,EAAqB;MACnBL,OAAO,CAACC,IAAR,CACE,iFADF;IAGD,CAJD,MAIO;MACL;MACA,MAAMK,QAAQ,GAAG,IAAAC,0BAAA,EACf,MAAM;QACJ;;QACA,IAAAC,sBAAA,EAAQX,EAAR;MACD,CAJc,EAKf,CAACC,KAAD,EAAQ,GAAGC,MAAX,CALe,EAMf,CAACG,KAAD,CANe,CAAjB,CAFK,CAUL;;MACA,OAAO,MAAM;QACX,IAAIO,yBAAA,IAAcH,QAAQ,KAAKI,SAA/B,EAA0C;UACxC,IAAAD,yBAAA,EAAWH,QAAX;QACD;MACF,CAJD;IAKD;;IACD,OAAO,MAAM,CAAE,CAAf,CAtBc,CAuBd;EACD,CAxBD,EAwBG,CAACJ,KAAD,EAAQJ,KAAR,EAAe,GAAGC,MAAlB,CAxBH;AAyBD,CApCM"}
1
+ {"version":3,"names":["useSharedValueEffect","cb","value","values","console","warn","input","useSharedValue","useEffect","HAS_REANIMATED2","mapperId","startMapper","runOnJS","stopMapper","undefined"],"sources":["useSharedValueEffect.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport type { SharedValueType } from \"../../renderer/processors/Animations\";\n\nimport {\n HAS_REANIMATED2,\n useSharedValue,\n runOnJS,\n startMapper,\n stopMapper,\n} from \"./moduleWrapper\";\n\n/**\n * Connects a shared value from reanimated to a SkiaView or Canvas\n * so whenever the shared value changes the SkiaView will redraw.\n * @param cb Callback that will be called whenever the shared value changes.\n * @param values One or more shared values to listen for.\n */\nexport const useSharedValueEffect = <T = number>(\n cb: () => void,\n value: SharedValueType<T>,\n ...values: SharedValueType<T>[]\n) => {\n console.warn(\n `useSharedValueEffect() is now deprecated, you can use Reanimated values directly.\nLearn more at https://shopify.github.io/react-native-skia/.`\n );\n const input = useSharedValue(0);\n\n useEffect(() => {\n if (!HAS_REANIMATED2) {\n console.warn(\n \"Reanimated was not found and the useSharedValueEffect hook will have no effect.\"\n );\n } else {\n // Start a mapper in Reanimated\n const mapperId = startMapper(\n () => {\n \"worklet\";\n runOnJS(cb)();\n },\n [value, ...values],\n [input]\n );\n // Return unregistering the mapper\n return () => {\n if (stopMapper && mapperId !== undefined) {\n stopMapper(mapperId);\n }\n };\n }\n return () => {};\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [input, value, ...values]);\n};\n"],"mappings":";;;;;;;AAAA;;AAIA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAG,UAClCC,EADkC,EAElCC,KAFkC,EAI/B;EAAA,kCADAC,MACA;IADAA,MACA;EAAA;;EACHC,OAAO,CAACC,IAAR,CACG;AACL,4DAFE;EAIA,MAAMC,KAAK,GAAG,IAAAC,6BAAA,EAAe,CAAf,CAAd;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,IAAI,CAACC,8BAAL,EAAsB;MACpBL,OAAO,CAACC,IAAR,CACE,iFADF;IAGD,CAJD,MAIO;MACL;MACA,MAAMK,QAAQ,GAAG,IAAAC,0BAAA,EACf,MAAM;QACJ;;QACA,IAAAC,sBAAA,EAAQX,EAAR;MACD,CAJc,EAKf,CAACC,KAAD,EAAQ,GAAGC,MAAX,CALe,EAMf,CAACG,KAAD,CANe,CAAjB,CAFK,CAUL;;MACA,OAAO,MAAM;QACX,IAAIO,yBAAA,IAAcH,QAAQ,KAAKI,SAA/B,EAA0C;UACxC,IAAAD,yBAAA,EAAWH,QAAX;QACD;MACF,CAJD;IAKD;;IACD,OAAO,MAAM,CAAE,CAAf,CAtBc,CAuBd;EACD,CAxBD,EAwBG,CAACJ,KAAD,EAAQJ,KAAR,EAAe,GAAGC,MAAlB,CAxBH;AAyBD,CApCM"}
@@ -103,8 +103,12 @@ class SkiaBaseWebView extends _react.default.Component {
103
103
  }
104
104
 
105
105
  componentWillUnmount() {
106
+ var _this$_canvasRef$curr, _this$_canvasRef$curr2, _this$_canvasRef$curr3;
107
+
106
108
  this.unsubscribeAll();
107
- cancelAnimationFrame(this.requestId);
109
+ cancelAnimationFrame(this.requestId); // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context
110
+
111
+ (_this$_canvasRef$curr = this._canvasRef.current) === null || _this$_canvasRef$curr === void 0 ? void 0 : (_this$_canvasRef$curr2 = _this$_canvasRef$curr.getContext("webgl2")) === null || _this$_canvasRef$curr2 === void 0 ? void 0 : (_this$_canvasRef$curr3 = _this$_canvasRef$curr2.getExtension("WEBGL_lose_context")) === null || _this$_canvasRef$curr3 === void 0 ? void 0 : _this$_canvasRef$curr3.loseContext();
108
112
  }
109
113
  /**
110
114
  * Creates a snapshot from the canvas in the surface
@@ -1 +1 @@
1
- {"version":3,"names":["pd","PixelRatio","get","SkiaBaseWebView","React","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","touches","_touches","Float32Array","of","save","scale","restore","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","TouchType","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = width * pd;\n canvas.height = height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, []);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const touches = [...this._touches];\n this._touches = [];\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas, touches);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEA,MAAMA,EAAE,GAAGC,uBAAA,CAAWC,GAAX,EAAX;;AAEO,MAAeC,eAAf,SAEGC,cAAA,CAAMC,SAFT,CAE2B;EAChCC,WAAW,CAACC,KAAD,EAAgB;IACzB,MAAMA,KAAN;;IADyB,kCAKa,IALb;;IAAA,0CAMmB,EANnB;;IAAA,kCAOU,EAPV;;IAAA,iCAQQ,IARR;;IAAA,iDASNH,cAAA,CAAMI,SAAN,EATM;;IAAA;;IAAA,yCAWD,CAXC;;IAAA,mCAYP,CAZO;;IAAA,+BAcT,CAdS;;IAAA,gCAeR,CAfQ;;IAEzB,KAAKC,KAAL,GAAaF,KAAK,CAACG,IAAN,IAAc,SAA3B;EACD;;EAcOC,cAAc,GAAG;IACvB,KAAKC,gBAAL,CAAsBC,OAAtB,CAA+BC,CAAD,IAAOA,CAAC,EAAtC;;IACA,KAAKF,gBAAL,GAAwB,EAAxB;EACD;;EAEOG,QAAQ,CAACC,GAAD,EAAyB;IACvC,MAAM;MAAEC;IAAF,IAAgBC,MAAtB;IACA,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAoBJ,GAAG,CAACK,WAAJ,CAAgBC,MAA1C;IACA,KAAKH,KAAL,GAAaA,KAAb;IACA,KAAKC,MAAL,GAAcA,MAAd,CAJuC,CAKvC;;IACA,IAAI,KAAKG,UAAL,CAAgBC,OAApB,EAA6B;MAC3B,MAAMC,MAAM,GAAG,KAAKF,U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MAOE,cAAc,EAAE,KAAKV,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC,CAPlB;MAQE,YAAY,EAAE,KAAKT,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC;IARhB,EADF,CADF;EAcD;;AA9K+B"}
1
+ {"version":3,"names":["pd","PixelRatio","get","SkiaBaseWebView","React","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","getContext","getExtension","loseContext","makeImageSnapshot","rect","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","touches","_touches","Float32Array","of","save","scale","restore","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","TouchType","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = width * pd;\n canvas.height = height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, []);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const touches = [...this._touches];\n this._touches = [];\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas, touches);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEA,MAAMA,EAAE,GAAGC,uBAAA,CAAWC,GAAX,EAAX;;AAEO,MAAeC,eAAf,SAEGC,cAAA,CAAMC,SAFT,CAE2B;EAChCC,WAAW,CAACC,KAAD,EAAgB;IACzB,MAAMA,KAAN;;IADyB,kCAKa,IALb;;IAAA,0CAMmB,EANnB;;IAAA,kCAOU,EAPV;;IAAA,iCAQQ,IARR;;IAAA,iDASNH,cAAA,CAAMI,SAAN,EATM;;IAAA;;IAAA,yCAWD,CAXC;;IAAA,mCAYP,CAZO;;IAAA,+BAcT,CAdS;;IAAA,gCAeR,CAfQ;;IAEzB,KAAKC,KAAL,GAAaF,KAAK,CAACG,IAAN,IAAc,SAA3B;EACD;;EAcOC,cAAc,GAAG;IACvB,KAAKC,gBAAL,CAAsBC,OAAtB,CAA+BC,CAAD,IAAOA,CAAC,EAAtC;;IACA,KAAKF,gBAAL,GAAwB,EAAxB;EACD;;EAEOG,QAAQ,CAACC,GAAD,EAAyB;IACvC,MAAM;MAAEC;IAAF,IAAgBC,MAAtB;IACA,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAoBJ,GAAG,CAACK,WAAJ,CAAgBC,MAA1C;IACA,KAAKH,KAAL,GAAaA,KAAb;IACA,KAAKC,MAAL,GAAcA,MAAd,CAJuC,CAKvC;;IACA,IAAI,KAAKG,UAAL,CAAgBC,OAApB,EAA6B;MAC3B,MAAMC,MAAM,GAAG,KAAKF,UAAL,CAAgBC,OAA/B;MACAC,MAAM,CAACN,KAAP,GAAeA,KAAK,GAAGnB,EAAvB;MACAyB,MAAM,CAACL,MAAP,GAAgBA,MAAM,GAAGpB,EAAzB;MACA,MAAM0B,OAAO,GAAGT,SAAS,CAACU,sBAAV,CAAiC,KAAKJ,UAAL,CAAgBC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AY,EAAE,KAAKT,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC;IARhB,EADF,CADF;EAcD;;AAnL+B"}
@@ -70,13 +70,21 @@ export class DisplacementMapImageFilterNode extends ImageFilterDeclaration {
70
70
  }
71
71
 
72
72
  decorate(ctx) {
73
+ this.decorateChildren(ctx);
73
74
  const {
74
75
  channelX,
75
76
  channelY,
76
77
  scale
77
78
  } = this.props;
78
- const imgf = this.Skia.ImageFilter.MakeDisplacementMap(ColorChannel[enumKey(channelX)], ColorChannel[enumKey(channelY)], scale, ctx.imageFilters.pop(), this.input(ctx));
79
- this.composeAndPush(ctx, imgf);
79
+ const shader = ctx.shaders.pop();
80
+
81
+ if (!shader) {
82
+ throw new Error("DisplacementMap expects a shader as child");
83
+ }
84
+
85
+ const map = this.Skia.ImageFilter.MakeShader(shader, null);
86
+ const imgf = this.Skia.ImageFilter.MakeDisplacementMap(ColorChannel[enumKey(channelX)], ColorChannel[enumKey(channelY)], scale, map, this.input(ctx));
87
+ ctx.imageFilters.push(imgf);
80
88
  }
81
89
 
82
90
  }