@shopify/react-native-skia 0.1.172 → 0.1.174

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +5 -0
  3. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +106 -5
  4. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +3 -1
  5. package/cpp/api/JsiSkSurface.h +7 -1
  6. package/cpp/api/JsiSkSurfaceFactory.h +15 -2
  7. package/cpp/rnskia/RNSkDomView.cpp +2 -4
  8. package/cpp/rnskia/RNSkJsView.cpp +3 -0
  9. package/cpp/rnskia/RNSkPictureView.h +3 -0
  10. package/cpp/rnskia/RNSkPlatformContext.h +9 -0
  11. package/cpp/rnskia/dom/JsiDomApi.h +1 -0
  12. package/cpp/rnskia/dom/base/ConcatablePaint.cpp +117 -0
  13. package/cpp/rnskia/dom/base/ConcatablePaint.h +49 -0
  14. package/cpp/rnskia/dom/base/Declaration.h +88 -0
  15. package/cpp/rnskia/dom/base/DeclarationContext.h +79 -0
  16. package/cpp/rnskia/dom/base/DerivedNodeProp.h +25 -9
  17. package/cpp/rnskia/dom/base/DrawingContext.cpp +32 -186
  18. package/cpp/rnskia/dom/base/DrawingContext.h +45 -64
  19. package/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +35 -106
  20. package/cpp/rnskia/dom/base/JsiDomDrawingNode.h +28 -9
  21. package/cpp/rnskia/dom/base/JsiDomNode.h +46 -17
  22. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +81 -67
  23. package/cpp/rnskia/dom/base/NodeProp.h +12 -2
  24. package/cpp/rnskia/dom/base/NodePropsContainer.h +15 -16
  25. package/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +22 -11
  26. package/cpp/rnskia/dom/nodes/JsiBlendNode.h +43 -59
  27. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +16 -17
  28. package/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +6 -5
  29. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +45 -69
  30. package/cpp/rnskia/dom/nodes/JsiGroupNode.h +1 -1
  31. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +121 -161
  32. package/cpp/rnskia/dom/nodes/JsiImageNode.h +1 -0
  33. package/cpp/rnskia/dom/nodes/JsiLayerNode.h +28 -18
  34. package/cpp/rnskia/dom/nodes/JsiPaintNode.h +82 -45
  35. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +68 -101
  36. package/cpp/rnskia/dom/nodes/JsiPathNode.h +3 -2
  37. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +150 -207
  38. package/cpp/rnskia/dom/props/BezierProps.h +4 -2
  39. package/cpp/rnskia/dom/props/BlendModeProp.h +4 -2
  40. package/cpp/rnskia/dom/props/BoxShadowProps.h +8 -10
  41. package/cpp/rnskia/dom/props/CircleProp.h +6 -5
  42. package/cpp/rnskia/dom/props/ClipProp.h +6 -4
  43. package/cpp/rnskia/dom/props/ColorProp.h +8 -4
  44. package/cpp/rnskia/dom/props/DrawingProp.h +5 -3
  45. package/cpp/rnskia/dom/props/FontProp.h +4 -2
  46. package/cpp/rnskia/dom/props/GlyphsProp.h +4 -2
  47. package/cpp/rnskia/dom/props/ImageProps.h +9 -6
  48. package/cpp/rnskia/dom/props/LayerProp.h +6 -4
  49. package/cpp/rnskia/dom/props/MatrixProp.h +4 -2
  50. package/cpp/rnskia/dom/props/NumbersProp.h +8 -4
  51. package/cpp/rnskia/dom/props/PaintProps.h +55 -92
  52. package/cpp/rnskia/dom/props/PathProp.h +4 -2
  53. package/cpp/rnskia/dom/props/PictureProp.h +4 -2
  54. package/cpp/rnskia/dom/props/PointProp.h +4 -2
  55. package/cpp/rnskia/dom/props/PointsProp.h +8 -4
  56. package/cpp/rnskia/dom/props/RRectProp.h +23 -16
  57. package/cpp/rnskia/dom/props/RadiusProp.h +4 -2
  58. package/cpp/rnskia/dom/props/RectProp.h +18 -12
  59. package/cpp/rnskia/dom/props/StrokeProps.h +8 -4
  60. package/cpp/rnskia/dom/props/SvgProp.h +4 -2
  61. package/cpp/rnskia/dom/props/TextBlobProp.h +10 -8
  62. package/cpp/rnskia/dom/props/TileModeProp.h +4 -2
  63. package/cpp/rnskia/dom/props/TransformProp.h +4 -2
  64. package/cpp/rnskia/dom/props/TransformsProps.h +5 -7
  65. package/cpp/rnskia/dom/props/UniformsProp.h +4 -2
  66. package/cpp/rnskia/dom/props/VertexModeProp.h +4 -2
  67. package/cpp/rnskia/dom/props/VerticesProps.h +7 -11
  68. package/ios/RNSkia-iOS/DisplayLink.mm +22 -24
  69. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +53 -50
  70. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +2 -0
  71. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +56 -25
  72. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +17 -17
  73. package/ios/RNSkia-iOS/SkiaDrawViewManager.mm +17 -17
  74. package/ios/RNSkia-iOS/SkiaManager.mm +12 -10
  75. package/ios/RNSkia-iOS/SkiaMetalRenderer.h +5 -0
  76. package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +53 -0
  77. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +17 -17
  78. package/ios/RNSkia-iOS/SkiaUIView.mm +63 -53
  79. package/ios/RNSkiaModule.mm +5 -7
  80. package/lib/commonjs/dom/nodes/DrawingNode.js +5 -1
  81. package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
  82. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +33 -34
  83. package/lib/commonjs/dom/nodes/LayerNode.js +13 -6
  84. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -1
  85. package/lib/commonjs/dom/nodes/Node.d.ts +6 -11
  86. package/lib/commonjs/dom/nodes/Node.js +8 -26
  87. package/lib/commonjs/dom/nodes/Node.js.map +1 -1
  88. package/lib/commonjs/dom/nodes/PaintContext.js.map +1 -1
  89. package/lib/commonjs/dom/nodes/PaintNode.d.ts +3 -3
  90. package/lib/commonjs/dom/nodes/PaintNode.js +32 -15
  91. package/lib/commonjs/dom/nodes/PaintNode.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/RenderNode.d.ts +2 -3
  93. package/lib/commonjs/dom/nodes/RenderNode.js +19 -187
  94. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  95. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  96. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.js +25 -7
  97. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  98. package/lib/commonjs/dom/nodes/drawings/Box.d.ts +3 -1
  99. package/lib/commonjs/dom/nodes/drawings/Box.js +3 -0
  100. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  101. package/lib/commonjs/dom/nodes/paint/BlendNode.d.ts +3 -7
  102. package/lib/commonjs/dom/nodes/paint/BlendNode.js +16 -47
  103. package/lib/commonjs/dom/nodes/paint/BlendNode.js.map +1 -1
  104. package/lib/commonjs/dom/nodes/paint/ColorFilters.d.ts +10 -11
  105. package/lib/commonjs/dom/nodes/paint/ColorFilters.js +29 -43
  106. package/lib/commonjs/dom/nodes/paint/ColorFilters.js.map +1 -1
  107. package/lib/commonjs/dom/nodes/paint/ImageFilters.d.ts +11 -11
  108. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +45 -42
  109. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  110. package/lib/commonjs/dom/nodes/paint/MaskFilters.d.ts +3 -3
  111. package/lib/commonjs/dom/nodes/paint/MaskFilters.js +3 -2
  112. package/lib/commonjs/dom/nodes/paint/MaskFilters.js.map +1 -1
  113. package/lib/commonjs/dom/nodes/paint/PathEffects.d.ts +15 -18
  114. package/lib/commonjs/dom/nodes/paint/PathEffects.js +30 -72
  115. package/lib/commonjs/dom/nodes/paint/PathEffects.js.map +1 -1
  116. package/lib/commonjs/dom/nodes/paint/Shaders.d.ts +11 -12
  117. package/lib/commonjs/dom/nodes/paint/Shaders.js +28 -18
  118. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  119. package/lib/commonjs/dom/types/DeclarationContext.d.ts +29 -0
  120. package/lib/commonjs/dom/types/DeclarationContext.js +118 -0
  121. package/lib/commonjs/dom/types/DeclarationContext.js.map +1 -0
  122. package/lib/commonjs/dom/types/DrawingContext.d.ts +18 -1
  123. package/lib/commonjs/dom/types/DrawingContext.js +330 -0
  124. package/lib/commonjs/dom/types/DrawingContext.js.map +1 -1
  125. package/lib/commonjs/dom/types/Node.d.ts +4 -10
  126. package/lib/commonjs/dom/types/Node.js.map +1 -1
  127. package/lib/commonjs/dom/types/SkDOM.d.ts +22 -23
  128. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  129. package/lib/commonjs/dom/types/index.d.ts +1 -0
  130. package/lib/commonjs/dom/types/index.js +13 -0
  131. package/lib/commonjs/dom/types/index.js.map +1 -1
  132. package/lib/commonjs/index.d.ts +1 -0
  133. package/lib/commonjs/index.js +13 -0
  134. package/lib/commonjs/index.js.map +1 -1
  135. package/lib/commonjs/renderer/Canvas.js +3 -3
  136. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  137. package/lib/commonjs/renderer/DrawingContext.d.ts +4 -3
  138. package/lib/commonjs/renderer/DrawingContext.js.map +1 -1
  139. package/lib/commonjs/renderer/HostComponents.d.ts +35 -35
  140. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  141. package/lib/commonjs/renderer/HostConfig.js +1 -0
  142. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  143. package/lib/commonjs/renderer/Offscreen.d.ts +2 -0
  144. package/lib/commonjs/renderer/Offscreen.js +31 -0
  145. package/lib/commonjs/renderer/Offscreen.js.map +1 -0
  146. package/lib/commonjs/renderer/Reconciler.js +0 -1
  147. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  148. package/lib/commonjs/skia/types/Surface/Surface.d.ts +4 -0
  149. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  150. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  151. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  152. package/lib/commonjs/skia/web/JsiSkDataFactory.js +0 -1
  153. package/lib/commonjs/skia/web/JsiSkDataFactory.js.map +1 -1
  154. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
  155. package/lib/commonjs/skia/web/JsiSkImage.js +34 -3
  156. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  157. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -0
  158. package/lib/commonjs/skia/web/JsiSkSurface.js +4 -0
  159. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  160. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  161. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +21 -1
  162. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  163. package/lib/commonjs/views/SkiaBaseWebView.js +14 -8
  164. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  165. package/lib/commonjs/views/SkiaDomView.web.js +3 -14
  166. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  167. package/lib/commonjs/views/SkiaPictureView.web.js +0 -7
  168. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  169. package/lib/commonjs/views/SkiaView.web.js +0 -7
  170. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  171. package/lib/module/dom/nodes/DrawingNode.js +5 -1
  172. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  173. package/lib/module/dom/nodes/JsiSkDOM.d.ts +33 -34
  174. package/lib/module/dom/nodes/LayerNode.js +13 -7
  175. package/lib/module/dom/nodes/LayerNode.js.map +1 -1
  176. package/lib/module/dom/nodes/Node.d.ts +6 -11
  177. package/lib/module/dom/nodes/Node.js +8 -25
  178. package/lib/module/dom/nodes/Node.js.map +1 -1
  179. package/lib/module/dom/nodes/PaintContext.js.map +1 -1
  180. package/lib/module/dom/nodes/PaintNode.d.ts +3 -3
  181. package/lib/module/dom/nodes/PaintNode.js +32 -15
  182. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  183. package/lib/module/dom/nodes/RenderNode.d.ts +2 -3
  184. package/lib/module/dom/nodes/RenderNode.js +20 -187
  185. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  186. package/lib/module/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  187. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js +23 -4
  188. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  189. package/lib/module/dom/nodes/drawings/Box.d.ts +3 -1
  190. package/lib/module/dom/nodes/drawings/Box.js +3 -0
  191. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  192. package/lib/module/dom/nodes/paint/BlendNode.d.ts +3 -7
  193. package/lib/module/dom/nodes/paint/BlendNode.js +15 -46
  194. package/lib/module/dom/nodes/paint/BlendNode.js.map +1 -1
  195. package/lib/module/dom/nodes/paint/ColorFilters.d.ts +10 -11
  196. package/lib/module/dom/nodes/paint/ColorFilters.js +29 -43
  197. package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
  198. package/lib/module/dom/nodes/paint/ImageFilters.d.ts +11 -11
  199. package/lib/module/dom/nodes/paint/ImageFilters.js +48 -41
  200. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  201. package/lib/module/dom/nodes/paint/MaskFilters.d.ts +3 -3
  202. package/lib/module/dom/nodes/paint/MaskFilters.js +3 -2
  203. package/lib/module/dom/nodes/paint/MaskFilters.js.map +1 -1
  204. package/lib/module/dom/nodes/paint/PathEffects.d.ts +15 -18
  205. package/lib/module/dom/nodes/paint/PathEffects.js +29 -72
  206. package/lib/module/dom/nodes/paint/PathEffects.js.map +1 -1
  207. package/lib/module/dom/nodes/paint/Shaders.d.ts +11 -12
  208. package/lib/module/dom/nodes/paint/Shaders.js +28 -18
  209. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  210. package/lib/module/dom/types/DeclarationContext.d.ts +29 -0
  211. package/lib/module/dom/types/DeclarationContext.js +107 -0
  212. package/lib/module/dom/types/DeclarationContext.js.map +1 -0
  213. package/lib/module/dom/types/DrawingContext.d.ts +18 -1
  214. package/lib/module/dom/types/DrawingContext.js +322 -1
  215. package/lib/module/dom/types/DrawingContext.js.map +1 -1
  216. package/lib/module/dom/types/Node.d.ts +4 -10
  217. package/lib/module/dom/types/Node.js.map +1 -1
  218. package/lib/module/dom/types/SkDOM.d.ts +22 -23
  219. package/lib/module/dom/types/SkDOM.js.map +1 -1
  220. package/lib/module/dom/types/index.d.ts +1 -0
  221. package/lib/module/dom/types/index.js +1 -0
  222. package/lib/module/dom/types/index.js.map +1 -1
  223. package/lib/module/index.d.ts +1 -0
  224. package/lib/module/index.js +1 -0
  225. package/lib/module/index.js.map +1 -1
  226. package/lib/module/renderer/Canvas.js +3 -3
  227. package/lib/module/renderer/Canvas.js.map +1 -1
  228. package/lib/module/renderer/DrawingContext.d.ts +4 -3
  229. package/lib/module/renderer/DrawingContext.js.map +1 -1
  230. package/lib/module/renderer/HostComponents.d.ts +35 -35
  231. package/lib/module/renderer/HostComponents.js.map +1 -1
  232. package/lib/module/renderer/HostConfig.js +1 -0
  233. package/lib/module/renderer/HostConfig.js.map +1 -1
  234. package/lib/module/renderer/Offscreen.d.ts +2 -0
  235. package/lib/module/renderer/Offscreen.js +19 -0
  236. package/lib/module/renderer/Offscreen.js.map +1 -0
  237. package/lib/module/renderer/Reconciler.js +0 -1
  238. package/lib/module/renderer/Reconciler.js.map +1 -1
  239. package/lib/module/skia/types/Surface/Surface.d.ts +4 -0
  240. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  241. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  242. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  243. package/lib/module/skia/web/JsiSkDataFactory.js +0 -1
  244. package/lib/module/skia/web/JsiSkDataFactory.js.map +1 -1
  245. package/lib/module/skia/web/JsiSkImage.d.ts +1 -0
  246. package/lib/module/skia/web/JsiSkImage.js +31 -3
  247. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  248. package/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  249. package/lib/module/skia/web/JsiSkSurface.js +4 -0
  250. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  251. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  252. package/lib/module/skia/web/JsiSkSurfaceFactory.js +21 -1
  253. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  254. package/lib/module/views/SkiaBaseWebView.js +14 -8
  255. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  256. package/lib/module/views/SkiaDomView.web.js +2 -11
  257. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  258. package/lib/module/views/SkiaPictureView.web.js +0 -5
  259. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  260. package/lib/module/views/SkiaView.web.js +0 -5
  261. package/lib/module/views/SkiaView.web.js.map +1 -1
  262. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +33 -34
  263. package/lib/typescript/src/dom/nodes/Node.d.ts +6 -11
  264. package/lib/typescript/src/dom/nodes/PaintNode.d.ts +3 -3
  265. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +2 -3
  266. package/lib/typescript/src/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  267. package/lib/typescript/src/dom/nodes/drawings/Box.d.ts +3 -1
  268. package/lib/typescript/src/dom/nodes/paint/BlendNode.d.ts +3 -7
  269. package/lib/typescript/src/dom/nodes/paint/ColorFilters.d.ts +10 -11
  270. package/lib/typescript/src/dom/nodes/paint/ImageFilters.d.ts +11 -11
  271. package/lib/typescript/src/dom/nodes/paint/MaskFilters.d.ts +3 -3
  272. package/lib/typescript/src/dom/nodes/paint/PathEffects.d.ts +15 -18
  273. package/lib/typescript/src/dom/nodes/paint/Shaders.d.ts +11 -12
  274. package/lib/typescript/src/dom/types/DeclarationContext.d.ts +29 -0
  275. package/lib/typescript/src/dom/types/DrawingContext.d.ts +18 -1
  276. package/lib/typescript/src/dom/types/Node.d.ts +4 -10
  277. package/lib/typescript/src/dom/types/SkDOM.d.ts +22 -23
  278. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  279. package/lib/typescript/src/index.d.ts +1 -0
  280. package/lib/typescript/src/renderer/DrawingContext.d.ts +4 -3
  281. package/lib/typescript/src/renderer/HostComponents.d.ts +35 -35
  282. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -0
  283. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +4 -0
  284. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  285. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -0
  286. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -0
  287. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  288. package/package.json +1 -1
  289. package/src/dom/nodes/DrawingNode.ts +5 -1
  290. package/src/dom/nodes/LayerNode.ts +13 -11
  291. package/src/dom/nodes/Node.ts +18 -41
  292. package/src/dom/nodes/PaintContext.ts +1 -0
  293. package/src/dom/nodes/PaintNode.ts +28 -18
  294. package/src/dom/nodes/RenderNode.ts +25 -183
  295. package/src/dom/nodes/drawings/BackdropFilterNode.ts +18 -11
  296. package/src/dom/nodes/drawings/Box.ts +6 -4
  297. package/src/dom/nodes/paint/BlendNode.ts +16 -63
  298. package/src/dom/nodes/paint/ColorFilters.ts +32 -55
  299. package/src/dom/nodes/paint/ImageFilters.ts +58 -53
  300. package/src/dom/nodes/paint/MaskFilters.ts +5 -7
  301. package/src/dom/nodes/paint/PathEffects.ts +37 -90
  302. package/src/dom/nodes/paint/Shaders.ts +31 -29
  303. package/src/dom/types/DeclarationContext.ts +105 -0
  304. package/src/dom/types/DrawingContext.ts +304 -1
  305. package/src/dom/types/Node.ts +4 -20
  306. package/src/dom/types/SkDOM.ts +22 -43
  307. package/src/dom/types/index.ts +1 -0
  308. package/src/index.ts +1 -0
  309. package/src/renderer/Canvas.tsx +3 -3
  310. package/src/renderer/DrawingContext.ts +4 -5
  311. package/src/renderer/HostComponents.ts +34 -53
  312. package/src/renderer/HostConfig.ts +1 -0
  313. package/src/renderer/Offscreen.tsx +24 -0
  314. package/src/renderer/Reconciler.tsx +0 -1
  315. package/src/skia/types/Surface/Surface.ts +5 -0
  316. package/src/skia/types/Surface/SurfaceFactory.ts +7 -0
  317. package/src/skia/web/JsiSkDataFactory.ts +0 -1
  318. package/src/skia/web/JsiSkImage.ts +26 -2
  319. package/src/skia/web/JsiSkSurface.ts +4 -0
  320. package/src/skia/web/JsiSkSurfaceFactory.ts +21 -2
  321. package/src/views/SkiaBaseWebView.tsx +9 -2
  322. package/src/views/SkiaDomView.web.tsx +2 -13
  323. package/src/views/SkiaPictureView.web.tsx +0 -7
  324. package/src/views/SkiaView.web.tsx +0 -7
