@shopify/react-native-skia 0.1.157 → 0.1.159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (482) hide show
  1. package/android/CMakeLists.txt +35 -11
  2. package/android/build.gradle +31 -30
  3. package/android/cpp/jni/JniLoad.cpp +2 -0
  4. package/android/cpp/jni/include/JniSkiaDomView.h +89 -0
  5. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +4 -3
  6. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +4 -3
  7. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +2 -1
  8. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +45 -0
  9. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +64 -0
  10. package/cpp/api/JsiSkContourMeasure.h +7 -5
  11. package/cpp/api/JsiSkHostObjects.h +6 -0
  12. package/cpp/api/JsiSkImageFilterFactory.h +1 -1
  13. package/cpp/api/JsiSkPaint.h +9 -2
  14. package/cpp/api/JsiSkPath.h +1 -0
  15. package/cpp/api/JsiSkRuntimeEffect.h +36 -36
  16. package/cpp/jsi/JsiHostObject.cpp +16 -28
  17. package/cpp/jsi/JsiHostObject.h +127 -7
  18. package/cpp/jsi/JsiValue.cpp +346 -0
  19. package/cpp/jsi/JsiValue.h +222 -0
  20. package/cpp/jsi/JsiValueWrapper.h +33 -5
  21. package/cpp/rnskia/RNSkDomView.cpp +220 -0
  22. package/cpp/rnskia/RNSkDomView.h +140 -0
  23. package/cpp/rnskia/RNSkJsView.cpp +0 -4
  24. package/cpp/rnskia/RNSkJsView.h +6 -4
  25. package/cpp/rnskia/RNSkManager.cpp +7 -0
  26. package/cpp/rnskia/RNSkPictureView.h +5 -8
  27. package/cpp/rnskia/RNSkView.h +113 -5
  28. package/cpp/rnskia/dom/JsiDomApi.h +167 -0
  29. package/cpp/rnskia/dom/base/BaseNodeProp.h +72 -0
  30. package/cpp/rnskia/dom/base/DerivedNodeProp.h +187 -0
  31. package/cpp/rnskia/dom/base/DrawingContext.cpp +227 -0
  32. package/cpp/rnskia/dom/base/DrawingContext.h +136 -0
  33. package/cpp/rnskia/dom/base/JsiDependencyManager.h +294 -0
  34. package/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +176 -0
  35. package/cpp/rnskia/dom/base/JsiDomDrawingNode.h +50 -0
  36. package/cpp/rnskia/dom/base/JsiDomNode.h +361 -0
  37. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +267 -0
  38. package/cpp/rnskia/dom/base/NodeProp.h +130 -0
  39. package/cpp/rnskia/dom/base/NodePropsContainer.h +119 -0
  40. package/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +38 -0
  41. package/cpp/rnskia/dom/nodes/JsiBlendNode.h +112 -0
  42. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +78 -0
  43. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +104 -0
  44. package/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +33 -0
  45. package/cpp/rnskia/dom/nodes/JsiCircleNode.h +38 -0
  46. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +192 -0
  47. package/cpp/rnskia/dom/nodes/JsiCustomDrawingNode.h +123 -0
  48. package/cpp/rnskia/dom/nodes/JsiDiffRectNode.h +42 -0
  49. package/cpp/rnskia/dom/nodes/JsiFillNode.h +22 -0
  50. package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +56 -0
  51. package/cpp/rnskia/dom/nodes/JsiGroupNode.h +26 -0
  52. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +415 -0
  53. package/cpp/rnskia/dom/nodes/JsiImageNode.h +34 -0
  54. package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +44 -0
  55. package/cpp/rnskia/dom/nodes/JsiLayerNode.h +64 -0
  56. package/cpp/rnskia/dom/nodes/JsiLineNode.h +43 -0
  57. package/cpp/rnskia/dom/nodes/JsiOvalNode.h +34 -0
  58. package/cpp/rnskia/dom/nodes/JsiPaintNode.h +77 -0
  59. package/cpp/rnskia/dom/nodes/JsiPatchNode.h +54 -0
  60. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +315 -0
  61. package/cpp/rnskia/dom/nodes/JsiPathNode.h +181 -0
  62. package/cpp/rnskia/dom/nodes/JsiPictureNode.h +32 -0
  63. package/cpp/rnskia/dom/nodes/JsiPointsNode.h +51 -0
  64. package/cpp/rnskia/dom/nodes/JsiRRectNode.h +34 -0
  65. package/cpp/rnskia/dom/nodes/JsiRectNode.h +34 -0
  66. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +517 -0
  67. package/cpp/rnskia/dom/nodes/JsiTextBlobNode.h +47 -0
  68. package/cpp/rnskia/dom/nodes/JsiTextNode.h +54 -0
  69. package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +32 -0
  70. package/cpp/rnskia/dom/nodes/JsiVerticesNode.h +43 -0
  71. package/cpp/rnskia/dom/props/BezierProps.h +63 -0
  72. package/cpp/rnskia/dom/props/BlendModeProp.h +101 -0
  73. package/cpp/rnskia/dom/props/BoxShadowProps.h +61 -0
  74. package/cpp/rnskia/dom/props/CircleProp.h +46 -0
  75. package/cpp/rnskia/dom/props/ClipProp.h +62 -0
  76. package/cpp/rnskia/dom/props/ColorProp.h +80 -0
  77. package/cpp/rnskia/dom/props/DrawingProp.h +33 -0
  78. package/cpp/rnskia/dom/props/FontProp.h +34 -0
  79. package/cpp/rnskia/dom/props/GlyphsProp.h +53 -0
  80. package/cpp/rnskia/dom/props/ImageProps.h +173 -0
  81. package/cpp/rnskia/dom/props/LayerProp.h +50 -0
  82. package/cpp/rnskia/dom/props/MatrixProp.h +33 -0
  83. package/cpp/rnskia/dom/props/NumbersProp.h +63 -0
  84. package/cpp/rnskia/dom/props/PaintProps.h +172 -0
  85. package/cpp/rnskia/dom/props/PathProp.h +55 -0
  86. package/cpp/rnskia/dom/props/PictureProp.h +38 -0
  87. package/cpp/rnskia/dom/props/PointProp.h +72 -0
  88. package/cpp/rnskia/dom/props/PointsProp.h +83 -0
  89. package/cpp/rnskia/dom/props/RRectProp.h +134 -0
  90. package/cpp/rnskia/dom/props/RadiusProp.h +43 -0
  91. package/cpp/rnskia/dom/props/RectProp.h +118 -0
  92. package/cpp/rnskia/dom/props/StrokeProps.h +75 -0
  93. package/cpp/rnskia/dom/props/SvgProp.h +37 -0
  94. package/cpp/rnskia/dom/props/TextBlobProp.h +128 -0
  95. package/cpp/rnskia/dom/props/TileModeProp.h +50 -0
  96. package/cpp/rnskia/dom/props/TransformProp.h +80 -0
  97. package/cpp/rnskia/dom/props/TransformsProps.h +68 -0
  98. package/cpp/rnskia/dom/props/UniformsProp.h +194 -0
  99. package/cpp/rnskia/dom/props/VertexModeProp.h +47 -0
  100. package/cpp/rnskia/dom/props/VerticesProps.h +67 -0
  101. package/cpp/rnskia/values/RNSkReadonlyValue.h +13 -4
  102. package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +35 -1
  103. package/cpp/skia/include/codec/SkAndroidCodec.h +17 -1
  104. package/cpp/skia/include/codec/SkCodec.h +8 -5
  105. package/cpp/skia/include/core/SkAnnotation.h +2 -0
  106. package/cpp/skia/include/core/SkBitmap.h +52 -1
  107. package/cpp/skia/include/core/SkBlendMode.h +2 -0
  108. package/cpp/skia/include/core/SkCanvas.h +52 -31
  109. package/cpp/skia/include/core/SkCapabilities.h +44 -0
  110. package/cpp/skia/include/core/SkColor.h +7 -0
  111. package/cpp/skia/include/core/SkColorFilter.h +37 -0
  112. package/cpp/skia/include/core/SkColorSpace.h +1 -1
  113. package/cpp/skia/include/core/SkFont.h +4 -0
  114. package/cpp/skia/include/core/SkFontMgr.h +3 -0
  115. package/cpp/skia/include/core/SkGraphics.h +9 -0
  116. package/cpp/skia/include/core/SkImage.h +77 -17
  117. package/cpp/skia/include/core/SkImageEncoder.h +5 -3
  118. package/cpp/skia/include/core/SkImageGenerator.h +27 -17
  119. package/cpp/skia/include/core/SkM44.h +1 -0
  120. package/cpp/skia/include/core/SkMesh.h +120 -34
  121. package/cpp/skia/include/core/SkMilestone.h +1 -1
  122. package/cpp/skia/include/core/SkOverdrawCanvas.h +2 -1
  123. package/cpp/skia/include/core/SkPaint.h +15 -2
  124. package/cpp/skia/include/core/SkPath.h +4 -0
  125. package/cpp/skia/include/core/SkPathBuilder.h +1 -1
  126. package/cpp/skia/include/core/SkPicture.h +0 -3
  127. package/cpp/skia/include/core/SkPictureRecorder.h +0 -2
  128. package/cpp/skia/include/core/SkPixmap.h +19 -0
  129. package/cpp/skia/include/core/SkRasterHandleAllocator.h +3 -1
  130. package/cpp/skia/include/core/SkRect.h +11 -4
  131. package/cpp/skia/include/core/SkRefCnt.h +13 -1
  132. package/cpp/skia/include/core/SkRegion.h +6 -0
  133. package/cpp/skia/include/core/SkSamplingOptions.h +8 -6
  134. package/cpp/skia/include/core/SkScalar.h +6 -25
  135. package/cpp/skia/include/core/SkShader.h +20 -12
  136. package/cpp/skia/include/core/SkSpan.h +51 -19
  137. package/cpp/skia/include/core/SkStream.h +2 -2
  138. package/cpp/skia/include/core/SkString.h +11 -3
  139. package/cpp/skia/include/core/SkSurface.h +85 -8
  140. package/cpp/skia/include/core/SkTextBlob.h +5 -2
  141. package/cpp/skia/include/core/SkTypes.h +11 -10
  142. package/cpp/skia/include/docs/SkPDFDocument.h +0 -5
  143. package/cpp/skia/include/effects/Sk1DPathEffect.h +6 -1
  144. package/cpp/skia/include/effects/Sk2DPathEffect.h +4 -1
  145. package/cpp/skia/include/effects/SkColorMatrix.h +1 -0
  146. package/cpp/skia/include/effects/SkColorMatrixFilter.h +5 -8
  147. package/cpp/skia/include/effects/SkCornerPathEffect.h +5 -1
  148. package/cpp/skia/include/effects/SkDashPathEffect.h +5 -1
  149. package/cpp/skia/include/effects/SkGradientShader.h +68 -38
  150. package/cpp/skia/include/effects/SkHighContrastFilter.h +5 -1
  151. package/cpp/skia/include/effects/SkImageFilters.h +5 -4
  152. package/cpp/skia/include/effects/SkLumaColorFilter.h +4 -1
  153. package/cpp/skia/include/effects/SkOpPathEffect.h +6 -2
  154. package/cpp/skia/include/effects/SkOverdrawColorFilter.h +5 -2
  155. package/cpp/skia/include/effects/SkRuntimeEffect.h +54 -62
  156. package/cpp/skia/include/effects/SkShaderMaskFilter.h +3 -1
  157. package/cpp/skia/include/effects/SkTableColorFilter.h +8 -21
  158. package/cpp/skia/include/effects/SkTableMaskFilter.h +5 -1
  159. package/cpp/skia/include/effects/SkTrimPathEffect.h +5 -1
  160. package/cpp/skia/include/encode/SkEncoder.h +17 -0
  161. package/cpp/skia/include/encode/SkWebpEncoder.h +17 -0
  162. package/cpp/skia/include/gpu/GpuTypes.h +18 -0
  163. package/cpp/skia/include/gpu/GrBackendSurface.h +38 -17
  164. package/cpp/skia/include/gpu/GrBackendSurfaceMutableState.h +6 -71
  165. package/cpp/skia/include/gpu/GrContextOptions.h +1 -1
  166. package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +10 -9
  167. package/cpp/skia/include/gpu/GrDirectContext.h +42 -22
  168. package/cpp/skia/include/gpu/GrRecordingContext.h +6 -3
  169. package/cpp/skia/include/gpu/GrTypes.h +11 -11
  170. package/cpp/skia/include/gpu/MutableTextureState.h +122 -0
  171. package/cpp/skia/include/gpu/gl/GrGLFunctions.h +1 -0
  172. package/cpp/skia/include/gpu/gl/GrGLInterface.h +1 -0
  173. package/cpp/skia/include/gpu/graphite/BackendTexture.h +7 -0
  174. package/cpp/skia/include/gpu/graphite/CombinationBuilder.h +195 -0
  175. package/cpp/skia/include/gpu/graphite/Context.h +47 -55
  176. package/cpp/skia/include/gpu/graphite/ContextOptions.h +85 -0
  177. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +1 -17
  178. package/cpp/skia/include/gpu/graphite/ImageProvider.h +61 -0
  179. package/cpp/skia/include/gpu/graphite/Recorder.h +87 -8
  180. package/cpp/skia/include/gpu/graphite/Recording.h +19 -9
  181. package/cpp/skia/include/gpu/graphite/TextureInfo.h +40 -8
  182. package/cpp/skia/include/gpu/graphite/dawn/DawnBackendContext.h +25 -0
  183. package/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +3 -2
  184. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +69 -0
  185. package/cpp/skia/include/gpu/mtl/MtlMemoryAllocator.h +39 -0
  186. package/cpp/skia/include/gpu/vk/GrVkBackendContext.h +21 -19
  187. package/cpp/skia/include/gpu/vk/GrVkExtensions.h +2 -50
  188. package/cpp/skia/include/gpu/vk/GrVkMemoryAllocator.h +2 -127
  189. package/cpp/skia/include/gpu/vk/GrVkTypes.h +5 -43
  190. package/cpp/skia/include/gpu/vk/VulkanBackendContext.h +46 -0
  191. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +67 -0
  192. package/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +116 -0
  193. package/cpp/skia/include/gpu/vk/VulkanTypes.h +59 -0
  194. package/cpp/skia/include/pathops/SkPathOps.h +1 -1
  195. package/cpp/skia/include/private/SkColorData.h +10 -40
  196. package/cpp/skia/include/private/SkEncodedInfo.h +9 -3
  197. package/cpp/skia/include/private/SkFloatingPoint.h +9 -6
  198. package/cpp/skia/include/private/SkHalf.h +5 -52
  199. package/cpp/skia/include/private/SkMacros.h +1 -1
  200. package/cpp/skia/include/private/SkMalloc.h +4 -0
  201. package/cpp/skia/include/private/SkPathRef.h +10 -10
  202. package/cpp/skia/include/private/SkSLModifiers.h +59 -23
  203. package/cpp/skia/include/private/SkSLProgramKind.h +1 -0
  204. package/cpp/skia/include/private/SkSLSymbol.h +7 -3
  205. package/cpp/skia/include/private/SkStringView.h +4 -0
  206. package/cpp/skia/include/private/SkTArray.h +21 -7
  207. package/cpp/skia/include/private/SkTDArray.h +173 -285
  208. package/cpp/skia/include/private/SkTHash.h +33 -32
  209. package/cpp/skia/include/private/SkTemplates.h +24 -26
  210. package/cpp/skia/include/private/SkVx.h +218 -135
  211. package/cpp/skia/include/private/chromium/GrSlug.h +3 -65
  212. package/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +6 -3
  213. package/cpp/skia/include/private/chromium/Slug.h +76 -0
  214. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +6 -1
  215. package/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +5 -39
  216. package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +63 -0
  217. package/cpp/skia/include/{gpu/vk/GrVkVulkan.h → private/gpu/vk/SkiaVulkan.h} +2 -2
  218. package/cpp/skia/include/private/gpu/vk/VulkanTypesPriv.h +57 -0
  219. package/cpp/skia/include/sksl/DSL.h +0 -1
  220. package/cpp/skia/include/sksl/DSLBlock.h +4 -18
  221. package/cpp/skia/include/sksl/DSLCase.h +2 -8
  222. package/cpp/skia/include/sksl/DSLCore.h +8 -15
  223. package/cpp/skia/include/sksl/DSLExpression.h +51 -142
  224. package/cpp/skia/include/sksl/DSLFunction.h +7 -15
  225. package/cpp/skia/include/sksl/DSLModifiers.h +5 -2
  226. package/cpp/skia/include/sksl/DSLStatement.h +4 -39
  227. package/cpp/skia/include/sksl/DSLSymbols.h +1 -11
  228. package/cpp/skia/include/sksl/DSLType.h +20 -12
  229. package/cpp/skia/include/sksl/DSLVar.h +56 -146
  230. package/cpp/skia/include/sksl/SkSLErrorReporter.h +2 -15
  231. package/cpp/skia/include/sksl/SkSLOperator.h +62 -59
  232. package/cpp/skia/include/sksl/SkSLPosition.h +2 -0
  233. package/cpp/skia/include/sksl/SkSLVersion.h +27 -0
  234. package/cpp/skia/include/svg/SkSVGCanvas.h +1 -0
  235. package/cpp/skia/include/utils/SkAnimCodecPlayer.h +1 -1
  236. package/cpp/skia/include/utils/SkBase64.h +2 -0
  237. package/cpp/skia/include/utils/SkCustomTypeface.h +24 -11
  238. package/cpp/skia/include/utils/SkEventTracer.h +12 -1
  239. package/cpp/skia/include/utils/SkNWayCanvas.h +11 -4
  240. package/cpp/skia/include/utils/SkPaintFilterCanvas.h +9 -4
  241. package/cpp/skia/include/utils/SkParse.h +3 -0
  242. package/cpp/skia/include/utils/SkShadowUtils.h +2 -0
  243. package/cpp/skia/include/utils/SkTextUtils.h +2 -1
  244. package/cpp/skia/{include/third_party → modules}/skcms/skcms.h +10 -0
  245. package/cpp/skia/modules/skcms/skcms_internal.h +56 -0
  246. package/cpp/skia/modules/skcms/src/Transform_inl.h +1609 -0
  247. package/cpp/skia/modules/skparagraph/include/DartTypes.h +153 -0
  248. package/cpp/skia/modules/skparagraph/include/FontArguments.h +46 -0
  249. package/cpp/skia/modules/skparagraph/include/FontCollection.h +84 -0
  250. package/cpp/skia/modules/skparagraph/include/Metrics.h +98 -0
  251. package/cpp/skia/modules/skparagraph/include/Paragraph.h +111 -0
  252. package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +69 -0
  253. package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +77 -0
  254. package/cpp/skia/modules/skparagraph/include/ParagraphStyle.h +143 -0
  255. package/cpp/skia/modules/skparagraph/include/TextShadow.h +30 -0
  256. package/cpp/skia/modules/skparagraph/include/TextStyle.h +352 -0
  257. package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +81 -0
  258. package/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +1 -1
  259. package/cpp/skia/modules/svg/include/SkSVGTypes.h +3 -3
  260. package/cpp/skia/src/core/SkLRUCache.h +126 -0
  261. package/cpp/skia/src/core/SkTInternalLList.h +302 -0
  262. package/cpp/utils/RNSkTimingInfo.h +1 -0
  263. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +15 -4
  264. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +40 -54
  265. package/ios/RNSkia-iOS/SkiaDomViewManager.h +8 -0
  266. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +51 -0
  267. package/lib/commonjs/dom/nodes/DrawingNode.js +1 -5
  268. package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
  269. package/lib/commonjs/dom/nodes/JsiSkDOM.js +56 -56
  270. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  271. package/lib/commonjs/dom/nodes/RenderNode.js +3 -9
  272. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  273. package/lib/commonjs/dom/nodes/drawings/Text.js +4 -9
  274. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  275. package/lib/commonjs/dom/types/Common.js.map +1 -1
  276. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  277. package/lib/commonjs/mock/index.js +0 -1
  278. package/lib/commonjs/mock/index.js.map +1 -1
  279. package/lib/commonjs/renderer/Canvas.js +21 -57
  280. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  281. package/lib/commonjs/renderer/DependencyManager.js +0 -5
  282. package/lib/commonjs/renderer/DependencyManager.js.map +1 -1
  283. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  284. package/lib/commonjs/renderer/components/Mask.js +1 -3
  285. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  286. package/lib/commonjs/renderer/components/Paint.js +5 -18
  287. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  288. package/lib/commonjs/renderer/useCanvas.js +8 -6
  289. package/lib/commonjs/renderer/useCanvas.js.map +1 -1
  290. package/lib/commonjs/skia/core/Picture.js +1 -24
  291. package/lib/commonjs/skia/core/Picture.js.map +1 -1
  292. package/lib/commonjs/skia/core/Rect.js +1 -1
  293. package/lib/commonjs/skia/core/Rect.js.map +1 -1
  294. package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
  295. package/lib/commonjs/skia/types/Size.js +2 -0
  296. package/lib/commonjs/skia/types/Size.js.map +1 -0
  297. package/lib/commonjs/skia/types/index.js +13 -0
  298. package/lib/commonjs/skia/types/index.js.map +1 -1
  299. package/lib/commonjs/skia/web/JsiSkColor.js +8 -0
  300. package/lib/commonjs/skia/web/JsiSkColor.js.map +1 -1
  301. package/lib/commonjs/skia/web/JsiSkContourMeasure.js +4 -7
  302. package/lib/commonjs/skia/web/JsiSkContourMeasure.js.map +1 -1
  303. package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -2
  304. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
  305. package/lib/commonjs/views/SkiaBaseWebView.js +9 -2
  306. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  307. package/lib/commonjs/views/SkiaDomView.js +152 -0
  308. package/lib/commonjs/views/SkiaDomView.js.map +1 -0
  309. package/lib/commonjs/views/SkiaDomView.web.js +55 -0
  310. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -0
  311. package/lib/commonjs/views/SkiaPictureView.js +16 -2
  312. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  313. package/lib/commonjs/views/SkiaView.js +17 -2
  314. package/lib/commonjs/views/SkiaView.js.map +1 -1
  315. package/lib/commonjs/views/index.js +13 -0
  316. package/lib/commonjs/views/index.js.map +1 -1
  317. package/lib/commonjs/views/types.js.map +1 -1
  318. package/lib/module/dom/nodes/DrawingNode.js +2 -6
  319. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  320. package/lib/module/dom/nodes/JsiSkDOM.js +56 -56
  321. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  322. package/lib/module/dom/nodes/RenderNode.js +2 -5
  323. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  324. package/lib/module/dom/nodes/drawings/Text.js +4 -9
  325. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  326. package/lib/module/dom/types/Common.js.map +1 -1
  327. package/lib/module/dom/types/Drawings.js.map +1 -1
  328. package/lib/module/mock/index.js +0 -1
  329. package/lib/module/mock/index.js.map +1 -1
  330. package/lib/module/renderer/Canvas.js +22 -58
  331. package/lib/module/renderer/Canvas.js.map +1 -1
  332. package/lib/module/renderer/DependencyManager.js +0 -5
  333. package/lib/module/renderer/DependencyManager.js.map +1 -1
  334. package/lib/module/renderer/HostComponents.js.map +1 -1
  335. package/lib/module/renderer/components/Mask.js +2 -4
  336. package/lib/module/renderer/components/Mask.js.map +1 -1
  337. package/lib/module/renderer/components/Paint.js +3 -14
  338. package/lib/module/renderer/components/Paint.js.map +1 -1
  339. package/lib/module/renderer/useCanvas.js +6 -4
  340. package/lib/module/renderer/useCanvas.js.map +1 -1
  341. package/lib/module/skia/core/Picture.js +0 -18
  342. package/lib/module/skia/core/Picture.js.map +1 -1
  343. package/lib/module/skia/core/Rect.js +1 -1
  344. package/lib/module/skia/core/Rect.js.map +1 -1
  345. package/lib/module/skia/types/ContourMeasure.js.map +1 -1
  346. package/lib/module/skia/types/Size.js +2 -0
  347. package/lib/module/skia/types/Size.js.map +1 -0
  348. package/lib/module/skia/types/index.js +1 -0
  349. package/lib/module/skia/types/index.js.map +1 -1
  350. package/lib/module/skia/web/JsiSkColor.js +8 -0
  351. package/lib/module/skia/web/JsiSkColor.js.map +1 -1
  352. package/lib/module/skia/web/JsiSkContourMeasure.js +3 -7
  353. package/lib/module/skia/web/JsiSkContourMeasure.js.map +1 -1
  354. package/lib/module/values/web/RNSkReadonlyValue.js +4 -2
  355. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
  356. package/lib/module/views/SkiaBaseWebView.js +9 -2
  357. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  358. package/lib/module/views/SkiaDomView.js +128 -0
  359. package/lib/module/views/SkiaDomView.js.map +1 -0
  360. package/lib/module/views/SkiaDomView.web.js +41 -0
  361. package/lib/module/views/SkiaDomView.web.js.map +1 -0
  362. package/lib/module/views/SkiaPictureView.js +14 -2
  363. package/lib/module/views/SkiaPictureView.js.map +1 -1
  364. package/lib/module/views/SkiaView.js +15 -2
  365. package/lib/module/views/SkiaView.js.map +1 -1
  366. package/lib/module/views/index.js +1 -0
  367. package/lib/module/views/index.js.map +1 -1
  368. package/lib/module/views/types.js.map +1 -1
  369. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +57 -64
  370. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +1 -3
  371. package/lib/typescript/src/dom/types/Common.d.ts +2 -3
  372. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -3
  373. package/lib/typescript/src/renderer/Canvas.d.ts +5 -5
  374. package/lib/typescript/src/renderer/DependencyManager.d.ts +0 -2
  375. package/lib/typescript/src/renderer/HostComponents.d.ts +67 -8
  376. package/lib/typescript/src/renderer/components/Paint.d.ts +3 -4
  377. package/lib/typescript/src/renderer/useCanvas.d.ts +1 -6
  378. package/lib/typescript/src/skia/core/Picture.d.ts +0 -8
  379. package/lib/typescript/src/skia/types/ContourMeasure.d.ts +3 -2
  380. package/lib/typescript/src/skia/types/Size.d.ts +4 -0
  381. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  382. package/lib/typescript/src/skia/web/JsiSkContourMeasure.d.ts +2 -6
  383. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +4 -0
  384. package/lib/typescript/src/views/SkiaDomView.d.ts +31 -0
  385. package/lib/typescript/src/views/SkiaDomView.web.d.ts +7 -0
  386. package/lib/typescript/src/views/index.d.ts +1 -0
  387. package/lib/typescript/src/views/types.d.ts +12 -2
  388. package/libs/android/arm64-v8a/libskia.a +0 -0
  389. package/libs/android/arm64-v8a/libskottie.a +0 -0
  390. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  391. package/libs/android/arm64-v8a/libsksg.a +0 -0
  392. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  393. package/libs/android/arm64-v8a/libskunicode.a +0 -0
  394. package/libs/android/arm64-v8a/libsvg.a +0 -0
  395. package/libs/android/armeabi-v7a/libskia.a +0 -0
  396. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  397. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  398. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  399. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  400. package/libs/android/armeabi-v7a/libskunicode.a +0 -0
  401. package/libs/android/armeabi-v7a/libsvg.a +0 -0
  402. package/libs/android/x86/libskia.a +0 -0
  403. package/libs/android/x86/libskottie.a +0 -0
  404. package/libs/android/x86/libskparagraph.a +0 -0
  405. package/libs/android/x86/libsksg.a +0 -0
  406. package/libs/android/x86/libskshaper.a +0 -0
  407. package/libs/android/x86/libskunicode.a +0 -0
  408. package/libs/android/x86/libsvg.a +0 -0
  409. package/libs/android/x86_64/libskia.a +0 -0
  410. package/libs/android/x86_64/libskottie.a +0 -0
  411. package/libs/android/x86_64/libskparagraph.a +0 -0
  412. package/libs/android/x86_64/libsksg.a +0 -0
  413. package/libs/android/x86_64/libskshaper.a +0 -0
  414. package/libs/android/x86_64/libskunicode.a +0 -0
  415. package/libs/android/x86_64/libsvg.a +0 -0
  416. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  417. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  418. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  419. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  420. package/libs/ios/libskparagraph.xcframework/Info.plist +42 -0
  421. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  422. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  423. package/libs/ios/libsksg.xcframework/Info.plist +5 -5
  424. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  425. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  426. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  427. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  428. package/libs/ios/libskunicode.xcframework/Info.plist +42 -0
  429. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  430. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  431. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  432. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  433. package/package.json +6 -4
  434. package/react-native-skia.podspec +3 -1
  435. package/src/dom/nodes/DrawingNode.ts +2 -4
  436. package/src/dom/nodes/JsiSkDOM.ts +170 -56
  437. package/src/dom/nodes/RenderNode.ts +2 -14
  438. package/src/dom/nodes/drawings/Text.ts +4 -4
  439. package/src/dom/types/Common.ts +2 -4
  440. package/src/dom/types/Drawings.ts +1 -4
  441. package/src/mock/index.ts +0 -1
  442. package/src/renderer/Canvas.tsx +32 -51
  443. package/src/renderer/DependencyManager.tsx +0 -5
  444. package/src/renderer/HostComponents.ts +153 -5
  445. package/src/renderer/components/Mask.tsx +2 -2
  446. package/src/renderer/components/Paint.tsx +3 -14
  447. package/src/renderer/useCanvas.ts +5 -5
  448. package/src/skia/core/Picture.ts +0 -24
  449. package/src/skia/core/Rect.ts +1 -1
  450. package/src/skia/types/ContourMeasure.tsx +3 -2
  451. package/src/skia/types/Size.ts +4 -0
  452. package/src/skia/types/index.ts +1 -0
  453. package/src/skia/web/JsiSkColor.ts +11 -0
  454. package/src/skia/web/JsiSkContourMeasure.ts +7 -3
  455. package/src/values/web/RNSkReadonlyValue.ts +4 -2
  456. package/src/views/SkiaBaseWebView.tsx +6 -2
  457. package/src/views/SkiaDomView.tsx +120 -0
  458. package/src/views/SkiaDomView.web.tsx +37 -0
  459. package/src/views/SkiaPictureView.tsx +10 -2
  460. package/src/views/SkiaView.tsx +11 -3
  461. package/src/views/index.ts +1 -0
  462. package/src/views/types.ts +19 -2
  463. package/cpp/jsi/JsiSimpleValueWrapper.h +0 -99
  464. package/cpp/skia/include/c/sk_canvas.h +0 -159
  465. package/cpp/skia/include/c/sk_colorspace.h +0 -25
  466. package/cpp/skia/include/c/sk_data.h +0 -65
  467. package/cpp/skia/include/c/sk_image.h +0 -71
  468. package/cpp/skia/include/c/sk_imageinfo.h +0 -62
  469. package/cpp/skia/include/c/sk_maskfilter.h +0 -47
  470. package/cpp/skia/include/c/sk_matrix.h +0 -49
  471. package/cpp/skia/include/c/sk_paint.h +0 -145
  472. package/cpp/skia/include/c/sk_path.h +0 -102
  473. package/cpp/skia/include/c/sk_picture.h +0 -70
  474. package/cpp/skia/include/c/sk_shader.h +0 -143
  475. package/cpp/skia/include/c/sk_surface.h +0 -73
  476. package/cpp/skia/include/c/sk_types.h +0 -278
  477. package/cpp/skia/include/gpu/graphite/SkStuff.h +0 -47
  478. package/cpp/skia/include/private/SkNx.h +0 -430
  479. package/cpp/skia/include/private/SkNx_neon.h +0 -713
  480. package/cpp/skia/include/private/SkNx_sse.h +0 -823
  481. package/cpp/skia/include/sksl/DSLRuntimeEffects.h +0 -32
  482. package/cpp/skia/include/sksl/DSLWrapper.h +0 -77
