@shopify/react-native-skia 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +3 -3
  2. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +13 -8
  3. package/cpp/api/JsiNativeBuffer.h +43 -0
  4. package/cpp/api/JsiSkApi.h +3 -3
  5. package/cpp/api/JsiSkImageFactory.h +3 -3
  6. package/cpp/rnskia/RNSkPlatformContext.h +5 -5
  7. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +3 -3
  8. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +70 -93
  9. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +119 -0
  10. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +332 -0
  11. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +2 -1
  12. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +27 -6
  13. package/lib/commonjs/external/ModuleProxy.d.ts +10 -0
  14. package/lib/commonjs/external/ModuleProxy.js +36 -0
  15. package/lib/commonjs/external/ModuleProxy.js.map +1 -0
  16. package/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +3 -0
  17. package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
  18. package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
  19. package/lib/commonjs/external/reanimated/buffers.js +9 -6
  20. package/lib/commonjs/external/reanimated/buffers.js.map +1 -1
  21. package/lib/commonjs/external/reanimated/interpolators.js +8 -7
  22. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  23. package/lib/commonjs/external/reanimated/renderHelpers.js +27 -11
  24. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  25. package/lib/commonjs/external/reanimated/textures.js +4 -3
  26. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  27. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +6 -6
  28. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  29. package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js +6 -5
  30. package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js.map +1 -1
  31. package/lib/commonjs/renderer/Offscreen.js +1 -5
  32. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  33. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +8 -15
  34. package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -10
  35. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  36. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  37. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +13 -0
  38. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  39. package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +1 -0
  40. package/lib/commonjs/skia/types/NativeBuffer/index.js +17 -0
  41. package/lib/commonjs/skia/types/NativeBuffer/index.js.map +1 -0
  42. package/lib/commonjs/skia/types/Skia.d.ts +2 -2
  43. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  44. package/lib/commonjs/skia/types/index.d.ts +1 -1
  45. package/lib/commonjs/skia/types/index.js +4 -4
  46. package/lib/commonjs/skia/types/index.js.map +1 -1
  47. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +3 -2
  48. package/lib/commonjs/skia/web/JsiSkImageFactory.js +18 -2
  49. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  50. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  51. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +29 -0
  52. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  53. package/lib/commonjs/skia/web/JsiSkia.js +2 -2
  54. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  55. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +0 -2
  56. package/lib/commonjs/specs/NativeSkiaModule.web.js +0 -8
  57. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  58. package/lib/module/external/ModuleProxy.d.ts +10 -0
  59. package/lib/module/external/ModuleProxy.js +28 -0
  60. package/lib/module/external/ModuleProxy.js.map +1 -0
  61. package/lib/module/external/reanimated/ReanimatedProxy.d.ts +3 -0
  62. package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
  63. package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
  64. package/lib/module/external/reanimated/buffers.js +8 -6
  65. package/lib/module/external/reanimated/buffers.js.map +1 -1
  66. package/lib/module/external/reanimated/interpolators.js +7 -7
  67. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  68. package/lib/module/external/reanimated/renderHelpers.js +26 -11
  69. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  70. package/lib/module/external/reanimated/textures.js +3 -3
  71. package/lib/module/external/reanimated/textures.js.map +1 -1
  72. package/lib/module/external/reanimated/useAnimatedImageValue.js +5 -6
  73. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  74. package/lib/module/external/reanimated/useDerivedValueOnJS.js +5 -5
  75. package/lib/module/external/reanimated/useDerivedValueOnJS.js.map +1 -1
  76. package/lib/module/renderer/Offscreen.js +1 -5
  77. package/lib/module/renderer/Offscreen.js.map +1 -1
  78. package/lib/module/skia/types/Image/ImageFactory.d.ts +8 -15
  79. package/lib/module/skia/types/Image/ImageFactory.js +1 -10
  80. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  81. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  82. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +4 -0
  83. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  84. package/lib/module/skia/types/NativeBuffer/index.d.ts +1 -0
  85. package/lib/module/skia/types/NativeBuffer/index.js +2 -0
  86. package/lib/module/skia/types/NativeBuffer/index.js.map +1 -0
  87. package/lib/module/skia/types/Skia.d.ts +2 -2
  88. package/lib/module/skia/types/Skia.js.map +1 -1
  89. package/lib/module/skia/types/index.d.ts +1 -1
  90. package/lib/module/skia/types/index.js +1 -1
  91. package/lib/module/skia/types/index.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkImageFactory.d.ts +3 -2
  93. package/lib/module/skia/web/JsiSkImageFactory.js +18 -2
  94. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  95. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  96. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +22 -0
  97. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  98. package/lib/module/skia/web/JsiSkia.js +2 -2
  99. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  100. package/lib/module/specs/NativeSkiaModule.web.d.ts +0 -2
  101. package/lib/module/specs/NativeSkiaModule.web.js +0 -3
  102. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  103. package/lib/typescript/src/external/ModuleProxy.d.ts +10 -0
  104. package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +3 -0
  105. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +8 -15
  106. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  107. package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +1 -0
  108. package/lib/typescript/src/skia/types/Skia.d.ts +2 -2
  109. package/lib/typescript/src/skia/types/index.d.ts +1 -1
  110. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +3 -2
  111. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  112. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +0 -2
  113. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  114. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  115. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  116. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  117. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  118. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  119. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  120. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  121. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  122. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  123. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  124. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  125. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  126. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  127. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  128. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  129. package/package.json +1 -1
  130. package/src/external/ModuleProxy.ts +30 -0
  131. package/src/external/reanimated/ReanimatedProxy.ts +18 -0
  132. package/src/external/reanimated/buffers.ts +7 -6
  133. package/src/external/reanimated/interpolators.ts +7 -12
  134. package/src/external/reanimated/renderHelpers.ts +31 -18
  135. package/src/external/reanimated/textures.tsx +3 -3
  136. package/src/external/reanimated/useAnimatedImageValue.ts +5 -10
  137. package/src/external/reanimated/useDerivedValueOnJS.ts +5 -10
  138. package/src/renderer/Offscreen.tsx +1 -7
  139. package/src/skia/types/Image/ImageFactory.ts +7 -23
  140. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +38 -0
  141. package/src/skia/types/NativeBuffer/index.ts +1 -0
  142. package/src/skia/types/Skia.ts +2 -2
  143. package/src/skia/types/index.ts +1 -1
  144. package/src/skia/web/JsiSkImageFactory.ts +28 -6
  145. package/src/skia/web/JsiSkNativeBufferFactory.ts +35 -0
  146. package/src/skia/web/JsiSkia.ts +2 -2
  147. package/src/specs/NativeSkiaModule.web.ts +0 -4
  148. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerDelegate.java +0 -34
  149. package/cpp/api/JsiPlatformBuffer.h +0 -51
  150. package/cpp/skia/include/gpu/GrBackendDrawableInfo.h +0 -9
  151. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +0 -15
  152. package/lib/commonjs/external/reanimated/moduleWrapper.js +0 -46
  153. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +0 -1
  154. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  155. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js +0 -6
  156. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +0 -1
  157. package/lib/commonjs/skia/types/PlatformBuffer/index.d.ts +0 -1
  158. package/lib/commonjs/skia/types/PlatformBuffer/index.js +0 -17
  159. package/lib/commonjs/skia/types/PlatformBuffer/index.js.map +0 -1
  160. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  161. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js +0 -20
  162. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js.map +0 -1
  163. package/lib/module/external/reanimated/moduleWrapper.d.ts +0 -15
  164. package/lib/module/external/reanimated/moduleWrapper.js +0 -37
  165. package/lib/module/external/reanimated/moduleWrapper.js.map +0 -1
  166. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  167. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js +0 -2
  168. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +0 -1
  169. package/lib/module/skia/types/PlatformBuffer/index.d.ts +0 -1
  170. package/lib/module/skia/types/PlatformBuffer/index.js +0 -2
  171. package/lib/module/skia/types/PlatformBuffer/index.js.map +0 -1
  172. package/lib/module/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  173. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js +0 -13
  174. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js.map +0 -1
  175. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +0 -15
  176. package/lib/typescript/src/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  177. package/lib/typescript/src/skia/types/PlatformBuffer/index.d.ts +0 -1
  178. package/lib/typescript/src/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  179. package/src/external/reanimated/moduleWrapper.ts +0 -83
  180. package/src/skia/types/PlatformBuffer/PlatformBufferFactory.ts +0 -14
  181. package/src/skia/types/PlatformBuffer/index.ts +0 -1
  182. package/src/skia/web/JsiSkPlatformBufferFactory.ts +0 -22