@@ -56,16 +56,7 @@ import type {
56
56
  BlendProps,
57
57
  MorphologyImageFilterProps,
58
58
  } from "../dom/types/ImageFilters";
59
- import type {
60
- SkColorFilter,
61
- SkImageFilter,
62
- SkMaskFilter,
63
- SkPaint,
64
- SkPathEffect,
65
- SkRect,
66
- SkRRect,
67
- SkShader,
68
- } from "../skia";
59
+ import type { SkRect, SkRRect } from "../skia/types";
69
60
  import type { JsiDrawingNode } from "../dom/nodes/DrawingNode";
70
61
  import type { SkiaValue } from "../values";
71
62
 
@@ -86,7 +77,7 @@ declare global {
86
77
  props: RoundedRectProps
87
78
  ) => JsiDrawingNode<RoundedRectProps, SkRRect>;
88
79
  GroupNode: (props: GroupProps) => RenderNode<GroupProps>;
89
- PaintNode: (props: PaintProps) => DeclarationNode<PaintProps, SkPaint>;
80
+ PaintNode: (props: PaintProps) => DeclarationNode<PaintProps>;
90
81
  FillNode: (props: PaintProps) => RenderNode<PaintProps>;
91
82
  CircleNode: (props: CircleProps) => RenderNode<CircleProps>;
