@shopify/react-native-skia 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/cpp/jni/JniPlatformContext.cpp +23 -0
  3. package/android/cpp/jni/include/JniPlatformContext.h +2 -0
  4. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +6 -0
  5. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +92 -0
  6. package/android/cpp/rnskia-android/RNSkAndroidVideo.h +36 -0
  7. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +34 -14
  8. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +2 -1
  9. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +5 -0
  10. package/android/src/main/java/com/shopify/reactnative/skia/RNSkVideo.java +185 -0
  11. package/cpp/api/JsiSkApi.h +2 -0
  12. package/cpp/api/JsiSkImageFactory.h +3 -3
  13. package/cpp/api/JsiVideo.h +87 -0
  14. package/cpp/rnskia/RNSkPlatformContext.h +4 -1
  15. package/cpp/rnskia/RNSkVideo.h +23 -0
  16. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +2 -0
  17. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +7 -1
  18. package/ios/RNSkia-iOS/RNSkiOSVideo.h +40 -0
  19. package/ios/RNSkia-iOS/RNSkiOSVideo.mm +119 -0
  20. package/ios/RNSkia-iOS/RNSkiOSView.mm +37 -0
  21. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +2 -2
  22. package/lib/commonjs/external/reanimated/index.d.ts +1 -0
  23. package/lib/commonjs/external/reanimated/index.js +11 -0
  24. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  25. package/lib/commonjs/external/reanimated/useVideo.d.ts +10 -0
  26. package/lib/commonjs/external/reanimated/useVideo.js +93 -0
  27. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -0
  28. package/lib/commonjs/mock/index.js +2 -1
  29. package/lib/commonjs/mock/index.js.map +1 -1
  30. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +3 -3
  31. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  32. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +2 -2
  33. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  34. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  35. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  36. package/lib/commonjs/skia/types/Video/Video.d.ts +8 -0
  37. package/lib/commonjs/skia/types/Video/Video.js +6 -0
  38. package/lib/commonjs/skia/types/Video/Video.js.map +1 -0
  39. package/lib/commonjs/skia/types/Video/index.d.ts +1 -0
  40. package/lib/commonjs/skia/types/Video/index.js +17 -0
  41. package/lib/commonjs/skia/types/Video/index.js.map +1 -0
  42. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  43. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +1 -1
  44. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkia.js +4 -1
  46. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  47. package/lib/module/external/reanimated/index.d.ts +1 -0
  48. package/lib/module/external/reanimated/index.js +1 -0
  49. package/lib/module/external/reanimated/index.js.map +1 -1
  50. package/lib/module/external/reanimated/useVideo.d.ts +10 -0
  51. package/lib/module/external/reanimated/useVideo.js +85 -0
  52. package/lib/module/external/reanimated/useVideo.js.map +1 -0
  53. package/lib/module/mock/index.js +2 -1
  54. package/lib/module/mock/index.js.map +1 -1
  55. package/lib/module/skia/types/Image/ImageFactory.d.ts +3 -3
  56. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  57. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +2 -2
  58. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  59. package/lib/module/skia/types/Skia.d.ts +2 -0
  60. package/lib/module/skia/types/Skia.js.map +1 -1
  61. package/lib/module/skia/types/Video/Video.d.ts +8 -0
  62. package/lib/module/skia/types/Video/Video.js +2 -0
  63. package/lib/module/skia/types/Video/Video.js.map +1 -0
  64. package/lib/module/skia/types/Video/index.d.ts +1 -0
  65. package/lib/module/skia/types/Video/index.js +2 -0
  66. package/lib/module/skia/types/Video/index.js.map +1 -0
  67. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  68. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +1 -1
  69. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  70. package/lib/module/skia/web/JsiSkia.js +4 -1
  71. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  72. package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
  73. package/lib/typescript/src/external/reanimated/useVideo.d.ts +10 -0
  74. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +3 -3
  75. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +2 -2
  76. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  77. package/lib/typescript/src/skia/types/Video/Video.d.ts +8 -0
  78. package/lib/typescript/src/skia/types/Video/index.d.ts +1 -0
  79. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  80. package/package.json +1 -1
  81. package/scripts/setup-canvaskit.js +1 -1
  82. package/src/external/reanimated/index.ts +1 -0
  83. package/src/external/reanimated/useVideo.ts +115 -0
  84. package/src/mock/index.ts +1 -0
  85. package/src/skia/types/Image/ImageFactory.ts +3 -3
  86. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +2 -2
  87. package/src/skia/types/Skia.ts +2 -0
  88. package/src/skia/types/Video/Video.ts +9 -0
  89. package/src/skia/types/Video/index.ts +1 -0
  90. package/src/skia/web/JsiSkNativeBufferFactory.ts +1 -1
  91. package/src/skia/web/JsiSkia.ts +3 -0
