@shopify/react-native-skia 0.1.141 → 0.1.145

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,5 +1,5 @@
1
1
  import { Skia } from "../Skia";
2
- import type { DataSource } from "../types";
2
+ import type { DataSourceParam } from "../types";
3
3
 
4
4
  import { useRawData } from "./Data";
5
5
 
@@ -9,6 +9,6 @@ const tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);
9
9
  * Returns a Skia Typeface object
10
10
  * */
11
11
  export const useTypeface = (
12
- source: DataSource | null | undefined,
12
+ source: DataSourceParam,
13
13
  onError?: (err: Error) => void
14
14
  ) => useRawData(source, tfFactory, onError);
@@ -2,4 +2,14 @@ import type { SkJSIInstance } from "../JsiInstance";
2
2
 
3
3
  export type SkData = SkJSIInstance<"Data">;
4
4
 
5
- export type DataSource = ReturnType<typeof require> | string | Uint8Array;
5
+ type RNModule = number;
6
+ type ESModule = {
7
+ __esModule: true;
8
+ default: string;
9
+ };
10
+ export type DataModule = RNModule | ESModule;
11
+ export type DataSource = DataModule | string | Uint8Array;
12
+ export type DataSourceParam = DataSource | null | undefined;
13
+
14
+ export const isRNModule = (mod: DataModule): mod is RNModule =>
15
+ typeof mod === "number";
@@ -34,6 +34,12 @@ export interface SkPaint extends SkJSIInstance<"Paint"> {
34
34
  */
35
35
  copy(): SkPaint;
36
36
 
37
+ /**
38
+ * Sets all SkPaint contents to their initial values. This is equivalent to replacing
39
+ SkPaint with the result of SkPaint().
40
+ */
41
+ reset(): void;
42
+
37
43
  /**
38
44
  * Retrieves the alpha and RGB unpremultiplied. RGB are extended sRGB values
39
45
  * (sRGB gamut, and encoded with the sRGB transfer function).
@@ -3,8 +3,9 @@ import type { TileMode } from "../ImageFilter";
3
3
  import type { SkRect } from "../Rect";
4
4
  import type { SkShader } from "../Shader";
5
5
  import type { SkMatrix } from "../Matrix";
6
+ import type { SkJSIInstance } from "../JsiInstance";
6
7
 
7
- export interface SkPicture {
8
+ export interface SkPicture extends SkJSIInstance<"Picture"> {
8
9
  /**
9
10
  * Returns a new shader that will draw with this picture.
10
11
  *
@@ -1,11 +1,10 @@
1
- /* eslint-disable no-nested-ternary */
2
1
  import type { CanvasKit, EmbindEnumEntity } from "canvaskit-wasm";
3
2
 
4
3
  import type { SkJSIInstance } from "../types";
5
4
 
6
5
  export class NotImplementedOnRNWeb extends Error {
7
- constructor() {
8
- super("Not implemented on React Native Web");
6
+ constructor(msg?: string) {
7
+ super(msg ?? "Not implemented on React Native Web");
9
8
  }
10
9
  }
11
10
 
@@ -17,12 +16,12 @@ export abstract class Host {
17
16
  }
18
17
  }
19
18
 
20
- export abstract class HostObject<T, N extends string>
19
+ export abstract class BaseHostObject<T, N extends string>
21
20
  extends Host
22
21
  implements SkJSIInstance<N>
23
22
  {
24
23
  readonly __typename__: N;
25
- readonly ref: T;
24
+ ref: T;
26
25
 
27
26
  constructor(CanvasKit: CanvasKit, ref: T, typename: N) {
28
27
  super(CanvasKit);
@@ -31,23 +30,14 @@ export abstract class HostObject<T, N extends string>
31
30
  }
32
31
  }
33
32
 
34
- // eslint-disable-next-line @typescript-eslint/ban-types
35
- export type NonNullish = {};
36
-
37
- export const toOptionalValue = <T>(
38
- value: NonNullish | undefined | null
39
- ): T | undefined | null =>
40
- value === undefined ? undefined : value === null ? null : toValue(value);
41
-
42
- export const toUndefinedableValue = <T>(
43
- value: NonNullish | undefined
44
- ): T | undefined => (value === undefined ? undefined : toValue(value));
45
-
46
- export const toNullableValue = <T>(value: NonNullish | null): T | null =>
47
- value === null ? null : toValue(value);
48
-
49
- export const toValue = <T>(value: NonNullish): T =>
50
- (value as HostObject<T, string>).ref;
33
+ export abstract class HostObject<T, N extends string> extends BaseHostObject<
34
+ T,
35
+ N
36
+ > {
37
+ static fromValue<T>(value: SkJSIInstance<string>) {
38
+ return (value as HostObject<T, string>).ref;
39
+ }
40
+ }
51
41
 
52
42
  export const ckEnum = (value: number): EmbindEnumEntity => ({ value });
53
43
  export const optEnum = (
@@ -1,4 +1,4 @@
1
- import type { Canvas, Image, CanvasKit, Paint } from "canvaskit-wasm";
1
+ import type { Canvas, CanvasKit } from "canvaskit-wasm";
2
2
 
3
3
  import type {
4
4
  BlendMode,
@@ -24,14 +24,19 @@ import type {
24
24
  SkVertices,
25
25
  } from "../types";
26
26
 
27
- import {
28
- ckEnum,
29
- HostObject,
30
- toValue,
31
- toUndefinedableValue,
32
- toOptionalValue,
33
- } from "./Host";
27
+ import { ckEnum, HostObject } from "./Host";
28
+ import { JsiSkPaint } from "./JsiSkPaint";
34
29
  import { JsiSkRect } from "./JsiSkRect";
30
+ import { JsiSkRRect } from "./JsiSkRRect";
31
+ import { JsiSkImage } from "./JsiSkImage";
32
+ import { JsiSkVertices } from "./JsiSkVertices";
33
+ import { JsiSkPath } from "./JsiSkPath";
34
+ import { JsiSkFont } from "./JsiSkFont";
35
+ import { JsiSkTextBlob } from "./JsiSkTextBlob";
36
+ import { JsiSkPicture } from "./JsiSkPicture";
37
+ import { JsiSkMatrix } from "./JsiSkMatrix";
38
+ import { JsiSkImageFilter } from "./JsiSkImageFilter";
39
+ import { JsiSkPoint } from "./JsiSkPoint";
35
40
 
36
41
  export class JsiSkCanvas
37
42
  extends HostObject<Canvas, "Canvas">
@@ -43,13 +48,18 @@ export class JsiSkCanvas
43
48
 
44
49
  drawRect(rect: SkRect, paint: SkPaint) {
45
50
  this.ref.drawRect(
46
- JsiSkRect.fromValue(this.CanvasKit, rect).ref,
47
- toValue<Paint>(paint)
51
+ JsiSkRect.fromValue(this.CanvasKit, rect),
52
+ JsiSkPaint.fromValue(paint)
48
53
  );
49
54
  }
50
55
 
51
56
  drawImage(image: SkImage, x: number, y: number, paint?: SkPaint) {
52
- this.ref.drawImage(toValue<Image>(image), x, y, toOptionalValue(paint));
57
+ this.ref.drawImage(
58
+ JsiSkImage.fromValue(image),
59
+ x,
60
+ y,
61
+ paint ? JsiSkPaint.fromValue(paint) : paint
62
+ );
53
63
  }
54
64
 
55
65
  drawImageRect(
@@ -60,10 +70,10 @@ export class JsiSkCanvas
60
70
  fastSample?: boolean
61
71
  ) {
62
72
  this.ref.drawImageRect(
63
- toValue<Image>(img),
64
- JsiSkRect.fromValue(this.CanvasKit, src).ref,
65
- JsiSkRect.fromValue(this.CanvasKit, dest).ref,
66
- toValue<Paint>(paint),
73
+ JsiSkImage.fromValue(img),
74
+ JsiSkRect.fromValue(this.CanvasKit, src),
75
+ JsiSkRect.fromValue(this.CanvasKit, dest),
76
+ JsiSkPaint.fromValue(paint),
67
77
  fastSample
68
78
  );
69
79
  }
@@ -77,12 +87,12 @@ export class JsiSkCanvas
77
87
  paint?: SkPaint | null
78
88
  ) {
79
89
  this.ref.drawImageCubic(
80
- toValue(img),
90
+ JsiSkImage.fromValue(img),
81
91
  left,
82
92
  top,
83
93
  B,
84
94
  C,
85
- toOptionalValue(paint)
95
+ paint ? JsiSkPaint.fromValue(paint) : paint
86
96
  );
87
97
  }
88
98
 
@@ -95,12 +105,12 @@ export class JsiSkCanvas
95
105
  paint?: SkPaint | null
96
106
  ) {
97
107
  this.ref.drawImageOptions(
98
- toValue(img),
108
+ JsiSkImage.fromValue(img),
99
109
  left,
100
110
  top,
101
111
  ckEnum(fm),
102
112
  ckEnum(mm),
103
- toOptionalValue(paint)
113
+ paint ? JsiSkPaint.fromValue(paint) : paint
104
114
  );
105
115
  }
106
116
 
@@ -112,11 +122,11 @@ export class JsiSkCanvas
112
122
  paint?: SkPaint | null
113
123
  ) {
114
124
  this.ref.drawImageNine(
115
- toValue(img),
116
- toValue(center),
117
- toValue(dest),
125
+ JsiSkImage.fromValue(img),
126
+ Array.from(JsiSkRect.fromValue(this.CanvasKit, center)),
127
+ JsiSkRect.fromValue(this.CanvasKit, dest),
118
128
  ckEnum(filter),
119
- toOptionalValue(paint)
129
+ paint ? JsiSkPaint.fromValue(paint) : paint
120
130
  );
121
131
  }