92
83
  PathNode: (props: PathProps) => RenderNode<PathProps>;
@@ -102,98 +93,90 @@ declare global {
102
93
  // Mask filters
103
94
  BlurMaskFilterNode: (
104
95
  props: BlurMaskFilterProps
105
- ) => DeclarationNode<BlurMaskFilterProps, SkMaskFilter>;
96
+ ) => DeclarationNode<BlurMaskFilterProps>;
106
97
 
107
98
  // Path effects
108
99
  DashPathEffectNode: (
109
100
  props: DashPathEffectProps
110
- ) => DeclarationNode<DashPathEffectProps, SkPathEffect>;
101
+ ) => DeclarationNode<DashPathEffectProps>;
111
102
  DiscretePathEffectNode: (
112
103
  props: DiscretePathEffectProps
113
- ) => DeclarationNode<DiscretePathEffectProps, SkPathEffect>;
104
+ ) => DeclarationNode<DiscretePathEffectProps>;
114
105
  CornerPathEffectNode: (
115
106
  props: CornerPathEffectProps
116
- ) => DeclarationNode<CornerPathEffectProps, SkPathEffect>;
107
+ ) => DeclarationNode<CornerPathEffectProps>;
117
108
  Path1DPathEffectNode: (
118
109
  props: Path1DPathEffectProps
119
- ) => DeclarationNode<Path1DPathEffectProps, SkPathEffect>;
110
+ ) => DeclarationNode<Path1DPathEffectProps>;
120
111
  Path2DPathEffectNode: (
121
112
  props: Path2DPathEffectProps
122
- ) => DeclarationNode<Path2DPathEffectProps, SkPathEffect>;
113
+ ) => DeclarationNode<Path2DPathEffectProps>;
123
114
  Line2DPathEffectNode: (
124
115
  props: Line2DPathEffectProps
125
- ) => DeclarationNode<Line2DPathEffectProps, SkPathEffect>;
126
- SumPathEffectNode: () => DeclarationNode<null, SkPathEffect>;
116
+ ) => DeclarationNode<Line2DPathEffectProps>;
117
+ SumPathEffectNode: () => DeclarationNode<null>;
127
118
 