@@ -5,6 +5,7 @@
5
5
  #include <thread>
6
6
  #include <utility>
7
7
 
8
+ #include "RNSkiOSVideo.h"
8
9
  #import "SkiaCVPixelBufferUtils.h"
9
10
  #import "SkiaMetalSurfaceFactory.h"
10
11
 
@@ -75,7 +76,7 @@ uint64_t RNSkiOSPlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
75
76
  if (image == nullptr) {
76
77
  throw std::runtime_error(
77
78
  "Failed to convert image to BGRA_8888 colortype! Only BGRA_8888 "
78
- "PlatformBuffers are supported.");
79
+ "NativeBuffers are supported.");
79
80
  }
80
81
  }
81
82
 
@@ -143,6 +144,11 @@ uint64_t RNSkiOSPlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
143
144
  return reinterpret_cast<uint64_t>(pixelBuffer);
144
145
  }
145
146
 
147
+ std::shared_ptr<RNSkVideo>
148
+ RNSkiOSPlatformContext::createVideo(const std::string &url) {
149
+ return std::make_shared<RNSkiOSVideo>(url, this);
150
+ }
151
+
146
152
  void RNSkiOSPlatformContext::raiseError(const std::exception &err) {
147
153
  RCTFatal(RCTErrorWithMessage([NSString stringWithUTF8String:err.what()]));
148
154
  }
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+
5
+ #include <AVFoundation/AVFoundation.h>
6
+ #include <CoreVideo/CoreVideo.h>
7
+
8
+ #pragma clang diagnostic push
9
+ #pragma clang diagnostic ignored "-Wdocumentation"
10
+
11
+ #include "include/core/SkImage.h"
12
+
13
+ #pragma clang diagnostic pop
14
+
15
+ #include "RNSkPlatformContext.h"
16
+ #include "RNSkVideo.h"
17
+
18
+ namespace RNSkia {
19
+
20
+ class RNSkiOSVideo : public RNSkVideo {
21
+ private:
22
+ std::string _url;
23
+ AVAssetReader *_reader = nullptr;
24
+ AVAssetReaderTrackOutput *_trackOutput = nullptr;
25
+ RNSkPlatformContext *_context;
26
+ double _duration = 0;
27
+ double _framerate = 0;
28
+ void setupReader(CMTimeRange timeRange);
29
+ NSDictionary *getOutputSettings();
30
+
31
+ public:
32
+ RNSkiOSVideo(std::string url, RNSkPlatformContext *context);
33
+ ~RNSkiOSVideo();
34
+ sk_sp<SkImage> nextImage(double *timeStamp = nullptr) override;
35
+ double duration() override;
36
+ double framerate() override;
37
+ void seek(double timestamp) override;
38
+ };
39
+
40
+ } // namespace RNSkia
@@ -0,0 +1,119 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #pragma clang diagnostic push
7
+ #pragma clang diagnostic ignored "-Wdocumentation"
8
+
9
+ #include "include/core/SkImage.h"
10
+
11
+ #pragma clang diagnostic pop
12
+
13
+ #include "RNSkiOSVideo.h"
14
+ #include <AVFoundation/AVFoundation.h>
15
+ #include <CoreVideo/CoreVideo.h>
16
+
17
+ namespace RNSkia {
18
+
19
+ RNSkiOSVideo::RNSkiOSVideo(std::string url, RNSkPlatformContext *context)
20
+ : _url(std::move(url)), _context(context) {
21
+ setupReader(CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity));
22
+ }
23
+
24
+ RNSkiOSVideo::~RNSkiOSVideo() {}
25
+
26
+ void RNSkiOSVideo::setupReader(CMTimeRange timeRange) {
27
+ NSError *error = nil;
28
+
29
+ AVURLAsset *asset =
30
+ [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@(_url.c_str())]
31
+ options:nil];
32
+ AVAssetReader *assetReader = [[AVAssetReader alloc] initWithAsset:asset
33
+ error:&error];
34
+ if (error) {
35
+ NSLog(@"Error initializing asset reader: %@", error.localizedDescription);
36
+ return;
37
+ }
38
+
39
+ CMTime time = [asset duration];
40
+ if (time.timescale == 0) {
41
+ NSLog(@"Error: Timescale of the asset is zero.");
42
+ return;
43
+ }
44
+
45
+ _duration = CMTimeGetSeconds(time) * 1000; // Store duration in milliseconds
46
+ AVAssetTrack *videoTrack =
47
+ [[asset tracksWithMediaType:AVMediaTypeVideo] firstObject];
48
+ _framerate = videoTrack.nominalFrameRate;
49
+
50
+ NSDictionary *outputSettings = getOutputSettings();
51
+ AVAssetReaderTrackOutput *trackOutput =
52
+ [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack
53
+ outputSettings:outputSettings];
54
+
55
+ assetReader.timeRange = timeRange;
56
+ if ([assetReader canAddOutput:trackOutput]) {
57
+ [assetReader addOutput:trackOutput];
58
+ [assetReader startReading];
59
+ } else {
60
+ NSLog(@"Cannot add output to asset reader.");
61
+ return;
62
+ }
63
+
64
+ _reader = assetReader;
65
+ _trackOutput = trackOutput;
66
+ }
67
+
68
+ sk_sp<SkImage> RNSkiOSVideo::nextImage(double *timeStamp) {
69
+ CMSampleBufferRef sampleBuffer = [_trackOutput copyNextSampleBuffer];
70
+ if (!sampleBuffer) {
71
+ NSLog(@"No sample buffer.");
72
+ return nullptr;
73
+ }
74
+
75
+ // Extract the pixel buffer from the sample buffer
76
+ CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
77
+ if (!pixelBuffer) {
78
+ NSLog(@"No pixel buffer.");
79
+ CFRelease(sampleBuffer);
80
+ return nullptr;
81
+ }
82
+
83
+ auto skImage = _context->makeImageFromNativeBuffer(
84
+ reinterpret_cast<void *>(pixelBuffer));
85
+
86
+ if (timeStamp) {
87
+ CMTime time = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
88
+ *timeStamp = CMTimeGetSeconds(time);
89
+ }
90
+
91
+ CFRelease(sampleBuffer);
92
+ return skImage;
93
+ }
94
+
95
+ NSDictionary *RNSkiOSVideo::getOutputSettings() {
96
+ return @{
97
+ (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA),
98
+ (id)kCVPixelBufferMetalCompatibilityKey : @YES
99
+ };
100
+ }
101
+
102
+ void RNSkiOSVideo::seek(double timeInMilliseconds) {
103
+ if (_reader) {
104
+ [_reader cancelReading];
105
+ _reader = nil;
106
+ _trackOutput = nil;
107
+ }
108
+
109
+ CMTime startTime =
110
+ CMTimeMakeWithSeconds(timeInMilliseconds / 1000.0, NSEC_PER_SEC);
111
+ CMTimeRange timeRange = CMTimeRangeMake(startTime, kCMTimePositiveInfinity);
112
+ setupReader(timeRange);
113
+ }
114
+
115
+ double RNSkiOSVideo::duration() { return _duration; }
116
+
117
+ double RNSkiOSVideo::framerate() { return _framerate; }
118
+
119
+ } // namespace RNSkia
@@ -0,0 +1,37 @@
1
+ #pragma once
2
+
3
+ #import <memory>
4
+
5
+ #import "RNSkMetalCanvasProvider.h"
6
+ #import "RNSkView.h"
7
+ #import "RNSkiOSPlatformContext.h"
8
+
9
+ class RNSkBaseiOSView {
10
+ public:
11
+ virtual CALayer *getLayer() = 0;
12
+ virtual void setSize(int width, int height) = 0;
13
+ virtual std::shared_ptr<RNSkia::RNSkView> getDrawView() = 0;
14
+ };
15
+
16
+ template <class T> class RNSkiOSView : public RNSkBaseiOSView, public T {
17
+ public:
18
+ RNSkiOSView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
19
+ : T(context,
20
+ std::make_shared<RNSkMetalCanvasProvider>(
21
+ std::bind(&RNSkia::RNSkView::requestRedraw, this), context)) {}
22
+
23
+ CALayer *getLayer() override {
24
+ return std::static_pointer_cast<RNSkMetalCanvasProvider>(
25
+ this->getCanvasProvider())
26
+ ->getLayer();
27
+ }
28
+
29
+ void setSize(int width, int height) override {
30
+ std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
31
+ ->setSize(width, height);
32
+ }
33
+
34
+ std::shared_ptr<RNSkia::RNSkView> getDrawView() override {
35
+ return this->shared_from_this();
36
+ }
37
+ };
@@ -130,8 +130,8 @@ sk_sp<SkImage> SkiaMetalSurfaceFactory::makeTextureFromCVPixelBuffer(
130
130
  }