122
132
 
@@ -129,12 +139,12 @@ export class JsiSkCanvas
129
139
  paint?: SkPaint | null
130
140
  ) {
131
141
  this.ref.drawImageRectCubic(
132
- toValue<Image>(img),
133
- JsiSkRect.fromValue(this.CanvasKit, src).ref,
134
- JsiSkRect.fromValue(this.CanvasKit, dest).ref,
142
+ JsiSkImage.fromValue(img),
143
+ JsiSkRect.fromValue(this.CanvasKit, src),
144
+ JsiSkRect.fromValue(this.CanvasKit, dest),
135
145
  B,
136
146
  C,
137
- toOptionalValue(paint)
147
+ paint ? JsiSkPaint.fromValue(paint) : paint
138
148
  );
139
149
  }
140
150
 
@@ -147,29 +157,33 @@ export class JsiSkCanvas
147
157
  paint?: SkPaint | null
148
158
  ) {
149
159
  this.ref.drawImageRectOptions(
150
- toValue<Image>(img),
151
- JsiSkRect.fromValue(this.CanvasKit, src).ref,
152
- JsiSkRect.fromValue(this.CanvasKit, dest).ref,
160
+ JsiSkImage.fromValue(img),
161
+ JsiSkRect.fromValue(this.CanvasKit, src),
162
+ JsiSkRect.fromValue(this.CanvasKit, dest),
153
163
  ckEnum(fm),
154
164
  ckEnum(mm),
155
- toOptionalValue(paint)
165
+ paint ? JsiSkPaint.fromValue(paint) : paint
156
166
  );
157
167
  }
