@shopify/react-native-skia 0.1.141 → 0.1.145

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +2 -2
  2. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +1 -1
  3. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +15 -16
  4. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +2 -2
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +69 -27
  6. package/cpp/api/JsiSkPaint.h +6 -0
  7. package/cpp/api/JsiSkPathFactory.h +1 -1
  8. package/cpp/api/JsiSkPicture.h +7 -1
  9. package/cpp/rnskia/RNSkDrawView.cpp +66 -66
  10. package/cpp/rnskia/RNSkDrawView.h +22 -6
  11. package/cpp/rnskia/RNSkJsiViewApi.h +2 -2
  12. package/cpp/rnskia/values/RNSkComputedValue.h +10 -7
  13. package/cpp/rnskia/values/RNSkReadonlyValue.h +21 -2
  14. package/cpp/rnskia/values/RNSkValue.h +1 -0
  15. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +1 -1
  16. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +2 -2
  17. package/ios/RNSkia-iOS/SkiaDrawView.mm +4 -0
  18. package/lib/commonjs/mock/index.js +3 -1
  19. package/lib/commonjs/mock/index.js.map +1 -1
  20. package/lib/commonjs/renderer/Canvas.js +17 -7
  21. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  22. package/lib/commonjs/renderer/DependencyManager.js +144 -36
  23. package/lib/commonjs/renderer/DependencyManager.js.map +1 -1
  24. package/lib/commonjs/renderer/HostConfig.js +1 -1
  25. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  26. package/lib/commonjs/renderer/components/Blend.js +20 -5
  27. package/lib/commonjs/renderer/components/Blend.js.map +1 -1
  28. package/lib/commonjs/renderer/components/backdrop/BackdropFilter.js.map +1 -1
  29. package/lib/commonjs/renderer/components/imageFilters/Morphology.js +1 -1
  30. package/lib/commonjs/renderer/components/imageFilters/Morphology.js.map +1 -1
  31. package/lib/commonjs/renderer/components/imageFilters/Shadow.js +1 -1
  32. package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -1
  33. package/lib/commonjs/renderer/nodes/Declaration.js +2 -3
  34. package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
  35. package/lib/commonjs/renderer/nodes/Drawing.js +3 -7
  36. package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
  37. package/lib/commonjs/renderer/nodes/Node.js +9 -7
  38. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  39. package/lib/commonjs/renderer/processors/Animations/Animations.js +14 -20
  40. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  41. package/lib/commonjs/skia/core/Data.js +10 -22
  42. package/lib/commonjs/skia/core/Data.js.map +1 -1
  43. package/lib/commonjs/skia/core/Font.js +2 -3
  44. package/lib/commonjs/skia/core/Font.js.map +1 -1
  45. package/lib/commonjs/skia/core/Image.js.map +1 -1
  46. package/lib/commonjs/skia/core/SVG.js.map +1 -1
  47. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  48. package/lib/commonjs/skia/types/Data/Data.js +5 -0
  49. package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
  50. package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
  51. package/lib/commonjs/skia/web/Host.js +12 -21
  52. package/lib/commonjs/skia/web/Host.js.map +1 -1
  53. package/lib/commonjs/skia/web/JsiSkCanvas.js +50 -28
  54. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  55. package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js +4 -4
  56. package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js.map +1 -1
  57. package/lib/commonjs/skia/web/JsiSkFont.js +7 -3
  58. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  59. package/lib/commonjs/skia/web/JsiSkImage.js +4 -2
  60. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  61. package/lib/commonjs/skia/web/JsiSkImageFactory.js +4 -2
  62. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  63. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +61 -19
  64. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  65. package/lib/commonjs/skia/web/JsiSkMatrix.js +1 -1
  66. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  67. package/lib/commonjs/skia/web/JsiSkPaint.js +19 -6
  68. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  69. package/lib/commonjs/skia/web/JsiSkPath.js +16 -60
  70. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  71. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +7 -3
  72. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  73. package/lib/commonjs/skia/web/JsiSkPathFactory.js +1 -1
  74. package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
  75. package/lib/commonjs/skia/web/JsiSkPicture.js +5 -1
  76. package/lib/commonjs/skia/web/JsiSkPicture.js.map +1 -1
  77. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js +3 -1
  78. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js.map +1 -1
  79. package/lib/commonjs/skia/web/JsiSkPoint.js +9 -1
  80. package/lib/commonjs/skia/web/JsiSkPoint.js.map +1 -1
  81. package/lib/commonjs/skia/web/JsiSkRRect.js +9 -1
  82. package/lib/commonjs/skia/web/JsiSkRRect.js.map +1 -1
  83. package/lib/commonjs/skia/web/JsiSkRSXform.js.map +1 -1
  84. package/lib/commonjs/skia/web/JsiSkRect.js +3 -3
  85. package/lib/commonjs/skia/web/JsiSkRect.js.map +1 -1
  86. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js +4 -2
  87. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  88. package/lib/commonjs/skia/web/JsiSkShaderFactory.js +10 -6
  89. package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
  90. package/lib/commonjs/skia/web/JsiSkSurface.js +3 -1
  91. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  92. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +8 -4
  93. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  94. package/lib/commonjs/skia/web/JsiSkTypefaceFactory.js +1 -1
  95. package/lib/commonjs/skia/web/JsiSkTypefaceFactory.js.map +1 -1
  96. package/lib/commonjs/skia/web/JsiSkia.js +12 -6
  97. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  98. package/lib/commonjs/values/hooks/useComputedValue.js +6 -2
  99. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  100. package/lib/commonjs/values/index.js +13 -0
  101. package/lib/commonjs/values/index.js.map +1 -1
  102. package/lib/commonjs/values/selector.js +24 -0
  103. package/lib/commonjs/values/selector.js.map +1 -0
  104. package/lib/commonjs/values/web/RNSkComputedValue.js +8 -0
  105. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -1
  106. package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -0
  107. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
  108. package/lib/module/mock/index.js +2 -1
  109. package/lib/module/mock/index.js.map +1 -1
  110. package/lib/module/renderer/Canvas.js +17 -6
  111. package/lib/module/renderer/Canvas.js.map +1 -1
  112. package/lib/module/renderer/DependencyManager.js +141 -34
  113. package/lib/module/renderer/DependencyManager.js.map +1 -1
  114. package/lib/module/renderer/HostConfig.js +1 -1
  115. package/lib/module/renderer/HostConfig.js.map +1 -1
  116. package/lib/module/renderer/components/Blend.js +21 -5
  117. package/lib/module/renderer/components/Blend.js.map +1 -1
  118. package/lib/module/renderer/components/backdrop/BackdropFilter.js.map +1 -1
  119. package/lib/module/renderer/components/imageFilters/Morphology.js +1 -1
  120. package/lib/module/renderer/components/imageFilters/Morphology.js.map +1 -1
  121. package/lib/module/renderer/components/imageFilters/Shadow.js +1 -1
  122. package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -1
  123. package/lib/module/renderer/nodes/Declaration.js +3 -4
  124. package/lib/module/renderer/nodes/Declaration.js.map +1 -1
  125. package/lib/module/renderer/nodes/Drawing.js +3 -6
  126. package/lib/module/renderer/nodes/Drawing.js.map +1 -1
  127. package/lib/module/renderer/nodes/Node.js +9 -7
  128. package/lib/module/renderer/nodes/Node.js.map +1 -1
  129. package/lib/module/renderer/processors/Animations/Animations.js +9 -15
  130. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  131. package/lib/module/skia/core/Data.js +10 -20
  132. package/lib/module/skia/core/Data.js.map +1 -1
  133. package/lib/module/skia/core/Font.js +2 -3
  134. package/lib/module/skia/core/Font.js.map +1 -1
  135. package/lib/module/skia/core/Image.js.map +1 -1
  136. package/lib/module/skia/core/SVG.js.map +1 -1
  137. package/lib/module/skia/core/Typeface.js.map +1 -1
  138. package/lib/module/skia/types/Data/Data.js +1 -1
  139. package/lib/module/skia/types/Data/Data.js.map +1 -1
  140. package/lib/module/skia/types/Paint/Paint.js.map +1 -1
  141. package/lib/module/skia/web/Host.js +9 -9
  142. package/lib/module/skia/web/Host.js.map +1 -1
  143. package/lib/module/skia/web/JsiSkCanvas.js +40 -29
  144. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  145. package/lib/module/skia/web/JsiSkColorFilterFactory.js +5 -5
  146. package/lib/module/skia/web/JsiSkColorFilterFactory.js.map +1 -1
  147. package/lib/module/skia/web/JsiSkFont.js +6 -4
  148. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  149. package/lib/module/skia/web/JsiSkImage.js +4 -3
  150. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  151. package/lib/module/skia/web/JsiSkImageFactory.js +4 -3
  152. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  153. package/lib/module/skia/web/JsiSkImageFilterFactory.js +61 -20
  154. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  155. package/lib/module/skia/web/JsiSkMatrix.js +2 -2
  156. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  157. package/lib/module/skia/web/JsiSkPaint.js +15 -7
  158. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  159. package/lib/module/skia/web/JsiSkPath.js +15 -62
  160. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  161. package/lib/module/skia/web/JsiSkPathEffectFactory.js +6 -4
  162. package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  163. package/lib/module/skia/web/JsiSkPathFactory.js +2 -2
  164. package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
  165. package/lib/module/skia/web/JsiSkPicture.js +4 -2
  166. package/lib/module/skia/web/JsiSkPicture.js.map +1 -1
  167. package/lib/module/skia/web/JsiSkPictureRecorder.js +3 -2
  168. package/lib/module/skia/web/JsiSkPictureRecorder.js.map +1 -1
  169. package/lib/module/skia/web/JsiSkPoint.js +10 -2
  170. package/lib/module/skia/web/JsiSkPoint.js.map +1 -1
  171. package/lib/module/skia/web/JsiSkRRect.js +10 -2
  172. package/lib/module/skia/web/JsiSkRRect.js.map +1 -1
  173. package/lib/module/skia/web/JsiSkRSXform.js.map +1 -1
  174. package/lib/module/skia/web/JsiSkRect.js +4 -4
  175. package/lib/module/skia/web/JsiSkRect.js.map +1 -1
  176. package/lib/module/skia/web/JsiSkRuntimeEffect.js +4 -3
  177. package/lib/module/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  178. package/lib/module/skia/web/JsiSkShaderFactory.js +9 -7
  179. package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
  180. package/lib/module/skia/web/JsiSkSurface.js +3 -2
  181. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  182. package/lib/module/skia/web/JsiSkTextBlobFactory.js +7 -5
  183. package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  184. package/lib/module/skia/web/JsiSkTypefaceFactory.js +2 -2
  185. package/lib/module/skia/web/JsiSkTypefaceFactory.js.map +1 -1
  186. package/lib/module/skia/web/JsiSkia.js +10 -5
  187. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  188. package/lib/module/values/hooks/useComputedValue.js +7 -3
  189. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  190. package/lib/module/values/index.js +1 -0
  191. package/lib/module/values/index.js.map +1 -1
  192. package/lib/module/values/selector.js +15 -0
  193. package/lib/module/values/selector.js.map +1 -0
  194. package/lib/module/values/web/RNSkComputedValue.js +8 -0
  195. package/lib/module/values/web/RNSkComputedValue.js.map +1 -1
  196. package/lib/module/values/web/RNSkReadonlyValue.js +4 -0
  197. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
  198. package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
  199. package/lib/typescript/src/renderer/DependencyManager.d.ts +40 -14
  200. package/lib/typescript/src/renderer/nodes/Declaration.d.ts +2 -2
  201. package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
  202. package/lib/typescript/src/renderer/nodes/Node.d.ts +3 -2
  203. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +7 -3
  204. package/lib/typescript/src/skia/core/Data.d.ts +3 -5
  205. package/lib/typescript/src/skia/core/Font.d.ts +2 -2
  206. package/lib/typescript/src/skia/core/Image.d.ts +2 -2
  207. package/lib/typescript/src/skia/core/SVG.d.ts +2 -2
  208. package/lib/typescript/src/skia/core/Typeface.d.ts +2 -2
  209. package/lib/typescript/src/skia/types/Data/Data.d.ts +10 -3
  210. package/lib/typescript/src/skia/types/Paint/Paint.d.ts +5 -0
  211. package/lib/typescript/src/skia/types/Picture/Picture.d.ts +2 -1
  212. package/lib/typescript/src/skia/web/Host.d.ts +6 -8
  213. package/lib/typescript/src/skia/web/JsiSkImageFilterFactory.d.ts +8 -8
  214. package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -0
  215. package/lib/typescript/src/skia/web/JsiSkPoint.d.ts +3 -2
  216. package/lib/typescript/src/skia/web/JsiSkRRect.d.ts +3 -2
  217. package/lib/typescript/src/skia/web/JsiSkRSXform.d.ts +1 -2
  218. package/lib/typescript/src/skia/web/JsiSkRect.d.ts +3 -3
  219. package/lib/typescript/src/skia/web/JsiSkTextBlobFactory.d.ts +2 -1
  220. package/lib/typescript/src/values/index.d.ts +1 -0
  221. package/lib/typescript/src/values/selector.d.ts +14 -0
  222. package/lib/typescript/src/values/types.d.ts +4 -0
  223. package/lib/typescript/src/values/web/RNSkComputedValue.d.ts +1 -0
  224. package/lib/typescript/src/values/web/RNSkReadonlyValue.d.ts +1 -0
  225. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  226. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  227. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  228. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  229. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  230. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  231. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  232. package/package.json +3 -3
  233. package/src/mock/index.ts +2 -1
  234. package/src/renderer/Canvas.tsx +19 -7
  235. package/src/renderer/DependencyManager.tsx +171 -37
  236. package/src/renderer/HostConfig.ts +1 -1
  237. package/src/renderer/components/Blend.tsx +25 -5
  238. package/src/renderer/components/backdrop/BackdropFilter.tsx +1 -1
  239. package/src/renderer/components/imageFilters/Morphology.tsx +2 -2
  240. package/src/renderer/components/imageFilters/Shadow.tsx +2 -2
  241. package/src/renderer/nodes/Declaration.tsx +6 -8
  242. package/src/renderer/nodes/Drawing.tsx +5 -7
  243. package/src/renderer/nodes/Node.ts +11 -9
  244. package/src/renderer/processors/Animations/Animations.ts +23 -14
  245. package/src/skia/core/Data.ts +20 -51
  246. package/src/skia/core/Font.ts +4 -5
  247. package/src/skia/core/Image.ts +2 -2
  248. package/src/skia/core/SVG.ts +2 -2
  249. package/src/skia/core/Typeface.ts +2 -2
  250. package/src/skia/types/Data/Data.ts +11 -1
  251. package/src/skia/types/Paint/Paint.ts +6 -0
  252. package/src/skia/types/Picture/Picture.ts +2 -1
  253. package/src/skia/web/Host.ts +12 -22
  254. package/src/skia/web/JsiSkCanvas.ts +99 -56
  255. package/src/skia/web/JsiSkColorFilterFactory.ts +15 -5
  256. package/src/skia/web/JsiSkFont.ts +11 -4
  257. package/src/skia/web/JsiSkImage.ts +4 -3
  258. package/src/skia/web/JsiSkImageFactory.ts +6 -3
  259. package/src/skia/web/JsiSkImageFilterFactory.ts +124 -52
  260. package/src/skia/web/JsiSkMatrix.ts +4 -2
  261. package/src/skia/web/JsiSkPaint.ts +15 -7
  262. package/src/skia/web/JsiSkPath.ts +30 -56
  263. package/src/skia/web/JsiSkPathEffectFactory.ts +10 -5
  264. package/src/skia/web/JsiSkPathFactory.ts +3 -3
  265. package/src/skia/web/JsiSkPicture.ts +5 -3
  266. package/src/skia/web/JsiSkPictureRecorder.ts +3 -2
  267. package/src/skia/web/JsiSkPoint.ts +12 -2
  268. package/src/skia/web/JsiSkRRect.ts +16 -2
  269. package/src/skia/web/JsiSkRSXform.ts +1 -1
  270. package/src/skia/web/JsiSkRect.ts +4 -7
  271. package/src/skia/web/JsiSkRuntimeEffect.ts +9 -4
  272. package/src/skia/web/JsiSkShaderFactory.ts +24 -15
  273. package/src/skia/web/JsiSkSurface.ts +7 -2
  274. package/src/skia/web/JsiSkTextBlobFactory.ts +14 -8
  275. package/src/skia/web/JsiSkTypefaceFactory.tsx +4 -2
  276. package/src/skia/web/JsiSkia.ts +17 -5
  277. package/src/values/hooks/useComputedValue.ts +6 -3
  278. package/src/values/index.ts +1 -0
  279. package/src/values/selector.ts +24 -0
  280. package/src/values/types.ts +4 -0
  281. package/src/values/web/RNSkComputedValue.ts +6 -0
  282. package/src/values/web/RNSkReadonlyValue.ts +4 -0
