@shopify/react-native-skia 0.1.176 → 0.1.180

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. package/android/CMakeLists.txt +2 -0
  2. package/cpp/jsi/JsiHostObject.cpp +13 -7
  3. package/cpp/jsi/JsiHostObject.h +3 -1
  4. package/cpp/jsi/RuntimeAwareCache.cpp +9 -0
  5. package/cpp/jsi/RuntimeAwareCache.h +101 -0
  6. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +57 -0
  7. package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
  8. package/cpp/rnskia/RNSkManager.cpp +4 -0
  9. package/cpp/rnskia/RNSkView.h +5 -3
  10. package/cpp/rnskia/dom/base/JsiDomNode.h +22 -2
  11. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +10 -9
  12. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +10 -2
  13. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  14. package/lib/commonjs/external/reanimated/index.d.ts +1 -0
  15. package/lib/commonjs/external/reanimated/index.js +13 -0
  16. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  17. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +8 -0
  18. package/lib/commonjs/external/reanimated/moduleWrapper.js +68 -0
  19. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -0
  20. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +5 -0
  21. package/lib/commonjs/external/reanimated/renderHelpers.js +81 -0
  22. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -0
  23. package/lib/commonjs/external/reanimated/useSharedValueEffect.d.ts +2 -5
  24. package/lib/commonjs/external/reanimated/useSharedValueEffect.js +10 -25
  25. package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +1 -1
  26. package/lib/commonjs/headless/index.d.ts +3 -0
  27. package/lib/commonjs/headless/index.js +57 -0
  28. package/lib/commonjs/headless/index.js.map +1 -0
  29. package/lib/commonjs/mock/index.d.ts +1 -2
  30. package/lib/commonjs/mock/index.js +0 -4
  31. package/lib/commonjs/mock/index.js.map +1 -1
  32. package/lib/commonjs/renderer/Canvas.js +7 -1
  33. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  34. package/lib/commonjs/renderer/Container.d.ts +2 -1
  35. package/lib/commonjs/renderer/Container.js +2 -0
  36. package/lib/commonjs/renderer/Container.js.map +1 -1
  37. package/lib/commonjs/renderer/HostConfig.js +6 -4
  38. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  39. package/lib/commonjs/renderer/Reconciler.d.ts +1 -1
  40. package/lib/commonjs/renderer/Reconciler.js +2 -1
  41. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  42. package/lib/commonjs/renderer/processors/Animations/Animations.d.ts +4 -1
  43. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  44. package/lib/module/dom/nodes/paint/ImageFilters.js +10 -2
  45. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  46. package/lib/module/external/reanimated/index.d.ts +1 -0
  47. package/lib/module/external/reanimated/index.js +1 -0
  48. package/lib/module/external/reanimated/index.js.map +1 -1
  49. package/lib/module/external/reanimated/moduleWrapper.d.ts +8 -0
  50. package/lib/module/external/reanimated/moduleWrapper.js +50 -0
  51. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -0
  52. package/lib/module/external/reanimated/renderHelpers.d.ts +5 -0
  53. package/lib/module/external/reanimated/renderHelpers.js +72 -0
  54. package/lib/module/external/reanimated/renderHelpers.js.map +1 -0
  55. package/lib/module/external/reanimated/useSharedValueEffect.d.ts +2 -5
  56. package/lib/module/external/reanimated/useSharedValueEffect.js +7 -22
  57. package/lib/module/external/reanimated/useSharedValueEffect.js.map +1 -1
  58. package/lib/module/headless/index.d.ts +3 -0
  59. package/lib/module/headless/index.js +29 -0
  60. package/lib/module/headless/index.js.map +1 -0
  61. package/lib/module/mock/index.d.ts +1 -2
  62. package/lib/module/mock/index.js +0 -3
  63. package/lib/module/mock/index.js.map +1 -1
  64. package/lib/module/renderer/Canvas.js +7 -1
  65. package/lib/module/renderer/Canvas.js.map +1 -1
  66. package/lib/module/renderer/Container.d.ts +2 -1
  67. package/lib/module/renderer/Container.js +2 -0
  68. package/lib/module/renderer/Container.js.map +1 -1
  69. package/lib/module/renderer/HostConfig.js +5 -4
  70. package/lib/module/renderer/HostConfig.js.map +1 -1
  71. package/lib/module/renderer/Reconciler.d.ts +1 -1
  72. package/lib/module/renderer/Reconciler.js +2 -1
  73. package/lib/module/renderer/Reconciler.js.map +1 -1
  74. package/lib/module/renderer/processors/Animations/Animations.d.ts +4 -1
  75. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  76. package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
  77. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +8 -0
  78. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +5 -0
  79. package/lib/typescript/src/external/reanimated/useSharedValueEffect.d.ts +2 -5
  80. package/lib/typescript/src/headless/index.d.ts +3 -0
  81. package/lib/typescript/src/mock/index.d.ts +1 -2
  82. package/lib/typescript/src/renderer/Container.d.ts +2 -1
  83. package/lib/typescript/src/renderer/Reconciler.d.ts +1 -1
  84. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +4 -1
  85. package/package.json +1 -1
  86. package/src/dom/nodes/paint/ImageFilters.ts +8 -2
  87. package/src/external/reanimated/index.ts +1 -0
  88. package/src/external/reanimated/moduleWrapper.ts +60 -0
  89. package/src/external/reanimated/renderHelpers.ts +70 -0
  90. package/src/external/reanimated/useSharedValueEffect.ts +17 -23
  91. package/src/headless/index.ts +31 -0
  92. package/src/mock/index.ts +0 -5
  93. package/src/renderer/Canvas.tsx +6 -2
  94. package/src/renderer/Container.tsx +2 -1
  95. package/src/renderer/HostConfig.ts +8 -2
  96. package/src/renderer/Reconciler.tsx +3 -2
  97. package/src/renderer/processors/Animations/Animations.ts +9 -1
@@ -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
  }