158
168
 
159
169
  drawPaint(paint: SkPaint) {
160
- this.ref.drawPaint(toValue(paint));
170
+ this.ref.drawPaint(JsiSkPaint.fromValue(paint));
161
171
  }
162
172
 
163
173
  drawLine(x0: number, y0: number, x1: number, y1: number, paint: SkPaint) {
164
- this.ref.drawLine(x0, y0, x1, y1, toValue(paint));
174
+ this.ref.drawLine(x0, y0, x1, y1, JsiSkPaint.fromValue(paint));
165
175
  }
166
176
 
167
177
  drawCircle(cx: number, cy: number, radius: number, paint: SkPaint) {
168
- this.ref.drawCircle(cx, cy, radius, toValue(paint));
178
+ this.ref.drawCircle(cx, cy, radius, JsiSkPaint.fromValue(paint));
169
179
  }
170
180
 
171
181
  drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint) {
172
- this.ref.drawVertices(toValue(verts), ckEnum(mode), toValue(paint));
182
+ this.ref.drawVertices(
183
+ JsiSkVertices.fromValue(verts),
184
+ ckEnum(mode),
185
+ JsiSkPaint.fromValue(paint)
186
+ );
173
187
  }
174
188
 
175
189
  drawPatch(
@@ -182,9 +196,9 @@ export class JsiSkCanvas
182
196
  this.ref.drawPatch(
183
197
  cubics.map(({ x, y }) => [x, y]).flat(),
184
198
  colors,
185
- toOptionalValue(texs),
199
+ texs ? texs.flatMap((p) => Array.from(JsiSkPoint.fromValue(p))) : texs,
186
200
  mode ? ckEnum(mode) : null,
187
- toUndefinedableValue(paint)
201
+ paint ? JsiSkPaint.fromValue(paint) : undefined
188
202
  );
189
203
  }