128
119
  // Image filters
129
120
  BlendImageFilterNode: (
130
121
  props: BlendImageFilterProps
131
- ) => DeclarationNode<BlendImageFilterProps, SkImageFilter>;
122
+ ) => DeclarationNode<BlendImageFilterProps>;
132
123
  DropShadowImageFilterNode: (
133
124
  props: DropShadowImageFilterProps
134
- ) => DeclarationNode<DropShadowImageFilterProps, SkImageFilter>;
125
+ ) => DeclarationNode<DropShadowImageFilterProps>;
135
126
  DisplacementMapImageFilterNode: (
136
127
  props: DisplacementMapImageFilterProps
137
- ) => DeclarationNode<DisplacementMapImageFilterProps, SkImageFilter>;
128
+ ) => DeclarationNode<DisplacementMapImageFilterProps>;
138
129
  BlurImageFilterNode: (
139
130
  props: BlurImageFilterProps
140
- ) => DeclarationNode<BlurImageFilterProps, SkImageFilter>;
131
+ ) => DeclarationNode<BlurImageFilterProps>;
141
132
  OffsetImageFilterNode: (
142
133
  props: OffsetImageFilterProps
143
- ) => DeclarationNode<OffsetImageFilterProps, SkImageFilter>;
134
+ ) => DeclarationNode<OffsetImageFilterProps>;
144
135
  MorphologyImageFilterNode: (
145
136
  props: MorphologyImageFilterProps
146
- ) => DeclarationNode<MorphologyImageFilterProps, SkImageFilter>;
137
+ ) => DeclarationNode<MorphologyImageFilterProps>;
147
138
  RuntimeShaderImageFilterNode: (
148
139
  props: RuntimeShaderImageFilterProps
149
- ) => DeclarationNode<RuntimeShaderImageFilterProps, SkImageFilter>;
140
+ ) => DeclarationNode<RuntimeShaderImageFilterProps>;
150
141
 