@@ -99,7 +99,7 @@ public:
99
99
  throw jsi::JSError(runtime, "invalid uniform index");
100
100
  }
101
101
  auto it = getObject()->uniforms().begin() + i;
102
- return jsi::String::createFromAscii(runtime, it->name.c_str());
102
+ return jsi::String::createFromAscii(runtime, std::string(it->name));
103
103
  }
104
104
 
105
105
  JSI_HOST_FUNCTION(getUniform) {
@@ -131,41 +131,7 @@ public:
131
131
  : JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>(std::move(context),
132
132
  std::move(rt)) {}
133
133
 
134
- private:
135
- sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value) {
136
- auto jsiUniforms = value.asObject(runtime).asArray(runtime);
137
- auto jsiUniformsSize = jsiUniforms.size(runtime);
138
-
139
- // verify size of input uniforms
140
- if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize()) {
141
- std::string msg =
142
- "Uniforms size differs from effect's uniform size. Received " +
143
- std::to_string(jsiUniformsSize) + " expected " +
144
- std::to_string(getObject()->uniformSize() / sizeof(float));
145
- throw jsi::JSError(runtime, msg.c_str());
146
- }
147
-
148
- auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
149
-
150
- // Convert to skia uniforms
151
- const auto &u = getObject()->uniforms();
152
- for (std::size_t i = 0; i < u.size(); i++) {
153
- auto it = getObject()->uniforms().begin() + i;
154
- RuntimeEffectUniform reu = fromUniform(*it);
155
- for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
156
- const std::size_t offset = reu.slot + j;
157
- float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
158
- int iValue = static_cast<int>(fValue);
159
- auto value = reu.isInteger ? iValue : fValue;
160
- memcpy(SkTAddOffset<void>(uniforms->writable_data(),
161
- offset * sizeof(value)),
162
- &value, sizeof(value));
163
- }
164
- }
165
- return uniforms;
166
- }
167
-
168
- RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform &u) {
134
+ static RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform &u) {
169
135
  RuntimeEffectUniform su;
170
136
  su.rows = u.count; // arrayLength
171
137
  su.columns = 1;
@@ -214,5 +180,39 @@ private:
214
180
  su.slot = static_cast<int>(u.offset / sizeof(float));
215
181
  return su;
216
182
  }