190
204
 
@@ -196,7 +210,7 @@ export class JsiSkCanvas
196
210
  this.ref.drawPoints(
197
211
  ckEnum(mode),
198
212
  points.map(({ x, y }) => [x, y]).flat(),
199
- toValue(paint)
213
+ JsiSkPaint.fromValue(paint)
200
214
  );
201
215
  }
202
216
 
@@ -208,36 +222,57 @@ export class JsiSkCanvas
208
222
  paint: SkPaint
209
223
  ) {
210
224
  this.ref.drawArc(
211
- toValue(oval),
225
+ JsiSkRect.fromValue(this.CanvasKit, oval),
212
226
  startAngle,
213
227
  sweepAngle,
214
228
  useCenter,
215
- toValue(paint)
229
+ JsiSkPaint.fromValue(paint)
216
230
  );
217
231
  }
218
232
 
219
233
  drawRRect(rrect: SkRRect, paint: SkPaint) {
220
- this.ref.drawRRect(toValue(rrect), toValue(paint));
234
+ this.ref.drawRRect(
235
+ JsiSkRRect.fromValue(this.CanvasKit, rrect),
236
+ JsiSkPaint.fromValue(paint)
237
+ );
221
238
  }
222
239
 
223
240
  drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint) {
224
- this.ref.drawDRRect(toValue(outer), toValue(inner), toValue(paint));
241
+ this.ref.drawDRRect(
242
+ JsiSkRRect.fromValue(this.CanvasKit, outer),
243
+ JsiSkRRect.fromValue(this.CanvasKit, inner),
244
+ JsiSkPaint.fromValue(paint)
245
+ );
225
246
  }
226
247
 
227
248
  drawOval(oval: SkRect, paint: SkPaint) {
228
- this.ref.drawOval(toValue(oval), toValue(paint));
249
+ this.ref.drawOval(
250
+ JsiSkRect.fromValue(this.CanvasKit, oval),
251
+ JsiSkPaint.fromValue(paint)
252
+ );
229
253
  }
230
254
 
231
255
  drawPath(path: SkPath, paint: SkPaint) {
232
- this.ref.drawPath(toValue(path), toValue(paint));
256
+ this.ref.drawPath(JsiSkPath.fromValue(path), JsiSkPaint.fromValue(paint));
233
257
  }
234
258
 
235
259
  drawText(str: string, x: number, y: number, paint: SkPaint, font: SkFont) {
236
- this.ref.drawText(str, x, y, toValue(paint), toValue(font));
260
+ this.ref.drawText(
261
+ str,
262
+ x,
263
+ y,
264
+ JsiSkPaint.fromValue(paint),
265
+ JsiSkFont.fromValue(font)
266
+ );
237
267
  }
238
268
 
239
269
  drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint) {
240
- this.ref.drawTextBlob(toValue(blob), x, y, toValue(paint));
270
+ this.ref.drawTextBlob(
271
+ JsiSkTextBlob.fromValue(blob),
272
+ x,
273
+ y,
274
+ JsiSkPaint.fromValue(paint)
275
+ );
241
276
  }
242
277
 
243
278
  drawGlyphs(
@@ -253,8 +288,8 @@ export class JsiSkCanvas
253
288
  positions.map((p) => [p.x, p.y]).flat(),
254
289
  x,
255
290
  y,
256
- toValue(font),
257
- toValue(paint)
291
+ JsiSkFont.fromValue(font),
292
+ JsiSkPaint.fromValue(paint)
258
293
  );
259
294
  }
260
295
 
@@ -273,9 +308,9 @@ export class JsiSkCanvas
273
308
  flags?: SaveLayerFlag