151
142
  // Color filters
152
143
  MatrixColorFilterNode: (
153
144
  props: MatrixColorFilterProps
154
- ) => DeclarationNode<MatrixColorFilterProps, SkColorFilter>;
145
+ ) => DeclarationNode<MatrixColorFilterProps>;
155
146
  BlendColorFilterNode: (
156
147
  props: BlendColorFilterProps
157
- ) => DeclarationNode<BlendColorFilterProps, SkColorFilter>;
158
- LinearToSRGBGammaColorFilterNode: () => DeclarationNode<
159
- null,
160
- SkColorFilter
161
- >;
162
- SRGBToLinearGammaColorFilterNode: () => DeclarationNode<
163
- null,
164
- SkColorFilter
165
- >;
166
- LumaColorFilterNode: () => DeclarationNode<null, SkColorFilter>;
148
+ ) => DeclarationNode<BlendColorFilterProps>;
149
+ LinearToSRGBGammaColorFilterNode: () => DeclarationNode<null>;
150
+ SRGBToLinearGammaColorFilterNode: () => DeclarationNode<null>;
151
+ LumaColorFilterNode: () => DeclarationNode<null>;
167
152
  LerpColorFilterNode: (
168
153
  props: LerpColorFilterProps
169
- ) => DeclarationNode<LerpColorFilterProps, SkColorFilter>;
154
+ ) => DeclarationNode<LerpColorFilterProps>;
170
155
 
