@shopify/react-native-skia 0.1.172 → 0.1.173

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) 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 +38 -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/JsiSkSurface.d.ts +1 -0
  153. package/lib/commonjs/skia/web/JsiSkSurface.js +4 -0
  154. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  155. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  156. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +21 -1
  157. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  158. package/lib/commonjs/views/SkiaBaseWebView.js +6 -4
  159. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  160. package/lib/commonjs/views/SkiaDomView.web.js +3 -14
  161. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  162. package/lib/commonjs/views/SkiaPictureView.web.js +0 -7
  163. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  164. package/lib/commonjs/views/SkiaView.web.js +0 -7
  165. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  166. package/lib/module/dom/nodes/DrawingNode.js +5 -1
  167. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  168. package/lib/module/dom/nodes/JsiSkDOM.d.ts +33 -34
  169. package/lib/module/dom/nodes/LayerNode.js +13 -7
  170. package/lib/module/dom/nodes/LayerNode.js.map +1 -1
  171. package/lib/module/dom/nodes/Node.d.ts +6 -11
  172. package/lib/module/dom/nodes/Node.js +8 -25
  173. package/lib/module/dom/nodes/Node.js.map +1 -1
  174. package/lib/module/dom/nodes/PaintContext.js.map +1 -1
  175. package/lib/module/dom/nodes/PaintNode.d.ts +3 -3
  176. package/lib/module/dom/nodes/PaintNode.js +32 -15
  177. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  178. package/lib/module/dom/nodes/RenderNode.d.ts +2 -3
  179. package/lib/module/dom/nodes/RenderNode.js +20 -187
  180. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  181. package/lib/module/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  182. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js +23 -4
  183. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  184. package/lib/module/dom/nodes/drawings/Box.d.ts +3 -1
  185. package/lib/module/dom/nodes/drawings/Box.js +3 -0
  186. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  187. package/lib/module/dom/nodes/paint/BlendNode.d.ts +3 -7
  188. package/lib/module/dom/nodes/paint/BlendNode.js +15 -46
  189. package/lib/module/dom/nodes/paint/BlendNode.js.map +1 -1
  190. package/lib/module/dom/nodes/paint/ColorFilters.d.ts +10 -11
  191. package/lib/module/dom/nodes/paint/ColorFilters.js +29 -43
  192. package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
  193. package/lib/module/dom/nodes/paint/ImageFilters.d.ts +11 -11
  194. package/lib/module/dom/nodes/paint/ImageFilters.js +48 -41
  195. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  196. package/lib/module/dom/nodes/paint/MaskFilters.d.ts +3 -3
  197. package/lib/module/dom/nodes/paint/MaskFilters.js +3 -2
  198. package/lib/module/dom/nodes/paint/MaskFilters.js.map +1 -1
  199. package/lib/module/dom/nodes/paint/PathEffects.d.ts +15 -18
  200. package/lib/module/dom/nodes/paint/PathEffects.js +29 -72
  201. package/lib/module/dom/nodes/paint/PathEffects.js.map +1 -1
  202. package/lib/module/dom/nodes/paint/Shaders.d.ts +11 -12
  203. package/lib/module/dom/nodes/paint/Shaders.js +28 -18
  204. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  205. package/lib/module/dom/types/DeclarationContext.d.ts +29 -0
  206. package/lib/module/dom/types/DeclarationContext.js +107 -0
  207. package/lib/module/dom/types/DeclarationContext.js.map +1 -0
  208. package/lib/module/dom/types/DrawingContext.d.ts +18 -1
  209. package/lib/module/dom/types/DrawingContext.js +322 -1
  210. package/lib/module/dom/types/DrawingContext.js.map +1 -1
  211. package/lib/module/dom/types/Node.d.ts +4 -10
  212. package/lib/module/dom/types/Node.js.map +1 -1
  213. package/lib/module/dom/types/SkDOM.d.ts +22 -23
  214. package/lib/module/dom/types/SkDOM.js.map +1 -1
  215. package/lib/module/dom/types/index.d.ts +1 -0
  216. package/lib/module/dom/types/index.js +1 -0
  217. package/lib/module/dom/types/index.js.map +1 -1
  218. package/lib/module/index.d.ts +1 -0
  219. package/lib/module/index.js +1 -0
  220. package/lib/module/index.js.map +1 -1
  221. package/lib/module/renderer/Canvas.js +3 -3
  222. package/lib/module/renderer/Canvas.js.map +1 -1
  223. package/lib/module/renderer/DrawingContext.d.ts +4 -3
  224. package/lib/module/renderer/DrawingContext.js.map +1 -1
  225. package/lib/module/renderer/HostComponents.d.ts +35 -35
  226. package/lib/module/renderer/HostComponents.js.map +1 -1
  227. package/lib/module/renderer/HostConfig.js +1 -0
  228. package/lib/module/renderer/HostConfig.js.map +1 -1
  229. package/lib/module/renderer/Offscreen.d.ts +2 -0
  230. package/lib/module/renderer/Offscreen.js +19 -0
  231. package/lib/module/renderer/Offscreen.js.map +1 -0
  232. package/lib/module/renderer/Reconciler.js +0 -1
  233. package/lib/module/renderer/Reconciler.js.map +1 -1
  234. package/lib/module/skia/types/Surface/Surface.d.ts +4 -0
  235. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  236. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  237. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  238. package/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  239. package/lib/module/skia/web/JsiSkSurface.js +4 -0
  240. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  241. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  242. package/lib/module/skia/web/JsiSkSurfaceFactory.js +21 -1
  243. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  244. package/lib/module/views/SkiaBaseWebView.js +6 -4
  245. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  246. package/lib/module/views/SkiaDomView.web.js +2 -11
  247. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  248. package/lib/module/views/SkiaPictureView.web.js +0 -5
  249. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  250. package/lib/module/views/SkiaView.web.js +0 -5
  251. package/lib/module/views/SkiaView.web.js.map +1 -1
  252. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +33 -34
  253. package/lib/typescript/src/dom/nodes/Node.d.ts +6 -11
  254. package/lib/typescript/src/dom/nodes/PaintNode.d.ts +3 -3
  255. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +2 -3
  256. package/lib/typescript/src/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  257. package/lib/typescript/src/dom/nodes/drawings/Box.d.ts +3 -1
  258. package/lib/typescript/src/dom/nodes/paint/BlendNode.d.ts +3 -7
  259. package/lib/typescript/src/dom/nodes/paint/ColorFilters.d.ts +10 -11
  260. package/lib/typescript/src/dom/nodes/paint/ImageFilters.d.ts +11 -11
  261. package/lib/typescript/src/dom/nodes/paint/MaskFilters.d.ts +3 -3
  262. package/lib/typescript/src/dom/nodes/paint/PathEffects.d.ts +15 -18
  263. package/lib/typescript/src/dom/nodes/paint/Shaders.d.ts +11 -12
  264. package/lib/typescript/src/dom/types/DeclarationContext.d.ts +29 -0
  265. package/lib/typescript/src/dom/types/DrawingContext.d.ts +18 -1
  266. package/lib/typescript/src/dom/types/Node.d.ts +4 -10
  267. package/lib/typescript/src/dom/types/SkDOM.d.ts +22 -23
  268. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  269. package/lib/typescript/src/index.d.ts +1 -0
  270. package/lib/typescript/src/renderer/DrawingContext.d.ts +4 -3
  271. package/lib/typescript/src/renderer/HostComponents.d.ts +35 -35
  272. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -0
  273. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +4 -0
  274. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  275. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -0
  276. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  277. package/package.json +1 -1
  278. package/src/dom/nodes/DrawingNode.ts +5 -1
  279. package/src/dom/nodes/LayerNode.ts +13 -11
  280. package/src/dom/nodes/Node.ts +18 -41
  281. package/src/dom/nodes/PaintContext.ts +1 -0
  282. package/src/dom/nodes/PaintNode.ts +28 -18
  283. package/src/dom/nodes/RenderNode.ts +25 -183
  284. package/src/dom/nodes/drawings/BackdropFilterNode.ts +18 -11
  285. package/src/dom/nodes/drawings/Box.ts +6 -4
  286. package/src/dom/nodes/paint/BlendNode.ts +16 -63
  287. package/src/dom/nodes/paint/ColorFilters.ts +32 -55
  288. package/src/dom/nodes/paint/ImageFilters.ts +58 -53
  289. package/src/dom/nodes/paint/MaskFilters.ts +5 -7
  290. package/src/dom/nodes/paint/PathEffects.ts +37 -90
  291. package/src/dom/nodes/paint/Shaders.ts +31 -29
  292. package/src/dom/types/DeclarationContext.ts +105 -0
  293. package/src/dom/types/DrawingContext.ts +304 -1
  294. package/src/dom/types/Node.ts +4 -20
  295. package/src/dom/types/SkDOM.ts +22 -43
  296. package/src/dom/types/index.ts +1 -0
  297. package/src/index.ts +1 -0
  298. package/src/renderer/Canvas.tsx +3 -3
  299. package/src/renderer/DrawingContext.ts +4 -5
  300. package/src/renderer/HostComponents.ts +34 -53
  301. package/src/renderer/HostConfig.ts +1 -0
  302. package/src/renderer/Offscreen.tsx +24 -0
  303. package/src/renderer/Reconciler.tsx +0 -1
  304. package/src/skia/types/Surface/Surface.ts +5 -0
  305. package/src/skia/types/Surface/SurfaceFactory.ts +7 -0
  306. package/src/skia/web/JsiSkSurface.ts +4 -0
  307. package/src/skia/web/JsiSkSurfaceFactory.ts +21 -2
  308. package/src/views/SkiaBaseWebView.tsx +6 -2
  309. package/src/views/SkiaDomView.web.tsx +2 -13
  310. package/src/views/SkiaPictureView.web.tsx +0 -7
  311. package/src/views/SkiaView.web.tsx +0 -7
