react-native-skia 3.0.0 → 3.0.2

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 (261) hide show
  1. package/Package.swift +14 -13
  2. package/android/CMakeLists.txt +13 -42
  3. package/android/build.gradle +55 -47
  4. package/android/cpp/jni/JniLoad.cpp +2 -4
  5. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  6. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  8. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  9. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  10. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  11. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  12. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  13. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  14. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  15. package/apple/MetalLayerColorSpace.mm +0 -4
  16. package/apple/RNSkApplePlatformContext.h +0 -14
  17. package/apple/RNSkApplePlatformContext.mm +2 -112
  18. package/apple/RNSkMetalCanvasProvider.h +14 -19
  19. package/apple/RNSkMetalCanvasProvider.mm +35 -68
  20. package/apple/SkiaView.h +20 -0
  21. package/apple/SkiaView.mm +210 -0
  22. package/cpp/api/JsiSkApi.h +2 -13
  23. package/cpp/api/JsiSkCanvas.h +4 -18
  24. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  25. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  26. package/cpp/api/JsiSkImage.h +7 -41
  27. package/cpp/api/JsiSkImageFactory.h +0 -14
  28. package/cpp/api/JsiSkSurface.h +2 -16
  29. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  30. package/cpp/rnskia/RNDawnContext.h +6 -0
  31. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  32. package/cpp/rnskia/RNDawnUtils.h +0 -1
  33. package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
  34. package/cpp/rnskia/RNDawnWindowContext.h +4 -0
  35. package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
  36. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  37. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  38. package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
  39. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  40. package/cpp/rnskia/RNSkPlatformContext.h +9 -15
  41. package/cpp/rnskia/RNSkView.h +340 -245
  42. package/jestSetup.js +1 -3
  43. package/lib/commonjs/Platform/Platform.web.js +1 -1
  44. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  45. package/lib/commonjs/index.d.ts +1 -3
  46. package/lib/commonjs/index.js +3 -12
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/mock/index.js +0 -1
  49. package/lib/commonjs/mock/index.js.map +1 -1
  50. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  51. package/lib/commonjs/renderer/Canvas.js +24 -20
  52. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  53. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  54. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  55. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  56. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  57. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  58. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  59. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  60. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  61. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  62. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  63. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  64. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  65. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  66. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  67. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  68. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  69. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  70. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  71. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  72. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  73. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  74. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  75. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  76. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  77. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  78. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  79. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  80. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  81. package/lib/commonjs/views/android.d.ts +6 -0
  82. package/lib/commonjs/views/android.js +17 -0
  83. package/lib/commonjs/views/android.js.map +1 -0
  84. package/lib/commonjs/views/types.d.ts +3 -12
  85. package/lib/commonjs/views/types.js.map +1 -1
  86. package/lib/module/Platform/Platform.web.js +1 -1
  87. package/lib/module/Platform/Platform.web.js.map +1 -1
  88. package/lib/module/index.d.ts +1 -3
  89. package/lib/module/index.js +1 -3
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/mock/index.js +0 -1
  92. package/lib/module/mock/index.js.map +1 -1
  93. package/lib/module/renderer/Canvas.d.ts +15 -12
  94. package/lib/module/renderer/Canvas.js +24 -19
  95. package/lib/module/renderer/Canvas.js.map +1 -1
  96. package/lib/module/skia/types/Graphite.d.ts +3 -3
  97. package/lib/module/skia/types/Graphite.js.map +1 -1
  98. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  99. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  100. package/lib/module/skia/types/Skia.d.ts +1 -2
  101. package/lib/module/skia/types/Skia.js.map +1 -1
  102. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  103. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  104. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  105. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  106. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  107. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  108. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  109. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  110. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  111. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  112. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  113. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  114. package/lib/module/views/SkiaGraphiteView.js +23 -12
  115. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  116. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  117. package/lib/module/views/SkiaPictureView.js +12 -10
  118. package/lib/module/views/SkiaPictureView.js.map +1 -1
  119. package/lib/module/views/SkiaView.web.d.ts +12 -0
  120. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  121. package/lib/module/views/SkiaView.web.js.map +1 -0
  122. package/lib/module/views/SkiaWebRenderer.js +1 -1
  123. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  124. package/lib/module/views/android.d.ts +6 -0
  125. package/lib/module/views/android.js +10 -0
  126. package/lib/module/views/android.js.map +1 -0
  127. package/lib/module/views/types.d.ts +3 -12
  128. package/lib/module/views/types.js.map +1 -1
  129. package/lib/typescript/src/index.d.ts +1 -3
  130. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  131. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  132. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  133. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  134. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  135. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  136. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  137. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  138. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  139. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  140. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  141. package/lib/typescript/src/views/android.d.ts +6 -0
  142. package/lib/typescript/src/views/types.d.ts +3 -12
  143. package/package.json +8 -16
  144. package/react-native-skia.podspec +50 -57
  145. package/src/Platform/Platform.web.tsx +1 -1
  146. package/src/index.ts +1 -3
  147. package/src/mock/index.ts +0 -1
  148. package/src/renderer/Canvas.tsx +23 -27
  149. package/src/skia/types/Graphite.ts +3 -3
  150. package/src/skia/types/Image/ImageFactory.ts +2 -2
  151. package/src/skia/types/Skia.ts +1 -2
  152. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  153. package/src/specs/NativeSkiaModule.web.ts +9 -21
  154. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  155. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  156. package/src/views/SkiaGraphiteView.tsx +27 -16
  157. package/src/views/SkiaPictureView.tsx +11 -10
  158. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  159. package/src/views/SkiaWebRenderer.ts +1 -1
  160. package/src/views/android.ts +16 -0
  161. package/src/views/types.ts +3 -14
  162. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  163. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  164. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  165. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  166. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  167. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  168. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  169. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  170. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  171. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  172. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  173. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  174. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  175. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  176. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  177. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  178. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  179. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  180. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  181. package/apple/MetalContext.h +0 -116
  182. package/apple/MetalContext.mm +0 -38
  183. package/apple/MetalWindowContext.h +0 -42
  184. package/apple/MetalWindowContext.mm +0 -95
  185. package/apple/RNSkAppleView.h +0 -49
  186. package/apple/RNSkAppleView.mm +0 -35
  187. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  188. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  189. package/apple/SkiaGraphiteView.h +0 -26
  190. package/apple/SkiaGraphiteView.mm +0 -180
  191. package/apple/SkiaPictureView.h +0 -7
  192. package/apple/SkiaPictureView.mm +0 -70
  193. package/apple/SkiaUIView.h +0 -31
  194. package/apple/SkiaUIView.mm +0 -164
  195. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  196. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  197. package/cpp/rnskia/RNSkPictureView.h +0 -211
  198. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  199. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  200. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  201. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  202. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  203. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  204. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  205. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  206. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  207. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  208. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  209. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  210. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  211. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  212. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  213. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  214. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  215. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  216. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  217. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  218. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  219. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  220. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  221. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  222. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  223. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  224. package/lib/module/renderer/DefaultCanvas.js +0 -34
  225. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  226. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  227. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  228. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  229. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  230. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  231. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  232. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  233. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  234. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  235. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  236. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  237. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  238. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  239. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  240. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  241. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  242. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  243. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  244. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  245. package/lib/module/views/SkiaPictureView.web.js +0 -156
  246. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  247. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  248. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  249. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  250. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  251. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  252. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  253. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  254. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  255. package/libs/.graphite +0 -1
  256. package/src/renderer/DefaultCanvas.tsx +0 -41
  257. package/src/renderer/GraphiteCanvas.tsx +0 -61
  258. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  259. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  260. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  261. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -2,7 +2,8 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
2
2
  import React, { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import Rea from "../external/reanimated/ReanimatedProxy";
4
4
  import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
5
- import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
5
+ import { androidNativeProps } from "../views/android";
6
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
6
7
  import { SkiaSGRoot } from "../sksg/Reconciler";
7
8
  import { Skia } from "../skia";
8
9
  import { Platform } from "../Platform";
@@ -34,16 +35,11 @@ export const useCanvasSize = userRef => {
34
35
  size
35
36
  };
36
37
  };
37
- // Anything else reaching the native component would hit the generated
38
- // string-enum parser, which aborts on unknown values.
39
- const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" ? surfaceType : "auto";
40
-
41
38
  /**
42
- * What every canvas shares, whichever native view it renders into: the native
43
- * id, the scene graph root rendered into it, the `onSize` measurement and the
44
- * imperative handle of the ref.
39
+ * What the canvas owns: the native id, the scene graph root rendered into it,
40
+ * the `onSize` measurement and the imperative handle of the ref.
45
41
  */
