@shopify/react-native-skia 1.3.3 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/android/cpp/jni/JniPlatformContext.cpp +4 -3
  2. package/cpp/rnskia/RNSkJsiViewApi.h +25 -67
  3. package/cpp/rnskia/RNSkManager.cpp +1 -1
  4. package/cpp/rnskia/RNSkView.h +0 -11
  5. package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +1 -1
  6. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  7. package/lib/commonjs/external/reanimated/useVideo.js +22 -9
  8. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  9. package/lib/commonjs/external/reanimated/useVideoLoading.d.ts +4 -0
  10. package/lib/commonjs/external/reanimated/useVideoLoading.js +28 -0
  11. package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -0
  12. package/lib/commonjs/external/reanimated/useVideoLoading.web.d.ts +4 -0
  13. package/lib/commonjs/external/reanimated/useVideoLoading.web.js +20 -0
  14. package/lib/commonjs/external/reanimated/useVideoLoading.web.js.map +1 -0
  15. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  16. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +4 -2
  17. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  18. package/lib/commonjs/skia/types/Skia.d.ts +1 -1
  19. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  20. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  21. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js +30 -0
  22. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js.map +1 -0
  23. package/lib/commonjs/skia/web/JsiSkImageFactory.js +8 -2
  24. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  25. package/lib/commonjs/skia/web/JsiSkia.js +2 -3
  26. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  27. package/lib/commonjs/skia/web/JsiVideo.d.ts +24 -0
  28. package/lib/commonjs/skia/web/JsiVideo.js +83 -0
  29. package/lib/commonjs/skia/web/JsiVideo.js.map +1 -0
  30. package/lib/commonjs/views/SkiaDomView.js +3 -1
  31. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  32. package/lib/commonjs/views/SkiaDomView.web.js +2 -0
  33. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  34. package/lib/commonjs/views/SkiaJSDomView.js +3 -1
  35. package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
  36. package/lib/commonjs/views/SkiaPictureView.js +1 -1
  37. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  38. package/lib/commonjs/views/types.d.ts +0 -8
  39. package/lib/commonjs/views/types.js +0 -3
  40. package/lib/commonjs/views/types.js.map +1 -1
  41. package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +1 -1
  42. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  43. package/lib/module/external/reanimated/useVideo.js +22 -9
  44. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  45. package/lib/module/external/reanimated/useVideoLoading.d.ts +4 -0
  46. package/lib/module/external/reanimated/useVideoLoading.js +20 -0
  47. package/lib/module/external/reanimated/useVideoLoading.js.map +1 -0
  48. package/lib/module/external/reanimated/useVideoLoading.web.d.ts +4 -0
  49. package/lib/module/external/reanimated/useVideoLoading.web.js +13 -0
  50. package/lib/module/external/reanimated/useVideoLoading.web.js.map +1 -0
  51. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  52. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +2 -1
  53. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  54. package/lib/module/skia/types/Skia.d.ts +1 -1
  55. package/lib/module/skia/types/Skia.js.map +1 -1
  56. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  57. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js +23 -0
  58. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js.map +1 -0
  59. package/lib/module/skia/web/JsiSkImageFactory.js +9 -3
  60. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  61. package/lib/module/skia/web/JsiSkia.js +2 -3
  62. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  63. package/lib/module/skia/web/JsiVideo.d.ts +24 -0
  64. package/lib/module/skia/web/JsiVideo.js +75 -0
  65. package/lib/module/skia/web/JsiVideo.js.map +1 -0
  66. package/lib/module/views/SkiaDomView.js +3 -1
  67. package/lib/module/views/SkiaDomView.js.map +1 -1
  68. package/lib/module/views/SkiaDomView.web.js +2 -0
  69. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  70. package/lib/module/views/SkiaJSDomView.js +3 -1
  71. package/lib/module/views/SkiaJSDomView.js.map +1 -1
  72. package/lib/module/views/SkiaPictureView.js +1 -1
  73. package/lib/module/views/SkiaPictureView.js.map +1 -1
  74. package/lib/module/views/types.d.ts +0 -8
  75. package/lib/module/views/types.js +0 -4
  76. package/lib/module/views/types.js.map +1 -1
  77. package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +1 -1
  78. package/lib/typescript/src/external/reanimated/useVideoLoading.d.ts +4 -0
  79. package/lib/typescript/src/external/reanimated/useVideoLoading.web.d.ts +4 -0
  80. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  81. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  82. package/lib/typescript/src/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  83. package/lib/typescript/src/skia/web/JsiVideo.d.ts +24 -0
  84. package/lib/typescript/src/views/types.d.ts +0 -8
  85. package/package.json +1 -1
  86. package/src/external/reanimated/useAnimatedImageValue.ts +1 -1
  87. package/src/external/reanimated/useVideo.ts +25 -9
  88. package/src/external/reanimated/useVideoLoading.ts +25 -0
  89. package/src/external/reanimated/useVideoLoading.web.ts +17 -0
  90. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +10 -2
  91. package/src/skia/types/Skia.ts +1 -1
  92. package/src/skia/web/CanvasKitWebGLBufferImpl.ts +22 -0
  93. package/src/skia/web/JsiSkImageFactory.ts +16 -3
  94. package/src/skia/web/JsiSkia.ts +2 -3
  95. package/src/skia/web/JsiVideo.ts +96 -0
  96. package/src/views/SkiaDomView.tsx +4 -1
  97. package/src/views/SkiaDomView.web.tsx +4 -0
  98. package/src/views/SkiaJSDomView.tsx +4 -1
  99. package/src/views/SkiaPictureView.tsx +0 -1
  100. package/src/views/types.ts +0 -13