@@ -1 +1 @@
1
- {"version":3,"names":["startMapper","stopMapper","isSharedValue","HAS_REANIMATED3","HAS_REANIMATED2","runOnJS","_bindings","WeakMap","unbindReanimatedNode","node","previousMapperId","get","undefined","extractReanimatedProps","props","reanimatedProps","otherProps","propName","propValue","value","bindReanimatedProps2","container","sharedValues","Object","values","length","viewId","getNativeId","SkiaViewApi","global","updateProps","setProp","requestRedraw","redraw","mapperId","set","bindReanimatedProps"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport {\n startMapper,\n stopMapper,\n isSharedValue,\n HAS_REANIMATED3,\n HAS_REANIMATED2,\n runOnJS,\n} from \"./moduleWrapper\";\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport const unbindReanimatedNode = (node: Node<unknown>) => {\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId as number);\n }\n};\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED3 && !HAS_REANIMATED2) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nfunction bindReanimatedProps2(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const updateProps = () => {\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n };\n const mapperId = startMapper(() => {\n \"worklet\";\n runOnJS(updateProps)();\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (HAS_REANIMATED2 && !HAS_REANIMATED3) {\n return bindReanimatedProps2(container, node, reanimatedProps);\n }\n if (!HAS_REANIMATED3) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = startMapper(() => {\n \"worklet\";\n if (node) {\n for (const propName in reanimatedProps) {\n node.setProp(propName, reanimatedProps[propName].value);\n }\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":"AAAA;;AAMA,SACEA,WAAW,EACXC,UAAU,EACVC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,OAAO,QACF,iBAAiB;AAExB,MAAMC,SAAS,GAAG,IAAIC,OAAO,CAAyB,CAAC;AAEvD,OAAO,MAAMC,oBAAoB,GAAIC,IAAmB,IAAK;EAC3D,MAAMC,gBAAgB,GAAGJ,SAAS,CAACK,GAAG,CAACF,IAAI,CAAC;EAC5C,IAAIC,gBAAgB,KAAKE,SAAS,EAAE;IAClCX,UAAU,CAACS,gBAA0B,CAAC;EACxC;AACF,CAAC;AAED,OAAO,SAASG,sBAAsBA,CAACC,KAAyB,EAAE;EAChE,IAAI,CAACX,eAAe,IAAI,CAACC,eAAe,EAAE;IACxC,OAAO,CAACU,KAAK,EAAE,CAAC,CAAC,CAAC;EACpB;EACA,MAAMC,eAAe,GAAG,CAAC,CAAuB;EAChD,MAAMC,UAAU,GAAG,CAAC,CAAuB;EAC3C,KAAK,MAAMC,QAAQ,IAAIH,KAAK,EAAE;IAC5B,IAAIG,QAAQ,KAAK,UAAU,EAAE;MAC3B;IACF;IACA,MAAMC,SAAS,GAAGJ,KAAK,CAACG,QAAQ,CAAC;IACjC,IAAIf,aAAa,CAACgB,SAAS,CAAC,EAAE;MAC5BH,eAAe,CAACE,QAAQ,CAAC,GAAGC,SAAS;MACrCF,UAAU,CAACC,QAAQ,CAAC,GAAGC,SAAS,CAACC,KAAK;IACxC,CAAC,MAAM;MACLH,UAAU,CAACC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EZ,IAAI,EAAEM,eAAe,CAAC;EAC/D;EACA,IAAI,CAACZ,eAAe,EAAE;IACpB;EACF;EACA,MAAMmB,YAAY,GAAGC,MAAM,CAACC,MAAM,CAACT,eAAe,CAAC;EACnD,MAAML,gBAAgB,GAAGJ,SAAS,CAACK,GAAG,CAACF,IAAI,CAAC;EAC5C,IAAIC,gBAAgB,KAAKE,SAAS,EAAE;IAClCX,UAAU,CAACS,gBAA0B,CAAC;EACxC;EACA,IAAIY,YAAY,CAACG,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAMC,MAAM,GAAGL,SAAS,CAACM,WAAW,CAAC,CAAC;IACtC,MAAM;MAAEC;IAAY,CAAC,GAAGC,MAAM;IAC9B,MAAMK,QAAQ,GAAGlC,WAAW,CAAC,MAAM;MACjC,SAAS;;MACT,IAAIS,IAAI,EAAE;QACR,KAAK,MAAMQ,QAAQ,IAAIF,eAAe,EAAE;UACtCN,IAAI,CAACsB,OAAO,CAACd,QAAQ,EAAEF,eAAe,CAACE,QAAQ,CAAC,CAACE,KAAK,CAAC;QACzD;MACF;MACA;MACA;MACA;MACA;MACA,IAAIS,WAAW,EAAE;QACfA,WAAW,CAACI,aAAa,CAACN,MAAM,CAAC;MACnC,CAAC,MAAM;QACLL,SAAS,CAACY,MAAM,CAAC,CAAC;MACpB;IACF,CAAC,EAAEX,YAAY,CAAC;IAChBhB,SAAS,CAAC6B,GAAG,CAAC1B,IAAI,EAAEyB,QAAQ,CAAC;EAC/B;AACF"}
1
+ {"version":3,"names":["Rea","HAS_REANIMATED","HAS_REANIMATED_3","require","reanimatedVersion","version","includes","e","_bindings","WeakMap","unbindReanimatedNode","node","previousMapperId","get","undefined","stopMapper","extractReanimatedProps","props","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps2","container","sharedValues","Object","values","length","viewId","getNativeId","SkiaViewApi","global","updateProps","setProp","requestRedraw","redraw","mapperId","startMapper","runOnJS","set","bindReanimatedProps"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nlet HAS_REANIMATED = false;\nlet HAS_REANIMATED_3 = false;\ntry {\n require(\"react-native-reanimated\");\n HAS_REANIMATED = true;\n const reanimatedVersion =\n require(\"react-native-reanimated/package.json\").version;\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n HAS_REANIMATED_3 = true;\n }\n} catch (e) {\n HAS_REANIMATED = false;\n}\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport const unbindReanimatedNode = (node: Node<unknown>) => {\n if (!HAS_REANIMATED) {\n return;\n }\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n};\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (Rea.isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nfunction bindReanimatedProps2(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const updateProps = () => {\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n };\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n Rea.runOnJS(updateProps)();\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (HAS_REANIMATED && !HAS_REANIMATED_3) {\n return bindReanimatedProps2(container, node, reanimatedProps);\n }\n if (!HAS_REANIMATED) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n if (node) {\n for (const propName in reanimatedProps) {\n node.setProp(propName, reanimatedProps[propName].value);\n }\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":"AAAA;;AAMA,OAAOA,GAAG,MAAM,mBAAmB;AAEnC,IAAIC,cAAc,GAAG,KAAK;AAC1B,IAAIC,gBAAgB,GAAG,KAAK;AAC5B,IAAI;EACFC,OAAO,CAAC,yBAAyB,CAAC;EAClCF,cAAc,GAAG,IAAI;EACrB,MAAMG,iBAAiB,GACrBD,OAAO,CAAC,sCAAsC,CAAC,CAACE,OAAO;EACzD,IACED,iBAAiB,KAChBA,iBAAiB,IAAI,OAAO,IAAIA,iBAAiB,CAACE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACtE;IACAJ,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gB,KAAKE,SAAS,EAAE;IAClCd,GAAG,CAACe,UAAU,CAACH,gBAA0B,CAAC;EAC5C;EACA,IAAIc,YAAY,CAACG,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAMC,MAAM,GAAGL,SAAS,CAACM,WAAW,CAAC,CAAC;IACtC,MAAM;MAAEC;IAAY,CAAC,GAAGC,MAAM;IAC9B,MAAMK,QAAQ,GAAGtC,GAAG,CAACuC,WAAW,CAAC,MAAM;MACrC,SAAS;;MACT,IAAI5B,IAAI,EAAE;QACR,KAAK,MAAMS,QAAQ,IAAIF,eAAe,EAAE;UACtCP,IAAI,CAACwB,OAAO,CAACf,QAAQ,EAAEF,eAAe,CAACE,QAAQ,CAAC,CAACG,KAAK,CAAC;QACzD;MACF;MACA;MACA;MACA;MACA;MACA,IAAIS,WAAW,EAAE;QACfA,WAAW,CAACI,aAAa,CAACN,MAAM,CAAC;MACnC,CAAC,MAAM;QACLL,SAAS,CAACY,MAAM,CAAC,CAAC;MACpB;IACF,CAAC,EAAEX,YAAY,CAAC;IAChBlB,SAAS,CAACiC,GAAG,CAAC9B,IAAI,EAAE2B,QAAQ,CAAC;EAC/B;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useMemo } from "react";
2
2
  import { drawAsImageFromPicture, drawAsPicture } from "../../renderer/Offscreen";
3
3
  import { Skia, useImage } from "../../skia";
4
- import { runOnUI, useSharedValue } from "./moduleWrapper";
4
+ import Rea from "./ReanimatedProxy";
5
5
  const createTexture = (texture, picture, size) => {
6
6
  "worklet";
7
7
 
@@ -31,10 +31,10 @@ export const useTextureValueFromPicture = (picture, size) => {
31
31
  return usePictureAsTexture(picture, size);
32
32
  };
33
33
  export const usePictureAsTexture = (picture, size) => {
34
- const texture = useSharedValue(null);
34
+ const texture = Rea.useSharedValue(null);
35
35
  useEffect(() => {
36
36
  if (picture !== null) {
37
- runOnUI(createTexture)(texture, picture, size);
37
+ Rea.runOnUI(createTexture)(texture, picture, size);
38
38
  }
39
39
  }, [texture, picture, size]);
40
40
  return texture;
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useMemo","drawAsImageFromPicture","drawAsPicture","Skia","useImage","runOnUI","useSharedValue","createTexture","texture","picture","size","value","useTexture","element","width","height","x","y","usePictureAsTexture","useTextureAsValue","console","warn","useTextureValueFromPicture","useImageAsTexture","source","image","recorder","PictureRecorder","canvas","beginRecording","drawImage","finishRecordingAsPicture"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport {\n drawAsImageFromPicture,\n drawAsPicture,\n} from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\n\nimport { runOnUI, useSharedValue } from \"./moduleWrapper\";\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n texture.value = drawAsImageFromPicture(picture, size);\n};\n\nexport const useTexture = (element: ReactElement, size: SkSize) => {\n const { width, height } = size;\n const picture = useMemo(() => {\n return drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n });\n }, [element, width, height]);\n return usePictureAsTexture(picture, size);\n};\n\nexport const useTextureAsValue = (element: ReactElement, size: SkSize) => {\n console.warn(\"useTextureAsValue has been renamed to use useTexture\");\n return useTexture(element, size);\n};\n\nexport const useTextureValueFromPicture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n console.warn(\n \"useTextureValueFromPicture has been renamed to use usePictureAsTexture\"\n );\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n runOnUI(createTexture)(texture, picture, size);\n }\n }, [texture, picture, size]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const size = useMemo(() => {\n if (image) {\n return { width: image.width(), height: image.height() };\n }\n return { width: 0, height: 0 };\n }, [image]);\n const picture = useMemo(() => {\n if (image) {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording({\n x: 0,\n y: 0,\n width: size.width,\n height: size.height,\n });\n canvas.drawImage(image, 0, 0);\n return recorder.finishRecordingAsPicture();\n } else {\n return null;\n }\n }, [size, image]);\n return usePictureAsTexture(picture, size);\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAU1C,SACEC,sBAAsB,EACtBC,aAAa,QACR,0BAA0B;AACjC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAE3C,SAASC,OAAO,EAAEC,cAAc,QAAQ,iBAAiB;AAEzD,MAAMC,aAAa,GAAGA,CACpBC,OAAoC,EACpCC,OAAkB,EAClBC,IAAY,KACT;EACH,SAAS;;EACTF,OAAO,CAACG,KAAK,GAAGV,sBAAsB,CAACQ,OAAO,EAAEC,IAAI,CAAC;AACvD,CAAC;AAED,OAAO,MAAME,UAAU,GAAGA,CAACC,OAAqB,EAAEH,IAAY,KAAK;EACjE,MAAM;IAAEI,KAAK;IAAEC;EAAO,CAAC,GAAGL,IAAI;EAC9B,MAAMD,OAAO,GAAGT,OAAO,CAAC,MAAM;IAC5B,OAAOE,aAAa,CAACW,OAAO,EAAE;MAC5BG,CAAC,EAAE,CAAC;MACJC,CAAC,EAAE,CAAC;MACJH,KAAK;MACLC;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAACF,OAAO,EAAEC,KAAK,EAAEC,MAAM,CAAC,CAAC;EAC5B,OAAOG,mBAAmB,CAACT,OAAO,EAAEC,IAAI,CAAC;AAC3C,CAAC;AAED,OAAO,MAAMS,iBAAiB,GAAGA,CAACN,OAAqB,EAAEH,IAAY,KAAK;EACxEU,OAAO,CAACC,IAAI,CAAC,sDAAsD,CAAC;EACpE,OAAOT,UAAU,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EJ,IAAI,CAACI,KAAK;QACjBC,MAAM,EAAEL,IAAI,CAACK;MACf,CAAC,CAAC;MACFa,MAAM,CAACE,SAAS,CAACL,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;MAC7B,OAAOC,QAAQ,CAACK,wBAAwB,CAAC,CAAC;IAC5C,CAAC,MAAM;MACL,OAAO,IAAI;IACb;EACF,CAAC,EAAE,CAACrB,IAAI,EAAEe,KAAK,CAAC,CAAC;EACjB,OAAOP,mBAAmB,CAACT,OAAO,EAAEC,IAAI,CAAC;AAC3C,CAAC"}
1
+ {"version":3,"names":["useEffect","useMemo","drawAsImageFromPicture","drawAsPicture","Skia","useImage","Rea","createTexture","texture","picture","size","value","useTexture","element","width","height","x","y","usePictureAsTexture","useTextureAsValue","console","warn","useTextureValueFromPicture","useSharedValue","runOnUI","useImageAsTexture","source","image","recorder","PictureRecorder","canvas","beginRecording","drawImage","finishRecordingAsPicture"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport {\n drawAsImageFromPicture,\n drawAsPicture,\n} from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n texture.value = drawAsImageFromPicture(picture, size);\n};\n\nexport const useTexture = (element: ReactElement, size: SkSize) => {\n const { width, height } = size;\n const picture = useMemo(() => {\n return drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n });\n }, [element, width, height]);\n return usePictureAsTexture(picture, size);\n};\n\nexport const useTextureAsValue = (element: ReactElement, size: SkSize) => {\n console.warn(\"useTextureAsValue has been renamed to use useTexture\");\n return useTexture(element, size);\n};\n\nexport const useTextureValueFromPicture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n console.warn(\n \"useTextureValueFromPicture has been renamed to use usePictureAsTexture\"\n );\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = Rea.useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n Rea.runOnUI(createTexture)(texture, picture, size);\n }\n }, [texture, picture, size]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const size = useMemo(() => {\n if (image) {\n return { width: image.width(), height: image.height() };\n }\n return { width: 0, height: 0 };\n }, [image]);\n const picture = useMemo(() => {\n if (image) {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording({\n x: 0,\n y: 0,\n width: size.width,\n height: size.height,\n });\n canvas.drawImage(image, 0, 0);\n return recorder.finishRecordingAsPicture();\n } else {\n return null;\n }\n }, [size, image]);\n return usePictureAsTexture(picture, size);\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAU1C,SACEC,sBAAsB,EACtBC,aAAa,QACR,0BAA0B;AACjC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAE3C,OAAOC,GAAG,MAAM,mBAAmB;AAEnC,MAAMC,aAAa,GAAGA,CACpBC,OAAoC,EACpCC,OAAkB,EAClBC,IAAY,KACT;EACH,SAAS;;EACTF,OAAO,CAACG,KAAK,GAAGT,sBAAsB,CAACO,OAAO,EAAEC,IAAI,CAAC;AACvD,CAAC;AAED,OAAO,MAAME,UAAU,GAAGA,CAACC,OAAqB,EAAEH,IAAY,KAAK;EACjE,MAAM;IAAEI,KAAK;IAAEC;EAAO,CAAC,GAAGL,IAAI;EAC9B,MAAMD,OAAO,GAAGR,OAAO,CAAC,MAAM;IAC5B,OAAOE,aAAa,CAACU,OAAO,EAAE;MAC5BG,CAAC,EAAE,CAAC;MACJC,CAAC,EAAE,CAAC;MACJ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E,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;EAChC,CAAC,EAAE,CAACY,KAAK,CAAC,CAAC;EACX,MAAMlB,OAAO,GAAGR,OAAO,CAAC,MAAM;IAC5B,IAAI0B,KAAK,EAAE;MACT,MAAMC,QAAQ,GAAGxB,IAAI,CAACyB,eAAe,CAAC,CAAC;MACvC,MAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAc,CAAC;QACrCf,CAAC,EAAE,CAAC;QACJC,CAAC,EAAE,CAAC;QACJH,KAAK,EAAEJ,IAAI,CAACI,KAAK;QACjBC,MAAM,EAAEL,IAAI,CAACK;MACf,CAAC,CAAC;MACFe,MAAM,CAACE,SAAS,CAACL,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;MAC7B,OAAOC,QAAQ,CAACK,wBAAwB,CAAC,CAAC;IAC5C,CAAC,MAAM;MACL,OAAO,IAAI;IACb;EACF,CAAC,EAAE,CAACvB,IAAI,EAAEiB,KAAK,CAAC,CAAC;EACjB,OAAOT,mBAAmB,CAACT,OAAO,EAAEC,IAAI,CAAC;AAC3C,CAAC"}
@@ -1,19 +1,18 @@
1
1
  import { useEffect } from "react";
2
2
  import { useAnimatedImage } from "../../skia/core/AnimatedImage";
3
- import { throwOnMissingReanimated, useFrameCallback, useSharedValue } from "./moduleWrapper";
3
+ import Rea from "./ReanimatedProxy";
4
4
  const DEFAULT_FRAME_DURATION = 60;
5
5
  export const useAnimatedImageValue = (source, paused) => {
6
- throwOnMissingReanimated();
7
- const defaultPaused = useSharedValue(false);
6
+ const defaultPaused = Rea.useSharedValue(false);
8
7
  const isPaused = paused !== null && paused !== void 0 ? paused : defaultPaused;
9
- const currentFrame = useSharedValue(null);
10
- const lastTimestamp = useSharedValue(-1);
8
+ const currentFrame = Rea.useSharedValue(null);
9
+ const lastTimestamp = Rea.useSharedValue(-1);
11
10
  const animatedImage = useAnimatedImage(source, err => {
12
11
  console.error(err);
13
12
  throw new Error(`Could not load animated image - got '${err.message}'`);
14
13
  }, false);
15
14
  const frameDuration = (animatedImage === null || animatedImage === void 0 ? void 0 : animatedImage.currentFrameDuration()) || DEFAULT_FRAME_DURATION;
16
- useFrameCallback(frameInfo => {
15
+ Rea.useFrameCallback(frameInfo => {
17
16
  if (!animatedImage) {
18
17
  currentFrame.value = null;
19
18
  return;
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useAnimatedImage","throwOnMissingReanimated","useFrameCallback","useSharedValue","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","isPaused","currentFrame","lastTimestamp","animatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { type FrameInfo, type SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport {\n throwOnMissingReanimated,\n useFrameCallback,\n useSharedValue,\n} from \"./moduleWrapper\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n throwOnMissingReanimated();\n const defaultPaused = useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = useSharedValue<null | SkImage>(null);\n const lastTimestamp = useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAGjC,SAASC,gBAAgB,QAAQ,+BAA+B;AAGhE,SACEC,wBAAwB,EACxBC,gBAAgB,EAChBC,cAAc,QACT,iBAAiB;AAExB,MAAMC,sBAAsB,GAAG,EAAE;AAEjC,OAAO,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACHN,wBAAwB,CAAC,CAAC;EAC1B,MAAMO,aAAa,GAAGL,cAAc,CAAC,KAAK,CAAC;EAC3C,MAAMM,QAAQ,GAAGF,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIC,aAAa;EACxC,MAAME,YAAY,GAAGP,cAAc,CAAiB,IAAI,CAAC;EACzD,MAAMQ,aAAa,GAAGR,cAAc,CAAC,CAAC,CAAC,CAAC;EACxC,MAAMS,aAAa,GAAGZ,gBAAgB,CACpCM,MAAM,EACLO,GAAG,IAAK;IACPC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,MAAM,IAAIG,KAAK,CAAE,wCAAuCH,GAAG,CAACI,OAAQ,GAAE,CAAC;EACzE,CAAC,EACD,KACF,CAAC;EACD,MAAMC,aAAa,GACjB,CAAAN,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEO,oBAAoB,CAAC,CAAC,KAAIf,sBAAsB;EAEjEF,gBAAgB,CAAEkB,SAAoB,IAAK;IACzC,IAAI,CAACR,aAAa,EAAE;MAClBF,YAAY,CAACW,KAAK,GAAG,IAAI;MACzB;IACF;IACA,IAAIZ,QAAQ,CAACY,KAAK,IAAIV,aAAa,CAACU,KAAK,KAAK,CAAC,CAAC,EAAE;MAChD;IACF;IACA,MAAM;MAAEC;IAAU,CAAC,GAAGF,SAAS;IAC/B,MAAMG,OAAO,GAAGD,SAAS,GAAGX,aAAa,CAACU,KAAK;;IAE/C;IACA,IAAIE,OAAO,GAAGL,aAAa,EAAE;MAC3B;IACF;;IAEA;IACAN,aAAa,CAACY,eAAe,CAAC,CAAC;IAC/B,IAAId,YAAY,CAACW,KAAK,EAAE;MACtBX,YAAY,CAACW,KAAK,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAf,YAAY,CAACW,KAAK,GAAGT,aAAa,CAACc,eAAe,CAAC,CAAC;;IAEpD;IACAf,aAAa,CAACU,KAAK,GAAGC,SAAS;EACjC,CAAC,CAAC;EACFvB,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXa,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEa,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAOf,YAAY;AACrB,CAAC"}
1
+ {"version":3,"names":["useEffect","useAnimatedImage","Rea","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { type FrameInfo, type SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAGjC,SAASC,gBAAgB,QAAQ,+BAA+B;AAGhE,OAAOC,GAAG,MAAM,mBAAmB;AAEnC,MAAMC,sBAAsB,GAAG,EAAE;AAEjC,OAAO,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACH,MAAMC,aAAa,GAAGL,GAAG,CAACM,cAAc,CAAC,KAAK,CAAC;EAC/C,MAAMC,QAAQ,GAAGH,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIC,aAAa;EACxC,MAAMG,YAAY,GAAGR,GAAG,CAACM,cAAc,CAAiB,IAAI,CAAC;EAC7D,MAAMG,aAAa,GAAGT,GAAG,CAACM,cAAc,CAAC,CAAC,CAAC,CAAC;EAC5C,MAAMI,aAAa,GAAGX,gBAAgB,CACpCI,MAAM,EACLQ,GAAG,IAAK;IACPC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,MAAM,IAAIG,KAAK,CAAE,wCAAuCH,GAAG,CAACI,OAAQ,GAAE,CAAC;EACzE,CAAC,EACD,KACF,CAAC;EACD,MAAMC,aAAa,GACjB,CAAAN,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEO,oBAAoB,CAAC,CAAC,KAAIhB,sBAAsB;EAEjED,GAAG,CAACkB,gBAAgB,CAAEC,SAAoB,IAAK;IAC7C,IAAI,CAACT,aAAa,EAAE;MAClBF,YAAY,CAACY,KAAK,GAAG,IAAI;MACzB;IACF;IACA,IAAIb,QAAQ,CAACa,KAAK,IAAIX,aAAa,CAACW,KAAK,KAAK,CAAC,CAAC,EAAE;MAChD;IACF;IACA,MAAM;MAAEC;IAAU,CAAC,GAAGF,SAAS;IAC/B,MAAMG,OAAO,GAAGD,SAAS,GAAGZ,aAAa,CAACW,KAAK;;IAE/C;IACA,IAAIE,OAAO,GAAGN,aAAa,EAAE;MAC3B;IACF;;IAEA;IACAN,aAAa,CAACa,eAAe,CAAC,CAAC;IAC/B,IAAIf,YAAY,CAACY,KAAK,EAAE;MACtBZ,YAAY,CAACY,KAAK,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAhB,YAAY,CAACY,KAAK,GAAGV,aAAa,CAACe,eAAe,CAAC,CAAC;;IAEpD;IACAhB,aAAa,CAACW,KAAK,GAAGC,SAAS;EACjC,CAAC,CAAC;EACFvB,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXY,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEc,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAOhB,YAAY;AACrB,CAAC"}
@@ -1,15 +1,15 @@
1
1
  import { useEffect, useMemo } from "react";
2
- import { useSharedValue, runOnJS, startMapper, stopMapper } from "./moduleWrapper";
2
+ import Rea from "./ReanimatedProxy";
3
3
  export const useDerivedValueOnJS = (fn, deps) => {
4
4
  const init = useMemo(() => fn(), [fn]);
5
- const value = useSharedValue(init);
5
+ const value = Rea.useSharedValue(init);
6
6
  useEffect(() => {
7
- const mapperId = startMapper(() => {
7
+ const mapperId = Rea.startMapper(() => {
8
8
  "worklet";
9
9
 
10
- runOnJS(fn)();
10
+ Rea.runOnJS(fn)();
11
11
  }, deps);
12
- return () => stopMapper(mapperId);
12
+ return () => Rea.stopMapper(mapperId);
13
13
  }, [deps, fn]);
14
14
  return value;
15
15
  };
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useMemo","useSharedValue","runOnJS","startMapper","stopMapper","useDerivedValueOnJS","fn","deps","init","value","mapperId"],"sources":["useDerivedValueOnJS.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\n\nimport {\n useSharedValue,\n runOnJS,\n startMapper,\n stopMapper,\n} from \"./moduleWrapper\";\n\nexport const useDerivedValueOnJS = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fn: () => any,\n deps: unknown[]\n) => {\n const init = useMemo(() => fn(), [fn]);\n const value = useSharedValue(init);\n useEffect(() => {\n const mapperId = startMapper(() => {\n \"worklet\";\n runOnJS(fn)();\n }, deps);\n return () => stopMapper(mapperId);\n }, [deps, fn]);\n return value;\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAE1C,SACEC,cAAc,EACdC,OAAO,EACPC,WAAW,EACXC,UAAU,QACL,iBAAiB;AAExB,OAAO,MAAMC,mBAAmB,GAAGA,CAEjCC,EAAa,EACbC,IAAe,KACZ;EACH,MAAMC,IAAI,GAAGR,OAAO,CAAC,MAAMM,EAAE,CAAC,CAAC,EAAE,CAACA,EAAE,CAAC,CAAC;EACtC,MAAMG,KAAK,GAAGR,cAAc,CAACO,IAAI,CAAC;EAClCT,SAAS,CAAC,MAAM;IACd,MAAMW,QAAQ,GAAGP,WAAW,CAAC,MAAM;MACjC,SAAS;;MACTD,OAAO,CAACI,EAAE,CAAC,CAAC,CAAC;IACf,CAAC,EAAEC,IAAI,CAAC;IACR,OAAO,MAAMH,UAAU,CAACM,QAAQ,CAAC;EACnC,CAAC,EAAE,CAACH,IAAI,EAAED,EAAE,CAAC,CAAC;EACd,OAAOG,KAAK;AACd,CAAC"}
1
+ {"version":3,"names":["useEffect","useMemo","Rea","useDerivedValueOnJS","fn","deps","init","value","useSharedValue","mapperId","startMapper","runOnJS","stopMapper"],"sources":["useDerivedValueOnJS.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nexport const useDerivedValueOnJS = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fn: () => any,\n deps: unknown[]\n) => {\n const init = useMemo(() => fn(), [fn]);\n const value = Rea.useSharedValue(init);\n useEffect(() => {\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n Rea.runOnJS(fn)();\n }, deps);\n return () => Rea.stopMapper(mapperId);\n }, [deps, fn]);\n return value;\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAE1C,OAAOC,GAAG,MAAM,mBAAmB;AAEnC,OAAO,MAAMC,mBAAmB,GAAGA,CAEjCC,EAAa,EACbC,IAAe,KACZ;EACH,MAAMC,IAAI,GAAGL,OAAO,CAAC,MAAMG,EAAE,CAAC,CAAC,EAAE,CAACA,EAAE,CAAC,CAAC;EACtC,MAAMG,KAAK,GAAGL,GAAG,CAACM,cAAc,CAACF,IAAI,CAAC;EACtCN,SAAS,CAAC,MAAM;IACd,MAAMS,QAAQ,GAAGP,GAAG,CAACQ,WAAW,CAAC,MAAM;MACrC,SAAS;;MACTR,GAAG,CAACS,OAAO,CAACP,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC,EAAEC,IAAI,CAAC;IACR,OAAO,MAAMH,GAAG,CAACU,UAAU,CAACH,QAAQ,CAAC;EACvC,CAAC,EAAE,CAACJ,IAAI,EAAED,EAAE,CAAC,CAAC;EACd,OAAOG,KAAK;AACd,CAAC"}
@@ -23,15 +23,11 @@ export const drawAsPicture = (element, bounds) => {
23
23
  export const drawAsImage = (element, size) => {
24
24
  return drawAsImageFromPicture(drawAsPicture(element), size);
25
25
  };
26
-
27
- // TODO: We're not sure yet why PixelRatio is not needed here.
28
- const pd = 1;
29
26
  export const drawAsImageFromPicture = (picture, size) => {
30
27
  "worklet";
31
28
 
32
- const surface = Skia.Surface.MakeOffscreen(size.width * pd, size.height * pd);
29
+ const surface = Skia.Surface.MakeOffscreen(size.width, size.height);
33
30
  const canvas = surface.getCanvas();
34
- canvas.scale(pd, pd);
35
31
  canvas.drawPicture(picture);
36
32
  surface.flush();
37
33
  const image = surface.makeImageSnapshot();
@@ -1 +1 @@
1
- {"version":3,"names":["JsiDrawingContext","Skia","Platform","SkiaRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","ctx","dom","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","pd","surface","Surface","MakeOffscreen","width","height","getCanvas","scale","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\n// We call it main thread because on web main is JS thread\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(drawAsPicture(element), size);\n};\n\n// TODO: We're not sure yet why PixelRatio is not needed here.\nconst pd = 1;\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(\n size.width * pd,\n size.height * pd\n )!;\n const canvas = surface.getCanvas();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n // If we are not on the main thread or if we are on Web, we need to make the image non-texture.\n if (!isOnMainThread() || Platform.OS === \"web\") {\n return image.makeNonTextureImage();\n } else {\n return image;\n }\n};\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,IAAI,QAAQ,SAAS;AAC9B,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,QAAQ,QAAQ,cAAc;;AAEvC;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDH,QAAQ,CAACI,EAAE,KAAK,KAAK;AAEzB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAACC,OAAqB,EAAEC,MAAe,KAAK;EACvE,MAAMC,QAAQ,GAAGT,IAAI,CAACU,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAc,CAACJ,MAAM,CAAC;EAC9C,MAAMK,IAAI,GAAG,IAAIX,QAAQ,CAACF,IAAI,EAAE,KAAK,CAAC;EACtCa,IAAI,CAACC,MAAM,CAACP,OAAO,CAAC;EACpB,MAAMQ,GAAG,GAAG,IAAIhB,iBAAiB,CAACC,IAAI,EAAEW,MAAM,CAAC;EAC/CE,IAAI,CAACG,GAAG,CAACF,MAAM,CAACC,GAAG,CAAC;EACpB,MAAME,OAAO,GAAGR,QAAQ,CAACS,wBAAwB,CAAC,CAAC;EACnDL,IAAI,CAACM,OAAO,CAAC,CAAC;EACd,OAAOF,OAAO;AAChB,CAAC;AAED,OAAO,MAAMG,WAAW,GAAGA,CAACb,OAAqB,EAAEc,IAAY,KAAK;EAClE,OAAOC,sBAAsB,CAAChB,aAAa,CAACC,OAAO,CAAC,EAAEc,IAAI,CAAC;AAC7D,CAAC;;AAED;AACA,MAAME,EAAE,GAAG,CAAC;AACZ,OAAO,MAAMD,sBAAsB,GAAGA,CAACL,OAAkB,EAAEI,IAAY,KAAK;EAC1E,SAAS;;EACT,MAAMG,OAAO,GAAGxB,IAAI,CAACyB,OAAO,CAACC,aAAa,CACxCL,IAAI,CAACM,KAAK,GAAGJ,EAAE,EACfF,IAAI,CAACO,MAAM,GAAGL,EAChB,CAAE;EACF,MAAMZ,MAAM,GAAGa,OAAO,CAACK,SAAS,CAAC,CAAC;EAClClB,MAAM,CAACmB,KAAK,CAACP,EAAE,EAAEA,EAAE,CAAC;EACpBZ,MAAM,CAACoB,WAAW,CAACd,OAAO,CAAC;EAC3BO,OAAO,CAACQ,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGT,OAAO,CAACU,iBAAiB,CAAC,CAAC;EACzC;EACA,IAAI,CAAC/B,cAAc,CAAC,CAAC,IAAIF,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;IAC9C,OAAO4B,KAAK,CAACE,mBAAmB,CAAC,CAAC;EACpC,CAAC,MAAM;IACL,OAAOF,KAAK;EACd;AACF,CAAC"}
1
+ {"version":3,"names":["JsiDrawingContext","Skia","Platform","SkiaRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","ctx","dom","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\n// We call it main thread because on web main is JS thread\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(drawAsPicture(element), size);\n};\n\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n // If we are not on the main thread or if we are on Web, we need to make the image non-texture.\n if (!isOnMainThread() || Platform.OS === \"web\") {\n return image.makeNonTextureImage();\n } else {\n return image;\n }\n};\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,IAAI,QAAQ,SAAS;AAC9B,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,QAAQ,QAAQ,cAAc;;AAEvC;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDH,QAAQ,CAACI,EAAE,KAAK,KAAK;AAEzB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAACC,OAAqB,EAAEC,MAAe,KAAK;EACvE,MAAMC,QAAQ,GAAGT,IAAI,CAACU,eAAe,CAAC,CAAC;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"../NativeBuffer";
2
3
  import type { SkImage } from "./Image";
3
4
  export declare enum AlphaType {
4
5
  Unknown = 0,
@@ -23,16 +24,7 @@ export declare enum ColorType {
23
24
  Gray_8 = 13,
24
25
  RGBA_F16Norm = 14,
25
26
  RGBA_F16 = 15,
26
- RGBA_F32 = 16,
27
- R8G8_unorm = 17,
28
- A16_float = 18,
29
- R16G16_float = 19,
30
- A16_unorm = 20,
31
- R16G16_unorm = 21,
32
- R16G16B16A16_unorm = 22,
33
- SRGBA_8888 = 23,
34
- R8_unorm = 24,
35
- N32_SkColorType = 25
27
+ RGBA_F32 = 16
36
28
  }
37
29
  export interface ImageInfo {
38
30
  alphaType: AlphaType;
@@ -53,19 +45,20 @@ export interface ImageFactory {
53
45
  */
54
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
55
47
  /**
56
- * Return an Image backed by the given native platform buffer.
48
+ * Return an Image backed by a given native buffer.
57
49
  * The platform buffer must be a valid owning reference.
58
50
  *
59
- * This API is used by [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
51
+ * For instance, this API is used by
52
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
60
53
  * to render a Skia Camera preview.
61
54
  *
62
55
  * - On Android; This is an `AHardwareBuffer*`
63
- * - On iOS, this is a `CMSampleBufferRef`
64
- * @param platformBuffer A strong `uintptr_t` pointer to the native platform buffer
56
+ * - On iOS, this is a `CVPixelBufferRef`
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
65
58
  * @throws Throws an error if the Image could not be created, for example when the given
66
59
  * platform buffer is invalid.
67
60
  */
68
- MakeImageFromPlatformBuffer: (platformBuffer: bigint) => SkImage;
61
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
69
62
  /**
70
63
  * Returns an image that will be a screenshot of the view represented by
71
64
  * the view tag
@@ -23,15 +23,6 @@ export let ColorType = /*#__PURE__*/function (ColorType) {
23
23
  ColorType[ColorType["RGBA_F16Norm"] = 14] = "RGBA_F16Norm";
24
24
  ColorType[ColorType["RGBA_F16"] = 15] = "RGBA_F16";
25
25
  ColorType[ColorType["RGBA_F32"] = 16] = "RGBA_F32";
26
- ColorType[ColorType["R8G8_unorm"] = 17] = "R8G8_unorm";
27
- ColorType[ColorType["A16_float"] = 18] = "A16_float";
28
- ColorType[ColorType["R16G16_float"] = 19] = "R16G16_float";
29
- ColorType[ColorType["A16_unorm"] = 20] = "A16_unorm";
30
- ColorType[ColorType["R16G16_unorm"] = 21] = "R16G16_unorm";
31
- ColorType[ColorType["R16G16B16A16_unorm"] = 22] = "R16G16B16A16_unorm";
32
- ColorType[ColorType["SRGBA_8888"] = 23] = "SRGBA_8888";
33
- ColorType[ColorType["R8_unorm"] = 24] = "R8_unorm";
34
- ColorType[ColorType["N32_SkColorType"] = 25] = "N32_SkColorType";
35
26
  return ColorType;
36
- }({}); // either BGRA_8888 or RGBA_8888 based on the platform
27
+ }({}); // pixel using C float for red, green, blue, alpha; in 128-bit word
37
28
  //# sourceMappingURL=ImageFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AlphaType","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\n\n // The following 6 colortypes are just for reading from - not for rendering to\n R8G8_unorm, // pixel with a uint8_t for red and green\n\n A16_float, // pixel with a half float for alpha\n R16G16_float, // pixel with a half float for red and green\n\n A16_unorm, // pixel with a little endian uint16_t for alpha\n R16G16_unorm, // pixel with a little endian uint16_t for red and green\n R16G16B16A16_unorm, // pixel with a little endian uint16_t for red, green, blue, and alpha\n\n SRGBA_8888,\n R8_unorm,\n\n // The `kN32_SkColorType` is platform dependent in the original enum,\n // and TypeScript doesn't support conditional compilation natively.\n // You might need to handle it differently based on your use case.\n N32_SkColorType, // either BGRA_8888 or RGBA_8888 based on the platform\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 /**\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 the given native platform buffer.\n * The platform buffer must be a valid owning reference.\n *\n * This API is used by [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 `CMSampleBufferRef`\n * @param platformBuffer A strong `uintptr_t` pointer to the native platform buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * platform buffer is invalid.\n */\n MakeImageFromPlatformBuffer: (platformBuffer: bigint) => 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"],"mappings":"AAIA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAOrB,WAAYC,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAmCF"}
1
+ {"version":3,"names":["AlphaType","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\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 /**\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 platform 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 platform buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * platform buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => 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"],"mappings":"AAKA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAOrB,WAAYC,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAiBT"}
@@ -0,0 +1,18 @@
1
+ import type { SkImage } from "../Image";
2
+ export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown> = T;
3
+ export type NativeBufferAddr = NativeBuffer<bigint>;
4
+ export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
5
+ export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
6
+ export declare const isNativeBufferAddr: (buffer: NativeBuffer) => buffer is bigint;
7
+ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is CanvasImageSource;
8
+ export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
9
+ export interface NativeBufferFactory {
10
+ /**
11
+ * Copy pixels to a native buffer.
12
+ */
13
+ MakeFromImage: (image: SkImage) => NativeBuffer;
14
+ /**
15
+ * Release a platform buffer that was created with `MakeFromImage`.
16
+ */
17
+ Release: (platformBuffer: NativeBuffer) => void;
18
+ }
@@ -0,0 +1,4 @@
1
+ export const isNativeBufferAddr = buffer => buffer instanceof BigInt;
2
+ export const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement;
3
+ export const isNativeBufferNode = buffer => buffer instanceof ArrayBuffer;
4
+ //# sourceMappingURL=NativeBufferFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a native buffer.\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a platform buffer that was created with `MakeFromImage`.\n */\n Release: (platformBuffer: NativeBuffer) => void;\n}\n"],"mappings":"AAUA,OAAO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AACzD,OAAO,MAAMC,iBAAiB,GAC5BF,MAAoB,IAEpBA,MAAM,YAAYG,gBAAgB,IAClCH,MAAM,YAAYI,iBAAiB,IACnCJ,MAAM,YAAYK,WAAW,IAC7BL,MAAM,YAAYM,eAAe,IACjCN,MAAM,YAAYO,UAAU,IAC5BP,MAAM,YAAYQ,gBAAgB,IAClCR,MAAM,YAAYS,eAAe;AAEnC,OAAO,MAAMC,kBAAkB,GAC7BV,MAAoB,IACWA,MAAM,YAAYW,WAAW"}
@@ -0,0 +1 @@
1
+ export * from "./NativeBufferFactory";
@@ -0,0 +1,2 @@
1
+ export * from "./NativeBufferFactory";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./NativeBufferFactory\";\n"],"mappings":"AAAA,cAAc,uBAAuB"}
@@ -26,7 +26,7 @@ import type { Color, SkColor } from "./Color";
26
26
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
27
27
  import type { AnimatedImageFactory } from "./AnimatedImage";
28
28
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
29
- import type { PlatformBufferFactory } from "./PlatformBuffer";
29
+ import type { NativeBufferFactory } from "./NativeBuffer";
30
30
  /**
31
31
  * Declares the interface for the native Skia API
32
32
  */
@@ -72,5 +72,5 @@ export interface Skia {
72
72
  TextBlob: TextBlobFactory;
73
73
  Surface: SurfaceFactory;
74
74
  ParagraphBuilder: ParagraphBuilderFactory;
75
- PlatformBuffer: PlatformBufferFactory;
75
+ NativeBuffer: NativeBufferFactory;
76
76
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } 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 { PlatformBufferFactory } from \"./PlatformBuffer\";\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 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 PlatformBuffer: PlatformBufferFactory;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } 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 { NativeBufferFactory } from \"./NativeBuffer\";\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 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 NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
@@ -29,4 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
@@ -29,5 +29,5 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
33
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./PlatformBuffer\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,kBAAkB"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./NativeBuffer\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,gBAAgB"}
@@ -1,11 +1,12 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkData, ImageInfo, SkImage, PlatformBuffer, ImageFactory } from "../types";
2
+ import type { SkData, ImageInfo, SkImage, NativeBuffer, ImageFactory } from "../types";
3
3
  import { Host } from "./Host";
4
4
  import { JsiSkImage } from "./JsiSkImage";
5
+ import type { JsiSkSurface } from "./JsiSkSurface";
5
6
  export declare class JsiSkImageFactory extends Host implements ImageFactory {
6
7
  constructor(CanvasKit: CanvasKit);
7
8
  MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
8
- MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage;
9
+ MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
9
10
  MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
10
11
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
11
12
  }
@@ -1,3 +1,4 @@
1
+ import { isNativeBufferWeb } from "../types";
1
2
  import { Host, getEnum } from "./Host";
2
3
  import { JsiSkImage } from "./JsiSkImage";
3
4
  import { JsiSkData } from "./JsiSkData";
@@ -11,8 +12,23 @@ export class JsiSkImageFactory extends Host {
11
12
  console.log(view);
12
13
  return Promise.resolve(null);
13
14
  }
14
- MakeImageFromPlatformBuffer(_platformBuffer) {
15
- throw new Error("MakeImageFromPlatformBuffer() is only available on iOS and Android!");
15
+ MakeImageFromNativeBuffer(buffer, surface, image) {
16
+ if (!isNativeBufferWeb(buffer)) {
17
+ throw new Error("Invalid NativeBuffer");
18
+ }
19
+ if (!surface) {
20
+ // TODO: this is way to slow
21
+ const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
22
+ return new JsiSkImage(this.CanvasKit, img);
23
+ } else if (!image) {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ const img = surface.makeImageFromTextureSource(buffer);
26
+ return new JsiSkImage(this.CanvasKit, img);
27
+ } else {
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ const img = surface.updateTextureFromSource(image, buffer);
30
+ return new JsiSkImage(this.CanvasKit, img);
31
+ }
16
32
  }
17
33
  MakeImageFromEncoded(encoded) {
18
34
  const image = this.CanvasKit.MakeImageFromEncoded(JsiSkData.fromValue(encoded));
@@ -1 +1 @@
1
- {"version":3,"names":["Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromPlatformBuffer","_platformBuffer","Error","MakeImageFromEncoded","encoded","image","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n PlatformBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage {\n throw new Error(\n \"MakeImageFromPlatformBuffer() is only available on iOS and Android!\"\n );\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit.ColorType, info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAUA,SAASA,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,MAAMC,iBAAiB,SAASJ,IAAI,CAAyB;EAClEK,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,o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","Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","Error","img","MakeImageFromCanvasImageSource","makeImageFromTextureSource","updateTextureFromSource","MakeImageFromEncoded","encoded","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit, Image } from \"canvaskit-wasm\";\n\nimport { isNativeBufferWeb } from \"../types\";\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n NativeBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\nimport type { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromNativeBuffer(\n buffer: NativeBuffer,\n surface?: JsiSkSurface,\n image?: JsiSkImage\n ) {\n if (!isNativeBufferWeb(buffer)) {\n throw new Error(\"Invalid NativeBuffer\");\n }\n if (!surface) {\n // TODO: this is way to slow\n const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);\n return new JsiSkImage(this.CanvasKit, img);\n } else if (!image) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).makeImageFromTextureSource(buffer) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).updateTextureFromSource(\n image,\n buffer\n ) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n }\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit.ColorType, info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,UAAU;AAS5C,SAASC,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAGvC,OAAO,MAAMC,iBAAiB,SAASJ,IAAI,CAAyB;EAClEK,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,oBAAoBA,CAACC,OAAe,EAA2B;IAC7D,MAAMC,IAAI,GAAGD,OAAiC;IAC9C;IACAE,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC;IACjB,OAAOG,OAAO,CAACC,OAAO,CAAC,IAAI,CAAC;EAC9B;EAEAC,yBAAyBA,CACvBC,MAAoB,EACpBC,OAAsB,EACtBC,KAAkB,EAClB;IACA,IAAI,CAAClB,iBAAiB,CAACgB,MAAM,CAAC,EAAE;MAC9B,MAAM,IAAIG,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,IAAI,CAACF,OAAO,EAAE;MACZ;MACA,MAAMG,GAAG,GAAG,IAAI,CAACb,SAAS,CAACc,8BAA8B,CAACL,MAAM,CAAC;MACjE,OAAO,IAAIb,UAAU,CAAC,IAAI,CAACI,SAAS,EA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AClB,OAAO,IAAI;IACb;IACA,OAAO,IAAIf,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEW,KAAK,CAAC;EAC9C;AACF"}
@@ -0,0 +1,8 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+ import { type NativeBuffer, type NativeBufferFactory, type SkImage } from "../types";
3
+ import { Host } from "./Host";
4
+ export declare class JsiSkNativeBufferFactory extends Host implements NativeBufferFactory {
5
+ constructor(CanvasKit: CanvasKit);
6
+ MakeFromImage(image: SkImage): NativeBuffer;
7
+ Release(_platformBuffer: NativeBuffer): void;
8
+ }
@@ -0,0 +1,22 @@
1
+ import { Host } from "./Host";
2
+ export class JsiSkNativeBufferFactory extends Host {
3
+ constructor(CanvasKit) {
4
+ super(CanvasKit);
5
+ }
6
+ MakeFromImage(image) {
7
+ const info = image.getImageInfo();
8
+ const uint8ClampedArray = new Uint8ClampedArray(image.readPixels());
9
+ const imageData = new ImageData(uint8ClampedArray, info.width, info.height);
10
+ const canvas = new OffscreenCanvas(info.width, info.height);
11
+ const ctx = canvas.getContext("2d");
12
+ if (!ctx) {
13
+ throw new Error("Failed to get 2d context from canvas");
14
+ }
15
+ ctx.putImageData(imageData, 0, 0);
16
+ return canvas;
17
+ }
18
+ Release(_platformBuffer) {
19
+ // it's a noop on Web
20
+ }
21
+ }
22
+ //# sourceMappingURL=JsiSkNativeBufferFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Host","JsiSkNativeBufferFactory","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_platformBuffer"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_platformBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":"AAQA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,OAAO,MAAMC,wBAAwB,SAC3BD,IAAI,CAEd;EACEE,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,eAA6B,EAAE;IACrC;EAAA;AAEJ"}
@@ -29,7 +29,7 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
29
29
  import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
30
30
  import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
31
31
  import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
32
- import { JsiSkPlatformBufferFactory } from "./JsiSkPlatformBufferFactory";
32
+ import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
33
33
  export const JsiSkApi = CanvasKit => ({
34
34
  Point: (x, y) => new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),
35
35
  RuntimeShaderBuilder: _ => {
@@ -74,6 +74,6 @@ export const JsiSkApi = CanvasKit => ({
74
74
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
75
75
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
76
76
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
77
- PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit)
77
+ NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit)
78
78
  });
79
79
  //# sourceMappingURL=JsiSkia.js.map