46
- export const useCanvasRoot = ({
42
+ const useCanvasRoot = ({
47
43
  children,
48
44
  onSize,
49
45
  ref,
@@ -132,14 +128,27 @@ export const useCanvasRoot = ({
132
128
  viewRef
133
129
  };
134
130
  };
131
+
132
+ /**
133
+ * The declarative canvas. Its children are rendered by Skia's own React
134
+ * renderer; the frames are produced off the JS thread:
135
+ *
136
+ * - the JS thread records the scene graph into a native recorder once per
137
+ * React commit and hands it to the view;
138
+ * - the Reanimated UI runtime only reads the shared values into it (the one
139
+ * step that needs a JS runtime), it never replays anything;
140
+ * - a dedicated native thread pool replays the recorder into a Graphite
141
+ * recording whenever the content changed, at most once per presented frame;
142
+ * - the view presents the recording on the next vsync.
143
+ *
144
+ * On the web the scene is drawn into a picture on the JS thread and painted
145
+ * on a WebGL canvas.
146
+ */
135
147
  export const Canvas = ({
136
- debug,
137
148
  opaque,
138
149
  children,
139
150
  onSize,
140
- colorSpace = "p3",
141
151
  highBitDepth = false,
142
- androidWarmup = false,
143
152
  android,
144
153
  ref,
145
154
  onLayout,
@@ -169,17 +178,13 @@ export const Canvas = ({
169
178
  };
170
179
  }
171
180
  }, [onLayout, onSize]);
172
- return /*#__PURE__*/React.createElement(SkiaPictureViewNativeComponent, _extends({
181
+ return /*#__PURE__*/React.createElement(SkiaViewNativeComponent, _extends({
173
182
  ref: viewRef,
174
183
  collapsable: false,
175
184
  nativeID: `${nativeId}`,
176
- debug: debug,
177
185
  opaque: opaque,
178
- colorSpace: colorSpace,
179
- highBitDepth: highBitDepth,
180
- androidWarmup: androidWarmup,
181
- androidSurfaceType: resolveSurfaceType(android === null || android === void 0 ? void 0 : android.surfaceType),
182
- androidZOrderOnTop: !!(android !== null && android !== void 0 && android.zOrderOnTop),
186
+ highBitDepth: highBitDepth
187
+ }, androidNativeProps(android), {
183
188
  onLayout: Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
184
189
  }, viewProps));
185
190
  };
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","useEffect","useImperativeHandle","useLayoutEffect","useMemo","useRef","useState","Rea","SkiaViewNativeId","SkiaPictureViewNativeComponent","SkiaSGRoot","Skia","Platform","HAS_REANIMATED_3","useCanvasRef","useReanimatedFrame","useFrameCallback","measure","useCanvasRefPriv","useAnimatedRef","useCanvasSize","userRef","ourRef","ref","size","setSize","width","height","current","_x","_y","resolveSurfaceType","surfaceType","useCanvasRoot","children","onSize","onLayout","OS","console","error","viewRef","nativeId","root","_viewRef$current","result","canvasRef","value","render","unmount","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current2","measureInWindow","_viewRef$current3","Canvas","debug","opaque","colorSpace","highBitDepth","androidWarmup","android","viewProps","onLayoutWeb","e","nativeEvent","layout","createElement","_extends","collapsable","nativeID","androidSurfaceType","androidZOrderOnTop","zOrderOnTop"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n LayoutChangeEvent,\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport type { AndroidCanvasProps, AndroidSurfaceType } from \"../views/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { HAS_REANIMATED_3 } from \"../external\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nconst useReanimatedFrame = !HAS_REANIMATED_3 ? () => {} : Rea.useFrameCallback;\nconst measure = !HAS_REANIMATED_3 ? null : Rea.measure;\n\nconst useCanvasRefPriv: typeof useRef<View> = !HAS_REANIMATED_3\n ? useRef\n : Rea.useAnimatedRef;\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n /** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */\n onLayout?: ViewProps[\"onLayout\"];\n /**\n * Declares that the canvas covers every pixel of its bounds, so nothing\n * behind it needs to show through. On Android an opaque canvas is backed by\n * a `SurfaceView` by default, the cheapest path (see `android.surfaceType`).\n * Defaults to false.\n */\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n /**\n * Renders into a surface with more than 8 bits per channel (16-bit float on\n * iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are\n * identical to the default 8-bit surface, only with more precision (this is\n * about bit depth, not HDR). On Android the extra precision survives\n * composition only when combined with `opaque`, and the prop must be set\n * before the canvas is mounted.\n */\n highBitDepth?: boolean;\n /** Android-only rendering options. Ignored on iOS and web. */\n android?: AndroidCanvasProps;\n ref?: React.Ref<CanvasRef>;\n androidWarmup?: boolean;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\n// Anything else reaching the native component would hit the generated\n// string-enum parser, which aborts on unknown values.\nconst resolveSurfaceType = (\n surfaceType: AndroidSurfaceType | undefined\n): \"auto\" | AndroidSurfaceType =>\n surfaceType === \"SurfaceView\" || surfaceType === \"TextureView\"\n ? surfaceType\n : \"auto\";\n\n/**\n * What every canvas shares, whichever native view it renders into: the native\n * id, the scene graph root rendered into it, the `onSize` measurement and the\n * imperative handle of the ref.\n */\nexport const useCanvasRoot = ({\n children,\n onSize,\n ref,\n onLayout,\n}: Pick<CanvasProps, \"children\" | \"onSize\" | \"ref\" | \"onLayout\">) => {\n if (onLayout && Platform.OS !== \"web\") {\n console.error(\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useCanvasRefPriv(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);\n\n useReanimatedFrame(() => {\n \"worklet\";\n if (onSize && measure) {\n const result =\n // eslint-disable-next-line no-nested-ternary\n Platform.OS === \"web\"\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n viewRef.current?.canvasRef\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n measure(viewRef.current.canvasRef)\n : { width: 0, height: 0 }\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n measure(viewRef as any);\n if (result) {\n const { width, height } = result;\n if (onSize.value.width !== width || onSize.value.height !== height) {\n onSize.value = { width, height };\n }\n }\n }\n }, !!onSize);\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n }) as CanvasRef\n );\n return { nativeId, viewRef };\n};\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n highBitDepth = false,\n androidWarmup = false,\n android,\n ref,\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n const { nativeId, viewRef } = useCanvasRoot({\n children,\n onSize,\n ref,\n onLayout,\n });\n\n const onLayoutWeb = useCallback(\n (e: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(e);\n }\n if (Platform.OS === \"web\" && onSize) {\n const { width, height } = e.nativeEvent.layout;\n onSize.value = { width, height };\n }\n },\n [onLayout, onSize]\n );\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n highBitDepth={highBitDepth}\n androidWarmup={androidWarmup}\n androidSurfaceType={resolveSurfaceType(android?.surfaceType)}\n androidZOrderOnTop={!!android?.zOrderOnTop}\n onLayout={\n Platform.OS === \"web\" && (onSize || onLayout) ? onLayoutWeb : onLayout\n }\n {...viewProps}\n />\n );\n};\n"],"mappings":";AACA,OAAOA,KAAK,IACVC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A,aAAc;IAC7BW,kBAAkB,EAAE7C,kBAAkB,CAACmC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAElC,WAAW,CAAE;IAC7D6C,kBAAkB,EAAE,CAAC,EAACX,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEY,WAAW,CAAC;IAC3C1C,QAAQ,EACNxB,QAAQ,CAACyB,EAAE,KAAK,KAAK,KAAKF,MAAM,IAAIC,QAAQ,CAAC,GAAGgC,WAAW,GAAGhC;EAC/D,GACG+B,SAAS,CACd,CAAC;AAEN,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useCallback","useEffect","useImperativeHandle","useLayoutEffect","useMemo","useRef","useState","Rea","SkiaViewNativeId","androidNativeProps","SkiaViewNativeComponent","SkiaSGRoot","Skia","Platform","HAS_REANIMATED_3","useCanvasRef","useReanimatedFrame","useFrameCallback","measure","useCanvasRefPriv","useAnimatedRef","useCanvasSize","userRef","ourRef","ref","size","setSize","width","height","current","_x","_y","useCanvasRoot","children","onSize","onLayout","OS","console","error","viewRef","nativeId","root","_viewRef$current","result","canvasRef","value","render","unmount","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current2","measureInWindow","_viewRef$current3","Canvas","opaque","highBitDepth","android","viewProps","onLayoutWeb","e","nativeEvent","layout","createElement","_extends","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n LayoutChangeEvent,\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport { androidNativeProps } from \"../views/android\";\nimport type { AndroidCanvasProps } from \"../views/types\";\nimport SkiaViewNativeComponent from \"../specs/SkiaViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { HAS_REANIMATED_3 } from \"../external\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nconst useReanimatedFrame = !HAS_REANIMATED_3 ? () => {} : Rea.useFrameCallback;\nconst measure = !HAS_REANIMATED_3 ? null : Rea.measure;\n\nconst useCanvasRefPriv: typeof useRef<View> = !HAS_REANIMATED_3\n ? useRef\n : Rea.useAnimatedRef;\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n /** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */\n onLayout?: ViewProps[\"onLayout\"];\n /**\n * Declares that the canvas covers every pixel of its bounds, so nothing\n * behind it needs to show through. On Android an opaque canvas is backed by\n * a `SurfaceView` by default, the cheapest path (see `android.surfaceType`).\n * Defaults to false.\n */\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n /**\n * Renders into a surface with more than 8 bits per channel (16-bit float on\n * iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are\n * identical to the default 8-bit surface, only with more precision (this is\n * about bit depth, not HDR). On Android the extra precision survives\n * composition only when combined with `opaque`, and the prop must be set\n * before the canvas is mounted.\n */\n highBitDepth?: boolean;\n /** Android-only rendering options. Ignored on iOS and web. */\n android?: AndroidCanvasProps;\n ref?: React.Ref<CanvasRef>;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\n/**\n * What the canvas owns: the native id, the scene graph root rendered into it,\n * the `onSize` measurement and the imperative handle of the ref.\n */\nconst useCanvasRoot = ({\n children,\n onSize,\n ref,\n onLayout,\n}: Pick<CanvasProps, \"children\" | \"onSize\" | \"ref\" | \"onLayout\">) => {\n if (onLayout && Platform.OS !== \"web\") {\n console.error(\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useCanvasRefPriv(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);\n\n useReanimatedFrame(() => {\n \"worklet\";\n if (onSize && measure) {\n const result =\n // eslint-disable-next-line no-nested-ternary\n Platform.OS === \"web\"\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n viewRef.current?.canvasRef\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n measure(viewRef.current.canvasRef)\n : { width: 0, height: 0 }\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n measure(viewRef as any);\n if (result) {\n const { width, height } = result;\n if (onSize.value.width !== width || onSize.value.height !== height) {\n onSize.value = { width, height };\n }\n }\n }\n }, !!onSize);\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n }) as CanvasRef\n );\n return { nativeId, viewRef };\n};\n\n/**\n * The declarative canvas. Its children are rendered by Skia's own React\n * renderer; the frames are produced off the JS thread:\n *\n * - the JS thread records the scene graph into a native recorder once per\n * React commit and hands it to the view;\n * - the Reanimated UI runtime only reads the shared values into it (the one\n * step that needs a JS runtime), it never replays anything;\n * - a dedicated native thread pool replays the recorder into a Graphite\n * recording whenever the content changed, at most once per presented frame;\n * - the view presents the recording on the next vsync.\n *\n * On the web the scene is drawn into a picture on the JS thread and painted\n * on a WebGL canvas.\n */\nexport const Canvas = ({\n opaque,\n children,\n onSize,\n highBitDepth = false,\n android,\n ref,\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n const { nativeId, viewRef } = useCanvasRoot({\n children,\n onSize,\n ref,\n onLayout,\n });\n\n const onLayoutWeb = useCallback(\n (e: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(e);\n }\n if (Platform.OS === \"web\" && onSize) {\n const { width, height } = e.nativeEvent.layout;\n onSize.value = { width, height };\n }\n },\n [onLayout, onSize]\n );\n return (\n <SkiaViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n opaque={opaque}\n highBitDepth={highBitDepth}\n {...androidNativeProps(android)}\n onLayout={\n Platform.OS === \"web\" && (onSize || onLayout) ? onLayoutWeb : onLayout\n }\n {...viewProps}\n />\n );\n};\n"],"mappings":";AACA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,OAAO,EACPC,MAAM,E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vas";
2
2
  import type { SkJSIInstance } from "./JsiInstance";
3
3
  /**
4
- * A frame recorded for a SkiaGraphiteView. Immutable once finished: submit it
5
- * to the view as many times as needed, from any runtime.
4
+ * A frame recorded for a view. Immutable once finished: submit it to the view
5
+ * as many times as needed, from any runtime.
6
6
  */
7
7
  export type SkGraphiteRecording = SkJSIInstance<"GraphiteRecording">;
8
8
  /**
9
- * The recording side of a SkiaGraphiteView, obtained from the view's ref.
9
+ * The recording side of a view, obtained from the ref of a SkiaGraphiteView.
10
10
  *
11
11
  * Frames are recorded on the calling thread and presented by the view on its
12
12
  * display link, so the context can be captured into a worklet and used from
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Graphite.ts"],"sourcesContent":["import type { SkCanvas } from \"./Canvas\";\nimport type { SkJSIInstance } from \"./JsiInstance\";\n\n/**\n * A frame recorded for a SkiaGraphiteView. Immutable once finished: submit it\n * to the view as many times as needed, from any runtime.\n */\nexport type SkGraphiteRecording = SkJSIInstance<\"GraphiteRecording\">;\n\n/**\n * The recording side of a SkiaGraphiteView, obtained from the view's ref.\n *\n * Frames are recorded on the calling thread and presented by the view on its\n * display link, so the context can be captured into a worklet and used from\n * the Reanimated UI runtime or a dedicated worklet runtime. One recording is\n * open at a time.\n */\nexport interface SkGraphiteContext extends SkJSIInstance<\"GraphiteContext\"> {\n /** Width of the view in points. */\n readonly width: number;\n /** Height of the view in points. */\n readonly height: number;\n /**\n * Starts a frame. The canvas draws in points and starts with whatever the\n * view currently shows: clear it first. It is only valid until\n * finishRecording().\n */\n beginRecording(): SkCanvas;\n /** Ends the frame started by beginRecording(). */\n finishRecording(): SkGraphiteRecording;\n /**\n * Queues a recording for the next display frame. Recordings are presented\n * in submission order and never dropped.\n */\n submit(recording: SkGraphiteRecording): void;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Graphite.ts"],"sourcesContent":["import type { SkCanvas } from \"./Canvas\";\nimport type { SkJSIInstance } from \"./JsiInstance\";\n\n/**\n * A frame recorded for a view. Immutable once finished: submit it to the view\n * as many times as needed, from any runtime.\n */\nexport type SkGraphiteRecording = SkJSIInstance<\"GraphiteRecording\">;\n\n/**\n * The recording side of a view, obtained from the ref of a SkiaGraphiteView.\n *\n * Frames are recorded on the calling thread and presented by the view on its\n * display link, so the context can be captured into a worklet and used from\n * the Reanimated UI runtime or a dedicated worklet runtime. One recording is\n * open at a time.\n */\nexport interface SkGraphiteContext extends SkJSIInstance<\"GraphiteContext\"> {\n /** Width of the view in points. */\n readonly width: number;\n /** Height of the view in points. */\n readonly height: number;\n /**\n * Starts a frame. The canvas draws in points and starts with whatever the\n * view currently shows: clear it first. It is only valid until\n * finishRecording().\n */\n beginRecording(): SkCanvas;\n /** Ends the frame started by beginRecording(). */\n finishRecording(): SkGraphiteRecording;\n /**\n * Queues a recording for the next display frame. Recordings are presented\n * in submission order and never dropped.\n */\n submit(recording: SkGraphiteRecording): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -89,7 +89,7 @@ export interface ImageFactory {
89
89
  * while the image is in use: destroy() releases the underlying GPU
90
90
  * resource regardless of reference counts.
91
91
  *
92
- * Note: This method is only available when the Graphite backend is enabled.
92
+ * Native only.
93
93
  *
94
94
  * @param pointer - The WGPUTexture pointer (texture.nativePointer)
95
95
  * @returns An SkImage wrapping the texture, or throws if the texture is invalid
@@ -101,7 +101,7 @@ export interface ImageFactory {
101
101
  * returned pointer carries one reference and must be adopted exactly once
102
102
  * with react-native-webgpu's adoptTexture(), which owns it from then on.
103
103
  *
104
- * Note: This method is only available when the Graphite backend is enabled.
104
+ * Native only.
105
105
  *
106
106
  * @param image - An SkImage to convert to a texture
107
107
  * @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
@@ -1 +1 @@
1
- {"version":3,"names":["AlphaType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { ColorType } from \"./ColorType\";\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n MakeNull: () => SkImage;\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The native buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * native buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n *\n * Return an Image backed by a given native texture.\n *\n * The native texture must be a valid owning reference.\n *\n * This API might be used to integrate with other libraries using gpu textures,\n * or to transfer images between different threads.\n *\n * @param texture A native texture handle\n * @param width The width of the texture\n * @param height The height of the texture\n * @param mipmapped Whether the texture is mipmapped\n * @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.\n *\n * @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.\n */\n MakeImageFromNativeTextureUnstable: (\n texture: unknown,\n width: number,\n height: number,\n mipmapped?: boolean,\n outputImage?: SkImage\n ) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n\n /**\n * Creates an SkImage from a WebGPU texture.\n * This allows using textures rendered by WebGPU in Skia drawings. The\n * texture crosses the package boundary as a raw pointer: pass\n * `texture.nativePointer` from a react-native-webgpu GPUTexture created on\n * the shared device (importDevice(Skia.getNativeDevice())). The native side\n * takes its own reference, so the handle stays valid even if the JS\n * GPUTexture is garbage collected — but do not call texture.destroy()\n * while the image is in use: destroy() releases the underlying GPU\n * resource regardless of reference counts.\n *\n * Note: This method is only available when the Graphite backend is enabled.\n *\n * @param pointer - The WGPUTexture pointer (texture.nativePointer)\n * @returns An SkImage wrapping the texture, or throws if the texture is invalid\n */\n MakeImageFromNativeTexture(pointer: bigint): SkImage;\n\n /**\n * Creates a WebGPU texture from an SkImage.\n * This allows using Skia images in WebGPU rendering pipelines. The\n * returned pointer carries one reference and must be adopted exactly once\n * with react-native-webgpu's adoptTexture(), which owns it from then on.\n *\n * Note: This method is only available when the Graphite backend is enabled.\n *\n * @param image - An SkImage to convert to a texture\n * @returns A WGPUTexture pointer for adoptTexture(), or throws on failure\n */\n MakeNativeTextureFromImage(image: SkImage): bigint;\n}\n"],"mappings":"AAMA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["AlphaType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { ColorType } from \"./ColorType\";\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n MakeNull: () => SkImage;\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The native buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * native buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n *\n * Return an Image backed by a given native texture.\n *\n * The native texture must be a valid owning reference.\n *\n * This API might be used to integrate with other libraries using gpu textures,\n * or to transfer images between different threads.\n *\n * @param texture A native texture handle\n * @param width The width of the texture\n * @param height The height of the texture\n * @param mipmapped Whether the texture is mipmapped\n * @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.\n *\n * @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.\n */\n MakeImageFromNativeTextureUnstable: (\n texture: unknown,\n width: number,\n height: number,\n mipmapped?: boolean,\n outputImage?: SkImage\n ) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n\n /**\n * Creates an SkImage from a WebGPU texture.\n * This allows using textures rendered by WebGPU in Skia drawings. The\n * texture crosses the package boundary as a raw pointer: pass\n * `texture.nativePointer` from a react-native-webgpu GPUTexture created on\n * the shared device (importDevice(Skia.getNativeDevice())). The native side\n * takes its own reference, so the handle stays valid even if the JS\n * GPUTexture is garbage collected — but do not call texture.destroy()\n * while the image is in use: destroy() releases the underlying GPU\n * resource regardless of reference counts.\n *\n * Native only.\n *\n * @param pointer - The WGPUTexture pointer (texture.nativePointer)\n * @returns An SkImage wrapping the texture, or throws if the texture is invalid\n */\n MakeImageFromNativeTexture(pointer: bigint): SkImage;\n\n /**\n * Creates a WebGPU texture from an SkImage.\n * This allows using Skia images in WebGPU rendering pipelines. The\n * returned pointer carries one reference and must be adopted exactly once\n * with react-native-webgpu's adoptTexture(), which owns it from then on.\n *\n * Native only.\n *\n * @param image - An SkImage to convert to a texture\n * @returns A WGPUTexture pointer for adoptTexture(), or throws on failure\n */\n MakeNativeTextureFromImage(image: SkImage): bigint;\n}\n"],"mappings":"AAMA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA","ignoreList":[]}
@@ -83,8 +83,7 @@ export interface Skia {
83
83
  /**
84
84
  * Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
85
85
  * react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's
86
- * device (zero-copy interop). Only available on Graphite builds; throws
87
- * otherwise.
86
+ * device (zero-copy interop). Native only.
88
87
  */
89
88
  getNativeDevice(): bigint;
90
89
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory, PathBuilderFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { Video } from \"./Video\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\nimport type { JsiRecorder } from \"./Recorder\";\nimport type { SkottieFactory } from \"./Skottie\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n PathBuilder: PathBuilderFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n Skottie: SkottieFactory;\n Video: (url: string) => Promise<Video> | Video;\n NativeBuffer: NativeBufferFactory;\n Recorder(): JsiRecorder;\n /**\n * Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to\n * react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's\n * device (zero-copy interop). Only available on Graphite builds; throws\n * otherwise.\n */\n getNativeDevice(): bigint;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory, PathBuilderFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { Video } from \"./Video\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\nimport type { JsiRecorder } from \"./Recorder\";\nimport type { SkottieFactory } from \"./Skottie\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n PathBuilder: PathBuilderFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n Skottie: SkottieFactory;\n Video: (url: string) => Promise<Video> | Video;\n NativeBuffer: NativeBufferFactory;\n Recorder(): JsiRecorder;\n /**\n * Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to\n * react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's\n * device (zero-copy interop). Native only.\n */\n getNativeDevice(): bigint;\n}\n"],"mappings":"","ignoreList":[]}
@@ -33,7 +33,7 @@ export interface SurfaceFactory {
33
33
  * surface exists. Calling destroy() on the GPUTexture still invalidates
34
34
  * the surface.
35
35
  *
36
- * Note: This method is only available when the Graphite backend is enabled.
36
+ * Native only.
37
37
  *
38
38
  * @param pointer - The WGPUTexture pointer (texture.nativePointer)
39
39
  * @returns An SkSurface rendering into the texture, or throws if the texture is invalid
@@ -1 +1 @@
1
- {"version":3,"names":["ColorSpace","SRGB","DisplayP3"],"sources":["SurfaceFactory.ts"],"sourcesContent":["import type { SkSurface } from \"./Surface\";\n\nexport const ColorSpace = {\n SRGB: \"srgb\",\n DisplayP3: \"display-p3\",\n} as const;\n\nexport type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];\n\nexport interface SurfaceOptions {\n colorSpace: ColorSpaceValue;\n}\n\nexport interface SurfaceFactory {\n /**\n * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul\n * alphaType and 8888 color type. The pixels belonging to this surface will be in memory and\n * not visible.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n */\n Make: (width: number, height: number) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n * @param opts - optional surface options (e.g. colorSpace: \"display-p3\" | \"srgb\").\n */\n MakeOffscreen: (\n width: number,\n height: number,\n opts?: SurfaceOptions\n ) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface that draws directly into a WebGPU texture\n * (zero-copy). The texture must be created on Skia's device\n * (importDevice(Skia.getNativeDevice())) with RENDER_ATTACHMENT usage; add\n * TEXTURE_BINDING to sample what Skia drew from WebGPU after each flush().\n * The surface holds its own reference to the texture and keeps it alive\n * for its lifetime, so the caller may release the GPUTexture once the\n * surface exists. Calling destroy() on the GPUTexture still invalidates\n * the surface.\n *\n * Note: This method is only available when the Graphite backend is enabled.\n *\n * @param pointer - The WGPUTexture pointer (texture.nativePointer)\n * @returns An SkSurface rendering into the texture, or throws if the texture is invalid\n */\n MakeFromNativeTexture: (pointer: bigint) => SkSurface;\n}\n"],"mappings":"AAEA,OAAO,MAAMA,UAAU,GAAG;EACxBC,IAAI,EAAE,MAAM;EACZC,SAAS,EAAE;AACb,CAAU","ignoreList":[]}
1
+ {"version":3,"names":["ColorSpace","SRGB","DisplayP3"],"sources":["SurfaceFactory.ts"],"sourcesContent":["import type { SkSurface } from \"./Surface\";\n\nexport const ColorSpace = {\n SRGB: \"srgb\",\n DisplayP3: \"display-p3\",\n} as const;\n\nexport type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];\n\nexport interface SurfaceOptions {\n colorSpace: ColorSpaceValue;\n}\n\nexport interface SurfaceFactory {\n /**\n * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul\n * alphaType and 8888 color type. The pixels belonging to this surface will be in memory and\n * not visible.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n */\n Make: (width: number, height: number) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n * @param opts - optional surface options (e.g. colorSpace: \"display-p3\" | \"srgb\").\n */\n MakeOffscreen: (\n width: number,\n height: number,\n opts?: SurfaceOptions\n ) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface that draws directly into a WebGPU texture\n * (zero-copy). The texture must be created on Skia's device\n * (importDevice(Skia.getNativeDevice())) with RENDER_ATTACHMENT usage; add\n * TEXTURE_BINDING to sample what Skia drew from WebGPU after each flush().\n * The surface holds its own reference to the texture and keeps it alive\n * for its lifetime, so the caller may release the GPUTexture once the\n * surface exists. Calling destroy() on the GPUTexture still invalidates\n * the surface.\n *\n * Native only.\n *\n * @param pointer - The WGPUTexture pointer (texture.nativePointer)\n * @returns An SkSurface rendering into the texture, or throws if the texture is invalid\n */\n MakeFromNativeTexture: (pointer: bigint) => SkSurface;\n}\n"],"mappings":"AAEA,OAAO,MAAMA,UAAU,GAAG;EACxBC,IAAI,EAAE,MAAM;EACZC,SAAS,EAAE;AACb,CAAU","ignoreList":[]}
@@ -1,7 +1,11 @@
1
1
  import type { SkGraphiteContext, SkImage, SkPicture, SkRect } from "../skia/types";
2
2
  import type { ISkiaViewApi } from "../views/types";
3
- /** What every web view registers under its native id. */
3
+ /** What the web view registers under its native id. */
4
4
  export interface SkiaWebViewHandle {
5
+ /** Shows a picture: the frame of a <Canvas> or a <SkiaPictureView>. */
6
+ setPicture(picture: SkPicture): void;
7
+ /** The recording side of the view, see SkiaGraphiteView. */
8
+ getContext(): SkGraphiteContext;
5
9
  getSize(): {
6
10
  width: number;
7
11
  height: number;
@@ -11,9 +15,6 @@ export interface SkiaWebViewHandle {
11
15
  measure(callback: (x: number, y: number, width: number, height: number, pageX: number, pageY: number) => void): void;
12
16
  measureInWindow(callback: (x: number, y: number, width: number, height: number) => void): void;
13
17
  }
14
- export interface SkiaGraphiteViewHandle extends SkiaWebViewHandle {
15
- getContext(): SkGraphiteContext;
16
- }
17
18
  export type ISkiaViewApiWeb = ISkiaViewApi & {
18
19
  views: Record<string, SkiaWebViewHandle>;
19
20
  deferedPictures: Record<string, SkPicture>;
@@ -1,9 +1,7 @@
1
1
  /* eslint-disable import/no-anonymous-default-export */
2
2
 
3
- /** What every web view registers under its native id. */
3
+ /** What the web view registers under its native id. */
4
4
 
5
- const hasPicture = view => "setPicture" in view;
6
- const hasContext = view => "getContext" in view;
7
5
  global.SkiaViewApi = {
8
6
  views: {},
9
7
  deferedPictures: {},
@@ -13,7 +11,7 @@ global.SkiaViewApi = {
13
11
  registerView(nativeId, view) {
14
12
  this.unregisteredViews.delete(nativeId);
15
13
  // Maybe a picture for this view was already set
16
- if (this.deferedPictures[nativeId] && hasPicture(view)) {
14
+ if (this.deferedPictures[nativeId]) {
17
15
  view.setPicture(this.deferedPictures[nativeId]);
18
16
  delete this.deferedPictures[nativeId];
19
17
  }
@@ -32,9 +30,7 @@ global.SkiaViewApi = {
32
30
  const id = `${nativeId}`;
33
31
  const view = this.views[id];
34
32
  if (view) {
35
- if (hasPicture(view)) {
36
- view.setPicture(value);
37
- }
33
+ view.setPicture(value);
38
34
  } else if (!this.unregisteredViews.has(id)) {
39
35
  this.deferedPictures[id] = value;
40
36
  }
@@ -71,8 +67,8 @@ global.SkiaViewApi = {
71
67
  },
72
68
  makeGraphiteContext(nativeId) {
73
69
  const view = this.views[`${nativeId}`];
74
- if (!view || !hasContext(view)) {
75
- throw new Error(`Cannot make a Graphite context: no SkiaGraphiteView with nativeID ${nativeId} is mounted`);
70
+ if (!view) {
71
+ throw new Error(`Cannot make a Graphite context: no view with nativeID ${nativeId} is mounted`);
76
72
  }
77
73
  return view.getContext();
78
74
  },
@@ -1 +1 @@
1
- {"version":3,"names":["hasPicture","view","hasContext","global","SkiaViewApi","views","deferedPictures","unregisteredViews","Set","deferedOnSize","web","registerView","nativeId","delete","setPicture","unregisterView","add","setJsiProperty","name","value","id","has","size","getSize","width","height","requestRedraw","_this$views","redraw","applyUpdates","makeImageSnapshot","rect","Error","makeGraphiteContext","getContext","makeImageSnapshotAsync","Promise","resolve","reject","result"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type {\n SkGraphiteContext,\n SkImage,\n SkPicture,\n SkRect,\n} from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\n\n/** What every web view registers under its native id. */\nexport interface SkiaWebViewHandle {\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n measure(\n callback: (\n x: number,\n y: number,\n width: number,\n height: number,\n pageX: number,\n pageY: number\n ) => void\n ): void;\n measureInWindow(\n callback: (x: number, y: number, width: number, height: number) => void\n ): void;\n}\n\nexport interface SkiaGraphiteViewHandle extends SkiaWebViewHandle {\n getContext(): SkGraphiteContext;\n}\n\ninterface PictureHandle extends SkiaWebViewHandle {\n setPicture(picture: SkPicture): void;\n}\n\nconst hasPicture = (view: SkiaWebViewHandle): view is PictureHandle =>\n \"setPicture\" in view;\n\nconst hasContext = (view: SkiaWebViewHandle): view is SkiaGraphiteViewHandle =>\n \"getContext\" in view;\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaWebViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n unregisteredViews: Set<string>;\n registerView(nativeId: string, view: SkiaWebViewHandle): void;\n unregisterView(nativeId: string): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n unregisteredViews: new Set<string>(),\n deferedOnSize: {},\n web: true,\n registerView(nativeId: string, view: SkiaWebViewHandle) {\n this.unregisteredViews.delete(nativeId);\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId] && hasPicture(view)) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n delete this.deferedPictures[nativeId];\n }\n this.views[nativeId] = view;\n },\n unregisterView(nativeId: string) {\n // Views must be removed on unmount: the handle's closures capture the\n // canvas element, so a stale entry retains the whole detached DOM tree.\n this.unregisteredViews.add(nativeId);\n delete this.views[nativeId];\n delete this.deferedPictures[nativeId];\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n const id = `${nativeId}`;\n const view = this.views[id];\n if (view) {\n if (hasPicture(view)) {\n view.setPicture(value);\n }\n } else if (!this.unregisteredViews.has(id)) {\n this.deferedPictures[id] = value;\n }\n // Otherwise the view has unmounted (e.g. a trailing animation frame):\n // drop the picture instead of deferring it for an id that will never\n // register again, which would retain it forever.\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n // The view may already have unmounted (e.g. a trailing animation frame).\n this.views[`${nativeId}`]?.redraw();\n },\n applyUpdates() {\n // Web canvases are driven from JS (see Container.web.ts); there is no\n // view-owned recorder to update.\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n const view = this.views[`${nativeId}`];\n if (!view) {\n throw new Error(\n `Cannot make image snapshot: view with nativeID ${nativeId} is not registered (it may have unmounted)`\n );\n }\n return view.makeImageSnapshot(rect);\n },\n makeGraphiteContext(nativeId: number) {\n const view = this.views[`${nativeId}`];\n if (!view || !hasContext(view)) {\n throw new Error(\n `Cannot make a Graphite context: no SkiaGraphiteView with nativeID ${nativeId} is mounted`\n );\n }\n return view.getContext();\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const view = this.views[`${nativeId}`];\n if (!view) {\n reject(\n new Error(\n `Cannot make image snapshot: view with nativeID ${nativeId} is not registered (it may have unmounted)`\n )\n );\n return;\n }\n const result = view.makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":"AAAA;;AASA;;AA4BA,MAAMA,UAAU,GAAIC,IAAuB,IACzC,YAAY,IAAIA,IAAI;AAEtB,MAAMC,UAAU,GAAID,IAAuB,IACzC,YAAY,IAAIA,IAAI;AAUtBE,MAAM,CAACC,WAAW,G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,OAAO,IAAIK,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC,MAAMrC,IAAI,GAAG,IAAI,CAACI,KAAK,CAAC,GAAGO,QAAQ,EAAE,CAAC;MACtC,IAAI,CAACX,IAAI,EAAE;QACTqC,MAAM,CACJ,IAAIN,KAAK,CACP,kDAAkDpB,QAAQ,4CAC5D,CACF,CAAC;QACD;MACF;MACA,MAAM2B,MAAM,GAAGtC,IAAI,CAAC6B,iBAAiB,CAACC,IAAI,CAAC;MAC3C,IAAIQ,MAAM,EAAE;QACVF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,MAAM;QACLD,MAAM,CAAC,IAAIN,KAAK,CAAC,+BAA+B,CAAC,CAAC;MACpD;IACF,CAAC,CAAC;EACJ;AACF,CAAoB;;AAEpB;AACA,eAAe,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["global","SkiaViewApi","views","deferedPictures","unregisteredViews","Set","deferedOnSize","web","registerView","nativeId","view","delete","setPicture","unregisterView","add","setJsiProperty","name","value","id","has","size","getSize","width","height","requestRedraw","_this$views","redraw","applyUpdates","makeImageSnapshot","rect","Error","makeGraphiteContext","getContext","makeImageSnapshotAsync","Promise","resolve","reject","result"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type {\n SkGraphiteContext,\n SkImage,\n SkPicture,\n SkRect,\n} from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\n\n/** What the web view registers under its native id. */\nexport interface SkiaWebViewHandle {\n /** Shows a picture: the frame of a <Canvas> or a <SkiaPictureView>. */\n setPicture(picture: SkPicture): void;\n /** The recording side of the view, see SkiaGraphiteView. */\n getContext(): SkGraphiteContext;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n measure(\n callback: (\n x: number,\n y: number,\n width: number,\n height: number,\n pageX: number,\n pageY: number\n ) => void\n ): void;\n measureInWindow(\n callback: (x: number, y: number, width: number, height: number) => void\n ): void;\n}\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaWebViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n unregisteredViews: Set<string>;\n registerView(nativeId: string, view: SkiaWebViewHandle): void;\n unregisterView(nativeId: string): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n unregisteredViews: new Set<string>(),\n deferedOnSize: {},\n web: true,\n registerView(nativeId: string, view: SkiaWebViewHandle) {\n this.unregisteredViews.delete(nativeId);\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n delete this.deferedPictures[nativeId];\n }\n this.views[nativeId] = view;\n },\n unregisterView(nativeId: string) {\n // Views must be removed on unmount: the handle's closures capture the\n // canvas element, so a stale entry retains the whole detached DOM tree.\n this.unregisteredViews.add(nativeId);\n delete this.views[nativeId];\n delete this.deferedPictures[nativeId];\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n const id = `${nativeId}`;\n const view = this.views[id];\n if (view) {\n view.setPicture(value);\n } else if (!this.unregisteredViews.has(id)) {\n this.deferedPictures[id] = value;\n }\n // Otherwise the view has unmounted (e.g. a trailing animation frame):\n // drop the picture instead of deferring it for an id that will never\n // register again, which would retain it forever.\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n // The view may already have unmounted (e.g. a trailing animation frame).\n this.views[`${nativeId}`]?.redraw();\n },\n applyUpdates() {\n // Web canvases are driven from JS (see Container.web.ts); there is no\n // view-owned recorder to update.\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n const view = this.views[`${nativeId}`];\n if (!view) {\n throw new Error(\n `Cannot make image snapshot: view with nativeID ${nativeId} is not registered (it may have unmounted)`\n );\n }\n return view.makeImageSnapshot(rect);\n },\n makeGraphiteContext(nativeId: number) {\n const view = this.views[`${nativeId}`];\n if (!view) {\n throw new Error(\n `Cannot make a Graphite context: no view with nativeID ${nativeId} is mounted`\n );\n }\n return view.getContext();\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const view = this.views[`${nativeId}`];\n if (!view) {\n reject(\n new Error(\n `Cannot make image snapshot: view with nativeID ${nativeId} is not registered (it may have unmounted)`\n )\n );\n return;\n }\n const result = view.makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":"AAAA;;AASA;;AAgCAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,iBAAiB,EAAE,IAAIC,GAAG,CAAS,CAAC;EACpCC,aAAa,EAAE,CAAC,CAAC;EACjBC,GAAG,EAAE,IAAI;EACTC,YAAYA,CAACC,QAAgB,EAAEC,IAAuB,EAAE;IACtD,IAAI,CAACN,iBAAiB,CAACO,MAAM,CAACF,QAAQ,CAAC;IACvC;IACA,IAAI,IAAI,CAACN,eAAe,CAACM,QAAQ,CAAC,EAAE;MAClCC,IAAI,CAACE,UAAU,CAAC,IAAI,CAACT,eAAe,CAACM,QAAQ,CAAc,CAAC;MAC5D,OAAO,IAAI,CAACN,eAAe,CAACM,QAAQ,CAAC;IACvC;IACA,IAAI,CAACP,KAAK,CAACO,QAAQ,CAAC,GAAGC,IAAI;EAC7B,CAAC;EACDG,cAAcA,CAACJ,QAAgB,EAAE;IAC/B;IACA;IACA,IAAI,CAACL,iBAAiB,CAACU,GAAG,CAACL,QAAQ,CAAC;IACpC,OAAO,IAAI,CAACP,KAAK,CAACO,QAAQ,CAAC;IAC3B,OAAO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AkDrB,QAAQ,4CAC5D,CAAC;IACH;IACA,OAAOC,IAAI,CAACkB,iBAAiB,CAACC,IAAI,CAAC;EACrC,CAAC;EACDE,mBAAmBA,CAACtB,QAAgB,EAAE;IACpC,MAAMC,IAAI,GAAG,IAAI,CAACR,KAAK,CAAC,GAAGO,QAAQ,EAAE,CAAC;IACtC,IAAI,CAACC,IAAI,EAAE;MACT,MAAM,IAAIoB,KAAK,CACb,yDAAyDrB,QAAQ,aACnE,CAAC;IACH;IACA,OAAOC,IAAI,CAACsB,UAAU,CAAC,CAAC;EAC1B,CAAC;EACDC,sBAAsBA,CAACxB,QAAgB,EAAEoB,IAAa,EAAE;IACtD,OAAO,IAAIK,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC,MAAM1B,IAAI,GAAG,IAAI,CAACR,KAAK,CAAC,GAAGO,QAAQ,EAAE,CAAC;MACtC,IAAI,CAACC,IAAI,EAAE;QACT0B,MAAM,CACJ,IAAIN,KAAK,CACP,kDAAkDrB,QAAQ,4CAC5D,CACF,CAAC;QACD;MACF;MACA,MAAM4B,MAAM,GAAG3B,IAAI,CAACkB,iBAAiB,CAACC,IAAI,CAAC;MAC3C,IAAIQ,MAAM,EAAE;QACVF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,MAAM;QACLD,MAAM,CAAC,IAAIN,KAAK,CAAC,+BAA+B,CAAC,CAAC;MACpD;IACF,CAAC,CAAC;EACJ;AACF,CAAoB;;AAEpB;AACA,eAAe,CAAC,CAAC","ignoreList":[]}
@@ -1,11 +1,8 @@
1
1
  import { type ViewProps } from "react-native";
2
2
  import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
3
3
  export interface NativeProps extends ViewProps {
4
- debug?: boolean;
5
4
  opaque?: boolean;
6
- colorSpace?: string;
7
5
  highBitDepth?: boolean;
8
- androidWarmup?: boolean;
9
6
  androidSurfaceType?: WithDefault<"auto" | "SurfaceView" | "TextureView", "auto">;
10
7
  androidZOrderOnTop?: WithDefault<boolean, false>;
11
8
  pointerEvents?: WithDefault<"auto" | "none" | "box-none" | "box-only", "auto">;
@@ -4,5 +4,5 @@ import { codegenNativeComponent } from "react-native";
4
4
  // @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
5
5
 
6
6
  // eslint-disable-next-line import/no-default-export
7
- export default codegenNativeComponent("SkiaPictureView");
8
- //# sourceMappingURL=SkiaPictureViewNativeComponent.js.map
7
+ export default codegenNativeComponent("SkiaView");
8
+ //# sourceMappingURL=SkiaViewNativeComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["codegenNativeComponent"],"sources":["SkiaViewNativeComponent.ts"],"sourcesContent":["import { codegenNativeComponent, type ViewProps } from \"react-native\";\nimport type { WithDefault } from \"react-native/Libraries/Types/CodegenTypes\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings\nexport interface NativeProps extends ViewProps {\n opaque?: boolean;\n highBitDepth?: boolean;\n androidSurfaceType?: WithDefault<\n \"auto\" | \"SurfaceView\" | \"TextureView\",\n \"auto\"\n >;\n androidZOrderOnTop?: WithDefault<boolean, false>;\n pointerEvents?: WithDefault<\n \"auto\" | \"none\" | \"box-none\" | \"box-only\",\n \"auto\"\n >;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default codegenNativeComponent<NativeProps>(\"SkiaView\");\n"],"mappings":"AAAA,SAASA,sBAAsB,QAAwB,cAAc;;AAGrE;AACA;;AAeA;AACA,eAAeA,sBAAsB,CAAc,UAAU,CAAC","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { ViewProps } from "react-native";
2
+ export interface NativeProps extends ViewProps {
3
+ opaque?: boolean;
4
+ highBitDepth?: boolean;
5
+ nativeID: string;
6
+ androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
7
+ androidZOrderOnTop?: boolean;
8
+ }
9
+ declare const SkiaViewNativeComponent: ({ nativeID, onLayout, opaque: _opaque, highBitDepth: _highBitDepth, androidSurfaceType: _androidSurfaceType, androidZOrderOnTop: _androidZOrderOnTop, ...viewProps }: NativeProps) => import("react").FunctionComponentElement<import("../views/SkiaView.web").SkiaViewProps>;
10
+ export default SkiaViewNativeComponent;
@@ -0,0 +1,21 @@
1
+ import { createElement } from "react";
2
+ import { SkiaView } from "../views/SkiaView.web";
3
+ const SkiaViewNativeComponent = ({
4
+ nativeID,
5
+ onLayout,
6
+ // Surface settings, never reach the DOM
7
+ opaque: _opaque,
8
+ highBitDepth: _highBitDepth,
9
+ androidSurfaceType: _androidSurfaceType,
10
+ androidZOrderOnTop: _androidZOrderOnTop,
11
+ ...viewProps
12
+ }) => {
13
+ return /*#__PURE__*/createElement(SkiaView, {
14
+ nativeID,
15
+ onLayout,
16
+ ...viewProps
17
+ });
18
+ };
19
+ // eslint-disable-next-line import/no-default-export
20
+ export default SkiaViewNativeComponent;
21
+ //# sourceMappingURL=SkiaViewNativeComponent.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElement","SkiaView","SkiaViewNativeComponent","nativeID","onLayout","opaque","_opaque","highBitDepth","_highBitDepth","androidSurfaceType","_androidSurfaceType","androidZOrderOnTop","_androidZOrderOnTop","viewProps"],"sources":["SkiaViewNativeComponent.web.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport { createElement } from \"react\";\n\nimport { SkiaView } from \"../views/SkiaView.web\";\n\nexport interface NativeProps extends ViewProps {\n opaque?: boolean;\n highBitDepth?: boolean;\n nativeID: string;\n androidSurfaceType?: \"auto\" | \"SurfaceView\" | \"TextureView\";\n androidZOrderOnTop?: boolean;\n}\n\nconst SkiaViewNativeComponent = ({\n nativeID,\n onLayout,\n // Surface settings, never reach the DOM\n opaque: _opaque,\n highBitDepth: _highBitDepth,\n androidSurfaceType: _androidSurfaceType,\n androidZOrderOnTop: _androidZOrderOnTop,\n ...viewProps\n}: NativeProps) => {\n return createElement(SkiaView, {\n nativeID,\n onLayout,\n ...viewProps,\n });\n};\n// eslint-disable-next-line import/no-default-export\nexport default SkiaViewNativeComponent;\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,OAAO;AAErC,SAASC,QAAQ,QAAQ,uBAAuB;AAUhD,MAAMC,uBAAuB,GAAGA,CAAC;EAC/BC,QAAQ;EACRC,QAAQ;EACR;EACAC,MAAM,EAAEC,OAAO;EACfC,YAAY,EAAEC,aAAa;EAC3BC,kBAAkB,EAAEC,mBAAmB;EACvCC,kBAAkB,EAAEC,mBAAmB;EACvC,GAAGC;AACQ,CAAC,KAAK;EACjB,oBAAOb,aAAa,CAACC,QAAQ,EAAE;IAC7BE,QAAQ;IACRC,QAAQ;IACR,GAAGS;EACL,CAAC,CAAC;AACJ,CAAC;AACD;AACA,eAAeX,uBAAuB","ignoreList":[]}
@@ -13,8 +13,7 @@ export interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {
13
13
  ref?: React.Ref<SkiaGraphiteViewRef>;
14
14
  }
15
15
  /**
16
- * A view presenting frames recorded with Skia Graphite. Requires the Graphite
17
- * backend (install-skia-graphite); with the default backend it renders
18
- * nothing. See {@link SkGraphiteContext}.
16
+ * A view whose frames are recorded from JavaScript, on any runtime, through
17
+ * the context of its ref. See {@link SkGraphiteContext}.
19
18
  */
20
- export declare const SkiaGraphiteView: ({ debug, opaque, highBitDepth, ref, ...viewProps }: SkiaGraphiteViewProps) => React.JSX.Element;
19
+ export declare const SkiaGraphiteView: ({ opaque, highBitDepth, android, ref, ...viewProps }: SkiaGraphiteViewProps) => React.JSX.Element;
@@ -1,17 +1,32 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import React, { useImperativeHandle, useMemo, useRef } from "react";
3
- import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
3
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
4
+ import { Platform } from "../Platform";
4
5
  import { SkiaViewApi } from "./api";
6
+ import { androidNativeProps } from "./android";
5
7
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
8
+ // The layout is known synchronously on the new architecture;
9
+ // getBoundingClientRect became stable in React Native 0.83. On the web the
10
+ // view measures itself (see SkiaView.web).
11
+ const measureLayout = view => {
12
+ if (Platform.OS === "web") {
13
+ return {
14
+ width: 0,
15
+ height: 0
16
+ };
17
+ }
18
+ const host = view;
19
+ return host.getBoundingClientRect ? host.getBoundingClientRect() : host.unstable_getBoundingClientRect();
20
+ };
21
+
6
22
  /**
7
- * A view presenting frames recorded with Skia Graphite. Requires the Graphite
8
- * backend (install-skia-graphite); with the default backend it renders
9
- * nothing. See {@link SkGraphiteContext}.
23
+ * A view whose frames are recorded from JavaScript, on any runtime, through
24
+ * the context of its ref. See {@link SkGraphiteContext}.
10
25
  */
11
26
  export const SkiaGraphiteView = ({
12
- debug = false,
13
27
  opaque = false,
14
28
  highBitDepth = false,
29
+ android,
15
30
  ref,
16
31
  ...viewProps
17
32
  }) => {
@@ -21,25 +36,21 @@ export const SkiaGraphiteView = ({
21
36
  getNativeId: () => nativeId,
22
37
  getContext: () => {
23
38
  assertSkiaViewApi();
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
39
  const view = viewRef.current;
26
40
  if (!view) {
27
41
  throw new Error("SkiaGraphiteView: getContext() was called before the view was mounted.");
28
42
  }
29
- // The layout is known synchronously on the new architecture;
30
- // getBoundingClientRect became stable in React Native 0.83.
31
- const size = "getBoundingClientRect" in view ? view.getBoundingClientRect() : view.unstable_getBoundingClientRect();
43
+ const size = measureLayout(view);
32
44
  return SkiaViewApi.makeGraphiteContext(nativeId, size.width, size.height, opaque, highBitDepth);
33
45
  }
34
46
  }), [nativeId, opaque, highBitDepth]);
35
- return /*#__PURE__*/React.createElement(SkiaGraphiteViewNativeComponent, _extends({
47
+ return /*#__PURE__*/React.createElement(SkiaViewNativeComponent, _extends({
36
48
  ref: viewRef,
37
49
  collapsable: false,
38
50
  nativeID: `${nativeId}`,
39
- debug: debug,
40
51
  opaque: opaque,
41
52
  highBitDepth: highBitDepth
42
- }, viewProps));
53
+ }, androidNativeProps(android), viewProps));
43
54
  };
44
55
  const assertSkiaViewApi = () => {
45
56
  if (SkiaViewApi === null || SkiaViewApi.makeGraphiteContext === null) {
@@ -1 +1 @@
1
- {"version":3,"names":["React","useImperativeHandle","useMemo","useRef","SkiaGraphiteViewNativeComponent","SkiaViewApi","SkiaViewNativeId","SkiaGraphiteView","debug","opaque","highBitDepth","ref","viewProps","nativeId","current","viewRef","getNativeId","getContext","assertSkiaViewApi","view","Error","size","getBoundingClientRect","unstable_getBoundingClientRect","makeGraphiteContext","width","height","createElement","_extends","collapsable","nativeID"],"sources":["SkiaGraphiteView.tsx"],"sourcesContent":["import React, { useImperativeHandle, useMemo, useRef } from \"react\";\n\nimport type { SkGraphiteContext } from \"../skia/types\";\nimport SkiaGraphiteViewNativeComponent from \"../specs/SkiaGraphiteViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaGraphiteViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nexport interface SkiaGraphiteViewRef {\n /**\n * The recording side of the view. Call it once the view is mounted. The\n * returned context can be captured into worklets and used from any runtime.\n */\n getContext(): SkGraphiteContext;\n getNativeId(): number;\n}\n\nexport interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {\n ref?: React.Ref<SkiaGraphiteViewRef>;\n}\n\n/**\n * A view presenting frames recorded with Skia Graphite. Requires the Graphite\n * backend (install-skia-graphite); with the default backend it renders\n * nothing. See {@link SkGraphiteContext}.\n */\nexport const SkiaGraphiteView = ({\n debug = false,\n opaque = false,\n highBitDepth = false,\n ref,\n ...viewProps\n}: SkiaGraphiteViewProps) => {\n const nativeId = useMemo(() => SkiaViewNativeId.current++, []);\n const viewRef =\n useRef<React.ComponentRef<typeof SkiaGraphiteViewNativeComponent>>(null);\n useImperativeHandle(\n ref,\n () => ({\n getNativeId: () => nativeId,\n getContext: () => {\n assertSkiaViewApi();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const view = viewRef.current as any;\n if (!view) {\n throw new Error(\n \"SkiaGraphiteView: getContext() was called before the view was mounted.\"\n );\n }\n // The layout is known synchronously on the new architecture;\n // getBoundingClientRect became stable in React Native 0.83.\n const size =\n \"getBoundingClientRect\" in view\n ? view.getBoundingClientRect()\n : view.unstable_getBoundingClientRect();\n return SkiaViewApi.makeGraphiteContext(\n nativeId,\n size.width,\n size.height,\n opaque,\n highBitDepth\n );\n },\n }),\n [nativeId, opaque, highBitDepth]\n );\n return (\n <SkiaGraphiteViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n highBitDepth={highBitDepth}\n {...viewProps}\n />\n );\n};\n\nconst assertSkiaViewApi = () => {\n if (SkiaViewApi === null || SkiaViewApi.makeGraphiteContext === null) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAGnE,OAAOC,+BAA+B,MAAM,0CAA0C;AAEtF,SAASC,WAAW,QAAQ,OAAO;AAEnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAerD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,KAAK,GAAG,KAAK;EACbC,MAAM,GAAG,KAAK;EACdC,YAAY,GAAG,KAAK;EACpBC,GAAG;EACH,GAAGC;AACkB,CAAC,KAAK;EAC3B,MAAMC,QAAQ,GAAGX,OAAO,CAAC,MAAMI,gBAAgB,CAACQ,OAAO,EAAE,EAAE,EAAE,CAAC;EAC9D,MAAMC,OAAO,GACXZ,MAAM,CAA6D,IAAI,CAAC;EAC1EF,mBAAmB,CACjBU,GAAG,EACH,OAAO;IACLK,WAAW,EAAEA,CAAA,KAAMH,QAAQ;IAC3BI,UAAU,EAAEA,CAAA,KAAM;MAChBC,iBAAiB,CAAC,CAAC;MACnB;MACA,MAAMC,IAAI,GAAGJ,OAAO,CAACD,OAAc;MACnC,IAAI,CAACK,IAAI,EAAE;QACT,MAAM,IAAIC,KAAK,CACb,wEACF,CAAC;MACH;MACA;MACA;MACA,MAAMC,IAAI,GACR,uBAAuB,IAAIF,IAAI,GAC3BA,IAAI,CAACG,qBAAqB,CAAC,CAAC,GAC5BH,IAAI,CAACI,8BAA8B,CAAC,CAAC;MAC3C,OAAOlB,WAAW,CAACmB,mBAAmB,CACpCX,QAAQ,EACRQ,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MAAM,EACXjB,MAAM,EACNC,YACF,CAAC;IACH;EACF,CAAC,CAAC,EACF,CAACG,QAAQ,EAAEJ,MAAM,EAAEC,YAAY,CACjC,CAAC;EACD,oBACEV,KAAA,CAAA2B,aAAA,CAACvB,+BAA+B,EAAAwB,QAAA;IAC9BjB,GAAG,EAAEI,OAAQ;IACbc,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGjB,QAAQ,EAAG;IACxBL,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfC,YAAY,EAAEA;EAAa,GACvBE,SAAS,CACd,CAAC;AAEN,CAAC;AAED,MAAMM,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IAAIb,WAAW,KAAK,IAAI,IAAIA,WAAW,CAACmB,mBAAmB,KAAK,IAAI,EAAE;IACpE,MAAMJ,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useImperativeHandle","useMemo","useRef","SkiaViewNativeComponent","Platform","SkiaViewApi","androidNativeProps","SkiaViewNativeId","measureLayout","view","OS","width","height","host","getBoundingClientRect","unstable_getBoundingClientRect","SkiaGraphiteView","opaque","highBitDepth","android","ref","viewProps","nativeId","current","viewRef","getNativeId","getContext","assertSkiaViewApi","Error","size","makeGraphiteContext","createElement","_extends","collapsable","nativeID"],"sources":["SkiaGraphiteView.tsx"],"sourcesContent":["import React, { useImperativeHandle, useMemo, useRef } from \"react\";\n\nimport type { SkGraphiteContext } from \"../skia/types\";\nimport SkiaViewNativeComponent from \"../specs/SkiaViewNativeComponent\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaViewApi } from \"./api\";\nimport { androidNativeProps } from \"./android\";\nimport type { SkiaGraphiteViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nexport interface SkiaGraphiteViewRef {\n /**\n * The recording side of the view. Call it once the view is mounted. The\n * returned context can be captured into worklets and used from any runtime.\n */\n getContext(): SkGraphiteContext;\n getNativeId(): number;\n}\n\nexport interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {\n ref?: React.Ref<SkiaGraphiteViewRef>;\n}\n\n// The layout is known synchronously on the new architecture;\n// getBoundingClientRect became stable in React Native 0.83. On the web the\n// view measures itself (see SkiaView.web).\nconst measureLayout = (view: unknown) => {\n if (Platform.OS === \"web\") {\n return { width: 0, height: 0 };\n }\n const host = view as {\n getBoundingClientRect?: () => { width: number; height: number };\n unstable_getBoundingClientRect: () => { width: number; height: number };\n };\n return host.getBoundingClientRect\n ? host.getBoundingClientRect()\n : host.unstable_getBoundingClientRect();\n};\n\n/**\n * A view whose frames are recorded from JavaScript, on any runtime, through\n * the context of its ref. See {@link SkGraphiteContext}.\n */\nexport const SkiaGraphiteView = ({\n opaque = false,\n highBitDepth = false,\n android,\n ref,\n ...viewProps\n}: SkiaGraphiteViewProps) => {\n const nativeId = useMemo(() => SkiaViewNativeId.current++, []);\n const viewRef =\n useRef<React.ComponentRef<typeof SkiaViewNativeComponent>>(null);\n useImperativeHandle(\n ref,\n () => ({\n getNativeId: () => nativeId,\n getContext: () => {\n assertSkiaViewApi();\n const view = viewRef.current;\n if (!view) {\n throw new Error(\n \"SkiaGraphiteView: getContext() was called before the view was mounted.\"\n );\n }\n const size = measureLayout(view);\n return SkiaViewApi.makeGraphiteContext(\n nativeId,\n size.width,\n size.height,\n opaque,\n highBitDepth\n );\n },\n }),\n [nativeId, opaque, highBitDepth]\n );\n return (\n <SkiaViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n opaque={opaque}\n highBitDepth={highBitDepth}\n {...androidNativeProps(android)}\n {...viewProps}\n />\n );\n};\n\nconst assertSkiaViewApi = () => {\n if (SkiaViewApi === null || SkiaViewApi.makeGraphiteContext === null) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAGnE,OAAOC,uBAAuB,MAAM,kCAAkC;AACtE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,WAAW,QAAQ,OAAO;AACnC,SAASC,kBAAkB,QAAQ,WAAW;AAE9C,SAASC,gBAAgB,QAAQ,oBAAoB;AAerD;AACA;AACA;AACA,MAAMC,aAAa,GAAIC,IAAa,IAAK;EACvC,IAAIL,QAAQ,CAACM,EAAE,KAAK,KAAK,EAAE;IACzB,OAAO;MAAEC,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;EAChC;EACA,MAAMC,IAAI,GAAGJ,IAGZ;EACD,OAAOI,IAAI,CAACC,qBAAqB,GAC7BD,IAAI,CAACC,qBAAqB,CAAC,CAAC,GAC5BD,IAAI,CAACE,8BAA8B,CAAC,CAAC;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,MAAM,GAAG,KAAK;EACdC,YAAY,GAAG,KAAK;EACpBC,OAAO;EACPC,GAAG;EACH,GAAGC;AACkB,CAAC,KAAK;EAC3B,MAAMC,QAAQ,GAAGrB,OAAO,CAAC,MAAMM,gBAAgB,CAACgB,OAAO,EAAE,EAAE,EAAE,CAAC;EAC9D,MAAMC,OAAO,GACXtB,MAAM,CAAqD,IAAI,CAAC;EAClEF,mBAAmB,CACjBoB,GAAG,EACH,OAAO;IACLK,WAAW,EAAEA,CAAA,KAAMH,QAAQ;IAC3BI,UAAU,EAAEA,CAAA,KAAM;MAChBC,iBAAiB,CAAC,CAAC;MACnB,MAAMlB,IAAI,GAAGe,OAAO,CAACD,OAAO;MAC5B,IAAI,CAACd,IAAI,EAAE;QACT,MAAM,IAAImB,KAAK,CACb,wEACF,CAAC;MACH;MACA,MAAMC,IAAI,GAAGrB,aAAa,CAACC,IAAI,CAAC;MAChC,OAAOJ,WAAW,CAACyB,mBAAmB,CACpCR,QAAQ,EACRO,IAAI,CAAClB,KAAK,EACVkB,IAAI,CAACjB,MAAM,EACXK,MAAM,EACNC,YACF,CAAC;IACH;EACF,CAAC,CAAC,EACF,CAACI,QAAQ,EAAEL,MAAM,EAAEC,YAAY,CACjC,CAAC;EACD,oBACEnB,KAAA,CAAAgC,aAAA,CAAC5B,uBAAuB,EAAA6B,QAAA;IACtBZ,GAAG,EAAEI,OAAQ;IACbS,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGZ,QAAQ,EAAG;IACxBL,MAAM,EAAEA,MAAO;IACfC,YAAY,EAAEA;EAAa,GACvBZ,kBAAkB,CAACa,OAAO,CAAC,EAC3BE,SAAS,CACd,CAAC;AAEN,CAAC;AAED,MAAMM,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IAAItB,WAAW,KAAK,IAAI,IAAIA,WAAW,CAACyB,mBAAmB,KAAK,IAAI,EAAE;IACpE,MAAMF,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
@@ -3,8 +3,11 @@ import type { SkRect } from "../skia/types";
3
3
  import type { SkiaPictureViewNativeProps } from "./types";
4
4
  interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
5
5
  mode?: "default" | "continuous";
6
- androidWarmup?: boolean;
7
6
  }
7
+ /**
8
+ * A view showing a picture. The picture is handed to the native view, which
9
+ * records it once (and again on every redraw) for its surface.
10
+ */
8
11
  export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
9
12
  private requestId;
10
13
  constructor(props: SkiaPictureViewProps);