131
131
  default:
132
132
  [[unlikely]] {
133
- throw std::runtime_error("Failed to convert PlatformBuffer to SkImage - "
134
- "PlatformBuffer has unsupported PixelFormat! " +
133
+ throw std::runtime_error("Failed to convert NativeBuffer to SkImage - "
134
+ "NativeBuffer has unsupported PixelFormat! " +
135
135
  std::to_string(static_cast<int>(format)));
136
136
  }
137
137
  }
@@ -4,3 +4,4 @@ export * from "./renderHelpers";
4
4
  export * from "./interpolators";
5
5
  export * from "./textures";
6
6
  export * from "./buffers";
7
+ export * from "./useVideo";
@@ -69,4 +69,15 @@ Object.keys(_buffers).forEach(function (key) {
69
69
  }
70
70
  });
71
71
  });
72
+ var _useVideo = require("./useVideo");
73
+ Object.keys(_useVideo).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _useVideo[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function () {
79
+ return _useVideo[key];
80
+ }
81
+ });
82
+ });
72
83
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_useAnimatedImageValue","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_useDerivedValueOnJS","_renderHelpers","_interpolators","_textures","_buffers"],"sources":["index.ts"],"sourcesContent":["export * from \"./useAnimatedImageValue\";\nexport * from \"./useDerivedValueOnJS\";\nexport * from \"./renderHelpers\";\nexport * from \"./interpolators\";\nexport * from \"./textures\";\nexport * from \"./buffers\";\n"],"mappings":";;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,sBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,sBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,sBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,oBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,oBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAA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AA,CAAA;MAAA,OAAAI,SAAA,CAAAR,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,QAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAS,QAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,QAAA,CAAAT,GAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":["_useAnimatedImageValue","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_useDerivedValueOnJS","_renderHelpers","_interpolators","_textures","_buffers","_useVideo"],"sources":["index.ts"],"sourcesContent":["export * from \"./useAnimatedImageValue\";\nexport * from \"./useDerivedValueOnJS\";\nexport * from \"./renderHelpers\";\nexport * from \"./interpolators\";\nexport * from \"./textures\";\nexport * from \"./buffers\";\nexport * from \"./useVideo\";\n"],"mappings":";;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,sBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,sBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,sBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,oBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,oBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,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GAAA,WAAAA,CAAA;MAAA,OAAAI,SAAA,CAAAR,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,QAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAS,QAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,QAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,SAAA,GAAAd,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAY,SAAA,EAAAX,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAU,SAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,SAAA,CAAAV,GAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,10 @@
1
+ import { type SharedValue } from "react-native-reanimated";
2
+ import type { SkImage } from "../../skia/types";
3
+ type Animated<T> = SharedValue<T> | T;
4
+ export interface PlaybackOptions {
5
+ playbackSpeed: Animated<number>;
6
+ looping: Animated<boolean>;
7
+ paused: Animated<boolean>;
8
+ }
9
+ export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => SharedValue<SkImage | null>;
10
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useVideo = void 0;
7
+ var _reactNativeReanimated = require("react-native-reanimated");
8
+ var _react = require("react");
9
+ var _Skia = require("../../skia/Skia");
10
+ var _Platform = require("../../Platform");
11
+ var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ const defaultOptions = {
14
+ playbackSpeed: 1,
15
+ looping: true,
16
+ paused: false
17
+ };
18
+ const useOption = value => {
19
+ "worklet";
20
+
21
+ // TODO: only create defaultValue is needed (via makeMutable)
22
+ const defaultValue = (0, _reactNativeReanimated.useSharedValue)(_ReanimatedProxy.default.isSharedValue(value) ? value.value : value);
23
+ return _ReanimatedProxy.default.isSharedValue(value) ? value : defaultValue;
24
+ };
25
+ const useVideo = (source, userOptions) => {
26
+ var _userOptions$paused, _userOptions$looping, _userOptions$playback;
27
+ const video = (0, _react.useMemo)(() => source ? _Skia.Skia.Video(source) : null, [source]);
28
+ const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused);
29
+ const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping);
30
+ const playbackSpeed = useOption((_userOptions$playback = userOptions === null || userOptions === void 0 ? void 0 : userOptions.playbackSpeed) !== null && _userOptions$playback !== void 0 ? _userOptions$playback : defaultOptions.playbackSpeed);
31
+ const currentFrame = _ReanimatedProxy.default.useSharedValue(null);
32
+ const lastTimestamp = _ReanimatedProxy.default.useSharedValue(-1);
33
+ const startTimestamp = _ReanimatedProxy.default.useSharedValue(-1);
34
+ const framerate = (0, _react.useMemo)(() => video ? video.framerate() : -1, [video]);
35
+ const duration = (0, _react.useMemo)(() => video ? video.duration() : -1, [video]);
36
+ const frameDuration = (0, _react.useMemo)(() => framerate > 0 ? 1000 / framerate : -1, [framerate]);
37
+ const disposeVideo = (0, _react.useCallback)(() => {
38
+ "worklet";
39
+
40
+ video === null || video === void 0 || video.dispose();
41
+ }, [video]);
42
+ _ReanimatedProxy.default.useFrameCallback(frameInfo => {
43
+ if (!video) {
44
+ return;
45
+ }
46
+ if (isPaused.value && lastTimestamp.value !== -1) {
47
+ return;
48
+ }
49
+ const {
50
+ timestamp
51
+ } = frameInfo;
52
+
53
+ // Initialize start timestamp
54
+ if (startTimestamp.value === -1) {
55
+ startTimestamp.value = timestamp;
56
+ }
57
+
58
+ // Calculate the current time in the video
59
+ const currentTimestamp = timestamp - startTimestamp.value;
60
+
61
+ // Handle looping
62
+ if (currentTimestamp > duration && looping.value) {
63
+ video.seek(0);
64
+ startTimestamp.value = timestamp;
65
+ }
66
+
67
+ // Update frame only if the elapsed time since last update is greater than the frame duration
68
+ const currentFrameDuration = frameDuration / playbackSpeed.value;
69
+ if (lastTimestamp.value === -1 || timestamp - lastTimestamp.value >= currentFrameDuration) {
70
+ const img = video.nextImage();
71
+ if (img) {
72
+ if (currentFrame.value) {
73
+ currentFrame.value.dispose();
74
+ }
75
+ if (_Platform.Platform.OS === "android") {
76
+ currentFrame.value = img.makeNonTextureImage();
77
+ } else {
78
+ currentFrame.value = img;
79
+ }
80
+ }
81
+ lastTimestamp.value = timestamp;
82
+ }
83
+ });
84
+ (0, _react.useEffect)(() => {
85
+ return () => {
86
+ // TODO: should video simply be a shared value instead?
87
+ (0, _reactNativeReanimated.runOnUI)(disposeVideo)();
88
+ };
89
+ }, [disposeVideo, video]);
90
+ return currentFrame;
91
+ };
92
+ exports.useVideo = useVideo;
93
+ //# sourceMappingURL=useVideo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNativeReanimated","require","_react","_Skia","_Platform","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","defaultOptions","playbackSpeed","looping","paused","useOption","value","defaultValue","useSharedValue","Rea","isSharedValue","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$playback","video","useMemo","Skia","Video","isPaused","currentFrame","lastTimestamp","startTimestamp","framerate","duration","frameDuration","disposeVideo","useCallback","dispose","useFrameCallback","frameInfo","timestamp","currentTimestamp","seek","currentFrameDuration","img","nextImage","Platform","OS","makeNonTextureImage","useEffect","runOnUI","exports"],"sources":["useVideo.ts"],"sourcesContent":["import {\n runOnUI,\n useSharedValue,\n type FrameInfo,\n type SharedValue,\n} from \"react-native-reanimated\";\nimport { useCallback, useEffect, useMemo } from \"react\";\n\nimport { Skia } from \"../../skia/Skia\";\nimport type { SkImage } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\n\ntype Animated<T> = SharedValue<T> | T;\n\nexport interface PlaybackOptions {\n playbackSpeed: Animated<number>;\n looping: Animated<boolean>;\n paused: Animated<boolean>;\n}\n\nconst defaultOptions = {\n playbackSpeed: 1,\n looping: true,\n paused: false,\n};\n\nconst useOption = <T>(value: Animated<T>) => {\n \"worklet\";\n // TODO: only create defaultValue is needed (via makeMutable)\n const defaultValue = useSharedValue(\n Rea.isSharedValue(value) ? value.value : value\n );\n return Rea.isSharedValue(value) ? value : defaultValue;\n};\n\nexport const useVideo = (\n source: string | null,\n userOptions?: Partial<PlaybackOptions>\n) => {\n const video = useMemo(() => (source ? Skia.Video(source) : null), [source]);\n const isPaused = useOption(userOptions?.paused ?? defaultOptions.paused);\n const looping = useOption(userOptions?.looping ?? defaultOptions.looping);\n const playbackSpeed = useOption(\n userOptions?.playbackSpeed ?? defaultOptions.playbackSpeed\n );\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\n const startTimestamp = Rea.useSharedValue(-1);\n\n const framerate = useMemo(() => (video ? video.framerate() : -1), [video]);\n const duration = useMemo(() => (video ? video.duration() : -1), [video]);\n const frameDuration = useMemo(\n () => (framerate > 0 ? 1000 / framerate : -1),\n [framerate]\n );\n const disposeVideo = useCallback(() => {\n \"worklet\";\n video?.dispose();\n }, [video]);\n\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!video) {\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n\n // Initialize start timestamp\n if (startTimestamp.value === -1) {\n startTimestamp.value = timestamp;\n }\n\n // Calculate the current time in the video\n const currentTimestamp = timestamp - startTimestamp.value;\n\n // Handle looping\n if (currentTimestamp > duration && looping.value) {\n video.seek(0);\n startTimestamp.value = timestamp;\n }\n\n // Update frame only if the elapsed time since last update is greater than the frame duration\n const currentFrameDuration = frameDuration / playbackSpeed.value;\n if (\n lastTimestamp.value === -1 ||\n timestamp - lastTimestamp.value >= currentFrameDuration\n ) {\n const img = video.nextImage();\n if (img) {\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n if (Platform.OS === \"android\") {\n currentFrame.value = img.makeNonTextureImage();\n } else {\n currentFrame.value = img;\n }\n }\n lastTimestamp.value = timestamp;\n }\n });\n\n useEffect(() => {\n return () => {\n // TODO: should video simply be a shared value instead?\n runOnUI(disposeVideo)();\n };\n }, [disposeVideo, video]);\n\n return currentFrame;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAAoC,SAAAK,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAUpC,MAAMG,cAAc,GAAG;EACrBC,aAAa,EAAE,CAAC;EAChBC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE;AACV,CAAC;AAED,MAAMC,SAAS,GAAOC,KAAkB,IAAK;EAC3C,SAAS;;EACT;EACA,MAAMC,YAAY,GAAG,IAAAC,qCAAc,EACjCC,wBAAG,CAACC,aAAa,CAACJ,KAAK,CAAC,GAAGA,KAAK,CAACA,KAAK,GAAGA,KAC3C,CAAC;EACD,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AID,GAAG,EAAE;QACP,IAAIf,YAAY,CAAChB,KAAK,EAAE;UACtBgB,YAAY,CAAChB,KAAK,CAACwB,OAAO,CAAC,CAAC;QAC9B;QACA,IAAIS,kBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;UAC7BlB,YAAY,CAAChB,KAAK,GAAG+B,GAAG,CAACI,mBAAmB,CAAC,CAAC;QAChD,CAAC,MAAM;UACLnB,YAAY,CAAChB,KAAK,GAAG+B,GAAG;QAC1B;MACF;MACAd,aAAa,CAACjB,KAAK,GAAG2B,SAAS;IACjC;EACF,CAAC,CAAC;EAEF,IAAAS,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACX;MACA,IAAAC,8BAAO,EAACf,YAAY,CAAC,CAAC,CAAC;IACzB,CAAC;EACH,CAAC,EAAE,CAACA,YAAY,EAAEX,KAAK,CAAC,CAAC;EAEzB,OAAOK,YAAY;AACrB,CAAC;AAACsB,OAAA,CAAAjC,QAAA,GAAAA,QAAA"}
@@ -51,7 +51,8 @@ const Mock = CanvasKit => {
51
51
  useFonts: Noop,
52
52
  useTypeface: () => null,
53
53
  useImage: () => null,
54
- useSVG: () => null
54
+ useSVG: () => null,
55
+ useVideo: () => null
55
56
  };