@@ -77,6 +77,8 @@ TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis,
77
77
 
78
78
  jni::global_ref<jobject>
79
79
  JniPlatformContext::createVideo(const std::string &url) {
80
+ jni::Environment::ensureCurrentThreadIsAttached();
81
+
80
82
  jni::ThreadScope ts; // Manages JNI thread attachment/detachment
81
83
 
82
84
  // Get the JNI environment
@@ -85,14 +87,13 @@ JniPlatformContext::createVideo(const std::string &url) {
85
87
  // Convert std::string to jstring
86
88
  jstring jUrl = env->NewStringUTF(url.c_str());
87
89
 
88
- // Get the method ID for the createVideo method
89
- // Replace "Lcom/yourpackage/RNSkVideo;" with the actual return type
90
- // descriptor
91
90
  static auto method =
92
91
  javaPart_->getClass()->getMethod<jobject(jstring)>("createVideo");
93
92
 
94
93
  // Call the method and receive a local reference to the video object
95
94
  auto videoObject = method(javaPart_.get(), jUrl);
95
+ env->DeleteLocalRef(jUrl);
96
+
96
97
  // Clean up the jstring local reference
97
98
  auto result = jni::make_global(videoObject);
98
99
  return result;
@@ -51,10 +51,11 @@ public:
51
51
 
52
52
  return jsi::Value::undefined();
53
53
  }
54
+
54
55
  auto nativeId = arguments[0].asNumber();
56
+ std::lock_guard<std::mutex> lock(_mutex);
55
57
  auto info = getEnsuredViewInfo(nativeId);
56
58
 
57
- std::lock_guard<std::mutex> lock(_mutex);
58
59
  info->props.insert_or_assign(arguments[1].asString(runtime).utf8(runtime),
59
60
  RNJsi::JsiValueWrapper(runtime, arguments[2]));
60
61
 
@@ -69,52 +70,6 @@ public:
69
70
  return jsi::Value::undefined();
70
71
  }
71
72
 