183
+
184
+ private:
185
+ sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value) {
186
+ auto jsiUniforms = value.asObject(runtime).asArray(runtime);
187
+ auto jsiUniformsSize = jsiUniforms.size(runtime);
188
+
189
+ // verify size of input uniforms
190
+ if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize()) {
191
+ std::string msg =
192
+ "Uniforms size differs from effect's uniform size. Received " +
193
+ std::to_string(jsiUniformsSize) + " expected " +
194
+ std::to_string(getObject()->uniformSize() / sizeof(float));
195
+ throw jsi::JSError(runtime, msg.c_str());
196
+ }
197
+
198
+ auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
199
+
200
+ // Convert to skia uniforms
201
+ const auto &u = getObject()->uniforms();
202
+ for (std::size_t i = 0; i < u.size(); i++) {
203
+ auto it = getObject()->uniforms().begin() + i;
204
+ RuntimeEffectUniform reu = fromUniform(*it);
205
+ for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
206
+ const std::size_t offset = reu.slot + j;
207
+ float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
208
+ int iValue = static_cast<int>(fValue);
209
+ auto value = reu.isInteger ? iValue : fValue;
210
+ memcpy(SkTAddOffset<void>(uniforms->writable_data(),
211
+ offset * sizeof(value)),
212
+ &value, sizeof(value));
213
+ }
214
+ }
215
+ return uniforms;
216
+ }
217
217
  };
