@shopify/react-native-skia 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. package/android/CMakeLists.txt +4 -8
  2. package/android/build.gradle +9 -2
  3. package/android/cpp/jni/JniPlatformContext.cpp +7 -7
  4. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +2 -2
  6. package/android/cpp/jni/include/JniSkiaDomView.h +4 -4
  7. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +4 -4
  9. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +245 -0
  10. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +33 -0
  11. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +3 -3
  12. package/android/cpp/rnskia-android/RNSkAndroidView.h +1 -1
  13. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +2 -2
  14. package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +4 -4
  15. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +32 -2
  16. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +7 -4
  17. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +16 -1
  18. package/cpp/api/JsiSkAnimatedImage.h +1 -1
  19. package/cpp/api/JsiSkCanvas.h +8 -8
  20. package/cpp/api/JsiSkColor.h +1 -1
  21. package/cpp/api/JsiSkColorFilter.h +1 -1
  22. package/cpp/api/JsiSkColorFilterFactory.h +2 -2
  23. package/cpp/api/JsiSkContourMeasure.h +1 -1
  24. package/cpp/api/JsiSkContourMeasureIter.h +1 -1
  25. package/cpp/api/JsiSkData.h +2 -2
  26. package/cpp/api/JsiSkFont.h +2 -2
  27. package/cpp/api/JsiSkFontMgr.h +1 -1
  28. package/cpp/api/JsiSkFontMgrFactory.h +1 -1
  29. package/cpp/api/JsiSkFontStyle.h +2 -2
  30. package/cpp/api/JsiSkImage.h +2 -2
  31. package/cpp/api/JsiSkImageFilter.h +1 -1
  32. package/cpp/api/JsiSkImageFilterFactory.h +1 -1
  33. package/cpp/api/JsiSkImageInfo.h +1 -1
  34. package/cpp/api/JsiSkMaskFilter.h +1 -1
  35. package/cpp/api/JsiSkMaskFilterFactory.h +1 -1
  36. package/cpp/api/JsiSkMatrix.h +1 -1
  37. package/cpp/api/JsiSkPaint.h +1 -1
  38. package/cpp/api/JsiSkParagraph.h +7 -7
  39. package/cpp/api/JsiSkParagraphBuilder.h +9 -9
  40. package/cpp/api/JsiSkParagraphBuilderFactory.h +4 -4
  41. package/cpp/api/JsiSkParagraphStyle.h +3 -3
  42. package/cpp/api/JsiSkPath.h +11 -11
  43. package/cpp/api/JsiSkPathEffect.h +1 -1
  44. package/cpp/api/JsiSkPathEffectFactory.h +4 -4
  45. package/cpp/api/JsiSkPathFactory.h +2 -2
  46. package/cpp/api/JsiSkPicture.h +1 -1
  47. package/cpp/api/JsiSkPictureFactory.h +2 -2
  48. package/cpp/api/JsiSkPictureRecorder.h +2 -2
  49. package/cpp/api/JsiSkPoint.h +1 -1
  50. package/cpp/api/JsiSkRRect.h +1 -1
  51. package/cpp/api/JsiSkRSXform.h +1 -1
  52. package/cpp/api/JsiSkRect.h +1 -1
  53. package/cpp/api/JsiSkRuntimeEffect.h +1 -1
  54. package/cpp/api/JsiSkRuntimeShaderBuilder.h +1 -1
  55. package/cpp/api/JsiSkSVGFactory.h +1 -1
  56. package/cpp/api/JsiSkShader.h +2 -2
  57. package/cpp/api/JsiSkShaderFactory.h +3 -3
  58. package/cpp/api/JsiSkStrutStyle.h +1 -1
  59. package/cpp/api/JsiSkSurface.h +1 -1
  60. package/cpp/api/JsiSkSurfaceFactory.h +1 -1
  61. package/cpp/api/JsiSkTextBlob.h +1 -1
  62. package/cpp/api/JsiSkTextBlobFactory.h +1 -1
  63. package/cpp/api/JsiSkTextStyle.h +2 -2
  64. package/cpp/api/JsiSkTypeface.h +3 -3
  65. package/cpp/api/JsiSkTypefaceFontProvider.h +2 -2
  66. package/cpp/api/JsiSkVertices.h +1 -1
  67. package/cpp/jsi/JsiHostObject.cpp +1 -1
  68. package/cpp/rnskia/RNSkDomView.cpp +1 -1
  69. package/cpp/rnskia/RNSkDomView.h +3 -3
  70. package/cpp/rnskia/RNSkManager.cpp +5 -5
  71. package/cpp/rnskia/RNSkPictureView.h +3 -3
  72. package/cpp/rnskia/RNSkPlatformContext.h +5 -5
  73. package/cpp/rnskia/RNSkView.h +2 -2
  74. package/cpp/rnskia/dom/base/ConcatablePaint.h +6 -6
  75. package/cpp/rnskia/dom/base/Declaration.h +1 -1
  76. package/cpp/rnskia/dom/base/DeclarationContext.h +7 -7
  77. package/cpp/rnskia/dom/base/DrawingContext.h +3 -3
  78. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +2 -2
  79. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
  80. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +1 -1
  81. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +1 -1
  82. package/cpp/rnskia/dom/nodes/JsiPathNode.h +1 -1
  83. package/cpp/rnskia/dom/nodes/JsiPointsNode.h +1 -1
  84. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +1 -1
  85. package/cpp/rnskia/dom/props/BlendModeProp.h +1 -1
  86. package/cpp/rnskia/dom/props/BoxShadowProps.h +1 -1
  87. package/cpp/rnskia/dom/props/CircleProp.h +1 -1
  88. package/cpp/rnskia/dom/props/ClipProp.h +2 -2
  89. package/cpp/rnskia/dom/props/PaintProps.h +1 -1
  90. package/cpp/rnskia/dom/props/PathProp.h +1 -1
  91. package/cpp/rnskia/dom/props/PointProp.h +1 -1
  92. package/cpp/rnskia/dom/props/PointsProp.h +1 -1
  93. package/cpp/rnskia/dom/props/RRectProp.h +2 -2
  94. package/cpp/rnskia/dom/props/RSXformProp.h +1 -1
  95. package/cpp/rnskia/dom/props/RadiusProp.h +1 -1
  96. package/cpp/rnskia/dom/props/RectProp.h +1 -1
  97. package/cpp/rnskia/dom/props/StrokeProps.h +1 -1
  98. package/cpp/rnskia/dom/props/TileModeProp.h +1 -1
  99. package/cpp/rnskia/dom/props/UniformsProp.h +1 -1
  100. package/cpp/rnskia/dom/props/VertexModeProp.h +1 -1
  101. package/cpp/rnskia/dom/props/VerticesProps.h +1 -1
  102. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +1158 -0
  103. package/cpp/utils/RNSkTypedArray.h +1 -1
  104. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +6 -6
  105. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +3 -3
  106. package/ios/RNSkia-iOS/SkiaDomView.mm +7 -7
  107. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +7 -7
  108. package/ios/RNSkia-iOS/SkiaManager.h +1 -1
  109. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +1 -1
  110. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +5 -5
  111. package/ios/RNSkia-iOS/SkiaPictureView.mm +7 -7
  112. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +4 -4
  113. package/ios/RNSkia-iOS/SkiaUIView.h +3 -3
  114. package/ios/RNSkia-iOS/SkiaUIView.mm +2 -2
  115. package/ios/RNSkia-iOS/ViewScreenshotService.h +1 -1
  116. package/ios/RNSkia-iOS/ViewScreenshotService.mm +1 -1
  117. package/lib/commonjs/headless/index.d.ts +4 -1
  118. package/lib/commonjs/headless/index.js +12 -2
  119. package/lib/commonjs/headless/index.js.map +1 -1
  120. package/lib/commonjs/renderer/Offscreen.js +1 -0
  121. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  122. package/lib/commonjs/skia/web/JsiSkImage.d.ts +2 -1
  123. package/lib/commonjs/skia/web/JsiSkImage.js +27 -2
  124. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  125. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +2 -1
  126. package/lib/commonjs/skia/web/JsiSkSurface.js +5 -1
  127. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  128. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +13 -2
  129. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  130. package/lib/module/headless/index.d.ts +4 -1
  131. package/lib/module/headless/index.js +9 -2
  132. package/lib/module/headless/index.js.map +1 -1
  133. package/lib/module/renderer/Offscreen.js +1 -0
  134. package/lib/module/renderer/Offscreen.js.map +1 -1
  135. package/lib/module/skia/web/JsiSkImage.d.ts +2 -1
  136. package/lib/module/skia/web/JsiSkImage.js +27 -2
  137. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  138. package/lib/module/skia/web/JsiSkSurface.d.ts +2 -1
  139. package/lib/module/skia/web/JsiSkSurface.js +5 -1
  140. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  141. package/lib/module/skia/web/JsiSkSurfaceFactory.js +13 -2
  142. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  143. package/lib/typescript/src/headless/index.d.ts +4 -1
  144. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +2 -1
  145. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +2 -1
  146. package/package.json +1 -1
  147. package/src/headless/index.ts +9 -2
  148. package/src/renderer/Offscreen.tsx +1 -0
  149. package/src/skia/web/JsiSkImage.ts +36 -5
  150. package/src/skia/web/JsiSkSurface.ts +8 -1
  151. package/src/skia/web/JsiSkSurfaceFactory.ts +17 -2