171
156
  // Shaders
172
- ShaderNode: (props: ShaderProps) => DeclarationNode<ShaderProps, SkShader>;
157
+ ShaderNode: (props: ShaderProps) => DeclarationNode<ShaderProps>;
173
158
  ImageShaderNode: (
174
159
  props: ImageShaderProps
175
- ) => DeclarationNode<ImageShaderProps, SkShader>;
176
- ColorShaderNode: (
177
- props: ColorProps
178
- ) => DeclarationNode<ColorProps, SkShader>;
160
+ ) => DeclarationNode<ImageShaderProps>;
161
+ ColorShaderNode: (props: ColorProps) => DeclarationNode<ColorProps>;
179
162
  TurbulenceNode: (
180
163
  props: TurbulenceProps
181
- ) => DeclarationNode<TurbulenceProps, SkShader>;
164
+ ) => DeclarationNode<TurbulenceProps>;
182
165
  FractalNoiseNode: (
183
166
  props: FractalNoiseProps
184
- ) => DeclarationNode<FractalNoiseProps, SkShader>;
167
+ ) => DeclarationNode<FractalNoiseProps>;
185
168
  LinearGradientNode: (
186
169
  props: LinearGradientProps
187
- ) => DeclarationNode<LinearGradientProps, SkShader>;
170
+ ) => DeclarationNode<LinearGradientProps>;
188
171
  RadialGradientNode: (
189
172
  props: RadialGradientProps
190
- ) => DeclarationNode<RadialGradientProps, SkShader>;
173
+ ) => DeclarationNode<RadialGradientProps>;
191
174
  SweepGradientNode: (
192
175
  props: SweepGradientProps
193
- ) => DeclarationNode<SweepGradientProps, SkShader>;
176
+ ) => DeclarationNode<SweepGradientProps>;
194
177
  TwoPointConicalGradientNode: (
195
178
  props: TwoPointConicalGradientProps
196
- ) => DeclarationNode<TwoPointConicalGradientProps, SkShader>;
179
+ ) => DeclarationNode<TwoPointConicalGradientProps>;
197
180
  PictureNode: (props: PictureProps) => RenderNode<PictureProps>;
198
181
  ImageSVGNode: (props: ImageSVGProps) => RenderNode<ImageSVGProps>;
199
182
  VerticesNode: (props: VerticesProps) => RenderNode<VerticesProps>;
@@ -201,12 +184,10 @@ declare global {
201
184
  TextPathNode: (prop: TextPathProps) => RenderNode<TextPathProps>;
202
185
  TextBlobNode: (prop: TextBlobProps) => RenderNode<TextBlobProps>;
203
186
  GlyphsNode: (prop: GlyphsProps) => RenderNode<GlyphsProps>;
204
- BlendNode: (prop: BlendProps) => DeclarationNode<BlendProps, SkImageFilter>;
187
+ BlendNode: (prop: BlendProps) => DeclarationNode<BlendProps>;
205
188
  BackdropFilterNode: (prop: ChildrenProps) => RenderNode<ChildrenProps>;
206
189
  BoxNode: (prop: BoxProps) => RenderNode<BoxProps>;
207
- BoxShadowNode: (
208
- prop: BoxShadowProps
209
- ) => DeclarationNode<BoxShadowProps, BoxShadowProps>;
190
+ BoxShadowNode: (prop: BoxShadowProps) => DeclarationNode<BoxShadowProps>;
210
191
  LayerNode: (prop: ChildrenProps) => RenderNode<ChildrenProps>;
211
192
  };
212
193
 