72
- /**
73
- Calls a custom command / method on a view by the view id.
74
- */
75
- JSI_HOST_FUNCTION(callJsiMethod) {
76
- if (count < 2) {
77
- _platformContext->raiseError(
78
- std::string("callCustomCommand: Expected at least 2 arguments, got " +
79
- std::to_string(count) + "."));
80
-
81
- return jsi::Value::undefined();
82
- }
83
-
84
- if (!arguments[0].isNumber()) {
85
- _platformContext->raiseError(
86
- "callCustomCommand: First argument must be a number");
87
-
88
- return jsi::Value::undefined();
89
- }
90
-
91
- if (!arguments[1].isString()) {
92
- _platformContext->raiseError("callCustomCommand: Second argument must be "
93
- "the name of the action to call.");
94
-
95
- return jsi::Value::undefined();
96
- }
97
-
98
- auto nativeId = arguments[0].asNumber();
99
- auto action = arguments[1].asString(runtime).utf8(runtime);
100
-
101
- auto info = getEnsuredViewInfo(nativeId);
102
-
103
- if (info->view == nullptr) {
104
- throw jsi::JSError(
105
- runtime, std::string("callCustomCommand: Could not call action " +
106
- action + " on view - view not ready.")
107
- .c_str());
108
-
109
- return jsi::Value::undefined();
110
- }
111
-
112
- // Get arguments
113
- size_t paramsCount = count - 2;
114
- const jsi::Value *params = paramsCount > 0 ? &arguments[2] : nullptr;
115
- return info->view->callJsiMethod(runtime, action, params, paramsCount);
116
- }
117
-
118
73
  JSI_HOST_FUNCTION(requestRedraw) {
119
74
  if (count != 1) {
120
75
  _platformContext->raiseError(
@@ -133,7 +88,7 @@ public:
133
88
 
134
89
  // find Skia View
135
90
  int nativeId = arguments[0].asNumber();
136
-
91
+ std::lock_guard<std::mutex> lock(_mutex);
137
92
  auto info = getEnsuredViewInfo(nativeId);
138
93
  if (info->view != nullptr) {
139
94
  info->view->requestRedraw();
@@ -158,13 +113,18 @@ public:
158
113
  // find Skia view
159
114
  int nativeId = arguments[0].asNumber();
160
115
  sk_sp<SkImage> image;
161
- auto info = getEnsuredViewInfo(nativeId);
162
- if (info->view != nullptr) {
116
+ std::shared_ptr<RNSkView> view;
117
+ {
118
+ std::lock_guard<std::mutex> lock(_mutex);
119
+ auto info = getEnsuredViewInfo(nativeId);
120
+ view = info->view;
121
+ }
122
+ if (view != nullptr) {
163
123
  if (count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
164
124
  auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
165
- image = info->view->makeImageSnapshot(rect.get());
125
+ image = view->makeImageSnapshot(rect.get());
166
126
  } else {
167
- image = info->view->makeImageSnapshot(nullptr);
127
+ image = view->makeImageSnapshot(nullptr);
168
128
  }
169
129
  if (image == nullptr) {
170
130
  throw jsi::JSError(runtime,
@@ -194,20 +154,25 @@ public:
194
154
 
195
155
  // find Skia view
196
156
  int nativeId = arguments[0].asNumber();
197
- auto info = getEnsuredViewInfo(nativeId);
157
+ std::shared_ptr<RNSkView> view;
158
+ {
159
+ std::lock_guard<std::mutex> lock(_mutex);
160
+ auto info = getEnsuredViewInfo(nativeId);
161
+ view = info->view;
162
+ }
198
163
  auto context = _platformContext;
199
164
  auto bounds =
200
165
  count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()
201
166
  ? JsiSkRect::fromValue(runtime, arguments[1])
202
167
  : nullptr;
203
168
  return RNJsi::JsiPromises::createPromiseAsJSIValue(
204
- runtime, [context = std::move(context), info, bounds](
169
+ runtime, [context = std::move(context), view, bounds](
205
170
  jsi::Runtime &runtime,
206
171
  std::shared_ptr<RNJsi::JsiPromises::Promise> promise) {
207
- context->runOnMainThread([&runtime, info = std::move(info),
172
+ context->runOnMainThread([&runtime, view = std::move(view),
208
173
  promise = std::move(promise),
209
174
  context = std::move(context), bounds]() {
210
- auto image = info->view->makeImageSnapshot(
175
+ auto image = view->makeImageSnapshot(
211
176
  bounds == nullptr ? nullptr : bounds.get());
212
177
  context->runOnJavascriptThread(
213
178
  [&runtime, context = std::move(context),
@@ -225,7 +190,6 @@ public:
225
190
  }
226
191
 
227
192
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
228
- JSI_EXPORT_FUNC(RNSkJsiViewApi, callJsiMethod),
229
193
  JSI_EXPORT_FUNC(RNSkJsiViewApi, requestRedraw),
230
194
  JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshotAsync),
231
195
  JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot))
@@ -237,21 +201,16 @@ public:
237
201
  explicit RNSkJsiViewApi(std::shared_ptr<RNSkPlatformContext> platformContext)
238
202
  : JsiHostObject(), _platformContext(platformContext) {}
239
203
 
240
- /**
241
- * Invalidates the Skia View Api object
242
- */
243
- void invalidate() { unregisterAll(); }
244
-
245
204
  /**
246
205
  Call to remove all draw view infos
247
206
  */
248
207
  void unregisterAll() {
208
+ std::lock_guard<std::mutex> lock(_mutex);
249
209
  // Unregister all views
250
210
  auto tempList = _viewInfos;
251
211
  for (const auto &info : tempList) {
252
212
  unregisterSkiaView(info.first);
253
213
  }
254
- std::lock_guard<std::mutex> lock(_mutex);
255
214
  _viewInfos.clear();
256
215
  }
257
216
 
@@ -261,8 +220,8 @@ public:
261
220
  * @param view View to register
262
221
  */
263
222
  void registerSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
264
- auto info = getEnsuredViewInfo(nativeId);
265
223
  std::lock_guard<std::mutex> lock(_mutex);
224
+ auto info = getEnsuredViewInfo(nativeId);
266
225
  info->view = view;
267
226
  info->view->setNativeId(nativeId);
268
227
  info->view->setJsiProperties(info->props);
@@ -274,12 +233,12 @@ public:
274
233
  * @param nativeId View id
275
234
  */
276
235
  void unregisterSkiaView(size_t nativeId) {
236
+ std::lock_guard<std::mutex> lock(_mutex);
277
237
  if (_viewInfos.count(nativeId) == 0) {
278
238
  return;
279
239
  }
280
240
  auto info = getEnsuredViewInfo(nativeId);
281
241
 
282
- std::lock_guard<std::mutex> lock(_mutex);
283
242
  info->view = nullptr;
284
243
  _viewInfos.erase(nativeId);
285
244
  }
@@ -291,11 +250,11 @@ public:
291
250
  or a valid view, effectively toggling the view's availability.
292
251
  */
293
252
  void setSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
253
+ std::lock_guard<std::mutex> lock(_mutex);
294
254
  if (_viewInfos.find(nativeId) == _viewInfos.end()) {
295
255
  return;
296
256
  }
297
257
  auto info = getEnsuredViewInfo(nativeId);
298
- std::lock_guard<std::mutex> lock(_mutex);
299
258
  if (view != nullptr) {
300
259
  info->view = view;
301
260
  info->view->setNativeId(nativeId);
@@ -315,7 +274,6 @@ private:
315
274
  RNSkViewInfo *getEnsuredViewInfo(size_t nativeId) {
316
275
  if (_viewInfos.count(nativeId) == 0) {
317
276
  RNSkViewInfo info;
318
- std::lock_guard<std::mutex> lock(_mutex);
319
277
  _viewInfos.emplace(nativeId, info);
320
278
  }
321
279
  return &_viewInfos.at(nativeId);
@@ -46,7 +46,7 @@ void RNSkManager::invalidate() {
46
46
  _isInvalidated = true;
47
47
 
48
48
  // Invalidate members
49
- _viewApi->invalidate();
49
+ _viewApi->unregisterAll();
50
50
  _platformContext->invalidate();
51
51
  }
52
52
 
@@ -173,17 +173,6 @@ public:
173
173
  // Nothing here...
174
174
  }
175
175
 
176
- /**
177
- Calls a custom action.
178
- */
179
- virtual jsi::Value callJsiMethod(jsi::Runtime &runtime,
180
- const std::string &name,
181
- const jsi::Value *arguments, size_t count) {
182
- throw std::runtime_error(
183
- "The base Skia View does not support any commands. Command " + name +
184
- " not found.");
185
- }
186
-
187
176
  /**
188
177
  * Repaints the Skia view using the underlying context and the drawcallback.
189
178
  * This method schedules a draw request that will be run on the correct
@@ -1,3 +1,3 @@
1
- import { type SharedValue } from "react-native-reanimated";
1
+ import type { SharedValue } from "react-native-reanimated";
2
2
  import type { DataSourceParam, SkImage } from "../../skia/types";
3
3
  export declare const useAnimatedImageValue: (source: DataSourceParam, paused?: SharedValue<boolean>) => SharedValue<SkImage | null>;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_AnimatedImage","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","Rea","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","useEffect","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { type FrameInfo, type SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedIm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MAAM;MAAEC;IAAU,CAAC,GAAGF,SAAS;IAC/B,MAAMG,OAAO,GAAGD,SAAS,GAAGb,aAAa,CAACY,KAAK;;IAE/C;IACA,IAAIE,OAAO,GAAGN,aAAa,EAAE;MAC3B;IACF;;IAEA;IACAP,aAAa,CAACc,eAAe,CAAC,CAAC;IAC/B,IAAIhB,YAAY,CAACa,KAAK,EAAE;MACtBb,YAAY,CAACa,KAAK,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAjB,YAAY,CAACa,KAAK,GAAGX,aAAa,CAACgB,eAAe,CAAC,CAAC;;IAEpD;IACAjB,aAAa,CAACY,KAAK,GAAGC,SAAS;EACjC,CAAC,CAAC;EACF,IAAAK,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACXjB,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEe,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAOjB,YAAY;AACrB,CAAC;AAACoB,OAAA,CAAA3B,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_react","require","_AnimatedImage","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","Rea","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","useEffect","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport type { FrameInfo, SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoC,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,sBAAsB,GAAG,EAAE;AAE1B,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACH,MAAMC,aAAa,GAAGC,wBAAG,CAACC,cAAc,CAAC,KAAK,CAAC;EAC/C,MAAMC,QAAQ,GAAGJ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIC,aAAa;EACxC,MAAMI,YAAY,GAAGH,wBAAG,CAACC,cAAc,CAAiB,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,YAAY;AACrB,CAAC;AAACoB,OAAA,CAAA3B,qBAAA,GAAAA,qBAAA"}
@@ -5,10 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useVideo = void 0;
7
7
  var _react = require("react");
8
- var _Skia = require("../../skia/Skia");
9
8
  var _Platform = require("../../Platform");
10
9
  var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
10
+ var _useVideoLoading = require("./useVideoLoading");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const copyFrameOnAndroid = currentFrame => {
13
+ "worklet";
14
+
15
+ // on android we need to copy the texture before it's invalidated
16
+ if (_Platform.Platform.OS === "android") {
17
+ const tex = currentFrame.value;
18
+ if (tex) {
19
+ currentFrame.value = tex.makeNonTextureImage();
20
+ tex.dispose();
21
+ }
22
+ }
23
+ };
12
24
  const setFrame = (video, currentFrame) => {
13
25
  "worklet";
14
26
 
@@ -17,11 +29,9 @@ const setFrame = (video, currentFrame) => {
17
29
  if (currentFrame.value) {
18
30
  currentFrame.value.dispose();
19
31
  }
20
- if (_Platform.Platform.OS === "android") {
21
- currentFrame.value = img.makeNonTextureImage();
22
- } else {
23
- currentFrame.value = img;
24
- }
32
+ currentFrame.value = img;
33
+ } else {
34
+ copyFrameOnAndroid(currentFrame);
25
35
  }
26
36
  };
27
37
  const defaultOptions = {
@@ -45,7 +55,7 @@ const disposeVideo = video => {
45
55
  };
46
56
  const useVideo = (source, userOptions) => {
47
57
  var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$volume;
48
- const video = (0, _react.useMemo)(() => source ? _Skia.Skia.Video(source) : null, [source]);
58
+ const video = (0, _useVideoLoading.useVideoLoading)(source);
49
59
  const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused);
50
60
  const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping);
51
61
  const seek = useOption((_userOptions$seek = userOptions === null || userOptions === void 0 ? void 0 : userOptions.seek) !== null && _userOptions$seek !== void 0 ? _userOptions$seek : defaultOptions.seek);
@@ -59,7 +69,7 @@ const useVideo = (source, userOptions) => {
59
69
  }, [video]);
60
70
  const framerate = (0, _react.useMemo)(() => {
61
71
  var _video$framerate;
62
- return (_video$framerate = video === null || video === void 0 ? void 0 : video.framerate()) !== null && _video$framerate !== void 0 ? _video$framerate : 0;
72
+ return _Platform.Platform.OS === "web" ? -1 : (_video$framerate = video === null || video === void 0 ? void 0 : video.framerate()) !== null && _video$framerate !== void 0 ? _video$framerate : 0;
63
73
  }, [video]);
64
74
  const size = (0, _react.useMemo)(() => {
65
75
  var _video$size;
@@ -84,6 +94,7 @@ const useVideo = (source, userOptions) => {
84
94
  });
85
95
  _ReanimatedProxy.default.useAnimatedReaction(() => seek.value, value => {
86
96
  if (value !== null) {
97
+ copyFrameOnAndroid(currentFrame);
87
98
  video === null || video === void 0 || video.seek(value);
88
99
  currentTime.value = value;
89
100
  seek.value = null;
@@ -112,7 +123,9 @@ const useVideo = (source, userOptions) => {
112
123
  currentTime.value = seek.value;
113
124
  lastTimestamp.value = currentTimestamp;
114
125
  }
115
- if (delta >= currentFrameDuration && !isOver) {
126
+ // On Web the framerate is uknown.
127
+ // This could be optimized by using requestVideoFrameCallback (Chrome only)
128
+ if (delta >= currentFrameDuration && !isOver || _Platform.Platform.OS === "web") {
116
129
  setFrame(video, currentFrame);
117
130
  currentTime.value += delta;
118
131
  lastTimestamp.value = currentTimestamp;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Skia","_Platform","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","setFrame","video","currentFrame","img","nextImage","value","dispose","Platform","OS","makeNonTextureImage","defaultOptions","looping","paused","seek","currentTime","volume","useOption","defaultValue","Rea","useSharedValue","isSharedValue","disposeVideo","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$volume","useMemo","Skia","Video","isPaused","lastTimestamp","duration","_video$duration","framerate","_video$framerate","size","_video$size","width","height","rotation","_video$rotation","frameDuration","currentFrameDuration","Math","floor","useAnimatedReaction","pause","play","setVolume","useFrameCallback","frameInfo","currentTimestamp","timestamp","delta","isOver","useEffect","runOnUI","exports"],"sources":["useVideo.ts"],"sourcesContent":["import type { SharedValue, FrameInfo } from \"react-native-reanimated\";\nimport { useEffect, useMemo } from \"react\";\n\nimport { Skia } from \"../../skia/Skia\";\nimport type { SkImage, Video } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\n\ntype Animated<T> = SharedValue<T> | T;\n\ninterface PlaybackOptions {\n looping: Animated<boolean>;\n paused: Animated<boolean>;\n seek: Animated<number | null>;\n volume: Animated<number>;\n}\n\nconst setFrame = (video: Video, currentFrame: SharedValue<SkImage | null>) => {\n \"worklet\";\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};\n\nconst defaultOptions = {\n looping: true,\n paused: false,\n seek: null,\n currentTime: 0,\n volume: 0,\n};\n\nconst useOption = <T>(value: Animated<T>) => {\n \"worklet\";\n // TODO: only create defaultValue is needed (via makeMutable)\n const defaultValue = Rea.useSharedValue(\n Rea.isSharedValue(value) ? value.value : value\n );\n return Rea.isSharedValue(value) ? value : defaultValue;\n};\n\nconst disposeVideo = (video: Video | null) => {\n \"worklet\";\n video?.dispose();\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 seek = useOption(userOptions?.seek ?? defaultOptions.seek);\n const volume = useOption(userOptions?.volume ?? defaultOptions.volume);\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const currentTime = Rea.useSharedValue(0);\n const lastTimestamp = Rea.useSharedValue(-1);\n const duration = useMemo(() => video?.duration() ?? 0, [video]);\n const framerate = useMemo(() => video?.framerate() ?? 0, [video]);\n const size = useMemo(() => video?.size() ?? { width: 0, height: 0 }, [video]);\n const rotation = useMemo(() => video?.rotation() ?? 0, [video]);\n const frameDuration = 1000 / framerate;\n const currentFrameDuration = Math.floor(frameDuration);\n Rea.useAnimatedReaction(\n () => isPaused.value,\n (paused) => {\n if (paused) {\n video?.pause();\n } else {\n lastTimestamp.value = -1;\n video?.play();\n }\n }\n );\n Rea.useAnimatedReaction(\n () => seek.value,\n (value) => {\n if (value !== null) {\n video?.seek(value);\n currentTime.value = value;\n seek.value = null;\n }\n }\n );\n Rea.useAnimatedReaction(\n () => volume.value,\n (value) => {\n video?.setVolume(value);\n }\n );\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n \"worklet\";\n if (!video) {\n return;\n }\n if (isPaused.value) {\n return;\n }\n const currentTimestamp = frameInfo.timestamp;\n if (lastTimestamp.value === -1) {\n lastTimestamp.value = currentTimestamp;\n }\n const delta = currentTimestamp - lastTimestamp.value;\n\n const isOver = currentTime.value + delta > duration;\n if (isOver && looping.value) {\n seek.value = 0;\n currentTime.value = seek.value;\n lastTimestamp.value = currentTimestamp;\n }\n if (delta >= currentFrameDuration && !isOver) {\n setFrame(video, currentFrame);\n currentTime.value += delta;\n lastTimestamp.value = currentTimestamp;\n }\n });\n\n useEffect(() => {\n return () => {\n // TODO: should video simply be a shared value instead?\n Rea.runOnUI(disposeVideo)(video);\n };\n }, [video]);\n\n return {\n currentFrame,\n currentTime,\n duration,\n framerate,\n rotation,\n size,\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,I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AAW,CAACT,KAAK,IAAImD,KAAK;MAC1BvB,aAAa,CAAC5B,KAAK,GAAGiD,gBAAgB;IACxC;EACF,CAAC,CAAC;EAEF,IAAAI,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACX;MACAxC,wBAAG,CAACyC,OAAO,CAACtC,YAAY,CAAC,CAACpB,KAAK,CAAC;IAClC,CAAC;EACH,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO;IACLC,YAAY;IACZY,WAAW;IACXoB,QAAQ;IACRE,SAAS;IACTM,QAAQ;IACRJ;EACF,CAAC;AACH,CAAC;AAACsB,OAAA,CAAAtC,QAAA,GAAAA,QAAA"}
1
+ {"version":3,"names":["_react","require","_Platform","_ReanimatedProxy","_interopRequireDefault","_useVideoLoading","obj","__esModule","default","copyFrameOnAndroid","currentFrame","Platform","OS","tex","value","makeNonTextureImage","dispose","setFrame","video","img","nextImage","defaultOptions","looping","paused","seek","currentTime","volume","useOption","defaultValue","Rea","useSharedValue","isSharedValue","disposeVideo","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$volume","useVideoLoading","isPaused","lastTimestamp","duration","useMemo","_video$duration","framerate","_video$framerate","size","_video$size","width","height","rotation","_video$rotation","frameDuration","currentFrameDuration","Math","floor","useAnimatedReaction","pause","play","setVolume","useFrameCallback","frameInfo","currentTimestamp","timestamp","delta","isOver","useEffect","runOnUI","exports"],"sources":["useVideo.ts"],"sourcesContent":["import type { SharedValue, FrameInfo } from \"react-native-reanimated\";\nimport { useEffect, useMemo } from \"react\";\n\nimport type { SkImage, Video } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\nimport { useVideoLoading } from \"./useVideoLoading\";\n\ntype Animated<T> = SharedValue<T> | T;\n\ninterface PlaybackOptions {\n looping: Animated<boolean>;\n paused: Animated<boolean>;\n seek: Animated<number | null>;\n volume: Animated<number>;\n}\n\nconst copyFrameOnAndroid = (currentFrame: SharedValue<SkImage | null>) => {\n \"worklet\";\n // on android we need to copy the texture before it's invalidated\n if (Platform.OS === \"android\") {\n const tex = currentFrame.value;\n if (tex) {\n currentFrame.value = tex.makeNonTextureImage();\n tex.dispose();\n }\n }\n};\n\nconst setFrame = (video: Video, currentFrame: SharedValue<SkImage | null>) => {\n \"worklet\";\n const img = video.nextImage();\n if (img) {\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = img;\n } else {\n copyFrameOnAndroid(currentFrame);\n }\n};\n\nconst defaultOptions = {\n looping: true,\n paused: false,\n seek: null,\n currentTime: 0,\n volume: 0,\n};\n\nconst useOption = <T>(value: Animated<T>) => {\n \"worklet\";\n // TODO: only create defaultValue is needed (via makeMutable)\n const defaultValue = Rea.useSharedValue(\n Rea.isSharedValue(value) ? value.value : value\n );\n return Rea.isSharedValue(value) ? value : defaultValue;\n};\n\nconst disposeVideo = (video: Video | null) => {\n \"worklet\";\n video?.dispose();\n};\n\nexport const useVideo = (\n source: string | null,\n userOptions?: Partial<PlaybackOptions>\n) => {\n const video = useVideoLoading(source);\n const isPaused = useOption(userOptions?.paused ?? defaultOptions.paused);\n const looping = useOption(userOptions?.looping ?? defaultOptions.looping);\n const seek = useOption(userOptions?.seek ?? defaultOptions.seek);\n const volume = useOption(userOptions?.volume ?? defaultOptions.volume);\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const currentTime = Rea.useSharedValue(0);\n const lastTimestamp = Rea.useSharedValue(-1);\n const duration = useMemo(() => video?.duration() ?? 0, [video]);\n const framerate = useMemo(\n () => (Platform.OS === \"web\" ? -1 : video?.framerate() ?? 0),\n [video]\n );\n const size = useMemo(() => video?.size() ?? { width: 0, height: 0 }, [video]);\n const rotation = useMemo(() => video?.rotation() ?? 0, [video]);\n const frameDuration = 1000 / framerate;\n const currentFrameDuration = Math.floor(frameDuration);\n Rea.useAnimatedReaction(\n () => isPaused.value,\n (paused) => {\n if (paused) {\n video?.pause();\n } else {\n lastTimestamp.value = -1;\n video?.play();\n }\n }\n );\n Rea.useAnimatedReaction(\n () => seek.value,\n (value) => {\n if (value !== null) {\n copyFrameOnAndroid(currentFrame);\n video?.seek(value);\n currentTime.value = value;\n seek.value = null;\n }\n }\n );\n Rea.useAnimatedReaction(\n () => volume.value,\n (value) => {\n video?.setVolume(value);\n }\n );\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n \"worklet\";\n if (!video) {\n return;\n }\n if (isPaused.value) {\n return;\n }\n const currentTimestamp = frameInfo.timestamp;\n if (lastTimestamp.value === -1) {\n lastTimestamp.value = currentTimestamp;\n }\n const delta = currentTimestamp - lastTimestamp.value;\n\n const isOver = currentTime.value + delta > duration;\n if (isOver && looping.value) {\n seek.value = 0;\n currentTime.value = seek.value;\n lastTimestamp.value = currentTimestamp;\n }\n // On Web the framerate is uknown.\n // This could be optimized by using requestVideoFrameCallback (Chrome only)\n if ((delta >= currentFrameDuration && !isOver) || Platform.OS === \"web\") {\n setFrame(video, currentFrame);\n currentTime.value += delta;\n lastTimestamp.value = currentTimestamp;\n }\n });\n\n useEffect(() => {\n return () => {\n // TODO: should video simply be a shared value instead?\n Rea.runOnUI(disposeVideo)(video);\n };\n }, [video]);\n\n return {\n currentFrame,\n currentTime,\n duration,\n framerate,\n rotation,\n size,\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AAAoD,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAWpD,MAAMG,kBAAkB,GAAIC,YAAyC,IAAK;EACxE,SAAS;;EACT;EACA,IAAIC,kBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC7B,MAAMC,GAAG,GAAGH,YAAY,CAACI,KAA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AGkD,gBAAgB;IACxC;EACF,CAAC,CAAC;EAEF,IAAAI,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACX;MACAvC,wBAAG,CAACwC,OAAO,CAACrC,YAAY,CAAC,CAACd,KAAK,CAAC;IAClC,CAAC;EACH,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO;IACLR,YAAY;IACZe,WAAW;IACXkB,QAAQ;IACRG,SAAS;IACTM,QAAQ;IACRJ;EACF,CAAC;AACH,CAAC;AAACsB,OAAA,CAAArC,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Video } from "../../skia/types";
2
+ type VideoSource = string | null;
3
+ export declare const useVideoLoading: (source: VideoSource) => Video | null;
4
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useVideoLoading = void 0;
7
+ var _react = require("react");
8
+ var _skia = require("../../skia");
9
+ var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const runtime = _ReanimatedProxy.default.createWorkletRuntime("video-metadata-runtime");
12
+ const useVideoLoading = source => {
13
+ const [video, setVideo] = (0, _react.useState)(null);
14
+ const cb = src => {
15
+ "worklet";
16
+
17
+ const vid = _skia.Skia.Video(src);
18
+ _ReanimatedProxy.default.runOnJS(setVideo)(vid);
19
+ };
20
+ (0, _react.useEffect)(() => {
21
+ if (source) {
22
+ _ReanimatedProxy.default.runOnRuntime(runtime, cb)(source);
23
+ }
24
+ }, [source]);
25
+ return video;
26
+ };
27
+ exports.useVideoLoading = useVideoLoading;
28
+ //# sourceMappingURL=useVideoLoading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_skia","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","runtime","Rea","createWorkletRuntime","useVideoLoading","source","video","setVideo","useState","cb","src","vid","Skia","Video","runOnJS","useEffect","runOnRuntime","exports"],"sources":["useVideoLoading.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport type { Video } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst runtime = Rea.createWorkletRuntime(\"video-metadata-runtime\");\n\ntype VideoSource = string | null;\n\nexport const useVideoLoading = (source: VideoSource) => {\n const [video, setVideo] = useState<Video | null>(null);\n const cb = (src: string) => {\n \"worklet\";\n const vid = Skia.Video(src) as Video;\n Rea.runOnJS(setVideo)(vid);\n };\n useEffect(() => {\n if (source) {\n Rea.runOnRuntime(runtime, cb)(source);\n }\n }, [source]);\n return video;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoC,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,OAAO,GAAGC,wBAAG,CAACC,oBAAoB,CAAC,wBAAwB,CAAC;AAI3D,MAAMC,eAAe,GAAIC,MAAmB,IAAK;EACtD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAe,IAAI,CAAC;EACtD,MAAMC,EAAE,GAAIC,GAAW,IAAK;IAC1B,SAAS;;IACT,MAAMC,GAAG,GAAGC,UAAI,CAACC,KAAK,CAACH,GAAG,CAAU;IACpCR,wBAAG,CAACY,OAAO,CAACP,QAAQ,CAAC,CAACI,GAAG,CAAC;EAC5B,CAAC;EACD,IAAAI,gBAAS,EAAC,MAAM;IACd,IAAIV,MAAM,EAAE;MACVH,wBAAG,CAACc,YAAY,CAACf,OAAO,EAAEQ,EAAE,CAAC,CAACJ,MAAM,CAAC;IACvC;EACF,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EACZ,OAAOC,KAAK;AACd,CAAC;AAACW,OAAA,CAAAb,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Video } from "../../skia/types";
2
+ type VideoSource = string | null;
3
+ export declare const useVideoLoading: (source: VideoSource) => Video | null;
4
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useVideoLoading = void 0;
7
+ var _react = require("react");
8
+ var _skia = require("../../skia");
9
+ const useVideoLoading = source => {
10
+ const [video, setVideo] = (0, _react.useState)(null);
11
+ (0, _react.useEffect)(() => {
12
+ if (source) {
13
+ const vid = _skia.Skia.Video(source);
14
+ vid.then(v => setVideo(v));
15
+ }
16
+ }, [source]);
17
+ return video;
18
+ };
19
+ exports.useVideoLoading = useVideoLoading;
20
+ //# sourceMappingURL=useVideoLoading.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_skia","useVideoLoading","source","video","setVideo","useState","useEffect","vid","Skia","Video","then","v","exports"],"sources":["useVideoLoading.web.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport type { Video } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\ntype VideoSource = string | null;\n\nexport const useVideoLoading = (source: VideoSource) => {\n const [video, setVideo] = useState<Video | null>(null);\n useEffect(() => {\n if (source) {\n const vid = Skia.Video(source) as Promise<Video>;\n vid.then((v) => setVideo(v));\n }\n }, [source]);\n return video;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAIO,MAAME,eAAe,GAAIC,MAAmB,IAAK;EACtD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAe,IAAI,CAAC;EACtD,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAIJ,MAAM,EAAE;MACV,MAAMK,GAAG,GAAGC,UAAI,CAACC,KAAK,CAACP,MAAM,CAAmB;MAChDK,GAAG,CAACG,IAAI,CAAEC,CAAC,IAAKP,QAAQ,CAACO,CAAC,CAAC,CAAC;IAC9B;EACF,CAAC,EAAE,CAACT,MAAM,CAAC,CAAC;EACZ,OAAOC,KAAK;AACd,CAAC;AAACS,OAAA,CAAAX,eAAA,GAAAA,eAAA"}
@@ -1,5 +1,7 @@
1
1
  import type { SkImage } from "../Image";
2
- export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown> = T;
2
+ export declare abstract class CanvasKitWebGLBuffer {
3
+ }
4
+ export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | CanvasKitWebGLBuffer | unknown = unknown> = T;
3
5
  export type NativeBufferAddr = NativeBuffer<bigint>;
4
6
  export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
5
7
  export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isNativeBufferWeb = exports.isNativeBufferNode = exports.isNativeBufferAddr = void 0;
6
+ exports.isNativeBufferWeb = exports.isNativeBufferNode = exports.isNativeBufferAddr = exports.CanvasKitWebGLBuffer = void 0;
7
+ class CanvasKitWebGLBuffer {}
8
+ exports.CanvasKitWebGLBuffer = CanvasKitWebGLBuffer;
7
9
  const isNativeBufferAddr = buffer => buffer instanceof BigInt;
8
10
  exports.isNativeBufferAddr = isNativeBufferAddr;
9
- const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement;
11
+ const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement || buffer instanceof CanvasKitWebGLBuffer;
10
12
  exports.isNativeBufferWeb = isNativeBufferWeb;
11
13
  const isNativeBufferNode = buffer => buffer instanceof ArrayBuffer;
12
14
  exports.isNativeBufferNode = isNativeBufferNode;
@@ -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 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"}
1
+ {"version":3,"names":["CanvasKitWebGLBuffer","exports","isNativeBufferAddr","buffer","BigInt","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport abstract class CanvasKitWebGLBuffer {}\n\nexport type NativeBuffer<\n T extends\n | bigint\n | ArrayBuffer\n | CanvasImageSource\n | CanvasKitWebGLBuffer\n | 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 buffer instanceof CanvasKitWebGLBuffer;\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":";;;;;;AAEO,MAAeA,oBAAoB,CAAC;AAAEC,OAAA,CAAAD,oBAAA,GAAAA,oBAAA;AAetC,MAAME,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AAACH,OAAA,CAAAC,kBAAA,GAAAA,kBAAA;AACnD,MAAMG,iBAAiB,GAC5BF,MAAoB,IAEpBA,MAAM,YAAYG,gBAAgB,IAClCH,MAAM,YAAYI,iBAAiB,IACnCJ,MAAM,YAAYK,WAAW,IAC7BL,MAAM,YAAYM,eAAe,IACjCN,MAAM,YAAYO,UAAU,IAC5BP,MAAM,YAAYQ,gBAAgB,IAClCR,MAAM,YAAYS,eAAe,IACjCT,MAAM,YAAYH,oBAAoB;AAACC,OAAA,CAAAI,iBAAA,GAAAA,iBAAA;AAElC,MAAMQ,kBAAkB,GAC7BV,MAAoB,IACWA,MAAM,YAAYW,WAAW;AAACb,OAAA,CAAAY,kBAAA,GAAAA,kBAAA"}
@@ -73,6 +73,6 @@ export interface Skia {
73
73
  TextBlob: TextBlobFactory;
74
74
  Surface: SurfaceFactory;
75
75
  ParagraphBuilder: ParagraphBuilderFactory;
76
- Video: (url: string) => Video;
76
+ Video: (url: string) => Promise<Video> | Video;
77
77
  NativeBuffer: NativeBufferFactory;
78
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 { 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":""}
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) => Promise<Video> | Video;\n NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { Surface, TextureSource, Image } from "canvaskit-wasm";
2
+ import { CanvasKitWebGLBuffer } from "../types";
3
+ export declare class CanvasKitWebGLBufferImpl extends CanvasKitWebGLBuffer {
4
+ surface: Surface;
5
+ private source;
6
+ image: Image | null;
7
+ constructor(surface: Surface, source: TextureSource);
8
+ toImage(): Image;
9
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CanvasKitWebGLBufferImpl = void 0;
7
+ var _types = require("../types");
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
10
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ class CanvasKitWebGLBufferImpl extends _types.CanvasKitWebGLBuffer {
12
+ constructor(surface, source) {
13
+ super();
14
+ this.surface = surface;
15
+ this.source = source;
16
+ _defineProperty(this, "image", null);
17
+ }
18
+ toImage() {
19
+ if (this.image === null) {
20
+ this.image = this.surface.makeImageFromTextureSource(this.source);
21
+ }
22
+ if (this.image === null) {
23
+ throw new Error("Failed to create image from texture source");
24
+ }
25
+ this.surface.updateTextureFromSource(this.image, this.source);
26
+ return this.image;
27
+ }
28
+ }
29
+ exports.CanvasKitWebGLBufferImpl = CanvasKitWebGLBufferImpl;
30
+ //# sourceMappingURL=CanvasKitWebGLBufferImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","CanvasKitWebGLBufferImpl","CanvasKitWebGLBuffer","constructor","surface","source","toImage","image","makeImageFromTextureSource","Error","updateTextureFromSource","exports"],"sources":["CanvasKitWebGLBufferImpl.ts"],"sourcesContent":["import type { Surface, TextureSource, Image } from \"canvaskit-wasm\";\n\nimport { CanvasKitWebGLBuffer } from \"../types\";\n\nexport class CanvasKitWebGLBufferImpl extends CanvasKitWebGLBuffer {\n public image: Image | null = null;\n\n constructor(public surface: Surface, private source: TextureSource) {\n super();\n }\n\n toImage() {\n if (this.image === null) {\n this.image = this.surface.makeImageFromTextureSource(this.source);\n }\n if (this.image === null) {\n throw new Error(\"Failed to create image from texture source\");\n }\n this.surface.updateTextureFromSource(this.image, this.source);\n return this.image;\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IA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F;AAACI,OAAA,CAAAV,wBAAA,GAAAA,wBAAA"}
@@ -23,8 +23,14 @@ class JsiSkImageFactory extends _Host.Host {
23
23
  throw new Error("Invalid NativeBuffer");
24
24
  }
25
25
  if (!surface) {
26
- // TODO: this is way to slow
27
- const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
26
+ let img;
27
+ if (buffer instanceof HTMLImageElement || buffer instanceof HTMLVideoElement || buffer instanceof ImageBitmap) {
28
+ img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);
29
+ } else if (buffer instanceof _types.CanvasKitWebGLBuffer) {
30
+ img = buffer.toImage();
31
+ } else {
32
+ img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
33
+ }
28
34
  return new _JsiSkImage.JsiSkImage(this.CanvasKit, img);
29
35
  } else if (!image) {
30
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any