@@ -1,6 +1,6 @@
1
1
  #pragma once
2
2
 
3
- #include "SkImage.h"
3
+ #include "include/core/SkImage.h"
4
4
  #include <jsi/jsi.h>
5
5
 
6
6
  namespace RNSkia {
@@ -1,13 +1,13 @@
1
- #import <RNSkLog.h>
2
- #import <RNSkMetalCanvasProvider.h>
3
- #import <SkiaMetalSurfaceFactory.h>
1
+ #import "RNSkMetalCanvasProvider.h"
2
+ #import "RNSkLog.h"
3
+ #import "SkiaMetalSurfaceFactory.h"
4
4
 
5
5
  #pragma clang diagnostic push
6
6
  #pragma clang diagnostic ignored "-Wdocumentation"
7
7
 
8
- #import "SkCanvas.h"
9
- #import "SkColorSpace.h"
10
- #import "SkSurface.h"
8
+ #import "include/core/SkCanvas.h"
9
+ #import "include/core/SkColorSpace.h"
10
+ #import "include/core/SkSurface.h"
11
11
 
12
12
  #import <include/gpu/GrBackendSurface.h>
13
13
  #import <include/gpu/GrDirectContext.h>
@@ -4,13 +4,13 @@
4
4
  #include <thread>
5
5
  #include <utility>
6
6
 
7
- #include <SkiaMetalSurfaceFactory.h>
7
+ #include "SkiaMetalSurfaceFactory.h"
8
8
 
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include "SkFontMgr.h"
13
- #include "SkSurface.h"
12
+ #include "include/core/SkFontMgr.h"
13
+ #include "include/core/SkSurface.h"
14
14
 
15
15
  #include "include/ports/SkFontMgr_mac_ct.h"
16
16
 
@@ -1,13 +1,13 @@
1
1
  #ifdef RCT_NEW_ARCH_ENABLED
2
- #import <SkiaDomView.h>
2
+ #import "SkiaDomView.h"
3
3
 
4
- #import <RNSkDomView.h>
5
- #import <RNSkIOSView.h>
6
- #import <RNSkPlatformContext.h>
4
+ #import "RNSkDomView.h"
5
+ #import "RNSkIOSView.h"
6
+ #import "RNSkPlatformContext.h"
7
7
 
8
- #import <RNSkiaModule.h>
9
- #import <SkiaManager.h>
10
- #import <SkiaUIView.h>
8
+ #import "RNSkiaModule.h"
9
+ #import "SkiaManager.h"
10
+ #import "SkiaUIView.h"
11
11
 
12
12
  #import <React/RCTBridge+Private.h>
13
13
  #import <React/RCTConversions.h>
@@ -1,14 +1,14 @@
1
1
 
2
+ #include "SkiaDomViewManager.h"
2
3
  #include <React/RCTBridge+Private.h>
3
- #include <SkiaDomViewManager.h>
4
4
 
5
- #include <RNSkDomView.h>
6
- #include <RNSkIOSView.h>
7
- #include <RNSkPlatformContext.h>
5
+ #include "RNSkDomView.h"
6
+ #include "RNSkIOSView.h"
7
+ #include "RNSkPlatformContext.h"
8
8
 
9
- #include <RNSkiaModule.h>
10
- #include <SkiaManager.h>
11
- #include <SkiaUIView.h>
9
+ #include "RNSkiaModule.h"
10
+ #include "SkiaManager.h"
11
+ #include "SkiaUIView.h"
12
12
 
13
13
  @implementation SkiaDomViewManager
14
14
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  #import <React/RCTBridge.h>
4
4
 
5
- #import <RNSkManager.h>
5
+ #import "RNSkManager.h"
6
6
 
7
7
  @interface SkiaManager : NSObject
8
8
 
@@ -3,7 +3,7 @@
3
3
  #pragma clang diagnostic push
4
4
  #pragma clang diagnostic ignored "-Wdocumentation"
5
5
 
6
- #import "SkCanvas.h"
6
+ #import "include/core/SkCanvas.h"
7
7
  #import <include/gpu/GrDirectContext.h>
8
8
 
9
9
  #pragma clang diagnostic pop
@@ -1,13 +1,13 @@
1
- #import <RNSkLog.h>
1
+ #import "RNSkLog.h"
2
2
 
3
- #include <SkiaMetalSurfaceFactory.h>
3
+ #include "SkiaMetalSurfaceFactory.h"
4
4
 
5
5
  #pragma clang diagnostic push
6
6
  #pragma clang diagnostic ignored "-Wdocumentation"
7
7
 
8
- #import "SkCanvas.h"
9
- #import "SkColorSpace.h"
10
- #import "SkSurface.h"
8
+ #import "include/core/SkCanvas.h"
9
+ #import "include/core/SkColorSpace.h"
10
+ #import "include/core/SkSurface.h"
11
11
 
12
12
  #import <include/gpu/GrBackendSurface.h>
13
13
  #import <include/gpu/GrDirectContext.h>
@@ -1,13 +1,13 @@
1
1
  #ifdef RCT_NEW_ARCH_ENABLED
2
- #import <SkiaPictureView.h>
2
+ #import "SkiaPictureView.h"
3
3
 
4
- #import <RNSkIOSView.h>
5
- #import <RNSkPictureView.h>
6
- #import <RNSkPlatformContext.h>
4
+ #import "RNSkIOSView.h"
5
+ #import "RNSkPictureView.h"
6
+ #import "RNSkPlatformContext.h"
7
7
 
8
- #import <RNSkiaModule.h>
9
- #import <SkiaManager.h>
10
- #import <SkiaUIView.h>
8
+ #import "RNSkiaModule.h"
9
+ #import "SkiaManager.h"
10
+ #import "SkiaUIView.h"
11
11
 
12
12
  #import <React/RCTBridge+Private.h>
13
13
  #import <React/RCTConversions.h>
@@ -2,13 +2,13 @@
2
2
  #include "SkiaPictureViewManager.h"
3
3
  #include <React/RCTBridge+Private.h>
4
4
 
5
- #include <RNSkIOSView.h>
6
- #include <RNSkPictureView.h>
7
- #include <RNSkPlatformContext.h>
5
+ #include "RNSkIOSView.h"
6
+ #include "RNSkPictureView.h"
7
+ #include "RNSkPlatformContext.h"
8
8
 
9
+ #include "RNSkiaModule.h"
9
10
  #include "SkiaManager.h"
10
11
  #include "SkiaUIView.h"
11
- #include <RNSkiaModule.h>
12
12
 
13
13
  @implementation SkiaPictureViewManager
14
14
 
@@ -6,9 +6,9 @@
6
6
  #import <CoreFoundation/CoreFoundation.h>
7
7
  #import <UIKit/UIKit.h>
8
8
 
9
- #import <RNSkManager.h>
10
- #import <RNSkiOSView.h>
11
- #import <SkiaManager.h>
9
+ #import "RNSkManager.h"
10
+ #import "RNSkiOSView.h"
11
+ #import "SkiaManager.h"
12
12
 
13
13
  #if RCT_NEW_ARCH_ENABLED
14
14
  #import <React/RCTViewComponentView.h>
@@ -1,12 +1,12 @@
1
1
  #import <React/RCTBridge.h>
2
2
 
3
+ #import "RNSkiaModule.h"
3
4
  #import "SkiaUIView.h"
4
- #import <RNSkiaModule.h>
5
5
 
6
6
  #include <utility>
7
7
  #include <vector>
8
8
 
9
- #import <RNSkManager.h>
9
+ #import "RNSkManager.h"
10
10
 
11
11
  @implementation SkiaUIView {
12
12
  std::shared_ptr<RNSkBaseiOSView> _impl;
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include "SkImage.h"
11
+ #include "include/core/SkImage.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14
 
@@ -4,7 +4,7 @@
4
4
  #pragma clang diagnostic push
5
5
  #pragma clang diagnostic ignored "-Wdocumentation"
6
6
 
7
- #include "SkData.h"
7
+ #include "include/core/SkData.h"
8
8
 
9
9
  #pragma clang diagnostic pop
10
10
 
@@ -1,5 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { SkSurface } from "../skia";
3
3
  export * from "../renderer/components";
4
- export declare const makeOffscreenSurface: (width: number, height: number) => any;
4
+ export declare const makeOffscreenSurface: (width: number, height: number) => SkSurface;
5
+ export declare const getSkiaExports: () => {
6
+ Skia: import("../skia/types").Skia;
7
+ };
5
8
  export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => import("../skia").SkImage;
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  makeOffscreenSurface: true,
8
+ getSkiaExports: true,
8
9
  drawOffscreen: true
9
10
  };
10
- exports.makeOffscreenSurface = exports.drawOffscreen = void 0;
11
+ exports.makeOffscreenSurface = exports.getSkiaExports = exports.drawOffscreen = void 0;
11
12
  var _web = require("../skia/web");
12
13
  var _Reconciler = require("../renderer/Reconciler");
13
14
  var _types = require("../dom/types");
@@ -26,7 +27,6 @@ Object.keys(_components).forEach(function (key) {
26
27
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
27
28
  // @ts-ignore
28
29
 
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
30
  let Skia;
31
31
  const makeOffscreenSurface = (width, height) => {
32
32
  if (!Skia) {
@@ -39,12 +39,22 @@ const makeOffscreenSurface = (width, height) => {
39
39
  return surface;
40
40
  };
41
41
  exports.makeOffscreenSurface = makeOffscreenSurface;
42
+ const getSkiaExports = () => {
43
+ if (!Skia) {
44
+ Skia = (0, _web.JsiSkApi)(CanvasKit);
45
+ }
46
+ return {
47
+ Skia
48
+ };
49
+ };
50
+ exports.getSkiaExports = getSkiaExports;
42
51
  const drawOffscreen = (surface, element) => {
43
52
  const root = new _Reconciler.SkiaRoot(Skia, false);
44
53
  root.render(element);
45
54
  const canvas = surface.getCanvas();
46
55
  const ctx = new _types.JsiDrawingContext(Skia, canvas);
47
56
  root.dom.render(ctx);
57
+ root.unmount();
48
58
  surface.flush();
49
59
  return surface.makeImageSnapshot();
50
60
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_web","require","_Reconciler","_types","_components","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Skia","makeOffscreenSurface","width","height","JsiSkApi","CanvasKit","surface","Surface","MakeOffscreen","Error","drawOffscreen","element","root","SkiaRoot","render","canvas","getCanvas","ctx","JsiDrawingContext","dom","flush","makeImageSnapshot"],"sources":["index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { ReactNode } from \"react\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { SkiaRoot } from \"../renderer/Reconciler\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkSurface } from \"../skia\";\n\nexport * from \"../renderer/components\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Skia: any;\n\nexport const makeOffscreenSurface = (width: number, height: number) => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n const surface = Skia.Surface.MakeOffscreen(width, height);\n if (surface === null) {\n throw new Error(\"Couldn't create surface!\");\n }\n return surface;\n};\n\nexport const drawOffscreen = (surface: SkSurface, element: ReactNode) => {\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const canvas = surface.getCanvas();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n surface.flush();\n return surface.makeImageSnapshot();\n};\n"],"mappings":";;;;;;;;;;AAKA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,G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MAAM,CAACG,GAAG,CAAC;EACpBX,OAAO,CAACc,KAAK,CAAC,CAAC;EACf,OAAOd,OAAO,CAACe,iBAAiB,CAAC,CAAC;AACpC,CAAC;AAACzB,OAAA,CAAAc,aAAA,GAAAA,aAAA"}
1
+ {"version":3,"names":["_web","require","_Reconciler","_types","_components","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Skia","makeOffscreenSurface","width","height","JsiSkApi","CanvasKit","surface","Surface","MakeOffscreen","Error","getSkiaExports","drawOffscreen","element","root","SkiaRoot","render","canvas","getCanvas","ctx","JsiDrawingContext","dom","unmount","flush","makeImageSnapshot"],"sources":["index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { ReactNode } from \"react\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { SkiaRoot } from \"../renderer/Reconciler\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkSurface } from \"../skia\";\n\nexport * from \"../renderer/components\";\n\nlet Skia: ReturnType<typeof JsiSkApi>;\n\nexport const makeOffscreenSurface = (width: number, height: number) => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n const surface = Skia.Surface.MakeOffscreen(width, height);\n if (surface === null) {\n throw new Error(\"Couldn't create surface!\");\n }\n return surface;\n};\n\nexport const getSkiaExports = () => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n return { Skia };\n};\n\nexport const drawOffscreen = (surface: SkSurface, element: ReactNode) => {\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const canvas = surface.getCanvas();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n root.unmount();\n surface.flush();\n return surface.makeImageSnapshot();\n};\n"],"mappings":";;;;;;;;;;;AAKA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA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E,KAAK,CAAC;EACtCa,IAAI,CAACE,MAAM,CAACH,OAAO,CAAC;EACpB,MAAMI,MAAM,GAAGV,OAAO,CAACW,SAAS,CAAC,CAAC;EAClC,MAAMC,GAAG,GAAG,IAAIC,wBAAiB,CAACnB,IAAI,EAAEgB,MAAM,CAAC;EAC/CH,IAAI,CAACO,GAAG,CAACL,MAAM,CAACG,GAAG,CAAC;EACpBL,IAAI,CAACQ,OAAO,CAAC,CAAC;EACdf,OAAO,CAACgB,KAAK,CAAC,CAAC;EACf,OAAOhB,OAAO,CAACiB,iBAAiB,CAAC,CAAC;AACpC,CAAC;AAAC3B,OAAA,CAAAe,aAAA,GAAAA,aAAA"}
@@ -23,6 +23,7 @@ const drawAsPicture = element => {
23
23
  const ctx = new _types.JsiDrawingContext(_skia.Skia, canvas);
24
24
  root.dom.render(ctx);
25
25
  const picture = recorder.finishRecordingAsPicture();
26
+ root.unmount();
26
27
  return picture;
27
28
  };
28
29
  exports.drawAsPicture = drawAsPicture;
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_skia","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","dom","picture","finishRecordingAsPicture","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, 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) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\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 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,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;AACO,MAAMI,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDC,kBAAQ,CAACC,EAAE,KAAK,KAAK;AAEzB,CAAC;AAACC,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEK,MAAMK,aAAa,GAAIC,OAAqB,IAAK;EACtD,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAAC,CAAC;EACxC,MAAMC,IAAI,GAAG,IAAIC,oBAAQ,CAACL,UAAI,EAAE,KAAK,CAAC;EACtCI,IAAI,CAACE,MAAM,CAACR,OAAO,CAAC;EACpB,MA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_WORKLET","Platform","OS","exports","drawAsPicture","element","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","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, 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) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\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,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAA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K,GAAGJ,EAAE,EACfF,IAAI,CAACO,MAAM,GAAGL,EAChB,CAAE;EACF,MAAMd,MAAM,GAAGe,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCpB,MAAM,CAACqB,KAAK,CAACP,EAAE,EAAEA,EAAE,CAAC;EACpBd,MAAM,CAACsB,WAAW,CAACd,OAAO,CAAC;EAC3BO,OAAO,CAACQ,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGT,OAAO,CAACU,iBAAiB,CAAC,CAAC;EACzC;EACA,IAAI,CAACnC,cAAc,CAAC,CAAC,IAAIE,kBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IAC9C,OAAO+B,KAAK,CAACE,mBAAmB,CAAC,CAAC;EACpC,CAAC,MAAM;IACL,OAAOF,KAAK;EACd;AACF,CAAC;AAAC9B,OAAA,CAAAmB,sBAAA,GAAAA,sBAAA"}
@@ -3,7 +3,8 @@ import type { FilterMode, MipmapMode, SkImage, SkMatrix, SkShader, TileMode, Ima
3
3
  import { HostObject } from "./Host";
4
4
  export declare const toBase64String: (bytes: Uint8Array) => string;
5
5
  export declare class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
6
- constructor(CanvasKit: CanvasKit, ref: Image);
6
+ private releaseCtx?;
7
+ constructor(CanvasKit: CanvasKit, ref: Image, releaseCtx?: (() => void) | undefined);
7
8
  height(): number;
8
9
  width(): number;
9
10
  getImageInfo(): ImageInfo;
@@ -38,10 +38,14 @@ const toBase64String = bytes => {
38
38
  };
39
39
  exports.toBase64String = toBase64String;
40
40
  class JsiSkImage extends _Host.HostObject {
41
- constructor(CanvasKit, ref) {
41
+ constructor(CanvasKit, ref, releaseCtx) {
42
42
  super(CanvasKit, ref, "Image");
43
+ this.releaseCtx = releaseCtx;
43
44
  _defineProperty(this, "dispose", () => {
44
45
  this.ref.delete();
46
+ if (this.releaseCtx) {
47
+ this.releaseCtx();
48
+ }
45
49
  });
46
50
  }
47
51
  height() {
@@ -83,6 +87,9 @@ class JsiSkImage extends _Host.HostObject {
83
87
  const bytes = this.encodeToBytes(fmt, quality);
84
88
  return toBase64String(bytes);
85
89
  }
90
+
91
+ // TODO: this is leaking on Web
92
+ // Add signature with allocated buffer
86
93
  readPixels(srcX, srcY, imageInfo) {
87
94
  var _imageInfo$width, _imageInfo$height;
88
95
  const info = this.getImageInfo();
@@ -96,7 +103,25 @@ class JsiSkImage extends _Host.HostObject {
96
103
  return this.ref.readPixels(srcX !== null && srcX !== void 0 ? srcX : 0, srcY !== null && srcY !== void 0 ? srcY : 0, pxInfo);
97
104
  }
98
105
  makeNonTextureImage() {
99
- return new JsiSkImage(this.CanvasKit, this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes()));
106
+ const partialInfo = this.ref.getImageInfo();
107
+ const colorSpace = this.ref.getColorSpace();
108
+ const info = {
109
+ ...partialInfo,
110
+ colorSpace
111
+ };
112
+ var pixelLen = info.width * info.height * 4;
113
+ const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
114
+ const pixels = this.ref.readPixels(0, 0, info, pixelPtr, info.width * 4);
115
+ if (!pixels) {
116
+ throw new Error("Could not create image from bytes");
117
+ }
118
+ const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);
119
+ if (!img) {
120
+ throw new Error("Could not create image from bytes");
121
+ }
122
+ return new JsiSkImage(this.CanvasKit, img, () => {
123
+ this.CanvasKit.Free(pixelPtr);
124
+ });
100
125
  }
101
126
  }
102
127
  exports.JsiSkImage = JsiSkImage;
@@ -1 +1 @@
1
- {"version":3,"names":["_Host","require","_JsiSkMatrix","_JsiSkShader","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","fromCharCode","apply","btoa","exports","JsiSkImage","HostObject","constructor","CanvasKit","ref","delete","height","width","getImageInfo","info","colorType","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","JsiSkShader","getEnum","TileMode","FilterMode","MipmapMode","JsiSkMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","ImageFormat","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","_imageInfo$width","_imageInfo$height","pxInfo","colorSpace","ColorSpace","SRGB","AlphaType","ColorType","makeNonTextureImage","MakeImageFromEncoded"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {\n CanvasKit,\n ImageInfo as CKImageInfo,\n Image,\n} from \"canvaskit-wasm\";\n\nimport type {\n FilterMode,\n MipmapMode,\n SkImage,\n SkMatrix,\n SkShader,\n TileMode,\n ImageFormat,\n ImageInfo,\n} from \"../types\";\n\nimport { getEnum, HostObject } from \"./Host\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js\nexport const toBase64String = (bytes: Uint8Array) => {\n if (typeof Buffer !== \"undefined\") {\n // Are we on node?\n return Buffer.from(bytes).toString(\"base64\");\n } else {\n // From https://stackoverflow.com/a/25644409\n // because the naive solution of\n // btoa(String.fromCharCode.apply(null, bytes));\n // would occasionally throw \"Maximum call stack size exceeded\"\n var CHUNK_SIZE = 0x8000; //arbitrary number\n var index = 0;\n var { length } = bytes;\n var result = \"\";\n var slice;\n while (index < length) {\n slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result += String.fromCharCode.apply(null, slice as any);\n index += CHUNK_SIZE;\n }\n return btoa(result);\n }\n};\n\nexport class JsiSkImage extends HostObject<Image, \"Image\"> implements SkImage {\n constructor(CanvasKit: CanvasKit, ref: Image) {\n super(CanvasKit, ref, \"Image\");\n }\n\n height() {\n return this.ref.height();\n }\n\n width() {\n return this.ref.width();\n }\n\n getImageInfo(): ImageInfo {\n const info = this.ref.getImageInfo();\n return {\n width: info.width,\n height: info.height,\n colorType: info.colorType.value,\n alphaType: info.alphaType.value,\n };\n }\n\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderOptions(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n getEnum(this.CanvasKit.FilterMode, fm),\n getEnum(this.CanvasKit.MipmapMode, mm),\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderCubic(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n B,\n C,\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n encodeToBytes(fmt?: ImageFormat, quality?: number) {\n let result: Uint8Array | null;\n if (fmt && quality) {\n result = this.ref.encodeToBytes(\n getEnum(this.CanvasKit.ImageFormat, fmt),\n quality\n );\n } else if (fmt) {\n result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));\n } else {\n result = this.ref.encodeToBytes();\n }\n if (!result) {\n throw new Error(\"encodeToBytes failed\");\n }\n return result;\n }\n\n encodeToBase64(fmt?: ImageFormat, quality?: number) {\n const bytes = this.encodeToBytes(fmt, quality);\n return toBase64String(bytes);\n }\n\n readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {\n const info = this.getImageInfo();\n const pxInfo: CKImageInfo = {\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n width: imageInfo?.width ?? info.width,\n height: imageInfo?.height ?? info.height,\n alphaType: getEnum(\n this.CanvasKit.AlphaType,\n (imageInfo ?? info).alphaType\n ),\n colorType: getEnum(\n this.CanvasKit.ColorType,\n (imageInfo ?? info).colorType\n ),\n };\n return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);\n }\n\n dispose = () => {\n this.ref.delete();\n };\n\n makeNonTextureImage(): SkImage {\n return new JsiSkImage(\n this.CanvasKit,\n this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes())!\n );\n }\n}\n"],"mappings":";;;;;;AAiBA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAA4C,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAE,MAAA,CAAAF,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAI,CAAA,2BAAAJ,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAK,CAAA,GAAAL,CAAA,CAAAM,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAJ,CAAA,GAAAI,CAAA,CAAAG,IAAA,CAAAR,CAAA,EAAAI,CAAA,uCAAAH,CAAA,SAAAA,CAAA,YAAAQ,SAAA,yEAAAL,CAAA,GAAAD,MAAA,GAAAO,MAAA,EAAAV,CAAA;AAE5C;AACO,MAAMW,cAAc,GAAIC,KAAiB,IAAK;EACnD,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC;IACA,OAAOA,MAAM,CAACC,IAAI,CAACF,KAAK,CAAC,CAACG,QAAQ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ChB,SAAS,CAAC0C,SAAS,EACxB,CAACP,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI7B,IAAI,EAAEE,SACtB,CAAC;MACDD,SAAS,EAAE,IAAAS,aAAO,EAChB,IAAI,CAAChB,SAAS,CAAC2C,SAAS,EACxB,CAACR,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI7B,IAAI,EAAEC,SACtB;IACF,CAAC;IACD,OAAO,IAAI,CAACN,GAAG,CAAC+B,UAAU,CAACC,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,CAAC,EAAEC,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,CAAC,EAAEI,MAAM,CAAC;EAC1D;EAMAM,mBAAmBA,CAAA,EAAY;IAC7B,OAAO,IAAI/C,UAAU,CACnB,IAAI,CAACG,SAAS,EACd,IAAI,CAACA,SAAS,CAAC6C,oBAAoB,CAAC,IAAI,CAACnB,aAAa,CAAC,CAAC,CAC1D,CAAC;EACH;AACF;AAAC9B,OAAA,CAAAC,UAAA,GAAAA,UAAA"}
1
+ {"version":3,"names":["_Host","require","_JsiSkMatrix","_JsiSkShader","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","fromCharCode","apply","btoa","exports","JsiSkImage","HostObject","constructor","CanvasKit","ref","releaseCtx","delete","height","width","getImageInfo","info","colorType","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","JsiSkShader","getEnum","TileMode","FilterMode","MipmapMode","JsiSkMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","ImageFormat","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","_imageInfo$width","_imageInfo$height","pxInfo","colorSpace","ColorSpace","SRGB","AlphaType","ColorType","makeNonTextureImage","partialInfo","getColorSpace","pixelLen","pixelPtr","Malloc","Uint8Array","pixels","img","MakeImage","Free"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {\n CanvasKit,\n ImageInfo as CKImageInfo,\n Image,\n} from \"canvaskit-wasm\";\n\nimport type {\n FilterMode,\n MipmapMode,\n SkImage,\n SkMatrix,\n SkShader,\n TileMode,\n ImageFormat,\n ImageInfo,\n} from \"../types\";\n\nimport { getEnum, HostObject } from \"./Host\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js\nexport const toBase64String = (bytes: Uint8Array) => {\n if (typeof Buffer !== \"undefined\") {\n // Are we on node?\n return Buffer.from(bytes).toString(\"base64\");\n } else {\n // From https://stackoverflow.com/a/25644409\n // because the naive solution of\n // btoa(String.fromCharCode.apply(null, bytes));\n // would occasionally throw \"Maximum call stack size exceeded\"\n var CHUNK_SIZE = 0x8000; //arbitrary number\n var index = 0;\n var { length } = bytes;\n var result = \"\";\n var slice;\n while (index < length) {\n slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result += String.fromCharCode.apply(null, slice as any);\n index += CHUNK_SIZE;\n }\n return btoa(result);\n }\n};\n\nexport class JsiSkImage extends HostObject<Image, \"Image\"> implements SkImage {\n constructor(\n CanvasKit: CanvasKit,\n ref: Image,\n private releaseCtx?: () => void\n ) {\n super(CanvasKit, ref, \"Image\");\n }\n\n height() {\n return this.ref.height();\n }\n\n width() {\n return this.ref.width();\n }\n\n getImageInfo(): ImageInfo {\n const info = this.ref.getImageInfo();\n return {\n width: info.width,\n height: info.height,\n colorType: info.colorType.value,\n alphaType: info.alphaType.value,\n };\n }\n\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderOptions(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n getEnum(this.CanvasKit.FilterMode, fm),\n getEnum(this.CanvasKit.MipmapMode, mm),\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderCubic(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n B,\n C,\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n encodeToBytes(fmt?: ImageFormat, quality?: number) {\n let result: Uint8Array | null;\n if (fmt && quality) {\n result = this.ref.encodeToBytes(\n getEnum(this.CanvasKit.ImageFormat, fmt),\n quality\n );\n } else if (fmt) {\n result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));\n } else {\n result = this.ref.encodeToBytes();\n }\n if (!result) {\n throw new Error(\"encodeToBytes failed\");\n }\n return result;\n }\n\n encodeToBase64(fmt?: ImageFormat, quality?: number) {\n const bytes = this.encodeToBytes(fmt, quality);\n return toBase64String(bytes);\n }\n\n // TODO: this is leaking on Web\n // Add signature with allocated buffer\n readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {\n const info = this.getImageInfo();\n const pxInfo: CKImageInfo = {\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n width: imageInfo?.width ?? info.width,\n height: imageInfo?.height ?? info.height,\n alphaType: getEnum(\n this.CanvasKit.AlphaType,\n (imageInfo ?? info).alphaType\n ),\n colorType: getEnum(\n this.CanvasKit.ColorType,\n (imageInfo ?? info).colorType\n ),\n };\n return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);\n }\n\n dispose = () => {\n this.ref.delete();\n if (this.releaseCtx) {\n this.releaseCtx();\n }\n };\n\n makeNonTextureImage(): SkImage {\n const partialInfo = this.ref.getImageInfo();\n const colorSpace = this.ref.getColorSpace();\n const info = {\n ...partialInfo,\n colorSpace,\n };\n\n var pixelLen = info.width * info.height * 4;\n const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);\n const pixels = this.ref.readPixels(\n 0,\n 0,\n info,\n pixelPtr,\n info.width * 4\n ) as Uint8Array | null;\n if (!pixels) {\n throw new Error(\"Could not create image from bytes\");\n }\n const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);\n if (!img) {\n throw new Error(\"Could not create image from bytes\");\n }\n return new JsiSkImage(this.CanvasKit, img, () => {\n this.CanvasKit.Free(pixelPtr);\n });\n }\n}\n"],"mappings":";;;;;;AAiBA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAA4C,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAE,MAAA,CAAAF,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAI,CAAA,2BAAAJ,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAK,CAAA,GAAAL,CAAA,CAAAM,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAJ,CAAA,GAAAI,CAAA,CAAAG,IAAA,CAAAR,CAAA,EAAAI,CAAA,uCAAAH,CAAA,SAAAA,CAAA,YAAAQ,SAAA,yEAAAL,C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C,UAAU,CAChC,CAAC,EACD,CAAC,EACD1B,IAAI,EACJ0C,QAAQ,EACR1C,IAAI,CAACF,KAAK,GAAG,CACf,CAAsB;IACtB,IAAI,CAAC+C,MAAM,EAAE;MACX,MAAM,IAAIrB,KAAK,CAAC,mCAAmC,CAAC;IACtD;IACA,MAAMsB,GAAG,GAAG,IAAI,CAACrD,SAAS,CAACsD,SAAS,CAAC/C,IAAI,EAAE6C,MAAM,EAAE7C,IAAI,CAACF,KAAK,GAAG,CAAC,CAAC;IAClE,IAAI,CAACgD,GAAG,EAAE;MACR,MAAM,IAAItB,KAAK,CAAC,mCAAmC,CAAC;IACtD;IACA,OAAO,IAAIlC,UAAU,CAAC,IAAI,CAACG,SAAS,EAAEqD,GAAG,EAAE,MAAM;MAC/C,IAAI,CAACrD,SAAS,CAACuD,IAAI,CAACN,QAAQ,CAAC;IAC/B,CAAC,CAAC;EACJ;AACF;AAACrD,OAAA,CAAAC,UAAA,GAAAA,UAAA"}
@@ -2,7 +2,8 @@ import type { CanvasKit, Surface } from "canvaskit-wasm";
2
2
  import type { SkCanvas, SkImage, SkRect, SkSurface } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  export declare class JsiSkSurface extends HostObject<Surface, "Surface"> implements SkSurface {
5
- constructor(CanvasKit: CanvasKit, ref: Surface);
5
+ private releaseCtx?;
6
+ constructor(CanvasKit: CanvasKit, ref: Surface, releaseCtx?: (() => void) | undefined);
6
7
  dispose: () => void;
7
8
  flush(): void;
8
9
  getCanvas(): SkCanvas;
@@ -12,10 +12,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
12
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
13
13
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
14
  class JsiSkSurface extends _Host.HostObject {
15
- constructor(CanvasKit, ref) {
15
+ constructor(CanvasKit, ref, releaseCtx) {
16
16
  super(CanvasKit, ref, "Surface");
17
+ this.releaseCtx = releaseCtx;
17
18
  _defineProperty(this, "dispose", () => {
18
19
  this.ref.delete();
20
+ if (this.releaseCtx) {
21
+ this.releaseCtx();
22
+ }
19
23
  });
20
24
  }
21
25
  flush() {
@@ -1 +1 @@
1
- {"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JsiSkSurface","HostObject","constructor","CanvasKit","ref","delete","flush","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.delete();\n };\n\n flush() {\n this.ref.flush();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAA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C,GAAG,CAACG,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAE,iBAAiBA,CAACC,MAAe,EAAW;IAC1C,MAAMC,KAAK,GAAG,IAAI,CAACP,GAAG,CAACK,iBAAiB,CACtCC,MAAM,GACFE,KAAK,CAACC,IAAI,CAACC,oBAAS,CAACC,SAAS,CAAC,IAAI,CAACZ,SAAS,EAAEO,MAAM,CAAC,CAAC,GACvDM,SACN,CAAC;IACD,OAAO,IAAIC,sBAAU,CAAC,IAAI,CAACd,SAAS,EAAEQ,KAAK,CAAC;EAC9C;AACF;AAACO,OAAA,CAAAlB,YAAA,GAAAA,YAAA"}
1
+ {"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JsiSkSurface","HostObject","constructor","CanvasKit","ref","releaseCtx","delete","flush","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(\n CanvasKit: CanvasKit,\n ref: Surface,\n private releaseCtx?: () => void\n ) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.delete();\n if (this.releaseCtx) {\n this.releaseCtx();\n }\n };\n\n flush() {\n this.ref.flush();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAAwC,SAAAI,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAE,MAAA,CAAAF,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAI,CAAA,2BAAAJ,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAK,CAAA,GAAAL,CAAA,CAAAM,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAJ,CAAA,GAAAI,CAAA,CAAAG,IAAA,CAAAR,CAAA,EAAAI,CAAA,uCAAAH,CAAA,SAAAA,CAAA,YAAAQ,SAAA,yEAAAL,CAAA,GAAAD,MAAA,GAAAO,MAAA,EAAAV,CAAA;AAEjC,MAAMW,YAAY,SACfC,gBAAU,CAEpB;EACEC,WAAWA,CACTC,SAAoB,EACpBC,GAAY,EACJC,UAAuB,EAC/B;IACA,KAAK,CAACF,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;IAAC,KAFzBC,UAAuB,GAAvBA,UAAuB;IAAA1B,eAAA,kBAKvB,MAAM;MACd,IAAI,CAACyB,GAAG,CAACE,MAAM,CAAC,CAAC;MACjB,IAAI,IAAI,CAACD,UAAU,EAAE;QACnB,IAAI,CAACA,UAAU,CAAC,CAAC;MACnB;IACF,CAAC;EAPD;EASAE,KAAKA,CAAA,EAAG;IACN,IAAI,CAACH,GAAG,CAACG,KAAK,CAAC,CAAC;EAClB;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIC,wBAAW,CAAC,IAAI,CAACN,SAAS,EAAE,IAAI,CAACC,GAAG,CAACI,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAE,iBAAiBA,CAACC,MAAe,EAAW;IAC1C,MAAMC,KAAK,GAAG,IAAI,CAACR,GAAG,CAACM,iBAAiB,CACtCC,MAAM,GACFE,KAAK,CAACC,IAAI,CAACC,oBAAS,CAACC,SAAS,CAAC,IAAI,CAACb,SAAS,EAAEQ,MAAM,CAAC,CAAC,GACvDM,SACN,CAAC;IACD,OAAO,IAAIC,sBAAU,CAAC,IAAI,CAACf,SAAS,EAAES,KAAK,CAAC;EAC9C;AACF;AAACO,OAAA,CAAAnB,YAAA,GAAAA,YAAA"}
@@ -11,11 +11,22 @@ class JsiSkSurfaceFactory extends _Host.Host {
11
11
  super(CanvasKit);
12
12
  }
13
13
  Make(width, height) {
14
- const surface = this.CanvasKit.MakeSurface(width, height);
14
+ var pixelLen = width * height * 4;
15
+ const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
16
+ const surface = this.CanvasKit.MakeRasterDirectSurface({
17
+ width: width,
18
+ height: height,
19
+ colorType: this.CanvasKit.ColorType.RGBA_8888,
20
+ alphaType: this.CanvasKit.AlphaType.Unpremul,
21
+ colorSpace: this.CanvasKit.ColorSpace.SRGB
22
+ }, pixelPtr, width * 4);
15
23
  if (!surface) {
16
24
  return null;
17
25
  }
18
- return new _JsiSkSurface.JsiSkSurface(this.CanvasKit, surface);
26
+ surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);
27
+ return new _JsiSkSurface.JsiSkSurface(this.CanvasKit, surface, () => {
28
+ this.CanvasKit.Free(pixelPtr);
29
+ });
19
30
  }
20
31
  MakeOffscreen(width, height) {
21
32
  // OffscreenCanvas may be unvailable in some environments.
@@ -1 +1 @@
1
- {"version":3,"names":["_Host","require","_JsiSkSurface","JsiSkSurfaceFactory","Host","constructor","CanvasKit","Make","width","height","surface","MakeSurface","JsiSkSurface","MakeOffscreen","OC","globalThis","OffscreenCanvas","undefined","offscreen","webglContext","GetWebGLContext","grContext","MakeWebGLContext","Error","MakeRenderTarget","exports"],"sources":["JsiSkSurfaceFactory.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SurfaceFactory } from \"../types\";\n\nimport { Host } from \"./Host\";\nimport { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkSurfaceFactory extends Host implements SurfaceFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n Make(width: number, height: number) {\n const surface = this.CanvasKit.MakeSurface(width, height);\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n\n MakeOffscreen(width: number, height: number) {\n // OffscreenCanvas may be unvailable in some environments.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const OC = (globalThis as any).OffscreenCanvas;\n let surface: Surface | null;\n if (OC === undefined) {\n surface = this.CanvasKit.MakeSurface(width, height);\n } else {\n const offscreen = new OC(width, height);\n const webglContext = this.CanvasKit.GetWebGLContext(offscreen);\n const grContext = this.CanvasKit.MakeWebGLContext(webglContext);\n if (!grContext) {\n throw new Error(\"Could not make a graphics context\");\n }\n surface = this.CanvasKit.MakeRenderTarget(grContext, width, height);\n }\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEO,MAAME,mBAAmB,SAASC,UAAI,CAA2B;E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or","CanvasKit","Make","width","height","pixelLen","pixelPtr","Malloc","Uint8Array","surface","MakeRasterDirectSurface","colorType","ColorType","RGBA_8888","alphaType","AlphaType","Unpremul","colorSpace","ColorSpace","SRGB","getCanvas","clear","TRANSPARENT","JsiSkSurface","Free","MakeOffscreen","OC","globalThis","OffscreenCanvas","undefined","MakeSurface","offscreen","webglContext","GetWebGLContext","grContext","MakeWebGLContext","Error","MakeRenderTarget","exports"],"sources":["JsiSkSurfaceFactory.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SurfaceFactory } from \"../types\";\n\nimport { Host } from \"./Host\";\nimport { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkSurfaceFactory extends Host implements SurfaceFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n Make(width: number, height: number) {\n var pixelLen = width * height * 4;\n const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);\n const surface = this.CanvasKit.MakeRasterDirectSurface(\n {\n width: width,\n height: height,\n colorType: this.CanvasKit.ColorType.RGBA_8888,\n alphaType: this.CanvasKit.AlphaType.Unpremul,\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n },\n pixelPtr,\n width * 4\n );\n if (!surface) {\n return null;\n }\n surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);\n return new JsiSkSurface(this.CanvasKit, surface, () => {\n this.CanvasKit.Free(pixelPtr);\n });\n }\n\n MakeOffscreen(width: number, height: number) {\n // OffscreenCanvas may be unvailable in some environments.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const OC = (globalThis as any).OffscreenCanvas;\n let surface: Surface | null;\n if (OC === undefined) {\n surface = this.CanvasKit.MakeSurface(width, height);\n } else {\n const offscreen = new OC(width, height);\n const webglContext = this.CanvasKit.GetWebGLContext(offscreen);\n const grContext = this.CanvasKit.MakeWebGLContext(webglContext);\n if (!grContext) {\n throw new Error(\"Could not make a graphics context\");\n }\n surface = this.CanvasKit.MakeRenderTarget(grContext, width, height);\n }\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEO,MAAME,mBAAmB,SAASC,UAAI,CAA2B;EACtEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,IAAIA,CAACC,KAAa,EAAEC,MAAc,EAAE;IAClC,IAAIC,QAAQ,GAAGF,KAAK,GAAGC,MAAM,GAAG,CAAC;IACjC,MAAME,QAAQ,GAAG,IAAI,CAACL,SAAS,CAACM,MAAM,CAACC,UAAU,EAAEH,QAAQ,CAAC;IAC5D,MAAMI,OAAO,GAAG,IAAI,CAACR,SAAS,CAACS,uBAAuB,CACpD;MACEP,KAAK,EAAEA,KAAK;MACZC,MAAM,EAAEA,MAAM;MACdO,SAAS,EAAE,IAAI,CAACV,SAAS,CAACW,SAAS,CAACC,SAAS;MAC7CC,SAAS,EAAE,IAAI,CAACb,SAAS,CAACc,SAAS,CAACC,QAAQ;MAC5CC,UAAU,EAAE,IAAI,CAAChB,SAAS,CAACiB,UAAU,CAACC;IACxC,CAAC,EACDb,QAAQ,EACRH,KAAK,GAAG,CACV,CAAC;IACD,IAAI,CAACM,OAAO,EAAE;MACZ,OAAO,IAAI;IACb;IACAA,OAAO,CAACW,SAAS,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAACpB,SAAS,CAACqB,WAAW,CAAC;IACrD,OAAO,IAAIC,0BAAY,CAAC,IAAI,CAACtB,SAAS,EAAEQ,OAAO,EAAE,MAAM;MACrD,IAAI,CAACR,SAAS,CAACuB,IAAI,CAAClB,QAAQ,CAAC;IAC/B,CAAC,CAAC;EACJ;EAEAmB,aAAaA,CAACtB,KAAa,EAAEC,MAAc,EAAE;IAC3C;IACA;IACA,MAAMsB,EAAE,GAAIC,UAAU,CAASC,eAAe;IAC9C,IAAInB,OAAuB;IAC3B,IAAIiB,EAAE,KAAKG,SAAS,EAAE;MACpBpB,OAAO,GAAG,IAAI,CAACR,SAAS,CAAC6B,WAAW,CAAC3B,KAAK,EAAEC,MAAM,CAAC;IACrD,CAAC,MAAM;MACL,MAAM2B,SAAS,GAAG,IAAIL,EAAE,CAACvB,KAAK,EAAEC,MAAM,CAAC;MACvC,MAAM4B,YAAY,GAAG,IAAI,CAAC/B,SAAS,CAACgC,eAAe,CAACF,SAAS,CAAC;MAC9D,MAAMG,SAAS,GAAG,IAAI,CAACjC,SAAS,CAACkC,gBAAgB,CAACH,YAAY,CAAC;MAC/D,IAAI,CAACE,SAAS,EAAE;QACd,MAAM,IAAIE,KAAK,CAAC,mCAAmC,CAAC;MACtD;MACA3B,OAAO,GAAG,IAAI,CAACR,SAAS,CAACoC,gBAAgB,CAACH,SAAS,EAAE/B,KAAK,EAAEC,MAAM,CAAC;IACrE;IACA,IAAI,CAACK,OAAO,EAAE;MACZ,OAAO,IAAI;IACb;IACA,OAAO,IAAIc,0BAAY,CAAC,IAAI,CAACtB,SAAS,EAAEQ,OAAO,CAAC;EAClD;AACF;AAAC6B,OAAA,CAAAxC,mBAAA,GAAAA,mBAAA"}
@@ -1,5 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { SkSurface } from "../skia";
3
3
  export * from "../renderer/components";
4
- export declare const makeOffscreenSurface: (width: number, height: number) => any;
4
+ export declare const makeOffscreenSurface: (width: number, height: number) => SkSurface;
5
+ export declare const getSkiaExports: () => {
6
+ Skia: import("../skia/types").Skia;
7
+ };
5
8
  export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => import("../skia").SkImage;
@@ -5,8 +5,6 @@ import { JsiSkApi } from "../skia/web";
5
5
  import { SkiaRoot } from "../renderer/Reconciler";
6
6
  import { JsiDrawingContext } from "../dom/types";
7
7
  export * from "../renderer/components";
8
-
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
8
  let Skia;
11
9
  export const makeOffscreenSurface = (width, height) => {
12
10
  if (!Skia) {
@@ -18,12 +16,21 @@ export const makeOffscreenSurface = (width, height) => {
18
16
  }
19
17
  return surface;
20
18
  };
19
+ export const getSkiaExports = () => {
20
+ if (!Skia) {
21
+ Skia = JsiSkApi(CanvasKit);
22
+ }
23
+ return {
24
+ Skia
25
+ };
26
+ };
21
27
  export const drawOffscreen = (surface, element) => {
22
28
  const root = new SkiaRoot(Skia, false);
23
29
  root.render(element);
24
30
  const canvas = surface.getCanvas();
25
31
  const ctx = new JsiDrawingContext(Skia, canvas);
26
32
  root.dom.render(ctx);
33
+ root.unmount();
27
34
  surface.flush();
28
35
  return surface.makeImageSnapshot();
29
36
  };
@@ -1 +1 @@
1
- {"version":3,"names":["JsiSkApi","SkiaRoot","JsiDrawingContext","Skia","makeOffscreenSurface","width","height","CanvasKit","surface","Surface","MakeOffscreen","Error","drawOffscreen","element","root","render","canvas","getCanvas","ctx","dom","flush","makeImageSnapshot"],"sources":["index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { ReactNode } from \"react\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { SkiaRoot } from \"../renderer/Reconciler\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkSurface } from \"../skia\";\n\nexport * from \"../renderer/components\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet Skia: any;\n\nexport const makeOffscreenSurface = (width: number, height: number) => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n const surface = Skia.Surface.MakeOffscreen(width, height);\n if (surface === null) {\n throw new Error(\"Couldn't create surface!\");\n }\n return surface;\n};\n\nexport const drawOffscreen = (surface: SkSurface, element: ReactNode) => {\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const canvas = surface.getCanvas();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n surface.flush();\n return surface.makeImageSnapshot();\n};\n"],"mappings":"AAAA;AACA;;AAIA,SAASA,QAAQ,QAAQ,aAAa;AACtC,SAASC,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,iBAAiB,QAAQ,cAAc;AAGhD,cAAc,wBAAwB;;AAEtC;AACA,IAAIC,IAAS;AAEb,OAAO,MAAMC,oBAAoB,GAAGA,CAACC,KAAa,EAAEC,MAAc,KAAK;EACrE,IAAI,CAACH,IAAI,EAAE;IACTA,IAAI,GAAGH,QAAQ,CAACO,SAAS,CAAC;EAC5B;EACA,MAAMC,OAAO,GAAGL,IAAI,CAACM,OAAO,CAACC,aAAa,CAACL,KAAK,EAAEC,MAAM,CAAC;EACzD,IAAIE,OAAO,KAAK,IAAI,EAAE;IACpB,MAAM,IAAIG,KAAK,CAAC,0BAA0B,CAAC;EAC7C;EACA,OAAOH,OAAO;AAChB,CAAC;AAED,OAAO,MAAMI,aAAa,GAAGA,CAACJ,OAAkB,EAAEK,OAAkB,KAAK;EACvE,MAAMC,IAAI,GAAG,IAAIb,QAAQ,CAACE,IAAI,EAAE,KAAK,CAAC;EACtCW,IAAI,CAACC,MAAM,CAACF,OAAO,CAAC;EACpB,MAAMG,MAAM,GAAGR,OAAO,CAACS,SAAS,CAAC,CAAC;EAClC,MAAMC,GAAG,GAAG,IAAIhB,iBAAiB,CAACC,IAAI,EAAEa,MAAM,CAAC;EAC/CF,IAAI,CAACK,GAAG,CAACJ,MAAM,CAACG,GAAG,CAAC;EACpBV,OAAO,CAACY,KAAK,CAAC,CAAC;EACf,OAAOZ,OAAO,CAACa,iBAAiB,CAAC,CAAC;AACpC,CAAC"}
1
+ {"version":3,"names":["JsiSkApi","SkiaRoot","JsiDrawingContext","Skia","makeOffscreenSurface","width","height","CanvasKit","surface","Surface","MakeOffscreen","Error","getSkiaExports","drawOffscreen","element","root","render","canvas","getCanvas","ctx","dom","unmount","flush","makeImageSnapshot"],"sources":["index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { ReactNode } from \"react\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { SkiaRoot } from \"../renderer/Reconciler\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkSurface } from \"../skia\";\n\nexport * from \"../renderer/components\";\n\nlet Skia: ReturnType<typeof JsiSkApi>;\n\nexport const makeOffscreenSurface = (width: number, height: number) => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n const surface = Skia.Surface.MakeOffscreen(width, height);\n if (surface === null) {\n throw new Error(\"Couldn't create surface!\");\n }\n return surface;\n};\n\nexport const getSkiaExports = () => {\n if (!Skia) {\n Skia = JsiSkApi(CanvasKit);\n }\n return { Skia };\n};\n\nexport const drawOffscreen = (surface: SkSurface, element: ReactNode) => {\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const canvas = surface.getCanvas();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n root.unmount();\n surface.flush();\n return surface.makeImageSnapshot();\n};\n"],"mappings":"AAAA;AACA;;AAIA,SAASA,QAAQ,QAAQ,aAAa;AACtC,SAASC,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,iBAAiB,QAAQ,cAAc;AAGhD,cAAc,wBAAwB;AAEtC,IAAIC,IAAiC;AAErC,OAAO,MAAMC,oBAAoB,GAAGA,CAACC,KAAa,EAAEC,MAAc,KAAK;EACrE,IAAI,CAACH,IAAI,EAAE;IACTA,IAAI,GAAGH,QAAQ,CAACO,SAAS,CAAC;EAC5B;EACA,MAAMC,OAAO,GAAGL,IAAI,CAACM,OAAO,CAACC,aAAa,CAACL,KAAK,EAAEC,MAAM,CAAC;EACzD,IAAIE,OAAO,KAAK,IAAI,EAAE;IACpB,MAAM,IAAIG,KAAK,CAAC,0BAA0B,CAAC;EAC7C;EACA,OAAOH,OAAO;AAChB,CAAC;AAED,OAAO,MAAMI,cAAc,GAAGA,CAAA,KAAM;EAClC,IAAI,CAACT,IAAI,EAAE;IACTA,IAAI,GAAGH,QAAQ,CAACO,SAAS,CAAC;EAC5B;EACA,OAAO;IAAEJ;EAAK,CAAC;AACjB,CAAC;AAED,OAAO,MAAMU,aAAa,GAAGA,CAACL,OAAkB,EAAEM,OAAkB,KAAK;EACvE,MAAMC,IAAI,GAAG,IAAId,QAAQ,CAACE,IAAI,EAAE,KAAK,CAAC;EACtCY,IAAI,CAACC,MAAM,CAACF,OAAO,CAAC;EACpB,MAAMG,MAAM,GAAGT,OAAO,CAACU,SAAS,CAAC,CAAC;EAClC,MAAMC,GAAG,GAAG,IAAIjB,iBAAiB,CAACC,IAAI,EAAEc,MAAM,CAAC;EAC/CF,IAAI,CAACK,GAAG,CAACJ,MAAM,CAACG,GAAG,CAAC;EACpBJ,IAAI,CAACM,OAAO,CAAC,CAAC;EACdb,OAAO,CAACc,KAAK,CAAC,CAAC;EACf,OAAOd,OAAO,CAACe,iBAAiB,CAAC,CAAC;AACpC,CAAC"}
@@ -17,6 +17,7 @@ export const drawAsPicture = element => {
17
17
  const ctx = new JsiDrawingContext(Skia, canvas);
18
18
  root.dom.render(ctx);
19
19
  const picture = recorder.finishRecordingAsPicture();
20
+ root.unmount();
20
21
  return picture;
21
22
  };
22
23
  export const drawAsImage = (element, size) => {