218
218
  } // namespace RNSkia
@@ -34,8 +34,7 @@ JsiHostObject::~JsiHostObject() {
34
34
  void JsiHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
35
35
  const jsi::Value &value) {
36
36
 
37
- auto nameVal = name.utf8(rt);
38
- auto nameStr = nameVal.c_str();
37
+ auto nameStr = name.utf8(rt);
39
38
 
40
39
  /** Check the static setters map */
41
40
  const JsiPropertySettersMap &setters = getExportedPropertySettersMap();
@@ -54,8 +53,15 @@ void JsiHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
54
53
 
55
54
  jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
56
55
  const jsi::PropNameID &name) {
57
- auto nameVal = name.utf8(runtime);
58
- auto nameStr = nameVal.c_str();
56
+ auto nameStr = name.utf8(runtime);
57
+
58
+ // Do the happy-paths first
59
+
60
+ // Check function cache
61
+ auto cachedFunc = _hostFunctionCache.find(nameStr);
62
+ if (cachedFunc != _hostFunctionCache.end()) {
63
+ return cachedFunc->second.asFunction(runtime);
64
+ }
59
65
 
60
66
  // Check the static getters map
61
67
  const JsiPropertyGettersMap &getters = getExportedPropertyGettersMap();
@@ -65,23 +71,6 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
65
71
  return dispatcher(runtime);
66
72
  }