@@ -9,6 +9,8 @@ var Values = _interopRequireWildcard(require("../values/web"));
9
9
 
10
10
  var ValuesHooks = _interopRequireWildcard(require("../values/hooks"));
11
11
 
12
+ var _selector = require("../values/selector");
13
+
12
14
  var BaseSkia = _interopRequireWildcard(require("../skia/types"));
13
15
 
14
16
  var _useSharedValueEffect = require("../external/reanimated/useSharedValueEffect");
@@ -64,7 +66,6 @@ const Mock = {
64
66
  Skia,
65
67
  ...BaseSkia,
66
68
  // 2. Hooks
67
- useDataCollection: Noop,
68
69
  useRawData: Noop,
69
70
  useData: Noop,
70
71
  useFont: Noop,
@@ -113,6 +114,7 @@ const Mock = {
113
114
  // ValueExports
114
115
  ...Values,
115
116
  ...ValuesHooks,
117
+ Selector: _selector.Selector,
116
118
  // Animations
117
119
  ...timingFunctions,
118
120
  ...springFunctions,
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useDataCollection","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","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","useSharedValueEffect","Values","ValuesHooks","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","ShaderLib","createDrawing","createDeclaration"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAjBA;AAmBA,MAAMA,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,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BAAkB,EAAExC,IAzChB;AA0CJ;AACAyC,EAAAA,oBAAoB,EAApBA,0CA3CI;AA4CJ;AACA,KAAGC,MA7CC;AA8CJ,KAAGC,WA9CC;AA+CJ;AACA,KAAGC,eAhDC;AAiDJ,KAAGC,eAjDC;AAkDJ,KAAGC,cAlDC;AAmDJ,KAAGC,aAnDC;AAoDJ,KAAGC,iBApDC;AAqDJ,KAAGC,mBArDC;AAsDJC,EAAAA,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA1DD;AA2DJC,EAAAA,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;AA4DJK,EAAAA,SAAS,EAATA,oBA5DI;AA6DJC,EAAAA,aAAa,EAAE7D,IA7DX;AA8DJ8D,EAAAA,iBAAiB,EAAE9D;AA9Df,CAPC","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 * 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 useDataCollection: Noop,\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: 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 // 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"]}
1
+ {"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","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","useSharedValueEffect","Values","ValuesHooks","Selector","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","ShaderLib","createDrawing","createDeclaration"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAlBA;AAoBA,MAAMA,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEO,MAAMC,IAAa,GAAG,IAAIP,IAAJ,EAAtB;;;AAEA,MAAMQ,GAAG,GAAG,CAACC,CAAD,EAAaC,CAAb;AAAA;;AAAA,SAA6B;AAAED,IAAAA,CAAC,EAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAO,CAAV;AAAaC,IAAAA,CAAC,UAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAOD,CAAP,uCAAY;AAA1B,GAA7B;AAAA,CAAZ;;;A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,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;AA4DJK,EAAAA,SAAS,EAATA,oBA5DI;AA6DJC,EAAAA,aAAa,EAAE7D,IA7DX;AA8DJ8D,EAAAA,iBAAiB,EAAE9D;AA9Df,CAPC","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 usePicture: 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"]}
@@ -41,7 +41,7 @@ skiaReconciler.injectIntoDevTools({
41
41
  const render = (element, root, container) => {
42
42
  skiaReconciler.updateContainer(element, root, null, () => {
43
43
  (0, _HostConfig.debug)("updateContainer");
44
- container.depMgr.subscribe();
44
+ container.depMgr.update();
45
45
  });
46
46
  };
47
47
 
@@ -68,14 +68,22 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
68
68
  const ref = useCombinedRefs(forwardedRef, innerRef);
69
69
  const [tick, setTick] = (0, _react.useState)(0);
70
70
  const redraw = (0, _react.useCallback)(() => setTick(t => t + 1), []);
71
- const container = (0, _react.useMemo)(() => new _nodes.Container(new _DependencyManager.DependencyManager(ref), redraw), [redraw, ref]);
71
+ const registerValues = (0, _react.useCallback)(values => {
72
+ if (ref.current === null) {
73
+ throw new Error("Canvas ref is not set");
74
+ }
75
+
76
+ return ref.current.registerValues(values);
77
+ }, [ref]);
78
+ const container = (0, _react.useMemo)(() => new _nodes.Container(new _DependencyManager.DependencyManager(registerValues), redraw), [redraw, registerValues]);
72
79
  const root = (0, _react.useMemo)(() => skiaReconciler.createContainer(container, 0, false, null), [container]); // Render effect
73
80
 
74
81
  (0, _react.useEffect)(() => {
75
82
  render( /*#__PURE__*/_react.default.createElement(_useCanvas.CanvasProvider, {
76
83
  value: canvasCtx
77
84
  }, children), root, container);
78
- }, [children, root, redraw, container, canvasCtx]); // Draw callback
85
+ }, [children, root, redraw, container, canvasCtx]);
86
+ const paint = (0, _react.useMemo)(() => _Skia.Skia.Paint(), []); // Draw callback
79
87
 
80
88
  const onDraw = (0, _views.useDrawCallback)((canvas, info) => {
81
89
  // TODO: if tree is empty (count === 1) maybe we should not render?
@@ -96,8 +104,7 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
96
104
  };
97
105
  }
98
106
 
99
- const paint = _Skia.Skia.Paint();
100
-
107
+ paint.reset();
101
108
  const ctx = {
102
109
  width,
103
110
  height,
@@ -106,7 +113,10 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
106
113
  paint,
107
114
  opacity: 1,
108
115
  ref,
109
- center: _Skia.Skia.Point(width / 2, height / 2),
116
+ center: {
117
+ x: width / 2,
118
+ y: height / 2
119
+ },
110
120
  Skia: _Skia.Skia
111
121
  };
112
122
  container.draw(ctx);
@@ -114,7 +124,7 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
114
124
  (0, _react.useEffect)(() => {
115
125
  return () => {
116
126
  skiaReconciler.updateContainer(null, root, null, () => {
117
- container.depMgr.unsubscribe();
127
+ container.depMgr.remove();
118
128
  });
119
129
  };
120
130
  }, [container, root]);
@@ -1 +1 @@
1
- {"version":3,"sources":["Canvas.tsx"],"names":["skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","Canvas","forwardedRef","children","style","debug","mode","onTouch","size","width","height","canvasCtx","Skia","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","Container","DependencyManager","createContainer","onDraw","canvas","info","timestamp","touches","current","paint","Paint","ctx","opacity","center","Point","draw","unsubscribe","refs","targetRef","React","useRef","useEffect","forEach"],"mappings":";;;;;;;AAAA;;AAgBA;;AAEA;;AAEA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;;;;;;;AAHA;AAKO,MAAMA,cAAc,GAAG,8BAAgBC,wBAAhB,CAAvB;;AAEPD,cAAc,CAACE,kBAAf,CAAkC;AAChCC,EAAAA,UAAU,EAAE,CADoB;AAEhCC,EAAAA,OAAO,EAAE,OAFuB;AAGhCC,EAAAA,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;AAC7ET,EAAAA,cAAc,CAACU,eAAf,CAA+BH,OAA/B,EAAwCC,IAAxC,EAA8C,IAA9C,EAAoD,MAAM;AACxD,2BAAU,iBAAV;AAEAC,IAAAA,SAAS,CAACE,MAAV,CAAiBC,SAAjB;AACD,GAJD;AAKD,CAND;;AAQO,MAAMC,YAAY,GAAG,MAAM,mBAAiB,IAAjB,CAA3B;;;AAQA,MAAMC,MAAM,gBAAG,uBACpB,OAA4CC,YAA5C,KAA6D;AAAA,MAA5D;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,KAAnB;AAA0BC,IAAAA,IAA1B;AAAgCC,IAAAA;AAAhC,GAA4D;AAC3D,QAAMC,IAAI,GAAG,wBAAS;AAAEC,IAAAA,KAAK,EAAE,CA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T,IADF;AASD,CA3EmB,CAAf;AA8EP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMU,eAAe,GAAG,YAEnB;AAAA,oCADAsB,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAGC,eAAMC,MAAN,CAAgB,IAAhB,CAAlB;;AACAD,iBAAME,SAAN,CAAgB,MAAM;AACpBJ,IAAAA,IAAI,CAACK,OAAL,CAAc5B,GAAD,IAAS;AACpB,UAAIA,GAAJ,EAAS;AACP,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAACwB,SAAS,CAACV,OAAX,CAAH;AACD,SAFD,MAEO;AACLd,UAAAA,GAAG,CAACc,OAAJ,GAAcU,SAAS,CAACV,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACS,IAAD,CAVH;;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport { SkiaView, useDrawCallback } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport { Skia } from \"../skia/Skia\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n\n container.depMgr.subscribe();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaView>(null);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaView> {\n ref?: RefObject<SkiaView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch }, forwardedRef) => {\n const size = useValue({ width: 0, height: 0 });\n const canvasCtx = useMemo(() => ({ Skia, size }), [size]);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [tick, setTick] = useState(0);\n const redraw = useCallback(() => setTick((t) => t + 1), []);\n\n const container = useMemo(\n () => new Container(new DependencyManager(ref), redraw),\n [redraw, ref]\n );\n\n const root = useMemo(\n () => skiaReconciler.createContainer(container, 0, false, null),\n [container]\n );\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={canvasCtx}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container, canvasCtx]);\n\n // Draw callback\n const onDraw = useDrawCallback(\n (canvas, info) => {\n // TODO: if tree is empty (count === 1) maybe we should not render?\n const { width, height, timestamp } = info;\n if (onTouch) {\n onTouch(info.touches);\n }\n if (\n width !== canvasCtx.size.current.width ||\n height !== canvasCtx.size.current.height\n ) {\n canvasCtx.size.current = { width, height };\n }\n const paint = Skia.Paint();\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: Skia.Point(width / 2, height / 2),\n Skia,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.unsubscribe();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaView\n ref={ref}\n style={style}\n onDraw={onDraw}\n mode={mode}\n debug={debug}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"]}
1
+ {"version":3,"sources":["Canvas.tsx"],"names":["skiaReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","update","useCanvasRef","Canvas","forwardedRef","children","style","debug","mode","onTouch","size","width","height","canvasCtx","Skia","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","registerValues","values","current","Error","Container","DependencyManager","createContainer","paint","Paint","onDraw","canvas","info","timestamp","touches","reset","ctx","opacity","center","x","y","draw","remove","refs","targetRef","React","useRef","useEffect","forEach"],"mappings":";;;;;;;AAAA;;AAgBA;;AAEA;;AAEA;;AACA;;AAGA;;AAEA;;AACA;;AACA;;;;;;;;AAHA;AAKO,MAAMA,cAAc,GAAG,8BAAgBC,wBAAhB,CAAvB;;AAEPD,cAAc,CAACE,kBAAf,CAAkC;AAChCC,EAAAA,UAAU,EAAE,CADoB;AAEhCC,EAAAA,OAAO,EAAE,OAFuB;AAGhCC,EAAAA,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;AAC7ET,EAAAA,cAAc,CAACU,eAAf,CAA+BH,OAA/B,EAAwCC,IAAxC,EAA8C,IAA9C,EAAoD,MAAM;AACxD,2BAAU,iBAAV;AACAC,IAAAA,SAAS,CAACE,MAAV,CAAiBC,MAAjB;AACD,GAHD;AAID,CALD;;AAOO,MAAMC,YAAY,GAAG,MAAM,mBAAiB,IAAjB,CAA3B;;;AAQA,MAAMC,MAAM,gBAAG,uBACp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AAA,IAAI,EAAJA;AATU,KAAZ;AAWAhB,IAAAA,SAAS,CAAC4C,IAAV,CAAeL,GAAf;AACD,GA1BY,EA2Bb,CAACnB,IAAD,EAAOT,OAAP,CA3Ba,CAAf;AA8BA,wBAAU,MAAM;AACd,WAAO,MAAM;AACXpB,MAAAA,cAAc,CAACU,eAAf,CAA+B,IAA/B,EAAqCF,IAArC,EAA2C,IAA3C,EAAiD,MAAM;AACrDC,QAAAA,SAAS,CAACE,MAAV,CAAiB2C,MAAjB;AACD,OAFD;AAGD,KAJD;AAKD,GAND,EAMG,CAAC7C,SAAD,EAAYD,IAAZ,CANH;AAQA,sBACE,6BAAC,eAAD;AACE,IAAA,GAAG,EAAEmB,GADP;AAEE,IAAA,KAAK,EAAEV,KAFT;AAGE,IAAA,MAAM,EAAEyB,MAHV;AAIE,IAAA,IAAI,EAAEvB,IAJR;AAKE,IAAA,KAAK,EAAED;AALT,IADF;AASD,CAvFmB,CAAf;AA0FP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMU,eAAe,GAAG,YAEnB;AAAA,oCADA2B,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAGC,eAAMC,MAAN,CAAgB,IAAhB,CAAlB;;AACAD,iBAAME,SAAN,CAAgB,MAAM;AACpBJ,IAAAA,IAAI,CAACK,OAAL,CAAcjC,GAAD,IAAS;AACpB,UAAIA,GAAJ,EAAS;AACP,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAAC6B,SAAS,CAACrB,OAAX,CAAH;AACD,SAFD,MAEO;AACLR,UAAAA,GAAG,CAACQ,OAAJ,GAAcqB,SAAS,CAACrB,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACoB,IAAD,CAVH;;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport { SkiaView, useDrawCallback } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaValue } from \"../values\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n container.depMgr.update();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaView>(null);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaView> {\n ref?: RefObject<SkiaView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch }, forwardedRef) => {\n const size = useValue({ width: 0, height: 0 });\n const canvasCtx = useMemo(() => ({ Skia, size }), [size]);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [tick, setTick] = useState(0);\n const redraw = useCallback(() => setTick((t) => t + 1), []);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current === null) {\n throw new Error(\"Canvas ref is not set\");\n }\n return ref.current.registerValues(values);\n },\n [ref]\n );\n\n const container = useMemo(\n () => new Container(new DependencyManager(registerValues), redraw),\n [redraw, registerValues]\n );\n\n const root = useMemo(\n () => skiaReconciler.createContainer(container, 0, false, null),\n [container]\n );\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={canvasCtx}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container, canvasCtx]);\n\n const paint = useMemo(() => Skia.Paint(), []);\n\n // Draw callback\n const onDraw = useDrawCallback(\n (canvas, info) => {\n // TODO: if tree is empty (count === 1) maybe we should not render?\n const { width, height, timestamp } = info;\n if (onTouch) {\n onTouch(info.touches);\n }\n if (\n width !== canvasCtx.size.current.width ||\n height !== canvasCtx.size.current.height\n ) {\n canvasCtx.size.current = { width, height };\n }\n paint.reset();\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: { x: width / 2, y: height / 2 },\n Skia,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.remove();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaView\n ref={ref}\n style={style}\n onDraw={onDraw}\n mode={mode}\n debug={debug}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"]}
@@ -7,64 +7,172 @@ exports.DependencyManager = void 0;
7
7
 