@@ -0,0 +1,105 @@
1
+ import type {
2
+ SkShader,
3
+ SkPaint,
4
+ SkImageFilter,
5
+ SkMaskFilter,
6
+ SkPathEffect,
7
+ Skia,
8
+ SkColorFilter,
9
+ } from "../../skia/types";
10
+
11
+ type Composer<T> = (outer: T, inner: T) => T;
12
+
13
+ export const composeDeclarations = <T>(filters: T[], composer: Composer<T>) => {
14
+ if (filters.length <= 1) {
15
+ return filters[0];
16
+ }
17
+ return filters.reverse().reduce((inner, outer) => {
18
+ if (!inner) {
19
+ return outer;
20
+ }
21
+ return composer(outer, inner);
22
+ });
23
+ };
24
+
25
+ class Declaration<T> {
26
+ private decls: T[] = [];
27
+ private indexes = [0];
28
+
29
+ constructor(private composer?: Composer<T>) {}
30
+
31
+ private get index() {
32
+ return this.indexes[this.indexes.length - 1];
33
+ }
34
+
35
+ save() {
36
+ this.indexes.push(this.decls.length);
37
+ }
38
+
39
+ restore() {
40
+ this.indexes.pop();
41
+ }
42
+
43
+ pop() {
44
+ return this.decls.pop();
45
+ }
46
+
47
+ push(decl: T) {
48
+ this.decls.push(decl);
49
+ }
50
+
51
+ popAll() {
52
+ return this.decls.splice(this.index, this.decls.length - this.index);
53
+ }
54
+
55
+ popAllAsOne() {
56
+ if (!this.composer) {
57
+ throw new Error("No composer for this type of declaration");
58
+ }
59
+ const decls = this.popAll();
60
+ return composeDeclarations(decls, this.composer!);
61
+ }
62
+ }
63
+
64
+ export class DeclarationContext {
65
+ readonly paints: Declaration<SkPaint>;
66
+ readonly maskFilters: Declaration<SkMaskFilter>;
67
+ readonly shaders: Declaration<SkShader>;
68
+ readonly pathEffects: Declaration<SkPathEffect>;
69
+ readonly imageFilters: Declaration<SkImageFilter>;
70
+ readonly colorFilters: Declaration<SkColorFilter>;
71
+
72
+ constructor(private Skia: Skia) {
73
+ const peComp = this.Skia.PathEffect.MakeCompose.bind(this.Skia.PathEffect);
74
+ const ifComp = this.Skia.ImageFilter.MakeCompose.bind(
75
+ this.Skia.ImageFilter
76
+ );
77
+ const cfComp = this.Skia.ColorFilter.MakeCompose.bind(
78
+ this.Skia.ColorFilter
79
+ );
80
+ this.paints = new Declaration<SkPaint>();
81
+ this.maskFilters = new Declaration<SkMaskFilter>();
82
+ this.shaders = new Declaration<SkShader>();
83
+ this.pathEffects = new Declaration<SkPathEffect>(peComp);
84
+ this.imageFilters = new Declaration<SkImageFilter>(ifComp);
85
+ this.colorFilters = new Declaration<SkColorFilter>(cfComp);
86
+ }
87
+
88
+ save() {
89
+ this.paints.save();
90
+ this.maskFilters.save();
91
+ this.shaders.save();
92
+ this.pathEffects.save();
93
+ this.imageFilters.save();
94
+ this.colorFilters.save();
95
+ }
96
+
97
+ restore() {
98
+ this.paints.restore();
99
+ this.maskFilters.restore();
100
+ this.shaders.restore();
101
+ this.pathEffects.restore();
102
+ this.imageFilters.restore();
103
+ this.colorFilters.restore();
104
+ }
105
+ }
@@ -1,6 +1,309 @@
1
- import type { SkCanvas, SkPaint } from "../../skia/types";
1
+ import type {
2
+ SkCanvas,
3
+ SkColor,
4
+ SkColorFilter,
5
+ SkImageFilter,
6
+ SkMaskFilter,
7
+ SkPaint,
8
+ SkPathEffect,
9
+ SkShader,
10
+ Skia,
11
+ } from "../../skia/types";
12
+ import { BlendMode, PaintStyle, StrokeCap, StrokeJoin } from "../../skia/types";
13
+ import { enumKey } from "../nodes/datatypes/Enum";
14
+ import { JsiDeclarationNode } from "../nodes/Node";
15
+
16
+ import type { PaintProps, SkEnum } from "./Common";
17
+ import { DeclarationContext } from "./DeclarationContext";
18
+ import type { Node } from "./Node";
2
19
 