274
309
  ) {
275
310
  return this.ref.saveLayer(
276
- toUndefinedableValue(paint),
277
- toOptionalValue(bounds),
278
- toOptionalValue(backdrop),
311
+ paint ? JsiSkPaint.fromValue(paint) : undefined,
312
+ bounds ? JsiSkRect.fromValue(this.CanvasKit, bounds) : bounds,
313
+ backdrop ? JsiSkImageFilter.fromValue(backdrop) : backdrop,
279
314
  flags
280
315
  );
281
316
  }
@@ -309,22 +344,30 @@ export class JsiSkCanvas
309
344
  }
310
345
 
311
346
  clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean) {
312
- this.ref.clipPath(toValue(path), ckEnum(op), doAntiAlias);
347
+ this.ref.clipPath(JsiSkPath.fromValue(path), ckEnum(op), doAntiAlias);
313
348
  }
314
349
 
315
350
  clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean) {
316
- this.ref.clipRect(toValue(rect), ckEnum(op), doAntiAlias);
351
+ this.ref.clipRect(
352
+ JsiSkRect.fromValue(this.CanvasKit, rect),
353
+ ckEnum(op),
354
+ doAntiAlias
355
+ );
317
356
  }
318
357
 
319
358
  clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean) {
320
- this.ref.clipRRect(toValue(rrect), ckEnum(op), doAntiAlias);
359
+ this.ref.clipRRect(
360
+ JsiSkRRect.fromValue(this.CanvasKit, rrect),
361
+ ckEnum(op),
362
+ doAntiAlias
363
+ );
321
364
  }
322
365
 
323
366
  concat(m: SkMatrix) {
324
- this.ref.concat(toValue(m));
367
+ this.ref.concat(JsiSkMatrix.fromValue(m));
325
368
  }
326
369
 
327
370
  drawPicture(skp: SkPicture) {
328
- this.ref.drawPicture(toValue(skp));
371
+ this.ref.drawPicture(JsiSkPicture.fromValue(skp));
329
372
  }
330
373
  }
@@ -8,7 +8,7 @@ import type {
8
8
  BlendMode,
9
9
  } from "../types";
10
10
 
11
- import { ckEnum, Host, toValue, NotImplementedOnRNWeb } from "./Host";
11
+ import { ckEnum, Host } from "./Host";
12
12
  import { JsiSkColorFilter } from "./JsiSkColorFilter";
13
13
 
14
14
  export class JsiSkColorFilterFactory
@@ -29,21 +29,28 @@ export class JsiSkColorFilterFactory
29
29
  MakeBlend(color: SkColor, mode: BlendMode) {
30
30
  return new JsiSkColorFilter(
31
31
  this.CanvasKit,
32
- this.CanvasKit.ColorFilter.MakeBlend(toValue(color), ckEnum(mode))
32
+ this.CanvasKit.ColorFilter.MakeBlend(color, ckEnum(mode))
33
33
  );
34
34
  }
35
35
 
36
36
  MakeCompose(outer: SkColorFilter, inner: SkColorFilter) {
37
37
  return new JsiSkColorFilter(
38
38
  this.CanvasKit,
39
- this.CanvasKit.ColorFilter.MakeCompose(toValue(outer), toValue(inner))
39
+ this.CanvasKit.ColorFilter.MakeCompose(
40
+ JsiSkColorFilter.fromValue(outer),
41
+ JsiSkColorFilter.fromValue(inner)
42
+ )
40
43
  );
41
44
  }
42
45
 
43
46
  MakeLerp(t: number, dst: SkColorFilter, src: SkColorFilter) {
44
47
  return new JsiSkColorFilter(
45
48
  this.CanvasKit,
46
- this.CanvasKit.ColorFilter.MakeLerp(t, toValue(dst), toValue(src))
49
+ this.CanvasKit.ColorFilter.MakeLerp(
50
+ t,
51
+ JsiSkColorFilter.fromValue(dst),
52
+ JsiSkColorFilter.fromValue(src)
53
+ )
47
54
  );
48
55
  }
49
56
 
@@ -62,6 +69,9 @@ export class JsiSkColorFilterFactory
62
69
  }
63
70
 
64
71
  MakeLumaColorFilter(): SkColorFilter {
65
- throw new NotImplementedOnRNWeb();
72
+ return new JsiSkColorFilter(
73
+ this.CanvasKit,
74
+ this.CanvasKit.ColorFilter.MakeLuma()
75
+ );
66
76
  }