67
73
 
68
- // Check the cache for functions
69
- auto runtimeCache = _cache.find(&runtime);
70
- JsiHostFunctionCache *currentCache;
71
- if (runtimeCache != _cache.end()) {
72
- currentCache = &runtimeCache->second;
73
- // Check if the runtime cache as a cache of the host function
74
- auto cachedFunc = runtimeCache->second.find(nameStr);
75
- if (cachedFunc != runtimeCache->second.end()) {
76
- return cachedFunc->second->asFunction(runtime);
77
- }
78
- } else {
79
- // Create cache for this runtime
80
- JsiHostFunctionCache runtimeCache;
81
- _cache.emplace(&runtime, JsiHostFunctionCache{});
82
- currentCache = &_cache.at(&runtime);
83
- }
84
-
85
74
  // Check the static function map
86
75
  const JsiFunctionMap &funcs = getExportedFunctionMap();
87
76
  auto func = funcs.find(nameStr);
@@ -91,13 +80,12 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
91
80
  std::placeholders::_1, std::placeholders::_2,
92
81
  std::placeholders::_3, std::placeholders::_4);
93
82
 
94
- // Add to cache
95
- currentCache->emplace(nameStr, std::make_unique<jsi::Function>(
96
- jsi::Function::createFromHostFunction(
97
- runtime, name, 0, dispatcher)));
98
-
99
- // return retVal;
100
- return currentCache->at(nameStr)->asFunction(runtime);
83
+ // Add to cache - it is important to cache the results from the
84
+ // createFromHostFunction function which takes some time.
85
+ return _hostFunctionCache
86
+ .emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name,
87
+ 0, dispatcher))
88
+ .first->second.asFunction(runtime);
101
89
  }