56
57
  };
57
58
  exports.Mock = Mock;
@@ -1 +1 @@
1
- {"version":3,"names":["_web","require","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","useValue","useComputedValue","useTouchHandler","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n global.SkiaApi = JsiSkApi(CanvasKit);\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTouchHandler: Noop,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5CC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,SAAS,CAAC;EACpC,MAAMI,IAAI,GAAGH,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLE,IAAI;IACJ,GAAGZ,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B;IACAa,MAAM,EAAEZ,IAAI;IACZ;IACAa,QAAQ,EAAEX,SAAS;IACnBY,gBAAgB,EAAEZ,SAAS;IAC3Ba,eAAe,EAAEf,IAAI;IACrBgB,SAAS,EAAEd,SAAS;IACpBe,OAAO,EAAEf,SAAS;IAClBgB,SAAS,EAAEhB,SAAS;IACpBiB,aAAa,EAAEjB,SAAS;IACxBkB,cAAc,EAAEpB,IAAI;IACpB;IACAqB,QAAQ,EAAEjB,eAAe;IACzBkB,oBAAoB,EAAElB,eAAe;IACrCmB,iBAAiB,EAAEnB,eAAe;IAClCoB,eAAe,EAAEpB,eAAe;IAChCqB,0BAA0B,EAAErB,eAAe;IAC3CsB,gBAAgB,EAAEtB,eAAe;IACjCuB,cAAc,EAAEvB,eAAe;IAC/BwB,cAAc,EAAExB,eAAe;IAC/ByB,aAAa,EAAEzB,eAAe;IAC9B0B,SAAS,EAAE1B,eAAe;IAC1B2B,UAAU,EAAE/B,IAAI;IAChBgC,OAAO,EAAEhC,IAAI;IACbiC,OAAO,EAAEA,CAAA,KAAMtB,IAAI,CAACuB,IAAI,CAACjC,SAAS,EAAE,CAAC,CAAC;IACtCkC,QAAQ,EAAEnC,IAAI;IACdoC,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM;EAChB,CAAC;AACH,CAAC;AAACC,OAAA,CAAAjC,IAAA,GAAAA,IAAA"}
1
+ {"version":3,"names":["_web","require","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","useValue","useComputedValue","useTouchHandler","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n global.SkiaApi = JsiSkApi(CanvasKit);\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTouchHandler: Noop,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAA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,EAAEnC,IAAI;IACdoC,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM,IAAI;IAClBC,QAAQ,EAAEA,CAAA,KAAM;EAClB,CAAC;AACH,CAAC;AAACC,OAAA,CAAAlC,IAAA,GAAAA,IAAA"}
@@ -46,7 +46,7 @@ export interface ImageFactory {
46
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
47
47
  /**
48
48
  * Return an Image backed by a given native buffer.
49
- * The platform buffer must be a valid owning reference.
49
+ * The native buffer must be a valid owning reference.
50
50
  *
51
51
  * For instance, this API is used by
52
52
  * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
@@ -54,9 +54,9 @@ export interface ImageFactory {
54
54
  *
55
55
  * - On Android; This is an `AHardwareBuffer*`
56
56
  * - On iOS, this is a `CVPixelBufferRef`
57
- * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
58
58
  * @throws Throws an error if the Image could not be created, for example when the given
59
- * platform buffer is invalid.
59
+ * native buffer is invalid.
60
60
  */
61
61
  MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
62
62
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["AlphaType","exports","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The platform buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * platform buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAKYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAAA,IAOTE,SAAS,GAAAD,OAAA,CAAAC,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAiBT"}
1
+ {"version":3,"names":["AlphaType","exports","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The native buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * native buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAKYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAAA,IAOTE,SAAS,GAAAD,OAAA,CAAAC,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAiBT"}
@@ -12,7 +12,7 @@ export interface NativeBufferFactory {
12
12
  */
13
13
  MakeFromImage: (image: SkImage) => NativeBuffer;
14
14
  /**
15
- * Release a platform buffer that was created with `MakeFromImage`.
15
+ * Release a native buffer that was created with `MakeFromImage`.
16
16
  */
17
- Release: (platformBuffer: NativeBuffer) => void;
17
+ Release: (nativeBuffer: NativeBuffer) => void;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","exports","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a native buffer.\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a platform buffer that was created with `MakeFromImage`.\n */\n Release: (platformBuffer: NativeBuffer) => void;\n}\n"],"mappings":";;;;;;AAUO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA;AACnD,MAAMI,iBAAiB,GAC5BH,MAAoB,IAEpBA,MAAM,YAAYI,gBAAgB,IAClCJ,MAAM,YAAYK,iBAAiB,IACnCL,MAAM,YAAYM,WAAW,IAC7BN,MAAM,YAAYO,eAAe,IACjCP,MAAM,YAAYQ,UAAU,IAC5BR,MAAM,YAAYS,gBAAgB,IAClCT,MAAM,YAAYU,eAAe;AAACR,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAE7B,MAAMQ,kBAAkB,GAC7BX,MAAoB,IACWA,MAAM,YAAYY,WAAW;AAACV,OAAA,CAAAS,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","exports","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a native buffer.\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a native buffer that was created with `MakeFromImage`.\n */\n Release: (nativeBuffer: NativeBuffer) => void;\n}\n"],"mappings":";;;;;;AAUO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA;AACnD,MAAMI,iBAAiB,GAC5BH,MAAoB,IAEpBA,MAAM,YAAYI,gBAAgB,IAClCJ,MAAM,YAAYK,iBAAiB,IACnCL,MAAM,YAAYM,WAAW,IAC7BN,MAAM,YAAYO,eAAe,IACjCP,MAAM,YAAYQ,UAAU,IAC5BR,MAAM,YAAYS,gBAAgB,IAClCT,MAAM,YAAYU,eAAe;AAACR,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAE7B,MAAMQ,kBAAkB,GAC7BX,MAAoB,IACWA,MAAM,YAAYY,WAAW;AAACV,OAAA,CAAAS,kBAAA,GAAAA,kBAAA"}
@@ -26,6 +26,7 @@ import type { Color, SkColor } from "./Color";
26
26
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
27
27
  import type { AnimatedImageFactory } from "./AnimatedImage";
28
28
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
29
+ import type { Video } from "./Video";
29
30
  import type { NativeBufferFactory } from "./NativeBuffer";
30
31
  /**
31
32
  * Declares the interface for the native Skia API
@@ -72,5 +73,6 @@ export interface Skia {
72
73
  TextBlob: TextBlobFactory;
73
74
  Surface: SurfaceFactory;
74
75
  ParagraphBuilder: ParagraphBuilderFactory;
76
+ Video: (url: string) => Video;
75
77
  NativeBuffer: NativeBufferFactory;
76
78
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { Video } from \"./Video\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n Video: (url: string) => Video;\n NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { SkImage } from "../Image";
2
+ import type { SkJSIInstance } from "../JsiInstance";
3
+ export interface Video extends SkJSIInstance<"Video"> {
4
+ duration(): number;
5
+ framerate(): number;
6
+ nextImage(): SkImage | null;
7
+ seek(time: number): void;
8
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=Video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["Video.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\n\nexport interface Video extends SkJSIInstance<\"Video\"> {\n duration(): number;\n framerate(): number;\n nextImage(): SkImage | null;\n seek(time: number): void;\n}\n"],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from "./Video";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Video = require("./Video");
7
+ Object.keys(_Video).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Video[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Video[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Video","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./Video\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
@@ -4,5 +4,5 @@ import { Host } from "./Host";
4
4
  export declare class JsiSkNativeBufferFactory extends Host implements NativeBufferFactory {
5
5
  constructor(CanvasKit: CanvasKit);
6
6
  MakeFromImage(image: SkImage): NativeBuffer;
7
- Release(_platformBuffer: NativeBuffer): void;
7
+ Release(_nativeBuffer: NativeBuffer): void;
8
8
  }
@@ -21,7 +21,7 @@ class JsiSkNativeBufferFactory extends _Host.Host {
21
21
  ctx.putImageData(imageData, 0, 0);
22
22
  return canvas;
23
23
  }
24
- Release(_platformBuffer) {
24
+ Release(_nativeBuffer) {
25
25
  // it's a noop on Web
26
26
  }
27
27
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_Host","require","JsiSkNativeBufferFactory","Host","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_platformBuffer","exports"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_platformBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,KAAA,GAAAC,OAAA;AAEO,MAAMC,wBAAwB,SAC3BC,UAAI,CAEd;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,eAA6B,EAAE;IACrC;EAAA;AAEJ;AAACC,OAAA,CAAAvB,wBAAA,GAAAA,wBAAA"}
1
+ {"version":3,"names":["_Host","require","JsiSkNativeBufferFactory","Host","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_nativeBuffer","exports"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_nativeBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,KAAA,GAAAC,OAAA;AAEO,MAAMC,wBAAwB,SAC3BC,UAAI,CAEd;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,aAA2B,EAAE;IACnC;EAAA;AAEJ;AAACC,OAAA,CAAAvB,wBAAA,GAAAA,wBAAA"}
@@ -80,7 +80,10 @@ const JsiSkApi = CanvasKit => ({
80
80
  TypefaceFontProvider: new _JsiSkTypefaceFontProviderFactory.JsiSkTypefaceFontProviderFactory(CanvasKit),
81
81
  FontMgr: new _JsiSkFontMgrFactory.JsiSkFontMgrFactory(CanvasKit),
82
82
  ParagraphBuilder: new _JsiSkParagraphBuilderFactory.JsiSkParagraphBuilderFactory(CanvasKit),
83
- NativeBuffer: new _JsiSkNativeBufferFactory.JsiSkNativeBufferFactory(CanvasKit)
83
+ NativeBuffer: new _JsiSkNativeBufferFactory.JsiSkNativeBufferFactory(CanvasKit),
84
+ Video: _localUri => {
85
+ throw new Error("Not implemented on React Native Web");
86
+ }
84
87
  });
85
88
  exports.JsiSkApi = JsiSkApi;
86
89
  //# sourceMappingURL=JsiSkia.js.map