@@ -155,6 +155,7 @@ export const skHostConfig: SkiaHostConfig = {
155
155
 
156
156
  resetAfterCommit(container) {
157
157
  debug("resetAfterCommit");
158
+ container.depMgr.update();
158
159
  container.redraw();
159
160
  },
160
161
 
@@ -0,0 +1,24 @@
1
+ import type { ReactElement } from "react";
2
+
3
+ import { JsiDrawingContext } from "../dom/types";
4
+ import { Skia } from "../skia";
5
+
6
+ import { SkiaRoot } from "./Reconciler";
7
+
8
+ export const drawAsImage = (
9
+ element: ReactElement,
10
+ width: number,
11
+ height: number
12
+ ) => {
13
+ const surface = Skia.Surface.MakeOffscreen(width, height);
14
+ if (!surface) {
15
+ throw new Error("Could not create offscreen surface");
16
+ }
17
+ const canvas = surface.getCanvas();
18
+ const root = new SkiaRoot(Skia);
19
+ root.render(element);
20
+ const ctx = new JsiDrawingContext(Skia, canvas);
21
+ root.dom.render(ctx);
22
+ surface.flush();
23
+ return surface.makeImageSnapshot();
24
+ };
@@ -50,7 +50,6 @@ export class SkiaRoot {
50
50
  render(element: ReactNode) {
51
51
  skiaReconciler.updateContainer(element, this.root, null, () => {
52
52
  hostDebug("updateContainer");
53
- this.container.depMgr.update();
54
53
  });
55
54
  }
56
55
 
@@ -24,4 +24,9 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
24
24
  example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
25
25
  */
26
26
  makeImageSnapshot(bounds?: SkRect): SkImage;
27
+
28
+ /**
29
+ * Make sure any queued draws are sent to the screen or the GPU.
30
+ */
31
+ flush(): void;
27
32
  }
@@ -9,4 +9,11 @@ export interface SurfaceFactory {
9
9
  * @param height - number of pixels of the height of the drawable area.
10
10
  */
11
11
  Make: (width: number, height: number) => SkSurface | null;
12
+
13
+ /**
14
+ * Creates a GPU backed surface.
15
+ * @param width - number of pixels of the width of the drawable area.
16
+ * @param height - number of pixels of the height of the drawable area.
17
+ */
18
+ MakeOffscreen: (width: number, height: number) => SkSurface | null;
12
19
  }
@@ -1,4 +1,3 @@
1
- /*global btoa, atob*/
2
1
  import type { CanvasKit } from "canvaskit-wasm";
3
2
 
4
3
  import type { SkData } from "../types";
@@ -1,4 +1,3 @@
1
- /*global btoa, atob*/
2
1
  import type { CanvasKit, Image } from "canvaskit-wasm";
3
2
 
4
3
  import type {
@@ -15,6 +14,31 @@ import { ckEnum, HostObject } from "./Host";
15
14
  import { JsiSkMatrix } from "./JsiSkMatrix";
16
15
  import { JsiSkShader } from "./JsiSkShader";
17
16
 
17
+ // https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js
18
+ export const toBase64String = (bytes: Uint8Array) => {
19
+ if (typeof Buffer !== "undefined") {
20
+ // Are we on node?
21
+ return Buffer.from(bytes).toString("base64");
22
+ } else {
23
+ // From https://stackoverflow.com/a/25644409
24
+ // because the naive solution of
25
+ // btoa(String.fromCharCode.apply(null, bytes));
26
+ // would occasionally throw "Maximum call stack size exceeded"
27
+ var CHUNK_SIZE = 0x8000; //arbitrary number
28
+ var index = 0;
29
+ var { length } = bytes;
30
+ var result = "";
31
+ var slice;
32
+ while (index < length) {
33
+ slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ result += String.fromCharCode.apply(null, slice as any);
36
+ index += CHUNK_SIZE;
37
+ }
38
+ return btoa(result);
39
+ }
40
+ };
41
+
18
42
  export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
19
43
  constructor(CanvasKit: CanvasKit, ref: Image) {
20
44
  super(CanvasKit, ref, "Image");
@@ -83,6 +107,6 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
83
107
 
84
108
  encodeToBase64(fmt?: ImageFormat, quality?: number) {
85
109
  const bytes = this.encodeToBytes(fmt, quality);
86
- return btoa(String.fromCharCode(...bytes));
110
+ return toBase64String(bytes);
87
111
  }
88
112
  }
@@ -15,6 +15,10 @@ export class JsiSkSurface
15
15
  super(CanvasKit, ref, "Surface");
16
16
  }
17
17
 
18
+ flush() {
19
+ this.ref.flush();
20
+ }
21
+
18
22
  getCanvas(): SkCanvas {
19
23
  return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
20
24
  }
@@ -1,4 +1,4 @@
1
- import type { CanvasKit } from "canvaskit-wasm";
1
+ import type { CanvasKit, Surface } from "canvaskit-wasm";
2
2
 
3
3
  import type { SurfaceFactory } from "../types";
4
4
 
@@ -13,7 +13,26 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
13
13
  Make(width: number, height: number) {
14
14
  const surface = this.CanvasKit.MakeSurface(width, height);
15
15
  if (!surface) {
16
- throw new Error("Could not create surface");
16
+ return null;
17
+ }
18
+ return new JsiSkSurface(this.CanvasKit, surface);
19
+ }
20
+
21
+ MakeOffscreen(width: number, height: number) {
22
+ // OffscreenCanvas may be unvailable in some environments.
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ const OC = (globalThis as any).OffscreenCanvas;
25
+ let surface: Surface | null;
26
+ if (OC === undefined) {
27
+ surface = this.CanvasKit.MakeSurface(width, height);
28
+ } else {
29
+ const offscreen = new OC(width, height);
30
+ surface = this.CanvasKit.MakeWebGLCanvasSurface(
31
+ offscreen as unknown as HTMLCanvasElement
32
+ );
33
+ }
34
+ if (!surface) {
35
+ return null;
17
36
  }
18
37
  return new JsiSkSurface(this.CanvasKit, surface);
19
38
  }
@@ -86,6 +86,9 @@ export abstract class SkiaBaseWebView<
86
86
  * @returns An Image object.
87
87
  */
88
88
  public makeImageSnapshot(rect?: SkRect) {
89
+ this._canvas!.clear(CanvasKit.TRANSPARENT);
90
+ this.renderInCanvas(this._canvas!, []);
91
+ this._surface?.ref.flush();
89
92
  return this._surface?.makeImageSnapshot(rect);
90
93
  }
91
94
 
@@ -106,8 +109,12 @@ export abstract class SkiaBaseWebView<
106
109
  if (this._canvas) {
107
110
  const touches = [...this._touches];
108
111
  this._touches = [];
109
- this._canvas!.clear(CanvasKit.TRANSPARENT);
110
- this.renderInCanvas(this._canvas!, touches);
112
+ const canvas = this._canvas!;
113
+ canvas.clear(Float32Array.of(0, 0, 0, 0));
114
+ canvas.save();
115
+ canvas.scale(pd, pd);
116
+ this.renderInCanvas(canvas, touches);
117
+ canvas.restore();
111
118
  this._surface?.ref.flush();
112
119
  }
113
120
  }