3
20
  export interface DrawingContext {
4
21
  canvas: SkCanvas;
5
22
  paint: SkPaint;
23
+ saveAndConcat(node: Node<PaintProps>, cache?: SkPaint): boolean;
24
+ restore(): void;
25
+ declarationCtx: DeclarationContext;
26
+ }
27
+
28
+ export class JsiDrawingContext implements DrawingContext {
29
+ paints: SkPaint[];
30
+
31
+ declarationCtx: DeclarationContext;
32
+
33
+ constructor(private readonly Skia: Skia, public readonly canvas: SkCanvas) {
34
+ const paint = this.Skia.Paint();
35
+ this.paints = [paint];
36
+ this.declarationCtx = new DeclarationContext(Skia);
37
+ }
38
+
39
+ get paint() {
40
+ return this.paints[this.paints.length - 1];
41
+ }
42
+
43
+ private save() {
44
+ const childPaint = this.paint.copy();
45
+ this.paints.push(childPaint);
46
+ }
47
+
48
+ restore(): void {
49
+ this.paints.pop();
50
+ }
51
+
52
+ saveAndConcat(node: Node<PaintProps>, cache?: SkPaint) {
53
+ if (cache) {
54
+ this.paints.push(cache);
55
+ return true;
56
+ }
57
+ const paint = new ConcatablePaint(this.Skia, this.declarationCtx, node);
58
+ if (!paint.isPristine()) {
59
+ this.save();
60
+ paint.concatTo(this.paint);
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ }
66
+
67
+ class ConcatablePaint {
68
+ private pristine = true;
69
+
70
+ _color?: SkColor;
71
+ _strokeWidth?: number;
72
+ _blendMode?: BlendMode;
73
+ _style?: PaintStyle;
74
+ _strokeJoin?: StrokeJoin;
75
+ _strokeCap?: StrokeCap;
76
+ _strokeMiter?: number;
77
+ _opacity = 1;
78
+ _antiAlias?: boolean;
79
+
80
+ _imageFilter?: SkImageFilter;
81
+ _shader?: SkShader;
82
+ _pathEffect?: SkPathEffect;
83
+ _colorFilter?: SkColorFilter;
84
+ _maskFilter?: SkMaskFilter;
85
+
86
+ constructor(Skia: Skia, declCtx: DeclarationContext, node: Node<PaintProps>) {
87
+ const props = node.getProps();
88
+ const children = node.children();
89
+ this.setColor(
90
+ props.color !== undefined ? Skia.Color(props.color) : props.color
91
+ );
92
+ this.setStrokeWidth(props.strokeWidth);
93
+ this.setBlendMode(props.blendMode);
94
+ this.setStyle(props.style);
95
+ this.setStrokeJoin(props.strokeJoin);
96
+ this.setStrokeCap(props.strokeCap);
97
+ this.setStrokeMiter(props.strokeMiter);
98
+ this.setOpacity(props.opacity);
99
+ this.setAntiAlias(props.antiAlias);
100
+ declCtx.save();
101
+ children.forEach((child) => {
102
+ if (child instanceof JsiDeclarationNode) {
103
+ child.decorate(declCtx);
104
+ }
105
+ });
106
+ const colorFilter = declCtx.colorFilters.popAllAsOne();
107
+ const imageFilter = declCtx.imageFilters.popAllAsOne();
108
+ const shader = declCtx.shaders.pop();
109
+ const maskFilter = declCtx.maskFilters.pop();
110
+ const pathEffect = declCtx.pathEffects.popAllAsOne();
111
+ declCtx.restore();
112
+ if (imageFilter) {
113
+ this.setImageFilter(imageFilter);
114
+ }
115
+ if (shader) {
116
+ this.setShader(shader);
117
+ }
118
+ if (pathEffect) {
119
+ this.setPathEffect(pathEffect);
120
+ }
121
+ if (colorFilter) {
122
+ this.setColorFilter(colorFilter);
123
+ }
124
+ if (maskFilter) {
125
+ this.setMaskFilter(maskFilter);
126
+ }
127
+ }
128
+
129
+ private enum<T>(value: T, key?: Uncapitalize<string>) {
130
+ if (key !== undefined) {
131
+ return value[enumKey(key) as keyof T];
132
+ }
133
+ return undefined;
134
+ }
135
+
136
+ private setValue<T extends keyof typeof this>(
137
+ key: T,
138
+ value?: typeof this[T]
139
+ ) {
140
+ if (value !== undefined) {
141
+ this[key] = value;
142
+ this.pristine = false;
143
+ }
144
+ }
145
+
146
+ setColor(color?: SkColor) {
147
+ this.setValue("_color", color);
148
+ }
149
+
150
+ getColor() {
151
+ return this._color;
152
+ }
153
+
154
+ setStrokeWidth(strokeWidth?: number) {
155
+ this.setValue("_strokeWidth", strokeWidth);
156
+ }
157
+
158
+ getStrokeWidth() {
159
+ return this._strokeWidth;
160
+ }
161
+
162
+ setBlendMode(blendMode?: SkEnum<typeof BlendMode>) {
163
+ this.setValue("_blendMode", this.enum(BlendMode, blendMode));
164
+ }
165
+
166
+ getBlendMode() {
167
+ return this._blendMode;
168
+ }
169
+
170
+ setStyle(style?: SkEnum<typeof PaintStyle>) {
171
+ this.setValue("_style", this.enum(PaintStyle, style));
172
+ }
173
+
174
+ getStyle() {
175
+ return this._style;
176
+ }
177
+
178
+ setStrokeJoin(strokeJoin?: SkEnum<typeof StrokeJoin>) {
179
+ this.setValue("_strokeJoin", this.enum(StrokeJoin, strokeJoin));
180
+ }
181
+
182
+ getStrokeJoin() {
183
+ return this._strokeJoin;
184
+ }
185
+
186
+ setStrokeCap(strokeCap?: SkEnum<typeof StrokeCap>) {
187
+ this.setValue("_strokeCap", this.enum(StrokeCap, strokeCap));
188
+ }
189
+
190
+ getStrokeCap() {
191
+ return this._strokeCap;
192
+ }
193
+
194
+ setStrokeMiter(strokeMiter?: number) {
195
+ this.setValue("_strokeMiter", strokeMiter);
196
+ }
197
+
198
+ getStrokeMiter() {
199
+ return this._strokeMiter;
200
+ }
201
+
202
+ setOpacity(opacity?: number) {
203
+ this.setValue("_opacity", opacity);
204
+ }
205
+
206
+ getOpacity() {
207
+ return this._opacity;
208
+ }
209
+
210
+ setAntiAlias(antiAlias?: boolean) {
211
+ this.setValue("_antiAlias", antiAlias);
212
+ }
213
+
214
+ getAntiAlias() {
215
+ return this._antiAlias;
216
+ }
217
+
218
+ setImageFilter(imageFilter?: SkImageFilter) {
219
+ this.setValue("_imageFilter", imageFilter);
220
+ }
221
+
222
+ getImageFilter() {
223
+ return this._imageFilter;
224
+ }
225
+
226
+ setShader(shader?: SkShader) {
227
+ this.setValue("_shader", shader);
228
+ }
229
+
230
+ getShader() {
231
+ return this._shader;
232
+ }
233
+
234
+ setPathEffect(pathEffect?: SkPathEffect) {
235
+ this.setValue("_pathEffect", pathEffect);
236
+ }
237
+
238
+ getPathEffect() {
239
+ return this._pathEffect;
240
+ }
241
+
242
+ setColorFilter(colorFilter?: SkColorFilter) {
243
+ this.setValue("_colorFilter", colorFilter);
244
+ }
245
+
246
+ getColorFilter() {
247
+ return this._colorFilter;
248
+ }
249
+
250
+ setMaskFilter(maskFilter?: SkMaskFilter) {
251
+ this.setValue("_maskFilter", maskFilter);
252
+ }
253
+
254
+ getMaskFilter() {
255
+ return this._maskFilter;
256
+ }
257
+
258
+ isPristine() {
259
+ return this.pristine;
260
+ }
261
+
262
+ concatTo(paint: SkPaint) {
263
+ if (this._opacity !== undefined) {
264
+ paint.setAlphaf(paint.getAlphaf() * this._opacity);
265
+ }
266
+ if (this._color !== undefined) {
267
+ const currentOpacity = paint.getAlphaf();
268
+ paint.setShader(null);
269
+ paint.setColor(this._color);
270
+ paint.setAlphaf(currentOpacity * paint.getAlphaf());
271
+ }
272
+ if (this._strokeWidth !== undefined) {
273
+ paint.setStrokeWidth(this._strokeWidth);
274
+ }
275
+ if (this._blendMode !== undefined) {
276
+ paint.setBlendMode(this._blendMode);
277
+ }
278
+ if (this._style !== undefined) {
279
+ paint.setStyle(this._style);
280
+ }
281
+ if (this._strokeJoin !== undefined) {
282
+ paint.setStrokeJoin(this._strokeJoin);
283
+ }
284
+ if (this._strokeCap !== undefined) {
285
+ paint.setStrokeCap(this._strokeCap);
286
+ }
287
+ if (this._strokeMiter !== undefined) {
288
+ paint.setStrokeMiter(this._strokeMiter);
289
+ }
290
+ if (this._antiAlias !== undefined) {
291
+ paint.setAntiAlias(this._antiAlias);
292
+ }
293
+ if (this._imageFilter !== undefined) {
294
+ paint.setImageFilter(this._imageFilter);
295
+ }
296
+ if (this._shader !== undefined) {
297
+ paint.setShader(this._shader);
298
+ }
299
+ if (this._pathEffect !== undefined) {
300
+ paint.setPathEffect(this._pathEffect);
301
+ }
302
+ if (this._colorFilter !== undefined) {
303
+ paint.setColorFilter(this._colorFilter);
304
+ }
305
+ if (this._maskFilter !== undefined) {
306
+ paint.setMaskFilter(this._maskFilter);
307
+ }
308
+ }
6
309
  }
@@ -1,15 +1,7 @@
1
- import type {
2
- SkColorFilter,
3
- SkImageFilter,
4
- SkMaskFilter,
5
- SkPaint,
6
- SkPathEffect,
7
- SkShader,
8
- } from "../../skia/types";
9
-
10
1
  import type { GroupProps } from "./Common";
11
- import type { DrawingContext } from "./DrawingContext";
12
2
  import type { DeclarationType, NodeType } from "./NodeType";
3
+ import type { DeclarationContext } from "./DeclarationContext";
4
+ import type { DrawingContext } from "./DrawingContext";
13
5
 
14
6
  export interface Node<P> {
15
7
  type: NodeType;
@@ -26,19 +18,11 @@ export interface Node<P> {
26
18
 
27
19
  export type Invalidate = () => void;
28
20
 
29
- export interface DeclarationNode<P, T, Nullable extends null | never = never>
30
- extends Node<P> {
21
+ export interface DeclarationNode<P> extends Node<P> {
31
22
  declarationType: DeclarationType;
32
- materialize(): T | Nullable;
23
+ decorate(ctx: DeclarationContext): void;
33
24
 
34
25
  setInvalidate(invalidate: Invalidate): void;
35
-
36
- isPaint(): this is DeclarationNode<unknown, SkPaint>;
37
- isImageFilter(): this is DeclarationNode<unknown, SkImageFilter>;
38
- isColorFilter(): this is DeclarationNode<unknown, SkColorFilter>;
39
- isShader(): this is DeclarationNode<unknown, SkShader>;
40
- isMaskFilter(): this is DeclarationNode<unknown, SkMaskFilter>;
41
- isPathEffect(): this is DeclarationNode<unknown, SkPathEffect>;
42
26
  }
43
27
 
44
28
  export interface RenderNode<P extends GroupProps> extends Node<P> {
@@ -1,12 +1,3 @@
1
- import type {
2
- SkImageFilter,
3
- SkMaskFilter,
4
- SkShader,
5
- SkColorFilter,
6
- SkPathEffect,
7
- SkPaint,
8
- } from "../../skia/types";
9
-
10
1
  import type { ChildrenProps, GroupProps, PaintProps } from "./Common";
11
2
  import type {
12
3
  BlendImageFilterProps,
@@ -68,17 +59,17 @@ import type {
68
59
  Path2DPathEffectProps,
69
60
  } from "./PathEffects";
70
61
 
71
- type ImageFilterNode<P> = DeclarationNode<P, SkImageFilter>;
62
+ type ImageFilterNode<P> = DeclarationNode<P>;
72
63
 
73
- type PathEffectNode<P> = DeclarationNode<P, SkPathEffect>;
74
- type NullablePathEffectNode<P> = DeclarationNode<P, SkPathEffect, null>;
64
+ type PathEffectNode<P> = DeclarationNode<P>;
65
+ type NullablePathEffectNode<P> = DeclarationNode<P>;
75
66
 
76
67
  type DrawingNode<P extends GroupProps> = RenderNode<P>;
77
68
 
78
69
  export interface SkDOM {
79
70
  Layer(props?: ChildrenProps): RenderNode<ChildrenProps>;
80
71
  Group(props?: GroupProps): RenderNode<GroupProps>;
81
- Paint(props: PaintProps): DeclarationNode<PaintProps, SkPaint>;
72
+ Paint(props: PaintProps): DeclarationNode<PaintProps>;
82
73
 
83
74
  // Drawings
84
75
  Fill(props?: DrawingNodeProps): DrawingNode<DrawingNodeProps>;
@@ -106,7 +97,7 @@ export interface SkDOM {
106
97
  // BlurMaskFilters
107
98
  BlurMaskFilter(
108
99
  props: BlurMaskFilterProps
109
- ): DeclarationNode<BlurMaskFilterProps, SkMaskFilter>;
100
+ ): DeclarationNode<BlurMaskFilterProps>;
110
101
 
111
102
  // ImageFilters
112
103
  BlendImageFilter(
@@ -134,41 +125,33 @@ export interface SkDOM {
134
125
  // ColorFilters
135
126
  MatrixColorFilter(
136
127
  props: MatrixColorFilterProps
137
- ): DeclarationNode<MatrixColorFilterProps, SkColorFilter>;
128
+ ): DeclarationNode<MatrixColorFilterProps>;
138
129
  BlendColorFilter(
139
130
  props: BlendColorFilterProps
140
- ): DeclarationNode<BlendColorFilterProps, SkColorFilter>;
141
- LumaColorFilter(): DeclarationNode<null, SkColorFilter>;
142
- LinearToSRGBGammaColorFilter(): DeclarationNode<null, SkColorFilter>;
143
- SRGBToLinearGammaColorFilter(): DeclarationNode<null, SkColorFilter>;
131
+ ): DeclarationNode<BlendColorFilterProps>;
132
+ LumaColorFilter(): DeclarationNode<null>;
133
+ LinearToSRGBGammaColorFilter(): DeclarationNode<null>;
134
+ SRGBToLinearGammaColorFilter(): DeclarationNode<null>;
144
135
  LerpColorFilter(
145
136
  props: LerpColorFilterProps
146
- ): DeclarationNode<LerpColorFilterProps, SkColorFilter>;
137
+ ): DeclarationNode<LerpColorFilterProps>;
147
138
 
148
139
  // Shaders
149
- Shader(props: ShaderProps): DeclarationNode<ShaderProps, SkShader>;
150
- ImageShader(
151
- props: ImageShaderProps
152
- ): DeclarationNode<ImageShaderProps, SkShader>;
153
- ColorShader(props: ColorProps): DeclarationNode<ColorProps, SkShader>;
154
- Turbulence(
155
- props: TurbulenceProps
156
- ): DeclarationNode<TurbulenceProps, SkShader>;
157
- FractalNoise(
158
- props: FractalNoiseProps
159
- ): DeclarationNode<FractalNoiseProps, SkShader>;
140
+ Shader(props: ShaderProps): DeclarationNode<ShaderProps>;
141
+ ImageShader(props: ImageShaderProps): DeclarationNode<ImageShaderProps>;
142
+ ColorShader(props: ColorProps): DeclarationNode<ColorProps>;
143
+ Turbulence(props: TurbulenceProps): DeclarationNode<TurbulenceProps>;
144
+ FractalNoise(props: FractalNoiseProps): DeclarationNode<FractalNoiseProps>;
160
145
  LinearGradient(
161
146
  props: LinearGradientProps
162
- ): DeclarationNode<LinearGradientProps, SkShader>;
147
+ ): DeclarationNode<LinearGradientProps>;
163
148
  RadialGradient(
164
149
  props: RadialGradientProps
165
- ): DeclarationNode<RadialGradientProps, SkShader>;
166
- SweepGradient(
167
- props: SweepGradientProps
168
- ): DeclarationNode<SweepGradientProps, SkShader>;
150
+ ): DeclarationNode<RadialGradientProps>;
151
+ SweepGradient(props: SweepGradientProps): DeclarationNode<SweepGradientProps>;
169
152
  TwoPointConicalGradient(
170
153
  props: TwoPointConicalGradientProps
171
- ): DeclarationNode<TwoPointConicalGradientProps, SkShader>;
154
+ ): DeclarationNode<TwoPointConicalGradientProps>;
172
155
 
173
156
  // Path Effects
174
157
  CornerPathEffect(
@@ -192,12 +175,8 @@ export interface SkDOM {
192
175
  ): NullablePathEffectNode<Line2DPathEffectProps>;
193
176
 
194
177
  // Mixed
195
- Blend(
196
- props: BlendProps
197
- ): DeclarationNode<BlendProps, SkShader | SkImageFilter>;
178
+ Blend(props: BlendProps): DeclarationNode<BlendProps>;
198
179
  BackdropFilter(props: ChildrenProps): RenderNode<ChildrenProps>;
199
180
  Box(props: BoxProps): RenderNode<BoxProps>;
200
- BoxShadow(
201
- props: BoxShadowProps
202
- ): DeclarationNode<BoxShadowProps, BoxShadowProps>;
181
+ BoxShadow(props: BoxShadowProps): DeclarationNode<BoxShadowProps>;
203
182
  }
@@ -1,4 +1,5 @@
1
1
  export * from "./DrawingContext";
2
+ export * from "./DeclarationContext";
2
3
  export * from "./Node";
3
4
  export * from "./NodeType";
4
5
  export * from "./SkDOM";
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import "./skia/NativeSetup";
2
2
  export * from "./renderer";
3
3
  export * from "./renderer/Canvas";
4
+ export * from "./renderer/Offscreen";
4
5
  export * from "./views";
5
6
  export * from "./skia";
6
7
  export * from "./external";
@@ -40,10 +40,10 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
40
40
 
41
41
  const registerValues = useCallback(
42
42
  (values: Array<SkiaValue<unknown>>) => {
43
- if (ref.current === null) {
44
- throw new Error("Canvas ref is not set");
43
+ if (ref.current !== null) {
44
+ return ref.current.registerValues(values);
45
45
  }
46
- return ref.current.registerValues(values);
46
+ return () => {};
47
47
  },
48
48
  [ref]
49
49
  );
@@ -1,9 +1,8 @@
1
1
  import type { DrawingInfo } from "../views";
2
- import type { Skia } from "../skia/types";
3
- import type { DrawingContext as DOMDrawingContext } from "../dom/types";
2
+ import type { Skia, SkCanvas, SkPaint } from "../skia/types";
4
3
 
5
- export interface DrawingContext
6
- extends Omit<DrawingInfo, "touches">,
7
- DOMDrawingContext {
4
+ export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
8
5
  Skia: Skia;
6
+ canvas: SkCanvas;
7
+ paint: SkPaint;
9
8
  }