@shopify/react-native-skia 0.1.196 → 0.1.199
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +32 -31
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +4 -2
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +3 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkShaderFactory.h +4 -4
- package/cpp/api/JsiSkSurface.h +0 -1
- package/cpp/api/JsiSkSurfaceFactory.h +2 -1
- package/cpp/rnskia/RNSkView.h +20 -40
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +2 -2
- package/cpp/rnskia/values/RNSkReadonlyValue.h +6 -7
- package/cpp/skia/include/android/SkCanvasAndroid.h +20 -0
- package/cpp/skia/include/android/SkHeifDecoder.h +43 -0
- package/cpp/skia/include/android/SkSurfaceAndroid.h +50 -0
- package/cpp/skia/include/codec/SkAvifDecoder.h +43 -0
- package/cpp/skia/include/codec/SkBmpDecoder.h +43 -0
- package/cpp/skia/include/codec/SkCodec.h +25 -1
- package/cpp/skia/include/codec/SkGifDecoder.h +43 -0
- package/cpp/skia/include/codec/SkIcoDecoder.h +43 -0
- package/cpp/skia/include/codec/SkJpegDecoder.h +43 -0
- package/cpp/skia/include/codec/SkJpegxlDecoder.h +43 -0
- package/cpp/skia/include/codec/SkPngDecoder.h +43 -0
- package/cpp/skia/include/codec/SkRawDecoder.h +49 -0
- package/cpp/skia/include/codec/SkWbmpDecoder.h +43 -0
- package/cpp/skia/include/codec/SkWebpDecoder.h +43 -0
- package/cpp/skia/include/core/SkBBHFactory.h +5 -1
- package/cpp/skia/include/core/SkBlender.h +0 -2
- package/cpp/skia/include/core/SkCanvas.h +4 -23
- package/cpp/skia/include/core/SkColorFilter.h +14 -1
- package/cpp/skia/include/core/SkColorTable.h +59 -0
- package/cpp/skia/include/core/SkContourMeasure.h +3 -0
- package/cpp/skia/include/core/SkDeferredDisplayList.h +8 -104
- package/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +8 -91
- package/cpp/skia/include/core/SkDrawable.h +5 -2
- package/cpp/skia/include/core/SkGraphics.h +7 -19
- package/cpp/skia/include/core/SkImage.h +157 -249
- package/cpp/skia/include/core/SkImageGenerator.h +0 -31
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPathMeasure.h +3 -3
- package/cpp/skia/include/core/SkPictureRecorder.h +1 -1
- package/cpp/skia/include/core/SkPoint.h +5 -563
- package/cpp/skia/include/core/SkPoint3.h +1 -0
- package/cpp/skia/include/core/SkPromiseImageTexture.h +4 -30
- package/cpp/skia/include/core/SkRect.h +8 -8
- package/cpp/skia/include/core/SkSamplingOptions.h +4 -2
- package/cpp/skia/include/core/SkScalar.h +1 -1
- package/cpp/skia/include/core/SkSerialProcs.h +5 -1
- package/cpp/skia/include/core/SkShader.h +14 -21
- package/cpp/skia/include/core/SkString.h +2 -0
- package/cpp/skia/include/core/SkSurface.h +169 -701
- package/cpp/skia/include/core/SkSurfaceCharacterization.h +8 -256
- package/cpp/skia/include/core/SkTiledImageUtils.h +97 -0
- package/cpp/skia/include/core/SkTypes.h +4 -2
- package/cpp/skia/include/core/SkYUVAPixmaps.h +0 -5
- package/cpp/skia/include/effects/SkGradientShader.h +10 -1
- package/cpp/skia/include/effects/SkImageFilters.h +62 -37
- package/cpp/skia/include/effects/SkPerlinNoiseShader.h +28 -29
- package/cpp/skia/include/effects/SkRuntimeEffect.h +17 -12
- package/cpp/skia/include/gpu/GrBackendSurface.h +12 -39
- package/cpp/skia/include/gpu/GrBackendSurfaceMutableState.h +6 -0
- package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +3 -3
- package/cpp/skia/include/gpu/GrDirectContext.h +103 -3
- package/cpp/skia/include/gpu/GrRecordingContext.h +10 -19
- package/cpp/skia/include/gpu/MutableTextureState.h +4 -0
- package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +54 -0
- package/cpp/skia/include/gpu/ganesh/SkImageGanesh.h +20 -76
- package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +217 -0
- package/cpp/skia/include/gpu/ganesh/mtl/SkSurfaceMetal.h +73 -0
- package/cpp/skia/include/gpu/gl/GrGLTypes.h +13 -2
- package/cpp/skia/include/gpu/graphite/BackendSemaphore.h +78 -0
- package/cpp/skia/include/gpu/graphite/BackendTexture.h +1 -0
- package/cpp/skia/include/gpu/graphite/Image.h +277 -0
- package/cpp/skia/include/gpu/graphite/ImageProvider.h +1 -1
- package/cpp/skia/include/gpu/graphite/Recording.h +1 -4
- package/cpp/skia/include/gpu/graphite/Surface.h +81 -0
- package/cpp/skia/include/gpu/graphite/TextureInfo.h +5 -7
- package/cpp/skia/include/gpu/graphite/YUVABackendTextures.h +2 -2
- package/cpp/skia/include/gpu/mock/GrMockTypes.h +23 -8
- package/cpp/skia/include/ports/SkTypeface_fontations.h +21 -0
- package/cpp/skia/include/private/SkGainmapInfo.h +2 -0
- package/cpp/skia/include/private/SkGainmapShader.h +1 -0
- package/cpp/skia/include/private/SkJpegMetadataDecoder.h +19 -1
- package/cpp/skia/include/private/SkPathRef.h +13 -15
- package/cpp/skia/include/private/SkXmp.h +53 -0
- package/cpp/skia/include/private/base/SkFeatures.h +0 -4
- package/cpp/skia/include/private/base/SkFloatingPoint.h +11 -5
- package/cpp/skia/include/private/base/SkPoint_impl.h +569 -0
- package/cpp/skia/include/private/base/SkSpan_impl.h +3 -7
- package/cpp/skia/include/private/base/SkTArray.h +11 -11
- package/cpp/skia/include/private/chromium/GrDeferredDisplayList.h +120 -0
- package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +98 -0
- package/cpp/skia/include/private/chromium/GrPromiseImageTexture.h +43 -0
- package/cpp/skia/include/private/chromium/GrSurfaceCharacterization.h +215 -0
- package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +6 -6
- package/cpp/skia/include/private/chromium/SkImageChromium.h +104 -0
- package/cpp/skia/include/private/chromium/Slug.h +7 -3
- package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +7 -3
- package/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +2 -0
- package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +3 -2
- package/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +10 -2
- package/cpp/skia/include/{gpu → private/gpu}/ganesh/GrTextureGenerator.h +2 -13
- package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +1 -1
- package/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h +7 -0
- package/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h +19 -6
- package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +13 -0
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +0 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +14 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +999 -79
- package/cpp/skia/modules/skcms/src/Transform_inl.h +36 -236
- package/cpp/skia/modules/skparagraph/include/Paragraph.h +2 -0
- package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +16 -0
- package/cpp/skia/modules/skparagraph/include/TextStyle.h +6 -2
- package/cpp/skia/modules/skresources/include/SkResources.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGCircle.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGClipPath.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGContainer.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGDOM.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGDefs.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGEllipse.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGG.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGHiddenContainer.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGLine.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGLinearGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPath.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRect.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRenderContext.h +3 -3
- package/cpp/skia/modules/svg/include/SkSVGSVG.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGStop.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGTypes.h +21 -21
- package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGValue.h +2 -2
- package/cpp/skia/{include/private → src/core}/SkChecksum.h +32 -17
- package/cpp/skia/src/core/SkTHash.h +1 -1
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +3 -1
- package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +3 -1
- package/lib/commonjs/renderer/Canvas.js +24 -13
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/core/Data.d.ts +2 -2
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/RRect.js +5 -1
- package/lib/commonjs/skia/core/RRect.js.map +1 -1
- package/lib/commonjs/skia/core/Rect.js +32 -6
- package/lib/commonjs/skia/core/Rect.js.map +1 -1
- package/lib/commonjs/skia/types/Color.js.map +1 -1
- package/lib/commonjs/skia/types/JsiInstance.d.ts +2 -4
- package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
- package/lib/module/renderer/Canvas.js +25 -14
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +2 -2
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/RRect.js +5 -1
- package/lib/module/skia/core/RRect.js.map +1 -1
- package/lib/module/skia/core/Rect.js +32 -6
- package/lib/module/skia/core/Rect.js.map +1 -1
- package/lib/module/skia/types/Color.js.map +1 -1
- package/lib/module/skia/types/JsiInstance.d.ts +2 -4
- package/lib/module/skia/types/JsiInstance.js.map +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +2 -2
- package/lib/typescript/src/skia/types/JsiInstance.d.ts +2 -4
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/arm64-v8a/libsvg.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libsvg.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86/libsvg.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.a +0 -0
- package/libs/android/x86_64/libsvg.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/Info.plist +5 -5
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -4
- package/src/renderer/Canvas.tsx +25 -19
- package/src/skia/core/Data.ts +3 -3
- package/src/skia/core/RRect.tsx +4 -2
- package/src/skia/core/Rect.ts +29 -12
- package/src/skia/types/Color.ts +1 -1
- package/src/skia/types/JsiInstance.ts +2 -5
- package/cpp/skia/include/effects/SkTableColorFilter.h +0 -29
- package/cpp/skia/include/private/SkOpts_spi.h +0 -23
- package/cpp/skia/include/private/SkSpinlock.h +0 -57
- package/cpp/skia/include/private/chromium/GrSlug.h +0 -16
- package/scripts/install-npm.js +0 -33
@@ -8,7 +8,9 @@
|
|
8
8
|
#import "SkColorSpace.h"
|
9
9
|
#import "SkSurface.h"
|
10
10
|
|
11
|
+
#import <include/gpu/GrBackendSurface.h>
|
11
12
|
#import <include/gpu/GrDirectContext.h>
|
13
|
+
#import <include/gpu/ganesh/SkSurfaceGanesh.h>
|
12
14
|
|
13
15
|
#pragma clang diagnostic pop
|
14
16
|
|
@@ -122,7 +124,7 @@ bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
122
124
|
GrBackendRenderTarget backendRT(_layer.drawableSize.width,
|
123
125
|
_layer.drawableSize.height, 1, fbInfo);
|
124
126
|
|
125
|
-
auto skSurface =
|
127
|
+
auto skSurface = SkSurfaces::WrapBackendRenderTarget(
|
126
128
|
renderContext->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
|
127
129
|
kBGRA_8888_SkColorType, nullptr, nullptr);
|
128
130
|
|
@@ -5,7 +5,9 @@
|
|
5
5
|
#import "SkColorSpace.h"
|
6
6
|
#import "SkSurface.h"
|
7
7
|
|
8
|
+
#import <include/gpu/GrBackendSurface.h>
|
8
9
|
#import <include/gpu/GrDirectContext.h>
|
10
|
+
#import <include/gpu/ganesh/SkSurfaceGanesh.h>
|
9
11
|
|
10
12
|
#pragma clang diagnostic pop
|
11
13
|
|
@@ -44,7 +46,7 @@ sk_sp<SkSurface> MakeOffscreenMetalSurface(int width, int height) {
|
|
44
46
|
GrBackendTexture backendTexture(width, height, GrMipMapped::kNo, info);
|
45
47
|
|
46
48
|
// Create a SkSurface from the GrBackendTexture
|
47
|
-
auto surface =
|
49
|
+
auto surface = SkSurfaces::WrapBackendTexture(
|
48
50
|
ctx->skiaContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0,
|
49
51
|
kBGRA_8888_SkColorType, nullptr, nullptr,
|
50
52
|
[](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx);
|
@@ -30,6 +30,28 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
30
30
|
const useCanvasRef = () => (0, _react.useRef)(null);
|
31
31
|
|
32
32
|
exports.useCanvasRef = useCanvasRef;
|
33
|
+
|
34
|
+
const useOnSizeEvent = resultValue => {
|
35
|
+
const onSize = (0, _values.useValue)({
|
36
|
+
width: 0,
|
37
|
+
height: 0
|
38
|
+
});
|
39
|
+
(0, _react.useLayoutEffect)(() => {
|
40
|
+
if (!resultValue) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
return onSize.addListener(newValue => {
|
45
|
+
if ((0, _processors.isValue)(resultValue)) {
|
46
|
+
resultValue.current = newValue;
|
47
|
+
} else {
|
48
|
+
resultValue.value = newValue;
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}, [resultValue, onSize]);
|
52
|
+
return onSize;
|
53
|
+
};
|
54
|
+
|
33
55
|
const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
34
56
|
let {
|
35
57
|
children,
|
@@ -37,21 +59,10 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
|
37
59
|
debug,
|
38
60
|
mode,
|
39
61
|
onTouch,
|
40
|
-
onSize:
|
62
|
+
onSize: _onSize,
|
41
63
|
...props
|
42
64
|
} = _ref;
|
43
|
-
const
|
44
|
-
width: 0,
|
45
|
-
height: 0
|
46
|
-
});
|
47
|
-
const onSize = (0, _processors.isValue)(onSizeReanimatedOrSkia) ? onSizeReanimatedOrSkia : size;
|
48
|
-
(0, _react.useEffect)(() => {
|
49
|
-
if (!(0, _processors.isValue)(onSizeReanimatedOrSkia) && onSizeReanimatedOrSkia) {
|
50
|
-
return size.addListener(v => onSizeReanimatedOrSkia.value = v);
|
51
|
-
}
|
52
|
-
|
53
|
-
return undefined;
|
54
|
-
}, [onSizeReanimatedOrSkia, size]);
|
65
|
+
const onSize = useOnSizeEvent(_onSize);
|
55
66
|
const innerRef = useCanvasRef();
|
56
67
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
57
68
|
const redraw = (0, _react.useCallback)(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useCanvasRef","useRef","
|
1
|
+
{"version":3,"names":["useCanvasRef","useRef","useOnSizeEvent","resultValue","onSize","useValue","width","height","useLayoutEffect","addListener","newValue","isValue","current","value","Canvas","forwardRef","forwardedRef","children","style","debug","mode","onTouch","_onSize","props","innerRef","ref","useCombinedRefs","redraw","useCallback","getNativeId","id","nativeId","registerValues","values","root","useMemo","SkiaRoot","Skia","useEffect","render","unmount","NATIVE_DOM","dom","canvas","info","touches","ctx","JsiDrawingContext","refs","targetRef","React","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useLayoutEffect,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\n\nimport { SkiaDomView, SkiaView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { TouchHandler, SkiaBaseViewProps } from \"../views\";\nimport type { SkiaValue } from \"../values/types\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport { useValue } from \"../values\";\n\nimport { SkiaRoot } from \"./Reconciler\";\nimport { NATIVE_DOM } from \"./HostComponents\";\nimport { isValue } from \"./processors\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nconst useOnSizeEvent = (resultValue: SkiaBaseViewProps[\"onSize\"]) => {\n const onSize = useValue({\n width: 0,\n height: 0,\n });\n\n useLayoutEffect(() => {\n if (!resultValue) {\n return;\n }\n return onSize.addListener((newValue) => {\n if (isValue(resultValue)) {\n resultValue.current = newValue;\n } else {\n resultValue.value = newValue;\n }\n });\n }, [resultValue, onSize]);\n\n return onSize;\n};\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize: _onSize, ...props },\n forwardedRef\n ) => {\n const onSize = useOnSizeEvent(_onSize);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current !== null) {\n return ref.current.registerValues(values);\n }\n return () => {};\n },\n [ref]\n );\n const root = useMemo(\n () => new SkiaRoot(Skia, registerValues, redraw, getNativeId),\n [redraw, registerValues, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n if (NATIVE_DOM) {\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n } else {\n return (\n <SkiaView\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref={ref as any}\n style={style}\n mode={mode}\n debug={debug}\n onSize={onSize}\n onDraw={(canvas, info) => {\n onTouch && onTouch(info.touches);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n }}\n {...props}\n />\n );\n }\n }\n) as React.FC<CanvasProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n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AAC,eAAD,CACE;IADF;MAEE,GAAG,EAAEE,GAFP;MAGE,KAAK,EAAEP,KAHT;MAIE,IAAI,EAAEE,IAJR;MAKE,KAAK,EAAED,KALT;MAME,MAAM,EAAEf,MANV;MAOE,MAAM,EAAE,CAACuC,MAAD,EAASC,IAAT,KAAkB;QACxBvB,OAAO,IAAIA,OAAO,CAACuB,IAAI,CAACC,OAAN,CAAlB;QACA,MAAMC,GAAG,GAAG,IAAIC,wBAAJ,CAAsBV,UAAtB,EAA4BM,MAA5B,CAAZ;QACAT,IAAI,CAACQ,GAAL,CAASH,MAAT,CAAgBO,GAAhB;MACD;IAXH,GAYMvB,KAZN,EADF;EAgBD;AACF,CAvEmB,CAAf;AA0EP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMG,eAAe,GAAG,YAEnB;EAAA,kCADAsB,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAGC,cAAA,CAAMjD,MAAN,CAAgB,IAAhB,CAAlB;;EACAiD,cAAA,CAAMZ,SAAN,CAAgB,MAAM;IACpBU,IAAI,CAACG,OAAL,CAAc1B,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACwB,SAAS,CAACrC,OAAX,CAAH;QACD,CAFD,MAEO;UACLa,GAAG,CAACb,OAAJ,GAAcqC,SAAS,CAACrC,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAACoC,IAAD,CAVH;;EAWA,OAAOC,SAAP;AACD,CAhBD"}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type { SkData, DataSourceParam,
|
2
|
-
export declare const useRawData: <T extends
|
1
|
+
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => T | null;
|
3
3
|
export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","useLoading","loader","mounted","useRef","data","setData","useState","dataRef","useEffect","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam,
|
1
|
+
{"version":3,"names":["factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","useLoading","loader","mounted","useRef","data","setData","useState","dataRef","useEffect","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA,MAAMA,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;EACH,MAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;EACA,IAAIG,aAAa,KAAK,IAAtB,EAA4B;IAC1BD,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;IACA,OAAO,IAAP;EACD,CAHD,MAGO;IACL,OAAOD,aAAP;EACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfC,MADe,EAEfL,OAFe,EAGfC,OAHe,KAIO;EACtB,IAAII,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKC,SAAlC,EAA6C;IAC3C,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;EACD,CAFD,MAEO,IAAIH,MAAM,YAAYI,UAAtB,EAAkC;IACvC,OAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACV,cAAc,CAACY,UAAA,CAAKC,IAAL,CAAUC,SAAV,CAAoBP,MAApB,CAAD,EAA8BL,OAA9B,EAAuCC,OAAvC,CAAf,CADF,CAAP;EAGD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IAAnC;;AAEO,MAAMU,OAAO,GAAG,CACrB5B,MADqB,EAErBJ,OAFqB,KAGlB8B,UAAU,CAAC1B,MAAD,EAAS2B,QAAT,EAAmB/B,OAAnB,CAHR"}
|
@@ -7,7 +7,11 @@ exports.rrect = void 0;
|
|
7
7
|
|
8
8
|
var _Skia = require("../Skia");
|
9
9
|
|
10
|
-
const rrect = (r, rx, ry) =>
|
10
|
+
const rrect = (r, rx, ry) => {
|
11
|
+
"worklet";
|
12
|
+
|
13
|
+
return _Skia.Skia.RRectXY(r, rx, ry);
|
14
|
+
};
|
11
15
|
|
12
16
|
exports.rrect = rrect;
|
13
17
|
//# sourceMappingURL=RRect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["rrect","r","rx","ry","Skia","RRectXY"],"sources":["RRect.tsx"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect } from \"../types\";\n\nexport const rrect = (r: SkRect, rx: number, ry: number)
|
1
|
+
{"version":3,"names":["rrect","r","rx","ry","Skia","RRectXY"],"sources":["RRect.tsx"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect } from \"../types\";\n\nexport const rrect = (r: SkRect, rx: number, ry: number) => {\n \"worklet\";\n return Skia.RRectXY(r, rx, ry);\n};\n"],"mappings":";;;;;;;AAAA;;AAGO,MAAMA,KAAK,GAAG,CAACC,CAAD,EAAYC,EAAZ,EAAwBC,EAAxB,KAAuC;EAC1D;;EACA,OAAOC,UAAA,CAAKC,OAAL,CAAaJ,CAAb,EAAgBC,EAAhB,EAAoBC,EAApB,CAAP;AACD,CAHM"}
|
@@ -11,11 +11,17 @@ var _types = require("../types");
|
|
11
11
|
|
12
12
|
var _Vector = require("./Vector");
|
13
13
|
|
14
|
-
const rect = (x, y, width, height) =>
|
14
|
+
const rect = (x, y, width, height) => {
|
15
|
+
"worklet";
|
16
|
+
|
17
|
+
return _Skia.Skia.XYWHRect(x, y, width, height);
|
18
|
+
};
|
15
19
|
|
16
20
|
exports.rect = rect;
|
17
21
|
|
18
22
|
const bounds = rects => {
|
23
|
+
"worklet";
|
24
|
+
|
19
25
|
const x = Math.min(...rects.map(r => r.x));
|
20
26
|
const y = Math.min(...rects.map(r => r.y));
|
21
27
|
const width = Math.max(...rects.map(r => r.x + r.width));
|
@@ -25,23 +31,43 @@ const bounds = rects => {
|
|
25
31
|
|
26
32
|
exports.bounds = bounds;
|
27
33
|
|
28
|
-
const topLeft = r =>
|
34
|
+
const topLeft = r => {
|
35
|
+
"worklet";
|
36
|
+
|
37
|
+
return (0, _types.isRRect)(r) ? (0, _Vector.vec)(r.rect.x, r.rect.y) : (0, _Vector.vec)(r.x, r.y);
|
38
|
+
};
|
29
39
|
|
30
40
|
exports.topLeft = topLeft;
|
31
41
|
|
32
|
-
const topRight = r =>
|
42
|
+
const topRight = r => {
|
43
|
+
"worklet";
|
44
|
+
|
45
|
+
return (0, _types.isRRect)(r) ? (0, _Vector.vec)(r.rect.x + r.rect.width, r.rect.y) : (0, _Vector.vec)(r.x + r.width, r.y);
|
46
|
+
};
|
33
47
|
|
34
48
|
exports.topRight = topRight;
|
35
49
|
|
36
|
-
const bottomLeft = r =>
|
50
|
+
const bottomLeft = r => {
|
51
|
+
"worklet";
|
52
|
+
|
53
|
+
return (0, _types.isRRect)(r) ? (0, _Vector.vec)(r.rect.x, r.rect.y + r.rect.height) : (0, _Vector.vec)(r.x, r.y + r.height);
|
54
|
+
};
|
37
55
|
|
38
56
|
exports.bottomLeft = bottomLeft;
|
39
57
|
|
40
|
-
const bottomRight = r =>
|
58
|
+
const bottomRight = r => {
|
59
|
+
"worklet";
|
60
|
+
|
61
|
+
return (0, _types.isRRect)(r) ? (0, _Vector.vec)(r.rect.x + r.rect.width, r.rect.y + r.rect.height) : (0, _Vector.vec)(r.x + r.width, r.y + r.height);
|
62
|
+
};
|
41
63
|
|
42
64
|
exports.bottomRight = bottomRight;
|
43
65
|
|
44
|
-
const center = r =>
|
66
|
+
const center = r => {
|
67
|
+
"worklet";
|
68
|
+
|
69
|
+
return (0, _types.isRRect)(r) ? (0, _Vector.vec)(r.rect.x + r.rect.width / 2, r.rect.y + r.rect.height / 2) : (0, _Vector.vec)(r.x + r.width / 2, r.y + r.height / 2);
|
70
|
+
};
|
45
71
|
|
46
72
|
exports.center = center;
|
47
73
|
//# sourceMappingURL=Rect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["rect","x","y","width","height","Skia","XYWHRect","bounds","rects","Math","min","map","r","max","topLeft","isRRect","vec","topRight","bottomLeft","bottomRight","center"],"sources":["Rect.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect, SkRRect } from \"../types\";\nimport { isRRect } from \"../types\";\n\nimport { vec } from \"./Vector\";\n\nexport const rect = (x: number, y: number, width: number, height: number)
|
1
|
+
{"version":3,"names":["rect","x","y","width","height","Skia","XYWHRect","bounds","rects","Math","min","map","r","max","topLeft","isRRect","vec","topRight","bottomLeft","bottomRight","center"],"sources":["Rect.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect, SkRRect } from \"../types\";\nimport { isRRect } from \"../types\";\n\nimport { vec } from \"./Vector\";\n\nexport const rect = (x: number, y: number, width: number, height: number) => {\n \"worklet\";\n return Skia.XYWHRect(x, y, width, height);\n};\n\nexport const bounds = (rects: SkRect[]) => {\n \"worklet\";\n const x = Math.min(...rects.map((r) => r.x));\n const y = Math.min(...rects.map((r) => r.y));\n const width = Math.max(...rects.map((r) => r.x + r.width));\n const height = Math.max(...rects.map((r) => r.y + r.height));\n return rect(x, y, width - x, height - y);\n};\n\nexport const topLeft = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r) ? vec(r.rect.x, r.rect.y) : vec(r.x, r.y);\n};\n\nexport const topRight = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width, r.rect.y)\n : vec(r.x + r.width, r.y);\n};\n\nexport const bottomLeft = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x, r.rect.y + r.rect.height)\n : vec(r.x, r.y + r.height);\n};\nexport const bottomRight = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width, r.rect.y + r.rect.height)\n : vec(r.x + r.width, r.y + r.height);\n};\nexport const center = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width / 2, r.rect.y + r.rect.height / 2)\n : vec(r.x + r.width / 2, r.y + r.height / 2);\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEO,MAAMA,IAAI,GAAG,CAACC,CAAD,EAAYC,CAAZ,EAAuBC,KAAvB,EAAsCC,MAAtC,KAAyD;EAC3E;;EACA,OAAOC,UAAA,CAAKC,QAAL,CAAcL,CAAd,EAAiBC,CAAjB,EAAoBC,KAApB,EAA2BC,MAA3B,CAAP;AACD,CAHM;;;;AAKA,MAAMG,MAAM,GAAIC,KAAD,IAAqB;EACzC;;EACA,MAAMP,CAAC,GAAGQ,IAAI,CAACC,GAAL,CAAS,GAAGF,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACX,CAAnB,CAAZ,CAAV;EACA,MAAMC,CAAC,GAAGO,IAAI,CAACC,GAAL,CAAS,GAAGF,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACV,CAAnB,CAAZ,CAAV;EACA,MAAMC,KAAK,GAAGM,IAAI,CAACI,GAAL,CAAS,GAAGL,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACX,CAAF,GAAMW,CAAC,CAACT,KAAzB,CAAZ,CAAd;EACA,MAAMC,MAAM,GAAGK,IAAI,CAACI,GAAL,CAAS,GAAGL,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,MAAzB,CAAZ,CAAf;EACA,OAAOJ,IAAI,CAACC,CAAD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AACZ,IAAF,CAAOG,KAAtB,EAA6BS,CAAC,CAACZ,IAAF,CAAOE,CAAP,GAAWU,CAAC,CAACZ,IAAF,CAAOI,MAA/C,CADG,GAEH,IAAAY,WAAA,EAAIJ,CAAC,CAACX,CAAF,GAAMW,CAAC,CAACT,KAAZ,EAAmBS,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,MAA3B,CAFJ;AAGD,CALM;;;;AAMA,MAAMgB,MAAM,GAAIR,CAAD,IAAyB;EAC7C;;EACA,OAAO,IAAAG,cAAA,EAAQH,CAAR,IACH,IAAAI,WAAA,EAAIJ,CAAC,CAACZ,IAAF,CAAOC,CAAP,GAAWW,CAAC,CAACZ,IAAF,CAAOG,KAAP,GAAe,CAA9B,EAAiCS,CAAC,CAACZ,IAAF,CAAOE,CAAP,GAAWU,CAAC,CAACZ,IAAF,CAAOI,MAAP,GAAgB,CAA5D,CADG,GAEH,IAAAY,WAAA,EAAIJ,CAAC,CAACX,CAAF,GAAMW,CAAC,CAACT,KAAF,GAAU,CAApB,EAAuBS,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,MAAF,GAAW,CAAxC,CAFJ;AAGD,CALM"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["Color.ts"],"sourcesContent":["// This is the JSI color\nexport type SkColor = Float32Array;\n// Input colors can be string, number or Float32Array\nexport type Color = string | Float32Array | number | number[];\n"],"mappings":""}
|
1
|
+
{"version":3,"names":[],"sources":["Color.ts"],"sourcesContent":["// This is the JSI color\nexport type SkColor = Float32Array;\n// Input colors can be string, number, number[] or Float32Array\nexport type Color = string | Float32Array | number | number[];\n"],"mappings":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["JsiInstance.ts"],"sourcesContent":["export interface
|
1
|
+
{"version":3,"names":[],"sources":["JsiInstance.ts"],"sourcesContent":["export interface SkJSIInstance<T extends string> {\n __typename__: T;\n dispose(): void;\n}\n"],"mappings":""}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
2
|
|
3
|
-
import React, { useEffect, useCallback, useMemo, forwardRef, useRef } from "react";
|
3
|
+
import React, { useEffect, useCallback, useMemo, forwardRef, useRef, useLayoutEffect } from "react";
|
4
4
|
import { SkiaDomView, SkiaView } from "../views";
|
5
5
|
import { Skia } from "../skia/Skia";
|
6
6
|
import { JsiDrawingContext } from "../dom/types";
|
@@ -9,6 +9,28 @@ import { SkiaRoot } from "./Reconciler";
|
|
9
9
|
import { NATIVE_DOM } from "./HostComponents";
|
10
10
|
import { isValue } from "./processors";
|
11
11
|
export const useCanvasRef = () => useRef(null);
|
12
|
+
|
13
|
+
const useOnSizeEvent = resultValue => {
|
14
|
+
const onSize = useValue({
|
15
|
+
width: 0,
|
16
|
+
height: 0
|
17
|
+
});
|
18
|
+
useLayoutEffect(() => {
|
19
|
+
if (!resultValue) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
return onSize.addListener(newValue => {
|
24
|
+
if (isValue(resultValue)) {
|
25
|
+
resultValue.current = newValue;
|
26
|
+
} else {
|
27
|
+
resultValue.value = newValue;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}, [resultValue, onSize]);
|
31
|
+
return onSize;
|
32
|
+
};
|
33
|
+
|
12
34
|
export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
13
35
|
let {
|
14
36
|
children,
|
@@ -16,21 +38,10 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
16
38
|
debug,
|
17
39
|
mode,
|
18
40
|
onTouch,
|
19
|
-
onSize:
|
41
|
+
onSize: _onSize,
|
20
42
|
...props
|
21
43
|
} = _ref;
|
22
|
-
const
|
23
|
-
width: 0,
|
24
|
-
height: 0
|
25
|
-
});
|
26
|
-
const onSize = isValue(onSizeReanimatedOrSkia) ? onSizeReanimatedOrSkia : size;
|
27
|
-
useEffect(() => {
|
28
|
-
if (!isValue(onSizeReanimatedOrSkia) && onSizeReanimatedOrSkia) {
|
29
|
-
return size.addListener(v => onSizeReanimatedOrSkia.value = v);
|
30
|
-
}
|
31
|
-
|
32
|
-
return undefined;
|
33
|
-
}, [onSizeReanimatedOrSkia, size]);
|
44
|
+
const onSize = useOnSizeEvent(_onSize);
|
34
45
|
const innerRef = useCanvasRef();
|
35
46
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
36
47
|
const redraw = useCallback(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","SkiaDomView","SkiaView","Skia","JsiDrawingContext","useValue","SkiaRoot","NATIVE_DOM","isValue","useCanvasRef","
|
1
|
+
{"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","useLayoutEffect","SkiaDomView","SkiaView","Skia","JsiDrawingContext","useValue","SkiaRoot","NATIVE_DOM","isValue","useCanvasRef","useOnSizeEvent","resultValue","onSize","width","height","addListener","newValue","current","value","Canvas","forwardedRef","children","style","debug","mode","onTouch","_onSize","props","innerRef","ref","useCombinedRefs","redraw","getNativeId","id","nativeId","registerValues","values","root","render","unmount","dom","canvas","info","touches","ctx","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useLayoutEffect,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\n\nimport { SkiaDomView, SkiaView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { TouchHandler, SkiaBaseViewProps } from \"../views\";\nimport type { SkiaValue } from \"../values/types\";\nimport { JsiDrawingContext } from \"../dom/types\";\nimport { useValue } from \"../values\";\n\nimport { SkiaRoot } from \"./Reconciler\";\nimport { NATIVE_DOM } from \"./HostComponents\";\nimport { isValue } from \"./processors\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nconst useOnSizeEvent = (resultValue: SkiaBaseViewProps[\"onSize\"]) => {\n const onSize = useValue({\n width: 0,\n height: 0,\n });\n\n useLayoutEffect(() => {\n if (!resultValue) {\n return;\n }\n return onSize.addListener((newValue) => {\n if (isValue(resultValue)) {\n resultValue.current = newValue;\n } else {\n resultValue.value = newValue;\n }\n });\n }, [resultValue, onSize]);\n\n return onSize;\n};\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize: _onSize, ...props },\n forwardedRef\n ) => {\n const onSize = useOnSizeEvent(_onSize);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current !== null) {\n return ref.current.registerValues(values);\n }\n return () => {};\n },\n [ref]\n );\n const root = useMemo(\n () => new SkiaRoot(Skia, registerValues, redraw, getNativeId),\n [redraw, registerValues, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n if (NATIVE_DOM) {\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n } else {\n return (\n <SkiaView\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref={ref as any}\n style={style}\n mode={mode}\n debug={debug}\n onSize={onSize}\n onDraw={(canvas, info) => {\n onTouch && onTouch(info.touches);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n }}\n {...props}\n />\n );\n }\n }\n) as React.FC<CanvasProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,WAFF,EAGEC,OAHF,EAIEC,UAJF,EAKEC,MALF,EAMEC,eANF,QAOO,OAPP;AAeA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,UAAtC;AACA,SAASC,IAAT,QAAqB,cAArB;AAGA,SAASC,iBAAT,QAAkC,cAAlC;AACA,SAASC,QAAT,QAAyB,WAAzB;AAEA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,UAAT,QAA2B,kBAA3B;AACA,SAASC,OAAT,QAAwB,cAAxB;AAEA,OAAO,MAAMC,YAAY,GAAG,MAAMV,MAAM,CAAc,IAAd,CAAjC;;AAQP,MAAMW,cAAc,GAAIC,WAAD,IAA8C;EACnE,MAAMC,MAAM,GAAGP,QAAQ,CAAC;IACtBQ,KAAK,EAAE,CADe;IAEtBC,MAAM,EAAE;EAFc,CAAD,CAAvB;EAKAd,eAAe,CAAC,MAAM;IACpB,IAAI,CAACW,WAAL,EAAkB;MAChB;IACD;;IACD,OAAOC,MAAM,CAACG,WAAP,CAAoBC,QAAD,IAAc;MACtC,IAAIR,OAAO,CAACG,WAAD,CAAX,EAA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EAAA,kCADAe,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAGpD,KAAK,CAACK,MAAN,CAAgB,IAAhB,CAAlB;EACAL,KAAK,CAACC,SAAN,CAAgB,MAAM;IACpBkD,IAAI,CAACE,OAAL,CAAclB,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACiB,SAAS,CAAC7B,OAAX,CAAH;QACD,CAFD,MAEO;UACLY,GAAG,CAACZ,OAAJ,GAAc6B,SAAS,CAAC7B,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAAC4B,IAAD,CAVH;EAWA,OAAOC,SAAP;AACD,CAhBD"}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type { SkData, DataSourceParam,
|
2
|
-
export declare const useRawData: <T extends
|
1
|
+
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => T | null;
|
3
3
|
export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam,
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;A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AtB;EACA,MAAM,CAAC0B,IAAD,EAAOC,OAAP,IAAkB1B,QAAQ,CAAW,IAAX,CAAhC;EACA,MAAM2B,OAAO,GAAG5B,MAAM,CAAW,IAAX,CAAtB;EACAD,SAAS,CAAC,MAAM;IACd0B,OAAO,CAACI,OAAR,GAAkB,IAAlB;IACAL,MAAM,GAAGH,IAAT,CAAeS,KAAD,IAAW;MACvB,IAAIL,OAAO,CAACI,OAAZ,EAAqB;QACnBF,OAAO,CAACG,KAAD,CAAP;QACAF,OAAO,CAACC,OAAR,GAAkBC,KAAlB;MACD;IACF,CALD;IAMA,OAAO,MAAM;MAAA;;MACX,oBAAAF,OAAO,CAACC,OAAR,sEAAiBE,OAAjB;MACAN,OAAO,CAACI,OAAR,GAAkB,KAAlB;IACD,CAHD,CARc,CAYd;EACD,CAbQ,EAaN,CAAClB,MAAD,CAbM,CAAT;EAcA,OAAOe,IAAP;AACD,CAtBD;;AAwBA,OAAO,MAAMM,UAAU,GAAG,CACxBrB,MADwB,EAExBL,OAFwB,EAGxBC,OAHwB,KAIrBgB,UAAU,CAACZ,MAAD,EAAS,MAAMD,QAAQ,CAAIC,MAAJ,EAAYL,OAAZ,EAAqBC,OAArB,CAAvB,CAJR;;AAMP,MAAM0B,QAAQ,GAAIP,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMQ,OAAO,GAAG,CACrBvB,MADqB,EAErBJ,OAFqB,KAGlByB,UAAU,CAACrB,MAAD,EAASsB,QAAT,EAAmB1B,OAAnB,CAHR"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Skia","rrect","r","rx","ry","RRectXY"],"sources":["RRect.tsx"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect } from \"../types\";\n\nexport const rrect = (r: SkRect, rx: number, ry: number)
|
1
|
+
{"version":3,"names":["Skia","rrect","r","rx","ry","RRectXY"],"sources":["RRect.tsx"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect } from \"../types\";\n\nexport const rrect = (r: SkRect, rx: number, ry: number) => {\n \"worklet\";\n return Skia.RRectXY(r, rx, ry);\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,OAAO,MAAMC,KAAK,GAAG,CAACC,CAAD,EAAYC,EAAZ,EAAwBC,EAAxB,KAAuC;EAC1D;;EACA,OAAOJ,IAAI,CAACK,OAAL,CAAaH,CAAb,EAAgBC,EAAhB,EAAoBC,EAApB,CAAP;AACD,CAHM"}
|
@@ -1,17 +1,43 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
2
|
import { isRRect } from "../types";
|
3
3
|
import { vec } from "./Vector";
|
4
|
-
export const rect = (x, y, width, height) =>
|
4
|
+
export const rect = (x, y, width, height) => {
|
5
|
+
"worklet";
|
6
|
+
|
7
|
+
return Skia.XYWHRect(x, y, width, height);
|
8
|
+
};
|
5
9
|
export const bounds = rects => {
|
10
|
+
"worklet";
|
11
|
+
|
6
12
|
const x = Math.min(...rects.map(r => r.x));
|
7
13
|
const y = Math.min(...rects.map(r => r.y));
|
8
14
|
const width = Math.max(...rects.map(r => r.x + r.width));
|
9
15
|
const height = Math.max(...rects.map(r => r.y + r.height));
|
10
16
|
return rect(x, y, width - x, height - y);
|
11
17
|
};
|
12
|
-
export const topLeft = r =>
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
export const topLeft = r => {
|
19
|
+
"worklet";
|
20
|
+
|
21
|
+
return isRRect(r) ? vec(r.rect.x, r.rect.y) : vec(r.x, r.y);
|
22
|
+
};
|
23
|
+
export const topRight = r => {
|
24
|
+
"worklet";
|
25
|
+
|
26
|
+
return isRRect(r) ? vec(r.rect.x + r.rect.width, r.rect.y) : vec(r.x + r.width, r.y);
|
27
|
+
};
|
28
|
+
export const bottomLeft = r => {
|
29
|
+
"worklet";
|
30
|
+
|
31
|
+
return isRRect(r) ? vec(r.rect.x, r.rect.y + r.rect.height) : vec(r.x, r.y + r.height);
|
32
|
+
};
|
33
|
+
export const bottomRight = r => {
|
34
|
+
"worklet";
|
35
|
+
|
36
|
+
return isRRect(r) ? vec(r.rect.x + r.rect.width, r.rect.y + r.rect.height) : vec(r.x + r.width, r.y + r.height);
|
37
|
+
};
|
38
|
+
export const center = r => {
|
39
|
+
"worklet";
|
40
|
+
|
41
|
+
return isRRect(r) ? vec(r.rect.x + r.rect.width / 2, r.rect.y + r.rect.height / 2) : vec(r.x + r.width / 2, r.y + r.height / 2);
|
42
|
+
};
|
17
43
|
//# sourceMappingURL=Rect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Skia","isRRect","vec","rect","x","y","width","height","XYWHRect","bounds","rects","Math","min","map","r","max","topLeft","topRight","bottomLeft","bottomRight","center"],"sources":["Rect.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect, SkRRect } from \"../types\";\nimport { isRRect } from \"../types\";\n\nimport { vec } from \"./Vector\";\n\nexport const rect = (x: number, y: number, width: number, height: number)
|
1
|
+
{"version":3,"names":["Skia","isRRect","vec","rect","x","y","width","height","XYWHRect","bounds","rects","Math","min","map","r","max","topLeft","topRight","bottomLeft","bottomRight","center"],"sources":["Rect.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkRect, SkRRect } from \"../types\";\nimport { isRRect } from \"../types\";\n\nimport { vec } from \"./Vector\";\n\nexport const rect = (x: number, y: number, width: number, height: number) => {\n \"worklet\";\n return Skia.XYWHRect(x, y, width, height);\n};\n\nexport const bounds = (rects: SkRect[]) => {\n \"worklet\";\n const x = Math.min(...rects.map((r) => r.x));\n const y = Math.min(...rects.map((r) => r.y));\n const width = Math.max(...rects.map((r) => r.x + r.width));\n const height = Math.max(...rects.map((r) => r.y + r.height));\n return rect(x, y, width - x, height - y);\n};\n\nexport const topLeft = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r) ? vec(r.rect.x, r.rect.y) : vec(r.x, r.y);\n};\n\nexport const topRight = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width, r.rect.y)\n : vec(r.x + r.width, r.y);\n};\n\nexport const bottomLeft = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x, r.rect.y + r.rect.height)\n : vec(r.x, r.y + r.height);\n};\nexport const bottomRight = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width, r.rect.y + r.rect.height)\n : vec(r.x + r.width, r.y + r.height);\n};\nexport const center = (r: SkRect | SkRRect) => {\n \"worklet\";\n return isRRect(r)\n ? vec(r.rect.x + r.rect.width / 2, r.rect.y + r.rect.height / 2)\n : vec(r.x + r.width / 2, r.y + r.height / 2);\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAEA,SAASC,OAAT,QAAwB,UAAxB;AAEA,SAASC,GAAT,QAAoB,UAApB;AAEA,OAAO,MAAMC,IAAI,GAAG,CAACC,CAAD,EAAYC,CAAZ,EAAuBC,KAAvB,EAAsCC,MAAtC,KAAyD;EAC3E;;EACA,OAAOP,IAAI,CAACQ,QAAL,CAAcJ,CAAd,EAAiBC,CAAjB,EAAoBC,KAApB,EAA2BC,MAA3B,CAAP;AACD,CAHM;AAKP,OAAO,MAAME,MAAM,GAAIC,KAAD,IAAqB;EACzC;;EACA,MAAMN,CAAC,GAAGO,IAAI,CAACC,GAAL,CAAS,GAAGF,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACV,CAAnB,CAAZ,CAAV;EACA,MAAMC,CAAC,GAAGM,IAAI,CAACC,GAAL,CAAS,GAAGF,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACT,CAAnB,CAAZ,CAAV;EACA,MAAMC,KAAK,GAAGK,IAAI,CAACI,GAAL,CAAS,GAAGL,KAAK,CAACG,GAAN,CAAWC,CAAD,IAAOA,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,KAAzB,CAAZ,CAAd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GAAIL,CAAD,IAAyB;EAClD;;EACA,OAAOb,OAAO,CAACa,CAAD,CAAP,GACHZ,GAAG,CAACY,CAAC,CAACX,IAAF,CAAOC,CAAP,GAAWU,CAAC,CAACX,IAAF,CAAOG,KAAnB,EAA0BQ,CAAC,CAACX,IAAF,CAAOE,CAAP,GAAWS,CAAC,CAACX,IAAF,CAAOI,MAA5C,CADA,GAEHL,GAAG,CAACY,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,KAAT,EAAgBQ,CAAC,CAACT,CAAF,GAAMS,CAAC,CAACP,MAAxB,CAFP;AAGD,CALM;AAMP,OAAO,MAAMa,MAAM,GAAIN,CAAD,IAAyB;EAC7C;;EACA,OAAOb,OAAO,CAACa,CAAD,CAAP,GACHZ,GAAG,CAACY,CAAC,CAACX,IAAF,CAAOC,CAAP,GAAWU,CAAC,CAACX,IAAF,CAAOG,KAAP,GAAe,CAA3B,EAA8BQ,CAAC,CAACX,IAAF,CAAOE,CAAP,GAAWS,CAAC,CAACX,IAAF,CAAOI,MAAP,GAAgB,CAAzD,CADA,GAEHL,GAAG,CAACY,CAAC,CAACV,CAAF,GAAMU,CAAC,CAACR,KAAF,GAAU,CAAjB,EAAoBQ,CAAC,CAACT,CAAF,GAAMS,CAAC,CAACP,MAAF,GAAW,CAArC,CAFP;AAGD,CALM"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["Color.ts"],"sourcesContent":["// This is the JSI color\nexport type SkColor = Float32Array;\n// Input colors can be string, number or Float32Array\nexport type Color = string | Float32Array | number | number[];\n"],"mappings":""}
|
1
|
+
{"version":3,"names":[],"sources":["Color.ts"],"sourcesContent":["// This is the JSI color\nexport type SkColor = Float32Array;\n// Input colors can be string, number, number[] or Float32Array\nexport type Color = string | Float32Array | number | number[];\n"],"mappings":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["JsiInstance.ts"],"sourcesContent":["export interface
|
1
|
+
{"version":3,"names":[],"sources":["JsiInstance.ts"],"sourcesContent":["export interface SkJSIInstance<T extends string> {\n __typename__: T;\n dispose(): void;\n}\n"],"mappings":""}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type { SkData, DataSourceParam,
|
2
|
-
export declare const useRawData: <T extends
|
1
|
+
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => T | null;
|
3
3
|
export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|