@@ -1,13 +1,10 @@
1
- import { PixelRatio } from "react-native";
2
-
3
1
  import { Skia } from "../skia";
4
2
  import type { SkCanvas } from "../skia/types";
3
+ import { JsiDrawingContext } from "../dom/types/DrawingContext";
5
4
 
6
5
  import { SkiaBaseWebView } from "./SkiaBaseWebView";
7
6
  import type { SkiaDomViewProps, TouchInfo } from "./types";
8
7
 
9
- const pd = PixelRatio.get();
10
-
11
8
  export class SkiaDomView extends SkiaBaseWebView<SkiaDomViewProps> {
12
9
  constructor(props: SkiaDomViewProps) {
13
10
  super(props);
@@ -22,16 +19,8 @@ export class SkiaDomView extends SkiaBaseWebView<SkiaDomViewProps> {
22
19
  this.props.onSize.current = { width, height };
23
20
  }
24
21
  if (this.props.root) {
25
- const paint = Skia.Paint();
26
- const ctx = {
27
- canvas,
28
- paint,
29
- opacity: 1,
30
- };
31
- canvas.save();
32
- canvas.scale(pd, pd);
22
+ const ctx = new JsiDrawingContext(Skia, canvas);
33
23
  this.props.root.render(ctx);
34
- canvas.restore();
35
24
  }
36
25
  }
37
26
  }
@@ -1,12 +1,8 @@
1
- import { PixelRatio } from "react-native";
2
-
3
1
  import type { SkCanvas } from "../skia/types";
4
2
 
5
3
  import type { SkiaPictureViewProps } from "./types";
6
4
  import { SkiaBaseWebView } from "./SkiaBaseWebView";
7
5
 
8
- const pd = PixelRatio.get();
9
-
10
6
  export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewProps> {
11
7
  constructor(props: SkiaPictureViewProps) {
12
8
  super(props);
@@ -14,10 +10,7 @@ export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewProps> {
14
10
 
15
11
  protected renderInCanvas(canvas: SkCanvas): void {
16
12
  if (this.props.picture) {
17
- canvas.save();
18
- canvas.scale(pd, pd);
19
13
  canvas.drawPicture(this.props.picture);
20
- canvas.restore();
21
14
  }
22
15
  }
23
16
  }
@@ -1,12 +1,8 @@
1
- import { PixelRatio } from "react-native";
2
-
3
1
  import type { SkCanvas } from "../skia/types";
4
2
 
5
3
  import type { DrawingInfo, SkiaDrawViewProps, TouchInfo } from "./types";
6
4
  import { SkiaBaseWebView } from "./SkiaBaseWebView";
7
5
 
8
- const pd = PixelRatio.get();
9
-
10
6
  export class SkiaView extends SkiaBaseWebView<SkiaDrawViewProps> {
11
7
  constructor(props: SkiaDrawViewProps) {
12
8
  super(props);
@@ -20,10 +16,7 @@ export class SkiaView extends SkiaBaseWebView<SkiaDrawViewProps> {
20
16
  timestamp: Date.now(),
21
17
  touches: touches.map((t) => [t]),
22
18
  };
23
- canvas.save();
24
- canvas.scale(pd, pd);
25
19
  this.props.onDraw(canvas, info);
26
- canvas.restore();
27
20
  }
28
21
  }
29
22
  }