102
90
 
103
91
  if (_funcMap.count(nameStr) > 0) {
@@ -3,6 +3,7 @@
3
3
  #include <jsi/jsi.h>
4
4
 
5
5
  #include <functional>
6
+ #include <map>
6
7
  #include <memory>
7
8
  #include <string>
8
9
  #include <unordered_map>
@@ -123,12 +124,6 @@ using JsiPropertySettersMap =
123
124
  std::unordered_map<std::string, void (JsiHostObject::*)(
124
125
  jsi::Runtime &, const jsi::Value &)>;
125
126
 
126
- using JsiHostFunctionCache =
127
- std::unordered_map<std::string, std::unique_ptr<jsi::Function>>;
128
-
129
- using JsiRuntimeCache =
130
- std::unordered_map<jsi::Runtime *, JsiHostFunctionCache>;
131
-
132
127
  /**
133
128
  * Base class for jsi host objects
134
129
  */
@@ -240,9 +235,134 @@ protected:
240
235
  });
241
236
  }
242
237
 
238
+ /**
239
+ @Returns a reference to the argument at the given position in the arguments
240
+ array. Raises an error if the index is above the number of arguments.
241
+ @param runtime jsi::Runtime
242
+ @param arguments Arguments list
243
+ @param count Number of arguments in arguments list
244
+ @param index Index of parameter to return
245
+ */
246
+ static const jsi::Value &getArgument(jsi::Runtime &runtime,
247
+ const jsi::Value *arguments,
248
+ size_t count, size_t index) {
249
+ if (index >= count) {
250
+ throw jsi::JSError(runtime, "Argument index out of bounds.");
251
+ }
252
+
253
+ return arguments[index];
254
+ }
255
+
256
+ /**
257
+ Returns argument as number or throws
258
+ */
259
+ static double getArgumentAsNumber(jsi::Runtime &runtime,
260
+ const jsi::Value *arguments, size_t count,
261
+ size_t index) {
262
+ const jsi::Value &value = getArgument(runtime, arguments, count, index);
263
+ if (!value.isNumber()) {
264
+ throw jsi::JSError(runtime,
265
+ "Expected type number for parameter at index " +
266
+ std::to_string(index));
267
+ }
268
+ return value.asNumber();
269
+ }
270
+
271
+ /**
272
+ Returns argument as bool or throws
273
+ */
274
+ static bool getArgumentAsBool(jsi::Runtime &runtime,
275
+ const jsi::Value *arguments, size_t count,
276
+ size_t index) {
277
+ const jsi::Value &value = getArgument(runtime, arguments, count, index);
278
+ if (!value.isBool()) {
279
+ throw jsi::JSError(runtime,
280
+ "Expected type boolean for parameter at index " +
281
+ std::to_string(index));
282
+ }
283
+ return value.getBool();
284
+ }
285
+
286
+ /**
287
+ Returns argument as string or throws
288
+ */
289
+ static jsi::String getArgumentAsString(jsi::Runtime &runtime,
290
+ const jsi::Value *arguments,
291
+ size_t count, size_t index) {
292
+ const jsi::Value &value = getArgument(runtime, arguments, count, index);
293
+ if (!value.isString()) {
294
+ throw jsi::JSError(runtime,
295
+ "Expected type string for parameter at index " +
296
+ std::to_string(index));
297
+ }
298
+ return value.asString(runtime);
299
+ }
300
+
301
+ /**
302
+ Returns argument as object or throws
303
+ */
304
+ static jsi::Object getArgumentAsObject(jsi::Runtime &runtime,
305
+ const jsi::Value *arguments,
306
+ size_t count, size_t index) {
307
+ const jsi::Value &value = getArgument(runtime, arguments, count, index);
308
+ if (!value.isObject()) {
309
+ throw jsi::JSError(runtime,
310
+ "Expected type object for parameter at index " +
311
+ std::to_string(index));
312
+ }
313
+ return value.asObject(runtime);
314
+ }
315
+
316
+ /**
317
+ Returns argument as host object or throws
318
+ */
319
+ template <typename T = HostObject>
320
+ static std::shared_ptr<T>
321
+ getArgumentAsHostObject(jsi::Runtime &runtime, const jsi::Value *arguments,
322
+ size_t count, size_t index) {
323
+ auto value = getArgumentAsObject(runtime, arguments, count, index);
324
+ if (!value.isHostObject(runtime)) {
325
+ throw jsi::JSError(runtime,
326
+ "Expected type host object for parameter at index " +
327
+ std::to_string(index));
328
+ }
329
+ return value.asHostObject<T>(runtime);
330
+ }
331
+
332
+ /**
333
+ Returns argument as array or throws
334
+ */
335
+ static jsi::Array getArgumentAsArray(jsi::Runtime &runtime,
336
+ const jsi::Value *arguments,
337
+ size_t count, size_t index) {
338
+ auto value = getArgumentAsObject(runtime, arguments, count, index);
339
+ if (!value.isArray(runtime)) {
340
+ throw jsi::JSError(runtime,
341
+ "Expected type array for parameter at index " +
342
+ std::to_string(index));
343
+ }
344
+ return value.asArray(runtime);
345
+ }
346
+
347
+ /**
348
+ Returns argument as function or throws
349
+ */
350
+ static jsi::Object getArgumentAsFunction(jsi::Runtime &runtime,
351
+ const jsi::Value *arguments,
352
+ size_t count, size_t index) {
353
+ auto value = getArgumentAsObject(runtime, arguments, count, index);
354
+ if (!value.isFunction(runtime)) {
355
+ throw jsi::JSError(runtime,
356
+ "Expected type function for parameter at index " +
357
+ std::to_string(index));
358
+ }
359
+ return value.asFunction(runtime);
360
+ }
361
+
243
362
  private:
244
363
  std::unordered_map<std::string, jsi::HostFunctionType> _funcMap;
245
364
  std::unordered_map<std::string, JsPropertyType> _propMap;
246
- JsiRuntimeCache _cache;
365
+
366
+ std::map<std::string, jsi::Function> _hostFunctionCache;
247
367
  };
248
368
  } // namespace RNJsi
@@ -0,0 +1,346 @@
1
+ #include "JsiValue.h"
2
+
3
+ namespace RNJsi {
4
+
5
+ JsiValue::JsiValue() : _type(PropType::Undefined) {}
6
+
7
+ JsiValue::JsiValue(jsi::Runtime &runtime, const jsi::Value &value)
8
+ : JsiValue() {
9
+ setCurrent(runtime, value);
10
+ }
11
+
12
+ void JsiValue::setCurrent(jsi::Runtime &runtime, const jsi::Value &value) {
13
+ _stringValue = "";
14
+ _hostObject = nullptr;
15
+ _hostFunction = nullptr;
16
+ _props.clear();
17
+ _array.clear();
18
+ _keysCache.clear();
19
+
20
+ if (value.isNumber()) {
21
+ _type = PropType::Number;
22
+ _numberValue = value.asNumber();
23
+ } else if (value.isBool()) {
24
+ _type = PropType::Bool;
25
+ _boolValue = value.getBool();
26
+ } else if (value.isString()) {
27
+ _type = PropType::String;
28
+ _stringValue = value.asString(runtime).utf8(runtime);
29
+ } else if (value.isUndefined()) {
30
+ _type = PropType::Undefined;
31
+ } else if (value.isNull()) {
32
+ _type = PropType::Null;
33
+ } else if (value.isObject()) {
34
+ setObject(runtime, value);
35
+ } else {
36
+ throw std::runtime_error("Could not store jsi::Value of provided type");
37
+ }
38
+ }
39
+
40
+ bool JsiValue::getAsBool() const {
41
+ if (_type != PropType::Bool) {
42
+ throw std::runtime_error("Expected type bool, got " +
43
+ getTypeAsString(_type));
44
+ }
45
+ return _boolValue;
46
+ }
47
+
48
+ double JsiValue::getAsNumber() const {
49
+ if (_type != PropType::Number) {
50
+ throw std::runtime_error("Expected type number, got " +
51
+ getTypeAsString(_type));
52
+ }
53
+ return _numberValue;
54
+ }
55
+
56
+ const std::string &JsiValue::getAsString() const {
57
+ if (_type == PropType::Number) {
58
+ return std::move(std::to_string(_numberValue));
59
+ }
60
+
61
+ if (_type != PropType::String) {
62
+ throw std::runtime_error("Expected type string, got " +
63
+ getTypeAsString(_type));
64
+ }
65
+ return _stringValue;
66
+ }
67
+
68
+ const std::vector<JsiValue> &JsiValue::getAsArray() const {
69
+ if (_type != PropType::Array) {
70
+ throw std::runtime_error("Expected type array, got " +
71
+ getTypeAsString(_type));
72
+ }
73
+ return _array;
74
+ }
75
+
76
+ const JsiValue &JsiValue::getValue(PropId name) const {
77
+ if (_type != PropType::Object) {
78
+ throw std::runtime_error("Expected type object, got " +
79
+ getTypeAsString(_type));
80
+ }
81
+ return _props.at(name);
82
+ }
83
+
84
+ bool JsiValue::hasValue(PropId name) const {
85
+ if (_type != PropType::Object) {
86
+ throw std::runtime_error("Expected type object, got " +
87
+ getTypeAsString(_type));
88
+ }
89
+ return _props.count(name) > 0;
90
+ }
91
+
92
+ std::vector<PropId> JsiValue::getKeys() const {
93
+ if (_type != PropType::Object) {
94
+ throw std::runtime_error("Expected type object, got " +
95
+ getTypeAsString(_type));
96
+ }
97
+ return _keysCache;
98
+ }
99
+
100
+ std::shared_ptr<jsi::HostObject> JsiValue::getAsHostObject() const {
101
+ if (_type != PropType::HostObject) {
102
+ throw std::runtime_error("Expected type host object, got " +
103
+ getTypeAsString(_type));
104
+ }
105
+ return _hostObject;
106
+ }
107
+
108
+ jsi::HostFunctionType JsiValue::getAsHostFunction() const {
109
+ if (_type != PropType::HostFunction) {
110
+ throw std::runtime_error("Expected type host function, got " +
111
+ getTypeAsString(_type));
112
+ }
113
+ return _hostFunction;
114
+ }
115
+
116
+ const jsi::HostFunctionType JsiValue::getAsFunction() const {
117
+ return getAsHostFunction();
118
+ }
119
+
120
+ std::string JsiValue::asString() const {
121
+ switch (_type) {
122
+ case PropType::Null:
123
+ return "(null)";
124
+ case PropType::Undefined:
125
+ return "(undefined)";
126
+ case PropType::Number:
127
+ return std::to_string(_numberValue);
128
+ case PropType::Bool:
129
+ return std::to_string(_boolValue);
130
+ case PropType::String:
131
+ return _stringValue;
132
+ case PropType::Object:
133
+ return "[Object]";
134
+ case PropType::Array:
135
+ return "[Array]";
136
+ case PropType::HostObject:
137
+ return "[HostObject]";
138
+ case PropType::HostFunction:
139
+ return "[HostFunction]";
140
+ }
141
+ }
142
+
143
+ jsi::Value JsiValue::getAsJsiValue(jsi::Runtime &runtime) const {
144
+ switch (_type) {
145
+ case PropType::Undefined:
146
+ return jsi::Value::undefined();
147
+ case PropType::Null:
148
+ return jsi::Value::null();
149
+ case PropType::Number:
150
+ return _numberValue;
151
+ case PropType::Bool:
152
+ return _boolValue;
153
+ case PropType::String:
154
+ return jsi::String::createFromUtf8(runtime, _stringValue);
155
+ case PropType::Object:
156
+ return getObject(runtime);
157
+ case PropType::Array:
158
+ return getArray(runtime);
159
+ case PropType::HostObject:
160
+ return getHostObject(runtime);
161
+ case PropType::HostFunction:
162
+ return getHostFunction(runtime);
163
+ }
164
+ }
165
+
166
+ std::string JsiValue::getTypeAsString(PropType type) {
167
+ switch (type) {
168
+ case PropType::Undefined:
169
+ return "undefined";
170
+ case PropType::Null:
171
+ return "null";
172
+ case PropType::Number:
173
+ return "number";
174
+ case PropType::Bool:
175
+ return "boolean";
176
+ case PropType::String:
177
+ return "string";
178
+ case PropType::Object:
179
+ return "object";
180
+ case PropType::Array:
181
+ return "array";
182
+ case PropType::HostObject:
183
+ return "hostobject";
184
+ case PropType::HostFunction:
185
+ return "hostfunction";
186
+ }
187
+ }
188
+
189
+ void JsiValue::setObject(jsi::Runtime &runtime, const jsi::Value &value) {
190
+ auto obj = value.asObject(runtime);
191
+ if (obj.isFunction(runtime)) {
192
+ setFunction(runtime, value);
193
+ } else if (obj.isArray(runtime)) {
194
+ setArray(runtime, obj);
195
+ } else if (obj.isHostObject(runtime)) {
196
+ setHostObject(runtime, obj);
197
+ } else {
198
+ _type = PropType::Object;
199
+ // Read object keys
200
+ auto keys = obj.getPropertyNames(runtime);
201
+ size_t size = keys.size(runtime);
202
+ _keysCache.clear();
203
+ _keysCache.reserve(size);
204
+ _props.clear();
205
+ _props.reserve(size);
206
+
207
+ for (size_t i = 0; i < size; ++i) {
208
+ auto key = JsiPropId::get(
209
+ keys.getValueAtIndex(runtime, i).asString(runtime).utf8(runtime));
210
+ try {
211
+ _props.try_emplace(key, runtime, obj.getProperty(runtime, key));
212
+ _keysCache.push_back(key);
213
+ } catch (jsi::JSError e) {
214
+ throw jsi::JSError(runtime,
215
+ "Could not set property for key " +
216
+ std::string(key) + ":\n" + e.getMessage(),
217
+ e.getStack());
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ jsi::Object JsiValue::getObject(jsi::Runtime &runtime) const {
224
+ assert(_type == PropType::Object);
225
+ auto obj = jsi::Object(runtime);
226
+ for (auto &p : _props) {
227
+ obj.setProperty(runtime, p.first, p.second.getAsJsiValue(runtime));
228
+ }
229
+ return obj;
230
+ }
231
+
232
+ bool JsiValue::operator!=(const JsiValue &other) const {
233
+ return !(this->operator==(other));
234
+ }
235
+
236
+ bool JsiValue::operator==(const JsiValue &other) const {
237
+
238
+ if (other.getType() != getType()) {
239
+ return false;
240
+ }
241
+
242
+ switch (_type) {
243
+ case PropType::Null:
244
+ case PropType::Undefined:
245
+ return true;
246
+ case PropType::Number:
247
+ return _numberValue == other.getAsNumber();
248
+ case PropType::Bool:
249
+ return _boolValue == other.getAsBool();
250
+ case PropType::String:
251
+ return _stringValue == other.getAsString();
252
+ case PropType::Object: {
253
+ if (_props.size() != other.getProps().size()) {
254
+ return false;
255
+ }
256
+ for (auto &p : _props) {
257
+ auto t = p.second.operator==(other.getValue(p.first));
258
+ if (!t) {
259
+ return false;
260
+ }
261
+ }
262
+ return true;
263
+ }
264
+ case PropType::Array: {
265
+ auto otherArr = other.getAsArray();
266
+ if (_array.size() != otherArr.size()) {
267
+ return false;
268
+ }
269
+ for (size_t i = 0; i < _array.size(); ++i) {
270
+ if (!_array[i].operator==(otherArr[i])) {
271
+ return false;
272
+ }
273
+ }
274
+ return true;
275
+ }
276
+ case PropType::HostObject:
277
+ return getAsHostObject() == other.getAsHostObject();
278
+ case PropType::HostFunction:
279
+ // Unable to compare host functions
280
+ return false;
281
+ }
282
+
283
+ throw std::runtime_error(
284
+ "Wrong type in equals call. Should not happen. File a bug.");
285
+
286
+ return false;
287
+ }
288
+
289
+ void JsiValue::setFunction(jsi::Runtime &runtime, const jsi::Value &value) {
290
+ auto func = value.asObject(runtime).asFunction(runtime);
291
+ if (func.isHostFunction(runtime)) {
292
+ _type = PropType::HostFunction;
293
+ _hostFunction = func.getHostFunction(runtime);
294
+ } else {
295
+ _type = PropType::HostFunction;
296
+ auto obj = std::make_shared<jsi::Object>(value.asObject(runtime));
297
+ _hostFunction = [obj](jsi::Runtime &runtime, const jsi::Value &thisValue,
298
+ const jsi::Value *arguments,
299
+ size_t count) -> jsi::Value {
300
+ auto func = obj->asFunction(runtime);
301
+ if (thisValue.isNull() || thisValue.isUndefined()) {
302
+ return func.call(runtime, arguments, count);
303
+ } else {
304
+ return func.callWithThis(runtime, thisValue.asObject(runtime),
305
+ arguments, count);
306
+ }
307
+ };
308
+ }
309
+ }
310
+
311
+ jsi::Object JsiValue::getHostFunction(jsi::Runtime &runtime) const {
312
+ assert(_type == PropType::HostFunction);
313
+ return jsi::Function::createFromHostFunction(
314
+ runtime, jsi::PropNameID::forUtf8(runtime, "fn"), 0, _hostFunction);
315
+ }
316
+
317
+ void JsiValue::setArray(jsi::Runtime &runtime, const jsi::Object &obj) {
318
+ _type = PropType::Array;
319
+ auto arr = obj.asArray(runtime);
320
+ size_t size = arr.size(runtime);
321
+ _array.reserve(size);
322
+ for (size_t i = 0; i < size; ++i) {
323
+ _array.emplace_back(runtime, arr.getValueAtIndex(runtime, i));
324
+ }
325
+ }
326
+
327
+ jsi::Array JsiValue::getArray(jsi::Runtime &runtime) const {
328
+ assert(_type == PropType::Array);
329
+ jsi::Array arr = jsi::Array(runtime, _array.size());
330
+ for (size_t i = 0; i < _array.size(); ++i) {
331
+ arr.setValueAtIndex(runtime, i, _array[i].getAsJsiValue(runtime));
332
+ }
333
+ return arr;
334
+ }
335
+
336
+ void JsiValue::setHostObject(jsi::Runtime &runtime, const jsi::Object &obj) {
337
+ _type = PropType::HostObject;
338
+ _hostObject = obj.asHostObject(runtime);
339
+ }
340
+
341
+ jsi::Object JsiValue::getHostObject(jsi::Runtime &runtime) const {
342
+ assert(_type == PropType::HostObject);
343
+ return jsi::Object::createFromHostObject(runtime, _hostObject);
344
+ }
345
+
346
+ } // namespace RNJsi