@@ -1 +1 @@
1
- {"version":3,"names":["BlendMode","ColorChannel","processUniforms","TileMode","DeclarationType","NodeType","processRadius","enumKey","JsiDeclarationNode","Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","constructor","ctx","type","props","imageFilters","pop","composeAndPush","imgf1","save","decorateChildren","imgf2","popAllAsOne","cf","colorFilters","restore","imgf","push","OffsetImageFilterNode","OffsetImageFilter","decorate","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","MakeDisplacementMap","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","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","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,SACEA,SADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,QAJF,QAKO,qBALP;AAgBA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AACA,SAASC,aAAT,EAAwBC,OAAxB,QAAuC,cAAvC;AAEA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,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,EAAkCT,SAAS,CAAC0B,GAA5C,CADoB,EAEpB,IAFoB,CAAtB;EAIA,MAAMC,WAAW,GAAGd,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CAClBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCT,SAAS,CA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,MAAMxC,IAAI,GAAG,KAAK1C,IAAL,CAAUS,WAAV,CAAsBG,SAAtB,CAAgC6C,IAAhC,EAAsCuB,CAAtC,EAAyCC,CAAzC,CAAb;IACA,KAAKhD,cAAL,CAAoBL,GAApB,EAAyBc,IAAzB;EACD;;AAdqF;AAiBxF,OAAO,MAAMyC,4BAAN,SAA2CzD,sBAA3C,CAAiG;EACtGC,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAyD;IAClE,MAAMF,GAAN,EAAWpC,QAAQ,CAAC4F,wBAApB,EAA8CtD,KAA9C;EACD;;EAEDgB,QAAQ,CAAClB,GAAD,EAA0B;IAChC,MAAM;MAAEyD,MAAF;MAAUC;IAAV,IAAuB,KAAKxD,KAAlC;IACA,MAAMyD,GAAG,GAAG,KAAKvF,IAAL,CAAUwF,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZjG,eAAe,CAACgG,MAAD,EAASC,QAAT,EAAmBC,GAAnB,CAAf;IACD;;IACD,MAAM7C,IAAI,GAAG,KAAK1C,IAAL,CAAUS,WAAV,CAAsBgF,iBAAtB,CACXF,GADW,EAEX,IAFW,EAGX,KAAKhF,KAAL,CAAWqB,GAAX,CAHW,CAAb;IAKA,KAAKK,cAAL,CAAoBL,GAApB,EAAyBc,IAAzB;EACD;;AAjBqG"}
1
+ {"version":3,"names":["BlendMode","ColorChannel","processUniforms","TileMode","DeclarationType","NodeType","processRadius","enumKey","JsiDeclarationNode","Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","constructor","ctx","type","props","imageFilters","pop","composeAndPush","imgf1","save","decorateChildren","imgf2","popAllAsOne","cf","colorFilters","restore","imgf","push","OffsetImageFilterNode","OffsetImageFilter","decorate","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","shader","shaders","Error","map","MakeShader","MakeDisplacementMap","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","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","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,SACEA,SADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,QAJF,QAKO,qBALP;AAgBA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AACA,SAASC,aAAT,EAAwBC,OAAxB,QAAuC,cAAvC;AAEA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,KAAK,GAAGC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAd;;AAEA,MAAMC,eAAe,GAAG,CACtBC,IADsB,EAEtB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,QAAJ,EAAc;MACZrG,eAAe,CAACoG,MAAD,EAASC,QAAT,EAAmBC,GAAnB,CAAf;IACD;;IACD,MAAMjD,IAAI,GAAG,KAAK1C,IAAL,CAAUS,WAAV,CAAsBoF,iBAAtB,CACXF,GADW,EAEX,IAFW,EAGX,KAAKpF,KAAL,CAAWqB,GAAX,CAHW,CAAb;IAKA,KAAKK,cAAL,CAAoBL,GAApB,EAAyBc,IAAzB;EACD;;AAjBqG"}
@@ -1 +1,2 @@
1
1
  export * from "./useSharedValueEffect";
2
+ export * from "./renderHelpers";
@@ -1,2 +1,3 @@
1
1
  export * from "./useSharedValueEffect";
2
+ export * from "./renderHelpers";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useSharedValueEffect\";\n"],"mappings":"AAAA,cAAc,wBAAd"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useSharedValueEffect\";\nexport * from \"./renderHelpers\";\n"],"mappings":"AAAA,cAAc,wBAAd;AACA,cAAc,iBAAd"}
@@ -0,0 +1,8 @@
1
+ import type { SharedValueType } from "../../renderer/processors/Animations";
2
+ export declare const HAS_REANIMATED2: boolean;
3
+ export declare const HAS_REANIMATED3: boolean;
4
+ export declare const useSharedValue: any;
5
+ export declare const startMapper: any;
6
+ export declare const stopMapper: any;
7
+ export declare const runOnJS: any;
8
+ export declare const isSharedValue: <T>(value: unknown) => value is SharedValueType<T>;
@@ -0,0 +1,50 @@
1
+ var _Reanimated, _Reanimated2, _Reanimated3, _Reanimated4;
2
+
3
+ import { useMemo } from "react";
4
+ // This one is needed for the deprecated useSharedValue function
5
+ // We can remove it once we remove the deprecation
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ let Reanimated2; // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+
9
+ let Reanimated3;
10
+ let reanimatedVersion;
11
+
12
+ try {
13
+ Reanimated2 = require("react-native-reanimated");
14
+ reanimatedVersion = // eslint-disable-next-line import/extensions
15
+ require("react-native-reanimated/package.json").version;
16
+
17
+ if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
18
+ Reanimated3 = Reanimated2;
19
+ }
20
+ } catch (e) {}
21
+
22
+ export const HAS_REANIMATED2 = !!Reanimated2;
23
+ export const HAS_REANIMATED3 = !!Reanimated3;
24
+
25
+ function throwOnMissingReanimated2() {
26
+ if (!HAS_REANIMATED2) {
27
+ throw new Error("Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
28
+ react-naitve-skia's integration layer API.");
29
+ }
30
+ }
31
+
32
+ function throwOnMissingReanimated3() {
33
+ if (!HAS_REANIMATED3) {
34
+ throw new Error(`Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`);
35
+ }
36
+
37
+ throwOnMissingReanimated2();
38
+ }
39
+
40
+ export const useSharedValue = ((_Reanimated = Reanimated2) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) || (value => useMemo(() => ({
41
+ value
42
+ }), [value]));
43
+ export const startMapper = ((_Reanimated2 = Reanimated2) === null || _Reanimated2 === void 0 ? void 0 : _Reanimated2.startMapper) || throwOnMissingReanimated2;
44
+ export const stopMapper = ((_Reanimated3 = Reanimated2) === null || _Reanimated3 === void 0 ? void 0 : _Reanimated3.stopMapper) || throwOnMissingReanimated2;
45
+ export const runOnJS = ((_Reanimated4 = Reanimated2) === null || _Reanimated4 === void 0 ? void 0 : _Reanimated4.runOnJS) || throwOnMissingReanimated2;
46
+ export const isSharedValue = value => {
47
+ throwOnMissingReanimated3();
48
+ return !!value && Reanimated3.isSharedValue(value);
49
+ };
50
+ //# sourceMappingURL=moduleWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","Reanimated2","Reanimated3","reanimatedVersion","require","version","includes","e","HAS_REANIMATED2","HAS_REANIMATED3","throwOnMissingReanimated2","Error","throwOnMissingReanimated3","useSharedValue","value","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,SAASA,OAAT,QAAwB,OAAxB;AAIA;AACA;AACA;AACA,IAAIC,WAAJ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AAF,IAAWZ,WAAW,CAACgB,aAAZ,CAA0BJ,KAA1B,CAAlB;AACD,CALM"}
@@ -0,0 +1,5 @@
1
+ import type { Container } from "../../renderer/Container";
2
+ import type { AnimatedProps } from "../../renderer/processors";
3
+ import type { Node } from "../../dom/types";
4
+ export declare function extractReanimatedProps(props: AnimatedProps<any>): AnimatedProps<any, never>[];
5
+ export declare function bindReanimatedProps(container: Container, node: Node<any>, reanimatedProps: AnimatedProps<any>): void;
@@ -0,0 +1,72 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ /* eslint-disable reanimated/js-function-in-worklet */
4
+ import { startMapper, stopMapper, isSharedValue, HAS_REANIMATED3 } from "./moduleWrapper";
5
+
6
+ const _bindings = new WeakMap();
7
+
8
+ export function extractReanimatedProps(props) {
9
+ if (!HAS_REANIMATED3) {
10
+ return [props, {}];
11
+ }
12
+
13
+ const reanimatedProps = {};
14
+ const otherProps = {};
15
+
16
+ for (const propName in props) {
17
+ if (propName === "children") {
18
+ continue;
19
+ }
20
+
21
+ const propValue = props[propName];
22
+
23
+ if (isSharedValue(propValue)) {
24
+ reanimatedProps[propName] = propValue;
25
+ otherProps[propName] = propValue.value;
26
+ } else {
27
+ otherProps[propName] = propValue;
28
+ }
29
+ }
30
+
31
+ return [otherProps, reanimatedProps];
32
+ }
33
+ export function bindReanimatedProps(container, node, reanimatedProps) {
34
+ if (!HAS_REANIMATED3) {
35
+ return;
36
+ }
37
+
38
+ const sharedValues = Object.values(reanimatedProps);
39
+
40
+ const previousMapperId = _bindings.get(node);
41
+
42
+ if (previousMapperId !== undefined) {
43
+ stopMapper(previousMapperId);
44
+ }
45
+
46
+ if (sharedValues.length > 0) {
47
+ const viewId = container.getNativeId();
48
+ const {
49
+ SkiaViewApi
50
+ } = global;
51
+ const mapperId = startMapper(() => {
52
+ "worklet";
53
+
54
+ for (const propName in reanimatedProps) {
55
+ node && node.setProp(propName, reanimatedProps[propName].value);
56
+ } // On React Native we use the SkiaViewApi to redraw because it can
57
+ // run on the worklet thread (container.redraw can't)
58
+ // if SkiaViewApi is undefined, we are on web and container.redraw()
59
+ // can safely be invoked
60
+
61
+
62
+ if (SkiaViewApi) {
63
+ SkiaViewApi.requestRedraw(viewId);
64
+ } else {
65
+ container.redraw();
66
+ }
67
+ }, sharedValues);
68
+
69
+ _bindings.set(node, mapperId);
70
+ }
71
+ }
72
+ //# sourceMappingURL=renderHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["startMapper","stopMapper","isSharedValue","HAS_REANIMATED3","_bindings","WeakMap","extractReanimatedProps","props","reanimatedProps","otherProps","propName","propValue","value","bindReanimatedProps","container","node","sharedValues","Object","values","previousMapperId","get","undefined","length","viewId","getNativeId","SkiaViewApi","global","mapperId","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":"AAAA;;AACA;AAKA,SACEA,WADF,EAEEC,UAFF,EAGEC,aAHF,EAIEC,eAJF,QAKO,iBALP;;AAOA,MAAMC,SAAS,GAAG,IAAIC,OAAJ,EAAlB;;AAEA,OAAO,SAASC,sBAAT,CAAgCC,KAAhC,EAA2D;EAChE,IAAI,CAACJ,eAAL,EAAsB;IACpB,OAAO,CAACI,KAAD,EAAQ,EAAR,CAAP;EACD;;EACD,MAAMC,eAAe,GAAG,EAAxB;EACA,MAAMC,UAAU,GAAG,EAAnB;;EACA,KAAK,MAAMC,QAAX,IAAuBH,KAAvB,EAA8B;IAC5B,IAAIG,QAAQ,KAAK,UAAjB,EAA6B;MAC3B;IACD;;IACD,MAAMC,SAAS,GAAGJ,KAAK,CAACG,QAAD,CAAvB;;IACA,IAAIR,aAAa,CAACS,SAAD,CAAjB,EAA8B;MAC5BH,eAAe,CAACE,QAAD,CAAf,GAA4BC,SAA5B;MACAF,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAS,CAACC,KAAjC;IACD,CAHD,MAGO;MACLH,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAvB;IACD;EACF;;EACD,OAAO,CAACF,UAAD,EAAaD,eAAb,CAAP;AACD;AAED,OAAO,SAASK,mBAAT,CACLC,SADK,EAELC,IAFK,EAGLP,eAHK,EAIL;EACA,IAAI,CAACL,eAAL,EAAsB;IACpB;EACD;;EACD,MAAMa,YAAY,GAAGC,MAAM,CAACC,MAAP,CAAcV,eAAd,CAArB;;EACA,MAAMW,gBAAgB,GAAGf,SAAS,CAACgB,GAAV,CAAcL,IAAd,CAAzB;;EACA,IAAII,gBAAgB,KAAKE,SAAzB,EAAoC;IAClCpB,UAAU,CAACkB,gBAAD,CAAV;EACD;;EACD,IAAIH,YAAY,CAACM,MAAb,GAAsB,CAA1B,EAA6B;IAC3B,MAAMC,MAAM,GAAGT,SAAS,CAACU,WAAV,EAAf;IACA,MAAM;MAAEC;IAAF,IAAkBC,MAAxB;IACA,MAAMC,QAAQ,GAAG3B,WAAW,CAAC,MAAM;MACjC;;MACA,KAAK,MAAMU,QAAX,IAAuBF,eAAvB,EAAwC;QACtCO,IAAI,IAAIA,IAAI,CAACa,OAAL,CAAalB,QAAb,EAAuBF,eAAe,CAACE,QAAD,CAAf,CAA0BE,KAAjD,CAAR;MACD,CAJgC,CAKjC;MACA;MACA;MACA;;;MACA,IAAIa,WAAJ,EAAiB;QACfA,WAAW,CAACI,aAAZ,CAA0BN,MAA1B;MACD,CAFD,MAEO;QACLT,SAAS,CAACgB,MAAV;MACD;IACF,CAd2B,EAczBd,YAdyB,CAA5B;;IAeAZ,SAAS,CAAC2B,GAAV,CAAchB,IAAd,EAAoBY,QAApB;EACD;AACF"}
@@ -1,11 +1,8 @@
1
- declare type SharedValueTypeWrapper<T = number> = {
2
- value: T;
3
- };
1
+ import type { SharedValueType } from "../../renderer/processors/Animations";
4
2
  /**
5
3
  * Connects a shared value from reanimated to a SkiaView or Canvas
6
4
  * so whenever the shared value changes the SkiaView will redraw.
7
5
  * @param cb Callback that will be called whenever the shared value changes.
8
6
  * @param values One or more shared values to listen for.
9
7
  */
10
- export declare const useSharedValueEffect: <T = number>(cb: () => void, value: SharedValueTypeWrapper<T>, ...values: SharedValueTypeWrapper<T>[]) => void;
11
- export {};
8
+ export declare const useSharedValueEffect: <T = number>(cb: () => void, value: SharedValueType<T>, ...values: SharedValueType<T>[]) => void;
@@ -1,17 +1,5 @@
1
- var _Reanimated;
2
-
3
- import { useEffect, useMemo } from "react"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
-
5
- let Reanimated;
6
-
7
- try {
8
- Reanimated = require("react-native-reanimated");
9
- } catch (e) {// Ignore
10
- }
11
-
12
- const useSharedValueWrapper = ((_Reanimated = Reanimated) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) === undefined ? value => useMemo(() => ({
13
- value
14
- }), [value]) : Reanimated.useSharedValue;
1
+ import { useEffect } from "react";
2
+ import { HAS_REANIMATED2, useSharedValue, runOnJS, startMapper, stopMapper } from "./moduleWrapper";
15
3
  /**
16
4
  * Connects a shared value from reanimated to a SkiaView or Canvas
17
5
  * so whenever the shared value changes the SkiaView will redraw.
@@ -24,17 +12,14 @@ export const useSharedValueEffect = function (cb, value) {
24
12
  values[_key - 2] = arguments[_key];
25
13
  }
26
14
 
27
- const input = useSharedValueWrapper(0);
15
+ console.warn(`useSharedValueEffect() is now deprecated, you can use Reanimated values directly.
16
+ Learn more at https://shopify.github.io/react-native-skia/.`);
17
+ const input = useSharedValue(0);
28
18
  useEffect(() => {
29
- if (!Reanimated) {
19
+ if (!HAS_REANIMATED2) {
30
20
  console.warn("Reanimated was not found and the useSharedValueEffect hook will have no effect.");
31
21
  } else {
32
- const {
33
- runOnJS,
34
- startMapper,
35
- stopMapper
36
- } = Reanimated; // Start a mapper in Reanimated
37
-
22
+ // Start a mapper in Reanimated
38
23
  const mapperId = startMapper(() => {
39
24
  "worklet";
40
25
 
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useMemo","Reanimated","require","e","useSharedValueWrapper","useSharedValue","undefined","value","useSharedValueEffect","cb","values","input","console","warn","runOnJS","startMapper","stopMapper","mapperId"],"sources":["useSharedValueEffect.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\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\ntype SharedValueTypeWrapper<T = number> = {\n value: T;\n};\n\nconst useSharedValueWrapper =\n Reanimated?.useSharedValue === undefined\n ? (value: number) => useMemo(() => ({ value }), [value])\n : Reanimated.useSharedValue;\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: SharedValueTypeWrapper<T>,\n ...values: SharedValueTypeWrapper<T>[]\n) => {\n const input = useSharedValueWrapper(0);\n\n useEffect(() => {\n if (!Reanimated) {\n console.warn(\n \"Reanimated was not found and the useSharedValueEffect hook will have no effect.\"\n );\n } else {\n const { runOnJS, startMapper, stopMapper } = Reanimated;\n\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,SAASA,SAAT,EAAoBC,OAApB,QAAmC,OAAnC,C,CAEA;;AACA,IAAIC,UAAJ;;AAEA,IAAI;EACFA,UAAU,GAAGC,OAAO,CAAC,yBAAD,CAApB;AACD,CAFD,CAEE,OAAOC,CAAP,EAAU,CACV;AACD;;AAMD,MAAMC,qBAAqB,GACzB,gBAAAH,UAAU,UAAV,kDAAYI,cAAZ,MAA+BC,SAA/B,GACKC,KAAD,IAAmBP,OAAO,CAAC,OAAO;EAAEO;AAAF,CAAP,CAAD,EAAoB,CAACA,KAAD,CAApB,CAD9B,GAEIN,UAAU,CAACI,cAHjB;AAKA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,oBAAoB,GAAG,UAClCC,EADkC,EAElCF,KAFkC,EAI/B;EAAA,kCADAG,MACA;IADAA,MACA;EAAA;;EACH,MAAMC,KAAK,GAAGP,qBAAqB,CAAC,CAAD,CAAnC;EAEAL,SAAS,CAAC,MAAM;IACd,IAAI,CAACE,UAAL,EAAiB;MACfW,OAAO,CAACC,IAAR,CACE,iFADF;IAGD,CAJD,MAIO;MACL,MAAM;QAAEC,OAAF;QAAWC,WAAX;QAAwBC;MAAxB,IAAuCf,UAA7C,CADK,CAGL;;MACA,MAAMgB,QAAQ,GAAGF,WAAW,CAC1B,MAAM;QACJ;;QACAD,OAAO,CAACL,EAAD,CAAP;MACD,CAJyB,EAK1B,CAACF,KAAD,EAAQ,GAAGG,MAAX,CAL0B,EAM1B,CAACC,KAAD,CAN0B,CAA5B,CAJK,CAYL;;MACA,OAAO,MAAM;QACX,IAAIK,UAAU,IAAIC,QAAQ,KAAKX,SAA/B,EAA0C;UACxCU,UAAU,CAACC,QAAD,CAAV;QACD;MACF,CAJD;IAKD;;IACD,OAAO,MAAM,CAAE,CAAf,CAxBc,CAyBd;EACD,CA1BQ,EA0BN,CAACN,KAAD,EAAQJ,KAAR,EAAe,GAAGG,MAAlB,CA1BM,CAAT;AA2BD,CAlCM"}
1
+ {"version":3,"names":["useEffect","HAS_REANIMATED2","useSharedValue","runOnJS","startMapper","stopMapper","useSharedValueEffect","cb","value","values","console","warn","input","mapperId","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,SAASA,SAAT,QAA0B,OAA1B;AAIA,SACEC,eADF,EAEEC,cAFF,EAGEC,OAHF,EAIEC,WAJF,EAKEC,UALF,QAMO,iBANP;AAQA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,oBAAoB,GAAG,UAClCC,EADkC,EAElCC,KAFkC,EAI/B;EAAA,kCADAC,MACA;IADAA,MACA;EAAA;;EACHC,OAAO,CAACC,IAAR,CACG;AACL,4DAFE;EAIA,MAAMC,KAAK,GAAGV,cAAc,CAAC,CAAD,CAA5B;EAEAF,SAAS,CAAC,MAAM;IACd,IAAI,CAACC,eAAL,EAAsB;MACpBS,OAAO,CAACC,IAAR,CACE,iFADF;IAGD,CAJD,MAIO;MACL;MACA,MAAME,QAAQ,GAAGT,WAAW,CAC1B,MAAM;QACJ;;QACAD,OAAO,CAACI,EAAD,CAAP;MACD,CAJyB,EAK1B,CAACC,KAAD,EAAQ,GAAGC,MAAX,CAL0B,EAM1B,CAACG,KAAD,CAN0B,CAA5B,CAFK,CAUL;;MACA,OAAO,MAAM;QACX,IAAIP,UAAU,IAAIQ,QAAQ,KAAKC,SAA/B,EAA0C;UACxCT,UAAU,CAACQ,QAAD,CAAV;QACD;MACF,CAJD;IAKD;;IACD,OAAO,MAAM,CAAE,CAAf,CAtBc,CAuBd;EACD,CAxBQ,EAwBN,CAACD,KAAD,EAAQJ,KAAR,EAAe,GAAGC,MAAlB,CAxBM,CAAT;AAyBD,CApCM"}
@@ -0,0 +1,3 @@
1
+ import type { ReactNode } from "react";
2
+ export * from "../renderer/components";
3
+ export declare const draw: (element: ReactNode, width: number, height: number) => any;
@@ -0,0 +1,29 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-ignore
3
+ import { JsiSkApi } from "../skia/web";
4
+ import { SkiaRoot } from "../renderer/Reconciler";
5
+ import { JsiDrawingContext } from "../dom/types";
6
+ export * from "../renderer/components"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+
8
+ let Skia;
9
+ export const draw = (element, width, height) => {
10
+ if (!Skia) {
11
+ Skia = JsiSkApi(CanvasKit);
12
+ }
13
+
14
+ const surface = Skia.Surface.MakeOffscreen(width, height);
15
+
16
+ if (surface === null) {
17
+ throw new Error("Couldn't create surface!");
18
+ }
19
+
20
+ const root = new SkiaRoot(Skia);
21
+ root.render(element);
22
+ const canvas = surface.getCanvas();
23
+ const ctx = new JsiDrawingContext(Skia, canvas);
24
+ root.dom.render(ctx);
25
+ surface.flush();
26
+ const image = surface.makeImageSnapshot();
27
+ return image;
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["JsiSkApi","SkiaRoot","JsiDrawingContext","Skia","draw","element","width","height","CanvasKit","surface","Surface","MakeOffscreen","Error","root","render","canvas","getCanvas","ctx","dom","flush","image","makeImageSnapshot"],"sources":["index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { ReactNode } from \"react\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { SkiaRoot } from \"../renderer/Reconciler\";\nimport { JsiDrawingContext } from \"../dom/types\";\n\nexport * from \"../renderer/components\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Skia: any;\n\nexport const draw = (element: ReactNode, width: number, height: number) => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n const surface = Skia.Surface.MakeOffscreen(width, height);\n if (surface === null) {\n throw new Error(\"Couldn't create surface!\");\n }\n const root = new SkiaRoot(Skia);\n root.render(element);\n const canvas = surface.getCanvas();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n surface.flush();\n const image = surface.makeImageSnapshot();\n return image;\n};\n"],"mappings":"AAAA;AACA;AAIA,SAASA,QAAT,QAAyB,aAAzB;AACA,SAASC,QAAT,QAAyB,wBAAzB;AACA,SAASC,iBAAT,QAAkC,cAAlC;AAEA,cAAc,wBAAd,C,CAEA;;AACA,IAAIC,IAAJ;AAEA,OAAO,MAAMC,IAAI,GAAG,CAACC,OAAD,EAAqBC,KAArB,EAAoCC,MAApC,KAAuD;EACzE,IAAI,CAACJ,IAAL,EAAW;IACTA,IAAI,GAAGH,QAAQ,CAACQ,SAAD,CAAf;EACD;;EACD,MAAMC,OAAO,GAAGN,IAAI,CAACO,OAAL,CAAaC,aAAb,CAA2BL,KAA3B,EAAkCC,MAAlC,CAAhB;;EACA,IAAIE,OAAO,KAAK,IAAhB,EAAsB;IACpB,MAAM,IAAIG,KAAJ,CAAU,0BAAV,CAAN;EACD;;EACD,MAAMC,IAAI,GAAG,IAAIZ,QAAJ,CAAaE,IAAb,CAAb;EACAU,IAAI,CAACC,MAAL,CAAYT,OAAZ;EACA,MAAMU,MAAM,GAAGN,OAAO,CAACO,SAAR,EAAf;EACA,MAAMC,GAAG,GAAG,IAAIf,iBAAJ,CAAsBC,IAAtB,EAA4BY,MAA5B,CAAZ;EACAF,IAAI,CAACK,GAAL,CAASJ,MAAT,CAAgBG,GAAhB;EACAR,OAAO,CAACU,KAAR;EACA,MAAMC,KAAK,GAAGX,OAAO,CAACY,iBAAR,EAAd;EACA,OAAOD,KAAP;AACD,CAhBM"}
@@ -1,6 +1,5 @@
1
1
  import type { Skia as SkiaApi } from "../skia/types";
2
2
  import type * as SkiaExports from "../skia";
3
- import type * as ExternalExports from "../external";
4
3
  import type * as ValueExports from "../values";
5
4
  import type * as AnimationExports from "../animation";
6
5
  import { ShaderLib } from "../renderer/components/shaders/ShaderLib";
@@ -9,7 +8,7 @@ export declare const vec: (x?: number, y?: number) => {
9
8
  x: number;
10
9
  y: number;
11
10
  };
12
- export declare const Mock: typeof SkiaExports & typeof ExternalExports & typeof ValueExports & typeof AnimationExports & {
11
+ export declare const Mock: typeof SkiaExports & typeof ValueExports & typeof AnimationExports & {
13
12
  createDrawing: () => any;
14
13
  createDeclaration: () => any;
15
14
  ShaderLib: typeof ShaderLib;
@@ -3,7 +3,6 @@ import * as Values from "../values/web";
3
3
  import * as ValuesHooks from "../values/hooks";
4
4
  import { Selector } from "../values/selector";
5
5
  import * as BaseSkia from "../skia/types";
6
- import { useSharedValueEffect } from "../external/reanimated/useSharedValueEffect";
7
6
  import * as timingFunctions from "../animation/timing";
8
7
  import * as springFunctions from "../animation/spring";
9
8
  import * as decayFunctions from "../animation/decay";
@@ -83,8 +82,6 @@ export const Mock = {
83
82
  bottomRight: Noop,
84
83
  center: Noop,
85
84
  processTransform2d: Noop,
86
- // ExternalExports
87
- useSharedValueEffect,
88
85
  // ValueExports
89
86
  ...Values,
90
87
  ...ValuesHooks,
@@ -1 +1 @@
1
- {"version":3,"names":["Values","ValuesHooks","Selector","BaseSkia","useSharedValueEffect","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useRawData","useData","useFont","useTypeface","useImage","useSVG","createPicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n createPicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"],"mappings":"AAAA;AAGA,OAAO,KAAKA,MAAZ,MAAwB,eAAxB;AACA,OAAO,KAAKC,WAAZ,MAA6B,iBAA7B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,OAAO,KAAKC,QAAZ,MAA0B,eAA1B;AAKA,SAASC,oBAAT,QAAqC,6CAArC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,cAAZ,MAAgC,oBAAhC;AACA,OAAO,KAAKC,aAAZ,MAA+B,oCAA/B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,yCAAnC;AACA,OAAO,KAAKC,mBAAZ,MAAqC,0CAArC;AACA,SAASC,SAAT,QAA0B,0CAA1B;;AAEA,MAAMC,IAAN,CAAW;EACTC,WAAW,GAAG;IACZ,OAAO,IAAIC,KAAJ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+C,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA1DD;EA2DJC,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;EA4DJnD,SA5DI;EA6DJwD,aAAa,EAAEjD,IA7DX;EA8DJkD,iBAAiB,EAAElD;AA9Df,CAPC"}
1
+ {"version":3,"names":["Values","ValuesHooks","Selector","BaseSkia","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useRawData","useData","useFont","useTypeface","useImage","useSVG","createPicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n createPicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: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;MAAKC;IAAL,CAAD;IAAA,OACT,CAAC;MAAE0B,UAAU,EAAE3B;IAAd,CAAD,EAAoB;MAAE4B,UAAU,EAAE3B;IAAd,CAApB,CADS;EAAA,CA/BP;EAkCJ4B,MAAM,EAAEhC,IAlCJ;EAmCJiC,OAAO,EAAEjC,IAnCL;EAoCJkC,QAAQ,EAAElC,IApCN;EAqCJmC,UAAU,EAAEnC,IArCR;EAsCJoC,WAAW,EAAEpC,IAtCT;EAuCJqC,MAAM,EAAErC,IAvCJ;EAwCJsC,kBAAkB,EAAEtC,IAxChB;EAyCJ;EACA,GAAGjB,MA1CC;EA2CJ,GAAGC,WA3CC;EA4CJC,QA5CI;EA6CJ;EACA,GAAGE,eA9CC;EA+CJ,GAAGC,eA/CC;EAgDJ,GAAGC,cAhDC;EAiDJ,GAAGC,aAjDC;EAkDJ,GAAGC,iBAlDC;EAmDJ,GAAGC,mBAnDC;EAoDJ+C,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAxDD;EAyDJC,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAzD7C;EA0DJnD,SA1DI;EA2DJwD,aAAa,EAAEjD,IA3DX;EA4DJkD,iBAAiB,EAAElD;AA5Df,CANC"}
@@ -22,6 +22,12 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
22
22
 
23
23
  (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.redraw();
24
24
  }, [innerRef]);
25
+ const getNativeId = useCallback(() => {
26
+ var _innerRef$current$nat, _innerRef$current2;
27
+
28
+ const id = (_innerRef$current$nat = (_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : _innerRef$current2.nativeId) !== null && _innerRef$current$nat !== void 0 ? _innerRef$current$nat : -1;
29
+ return id;
30
+ }, [innerRef]);
25
31
  const registerValues = useCallback(values => {
26
32
  if (ref.current !== null) {
27
33
  return ref.current.registerValues(values);
@@ -29,7 +35,7 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
29
35
 
30
36
  return () => {};
31
37
  }, [ref]);
32
- const root = useMemo(() => new SkiaRoot(Skia, registerValues, redraw), [redraw, registerValues]); // Render effect
38
+ const root = useMemo(() => new SkiaRoot(Skia, registerValues, redraw, getNativeId), [redraw, registerValues, getNativeId]); // Render effect
33
39
 
34
40
  useEffect(() => {
35
41
  root.render(children);
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","SkiaDomView","Skia","SkiaRoot","useCanvasRef","Canvas","forwardedRef","children","style","debug","mode","onTouch","onSize","props","innerRef","ref","useCombinedRefs","redraw","current","registerValues","values","root","render","unmount","dom","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\n\nimport { SkiaDomView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { TouchHandler, SkiaBaseViewProps } from \"../views\";\nimport type { SkiaValue } from \"../values/types\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize, ...props },\n forwardedRef\n ) => {\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current !== null) {\n return ref.current.registerValues(values);\n }\n return () => {};\n },\n [ref]\n );\n const root = useMemo(\n () => new SkiaRoot(Skia, registerValues, redraw),\n [redraw, registerValues]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n) as React.FC<CanvasProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,WAFF,EAGEC,OAHF,EAIEC,UAJF,EAKEC,MALF,QAMO,OANP;AAcA,SAASC,WAAT,QAA4B,UAA5B;AACA,SAASC,IAAT,QAAqB,cAArB;AAIA,SAASC,QAAT,QAAyB,cAAzB;AAEA,OAAO,MAAMC,YAAY,GAAG,MAAMJ,MAAM,CAAc,IAAd,CAAjC;AAQP,OAAO,MAAMK,MAAM,gBAAGN,UAAU,CAC9B,OAEEO,YAFF,KAGK;EAAA,IAFH;IAAEC,QAAF;IAAYC,KAAZ;IAAmBC,KAAnB;IAA0BC,IAA1B;IAAgCC,OAAhC;IAAyCC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;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMG,eAAe,GAAG,YAEnB;EAAA,kCADAS,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAG/B,KAAK,CAACK,MAAN,CAAgB,IAAhB,CAAlB;EACAL,KAAK,CAACC,SAAN,CAAgB,MAAM;IACpB6B,IAAI,CAACE,OAAL,CAAcZ,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACW,SAAS,CAACR,OAAX,CAAH;QACD,CAFD,MAEO;UACLH,GAAG,CAACG,OAAJ,GAAcQ,SAAS,CAACR,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAACO,IAAD,CAVH;EAWA,OAAOC,SAAP;AACD,CAhBD"}
1
+ {"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","SkiaDomView","Skia","SkiaRoot","useCanvasRef","Canvas","forwardedRef","children","style","debug","mode","onTouch","onSize","props","innerRef","ref","useCombinedRefs","redraw","current","getNativeId","id","nativeId","registerValues","values","root","render","unmount","dom","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\n\nimport { SkiaDomView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { TouchHandler, SkiaBaseViewProps } from \"../views\";\nimport type { SkiaValue } from \"../values/types\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize, ...props },\n forwardedRef\n ) => {\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current !== null) {\n return ref.current.registerValues(values);\n }\n return () => {};\n },\n [ref]\n );\n const root = useMemo(\n () => new SkiaRoot(Skia, registerValues, redraw, getNativeId),\n [redraw, registerValues, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n) as React.FC<CanvasProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,WAFF,EAGEC,OAHF,EAIEC,UAJF,EAKEC,MALF,QAMO,OANP;AAcA,SAASC,WAAT,QAA4B,UAA5B;AACA,SAASC,IAAT,QAAqB,cAArB;AAIA,SAASC,QAAT,QAAyB,cAAzB;AAEA,OAAO,MAAMC,YAAY,GAAG,MAAMJ,MAAM,CAAc,IAAd,CAAjC;AAQP,OAAO,MAAMK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,CAAT;EAIArB,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX4B,IAAI,CAACE,OAAL;IACD,CAFD;EAGD,CAJQ,EAIN,CAACF,IAAD,CAJM,CAAT;EAMA,oBACE,oBAAC,WAAD;IACE,GAAG,EAAET,GADP;IAEE,KAAK,EAAEP,KAFT;IAGE,IAAI,EAAEgB,IAAI,CAACG,GAHb;IAIE,OAAO,EAAEhB,OAJX;IAKE,MAAM,EAAEC,MALV;IAME,IAAI,EAAEF,IANR;IAOE,KAAK,EAAED;EAPT,GAQMI,KARN,EADF;AAYD,CApD6B,CAAzB;AAuDP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMG,eAAe,GAAG,YAEnB;EAAA,kCADAY,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAGlC,KAAK,CAACK,MAAN,CAAgB,IAAhB,CAAlB;EACAL,KAAK,CAACC,SAAN,CAAgB,MAAM;IACpBgC,IAAI,CAACE,OAAL,CAAcf,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACc,SAAS,CAACX,OAAX,CAAH;QACD,CAFD,MAEO;UACLH,GAAG,CAACG,OAAJ,GAAcW,SAAS,CAACX,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAACU,IAAD,CAVH;EAWA,OAAOC,SAAP;AACD,CAhBD"}
@@ -4,9 +4,10 @@ import type { DependencyManager } from "./DependencyManager";
4
4
  export declare class Container {
5
5
  depMgr: DependencyManager;
6
6
  redraw: () => void;
7
+ getNativeId: () => number;
7
8
  private _root;
8
9
  Sk: SkDOM;
9
- constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void);
10
+ constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void, getNativeId?: () => number);
10
11
  draw(ctx: DrawingContext): void;
11
12
  get root(): RenderNode<GroupProps>;
12
13
  }
@@ -4,8 +4,10 @@ import { JsiSkDOM } from "../dom/nodes";
4
4
  export class Container {
5
5
  constructor(Skia, depMgr) {
6
6
  let redraw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
7
+ let getNativeId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => 0;
7
8
  this.depMgr = depMgr;
8
9
  this.redraw = redraw;
10
+ this.getNativeId = getNativeId;
9
11
 
10
12
  _defineProperty(this, "_root", void 0);
11
13
 
@@ -1 +1 @@
1
- {"version":3,"names":["JsiSkDOM","Container","constructor","Skia","depMgr","redraw","Sk","_root","Group","draw","ctx","render","root"],"sources":["Container.tsx"],"sourcesContent":["import { JsiSkDOM } from \"../dom/nodes\";\nimport type {\n GroupProps,\n DrawingContext,\n RenderNode,\n SkDOM,\n} from \"../dom/types\";\nimport type { Skia } from \"../skia/types\";\n\nimport type { DependencyManager } from \"./DependencyManager\";\n\nexport class Container {\n private _root: RenderNode<GroupProps>;\n public Sk: SkDOM;\n constructor(\n Skia: Skia,\n public depMgr: DependencyManager,\n public redraw: () => void = () => {}\n ) {\n this.Sk = new JsiSkDOM({ Skia, depMgr });\n this._root = this.Sk.Group();\n }\n\n draw(ctx: DrawingContext) {\n this._root.render(ctx);\n }\n\n get root() {\n return this._root;\n }\n}\n"],"mappings":";;AAAA,SAASA,QAAT,QAAyB,cAAzB;AAWA,OAAO,MAAMC,SAAN,CAAgB;EAGrBC,WAAW,CACTC,IADS,EAEFC,MAFE,EAIT;IAAA,IADOC,MACP,uEAD4B,MAAM,CAAE,CACpC;IAAA,KAFOD,MAEP,GAFOA,MAEP;IAAA,KADOC,MACP,GADOA,MACP;;IAAA;;IAAA;;IACA,KAAKC,EAAL,GAAU,IAAIN,QAAJ,CAAa;MAAEG,IAAF;MAAQC;IAAR,CAAb,CAAV;IACA,KAAKG,KAAL,GAAa,KAAKD,EAAL,CAAQE,KAAR,EAAb;EACD;;EAEDC,IAAI,CAACC,GAAD,EAAsB;IACxB,KAAKH,KAAL,CAAWI,MAAX,CAAkBD,GAAlB;EACD;;EAEO,IAAJE,IAAI,GAAG;IACT,OAAO,KAAKL,KAAZ;EACD;;AAlBoB"}
1
+ {"version":3,"names":["JsiSkDOM","Container","constructor","Skia","depMgr","redraw","getNativeId","Sk","_root","Group","draw","ctx","render","root"],"sources":["Container.tsx"],"sourcesContent":["import { JsiSkDOM } from \"../dom/nodes\";\nimport type {\n GroupProps,\n DrawingContext,\n RenderNode,\n SkDOM,\n} from \"../dom/types\";\nimport type { Skia } from \"../skia/types\";\n\nimport type { DependencyManager } from \"./DependencyManager\";\n\nexport class Container {\n private _root: RenderNode<GroupProps>;\n public Sk: SkDOM;\n constructor(\n Skia: Skia,\n public depMgr: DependencyManager,\n public redraw: () => void = () => {},\n public getNativeId: () => number = () => 0\n ) {\n this.Sk = new JsiSkDOM({ Skia, depMgr });\n this._root = this.Sk.Group();\n }\n\n draw(ctx: DrawingContext) {\n this._root.render(ctx);\n }\n\n get root() {\n return this._root;\n }\n}\n"],"mappings":";;AAAA,SAASA,QAAT,QAAyB,cAAzB;AAWA,OAAO,MAAMC,SAAN,CAAgB;EAGrBC,WAAW,CACTC,IADS,EAEFC,MAFE,EAKT;IAAA,IAFOC,MAEP,uEAF4B,MAAM,CAAE,CAEpC;IAAA,IADOC,WACP,uEADmC,MAAM,CACzC;IAAA,KAHOF,MAGP,GAHOA,MAGP;IAAA,KAFOC,MAEP,GAFOA,MAEP;IAAA,KADOC,WACP,GADOA,WACP;;IAAA;;IAAA;;IACA,KAAKC,EAAL,GAAU,IAAIP,QAAJ,CAAa;MAAEG,IAAF;MAAQC;IAAR,CAAb,CAAV;IACA,KAAKI,KAAL,GAAa,KAAKD,EAAL,CAAQE,KAAR,EAAb;EACD;;EAEDC,IAAI,CAACC,GAAD,EAAsB;IACxB,KAAKH,KAAL,CAAWI,MAAX,CAAkBD,GAAlB;EACD;;EAEO,IAAJE,IAAI,GAAG;IACT,OAAO,KAAKL,KAAZ;EACD;;AAnBoB"}
@@ -1,5 +1,6 @@
1
1
  /*global NodeJS*/
2
2
  import { DefaultEventPriority } from "react-reconciler/constants";
3
+ import { bindReanimatedProps, extractReanimatedProps } from "../external/reanimated";
3
4
  import { createNode } from "./HostComponents";
4
5
  import { isSelector, isValue } from "./processors";
5
6
  import { mapKeys, shallowEq } from "./typeddash";
@@ -68,9 +69,9 @@ export const skHostConfig = {
68
69
 
69
70
  createInstance(type, pristineProps, container, _hostContext, _internalInstanceHandle) {
70
71
  debug("createInstance", type);
71
- const props = { ...pristineProps
72
- };
72
+ const [props, reanimatedProps] = extractReanimatedProps(pristineProps);
73
73
  const node = createNode(container, type, materialize(props));
74
+ bindReanimatedProps(container, node, reanimatedProps);
74
75
  container.depMgr.subscribeNode(node, props);
75
76
  return node;
76
77
  },
@@ -125,10 +126,10 @@ export const skHostConfig = {
125
126
  return;
126
127
  }
127
128
 
128
- const props = { ...nextProps
129
- };
129
+ const [props, reanimatedProps] = extractReanimatedProps(nextProps);
130
130
  updatePayload.depMgr.unsubscribeNode(instance);
131
131
  instance.setProps(materialize(props));
132
+ bindReanimatedProps(updatePayload, instance, reanimatedProps);
132
133
  updatePayload.depMgr.subscribeNode(instance, props);
133
134
  },
134
135