67
77
  }
@@ -9,7 +9,9 @@ import type {
9
9
  SkTypeface,
10
10
  } from "../types";
11
11
 
12
- import { HostObject, toValue, ckEnum } from "./Host";
12
+ import { HostObject, ckEnum } from "./Host";
13
+ import { JsiSkPaint } from "./JsiSkPaint";
14
+ import { JsiSkPoint } from "./JsiSkPoint";
13
15
  import { JsiSkRect } from "./JsiSkRect";
14
16
  import { JsiSkTypeface } from "./JsiSkTypeface";
15
17
 
@@ -43,7 +45,12 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
43
45
 
44
46
  // TODO: Fix return value in the C++ implementation, it return float32
45
47
  getGlyphWidths(glyphs: number[], paint?: SkPaint | null) {
46
- return [...this.ref.getGlyphWidths(glyphs, paint ? toValue(paint) : null)];
48
+ return [
49
+ ...this.ref.getGlyphWidths(
50
+ glyphs,
51
+ paint ? JsiSkPaint.fromValue(paint) : null
52
+ ),
53
+ ];
47
54
  }
48
55
 
49
56
  getGlyphIntercepts(
@@ -55,7 +62,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
55
62
  return [
56
63
  ...this.ref.getGlyphIntercepts(
57
64
  glyphs,
58
- positions.map((p) => toValue(p)),
65
+ positions.map((p) => Array.from(JsiSkPoint.fromValue(p))).flat(),
59
66
  top,
60
67
  bottom
61
68
  ),
@@ -120,6 +127,6 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
120
127
  }
121
128
 
122
129
  setTypeface(face: SkTypeface | null) {
123
- this.ref.setTypeface(face ? toValue(face) : null);
130
+ this.ref.setTypeface(face ? JsiSkTypeface.fromValue(face) : null);
124
131
  }
125
132
  }
@@ -11,7 +11,8 @@ import type {
11
11
  TileMode,
12
12
  } from "../types";
13
13
 
14
- import { ckEnum, HostObject, toValue } from "./Host";
14
+ import { ckEnum, HostObject } from "./Host";
15
+ import { JsiSkMatrix } from "./JsiSkMatrix";
15
16
  import { JsiSkShader } from "./JsiSkShader";
16
17
 
17
18
  export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
@@ -41,7 +42,7 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
41
42
  ckEnum(ty),
42
43
  ckEnum(fm),
43
44
  ckEnum(mm),
44
- localMatrix ? toValue(localMatrix) : undefined
45
+ localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
45
46
  )
46
47
  );
47
48
  }
@@ -60,7 +61,7 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
60
61
  ckEnum(ty),
61
62
  B,
62
63
  C,
63
- localMatrix ? toValue(localMatrix) : undefined
64
+ localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
64
65
  )
65
66
  );
66
67
  }
@@ -3,8 +3,9 @@ import type { CanvasKit } from "canvaskit-wasm";
3
3
  import type { SkData, ImageInfo } from "../types";
4
4
  import type { ImageFactory } from "../types/Image/ImageFactory";
5
5
 
6
- import { Host, toValue, ckEnum } from "./Host";
6
+ import { Host, ckEnum } from "./Host";
7
7
  import { JsiSkImage } from "./JsiSkImage";
8
+ import { JsiSkData } from "./JsiSkData";
8
9
 
9
10
  export class JsiSkImageFactory extends Host implements ImageFactory {
10
11
  constructor(CanvasKit: CanvasKit) {
@@ -12,7 +13,9 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
12
13
  }
13
14
 
14
15
  MakeImageFromEncoded(encoded: SkData) {
15
- const image = this.CanvasKit.MakeImageFromEncoded(toValue(encoded));
16
+ const image = this.CanvasKit.MakeImageFromEncoded(
17
+ JsiSkData.fromValue(encoded)
18
+ );
16
19
  if (image === null) {
17
20
  return null;
18
21
  }
@@ -29,7 +32,7 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
29
32
  height: info.height,
30
33
  width: info.width,
31
34
  },
32
- toValue(data),
35
+ JsiSkData.fromValue(data),
33
36
  bytesPerRow
34
37
  );
35
38
  if (image === null) {