8
8
  var _processors = require("./processors");
9
9
 
10
+ var _typeddash = require("./typeddash");
11
+
10
12
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
13
 
12
14
  class DependencyManager {
13
- constructor(ref) {
14
- _defineProperty(this, "ref", void 0);
15
+ constructor(registerValues) {
16
+ _defineProperty(this, "registerValues", void 0);
15
17
 
16
18
  _defineProperty(this, "subscriptions", new Map());
17
19
 
18
- this.ref = ref;
19
- }
20
-
21
- unSubscribeNode(node) {
22
- const subscription = this.subscriptions.get(node);
20
+ _defineProperty(this, "unregisterDependantValues", null);
23
21
 
24
- if (subscription && subscription.unsubscribe) {
25
- subscription.unsubscribe();
22
+ this.registerValues = registerValues;
23
+ }
24
+ /**
25
+ * Call to unsubscribe all value listeners from the given node based
26
+ * on the current list of subscriptions for the node. This function
27
+ * is typically called when the node is unmounted or when one or more
28
+ * properties have changed.
29
+ * @param node Node to unsubscribe value listeners from
30
+ */
31
+
32
+
33
+ unsubscribeNode(node) {
34
+ const subscriptions = Array.from(this.subscriptions.values()).filter(p => p.nodes.has(node));
35
+
36
+ if (subscriptions) {
37
+ subscriptions.forEach(si => {
38
+ // Delete node from subscription
39
+ si.nodes.delete(node); // Remove subscription if there are no listeneres left on the value
40
+
41
+ if (si.nodes.size === 0) {
42
+ // There are no more nodes subscribing to this value, we can call
43
+ // unsubscribe on it.
44
+ if (!si.unsubscribe) {
45
+ throw new Error("Failed to unsubscribe to value subscription");
46
+ }
47
+
48
+ si.unsubscribe && si.unsubscribe(); // Remove from subscription states as well
49
+
50
+ const element = Array.from(this.subscriptions.entries()).find(_ref => {
51
+ let [_, sub] = _ref;
52
+ return sub === si;
53
+ });
54
+
55
+ if (!element) {
56
+ throw new Error("Failed to find value subscription");
57
+ }
58
+
59
+ if (!this.subscriptions.delete(element[0])) {
60
+ throw new Error("Failed to delete value subscription");
61
+ }
62
+ }
63
+ });
26
64
  }
27
-
28
- this.subscriptions.delete(node);
29
65
  }
66
+ /**
67
+ * Adds listeners to the provided values so that the node is notified
68
+ * when a value changes. This is done in an optimized way so that this
69
+ * class only needs to listen to the value once and then forwards the
70
+ * change to the node and its listener. This method is typically called
71
+ * when the node is mounted and when one or more props on the node changes.
72
+ * @param node Node to subscribe to value changes for
73
+ * @param props Node's properties
74
+ * @param onResolveProp Callback when a property value changes
75
+ */
76
+
30
77
 
31
78
  subscribeNode(node, props) {
32
- const values = Object.values(props).filter(_processors.isValue);
79
+ // Get mutators from node's properties
80
+ const propSubscriptions = initializePropertySubscriptions(node, props);
33
81
 
34
- if (values.length > 0) {
35
- this.subscriptions.set(node, {
36
- values,
37
- unsubscribe: null
38
- });
39
- }
40
- }
82
+ if (propSubscriptions.length === 0) {
83
+ return;
84
+ } // Install all mutators for the node
41
85
 
42
- subscribe() {
43
- if (this.ref.current === null) {
44
- throw new Error("Canvas ref is not set");
45
- }
46
86
 
47
- this.subscriptions.forEach(subscription => {
48
- if (subscription.unsubscribe === null) {
49
- subscription.unsubscribe = this.ref.current.registerValues(subscription.values);
50
- }
87
+ propSubscriptions.forEach(ps => {
88
+ // Do we already have a state for this SkiaValue
89
+ let subscriptionState = this.subscriptions.get(ps.value);
90
+
91
+ if (!subscriptionState) {
92
+ // Let's create a new subscription state for the skia value
93
+ subscriptionState = {
94
+ nodes: new Map(),
95
+ unsubscribe: null
96
+ }; // Add single subscription to the new value
97
+
98
+ subscriptionState.unsubscribe = ps.value.addListener(v => {
99
+ subscriptionState.nodes.forEach(mutators => mutators.forEach(m => m(v)));
100
+ });
101
+ this.subscriptions.set(ps.value, subscriptionState);
102
+ } // subscription mutators
103
+
104
+
105
+ subscriptionState.nodes.set(node, propSubscriptions.filter(m => m.value === ps.value).map(m => m.mutator));
51
106
  });
52
107
  }
108
+ /**
109
+ * Called when the hosting container is mounted or updated. This ensures that we have
110
+ * a ref to the underlying SkiaView so that we can registers redraw listeners
111
+ * on values used in the current View automatically.
112
+ */
53
113
 
54
- unsubscribe() {
55
- this.subscriptions.forEach(_ref => {
56
- let {
57
- unsubscribe
58
- } = _ref;
59
114
 
60
- if (unsubscribe) {
61
- unsubscribe();
62
- }
63
- });
115
+ update() {
116
+ // Remove any previous registrations
117
+ if (this.unregisterDependantValues) {
118
+ this.unregisterDependantValues();
119
+ } // Register redraw requests on the SkiaView for each unique value
120
+
121
+
122
+ this.unregisterDependantValues = this.registerValues(Array.from(this.subscriptions.keys()));
123
+ }
124
+ /**
125
+ * Called when the hosting container is unmounted or recreated. This ensures that we remove
126
+ * all subscriptions to Skia values so that we don't have any listeners left after
127
+ * the component is removed.
128
+ */
129
+
130
+
131
+ remove() {
132
+ // 1) Unregister redraw requests
133
+ if (this.unregisterDependantValues) {
134
+ this.unregisterDependantValues();
135
+ this.unregisterDependantValues = null;
136
+ } // 2) Unregister nodes
137
+
138
+
139
+ Array.from(this.subscriptions.values()).forEach(si => {
140
+ Array.from(si.nodes.keys()).forEach(node => this.unsubscribeNode(node));
141
+ }); // 3) Clear the rest of the subscriptions
142
+
64
143
  this.subscriptions.clear();
65
144
  }
66
145
 
67
146
  }
68
147
 
69
148
  exports.DependencyManager = DependencyManager;
149
+
150
+ const initializePropertySubscriptions = (node, props) => {
151
+ const nodePropSubscriptions = [];
152
+ (0, _typeddash.mapKeys)(props).forEach(key => {
153
+ const propvalue = props[key];
154
+
155
+ if ((0, _processors.isValue)(propvalue)) {
156
+ // Subscribe to changes
157
+ nodePropSubscriptions.push({
158
+ value: propvalue,
159
+ mutator: v => node.resolvedProps[key] = v
160
+ }); // Set initial value
161
+
162
+ node.resolvedProps[key] = propvalue.current;
163
+ } else if ((0, _processors.isSelector)(propvalue)) {
164
+ // Subscribe to changes
165
+ nodePropSubscriptions.push({
166
+ value: propvalue.value,
167
+ mutator: v => node.resolvedProps[key] = propvalue.selector(v)
168
+ }); // Set initial value
169
+
170
+ node.resolvedProps[key] = propvalue.selector(propvalue.value.current);
171
+ } else {
172
+ // Set initial value
173
+ node.resolvedProps[key] = propvalue;
174
+ }
175
+ });
176
+ return nodePropSubscriptions;
177
+ };
70
178
  //# sourceMappingURL=DependencyManager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["DependencyManager.tsx"],"names":["DependencyManager","constructor","ref","Map","unSubscribeNode","node","subscription","subscriptions","get","unsubscribe","delete","subscribeNode","props","values","Object","filter","isValue","length","set","subscribe","current","Error","forEach","registerValues","clear"],"mappings":";;;;;;;AAKA;;;;AAMO,MAAMA,iBAAN,CAAwB;AAO7BC,EAAAA,WAAW,CAACC,GAAD,EAA2B;AAAA;;AAAA,2CAFlC,IAAIC,GAAJ,EAEkC;;AACpC,SAAKD,GAAL,GAAWA,GAAX;AACD;;AAEDE,EAAAA,eAAe,CAACC,IAAD,EAAa;AAC1B,UAAMC,YAAY,GAAG,KAAKC,aAAL,CAAmBC,GAAnB,CAAuBH,IAAvB,CAArB;;AACA,QAAIC,YAAY,IAAIA,YAAY,CAACG,WAAjC,EAA8C;AAC5CH,MAAAA,YAAY,CAACG,WAAb;AACD;;AACD,SAAKF,aAAL,CAAmBG,MAAnB,CAA0BL,IAA1B;AACD;;AAEDM,EAAAA,aAAa,CAACN,IAAD,EAAaO,KAAb,EAA2B;AACtC,UAAMC,MAAM,GAAGC,MAAM,CAACD,MAAP,CAAcD,KAAd,EAAqBG,MAArB,CAA4BC,mBAA5B,CAAf;;AACA,QAAIH,MAAM,CAACI,MAAP,GAAgB,CAApB,EAAuB;AACrB,WAAKV,aAAL,CAAmBW,GAAnB,CAAuBb,IAAvB,EAA6B;AAAEQ,QAAAA,MAAF;AAAUJ,QAAAA,WAAW,EAAE;AAAvB,OAA7B;AACD;AACF;;AAEDU,EAAAA,SAAS,GAAG;AACV,QAAI,KAAKjB,GAAL,CAASkB,OAAT,KAAqB,IAAzB,EAA+B;AAC7B,YAAM,IAAIC,KAAJ,CAAU,uBAAV,CAAN;AACD;;AACD,SAAKd,aAAL,CAAmBe,OAAnB,CAA4BhB,YAAD,IAAkB;AAC3C,UAAIA,YAAY,CAACG,WAAb,KAA6B,IAAjC,EAAuC;AACrCH,QAAAA,YAAY,CAACG,WAAb,GAA2B,KAAKP,GAAL,CAASkB,OAAT,CAAkBG,cAAlB,CACzBjB,YAAY,CAACO,MADY,CAA3B;AAGD;AACF,KAND;AAOD;;AAEDJ,EAAAA,WAAW,GAAG;AACZ,SAAKF,aAAL,CAAmBe,OAAnB,CAA2B,QAAqB;AAAA,UAApB;AAAEb,QAAAA;AAAF,OAAoB;;AAC9C,UAAIA,WAAJ,EAAiB;AACfA,QAAAA,WAAW;AACZ;AACF,KAJD;AAKA,SAAKF,aAAL,CAAmBiB,KAAnB;AACD;;AA9C4B","sourcesContent":["import type { RefObject } from \"react\";\n\nimport type { SkiaView } from \"../views\";\nimport type { SkiaValue } from \"../values\";\n\nimport { isValue } from \"./processors\";\nimport type { Node } from \"./nodes\";\n\ntype Unsubscribe = () => void;\ntype Props = { [key: string]: unknown };\n\nexport class DependencyManager {\n ref: RefObject<SkiaView>;\n subscriptions: Map<\n Node,\n { values: SkiaValue<unknown>[]; unsubscribe: null | Unsubscribe }\n > = new Map();\n\n constructor(ref: RefObject<SkiaView>) {\n this.ref = ref;\n }\n\n unSubscribeNode(node: Node) {\n const subscription = this.subscriptions.get(node);\n if (subscription && subscription.unsubscribe) {\n subscription.unsubscribe();\n }\n this.subscriptions.delete(node);\n }\n\n subscribeNode(node: Node, props: Props) {\n const values = Object.values(props).filter(isValue);\n if (values.length > 0) {\n this.subscriptions.set(node, { values, unsubscribe: null });\n }\n }\n\n subscribe() {\n if (this.ref.current === null) {\n throw new Error(\"Canvas ref is not set\");\n }\n this.subscriptions.forEach((subscription) => {\n if (subscription.unsubscribe === null) {\n subscription.unsubscribe = this.ref.current!.registerValues(\n subscription.values\n );\n }\n });\n }\n\n unsubscribe() {\n this.subscriptions.forEach(({ unsubscribe }) => {\n if (unsubscribe) {\n unsubscribe();\n }\n });\n this.subscriptions.clear();\n }\n}\n"]}
1
+ {"version":3,"sources":["DependencyManager.tsx"],"names":["DependencyManager","constructor","registerValues","Map","unsubscribeNode","node","subscriptions","Array","from","values","filter","p","nodes","has","forEach","si","delete","size","unsubscribe","Error","element","entries","find","_","sub","subscribeNode","props","propSubscriptions","initializePropertySubscriptions","length","ps","subscriptionState","get","value","addListener","v","mutators","m","set","map","mutator","update","unregisterDependantValues","keys","remove","clear","nodePropSubscriptions","key","propvalue","push","resolvedProps","current","selector"],"mappings":";;;;;;;AAIA;;AACA;;;;AAUO,MAAMA,iBAAN,CAAwB;AAK7BC,EAAAA,WAAW,CACTC,cADS,EAET;AAAA;;AAAA,2CAL0D,IAAIC,GAAJ,EAK1D;;AAAA,uDAJ8C,IAI9C;;AACA,SAAKD,cAAL,GAAsBA,cAAtB;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;;;AACEE,EAAAA,eAAe,CAACC,IAAD,EAAa;AAC1B,UAAMC,aAAa,GAAGC,KAAK,CAACC,IAAN,CAAW,KAAKF,aAAL,CAAmBG,MAAnB,EAAX,EAAwCC,MAAxC,CAAgDC,CAAD,IACnEA,CAAC,CAACC,KAAF,CAAQC,GAAR,CAAYR,IAAZ,CADoB,CAAtB;;AAIA,QAAIC,aAAJ,EAAmB;AACjBA,MAAAA,aAAa,CAACQ,OAAd,CAAuBC,EAAD,IAAQ;AAC5B;AACAA,QAAAA,EAAE,CAACH,KAAH,CAASI,MAAT,CAAgBX,IAAhB,EAF4B,CAI5B;;AACA,YAAIU,EAAE,CAACH,KAAH,CAASK,IAAT,KAAkB,CAAtB,EAAyB;AACvB;AACA;AACA,cAAI,CAACF,EAAE,CAACG,WAAR,EAAqB;AACnB,kBAAM,IAAIC,KAAJ,CAAU,6CAAV,CAAN;AACD;;AACDJ,UAAAA,EAAE,CAACG,WAAH,IAAkBH,EAAE,CAACG,WAAH,EAAlB,CANuB,CAQvB;;AACA,gBAAME,OAAO,GAAGb,KAAK,CAACC,IAAN,CAAW,KAAKF,aAAL,CAAmBe,OAAnB,EAAX,EAAyCC,IAAzC,CACd;AAAA,gBAAC,CAACC,CAAD,EAAIC,GAAJ,CAAD;AAAA,mBAAcA,GAAG,KAAKT,EAAtB;AAAA,WADc,CAAhB;;AAGA,cAAI,CAACK,OAAL,EAAc;AACZ,kBAAM,IAAID,KAAJ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hB,QAAAA,KAAK,EAAEe,SADkB;AAEzBR,QAAAA,OAAO,EAAGL,CAAD,IAAQ9B,IAAI,CAAC6C,aAAL,CAAmBH,GAAnB,IAA0BZ;AAFlB,OAA3B,EAFsB,CAMtB;;AACA9B,MAAAA,IAAI,CAAC6C,aAAL,CAAmBH,GAAnB,IAA2BC,SAAD,CAAwCG,OAAlE;AACD,KARD,MAQO,IAAI,4BAAWH,SAAX,CAAJ,EAA2B;AAChC;AACAF,MAAAA,qBAAqB,CAACG,IAAtB,CAA2B;AACzBhB,QAAAA,KAAK,EAAEe,SAAS,CAACf,KADQ;AAEzBO,QAAAA,OAAO,EAAGL,CAAD,IACN9B,IAAI,CAAC6C,aAAL,CAAmBH,GAAnB,IAA0BC,SAAS,CAACI,QAAV,CAAmBjB,CAAnB;AAHJ,OAA3B,EAFgC,CAOhC;;AACA9B,MAAAA,IAAI,CAAC6C,aAAL,CAAmBH,GAAnB,IAA0BC,SAAS,CAACI,QAAV,CACxBJ,SAAS,CAACf,KAAV,CAAgBkB,OADQ,CAA1B;AAGD,KAXM,MAWA;AACL;AACA9C,MAAAA,IAAI,CAAC6C,aAAL,CAAmBH,GAAnB,IAA0BC,SAA1B;AACD;AACF,GA1BD;AA4BA,SAAOF,qBAAP;AACD,CAtCD","sourcesContent":["import type { SkiaValue } from \"../values\";\n\nimport type { Node } from \"./nodes\";\nimport type { AnimatedProps } from \"./processors\";\nimport { isSelector, isValue } from \"./processors\";\nimport { mapKeys } from \"./typeddash\";\n\ntype Unsubscribe = () => void;\ntype Mutator = (value: unknown) => void;\n\ntype SubscriptionState = {\n nodes: Map<Node, Mutator[]>;\n unsubscribe: null | Unsubscribe;\n};\n\nexport class DependencyManager {\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void;\n subscriptions: Map<SkiaValue<unknown>, SubscriptionState> = new Map();\n unregisterDependantValues: null | Unsubscribe = null;\n\n constructor(\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void\n ) {\n this.registerValues = registerValues;\n }\n\n /**\n * Call to unsubscribe all value listeners from the given node based\n * on the current list of subscriptions for the node. This function\n * is typically called when the node is unmounted or when one or more\n * properties have changed.\n * @param node Node to unsubscribe value listeners from\n */\n unsubscribeNode(node: Node) {\n const subscriptions = Array.from(this.subscriptions.values()).filter((p) =>\n p.nodes.has(node)\n );\n\n if (subscriptions) {\n subscriptions.forEach((si) => {\n // Delete node from subscription\n si.nodes.delete(node);\n\n // Remove subscription if there are no listeneres left on the value\n if (si.nodes.size === 0) {\n // There are no more nodes subscribing to this value, we can call\n // unsubscribe on it.\n if (!si.unsubscribe) {\n throw new Error(\"Failed to unsubscribe to value subscription\");\n }\n si.unsubscribe && si.unsubscribe();\n\n // Remove from subscription states as well\n const element = Array.from(this.subscriptions.entries()).find(\n ([_, sub]) => sub === si\n );\n if (!element) {\n throw new Error(\"Failed to find value subscription\");\n }\n if (!this.subscriptions.delete(element[0])) {\n throw new Error(\"Failed to delete value subscription\");\n }\n }\n });\n }\n }\n\n /**\n * Adds listeners to the provided values so that the node is notified\n * when a value changes. This is done in an optimized way so that this\n * class only needs to listen to the value once and then forwards the\n * change to the node and its listener. This method is typically called\n * when the node is mounted and when one or more props on the node changes.\n * @param node Node to subscribe to value changes for\n * @param props Node's properties\n * @param onResolveProp Callback when a property value changes\n */\n subscribeNode<P extends Record<string, unknown>>(\n node: Node,\n props: AnimatedProps<P>\n ) {\n // Get mutators from node's properties\n const propSubscriptions = initializePropertySubscriptions(node, props);\n if (propSubscriptions.length === 0) {\n return;\n }\n\n // Install all mutators for the node\n propSubscriptions.forEach((ps) => {\n // Do we already have a state for this SkiaValue\n let subscriptionState = this.subscriptions.get(ps.value);\n if (!subscriptionState) {\n // Let's create a new subscription state for the skia value\n subscriptionState = {\n nodes: new Map(),\n unsubscribe: null,\n };\n // Add single subscription to the new value\n subscriptionState.unsubscribe = ps.value.addListener((v) => {\n subscriptionState!.nodes.forEach((mutators) =>\n mutators.forEach((m) => m(v))\n );\n });\n this.subscriptions.set(ps.value, subscriptionState);\n }\n // subscription mutators\n subscriptionState.nodes.set(\n node,\n propSubscriptions\n .filter((m) => m.value === ps.value)\n .map((m) => m.mutator)\n );\n });\n }\n\n /**\n * Called when the hosting container is mounted or updated. This ensures that we have\n * a ref to the underlying SkiaView so that we can registers redraw listeners\n * on values used in the current View automatically.\n */\n update() {\n // Remove any previous registrations\n if (this.unregisterDependantValues) {\n this.unregisterDependantValues();\n }\n\n // Register redraw requests on the SkiaView for each unique value\n this.unregisterDependantValues = this.registerValues(\n Array.from(this.subscriptions.keys())\n );\n }\n\n /**\n * Called when the hosting container is unmounted or recreated. This ensures that we remove\n * all subscriptions to Skia values so that we don't have any listeners left after\n * the component is removed.\n */\n remove() {\n // 1) Unregister redraw requests\n if (this.unregisterDependantValues) {\n this.unregisterDependantValues();\n this.unregisterDependantValues = null;\n }\n\n // 2) Unregister nodes\n Array.from(this.subscriptions.values()).forEach((si) => {\n Array.from(si.nodes.keys()).forEach((node) => this.unsubscribeNode(node));\n });\n\n // 3) Clear the rest of the subscriptions\n this.subscriptions.clear();\n }\n}\n\nconst initializePropertySubscriptions = <P,>(\n node: Node<P>,\n props: AnimatedProps<P>\n) => {\n const nodePropSubscriptions: Array<{\n value: SkiaValue<unknown>;\n mutator: Mutator;\n }> = [];\n\n mapKeys(props).forEach((key) => {\n const propvalue = props[key];\n\n if (isValue(propvalue)) {\n // Subscribe to changes\n nodePropSubscriptions.push({\n value: propvalue,\n mutator: (v) => (node.resolvedProps[key] = v as P[typeof key]),\n });\n // Set initial value\n node.resolvedProps[key] = (propvalue as SkiaValue<P[typeof key]>).current;\n } else if (isSelector(propvalue)) {\n // Subscribe to changes\n nodePropSubscriptions.push({\n value: propvalue.value,\n mutator: (v) =>\n (node.resolvedProps[key] = propvalue.selector(v) as P[typeof key]),\n });\n // Set initial value\n node.resolvedProps[key] = propvalue.selector(\n propvalue.value.current\n ) as P[typeof key];\n } else {\n // Set initial value\n node.resolvedProps[key] = propvalue as P[typeof key];\n }\n });\n\n return nodePropSubscriptions;\n};\n"]}
@@ -75,7 +75,7 @@ const removeNode = (parent, child) => {
75
75
  bustBranchMemoization(parent);
76
76
  const index = parent.children.indexOf(child);
77
77
  parent.children.splice(index, 1);
78
- child.depMgr.unSubscribeNode(child); // unsubscribe to all children as well
78
+ child.depMgr.unsubscribeNode(child); // unsubscribe to all children as well
79
79
 
80
80
  for (const c of child.children) {
81
81
  removeNode(child, c);
@@ -1 +1 @@
1
- {"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unSubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","p1","DrawingNode","Declaration","onDeclare","p2","DeclarationNode","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MA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0B,CAA1B;AACD,GAlJyC;AAoJ1CyE,EAAAA,kBAAkB,EAAE,MAAM;AACxB3F,IAAAA,KAAK,CAAC,oBAAD,CAAL;AACD,GAtJyC;AAwJ1C4F,EAAAA,WAAW,EAAE,CAAClF,MAAD,EAASJ,KAAT,KAAmB;AAC9BS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA1JyC;AA4J1CuF,EAAAA,wBAAwB,EAAE,CAACnF,MAAD,EAASJ,KAAT,KAAmB;AAC3CS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA9JyC;AAgK1CwF,EAAAA,uBAAuB,EAAE,CAACpF,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AAClDD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD,GAlKyC;AAoK1CD,EAAAA,YAAY,EAAE,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unSubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
1
+ {"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unsubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","p1","DrawingNode","Declaration","onDeclare","p2","DeclarationNode","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MAAI,CAACA,IAAI,CAACC,UAAV,EAAsB;AACpB,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACG,QAAzB,EAAmC;AACjC,QAAI,CAACD,KAAK,CAACE,QAAX,EAAqB;AACnB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAVD;;AAYA,MAAMC,qBAAqB,GAAIC,MAAD,IAAkB;AAC9C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;AACfA,MAAAA,QAAQ,CAACH,QAAT,GAAoB,IAApB;AACAG,MAAAA,QAAQ,GAAGA,QAAQ,CAACD,MAApB;AACD;AACF;AACF,CARD;;AAUA,MAAME,oBAAoB,GAAIF,MAAD,IAAkB;AAC7C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;A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B,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unsubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
@@ -17,6 +17,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
 
18
18
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
19
19
 
20
+ const childrenAreImageFilters = children => children.every(child => (0, _types.isImageFilter)(child));
21
+
22
+ const childrenAreShaders = children => children.every(child => (0, _types.isShader)(child));
23
+
20
24
  const onDeclare = (0, _nodes.createDeclaration)((_ref, children, _ref2) => {
21
25
  let {
22
26
  mode
@@ -24,14 +28,25 @@ const onDeclare = (0, _nodes.createDeclaration)((_ref, children, _ref2) => {
24
28
  let {
25
29
  Skia
26
30
  } = _ref2;
27
- const [inner, outer] = children;
28
31
 
29
32
  const blend = _types.BlendMode[(0, _Paint.enumKey)(mode)];
30
33
 
31
- if ((0, _types.isImageFilter)(outer) && (0, _types.isImageFilter)(inner)) {
32
- return Skia.ImageFilter.MakeBlend(blend, outer, inner);
33
- } else if ((0, _types.isShader)(outer) && (0, _types.isShader)(inner)) {
34
- return Skia.Shader.MakeBlend(blend, outer, inner);
34
+ if (childrenAreImageFilters(children)) {
35
+ return children.reverse().reduce((inner, outer) => {
36
+ if (inner === null) {
37
+ return outer;
38
+ }
39
+
40
+ return Skia.ImageFilter.MakeBlend(blend, outer, inner);
41
+ }, null);
42
+ } else if (childrenAreShaders(children)) {
43
+ return children.reverse().reduce((inner, outer) => {
44
+ if (inner === null) {
45
+ return outer;
46
+ }
47
+
48
+ return Skia.Shader.MakeBlend(blend, outer, inner);
49
+ }, null);
35
50
  }
36
51
 
37
52
  throw new Error("<Blend /> can only blend Shaders or ImageFilters");
@@ -1 +1 @@
1
- {"version":3,"sources":["Blend.tsx"],"names":["onDeclare","children","mode","Skia","inner","outer","blend","BlendMode","ImageFilter","MakeBlend","Shader","Error","Blend","props"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AAEA;;;;;;AAOA,MAAMA,SAAS,GAAG,8BAChB,OAAWC,QAAX,YAAkC;AAAA,MAAjC;AAAEC,IAAAA;AAAF,GAAiC;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AAChC,QAAM,CAACC,KAAD,EAAQC,KAAR,IAAiBJ,QAAvB;;AACA,QAAMK,KAAK,GAAGC,iBAAU,oBAAQL,IAAR,CAAV,CAAd;;AACA,MAAI,0BAAcG,KAAd,KAAwB,0BAAcD,KAAd,CAA5B,EAAkD;AAChD,WAAOD,IAAI,CAACK,WAAL,CAAiBC,SAAjB,CAA2BH,KAA3B,EAAkCD,KAAlC,EAAyCD,KAAzC,CAAP;AACD,GAFD,MAEO,IAAI,qBAASC,KAAT,KAAmB,qBAASD,KAAT,CAAvB,EAAwC;AAC7C,WAAOD,IAAI,CAACO,MAAL,CAAYD,SAAZ,CAAsBH,KAAtB,EAA6BD,KAA7B,EAAoCD,KAApC,CAAP;AACD;;AACD,QAAM,IAAIO,KAAJ,CAAU,kDAAV,CAAN;AACD,CAVe,CAAlB;;AAaO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAe,IAAA,SAAS,EAAEb;AAA1B,KAAyCa,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\n\nimport { isImageFilter, BlendMode, isShader } from \"../../skia/types\";\nimport { createDeclaration } from \"../nodes\";\nimport type { AnimatedProps, SkEnum } from \"../processors\";\nimport { enumKey } from \"../processors/Paint\";\n\ninterface BlendProps {\n mode: SkEnum<typeof BlendMode>;\n children?: ReactNode | ReactNode[];\n}\n\nconst onDeclare = createDeclaration<BlendProps>(\n ({ mode }, children, { Skia }) => {\n const [inner, outer] = children;\n const blend = BlendMode[enumKey(mode)];\n if (isImageFilter(outer) && isImageFilter(inner)) {\n return Skia.ImageFilter.MakeBlend(blend, outer, inner);\n } else if (isShader(outer) && isShader(inner)) {\n return Skia.Shader.MakeBlend(blend, outer, inner);\n }\n throw new Error(\"<Blend /> can only blend Shaders or ImageFilters\");\n }\n);\n\nexport const Blend = (props: AnimatedProps<BlendProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
1
+ {"version":3,"sources":["Blend.tsx"],"names":["childrenAreImageFilters","children","every","child","childrenAreShaders","onDeclare","mode","Skia","blend","BlendMode","reverse","reduce","inner","outer","ImageFilter","MakeBlend","Shader","Error","Blend","props"],"mappings":";;;;;;;AACA;;AAGA;;AACA;;AAEA;;;;;;AAGA,MAAMA,uBAAuB,GAC3BC,QAD8B,IAG9BA,QAAQ,CAACC,KAAT,CAAgBC,KAAD,IAAW,0BAAcA,KAAd,CAA1B,CAHF;;AAKA,MAAMC,kBAAkB,GACtBH,QADyB,IAEEA,QAAQ,CAACC,KAAT,CAAgBC,KAAD,IAAW,qBAASA,KAAT,CAA1B,CAF7B;;AASA,MAAME,SAAS,GAAG,8BAChB,OAAWJ,QAAX,YAAkC;AAAA,MAAjC;AAAEK,IAAAA;AAAF,GAAiC;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;;AAChC,QAAMC,KAAK,GAAGC,iBAAU,oBAAQH,IAAR,CAAV,CAAd;;AACA,MAAIN,uBAAuB,CAACC,QAAD,CAA3B,EAAuC;AACrC,WAAOA,QAAQ,CAACS,OAAT,GAAmBC,MAAnB,CAAgD,CAACC,KAAD,EAAQC,KAAR,KAAkB;AACvE,UAAID,KAAK,KAAK,IAAd,EAAoB;AAClB,eAAOC,KAAP;AACD;;AACD,aAAON,IAAI,CAACO,WAAL,CAAiBC,SAAjB,CAA2BP,KAA3B,EAAkCK,KAAlC,EAAyCD,KAAzC,CAAP;AACD,KALM,EAKJ,IALI,CAAP;AAMD,GAPD,MAOO,IAAIR,kBAAkB,CAACH,QAAD,CAAtB,EAAkC;AACvC,WAAOA,QAAQ,CAACS,OAAT,GAAmBC,MAAnB,CAA2C,CAACC,KAAD,EAAQC,KAAR,KAAkB;AAClE,UAAID,KAAK,KAAK,IAAd,EAAoB;AAClB,eAAOC,KAAP;AACD;;AACD,aAAON,IAAI,CAACS,MAAL,CAAYD,SAAZ,CAAsBP,KAAtB,EAA6BK,KAA7B,EAAoCD,KAApC,CAAP;AACD,KALM,EAKJ,IALI,CAAP;AAMD;;AACD,QAAM,IAAIK,KAAJ,CAAU,kDAAV,CAAN;AACD,CAnBe,CAAlB;;AAsBO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAe,IAAA,SAAS,EAAEd;AAA1B,KAAyCc,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\n\nimport type { SkImageFilter, SkShader } from \"../../skia/types\";\nimport { isImageFilter, BlendMode, isShader } from \"../../skia/types\";\nimport { createDeclaration } from \"../nodes\";\nimport type { AnimatedProps, SkEnum } from \"../processors\";\nimport { enumKey } from \"../processors/Paint\";\nimport type { DeclarationResult } from \"../nodes/Declaration\";\n\nconst childrenAreImageFilters = (\n children: DeclarationResult[]\n): children is SkImageFilter[] =>\n children.every((child) => isImageFilter(child));\n\nconst childrenAreShaders = (\n children: DeclarationResult[]\n): children is SkShader[] => children.every((child) => isShader(child));\n\ninterface BlendProps {\n mode: SkEnum<typeof BlendMode>;\n children?: ReactNode | ReactNode[];\n}\n\nconst onDeclare = createDeclaration<BlendProps>(\n ({ mode }, children, { Skia }) => {\n const blend = BlendMode[enumKey(mode)];\n if (childrenAreImageFilters(children)) {\n return children.reverse().reduce<SkImageFilter | null>((inner, outer) => {\n if (inner === null) {\n return outer;\n }\n return Skia.ImageFilter.MakeBlend(blend, outer, inner);\n }, null);\n } else if (childrenAreShaders(children)) {\n return children.reverse().reduce<SkShader | null>((inner, outer) => {\n if (inner === null) {\n return outer;\n }\n return Skia.Shader.MakeBlend(blend, outer, inner);\n }, null);\n }\n throw new Error(\"<Blend /> can only blend Shaders or ImageFilters\");\n }\n);\n\nexport const Blend = (props: AnimatedProps<BlendProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["BackdropFilter.tsx"],"names":["disableFilterMemoization","children","forEach","child","memoizable","onDraw","ctx","_","node","toFilter","visit","filter","Skia","Error","canvas","saveLayer","undefined","restore","BackdropFilter","filterChild","groupChildren","props"],"mappings":";;;;;;;AACA;;AAGA;;AAEA;;AAEA;;;;AAEA,MAAMA,wBAAwB,GAAIC,QAAD,IAA+B;AAC9DA,EAAAA,QAAQ,CAACC,OAAT,CAAkBC,KAAD,IAAW;AAC1BA,IAAAA,KAAK,CAACC,UAAN,GAAmB,KAAnB;AACAJ,IAAAA,wBAAwB,CAACG,KAAK,CAACF,QAAP,CAAxB;AACD,GAHD;AAID,CALD;;AAWA,MAAMI,MAAM,GAAG,0BAAmC,CAACC,GAAD,EAAMC,CAAN,EAASC,IAAT,KAAkB;AAClER,EAAAA,wBAAwB,CAACQ,IAAI,CAACP,QAAN,CAAxB;AACA,QAAMQ,QAAQ,GAAGD,IAAI,CAACE,KAAL,CAAWJ,GAAX,CAAjB;AACA,QAAMK,MAAM,GAAG,wBAASL,GAAG,CAACM,IAAb,EAAmBH,QAAnB,CAAf;;AACA,MAAI,CAACE,MAAL,EAAa;AACX,UAAM,IAAIE,KAAJ,CAAU,4CAAV,CAAN;AACD;;AACD,QAAM;AAAEC,IAAAA;AAAF,MAAaR,GAAnB;AACAQ,EAAAA,MAAM,CAACC,SAAP,CAAiBC,SAAjB,EAA4B,IAA5B,EAAkCL,MAAlC;AACAG,EAAAA,MAAM,CAACG,OAAP;AACD,CAVc,CAAf;;AAYO,MAAMC,cAAc,GAAG,QAIY;AAAA,MAJX;AAC7BP,IAAAA,MAAM,EAAEQ,WADqB;AAE7BlB,IAAAA,QAAQ,EAAEmB,aAFmB;AAG7B,OAAGC;AAH0B,GAIW;AACxC,sBACE,6BAAC,YAAD,EAAWA,KAAX,eACE;AAAW,IAAA,MAAM,EAAEhB,MAAnB;AAA2B,IAAA,cAAc;AAAzC,KACGc,WADH,CADF,EAIGC,aAJH,CADF;AAQD,CAbM","sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\n\nimport type { AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes\";\nimport type { Node } from \"../../nodes\";\nimport { getInput } from \"../imageFilters/getInput\";\nimport type { GroupProps } from \"../Group\";\nimport { Group } from \"../Group\";\n\nconst disableFilterMemoization = (children: Node<unknown>[]) => {\n children.forEach((child) => {\n child.memoizable = false;\n disableFilterMemoization(child.children);\n });\n};\n\nexport interface BackdropFilterProps extends GroupProps {\n filter: ReactNode | ReactNode[];\n}\n\nconst onDraw = createDrawing<BackdropFilterProps>((ctx, _, node) => {\n disableFilterMemoization(node.children);\n const toFilter = node.visit(ctx);\n const filter = getInput(ctx.Skia, toFilter);\n if (!filter) {\n throw new Error(\"No image filter provided to the background\");\n }\n const { canvas } = ctx;\n canvas.saveLayer(undefined, null, filter);\n canvas.restore();\n});\n\nexport const BackdropFilter = ({\n filter: filterChild,\n children: groupChildren,\n ...props\n}: AnimatedProps<BackdropFilterProps>) => {\n return (\n <Group {...props}>\n <skDrawing onDraw={onDraw} skipProcessing>\n {filterChild}\n </skDrawing>\n {groupChildren}\n </Group>\n );\n};\n"]}
1
+ {"version":3,"sources":["BackdropFilter.tsx"],"names":["disableFilterMemoization","children","forEach","child","memoizable","onDraw","ctx","_","node","toFilter","visit","filter","Skia","Error","canvas","saveLayer","undefined","restore","BackdropFilter","filterChild","groupChildren","props"],"mappings":";;;;;;;AACA;;AAGA;;AAEA;;AAEA;;;;AAEA,MAAMA,wBAAwB,GAAIC,QAAD,IAAsB;AACrDA,EAAAA,QAAQ,CAACC,OAAT,CAAkBC,KAAD,IAAW;AAC1BA,IAAAA,KAAK,CAACC,UAAN,GAAmB,KAAnB;AACAJ,IAAAA,wBAAwB,CAACG,KAAK,CAACF,QAAP,CAAxB;AACD,GAHD;AAID,CALD;;AAWA,MAAMI,MAAM,GAAG,0BAAmC,CAACC,GAAD,EAAMC,CAAN,EAASC,IAAT,KAAkB;AAClER,EAAAA,wBAAwB,CAACQ,IAAI,CAACP,QAAN,CAAxB;AACA,QAAMQ,QAAQ,GAAGD,IAAI,CAACE,KAAL,CAAWJ,GAAX,CAAjB;AACA,QAAMK,MAAM,GAAG,wBAASL,GAAG,CAACM,IAAb,EAAmBH,QAAnB,CAAf;;AACA,MAAI,CAACE,MAAL,EAAa;AACX,UAAM,IAAIE,KAAJ,CAAU,4CAAV,CAAN;AACD;;AACD,QAAM;AAAEC,IAAAA;AAAF,MAAaR,GAAnB;AACAQ,EAAAA,MAAM,CAACC,SAAP,CAAiBC,SAAjB,EAA4B,IAA5B,EAAkCL,MAAlC;AACAG,EAAAA,MAAM,CAACG,OAAP;AACD,CAVc,CAAf;;AAYO,MAAMC,cAAc,GAAG,QAIY;AAAA,MAJX;AAC7BP,IAAAA,MAAM,EAAEQ,WADqB;AAE7BlB,IAAAA,QAAQ,EAAEmB,aAFmB;AAG7B,OAAGC;AAH0B,GAIW;AACxC,sBACE,6BAAC,YAAD,EAAWA,KAAX,eACE;AAAW,IAAA,MAAM,EAAEhB,MAAnB;AAA2B,IAAA,cAAc;AAAzC,KACGc,WADH,CADF,EAIGC,aAJH,CADF;AAQD,CAbM","sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\n\nimport type { AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes\";\nimport type { Node } from \"../../nodes\";\nimport { getInput } from \"../imageFilters/getInput\";\nimport type { GroupProps } from \"../Group\";\nimport { Group } from \"../Group\";\n\nconst disableFilterMemoization = (children: Node[]) => {\n children.forEach((child) => {\n child.memoizable = false;\n disableFilterMemoization(child.children);\n });\n};\n\nexport interface BackdropFilterProps extends GroupProps {\n filter: ReactNode | ReactNode[];\n}\n\nconst onDraw = createDrawing<BackdropFilterProps>((ctx, _, node) => {\n disableFilterMemoization(node.children);\n const toFilter = node.visit(ctx);\n const filter = getInput(ctx.Skia, toFilter);\n if (!filter) {\n throw new Error(\"No image filter provided to the background\");\n }\n const { canvas } = ctx;\n canvas.saveLayer(undefined, null, filter);\n canvas.restore();\n});\n\nexport const BackdropFilter = ({\n filter: filterChild,\n children: groupChildren,\n ...props\n}: AnimatedProps<BackdropFilterProps>) => {\n return (\n <Group {...props}>\n <skDrawing onDraw={onDraw} skipProcessing>\n {filterChild}\n </skDrawing>\n {groupChildren}\n </Group>\n );\n};\n"]}
@@ -27,7 +27,7 @@ const onDeclare = (0, _Declaration.createDeclaration)((_ref, children, _ref2) =>
27
27
  } = _ref2;
28
28
  const input = (0, _getInput.getInput)(Skia, children);
29
29
  const r = (0, _Radius.processRadius)(Skia, radius);
30
- const factory = operator === "dilate" ? Skia.ImageFilter.MakeDilate : Skia.ImageFilter.MakeErode;
30
+ const factory = operator === "dilate" ? Skia.ImageFilter.MakeDilate.bind(Skia.ImageFilter) : Skia.ImageFilter.MakeErode.bind(Skia.ImageFilter);
31
31
  return factory(r.x, r.y, input);
32
32
  });
33
33
 
@@ -1 +1 @@
1
- {"version":3,"sources":["Morphology.tsx"],"names":["onDeclare","children","radius","operator","Skia","input","r","factory","ImageFilter","MakeDilate","MakeErode","x","y","Morphology","props","defaultProps"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA;;;;;;AAQA,MAAMA,SAAS,GAAG,oCAChB,OAAuBC,QAAvB,YAA8C;AAAA,MAA7C;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA6C;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AAC5C,QAAMC,KAAK,GAAG,wBAASD,IAAT,EAAeH,QAAf,CAAd;AACA,QAAMK,CAAC,GAAG,2BAAcF,IAAd,EAAoBF,MAApB,CAAV;AACA,QAAMK,OAAO,GACXJ,QAAQ,KAAK,QAAb,GACIC,IAAI,CAACI,WAAL,CAAiBC,UADrB,GAEIL,IAAI,CAACI,WAAL,CAAiBE,SAHvB;AAIA,SAAOH,OAAO,CAACD,CAAC,CAACK,CAAH,EAAML,CAAC,CAACM,CAAR,EAAWP,KAAX,CAAd;AACD,CATe,CAAlB;;AAYO,MAAMQ,UAAU,GAAIC,KAAD,IAA2C;AACnE,sBAAO;AAAe,IAAA,SAAS,EAAEd;AAA1B,KAAyCc,KAAzC,EAAP;AACD,CAFM;;;AAIPD,UAAU,CAACE,YAAX,GAA0B;AACxBZ,EAAAA,QAAQ,EAAE;AADc,CAA1B","sourcesContent":["import React from \"react\";\n\nimport { createDeclaration } from \"../../nodes/Declaration\";\nimport type { AnimatedProps, Radius } from \"../../processors\";\nimport { processRadius } from \"../../processors/Radius\";\n\nimport { getInput } from \"./getInput\";\n\nexport interface MorphologyProps {\n operator: \"erode\" | \"dilate\";\n radius: Radius;\n children?: React.ReactNode | React.ReactNode[];\n}\n\nconst onDeclare = createDeclaration<MorphologyProps>(\n ({ radius, operator }, children, { Skia }) => {\n const input = getInput(Skia, children);\n const r = processRadius(Skia, radius);\n const factory =\n operator === \"dilate\"\n ? Skia.ImageFilter.MakeDilate\n : Skia.ImageFilter.MakeErode;\n return factory(r.x, r.y, input);\n }\n);\n\nexport const Morphology = (props: AnimatedProps<MorphologyProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n\nMorphology.defaultProps = {\n operator: \"dilate\",\n};\n"]}
1
+ {"version":3,"sources":["Morphology.tsx"],"names":["onDeclare","children","radius","operator","Skia","input","r","factory","ImageFilter","MakeDilate","bind","MakeErode","x","y","Morphology","props","defaultProps"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA;;;;;;AAQA,MAAMA,SAAS,GAAG,oCAChB,OAAuBC,QAAvB,YAA8C;AAAA,MAA7C;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA6C;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AAC5C,QAAMC,KAAK,GAAG,wBAASD,IAAT,EAAeH,QAAf,CAAd;AACA,QAAMK,CAAC,GAAG,2BAAcF,IAAd,EAAoBF,MAApB,CAAV;AACA,QAAMK,OAAO,GACXJ,QAAQ,KAAK,QAAb,GACIC,IAAI,CAACI,WAAL,CAAiBC,UAAjB,CAA4BC,IAA5B,CAAiCN,IAAI,CAACI,WAAtC,CADJ,GAEIJ,IAAI,CAACI,WAAL,CAAiBG,SAAjB,CAA2BD,IAA3B,CAAgCN,IAAI,CAACI,WAArC,CAHN;AAIA,SAAOD,OAAO,CAACD,CAAC,CAACM,CAAH,EAAMN,CAAC,CAACO,CAAR,EAAWR,KAAX,CAAd;AACD,CATe,CAAlB;;AAYO,MAAMS,UAAU,GAAIC,KAAD,IAA2C;AACnE,sBAAO;AAAe,IAAA,SAAS,EAAEf;AAA1B,KAAyCe,KAAzC,EAAP;AACD,CAFM;;;AAIPD,UAAU,CAACE,YAAX,GAA0B;AACxBb,EAAAA,QAAQ,EAAE;AADc,CAA1B","sourcesContent":["import React from \"react\";\n\nimport { createDeclaration } from \"../../nodes/Declaration\";\nimport type { AnimatedProps, Radius } from \"../../processors\";\nimport { processRadius } from \"../../processors/Radius\";\n\nimport { getInput } from \"./getInput\";\n\nexport interface MorphologyProps {\n operator: \"erode\" | \"dilate\";\n radius: Radius;\n children?: React.ReactNode | React.ReactNode[];\n}\n\nconst onDeclare = createDeclaration<MorphologyProps>(\n ({ radius, operator }, children, { Skia }) => {\n const input = getInput(Skia, children);\n const r = processRadius(Skia, radius);\n const factory =\n operator === \"dilate\"\n ? Skia.ImageFilter.MakeDilate.bind(Skia.ImageFilter)\n : Skia.ImageFilter.MakeErode.bind(Skia.ImageFilter);\n return factory(r.x, r.y, input);\n }\n);\n\nexport const Morphology = (props: AnimatedProps<MorphologyProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n\nMorphology.defaultProps = {\n operator: \"dilate\",\n};\n"]}